@ilamanownuk/blog-kit 0.0.0-stage → 0.1.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,894 @@
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 cx = (...parts) => parts.filter(Boolean).join(" ");
261
+ function Button({ variant = "ghost", size = "md", pressed, className, type = "button", ...rest }) {
262
+ return /* @__PURE__ */ jsx(
263
+ "button",
264
+ {
265
+ type,
266
+ className: cx("bk-btn", `bk-btn-${variant}`, `bk-btn-${size}`, pressed && "bk-pressed", className),
267
+ ...rest
268
+ }
269
+ );
270
+ }
271
+ function Input(props) {
272
+ return /* @__PURE__ */ jsx("input", { ...props, className: cx("bk-input", props.className) });
273
+ }
274
+ function Label(props) {
275
+ return /* @__PURE__ */ jsx("label", { ...props, className: cx("bk-label", props.className) });
276
+ }
277
+ function Dialog({ open, ...rest }) {
278
+ if (!open || typeof document === "undefined") return null;
279
+ return createPortal(/* @__PURE__ */ jsx(DialogShell, { ...rest }), document.body);
280
+ }
281
+ function DialogShell({ onClose, title, dir, wide, children }) {
282
+ const ref = React.useRef(null);
283
+ React.useEffect(() => {
284
+ const dialog = ref.current;
285
+ if (dialog && !dialog.open) dialog.showModal();
286
+ }, []);
287
+ return /* @__PURE__ */ jsx(
288
+ "dialog",
289
+ {
290
+ ref,
291
+ dir,
292
+ "aria-label": title,
293
+ className: cx("bk-dialog", wide && "bk-dialog-wide"),
294
+ onClose,
295
+ onClick: (event) => {
296
+ if (event.target === event.currentTarget) onClose();
297
+ },
298
+ children: /* @__PURE__ */ jsx("div", { className: "bk-dialog-body", children })
299
+ }
300
+ );
301
+ }
302
+ function Popover({ trigger, children }) {
303
+ const [open, setOpen] = React.useState(false);
304
+ const ref = React.useRef(null);
305
+ React.useEffect(() => {
306
+ if (!open) return;
307
+ const onDown = (event) => {
308
+ if (!ref.current?.contains(event.target)) setOpen(false);
309
+ };
310
+ const onKey = (event) => event.key === "Escape" && setOpen(false);
311
+ document.addEventListener("mousedown", onDown);
312
+ document.addEventListener("keydown", onKey);
313
+ return () => {
314
+ document.removeEventListener("mousedown", onDown);
315
+ document.removeEventListener("keydown", onKey);
316
+ };
317
+ }, [open]);
318
+ return /* @__PURE__ */ jsxs("span", { ref, className: "bk-popover", children: [
319
+ trigger({ onClick: () => setOpen((value) => !value), open }),
320
+ open ? /* @__PURE__ */ jsx("div", { className: "bk-popover-content", children }) : null
321
+ ] });
322
+ }
323
+
324
+ // src/editor/color-menu.tsx
325
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
326
+ var TEXT_COLORS = ["#1c1c1c", "#997b2d", "#b91c1c", "#15803d", "#1d4ed8", "#7e22ce"];
327
+ var HIGHLIGHT_COLORS = ["#fde68a", "#bbf7d0", "#bfdbfe", "#fecaca", "#e9d5ff"];
328
+ var MODES = {
329
+ text: {
330
+ label: "textColor",
331
+ colors: TEXT_COLORS,
332
+ apply: (editor, color) => editor.chain().focus().setColor(color).run(),
333
+ clear: (editor) => editor.chain().focus().unsetColor().run()
334
+ },
335
+ highlight: {
336
+ label: "highlight",
337
+ colors: HIGHLIGHT_COLORS,
338
+ apply: (editor, color) => editor.chain().focus().setHighlight({ color }).run(),
339
+ clear: (editor) => editor.chain().focus().unsetHighlight().run()
340
+ }
341
+ };
342
+ function ColorMenu({ editor, mode, icon: Icon, active }) {
343
+ const labels = useLabels();
344
+ const config = MODES[mode];
345
+ const label = labels[config.label];
346
+ return /* @__PURE__ */ jsx2(
347
+ Popover,
348
+ {
349
+ trigger: ({ onClick, open }) => /* @__PURE__ */ jsx2(
350
+ Button,
351
+ {
352
+ size: "icon",
353
+ pressed: active,
354
+ "aria-label": label,
355
+ title: label,
356
+ "aria-pressed": active,
357
+ "aria-expanded": open,
358
+ onMouseDown: (event) => event.preventDefault(),
359
+ onClick,
360
+ children: /* @__PURE__ */ jsx2(Icon, { size: 16 })
361
+ }
362
+ ),
363
+ children: /* @__PURE__ */ jsxs2("div", { className: "bk-colors", children: [
364
+ config.colors.map((color) => /* @__PURE__ */ jsx2(
365
+ "button",
366
+ {
367
+ type: "button",
368
+ className: "bk-swatch",
369
+ style: { backgroundColor: color },
370
+ "aria-label": `${label} ${color}`,
371
+ title: color,
372
+ onMouseDown: (event) => event.preventDefault(),
373
+ onClick: () => config.apply(editor, color)
374
+ },
375
+ color
376
+ )),
377
+ /* @__PURE__ */ jsx2(Button, { size: "sm", onMouseDown: (event) => event.preventDefault(), onClick: () => config.clear(editor), children: labels.remove })
378
+ ] })
379
+ }
380
+ );
381
+ }
382
+
383
+ // src/editor/image-dialog.tsx
384
+ import * as React4 from "react";
385
+ import { ImagePlus, Images, Loader2 } from "lucide-react";
386
+
387
+ // src/editor/media/media-picker.tsx
388
+ import * as React3 from "react";
389
+ import { ChevronLeft, ChevronRight, X } from "lucide-react";
390
+
391
+ // src/editor/media/media-grid.tsx
392
+ import { Check } from "lucide-react";
393
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
394
+ function MediaGrid({ items, selectedId, onSelect }) {
395
+ const labels = useLabels();
396
+ if (!items.length) return /* @__PURE__ */ jsx3("div", { className: "bk-media-empty", children: labels.mediaEmpty });
397
+ return /* @__PURE__ */ jsx3("ul", { className: "bk-media-grid", children: items.map((item) => {
398
+ const selected = item.id === selectedId;
399
+ const thumb = item.variants["320"];
400
+ return /* @__PURE__ */ jsx3("li", { children: /* @__PURE__ */ jsxs3(
401
+ "button",
402
+ {
403
+ type: "button",
404
+ "aria-pressed": selected,
405
+ title: item.originalName,
406
+ onClick: () => onSelect(item),
407
+ className: cx("bk-media-item", selected && "bk-selected"),
408
+ children: [
409
+ /* @__PURE__ */ jsx3("img", { src: thumb?.url ?? item.url, alt: item.alt ?? item.originalName, loading: "lazy" }),
410
+ selected ? /* @__PURE__ */ jsx3("span", { className: "bk-media-check", children: /* @__PURE__ */ jsx3(Check, { size: 16 }) }) : null
411
+ ]
412
+ }
413
+ ) }, item.id);
414
+ }) });
415
+ }
416
+
417
+ // src/editor/media/media-upload-button.tsx
418
+ import * as React2 from "react";
419
+ import { UploadCloud } from "lucide-react";
420
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
421
+ function MediaUploadButton({ api, onUploaded }) {
422
+ const labels = useLabels();
423
+ const inputRef = React2.useRef(null);
424
+ const [busy, setBusy] = React2.useState(false);
425
+ const [error, setError] = React2.useState(null);
426
+ const handleChange = async (event) => {
427
+ const file = event.target.files?.[0];
428
+ event.target.value = "";
429
+ if (!file) return;
430
+ const formData = new FormData();
431
+ formData.append("file", file);
432
+ setBusy(true);
433
+ setError(null);
434
+ try {
435
+ const result = await api.upload(formData);
436
+ const item = result.items[0];
437
+ if (result.error || !item) setError(result.error ?? labels.mediaUploadFailed);
438
+ else onUploaded(item);
439
+ } catch {
440
+ setError(labels.mediaUploadFailed);
441
+ } finally {
442
+ setBusy(false);
443
+ }
444
+ };
445
+ return /* @__PURE__ */ jsxs4("div", { className: "bk-media-upload", children: [
446
+ /* @__PURE__ */ jsx4(
447
+ "input",
448
+ {
449
+ ref: inputRef,
450
+ type: "file",
451
+ className: "bk-sr-only",
452
+ tabIndex: -1,
453
+ accept: "image/jpeg,image/png,image/webp,image/gif",
454
+ onChange: handleChange
455
+ }
456
+ ),
457
+ /* @__PURE__ */ jsxs4(Button, { variant: "outline", size: "sm", disabled: busy, onClick: () => inputRef.current?.click(), children: [
458
+ /* @__PURE__ */ jsx4(UploadCloud, { size: 16 }),
459
+ busy ? labels.imageUploading : labels.mediaUpload
460
+ ] }),
461
+ error ? /* @__PURE__ */ jsx4("p", { role: "alert", className: "bk-error", children: error }) : null
462
+ ] });
463
+ }
464
+
465
+ // src/editor/media/media-picker.tsx
466
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
467
+ var toPicked = (item) => ({ url: item.url, alt: item.alt ?? void 0 });
468
+ function MediaPicker({ api, dir, onSelect, onClose }) {
469
+ const labels = useLabels();
470
+ const [q, setQ] = React3.useState("");
471
+ const [debouncedQ, setDebouncedQ] = React3.useState("");
472
+ const [page, setPage] = React3.useState(1);
473
+ const [data, setData] = React3.useState({ items: [], total: 0, pageSize: 24 });
474
+ const [error, setError] = React3.useState(null);
475
+ const [loading, setLoading] = React3.useState(false);
476
+ const [selected, setSelected] = React3.useState(null);
477
+ const requestId = React3.useRef(0);
478
+ React3.useEffect(() => {
479
+ const timer = setTimeout(() => {
480
+ setDebouncedQ(q.trim());
481
+ setPage(1);
482
+ }, 250);
483
+ return () => clearTimeout(timer);
484
+ }, [q]);
485
+ React3.useEffect(() => {
486
+ const id = ++requestId.current;
487
+ setLoading(true);
488
+ api.list({ q: debouncedQ || void 0, page }).then((result) => {
489
+ if (id !== requestId.current) return;
490
+ if (result.error) setError(result.error);
491
+ else {
492
+ setError(null);
493
+ setData({ items: result.items, total: result.total, pageSize: result.pageSize || 24 });
494
+ }
495
+ }).catch(() => id === requestId.current && setError(labels.mediaLoadFailed)).finally(() => id === requestId.current && setLoading(false));
496
+ }, [api, debouncedQ, page, labels.mediaLoadFailed]);
497
+ const pageCount = Math.max(1, Math.ceil(data.total / data.pageSize));
498
+ const Prev = dir === "ltr" ? ChevronLeft : ChevronRight;
499
+ const Next = dir === "ltr" ? ChevronRight : ChevronLeft;
500
+ return /* @__PURE__ */ jsxs5(Dialog, { open: true, onClose, title: labels.mediaTitle, dir, wide: true, children: [
501
+ /* @__PURE__ */ jsxs5("header", { className: "bk-dialog-header", children: [
502
+ /* @__PURE__ */ jsx5("h2", { children: labels.mediaTitle }),
503
+ /* @__PURE__ */ jsx5(Button, { size: "icon", "aria-label": labels.close, onClick: onClose, children: /* @__PURE__ */ jsx5(X, { size: 16 }) })
504
+ ] }),
505
+ /* @__PURE__ */ jsxs5("div", { className: "bk-media-toolbar", children: [
506
+ /* @__PURE__ */ jsx5(
507
+ Input,
508
+ {
509
+ value: q,
510
+ onChange: (event) => setQ(event.target.value),
511
+ placeholder: labels.mediaSearchPlaceholder,
512
+ "aria-label": labels.mediaSearch
513
+ }
514
+ ),
515
+ /* @__PURE__ */ jsx5(MediaUploadButton, { api, onUploaded: (item) => onSelect(toPicked(item)) })
516
+ ] }),
517
+ /* @__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 }) }),
518
+ /* @__PURE__ */ jsxs5("footer", { className: "bk-dialog-footer bk-media-footer", children: [
519
+ /* @__PURE__ */ jsxs5("div", { className: "bk-pager", children: [
520
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", size: "icon", "aria-label": labels.mediaPrevPage, disabled: page <= 1, onClick: () => setPage(page - 1), children: /* @__PURE__ */ jsx5(Prev, { size: 16 }) }),
521
+ /* @__PURE__ */ jsxs5("span", { children: [
522
+ page,
523
+ " / ",
524
+ pageCount
525
+ ] }),
526
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", size: "icon", "aria-label": labels.mediaNextPage, disabled: page >= pageCount, onClick: () => setPage(page + 1), children: /* @__PURE__ */ jsx5(Next, { size: 16 }) })
527
+ ] }),
528
+ /* @__PURE__ */ jsxs5("div", { className: "bk-actions", children: [
529
+ /* @__PURE__ */ jsx5(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
530
+ /* @__PURE__ */ jsx5(Button, { variant: "primary", disabled: !selected, onClick: () => selected && onSelect(toPicked(selected)), children: labels.mediaSelect })
531
+ ] })
532
+ ] })
533
+ ] });
534
+ }
535
+
536
+ // src/editor/image-dialog.tsx
537
+ import { Fragment, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
538
+ var isHttps = (value) => /^https:\/\/\S+$/i.test(value);
539
+ function ImageDialog({ open, onOpenChange, dir, ...form }) {
540
+ const labels = useLabels();
541
+ return /* @__PURE__ */ jsx6(Dialog, { open, onClose: () => onOpenChange(false), title: labels.imageTitle, dir, children: /* @__PURE__ */ jsx6(ImageForm, { ...form, dir, onClose: () => onOpenChange(false) }) });
542
+ }
543
+ function ImageForm({
544
+ onSubmit,
545
+ onClose,
546
+ dir,
547
+ uploadImage,
548
+ mediaApi,
549
+ renderMediaPicker,
550
+ resolveImageSrc
551
+ }) {
552
+ const labels = useLabels();
553
+ const id = React4.useId();
554
+ const fileRef = React4.useRef(null);
555
+ const [src, setSrc] = React4.useState("");
556
+ const [alt, setAlt] = React4.useState("");
557
+ const [error, setError] = React4.useState(null);
558
+ const [uploading, setUploading] = React4.useState(false);
559
+ const [pickerOpen, setPickerOpen] = React4.useState(false);
560
+ const applyPicked = (image) => {
561
+ const url = resolveImageSrc ? resolveImageSrc(image.url) : image.url;
562
+ if (!isHttps(url)) {
563
+ setError(labels.imageHttpsError);
564
+ return false;
565
+ }
566
+ setError(null);
567
+ setSrc(url);
568
+ if (image.alt && !alt) setAlt(image.alt);
569
+ return true;
570
+ };
571
+ const handleFile = async (event) => {
572
+ const file = event.target.files?.[0];
573
+ event.target.value = "";
574
+ if (!file || !uploadImage) return;
575
+ setUploading(true);
576
+ setError(null);
577
+ try {
578
+ applyPicked(await uploadImage(file));
579
+ } catch (e) {
580
+ setError(e instanceof Error && e.message ? e.message : labels.imageUploadFailed);
581
+ } finally {
582
+ setUploading(false);
583
+ }
584
+ };
585
+ const submit = (event) => {
586
+ event.preventDefault();
587
+ event.stopPropagation();
588
+ const value = src.trim();
589
+ if (!isHttps(value)) {
590
+ setError(labels.imageHttpsError);
591
+ return;
592
+ }
593
+ onSubmit({ src: value, alt: alt.trim() });
594
+ onClose();
595
+ };
596
+ const hasLibrary = Boolean(renderMediaPicker || mediaApi);
597
+ const closePicker = () => setPickerOpen(false);
598
+ const onPicked = (image) => {
599
+ if (applyPicked(image)) closePicker();
600
+ };
601
+ return /* @__PURE__ */ jsxs6(Fragment, { children: [
602
+ /* @__PURE__ */ jsxs6("form", { onSubmit: submit, className: "bk-form", children: [
603
+ /* @__PURE__ */ jsx6("h2", { className: "bk-dialog-title", children: labels.imageTitle }),
604
+ uploadImage || hasLibrary ? /* @__PURE__ */ jsxs6("div", { className: "bk-actions bk-actions-start", children: [
605
+ uploadImage ? /* @__PURE__ */ jsxs6(Fragment, { children: [
606
+ /* @__PURE__ */ jsx6("input", { ref: fileRef, type: "file", accept: "image/*", className: "bk-sr-only", tabIndex: -1, onChange: handleFile }),
607
+ /* @__PURE__ */ jsxs6(Button, { variant: "outline", size: "sm", disabled: uploading, onClick: () => fileRef.current?.click(), children: [
608
+ uploading ? /* @__PURE__ */ jsx6(Loader2, { size: 16, className: "bk-spin" }) : /* @__PURE__ */ jsx6(ImagePlus, { size: 16 }),
609
+ uploading ? labels.imageUploading : labels.imageUpload
610
+ ] })
611
+ ] }) : null,
612
+ hasLibrary ? /* @__PURE__ */ jsxs6(Button, { variant: "outline", size: "sm", onClick: () => setPickerOpen(true), children: [
613
+ /* @__PURE__ */ jsx6(Images, { size: 16 }),
614
+ labels.imageLibrary
615
+ ] }) : null
616
+ ] }) : null,
617
+ /* @__PURE__ */ jsxs6("div", { className: "bk-field", children: [
618
+ /* @__PURE__ */ jsx6(Label, { htmlFor: `${id}-src`, children: labels.imageUrl }),
619
+ /* @__PURE__ */ jsx6(
620
+ Input,
621
+ {
622
+ id: `${id}-src`,
623
+ dir: "ltr",
624
+ value: src,
625
+ placeholder: labels.imageUrlPlaceholder,
626
+ onChange: (event) => setSrc(event.target.value)
627
+ }
628
+ )
629
+ ] }),
630
+ src && isHttps(src) ? (
631
+ // eslint-disable-next-line @next/next/no-img-element
632
+ /* @__PURE__ */ jsx6("img", { src, alt: "", className: "bk-image-preview" })
633
+ ) : null,
634
+ /* @__PURE__ */ jsxs6("div", { className: "bk-field", children: [
635
+ /* @__PURE__ */ jsx6(Label, { htmlFor: `${id}-alt`, children: labels.imageAlt }),
636
+ /* @__PURE__ */ jsx6(Input, { id: `${id}-alt`, value: alt, onChange: (event) => setAlt(event.target.value) })
637
+ ] }),
638
+ error ? /* @__PURE__ */ jsx6("p", { role: "alert", className: "bk-error", children: error }) : null,
639
+ /* @__PURE__ */ jsxs6("div", { className: "bk-dialog-footer", children: [
640
+ /* @__PURE__ */ jsx6(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
641
+ /* @__PURE__ */ jsx6(Button, { variant: "primary", type: "submit", disabled: !src.trim() || uploading, children: labels.imageInsert })
642
+ ] })
643
+ ] }),
644
+ pickerOpen ? renderMediaPicker ? renderMediaPicker({ onSelect: onPicked, close: closePicker }) : mediaApi ? /* @__PURE__ */ jsx6(MediaPicker, { api: mediaApi, dir, onSelect: onPicked, onClose: closePicker }) : null : null
645
+ ] });
646
+ }
647
+
648
+ // src/editor/url-dialog.tsx
649
+ import * as React5 from "react";
650
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
651
+ function UrlDialog({ open, onOpenChange, ...form }) {
652
+ return /* @__PURE__ */ jsx7(Dialog, { open, onClose: () => onOpenChange(false), title: form.title, dir: form.dir, children: /* @__PURE__ */ jsx7(UrlForm, { ...form, onClose: () => onOpenChange(false) }) });
653
+ }
654
+ function UrlForm({
655
+ title,
656
+ label,
657
+ placeholder,
658
+ initialValue = "",
659
+ errorMessage,
660
+ parse,
661
+ onSubmit,
662
+ onClose
663
+ }) {
664
+ const labels = useLabels();
665
+ const id = React5.useId();
666
+ const [value, setValue] = React5.useState(initialValue);
667
+ const [error, setError] = React5.useState(null);
668
+ const submit = (event) => {
669
+ event.preventDefault();
670
+ event.stopPropagation();
671
+ const url = parse(value);
672
+ if (!url) {
673
+ setError(errorMessage);
674
+ return;
675
+ }
676
+ onSubmit(url);
677
+ onClose();
678
+ };
679
+ return /* @__PURE__ */ jsxs7("form", { onSubmit: submit, className: "bk-form", children: [
680
+ /* @__PURE__ */ jsx7("h2", { className: "bk-dialog-title", children: title }),
681
+ /* @__PURE__ */ jsxs7("div", { className: "bk-field", children: [
682
+ /* @__PURE__ */ jsx7(Label, { htmlFor: id, children: label }),
683
+ /* @__PURE__ */ jsx7(
684
+ Input,
685
+ {
686
+ id,
687
+ dir: "ltr",
688
+ value,
689
+ placeholder,
690
+ onChange: (event) => setValue(event.target.value),
691
+ autoFocus: true
692
+ }
693
+ ),
694
+ error ? /* @__PURE__ */ jsx7("p", { role: "alert", className: "bk-error", children: error }) : null
695
+ ] }),
696
+ /* @__PURE__ */ jsxs7("div", { className: "bk-dialog-footer", children: [
697
+ /* @__PURE__ */ jsx7(Button, { variant: "outline", onClick: onClose, children: labels.cancel }),
698
+ /* @__PURE__ */ jsx7(Button, { variant: "primary", type: "submit", children: labels.insert })
699
+ ] })
700
+ ] });
701
+ }
702
+
703
+ // src/editor/toolbar.tsx
704
+ import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
705
+ var chain = (editor) => editor.chain().focus();
706
+ var GROUPS = [
707
+ [
708
+ { key: "bold", icon: Bold, label: "bold", isActive: (e) => e.isActive("bold"), run: (e) => chain(e).toggleBold().run() },
709
+ { key: "italic", icon: Italic, label: "italic", isActive: (e) => e.isActive("italic"), run: (e) => chain(e).toggleItalic().run() },
710
+ { key: "underline", icon: Underline, label: "underline", isActive: (e) => e.isActive("underline"), run: (e) => chain(e).toggleUnderline().run() },
711
+ { key: "strike", icon: Strikethrough, label: "strike", isActive: (e) => e.isActive("strike"), run: (e) => chain(e).toggleStrike().run() }
712
+ ],
713
+ [
714
+ { key: "h2", icon: Heading2, label: "h2", isActive: (e) => e.isActive("heading", { level: 2 }), run: (e) => chain(e).toggleHeading({ level: 2 }).run() },
715
+ { key: "h3", icon: Heading3, label: "h3", isActive: (e) => e.isActive("heading", { level: 3 }), run: (e) => chain(e).toggleHeading({ level: 3 }).run() },
716
+ { key: "h4", icon: Heading4, label: "h4", isActive: (e) => e.isActive("heading", { level: 4 }), run: (e) => chain(e).toggleHeading({ level: 4 }).run() }
717
+ ],
718
+ [
719
+ { key: "right", icon: AlignRight, label: "alignRight", isActive: (e) => e.isActive({ textAlign: "right" }), run: (e) => chain(e).setTextAlign("right").run() },
720
+ { key: "center", icon: AlignCenter, label: "alignCenter", isActive: (e) => e.isActive({ textAlign: "center" }), run: (e) => chain(e).setTextAlign("center").run() },
721
+ { key: "left", icon: AlignLeft, label: "alignLeft", isActive: (e) => e.isActive({ textAlign: "left" }), run: (e) => chain(e).setTextAlign("left").run() },
722
+ { key: "justify", icon: AlignJustify, label: "alignJustify", isActive: (e) => e.isActive({ textAlign: "justify" }), run: (e) => chain(e).setTextAlign("justify").run() }
723
+ ],
724
+ [
725
+ { key: "bullet", icon: List, label: "bulletList", isActive: (e) => e.isActive("bulletList"), run: (e) => chain(e).toggleBulletList().run() },
726
+ { key: "ordered", icon: ListOrdered, label: "orderedList", isActive: (e) => e.isActive("orderedList"), run: (e) => chain(e).toggleOrderedList().run() },
727
+ { key: "quote", icon: Quote, label: "quote", isActive: (e) => e.isActive("blockquote"), run: (e) => chain(e).toggleBlockquote().run() },
728
+ { key: "code", icon: Code2, label: "codeBlock", isActive: (e) => e.isActive("codeBlock"), run: (e) => chain(e).toggleCodeBlock().run() },
729
+ { key: "hr", icon: Minus, label: "hr", run: (e) => chain(e).setHorizontalRule().run() }
730
+ ],
731
+ [
732
+ { key: "link", icon: Link2, label: "link", isActive: (e) => e.isActive("link"), run: (_e, open) => open("link") },
733
+ { key: "unlink", icon: Link2Off, label: "unlink", isDisabled: (e) => !e.isActive("link"), run: (e) => chain(e).extendMarkRange("link").unsetLink().run() },
734
+ { key: "image", icon: ImagePlus2, label: "image", run: (_e, open) => open("image") },
735
+ { key: "video", icon: Video, label: "video", run: (_e, open) => open("video") },
736
+ { key: "table", icon: Table2, label: "table", isActive: (e) => e.isActive("table"), run: (e) => chain(e).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() }
737
+ ],
738
+ [
739
+ { key: "undo", icon: Undo2, label: "undo", isDisabled: (e) => !e.can().undo(), run: (e) => chain(e).undo().run() },
740
+ { key: "redo", icon: Redo2, label: "redo", isDisabled: (e) => !e.can().redo(), run: (e) => chain(e).redo().run() }
741
+ ]
742
+ ];
743
+ var TABLE_ACTIONS = [
744
+ { key: "row-after", label: "addRow", run: (e) => chain(e).addRowAfter().run() },
745
+ { key: "col-after", label: "addColumn", run: (e) => chain(e).addColumnAfter().run() },
746
+ { key: "row-delete", label: "deleteRow", run: (e) => chain(e).deleteRow().run() },
747
+ { key: "col-delete", label: "deleteColumn", run: (e) => chain(e).deleteColumn().run() },
748
+ { key: "table-delete", label: "deleteTable", run: (e) => chain(e).deleteTable().run() }
749
+ ];
750
+ var ALL_BUTTONS = GROUPS.flat();
751
+ function RichTextToolbar({ editor, dir, allowedEmbeds, ...imageProps }) {
752
+ const labels = useLabels();
753
+ const [dialog, setDialog] = React6.useState(null);
754
+ const state = useEditorState({
755
+ editor,
756
+ selector: ({ editor: e }) => ({
757
+ active: Object.fromEntries(ALL_BUTTONS.map((b) => [b.key, b.isActive?.(e) ?? false])),
758
+ disabled: Object.fromEntries(ALL_BUTTONS.map((b) => [b.key, b.isDisabled?.(e) ?? false])),
759
+ color: e.isActive("textStyle", { color: /.+/ }),
760
+ highlight: e.isActive("highlight"),
761
+ inTable: e.isActive("table"),
762
+ href: e.getAttributes("link").href ?? ""
763
+ })
764
+ });
765
+ const closeDialog = (open) => !open && setDialog(null);
766
+ return /* @__PURE__ */ jsxs8("div", { className: "bk-toolbar", children: [
767
+ GROUPS.map((group, index) => /* @__PURE__ */ jsxs8(React6.Fragment, { children: [
768
+ index > 0 ? /* @__PURE__ */ jsx8("span", { className: "bk-sep", "aria-hidden": true }) : null,
769
+ group.map((button) => {
770
+ const label = labels[button.label];
771
+ const active = state.active[button.key] ?? false;
772
+ return /* @__PURE__ */ jsx8(
773
+ Button,
774
+ {
775
+ size: "icon",
776
+ pressed: active,
777
+ "aria-label": label,
778
+ title: label,
779
+ "aria-pressed": button.isActive ? active : void 0,
780
+ disabled: state.disabled[button.key],
781
+ onMouseDown: (event) => event.preventDefault(),
782
+ onClick: () => button.run(editor, setDialog),
783
+ children: /* @__PURE__ */ jsx8(button.icon, { size: 16 })
784
+ },
785
+ button.key
786
+ );
787
+ }),
788
+ index === 0 ? /* @__PURE__ */ jsxs8(Fragment3, { children: [
789
+ /* @__PURE__ */ jsx8(ColorMenu, { editor, mode: "text", icon: Palette, active: state.color }),
790
+ /* @__PURE__ */ jsx8(ColorMenu, { editor, mode: "highlight", icon: Highlighter, active: state.highlight })
791
+ ] }) : null
792
+ ] }, group[0].key)),
793
+ state.inTable ? /* @__PURE__ */ jsx8("div", { className: "bk-table-tools", 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,
794
+ /* @__PURE__ */ jsx8(
795
+ UrlDialog,
796
+ {
797
+ open: dialog === "link",
798
+ onOpenChange: closeDialog,
799
+ dir,
800
+ title: labels.linkTitle,
801
+ label: labels.linkField,
802
+ placeholder: labels.linkPlaceholder,
803
+ initialValue: state.href,
804
+ errorMessage: labels.linkError,
805
+ parse: normalizeLinkUrl,
806
+ onSubmit: (href) => chain(editor).extendMarkRange("link").setLink({ href }).run()
807
+ }
808
+ ),
809
+ /* @__PURE__ */ jsx8(
810
+ UrlDialog,
811
+ {
812
+ open: dialog === "video",
813
+ onOpenChange: closeDialog,
814
+ dir,
815
+ title: labels.videoTitle,
816
+ label: labels.videoField,
817
+ placeholder: labels.videoPlaceholder,
818
+ errorMessage: labels.videoError,
819
+ parse: (value) => toVideoEmbedUrl(value, allowedEmbeds),
820
+ onSubmit: (src) => chain(editor).insertContent({ type: "videoEmbed", attrs: { src } }).run()
821
+ }
822
+ ),
823
+ /* @__PURE__ */ jsx8(
824
+ ImageDialog,
825
+ {
826
+ ...imageProps,
827
+ dir,
828
+ open: dialog === "image",
829
+ onOpenChange: closeDialog,
830
+ onSubmit: (image) => chain(editor).setImage(image).run()
831
+ }
832
+ )
833
+ ] });
834
+ }
835
+
836
+ // src/editor/rich-text-editor.tsx
837
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
838
+ function RichTextEditor({
839
+ value,
840
+ onChange,
841
+ placeholder,
842
+ invalid,
843
+ id,
844
+ className,
845
+ uploadImage,
846
+ mediaApi,
847
+ renderMediaPicker,
848
+ resolveImageSrc,
849
+ allowedEmbeds = ALL_EMBED_PROVIDERS,
850
+ labels,
851
+ dir = "rtl"
852
+ }) {
853
+ const merged = React7.useMemo(() => ({ ...defaultLabels, ...labels }), [labels]);
854
+ const onChangeRef = React7.useRef(onChange);
855
+ onChangeRef.current = onChange;
856
+ const editor = useEditor({
857
+ extensions: buildEditorExtensions(placeholder ?? merged.placeholder, allowedEmbeds, dir),
858
+ content: value,
859
+ immediatelyRender: false,
860
+ // SSR-safe
861
+ editorProps: {
862
+ attributes: { class: "bk-rich bk-editor-content", dir, ...id ? { id } : {} }
863
+ },
864
+ onUpdate: ({ editor: e }) => onChangeRef.current(e.isEmpty ? "" : e.getHTML())
865
+ });
866
+ React7.useEffect(() => {
867
+ if (!editor) return;
868
+ const current = editor.isEmpty ? "" : editor.getHTML();
869
+ if (value !== current) editor.commands.setContent(value, { emitUpdate: false });
870
+ }, [editor, value]);
871
+ return /* @__PURE__ */ jsx9(LabelsContext.Provider, { value: merged, children: /* @__PURE__ */ jsxs9("div", { className: cx("bk-editor", invalid && "bk-invalid", className), dir, children: [
872
+ editor ? /* @__PURE__ */ jsx9(
873
+ RichTextToolbar,
874
+ {
875
+ editor,
876
+ dir,
877
+ allowedEmbeds,
878
+ uploadImage,
879
+ mediaApi,
880
+ renderMediaPicker,
881
+ resolveImageSrc
882
+ }
883
+ ) : null,
884
+ /* @__PURE__ */ jsx9(EditorContent, { editor })
885
+ ] }) });
886
+ }
887
+ export {
888
+ RichTextEditor,
889
+ defaultLabels,
890
+ isAllowedEmbedSrc,
891
+ normalizeLinkUrl,
892
+ toVideoEmbedUrl
893
+ };
894
+ //# sourceMappingURL=index.js.map