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