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