plitejs 54.0.0-beta.6 → 54.0.0-beta.8

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 (61) hide show
  1. package/README.md +4 -4
  2. package/dist/authored/index.d.ts +67 -47
  3. package/dist/authored/index.js +7640 -4563
  4. package/dist/{authored-veto-BsBDXC0b.js → authored-veto-DLmBMIcy.js} +1 -1
  5. package/dist/clipboard-format-key-SzffxWqa.js +14 -0
  6. package/dist/{comparison-plan-IOewH50q.js → comparison-plan-BqFJWjO4.js} +142 -14
  7. package/dist/{create-editor-DRRzGwaC.js → create-editor-kU8fg-PF.js} +30 -78
  8. package/dist/diff/index.d.ts +2 -32
  9. package/dist/diff/index.js +92 -372
  10. package/dist/dom/index.d.ts +3 -2
  11. package/dist/dom/index.js +3 -2
  12. package/dist/{dom-CVYV5Qd5.js → dom-SUWlnfT9.js} +1052 -261
  13. package/dist/history/index.d.ts +5 -5
  14. package/dist/history/index.js +3237 -2096
  15. package/dist/history-skip-CcEhIzak.js +35 -0
  16. package/dist/hyperscript/index.d.ts +1 -1
  17. package/dist/hyperscript/index.js +1 -1
  18. package/dist/{hyperscript-CT6hhnAY.js → hyperscript-DdeGYoSc.js} +3 -2
  19. package/dist/{index-PDROnF1G.d.ts → index-4PpawhYe.d.ts} +1 -1
  20. package/dist/{index-VZrKWWeh.d.ts → index-BsOySJwr.d.ts} +86 -203
  21. package/dist/{index-D7-n2GCk.d.ts → index-CHEKdrHP.d.ts} +32 -24
  22. package/dist/{comparison-types-DBQFu7Rt.d.ts → index-DM-b6jEe.d.ts} +21 -57
  23. package/dist/{index-BT7D4vtf.d.ts → index-DqmhcD_0.d.ts} +1 -5
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +5 -4
  26. package/dist/internal/index.d.ts +2 -2
  27. package/dist/internal/index.js +66 -5
  28. package/dist/law-check-Bvnz2EKh.js +19271 -0
  29. package/dist/pagination/index.d.ts +1 -1
  30. package/dist/pagination/index.js +1 -1
  31. package/dist/pagination/react.d.ts +14 -11
  32. package/dist/pagination/react.js +237 -144
  33. package/dist/{pagination-Cs5ka6hW.js → pagination-XEnxZ1DX.js} +2 -1
  34. package/dist/{plugin-Bm6nsPHh.js → plugin-B8uCi-Hr.js} +17196 -22475
  35. package/dist/{range-geometry-DO-kbNrb.d.ts → range-geometry-B2f67yLv.d.ts} +1 -1
  36. package/dist/{range-geometry-D1XfYWs0.js → range-geometry-BGKYQHqO.js} +3 -2
  37. package/dist/react/index.d.ts +4 -5
  38. package/dist/react/index.js +8 -7
  39. package/dist/react/virtualized.d.ts +5 -5
  40. package/dist/react/virtualized.js +69 -43
  41. package/dist/{react-BYtwRr4v.js → react-B6B-5z7t.js} +141 -171
  42. package/dist/{retraction-DnEUo8oE.js → retraction-BMzQ2on5.js} +2 -18
  43. package/dist/scroll-root-DudA40xj.js +25 -0
  44. package/dist/{src-DIQDddmh.js → src--BZ7fZY4.js} +183 -64
  45. package/dist/testing/index.d.ts +2 -2
  46. package/dist/testing/index.js +4 -3
  47. package/dist/{index-DHt8nZQ6.d.ts → tx-only-D8lpB-sT.d.ts} +9246 -8660
  48. package/dist/{editor-owner-CGj1wYCa.js → update-policy-J-4sHmrg.js} +54 -2
  49. package/dist/{use-editor-dom-scope-hT7W9d-p.js → use-editor-dom-scope-BFWvutxn.js} +18267 -15917
  50. package/dist/yjs/index.d.ts +1 -1
  51. package/dist/yjs/index.js +1 -1
  52. package/dist/yjs/react/index.d.ts +3 -3
  53. package/dist/yjs/react/index.js +3 -3
  54. package/dist/{yjs-C_g9gZwI.js → yjs-DPngKQWQ.js} +420 -164
  55. package/package.json +2 -9
  56. package/dist/annotation-store-metrics-Ccjkef45.js +0 -12
  57. package/dist/annotations/index.d.ts +0 -2
  58. package/dist/annotations/index.js +0 -2
  59. package/dist/index-BvQzYVAW.d.ts +0 -71
  60. package/dist/mapped-view-store-CBk2-bDR.js +0 -120
  61. package/dist/store-BLYxJgOU.js +0 -747
@@ -1,6 +1,7 @@
1
- import { Au as ElementApi, B as NodeApi, Bt as point, Bu as getEditorRuntimeOwner, Ef as getNodeKeyForNode, En as attachTransactionSpecAfterCommit, Et as isInline, Eu as definePluginPoint, F as getActiveCommandEditor, Fd as mapInternalDocumentChangePosition, Gu as defineCommand, Hu as getEditorSchema, Il as getPluginContributions, Is as mapSelectionThroughChange, Jr as resolveEditorNodeKeyForNode, Ka as getCaretOwner, Ld as valueRoot, Ll as getPluginRegistry, Lt as next, M as dispatchCommand, Ma as isTextCell, N as evaluateCommand, Ns as getSelectionDOMRange, Oc as getEditorCommitSnapshot, Oi as withUpdateTagContext, Ol as reportEditorLifecycleError, P as evaluateCommandWithState, Pd as mapInternalDocumentChangePoint, Pl as getCompiledEditorSchema, Pn as getActiveEditorTransaction, Pu as TextApi, Qn as getEditorReadDepth, Ra as nodes, Rn as getBaseCallRoot, Rp as getDefined, Sp as PathApi, Tu as failInvariant, U as after, Uu as hasEditorRuntime, V as above, Vu as getEditorRuntimeRoot, W as before, Wt as range, Ya as holdsCaret, Yl as getCompiledSchemaPropertyId, Zo as txLocate, _a as readRemovalLanding, _c as createDetachedContentSlice, _n as afterActiveTransactionEnds, _p as PointApi, _s as getCompiledEditorSchemaFromApi, at as getNodeKey, bt as isBlock, co as setSelectionAsView, ct as getSelection$1, dn as voidEditor, ft as hasPath, gc as ContentSlice, hl as toPublicRoot, hp as LocationApi, hu as EditorSchemaValidationError, ii as setEditorFocused, io as resolveParkedCaret, jc as getEditorCommitValue, jd as hasInternalDocumentChangeRoot, ji as captureSliceLanding, jp as countCoreWork, ju as formatDebugValue, kt as isVoid$2, ku as SelectionApi, l as definePlugin, lr as getNodeTargetRoot, lt as getSnapshot, m as getInstalledPlugin, ma as withLandingBlock, mi as subscribeCaretTarget, ml as toInternalRoot, mp as RangeApi, ot as getPathByNodeKey, pl as getPublicExplicitLocationRoot, pn as editorCommands, pr as getSetSite, qa as getPlacementGeneration, rf as DocumentIndex, sn as unhangRange, to as placedSince, tr as getEditorStateView, tt as getChildren, vi as toEditorCoreStateView, vs as getInternalEditorSchemaFromApi, wo as getViewFollowTarget, xn as applyTransactionSpec, xo as getOwnViewPresentation, zu as getEditorRuntime } from "./plugin-Bm6nsPHh.js";
2
- import { a as transferEntries, c as dispatchPaste, n as checkFilesLanding, r as checkTransfer, u as landPaste } from "./src-DIQDddmh.js";
3
- import scrollIntoViewIfNeeded from "scroll-into-view-if-needed";
1
+ import { Ai as countCoreWork, Bn as getNodeKeyForNode, G as mapInternalDocumentChangePosition, N as hasInternalDocumentChangeRoot, W as mapInternalDocumentChangePoint, Wi as getDefined, Y as valueRoot, hi as PathApi, ii as PointApi, ni as LocationApi, ti as RangeApi, tn as DocumentIndex } from "./law-check-Bvnz2EKh.js";
2
+ import { At as isVoid$2, Au as getPluginRegistry, Bd as hasEditorRuntime, Bo as placedSince, Cd as definePluginPoint, Co as nodes, Dd as ElementApi, Dn as attachTransactionSpecAfterCommit, Dt as isInline, Du as getCompiledEditorSchema, Ed as SelectionApi, Ei as subscribeCaretTarget, F as evaluateCommandWithState, G as before, Gi as captureSliceLanding, Gt as range, H as above, Hd as defineCommand, Hi as withUpdateTagContext, I as getActiveCommandEditor, Id as getEditorRuntime, Ld as getEditorRuntimeOwner, Ls as txLocate, Mo as getPlacementGeneration, N as dispatchCommand, Od as formatDebugValue, P as evaluateCommand, Po as holdsCaret, Rd as getEditorRuntimeRoot, Rt as next, Sn as applyTransactionSpec, Ud as registerImplicitTargetCommand, Un as getBaseCallRoot, Uo as resolveParkedCaret, Uu as getCompiledSchemaPropertyId, V as NodeApi, Vt as point, W as after, Xa as readRemovalLanding, Xc as createDetachedContentSlice, Yc as ContentSlice, ac as getCompiledEditorSchemaFromApi, ar as getEditorReadDepth, bc as getSelectionDOMRange, bd as failInvariant, br as getSetSite, cn as unhangRange, cr as getEditorStateView, du as toPublicRoot, fn as voidEditor, fo as isTextCell, gr as getNodeTargetRoot, hi as setEditorFocused, ii as resolveEditorNodeKeyForNode, jd as TextApi, ji as toEditorCoreStateView, jo as getCaretOwner, ku as getPluginContributions, l as definePlugin, ls as getViewFollowTarget, lt as getSelection$1, lu as getPublicExplicitLocationRoot, m as getInstalledPlugin, mn as editorCommands, nt as getChildren, oc as getInternalEditorSchemaFromApi, os as getOwnViewPresentation, ot as getNodeKey, pt as hasPath, qa as withLandingBlock, qo as setSelectionAsView, st as getPathByNodeKey, ud as EditorSchemaValidationError, ut as getSnapshot, uu as toInternalRoot, vl as getEditorCommitSnapshot, vn as afterActiveTransactionEnds, wc as mapSelectionThroughChange, wl as readRootEntries, xl as getEditorCommitValue, xt as isBlock, xu as reportEditorLifecycleError, zd as getEditorSchema, zn as getActiveEditorTransaction } from "./plugin-B8uCi-Hr.js";
3
+ import { a as transferEntries, c as dispatchPaste, n as checkFilesLanding, r as checkTransfer, u as landPaste } from "./src--BZ7fZY4.js";
4
+ import { i as setDOMClipboardFormatKey, n as clearDOMClipboardFormatKey, r as getDOMClipboardFormatKey, t as DEFAULT_CLIPBOARD_FORMAT_KEY$2 } from "./clipboard-format-key-SzffxWqa.js";
4
5
  //#region src/dom/utils/dom.ts
5
6
  globalThis.Node;
6
7
  globalThis.Text;
@@ -160,18 +161,18 @@ const getPlainText = (domNode, skip) => {
160
161
  endLine();
161
162
  return lines.join("\n");
162
163
  };
163
- const DEFAULT_CLIPBOARD_FORMAT_KEY$2 = "x-editor-fragment";
164
+ const DEFAULT_CLIPBOARD_FORMAT_KEY$1 = "x-editor-fragment";
164
165
  const catchOpeningHtmlTag = /<[A-Za-z][^<>]*?>/g;
