slate-vue3 1.0.1 → 1.0.2

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/dist/dom.js CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as getSelection, A as CAN_USE_DOM, B as IS_IOS, C as MARK_PLACEHOLDER_SYMBOL, D as NODE_TO_PARENT, E as NODE_TO_KEY, F as IS_CHROME, G as closestShadowAware, H as IS_UC_MOBILE, I as IS_CHROME_LEGACY, J as getClipboardData, K as containsShadowAware, L as IS_EDGE_LEGACY, M as IS_ANDROID, N as IS_ANDROID_CHROME_LEGACY, O as PLACEHOLDER_SYMBOL, P as IS_APPLE, Q as getPlainText, R as IS_FIREFOX, S as IS_READ_ONLY, T as NODE_TO_INDEX, U as IS_WEBKIT, V as IS_SAFARI_LEGACY, W as IS_WECHATBROWSER, X as getEditableChild, Y as getDefaultView, Z as getEditableChildAndIndex, _ as EDITOR_TO_USER_SELECTION, a as Hotkeys, at as isDOMElement, b as IS_COMPOSING, c as withDOM, ct as isDOMText, dt as normalizeDOMPoint, et as getSlateFragmentAttribute, f as DOMEditor, g as EDITOR_TO_USER_MARKS, h as EDITOR_TO_ON_CHANGE, i as splitDecorationsByChild, it as isDOMComment, j as HAS_BEFORE_INPUT_SUPPORT, k as Key, lt as isPlainTextOnlyPaste, m as EDITOR_TO_KEY_TO_ELEMENT, n as isTextDecorationsEqual, nt as isAfter, o as applyStringDiff, ot as isDOMNode, p as EDITOR_TO_ELEMENT, q as getActiveElement, r as shallowCompare, rt as isBefore, s as normalizeStringDiff, st as isDOMSelection, t as isElementDecorationsEqual, tt as hasShadowRoot, ut as isTrackedMutation, v as EDITOR_TO_WINDOW, w as NODE_TO_ELEMENT, x as IS_FOCUSED, y as ELEMENT_TO_NODE, z as IS_FIREFOX_LEGACY } from "./slate-dom-cOXt9FLf.js";
2
- export { CAN_USE_DOM, DOMEditor, EDITOR_TO_ELEMENT, EDITOR_TO_KEY_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_USER_MARKS, EDITOR_TO_USER_SELECTION, EDITOR_TO_WINDOW, ELEMENT_TO_NODE, HAS_BEFORE_INPUT_SUPPORT, Hotkeys, IS_ANDROID, IS_ANDROID_CHROME_LEGACY, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_COMPOSING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_READ_ONLY, IS_SAFARI_LEGACY, IS_UC_MOBILE, IS_WEBKIT, IS_WECHATBROWSER, Key, MARK_PLACEHOLDER_SYMBOL, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, applyStringDiff, closestShadowAware, containsShadowAware, getActiveElement, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getPlainText, getSelection, getSlateFragmentAttribute, hasShadowRoot, isAfter, isBefore, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isElementDecorationsEqual, isPlainTextOnlyPaste, isTextDecorationsEqual, isTrackedMutation, normalizeDOMPoint, normalizeStringDiff, shallowCompare, splitDecorationsByChild, withDOM };
1
+ import { $ as getSelection, A as CAN_USE_DOM, B as IS_IOS, C as MARK_PLACEHOLDER_SYMBOL, D as NODE_TO_PARENT, E as NODE_TO_KEY, F as IS_CHROME, G as closestShadowAware, H as IS_UC_MOBILE, I as IS_CHROME_LEGACY, J as getClipboardData, K as containsShadowAware, L as IS_EDGE_LEGACY, M as IS_ANDROID, N as IS_ANDROID_CHROME_LEGACY, O as PLACEHOLDER_SYMBOL, P as IS_APPLE, Q as getPlainText, R as IS_FIREFOX, S as IS_READ_ONLY, T as NODE_TO_INDEX, U as IS_WEBKIT, V as IS_SAFARI_LEGACY, W as IS_WECHATBROWSER, X as getEditableChild, Y as getDefaultView, Z as getEditableChildAndIndex, _ as EDITOR_TO_USER_SELECTION, a as isTextDecorationsEqual, at as isDOMElement, b as IS_COMPOSING, c as Hotkeys, ct as isDOMText, d as withDOM, dt as normalizeDOMPoint, et as getSlateFragmentAttribute, f as DOMEditor, g as EDITOR_TO_USER_MARKS, h as EDITOR_TO_ON_CHANGE, i as isElementDecorationsEqual, it as isDOMComment, j as HAS_BEFORE_INPUT_SUPPORT, k as Key, l as applyStringDiff, lt as isPlainTextOnlyPaste, m as EDITOR_TO_KEY_TO_ELEMENT, n as getFragment, nt as isAfter, o as shallowCompare, ot as isDOMNode, p as EDITOR_TO_ELEMENT, q as getActiveElement, r as nodeFragment, rt as isBefore, s as splitDecorationsByChild, st as isDOMSelection, t as fragment, tt as hasShadowRoot, u as normalizeStringDiff, ut as isTrackedMutation, v as EDITOR_TO_WINDOW, w as NODE_TO_ELEMENT, x as IS_FOCUSED, y as ELEMENT_TO_NODE, z as IS_FIREFOX_LEGACY } from "./slate-dom-CNAZgdb8.js";
2
+ export { CAN_USE_DOM, DOMEditor, EDITOR_TO_ELEMENT, EDITOR_TO_KEY_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_USER_MARKS, EDITOR_TO_USER_SELECTION, EDITOR_TO_WINDOW, ELEMENT_TO_NODE, HAS_BEFORE_INPUT_SUPPORT, Hotkeys, IS_ANDROID, IS_ANDROID_CHROME_LEGACY, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_COMPOSING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_READ_ONLY, IS_SAFARI_LEGACY, IS_UC_MOBILE, IS_WEBKIT, IS_WECHATBROWSER, Key, MARK_PLACEHOLDER_SYMBOL, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, applyStringDiff, closestShadowAware, containsShadowAware, fragment, getActiveElement, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getFragment, getPlainText, getSelection, getSlateFragmentAttribute, hasShadowRoot, isAfter, isBefore, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isElementDecorationsEqual, isPlainTextOnlyPaste, isTextDecorationsEqual, isTrackedMutation, nodeFragment, normalizeDOMPoint, normalizeStringDiff, shallowCompare, splitDecorationsByChild, withDOM };
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
- import { d as reconcileChildren, l as KEY_TO_CHUNK_TREE, u as getChunkTreeForNode } from "./slate-dom-cOXt9FLf.js";
2
- import { C as isEventHandled, D as SLATE_USE_FOCUSED, E as SLATE_USE_ELEMENT, O as SLATE_USE_READ_ONLY, S as isDOMEventTargetInput, T as SLATE_USE_EDITOR, _ as DEFAULT_PLACEHOLDER_RENDER, a as useFocused, b as handleNativeHistoryEvents, c as useReadOnly, d as useEditor, f as Slate, g as DEFAULT_LEAF_RENDER, h as DEFAULT_ELEMENT_RENDER, i as useSelected, k as SLATE_USE_SELECTION, l as useElement, m as DEFAULT_DECORATE_FN, n as useInheritRef, o as Editable, p as DEFAULT_CHUNK_RENDER, r as useSelection, s as useComposing, t as createReactiveEditor, u as useElementIf, v as DEFAULT_SCROLL_INTO_VIEW, w as SLATE_USE_COMPOSING, x as isDOMEventHandled, y as DEFAULT_TEXT_RENDER } from "./slate-vue-CluiGoan.js";
1
+ import { A as SLATE_USE_FOCUSED, C as handleNativeHistoryEvents, D as SLATE_USE_COMPOSING, E as isEventHandled, M as SLATE_USE_SELECTION, O as SLATE_USE_EDITOR, S as DEFAULT_TEXT_RENDER, T as isDOMEventTargetInput, _ as DEFAULT_DECORATE_FN, a as useFocused, b as DEFAULT_PLACEHOLDER_RENDER, c as KEY_TO_CHUNK_TREE, d as useReadOnly, f as useElement, g as DEFAULT_CHUNK_RENDER, h as Slate, i as useSelected, j as SLATE_USE_READ_ONLY, k as SLATE_USE_ELEMENT, l as getChunkTreeForNode, m as useEditor, n as useInheritRef, o as Editable, p as useElementIf, r as useSelection, s as useComposing, t as createReactiveEditor, u as reconcileChildren, v as DEFAULT_ELEMENT_RENDER, w as isDOMEventHandled, x as DEFAULT_SCROLL_INTO_VIEW, y as DEFAULT_LEAF_RENDER } from "./slate-vue-BivbsnlR.js";
3
2
  export { DEFAULT_CHUNK_RENDER, DEFAULT_DECORATE_FN, DEFAULT_ELEMENT_RENDER, DEFAULT_LEAF_RENDER, DEFAULT_PLACEHOLDER_RENDER, DEFAULT_SCROLL_INTO_VIEW, DEFAULT_TEXT_RENDER, Editable, KEY_TO_CHUNK_TREE, SLATE_USE_COMPOSING, SLATE_USE_EDITOR, SLATE_USE_ELEMENT, SLATE_USE_FOCUSED, SLATE_USE_READ_ONLY, SLATE_USE_SELECTION, Slate, createReactiveEditor, getChunkTreeForNode, handleNativeHistoryEvents, isDOMEventHandled, isDOMEventTargetInput, isEventHandled, reconcileChildren, useComposing, useEditor, useElement, useElementIf, useFocused, useInheritRef, useReadOnly, useSelected, useSelection };
