@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
package/lib/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
|
20
20
|
import uniq from "lodash/uniq.js";
|
|
21
21
|
import { Subject } from "rxjs";
|
|
22
22
|
import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
|
|
23
|
-
import { setup, assign, enqueueActions, emit, assertEvent,
|
|
23
|
+
import { setup, assign, enqueueActions, emit, assertEvent, fromCallback, and, raise as raise$1, not, createActor } from "xstate";
|
|
24
24
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
25
25
|
import { toHTML } from "@portabletext/to-html";
|
|
26
26
|
import { Schema } from "@sanity/schema";
|
|
@@ -1353,10 +1353,17 @@ function buildIndexMaps(context, {
|
|
|
1353
1353
|
continue;
|
|
1354
1354
|
}
|
|
1355
1355
|
levelIndexMaps.forEach((levelIndexMap2, listItem) => {
|
|
1356
|
-
listItem
|
|
1356
|
+
if (listItem === block.listItem)
|
|
1357
|
+
return;
|
|
1358
|
+
const levelsToDelete = [];
|
|
1359
|
+
levelIndexMap2.forEach((_, level) => {
|
|
1360
|
+
level >= block.level && levelsToDelete.push(level);
|
|
1361
|
+
}), levelsToDelete.forEach((level) => {
|
|
1362
|
+
levelIndexMap2.delete(level);
|
|
1363
|
+
});
|
|
1357
1364
|
});
|
|
1358
1365
|
const levelIndexMap = levelIndexMaps.get(block.listItem) ?? /* @__PURE__ */ new Map(), levelCounter = levelIndexMap.get(block.level) ?? 0;
|
|
1359
|
-
levelIndexMap.set(block.level, levelCounter + 1), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
1366
|
+
levelIndexMap.set(block.level, levelCounter + 1), levelIndexMaps.set(block.listItem, levelIndexMap), listIndexMap.set(block._key, levelCounter + 1), previousListItem = {
|
|
1360
1367
|
listItem: block.listItem,
|
|
1361
1368
|
level: block.level
|
|
1362
1369
|
};
|
|
@@ -4905,7 +4912,7 @@ function createWithPatches({
|
|
|
4905
4912
|
...patch,
|
|
4906
4913
|
origin: "local"
|
|
4907
4914
|
},
|
|
4908
|
-
operationId:
|
|
4915
|
+
operationId: getCurrentUndoStepId(editor),
|
|
4909
4916
|
value: editor.value
|
|
4910
4917
|
});
|
|
4911
4918
|
return editor;
|
|
@@ -6786,6 +6793,51 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
6786
6793
|
unit: event.unit,
|
|
6787
6794
|
at: selection
|
|
6788
6795
|
})]]
|
|
6796
|
+
}), defineBehavior({
|
|
6797
|
+
on: "delete",
|
|
6798
|
+
guard: ({
|
|
6799
|
+
snapshot,
|
|
6800
|
+
event
|
|
6801
|
+
}) => {
|
|
6802
|
+
if (event.direction !== "forward")
|
|
6803
|
+
return !1;
|
|
6804
|
+
const nextBlock = getNextBlock({
|
|
6805
|
+
...snapshot,
|
|
6806
|
+
context: {
|
|
6807
|
+
...snapshot.context,
|
|
6808
|
+
selection: event.at
|
|
6809
|
+
}
|
|
6810
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
6811
|
+
...snapshot,
|
|
6812
|
+
context: {
|
|
6813
|
+
...snapshot.context,
|
|
6814
|
+
selection: event.at
|
|
6815
|
+
}
|
|
6816
|
+
});
|
|
6817
|
+
if (!nextBlock || !focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
6818
|
+
return !1;
|
|
6819
|
+
const nextBlockStartPoint = getBlockStartPoint({
|
|
6820
|
+
context: snapshot.context,
|
|
6821
|
+
block: nextBlock
|
|
6822
|
+
});
|
|
6823
|
+
return {
|
|
6824
|
+
focusTextBlock,
|
|
6825
|
+
nextBlockStartPoint
|
|
6826
|
+
};
|
|
6827
|
+
},
|
|
6828
|
+
actions: [(_, {
|
|
6829
|
+
focusTextBlock,
|
|
6830
|
+
nextBlockStartPoint
|
|
6831
|
+
}) => [raise({
|
|
6832
|
+
type: "delete.block",
|
|
6833
|
+
at: focusTextBlock.path
|
|
6834
|
+
}), raise({
|
|
6835
|
+
type: "select",
|
|
6836
|
+
at: {
|
|
6837
|
+
anchor: nextBlockStartPoint,
|
|
6838
|
+
focus: nextBlockStartPoint
|
|
6839
|
+
}
|
|
6840
|
+
})]]
|
|
6789
6841
|
}), defineBehavior({
|
|
6790
6842
|
on: "delete",
|
|
6791
6843
|
guard: ({
|
|
@@ -8674,14 +8726,14 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
8674
8726
|
input.slateEditor.apply = originalApply;
|
|
8675
8727
|
};
|
|
8676
8728
|
}),
|
|
8677
|
-
"mutation
|
|
8729
|
+
"mutation interval": fromCallback(({
|
|
8678
8730
|
sendBack
|
|
8679
8731
|
}) => {
|
|
8680
8732
|
const interval = setInterval(() => {
|
|
8681
8733
|
sendBack({
|
|
8682
|
-
type: "
|
|
8734
|
+
type: "emit changes"
|
|
8683
8735
|
});
|
|
8684
|
-
}, process.env.NODE_ENV === "test" ? 250 :
|
|
8736
|
+
}, process.env.NODE_ENV === "test" ? 250 : 1e3);
|
|
8685
8737
|
return () => {
|
|
8686
8738
|
clearInterval(interval);
|
|
8687
8739
|
};
|
|
@@ -8691,15 +8743,12 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
8691
8743
|
"is read-only": ({
|
|
8692
8744
|
context
|
|
8693
8745
|
}) => context.readOnly,
|
|
8694
|
-
"is typing": stateIn({
|
|
8695
|
-
typing: "typing"
|
|
8696
|
-
}),
|
|
8697
8746
|
"slate is normalizing": ({
|
|
8698
8747
|
context
|
|
8699
8748
|
}) => Editor.isNormalizing(context.slateEditor)
|
|
8700
8749
|
},
|
|
8701
8750
|
delays: {
|
|
8702
|
-
"type debounce":
|
|
8751
|
+
"type debounce": 250
|
|
8703
8752
|
}
|
|
8704
8753
|
}).createMachine({
|
|
8705
8754
|
id: "mutation",
|
|
@@ -8747,14 +8796,19 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
8747
8796
|
after: {
|
|
8748
8797
|
"type debounce": {
|
|
8749
8798
|
target: "idle",
|
|
8750
|
-
actions: [(
|
|
8799
|
+
actions: [raise$1({
|
|
8800
|
+
type: "emit changes"
|
|
8801
|
+
}), () => {
|
|
8751
8802
|
debug$6("exit: typing->typing");
|
|
8752
8803
|
}]
|
|
8753
8804
|
}
|
|
8754
8805
|
},
|
|
8755
8806
|
on: {
|
|
8756
8807
|
"not typing": {
|
|
8757
|
-
target: "idle"
|
|
8808
|
+
target: "idle",
|
|
8809
|
+
actions: [raise$1({
|
|
8810
|
+
type: "emit changes"
|
|
8811
|
+
})]
|
|
8758
8812
|
},
|
|
8759
8813
|
typing: {
|
|
8760
8814
|
target: "typing",
|
|
@@ -8793,11 +8847,11 @@ const debug$7 = debugWithName("editor machine"), editorMachine = setup({
|
|
|
8793
8847
|
debug$6("exit: mutations->has pending mutations");
|
|
8794
8848
|
}],
|
|
8795
8849
|
invoke: {
|
|
8796
|
-
src: "mutation
|
|
8850
|
+
src: "mutation interval"
|
|
8797
8851
|
},
|
|
8798
8852
|
on: {
|
|
8799
|
-
"
|
|
8800
|
-
guard: and([not("is read-only"),
|
|
8853
|
+
"emit changes": {
|
|
8854
|
+
guard: and([not("is read-only"), "slate is normalizing"]),
|
|
8801
8855
|
target: "idle",
|
|
8802
8856
|
actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
|
|
8803
8857
|
},
|