@haklex/rich-editor 0.57.0 → 0.59.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 (115) hide show
  1. package/README.md +35 -0
  2. package/dist/{AlertQuoteEditNode-DQt5pIZ8.js → AlertQuoteEditNode-Ck4v29Wg.js} +9 -20
  3. package/dist/BlockIdPlugin-Cwv8aV9g.js +106 -0
  4. package/dist/{ColorSchemeContext-RLg0uDRt.js → ColorSchemeContext-Dc_HebHd.js} +5 -4
  5. package/dist/ContentEditable.css--lQ6ekTS.js +7 -0
  6. package/dist/EditorBlockContext-DytAx9Tg.js +9 -0
  7. package/dist/{ExtraNodesContext-DdU7MZwS.js → ExtraNodesContext-xQ2RNsqH.js} +1 -1
  8. package/dist/{MermaidPlugin-BpoGXa9D.js → MermaidPlugin-BCoGsdi3.js} +3 -3
  9. package/dist/NestedEditorPluginsContext-D78UZkmx.js +16 -0
  10. package/dist/{RubyRenderer-CnTFvt0b.js → RubyRenderer-8HMSMaZz.js} +1 -1
  11. package/dist/VirtualizationPlugin-C8TJ4HJN.js +178 -0
  12. package/dist/{SubmitShortcutPlugin-BuRxU6WD.js → VirtualizationPlugin-Crc0cLUx.js} +969 -532
  13. package/dist/VirtualizedEditor-CIGYcIfr.js +818 -0
  14. package/dist/command-registry-entry.d.ts +3 -0
  15. package/dist/command-registry-entry.d.ts.map +1 -0
  16. package/dist/command-registry-entry.mjs +343 -0
  17. package/dist/commands/registry.d.ts +24 -0
  18. package/dist/commands/registry.d.ts.map +1 -0
  19. package/dist/commands-entry.mjs +2 -2
  20. package/dist/components/EditorSurfaceHost.d.ts +3 -0
  21. package/dist/components/EditorSurfaceHost.d.ts.map +1 -0
  22. package/dist/components/RichEditor.d.ts.map +1 -1
  23. package/dist/components/RichEditorShell.d.ts +3 -1
  24. package/dist/components/RichEditorShell.d.ts.map +1 -1
  25. package/dist/components/VirtualizationFromProps.d.ts +6 -0
  26. package/dist/components/VirtualizationFromProps.d.ts.map +1 -0
  27. package/dist/components/decorators/GridEditDecorator.d.ts.map +1 -1
  28. package/dist/components/renderers/ImageRenderer.d.ts +1 -0
  29. package/dist/components/renderers/ImageRenderer.d.ts.map +1 -1
  30. package/dist/context/EditorBlockContext.d.ts +12 -0
  31. package/dist/context/EditorBlockContext.d.ts.map +1 -0
  32. package/dist/context/EditorSurfaceContext.d.ts +42 -0
  33. package/dist/context/EditorSurfaceContext.d.ts.map +1 -0
  34. package/dist/defineProperty-BYhxpJwd.js +39 -0
  35. package/dist/{grid.css-CUb_icKZ.js → grid.css-DJWKdYpz.js} +2 -1
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.mjs +95 -43
  39. package/dist/{katex.css-9tq8FN8h.js → katex.css-9crOcnIa.js} +2 -1
  40. package/dist/{node-registry-CH2oHfO4.js → node-registry-jRE4LqH-.js} +37 -21
  41. package/dist/nodes/ImageNode.d.ts +7 -1
  42. package/dist/nodes/ImageNode.d.ts.map +1 -1
  43. package/dist/nodes/RichQuoteNode.d.ts +4 -1
  44. package/dist/nodes/RichQuoteNode.d.ts.map +1 -1
  45. package/dist/nodes-entry.mjs +4 -4
  46. package/dist/plugins/FileUploadPlugin.d.ts.map +1 -1
  47. package/dist/plugins/ImageDialog.d.ts +13 -0
  48. package/dist/plugins/ImageDialog.d.ts.map +1 -0
  49. package/dist/plugins/ImageDialogReview.d.ts +13 -0
  50. package/dist/plugins/ImageDialogReview.d.ts.map +1 -0
  51. package/dist/plugins/ImageDialogSource.d.ts +12 -0
  52. package/dist/plugins/ImageDialogSource.d.ts.map +1 -0
  53. package/dist/plugins/ImagePlugin.d.ts.map +1 -1
  54. package/dist/plugins/ImageUploadPlugin.d.ts +1 -1
  55. package/dist/plugins/ImageUploadPlugin.d.ts.map +1 -1
  56. package/dist/plugins/VideoUploadPlugin.d.ts +1 -1
  57. package/dist/plugins/VideoUploadPlugin.d.ts.map +1 -1
  58. package/dist/plugins/VirtualizationPlugin.d.ts +2 -0
  59. package/dist/plugins/VirtualizationPlugin.d.ts.map +1 -0
  60. package/dist/plugins/image-dialog-model.d.ts +65 -0
  61. package/dist/plugins/image-dialog-model.d.ts.map +1 -0
  62. package/dist/plugins/image-dialog.css.d.ts +30 -0
  63. package/dist/plugins/image-dialog.css.d.ts.map +1 -0
  64. package/dist/plugins/image-upload-toast.d.ts +2 -0
  65. package/dist/plugins/image-upload-toast.d.ts.map +1 -0
  66. package/dist/plugins/image-upload.css.d.ts +0 -23
  67. package/dist/plugins/image-upload.css.d.ts.map +1 -1
  68. package/dist/plugins/insertion-cursor.d.ts +20 -0
  69. package/dist/plugins/insertion-cursor.d.ts.map +1 -0
  70. package/dist/plugins/present-image-dialog.d.ts +14 -0
  71. package/dist/plugins/present-image-dialog.d.ts.map +1 -0
  72. package/dist/plugins-entry.d.ts +5 -0
  73. package/dist/plugins-entry.d.ts.map +1 -1
  74. package/dist/plugins-entry.mjs +7 -5
  75. package/dist/recycler-entry.d.ts +8 -0
  76. package/dist/recycler-entry.d.ts.map +1 -0
  77. package/dist/recycler-entry.mjs +3 -0
  78. package/dist/renderers-entry.mjs +4 -4
  79. package/dist/rich-editor.css +1 -1
  80. package/dist/static-entry.d.ts +1 -0
  81. package/dist/static-entry.d.ts.map +1 -1
  82. package/dist/static-entry.mjs +10 -9
  83. package/dist/styles/grid.css.d.ts.map +1 -1
  84. package/dist/styles/shared.css.d.ts.map +1 -1
  85. package/dist/styles-entry.mjs +3 -3
  86. package/dist/{theme-Blq1EG_t.js → theme-DH4xzxU-.js} +63 -48
  87. package/dist/{thumbhash-DHHqtr0c.js → thumbhash-GjK8OYAb.js} +1 -1
  88. package/dist/types.d.ts +3 -0
  89. package/dist/types.d.ts.map +1 -1
  90. package/dist/{utils-CdxPji5z.js → utils-E6qVk-NR.js} +1 -0
  91. package/dist/viewport-BvO92tse.js +210 -0
  92. package/dist/virtualization/VirtualizationPlugin.d.ts +5 -0
  93. package/dist/virtualization/VirtualizationPlugin.d.ts.map +1 -0
  94. package/dist/virtualization/VirtualizedEditor.d.ts +6 -0
  95. package/dist/virtualization/VirtualizedEditor.d.ts.map +1 -0
  96. package/dist/virtualization/controller.d.ts +73 -0
  97. package/dist/virtualization/controller.d.ts.map +1 -0
  98. package/dist/virtualization/document.d.ts +26 -0
  99. package/dist/virtualization/document.d.ts.map +1 -0
  100. package/dist/virtualization/layout.d.ts +42 -0
  101. package/dist/virtualization/layout.d.ts.map +1 -0
  102. package/dist/virtualization/preserve.d.ts +21 -0
  103. package/dist/virtualization/preserve.d.ts.map +1 -0
  104. package/dist/virtualization/style.css.d.ts +4 -0
  105. package/dist/virtualization/style.css.d.ts.map +1 -0
  106. package/dist/virtualization/sync.d.ts +4 -0
  107. package/dist/virtualization/sync.d.ts.map +1 -0
  108. package/dist/virtualization/types.d.ts +13 -0
  109. package/dist/virtualization/types.d.ts.map +1 -0
  110. package/dist/virtualization/viewport.d.ts +3 -0
  111. package/dist/virtualization/viewport.d.ts.map +1 -0
  112. package/dist/virtualization-entry.d.ts +3 -0
  113. package/dist/virtualization-entry.d.ts.map +1 -0
  114. package/dist/virtualization-entry.mjs +1 -0
  115. package/package.json +17 -5
