@portabletext/editor 2.6.7 → 2.6.9
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-dts/behavior.types.action.d.cts +9 -9
- package/lib/_chunks-dts/behavior.types.action.d.ts +9 -9
- package/lib/index.cjs +69 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +70 -16
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.cts +2 -2
- package/package.json +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +53 -0
- package/src/editor/__tests__/self-solving.test.tsx +1 -33
- package/src/editor/mutation-machine.ts +11 -14
- package/src/editor/plugins/createWithPatches.ts +2 -2
- package/src/internal-utils/build-index-maps.test.ts +119 -0
- package/src/internal-utils/build-index-maps.ts +14 -2
- package/src/operations/behavior.operation.delete.ts +1 -1
|
@@ -6,7 +6,7 @@ import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObject
|
|
|
6
6
|
import * as xstate227 from "xstate";
|
|
7
7
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
8
8
|
import { BaseRange, Descendant, Operation } from "slate";
|
|
9
|
-
import * as
|
|
9
|
+
import * as react20 from "react";
|
|
10
10
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
11
11
|
import * as xstate_guards12 from "xstate/guards";
|
|
12
12
|
import { Observable, Subject } from "rxjs";
|
|
@@ -215,7 +215,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
|
|
|
215
215
|
componentDidUpdate(prevProps: PortableTextEditorProps): void;
|
|
216
216
|
componentWillUnmount(): void;
|
|
217
217
|
setEditable: (editable: EditableAPI) => void;
|
|
218
|
-
render():
|
|
218
|
+
render(): react20.JSX.Element;
|
|
219
219
|
/**
|
|
220
220
|
* @deprecated
|
|
221
221
|
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
@@ -610,7 +610,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
610
610
|
* ```
|
|
611
611
|
* @group Components
|
|
612
612
|
*/
|
|
613
|
-
declare const PortableTextEditable:
|
|
613
|
+
declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
614
614
|
type DecoratedRange = BaseRange & {
|
|
615
615
|
rangeDecoration: RangeDecoration;
|
|
616
616
|
};
|
|
@@ -1339,7 +1339,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1339
1339
|
initialValue?: Array<PortableTextBlock>;
|
|
1340
1340
|
}, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1341
1341
|
type: "blurred";
|
|
1342
|
-
event:
|
|
1342
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
1343
1343
|
} | {
|
|
1344
1344
|
type: "done loading";
|
|
1345
1345
|
} | {
|
|
@@ -1351,7 +1351,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1351
1351
|
data: unknown;
|
|
1352
1352
|
} | {
|
|
1353
1353
|
type: "focused";
|
|
1354
|
-
event:
|
|
1354
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
1355
1355
|
} | {
|
|
1356
1356
|
type: "invalid value";
|
|
1357
1357
|
resolution: InvalidValueResolution | null;
|
|
@@ -2007,7 +2007,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2007
2007
|
type: "drop";
|
|
2008
2008
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2009
2009
|
type: "blurred";
|
|
2010
|
-
event:
|
|
2010
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2011
2011
|
} | {
|
|
2012
2012
|
type: "done loading";
|
|
2013
2013
|
} | {
|
|
@@ -2019,7 +2019,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2019
2019
|
data: unknown;
|
|
2020
2020
|
} | {
|
|
2021
2021
|
type: "focused";
|
|
2022
|
-
event:
|
|
2022
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2023
2023
|
} | {
|
|
2024
2024
|
type: "invalid value";
|
|
2025
2025
|
resolution: InvalidValueResolution | null;
|
|
@@ -2890,7 +2890,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2890
2890
|
type: "drop";
|
|
2891
2891
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2892
2892
|
type: "blurred";
|
|
2893
|
-
event:
|
|
2893
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2894
2894
|
} | {
|
|
2895
2895
|
type: "done loading";
|
|
2896
2896
|
} | {
|
|
@@ -2902,7 +2902,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2902
2902
|
data: unknown;
|
|
2903
2903
|
} | {
|
|
2904
2904
|
type: "focused";
|
|
2905
|
-
event:
|
|
2905
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2906
2906
|
} | {
|
|
2907
2907
|
type: "invalid value";
|
|
2908
2908
|
resolution: InvalidValueResolution | null;
|
|
@@ -6,7 +6,7 @@ import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObject
|
|
|
6
6
|
import * as xstate227 from "xstate";
|
|
7
7
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
8
8
|
import { BaseRange, Descendant, Operation } from "slate";
|
|
9
|
-
import * as
|
|
9
|
+
import * as react22 from "react";
|
|
10
10
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
11
11
|
import * as xstate_guards12 from "xstate/guards";
|
|
12
12
|
import { Observable, Subject } from "rxjs";
|
|
@@ -215,7 +215,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
|
|
|
215
215
|
componentDidUpdate(prevProps: PortableTextEditorProps): void;
|
|
216
216
|
componentWillUnmount(): void;
|
|
217
217
|
setEditable: (editable: EditableAPI) => void;
|
|
218
|
-
render():
|
|
218
|
+
render(): react22.JSX.Element;
|
|
219
219
|
/**
|
|
220
220
|
* @deprecated
|
|
221
221
|
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
@@ -610,7 +610,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
610
610
|
* ```
|
|
611
611
|
* @group Components
|
|
612
612
|
*/
|
|
613
|
-
declare const PortableTextEditable:
|
|
613
|
+
declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
614
614
|
type DecoratedRange = BaseRange & {
|
|
615
615
|
rangeDecoration: RangeDecoration;
|
|
616
616
|
};
|
|
@@ -1339,7 +1339,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1339
1339
|
initialValue?: Array<PortableTextBlock>;
|
|
1340
1340
|
}, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1341
1341
|
type: "blurred";
|
|
1342
|
-
event:
|
|
1342
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
1343
1343
|
} | {
|
|
1344
1344
|
type: "done loading";
|
|
1345
1345
|
} | {
|
|
@@ -1351,7 +1351,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
1351
1351
|
data: unknown;
|
|
1352
1352
|
} | {
|
|
1353
1353
|
type: "focused";
|
|
1354
|
-
event:
|
|
1354
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
1355
1355
|
} | {
|
|
1356
1356
|
type: "invalid value";
|
|
1357
1357
|
resolution: InvalidValueResolution | null;
|
|
@@ -2007,7 +2007,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2007
2007
|
type: "drop";
|
|
2008
2008
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2009
2009
|
type: "blurred";
|
|
2010
|
-
event:
|
|
2010
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2011
2011
|
} | {
|
|
2012
2012
|
type: "done loading";
|
|
2013
2013
|
} | {
|
|
@@ -2019,7 +2019,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2019
2019
|
data: unknown;
|
|
2020
2020
|
} | {
|
|
2021
2021
|
type: "focused";
|
|
2022
|
-
event:
|
|
2022
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2023
2023
|
} | {
|
|
2024
2024
|
type: "invalid value";
|
|
2025
2025
|
resolution: InvalidValueResolution | null;
|
|
@@ -2890,7 +2890,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2890
2890
|
type: "drop";
|
|
2891
2891
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2892
2892
|
type: "blurred";
|
|
2893
|
-
event:
|
|
2893
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2894
2894
|
} | {
|
|
2895
2895
|
type: "done loading";
|
|
2896
2896
|
} | {
|
|
@@ -2902,7 +2902,7 @@ declare const editorMachine: xstate227.StateMachine<{
|
|
|
2902
2902
|
data: unknown;
|
|
2903
2903
|
} | {
|
|
2904
2904
|
type: "focused";
|
|
2905
|
-
event:
|
|
2905
|
+
event: react22.FocusEvent<HTMLDivElement, Element>;
|
|
2906
2906
|
} | {
|
|
2907
2907
|
type: "invalid value";
|
|
2908
2908
|
resolution: InvalidValueResolution | null;
|
package/lib/index.cjs
CHANGED
|
@@ -1323,10 +1323,17 @@ function buildIndexMaps(context, {
|
|
|
1323
1323
|
continue;
|
|
1324
1324
|
}
|
|
1325
1325
|
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
1326
|
-
listItem
|
|
1326
|
+
if (listItem === block.listItem)
|
|
1327
|
+
return;
|
|
1328
|
+
const levelsToDelete = [];
|
|
1329
|
+
levelIndexMap2.forEach((_, level) => {
|
|
1330
|
+
level >= block.level && levelsToDelete.push(level);
|
|
1331
|
+
}), levelsToDelete.forEach((level) => {
|
|
1332
|
+
levelIndexMap2.delete(level);
|
|
1333
|
+
});
|
|
1327
1334
|
});
|
|
1328
1335
|
const levelIndexMap = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map(), levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
1329
|
-
levelIndexMap.set(block.level, levelCounter + 1), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
1336
|
+
levelIndexMap.set(block.level, levelCounter + 1), levelIndexMaps.set(block.listItem, levelIndexMap), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
1330
1337
|
listItem: block.listItem,
|
|
1331
1338
|
level: block.level
|
|
1332
1339
|
};
|
|
@@ -4875,7 +4882,7 @@ function createWithPatches({
|
|
|
4875
4882
|
...patch,
|
|
4876
4883
|
origin: "local"
|
|
4877
4884
|
},
|
|
4878
|
-
operationId:
|
|
4885
|
+
operationId: getCurrentUndoStepId(editor),
|
|
4879
4886
|
value: editor.value
|
|
4880
4887
|
});
|
|
4881
4888
|
return editor;
|
|
@@ -6756,6 +6763,51 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
6756
6763
|
unit: event.unit,
|
|
6757
6764
|
at: selection
|
|
6758
6765
|
})]]
|
|
6766
|
+
}), behaviors_index.defineBehavior({
|
|
6767
|
+
on: "delete",
|
|
6768
|
+
guard: ({
|
|
6769
|
+
snapshot,
|
|
6770
|
+
event
|
|
6771
|
+
}) => {
|
|
6772
|
+
if (event.direction !== "forward")
|
|
6773
|
+
return !1;
|
|
6774
|
+
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock({
|
|
6775
|
+
...snapshot,
|
|
6776
|
+
context: {
|
|
6777
|
+
...snapshot.context,
|
|
6778
|
+
selection: event.at
|
|
6779
|
+
}
|
|
6780
|
+
}), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
|
|
6781
|
+
...snapshot,
|
|
6782
|
+
context: {
|
|
6783
|
+
...snapshot.context,
|
|
6784
|
+
selection: event.at
|
|
6785
|
+
}
|
|
6786
|
+
});
|
|
6787
|
+
if (!nextBlock || !focusTextBlock || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
6788
|
+
return !1;
|
|
6789
|
+
const nextBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
6790
|
+
context: snapshot.context,
|
|
6791
|
+
block: nextBlock
|
|
6792
|
+
});
|
|
6793
|
+
return {
|
|
6794
|
+
focusTextBlock,
|
|
6795
|
+
nextBlockStartPoint
|
|
6796
|
+
};
|
|
6797
|
+
},
|
|
6798
|
+
actions: [(_, {
|
|
6799
|
+
focusTextBlock,
|
|
6800
|
+
nextBlockStartPoint
|
|
6801
|
+
}) => [behaviors_index.raise({
|
|
6802
|
+
type: "delete.block",
|
|
6803
|
+
at: focusTextBlock.path
|
|
6804
|
+
}), behaviors_index.raise({
|
|
6805
|
+
type: "select",
|
|
6806
|
+
at: {
|
|
6807
|
+
anchor: nextBlockStartPoint,
|
|
6808
|
+
focus: nextBlockStartPoint
|
|
6809
|
+
}
|
|
6810
|
+
})]]
|
|
6759
6811
|
}), behaviors_index.defineBehavior({
|
|
6760
6812
|
on: "delete",
|
|
6761
6813
|
guard: ({
|
|
@@ -8644,14 +8696,14 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
8644
8696
|
input.slateEditor.apply = originalApply;
|
|
8645
8697
|
};
|
|
8646
8698
|
}),
|
|
8647
|
-
"mutation
|
|
8699
|
+
"mutation interval": xstate.fromCallback(({
|
|
8648
8700
|
sendBack
|
|
8649
8701
|
}) => {
|
|
8650
8702
|
const interval = setInterval(() => {
|
|
8651
8703
|
sendBack({
|
|
8652
|
-
type: "
|
|
8704
|
+
type: "emit changes"
|
|
8653
8705
|
});
|
|
8654
|
-
}, process.env.NODE_ENV === "test" ? 250 :
|
|
8706
|
+
}, process.env.NODE_ENV === "test" ? 250 : 1e3);
|
|
8655
8707
|
return () => {
|
|
8656
8708
|
clearInterval(interval);
|
|
8657
8709
|
};
|
|
@@ -8661,15 +8713,12 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
8661
8713
|
"is read-only": ({
|
|
8662
8714
|
context
|
|
8663
8715
|
}) => context.readOnly,
|
|
8664
|
-
"is typing": xstate.stateIn({
|
|
8665
|
-
typing: "typing"
|
|
8666
|
-
}),
|
|
8667
8716
|
"slate is normalizing": ({
|
|
8668
8717
|
context
|
|
8669
8718
|
}) => slate.Editor.isNormalizing(context.slateEditor)
|
|
8670
8719
|
},
|
|
8671
8720
|
delays: {
|
|
8672
|
-
"type debounce":
|
|
8721
|
+
"type debounce": 250
|
|
8673
8722
|
}
|
|
8674
8723
|
}).createMachine({
|
|
8675
8724
|
id: "mutation",
|
|
@@ -8717,14 +8766,19 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
8717
8766
|
after: {
|
|
8718
8767
|
"type debounce": {
|
|
8719
8768
|
target: "idle",
|
|
8720
|
-
actions: [(
|
|
8769
|
+
actions: [xstate.raise({
|
|
8770
|
+
type: "emit changes"
|
|
8771
|
+
}), () => {
|
|
8721
8772
|
debug$6("exit: typing->typing");
|
|
8722
8773
|
}]
|
|
8723
8774
|
}
|
|
8724
8775
|
},
|
|
8725
8776
|
on: {
|
|
8726
8777
|
"not typing": {
|
|
8727
|
-
target: "idle"
|
|
8778
|
+
target: "idle",
|
|
8779
|
+
actions: [xstate.raise({
|
|
8780
|
+
type: "emit changes"
|
|
8781
|
+
})]
|
|
8728
8782
|
},
|
|
8729
8783
|
typing: {
|
|
8730
8784
|
target: "typing",
|
|
@@ -8763,11 +8817,11 @@ const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
8763
8817
|
debug$6("exit: mutations->has pending mutations");
|
|
8764
8818
|
}],
|
|
8765
8819
|
invoke: {
|
|
8766
|
-
src: "mutation
|
|
8820
|
+
src: "mutation interval"
|
|
8767
8821
|
},
|
|
8768
8822
|
on: {
|
|
8769
|
-
"
|
|
8770
|
-
guard: xstate.and([xstate.not("is read-only"),
|
|
8823
|
+
"emit changes": {
|
|
8824
|
+
guard: xstate.and([xstate.not("is read-only"), "slate is normalizing"]),
|
|
8771
8825
|
target: "idle",
|
|
8772
8826
|
actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
|
|
8773
8827
|
},
|