@haklex/rich-editor 0.36.0 → 0.37.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 (57) hide show
  1. package/dist/{AlertQuoteEditNode-C4NKE1Lt.js → AlertQuoteEditNode-DUvNEyjw.js} +3 -3
  2. package/dist/{KaTeXRenderer-DLtnsRSv.js → KaTeXRenderer-DvxFML1l.js} +2 -1
  3. package/dist/LinkCardRenderer-BT8P5aJC.js +100 -0
  4. package/dist/{MermaidPlugin-BOP4CFU_.js → MermaidPlugin-DgIAgFH8.js} +2 -2
  5. package/dist/{SubmitShortcutPlugin-DQLW3pPC.js → SubmitShortcutPlugin-DuKGB15Q.js} +286 -7
  6. package/dist/commands-entry.d.ts +1 -0
  7. package/dist/commands-entry.d.ts.map +1 -1
  8. package/dist/commands-entry.mjs +3 -3
  9. package/dist/components/CorePlugins.d.ts.map +1 -1
  10. package/dist/components/RichEditor.d.ts +1 -1
  11. package/dist/components/RichEditor.d.ts.map +1 -1
  12. package/dist/components/renderers/FileRenderer.d.ts +14 -0
  13. package/dist/components/renderers/FileRenderer.d.ts.map +1 -0
  14. package/dist/{config-CwZ9fwU0.js → config-D8JJ7F11.js} +154 -8
  15. package/dist/config-edit.d.ts.map +1 -1
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/context/FileUploadContext.d.ts +8 -0
  18. package/dist/context/FileUploadContext.d.ts.map +1 -0
  19. package/dist/index.mjs +30 -26
  20. package/dist/{node-registry-BOe08y9j.js → node-registry-BFDycNE-.js} +5 -4
  21. package/dist/nodes/FileNode.d.ts +49 -0
  22. package/dist/nodes/FileNode.d.ts.map +1 -0
  23. package/dist/nodes/KaTeXInlineNode.d.ts.map +1 -1
  24. package/dist/nodes/MentionNode.d.ts.map +1 -1
  25. package/dist/nodes-entry.d.ts +2 -0
  26. package/dist/nodes-entry.d.ts.map +1 -1
  27. package/dist/nodes-entry.mjs +5 -5
  28. package/dist/plugins/FileUploadPlugin.d.ts +12 -0
  29. package/dist/plugins/FileUploadPlugin.d.ts.map +1 -0
  30. package/dist/plugins/InlineDndPlugin.d.ts +2 -0
  31. package/dist/plugins/InlineDndPlugin.d.ts.map +1 -0
  32. package/dist/plugins/file-upload-command.d.ts +3 -0
  33. package/dist/plugins/file-upload-command.d.ts.map +1 -0
  34. package/dist/plugins/file-upload-store.d.ts +11 -0
  35. package/dist/plugins/file-upload-store.d.ts.map +1 -0
  36. package/dist/plugins/image-upload.css.d.ts +1 -1
  37. package/dist/plugins/inline-dnd-shared.d.ts +4 -0
  38. package/dist/plugins/inline-dnd-shared.d.ts.map +1 -0
  39. package/dist/plugins/inline-dnd.css.d.ts +3 -0
  40. package/dist/plugins/inline-dnd.css.d.ts.map +1 -0
  41. package/dist/plugins-entry.d.ts +5 -0
  42. package/dist/plugins-entry.d.ts.map +1 -1
  43. package/dist/plugins-entry.mjs +5 -4
  44. package/dist/renderers-entry.d.ts +3 -1
  45. package/dist/renderers-entry.d.ts.map +1 -1
  46. package/dist/renderers-entry.mjs +3 -3
  47. package/dist/rich-editor.css +1 -1
  48. package/dist/static-entry.mjs +3 -3
  49. package/dist/{theme-CnNR-Ttt.js → theme-Vu_9D3oG.js} +22 -8
  50. package/dist/types/renderer-config.d.ts +3 -0
  51. package/dist/types/renderer-config.d.ts.map +1 -1
  52. package/dist/types/renderer-keys.d.ts +1 -0
  53. package/dist/types/renderer-keys.d.ts.map +1 -1
  54. package/dist/types.d.ts +5 -0
  55. package/dist/types.d.ts.map +1 -1
  56. package/package.json +6 -6
  57. package/dist/LinkCardRenderer-DPV1JP0X.js +0 -45
@@ -1,5 +1,5 @@
1
- import { B as FootnoteNode, G as _defineProperty, V as $isAlertQuoteNode, W as AlertQuoteNode, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, d as RichQuoteNode, i as TagNode, q as AlertRenderer, t as editorTheme } from "./theme-CnNR-Ttt.js";
2
- import { h as ALERT_NODE_KEY, l as RendererWrapper } from "./KaTeXRenderer-DLtnsRSv.js";
1
+ import { B as FootnoteNode, G as AlertQuoteNode, H as $isAlertQuoteNode, J as AlertRenderer, K as _defineProperty, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, d as RichQuoteNode, i as TagNode, t as editorTheme } from "./theme-Vu_9D3oG.js";
2
+ import { h as ALERT_NODE_KEY, l as RendererWrapper } from "./KaTeXRenderer-DvxFML1l.js";
3
3
  import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
