@haklex/rich-editor 0.59.0 → 0.60.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.
@@ -142,14 +142,15 @@ function ActiveEditorScope({ children }) {
142
142
  }
143
143
  //#endregion
144
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 }) {
145
+ var VirtualizedEditor = lazy(() => import("./VirtualizedEditor-D9Ivycdp.js").then((module) => ({ default: module.VirtualizedEditor })));
146
+ function VirtualizationPlugin({ scrollContainer, overscan, estimateBlockHeight, preserveCapacity, selectionMergeLimit, priority = 0 }) {
147
147
  const surface = useMemo(() => {
148
148
  const options = {
149
149
  scrollContainer,
150
150
  overscan,
151
151
  estimateBlockHeight,
152
- preserveCapacity
152
+ preserveCapacity,
153
+ selectionMergeLimit
153
154
  };
154
155
  return function VirtualizationSurface(props) {
155
156
  return /* @__PURE__ */ jsx(Suspense, {
@@ -167,7 +168,8 @@ function VirtualizationPlugin({ scrollContainer, overscan, estimateBlockHeight,
167
168
  scrollContainer,
168
169
  overscan,
169
170
  estimateBlockHeight,
170
- preserveCapacity
171
+ preserveCapacity,
172
+ selectionMergeLimit
171
173
  ]);
172
174
  return /* @__PURE__ */ jsx(EditorSurfacePlugin, {
173
175
  priority,
@@ -5,7 +5,7 @@ import { i as FootnoteDefinitionsProvider, t as computeImageMeta } from "./thumb
5
5
  import { C as fileExtFromName, D as $createCommentPlaceholderNode, E as $createCommentNode, F as BannerNode, T as DetailsNode, _ as $createFootnoteSectionNode, b as $createFileNode, c as $createRubyNode, h as $isGridContainerNode, j as CodeBlockNode, k as CommentNode, o as $createVideoNode, u as RubyNode, v as $isFootnoteSectionNode, w as $createDetailsNode, x as $isFileNode, y as FootnoteSectionNode } from "./ColorSchemeContext-Dc_HebHd.js";
6
6
  import { c as PasteLinkPlugin, t as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-Ck4v29Wg.js";
7
7
  import { n as getHostname, r as probeFavicon, t as normalizeSerializedEditorState } from "./normalizeSerializedEditorState-VaI73T09.js";
8
- import "./VirtualizationPlugin-C8TJ4HJN.js";
8
+ import "./VirtualizationPlugin-BA7YFDRN.js";
9
9
  import { n as blockIdState } from "./BlockIdPlugin-Cwv8aV9g.js";
10
10
  import { n as useEditorBlock } from "./EditorBlockContext-DytAx9Tg.js";
11
11
  import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin";
@@ -3,10 +3,10 @@ import { n as useNestedEditorPlugins } from "./NestedEditorPluginsContext-D78UZk
3
3
  import { n as blockIdState } from "./BlockIdPlugin-Cwv8aV9g.js";
4
4
  import { t as EditorBlockContext } from "./EditorBlockContext-DytAx9Tg.js";
5
5
  import { n as contentWrapper, t as content } from "./ContentEditable.css--lQ6ekTS.js";
6
- import { a as PreserveNodeManager, i as slot, l as estimateHeight, n as canvas, o as HeightIndex, s as TypePool, t as resolveScrollContainer, u as occupiedHeight } from "./viewport-BvO92tse.js";
6
+ import { a as PreserveNodeManager, i as slot, l as estimateHeight, n as canvas, o as HeightIndex, s as TypePool, t as resolveScrollContainer, u as occupiedHeight } from "./viewport-CFJHn_Y6.js";
7
7
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
8
8
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
9
- import { $exportNodeJSON, $getNodeByKey, $getRoot, $getSelection, $getSlot, $getSlotNames, $getState, $isElementNode, $isRangeSelection, $parseSerializedNode, $setSelection, $setState, COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, REDO_COMMAND, SKIP_DOM_SELECTION_TAG, SKIP_SCROLL_INTO_VIEW_TAG, UNDO_COMMAND, createEditor } from "lexical";
9
+ import { $exportNodeJSON, $getNodeByKey, $getRoot, $getSelection, $getSlot, $getSlotNames, $getState, $isElementNode, $isRangeSelection, $parseSerializedNode, $setSelection, $setState, COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, REDO_COMMAND, SKIP_DOM_SELECTION_TAG, SKIP_SCROLL_INTO_VIEW_TAG, UNDO_COMMAND, createEditor } from "lexical";
10
10
  import { createPortal, flushSync } from "react-dom";
11
11
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
12
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
@@ -14,6 +14,99 @@ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
14
14
  import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
15
15
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
16
16
  import { nanoid } from "nanoid";
17
+ //#region src/virtualization/blocks.ts
18
+ var DocumentBlockSelection = class {
19
+ constructor(host) {
20
+ _defineProperty(this, "host", void 0);
21
+ _defineProperty(this, "range", void 0);
22
+ _defineProperty(this, "listeners", /* @__PURE__ */ new Set());
23
+ this.host = host;
24
+ }
25
+ get editor() {
26
+ return this.host.master;
27
+ }
28
+ keys() {
29
+ const bounds = this.bounds();
30
+ return bounds ? this.host.rows.slice(bounds[0], bounds[1] + 1).map((row) => row.key) : [];
31
+ }
32
+ islandKeys(editor) {
33
+ const bounds = this.bounds();
34
+ const ids = this.host.islandIds(editor);
35
+ if (!bounds || !ids) return [];
36
+ return editor.getEditorState().read(() => $getRoot().getChildren().filter((_, i) => {
37
+ const index = ids[i] === void 0 ? void 0 : this.host.indexOf(ids[i]);
38
+ return index !== void 0 && index >= bounds[0] && index <= bounds[1];
39
+ }).map((node) => node.getKey()));
40
+ }
41
+ select(editor, anchorKey, focusKey) {
42
+ const ids = this.host.islandIds(editor);
43
+ if (!ids) return;
44
+ const [anchor, focus] = editor.getEditorState().read(() => {
45
+ const keys = $getRoot().getChildren().map((node) => node.getKey());
46
+ return [ids[keys.indexOf(anchorKey)], ids[keys.indexOf(focusKey)]];
47
+ });
48
+ if (anchor && focus) this.set({
49
+ anchorId: anchor,
50
+ focusId: focus
51
+ });
52
+ }
53
+ selectAll() {
54
+ const { rows } = this.host;
55
+ if (rows.length) this.set({
56
+ anchorId: rows[0].id,
57
+ focusId: rows.at(-1).id
58
+ });
59
+ }
60
+ extend(step) {
61
+ const focus = this.range && this.host.indexOf(this.range.focusId);
62
+ const next = focus === void 0 ? void 0 : this.host.rows[focus + step];
63
+ if (!this.range || !next) return false;
64
+ this.set({
65
+ anchorId: this.range.anchorId,
66
+ focusId: next.id
67
+ });
68
+ return true;
69
+ }
70
+ clear() {
71
+ if (this.range) this.set(void 0);
72
+ }
73
+ prune() {
74
+ if (this.range && (this.host.indexOf(this.range.anchorId) === void 0 || this.host.indexOf(this.range.focusId) === void 0)) this.set(void 0);
75
+ }
76
+ focusSelection() {
77
+ const target = this.host.master.getEditorState().read(() => {
78
+ const selection = $getSelection();
79
+ if (!$isRangeSelection(selection)) return null;
80
+ const node = selection.anchor.getNode();
81
+ const top = node.getTopLevelElement() ?? node;
82
+ const last = ($isElementNode(top) ? top.getLastDescendant() : null) ?? top;
83
+ return {
84
+ key: top.getKey(),
85
+ end: node.is(last) && selection.anchor.offset === node.getTextContentSize()
86
+ };
87
+ });
88
+ const index = target ? this.host.rows.findIndex((row) => row.key === target.key) : -1;
89
+ if (index >= 0) this.host.focusBlock(index, target.end);
90
+ }
91
+ subscribe(listener) {
92
+ this.listeners.add(listener);
93
+ return () => {
94
+ this.listeners.delete(listener);
95
+ };
96
+ }
97
+ bounds() {
98
+ if (!this.range) return null;
99
+ const anchor = this.host.indexOf(this.range.anchorId);
100
+ const focus = this.host.indexOf(this.range.focusId);
101
+ if (anchor === void 0 || focus === void 0) return null;
102
+ return [Math.min(anchor, focus), Math.max(anchor, focus)];
103
+ }
104
+ set(range) {
105
+ this.range = range;
106
+ this.listeners.forEach((listener) => listener());
107
+ }
108
+ };
109
+ //#endregion
17
110
  //#region src/virtualization/document.ts
18
111
  function $serializeBlock(node) {
19
112
  const data = $exportNodeJSON(node);
@@ -128,6 +221,22 @@ function $syncChildren(parent, data) {
128
221
  }
129
222
  //#endregion
130
223
  //#region src/virtualization/controller.ts
224
+ function $topLevel(node) {
225
+ while (node?.getParent() && node.getParent().getType() !== "root") node = node.getParent();
226
+ return node?.getParent() ? node : null;
227
+ }
228
+ function caretFromPoint(x, y) {
229
+ const position = document.caretPositionFromPoint?.(x, y);
230
+ if (position) return {
231
+ node: position.offsetNode,
232
+ offset: position.offset
233
+ };
234
+ const range = document.caretRangeFromPoint?.(x, y);
235
+ return range ? {
236
+ node: range.startContainer,
237
+ offset: range.startOffset
238
+ } : null;
239
+ }
131
240
  var EditorRecycler = class {
132
241
  constructor(master, canvas, options) {
133
242
  _defineProperty(this, "master", void 0);
@@ -139,6 +248,7 @@ var EditorRecycler = class {
139
248
  _defineProperty(this, "states", /* @__PURE__ */ new Map());
140
249
  _defineProperty(this, "viewport", void 0);
141
250
  _defineProperty(this, "preserve", void 0);
251
+ _defineProperty(this, "documentBlocks", new DocumentBlockSelection(this));
142
252
  _defineProperty(this, "heights", void 0);
143
253
  _defineProperty(this, "revision", 0);
144
254
  _defineProperty(this, "indices", /* @__PURE__ */ new Map());
@@ -149,8 +259,51 @@ var EditorRecycler = class {
149
259
  _defineProperty(this, "width", void 0);
150
260
  _defineProperty(this, "metrics", /* @__PURE__ */ new Map());
151
261
  _defineProperty(this, "firstParagraph", -1);
262
+ _defineProperty(this, "selectionOwner", void 0);
263
+ _defineProperty(this, "splitting", /* @__PURE__ */ new Set());
264
+ _defineProperty(this, "drag", void 0);
152
265
  _defineProperty(this, "previousRows", []);
153
- _defineProperty(this, "onScroll", () => this.refresh());
266
+ _defineProperty(this, "onScroll", () => {
267
+ this.refresh();
268
+ if (this.drag) this.dragTo(this.drag.y);
269
+ });
270
+ _defineProperty(this, "onPointerDown", (event) => {
271
+ if (event.button !== 0) return;
272
+ this.documentBlocks.clear();
273
+ const target = this.pool.slots.find((item) => item.active && item.element?.contains(event.target));
274
+ if (!target) return;
275
+ const owner = this.pool.slots.find((item) => item.active && item.id === this.selectionOwner);
276
+ const slot = event.shiftKey && owner && owner !== target ? owner : target;
277
+ const root = this.island(slot).editor.getRootElement();
278
+ if (!root) return;
279
+ if (slot !== target) {
280
+ event.preventDefault();
281
+ this.extendToPoint(slot, root, event.clientX, event.clientY);
282
+ } else if (event.target.closest?.("[contenteditable]") !== root) return;
283
+ this.drag = {
284
+ slot,
285
+ y: event.clientY
286
+ };
287
+ document.addEventListener("pointermove", this.onPointerMove);
288
+ document.addEventListener("pointerup", this.endDrag);
289
+ document.addEventListener("pointercancel", this.endDrag);
290
+ });
291
+ _defineProperty(this, "onPointerMove", (event) => {
292
+ if (!this.drag) return;
293
+ if (!(event.buttons & 1)) return this.endDrag();
294
+ this.drag.y = event.clientY;
295
+ this.dragTo(event.clientY);
296
+ });
297
+ _defineProperty(this, "endDrag", () => {
298
+ this.drag = void 0;
299
+ document.removeEventListener("pointermove", this.onPointerMove);
300
+ document.removeEventListener("pointerup", this.endDrag);
301
+ document.removeEventListener("pointercancel", this.endDrag);
302
+ });
303
+ _defineProperty(this, "onFocusIn", (event) => {
304
+ const slot = this.pool.slots.find((item) => item.element?.contains(event.target));
305
+ if (slot) this.selectionOwner = slot.id;
306
+ });
154
307
  this.master = master;
155
308
  this.canvas = canvas;
156
309
  this.options = options;
@@ -186,6 +339,8 @@ var EditorRecycler = class {
186
339
  if (this.viewport instanceof HTMLElement) this.observer.observe(this.viewport);
187
340
  this.viewport.addEventListener("scroll", this.onScroll, { passive: true });
188
341
  window.addEventListener("resize", this.onScroll);
342
+ canvas.addEventListener("focusin", this.onFocusIn);
343
+ canvas.addEventListener("pointerdown", this.onPointerDown);
189
344
  this.refresh(false);
190
345
  }
191
346
  get rows() {
@@ -224,12 +379,14 @@ var EditorRecycler = class {
224
379
  if (this.rows.length !== this.previousRows.length || this.rows.some((row, i) => row.id !== this.previousRows[i].id)) this.heights = new HeightIndex(this.rows.map((row) => previous.get(row.id)?.height ?? this.estimate(row.data)));
225
380
  const indices = new Map(this.rows.map((row, index) => [row.id, index]));
226
381
  this.indices = indices;
382
+ this.documentBlocks.prune();
227
383
  this.firstParagraph = this.rows.findIndex((row) => row.data.type === "paragraph");
228
384
  for (const id of this.metrics.keys()) if (!indices.has(id)) this.metrics.delete(id);
229
385
  for (const slot of this.pool.slots) {
230
386
  const island = this.islands.get(slot.id);
231
387
  if (!island) continue;
232
- island.ids = island.ids.filter((id) => indices.has(id));
388
+ const positions = island.ids.flatMap((id) => indices.get(id) ?? []);
389
+ island.ids = positions.length > 1 ? this.rows.slice(Math.min(...positions), Math.max(...positions) + 1).map((row) => row.id) : positions.map((index) => this.rows[index].id);
233
390
  island.source = source === `virtual-island:${slot.id}`;
234
391
  if (island.ids.length) {
235
392
  slot.index = indices.get(island.ids[0]);
@@ -270,6 +427,31 @@ var EditorRecycler = class {
270
427
  if (sync) flushSync(notify);
271
428
  else notify();
272
429
  }
430
+ indexOf(id) {
431
+ return this.indices.get(id);
432
+ }
433
+ islandIds(editor) {
434
+ for (const island of this.islands.values()) if (island.editor === editor) return island.ids;
435
+ }
436
+ rowAt(clientY) {
437
+ const y = clientY - this.canvas.getBoundingClientRect().top - this.leadingMargin;
438
+ return this.heights.find(Math.max(0, y));
439
+ }
440
+ dragTo(clientY) {
441
+ const slot = this.drag?.slot;
442
+ if (!slot?.active) return;
443
+ const index = this.rowAt(clientY);
444
+ if (index < slot.index || index >= slot.index + this.island(slot).ids.length) this.extendIsland(slot, index, true);
445
+ }
446
+ extendToPoint(slot, root, x, y) {
447
+ if (!this.extendIsland(slot, this.rowAt(y), true)) return;
448
+ const selection = window.getSelection();
449
+ const caret = caretFromPoint(x, y);
450
+ if (selection?.anchorNode && root.contains(selection.anchorNode) && caret && root.contains(caret.node)) selection.extend(caret.node, caret.offset);
451
+ }
452
+ holdsSelection(slot, island) {
453
+ return slot.id === this.selectionOwner && island.editor.getEditorState().read(() => $getSelection() !== null);
454
+ }
273
455
  refresh(sync = true) {
274
456
  if (this.dead || !this.rows.length) return;
275
457
  const y = Math.max(0, this.scrollTop - this.canvasTop());
@@ -282,7 +464,7 @@ var EditorRecycler = class {
282
464
  for (const slot of this.pool.slots) {
283
465
  const island = this.islands.get(slot.id);
284
466
  if (!island || !slot.active && !this.preserve.has(slot.id)) continue;
285
- if (island.retained || island.editor.isComposing() || slot.element?.contains(document.activeElement)) pinned.add(slot.id);
467
+ if (island.retained || island.editor.isComposing() || slot.element?.contains(document.activeElement) || this.holdsSelection(slot, island)) pinned.add(slot.id);
286
468
  for (let i = 1; i < island.ids.length; i++) covered.add(slot.index + i);
287
469
  if (island.ids.length > 1 && slot.index < first && slot.index + island.ids.length > first) groupHeads.push(slot.index);
288
470
  }
@@ -317,13 +499,15 @@ var EditorRecycler = class {
317
499
  };
318
500
  this.islands.set(slot.id, island);
319
501
  island.unsubscribe = editor.registerUpdateListener(({ editorState, dirtyElements, dirtyLeaves, tags }) => {
502
+ if (island.ids.length > 1) this.queueSplit(slot);
320
503
  if (island.loading || !island.ids.length || tags.has("virtual-bind") || !dirtyElements.size && !dirtyLeaves.size) return;
321
504
  const children = editorState.toJSON().root.children;
322
505
  if (JSON.stringify(children) === island.data) return;
323
506
  const used = /* @__PURE__ */ new Set();
324
507
  children.forEach((data, i) => {
325
508
  let id = data.$?.blockId;
326
- if (!id || used.has(id)) id = i === 0 ? island.ids[0] : nanoid(8);
509
+ const foreign = this.indices.has(id) && !island.ids.includes(id);
510
+ if (!id || used.has(id) || foreign) id = i === 0 ? island.ids[0] : nanoid(8);
327
511
  data.$ = {
328
512
  ...data.$,
329
513
  blockId: id
@@ -532,12 +716,104 @@ var EditorRecycler = class {
532
716
  requestAnimationFrame(() => {
533
717
  const slot = this.pool.slots.find((item) => item.active && this.islands.get(item.id)?.ids.includes(this.rows[index]?.id));
534
718
  if (!slot) return;
535
- this.island(slot).editor.update(() => {
719
+ const { editor } = this.island(slot);
720
+ editor.getRootElement()?.focus({ preventScroll: true });
721
+ editor.update(() => {
536
722
  if (end) $getRoot().selectEnd();
537
723
  else $getRoot().selectStart();
538
724
  }, { tag: scroll ? void 0 : SKIP_SCROLL_INTO_VIEW_TAG });
539
725
  });
540
726
  }
727
+ extendIsland(slot, toIndex, sync = false) {
728
+ const island = this.island(slot);
729
+ const first = slot.index;
730
+ const last = first + island.ids.length - 1;
731
+ const target = Math.max(0, Math.min(toIndex, this.rows.length - 1));
732
+ if (target >= first && target <= last) return true;
733
+ const backward = target < first;
734
+ const added = backward ? this.rows.slice(target, first) : this.rows.slice(last + 1, target + 1);
735
+ if (island.ids.length + added.length > (this.options.selectionMergeLimit ?? 200)) return false;
736
+ const addedIds = new Set(added.map((row) => row.id));
737
+ const holders = this.pool.slots.filter((other) => other !== slot && this.islands.get(other.id)?.ids.some((id) => addedIds.has(id)));
738
+ if (holders.some((other) => {
739
+ const held = this.islands.get(other.id);
740
+ return held.retained > 0 || held.editor.isComposing();
741
+ })) return false;
742
+ for (const other of holders) {
743
+ other.beforeRelease?.();
744
+ other.active = false;
745
+ this.islands.get(other.id).generation = -1;
746
+ }
747
+ island.ids = backward ? [...addedIds, ...island.ids] : [...island.ids, ...addedIds];
748
+ if (backward) slot.index = target;
749
+ island.data = JSON.stringify(island.ids.map((id) => this.rows[this.indices.get(id)].data));
750
+ island.editor.update(() => {
751
+ const nodes = added.map((row) => $parseSerializedNode(row.data));
752
+ const head = $getRoot().getFirstChild();
753
+ if (backward && head) nodes.forEach((node) => head.insertBefore(node));
754
+ else $getRoot().append(...nodes);
755
+ }, {
756
+ discrete: true,
757
+ tag: ["virtual-bind", SKIP_DOM_SELECTION_TAG]
758
+ });
759
+ this.refresh(false);
760
+ this.publish(sync);
761
+ this.queueMeasure();
762
+ return true;
763
+ }
764
+ extendForKey(slot, key) {
765
+ const island = this.island(slot);
766
+ const forward = key === "down" || key === "right";
767
+ const atEdge = island.editor.getEditorState().read(() => {
768
+ const selection = $getSelection();
769
+ if (!$isRangeSelection(selection)) return false;
770
+ const root = $getRoot();
771
+ const focus = selection.focus.getNode();
772
+ if (key === "up" || key === "down") return $topLevel(focus)?.is(forward ? root.getLastChild() : root.getFirstChild()) ?? false;
773
+ const edge = forward ? root.getLastDescendant() : root.getFirstDescendant();
774
+ return !!edge && focus.is(edge) && selection.focus.offset === (forward ? edge.getTextContentSize() : 0);
775
+ });
776
+ const index = forward ? slot.index + island.ids.length : slot.index - 1;
777
+ if (!atEdge || index < 0 || index >= this.rows.length) return false;
778
+ return this.extendIsland(slot, index);
779
+ }
780
+ splitIsland(slot) {
781
+ const island = this.islands.get(slot.id);
782
+ if (!island || island.ids.length < 2) return;
783
+ const keep = island.editor.getEditorState().read(() => {
784
+ const selection = $getSelection();
785
+ return $topLevel($isRangeSelection(selection) ? selection.focus.getNode() : null)?.getIndexWithinParent() ?? 0;
786
+ });
787
+ const id = island.ids[keep] ?? island.ids[0];
788
+ island.ids = [id];
789
+ slot.index = this.indices.get(id);
790
+ island.data = JSON.stringify([this.rows[slot.index].data]);
791
+ island.editor.update(() => $getRoot().getChildren().forEach((node, i) => {
792
+ if (i !== keep) node.remove();
793
+ }), {
794
+ discrete: true,
795
+ tag: "virtual-bind"
796
+ });
797
+ this.refresh(false);
798
+ this.publish();
799
+ this.queueMeasure();
800
+ }
801
+ queueSplit(slot) {
802
+ if (this.splitting.has(slot.id)) return;
803
+ this.splitting.add(slot.id);
804
+ requestAnimationFrame(() => {
805
+ this.splitting.delete(slot.id);
806
+ const island = this.islands.get(slot.id);
807
+ if (this.dead || !slot.active || !island || island.editor.isComposing()) return;
808
+ const live = window.getSelection();
809
+ const root = island.editor.getRootElement();
810
+ if (live && !live.isCollapsed && live.anchorNode && root?.contains(live.anchorNode)) return;
811
+ if (island.editor.getEditorState().read(() => {
812
+ const selection = $getSelection();
813
+ return selection === null || $isRangeSelection(selection) && selection.isCollapsed();
814
+ })) this.splitIsland(slot);
815
+ });
816
+ }
541
817
  joinNeighbor(slot, backward) {
542
818
  const island = this.island(slot);
543
819
  const index = backward ? slot.index - 1 : slot.index + island.ids.length;
@@ -565,6 +841,9 @@ var EditorRecycler = class {
565
841
  cancelAnimationFrame(this.frame);
566
842
  this.viewport.removeEventListener("scroll", this.onScroll);
567
843
  window.removeEventListener("resize", this.onScroll);
844
+ this.canvas.removeEventListener("focusin", this.onFocusIn);
845
+ this.canvas.removeEventListener("pointerdown", this.onPointerDown);
846
+ this.endDrag();
568
847
  for (const island of this.islands.values()) island.unsubscribe();
569
848
  this.listeners.clear();
570
849
  this.preserve.clear();
@@ -581,6 +860,10 @@ function IslandPlugins({ controller, slot }) {
581
860
  const node = end ? $getRoot().getLastDescendant() : $getRoot().getFirstDescendant();
582
861
  return !!node && selection.anchor.key === node.getKey() && selection.anchor.offset === (end ? node.getTextContentSize() : 0);
583
862
  };
863
+ const extend = (key) => {
864
+ controller.extendForKey(slot, key);
865
+ return false;
866
+ };
584
867
  const unregister = [
585
868
  editor.registerCommand(UNDO_COMMAND, () => {
586
869
  controller.master.dispatchCommand(UNDO_COMMAND, void 0);
@@ -601,19 +884,23 @@ function IslandPlugins({ controller, slot }) {
601
884
  return true;
602
885
  }, COMMAND_PRIORITY_CRITICAL),
603
886
  editor.registerCommand(KEY_ARROW_UP_COMMAND, (event) => {
604
- if (!edge(false) || event?.shiftKey || slot.index === 0) return false;
887
+ if (event?.shiftKey) return extend("up");
888
+ if (!edge(false) || slot.index === 0) return false;
605
889
  event?.preventDefault();
606
890
  controller.focusBlock(slot.index - 1, true);
607
891
  return true;
608
892
  }, COMMAND_PRIORITY_CRITICAL),
609
893
  editor.registerCommand(KEY_ARROW_DOWN_COMMAND, (event) => {
610
- if (!edge(true) || event?.shiftKey) return false;
894
+ if (event?.shiftKey) return extend("down");
895
+ if (!edge(true)) return false;
611
896
  const index = slot.index + controller.island(slot).ids.length;
612
897
  if (index >= controller.rows.length) return false;
613
898
  event?.preventDefault();
614
899
  controller.focusBlock(index);
615
900
  return true;
616
- }, COMMAND_PRIORITY_CRITICAL)
901
+ }, COMMAND_PRIORITY_CRITICAL),
902
+ editor.registerCommand(KEY_ARROW_LEFT_COMMAND, (event) => !!event.shiftKey && extend("left"), COMMAND_PRIORITY_CRITICAL),
903
+ editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, (event) => !!event.shiftKey && extend("right"), COMMAND_PRIORITY_CRITICAL)
617
904
  ];
618
905
  return () => unregister.forEach((fn) => fn());
619
906
  }, [
@@ -639,6 +926,7 @@ function EditorSlot({ controller, slot: slot$1, plugins: surfacePlugins, onActiv
639
926
  blockId: row.id,
640
927
  active: slot$1.active,
641
928
  editor: island.editor,
929
+ documentBlocks: controller.documentBlocks,
642
930
  nodeState: (key) => controller.nodeState(slot$1, key, row.id),
643
931
  retain: () => {
644
932
  island.retained++;
@@ -741,17 +1029,19 @@ function Contents({ controller, plugins, onActiveEditorChange, onRelease, retain
741
1029
  }
742
1030
  function VirtualizedEditor({ options, className, plugins, autoFocus, hasHeader, onActiveEditorChange, retainSurface, placeholder }) {
743
1031
  const [editor] = useLexicalComposerContext();
744
- const { scrollContainer, overscan, estimateBlockHeight, preserveCapacity } = options;
1032
+ const { scrollContainer, overscan, estimateBlockHeight, preserveCapacity, selectionMergeLimit } = options;
745
1033
  const stableOptions = useMemo(() => ({
746
1034
  scrollContainer,
747
1035
  overscan,
748
1036
  estimateBlockHeight,
749
- preserveCapacity
1037
+ preserveCapacity,
1038
+ selectionMergeLimit
750
1039
  }), [
751
1040
  scrollContainer,
752
1041
  overscan,
753
1042
  estimateBlockHeight,
754
- preserveCapacity
1043
+ preserveCapacity,
1044
+ selectionMergeLimit
755
1045
  ]);
756
1046
  const active = useRef(null);
757
1047
  const selectEditor = useCallback((editor) => {
@@ -1,7 +1,19 @@
1
1
  import { LexicalEditor, NodeKey } from 'lexical';
2
+ export interface DocumentBlocks {
3
+ clear: () => void;
4
+ readonly editor: LexicalEditor;
5
+ extend: (step: -1 | 1) => boolean;
6
+ focusSelection: () => void;
7
+ islandKeys: (editor: LexicalEditor) => NodeKey[];
8
+ keys: () => NodeKey[];
9
+ select: (editor: LexicalEditor, anchorKey: NodeKey, focusKey: NodeKey) => void;
10
+ selectAll: () => void;
11
+ subscribe: (listener: () => void) => () => void;
12
+ }
2
13
  export interface EditorBlockBinding {
3
14
  active: boolean;
4
15
  blockId: string;
16
+ documentBlocks?: DocumentBlocks;
5
17
  editor: LexicalEditor;
6
18
  nodeState: (key?: NodeKey) => Map<string, unknown>;
7
19
  retain: () => () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"EditorBlockContext.d.ts","sourceRoot":"","sources":["../../src/context/EditorBlockContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGtD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,EAAE,MAAM,MAAM,IAAI,CAAC;CAC1B;AACD,eAAO,MAAM,kBAAkB,oDAAiD,CAAC;AACjF,qFAAqF;AACrF,wBAAgB,cAAc,8BAE7B"}
1
+ {"version":3,"file":"EditorBlockContext.d.ts","sourceRoot":"","sources":["../../src/context/EditorBlockContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGtD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC;IAClC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;IACjD,IAAI,EAAE,MAAM,OAAO,EAAE,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/E,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,EAAE,MAAM,MAAM,IAAI,CAAC;CAC1B;AACD,eAAO,MAAM,kBAAkB,oDAAiD,CAAC;AACjF,qFAAqF;AACrF,wBAAgB,cAAc,8BAE7B"}
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { RichEditorShell } from './components/RichEditorShell';
9
9
  export { getVariantClass } from './components/utils';
10
10
  export type { ColorScheme } from './context/ColorSchemeContext';
11
11
  export { ColorSchemeProvider, useColorScheme } from './context/ColorSchemeContext';
12
+ export type { DocumentBlocks } from './context/EditorBlockContext';
12
13
  export { useEditorBlock, useEditorBlock as useVirtualizedBlock, } from './context/EditorBlockContext';
13
14
  export type { EditorSurfaceProps } from './context/EditorSurfaceContext';
14
15
  export { ActiveEditorScope, EditorSurfacePlugin, EditorSurfacePlugins, useActiveEditor, } from './context/EditorSurf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ChB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EACL,qBAAqB,EACrB,uCAAuC,EACvC,qBAAqB,EACrB,+BAA+B,EAC/B,wBAAwB,EACxB,mBAAmB,EACnB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AACjF,YAAY,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as createTextSelectionStore, D as ImageUploadPlugin, E as LinkFaviconPlugin, G as CorePlugins, L as VideoUploadProvider, O as defaultImageUpload, P as FileUploadPlugin, S as TextSelectionStoreProvider, T as useTextSelectionStore, U as FileUploadProvider, V as ImagePreprocessProvider, _ as $getRootBlock, a as EditorRefPlugin, b as buildBlockAnchor, c as $captureTextSelection, d as createDOMRangeFromTextSelection, f as findDOMPointByTextOffset, g as TEXT_SELECTION_HIGHLIGHT_NAME, h as getTextOffsetFromDOMPoint, i as FootnotePlugin, l as $captureTextSelectionFromRangeSelection, m as getDOMRectFromTextSelection, n as SubmitShortcutPlugin, o as VideoUploadPlugin, p as getBlockElementById, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, u as $restoreTextSelection, v as $getTextOffsetInBlock, w as useTextSelectionSnapshot, x as buildRangeAnchor, y as $resolveSelectionPoint, z as ImageUploadProvider } from "./VirtualizationPlugin-Crc0cLUx.js";
1
+ import { C as createTextSelectionStore, D as ImageUploadPlugin, E as LinkFaviconPlugin, G as CorePlugins, L as VideoUploadProvider, O as defaultImageUpload, P as FileUploadPlugin, S as TextSelectionStoreProvider, T as useTextSelectionStore, U as FileUploadProvider, V as ImagePreprocessProvider, _ as $getRootBlock, a as EditorRefPlugin, b as buildBlockAnchor, c as $captureTextSelection, d as createDOMRangeFromTextSelection, f as findDOMPointByTextOffset, g as TEXT_SELECTION_HIGHLIGHT_NAME, h as getTextOffsetFromDOMPoint, i as FootnotePlugin, l as $captureTextSelectionFromRangeSelection, m as getDOMRectFromTextSelection, n as SubmitShortcutPlugin, o as VideoUploadPlugin, p as getBlockElementById, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, u as $restoreTextSelection, v as $getTextOffsetInBlock, w as useTextSelectionSnapshot, x as buildRangeAnchor, y as $resolveSelectionPoint, z as ImageUploadProvider } from "./VirtualizationPlugin-eHBms1eF.js";
2
2
  import { n as setResolvedEditNodes, r as allEditNodes } from "./node-registry-jRE4LqH-.js";
3
3
  import { J as NestedContentRendererProvider, X as useOptionalNestedContentRenderer, Y as useNestedContentRenderer, t as editorTheme } from "./theme-DH4xzxU-.js";
4
4
  import { C as MENTION_NODE_KEY, D as VIDEO_NODE_KEY, E as TAG_NODE_KEY, S as LINK_CARD_NODE_KEY, T as RUBY_NODE_KEY, _ as FILE_NODE_KEY, a as useFootnoteContent, b as IMAGE_NODE_KEY, d as useRendererConfig, f as useRendererMode, g as CODE_BLOCK_NODE_KEY, h as BANNER_NODE_KEY, i as FootnoteDefinitionsProvider, m as ALERT_NODE_KEY, o as useFootnoteDefinitions, p as useVariant, s as useFootnoteDisplayNumber, u as RendererConfigProvider, v as FOOTNOTE_NODE_KEY, w as MERMAID_NODE_KEY, x as KATEX_NODE_KEY, y as FOOTNOTE_SECTION_NODE_KEY } from "./thumbhash-GjK8OYAb.js";
@@ -9,7 +9,7 @@ import { n as useNestedEditorPlugins, t as NestedEditorPluginsProvider } from ".
9
9
  import { a as useNestedEditorSync, i as createNestedEditor, o as registerNestedEditorSync, r as NESTED_EDITOR_NODES, s as NestedEditorCorePlugins } from "./AlertQuoteEditNode-Ck4v29Wg.js";
10
10
  import { t as normalizeSerializedEditorState } from "./normalizeSerializedEditorState-VaI73T09.js";
11
11
  import { n as useExtraNodes, r as LinkFavicon, t as ExtraNodesProvider } from "./ExtraNodesContext-xQ2RNsqH.js";
12
- import { a as EditorSurfaceProvider, i as EditorSurfacePlugins, n as ActiveEditorScope, o as useActiveEditor, r as EditorSurfacePlugin, s as useEditorSurface, t as VirtualizationPlugin } from "./VirtualizationPlugin-C8TJ4HJN.js";
12
+ import { a as EditorSurfaceProvider, i as EditorSurfacePlugins, n as ActiveEditorScope, o as useActiveEditor, r as EditorSurfacePlugin, s as useEditorSurface, t as VirtualizationPlugin } from "./VirtualizationPlugin-BA7YFDRN.js";
13
13
  import { a as KaTeXPlugin, c as AlertPlugin, n as MermaidPlugin, s as ImagePlugin } from "./MermaidPlugin-BCoGsdi3.js";
14
14
  import { n as blockIdState, t as BlockIdPlugin } from "./BlockIdPlugin-Cwv8aV9g.js";
15
15
  import { n as useEditorBlock } from "./EditorBlockContext-DytAx9Tg.js";
@@ -1,7 +1,7 @@
1
- import { $ as BlockExitPlugin, A as ImageDialog, B as useImageUpload, D as ImageUploadPlugin, E as LinkFaviconPlugin, F as setFileUploadEntry, G as CorePlugins, H as useImagePreprocess, I as useFileUploadEntry, J as ALL_TRANSFORMERS, K as MarkdownShortcutsPlugin, L as VideoUploadProvider, M as registerImageEditor, N as resolvePreprocessTargets, O as defaultImageUpload, P as FileUploadPlugin, Q as registerClickBelowCommand, R as useVideoUpload, U as FileUploadProvider, V as ImagePreprocessProvider, W as useFileUpload, X as HorizontalRulePlugin, Y as InlineDndPlugin, Z as ClickBelowPlugin, a as EditorRefPlugin, et as AutoLinkPlugin, i as FootnotePlugin, j as getImageEditor, k as presentImageDialog, n as SubmitShortcutPlugin, o as VideoUploadPlugin, q as MarkdownPastePlugin, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, z as ImageUploadProvider } from "./VirtualizationPlugin-Crc0cLUx.js";
1
+ import { $ as BlockExitPlugin, A as ImageDialog, B as useImageUpload, D as ImageUploadPlugin, E as LinkFaviconPlugin, F as setFileUploadEntry, G as CorePlugins, H as useImagePreprocess, I as useFileUploadEntry, J as ALL_TRANSFORMERS, K as MarkdownShortcutsPlugin, L as VideoUploadProvider, M as registerImageEditor, N as resolvePreprocessTargets, O as defaultImageUpload, P as FileUploadPlugin, Q as registerClickBelowCommand, R as useVideoUpload, U as FileUploadProvider, V as ImagePreprocessProvider, W as useFileUpload, X as HorizontalRulePlugin, Y as InlineDndPlugin, Z as ClickBelowPlugin, a as EditorRefPlugin, et as AutoLinkPlugin, i as FootnotePlugin, j as getImageEditor, k as presentImageDialog, n as SubmitShortcutPlugin, o as VideoUploadPlugin, q as MarkdownPastePlugin, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, z as ImageUploadProvider } from "./VirtualizationPlugin-eHBms1eF.js";
2
2
  import { $ as markInlineDraggable, Z as INLINE_DRAG_ATTR } from "./theme-DH4xzxU-.js";
3
3
  import { c as PasteLinkPlugin } from "./AlertQuoteEditNode-Ck4v29Wg.js";
4
- import { i as EditorSurfacePlugins, n as ActiveEditorScope, o as useActiveEditor, r as EditorSurfacePlugin, t as VirtualizationPlugin } from "./VirtualizationPlugin-C8TJ4HJN.js";
4
+ import { i as EditorSurfacePlugins, n as ActiveEditorScope, o as useActiveEditor, r as EditorSurfacePlugin, t as VirtualizationPlugin } from "./VirtualizationPlugin-BA7YFDRN.js";
5
5
  import { a as KaTeXPlugin, c as AlertPlugin, n as MermaidPlugin, s as ImagePlugin } from "./MermaidPlugin-BCoGsdi3.js";
6
6
  import { n as blockIdState, t as BlockIdPlugin } from "./BlockIdPlugin-Cwv8aV9g.js";
7
7
  export { ALL_TRANSFORMERS, ActiveEditorScope, AlertPlugin, AutoFocusPlugin, AutoLinkPlugin, BlockExitPlugin, BlockIdPlugin, ClickBelowPlugin, CorePlugins, EditorRefPlugin, EditorSurfacePlugin, EditorSurfacePlugins, FileUploadPlugin, FileUploadProvider, FootnotePlugin, HorizontalRulePlugin, INLINE_DRAG_ATTR, ImageDialog, ImagePlugin, ImagePreprocessProvider, ImageUploadPlugin, ImageUploadProvider, InlineDndPlugin, KaTeXPlugin, LinkFaviconPlugin, MarkdownPastePlugin, MarkdownShortcutsPlugin, MermaidPlugin, OnChangePlugin, PasteLinkPlugin, SubmitShortcutPlugin, TextSelectionPlugin, VideoUploadPlugin, VideoUploadProvider, VirtualizationPlugin, blockIdState, defaultImageUpload, getImageEditor, markInlineDraggable, presentImageDialog, registerClickBelowCommand, registerImageEditor, resolvePreprocessTargets, setFileUploadEntry, useActiveEditor, useFileUpload, useFileUploadEntry, useImagePreprocess, useImageUpload, useVideoUpload };
@@ -1,3 +1,3 @@
1
1
  import { t as EditorBlockContext } from "./EditorBlockContext-DytAx9Tg.js";
2
- import { a as PreserveNodeManager, c as collapsedMargin, i as slot, l as estimateHeight, n as canvas, o as HeightIndex, r as editable, s as TypePool, t as resolveScrollContainer, u as occupiedHeight } from "./viewport-BvO92tse.js";
2
+ import { a as PreserveNodeManager, c as collapsedMargin, i as slot, l as estimateHeight, n as canvas, o as HeightIndex, r as editable, s as TypePool, t as resolveScrollContainer, u as occupiedHeight } from "./viewport-CFJHn_Y6.js";
3
3
  export { EditorBlockContext, HeightIndex, PreserveNodeManager, TypePool, collapsedMargin, estimateHeight, occupiedHeight, canvas as recyclerCanvas, editable as recyclerContent, slot as recyclerSlot, resolveScrollContainer };
@@ -9,6 +9,7 @@ export { getVariantClass } from './components/utils';
9
9
  export { allNodes, builtinNodes, customNodes } from './config';
10
10
  export type { ColorScheme } from './context/ColorSchemeContext';
11
11
  export { ColorSchemeProvider, useColorScheme } from './context/ColorSchemeContext';
12
+ export type { DocumentBlocks } from './context/EditorBlockContext';
12
13
  export { useEditorBlock, useEditorBlock as useVirtualizedBlock, } from './context/EditorBlockContext';
13
14
  export { ExtraNodesProvider, useExtraNodes } from './context/ExtraNodesContext';
14
15
  export type { FootnoteDefinitionsContextValue } from './context/FootnoteDefinitionsContext';
@@ -1 +1 @@
1
- {"version":3,"file":"static-entry.d.ts","sourceRoot":"","sources":["../src/static-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAChF,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EACL,cAAc,EACd,cAAc,IAAI,mBAAmB,GACtC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAChF,YAAY,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAC5F,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,m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
  mount(slot, host, parent, before = null) {
173
173
  this.hosts.set(slot, host);
174
174
  if (parent) {
175
- if (host.parentNode !== parent || host.nextSibling !== before) parent.insertBefore(host, before);
175
+ if (host.parentNode !== parent || before && !(host.compareDocumentPosition(before) & Node.DOCUMENT_POSITION_FOLLOWING)) parent.insertBefore(host, before);
176
176
  } else {
177
177
  this.parking ?? (this.parking = host.ownerDocument.createDocumentFragment());
178
178
  if (host.parentNode !== this.parking) this.parking.append(host);
@@ -1,5 +1,5 @@
1
1
  import { EditorVirtualizationOptions } from './types';
2
- export declare function VirtualizationPlugin({ scrollContainer, overscan, estimateBlockHeight, preserveCapacity, priority, }: EditorVirtualizationOptions & {
2
+ export declare function VirtualizationPlugin({ scrollContainer, overscan, estimateBlockHeight, preserveCapacity, selectionMergeLimit, priority, }: EditorVirtualizationOptions & {
3
3
  priority?: number;
4
4
  }): import('react').JSX.Element;
5
5
  //# sourceMappingURL=VirtualizationPlugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualizationPlugin.d.ts","sourceRoot":"","sources":["../../src/virtualization/VirtualizationPlugin.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAM3D,wBAAgB,oBAAoB,CAAC,EACnC,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,QAAY,GACb,EAAE,2BAA2B,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,+BAYrD"}
1
+ {"version":3,"file":"VirtualizationPlugin.d.ts","sourceRoot":"","sources":["../../src/virtualization/VirtualizationPlugin.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAM3D,wBAAgB,oBAAoB,CAAC,EACnC,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,QAAY,GACb,EAAE,2BAA2B,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,+BAkBrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualizedEditor.d.ts","sourceRoot":"","sources":["../../src/virtualization/VirtualizedEditor.tsx"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAK1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AA+O3D,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,SAAS,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,GACZ,EAAE,kBAAkB,GAAG;IAAE,OAAO,EAAE,2BAA2B,CAAA;CAAE,+BAoE/D"}
1
+ {"version":3,"file":"VirtualizedEditor.d.ts","sourceRoot":"","sources":["../../src/virtualization/VirtualizedEditor.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAK1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAgQ3D,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,SAAS,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,GACZ,EAAE,kBAAkB,GAAG;IAAE,OAAO,EAAE,2BAA2B,CAAA;CAAE,+BA2E/D"}
@@ -0,0 +1,29 @@
1
+ import { LexicalEditor, NodeKey } from 'lexical';
2
+ import { DocumentBlocks } from '../context/EditorBlockContext';
3
+ import { DocumentRow } from './document';
4
+ export interface DocumentBlocksHost {
5
+ focusBlock: (index: number, end?: boolean) => void;
6
+ indexOf: (id: string) => number | undefined;
7
+ islandIds: (editor: LexicalEditor) => string[] | undefined;
8
+ readonly master: LexicalEditor;
9
+ readonly rows: DocumentRow[];
10
+ }
11
+ export declare class DocumentBlockSelection implements DocumentBlocks {
12
+ private readonly host;
13
+ private range?;
14
+ private listeners;
15
+ constructor(host: DocumentBlocksHost);
16
+ get editor(): LexicalEditor;
17
+ keys(): string[];
18
+ islandKeys(editor: LexicalEditor): string[];
19
+ select(editor: LexicalEditor, anchorKey: NodeKey, focusKey: NodeKey): void;
20
+ selectAll(): void;
21
+ extend(step: -1 | 1): boolean;
22
+ clear(): void;
23
+ prune(): void;
24
+ focusSelection(): void;
25
+ subscribe(listener: () => void): () => void;
26
+ private bounds;
27
+ private set;
28
+ }
29
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/virtualization/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,OAAO,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC5C,SAAS,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC;CAC9B;AAED,qBAAa,sBAAuB,YAAW,cAAc;IAI/C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,KAAK,CAAC,CAAwC;IACtD,OAAO,CAAC,SAAS,CAAyB;gBAEb,IAAI,EAAE,kBAAkB;IAErD,IAAI,MAAM,kBAET;IAED,IAAI;IAKJ,UAAU,CAAC,MAAM,EAAE,aAAa;IAehC,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;IAYnE,SAAS;IAKT,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;IAQnB,KAAK;IAIL,KAAK;IASL,cAAc;IAgBd,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;IAO9B,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,GAAG;CAIZ"}
@@ -1,4 +1,5 @@
1
1
  import { LexicalEditor, NodeKey } from 'lexical';
2
+ import { DocumentBlockSelection } from './blocks';
2
3
  import { VirtualDocument } from './document';
3
4
  import { HeightIndex, Slot, TypePool } from './layout';
4
5
  import { PreserveNodeManager } from './preserve';
@@ -23,6 +24,7 @@ export declare class EditorRecycler {
23
24
  readonly states: Map<string, Map<string, unknown>>;
24
25
  readonly viewport: HTMLElement | Window;
25
26
  readonly preserve: PreserveNodeManager;
27
+ readonly documentBlocks: DocumentBlockSelection;
26
28
  heights: HeightIndex;
27
29
  revision: number;
28
30
  private indices;
@@ -33,6 +35,9 @@ export declare class EditorRecycler {
33
35
  private width;
34
36
  private metrics;
35
37
  private firstParagraph;
38
+ private selectionOwner?;
39
+ private splitting;
40
+ private drag?;
36
41
  constructor(master: LexicalEditor, canvas: HTMLElement, options: EditorVirtualizationOptions);
37
42
  private previousRows;
38
43
  get rows(): import('./document').DocumentRow[];
@@ -47,6 +52,16 @@ export declare class EditorRecycler {
47
52
  subscribe(listener: () => void): () => void;
48
53
  private publish;
49
54
  private onScroll;
55
+ indexOf(id: string): number | undefined;
56
+ islandIds(editor: LexicalEditor): string[] | undefined;
57
+ private onPointerDown;
58
+ private onPointerMove;
59
+ private endDrag;
60
+ private rowAt;
61
+ private dragTo;
62
+ private extendToPoint;
63
+ private onFocusIn;
64
+ private holdsSelection;
50
65
  refresh(sync?: boolean): void;
51
66
  island(slot: Slot): Island;
52
67
  bind(slot: Slot): void;
@@ -67,6 +82,10 @@ export declare class EditorRecycler {
67
82
  private measure;
68
83
  scrollTo(index: number): void;
69
84
  focusBlock(index: number, end?: boolean, scroll?: boolean): void;
85
+ extendIsland(slot: Slot, toIndex: number, sync?: boolean): boolean;
86
+ extendForKey(slot: Slot, key: 'up' | 'down' | 'left' | 'right'): boolean;
87
+ splitIsland(slot: Slot): void;
88
+ private queueSplit;
70
89
  joinNeighbor(slot: Slot, backward: boolean): boolean;
71
90
  dispose(): void;
72
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/virtualization/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,aAAa,EAElB,KAAK,OAAO,EAGb,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAwB,eAAe,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAGL,WAAW,EAEX,KAAK,IAAI,EACT,QAAQ,EACT,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAG3D,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,qBAAa,cAAc;IAmBvB,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,MAAM,EAAE,WAAW;IAC5B,QAAQ,CAAC,OAAO,EAAE,2BAA2B;IApB/C,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,IAAI,WAAkB;IAC/B,QAAQ,CAAC,OAAO,sBAA6B;IAC7C,QAAQ,CAAC,MAAM,oCAA2C;IAC1D,QAAQ,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,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;IAqB9D,WAAW,CAAC,IAAI,EAAE,IAAI;IAyBtB,OAAO,CAAC,UAAU;IAiBlB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO;IAwB1C,OAAO;CAcR"}
@@ -1 +1 @@
1
- {"version":3,"file":"preserve.d.ts","sourceRoot":"","sources":["../../src/virtualization/preserve.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qBAAa,mBAAmB;IAQ5B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IARxB,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAmB;IACnC,IAAI,SAAK;IACT,SAAS,SAAK;gBAGH,QAAQ,EAAE,MAAM,EACR,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI;IAK/D,IAAI,IAAI,WAEP;IACD,GAAG,CAAC,IAAI,EAAE,MAAM;IAGhB,GAAG;IAGH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAUhC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAKrB,IAAI,CAAC,IAAI,EAAE,MAAM;IAGjB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,EAAE,MAAM,GAAE,IAAI,GAAG,IAAW;IAU7F,MAAM,CAAC,IAAI,EAAE,MAAM;IAKnB,KAAK;CAKN"}
1
+ {"version":3,"file":"preserve.d.ts","sourceRoot":"","sources":["../../src/virtualization/preserve.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qBAAa,mBAAmB;IAQ5B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IARxB,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAmB;IACnC,IAAI,SAAK;IACT,SAAS,SAAK;gBAGH,QAAQ,EAAE,MAAM,EACR,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI;IAK/D,IAAI,IAAI,WAEP;IACD,GAAG,CAAC,IAAI,EAAE,MAAM;IAGhB,GAAG;IAGH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAUhC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAKrB,IAAI,CAAC,IAAI,EAAE,MAAM;IAGjB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,EAAE,MAAM,GAAE,IAAI,GAAG,IAAW;IAc7F,MAAM,CAAC,IAAI,EAAE,MAAM;IAKnB,KAAK;CAKN"}
@@ -8,6 +8,8 @@ export interface EditorVirtualizationOptions {
8
8
  preserveCapacity?: number;
9
9
  /** The scrolling viewport, not its content. Defaults to the nearest scrollable ancestor. */
10
10
  scrollContainer?: HTMLElement | RefObject<HTMLElement | null> | (() => HTMLElement | null);
11
+ /** Maximum rows one editing instance may hold while a selection grows across blocks. Defaults to 200. */
12
+ selectionMergeLimit?: number;
11
13
  }
12
14
  export type EditorVirtualization = boolean | EditorVirtualizationOptions;
13
15
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/virtualization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,2BAA2B;IAC1C,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxE,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC;CAC5F;AACD,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,2BAA2B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/virtualization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,2BAA2B;IAC1C,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxE,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC;IAC3F,yGAAyG;IACzG,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AACD,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,2BAA2B,CAAC"}
@@ -1 +1 @@
1
- export { t as VirtualizationPlugin } from "./VirtualizationPlugin-C8TJ4HJN.js";
1
+ export { t as VirtualizationPlugin } from "./VirtualizationPlugin-BA7YFDRN.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-editor",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "Core rich text editor based on Lexical",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,9 +57,9 @@
57
57
  "dist"
58
58
  ],
59
59
  "dependencies": {
60
- "@haklex/rich-editor-ui": "0.59.0",
61
- "@haklex/rich-headless": "0.59.0",
62
- "@haklex/rich-style-token": "0.59.0",
60
+ "@haklex/rich-editor-ui": "0.60.0",
61
+ "@haklex/rich-headless": "0.60.0",
62
+ "@haklex/rich-style-token": "0.60.0",
63
63
  "@lexical/code-core": "^0.52.0",
64
64
  "nanoid": "^6.0.2",
65
65
  "thumbhash": "^0.1.1"