package/README.md CHANGED
@@ -40,6 +40,41 @@ import '@haklex/rich-editor/style.css';
40
40
 
41
41
  For read-only rendering, use `@haklex/rich-compose` (exports `RichRenderer` and the modular composition API).
42
42
 
43
+ ## Experimental editor recycler
44
+
45
+ Virtualization is **off by default**. The optional plugin keeps the full document in the main editor and projects visible blocks into editable Lexical instances. The recycler implementation loads on demand. Native selection currently spans one editing instance; collaboration and custom plugins still need compatibility work. See the [integration contract and validation](../../demo/src/poc-virtualization/EDITOR-RESULTS.md).
46
+
47
+ ```tsx
48
+ const scrollRef = useRef<HTMLDivElement>(null);
49
+
50
+ <div ref={scrollRef} style={{ height: 600, overflow: 'auto' }}>
51
+ <RichEditor
52
+ initialValue={savedState}
53
+ onChange={save} // receives the full document
54
+ virtualization={{ scrollContainer: scrollRef, preserveCapacity: 32 }}
55
+ />
56
+ </div>;
57
+ ```
58
+
59
+ Alternatively, inject the same recycler as a child plugin:
60
+
61
+ ```tsx
62
+ import { RichEditor } from '@haklex/rich-editor';
63
+ import { VirtualizationPlugin } from '@haklex/rich-editor/virtualization';
64
+
65
+ <RichEditor initialValue={savedState} onChange={save}>
66
+ <VirtualizationPlugin scrollContainer={scrollRef} />
67
+ </RichEditor>;
68
+ ```
69
+
70
+ The scroll container must contain the editor; pass its DOM element, ref, or getter. Without an explicit container, the recycler finds the nearest scrolling ancestor, falling back to the window. `virtualization={false}` overrides a plugin. Options also accept `overscan` in pixels and `estimateBlockHeight(block, width)` for custom block estimates.
71
+
72
+ `preserveCapacity` defaults to **32 offscreen nodes**. Their portals, DOM and editor instances stay mounted in detached hosts. Returning to a preserved node keeps its internal state directly. Once the budget is exceeded, the least recently used offscreen node falls back to state capture and recycling; `0` always uses that fallback. Focused/composing nodes and retained async operations are excluded from eviction. Dormant DOM plugins are suspended, while node components remain mounted. Components with background work can use `useEditorBlock().active` to pause it.
73
+
74
+ The core exposes generic `EditorSurfacePlugin` and `EditorSurfacePlugins` extension points. The virtualization plugin owns its view, node preservation/LRU policy, measurement, scrolling and document bridge. `EditorSurfacePlugins` installs DOM/selection plugins in the selected view; save/history plugins remain on the document editor. `ActiveEditorScope` routes toolbar actions to the focused view editor, and `useActiveEditor()` exposes that editor. In composed modules, use `surfacePlugins` for DOM/selection plugins and `plugins` for document-level extensions, including `VirtualizationPlugin` itself. Do not put the surface-registering plugin inside `EditorSurfacePlugins`.
75
+
76
+ `useEditorBlock()` provides logical node state and `retain()` for UI/async operations. Retention also postpones a requested view switch until the operation commits. Built-in media uploads use this contract. Custom components need a fallback state adapter if their internal state must survive LRU eviction; details and dynamic components are already adapted. Dynamic `getState()` should return an independent snapshot, and `setState(undefined)` must reset a fresh binding.
77
+
43
78
  ## Exports