4
4
  import { ListPlugin } from "@lexical/react/LexicalListPlugin";
5
5
  import { AutoLinkNode, LinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
@@ -8,10 +8,10 @@ import { createContext, createElement, use, useCallback, useEffect, useMemo } fr
8
8
  import { HeadingNode, QuoteNode } from "@lexical/rich-text";
9
9
  import { $createParagraphNode, $getEditor, $getNodeByKey, $getRoot, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, KEY_ARROW_DOWN_COMMAND, KEY_ENTER_COMMAND, PASTE_COMMAND, createEditor } from "lexical";
10
10
  import { HorizontalRuleNode } from "@lexical/extension";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
12
  import { CodeNode } from "@lexical/code-core";
12
13
  import { ListItemNode, ListNode } from "@lexical/list";
13
14
  import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
14
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
15
  import { Info, Lightbulb, TriangleAlert } from "lucide-react";
16
16
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
17
17
  import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
@@ -18,6 +18,7 @@ import { rgbaToThumbHash, thumbHashToDataURL } from "thumbhash";
18
18
  var ALERT_NODE_KEY = "Alert";
19
19
  var BANNER_NODE_KEY = "Banner";
20
20
  var CODE_BLOCK_NODE_KEY = "CodeBlock";
21
+ var FILE_NODE_KEY = "File";
21
22
  var FOOTNOTE_NODE_KEY = "Footnote";
22
23
  var FOOTNOTE_SECTION_NODE_KEY = "FootnoteSection";
23
24
  var IMAGE_NODE_KEY = "Image";
@@ -249,4 +250,4 @@ function KaTeXRenderer({ equation, displayMode }) {
249
250
  });
250
251
  }
251
252
  //#endregion
