@portabletext/editor 1.50.4 → 1.50.6
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 +9 -1
- package/lib/behaviors/index.d.ts +9 -1
- package/lib/index.cjs +271 -205
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +9 -1
- package/lib/index.d.ts +9 -1
- package/lib/index.js +280 -214
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +9 -1
- package/lib/plugins/index.d.ts +9 -1
- package/lib/selectors/index.d.cts +9 -1
- package/lib/selectors/index.d.ts +9 -1
- package/lib/utils/index.d.cts +9 -1
- package/lib/utils/index.d.ts +9 -1
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.delete.ts +6 -2
- package/src/behaviors/behavior.abstract.ts +1 -1
- package/src/editor/create-slate-editor.tsx +2 -0
- package/src/editor/editor-selector.ts +10 -4
- package/src/editor/editor-snapshot.ts +12 -5
- 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 +1 -4
- package/src/editor/plugins/with-plugins.ts +8 -1
- package/src/internal-utils/create-test-snapshot.ts +2 -1
- package/src/internal-utils/mark-state.ts +172 -0
- package/src/internal-utils/slate-utils.ts +52 -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 +3 -0
- package/src/editor/get-value.ts +0 -18
- package/src/selectors/selector.get-active-annotations.test.ts +0 -141
package/lib/index.cjs
CHANGED
|
@@ -220,6 +220,34 @@ function getFocusBlock({
|
|
|
220
220
|
return [void 0, void 0];
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
+
function getFocusSpan({
|
|
224
|
+
editor
|
|
225
|
+
}) {
|
|
226
|
+
if (!editor.selection)
|
|
227
|
+
return [void 0, void 0];
|
|
228
|
+
try {
|
|
229
|
+
const [node, path] = slate.Editor.node(editor, editor.selection.focus.path);
|
|
230
|
+
if (editor.isTextSpan(node))
|
|
231
|
+
return [node, path];
|
|
232
|
+
} catch {
|
|
233
|
+
return [void 0, void 0];
|
|
234
|
+
}
|
|
235
|
+
return [void 0, void 0];
|
|
236
|
+
}
|
|
237
|
+
function getSelectedSpans({
|
|
238
|
+
editor
|
|
239
|
+
}) {
|
|
240
|
+
if (!editor.selection)
|
|
241
|
+
return [];
|
|
242
|
+
try {
|
|
243
|
+
return Array.from(slate.Editor.nodes(editor, {
|
|
244
|
+
at: editor.selection,
|
|
245
|
+
match: (node) => editor.isTextSpan(node)
|
|
246
|
+
}));
|
|
247
|
+
} catch {
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
223
251
|
function getSelectionStartBlock({
|
|
224
252
|
editor
|
|
225
253
|
}) {
|
|
@@ -288,6 +316,8 @@ function getPointChild({
|
|
|
288
316
|
function getFirstBlock({
|
|
289
317
|
editor
|
|
290
318
|
}) {
|
|
319
|
+
if (editor.children.length === 0)
|
|
320
|
+
return [void 0, void 0];
|
|
291
321
|
const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
|
|
292
322
|
try {
|
|
293
323
|
return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
@@ -298,6 +328,8 @@ function getFirstBlock({
|
|
|
298
328
|
function getLastBlock({
|
|
299
329
|
editor
|
|
300
330
|
}) {
|
|
331
|
+
if (editor.children.length === 0)
|
|
332
|
+
return [void 0, void 0];
|
|
301
333
|
const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
|
|
302
334
|
try {
|
|
303
335
|
return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
@@ -1362,13 +1394,54 @@ function createPlaceholderBlock(context) {
|
|
|
1362
1394
|
}]
|
|
1363
1395
|
};
|
|
1364
1396
|
}
|
|
1397
|
+
function getActiveAnnotations({
|
|
1398
|
+
markState,
|
|
1399
|
+
schema: schema2
|
|
1400
|
+
}) {
|
|
1401
|
+
return (markState?.marks ?? []).filter((mark) => !schema2.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1402
|
+
}
|
|
1403
|
+
function getActiveDecorators({
|
|
1404
|
+
decoratorState,
|
|
1405
|
+
markState,
|
|
1406
|
+
schema: schema2
|
|
1407
|
+
}) {
|
|
1408
|
+
const decorators = schema2.decorators.map((decorator) => decorator.name);
|
|
1409
|
+
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
1410
|
+
for (const decorator in decoratorState)
|
|
1411
|
+
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
1412
|
+
return activeDecorators;
|
|
1413
|
+
}
|
|
1365
1414
|
const insertTextOperationImplementation = ({
|
|
1415
|
+
context,
|
|
1366
1416
|
operation
|
|
1367
1417
|
}) => {
|
|
1368
|
-
|
|
1418
|
+
const activeDecorators = getActiveDecorators({
|
|
1419
|
+
decoratorState: operation.editor.decoratorState,
|
|
1420
|
+
markState: operation.editor.markState,
|
|
1421
|
+
schema: context.schema
|
|
1422
|
+
}), activeAnnotations = getActiveAnnotations({
|
|
1423
|
+
markState: operation.editor.markState,
|
|
1424
|
+
schema: context.schema
|
|
1425
|
+
}), [focusSpan] = getFocusSpan({
|
|
1426
|
+
editor: operation.editor
|
|
1427
|
+
});
|
|
1428
|
+
if (!focusSpan) {
|
|
1429
|
+
slate.Transforms.insertText(operation.editor, operation.text);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
if (operation.editor.markState && operation.editor.markState.state === "unchanged") {
|
|
1433
|
+
const markStateDecorators = (operation.editor.markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1434
|
+
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
1435
|
+
slate.Transforms.insertText(operation.editor, operation.text);
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
slate.Transforms.insertNodes(operation.editor, {
|
|
1440
|
+
_type: focusSpan._type,
|
|
1441
|
+
_key: context.keyGenerator(),
|
|
1369
1442
|
text: operation.text,
|
|
1370
|
-
...
|
|
1371
|
-
})
|
|
1443
|
+
marks: [...activeDecorators, ...activeAnnotations]
|
|
1444
|
+
}), operation.editor.decoratorState = {};
|
|
1372
1445
|
};
|
|
1373
1446
|
function isPortableTextSpan(node) {
|
|
1374
1447
|
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"));
|
|
@@ -1441,6 +1514,50 @@ function isRedoing(editor) {
|
|
|
1441
1514
|
function setIsRedoing(editor, isRedoing2) {
|
|
1442
1515
|
IS_REDOING.set(editor, isRedoing2);
|
|
1443
1516
|
}
|
|
1517
|
+
function defaultCompare(a, b) {
|
|
1518
|
+
return a === b;
|
|
1519
|
+
}
|
|
1520
|
+
function useEditorSelector(editor, selector, t0) {
|
|
1521
|
+
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
1522
|
+
let t1;
|
|
1523
|
+
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
1524
|
+
const snapshot = getEditorSnapshot({
|
|
1525
|
+
editorActorSnapshot,
|
|
1526
|
+
slateEditorInstance: editor._internal.slateEditor.instance
|
|
1527
|
+
});
|
|
1528
|
+
return selector(snapshot);
|
|
1529
|
+
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
1530
|
+
}
|
|
1531
|
+
function getEditorSnapshot({
|
|
1532
|
+
editorActorSnapshot,
|
|
1533
|
+
slateEditorInstance
|
|
1534
|
+
}) {
|
|
1535
|
+
return {
|
|
1536
|
+
context: {
|
|
1537
|
+
converters: [...editorActorSnapshot.context.converters],
|
|
1538
|
+
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
1539
|
+
readOnly: editorActorSnapshot.matches({
|
|
1540
|
+
"edit mode": "read only"
|
|
1541
|
+
}),
|
|
1542
|
+
schema: editorActorSnapshot.context.schema,
|
|
1543
|
+
selection: editorActorSnapshot.context.selection,
|
|
1544
|
+
value: slateEditorInstance.value
|
|
1545
|
+
},
|
|
1546
|
+
beta: {
|
|
1547
|
+
activeAnnotations: getActiveAnnotations({
|
|
1548
|
+
markState: slateEditorInstance.markState,
|
|
1549
|
+
schema: editorActorSnapshot.context.schema
|
|
1550
|
+
}),
|
|
1551
|
+
activeDecorators: getActiveDecorators({
|
|
1552
|
+
decoratorState: slateEditorInstance.decoratorState,
|
|
1553
|
+
markState: slateEditorInstance.markState,
|
|
1554
|
+
schema: editorActorSnapshot.context.schema
|
|
1555
|
+
}),
|
|
1556
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
1557
|
+
internalDrag: editorActorSnapshot.context.internalDrag
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1444
1561
|
const debug$h = debugWithName("plugin:withPortableTextMarkModel");
|
|
1445
1562
|
function createWithPortableTextMarkModel(editorActor) {
|
|
1446
1563
|
return function(editor) {
|
|
@@ -1585,7 +1702,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1585
1702
|
apply2(op);
|
|
1586
1703
|
return;
|
|
1587
1704
|
}
|
|
1588
|
-
if (op.type === "set_selection" &&
|
|
1705
|
+
if (op.type === "set_selection" && op.properties && op.newProperties && op.properties.anchor && op.properties.focus && op.newProperties.anchor && op.newProperties.focus) {
|
|
1589
1706
|
const previousSelectionIsCollapsed = slate.Range.isCollapsed({
|
|
1590
1707
|
anchor: op.properties.anchor,
|
|
1591
1708
|
focus: op.properties.focus
|
|
@@ -1605,8 +1722,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1605
1722
|
match: (n) => editor.isTextSpan(n),
|
|
1606
1723
|
voids: !1
|
|
1607
1724
|
}))[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;
|
|
1608
|
-
|
|
1609
|
-
return;
|
|
1725
|
+
!movedToNextSpan && !movedToPreviousSpan && (editor.decoratorState = {});
|
|
1610
1726
|
}
|
|
1611
1727
|
}
|
|
1612
1728
|
if (op.type === "insert_node") {
|
|
@@ -1654,88 +1770,21 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1654
1770
|
}
|
|
1655
1771
|
}
|
|
1656
1772
|
if (op.type === "insert_text") {
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
mode: "lowest",
|
|
1665
|
-
at: selection.focus,
|
|
1666
|
-
match: (n) => editor.isTextSpan(n),
|
|
1667
|
-
voids: !1
|
|
1668
|
-
}))[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({
|
|
1669
|
-
editor,
|
|
1670
|
-
blockPath,
|
|
1671
|
-
spanPath
|
|
1672
|
-
}), nextSpan = getNextSpan({
|
|
1673
|
-
editor,
|
|
1674
|
-
blockPath,
|
|
1675
|
-
spanPath
|
|
1676
|
-
}), 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));
|
|
1677
|
-
if (spanHasAnnotations && !spanIsEmpty) {
|
|
1678
|
-
if (atTheBeginningOfSpan) {
|
|
1679
|
-
if (previousSpanHasSameMarks) {
|
|
1680
|
-
slate.Transforms.insertNodes(editor, {
|
|
1681
|
-
_type: "span",
|
|
1682
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1683
|
-
text: op.text,
|
|
1684
|
-
marks: previousSpan?.marks ?? []
|
|
1685
|
-
});
|
|
1686
|
-
return;
|
|
1687
|
-
} else if (previousSpanHasSameAnnotations) {
|
|
1688
|
-
slate.Transforms.insertNodes(editor, {
|
|
1689
|
-
_type: "span",
|
|
1690
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1691
|
-
text: op.text,
|
|
1692
|
-
marks: previousSpan?.marks ?? []
|
|
1693
|
-
});
|
|
1694
|
-
return;
|
|
1695
|
-
} else if (previousSpanHasSameAnnotation) {
|
|
1696
|
-
apply2(op);
|
|
1697
|
-
return;
|
|
1698
|
-
} else if (!previousSpan) {
|
|
1699
|
-
slate.Transforms.insertNodes(editor, {
|
|
1700
|
-
_type: "span",
|
|
1701
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1702
|
-
text: op.text,
|
|
1703
|
-
marks: []
|
|
1704
|
-
});
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
if (atTheEndOfSpan) {
|
|
1709
|
-
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations) {
|
|
1710
|
-
slate.Transforms.insertNodes(editor, {
|
|
1711
|
-
_type: "span",
|
|
1712
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1713
|
-
text: op.text,
|
|
1714
|
-
marks: nextSpan?.marks ?? []
|
|
1715
|
-
});
|
|
1716
|
-
return;
|
|
1717
|
-
}
|
|
1718
|
-
if (!nextSpan) {
|
|
1719
|
-
slate.Transforms.insertNodes(editor, {
|
|
1720
|
-
_type: "span",
|
|
1721
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1722
|
-
text: op.text,
|
|
1723
|
-
marks: []
|
|
1724
|
-
});
|
|
1725
|
-
return;
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
if (atTheBeginningOfSpan && !spanIsEmpty && previousSpan) {
|
|
1730
|
-
slate.Transforms.insertNodes(editor, {
|
|
1731
|
-
_type: "span",
|
|
1732
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1733
|
-
text: op.text,
|
|
1734
|
-
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
1735
|
-
});
|
|
1736
|
-
return;
|
|
1737
|
-
}
|
|
1773
|
+
if (!editor.markState) {
|
|
1774
|
+
apply2(op);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
if (editor.markState.state === "unchanged") {
|
|
1778
|
+
apply2(op);
|
|
1779
|
+
return;
|
|
1738
1780
|
}
|
|
1781
|
+
slate.Transforms.insertNodes(editor, {
|
|
1782
|
+
_type: "span",
|
|
1783
|
+
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1784
|
+
text: op.text,
|
|
1785
|
+
marks: editor.markState.marks
|
|
1786
|
+
});
|
|
1787
|
+
return;
|
|
1739
1788
|
}
|
|
1740
1789
|
if (op.type === "remove_text") {
|
|
1741
1790
|
const {
|
|
@@ -1764,12 +1813,13 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1764
1813
|
spanPath
|
|
1765
1814
|
}), 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;
|
|
1766
1815
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
1767
|
-
const
|
|
1768
|
-
|
|
1769
|
-
|
|
1816
|
+
const snapshot = getEditorSnapshot({
|
|
1817
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1818
|
+
slateEditorInstance: editor
|
|
1819
|
+
});
|
|
1770
1820
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
1771
1821
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
1772
|
-
marks:
|
|
1822
|
+
marks: snapshot.beta.activeDecorators
|
|
1773
1823
|
}, {
|
|
1774
1824
|
at: op.path
|
|
1775
1825
|
});
|
|
@@ -1832,18 +1882,8 @@ const removeDecoratorOperationImplementation = ({
|
|
|
1832
1882
|
at: blockPath,
|
|
1833
1883
|
match: (node) => editor.isTextSpan(node)
|
|
1834
1884
|
});
|
|
1835
|
-
} else
|
|
1836
|
-
|
|
1837
|
-
...slate.Editor.marks(editor) || {}
|
|
1838
|
-
}.marks || [], marks = {
|
|
1839
|
-
...slate.Editor.marks(editor) || {},
|
|
1840
|
-
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
1841
|
-
};
|
|
1842
|
-
editor.marks = {
|
|
1843
|
-
marks: marks.marks,
|
|
1844
|
-
_type: "span"
|
|
1845
|
-
};
|
|
1846
|
-
}
|
|
1885
|
+
} else
|
|
1886
|
+
editor.decoratorState[mark] = !1;
|
|
1847
1887
|
}
|
|
1848
1888
|
if (editor.selection) {
|
|
1849
1889
|
const selection2 = editor.selection;
|
|
@@ -1853,23 +1893,6 @@ const removeDecoratorOperationImplementation = ({
|
|
|
1853
1893
|
}
|
|
1854
1894
|
}
|
|
1855
1895
|
};
|
|
1856
|
-
function isDecoratorActive({
|
|
1857
|
-
editor,
|
|
1858
|
-
decorator
|
|
1859
|
-
}) {
|
|
1860
|
-
if (!editor.selection)
|
|
1861
|
-
return !1;
|
|
1862
|
-
const selectedTextNodes = Array.from(slate.Editor.nodes(editor, {
|
|
1863
|
-
match: slate.Text.isText,
|
|
1864
|
-
at: editor.selection
|
|
1865
|
-
}));
|
|
1866
|
-
return selectedTextNodes.length === 0 ? !1 : slate.Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
1867
|
-
const [node] = n;
|
|
1868
|
-
return node.marks?.includes(decorator);
|
|
1869
|
-
}) : ({
|
|
1870
|
-
...slate.Editor.marks(editor) || {}
|
|
1871
|
-
}.marks || []).includes(decorator);
|
|
1872
|
-
}
|
|
1873
1896
|
function cloneDiff(diff2) {
|
|
1874
1897
|
const [type, patch] = diff2;
|
|
1875
1898
|
return [type, patch];
|
|
@@ -3089,7 +3112,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
3089
3112
|
backward: editorSelection?.backward
|
|
3090
3113
|
}), trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
|
|
3091
3114
|
context: {
|
|
3092
|
-
activeDecorators: [],
|
|
3093
3115
|
converters: [],
|
|
3094
3116
|
keyGenerator: context.keyGenerator,
|
|
3095
3117
|
readOnly: !1,
|
|
@@ -3135,15 +3157,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
3135
3157
|
at: blockPath,
|
|
3136
3158
|
match: (node) => editor.isTextSpan(node)
|
|
3137
3159
|
});
|
|
3138
|
-
} else
|
|
3139
|
-
|
|
3140
|
-
...slate.Editor.marks(editor) || {}
|
|
3141
|
-
}.marks || [], marks = {
|
|
3142
|
-
...slate.Editor.marks(editor) || {},
|
|
3143
|
-
marks: [...existingMarks, mark]
|
|
3144
|
-
};
|
|
3145
|
-
editor.marks = marks;
|
|
3146
|
-
}
|
|
3160
|
+
} else
|
|
3161
|
+
editor.decoratorState[mark] = !0;
|
|
3147
3162
|
}
|
|
3148
3163
|
if (editor.selection) {
|
|
3149
3164
|
const selection2 = editor.selection;
|
|
@@ -3676,7 +3691,6 @@ function createWithEventListeners(editorActor) {
|
|
|
3676
3691
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
3677
3692
|
return editor;
|
|
3678
3693
|
const {
|
|
3679
|
-
insertText,
|
|
3680
3694
|
select
|
|
3681
3695
|
} = editor;
|
|
3682
3696
|
return editor.deleteBackward = (unit) => {
|
|
@@ -3754,9 +3768,18 @@ function createWithEventListeners(editorActor) {
|
|
|
3754
3768
|
},
|
|
3755
3769
|
editor
|
|
3756
3770
|
});
|
|
3757
|
-
}, editor.insertText = (text
|
|
3771
|
+
}, editor.insertText = (text) => {
|
|
3758
3772
|
if (isApplyingBehaviorOperations(editor)) {
|
|
3759
|
-
|
|
3773
|
+
insertTextOperationImplementation({
|
|
3774
|
+
context: {
|
|
3775
|
+
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
3776
|
+
schema: editorActor.getSnapshot().context.schema
|
|
3777
|
+
},
|
|
3778
|
+
operation: {
|
|
3779
|
+
text,
|
|
3780
|
+
editor
|
|
3781
|
+
}
|
|
3782
|
+
});
|
|
3760
3783
|
return;
|
|
3761
3784
|
}
|
|
3762
3785
|
editorActor.send({
|
|
@@ -4730,6 +4753,98 @@ function createWithUtils({
|
|
|
4730
4753
|
})[0], editor;
|
|
4731
4754
|
};
|
|
4732
4755
|
}
|
|
4756
|
+
function getMarkState({
|
|
4757
|
+
schema: schema2,
|
|
4758
|
+
editor
|
|
4759
|
+
}) {
|
|
4760
|
+
if (!editor.selection)
|
|
4761
|
+
return;
|
|
4762
|
+
const [block, blockPath] = getFocusBlock({
|
|
4763
|
+
editor
|
|
4764
|
+
}), [span, spanPath] = getFocusSpan({
|
|
4765
|
+
editor
|
|
4766
|
+
});
|
|
4767
|
+
if (!block || !editor.isTextBlock(block) || !span)
|
|
4768
|
+
return;
|
|
4769
|
+
if (slate.Range.isExpanded(editor.selection)) {
|
|
4770
|
+
const selectedSpans = getSelectedSpans({
|
|
4771
|
+
editor
|
|
4772
|
+
});
|
|
4773
|
+
let index = 0, marks2 = [];
|
|
4774
|
+
for (const [span2] of selectedSpans)
|
|
4775
|
+
index === 0 ? marks2 = span2.marks ?? [] : (span2.marks?.length === 0 || (span2.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4776
|
+
return {
|
|
4777
|
+
state: "unchanged",
|
|
4778
|
+
marks: marks2
|
|
4779
|
+
};
|
|
4780
|
+
}
|
|
4781
|
+
const decorators = schema2.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({
|
|
4782
|
+
editor,
|
|
4783
|
+
blockPath,
|
|
4784
|
+
spanPath
|
|
4785
|
+
}), nextSpan = getNextSpan({
|
|
4786
|
+
editor,
|
|
4787
|
+
blockPath,
|
|
4788
|
+
spanPath
|
|
4789
|
+
}), 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));
|
|
4790
|
+
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4791
|
+
if (atTheBeginningOfSpan) {
|
|
4792
|
+
if (previousSpanHasSameMarks)
|
|
4793
|
+
return {
|
|
4794
|
+
state: "changed",
|
|
4795
|
+
marks: previousSpan?.marks ?? []
|
|
4796
|
+
};
|
|
4797
|
+
if (previousSpanHasSameAnnotations)
|
|
4798
|
+
return {
|
|
4799
|
+
state: "changed",
|
|
4800
|
+
marks: previousSpan?.marks ?? []
|
|
4801
|
+
};
|
|
4802
|
+
if (previousSpanHasSameAnnotation)
|
|
4803
|
+
return {
|
|
4804
|
+
state: "unchanged",
|
|
4805
|
+
marks: span.marks ?? []
|
|
4806
|
+
};
|
|
4807
|
+
if (!previousSpan)
|
|
4808
|
+
return {
|
|
4809
|
+
state: "changed",
|
|
4810
|
+
marks: []
|
|
4811
|
+
};
|
|
4812
|
+
}
|
|
4813
|
+
if (atTheEndOfSpan) {
|
|
4814
|
+
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
4815
|
+
return {
|
|
4816
|
+
state: "changed",
|
|
4817
|
+
marks: nextSpan?.marks ?? []
|
|
4818
|
+
};
|
|
4819
|
+
if (!nextSpan)
|
|
4820
|
+
return {
|
|
4821
|
+
state: "changed",
|
|
4822
|
+
marks: []
|
|
4823
|
+
};
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
4827
|
+
state: "changed",
|
|
4828
|
+
marks: []
|
|
4829
|
+
} : {
|
|
4830
|
+
state: "changed",
|
|
4831
|
+
marks: (previousSpan?.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4832
|
+
} : {
|
|
4833
|
+
state: "unchanged",
|
|
4834
|
+
marks: span.marks ?? []
|
|
4835
|
+
};
|
|
4836
|
+
}
|
|
4837
|
+
function pluginUpdateMarkState(context, editor) {
|
|
4838
|
+
const {
|
|
4839
|
+
apply: apply2
|
|
4840
|
+
} = editor;
|
|
4841
|
+
return editor.apply = (operation) => {
|
|
4842
|
+
apply2(operation), editor.markState = getMarkState({
|
|
4843
|
+
editor,
|
|
4844
|
+
schema: context.schema
|
|
4845
|
+
});
|
|
4846
|
+
}, editor;
|
|
4847
|
+
}
|
|
4733
4848
|
function isEditorNode(node) {
|
|
4734
4849
|
return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
|
|
4735
4850
|
}
|
|
@@ -5007,10 +5122,7 @@ function pluginUpdateValue(context, editor) {
|
|
|
5007
5122
|
apply2(operation);
|
|
5008
5123
|
return;
|
|
5009
5124
|
}
|
|
5010
|
-
editor.value = applyOperationToPortableText(
|
|
5011
|
-
keyGenerator: context.keyGenerator,
|
|
5012
|
-
schema: context.schema
|
|
5013
|
-
}, editor.value, operation), apply2(operation);
|
|
5125
|
+
editor.value = applyOperationToPortableText(context, editor.value, operation), apply2(operation);
|
|
5014
5126
|
}, editor;
|
|
5015
5127
|
}
|
|
5016
5128
|
const withPlugins = (editor, options) => {
|
|
@@ -5029,7 +5141,7 @@ const withPlugins = (editor, options) => {
|
|
|
5029
5141
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5030
5142
|
editorActor
|
|
5031
5143
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
5032
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, e))))))))))));
|
|
5144
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e)))))))))))));
|
|
5033
5145
|
}, debug$a = debugWithName("setup");
|
|
5034
5146
|
function createSlateEditor(config) {
|
|
5035
5147
|
debug$a("Creating new Slate editor instance");
|
|
@@ -5038,7 +5150,7 @@ function createSlateEditor(config) {
|
|
|
5038
5150
|
relayActor: config.relayActor,
|
|
5039
5151
|
subscriptions: config.subscriptions
|
|
5040
5152
|
});
|
|
5041
|
-
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.value = [createPlaceholderBlock(config.editorActor.getSnapshot().context)];
|
|
5153
|
+
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)];
|
|
5042
5154
|
const initialValue = toSlateValue(instance.value, {
|
|
5043
5155
|
schemaTypes: config.editorActor.getSnapshot().context.schema
|
|
5044
5156
|
});
|
|
@@ -5789,7 +5901,6 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5789
5901
|
converters: [],
|
|
5790
5902
|
schema: snapshot.context.schema,
|
|
5791
5903
|
keyGenerator: snapshot.context.keyGenerator,
|
|
5792
|
-
activeDecorators: [],
|
|
5793
5904
|
readOnly: !1,
|
|
5794
5905
|
value: snapshot.context.value,
|
|
5795
5906
|
selection
|
|
@@ -6485,7 +6596,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6485
6596
|
event
|
|
6486
6597
|
}) => {
|
|
6487
6598
|
if (selector_isSelectionExpanded.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
6488
|
-
const activeDecorators = snapshot.
|
|
6599
|
+
const activeDecorators = snapshot.beta.activeDecorators;
|
|
6489
6600
|
return {
|
|
6490
6601
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
6491
6602
|
activeDecorators,
|
|
@@ -6833,15 +6944,6 @@ function sortByPriority(items) {
|
|
|
6833
6944
|
result.includes(item) || result.push(item);
|
|
6834
6945
|
return [...result, ...itemsWithoutPriority];
|
|
6835
6946
|
}
|
|
6836
|
-
function getActiveDecorators({
|
|
6837
|
-
schema: schema2,
|
|
6838
|
-
slateEditorInstance
|
|
6839
|
-
}) {
|
|
6840
|
-
const decorators = schema2.decorators.map((decorator) => decorator.name);
|
|
6841
|
-
return ({
|
|
6842
|
-
...slate.Editor.marks(slateEditorInstance) ?? {}
|
|
6843
|
-
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
6844
|
-
}
|
|
6845
6947
|
function createEditorSnapshot({
|
|
6846
6948
|
converters,
|
|
6847
6949
|
editor,
|
|
@@ -6858,10 +6960,6 @@ function createEditorSnapshot({
|
|
|
6858
6960
|
}) : null;
|
|
6859
6961
|
return {
|
|
6860
6962
|
context: {
|
|
6861
|
-
activeDecorators: getActiveDecorators({
|
|
6862
|
-
schema: schema2,
|
|
6863
|
-
slateEditorInstance: editor
|
|
6864
|
-
}),
|
|
6865
6963
|
converters,
|
|
6866
6964
|
keyGenerator,
|
|
6867
6965
|
readOnly,
|
|
@@ -6870,6 +6968,15 @@ function createEditorSnapshot({
|
|
|
6870
6968
|
value: editor.value
|
|
6871
6969
|
},
|
|
6872
6970
|
beta: {
|
|
6971
|
+
activeAnnotations: getActiveAnnotations({
|
|
6972
|
+
markState: editor.markState,
|
|
6973
|
+
schema: schema2
|
|
6974
|
+
}),
|
|
6975
|
+
activeDecorators: getActiveDecorators({
|
|
6976
|
+
decoratorState: editor.decoratorState,
|
|
6977
|
+
markState: editor.markState,
|
|
6978
|
+
schema: schema2
|
|
6979
|
+
}),
|
|
6873
6980
|
hasTag,
|
|
6874
6981
|
internalDrag
|
|
6875
6982
|
}
|
|
@@ -7552,45 +7659,6 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
7552
7659
|
} : inlineObject)
|
|
7553
7660
|
};
|
|
7554
7661
|
}
|
|
7555
|
-
function defaultCompare(a, b) {
|
|
7556
|
-
return a === b;
|
|
7557
|
-
}
|
|
7558
|
-
function useEditorSelector(editor, selector, t0) {
|
|
7559
|
-
const $ = reactCompilerRuntime.c(3), compare = t0 === void 0 ? defaultCompare : t0;
|
|
7560
|
-
let t1;
|
|
7561
|
-
return $[0] !== editor || $[1] !== selector ? (t1 = (editorActorSnapshot) => {
|
|
7562
|
-
const snapshot = getEditorSnapshot({
|
|
7563
|
-
editorActorSnapshot,
|
|
7564
|
-
slateEditorInstance: editor._internal.slateEditor.instance
|
|
7565
|
-
});
|
|
7566
|
-
return selector(snapshot);
|
|
7567
|
-
}, $[0] = editor, $[1] = selector, $[2] = t1) : t1 = $[2], react.useSelector(editor._internal.editorActor, t1, compare);
|
|
7568
|
-
}
|
|
7569
|
-
function getEditorSnapshot({
|
|
7570
|
-
editorActorSnapshot,
|
|
7571
|
-
slateEditorInstance
|
|
7572
|
-
}) {
|
|
7573
|
-
return {
|
|
7574
|
-
context: {
|
|
7575
|
-
converters: [...editorActorSnapshot.context.converters],
|
|
7576
|
-
activeDecorators: getActiveDecorators({
|
|
7577
|
-
schema: editorActorSnapshot.context.schema,
|
|
7578
|
-
slateEditorInstance
|
|
7579
|
-
}),
|
|
7580
|
-
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
7581
|
-
readOnly: editorActorSnapshot.matches({
|
|
7582
|
-
"edit mode": "read only"
|
|
7583
|
-
}),
|
|
7584
|
-
schema: editorActorSnapshot.context.schema,
|
|
7585
|
-
selection: editorActorSnapshot.context.selection,
|
|
7586
|
-
value: slateEditorInstance.value
|
|
7587
|
-
},
|
|
7588
|
-
beta: {
|
|
7589
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
7590
|
-
internalDrag: editorActorSnapshot.context.internalDrag
|
|
7591
|
-
}
|
|
7592
|
-
};
|
|
7593
|
-
}
|
|
7594
7662
|
const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setup({
|
|
7595
7663
|
types: {
|
|
7596
7664
|
context: {},
|
|
@@ -7884,19 +7952,17 @@ function createEditableAPI(editor, editorActor) {
|
|
|
7884
7952
|
editor
|
|
7885
7953
|
});
|
|
7886
7954
|
},
|
|
7887
|
-
isMarkActive: (mark) => {
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
}
|
|
7955
|
+
isMarkActive: (mark) => getEditorSnapshot({
|
|
7956
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7957
|
+
slateEditorInstance: editor
|
|
7958
|
+
}).beta.activeDecorators.includes(mark),
|
|
7959
|
+
marks: () => {
|
|
7960
|
+
const snapshot = getEditorSnapshot({
|
|
7961
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
7962
|
+
slateEditorInstance: editor
|
|
7963
|
+
});
|
|
7964
|
+
return [...snapshot.beta.activeAnnotations, ...snapshot.beta.activeDecorators];
|
|
7896
7965
|
},
|
|
7897
|
-
marks: () => ({
|
|
7898
|
-
...slate.Editor.marks(editor) || {}
|
|
7899
|
-
}).marks || [],
|
|
7900
7966
|
undo: () => {
|
|
7901
7967
|
editorActor.send({
|
|
7902
7968
|
type: "behavior event",
|