@portabletext/editor 1.49.12 → 1.49.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/behaviors/index.d.cts +136 -0
- package/lib/behaviors/index.d.ts +136 -0
- package/lib/index.cjs +19 -23
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +136 -0
- package/lib/index.d.ts +136 -0
- package/lib/index.js +19 -23
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +136 -0
- package/lib/plugins/index.d.ts +136 -0
- package/lib/selectors/index.d.cts +136 -0
- package/lib/selectors/index.d.ts +136 -0
- package/lib/utils/index.d.cts +136 -0
- package/lib/utils/index.d.ts +136 -0
- package/package.json +3 -3
- package/src/editor/Editable.tsx +6 -6
- package/src/editor/__tests__/self-solving.test.tsx +9 -9
- package/src/editor/create-editor.ts +1 -15
- package/src/editor/editor-machine.ts +4 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +2 -4
- package/src/editor/plugins/with-plugins.ts +2 -4
package/lib/index.d.cts
CHANGED
|
@@ -1514,6 +1514,142 @@ declare const editorMachine: StateMachine<
|
|
|
1514
1514
|
never,
|
|
1515
1515
|
never
|
|
1516
1516
|
>,
|
|
1517
|
+
ActionFunction<
|
|
1518
|
+
{
|
|
1519
|
+
behaviors: Set<BehaviorConfig>
|
|
1520
|
+
converters: Set<Converter>
|
|
1521
|
+
getLegacySchema: () => PortableTextMemberSchemaTypes
|
|
1522
|
+
keyGenerator: () => string
|
|
1523
|
+
pendingEvents: Array<InternalPatchEvent | MutationEvent>
|
|
1524
|
+
pendingIncomingPatchesEvents: Array<PatchesEvent>
|
|
1525
|
+
schema: EditorSchema
|
|
1526
|
+
initialReadOnly: boolean
|
|
1527
|
+
maxBlocks: number | undefined
|
|
1528
|
+
selection: EditorSelection
|
|
1529
|
+
initialValue: Array<PortableTextBlock> | undefined
|
|
1530
|
+
internalDrag?: {
|
|
1531
|
+
ghost?: HTMLElement
|
|
1532
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1533
|
+
}
|
|
1534
|
+
slateEditor?: PortableTextSlateEditor
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
type: 'update selection'
|
|
1538
|
+
selection: EditorSelection
|
|
1539
|
+
},
|
|
1540
|
+
| InternalPatchEvent
|
|
1541
|
+
| MutationEvent
|
|
1542
|
+
| PatchesEvent
|
|
1543
|
+
| {
|
|
1544
|
+
type: 'update readOnly'
|
|
1545
|
+
readOnly: boolean
|
|
1546
|
+
}
|
|
1547
|
+
| {
|
|
1548
|
+
type: 'update maxBlocks'
|
|
1549
|
+
maxBlocks: number | undefined
|
|
1550
|
+
}
|
|
1551
|
+
| {
|
|
1552
|
+
type: 'add behavior'
|
|
1553
|
+
behaviorConfig: BehaviorConfig
|
|
1554
|
+
}
|
|
1555
|
+
| {
|
|
1556
|
+
type: 'remove behavior'
|
|
1557
|
+
behaviorConfig: BehaviorConfig
|
|
1558
|
+
}
|
|
1559
|
+
| {
|
|
1560
|
+
type: 'blur'
|
|
1561
|
+
editor: PortableTextSlateEditor
|
|
1562
|
+
}
|
|
1563
|
+
| {
|
|
1564
|
+
type: 'focus'
|
|
1565
|
+
editor: PortableTextSlateEditor
|
|
1566
|
+
}
|
|
1567
|
+
| {
|
|
1568
|
+
type: 'normalizing'
|
|
1569
|
+
}
|
|
1570
|
+
| {
|
|
1571
|
+
type: 'update selection'
|
|
1572
|
+
selection: EditorSelection
|
|
1573
|
+
}
|
|
1574
|
+
| {
|
|
1575
|
+
type: 'done normalizing'
|
|
1576
|
+
}
|
|
1577
|
+
| {
|
|
1578
|
+
type: 'done syncing value'
|
|
1579
|
+
}
|
|
1580
|
+
| {
|
|
1581
|
+
type: 'syncing value'
|
|
1582
|
+
}
|
|
1583
|
+
| {
|
|
1584
|
+
type: 'behavior event'
|
|
1585
|
+
behaviorEvent: BehaviorEvent
|
|
1586
|
+
editor: PortableTextSlateEditor
|
|
1587
|
+
nativeEvent?: {
|
|
1588
|
+
preventDefault: () => void
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
| {
|
|
1592
|
+
type: 'dragstart'
|
|
1593
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1594
|
+
ghost?: HTMLElement
|
|
1595
|
+
}
|
|
1596
|
+
| {
|
|
1597
|
+
type: 'dragend'
|
|
1598
|
+
}
|
|
1599
|
+
| {
|
|
1600
|
+
type: 'drop'
|
|
1601
|
+
},
|
|
1602
|
+
undefined,
|
|
1603
|
+
never,
|
|
1604
|
+
never,
|
|
1605
|
+
never,
|
|
1606
|
+
never,
|
|
1607
|
+
| InternalPatchEvent
|
|
1608
|
+
| MutationEvent
|
|
1609
|
+
| PatchesEvent
|
|
1610
|
+
| {
|
|
1611
|
+
type: 'blurred'
|
|
1612
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1613
|
+
}
|
|
1614
|
+
| {
|
|
1615
|
+
type: 'done loading'
|
|
1616
|
+
}
|
|
1617
|
+
| {
|
|
1618
|
+
type: 'editable'
|
|
1619
|
+
}
|
|
1620
|
+
| {
|
|
1621
|
+
type: 'error'
|
|
1622
|
+
name: string
|
|
1623
|
+
description: string
|
|
1624
|
+
data: unknown
|
|
1625
|
+
}
|
|
1626
|
+
| {
|
|
1627
|
+
type: 'focused'
|
|
1628
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1629
|
+
}
|
|
1630
|
+
| {
|
|
1631
|
+
type: 'invalid value'
|
|
1632
|
+
resolution: InvalidValueResolution_2 | null
|
|
1633
|
+
value: Array<PortableTextBlock> | undefined
|
|
1634
|
+
}
|
|
1635
|
+
| {
|
|
1636
|
+
type: 'loading'
|
|
1637
|
+
}
|
|
1638
|
+
| {
|
|
1639
|
+
type: 'read only'
|
|
1640
|
+
}
|
|
1641
|
+
| {
|
|
1642
|
+
type: 'ready'
|
|
1643
|
+
}
|
|
1644
|
+
| {
|
|
1645
|
+
type: 'selection'
|
|
1646
|
+
selection: EditorSelection
|
|
1647
|
+
}
|
|
1648
|
+
| {
|
|
1649
|
+
type: 'value changed'
|
|
1650
|
+
value: Array<PortableTextBlock> | undefined
|
|
1651
|
+
}
|
|
1652
|
+
>,
|
|
1517
1653
|
]
|
|
1518
1654
|
}
|
|
1519
1655
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1514,6 +1514,142 @@ declare const editorMachine: StateMachine<
|
|
|
1514
1514
|
never,
|
|
1515
1515
|
never
|
|
1516
1516
|
>,
|
|
1517
|
+
ActionFunction<
|
|
1518
|
+
{
|
|
1519
|
+
behaviors: Set<BehaviorConfig>
|
|
1520
|
+
converters: Set<Converter>
|
|
1521
|
+
getLegacySchema: () => PortableTextMemberSchemaTypes
|
|
1522
|
+
keyGenerator: () => string
|
|
1523
|
+
pendingEvents: Array<InternalPatchEvent | MutationEvent>
|
|
1524
|
+
pendingIncomingPatchesEvents: Array<PatchesEvent>
|
|
1525
|
+
schema: EditorSchema
|
|
1526
|
+
initialReadOnly: boolean
|
|
1527
|
+
maxBlocks: number | undefined
|
|
1528
|
+
selection: EditorSelection
|
|
1529
|
+
initialValue: Array<PortableTextBlock> | undefined
|
|
1530
|
+
internalDrag?: {
|
|
1531
|
+
ghost?: HTMLElement
|
|
1532
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1533
|
+
}
|
|
1534
|
+
slateEditor?: PortableTextSlateEditor
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
type: 'update selection'
|
|
1538
|
+
selection: EditorSelection
|
|
1539
|
+
},
|
|
1540
|
+
| InternalPatchEvent
|
|
1541
|
+
| MutationEvent
|
|
1542
|
+
| PatchesEvent
|
|
1543
|
+
| {
|
|
1544
|
+
type: 'update readOnly'
|
|
1545
|
+
readOnly: boolean
|
|
1546
|
+
}
|
|
1547
|
+
| {
|
|
1548
|
+
type: 'update maxBlocks'
|
|
1549
|
+
maxBlocks: number | undefined
|
|
1550
|
+
}
|
|
1551
|
+
| {
|
|
1552
|
+
type: 'add behavior'
|
|
1553
|
+
behaviorConfig: BehaviorConfig
|
|
1554
|
+
}
|
|
1555
|
+
| {
|
|
1556
|
+
type: 'remove behavior'
|
|
1557
|
+
behaviorConfig: BehaviorConfig
|
|
1558
|
+
}
|
|
1559
|
+
| {
|
|
1560
|
+
type: 'blur'
|
|
1561
|
+
editor: PortableTextSlateEditor
|
|
1562
|
+
}
|
|
1563
|
+
| {
|
|
1564
|
+
type: 'focus'
|
|
1565
|
+
editor: PortableTextSlateEditor
|
|
1566
|
+
}
|
|
1567
|
+
| {
|
|
1568
|
+
type: 'normalizing'
|
|
1569
|
+
}
|
|
1570
|
+
| {
|
|
1571
|
+
type: 'update selection'
|
|
1572
|
+
selection: EditorSelection
|
|
1573
|
+
}
|
|
1574
|
+
| {
|
|
1575
|
+
type: 'done normalizing'
|
|
1576
|
+
}
|
|
1577
|
+
| {
|
|
1578
|
+
type: 'done syncing value'
|
|
1579
|
+
}
|
|
1580
|
+
| {
|
|
1581
|
+
type: 'syncing value'
|
|
1582
|
+
}
|
|
1583
|
+
| {
|
|
1584
|
+
type: 'behavior event'
|
|
1585
|
+
behaviorEvent: BehaviorEvent
|
|
1586
|
+
editor: PortableTextSlateEditor
|
|
1587
|
+
nativeEvent?: {
|
|
1588
|
+
preventDefault: () => void
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
| {
|
|
1592
|
+
type: 'dragstart'
|
|
1593
|
+
origin: Pick<EventPosition, 'selection'>
|
|
1594
|
+
ghost?: HTMLElement
|
|
1595
|
+
}
|
|
1596
|
+
| {
|
|
1597
|
+
type: 'dragend'
|
|
1598
|
+
}
|
|
1599
|
+
| {
|
|
1600
|
+
type: 'drop'
|
|
1601
|
+
},
|
|
1602
|
+
undefined,
|
|
1603
|
+
never,
|
|
1604
|
+
never,
|
|
1605
|
+
never,
|
|
1606
|
+
never,
|
|
1607
|
+
| InternalPatchEvent
|
|
1608
|
+
| MutationEvent
|
|
1609
|
+
| PatchesEvent
|
|
1610
|
+
| {
|
|
1611
|
+
type: 'blurred'
|
|
1612
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1613
|
+
}
|
|
1614
|
+
| {
|
|
1615
|
+
type: 'done loading'
|
|
1616
|
+
}
|
|
1617
|
+
| {
|
|
1618
|
+
type: 'editable'
|
|
1619
|
+
}
|
|
1620
|
+
| {
|
|
1621
|
+
type: 'error'
|
|
1622
|
+
name: string
|
|
1623
|
+
description: string
|
|
1624
|
+
data: unknown
|
|
1625
|
+
}
|
|
1626
|
+
| {
|
|
1627
|
+
type: 'focused'
|
|
1628
|
+
event: FocusEvent_2<HTMLDivElement, Element>
|
|
1629
|
+
}
|
|
1630
|
+
| {
|
|
1631
|
+
type: 'invalid value'
|
|
1632
|
+
resolution: InvalidValueResolution_2 | null
|
|
1633
|
+
value: Array<PortableTextBlock> | undefined
|
|
1634
|
+
}
|
|
1635
|
+
| {
|
|
1636
|
+
type: 'loading'
|
|
1637
|
+
}
|
|
1638
|
+
| {
|
|
1639
|
+
type: 'read only'
|
|
1640
|
+
}
|
|
1641
|
+
| {
|
|
1642
|
+
type: 'ready'
|
|
1643
|
+
}
|
|
1644
|
+
| {
|
|
1645
|
+
type: 'selection'
|
|
1646
|
+
selection: EditorSelection
|
|
1647
|
+
}
|
|
1648
|
+
| {
|
|
1649
|
+
type: 'value changed'
|
|
1650
|
+
value: Array<PortableTextBlock> | undefined
|
|
1651
|
+
}
|
|
1652
|
+
>,
|
|
1517
1653
|
]
|
|
1518
1654
|
}
|
|
1519
1655
|
}
|
package/lib/index.js
CHANGED
|
@@ -4597,7 +4597,7 @@ function createWithPortableTextBlockStyle(editorActor) {
|
|
|
4597
4597
|
};
|
|
4598
4598
|
}
|
|
4599
4599
|
debugWithName("plugin:withPortableTextSelections");
|
|
4600
|
-
function createWithPortableTextSelections(editorActor
|
|
4600
|
+
function createWithPortableTextSelections(editorActor) {
|
|
4601
4601
|
let prevSelection = null;
|
|
4602
4602
|
return function(editor) {
|
|
4603
4603
|
const emitPortableTextSelection = () => {
|
|
@@ -4611,11 +4611,11 @@ function createWithPortableTextSelections(editorActor, relayActor) {
|
|
|
4611
4611
|
range: editor.selection
|
|
4612
4612
|
}), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
|
|
4613
4613
|
}
|
|
4614
|
-
ptRange ?
|
|
4615
|
-
type: "selection",
|
|
4614
|
+
ptRange ? editorActor.send({
|
|
4615
|
+
type: "update selection",
|
|
4616
4616
|
selection: ptRange
|
|
4617
|
-
}) :
|
|
4618
|
-
type: "selection",
|
|
4617
|
+
}) : editorActor.send({
|
|
4618
|
+
type: "update selection",
|
|
4619
4619
|
selection: null
|
|
4620
4620
|
});
|
|
4621
4621
|
}
|
|
@@ -4719,7 +4719,7 @@ const withPlugins = (editor, options) => {
|
|
|
4719
4719
|
subscriptions: options.subscriptions
|
|
4720
4720
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
4721
4721
|
editorActor
|
|
4722
|
-
}), withPortableTextSelections = createWithPortableTextSelections(editorActor
|
|
4722
|
+
}), withPortableTextSelections = createWithPortableTextSelections(editorActor);
|
|
4723
4723
|
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
4724
4724
|
}, debug$a = debugWithName("setup");
|
|
4725
4725
|
function createSlateEditor(config) {
|
|
@@ -6764,7 +6764,12 @@ const debug$8 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
6764
6764
|
selection: ({
|
|
6765
6765
|
event
|
|
6766
6766
|
}) => event.selection
|
|
6767
|
-
})
|
|
6767
|
+
}), emit(({
|
|
6768
|
+
event
|
|
6769
|
+
}) => ({
|
|
6770
|
+
...event,
|
|
6771
|
+
type: "selection"
|
|
6772
|
+
}))]
|
|
6768
6773
|
}
|
|
6769
6774
|
},
|
|
6770
6775
|
type: "parallel",
|
|
@@ -8936,16 +8941,6 @@ function createActors(config) {
|
|
|
8936
8941
|
return () => {
|
|
8937
8942
|
subscription.unsubscribe();
|
|
8938
8943
|
};
|
|
8939
|
-
}), config.subscriptions.push(() => {
|
|
8940
|
-
const subscription = config.relayActor.on("*", (event) => {
|
|
8941
|
-
event.type === "selection" && config.editorActor.send({
|
|
8942
|
-
type: "update selection",
|
|
8943
|
-
selection: event.selection
|
|
8944
|
-
});
|
|
8945
|
-
});
|
|
8946
|
-
return () => {
|
|
8947
|
-
subscription.unsubscribe();
|
|
8948
|
-
};
|
|
8949
8944
|
}), config.subscriptions.push(() => {
|
|
8950
8945
|
const subscription = syncActor.on("*", (event) => {
|
|
8951
8946
|
switch (event.type) {
|
|
@@ -8997,6 +8992,7 @@ function createActors(config) {
|
|
|
8997
8992
|
case "mutation":
|
|
8998
8993
|
case "ready":
|
|
8999
8994
|
case "read only":
|
|
8995
|
+
case "selection":
|
|
9000
8996
|
config.relayActor.send(event);
|
|
9001
8997
|
break;
|
|
9002
8998
|
case "internal.patch":
|
|
@@ -10061,13 +10057,13 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10061
10057
|
if (normalizedSelection !== null) {
|
|
10062
10058
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
10063
10059
|
const slateRange = toSlateRange(normalizedSelection, slateEditor);
|
|
10064
|
-
slateRange && (Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") ||
|
|
10065
|
-
type: "selection",
|
|
10060
|
+
slateRange && (Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
|
|
10061
|
+
type: "update selection",
|
|
10066
10062
|
selection: normalizedSelection
|
|
10067
10063
|
}), slateEditor.onChange());
|
|
10068
10064
|
}
|
|
10069
10065
|
}
|
|
10070
|
-
}, [editorActor, propsSelection,
|
|
10066
|
+
}, [editorActor, propsSelection, slateEditor]);
|
|
10071
10067
|
useEffect(() => {
|
|
10072
10068
|
const onReady = editorActor.on("ready", () => {
|
|
10073
10069
|
rangeDecorationsActor.send({
|
|
@@ -10229,12 +10225,12 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10229
10225
|
event: event_2
|
|
10230
10226
|
});
|
|
10231
10227
|
const newSelection = PortableTextEditor.getSelection(portableTextEditor);
|
|
10232
|
-
selection_3 === newSelection &&
|
|
10233
|
-
type: "selection",
|
|
10228
|
+
selection_3 === newSelection && editorActor.send({
|
|
10229
|
+
type: "update selection",
|
|
10234
10230
|
selection: selection_3
|
|
10235
10231
|
});
|
|
10236
10232
|
}
|
|
10237
|
-
}, [onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = useCallback((event_3) => {
|
|
10233
|
+
}, [editorActor, onFocus, slateEditor, portableTextEditor, relayActor]), handleClick = useCallback((event_3) => {
|
|
10238
10234
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10239
10235
|
return;
|
|
10240
10236
|
const position_3 = getEventPosition({
|