@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.esm.js
CHANGED
|
@@ -1299,55 +1299,85 @@ function createWithInsertBreak(types) {
|
|
|
1299
1299
|
}, editor;
|
|
1300
1300
|
};
|
|
1301
1301
|
}
|
|
1302
|
+
function withRemoteChanges(editor, fn) {
|
|
1303
|
+
const prev = isChangingRemotely(editor) || !1;
|
|
1304
|
+
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
1305
|
+
}
|
|
1306
|
+
function isChangingRemotely(editor) {
|
|
1307
|
+
return IS_PROCESSING_REMOTE_CHANGES.get(editor);
|
|
1308
|
+
}
|
|
1309
|
+
function isChangingLocally(editor) {
|
|
1310
|
+
return IS_PROCESSING_LOCAL_CHANGES.get(editor);
|
|
1311
|
+
}
|
|
1312
|
+
const IS_UDOING = /* @__PURE__ */ new WeakMap(), IS_REDOING = /* @__PURE__ */ new WeakMap();
|
|
1313
|
+
function withUndoing(editor, fn) {
|
|
1314
|
+
const prev = isUndoing(editor);
|
|
1315
|
+
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
1316
|
+
}
|
|
1317
|
+
function isUndoing(editor) {
|
|
1318
|
+
return IS_UDOING.get(editor) ?? !1;
|
|
1319
|
+
}
|
|
1320
|
+
function setIsUndoing(editor, isUndoing2) {
|
|
1321
|
+
IS_UDOING.set(editor, isUndoing2);
|
|
1322
|
+
}
|
|
1323
|
+
function withRedoing(editor, fn) {
|
|
1324
|
+
const prev = isRedoing(editor);
|
|
1325
|
+
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
1326
|
+
}
|
|
1327
|
+
function isRedoing(editor) {
|
|
1328
|
+
return IS_REDOING.get(editor) ?? !1;
|
|
1329
|
+
}
|
|
1330
|
+
function setIsRedoing(editor, isRedoing2) {
|
|
1331
|
+
IS_REDOING.set(editor, isRedoing2);
|
|
1332
|
+
}
|
|
1302
1333
|
function createWithMaxBlocks(maxBlocks) {
|
|
1303
1334
|
return function(editor) {
|
|
1304
1335
|
const { apply: apply2 } = editor;
|
|
1305
1336
|
return editor.apply = (operation) => {
|
|
1337
|
+
if (isChangingRemotely(editor)) {
|
|
1338
|
+
apply2(operation);
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
1342
|
+
apply2(operation);
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1306
1345
|
const rows = maxBlocks;
|
|
1307
1346
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
1308
1347
|
}, editor;
|
|
1309
1348
|
};
|
|
1310
1349
|
}
|
|
1311
|
-
const PRESERVE_KEYS = /* @__PURE__ */ new WeakMap();
|
|
1312
|
-
function withPreserveKeys(editor, fn) {
|
|
1313
|
-
const prev = isPreservingKeys(editor);
|
|
1314
|
-
PRESERVE_KEYS.set(editor, !0), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1315
|
-
}
|
|
1316
|
-
function withoutPreserveKeys(editor, fn) {
|
|
1317
|
-
const prev = isPreservingKeys(editor);
|
|
1318
|
-
PRESERVE_KEYS.set(editor, !1), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1319
|
-
}
|
|
1320
|
-
function isPreservingKeys(editor) {
|
|
1321
|
-
return PRESERVE_KEYS.get(editor);
|
|
1322
|
-
}
|
|
1323
1350
|
function createWithObjectKeys(schemaTypes, keyGenerator) {
|
|
1324
1351
|
return function(editor) {
|
|
1325
|
-
PRESERVE_KEYS.set(editor, !1);
|
|
1326
1352
|
const { apply: apply2, normalizeNode } = editor;
|
|
1327
1353
|
return editor.apply = (operation) => {
|
|
1354
|
+
if (isChangingRemotely(editor)) {
|
|
1355
|
+
apply2(operation);
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
1359
|
+
apply2(operation);
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1328
1362
|
if (operation.type === "split_node") {
|
|
1329
|
-
const withNewKey = !isPreservingKeys(editor) || !("_key" in operation.properties);
|
|
1330
1363
|
apply2({
|
|
1331
1364
|
...operation,
|
|
1332
1365
|
properties: {
|
|
1333
1366
|
...operation.properties,
|
|
1334
|
-
|
|
1367
|
+
_key: keyGenerator()
|
|
1335
1368
|
}
|
|
1336
1369
|
});
|
|
1337
1370
|
return;
|
|
1338
1371
|
}
|
|
1339
|
-
if (operation.type === "insert_node") {
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
...operation,
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
});
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1372
|
+
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
1373
|
+
apply2({
|
|
1374
|
+
...operation,
|
|
1375
|
+
node: {
|
|
1376
|
+
...operation.node,
|
|
1377
|
+
_key: keyGenerator()
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
return;
|
|
1351
1381
|
}
|
|
1352
1382
|
apply2(operation);
|
|
1353
1383
|
}, editor.normalizeNode = (entry) => {
|
|
@@ -2237,16 +2267,6 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2237
2267
|
});
|
|
2238
2268
|
return child ? { block, child, blockPath, childPath: blockPath?.concat(childIndex) } : { block, blockPath, child: void 0, childPath: void 0 };
|
|
2239
2269
|
}
|
|
2240
|
-
function withRemoteChanges(editor, fn) {
|
|
2241
|
-
const prev = isChangingRemotely(editor) || !1;
|
|
2242
|
-
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
2243
|
-
}
|
|
2244
|
-
function isChangingRemotely(editor) {
|
|
2245
|
-
return IS_PROCESSING_REMOTE_CHANGES.get(editor);
|
|
2246
|
-
}
|
|
2247
|
-
function isChangingLocally(editor) {
|
|
2248
|
-
return IS_PROCESSING_LOCAL_CHANGES.get(editor);
|
|
2249
|
-
}
|
|
2250
2270
|
const PATCHING = /* @__PURE__ */ new WeakMap();
|
|
2251
2271
|
function withoutPatching(editor, fn) {
|
|
2252
2272
|
const prev = isPatching(editor);
|
|
@@ -2327,7 +2347,7 @@ function createWithUndoRedo(options) {
|
|
|
2327
2347
|
const reversedOperations = transformedOperations.map(Operation.inverse).reverse();
|
|
2328
2348
|
try {
|
|
2329
2349
|
Editor.withoutNormalizing(editor, () => {
|
|
2330
|
-
|
|
2350
|
+
withUndoing(editor, () => {
|
|
2331
2351
|
withoutSaving(editor, () => {
|
|
2332
2352
|
reversedOperations.forEach((op) => {
|
|
2333
2353
|
editor.apply(op);
|
|
@@ -2336,7 +2356,7 @@ function createWithUndoRedo(options) {
|
|
|
2336
2356
|
});
|
|
2337
2357
|
}), editor.normalize(), editor.onChange();
|
|
2338
2358
|
} catch (err) {
|
|
2339
|
-
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2359
|
+
debug$h("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
2340
2360
|
return;
|
|
2341
2361
|
}
|
|
2342
2362
|
editor.history.redos.push(step), editor.history.undos.pop();
|
|
@@ -2360,7 +2380,7 @@ function createWithUndoRedo(options) {
|
|
|
2360
2380
|
});
|
|
2361
2381
|
try {
|
|
2362
2382
|
Editor.withoutNormalizing(editor, () => {
|
|
2363
|
-
|
|
2383
|
+
withRedoing(editor, () => {
|
|
2364
2384
|
withoutSaving(editor, () => {
|
|
2365
2385
|
transformedOperations.forEach((op) => {
|
|
2366
2386
|
editor.apply(op);
|
|
@@ -2369,7 +2389,7 @@ function createWithUndoRedo(options) {
|
|
|
2369
2389
|
});
|
|
2370
2390
|
}), editor.normalize(), editor.onChange();
|
|
2371
2391
|
} catch (err) {
|
|
2372
|
-
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), editor.onChange();
|
|
2392
|
+
debug$h("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = { undos: [], redos: [] }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
2373
2393
|
return;
|
|
2374
2394
|
}
|
|
2375
2395
|
editor.history.undos.push(step), editor.history.redos.pop();
|
|
@@ -2483,10 +2503,8 @@ function createWithPatches({
|
|
|
2483
2503
|
Editor.withoutNormalizing(editor, () => {
|
|
2484
2504
|
withoutPatching(editor, () => {
|
|
2485
2505
|
withoutSaving(editor, () => {
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
debug$g.enabled && debug$g(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2489
|
-
});
|
|
2506
|
+
patches.forEach((patch) => {
|
|
2507
|
+
debug$g.enabled && debug$g(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2490
2508
|
});
|
|
2491
2509
|
});
|
|
2492
2510
|
});
|
|
@@ -2583,6 +2601,14 @@ function createWithPlaceholderBlock() {
|
|
|
2583
2601
|
return function(editor) {
|
|
2584
2602
|
const { apply: apply2 } = editor;
|
|
2585
2603
|
return editor.apply = (op) => {
|
|
2604
|
+
if (isChangingRemotely(editor)) {
|
|
2605
|
+
apply2(op);
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
2609
|
+
apply2(op);
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2586
2612
|
if (op.type === "remove_node") {
|
|
2587
2613
|
const node = op.node;
|
|
2588
2614
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
@@ -2752,19 +2778,27 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2752
2778
|
change$.next({ type: "selection", selection: ptRange });
|
|
2753
2779
|
};
|
|
2754
2780
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2755
|
-
normalizeNode(nodeEntry), editor.operations.some(
|
|
2756
|
-
(op) => [
|
|
2757
|
-
"insert_node",
|
|
2758
|
-
"insert_text",
|
|
2759
|
-
"merge_node",
|
|
2760
|
-
"remove_node",
|
|
2761
|
-
"remove_text",
|
|
2762
|
-
"set_node"
|
|
2763
|
-
].includes(op.type)
|
|
2764
|
-
) && mergeSpans(editor);
|
|
2765
2781
|
const [node, path] = nodeEntry, isSpan = Text.isText(node) && node._type === types.span.name, isTextBlock = editor.isTextBlock(node);
|
|
2782
|
+
if (editor.isTextBlock(node)) {
|
|
2783
|
+
const children = Node.children(editor, path);
|
|
2784
|
+
for (const [child, childPath] of children) {
|
|
2785
|
+
const nextNode = node.children[childPath[1] + 1];
|
|
2786
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && isEqual(child.marks, nextNode.marks)) {
|
|
2787
|
+
debug$c(
|
|
2788
|
+
"Merging spans",
|
|
2789
|
+
JSON.stringify(child, null, 2),
|
|
2790
|
+
JSON.stringify(nextNode, null, 2)
|
|
2791
|
+
), Transforms.mergeNodes(editor, { at: [childPath[0], childPath[1] + 1], voids: !0 });
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2766
2796
|
if (isSpan || isTextBlock) {
|
|
2767
|
-
if (isSpan && !Array.isArray(node.marks)
|
|
2797
|
+
if (isSpan && !Array.isArray(node.marks)) {
|
|
2798
|
+
debug$c("Adding .marks to span node"), Transforms.setNodes(editor, { marks: [] }, { at: path });
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
if (isSpan && (node.marks || []).length > 0) {
|
|
2768
2802
|
const spanMarks = node.marks || EMPTY_MARKS$1, annotationMarks = spanMarks.filter(
|
|
2769
2803
|
(mark) => !types.decorators.map((dec) => dec.value).includes(mark)
|
|
2770
2804
|
);
|
|
@@ -2772,11 +2806,14 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2772
2806
|
const [block] = Editor.node(editor, Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2773
2807
|
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2774
2808
|
) || [];
|
|
2775
|
-
orphanedMarks.length > 0
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2809
|
+
if (orphanedMarks.length > 0) {
|
|
2810
|
+
debug$c("Removing orphaned .marks from span node"), Transforms.setNodes(
|
|
2811
|
+
editor,
|
|
2812
|
+
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2813
|
+
{ at: path }
|
|
2814
|
+
);
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2780
2817
|
}
|
|
2781
2818
|
}
|
|
2782
2819
|
for (const op of editor.operations) {
|
|
@@ -2784,7 +2821,10 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2784
2821
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
2785
2822
|
if (debug$c("Copying markDefs over to merged block", op), editor.isTextBlock(targetBlock)) {
|
|
2786
2823
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
2787
|
-
isEqual(newMarkDefs, targetBlock.markDefs)
|
|
2824
|
+
if (!isEqual(newMarkDefs, targetBlock.markDefs)) {
|
|
2825
|
+
Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: targetPath, voids: !1 });
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2788
2828
|
}
|
|
2789
2829
|
}
|
|
2790
2830
|
if (op.type === "split_node" && op.path.length === 1 && Element$1.isElementProps(op.properties) && op.properties._type === types.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
@@ -2795,33 +2835,55 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2795
2835
|
editor,
|
|
2796
2836
|
{ markDefs: uniq([...oldDefs, ...op.properties.markDefs]) },
|
|
2797
2837
|
{ at: targetPath, voids: !1 }
|
|
2798
|
-
)
|
|
2838
|
+
);
|
|
2839
|
+
return;
|
|
2799
2840
|
}
|
|
2800
2841
|
}
|
|
2801
2842
|
if (op.type === "split_node" && op.path.length === 2 && op.properties._type === types.span.name && "marks" in op.properties && Array.isArray(op.properties.marks) && op.properties.marks.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2802
2843
|
const [child, childPath] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
2803
|
-
Text.isText(child) && child.text === "" && Array.isArray(child.marks) && child.marks.length > 0
|
|
2844
|
+
if (Text.isText(child) && child.text === "" && Array.isArray(child.marks) && child.marks.length > 0) {
|
|
2845
|
+
Transforms.setNodes(editor, { marks: [] }, { at: childPath, voids: !1 });
|
|
2846
|
+
return;
|
|
2847
|
+
}
|
|
2804
2848
|
}
|
|
2805
2849
|
if (op.type === "split_node" && op.path.length === 1 && op.properties._type === types.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0) {
|
|
2806
2850
|
const [block, blockPath] = Editor.node(editor, [op.path[0]]);
|
|
2807
|
-
editor.isTextBlock(block) && block.children.length === 1 && block.markDefs && block.markDefs.length > 0 && Text.isText(block.children[0]) && block.children[0].text === "" && (!block.children[0].marks || block.children[0].marks.length === 0)
|
|
2851
|
+
if (editor.isTextBlock(block) && block.children.length === 1 && block.markDefs && block.markDefs.length > 0 && Text.isText(block.children[0]) && block.children[0].text === "" && (!block.children[0].marks || block.children[0].marks.length === 0)) {
|
|
2852
|
+
Transforms.setNodes(editor, { markDefs: [] }, { at: blockPath });
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2808
2855
|
}
|
|
2809
2856
|
}
|
|
2810
|
-
isSpan && Array.isArray(node.marks) && (!node.marks || node.marks.length > 0 && node.text === "")
|
|
2857
|
+
if (isSpan && Array.isArray(node.marks) && (!node.marks || node.marks.length > 0 && node.text === "")) {
|
|
2858
|
+
Transforms.setNodes(editor, { marks: [] }, { at: path, voids: !1 });
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2811
2861
|
}
|
|
2812
2862
|
if (editor.isTextBlock(node) && !editor.operations.some(
|
|
2813
2863
|
(op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1
|
|
2814
2864
|
)) {
|
|
2815
2865
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
2816
|
-
node.markDefs && !isEqual(newMarkDefs, node.markDefs)
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2866
|
+
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
2867
|
+
debug$c("Removing markDef not in use"), Transforms.setNodes(
|
|
2868
|
+
editor,
|
|
2869
|
+
{
|
|
2870
|
+
markDefs: newMarkDefs
|
|
2871
|
+
},
|
|
2872
|
+
{ at: path }
|
|
2873
|
+
);
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2823
2876
|
}
|
|
2877
|
+
normalizeNode(nodeEntry);
|
|
2824
2878
|
}, editor.apply = (op) => {
|
|
2879
|
+
if (isChangingRemotely(editor)) {
|
|
2880
|
+
apply2(op);
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
2884
|
+
apply2(op);
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2825
2887
|
if (op.type === "insert_text") {
|
|
2826
2888
|
const { selection } = editor;
|
|
2827
2889
|
if (selection && Range.isCollapsed(selection) && Editor.marks(editor)?.marks?.some((mark) => !decorators.includes(mark))) {
|
|
@@ -2862,29 +2924,33 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2862
2924
|
), deletingPartOfTheNode = op.offset !== 0, deletingFromTheEnd = op.offset + op.text.length === node.text.length;
|
|
2863
2925
|
if (nodeHasAnnotations && deletingPartOfTheNode && deletingFromTheEnd) {
|
|
2864
2926
|
Editor.withoutNormalizing(editor, () => {
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
at: { path: op.path, offset: op.offset }
|
|
2869
|
-
});
|
|
2927
|
+
Transforms.splitNodes(editor, {
|
|
2928
|
+
match: Text.isText,
|
|
2929
|
+
at: { path: op.path, offset: op.offset }
|
|
2870
2930
|
}), Transforms.removeNodes(editor, { at: Path.next(op.path) });
|
|
2871
2931
|
}), editor.onChange();
|
|
2872
2932
|
return;
|
|
2873
2933
|
}
|
|
2934
|
+
const deletingAllText = op.offset === 0 && deletingFromTheEnd;
|
|
2935
|
+
if (nodeHasAnnotations && deletingAllText) {
|
|
2936
|
+
const marksWithoutAnnotationMarks = ({
|
|
2937
|
+
...Editor.marks(editor) || {}
|
|
2938
|
+
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
2939
|
+
Editor.withoutNormalizing(editor, () => {
|
|
2940
|
+
apply2(op), Transforms.setNodes(editor, { marks: marksWithoutAnnotationMarks }, { at: op.path });
|
|
2941
|
+
}), editor.onChange();
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2874
2944
|
}
|
|
2875
2945
|
}
|
|
2876
2946
|
apply2(op);
|
|
2877
2947
|
}, editor.addMark = (mark) => {
|
|
2878
2948
|
if (editor.selection) {
|
|
2879
|
-
if (Range.isExpanded(editor.selection))
|
|
2880
|
-
Transforms.setNodes(editor, {}, { match: Text.isText, split: !0 });
|
|
2881
|
-
const splitTextNodes = [
|
|
2882
|
-
...Editor.nodes(editor, { at: editor.selection, match: Text.isText })
|
|
2883
|
-
];
|
|
2884
|
-
if (splitTextNodes.every((node) => node[0].marks?.includes(mark)))
|
|
2885
|
-
return editor.removeMark(mark), editor;
|
|
2949
|
+
if (Range.isExpanded(editor.selection))
|
|
2886
2950
|
Editor.withoutNormalizing(editor, () => {
|
|
2887
|
-
|
|
2951
|
+
Transforms.setNodes(editor, {}, { match: Text.isText, split: !0 });
|
|
2952
|
+
const splitTextNodes = Range.isRange(editor.selection) ? [...Editor.nodes(editor, { at: editor.selection, match: Text.isText })] : [];
|
|
2953
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
2888
2954
|
const marks = [
|
|
2889
2955
|
...(Array.isArray(node.marks) ? node.marks : []).filter(
|
|
2890
2956
|
(eMark) => eMark !== mark
|
|
@@ -2897,8 +2963,8 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2897
2963
|
{ at: path, match: Text.isText, split: !0, hanging: !0 }
|
|
2898
2964
|
);
|
|
2899
2965
|
});
|
|
2900
|
-
})
|
|
2901
|
-
|
|
2966
|
+
});
|
|
2967
|
+
else {
|
|
2902
2968
|
const existingMarks = {
|
|
2903
2969
|
...Editor.marks(editor) || {}
|
|
2904
2970
|
}.marks || [], marks = {
|
|
@@ -2959,25 +3025,6 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2959
3025
|
editor.pteIsMarkActive(mark) ? (debug$c(`Remove mark '${mark}'`), Editor.removeMark(editor, mark)) : (debug$c(`Add mark '${mark}'`), Editor.addMark(editor, mark, !0));
|
|
2960
3026
|
}, editor;
|
|
2961
3027
|
};
|
|
2962
|
-
function mergeSpans(editor) {
|
|
2963
|
-
const { selection } = editor;
|
|
2964
|
-
if (selection) {
|
|
2965
|
-
const textNodesInSelection = Array.from(
|
|
2966
|
-
Editor.nodes(editor, {
|
|
2967
|
-
at: Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]]),
|
|
2968
|
-
match: Text.isText,
|
|
2969
|
-
reverse: !0
|
|
2970
|
-
})
|
|
2971
|
-
);
|
|
2972
|
-
for (const [node, path] of textNodesInSelection) {
|
|
2973
|
-
const [parent] = path.length > 1 ? Editor.node(editor, Path.parent(path)) : [void 0], nextPath = [path[0], path[1] + 1];
|
|
2974
|
-
if (editor.isTextBlock(parent)) {
|
|
2975
|
-
const nextNode = parent.children[nextPath[1]];
|
|
2976
|
-
Text.isText(nextNode) && isEqual(nextNode.marks, node.marks) && (debug$c("Merging spans"), Transforms.mergeNodes(editor, { at: nextPath, voids: !0 }), editor.onChange());
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
3028
|
}
|
|
2982
3029
|
const debug$b = debugWithName("plugin:withPortableTextSelections"), debugVerbose$2 = debug$b.enabled && !1;
|
|
2983
3030
|
function createWithPortableTextSelections(change$, types) {
|
|
@@ -3837,10 +3884,8 @@ function useSyncValue(props) {
|
|
|
3837
3884
|
debug$5.enabled && debug$5(
|
|
3838
3885
|
"Validating and inserting new block in the end of the value",
|
|
3839
3886
|
currentBlock
|
|
3840
|
-
), validation.valid || validation.resolution?.autoResolve ?
|
|
3841
|
-
|
|
3842
|
-
at: [currentBlockIndex]
|
|
3843
|
-
});
|
|
3887
|
+
), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3888
|
+
at: [currentBlockIndex]
|
|
3844
3889
|
}) : (debug$5("Invalid", validation), change$.next({
|
|
3845
3890
|
type: "invalidValue",
|
|
3846
3891
|
resolution: validation.resolution,
|
|
@@ -3890,9 +3935,7 @@ function useSyncValue(props) {
|
|
|
3890
3935
|
}
|
|
3891
3936
|
function _replaceBlock(slateEditor, currentBlock, currentBlockIndex) {
|
|
3892
3937
|
const currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === currentBlockIndex;
|
|
3893
|
-
selectionFocusOnBlock && Transforms.deselect(slateEditor), Transforms.removeNodes(slateEditor, { at: [currentBlockIndex] }),
|
|
3894
|
-
Transforms.insertNodes(slateEditor, currentBlock, { at: [currentBlockIndex] });
|
|
3895
|
-
}), slateEditor.onChange(), selectionFocusOnBlock && Transforms.select(slateEditor, currentSelection);
|
|
3938
|
+
selectionFocusOnBlock && Transforms.deselect(slateEditor), Transforms.removeNodes(slateEditor, { at: [currentBlockIndex] }), Transforms.insertNodes(slateEditor, currentBlock, { at: [currentBlockIndex] }), slateEditor.onChange(), selectionFocusOnBlock && Transforms.select(slateEditor, currentSelection);
|
|
3896
3939
|
}
|
|
3897
3940
|
function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
3898
3941
|
if (Transforms.setNodes(slateEditor, currentBlock, {
|
|
@@ -3928,15 +3971,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3928
3971
|
));
|
|
3929
3972
|
} else oldBlockChild ? (debug$5("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
3930
3973
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3931
|
-
}),
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
}), slateEditor.onChange())
|
|
3936
|
-
Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3937
|
-
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3938
|
-
}), slateEditor.onChange();
|
|
3939
|
-
}));
|
|
3974
|
+
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3975
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3976
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$5("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3977
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3978
|
+
}), slateEditor.onChange());
|
|
3940
3979
|
});
|
|
3941
3980
|
}
|
|
3942
3981
|
}
|