@@ -8,3 +8,4 @@ export * from './utils/hotkeys';
8
8
  export * from './utils/key';
9
9
  export * from './utils/range-list';
10
10
  export * from './utils/weak-maps';
11
+ export * from './override';
@@ -0,0 +1,2 @@
1
+ import { EditorInterface } from 'slate';
2
+ export declare const fragment: EditorInterface["fragment"];
@@ -0,0 +1,3 @@
1
+ import { Editor } from 'slate';
2
+ import { WithEditorFirstArg } from 'slate/dist/utils';
3
+ export declare const getFragment: WithEditorFirstArg<Editor["getFragment"]>;
@@ -0,0 +1,3 @@
1
+ export * from './get-fragment';
2
+ export * from './fragment';
3
+ export * from './node-fragment';
@@ -0,0 +1,2 @@
1
+ import { Ancestor, Editor, Range } from 'slate';
2
+ export declare const nodeFragment: <T extends Ancestor = Editor>(editor: Editor, range: Range) => T["children"];
@@ -770,545 +770,6 @@ var findCurrentLineRange = (editor, parentRange) => {
770
770
  return Editor.range(editor, positions[left], parentRangeBoundary);
771
771
  };
772
772
  //#endregion
773
- //#region packages/slate-vue/chunking/chunk-tree-helper.ts
774
- /**
775
- * Traverse and modify a chunk tree
776
- */
777
- var ChunkTreeHelper = class {
778
- /**
779
- * The root of the chunk tree
780
- */
781
- root;
782
- /**
783
- * The ideal size of a chunk
784
- */
785
- chunkSize;
786
- /**
787
- * Whether debug mode is enabled
788
- *
789
- * If enabled, the pointer state will be checked for internal consistency
790
- * after each mutating operation.
791
- */
792
- debug;
793
- /**
794
- * Whether the traversal has reached the end of the chunk tree
795
- *
796
- * When this is true, the pointerChunk and pointerIndex point to the last
797
- * top-level node in the chunk tree, although pointerNode returns null.
798
- */
799
- reachedEnd;
800
- /**
801
- * The chunk containing the current node
802
- */
803
- pointerChunk;
804
- /**
805
- * The index of the current node within pointerChunk
806
- *
807
- * Can be -1 to indicate that the pointer is before the start of the tree.
808
- */
809
- pointerIndex;
810
- /**
811
- * Similar to a Slate path; tracks the path of pointerChunk relative to the
812
- * root.
813
- *
814
- * Used to move the pointer from the current chunk to the parent chunk more
815
- * efficiently.
816
- */
817
- pointerIndexStack;
818
- /**
819
- * Indexing the current chunk's children has a slight time cost, which adds up
820
- * when traversing very large trees, so the current node is cached.
821
- *
822
- * A value of undefined means that the current node is not cached. This
823
- * property must be set to undefined whenever the pointer is moved, unless
824
- * the pointer is guaranteed to point to the same node that it did previously.
825
- */
826
- cachedPointerNode;
827
- constructor(chunkTree, { chunkSize, debug }) {
828
- this.root = chunkTree;
829
- this.chunkSize = chunkSize;
830
- // istanbul ignore next
831
- this.debug = debug ?? false;
832
- this.pointerChunk = chunkTree;
833
- this.pointerIndex = -1;
834
- this.pointerIndexStack = [];
835
- this.reachedEnd = false;
836
- this.validateState();
837
- }
838
- /**
839
- * Move the pointer to the next leaf in the chunk tree
840
- */
841
- readLeaf() {
842
- // istanbul ignore next
843
- if (this.reachedEnd) return null;
844
- while (true) if (this.pointerIndex + 1 < this.pointerSiblings.length) {
845
- this.pointerIndex++;
846
- this.cachedPointerNode = void 0;
847
- break;
848
- } else if (this.pointerChunk.type === "root") {
849
- this.reachedEnd = true;
850
- return null;
851
- } else this.exitChunk();
852
- this.validateState();
853
- this.enterChunkUntilLeaf(false);
854
- return this.pointerNode;
855
- }
856
- /**
857
- * Move the pointer to the previous leaf in the chunk tree
858
- */
859
- returnToPreviousLeaf() {
860
- if (this.reachedEnd) {
861
- this.reachedEnd = false;
862
- this.enterChunkUntilLeaf(true);
863
- return;
864
- }
865
- while (true) if (this.pointerIndex >= 1) {
866
- this.pointerIndex--;
867
- this.cachedPointerNode = void 0;
868
- break;
869
- } else if (this.pointerChunk.type === "root") {
870
- this.pointerIndex = -1;
871
- return;
872
- } else this.exitChunk();
873
- this.validateState();
874
- this.enterChunkUntilLeaf(true);
875
- }
876
- /**
877
- * Insert leaves before the current leaf, leaving the pointer unchanged
878
- */
879
- insertBefore(leaves) {
880
- this.returnToPreviousLeaf();
881
- this.insertAfter(leaves);
882
- this.readLeaf();
883
- }
884
- /**
885
- * Insert leaves after the current leaf, leaving the pointer on the last
886
- * inserted leaf
887
- *
888
- * The insertion algorithm first checks for any chunk we're currently at the
889
- * end of that can receive additional leaves. Next, it tries to insert leaves
890
- * at the starts of any subsequent chunks.
891
- *
892
- * Any remaining leaves are passed to rawInsertAfter to be chunked and
893
- * inserted at the highest possible level.
894
- */
895
- insertAfter(leaves) {
896
- // istanbul ignore next
897
- if (leaves.length === 0) return;
898
- let beforeDepth = 0;
899
- let afterDepth = 0;
900
- while (this.pointerChunk.type === "chunk" && this.pointerIndex === this.pointerSiblings.length - 1) {
901
- const remainingCapacity = this.chunkSize - this.pointerSiblings.length;
902
- const toInsertCount = Math.min(remainingCapacity, leaves.length);
903
- if (toInsertCount > 0) {
904
- const leavesToInsert = leaves.splice(0, toInsertCount);
905
- this.rawInsertAfter(leavesToInsert, beforeDepth);
906
- }
907
- this.exitChunk();
908
- beforeDepth++;
909
- }
910
- if (leaves.length === 0) return;
911
- const rawInsertPointer = this.savePointer();
912
- let finalPointer = null;
913
- if (this.readLeaf()) while (this.pointerChunk.type === "chunk" && this.pointerIndex === 0) {
914
- const remainingCapacity = this.chunkSize - this.pointerSiblings.length;
915
- const toInsertCount = Math.min(remainingCapacity, leaves.length);
916
- if (toInsertCount > 0) {
917
- const leavesToInsert = leaves.splice(-toInsertCount, toInsertCount);
918
- this.pointerIndex = -1;
919
- this.cachedPointerNode = void 0;
920
- this.rawInsertAfter(leavesToInsert, afterDepth);
921
- if (!finalPointer) finalPointer = this.savePointer();
922
- }
923
- this.exitChunk();
924
- afterDepth++;
925
- }
926
- this.restorePointer(rawInsertPointer);
927
- const minDepth = Math.max(beforeDepth, afterDepth);
928
- this.rawInsertAfter(leaves, minDepth);
929
- if (finalPointer) this.restorePointer(finalPointer);
930
- this.validateState();
931
- }
932
- /**
933
- * Remove the current node and decrement the pointer, deleting any ancestor
934
- * chunk that becomes empty as a result
935
- */
936
- remove() {
937
- this.pointerSiblings.splice(this.pointerIndex--, 1);
938
- this.cachedPointerNode = void 0;
939
- if (this.pointerSiblings.length === 0 && this.pointerChunk.type === "chunk") {
940
- this.exitChunk();
941
- this.remove();
942
- } else this.invalidateChunk();
943
- this.validateState();
944
- }
945
- /**
946
- * Add the current chunk and all ancestor chunks to the list of modified
947
- * chunks
948
- */
949
- invalidateChunk() {
950
- for (let c = this.pointerChunk; c.type === "chunk"; c = c.parent) this.root.modifiedChunks.add(c);
951
- }
952
- /**
953
- * Whether the pointer is at the start of the tree
954
- */
955
- get atStart() {
956
- return this.pointerChunk.type === "root" && this.pointerIndex === -1;
957
- }
958
- /**
959
- * The siblings of the current node
960
- */
961
- get pointerSiblings() {
962
- return this.pointerChunk.children;
963
- }
964
- /**
965
- * Get the current node (uncached)
966
- *
967
- * If the pointer is at the start or end of the document, returns null.
968
- *
969
- * Usually, the current node is a chunk leaf, although it can be a chunk
970
- * while insertions are in progress.
971
- */
972
- getPointerNode() {
973
- if (this.reachedEnd || this.pointerIndex === -1) return null;
974
- return this.pointerSiblings[this.pointerIndex];
975
- }
976
- /**
977
- * Cached getter for the current node
978
- */
979
- get pointerNode() {
980
- if (this.cachedPointerNode !== void 0) return this.cachedPointerNode;
981
- const pointerNode = this.getPointerNode();
982
- this.cachedPointerNode = pointerNode;
983
- return pointerNode;
984
- }
985
- /**
986
- * Get the path of a chunk relative to the root, returning null if the chunk
987
- * is not connected to the root
988
- */
989
- getChunkPath(chunk) {
990
- const path = [];
991
- for (let c = chunk; c.type === "chunk"; c = c.parent) {
992
- const index = c.parent.children.indexOf(c);
993
- // istanbul ignore next
994
- if (index === -1) return null;
995
- path.unshift(index);
996
- }
997
- return path;
998
- }
999
- /**
1000
- * Save the current pointer to be restored later
1001
- */
1002
- savePointer() {
1003
- if (this.atStart) return "start";
1004
- // istanbul ignore next
1005
- if (!this.pointerNode) throw new Error("Cannot save pointer when pointerNode is null");
1006
- return {
1007
- chunk: this.pointerChunk,
1008
- node: this.pointerNode
1009
- };
1010
- }
1011
- /**
1012
- * Restore the pointer to a previous state
1013
- */
1014
- restorePointer(savedPointer) {
1015
- if (savedPointer === "start") {
1016
- this.pointerChunk = this.root;
1017
- this.pointerIndex = -1;
1018
- this.pointerIndexStack = [];
1019
- this.reachedEnd = false;
1020
- this.cachedPointerNode = void 0;
1021
- return;
1022
- }
1023
- const { chunk, node } = savedPointer;
1024
- const index = chunk.children.indexOf(node);
1025
- // istanbul ignore next
1026
- if (index === -1) throw new Error("Cannot restore point because saved node is no longer in saved chunk");
1027
- const indexStack = this.getChunkPath(chunk);
1028
- // istanbul ignore next
1029
- if (!indexStack) throw new Error("Cannot restore point because saved chunk is no longer connected to root");
1030
- this.pointerChunk = chunk;
1031
- this.pointerIndex = index;
1032
- this.pointerIndexStack = indexStack;
1033
- this.reachedEnd = false;
1034
- this.cachedPointerNode = node;
1035
- this.validateState();
1036
- }
1037
- /**
1038
- * Assuming the current node is a chunk, move the pointer into that chunk
1039
- *
1040
- * @param end If true, place the pointer on the last node of the chunk.
1041
- * Otherwise, place the pointer on the first node.
1042
- */
1043
- enterChunk(end) {
1044
- // istanbul ignore next
1045
- if (this.pointerNode?.type !== "chunk") throw new Error("Cannot enter non-chunk");
1046
- this.pointerIndexStack.push(this.pointerIndex);
1047
- this.pointerChunk = this.pointerNode;
1048
- this.pointerIndex = end ? this.pointerSiblings.length - 1 : 0;
1049
- this.cachedPointerNode = void 0;
1050
- this.validateState();
1051
- // istanbul ignore next
1052
- if (this.pointerChunk.children.length === 0) throw new Error("Cannot enter empty chunk");
1053
- }
1054
- /**
1055
- * Assuming the current node is a chunk, move the pointer into that chunk
1056
- * repeatedly until the current node is a leaf
1057
- *
1058
- * @param end If true, place the pointer on the last node of the chunk.
1059
- * Otherwise, place the pointer on the first node.
1060
- */
1061
- enterChunkUntilLeaf(end) {
1062
- while (this.pointerNode?.type === "chunk") this.enterChunk(end);
1063
- }
1064
- /**
1065
- * Move the pointer to the parent chunk
1066
- */
1067
- exitChunk() {
1068
- // istanbul ignore next
1069
- if (this.pointerChunk.type === "root") throw new Error("Cannot exit root");
1070
- const previousPointerChunk = this.pointerChunk;
1071
- this.pointerChunk = previousPointerChunk.parent;
1072
- this.pointerIndex = this.pointerIndexStack.pop();
1073
- this.cachedPointerNode = void 0;
1074
- this.validateState();
1075
- }
1076
- /**
1077
- * Insert leaves immediately after the current node, leaving the pointer on
1078
- * the last inserted leaf
1079
- *
1080
- * Leaves are chunked according to the number of nodes already in the parent
1081
- * plus the number of nodes being inserted, or the minimum depth if larger
1082
- */
1083
- rawInsertAfter(leaves, minDepth) {
1084
- if (leaves.length === 0) return;
1085
- const groupIntoChunks = (leaves, parent, perChunk) => {
1086
- if (perChunk === 1) return leaves;
1087
- const chunks = [];
1088
- for (let i = 0; i < this.chunkSize; i++) {
1089
- const chunkNodes = leaves.slice(i * perChunk, (i + 1) * perChunk);
1090
- if (chunkNodes.length === 0) break;
1091
- const chunk = {
1092
- type: "chunk",
1093
- key: new Key(),
1094
- parent,
1095
- children: []
1096
- };
1097
- chunk.children = groupIntoChunks(chunkNodes, chunk, perChunk / this.chunkSize);
1098
- chunks.push(chunk);
1099
- }
1100
- return chunks;
1101
- };
1102
- const newTotal = this.pointerSiblings.length + leaves.length;
1103
- let depthForTotal = 0;
1104
- for (let i = this.chunkSize; i < newTotal; i *= this.chunkSize) depthForTotal++;
1105
- const depth = Math.max(depthForTotal, minDepth);
1106
- const perTopLevelChunk = Math.pow(this.chunkSize, depth);
1107
- const chunks = groupIntoChunks(leaves, this.pointerChunk, perTopLevelChunk);
1108
- this.pointerSiblings.splice(this.pointerIndex + 1, 0, ...chunks);
1109
- this.pointerIndex += chunks.length;
1110
- this.cachedPointerNode = void 0;
1111
- this.invalidateChunk();
1112
- this.validateState();
1113
- }
1114
- /**
1115
- * If debug mode is enabled, ensure that the state is internally consistent
1116
- */
1117
- // istanbul ignore next
1118
- validateState() {
1119
- if (!this.debug) return;
1120
- const validateDescendant = (node) => {
1121
- if (node.type === "chunk") {
1122
- const { parent, children } = node;
1123
- if (!parent.children.includes(node)) throw new Error(`Debug: Chunk ${node.key.id} has an incorrect parent property`);
1124
- children.forEach(validateDescendant);
1125
- }
1126
- };
1127
- this.root.children.forEach(validateDescendant);
1128
- if (this.cachedPointerNode !== void 0 && this.cachedPointerNode !== this.getPointerNode()) throw new Error("Debug: The cached pointer is incorrect and has not been invalidated");
1129
- const actualIndexStack = this.getChunkPath(this.pointerChunk);
1130
- if (!actualIndexStack) throw new Error("Debug: The pointer chunk is not connected to the root");
1131
- if (!Path.equals(this.pointerIndexStack, actualIndexStack)) throw new Error(`Debug: The cached index stack [${this.pointerIndexStack.join(", ")}] does not match the path of the pointer chunk [${actualIndexStack.join(", ")}]`);
1132
- }
1133
- };
1134
- //#endregion
1135
- //#region packages/slate-vue/chunking/children-helper.ts
1136
- /**
1137
- * Traverse an array of children, providing helpers useful for reconciling the
1138
- * children array with a chunk tree
1139
- */
1140
- var ChildrenHelper = class {
1141
- editor;
1142
- children;
1143
- /**
1144
- * Sparse array of Slate node keys, each index corresponding to an index in
1145
- * the children array
1146
- *
1147
- * Fetching the key for a Slate node is expensive, so we cache them here.
1148
- */
1149
- cachedKeys;
1150
- /**
1151
- * The index of the next node to be read in the children array
1152
- */
1153
- pointerIndex;
1154
- constructor(editor, children) {
1155
- this.editor = editor;
1156
- this.children = children;
1157
- this.cachedKeys = new Array(children.length);
1158
- this.pointerIndex = 0;
1159
- }
1160
- /**
1161
- * Read a given number of nodes, advancing the pointer by that amount
1162
- */
1163
- read(n) {
1164
- if (n === 1) return [this.children[this.pointerIndex++]];
1165
- const slicedChildren = this.remaining(n);
1166
- this.pointerIndex += n;
1167
- return slicedChildren;
1168
- }
1169
- /**
1170
- * Get the remaining children without advancing the pointer
1171
- *
1172
- * @param [maxChildren] Limit the number of children returned.
1173
- */
1174
- remaining(maxChildren) {
1175
- if (maxChildren === void 0) return this.children.slice(this.pointerIndex);
1176
- return this.children.slice(this.pointerIndex, this.pointerIndex + maxChildren);
1177
- }
1178
- /**
1179
- * Whether all children have been read
1180
- */
1181
- get reachedEnd() {
1182
- return this.pointerIndex >= this.children.length;
1183
- }
1184
- /**
1185
- * Determine whether a node with a given key appears in the unread part of the
1186
- * children array, and return its index relative to the current pointer if so
1187
- *
1188
- * Searching for the node object itself using indexOf is most efficient, but
1189
- * will fail to locate nodes that have been modified. In this case, nodes
1190
- * should be identified by their keys instead.
1191
- *
1192
- * Searching an array of keys using indexOf is very inefficient since fetching
1193
- * the keys for all children in advance is very slow. Insead, if the node
1194
- * search fails to return a value, fetch the keys of each remaining child one
1195
- * by one and compare it to the known key.
1196
- */
1197
- lookAhead(node, key) {
1198
- const elementResult = this.children.indexOf(node, this.pointerIndex);
1199
- if (elementResult > -1) return elementResult - this.pointerIndex;
1200
- for (let i = this.pointerIndex; i < this.children.length; i++) {
1201
- const candidateNode = this.children[i];
1202
- if (this.findKey(candidateNode, i) === key) return i - this.pointerIndex;
1203
- }
1204
- return -1;
1205
- }
1206
- /**
1207
- * Convert an array of Slate nodes to an array of chunk leaves, each
1208
- * containing the node and its key
1209
- */
1210
- toChunkLeaves(nodes, startIndex) {
1211
- return nodes.map((node, i) => ({
1212
- type: "leaf",
1213
- node,
1214
- key: this.findKey(node, startIndex + i),
1215
- index: startIndex + i
1216
- }));
1217
- }
1218
- /**
1219
- * Get the key for a Slate node, cached using the node's index
1220
- */
1221
- findKey(node, index) {
1222
- const cachedKey = this.cachedKeys[index];
1223
- if (cachedKey) return cachedKey;
1224
- const key = DOMEditor.findKey(this.editor, node);
1225
- this.cachedKeys[index] = key;
1226
- return key;
1227
- }
1228
- };
1229
- //#endregion
1230
- //#region packages/slate-vue/chunking/reconcile-children.ts
1231
- /**
1232
- * Update the chunk tree to match the children array, inserting, removing and
1233
- * updating differing nodes
1234
- */
1235
- var reconcileChildren = (editor, { chunkTree, children, chunkSize, rerenderChildren = [], onInsert, onUpdate, onIndexChange, debug }) => {
1236
- const chunkTreeHelper = new ChunkTreeHelper(chunkTree, {
1237
- chunkSize,
1238
- debug
1239
- });
1240
- const childrenHelper = new ChildrenHelper(editor, children);
1241
- let treeLeaf;
1242
- while (treeLeaf = chunkTreeHelper.readLeaf()) {
1243
- const lookAhead = childrenHelper.lookAhead(treeLeaf.node, treeLeaf.key);
1244
- const wasMoved = lookAhead > 0 && chunkTree.movedNodeKeys.has(treeLeaf.key);
1245
- if (lookAhead === -1 || wasMoved) {
1246
- chunkTreeHelper.remove();
1247
- continue;
1248
- }
1249
- const insertedChildrenStartIndex = childrenHelper.pointerIndex;
1250
- const insertedChildren = childrenHelper.read(lookAhead + 1);
1251
- const matchingChild = insertedChildren.pop();
1252
- if (insertedChildren.length) {
1253
- const leavesToInsert = childrenHelper.toChunkLeaves(insertedChildren, insertedChildrenStartIndex);
1254
- chunkTreeHelper.insertBefore(leavesToInsert);
1255
- insertedChildren.forEach((node, relativeIndex) => {
1256
- onInsert?.(node, insertedChildrenStartIndex + relativeIndex);
1257
- });
1258
- }
1259
- const matchingChildIndex = childrenHelper.pointerIndex - 1;
1260
- if (treeLeaf.node !== matchingChild) {
1261
- treeLeaf.node = matchingChild;
1262
- chunkTreeHelper.invalidateChunk();
1263
- onUpdate?.(matchingChild, matchingChildIndex);
1264
- }
1265
- if (treeLeaf.index !== matchingChildIndex) {
1266
- treeLeaf.index = matchingChildIndex;
1267
- onIndexChange?.(matchingChild, matchingChildIndex);
1268
- }
1269
- if (rerenderChildren.includes(matchingChildIndex)) chunkTreeHelper.invalidateChunk();
1270
- }
1271
- if (!childrenHelper.reachedEnd) {
1272
- const remainingChildren = childrenHelper.remaining();
1273
- const leavesToInsert = childrenHelper.toChunkLeaves(remainingChildren, childrenHelper.pointerIndex);
1274
- chunkTreeHelper.returnToPreviousLeaf();
1275
- chunkTreeHelper.insertAfter(leavesToInsert);
1276
- remainingChildren.forEach((node, relativeIndex) => {
1277
- onInsert?.(node, childrenHelper.pointerIndex + relativeIndex);
1278
- });
1279
- }
1280
- chunkTree.movedNodeKeys.clear();
1281
- };
1282
- //#endregion
1283
- //#region packages/slate-vue/chunking/get-chunk-tree-for-node.ts
1284
- var KEY_TO_CHUNK_TREE = /* @__PURE__ */ new WeakMap();
1285
- /**
1286
- * Get or create the chunk tree for a Slate node
1287
- *
1288
- * If the reconcile option is provided, the chunk tree will be updated to
1289
- * match the current children of the node. The children are chunked
1290
- * automatically using the given chunk size.
1291
- */
1292
- var getChunkTreeForNode = (editor, node, options = {}) => {
1293
- const key = DOMEditor.findKey(editor, node);
1294
- let chunkTree = KEY_TO_CHUNK_TREE.get(key);
1295
- if (!chunkTree) {
1296
- chunkTree = {
1297
- type: "root",
1298
- movedNodeKeys: /* @__PURE__ */ new Set(),
1299
- modifiedChunks: /* @__PURE__ */ new Set(),
1300
- children: []
1301
- };
1302
- KEY_TO_CHUNK_TREE.set(key, chunkTree);
1303
- }
1304
- if (options.reconcile) reconcileChildren(editor, {
1305
- chunkTree,
1306
- children: node.children,
1307
- ...options.reconcile
1308
- });
1309
- return chunkTree;
1310
- };
1311
- //#endregion
1312
773
  //#region packages/slate-dom/plugin/with-dom.ts
