slate-vue3 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core.js +3 -3
- package/dist/{create-editor-BEF9fMF8.js → create-editor-C9yJ-Zny.js} +40 -13
- package/dist/dom.js +87 -111
- package/dist/history.js +7 -4
- package/dist/{hotkeys-B9cuO97x.js → hotkeys-DpQWNvFe.js} +59 -42
- package/dist/hyperscript.js +8 -4
- package/dist/{index-CCzZ6aOH.js → index-Bj4hXlPm.js} +11 -5
- package/dist/index.js +4 -4
- package/dist/{location-Be5j1v5S.js → location-Ca0TF-GI.js} +1 -1
- package/dist/slate/core/apply.d.ts +1 -1
- package/dist/slate/core/get-dirty-paths.d.ts +1 -1
- package/dist/slate/core/get-fragment.d.ts +1 -1
- package/dist/slate/core/normalize-node.d.ts +1 -1
- package/dist/slate/core/should-normalize.d.ts +1 -1
- package/dist/slate/editor/above.d.ts +1 -1
- package/dist/slate/editor/add-mark.d.ts +1 -1
- package/dist/slate/editor/after.d.ts +1 -1
- package/dist/slate/editor/before.d.ts +1 -1
- package/dist/slate/editor/delete-backward.d.ts +1 -1
- package/dist/slate/editor/delete-forward.d.ts +1 -1
- package/dist/slate/editor/delete-fragment.d.ts +1 -1
- package/dist/slate/editor/edges.d.ts +1 -1
- package/dist/slate/editor/element-read-only.d.ts +1 -1
- package/dist/slate/editor/end.d.ts +1 -1
- package/dist/slate/editor/first.d.ts +1 -1
- package/dist/slate/editor/fragment.d.ts +1 -1
- package/dist/slate/editor/get-void.d.ts +1 -1
- package/dist/slate/editor/has-blocks.d.ts +1 -1
- package/dist/slate/editor/has-inlines.d.ts +1 -1
- package/dist/slate/editor/has-path.d.ts +1 -1
- package/dist/slate/editor/has-texts.d.ts +1 -1
- package/dist/slate/editor/insert-break.d.ts +1 -1
- package/dist/slate/editor/insert-node.d.ts +1 -1
- package/dist/slate/editor/insert-soft-break.d.ts +1 -1
- package/dist/slate/editor/insert-text.d.ts +1 -1
- package/dist/slate/editor/is-block.d.ts +1 -1
- package/dist/slate/editor/is-edge.d.ts +1 -1
- package/dist/slate/editor/is-editor.d.ts +1 -1
- package/dist/slate/editor/is-empty.d.ts +1 -1
- package/dist/slate/editor/is-end.d.ts +1 -1
- package/dist/slate/editor/is-normalizing.d.ts +1 -1
- package/dist/slate/editor/is-start.d.ts +1 -1
- package/dist/slate/editor/last.d.ts +1 -1
- package/dist/slate/editor/leaf.d.ts +1 -1
- package/dist/slate/editor/marks.d.ts +1 -1
- package/dist/slate/editor/next.d.ts +1 -1
- package/dist/slate/editor/node.d.ts +1 -1
- package/dist/slate/editor/normalize.d.ts +1 -1
- package/dist/slate/editor/parent.d.ts +1 -1
- package/dist/slate/editor/path-ref.d.ts +1 -1
- package/dist/slate/editor/path-refs.d.ts +1 -1
- package/dist/slate/editor/path.d.ts +1 -1
- package/dist/slate/editor/point-ref.d.ts +1 -1
- package/dist/slate/editor/point-refs.d.ts +1 -1
- package/dist/slate/editor/point.d.ts +1 -1
- package/dist/slate/editor/previous.d.ts +1 -1
- package/dist/slate/editor/range-ref.d.ts +1 -1
- package/dist/slate/editor/range-refs.d.ts +1 -1
- package/dist/slate/editor/range.d.ts +1 -1
- package/dist/slate/editor/remove-mark.d.ts +1 -1
- package/dist/slate/editor/set-normalizing.d.ts +1 -1
- package/dist/slate/editor/should-merge-nodes-remove-prev-node.d.ts +1 -1
- package/dist/slate/editor/start.d.ts +1 -1
- package/dist/slate/editor/string.d.ts +1 -1
- package/dist/slate/editor/unhang-range.d.ts +1 -1
- package/dist/slate/editor/without-normalizing.d.ts +1 -1
- package/dist/slate/interfaces/editor.d.ts +4 -4
- package/dist/slate/interfaces/element.d.ts +1 -1
- package/dist/slate/interfaces/node.d.ts +2 -2
- package/dist/slate/interfaces/operation.d.ts +21 -21
- package/dist/slate/interfaces/path-ref.d.ts +1 -1
- package/dist/slate/interfaces/point.d.ts +2 -2
- package/dist/slate/interfaces/range-ref.d.ts +1 -1
- package/dist/slate/interfaces/range.d.ts +1 -1
- package/dist/slate/interfaces/text.d.ts +1 -1
- package/dist/slate/transforms-node/insert-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/lift-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/merge-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/move-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/remove-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/set-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/split-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/unset-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/unwrap-nodes.d.ts +1 -1
- package/dist/slate/transforms-node/wrap-nodes.d.ts +1 -1
- package/dist/slate/transforms-selection/collapse.d.ts +1 -1
- package/dist/slate/transforms-selection/deselect.d.ts +1 -1
- package/dist/slate/transforms-selection/move.d.ts +1 -1
- package/dist/slate/transforms-selection/select.d.ts +1 -1
- package/dist/slate/transforms-selection/set-point.d.ts +1 -1
- package/dist/slate/transforms-selection/set-selection.d.ts +1 -1
- package/dist/slate/transforms-text/delete-text.d.ts +1 -1
- package/dist/slate/transforms-text/insert-fragment.d.ts +1 -1
- package/dist/slate/types/custom-types.d.ts +1 -1
- package/dist/slate/types/types.d.ts +10 -10
- package/dist/slate/utils/types.d.ts +1 -1
- package/dist/slate-dom/chunking/children-helper.d.ts +1 -1
- package/dist/slate-dom/chunking/get-chunk-tree-for-node.d.ts +1 -4
- package/dist/slate-dom/chunking/reconcile-children.d.ts +1 -3
- package/dist/slate-dom/chunking/types.d.ts +3 -3
- package/dist/slate-dom/index.d.ts +1 -1
- package/dist/slate-dom/utils/dom.d.ts +3 -3
- package/dist/slate-hyperscript/hyperscript.d.ts +1 -1
- package/dist/slate-hyperscript/index.d.ts +1 -1
- package/dist/slate-vue/hooks/use-editor.d.ts +2 -7
- package/dist/slate-vue/hooks/use-render.d.ts +2 -2
- package/dist/slate-vue/index.d.ts +1 -1
- package/dist/slate-vue/utils/interface.d.ts +2 -2
- package/dist/slate-yjs/hooks/useRemoteCursorOverlayPositions.d.ts +1 -1
- package/dist/slate-yjs/hooks/utils.d.ts +1 -1
- package/dist/slate-yjs/index.d.ts +3 -3
- package/dist/slate-yjs/utils/position.d.ts +1 -1
- package/dist/slate-yjs/utils/slate.d.ts +1 -1
- package/dist/slate-yjs/utils/yjs.d.ts +1 -1
- package/dist/{use-focused-Dy4w0CWr.js → use-focused-MykI6tSp.js} +63 -39
- package/dist/yjs.js +15 -14
- package/package.json +31 -11
package/README.md
CHANGED
package/dist/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-
|
|
2
|
-
import { E as E2, a as a10, I as I2, N as N2, O as O2, P as P2, b as b2, R as R2, S as S2, T as T2, c as c2, i as i2, d as d2 } from "./index-
|
|
3
|
-
import { L as L2, S as S3 } from "./location-
|
|
1
|
+
import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-C9yJ-Zny.js";
|
|
2
|
+
import { E as E2, a as a10, I as I2, N as N2, O as O2, P as P2, b as b2, R as R2, S as S2, T as T2, c as c2, i as i2, d as d2 } from "./index-Bj4hXlPm.js";
|
|
3
|
+
import { L as L2, S as S3 } from "./location-Ca0TF-GI.js";
|
|
4
4
|
export {
|
|
5
5
|
E2 as Editor,
|
|
6
6
|
a10 as Element,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as Path, b as Point, R as Range, E as Editor, c as Transforms, T as Text, N as Node, a as Element, e as cloneDeep, g as getDefaultInsertLocation, S as Scrubber, I as IS_EDITOR_SET } from "./index-
|
|
2
|
-
import { reactive } from "vue";
|
|
3
|
-
import { S as Span } from "./location-
|
|
1
|
+
import { P as Path, b as Point, R as Range, E as Editor, c as Transforms, T as Text, N as Node, a as Element, e as cloneDeep, g as getDefaultInsertLocation, S as Scrubber, I as IS_EDITOR_SET } from "./index-Bj4hXlPm.js";
|
|
2
|
+
import { shallowReactive, reactive } from "vue";
|
|
3
|
+
import { S as Span } from "./location-Ca0TF-GI.js";
|
|
4
4
|
const PathRef = {
|
|
5
5
|
transform(ref, op) {
|
|
6
6
|
const { current, affinity } = ref;
|
|
@@ -180,7 +180,10 @@ const isLowSurrogate = (charCode) => {
|
|
|
180
180
|
};
|
|
181
181
|
const reExtend = /^[\p{Gr_Ext}\p{EMod}]$/u;
|
|
182
182
|
const rePrepend = /^[\u0600-\u0605\u06DD\u070F\u0890-\u0891\u08E2\u0D4E\u{110BD}\u{110CD}\u{111C2}-\u{111C3}\u{1193F}\u{11941}\u{11A3A}\u{11A84}-\u{11A89}\u{11D46}]$/u;
|
|
183
|
-
const reSpacingMark =
|
|
183
|
+
const reSpacingMark = (
|
|
184
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
185
|
+
/^[\u0903\u093B\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0982-\u0983\u09BF-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u0A03\u0A3E-\u0A40\u0A83\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0B02-\u0B03\u0B40\u0B47-\u0B48\u0B4B-\u0B4C\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0C01-\u0C03\u0C41-\u0C44\u0C82-\u0C83\u0CBE\u0CC0-\u0CC1\u0CC3-\u0CC4\u0CC7-\u0CC8\u0CCA-\u0CCB\u0D02-\u0D03\u0D3F-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D82-\u0D83\u0DD0-\u0DD1\u0DD8-\u0DDE\u0DF2-\u0DF3\u0E33\u0EB3\u0F3E-\u0F3F\u0F7F\u1031\u103B-\u103C\u1056-\u1057\u1084\u1715\u1734\u17B6\u17BE-\u17C5\u17C7-\u17C8\u1923-\u1926\u1929-\u192B\u1930-\u1931\u1933-\u1938\u1A19-\u1A1A\u1A55\u1A57\u1A6D-\u1A72\u1B04\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B82\u1BA1\u1BA6-\u1BA7\u1BAA\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1C24-\u1C2B\u1C34-\u1C35\u1CE1\u1CF7\uA823-\uA824\uA827\uA880-\uA881\uA8B4-\uA8C3\uA952-\uA953\uA983\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BE-\uA9C0\uAA2F-\uAA30\uAA33-\uAA34\uAA4D\uAAEB\uAAEE-\uAAEF\uAAF5\uABE3-\uABE4\uABE6-\uABE7\uABE9-\uABEA\uABEC\u{11000}\u{11002}\u{11082}\u{110B0}-\u{110B2}\u{110B7}-\u{110B8}\u{1112C}\u{11145}-\u{11146}\u{11182}\u{111B3}-\u{111B5}\u{111BF}-\u{111C0}\u{111CE}\u{1122C}-\u{1122E}\u{11232}-\u{11233}\u{11235}\u{112E0}-\u{112E2}\u{11302}-\u{11303}\u{1133F}\u{11341}-\u{11344}\u{11347}-\u{11348}\u{1134B}-\u{1134D}\u{11362}-\u{11363}\u{11435}-\u{11437}\u{11440}-\u{11441}\u{11445}\u{114B1}-\u{114B2}\u{114B9}\u{114BB}-\u{114BC}\u{114BE}\u{114C1}\u{115B0}-\u{115B1}\u{115B8}-\u{115BB}\u{115BE}\u{11630}-\u{11632}\u{1163B}-\u{1163C}\u{1163E}\u{116AC}\u{116AE}-\u{116AF}\u{116B6}\u{11726}\u{1182C}-\u{1182E}\u{11838}\u{11931}-\u{11935}\u{11937}-\u{11938}\u{1193D}\u{11940}\u{11942}\u{119D1}-\u{119D3}\u{119DC}-\u{119DF}\u{119E4}\u{11A39}\u{11A57}-\u{11A58}\u{11A97}\u{11C2F}\u{11C3E}\u{11CA9}\u{11CB1}\u{11CB4}\u{11D8A}-\u{11D8E}\u{11D93}-\u{11D94}\u{11D96}\u{11EF5}-\u{11EF6}\u{16F51}-\u{16F87}\u{16FF0}-\u{16FF1}\u{1D166}\u{1D16D}]$/u
|
|
186
|
+
);
|
|
184
187
|
const reL = /^[\u1100-\u115F\uA960-\uA97C]$/u;
|
|
185
188
|
const reV = /^[\u1160-\u11A7\uD7B0-\uD7C6]$/u;
|
|
186
189
|
const reT = /^[\u11A8-\u11FF\uD7CB-\uD7FB]$/u;
|
|
@@ -838,7 +841,8 @@ const marks = (editor, options = {}) => {
|
|
|
838
841
|
};
|
|
839
842
|
const next = (editor, options = {}) => {
|
|
840
843
|
const { mode = "lowest", voids = false } = options;
|
|
841
|
-
|
|
844
|
+
const { at = editor.selection } = options;
|
|
845
|
+
let { match } = options;
|
|
842
846
|
if (!at) {
|
|
843
847
|
return;
|
|
844
848
|
}
|
|
@@ -1134,7 +1138,9 @@ function* positions(editor, options = {}) {
|
|
|
1134
1138
|
reverse,
|
|
1135
1139
|
voids
|
|
1136
1140
|
})) {
|
|
1137
|
-
const hasSkippedAncestor = skippedPaths.some(
|
|
1141
|
+
const hasSkippedAncestor = skippedPaths.some(
|
|
1142
|
+
(p) => Path.isAncestor(p, path2)
|
|
1143
|
+
);
|
|
1138
1144
|
function* maybeYield(point2) {
|
|
1139
1145
|
if (!hasSkippedAncestor) {
|
|
1140
1146
|
yield point2;
|
|
@@ -1211,7 +1217,8 @@ function* positions(editor, options = {}) {
|
|
|
1211
1217
|
}
|
|
1212
1218
|
const previous = (editor, options = {}) => {
|
|
1213
1219
|
const { mode = "lowest", voids = false } = options;
|
|
1214
|
-
let { match
|
|
1220
|
+
let { match } = options;
|
|
1221
|
+
const { at = editor.selection } = options;
|
|
1215
1222
|
if (!at) {
|
|
1216
1223
|
return;
|
|
1217
1224
|
}
|
|
@@ -1338,7 +1345,9 @@ const string = (editor, at, options = {}) => {
|
|
|
1338
1345
|
};
|
|
1339
1346
|
const unhangRange = (editor, range2, options = {}) => {
|
|
1340
1347
|
const { voids = false } = options;
|
|
1341
|
-
|
|
1348
|
+
const edges2 = Range.edges(range2);
|
|
1349
|
+
const [start2] = edges2;
|
|
1350
|
+
let [, end2] = edges2;
|
|
1342
1351
|
if (start2.offset !== 0 || end2.offset !== 0 || Range.isCollapsed(range2) || Path.hasPrevious(end2.path)) {
|
|
1343
1352
|
return range2;
|
|
1344
1353
|
}
|
|
@@ -1498,6 +1507,7 @@ const deleteText = (editor, options = {}) => {
|
|
|
1498
1507
|
});
|
|
1499
1508
|
}
|
|
1500
1509
|
if (isCollapsed && reverse && unit === "character" && removedText.length > 1 && removedText.match(
|
|
1510
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
1501
1511
|
/[\u0980-\u09FF\u0E00-\u0E7F\u1000-\u109F\u0900-\u097F\u1780-\u17FF\u0D00-\u0D7F\u0B00-\u0B7F\u0A00-\u0A7F\u0B80-\u0BFF\u0C00-\u0C7F]+/
|
|
1502
1512
|
)) {
|
|
1503
1513
|
Transforms.insertText(
|
|
@@ -1516,7 +1526,8 @@ const deleteText = (editor, options = {}) => {
|
|
|
1516
1526
|
const insertFragment = (editor, fragment2, options = {}) => {
|
|
1517
1527
|
Editor.withoutNormalizing(editor, () => {
|
|
1518
1528
|
const { hanging = false, voids = false } = options;
|
|
1519
|
-
let { at = getDefaultInsertLocation(editor)
|
|
1529
|
+
let { at = getDefaultInsertLocation(editor) } = options;
|
|
1530
|
+
const { batchDirty = true } = options;
|
|
1520
1531
|
if (!fragment2.length) {
|
|
1521
1532
|
return;
|
|
1522
1533
|
}
|
|
@@ -2126,7 +2137,8 @@ const removeNodes = (editor, options = {}) => {
|
|
|
2126
2137
|
};
|
|
2127
2138
|
const setNodes = (editor, props, options = {}) => {
|
|
2128
2139
|
Editor.withoutNormalizing(editor, () => {
|
|
2129
|
-
let { match, at = cloneDeep(editor.selection), compare
|
|
2140
|
+
let { match, at = cloneDeep(editor.selection), compare } = options;
|
|
2141
|
+
const { merge } = options;
|
|
2130
2142
|
const {
|
|
2131
2143
|
hanging = false,
|
|
2132
2144
|
mode = "lowest",
|
|
@@ -2191,7 +2203,7 @@ const setNodes = (editor, props, options = {}) => {
|
|
|
2191
2203
|
}
|
|
2192
2204
|
if (compare(props[k], node2[k])) {
|
|
2193
2205
|
hasChanges = true;
|
|
2194
|
-
if (
|
|
2206
|
+
if (Object.prototype.hasOwnProperty.call(node2, k))
|
|
2195
2207
|
properties[k] = node2[k];
|
|
2196
2208
|
if (merge) {
|
|
2197
2209
|
if (props[k] != null)
|
|
@@ -2229,7 +2241,12 @@ const deleteRange = (editor, range2) => {
|
|
|
2229
2241
|
const splitNodes = (editor, options = {}) => {
|
|
2230
2242
|
Editor.withoutNormalizing(editor, () => {
|
|
2231
2243
|
const { mode = "lowest", voids = false } = options;
|
|
2232
|
-
let {
|
|
2244
|
+
let {
|
|
2245
|
+
match,
|
|
2246
|
+
at = cloneDeep(editor.selection),
|
|
2247
|
+
height = 0,
|
|
2248
|
+
always = false
|
|
2249
|
+
} = options;
|
|
2233
2250
|
if (match == null) {
|
|
2234
2251
|
match = (n) => Element.isElement(n) && Editor.isBlock(editor, n);
|
|
2235
2252
|
}
|
|
@@ -2452,7 +2469,7 @@ const wrapNodes = (editor, element, options = {}) => {
|
|
|
2452
2469
|
});
|
|
2453
2470
|
};
|
|
2454
2471
|
const createEditor = () => {
|
|
2455
|
-
const editor =
|
|
2472
|
+
const editor = shallowReactive({
|
|
2456
2473
|
children: [],
|
|
2457
2474
|
operations: [],
|
|
2458
2475
|
selection: null,
|
|
@@ -2545,6 +2562,16 @@ const createEditor = () => {
|
|
|
2545
2562
|
wrapNodes: (...args) => wrapNodes(editor, ...args),
|
|
2546
2563
|
shouldMergeNodesRemovePrevNode: (...args) => shouldMergeNodesRemovePrevNode(editor, ...args)
|
|
2547
2564
|
});
|
|
2565
|
+
const _children = reactive([]);
|
|
2566
|
+
Object.defineProperty(editor, "children", {
|
|
2567
|
+
get() {
|
|
2568
|
+
return _children;
|
|
2569
|
+
},
|
|
2570
|
+
set(value) {
|
|
2571
|
+
_children.length = 0;
|
|
2572
|
+
_children.push(...value);
|
|
2573
|
+
}
|
|
2574
|
+
});
|
|
2548
2575
|
IS_EDITOR_SET.add(editor);
|
|
2549
2576
|
return editor;
|
|
2550
2577
|
};
|
package/dist/dom.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { D as DOMEditor,
|
|
2
|
-
import { C,
|
|
3
|
-
import { E as Editor, R as Range, a as Element, c as Transforms, N as Node, P as Path } from "./index-
|
|
4
|
-
import
|
|
1
|
+
import { D as DOMEditor, E as EDITOR_TO_KEY_TO_ELEMENT, a as EDITOR_TO_USER_MARKS, g as getChunkTreeForNode, b as EDITOR_TO_USER_SELECTION, N as NODE_TO_KEY, i as isDOMText, c as getPlainText, d as getSlateFragmentAttribute, e as EDITOR_TO_ON_CHANGE } from "./hotkeys-DpQWNvFe.js";
|
|
2
|
+
import { C, L, M, O, H, F, I, v, P, w, x, Q, y, R, A, z, B, J, K, S, T, U, V, f, h, j, k, l, m, o, p, q, r, s, t, u, n, G } from "./hotkeys-DpQWNvFe.js";
|
|
3
|
+
import { E as Editor, R as Range, a as Element, c as Transforms, N as Node, P as Path } from "./index-Bj4hXlPm.js";
|
|
4
|
+
import "vue";
|
|
5
5
|
const doRectsIntersect = (rect, compareRect) => {
|
|
6
6
|
const middle = (compareRect.top + compareRect.bottom) / 2;
|
|
7
7
|
return rect.top <= middle && rect.bottom >= middle;
|
|
@@ -45,70 +45,49 @@ const findCurrentLineRange = (editor, parentRange) => {
|
|
|
45
45
|
}
|
|
46
46
|
return Editor.range(editor, positions[left], parentRangeBoundary);
|
|
47
47
|
};
|
|
48
|
-
const KEY_TO_CHUNK_TREE = /* @__PURE__ */ new WeakMap();
|
|
49
|
-
const getChunkTreeForNode = (editor, node, options = {}) => {
|
|
50
|
-
const key = DOMEditor.findKey(editor, node);
|
|
51
|
-
let chunkTree = KEY_TO_CHUNK_TREE.get(key);
|
|
52
|
-
if (!chunkTree) {
|
|
53
|
-
chunkTree = {
|
|
54
|
-
type: "root",
|
|
55
|
-
movedNodeKeys: /* @__PURE__ */ new Set(),
|
|
56
|
-
children: reactive([])
|
|
57
|
-
};
|
|
58
|
-
KEY_TO_CHUNK_TREE.set(key, chunkTree);
|
|
59
|
-
}
|
|
60
|
-
if (options.reconcile) {
|
|
61
|
-
reconcileChildren(editor, {
|
|
62
|
-
chunkTree,
|
|
63
|
-
children: node.children,
|
|
64
|
-
...options.reconcile
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return chunkTree;
|
|
68
|
-
};
|
|
69
48
|
const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
70
|
-
const
|
|
71
|
-
const { apply, onChange, deleteBackward, addMark, removeMark } =
|
|
72
|
-
EDITOR_TO_KEY_TO_ELEMENT.set(
|
|
73
|
-
|
|
74
|
-
EDITOR_TO_USER_MARKS.delete(
|
|
49
|
+
const e = editor;
|
|
50
|
+
const { apply, onChange, deleteBackward, addMark, removeMark } = e;
|
|
51
|
+
EDITOR_TO_KEY_TO_ELEMENT.set(e, /* @__PURE__ */ new WeakMap());
|
|
52
|
+
e.addMark = (key, value) => {
|
|
53
|
+
EDITOR_TO_USER_MARKS.delete(e);
|
|
75
54
|
addMark(key, value);
|
|
76
55
|
};
|
|
77
|
-
|
|
78
|
-
EDITOR_TO_USER_MARKS.delete(
|
|
56
|
+
e.removeMark = (key) => {
|
|
57
|
+
EDITOR_TO_USER_MARKS.delete(e);
|
|
79
58
|
removeMark(key);
|
|
80
59
|
};
|
|
81
|
-
|
|
60
|
+
e.deleteBackward = (unit) => {
|
|
82
61
|
if (unit !== "line") {
|
|
83
62
|
return deleteBackward(unit);
|
|
84
63
|
}
|
|
85
|
-
if (
|
|
86
|
-
const parentBlockEntry = Editor.above(
|
|
87
|
-
match: (n2) => Element.isElement(n2) && Editor.isBlock(
|
|
88
|
-
at:
|
|
64
|
+
if (e.selection && Range.isCollapsed(e.selection)) {
|
|
65
|
+
const parentBlockEntry = Editor.above(e, {
|
|
66
|
+
match: (n2) => Element.isElement(n2) && Editor.isBlock(e, n2),
|
|
67
|
+
at: e.selection
|
|
89
68
|
});
|
|
90
69
|
if (parentBlockEntry) {
|
|
91
70
|
const [, parentBlockPath] = parentBlockEntry;
|
|
92
71
|
const parentElementRange = Editor.range(
|
|
93
|
-
|
|
72
|
+
e,
|
|
94
73
|
parentBlockPath,
|
|
95
|
-
|
|
74
|
+
e.selection.anchor
|
|
96
75
|
);
|
|
97
|
-
const currentLineRange = findCurrentLineRange(
|
|
76
|
+
const currentLineRange = findCurrentLineRange(e, parentElementRange);
|
|
98
77
|
if (!Range.isCollapsed(currentLineRange)) {
|
|
99
|
-
Transforms.delete(
|
|
78
|
+
Transforms.delete(e, { at: currentLineRange });
|
|
100
79
|
}
|
|
101
80
|
}
|
|
102
81
|
}
|
|
103
82
|
};
|
|
104
|
-
|
|
83
|
+
e.apply = (op) => {
|
|
105
84
|
if (op.type === "move_node") {
|
|
106
|
-
const parent = Node.parent(
|
|
107
|
-
const chunking = !!
|
|
85
|
+
const parent = Node.parent(e, op.path);
|
|
86
|
+
const chunking = !!e.getChunkSize(parent);
|
|
108
87
|
if (chunking) {
|
|
109
|
-
const node = Node.get(
|
|
110
|
-
const chunkTree = getChunkTreeForNode(
|
|
111
|
-
const key = DOMEditor.findKey(
|
|
88
|
+
const node = Node.get(e, op.path);
|
|
89
|
+
const chunkTree = getChunkTreeForNode(e, parent);
|
|
90
|
+
const key = DOMEditor.findKey(e, node);
|
|
112
91
|
chunkTree.movedNodeKeys.add(key);
|
|
113
92
|
}
|
|
114
93
|
}
|
|
@@ -119,22 +98,22 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
119
98
|
case "remove_text":
|
|
120
99
|
case "set_node":
|
|
121
100
|
case "split_node": {
|
|
122
|
-
matches.push(...getMatches(
|
|
101
|
+
matches.push(...getMatches(e, op.path));
|
|
123
102
|
break;
|
|
124
103
|
}
|
|
125
104
|
case "set_selection": {
|
|
126
|
-
EDITOR_TO_USER_SELECTION.get(
|
|
127
|
-
EDITOR_TO_USER_SELECTION.delete(
|
|
105
|
+
EDITOR_TO_USER_SELECTION.get(e)?.unref();
|
|
106
|
+
EDITOR_TO_USER_SELECTION.delete(e);
|
|
128
107
|
break;
|
|
129
108
|
}
|
|
130
109
|
case "insert_node":
|
|
131
110
|
case "remove_node": {
|
|
132
|
-
matches.push(...getMatches(
|
|
111
|
+
matches.push(...getMatches(e, Path.parent(op.path)));
|
|
133
112
|
break;
|
|
134
113
|
}
|
|
135
114
|
case "merge_node": {
|
|
136
115
|
const prevPath = Path.previous(op.path);
|
|
137
|
-
matches.push(...getMatches(
|
|
116
|
+
matches.push(...getMatches(e, prevPath));
|
|
138
117
|
break;
|
|
139
118
|
}
|
|
140
119
|
case "move_node": {
|
|
@@ -142,47 +121,47 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
142
121
|
Path.parent(op.path),
|
|
143
122
|
Path.parent(op.newPath)
|
|
144
123
|
);
|
|
145
|
-
matches.push(...getMatches(
|
|
124
|
+
matches.push(...getMatches(e, commonPath));
|
|
146
125
|
let changedPath;
|
|
147
126
|
if (Path.isBefore(op.path, op.newPath)) {
|
|
148
|
-
matches.push(...getMatches(
|
|
127
|
+
matches.push(...getMatches(e, Path.parent(op.path)));
|
|
149
128
|
changedPath = op.newPath;
|
|
150
129
|
} else {
|
|
151
|
-
matches.push(...getMatches(
|
|
130
|
+
matches.push(...getMatches(e, Path.parent(op.newPath)));
|
|
152
131
|
changedPath = op.path;
|
|
153
132
|
}
|
|
154
133
|
const changedNode = Node.get(editor, Path.parent(changedPath));
|
|
155
|
-
const changedNodeKey = DOMEditor.findKey(
|
|
156
|
-
const changedPathRef = Editor.pathRef(
|
|
134
|
+
const changedNodeKey = DOMEditor.findKey(e, changedNode);
|
|
135
|
+
const changedPathRef = Editor.pathRef(e, Path.parent(changedPath));
|
|
157
136
|
pathRefMatches.push([changedPathRef, changedNodeKey]);
|
|
158
137
|
break;
|
|
159
138
|
}
|
|
160
139
|
}
|
|
161
140
|
apply(op);
|
|
162
141
|
for (const [path, key] of matches) {
|
|
163
|
-
const [node] = Editor.node(
|
|
142
|
+
const [node] = Editor.node(e, path);
|
|
164
143
|
NODE_TO_KEY.set(node, key);
|
|
165
144
|
}
|
|
166
145
|
for (const [pathRef, key] of pathRefMatches) {
|
|
167
146
|
if (pathRef.current) {
|
|
168
|
-
const [node] = Editor.node(
|
|
147
|
+
const [node] = Editor.node(e, pathRef.current);
|
|
169
148
|
NODE_TO_KEY.set(node, key);
|
|
170
149
|
}
|
|
171
150
|
pathRef.unref();
|
|
172
151
|
}
|
|
173
152
|
};
|
|
174
|
-
|
|
175
|
-
const { selection } =
|
|
153
|
+
e.setFragmentData = (data) => {
|
|
154
|
+
const { selection } = e;
|
|
176
155
|
if (!selection) {
|
|
177
156
|
return;
|
|
178
157
|
}
|
|
179
158
|
const [start, end] = Range.edges(selection);
|
|
180
|
-
const startVoid = Editor.void(
|
|
181
|
-
const endVoid = Editor.void(
|
|
159
|
+
const startVoid = Editor.void(e, { at: start.path });
|
|
160
|
+
const endVoid = Editor.void(e, { at: end.path });
|
|
182
161
|
if (Range.isCollapsed(selection) && !startVoid) {
|
|
183
162
|
return;
|
|
184
163
|
}
|
|
185
|
-
const domRange = DOMEditor.toDOMRange(
|
|
164
|
+
const domRange = DOMEditor.toDOMRange(e, selection);
|
|
186
165
|
let contents = domRange.cloneContents();
|
|
187
166
|
let attach = contents.childNodes[0];
|
|
188
167
|
contents.childNodes.forEach((node) => {
|
|
@@ -192,10 +171,10 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
192
171
|
});
|
|
193
172
|
if (endVoid) {
|
|
194
173
|
const [voidNode] = endVoid;
|
|
195
|
-
const
|
|
196
|
-
const domNode = DOMEditor.toDOMNode(
|
|
197
|
-
|
|
198
|
-
contents =
|
|
174
|
+
const r2 = domRange.cloneRange();
|
|
175
|
+
const domNode = DOMEditor.toDOMNode(e, voidNode);
|
|
176
|
+
r2.setEndAfter(domNode);
|
|
177
|
+
contents = r2.cloneContents();
|
|
199
178
|
}
|
|
200
179
|
if (startVoid) {
|
|
201
180
|
attach = contents.querySelector("[data-slate-spacer]");
|
|
@@ -213,7 +192,7 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
213
192
|
contents.appendChild(span);
|
|
214
193
|
attach = span;
|
|
215
194
|
}
|
|
216
|
-
const fragment =
|
|
195
|
+
const fragment = e.getFragment();
|
|
217
196
|
const string = JSON.stringify(fragment);
|
|
218
197
|
const encoded = window.btoa(encodeURIComponent(string));
|
|
219
198
|
attach.setAttribute("data-slate-fragment", encoded);
|
|
@@ -227,65 +206,62 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
227
206
|
contents.ownerDocument.body.removeChild(div);
|
|
228
207
|
return data;
|
|
229
208
|
};
|
|
230
|
-
|
|
231
|
-
if (!
|
|
232
|
-
|
|
209
|
+
e.insertData = (data) => {
|
|
210
|
+
if (!e.insertFragmentData(data)) {
|
|
211
|
+
e.insertTextData(data);
|
|
233
212
|
}
|
|
234
213
|
};
|
|
235
|
-
|
|
214
|
+
e.insertFragmentData = (data) => {
|
|
236
215
|
const fragment = data.getData(`application/${clipboardFormatKey}`) || getSlateFragmentAttribute(data);
|
|
237
216
|
if (fragment) {
|
|
238
217
|
const decoded = decodeURIComponent(window.atob(fragment));
|
|
239
218
|
const parsed = JSON.parse(decoded);
|
|
240
|
-
|
|
219
|
+
e.insertFragment(parsed);
|
|
241
220
|
return true;
|
|
242
221
|
}
|
|
243
222
|
return false;
|
|
244
223
|
};
|
|
245
|
-
|
|
224
|
+
e.insertTextData = (data) => {
|
|
246
225
|
const text = data.getData("text/plain");
|
|
247
226
|
if (text) {
|
|
248
227
|
const lines = text.split(/\r\n|\r|\n/);
|
|
249
228
|
let split = false;
|
|
250
229
|
for (const line of lines) {
|
|
251
230
|
if (split) {
|
|
252
|
-
Transforms.splitNodes(
|
|
231
|
+
Transforms.splitNodes(e, { always: true });
|
|
253
232
|
}
|
|
254
|
-
|
|
233
|
+
e.insertText(line);
|
|
255
234
|
split = true;
|
|
256
235
|
}
|
|
257
236
|
return true;
|
|
258
237
|
}
|
|
259
238
|
return false;
|
|
260
239
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const onContextChange = EDITOR_TO_ON_CHANGE.get(
|
|
240
|
+
e.getChunkSize = () => null;
|
|
241
|
+
e.onChange = (options) => {
|
|
242
|
+
const onContextChange = EDITOR_TO_ON_CHANGE.get(e);
|
|
264
243
|
if (onContextChange) {
|
|
265
244
|
onContextChange(options);
|
|
266
245
|
}
|
|
267
246
|
onChange(options);
|
|
268
247
|
};
|
|
269
|
-
return
|
|
248
|
+
return e;
|
|
270
249
|
};
|
|
271
|
-
const getMatches = (
|
|
250
|
+
const getMatches = (e, path) => {
|
|
272
251
|
const matches = [];
|
|
273
|
-
for (const [n2, p2] of Editor.levels(
|
|
274
|
-
const key = DOMEditor.findKey(
|
|
252
|
+
for (const [n2, p2] of Editor.levels(e, { at: path })) {
|
|
253
|
+
const key = DOMEditor.findKey(e, n2);
|
|
275
254
|
matches.push([p2, key]);
|
|
276
255
|
}
|
|
277
256
|
return matches;
|
|
278
257
|
};
|
|
279
258
|
const shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every(
|
|
280
|
-
(key) =>
|
|
259
|
+
(key) => Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key]
|
|
281
260
|
);
|
|
282
261
|
const isDecorationFlagsEqual = (range, other) => {
|
|
283
262
|
const { anchor: rangeAnchor, focus: rangeFocus, ...rangeOwnProps } = range;
|
|
284
263
|
const { anchor: otherAnchor, focus: otherFocus, ...otherOwnProps } = other;
|
|
285
|
-
return shallowCompare(
|
|
286
|
-
rangeOwnProps,
|
|
287
|
-
otherOwnProps
|
|
288
|
-
);
|
|
264
|
+
return shallowCompare(rangeOwnProps, otherOwnProps);
|
|
289
265
|
};
|
|
290
266
|
const isElementDecorationsEqual = (list, another) => {
|
|
291
267
|
if (list === another) {
|
|
@@ -364,51 +340,51 @@ const splitDecorationsByChild = (editor, node, decorations) => {
|
|
|
364
340
|
export {
|
|
365
341
|
C as CAN_USE_DOM,
|
|
366
342
|
DOMEditor,
|
|
367
|
-
|
|
343
|
+
L as EDITOR_TO_ELEMENT,
|
|
368
344
|
EDITOR_TO_KEY_TO_ELEMENT,
|
|
369
345
|
EDITOR_TO_ON_CHANGE,
|
|
370
346
|
EDITOR_TO_USER_MARKS,
|
|
371
347
|
EDITOR_TO_USER_SELECTION,
|
|
372
|
-
|
|
373
|
-
|
|
348
|
+
M as EDITOR_TO_WINDOW,
|
|
349
|
+
O as ELEMENT_TO_NODE,
|
|
374
350
|
H as HAS_BEFORE_INPUT_SUPPORT,
|
|
375
351
|
F as Hotkeys,
|
|
376
352
|
I as IS_ANDROID,
|
|
377
353
|
v as IS_CHROME,
|
|
378
|
-
|
|
354
|
+
P as IS_COMPOSING,
|
|
379
355
|
w as IS_FIREFOX,
|
|
380
356
|
x as IS_FIREFOX_LEGACY,
|
|
381
|
-
|
|
357
|
+
Q as IS_FOCUSED,
|
|
382
358
|
y as IS_IOS,
|
|
383
|
-
|
|
359
|
+
R as IS_READ_ONLY,
|
|
384
360
|
A as IS_UC_MOBILE,
|
|
385
361
|
z as IS_WEBKIT,
|
|
386
362
|
B as IS_WECHATBROWSER,
|
|
387
|
-
KEY_TO_CHUNK_TREE,
|
|
363
|
+
J as KEY_TO_CHUNK_TREE,
|
|
388
364
|
K as Key,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
365
|
+
S as MARK_PLACEHOLDER_SYMBOL,
|
|
366
|
+
T as NODE_TO_ELEMENT,
|
|
367
|
+
U as NODE_TO_INDEX,
|
|
392
368
|
NODE_TO_KEY,
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
369
|
+
V as NODE_TO_PARENT,
|
|
370
|
+
f as applyStringDiff,
|
|
371
|
+
h as getActiveElement,
|
|
396
372
|
getChunkTreeForNode,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
373
|
+
j as getDefaultView,
|
|
374
|
+
k as getSelection,
|
|
375
|
+
l as hasShadowRoot,
|
|
376
|
+
m as isAfter,
|
|
377
|
+
o as isBefore,
|
|
378
|
+
p as isDOMElement,
|
|
379
|
+
q as isDOMNode,
|
|
380
|
+
r as isDOMSelection,
|
|
405
381
|
isElementDecorationsEqual,
|
|
406
382
|
s as isPlainTextOnlyPaste,
|
|
407
383
|
isTextDecorationsEqual,
|
|
408
384
|
t as isTrackedMutation,
|
|
409
385
|
u as normalizeDOMPoint,
|
|
410
386
|
n as normalizeStringDiff,
|
|
411
|
-
reconcileChildren,
|
|
387
|
+
G as reconcileChildren,
|
|
412
388
|
splitDecorationsByChild,
|
|
413
389
|
withDOM
|
|
414
390
|
};
|
package/dist/history.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as isObject, O as Operation, E as Editor, c as Transforms, P as Path } from "./index-
|
|
2
|
-
import "vue";
|
|
1
|
+
import { d as isObject, O as Operation, E as Editor, c as Transforms, P as Path } from "./index-Bj4hXlPm.js";
|
|
2
|
+
import { shallowReactive } from "vue";
|
|
3
3
|
const History = {
|
|
4
4
|
/**
|
|
5
5
|
* Check if a value is a `History` object.
|
|
@@ -102,10 +102,13 @@ const HistoryEditor = {
|
|
|
102
102
|
const withHistory = (editor) => {
|
|
103
103
|
const e = editor;
|
|
104
104
|
const { apply } = e;
|
|
105
|
-
e.history = {
|
|
105
|
+
e.history = {
|
|
106
|
+
undos: shallowReactive([]),
|
|
107
|
+
redos: shallowReactive([])
|
|
108
|
+
};
|
|
106
109
|
e.redo = () => {
|
|
107
110
|
const { history } = e;
|
|
108
|
-
const
|
|
111
|
+
const redos = history.redos;
|
|
109
112
|
if (redos.length > 0) {
|
|
110
113
|
const batch = redos[redos.length - 1];
|
|
111
114
|
if (batch.selectionBefore) {
|