@portabletext/editor 1.0.13 → 1.0.15
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/lib/index.esm.js +162 -123
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +162 -123
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +162 -123
- package/lib/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/editor/hooks/useSyncValue.ts +8 -17
- package/src/editor/plugins/createWithMaxBlocks.ts +20 -0
- package/src/editor/plugins/createWithObjectKeys.ts +22 -11
- package/src/editor/plugins/createWithPatches.ts +3 -6
- package/src/editor/plugins/createWithPlaceholderBlock.ts +20 -0
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +103 -97
- package/src/editor/plugins/createWithUndoRedo.ts +5 -3
- package/src/utils/withUndoRedo.ts +34 -0
- package/src/utils/withPreserveKeys.ts +0 -21
package/lib/index.js
CHANGED
|
@@ -1283,55 +1283,85 @@ function createWithInsertBreak(types2) {
|
|
|
1283
1283
|
}, editor;
|
|
1284
1284
|
};
|
|
1285
1285
|
}
|
|
1286
|
+
function withRemoteChanges(editor, fn) {
|
|
1287
|
+
const prev = isChangingRemotely(editor) || !1;
|
|
1288
|
+
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
1289
|
+
}
|
|
1290
|
+
function isChangingRemotely(editor) {
|
|
1291
|
+
return IS_PROCESSING_REMOTE_CHANGES.get(editor);
|
|
1292
|
+
}
|
|
1293
|
+
function isChangingLocally(editor) {
|
|
1294
|
+
return IS_PROCESSING_LOCAL_CHANGES.get(editor);
|
|
1295
|
+
}
|
|
1296
|
+
const IS_UDOING = /* @__PURE__ */ new WeakMap(), IS_REDOING = /* @__PURE__ */ new WeakMap();
|
|
1297
|
+
function withUndoing(editor, fn) {
|
|
1298
|
+
const prev = isUndoing(editor);
|
|
1299
|
+
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
1300
|
+
}
|
|
1301
|
+
function isUndoing(editor) {
|
|
1302
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
1303
|
+
}
|
|
1304
|
+
function setIsUndoing(editor, isUndoing2) {
|
|
1305
|
+
IS_UDOING.set(editor, isUndoing2);
|
|
1306
|
+
}
|
|
1307
|
+
function withRedoing(editor, fn) {
|
|
1308
|
+
const prev = isRedoing(editor);
|
|
1309
|
+
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
1310
|
+
}
|
|
1311
|
+
function isRedoing(editor) {
|
|
1312
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
1313
|
+
}
|
|
1314
|
+
function setIsRedoing(editor, isRedoing2) {
|
|
1315
|
+
IS_REDOING.set(editor, isRedoing2);
|
|
1316
|
+
}
|
|
1286
1317
|
function createWithMaxBlocks(maxBlocks) {
|
|
1287
1318
|
return function(editor) {
|
|
1288
1319
|
const { apply: apply2 } = editor;
|
|
1289
1320
|
return editor.apply = (operation) => {
|
|
1321
|
+
if (isChangingRemotely(editor)) {
|
|
1322
|
+
apply2(operation);
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
1326
|
+
apply2(operation);
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1290
1329
|
const rows = maxBlocks;
|
|
1291
1330
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
1292
1331
|
}, editor;
|
|
1293
1332
|
};
|
|
1294
1333
|
}
|
|
1295
|
-
const PRESERVE_KEYS = /* @__PURE__ */ new WeakMap();
|
|
1296
|
-
function withPreserveKeys(editor, fn) {
|
|
1297
|
-
const prev = isPreservingKeys(editor);
|
|
1298
|
-
PRESERVE_KEYS.set(editor, !0), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1299
|
-
}
|
|
1300
|
-
function withoutPreserveKeys(editor, fn) {
|
|
1301
|
-
const prev = isPreservingKeys(editor);
|
|
1302
|
-
PRESERVE_KEYS.set(editor, !1), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1303
|
-
}
|
|
1304
|
-
function isPreservingKeys(editor) {
|
|
1305
|
-
return PRESERVE_KEYS.get(editor);
|
|
1306
|
-
}
|
|
1307
1334
|
function createWithObjectKeys(schemaTypes, keyGenerator) {
|
|
1308
1335
|
return function(editor) {
|
|
1309
|
-
PRESERVE_KEYS.set(editor, !1);
|
|
1310
1336
|
const { apply: apply2, normalizeNode } = editor;
|
|
1311
1337
|
return editor.apply = (operation) => {
|
|
1338
|
+
if (isChangingRemotely(editor)) {
|
|
1339
|
+
apply2(operation);
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
1343
|
+
apply2(operation);
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1312
1346
|
if (operation.type === "split_node") {
|
|
1313
|
-
const withNewKey = !isPreservingKeys(editor) || !("_key" in operation.properties);
|
|
1314
1347
|
apply2({
|
|
1315
1348
|
...operation,
|
|
1316
1349
|
properties: {
|
|
1317
1350
|
...operation.properties,
|
|
1318
|
-
|
|
1351
|
+
_key: keyGenerator()
|
|
1319
1352
|
}
|
|
1320
1353
|
});
|
|
1321
1354
|
return;
|
|
1322
1355
|
}
|
|
1323
|
-
if (operation.type === "insert_node") {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
...operation,
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
});
|
|
1333
|
-
return;
|
|
1334
|
-
}
|
|
1356
|
+
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
1357
|
+
apply2({
|
|
1358
|
+
...operation,
|
|
1359
|
+
node: {
|
|
1360
|
+
...operation.node,
|
|
1361
|
+
_key: keyGenerator()
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
return;
|
|
1335
1365
|
}
|
|
1336
1366
|
apply2(operation);
|
|
1337
1367
|
}, editor.normalizeNode = (entry) => {
|
|
@@ -2221,16 +2251,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2221
2251
|
});
|
|
2222
2252
|
return child ? { block, child, blockPath, childPath: blockPath?.concat(childIndex) } : { block, blockPath, child: void 0, childPath: void 0 };
|
|
2223
2253
|
}
|
|
2224
|
-
function withRemoteChanges(editor, fn) {
|
|
2225
|
-
const prev = isChangingRemotely(editor) || !1;
|
|
2226
|
-
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
2227
|
-
}
|
|
2228
|
-
function isChangingRemotely(editor) {
|
|
2229
|
-
return IS_PROCESSING_REMOTE_CHANGES.get(editor);
|
|
2230
|
-
}
|
|
2231
|
-
function isChangingLocally(editor) {
|
|
2232
|
-
return IS_PROCESSING_LOCAL_CHANGES.get(editor);
|
|
2233
|
-
}
|
|
2234
2254
|
const PATCHING = /* @__PURE__ */ new WeakMap();
|
|
2235
2255
|
function withoutPatching(editor, fn) {
|
|
2236
2256
|
const prev = isPatching(editor);
|
|
@@ -2311,7 +2331,7 @@ function createWithUndoRedo(options) {
|
|
|
2311
2331
|
const reversedOperations = transformedOperations.map(slate.Operation.inverse).reverse();
|
|
2312
2332
|
try {
|
|
2313
2333
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2314
|
-
|
|
2334
|
+
withUndoing(editor, () => {
|
|
2315
2335
|
withoutSaving(editor, () => {
|
|
2316
2336
|
reversedOperations.forEach((op) => {
|
|
2317
2337
|
editor.apply(op);
|
|
@@ -2320,7 +2340,7 @@ function createWithUndoRedo(options) {
|
|
|
2320
2340
|
});
|
|
2321
2341
|
}), editor.normalize(), editor.onChange();
|
|
2322
2342
|
} catch (err) {
|
|
2323
|
-
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2343
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
2324
2344
|
return;
|
|
2325
2345
|
}
|
|
2326
2346
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
@@ -2344,7 +2364,7 @@ function createWithUndoRedo(options) {
|
|
|
2344
2364
|
});
|
|
2345
2365
|
try {
|
|
2346
2366
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2347
|
-
|
|
2367
|
+
withRedoing(editor, () => {
|
|
2348
2368
|
withoutSaving(editor, () => {
|
|
2349
2369
|
transformedOperations.forEach((op) => {
|
|
2350
2370
|
editor.apply(op);
|
|
@@ -2353,7 +2373,7 @@ function createWithUndoRedo(options) {
|
|
|
2353
2373
|
});
|
|
2354
2374
|
}), editor.normalize(), editor.onChange();
|
|
2355
2375
|
} catch (err) {
|
|
2356
|
-
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2376
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
2357
2377
|
return;
|
|
2358
2378
|
}
|
|
2359
2379
|
editor.history.undos.push(step), editor.history.redos.pop();
|
|
@@ -2467,10 +2487,8 @@ function createWithPatches({
|
|
|
2467
2487
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2468
2488
|
withoutPatching(editor, () => {
|
|
2469
2489
|
withoutSaving(editor, () => {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
debug$g.enabled && debug$g(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2473
|
-
});
|
|
2490
|
+
patches2.forEach((patch) => {
|
|
2491
|
+
debug$g.enabled && debug$g(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2474
2492
|
});
|
|
2475
2493
|
});
|
|
2476
2494
|
});
|
|
@@ -2567,6 +2585,14 @@ function createWithPlaceholderBlock() {
|
|
|
2567
2585
|
return function(editor) {
|
|
2568
2586
|
const { apply: apply2 } = editor;
|
|
2569
2587
|
return editor.apply = (op) => {
|
|
2588
|
+
if (isChangingRemotely(editor)) {
|
|
2589
|
+
apply2(op);
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
2593
|
+
apply2(op);
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2570
2596
|
if (op.type === "remove_node") {
|
|
2571
2597
|
const node = op.node;
|
|
2572
2598
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
@@ -2736,19 +2762,27 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2736
2762
|
change$.next({ type: "selection", selection: ptRange });
|
|
2737
2763
|
};
|
|
2738
2764
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2739
|
-
normalizeNode(nodeEntry), editor.operations.some(
|
|
2740
|
-
(op) => [
|
|
2741
|
-
"insert_node",
|
|
2742
|
-
"insert_text",
|
|
2743
|
-
"merge_node",
|
|
2744
|
-
"remove_node",
|
|
2745
|
-
"remove_text",
|
|
2746
|
-
"set_node"
|
|
2747
|
-
].includes(op.type)
|
|
2748
|
-
) && mergeSpans(editor);
|
|
2749
2765
|
const [node, path] = nodeEntry, isSpan = slate.Text.isText(node) && node._type === types2.span.name, isTextBlock = editor.isTextBlock(node);
|
|
2766
|
+
if (editor.isTextBlock(node)) {
|
|
2767
|
+
const children = slate.Node.children(editor, path);
|
|
2768
|
+
for (const [child, childPath] of children) {
|
|
2769
|
+
const nextNode = node.children[childPath[1] + 1];
|
|
2770
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && isEqual__default.default(child.marks, nextNode.marks)) {
|
|
2771
|
+
debug$c(
|
|
2772
|
+
"Merging spans",
|
|
2773
|
+
JSON.stringify(child, null, 2),
|
|
2774
|
+
JSON.stringify(nextNode, null, 2)
|
|
2775
|
+
), slate.Transforms.mergeNodes(editor, { at: [childPath[0], childPath[1] + 1], voids: !0 });
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2750
2780
|
if (isSpan || isTextBlock) {
|
|
2751
|
-
if (isSpan && !Array.isArray(node.marks)
|
|
2781
|
+
if (isSpan && !Array.isArray(node.marks)) {
|
|
2782
|
+
debug$c("Adding .marks to span node"), slate.Transforms.setNodes(editor, { marks: [] }, { at: path });
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
if (isSpan && (node.marks || []).length > 0) {
|
|
2752
2786
|
const spanMarks = node.marks || EMPTY_MARKS$1, annotationMarks = spanMarks.filter(
|
|
2753
2787
|
(mark) => !types2.decorators.map((dec) => dec.value).includes(mark)
|
|
2754
2788
|
);
|
|
@@ -2756,11 +2790,14 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2756
2790
|
const [block] = slate.Editor.node(editor, slate.Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2757
2791
|
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2758
2792
|
) || [];
|
|
2759
|
-
orphanedMarks.length > 0
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2793
|
+
if (orphanedMarks.length > 0) {
|
|
2794
|
+
debug$c("Removing orphaned .marks from span node"), slate.Transforms.setNodes(
|
|
2795
|
+
editor,
|
|
2796
|
+
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2797
|
+
{ at: path }
|
|
2798
|
+
);
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2764
2801
|
}
|
|
2765
2802
|
}
|
|
2766
2803
|
for (const op of editor.operations) {
|
|
@@ -2768,7 +2805,10 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2768
2805
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
2769
2806
|
if (debug$c("Copying markDefs over to merged block", op), editor.isTextBlock(targetBlock)) {
|
|
2770
2807
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
2771
|
-
isEqual__default.default(newMarkDefs, targetBlock.markDefs)
|
|
2808
|
+
if (!isEqual__default.default(newMarkDefs, targetBlock.markDefs)) {
|
|
2809
|
+
slate.Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: targetPath, voids: !1 });
|
|
2810
|
+
return;
|
|
2811
|
+
}
|
|
2772
2812
|
}
|
|
2773
2813
|
}
|
|
2774
2814
|
if (op.type === "split_node" && op.path.length === 1 && slate.Element.isElementProps(op.properties) && op.properties._type === types2.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
@@ -2779,33 +2819,55 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2779
2819
|
editor,
|
|
2780
2820
|
{ markDefs: uniq__default.default([...oldDefs, ...op.properties.markDefs]) },
|
|
2781
2821
|
{ at: targetPath, voids: !1 }
|
|
2782
|
-
)
|
|
2822
|
+
);
|
|
2823
|
+
return;
|
|
2783
2824
|
}
|
|
2784
2825
|
}
|
|
2785
2826
|
if (op.type === "split_node" && op.path.length === 2 && op.properties._type === types2.span.name && "marks" in op.properties && Array.isArray(op.properties.marks) && op.properties.marks.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2786
2827
|
const [child, childPath] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
2787
|
-
slate.Text.isText(child) && child.text === "" && Array.isArray(child.marks) && child.marks.length > 0
|
|
2828
|
+
if (slate.Text.isText(child) && child.text === "" && Array.isArray(child.marks) && child.marks.length > 0) {
|
|
2829
|
+
slate.Transforms.setNodes(editor, { marks: [] }, { at: childPath, voids: !1 });
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2788
2832
|
}
|
|
2789
2833
|
if (op.type === "split_node" && op.path.length === 1 && op.properties._type === types2.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0) {
|
|
2790
2834
|
const [block, blockPath] = slate.Editor.node(editor, [op.path[0]]);
|
|
2791
|
-
editor.isTextBlock(block) && block.children.length === 1 && block.markDefs && block.markDefs.length > 0 && slate.Text.isText(block.children[0]) && block.children[0].text === "" && (!block.children[0].marks || block.children[0].marks.length === 0)
|
|
2835
|
+
if (editor.isTextBlock(block) && block.children.length === 1 && block.markDefs && block.markDefs.length > 0 && slate.Text.isText(block.children[0]) && block.children[0].text === "" && (!block.children[0].marks || block.children[0].marks.length === 0)) {
|
|
2836
|
+
slate.Transforms.setNodes(editor, { markDefs: [] }, { at: blockPath });
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2792
2839
|
}
|
|
2793
2840
|
}
|
|
2794
|
-
isSpan && Array.isArray(node.marks) && (!node.marks || node.marks.length > 0 && node.text === "")
|
|
2841
|
+
if (isSpan && Array.isArray(node.marks) && (!node.marks || node.marks.length > 0 && node.text === "")) {
|
|
2842
|
+
slate.Transforms.setNodes(editor, { marks: [] }, { at: path, voids: !1 });
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2795
2845
|
}
|
|
2796
2846
|
if (editor.isTextBlock(node) && !editor.operations.some(
|
|
2797
2847
|
(op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1
|
|
2798
2848
|
)) {
|
|
2799
2849
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
2800
|
-
node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2850
|
+
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
2851
|
+
debug$c("Removing markDef not in use"), slate.Transforms.setNodes(
|
|
2852
|
+
editor,
|
|
2853
|
+
{
|
|
2854
|
+
markDefs: newMarkDefs
|
|
2855
|
+
},
|
|
2856
|
+
{ at: path }
|
|
2857
|
+
);
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2807
2860
|
}
|
|
2861
|
+
normalizeNode(nodeEntry);
|
|
2808
2862
|
}, editor.apply = (op) => {
|
|
2863
|
+
if (isChangingRemotely(editor)) {
|
|
2864
|
+
apply2(op);
|
|
2865
|
+
return;
|
|
2866
|
+
}
|
|
2867
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
2868
|
+
apply2(op);
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2809
2871
|
if (op.type === "insert_text") {
|
|
2810
2872
|
const { selection } = editor;
|
|
2811
2873
|
if (selection && slate.Range.isCollapsed(selection) && slate.Editor.marks(editor)?.marks?.some((mark) => !decorators.includes(mark))) {
|
|
@@ -2846,29 +2908,33 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2846
2908
|
), deletingPartOfTheNode = op.offset !== 0, deletingFromTheEnd = op.offset + op.text.length === node.text.length;
|
|
2847
2909
|
if (nodeHasAnnotations && deletingPartOfTheNode && deletingFromTheEnd) {
|
|
2848
2910
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2849
|
-
|
|
2850
|
-
slate.
|
|
2851
|
-
|
|
2852
|
-
at: { path: op.path, offset: op.offset }
|
|
2853
|
-
});
|
|
2911
|
+
slate.Transforms.splitNodes(editor, {
|
|
2912
|
+
match: slate.Text.isText,
|
|
2913
|
+
at: { path: op.path, offset: op.offset }
|
|
2854
2914
|
}), slate.Transforms.removeNodes(editor, { at: slate.Path.next(op.path) });
|
|
2855
2915
|
}), editor.onChange();
|
|
2856
2916
|
return;
|
|
2857
2917
|
}
|
|
2918
|
+
const deletingAllText = op.offset === 0 && deletingFromTheEnd;
|
|
2919
|
+
if (nodeHasAnnotations && deletingAllText) {
|
|
2920
|
+
const marksWithoutAnnotationMarks = ({
|
|
2921
|
+
...slate.Editor.marks(editor) || {}
|
|
2922
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
2923
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
2924
|
+
apply2(op), slate.Transforms.setNodes(editor, { marks: marksWithoutAnnotationMarks }, { at: op.path });
|
|
2925
|
+
}), editor.onChange();
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2858
2928
|
}
|
|
2859
2929
|
}
|
|
2860
2930
|
apply2(op);
|
|
2861
2931
|
}, editor.addMark = (mark) => {
|
|
2862
2932
|
if (editor.selection) {
|
|
2863
|
-
if (slate.Range.isExpanded(editor.selection))
|
|
2864
|
-
slate.Transforms.setNodes(editor, {}, { match: slate.Text.isText, split: !0 });
|
|
2865
|
-
const splitTextNodes = [
|
|
2866
|
-
...slate.Editor.nodes(editor, { at: editor.selection, match: slate.Text.isText })
|
|
2867
|
-
];
|
|
2868
|
-
if (splitTextNodes.every((node) => node[0].marks?.includes(mark)))
|
|
2869
|
-
return editor.removeMark(mark), editor;
|
|
2933
|
+
if (slate.Range.isExpanded(editor.selection))
|
|
2870
2934
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2871
|
-
|
|
2935
|
+
slate.Transforms.setNodes(editor, {}, { match: slate.Text.isText, split: !0 });
|
|
2936
|
+
const splitTextNodes = slate.Range.isRange(editor.selection) ? [...slate.Editor.nodes(editor, { at: editor.selection, match: slate.Text.isText })] : [];
|
|
2937
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
2872
2938
|
const marks = [
|
|
2873
2939
|
...(Array.isArray(node.marks) ? node.marks : []).filter(
|
|
2874
2940
|
(eMark) => eMark !== mark
|
|
@@ -2881,8 +2947,8 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2881
2947
|
{ at: path, match: slate.Text.isText, split: !0, hanging: !0 }
|
|
2882
2948
|
);
|
|
2883
2949
|
});
|
|
2884
|
-
})
|
|
2885
|
-
|
|
2950
|
+
});
|
|
2951
|
+
else {
|
|
2886
2952
|
const existingMarks = {
|
|
2887
2953
|
...slate.Editor.marks(editor) || {}
|
|
2888
2954
|
}.marks || [], marks = {
|
|
@@ -2943,25 +3009,6 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2943
3009
|
editor.pteIsMarkActive(mark) ? (debug$c(`Remove mark '${mark}'`), slate.Editor.removeMark(editor, mark)) : (debug$c(`Add mark '${mark}'`), slate.Editor.addMark(editor, mark, !0));
|
|
2944
3010
|
}, editor;
|
|
2945
3011
|
};
|
|
2946
|
-
function mergeSpans(editor) {
|
|
2947
|
-
const { selection } = editor;
|
|
2948
|
-
if (selection) {
|
|
2949
|
-
const textNodesInSelection = Array.from(
|
|
2950
|
-
slate.Editor.nodes(editor, {
|
|
2951
|
-
at: slate.Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]]),
|
|
2952
|
-
match: slate.Text.isText,
|
|
2953
|
-
reverse: !0
|
|
2954
|
-
})
|
|
2955
|
-
);
|
|
2956
|
-
for (const [node, path] of textNodesInSelection) {
|
|
2957
|
-
const [parent] = path.length > 1 ? slate.Editor.node(editor, slate.Path.parent(path)) : [void 0], nextPath = [path[0], path[1] + 1];
|
|
2958
|
-
if (editor.isTextBlock(parent)) {
|
|
2959
|
-
const nextNode = parent.children[nextPath[1]];
|
|
2960
|
-
slate.Text.isText(nextNode) && isEqual__default.default(nextNode.marks, node.marks) && (debug$c("Merging spans"), slate.Transforms.mergeNodes(editor, { at: nextPath, voids: !0 }), editor.onChange());
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
3012
|
}
|
|
2966
3013
|
const debug$b = debugWithName("plugin:withPortableTextSelections"), debugVerbose$2 = debug$b.enabled && !1;
|
|
2967
3014
|
function createWithPortableTextSelections(change$, types2) {
|
|
@@ -3821,10 +3868,8 @@ function useSyncValue(props) {
|
|
|
3821
3868
|
debug$5.enabled && debug$5(
|
|
3822
3869
|
"Validating and inserting new block in the end of the value",
|
|
3823
3870
|
currentBlock
|
|
3824
|
-
), validation.valid || validation.resolution?.autoResolve ?
|
|
3825
|
-
|
|
3826
|
-
at: [currentBlockIndex]
|
|
3827
|
-
});
|
|
3871
|
+
), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3872
|
+
at: [currentBlockIndex]
|
|
3828
3873
|
}) : (debug$5("Invalid", validation), change$.next({
|
|
3829
3874
|
type: "invalidValue",
|
|
3830
3875
|
resolution: validation.resolution,
|
|
@@ -3874,9 +3919,7 @@ function useSyncValue(props) {
|
|
|
3874
3919
|
}
|
|
3875
3920
|
function _replaceBlock(slateEditor, currentBlock, currentBlockIndex) {
|
|
3876
3921
|
const currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === currentBlockIndex;
|
|
3877
|
-
selectionFocusOnBlock && slate.Transforms.deselect(slateEditor), slate.Transforms.removeNodes(slateEditor, { at: [currentBlockIndex] }),
|
|
3878
|
-
slate.Transforms.insertNodes(slateEditor, currentBlock, { at: [currentBlockIndex] });
|
|
3879
|
-
}), slateEditor.onChange(), selectionFocusOnBlock && slate.Transforms.select(slateEditor, currentSelection);
|
|
3922
|
+
selectionFocusOnBlock && slate.Transforms.deselect(slateEditor), slate.Transforms.removeNodes(slateEditor, { at: [currentBlockIndex] }), slate.Transforms.insertNodes(slateEditor, currentBlock, { at: [currentBlockIndex] }), slateEditor.onChange(), selectionFocusOnBlock && slate.Transforms.select(slateEditor, currentSelection);
|
|
3880
3923
|
}
|
|
3881
3924
|
function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
3882
3925
|
if (slate.Transforms.setNodes(slateEditor, currentBlock, {
|
|
@@ -3912,15 +3955,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3912
3955
|
));
|
|
3913
3956
|
} else oldBlockChild ? (debug$5("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
3914
3957
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3915
|
-
}),
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
}), slateEditor.onChange())
|
|
3920
|
-
slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3921
|
-
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3922
|
-
}), slateEditor.onChange();
|
|
3923
|
-
}));
|
|
3958
|
+
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3959
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3960
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$5("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3961
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3962
|
+
}), slateEditor.onChange());
|
|
3924
3963
|
});
|
|
3925
3964
|
}
|
|
3926
3965
|
}
|