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