@portabletext/editor 1.1.10 → 1.1.11
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 +203 -1031
- package/lib/index.d.ts +203 -1031
- package/lib/index.esm.js +291 -198
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +288 -195
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +291 -198
- package/lib/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/editor/behavior/behavior.action.insert-break.ts +206 -0
- package/src/editor/behavior/behavior.actions.ts +90 -33
- package/src/editor/behavior/behavior.core.ts +2 -2
- package/src/editor/behavior/behavior.types.ts +30 -15
- package/src/editor/editor-machine.ts +106 -34
- package/src/editor/plugins/create-with-event-listeners.ts +1 -6
- package/src/editor/plugins/index.ts +2 -9
- package/src/index.ts +1 -1
- package/src/editor/plugins/createWithInsertBreak.ts +0 -224
package/lib/index.js
CHANGED
|
@@ -801,12 +801,12 @@ function getFocusBlockObject(context) {
|
|
|
801
801
|
}
|
|
802
802
|
const softReturn = {
|
|
803
803
|
on: "insert soft break",
|
|
804
|
-
actions: [() =>
|
|
805
|
-
` }
|
|
804
|
+
actions: [() => [{ type: "insert text", text: `
|
|
805
|
+
` }]]
|
|
806
806
|
}, breakingVoidBlock = {
|
|
807
807
|
on: "insert break",
|
|
808
808
|
guard: ({ context }) => !!getFocusBlockObject(context),
|
|
809
|
-
actions: [() =>
|
|
809
|
+
actions: [() => [{ type: "insert text block", decorators: [] }]]
|
|
810
810
|
}, coreBehaviors = [softReturn, breakingVoidBlock], debug$k = debugWithName("operationToPatches");
|
|
811
811
|
function createOperationToPatches(types2) {
|
|
812
812
|
const textBlockName = types2.block.name;
|
|
@@ -1084,14 +1084,12 @@ function createOperationToPatches(types2) {
|
|
|
1084
1084
|
}
|
|
1085
1085
|
function createWithEventListeners(editorActor) {
|
|
1086
1086
|
return function(editor) {
|
|
1087
|
-
const { deleteBackward, insertBreak, insertSoftBreak, insertText } = editor;
|
|
1088
1087
|
return editor.deleteBackward = (unit) => {
|
|
1089
1088
|
editorActor.send({
|
|
1090
1089
|
type: "behavior event",
|
|
1091
1090
|
behaviorEvent: {
|
|
1092
1091
|
type: "delete backward",
|
|
1093
|
-
unit
|
|
1094
|
-
default: () => deleteBackward(unit)
|
|
1092
|
+
unit
|
|
1095
1093
|
},
|
|
1096
1094
|
editor
|
|
1097
1095
|
});
|
|
@@ -1099,8 +1097,7 @@ function createWithEventListeners(editorActor) {
|
|
|
1099
1097
|
editorActor.send({
|
|
1100
1098
|
type: "behavior event",
|
|
1101
1099
|
behaviorEvent: {
|
|
1102
|
-
type: "insert break"
|
|
1103
|
-
default: insertBreak
|
|
1100
|
+
type: "insert break"
|
|
1104
1101
|
},
|
|
1105
1102
|
editor
|
|
1106
1103
|
});
|
|
@@ -1108,8 +1105,7 @@ function createWithEventListeners(editorActor) {
|
|
|
1108
1105
|
editorActor.send({
|
|
1109
1106
|
type: "behavior event",
|
|
1110
1107
|
behaviorEvent: {
|
|
1111
|
-
type: "insert soft break"
|
|
1112
|
-
default: insertSoftBreak
|
|
1108
|
+
type: "insert soft break"
|
|
1113
1109
|
},
|
|
1114
1110
|
editor
|
|
1115
1111
|
});
|
|
@@ -1119,7 +1115,7 @@ function createWithEventListeners(editorActor) {
|
|
|
1119
1115
|
behaviorEvent: {
|
|
1120
1116
|
type: "insert text",
|
|
1121
1117
|
text,
|
|
1122
|
-
|
|
1118
|
+
options
|
|
1123
1119
|
},
|
|
1124
1120
|
editor
|
|
1125
1121
|
});
|
|
@@ -1612,131 +1608,6 @@ function createWithEditableAPI(editorActor, portableTextEditor, types$1) {
|
|
|
1612
1608
|
}), editor;
|
|
1613
1609
|
};
|
|
1614
1610
|
}
|
|
1615
|
-
function createWithInsertBreak(editorActor, types2) {
|
|
1616
|
-
return function(editor) {
|
|
1617
|
-
const { insertBreak } = editor;
|
|
1618
|
-
return editor.insertBreak = () => {
|
|
1619
|
-
if (!editor.selection) {
|
|
1620
|
-
insertBreak();
|
|
1621
|
-
return;
|
|
1622
|
-
}
|
|
1623
|
-
const [focusSpan] = Array.from(
|
|
1624
|
-
slate.Editor.nodes(editor, {
|
|
1625
|
-
mode: "lowest",
|
|
1626
|
-
at: editor.selection.focus,
|
|
1627
|
-
match: (n) => editor.isTextSpan(n),
|
|
1628
|
-
voids: !1
|
|
1629
|
-
})
|
|
1630
|
-
)[0] ?? [void 0], focusDecorators = focusSpan.marks?.filter(
|
|
1631
|
-
(mark) => types2.decorators.some((decorator) => decorator.value === mark)
|
|
1632
|
-
) ?? [], focusAnnotations = focusSpan.marks?.filter(
|
|
1633
|
-
(mark) => !types2.decorators.some((decorator) => decorator.value === mark)
|
|
1634
|
-
) ?? [], focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
1635
|
-
if (editor.isTextBlock(focusBlock)) {
|
|
1636
|
-
const [start, end] = slate.Range.edges(editor.selection), atTheStartOfBlock = isEqual__default.default(end, {
|
|
1637
|
-
path: [...focusBlockPath, 0],
|
|
1638
|
-
offset: 0
|
|
1639
|
-
});
|
|
1640
|
-
if (atTheStartOfBlock && slate.Range.isCollapsed(editor.selection)) {
|
|
1641
|
-
slate.Editor.insertNode(
|
|
1642
|
-
editor,
|
|
1643
|
-
editor.pteCreateTextBlock({
|
|
1644
|
-
decorators: focusAnnotations.length === 0 ? focusDecorators : [],
|
|
1645
|
-
listItem: focusBlock.listItem,
|
|
1646
|
-
level: focusBlock.level
|
|
1647
|
-
})
|
|
1648
|
-
);
|
|
1649
|
-
const [nextBlockPath] = slate.Path.next(focusBlockPath);
|
|
1650
|
-
slate.Transforms.select(editor, {
|
|
1651
|
-
anchor: { path: [nextBlockPath, 0], offset: 0 },
|
|
1652
|
-
focus: { path: [nextBlockPath, 0], offset: 0 }
|
|
1653
|
-
});
|
|
1654
|
-
return;
|
|
1655
|
-
}
|
|
1656
|
-
const lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
|
|
1657
|
-
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
1658
|
-
offset: editor.isTextSpan(lastFocusBlockChild) ? lastFocusBlockChild.text.length : 0
|
|
1659
|
-
});
|
|
1660
|
-
if (atTheEndOfBlock && slate.Range.isCollapsed(editor.selection)) {
|
|
1661
|
-
slate.Editor.insertNode(
|
|
1662
|
-
editor,
|
|
1663
|
-
editor.pteCreateTextBlock({
|
|
1664
|
-
decorators: [],
|
|
1665
|
-
listItem: focusBlock.listItem,
|
|
1666
|
-
level: focusBlock.level
|
|
1667
|
-
})
|
|
1668
|
-
);
|
|
1669
|
-
const [nextBlockPath] = slate.Path.next(focusBlockPath);
|
|
1670
|
-
slate.Transforms.setSelection(editor, {
|
|
1671
|
-
anchor: { path: [nextBlockPath, 0], offset: 0 },
|
|
1672
|
-
focus: { path: [nextBlockPath, 0], offset: 0 }
|
|
1673
|
-
});
|
|
1674
|
-
return;
|
|
1675
|
-
}
|
|
1676
|
-
if (!atTheStartOfBlock && !atTheEndOfBlock) {
|
|
1677
|
-
slate.Editor.withoutNormalizing(editor, () => {
|
|
1678
|
-
if (!editor.selection)
|
|
1679
|
-
return;
|
|
1680
|
-
slate.Transforms.splitNodes(editor, {
|
|
1681
|
-
at: editor.selection
|
|
1682
|
-
});
|
|
1683
|
-
const [nextNode, nextNodePath] = slate.Editor.node(
|
|
1684
|
-
editor,
|
|
1685
|
-
slate.Path.next(focusBlockPath),
|
|
1686
|
-
{ depth: 1 }
|
|
1687
|
-
);
|
|
1688
|
-
if (slate.Transforms.setSelection(editor, {
|
|
1689
|
-
anchor: { path: [...nextNodePath, 0], offset: 0 },
|
|
1690
|
-
focus: { path: [...nextNodePath, 0], offset: 0 }
|
|
1691
|
-
}), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
|
|
1692
|
-
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(
|
|
1693
|
-
slate.Node.children(editor, focusBlockPath)
|
|
1694
|
-
).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextNodePath);
|
|
1695
|
-
for (const [child, childPath] of children) {
|
|
1696
|
-
if (!editor.isTextSpan(child))
|
|
1697
|
-
continue;
|
|
1698
|
-
const marks = child.marks ?? [];
|
|
1699
|
-
for (const mark of marks)
|
|
1700
|
-
types2.decorators.some(
|
|
1701
|
-
(decorator) => decorator.value === mark
|
|
1702
|
-
) || prevNodeSpans.some(
|
|
1703
|
-
(prevNodeSpan) => prevNodeSpan.marks?.includes(mark)
|
|
1704
|
-
) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(
|
|
1705
|
-
mark,
|
|
1706
|
-
editorActor.getSnapshot().context.keyGenerator()
|
|
1707
|
-
);
|
|
1708
|
-
const newMarks = marks.map(
|
|
1709
|
-
(mark) => newMarkDefKeys.get(mark) ?? mark
|
|
1710
|
-
);
|
|
1711
|
-
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(
|
|
1712
|
-
editor,
|
|
1713
|
-
{ marks: newMarks },
|
|
1714
|
-
{
|
|
1715
|
-
at: childPath
|
|
1716
|
-
}
|
|
1717
|
-
);
|
|
1718
|
-
}
|
|
1719
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
1720
|
-
...markDef,
|
|
1721
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
1722
|
-
}));
|
|
1723
|
-
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(
|
|
1724
|
-
editor,
|
|
1725
|
-
{ markDefs: newMarkDefs },
|
|
1726
|
-
{
|
|
1727
|
-
at: nextNodePath,
|
|
1728
|
-
match: (node) => editor.isTextBlock(node)
|
|
1729
|
-
}
|
|
1730
|
-
);
|
|
1731
|
-
}
|
|
1732
|
-
}), editor.onChange();
|
|
1733
|
-
return;
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
insertBreak();
|
|
1737
|
-
}, editor;
|
|
1738
|
-
};
|
|
1739
|
-
}
|
|
1740
1611
|
function withRemoteChanges(editor, fn) {
|
|
1741
1612
|
const prev = isChangingRemotely(editor) || !1;
|
|
1742
1613
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
@@ -4442,7 +4313,7 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4442
4313
|
), withPortableTextBlockStyle = createWithPortableTextBlockStyle(
|
|
4443
4314
|
editorActor,
|
|
4444
4315
|
schemaTypes
|
|
4445
|
-
), withPlaceholderBlock = createWithPlaceholderBlock(),
|
|
4316
|
+
), withPlaceholderBlock = createWithPlaceholderBlock(), withUtils = createWithUtils({
|
|
4446
4317
|
editorActor,
|
|
4447
4318
|
schemaTypes,
|
|
4448
4319
|
portableTextEditor
|
|
@@ -4463,9 +4334,7 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4463
4334
|
withUtils(
|
|
4464
4335
|
withPlaceholderBlock(
|
|
4465
4336
|
withPortableTextLists(
|
|
4466
|
-
withPortableTextSelections(
|
|
4467
|
-
withEditableAPI(withInsertBreak(e))
|
|
4468
|
-
)
|
|
4337
|
+
withPortableTextSelections(withEditableAPI(e))
|
|
4469
4338
|
)
|
|
4470
4339
|
)
|
|
4471
4340
|
)
|
|
@@ -4486,9 +4355,7 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4486
4355
|
withMaxBlocks(
|
|
4487
4356
|
withUndoRedo(
|
|
4488
4357
|
withPatches(
|
|
4489
|
-
withPortableTextSelections(
|
|
4490
|
-
withEditableAPI(withInsertBreak(e))
|
|
4491
|
-
)
|
|
4358
|
+
withPortableTextSelections(withEditableAPI(e))
|
|
4492
4359
|
)
|
|
4493
4360
|
)
|
|
4494
4361
|
)
|
|
@@ -4859,35 +4726,162 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4859
4726
|
debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({ type: "ready" }), isInitialValueFromProps.current = !1);
|
|
4860
4727
|
}, [editorActor, syncValue, value]), null;
|
|
4861
4728
|
}
|
|
4862
|
-
const EditorActorContext = react.createContext({}),
|
|
4863
|
-
|
|
4864
|
-
|
|
4729
|
+
const EditorActorContext = react.createContext({}), insertBreakActionImplementation = ({ context, action }) => {
|
|
4730
|
+
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
4731
|
+
if (!editor.selection)
|
|
4732
|
+
return;
|
|
4733
|
+
const [focusSpan] = Array.from(
|
|
4734
|
+
slate.Editor.nodes(editor, {
|
|
4735
|
+
mode: "lowest",
|
|
4736
|
+
at: editor.selection.focus,
|
|
4737
|
+
match: (n) => editor.isTextSpan(n),
|
|
4738
|
+
voids: !1
|
|
4739
|
+
})
|
|
4740
|
+
)[0] ?? [void 0], focusDecorators = focusSpan.marks?.filter(
|
|
4741
|
+
(mark) => schema2.decorators.some((decorator) => decorator.value === mark)
|
|
4742
|
+
) ?? [], focusAnnotations = focusSpan.marks?.filter(
|
|
4743
|
+
(mark) => !schema2.decorators.some((decorator) => decorator.value === mark)
|
|
4744
|
+
) ?? [], focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
4745
|
+
if (editor.isTextBlock(focusBlock)) {
|
|
4746
|
+
const [start, end] = slate.Range.edges(editor.selection), atTheStartOfBlock = isEqual__default.default(end, {
|
|
4747
|
+
path: [...focusBlockPath, 0],
|
|
4748
|
+
offset: 0
|
|
4749
|
+
});
|
|
4750
|
+
if (atTheStartOfBlock && slate.Range.isCollapsed(editor.selection)) {
|
|
4751
|
+
slate.Editor.insertNode(
|
|
4752
|
+
editor,
|
|
4753
|
+
editor.pteCreateTextBlock({
|
|
4754
|
+
decorators: focusAnnotations.length === 0 ? focusDecorators : [],
|
|
4755
|
+
listItem: focusBlock.listItem,
|
|
4756
|
+
level: focusBlock.level
|
|
4757
|
+
})
|
|
4758
|
+
);
|
|
4759
|
+
const [nextBlockPath] = slate.Path.next(focusBlockPath);
|
|
4760
|
+
slate.Transforms.select(editor, {
|
|
4761
|
+
anchor: { path: [nextBlockPath, 0], offset: 0 },
|
|
4762
|
+
focus: { path: [nextBlockPath, 0], offset: 0 }
|
|
4763
|
+
});
|
|
4764
|
+
return;
|
|
4765
|
+
}
|
|
4766
|
+
const lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
|
|
4767
|
+
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
4768
|
+
offset: editor.isTextSpan(lastFocusBlockChild) ? lastFocusBlockChild.text.length : 0
|
|
4769
|
+
});
|
|
4770
|
+
if (atTheEndOfBlock && slate.Range.isCollapsed(editor.selection)) {
|
|
4771
|
+
slate.Editor.insertNode(
|
|
4772
|
+
editor,
|
|
4773
|
+
editor.pteCreateTextBlock({
|
|
4774
|
+
decorators: [],
|
|
4775
|
+
listItem: focusBlock.listItem,
|
|
4776
|
+
level: focusBlock.level
|
|
4777
|
+
})
|
|
4778
|
+
);
|
|
4779
|
+
const [nextBlockPath] = slate.Path.next(focusBlockPath);
|
|
4780
|
+
slate.Transforms.setSelection(editor, {
|
|
4781
|
+
anchor: { path: [nextBlockPath, 0], offset: 0 },
|
|
4782
|
+
focus: { path: [nextBlockPath, 0], offset: 0 }
|
|
4783
|
+
});
|
|
4784
|
+
return;
|
|
4785
|
+
}
|
|
4786
|
+
if (!atTheStartOfBlock && !atTheEndOfBlock) {
|
|
4787
|
+
slate.Editor.withoutNormalizing(editor, () => {
|
|
4788
|
+
if (!editor.selection)
|
|
4789
|
+
return;
|
|
4790
|
+
slate.Transforms.splitNodes(editor, {
|
|
4791
|
+
at: editor.selection
|
|
4792
|
+
});
|
|
4793
|
+
const [nextNode, nextNodePath] = slate.Editor.node(
|
|
4794
|
+
editor,
|
|
4795
|
+
slate.Path.next(focusBlockPath),
|
|
4796
|
+
{ depth: 1 }
|
|
4797
|
+
);
|
|
4798
|
+
if (slate.Transforms.setSelection(editor, {
|
|
4799
|
+
anchor: { path: [...nextNodePath, 0], offset: 0 },
|
|
4800
|
+
focus: { path: [...nextNodePath, 0], offset: 0 }
|
|
4801
|
+
}), editor.isTextBlock(nextNode) && nextNode.markDefs && nextNode.markDefs.length > 0) {
|
|
4802
|
+
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(
|
|
4803
|
+
slate.Node.children(editor, focusBlockPath)
|
|
4804
|
+
).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextNodePath);
|
|
4805
|
+
for (const [child, childPath] of children) {
|
|
4806
|
+
if (!editor.isTextSpan(child))
|
|
4807
|
+
continue;
|
|
4808
|
+
const marks = child.marks ?? [];
|
|
4809
|
+
for (const mark of marks)
|
|
4810
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some(
|
|
4811
|
+
(prevNodeSpan) => prevNodeSpan.marks?.includes(mark)
|
|
4812
|
+
) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4813
|
+
const newMarks = marks.map(
|
|
4814
|
+
(mark) => newMarkDefKeys.get(mark) ?? mark
|
|
4815
|
+
);
|
|
4816
|
+
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(
|
|
4817
|
+
editor,
|
|
4818
|
+
{ marks: newMarks },
|
|
4819
|
+
{
|
|
4820
|
+
at: childPath
|
|
4821
|
+
}
|
|
4822
|
+
);
|
|
4823
|
+
}
|
|
4824
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => ({
|
|
4825
|
+
...markDef,
|
|
4826
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4827
|
+
}));
|
|
4828
|
+
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(
|
|
4829
|
+
editor,
|
|
4830
|
+
{ markDefs: newMarkDefs },
|
|
4831
|
+
{
|
|
4832
|
+
at: nextNodePath,
|
|
4833
|
+
match: (node) => editor.isTextBlock(node)
|
|
4834
|
+
}
|
|
4835
|
+
);
|
|
4836
|
+
}
|
|
4837
|
+
}), editor.onChange();
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
}, behaviorActionImplementations = {
|
|
4842
|
+
"set block": ({ action }) => {
|
|
4843
|
+
for (const path of action.paths) {
|
|
4865
4844
|
const at = toSlateRange(
|
|
4866
4845
|
{ anchor: { path, offset: 0 }, focus: { path, offset: 0 } },
|
|
4867
|
-
|
|
4846
|
+
action.editor
|
|
4847
|
+
);
|
|
4848
|
+
slate.Transforms.setNodes(
|
|
4849
|
+
action.editor,
|
|
4850
|
+
{
|
|
4851
|
+
...action.style ? { style: action.style } : {},
|
|
4852
|
+
...action.listItem ? { listItem: action.listItem } : {},
|
|
4853
|
+
...action.level ? { level: action.level } : {}
|
|
4854
|
+
},
|
|
4855
|
+
{ at }
|
|
4868
4856
|
);
|
|
4869
|
-
slate.Transforms.setNodes(event.editor, { style: event.style }, { at });
|
|
4870
4857
|
}
|
|
4871
4858
|
},
|
|
4872
|
-
"
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4859
|
+
"unset block": ({ action }) => {
|
|
4860
|
+
for (const path of action.paths) {
|
|
4861
|
+
const at = toSlateRange(
|
|
4862
|
+
{ anchor: { path, offset: 0 }, focus: { path, offset: 0 } },
|
|
4863
|
+
action.editor
|
|
4864
|
+
);
|
|
4865
|
+
slate.Transforms.unsetNodes(action.editor, action.props, { at });
|
|
4866
|
+
}
|
|
4879
4867
|
},
|
|
4880
|
-
"
|
|
4881
|
-
slate.
|
|
4868
|
+
"delete backward": ({ action }) => {
|
|
4869
|
+
slate.deleteBackward(action.editor, action.unit);
|
|
4882
4870
|
},
|
|
4883
|
-
"
|
|
4884
|
-
slate.
|
|
4871
|
+
"delete text": ({ action }) => {
|
|
4872
|
+
slate.Transforms.delete(action.editor, {
|
|
4873
|
+
at: toSlateRange(action.selection, action.editor)
|
|
4874
|
+
});
|
|
4885
4875
|
},
|
|
4886
|
-
"insert
|
|
4887
|
-
|
|
4876
|
+
"insert break": insertBreakActionImplementation,
|
|
4877
|
+
// This mimics Slate's internal which also just does a regular insert break
|
|
4878
|
+
// when on soft break
|
|
4879
|
+
"insert soft break": insertBreakActionImplementation,
|
|
4880
|
+
"insert text": ({ action }) => {
|
|
4881
|
+
slate.insertText(action.editor, action.text);
|
|
4888
4882
|
},
|
|
4889
|
-
"insert text block": ({ context,
|
|
4890
|
-
slate.Editor.insertNode(
|
|
4883
|
+
"insert text block": ({ context, action }) => {
|
|
4884
|
+
slate.Editor.insertNode(action.editor, {
|
|
4891
4885
|
_key: context.keyGenerator(),
|
|
4892
4886
|
_type: context.schema.block.name,
|
|
4893
4887
|
style: context.schema.styles[0].value ?? "normal",
|
|
@@ -4900,8 +4894,47 @@ const EditorActorContext = react.createContext({}), behaviorActionImplementation
|
|
|
4900
4894
|
}
|
|
4901
4895
|
]
|
|
4902
4896
|
});
|
|
4897
|
+
},
|
|
4898
|
+
effect: ({ action }) => {
|
|
4899
|
+
action.effect();
|
|
4900
|
+
}
|
|
4901
|
+
};
|
|
4902
|
+
function performDefaultAction({
|
|
4903
|
+
context,
|
|
4904
|
+
action
|
|
4905
|
+
}) {
|
|
4906
|
+
switch (action.type) {
|
|
4907
|
+
case "delete backward": {
|
|
4908
|
+
behaviorActionImplementations["delete backward"]({
|
|
4909
|
+
context,
|
|
4910
|
+
action
|
|
4911
|
+
});
|
|
4912
|
+
break;
|
|
4913
|
+
}
|
|
4914
|
+
case "insert break": {
|
|
4915
|
+
behaviorActionImplementations["insert break"]({
|
|
4916
|
+
context,
|
|
4917
|
+
action
|
|
4918
|
+
});
|
|
4919
|
+
break;
|
|
4920
|
+
}
|
|
4921
|
+
case "insert soft break": {
|
|
4922
|
+
behaviorActionImplementations["insert soft break"]({
|
|
4923
|
+
context,
|
|
4924
|
+
action
|
|
4925
|
+
});
|
|
4926
|
+
break;
|
|
4927
|
+
}
|
|
4928
|
+
case "insert text": {
|
|
4929
|
+
behaviorActionImplementations["insert text"]({
|
|
4930
|
+
context,
|
|
4931
|
+
action
|
|
4932
|
+
});
|
|
4933
|
+
break;
|
|
4934
|
+
}
|
|
4903
4935
|
}
|
|
4904
|
-
}
|
|
4936
|
+
}
|
|
4937
|
+
const networkLogic = xstate.fromCallback(({ sendBack }) => {
|
|
4905
4938
|
const onlineHandler = () => {
|
|
4906
4939
|
sendBack({ type: "online" });
|
|
4907
4940
|
}, offlineHandler = () => {
|
|
@@ -4935,11 +4968,14 @@ const EditorActorContext = react.createContext({}), behaviorActionImplementation
|
|
|
4935
4968
|
}),
|
|
4936
4969
|
"handle behavior event": xstate.enqueueActions(({ context, event, enqueue }) => {
|
|
4937
4970
|
xstate.assertEvent(event, ["behavior event"]);
|
|
4938
|
-
const
|
|
4971
|
+
const defaultAction = {
|
|
4972
|
+
...event.behaviorEvent,
|
|
4973
|
+
editor: event.editor
|
|
4974
|
+
}, eventBehaviors = context.behaviors.filter(
|
|
4939
4975
|
(behavior) => behavior.on === event.behaviorEvent.type
|
|
4940
4976
|
);
|
|
4941
4977
|
if (eventBehaviors.length === 0) {
|
|
4942
|
-
|
|
4978
|
+
performDefaultAction({ context, action: defaultAction });
|
|
4943
4979
|
return;
|
|
4944
4980
|
}
|
|
4945
4981
|
const value = fromSlateValue(
|
|
@@ -4954,7 +4990,7 @@ const EditorActorContext = react.createContext({}), behaviorActionImplementation
|
|
|
4954
4990
|
if (!selection) {
|
|
4955
4991
|
console.warn(
|
|
4956
4992
|
`Unable to handle event ${event.type} due to missing selection`
|
|
4957
|
-
),
|
|
4993
|
+
), performDefaultAction({ context, action: defaultAction });
|
|
4958
4994
|
return;
|
|
4959
4995
|
}
|
|
4960
4996
|
const behaviorContext = {
|
|
@@ -4970,19 +5006,20 @@ const EditorActorContext = react.createContext({}), behaviorActionImplementation
|
|
|
4970
5006
|
}) ?? !0;
|
|
4971
5007
|
if (!shouldRun)
|
|
4972
5008
|
continue;
|
|
4973
|
-
const
|
|
4974
|
-
(
|
|
5009
|
+
const actionIntendSets = eventBehavior.actions.map(
|
|
5010
|
+
(actionSet) => actionSet(
|
|
4975
5011
|
{ context: behaviorContext, event: event.behaviorEvent },
|
|
4976
5012
|
shouldRun
|
|
4977
5013
|
)
|
|
4978
5014
|
);
|
|
4979
|
-
for (const
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
editor: event.editor
|
|
4983
|
-
|
|
5015
|
+
for (const actionIntends of actionIntendSets)
|
|
5016
|
+
behaviorOverwritten = actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
|
|
5017
|
+
type: "behavior action intends",
|
|
5018
|
+
editor: event.editor,
|
|
5019
|
+
actionIntends
|
|
5020
|
+
});
|
|
4984
5021
|
}
|
|
4985
|
-
behaviorOverwritten ||
|
|
5022
|
+
behaviorOverwritten || performDefaultAction({ context, action: defaultAction });
|
|
4986
5023
|
})
|
|
4987
5024
|
},
|
|
4988
5025
|
actors: {
|
|
@@ -5015,26 +5052,82 @@ const EditorActorContext = react.createContext({}), behaviorActionImplementation
|
|
|
5015
5052
|
"done loading": { actions: xstate.emit({ type: "done loading" }) },
|
|
5016
5053
|
"update schema": { actions: "assign schema" },
|
|
5017
5054
|
"behavior event": { actions: "handle behavior event" },
|
|
5018
|
-
"
|
|
5019
|
-
actions: [
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5055
|
+
"behavior action intends": {
|
|
5056
|
+
actions: [
|
|
5057
|
+
({ context, event }) => {
|
|
5058
|
+
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
5059
|
+
for (const actionIntend of event.actionIntends) {
|
|
5060
|
+
const action = {
|
|
5061
|
+
...actionIntend,
|
|
5062
|
+
editor: event.editor
|
|
5063
|
+
};
|
|
5064
|
+
switch (action.type) {
|
|
5065
|
+
case "delete backward": {
|
|
5066
|
+
behaviorActionImplementations["delete backward"]({
|
|
5067
|
+
context,
|
|
5068
|
+
action
|
|
5069
|
+
});
|
|
5070
|
+
break;
|
|
5071
|
+
}
|
|
5072
|
+
case "delete text": {
|
|
5073
|
+
behaviorActionImplementations["delete text"]({
|
|
5074
|
+
context,
|
|
5075
|
+
action
|
|
5076
|
+
});
|
|
5077
|
+
break;
|
|
5078
|
+
}
|
|
5079
|
+
case "insert break": {
|
|
5080
|
+
behaviorActionImplementations["insert break"]({
|
|
5081
|
+
context,
|
|
5082
|
+
action
|
|
5083
|
+
});
|
|
5084
|
+
break;
|
|
5085
|
+
}
|
|
5086
|
+
case "insert soft break": {
|
|
5087
|
+
behaviorActionImplementations["insert soft break"]({
|
|
5088
|
+
context,
|
|
5089
|
+
action
|
|
5090
|
+
});
|
|
5091
|
+
break;
|
|
5092
|
+
}
|
|
5093
|
+
case "insert text": {
|
|
5094
|
+
behaviorActionImplementations["insert text"]({
|
|
5095
|
+
context,
|
|
5096
|
+
action
|
|
5097
|
+
});
|
|
5098
|
+
break;
|
|
5099
|
+
}
|
|
5100
|
+
case "insert text block": {
|
|
5101
|
+
behaviorActionImplementations["insert text block"]({
|
|
5102
|
+
context,
|
|
5103
|
+
action
|
|
5104
|
+
});
|
|
5105
|
+
break;
|
|
5106
|
+
}
|
|
5107
|
+
case "set block": {
|
|
5108
|
+
behaviorActionImplementations["set block"]({
|
|
5109
|
+
context,
|
|
5110
|
+
action
|
|
5111
|
+
});
|
|
5112
|
+
break;
|
|
5113
|
+
}
|
|
5114
|
+
case "unset block": {
|
|
5115
|
+
behaviorActionImplementations["unset block"]({
|
|
5116
|
+
context,
|
|
5117
|
+
action
|
|
5118
|
+
});
|
|
5119
|
+
break;
|
|
5120
|
+
}
|
|
5121
|
+
default:
|
|
5122
|
+
behaviorActionImplementations.effect({
|
|
5123
|
+
context,
|
|
5124
|
+
action
|
|
5125
|
+
});
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
}), event.editor.onChange();
|
|
5129
|
+
}
|
|
5130
|
+
]
|
|
5038
5131
|
}
|
|
5039
5132
|
},
|
|
5040
5133
|
initial: "pristine",
|