@portabletext/editor 1.54.3 → 1.54.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +98 -105
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +6 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +98 -105
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/src/editor/Editable.tsx +4 -8
- package/src/editor/create-slate-editor.tsx +1 -0
- package/src/editor/plugins/createWithPlaceholderBlock.ts +14 -14
- package/src/editor/range-decorations-machine.ts +138 -157
- package/src/types/editor.ts +2 -0
package/lib/index.cjs
CHANGED
|
@@ -4656,13 +4656,10 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4656
4656
|
return;
|
|
4657
4657
|
}
|
|
4658
4658
|
if (op.type === "remove_node") {
|
|
4659
|
-
const
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
decorators: []
|
|
4664
|
-
})));
|
|
4665
|
-
}
|
|
4659
|
+
const blockIndex = op.path.at(0), isLonelyBlock = op.path.length === 1 && blockIndex === 0 && editor.children.length === 1, isBlockObject = op.node._type !== editorActor.getSnapshot().context.schema.block.name;
|
|
4660
|
+
isLonelyBlock && isBlockObject && (debug$b("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
4661
|
+
decorators: []
|
|
4662
|
+
})));
|
|
4666
4663
|
}
|
|
4667
4664
|
apply2(op);
|
|
4668
4665
|
}, editor;
|
|
@@ -5189,7 +5186,7 @@ function createSlateEditor(config) {
|
|
|
5189
5186
|
relayActor: config.relayActor,
|
|
5190
5187
|
subscriptions: config.subscriptions
|
|
5191
5188
|
});
|
|
5192
|
-
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)];
|
|
5189
|
+
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {}, instance.markState = void 0, instance.value = [createPlaceholderBlock(config.editorActor.getSnapshot().context)];
|
|
5193
5190
|
const initialValue = toSlateValue(instance.value, {
|
|
5194
5191
|
schemaTypes: config.editorActor.getSnapshot().context.schema
|
|
5195
5192
|
});
|
|
@@ -10541,111 +10538,107 @@ const slateOperationCallback = ({
|
|
|
10541
10538
|
event
|
|
10542
10539
|
}) => event.type !== "range decorations updated" ? context.pendingRangeDecorations : event.rangeDecorations
|
|
10543
10540
|
}),
|
|
10544
|
-
"set up initial range decorations":
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
newSelection: null,
|
|
10554
|
-
rangeDecoration,
|
|
10555
|
-
origin: "local"
|
|
10556
|
-
});
|
|
10557
|
-
continue;
|
|
10558
|
-
}
|
|
10559
|
-
rangeDecorationState.push({
|
|
10541
|
+
"set up initial range decorations": ({
|
|
10542
|
+
context
|
|
10543
|
+
}) => {
|
|
10544
|
+
const rangeDecorationState = [];
|
|
10545
|
+
for (const rangeDecoration of context.pendingRangeDecorations) {
|
|
10546
|
+
const slateRange = toSlateRange(rangeDecoration.selection, context.slateEditor);
|
|
10547
|
+
if (!slate.Range.isRange(slateRange)) {
|
|
10548
|
+
rangeDecoration.onMoved?.({
|
|
10549
|
+
newSelection: null,
|
|
10560
10550
|
rangeDecoration,
|
|
10561
|
-
|
|
10551
|
+
origin: "local"
|
|
10562
10552
|
});
|
|
10553
|
+
continue;
|
|
10563
10554
|
}
|
|
10564
|
-
|
|
10555
|
+
rangeDecorationState.push({
|
|
10556
|
+
rangeDecoration,
|
|
10557
|
+
...slateRange
|
|
10558
|
+
});
|
|
10565
10559
|
}
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
rangeDecoration,
|
|
10581
|
-
origin: "local"
|
|
10582
|
-
});
|
|
10583
|
-
continue;
|
|
10584
|
-
}
|
|
10585
|
-
rangeDecorationState.push({
|
|
10560
|
+
context.slateEditor.decoratedRanges = rangeDecorationState;
|
|
10561
|
+
},
|
|
10562
|
+
"update range decorations": ({
|
|
10563
|
+
context,
|
|
10564
|
+
event
|
|
10565
|
+
}) => {
|
|
10566
|
+
if (event.type !== "range decorations updated")
|
|
10567
|
+
return;
|
|
10568
|
+
const rangeDecorationState = [];
|
|
10569
|
+
for (const rangeDecoration of event.rangeDecorations) {
|
|
10570
|
+
const slateRange = toSlateRange(rangeDecoration.selection, context.slateEditor);
|
|
10571
|
+
if (!slate.Range.isRange(slateRange)) {
|
|
10572
|
+
rangeDecoration.onMoved?.({
|
|
10573
|
+
newSelection: null,
|
|
10586
10574
|
rangeDecoration,
|
|
10587
|
-
|
|
10575
|
+
origin: "local"
|
|
10588
10576
|
});
|
|
10577
|
+
continue;
|
|
10589
10578
|
}
|
|
10590
|
-
|
|
10579
|
+
rangeDecorationState.push({
|
|
10580
|
+
rangeDecoration,
|
|
10581
|
+
...slateRange
|
|
10582
|
+
});
|
|
10591
10583
|
}
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10584
|
+
context.slateEditor.decoratedRanges = rangeDecorationState;
|
|
10585
|
+
},
|
|
10586
|
+
"move range decorations": ({
|
|
10587
|
+
context,
|
|
10588
|
+
event
|
|
10589
|
+
}) => {
|
|
10590
|
+
if (event.type !== "slate operation")
|
|
10591
|
+
return;
|
|
10592
|
+
const rangeDecorationState = [];
|
|
10593
|
+
for (const decoratedRange of context.slateEditor.decoratedRanges) {
|
|
10594
|
+
const slateRange = toSlateRange(decoratedRange.rangeDecoration.selection, context.slateEditor);
|
|
10595
|
+
if (!slate.Range.isRange(slateRange)) {
|
|
10596
|
+
decoratedRange.rangeDecoration.onMoved?.({
|
|
10597
|
+
newSelection: null,
|
|
10598
|
+
rangeDecoration: decoratedRange.rangeDecoration,
|
|
10599
|
+
origin: "local"
|
|
10600
|
+
});
|
|
10601
|
+
continue;
|
|
10602
|
+
}
|
|
10603
|
+
let newRange;
|
|
10604
|
+
if (newRange = moveRangeByOperation(slateRange, event.operation), newRange && newRange !== slateRange || newRange === null && slateRange) {
|
|
10605
|
+
const newRangeSelection = newRange ? slateRangeToSelection({
|
|
10606
|
+
schema: context.schema,
|
|
10607
|
+
editor: context.slateEditor,
|
|
10608
|
+
range: newRange
|
|
10609
|
+
}) : null;
|
|
10610
|
+
decoratedRange.rangeDecoration.onMoved?.({
|
|
10611
|
+
newSelection: newRangeSelection,
|
|
10612
|
+
rangeDecoration: decoratedRange.rangeDecoration,
|
|
10613
|
+
origin: "local"
|
|
10614
|
+
});
|
|
10615
|
+
}
|
|
10616
|
+
newRange !== null && rangeDecorationState.push({
|
|
10617
|
+
...newRange || slateRange,
|
|
10618
|
+
rangeDecoration: {
|
|
10619
|
+
...decoratedRange.rangeDecoration,
|
|
10620
|
+
selection: slateRangeToSelection({
|
|
10614
10621
|
schema: context.schema,
|
|
10615
10622
|
editor: context.slateEditor,
|
|
10616
10623
|
range: newRange
|
|
10617
|
-
})
|
|
10618
|
-
decoratedRange.rangeDecoration.onMoved?.({
|
|
10619
|
-
newSelection: newRangeSelection,
|
|
10620
|
-
rangeDecoration: decoratedRange.rangeDecoration,
|
|
10621
|
-
origin: "local"
|
|
10622
|
-
});
|
|
10624
|
+
})
|
|
10623
10625
|
}
|
|
10624
|
-
|
|
10625
|
-
...newRange || slateRange,
|
|
10626
|
-
rangeDecoration: {
|
|
10627
|
-
...decoratedRange.rangeDecoration,
|
|
10628
|
-
selection: slateRangeToSelection({
|
|
10629
|
-
schema: context.schema,
|
|
10630
|
-
editor: context.slateEditor,
|
|
10631
|
-
range: newRange
|
|
10632
|
-
})
|
|
10633
|
-
}
|
|
10634
|
-
});
|
|
10635
|
-
}
|
|
10636
|
-
return rangeDecorationState;
|
|
10626
|
+
});
|
|
10637
10627
|
}
|
|
10638
|
-
|
|
10628
|
+
context.slateEditor.decoratedRanges = rangeDecorationState;
|
|
10629
|
+
},
|
|
10639
10630
|
"assign readOnly": xstate.assign({
|
|
10640
10631
|
readOnly: ({
|
|
10641
10632
|
context,
|
|
10642
10633
|
event
|
|
10643
10634
|
}) => event.type !== "update read only" ? context.readOnly : event.readOnly
|
|
10644
10635
|
}),
|
|
10645
|
-
"
|
|
10646
|
-
|
|
10636
|
+
"update decorate": xstate.assign({
|
|
10637
|
+
decorate: ({
|
|
10647
10638
|
context
|
|
10648
|
-
}) =>
|
|
10639
|
+
}) => ({
|
|
10640
|
+
fn: createDecorate(context.schema, context.slateEditor)
|
|
10641
|
+
})
|
|
10649
10642
|
})
|
|
10650
10643
|
},
|
|
10651
10644
|
actors: {
|
|
@@ -10657,14 +10650,14 @@ const slateOperationCallback = ({
|
|
|
10657
10650
|
}) => context.pendingRangeDecorations.length > 0,
|
|
10658
10651
|
"has range decorations": ({
|
|
10659
10652
|
context
|
|
10660
|
-
}) => context.decoratedRanges.length > 0,
|
|
10653
|
+
}) => context.slateEditor.decoratedRanges.length > 0,
|
|
10661
10654
|
"has different decorations": ({
|
|
10662
10655
|
context,
|
|
10663
10656
|
event
|
|
10664
10657
|
}) => {
|
|
10665
10658
|
if (event.type !== "range decorations updated")
|
|
10666
10659
|
return !1;
|
|
10667
|
-
const existingRangeDecorations = context.decoratedRanges.map((decoratedRange) => ({
|
|
10660
|
+
const existingRangeDecorations = context.slateEditor.decoratedRanges.map((decoratedRange) => ({
|
|
10668
10661
|
anchor: decoratedRange.rangeDecoration.selection?.anchor,
|
|
10669
10662
|
focus: decoratedRange.rangeDecoration.selection?.focus
|
|
10670
10663
|
})), newRangeDecorations = event.rangeDecorations.map((rangeDecoration) => ({
|
|
@@ -10691,7 +10684,9 @@ const slateOperationCallback = ({
|
|
|
10691
10684
|
skipSetup: input.skipSetup,
|
|
10692
10685
|
schema: input.schema,
|
|
10693
10686
|
slateEditor: input.slateEditor,
|
|
10694
|
-
|
|
10687
|
+
decorate: {
|
|
10688
|
+
fn: createDecorate(input.schema, input.slateEditor)
|
|
10689
|
+
}
|
|
10695
10690
|
}),
|
|
10696
10691
|
invoke: {
|
|
10697
10692
|
src: "slate operation listener",
|
|
@@ -10712,7 +10707,7 @@ const slateOperationCallback = ({
|
|
|
10712
10707
|
always: [{
|
|
10713
10708
|
guard: xstate.and(["should skip setup", "has pending range decorations"]),
|
|
10714
10709
|
target: "ready",
|
|
10715
|
-
actions: ["set up initial range decorations", "
|
|
10710
|
+
actions: ["set up initial range decorations", "update decorate"]
|
|
10716
10711
|
}, {
|
|
10717
10712
|
guard: "should skip setup",
|
|
10718
10713
|
target: "ready"
|
|
@@ -10724,7 +10719,7 @@ const slateOperationCallback = ({
|
|
|
10724
10719
|
ready: [{
|
|
10725
10720
|
target: "ready",
|
|
10726
10721
|
guard: "has pending range decorations",
|
|
10727
|
-
actions: ["set up initial range decorations", "
|
|
10722
|
+
actions: ["set up initial range decorations", "update decorate"]
|
|
10728
10723
|
}, {
|
|
10729
10724
|
target: "ready"
|
|
10730
10725
|
}]
|
|
@@ -10736,7 +10731,7 @@ const slateOperationCallback = ({
|
|
|
10736
10731
|
"range decorations updated": {
|
|
10737
10732
|
target: ".idle",
|
|
10738
10733
|
guard: "has different decorations",
|
|
10739
|
-
actions: ["update range decorations", "
|
|
10734
|
+
actions: ["update range decorations", "update decorate"]
|
|
10740
10735
|
}
|
|
10741
10736
|
},
|
|
10742
10737
|
states: {
|
|
@@ -10758,9 +10753,9 @@ const slateOperationCallback = ({
|
|
|
10758
10753
|
}
|
|
10759
10754
|
}
|
|
10760
10755
|
});
|
|
10761
|
-
function createDecorate(
|
|
10756
|
+
function createDecorate(schema2, slateEditor) {
|
|
10762
10757
|
return function([node, path]) {
|
|
10763
|
-
if (isEqualToEmptyEditor(
|
|
10758
|
+
if (isEqualToEmptyEditor(slateEditor.children, schema2))
|
|
10764
10759
|
return [{
|
|
10765
10760
|
anchor: {
|
|
10766
10761
|
path: [0, 0],
|
|
@@ -10777,7 +10772,7 @@ function createDecorate(rangeDecorationActor) {
|
|
|
10777
10772
|
if (!slate.Element.isElement(node) || node.children.length === 0)
|
|
10778
10773
|
return [];
|
|
10779
10774
|
const blockIndex = path.at(0);
|
|
10780
|
-
return blockIndex === void 0 ? [] :
|
|
10775
|
+
return blockIndex === void 0 ? [] : slateEditor.decoratedRanges.filter((decoratedRange) => slate.Range.isCollapsed(decoratedRange) ? node.children.some((_, childIndex) => slate.Path.equals(decoratedRange.anchor.path, [blockIndex, childIndex]) && slate.Path.equals(decoratedRange.focus.path, [blockIndex, childIndex])) : slate.Range.intersection(decoratedRange, {
|
|
10781
10776
|
anchor: {
|
|
10782
10777
|
path,
|
|
10783
10778
|
offset: 0
|
|
@@ -10832,9 +10827,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10832
10827
|
setup: "setting up"
|
|
10833
10828
|
})
|
|
10834
10829
|
}
|
|
10835
|
-
});
|
|
10836
|
-
react.useSelector(rangeDecorationsActor, (s_0) => s_0.context.updateCount);
|
|
10837
|
-
const decorate = React.useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
10830
|
+
}), decorate = react.useSelector(rangeDecorationsActor, (s_0) => s_0.context.decorate?.fn);
|
|
10838
10831
|
React.useEffect(() => {
|
|
10839
10832
|
rangeDecorationsActor.send({
|
|
10840
10833
|
type: "update read only",
|