neuphlo-editor 2.1.0 → 2.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.
@@ -0,0 +1,1352 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all2) => {
6
+ for (var name in all2)
7
+ __defProp(target, name, { get: all2[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // src/headless/index.ts
20
+ import { useCurrentEditor as useCurrentEditor4 } from "@tiptap/react";
21
+
22
+ // src/headless/components/editor.tsx
23
+ import { EditorProvider } from "@tiptap/react";
24
+ import { forwardRef } from "react";
25
+ import { Provider } from "jotai";
26
+
27
+ // src/headless/utils/store.ts
28
+ var store_exports = {};
29
+ __export(store_exports, {
30
+ novelStore: () => novelStore
31
+ });
32
+ __reExport(store_exports, jotai_star);
33
+ import { createStore } from "jotai";
34
+ import * as jotai_star from "jotai";
35
+ var novelStore = createStore();
36
+
37
+ // src/headless/components/editor.tsx
38
+ import { jsx } from "react/jsx-runtime";
39
+ var EditorRoot = ({ children }) => {
40
+ return /* @__PURE__ */ jsx(Provider, { store: novelStore, children });
41
+ };
42
+ var EditorContent = forwardRef(
43
+ ({ className, children, initialContent, content, ...rest }, ref) => {
44
+ const effectiveContent = content ?? initialContent;
45
+ return /* @__PURE__ */ jsx("div", { ref, className, children: /* @__PURE__ */ jsx(EditorProvider, { ...rest, content: effectiveContent, children }) });
46
+ }
47
+ );
48
+ EditorContent.displayName = "EditorContent";
49
+
50
+ // src/headless/components/editor-bubble.tsx
51
+ import { useCurrentEditor } from "@tiptap/react";
52
+ import { BubbleMenu as BubbleMenuReact } from "@tiptap/react/menus";
53
+ import { jsx as jsx2 } from "react/jsx-runtime";
54
+ function EditorBubble({ className, children, ...rest }) {
55
+ const { editor } = useCurrentEditor();
56
+ if (!editor) return null;
57
+ return /* @__PURE__ */ jsx2(BubbleMenuReact, { editor, ...rest, children: /* @__PURE__ */ jsx2("div", { className, children }) });
58
+ }
59
+
60
+ // src/headless/components/editor-bubble-item.tsx
61
+ import { forwardRef as forwardRef2, isValidElement, cloneElement } from "react";
62
+ import { useCurrentEditor as useCurrentEditor2 } from "@tiptap/react";
63
+ import { jsx as jsx3 } from "react/jsx-runtime";
64
+ var EditorBubbleItem = forwardRef2(({ children, asChild, onSelect, ...rest }, ref) => {
65
+ const { editor } = useCurrentEditor2();
66
+ if (!editor) return null;
67
+ const handleClick = (e) => {
68
+ e.preventDefault();
69
+ onSelect?.(editor);
70
+ };
71
+ if (asChild && isValidElement(children)) {
72
+ const child = children;
73
+ const childOnClick = child.props?.onClick;
74
+ const mergedOnClick = (e) => {
75
+ childOnClick?.(e);
76
+ if (!e?.defaultPrevented) onSelect?.(editor);
77
+ };
78
+ return cloneElement(child, {
79
+ ...rest,
80
+ ref: child.ref ?? ref,
81
+ onClick: mergedOnClick
82
+ });
83
+ }
84
+ return /* @__PURE__ */ jsx3("div", { ref, ...rest, onClick: handleClick, children });
85
+ });
86
+ EditorBubbleItem.displayName = "EditorBubbleItem";
87
+
88
+ // src/headless/components/editor-command.tsx
89
+ import { useAtomValue } from "jotai";
90
+ import { forwardRef as forwardRef3, useRef, useEffect, useLayoutEffect, useState, useCallback } from "react";
91
+ import { createPortal } from "react-dom";
92
+
93
+ // src/headless/utils/atoms.ts
94
+ import { atom } from "jotai";
95
+ var queryAtom = atom("");
96
+ var rangeAtom = atom(null);
97
+ var slashMenuOpenAtom = atom(false);
98
+ var slashMenuRectAtom = atom(null);
99
+
100
+ // src/headless/components/editor-command.tsx
101
+ import { jsx as jsx4 } from "react/jsx-runtime";
102
+ var EditorCommandOut = () => null;
103
+ var EditorCommand = forwardRef3(
104
+ ({ children, className, ...rest }, ref) => {
105
+ const isOpen = useAtomValue(slashMenuOpenAtom, { store: novelStore });
106
+ const rect = useAtomValue(slashMenuRectAtom, { store: novelStore });
107
+ const containerRef = useRef(null);
108
+ const [activeIndex, setActiveIndex] = useState(0);
109
+ const contentRef = useRef(null);
110
+ const query = useAtomValue(queryAtom, { store: novelStore });
111
+ useEffect(() => {
112
+ setActiveIndex(0);
113
+ }, [query]);
114
+ if (typeof document !== "undefined" && !containerRef.current) {
115
+ const el = document.createElement("div");
116
+ el.style.position = "fixed";
117
+ el.style.zIndex = "9999";
118
+ el.style.minWidth = "240px";
119
+ el.style.display = "none";
120
+ containerRef.current = el;
121
+ }
122
+ useEffect(() => {
123
+ const el = containerRef.current;
124
+ if (!el) return;
125
+ document.body.appendChild(el);
126
+ return () => {
127
+ el.remove();
128
+ };
129
+ }, []);
130
+ useLayoutEffect(() => {
131
+ const container = containerRef.current;
132
+ if (!container) return;
133
+ if (!isOpen || !rect) {
134
+ container.style.display = "none";
135
+ return;
136
+ }
137
+ container.style.display = "";
138
+ const menuHeight = container.offsetHeight || 360;
139
+ const viewportHeight = window.innerHeight;
140
+ const spaceBelow = viewportHeight - rect.bottom;
141
+ const spaceAbove = rect.top;
142
+ let top;
143
+ if (spaceBelow < menuHeight + 16 && spaceAbove > spaceBelow) {
144
+ top = Math.round(rect.top - menuHeight - 8);
145
+ if (top < 8) top = 8;
146
+ } else {
147
+ top = Math.round(rect.bottom + 8);
148
+ }
149
+ let left = Math.round(rect.left);
150
+ const menuWidth = container.offsetWidth || 280;
151
+ if (left + menuWidth > window.innerWidth - 8) {
152
+ left = window.innerWidth - menuWidth - 8;
153
+ }
154
+ if (left < 8) left = 8;
155
+ container.style.top = `${top}px`;
156
+ container.style.left = `${left}px`;
157
+ }, [isOpen, rect]);
158
+ const handleKeyDown = useCallback(
159
+ (e) => {
160
+ if (!isOpen || !contentRef.current) return;
161
+ const items = contentRef.current.querySelectorAll("[role='option']");
162
+ if (items.length === 0) return;
163
+ if (e.key === "ArrowDown") {
164
+ e.preventDefault();
165
+ setActiveIndex((prev) => {
166
+ const next = Math.min(prev + 1, items.length - 1);
167
+ items[next]?.scrollIntoView({ block: "nearest" });
168
+ return next;
169
+ });
170
+ } else if (e.key === "ArrowUp") {
171
+ e.preventDefault();
172
+ setActiveIndex((prev) => {
173
+ const next = Math.max(prev - 1, 0);
174
+ items[next]?.scrollIntoView({ block: "nearest" });
175
+ return next;
176
+ });
177
+ } else if (e.key === "Enter") {
178
+ e.preventDefault();
179
+ const activeItem = items[activeIndex];
180
+ activeItem?.click();
181
+ }
182
+ },
183
+ [isOpen, activeIndex]
184
+ );
185
+ useEffect(() => {
186
+ if (!isOpen) return;
187
+ document.addEventListener("keydown", handleKeyDown);
188
+ return () => document.removeEventListener("keydown", handleKeyDown);
189
+ }, [isOpen, handleKeyDown]);
190
+ useEffect(() => {
191
+ if (!contentRef.current) return;
192
+ const items = contentRef.current.querySelectorAll("[role='option']");
193
+ items.forEach((item, i) => {
194
+ if (i === activeIndex) {
195
+ item.setAttribute("aria-selected", "true");
196
+ } else {
197
+ item.removeAttribute("aria-selected");
198
+ }
199
+ });
200
+ });
201
+ if (!isOpen || !containerRef.current) return null;
202
+ return createPortal(
203
+ /* @__PURE__ */ jsx4(
204
+ "div",
205
+ {
206
+ ref: (el) => {
207
+ contentRef.current = el;
208
+ if (typeof ref === "function") ref(el);
209
+ else if (ref) ref.current = el;
210
+ },
211
+ id: "slash-command",
212
+ className,
213
+ ...rest,
214
+ children
215
+ }
216
+ ),
217
+ containerRef.current
218
+ );
219
+ }
220
+ );
221
+ var EditorCommandList = forwardRef3(
222
+ ({ children, ...rest }, ref) => {
223
+ return /* @__PURE__ */ jsx4("div", { ref, role: "listbox", ...rest, children });
224
+ }
225
+ );
226
+ EditorCommand.displayName = "EditorCommand";
227
+ EditorCommandList.displayName = "EditorCommandList";
228
+
229
+ // src/headless/components/editor-command-item.tsx
230
+ import { forwardRef as forwardRef4 } from "react";
231
+ import { useCurrentEditor as useCurrentEditor3 } from "@tiptap/react";
232
+ import { useAtomValue as useAtomValue2 } from "jotai";
233
+ import { jsx as jsx5 } from "react/jsx-runtime";
234
+ var EditorCommandItem = forwardRef4(({ children, onCommand, value, className, ...rest }, ref) => {
235
+ const { editor } = useCurrentEditor3();
236
+ const range = useAtomValue2(rangeAtom, { store: novelStore });
237
+ const query = useAtomValue2(queryAtom, { store: novelStore });
238
+ if (!editor || !range) return null;
239
+ if (query && value) {
240
+ const searchText = value.toLowerCase();
241
+ const q = query.toLowerCase();
242
+ if (!searchText.includes(q)) return null;
243
+ }
244
+ return /* @__PURE__ */ jsx5(
245
+ "div",
246
+ {
247
+ ref,
248
+ role: "option",
249
+ className,
250
+ onClick: () => onCommand({ editor, range }),
251
+ ...rest,
252
+ children
253
+ }
254
+ );
255
+ });
256
+ EditorCommandItem.displayName = "EditorCommandItem";
257
+ var EditorCommandEmpty = forwardRef4(
258
+ ({ children, ...rest }, ref) => {
259
+ return /* @__PURE__ */ jsx5("div", { ref, ...rest, children });
260
+ }
261
+ );
262
+ EditorCommandEmpty.displayName = "EditorCommandEmpty";
263
+
264
+ // src/headless/extensions/index.ts
265
+ import { StarterKit } from "@tiptap/starter-kit";
266
+ import { Placeholder } from "@tiptap/extension-placeholder";
267
+
268
+ // src/headless/extensions/CodeBlock/CodeBlock.ts
269
+ import { CodeBlockLowlight } from "@tiptap/extension-code-block-lowlight";
270
+ import { all, createLowlight } from "lowlight";
271
+ var lowlight = createLowlight(all);
272
+ var CodeBlock = CodeBlockLowlight.configure({
273
+ lowlight
274
+ });
275
+
276
+ // src/headless/extensions/Link/Link.ts
277
+ import { mergeAttributes } from "@tiptap/core";
278
+ import TiptapLink from "@tiptap/extension-link";
279
+ import { Plugin } from "@tiptap/pm/state";
280
+ var Link = TiptapLink.extend({
281
+ inclusive: false,
282
+ parseHTML() {
283
+ return [
284
+ {
285
+ tag: 'a[href]:not([data-type="button"]):not([href *= "javascript:" i])'
286
+ }
287
+ ];
288
+ },
289
+ renderHTML({ HTMLAttributes }) {
290
+ return [
291
+ "a",
292
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
293
+ class: "link"
294
+ }),
295
+ 0
296
+ ];
297
+ },
298
+ addProseMirrorPlugins() {
299
+ const { editor } = this;
300
+ return [
301
+ ...this.parent?.() || [],
302
+ new Plugin({
303
+ props: {
304
+ handleKeyDown: (view, event) => {
305
+ const { selection } = editor.state;
306
+ if (event.key === "Escape" && selection.empty !== true) {
307
+ editor.commands.focus(selection.to, { scrollIntoView: false });
308
+ }
309
+ return false;
310
+ }
311
+ }
312
+ })
313
+ ];
314
+ }
315
+ }).configure({
316
+ openOnClick: false,
317
+ autolink: true,
318
+ enableClickSelection: true
319
+ });
320
+
321
+ // src/headless/extensions/ImageBlock/ImageBlock.ts
322
+ import { mergeAttributes as mergeAttributes2 } from "@tiptap/core";
323
+ import { Image as TiptapImage } from "@tiptap/extension-image";
324
+ import { ReactNodeViewRenderer } from "@tiptap/react";
325
+ import { Plugin as Plugin2, PluginKey } from "@tiptap/pm/state";
326
+ var ImageBlock = TiptapImage.extend({
327
+ name: "imageBlock",
328
+ group: "block",
329
+ defining: true,
330
+ isolating: true,
331
+ addOptions() {
332
+ return {
333
+ ...this.parent?.(),
334
+ uploadImage: null,
335
+ browseAssets: null,
336
+ inline: false
337
+ };
338
+ },
339
+ addAttributes() {
340
+ return {
341
+ src: {
342
+ default: "",
343
+ parseHTML: (element) => element.getAttribute("src"),
344
+ renderHTML: (attributes) => ({
345
+ src: attributes.src
346
+ })
347
+ },
348
+ width: {
349
+ default: "100%",
350
+ parseHTML: (element) => element.getAttribute("data-width"),
351
+ renderHTML: (attributes) => ({
352
+ "data-width": attributes.width
353
+ })
354
+ },
355
+ align: {
356
+ default: "center",
357
+ parseHTML: (element) => element.getAttribute("data-align"),
358
+ renderHTML: (attributes) => ({
359
+ "data-align": attributes.align
360
+ })
361
+ },
362
+ alt: {
363
+ default: void 0,
364
+ parseHTML: (element) => element.getAttribute("alt"),
365
+ renderHTML: (attributes) => ({
366
+ alt: attributes.alt
367
+ })
368
+ },
369
+ loading: {
370
+ default: false,
371
+ parseHTML: () => false,
372
+ renderHTML: () => ({})
373
+ }
374
+ };
375
+ },
376
+ parseHTML() {
377
+ return [
378
+ {
379
+ tag: 'img[src]:not([src^="data:"])',
380
+ getAttrs: (element) => {
381
+ const el = element;
382
+ return {
383
+ src: el.getAttribute("src"),
384
+ alt: el.getAttribute("alt"),
385
+ width: el.getAttribute("data-width") || "100%",
386
+ align: el.getAttribute("data-align") || "center"
387
+ };
388
+ }
389
+ }
390
+ ];
391
+ },
392
+ renderHTML({ HTMLAttributes }) {
393
+ return ["img", mergeAttributes2(HTMLAttributes)];
394
+ },
395
+ addCommands() {
396
+ return {
397
+ setImageBlock: (attrs) => ({ commands }) => {
398
+ return commands.insertContent({
399
+ type: "imageBlock",
400
+ attrs: { src: attrs.src }
401
+ });
402
+ },
403
+ setImageBlockAt: (attrs) => ({ commands }) => {
404
+ return commands.insertContentAt(attrs.pos, {
405
+ type: "imageBlock",
406
+ attrs: { src: attrs.src }
407
+ });
408
+ },
409
+ setImageBlockAlign: (align) => ({ commands }) => commands.updateAttributes("imageBlock", { align }),
410
+ setImageBlockWidth: (width) => ({ commands }) => commands.updateAttributes("imageBlock", {
411
+ width: `${Math.max(0, Math.min(100, width))}%`
412
+ })
413
+ };
414
+ },
415
+ addNodeView() {
416
+ if (this.options.nodeView) {
417
+ return ReactNodeViewRenderer(this.options.nodeView);
418
+ }
419
+ return null;
420
+ },
421
+ addProseMirrorPlugins() {
422
+ return [
423
+ new Plugin2({
424
+ key: new PluginKey("imageBlockDrop"),
425
+ props: {
426
+ handleDOMEvents: {
427
+ drop: (view, event) => {
428
+ const hasFiles = event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length;
429
+ if (!hasFiles) {
430
+ return false;
431
+ }
432
+ const images = Array.from(event.dataTransfer.files).filter(
433
+ (file) => /image/i.test(file.type)
434
+ );
435
+ if (images.length === 0) {
436
+ return false;
437
+ }
438
+ event.preventDefault();
439
+ const { schema } = view.state;
440
+ const coordinates = view.posAtCoords({
441
+ left: event.clientX,
442
+ top: event.clientY
443
+ });
444
+ if (!coordinates) return false;
445
+ images.forEach(async (image) => {
446
+ if (this.options.uploadImage) {
447
+ try {
448
+ const placeholderNode = schema.nodes.imageBlock.create({
449
+ src: "",
450
+ loading: true
451
+ });
452
+ const placeholderTr = view.state.tr.insert(
453
+ coordinates.pos,
454
+ placeholderNode
455
+ );
456
+ view.dispatch(placeholderTr);
457
+ const url = await this.options.uploadImage(image);
458
+ const node = schema.nodes.imageBlock.create({ src: url });
459
+ const currentState = view.state;
460
+ let foundPos = -1;
461
+ currentState.doc.descendants((node2, pos) => {
462
+ if (node2.type.name === "imageBlock" && node2.attrs.loading) {
463
+ foundPos = pos;
464
+ return false;
465
+ }
466
+ });
467
+ if (foundPos !== -1) {
468
+ const transaction = view.state.tr.replaceWith(
469
+ foundPos,
470
+ foundPos + 1,
471
+ node
472
+ );
473
+ view.dispatch(transaction);
474
+ }
475
+ } catch (error) {
476
+ console.error("Failed to upload image:", error);
477
+ const currentState = view.state;
478
+ let foundPos = -1;
479
+ currentState.doc.descendants((node, pos) => {
480
+ if (node.type.name === "imageBlock" && node.attrs.loading) {
481
+ foundPos = pos;
482
+ return false;
483
+ }
484
+ });
485
+ if (foundPos !== -1) {
486
+ const transaction = view.state.tr.delete(
487
+ foundPos,
488
+ foundPos + 1
489
+ );
490
+ view.dispatch(transaction);
491
+ }
492
+ }
493
+ }
494
+ });
495
+ return true;
496
+ },
497
+ paste: (view, event) => {
498
+ const hasFiles = event.clipboardData && event.clipboardData.files && event.clipboardData.files.length;
499
+ if (!hasFiles) {
500
+ return false;
501
+ }
502
+ const images = Array.from(event.clipboardData.files).filter(
503
+ (file) => /image/i.test(file.type)
504
+ );
505
+ if (images.length === 0) {
506
+ return false;
507
+ }
508
+ event.preventDefault();
509
+ images.forEach(async (image) => {
510
+ if (this.options.uploadImage) {
511
+ try {
512
+ const placeholderNode = view.state.schema.nodes.imageBlock.create({
513
+ src: "",
514
+ loading: true
515
+ });
516
+ view.dispatch(
517
+ view.state.tr.replaceSelectionWith(placeholderNode)
518
+ );
519
+ const url = await this.options.uploadImage(image);
520
+ const node = view.state.schema.nodes.imageBlock.create({
521
+ src: url
522
+ });
523
+ const currentState = view.state;
524
+ let foundPos = -1;
525
+ currentState.doc.descendants((node2, pos) => {
526
+ if (node2.type.name === "imageBlock" && node2.attrs.loading) {
527
+ foundPos = pos;
528
+ return false;
529
+ }
530
+ });
531
+ if (foundPos !== -1) {
532
+ const transaction = view.state.tr.replaceWith(
533
+ foundPos,
534
+ foundPos + 1,
535
+ node
536
+ );
537
+ view.dispatch(transaction);
538
+ }
539
+ } catch (error) {
540
+ console.error("Failed to upload image:", error);
541
+ const currentState = view.state;
542
+ let foundPos = -1;
543
+ currentState.doc.descendants((node, pos) => {
544
+ if (node.type.name === "imageBlock" && node.attrs.loading) {
545
+ foundPos = pos;
546
+ return false;
547
+ }
548
+ });
549
+ if (foundPos !== -1) {
550
+ const transaction = view.state.tr.delete(
551
+ foundPos,
552
+ foundPos + 1
553
+ );
554
+ view.dispatch(transaction);
555
+ }
556
+ }
557
+ }
558
+ });
559
+ return true;
560
+ }
561
+ }
562
+ }
563
+ })
564
+ ];
565
+ }
566
+ });
567
+
568
+ // src/headless/extensions/Mention/mention.tsx
569
+ import { ReactRenderer, ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
570
+ import Mention from "@tiptap/extension-mention";
571
+
572
+ // src/headless/extensions/Mention/mention-command.tsx
573
+ import { forwardRef as forwardRef5, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
574
+ import { jsx as jsx6, jsxs } from "react/jsx-runtime";
575
+ function Avatar({ src, fallback }) {
576
+ return /* @__PURE__ */ jsx6("div", { style: {
577
+ position: "relative",
578
+ display: "flex",
579
+ height: "24px",
580
+ width: "24px",
581
+ flexShrink: 0,
582
+ overflow: "hidden",
583
+ borderRadius: "9999px"
584
+ }, children: src ? /* @__PURE__ */ jsx6(
585
+ "img",
586
+ {
587
+ style: {
588
+ aspectRatio: "1",
589
+ height: "100%",
590
+ width: "100%"
591
+ },
592
+ src,
593
+ alt: fallback
594
+ }
595
+ ) : /* @__PURE__ */ jsx6("div", { style: {
596
+ display: "flex",
597
+ height: "100%",
598
+ width: "100%",
599
+ alignItems: "center",
600
+ justifyContent: "center",
601
+ borderRadius: "9999px",
602
+ backgroundColor: "var(--muted)",
603
+ color: "var(--muted-foreground)",
604
+ fontSize: "10px",
605
+ fontWeight: 600
606
+ }, children: fallback }) });
607
+ }
608
+ function ReferenceIcon({ type }) {
609
+ if (type === "node") {
610
+ return /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { flexShrink: 0 }, children: [
611
+ /* @__PURE__ */ jsx6("path", { d: "M12 3l8 4.5v9l-8 4.5l-8-4.5v-9l8-4.5" }),
612
+ /* @__PURE__ */ jsx6("path", { d: "M12 12l8-4.5" }),
613
+ /* @__PURE__ */ jsx6("path", { d: "M12 12v9" }),
614
+ /* @__PURE__ */ jsx6("path", { d: "M12 12l-8-4.5" })
615
+ ] });
616
+ }
617
+ return /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { flexShrink: 0 }, children: [
618
+ /* @__PURE__ */ jsx6("path", { d: "M14 3v4a1 1 0 0 0 1 1h4" }),
619
+ /* @__PURE__ */ jsx6("path", { d: "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" }),
620
+ /* @__PURE__ */ jsx6("path", { d: "M9 9l1 0" }),
621
+ /* @__PURE__ */ jsx6("path", { d: "M9 13l6 0" }),
622
+ /* @__PURE__ */ jsx6("path", { d: "M9 17l6 0" })
623
+ ] });
624
+ }
625
+ var MentionCommand = forwardRef5((props, ref) => {
626
+ const [selectedIndex, setSelectedIndex] = useState2(0);
627
+ const selectItem = (index) => {
628
+ const item = props.items[index];
629
+ if (item) {
630
+ props.command(item);
631
+ }
632
+ };
633
+ const upHandler = () => {
634
+ setSelectedIndex((selectedIndex + props.items.length - 1) % props.items.length);
635
+ };
636
+ const downHandler = () => {
637
+ setSelectedIndex((selectedIndex + 1) % props.items.length);
638
+ };
639
+ const enterHandler = () => {
640
+ selectItem(selectedIndex);
641
+ };
642
+ useEffect2(() => setSelectedIndex(0), [props.items]);
643
+ useImperativeHandle(ref, () => ({
644
+ onKeyDown: ({ event }) => {
645
+ if (event.key === "ArrowUp") {
646
+ upHandler();
647
+ return true;
648
+ }
649
+ if (event.key === "ArrowDown") {
650
+ downHandler();
651
+ return true;
652
+ }
653
+ if (event.key === "Enter") {
654
+ enterHandler();
655
+ return true;
656
+ }
657
+ return false;
658
+ }
659
+ }));
660
+ return /* @__PURE__ */ jsx6(
661
+ "div",
662
+ {
663
+ id: "mention-list",
664
+ style: {
665
+ backgroundColor: "var(--popover)",
666
+ color: "var(--foreground)",
667
+ maxHeight: "300px",
668
+ minWidth: "280px",
669
+ overflow: "hidden",
670
+ overflowY: "auto",
671
+ borderRadius: "12px",
672
+ border: "1px solid var(--border)",
673
+ padding: "4px",
674
+ boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)"
675
+ },
676
+ children: props.items.length ? props.items.map((item, index) => /* @__PURE__ */ jsxs(
677
+ "button",
678
+ {
679
+ type: "button",
680
+ onClick: () => selectItem(index),
681
+ onMouseEnter: () => setSelectedIndex(index),
682
+ style: {
683
+ position: "relative",
684
+ display: "flex",
685
+ width: "100%",
686
+ cursor: "default",
687
+ userSelect: "none",
688
+ alignItems: "center",
689
+ gap: "8px",
690
+ borderRadius: "4px",
691
+ padding: "10px 8px",
692
+ fontSize: "14px",
693
+ outline: "none",
694
+ backgroundColor: index === selectedIndex ? "var(--accent)" : "transparent",
695
+ color: index === selectedIndex ? "var(--accent-foreground)" : "inherit",
696
+ border: "none",
697
+ textAlign: "left"
698
+ },
699
+ children: [
700
+ item.type ? /* @__PURE__ */ jsx6(ReferenceIcon, { type: item.type }) : /* @__PURE__ */ jsx6(
701
+ Avatar,
702
+ {
703
+ src: item.avatar,
704
+ fallback: item.label.slice(0, 2).toUpperCase()
705
+ }
706
+ ),
707
+ /* @__PURE__ */ jsx6("span", { style: {
708
+ flex: 1,
709
+ overflow: "hidden",
710
+ textOverflow: "ellipsis",
711
+ whiteSpace: "nowrap"
712
+ }, children: item.label })
713
+ ]
714
+ },
715
+ item.id
716
+ )) : /* @__PURE__ */ jsx6("div", { style: {
717
+ padding: "24px 0",
718
+ textAlign: "center",
719
+ fontSize: "14px",
720
+ color: "var(--muted-foreground)"
721
+ }, children: "No results found" })
722
+ }
723
+ );
724
+ });
725
+ MentionCommand.displayName = "MentionCommand";
726
+
727
+ // src/headless/extensions/Mention/mention-node-view.tsx
728
+ import { NodeViewWrapper } from "@tiptap/react";
729
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
730
+ function NodeIcon() {
731
+ return /* @__PURE__ */ jsxs2("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { flexShrink: 0 }, children: [
732
+ /* @__PURE__ */ jsx7("path", { d: "M12 3l8 4.5v9l-8 4.5l-8-4.5v-9l8-4.5" }),
733
+ /* @__PURE__ */ jsx7("path", { d: "M12 12l8-4.5" }),
734
+ /* @__PURE__ */ jsx7("path", { d: "M12 12v9" }),
735
+ /* @__PURE__ */ jsx7("path", { d: "M12 12l-8-4.5" })
736
+ ] });
737
+ }
738
+ function ArticleIcon() {
739
+ return /* @__PURE__ */ jsxs2("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { flexShrink: 0 }, children: [
740
+ /* @__PURE__ */ jsx7("path", { d: "M14 3v4a1 1 0 0 0 1 1h4" }),
741
+ /* @__PURE__ */ jsx7("path", { d: "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z" }),
742
+ /* @__PURE__ */ jsx7("path", { d: "M9 9l1 0" }),
743
+ /* @__PURE__ */ jsx7("path", { d: "M9 13l6 0" }),
744
+ /* @__PURE__ */ jsx7("path", { d: "M9 17l6 0" })
745
+ ] });
746
+ }
747
+ var MentionNodeView = (props) => {
748
+ const { node } = props;
749
+ const { id, label, avatar, type } = node.attrs;
750
+ const isNode = type === "node";
751
+ const isArticle = type === "article";
752
+ const isReference = isNode || isArticle;
753
+ const backgroundColor = isArticle ? "rgba(249, 115, 22, 0.15)" : isNode ? "rgba(107, 114, 128, 0.15)" : "var(--accent)";
754
+ const color = isArticle ? "rgb(234, 88, 12)" : isNode ? "rgb(75, 85, 99)" : "var(--accent-foreground)";
755
+ const border = isArticle ? "1px solid rgba(249, 115, 22, 0.3)" : isNode ? "1px solid rgba(107, 114, 128, 0.3)" : "none";
756
+ return /* @__PURE__ */ jsxs2(
757
+ NodeViewWrapper,
758
+ {
759
+ as: "span",
760
+ style: {
761
+ display: "inline-flex",
762
+ alignItems: "center",
763
+ gap: "3px",
764
+ backgroundColor,
765
+ color,
766
+ border,
767
+ padding: isReference ? "1px 6px" : "1px 6px 1px 1px",
768
+ borderRadius: "12px",
769
+ fontSize: "13px",
770
+ fontWeight: 500,
771
+ verticalAlign: "middle"
772
+ },
773
+ children: [
774
+ isNode && /* @__PURE__ */ jsx7(NodeIcon, {}),
775
+ isArticle && /* @__PURE__ */ jsx7(ArticleIcon, {}),
776
+ !isReference && avatar && /* @__PURE__ */ jsx7(
777
+ "img",
778
+ {
779
+ src: avatar,
780
+ alt: label || id,
781
+ style: {
782
+ width: "20px",
783
+ height: "20px",
784
+ borderRadius: "50%",
785
+ flexShrink: 0
786
+ }
787
+ }
788
+ ),
789
+ !isReference && !avatar && /* @__PURE__ */ jsx7(
790
+ "div",
791
+ {
792
+ style: {
793
+ width: "20px",
794
+ height: "20px",
795
+ borderRadius: "50%",
796
+ backgroundColor: "var(--muted)",
797
+ color: "var(--muted-foreground)",
798
+ display: "flex",
799
+ alignItems: "center",
800
+ justifyContent: "center",
801
+ fontSize: "10px",
802
+ fontWeight: 600,
803
+ flexShrink: 0
804
+ },
805
+ children: (label || id).slice(0, 2).toUpperCase()
806
+ }
807
+ ),
808
+ /* @__PURE__ */ jsx7("span", { children: label || id })
809
+ ]
810
+ }
811
+ );
812
+ };
813
+
814
+ // src/headless/extensions/Mention/mention.tsx
815
+ var createMentionExtension = (options) => {
816
+ const extensionName = options?.name ?? "mention";
817
+ return Mention.extend({
818
+ name: extensionName,
819
+ addAttributes() {
820
+ return {
821
+ id: {
822
+ default: null,
823
+ parseHTML: (element) => element.getAttribute("data-id"),
824
+ renderHTML: (attributes) => {
825
+ if (!attributes.id) {
826
+ return {};
827
+ }
828
+ return {
829
+ "data-id": attributes.id
830
+ };
831
+ }
832
+ },
833
+ label: {
834
+ default: null,
835
+ parseHTML: (element) => element.getAttribute("data-label"),
836
+ renderHTML: (attributes) => {
837
+ if (!attributes.label) {
838
+ return {};
839
+ }
840
+ return {
841
+ "data-label": attributes.label
842
+ };
843
+ }
844
+ },
845
+ avatar: {
846
+ default: null,
847
+ parseHTML: (element) => element.getAttribute("data-avatar"),
848
+ renderHTML: (attributes) => {
849
+ if (!attributes.avatar) {
850
+ return {};
851
+ }
852
+ return {
853
+ "data-avatar": attributes.avatar
854
+ };
855
+ }
856
+ },
857
+ type: {
858
+ default: null,
859
+ parseHTML: (element) => element.getAttribute("data-ref-type"),
860
+ renderHTML: (attributes) => {
861
+ if (!attributes.type) {
862
+ return {};
863
+ }
864
+ return {
865
+ "data-ref-type": attributes.type
866
+ };
867
+ }
868
+ },
869
+ nodeId: {
870
+ default: null,
871
+ parseHTML: (element) => element.getAttribute("data-node-id"),
872
+ renderHTML: (attributes) => {
873
+ if (!attributes.nodeId) {
874
+ return {};
875
+ }
876
+ return {
877
+ "data-node-id": attributes.nodeId
878
+ };
879
+ }
880
+ },
881
+ slug: {
882
+ default: null,
883
+ parseHTML: (element) => element.getAttribute("data-slug"),
884
+ renderHTML: (attributes) => {
885
+ if (!attributes.slug) {
886
+ return {};
887
+ }
888
+ return {
889
+ "data-slug": attributes.slug
890
+ };
891
+ }
892
+ }
893
+ };
894
+ },
895
+ addNodeView() {
896
+ return ReactNodeViewRenderer2(MentionNodeView);
897
+ }
898
+ }).configure({
899
+ HTMLAttributes: {
900
+ class: "mention"
901
+ },
902
+ suggestion: {
903
+ char: options?.char ?? "@",
904
+ items: async ({ query }) => {
905
+ if (!options?.items) return [];
906
+ const items = await options.items(query);
907
+ return items;
908
+ },
909
+ command: ({ editor, range, props: item }) => {
910
+ editor.chain().focus().insertContentAt(range, [
911
+ {
912
+ type: extensionName,
913
+ attrs: {
914
+ id: item.id,
915
+ label: item.label,
916
+ avatar: item.avatar,
917
+ type: item.type,
918
+ nodeId: item.nodeId,
919
+ slug: item.slug
920
+ }
921
+ }
922
+ ]).run();
923
+ },
924
+ render: renderMentionSuggestion
925
+ },
926
+ renderLabel: options?.renderLabel ?? ((props) => {
927
+ return `@${props.node.attrs.label ?? props.node.attrs.id}`;
928
+ })
929
+ });
930
+ };
931
+ var renderMentionSuggestion = () => {
932
+ let component = null;
933
+ let container = null;
934
+ const destroy = () => {
935
+ component?.destroy();
936
+ component = null;
937
+ if (container) {
938
+ container.remove();
939
+ container = null;
940
+ }
941
+ };
942
+ const updatePosition = (clientRect) => {
943
+ if (!container || !clientRect) return;
944
+ const gap = 8;
945
+ const maxDropdownHeight = 300;
946
+ const spaceBelow = window.innerHeight - clientRect.bottom;
947
+ const spaceAbove = clientRect.top;
948
+ const shouldPositionAbove = spaceBelow < maxDropdownHeight && spaceAbove > spaceBelow;
949
+ const left = Math.round(clientRect.left);
950
+ if (shouldPositionAbove) {
951
+ const bottom = Math.round(window.innerHeight - clientRect.top + gap);
952
+ container.style.bottom = `${bottom}px`;
953
+ container.style.top = "auto";
954
+ } else {
955
+ const top = Math.round(clientRect.bottom + gap);
956
+ container.style.top = `${top}px`;
957
+ container.style.bottom = "auto";
958
+ }
959
+ container.style.left = `${left}px`;
960
+ };
961
+ return {
962
+ onStart: (props) => {
963
+ component = new ReactRenderer(MentionCommand, {
964
+ props: {
965
+ items: props.items ?? [],
966
+ command: props.command ?? (() => {
967
+ }),
968
+ query: props.query ?? ""
969
+ },
970
+ editor: props.editor
971
+ });
972
+ container = document.createElement("div");
973
+ container.style.position = "fixed";
974
+ container.style.zIndex = "9999";
975
+ document.body.appendChild(container);
976
+ container.appendChild(component.element);
977
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
978
+ if (rect) updatePosition(rect);
979
+ },
980
+ onUpdate: (props) => {
981
+ component?.updateProps({
982
+ items: props.items ?? [],
983
+ command: props.command ?? (() => {
984
+ }),
985
+ query: props.query ?? ""
986
+ });
987
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
988
+ if (rect) updatePosition(rect);
989
+ },
990
+ onKeyDown: ({ event }) => {
991
+ if (!component) return false;
992
+ if (event.key === "Escape") {
993
+ event.preventDefault();
994
+ event.stopPropagation();
995
+ destroy();
996
+ return true;
997
+ }
998
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
999
+ event.preventDefault();
1000
+ event.stopPropagation();
1001
+ return component.ref?.onKeyDown?.({ event }) ?? false;
1002
+ }
1003
+ return false;
1004
+ },
1005
+ onExit: () => {
1006
+ destroy();
1007
+ }
1008
+ };
1009
+ };
1010
+
1011
+ // src/headless/extensions/DragHandle/DragHandle.ts
1012
+ import BaseDragHandle from "@tiptap/extension-drag-handle";
1013
+ var currentCallbacks = {};
1014
+ var currentNode = null;
1015
+ var currentEditor = null;
1016
+ function setDragHandleCallbacks(callbacks) {
1017
+ currentCallbacks = callbacks;
1018
+ }
1019
+ function createDragHandleElement() {
1020
+ const container = document.createElement("div");
1021
+ container.className = "nph-drag-handle";
1022
+ const plusBtn = document.createElement("button");
1023
+ plusBtn.className = "nph-drag-handle__btn";
1024
+ plusBtn.type = "button";
1025
+ plusBtn.setAttribute("aria-label", "Add block");
1026
+ plusBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/></svg>`;
1027
+ plusBtn.addEventListener("click", (e) => {
1028
+ e.preventDefault();
1029
+ e.stopPropagation();
1030
+ if (currentEditor) {
1031
+ currentCallbacks.onAddBlock?.(currentEditor, currentNode);
1032
+ }
1033
+ });
1034
+ const gripBtn = document.createElement("button");
1035
+ gripBtn.className = "nph-drag-handle__btn nph-drag-handle__grip";
1036
+ gripBtn.type = "button";
1037
+ gripBtn.setAttribute("aria-label", "Drag to reorder");
1038
+ gripBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="5" r="1"/><circle cx="9" cy="12" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="19" r="1"/></svg>`;
1039
+ gripBtn.addEventListener("click", (e) => {
1040
+ e.preventDefault();
1041
+ e.stopPropagation();
1042
+ if (currentEditor) {
1043
+ currentCallbacks.onGripClick?.(currentEditor, currentNode, container);
1044
+ }
1045
+ });
1046
+ container.appendChild(plusBtn);
1047
+ container.appendChild(gripBtn);
1048
+ return container;
1049
+ }
1050
+ var DragHandle = BaseDragHandle.configure({
1051
+ render: createDragHandleElement,
1052
+ nested: true,
1053
+ onNodeChange: ({ node, editor }) => {
1054
+ currentNode = node;
1055
+ currentEditor = editor;
1056
+ }
1057
+ });
1058
+
1059
+ // src/headless/extensions/Table/index.ts
1060
+ import { TableKit } from "@tiptap/extension-table";
1061
+ import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
1062
+
1063
+ // src/headless/extensions/MarkdownPaste.ts
1064
+ import { Extension } from "@tiptap/core";
1065
+ import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1066
+ import { MarkdownParser, defaultMarkdownParser } from "@tiptap/pm/markdown";
1067
+ var markdownPastePluginKey = new PluginKey2("markdownPaste");
1068
+ function looksLikeMarkdown(text) {
1069
+ const patterns = [
1070
+ /^#{1,6}\s/m,
1071
+ // headings
1072
+ /^\s*[-*+]\s/m,
1073
+ // unordered list
1074
+ /^\s*\d+\.\s/m,
1075
+ // ordered list
1076
+ /^\s*>\s/m,
1077
+ // blockquote
1078
+ /\|.+\|/m,
1079
+ // table
1080
+ /^```/m,
1081
+ // fenced code block
1082
+ /\*\*.+\*\*/,
1083
+ // bold
1084
+ /\*.+\*/,
1085
+ // italic
1086
+ /~~.+~~/,
1087
+ // strikethrough
1088
+ /`[^`]+`/,
1089
+ // inline code
1090
+ /^\s*---\s*$/m,
1091
+ // horizontal rule
1092
+ /^\s*\*\*\*\s*$/m,
1093
+ // horizontal rule alt
1094
+ /\[.+\]\(.+\)/,
1095
+ // links
1096
+ /!\[.*\]\(.+\)/
1097
+ // images
1098
+ ];
1099
+ const hasMarkdown = patterns.some((p) => p.test(text));
1100
+ const isHtml = /^<[a-z][\s\S]*>/i.test(text.trim());
1101
+ return hasMarkdown && !isHtml;
1102
+ }
1103
+ function buildParser(schema) {
1104
+ const md = defaultMarkdownParser.tokenizer;
1105
+ const tokens = {};
1106
+ if (schema.nodes.paragraph) tokens.paragraph = { block: "paragraph" };
1107
+ if (schema.nodes.heading) {
1108
+ tokens.heading = {
1109
+ block: "heading",
1110
+ getAttrs: (tok) => ({ level: Number(tok.tag.slice(1)) })
1111
+ };
1112
+ }
1113
+ if (schema.nodes.blockquote) tokens.blockquote = { block: "blockquote" };
1114
+ if (schema.nodes.bulletList) tokens.bullet_list = { block: "bulletList" };
1115
+ if (schema.nodes.orderedList) {
1116
+ tokens.ordered_list = {
1117
+ block: "orderedList",
1118
+ getAttrs: (tok) => ({ start: Number(tok.attrGet("start") || 1) })
1119
+ };
1120
+ }
1121
+ if (schema.nodes.listItem) tokens.list_item = { block: "listItem" };
1122
+ if (schema.nodes.codeBlock) {
1123
+ tokens.code_block = { block: "codeBlock", noCloseToken: true };
1124
+ tokens.fence = {
1125
+ block: "codeBlock",
1126
+ getAttrs: (tok) => ({ language: tok.info || "" }),
1127
+ noCloseToken: true
1128
+ };
1129
+ }
1130
+ if (schema.nodes.horizontalRule) {
1131
+ tokens.hr = { node: "horizontalRule" };
1132
+ }
1133
+ if (schema.nodes.hardBreak) {
1134
+ tokens.hardbreak = { node: "hardBreak" };
1135
+ }
1136
+ if (schema.nodes.image) {
1137
+ tokens.image = {
1138
+ node: "image",
1139
+ getAttrs: (tok) => ({
1140
+ src: tok.attrGet("src"),
1141
+ title: tok.attrGet("title") || null,
1142
+ alt: tok.children?.[0]?.content || null
1143
+ })
1144
+ };
1145
+ }
1146
+ if (schema.nodes.table) {
1147
+ tokens.table = { block: "table" };
1148
+ tokens.thead = { ignore: true };
1149
+ tokens.tbody = { ignore: true };
1150
+ tokens.tr = { block: "tableRow" };
1151
+ tokens.th = { block: "tableHeader" };
1152
+ tokens.td = { block: "tableCell" };
1153
+ }
1154
+ if (schema.marks.bold || schema.marks.strong) {
1155
+ tokens.strong = { mark: schema.marks.bold ? "bold" : "strong" };
1156
+ }
1157
+ if (schema.marks.italic || schema.marks.em) {
1158
+ tokens.em = { mark: schema.marks.italic ? "italic" : "em" };
1159
+ }
1160
+ if (schema.marks.code) {
1161
+ tokens.code_inline = { mark: "code", noCloseToken: true };
1162
+ }
1163
+ if (schema.marks.link) {
1164
+ tokens.link = {
1165
+ mark: "link",
1166
+ getAttrs: (tok) => ({
1167
+ href: tok.attrGet("href"),
1168
+ title: tok.attrGet("title") || null
1169
+ })
1170
+ };
1171
+ }
1172
+ if (schema.marks.strike || schema.marks.strikethrough) {
1173
+ tokens.s = { mark: schema.marks.strike ? "strike" : "strikethrough" };
1174
+ }
1175
+ try {
1176
+ return new MarkdownParser(schema, md, tokens);
1177
+ } catch {
1178
+ return null;
1179
+ }
1180
+ }
1181
+ var MarkdownPaste = Extension.create({
1182
+ name: "markdownPaste",
1183
+ addProseMirrorPlugins() {
1184
+ const schema = this.editor.schema;
1185
+ let parser = null;
1186
+ return [
1187
+ new Plugin3({
1188
+ key: markdownPastePluginKey,
1189
+ props: {
1190
+ handlePaste(view, event) {
1191
+ const clipboardData = event.clipboardData;
1192
+ if (!clipboardData) return false;
1193
+ const html = clipboardData.getData("text/html");
1194
+ if (html && html.trim().length > 0) return false;
1195
+ const text = clipboardData.getData("text/plain");
1196
+ if (!text || !looksLikeMarkdown(text)) return false;
1197
+ if (!parser) {
1198
+ parser = buildParser(schema);
1199
+ }
1200
+ if (!parser) return false;
1201
+ try {
1202
+ const doc = parser.parse(text);
1203
+ if (!doc || doc.content.size === 0) return false;
1204
+ const { tr } = view.state;
1205
+ const slice = doc.slice(0, doc.content.size);
1206
+ tr.replaceSelection(slice);
1207
+ view.dispatch(tr);
1208
+ return true;
1209
+ } catch {
1210
+ return false;
1211
+ }
1212
+ }
1213
+ }
1214
+ })
1215
+ ];
1216
+ }
1217
+ });
1218
+
1219
+ // src/headless/extensions/slash-command.tsx
1220
+ import Suggestion from "@tiptap/suggestion";
1221
+ import { Extension as Extension2 } from "@tiptap/core";
1222
+ var Command = Extension2.create({
1223
+ name: "slash-command",
1224
+ addOptions() {
1225
+ return {
1226
+ suggestion: {
1227
+ char: "/",
1228
+ command: (ctx) => {
1229
+ ctx.props.command({ editor: ctx.editor, range: ctx.range });
1230
+ }
1231
+ }
1232
+ };
1233
+ },
1234
+ addProseMirrorPlugins() {
1235
+ const base = this.options.suggestion ?? {};
1236
+ return [
1237
+ Suggestion({
1238
+ editor: this.editor,
1239
+ char: base.char ?? "/",
1240
+ startOfLine: base.startOfLine ?? true,
1241
+ items: base.items ?? (() => ["/"]),
1242
+ command: (ctx) => {
1243
+ if (typeof ctx?.props?.command === "function") {
1244
+ ctx.props.command({ editor: ctx.editor, range: ctx.range });
1245
+ }
1246
+ },
1247
+ ...base,
1248
+ render: () => {
1249
+ return {
1250
+ onStart: (props) => {
1251
+ const { selection } = props.editor.state;
1252
+ const parentNode = selection.$from.node(selection.$from.depth);
1253
+ const blockType = parentNode.type.name;
1254
+ if (blockType === "codeBlock") return false;
1255
+ const { $from } = selection;
1256
+ const marks = $from.marks();
1257
+ if (marks.some((mark) => mark.type.name === "code" || mark.type.name === "link")) {
1258
+ return false;
1259
+ }
1260
+ novelStore.set(queryAtom, props.query ?? "");
1261
+ novelStore.set(rangeAtom, props.range ?? null);
1262
+ novelStore.set(slashMenuOpenAtom, true);
1263
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1264
+ novelStore.set(slashMenuRectAtom, rect);
1265
+ },
1266
+ onUpdate: (props) => {
1267
+ novelStore.set(queryAtom, props.query ?? "");
1268
+ novelStore.set(rangeAtom, props.range ?? null);
1269
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1270
+ novelStore.set(slashMenuRectAtom, rect);
1271
+ },
1272
+ onKeyDown: ({ event }) => {
1273
+ if (event.key === "Escape") {
1274
+ novelStore.set(slashMenuOpenAtom, false);
1275
+ return true;
1276
+ }
1277
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
1278
+ const slashCommand = document.querySelector("#slash-command");
1279
+ if (slashCommand) {
1280
+ slashCommand.dispatchEvent(
1281
+ new KeyboardEvent("keydown", {
1282
+ key: event.key,
1283
+ cancelable: true,
1284
+ bubbles: true
1285
+ })
1286
+ );
1287
+ return true;
1288
+ }
1289
+ }
1290
+ return false;
1291
+ },
1292
+ onExit: () => {
1293
+ novelStore.set(slashMenuOpenAtom, false);
1294
+ novelStore.set(queryAtom, "");
1295
+ novelStore.set(rangeAtom, null);
1296
+ novelStore.set(slashMenuRectAtom, null);
1297
+ }
1298
+ };
1299
+ }
1300
+ })
1301
+ ];
1302
+ }
1303
+ });
1304
+ var renderItems = () => ({
1305
+ onStart: () => {
1306
+ },
1307
+ onUpdate: () => {
1308
+ },
1309
+ onKeyDown: () => false,
1310
+ onExit: () => {
1311
+ }
1312
+ });
1313
+ var createSuggestionItems = (items) => items;
1314
+ var handleCommandNavigation = (event) => {
1315
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
1316
+ const slashCommand = document.querySelector("#slash-command");
1317
+ if (slashCommand) return true;
1318
+ }
1319
+ };
1320
+
1321
+ export {
1322
+ novelStore,
1323
+ store_exports,
1324
+ EditorRoot,
1325
+ EditorContent,
1326
+ EditorBubble,
1327
+ EditorBubbleItem,
1328
+ queryAtom,
1329
+ EditorCommandOut,
1330
+ EditorCommand,
1331
+ EditorCommandList,
1332
+ EditorCommandItem,
1333
+ EditorCommandEmpty,
1334
+ CodeBlock,
1335
+ Link,
1336
+ ImageBlock,
1337
+ MentionCommand,
1338
+ createMentionExtension,
1339
+ renderMentionSuggestion,
1340
+ setDragHandleCallbacks,
1341
+ DragHandle,
1342
+ TableKit,
1343
+ MarkdownPaste,
1344
+ StarterKit,
1345
+ Placeholder,
1346
+ Command,
1347
+ renderItems,
1348
+ createSuggestionItems,
1349
+ handleCommandNavigation,
1350
+ useCurrentEditor4 as useCurrentEditor
1351
+ };
1352
+ //# sourceMappingURL=chunk-G5E32MLB.js.map