@portabletext/editor 1.0.18 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +140 -66
- package/lib/index.d.ts +140 -66
- package/lib/index.esm.js +1164 -410
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1164 -410
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1164 -410
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -4
- package/src/editor/Editable.tsx +107 -36
- package/src/editor/PortableTextEditor.tsx +47 -12
- package/src/editor/__tests__/PortableTextEditor.test.tsx +42 -15
- package/src/editor/__tests__/PortableTextEditorTester.tsx +50 -38
- package/src/editor/__tests__/RangeDecorations.test.tsx +0 -1
- package/src/editor/__tests__/handleClick.test.tsx +28 -9
- package/src/editor/__tests__/insert-block.test.tsx +22 -6
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +30 -62
- package/src/editor/__tests__/utils.ts +10 -3
- package/src/editor/components/DraggableBlock.tsx +36 -13
- package/src/editor/components/Element.tsx +59 -17
- package/src/editor/components/Leaf.tsx +106 -68
- package/src/editor/components/SlateContainer.tsx +12 -5
- package/src/editor/components/Synchronizer.tsx +5 -2
- package/src/editor/hooks/usePortableTextEditor.ts +2 -2
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +9 -3
- package/src/editor/hooks/useSyncValue.test.tsx +9 -4
- package/src/editor/hooks/useSyncValue.ts +199 -130
- package/src/editor/nodes/DefaultAnnotation.tsx +6 -3
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +25 -7
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +26 -9
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +15 -5
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +60 -19
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +61 -550
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +6 -3
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +30 -13
- package/src/editor/plugins/createWithEditableAPI.ts +354 -115
- package/src/editor/plugins/createWithHotKeys.ts +41 -121
- package/src/editor/plugins/createWithInsertBreak.ts +166 -27
- package/src/editor/plugins/createWithInsertData.ts +60 -23
- package/src/editor/plugins/createWithMaxBlocks.ts +5 -2
- package/src/editor/plugins/createWithObjectKeys.ts +7 -3
- package/src/editor/plugins/createWithPatches.ts +60 -16
- package/src/editor/plugins/createWithPlaceholderBlock.ts +7 -3
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +17 -7
- package/src/editor/plugins/createWithPortableTextLists.ts +21 -8
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +301 -155
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +25 -9
- package/src/editor/plugins/createWithUndoRedo.ts +107 -24
- package/src/editor/plugins/createWithUtils.ts +32 -10
- package/src/editor/plugins/index.ts +31 -10
- package/src/types/editor.ts +44 -15
- package/src/types/options.ts +4 -2
- package/src/types/slate.ts +2 -2
- package/src/utils/__tests__/dmpToOperations.test.ts +38 -13
- package/src/utils/__tests__/operationToPatches.test.ts +3 -2
- package/src/utils/__tests__/patchToOperations.test.ts +15 -4
- package/src/utils/__tests__/ranges.test.ts +8 -3
- package/src/utils/__tests__/valueNormalization.test.tsx +12 -4
- package/src/utils/__tests__/values.test.ts +0 -1
- package/src/utils/applyPatch.ts +71 -20
- package/src/utils/getPortableTextMemberSchemaTypes.ts +30 -15
- package/src/utils/operationToPatches.ts +126 -43
- package/src/utils/paths.ts +24 -7
- package/src/utils/ranges.ts +12 -5
- package/src/utils/selection.ts +19 -7
- package/src/utils/validateValue.ts +118 -45
- package/src/utils/values.ts +31 -10
- package/src/utils/weakMaps.ts +18 -8
- package/src/utils/withChanges.ts +4 -2
- package/src/editor/plugins/__tests__/withHotkeys.test.tsx +0 -212
- package/src/editor/plugins/__tests__/withInsertBreak.test.tsx +0 -220
- package/src/editor/plugins/__tests__/withPlaceholderBlock.test.tsx +0 -133
package/lib/index.js
CHANGED
|
@@ -38,7 +38,9 @@ function createArrayedPath(point, editor) {
|
|
|
38
38
|
return [];
|
|
39
39
|
if (editor.isVoid(block))
|
|
40
40
|
return [blockPath[0], 0];
|
|
41
|
-
const childPath = [point.path[2]], childIndex = block.children.findIndex(
|
|
41
|
+
const childPath = [point.path[2]], childIndex = block.children.findIndex(
|
|
42
|
+
(child) => isEqual__default.default([{ _key: child._key }], childPath)
|
|
43
|
+
);
|
|
42
44
|
if (childIndex >= 0 && block.children[childIndex]) {
|
|
43
45
|
const child = block.children[childIndex];
|
|
44
46
|
return slate.Element.isElement(child) && editor.isVoid(child) ? blockPath.concat(childIndex).concat(0) : blockPath.concat(childIndex);
|
|
@@ -83,7 +85,9 @@ function normalizePoint(point, value) {
|
|
|
83
85
|
return null;
|
|
84
86
|
const newPath = [];
|
|
85
87
|
let newOffset = point.offset || 0;
|
|
86
|
-
const blockKey = typeof point.path[0] == "object" && "_key" in point.path[0] && point.path[0]._key, childKey = typeof point.path[2] == "object" && "_key" in point.path[2] && point.path[2]._key, block = value.find(
|
|
88
|
+
const blockKey = typeof point.path[0] == "object" && "_key" in point.path[0] && point.path[0]._key, childKey = typeof point.path[2] == "object" && "_key" in point.path[2] && point.path[2]._key, block = value.find(
|
|
89
|
+
(blk) => blk._key === blockKey
|
|
90
|
+
);
|
|
87
91
|
if (block)
|
|
88
92
|
newPath.push({ _key: block._key });
|
|
89
93
|
else
|
|
@@ -106,14 +110,16 @@ function normalizeSelection(selection, value) {
|
|
|
106
110
|
const { anchor, focus } = selection;
|
|
107
111
|
return anchor && value.find((blk) => isEqual__default.default({ _key: blk._key }, anchor.path[0])) && (newAnchor = normalizePoint(anchor, value)), focus && value.find((blk) => isEqual__default.default({ _key: blk._key }, focus.path[0])) && (newFocus = normalizePoint(focus, value)), newAnchor && newFocus ? { anchor: newAnchor, focus: newFocus, backward: selection.backward } : null;
|
|
108
112
|
}
|
|
109
|
-
const EMPTY_MARKDEFS = [],
|
|
113
|
+
const EMPTY_MARKDEFS = [], VOID_CHILD_KEY = "void-child";
|
|
110
114
|
function keepObjectEquality(object, keyMap) {
|
|
111
115
|
const value = keyMap[object._key];
|
|
112
116
|
return value && isEqual__default.default(object, value) ? value : (keyMap[object._key] = object, object);
|
|
113
117
|
}
|
|
114
118
|
function toSlateValue(value, { schemaTypes }, keyMap = {}) {
|
|
115
119
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
116
|
-
const { _type, _key, ...rest } = block, voidChildren = [
|
|
120
|
+
const { _type, _key, ...rest } = block, voidChildren = [
|
|
121
|
+
{ _key: VOID_CHILD_KEY, _type: "span", text: "", marks: [] }
|
|
122
|
+
];
|
|
117
123
|
if (block && block._type === schemaTypes.block.name) {
|
|
118
124
|
const textBlock = block;
|
|
119
125
|
let hasInlines = !1;
|
|
@@ -154,12 +160,25 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
154
160
|
const { _type: _cType } = child;
|
|
155
161
|
if ("value" in child && _cType !== "span") {
|
|
156
162
|
hasInlines = !0;
|
|
157
|
-
const {
|
|
158
|
-
|
|
163
|
+
const {
|
|
164
|
+
value: v,
|
|
165
|
+
_key: k,
|
|
166
|
+
_type: t,
|
|
167
|
+
__inline: _i,
|
|
168
|
+
children: _c,
|
|
169
|
+
...rest
|
|
170
|
+
} = child;
|
|
171
|
+
return keepObjectEquality(
|
|
172
|
+
{ ...rest, ...v, _key: k, _type: t },
|
|
173
|
+
keyMap
|
|
174
|
+
);
|
|
159
175
|
}
|
|
160
176
|
return child;
|
|
161
177
|
});
|
|
162
|
-
return hasInlines ? keepObjectEquality(
|
|
178
|
+
return hasInlines ? keepObjectEquality(
|
|
179
|
+
{ ...block, children, _key, _type },
|
|
180
|
+
keyMap
|
|
181
|
+
) : block;
|
|
163
182
|
}
|
|
164
183
|
const blockValue = "value" in block && block.value;
|
|
165
184
|
return keepObjectEquality(
|
|
@@ -331,10 +350,23 @@ function getCounterContentForListLevel(level) {
|
|
|
331
350
|
return "counter(listItemNumberNextNextNext) '. '";
|
|
332
351
|
}
|
|
333
352
|
}
|
|
334
|
-
const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
335
|
-
|
|
353
|
+
const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
354
|
+
children,
|
|
355
|
+
element,
|
|
356
|
+
readOnly,
|
|
357
|
+
blockRef
|
|
358
|
+
}) => {
|
|
359
|
+
const editor = slateReact.useSlateStatic(), dragGhostRef = react.useRef(), [isDragOver, setIsDragOver] = react.useState(!1), isVoid = react.useMemo(
|
|
360
|
+
() => slate.Editor.isVoid(editor, element),
|
|
361
|
+
[editor, element]
|
|
362
|
+
), isInline = react.useMemo(
|
|
363
|
+
() => slate.Editor.isInline(editor, element),
|
|
364
|
+
[editor, element]
|
|
365
|
+
), [blockElement, setBlockElement] = react.useState(null);
|
|
336
366
|
react.useEffect(
|
|
337
|
-
() => setBlockElement(
|
|
367
|
+
() => setBlockElement(
|
|
368
|
+
blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)
|
|
369
|
+
),
|
|
338
370
|
[editor, element, blockRef]
|
|
339
371
|
);
|
|
340
372
|
const handleDragOver = react.useCallback(
|
|
@@ -421,7 +453,9 @@ const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = ({
|
|
|
421
453
|
}
|
|
422
454
|
if (debug$l("Drag start"), IS_DRAGGING.set(editor, !0), event.dataTransfer && (event.dataTransfer.setData("application/portable-text", "something"), event.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
|
|
423
455
|
let dragGhost = blockElement.cloneNode(!0);
|
|
424
|
-
const customGhost = dragGhost.querySelector(
|
|
456
|
+
const customGhost = dragGhost.querySelector(
|
|
457
|
+
"[data-pt-drag-ghost-element]"
|
|
458
|
+
);
|
|
425
459
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
426
460
|
dragGhostRef.current = dragGhost, dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
427
461
|
const rect = blockElement.getBoundingClientRect(), x = event.clientX - rect.left, y = event.clientY - rect.top;
|
|
@@ -479,7 +513,11 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
479
513
|
spellCheck
|
|
480
514
|
}) => {
|
|
481
515
|
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = react.useRef(null), inlineBlockObjectRef = react.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = react.useMemo(
|
|
482
|
-
() => fromSlateValue(
|
|
516
|
+
() => fromSlateValue(
|
|
517
|
+
[element],
|
|
518
|
+
schemaTypes.block.name,
|
|
519
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
520
|
+
)[0],
|
|
483
521
|
[editor, element, schemaTypes.block.name]
|
|
484
522
|
);
|
|
485
523
|
let renderedBlock = children, className;
|
|
@@ -489,11 +527,17 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
489
527
|
if (typeof element._key != "string")
|
|
490
528
|
throw new Error("Expected element to have a _key property");
|
|
491
529
|
if (editor.isInline(element)) {
|
|
492
|
-
const path = slateReact.ReactEditor.findPath(editor, element), [block2] = slate.Editor.node(editor, path, { depth: 1 }), schemaType2 = schemaTypes.inlineObjects.find(
|
|
530
|
+
const path = slateReact.ReactEditor.findPath(editor, element), [block2] = slate.Editor.node(editor, path, { depth: 1 }), schemaType2 = schemaTypes.inlineObjects.find(
|
|
531
|
+
(_type) => _type.name === element._type
|
|
532
|
+
);
|
|
493
533
|
if (!schemaType2)
|
|
494
534
|
throw new Error("Could not find type for inline block element");
|
|
495
535
|
if (slate.Element.isElement(block2)) {
|
|
496
|
-
const elmPath = [
|
|
536
|
+
const elmPath = [
|
|
537
|
+
{ _key: block2._key },
|
|
538
|
+
"children",
|
|
539
|
+
{ _key: element._key }
|
|
540
|
+
];
|
|
497
541
|
return /* @__PURE__ */ jsxRuntime.jsxs("span", { ...attributes, children: [
|
|
498
542
|
children,
|
|
499
543
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -531,7 +575,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
531
575
|
className = "pt-block pt-text-block";
|
|
532
576
|
const isListItem = "listItem" in element, style = "style" in element && element.style || "normal";
|
|
533
577
|
className = `pt-block pt-text-block pt-text-block-style-${style}`;
|
|
534
|
-
const blockStyleType = schemaTypes.styles.find(
|
|
578
|
+
const blockStyleType = schemaTypes.styles.find(
|
|
579
|
+
(item) => item.value === style
|
|
580
|
+
);
|
|
535
581
|
renderStyle && blockStyleType && (renderedBlock = renderStyle({
|
|
536
582
|
block: element,
|
|
537
583
|
children,
|
|
@@ -544,7 +590,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
544
590
|
}));
|
|
545
591
|
let level;
|
|
546
592
|
if (isListItem && (typeof element.level == "number" && (level = element.level), className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`), editor.isListBlock(value) && isListItem && element.listItem) {
|
|
547
|
-
const listType = schemaTypes.lists.find(
|
|
593
|
+
const listType = schemaTypes.lists.find(
|
|
594
|
+
(item) => item.value === element.listItem
|
|
595
|
+
);
|
|
548
596
|
renderListItem && listType ? renderedBlock = renderListItem({
|
|
549
597
|
block: value,
|
|
550
598
|
children: renderedBlock,
|
|
@@ -581,15 +629,38 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
581
629
|
{
|
|
582
630
|
enumerable: !1,
|
|
583
631
|
get() {
|
|
584
|
-
return console.warn(
|
|
632
|
+
return console.warn(
|
|
633
|
+
"Property 'type' is deprecated, use 'schemaType' instead."
|
|
634
|
+
), schemaTypes.block;
|
|
585
635
|
}
|
|
586
636
|
}
|
|
587
637
|
), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
588
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
638
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
639
|
+
"div",
|
|
640
|
+
{
|
|
641
|
+
...attributes,
|
|
642
|
+
className,
|
|
643
|
+
spellCheck,
|
|
644
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
645
|
+
DraggableBlock,
|
|
646
|
+
{
|
|
647
|
+
element,
|
|
648
|
+
readOnly,
|
|
649
|
+
blockRef,
|
|
650
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered })
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
},
|
|
654
|
+
element._key
|
|
655
|
+
);
|
|
589
656
|
}
|
|
590
|
-
const schemaType = schemaTypes.blockObjects.find(
|
|
657
|
+
const schemaType = schemaTypes.blockObjects.find(
|
|
658
|
+
(_type) => _type.name === element._type
|
|
659
|
+
);
|
|
591
660
|
if (!schemaType)
|
|
592
|
-
throw new Error(
|
|
661
|
+
throw new Error(
|
|
662
|
+
`Could not find schema type for block element of _type ${element._type}`
|
|
663
|
+
);
|
|
593
664
|
className = "pt-block pt-object-block";
|
|
594
665
|
const block = fromSlateValue(
|
|
595
666
|
[element],
|
|
@@ -612,7 +683,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
612
683
|
{
|
|
613
684
|
enumerable: !1,
|
|
614
685
|
get() {
|
|
615
|
-
return console.warn(
|
|
686
|
+
return console.warn(
|
|
687
|
+
"Property 'type' is deprecated, use 'schemaType' instead."
|
|
688
|
+
), schemaType;
|
|
616
689
|
}
|
|
617
690
|
}
|
|
618
691
|
);
|
|
@@ -634,7 +707,11 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = { display: "inline-block" }, El
|
|
|
634
707
|
return editor;
|
|
635
708
|
};
|
|
636
709
|
function DefaultAnnotation(props) {
|
|
637
|
-
const handleClick = react.useCallback(
|
|
710
|
+
const handleClick = react.useCallback(
|
|
711
|
+
// eslint-disable-next-line no-alert
|
|
712
|
+
() => alert(JSON.stringify(props.annotation)),
|
|
713
|
+
[props.annotation]
|
|
714
|
+
);
|
|
638
715
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "blue" }, onClick: handleClick, children: props.children });
|
|
639
716
|
}
|
|
640
717
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
@@ -643,16 +720,24 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
643
720
|
const blockType = portableTextType.of?.find(findBlockType);
|
|
644
721
|
if (!blockType)
|
|
645
722
|
throw new Error("Block type is not defined in this schema (required)");
|
|
646
|
-
const childrenField = blockType.fields?.find(
|
|
723
|
+
const childrenField = blockType.fields?.find(
|
|
724
|
+
(field) => field.name === "children"
|
|
725
|
+
);
|
|
647
726
|
if (!childrenField)
|
|
648
727
|
throw new Error("Children field for block type found in schema (required)");
|
|
649
728
|
const ofType = childrenField.type.of;
|
|
650
729
|
if (!ofType)
|
|
651
|
-
throw new Error(
|
|
730
|
+
throw new Error(
|
|
731
|
+
"Valid types for block children not found in schema (required)"
|
|
732
|
+
);
|
|
652
733
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
653
734
|
if (!spanType)
|
|
654
735
|
throw new Error("Span type not found in schema (required)");
|
|
655
|
-
const inlineObjectTypes = ofType.filter(
|
|
736
|
+
const inlineObjectTypes = ofType.filter(
|
|
737
|
+
(memberType) => memberType.name !== "span"
|
|
738
|
+
) || [], blockObjectTypes = portableTextType.of?.filter(
|
|
739
|
+
(field) => field.name !== blockType.name
|
|
740
|
+
) || [];
|
|
656
741
|
return {
|
|
657
742
|
styles: resolveEnabledStyles(blockType),
|
|
658
743
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -666,10 +751,16 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
666
751
|
};
|
|
667
752
|
}
|
|
668
753
|
function resolveEnabledStyles(blockType) {
|
|
669
|
-
const styleField = blockType.fields?.find(
|
|
754
|
+
const styleField = blockType.fields?.find(
|
|
755
|
+
(btField) => btField.name === "style"
|
|
756
|
+
);
|
|
670
757
|
if (!styleField)
|
|
671
|
-
throw new Error(
|
|
672
|
-
|
|
758
|
+
throw new Error(
|
|
759
|
+
"A field with name 'style' is not defined in the block type (required)."
|
|
760
|
+
);
|
|
761
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter(
|
|
762
|
+
(style) => style.value
|
|
763
|
+
);
|
|
673
764
|
if (!textStyles || textStyles.length === 0)
|
|
674
765
|
throw new Error(
|
|
675
766
|
"The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}."
|
|
@@ -680,9 +771,13 @@ function resolveEnabledDecorators(spanType) {
|
|
|
680
771
|
return spanType.decorators;
|
|
681
772
|
}
|
|
682
773
|
function resolveEnabledListItems(blockType) {
|
|
683
|
-
const listField = blockType.fields?.find(
|
|
774
|
+
const listField = blockType.fields?.find(
|
|
775
|
+
(btField) => btField.name === "listItem"
|
|
776
|
+
);
|
|
684
777
|
if (!listField)
|
|
685
|
-
throw new Error(
|
|
778
|
+
throw new Error(
|
|
779
|
+
"A field with name 'listItem' is not defined in the block type (required)."
|
|
780
|
+
);
|
|
686
781
|
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
687
782
|
if (!listItems)
|
|
688
783
|
throw new Error("The list field need at least to be an empty array");
|
|
@@ -708,7 +803,12 @@ function createOperationToPatches(types2) {
|
|
|
708
803
|
const textChild = editor.isTextBlock(block) && editor.isTextSpan(block.children[operation.path[1]]) && block.children[operation.path[1]];
|
|
709
804
|
if (!textChild)
|
|
710
805
|
throw new Error("Could not find child");
|
|
711
|
-
const path = [
|
|
806
|
+
const path = [
|
|
807
|
+
{ _key: block._key },
|
|
808
|
+
"children",
|
|
809
|
+
{ _key: textChild._key },
|
|
810
|
+
"text"
|
|
811
|
+
], prevBlock = beforeValue[operation.path[0]], prevChild = editor.isTextBlock(prevBlock) && prevBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevChild) ? prevChild.text : "", patch = patches.diffMatchPatch(prevText, textChild.text, path);
|
|
712
812
|
return patch.value.length ? [patch] : [];
|
|
713
813
|
}
|
|
714
814
|
function removeTextPatch(editor, operation, beforeValue) {
|
|
@@ -720,7 +820,12 @@ function createOperationToPatches(types2) {
|
|
|
720
820
|
throw new Error("Expected span");
|
|
721
821
|
if (!textChild)
|
|
722
822
|
throw new Error("Could not find child");
|
|
723
|
-
const path = [
|
|
823
|
+
const path = [
|
|
824
|
+
{ _key: block._key },
|
|
825
|
+
"children",
|
|
826
|
+
{ _key: textChild._key },
|
|
827
|
+
"text"
|
|
828
|
+
], beforeBlock = beforeValue[operation.path[0]], prevTextChild = editor.isTextBlock(beforeBlock) && beforeBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevTextChild) && prevTextChild.text, patch = patches.diffMatchPatch(prevText || "", textChild.text, path);
|
|
724
829
|
return patch.value ? [patch] : [];
|
|
725
830
|
}
|
|
726
831
|
function setNodePatch(editor, operation) {
|
|
@@ -732,7 +837,9 @@ function createOperationToPatches(types2) {
|
|
|
732
837
|
{ ...editor.children[operation.path[0]], ...operation.newProperties },
|
|
733
838
|
isUndefined__default.default
|
|
734
839
|
);
|
|
735
|
-
return [
|
|
840
|
+
return [
|
|
841
|
+
patches.set(fromSlateValue([setNode], textBlockName)[0], [{ _key: block._key }])
|
|
842
|
+
];
|
|
736
843
|
} else if (operation.path.length === 2) {
|
|
737
844
|
const block = editor.children[operation.path[0]];
|
|
738
845
|
if (editor.isTextBlock(block)) {
|
|
@@ -743,11 +850,23 @@ function createOperationToPatches(types2) {
|
|
|
743
850
|
if (keys.length === 1 && keyName === "_key") {
|
|
744
851
|
const val = get__default.default(operation.newProperties, keyName);
|
|
745
852
|
patches$1.push(
|
|
746
|
-
patches.set(val, [
|
|
853
|
+
patches.set(val, [
|
|
854
|
+
{ _key: blockKey },
|
|
855
|
+
"children",
|
|
856
|
+
block.children.indexOf(child),
|
|
857
|
+
keyName
|
|
858
|
+
])
|
|
747
859
|
);
|
|
748
860
|
} else {
|
|
749
861
|
const val = get__default.default(operation.newProperties, keyName);
|
|
750
|
-
patches$1.push(
|
|
862
|
+
patches$1.push(
|
|
863
|
+
patches.set(val, [
|
|
864
|
+
{ _key: blockKey },
|
|
865
|
+
"children",
|
|
866
|
+
{ _key: childKey },
|
|
867
|
+
keyName
|
|
868
|
+
])
|
|
869
|
+
);
|
|
751
870
|
}
|
|
752
871
|
}), patches$1;
|
|
753
872
|
}
|
|
@@ -755,21 +874,27 @@ function createOperationToPatches(types2) {
|
|
|
755
874
|
}
|
|
756
875
|
throw new Error("Could not find a valid block");
|
|
757
876
|
} else
|
|
758
|
-
throw new Error(
|
|
877
|
+
throw new Error(
|
|
878
|
+
`Unexpected path encountered: ${JSON.stringify(operation.path)}`
|
|
879
|
+
);
|
|
759
880
|
}
|
|
760
881
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
761
882
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
762
883
|
if (operation.path.length === 1) {
|
|
763
884
|
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
764
885
|
return targetKey ? [
|
|
765
|
-
patches.insert(
|
|
766
|
-
|
|
767
|
-
|
|
886
|
+
patches.insert(
|
|
887
|
+
[fromSlateValue([operation.node], textBlockName)[0]],
|
|
888
|
+
position,
|
|
889
|
+
[{ _key: targetKey }]
|
|
890
|
+
)
|
|
768
891
|
] : [
|
|
769
892
|
patches.setIfMissing(beforeValue, []),
|
|
770
|
-
patches.insert(
|
|
771
|
-
operation.
|
|
772
|
-
|
|
893
|
+
patches.insert(
|
|
894
|
+
[fromSlateValue([operation.node], textBlockName)[0]],
|
|
895
|
+
"before",
|
|
896
|
+
[operation.path[0]]
|
|
897
|
+
)
|
|
773
898
|
];
|
|
774
899
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
775
900
|
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = { ...operation.node };
|
|
@@ -792,7 +917,9 @@ function createOperationToPatches(types2) {
|
|
|
792
917
|
])
|
|
793
918
|
];
|
|
794
919
|
}
|
|
795
|
-
return debug$k(
|
|
920
|
+
return debug$k(
|
|
921
|
+
"Something was inserted into a void block. Not producing editor patches."
|
|
922
|
+
), [];
|
|
796
923
|
}
|
|
797
924
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
798
925
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -809,7 +936,9 @@ function createOperationToPatches(types2) {
|
|
|
809
936
|
[editor.children[operation.path[0] + 1]],
|
|
810
937
|
textBlockName
|
|
811
938
|
)[0];
|
|
812
|
-
targetValue && (patches$1.push(
|
|
939
|
+
targetValue && (patches$1.push(
|
|
940
|
+
patches.insert([targetValue], "after", [{ _key: splitBlock._key }])
|
|
941
|
+
), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
813
942
|
const path = [{ _key: oldBlock._key }, "children", { _key: span._key }];
|
|
814
943
|
patches$1.push(patches.unset(path));
|
|
815
944
|
}));
|
|
@@ -823,7 +952,10 @@ function createOperationToPatches(types2) {
|
|
|
823
952
|
[
|
|
824
953
|
{
|
|
825
954
|
...splitBlock,
|
|
826
|
-
children: splitBlock.children.slice(
|
|
955
|
+
children: splitBlock.children.slice(
|
|
956
|
+
operation.path[1] + 1,
|
|
957
|
+
operation.path[1] + 2
|
|
958
|
+
)
|
|
827
959
|
}
|
|
828
960
|
],
|
|
829
961
|
textBlockName
|
|
@@ -855,10 +987,14 @@ function createOperationToPatches(types2) {
|
|
|
855
987
|
throw new Error("Block not found");
|
|
856
988
|
} else if (editor.isTextBlock(block) && operation.path.length === 2) {
|
|
857
989
|
const spanToRemove = block.children[operation.path[1]];
|
|
858
|
-
return spanToRemove ? block.children.filter(
|
|
990
|
+
return spanToRemove ? block.children.filter(
|
|
991
|
+
(span) => span._key === operation.node._key
|
|
992
|
+
).length > 1 ? (console.warn(
|
|
859
993
|
`Multiple spans have \`_key\` ${operation.node._key}. It's ambiguous which one to remove.`,
|
|
860
994
|
JSON.stringify(block, null, 2)
|
|
861
|
-
), []) : [
|
|
995
|
+
), []) : [
|
|
996
|
+
patches.unset([{ _key: block._key }, "children", { _key: spanToRemove._key }])
|
|
997
|
+
] : (debug$k("Span not found in editor trying to remove node"), []);
|
|
862
998
|
} else
|
|
863
999
|
return debug$k("Not creating patch inside object block"), [];
|
|
864
1000
|
}
|
|
@@ -866,13 +1002,18 @@ function createOperationToPatches(types2) {
|
|
|
866
1002
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
867
1003
|
if (operation.path.length === 1)
|
|
868
1004
|
if (block?._key) {
|
|
869
|
-
const newBlock = fromSlateValue(
|
|
1005
|
+
const newBlock = fromSlateValue(
|
|
1006
|
+
[editor.children[operation.path[0] - 1]],
|
|
1007
|
+
textBlockName
|
|
1008
|
+
)[0];
|
|
870
1009
|
patches$1.push(patches.set(newBlock, [{ _key: newBlock._key }])), patches$1.push(patches.unset([{ _key: block._key }]));
|
|
871
1010
|
} else
|
|
872
1011
|
throw new Error("Target key not found!");
|
|
873
1012
|
else if (editor.isTextBlock(block) && editor.isTextBlock(updatedBlock) && operation.path.length === 2) {
|
|
874
1013
|
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && editor.isTextSpan(updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && editor.isTextSpan(block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
875
|
-
updatedSpan && (block.children.filter(
|
|
1014
|
+
updatedSpan && (block.children.filter(
|
|
1015
|
+
(span) => span._key === updatedSpan._key
|
|
1016
|
+
).length === 1 ? patches$1.push(
|
|
876
1017
|
patches.set(updatedSpan.text, [
|
|
877
1018
|
{ _key: block._key },
|
|
878
1019
|
"children",
|
|
@@ -882,7 +1023,11 @@ function createOperationToPatches(types2) {
|
|
|
882
1023
|
) : console.warn(
|
|
883
1024
|
`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`,
|
|
884
1025
|
JSON.stringify(block, null, 2)
|
|
885
|
-
)), removedSpan && (block.children.filter(
|
|
1026
|
+
)), removedSpan && (block.children.filter(
|
|
1027
|
+
(span) => span._key === removedSpan._key
|
|
1028
|
+
).length === 1 ? patches$1.push(
|
|
1029
|
+
patches.unset([{ _key: block._key }, "children", { _key: removedSpan._key }])
|
|
1030
|
+
) : console.warn(
|
|
886
1031
|
`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`,
|
|
887
1032
|
JSON.stringify(block, null, 2)
|
|
888
1033
|
));
|
|
@@ -895,7 +1040,9 @@ function createOperationToPatches(types2) {
|
|
|
895
1040
|
if (operation.path.length === 1) {
|
|
896
1041
|
const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
|
|
897
1042
|
patches$1.push(patches.unset([{ _key: block._key }])), patches$1.push(
|
|
898
|
-
patches.insert([fromSlateValue([block], textBlockName)[0]], position, [
|
|
1043
|
+
patches.insert([fromSlateValue([block], textBlockName)[0]], position, [
|
|
1044
|
+
{ _key: targetBlock._key }
|
|
1045
|
+
])
|
|
899
1046
|
);
|
|
900
1047
|
} else if (operation.path.length === 2 && editor.isTextBlock(block) && editor.isTextBlock(targetBlock)) {
|
|
901
1048
|
const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = fromSlateValue([block], textBlockName)[0].children[operation.path[1]];
|
|
@@ -957,14 +1104,24 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
957
1104
|
},
|
|
958
1105
|
focusBlock: () => {
|
|
959
1106
|
if (editor.selection) {
|
|
960
|
-
const block = slate.Node.descendant(
|
|
1107
|
+
const block = slate.Node.descendant(
|
|
1108
|
+
editor,
|
|
1109
|
+
editor.selection.focus.path.slice(0, 1)
|
|
1110
|
+
);
|
|
961
1111
|
if (block)
|
|
962
|
-
return fromSlateValue(
|
|
1112
|
+
return fromSlateValue(
|
|
1113
|
+
[block],
|
|
1114
|
+
types$1.block.name,
|
|
1115
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1116
|
+
)[0];
|
|
963
1117
|
}
|
|
964
1118
|
},
|
|
965
1119
|
focusChild: () => {
|
|
966
1120
|
if (editor.selection) {
|
|
967
|
-
const block = slate.Node.descendant(
|
|
1121
|
+
const block = slate.Node.descendant(
|
|
1122
|
+
editor,
|
|
1123
|
+
editor.selection.focus.path.slice(0, 1)
|
|
1124
|
+
);
|
|
968
1125
|
if (block && editor.isTextBlock(block))
|
|
969
1126
|
return fromSlateValue(
|
|
970
1127
|
[block],
|
|
@@ -985,7 +1142,9 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
985
1142
|
if (!focusBlock)
|
|
986
1143
|
throw new Error("No focused text block");
|
|
987
1144
|
if (type.name !== types$1.span.name && !types$1.inlineObjects.some((t) => t.name === type.name))
|
|
988
|
-
throw new Error(
|
|
1145
|
+
throw new Error(
|
|
1146
|
+
"This type cannot be inserted as a child to a text block"
|
|
1147
|
+
);
|
|
989
1148
|
const child = toSlateValue(
|
|
990
1149
|
[
|
|
991
1150
|
{
|
|
@@ -1002,11 +1161,17 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1002
1161
|
],
|
|
1003
1162
|
portableTextEditor
|
|
1004
1163
|
)[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types$1.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
1005
|
-
return isSpanNode && focusNode._type !== types$1.span.name && (debug$j(
|
|
1164
|
+
return isSpanNode && focusNode._type !== types$1.span.name && (debug$j(
|
|
1165
|
+
"Inserting span child next to inline object child, moving selection + 1"
|
|
1166
|
+
), editor.move({ distance: 1, unit: "character" })), slate.Transforms.insertNodes(editor, child, {
|
|
1006
1167
|
select: !0,
|
|
1007
1168
|
at: editor.selection
|
|
1008
1169
|
}), editor.onChange(), toPortableTextRange(
|
|
1009
|
-
fromSlateValue(
|
|
1170
|
+
fromSlateValue(
|
|
1171
|
+
editor.children,
|
|
1172
|
+
types$1.block.name,
|
|
1173
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1174
|
+
),
|
|
1010
1175
|
editor.selection,
|
|
1011
1176
|
types$1
|
|
1012
1177
|
)?.focus.path || [];
|
|
@@ -1031,7 +1196,11 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1031
1196
|
})
|
|
1032
1197
|
)[0];
|
|
1033
1198
|
return slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: lastBlock[1] }), editor.onChange(), toPortableTextRange(
|
|
1034
|
-
fromSlateValue(
|
|
1199
|
+
fromSlateValue(
|
|
1200
|
+
editor.children,
|
|
1201
|
+
types$1.block.name,
|
|
1202
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1203
|
+
),
|
|
1035
1204
|
editor.selection,
|
|
1036
1205
|
types$1
|
|
1037
1206
|
)?.focus.path ?? [];
|
|
@@ -1043,7 +1212,11 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1043
1212
|
})
|
|
1044
1213
|
)[0];
|
|
1045
1214
|
return slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types$1) && slate.Transforms.removeNodes(editor, { at: focusBlock[1] }), editor.onChange(), toPortableTextRange(
|
|
1046
|
-
fromSlateValue(
|
|
1215
|
+
fromSlateValue(
|
|
1216
|
+
editor.children,
|
|
1217
|
+
types$1.block.name,
|
|
1218
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1219
|
+
),
|
|
1047
1220
|
editor.selection,
|
|
1048
1221
|
types$1
|
|
1049
1222
|
)?.focus.path || [];
|
|
@@ -1069,10 +1242,16 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1069
1242
|
editor
|
|
1070
1243
|
);
|
|
1071
1244
|
if (slatePath) {
|
|
1072
|
-
const [block, blockPath] = slate.Editor.node(
|
|
1245
|
+
const [block, blockPath] = slate.Editor.node(
|
|
1246
|
+
editor,
|
|
1247
|
+
slatePath.focus.path.slice(0, 1)
|
|
1248
|
+
);
|
|
1073
1249
|
if (block && blockPath && typeof block._key == "string") {
|
|
1074
1250
|
if (path.length === 1 && slatePath.focus.path.length === 1)
|
|
1075
|
-
return [
|
|
1251
|
+
return [
|
|
1252
|
+
fromSlateValue([block], types$1.block.name)[0],
|
|
1253
|
+
[{ _key: block._key }]
|
|
1254
|
+
];
|
|
1076
1255
|
const ptBlock = fromSlateValue(
|
|
1077
1256
|
[block],
|
|
1078
1257
|
types$1.block.name,
|
|
@@ -1081,7 +1260,10 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1081
1260
|
if (editor.isTextBlock(ptBlock)) {
|
|
1082
1261
|
const ptChild = ptBlock.children[slatePath.focus.path[1]];
|
|
1083
1262
|
if (ptChild)
|
|
1084
|
-
return [
|
|
1263
|
+
return [
|
|
1264
|
+
ptChild,
|
|
1265
|
+
[{ _key: block._key }, "children", { _key: ptChild._key }]
|
|
1266
|
+
];
|
|
1085
1267
|
}
|
|
1086
1268
|
}
|
|
1087
1269
|
}
|
|
@@ -1148,43 +1330,74 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1148
1330
|
addAnnotation: (type, value) => {
|
|
1149
1331
|
const { selection: originalSelection } = editor;
|
|
1150
1332
|
let returnValue;
|
|
1151
|
-
if (originalSelection) {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
editor
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1333
|
+
if (originalSelection && (slate.Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange()), editor.selection)) {
|
|
1334
|
+
let spanPath, markDefPath;
|
|
1335
|
+
const markDefPaths = [];
|
|
1336
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
1337
|
+
if (!editor.selection)
|
|
1338
|
+
return;
|
|
1339
|
+
const selectedBlocks = slate.Editor.nodes(editor, {
|
|
1340
|
+
at: editor.selection,
|
|
1341
|
+
match: (node) => editor.isTextBlock(node),
|
|
1342
|
+
reverse: slate.Range.isBackward(editor.selection)
|
|
1343
|
+
});
|
|
1344
|
+
for (const [block, blockPath] of selectedBlocks) {
|
|
1345
|
+
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
1346
|
+
continue;
|
|
1347
|
+
const annotationKey = keyGenerator(), markDefs = block.markDefs ?? [];
|
|
1348
|
+
markDefs.find(
|
|
1349
|
+
(markDef) => markDef._type === type.name && markDef._key === annotationKey
|
|
1350
|
+
) === void 0 && (slate.Transforms.setNodes(
|
|
1351
|
+
editor,
|
|
1352
|
+
{
|
|
1353
|
+
markDefs: [
|
|
1354
|
+
...markDefs,
|
|
1355
|
+
{
|
|
1356
|
+
_type: type.name,
|
|
1357
|
+
_key: annotationKey,
|
|
1358
|
+
...value
|
|
1359
|
+
}
|
|
1360
|
+
]
|
|
1361
|
+
},
|
|
1362
|
+
{ at: blockPath }
|
|
1363
|
+
), markDefPath = [
|
|
1364
|
+
{ _key: block._key },
|
|
1365
|
+
"markDefs",
|
|
1366
|
+
{ _key: annotationKey }
|
|
1367
|
+
], slate.Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), slate.Transforms.setNodes(
|
|
1368
|
+
editor,
|
|
1369
|
+
{},
|
|
1370
|
+
{ match: slate.Text.isText, split: !0 }
|
|
1371
|
+
);
|
|
1372
|
+
const children = slate.Node.children(editor, blockPath);
|
|
1373
|
+
for (const [span, path] of children) {
|
|
1374
|
+
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
1375
|
+
continue;
|
|
1376
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter(
|
|
1377
|
+
(mark) => markDefs.some(
|
|
1378
|
+
(markDef) => markDef._key === mark && markDef._type === type.name
|
|
1379
|
+
)
|
|
1380
|
+
);
|
|
1381
|
+
slate.Transforms.setNodes(
|
|
1382
|
+
editor,
|
|
1383
|
+
{
|
|
1384
|
+
marks: [
|
|
1385
|
+
...marks.filter(
|
|
1386
|
+
(mark) => !existingSameTypeAnnotations.includes(mark)
|
|
1387
|
+
),
|
|
1388
|
+
annotationKey
|
|
1389
|
+
]
|
|
1390
|
+
},
|
|
1391
|
+
{ at: path }
|
|
1392
|
+
), spanPath = [{ _key: block._key }, "children", { _key: span._key }];
|
|
1176
1393
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
);
|
|
1183
|
-
newPortableTextEditorSelection && (returnValue = {
|
|
1184
|
-
spanPath: newPortableTextEditorSelection.focus.path,
|
|
1185
|
-
markDefPath: [{ _key: block._key }, "markDefs", { _key: annotationKey }]
|
|
1394
|
+
}
|
|
1395
|
+
markDefPath && spanPath && (returnValue = {
|
|
1396
|
+
markDefPath,
|
|
1397
|
+
markDefPaths,
|
|
1398
|
+
spanPath
|
|
1186
1399
|
});
|
|
1187
|
-
}),
|
|
1400
|
+
}), editor.onChange();
|
|
1188
1401
|
}
|
|
1189
1402
|
return returnValue;
|
|
1190
1403
|
},
|
|
@@ -1211,34 +1424,98 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1211
1424
|
voids: !0,
|
|
1212
1425
|
match: (node) => node._type === types$1.span.name || // Text children
|
|
1213
1426
|
!editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
1214
|
-
})), editor.children.length === 0 && (editor.children = [editor.
|
|
1427
|
+
})), editor.children.length === 0 && (editor.children = [editor.pteCreateTextBlock({ decorators: [] })]), editor.onChange();
|
|
1215
1428
|
}
|
|
1216
1429
|
}
|
|
1217
1430
|
},
|
|
1218
1431
|
removeAnnotation: (type) => {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
if (selection && slate.Range.isExpanded(selection)) {
|
|
1227
|
-
if (selection = editor.selection, !selection)
|
|
1432
|
+
debug$j("Removing annotation", type), slate.Editor.withoutNormalizing(editor, () => {
|
|
1433
|
+
if (editor.selection)
|
|
1434
|
+
if (slate.Range.isCollapsed(editor.selection)) {
|
|
1435
|
+
const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
|
|
1436
|
+
depth: 1
|
|
1437
|
+
});
|
|
1438
|
+
if (!editor.isTextBlock(block))
|
|
1228
1439
|
return;
|
|
1229
|
-
[
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1440
|
+
const potentialAnnotations = (block.markDefs ?? []).filter(
|
|
1441
|
+
(markDef) => markDef._type === type.name
|
|
1442
|
+
), [selectedChild, selectedChildPath] = slate.Editor.node(
|
|
1443
|
+
editor,
|
|
1444
|
+
editor.selection,
|
|
1445
|
+
{
|
|
1446
|
+
depth: 2
|
|
1447
|
+
}
|
|
1448
|
+
);
|
|
1449
|
+
if (!editor.isTextSpan(selectedChild))
|
|
1450
|
+
return;
|
|
1451
|
+
const annotationToRemove = selectedChild.marks?.find(
|
|
1452
|
+
(mark) => potentialAnnotations.some((markDef) => markDef._key === mark)
|
|
1453
|
+
);
|
|
1454
|
+
if (!annotationToRemove)
|
|
1455
|
+
return;
|
|
1456
|
+
const previousSpansWithSameAnnotation = [];
|
|
1457
|
+
for (const [child, childPath] of slate.Node.children(editor, blockPath, {
|
|
1458
|
+
reverse: !0
|
|
1459
|
+
}))
|
|
1460
|
+
if (editor.isTextSpan(child) && slate.Path.isBefore(childPath, selectedChildPath))
|
|
1461
|
+
if (child.marks?.includes(annotationToRemove))
|
|
1462
|
+
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
1463
|
+
else
|
|
1464
|
+
break;
|
|
1465
|
+
const nextSpansWithSameAnnotation = [];
|
|
1466
|
+
for (const [child, childPath] of slate.Node.children(editor, blockPath))
|
|
1467
|
+
if (editor.isTextSpan(child) && slate.Path.isAfter(childPath, selectedChildPath))
|
|
1468
|
+
if (child.marks?.includes(annotationToRemove))
|
|
1469
|
+
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
1470
|
+
else
|
|
1471
|
+
break;
|
|
1472
|
+
for (const [child, childPath] of [
|
|
1473
|
+
...previousSpansWithSameAnnotation,
|
|
1474
|
+
[selectedChild, selectedChildPath],
|
|
1475
|
+
...nextSpansWithSameAnnotation
|
|
1476
|
+
])
|
|
1477
|
+
slate.Transforms.setNodes(
|
|
1478
|
+
editor,
|
|
1479
|
+
{
|
|
1480
|
+
marks: child.marks?.filter(
|
|
1481
|
+
(mark) => mark !== annotationToRemove
|
|
1482
|
+
)
|
|
1483
|
+
},
|
|
1484
|
+
{ at: childPath }
|
|
1485
|
+
);
|
|
1486
|
+
} else {
|
|
1487
|
+
slate.Transforms.setNodes(
|
|
1488
|
+
editor,
|
|
1489
|
+
{},
|
|
1490
|
+
{
|
|
1491
|
+
match: (node) => editor.isTextSpan(node),
|
|
1492
|
+
split: !0,
|
|
1493
|
+
hanging: !0
|
|
1494
|
+
}
|
|
1495
|
+
);
|
|
1496
|
+
const blocks = slate.Editor.nodes(editor, {
|
|
1497
|
+
at: editor.selection,
|
|
1498
|
+
match: (node) => editor.isTextBlock(node)
|
|
1238
1499
|
});
|
|
1500
|
+
for (const [block, blockPath] of blocks) {
|
|
1501
|
+
const children = slate.Node.children(editor, blockPath);
|
|
1502
|
+
for (const [child, childPath] of children) {
|
|
1503
|
+
if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
|
|
1504
|
+
continue;
|
|
1505
|
+
const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find(
|
|
1506
|
+
(markDef2) => markDef2._key === mark
|
|
1507
|
+
)?._type !== type.name);
|
|
1508
|
+
marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(
|
|
1509
|
+
editor,
|
|
1510
|
+
{
|
|
1511
|
+
marks: marksWithoutAnnotation
|
|
1512
|
+
},
|
|
1513
|
+
{ at: childPath }
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1239
1517
|
}
|
|
1240
|
-
|
|
1241
|
-
}
|
|
1518
|
+
}), editor.onChange();
|
|
1242
1519
|
},
|
|
1243
1520
|
getSelection: () => {
|
|
1244
1521
|
let ptRange = null;
|
|
@@ -1247,14 +1524,22 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1247
1524
|
if (existing)
|
|
1248
1525
|
return existing;
|
|
1249
1526
|
ptRange = toPortableTextRange(
|
|
1250
|
-
fromSlateValue(
|
|
1527
|
+
fromSlateValue(
|
|
1528
|
+
editor.children,
|
|
1529
|
+
types$1.block.name,
|
|
1530
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1531
|
+
),
|
|
1251
1532
|
editor.selection,
|
|
1252
1533
|
types$1
|
|
1253
1534
|
), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
1254
1535
|
}
|
|
1255
1536
|
return ptRange;
|
|
1256
1537
|
},
|
|
1257
|
-
getValue: () => fromSlateValue(
|
|
1538
|
+
getValue: () => fromSlateValue(
|
|
1539
|
+
editor.children,
|
|
1540
|
+
types$1.block.name,
|
|
1541
|
+
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1542
|
+
),
|
|
1258
1543
|
isCollapsedSelection: () => !!editor.selection && slate.Range.isCollapsed(editor.selection),
|
|
1259
1544
|
isExpandedSelection: () => !!editor.selection && slate.Range.isExpanded(editor.selection),
|
|
1260
1545
|
insertBreak: () => {
|
|
@@ -1268,23 +1553,94 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1268
1553
|
}), editor;
|
|
1269
1554
|
};
|
|
1270
1555
|
}
|
|
1271
|
-
function createWithInsertBreak(types2) {
|
|
1556
|
+
function createWithInsertBreak(types2, keyGenerator) {
|
|
1272
1557
|
return function(editor) {
|
|
1273
1558
|
const { insertBreak } = editor;
|
|
1274
1559
|
return editor.insertBreak = () => {
|
|
1275
|
-
if (editor.selection) {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1560
|
+
if (!editor.selection) {
|
|
1561
|
+
insertBreak();
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
const focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
1565
|
+
if (editor.isTextBlock(focusBlock)) {
|
|
1566
|
+
const [start, end] = slate.Range.edges(editor.selection), isEndAtStartOfBlock = isEqual__default.default(end, {
|
|
1567
|
+
path: [...focusBlockPath, 0],
|
|
1568
|
+
offset: 0
|
|
1569
|
+
});
|
|
1570
|
+
if (isEndAtStartOfBlock && slate.Range.isCollapsed(editor.selection)) {
|
|
1571
|
+
const focusDecorators = editor.isTextSpan(focusBlock.children[0]) ? (focusBlock.children[0].marks ?? []).filter(
|
|
1572
|
+
(mark) => types2.decorators.some((decorator) => decorator.value === mark)
|
|
1573
|
+
) : [];
|
|
1574
|
+
slate.Editor.insertNode(
|
|
1575
|
+
editor,
|
|
1576
|
+
editor.pteCreateTextBlock({ decorators: focusDecorators })
|
|
1577
|
+
);
|
|
1578
|
+
const [nextBlockPath] = slate.Path.next(focusBlockPath);
|
|
1579
|
+
slate.Transforms.select(editor, {
|
|
1580
|
+
anchor: { path: [nextBlockPath, 0], offset: 0 },
|
|
1581
|
+
focus: { path: [nextBlockPath, 0], offset: 0 }
|
|
1582
|
+
}), editor.onChange();
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
const lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], isStartAtEndOfBlock = isEqual__default.default(start, {
|
|
1586
|
+
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
1587
|
+
offset: editor.isTextSpan(lastFocusBlockChild) ? lastFocusBlockChild.text.length : 0
|
|
1588
|
+
});
|
|
1589
|
+
if (!isEndAtStartOfBlock && !isStartAtEndOfBlock) {
|
|
1590
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
1591
|
+
if (!editor.selection)
|
|
1592
|
+
return;
|
|
1593
|
+
slate.Transforms.splitNodes(editor, {
|
|
1594
|
+
at: editor.selection
|
|
1595
|
+
});
|
|
1596
|
+
const [nextNode, nextNodePath] = slate.Editor.node(
|
|
1597
|
+
editor,
|
|
1598
|
+
slate.Path.next(focusBlockPath),
|
|
1599
|
+
{ depth: 1 }
|
|
1600
|
+
);
|
|
1601
|
+
if (slate.Transforms.setSelection(editor, {
|
|
1602
|
+
anchor: { path: [...nextNodePath, 0], offset: 0 },
|
|
1603
|
+
focus: { path: [...nextNodePath, 0], offset: 0 }
|
|
1604
|
+
}), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
|
|
1605
|
+
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(
|
|
1606
|
+
slate.Node.children(editor, focusBlockPath)
|
|
1607
|
+
).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextNodePath);
|
|
1608
|
+
for (const [child, childPath] of children) {
|
|
1609
|
+
if (!editor.isTextSpan(child))
|
|
1610
|
+
continue;
|
|
1611
|
+
const marks = child.marks ?? [];
|
|
1612
|
+
for (const mark of marks)
|
|
1613
|
+
types2.decorators.some(
|
|
1614
|
+
(decorator) => decorator.value === mark
|
|
1615
|
+
) || prevNodeSpans.some(
|
|
1616
|
+
(prevNodeSpan) => prevNodeSpan.marks?.includes(mark)
|
|
1617
|
+
) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
1618
|
+
const newMarks = marks.map(
|
|
1619
|
+
(mark) => newMarkDefKeys.get(mark) ?? mark
|
|
1620
|
+
);
|
|
1621
|
+
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(
|
|
1622
|
+
editor,
|
|
1623
|
+
{ marks: newMarks },
|
|
1624
|
+
{
|
|
1625
|
+
at: childPath
|
|
1626
|
+
}
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
1630
|
+
...markDef,
|
|
1631
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
1632
|
+
}));
|
|
1633
|
+
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(
|
|
1634
|
+
editor,
|
|
1635
|
+
{ markDefs: newMarkDefs },
|
|
1636
|
+
{
|
|
1637
|
+
at: nextNodePath,
|
|
1638
|
+
match: (node) => editor.isTextBlock(node)
|
|
1639
|
+
}
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
}), editor.onChange();
|
|
1643
|
+
return;
|
|
1288
1644
|
}
|
|
1289
1645
|
}
|
|
1290
1646
|
insertBreak();
|
|
@@ -2086,9 +2442,11 @@ function createApplyPatch(schemaTypes) {
|
|
|
2086
2442
|
let previousPatch;
|
|
2087
2443
|
return function(editor, patch) {
|
|
2088
2444
|
let changed = !1;
|
|
2089
|
-
debugVerbose$4 && (debug$i(
|
|
2445
|
+
debugVerbose$4 && (debug$i(
|
|
2446
|
+
`
|
|
2090
2447
|
|
|
2091
|
-
NEW PATCH =============================================================`
|
|
2448
|
+
NEW PATCH =============================================================`
|
|
2449
|
+
), debug$i(JSON.stringify(patch, null, 2)));
|
|
2092
2450
|
try {
|
|
2093
2451
|
switch (patch.type) {
|
|
2094
2452
|
case "insert":
|
|
@@ -2113,14 +2471,19 @@ NEW PATCH =============================================================`), debug
|
|
|
2113
2471
|
};
|
|
2114
2472
|
}
|
|
2115
2473
|
function diffMatchPatch(editor, patch) {
|
|
2116
|
-
const { block, child, childPath } = findBlockAndChildFromPath(
|
|
2474
|
+
const { block, child, childPath } = findBlockAndChildFromPath(
|
|
2475
|
+
editor,
|
|
2476
|
+
patch.path
|
|
2477
|
+
);
|
|
2117
2478
|
if (!block)
|
|
2118
2479
|
return debug$i("Block not found"), !1;
|
|
2119
2480
|
if (!child || !childPath)
|
|
2120
2481
|
return debug$i("Child not found"), !1;
|
|
2121
2482
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
2122
2483
|
return !1;
|
|
2123
|
-
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
2484
|
+
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
2485
|
+
allowExceedingIndices: !0
|
|
2486
|
+
}), diff$1 = cleanupEfficiency(diff(child.text, newValue), 5);
|
|
2124
2487
|
debugState(editor, "before");
|
|
2125
2488
|
let offset = 0;
|
|
2126
2489
|
for (const [op, text] of diff$1)
|
|
@@ -2154,12 +2517,17 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
2154
2517
|
{ schemaTypes },
|
|
2155
2518
|
KEY_TO_SLATE_ELEMENT.get(editor)
|
|
2156
2519
|
), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
2157
|
-
return debug$i(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
2520
|
+
return debug$i(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
2521
|
+
at: childInsertPath
|
|
2522
|
+
}), debugState(editor, "after"), !0;
|
|
2158
2523
|
}
|
|
2159
2524
|
function setPatch(editor, patch) {
|
|
2160
2525
|
let value = patch.value;
|
|
2161
2526
|
typeof patch.path[3] == "string" && (value = {}, value[patch.path[3]] = patch.value);
|
|
2162
|
-
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(
|
|
2527
|
+
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(
|
|
2528
|
+
editor,
|
|
2529
|
+
patch.path
|
|
2530
|
+
);
|
|
2163
2531
|
if (!block)
|
|
2164
2532
|
return debug$i("Block not found"), !1;
|
|
2165
2533
|
const isTextBlock = editor.isTextBlock(block);
|
|
@@ -2220,12 +2588,15 @@ function unsetPatch(editor, patch, previousPatch) {
|
|
|
2220
2588
|
const previousSelection = editor.selection;
|
|
2221
2589
|
return slate.Transforms.deselect(editor), editor.children.forEach((c, i) => {
|
|
2222
2590
|
slate.Transforms.removeNodes(editor, { at: [i] });
|
|
2223
|
-
}), slate.Transforms.insertNodes(editor, editor.
|
|
2591
|
+
}), slate.Transforms.insertNodes(editor, editor.pteCreateTextBlock({ decorators: [] })), previousSelection && slate.Transforms.select(editor, {
|
|
2224
2592
|
anchor: { path: [0, 0], offset: 0 },
|
|
2225
2593
|
focus: { path: [0, 0], offset: 0 }
|
|
2226
2594
|
}), editor.onChange(), debugState(editor, "after"), !0;
|
|
2227
2595
|
}
|
|
2228
|
-
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(
|
|
2596
|
+
const { block, blockPath, child, childPath } = findBlockAndChildFromPath(
|
|
2597
|
+
editor,
|
|
2598
|
+
patch.path
|
|
2599
|
+
);
|
|
2229
2600
|
if (patch.path.length === 1) {
|
|
2230
2601
|
if (!block || !blockPath)
|
|
2231
2602
|
return debug$i("Block not found"), !1;
|
|
@@ -2257,7 +2628,12 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2257
2628
|
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
2258
2629
|
return isMatch && (childIndex = index), isMatch;
|
|
2259
2630
|
});
|
|
2260
|
-
return child ? {
|
|
2631
|
+
return child ? {
|
|
2632
|
+
block,
|
|
2633
|
+
child,
|
|
2634
|
+
blockPath,
|
|
2635
|
+
childPath: blockPath?.concat(childIndex)
|
|
2636
|
+
} : { block, blockPath, child: void 0, childPath: void 0 };
|
|
2261
2637
|
}
|
|
2262
2638
|
const PATCHING = /* @__PURE__ */ new WeakMap();
|
|
2263
2639
|
function withoutPatching(editor, fn) {
|
|
@@ -2286,10 +2662,17 @@ function createWithUndoRedo(options) {
|
|
|
2286
2662
|
patches2.forEach((patch) => {
|
|
2287
2663
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2288
2664
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2289
|
-
debug$h(
|
|
2665
|
+
debug$h(
|
|
2666
|
+
"Someone else cleared the content, resetting undo/redo history"
|
|
2667
|
+
), editor.history = { undos: [], redos: [] }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
2290
2668
|
return;
|
|
2291
2669
|
}
|
|
2292
|
-
remotePatches.push({
|
|
2670
|
+
remotePatches.push({
|
|
2671
|
+
patch,
|
|
2672
|
+
time: /* @__PURE__ */ new Date(),
|
|
2673
|
+
snapshot,
|
|
2674
|
+
previousSnapshot
|
|
2675
|
+
});
|
|
2293
2676
|
}
|
|
2294
2677
|
}), previousSnapshot = snapshot;
|
|
2295
2678
|
});
|
|
@@ -2310,7 +2693,10 @@ function createWithUndoRedo(options) {
|
|
|
2310
2693
|
step.operations.push(op);
|
|
2311
2694
|
else {
|
|
2312
2695
|
const newStep = {
|
|
2313
|
-
operations: [
|
|
2696
|
+
operations: [
|
|
2697
|
+
...editor.selection === null ? [] : [createSelectOperation(editor)],
|
|
2698
|
+
op
|
|
2699
|
+
],
|
|
2314
2700
|
timestamp: /* @__PURE__ */ new Date()
|
|
2315
2701
|
};
|
|
2316
2702
|
undos.push(newStep), debug$h("Created new undo step", step);
|
|
@@ -2327,12 +2713,20 @@ function createWithUndoRedo(options) {
|
|
|
2327
2713
|
if (undos.length > 0) {
|
|
2328
2714
|
const step = undos[undos.length - 1];
|
|
2329
2715
|
if (debug$h("Undoing", step), step.operations.length > 0) {
|
|
2330
|
-
const otherPatches = remotePatches.filter(
|
|
2716
|
+
const otherPatches = remotePatches.filter(
|
|
2717
|
+
(item) => item.time >= step.timestamp
|
|
2718
|
+
);
|
|
2331
2719
|
let transformedOperations = step.operations;
|
|
2332
2720
|
otherPatches.forEach((item) => {
|
|
2333
2721
|
transformedOperations = flatten__default.default(
|
|
2334
2722
|
transformedOperations.map(
|
|
2335
|
-
(op) => transformOperation(
|
|
2723
|
+
(op) => transformOperation(
|
|
2724
|
+
editor,
|
|
2725
|
+
item.patch,
|
|
2726
|
+
op,
|
|
2727
|
+
item.snapshot,
|
|
2728
|
+
item.previousSnapshot
|
|
2729
|
+
)
|
|
2336
2730
|
)
|
|
2337
2731
|
);
|
|
2338
2732
|
});
|
|
@@ -2361,12 +2755,20 @@ function createWithUndoRedo(options) {
|
|
|
2361
2755
|
if (redos.length > 0) {
|
|
2362
2756
|
const step = redos[redos.length - 1];
|
|
2363
2757
|
if (debug$h("Redoing", step), step.operations.length > 0) {
|
|
2364
|
-
const otherPatches = remotePatches.filter(
|
|
2758
|
+
const otherPatches = remotePatches.filter(
|
|
2759
|
+
(item) => item.time >= step.timestamp
|
|
2760
|
+
);
|
|
2365
2761
|
let transformedOperations = step.operations;
|
|
2366
2762
|
otherPatches.forEach((item) => {
|
|
2367
2763
|
transformedOperations = flatten__default.default(
|
|
2368
2764
|
transformedOperations.map(
|
|
2369
|
-
(op) => transformOperation(
|
|
2765
|
+
(op) => transformOperation(
|
|
2766
|
+
editor,
|
|
2767
|
+
item.patch,
|
|
2768
|
+
op,
|
|
2769
|
+
item.snapshot,
|
|
2770
|
+
item.previousSnapshot
|
|
2771
|
+
)
|
|
2370
2772
|
)
|
|
2371
2773
|
);
|
|
2372
2774
|
});
|
|
@@ -2391,7 +2793,9 @@ function createWithUndoRedo(options) {
|
|
|
2391
2793
|
};
|
|
2392
2794
|
}
|
|
2393
2795
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2394
|
-
debugVerbose$3 && (debug$h(
|
|
2796
|
+
debugVerbose$3 && (debug$h(
|
|
2797
|
+
`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`
|
|
2798
|
+
), debug$h(`Operation ${JSON.stringify(operation)}`), debug$h(`Patch ${JSON.stringify(patch)}`));
|
|
2395
2799
|
const transformedOperation = { ...operation };
|
|
2396
2800
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2397
2801
|
const insertBlockIndex = (snapshot || []).findIndex(
|
|
@@ -2399,7 +2803,13 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2399
2803
|
);
|
|
2400
2804
|
return debug$h(
|
|
2401
2805
|
`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`
|
|
2402
|
-
), [
|
|
2806
|
+
), [
|
|
2807
|
+
adjustBlockPath(
|
|
2808
|
+
transformedOperation,
|
|
2809
|
+
patch.items.length,
|
|
2810
|
+
insertBlockIndex
|
|
2811
|
+
)
|
|
2812
|
+
];
|
|
2403
2813
|
}
|
|
2404
2814
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2405
2815
|
const unsetBlockIndex = (previousSnapshot || []).findIndex(
|
|
@@ -2410,9 +2820,14 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2410
2820
|
)), [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)]);
|
|
2411
2821
|
}
|
|
2412
2822
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2413
|
-
return debug$h(
|
|
2823
|
+
return debug$h(
|
|
2824
|
+
`Adjusting selection for unset everything patch and ${operation.type} operation`
|
|
2825
|
+
), [];
|
|
2414
2826
|
if (patch.type === "diffMatchPatch") {
|
|
2415
|
-
const operationTargetBlock = findOperationTargetBlock(
|
|
2827
|
+
const operationTargetBlock = findOperationTargetBlock(
|
|
2828
|
+
editor,
|
|
2829
|
+
transformedOperation
|
|
2830
|
+
);
|
|
2416
2831
|
return !operationTargetBlock || !isEqual__default.default({ _key: operationTargetBlock._key }, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2417
2832
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2418
2833
|
const { diffs } = diffPatch;
|
|
@@ -2438,7 +2853,10 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2438
2853
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
2439
2854
|
const transformedOperation = { ...operation };
|
|
2440
2855
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
2441
|
-
const newPath = [
|
|
2856
|
+
const newPath = [
|
|
2857
|
+
transformedOperation.path[0] + level,
|
|
2858
|
+
...transformedOperation.path.slice(1)
|
|
2859
|
+
];
|
|
2442
2860
|
transformedOperation.path = newPath;
|
|
2443
2861
|
}
|
|
2444
2862
|
if (transformedOperation.type === "set_selection") {
|
|
@@ -2526,31 +2944,51 @@ function createWithPatches({
|
|
|
2526
2944
|
case "insert_text":
|
|
2527
2945
|
patches$1 = [
|
|
2528
2946
|
...patches$1,
|
|
2529
|
-
...patchFunctions.insertTextPatch(
|
|
2947
|
+
...patchFunctions.insertTextPatch(
|
|
2948
|
+
editor,
|
|
2949
|
+
operation,
|
|
2950
|
+
previousChildren
|
|
2951
|
+
)
|
|
2530
2952
|
];
|
|
2531
2953
|
break;
|
|
2532
2954
|
case "remove_text":
|
|
2533
2955
|
patches$1 = [
|
|
2534
2956
|
...patches$1,
|
|
2535
|
-
...patchFunctions.removeTextPatch(
|
|
2957
|
+
...patchFunctions.removeTextPatch(
|
|
2958
|
+
editor,
|
|
2959
|
+
operation,
|
|
2960
|
+
previousChildren
|
|
2961
|
+
)
|
|
2536
2962
|
];
|
|
2537
2963
|
break;
|
|
2538
2964
|
case "remove_node":
|
|
2539
2965
|
patches$1 = [
|
|
2540
2966
|
...patches$1,
|
|
2541
|
-
...patchFunctions.removeNodePatch(
|
|
2967
|
+
...patchFunctions.removeNodePatch(
|
|
2968
|
+
editor,
|
|
2969
|
+
operation,
|
|
2970
|
+
previousChildren
|
|
2971
|
+
)
|
|
2542
2972
|
];
|
|
2543
2973
|
break;
|
|
2544
2974
|
case "split_node":
|
|
2545
2975
|
patches$1 = [
|
|
2546
2976
|
...patches$1,
|
|
2547
|
-
...patchFunctions.splitNodePatch(
|
|
2977
|
+
...patchFunctions.splitNodePatch(
|
|
2978
|
+
editor,
|
|
2979
|
+
operation,
|
|
2980
|
+
previousChildren
|
|
2981
|
+
)
|
|
2548
2982
|
];
|
|
2549
2983
|
break;
|
|
2550
2984
|
case "insert_node":
|
|
2551
2985
|
patches$1 = [
|
|
2552
2986
|
...patches$1,
|
|
2553
|
-
...patchFunctions.insertNodePatch(
|
|
2987
|
+
...patchFunctions.insertNodePatch(
|
|
2988
|
+
editor,
|
|
2989
|
+
operation,
|
|
2990
|
+
previousChildren
|
|
2991
|
+
)
|
|
2554
2992
|
];
|
|
2555
2993
|
break;
|
|
2556
2994
|
case "set_node":
|
|
@@ -2562,17 +3000,27 @@ function createWithPatches({
|
|
|
2562
3000
|
case "merge_node":
|
|
2563
3001
|
patches$1 = [
|
|
2564
3002
|
...patches$1,
|
|
2565
|
-
...patchFunctions.mergeNodePatch(
|
|
3003
|
+
...patchFunctions.mergeNodePatch(
|
|
3004
|
+
editor,
|
|
3005
|
+
operation,
|
|
3006
|
+
previousChildren
|
|
3007
|
+
)
|
|
2566
3008
|
];
|
|
2567
3009
|
break;
|
|
2568
3010
|
case "move_node":
|
|
2569
3011
|
patches$1 = [
|
|
2570
3012
|
...patches$1,
|
|
2571
|
-
...patchFunctions.moveNodePatch(
|
|
3013
|
+
...patchFunctions.moveNodePatch(
|
|
3014
|
+
editor,
|
|
3015
|
+
operation,
|
|
3016
|
+
previousChildren
|
|
3017
|
+
)
|
|
2572
3018
|
];
|
|
2573
3019
|
break;
|
|
2574
3020
|
}
|
|
2575
|
-
return !editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(
|
|
3021
|
+
return !editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(
|
|
3022
|
+
operation.type
|
|
3023
|
+
) && (patches$1 = [...patches$1, patches.unset([])], change$.next({
|
|
2576
3024
|
type: "unset",
|
|
2577
3025
|
previousValue: fromSlateValue(
|
|
2578
3026
|
previousChildren,
|
|
@@ -2605,7 +3053,10 @@ function createWithPlaceholderBlock() {
|
|
|
2605
3053
|
const node = op.node;
|
|
2606
3054
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
2607
3055
|
const nextPath = slate.Path.next(op.path);
|
|
2608
|
-
editor.children[nextPath[0]] || (debug$f("Adding placeholder block"), slate.Editor.insertNode(
|
|
3056
|
+
editor.children[nextPath[0]] || (debug$f("Adding placeholder block"), slate.Editor.insertNode(
|
|
3057
|
+
editor,
|
|
3058
|
+
editor.pteCreateTextBlock({ decorators: [] })
|
|
3059
|
+
));
|
|
2609
3060
|
}
|
|
2610
3061
|
}
|
|
2611
3062
|
apply2(op);
|
|
@@ -2624,7 +3075,11 @@ function createWithPortableTextBlockStyle(types2) {
|
|
|
2624
3075
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
|
|
2625
3076
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
2626
3077
|
if (slate.Text.isText(child) && child.text === "") {
|
|
2627
|
-
debug$e(`Normalizing split node to ${defaultStyle} style`, op), slate.Transforms.setNodes(
|
|
3078
|
+
debug$e(`Normalizing split node to ${defaultStyle} style`, op), slate.Transforms.setNodes(
|
|
3079
|
+
editor,
|
|
3080
|
+
{ style: defaultStyle },
|
|
3081
|
+
{ at: [op.path[0] + 1], voids: !1 }
|
|
3082
|
+
);
|
|
2628
3083
|
break;
|
|
2629
3084
|
}
|
|
2630
3085
|
}
|
|
@@ -2640,9 +3095,13 @@ function createWithPortableTextBlockStyle(types2) {
|
|
|
2640
3095
|
match: (node) => editor.isTextBlock(node)
|
|
2641
3096
|
})
|
|
2642
3097
|
].forEach(([node, path]) => {
|
|
2643
|
-
editor.isTextBlock(node) && node.style === blockStyle ? (debug$e(`Unsetting block style '${blockStyle}'`), slate.Transforms.setNodes(
|
|
2644
|
-
|
|
2645
|
-
|
|
3098
|
+
editor.isTextBlock(node) && node.style === blockStyle ? (debug$e(`Unsetting block style '${blockStyle}'`), slate.Transforms.setNodes(
|
|
3099
|
+
editor,
|
|
3100
|
+
{ ...node, style: defaultStyle },
|
|
3101
|
+
{
|
|
3102
|
+
at: path
|
|
3103
|
+
}
|
|
3104
|
+
)) : (blockStyle ? debug$e(`Setting style '${blockStyle}'`) : debug$e("Setting default style", defaultStyle), slate.Transforms.setNodes(
|
|
2646
3105
|
editor,
|
|
2647
3106
|
{
|
|
2648
3107
|
...node,
|
|
@@ -2724,7 +3183,13 @@ function createWithPortableTextLists(types2) {
|
|
|
2724
3183
|
return selectedBlocks.length === 0 ? !1 : (selectedBlocks.forEach(([node, path]) => {
|
|
2725
3184
|
if (editor.isListBlock(node)) {
|
|
2726
3185
|
let level = node.level || 1;
|
|
2727
|
-
reverse ? (level--, debug$d(
|
|
3186
|
+
reverse ? (level--, debug$d(
|
|
3187
|
+
"Decrementing list level",
|
|
3188
|
+
Math.min(MAX_LIST_LEVEL, Math.max(1, level))
|
|
3189
|
+
)) : (level++, debug$d(
|
|
3190
|
+
"Incrementing list level",
|
|
3191
|
+
Math.min(MAX_LIST_LEVEL, Math.max(1, level))
|
|
3192
|
+
)), slate.Transforms.setNodes(
|
|
2728
3193
|
editor,
|
|
2729
3194
|
{ level: Math.min(MAX_LIST_LEVEL, Math.max(1, level)) },
|
|
2730
3195
|
{ at: path }
|
|
@@ -2766,11 +3231,15 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2766
3231
|
return function(editor) {
|
|
2767
3232
|
const { apply: apply2, normalizeNode } = editor, decorators = types2.decorators.map((t) => t.value), forceNewSelection = () => {
|
|
2768
3233
|
editor.selection && (slate.Transforms.select(editor, { ...editor.selection }), editor.selection = { ...editor.selection });
|
|
2769
|
-
const ptRange = toPortableTextRange(
|
|
3234
|
+
const ptRange = toPortableTextRange(
|
|
3235
|
+
editor.children,
|
|
3236
|
+
editor.selection,
|
|
3237
|
+
types2
|
|
3238
|
+
);
|
|
2770
3239
|
change$.next({ type: "selection", selection: ptRange });
|
|
2771
3240
|
};
|
|
2772
3241
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2773
|
-
const [node, path] = nodeEntry
|
|
3242
|
+
const [node, path] = nodeEntry;
|
|
2774
3243
|
if (editor.isTextBlock(node)) {
|
|
2775
3244
|
const children = slate.Node.children(editor, path);
|
|
2776
3245
|
for (const [child, childPath] of children) {
|
|
@@ -2780,73 +3249,80 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2780
3249
|
"Merging spans",
|
|
2781
3250
|
JSON.stringify(child, null, 2),
|
|
2782
3251
|
JSON.stringify(nextNode, null, 2)
|
|
2783
|
-
), slate.Transforms.mergeNodes(editor, {
|
|
3252
|
+
), slate.Transforms.mergeNodes(editor, {
|
|
3253
|
+
at: [childPath[0], childPath[1] + 1],
|
|
3254
|
+
voids: !0
|
|
3255
|
+
});
|
|
2784
3256
|
return;
|
|
2785
3257
|
}
|
|
2786
3258
|
}
|
|
2787
3259
|
}
|
|
2788
|
-
if (
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
3260
|
+
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3261
|
+
debug$c("Adding .markDefs to block node"), slate.Transforms.setNodes(editor, { markDefs: [] }, { at: path });
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3265
|
+
debug$c("Adding .marks to span node"), slate.Transforms.setNodes(editor, { marks: [] }, { at: path });
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
if (editor.isTextSpan(node)) {
|
|
3269
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter(
|
|
3270
|
+
(mark) => !decorators2.includes(mark)
|
|
3271
|
+
);
|
|
3272
|
+
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3273
|
+
debug$c("Removing annotations from empty span node"), slate.Transforms.setNodes(
|
|
3274
|
+
editor,
|
|
3275
|
+
{ marks: node.marks?.filter((mark) => decorators2.includes(mark)) },
|
|
3276
|
+
{ at: path }
|
|
2796
3277
|
);
|
|
2797
|
-
|
|
2798
|
-
const [block] = slate.Editor.node(editor, slate.Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2799
|
-
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2800
|
-
) || [];
|
|
2801
|
-
if (orphanedMarks.length > 0) {
|
|
2802
|
-
debug$c("Removing orphaned .marks from span node"), slate.Transforms.setNodes(
|
|
2803
|
-
editor,
|
|
2804
|
-
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2805
|
-
{ at: path }
|
|
2806
|
-
);
|
|
2807
|
-
return;
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
3278
|
+
return;
|
|
2810
3279
|
}
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
if (op.type === "split_node" && op.path.length === 1 && slate.Element.isElementProps(op.properties) && op.properties._type === types2.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2823
|
-
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] + 1]);
|
|
2824
|
-
if (debug$c("Copying markDefs over to split block", op), editor.isTextBlock(targetBlock)) {
|
|
2825
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [];
|
|
2826
|
-
slate.Transforms.setNodes(
|
|
3280
|
+
}
|
|
3281
|
+
if (editor.isTextBlock(node)) {
|
|
3282
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value);
|
|
3283
|
+
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
3284
|
+
if (editor.isTextSpan(child)) {
|
|
3285
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3286
|
+
if (orphanedAnnotations.length > 0) {
|
|
3287
|
+
debug$c("Removing orphaned annotations from span node"), slate.Transforms.setNodes(
|
|
2827
3288
|
editor,
|
|
2828
|
-
{
|
|
2829
|
-
|
|
3289
|
+
{
|
|
3290
|
+
marks: marks.filter(
|
|
3291
|
+
(mark) => !orphanedAnnotations.includes(mark)
|
|
3292
|
+
)
|
|
3293
|
+
},
|
|
3294
|
+
{ at: childPath }
|
|
2830
3295
|
);
|
|
2831
3296
|
return;
|
|
2832
3297
|
}
|
|
2833
3298
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
if (
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
3299
|
+
}
|
|
3300
|
+
if (editor.isTextSpan(node)) {
|
|
3301
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
3302
|
+
if (editor.isTextBlock(block)) {
|
|
3303
|
+
const decorators2 = types2.decorators.map(
|
|
3304
|
+
(decorator) => decorator.value
|
|
3305
|
+
), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3306
|
+
if (orphanedAnnotations.length > 0) {
|
|
3307
|
+
debug$c("Removing orphaned annotations from span node"), slate.Transforms.setNodes(
|
|
3308
|
+
editor,
|
|
3309
|
+
{
|
|
3310
|
+
marks: marks.filter(
|
|
3311
|
+
(mark) => !orphanedAnnotations.includes(mark)
|
|
3312
|
+
)
|
|
3313
|
+
},
|
|
3314
|
+
{ at: path }
|
|
3315
|
+
);
|
|
3316
|
+
return;
|
|
2847
3317
|
}
|
|
2848
3318
|
}
|
|
2849
3319
|
}
|
|
3320
|
+
if (editor.isTextBlock(node)) {
|
|
3321
|
+
const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
3322
|
+
for (const markDef of markDefs)
|
|
3323
|
+
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3324
|
+
markDefs.length !== newMarkDefs.length && (debug$c("Removing duplicate markDefs"), slate.Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: path }));
|
|
3325
|
+
}
|
|
2850
3326
|
if (editor.isTextBlock(node) && !editor.operations.some(
|
|
2851
3327
|
(op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1
|
|
2852
3328
|
)) {
|
|
@@ -2874,7 +3350,9 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2874
3350
|
}
|
|
2875
3351
|
if (op.type === "insert_text") {
|
|
2876
3352
|
const { selection } = editor;
|
|
2877
|
-
if (selection && slate.Range.isCollapsed(selection) && slate.Editor.marks(editor)?.marks?.some(
|
|
3353
|
+
if (selection && slate.Range.isCollapsed(selection) && slate.Editor.marks(editor)?.marks?.some(
|
|
3354
|
+
(mark) => !decorators.includes(mark)
|
|
3355
|
+
)) {
|
|
2878
3356
|
const [node] = Array.from(
|
|
2879
3357
|
slate.Editor.nodes(editor, {
|
|
2880
3358
|
mode: "lowest",
|
|
@@ -2925,7 +3403,11 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2925
3403
|
...slate.Editor.marks(editor) || {}
|
|
2926
3404
|
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
2927
3405
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2928
|
-
apply2(op), slate.Transforms.setNodes(
|
|
3406
|
+
apply2(op), slate.Transforms.setNodes(
|
|
3407
|
+
editor,
|
|
3408
|
+
{ marks: marksWithoutAnnotationMarks },
|
|
3409
|
+
{ at: op.path }
|
|
3410
|
+
);
|
|
2929
3411
|
}), editor.onChange();
|
|
2930
3412
|
return;
|
|
2931
3413
|
}
|
|
@@ -2937,13 +3419,34 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2937
3419
|
}
|
|
2938
3420
|
}
|
|
2939
3421
|
}
|
|
3422
|
+
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === types2.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
3423
|
+
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
3424
|
+
if (editor.isTextBlock(targetBlock)) {
|
|
3425
|
+
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
3426
|
+
debug$c("Copying markDefs over to merged block", op), slate.Transforms.setNodes(
|
|
3427
|
+
editor,
|
|
3428
|
+
{ markDefs: newMarkDefs },
|
|
3429
|
+
{ at: targetPath, voids: !1 }
|
|
3430
|
+
), apply2(op);
|
|
3431
|
+
return;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
2940
3434
|
apply2(op);
|
|
2941
3435
|
}, editor.addMark = (mark) => {
|
|
2942
3436
|
if (editor.selection) {
|
|
2943
3437
|
if (slate.Range.isExpanded(editor.selection))
|
|
2944
3438
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2945
|
-
slate.Transforms.setNodes(
|
|
2946
|
-
|
|
3439
|
+
slate.Transforms.setNodes(
|
|
3440
|
+
editor,
|
|
3441
|
+
{},
|
|
3442
|
+
{ match: slate.Text.isText, split: !0, hanging: !0 }
|
|
3443
|
+
);
|
|
3444
|
+
const splitTextNodes = slate.Range.isRange(editor.selection) ? [
|
|
3445
|
+
...slate.Editor.nodes(editor, {
|
|
3446
|
+
at: editor.selection,
|
|
3447
|
+
match: slate.Text.isText
|
|
3448
|
+
})
|
|
3449
|
+
] : [];
|
|
2947
3450
|
splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
2948
3451
|
const marks = [
|
|
2949
3452
|
...(Array.isArray(node.marks) ? node.marks : []).filter(
|
|
@@ -2959,13 +3462,32 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2959
3462
|
});
|
|
2960
3463
|
});
|
|
2961
3464
|
else {
|
|
2962
|
-
const
|
|
2963
|
-
|
|
2964
|
-
}.
|
|
2965
|
-
|
|
2966
|
-
marks
|
|
2967
|
-
|
|
2968
|
-
|
|
3465
|
+
const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
|
|
3466
|
+
depth: 1
|
|
3467
|
+
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
3468
|
+
if (lonelyEmptySpan) {
|
|
3469
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter(
|
|
3470
|
+
(existingMark) => existingMark !== mark
|
|
3471
|
+
);
|
|
3472
|
+
slate.Transforms.setNodes(
|
|
3473
|
+
editor,
|
|
3474
|
+
{
|
|
3475
|
+
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
3476
|
+
},
|
|
3477
|
+
{
|
|
3478
|
+
at: blockPath,
|
|
3479
|
+
match: (node) => editor.isTextSpan(node)
|
|
3480
|
+
}
|
|
3481
|
+
);
|
|
3482
|
+
} else {
|
|
3483
|
+
const existingMarks = {
|
|
3484
|
+
...slate.Editor.marks(editor) || {}
|
|
3485
|
+
}.marks || [], marks = {
|
|
3486
|
+
...slate.Editor.marks(editor) || {},
|
|
3487
|
+
marks: [...existingMarks, mark]
|
|
3488
|
+
};
|
|
3489
|
+
return editor.marks = marks, forceNewSelection(), editor;
|
|
3490
|
+
}
|
|
2969
3491
|
}
|
|
2970
3492
|
editor.onChange(), forceNewSelection();
|
|
2971
3493
|
}
|
|
@@ -2975,16 +3497,21 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2975
3497
|
if (selection) {
|
|
2976
3498
|
if (slate.Range.isExpanded(selection))
|
|
2977
3499
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
2978
|
-
slate.Transforms.setNodes(
|
|
2979
|
-
|
|
3500
|
+
slate.Transforms.setNodes(
|
|
3501
|
+
editor,
|
|
3502
|
+
{},
|
|
3503
|
+
{ match: slate.Text.isText, split: !0, hanging: !0 }
|
|
3504
|
+
), editor.selection && [
|
|
3505
|
+
...slate.Editor.nodes(editor, {
|
|
3506
|
+
at: editor.selection,
|
|
3507
|
+
match: slate.Text.isText
|
|
3508
|
+
})
|
|
2980
3509
|
].forEach(([node, path]) => {
|
|
2981
3510
|
const block = editor.children[path[0]];
|
|
2982
3511
|
slate.Element.isElement(block) && block.children.includes(node) && slate.Transforms.setNodes(
|
|
2983
3512
|
editor,
|
|
2984
3513
|
{
|
|
2985
|
-
marks: (Array.isArray(node.marks) ? node.marks : []).filter(
|
|
2986
|
-
(eMark) => eMark !== mark
|
|
2987
|
-
),
|
|
3514
|
+
marks: (Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark),
|
|
2988
3515
|
_type: "span"
|
|
2989
3516
|
},
|
|
2990
3517
|
{ at: path }
|
|
@@ -2992,13 +3519,32 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2992
3519
|
});
|
|
2993
3520
|
}), slate.Editor.normalize(editor);
|
|
2994
3521
|
else {
|
|
2995
|
-
const
|
|
2996
|
-
|
|
2997
|
-
}.
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3522
|
+
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
3523
|
+
depth: 1
|
|
3524
|
+
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
3525
|
+
if (lonelyEmptySpan) {
|
|
3526
|
+
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter(
|
|
3527
|
+
(existingMark) => existingMark !== mark
|
|
3528
|
+
);
|
|
3529
|
+
slate.Transforms.setNodes(
|
|
3530
|
+
editor,
|
|
3531
|
+
{
|
|
3532
|
+
marks: existingMarksWithoutDecorator
|
|
3533
|
+
},
|
|
3534
|
+
{
|
|
3535
|
+
at: blockPath,
|
|
3536
|
+
match: (node) => editor.isTextSpan(node)
|
|
3537
|
+
}
|
|
3538
|
+
);
|
|
3539
|
+
} else {
|
|
3540
|
+
const existingMarks = {
|
|
3541
|
+
...slate.Editor.marks(editor) || {}
|
|
3542
|
+
}.marks || [], marks = {
|
|
3543
|
+
...slate.Editor.marks(editor) || {},
|
|
3544
|
+
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
3545
|
+
};
|
|
3546
|
+
return editor.marks = { marks: marks.marks, _type: "span" }, forceNewSelection(), editor;
|
|
3547
|
+
}
|
|
3002
3548
|
}
|
|
3003
3549
|
editor.onChange(), forceNewSelection();
|
|
3004
3550
|
}
|
|
@@ -3063,7 +3609,11 @@ function createWithSchemaTypes({
|
|
|
3063
3609
|
if (node._type === void 0 && path.length === 2) {
|
|
3064
3610
|
debug$a("Setting span type on text node without a type");
|
|
3065
3611
|
const span = node, key = span._key || keyGenerator();
|
|
3066
|
-
slate.Transforms.setNodes(
|
|
3612
|
+
slate.Transforms.setNodes(
|
|
3613
|
+
editor,
|
|
3614
|
+
{ ...span, _type: schemaTypes.span.name, _key: key },
|
|
3615
|
+
{ at: path }
|
|
3616
|
+
);
|
|
3067
3617
|
}
|
|
3068
3618
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
3069
3619
|
debug$a("Setting missing key on child node without a key");
|
|
@@ -3075,7 +3625,11 @@ function createWithSchemaTypes({
|
|
|
3075
3625
|
};
|
|
3076
3626
|
}
|
|
3077
3627
|
const debug$9 = debugWithName("plugin:withUtils");
|
|
3078
|
-
function createWithUtils({
|
|
3628
|
+
function createWithUtils({
|
|
3629
|
+
schemaTypes,
|
|
3630
|
+
keyGenerator,
|
|
3631
|
+
portableTextEditor
|
|
3632
|
+
}) {
|
|
3079
3633
|
return function(editor) {
|
|
3080
3634
|
return editor.pteExpandToWord = () => {
|
|
3081
3635
|
const { selection } = editor;
|
|
@@ -3095,7 +3649,7 @@ function createWithUtils({ schemaTypes, keyGenerator, portableTextEditor }) {
|
|
|
3095
3649
|
}
|
|
3096
3650
|
debug$9("pteExpandToWord: Can't expand to word here");
|
|
3097
3651
|
}
|
|
3098
|
-
}, editor.
|
|
3652
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue(
|
|
3099
3653
|
[
|
|
3100
3654
|
{
|
|
3101
3655
|
_type: schemaTypes.block.name,
|
|
@@ -3107,7 +3661,9 @@ function createWithUtils({ schemaTypes, keyGenerator, portableTextEditor }) {
|
|
|
3107
3661
|
_type: "span",
|
|
3108
3662
|
_key: keyGenerator(),
|
|
3109
3663
|
text: "",
|
|
3110
|
-
marks:
|
|
3664
|
+
marks: options.decorators.filter(
|
|
3665
|
+
(decorator) => schemaTypes.decorators.find(({ value }) => value === decorator)
|
|
3666
|
+
)
|
|
3111
3667
|
}
|
|
3112
3668
|
]
|
|
3113
3669
|
}
|
|
@@ -3156,59 +3712,46 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3156
3712
|
}
|
|
3157
3713
|
}
|
|
3158
3714
|
});
|
|
3159
|
-
const isEnter = isHotkeyEsm.isHotkey("enter", event.nativeEvent), isTab = isHotkeyEsm.isHotkey("tab", event.nativeEvent), isShiftEnter = isHotkeyEsm.isHotkey("shift+enter", event.nativeEvent), isShiftTab = isHotkeyEsm.isHotkey("shift+tab", event.nativeEvent),
|
|
3715
|
+
const isEnter = isHotkeyEsm.isHotkey("enter", event.nativeEvent), isTab = isHotkeyEsm.isHotkey("tab", event.nativeEvent), isShiftEnter = isHotkeyEsm.isHotkey("shift+enter", event.nativeEvent), isShiftTab = isHotkeyEsm.isHotkey("shift+tab", event.nativeEvent), isArrowDown = isHotkeyEsm.isHotkey("down", event.nativeEvent), isArrowUp = isHotkeyEsm.isHotkey("up", event.nativeEvent);
|
|
3160
3716
|
if (isArrowDown && editor.selection) {
|
|
3161
|
-
const focusBlock = slate.Node.descendant(
|
|
3717
|
+
const focusBlock = slate.Node.descendant(
|
|
3718
|
+
editor,
|
|
3719
|
+
editor.selection.focus.path.slice(0, 1)
|
|
3720
|
+
);
|
|
3162
3721
|
if (focusBlock && slate.Editor.isVoid(editor, focusBlock)) {
|
|
3163
3722
|
const nextPath = slate.Path.next(editor.selection.focus.path.slice(0, 1));
|
|
3164
3723
|
if (!slate.Node.has(editor, nextPath)) {
|
|
3165
|
-
slate.Transforms.insertNodes(
|
|
3724
|
+
slate.Transforms.insertNodes(
|
|
3725
|
+
editor,
|
|
3726
|
+
editor.pteCreateTextBlock({ decorators: [] }),
|
|
3727
|
+
{
|
|
3728
|
+
at: nextPath
|
|
3729
|
+
}
|
|
3730
|
+
), editor.onChange();
|
|
3166
3731
|
return;
|
|
3167
3732
|
}
|
|
3168
3733
|
}
|
|
3169
3734
|
}
|
|
3170
3735
|
if (isArrowUp && editor.selection) {
|
|
3171
|
-
const isFirstBlock = editor.selection.focus.path[0] === 0, focusBlock = slate.Node.descendant(
|
|
3172
|
-
if (isFirstBlock && focusBlock && slate.Editor.isVoid(editor, focusBlock)) {
|
|
3173
|
-
slate.Transforms.insertNodes(editor, editor.pteCreateEmptyBlock(), { at: [0] }), slate.Transforms.select(editor, { path: [0, 0], offset: 0 }), editor.onChange();
|
|
3174
|
-
return;
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
if (isBackspace && editor.selection && editor.selection.focus.path[0] === 0 && slate.Range.isCollapsed(editor.selection)) {
|
|
3178
|
-
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 === "";
|
|
3179
|
-
if (nextBlock && isTextBlock && isEmptyFocusBlock) {
|
|
3180
|
-
event.preventDefault(), event.stopPropagation(), slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), editor.onChange();
|
|
3181
|
-
return;
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
if (isBackspace && editor.selection && editor.selection.focus.path[0] > 0 && slate.Range.isCollapsed(editor.selection)) {
|
|
3185
|
-
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));
|
|
3186
|
-
if (prevBlock && focusBlock && slate.Editor.isVoid(editor, prevBlock) && editor.selection.focus.offset === 0) {
|
|
3187
|
-
debug$8("Preventing deleting void block above"), event.preventDefault(), event.stopPropagation();
|
|
3188
|
-
const isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && focusBlock.children?.[0]?.text === "";
|
|
3189
|
-
if (!isTextBlock || isEmptyFocusBlock) {
|
|
3190
|
-
slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, prevPath), editor.onChange();
|
|
3191
|
-
return;
|
|
3192
|
-
}
|
|
3193
|
-
if (isTextBlock && !isEmptyFocusBlock) {
|
|
3194
|
-
slate.Transforms.select(editor, prevPath), editor.onChange();
|
|
3195
|
-
return;
|
|
3196
|
-
}
|
|
3197
|
-
return;
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
if (isDelete && editor.selection && editor.selection.focus.offset === 0 && slate.Range.isCollapsed(editor.selection) && editor.children[editor.selection.focus.path[0] + 1]) {
|
|
3201
|
-
const nextBlock = slate.Node.descendant(
|
|
3736
|
+
const isFirstBlock = editor.selection.focus.path[0] === 0, focusBlock = slate.Node.descendant(
|
|
3202
3737
|
editor,
|
|
3203
|
-
|
|
3204
|
-
)
|
|
3205
|
-
if (
|
|
3206
|
-
|
|
3738
|
+
editor.selection.focus.path.slice(0, 1)
|
|
3739
|
+
);
|
|
3740
|
+
if (isFirstBlock && focusBlock && slate.Editor.isVoid(editor, focusBlock)) {
|
|
3741
|
+
slate.Transforms.insertNodes(
|
|
3742
|
+
editor,
|
|
3743
|
+
editor.pteCreateTextBlock({ decorators: [] }),
|
|
3744
|
+
{
|
|
3745
|
+
at: [0]
|
|
3746
|
+
}
|
|
3747
|
+
), slate.Transforms.select(editor, { path: [0, 0], offset: 0 }), editor.onChange();
|
|
3207
3748
|
return;
|
|
3208
3749
|
}
|
|
3209
3750
|
}
|
|
3210
3751
|
if ((isTab || isShiftTab) && editor.selection) {
|
|
3211
|
-
const [focusChild] = slate.Editor.node(editor, editor.selection.focus, {
|
|
3752
|
+
const [focusChild] = slate.Editor.node(editor, editor.selection.focus, {
|
|
3753
|
+
depth: 2
|
|
3754
|
+
}), [focusBlock] = types.isPortableTextSpan(focusChild) ? slate.Editor.node(editor, editor.selection.focus, { depth: 1 }) : [], hasAnnotationFocus = focusChild && types.isPortableTextTextBlock(focusBlock) && types.isPortableTextSpan(focusChild) && (focusChild.marks || []).filter(
|
|
3212
3755
|
(m) => (focusBlock.markDefs || []).map((def) => def._key).includes(m)
|
|
3213
3756
|
).length > 0, [start] = slate.Range.edges(editor.selection), atStartOfNode = slate.Editor.isStart(editor, start, start.path);
|
|
3214
3757
|
focusChild && types.isPortableTextSpan(focusChild) && (!hasAnnotationFocus || atStartOfNode) && editor.pteIncrementBlockLevels(isShiftTab) && event.preventDefault();
|
|
@@ -3222,12 +3765,15 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3222
3765
|
if (editor.isTextBlock(focusBlock) && focusBlock.style && focusBlock.style !== types$1.styles[0].value) {
|
|
3223
3766
|
const [, end] = slate.Range.edges(editor.selection);
|
|
3224
3767
|
if (slate.Editor.isEnd(editor, end, end.path)) {
|
|
3225
|
-
slate.Editor.insertNode(
|
|
3768
|
+
slate.Editor.insertNode(
|
|
3769
|
+
editor,
|
|
3770
|
+
editor.pteCreateTextBlock({ decorators: [] })
|
|
3771
|
+
), event.preventDefault(), editor.onChange();
|
|
3226
3772
|
return;
|
|
3227
3773
|
}
|
|
3228
3774
|
}
|
|
3229
3775
|
if (focusBlock && slate.Editor.isVoid(editor, focusBlock)) {
|
|
3230
|
-
slate.Editor.insertNode(editor, editor.
|
|
3776
|
+
slate.Editor.insertNode(editor, editor.pteCreateTextBlock({ decorators: [] })), event.preventDefault(), editor.onChange();
|
|
3231
3777
|
return;
|
|
3232
3778
|
}
|
|
3233
3779
|
event.preventDefault(), editor.insertBreak(), editor.onChange();
|
|
@@ -3247,7 +3793,13 @@ function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
|
3247
3793
|
}
|
|
3248
3794
|
function validateValue(value, types$1, keyGenerator) {
|
|
3249
3795
|
let resolution = null, valid = !0;
|
|
3250
|
-
const validChildTypes = [
|
|
3796
|
+
const validChildTypes = [
|
|
3797
|
+
types$1.span.name,
|
|
3798
|
+
...types$1.inlineObjects.map((t) => t.name)
|
|
3799
|
+
], validBlockTypes = [
|
|
3800
|
+
types$1.block.name,
|
|
3801
|
+
...types$1.blockObjects.map((t) => t.name)
|
|
3802
|
+
];
|
|
3251
3803
|
return value === void 0 ? { valid: !0, resolution: null, value } : !Array.isArray(value) || value.length === 0 ? {
|
|
3252
3804
|
valid: !1,
|
|
3253
3805
|
resolution: {
|
|
@@ -3290,7 +3842,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3290
3842
|
if (blk._type === "block") {
|
|
3291
3843
|
const currentBlockTypeName = types$1.block.name;
|
|
3292
3844
|
return resolution = {
|
|
3293
|
-
patches: [
|
|
3845
|
+
patches: [
|
|
3846
|
+
patches.set({ ...blk, _type: currentBlockTypeName }, [{ _key: blk._key }])
|
|
3847
|
+
],
|
|
3294
3848
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
3295
3849
|
action: `Use type '${currentBlockTypeName}'`,
|
|
3296
3850
|
item: blk,
|
|
@@ -3302,7 +3856,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3302
3856
|
}, !0;
|
|
3303
3857
|
}
|
|
3304
3858
|
return !blk._type && types.isPortableTextTextBlock({ ...blk, _type: types$1.block.name }) ? (resolution = {
|
|
3305
|
-
patches: [
|
|
3859
|
+
patches: [
|
|
3860
|
+
patches.set({ ...blk, _type: types$1.block.name }, [{ _key: blk._key }])
|
|
3861
|
+
],
|
|
3306
3862
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types$1.block.name}'`,
|
|
3307
3863
|
action: `Use type '${types$1.block.name}'`,
|
|
3308
3864
|
item: blk,
|
|
@@ -3372,7 +3928,11 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3372
3928
|
}
|
|
3373
3929
|
if (blk.markDefs && !Array.isArray(blk.markDefs))
|
|
3374
3930
|
return resolution = {
|
|
3375
|
-
patches: [
|
|
3931
|
+
patches: [
|
|
3932
|
+
patches.set({ ...textBlock, markDefs: EMPTY_MARKDEFS }, [
|
|
3933
|
+
{ _key: textBlock._key }
|
|
3934
|
+
])
|
|
3935
|
+
],
|
|
3376
3936
|
description: "Block has invalid required property 'markDefs'.",
|
|
3377
3937
|
action: "Add empty markDefs array",
|
|
3378
3938
|
item: textBlock,
|
|
@@ -3405,7 +3965,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3405
3965
|
i18n: {
|
|
3406
3966
|
description: "inputs.portable-text.invalid-value.orphaned-mark-defs.description",
|
|
3407
3967
|
action: "inputs.portable-text.invalid-value.orphaned-mark-defs.action",
|
|
3408
|
-
values: {
|
|
3968
|
+
values: {
|
|
3969
|
+
key: blk._key,
|
|
3970
|
+
unusedMarkDefs: unusedMarkDefs.map((m) => m.toString())
|
|
3971
|
+
}
|
|
3409
3972
|
}
|
|
3410
3973
|
}, !0;
|
|
3411
3974
|
}
|
|
@@ -3423,7 +3986,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3423
3986
|
return resolution = {
|
|
3424
3987
|
autoResolve: !0,
|
|
3425
3988
|
patches: spanChildren.map((child) => patches.set(
|
|
3426
|
-
(child.marks || []).filter(
|
|
3989
|
+
(child.marks || []).filter(
|
|
3990
|
+
(cMrk) => !orphanedMarks.includes(cMrk)
|
|
3991
|
+
),
|
|
3427
3992
|
[{ _key: blk._key }, "children", { _key: child._key }, "marks"]
|
|
3428
3993
|
)),
|
|
3429
3994
|
description: `Block with _key '${blk._key}' contains marks (${orphaned}) not supported by the current content model.`,
|
|
@@ -3432,7 +3997,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3432
3997
|
i18n: {
|
|
3433
3998
|
description: "inputs.portable-text.invalid-value.orphaned-marks.description",
|
|
3434
3999
|
action: "inputs.portable-text.invalid-value.orphaned-marks.action",
|
|
3435
|
-
values: {
|
|
4000
|
+
values: {
|
|
4001
|
+
key: blk._key,
|
|
4002
|
+
orphanedMarks: orphanedMarks.map((m) => m.toString())
|
|
4003
|
+
}
|
|
3436
4004
|
}
|
|
3437
4005
|
}, !0;
|
|
3438
4006
|
}
|
|
@@ -3454,7 +4022,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3454
4022
|
const newChild = { ...child, _key: keyGenerator() };
|
|
3455
4023
|
return resolution = {
|
|
3456
4024
|
autoResolve: !0,
|
|
3457
|
-
patches: [
|
|
4025
|
+
patches: [
|
|
4026
|
+
patches.set(newChild, [{ _key: blk._key }, "children", cIndex])
|
|
4027
|
+
],
|
|
3458
4028
|
description: `Child at index ${cIndex} is missing required _key in block with _key ${blk._key}.`,
|
|
3459
4029
|
action: "Set a new random _key on the object",
|
|
3460
4030
|
item: blk,
|
|
@@ -3467,7 +4037,11 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3467
4037
|
}
|
|
3468
4038
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
3469
4039
|
patches: [
|
|
3470
|
-
patches.set({ ...child, text: "" }, [
|
|
4040
|
+
patches.set({ ...child, text: "" }, [
|
|
4041
|
+
{ _key: blk._key },
|
|
4042
|
+
"children",
|
|
4043
|
+
{ _key: child._key }
|
|
4044
|
+
])
|
|
3471
4045
|
],
|
|
3472
4046
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' has missing or invalid text property!`,
|
|
3473
4047
|
action: "Write an empty text property to the object",
|
|
@@ -3478,17 +4052,25 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3478
4052
|
values: { key: blk._key, childKey: child._key }
|
|
3479
4053
|
}
|
|
3480
4054
|
}, !0) : !1 : (resolution = {
|
|
3481
|
-
patches: [
|
|
4055
|
+
patches: [
|
|
4056
|
+
patches.unset([{ _key: blk._key }, "children", { _key: child._key }])
|
|
4057
|
+
],
|
|
3482
4058
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' has invalid '_type' property (${child._type}).`,
|
|
3483
4059
|
action: "Remove the object",
|
|
3484
4060
|
item: blk,
|
|
3485
4061
|
i18n: {
|
|
3486
4062
|
description: "inputs.portable-text.invalid-value.disallowed-child-type.description",
|
|
3487
4063
|
action: "inputs.portable-text.invalid-value.disallowed-child-type.action",
|
|
3488
|
-
values: {
|
|
4064
|
+
values: {
|
|
4065
|
+
key: blk._key,
|
|
4066
|
+
childKey: child._key,
|
|
4067
|
+
childType: child._type
|
|
4068
|
+
}
|
|
3489
4069
|
}
|
|
3490
4070
|
}, !0) : (resolution = {
|
|
3491
|
-
patches: [
|
|
4071
|
+
patches: [
|
|
4072
|
+
patches.unset([{ _key: blk._key }, "children", { _key: child._key }])
|
|
4073
|
+
],
|
|
3492
4074
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' is missing '_type' property.`,
|
|
3493
4075
|
action: "Remove the object",
|
|
3494
4076
|
item: blk,
|
|
@@ -3522,11 +4104,13 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3522
4104
|
const [voidNode] = endVoid, r = domRange.cloneRange(), domNode = slateReact.ReactEditor.toDOMNode(editor, voidNode);
|
|
3523
4105
|
r.setEndAfter(domNode), contents = r.cloneContents();
|
|
3524
4106
|
}
|
|
3525
|
-
Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach(
|
|
3526
|
-
|
|
3527
|
-
|
|
4107
|
+
Array.from(contents.querySelectorAll("[data-slate-zero-width]")).forEach(
|
|
4108
|
+
(zw) => {
|
|
4109
|
+
const isNewline = zw.getAttribute("data-slate-zero-width") === "n";
|
|
4110
|
+
zw.textContent = isNewline ? `
|
|
3528
4111
|
` : "";
|
|
3529
|
-
|
|
4112
|
+
}
|
|
4113
|
+
), Array.from(contents.querySelectorAll("*")).forEach((elm) => {
|
|
3530
4114
|
elm.removeAttribute("contentEditable"), elm.removeAttribute("data-slate-inline"), elm.removeAttribute("data-slate-leaf"), elm.removeAttribute("data-slate-node"), elm.removeAttribute("data-slate-spacer"), elm.removeAttribute("data-slate-string"), elm.removeAttribute("data-slate-zero-width"), elm.removeAttribute("draggable");
|
|
3531
4115
|
for (const key in elm.attributes)
|
|
3532
4116
|
elm.hasAttribute(key) && elm.removeAttribute(key);
|
|
@@ -3536,7 +4120,10 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3536
4120
|
const asHTML = div.innerHTML;
|
|
3537
4121
|
contents.ownerDocument.body.removeChild(div);
|
|
3538
4122
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
3539
|
-
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(
|
|
4123
|
+
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(
|
|
4124
|
+
"application/x-portable-text-event-origin",
|
|
4125
|
+
originEvent || "external"
|
|
4126
|
+
), debug$7("Set fragment data", asJSON, asHTML);
|
|
3540
4127
|
}, editor.insertPortableTextData = (data) => {
|
|
3541
4128
|
if (!editor.selection)
|
|
3542
4129
|
return !1;
|
|
@@ -3576,7 +4163,9 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3576
4163
|
if (html) {
|
|
3577
4164
|
if (portableText = blockTools.htmlToBlocks(html, schemaTypes.portableText, {
|
|
3578
4165
|
unstable_whitespaceOnPasteMode: whitespaceOnPasteMode
|
|
3579
|
-
}).map(
|
|
4166
|
+
}).map(
|
|
4167
|
+
(block) => blockTools.normalizeBlock(block, { blockTypeName })
|
|
4168
|
+
), fragment = toSlateValue(portableText, { schemaTypes }), insertedType = "HTML", portableText.length === 0)
|
|
3580
4169
|
return !1;
|
|
3581
4170
|
} else {
|
|
3582
4171
|
const textToHtml = `<html><body>${escapeHtml(text).split(/\n{2,}/).map(
|
|
@@ -3588,7 +4177,11 @@ function createWithInsertData(change$, schemaTypes, keyGenerator) {
|
|
|
3588
4177
|
schemaTypes
|
|
3589
4178
|
}), insertedType = "text";
|
|
3590
4179
|
}
|
|
3591
|
-
const validation = validateValue(
|
|
4180
|
+
const validation = validateValue(
|
|
4181
|
+
portableText,
|
|
4182
|
+
schemaTypes,
|
|
4183
|
+
keyGenerator
|
|
4184
|
+
);
|
|
3592
4185
|
if (!validation.valid) {
|
|
3593
4186
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
3594
4187
|
${validation.resolution?.description}
|
|
@@ -3601,7 +4194,9 @@ Try to insert as plain text (shift-paste) instead.`;
|
|
|
3601
4194
|
data: validation
|
|
3602
4195
|
}), debug$7("Invalid insert result", validation), !1;
|
|
3603
4196
|
}
|
|
3604
|
-
return debug$7(
|
|
4197
|
+
return debug$7(
|
|
4198
|
+
`Inserting ${insertedType} fragment at ${JSON.stringify(editor.selection)}`
|
|
4199
|
+
), _insertFragment(editor, fragment, schemaTypes), change$.next({ type: "loading", isLoading: !1 }), !0;
|
|
3605
4200
|
}
|
|
3606
4201
|
return change$.next({ type: "loading", isLoading: !1 }), !1;
|
|
3607
4202
|
}, editor.insertData = (data) => {
|
|
@@ -3666,18 +4261,30 @@ function _insertFragment(editor, fragment, schemaTypes) {
|
|
|
3666
4261
|
editor.withoutNormalizing(() => {
|
|
3667
4262
|
if (!editor.selection)
|
|
3668
4263
|
return;
|
|
3669
|
-
const [focusBlock, focusPath] = slate.Editor.node(editor, editor.selection, {
|
|
4264
|
+
const [focusBlock, focusPath] = slate.Editor.node(editor, editor.selection, {
|
|
4265
|
+
depth: 1
|
|
4266
|
+
});
|
|
3670
4267
|
if (editor.isTextBlock(focusBlock) && editor.isTextBlock(fragment[0])) {
|
|
3671
4268
|
const { markDefs } = focusBlock;
|
|
3672
|
-
debug$7(
|
|
4269
|
+
debug$7(
|
|
4270
|
+
"Mixing markDefs of focusBlock and fragments[0] block",
|
|
4271
|
+
markDefs,
|
|
4272
|
+
fragment[0].markDefs
|
|
4273
|
+
), isEqual__default.default(markDefs, fragment[0].markDefs) || slate.Transforms.setNodes(
|
|
3673
4274
|
editor,
|
|
3674
4275
|
{
|
|
3675
|
-
markDefs: uniq__default.default([
|
|
4276
|
+
markDefs: uniq__default.default([
|
|
4277
|
+
...fragment[0].markDefs || [],
|
|
4278
|
+
...markDefs || []
|
|
4279
|
+
])
|
|
3676
4280
|
},
|
|
3677
4281
|
{ at: focusPath, mode: "lowest", voids: !1 }
|
|
3678
4282
|
);
|
|
3679
4283
|
}
|
|
3680
|
-
isEqualToEmptyEditor(
|
|
4284
|
+
isEqualToEmptyEditor(
|
|
4285
|
+
editor.children,
|
|
4286
|
+
schemaTypes
|
|
4287
|
+
) ? (slate.Transforms.splitNodes(editor, { at: [0, 0] }), editor.insertFragment(fragment), slate.Transforms.removeNodes(editor, { at: [0] })) : editor.insertFragment(fragment);
|
|
3681
4288
|
}), editor.onChange();
|
|
3682
4289
|
}
|
|
3683
4290
|
const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, options) => {
|
|
@@ -3687,7 +4294,11 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3687
4294
|
onChange: e.onChange,
|
|
3688
4295
|
normalizeNode: e.normalizeNode
|
|
3689
4296
|
});
|
|
3690
|
-
const operationToPatches = createOperationToPatches(schemaTypes), withObjectKeys = createWithObjectKeys(schemaTypes, keyGenerator), withSchemaTypes = createWithSchemaTypes({ schemaTypes, keyGenerator }), withEditableAPI = createWithEditableAPI(
|
|
4297
|
+
const operationToPatches = createOperationToPatches(schemaTypes), withObjectKeys = createWithObjectKeys(schemaTypes, keyGenerator), withSchemaTypes = createWithSchemaTypes({ schemaTypes, keyGenerator }), withEditableAPI = createWithEditableAPI(
|
|
4298
|
+
portableTextEditor,
|
|
4299
|
+
schemaTypes,
|
|
4300
|
+
keyGenerator
|
|
4301
|
+
), withPatches = createWithPatches({
|
|
3691
4302
|
change$,
|
|
3692
4303
|
keyGenerator,
|
|
3693
4304
|
patches$,
|
|
@@ -3702,7 +4313,14 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3702
4313
|
schemaTypes,
|
|
3703
4314
|
change$,
|
|
3704
4315
|
keyGenerator
|
|
3705
|
-
), withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withInsertBreak = createWithInsertBreak(schemaTypes), withUtils = createWithUtils({
|
|
4316
|
+
), withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withInsertBreak = createWithInsertBreak(schemaTypes, keyGenerator), withUtils = createWithUtils({
|
|
4317
|
+
keyGenerator,
|
|
4318
|
+
schemaTypes,
|
|
4319
|
+
portableTextEditor
|
|
4320
|
+
}), withPortableTextSelections = createWithPortableTextSelections(
|
|
4321
|
+
change$,
|
|
4322
|
+
schemaTypes
|
|
4323
|
+
);
|
|
3706
4324
|
return e.destroy = () => {
|
|
3707
4325
|
const originalFunctions = originalFnMap.get(e);
|
|
3708
4326
|
if (!originalFunctions)
|
|
@@ -3716,7 +4334,9 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3716
4334
|
withUtils(
|
|
3717
4335
|
withPlaceholderBlock(
|
|
3718
4336
|
withPortableTextLists(
|
|
3719
|
-
withPortableTextSelections(
|
|
4337
|
+
withPortableTextSelections(
|
|
4338
|
+
withEditableAPI(withInsertBreak(e))
|
|
4339
|
+
)
|
|
3720
4340
|
)
|
|
3721
4341
|
)
|
|
3722
4342
|
)
|
|
@@ -3735,7 +4355,11 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
3735
4355
|
withUtils(
|
|
3736
4356
|
withMaxBlocks(
|
|
3737
4357
|
withUndoRedo(
|
|
3738
|
-
withPatches(
|
|
4358
|
+
withPatches(
|
|
4359
|
+
withPortableTextSelections(
|
|
4360
|
+
withEditableAPI(withInsertBreak(e))
|
|
4361
|
+
)
|
|
4362
|
+
)
|
|
3739
4363
|
)
|
|
3740
4364
|
)
|
|
3741
4365
|
)
|
|
@@ -3782,8 +4406,15 @@ function SlateContainer(props) {
|
|
|
3782
4406
|
portableTextEditor,
|
|
3783
4407
|
readOnly
|
|
3784
4408
|
});
|
|
3785
|
-
}, [
|
|
3786
|
-
|
|
4409
|
+
}, [
|
|
4410
|
+
keyGenerator,
|
|
4411
|
+
portableTextEditor,
|
|
4412
|
+
maxBlocks,
|
|
4413
|
+
readOnly,
|
|
4414
|
+
patches$,
|
|
4415
|
+
slateEditor
|
|
4416
|
+
]);
|
|
4417
|
+
const initialValue = react.useMemo(() => [slateEditor.pteCreateTextBlock({ decorators: [] })], [slateEditor]);
|
|
3787
4418
|
return react.useEffect(() => () => {
|
|
3788
4419
|
debug$6("Destroying Slate editor"), slateEditor.destroy();
|
|
3789
4420
|
}, [slateEditor]), /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor, initialValue, children: props.children });
|
|
@@ -3840,7 +4471,11 @@ function useSyncValue(props) {
|
|
|
3840
4471
|
slate.Transforms.removeNodes(slateEditor, {
|
|
3841
4472
|
at: [childrenLength - 1 - index]
|
|
3842
4473
|
});
|
|
3843
|
-
}), slate.Transforms.insertNodes(
|
|
4474
|
+
}), slate.Transforms.insertNodes(
|
|
4475
|
+
slateEditor,
|
|
4476
|
+
slateEditor.pteCreateTextBlock({ decorators: [] }),
|
|
4477
|
+
{ at: [0] }
|
|
4478
|
+
), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
|
|
3844
4479
|
});
|
|
3845
4480
|
});
|
|
3846
4481
|
}), isChanged = !0), value && value.length > 0) {
|
|
@@ -3859,34 +4494,53 @@ function useSyncValue(props) {
|
|
|
3859
4494
|
});
|
|
3860
4495
|
isChanged = !0;
|
|
3861
4496
|
}
|
|
3862
|
-
slateValueFromProps.forEach(
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
currentBlock
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
4497
|
+
slateValueFromProps.forEach(
|
|
4498
|
+
(currentBlock, currentBlockIndex) => {
|
|
4499
|
+
const oldBlock = slateEditor.children[currentBlockIndex];
|
|
4500
|
+
if (oldBlock && !isEqual__default.default(currentBlock, oldBlock) && isValid) {
|
|
4501
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(
|
|
4502
|
+
validationValue,
|
|
4503
|
+
schemaTypes,
|
|
4504
|
+
keyGenerator
|
|
4505
|
+
);
|
|
4506
|
+
!validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(
|
|
4507
|
+
`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`
|
|
4508
|
+
), validation.resolution.patches.forEach((patch) => {
|
|
4509
|
+
change$.next({ type: "patch", patch });
|
|
4510
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$5.enabled && debug$5("Updating block", oldBlock, currentBlock), _updateBlock(
|
|
4511
|
+
slateEditor,
|
|
4512
|
+
currentBlock,
|
|
4513
|
+
oldBlock,
|
|
4514
|
+
currentBlockIndex
|
|
4515
|
+
)) : (debug$5.enabled && debug$5("Replacing block", oldBlock, currentBlock), _replaceBlock(
|
|
4516
|
+
slateEditor,
|
|
4517
|
+
currentBlock,
|
|
4518
|
+
currentBlockIndex
|
|
4519
|
+
)), isChanged = !0) : (change$.next({
|
|
4520
|
+
type: "invalidValue",
|
|
4521
|
+
resolution: validation.resolution,
|
|
4522
|
+
value
|
|
4523
|
+
}), isValid = !1);
|
|
4524
|
+
}
|
|
4525
|
+
if (!oldBlock && isValid) {
|
|
4526
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(
|
|
4527
|
+
validationValue,
|
|
4528
|
+
schemaTypes,
|
|
4529
|
+
keyGenerator
|
|
4530
|
+
);
|
|
4531
|
+
debug$5.enabled && debug$5(
|
|
4532
|
+
"Validating and inserting new block in the end of the value",
|
|
4533
|
+
currentBlock
|
|
4534
|
+
), validation.valid || validation.resolution?.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
4535
|
+
at: [currentBlockIndex]
|
|
4536
|
+
}) : (debug$5("Invalid", validation), change$.next({
|
|
4537
|
+
type: "invalidValue",
|
|
4538
|
+
resolution: validation.resolution,
|
|
4539
|
+
value
|
|
4540
|
+
}), isValid = !1);
|
|
4541
|
+
}
|
|
3888
4542
|
}
|
|
3889
|
-
|
|
4543
|
+
);
|
|
3890
4544
|
});
|
|
3891
4545
|
});
|
|
3892
4546
|
});
|
|
@@ -3936,41 +4590,53 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3936
4590
|
at: [currentBlockIndex]
|
|
3937
4591
|
}), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
3938
4592
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
3939
|
-
currentBlock.children.length < oldBlockChildrenLength && Array.from(
|
|
3940
|
-
(
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
4593
|
+
currentBlock.children.length < oldBlockChildrenLength && Array.from(
|
|
4594
|
+
Array(oldBlockChildrenLength - currentBlock.children.length)
|
|
4595
|
+
).forEach((_, index) => {
|
|
4596
|
+
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
4597
|
+
childIndex > 0 && (debug$5("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
4598
|
+
at: [currentBlockIndex, childIndex]
|
|
4599
|
+
}));
|
|
4600
|
+
}), currentBlock.children.forEach(
|
|
4601
|
+
(currentBlockChild, currentBlockChildIndex) => {
|
|
4602
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(
|
|
4603
|
+
currentBlockChild.text,
|
|
4604
|
+
oldBlockChild?.text
|
|
4605
|
+
), path = [currentBlockIndex, currentBlockChildIndex];
|
|
4606
|
+
if (isChildChanged)
|
|
4607
|
+
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
4608
|
+
debug$5("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(
|
|
4609
|
+
slateEditor,
|
|
4610
|
+
currentBlockChild,
|
|
4611
|
+
{
|
|
4612
|
+
at: path
|
|
4613
|
+
}
|
|
4614
|
+
);
|
|
4615
|
+
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
4616
|
+
isSpanNode && isTextChanged ? (slate.Transforms.delete(slateEditor, {
|
|
4617
|
+
at: {
|
|
4618
|
+
focus: { path, offset: 0 },
|
|
4619
|
+
anchor: { path, offset: oldBlockChild.text.length }
|
|
4620
|
+
}
|
|
4621
|
+
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
4622
|
+
at: path
|
|
4623
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$5("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(
|
|
4624
|
+
slateEditor,
|
|
4625
|
+
{ _key: VOID_CHILD_KEY },
|
|
4626
|
+
{
|
|
4627
|
+
at: [...path, 0],
|
|
4628
|
+
voids: !0
|
|
4629
|
+
}
|
|
4630
|
+
));
|
|
4631
|
+
} else oldBlockChild ? (debug$5("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
4632
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
4633
|
+
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
4634
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
4635
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$5("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
4636
|
+
at: [currentBlockIndex, currentBlockChildIndex]
|
|
4637
|
+
}), slateEditor.onChange());
|
|
3945
4638
|
}
|
|
3946
|
-
)
|
|
3947
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3948
|
-
if (isChildChanged)
|
|
3949
|
-
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
3950
|
-
debug$5("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3951
|
-
at: path
|
|
3952
|
-
});
|
|
3953
|
-
const isSpanNode = slate.Text.isText(currentBlockChild) && currentBlockChild._type === "span" && slate.Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
3954
|
-
isSpanNode && isTextChanged ? (slate.Transforms.delete(slateEditor, {
|
|
3955
|
-
at: { focus: { path, offset: 0 }, anchor: { path, offset: oldBlockChild.text.length } }
|
|
3956
|
-
}), slate.Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
3957
|
-
at: path
|
|
3958
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$5("Updating changed inline object child", currentBlockChild), slate.Transforms.setNodes(
|
|
3959
|
-
slateEditor,
|
|
3960
|
-
{ _key: VOID_CHILD_KEY },
|
|
3961
|
-
{
|
|
3962
|
-
at: [...path, 0],
|
|
3963
|
-
voids: !0
|
|
3964
|
-
}
|
|
3965
|
-
));
|
|
3966
|
-
} else oldBlockChild ? (debug$5("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
3967
|
-
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3968
|
-
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3969
|
-
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3970
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$5("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
3971
|
-
at: [currentBlockIndex, currentBlockChildIndex]
|
|
3972
|
-
}), slateEditor.onChange());
|
|
3973
|
-
});
|
|
4639
|
+
);
|
|
3974
4640
|
}
|
|
3975
4641
|
}
|
|
3976
4642
|
const debug$4 = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$1 = debug$4.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
|
|
@@ -3989,7 +4655,11 @@ function Synchronizer(props) {
|
|
|
3989
4655
|
debug$4("Flushing pending patches"), debugVerbose$1 && debug$4(`Patches:
|
|
3990
4656
|
${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
3991
4657
|
const snapshot = getValue();
|
|
3992
|
-
change$.next({
|
|
4658
|
+
change$.next({
|
|
4659
|
+
type: "mutation",
|
|
4660
|
+
patches: pendingPatches.current,
|
|
4661
|
+
snapshot
|
|
4662
|
+
}), pendingPatches.current = [];
|
|
3993
4663
|
}
|
|
3994
4664
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
3995
4665
|
}, [slateEditor, getValue, change$]), onFlushPendingPatchesThrottled = react.useMemo(() => throttle__default.default(
|
|
@@ -4075,7 +4745,9 @@ class PortableTextEditor extends react.Component {
|
|
|
4075
4745
|
constructor(props) {
|
|
4076
4746
|
if (super(props), !props.schemaType)
|
|
4077
4747
|
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
4078
|
-
props.incomingPatches$ && console.warn(
|
|
4748
|
+
props.incomingPatches$ && console.warn(
|
|
4749
|
+
"The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"
|
|
4750
|
+
), this.change$.next({ type: "loading", isLoading: !0 }), this.schemaTypes = getPortableTextMemberSchemaTypes(
|
|
4079
4751
|
props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)
|
|
4080
4752
|
);
|
|
4081
4753
|
}
|
|
@@ -4167,14 +4839,26 @@ class PortableTextEditor extends react.Component {
|
|
|
4167
4839
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
4168
4840
|
}
|
|
4169
4841
|
const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
4170
|
-
const {
|
|
4842
|
+
const {
|
|
4843
|
+
attributes,
|
|
4844
|
+
children,
|
|
4845
|
+
leaf,
|
|
4846
|
+
schemaTypes,
|
|
4847
|
+
renderChild,
|
|
4848
|
+
renderDecorator,
|
|
4849
|
+
renderAnnotation
|
|
4850
|
+
} = 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(
|
|
4171
4851
|
() => block ? [{ _key: block?._key }, "children", { _key: leaf._key }] : [],
|
|
4172
4852
|
[block, leaf._key]
|
|
4173
4853
|
), decoratorValues = react.useMemo(
|
|
4174
4854
|
() => schemaTypes.decorators.map((dec) => dec.value),
|
|
4175
4855
|
[schemaTypes.decorators]
|
|
4176
4856
|
), marks = react.useMemo(
|
|
4177
|
-
() => uniq__default.default(
|
|
4857
|
+
() => uniq__default.default(
|
|
4858
|
+
(leaf.marks || EMPTY_MARKS).filter(
|
|
4859
|
+
(mark) => decoratorValues.includes(mark)
|
|
4860
|
+
)
|
|
4861
|
+
),
|
|
4178
4862
|
[decoratorValues, leaf.marks]
|
|
4179
4863
|
), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = react.useMemo(
|
|
4180
4864
|
() => annotationMarks.map(
|
|
@@ -4225,11 +4909,18 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4225
4909
|
return () => {
|
|
4226
4910
|
sub.unsubscribe();
|
|
4227
4911
|
};
|
|
4228
|
-
}, [
|
|
4912
|
+
}, [
|
|
4913
|
+
path,
|
|
4914
|
+
portableTextEditor,
|
|
4915
|
+
setSelectedFromRange,
|
|
4916
|
+
shouldTrackSelectionAndFocus
|
|
4917
|
+
]), react.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
|
|
4229
4918
|
const content2 = react.useMemo(() => {
|
|
4230
4919
|
let returnedChildren = children;
|
|
4231
4920
|
if (slate.Text.isText(leaf) && leaf._type === schemaTypes.span.name && (marks.forEach((mark) => {
|
|
4232
|
-
const schemaType = schemaTypes.decorators.find(
|
|
4921
|
+
const schemaType = schemaTypes.decorators.find(
|
|
4922
|
+
(dec) => dec.value === mark
|
|
4923
|
+
);
|
|
4233
4924
|
if (schemaType && renderDecorator) {
|
|
4234
4925
|
const _props = Object.defineProperty(
|
|
4235
4926
|
{
|
|
@@ -4245,14 +4936,20 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4245
4936
|
{
|
|
4246
4937
|
enumerable: !1,
|
|
4247
4938
|
get() {
|
|
4248
|
-
return console.warn(
|
|
4939
|
+
return console.warn(
|
|
4940
|
+
"Property 'type' is deprecated, use 'schemaType' instead."
|
|
4941
|
+
), schemaType;
|
|
4249
4942
|
}
|
|
4250
4943
|
}
|
|
4251
4944
|
);
|
|
4252
|
-
returnedChildren = renderDecorator(
|
|
4945
|
+
returnedChildren = renderDecorator(
|
|
4946
|
+
_props
|
|
4947
|
+
);
|
|
4253
4948
|
}
|
|
4254
4949
|
}), block && annotations.length > 0 && annotations.forEach((annotation) => {
|
|
4255
|
-
const schemaType = schemaTypes.annotations.find(
|
|
4950
|
+
const schemaType = schemaTypes.annotations.find(
|
|
4951
|
+
(t) => t.name === annotation._type
|
|
4952
|
+
);
|
|
4256
4953
|
if (schemaType)
|
|
4257
4954
|
if (renderAnnotation) {
|
|
4258
4955
|
const _props = Object.defineProperty(
|
|
@@ -4270,7 +4967,9 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4270
4967
|
{
|
|
4271
4968
|
enumerable: !1,
|
|
4272
4969
|
get() {
|
|
4273
|
-
return console.warn(
|
|
4970
|
+
return console.warn(
|
|
4971
|
+
"Property 'type' is deprecated, use 'schemaType' instead."
|
|
4972
|
+
), schemaType;
|
|
4274
4973
|
}
|
|
4275
4974
|
}
|
|
4276
4975
|
);
|
|
@@ -4295,7 +4994,9 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4295
4994
|
{
|
|
4296
4995
|
enumerable: !1,
|
|
4297
4996
|
get() {
|
|
4298
|
-
return console.warn(
|
|
4997
|
+
return console.warn(
|
|
4998
|
+
"Property 'type' is deprecated, use 'schemaType' instead."
|
|
4999
|
+
), schemaTypes.span;
|
|
4299
5000
|
}
|
|
4300
5001
|
}
|
|
4301
5002
|
);
|
|
@@ -4350,8 +5051,13 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4350
5051
|
scrollSelectionIntoView,
|
|
4351
5052
|
spellCheck,
|
|
4352
5053
|
...restProps
|
|
4353
|
-
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), keyGenerator = usePortableTextEditorKeyGenerator(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(
|
|
4354
|
-
|
|
5054
|
+
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), keyGenerator = usePortableTextEditorKeyGenerator(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(
|
|
5055
|
+
null
|
|
5056
|
+
), [hasInvalidValue, setHasInvalidValue] = react.useState(!1), [rangeDecorationState, setRangeDecorationsState] = react.useState([]);
|
|
5057
|
+
react.useImperativeHandle(
|
|
5058
|
+
forwardedRef,
|
|
5059
|
+
() => ref.current
|
|
5060
|
+
);
|
|
4355
5061
|
const rangeDecorationsRef = react.useRef(rangeDecorations), { change$, schemaTypes } = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = react.useMemo(
|
|
4356
5062
|
() => createWithInsertData(change$, schemaTypes, keyGenerator),
|
|
4357
5063
|
[change$, keyGenerator, schemaTypes]
|
|
@@ -4374,7 +5080,15 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4374
5080
|
spellCheck
|
|
4375
5081
|
}
|
|
4376
5082
|
),
|
|
4377
|
-
[
|
|
5083
|
+
[
|
|
5084
|
+
schemaTypes,
|
|
5085
|
+
spellCheck,
|
|
5086
|
+
readOnly,
|
|
5087
|
+
renderBlock,
|
|
5088
|
+
renderChild,
|
|
5089
|
+
renderListItem,
|
|
5090
|
+
renderStyle
|
|
5091
|
+
]
|
|
4378
5092
|
), renderLeaf = react.useCallback(
|
|
4379
5093
|
(lProps) => {
|
|
4380
5094
|
if (lProps.leaf._type === "span") {
|
|
@@ -4399,7 +5113,14 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4399
5113
|
}
|
|
4400
5114
|
return lProps.children;
|
|
4401
5115
|
},
|
|
4402
|
-
[
|
|
5116
|
+
[
|
|
5117
|
+
readOnly,
|
|
5118
|
+
renderAnnotation,
|
|
5119
|
+
renderChild,
|
|
5120
|
+
renderDecorator,
|
|
5121
|
+
renderPlaceholder,
|
|
5122
|
+
schemaTypes
|
|
5123
|
+
]
|
|
4403
5124
|
), restoreSelectionFromProps = react.useCallback(() => {
|
|
4404
5125
|
if (propsSelection) {
|
|
4405
5126
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
@@ -4408,7 +5129,9 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4408
5129
|
fromSlateValue(slateEditor.children, blockTypeName)
|
|
4409
5130
|
);
|
|
4410
5131
|
if (normalizedSelection !== null) {
|
|
4411
|
-
debug(
|
|
5132
|
+
debug(
|
|
5133
|
+
`Normalized selection from props ${JSON.stringify(normalizedSelection)}`
|
|
5134
|
+
);
|
|
4412
5135
|
const slateRange = toSlateRange(normalizedSelection, slateEditor);
|
|
4413
5136
|
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || change$.next({ type: "selection", selection: normalizedSelection }), slateEditor.onChange());
|
|
4414
5137
|
}
|
|
@@ -4418,7 +5141,10 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4418
5141
|
if (rangeDecorations && rangeDecorations.length > 0) {
|
|
4419
5142
|
const newSlateRanges = [];
|
|
4420
5143
|
if (rangeDecorations.forEach((rangeDecorationItem) => {
|
|
4421
|
-
const slateRange = toSlateRange(
|
|
5144
|
+
const slateRange = toSlateRange(
|
|
5145
|
+
rangeDecorationItem.selection,
|
|
5146
|
+
slateEditor
|
|
5147
|
+
);
|
|
4422
5148
|
if (!slate.Range.isRange(slateRange)) {
|
|
4423
5149
|
rangeDecorationItem.onMoved && rangeDecorationItem.onMoved({
|
|
4424
5150
|
newSelection: null,
|
|
@@ -4429,14 +5155,21 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4429
5155
|
}
|
|
4430
5156
|
let newRange;
|
|
4431
5157
|
if (operation && (newRange = moveRangeByOperation(slateRange, operation), newRange && newRange !== slateRange || newRange === null && slateRange)) {
|
|
4432
|
-
const value = PortableTextEditor.getValue(portableTextEditor), newRangeSelection = toPortableTextRange(
|
|
5158
|
+
const value = PortableTextEditor.getValue(portableTextEditor), newRangeSelection = toPortableTextRange(
|
|
5159
|
+
value,
|
|
5160
|
+
newRange,
|
|
5161
|
+
schemaTypes
|
|
5162
|
+
);
|
|
4433
5163
|
rangeDecorationItem.onMoved && rangeDecorationItem.onMoved({
|
|
4434
5164
|
newSelection: newRangeSelection,
|
|
4435
5165
|
rangeDecoration: rangeDecorationItem,
|
|
4436
5166
|
origin: "local"
|
|
4437
5167
|
});
|
|
4438
5168
|
}
|
|
4439
|
-
newRange !== null && newSlateRanges.push({
|
|
5169
|
+
newRange !== null && newSlateRanges.push({
|
|
5170
|
+
...newRange || slateRange,
|
|
5171
|
+
rangeDecoration: rangeDecorationItem
|
|
5172
|
+
});
|
|
4440
5173
|
}), newSlateRanges.length > 0) {
|
|
4441
5174
|
setRangeDecorationsState(newSlateRanges);
|
|
4442
5175
|
return;
|
|
@@ -4489,11 +5222,20 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4489
5222
|
debug("Pasting normally"), slateEditor.insertData(event.clipboardData);
|
|
4490
5223
|
return;
|
|
4491
5224
|
}
|
|
4492
|
-
const value = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(
|
|
5225
|
+
const value = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(
|
|
5226
|
+
value,
|
|
5227
|
+
slateEditor.selection,
|
|
5228
|
+
schemaTypes
|
|
5229
|
+
)?.focus.path || [], onPasteResult = onPaste({ event, value, path, schemaTypes });
|
|
4493
5230
|
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) => {
|
|
4494
5231
|
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(
|
|
4495
|
-
toSlateValue(result.insert, {
|
|
4496
|
-
|
|
5232
|
+
toSlateValue(result.insert, {
|
|
5233
|
+
schemaTypes
|
|
5234
|
+
})
|
|
5235
|
+
) : console.warn(
|
|
5236
|
+
"Your onPaste function returned something unexpected:",
|
|
5237
|
+
result
|
|
5238
|
+
);
|
|
4497
5239
|
}).catch((error) => (console.error(error), error)).finally(() => {
|
|
4498
5240
|
change$.next({ type: "loading", isLoading: !1 });
|
|
4499
5241
|
}));
|
|
@@ -4518,7 +5260,10 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4518
5260
|
const [lastBlock, path] = slate.Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path.slice(0, 1);
|
|
4519
5261
|
if (slate.Path.equals(focusPath, lastPath)) {
|
|
4520
5262
|
const node = slate.Node.descendant(slateEditor, path.slice(0, 1));
|
|
4521
|
-
lastBlock && slate.Editor.isVoid(slateEditor, node) && (slate.Transforms.insertNodes(
|
|
5263
|
+
lastBlock && slate.Editor.isVoid(slateEditor, node) && (slate.Transforms.insertNodes(
|
|
5264
|
+
slateEditor,
|
|
5265
|
+
slateEditor.pteCreateTextBlock({ decorators: [] })
|
|
5266
|
+
), slateEditor.onChange());
|
|
4522
5267
|
}
|
|
4523
5268
|
}
|
|
4524
5269
|
},
|
|
@@ -4544,7 +5289,10 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4544
5289
|
return;
|
|
4545
5290
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
4546
5291
|
try {
|
|
4547
|
-
const newDOMRange = slateReact.ReactEditor.toDOMRange(
|
|
5292
|
+
const newDOMRange = slateReact.ReactEditor.toDOMRange(
|
|
5293
|
+
slateEditor,
|
|
5294
|
+
slateEditor.selection
|
|
5295
|
+
);
|
|
4548
5296
|
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
4549
5297
|
} catch {
|
|
4550
5298
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
@@ -4592,13 +5340,19 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
4592
5340
|
];
|
|
4593
5341
|
if (path.length === 0)
|
|
4594
5342
|
return [];
|
|
4595
|
-
const result = rangeDecorationState.filter((item) => slate.Range.isCollapsed(item) ? path.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path) && slate.Path.equals(item.anchor.path, path) : slate.Range.intersection(item, {
|
|
5343
|
+
const result = rangeDecorationState.filter((item) => slate.Range.isCollapsed(item) ? path.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path) && slate.Path.equals(item.anchor.path, path) : slate.Range.intersection(item, {
|
|
5344
|
+
anchor: { path, offset: 0 },
|
|
5345
|
+
focus: { path, offset: 0 }
|
|
5346
|
+
}) || slate.Range.includes(item, path));
|
|
4596
5347
|
return result.length > 0 ? result : [];
|
|
4597
5348
|
},
|
|
4598
5349
|
[slateEditor, schemaTypes, rangeDecorationState]
|
|
4599
5350
|
);
|
|
4600
5351
|
return react.useEffect(() => {
|
|
4601
|
-
ref.current = slateReact.ReactEditor.toDOMNode(
|
|
5352
|
+
ref.current = slateReact.ReactEditor.toDOMNode(
|
|
5353
|
+
slateEditor,
|
|
5354
|
+
slateEditor
|
|
5355
|
+
), setEditableElement(ref.current);
|
|
4602
5356
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4603
5357
|
slateReact.Editable,
|
|
4604
5358
|
{
|