@ilamanownuk/blog-kit 0.0.0-stage → 0.2.0

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/dist/index.js ADDED
@@ -0,0 +1,948 @@
1
+ "use client";
2
+
3
+ // src/editor/rich-text-editor.tsx
4
+ import * as React7 from "react";
5
+ import { EditorContent, useEditor } from "@tiptap/react";
6
+
7
+ // src/shared/embed.ts
8
+ var ALL_EMBED_PROVIDERS = ["aparat", "youtube"];
9
+ var EMBED_PROVIDERS = {
10
+ aparat: {
11
+ hostname: "www.aparat.com",
12
+ prefix: "https://www.aparat.com/video/video/embed/",
13
+ embedBase: "https://www.aparat.com/video/video/embed/videohash/"
14
+ },
15
+ youtube: {
16
+ hostname: "www.youtube-nocookie.com",
17
+ prefix: "https://www.youtube-nocookie.com/embed/",
18
+ embedBase: "https://www.youtube-nocookie.com/embed/"
19
+ }
20
+ };
21
+ var YOUTUBE_ID = /^[A-Za-z0-9_-]{6,20}$/;
22
+ var APARAT_ID = /^[A-Za-z0-9]{3,20}$/;
23
+ function toVideoEmbedUrl(input, allowed = ALL_EMBED_PROVIDERS) {
24
+ let url;
25
+ try {
26
+ url = new URL(input.trim());
27
+ } catch {
28
+ return null;
29
+ }
30
+ if (url.protocol !== "https:") return null;
31
+ const host = url.hostname.replace(/^(www\.|m\.)/, "");
32
+ const segments = url.pathname.split("/").filter(Boolean);
33
+ if (host === "aparat.com") {
34
+ if (!allowed.includes("aparat")) return null;
35
+ const id2 = segments[0] === "v" ? segments[1] : segments.at(-1) === "frame" ? segments.at(-3) : void 0;
36
+ return id2 && APARAT_ID.test(id2) ? `${EMBED_PROVIDERS.aparat.embedBase}${id2}/vt/frame` : null;
37
+ }
38
+ if (!allowed.includes("youtube")) return null;
39
+ let id;
40
+ if (host === "youtu.be") id = segments[0];
41
+ else if (host === "youtube.com" || host === "youtube-nocookie.com") {
42
+ id = ["embed", "shorts", "live"].includes(segments[0] ?? "") ? segments[1] : url.searchParams.get("v");
43
+ }
44
+ return id && YOUTUBE_ID.test(id) ? `${EMBED_PROVIDERS.youtube.embedBase}${id}` : null;
45
+ }
46
+ function isAllowedEmbedSrc(src, allowed = ALL_EMBED_PROVIDERS) {
47
+ if (/[\s\\\u0000-\u001f]/.test(src)) return false;
48
+ let url;
49
+ try {
50
+ url = new URL(src);
51
+ } catch {
52
+ return false;
53
+ }
54
+ if (url.protocol !== "https:" || url.username || url.password || url.port) return false;
55
+ return allowed.some((name) => {
56
+ const provider = EMBED_PROVIDERS[name];
57
+ return src.startsWith(provider.prefix) && url.hostname === provider.hostname && url.pathname.startsWith(new URL(provider.prefix).pathname);
58
+ });
59
+ }
60
+ function normalizeLinkUrl(input) {
61
+ const value = input.trim();
62
+ if (!value) return null;
63
+ if (value.startsWith("//")) return null;
64
+ if (value.startsWith("/")) return value;
65
+ if (/^(mailto|tel):[^\s]+$/i.test(value)) return value;
66
+ try {
67
+ const url = new URL(/^[a-z][a-z0-9+.-]*:/i.test(value) ? value : `https://${value}`);
68
+ return url.protocol === "http:" || url.protocol === "https:" ? url.toString() : null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ // src/editor/extensions.ts
75
+ import Highlight from "@tiptap/extension-highlight";
76
+ import Image from "@tiptap/extension-image";
77
+ import { Placeholder } from "@tiptap/extension-placeholder";
78
+ import { TableKit } from "@tiptap/extension-table";
79
+ import TextAlign from "@tiptap/extension-text-align";
80
+ import { Color, TextStyle } from "@tiptap/extension-text-style";
81
+ import StarterKit from "@tiptap/starter-kit";
82
+
83
+ // src/editor/video-node.ts
84
+ import { mergeAttributes, Node } from "@tiptap/react";
85
+ function createVideoEmbed(allowed) {
86
+ return Node.create({
87
+ name: "videoEmbed",
88
+ group: "block",
89
+ atom: true,
90
+ draggable: true,
91
+ addAttributes() {
92
+ return { src: { default: null } };
93
+ },
94
+ parseHTML() {
95
+ return [
96
+ {
97
+ tag: "iframe[src]",
98
+ getAttrs: (element) => {
99
+ const src = element.getAttribute("src");
100
+ return src && isAllowedEmbedSrc(src, allowed) ? { src } : false;
101
+ }
102
+ }
103
+ ];
104
+ },
105
+ renderHTML({ HTMLAttributes }) {
106
+ return [
107
+ "iframe",
108
+ mergeAttributes(HTMLAttributes, {
109
+ sandbox: "allow-scripts allow-same-origin allow-presentation",
110
+ loading: "lazy",
111
+ allowfullscreen: "true"
112
+ })
113
+ ];
114
+ }
115
+ });
116
+ }
117
+
118
+ // src/editor/extensions.ts
119
+ function buildEditorExtensions(placeholder, allowedEmbeds, dir) {
120
+ return [
121
+ StarterKit.configure({
122
+ heading: { levels: [2, 3, 4] },
123
+ link: {
124
+ openOnClick: false,
125
+ autolink: true,
126
+ defaultProtocol: "https",
127
+ isAllowedUri: (url) => normalizeLinkUrl(url) !== null
128
+ }
129
+ }),
130
+ // https images only; data: / relative paths are rejected on paste.
131
+ Image.extend({
132
+ parseHTML() {
133
+ return [
134
+ {
135
+ tag: "img[src]",
136
+ getAttrs: (element) => (element.getAttribute("src") ?? "").startsWith("https://") ? null : false
137
+ }
138
+ ];
139
+ }
140
+ }).configure({ allowBase64: false }),
141
+ TextAlign.configure({
142
+ types: ["heading", "paragraph"],
143
+ alignments: ["right", "center", "left", "justify"],
144
+ defaultAlignment: dir === "rtl" ? "right" : "left"
145
+ }),
146
+ Highlight.configure({ multicolor: true }),
147
+ TextStyle,
148
+ Color,
149
+ TableKit.configure({ table: { resizable: false } }),
150
+ Placeholder.configure({ placeholder }),
151
+ createVideoEmbed(allowedEmbeds)
152
+ ];
153
+ }
154
+
155
+ // src/editor/labels.ts
156
+ import { createContext, useContext } from "react";
157
+ var defaultLabels = {
158
+ placeholder: "\u0645\u062A\u0646 \u0631\u0627 \u0628\u0646\u0648\u06CC\u0633\u06CC\u062F\u2026",
159
+ bold: "\u067E\u0631\u0631\u0646\u06AF",
160
+ italic: "\u0645\u0648\u0631\u0628",
161
+ underline: "\u0632\u06CC\u0631\u062E\u0637",
162
+ strike: "\u062E\u0637\u200C\u062E\u0648\u0631\u062F\u0647",
163
+ h2: "\u062A\u06CC\u062A\u0631 \u06F2",
164
+ h3: "\u062A\u06CC\u062A\u0631 \u06F3",
165
+ h4: "\u062A\u06CC\u062A\u0631 \u06F4",
166
+ alignRight: "\u0631\u0627\u0633\u062A\u200C\u0686\u06CC\u0646",
167
+ alignCenter: "\u0648\u0633\u0637\u200C\u0686\u06CC\u0646",
168
+ alignLeft: "\u0686\u067E\u200C\u0686\u06CC\u0646",
169
+ alignJustify: "\u062A\u0631\u0627\u0632 \u062F\u0648 \u0637\u0631\u0641",
170
+ bulletList: "\u0644\u06CC\u0633\u062A \u0646\u0642\u0637\u0647\u200C\u0627\u06CC",
171
+ orderedList: "\u0644\u06CC\u0633\u062A \u0634\u0645\u0627\u0631\u0647\u200C\u062F\u0627\u0631",
172
+ quote: "\u0646\u0642\u0644\u200C\u0642\u0648\u0644",
173
+ codeBlock: "\u0628\u0644\u0648\u06A9 \u06A9\u062F",
174
+ hr: "\u062E\u0637 \u062C\u062F\u0627\u06A9\u0646\u0646\u062F\u0647",
175
+ link: "\u0644\u06CC\u0646\u06A9",
176
+ unlink: "\u062D\u0630\u0641 \u0644\u06CC\u0646\u06A9",
177
+ image: "\u062A\u0635\u0648\u06CC\u0631",
178
+ video: "\u0648\u06CC\u062F\u06CC\u0648 (\u0622\u067E\u0627\u0631\u0627\u062A/\u06CC\u0648\u062A\u06CC\u0648\u0628)",
179
+ table: "\u062C\u062F\u0648\u0644",
180
+ undo: "\u0648\u0627\u06AF\u0631\u062F",
181
+ redo: "\u0627\u0632\u0646\u0648",
182
+ textColor: "\u0631\u0646\u06AF \u0645\u062A\u0646",
183
+ highlight: "\u0647\u0627\u06CC\u0644\u0627\u06CC\u062A",
184
+ remove: "\u062D\u0630\u0641",
185
+ addRow: "+ \u0633\u0637\u0631",
186
+ addColumn: "+ \u0633\u062A\u0648\u0646",
187
+ deleteRow: "\u062D\u0630\u0641 \u0633\u0637\u0631",
188
+ deleteColumn: "\u062D\u0630\u0641 \u0633\u062A\u0648\u0646",
189
+ deleteTable: "\u062D\u0630\u0641 \u062C\u062F\u0648\u0644",
190
+ cancel: "\u0627\u0646\u0635\u0631\u0627\u0641",
191
+ insert: "\u062F\u0631\u062C",
192
+ close: "\u0628\u0633\u062A\u0646",
193
+ linkTitle: "\u062F\u0631\u062C \u0644\u06CC\u0646\u06A9",
194
+ linkField: "\u0622\u062F\u0631\u0633",
195
+ linkPlaceholder: "https://\u2026 \u06CC\u0627 /news/\u2026",
196
+ linkError: "\u0622\u062F\u0631\u0633 \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A (javascript: \u0648 data: \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A).",
197
+ videoTitle: "\u062F\u0631\u062C \u0648\u06CC\u062F\u06CC\u0648",
198
+ videoField: "\u0644\u06CC\u0646\u06A9 \u0648\u06CC\u062F\u06CC\u0648 \u062F\u0631 \u0622\u067E\u0627\u0631\u0627\u062A \u06CC\u0627 \u06CC\u0648\u062A\u06CC\u0648\u0628",
199
+ videoPlaceholder: "https://www.aparat.com/v/\u2026",
200
+ videoError: "\u0641\u0642\u0637 \u0644\u06CC\u0646\u06A9 \u0648\u06CC\u062F\u06CC\u0648\u06CC \u0622\u067E\u0627\u0631\u0627\u062A \u06CC\u0627 \u06CC\u0648\u062A\u06CC\u0648\u0628 \u067E\u0630\u06CC\u0631\u0641\u062A\u0647 \u0645\u06CC\u200C\u0634\u0648\u062F.",
201
+ imageTitle: "\u062F\u0631\u062C \u062A\u0635\u0648\u06CC\u0631",
202
+ imageUrl: "\u0622\u062F\u0631\u0633 \u062A\u0635\u0648\u06CC\u0631 (https)",
203
+ imageUrlPlaceholder: "https://\u2026",
204
+ imageAlt: "\u0645\u062A\u0646 \u062C\u0627\u06CC\u06AF\u0632\u06CC\u0646 (alt)",
205
+ imageUpload: "\u0622\u067E\u0644\u0648\u062F \u062A\u0635\u0648\u06CC\u0631",
206
+ imageUploading: "\u062F\u0631 \u062D\u0627\u0644 \u0622\u067E\u0644\u0648\u062F\u2026",
207
+ imageLibrary: "\u0627\u0646\u062A\u062E\u0627\u0628 \u0627\u0632 \u06A9\u062A\u0627\u0628\u062E\u0627\u0646\u0647",
208
+ imageInsert: "\u062F\u0631\u062C \u062A\u0635\u0648\u06CC\u0631",
209
+ imageHttpsError: "\u0641\u0642\u0637 \u0622\u062F\u0631\u0633 https \u0628\u0631\u0627\u06CC \u062A\u0635\u0648\u06CC\u0631 \u067E\u0630\u06CC\u0631\u0641\u062A\u0647 \u0645\u06CC\u200C\u0634\u0648\u062F.",
210
+ imageUploadFailed: "\u0622\u067E\u0644\u0648\u062F \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0648\u062F. \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F.",
211
+ mediaTitle: "\u06A9\u062A\u0627\u0628\u062E\u0627\u0646\u0647\u200C\u06CC \u062A\u0635\u0627\u0648\u06CC\u0631",
212
+ mediaSearch: "\u062C\u0633\u062A\u062C\u0648",
213
+ mediaSearchPlaceholder: "\u062C\u0633\u062A\u062C\u0648 \u062F\u0631 \u0646\u0627\u0645 \u06CC\u0627 \u0645\u062A\u0646 \u062C\u0627\u06CC\u06AF\u0632\u06CC\u0646\u2026",
214
+ mediaEmpty: "\u062A\u0635\u0648\u06CC\u0631\u06CC \u06CC\u0627\u0641\u062A \u0646\u0634\u062F. \u06CC\u06A9 \u062A\u0635\u0648\u06CC\u0631 \u0622\u067E\u0644\u0648\u062F \u06A9\u0646\u06CC\u062F.",
215
+ mediaUpload: "\u0627\u0646\u062A\u062E\u0627\u0628 \u062A\u0635\u0648\u06CC\u0631",
216
+ mediaSelect: "\u0627\u0646\u062A\u062E\u0627\u0628",
217
+ mediaPrevPage: "\u0635\u0641\u062D\u0647\u200C\u06CC \u0642\u0628\u0644",
218
+ mediaNextPage: "\u0635\u0641\u062D\u0647\u200C\u06CC \u0628\u0639\u062F",
219
+ mediaLoadFailed: "\u062F\u0631\u06CC\u0627\u0641\u062A \u062A\u0635\u0627\u0648\u06CC\u0631 \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0648\u062F.",
220
+ mediaUploadFailed: "\u0622\u067E\u0644\u0648\u062F \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0648\u062F. \u062F\u0648\u0628\u0627\u0631\u0647 \u062A\u0644\u0627\u0634 \u06A9\u0646\u06CC\u062F."
221
+ };
222
+ var LabelsContext = createContext(defaultLabels);
223
+ var useLabels = () => useContext(LabelsContext);
224
+
225
+ // src/editor/toolbar.tsx
226
+ import * as React6 from "react";
227
+ import { useEditorState } from "@tiptap/react";
228
+ import {
229
+ AlignCenter,
230
+ AlignJustify,
231
+ AlignLeft,
232
+ AlignRight,
233
+ Bold,
234
+ Code2,
235
+ Heading2,
236
+ Heading3,
237
+ Heading4,
238
+ Highlighter,
239
+ ImagePlus as ImagePlus2,
240
+ Italic,
241
+ Link2,
242
+ Link2Off,
243
+ List,
244
+ ListOrdered,
245
+ Minus,
246
+ Palette,
247
+ Quote,
248
+ Redo2,
249
+ Strikethrough,
250
+ Table2,
251
+ Underline,
252
+ Undo2,
253
+ Video
254
+ } from "lucide-react";
255
+
256
+ // src/editor/ui/index.tsx
257
+ import * as React from "react";
258
+ import { createPortal } from "react-dom";
259
+ import { jsx, jsxs } from "react/jsx-runtime";
260
+ var ClassNamesContext = React.createContext({});
261
+ var useClassNames = () => React.useContext(ClassNamesContext);
262
+ var cx = (...parts) => parts.filter(Boolean).join(" ");
263
+ function Button({ variant = "ghost", size = "md", pressed, className, type = "button", ...rest }) {
264
+ const slots = useClassNames();
265
+ return /* @__PURE__ */ jsx(
266
+ "button",
267
+ {
268
+ type,
269
+ className: cx("bk-btn", `bk-btn-${variant}`, `bk-btn-${size}`, pressed && "bk-pressed", slots.button, className),
270
+ ...rest
271
+ }
272
+ );
273
+ }
274
+ function Input(props) {
275
+ const slots = useClassNames();
276
+ return /* @__PURE__ */ jsx("input", { ...props, className: cx("bk-input", slots.input, props.className) });
277
+ }
278
+ function Label(props) {
279
+ const slots = useClassNames();
280
+ return /* @__PURE__ */ jsx("label", { ...props, className: cx("bk-label", slots.label, props.className) });
281
+ }
282
+ function Dialog({ open, ...rest }) {
283
+ if (!open || typeof document === "undefined") return null;
284
+ return createPortal(/* @__PURE__ */ jsx(DialogShell, { ...rest }), document.body);
285
+ }
286
+ function DialogShell({ onClose, title, dir, wide, children }) {
287
+ const ref = React.useRef(null);
288
+ const slots = useClassNames();
289
+ React.useEffect(() => {
290
+ const dialog = ref.current;
291
+ if (dialog && !dialog.open) dialog.showModal();
292
+ }, []);
293
+ return /* @__PURE__ */ jsx(
294
+ "dialog",
295
+ {
296
+ ref,
297
+ dir,
298
+ "aria-label": title,
299
+ className: cx("bk-dialog", wide && "bk-dialog-wide", slots.dialog),
300
+ onClose,
301
+ onClick: (event) => {
302
+ if (event.target === event.currentTarget) onClose();
303
+ },
304
+ children: /* @__PURE__ */ jsx("div", { className: "bk-dialog-body", children })
305
+ }
306
+ );
307
+ }
308
+ function Popover({ trigger, children }) {
309
+ const [open, setOpen] = React.useState(false);
310
+ const ref = React.useRef(null);
311
+ const slots = useClassNames();
312
+ React.useEffect(() => {
313
+ if (!open) return;
314
+ const onDown = (event) => {
315
+ if (!ref.current?.contains(event.target)) setOpen(false);
316
+ };
317
+ const onKey = (event) => event.key === "Escape" && setOpen(false);
318
+ document.addEventListener("mousedown", onDown);
319
+ document.addEventListener("keydown", onKey);
320
+ return () => {
321
+ document.removeEventListener("mousedown", onDown);
322
+ document.removeEventListener("keydown", onKey);
323
+ };
324
+ }, [open]);
325
+ return /* @__PURE__ */ jsxs("span", { ref, className: "bk-popover", children: [
326
+ trigger({ onClick: () => setOpen((value) => !value), open }),
327
+ open ? /* @__PURE__ */ jsx("div", { className: cx("bk-popover-content", slots.popover), children }) : null
328
+ ] });
329
+ }
330
+
331
+ // src/editor/color-menu.tsx
332
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
333
+ var TEXT_COLORS = ["#1c1c1c", "#997b2d", "#b91c1c", "#15803d", "#1d4ed8", "#7e22ce"];
334
+ var HIGHLIGHT_COLORS = ["#fde68a", "#bbf7d0", "#bfdbfe", "#fecaca", "#e9d5ff"];
335
+ var MODES = {
336
+ text: {
337
+ label: "textColor",
338
+ colors: TEXT_COLORS,
339
+ apply: (editor, color) => editor.chain().focus().setColor(color).run(),
340
+ clear: (editor) => editor.chain().focus().unsetColor().run()
341
+ },
342
+ highlight: {
343
+ label: "highlight",
344
+ colors: HIGHLIGHT_COLORS,
345
+ apply: (editor, color) => editor.chain().focus().setHighlight({ color }).run(),
346
+ clear: (editor) => editor.chain().focus().unsetHighlight().run()
347
+ }
348
+ };
349
+ function ColorMenu({ editor, mode, icon: Icon, active }) {
350
+ const labels = useLabels();
351
+ const config = MODES[mode];
352
+ const label = labels[config.label];
353
+ return /* @__PURE__ */ jsx2(
354
+ Popover,
355
+ {
356
+ trigger: ({ onClick, open }) => /* @__PURE__ */ jsx2(
357
+ Button,
358
+ {
359
+ size: "icon",
360
+ pressed: active,
361
+ "aria-label": label,
362
+ title: label,
363
+ "aria-pressed": active,
364
+ "aria-expanded": open,
365
+ onMouseDown: (event) => event.preventDefault(),
366
+ onClick,
367
+ children: /* @__PURE__ */ jsx2(Icon, { size: 16 })
368
+ }
369
+ ),
370
+ children: /* @__PURE__ */ jsxs2("div", { className: "bk-colors", children: [
371
+ config.colors.map((color) => /* @__PURE__ */ jsx2(
372
+ "button",
373
+ {
374
+ type: "button",
375
+ className: "bk-swatch",
376
+ style: { backgroundColor: color },
377
+ "aria-label": `${label} ${color}`,
378
+ title: color,
379
+ onMouseDown: (event) => event.preventDefault(),
380
+ onClick: () => config.apply(editor, color)
381
+ },
382
+ color
383
+ )),
384
+ /* @__PURE__ */ jsx2(Button, { size: "sm", onMouseDown: (event) => event.preventDefault(), onClick: () => config.clear(editor), children: labels.remove })
385
+ ] })
386
+ }
387
+ );
388
+ }
389
+
390
+ // src/editor/image-dialog.tsx
391
+ import * as React4 from "react";
392
+ import { ImagePlus, Images, Loader2 } from "lucide-react";
393
+
394
+ // src/editor/media/media-picker.tsx
395
+ import * as React3 from "react";
396
+ import { ChevronLeft, ChevronRight, X } from "lucide-react";
397
+
398
+ // src/editor/media/media-grid.tsx
399
+ import { Check } from "lucide-react";
400
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
401
+ function MediaGrid({ items, selectedId, onSelect }) {
402
+ const labels = useLabels();
403
+ if (!items.length) return /* @__PURE__ */ jsx3("div", { className: "bk-media-empty", children: labels.mediaEmpty });
404
+ return /* @__PURE__ */ jsx3("ul", { className: "bk-media-grid", children: items.map((item) => {
405
+ const selected = item.id === selectedId;
406
+ const thumb = item.variants["320"];
407
+ return /* @__PURE__ */ jsx3("li", { children: /* @__PURE__ */ jsxs3(
408
+ "button",
409
+ {
410
+ type: "button",
411
+ "aria-pressed": selected,
412
+ title: item.originalName,
413
+ onClick: () => onSelect(item),
414
+ className: cx("bk-media-item", selected && "bk-selected"),
415
+ children: [
416
+ /* @__PURE__ */ jsx3("img", { src: thumb?.url ?? item.url, alt: item.alt ?? item.originalName, loading: "lazy" }),
417
+ selected ? /* @__PURE__ */ jsx3("span", { className: "bk-media-check", children: /* @__PURE__ */ jsx3(Check, { size: 16 }) }) : null
418
+ ]
419
+ }
420
+ ) }, item.id);
421
+ }) });
422
+ }
423
+
424
+ // src/editor/media/media-upload-button.tsx
425
+ import * as React2 from "react";
426
+ import { UploadCloud } from "lucide-react";
427
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
428
+ function MediaUploadButton({ api, onUploaded }) {
429
+ const labels = useLabels();
430
+ const inputRef = React2.useRef(null);
431
+ const [busy, setBusy] = React2.useState(false);
432
+ const [error, setError] = React2.useState(null);
433
+ const handleChange = async (event) => {
434
+ const file = event.target.files?.[0];
435
+ event.target.value = "";
436
+ if (!file) return;
437
+ const formData = new FormData();
438
+ formData.append("file", file);
439
+ setBusy(true);
440
+ setError(null);
441
+ try {
442
+ const result = await api.upload(formData);
443
+ const item = result.items[0];
444
+ if (result.error || !item) setError(result.error ?? labels.mediaUploadFailed);
445
+ else onUploaded(item);
446
+ } catch {
447
+ setError(labels.mediaUploadFailed);
448
+ } finally {
449
+ setBusy(false);
450
+ }
451
+ };
452
+ return /* @__PURE__ */ jsxs4("div", { className: "bk-media-upload", children: [
453
+ /* @__PURE__ */ jsx4(
454
+ "input",
455
+ {
456
+ ref: inputRef,
457
+ type: "file",
458
+ className: "bk-sr-only",
459
+ tabIndex: -1,
460
+ accept: "image/jpeg,image/png,image/webp,image/gif",
461
+ onChange: handleChange
462
+ }
463
+ ),
464
+ /* @__PURE__ */ jsxs4(Button, { variant: "outline", size: "sm", disabled: busy, onClick: () => inputRef.current?.click(), children: [
465
+ /* @__PURE__ */ jsx4(UploadCloud, { size: 16 }),
466
+ busy ? labels.imageUploading : labels.mediaUpload
467
+ ] }),
468
+ error ? /* @__PURE__ */ jsx4("p", { role: "alert", className: "bk-error", children: error }) : null
469
+ ] });
470
+ }
471
+
472
+ // src/editor/media/media-picker.tsx
473
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
474
+ var toPicked = (item) => ({ url: item.url, alt: item.alt ?? void 0 });
475
+ function MediaPicker({ api, dir, onSelect, onClose }) {
476
+ const labels = useLabels();
477
+ const [q, setQ] = React3.useState("");
478
+ const [debouncedQ, setDebouncedQ] = React3.useState("");
479
+ const [page, setPage] = React3.useState(1);
480
+ const [data, setData] = React3.useState({ items: [], total: 0, pageSize: 24 });
481
+ const [error, setError] = React3.useState(null);
482
+ const [loading, setLoading] = React3.useState(false);
483
+ const [selected, setSelected] = React3.useState(null);
484
+ const requestId = React3.useRef(0);
485
+ React3.useEffect(() => {
486
+ const timer = setTimeout(() => {
487
+ setDebouncedQ(q.trim());
488
+ setPage(1);
489
+ }, 250);
490
+ return () => clearTimeout(timer);
491
+ }, [q]);
492
+ React3.useEffect(() => {
493
+ const id = ++requestId.current;
494
+ setLoading(true);
495
+ api.list({ q: debouncedQ || void 0, page }).then((result) => {
496
+ if (id !== requestId.current) return;
497
+ if (result.error) setError(result.error);
498
+ else {
499
+ setError(null);
500
+ setData({ items: result.items, total: result.total, pageSize: result.pageSize || 24 });
501
+ }
502
+ }).catch(() => id === requestId.current && setError(labels.mediaLoadFailed)).finally(() => id === requestId.current && setLoading(false));
503
+ }, [api, debouncedQ, page, labels.mediaLoadFailed]);
504
+ const pageCount = Math.max(1, Math.ceil(data.total / data.pageSize));
505
+ const Prev = dir === "ltr" ? ChevronLeft : ChevronRight;
506
+ const Next = dir === "ltr" ? ChevronRight : ChevronLeft;
507
+ return /* @__PURE__ */ jsxs5(Dialog, { open: true, onClose, title: labels.mediaTitle, dir, wide: true, children: [
508
+ /* @__PURE__ */ jsxs5("header", { className: "bk-dialog-header", children: [
509
+ /* @__PURE__ */ jsx5("h2", { children: labels.mediaTitle }),
510
+ /* @__PURE__ */ jsx5(Button, { size: "icon", "aria-label": labels.close, onClick: onClose, children: /* @__PURE__ */ jsx5(X, { size: 16 }) })
511
+ ] }),
512
+ /* @__PURE__ */ jsxs5("div", { className: "bk-media-toolbar", children: [
513
+ /* @__PURE__ */ jsx5(
514
+ Input,
515
+ {
516
+ value: q,
517
+ onChange: (event) => setQ(event.target.value),
518
+ placeholder: labels.mediaSearchPlaceholder,
519
+ "aria-label": labels.mediaSearch
520
+ }
521
+ ),
522
+ /* @__PURE__ */ jsx5(MediaUploadButton, { api, onUploaded: (item) => onSelect(toPicked(item)) })
523
+ ] }),
524
+ /* @__PURE__ */ jsx5("div", { className: "bk-media-body", "aria-busy": loading, children: error ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "bk-error", children: error }) : /* @__PURE__ */ jsx5(MediaGrid, { items: data.items, selectedId: selected?.id ?? null, onSelect: setSelected }) }),
525
+ /* @__PURE__ */ jsxs5("footer", { className: "bk-dialog-footer bk-media-footer", children: [
526
+ /* @__PURE__ */ jsxs5("div", { className: "bk-pager", children: [
527
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", size: "icon", "aria-label": labels.mediaPrevPage, disabled: page <= 1, onClick: () => setPage(page - 1), children: /* @__PURE__ */ jsx5(Prev, { size: 16 }) }),
528
+ /* @__PURE__ */ jsxs5("span", { children: [
529
+ page,
530
+ " / ",
531
+ pageCount
532
+ ] }),
533
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", size: "icon", "aria-label": labels.mediaNextPage, disabled: page >= pageCount, onClick: () => setPage(page + 1), children: /* @__PURE__ */ jsx5(Next, { size: 16 }) })
534
+ ] }),
535
+ /* @__PURE__ */ jsxs5("div", { className: "bk-actions", children: [
536
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
537
+ /* @__PURE__ */ jsx5(Button, { variant: "primary", disabled: !selected, onClick: () => selected && onSelect(toPicked(selected)), children: labels.mediaSelect })
538
+ ] })
539
+ ] })
540
+ ] });
541
+ }
542
+
543
+ // src/editor/image-dialog.tsx
544
+ import { Fragment, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
545
+ var isHttps = (value) => /^https:\/\/\S+$/i.test(value);
546
+ function ImageDialog({ open, onOpenChange, dir, ...form }) {
547
+ const labels = useLabels();
548
+ return /* @__PURE__ */ jsx6(Dialog, { open, onClose: () => onOpenChange(false), title: labels.imageTitle, dir, children: /* @__PURE__ */ jsx6(ImageForm, { ...form, dir, onClose: () => onOpenChange(false) }) });
549
+ }
550
+ function ImageForm({
551
+ onSubmit,
552
+ onClose,
553
+ dir,
554
+ uploadImage,
555
+ mediaApi,
556
+ renderMediaPicker,
557
+ resolveImageSrc
558
+ }) {
559
+ const labels = useLabels();
560
+ const id = React4.useId();
561
+ const fileRef = React4.useRef(null);
562
+ const [src, setSrc] = React4.useState("");
563
+ const [alt, setAlt] = React4.useState("");
564
+ const [error, setError] = React4.useState(null);
565
+ const [uploading, setUploading] = React4.useState(false);
566
+ const [pickerOpen, setPickerOpen] = React4.useState(false);
567
+ const applyPicked = (image) => {
568
+ const url = resolveImageSrc ? resolveImageSrc(image.url) : image.url;
569
+ if (!isHttps(url)) {
570
+ setError(labels.imageHttpsError);
571
+ return false;
572
+ }
573
+ setError(null);
574
+ setSrc(url);
575
+ if (image.alt && !alt) setAlt(image.alt);
576
+ return true;
577
+ };
578
+ const handleFile = async (event) => {
579
+ const file = event.target.files?.[0];
580
+ event.target.value = "";
581
+ if (!file || !uploadImage) return;
582
+ setUploading(true);
583
+ setError(null);
584
+ try {
585
+ applyPicked(await uploadImage(file));
586
+ } catch (e) {
587
+ setError(e instanceof Error && e.message ? e.message : labels.imageUploadFailed);
588
+ } finally {
589
+ setUploading(false);
590
+ }
591
+ };
592
+ const submit = (event) => {
593
+ event.preventDefault();
594
+ event.stopPropagation();
595
+ const value = src.trim();
596
+ if (!isHttps(value)) {
597
+ setError(labels.imageHttpsError);
598
+ return;
599
+ }
600
+ onSubmit({ src: value, alt: alt.trim() });
601
+ onClose();
602
+ };
603
+ const hasLibrary = Boolean(renderMediaPicker || mediaApi);
604
+ const closePicker = () => setPickerOpen(false);
605
+ const onPicked = (image) => {
606
+ if (applyPicked(image)) closePicker();
607
+ };
608
+ return /* @__PURE__ */ jsxs6(Fragment, { children: [
609
+ /* @__PURE__ */ jsxs6("form", { onSubmit: submit, className: "bk-form", children: [
610
+ /* @__PURE__ */ jsx6("h2", { className: "bk-dialog-title", children: labels.imageTitle }),
611
+ uploadImage || hasLibrary ? /* @__PURE__ */ jsxs6("div", { className: "bk-actions bk-actions-start", children: [
612
+ uploadImage ? /* @__PURE__ */ jsxs6(Fragment, { children: [
613
+ /* @__PURE__ */ jsx6("input", { ref: fileRef, type: "file", accept: "image/*", className: "bk-sr-only", tabIndex: -1, onChange: handleFile }),
614
+ /* @__PURE__ */ jsxs6(Button, { variant: "outline", size: "sm", disabled: uploading, onClick: () => fileRef.current?.click(), children: [
615
+ uploading ? /* @__PURE__ */ jsx6(Loader2, { size: 16, className: "bk-spin" }) : /* @__PURE__ */ jsx6(ImagePlus, { size: 16 }),
616
+ uploading ? labels.imageUploading : labels.imageUpload
617
+ ] })
618
+ ] }) : null,
619
+ hasLibrary ? /* @__PURE__ */ jsxs6(Button, { variant: "outline", size: "sm", onClick: () => setPickerOpen(true), children: [
620
+ /* @__PURE__ */ jsx6(Images, { size: 16 }),
621
+ labels.imageLibrary
622
+ ] }) : null
623
+ ] }) : null,
624
+ /* @__PURE__ */ jsxs6("div", { className: "bk-field", children: [
625
+ /* @__PURE__ */ jsx6(Label, { htmlFor: `${id}-src`, children: labels.imageUrl }),
626
+ /* @__PURE__ */ jsx6(
627
+ Input,
628
+ {
629
+ id: `${id}-src`,
630
+ dir: "ltr",
631
+ value: src,
632
+ placeholder: labels.imageUrlPlaceholder,
633
+ onChange: (event) => setSrc(event.target.value)
634
+ }
635
+ )
636
+ ] }),
637
+ src && isHttps(src) ? (
638
+ // eslint-disable-next-line @next/next/no-img-element
639
+ /* @__PURE__ */ jsx6("img", { src, alt: "", className: "bk-image-preview" })
640
+ ) : null,
641
+ /* @__PURE__ */ jsxs6("div", { className: "bk-field", children: [
642
+ /* @__PURE__ */ jsx6(Label, { htmlFor: `${id}-alt`, children: labels.imageAlt }),
643
+ /* @__PURE__ */ jsx6(Input, { id: `${id}-alt`, value: alt, onChange: (event) => setAlt(event.target.value) })
644
+ ] }),
645
+ error ? /* @__PURE__ */ jsx6("p", { role: "alert", className: "bk-error", children: error }) : null,
646
+ /* @__PURE__ */ jsxs6("div", { className: "bk-dialog-footer", children: [
647
+ /* @__PURE__ */ jsx6(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
648
+ /* @__PURE__ */ jsx6(Button, { variant: "primary", type: "submit", disabled: !src.trim() || uploading, children: labels.imageInsert })
649
+ ] })
650
+ ] }),
651
+ pickerOpen ? renderMediaPicker ? renderMediaPicker({ onSelect: onPicked, close: closePicker }) : mediaApi ? /* @__PURE__ */ jsx6(MediaPicker, { api: mediaApi, dir, onSelect: onPicked, onClose: closePicker }) : null : null
652
+ ] });
653
+ }
654
+
655
+ // src/editor/url-dialog.tsx
656
+ import * as React5 from "react";
657
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
658
+ function UrlDialog({ open, onOpenChange, ...form }) {
659
+ return /* @__PURE__ */ jsx7(Dialog, { open, onClose: () => onOpenChange(false), title: form.title, dir: form.dir, children: /* @__PURE__ */ jsx7(UrlForm, { ...form, onClose: () => onOpenChange(false) }) });
660
+ }
661
+ function UrlForm({
662
+ title,
663
+ label,
664
+ placeholder,
665
+ initialValue = "",
666
+ errorMessage,
667
+ parse,
668
+ onSubmit,
669
+ onClose
670
+ }) {
671
+ const labels = useLabels();
672
+ const id = React5.useId();
673
+ const [value, setValue] = React5.useState(initialValue);
674
+ const [error, setError] = React5.useState(null);
675
+ const submit = (event) => {
676
+ event.preventDefault();
677
+ event.stopPropagation();
678
+ const url = parse(value);
679
+ if (!url) {
680
+ setError(errorMessage);
681
+ return;
682
+ }
683
+ onSubmit(url);
684
+ onClose();
685
+ };
686
+ return /* @__PURE__ */ jsxs7("form", { onSubmit: submit, className: "bk-form", children: [
687
+ /* @__PURE__ */ jsx7("h2", { className: "bk-dialog-title", children: title }),
688
+ /* @__PURE__ */ jsxs7("div", { className: "bk-field", children: [
689
+ /* @__PURE__ */ jsx7(Label, { htmlFor: id, children: label }),
690
+ /* @__PURE__ */ jsx7(
691
+ Input,
692
+ {
693
+ id,
694
+ dir: "ltr",
695
+ value,
696
+ placeholder,
697
+ onChange: (event) => setValue(event.target.value),
698
+ autoFocus: true
699
+ }
700
+ ),
701
+ error ? /* @__PURE__ */ jsx7("p", { role: "alert", className: "bk-error", children: error }) : null
702
+ ] }),
703
+ /* @__PURE__ */ jsxs7("div", { className: "bk-dialog-footer", children: [
704
+ /* @__PURE__ */ jsx7(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
705
+ /* @__PURE__ */ jsx7(Button, { variant: "primary", type: "submit", children: labels.insert })
706
+ ] })
707
+ ] });
708
+ }
709
+
710
+ // src/editor/toolbar.tsx
711
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
712
+ var chain = (editor) => editor.chain().focus();
713
+ var GROUPS = [
714
+ [
715
+ { key: "bold", icon: Bold, label: "bold", isActive: (e) => e.isActive("bold"), run: (e) => chain(e).toggleBold().run() },
716
+ { key: "italic", icon: Italic, label: "italic", isActive: (e) => e.isActive("italic"), run: (e) => chain(e).toggleItalic().run() },
717
+ { key: "underline", icon: Underline, label: "underline", isActive: (e) => e.isActive("underline"), run: (e) => chain(e).toggleUnderline().run() },
718
+ { key: "strike", icon: Strikethrough, label: "strike", isActive: (e) => e.isActive("strike"), run: (e) => chain(e).toggleStrike().run() }
719
+ ],
720
+ [
721
+ { key: "h2", icon: Heading2, label: "h2", isActive: (e) => e.isActive("heading", { level: 2 }), run: (e) => chain(e).toggleHeading({ level: 2 }).run() },
722
+ { key: "h3", icon: Heading3, label: "h3", isActive: (e) => e.isActive("heading", { level: 3 }), run: (e) => chain(e).toggleHeading({ level: 3 }).run() },
723
+ { key: "h4", icon: Heading4, label: "h4", isActive: (e) => e.isActive("heading", { level: 4 }), run: (e) => chain(e).toggleHeading({ level: 4 }).run() }
724
+ ],
725
+ [
726
+ { key: "right", icon: AlignRight, label: "alignRight", isActive: (e) => e.isActive({ textAlign: "right" }), run: (e) => chain(e).setTextAlign("right").run() },
727
+ { key: "center", icon: AlignCenter, label: "alignCenter", isActive: (e) => e.isActive({ textAlign: "center" }), run: (e) => chain(e).setTextAlign("center").run() },
728
+ { key: "left", icon: AlignLeft, label: "alignLeft", isActive: (e) => e.isActive({ textAlign: "left" }), run: (e) => chain(e).setTextAlign("left").run() },
729
+ { key: "justify", icon: AlignJustify, label: "alignJustify", isActive: (e) => e.isActive({ textAlign: "justify" }), run: (e) => chain(e).setTextAlign("justify").run() }
730
+ ],
731
+ [
732
+ { key: "bullet", icon: List, label: "bulletList", isActive: (e) => e.isActive("bulletList"), run: (e) => chain(e).toggleBulletList().run() },
733
+ { key: "ordered", icon: ListOrdered, label: "orderedList", isActive: (e) => e.isActive("orderedList"), run: (e) => chain(e).toggleOrderedList().run() },
734
+ { key: "quote", icon: Quote, label: "quote", isActive: (e) => e.isActive("blockquote"), run: (e) => chain(e).toggleBlockquote().run() },
735
+ { key: "code", icon: Code2, label: "codeBlock", isActive: (e) => e.isActive("codeBlock"), run: (e) => chain(e).toggleCodeBlock().run() },
736
+ { key: "hr", icon: Minus, label: "hr", run: (e) => chain(e).setHorizontalRule().run() }
737
+ ],
738
+ [
739
+ { key: "link", icon: Link2, label: "link", isActive: (e) => e.isActive("link"), run: (_e, open) => open("link") },
740
+ { key: "unlink", icon: Link2Off, label: "unlink", isDisabled: (e) => !e.isActive("link"), run: (e) => chain(e).extendMarkRange("link").unsetLink().run() },
741
+ { key: "image", icon: ImagePlus2, label: "image", run: (_e, open) => open("image") },
742
+ { key: "video", icon: Video, label: "video", run: (_e, open) => open("video") },
743
+ { key: "table", icon: Table2, label: "table", isActive: (e) => e.isActive("table"), run: (e) => chain(e).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() }
744
+ ],
745
+ [
746
+ { key: "undo", icon: Undo2, label: "undo", isDisabled: (e) => !e.can().undo(), run: (e) => chain(e).undo().run() },
747
+ { key: "redo", icon: Redo2, label: "redo", isDisabled: (e) => !e.can().redo(), run: (e) => chain(e).redo().run() }
748
+ ]
749
+ ];
750
+ var TABLE_ACTIONS = [
751
+ { key: "row-after", label: "addRow", run: (e) => chain(e).addRowAfter().run() },
752
+ { key: "col-after", label: "addColumn", run: (e) => chain(e).addColumnAfter().run() },
753
+ { key: "row-delete", label: "deleteRow", run: (e) => chain(e).deleteRow().run() },
754
+ { key: "col-delete", label: "deleteColumn", run: (e) => chain(e).deleteColumn().run() },
755
+ { key: "table-delete", label: "deleteTable", run: (e) => chain(e).deleteTable().run() }
756
+ ];
757
+ var ALL_BUTTONS = GROUPS.flat();
758
+ var BUTTONS_BY_KEY = new Map(ALL_BUTTONS.map((b) => [b.key, b]));
759
+ var defaultToolbar = [
760
+ "bold",
761
+ "italic",
762
+ "underline",
763
+ "strike",
764
+ "textColor",
765
+ "highlight",
766
+ "|",
767
+ "h2",
768
+ "h3",
769
+ "h4",
770
+ "|",
771
+ "right",
772
+ "center",
773
+ "left",
774
+ "justify",
775
+ "|",
776
+ "bullet",
777
+ "ordered",
778
+ "quote",
779
+ "code",
780
+ "hr",
781
+ "|",
782
+ "link",
783
+ "unlink",
784
+ "image",
785
+ "video",
786
+ "table",
787
+ "|",
788
+ "undo",
789
+ "redo"
790
+ ];
791
+ function normalizeItems(items) {
792
+ const out = [];
793
+ for (const item of items) {
794
+ const valid = item === "|" || item === "textColor" || item === "highlight" || BUTTONS_BY_KEY.has(item);
795
+ if (!valid || item === "|" && (out.length === 0 || out[out.length - 1] === "|")) continue;
796
+ out.push(item);
797
+ }
798
+ while (out[out.length - 1] === "|") out.pop();
799
+ return out;
800
+ }
801
+ function RichTextToolbar({ editor, items = defaultToolbar, dir, allowedEmbeds, ...imageProps }) {
802
+ const labels = useLabels();
803
+ const slots = useClassNames();
804
+ const entries = React6.useMemo(() => normalizeItems(items), [items]);
805
+ const [dialog, setDialog] = React6.useState(null);
806
+ const state = useEditorState({
807
+ editor,
808
+ selector: ({ editor: e }) => ({
809
+ active: Object.fromEntries(ALL_BUTTONS.map((b) => [b.key, b.isActive?.(e) ?? false])),
810
+ disabled: Object.fromEntries(ALL_BUTTONS.map((b) => [b.key, b.isDisabled?.(e) ?? false])),
811
+ color: e.isActive("textStyle", { color: /.+/ }),
812
+ highlight: e.isActive("highlight"),
813
+ inTable: e.isActive("table"),
814
+ href: e.getAttributes("link").href ?? ""
815
+ })
816
+ });
817
+ const closeDialog = (open) => !open && setDialog(null);
818
+ return /* @__PURE__ */ jsxs8("div", { className: cx("bk-toolbar", slots.toolbar), children: [
819
+ entries.map((item, index) => {
820
+ if (item === "|") return /* @__PURE__ */ jsx8("span", { className: cx("bk-sep", slots.separator), "aria-hidden": true }, `sep-${index}`);
821
+ if (item === "textColor") return /* @__PURE__ */ jsx8(ColorMenu, { editor, mode: "text", icon: Palette, active: state.color }, item);
822
+ if (item === "highlight") return /* @__PURE__ */ jsx8(ColorMenu, { editor, mode: "highlight", icon: Highlighter, active: state.highlight }, item);
823
+ const button = BUTTONS_BY_KEY.get(item);
824
+ const label = labels[button.label];
825
+ const active = state.active[button.key] ?? false;
826
+ return /* @__PURE__ */ jsx8(
827
+ Button,
828
+ {
829
+ size: "icon",
830
+ pressed: active,
831
+ "aria-label": label,
832
+ title: label,
833
+ "aria-pressed": button.isActive ? active : void 0,
834
+ disabled: state.disabled[button.key],
835
+ onMouseDown: (event) => event.preventDefault(),
836
+ onClick: () => button.run(editor, setDialog),
837
+ children: /* @__PURE__ */ jsx8(button.icon, { size: 16 })
838
+ },
839
+ button.key
840
+ );
841
+ }),
842
+ state.inTable ? /* @__PURE__ */ jsx8("div", { className: cx("bk-table-tools", slots.tableTools), children: TABLE_ACTIONS.map((action) => /* @__PURE__ */ jsx8(Button, { variant: "outline", size: "sm", onMouseDown: (event) => event.preventDefault(), onClick: () => action.run(editor), children: labels[action.label] }, action.key)) }) : null,
843
+ /* @__PURE__ */ jsx8(
844
+ UrlDialog,
845
+ {
846
+ open: dialog === "link",
847
+ onOpenChange: closeDialog,
848
+ dir,
849
+ title: labels.linkTitle,
850
+ label: labels.linkField,
851
+ placeholder: labels.linkPlaceholder,
852
+ initialValue: state.href,
853
+ errorMessage: labels.linkError,
854
+ parse: normalizeLinkUrl,
855
+ onSubmit: (href) => chain(editor).extendMarkRange("link").setLink({ href }).run()
856
+ }
857
+ ),
858
+ /* @__PURE__ */ jsx8(
859
+ UrlDialog,
860
+ {
861
+ open: dialog === "video",
862
+ onOpenChange: closeDialog,
863
+ dir,
864
+ title: labels.videoTitle,
865
+ label: labels.videoField,
866
+ placeholder: labels.videoPlaceholder,
867
+ errorMessage: labels.videoError,
868
+ parse: (value) => toVideoEmbedUrl(value, allowedEmbeds),
869
+ onSubmit: (src) => chain(editor).insertContent({ type: "videoEmbed", attrs: { src } }).run()
870
+ }
871
+ ),
872
+ /* @__PURE__ */ jsx8(
873
+ ImageDialog,
874
+ {
875
+ ...imageProps,
876
+ dir,
877
+ open: dialog === "image",
878
+ onOpenChange: closeDialog,
879
+ onSubmit: (image) => chain(editor).setImage(image).run()
880
+ }
881
+ )
882
+ ] });
883
+ }
884
+
885
+ // src/editor/rich-text-editor.tsx
886
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
887
+ var EMPTY = {};
888
+ function RichTextEditor({
889
+ value,
890
+ onChange,
891
+ placeholder,
892
+ invalid,
893
+ id,
894
+ className,
895
+ classNames,
896
+ toolbar,
897
+ uploadImage,
898
+ mediaApi,
899
+ renderMediaPicker,
900
+ resolveImageSrc,
901
+ allowedEmbeds = ALL_EMBED_PROVIDERS,
902
+ labels,
903
+ dir = "rtl"
904
+ }) {
905
+ const merged = React7.useMemo(() => ({ ...defaultLabels, ...labels }), [labels]);
906
+ const onChangeRef = React7.useRef(onChange);
907
+ onChangeRef.current = onChange;
908
+ const editor = useEditor({
909
+ extensions: buildEditorExtensions(placeholder ?? merged.placeholder, allowedEmbeds, dir),
910
+ content: value,
911
+ immediatelyRender: false,
912
+ // SSR-safe
913
+ editorProps: {
914
+ attributes: { class: cx("bk-rich bk-editor-content", classNames?.content), dir, ...id ? { id } : {} }
915
+ },
916
+ onUpdate: ({ editor: e }) => onChangeRef.current(e.isEmpty ? "" : e.getHTML())
917
+ });
918
+ React7.useEffect(() => {
919
+ if (!editor) return;
920
+ const current = editor.isEmpty ? "" : editor.getHTML();
921
+ if (value !== current) editor.commands.setContent(value, { emitUpdate: false });
922
+ }, [editor, value]);
923
+ return /* @__PURE__ */ jsx9(LabelsContext.Provider, { value: merged, children: /* @__PURE__ */ jsx9(ClassNamesContext.Provider, { value: classNames ?? EMPTY, children: /* @__PURE__ */ jsxs9("div", { className: cx("bk-editor", invalid && "bk-invalid", classNames?.root, className), dir, children: [
924
+ editor ? /* @__PURE__ */ jsx9(
925
+ RichTextToolbar,
926
+ {
927
+ editor,
928
+ dir,
929
+ items: toolbar,
930
+ allowedEmbeds,
931
+ uploadImage,
932
+ mediaApi,
933
+ renderMediaPicker,
934
+ resolveImageSrc
935
+ }
936
+ ) : null,
937
+ /* @__PURE__ */ jsx9(EditorContent, { editor })
938
+ ] }) }) });
939
+ }
940
+ export {
941
+ RichTextEditor,
942
+ defaultLabels,
943
+ defaultToolbar,
944
+ isAllowedEmbedSrc,
945
+ normalizeLinkUrl,
946
+ toVideoEmbedUrl
947
+ };
948
+ //# sourceMappingURL=index.js.map