165
166
  const catchEditorFragment = /\bdata-editor-fragment\s*=\s*(["'])(.*?)\1/i;
166
167
  const catchEditorFragmentFormat = /\bdata-editor-fragment-format\s*=\s*(["'])(.*?)\1/i;
167
168
  /** Read an HTML clipboard envelope for the editor's configured format. */
168
- const getFragmentAttribute = (dataTransfer, clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$2) => {
169
+ const getFragmentAttribute = (dataTransfer, clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$1) => {
169
170
  const openingTags = dataTransfer.getData("text/html").match(catchOpeningHtmlTag) ?? [];
170
171
  for (const tag of openingTags) {
171
172
  const fragment = tag.match(catchEditorFragment)?.[2];
172
173
  if (fragment === void 0) continue;
173
174
  const fragmentFormat = tag.match(catchEditorFragmentFormat)?.[2];
174
- if (fragmentFormat === clipboardFormatKey || fragmentFormat === void 0 && clipboardFormatKey === DEFAULT_CLIPBOARD_FORMAT_KEY$2) return fragment;
175
+ if (fragmentFormat === clipboardFormatKey || fragmentFormat === void 0 && clipboardFormatKey === DEFAULT_CLIPBOARD_FORMAT_KEY$1) return fragment;
175
176
  }
176
177
  };
177
178
  const plainTextPastes = /* @__PURE__ */ new WeakSet();
@@ -1101,6 +1102,45 @@ const readDOMTextFlowHost = (host) => {
1101
1102
  text: segments ? readDOMTextFlowRecord(record, segments) : null
1102
1103
  }));
1103
1104
  };
1105
+ const pathsEqual = (left, right) => left !== null && left.length === right.length && left.every((value, index) => value === right[index]);
1106
+ const getDOMTextFlowRestoreSegments = (host, path) => {
1107
+ const index = TEXT_HOST_TO_FLOW_INDEX.get(host);
1108
+ if (!index) return null;
1109
+ let matched = null;
1110
+ if (path) {
1111
+ for (const { record } of index.records.values()) if (pathsEqual(record.path, path)) {
1112
+ matched = record;
1113
+ break;
1114
+ }
1115
+ }
1116
+ if (!matched && index.records.size === 1) matched = index.records.values().next().value?.record ?? null;
1117
+ if (!matched || matched.segments.length === 0) return null;
1118
+ const record = matched;
1119
+ return record.segments.map((segment) => {
1120
+ const bounds = getBindingSegmentBounds({
1121
+ record,
1122
+ segment
1123
+ });
1124
+ return {
1125
+ domLength: segment.domLength,
1126
+ end: bounds.end,
1127
+ replaceTextNode: (nextTextNode) => {
1128
+ if (segment.textNode === nextTextNode) return;
1129
+ segment.textNode[DOM_TEXT_FLOW_SEGMENT] = null;
1130
+ segment.textNode = nextTextNode;
1131
+ nextTextNode[DOM_TEXT_FLOW_SEGMENT] = segment;
1132
+ segment.boundNodes = [
1133
+ segment.rootNode,
1134
+ segment.stringElement,
1135
+ nextTextNode
1136
+ ].filter((node) => !!node);
1137
+ },
1138
+ start: bounds.start,
1139
+ stringElement: segment.stringElement,
1140
+ textNode: segment.textNode
1141
+ };
1142
+ });
1143
+ };
1104
1144
  const resolveDOMTextFlowOffset = (host, node, offset) => {
1105
1145
  if (node.nodeType !== Node.TEXT_NODE) return null;
1106
1146
  const directBinding = getSegmentBinding(node);
@@ -1493,9 +1533,12 @@ const getPliteStringDirectPlacement = ({ root, target, x, y }) => {
1493
1533
  };
1494
1534
  const isOverLetterBefore = (document, [textNode, offset], x, y) => {
1495
1535
  if (offset === 0) return false;
1536
+ const boundaries = getGraphemeBoundaryOffsets(textNode.textContent ?? "");
1537
+ const start = boundaries.findLast((boundary) => boundary < offset) ?? 0;
1538
+ const end = boundaries.find((boundary) => boundary >= offset) ?? offset;
1496
1539
  const letter = document.createRange();
1497
- letter.setStart(textNode, offset - 1);
1498
- letter.setEnd(textNode, offset);
1540
+ letter.setStart(textNode, start);
1541
+ letter.setEnd(textNode, end);
1499
1542
  return getUsableRangeRects(letter).some((candidate) => x >= candidate.left && x < candidate.right && y >= candidate.top && y <= candidate.bottom);
1500
1543
  };
1501
1544
  const getNearestPliteStringRect = ({ strings, x, y }) => {
@@ -2401,6 +2444,88 @@ const hasDOMHostQuirk = (source, quirk) => resolveDOMSourceFacts(source)?.quirks
2401
2444
  /** True when the current environment exposes the browser DOM APIs Plite needs. */
2402
2445
  const CAN_USE_DOM = !!(typeof window !== "undefined" && window.document !== void 0 && "createElement" in window.document);
2403
2446
  //#endregion
2447
+ //#region src/dom/utils/selection-writes.ts
2448
+ const RECORDS = /* @__PURE__ */ new WeakMap();
2449
+ const UNPLACED_WRITES = /* @__PURE__ */ new WeakMap();
2450
+ const hasLayoutBox = ([node]) => {
2451
+ const element = node.nodeType === 1 ? node : node.parentElement;
2452
+ return !!element && element.getClientRects().length > 0;
2453
+ };
2454
+ const readDOMSelectionPoints = (selection) => {
2455
+ const { anchorNode, focusNode } = selection;
2456
+ return selection.rangeCount > 0 && anchorNode && focusNode ? {
2457
+ anchor: [anchorNode, selection.anchorOffset],
2458
+ focus: [focusNode, selection.focusOffset]
2459
+ } : null;
2460
+ };
2461
+ const sameDOMPoint = ([node, offset], [otherNode, otherOffset]) => node === otherNode && offset === otherOffset;
2462
+ const sameDOMSelectionPoints = (points, other) => points === null || other === null ? points === other : sameDOMPoint(points.anchor, other.anchor) && sameDOMPoint(points.focus, other.focus);
2463
+ const readDOMSelectionRecord = (tree) => RECORDS.get(tree) ?? null;
2464
+ const isDOMSelectionWriteEcho = (tree, points) => {
2465
+ const record = RECORDS.get(tree);
2466
+ return record?.source === "write" && sameDOMSelectionPoints(points, record.points);
2467
+ };
2468
+ const recordDOMSelection = (tree, points, source) => {
2469
+ RECORDS.set(tree, {
2470
+ points,
2471
+ source
2472
+ });
2473
+ UNPLACED_WRITES.delete(tree);
2474
+ };
2475
+ const forgetDOMSelectionRecord = (tree) => {
2476
+ RECORDS.delete(tree);
2477
+ UNPLACED_WRITES.delete(tree);
2478
+ };
2479
+ const touches = (container, points) => !!points && (container.contains(points.anchor[0]) || container.contains(points.focus[0]));
2480
+ const forgetDOMSelectionRecordWithin = (tree, container) => {
2481
+ if (touches(container, RECORDS.get(tree)?.points)) RECORDS.delete(tree);
2482
+ if (touches(container, UNPLACED_WRITES.get(tree))) UNPLACED_WRITES.delete(tree);
2483
+ };
2484
+ const getDOMRangeSelectionPoints = (range, backward = false) => {
2485
+ const start = [range.startContainer, range.startOffset];
2486
+ const end = [range.endContainer, range.endOffset];
2487
+ return backward ? {
2488
+ anchor: end,
2489
+ focus: start
2490
+ } : {
2491
+ anchor: start,
2492
+ focus: end
2493
+ };
2494
+ };
2495
+ const readsSelectionAsHost = (tree) => tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && isWebKitDOMHost(tree);
2496
+ /**
2497
+ * Write `points` as `tree`'s selection, keeping their direction, or clear its
2498
+ * ranges for null, and record what the tree then shows, or the points written
2499
+ * where the tree reads its selection as its host. A selection that already
2500
+ * shows them is left alone, and so is the record, unless WebKit got them from
2501
+ * a write while their anchor had no layout box, neither the user nor a write
2502
+ * of other points has come since, and the anchor has one now.
2503
+ */
2504
+ const writeDOMSelection = (tree, points) => {
2505
+ changeDOMSelection(tree, points);
2506
+ };
2507
+ const changeDOMSelection = (tree, points, beforeChange, canCommit) => {
2508
+ const selection = getSelection(tree);
2509
+ if (!selection) return false;
2510
+ const rewritesUnplaced = points !== null && sameDOMSelectionPoints(UNPLACED_WRITES.get(tree) ?? null, points);
2511
+ if (!rewritesUnplaced) UNPLACED_WRITES.delete(tree);
2512
+ if (!(points === null && tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && !!canCommit) && sameDOMSelectionPoints(readDOMSelectionPoints(selection), points) && !(rewritesUnplaced && hasLayoutBox(points.anchor))) return true;
2513
+ beforeChange?.();
2514
+ if (canCommit && !canCommit()) return false;
2515
+ if (points) selection.setBaseAndExtent(points.anchor[0], points.anchor[1], points.focus[0], points.focus[1]);
2516
+ else selection.removeAllRanges();
2517
+ if (points && hasDOMHostQuirk(tree, "unrendered-caret-needs-rewrite") && !hasLayoutBox(points.anchor)) UNPLACED_WRITES.set(tree, points);
2518
+ else UNPLACED_WRITES.delete(tree);
2519
+ const writtenPoints = readDOMSelectionPoints(selection);
2520
+ RECORDS.set(tree, {
2521
+ points: readsSelectionAsHost(tree) || tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && points !== null && !writtenPoints ? points : writtenPoints,
2522
+ source: "write"
2523
+ });
2524
+ return true;
2525
+ };
2526
+ /** A copy of `selection`'s range at `index`, safe to keep or change. */
2527
+ const readDOMSelectionRange = (selection, index = 0) => selection.getRangeAt(index).cloneRange();
2528
+ //#endregion
2404
2529
  //#region src/dom/plugin/dom-input-runtime.ts
2405
2530
  /**
2406
2531
  * Choose the event phase that owns a default editing action.
@@ -2970,94 +3095,6 @@ var DOMInputRuntime = class {
2970
3095
  }
2971
3096
  };
2972
3097
  //#endregion
2973
- //#region src/dom/utils/selection-writes.ts
2974
- const RECORDS = /* @__PURE__ */ new WeakMap();
2975
- const UNPLACED_WRITES = /* @__PURE__ */ new WeakMap();
2976
- const hasLayoutBox = ([node]) => {
2977
- const element = node.nodeType === 1 ? node : node.parentElement;
2978
- return !!element && element.getClientRects().length > 0;
2979
- };
2980
- const readDOMSelectionPoints = (selection) => {
2981
- const { anchorNode, focusNode } = selection;
2982
- return selection.rangeCount > 0 && anchorNode && focusNode ? {
2983
- anchor: [anchorNode, selection.anchorOffset],
2984
- focus: [focusNode, selection.focusOffset]
2985
- } : null;
2986
- };
2987
- const sameDOMPoint = ([node, offset], [otherNode, otherOffset]) => node === otherNode && offset === otherOffset;
2988
- const sameDOMSelectionPoints = (points, other) => points === null || other === null ? points === other : sameDOMPoint(points.anchor, other.anchor) && sameDOMPoint(points.focus, other.focus);
2989
- const readDOMSelectionRecord = (tree) => RECORDS.get(tree) ?? null;
2990
- const isDOMSelectionWriteEcho = (tree, points) => {
2991
- const record = RECORDS.get(tree);
2992
- return record?.source === "write" && sameDOMSelectionPoints(points, record.points);
2993
- };
2994
- const recordDOMSelection = (tree, points, source) => {
2995
- RECORDS.set(tree, {
2996
- points,
2997
- source
2998
- });
2999
- UNPLACED_WRITES.delete(tree);
3000
- };
3001
- const forgetDOMSelectionRecord = (tree) => {
3002
- RECORDS.delete(tree);
3003
- UNPLACED_WRITES.delete(tree);
3004
- };
3005
- const touches = (container, points) => !!points && (container.contains(points.anchor[0]) || container.contains(points.focus[0]));
3006
- const forgetDOMSelectionRecordWithin = (tree, container) => {
3007
- if (touches(container, RECORDS.get(tree)?.points)) RECORDS.delete(tree);
3008
- if (touches(container, UNPLACED_WRITES.get(tree))) UNPLACED_WRITES.delete(tree);
3009
- };
3010
- const getDOMRangeSelectionPoints = (range, backward = false) => {
3011
- const start = [range.startContainer, range.startOffset];
3012
- const end = [range.endContainer, range.endOffset];
3013
- return backward ? {
3014
- anchor: end,
3015
- focus: start
3016
- } : {
3017
- anchor: start,
3018
- focus: end
3019
- };
3020
- };
3021
- const readsSelectionAsHost = (tree) => tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && isWebKitDOMHost(tree);
3022
- /**
3023
- * Write `points` as `tree`'s selection, keeping their direction, or clear its
3024
- * ranges for null, and record what the tree then shows, or the points written
3025
- * where the tree reads its selection as its host. A selection that already
3026
- * shows them is left alone, and so is the record, unless WebKit got them from
3027
- * a write while their anchor had no layout box, neither the user nor a write
3028
- * of other points has come since, and the anchor has one now.
3029
- */
3030
- const writeDOMSelection = (tree, points) => {
3031
- changeDOMSelection(tree, points);
3032
- };
3033
- /**
3034
- * Write `points` as `tree`'s selection on the user's behalf and keep no
3035
- * record, so the selection claim reads them as the user's own selection, as
3036
- * it reads a native Shift-click.
3037
- */
3038
- const writeUserDOMSelection = (tree, points) => {
3039
- changeDOMSelection(tree, points);
3040
- forgetDOMSelectionRecord(tree);
3041
- };
3042
- const changeDOMSelection = (tree, points, beforeChange) => {
3043
- const selection = getSelection(tree);
3044
- if (!selection) return;
3045
- const rewritesUnplaced = points !== null && sameDOMSelectionPoints(UNPLACED_WRITES.get(tree) ?? null, points);
3046
- if (!rewritesUnplaced) UNPLACED_WRITES.delete(tree);
3047
- if (sameDOMSelectionPoints(readDOMSelectionPoints(selection), points) && !(rewritesUnplaced && hasLayoutBox(points.anchor))) return;
3048
- beforeChange?.();
3049
- if (points) selection.setBaseAndExtent(points.anchor[0], points.anchor[1], points.focus[0], points.focus[1]);
3050
- else selection.removeAllRanges();
3051
- if (points && hasDOMHostQuirk(tree, "unrendered-caret-needs-rewrite") && !hasLayoutBox(points.anchor)) UNPLACED_WRITES.set(tree, points);
3052
- else UNPLACED_WRITES.delete(tree);
3053
- RECORDS.set(tree, {
3054
- points: readsSelectionAsHost(tree) ? points : readDOMSelectionPoints(selection),
3055
- source: "write"
3056
- });
3057
- };
3058
- /** A copy of `selection`'s range at `index`, safe to keep or change. */
3059
- const readDOMSelectionRange = (selection, index = 0) => selection.getRangeAt(index).cloneRange();
3060
- //#endregion
3061
3098
  //#region src/dom/plugin/dom-integrity-observer.ts
3062
3099
  const OBSERVER_OPTIONS = {
3063
3100
  attributeOldValue: true,
@@ -3154,11 +3191,21 @@ const EDITOR_DOM_ATTRIBUTES = /* @__PURE__ */ new Set([
3154
3191
  "data-editor-zero-width"
3155
3192
  ]);
3156
3193
  const affectsEditorDOMContract = (mutation) => mutation.type !== "attributes" || mutation.attributeName !== null && EDITOR_DOM_ATTRIBUTES.has(mutation.attributeName);
3157
- const captureSelection = (root) => {
3158
- const selection = root.ownerDocument.getSelection();
3194
+ const captureSelection = (root, readSelection) => {
3195
+ if (readSelection) {
3196
+ const points = readSelection(root);
3197
+ if (!points || !containsShadowAware(root, points.anchor[0]) || !containsShadowAware(root, points.focus[0])) return null;
3198
+ return {
3199
+ anchorNode: points.anchor[0],
3200
+ anchorOffset: points.anchor[1],
3201
+ focusNode: points.focus[0],
3202
+ focusOffset: points.focus[1]
3203
+ };
3204
+ }
3205
+ const selection = getSelection(root.getRootNode());
3159
3206
  const anchorNode = selection?.anchorNode ?? null;
3160
3207
  const focusNode = selection?.focusNode ?? null;
3161
- if (!selection || !anchorNode || !focusNode || !root.contains(anchorNode) || !root.contains(focusNode)) return null;
3208
+ if (!selection || !anchorNode || !focusNode || !containsShadowAware(root, anchorNode) || !containsShadowAware(root, focusNode)) return null;
3162
3209
  return {
3163
3210
  anchorNode,
3164
3211
  anchorOffset: selection.anchorOffset,
@@ -3167,9 +3214,9 @@ const captureSelection = (root) => {
3167
3214
  };
3168
3215
  };
3169
3216
  const maxOffset = (node) => node.nodeType === TEXT_NODE ? node.nodeValue?.length ?? 0 : node.childNodes.length;
3170
- const restoreSelection = (root, snapshot) => {
3171
- if (!snapshot || !root.contains(snapshot.anchorNode) || !root.contains(snapshot.focusNode)) return;
3172
- writeDOMSelection(root.getRootNode(), {
3217
+ const restoreSelection = (root, snapshot, writeSelection) => {
3218
+ if (!snapshot || !writeSelection || !containsShadowAware(root, snapshot.anchorNode) || !containsShadowAware(root, snapshot.focusNode)) return;
3219
+ writeSelection(root, {
3173
3220
  anchor: [snapshot.anchorNode, Math.min(snapshot.anchorOffset, maxOffset(snapshot.anchorNode))],
3174
3221
  focus: [snapshot.focusNode, Math.min(snapshot.focusOffset, maxOffset(snapshot.focusNode))]
3175
3222
  });
@@ -3444,9 +3491,9 @@ var DOMIntegrityObserver = class {
3444
3491
  path: this.options.resolvePath(mutation),
3445
3492
  type: mutation.type
3446
3493
  }));
3447
- const selection = captureSelection(root);
3494
+ const selection = captureSelection(root, this.options.readSelection);
3448
3495
  for (const mutation of mutations.reverse()) restoreMutation(mutation);
3449
- restoreSelection(root, selection);
3496
+ restoreSelection(root, selection, this.options.writeSelection);
3450
3497
  this.repairPassesInFrame += 1;
3451
3498
  this.scheduleRepairPassReset();
3452
3499
  this.diagnosticsValue.repairPasses += 1;
@@ -4014,12 +4061,21 @@ const findDOMRootRuntime = (node) => {
4014
4061
  }
4015
4062
  return null;
4016
4063
  };
4064
+ const isNestedEditableOrInput = (root, node) => {
4065
+ let current = node ? asElement(node) : null;
4066
+ while (current && current !== root) {
4067
+ const tag = current.tagName;
4068
+ const ce = current.getAttribute("contenteditable");
4069
+ if (tag === "INPUT" || tag === "TEXTAREA" || current.hasAttribute("data-editor") || ce !== null && ce.toLowerCase() !== "false") return true;
4070
+ current = composedParent(current);
4071
+ }
4072
+ return false;
4073
+ };
4017
4074
  const isRuntimeRootActive = (runtime) => {
4018
4075
  const root = runtime.rootRef.current;
4019
4076
  if (!root) return false;
4020
- const rootNode = root.getRootNode();
4021
- const activeElement = "activeElement" in rootNode ? rootNode.activeElement : root.ownerDocument.activeElement;
4022
- return activeElement === root || !!activeElement && root.contains(activeElement);
4077
+ const active = focusedElementOnPage(root);
4078
+ return !!active && (active === root || containsShadowAware(root, active) && !isNestedEditableOrInput(root, active));
4023
4079
  };
4024
4080
  const hasMountedDOMRoot = (editor) => DOM_ROOT_RUNTIMES_BY_EDITOR.has(editor);
4025
4081
  const hasMountedDocumentView = (editor) => MOUNTED_VIEWS_BY_DOCUMENT.has(documentOf(editor));
@@ -4070,21 +4126,268 @@ const isElementFocused = (element) => {
4070
4126
  node = frame;
4071
4127
  }
4072
4128
  };
4129
+ const isReadOnlyRoot = (editable, editor) => {
4130
+ const owner = editor ?? findDOMRootRuntime(editable)?.editor;
4131
+ return !!owner && !!IS_READ_ONLY.get(owner) || editable.getAttribute("contenteditable") === "false";
4132
+ };
4133
+ const canWriteDOMSelection = (editable, editor) => {
4134
+ if (isElementFocused(editable)) return true;
4135
+ if (!isReadOnlyRoot(editable, editor)) return false;
4136
+ const active = focusedElementOnPage(editable);
4137
+ return !active || active === active.ownerDocument.body || active === active.ownerDocument.documentElement || containsShadowAware(editable, active) && !isNestedEditableOrInput(editable, active);
4138
+ };
4139
+ const shadowRootsAbove = (element) => {
4140
+ const roots = [];
4141
+ let current = element;
4142
+ while (current) {
4143
+ const rootNode = current.getRootNode();
4144
+ if ("host" in rootNode) {
4145
+ const shadowRoot = rootNode;
4146
+ roots.push(shadowRoot);
4147
+ current = shadowRoot.host;
4148
+ } else break;
4149
+ }
4150
+ return roots;
4151
+ };
4152
+ const readComposedSelectionRange = (editable, selection, shadowRoots = shadowRootsAbove(editable)) => {
4153
+ const composedSelection = selection;
4154
+ if (typeof composedSelection.getComposedRanges !== "function") return null;
4155
+ try {
4156
+ return composedSelection.getComposedRanges({ shadowRoots })[0] ?? null;
4157
+ } catch {
4158
+ try {
4159
+ return composedSelection.getComposedRanges(...shadowRoots)[0] ?? null;
4160
+ } catch {
4161
+ return null;
4162
+ }
4163
+ }
4164
+ };
4165
+ const readEditableDOMSelectionPoints = (editable, selection) => {
4166
+ if (!selection) return null;
4167
+ const tree = editable.getRootNode();
4168
+ if (tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE) {
4169
+ const composed = readComposedSelectionRange(editable, selection);
4170
+ if (composed) return selection.direction === "backward" ? {
4171
+ anchor: [composed.endContainer, composed.endOffset],
4172
+ focus: [composed.startContainer, composed.startOffset]
4173
+ } : {
4174
+ anchor: [composed.startContainer, composed.startOffset],
4175
+ focus: [composed.endContainer, composed.endOffset]
4176
+ };
4177
+ }
4178
+ return readDOMSelectionPoints(selection);
4179
+ };
4180
+ const isSelectionOwnedByEditable = (editable, selection, exclude) => {
4181
+ if (!selection) return false;
4182
+ const owns = (node) => !!node && containsShadowAware(editable, node) && !(exclude && exclude !== editable && containsShadowAware(exclude, node)) && !isNestedEditableOrInput(editable, node);
4183
+ if (owns(selection.anchorNode) || owns(selection.focusNode)) return true;
4184
+ const tree = editable.getRootNode();
4185
+ if (tree.nodeType !== tree.DOCUMENT_FRAGMENT_NODE) return false;
4186
+ const shadowRoots = shadowRootsAbove(editable);
4187
+ if (typeof selection.getComposedRanges === "function") {
4188
+ const composed = readComposedSelectionRange(editable, selection, shadowRoots);
4189
+ return !!composed && (owns(composed.startContainer) || owns(composed.endContainer));
4190
+ }
4191
+ if (!readsSelectionAsHost(tree)) return false;
4192
+ if (!shadowRoots.some((shadowRoot) => selection.anchorNode === shadowRoot.host || selection.focusNode === shadowRoot.host)) return false;
4193
+ if (selection.rangeCount > 0) try {
4194
+ const range = readDOMSelectionRange(selection);
4195
+ if (!shadowRoots.some((shadowRoot) => range.startContainer === shadowRoot.host && range.endContainer === shadowRoot.host)) return owns(range.startContainer) || owns(range.endContainer);
4196
+ } catch {
4197
+ return false;
4198
+ }
4199
+ const recorded = readDOMSelectionRecord(tree)?.points;
4200
+ return !!recorded && (owns(recorded.anchor[0]) || owns(recorded.focus[0]));
4201
+ };
4202
+ const shouldClearEditableDOMSelection = (editable, editor) => {
4203
+ const focusElement = findDOMRootRuntime(editable)?.nodeSelectionFocus();
4204
+ if (!canWriteDOMSelection(editable, editor) && !(focusElement && isElementFocused(focusElement))) return false;
4205
+ return isSelectionOwnedByEditable(editable, getSelection(editable.getRootNode()), focusElement);
4206
+ };
4207
+ const canWriteEditableDOMSelection = (editable, { editor, policy = "editable" } = {}) => policy === "focused" ? isElementFocused(editable) : canWriteDOMSelection(editable, editor);
4208
+ const writeEditableDOMSelection = (editable, points, { beforeChange, editor, policy = "editable", record = "write" } = {}) => {
4209
+ const tree = editable.getRootNode();
4210
+ const isAllowed = () => editable.getRootNode() === tree && canWriteEditableDOMSelection(editable, {
4211
+ editor,
4212
+ policy
4213
+ });
4214
+ if (!isAllowed()) return false;
4215
+ if (!changeDOMSelection(tree, points, beforeChange, isAllowed)) return false;
4216
+ if (record === "user") forgetDOMSelectionRecord(tree);
4217
+ return true;
4218
+ };
4219
+ const clearEditableDOMSelection = (editable, { beforeChange, editor, policy = "editable" } = {}) => {
4220
+ const tree = editable.getRootNode();
4221
+ const isAllowed = () => {
4222
+ if (editable.getRootNode() !== tree) return false;
4223
+ const focusElement = findDOMRootRuntime(editable)?.nodeSelectionFocus();
4224
+ const selection = getSelection(tree);
4225
+ return policy === "owned" ? isSelectionOwnedByEditable(editable, selection, focusElement) : policy === "focused" ? isElementFocused(editable) && isSelectionOwnedByEditable(editable, selection, focusElement) : shouldClearEditableDOMSelection(editable, editor);
4226
+ };
4227
+ if (!isAllowed()) return false;
4228
+ return changeDOMSelection(tree, null, beforeChange, isAllowed);
4229
+ };
4073
4230
  const resolveInnermostElementAtPoint = (document, x, y) => {
4074
4231
  let element = document.elementFromPoint(x, y);
4075
4232
  for (let inner = element && shadowRootOf(element)?.elementFromPoint(x, y); inner && inner !== element; inner = shadowRootOf(element)?.elementFromPoint(x, y)) element = inner;
4076
4233
  return element;
4077
4234
  };
4078
- const focusedElementOf = (top) => {
4235
+ const focusedElementOf = (top, extraShadowRoots) => {
4079
4236
  let element = top.activeElement;
4080
4237
  while (element) {
4081
- const inner = shadowRootOf(element)?.activeElement ?? element.contentDocument?.activeElement;
4238
+ const inner = (shadowRootOf(element) ?? extraShadowRoots?.get(element))?.activeElement ?? element.contentDocument?.activeElement;
4082
4239
  if (!inner) return element;
4083
4240
  element = inner;
4084
4241
  }
4085
4242
  return null;
4086
4243
  };
4087
- const focusedElementOnPage = (node) => focusedElementOf(pageOf(node.ownerDocument ?? node));
4244
+ const focusedElementOnPage = (node) => {
4245
+ let extraShadowRoots;
4246
+ const element = asElement(node);
4247
+ if (element) {
4248
+ for (const shadowRoot of shadowRootsAbove(element)) if (!shadowRootOf(shadowRoot.host)) {
4249
+ extraShadowRoots ??= /* @__PURE__ */ new Map();
4250
+ extraShadowRoots.set(shadowRoot.host, shadowRoot);
4251
+ }
4252
+ }
4253
+ return focusedElementOf(pageOf(node.ownerDocument ?? node), extraShadowRoots);
4254
+ };
4255
+ const isEventInsideRoot = (root, event, seen) => {
4256
+ if (seen?.has(event)) return true;
4257
+ return (typeof event.composedPath === "function" ? event.composedPath() : []).includes(root) || isDOMNode(event.target) && containsShadowAware(root, event.target);
4258
+ };
4259
+ const getEventTargetInRoot = (root, event) => {
4260
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4261
+ return path.includes(root) ? path[0] ?? event.target : event.target;
4262
+ };
4263
+ const isSlottedIntoShadowRoot = (shadowRoot, target) => {
4264
+ if (!isDOMNode(target)) return false;
4265
+ const slots = shadowRoot.querySelectorAll("slot");
4266
+ if (slots.length === 0) return false;
4267
+ for (const slot of slots) for (const assigned of slot.assignedNodes({ flatten: true })) if (assigned === target || containsShadowAware(assigned, target)) return true;
4268
+ return false;
4269
+ };
4270
+ const observeRootBoundaryEvent = (root, type, listener, { capture = true, filter = "all", scope = "document" } = {}) => {
4271
+ const { ownerDocument } = root;
4272
+ const outerTarget = scope === "window" ? ownerDocument.defaultView : ownerDocument;
4273
+ if (!outerTarget) return () => {};
4274
+ const allShadowRoots = shadowRootsAbove(root);
4275
+ const closedRoots = allShadowRoots.filter((shadowRoot) => shadowRoot.mode === "closed");
4276
+ const emit = (event, inRoot, target) => {
4277
+ if (filter === "inside" && !inRoot) return;
4278
+ if (filter === "outside" && inRoot) return;
4279
+ listener(event, {
4280
+ inRoot,
4281
+ target
4282
+ });
4283
+ };
4284
+ if (filter === "inside") {
4285
+ const insideTarget = allShadowRoots[0] ?? outerTarget;
4286
+ const handleInner = (event) => {
4287
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4288
+ if (!path.includes(root) && !(isDOMNode(event.target) && containsShadowAware(root, event.target))) return;
4289
+ emit(event, true, path[0] ?? event.target);
4290
+ };
4291
+ insideTarget.addEventListener(type, handleInner, capture);
4292
+ return () => {
4293
+ insideTarget.removeEventListener(type, handleInner, capture);
4294
+ };
4295
+ }
4296
+ if (closedRoots.length === 0) {
4297
+ const handleOuter = (event) => {
4298
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4299
+ const inRoot = path.includes(root) || isDOMNode(event.target) && containsShadowAware(root, event.target);
4300
+ const target = inRoot ? path[0] ?? event.target : event.target;
4301
+ emit(event, inRoot, target);
4302
+ };
4303
+ outerTarget.addEventListener(type, handleOuter, capture);
4304
+ return () => {
4305
+ outerTarget.removeEventListener(type, handleOuter, capture);
4306
+ };
4307
+ }
4308
+ const innermostRoot = allShadowRoots[0];
4309
+ if (!capture) {
4310
+ const insideTargets = /* @__PURE__ */ new WeakMap();
4311
+ const resetOnOuterCapture = (event) => {
4312
+ insideTargets.delete(event);
4313
+ };
4314
+ const markInside = (event) => {
4315
+ if (isEventInsideRoot(root, event)) {
4316
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4317
+ insideTargets.set(event, path[0] ?? event.target);
4318
+ }
4319
+ };
4320
+ const handleBubble = (event) => {
4321
+ const hasInside = insideTargets.has(event);
4322
+ const insideTarget = insideTargets.get(event) ?? null;
4323
+ insideTargets.delete(event);
4324
+ const inRoot = hasInside || isEventInsideRoot(root, event);
4325
+ const target = hasInside ? insideTarget ?? event.target : getEventTargetInRoot(root, event);
4326
+ emit(event, inRoot, target);
4327
+ };
4328
+ outerTarget.addEventListener(type, resetOnOuterCapture, true);
4329
+ innermostRoot.addEventListener(type, markInside, true);
4330
+ outerTarget.addEventListener(type, handleBubble, false);
4331
+ return () => {
4332
+ outerTarget.removeEventListener(type, resetOnOuterCapture, true);
4333
+ innermostRoot.removeEventListener(type, markInside, true);
4334
+ outerTarget.removeEventListener(type, handleBubble, false);
4335
+ };
4336
+ }
4337
+ const outerToInnerClosed = [...closedRoots].reverse();
4338
+ const levels = [outerTarget, ...outerToInnerClosed];
4339
+ const handled = /* @__PURE__ */ new WeakSet();
4340
+ const cleanups = [];
4341
+ for (let index = 0; index < levels.length; index += 1) {
4342
+ const levelTarget = levels[index];
4343
+ const nextClosed = outerToInnerClosed[index] ?? null;
4344
+ if (nextClosed) {
4345
+ const nextHost = nextClosed.host;
4346
+ const handleLevelCapture = (event) => {
4347
+ if (index === 0) handled.delete(event);
4348
+ if (handled.has(event)) return;
4349
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4350
+ const deepestTarget = path[0] ?? event.target;
4351
+ if (deepestTarget === nextHost || path.includes(nextHost) && isSlottedIntoShadowRoot(nextClosed, deepestTarget)) return;
4352
+ if (event.composed) handled.add(event);
4353
+ emit(event, false, deepestTarget);
4354
+ };
4355
+ const handleHostFallback = (event) => {
4356
+ if (handled.has(event)) return;
4357
+ if (((typeof event.composedPath === "function" ? event.composedPath() : [])[0] ?? event.target) !== nextHost) return;
4358
+ if (event.composed) handled.add(event);
4359
+ emit(event, false, event.target);
4360
+ };
4361
+ levelTarget.addEventListener(type, handleLevelCapture, true);
4362
+ nextHost.addEventListener(type, handleHostFallback, false);
4363
+ cleanups.push(() => {
4364
+ levelTarget.removeEventListener(type, handleLevelCapture, true);
4365
+ nextHost.removeEventListener(type, handleHostFallback, false);
4366
+ });
4367
+ } else {
4368
+ const handleInnermostCapture = (event) => {
4369
+ if (handled.has(event)) return;
4370
+ if (event.composed) handled.add(event);
4371
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
4372
+ const inRoot = path.includes(root) || isDOMNode(event.target) && containsShadowAware(root, event.target);
4373
+ emit(event, inRoot, inRoot ? path[0] ?? event.target : event.target);
4374
+ };
4375
+ levelTarget.addEventListener(type, handleInnermostCapture, true);
4376
+ cleanups.push(() => {
4377
+ levelTarget.removeEventListener(type, handleInnermostCapture, true);
4378
+ });
4379
+ }
4380
+ }
4381
+ return () => {
4382
+ for (const cleanup of cleanups) cleanup();
4383
+ };
4384
+ };
4385
+ const movedFocusElsewhere = (element, before, after) => {
4386
+ if (!after || after === before || after === element || containsShadowAware(element, after) && !isNestedEditableOrInput(element, after)) return false;
4387
+ const ownDoc = element.ownerDocument;
4388
+ const topDoc = pageOf(ownDoc);
4389
+ return after !== ownDoc.body && after !== ownDoc.documentElement && after !== topDoc.body && after !== topDoc.documentElement;
4390
+ };
4088
4391
  const outerElementOf = (element) => {
4089
4392
  if (element.parentElement) return element.parentElement;
4090
4393
  const parent = element.parentNode;
@@ -4131,6 +4434,16 @@ const resolveDOMReach = (handle, request = {}) => {
4131
4434
  if (presentation) return reachOwnView(mounted, handle, presentation, request);
4132
4435
  return handle === owner ? reachDocumentView(mounted, handle, request) : null;
4133
4436
  };
4437
+ const resolveMountedViewForRoot = (handle, root) => {
4438
+ if (!hasEditorRuntime(handle)) return null;
4439
+ if (hasMountedDOMRoot(handle) && getEditorRuntimeRoot(handle) === root) return handle;
4440
+ const owner = documentOf(handle);
4441
+ const mounted = MOUNTED_VIEWS_BY_DOCUMENT.get(owner);
4442
+ if (!mounted) return null;
4443
+ const presentation = getOwnViewPresentation(handle);
4444
+ if (presentation) return pickView(mounted, (view) => getOwnViewPresentation(view) === presentation && getEditorRuntimeRoot(view) === root);
4445
+ return handle === owner ? reachDocumentView(mounted, handle, { root }) : null;
4446
+ };
4134
4447
  const resolveDOMTargetView = (handle, node) => {
4135
4448
  if (hasMountedDOMRoot(handle)) return handle;
4136
4449
  const view = node ? findDOMRootRuntime(node)?.editor : null;
@@ -4192,6 +4505,7 @@ var DOMRootRuntime = class DOMRootRuntime {
4192
4505
  connected = false;
4193
4506
  isComposing;
4194
4507
  isSelectionHeld;
4508
+ exportSelection;
4195
4509
  focusSelection;
4196
4510
  nodeSelectionFocus;
4197
4511
  generation = 0;
@@ -4210,6 +4524,7 @@ var DOMRootRuntime = class DOMRootRuntime {
4210
4524
  constructor(options) {
4211
4525
  this.isComposing = options.isComposing;
4212
4526
  this.isSelectionHeld = options.isSelectionHeld ?? (() => false);
4527
+ this.exportSelection = options.exportSelection ?? (() => void 0);
4213
4528
  this.focusSelection = options.focusSelection ?? (() => false);
4214
4529
  this.nodeSelectionFocus = options.nodeSelectionFocus ?? (() => null);
4215
4530
  this.adapter = options.adapter;
@@ -4228,6 +4543,8 @@ var DOMRootRuntime = class DOMRootRuntime {
4228
4543
  this.schedulerImplementation = this.createScheduler();
4229
4544
  this.domSyncMutationOwnership = new DOMSyncMutationOwnership((phase, label, callback, scheduleOptions) => this.schedulerImplementation?.schedule(phase, label, callback, scheduleOptions) ?? (() => {}));
4230
4545
  this.domIntegrityObserver = new DOMIntegrityObserver({
4546
+ readSelection: (root) => readEditableDOMSelectionPoints(root, getSelection(root.getRootNode())),
4547
+ writeSelection: (root, points) => writeEditableDOMSelection(root, points, { editor: this.editor }),
4231
4548
  getAndroidMutationHandler: options.getAndroidMutationHandler,
4232
4549
  isAndroidMutationOwned: options.isAndroidMutationOwned,
4233
4550
  isCanonicalTextMutation: options.isCanonicalTextMutation,
@@ -4554,7 +4871,7 @@ var DOMRootRuntime = class DOMRootRuntime {
4554
4871
  this.rootInputActivationCleanup = null;
4555
4872
  const runtime = this;
4556
4873
  const root = this.rootRef.current;
4557
- const activeElement = (root?.getRootNode())?.activeElement;
4874
+ const activeElement = root ? focusedElementOnPage(root) : null;
4558
4875
  const focusedRuntime = activeElement ? findDOMRootRuntime(activeElement) : null;
4559
4876
  const otherFocusedView = focusedRuntime && focusedRuntime.editor === this.editor && focusedRuntime !== runtime;
4560
4877
  if (root && DOM_ROOT_RUNTIME_BY_ROOT.get(root) === runtime) DOM_ROOT_RUNTIME_BY_ROOT.delete(root);
@@ -5992,9 +6309,7 @@ const writeDataTransferFragment = (editor, data, slice, options = {}) => {
5992
6309
  //#region src/dom/plugin/dom-clipboard-runtime.ts
5993
6310
  const PLITE_FRAGMENT_ATTRIBUTE_RE = /\bdata-editor-fragment\s*=/i;
5994
6311
  const OPENING_HTML_TAG_RE = /<[A-Za-z][^<>]*?>/;
5995
- const DEFAULT_CLIPBOARD_FORMAT_KEY$1 = "x-editor-fragment";
5996
6312
  const PLITE_FRAGMENT_FORMAT_ATTRIBUTE = "data-editor-fragment-format";
5997
- const EDITOR_TO_CLIPBOARD_FORMAT_KEY = /* @__PURE__ */ new WeakMap();
5998
6313
  /** Semantic commands that own DOM clipboard ingress. */
5999
6314
  const domCommands = Object.freeze({ insertData: defineCommand("dom.insertData", {
6000
6315
  locate: false,
@@ -6003,6 +6318,7 @@ const domCommands = Object.freeze({ insertData: defineCommand("dom.insertData",
6003
6318
  return getInstalledPlugin(editor, "dom") ? withLandingBlock(editor, state, (current) => createDOMDataTransactionSpec(editor, input, current)) : false;
6004
6319
  }
6005
6320
  }) });
6321
+ registerImplicitTargetCommand(domCommands.insertData, void 0, { crossingPolicy: "cancel" });
6006
6322
  const stripRenderOnlyLeafWrappers = (root, ui) => {
6007
6323
  Array.from(root.querySelectorAll("[data-editor-leaf] span:not([data-editor-string]):not([data-editor-zero-width])")).forEach((candidate) => {
6008
6324
  if (candidate.closest("[data-editor-leaf]")) {
@@ -6012,14 +6328,6 @@ const stripRenderOnlyLeafWrappers = (root, ui) => {
6012
6328
  }
6013
6329
  });
6014
6330
  };
6015
- const setDOMClipboardFormatKey = (editor, clipboardFormatKey) => {
6016
- EDITOR_TO_CLIPBOARD_FORMAT_KEY.set(getEditorRuntimeOwner(editor), clipboardFormatKey);
6017
- };
6018
- const clearDOMClipboardFormatKey = (editor) => {
6019
- EDITOR_TO_CLIPBOARD_FORMAT_KEY.delete(getEditorRuntimeOwner(editor));
6020
- };
6021
- /** Read the configured MIME suffix used for exact Plite clipboard payloads. */
6022
- const getDOMClipboardFormatKey = (editor) => EDITOR_TO_CLIPBOARD_FORMAT_KEY.get(getEditorRuntimeOwner(editor)) ?? DEFAULT_CLIPBOARD_FORMAT_KEY$1;
6023
6331
  const escapeHtmlText = (text) => text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
6024
6332
  const escapeHtmlAttribute = (text) => escapeHtmlText(text).replaceAll("\"", "&quot;");
6025
6333
  const attachFragmentMetadataToHtml = (html, encoded, clipboardFormatKey) => {
@@ -6147,7 +6455,7 @@ const encodeDOMFragmentData = (slice, window) => {
6147
6455
  return (window?.btoa ?? globalThis.btoa)(encodeURIComponent(string));
6148
6456
  };
6149
6457
  /** Write Plite fragment MIME, HTML, and plain-text clipboard payloads. */
6150
- const writeDOMFragmentData = (data, { clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$1, html, slice, text, window }) => {
6458
+ const writeDOMFragmentData = (data, { clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$2, html, slice, text, window }) => {
6151
6459
  const sourceSlice = ContentSlice.fromJSON(slice);
6152
6460
  const sourceText = text ?? getFragmentText(sourceSlice);
6153
6461
  const encoded = encodeDOMFragmentData(sourceSlice, window);
@@ -7370,7 +7678,9 @@ const resolveVoidEventRange = (editor, { node, path, target, x, y }) => {
7370
7678
  //#endregion
7371
7679
  //#region src/dom/plugin/dom-scroll-into-view.ts
7372
7680
  const MARGIN = 4;
7681
+ const MAX_IFRAME_DEPTH = 16;
7373
7682
  const SCROLLABLE_RE = /(auto|scroll|overlay)/;
7683
+ const HIDDEN_OVERFLOW_RE = /\bhidden\b/;
7374
7684
  const isUsableScrollRect = (r) => r.width > 0 || r.height > 0 || r.x !== 0 || r.y !== 0 || r.top !== 0 || r.left !== 0 || r.bottom !== 0 || r.right !== 0;
7375
7685
  const toScrollRect = (r) => ({
7376
7686
  bottom: r.bottom,
@@ -7378,28 +7688,105 @@ const toScrollRect = (r) => ({
7378
7688
  right: r.right,
7379
7689
  top: r.top
7380
7690
  });
7691
+ const isDefaultScrollRevealOptions = (options) => options === void 0 || typeof options === "object" && options !== null && (options.scrollMode === void 0 || options.scrollMode === "if-needed") && options.block === void 0 && options.inline === void 0 && options.behavior === void 0 && options.boundary === void 0 && options.skipOverflowHiddenElements === void 0;
7692
+ const normalizeOptions = (options) => {
7693
+ if (isDefaultScrollRevealOptions(options)) return {
7694
+ behavior: "auto",
7695
+ block: "nearest",
7696
+ boundary: null,
7697
+ defaultReveal: true,
7698
+ inline: "nearest",
7699
+ scrollMode: "if-needed",
7700
+ skipOverflowHiddenElements: true
7701
+ };
7702
+ if (typeof options === "boolean") return {
7703
+ behavior: "auto",
7704
+ block: options ? "start" : "end",
7705
+ boundary: null,
7706
+ defaultReveal: false,
7707
+ inline: "nearest",
7708
+ scrollMode: "always",
7709
+ skipOverflowHiddenElements: true
7710
+ };
7711
+ const scrollMode = options?.scrollMode ?? "always";
7712
+ return {
7713
+ behavior: options?.behavior ?? "auto",
7714
+ block: options?.block ?? (scrollMode === "always" ? "center" : "nearest"),
7715
+ boundary: options?.boundary ?? null,
7716
+ defaultReveal: false,
7717
+ inline: options?.inline ?? "nearest",
7718
+ scrollMode,
7719
+ skipOverflowHiddenElements: options?.skipOverflowHiddenElements ?? true
7720
+ };
7721
+ };
7381
7722
  const shiftRect = (r, dx, dy) => ({
7382
7723
  bottom: r.bottom - dy,
7383
7724
  left: r.left - dx,
7384
7725
  right: r.right - dx,
7385
7726
  top: r.top - dy
7386
7727
  });
7387
- const canScroll = (el, style, axis) => {
7728
+ const parsePositivePx = (value) => {
7729
+ const n = Number.parseFloat(value ?? "");
7730
+ return Number.isFinite(n) && n > 0 ? n : 0;
7731
+ };
7732
+ const getElementStyle = (element) => element.ownerDocument.defaultView?.getComputedStyle(element) ?? (isDOMHTMLElement(element) ? element.style : void 0);
7733
+ const readScrollMargins = (element, scrollMarginTopOverride) => {
7734
+ const style = getElementStyle(element);
7735
+ const inlineStyle = isDOMHTMLElement(element) ? element.style : void 0;
7736
+ const top = scrollMarginTopOverride !== void 0 ? Math.max(0, scrollMarginTopOverride) : parsePositivePx(inlineStyle?.scrollMarginTop || style?.scrollMarginTop);
7737
+ return {
7738
+ bottom: parsePositivePx(inlineStyle?.scrollMarginBottom || style?.scrollMarginBottom),
7739
+ left: parsePositivePx(inlineStyle?.scrollMarginLeft || style?.scrollMarginLeft),
7740
+ right: parsePositivePx(inlineStyle?.scrollMarginRight || style?.scrollMarginRight),
7741
+ top
7742
+ };
7743
+ };
7744
+ const canScroll = (el, style, axis, skipOverflowHiddenElements) => {
7388
7745
  const overflow = axis === "y" ? `${style?.overflowY ?? ""} ${style?.overflow ?? ""}` : `${style?.overflowX ?? ""} ${style?.overflow ?? ""}`;
7389
- return SCROLLABLE_RE.test(overflow) && (axis === "y" ? el.scrollHeight > el.clientHeight : el.scrollWidth > el.clientWidth);
7746
+ return (SCROLLABLE_RE.test(overflow) || !skipOverflowHiddenElements && HIDDEN_OVERFLOW_RE.test(overflow)) && (axis === "y" ? el.scrollHeight > el.clientHeight : el.scrollWidth > el.clientWidth);
7390
7747
  };
7391
7748
  const pad = (value, size) => {
7392
7749
  const n = Number.parseFloat(value ?? "");
7393
7750
  if (!Number.isFinite(n) || n <= 0) return 0;
7394
7751
  return value?.trim().endsWith("%") ? n / 100 * size : n;
7395
7752
  };
7396
- const paddedBox = (rect, style) => ({
7397
- bottom: rect.bottom - pad(style?.scrollPaddingBottom, rect.height) - MARGIN,
7398
- left: rect.left + pad(style?.scrollPaddingLeft, rect.width) + MARGIN,
7399
- right: rect.right - pad(style?.scrollPaddingRight, rect.width) - MARGIN,
7400
- top: rect.top + pad(style?.scrollPaddingTop, rect.height) + MARGIN
7753
+ const paddedBox = (rect, style, margin, scaleX = 1, scaleY = 1) => ({
7754
+ bottom: rect.bottom - pad(style?.scrollPaddingBottom, rect.height / scaleY) * scaleY - margin,
7755
+ left: rect.left + pad(style?.scrollPaddingLeft, rect.width / scaleX) * scaleX + margin,
7756
+ right: rect.right - pad(style?.scrollPaddingRight, rect.width / scaleX) * scaleX - margin,
7757
+ top: rect.top + pad(style?.scrollPaddingTop, rect.height / scaleY) * scaleY + margin
7401
7758
  });
7402
- const getVisibleViewportBox = (win, scrollingElement) => {
7759
+ const getElementScale = (el, rect) => {
7760
+ if (!isDOMHTMLElement(el)) return {
7761
+ x: 1,
7762
+ y: 1
7763
+ };
7764
+ return {
7765
+ x: el.offsetWidth > 0 && rect.width > 0 ? rect.width / el.offsetWidth : 1,
7766
+ y: el.offsetHeight > 0 && rect.height > 0 ? rect.height / el.offsetHeight : 1
7767
+ };
7768
+ };
7769
+ const getScrollContainerBox = (el, style, scale, margin) => {
7770
+ const rect = el.getBoundingClientRect();
7771
+ const borderTop = parsePositivePx(style?.borderTopWidth) * scale.y;
7772
+ const borderBottom = parsePositivePx(style?.borderBottomWidth) * scale.y;
7773
+ const borderLeft = parsePositivePx(style?.borderLeftWidth) * scale.x;
7774
+ const borderRight = parsePositivePx(style?.borderRightWidth) * scale.x;
7775
+ const top = rect.top + borderTop;
7776
+ const bottom = el.clientHeight > 0 ? Math.min(rect.bottom - borderBottom, top + el.clientHeight * scale.y) : rect.bottom - borderBottom;
7777
+ const isRtl = style?.direction === "rtl";
7778
+ const left = isRtl && el.clientWidth > 0 ? Math.max(rect.left + borderLeft, rect.right - borderRight - el.clientWidth * scale.x) : rect.left + borderLeft;
7779
+ const right = !isRtl && el.clientWidth > 0 ? Math.min(rect.right - borderRight, left + el.clientWidth * scale.x) : rect.right - borderRight;
7780
+ return paddedBox({
7781
+ bottom,
7782
+ height: Math.max(0, bottom - top),
7783
+ left,
7784
+ right,
7785
+ top,
7786
+ width: Math.max(0, right - left)
7787
+ }, style, margin, scale.x, scale.y);
7788
+ };
7789
+ const getVisibleViewportBox = (win, scrollingElement, margin) => {
7403
7790
  const vv = win.visualViewport;
7404
7791
  const height = vv?.height ?? win.innerHeight;
7405
7792
  const width = vv?.width ?? win.innerWidth;
@@ -7412,10 +7799,15 @@ const getVisibleViewportBox = (win, scrollingElement) => {
7412
7799
  right: left + width,
7413
7800
  top,
7414
7801
  width
7415
- }, win.getComputedStyle(scrollingElement));
7802
+ }, win.getComputedStyle(scrollingElement), margin);
7416
7803
  };
7417
- const axisDelta = (start, end, low, high, ownLow, ownHigh) => {
7804
+ const axisDelta = ({ align, end, high, low, ownHigh, ownLow, rtl = false, scrollMode, start }) => {
7418
7805
  if (low >= high) return 0;
7806
+ if (scrollMode === "if-needed" && start >= low && end <= high) return 0;
7807
+ if (align === "start") return rtl ? end - high : start - low;
7808
+ if (align === "end") return rtl ? start - low : end - high;
7809
+ if (align === "center") return (start + end) / 2 - (low + high) / 2;
7810
+ if (start < low && end > high) return 0;
7419
7811
  if (start < low) {
7420
7812
  const d = low - start;
7421
7813
  return ownHigh === void 0 ? -d : -Math.min(d, Math.max(0, ownHigh - end));
@@ -7426,49 +7818,271 @@ const axisDelta = (start, end, low, high, ownLow, ownHigh) => {
7426
7818
  }
7427
7819
  return 0;
7428
7820
  };
7429
- const scrollAncestors = (startElement, scrollingElement, rect, visibleBox) => {
7821
+ const applyElementScroll = (el, dx, dy, behavior) => {
7822
+ const prevLeft = el.scrollLeft;
7823
+ const prevTop = el.scrollTop;
7824
+ const nextLeft = prevLeft + dx;
7825
+ const nextTop = prevTop + dy;
7826
+ if (behavior === "smooth" && typeof el.scroll === "function") {
7827
+ el.scroll({
7828
+ behavior,
7829
+ left: nextLeft,
7830
+ top: nextTop
7831
+ });
7832
+ return {
7833
+ dx,
7834
+ dy
7835
+ };
7836
+ }
7837
+ if (typeof el.scroll === "function") el.scroll({
7838
+ behavior,
7839
+ left: nextLeft,
7840
+ top: nextTop
7841
+ });
7842
+ if (el.scrollTop === prevTop && dy !== 0) el.scrollTop = nextTop;
7843
+ if (el.scrollLeft === prevLeft && dx !== 0) el.scrollLeft = nextLeft;
7844
+ return {
7845
+ dx: el.scrollLeft - prevLeft,
7846
+ dy: el.scrollTop - prevTop
7847
+ };
7848
+ };
7849
+ const scrollAncestors = (startElement, scrollingElement, rect, visibleBox, options) => {
7430
7850
  let cur = rect;
7851
+ const margin = options.defaultReveal ? MARGIN : 0;
7852
+ if (getElementStyle(startElement)?.position === "fixed") return {
7853
+ cur,
7854
+ stopped: true
7855
+ };
7856
+ if (options.boundary === startElement) return {
7857
+ cur,
7858
+ stopped: true
7859
+ };
7431
7860
  for (let el = getFlatTreeParentElement(startElement); el; el = getFlatTreeParentElement(el)) {
7432
- if (el === scrollingElement) continue;
7433
- const style = el.ownerDocument.defaultView?.getComputedStyle(el);
7434
- const scrollY = canScroll(el, style, "y");
7435
- const scrollX = canScroll(el, style, "x");
7436
- if (!scrollY && !scrollX) continue;
7437
- const own = paddedBox(el.getBoundingClientRect(), style);
7438
- const dy = scrollY ? visibleBox ? axisDelta(cur.top, cur.bottom, Math.max(own.top, visibleBox.top), Math.min(own.bottom, visibleBox.bottom), own.top, own.bottom) : axisDelta(cur.top, cur.bottom, own.top, own.bottom) : 0;
7439
- const dx = scrollX ? visibleBox ? axisDelta(cur.left, cur.right, Math.max(own.left, visibleBox.left), Math.min(own.right, visibleBox.right), own.left, own.right) : axisDelta(cur.left, cur.right, own.left, own.right) : 0;
7440
- if (dy === 0 && dx === 0) continue;
7441
- const prevTop = el.scrollTop;
7442
- const prevLeft = el.scrollLeft;
7443
- el.scrollTop += dy;
7444
- el.scrollLeft += dx;
7445
- cur = shiftRect(cur, el.scrollLeft - prevLeft, el.scrollTop - prevTop);
7446
- }
7447
- return cur;
7861
+ if (typeof options.boundary === "function" && !options.boundary(el)) return {
7862
+ cur,
7863
+ stopped: true
7864
+ };
7865
+ if (el === scrollingElement) return {
7866
+ cur,
7867
+ stopped: options.boundary === el
7868
+ };
7869
+ const style = getElementStyle(el);
7870
+ const scrollY = canScroll(el, style, "y", options.skipOverflowHiddenElements);
7871
+ const scrollX = canScroll(el, style, "x", options.skipOverflowHiddenElements);
7872
+ if (scrollY || scrollX) {
7873
+ const scale = getElementScale(el, el.getBoundingClientRect());
7874
+ const own = getScrollContainerBox(el, style, scale, margin);
7875
+ const isRtl = style?.direction === "rtl";
7876
+ const dy = scrollY ? visibleBox ? axisDelta({
7877
+ align: "nearest",
7878
+ end: cur.bottom,
7879
+ high: Math.min(own.bottom, visibleBox.bottom),
7880
+ low: Math.max(own.top, visibleBox.top),
7881
+ ownHigh: own.bottom,
7882
+ ownLow: own.top,
7883
+ scrollMode: "if-needed",
7884
+ start: cur.top
7885
+ }) : axisDelta({
7886
+ align: options.block,
7887
+ end: cur.bottom,
7888
+ high: own.bottom,
7889
+ low: own.top,
7890
+ scrollMode: options.scrollMode,
7891
+ start: cur.top
7892
+ }) : 0;
7893
+ const dx = scrollX ? visibleBox ? axisDelta({
7894
+ align: "nearest",
7895
+ end: cur.right,
7896
+ high: Math.min(own.right, visibleBox.right),
7897
+ low: Math.max(own.left, visibleBox.left),
7898
+ ownHigh: own.right,
7899
+ ownLow: own.left,
7900
+ rtl: isRtl,
7901
+ scrollMode: "if-needed",
7902
+ start: cur.left
7903
+ }) : axisDelta({
7904
+ align: options.inline,
7905
+ end: cur.right,
7906
+ high: own.right,
7907
+ low: own.left,
7908
+ rtl: isRtl,
7909
+ scrollMode: options.scrollMode,
7910
+ start: cur.left
7911
+ }) : 0;
7912
+ if (dy !== 0 || dx !== 0) {
7913
+ const applied = applyElementScroll(el, dx / scale.x, dy / scale.y, options.behavior);
7914
+ cur = shiftRect(cur, applied.dx * scale.x, applied.dy * scale.y);
7915
+ }
7916
+ }
7917
+ if (style?.position === "fixed" || options.boundary === el) return {
7918
+ cur,
7919
+ stopped: true
7920
+ };
7921
+ }
7922
+ return {
7923
+ cur,
7924
+ stopped: false
7925
+ };
7926
+ };
7927
+ const outsideBox = (rect, box, tolerance = 0) => rect.top < box.top - tolerance || rect.bottom > box.bottom + tolerance || rect.left < box.left - tolerance || rect.right > box.right + tolerance;
7928
+ const setCaretScrollMargin = (el, elRect, caret, top, right, bottom, left) => {
7929
+ el.style.setProperty("scroll-margin", `${top - (caret.top - elRect.top)}px ${right - (elRect.right - caret.right)}px ${bottom - (elRect.bottom - caret.bottom)}px ${left - (caret.left - elRect.left)}px`);
7930
+ };
7931
+ const canPanVisualViewport = (win, scrollingElement, el) => {
7932
+ const vv = win.visualViewport;
7933
+ return Boolean(vv && isDOMHTMLElement(el) && typeof el.scrollIntoView === "function" && (vv.height < scrollingElement.clientHeight || vv.width < scrollingElement.clientWidth));
7934
+ };
7935
+ const panVisualViewportNearest = (win, scrollingElement, el, caret, margin) => {
7936
+ const vv = win.visualViewport;
7937
+ if (!vv || !canPanVisualViewport(win, scrollingElement, el)) return caret;
7938
+ const elRect = el.getBoundingClientRect();
7939
+ const prev = el.style.getPropertyValue("scroll-margin");
7940
+ const priority = el.style.getPropertyPriority("scroll-margin");
7941
+ const caretAfter = () => {
7942
+ const afterRect = el.getBoundingClientRect();
7943
+ return shiftRect(caret, elRect.left - afterRect.left, elRect.top - afterRect.top);
7944
+ };
7945
+ setCaretScrollMargin(el, elRect, caret, margin, margin, margin, margin);
7946
+ el.scrollIntoView({
7947
+ block: "nearest",
7948
+ inline: "nearest"
7949
+ });
7950
+ let nextCaret = caretAfter();
7951
+ if (outsideBox(nextCaret, getVisibleViewportBox(win, scrollingElement, margin), 1)) {
7952
+ const rootStyle = win.getComputedStyle(scrollingElement);
7953
+ const padTop = pad(rootStyle.scrollPaddingTop, vv.height);
7954
+ const padRight = pad(rootStyle.scrollPaddingRight, vv.width);
7955
+ const padBottom = pad(rootStyle.scrollPaddingBottom, vv.height);
7956
+ const padLeft = pad(rootStyle.scrollPaddingLeft, vv.width);
7957
+ if (padTop > 0 || padRight > 0 || padBottom > 0 || padLeft > 0) {
7958
+ setCaretScrollMargin(el, elRect, caret, margin + padTop, margin + padRight, margin + padBottom, margin + padLeft);
7959
+ el.scrollIntoView({
7960
+ block: "nearest",
7961
+ inline: "nearest"
7962
+ });
7963
+ nextCaret = caretAfter();
7964
+ }
7965
+ }
7966
+ if (prev) el.style.setProperty("scroll-margin", prev, priority);
7967
+ else el.style.removeProperty("scroll-margin");
7968
+ return nextCaret;
7969
+ };
7970
+ const panVisualViewportCenter = (win, scrollingElement, el, caret, margin) => {
7971
+ if (!canPanVisualViewport(win, scrollingElement, el)) return;
7972
+ const elRect = el.getBoundingClientRect();
7973
+ const prev = el.style.getPropertyValue("scroll-margin");
7974
+ const priority = el.style.getPropertyPriority("scroll-margin");
7975
+ setCaretScrollMargin(el, elRect, caret, margin, margin, margin, margin);
7976
+ el.scrollIntoView({
7977
+ block: "center",
7978
+ inline: "nearest"
7979
+ });
7980
+ if (prev) el.style.setProperty("scroll-margin", prev, priority);
7981
+ else el.style.removeProperty("scroll-margin");
7982
+ };
7983
+ const getEnclosingFrame = (win) => {
7984
+ try {
7985
+ return win.frameElement;
7986
+ } catch {
7987
+ return null;
7988
+ }
7989
+ };
7990
+ const mapRectIntoParentWindow = (rect, frame) => {
7991
+ const frameRect = frame.getBoundingClientRect();
7992
+ const frameStyle = getElementStyle(frame);
7993
+ const scale = getElementScale(frame, frameRect);
7994
+ const offsetX = frameRect.left + (parsePositivePx(frameStyle?.borderLeftWidth) + parsePositivePx(frameStyle?.paddingLeft)) * scale.x;
7995
+ const offsetY = frameRect.top + (parsePositivePx(frameStyle?.borderTopWidth) + parsePositivePx(frameStyle?.paddingTop)) * scale.y;
7996
+ return {
7997
+ bottom: offsetY + rect.bottom * scale.y,
7998
+ left: offsetX + rect.left * scale.x,
7999
+ right: offsetX + rect.right * scale.x,
8000
+ top: offsetY + rect.top * scale.y
8001
+ };
8002
+ };
8003
+ const scrollRectIntoView = ({ options, rect, scrollMarginTop, startElement }) => {
8004
+ const normalized = normalizeOptions(options);
8005
+ const margin = normalized.defaultReveal ? MARGIN : 0;
8006
+ const margins = readScrollMargins(startElement, scrollMarginTop);
8007
+ let cur = {
8008
+ bottom: rect.bottom + margins.bottom,
8009
+ left: rect.left - margins.left,
8010
+ right: rect.right + margins.right,
8011
+ top: rect.top - margins.top
8012
+ };
8013
+ let currentStart = startElement;
8014
+ for (let depth = 0; depth < MAX_IFRAME_DEPTH; depth += 1) {
8015
+ const doc = currentStart.ownerDocument;
8016
+ const scrollingElement = doc.scrollingElement ?? doc.documentElement;
8017
+ if (!scrollingElement) return;
8018
+ const { cur: afterAncestors, stopped } = scrollAncestors(currentStart, scrollingElement, cur, null, normalized);
8019
+ cur = afterAncestors;
8020
+ if (stopped) return;
8021
+ const win = doc.defaultView;
8022
+ if (!win) return;
8023
+ const isRtl = win.getComputedStyle(scrollingElement)?.direction === "rtl";
8024
+ let visible = getVisibleViewportBox(win, scrollingElement, margin);
8025
+ const dy = scrollingElement.scrollHeight > scrollingElement.clientHeight ? axisDelta({
8026
+ align: normalized.block,
8027
+ end: cur.bottom,
8028
+ high: visible.bottom,
8029
+ low: visible.top,
8030
+ scrollMode: normalized.scrollMode,
8031
+ start: cur.top
8032
+ }) : 0;
8033
+ const dx = scrollingElement.scrollWidth > scrollingElement.clientWidth ? axisDelta({
8034
+ align: normalized.inline,
8035
+ end: cur.right,
8036
+ high: visible.right,
8037
+ low: visible.left,
8038
+ rtl: isRtl,
8039
+ scrollMode: normalized.scrollMode,
8040
+ start: cur.left
8041
+ }) : 0;
8042
+ if (dy !== 0 || dx !== 0) {
8043
+ if (normalized.behavior === "smooth") {
8044
+ win.scrollBy({
8045
+ behavior: "smooth",
8046
+ left: dx,
8047
+ top: dy
8048
+ });
8049
+ cur = shiftRect(cur, dx, dy);
8050
+ } else {
8051
+ const prevY = win.scrollY;
8052
+ const prevX = win.scrollX;
8053
+ win.scrollBy(dx, dy);
8054
+ cur = shiftRect(cur, win.scrollX - prevX, win.scrollY - prevY);
8055
+ }
8056
+ visible = getVisibleViewportBox(win, scrollingElement, margin);
8057
+ }
8058
+ if (normalized.behavior !== "smooth") {
8059
+ if (outsideBox(cur, visible, 1)) {
8060
+ cur = panVisualViewportNearest(win, scrollingElement, currentStart, cur, margin);
8061
+ visible = getVisibleViewportBox(win, scrollingElement, margin);
8062
+ }
8063
+ if (outsideBox(cur, visible)) ({cur} = scrollAncestors(currentStart, scrollingElement, cur, visible, normalized));
8064
+ if (outsideBox(cur, visible, 1)) panVisualViewportCenter(win, scrollingElement, currentStart, cur, margin);
8065
+ }
8066
+ const frame = getEnclosingFrame(win);
8067
+ if (!frame || frame.ownerDocument === doc) return;
8068
+ if (normalized.boundary === frame || typeof normalized.boundary === "function" && !normalized.boundary(frame)) return;
8069
+ cur = mapRectIntoParentWindow(cur, frame);
8070
+ currentStart = frame;
8071
+ }
7448
8072
  };
7449
8073
  const scrollRectIntoViewIfNeeded = ({ rect, startElement }) => {
7450
- const scrollingElement = startElement.ownerDocument.scrollingElement ?? startElement.ownerDocument.documentElement;
7451
- let cur = scrollAncestors(startElement, scrollingElement, rect, null);
7452
- const win = startElement.ownerDocument.defaultView;
7453
- if (!win) return;
7454
- let visible = getVisibleViewportBox(win, scrollingElement);
7455
- const dy = scrollingElement.scrollHeight > scrollingElement.clientHeight ? axisDelta(cur.top, cur.bottom, visible.top, visible.bottom) : 0;
7456
- const dx = scrollingElement.scrollWidth > scrollingElement.clientWidth ? axisDelta(cur.left, cur.right, visible.left, visible.right) : 0;
7457
- if (dy !== 0 || dx !== 0) {
7458
- const prevY = win.scrollY;
7459
- const prevX = win.scrollX;
7460
- win.scrollBy(dx, dy);
7461
- cur = shiftRect(cur, win.scrollX - prevX, win.scrollY - prevY);
7462
- visible = getVisibleViewportBox(win, scrollingElement);
7463
- }
7464
- if (cur.top < visible.top || cur.bottom > visible.bottom || cur.left < visible.left || cur.right > visible.right) scrollAncestors(startElement, scrollingElement, cur, visible);
7465
- };
7466
- const scrollDOMRangeIntoViewIfNeeded = (domRange, isBackward = false) => {
8074
+ scrollRectIntoView({
8075
+ rect,
8076
+ startElement
8077
+ });
8078
+ };
8079
+ const scrollDOMRangeFocusIntoViewIfNeeded = (domRange, isBackward = false) => {
7467
8080
  const focusRange = domRange.cloneRange();
7468
8081
  focusRange.collapse(isBackward);
7469
8082
  const container = focusRange.startContainer;
7470
8083
  const leafEl = isDOMElement(container) ? container : container.parentElement;
7471
8084
  if (!leafEl) return;
8085
+ if (typeof focusRange.getBoundingClientRect !== "function") return;
7472
8086
  const domRect = focusRange.getBoundingClientRect();
7473
8087
  const targetRect = isUsableScrollRect(domRect) ? domRect : leafEl.getBoundingClientRect();
7474
8088
  if (!isUsableScrollRect(targetRect)) return;
@@ -7530,6 +8144,41 @@ const claimFocusRequest = (editor, element) => {
7530
8144
  supersedeFocusRequest(editor);
7531
8145
  PAGE_TO_FOCUS_REQUEST_OWNER.set(pageOf(element.ownerDocument), { editor: new WeakRef(editor) });
7532
8146
  };
8147
+ const isAncestorChainActive = (node) => {
8148
+ let current = node;
8149
+ while (current) {
8150
+ const tree = current.getRootNode();
8151
+ if (tree.activeElement !== current) return false;
8152
+ current = "host" in tree ? tree.host : tree.defaultView?.frameElement ?? null;
8153
+ }
8154
+ return true;
8155
+ };
8156
+ const focusEnclosingFrames = (el) => {
8157
+ const frames = [];
8158
+ for (let frame = el.ownerDocument.defaultView?.frameElement; frame; frame = frame.ownerDocument.defaultView?.frameElement) if ("focus" in frame && typeof frame.focus === "function") frames.push(frame);
8159
+ for (let i = frames.length - 1; i >= 0; i -= 1) {
8160
+ const frame = frames[i];
8161
+ const frameDoc = "contentDocument" in frame ? frame.contentDocument : null;
8162
+ const expectedChild = i > 0 ? frames[i - 1] : el;
8163
+ const childBefore = frameDoc?.activeElement ?? null;
8164
+ if (isAncestorChainActive(frame)) continue;
8165
+ frame.focus({ preventScroll: true });
8166
+ if (!isAncestorChainActive(frame)) return false;
8167
+ const childAfter = frameDoc?.activeElement ?? null;
8168
+ if (childAfter && childAfter !== childBefore && childAfter !== expectedChild && childAfter !== frameDoc?.body && childAfter !== frameDoc?.documentElement) return false;
8169
+ }
8170
+ return true;
8171
+ };
8172
+ const focusEditableElement = (editor, el) => {
8173
+ if (!focusEnclosingFrames(el)) return false;
8174
+ IS_FOCUSED.set(editor, true);
8175
+ setEditorFocused(editor, true);
8176
+ el.focus({ preventScroll: true });
8177
+ if (isElementFocused(el)) return true;
8178
+ IS_FOCUSED.delete(editor);
8179
+ setEditorFocused(editor, false);
8180
+ return false;
8181
+ };
7533
8182
  const getLastChildren = (element) => {
7534
8183
  if (element.childElementCount > 0) return getLastChildren(element.children[0]);
7535
8184
  return element;
@@ -7643,15 +8292,58 @@ const setEditorDOMScrollElement = (editor, element, { fallback = false } = {}) =
7643
8292
  if (setWeakElement(fallback ? EDITOR_TO_DOM_FALLBACK_SCROLL : EDITOR_TO_DOM_SCROLL, owner, element)) notifyEditorDOMScopeListeners(owner);
7644
8293
  };
7645
8294
  const ELEMENT_TO_ROOT_REVEAL = /* @__PURE__ */ new WeakMap();
8295
+ const VIEW_TO_SCROLL_TOKEN = /* @__PURE__ */ new WeakMap();
8296
+ const nextScrollIntoViewToken = (scope) => {
8297
+ const token = (VIEW_TO_SCROLL_TOKEN.get(scope) ?? 0) + 1;
8298
+ VIEW_TO_SCROLL_TOKEN.set(scope, token);
8299
+ return token;
8300
+ };
8301
+ const getScrollIntoViewScope = (editor, fallback) => hasEditorRuntime(editor) ? getOwnViewPresentation(editor) ?? documentOf(editor) : fallback;
8302
+ const findMountedAncestorRevealStep = (editor, targetRoot) => {
8303
+ if (!hasEditorRuntime(editor)) return null;
8304
+ const owner = getEditorRuntimeOwner(editor);
8305
+ const entryByRoot = new Map(readRootEntries(owner).map((entry) => [entry.root, entry]));
8306
+ const visited = /* @__PURE__ */ new Set([targetRoot]);
8307
+ const queue = [targetRoot];
8308
+ for (const currentRoot of queue) {
8309
+ const entry = entryByRoot.get(currentRoot);
8310
+ if (!entry) continue;
8311
+ for (const edge of entry.owners) {
8312
+ const parentRoot = toInternalRoot(edge.root);
8313
+ const mountedParent = resolveMountedViewForRoot(editor, parentRoot);
8314
+ if (mountedParent) return {
8315
+ ownerPath: edge.path,
8316
+ ownerRoot: parentRoot,
8317
+ ownerView: mountedParent
8318
+ };
8319
+ if (!visited.has(parentRoot)) {
8320
+ visited.add(parentRoot);
8321
+ queue.push(parentRoot);
8322
+ }
8323
+ }
8324
+ }
8325
+ return null;
8326
+ };
8327
+ const getScrollTargetRoot = (editor, target) => {
8328
+ if (!PathApi.isPath(target) && !PointApi.isPoint(target) && !RangeApi.isRange(target)) return null;
8329
+ const explicitRoot = getPublicExplicitLocationRoot(target);
8330
+ if (explicitRoot !== void 0) return toInternalRoot(explicitRoot);
8331
+ if (hasEditorRuntime(editor)) return getEditorRuntimeRoot(editor);
8332
+ return null;
8333
+ };
7646
8334
  const setEditableRootReveal = (element, reveal) => {
7647
- ELEMENT_TO_ROOT_REVEAL.set(element, reveal);
8335
+ const registration = typeof reveal === "function" ? {
8336
+ revealCulled: reveal,
8337
+ revealMounted: reveal
8338
+ } : reveal;
8339
+ ELEMENT_TO_ROOT_REVEAL.set(element, registration);
7648
8340
  return () => {
7649
- if (ELEMENT_TO_ROOT_REVEAL.get(element) === reveal) ELEMENT_TO_ROOT_REVEAL.delete(element);
8341
+ if (ELEMENT_TO_ROOT_REVEAL.get(element) === registration) ELEMENT_TO_ROOT_REVEAL.delete(element);
7650
8342
  };
7651
8343
  };
7652
8344
  const revealInEditableRoot = (element, path) => {
7653
8345
  const root = element.closest("[data-editor-root]");
7654
- if (root) ELEMENT_TO_ROOT_REVEAL.get(root)?.(path, "auto");
8346
+ if (root) ELEMENT_TO_ROOT_REVEAL.get(root)?.revealMounted?.(path, "auto");
7655
8347
  };
7656
8348
  const getEditorDOMHostScrollElement = (editor) => EDITOR_TO_DOM_SCROLL.get(documentOf(editor)) ?? null;
7657
8349
  const getRegisteredScrollElement = (editor) => getEditorDOMHostScrollElement(editor) ?? EDITOR_TO_DOM_FALLBACK_SCROLL.get(editor) ?? EDITOR_TO_DOM_FALLBACK_SCROLL.get(documentOf(editor));
@@ -7863,6 +8555,11 @@ const resolveDOMRangeInRoot = (editor, range, root, { checkPageText = false, exp
7863
8555
  }
7864
8556
  return domRange;
7865
8557
  };
8558
+ const isTargetInsideVoid = (editor, target) => {
8559
+ if (!DOMEditor.hasTarget(editor, target)) return false;
8560
+ const editorNode = DOMEditor.resolveNode(editor, target);
8561
+ return !!editorNode && NodeApi.isElement(editorNode) && isVoid$2(editor, editorNode);
8562
+ };
7866
8563
  const DOMEditorImpl = {
7867
8564
  androidPendingDiffs: (editor) => EDITOR_TO_PENDING_DIFFS.get(editor),
7868
8565
  androidScheduleFlush: (editor) => {
@@ -7881,8 +8578,11 @@ const DOMEditorImpl = {
7881
8578
  },
7882
8579
  deselect: (editor) => {
7883
8580
  const selection = editor.read((state) => state.selection());
7884
- const root = DOMEditor.resolveDocumentOrShadowRoot(editor);
7885
- if (root) writeDOMSelection(root, null);
8581
+ const el = DOMEditor.editable(editor);
8582
+ if (el) clearEditableDOMSelection(el, {
8583
+ editor,
8584
+ policy: "owned"
8585
+ });
7886
8586
  if (selection) editor.update((tx) => {
7887
8587
  tx.selection.set(null);
7888
8588
  });
@@ -7970,11 +8670,6 @@ const DOMEditorImpl = {
7970
8670
  if (retries <= 0) return;
7971
8671
  PAGE_TO_FOCUS_REQUEST_OWNER.set(pageOf(el.ownerDocument), { editor: new WeakRef(editor) });
7972
8672
  const superseded = watchFocusSuperseded(editor, el);
7973
- const markAndFocus = () => {
7974
- IS_FOCUSED.set(editor, true);
7975
- setEditorFocused(editor, true);
7976
- el.focus({ preventScroll: true });
7977
- };
7978
8673
  if (IS_NODE_MAP_DIRTY.get(editor)) {
7979
8674
  let cancel = () => {};
7980
8675
  const generation = getPlacementGeneration(editor);
@@ -7991,25 +8686,38 @@ const DOMEditorImpl = {
7991
8686
  return;
7992
8687
  }
7993
8688
  if (findDOMRootRuntime(el)?.focusSelection(el)) return;
8689
+ const activeBeforeCaret = focusedElementOnPage(el);
7994
8690
  const selection = ensureFocusCaret(editor, el);
7995
- if (superseded()) return;
8691
+ if (superseded() || movedFocusElsewhere(el, activeBeforeCaret, focusedElementOnPage(el))) return;
8692
+ const focusPlacement = getPlacementGeneration(editor);
7996
8693
  const selectionAtFocus = selection ? getSelectionDOMRange(editor, selection) : null;
7997
8694
  const syncDomSelection = () => {
7998
8695
  if (findDOMRootRuntime(el)?.isSelectionHeld()) return;
7999
8696
  const innerSelection = resolveNextKeyCaret(editor, el);
8000
- if (innerSelection) {
8001
- const projectedSelection = getSelectionDOMRange(editor, innerSelection);
8002
- if (!projectedSelection) {
8003
- writeDOMSelection(root, null);
8004
- return;
8005
- }
8006
- const view = reachAt(editor, projectedSelection);
8007
- const domRange = view && resolveDOMRangeInRoot(view, projectedSelection, void 0, {
8008
- exportingSelection: true,
8009
- rejectStaleText: true
8010
- });
8011
- if (domRange) writeDOMSelection(root, getDOMRangeSelectionPoints(domRange, RangeApi.isBackward(projectedSelection)));
8697
+ if (!innerSelection) return;
8698
+ const projectedSelection = getSelectionDOMRange(editor, innerSelection);
8699
+ const view = projectedSelection ? reachAt(editor, projectedSelection) : null;
8700
+ const targetEditable = (view && view !== editor ? DOMEditor.editable(view) : null) ?? el;
8701
+ const targetRuntime = findDOMRootRuntime(targetEditable);
8702
+ if (targetRuntime?.isSelectionHeld()) return;
8703
+ if (targetRuntime?.exportSelection({
8704
+ coverageMode: "model-only",
8705
+ forceModelExport: true,
8706
+ requireFocused: true,
8707
+ skipScroll: true
8708
+ }) !== void 0) return;
8709
+ if (!projectedSelection) {
8710
+ clearEditableDOMSelection(el, { editor });
8711
+ return;
8012
8712
  }
8713
+ const domRange = view && resolveDOMRangeInRoot(view, projectedSelection, void 0, {
8714
+ exportingSelection: true,
8715
+ rejectStaleText: true
8716
+ });
8717
+ if (domRange) writeEditableDOMSelection(targetEditable, getDOMRangeSelectionPoints(domRange, RangeApi.isBackward(projectedSelection)), {
8718
+ editor: view ?? editor,
8719
+ policy: "focused"
8720
+ });
8013
8721
  };
8014
8722
  const trySyncDomSelection = () => {
8015
8723
  try {
@@ -8026,18 +8734,20 @@ const DOMEditorImpl = {
8026
8734
  const rootActiveElement = root.activeElement;
8027
8735
  const shadowHost = "host" in root ? root.host : null;
8028
8736
  const activeElement = rootActiveElement ?? (root === el.ownerDocument ? null : el.ownerDocument.activeElement);
8029
- if (activeElement === el) {
8737
+ if (isElementFocused(el)) {
8738
+ if (placedSince(editor, focusPlacement)) return;
8030
8739
  trySyncDomSelection();
8031
8740
  return;
8032
8741
  }
8033
- if (activeElement?.isConnected && containsShadowAware(el, activeElement)) {
8742
+ if (activeElement && activeElement !== el && activeElement.isConnected && containsShadowAware(el, activeElement)) {
8034
8743
  ownedActiveElement = activeElement;
8035
8744
  return;
8036
8745
  }
8037
- if (!(activeElement === null || activeElement === el.ownerDocument.body || rootActiveElement === null && activeElement === shadowHost || activeElement === ownedActiveElement && !activeElement.isConnected)) return;
8038
- markAndFocus();
8746
+ const pageActive = focusedElementOnPage(el);
8747
+ if (!(pageActive === null || pageActive === pageActive.ownerDocument.body || rootActiveElement === null && activeElement === shadowHost || activeElement !== null && activeElement === ownedActiveElement && !activeElement.isConnected)) return;
8748
+ const focused = focusEditableElement(editor, el);
8039
8749
  if (superseded()) return;
8040
- trySyncDomSelection();
8750
+ if (focused) trySyncDomSelection();
8041
8751
  };
8042
8752
  const scheduleFocusSettle = () => {
8043
8753
  scheduleEditorDOMPhase(editor, "dom-write", "dom-editor-focus-settle-microtask", settleFocus, {
@@ -8054,15 +8764,16 @@ const DOMEditorImpl = {
8054
8764
  timing: "timeout"
8055
8765
  });
8056
8766
  };
8057
- if (root.activeElement !== el) {
8767
+ if (!isElementFocused(el)) {
8058
8768
  const { activeElement } = root;
8059
- if (isDOMElement(activeElement) && containsShadowAware(el, activeElement) && "blur" in activeElement && typeof activeElement.blur === "function") {
8769
+ if (isDOMElement(activeElement) && activeElement !== el && containsShadowAware(el, activeElement) && "blur" in activeElement && typeof activeElement.blur === "function") {
8770
+ const activeBeforeBlur = focusedElementOnPage(el);
8060
8771
  activeElement.blur();
8061
- if (superseded()) return;
8772
+ if (superseded() || movedFocusElsewhere(el, activeBeforeBlur, focusedElementOnPage(el))) return;
8062
8773
  }
8063
- markAndFocus();
8774
+ const focused = focusEditableElement(editor, el);
8064
8775
  if (superseded()) return;
8065
- trySyncDomSelection();
8776
+ if (focused) trySyncDomSelection();
8066
8777
  if (selectionAtFocus) scheduleEditorDOMPhase(editor, "selection-repair", "dom-editor-focus-selection-sync", () => {
8067
8778
  if (superseded() || !isElementFocused(el)) return;
8068
8779
  const currentSelection = getSelectionDOMRange(editor, resolveNextKeyCaret(editor, el));
@@ -8102,7 +8813,7 @@ const DOMEditorImpl = {
8102
8813
  },
8103
8814
  hasEditableTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target, { editable: true }),
8104
8815
  hasRange: (editor, { anchor, focus }) => hasPointPath(editor, anchor) && hasPointPath(editor, focus),
8105
- hasSelectableTarget: (editor, target) => DOMEditor.hasEditableTarget(editor, target) || DOMEditor.isTargetInsideNonReadonlyVoid(editor, target) || DOMEditor.hasTarget(editor, target) && isSoftLineEndTarget(target),
8816
+ hasSelectableTarget: (editor, target) => DOMEditor.hasEditableTarget(editor, target) || isTargetInsideVoid(editor, target) || DOMEditor.hasTarget(editor, target) && isSoftLineEndTarget(target),
8106
8817
  hasTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target),
8107
8818
  clipboard: {
8108
8819
  insertData: (editor, data) => insertDOMData(editor, data),
@@ -8115,12 +8826,7 @@ const DOMEditorImpl = {
8115
8826
  isComposing: (editor) => !!IS_COMPOSING.get(editor),
8116
8827
  isFocused: (editor) => !!IS_FOCUSED.get(editor),
8117
8828
  isReadOnly: (editor) => !!IS_READ_ONLY.get(editor),
8118
- isTargetInsideNonReadonlyVoid: (editor, target) => {
8119
- if (IS_READ_ONLY.get(editor)) return false;
8120
- if (!DOMEditor.hasTarget(editor, target)) return false;
8121
- const editorNode = DOMEditor.resolveNode(editor, target);
8122
- return !!editorNode && NodeApi.isElement(editorNode) && isVoid$2(editor, editorNode);
8123
- },
8829
+ isTargetInsideNonReadonlyVoid: (editor, target) => !IS_READ_ONLY.get(editor) && isTargetInsideVoid(editor, target),
8124
8830
  resolveDOMNode: (editor, nodeOrKey) => {
8125
8831
  if (nodeOrKey === editor) return DOMEditor.editable(editor);
8126
8832
  if (DOMEditor.editable(editor)?.isConnected !== true) return null;
@@ -8184,82 +8890,163 @@ const DOMEditorImpl = {
8184
8890
  },
8185
8891
  scroll: (editor) => getRegisteredScrollElement(editor) ?? DOMEditor.root(editor) ?? DOMEditor.editable(editor) ?? null,
8186
8892
  scrollIntoView: (editor, target, options = { scrollMode: "if-needed" }) => {
8187
- const usesDefaultReveal = typeof options === "object" && options !== null && (options.scrollMode === void 0 || options.scrollMode === "if-needed") && options.block === void 0 && options.inline === void 0 && options.behavior === void 0 && options.boundary === void 0 && options.skipOverflowHiddenElements === void 0;
8188
- const requestedScrollMarginTop = PathApi.isPath(target) ? (() => {
8189
- const node = editor.read((state) => state.nodes.get(target)?.[0]);
8190
- const element = node ? DOMEditor.resolveDOMNode(editor, node) : null;
8191
- const window = element?.ownerDocument?.defaultView;
8192
- if (!element || !window) return 0;
8893
+ const usesDefaultReveal = isDefaultScrollRevealOptions(options);
8894
+ const readScrollMarginTop = (element) => {
8895
+ const window = element.ownerDocument?.defaultView;
8896
+ if (!window) return 0;
8193
8897
  const style = window.getComputedStyle(element);
8194
8898
  return Number.parseFloat(element.style.scrollMarginTop || style.scrollMarginTop) || 0;
8195
- })() : 0;
8899
+ };
8900
+ const canReadEditor = typeof editor.read === "function";
8901
+ const isLocationTarget = PathApi.isPath(target) || PointApi.isPoint(target) || RangeApi.isRange(target);
8902
+ const targetRoot = canReadEditor ? getScrollTargetRoot(editor, target) : null;
8903
+ const resolveTargetView = () => {
8904
+ if (!canReadEditor) return editor;
8905
+ if (isLocationTarget) return reachAt(editor, target) ?? (targetRoot ? resolveMountedViewForRoot(editor, targetRoot) : null);
8906
+ return hasMountedDocumentView(editor) ? resolveDOMReach(editor) : editor;
8907
+ };
8908
+ const initialView = resolveTargetView();
8909
+ const initialAncestorStep = !initialView && targetRoot ? findMountedAncestorRevealStep(editor, targetRoot) : null;
8910
+ const initialSchedulerView = initialView ?? initialAncestorStep?.ownerView ?? null;
8911
+ if (!initialSchedulerView) return () => {};
8912
+ const scrollScope = getScrollIntoViewScope(editor, initialSchedulerView);
8913
+ const scrollToken = nextScrollIntoViewToken(scrollScope);
8914
+ const isStale = () => cancelled || VIEW_TO_SCROLL_TOKEN.get(scrollScope) !== scrollToken;
8915
+ const initialPathElement = initialView && PathApi.isPath(target) && typeof initialView.read === "function" ? (() => {
8916
+ const node = initialView.read((state) => state.nodes.get(target)?.[0]);
8917
+ return node ? DOMEditor.resolveDOMNode(initialView, node) : null;
8918
+ })() : null;
8919
+ const initialScrollMarginTop = initialPathElement ? readScrollMarginTop(initialPathElement) : 0;
8920
+ const resolveCulledPaths = (view) => {
8921
+ if (PathApi.isPath(target)) return [target];
8922
+ if (PointApi.isPoint(target)) return [target.path];
8923
+ if (!RangeApi.isRange(target)) return [];
8924
+ const startPath = RangeApi.start(target).path;
8925
+ const endPath = RangeApi.end(target).path;
8926
+ if (PathApi.equals(startPath, endPath) || typeof view.read !== "function") return [startPath];
8927
+ const missing = [];
8928
+ const startNode = view.read((state) => state.nodes.get(startPath)?.[0]);
8929
+ const endNode = view.read((state) => state.nodes.get(endPath)?.[0]);
8930
+ if (!startNode || !DOMEditor.resolveDOMNode(view, startNode)) missing.push(startPath);
8931
+ if (!endNode || !DOMEditor.resolveDOMNode(view, endNode)) missing.push(endPath);
8932
+ return missing.length > 0 ? missing : [startPath];
8933
+ };
8934
+ const alwaysMode = typeof options === "object" && options?.scrollMode === "always";
8935
+ const schedulePhase = (schedulerView, label, callback) => scheduleEditorDOMPhase(schedulerView, alwaysMode ? "post-selection" : "dom-write", label, callback, {
8936
+ key: "dom-editor-scroll-into-view",
8937
+ timing: "animation-frame"
8938
+ });
8939
+ let cancelled = false;
8940
+ let retriedTarget = false;
8941
+ const revealedAncestors = /* @__PURE__ */ new Set();
8942
+ let cancelRetry;
8943
+ const revealCulledOnView = (view, paths) => {
8944
+ if (paths.length === 0) return false;
8945
+ const editable = EDITOR_TO_ELEMENT.get(view) ?? (typeof view.read === "function" ? DOMEditorImpl.editable(view) : null);
8946
+ const reveal = editable ? ELEMENT_TO_ROOT_REVEAL.get(editable)?.revealCulled : void 0;
8947
+ if (!reveal) return false;
8948
+ let revealed = false;
8949
+ for (const path of paths) {
8950
+ if (reveal(path, "auto") === true) revealed = true;
8951
+ if (isStale()) return false;
8952
+ }
8953
+ return revealed;
8954
+ };
8955
+ const retryAfterTargetReveal = (view) => {
8956
+ if (isStale() || retriedTarget) return;
8957
+ const paths = resolveCulledPaths(view);
8958
+ if (!revealCulledOnView(view, paths) || isStale()) return;
8959
+ retriedTarget = true;
8960
+ cancelRetry = schedulePhase(view, "dom-editor-scroll-into-view-retry", run);
8961
+ };
8196
8962
  const run = () => {
8963
+ if (isStale()) return;
8964
+ const activeView = resolveTargetView();
8965
+ if (!activeView) {
8966
+ if (!targetRoot) return;
8967
+ const step = findMountedAncestorRevealStep(editor, targetRoot);
8968
+ if (!step) return;
8969
+ const stepKey = `${step.ownerRoot}:${step.ownerPath.join(".")}`;
8970
+ if (revealedAncestors.has(stepKey)) return;
8971
+ revealedAncestors.add(stepKey);
8972
+ if (!revealCulledOnView(step.ownerView, [step.ownerPath]) || isStale()) return;
8973
+ cancelRetry = schedulePhase(step.ownerView, "dom-editor-scroll-into-view-ancestor-retry", run);
8974
+ return;
8975
+ }
8976
+ const canReadActiveView = typeof activeView.read === "function";
8197
8977
  if (PathApi.isPath(target)) {
8198
- const node = editor.read((state) => state.nodes.get(target)?.[0]);
8199
- const element = node ? DOMEditor.resolveDOMNode(editor, node) : null;
8200
- if (element) {
8201
- revealInEditableRoot(element, target);
8202
- const scrollElement = getRegisteredScrollElement(editor);
8203
- if (scrollElement && requestedScrollMarginTop > 0 && typeof options === "object" && options.block === "start" && options.scrollMode === "always") {
8204
- const elementRect = element.getBoundingClientRect();
8205
- const scrollRect = scrollElement.getBoundingClientRect();
8206
- scrollElement.scroll({
8207
- behavior: options.behavior ?? "auto",
8208
- left: scrollElement.scrollLeft,
8209
- top: scrollElement.scrollTop + elementRect.top - scrollRect.top - requestedScrollMarginTop
8210
- });
8211
- } else if (usesDefaultReveal) {
8212
- const rect = element.getBoundingClientRect();
8213
- if (isUsableScrollRect(rect)) scrollRectIntoViewIfNeeded({
8214
- rect: toScrollRect(rect),
8215
- startElement: element
8216
- });
8217
- } else scrollIntoViewIfNeeded(element, options);
8978
+ const node = canReadActiveView ? activeView.read((state) => state.nodes.get(target)?.[0]) : void 0;
8979
+ const element = node ? DOMEditor.resolveDOMNode(activeView, node) : null;
8980
+ if (!element) {
8981
+ retryAfterTargetReveal(activeView);
8982
+ return;
8983
+ }
8984
+ revealInEditableRoot(element, target);
8985
+ const scrollElement = getRegisteredScrollElement(activeView);
8986
+ const requestedScrollMarginTop = initialPathElement ? initialScrollMarginTop : readScrollMarginTop(element);
8987
+ if (scrollElement && requestedScrollMarginTop > 0 && typeof options === "object" && options.block === "start" && options.scrollMode === "always") {
8988
+ const elementRect = element.getBoundingClientRect();
8989
+ const scrollRect = scrollElement.getBoundingClientRect();
8990
+ scrollElement.scroll({
8991
+ behavior: options.behavior ?? "auto",
8992
+ left: scrollElement.scrollLeft,
8993
+ top: scrollElement.scrollTop + elementRect.top - scrollRect.top - requestedScrollMarginTop
8994
+ });
8995
+ } else {
8996
+ const rect = element.getBoundingClientRect();
8997
+ if (isUsableScrollRect(rect)) scrollRectIntoView({
8998
+ options,
8999
+ rect: toScrollRect(rect),
9000
+ scrollMarginTop: requestedScrollMarginTop,
9001
+ startElement: element
9002
+ });
8218
9003
  }
8219
9004
  return;
8220
9005
  }
8221
- const domRange = PointApi.isPoint(target) ? DOMEditor.resolveDOMRange(editor, {
9006
+ const domRange = PointApi.isPoint(target) ? DOMEditor.resolveDOMRange(activeView, {
8222
9007
  anchor: target,
8223
9008
  focus: target
8224
- }) : RangeApi.isRange(target) ? DOMEditor.resolveDOMRange(editor, target) : target;
8225
- if (!domRange) return;
9009
+ }) : RangeApi.isRange(target) ? DOMEditor.resolveDOMRange(activeView, target) : target;
9010
+ if (!domRange) {
9011
+ retryAfterTargetReveal(activeView);
9012
+ return;
9013
+ }
8226
9014
  const leafElement = isDOMElement(domRange.startContainer) ? domRange.startContainer : domRange.startContainer.parentElement;
8227
9015
  if (!leafElement) return;
8228
9016
  if (PointApi.isPoint(target)) revealInEditableRoot(leafElement, target.path);
8229
9017
  else if (RangeApi.isRange(target)) revealInEditableRoot(leafElement, RangeApi.start(target).path);
8230
9018
  if (usesDefaultReveal) {
8231
9019
  const range = RangeApi.isRange(target) ? target : PointApi.isPoint(target) ? null : editor.read((state) => state.selection());
8232
- scrollDOMRangeIntoViewIfNeeded(domRange, Boolean(range && RangeApi.isBackward(range)));
9020
+ scrollDOMRangeFocusIntoViewIfNeeded(domRange, Boolean(range && RangeApi.isBackward(range)));
8233
9021
  return;
8234
9022
  }
8235
- const hadOwnRect = Object.hasOwn(leafElement, "getBoundingClientRect");
8236
- const originalGetBoundingClientRect = leafElement.getBoundingClientRect;
8237
- leafElement.getBoundingClientRect = () => {
8238
- const rangeRect = domRange.getBoundingClientRect();
8239
- return isUsableScrollRect(rangeRect) ? rangeRect : originalGetBoundingClientRect.call(leafElement);
8240
- };
8241
- try {
8242
- scrollIntoViewIfNeeded(leafElement, options);
8243
- } finally {
8244
- if (hadOwnRect) leafElement.getBoundingClientRect = originalGetBoundingClientRect;
8245
- else Reflect.deleteProperty(leafElement, "getBoundingClientRect");
8246
- }
9023
+ const rangeRect = typeof domRange.getBoundingClientRect === "function" ? domRange.getBoundingClientRect() : null;
9024
+ const baseRect = rangeRect && isUsableScrollRect(rangeRect) ? rangeRect : leafElement.getBoundingClientRect();
9025
+ if (!isUsableScrollRect(baseRect)) return;
9026
+ scrollRectIntoView({
9027
+ options,
9028
+ rect: toScrollRect(baseRect),
9029
+ startElement: leafElement
9030
+ });
8247
9031
  };
8248
- if (typeof options !== "object" || options.scrollMode !== "always") return scheduleEditorDOMPhase(editor, "dom-write", "dom-editor-scroll-into-view", run, {
8249
- key: "dom-editor-scroll-into-view",
8250
- timing: "animation-frame"
8251
- });
8252
- const scheduleNavigation = (label, callback) => scheduleEditorDOMPhase(editor, "post-selection", label, callback, {
8253
- key: "dom-editor-scroll-into-view",
8254
- timing: "animation-frame"
8255
- });
9032
+ if (!alwaysMode) {
9033
+ const cancelInitial = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view", run);
9034
+ return () => {
9035
+ cancelled = true;
9036
+ cancelInitial();
9037
+ cancelRetry?.();
9038
+ };
9039
+ }
8256
9040
  let cancelScroll;
8257
- const cancelSettle = scheduleNavigation("dom-editor-scroll-into-view-settle", () => {
8258
- cancelScroll = scheduleNavigation("dom-editor-scroll-into-view", run);
9041
+ const cancelSettle = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view-settle", () => {
9042
+ if (cancelled) return;
9043
+ cancelScroll = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view", run);
8259
9044
  });
8260
9045
  return () => {
9046
+ cancelled = true;
8261
9047
  cancelSettle();
8262
9048
  cancelScroll?.();
9049
+ cancelRetry?.();
8263
9050
  };
8264
9051
  },
8265
9052
  resolveNode: (editor, domNode) => {
@@ -9371,7 +10158,11 @@ function isHotkey(hotkey, optionsOrEvent, event) {
9371
10158
  const targetEvent = isKeyboardEventLike(optionsOrEvent) ? optionsOrEvent : event;
9372
10159
  const options = isKeyboardEventLike(optionsOrEvent) ? void 0 : optionsOrEvent;
9373
10160
  if (!targetEvent) throw new TypeError("isHotkey requires a keyboard event");
9374
- return getCachedHotkeyMatcher(hotkey, options ?? { platform: usesAppleDOMHotkeys(targetEvent) ? "apple" : "other" })(targetEvent);
10161
+ const rawPlatform = options?.platform;
10162
+ return getCachedHotkeyMatcher(hotkey, {
10163
+ ignoreModifiers: options?.ignoreModifiers,
10164
+ platform: rawPlatform ?? (usesAppleDOMHotkeys(targetEvent) ? "apple" : "other")
10165
+ })(targetEvent);
9375
10166
  }
9376
10167
  //#endregion
9377
10168
  //#region src/dom/utils/hotkeys.ts
@@ -9517,4 +10308,4 @@ const keyToDataAttribute = (key) => `data-editor-${toKebabCase(key)}`;
9517
10308
  /** Return DOM data attribute names that mirror primitive node properties. */
9518
10309
  const getNodeDataAttributeKeys = (node) => Object.keys(node).filter((key) => typeof node[key] !== "object" && (!TextApi.isText(node) || key !== "text")).map((key) => keyToDataAttribute(key));
9519
10310
  //#endregion
9520
- export { getDragAutoScrollTarget as $, EDITOR_TO_FORCE_RENDER as $n, scheduleEditorDOMPhase as $t, createDOMEditorCapability as A, getPliteStringDocumentOffset as An, isBefore as Ar, SOFT_LINE_END_SELECTOR as At, setEditableRootReveal as B, isDOMTextFlowSegmentSynchronized as Bn, readClipboardCut as Br, findMountedDOMNodeByPath as Bt, normalizeRange as C, usesAppleDOMHotkeys as Cn, containsShadowAware as Cr, writeDOMFragmentData as Ct, DOMEditor as D, getOwnedPliteTextStrings as Dn, getSelection as Dr, writeDataTransferFragment as Dt, verifyDiffState as E, getNearestPliteStringRect as En, getFlatTreeParentElement as Er, observeDataTransferInsertion as Et, isSelectableDOMSelection as F, getPliteTextHostBounds as Fn, isDOMSelection as Fr, noteAfterInsertCaret as Ft, supersedeFocusRequest as G, resolveDOMTextFlowOffset as Gn, focusedElementOnPage as Gt, setEditorDOMRootElement as H, releaseDOMTextFlowRecordIndex as Hn, DOMRootRuntime as Ht, isTrackedMutation as I, getPliteTextHostStrings as In, isDOMText as Ir, readAfterInsertCaret as It, ensureFocusCaret as J, setDOMTextFlowRecordIndex as Jn, resolveDOMReach as Jt, watchFocusSuperseded as K, resolveDOMTextFlowRecordDOMText as Kn, getEditorDOMRoot as Kt, resolveDOMPointInRoot as L, getTextFlowPointAtCoordinates as Ln, isPlainTextOnlyPaste as Lr, readLowerSoftLineEnd as Lt, getEditorDOMHostScrollElement as M, getPliteStringLength as Mn, isDOMHTMLElement as Mr, clearAfterInsertCaret as Mt, getOrCreateDOMNodeKey as N, getPliteStringPlacementAtX as Nn, isDOMInputOrTextArea as Nr, isSoftLineEndBetween as Nt, DOMResolutionError as O, getPliteStringCoordinatePlacement as On, hasShadowRoot as Or, Key as Ot, isFocusRequestedElsewhere as P, getPliteStringPlacementDOMPoint as Pn, isDOMNode as Pr, isSoftLineTextStale as Pt, resolveBlockFragmentDropRange as Q, EDITOR_TO_ELEMENT as Qn, watchDOMSyncTextMarks as Qt, resolveDOMRangeInRoot as R, getUsableRangeRects as Rn, markPlainTextPaste as Rr, recordSoftLineEnd as Rt, normalizePoint as S, supportsDOMBeforeInput as Sn, closestShadowAware as Sr, writeDOMDataTransferFragment as St, targetRange as T, createDOMGeometryKernel as Tn, getDefaultView as Tr, dataTransferFormats as Tt, setEditorDOMScrollElement as U, resolveDOMTextFlowEntry as Un, findDOMRootRuntime as Ut, setEditorDOMEditableElement as V, readDOMTextFlowPaint as Vn, writeClipboardCut as Vr, resolvePliteNodePath as Vt, subscribeEditorDOMScope as W, resolveDOMTextFlowInsertTarget as Wn, findEditorDOMRootRuntime as Wt, resolveNextKeyCaret as X, DOMCoverage as Xn, isDOMSyncMutation as Xt, liftCaretOutOfCollapsedSection as Y, setDOMTextFlowRecordIndexes as Yn, resolveDOMTargetView as Yt, eventCarriesBlockFragment as Z, isCollapsedDOMCoverageBoundary as Zn, markDOMSyncMutationTarget as Zt, TRIPLE_CLICK as _, hasDOMHostQuirk as _n, IS_NODE_MAP_DIRTY as _r, readDropIndicator as _t, isLeaf as a, readDOMSelectionPoints as an, EDITOR_TO_PLACEHOLDER_ELEMENT as ar, resolveDOMDropTarget as at, longestCommonPrefixLength as b, isGeckoDOMHost as bn, NODE_TO_INDEX as br, domCommands as bt, isText as c, readsSelectionAsHost as cn, EDITOR_TO_RUNTIME_ID_TO_KEY as cr, cancelDragRest as ct, Hotkeys as d, writeDOMSelection as dn, EDITOR_TO_USER_SELECTION as dr, isDragSessionClaimed as dt, changeDOMSelection as en, EDITOR_TO_KEY_TO_ELEMENT as er, intersectClipChain as et, getLineBoundaryKeyboardMove as f, writeUserDOMSelection as fn, EDITOR_TO_WINDOW as fr, readDragSession as ft, isHotkey as g, getDOMHostLanguage as gn, IS_FOCUSED as gr, publishDropIndicator as gt, createCompiledHotkeyMatcher as h, CAN_USE_DOM as hn, IS_COMPOSING as hr, takeDragSession as ht, isElement as i, isDOMSelectionWriteEcho as in, EDITOR_TO_PENDING_SELECTION as ir, pointAt as it, findDOMPointElementInRoot as j, getPliteStringEdgeOffset as jn, isDOMElement as jr, SOFT_LINE_FLAG as jt, claimFocusRequest as k, getPliteStringDirectPlacement as kn, isAfter as kr, SOFT_LINE_END as kt, isVoid as l, recordDOMSelection as ln, EDITOR_TO_SCHEDULE_FLUSH as lr, clearDragScrollRepaint as lt, ariaKeyShortcuts as m, selectDOMInputDefaultActionPhase as mn, ELEMENT_TO_NODE as mr, settleDragSession as mt, getNodeDataAttributeKeys as n, forgetDOMSelectionRecordWithin as nn, EDITOR_TO_PENDING_DIFFS as nr, copyIntentOf as nt, isNode as o, readDOMSelectionRange as on, EDITOR_TO_ROOT_VIEW_EDITORS as or, restDOMBlockDrag as ot, isPasteWithoutFormatting as p, enableKernelTraceRetention as pn, ELEMENT_TO_EDITOR as pr, setDragScrollRepaint as pt, writeViewSelectionPart as q, resolveDOMTextFlowRecordText as qn, isElementFocused as qt, isEditor as r, getDOMRangeSelectionPoints as rn, EDITOR_TO_PENDING_INSERTION_MARKS as rr, indicateDOMDropTarget as rt, isString as s, readDOMSelectionRecord as sn, EDITOR_TO_RUNTIME_ID_TO_ELEMENTS as sr, beginDragSession as st, getElements as t, forgetDOMSelectionRecord as tn, EDITOR_TO_PENDING_ACTION as tr, walkClipChain as tt, keyToDataAttribute as u, sameDOMSelectionPoints as un, EDITOR_TO_USER_MARKS as ur, clearDragSession as ut, dom as v, isAndroidDOMHost as vn, IS_READ_ONLY as vr, subscribeDropIndicator as vt, normalizeStringDiff as w, caretShowsPointOffTextFlowCharacters as wn, getActiveElement as wr, writeDOMRangeData as wt, mergeStringDiffs as x, isWebKitDOMHost as xn, NODE_TO_PARENT as xr, getDOMClipboardFormatKey as xt, applyStringDiff as y, isBlinkDOMHost as yn, NODE_TO_ELEMENT as yr, cleanDOMClipboardContents as yt, resolveWrittenDOMRange as z, hasUsableDOMRect as zn, normalizeDOMPoint as zr, resolveSoftLineEndDOMPoint as zt };
10311
+ export { eventCarriesBlockFragment as $, getDOMTextFlowRestoreSegments as $n, normalizeDOMPoint as $r, hasMountedDOMRoot as $t, createDOMEditorCapability as A, isAndroidDOMHost as An, IS_FOCUSED as Ar, SOFT_LINE_END as At, resolveWrittenDOMRange as B, getPliteStringCoordinatePlacement as Bn, getFlatTreeParentElement as Br, resolveSoftLineEndDOMPoint as Bt, normalizeRange as C, readsSelectionAsHost as Cn, EDITOR_TO_SCHEDULE_FLUSH as Cr, writeDOMDataTransferFragment as Ct, DOMEditor as D, CAN_USE_DOM as Dn, ELEMENT_TO_EDITOR as Dr, observeDataTransferInsertion as Dt, verifyDiffState as E, writeDOMSelection as En, EDITOR_TO_WINDOW as Er, dataTransferFormats as Et, isFocusRequestedElsewhere as F, usesAppleDOMHotkeys as Fn, NODE_TO_PARENT as Fr, isSoftLineTextStale as Ft, subscribeEditorDOMScope as G, getPliteStringPlacementAtX as Gn, isDOMElement as Gr, canWriteEditableDOMSelection as Gt, setEditorDOMEditableElement as H, getPliteStringDocumentOffset as Hn, hasShadowRoot as Hr, resolvePliteNodePath as Ht, isSelectableDOMSelection as I, caretShowsPointOffTextFlowCharacters as In, closestShadowAware as Ir, noteAfterInsertCaret as It, writeViewSelectionPart as J, getPliteTextHostStrings as Jn, isDOMNode as Jr, findDOMRootRuntime as Jt, supersedeFocusRequest as K, getPliteStringPlacementDOMPoint as Kn, isDOMHTMLElement as Kr, clearEditableDOMSelection as Kt, isTrackedMutation as L, createDOMGeometryKernel as Ln, containsShadowAware as Lr, readAfterInsertCaret as Lt, focusEditableElement as M, isGeckoDOMHost as Mn, IS_READ_ONLY as Mr, SOFT_LINE_FLAG as Mt, getEditorDOMHostScrollElement as N, isWebKitDOMHost as Nn, NODE_TO_ELEMENT as Nr, clearAfterInsertCaret as Nt, DOMResolutionError as O, getDOMHostLanguage as On, ELEMENT_TO_NODE as Or, writeDataTransferFragment as Ot, getOrCreateDOMNodeKey as P, supportsDOMBeforeInput as Pn, NODE_TO_INDEX as Pr, isSoftLineEndBetween as Pt, scrollDOMRangeFocusIntoViewIfNeeded as Q, isOnVisualRow as Qn, markPlainTextPaste as Qr, getEventTargetInRoot as Qt, resolveDOMPointInRoot as R, getNearestPliteStringRect as Rn, getActiveElement as Rr, readLowerSoftLineEnd as Rt, normalizePoint as S, readDOMSelectionRecord as Sn, EDITOR_TO_RUNTIME_ID_TO_KEY as Sr, domCommands as St, targetRange as T, sameDOMSelectionPoints as Tn, EDITOR_TO_USER_SELECTION as Tr, writeDOMRangeData as Tt, setEditorDOMRootElement as U, getPliteStringEdgeOffset as Un, isAfter as Ur, DOMRootRuntime as Ut, setEditableRootReveal as V, getPliteStringDirectPlacement as Vn, getSelection as Vr, findMountedDOMNodeByPath as Vt, setEditorDOMScrollElement as W, getPliteStringLength as Wn, isBefore as Wr, canWriteDOMSelection as Wt, liftCaretOutOfCollapsedSection as X, getUsableRangeRects as Xn, isDOMText as Xr, focusedElementOnPage as Xt, ensureFocusCaret as Y, getTextFlowPointAtCoordinates as Yn, isDOMSelection as Yr, findEditorDOMRootRuntime as Yt, resolveNextKeyCaret as Z, hasUsableDOMRect as Zn, isPlainTextOnlyPaste as Zr, getEditorDOMRoot as Zt, TRIPLE_CLICK as _, forgetDOMSelectionRecordWithin as _n, EDITOR_TO_PENDING_INSERTION_MARKS as _r, takeDragSession as _t, isLeaf as a, readEditableDOMSelectionPoints as an, resolveDOMTextFlowOffset as ar, indicateDOMDropTarget as at, longestCommonPrefixLength as b, readDOMSelectionPoints as bn, EDITOR_TO_ROOT_VIEW_EDITORS as br, subscribeDropIndicator as bt, isText as c, shouldClearEditableDOMSelection as cn, setDOMTextFlowRecordIndex as cr, restDOMBlockDrag as ct, Hotkeys as d, markDOMSyncMutationTarget as dn, isCollapsedDOMCoverageBoundary as dr, clearDragScrollRepaint as dt, readClipboardCut as ei, isElementFocused as en, isDOMTextFlowSegmentSynchronized as er, resolveBlockFragmentDropRange as et, getLineBoundaryKeyboardMove as f, watchDOMSyncTextMarks as fn, EDITOR_TO_ELEMENT as fr, clearDragSession as ft, isHotkey as g, forgetDOMSelectionRecord as gn, EDITOR_TO_PENDING_DIFFS as gr, settleDragSession as gt, createCompiledHotkeyMatcher as h, selectDOMInputDefaultActionPhase as hn, EDITOR_TO_PENDING_ACTION as hr, setDragScrollRepaint as ht, isElement as i, observeRootBoundaryEvent as in, resolveDOMTextFlowInsertTarget as ir, copyIntentOf as it, findDOMPointElementInRoot as j, isBlinkDOMHost as jn, IS_NODE_MAP_DIRTY as jr, SOFT_LINE_END_SELECTOR as jt, claimFocusRequest as k, hasDOMHostQuirk as kn, IS_COMPOSING as kr, Key as kt, isVoid as l, writeEditableDOMSelection as ln, setDOMTextFlowRecordIndexes as lr, beginDragSession as lt, ariaKeyShortcuts as m, enableKernelTraceRetention as mn, EDITOR_TO_KEY_TO_ELEMENT as mr, readDragSession as mt, getNodeDataAttributeKeys as n, isSelectionOwnedByEditable as nn, releaseDOMTextFlowRecordIndex as nr, intersectClipChain as nt, isNode as o, resolveDOMReach as on, resolveDOMTextFlowRecordDOMText as or, pointAt as ot, isPasteWithoutFormatting as p, scheduleEditorDOMPhase as pn, EDITOR_TO_FORCE_RENDER as pr, isDragSessionClaimed as pt, watchFocusSuperseded as q, getPliteTextHostBounds as qn, isDOMInputOrTextArea as qr, documentOf as qt, isEditor as r, movedFocusElsewhere as rn, resolveDOMTextFlowEntry as rr, walkClipChain as rt, isString as s, resolveDOMTargetView as sn, resolveDOMTextFlowRecordText as sr, resolveDOMDropTarget as st, getElements as t, writeClipboardCut as ti, isEventInsideRoot as tn, readDOMTextFlowPaint as tr, getDragAutoScrollTarget as tt, keyToDataAttribute as u, isDOMSyncMutation as un, DOMCoverage as ur, cancelDragRest as ut, dom as v, getDOMRangeSelectionPoints as vn, EDITOR_TO_PENDING_SELECTION as vr, publishDropIndicator as vt, normalizeStringDiff as w, recordDOMSelection as wn, EDITOR_TO_USER_MARKS as wr, writeDOMFragmentData as wt, mergeStringDiffs as x, readDOMSelectionRange as xn, EDITOR_TO_RUNTIME_ID_TO_ELEMENTS as xr, cleanDOMClipboardContents as xt, applyStringDiff as y, isDOMSelectionWriteEcho as yn, EDITOR_TO_PLACEHOLDER_ELEMENT as yr, readDropIndicator as yt, resolveDOMRangeInRoot as z, getOwnedPliteTextStrings as zn, getDefaultView as zr, recordSoftLineEnd as zt };