44
79
 
45
80
  ### Components
@@ -1,14 +1,16 @@
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-Blq1EG_t.js";
2
- import { c as RendererWrapper, m as ALERT_NODE_KEY } from "./thumbhash-DHHqtr0c.js";
1
+ import { B as FootnoteNode, G as AlertQuoteNode, H as $isAlertQuoteNode, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, d as RichQuoteNode, i as TagNode, q as AlertRenderer, t as editorTheme } from "./theme-DH4xzxU-.js";
2
+ import { c as RendererWrapper, m as ALERT_NODE_KEY } from "./thumbhash-GjK8OYAb.js";
3
+ import { t as _defineProperty } from "./defineProperty-BYhxpJwd.js";
4
+ import { n as useNestedEditorPlugins } from "./NestedEditorPluginsContext-D78UZkmx.js";
3
5
  import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
4
6
  import { ListPlugin } from "@lexical/react/LexicalListPlugin";
5
7
  import { AutoLinkNode, LinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
6
8
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
7
- import { createContext, createElement, use, useCallback, useEffect, useMemo } from "react";
9
+ import { createElement, useCallback, useEffect, useMemo } from "react";
8
10
  import { HeadingNode, QuoteNode } from "@lexical/rich-text";
9
11
  import { $addUpdateTag, $createParagraphNode, $getEditor, $getNodeByKey, $getRoot, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, HISTORY_MERGE_TAG, KEY_ARROW_DOWN_COMMAND, KEY_ENTER_COMMAND, PASTE_COMMAND, SKIP_DOM_SELECTION_TAG, createEditor } from "lexical";
10
12
  import { HorizontalRuleNode } from "@lexical/extension";
11
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
14
  import { CodeNode } from "@lexical/code-core";
13
15
  import { ListItemNode, ListNode } from "@lexical/list";
14
16
  import { TableCellNode, TableNode, TableRowNode } from "@lexical/table";
@@ -17,19 +19,6 @@ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
17
19
  import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
18
20
  import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
19
21
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
20
- //#region src/context/NestedEditorPluginsContext.tsx
21
- var NestedEditorPluginsContext = createContext(null);
22
- function NestedEditorPluginsProvider({ children, plugins }) {
23
- const value = useMemo(() => ({ plugins }), [plugins]);
24
- return /* @__PURE__ */ jsx(NestedEditorPluginsContext.Provider, {
25
- value,
26
- children
27
- });
28
- }
29
- function useNestedEditorPlugins() {
30
- return use(NestedEditorPluginsContext)?.plugins ?? null;
31
- }
32
- //#endregion
33
22
  //#region src/plugins/PasteLinkPlugin.tsx
34
23
  var LINK_PROTOCOLS = /* @__PURE__ */ new Set([
35
24
  "http:",
@@ -71,7 +60,7 @@ function PasteLinkPlugin() {
71
60
  //#region src/components/decorators/NestedEditorCorePlugins.tsx
72
61
  function NestedEditorCorePlugins() {
73
62
  const nestedEditorPlugins = useNestedEditorPlugins();
74
- return /* @__PURE__ */ jsxs(Fragment, { children: [
63
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
75
64
  /* @__PURE__ */ jsx(ListPlugin, {}),
76
65
  /* @__PURE__ */ jsx(LinkPlugin, {}),
77
66
  /* @__PURE__ */ jsx(PasteLinkPlugin, {}),
@@ -195,7 +184,7 @@ function AlertEditDecorator({ nodeKey, alertType, contentEditor }) {
195
184
  if ($isAlertQuoteNode(node)) node.setAlertType(newType);
196
185
  });
197
186
  }, [editor, nodeKey]);
198
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(RendererWrapper, {
187
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(RendererWrapper, {
199
188
  defaultRenderer: AlertRenderer,
200
189
  rendererKey: ALERT_NODE_KEY,
201
190
  props: {
@@ -372,4 +361,4 @@ function $createAlertQuoteEditNode(alertType, contentState) {
372
361
  return new AlertQuoteEditNode(alertType, contentState);
373
362
  }
374
363
  //#endregion
375
- export { useNestedEditorSync as a, PasteLinkPlugin as c, createNestedEditor as i, NestedEditorPluginsProvider as l, AlertQuoteEditNode as n, registerNestedEditorSync as o, NESTED_EDITOR_NODES as r, NestedEditorCorePlugins as s, $createAlertQuoteEditNode as t, useNestedEditorPlugins as u };
364
+ export { useNestedEditorSync as a, PasteLinkPlugin as c, createNestedEditor as i, AlertQuoteEditNode as n, registerNestedEditorSync as o, NESTED_EDITOR_NODES as r, NestedEditorCorePlugins as s, $createAlertQuoteEditNode as t };
@@ -0,0 +1,106 @@
1
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
+ import { useEffect } from "react";
3
+ import { $addUpdateTag, $getRoot, $getState, $setState, createState } from "lexical";
4
+ import { nanoid } from "nanoid";
5
+ //#region src/plugins/BlockIdPlugin.tsx
6
+ var blockIdState = createState("blockId", { parse: (v) => typeof v === "string" ? v : "" });
7
+ var NORMALIZATION_TAG = "block-id-normalization";
8
+ function buildPreviousIdIndex(editorState) {
9
+ return editorState.read(() => {
10
+ const map = /* @__PURE__ */ new Map();
11
+ for (const child of $getRoot().getChildren()) {
12
+ const id = $getState(child, blockIdState);
13
+ if (!id) continue;
14
+ const set = map.get(id) ?? /* @__PURE__ */ new Set();
15
+ set.add(child.getKey());
16
+ map.set(id, set);
17
+ }
18
+ return map;
19
+ });
20
+ }
21
+ function collectRootChildren(editorState) {
22
+ return editorState.read(() => $getRoot().getChildren().map((child) => $getState(child, blockIdState)));
23
+ }
24
+ function hasDuplicateOrMissingId(children) {
25
+ const seen = /* @__PURE__ */ new Set();
26
+ for (const id of children) {
27
+ if (!id || seen.has(id)) return true;
28
+ seen.add(id);
29
+ }
30
+ return false;
31
+ }
32
+ function generateBlockId(used) {
33
+ while (true) {
34
+ const id = nanoid(8);
35
+ if (!used.has(id)) return id;
36
+ }
37
+ }
38
+ function pickKeeperKey(nodes, previousKeys) {
39
+ if (!nodes.length) return null;
40
+ if (previousKeys?.size) {
41
+ for (const node of nodes) if (previousKeys.has(node.getKey())) return node.getKey();
42
+ }
43
+ return nodes[0]?.getKey() ?? null;
44
+ }
45
+ function normalizeRootBlockIds(editor, previousIdIndex) {
46
+ editor.update(() => {
47
+ $addUpdateTag("history-merge");
48
+ const children = $getRoot().getChildren();
49
+ const groupedById = /* @__PURE__ */ new Map();
50
+ for (const child of children) {
51
+ const id = $getState(child, blockIdState);
52
+ if (!id) continue;
53
+ const bucket = groupedById.get(id) ?? [];
54
+ bucket.push(child);
55
+ groupedById.set(id, bucket);
56
+ }
57
+ const keeperById = /* @__PURE__ */ new Map();
58
+ for (const [id, nodes] of groupedById) {
59
+ if (nodes.length <= 1) continue;
60
+ const keeperKey = pickKeeperKey(nodes, previousIdIndex.get(id));
61
+ if (keeperKey) keeperById.set(id, keeperKey);
62
+ }
63
+ const used = /* @__PURE__ */ new Set();
64
+ for (const child of children) {
65
+ let id = $getState(child, blockIdState);
66
+ const keeperKey = id ? keeperById.get(id) : null;
67
+ if (!id || used.has(id) || keeperKey !== void 0 && child.getKey() !== keeperKey) {
68
+ id = generateBlockId(used);
69
+ $setState(child, blockIdState, id);
70
+ }
71
+ used.add(id);
72
+ }
73
+ }, { tag: NORMALIZATION_TAG });
74
+ }
75
+ function syncBlockIdAttributes(editor) {
76
+ editor.getEditorState().read(() => {
77
+ for (const child of $getRoot().getChildren()) {
78
+ const id = $getState(child, blockIdState);
79
+ if (!id) continue;
80
+ const dom = editor.getElementByKey(child.getKey());
81
+ if (dom && dom.getAttribute("data-block-id") !== id) dom.setAttribute("data-block-id", id);
82
+ }
83
+ });
84
+ }
85
+ function BlockIdPlugin() {
86
+ const [editor] = useLexicalComposerContext();
87
+ useEffect(() => {
88
+ if (hasDuplicateOrMissingId(collectRootChildren(editor.getEditorState()))) normalizeRootBlockIds(editor, /* @__PURE__ */ new Map());
89
+ syncBlockIdAttributes(editor);
90
+ return editor.registerUpdateListener(({ tags, editorState, prevEditorState }) => {
91
+ if (tags.has(NORMALIZATION_TAG)) {
92
+ syncBlockIdAttributes(editor);
93
+ return;
94
+ }
95
+ if (!hasDuplicateOrMissingId(collectRootChildren(editorState))) {
96
+ syncBlockIdAttributes(editor);
97
+ return;
98
+ }
99
+ const previousIdIndex = buildPreviousIdIndex(prevEditorState);
100
+ normalizeRootBlockIds(editor, previousIdIndex);
101
+ });
102
+ }, [editor]);
103
+ return null;
104
+ }
105
+ //#endregion
106
+ export { blockIdState as n, BlockIdPlugin as t };
@@ -1,7 +1,8 @@
1
- import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-CdxPji5z.js";
2
- import { B as FootnoteNode, C as KaTeXBlockNode, E as ImageNode, G as AlertQuoteNode, K as _defineProperty, V as OPEN_FILE_PICKER_COMMAND, X as useNestedContentRenderer, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, d as RichQuoteNode, et as markInlineDraggable, i as TagNode, m as MermaidNode, q as extractTextContent } from "./theme-Blq1EG_t.js";
3
- import { D as VIDEO_NODE_KEY, S as LINK_CARD_NODE_KEY, _ as FILE_NODE_KEY, c as RendererWrapper, g as CODE_BLOCK_NODE_KEY, h as BANNER_NODE_KEY, l as createRendererDecoration, o as useFootnoteDefinitions, y as FOOTNOTE_SECTION_NODE_KEY } from "./thumbhash-DHHqtr0c.js";
4
- import { i as detailsStyles, n as gridStyles, r as detailsClassNames, t as gridClassNames } from "./grid.css-CUb_icKZ.js";
1
+ import { $ as markInlineDraggable, B as FootnoteNode, C as KaTeXBlockNode, E as ImageNode, G as AlertQuoteNode, K as extractTextContent, V as OPEN_FILE_PICKER_COMMAND, Y as useNestedContentRenderer, _ as MentionNode, b as KaTeXInlineNode, c as SpoilerNode, d as RichQuoteNode, i as TagNode, m as MermaidNode } from "./theme-DH4xzxU-.js";
2
+ import { D as VIDEO_NODE_KEY, S as LINK_CARD_NODE_KEY, _ as FILE_NODE_KEY, c as RendererWrapper, g as CODE_BLOCK_NODE_KEY, h as BANNER_NODE_KEY, l as createRendererDecoration, o as useFootnoteDefinitions, y as FOOTNOTE_SECTION_NODE_KEY } from "./thumbhash-GjK8OYAb.js";
3
+ import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-E6qVk-NR.js";
4
+ import { t as _defineProperty } from "./defineProperty-BYhxpJwd.js";
5
+ import { i as detailsStyles, n as gridStyles, r as detailsClassNames, t as gridClassNames } from "./grid.css-DJWKdYpz.js";
5
6
  import { n as FileRenderer, t as LinkCardRenderer } from "./LinkCardRenderer-BT8P5aJC.js";
6
7
  import { AutoLinkNode, LinkNode } from "@lexical/link";
7
8
  import { createContext, createElement, use, useCallback } from "react";
@@ -0,0 +1,7 @@
1
+ /* empty css */
2
+ //#region src/components/ContentEditable.css.ts
3
+ var contentWrapper = "b94s950";
4
+ var content = "b94s951";
5
+ var placeholder = "b94s952";
6
+ //#endregion
7
+ export { contentWrapper as n, placeholder as r, content as t };
@@ -0,0 +1,9 @@
1
+ import { createContext, use } from "react";
2
+ //#region src/context/EditorBlockContext.tsx
3
+ var EditorBlockContext = createContext(null);
4
+ /** Optional logical block identity/state for views that rebind editing instances. */
5
+ function useEditorBlock() {
6
+ return use(EditorBlockContext);
7
+ }
8
+ //#endregion
9
+ export { useEditorBlock as n, EditorBlockContext as t };
@@ -1,4 +1,4 @@
1
- import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-CdxPji5z.js";
1
+ import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-E6qVk-NR.js";
2
2
  import { n as getHostname, r as probeFavicon } from "./normalizeSerializedEditorState-VaI73T09.js";
3
3
  import { createContext, use, useEffect, useMemo, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
@@ -1,5 +1,5 @@
1
- import { O as $withAdaptiveImageDisplayWidth, f as $createMermaidNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode } from "./theme-Blq1EG_t.js";
2
- import { t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-DQt5pIZ8.js";
1
+ import { O as $withAdaptiveImageDisplayWidth, f as $createMermaidNode, v as $createKaTeXInlineNode, w as $createImageNode, x as $createKaTeXBlockNode } from "./theme-DH4xzxU-.js";
2
+ import { t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-Ck4v29Wg.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";
@@ -22,7 +22,7 @@ function ImagePlugin() {
22
22
  const [editor] = useLexicalComposerContext();
23
23
  useEffect(() => {
24
24
  return editor.registerCommand(INSERT_IMAGE_COMMAND, (payload) => {
25
- const imageNode = $createImageNode($withAdaptiveImageDisplayWidth(payload));
25
+ const imageNode = $createImageNode($withAdaptiveImageDisplayWidth(payload), { autoOpenOnMount: !payload.src });
26
26
  $insertNodes([imageNode]);
27
27
  return true;
28
28
  }, COMMAND_PRIORITY_EDITOR);
@@ -0,0 +1,16 @@
1
+ import { createContext, use, useMemo } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ //#region src/context/NestedEditorPluginsContext.tsx
4
+ var NestedEditorPluginsContext = createContext(null);
5
+ function NestedEditorPluginsProvider({ children, plugins }) {
6
+ const value = useMemo(() => ({ plugins }), [plugins]);
7
+ return /* @__PURE__ */ jsx(NestedEditorPluginsContext.Provider, {
8
+ value,
9
+ children
10
+ });
11
+ }
12
+ function useNestedEditorPlugins() {
13
+ return use(NestedEditorPluginsContext)?.plugins ?? null;
14
+ }
15
+ //#endregion
16
+ export { useNestedEditorPlugins as n, NestedEditorPluginsProvider as t };
@@ -1,4 +1,4 @@
1
- import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-CdxPji5z.js";
1
+ import { c as semanticClassNames, l as sharedStyles, t as clsx } from "./utils-E6qVk-NR.js";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  //#region src/components/renderers/RubyRenderer.tsx
4
4
  function RubyRenderer({ reading, children }) {
@@ -0,0 +1,178 @@
1
+ import { LexicalComposerContext, useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
+ import { Fragment, Suspense, createContext, lazy, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW } from "lexical";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/context/EditorSurfaceContext.tsx
6
+ var Context = createContext(null);
7
+ function EditorSurfaceProvider({ children }) {
8
+ const [documentEditor] = useLexicalComposerContext();
9
+ const [activeEditor, setActiveEditor] = useState(documentEditor);
10
+ const active = useRef(activeEditor);
11
+ active.current = activeEditor;
12
+ const history = useRef({
13
+ undo: false,
14
+ redo: false
15
+ });
16
+ useEffect(() => {
17
+ const register = (command, key) => documentEditor.registerCommand(command, (value, fromEditor) => {
18
+ if (fromEditor !== documentEditor) return false;
19
+ history.current[key] = value;
20
+ const target = active.current;
21
+ if (target && target !== documentEditor) target.dispatchCommand(command, value);
22
+ return false;
23
+ }, COMMAND_PRIORITY_LOW);
24
+ const unregister = [register(CAN_UNDO_COMMAND, "undo"), register(CAN_REDO_COMMAND, "redo")];
25
+ return () => unregister.forEach((dispose) => dispose());
26
+ }, [documentEditor]);
27
+ useEffect(() => {
28
+ if (activeEditor && activeEditor !== documentEditor) {
29
+ activeEditor.dispatchCommand(CAN_UNDO_COMMAND, history.current.undo);
30
+ activeEditor.dispatchCommand(CAN_REDO_COMMAND, history.current.redo);
31
+ }
32
+ }, [activeEditor, documentEditor]);
33
+ const [surfaces, setSurfaces] = useState(() => /* @__PURE__ */ new Map());
34
+ const [injections, setInjections] = useState(() => /* @__PURE__ */ new Map());
35
+ const registerSurface = useCallback((key, surface, priority) => {
36
+ setSurfaces((previous) => new Map(previous).set(key, {
37
+ surface,
38
+ priority
39
+ }));
40
+ return () => setSurfaces((previous) => {
41
+ const next = new Map(previous);
42
+ next.delete(key);
43
+ return next;
44
+ });
45
+ }, []);
46
+ const registerPlugins = useCallback((key, plugins) => {
47
+ setInjections((previous) => new Map(previous).set(key, plugins));
48
+ return () => setInjections((previous) => {
49
+ const next = new Map(previous);
50
+ next.delete(key);
51
+ return next;
52
+ });
53
+ }, []);
54
+ const requested = useMemo(() => {
55
+ let selected;
56
+ for (const entry of surfaces.values()) if (!selected || entry.priority >= selected.priority) selected = entry;
57
+ return selected?.surface ?? null;
58
+ }, [surfaces]);
59
+ const [leases, setLeases] = useState(0);
60
+ const leaseCount = useRef(0);
61
+ const heldSurface = useRef(null);
62
+ const surface = leases > 0 ? heldSurface.current : requested;
63
+ const currentSurface = useRef(surface);
64
+ currentSurface.current = surface;
65
+ const retainSurface = useCallback(() => {
66
+ if (leaseCount.current++ === 0) heldSurface.current = currentSurface.current;
67
+ setLeases(leaseCount.current);
68
+ let released = false;
69
+ return () => {
70
+ if (released) return;
71
+ released = true;
72
+ setLeases(--leaseCount.current);
73
+ };
74
+ }, []);
75
+ const plugins = useMemo(() => [...injections].map(([key, node]) => /* @__PURE__ */ jsx(Fragment, { children: node }, key)), [injections]);
76
+ useLayoutEffect(() => setActiveEditor(surface ? null : documentEditor), [documentEditor, surface]);
77
+ const value = useMemo(() => ({
78
+ surface,
79
+ activeEditor,
80
+ setActiveEditor,
81
+ plugins,
82
+ registerSurface,
83
+ registerPlugins,
84
+ retainSurface
85
+ }), [
86
+ surface,
87
+ activeEditor,
88
+ plugins,
89
+ registerSurface,
90
+ registerPlugins,
91
+ retainSurface
92
+ ]);
93
+ return /* @__PURE__ */ jsx(Context, {
94
+ value,
95
+ children
96
+ });
97
+ }
98
+ function useEditorSurface() {
99
+ const context = use(Context);
100
+ if (!context) throw new Error("Editor surface extensions must be mounted inside RichEditor");
101
+ return context;
102
+ }
103
+ /** Register an editing surface; null explicitly selects the standard surface. */
104
+ function EditorSurfacePlugin({ surface, priority = 0 }) {
105
+ const key = useId();
106
+ const { registerSurface } = useEditorSurface();
107
+ useLayoutEffect(() => registerSurface(key, surface, priority), [
108
+ key,
109
+ priority,
110
+ registerSurface,
111
+ surface
112
+ ]);
113
+ return null;
114
+ }
115
+ /** Mount DOM/selection plugins inside whichever editing surface is installed. */
116
+ function EditorSurfacePlugins({ children }) {
117
+ const key = useId();
118
+ const { registerPlugins } = useEditorSurface();
119
+ useLayoutEffect(() => registerPlugins(key, children), [
120
+ children,
121
+ key,
122
+ registerPlugins
123
+ ]);
124
+ return null;
125
+ }
126
+ function useActiveEditor() {
127
+ return useEditorSurface().activeEditor;
128
+ }
129
+ /** Keep document-level history/save outside this scope; toolbar actions belong inside it. */
130
+ function ActiveEditorScope({ children }) {
131
+ const [documentEditor, context] = useLexicalComposerContext();
132
+ const activeEditor = useActiveEditor();
133
+ const value = useMemo(() => [activeEditor ?? documentEditor, context], [
134
+ activeEditor,
135
+ context,
136
+ documentEditor
137
+ ]);
138
+ return /* @__PURE__ */ jsx(LexicalComposerContext, {
139
+ value,
140
+ children
141
+ });
142
+ }
143
+ //#endregion
144
+ //#region src/virtualization/VirtualizationPlugin.tsx
145
+ var VirtualizedEditor = lazy(() => import("./VirtualizedEditor-CIGYcIfr.js").then((module) => ({ default: module.VirtualizedEditor })));
146
+ function VirtualizationPlugin({ scrollContainer, overscan, estimateBlockHeight, preserveCapacity, priority = 0 }) {
147
+ const surface = useMemo(() => {
148
+ const options = {
149
+ scrollContainer,
150
+ overscan,
151
+ estimateBlockHeight,
152
+ preserveCapacity
153
+ };
154
+ return function VirtualizationSurface(props) {
155
+ return /* @__PURE__ */ jsx(Suspense, {
156
+ fallback: /* @__PURE__ */ jsx("p", {
157
+ role: "status",
158
+ children: "Loading editor…"
159
+ }),
160
+ children: /* @__PURE__ */ jsx(VirtualizedEditor, {
161
+ ...props,
162
+ options
163
+ })
164
+ });
165
+ };
166
+ }, [
167
+ scrollContainer,
168
+ overscan,
169
+ estimateBlockHeight,
170
+ preserveCapacity
171
+ ]);
172
+ return /* @__PURE__ */ jsx(EditorSurfacePlugin, {
173
+ priority,
174
+ surface
175
+ });
176
+ }
177
+ //#endregion
178
+ export { EditorSurfaceProvider as a, EditorSurfacePlugins as i, ActiveEditorScope as n, useActiveEditor as o, EditorSurfacePlugin as r, useEditorSurface as s, VirtualizationPlugin as t };