@portabletext/editor 1.0.11 → 1.0.13
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 +208 -216
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +204 -212
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +208 -216
- package/lib/index.mjs.map +1 -1
- package/package.json +19 -17
- package/src/editor/__tests__/PortableTextEditor.test.tsx +15 -1
- package/src/editor/__tests__/handleClick.test.tsx +40 -20
- package/src/editor/__tests__/utils.ts +14 -15
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +62 -20
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +19 -0
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +259 -134
- package/src/editor/plugins/__tests__/withHotkeys.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withInsertBreak.test.tsx +18 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +176 -154
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +17 -0
- package/src/editor/plugins/createWithObjectKeys.ts +23 -8
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +68 -14
- package/src/editor/plugins/createWithUndoRedo.ts +5 -7
- package/src/editor/plugins/index.ts +5 -1
- package/src/utils/__tests__/values.test.ts +1 -0
- package/src/utils/operationToPatches.ts +0 -1
- package/src/utils/withPreserveKeys.ts +7 -0
package/lib/index.js
CHANGED
|
@@ -169,8 +169,7 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
172
|
-
|
|
173
|
-
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
172
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
|
|
174
173
|
}
|
|
175
174
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_PROCESSING_LOCAL_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("pre", { children: JSON.stringify(props.value, null, 2) }) }), DefaultBlockObject = styledComponents.styled.div`
|
|
176
175
|
user-select: none;
|
|
@@ -639,13 +638,12 @@ function DefaultAnnotation(props) {
|
|
|
639
638
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "blue" }, onClick: handleClick, children: props.children });
|
|
640
639
|
}
|
|
641
640
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
642
|
-
var _a, _b, _c;
|
|
643
641
|
if (!portableTextType)
|
|
644
642
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
645
|
-
const blockType =
|
|
643
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
646
644
|
if (!blockType)
|
|
647
645
|
throw new Error("Block type is not defined in this schema (required)");
|
|
648
|
-
const childrenField =
|
|
646
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
649
647
|
if (!childrenField)
|
|
650
648
|
throw new Error("Children field for block type found in schema (required)");
|
|
651
649
|
const ofType = childrenField.type.of;
|
|
@@ -654,7 +652,7 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
654
652
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
655
653
|
if (!spanType)
|
|
656
654
|
throw new Error("Span type not found in schema (required)");
|
|
657
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes =
|
|
655
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
658
656
|
return {
|
|
659
657
|
styles: resolveEnabledStyles(blockType),
|
|
660
658
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -668,11 +666,10 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
668
666
|
};
|
|
669
667
|
}
|
|
670
668
|
function resolveEnabledStyles(blockType) {
|
|
671
|
-
|
|
672
|
-
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
669
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
673
670
|
if (!styleField)
|
|
674
671
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
675
|
-
const textStyles =
|
|
672
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
676
673
|
if (!textStyles || textStyles.length === 0)
|
|
677
674
|
throw new Error(
|
|
678
675
|
"The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}."
|
|
@@ -683,11 +680,10 @@ function resolveEnabledDecorators(spanType) {
|
|
|
683
680
|
return spanType.decorators;
|
|
684
681
|
}
|
|
685
682
|
function resolveEnabledListItems(blockType) {
|
|
686
|
-
|
|
687
|
-
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
683
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
688
684
|
if (!listField)
|
|
689
685
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
690
|
-
const listItems =
|
|
686
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
691
687
|
if (!listItems)
|
|
692
688
|
throw new Error("The list field need at least to be an empty array");
|
|
693
689
|
return listItems;
|
|
@@ -702,7 +698,6 @@ function compileType(rawType) {
|
|
|
702
698
|
}).get(rawType.name);
|
|
703
699
|
}
|
|
704
700
|
const debug$k = debugWithName("operationToPatches");
|
|
705
|
-
debug$k.enabled = !1;
|
|
706
701
|
function createOperationToPatches(types2) {
|
|
707
702
|
const textBlockName = types2.block.name;
|
|
708
703
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
@@ -765,7 +760,7 @@ function createOperationToPatches(types2) {
|
|
|
765
760
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
766
761
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
767
762
|
if (operation.path.length === 1) {
|
|
768
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
763
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
769
764
|
return targetKey ? [
|
|
770
765
|
patches.insert([fromSlateValue([operation.node], textBlockName)[0]], position, [
|
|
771
766
|
{ _key: targetKey }
|
|
@@ -867,7 +862,7 @@ function createOperationToPatches(types2) {
|
|
|
867
862
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
868
863
|
const patches$1 = [], block = beforeValue[operation.path[0]], targetBlock = editor.children[operation.path[0]];
|
|
869
864
|
if (operation.path.length === 1)
|
|
870
|
-
if (block
|
|
865
|
+
if (block?._key) {
|
|
871
866
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
872
867
|
patches$1.push(patches.set(newBlock, [{ _key: newBlock._key }])), patches$1.push(patches.unset([{ _key: block._key }]));
|
|
873
868
|
} else
|
|
@@ -965,7 +960,6 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
965
960
|
}
|
|
966
961
|
},
|
|
967
962
|
insertChild: (type, value) => {
|
|
968
|
-
var _a;
|
|
969
963
|
if (!editor.selection)
|
|
970
964
|
throw new Error("The editor has no selection");
|
|
971
965
|
const [focusBlock] = Array.from(
|
|
@@ -997,14 +991,13 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
997
991
|
return isSpanNode && focusNode._type !== types$1.span.name && (debug$j("Inserting span child next to inline object child, moving selection + 1"), editor.move({ distance: 1, unit: "character" })), slate.Transforms.insertNodes(editor, child, {
|
|
998
992
|
select: !0,
|
|
999
993
|
at: editor.selection
|
|
1000
|
-
}), editor.onChange(),
|
|
994
|
+
}), editor.onChange(), toPortableTextRange(
|
|
1001
995
|
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1002
996
|
editor.selection,
|
|
1003
997
|
types$1
|
|
1004
|
-
)
|
|
998
|
+
)?.focus.path || [];
|
|
1005
999
|
},
|
|
1006
1000
|
insertBlock: (type, value) => {
|
|
1007
|
-
var _a, _b, _c;
|
|
1008
1001
|
const block = toSlateValue(
|
|
1009
1002
|
[
|
|
1010
1003
|
{
|
|
@@ -1023,11 +1016,11 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1023
1016
|
reverse: !0
|
|
1024
1017
|
})
|
|
1025
1018
|
)[0];
|
|
1026
|
-
return slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: lastBlock[1] }), editor.onChange(),
|
|
1019
|
+
return slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: lastBlock[1] }), editor.onChange(), toPortableTextRange(
|
|
1027
1020
|
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1028
1021
|
editor.selection,
|
|
1029
1022
|
types$1
|
|
1030
|
-
)
|
|
1023
|
+
)?.focus.path ?? [];
|
|
1031
1024
|
}
|
|
1032
1025
|
const focusBlock = Array.from(
|
|
1033
1026
|
slate.Editor.nodes(editor, {
|
|
@@ -1035,11 +1028,11 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1035
1028
|
match: (n) => n._type === types$1.block.name
|
|
1036
1029
|
})
|
|
1037
1030
|
)[0];
|
|
1038
|
-
return slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: focusBlock[1] }), editor.onChange(),
|
|
1031
|
+
return slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: focusBlock[1] }), editor.onChange(), toPortableTextRange(
|
|
1039
1032
|
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1040
1033
|
editor.selection,
|
|
1041
1034
|
types$1
|
|
1042
|
-
)
|
|
1035
|
+
)?.focus.path || [];
|
|
1043
1036
|
},
|
|
1044
1037
|
hasBlockStyle: (style) => {
|
|
1045
1038
|
try {
|
|
@@ -1095,7 +1088,6 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1095
1088
|
return node;
|
|
1096
1089
|
},
|
|
1097
1090
|
activeAnnotations: () => {
|
|
1098
|
-
var _a;
|
|
1099
1091
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
1100
1092
|
return [];
|
|
1101
1093
|
try {
|
|
@@ -1105,9 +1097,9 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1105
1097
|
});
|
|
1106
1098
|
for (const [span, path] of spans) {
|
|
1107
1099
|
const [block] = slate.Editor.node(editor, path, { depth: 1 });
|
|
1108
|
-
editor.isTextBlock(block) &&
|
|
1100
|
+
editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
|
|
1109
1101
|
slate.Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
1110
|
-
})
|
|
1102
|
+
});
|
|
1111
1103
|
}
|
|
1112
1104
|
return activeAnnotations;
|
|
1113
1105
|
} catch {
|
|
@@ -1125,27 +1117,16 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1125
1117
|
})
|
|
1126
1118
|
];
|
|
1127
1119
|
if (spans.length === 0 || spans.some(
|
|
1128
|
-
([span]) =>
|
|
1129
|
-
var _a;
|
|
1130
|
-
return !types.isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
1131
|
-
}
|
|
1120
|
+
([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0
|
|
1132
1121
|
))
|
|
1133
1122
|
return !1;
|
|
1134
1123
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
1135
1124
|
const [block] = slate.Editor.node(editor, path, { depth: 1 });
|
|
1136
1125
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
1137
1126
|
}, []);
|
|
1138
|
-
return spans.every(([span]) =>
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map(
|
|
1142
|
-
(markKey) => {
|
|
1143
|
-
var _a2;
|
|
1144
|
-
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
1145
|
-
}
|
|
1146
|
-
);
|
|
1147
|
-
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotationType);
|
|
1148
|
-
});
|
|
1127
|
+
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map(
|
|
1128
|
+
(markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type
|
|
1129
|
+
)?.includes(annotationType) : !1);
|
|
1149
1130
|
} catch {
|
|
1150
1131
|
return !1;
|
|
1151
1132
|
}
|
|
@@ -1205,7 +1186,7 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1205
1186
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
1206
1187
|
throw new Error("Invalid range");
|
|
1207
1188
|
if (range) {
|
|
1208
|
-
if (!
|
|
1189
|
+
if (!options?.mode || options?.mode === "selected") {
|
|
1209
1190
|
debug$j("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
1210
1191
|
at: range,
|
|
1211
1192
|
hanging: !0,
|
|
@@ -1213,11 +1194,11 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1213
1194
|
}), editor.onChange();
|
|
1214
1195
|
return;
|
|
1215
1196
|
}
|
|
1216
|
-
|
|
1197
|
+
options?.mode === "blocks" && (debug$j("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
1217
1198
|
at: range,
|
|
1218
1199
|
voids: !0,
|
|
1219
1200
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
1220
|
-
})),
|
|
1201
|
+
})), options?.mode === "children" && (debug$j("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
1221
1202
|
at: range,
|
|
1222
1203
|
voids: !0,
|
|
1223
1204
|
match: (node) => node._type === types$1.span.name || // Text children
|
|
@@ -1316,6 +1297,10 @@ function withPreserveKeys(editor, fn) {
|
|
|
1316
1297
|
const prev = isPreservingKeys(editor);
|
|
1317
1298
|
PRESERVE_KEYS.set(editor, !0), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1318
1299
|
}
|
|
1300
|
+
function withoutPreserveKeys(editor, fn) {
|
|
1301
|
+
const prev = isPreservingKeys(editor);
|
|
1302
|
+
PRESERVE_KEYS.set(editor, !1), fn(), PRESERVE_KEYS.set(editor, prev);
|
|
1303
|
+
}
|
|
1319
1304
|
function isPreservingKeys(editor) {
|
|
1320
1305
|
return PRESERVE_KEYS.get(editor);
|
|
1321
1306
|
}
|
|
@@ -1326,17 +1311,27 @@ function createWithObjectKeys(schemaTypes, keyGenerator) {
|
|
|
1326
1311
|
return editor.apply = (operation) => {
|
|
1327
1312
|
if (operation.type === "split_node") {
|
|
1328
1313
|
const withNewKey = !isPreservingKeys(editor) || !("_key" in operation.properties);
|
|
1329
|
-
|
|
1330
|
-
...operation
|
|
1331
|
-
|
|
1332
|
-
|
|
1314
|
+
apply2({
|
|
1315
|
+
...operation,
|
|
1316
|
+
properties: {
|
|
1317
|
+
...operation.properties,
|
|
1318
|
+
...withNewKey ? { _key: keyGenerator() } : {}
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
return;
|
|
1333
1322
|
}
|
|
1334
1323
|
if (operation.type === "insert_node") {
|
|
1335
1324
|
const withNewKey = !isPreservingKeys(editor) || !("_key" in operation.node);
|
|
1336
|
-
slate.Editor.isEditor(operation.node)
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1325
|
+
if (!slate.Editor.isEditor(operation.node)) {
|
|
1326
|
+
apply2({
|
|
1327
|
+
...operation,
|
|
1328
|
+
node: {
|
|
1329
|
+
...operation.node,
|
|
1330
|
+
...withNewKey ? { _key: keyGenerator() } : {}
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1340
1335
|
}
|
|
1341
1336
|
apply2(operation);
|
|
1342
1337
|
}, editor.normalizeNode = (entry) => {
|
|
@@ -2224,7 +2219,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2224
2219
|
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
2225
2220
|
return isMatch && (childIndex = index), isMatch;
|
|
2226
2221
|
});
|
|
2227
|
-
return child ? { block, child, blockPath, childPath: blockPath
|
|
2222
|
+
return child ? { block, child, blockPath, childPath: blockPath?.concat(childIndex) } : { block, blockPath, child: void 0, childPath: void 0 };
|
|
2228
2223
|
}
|
|
2229
2224
|
function withRemoteChanges(editor, fn) {
|
|
2230
2225
|
const prev = isChangingRemotely(editor) || !1;
|
|
@@ -2313,11 +2308,12 @@ function createWithUndoRedo(options) {
|
|
|
2313
2308
|
)
|
|
2314
2309
|
);
|
|
2315
2310
|
});
|
|
2311
|
+
const reversedOperations = transformedOperations.map(slate.Operation.inverse).reverse();
|
|
2316
2312
|
try {
|
|
2317
2313
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2318
2314
|
withPreserveKeys(editor, () => {
|
|
2319
2315
|
withoutSaving(editor, () => {
|
|
2320
|
-
|
|
2316
|
+
reversedOperations.forEach((op) => {
|
|
2321
2317
|
editor.apply(op);
|
|
2322
2318
|
});
|
|
2323
2319
|
});
|
|
@@ -2390,14 +2386,13 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2390
2386
|
if (patch.type === "diffMatchPatch") {
|
|
2391
2387
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2392
2388
|
return !operationTargetBlock || !isEqual__default.default({ _key: operationTargetBlock._key }, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2393
|
-
var _a, _b, _c, _d;
|
|
2394
2389
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2395
2390
|
const { diffs } = diffPatch;
|
|
2396
2391
|
if (diffs.forEach((diff2, index) => {
|
|
2397
2392
|
const [diffType, text] = diff2;
|
|
2398
2393
|
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2399
2394
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2400
|
-
const currentFocus =
|
|
2395
|
+
const currentFocus = transformedOperation.properties?.focus ? { ...transformedOperation.properties.focus } : void 0, currentAnchor = transformedOperation?.properties?.anchor ? { ...transformedOperation.properties.anchor } : void 0, newFocus = transformedOperation?.newProperties?.focus ? { ...transformedOperation.newProperties.focus } : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? { ...transformedOperation.newProperties.anchor } : void 0;
|
|
2401
2396
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2402
2397
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
2403
2398
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2413,14 +2408,13 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2413
2408
|
return [transformedOperation];
|
|
2414
2409
|
}
|
|
2415
2410
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2416
|
-
var _a, _b, _c, _d;
|
|
2417
2411
|
const transformedOperation = { ...operation };
|
|
2418
2412
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2419
2413
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
2420
2414
|
transformedOperation.path = newPath;
|
|
2421
2415
|
}
|
|
2422
2416
|
if (transformedOperation.type === "set_selection") {
|
|
2423
|
-
const currentFocus =
|
|
2417
|
+
const currentFocus = transformedOperation.properties?.focus ? { ...transformedOperation.properties.focus } : void 0, currentAnchor = transformedOperation?.properties?.anchor ? { ...transformedOperation.properties.anchor } : void 0, newFocus = transformedOperation?.newProperties?.focus ? { ...transformedOperation.newProperties.focus } : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? { ...transformedOperation.newProperties.anchor } : void 0;
|
|
2424
2418
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
2425
2419
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
2426
2420
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -2718,8 +2712,23 @@ function createWithPortableTextLists(types2) {
|
|
|
2718
2712
|
}, editor;
|
|
2719
2713
|
};
|
|
2720
2714
|
}
|
|
2715
|
+
function isPortableTextSpan(node) {
|
|
2716
|
+
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
2717
|
+
}
|
|
2718
|
+
function isPortableTextBlock(node) {
|
|
2719
|
+
return (
|
|
2720
|
+
// A block doesn't _have_ to be named 'block' - to differentiate between
|
|
2721
|
+
// allowed child types and marks, one might name them differently
|
|
2722
|
+
typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
|
|
2723
|
+
node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
|
|
2724
|
+
(!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
|
|
2725
|
+
node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
|
|
2726
|
+
"children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
|
|
2727
|
+
node.children.every((child) => typeof child == "object" && "_type" in child)
|
|
2728
|
+
);
|
|
2729
|
+
}
|
|
2721
2730
|
const debug$c = debugWithName("plugin:withPortableTextMarkModel");
|
|
2722
|
-
function createWithPortableTextMarkModel(types2, change
|
|
2731
|
+
function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
2723
2732
|
return function(editor) {
|
|
2724
2733
|
const { apply: apply2, normalizeNode } = editor, decorators = types2.decorators.map((t) => t.value), forceNewSelection = () => {
|
|
2725
2734
|
editor.selection && (slate.Transforms.select(editor, { ...editor.selection }), editor.selection = { ...editor.selection });
|
|
@@ -2745,10 +2754,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2745
2754
|
);
|
|
2746
2755
|
if (annotationMarks.length > 0) {
|
|
2747
2756
|
const [block] = slate.Editor.node(editor, slate.Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2748
|
-
(mark) =>
|
|
2749
|
-
var _a;
|
|
2750
|
-
return !((_a = block.markDefs) != null && _a.find((def) => def._key === mark));
|
|
2751
|
-
}
|
|
2757
|
+
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2752
2758
|
) || [];
|
|
2753
2759
|
orphanedMarks.length > 0 && (debug$c("Removing orphaned .marks from span node"), slate.Transforms.setNodes(
|
|
2754
2760
|
editor,
|
|
@@ -2800,10 +2806,9 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2800
2806
|
), editor.onChange());
|
|
2801
2807
|
}
|
|
2802
2808
|
}, editor.apply = (op) => {
|
|
2803
|
-
var _a, _b;
|
|
2804
2809
|
if (op.type === "insert_text") {
|
|
2805
2810
|
const { selection } = editor;
|
|
2806
|
-
if (selection && slate.Range.isCollapsed(selection) &&
|
|
2811
|
+
if (selection && slate.Range.isCollapsed(selection) && slate.Editor.marks(editor)?.marks?.some((mark) => !decorators.includes(mark))) {
|
|
2807
2812
|
const [node] = Array.from(
|
|
2808
2813
|
slate.Editor.nodes(editor, {
|
|
2809
2814
|
mode: "lowest",
|
|
@@ -2813,18 +2818,41 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2813
2818
|
})
|
|
2814
2819
|
)[0] || [void 0];
|
|
2815
2820
|
if (slate.Text.isText(node) && node.text.length === selection.focus.offset && Array.isArray(node.marks) && node.marks.length > 0) {
|
|
2816
|
-
apply2(op), slate.Transforms.splitNodes(editor, {
|
|
2817
|
-
match: slate.Text.isText,
|
|
2818
|
-
at: { ...selection.focus, offset: selection.focus.offset }
|
|
2819
|
-
});
|
|
2820
2821
|
const marksWithoutAnnotationMarks = ({
|
|
2821
2822
|
...slate.Editor.marks(editor) || {}
|
|
2822
2823
|
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
2823
|
-
slate.Transforms.
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2824
|
+
slate.Transforms.insertNodes(editor, {
|
|
2825
|
+
_type: "span",
|
|
2826
|
+
_key: keyGenerator(),
|
|
2827
|
+
text: op.text,
|
|
2828
|
+
marks: marksWithoutAnnotationMarks
|
|
2829
|
+
}), debug$c("Inserting text at end of annotation");
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
if (op.type === "remove_text") {
|
|
2835
|
+
const node = Array.from(
|
|
2836
|
+
slate.Editor.nodes(editor, {
|
|
2837
|
+
mode: "lowest",
|
|
2838
|
+
at: { path: op.path, offset: op.offset },
|
|
2839
|
+
match: (n) => n._type === types2.span.name,
|
|
2840
|
+
voids: !1
|
|
2841
|
+
})
|
|
2842
|
+
)[0][0], block = slate.Editor.node(editor, slate.Path.parent(op.path))[0];
|
|
2843
|
+
if (node && isPortableTextSpan(node) && block && isPortableTextBlock(block)) {
|
|
2844
|
+
const markDefs = block.markDefs ?? [], nodeHasAnnotations = (node.marks ?? []).some(
|
|
2845
|
+
(mark) => markDefs.find((markDef) => markDef._key === mark)
|
|
2846
|
+
), deletingPartOfTheNode = op.offset !== 0, deletingFromTheEnd = op.offset + op.text.length === node.text.length;
|
|
2847
|
+
if (nodeHasAnnotations && deletingPartOfTheNode && deletingFromTheEnd) {
|
|
2848
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
2849
|
+
withoutPreserveKeys(editor, () => {
|
|
2850
|
+
slate.Transforms.splitNodes(editor, {
|
|
2851
|
+
match: slate.Text.isText,
|
|
2852
|
+
at: { path: op.path, offset: op.offset }
|
|
2853
|
+
});
|
|
2854
|
+
}), slate.Transforms.removeNodes(editor, { at: slate.Path.next(op.path) });
|
|
2855
|
+
}), editor.onChange();
|
|
2828
2856
|
return;
|
|
2829
2857
|
}
|
|
2830
2858
|
}
|
|
@@ -2837,10 +2865,7 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2837
2865
|
const splitTextNodes = [
|
|
2838
2866
|
...slate.Editor.nodes(editor, { at: editor.selection, match: slate.Text.isText })
|
|
2839
2867
|
];
|
|
2840
|
-
if (splitTextNodes.every((node) =>
|
|
2841
|
-
var _a;
|
|
2842
|
-
return (_a = node[0].marks) == null ? void 0 : _a.includes(mark);
|
|
2843
|
-
}))
|
|
2868
|
+
if (splitTextNodes.every((node) => node[0].marks?.includes(mark)))
|
|
2844
2869
|
return editor.removeMark(mark), editor;
|
|
2845
2870
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2846
2871
|
splitTextNodes.forEach(([node, path]) => {
|
|
@@ -2909,9 +2934,8 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2909
2934
|
slate.Editor.nodes(editor, { match: slate.Text.isText, at: editor.selection })
|
|
2910
2935
|
);
|
|
2911
2936
|
return slate.Range.isExpanded(editor.selection) ? selectedNodes.every((n) => {
|
|
2912
|
-
var _a;
|
|
2913
2937
|
const [node] = n;
|
|
2914
|
-
return
|
|
2938
|
+
return node.marks?.includes(mark);
|
|
2915
2939
|
}) : ({
|
|
2916
2940
|
...slate.Editor.marks(editor) || {}
|
|
2917
2941
|
}.marks || []).includes(mark);
|
|
@@ -2921,18 +2945,22 @@ function createWithPortableTextMarkModel(types2, change$) {
|
|
|
2921
2945
|
};
|
|
2922
2946
|
function mergeSpans(editor) {
|
|
2923
2947
|
const { selection } = editor;
|
|
2924
|
-
if (selection)
|
|
2925
|
-
|
|
2948
|
+
if (selection) {
|
|
2949
|
+
const textNodesInSelection = Array.from(
|
|
2926
2950
|
slate.Editor.nodes(editor, {
|
|
2927
|
-
at: slate.Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]])
|
|
2951
|
+
at: slate.Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]]),
|
|
2952
|
+
match: slate.Text.isText,
|
|
2953
|
+
reverse: !0
|
|
2928
2954
|
})
|
|
2929
|
-
)
|
|
2955
|
+
);
|
|
2956
|
+
for (const [node, path] of textNodesInSelection) {
|
|
2930
2957
|
const [parent] = path.length > 1 ? slate.Editor.node(editor, slate.Path.parent(path)) : [void 0], nextPath = [path[0], path[1] + 1];
|
|
2931
2958
|
if (editor.isTextBlock(parent)) {
|
|
2932
2959
|
const nextNode = parent.children[nextPath[1]];
|
|
2933
|
-
slate.Text.isText(
|
|
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());
|
|
2934
2961
|
}
|
|
2935
2962
|
}
|
|
2963
|
+
}
|
|
2936
2964
|
}
|
|
2937
2965
|
}
|
|
2938
2966
|
const debug$b = debugWithName("plugin:withPortableTextSelections"), debugVerbose$2 = debug$b.enabled && !1;
|
|
@@ -3044,7 +3072,6 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3044
3072
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions || DEFAULT_HOTKEYS;
|
|
3045
3073
|
return function(editor) {
|
|
3046
3074
|
return editor.pteWithHotKeys = (event) => {
|
|
3047
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3048
3075
|
Object.keys(activeHotkeys).forEach((cat) => {
|
|
3049
3076
|
if (cat === "marks")
|
|
3050
3077
|
for (const hotkey in activeHotkeys[cat]) {
|
|
@@ -3091,7 +3118,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3091
3118
|
}
|
|
3092
3119
|
}
|
|
3093
3120
|
if (isBackspace && editor.selection && editor.selection.focus.path[0] === 0 && slate.Range.isCollapsed(editor.selection)) {
|
|
3094
|
-
const focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1)), nextPath = slate.Path.next(editor.selection.focus.path.slice(0, 1)), nextBlock = slate.Node.has(editor, nextPath), isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 &&
|
|
3121
|
+
const focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1)), nextPath = slate.Path.next(editor.selection.focus.path.slice(0, 1)), nextBlock = slate.Node.has(editor, nextPath), isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && focusBlock.children?.[0]?.text === "";
|
|
3095
3122
|
if (nextBlock && isTextBlock && isEmptyFocusBlock) {
|
|
3096
3123
|
event.preventDefault(), event.stopPropagation(), slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), editor.onChange();
|
|
3097
3124
|
return;
|
|
@@ -3101,7 +3128,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3101
3128
|
const prevPath = slate.Path.previous(editor.selection.focus.path.slice(0, 1)), prevBlock = slate.Node.descendant(editor, prevPath), focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
3102
3129
|
if (prevBlock && focusBlock && slate.Editor.isVoid(editor, prevBlock) && editor.selection.focus.offset === 0) {
|
|
3103
3130
|
debug$8("Preventing deleting void block above"), event.preventDefault(), event.stopPropagation();
|
|
3104
|
-
const isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 &&
|
|
3131
|
+
const isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && focusBlock.children?.[0]?.text === "";
|
|
3105
3132
|
if (!isTextBlock || isEmptyFocusBlock) {
|
|
3106
3133
|
slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, prevPath), editor.onChange();
|
|
3107
3134
|
return;
|
|
@@ -3117,7 +3144,7 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3117
3144
|
const nextBlock = slate.Node.descendant(
|
|
3118
3145
|
editor,
|
|
3119
3146
|
slate.Path.next(editor.selection.focus.path.slice(0, 1))
|
|
3120
|
-
), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath), isEmptyFocusBlock = types.isPortableTextTextBlock(focusBlock) && focusBlock.children.length === 1 &&
|
|
3147
|
+
), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath), isEmptyFocusBlock = types.isPortableTextTextBlock(focusBlock) && focusBlock.children.length === 1 && focusBlock.children?.[0]?.text === "";
|
|
3121
3148
|
if (nextBlock && focusBlock && !slate.Editor.isVoid(editor, focusBlock) && slate.Editor.isVoid(editor, nextBlock) && isEmptyFocusBlock) {
|
|
3122
3149
|
debug$8("Preventing deleting void block below"), event.preventDefault(), event.stopPropagation(), slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, focusBlockPath), editor.onChange();
|
|
3123
3150
|
return;
|
|
@@ -3422,13 +3449,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3422
3449
|
const debug$7 = debugWithName("plugin:withInsertData");
|
|
3423
3450
|
function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
3424
3451
|
return function(editor) {
|
|
3425
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
3426
|
-
var _a;
|
|
3427
|
-
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
3428
|
-
var _a2;
|
|
3429
|
-
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
3430
|
-
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
3431
|
-
}).join(`
|
|
3452
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
|
|
3432
3453
|
|
|
3433
3454
|
`);
|
|
3434
3455
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -3460,7 +3481,6 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3460
3481
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
3461
3482
|
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$7("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$7("Set fragment data", asJSON, asHTML);
|
|
3462
3483
|
}, editor.insertPortableTextData = (data) => {
|
|
3463
|
-
var _a, _b;
|
|
3464
3484
|
if (!editor.selection)
|
|
3465
3485
|
return !1;
|
|
3466
3486
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -3474,8 +3494,8 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3474
3494
|
spanTypeName,
|
|
3475
3495
|
schemaTypes
|
|
3476
3496
|
), validation = validateValue(parsed, schemaTypes, keyGenerator);
|
|
3477
|
-
if (!validation.valid && !
|
|
3478
|
-
const errorDescription = `${
|
|
3497
|
+
if (!validation.valid && !validation.resolution?.autoResolve) {
|
|
3498
|
+
const errorDescription = `${validation.resolution?.description}`;
|
|
3479
3499
|
return change$.next({
|
|
3480
3500
|
type: "error",
|
|
3481
3501
|
level: "warning",
|
|
@@ -3489,7 +3509,6 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3489
3509
|
}
|
|
3490
3510
|
return !1;
|
|
3491
3511
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
3492
|
-
var _a;
|
|
3493
3512
|
if (!editor.selection)
|
|
3494
3513
|
return debug$7("No selection, not inserting"), !1;
|
|
3495
3514
|
change$.next({ type: "loading", isLoading: !0 });
|
|
@@ -3515,7 +3534,7 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3515
3534
|
const validation = validateValue(portableText, schemaTypes, keyGenerator);
|
|
3516
3535
|
if (!validation.valid) {
|
|
3517
3536
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
3518
|
-
${
|
|
3537
|
+
${validation.resolution?.description}
|
|
3519
3538
|
Try to insert as plain text (shift-paste) instead.`;
|
|
3520
3539
|
return change$.next({
|
|
3521
3540
|
type: "error",
|
|
@@ -3622,7 +3641,11 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3622
3641
|
readOnly,
|
|
3623
3642
|
patches$,
|
|
3624
3643
|
blockSchemaType: schemaTypes.block
|
|
3625
|
-
}), withPortableTextMarkModel = createWithPortableTextMarkModel(
|
|
3644
|
+
}), withPortableTextMarkModel = createWithPortableTextMarkModel(
|
|
3645
|
+
schemaTypes,
|
|
3646
|
+
change$,
|
|
3647
|
+
keyGenerator
|
|
3648
|
+
), withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withInsertBreak = createWithInsertBreak(schemaTypes), withUtils = createWithUtils({ keyGenerator, schemaTypes, portableTextEditor }), withPortableTextSelections = createWithPortableTextSelections(change$, schemaTypes);
|
|
3626
3649
|
return e.destroy = () => {
|
|
3627
3650
|
const originalFunctions = originalFnMap.get(e);
|
|
3628
3651
|
if (!originalFunctions)
|
|
@@ -3780,15 +3803,14 @@ function useSyncValue(props) {
|
|
|
3780
3803
|
isChanged = !0;
|
|
3781
3804
|
}
|
|
3782
3805
|
slateValueFromProps.forEach((currentBlock, currentBlockIndex) => {
|
|
3783
|
-
var _a, _b, _c, _d, _e;
|
|
3784
3806
|
const oldBlock = slateEditor.children[currentBlockIndex];
|
|
3785
3807
|
if (oldBlock && !isEqual__default.default(currentBlock, oldBlock) && isValid) {
|
|
3786
3808
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, keyGenerator);
|
|
3787
|
-
!validation.valid &&
|
|
3788
|
-
`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${
|
|
3809
|
+
!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(
|
|
3810
|
+
`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`
|
|
3789
3811
|
), validation.resolution.patches.forEach((patch) => {
|
|
3790
3812
|
change$.next({ type: "patch", patch });
|
|
3791
|
-
})), validation.valid ||
|
|
3813
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$5.enabled && debug$5("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$5.enabled && debug$5("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (change$.next({
|
|
3792
3814
|
type: "invalidValue",
|
|
3793
3815
|
resolution: validation.resolution,
|
|
3794
3816
|
value
|
|
@@ -3799,7 +3821,7 @@ function useSyncValue(props) {
|
|
|
3799
3821
|
debug$5.enabled && debug$5(
|
|
3800
3822
|
"Validating and inserting new block in the end of the value",
|
|
3801
3823
|
currentBlock
|
|
3802
|
-
), validation.valid ||
|
|
3824
|
+
), validation.valid || validation.resolution?.autoResolve ? withPreserveKeys(slateEditor, () => {
|
|
3803
3825
|
slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3804
3826
|
at: [currentBlockIndex]
|
|
3805
3827
|
});
|
|
@@ -3869,9 +3891,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3869
3891
|
}));
|
|
3870
3892
|
}
|
|
3871
3893
|
), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3872
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild
|
|
3894
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3873
3895
|
if (isChildChanged)
|
|
3874
|
-
if (currentBlockChild._key ===
|
|
3896
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
3875
3897
|
debug$5("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3876
3898
|
at: path
|
|
3877
3899
|
});
|
|
@@ -3987,16 +4009,22 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
3987
4009
|
};
|
|
3988
4010
|
}, [change$]), /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children });
|
|
3989
4011
|
}
|
|
3990
|
-
var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3991
4012
|
const debug$2 = debugWithName("component:PortableTextEditor");
|
|
3992
4013
|
class PortableTextEditor extends react.Component {
|
|
4014
|
+
/**
|
|
4015
|
+
* An observable of all the editor changes.
|
|
4016
|
+
*/
|
|
4017
|
+
change$ = new rxjs.Subject();
|
|
4018
|
+
/**
|
|
4019
|
+
* A lookup table for all the relevant schema types for this portable text type.
|
|
4020
|
+
*/
|
|
4021
|
+
schemaTypes;
|
|
4022
|
+
/**
|
|
4023
|
+
* The editor API (currently implemented with Slate).
|
|
4024
|
+
*/
|
|
4025
|
+
editable;
|
|
3993
4026
|
constructor(props) {
|
|
3994
|
-
if (super(props),
|
|
3995
|
-
this.editable = { ...this.editable, ...editable };
|
|
3996
|
-
}), __publicField(this, "getValue", () => {
|
|
3997
|
-
if (this.editable)
|
|
3998
|
-
return this.editable.getValue();
|
|
3999
|
-
}), !props.schemaType)
|
|
4027
|
+
if (super(props), !props.schemaType)
|
|
4000
4028
|
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
4001
4029
|
props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.change$.next({ type: "loading", isLoading: !0 }), this.schemaTypes = getPortableTextMemberSchemaTypes(
|
|
4002
4030
|
props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)
|
|
@@ -4007,6 +4035,13 @@ class PortableTextEditor extends react.Component {
|
|
|
4007
4035
|
this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)
|
|
4008
4036
|
)), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
|
|
4009
4037
|
}
|
|
4038
|
+
setEditable = (editable) => {
|
|
4039
|
+
this.editable = { ...this.editable, ...editable };
|
|
4040
|
+
};
|
|
4041
|
+
getValue = () => {
|
|
4042
|
+
if (this.editable)
|
|
4043
|
+
return this.editable.getValue();
|
|
4044
|
+
};
|
|
4010
4045
|
render() {
|
|
4011
4046
|
const { onChange, value, children, patches$, incomingPatches$ } = this.props, { change$ } = this, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, keyGenerator = this.props.keyGenerator || defaultKeyGenerator;
|
|
4012
4047
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4032,99 +4067,59 @@ class PortableTextEditor extends react.Component {
|
|
|
4032
4067
|
}
|
|
4033
4068
|
);
|
|
4034
4069
|
}
|
|
4070
|
+
// Static API methods
|
|
4071
|
+
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
4072
|
+
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
4073
|
+
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
4074
|
+
static blur = (editor) => {
|
|
4075
|
+
debug$2("Host blurred"), editor.editable?.blur();
|
|
4076
|
+
};
|
|
4077
|
+
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
4078
|
+
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
4079
|
+
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
4080
|
+
static focus = (editor) => {
|
|
4081
|
+
debug$2("Host requesting focus"), editor.editable?.focus();
|
|
4082
|
+
};
|
|
4083
|
+
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
4084
|
+
static focusChild = (editor) => editor.editable?.focusChild();
|
|
4085
|
+
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
4086
|
+
static getValue = (editor) => editor.editable?.getValue();
|
|
4087
|
+
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
4088
|
+
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
4089
|
+
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
4090
|
+
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
4091
|
+
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
4092
|
+
static insertChild = (editor, type, value) => (debug$2("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
4093
|
+
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
4094
|
+
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
4095
|
+
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
4096
|
+
static isObjectPath = (editor, path) => {
|
|
4097
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
4098
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
4099
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
4100
|
+
};
|
|
4101
|
+
static marks = (editor) => editor.editable?.marks();
|
|
4102
|
+
static select = (editor, selection) => {
|
|
4103
|
+
debug$2("Host setting selection", selection), editor.editable?.select(selection);
|
|
4104
|
+
};
|
|
4105
|
+
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
4106
|
+
static toggleBlockStyle = (editor, blockStyle) => (debug$2("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
4107
|
+
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
4108
|
+
static toggleMark = (editor, mark) => {
|
|
4109
|
+
debug$2("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
4110
|
+
};
|
|
4111
|
+
static getFragment = (editor) => (debug$2("Host getting fragment"), editor.editable?.getFragment());
|
|
4112
|
+
static undo = (editor) => {
|
|
4113
|
+
debug$2("Host undoing"), editor.editable?.undo();
|
|
4114
|
+
};
|
|
4115
|
+
static redo = (editor) => {
|
|
4116
|
+
debug$2("Host redoing"), editor.editable?.redo();
|
|
4117
|
+
};
|
|
4118
|
+
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
4035
4119
|
}
|
|
4036
|
-
__publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
|
|
4037
|
-
var _a;
|
|
4038
|
-
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
4039
|
-
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
4040
|
-
var _a;
|
|
4041
|
-
debug$2("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
4042
|
-
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
4043
|
-
var _a;
|
|
4044
|
-
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
4045
|
-
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
4046
|
-
var _a;
|
|
4047
|
-
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
4048
|
-
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
4049
|
-
var _a;
|
|
4050
|
-
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
4051
|
-
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
4052
|
-
var _a;
|
|
4053
|
-
debug$2("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
4054
|
-
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
4055
|
-
var _a;
|
|
4056
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
4057
|
-
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
4058
|
-
var _a;
|
|
4059
|
-
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
4060
|
-
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
4061
|
-
var _a;
|
|
4062
|
-
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
4063
|
-
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
4064
|
-
var _a;
|
|
4065
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
4066
|
-
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
4067
|
-
var _a;
|
|
4068
|
-
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
4069
|
-
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
4070
|
-
var _a;
|
|
4071
|
-
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
4072
|
-
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
4073
|
-
var _a;
|
|
4074
|
-
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
4075
|
-
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
4076
|
-
var _a;
|
|
4077
|
-
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
4078
|
-
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
4079
|
-
var _a;
|
|
4080
|
-
return debug$2("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
4081
|
-
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
4082
|
-
var _a;
|
|
4083
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
4084
|
-
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
4085
|
-
var _a;
|
|
4086
|
-
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
4087
|
-
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
4088
|
-
var _a;
|
|
4089
|
-
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
4090
|
-
}), __publicField(PortableTextEditor, "isObjectPath", (editor, path) => {
|
|
4091
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
4092
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
4093
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
4094
|
-
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
4095
|
-
var _a;
|
|
4096
|
-
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
4097
|
-
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
4098
|
-
var _a;
|
|
4099
|
-
debug$2("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
4100
|
-
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
4101
|
-
var _a;
|
|
4102
|
-
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
4103
|
-
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
4104
|
-
var _a;
|
|
4105
|
-
return debug$2("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
4106
|
-
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
4107
|
-
var _a;
|
|
4108
|
-
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
4109
|
-
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
4110
|
-
var _a;
|
|
4111
|
-
debug$2("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
4112
|
-
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
4113
|
-
var _a;
|
|
4114
|
-
return debug$2("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
4115
|
-
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
4116
|
-
var _a;
|
|
4117
|
-
debug$2("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
4118
|
-
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
4119
|
-
var _a;
|
|
4120
|
-
debug$2("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
4121
|
-
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
4122
|
-
var _a;
|
|
4123
|
-
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
4124
|
-
});
|
|
4125
4120
|
const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
4126
4121
|
const { attributes, children, leaf, schemaTypes, renderChild, renderDecorator, renderAnnotation } = props, spanRef = react.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = react.useState(!1), [selected, setSelected] = react.useState(!1), block = children.props.parent, path = react.useMemo(
|
|
4127
|
-
() => block ? [{ _key: block
|
|
4122
|
+
() => block ? [{ _key: block?._key }, "children", { _key: leaf._key }] : [],
|
|
4128
4123
|
[block, leaf._key]
|
|
4129
4124
|
), decoratorValues = react.useMemo(
|
|
4130
4125
|
() => schemaTypes.decorators.map((dec) => dec.value),
|
|
@@ -4134,10 +4129,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4134
4129
|
[decoratorValues, leaf.marks]
|
|
4135
4130
|
), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = react.useMemo(
|
|
4136
4131
|
() => annotationMarks.map(
|
|
4137
|
-
(mark) =>
|
|
4138
|
-
var _a;
|
|
4139
|
-
return !decoratorValues.includes(mark) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark));
|
|
4140
|
-
}
|
|
4132
|
+
(mark) => !decoratorValues.includes(mark) && block?.markDefs?.find((def) => def._key === mark)
|
|
4141
4133
|
).filter(Boolean),
|
|
4142
4134
|
[annotationMarks, block, decoratorValues]
|
|
4143
4135
|
), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
@@ -4448,7 +4440,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4448
4440
|
debug("Pasting normally"), slateEditor.insertData(event.clipboardData);
|
|
4449
4441
|
return;
|
|
4450
4442
|
}
|
|
4451
|
-
const value = PortableTextEditor.getValue(portableTextEditor),
|
|
4443
|
+
const value = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste({ event, value, path, schemaTypes });
|
|
4452
4444
|
onPasteResult === void 0 ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event.clipboardData)) : (change$.next({ type: "loading", isLoading: !0 }), Promise.resolve(onPasteResult).then((result) => {
|
|
4453
4445
|
debug("Custom paste function from client resolved", result), !result || !result.insert ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event.clipboardData)) : result.insert ? slateEditor.insertFragment(
|
|
4454
4446
|
toSlateValue(result.insert, { schemaTypes })
|
|
@@ -4504,7 +4496,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4504
4496
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
4505
4497
|
try {
|
|
4506
4498
|
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
4507
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
4499
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
4508
4500
|
} catch {
|
|
4509
4501
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
4510
4502
|
}
|