1313
774
  /**
1314
775
  * `withDOM` adds DOM specific behaviors to the editor.
@@ -1346,15 +807,6 @@ var withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
1346
807
  }
1347
808
  };
1348
809
  e.apply = (op) => {
1349
- if (op.type === "move_node") {
1350
- const parent = Node.parent(e, op.path);
1351
- if (!!e.getChunkSize(parent)) {
1352
- const node = Node.get(e, op.path);
1353
- const chunkTree = getChunkTreeForNode(e, parent);
1354
- const key = DOMEditor.findKey(e, node);
1355
- chunkTree.movedNodeKeys.add(key);
1356
- }
1357
- }
1358
810
  const matches = [];
1359
811
  const pathRefMatches = [];
1360
812
  switch (op.type) {
@@ -1871,4 +1323,82 @@ var splitDecorationsByChild = (editor, node, decorations) => {
1871
1323
  return decorationsByChild;
1872
1324
  };
1873
1325
  //#endregion
1874
- export { getSelection as $, CAN_USE_DOM as A, IS_IOS as B, MARK_PLACEHOLDER_SYMBOL as C, NODE_TO_PARENT as D, NODE_TO_KEY as E, IS_CHROME as F, closestShadowAware as G, IS_UC_MOBILE as H, IS_CHROME_LEGACY as I, getClipboardData as J, containsShadowAware as K, IS_EDGE_LEGACY as L, IS_ANDROID as M, IS_ANDROID_CHROME_LEGACY as N, PLACEHOLDER_SYMBOL as O, IS_APPLE as P, getPlainText as Q, IS_FIREFOX as R, IS_READ_ONLY as S, NODE_TO_INDEX as T, IS_WEBKIT as U, IS_SAFARI_LEGACY as V, IS_WECHATBROWSER as W, getEditableChild as X, getDefaultView as Y, getEditableChildAndIndex as Z, EDITOR_TO_USER_SELECTION as _, Hotkeys as a, isDOMElement as at, IS_COMPOSING as b, withDOM as c, isDOMText as ct, reconcileChildren as d, normalizeDOMPoint as dt, getSlateFragmentAttribute as et, DOMEditor as f, EDITOR_TO_USER_MARKS as g, EDITOR_TO_ON_CHANGE as h, splitDecorationsByChild as i, isDOMComment as it, HAS_BEFORE_INPUT_SUPPORT as j, Key as k, KEY_TO_CHUNK_TREE as l, isPlainTextOnlyPaste as lt, EDITOR_TO_KEY_TO_ELEMENT as m, isTextDecorationsEqual as n, isAfter as nt, applyStringDiff as o, isDOMNode as ot, EDITOR_TO_ELEMENT as p, getActiveElement as q, shallowCompare as r, isBefore as rt, normalizeStringDiff as s, isDOMSelection as st, isElementDecorationsEqual as t, hasShadowRoot as tt, getChunkTreeForNode as u, isTrackedMutation as ut, EDITOR_TO_WINDOW as v, NODE_TO_ELEMENT as w, IS_FOCUSED as x, ELEMENT_TO_NODE as y, IS_FIREFOX_LEGACY as z };
1326
+ //#region packages/slate-dom/override/node-fragment.ts
1327
+ var nodeFragment = (editor, range) => {
1328
+ const [start, end] = Range.edges(range);
1329
+ /**
1330
+ * 判断 path 是否是 ancestorPath 的前缀。
1331
+ */
1332
+ const isPrefix = (ancestorPath, path) => {
1333
+ if (ancestorPath.length > path.length) return false;
1334
+ for (let i = 0; i < ancestorPath.length; i++) if (ancestorPath[i] !== path[i]) return false;
1335
+ return true;
1336
+ };
1337
+ const buildChildren = (children, path) => {
1338
+ const depth = path.length;
1339
+ const startInside = isPrefix(path, start.path);
1340
+ const endInside = isPrefix(path, end.path);
1341
+ let from = 0;
1342
+ let to = children.length;
1343
+ if (startInside) from = start.path[depth];
1344
+ if (endInside) to = end.path[depth] + 1;
1345
+ const result = [];
1346
+ for (let i = from; i < to; i++) {
1347
+ const child = children[i];
1348
+ const childPath = [...path, i];
1349
+ const isStartBoundary = startInside && start.path.length > depth && start.path[depth] === i;
1350
+ const isEndBoundary = endInside && end.path.length > depth && end.path[depth] === i;
1351
+ /**
1352
+ * 这个 child 是 start/end 路径上的边界,
1353
+ * 需要继续进入它。
1354
+ */
1355
+ if (isStartBoundary || isEndBoundary) {
1356
+ if ("text" in child) {
1357
+ let text = child.text;
1358
+ /**
1359
+ * start 和 end 落在同一个 leaf。
1360
+ */
1361
+ if (childPath.length === start.path.length && childPath.length === end.path.length && start.path.every((value, index) => value === end.path[index])) text = text.slice(start.offset, end.offset);
1362
+ else {
1363
+ if (childPath.length === start.path.length && start.path.every((value, index) => value === childPath[index])) text = text.slice(start.offset);
1364
+ if (childPath.length === end.path.length && end.path.every((value, index) => value === childPath[index])) text = text.slice(0, end.offset);
1365
+ }
1366
+ result.push({
1367
+ ...child,
1368
+ text
1369
+ });
1370
+ } else
1371
+ /**
1372
+ * 只有边界 ancestor 需要 clone。
1373
+ */
1374
+ result.push({
1375
+ ...child,
1376
+ children: buildChildren(child.children, childPath)
1377
+ });
1378
+ continue;
1379
+ }
1380
+ /**
1381
+ * 完整包含在 selection 中的 subtree。
1382
+ *
1383
+ * 不需要 clone。
1384
+ */
1385
+ result.push(child);
1386
+ }
1387
+ return result;
1388
+ };
1389
+ return buildChildren(editor.children, []);
1390
+ };
1391
+ //#endregion
1392
+ //#region packages/slate-dom/override/get-fragment.ts
1393
+ var getFragment = (editor) => {
1394
+ const { selection } = editor;
1395
+ if (selection) return nodeFragment(editor, selection);
1396
+ return [];
1397
+ };
1398
+ //#endregion
1399
+ //#region packages/slate-dom/override/fragment.ts
1400
+ var fragment = (editor, at) => {
1401
+ return nodeFragment(editor, Editor.range(editor, at));
1402
+ };
1403
+ //#endregion
1404
+ export { getSelection as $, CAN_USE_DOM as A, IS_IOS as B, MARK_PLACEHOLDER_SYMBOL as C, NODE_TO_PARENT as D, NODE_TO_KEY as E, IS_CHROME as F, closestShadowAware as G, IS_UC_MOBILE as H, IS_CHROME_LEGACY as I, getClipboardData as J, containsShadowAware as K, IS_EDGE_LEGACY as L, IS_ANDROID as M, IS_ANDROID_CHROME_LEGACY as N, PLACEHOLDER_SYMBOL as O, IS_APPLE as P, getPlainText as Q, IS_FIREFOX as R, IS_READ_ONLY as S, NODE_TO_INDEX as T, IS_WEBKIT as U, IS_SAFARI_LEGACY as V, IS_WECHATBROWSER as W, getEditableChild as X, getDefaultView as Y, getEditableChildAndIndex as Z, EDITOR_TO_USER_SELECTION as _, isTextDecorationsEqual as a, isDOMElement as at, IS_COMPOSING as b, Hotkeys as c, isDOMText as ct, withDOM as d, normalizeDOMPoint as dt, getSlateFragmentAttribute as et, DOMEditor as f, EDITOR_TO_USER_MARKS as g, EDITOR_TO_ON_CHANGE as h, isElementDecorationsEqual as i, isDOMComment as it, HAS_BEFORE_INPUT_SUPPORT as j, Key as k, applyStringDiff as l, isPlainTextOnlyPaste as lt, EDITOR_TO_KEY_TO_ELEMENT as m, getFragment as n, isAfter as nt, shallowCompare as o, isDOMNode as ot, EDITOR_TO_ELEMENT as p, getActiveElement as q, nodeFragment as r, isBefore as rt, splitDecorationsByChild as s, isDOMSelection as st, fragment as t, hasShadowRoot as tt, normalizeStringDiff as u, isTrackedMutation as ut, EDITOR_TO_WINDOW as v, NODE_TO_ELEMENT as w, IS_FOCUSED as x, ELEMENT_TO_NODE as y, IS_FIREFOX_LEGACY as z };