neuphlo-editor 2.3.0 → 2.4.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,1387 @@
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
+ inline: false
335
+ };
336
+ },
337
+ addAttributes() {
338
+ return {
339
+ src: {
340
+ default: "",
341
+ parseHTML: (element) => element.getAttribute("src"),
342
+ renderHTML: (attributes) => ({
343
+ src: attributes.src
344
+ })
345
+ },
346
+ width: {
347
+ default: "100%",
348
+ parseHTML: (element) => element.getAttribute("data-width"),
349
+ renderHTML: (attributes) => ({
350
+ "data-width": attributes.width
351
+ })
352
+ },
353
+ align: {
354
+ default: "center",
355
+ parseHTML: (element) => element.getAttribute("data-align"),
356
+ renderHTML: (attributes) => ({
357
+ "data-align": attributes.align
358
+ })
359
+ },
360
+ alt: {
361
+ default: void 0,
362
+ parseHTML: (element) => element.getAttribute("alt"),
363
+ renderHTML: (attributes) => ({
364
+ alt: attributes.alt
365
+ })
366
+ },
367
+ loading: {
368
+ default: false,
369
+ parseHTML: () => false,
370
+ renderHTML: () => ({})
371
+ }
372
+ };
373
+ },
374
+ parseHTML() {
375
+ return [
376
+ {
377
+ tag: 'img[src]:not([src^="data:"])',
378
+ getAttrs: (element) => {
379
+ const el = element;
380
+ return {
381
+ src: el.getAttribute("src"),
382
+ alt: el.getAttribute("alt"),
383
+ width: el.getAttribute("data-width") || "100%",
384
+ align: el.getAttribute("data-align") || "center"
385
+ };
386
+ }
387
+ }
388
+ ];
389
+ },
390
+ renderHTML({ HTMLAttributes }) {
391
+ return ["img", mergeAttributes2(HTMLAttributes)];
392
+ },
393
+ addCommands() {
394
+ return {
395
+ setImageBlock: (attrs) => ({ commands }) => {
396
+ return commands.insertContent({
397
+ type: "imageBlock",
398
+ attrs: { src: attrs.src }
399
+ });
400
+ },
401
+ setImageBlockAt: (attrs) => ({ commands }) => {
402
+ return commands.insertContentAt(attrs.pos, {
403
+ type: "imageBlock",
404
+ attrs: { src: attrs.src }
405
+ });
406
+ },
407
+ setImageBlockAlign: (align) => ({ commands }) => commands.updateAttributes("imageBlock", { align }),
408
+ setImageBlockWidth: (width) => ({ commands }) => commands.updateAttributes("imageBlock", {
409
+ width: `${Math.max(0, Math.min(100, width))}%`
410
+ })
411
+ };
412
+ },
413
+ addNodeView() {
414
+ if (this.options.nodeView) {
415
+ return ReactNodeViewRenderer(this.options.nodeView);
416
+ }
417
+ return null;
418
+ },
419
+ addProseMirrorPlugins() {
420
+ return [
421
+ new Plugin2({
422
+ key: new PluginKey("imageBlockDrop"),
423
+ props: {
424
+ handleDOMEvents: {
425
+ drop: (view, event) => {
426
+ const hasFiles = event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length;
427
+ if (!hasFiles) {
428
+ return false;
429
+ }
430
+ const images = Array.from(event.dataTransfer.files).filter(
431
+ (file) => /image/i.test(file.type)
432
+ );
433
+ if (images.length === 0) {
434
+ return false;
435
+ }
436
+ event.preventDefault();
437
+ const { schema } = view.state;
438
+ const coordinates = view.posAtCoords({
439
+ left: event.clientX,
440
+ top: event.clientY
441
+ });
442
+ if (!coordinates) return false;
443
+ images.forEach(async (image) => {
444
+ if (this.options.uploadImage) {
445
+ try {
446
+ const placeholderNode = schema.nodes.imageBlock.create({
447
+ src: "",
448
+ loading: true
449
+ });
450
+ const placeholderTr = view.state.tr.insert(
451
+ coordinates.pos,
452
+ placeholderNode
453
+ );
454
+ view.dispatch(placeholderTr);
455
+ const url = await this.options.uploadImage(image);
456
+ const node = schema.nodes.imageBlock.create({ src: url });
457
+ const currentState = view.state;
458
+ let foundPos = -1;
459
+ currentState.doc.descendants((node2, pos) => {
460
+ if (node2.type.name === "imageBlock" && node2.attrs.loading) {
461
+ foundPos = pos;
462
+ return false;
463
+ }
464
+ });
465
+ if (foundPos !== -1) {
466
+ const transaction = view.state.tr.replaceWith(
467
+ foundPos,
468
+ foundPos + 1,
469
+ node
470
+ );
471
+ view.dispatch(transaction);
472
+ }
473
+ } catch (error) {
474
+ console.error("Failed to upload image:", error);
475
+ const currentState = view.state;
476
+ let foundPos = -1;
477
+ currentState.doc.descendants((node, pos) => {
478
+ if (node.type.name === "imageBlock" && node.attrs.loading) {
479
+ foundPos = pos;
480
+ return false;
481
+ }
482
+ });
483
+ if (foundPos !== -1) {
484
+ const transaction = view.state.tr.delete(
485
+ foundPos,
486
+ foundPos + 1
487
+ );
488
+ view.dispatch(transaction);
489
+ }
490
+ }
491
+ }
492
+ });
493
+ return true;
494
+ },
495
+ paste: (view, event) => {
496
+ const hasFiles = event.clipboardData && event.clipboardData.files && event.clipboardData.files.length;
497
+ if (!hasFiles) {
498
+ return false;
499
+ }
500
+ const images = Array.from(event.clipboardData.files).filter(
501
+ (file) => /image/i.test(file.type)
502
+ );
503
+ if (images.length === 0) {
504
+ return false;
505
+ }
506
+ event.preventDefault();
507
+ images.forEach(async (image) => {
508
+ if (this.options.uploadImage) {
509
+ try {
510
+ const placeholderNode = view.state.schema.nodes.imageBlock.create({
511
+ src: "",
512
+ loading: true
513
+ });
514
+ view.dispatch(
515
+ view.state.tr.replaceSelectionWith(placeholderNode)
516
+ );
517
+ const url = await this.options.uploadImage(image);
518
+ const node = view.state.schema.nodes.imageBlock.create({
519
+ src: url
520
+ });
521
+ const currentState = view.state;
522
+ let foundPos = -1;
523
+ currentState.doc.descendants((node2, pos) => {
524
+ if (node2.type.name === "imageBlock" && node2.attrs.loading) {
525
+ foundPos = pos;
526
+ return false;
527
+ }
528
+ });
529
+ if (foundPos !== -1) {
530
+ const transaction = view.state.tr.replaceWith(
531
+ foundPos,
532
+ foundPos + 1,
533
+ node
534
+ );
535
+ view.dispatch(transaction);
536
+ }
537
+ } catch (error) {
538
+ console.error("Failed to upload image:", error);
539
+ const currentState = view.state;
540
+ let foundPos = -1;
541
+ currentState.doc.descendants((node, pos) => {
542
+ if (node.type.name === "imageBlock" && node.attrs.loading) {
543
+ foundPos = pos;
544
+ return false;
545
+ }
546
+ });
547
+ if (foundPos !== -1) {
548
+ const transaction = view.state.tr.delete(
549
+ foundPos,
550
+ foundPos + 1
551
+ );
552
+ view.dispatch(transaction);
553
+ }
554
+ }
555
+ }
556
+ });
557
+ return true;
558
+ }
559
+ }
560
+ }
561
+ })
562
+ ];
563
+ }
564
+ });
565
+
566
+ // src/headless/extensions/Mention/mention.tsx
567
+ import { ReactRenderer, ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
568
+ import Mention from "@tiptap/extension-mention";
569
+
570
+ // src/headless/extensions/Mention/mention-command.tsx
571
+ import { forwardRef as forwardRef5, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
572
+ import { jsx as jsx6, jsxs } from "react/jsx-runtime";
573
+ function Avatar({ src, fallback }) {
574
+ return /* @__PURE__ */ jsx6("div", { style: {
575
+ position: "relative",
576
+ display: "flex",
577
+ height: "24px",
578
+ width: "24px",
579
+ flexShrink: 0,
580
+ overflow: "hidden",
581
+ borderRadius: "9999px"
582
+ }, children: src ? /* @__PURE__ */ jsx6(
583
+ "img",
584
+ {
585
+ style: {
586
+ aspectRatio: "1",
587
+ height: "100%",
588
+ width: "100%"
589
+ },
590
+ src,
591
+ alt: fallback
592
+ }
593
+ ) : /* @__PURE__ */ jsx6("div", { style: {
594
+ display: "flex",
595
+ height: "100%",
596
+ width: "100%",
597
+ alignItems: "center",
598
+ justifyContent: "center",
599
+ borderRadius: "9999px",
600
+ backgroundColor: "var(--muted)",
601
+ color: "var(--muted-foreground)",
602
+ fontSize: "10px",
603
+ fontWeight: 600
604
+ }, children: fallback }) });
605
+ }
606
+ function ReferenceIcon({ type }) {
607
+ if (type === "node") {
608
+ 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: [
609
+ /* @__PURE__ */ jsx6("path", { d: "M12 3l8 4.5v9l-8 4.5l-8-4.5v-9l8-4.5" }),
610
+ /* @__PURE__ */ jsx6("path", { d: "M12 12l8-4.5" }),
611
+ /* @__PURE__ */ jsx6("path", { d: "M12 12v9" }),
612
+ /* @__PURE__ */ jsx6("path", { d: "M12 12l-8-4.5" })
613
+ ] });
614
+ }
615
+ 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: [
616
+ /* @__PURE__ */ jsx6("path", { d: "M14 3v4a1 1 0 0 0 1 1h4" }),
617
+ /* @__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" }),
618
+ /* @__PURE__ */ jsx6("path", { d: "M9 9l1 0" }),
619
+ /* @__PURE__ */ jsx6("path", { d: "M9 13l6 0" }),
620
+ /* @__PURE__ */ jsx6("path", { d: "M9 17l6 0" })
621
+ ] });
622
+ }
623
+ var MentionCommand = forwardRef5((props, ref) => {
624
+ const [selectedIndex, setSelectedIndex] = useState2(0);
625
+ const selectItem = (index) => {
626
+ const item = props.items[index];
627
+ if (item) {
628
+ props.command(item);
629
+ }
630
+ };
631
+ const upHandler = () => {
632
+ setSelectedIndex((selectedIndex + props.items.length - 1) % props.items.length);
633
+ };
634
+ const downHandler = () => {
635
+ setSelectedIndex((selectedIndex + 1) % props.items.length);
636
+ };
637
+ const enterHandler = () => {
638
+ selectItem(selectedIndex);
639
+ };
640
+ useEffect2(() => setSelectedIndex(0), [props.items]);
641
+ useImperativeHandle(ref, () => ({
642
+ onKeyDown: ({ event }) => {
643
+ if (event.key === "ArrowUp") {
644
+ upHandler();
645
+ return true;
646
+ }
647
+ if (event.key === "ArrowDown") {
648
+ downHandler();
649
+ return true;
650
+ }
651
+ if (event.key === "Enter") {
652
+ enterHandler();
653
+ return true;
654
+ }
655
+ return false;
656
+ }
657
+ }));
658
+ return /* @__PURE__ */ jsx6(
659
+ "div",
660
+ {
661
+ id: "mention-list",
662
+ style: {
663
+ backgroundColor: "var(--popover)",
664
+ color: "var(--foreground)",
665
+ maxHeight: "300px",
666
+ minWidth: "280px",
667
+ overflow: "hidden",
668
+ overflowY: "auto",
669
+ borderRadius: "12px",
670
+ border: "1px solid var(--border)",
671
+ padding: "4px",
672
+ boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)"
673
+ },
674
+ children: props.items.length ? props.items.map((item, index) => /* @__PURE__ */ jsxs(
675
+ "button",
676
+ {
677
+ type: "button",
678
+ onClick: () => selectItem(index),
679
+ onMouseEnter: () => setSelectedIndex(index),
680
+ style: {
681
+ position: "relative",
682
+ display: "flex",
683
+ width: "100%",
684
+ cursor: "default",
685
+ userSelect: "none",
686
+ alignItems: "center",
687
+ gap: "8px",
688
+ borderRadius: "4px",
689
+ padding: "10px 8px",
690
+ fontSize: "14px",
691
+ outline: "none",
692
+ backgroundColor: index === selectedIndex ? "var(--accent)" : "transparent",
693
+ color: index === selectedIndex ? "var(--accent-foreground)" : "inherit",
694
+ border: "none",
695
+ textAlign: "left"
696
+ },
697
+ children: [
698
+ item.type ? /* @__PURE__ */ jsx6(ReferenceIcon, { type: item.type }) : /* @__PURE__ */ jsx6(
699
+ Avatar,
700
+ {
701
+ src: item.avatar,
702
+ fallback: item.label.slice(0, 2).toUpperCase()
703
+ }
704
+ ),
705
+ /* @__PURE__ */ jsx6("span", { style: {
706
+ flex: 1,
707
+ overflow: "hidden",
708
+ textOverflow: "ellipsis",
709
+ whiteSpace: "nowrap"
710
+ }, children: item.label })
711
+ ]
712
+ },
713
+ item.id
714
+ )) : /* @__PURE__ */ jsx6("div", { style: {
715
+ padding: "24px 0",
716
+ textAlign: "center",
717
+ fontSize: "14px",
718
+ color: "var(--muted-foreground)"
719
+ }, children: "No results found" })
720
+ }
721
+ );
722
+ });
723
+ MentionCommand.displayName = "MentionCommand";
724
+
725
+ // src/headless/extensions/Mention/mention-node-view.tsx
726
+ import { NodeViewWrapper } from "@tiptap/react";
727
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
728
+ var GRADIENT_MAP = {
729
+ red: "linear-gradient(135deg, #ef4444, #fb7185)",
730
+ coral: "linear-gradient(135deg, #f87171, #fb923c)",
731
+ orange: "linear-gradient(135deg, #f97316, #fbbf24)",
732
+ amber: "linear-gradient(135deg, #f59e0b, #facc15)",
733
+ lime: "linear-gradient(135deg, #84cc16, #4ade80)",
734
+ green: "linear-gradient(135deg, #10b981, #2dd4bf)",
735
+ teal: "linear-gradient(135deg, #14b8a6, #22d3ee)",
736
+ cyan: "linear-gradient(135deg, #06b6d4, #60a5fa)",
737
+ blue: "linear-gradient(135deg, #3b82f6, #818cf8)",
738
+ indigo: "linear-gradient(135deg, #6366f1, #a78bfa)",
739
+ violet: "linear-gradient(135deg, #8b5cf6, #a855f7)",
740
+ purple: "linear-gradient(135deg, #a855f7, #d946ef)",
741
+ fuchsia: "linear-gradient(135deg, #d946ef, #f472b6)",
742
+ pink: "linear-gradient(135deg, #ec4899, #fb7185)",
743
+ slate: "linear-gradient(135deg, #64748b, #71717a)",
744
+ stone: "linear-gradient(135deg, #78716c, #a3a3a3)"
745
+ };
746
+ function NodeIcon() {
747
+ 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: [
748
+ /* @__PURE__ */ jsx7("path", { d: "M12 3l8 4.5v9l-8 4.5l-8-4.5v-9l8-4.5" }),
749
+ /* @__PURE__ */ jsx7("path", { d: "M12 12l8-4.5" }),
750
+ /* @__PURE__ */ jsx7("path", { d: "M12 12v9" }),
751
+ /* @__PURE__ */ jsx7("path", { d: "M12 12l-8-4.5" })
752
+ ] });
753
+ }
754
+ function ArticleIcon() {
755
+ 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: [
756
+ /* @__PURE__ */ jsx7("path", { d: "M14 3v4a1 1 0 0 0 1 1h4" }),
757
+ /* @__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" }),
758
+ /* @__PURE__ */ jsx7("path", { d: "M9 9l1 0" }),
759
+ /* @__PURE__ */ jsx7("path", { d: "M9 13l6 0" }),
760
+ /* @__PURE__ */ jsx7("path", { d: "M9 17l6 0" })
761
+ ] });
762
+ }
763
+ var MentionNodeView = (props) => {
764
+ const { node } = props;
765
+ const { id, label, avatar, type } = node.attrs;
766
+ const isNode = type === "node";
767
+ const isArticle = type === "article";
768
+ const isReference = isNode || isArticle;
769
+ const backgroundColor = isArticle ? "rgba(249, 115, 22, 0.15)" : isNode ? "rgba(107, 114, 128, 0.15)" : "var(--accent)";
770
+ const color = isArticle ? "rgb(234, 88, 12)" : isNode ? "rgb(75, 85, 99)" : "var(--accent-foreground)";
771
+ const border = isArticle ? "1px solid rgba(249, 115, 22, 0.3)" : isNode ? "1px solid rgba(107, 114, 128, 0.3)" : "none";
772
+ return /* @__PURE__ */ jsxs2(
773
+ NodeViewWrapper,
774
+ {
775
+ as: "span",
776
+ style: {
777
+ display: "inline-flex",
778
+ alignItems: "center",
779
+ gap: "3px",
780
+ backgroundColor,
781
+ color,
782
+ border,
783
+ padding: isReference ? "1px 6px" : "1px 6px 1px 1px",
784
+ borderRadius: "12px",
785
+ fontSize: "13px",
786
+ fontWeight: 500,
787
+ verticalAlign: "middle"
788
+ },
789
+ children: [
790
+ isNode && /* @__PURE__ */ jsx7(NodeIcon, {}),
791
+ isArticle && /* @__PURE__ */ jsx7(ArticleIcon, {}),
792
+ !isReference && avatar && avatar in GRADIENT_MAP && /* @__PURE__ */ jsx7(
793
+ "div",
794
+ {
795
+ style: {
796
+ width: "20px",
797
+ height: "20px",
798
+ borderRadius: "50%",
799
+ background: GRADIENT_MAP[avatar],
800
+ color: "#ffffff",
801
+ display: "flex",
802
+ alignItems: "center",
803
+ justifyContent: "center",
804
+ fontSize: "8px",
805
+ fontWeight: 600,
806
+ flexShrink: 0
807
+ },
808
+ children: (label || id).split(/\s+/).map((w) => w[0]).join("").slice(0, 2).toUpperCase()
809
+ }
810
+ ),
811
+ !isReference && avatar && !(avatar in GRADIENT_MAP) && /* @__PURE__ */ jsx7(
812
+ "img",
813
+ {
814
+ src: avatar,
815
+ alt: label || id,
816
+ style: {
817
+ width: "20px",
818
+ height: "20px",
819
+ borderRadius: "50%",
820
+ flexShrink: 0
821
+ }
822
+ }
823
+ ),
824
+ !isReference && !avatar && /* @__PURE__ */ jsx7(
825
+ "div",
826
+ {
827
+ style: {
828
+ width: "20px",
829
+ height: "20px",
830
+ borderRadius: "50%",
831
+ backgroundColor: "var(--muted)",
832
+ color: "var(--muted-foreground)",
833
+ display: "flex",
834
+ alignItems: "center",
835
+ justifyContent: "center",
836
+ fontSize: "10px",
837
+ fontWeight: 600,
838
+ flexShrink: 0
839
+ },
840
+ children: (label || id).slice(0, 2).toUpperCase()
841
+ }
842
+ ),
843
+ /* @__PURE__ */ jsx7("span", { children: label || id })
844
+ ]
845
+ }
846
+ );
847
+ };
848
+
849
+ // src/headless/extensions/Mention/mention.tsx
850
+ var createMentionExtension = (options) => {
851
+ const extensionName = options?.name ?? "mention";
852
+ return Mention.extend({
853
+ name: extensionName,
854
+ addAttributes() {
855
+ return {
856
+ id: {
857
+ default: null,
858
+ parseHTML: (element) => element.getAttribute("data-id"),
859
+ renderHTML: (attributes) => {
860
+ if (!attributes.id) {
861
+ return {};
862
+ }
863
+ return {
864
+ "data-id": attributes.id
865
+ };
866
+ }
867
+ },
868
+ label: {
869
+ default: null,
870
+ parseHTML: (element) => element.getAttribute("data-label"),
871
+ renderHTML: (attributes) => {
872
+ if (!attributes.label) {
873
+ return {};
874
+ }
875
+ return {
876
+ "data-label": attributes.label
877
+ };
878
+ }
879
+ },
880
+ avatar: {
881
+ default: null,
882
+ parseHTML: (element) => element.getAttribute("data-avatar"),
883
+ renderHTML: (attributes) => {
884
+ if (!attributes.avatar) {
885
+ return {};
886
+ }
887
+ return {
888
+ "data-avatar": attributes.avatar
889
+ };
890
+ }
891
+ },
892
+ type: {
893
+ default: null,
894
+ parseHTML: (element) => element.getAttribute("data-ref-type"),
895
+ renderHTML: (attributes) => {
896
+ if (!attributes.type) {
897
+ return {};
898
+ }
899
+ return {
900
+ "data-ref-type": attributes.type
901
+ };
902
+ }
903
+ },
904
+ nodeId: {
905
+ default: null,
906
+ parseHTML: (element) => element.getAttribute("data-node-id"),
907
+ renderHTML: (attributes) => {
908
+ if (!attributes.nodeId) {
909
+ return {};
910
+ }
911
+ return {
912
+ "data-node-id": attributes.nodeId
913
+ };
914
+ }
915
+ },
916
+ slug: {
917
+ default: null,
918
+ parseHTML: (element) => element.getAttribute("data-slug"),
919
+ renderHTML: (attributes) => {
920
+ if (!attributes.slug) {
921
+ return {};
922
+ }
923
+ return {
924
+ "data-slug": attributes.slug
925
+ };
926
+ }
927
+ }
928
+ };
929
+ },
930
+ addNodeView() {
931
+ return ReactNodeViewRenderer2(MentionNodeView);
932
+ }
933
+ }).configure({
934
+ HTMLAttributes: {
935
+ class: "mention"
936
+ },
937
+ suggestion: {
938
+ char: options?.char ?? "@",
939
+ items: async ({ query }) => {
940
+ if (!options?.items) return [];
941
+ const items = await options.items(query);
942
+ return items;
943
+ },
944
+ command: ({ editor, range, props: item }) => {
945
+ editor.chain().focus().insertContentAt(range, [
946
+ {
947
+ type: extensionName,
948
+ attrs: {
949
+ id: item.id,
950
+ label: item.label,
951
+ avatar: item.avatar,
952
+ type: item.type,
953
+ nodeId: item.nodeId,
954
+ slug: item.slug
955
+ }
956
+ }
957
+ ]).run();
958
+ },
959
+ render: renderMentionSuggestion
960
+ },
961
+ renderLabel: options?.renderLabel ?? ((props) => {
962
+ return `@${props.node.attrs.label ?? props.node.attrs.id}`;
963
+ })
964
+ });
965
+ };
966
+ var renderMentionSuggestion = () => {
967
+ let component = null;
968
+ let container = null;
969
+ const destroy = () => {
970
+ component?.destroy();
971
+ component = null;
972
+ if (container) {
973
+ container.remove();
974
+ container = null;
975
+ }
976
+ };
977
+ const updatePosition = (clientRect) => {
978
+ if (!container || !clientRect) return;
979
+ const gap = 8;
980
+ const maxDropdownHeight = 300;
981
+ const spaceBelow = window.innerHeight - clientRect.bottom;
982
+ const spaceAbove = clientRect.top;
983
+ const shouldPositionAbove = spaceBelow < maxDropdownHeight && spaceAbove > spaceBelow;
984
+ const left = Math.round(clientRect.left);
985
+ if (shouldPositionAbove) {
986
+ const bottom = Math.round(window.innerHeight - clientRect.top + gap);
987
+ container.style.bottom = `${bottom}px`;
988
+ container.style.top = "auto";
989
+ } else {
990
+ const top = Math.round(clientRect.bottom + gap);
991
+ container.style.top = `${top}px`;
992
+ container.style.bottom = "auto";
993
+ }
994
+ container.style.left = `${left}px`;
995
+ };
996
+ return {
997
+ onStart: (props) => {
998
+ component = new ReactRenderer(MentionCommand, {
999
+ props: {
1000
+ items: props.items ?? [],
1001
+ command: props.command ?? (() => {
1002
+ }),
1003
+ query: props.query ?? ""
1004
+ },
1005
+ editor: props.editor
1006
+ });
1007
+ container = document.createElement("div");
1008
+ container.style.position = "fixed";
1009
+ container.style.zIndex = "9999";
1010
+ document.body.appendChild(container);
1011
+ container.appendChild(component.element);
1012
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1013
+ if (rect) updatePosition(rect);
1014
+ },
1015
+ onUpdate: (props) => {
1016
+ component?.updateProps({
1017
+ items: props.items ?? [],
1018
+ command: props.command ?? (() => {
1019
+ }),
1020
+ query: props.query ?? ""
1021
+ });
1022
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1023
+ if (rect) updatePosition(rect);
1024
+ },
1025
+ onKeyDown: ({ event }) => {
1026
+ if (!component) return false;
1027
+ if (event.key === "Escape") {
1028
+ event.preventDefault();
1029
+ event.stopPropagation();
1030
+ destroy();
1031
+ return true;
1032
+ }
1033
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
1034
+ event.preventDefault();
1035
+ event.stopPropagation();
1036
+ return component.ref?.onKeyDown?.({ event }) ?? false;
1037
+ }
1038
+ return false;
1039
+ },
1040
+ onExit: () => {
1041
+ destroy();
1042
+ }
1043
+ };
1044
+ };
1045
+
1046
+ // src/headless/extensions/DragHandle/DragHandle.ts
1047
+ import BaseDragHandle from "@tiptap/extension-drag-handle";
1048
+ var currentCallbacks = {};
1049
+ var currentNode = null;
1050
+ var currentEditor = null;
1051
+ function setDragHandleCallbacks(callbacks) {
1052
+ currentCallbacks = callbacks;
1053
+ }
1054
+ function createDragHandleElement() {
1055
+ const container = document.createElement("div");
1056
+ container.className = "nph-drag-handle";
1057
+ const plusBtn = document.createElement("button");
1058
+ plusBtn.className = "nph-drag-handle__btn";
1059
+ plusBtn.type = "button";
1060
+ plusBtn.setAttribute("aria-label", "Add block");
1061
+ 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>`;
1062
+ plusBtn.addEventListener("click", (e) => {
1063
+ e.preventDefault();
1064
+ e.stopPropagation();
1065
+ if (currentEditor) {
1066
+ currentCallbacks.onAddBlock?.(currentEditor, currentNode);
1067
+ }
1068
+ });
1069
+ const gripBtn = document.createElement("button");
1070
+ gripBtn.className = "nph-drag-handle__btn nph-drag-handle__grip";
1071
+ gripBtn.type = "button";
1072
+ gripBtn.setAttribute("aria-label", "Drag to reorder");
1073
+ 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>`;
1074
+ gripBtn.addEventListener("click", (e) => {
1075
+ e.preventDefault();
1076
+ e.stopPropagation();
1077
+ if (currentEditor) {
1078
+ currentCallbacks.onGripClick?.(currentEditor, currentNode, container);
1079
+ }
1080
+ });
1081
+ container.appendChild(plusBtn);
1082
+ container.appendChild(gripBtn);
1083
+ return container;
1084
+ }
1085
+ var DragHandle = BaseDragHandle.configure({
1086
+ render: createDragHandleElement,
1087
+ nested: true,
1088
+ onNodeChange: ({ node, editor }) => {
1089
+ currentNode = node;
1090
+ currentEditor = editor;
1091
+ }
1092
+ });
1093
+
1094
+ // src/headless/extensions/Table/index.ts
1095
+ import { TableKit } from "@tiptap/extension-table";
1096
+ import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
1097
+
1098
+ // src/headless/extensions/MarkdownPaste.ts
1099
+ import { Extension } from "@tiptap/core";
1100
+ import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1101
+ import { MarkdownParser, defaultMarkdownParser } from "@tiptap/pm/markdown";
1102
+ var markdownPastePluginKey = new PluginKey2("markdownPaste");
1103
+ function looksLikeMarkdown(text) {
1104
+ const patterns = [
1105
+ /^#{1,6}\s/m,
1106
+ // headings
1107
+ /^\s*[-*+]\s/m,
1108
+ // unordered list
1109
+ /^\s*\d+\.\s/m,
1110
+ // ordered list
1111
+ /^\s*>\s/m,
1112
+ // blockquote
1113
+ /\|.+\|/m,
1114
+ // table
1115
+ /^```/m,
1116
+ // fenced code block
1117
+ /\*\*.+\*\*/,
1118
+ // bold
1119
+ /\*.+\*/,
1120
+ // italic
1121
+ /~~.+~~/,
1122
+ // strikethrough
1123
+ /`[^`]+`/,
1124
+ // inline code
1125
+ /^\s*---\s*$/m,
1126
+ // horizontal rule
1127
+ /^\s*\*\*\*\s*$/m,
1128
+ // horizontal rule alt
1129
+ /\[.+\]\(.+\)/,
1130
+ // links
1131
+ /!\[.*\]\(.+\)/
1132
+ // images
1133
+ ];
1134
+ const hasMarkdown = patterns.some((p) => p.test(text));
1135
+ const isHtml = /^<[a-z][\s\S]*>/i.test(text.trim());
1136
+ return hasMarkdown && !isHtml;
1137
+ }
1138
+ function buildParser(schema) {
1139
+ const md = defaultMarkdownParser.tokenizer;
1140
+ const tokens = {};
1141
+ if (schema.nodes.paragraph) tokens.paragraph = { block: "paragraph" };
1142
+ if (schema.nodes.heading) {
1143
+ tokens.heading = {
1144
+ block: "heading",
1145
+ getAttrs: (tok) => ({ level: Number(tok.tag.slice(1)) })
1146
+ };
1147
+ }
1148
+ if (schema.nodes.blockquote) tokens.blockquote = { block: "blockquote" };
1149
+ if (schema.nodes.bulletList) tokens.bullet_list = { block: "bulletList" };
1150
+ if (schema.nodes.orderedList) {
1151
+ tokens.ordered_list = {
1152
+ block: "orderedList",
1153
+ getAttrs: (tok) => ({ start: Number(tok.attrGet("start") || 1) })
1154
+ };
1155
+ }
1156
+ if (schema.nodes.listItem) tokens.list_item = { block: "listItem" };
1157
+ if (schema.nodes.codeBlock) {
1158
+ tokens.code_block = { block: "codeBlock", noCloseToken: true };
1159
+ tokens.fence = {
1160
+ block: "codeBlock",
1161
+ getAttrs: (tok) => ({ language: tok.info || "" }),
1162
+ noCloseToken: true
1163
+ };
1164
+ }
1165
+ if (schema.nodes.horizontalRule) {
1166
+ tokens.hr = { node: "horizontalRule" };
1167
+ }
1168
+ if (schema.nodes.hardBreak) {
1169
+ tokens.hardbreak = { node: "hardBreak" };
1170
+ }
1171
+ if (schema.nodes.image) {
1172
+ tokens.image = {
1173
+ node: "image",
1174
+ getAttrs: (tok) => ({
1175
+ src: tok.attrGet("src"),
1176
+ title: tok.attrGet("title") || null,
1177
+ alt: tok.children?.[0]?.content || null
1178
+ })
1179
+ };
1180
+ }
1181
+ if (schema.nodes.table) {
1182
+ tokens.table = { block: "table" };
1183
+ tokens.thead = { ignore: true };
1184
+ tokens.tbody = { ignore: true };
1185
+ tokens.tr = { block: "tableRow" };
1186
+ tokens.th = { block: "tableHeader" };
1187
+ tokens.td = { block: "tableCell" };
1188
+ }
1189
+ if (schema.marks.bold || schema.marks.strong) {
1190
+ tokens.strong = { mark: schema.marks.bold ? "bold" : "strong" };
1191
+ }
1192
+ if (schema.marks.italic || schema.marks.em) {
1193
+ tokens.em = { mark: schema.marks.italic ? "italic" : "em" };
1194
+ }
1195
+ if (schema.marks.code) {
1196
+ tokens.code_inline = { mark: "code", noCloseToken: true };
1197
+ }
1198
+ if (schema.marks.link) {
1199
+ tokens.link = {
1200
+ mark: "link",
1201
+ getAttrs: (tok) => ({
1202
+ href: tok.attrGet("href"),
1203
+ title: tok.attrGet("title") || null
1204
+ })
1205
+ };
1206
+ }
1207
+ if (schema.marks.strike || schema.marks.strikethrough) {
1208
+ tokens.s = { mark: schema.marks.strike ? "strike" : "strikethrough" };
1209
+ }
1210
+ try {
1211
+ return new MarkdownParser(schema, md, tokens);
1212
+ } catch {
1213
+ return null;
1214
+ }
1215
+ }
1216
+ var MarkdownPaste = Extension.create({
1217
+ name: "markdownPaste",
1218
+ addProseMirrorPlugins() {
1219
+ const schema = this.editor.schema;
1220
+ let parser = null;
1221
+ return [
1222
+ new Plugin3({
1223
+ key: markdownPastePluginKey,
1224
+ props: {
1225
+ handlePaste(view, event) {
1226
+ const clipboardData = event.clipboardData;
1227
+ if (!clipboardData) return false;
1228
+ const html = clipboardData.getData("text/html");
1229
+ if (html && html.trim().length > 0) return false;
1230
+ const text = clipboardData.getData("text/plain");
1231
+ if (!text || !looksLikeMarkdown(text)) return false;
1232
+ if (!parser) {
1233
+ parser = buildParser(schema);
1234
+ }
1235
+ if (!parser) return false;
1236
+ try {
1237
+ const doc = parser.parse(text);
1238
+ if (!doc || doc.content.size === 0) return false;
1239
+ const { tr } = view.state;
1240
+ const slice = doc.slice(0, doc.content.size);
1241
+ tr.replaceSelection(slice);
1242
+ view.dispatch(tr);
1243
+ return true;
1244
+ } catch {
1245
+ return false;
1246
+ }
1247
+ }
1248
+ }
1249
+ })
1250
+ ];
1251
+ }
1252
+ });
1253
+
1254
+ // src/headless/extensions/slash-command.tsx
1255
+ import Suggestion from "@tiptap/suggestion";
1256
+ import { Extension as Extension2 } from "@tiptap/core";
1257
+ var Command = Extension2.create({
1258
+ name: "slash-command",
1259
+ addOptions() {
1260
+ return {
1261
+ suggestion: {
1262
+ char: "/",
1263
+ command: (ctx) => {
1264
+ ctx.props.command({ editor: ctx.editor, range: ctx.range });
1265
+ }
1266
+ }
1267
+ };
1268
+ },
1269
+ addProseMirrorPlugins() {
1270
+ const base = this.options.suggestion ?? {};
1271
+ return [
1272
+ Suggestion({
1273
+ editor: this.editor,
1274
+ char: base.char ?? "/",
1275
+ startOfLine: base.startOfLine ?? true,
1276
+ items: base.items ?? (() => ["/"]),
1277
+ command: (ctx) => {
1278
+ if (typeof ctx?.props?.command === "function") {
1279
+ ctx.props.command({ editor: ctx.editor, range: ctx.range });
1280
+ }
1281
+ },
1282
+ ...base,
1283
+ render: () => {
1284
+ return {
1285
+ onStart: (props) => {
1286
+ const { selection } = props.editor.state;
1287
+ const parentNode = selection.$from.node(selection.$from.depth);
1288
+ const blockType = parentNode.type.name;
1289
+ if (blockType === "codeBlock") return false;
1290
+ const { $from } = selection;
1291
+ const marks = $from.marks();
1292
+ if (marks.some((mark) => mark.type.name === "code" || mark.type.name === "link")) {
1293
+ return false;
1294
+ }
1295
+ novelStore.set(queryAtom, props.query ?? "");
1296
+ novelStore.set(rangeAtom, props.range ?? null);
1297
+ novelStore.set(slashMenuOpenAtom, true);
1298
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1299
+ novelStore.set(slashMenuRectAtom, rect);
1300
+ },
1301
+ onUpdate: (props) => {
1302
+ novelStore.set(queryAtom, props.query ?? "");
1303
+ novelStore.set(rangeAtom, props.range ?? null);
1304
+ const rect = typeof props.clientRect === "function" ? props.clientRect() : null;
1305
+ novelStore.set(slashMenuRectAtom, rect);
1306
+ },
1307
+ onKeyDown: ({ event }) => {
1308
+ if (event.key === "Escape") {
1309
+ novelStore.set(slashMenuOpenAtom, false);
1310
+ return true;
1311
+ }
1312
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
1313
+ const slashCommand = document.querySelector("#slash-command");
1314
+ if (slashCommand) {
1315
+ slashCommand.dispatchEvent(
1316
+ new KeyboardEvent("keydown", {
1317
+ key: event.key,
1318
+ cancelable: true,
1319
+ bubbles: true
1320
+ })
1321
+ );
1322
+ return true;
1323
+ }
1324
+ }
1325
+ return false;
1326
+ },
1327
+ onExit: () => {
1328
+ novelStore.set(slashMenuOpenAtom, false);
1329
+ novelStore.set(queryAtom, "");
1330
+ novelStore.set(rangeAtom, null);
1331
+ novelStore.set(slashMenuRectAtom, null);
1332
+ }
1333
+ };
1334
+ }
1335
+ })
1336
+ ];
1337
+ }
1338
+ });
1339
+ var renderItems = () => ({
1340
+ onStart: () => {
1341
+ },
1342
+ onUpdate: () => {
1343
+ },
1344
+ onKeyDown: () => false,
1345
+ onExit: () => {
1346
+ }
1347
+ });
1348
+ var createSuggestionItems = (items) => items;
1349
+ var handleCommandNavigation = (event) => {
1350
+ if (["ArrowUp", "ArrowDown", "Enter"].includes(event.key)) {
1351
+ const slashCommand = document.querySelector("#slash-command");
1352
+ if (slashCommand) return true;
1353
+ }
1354
+ };
1355
+
1356
+ export {
1357
+ novelStore,
1358
+ store_exports,
1359
+ EditorRoot,
1360
+ EditorContent,
1361
+ EditorBubble,
1362
+ EditorBubbleItem,
1363
+ queryAtom,
1364
+ EditorCommandOut,
1365
+ EditorCommand,
1366
+ EditorCommandList,
1367
+ EditorCommandItem,
1368
+ EditorCommandEmpty,
1369
+ CodeBlock,
1370
+ Link,
1371
+ ImageBlock,
1372
+ MentionCommand,
1373
+ createMentionExtension,
1374
+ renderMentionSuggestion,
1375
+ setDragHandleCallbacks,
1376
+ DragHandle,
1377
+ TableKit,
1378
+ MarkdownPaste,
1379
+ StarterKit,
1380
+ Placeholder,
1381
+ Command,
1382
+ renderItems,
1383
+ createSuggestionItems,
1384
+ handleCommandNavigation,
1385
+ useCurrentEditor4 as useCurrentEditor
1386
+ };
1387
+ //# sourceMappingURL=chunk-3CLWAYRP.js.map