plitejs 54.0.0-beta.6 → 54.0.0-beta.7
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.
- package/README.md +4 -4
- package/dist/authored/index.d.ts +25 -8
- package/dist/authored/index.js +3112 -343
- package/dist/{authored-veto-BsBDXC0b.js → authored-veto-CferDljr.js} +1 -1
- package/dist/clipboard-format-key-CLFcThXH.js +14 -0
- package/dist/{comparison-plan-IOewH50q.js → comparison-plan-7iIABSWG.js} +108 -2
- package/dist/{comparison-types-DBQFu7Rt.d.ts → comparison-types-CsmDG5r2.d.ts} +1 -1
- package/dist/{create-editor-DRRzGwaC.js → create-editor-acDgsovY.js} +25 -49
- package/dist/diff/index.d.ts +2 -2
- package/dist/diff/index.js +111 -20
- package/dist/dom/index.d.ts +3 -2
- package/dist/dom/index.js +3 -2
- package/dist/{dom-CVYV5Qd5.js → dom-B5bAma7X.js} +553 -179
- package/dist/history/index.d.ts +1 -1
- package/dist/history/index.js +4899 -3966
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/hyperscript/index.js +1 -1
- package/dist/{hyperscript-CT6hhnAY.js → hyperscript-BXUV6sdO.js} +2 -2
- package/dist/{index-PDROnF1G.d.ts → index-CTTjpWgb.d.ts} +1 -1
- package/dist/{index-D7-n2GCk.d.ts → index-D8DQ1YFB.d.ts} +22 -22
- package/dist/{index-VZrKWWeh.d.ts → index-DJvrmSRP.d.ts} +82 -199
- package/dist/{index-BT7D4vtf.d.ts → index-LhVJuuEf.d.ts} +1 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +5 -5
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/pagination/react.d.ts +14 -11
- package/dist/pagination/react.js +150 -103
- package/dist/{pagination-Cs5ka6hW.js → pagination-CwjmxPoX.js} +1 -1
- package/dist/{plugin-Bm6nsPHh.js → plugin-BZCGtqMI.js} +8162 -2747
- package/dist/{range-geometry-DO-kbNrb.d.ts → range-geometry-CZari453.d.ts} +1 -1
- package/dist/{range-geometry-D1XfYWs0.js → range-geometry-CqWrwkjH.js} +2 -2
- package/dist/react/index.d.ts +4 -5
- package/dist/react/index.js +7 -7
- package/dist/react/virtualized.d.ts +5 -5
- package/dist/react/virtualized.js +12 -7
- package/dist/{react-BYtwRr4v.js → react-DO9IETEQ.js} +126 -125
- package/dist/{retraction-DnEUo8oE.js → retraction-RHEKiF3h.js} +2 -18
- package/dist/{src-DIQDddmh.js → src-fLbHzUjC.js} +126 -41
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +3 -3
- package/dist/{index-DHt8nZQ6.d.ts → tx-only-1FM45FSj.d.ts} +9198 -8803
- package/dist/{editor-owner-CGj1wYCa.js → update-policy-C32RjjGt.js} +53 -2
- package/dist/{use-editor-dom-scope-hT7W9d-p.js → use-editor-dom-scope-CUBnNAZV.js} +5785 -4179
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/index.js +1 -1
- package/dist/yjs/react/index.d.ts +3 -3
- package/dist/yjs/react/index.js +3 -3
- package/dist/{yjs-C_g9gZwI.js → yjs-BMguSAX_.js} +309 -128
- package/package.json +1 -7
- package/dist/annotation-store-metrics-Ccjkef45.js +0 -12
- package/dist/annotations/index.d.ts +0 -2
- package/dist/annotations/index.js +0 -2
- package/dist/index-BvQzYVAW.d.ts +0 -71
- package/dist/mapped-view-store-CBk2-bDR.js +0 -120
- package/dist/store-BLYxJgOU.js +0 -747
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as transferEntries, c as dispatchPaste, n as checkFilesLanding, r as checkTransfer, u as landPaste } from "./src-
|
|
1
|
+
import { Ad as getEditorRuntimeRoot, Ai as toEditorCoreStateView, At as isVoid$2, Cd as TextApi, Cu as getCompiledEditorSchema, Df as valueRoot, Dm as countCoreWork, Dn as attachTransactionSpecAfterCommit, Do as getPlacementGeneration, Dt as isInline, Eo as getCaretOwner, Eu as getPluginRegistry, F as evaluateCommandWithState, Fo as placedSince, G as before, Gt as range, H as above, Ho as setSelectionAsView, I as getActiveCommandEditor, Md as hasEditorRuntime, Ms as txLocate, N as dispatchCommand, Od as getEditorRuntime, P as evaluateCommand, Pd as defineCommand, Pm as getDefined, Qf as DocumentIndex, Ro as resolveParkedCaret, Rt as next, Ru as getCompiledSchemaPropertyId, Sn as applyTransactionSpec, Tf as mapInternalDocumentChangePosition, Ti as subscribeCaretTarget, Tu as getPluginContributions, Un as getBaseCallRoot, V as NodeApi, Vi as withUpdateTagContext, Vt as point, W as after, Wi as captureSliceLanding, Xa as readRemovalLanding, _c as getSelectionDOMRange, _u as reportEditorLifecycleError, ar as getEditorReadDepth, au as getPublicExplicitLocationRoot, bd as formatDebugValue, bf as hasInternalDocumentChangeRoot, br as getSetSite, cn as unhangRange, cr as getEditorStateView, dm as LocationApi, ec as getCompiledEditorSchemaFromApi, fn as voidEditor, fo as isTextCell, gr as getNodeTargetRoot, hd as definePluginPoint, hl as getEditorCommitSnapshot, id as EditorSchemaValidationError, ii as resolveEditorNodeKeyForNode, il as createDetachedContentSlice, is as getViewFollowTarget, jd as getEditorSchema, kd as getEditorRuntimeOwner, ko as holdsCaret, l as definePlugin, lt as getSelection$1, m as getInstalledPlugin, md as failInvariant, mi as setEditorFocused, mn as editorCommands, nt as getChildren, ot as getNodeKey, ou as toInternalRoot, pm as PointApi, pt as hasPath, qa as withLandingBlock, rl as ContentSlice, st as getPathByNodeKey, su as toPublicRoot, tc as getInternalEditorSchemaFromApi, ts as getOwnViewPresentation, um as RangeApi, ut as getSnapshot, vd as SelectionApi, vl as getEditorCommitValue, vm as PathApi, vn as afterActiveTransactionEnds, vo as nodes, wf as mapInternalDocumentChangePoint, xc as mapSelectionThroughChange, xl as readRootEntries, xp as getNodeKeyForNode, xt as isBlock, yd as ElementApi, zn as getActiveEditorTransaction } from "./plugin-BZCGtqMI.js";
|
|
2
|
+
import { a as transferEntries, c as dispatchPaste, n as checkFilesLanding, r as checkTransfer, u as landPaste } from "./src-fLbHzUjC.js";
|
|
3
|
+
import { i as setDOMClipboardFormatKey, n as clearDOMClipboardFormatKey, r as getDOMClipboardFormatKey, t as DEFAULT_CLIPBOARD_FORMAT_KEY$2 } from "./clipboard-format-key-CLFcThXH.js";
|
|
3
4
|
import scrollIntoViewIfNeeded from "scroll-into-view-if-needed";
|
|
4
5
|
//#region src/dom/utils/dom.ts
|
|
5
6
|
globalThis.Node;
|
|
@@ -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$
|
|
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$
|
|
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$
|
|
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();
|
|
@@ -2401,6 +2402,88 @@ const hasDOMHostQuirk = (source, quirk) => resolveDOMSourceFacts(source)?.quirks
|
|
|
2401
2402
|
/** True when the current environment exposes the browser DOM APIs Plite needs. */
|
|
2402
2403
|
const CAN_USE_DOM = !!(typeof window !== "undefined" && window.document !== void 0 && "createElement" in window.document);
|
|
2403
2404
|
//#endregion
|
|
2405
|
+
//#region src/dom/utils/selection-writes.ts
|
|
2406
|
+
const RECORDS = /* @__PURE__ */ new WeakMap();
|
|
2407
|
+
const UNPLACED_WRITES = /* @__PURE__ */ new WeakMap();
|
|
2408
|
+
const hasLayoutBox = ([node]) => {
|
|
2409
|
+
const element = node.nodeType === 1 ? node : node.parentElement;
|
|
2410
|
+
return !!element && element.getClientRects().length > 0;
|
|
2411
|
+
};
|
|
2412
|
+
const readDOMSelectionPoints = (selection) => {
|
|
2413
|
+
const { anchorNode, focusNode } = selection;
|
|
2414
|
+
return selection.rangeCount > 0 && anchorNode && focusNode ? {
|
|
2415
|
+
anchor: [anchorNode, selection.anchorOffset],
|
|
2416
|
+
focus: [focusNode, selection.focusOffset]
|
|
2417
|
+
} : null;
|
|
2418
|
+
};
|
|
2419
|
+
const sameDOMPoint = ([node, offset], [otherNode, otherOffset]) => node === otherNode && offset === otherOffset;
|
|
2420
|
+
const sameDOMSelectionPoints = (points, other) => points === null || other === null ? points === other : sameDOMPoint(points.anchor, other.anchor) && sameDOMPoint(points.focus, other.focus);
|
|
2421
|
+
const readDOMSelectionRecord = (tree) => RECORDS.get(tree) ?? null;
|
|
2422
|
+
const isDOMSelectionWriteEcho = (tree, points) => {
|
|
2423
|
+
const record = RECORDS.get(tree);
|
|
2424
|
+
return record?.source === "write" && sameDOMSelectionPoints(points, record.points);
|
|
2425
|
+
};
|
|
2426
|
+
const recordDOMSelection = (tree, points, source) => {
|
|
2427
|
+
RECORDS.set(tree, {
|
|
2428
|
+
points,
|
|
2429
|
+
source
|
|
2430
|
+
});
|
|
2431
|
+
UNPLACED_WRITES.delete(tree);
|
|
2432
|
+
};
|
|
2433
|
+
const forgetDOMSelectionRecord = (tree) => {
|
|
2434
|
+
RECORDS.delete(tree);
|
|
2435
|
+
UNPLACED_WRITES.delete(tree);
|
|
2436
|
+
};
|
|
2437
|
+
const touches = (container, points) => !!points && (container.contains(points.anchor[0]) || container.contains(points.focus[0]));
|
|
2438
|
+
const forgetDOMSelectionRecordWithin = (tree, container) => {
|
|
2439
|
+
if (touches(container, RECORDS.get(tree)?.points)) RECORDS.delete(tree);
|
|
2440
|
+
if (touches(container, UNPLACED_WRITES.get(tree))) UNPLACED_WRITES.delete(tree);
|
|
2441
|
+
};
|
|
2442
|
+
const getDOMRangeSelectionPoints = (range, backward = false) => {
|
|
2443
|
+
const start = [range.startContainer, range.startOffset];
|
|
2444
|
+
const end = [range.endContainer, range.endOffset];
|
|
2445
|
+
return backward ? {
|
|
2446
|
+
anchor: end,
|
|
2447
|
+
focus: start
|
|
2448
|
+
} : {
|
|
2449
|
+
anchor: start,
|
|
2450
|
+
focus: end
|
|
2451
|
+
};
|
|
2452
|
+
};
|
|
2453
|
+
const readsSelectionAsHost = (tree) => tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && isWebKitDOMHost(tree);
|
|
2454
|
+
/**
|
|
2455
|
+
* Write `points` as `tree`'s selection, keeping their direction, or clear its
|
|
2456
|
+
* ranges for null, and record what the tree then shows, or the points written
|
|
2457
|
+
* where the tree reads its selection as its host. A selection that already
|
|
2458
|
+
* shows them is left alone, and so is the record, unless WebKit got them from
|
|
2459
|
+
* a write while their anchor had no layout box, neither the user nor a write
|
|
2460
|
+
* of other points has come since, and the anchor has one now.
|
|
2461
|
+
*/
|
|
2462
|
+
const writeDOMSelection = (tree, points) => {
|
|
2463
|
+
changeDOMSelection(tree, points);
|
|
2464
|
+
};
|
|
2465
|
+
const changeDOMSelection = (tree, points, beforeChange, canCommit) => {
|
|
2466
|
+
const selection = getSelection(tree);
|
|
2467
|
+
if (!selection) return false;
|
|
2468
|
+
const rewritesUnplaced = points !== null && sameDOMSelectionPoints(UNPLACED_WRITES.get(tree) ?? null, points);
|
|
2469
|
+
if (!rewritesUnplaced) UNPLACED_WRITES.delete(tree);
|
|
2470
|
+
if (!(points === null && tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && !!canCommit) && sameDOMSelectionPoints(readDOMSelectionPoints(selection), points) && !(rewritesUnplaced && hasLayoutBox(points.anchor))) return true;
|
|
2471
|
+
beforeChange?.();
|
|
2472
|
+
if (canCommit && !canCommit()) return false;
|
|
2473
|
+
if (points) selection.setBaseAndExtent(points.anchor[0], points.anchor[1], points.focus[0], points.focus[1]);
|
|
2474
|
+
else selection.removeAllRanges();
|
|
2475
|
+
if (points && hasDOMHostQuirk(tree, "unrendered-caret-needs-rewrite") && !hasLayoutBox(points.anchor)) UNPLACED_WRITES.set(tree, points);
|
|
2476
|
+
else UNPLACED_WRITES.delete(tree);
|
|
2477
|
+
const writtenPoints = readDOMSelectionPoints(selection);
|
|
2478
|
+
RECORDS.set(tree, {
|
|
2479
|
+
points: readsSelectionAsHost(tree) || tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE && points !== null && !writtenPoints ? points : writtenPoints,
|
|
2480
|
+
source: "write"
|
|
2481
|
+
});
|
|
2482
|
+
return true;
|
|
2483
|
+
};
|
|
2484
|
+
/** A copy of `selection`'s range at `index`, safe to keep or change. */
|
|
2485
|
+
const readDOMSelectionRange = (selection, index = 0) => selection.getRangeAt(index).cloneRange();
|
|
2486
|
+
//#endregion
|
|
2404
2487
|
//#region src/dom/plugin/dom-input-runtime.ts
|
|
2405
2488
|
/**
|
|
2406
2489
|
* Choose the event phase that owns a default editing action.
|
|
@@ -2970,94 +3053,6 @@ var DOMInputRuntime = class {
|
|
|
2970
3053
|
}
|
|
2971
3054
|
};
|
|
2972
3055
|
//#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
3056
|
//#region src/dom/plugin/dom-integrity-observer.ts
|
|
3062
3057
|
const OBSERVER_OPTIONS = {
|
|
3063
3058
|
attributeOldValue: true,
|
|
@@ -3167,9 +3162,9 @@ const captureSelection = (root) => {
|
|
|
3167
3162
|
};
|
|
3168
3163
|
};
|
|
3169
3164
|
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
|
-
|
|
3165
|
+
const restoreSelection = (root, snapshot, writeSelection) => {
|
|
3166
|
+
if (!snapshot || !writeSelection || !root.contains(snapshot.anchorNode) || !root.contains(snapshot.focusNode)) return;
|
|
3167
|
+
writeSelection(root, {
|
|
3173
3168
|
anchor: [snapshot.anchorNode, Math.min(snapshot.anchorOffset, maxOffset(snapshot.anchorNode))],
|
|
3174
3169
|
focus: [snapshot.focusNode, Math.min(snapshot.focusOffset, maxOffset(snapshot.focusNode))]
|
|
3175
3170
|
});
|
|
@@ -3446,7 +3441,7 @@ var DOMIntegrityObserver = class {
|
|
|
3446
3441
|
}));
|
|
3447
3442
|
const selection = captureSelection(root);
|
|
3448
3443
|
for (const mutation of mutations.reverse()) restoreMutation(mutation);
|
|
3449
|
-
restoreSelection(root, selection);
|
|
3444
|
+
restoreSelection(root, selection, this.options.writeSelection);
|
|
3450
3445
|
this.repairPassesInFrame += 1;
|
|
3451
3446
|
this.scheduleRepairPassReset();
|
|
3452
3447
|
this.diagnosticsValue.repairPasses += 1;
|
|
@@ -4014,12 +4009,21 @@ const findDOMRootRuntime = (node) => {
|
|
|
4014
4009
|
}
|
|
4015
4010
|
return null;
|
|
4016
4011
|
};
|
|
4012
|
+
const isNestedEditableOrInput = (root, node) => {
|
|
4013
|
+
let current = node ? asElement(node) : null;
|
|
4014
|
+
while (current && current !== root) {
|
|
4015
|
+
const tag = current.tagName;
|
|
4016
|
+
const ce = current.getAttribute("contenteditable");
|
|
4017
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || current.hasAttribute("data-editor") || ce !== null && ce.toLowerCase() !== "false") return true;
|
|
4018
|
+
current = composedParent(current);
|
|
4019
|
+
}
|
|
4020
|
+
return false;
|
|
4021
|
+
};
|
|
4017
4022
|
const isRuntimeRootActive = (runtime) => {
|
|
4018
4023
|
const root = runtime.rootRef.current;
|
|
4019
4024
|
if (!root) return false;
|
|
4020
|
-
const
|
|
4021
|
-
|
|
4022
|
-
return activeElement === root || !!activeElement && root.contains(activeElement);
|
|
4025
|
+
const active = focusedElementOnPage(root);
|
|
4026
|
+
return !!active && (active === root || containsShadowAware(root, active) && !isNestedEditableOrInput(root, active));
|
|
4023
4027
|
};
|
|
4024
4028
|
const hasMountedDOMRoot = (editor) => DOM_ROOT_RUNTIMES_BY_EDITOR.has(editor);
|
|
4025
4029
|
const hasMountedDocumentView = (editor) => MOUNTED_VIEWS_BY_DOCUMENT.has(documentOf(editor));
|
|
@@ -4070,6 +4074,104 @@ const isElementFocused = (element) => {
|
|
|
4070
4074
|
node = frame;
|
|
4071
4075
|
}
|
|
4072
4076
|
};
|
|
4077
|
+
const isReadOnlyRoot = (editable, editor) => {
|
|
4078
|
+
const owner = editor ?? findDOMRootRuntime(editable)?.editor;
|
|
4079
|
+
return !!owner && !!IS_READ_ONLY.get(owner) || editable.getAttribute("contenteditable") === "false";
|
|
4080
|
+
};
|
|
4081
|
+
const canWriteDOMSelection = (editable, editor) => {
|
|
4082
|
+
if (isElementFocused(editable)) return true;
|
|
4083
|
+
if (!isReadOnlyRoot(editable, editor)) return false;
|
|
4084
|
+
const active = focusedElementOnPage(editable);
|
|
4085
|
+
return !active || active === active.ownerDocument.body || active === active.ownerDocument.documentElement || containsShadowAware(editable, active) && !isNestedEditableOrInput(editable, active);
|
|
4086
|
+
};
|
|
4087
|
+
const shadowRootsAbove = (element) => {
|
|
4088
|
+
const roots = [];
|
|
4089
|
+
let current = element;
|
|
4090
|
+
while (current) {
|
|
4091
|
+
const rootNode = current.getRootNode();
|
|
4092
|
+
if ("host" in rootNode) {
|
|
4093
|
+
const shadowRoot = rootNode;
|
|
4094
|
+
roots.push(shadowRoot);
|
|
4095
|
+
current = shadowRoot.host;
|
|
4096
|
+
} else break;
|
|
4097
|
+
}
|
|
4098
|
+
return roots;
|
|
4099
|
+
};
|
|
4100
|
+
const readComposedSelectionRange = (editable, selection, shadowRoots = shadowRootsAbove(editable)) => {
|
|
4101
|
+
const composedSelection = selection;
|
|
4102
|
+
if (typeof composedSelection.getComposedRanges !== "function") return null;
|
|
4103
|
+
try {
|
|
4104
|
+
return composedSelection.getComposedRanges({ shadowRoots })[0] ?? null;
|
|
4105
|
+
} catch {
|
|
4106
|
+
try {
|
|
4107
|
+
return composedSelection.getComposedRanges(...shadowRoots)[0] ?? null;
|
|
4108
|
+
} catch {
|
|
4109
|
+
return null;
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
};
|
|
4113
|
+
const readEditableDOMSelectionPoints = (editable, selection) => {
|
|
4114
|
+
if (!selection) return null;
|
|
4115
|
+
const tree = editable.getRootNode();
|
|
4116
|
+
if (tree.nodeType === tree.DOCUMENT_FRAGMENT_NODE) {
|
|
4117
|
+
const composed = readComposedSelectionRange(editable, selection);
|
|
4118
|
+
if (composed) return {
|
|
4119
|
+
anchor: [composed.startContainer, composed.startOffset],
|
|
4120
|
+
focus: [composed.endContainer, composed.endOffset]
|
|
4121
|
+
};
|
|
4122
|
+
}
|
|
4123
|
+
return readDOMSelectionPoints(selection);
|
|
4124
|
+
};
|
|
4125
|
+
const isSelectionOwnedByEditable = (editable, selection, exclude) => {
|
|
4126
|
+
if (!selection) return false;
|
|
4127
|
+
const owns = (node) => !!node && containsShadowAware(editable, node) && !(exclude && exclude !== editable && containsShadowAware(exclude, node)) && !isNestedEditableOrInput(editable, node);
|
|
4128
|
+
if (owns(selection.anchorNode) || owns(selection.focusNode)) return true;
|
|
4129
|
+
const tree = editable.getRootNode();
|
|
4130
|
+
if (tree.nodeType !== tree.DOCUMENT_FRAGMENT_NODE) return false;
|
|
4131
|
+
const shadowRoots = shadowRootsAbove(editable);
|
|
4132
|
+
if (typeof selection.getComposedRanges === "function") {
|
|
4133
|
+
const composed = readComposedSelectionRange(editable, selection, shadowRoots);
|
|
4134
|
+
return !!composed && (owns(composed.startContainer) || owns(composed.endContainer));
|
|
4135
|
+
}
|
|
4136
|
+
if (!readsSelectionAsHost(tree)) return false;
|
|
4137
|
+
if (!shadowRoots.some((shadowRoot) => selection.anchorNode === shadowRoot.host || selection.focusNode === shadowRoot.host)) return false;
|
|
4138
|
+
if (selection.rangeCount > 0) try {
|
|
4139
|
+
const range = readDOMSelectionRange(selection);
|
|
4140
|
+
if (!shadowRoots.some((shadowRoot) => range.startContainer === shadowRoot.host && range.endContainer === shadowRoot.host)) return owns(range.startContainer) || owns(range.endContainer);
|
|
4141
|
+
} catch {
|
|
4142
|
+
return false;
|
|
4143
|
+
}
|
|
4144
|
+
const recorded = readDOMSelectionRecord(tree)?.points;
|
|
4145
|
+
return !!recorded && (owns(recorded.anchor[0]) || owns(recorded.focus[0]));
|
|
4146
|
+
};
|
|
4147
|
+
const shouldClearEditableDOMSelection = (editable, editor) => {
|
|
4148
|
+
const focusElement = findDOMRootRuntime(editable)?.nodeSelectionFocus();
|
|
4149
|
+
if (!canWriteDOMSelection(editable, editor) && !(focusElement && isElementFocused(focusElement))) return false;
|
|
4150
|
+
return isSelectionOwnedByEditable(editable, getSelection(editable.getRootNode()), focusElement);
|
|
4151
|
+
};
|
|
4152
|
+
const canWriteEditableDOMSelection = (editable, { editor, policy = "editable" } = {}) => policy === "focused" ? isElementFocused(editable) : canWriteDOMSelection(editable, editor);
|
|
4153
|
+
const writeEditableDOMSelection = (editable, points, { beforeChange, editor, policy = "editable", record = "write" } = {}) => {
|
|
4154
|
+
const tree = editable.getRootNode();
|
|
4155
|
+
const isAllowed = () => editable.getRootNode() === tree && canWriteEditableDOMSelection(editable, {
|
|
4156
|
+
editor,
|
|
4157
|
+
policy
|
|
4158
|
+
});
|
|
4159
|
+
if (!isAllowed()) return false;
|
|
4160
|
+
if (!changeDOMSelection(tree, points, beforeChange, isAllowed)) return false;
|
|
4161
|
+
if (record === "user") forgetDOMSelectionRecord(tree);
|
|
4162
|
+
return true;
|
|
4163
|
+
};
|
|
4164
|
+
const clearEditableDOMSelection = (editable, { beforeChange, editor, policy = "editable" } = {}) => {
|
|
4165
|
+
const tree = editable.getRootNode();
|
|
4166
|
+
const isAllowed = () => {
|
|
4167
|
+
if (editable.getRootNode() !== tree) return false;
|
|
4168
|
+
const focusElement = findDOMRootRuntime(editable)?.nodeSelectionFocus();
|
|
4169
|
+
const selection = getSelection(tree);
|
|
4170
|
+
return policy === "owned" ? isSelectionOwnedByEditable(editable, selection, focusElement) : policy === "focused" ? isElementFocused(editable) && isSelectionOwnedByEditable(editable, selection, focusElement) : shouldClearEditableDOMSelection(editable, editor);
|
|
4171
|
+
};
|
|
4172
|
+
if (!isAllowed()) return false;
|
|
4173
|
+
return changeDOMSelection(tree, null, beforeChange, isAllowed);
|
|
4174
|
+
};
|
|
4073
4175
|
const resolveInnermostElementAtPoint = (document, x, y) => {
|
|
4074
4176
|
let element = document.elementFromPoint(x, y);
|
|
4075
4177
|
for (let inner = element && shadowRootOf(element)?.elementFromPoint(x, y); inner && inner !== element; inner = shadowRootOf(element)?.elementFromPoint(x, y)) element = inner;
|
|
@@ -4085,6 +4187,12 @@ const focusedElementOf = (top) => {
|
|
|
4085
4187
|
return null;
|
|
4086
4188
|
};
|
|
4087
4189
|
const focusedElementOnPage = (node) => focusedElementOf(pageOf(node.ownerDocument ?? node));
|
|
4190
|
+
const movedFocusElsewhere = (element, before, after) => {
|
|
4191
|
+
if (!after || after === before || after === element || containsShadowAware(element, after) && !isNestedEditableOrInput(element, after)) return false;
|
|
4192
|
+
const ownDoc = element.ownerDocument;
|
|
4193
|
+
const topDoc = pageOf(ownDoc);
|
|
4194
|
+
return after !== ownDoc.body && after !== ownDoc.documentElement && after !== topDoc.body && after !== topDoc.documentElement;
|
|
4195
|
+
};
|
|
4088
4196
|
const outerElementOf = (element) => {
|
|
4089
4197
|
if (element.parentElement) return element.parentElement;
|
|
4090
4198
|
const parent = element.parentNode;
|
|
@@ -4131,6 +4239,16 @@ const resolveDOMReach = (handle, request = {}) => {
|
|
|
4131
4239
|
if (presentation) return reachOwnView(mounted, handle, presentation, request);
|
|
4132
4240
|
return handle === owner ? reachDocumentView(mounted, handle, request) : null;
|
|
4133
4241
|
};
|
|
4242
|
+
const resolveMountedViewForRoot = (handle, root) => {
|
|
4243
|
+
if (!hasEditorRuntime(handle)) return null;
|
|
4244
|
+
if (hasMountedDOMRoot(handle) && getEditorRuntimeRoot(handle) === root) return handle;
|
|
4245
|
+
const owner = documentOf(handle);
|
|
4246
|
+
const mounted = MOUNTED_VIEWS_BY_DOCUMENT.get(owner);
|
|
4247
|
+
if (!mounted) return null;
|
|
4248
|
+
const presentation = getOwnViewPresentation(handle);
|
|
4249
|
+
if (presentation) return pickView(mounted, (view) => getOwnViewPresentation(view) === presentation && getEditorRuntimeRoot(view) === root);
|
|
4250
|
+
return handle === owner ? reachDocumentView(mounted, handle, { root }) : null;
|
|
4251
|
+
};
|
|
4134
4252
|
const resolveDOMTargetView = (handle, node) => {
|
|
4135
4253
|
if (hasMountedDOMRoot(handle)) return handle;
|
|
4136
4254
|
const view = node ? findDOMRootRuntime(node)?.editor : null;
|
|
@@ -4228,6 +4346,7 @@ var DOMRootRuntime = class DOMRootRuntime {
|
|
|
4228
4346
|
this.schedulerImplementation = this.createScheduler();
|
|
4229
4347
|
this.domSyncMutationOwnership = new DOMSyncMutationOwnership((phase, label, callback, scheduleOptions) => this.schedulerImplementation?.schedule(phase, label, callback, scheduleOptions) ?? (() => {}));
|
|
4230
4348
|
this.domIntegrityObserver = new DOMIntegrityObserver({
|
|
4349
|
+
writeSelection: (root, points) => writeEditableDOMSelection(root, points, { editor: this.editor }),
|
|
4231
4350
|
getAndroidMutationHandler: options.getAndroidMutationHandler,
|
|
4232
4351
|
isAndroidMutationOwned: options.isAndroidMutationOwned,
|
|
4233
4352
|
isCanonicalTextMutation: options.isCanonicalTextMutation,
|
|
@@ -5992,9 +6111,7 @@ const writeDataTransferFragment = (editor, data, slice, options = {}) => {
|
|
|
5992
6111
|
//#region src/dom/plugin/dom-clipboard-runtime.ts
|
|
5993
6112
|
const PLITE_FRAGMENT_ATTRIBUTE_RE = /\bdata-editor-fragment\s*=/i;
|
|
5994
6113
|
const OPENING_HTML_TAG_RE = /<[A-Za-z][^<>]*?>/;
|
|
5995
|
-
const DEFAULT_CLIPBOARD_FORMAT_KEY$1 = "x-editor-fragment";
|
|
5996
6114
|
const PLITE_FRAGMENT_FORMAT_ATTRIBUTE = "data-editor-fragment-format";
|
|
5997
|
-
const EDITOR_TO_CLIPBOARD_FORMAT_KEY = /* @__PURE__ */ new WeakMap();
|
|
5998
6115
|
/** Semantic commands that own DOM clipboard ingress. */
|
|
5999
6116
|
const domCommands = Object.freeze({ insertData: defineCommand("dom.insertData", {
|
|
6000
6117
|
locate: false,
|
|
@@ -6012,14 +6129,6 @@ const stripRenderOnlyLeafWrappers = (root, ui) => {
|
|
|
6012
6129
|
}
|
|
6013
6130
|
});
|
|
6014
6131
|
};
|
|
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
6132
|
const escapeHtmlText = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
6024
6133
|
const escapeHtmlAttribute = (text) => escapeHtmlText(text).replaceAll("\"", """);
|
|
6025
6134
|
const attachFragmentMetadataToHtml = (html, encoded, clipboardFormatKey) => {
|
|
@@ -6147,7 +6256,7 @@ const encodeDOMFragmentData = (slice, window) => {
|
|
|
6147
6256
|
return (window?.btoa ?? globalThis.btoa)(encodeURIComponent(string));
|
|
6148
6257
|
};
|
|
6149
6258
|
/** Write Plite fragment MIME, HTML, and plain-text clipboard payloads. */
|
|
6150
|
-
const writeDOMFragmentData = (data, { clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$
|
|
6259
|
+
const writeDOMFragmentData = (data, { clipboardFormatKey = DEFAULT_CLIPBOARD_FORMAT_KEY$2, html, slice, text, window }) => {
|
|
6151
6260
|
const sourceSlice = ContentSlice.fromJSON(slice);
|
|
6152
6261
|
const sourceText = text ?? getFragmentText(sourceSlice);
|
|
6153
6262
|
const encoded = encodeDOMFragmentData(sourceSlice, window);
|
|
@@ -7446,6 +7555,62 @@ const scrollAncestors = (startElement, scrollingElement, rect, visibleBox) => {
|
|
|
7446
7555
|
}
|
|
7447
7556
|
return cur;
|
|
7448
7557
|
};
|
|
7558
|
+
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;
|
|
7559
|
+
const setCaretScrollMargin = (el, elRect, caret, top, right, bottom, left) => {
|
|
7560
|
+
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`);
|
|
7561
|
+
};
|
|
7562
|
+
const canPanVisualViewport = (win, scrollingElement, el) => {
|
|
7563
|
+
const vv = win.visualViewport;
|
|
7564
|
+
return Boolean(vv && isDOMHTMLElement(el) && typeof el.scrollIntoView === "function" && (vv.height < scrollingElement.clientHeight || vv.width < scrollingElement.clientWidth));
|
|
7565
|
+
};
|
|
7566
|
+
const panVisualViewportNearest = (win, scrollingElement, el, caret) => {
|
|
7567
|
+
const vv = win.visualViewport;
|
|
7568
|
+
if (!vv || !canPanVisualViewport(win, scrollingElement, el)) return caret;
|
|
7569
|
+
const elRect = el.getBoundingClientRect();
|
|
7570
|
+
const prev = el.style.getPropertyValue("scroll-margin");
|
|
7571
|
+
const priority = el.style.getPropertyPriority("scroll-margin");
|
|
7572
|
+
const caretAfter = () => {
|
|
7573
|
+
const afterRect = el.getBoundingClientRect();
|
|
7574
|
+
return shiftRect(caret, elRect.left - afterRect.left, elRect.top - afterRect.top);
|
|
7575
|
+
};
|
|
7576
|
+
setCaretScrollMargin(el, elRect, caret, MARGIN, MARGIN, MARGIN, MARGIN);
|
|
7577
|
+
el.scrollIntoView({
|
|
7578
|
+
block: "nearest",
|
|
7579
|
+
inline: "nearest"
|
|
7580
|
+
});
|
|
7581
|
+
let nextCaret = caretAfter();
|
|
7582
|
+
if (outsideBox(nextCaret, getVisibleViewportBox(win, scrollingElement), 1)) {
|
|
7583
|
+
const rootStyle = win.getComputedStyle(scrollingElement);
|
|
7584
|
+
const padTop = pad(rootStyle.scrollPaddingTop, vv.height);
|
|
7585
|
+
const padRight = pad(rootStyle.scrollPaddingRight, vv.width);
|
|
7586
|
+
const padBottom = pad(rootStyle.scrollPaddingBottom, vv.height);
|
|
7587
|
+
const padLeft = pad(rootStyle.scrollPaddingLeft, vv.width);
|
|
7588
|
+
if (padTop > 0 || padRight > 0 || padBottom > 0 || padLeft > 0) {
|
|
7589
|
+
setCaretScrollMargin(el, elRect, caret, MARGIN + padTop, MARGIN + padRight, MARGIN + padBottom, MARGIN + padLeft);
|
|
7590
|
+
el.scrollIntoView({
|
|
7591
|
+
block: "nearest",
|
|
7592
|
+
inline: "nearest"
|
|
7593
|
+
});
|
|
7594
|
+
nextCaret = caretAfter();
|
|
7595
|
+
}
|
|
7596
|
+
}
|
|
7597
|
+
if (prev) el.style.setProperty("scroll-margin", prev, priority);
|
|
7598
|
+
else el.style.removeProperty("scroll-margin");
|
|
7599
|
+
return nextCaret;
|
|
7600
|
+
};
|
|
7601
|
+
const panVisualViewportCenter = (win, scrollingElement, el, caret) => {
|
|
7602
|
+
if (!canPanVisualViewport(win, scrollingElement, el)) return;
|
|
7603
|
+
const elRect = el.getBoundingClientRect();
|
|
7604
|
+
const prev = el.style.getPropertyValue("scroll-margin");
|
|
7605
|
+
const priority = el.style.getPropertyPriority("scroll-margin");
|
|
7606
|
+
setCaretScrollMargin(el, elRect, caret, MARGIN, MARGIN, MARGIN, MARGIN);
|
|
7607
|
+
el.scrollIntoView({
|
|
7608
|
+
block: "center",
|
|
7609
|
+
inline: "nearest"
|
|
7610
|
+
});
|
|
7611
|
+
if (prev) el.style.setProperty("scroll-margin", prev, priority);
|
|
7612
|
+
else el.style.removeProperty("scroll-margin");
|
|
7613
|
+
};
|
|
7449
7614
|
const scrollRectIntoViewIfNeeded = ({ rect, startElement }) => {
|
|
7450
7615
|
const scrollingElement = startElement.ownerDocument.scrollingElement ?? startElement.ownerDocument.documentElement;
|
|
7451
7616
|
let cur = scrollAncestors(startElement, scrollingElement, rect, null);
|
|
@@ -7461,14 +7626,20 @@ const scrollRectIntoViewIfNeeded = ({ rect, startElement }) => {
|
|
|
7461
7626
|
cur = shiftRect(cur, win.scrollX - prevX, win.scrollY - prevY);
|
|
7462
7627
|
visible = getVisibleViewportBox(win, scrollingElement);
|
|
7463
7628
|
}
|
|
7464
|
-
if (cur
|
|
7629
|
+
if (outsideBox(cur, visible, 1)) {
|
|
7630
|
+
cur = panVisualViewportNearest(win, scrollingElement, startElement, cur);
|
|
7631
|
+
visible = getVisibleViewportBox(win, scrollingElement);
|
|
7632
|
+
}
|
|
7633
|
+
if (outsideBox(cur, visible)) cur = scrollAncestors(startElement, scrollingElement, cur, visible);
|
|
7634
|
+
if (outsideBox(cur, visible, 1)) panVisualViewportCenter(win, scrollingElement, startElement, cur);
|
|
7465
7635
|
};
|
|
7466
|
-
const
|
|
7636
|
+
const scrollDOMRangeFocusIntoViewIfNeeded = (domRange, isBackward = false) => {
|
|
7467
7637
|
const focusRange = domRange.cloneRange();
|
|
7468
7638
|
focusRange.collapse(isBackward);
|
|
7469
7639
|
const container = focusRange.startContainer;
|
|
7470
7640
|
const leafEl = isDOMElement(container) ? container : container.parentElement;
|
|
7471
7641
|
if (!leafEl) return;
|
|
7642
|
+
if (typeof focusRange.getBoundingClientRect !== "function") return;
|
|
7472
7643
|
const domRect = focusRange.getBoundingClientRect();
|
|
7473
7644
|
const targetRect = isUsableScrollRect(domRect) ? domRect : leafEl.getBoundingClientRect();
|
|
7474
7645
|
if (!isUsableScrollRect(targetRect)) return;
|
|
@@ -7530,6 +7701,41 @@ const claimFocusRequest = (editor, element) => {
|
|
|
7530
7701
|
supersedeFocusRequest(editor);
|
|
7531
7702
|
PAGE_TO_FOCUS_REQUEST_OWNER.set(pageOf(element.ownerDocument), { editor: new WeakRef(editor) });
|
|
7532
7703
|
};
|
|
7704
|
+
const isAncestorChainActive = (node) => {
|
|
7705
|
+
let current = node;
|
|
7706
|
+
while (current) {
|
|
7707
|
+
const tree = current.getRootNode();
|
|
7708
|
+
if (tree.activeElement !== current) return false;
|
|
7709
|
+
current = "host" in tree ? tree.host : tree.defaultView?.frameElement ?? null;
|
|
7710
|
+
}
|
|
7711
|
+
return true;
|
|
7712
|
+
};
|
|
7713
|
+
const focusEnclosingFrames = (el) => {
|
|
7714
|
+
const frames = [];
|
|
7715
|
+
for (let frame = el.ownerDocument.defaultView?.frameElement; frame; frame = frame.ownerDocument.defaultView?.frameElement) if ("focus" in frame && typeof frame.focus === "function") frames.push(frame);
|
|
7716
|
+
for (let i = frames.length - 1; i >= 0; i -= 1) {
|
|
7717
|
+
const frame = frames[i];
|
|
7718
|
+
const frameDoc = "contentDocument" in frame ? frame.contentDocument : null;
|
|
7719
|
+
const expectedChild = i > 0 ? frames[i - 1] : el;
|
|
7720
|
+
const childBefore = frameDoc?.activeElement ?? null;
|
|
7721
|
+
if (isAncestorChainActive(frame)) continue;
|
|
7722
|
+
frame.focus({ preventScroll: true });
|
|
7723
|
+
if (!isAncestorChainActive(frame)) return false;
|
|
7724
|
+
const childAfter = frameDoc?.activeElement ?? null;
|
|
7725
|
+
if (childAfter && childAfter !== childBefore && childAfter !== expectedChild && childAfter !== frameDoc?.body && childAfter !== frameDoc?.documentElement) return false;
|
|
7726
|
+
}
|
|
7727
|
+
return true;
|
|
7728
|
+
};
|
|
7729
|
+
const focusEditableElement = (editor, el) => {
|
|
7730
|
+
if (!focusEnclosingFrames(el)) return false;
|
|
7731
|
+
IS_FOCUSED.set(editor, true);
|
|
7732
|
+
setEditorFocused(editor, true);
|
|
7733
|
+
el.focus({ preventScroll: true });
|
|
7734
|
+
if (isElementFocused(el)) return true;
|
|
7735
|
+
IS_FOCUSED.delete(editor);
|
|
7736
|
+
setEditorFocused(editor, false);
|
|
7737
|
+
return false;
|
|
7738
|
+
};
|
|
7533
7739
|
const getLastChildren = (element) => {
|
|
7534
7740
|
if (element.childElementCount > 0) return getLastChildren(element.children[0]);
|
|
7535
7741
|
return element;
|
|
@@ -7643,15 +7849,81 @@ const setEditorDOMScrollElement = (editor, element, { fallback = false } = {}) =
|
|
|
7643
7849
|
if (setWeakElement(fallback ? EDITOR_TO_DOM_FALLBACK_SCROLL : EDITOR_TO_DOM_SCROLL, owner, element)) notifyEditorDOMScopeListeners(owner);
|
|
7644
7850
|
};
|
|
7645
7851
|
const ELEMENT_TO_ROOT_REVEAL = /* @__PURE__ */ new WeakMap();
|
|
7852
|
+
const VIEW_TO_SCROLL_TOKEN = /* @__PURE__ */ new WeakMap();
|
|
7853
|
+
const nextScrollIntoViewToken = (scope) => {
|
|
7854
|
+
const token = (VIEW_TO_SCROLL_TOKEN.get(scope) ?? 0) + 1;
|
|
7855
|
+
VIEW_TO_SCROLL_TOKEN.set(scope, token);
|
|
7856
|
+
return token;
|
|
7857
|
+
};
|
|
7858
|
+
const hasCSSScrollMargin = (element) => {
|
|
7859
|
+
const win = element.ownerDocument?.defaultView;
|
|
7860
|
+
if (!win) return false;
|
|
7861
|
+
const style = win.getComputedStyle(element);
|
|
7862
|
+
return (Number.parseFloat(element.style.scrollMarginTop || style.scrollMarginTop) || 0) > 0 || (Number.parseFloat(element.style.scrollMarginBottom || style.scrollMarginBottom) || 0) > 0 || (Number.parseFloat(element.style.scrollMarginLeft || style.scrollMarginLeft) || 0) > 0 || (Number.parseFloat(element.style.scrollMarginRight || style.scrollMarginRight) || 0) > 0;
|
|
7863
|
+
};
|
|
7864
|
+
const runScrollIntoViewIfNeeded = (element, options) => {
|
|
7865
|
+
if (typeof options !== "object" || options === null || typeof options.behavior === "function" || !hasCSSScrollMargin(element)) {
|
|
7866
|
+
scrollIntoViewIfNeeded(element, options);
|
|
7867
|
+
return;
|
|
7868
|
+
}
|
|
7869
|
+
const { behavior } = options;
|
|
7870
|
+
scrollIntoViewIfNeeded(element, {
|
|
7871
|
+
...options,
|
|
7872
|
+
behavior: (actions) => {
|
|
7873
|
+
for (const { el, left, top } of actions) if (el.scrollTop !== top || el.scrollLeft !== left) el.scroll({
|
|
7874
|
+
behavior,
|
|
7875
|
+
left,
|
|
7876
|
+
top
|
|
7877
|
+
});
|
|
7878
|
+
}
|
|
7879
|
+
});
|
|
7880
|
+
};
|
|
7881
|
+
const getScrollIntoViewScope = (editor, fallback) => hasEditorRuntime(editor) ? getOwnViewPresentation(editor) ?? documentOf(editor) : fallback;
|
|
7882
|
+
const findMountedAncestorRevealStep = (editor, targetRoot) => {
|
|
7883
|
+
if (!hasEditorRuntime(editor)) return null;
|
|
7884
|
+
const owner = getEditorRuntimeOwner(editor);
|
|
7885
|
+
const entryByRoot = new Map(readRootEntries(owner).map((entry) => [entry.root, entry]));
|
|
7886
|
+
const visited = /* @__PURE__ */ new Set([targetRoot]);
|
|
7887
|
+
const queue = [targetRoot];
|
|
7888
|
+
for (const currentRoot of queue) {
|
|
7889
|
+
const entry = entryByRoot.get(currentRoot);
|
|
7890
|
+
if (!entry) continue;
|
|
7891
|
+
for (const edge of entry.owners) {
|
|
7892
|
+
const parentRoot = toInternalRoot(edge.root);
|
|
7893
|
+
const mountedParent = resolveMountedViewForRoot(editor, parentRoot);
|
|
7894
|
+
if (mountedParent) return {
|
|
7895
|
+
ownerPath: edge.path,
|
|
7896
|
+
ownerRoot: parentRoot,
|
|
7897
|
+
ownerView: mountedParent
|
|
7898
|
+
};
|
|
7899
|
+
if (!visited.has(parentRoot)) {
|
|
7900
|
+
visited.add(parentRoot);
|
|
7901
|
+
queue.push(parentRoot);
|
|
7902
|
+
}
|
|
7903
|
+
}
|
|
7904
|
+
}
|
|
7905
|
+
return null;
|
|
7906
|
+
};
|
|
7907
|
+
const getScrollTargetRoot = (editor, target) => {
|
|
7908
|
+
if (!PathApi.isPath(target) && !PointApi.isPoint(target) && !RangeApi.isRange(target)) return null;
|
|
7909
|
+
const explicitRoot = getPublicExplicitLocationRoot(target);
|
|
7910
|
+
if (explicitRoot !== void 0) return toInternalRoot(explicitRoot);
|
|
7911
|
+
if (hasEditorRuntime(editor)) return getEditorRuntimeRoot(editor);
|
|
7912
|
+
return null;
|
|
7913
|
+
};
|
|
7646
7914
|
const setEditableRootReveal = (element, reveal) => {
|
|
7647
|
-
|
|
7915
|
+
const registration = typeof reveal === "function" ? {
|
|
7916
|
+
revealCulled: reveal,
|
|
7917
|
+
revealMounted: reveal
|
|
7918
|
+
} : reveal;
|
|
7919
|
+
ELEMENT_TO_ROOT_REVEAL.set(element, registration);
|
|
7648
7920
|
return () => {
|
|
7649
|
-
if (ELEMENT_TO_ROOT_REVEAL.get(element) ===
|
|
7921
|
+
if (ELEMENT_TO_ROOT_REVEAL.get(element) === registration) ELEMENT_TO_ROOT_REVEAL.delete(element);
|
|
7650
7922
|
};
|
|
7651
7923
|
};
|
|
7652
7924
|
const revealInEditableRoot = (element, path) => {
|
|
7653
7925
|
const root = element.closest("[data-editor-root]");
|
|
7654
|
-
if (root) ELEMENT_TO_ROOT_REVEAL.get(root)?.(path, "auto");
|
|
7926
|
+
if (root) ELEMENT_TO_ROOT_REVEAL.get(root)?.revealMounted?.(path, "auto");
|
|
7655
7927
|
};
|
|
7656
7928
|
const getEditorDOMHostScrollElement = (editor) => EDITOR_TO_DOM_SCROLL.get(documentOf(editor)) ?? null;
|
|
7657
7929
|
const getRegisteredScrollElement = (editor) => getEditorDOMHostScrollElement(editor) ?? EDITOR_TO_DOM_FALLBACK_SCROLL.get(editor) ?? EDITOR_TO_DOM_FALLBACK_SCROLL.get(documentOf(editor));
|
|
@@ -7881,8 +8153,11 @@ const DOMEditorImpl = {
|
|
|
7881
8153
|
},
|
|
7882
8154
|
deselect: (editor) => {
|
|
7883
8155
|
const selection = editor.read((state) => state.selection());
|
|
7884
|
-
const
|
|
7885
|
-
if (
|
|
8156
|
+
const el = DOMEditor.editable(editor);
|
|
8157
|
+
if (el) clearEditableDOMSelection(el, {
|
|
8158
|
+
editor,
|
|
8159
|
+
policy: "owned"
|
|
8160
|
+
});
|
|
7886
8161
|
if (selection) editor.update((tx) => {
|
|
7887
8162
|
tx.selection.set(null);
|
|
7888
8163
|
});
|
|
@@ -7970,11 +8245,6 @@ const DOMEditorImpl = {
|
|
|
7970
8245
|
if (retries <= 0) return;
|
|
7971
8246
|
PAGE_TO_FOCUS_REQUEST_OWNER.set(pageOf(el.ownerDocument), { editor: new WeakRef(editor) });
|
|
7972
8247
|
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
8248
|
if (IS_NODE_MAP_DIRTY.get(editor)) {
|
|
7979
8249
|
let cancel = () => {};
|
|
7980
8250
|
const generation = getPlacementGeneration(editor);
|
|
@@ -7991,8 +8261,10 @@ const DOMEditorImpl = {
|
|
|
7991
8261
|
return;
|
|
7992
8262
|
}
|
|
7993
8263
|
if (findDOMRootRuntime(el)?.focusSelection(el)) return;
|
|
8264
|
+
const activeBeforeCaret = focusedElementOnPage(el);
|
|
7994
8265
|
const selection = ensureFocusCaret(editor, el);
|
|
7995
|
-
if (superseded()) return;
|
|
8266
|
+
if (superseded() || movedFocusElsewhere(el, activeBeforeCaret, focusedElementOnPage(el))) return;
|
|
8267
|
+
const focusPlacement = getPlacementGeneration(editor);
|
|
7996
8268
|
const selectionAtFocus = selection ? getSelectionDOMRange(editor, selection) : null;
|
|
7997
8269
|
const syncDomSelection = () => {
|
|
7998
8270
|
if (findDOMRootRuntime(el)?.isSelectionHeld()) return;
|
|
@@ -8000,7 +8272,7 @@ const DOMEditorImpl = {
|
|
|
8000
8272
|
if (innerSelection) {
|
|
8001
8273
|
const projectedSelection = getSelectionDOMRange(editor, innerSelection);
|
|
8002
8274
|
if (!projectedSelection) {
|
|
8003
|
-
|
|
8275
|
+
clearEditableDOMSelection(el, { editor });
|
|
8004
8276
|
return;
|
|
8005
8277
|
}
|
|
8006
8278
|
const view = reachAt(editor, projectedSelection);
|
|
@@ -8008,7 +8280,10 @@ const DOMEditorImpl = {
|
|
|
8008
8280
|
exportingSelection: true,
|
|
8009
8281
|
rejectStaleText: true
|
|
8010
8282
|
});
|
|
8011
|
-
if (domRange)
|
|
8283
|
+
if (domRange) writeEditableDOMSelection((view && view !== editor ? DOMEditor.editable(view) : null) ?? el, getDOMRangeSelectionPoints(domRange, RangeApi.isBackward(projectedSelection)), {
|
|
8284
|
+
editor: view ?? editor,
|
|
8285
|
+
policy: "focused"
|
|
8286
|
+
});
|
|
8012
8287
|
}
|
|
8013
8288
|
};
|
|
8014
8289
|
const trySyncDomSelection = () => {
|
|
@@ -8026,18 +8301,20 @@ const DOMEditorImpl = {
|
|
|
8026
8301
|
const rootActiveElement = root.activeElement;
|
|
8027
8302
|
const shadowHost = "host" in root ? root.host : null;
|
|
8028
8303
|
const activeElement = rootActiveElement ?? (root === el.ownerDocument ? null : el.ownerDocument.activeElement);
|
|
8029
|
-
if (
|
|
8304
|
+
if (isElementFocused(el)) {
|
|
8305
|
+
if (placedSince(editor, focusPlacement)) return;
|
|
8030
8306
|
trySyncDomSelection();
|
|
8031
8307
|
return;
|
|
8032
8308
|
}
|
|
8033
|
-
if (activeElement
|
|
8309
|
+
if (activeElement && activeElement !== el && activeElement.isConnected && containsShadowAware(el, activeElement)) {
|
|
8034
8310
|
ownedActiveElement = activeElement;
|
|
8035
8311
|
return;
|
|
8036
8312
|
}
|
|
8037
|
-
|
|
8038
|
-
|
|
8313
|
+
const pageActive = focusedElementOnPage(el);
|
|
8314
|
+
if (!(pageActive === null || pageActive === pageActive.ownerDocument.body || rootActiveElement === null && activeElement === shadowHost || activeElement !== null && activeElement === ownedActiveElement && !activeElement.isConnected)) return;
|
|
8315
|
+
const focused = focusEditableElement(editor, el);
|
|
8039
8316
|
if (superseded()) return;
|
|
8040
|
-
trySyncDomSelection();
|
|
8317
|
+
if (focused) trySyncDomSelection();
|
|
8041
8318
|
};
|
|
8042
8319
|
const scheduleFocusSettle = () => {
|
|
8043
8320
|
scheduleEditorDOMPhase(editor, "dom-write", "dom-editor-focus-settle-microtask", settleFocus, {
|
|
@@ -8054,15 +8331,16 @@ const DOMEditorImpl = {
|
|
|
8054
8331
|
timing: "timeout"
|
|
8055
8332
|
});
|
|
8056
8333
|
};
|
|
8057
|
-
if (
|
|
8334
|
+
if (!isElementFocused(el)) {
|
|
8058
8335
|
const { activeElement } = root;
|
|
8059
|
-
if (isDOMElement(activeElement) && containsShadowAware(el, activeElement) && "blur" in activeElement && typeof activeElement.blur === "function") {
|
|
8336
|
+
if (isDOMElement(activeElement) && activeElement !== el && containsShadowAware(el, activeElement) && "blur" in activeElement && typeof activeElement.blur === "function") {
|
|
8337
|
+
const activeBeforeBlur = focusedElementOnPage(el);
|
|
8060
8338
|
activeElement.blur();
|
|
8061
|
-
if (superseded()) return;
|
|
8339
|
+
if (superseded() || movedFocusElsewhere(el, activeBeforeBlur, focusedElementOnPage(el))) return;
|
|
8062
8340
|
}
|
|
8063
|
-
|
|
8341
|
+
const focused = focusEditableElement(editor, el);
|
|
8064
8342
|
if (superseded()) return;
|
|
8065
|
-
trySyncDomSelection();
|
|
8343
|
+
if (focused) trySyncDomSelection();
|
|
8066
8344
|
if (selectionAtFocus) scheduleEditorDOMPhase(editor, "selection-repair", "dom-editor-focus-selection-sync", () => {
|
|
8067
8345
|
if (superseded() || !isElementFocused(el)) return;
|
|
8068
8346
|
const currentSelection = getSelectionDOMRange(editor, resolveNextKeyCaret(editor, el));
|
|
@@ -8185,81 +8463,177 @@ const DOMEditorImpl = {
|
|
|
8185
8463
|
scroll: (editor) => getRegisteredScrollElement(editor) ?? DOMEditor.root(editor) ?? DOMEditor.editable(editor) ?? null,
|
|
8186
8464
|
scrollIntoView: (editor, target, options = { scrollMode: "if-needed" }) => {
|
|
8187
8465
|
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
|
|
8189
|
-
const
|
|
8190
|
-
|
|
8191
|
-
const window = element?.ownerDocument?.defaultView;
|
|
8192
|
-
if (!element || !window) return 0;
|
|
8466
|
+
const readScrollMarginTop = (element) => {
|
|
8467
|
+
const window = element.ownerDocument?.defaultView;
|
|
8468
|
+
if (!window) return 0;
|
|
8193
8469
|
const style = window.getComputedStyle(element);
|
|
8194
8470
|
return Number.parseFloat(element.style.scrollMarginTop || style.scrollMarginTop) || 0;
|
|
8195
|
-
}
|
|
8471
|
+
};
|
|
8472
|
+
const canReadEditor = typeof editor.read === "function";
|
|
8473
|
+
const isLocationTarget = PathApi.isPath(target) || PointApi.isPoint(target) || RangeApi.isRange(target);
|
|
8474
|
+
const targetRoot = canReadEditor ? getScrollTargetRoot(editor, target) : null;
|
|
8475
|
+
const resolveTargetView = () => {
|
|
8476
|
+
if (!canReadEditor) return editor;
|
|
8477
|
+
if (isLocationTarget) return reachAt(editor, target) ?? (targetRoot ? resolveMountedViewForRoot(editor, targetRoot) : null);
|
|
8478
|
+
return hasMountedDocumentView(editor) ? resolveDOMReach(editor) : editor;
|
|
8479
|
+
};
|
|
8480
|
+
const initialView = resolveTargetView();
|
|
8481
|
+
const initialAncestorStep = !initialView && targetRoot ? findMountedAncestorRevealStep(editor, targetRoot) : null;
|
|
8482
|
+
const initialSchedulerView = initialView ?? initialAncestorStep?.ownerView ?? null;
|
|
8483
|
+
if (!initialSchedulerView) return () => {};
|
|
8484
|
+
const scrollScope = getScrollIntoViewScope(editor, initialSchedulerView);
|
|
8485
|
+
const scrollToken = nextScrollIntoViewToken(scrollScope);
|
|
8486
|
+
const isStale = () => cancelled || VIEW_TO_SCROLL_TOKEN.get(scrollScope) !== scrollToken;
|
|
8487
|
+
const initialPathElement = initialView && PathApi.isPath(target) && typeof initialView.read === "function" ? (() => {
|
|
8488
|
+
const node = initialView.read((state) => state.nodes.get(target)?.[0]);
|
|
8489
|
+
return node ? DOMEditor.resolveDOMNode(initialView, node) : null;
|
|
8490
|
+
})() : null;
|
|
8491
|
+
const initialScrollMarginTop = initialPathElement ? readScrollMarginTop(initialPathElement) : 0;
|
|
8492
|
+
const resolveCulledPaths = (view) => {
|
|
8493
|
+
if (PathApi.isPath(target)) return [target];
|
|
8494
|
+
if (PointApi.isPoint(target)) return [target.path];
|
|
8495
|
+
if (!RangeApi.isRange(target)) return [];
|
|
8496
|
+
const startPath = RangeApi.start(target).path;
|
|
8497
|
+
const endPath = RangeApi.end(target).path;
|
|
8498
|
+
if (PathApi.equals(startPath, endPath) || typeof view.read !== "function") return [startPath];
|
|
8499
|
+
const missing = [];
|
|
8500
|
+
const startNode = view.read((state) => state.nodes.get(startPath)?.[0]);
|
|
8501
|
+
const endNode = view.read((state) => state.nodes.get(endPath)?.[0]);
|
|
8502
|
+
if (!startNode || !DOMEditor.resolveDOMNode(view, startNode)) missing.push(startPath);
|
|
8503
|
+
if (!endNode || !DOMEditor.resolveDOMNode(view, endNode)) missing.push(endPath);
|
|
8504
|
+
return missing.length > 0 ? missing : [startPath];
|
|
8505
|
+
};
|
|
8506
|
+
const alwaysMode = typeof options === "object" && options?.scrollMode === "always";
|
|
8507
|
+
const schedulePhase = (schedulerView, label, callback) => scheduleEditorDOMPhase(schedulerView, alwaysMode ? "post-selection" : "dom-write", label, callback, {
|
|
8508
|
+
key: "dom-editor-scroll-into-view",
|
|
8509
|
+
timing: "animation-frame"
|
|
8510
|
+
});
|
|
8511
|
+
let cancelled = false;
|
|
8512
|
+
let retriedTarget = false;
|
|
8513
|
+
const revealedAncestors = /* @__PURE__ */ new Set();
|
|
8514
|
+
let cancelRetry;
|
|
8515
|
+
const revealCulledOnView = (view, paths) => {
|
|
8516
|
+
if (paths.length === 0) return false;
|
|
8517
|
+
const editable = EDITOR_TO_ELEMENT.get(view) ?? (typeof view.read === "function" ? DOMEditorImpl.editable(view) : null);
|
|
8518
|
+
const reveal = editable ? ELEMENT_TO_ROOT_REVEAL.get(editable)?.revealCulled : void 0;
|
|
8519
|
+
if (!reveal) return false;
|
|
8520
|
+
let revealed = false;
|
|
8521
|
+
for (const path of paths) {
|
|
8522
|
+
if (reveal(path, "auto") === true) revealed = true;
|
|
8523
|
+
if (isStale()) return false;
|
|
8524
|
+
}
|
|
8525
|
+
return revealed;
|
|
8526
|
+
};
|
|
8527
|
+
const retryAfterTargetReveal = (view) => {
|
|
8528
|
+
if (isStale() || retriedTarget) return;
|
|
8529
|
+
const paths = resolveCulledPaths(view);
|
|
8530
|
+
if (!revealCulledOnView(view, paths) || isStale()) return;
|
|
8531
|
+
retriedTarget = true;
|
|
8532
|
+
cancelRetry = schedulePhase(view, "dom-editor-scroll-into-view-retry", run);
|
|
8533
|
+
};
|
|
8196
8534
|
const run = () => {
|
|
8535
|
+
if (isStale()) return;
|
|
8536
|
+
const activeView = resolveTargetView();
|
|
8537
|
+
if (!activeView) {
|
|
8538
|
+
if (!targetRoot) return;
|
|
8539
|
+
const step = findMountedAncestorRevealStep(editor, targetRoot);
|
|
8540
|
+
if (!step) return;
|
|
8541
|
+
const stepKey = `${step.ownerRoot}:${step.ownerPath.join(".")}`;
|
|
8542
|
+
if (revealedAncestors.has(stepKey)) return;
|
|
8543
|
+
revealedAncestors.add(stepKey);
|
|
8544
|
+
if (!revealCulledOnView(step.ownerView, [step.ownerPath]) || isStale()) return;
|
|
8545
|
+
cancelRetry = schedulePhase(step.ownerView, "dom-editor-scroll-into-view-ancestor-retry", run);
|
|
8546
|
+
return;
|
|
8547
|
+
}
|
|
8548
|
+
const canReadActiveView = typeof activeView.read === "function";
|
|
8197
8549
|
if (PathApi.isPath(target)) {
|
|
8198
|
-
const node =
|
|
8199
|
-
const element = node ? DOMEditor.resolveDOMNode(
|
|
8200
|
-
if (element) {
|
|
8201
|
-
|
|
8202
|
-
|
|
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);
|
|
8550
|
+
const node = canReadActiveView ? activeView.read((state) => state.nodes.get(target)?.[0]) : void 0;
|
|
8551
|
+
const element = node ? DOMEditor.resolveDOMNode(activeView, node) : null;
|
|
8552
|
+
if (!element) {
|
|
8553
|
+
retryAfterTargetReveal(activeView);
|
|
8554
|
+
return;
|
|
8218
8555
|
}
|
|
8556
|
+
revealInEditableRoot(element, target);
|
|
8557
|
+
const scrollElement = getRegisteredScrollElement(activeView);
|
|
8558
|
+
const requestedScrollMarginTop = initialPathElement ? initialScrollMarginTop : readScrollMarginTop(element);
|
|
8559
|
+
if (scrollElement && requestedScrollMarginTop > 0 && typeof options === "object" && options.block === "start" && options.scrollMode === "always") {
|
|
8560
|
+
const elementRect = element.getBoundingClientRect();
|
|
8561
|
+
const scrollRect = scrollElement.getBoundingClientRect();
|
|
8562
|
+
scrollElement.scroll({
|
|
8563
|
+
behavior: options.behavior ?? "auto",
|
|
8564
|
+
left: scrollElement.scrollLeft,
|
|
8565
|
+
top: scrollElement.scrollTop + elementRect.top - scrollRect.top - requestedScrollMarginTop
|
|
8566
|
+
});
|
|
8567
|
+
} else if (usesDefaultReveal) {
|
|
8568
|
+
const rect = element.getBoundingClientRect();
|
|
8569
|
+
if (isUsableScrollRect(rect)) scrollRectIntoViewIfNeeded({
|
|
8570
|
+
rect: toScrollRect(rect),
|
|
8571
|
+
startElement: element
|
|
8572
|
+
});
|
|
8573
|
+
} else runScrollIntoViewIfNeeded(element, options);
|
|
8219
8574
|
return;
|
|
8220
8575
|
}
|
|
8221
|
-
const domRange = PointApi.isPoint(target) ? DOMEditor.resolveDOMRange(
|
|
8576
|
+
const domRange = PointApi.isPoint(target) ? DOMEditor.resolveDOMRange(activeView, {
|
|
8222
8577
|
anchor: target,
|
|
8223
8578
|
focus: target
|
|
8224
|
-
}) : RangeApi.isRange(target) ? DOMEditor.resolveDOMRange(
|
|
8225
|
-
if (!domRange)
|
|
8579
|
+
}) : RangeApi.isRange(target) ? DOMEditor.resolveDOMRange(activeView, target) : target;
|
|
8580
|
+
if (!domRange) {
|
|
8581
|
+
retryAfterTargetReveal(activeView);
|
|
8582
|
+
return;
|
|
8583
|
+
}
|
|
8226
8584
|
const leafElement = isDOMElement(domRange.startContainer) ? domRange.startContainer : domRange.startContainer.parentElement;
|
|
8227
8585
|
if (!leafElement) return;
|
|
8228
8586
|
if (PointApi.isPoint(target)) revealInEditableRoot(leafElement, target.path);
|
|
8229
8587
|
else if (RangeApi.isRange(target)) revealInEditableRoot(leafElement, RangeApi.start(target).path);
|
|
8230
8588
|
if (usesDefaultReveal) {
|
|
8231
8589
|
const range = RangeApi.isRange(target) ? target : PointApi.isPoint(target) ? null : editor.read((state) => state.selection());
|
|
8232
|
-
|
|
8590
|
+
scrollDOMRangeFocusIntoViewIfNeeded(domRange, Boolean(range && RangeApi.isBackward(range)));
|
|
8233
8591
|
return;
|
|
8234
8592
|
}
|
|
8235
8593
|
const hadOwnRect = Object.hasOwn(leafElement, "getBoundingClientRect");
|
|
8236
8594
|
const originalGetBoundingClientRect = leafElement.getBoundingClientRect;
|
|
8595
|
+
const nearestScrollMarginTop = typeof options === "object" && options !== null && (options.block === void 0 || options.block === "nearest") ? readScrollMarginTop(leafElement) : 0;
|
|
8237
8596
|
leafElement.getBoundingClientRect = () => {
|
|
8238
8597
|
const rangeRect = domRange.getBoundingClientRect();
|
|
8239
|
-
|
|
8598
|
+
const baseRect = isUsableScrollRect(rangeRect) ? rangeRect : originalGetBoundingClientRect.call(leafElement);
|
|
8599
|
+
if (nearestScrollMarginTop <= 0) return baseRect;
|
|
8600
|
+
return {
|
|
8601
|
+
bottom: baseRect.bottom + nearestScrollMarginTop,
|
|
8602
|
+
height: baseRect.height + nearestScrollMarginTop,
|
|
8603
|
+
left: baseRect.left,
|
|
8604
|
+
right: baseRect.right,
|
|
8605
|
+
toJSON: () => baseRect.toJSON?.() ?? {},
|
|
8606
|
+
top: baseRect.top,
|
|
8607
|
+
width: baseRect.width,
|
|
8608
|
+
x: baseRect.x,
|
|
8609
|
+
y: baseRect.y
|
|
8610
|
+
};
|
|
8240
8611
|
};
|
|
8241
8612
|
try {
|
|
8242
|
-
|
|
8613
|
+
runScrollIntoViewIfNeeded(leafElement, options);
|
|
8243
8614
|
} finally {
|
|
8244
8615
|
if (hadOwnRect) leafElement.getBoundingClientRect = originalGetBoundingClientRect;
|
|
8245
8616
|
else Reflect.deleteProperty(leafElement, "getBoundingClientRect");
|
|
8246
8617
|
}
|
|
8247
8618
|
};
|
|
8248
|
-
if (
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
}
|
|
8619
|
+
if (!alwaysMode) {
|
|
8620
|
+
const cancelInitial = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view", run);
|
|
8621
|
+
return () => {
|
|
8622
|
+
cancelled = true;
|
|
8623
|
+
cancelInitial();
|
|
8624
|
+
cancelRetry?.();
|
|
8625
|
+
};
|
|
8626
|
+
}
|
|
8256
8627
|
let cancelScroll;
|
|
8257
|
-
const cancelSettle =
|
|
8258
|
-
|
|
8628
|
+
const cancelSettle = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view-settle", () => {
|
|
8629
|
+
if (cancelled) return;
|
|
8630
|
+
cancelScroll = schedulePhase(initialSchedulerView, "dom-editor-scroll-into-view", run);
|
|
8259
8631
|
});
|
|
8260
8632
|
return () => {
|
|
8633
|
+
cancelled = true;
|
|
8261
8634
|
cancelSettle();
|
|
8262
8635
|
cancelScroll?.();
|
|
8636
|
+
cancelRetry?.();
|
|
8263
8637
|
};
|
|
8264
8638
|
},
|
|
8265
8639
|
resolveNode: (editor, domNode) => {
|
|
@@ -9517,4 +9891,4 @@ const keyToDataAttribute = (key) => `data-editor-${toKebabCase(key)}`;
|
|
|
9517
9891
|
/** Return DOM data attribute names that mirror primitive node properties. */
|
|
9518
9892
|
const getNodeDataAttributeKeys = (node) => Object.keys(node).filter((key) => typeof node[key] !== "object" && (!TextApi.isText(node) || key !== "text")).map((key) => keyToDataAttribute(key));
|
|
9519
9893
|
//#endregion
|
|
9520
|
-
export {
|
|
9894
|
+
export { eventCarriesBlockFragment as $, resolveDOMTextFlowInsertTarget as $n, isElementFocused as $t, createDOMEditorCapability as A, isWebKitDOMHost as An, NODE_TO_PARENT as Ar, SOFT_LINE_END as At, resolveWrittenDOMRange as B, getPliteStringEdgeOffset as Bn, isDOMElement as Br, resolveSoftLineEndDOMPoint as Bt, normalizeRange as C, writeDOMSelection as Cn, ELEMENT_TO_NODE as Cr, writeDOMDataTransferFragment as Ct, DOMEditor as D, isAndroidDOMHost as Dn, IS_READ_ONLY as Dr, observeDataTransferInsertion as Dt, verifyDiffState as E, hasDOMHostQuirk as En, IS_NODE_MAP_DIRTY as Er, dataTransferFormats as Et, isFocusRequestedElsewhere as F, getNearestPliteStringRect as Fn, getFlatTreeParentElement as Fr, isSoftLineTextStale as Ft, subscribeEditorDOMScope as G, getPliteTextHostStrings as Gn, isDOMText as Gr, canWriteEditableDOMSelection as Gt, setEditorDOMEditableElement as H, getPliteStringPlacementAtX as Hn, isDOMInputOrTextArea as Hr, resolvePliteNodePath as Ht, isSelectableDOMSelection as I, getOwnedPliteTextStrings as In, getSelection as Ir, noteAfterInsertCaret as It, writeViewSelectionPart as J, hasUsableDOMRect as Jn, normalizeDOMPoint as Jr, findDOMRootRuntime as Jt, supersedeFocusRequest as K, getTextFlowPointAtCoordinates as Kn, isPlainTextOnlyPaste as Kr, clearEditableDOMSelection as Kt, isTrackedMutation as L, getPliteStringCoordinatePlacement as Ln, hasShadowRoot as Lr, readAfterInsertCaret as Lt, focusEditableElement as M, usesAppleDOMHotkeys as Mn, containsShadowAware as Mr, SOFT_LINE_FLAG as Mt, getEditorDOMHostScrollElement as N, caretShowsPointOffTextFlowCharacters as Nn, getActiveElement as Nr, clearAfterInsertCaret as Nt, DOMResolutionError as O, isBlinkDOMHost as On, NODE_TO_ELEMENT as Or, writeDataTransferFragment as Ot, getOrCreateDOMNodeKey as P, createDOMGeometryKernel as Pn, getDefaultView as Pr, isSoftLineEndBetween as Pt, scrollDOMRangeFocusIntoViewIfNeeded as Q, resolveDOMTextFlowEntry as Qn, hasMountedDOMRoot as Qt, resolveDOMPointInRoot as R, getPliteStringDirectPlacement as Rn, isAfter as Rr, readLowerSoftLineEnd as Rt, normalizePoint as S, sameDOMSelectionPoints as Sn, ELEMENT_TO_EDITOR as Sr, domCommands as St, targetRange as T, getDOMHostLanguage as Tn, IS_FOCUSED as Tr, writeDOMRangeData as Tt, setEditorDOMRootElement as U, getPliteStringPlacementDOMPoint as Un, isDOMNode as Ur, DOMRootRuntime as Ut, setEditableRootReveal as V, getPliteStringLength as Vn, isDOMHTMLElement as Vr, findMountedDOMNodeByPath as Vt, setEditorDOMScrollElement as W, getPliteTextHostBounds as Wn, isDOMSelection as Wr, canWriteDOMSelection as Wt, liftCaretOutOfCollapsedSection as X, readDOMTextFlowPaint as Xn, writeClipboardCut as Xr, focusedElementOnPage as Xt, ensureFocusCaret as Y, isDOMTextFlowSegmentSynchronized as Yn, readClipboardCut as Yr, findEditorDOMRootRuntime as Yt, resolveNextKeyCaret as Z, releaseDOMTextFlowRecordIndex as Zn, getEditorDOMRoot as Zt, TRIPLE_CLICK as _, readDOMSelectionPoints as _n, EDITOR_TO_RUNTIME_ID_TO_KEY as _r, takeDragSession as _t, isLeaf as a, shouldClearEditableDOMSelection as an, DOMCoverage as ar, indicateDOMDropTarget as at, longestCommonPrefixLength as b, readsSelectionAsHost as bn, EDITOR_TO_USER_SELECTION as br, subscribeDropIndicator as bt, isText as c, markDOMSyncMutationTarget as cn, EDITOR_TO_FORCE_RENDER as cr, restDOMBlockDrag as ct, Hotkeys as d, enableKernelTraceRetention as dn, EDITOR_TO_PENDING_DIFFS as dr, clearDragScrollRepaint as dt, isSelectionOwnedByEditable as en, resolveDOMTextFlowOffset as er, resolveBlockFragmentDropRange as et, getLineBoundaryKeyboardMove as f, selectDOMInputDefaultActionPhase as fn, EDITOR_TO_PENDING_INSERTION_MARKS as fr, clearDragSession as ft, isHotkey as g, isDOMSelectionWriteEcho as gn, EDITOR_TO_RUNTIME_ID_TO_ELEMENTS as gr, settleDragSession as gt, createCompiledHotkeyMatcher as h, getDOMRangeSelectionPoints as hn, EDITOR_TO_ROOT_VIEW_EDITORS as hr, setDragScrollRepaint as ht, isElement as i, resolveDOMTargetView as in, setDOMTextFlowRecordIndexes as ir, copyIntentOf as it, findDOMPointElementInRoot as j, supportsDOMBeforeInput as jn, closestShadowAware as jr, SOFT_LINE_END_SELECTOR as jt, claimFocusRequest as k, isGeckoDOMHost as kn, NODE_TO_INDEX as kr, Key as kt, isVoid as l, watchDOMSyncTextMarks as ln, EDITOR_TO_KEY_TO_ELEMENT as lr, beginDragSession as lt, ariaKeyShortcuts as m, forgetDOMSelectionRecordWithin as mn, EDITOR_TO_PLACEHOLDER_ELEMENT as mr, readDragSession as mt, getNodeDataAttributeKeys as n, readEditableDOMSelectionPoints as nn, resolveDOMTextFlowRecordText as nr, intersectClipChain as nt, isNode as o, writeEditableDOMSelection as on, isCollapsedDOMCoverageBoundary as or, pointAt as ot, isPasteWithoutFormatting as p, forgetDOMSelectionRecord as pn, EDITOR_TO_PENDING_SELECTION as pr, isDragSessionClaimed as pt, watchFocusSuperseded as q, getUsableRangeRects as qn, markPlainTextPaste as qr, documentOf as qt, isEditor as r, resolveDOMReach as rn, setDOMTextFlowRecordIndex as rr, walkClipChain as rt, isString as s, isDOMSyncMutation as sn, EDITOR_TO_ELEMENT as sr, resolveDOMDropTarget as st, getElements as t, movedFocusElsewhere as tn, resolveDOMTextFlowRecordDOMText as tr, getDragAutoScrollTarget as tt, keyToDataAttribute as u, scheduleEditorDOMPhase as un, EDITOR_TO_PENDING_ACTION as ur, cancelDragRest as ut, dom as v, readDOMSelectionRange as vn, EDITOR_TO_SCHEDULE_FLUSH as vr, publishDropIndicator as vt, normalizeStringDiff as w, CAN_USE_DOM as wn, IS_COMPOSING as wr, writeDOMFragmentData as wt, mergeStringDiffs as x, recordDOMSelection as xn, EDITOR_TO_WINDOW as xr, cleanDOMClipboardContents as xt, applyStringDiff as y, readDOMSelectionRecord as yn, EDITOR_TO_USER_MARKS as yr, readDropIndicator as yt, resolveDOMRangeInRoot as z, getPliteStringDocumentOffset as zn, isBefore as zr, recordSoftLineEnd as zt };
|