@spatika/editor 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -62,6 +62,7 @@ describe("ToolbarInsertPanels", () => {
|
|
|
62
62
|
const editor = createEditor();
|
|
63
63
|
const close = vi.fn();
|
|
64
64
|
const onGalleryPrefetch = vi.fn();
|
|
65
|
+
const chain = editor.chain();
|
|
65
66
|
|
|
66
67
|
render(
|
|
67
68
|
<ImageInsertPanel
|
|
@@ -71,13 +72,17 @@ describe("ToolbarInsertPanels", () => {
|
|
|
71
72
|
galleryPhotos: [{ id: 1, url: "https://example.com/gallery.png", alt: "Gallery photo" }],
|
|
72
73
|
onGalleryPrefetch,
|
|
73
74
|
galleryOpenLabel: "Open full gallery",
|
|
75
|
+
galleryInsertWidth: "min(100%, 28rem)",
|
|
74
76
|
}}
|
|
75
77
|
/>,
|
|
76
78
|
);
|
|
77
79
|
|
|
78
80
|
expect(onGalleryPrefetch).toHaveBeenCalled();
|
|
79
81
|
await userEvent.click(screen.getByRole("button", { name: "Gallery photo" }));
|
|
80
|
-
expect(
|
|
82
|
+
expect(chain.setImage).toHaveBeenCalledWith({
|
|
83
|
+
src: "https://example.com/gallery.png",
|
|
84
|
+
width: "min(100%, 28rem)",
|
|
85
|
+
});
|
|
81
86
|
expect(close).toHaveBeenCalled();
|
|
82
87
|
});
|
|
83
88
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Editor } from "@tiptap/core";
|
|
2
|
-
import {
|
|
2
|
+
import { Images, Upload } from "lucide-react";
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import type { ImageInsertConfig } from "../lib/types";
|
|
5
5
|
import { cn } from "../lib/cn";
|
|
@@ -75,8 +75,12 @@ export function LinkInsertPanel({ editor, close }: PanelProps) {
|
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function insertImageSrc(editor: Editor, src: string) {
|
|
79
|
-
editor
|
|
78
|
+
function insertImageSrc(editor: Editor, src: string, width?: string) {
|
|
79
|
+
editor
|
|
80
|
+
.chain()
|
|
81
|
+
.focus()
|
|
82
|
+
.setImage(width ? { src, width } : { src })
|
|
83
|
+
.run();
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
function resolveGalleryPhotoSrc(photo: NonNullable<ImageInsertConfig["galleryPhotos"]>[number]) {
|
|
@@ -119,7 +123,7 @@ export function ImageInsertPanel({ editor, close, config }: ImagePanelProps) {
|
|
|
119
123
|
|
|
120
124
|
const insertGalleryPhoto = (photoUrl: string) => {
|
|
121
125
|
if (!photoUrl.trim()) return;
|
|
122
|
-
insertImageSrc(editor, photoUrl);
|
|
126
|
+
insertImageSrc(editor, photoUrl, config?.galleryInsertWidth);
|
|
123
127
|
close();
|
|
124
128
|
};
|
|
125
129
|
|
|
@@ -244,7 +248,6 @@ export function ImageInsertPanel({ editor, close, config }: ImagePanelProps) {
|
|
|
244
248
|
onClick={insertFromUrl}
|
|
245
249
|
disabled={!url.trim()}
|
|
246
250
|
>
|
|
247
|
-
<ImagePlus className="size-4" aria-hidden="true" />
|
|
248
251
|
Insert
|
|
249
252
|
</button>
|
|
250
253
|
</div>
|
package/src/lib/types.ts
CHANGED
|
@@ -47,6 +47,8 @@ export type ImageInsertConfig = {
|
|
|
47
47
|
galleryEmptyMessage?: string;
|
|
48
48
|
/** Label for the host gallery action button. Default "Open gallery". */
|
|
49
49
|
galleryOpenLabel?: string;
|
|
50
|
+
/** Width applied when inserting from the gallery quick-pick. */
|
|
51
|
+
galleryInsertWidth?: string;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
export type SlashCommandItem = {
|
package/src/styles/editor.css
CHANGED
|
@@ -615,13 +615,20 @@
|
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
.spk-editor-toolbar-popover-btn {
|
|
618
|
+
display: inline-flex;
|
|
619
|
+
align-items: center;
|
|
620
|
+
justify-content: center;
|
|
621
|
+
gap: 0.35rem;
|
|
618
622
|
border: 0;
|
|
619
623
|
border-radius: var(--radius-pill, 999px);
|
|
620
624
|
padding: 0.35rem 0.75rem;
|
|
621
625
|
font: inherit;
|
|
622
626
|
font-size: 0.8125rem;
|
|
623
627
|
font-weight: 600;
|
|
628
|
+
line-height: 1.2;
|
|
629
|
+
white-space: nowrap;
|
|
624
630
|
cursor: pointer;
|
|
631
|
+
flex: 0 0 auto;
|
|
625
632
|
}
|
|
626
633
|
|
|
627
634
|
.spk-editor-toolbar-popover-btn--ghost {
|
|
@@ -718,7 +725,8 @@
|
|
|
718
725
|
}
|
|
719
726
|
|
|
720
727
|
.spk-editor-image-insert {
|
|
721
|
-
min-width:
|
|
728
|
+
min-width: 0;
|
|
729
|
+
max-width: 100%;
|
|
722
730
|
}
|
|
723
731
|
|
|
724
732
|
.spk-editor-image-gallery {
|
|
@@ -729,13 +737,14 @@
|
|
|
729
737
|
|
|
730
738
|
.spk-editor-image-gallery-grid {
|
|
731
739
|
display: grid;
|
|
732
|
-
grid-template-columns: repeat(
|
|
733
|
-
gap: 0.
|
|
740
|
+
grid-template-columns: repeat(5, minmax(0, 1fr));
|
|
741
|
+
gap: 0.35rem;
|
|
734
742
|
}
|
|
735
743
|
|
|
736
744
|
.spk-editor-image-gallery-item {
|
|
737
745
|
position: relative;
|
|
738
746
|
aspect-ratio: 1;
|
|
747
|
+
max-height: 3.25rem;
|
|
739
748
|
overflow: hidden;
|
|
740
749
|
border: 2px solid transparent;
|
|
741
750
|
border-radius: 0.65rem;
|
|
@@ -894,6 +903,8 @@
|
|
|
894
903
|
.spk-editor-toolbar-popover-panel--portal {
|
|
895
904
|
position: fixed;
|
|
896
905
|
z-index: 60;
|
|
906
|
+
width: min(18rem, calc(100vw - 1.5rem));
|
|
907
|
+
max-width: min(18rem, calc(100vw - 1.5rem));
|
|
897
908
|
}
|
|
898
909
|
|
|
899
910
|
.spk-editor-ai-panel {
|