@portabletext/editor 1.52.0 → 1.52.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/lib/_chunks-cjs/selection-point.cjs +2 -25
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -1
- package/lib/_chunks-es/selection-point.js +2 -25
- package/lib/_chunks-es/selection-point.js.map +1 -1
- package/lib/index.cjs +65 -138
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +67 -140
- package/lib/index.js.map +1 -1
- package/package.json +10 -10
- package/src/editor/components/render-element.tsx +27 -46
- package/src/editor/plugins/createWithSchemaTypes.ts +21 -1
- package/src/editor/plugins/with-plugins.ts +10 -15
- package/src/internal-utils/create-placeholder-block.ts +2 -1
- package/src/internal-utils/parse-blocks.ts +26 -15
- package/src/operations/behavior.operation.delete.ts +6 -1
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +0 -51
package/lib/index.js
CHANGED
|
@@ -7,9 +7,9 @@ import { useSelector, useActorRef } from "@xstate/react";
|
|
|
7
7
|
import noop from "lodash/noop.js";
|
|
8
8
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Transforms, Path, Operation, createEditor } from "slate";
|
|
9
9
|
import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
|
-
import debug$
|
|
10
|
+
import debug$g from "debug";
|
|
11
11
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
12
|
-
import { getBlockStartPoint, getBlockKeyFromSelectionPoint,
|
|
12
|
+
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, isTextBlock, parseBlock, sliceBlocks, parseAnnotation, blockOffsetToSpanSelectionPoint, parseInlineObject, isKeyedSegment, isSpan$1 as isSpan, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText, parseBlocks } from "./_chunks-es/selection-point.js";
|
|
13
13
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
14
14
|
import { isSelectionCollapsed, selectionPointToBlockOffset } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
15
15
|
import isEqual from "lodash/isEqual.js";
|
|
@@ -47,10 +47,10 @@ function EditorEventListener(props) {
|
|
|
47
47
|
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
|
|
48
48
|
}
|
|
49
49
|
const rootName = "sanity-pte:";
|
|
50
|
-
debug$
|
|
50
|
+
debug$g(rootName);
|
|
51
51
|
function debugWithName(name) {
|
|
52
52
|
const namespace = `${rootName}${name}`;
|
|
53
|
-
return debug$
|
|
53
|
+
return debug$g && debug$g.enabled(namespace) ? debug$g(namespace) : debug$g(rootName);
|
|
54
54
|
}
|
|
55
55
|
const VOID_CHILD_KEY = "void-child";
|
|
56
56
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1013,93 +1013,49 @@ function RenderTextBlock(props) {
|
|
|
1013
1013
|
] });
|
|
1014
1014
|
}
|
|
1015
1015
|
function RenderElement(props) {
|
|
1016
|
-
const $ = c(
|
|
1016
|
+
const $ = c(43), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp$1);
|
|
1017
1017
|
if ("__inline" in props.element && props.element.__inline === !0) {
|
|
1018
1018
|
let t02;
|
|
1019
|
-
|
|
1020
|
-
let t13;
|
|
1021
|
-
$[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = parseInlineObject({
|
|
1022
|
-
context: {
|
|
1023
|
-
keyGenerator: _temp2,
|
|
1024
|
-
schema
|
|
1025
|
-
},
|
|
1026
|
-
options: {
|
|
1027
|
-
refreshKeys: !1,
|
|
1028
|
-
validateFields: !1
|
|
1029
|
-
},
|
|
1030
|
-
inlineObject: {
|
|
1031
|
-
_key: props.element._key,
|
|
1032
|
-
_type: props.element._type,
|
|
1033
|
-
...t13
|
|
1034
|
-
}
|
|
1035
|
-
}), $[0] = props.element, $[1] = schema, $[2] = t02;
|
|
1036
|
-
} else
|
|
1037
|
-
t02 = $[2];
|
|
1038
|
-
const inlineObject = t02;
|
|
1039
|
-
inlineObject || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
|
|
1019
|
+
$[0] !== props.element ? (t02 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[0] = props.element, $[1] = t02) : t02 = $[1];
|
|
1040
1020
|
let t12;
|
|
1041
|
-
$[
|
|
1021
|
+
$[2] !== props.element._key || $[3] !== props.element._type || $[4] !== t02 ? (t12 = {
|
|
1042
1022
|
_key: props.element._key,
|
|
1043
|
-
_type: props.element._type
|
|
1044
|
-
|
|
1023
|
+
_type: props.element._type,
|
|
1024
|
+
...t02
|
|
1025
|
+
}, $[2] = props.element._key, $[3] = props.element._type, $[4] = t02, $[5] = t12) : t12 = $[5];
|
|
1026
|
+
const inlineObject = t12;
|
|
1027
|
+
schema.inlineObjects.find((inlineObject_0) => inlineObject_0.name === props.element._type) || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
|
|
1045
1028
|
let t22;
|
|
1046
|
-
|
|
1029
|
+
$[6] !== inlineObject || $[7] !== props.element._key || $[8] !== props.element._type ? (t22 = inlineObject ?? {
|
|
1030
|
+
_key: props.element._key,
|
|
1031
|
+
_type: props.element._type
|
|
1032
|
+
}, $[6] = inlineObject, $[7] = props.element._key, $[8] = props.element._type, $[9] = t22) : t22 = $[9];
|
|
1033
|
+
let t32;
|
|
1034
|
+
return $[10] !== props.attributes || $[11] !== props.children || $[12] !== props.element || $[13] !== props.readOnly || $[14] !== props.renderChild || $[15] !== t22 ? (t32 = /* @__PURE__ */ jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t22, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[10] = props.attributes, $[11] = props.children, $[12] = props.element, $[13] = props.readOnly, $[14] = props.renderChild, $[15] = t22, $[16] = t32) : t32 = $[16], t32;
|
|
1047
1035
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
},
|
|
1054
|
-
options: {
|
|
1055
|
-
refreshKeys: !1,
|
|
1056
|
-
validateFields: !1
|
|
1057
|
-
},
|
|
1058
|
-
block: props.element
|
|
1059
|
-
}), $[16] = props.element, $[17] = schema, $[18] = t0) : t0 = $[18];
|
|
1060
|
-
const textBlock = t0;
|
|
1061
|
-
if (textBlock) {
|
|
1062
|
-
let t12;
|
|
1063
|
-
return $[19] !== props.attributes || $[20] !== props.children || $[21] !== props.element || $[22] !== props.readOnly || $[23] !== props.renderBlock || $[24] !== props.renderListItem || $[25] !== props.renderStyle || $[26] !== props.spellCheck || $[27] !== textBlock ? (t12 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock, children: props.children }), $[19] = props.attributes, $[20] = props.children, $[21] = props.element, $[22] = props.readOnly, $[23] = props.renderBlock, $[24] = props.renderListItem, $[25] = props.renderStyle, $[26] = props.spellCheck, $[27] = textBlock, $[28] = t12) : t12 = $[28], t12;
|
|
1036
|
+
if (isTextBlock({
|
|
1037
|
+
schema
|
|
1038
|
+
}, props.element)) {
|
|
1039
|
+
let t02;
|
|
1040
|
+
return $[17] !== props.attributes || $[18] !== props.children || $[19] !== props.element || $[20] !== props.readOnly || $[21] !== props.renderBlock || $[22] !== props.renderListItem || $[23] !== props.renderStyle || $[24] !== props.spellCheck ? (t02 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[17] = props.attributes, $[18] = props.children, $[19] = props.element, $[20] = props.readOnly, $[21] = props.renderBlock, $[22] = props.renderListItem, $[23] = props.renderStyle, $[24] = props.spellCheck, $[25] = t02) : t02 = $[25], t02;
|
|
1064
1041
|
}
|
|
1042
|
+
let t0;
|
|
1043
|
+
$[26] !== props.element ? (t0 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[26] = props.element, $[27] = t0) : t0 = $[27];
|
|
1065
1044
|
let t1;
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
schema
|
|
1072
|
-
},
|
|
1073
|
-
options: {
|
|
1074
|
-
refreshKeys: !1,
|
|
1075
|
-
validateFields: !1
|
|
1076
|
-
},
|
|
1077
|
-
blockObject: {
|
|
1078
|
-
_key: props.element._key,
|
|
1079
|
-
_type: props.element._type,
|
|
1080
|
-
...t22
|
|
1081
|
-
}
|
|
1082
|
-
}), $[29] = props.element, $[30] = schema, $[31] = t1;
|
|
1083
|
-
} else
|
|
1084
|
-
t1 = $[31];
|
|
1045
|
+
$[28] !== props.element._key || $[29] !== props.element._type || $[30] !== t0 ? (t1 = {
|
|
1046
|
+
_key: props.element._key,
|
|
1047
|
+
_type: props.element._type,
|
|
1048
|
+
...t0
|
|
1049
|
+
}, $[28] = props.element._key, $[29] = props.element._type, $[30] = t0, $[31] = t1) : t1 = $[31];
|
|
1085
1050
|
const blockObject = t1;
|
|
1086
|
-
|
|
1051
|
+
schema.blockObjects.find((blockObject_0) => blockObject_0.name === props.element._type) || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
|
|
1087
1052
|
let t2;
|
|
1088
|
-
$[
|
|
1053
|
+
$[32] !== blockObject || $[33] !== props.element._key || $[34] !== props.element._type ? (t2 = blockObject ?? {
|
|
1089
1054
|
_key: props.element._key,
|
|
1090
1055
|
_type: props.element._type
|
|
1091
|
-
}, $[
|
|
1056
|
+
}, $[32] = blockObject, $[33] = props.element._key, $[34] = props.element._type, $[35] = t2) : t2 = $[35];
|
|
1092
1057
|
let t3;
|
|
1093
|
-
return $[
|
|
1094
|
-
}
|
|
1095
|
-
function _temp4() {
|
|
1096
|
-
return "";
|
|
1097
|
-
}
|
|
1098
|
-
function _temp3() {
|
|
1099
|
-
return "";
|
|
1100
|
-
}
|
|
1101
|
-
function _temp2() {
|
|
1102
|
-
return "";
|
|
1058
|
+
return $[36] !== props.attributes || $[37] !== props.children || $[38] !== props.element || $[39] !== props.readOnly || $[40] !== props.renderBlock || $[41] !== t2 ? (t3 = /* @__PURE__ */ jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[36] = props.attributes, $[37] = props.children, $[38] = props.element, $[39] = props.readOnly, $[40] = props.renderBlock, $[41] = t2, $[42] = t3) : t3 = $[42], t3;
|
|
1103
1059
|
}
|
|
1104
1060
|
function _temp$1(s) {
|
|
1105
1061
|
return s.context.schema;
|
|
@@ -1556,7 +1512,7 @@ function getEditorSnapshot({
|
|
|
1556
1512
|
}
|
|
1557
1513
|
};
|
|
1558
1514
|
}
|
|
1559
|
-
const debug$
|
|
1515
|
+
const debug$f = debugWithName("plugin:withPortableTextMarkModel");
|
|
1560
1516
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1561
1517
|
return function(editor) {
|
|
1562
1518
|
const {
|
|
@@ -1570,7 +1526,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1570
1526
|
for (const [child, childPath] of children) {
|
|
1571
1527
|
const nextNode = node.children[childPath[1] + 1];
|
|
1572
1528
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
1573
|
-
debug$
|
|
1529
|
+
debug$f("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
1574
1530
|
type: "normalizing"
|
|
1575
1531
|
}), Transforms.mergeNodes(editor, {
|
|
1576
1532
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -1583,7 +1539,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1583
1539
|
}
|
|
1584
1540
|
}
|
|
1585
1541
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
1586
|
-
debug$
|
|
1542
|
+
debug$f("Adding .markDefs to block node"), editorActor.send({
|
|
1587
1543
|
type: "normalizing"
|
|
1588
1544
|
}), Transforms.setNodes(editor, {
|
|
1589
1545
|
markDefs: []
|
|
@@ -1595,7 +1551,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1595
1551
|
return;
|
|
1596
1552
|
}
|
|
1597
1553
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
1598
|
-
debug$
|
|
1554
|
+
debug$f("Adding .marks to span node"), editorActor.send({
|
|
1599
1555
|
type: "normalizing"
|
|
1600
1556
|
}), Transforms.setNodes(editor, {
|
|
1601
1557
|
marks: []
|
|
@@ -1609,7 +1565,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1609
1565
|
if (editor.isTextSpan(node)) {
|
|
1610
1566
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
1611
1567
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
1612
|
-
debug$
|
|
1568
|
+
debug$f("Removing annotations from empty span node"), editorActor.send({
|
|
1613
1569
|
type: "normalizing"
|
|
1614
1570
|
}), Transforms.setNodes(editor, {
|
|
1615
1571
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -1627,7 +1583,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1627
1583
|
if (editor.isTextSpan(child)) {
|
|
1628
1584
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
1629
1585
|
if (orphanedAnnotations.length > 0) {
|
|
1630
|
-
debug$
|
|
1586
|
+
debug$f("Removing orphaned annotations from span node"), editorActor.send({
|
|
1631
1587
|
type: "normalizing"
|
|
1632
1588
|
}), Transforms.setNodes(editor, {
|
|
1633
1589
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1645,7 +1601,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1645
1601
|
if (editor.isTextBlock(block)) {
|
|
1646
1602
|
const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
1647
1603
|
if (orphanedAnnotations.length > 0) {
|
|
1648
|
-
debug$
|
|
1604
|
+
debug$f("Removing orphaned annotations from span node"), editorActor.send({
|
|
1649
1605
|
type: "normalizing"
|
|
1650
1606
|
}), Transforms.setNodes(editor, {
|
|
1651
1607
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -1663,7 +1619,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1663
1619
|
for (const markDef of markDefs)
|
|
1664
1620
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
1665
1621
|
if (markDefs.length !== newMarkDefs.length) {
|
|
1666
|
-
debug$
|
|
1622
|
+
debug$f("Removing duplicate markDefs"), editorActor.send({
|
|
1667
1623
|
type: "normalizing"
|
|
1668
1624
|
}), Transforms.setNodes(editor, {
|
|
1669
1625
|
markDefs: newMarkDefs
|
|
@@ -1678,7 +1634,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1678
1634
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
1679
1635
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
1680
1636
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
1681
|
-
debug$
|
|
1637
|
+
debug$f("Removing markDef not in use"), editorActor.send({
|
|
1682
1638
|
type: "normalizing"
|
|
1683
1639
|
}), Transforms.setNodes(editor, {
|
|
1684
1640
|
markDefs: newMarkDefs
|
|
@@ -1831,7 +1787,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1831
1787
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
1832
1788
|
if (editor.isTextBlock(targetBlock)) {
|
|
1833
1789
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
1834
|
-
debug$
|
|
1790
|
+
debug$f("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
1835
1791
|
markDefs: newMarkDefs
|
|
1836
1792
|
}, {
|
|
1837
1793
|
at: targetPath,
|
|
@@ -2541,7 +2497,7 @@ function withUndoStep(editor, fn) {
|
|
|
2541
2497
|
function getCurrentUndoStepId(editor) {
|
|
2542
2498
|
return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
|
|
2543
2499
|
}
|
|
2544
|
-
const debug$
|
|
2500
|
+
const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2545
2501
|
const state = SAVING.get(editor);
|
|
2546
2502
|
return state === void 0 ? !0 : state;
|
|
2547
2503
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -2554,7 +2510,7 @@ function createWithUndoRedo(options) {
|
|
|
2554
2510
|
const remotePatches = getRemotePatches(editor);
|
|
2555
2511
|
let previousUndoStepId = getCurrentUndoStepId(editor);
|
|
2556
2512
|
options.subscriptions.push(() => {
|
|
2557
|
-
debug$
|
|
2513
|
+
debug$e("Subscribing to patches");
|
|
2558
2514
|
const sub = editorActor.on("patches", ({
|
|
2559
2515
|
patches,
|
|
2560
2516
|
snapshot
|
|
@@ -2563,7 +2519,7 @@ function createWithUndoRedo(options) {
|
|
|
2563
2519
|
patches.forEach((patch) => {
|
|
2564
2520
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2565
2521
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2566
|
-
debug$
|
|
2522
|
+
debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
2567
2523
|
undos: [],
|
|
2568
2524
|
redos: []
|
|
2569
2525
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2579,7 +2535,7 @@ function createWithUndoRedo(options) {
|
|
|
2579
2535
|
}), previousSnapshot = snapshot;
|
|
2580
2536
|
});
|
|
2581
2537
|
return () => {
|
|
2582
|
-
debug$
|
|
2538
|
+
debug$e("Unsubscribing to patches"), sub.unsubscribe();
|
|
2583
2539
|
};
|
|
2584
2540
|
}), editor.history = {
|
|
2585
2541
|
undos: [],
|
|
@@ -2618,7 +2574,7 @@ function createWithUndoRedo(options) {
|
|
|
2618
2574
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
2619
2575
|
timestamp: /* @__PURE__ */ new Date()
|
|
2620
2576
|
};
|
|
2621
|
-
undos.push(newStep), debug$
|
|
2577
|
+
undos.push(newStep), debug$e("Created new undo step", step);
|
|
2622
2578
|
}
|
|
2623
2579
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
2624
2580
|
undos.shift();
|
|
@@ -2636,7 +2592,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2636
2592
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2637
2593
|
if (undos.length > 0) {
|
|
2638
2594
|
const step = undos[undos.length - 1];
|
|
2639
|
-
if (debug$
|
|
2595
|
+
if (debug$e("Undoing", step), step.operations.length > 0) {
|
|
2640
2596
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2641
2597
|
let transformedOperations = step.operations;
|
|
2642
2598
|
otherPatches.forEach((item) => {
|
|
@@ -2654,7 +2610,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2654
2610
|
});
|
|
2655
2611
|
});
|
|
2656
2612
|
} catch (err) {
|
|
2657
|
-
debug$
|
|
2613
|
+
debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2658
2614
|
undos: [],
|
|
2659
2615
|
redos: []
|
|
2660
2616
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2671,7 +2627,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2671
2627
|
} = editor.history, remotePatches = getRemotePatches(editor);
|
|
2672
2628
|
if (redos.length > 0) {
|
|
2673
2629
|
const step = redos[redos.length - 1];
|
|
2674
|
-
if (debug$
|
|
2630
|
+
if (debug$e("Redoing", step), step.operations.length > 0) {
|
|
2675
2631
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2676
2632
|
let transformedOperations = step.operations;
|
|
2677
2633
|
otherPatches.forEach((item) => {
|
|
@@ -2688,7 +2644,7 @@ const historyUndoOperationImplementation = ({
|
|
|
2688
2644
|
});
|
|
2689
2645
|
});
|
|
2690
2646
|
} catch (err) {
|
|
2691
|
-
debug$
|
|
2647
|
+
debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2692
2648
|
undos: [],
|
|
2693
2649
|
redos: []
|
|
2694
2650
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2706,16 +2662,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2706
2662
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2707
2663
|
_key: blk._key
|
|
2708
2664
|
}, patch.path[0]));
|
|
2709
|
-
return debug$
|
|
2665
|
+
return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2710
2666
|
}
|
|
2711
2667
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2712
2668
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
2713
2669
|
_key: blk._key
|
|
2714
2670
|
}, patch.path[0]));
|
|
2715
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
2671
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2716
2672
|
}
|
|
2717
2673
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2718
|
-
return debug$
|
|
2674
|
+
return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2719
2675
|
if (patch.type === "diffMatchPatch") {
|
|
2720
2676
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2721
2677
|
return !operationTargetBlock || !isEqual({
|
|
@@ -3165,6 +3121,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3165
3121
|
};
|
|
3166
3122
|
}
|
|
3167
3123
|
}, deleteOperationImplementation = ({
|
|
3124
|
+
context,
|
|
3168
3125
|
operation
|
|
3169
3126
|
}) => {
|
|
3170
3127
|
const anchorBlockKey = getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
|
|
@@ -3177,7 +3134,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3177
3134
|
if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3178
3135
|
Transforms.removeNodes(operation.editor, {
|
|
3179
3136
|
at: [anchorBlockPath[0]]
|
|
3180
|
-
});
|
|
3137
|
+
}), operation.editor.children.length === 0 && Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
3181
3138
|
return;
|
|
3182
3139
|
}
|
|
3183
3140
|
const range = toSlateRange(operation.at, operation.editor);
|
|
@@ -4480,7 +4437,7 @@ function withoutPatching(editor, fn) {
|
|
|
4480
4437
|
function isPatching(editor) {
|
|
4481
4438
|
return PATCHING.get(editor);
|
|
4482
4439
|
}
|
|
4483
|
-
const debug$
|
|
4440
|
+
const debug$d = debugWithName("plugin:withPatches");
|
|
4484
4441
|
function createWithPatches({
|
|
4485
4442
|
editorActor,
|
|
4486
4443
|
relayActor,
|
|
@@ -4505,7 +4462,7 @@ function createWithPatches({
|
|
|
4505
4462
|
withoutPatching(editor, () => {
|
|
4506
4463
|
withoutSaving(editor, () => {
|
|
4507
4464
|
for (const patch of patches) {
|
|
4508
|
-
debug$
|
|
4465
|
+
debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`);
|
|
4509
4466
|
try {
|
|
4510
4467
|
changed = applyPatch(editor, patch);
|
|
4511
4468
|
} catch (error) {
|
|
@@ -4523,10 +4480,10 @@ function createWithPatches({
|
|
|
4523
4480
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
4524
4481
|
};
|
|
4525
4482
|
return subscriptions.push(() => {
|
|
4526
|
-
debug$
|
|
4483
|
+
debug$d("Subscribing to remote patches");
|
|
4527
4484
|
const sub = editorActor.on("patches", handlePatches);
|
|
4528
4485
|
return () => {
|
|
4529
|
-
debug$
|
|
4486
|
+
debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
4530
4487
|
};
|
|
4531
4488
|
}), editor.apply = (operation) => {
|
|
4532
4489
|
let patches = [];
|
|
@@ -4580,7 +4537,7 @@ function createWithPatches({
|
|
|
4580
4537
|
}, editor;
|
|
4581
4538
|
};
|
|
4582
4539
|
}
|
|
4583
|
-
const debug$
|
|
4540
|
+
const debug$c = debugWithName("plugin:withPlaceholderBlock");
|
|
4584
4541
|
function createWithPlaceholderBlock(editorActor) {
|
|
4585
4542
|
return function(editor) {
|
|
4586
4543
|
const {
|
|
@@ -4605,7 +4562,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4605
4562
|
const node = op.node;
|
|
4606
4563
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
4607
4564
|
const nextPath = Path.next(op.path);
|
|
4608
|
-
editor.children[nextPath[0]] || (debug$
|
|
4565
|
+
editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
4609
4566
|
decorators: []
|
|
4610
4567
|
})));
|
|
4611
4568
|
}
|
|
@@ -4614,36 +4571,6 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4614
4571
|
}, editor;
|
|
4615
4572
|
};
|
|
4616
4573
|
}
|
|
4617
|
-
const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
|
|
4618
|
-
function createWithPortableTextBlockStyle(editorActor) {
|
|
4619
|
-
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
|
|
4620
|
-
return function(editor) {
|
|
4621
|
-
const {
|
|
4622
|
-
normalizeNode
|
|
4623
|
-
} = editor;
|
|
4624
|
-
return editor.normalizeNode = (nodeEntry) => {
|
|
4625
|
-
const [, path] = nodeEntry;
|
|
4626
|
-
for (const op of editor.operations)
|
|
4627
|
-
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
|
|
4628
|
-
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
4629
|
-
if (Text.isText(child) && child.text === "") {
|
|
4630
|
-
debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
4631
|
-
type: "normalizing"
|
|
4632
|
-
}), Transforms.setNodes(editor, {
|
|
4633
|
-
style: defaultStyle
|
|
4634
|
-
}, {
|
|
4635
|
-
at: [op.path[0] + 1],
|
|
4636
|
-
voids: !1
|
|
4637
|
-
}), editorActor.send({
|
|
4638
|
-
type: "done normalizing"
|
|
4639
|
-
});
|
|
4640
|
-
return;
|
|
4641
|
-
}
|
|
4642
|
-
}
|
|
4643
|
-
normalizeNode(nodeEntry);
|
|
4644
|
-
}, editor;
|
|
4645
|
-
};
|
|
4646
|
-
}
|
|
4647
4574
|
debugWithName("plugin:withPortableTextSelections");
|
|
4648
4575
|
function createWithPortableTextSelections(editorActor) {
|
|
4649
4576
|
let prevSelection = null;
|
|
@@ -4683,7 +4610,7 @@ function createWithSchemaTypes({
|
|
|
4683
4610
|
editorActor
|
|
4684
4611
|
}) {
|
|
4685
4612
|
return function(editor) {
|
|
4686
|
-
editor.isTextBlock = (value) => isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4613
|
+
editor.isTextBlock = (value) => Editor.isEditor(value) ? !1 : isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => Editor.isEditor(value) ? !1 : isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => Editor.isEditor(value) ? !1 : isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4687
4614
|
const {
|
|
4688
4615
|
normalizeNode
|
|
4689
4616
|
} = editor;
|
|
@@ -5136,10 +5063,10 @@ const withPlugins = (editor, options) => {
|
|
|
5136
5063
|
}), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
|
|
5137
5064
|
editorActor,
|
|
5138
5065
|
subscriptions: options.subscriptions
|
|
5139
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor),
|
|
5066
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5140
5067
|
editorActor
|
|
5141
5068
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5142
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(
|
|
5069
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))))))))))));
|
|
5143
5070
|
}, debug$a = debugWithName("setup");
|
|
5144
5071
|
function createSlateEditor(config) {
|
|
5145
5072
|
debug$a("Creating new Slate editor instance");
|