252
- export { MENTION_NODE_KEY as C, VIDEO_NODE_KEY as D, TAG_NODE_KEY as E, LINK_CARD_NODE_KEY as S, RUBY_NODE_KEY as T, CODE_BLOCK_NODE_KEY as _, FootnoteDefinitionsProvider as a, IMAGE_NODE_KEY as b, useFootnoteDisplayNumber as c, RendererConfigProvider as d, useRendererConfig as f, BANNER_NODE_KEY as g, ALERT_NODE_KEY as h, FootnoteStaticRenderer as i, RendererWrapper as l, useVariant as m, computeImageMeta as n, useFootnoteContent as o, useRendererMode as p, decodeThumbHash as r, useFootnoteDefinitions as s, KaTeXRenderer as t, createRendererDecoration as u, FOOTNOTE_NODE_KEY as v, MERMAID_NODE_KEY as w, KATEX_NODE_KEY as x, FOOTNOTE_SECTION_NODE_KEY as y };
253
+ export { LINK_CARD_NODE_KEY as C, TAG_NODE_KEY as D, RUBY_NODE_KEY as E, VIDEO_NODE_KEY as O, KATEX_NODE_KEY as S, MERMAID_NODE_KEY as T, CODE_BLOCK_NODE_KEY as _, FootnoteDefinitionsProvider as a, FOOTNOTE_SECTION_NODE_KEY as b, useFootnoteDisplayNumber as c, RendererConfigProvider as d, useRendererConfig as f, BANNER_NODE_KEY as g, ALERT_NODE_KEY as h, FootnoteStaticRenderer as i, RendererWrapper as l, useVariant as m, computeImageMeta as n, useFootnoteContent as o, useRendererMode as p, decodeThumbHash as r, useFootnoteDefinitions as s, KaTeXRenderer as t, createRendererDecoration as u, FILE_NODE_KEY as v, MENTION_NODE_KEY as w, IMAGE_NODE_KEY as x, FOOTNOTE_NODE_KEY as y };
@@ -0,0 +1,100 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ //#region src/components/renderers/FileRenderer.tsx
3
+ function formatFileSize(bytes) {
4
+ if (bytes == null || !Number.isFinite(bytes) || bytes < 0) return null;
5
+ if (bytes < 1024) return `${bytes} B`;
6
+ const units = [
7
+ "KB",
8
+ "MB",
9
+ "GB",
10
+ "TB"
11
+ ];
12
+ let value = bytes;
13
+ let unit = "";
14
+ for (const next of units) {
15
+ value /= 1024;
16
+ unit = next;
17
+ if (value < 1024) break;
18
+ }
19
+ return `${value >= 100 ? Math.round(value) : value.toFixed(1)} ${unit}`;
20
+ }
21
+ function fileExtension(name, ext) {
22
+ if (ext) return ext.toUpperCase();
23
+ const index = name.lastIndexOf(".");
24
+ if (index <= 0 || index === name.length - 1) return null;
25
+ const derived = name.slice(index + 1);
26
+ return derived.length > 8 ? null : derived.toUpperCase();
27
+ }
28
+ function fileMetaText(name, size, ext) {
29
+ return [formatFileSize(size), fileExtension(name, ext)].filter(Boolean).join(" · ");
30
+ }
31
+ function FileRenderer({ src, name, size, ext, display }) {
32
+ if (display === "inline") return /* @__PURE__ */ jsx("a", {
33
+ className: "rich-file-chip",
34
+ download: name,
35
+ href: src || void 0,
36
+ rel: "noopener noreferrer",
37
+ target: "_blank",
38
+ children: name
39
+ });
40
+ const meta = fileMetaText(name, size, ext);
41
+ return /* @__PURE__ */ jsxs("a", {
42
+ className: "rich-file-card",
43
+ download: name,
44
+ href: src || void 0,
45
+ rel: "noopener noreferrer",
46
+ target: "_blank",
47
+ children: [/* @__PURE__ */ jsx("span", {
48
+ className: "rich-file-card-name",
49
+ children: name
50
+ }), meta && /* @__PURE__ */ jsx("span", {
51
+ className: "rich-file-card-meta",
52
+ children: meta
53
+ })]
54
+ });
55
+ }
56
+ //#endregion
57
+ //#region src/components/renderers/LinkCardRenderer.tsx
58
+ function LinkCardRenderer({ url, title, description, favicon, image }) {
59
+ return /* @__PURE__ */ jsxs("a", {
60
+ className: "rich-link-card",
61
+ href: url,
62
+ rel: "noopener noreferrer",
63
+ target: "_blank",
64
+ children: [image && /* @__PURE__ */ jsx("span", {
65
+ className: "rich-link-card-image",
66
+ children: /* @__PURE__ */ jsx("img", {
67
+ alt: "",
68
+ loading: "lazy",
69
+ src: image
70
+ })
71
+ }), /* @__PURE__ */ jsxs("span", {
72
+ className: "rich-link-card-content",
73
+ children: [
74
+ /* @__PURE__ */ jsxs("span", {
75
+ className: "rich-link-card-title",
76
+ children: [favicon && /* @__PURE__ */ jsx("img", {
77
+ alt: "",
78
+ className: "rich-link-card-favicon",
79
+ height: 16,
80
+ src: favicon,
81
+ width: 16,
82
+ onError: (e) => {
83
+ e.target.style.display = "none";
84
+ }
85
+ }), title || url]
86
+ }),
87
+ description && /* @__PURE__ */ jsx("span", {
88
+ className: "rich-link-card-description",
89
+ children: description
90
+ }),
91
+ /* @__PURE__ */ jsx("span", {
92
+ className: "rich-link-card-url",
93
+ children: url
94
+ })
95
+ ]
96
+ })]
97
+ });
98
+ }
99
+ //#endregion
100
+ export { formatFileSize as a, fileMetaText as i, FileRenderer as n, fileExtension as r, LinkCardRenderer as t };
@@ -1,5 +1,5 @@
1
- import { O as $withAdaptiveImageDisplayWidth, f as $createMermaidNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode } from "./theme-CnNR-Ttt.js";
2
- import { t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-C4NKE1Lt.js";
1
+ import { O as $withAdaptiveImageDisplayWidth, f as $createMermaidNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode } from "./theme-Vu_9D3oG.js";
2
+ import { t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-DUvNEyjw.js";
3
3
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
4
  import { useEffect } from "react";
5
5
  import { $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from "lexical";
@@ -1,9 +1,9 @@
1
- import { c as setCodeBlockCursorIntent, o as $createCodeBlockEditNode, s as $createBannerEditNode, t as getResolvedEditNodes } from "./node-registry-BOe08y9j.js";
2
- import { B as FootnoteNode, C as KaTeXBlockNode, K as extractTextContent, O as $withAdaptiveImageDisplayWidth, W as AlertQuoteNode, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, h as $createMentionNode, k as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, o as $createSpoilerNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode, z as $createFootnoteNode } from "./theme-CnNR-Ttt.js";
3
- import { a as FootnoteDefinitionsProvider, n as computeImageMeta } from "./KaTeXRenderer-DLtnsRSv.js";
1
+ import { c as setCodeBlockCursorIntent, o as $createCodeBlockEditNode, s as $createBannerEditNode, t as getResolvedEditNodes } from "./node-registry-BFDycNE-.js";
4
2
  import "./katex.css-0TJGE4On.js";
5
- import { C as CommentNode, M as BannerNode, T as CodeBlockNode, _ as FootnoteSectionNode, b as $createCommentNode, c as RubyNode, g as $isFootnoteSectionNode, h as $createFootnoteSectionNode, i as $createVideoNode, o as $createRubyNode, p as $isGridContainerNode, v as $createDetailsNode, x as $createCommentPlaceholderNode, y as DetailsNode } from "./config-CwZ9fwU0.js";
6
- import { o as PasteLinkPlugin, t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-C4NKE1Lt.js";
3
+ import { $ as INLINE_DRAG_MIME, B as FootnoteNode, C as KaTeXBlockNode, G as AlertQuoteNode, O as $withAdaptiveImageDisplayWidth, Q as INLINE_DRAG_ATTR, V as OPEN_FILE_PICKER_COMMAND, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, h as $createMentionNode, k as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, o as $createSpoilerNode, q as extractTextContent, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode, z as $createFootnoteNode } from "./theme-Vu_9D3oG.js";
4
+ import { a as FootnoteDefinitionsProvider, n as computeImageMeta } from "./KaTeXRenderer-DvxFML1l.js";
5
+ import { C as DetailsNode, D as CommentNode, I as BannerNode, S as $createDetailsNode, T as $createCommentPlaceholderNode, _ as FootnoteSectionNode, c as RubyNode, g as $isFootnoteSectionNode, h as $createFootnoteSectionNode, i as $createVideoNode, k as CodeBlockNode, o as $createRubyNode, p as $isGridContainerNode, v as $createFileNode, w as $createCommentNode, x as fileExtFromName, y as $isFileNode } from "./config-D8JJ7F11.js";
6
+ import { o as PasteLinkPlugin, t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-DUvNEyjw.js";
7
7
  import { n as getHostname, r as probeFavicon, t as normalizeSerializedEditorState } from "./normalizeSerializedEditorState-VaI73T09.js";
8
8
  import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin";
9
9
  import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
@@ -17,9 +17,10 @@ import { $createQuoteNode, $isQuoteNode, DRAG_DROP_PASTE, QuoteNode } from "@lex
17
17
  import { $addUpdateTag, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createRangeSelection, $createTextNode, $getNodeByKey, $getRoot, $getSelection, $getState, $insertNodes, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isParagraphNode, $isRangeSelection, $isRootNode, $isTextNode, $nodesOfType, $parseSerializedNode, $setSelection, $setState, CLICK_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, IS_CODE, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, PASTE_COMMAND, SELECTION_CHANGE_COMMAND, createEditor, createState } from "lexical";
18
18
  import { $createHorizontalRuleNode, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/extension";
19
19
  import { CODE_BLOCK_NODE_TRANSFORMER, COMMENT_TRANSFORMER, CONTAINER_TRANSFORMER, FOOTNOTE_SECTION_TRANSFORMER, FOOTNOTE_TRANSFORMER, GIT_ALERT_TRANSFORMER, HORIZONTAL_RULE_BLOCK_TRANSFORMER, IMAGE_BLOCK_TRANSFORMER, INSERT_TRANSFORMER, KATEX_BLOCK_TRANSFORMER, KATEX_INLINE_TRANSFORMER, LINK_CARD_BLOCK_TRANSFORMER, MENTION_TRANSFORMER, MERMAID_BLOCK_TRANSFORMER, RUBY_TRANSFORMER, SPOILER_TRANSFORMER, SUBSCRIPT_TRANSFORMER, SUPERSCRIPT_TRANSFORMER, TABLE_BLOCK_TRANSFORMER, VIDEO_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
20
+ import { createPortal } from "react-dom";
21
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
20
22
  import { $convertFromMarkdownString, CHECK_LIST, CODE, QUOTE, TRANSFORMERS } from "@lexical/markdown";
21
23
  import { $createTableCellNode, $createTableNode, $createTableRowNode, TableCellHeaderStates } from "@lexical/table";
22
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
23
24
  import { Check, Info, Link2, Upload } from "lucide-react";
24
25
  import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin";
25
26
  import { nanoid } from "nanoid";
@@ -430,6 +431,141 @@ function HorizontalRulePlugin() {
430
431
  return null;
431
432
  }
432
433
  //#endregion
434
+ //#region src/plugins/inline-dnd.css.ts
435
+ var dropCaret = "_224tt30";
436
+ var draggingSource = "_224tt31";
437
+ //#endregion
438
+ //#region src/plugins/InlineDndPlugin.tsx
439
+ function caretRangeAtPoint(x, y) {
440
+ if (document.caretRangeFromPoint) return document.caretRangeFromPoint(x, y);
441
+ const position = document.caretPositionFromPoint?.(x, y);
442
+ if (!position) return null;
443
+ const range = document.createRange();
444
+ range.setStart(position.offsetNode, position.offset);
445
+ range.collapse(true);
446
+ return range;
447
+ }
448
+ function snapRangeToNearestBlock(root, y) {
449
+ let nearest = null;
450
+ for (const el of root.children) {
451
+ const rect = el.getBoundingClientRect();
452
+ if (rect.height === 0) continue;
453
+ const distance = y < rect.top ? rect.top - y : y > rect.bottom ? y - rect.bottom : 0;
454
+ const below = y > (rect.top + rect.bottom) / 2;
455
+ if (!nearest || distance < nearest.distance) nearest = {
456
+ el,
457
+ distance,
458
+ below
459
+ };
460
+ }
461
+ if (!nearest) return null;
462
+ const range = document.createRange();
463
+ range.selectNodeContents(nearest.el);
464
+ range.collapse(!nearest.below);
465
+ return range;
466
+ }
467
+ function resolveDropRange(root, event) {
468
+ const range = caretRangeAtPoint(event.clientX, event.clientY);
469
+ if (range && root.contains(range.startContainer)) return range;
470
+ return snapRangeToNearestBlock(root, event.clientY);
471
+ }
472
+ function caretRect(range) {
473
+ const rects = range.getClientRects();
474
+ if (rects.length > 0) return rects[0];
475
+ const rect = range.getBoundingClientRect();
476
+ if (rect.height > 0) return rect;
477
+ const container = range.startContainer;
478
+ const el = container instanceof Element ? container : container.parentElement;
479
+ return el ? el.getBoundingClientRect() : null;
480
+ }
481
+ function InlineDndPlugin() {
482
+ const [editor] = useLexicalComposerContext();
483
+ const [caret, setCaret] = useState(null);
484
+ useEffect(() => {
485
+ const root = editor.getRootElement();
486
+ if (!root) return;
487
+ let draggedKey = null;
488
+ let sourceEl = null;
489
+ const clear = () => {
490
+ draggedKey = null;
491
+ sourceEl?.classList.remove(draggingSource);
492
+ sourceEl = null;
493
+ setCaret(null);
494
+ };
495
+ const onDragStart = (event) => {
496
+ const target = event.target?.closest?.(`[${INLINE_DRAG_ATTR}]`);
497
+ if (!(target instanceof HTMLElement) || !event.dataTransfer) return;
498
+ const nodeKey = target.getAttribute(INLINE_DRAG_ATTR);
499
+ if (!nodeKey) return;
500
+ draggedKey = nodeKey;
501
+ sourceEl = target;
502
+ event.dataTransfer.setData(INLINE_DRAG_MIME, nodeKey);
503
+ event.dataTransfer.setData("text/plain", target.textContent ?? "");
504
+ event.dataTransfer.effectAllowed = "move";
505
+ requestAnimationFrame(() => sourceEl?.classList.add(draggingSource));
506
+ };
507
+ const onDragOver = (event) => {
508
+ if (!draggedKey && !event.dataTransfer?.types.includes("application/x-haklex-inline-node")) return;
509
+ event.preventDefault();
510
+ if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
511
+ const range = resolveDropRange(root, event);
512
+ const rect = range && caretRect(range);
513
+ if (!rect) {
514
+ setCaret(null);
515
+ return;
516
+ }
517
+ setCaret({
518
+ left: rect.left,
519
+ top: rect.top,
520
+ height: rect.height || 20
521
+ });
522
+ };
523
+ const onDrop = (event) => {
524
+ const nodeKey = draggedKey ?? event.dataTransfer?.getData("application/x-haklex-inline-node");
525
+ if (!nodeKey) return;
526
+ event.preventDefault();
527
+ event.stopPropagation();
528
+ const range = resolveDropRange(root, event);
529
+ if (range) editor.update(() => {
530
+ const node = $getNodeByKey(nodeKey);
531
+ if (!node) return;
532
+ node.remove();
533
+ const selection = $createRangeSelection();
534
+ selection.applyDOMRange(range);
535
+ $setSelection(selection);
536
+ selection.insertNodes([node]);
537
+ });
538
+ clear();
539
+ };
540
+ const onDragEnd = () => clear();
541
+ const onDragLeave = (event) => {
542
+ if (!root.contains(event.relatedTarget)) setCaret(null);
543
+ };
544
+ root.addEventListener("dragstart", onDragStart);
545
+ root.addEventListener("dragover", onDragOver);
546
+ root.addEventListener("drop", onDrop);
547
+ root.addEventListener("dragend", onDragEnd);
548
+ root.addEventListener("dragleave", onDragLeave);
549
+ return () => {
550
+ clear();
551
+ root.removeEventListener("dragstart", onDragStart);
552
+ root.removeEventListener("dragover", onDragOver);
553
+ root.removeEventListener("drop", onDrop);
554
+ root.removeEventListener("dragend", onDragEnd);
555
+ root.removeEventListener("dragleave", onDragLeave);
556
+ };
557
+ }, [editor]);
558
+ if (!caret) return null;
559
+ return createPortal(/* @__PURE__ */ jsx("div", {
560
+ className: dropCaret,
561
+ style: {
562
+ left: caret.left,
563
+ top: caret.top,
564
+ height: caret.height
565
+ }
566
+ }), document.body);
567
+ }
568
+ //#endregion
433
569
  //#region src/transformers/alert.ts
434
570
  var ALERT_TYPE_MAP = {
435
571
  NOTE: "note",
@@ -898,6 +1034,7 @@ function CorePlugins() {
898
1034
  /* @__PURE__ */ jsx(TablePlugin, { hasHorizontalScroll: true }),
899
1035
  /* @__PURE__ */ jsx(CheckListPlugin, {}),
900
1036
  /* @__PURE__ */ jsx(MarkdownShortcutsPlugin, {}),
1037
+ /* @__PURE__ */ jsx(InlineDndPlugin, {}),
901
1038
  /* @__PURE__ */ jsx(MarkdownPastePlugin, {}),
902
1039
  /* @__PURE__ */ jsx(BlockExitPlugin, {}),
903
1040
  /* @__PURE__ */ jsx(ClickBelowPlugin, {}),
@@ -906,6 +1043,18 @@ function CorePlugins() {
906
1043
  ] });
907
1044
  }
908
1045
  //#endregion
1046
+ //#region src/context/FileUploadContext.tsx
1047
+ var FileUploadContext = createContext(null);
1048
+ function FileUploadProvider({ upload, children }) {
1049
+ return /* @__PURE__ */ jsx(FileUploadContext.Provider, {
1050
+ value: upload,
1051
+ children
1052
+ });
1053
+ }
1054
+ function useFileUpload() {
1055
+ return use(FileUploadContext);
1056
+ }
1057
+ //#endregion
909
1058
  //#region src/context/ImagePreprocessContext.tsx
910
1059
  var ImagePreprocessContext = createContext(null);
911
1060
  function ImagePreprocessProvider({ children }) {
@@ -1053,6 +1202,136 @@ function BlockIdPlugin() {
1053
1202
  return null;
1054
1203
  }
1055
1204
  //#endregion
1205
+ //#region src/plugins/file-upload-store.ts
1206
+ var stores = /* @__PURE__ */ new WeakMap();
1207
+ function getStore(editor) {
1208
+ let store = stores.get(editor);
1209
+ if (!store) {
1210
+ store = {
1211
+ entries: /* @__PURE__ */ new Map(),
1212
+ listeners: /* @__PURE__ */ new Set()
1213
+ };
1214
+ stores.set(editor, store);
1215
+ }
1216
+ return store;
1217
+ }
1218
+ function setFileUploadEntry(editor, nodeKey, entry) {
1219
+ const store = getStore(editor);
1220
+ if (entry) store.entries.set(nodeKey, entry);
1221
+ else store.entries.delete(nodeKey);
1222
+ for (const listener of store.listeners) listener();
1223
+ }
1224
+ function useFileUploadEntry(editor, nodeKey) {
1225
+ return useSyncExternalStore((onChange) => {
1226
+ const store = getStore(editor);
1227
+ store.listeners.add(onChange);
1228
+ return () => store.listeners.delete(onChange);
1229
+ }, () => nodeKey ? getStore(editor).entries.get(nodeKey) : void 0, () => void 0);
1230
+ }
1231
+ //#endregion
1232
+ //#region src/plugins/FileUploadPlugin.tsx
1233
+ function isMediaFile(file) {
1234
+ return file.type.startsWith("image/") || file.type.startsWith("video/");
1235
+ }
1236
+ function FileUploadPlugin({ onUpload }) {
1237
+ const [editor] = useLexicalComposerContext();
1238
+ const uploadRef = useRef(onUpload);
1239
+ uploadRef.current = onUpload;
1240
+ const targetEditorRef = useRef(editor);
1241
+ const fileInputRef = useRef(null);
1242
+ const uploadFile = useCallback((file, target) => {
1243
+ let nodeKey = "";
1244
+ target.update(() => {
1245
+ const node = $createFileNode({
1246
+ src: "",
1247
+ name: file.name,
1248
+ size: file.size,
1249
+ mimeType: file.type || void 0,
1250
+ ext: fileExtFromName(file.name)
1251
+ });
1252
+ $insertNodes([node]);
1253
+ nodeKey = node.getKey();
1254
+ });
1255
+ const remove = () => {
1256
+ setFileUploadEntry(target, nodeKey, null);
1257
+ target.update(() => {
1258
+ const node = $getNodeByKey(nodeKey);
1259
+ if (node) node.remove();
1260
+ });
1261
+ };
1262
+ const run = async () => {
1263
+ const base = {
1264
+ percent: 0,
1265
+ retry: () => void run(),
1266
+ remove
1267
+ };
1268
+ setFileUploadEntry(target, nodeKey, {
1269
+ ...base,
1270
+ status: "uploading"
1271
+ });
1272
+ try {
1273
+ const result = await uploadRef.current(file, { onProgress: (percent) => {
1274
+ setFileUploadEntry(target, nodeKey, {
1275
+ ...base,
1276
+ status: "uploading",
1277
+ percent: Math.round(percent)
1278
+ });
1279
+ } });
1280
+ target.update(() => {
1281
+ const node = $getNodeByKey(nodeKey);
1282
+ if ($isFileNode(node)) node.setSrc(result.src);
1283
+ });
1284
+ setFileUploadEntry(target, nodeKey, null);
1285
+ } catch (err) {
1286
+ console.error("[FileUploadPlugin]", err);
1287
+ setFileUploadEntry(target, nodeKey, {
1288
+ ...base,
1289
+ status: "error",
1290
+ error: "Upload failed"
1291
+ });
1292
+ }
1293
+ };
1294
+ run();
1295
+ }, []);
1296
+ const handleFiles = useCallback((files, target) => {
1297
+ const plainFiles = files.filter((file) => !isMediaFile(file));
1298
+ if (plainFiles.length === 0) return false;
1299
+ for (const file of plainFiles) uploadFile(file, target);
1300
+ return plainFiles.length === files.length;
1301
+ }, [uploadFile]);
1302
+ useEffect(() => {
1303
+ const unregisterDragDrop = editor.registerCommand(DRAG_DROP_PASTE, (files, fromEditor) => handleFiles(files, fromEditor), COMMAND_PRIORITY_LOW);
1304
+ const unregisterPaste = editor.registerCommand(PASTE_COMMAND, (event, fromEditor) => {
1305
+ const clipboardData = "clipboardData" in event ? event.clipboardData : null;
1306
+ if (!clipboardData) return false;
1307
+ const files = [...clipboardData.files];
1308
+ if (files.some((file) => !isMediaFile(file))) return handleFiles(files, fromEditor);
1309
+ return false;
1310
+ }, COMMAND_PRIORITY_LOW);
1311
+ const unregisterOpenPicker = editor.registerCommand(OPEN_FILE_PICKER_COMMAND, (_payload, fromEditor) => {
1312
+ targetEditorRef.current = fromEditor;
1313
+ fileInputRef.current?.click();
1314
+ return true;
1315
+ }, COMMAND_PRIORITY_EDITOR);
1316
+ return () => {
1317
+ unregisterDragDrop();
1318
+ unregisterPaste();
1319
+ unregisterOpenPicker();
1320
+ };
1321
+ }, [editor, handleFiles]);
1322
+ return /* @__PURE__ */ jsx("input", {
1323
+ multiple: true,
1324
+ ref: fileInputRef,
1325
+ style: { display: "none" },
1326
+ type: "file",
1327
+ onChange: (event) => {
1328
+ const files = [...event.currentTarget.files ?? []];
1329
+ for (const file of files) uploadFile(file, targetEditorRef.current);
1330
+ event.currentTarget.value = "";
1331
+ }
1332
+ });
1333
+ }
1334
+ //#endregion
1056
1335
  //#region src/utils/image-preprocess.ts
1057
1336
  async function resolvePreprocessTargets(files, source, preprocess) {
1058
1337
  if (!preprocess || files.length !== 1) return files;
@@ -2420,4 +2699,4 @@ function SubmitShortcutPlugin({ onSubmit }) {
2420
2699
  return null;
2421
2700
  }
2422
2701
  //#endregion
2423
- export { blockIdState as A, ALL_TRANSFORMERS as B, createTextSelectionStore as C, ImageUploadPlugin as D, LinkFaviconPlugin as E, ImagePreprocessProvider as F, AutoLinkPlugin as G, ClickBelowPlugin as H, useImagePreprocess as I, CorePlugins as L, useVideoUpload as M, ImageUploadProvider as N, defaultImageUpload as O, useImageUpload as P, MarkdownShortcutsPlugin as R, TextSelectionStoreProvider as S, useTextSelectionStore as T, registerClickBelowCommand as U, HorizontalRulePlugin as V, BlockExitPlugin as W, $getRootBlock as _, AutoFocusPlugin as a, buildBlockAnchor as b, $captureTextSelection as c, createDOMRangeFromTextSelection as d, findDOMPointByTextOffset as f, TEXT_SELECTION_HIGHLIGHT_NAME as g, getTextOffsetFromDOMPoint as h, EditorRefPlugin as i, VideoUploadProvider as j, BlockIdPlugin as k, $captureTextSelectionFromRangeSelection as l, getDOMRectFromTextSelection as m, OnChangePlugin as n, VideoUploadPlugin as o, getBlockElementById as p, FootnotePlugin as r, TextSelectionPlugin as s, SubmitShortcutPlugin as t, $restoreTextSelection as u, $getTextOffsetInBlock as v, useTextSelectionSnapshot as w, buildRangeAnchor as x, $resolveSelectionPoint as y, MarkdownPastePlugin as z };
2702
+ export { setFileUploadEntry as A, FileUploadProvider as B, createTextSelectionStore as C, ImageUploadPlugin as D, LinkFaviconPlugin as E, useVideoUpload as F, ALL_TRANSFORMERS as G, CorePlugins as H, ImageUploadProvider as I, ClickBelowPlugin as J, InlineDndPlugin as K, useImageUpload as L, BlockIdPlugin as M, blockIdState as N, defaultImageUpload as O, VideoUploadProvider as P, ImagePreprocessProvider as R, TextSelectionStoreProvider as S, useTextSelectionStore as T, MarkdownShortcutsPlugin as U, useFileUpload as V, MarkdownPastePlugin as W, BlockExitPlugin as X, registerClickBelowCommand as Y, AutoLinkPlugin as Z, $getRootBlock as _, AutoFocusPlugin as a, buildBlockAnchor as b, $captureTextSelection as c, createDOMRangeFromTextSelection as d, findDOMPointByTextOffset as f, TEXT_SELECTION_HIGHLIGHT_NAME as g, getTextOffsetFromDOMPoint as h, EditorRefPlugin as i, useFileUploadEntry as j, FileUploadPlugin as k, $captureTextSelectionFromRangeSelection as l, getDOMRectFromTextSelection as m, OnChangePlugin as n, VideoUploadPlugin as o, getBlockElementById as p, HorizontalRulePlugin as q, FootnotePlugin as r, TextSelectionPlugin as s, SubmitShortcutPlugin as t, $restoreTextSelection as u, $getTextOffsetInBlock as v, useTextSelectionSnapshot as w, buildRangeAnchor as x, $resolveSelectionPoint as y, useImagePreprocess as z };
@@ -1,4 +1,5 @@
1
1
  export { INSERT_ALERT_COMMAND } from './plugins/AlertPlugin';
2
+ export { OPEN_FILE_PICKER_COMMAND } from './plugins/file-upload-command';
2
3
  export { OPEN_IMAGE_UPLOAD_DIALOG_COMMAND } from './plugins/image-upload-command';
3
4
  export { INSERT_IMAGE_COMMAND } from './plugins/ImagePlugin';
4
5
  export { INSERT_KATEX_BLOCK_COMMAND, INSERT_KATEX_INLINE_COMMAND } from './plugins/KaTeXPlugin';
@@ -1 +1 @@
1
- {"version":3,"file":"commands-entry.d.ts","sourceRoot":"","sources":["../src/commands-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"commands-entry.d.ts","sourceRoot":"","sources":["../src/commands-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { K as extractTextContent, k as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, o as $createSpoilerNode, s as $isSpoilerNode } from "./theme-CnNR-Ttt.js";
2
- import { i as INSERT_KATEX_INLINE_COMMAND, l as INSERT_ALERT_COMMAND, o as INSERT_IMAGE_COMMAND, r as INSERT_KATEX_BLOCK_COMMAND, t as INSERT_MERMAID_COMMAND } from "./MermaidPlugin-BOP4CFU_.js";
1
+ import { V as OPEN_FILE_PICKER_COMMAND, k as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, o as $createSpoilerNode, q as extractTextContent, s as $isSpoilerNode } from "./theme-Vu_9D3oG.js";
2
+ import { i as INSERT_KATEX_INLINE_COMMAND, l as INSERT_ALERT_COMMAND, o as INSERT_IMAGE_COMMAND, r as INSERT_KATEX_BLOCK_COMMAND, t as INSERT_MERMAID_COMMAND } from "./MermaidPlugin-DgIAgFH8.js";
3
3
  import { $createTextNode, $getSelection, $isRangeSelection } from "lexical";
4
4
  //#region src/utils/collect-command-items.ts
5
5
  function collectCommandItems(editor) {
@@ -63,4 +63,4 @@ function $toggleSpoilerSelection() {
63
63
  if ($isRangeSelection(freshSelection)) freshSelection.insertNodes([spoiler]);
64
64
  }
65
65
  //#endregion
66
- export { $selectionTouchesSpoiler, $toggleSpoilerSelection, INSERT_ALERT_COMMAND, INSERT_IMAGE_COMMAND, INSERT_KATEX_BLOCK_COMMAND, INSERT_KATEX_INLINE_COMMAND, INSERT_MERMAID_COMMAND, OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, collectCommandItems, extractTextContent };
66
+ export { $selectionTouchesSpoiler, $toggleSpoilerSelection, INSERT_ALERT_COMMAND, INSERT_IMAGE_COMMAND, INSERT_KATEX_BLOCK_COMMAND, INSERT_KATEX_INLINE_COMMAND, INSERT_MERMAID_COMMAND, OPEN_FILE_PICKER_COMMAND, OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, collectCommandItems, extractTextContent };
@@ -1 +1 @@
1
- {"version":3,"file":"CorePlugins.d.ts","sourceRoot":"","sources":["../../src/components/CorePlugins.tsx"],"names":[],"mappings":"AAcA,wBAAgB,WAAW,gCAiB1B"}
1
+ {"version":3,"file":"CorePlugins.d.ts","sourceRoot":"","sources":["../../src/components/CorePlugins.tsx"],"names":[],"mappings":"AAeA,wBAAgB,WAAW,gCAkB1B"}
@@ -1,3 +1,3 @@
1
1
  import { RichEditorProps } from '../types';
2
- export declare function RichEditor({ extraNodes, imageUpload, videoUpload, children, ...shellProps }: RichEditorProps): import("react").JSX.Element;
2
+ export declare function RichEditor({ extraNodes, imageUpload, videoUpload, fileUpload, children, ...shellProps }: RichEditorProps): import("react").JSX.Element;
3
3
  //# sourceMappingURL=RichEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichEditor.d.ts","sourceRoot":"","sources":["../../src/components/RichEditor.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,wBAAgB,UAAU,CAAC,EACzB,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,GAAG,UAAU,EACd,EAAE,eAAe,+BA2BjB"}
1
+ {"version":3,"file":"RichEditor.d.ts","sourceRoot":"","sources":["../../src/components/RichEditor.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,wBAAgB,UAAU,CAAC,EACzB,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,GAAG,UAAU,EACd,EAAE,eAAe,+BA8BjB"}
@@ -0,0 +1,14 @@
1
+ export interface FileRendererProps {
2
+ display?: 'block' | 'inline';
3
+ ext?: string;
4
+ mimeType?: string;
5
+ name: string;
6
+ nodeKey?: string;
7
+ size?: number;
8
+ src: string;
9
+ }
10
+ export declare function formatFileSize(bytes?: number): string | null;
11
+ export declare function fileExtension(name: string, ext?: string): string | null;
12
+ export declare function fileMetaText(name: string, size?: number, ext?: string): string;
13
+ export declare function FileRenderer({ src, name, size, ext, display }: FileRendererProps): import("react").JSX.Element;
14
+ //# sourceMappingURL=FileRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileRenderer.d.ts","sourceRoot":"","sources":["../../../src/components/renderers/FileRenderer.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY5D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,iBAAiB,+BA6BhF"}