@portabletext/editor 1.50.3 → 1.50.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +4 -14
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -14
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +10 -1
- package/lib/behaviors/index.d.ts +10 -1
- package/lib/index.cjs +582 -253
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +11 -1
- package/lib/index.d.ts +11 -1
- package/lib/index.js +592 -262
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +10 -1
- package/lib/plugins/index.d.ts +10 -1
- package/lib/selectors/index.d.cts +10 -1
- package/lib/selectors/index.d.ts +10 -1
- package/lib/utils/index.d.cts +10 -1
- package/lib/utils/index.d.ts +10 -1
- package/package.json +4 -3
- package/src/behaviors/behavior.abstract.delete.ts +6 -2
- package/src/behaviors/behavior.abstract.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +22 -22
- package/src/editor/create-slate-editor.tsx +11 -1
- package/src/editor/editor-selector.ts +11 -9
- package/src/editor/editor-snapshot.ts +13 -8
- package/src/editor/get-active-annotations.ts +15 -0
- package/src/editor/get-active-decorators.ts +23 -9
- package/src/editor/plugins/create-with-event-listeners.ts +9 -3
- package/src/editor/plugins/createWithEditableAPI.ts +16 -14
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +26 -190
- package/src/editor/plugins/slate-plugin.update-mark-state.ts +21 -0
- package/src/editor/plugins/slate-plugin.update-value.ts +27 -0
- package/src/editor/plugins/with-plugins.ts +15 -1
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +175 -0
- package/src/internal-utils/apply-operation-to-portable-text.ts +435 -0
- package/src/internal-utils/create-placeholder-block.ts +20 -0
- package/src/internal-utils/create-test-snapshot.ts +2 -1
- package/src/internal-utils/mark-state.ts +172 -0
- package/src/internal-utils/portable-text-node.ts +209 -0
- package/src/internal-utils/slate-utils.ts +44 -0
- package/src/operations/behavior.operation.decorator.add.ts +7 -11
- package/src/operations/behavior.operation.insert.text.ts +48 -8
- package/src/selectors/selector.get-active-annotations.ts +2 -1
- package/src/selectors/selector.is-active-annotation.ts +7 -39
- package/src/selectors/selector.is-active-decorator.ts +1 -1
- package/src/types/editor.ts +4 -0
- package/src/editor/get-value.ts +0 -18
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -312
- package/src/internal-utils/slate-children-to-blocks.ts +0 -49
- package/src/selectors/selector.get-active-annotations.test.ts +0 -141
package/lib/index.js
CHANGED
|
@@ -9,9 +9,9 @@ import { Element as Element$1, Text, Range, Editor, Node, Point, Transforms, Pat
|
|
|
9
9
|
import { useSlateStatic, useSelected, withReact, ReactEditor, Slate, useSlate, Editable } from "slate-react";
|
|
10
10
|
import debug$i from "debug";
|
|
11
11
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
12
|
-
import { getBlockStartPoint, isKeyedSegment as isKeyedSegment$1, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isSpan$1 as isSpan, isListBlock, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
13
|
-
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
14
|
-
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
12
|
+
import { getBlockStartPoint, isKeyedSegment as isKeyedSegment$1, parseInlineObject, parseTextBlock, parseBlockObject, parseBlock, sliceBlocks, isTextBlock, parseAnnotation, blockOffsetToSpanSelectionPoint, isSpan$1 as isSpan, isListBlock, isTypedObject, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
|
|
13
|
+
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
14
|
+
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
15
15
|
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
16
16
|
import { isSelectionCollapsed as isSelectionCollapsed$1, selectionPointToBlockOffset, getSelectionStartPoint, getSelectionEndPoint } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
17
17
|
import isEqual from "lodash/isEqual.js";
|
|
@@ -31,6 +31,7 @@ import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatch
|
|
|
31
31
|
import get from "lodash/get.js";
|
|
32
32
|
import isUndefined from "lodash/isUndefined.js";
|
|
33
33
|
import omitBy from "lodash/omitBy.js";
|
|
34
|
+
import { createDraft, finishDraft } from "immer";
|
|
34
35
|
import startCase from "lodash.startcase";
|
|
35
36
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
36
37
|
function EditorEventListener(props) {
|
|
@@ -86,7 +87,7 @@ function getDragSelection({
|
|
|
86
87
|
...snapshot.context,
|
|
87
88
|
selection: eventSelection
|
|
88
89
|
}
|
|
89
|
-
}), draggedSpan = getFocusSpan({
|
|
90
|
+
}), draggedSpan = getFocusSpan$1({
|
|
90
91
|
context: {
|
|
91
92
|
...snapshot.context,
|
|
92
93
|
selection: eventSelection
|
|
@@ -248,6 +249,34 @@ function getFocusBlock({
|
|
|
248
249
|
return [void 0, void 0];
|
|
249
250
|
}
|
|
250
251
|
}
|
|
252
|
+
function getFocusSpan({
|
|
253
|
+
editor
|
|
254
|
+
}) {
|
|
255
|
+
if (!editor.selection)
|
|
256
|
+
return [void 0, void 0];
|
|
257
|
+
try {
|
|
258
|
+
const [node, path] = Editor.node(editor, editor.selection.focus.path);
|
|
259
|
+
if (editor.isTextSpan(node))
|
|
260
|
+
return [node, path];
|
|
261
|
+
} catch {
|
|
262
|
+
return [void 0, void 0];
|
|
263
|
+
}
|
|
264
|
+
return [void 0, void 0];
|
|
265
|
+
}
|
|
266
|
+
function getSelectedSpans({
|
|
267
|
+
editor
|
|
268
|
+
}) {
|
|
269
|
+
if (!editor.selection)
|
|
270
|
+
return [];
|
|
271
|
+
try {
|
|
272
|
+
return Array.from(Editor.nodes(editor, {
|
|
273
|
+
at: editor.selection,
|
|
274
|
+
match: (node) => editor.isTextSpan(node)
|
|
275
|
+
}));
|
|
276
|
+
} catch {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
251
280
|
function getSelectionStartBlock({
|
|
252
281
|
editor
|
|
253
282
|
}) {
|
|
@@ -1376,13 +1405,68 @@ function compileType(rawType) {
|
|
|
1376
1405
|
types: [rawType]
|
|
1377
1406
|
}).get(rawType.name);
|
|
1378
1407
|
}
|
|
1408
|
+
function createPlaceholderBlock(context) {
|
|
1409
|
+
return {
|
|
1410
|
+
_type: context.schema.block.name,
|
|
1411
|
+
_key: context.keyGenerator(),
|
|
1412
|
+
style: context.schema.styles[0].name ?? "normal",
|
|
1413
|
+
markDefs: [],
|
|
1414
|
+
children: [{
|
|
1415
|
+
_type: context.schema.span.name,
|
|
1416
|
+
_key: context.keyGenerator(),
|
|
1417
|
+
text: "",
|
|
1418
|
+
marks: []
|
|
1419
|
+
}]
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
function getActiveAnnotations({
|
|
1423
|
+
markState,
|
|
1424
|
+
schema
|
|
1425
|
+
}) {
|
|
1426
|
+
return (markState?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1427
|
+
}
|
|
1428
|
+
function getActiveDecorators({
|
|
1429
|
+
decoratorState,
|
|
1430
|
+
markState,
|
|
1431
|
+
schema
|
|
1432
|
+
}) {
|
|
1433
|
+
const decorators = schema.decorators.map((decorator) => decorator.name);
|
|
1434
|
+
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
1435
|
+
for (const decorator in decoratorState)
|
|
1436
|
+
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
1437
|
+
return activeDecorators;
|
|
1438
|
+
}
|
|
1379
1439
|
const insertTextOperationImplementation = ({
|
|
1440
|
+
context,
|
|
1380
1441
|
operation
|
|
1381
1442
|
}) => {
|
|
1382
|
-
|
|
1443
|
+
const activeDecorators = getActiveDecorators({
|
|
1444
|
+
decoratorState: operation.editor.decoratorState,
|
|
1445
|
+
markState: operation.editor.markState,
|
|
1446
|
+
schema: context.schema
|
|
1447
|
+
}), activeAnnotations = getActiveAnnotations({
|
|
1448
|
+
markState: operation.editor.markState,
|
|
1449
|
+
schema: context.schema
|
|
1450
|
+
}), [focusSpan] = getFocusSpan({
|
|
1451
|
+
editor: operation.editor
|
|
1452
|
+
});
|
|
1453
|
+
if (!focusSpan) {
|
|
1454
|
+
Transforms.insertText(operation.editor, operation.text);
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
if (operation.editor.markState && operation.editor.markState.state === "unchanged") {
|
|
1458
|
+
const markStateDecorators = (operation.editor.markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1459
|
+
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
1460
|
+
Transforms.insertText(operation.editor, operation.text);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
Transforms.insertNodes(operation.editor, {
|
|
1465
|
+
_type: focusSpan._type,
|
|
1466
|
+
_key: context.keyGenerator(),
|
|
1383
1467
|
text: operation.text,
|
|
1384
|
-
...
|
|
1385
|
-
})
|
|
1468
|
+
marks: [...activeDecorators, ...activeAnnotations]
|
|
1469
|
+
}), operation.editor.decoratorState = {};
|
|
1386
1470
|
};
|
|
1387
1471
|
function isPortableTextSpan(node) {
|
|
1388
1472
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
@@ -1455,6 +1539,50 @@ function isRedoing(editor) {
|
|
|
1455
1539
|
function setIsRedoing(editor, isRedoing2) {
|
|
1456
1540
|
IS_REDOING.set(editor, isRedoing2);
|
|
1457
1541
|
}
|
|
1542
|
+
function defaultCompare(a, b) {
|
|
1543
|
+
return a === b;
|
|
1544
|
+
}
|
|
1545
|
+
function useEditorSelector(editor, selector, t0) {
|
|
1546
|
+
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
1547
|
+
let t1;
|
|
1548
|
+
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
1549
|
+
const snapshot = getEditorSnapshot({
|
|
1550
|
+
editorActorSnapshot,
|
|
1551
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
1552
|
+
});
|
|
1553
|
+
return selector(snapshot);
|
|
1554
|
+
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
1555
|
+
}
|
|
1556
|
+
function getEditorSnapshot({
|
|
1557
|
+
editorActorSnapshot,
|
|
1558
|
+
slateEditorInstance
|
|
1559
|
+
}) {
|
|
1560
|
+
return {
|
|
1561
|
+
context: {
|
|
1562
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
1563
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
1564
|
+
readOnly: editorActorSnapshot.matches({
|
|
1565
|
+
"edit mode": "read only"
|
|
1566
|
+
}),
|
|
1567
|
+
schema: editorActorSnapshot.context.schema,
|
|
1568
|
+
selection: editorActorSnapshot.context.selection,
|
|
1569
|
+
value: slateEditorInstance.value
|
|
1570
|
+
},
|
|
1571
|
+
beta: {
|
|
1572
|
+
activeAnnotations: getActiveAnnotations({
|
|
1573
|
+
markState: slateEditorInstance.markState,
|
|
1574
|
+
schema: editorActorSnapshot.context.schema
|
|
1575
|
+
}),
|
|
1576
|
+
activeDecorators: getActiveDecorators({
|
|
1577
|
+
decoratorState: slateEditorInstance.decoratorState,
|
|
1578
|
+
markState: slateEditorInstance.markState,
|
|
1579
|
+
schema: editorActorSnapshot.context.schema
|
|
1580
|
+
}),
|
|
1581
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
1582
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1458
1586
|
const debug$h = debugWithName("plugin:withPortableTextMarkModel");
|
|
1459
1587
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1460
1588
|
return function(editor) {
|
|
@@ -1599,7 +1727,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1599
1727
|
apply2(op);
|
|
1600
1728
|
return;
|
|
1601
1729
|
}
|
|
1602
|
-
if (op.type === "set_selection" &&
|
|
1730
|
+
if (op.type === "set_selection" && op.properties && op.newProperties && op.properties.anchor && op.properties.focus && op.newProperties.anchor && op.newProperties.focus) {
|
|
1603
1731
|
const previousSelectionIsCollapsed = Range.isCollapsed({
|
|
1604
1732
|
anchor: op.properties.anchor,
|
|
1605
1733
|
focus: op.properties.focus
|
|
@@ -1619,8 +1747,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1619
1747
|
match: (n) => editor.isTextSpan(n),
|
|
1620
1748
|
voids: !1
|
|
1621
1749
|
}))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
1622
|
-
|
|
1623
|
-
return;
|
|
1750
|
+
!movedToNextSpan && !movedToPreviousSpan && (editor.decoratorState = {});
|
|
1624
1751
|
}
|
|
1625
1752
|
}
|
|
1626
1753
|
if (op.type === "insert_node") {
|
|
@@ -1668,88 +1795,21 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1668
1795
|
}
|
|
1669
1796
|
}
|
|
1670
1797
|
if (op.type === "insert_text") {
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
mode: "lowest",
|
|
1679
|
-
at: selection.focus,
|
|
1680
|
-
match: (n) => editor.isTextSpan(n),
|
|
1681
|
-
voids: !1
|
|
1682
|
-
}))[0] ?? [void 0, void 0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
1683
|
-
editor,
|
|
1684
|
-
blockPath,
|
|
1685
|
-
spanPath
|
|
1686
|
-
}), nextSpan = getNextSpan({
|
|
1687
|
-
editor,
|
|
1688
|
-
blockPath,
|
|
1689
|
-
spanPath
|
|
1690
|
-
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
1691
|
-
if (spanHasAnnotations && !spanIsEmpty) {
|
|
1692
|
-
if (atTheBeginningOfSpan) {
|
|
1693
|
-
if (previousSpanHasSameMarks) {
|
|
1694
|
-
Transforms.insertNodes(editor, {
|
|
1695
|
-
_type: "span",
|
|
1696
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1697
|
-
text: op.text,
|
|
1698
|
-
marks: previousSpan?.marks ?? []
|
|
1699
|
-
});
|
|
1700
|
-
return;
|
|
1701
|
-
} else if (previousSpanHasSameAnnotations) {
|
|
1702
|
-
Transforms.insertNodes(editor, {
|
|
1703
|
-
_type: "span",
|
|
1704
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1705
|
-
text: op.text,
|
|
1706
|
-
marks: previousSpan?.marks ?? []
|
|
1707
|
-
});
|
|
1708
|
-
return;
|
|
1709
|
-
} else if (previousSpanHasSameAnnotation) {
|
|
1710
|
-
apply2(op);
|
|
1711
|
-
return;
|
|
1712
|
-
} else if (!previousSpan) {
|
|
1713
|
-
Transforms.insertNodes(editor, {
|
|
1714
|
-
_type: "span",
|
|
1715
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1716
|
-
text: op.text,
|
|
1717
|
-
marks: []
|
|
1718
|
-
});
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
if (atTheEndOfSpan) {
|
|
1723
|
-
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations) {
|
|
1724
|
-
Transforms.insertNodes(editor, {
|
|
1725
|
-
_type: "span",
|
|
1726
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1727
|
-
text: op.text,
|
|
1728
|
-
marks: nextSpan?.marks ?? []
|
|
1729
|
-
});
|
|
1730
|
-
return;
|
|
1731
|
-
}
|
|
1732
|
-
if (!nextSpan) {
|
|
1733
|
-
Transforms.insertNodes(editor, {
|
|
1734
|
-
_type: "span",
|
|
1735
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1736
|
-
text: op.text,
|
|
1737
|
-
marks: []
|
|
1738
|
-
});
|
|
1739
|
-
return;
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
if (atTheBeginningOfSpan && !spanIsEmpty && previousSpan) {
|
|
1744
|
-
Transforms.insertNodes(editor, {
|
|
1745
|
-
_type: "span",
|
|
1746
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1747
|
-
text: op.text,
|
|
1748
|
-
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
1749
|
-
});
|
|
1750
|
-
return;
|
|
1751
|
-
}
|
|
1798
|
+
if (!editor.markState) {
|
|
1799
|
+
apply2(op);
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
if (editor.markState.state === "unchanged") {
|
|
1803
|
+
apply2(op);
|
|
1804
|
+
return;
|
|
1752
1805
|
}
|
|
1806
|
+
Transforms.insertNodes(editor, {
|
|
1807
|
+
_type: "span",
|
|
1808
|
+
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1809
|
+
text: op.text,
|
|
1810
|
+
marks: editor.markState.marks
|
|
1811
|
+
});
|
|
1812
|
+
return;
|
|
1753
1813
|
}
|
|
1754
1814
|
if (op.type === "remove_text") {
|
|
1755
1815
|
const {
|
|
@@ -1778,12 +1838,13 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1778
1838
|
spanPath
|
|
1779
1839
|
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
1780
1840
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
1781
|
-
const
|
|
1782
|
-
|
|
1783
|
-
|
|
1841
|
+
const snapshot = getEditorSnapshot({
|
|
1842
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1843
|
+
slateEditorInstance: editor
|
|
1844
|
+
});
|
|
1784
1845
|
Editor.withoutNormalizing(editor, () => {
|
|
1785
1846
|
apply2(op), Transforms.setNodes(editor, {
|
|
1786
|
-
marks:
|
|
1847
|
+
marks: snapshot.beta.activeDecorators
|
|
1787
1848
|
}, {
|
|
1788
1849
|
at: op.path
|
|
1789
1850
|
});
|
|
@@ -1846,18 +1907,8 @@ const removeDecoratorOperationImplementation = ({
|
|
|
1846
1907
|
at: blockPath,
|
|
1847
1908
|
match: (node) => editor.isTextSpan(node)
|
|
1848
1909
|
});
|
|
1849
|
-
} else
|
|
1850
|
-
|
|
1851
|
-
...Editor.marks(editor) || {}
|
|
1852
|
-
}.marks || [], marks = {
|
|
1853
|
-
...Editor.marks(editor) || {},
|
|
1854
|
-
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
1855
|
-
};
|
|
1856
|
-
editor.marks = {
|
|
1857
|
-
marks: marks.marks,
|
|
1858
|
-
_type: "span"
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1910
|
+
} else
|
|
1911
|
+
editor.decoratorState[mark] = !1;
|
|
1861
1912
|
}
|
|
1862
1913
|
if (editor.selection) {
|
|
1863
1914
|
const selection2 = editor.selection;
|
|
@@ -1867,23 +1918,6 @@ const removeDecoratorOperationImplementation = ({
|
|
|
1867
1918
|
}
|
|
1868
1919
|
}
|
|
1869
1920
|
};
|
|
1870
|
-
function isDecoratorActive({
|
|
1871
|
-
editor,
|
|
1872
|
-
decorator
|
|
1873
|
-
}) {
|
|
1874
|
-
if (!editor.selection)
|
|
1875
|
-
return !1;
|
|
1876
|
-
const selectedTextNodes = Array.from(Editor.nodes(editor, {
|
|
1877
|
-
match: Text.isText,
|
|
1878
|
-
at: editor.selection
|
|
1879
|
-
}));
|
|
1880
|
-
return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
1881
|
-
const [node] = n;
|
|
1882
|
-
return node.marks?.includes(decorator);
|
|
1883
|
-
}) : ({
|
|
1884
|
-
...Editor.marks(editor) || {}
|
|
1885
|
-
}.marks || []).includes(decorator);
|
|
1886
|
-
}
|
|
1887
1921
|
function cloneDiff(diff2) {
|
|
1888
1922
|
const [type, patch] = diff2;
|
|
1889
1923
|
return [type, patch];
|
|
@@ -3103,7 +3137,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
3103
3137
|
backward: editorSelection?.backward
|
|
3104
3138
|
}), trimmedSelection = getTrimmedSelection({
|
|
3105
3139
|
context: {
|
|
3106
|
-
activeDecorators: [],
|
|
3107
3140
|
converters: [],
|
|
3108
3141
|
keyGenerator: context.keyGenerator,
|
|
3109
3142
|
readOnly: !1,
|
|
@@ -3149,15 +3182,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
3149
3182
|
at: blockPath,
|
|
3150
3183
|
match: (node) => editor.isTextSpan(node)
|
|
3151
3184
|
});
|
|
3152
|
-
} else
|
|
3153
|
-
|
|
3154
|
-
...Editor.marks(editor) || {}
|
|
3155
|
-
}.marks || [], marks = {
|
|
3156
|
-
...Editor.marks(editor) || {},
|
|
3157
|
-
marks: [...existingMarks, mark]
|
|
3158
|
-
};
|
|
3159
|
-
editor.marks = marks;
|
|
3160
|
-
}
|
|
3185
|
+
} else
|
|
3186
|
+
editor.decoratorState[mark] = !0;
|
|
3161
3187
|
}
|
|
3162
3188
|
if (editor.selection) {
|
|
3163
3189
|
const selection2 = editor.selection;
|
|
@@ -3690,7 +3716,6 @@ function createWithEventListeners(editorActor) {
|
|
|
3690
3716
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
3691
3717
|
return editor;
|
|
3692
3718
|
const {
|
|
3693
|
-
insertText,
|
|
3694
3719
|
select
|
|
3695
3720
|
} = editor;
|
|
3696
3721
|
return editor.deleteBackward = (unit) => {
|
|
@@ -3768,9 +3793,18 @@ function createWithEventListeners(editorActor) {
|
|
|
3768
3793
|
},
|
|
3769
3794
|
editor
|
|
3770
3795
|
});
|
|
3771
|
-
}, editor.insertText = (text
|
|
3796
|
+
}, editor.insertText = (text) => {
|
|
3772
3797
|
if (isApplyingBehaviorOperations(editor)) {
|
|
3773
|
-
|
|
3798
|
+
insertTextOperationImplementation({
|
|
3799
|
+
context: {
|
|
3800
|
+
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
3801
|
+
schema: editorActor.getSnapshot().context.schema
|
|
3802
|
+
},
|
|
3803
|
+
operation: {
|
|
3804
|
+
text,
|
|
3805
|
+
editor
|
|
3806
|
+
}
|
|
3807
|
+
});
|
|
3774
3808
|
return;
|
|
3775
3809
|
}
|
|
3776
3810
|
editorActor.send({
|
|
@@ -4744,6 +4778,378 @@ function createWithUtils({
|
|
|
4744
4778
|
})[0], editor;
|
|
4745
4779
|
};
|
|
4746
4780
|
}
|
|
4781
|
+
function getMarkState({
|
|
4782
|
+
schema,
|
|
4783
|
+
editor
|
|
4784
|
+
}) {
|
|
4785
|
+
if (!editor.selection)
|
|
4786
|
+
return;
|
|
4787
|
+
const [block, blockPath] = getFocusBlock({
|
|
4788
|
+
editor
|
|
4789
|
+
}), [span, spanPath] = getFocusSpan({
|
|
4790
|
+
editor
|
|
4791
|
+
});
|
|
4792
|
+
if (!block || !editor.isTextBlock(block) || !span)
|
|
4793
|
+
return;
|
|
4794
|
+
if (Range.isExpanded(editor.selection)) {
|
|
4795
|
+
const selectedSpans = getSelectedSpans({
|
|
4796
|
+
editor
|
|
4797
|
+
});
|
|
4798
|
+
let index = 0, marks2 = [];
|
|
4799
|
+
for (const [span2] of selectedSpans)
|
|
4800
|
+
index === 0 ? marks2 = span2.marks ?? [] : (span2.marks?.length === 0 || (span2.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4801
|
+
return {
|
|
4802
|
+
state: "unchanged",
|
|
4803
|
+
marks: marks2
|
|
4804
|
+
};
|
|
4805
|
+
}
|
|
4806
|
+
const decorators = schema.decorators.map((decorator) => decorator.name), marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = editor.selection.anchor.offset === 0, atTheEndOfSpan = editor.selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4807
|
+
editor,
|
|
4808
|
+
blockPath,
|
|
4809
|
+
spanPath
|
|
4810
|
+
}), nextSpan = getNextSpan({
|
|
4811
|
+
editor,
|
|
4812
|
+
blockPath,
|
|
4813
|
+
spanPath
|
|
4814
|
+
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4815
|
+
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4816
|
+
if (atTheBeginningOfSpan) {
|
|
4817
|
+
if (previousSpanHasSameMarks)
|
|
4818
|
+
return {
|
|
4819
|
+
state: "changed",
|
|
4820
|
+
marks: previousSpan?.marks ?? []
|
|
4821
|
+
};
|
|
4822
|
+
if (previousSpanHasSameAnnotations)
|
|
4823
|
+
return {
|
|
4824
|
+
state: "changed",
|
|
4825
|
+
marks: previousSpan?.marks ?? []
|
|
4826
|
+
};
|
|
4827
|
+
if (previousSpanHasSameAnnotation)
|
|
4828
|
+
return {
|
|
4829
|
+
state: "unchanged",
|
|
4830
|
+
marks: span.marks ?? []
|
|
4831
|
+
};
|
|
4832
|
+
if (!previousSpan)
|
|
4833
|
+
return {
|
|
4834
|
+
state: "changed",
|
|
4835
|
+
marks: []
|
|
4836
|
+
};
|
|
4837
|
+
}
|
|
4838
|
+
if (atTheEndOfSpan) {
|
|
4839
|
+
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
4840
|
+
return {
|
|
4841
|
+
state: "changed",
|
|
4842
|
+
marks: nextSpan?.marks ?? []
|
|
4843
|
+
};
|
|
4844
|
+
if (!nextSpan)
|
|
4845
|
+
return {
|
|
4846
|
+
state: "changed",
|
|
4847
|
+
marks: []
|
|
4848
|
+
};
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
4852
|
+
state: "changed",
|
|
4853
|
+
marks: []
|
|
4854
|
+
} : {
|
|
4855
|
+
state: "changed",
|
|
4856
|
+
marks: (previousSpan?.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4857
|
+
} : {
|
|
4858
|
+
state: "unchanged",
|
|
4859
|
+
marks: span.marks ?? []
|
|
4860
|
+
};
|
|
4861
|
+
}
|
|
4862
|
+
function pluginUpdateMarkState(context, editor) {
|
|
4863
|
+
const {
|
|
4864
|
+
apply: apply2
|
|
4865
|
+
} = editor;
|
|
4866
|
+
return editor.apply = (operation) => {
|
|
4867
|
+
apply2(operation), editor.markState = getMarkState({
|
|
4868
|
+
editor,
|
|
4869
|
+
schema: context.schema
|
|
4870
|
+
});
|
|
4871
|
+
}, editor;
|
|
4872
|
+
}
|
|
4873
|
+
function isEditorNode(node) {
|
|
4874
|
+
return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
|
|
4875
|
+
}
|
|
4876
|
+
function isTextBlockNode(context, node) {
|
|
4877
|
+
return isTypedObject(node) && node._type === context.schema.block.name;
|
|
4878
|
+
}
|
|
4879
|
+
function isSpanNode(context, node) {
|
|
4880
|
+
return typeof node != "object" || node === null || "children" in node ? !1 : "_type" in node ? node._type === context.schema.span.name : "text" in node;
|
|
4881
|
+
}
|
|
4882
|
+
function isPartialSpanNode(node) {
|
|
4883
|
+
return typeof node == "object" && node !== null && "text" in node && typeof node.text == "string";
|
|
4884
|
+
}
|
|
4885
|
+
function isObjectNode(context, node) {
|
|
4886
|
+
return !isEditorNode(node) && !isTextBlockNode(context, node) && !isSpanNode(context, node) && !isPartialSpanNode(node);
|
|
4887
|
+
}
|
|
4888
|
+
function getBlock(root, path) {
|
|
4889
|
+
const index = path.at(0);
|
|
4890
|
+
if (!(index === void 0 || path.length !== 1))
|
|
4891
|
+
return root.children.at(index);
|
|
4892
|
+
}
|
|
4893
|
+
function getNode(context, root, path) {
|
|
4894
|
+
if (path.length === 0)
|
|
4895
|
+
return root;
|
|
4896
|
+
if (path.length === 1)
|
|
4897
|
+
return getBlock(root, path);
|
|
4898
|
+
if (path.length === 2) {
|
|
4899
|
+
const block = getBlock(root, path.slice(0, 1));
|
|
4900
|
+
return !block || !isTextBlockNode(context, block) ? void 0 : block.children.at(path[1]) || void 0;
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
function getSpan(context, root, path) {
|
|
4904
|
+
const node = getNode(context, root, path);
|
|
4905
|
+
if (node && isSpanNode(context, node))
|
|
4906
|
+
return node;
|
|
4907
|
+
}
|
|
4908
|
+
function getParent(context, root, path) {
|
|
4909
|
+
if (path.length === 0)
|
|
4910
|
+
return;
|
|
4911
|
+
const parentPath = path.slice(0, -1);
|
|
4912
|
+
if (parentPath.length === 0)
|
|
4913
|
+
return root;
|
|
4914
|
+
const blockIndex = parentPath.at(0);
|
|
4915
|
+
if (blockIndex === void 0 || parentPath.length !== 1)
|
|
4916
|
+
return;
|
|
4917
|
+
const block = root.children.at(blockIndex);
|
|
4918
|
+
if (block && isTextBlockNode(context, block))
|
|
4919
|
+
return block;
|
|
4920
|
+
}
|
|
4921
|
+
function applyOperationToPortableText(context, value, operation) {
|
|
4922
|
+
const draft = createDraft({
|
|
4923
|
+
children: value
|
|
4924
|
+
});
|
|
4925
|
+
try {
|
|
4926
|
+
applyOperationToPortableTextDraft(context, draft, operation);
|
|
4927
|
+
} catch (e) {
|
|
4928
|
+
console.error(e);
|
|
4929
|
+
}
|
|
4930
|
+
return finishDraft(draft).children;
|
|
4931
|
+
}
|
|
4932
|
+
function applyOperationToPortableTextDraft(context, root, operation) {
|
|
4933
|
+
switch (operation.type) {
|
|
4934
|
+
case "insert_node": {
|
|
4935
|
+
const {
|
|
4936
|
+
path,
|
|
4937
|
+
node: insertedNode
|
|
4938
|
+
} = operation, parent = getParent(context, root, path), index = path[path.length - 1];
|
|
4939
|
+
if (!parent || index > parent.children.length)
|
|
4940
|
+
break;
|
|
4941
|
+
if (path.length === 1) {
|
|
4942
|
+
if (isTextBlockNode(context, insertedNode)) {
|
|
4943
|
+
parent.children.splice(index, 0, {
|
|
4944
|
+
...insertedNode,
|
|
4945
|
+
children: insertedNode.children.map((child) => "__inline" in child ? {
|
|
4946
|
+
_key: child._key,
|
|
4947
|
+
_type: child._type,
|
|
4948
|
+
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
4949
|
+
} : child)
|
|
4950
|
+
});
|
|
4951
|
+
break;
|
|
4952
|
+
}
|
|
4953
|
+
if (Element$1.isElement(insertedNode) && !("__inline" in insertedNode)) {
|
|
4954
|
+
parent.children.splice(index, 0, {
|
|
4955
|
+
_key: insertedNode._key,
|
|
4956
|
+
_type: insertedNode._type,
|
|
4957
|
+
..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
|
|
4958
|
+
});
|
|
4959
|
+
break;
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
if (path.length === 2) {
|
|
4963
|
+
if (!isTextBlockNode(context, parent))
|
|
4964
|
+
break;
|
|
4965
|
+
if (isPartialSpanNode(insertedNode)) {
|
|
4966
|
+
parent.children.splice(index, 0, insertedNode);
|
|
4967
|
+
break;
|
|
4968
|
+
}
|
|
4969
|
+
if ("__inline" in insertedNode) {
|
|
4970
|
+
parent.children.splice(index, 0, {
|
|
4971
|
+
_key: insertedNode._key,
|
|
4972
|
+
_type: insertedNode._type,
|
|
4973
|
+
..."value" in insertedNode && typeof insertedNode.value == "object" ? insertedNode.value : {}
|
|
4974
|
+
});
|
|
4975
|
+
break;
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
break;
|
|
4979
|
+
}
|
|
4980
|
+
case "insert_text": {
|
|
4981
|
+
const {
|
|
4982
|
+
path,
|
|
4983
|
+
offset,
|
|
4984
|
+
text
|
|
4985
|
+
} = operation;
|
|
4986
|
+
if (text.length === 0) break;
|
|
4987
|
+
const span = getSpan(context, root, path);
|
|
4988
|
+
if (!span)
|
|
4989
|
+
break;
|
|
4990
|
+
const before = span.text.slice(0, offset), after = span.text.slice(offset);
|
|
4991
|
+
span.text = before + text + after;
|
|
4992
|
+
break;
|
|
4993
|
+
}
|
|
4994
|
+
case "merge_node": {
|
|
4995
|
+
const {
|
|
4996
|
+
path
|
|
4997
|
+
} = operation, node = getNode(context, root, path), prevPath = Path.previous(path), prev = getNode(context, root, prevPath), parent = getParent(context, root, path);
|
|
4998
|
+
if (!node || !prev || !parent)
|
|
4999
|
+
break;
|
|
5000
|
+
const index = path[path.length - 1];
|
|
5001
|
+
if (isPartialSpanNode(node) && isPartialSpanNode(prev))
|
|
5002
|
+
prev.text += node.text;
|
|
5003
|
+
else if (isTextBlockNode(context, node) && isTextBlockNode(context, prev))
|
|
5004
|
+
prev.children.push(...node.children);
|
|
5005
|
+
else
|
|
5006
|
+
break;
|
|
5007
|
+
parent.children.splice(index, 1);
|
|
5008
|
+
break;
|
|
5009
|
+
}
|
|
5010
|
+
case "move_node": {
|
|
5011
|
+
const {
|
|
5012
|
+
path,
|
|
5013
|
+
newPath
|
|
5014
|
+
} = operation;
|
|
5015
|
+
if (Path.isAncestor(path, newPath))
|
|
5016
|
+
break;
|
|
5017
|
+
const node = getNode(context, root, path), parent = getParent(context, root, path), index = path[path.length - 1];
|
|
5018
|
+
if (!node || !parent)
|
|
5019
|
+
break;
|
|
5020
|
+
parent.children.splice(index, 1);
|
|
5021
|
+
const truePath = Path.transform(path, operation), newParent = getNode(context, root, Path.parent(truePath)), newIndex = truePath[truePath.length - 1];
|
|
5022
|
+
if (!newParent || !("children" in newParent) || !Array.isArray(newParent.children))
|
|
5023
|
+
break;
|
|
5024
|
+
newParent.children.splice(newIndex, 0, node);
|
|
5025
|
+
break;
|
|
5026
|
+
}
|
|
5027
|
+
case "remove_node": {
|
|
5028
|
+
const {
|
|
5029
|
+
path
|
|
5030
|
+
} = operation, index = path[path.length - 1];
|
|
5031
|
+
getParent(context, root, path)?.children.splice(index, 1);
|
|
5032
|
+
break;
|
|
5033
|
+
}
|
|
5034
|
+
case "remove_text": {
|
|
5035
|
+
const {
|
|
5036
|
+
path,
|
|
5037
|
+
offset,
|
|
5038
|
+
text
|
|
5039
|
+
} = operation;
|
|
5040
|
+
if (text.length === 0)
|
|
5041
|
+
break;
|
|
5042
|
+
const span = getSpan(context, root, path);
|
|
5043
|
+
if (!span)
|
|
5044
|
+
break;
|
|
5045
|
+
const before = span.text.slice(0, offset), after = span.text.slice(offset + text.length);
|
|
5046
|
+
span.text = before + after;
|
|
5047
|
+
break;
|
|
5048
|
+
}
|
|
5049
|
+
case "set_node": {
|
|
5050
|
+
const {
|
|
5051
|
+
path,
|
|
5052
|
+
properties,
|
|
5053
|
+
newProperties
|
|
5054
|
+
} = operation, node = getNode(context, root, path);
|
|
5055
|
+
if (!node || isEditorNode(node))
|
|
5056
|
+
break;
|
|
5057
|
+
if (isObjectNode(context, node)) {
|
|
5058
|
+
const valueBefore = "value" in properties && typeof properties.value == "object" ? properties.value : {}, valueAfter = "value" in newProperties && typeof newProperties.value == "object" ? newProperties.value : {};
|
|
5059
|
+
for (const key in newProperties) {
|
|
5060
|
+
if (key === "value")
|
|
5061
|
+
continue;
|
|
5062
|
+
const value = newProperties[key];
|
|
5063
|
+
value == null ? delete node[key] : node[key] = value;
|
|
5064
|
+
}
|
|
5065
|
+
for (const key in properties)
|
|
5066
|
+
key !== "value" && (newProperties.hasOwnProperty(key) || delete node[key]);
|
|
5067
|
+
for (const key in valueAfter) {
|
|
5068
|
+
const value = valueAfter[key];
|
|
5069
|
+
value == null ? delete node[key] : node[key] = value;
|
|
5070
|
+
}
|
|
5071
|
+
for (const key in valueBefore)
|
|
5072
|
+
valueAfter.hasOwnProperty(key) || delete node[key];
|
|
5073
|
+
break;
|
|
5074
|
+
}
|
|
5075
|
+
if (isTextBlockNode(context, node)) {
|
|
5076
|
+
for (const key in newProperties) {
|
|
5077
|
+
if (key === "children" || key === "text")
|
|
5078
|
+
break;
|
|
5079
|
+
const value = newProperties[key];
|
|
5080
|
+
value == null ? delete node[key] : node[key] = value;
|
|
5081
|
+
}
|
|
5082
|
+
for (const key in properties)
|
|
5083
|
+
newProperties.hasOwnProperty(key) || delete node[key];
|
|
5084
|
+
break;
|
|
5085
|
+
}
|
|
5086
|
+
if (isPartialSpanNode(node)) {
|
|
5087
|
+
for (const key in newProperties) {
|
|
5088
|
+
if (key === "text")
|
|
5089
|
+
break;
|
|
5090
|
+
const value = newProperties[key];
|
|
5091
|
+
value == null ? delete node[key] : node[key] = value;
|
|
5092
|
+
}
|
|
5093
|
+
for (const key in properties)
|
|
5094
|
+
newProperties.hasOwnProperty(key) || delete node[key];
|
|
5095
|
+
break;
|
|
5096
|
+
}
|
|
5097
|
+
break;
|
|
5098
|
+
}
|
|
5099
|
+
case "split_node": {
|
|
5100
|
+
const {
|
|
5101
|
+
path,
|
|
5102
|
+
position,
|
|
5103
|
+
properties
|
|
5104
|
+
} = operation;
|
|
5105
|
+
if (path.length === 0)
|
|
5106
|
+
break;
|
|
5107
|
+
const parent = getParent(context, root, path), index = path[path.length - 1];
|
|
5108
|
+
if (!parent)
|
|
5109
|
+
break;
|
|
5110
|
+
if (isEditorNode(parent)) {
|
|
5111
|
+
const block = getBlock(root, path);
|
|
5112
|
+
if (!block || !isTextBlockNode(context, block))
|
|
5113
|
+
break;
|
|
5114
|
+
const before = block.children.slice(0, position), after = block.children.slice(position);
|
|
5115
|
+
block.children = before;
|
|
5116
|
+
const newTextBlockNode = {
|
|
5117
|
+
...properties,
|
|
5118
|
+
children: after,
|
|
5119
|
+
_type: context.schema.block.name
|
|
5120
|
+
};
|
|
5121
|
+
parent.children.splice(index + 1, 0, newTextBlockNode);
|
|
5122
|
+
break;
|
|
5123
|
+
}
|
|
5124
|
+
if (isTextBlockNode(context, parent)) {
|
|
5125
|
+
const node = getNode(context, root, path);
|
|
5126
|
+
if (!node || !isSpanNode(context, node))
|
|
5127
|
+
break;
|
|
5128
|
+
const before = node.text.slice(0, position), after = node.text.slice(position);
|
|
5129
|
+
node.text = before;
|
|
5130
|
+
const newSpanNode = {
|
|
5131
|
+
...properties,
|
|
5132
|
+
text: after
|
|
5133
|
+
};
|
|
5134
|
+
parent.children.splice(index + 1, 0, newSpanNode);
|
|
5135
|
+
}
|
|
5136
|
+
break;
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
return root;
|
|
5140
|
+
}
|
|
5141
|
+
function pluginUpdateValue(context, editor) {
|
|
5142
|
+
const {
|
|
5143
|
+
apply: apply2
|
|
5144
|
+
} = editor;
|
|
5145
|
+
return editor.apply = (operation) => {
|
|
5146
|
+
if (operation.type === "set_selection") {
|
|
5147
|
+
apply2(operation);
|
|
5148
|
+
return;
|
|
5149
|
+
}
|
|
5150
|
+
editor.value = applyOperationToPortableText(context, editor.value, operation), apply2(operation);
|
|
5151
|
+
}, editor;
|
|
5152
|
+
}
|
|
4747
5153
|
const withPlugins = (editor, options) => {
|
|
4748
5154
|
const e = editor, {
|
|
4749
5155
|
editorActor,
|
|
@@ -4760,7 +5166,7 @@ const withPlugins = (editor, options) => {
|
|
|
4760
5166
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
4761
5167
|
editorActor
|
|
4762
5168
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
4763
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5169
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e)))))))))))));
|
|
4764
5170
|
}, debug$a = debugWithName("setup");
|
|
4765
5171
|
function createSlateEditor(config) {
|
|
4766
5172
|
debug$a("Creating new Slate editor instance");
|
|
@@ -4769,10 +5175,10 @@ function createSlateEditor(config) {
|
|
|
4769
5175
|
relayActor: config.relayActor,
|
|
4770
5176
|
subscriptions: config.subscriptions
|
|
4771
5177
|
});
|
|
4772
|
-
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
4773
|
-
const initialValue =
|
|
4774
|
-
|
|
4775
|
-
})
|
|
5178
|
+
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratorState = {}, instance.markState = void 0, instance.value = [createPlaceholderBlock(config.editorActor.getSnapshot().context)];
|
|
5179
|
+
const initialValue = toSlateValue(instance.value, {
|
|
5180
|
+
schemaTypes: config.editorActor.getSnapshot().context.schema
|
|
5181
|
+
});
|
|
4776
5182
|
return {
|
|
4777
5183
|
instance,
|
|
4778
5184
|
initialValue
|
|
@@ -5225,7 +5631,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5225
5631
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
5226
5632
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5227
5633
|
return !1;
|
|
5228
|
-
const focusSpan = getFocusSpan(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
5634
|
+
const focusSpan = getFocusSpan$1(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
5229
5635
|
return isAtTheStartOfBlock(focusTextBlock)(snapshot) ? {
|
|
5230
5636
|
focusAnnotations,
|
|
5231
5637
|
focusDecorators,
|
|
@@ -5334,7 +5740,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5334
5740
|
guard: ({
|
|
5335
5741
|
snapshot
|
|
5336
5742
|
}) => {
|
|
5337
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan(snapshot);
|
|
5743
|
+
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5338
5744
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
5339
5745
|
focusTextBlock
|
|
5340
5746
|
} : !1;
|
|
@@ -5351,7 +5757,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5351
5757
|
guard: ({
|
|
5352
5758
|
snapshot
|
|
5353
5759
|
}) => {
|
|
5354
|
-
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan(snapshot);
|
|
5760
|
+
const selectionCollapsed = isSelectionCollapsed(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
|
|
5355
5761
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
5356
5762
|
focusTextBlock,
|
|
5357
5763
|
level: focusTextBlock.node.level - 1
|
|
@@ -5520,7 +5926,6 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
5520
5926
|
converters: [],
|
|
5521
5927
|
schema: snapshot.context.schema,
|
|
5522
5928
|
keyGenerator: snapshot.context.keyGenerator,
|
|
5523
|
-
activeDecorators: [],
|
|
5524
5929
|
readOnly: !1,
|
|
5525
5930
|
value: snapshot.context.value,
|
|
5526
5931
|
selection
|
|
@@ -6050,7 +6455,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6050
6455
|
guard: ({
|
|
6051
6456
|
snapshot
|
|
6052
6457
|
}) => {
|
|
6053
|
-
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6458
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6054
6459
|
return focusSpan && selectionCollapsed;
|
|
6055
6460
|
},
|
|
6056
6461
|
actions: []
|
|
@@ -6069,7 +6474,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6069
6474
|
guard: ({
|
|
6070
6475
|
snapshot
|
|
6071
6476
|
}) => {
|
|
6072
|
-
const focusSpan = getFocusSpan(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6477
|
+
const focusSpan = getFocusSpan$1(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot);
|
|
6073
6478
|
return focusSpan && selectionCollapsed;
|
|
6074
6479
|
},
|
|
6075
6480
|
actions: []
|
|
@@ -6216,9 +6621,9 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
6216
6621
|
event
|
|
6217
6622
|
}) => {
|
|
6218
6623
|
if (getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
6219
|
-
const activeDecorators = snapshot.
|
|
6624
|
+
const activeDecorators = snapshot.beta.activeDecorators;
|
|
6220
6625
|
return {
|
|
6221
|
-
activeAnnotations: getActiveAnnotations(snapshot),
|
|
6626
|
+
activeAnnotations: getActiveAnnotations$1(snapshot),
|
|
6222
6627
|
activeDecorators,
|
|
6223
6628
|
textRuns: event.data.flatMap((block) => isTextBlock(snapshot.context, block) ? [getTextBlockText(block)] : [])
|
|
6224
6629
|
};
|
|
@@ -6564,43 +6969,6 @@ function sortByPriority(items) {
|
|
|
6564
6969
|
result.includes(item) || result.push(item);
|
|
6565
6970
|
return [...result, ...itemsWithoutPriority];
|
|
6566
6971
|
}
|
|
6567
|
-
function slateChildrenToBlocks(schema, value) {
|
|
6568
|
-
const blocks = new Array(value.length);
|
|
6569
|
-
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
6570
|
-
const descendant = value[blockIndex];
|
|
6571
|
-
if (descendant._type !== schema.block.name) {
|
|
6572
|
-
blocks[blockIndex] = {
|
|
6573
|
-
_key: descendant._key,
|
|
6574
|
-
_type: descendant._type,
|
|
6575
|
-
..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
|
|
6576
|
-
};
|
|
6577
|
-
continue;
|
|
6578
|
-
}
|
|
6579
|
-
const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
|
|
6580
|
-
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
6581
|
-
const child = children[childIndex];
|
|
6582
|
-
processedChildren[childIndex] = child._type === schema.span.name ? child : {
|
|
6583
|
-
_key: child._key,
|
|
6584
|
-
_type: child._type,
|
|
6585
|
-
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
6586
|
-
};
|
|
6587
|
-
}
|
|
6588
|
-
blocks[blockIndex] = {
|
|
6589
|
-
...descendant,
|
|
6590
|
-
children: processedChildren
|
|
6591
|
-
};
|
|
6592
|
-
}
|
|
6593
|
-
return blocks;
|
|
6594
|
-
}
|
|
6595
|
-
function getActiveDecorators({
|
|
6596
|
-
schema,
|
|
6597
|
-
slateEditorInstance
|
|
6598
|
-
}) {
|
|
6599
|
-
const decorators = schema.decorators.map((decorator) => decorator.name);
|
|
6600
|
-
return ({
|
|
6601
|
-
...Editor.marks(slateEditorInstance) ?? {}
|
|
6602
|
-
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
6603
|
-
}
|
|
6604
6972
|
function createEditorSnapshot({
|
|
6605
6973
|
converters,
|
|
6606
6974
|
editor,
|
|
@@ -6610,25 +6978,30 @@ function createEditorSnapshot({
|
|
|
6610
6978
|
hasTag,
|
|
6611
6979
|
internalDrag
|
|
6612
6980
|
}) {
|
|
6613
|
-
const
|
|
6981
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
6614
6982
|
schema,
|
|
6615
6983
|
editor,
|
|
6616
6984
|
range: editor.selection
|
|
6617
6985
|
}) : null;
|
|
6618
6986
|
return {
|
|
6619
6987
|
context: {
|
|
6620
|
-
activeDecorators: getActiveDecorators({
|
|
6621
|
-
schema,
|
|
6622
|
-
slateEditorInstance: editor
|
|
6623
|
-
}),
|
|
6624
6988
|
converters,
|
|
6625
6989
|
keyGenerator,
|
|
6626
6990
|
readOnly,
|
|
6627
6991
|
schema,
|
|
6628
6992
|
selection,
|
|
6629
|
-
value
|
|
6993
|
+
value: editor.value
|
|
6630
6994
|
},
|
|
6631
6995
|
beta: {
|
|
6996
|
+
activeAnnotations: getActiveAnnotations({
|
|
6997
|
+
markState: editor.markState,
|
|
6998
|
+
schema
|
|
6999
|
+
}),
|
|
7000
|
+
activeDecorators: getActiveDecorators({
|
|
7001
|
+
decoratorState: editor.decoratorState,
|
|
7002
|
+
markState: editor.markState,
|
|
7003
|
+
schema
|
|
7004
|
+
}),
|
|
6632
7005
|
hasTag,
|
|
6633
7006
|
internalDrag
|
|
6634
7007
|
}
|
|
@@ -7311,45 +7684,6 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
7311
7684
|
} : inlineObject)
|
|
7312
7685
|
};
|
|
7313
7686
|
}
|
|
7314
|
-
function defaultCompare(a, b) {
|
|
7315
|
-
return a === b;
|
|
7316
|
-
}
|
|
7317
|
-
function useEditorSelector(editor, selector, t0) {
|
|
7318
|
-
const $ = c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
7319
|
-
let t1;
|
|
7320
|
-
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
7321
|
-
const snapshot = getEditorSnapshot({
|
|
7322
|
-
editorActorSnapshot,
|
|
7323
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7324
|
-
});
|
|
7325
|
-
return selector(snapshot);
|
|
7326
|
-
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], useSelector(editor._internal.editorActor, t1, compare);
|
|
7327
|
-
}
|
|
7328
|
-
function getEditorSnapshot({
|
|
7329
|
-
editorActorSnapshot,
|
|
7330
|
-
slateEditorInstance
|
|
7331
|
-
}) {
|
|
7332
|
-
return {
|
|
7333
|
-
context: {
|
|
7334
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
7335
|
-
activeDecorators: getActiveDecorators({
|
|
7336
|
-
schema: editorActorSnapshot.context.schema,
|
|
7337
|
-
slateEditorInstance
|
|
7338
|
-
}),
|
|
7339
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
7340
|
-
readOnly: editorActorSnapshot.matches({
|
|
7341
|
-
"edit mode": "read only"
|
|
7342
|
-
}),
|
|
7343
|
-
schema: editorActorSnapshot.context.schema,
|
|
7344
|
-
selection: editorActorSnapshot.context.selection,
|
|
7345
|
-
value: slateChildrenToBlocks(editorActorSnapshot.context.schema, slateEditorInstance.children)
|
|
7346
|
-
},
|
|
7347
|
-
beta: {
|
|
7348
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
7349
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
7350
|
-
}
|
|
7351
|
-
};
|
|
7352
|
-
}
|
|
7353
7687
|
const debug$7 = debugWithName("mutation-machine"), mutationMachine = setup({
|
|
7354
7688
|
types: {
|
|
7355
7689
|
context: {},
|
|
@@ -7643,19 +7977,17 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7643
7977
|
editor
|
|
7644
7978
|
});
|
|
7645
7979
|
},
|
|
7646
|
-
isMarkActive: (mark) => {
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
}
|
|
7980
|
+
isMarkActive: (mark) => getEditorSnapshot({
|
|
7981
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7982
|
+
slateEditorInstance: editor
|
|
7983
|
+
}).beta.activeDecorators.includes(mark),
|
|
7984
|
+
marks: () => {
|
|
7985
|
+
const snapshot = getEditorSnapshot({
|
|
7986
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7987
|
+
slateEditorInstance: editor
|
|
7988
|
+
});
|
|
7989
|
+
return [...snapshot.beta.activeAnnotations, ...snapshot.beta.activeDecorators];
|
|
7655
7990
|
},
|
|
7656
|
-
marks: () => ({
|
|
7657
|
-
...Editor.marks(editor) || {}
|
|
7658
|
-
}).marks || [],
|
|
7659
7991
|
undo: () => {
|
|
7660
7992
|
editorActor.send({
|
|
7661
7993
|
type: "behavior event",
|
|
@@ -7729,8 +8061,8 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7729
8061
|
}]
|
|
7730
8062
|
}], {
|
|
7731
8063
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
7732
|
-
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2),
|
|
7733
|
-
return
|
|
8064
|
+
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
8065
|
+
return isSpanNode2 && focusNode._type !== types.span.name && (debug$6("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
7734
8066
|
distance: 1,
|
|
7735
8067
|
unit: "character"
|
|
7736
8068
|
})), Transforms.insertNodes(editor, child, {
|
|
@@ -8770,8 +9102,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
8770
9102
|
debug$5("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
8771
9103
|
at: path
|
|
8772
9104
|
});
|
|
8773
|
-
const
|
|
8774
|
-
|
|
9105
|
+
const isSpanNode2 = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
9106
|
+
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && Transforms.delete(slateEditor, {
|
|
8775
9107
|
at: {
|
|
8776
9108
|
focus: {
|
|
8777
9109
|
path,
|
|
@@ -8784,7 +9116,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
8784
9116
|
}
|
|
8785
9117
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
8786
9118
|
at: path
|
|
8787
|
-
}), slateEditor.onChange()) :
|
|
9119
|
+
}), slateEditor.onChange()) : isSpanNode2 || (debug$5("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
8788
9120
|
_key: VOID_CHILD_KEY
|
|
8789
9121
|
}, {
|
|
8790
9122
|
at: [...path, 0],
|
|
@@ -9154,6 +9486,7 @@ class PortableTextEditor extends Component {
|
|
|
9154
9486
|
/*
|
|
9155
9487
|
* The editor API (currently implemented with Slate).
|
|
9156
9488
|
*/
|
|
9489
|
+
subscriptions = [];
|
|
9157
9490
|
unsubscribers = [];
|
|
9158
9491
|
constructor(props) {
|
|
9159
9492
|
if (super(props), props.editor)
|
|
@@ -9170,23 +9503,20 @@ class PortableTextEditor extends Component {
|
|
|
9170
9503
|
readOnly: props.readOnly,
|
|
9171
9504
|
schema: props.schemaType
|
|
9172
9505
|
});
|
|
9173
|
-
this.
|
|
9174
|
-
const subscription = actors.relayActor.on("*", (event) => {
|
|
9175
|
-
const change = eventToChange(event);
|
|
9176
|
-
change && (props.onChange(change), this.change$.next(change));
|
|
9177
|
-
});
|
|
9178
|
-
return () => {
|
|
9179
|
-
subscription.unsubscribe();
|
|
9180
|
-
};
|
|
9181
|
-
})());
|
|
9182
|
-
for (const subscription of subscriptions)
|
|
9183
|
-
this.unsubscribers.push(subscription());
|
|
9184
|
-
this.actors = actors, this.editor = editor, this.schemaTypes = actors.editorActor.getSnapshot().context.getLegacySchema();
|
|
9506
|
+
this.subscriptions = subscriptions, this.actors = actors, this.editor = editor, this.schemaTypes = actors.editorActor.getSnapshot().context.getLegacySchema();
|
|
9185
9507
|
}
|
|
9186
9508
|
this.editable = this.editor._internal.editable;
|
|
9187
9509
|
}
|
|
9188
9510
|
componentDidMount() {
|
|
9189
|
-
|
|
9511
|
+
if (!this.actors)
|
|
9512
|
+
return;
|
|
9513
|
+
for (const subscription of this.subscriptions)
|
|
9514
|
+
this.unsubscribers.push(subscription());
|
|
9515
|
+
const relayActorSubscription = this.actors.relayActor.on("*", (event) => {
|
|
9516
|
+
const change = eventToChange(event);
|
|
9517
|
+
change && (this.props.editor || this.props.onChange(change), this.change$.next(change));
|
|
9518
|
+
});
|
|
9519
|
+
this.unsubscribers.push(relayActorSubscription.unsubscribe), this.actors.editorActor.start(), this.actors.mutationActor.start(), this.actors.relayActor.start(), this.actors.syncActor.start();
|
|
9190
9520
|
}
|
|
9191
9521
|
componentDidUpdate(prevProps) {
|
|
9192
9522
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && console.warn("Updating schema type is no longer supported"), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|