Compare commits
2 Commits
docs/dev-s
...
image-inli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20032be921 | ||
| 2524f39a36 |
@@ -12,6 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- **Place several images side by side in a row.** A new "Inline (side by
|
||||||
|
side)" alignment mode in the image bubble menu renders consecutive inline
|
||||||
|
images as a row that wraps onto the next line on narrow screens. Unlike the
|
||||||
|
float modes, text does not wrap around inline images. The mode round-trips
|
||||||
|
losslessly through markdown as `data-align`, like the other alignment
|
||||||
|
values.
|
||||||
|
|
||||||
- **Editable captions for images.** Images gain an optional caption shown
|
- **Editable captions for images.** Images gain an optional caption shown
|
||||||
below them, edited inline from the image bubble menu and stored as a `caption` attribute. Captions round-trip
|
below them, edited inline from the image bubble menu and stored as a `caption` attribute. Captions round-trip
|
||||||
losslessly through markdown as a `data-caption` attribute on the image, so
|
losslessly through markdown as a `data-caption` attribute on the image, so
|
||||||
|
|||||||
@@ -1322,6 +1322,7 @@
|
|||||||
"Move to space": "Move to space",
|
"Move to space": "Move to space",
|
||||||
"Float left (wrap text)": "Float left (wrap text)",
|
"Float left (wrap text)": "Float left (wrap text)",
|
||||||
"Float right (wrap text)": "Float right (wrap text)",
|
"Float right (wrap text)": "Float right (wrap text)",
|
||||||
|
"Inline (side by side)": "Inline (side by side)",
|
||||||
"Switch to tree": "Switch to tree",
|
"Switch to tree": "Switch to tree",
|
||||||
"Switch to flat list": "Switch to flat list",
|
"Switch to flat list": "Switch to flat list",
|
||||||
"Toggle subpages display mode": "Toggle subpages display mode",
|
"Toggle subpages display mode": "Toggle subpages display mode",
|
||||||
|
|||||||
@@ -1175,6 +1175,7 @@
|
|||||||
"Spoken language hint sent to the transcription model. Auto-detect lets the model decide.": "Подсказка языка речи для модели транскрипции. «Автоопределение» оставляет выбор за моделью.",
|
"Spoken language hint sent to the transcription model. Auto-detect lets the model decide.": "Подсказка языка речи для модели транскрипции. «Автоопределение» оставляет выбор за моделью.",
|
||||||
"Float left (wrap text)": "Обтекание слева",
|
"Float left (wrap text)": "Обтекание слева",
|
||||||
"Float right (wrap text)": "Обтекание справа",
|
"Float right (wrap text)": "Обтекание справа",
|
||||||
|
"Inline (side by side)": "В ряд",
|
||||||
"Switch to tree": "Переключить на дерево",
|
"Switch to tree": "Переключить на дерево",
|
||||||
"Switch to flat list": "Переключить на плоский список",
|
"Switch to flat list": "Переключить на плоский список",
|
||||||
"Toggle subpages display mode": "Переключить режим отображения подстраниц",
|
"Toggle subpages display mode": "Переключить режим отображения подстраниц",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
IconLayoutAlignRight,
|
IconLayoutAlignRight,
|
||||||
IconFloatLeft,
|
IconFloatLeft,
|
||||||
IconFloatRight,
|
IconFloatRight,
|
||||||
|
IconLayoutColumns,
|
||||||
IconDownload,
|
IconDownload,
|
||||||
IconRefresh,
|
IconRefresh,
|
||||||
IconTrash,
|
IconTrash,
|
||||||
@@ -46,6 +47,7 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
isAlignRight: ctx.editor.isActive("image", { align: "right" }),
|
isAlignRight: ctx.editor.isActive("image", { align: "right" }),
|
||||||
isFloatLeft: ctx.editor.isActive("image", { align: "floatLeft" }),
|
isFloatLeft: ctx.editor.isActive("image", { align: "floatLeft" }),
|
||||||
isFloatRight: ctx.editor.isActive("image", { align: "floatRight" }),
|
isFloatRight: ctx.editor.isActive("image", { align: "floatRight" }),
|
||||||
|
isInline: ctx.editor.isActive("image", { align: "inline" }),
|
||||||
src: imageAttrs?.src || null,
|
src: imageAttrs?.src || null,
|
||||||
alt: imageAttrs?.alt || "",
|
alt: imageAttrs?.alt || "",
|
||||||
caption: imageAttrs?.caption || "",
|
caption: imageAttrs?.caption || "",
|
||||||
@@ -126,6 +128,14 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
.run();
|
.run();
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
const alignImageInline = useCallback(() => {
|
||||||
|
editor
|
||||||
|
.chain()
|
||||||
|
.focus(undefined, { scrollIntoView: false })
|
||||||
|
.setImageAlign("inline")
|
||||||
|
.run();
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
const handleDownload = useCallback(() => {
|
const handleDownload = useCallback(() => {
|
||||||
if (!editorState?.src) return;
|
if (!editorState?.src) return;
|
||||||
const url = getFileUrl(editorState.src);
|
const url = getFileUrl(editorState.src);
|
||||||
@@ -259,6 +269,18 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip position="top" label={t("Inline (side by side)")} withinPortal={false}>
|
||||||
|
<ActionIcon
|
||||||
|
onClick={alignImageInline}
|
||||||
|
size="lg"
|
||||||
|
aria-label={t("Inline (side by side)")}
|
||||||
|
variant="subtle"
|
||||||
|
className={clsx({ [classes.active]: editorState?.isInline })}
|
||||||
|
>
|
||||||
|
<IconLayoutColumns size={18} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
<div className={classes.divider} />
|
<div className={classes.divider} />
|
||||||
|
|
||||||
{altTextButton}
|
{altTextButton}
|
||||||
|
|||||||
@@ -63,6 +63,38 @@ describe("applyAlignment", () => {
|
|||||||
expect(el.dataset.imageAlign).toBe("center");
|
expect(el.dataset.imageAlign).toBe("center");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("inline -> inline-block + top alignment + gap padding, no float", () => {
|
||||||
|
applyAlignment(el, "inline");
|
||||||
|
expect(el.style.display).toBe("inline-block");
|
||||||
|
expect(el.style.verticalAlign).toBe("top");
|
||||||
|
expect(el.style.padding).toBe("0px 10px 10px 0px");
|
||||||
|
expect(el.dataset.imageAlign).toBe("inline");
|
||||||
|
expect(el.style.cssFloat).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("clears inline-block when switching inline -> center (reset-then-apply)", () => {
|
||||||
|
applyAlignment(el, "inline");
|
||||||
|
expect(el.style.display).toBe("inline-block");
|
||||||
|
// Switching back to a flex alignment must replace the inline-block
|
||||||
|
// override with the constructor-style flex, not just clear it.
|
||||||
|
applyAlignment(el, "center");
|
||||||
|
expect(el.style.display).toBe("flex");
|
||||||
|
expect(el.style.verticalAlign).toBe("");
|
||||||
|
expect(el.style.padding).toBe("");
|
||||||
|
expect(el.dataset.imageAlign).toBe("center");
|
||||||
|
expect(el.style.justifyContent).toBe("center");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("clears a previous float when switching floatLeft -> inline", () => {
|
||||||
|
applyAlignment(el, "floatLeft");
|
||||||
|
expect(el.style.cssFloat).toBe("left");
|
||||||
|
applyAlignment(el, "inline");
|
||||||
|
expect(el.style.cssFloat).toBe("");
|
||||||
|
expect(el.style.display).toBe("inline-block");
|
||||||
|
expect(el.style.verticalAlign).toBe("top");
|
||||||
|
expect(el.dataset.imageAlign).toBe("inline");
|
||||||
|
});
|
||||||
|
|
||||||
it("clears a previous float when switching floatLeft -> left (reset-then-apply)", () => {
|
it("clears a previous float when switching floatLeft -> left (reset-then-apply)", () => {
|
||||||
applyAlignment(el, "floatLeft");
|
applyAlignment(el, "floatLeft");
|
||||||
expect(el.style.cssFloat).toBe("left");
|
expect(el.style.cssFloat).toBe("left");
|
||||||
|
|||||||
@@ -53,7 +53,13 @@ declare module "@tiptap/core" {
|
|||||||
attributes: ImageAttributes & { pos: number | Range },
|
attributes: ImageAttributes & { pos: number | Range },
|
||||||
) => ReturnType;
|
) => ReturnType;
|
||||||
setImageAlign: (
|
setImageAlign: (
|
||||||
align: "left" | "center" | "right" | "floatLeft" | "floatRight",
|
align:
|
||||||
|
| "left"
|
||||||
|
| "center"
|
||||||
|
| "right"
|
||||||
|
| "floatLeft"
|
||||||
|
| "floatRight"
|
||||||
|
| "inline",
|
||||||
) => ReturnType;
|
) => ReturnType;
|
||||||
setImageWidth: (width: number) => ReturnType;
|
setImageWidth: (width: number) => ReturnType;
|
||||||
setImageSize: (width: number, height: number) => ReturnType;
|
setImageSize: (width: number, height: number) => ReturnType;
|
||||||
@@ -415,6 +421,14 @@ export function applyAlignment(container: HTMLElement, align: string) {
|
|||||||
// (a previous float must not leak into a later left/center/right).
|
// (a previous float must not leak into a later left/center/right).
|
||||||
container.style.cssFloat = "";
|
container.style.cssFloat = "";
|
||||||
container.style.padding = "";
|
container.style.padding = "";
|
||||||
|
// The ResizableNodeView constructor sets an inline `display: flex` on the
|
||||||
|
// container; the inline mode overrides it with `inline-block`, so the reset
|
||||||
|
// restores the constructor's flex here. This keeps the container's layout
|
||||||
|
// independent of any app-level CSS class (which also happens to set flex)
|
||||||
|
// and makes non-inline modes carry exactly the same inline styles as before
|
||||||
|
// the inline mode existed.
|
||||||
|
container.style.display = "flex";
|
||||||
|
container.style.verticalAlign = "";
|
||||||
// Mirror the resolved alignment onto the CONTAINER as a data attribute so the
|
// Mirror the resolved alignment onto the CONTAINER as a data attribute so the
|
||||||
// responsive stylesheet can neutralize the float on small screens (an inline
|
// responsive stylesheet can neutralize the float on small screens (an inline
|
||||||
// `float` can only be overridden by `!important`, which keys off this attr).
|
// `float` can only be overridden by `!important`, which keys off this attr).
|
||||||
@@ -430,6 +444,15 @@ export function applyAlignment(container: HTMLElement, align: string) {
|
|||||||
container.style.cssFloat = "right";
|
container.style.cssFloat = "right";
|
||||||
container.style.padding = "0 0 0 10px";
|
container.style.padding = "0 0 0 10px";
|
||||||
container.style.justifyContent = "flex-end";
|
container.style.justifyContent = "flex-end";
|
||||||
|
} else if (align === "inline") {
|
||||||
|
// Consecutive inline images sit side by side on one line box and wrap to
|
||||||
|
// the next line when the viewport is narrow. The right/bottom padding
|
||||||
|
// provides the gap between images in a row and between wrapped rows;
|
||||||
|
// vertical-align: top keeps rows of different-height images aligned by
|
||||||
|
// their top edge.
|
||||||
|
container.style.display = "inline-block";
|
||||||
|
container.style.verticalAlign = "top";
|
||||||
|
container.style.padding = "0 10px 10px 0";
|
||||||
} else if (align === "left") {
|
} else if (align === "left") {
|
||||||
container.style.justifyContent = "flex-start";
|
container.style.justifyContent = "flex-start";
|
||||||
} else if (align === "right") {
|
} else if (align === "right") {
|
||||||
|
|||||||
Reference in New Issue
Block a user