@portabletext/editor 1.48.9 → 1.48.11
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/editor-provider.cjs +879 -169
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +464 -19
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +9 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-es/editor-provider.js +773 -65
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +448 -3
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +9 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/behaviors/index.cjs +27 -377
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +3696 -13915
- package/lib/behaviors/index.d.ts +3696 -13915
- package/lib/behaviors/index.js +22 -377
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +17 -17
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3008 -394
- package/lib/index.d.ts +3008 -394
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +347 -30
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3008 -395
- package/lib/plugins/index.d.ts +3008 -395
- package/lib/plugins/index.js +324 -8
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +29 -29
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +3007 -387
- package/lib/selectors/index.d.ts +3007 -387
- package/lib/selectors/index.js +2 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3008 -389
- package/lib/utils/index.d.ts +3008 -389
- package/lib/utils/index.js +2 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.emoji-picker.ts +0 -6
- package/src/behaviors/behavior.markdown.ts +0 -48
- package/src/behaviors/index.ts +0 -15
- package/src/editor/create-editor.ts +0 -3
- package/src/editor/editor-machine.ts +105 -52
- package/src/editor/sync-machine.ts +10 -4
- package/src/internal-utils/__tests__/operationToPatches.test.ts +0 -2
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -2
- package/src/plugins/plugin.core.tsx +1 -1
- package/lib/_chunks-cjs/behavior.core.cjs +0 -700
- package/lib/_chunks-cjs/behavior.core.cjs.map +0 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +0 -321
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -449
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +0 -1
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs +0 -10
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +0 -1
- package/lib/_chunks-es/behavior.core.js +0 -703
- package/lib/_chunks-es/behavior.core.js.map +0 -1
- package/lib/_chunks-es/behavior.markdown.js +0 -325
- package/lib/_chunks-es/behavior.markdown.js.map +0 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +0 -451
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +0 -1
- package/lib/_chunks-es/util.get-selection-start-point.js +0 -11
- package/lib/_chunks-es/util.get-selection-start-point.js.map +0 -1
- package/src/behaviors/behavior.code-editor.ts +0 -77
- package/src/behaviors/behavior.links.ts +0 -84
- package/src/internal-utils/looks-like-url.test.ts +0 -19
- package/src/internal-utils/looks-like-url.ts +0 -15
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$f = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), util_sliceBlocks = require("./util.slice-blocks.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), types = require("@sanity/types"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"),
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$f = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), util_sliceBlocks = require("./util.slice-blocks.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), types = require("@sanity/types"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behaviors_index = require("../behaviors/index.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -1626,8 +1626,11 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1626
1626
|
event
|
|
1627
1627
|
}) => (xstate.assertEvent(event, "done syncing"), event.value)
|
|
1628
1628
|
}),
|
|
1629
|
-
"emit done syncing
|
|
1630
|
-
type: "done syncing
|
|
1629
|
+
"emit done syncing value": xstate.emit({
|
|
1630
|
+
type: "done syncing value"
|
|
1631
|
+
}),
|
|
1632
|
+
"emit syncing value": xstate.emit({
|
|
1633
|
+
type: "syncing value"
|
|
1631
1634
|
})
|
|
1632
1635
|
},
|
|
1633
1636
|
guards: {
|
|
@@ -1703,7 +1706,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1703
1706
|
}
|
|
1704
1707
|
},
|
|
1705
1708
|
"done syncing initial value": {
|
|
1706
|
-
entry: ["emit done syncing
|
|
1709
|
+
entry: ["emit done syncing value", () => {
|
|
1707
1710
|
debug$d("entry: done syncing initial value");
|
|
1708
1711
|
}],
|
|
1709
1712
|
exit: [() => {
|
|
@@ -1762,10 +1765,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1762
1765
|
syncing: {
|
|
1763
1766
|
entry: [() => {
|
|
1764
1767
|
debug$d("entry: syncing->syncing");
|
|
1765
|
-
}],
|
|
1768
|
+
}, "emit syncing value"],
|
|
1766
1769
|
exit: [() => {
|
|
1767
1770
|
debug$d("exit: syncing->syncing");
|
|
1768
|
-
}],
|
|
1771
|
+
}, "emit done syncing value"],
|
|
1769
1772
|
always: {
|
|
1770
1773
|
guard: "pending value equals previous value",
|
|
1771
1774
|
target: "idle",
|
|
@@ -4943,7 +4946,7 @@ function createWithSchemaTypes({
|
|
|
4943
4946
|
editorActor
|
|
4944
4947
|
}) {
|
|
4945
4948
|
return function(editor) {
|
|
4946
|
-
editor.isTextBlock = (value) => util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => util_sliceBlocks.isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => util_sliceBlocks.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4949
|
+
editor.isTextBlock = (value) => util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => util_sliceBlocks.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => util_sliceBlocks.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4947
4950
|
const {
|
|
4948
4951
|
normalizeNode
|
|
4949
4952
|
} = editor;
|
|
@@ -5694,7 +5697,6 @@ function editorConfigToMachineInput(config) {
|
|
|
5694
5697
|
schema: schema2
|
|
5695
5698
|
} = compileSchemasFromEditorConfig(config);
|
|
5696
5699
|
return {
|
|
5697
|
-
behaviors: config.behaviors,
|
|
5698
5700
|
converters: createCoreConverters(legacySchema),
|
|
5699
5701
|
getLegacySchema: () => legacySchema,
|
|
5700
5702
|
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
@@ -5726,7 +5728,6 @@ function createInternalEditor(editorActor) {
|
|
|
5726
5728
|
switch (event.type) {
|
|
5727
5729
|
case "add behavior":
|
|
5728
5730
|
case "remove behavior":
|
|
5729
|
-
case "update behaviors":
|
|
5730
5731
|
case "update key generator":
|
|
5731
5732
|
case "update readOnly":
|
|
5732
5733
|
case "patches":
|
|
@@ -5808,7 +5809,669 @@ function createGloballyScopedContext(key, defaultValue) {
|
|
|
5808
5809
|
const symbol = Symbol.for(key);
|
|
5809
5810
|
return typeof document > "u" ? React.createContext(defaultValue) : (globalScope[symbol] = globalScope[symbol] ?? React.createContext(defaultValue), globalScope[symbol]);
|
|
5810
5811
|
}
|
|
5811
|
-
const EditorContext = createGloballyScopedContext("@portabletext/editor/context/editor", null),
|
|
5812
|
+
const EditorContext = createGloballyScopedContext("@portabletext/editor/context/editor", null), addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
5813
|
+
on: "annotation.add",
|
|
5814
|
+
guard: ({
|
|
5815
|
+
snapshot
|
|
5816
|
+
}) => {
|
|
5817
|
+
if (!selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot))
|
|
5818
|
+
return !1;
|
|
5819
|
+
const caretWordSelection = selector_isSelectingEntireBlocks.getCaretWordSelection(snapshot);
|
|
5820
|
+
return !caretWordSelection || !selector_isSelectingEntireBlocks.isSelectionExpanded({
|
|
5821
|
+
context: {
|
|
5822
|
+
...snapshot.context,
|
|
5823
|
+
selection: caretWordSelection
|
|
5824
|
+
}
|
|
5825
|
+
}) ? !1 : {
|
|
5826
|
+
caretWordSelection
|
|
5827
|
+
};
|
|
5828
|
+
},
|
|
5829
|
+
actions: [({
|
|
5830
|
+
event
|
|
5831
|
+
}, {
|
|
5832
|
+
caretWordSelection
|
|
5833
|
+
}) => [behaviors_index.raise({
|
|
5834
|
+
type: "select",
|
|
5835
|
+
at: caretWordSelection
|
|
5836
|
+
}), behaviors_index.raise({
|
|
5837
|
+
type: "annotation.add",
|
|
5838
|
+
annotation: event.annotation
|
|
5839
|
+
})]]
|
|
5840
|
+
}), coreAnnotationBehaviors = {
|
|
5841
|
+
addAnnotationOnCollapsedSelection
|
|
5842
|
+
}, IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
5843
|
+
alt: "altKey",
|
|
5844
|
+
control: "ctrlKey",
|
|
5845
|
+
meta: "metaKey",
|
|
5846
|
+
shift: "shiftKey"
|
|
5847
|
+
}, aliases = {
|
|
5848
|
+
add: "+",
|
|
5849
|
+
break: "pause",
|
|
5850
|
+
cmd: "meta",
|
|
5851
|
+
command: "meta",
|
|
5852
|
+
ctl: "control",
|
|
5853
|
+
ctrl: "control",
|
|
5854
|
+
del: "delete",
|
|
5855
|
+
down: "arrowdown",
|
|
5856
|
+
esc: "escape",
|
|
5857
|
+
ins: "insert",
|
|
5858
|
+
left: "arrowleft",
|
|
5859
|
+
mod: IS_MAC ? "meta" : "control",
|
|
5860
|
+
opt: "alt",
|
|
5861
|
+
option: "alt",
|
|
5862
|
+
return: "enter",
|
|
5863
|
+
right: "arrowright",
|
|
5864
|
+
space: " ",
|
|
5865
|
+
spacebar: " ",
|
|
5866
|
+
up: "arrowup",
|
|
5867
|
+
win: "meta",
|
|
5868
|
+
windows: "meta"
|
|
5869
|
+
}, keyCodes = {
|
|
5870
|
+
backspace: 8,
|
|
5871
|
+
tab: 9,
|
|
5872
|
+
enter: 13,
|
|
5873
|
+
shift: 16,
|
|
5874
|
+
control: 17,
|
|
5875
|
+
alt: 18,
|
|
5876
|
+
pause: 19,
|
|
5877
|
+
capslock: 20,
|
|
5878
|
+
escape: 27,
|
|
5879
|
+
" ": 32,
|
|
5880
|
+
pageup: 33,
|
|
5881
|
+
pagedown: 34,
|
|
5882
|
+
end: 35,
|
|
5883
|
+
home: 36,
|
|
5884
|
+
arrowleft: 37,
|
|
5885
|
+
arrowup: 38,
|
|
5886
|
+
arrowright: 39,
|
|
5887
|
+
arrowdown: 40,
|
|
5888
|
+
insert: 45,
|
|
5889
|
+
delete: 46,
|
|
5890
|
+
meta: 91,
|
|
5891
|
+
numlock: 144,
|
|
5892
|
+
scrolllock: 145,
|
|
5893
|
+
";": 186,
|
|
5894
|
+
"=": 187,
|
|
5895
|
+
",": 188,
|
|
5896
|
+
"-": 189,
|
|
5897
|
+
".": 190,
|
|
5898
|
+
"/": 191,
|
|
5899
|
+
"`": 192,
|
|
5900
|
+
"[": 219,
|
|
5901
|
+
"\\": 220,
|
|
5902
|
+
"]": 221,
|
|
5903
|
+
"'": 222,
|
|
5904
|
+
f1: 112,
|
|
5905
|
+
f2: 113,
|
|
5906
|
+
f3: 114,
|
|
5907
|
+
f4: 115,
|
|
5908
|
+
f5: 116,
|
|
5909
|
+
f6: 117,
|
|
5910
|
+
f7: 118,
|
|
5911
|
+
f8: 119,
|
|
5912
|
+
f9: 120,
|
|
5913
|
+
f10: 121,
|
|
5914
|
+
f11: 122,
|
|
5915
|
+
f12: 123,
|
|
5916
|
+
f13: 124,
|
|
5917
|
+
f14: 125,
|
|
5918
|
+
f15: 126,
|
|
5919
|
+
f16: 127,
|
|
5920
|
+
f17: 128,
|
|
5921
|
+
f18: 129,
|
|
5922
|
+
f19: 130,
|
|
5923
|
+
f20: 131
|
|
5924
|
+
};
|
|
5925
|
+
function isHotkey(hotkey, event) {
|
|
5926
|
+
return compareHotkey(parseHotkey(hotkey), event);
|
|
5927
|
+
}
|
|
5928
|
+
function parseHotkey(hotkey) {
|
|
5929
|
+
const parsedHotkey = {
|
|
5930
|
+
altKey: !1,
|
|
5931
|
+
ctrlKey: !1,
|
|
5932
|
+
metaKey: !1,
|
|
5933
|
+
shiftKey: !1
|
|
5934
|
+
}, hotkeySegments = hotkey.replace("++", "+add").split("+");
|
|
5935
|
+
for (const rawHotkeySegment of hotkeySegments) {
|
|
5936
|
+
const optional = rawHotkeySegment.endsWith("?") && rawHotkeySegment.length > 1, hotkeySegment = optional ? rawHotkeySegment.slice(0, -1) : rawHotkeySegment, keyName = toKeyName(hotkeySegment), modifier = modifiers[keyName], alias = aliases[hotkeySegment], code = keyCodes[keyName];
|
|
5937
|
+
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
|
|
5938
|
+
throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
|
|
5939
|
+
(hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
|
|
5940
|
+
}
|
|
5941
|
+
return parsedHotkey;
|
|
5942
|
+
}
|
|
5943
|
+
function compareHotkey(parsedHotkey, event) {
|
|
5944
|
+
return (parsedHotkey.altKey == null || parsedHotkey.altKey === event.altKey) && (parsedHotkey.ctrlKey == null || parsedHotkey.ctrlKey === event.ctrlKey) && (parsedHotkey.metaKey == null || parsedHotkey.metaKey === event.metaKey) && (parsedHotkey.shiftKey == null || parsedHotkey.shiftKey === event.shiftKey) ? parsedHotkey.keyCode !== void 0 && event.keyCode !== void 0 ? parsedHotkey.keyCode === 91 && event.keyCode === 93 ? !0 : parsedHotkey.keyCode === event.keyCode : parsedHotkey.keyCode === event.keyCode || parsedHotkey.key === event.key.toLowerCase() : !1;
|
|
5945
|
+
}
|
|
5946
|
+
function toKeyCode(name) {
|
|
5947
|
+
const keyName = toKeyName(name);
|
|
5948
|
+
return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
|
|
5949
|
+
}
|
|
5950
|
+
function toKeyName(name) {
|
|
5951
|
+
const keyName = name.toLowerCase();
|
|
5952
|
+
return aliases[keyName] ?? keyName;
|
|
5953
|
+
}
|
|
5954
|
+
const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
5955
|
+
on: "keyboard.keydown",
|
|
5956
|
+
guard: ({
|
|
5957
|
+
snapshot,
|
|
5958
|
+
event
|
|
5959
|
+
}) => {
|
|
5960
|
+
if (!isHotkey("ArrowDown", event.originEvent) || !selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot))
|
|
5961
|
+
return !1;
|
|
5962
|
+
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
5963
|
+
return focusBlockObject && !nextBlock;
|
|
5964
|
+
},
|
|
5965
|
+
actions: [({
|
|
5966
|
+
snapshot
|
|
5967
|
+
}) => [behaviors_index.raise({
|
|
5968
|
+
type: "insert.block",
|
|
5969
|
+
block: {
|
|
5970
|
+
_type: snapshot.context.schema.block.name
|
|
5971
|
+
},
|
|
5972
|
+
placement: "after"
|
|
5973
|
+
})]]
|
|
5974
|
+
}), arrowUpOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
5975
|
+
on: "keyboard.keydown",
|
|
5976
|
+
guard: ({
|
|
5977
|
+
snapshot,
|
|
5978
|
+
event
|
|
5979
|
+
}) => {
|
|
5980
|
+
if (!isHotkey("ArrowUp", event.originEvent) || !selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot))
|
|
5981
|
+
return !1;
|
|
5982
|
+
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
5983
|
+
return focusBlockObject && !previousBlock;
|
|
5984
|
+
},
|
|
5985
|
+
actions: [({
|
|
5986
|
+
snapshot
|
|
5987
|
+
}) => [behaviors_index.raise({
|
|
5988
|
+
type: "insert.block",
|
|
5989
|
+
block: {
|
|
5990
|
+
_type: snapshot.context.schema.block.name
|
|
5991
|
+
},
|
|
5992
|
+
placement: "before"
|
|
5993
|
+
})]]
|
|
5994
|
+
}), breakingBlockObject = behaviors_index.defineBehavior({
|
|
5995
|
+
on: "insert.break",
|
|
5996
|
+
guard: ({
|
|
5997
|
+
snapshot
|
|
5998
|
+
}) => {
|
|
5999
|
+
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot);
|
|
6000
|
+
return selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
|
|
6001
|
+
},
|
|
6002
|
+
actions: [({
|
|
6003
|
+
snapshot
|
|
6004
|
+
}) => [behaviors_index.raise({
|
|
6005
|
+
type: "insert.block",
|
|
6006
|
+
block: {
|
|
6007
|
+
_type: snapshot.context.schema.block.name
|
|
6008
|
+
},
|
|
6009
|
+
placement: "after"
|
|
6010
|
+
})]]
|
|
6011
|
+
}), clickingAboveLonelyBlockObject = behaviors_index.defineBehavior({
|
|
6012
|
+
on: "mouse.click",
|
|
6013
|
+
guard: ({
|
|
6014
|
+
snapshot,
|
|
6015
|
+
event
|
|
6016
|
+
}) => {
|
|
6017
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot))
|
|
6018
|
+
return !1;
|
|
6019
|
+
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
6020
|
+
context: {
|
|
6021
|
+
...snapshot.context,
|
|
6022
|
+
selection: event.position.selection
|
|
6023
|
+
}
|
|
6024
|
+
}), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock({
|
|
6025
|
+
context: {
|
|
6026
|
+
...snapshot.context,
|
|
6027
|
+
selection: event.position.selection
|
|
6028
|
+
}
|
|
6029
|
+
});
|
|
6030
|
+
return event.position.isEditor && event.position.block === "start" && focusBlockObject && !previousBlock;
|
|
6031
|
+
},
|
|
6032
|
+
actions: [({
|
|
6033
|
+
snapshot,
|
|
6034
|
+
event
|
|
6035
|
+
}) => [behaviors_index.raise({
|
|
6036
|
+
type: "select",
|
|
6037
|
+
at: event.position.selection
|
|
6038
|
+
}), behaviors_index.raise({
|
|
6039
|
+
type: "insert.block",
|
|
6040
|
+
block: {
|
|
6041
|
+
_type: snapshot.context.schema.block.name
|
|
6042
|
+
},
|
|
6043
|
+
placement: "before",
|
|
6044
|
+
select: "start"
|
|
6045
|
+
})]]
|
|
6046
|
+
}), clickingBelowLonelyBlockObject = behaviors_index.defineBehavior({
|
|
6047
|
+
on: "mouse.click",
|
|
6048
|
+
guard: ({
|
|
6049
|
+
snapshot,
|
|
6050
|
+
event
|
|
6051
|
+
}) => {
|
|
6052
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot))
|
|
6053
|
+
return !1;
|
|
6054
|
+
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
6055
|
+
context: {
|
|
6056
|
+
...snapshot.context,
|
|
6057
|
+
selection: event.position.selection
|
|
6058
|
+
}
|
|
6059
|
+
}), nextBlock = selector_isSelectingEntireBlocks.getNextBlock({
|
|
6060
|
+
context: {
|
|
6061
|
+
...snapshot.context,
|
|
6062
|
+
selection: event.position.selection
|
|
6063
|
+
}
|
|
6064
|
+
});
|
|
6065
|
+
return event.position.isEditor && event.position.block === "end" && focusBlockObject && !nextBlock;
|
|
6066
|
+
},
|
|
6067
|
+
actions: [({
|
|
6068
|
+
snapshot,
|
|
6069
|
+
event
|
|
6070
|
+
}) => [behaviors_index.raise({
|
|
6071
|
+
type: "select",
|
|
6072
|
+
at: event.position.selection
|
|
6073
|
+
}), behaviors_index.raise({
|
|
6074
|
+
type: "insert.block",
|
|
6075
|
+
block: {
|
|
6076
|
+
_type: snapshot.context.schema.block.name
|
|
6077
|
+
},
|
|
6078
|
+
placement: "after",
|
|
6079
|
+
select: "start"
|
|
6080
|
+
})]]
|
|
6081
|
+
}), deletingEmptyTextBlockAfterBlockObject = behaviors_index.defineBehavior({
|
|
6082
|
+
on: "delete.backward",
|
|
6083
|
+
guard: ({
|
|
6084
|
+
snapshot
|
|
6085
|
+
}) => {
|
|
6086
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
6087
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
6088
|
+
focusTextBlock,
|
|
6089
|
+
previousBlock
|
|
6090
|
+
} : !1;
|
|
6091
|
+
},
|
|
6092
|
+
actions: [(_, {
|
|
6093
|
+
focusTextBlock,
|
|
6094
|
+
previousBlock
|
|
6095
|
+
}) => [behaviors_index.raise({
|
|
6096
|
+
type: "delete.block",
|
|
6097
|
+
at: focusTextBlock.path
|
|
6098
|
+
}), behaviors_index.raise({
|
|
6099
|
+
type: "select",
|
|
6100
|
+
at: {
|
|
6101
|
+
anchor: {
|
|
6102
|
+
path: previousBlock.path,
|
|
6103
|
+
offset: 0
|
|
6104
|
+
},
|
|
6105
|
+
focus: {
|
|
6106
|
+
path: previousBlock.path,
|
|
6107
|
+
offset: 0
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
})]]
|
|
6111
|
+
}), deletingEmptyTextBlockBeforeBlockObject = behaviors_index.defineBehavior({
|
|
6112
|
+
on: "delete.forward",
|
|
6113
|
+
guard: ({
|
|
6114
|
+
snapshot
|
|
6115
|
+
}) => {
|
|
6116
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
6117
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
6118
|
+
focusTextBlock,
|
|
6119
|
+
nextBlock
|
|
6120
|
+
} : !1;
|
|
6121
|
+
},
|
|
6122
|
+
actions: [(_, {
|
|
6123
|
+
focusTextBlock,
|
|
6124
|
+
nextBlock
|
|
6125
|
+
}) => [behaviors_index.raise({
|
|
6126
|
+
type: "delete.block",
|
|
6127
|
+
at: focusTextBlock.path
|
|
6128
|
+
}), behaviors_index.raise({
|
|
6129
|
+
type: "select",
|
|
6130
|
+
at: {
|
|
6131
|
+
anchor: {
|
|
6132
|
+
path: nextBlock.path,
|
|
6133
|
+
offset: 0
|
|
6134
|
+
},
|
|
6135
|
+
focus: {
|
|
6136
|
+
path: nextBlock.path,
|
|
6137
|
+
offset: 0
|
|
6138
|
+
}
|
|
6139
|
+
}
|
|
6140
|
+
})]]
|
|
6141
|
+
}), coreBlockObjectBehaviors = {
|
|
6142
|
+
arrowDownOnLonelyBlockObject,
|
|
6143
|
+
arrowUpOnLonelyBlockObject,
|
|
6144
|
+
breakingBlockObject,
|
|
6145
|
+
clickingAboveLonelyBlockObject,
|
|
6146
|
+
clickingBelowLonelyBlockObject,
|
|
6147
|
+
deletingEmptyTextBlockAfterBlockObject,
|
|
6148
|
+
deletingEmptyTextBlockBeforeBlockObject
|
|
6149
|
+
}, coreDecoratorBehaviors = {
|
|
6150
|
+
strongShortcut: behaviors_index.defineBehavior({
|
|
6151
|
+
on: "keyboard.keydown",
|
|
6152
|
+
guard: ({
|
|
6153
|
+
snapshot,
|
|
6154
|
+
event
|
|
6155
|
+
}) => isHotkey("mod+b", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "strong"),
|
|
6156
|
+
actions: [() => [behaviors_index.raise({
|
|
6157
|
+
type: "decorator.toggle",
|
|
6158
|
+
decorator: "strong"
|
|
6159
|
+
})]]
|
|
6160
|
+
}),
|
|
6161
|
+
emShortcut: behaviors_index.defineBehavior({
|
|
6162
|
+
on: "keyboard.keydown",
|
|
6163
|
+
guard: ({
|
|
6164
|
+
snapshot,
|
|
6165
|
+
event
|
|
6166
|
+
}) => isHotkey("mod+i", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "em"),
|
|
6167
|
+
actions: [() => [behaviors_index.raise({
|
|
6168
|
+
type: "decorator.toggle",
|
|
6169
|
+
decorator: "em"
|
|
6170
|
+
})]]
|
|
6171
|
+
}),
|
|
6172
|
+
underlineShortcut: behaviors_index.defineBehavior({
|
|
6173
|
+
on: "keyboard.keydown",
|
|
6174
|
+
guard: ({
|
|
6175
|
+
snapshot,
|
|
6176
|
+
event
|
|
6177
|
+
}) => isHotkey("mod+u", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "underline"),
|
|
6178
|
+
actions: [() => [behaviors_index.raise({
|
|
6179
|
+
type: "decorator.toggle",
|
|
6180
|
+
decorator: "underline"
|
|
6181
|
+
})]]
|
|
6182
|
+
}),
|
|
6183
|
+
codeShortcut: behaviors_index.defineBehavior({
|
|
6184
|
+
on: "keyboard.keydown",
|
|
6185
|
+
guard: ({
|
|
6186
|
+
snapshot,
|
|
6187
|
+
event
|
|
6188
|
+
}) => isHotkey("mod+'", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "code"),
|
|
6189
|
+
actions: [() => [behaviors_index.raise({
|
|
6190
|
+
type: "decorator.toggle",
|
|
6191
|
+
decorator: "code"
|
|
6192
|
+
})]]
|
|
6193
|
+
})
|
|
6194
|
+
}, coreDndBehaviors = [
|
|
6195
|
+
/**
|
|
6196
|
+
* When dragging over the drag origin, we don't want to show the caret in the
|
|
6197
|
+
* text.
|
|
6198
|
+
*/
|
|
6199
|
+
behaviors_index.defineBehavior({
|
|
6200
|
+
on: "drag.dragover",
|
|
6201
|
+
guard: ({
|
|
6202
|
+
snapshot,
|
|
6203
|
+
event
|
|
6204
|
+
}) => {
|
|
6205
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin;
|
|
6206
|
+
return dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(event.position.selection)({
|
|
6207
|
+
...snapshot,
|
|
6208
|
+
context: {
|
|
6209
|
+
...snapshot.context,
|
|
6210
|
+
selection: dragOrigin.selection
|
|
6211
|
+
}
|
|
6212
|
+
}) : !1;
|
|
6213
|
+
},
|
|
6214
|
+
actions: []
|
|
6215
|
+
})
|
|
6216
|
+
], breakingAtTheEndOfTextBlock = behaviors_index.defineBehavior({
|
|
6217
|
+
on: "insert.break",
|
|
6218
|
+
guard: ({
|
|
6219
|
+
snapshot
|
|
6220
|
+
}) => {
|
|
6221
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot);
|
|
6222
|
+
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
6223
|
+
return !1;
|
|
6224
|
+
const atTheEndOfBlock = selector_isSelectingEntireBlocks.isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
6225
|
+
return atTheEndOfBlock ? {
|
|
6226
|
+
focusListItem,
|
|
6227
|
+
focusLevel
|
|
6228
|
+
} : !1;
|
|
6229
|
+
},
|
|
6230
|
+
actions: [({
|
|
6231
|
+
snapshot
|
|
6232
|
+
}, {
|
|
6233
|
+
focusListItem,
|
|
6234
|
+
focusLevel
|
|
6235
|
+
}) => [behaviors_index.raise({
|
|
6236
|
+
type: "insert.block",
|
|
6237
|
+
block: {
|
|
6238
|
+
_type: snapshot.context.schema.block.name,
|
|
6239
|
+
children: [{
|
|
6240
|
+
_type: snapshot.context.schema.span.name,
|
|
6241
|
+
text: "",
|
|
6242
|
+
marks: []
|
|
6243
|
+
}],
|
|
6244
|
+
markDefs: [],
|
|
6245
|
+
listItem: focusListItem,
|
|
6246
|
+
level: focusLevel,
|
|
6247
|
+
style: snapshot.context.schema.styles[0]?.name
|
|
6248
|
+
},
|
|
6249
|
+
placement: "after"
|
|
6250
|
+
})]]
|
|
6251
|
+
}), breakingAtTheStartOfTextBlock = behaviors_index.defineBehavior({
|
|
6252
|
+
on: "insert.break",
|
|
6253
|
+
guard: ({
|
|
6254
|
+
snapshot
|
|
6255
|
+
}) => {
|
|
6256
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot);
|
|
6257
|
+
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
6258
|
+
return !1;
|
|
6259
|
+
const focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
6260
|
+
return selector_isSelectingEntireBlocks.isAtTheStartOfBlock(focusTextBlock)(snapshot) ? {
|
|
6261
|
+
focusAnnotations,
|
|
6262
|
+
focusDecorators,
|
|
6263
|
+
focusListItem,
|
|
6264
|
+
focusLevel
|
|
6265
|
+
} : !1;
|
|
6266
|
+
},
|
|
6267
|
+
actions: [({
|
|
6268
|
+
snapshot
|
|
6269
|
+
}, {
|
|
6270
|
+
focusAnnotations,
|
|
6271
|
+
focusDecorators,
|
|
6272
|
+
focusListItem,
|
|
6273
|
+
focusLevel
|
|
6274
|
+
}) => [behaviors_index.raise({
|
|
6275
|
+
type: "insert.block",
|
|
6276
|
+
block: {
|
|
6277
|
+
_type: snapshot.context.schema.block.name,
|
|
6278
|
+
children: [{
|
|
6279
|
+
_type: snapshot.context.schema.span.name,
|
|
6280
|
+
marks: focusAnnotations.length === 0 ? focusDecorators : [],
|
|
6281
|
+
text: ""
|
|
6282
|
+
}],
|
|
6283
|
+
listItem: focusListItem,
|
|
6284
|
+
level: focusLevel,
|
|
6285
|
+
style: snapshot.context.schema.styles[0]?.name
|
|
6286
|
+
},
|
|
6287
|
+
placement: "before",
|
|
6288
|
+
select: "none"
|
|
6289
|
+
})]]
|
|
6290
|
+
}), breakingEntireDocument = behaviors_index.defineBehavior({
|
|
6291
|
+
on: "insert.break",
|
|
6292
|
+
guard: ({
|
|
6293
|
+
snapshot
|
|
6294
|
+
}) => {
|
|
6295
|
+
if (!snapshot.context.selection || !selector_isSelectingEntireBlocks.isSelectionExpanded(snapshot))
|
|
6296
|
+
return !1;
|
|
6297
|
+
const firstBlock = selector_isSelectingEntireBlocks.getFirstBlock(snapshot), lastBlock = selector_isSelectingEntireBlocks.getLastBlock(snapshot);
|
|
6298
|
+
if (!firstBlock || !lastBlock)
|
|
6299
|
+
return !1;
|
|
6300
|
+
const firstBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
6301
|
+
context: snapshot.context,
|
|
6302
|
+
block: firstBlock
|
|
6303
|
+
}), selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_sliceBlocks.getBlockEndPoint({
|
|
6304
|
+
context: snapshot.context,
|
|
6305
|
+
block: lastBlock
|
|
6306
|
+
}), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection);
|
|
6307
|
+
return util_sliceBlocks.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_sliceBlocks.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
|
|
6308
|
+
selection: snapshot.context.selection
|
|
6309
|
+
} : !1;
|
|
6310
|
+
},
|
|
6311
|
+
actions: [(_, {
|
|
6312
|
+
selection
|
|
6313
|
+
}) => [behaviors_index.raise({
|
|
6314
|
+
type: "delete",
|
|
6315
|
+
at: selection
|
|
6316
|
+
})]]
|
|
6317
|
+
}), breakingEntireBlocks = behaviors_index.defineBehavior({
|
|
6318
|
+
on: "insert.break",
|
|
6319
|
+
guard: ({
|
|
6320
|
+
snapshot
|
|
6321
|
+
}) => {
|
|
6322
|
+
if (!snapshot.context.selection || !selector_isSelectingEntireBlocks.isSelectionExpanded(snapshot))
|
|
6323
|
+
return !1;
|
|
6324
|
+
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot), selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
6325
|
+
if (!selectionStartBlock || !selectionEndBlock)
|
|
6326
|
+
return !1;
|
|
6327
|
+
const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
6328
|
+
context: snapshot.context,
|
|
6329
|
+
block: selectionStartBlock
|
|
6330
|
+
}), selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_sliceBlocks.getBlockEndPoint({
|
|
6331
|
+
context: snapshot.context,
|
|
6332
|
+
block: selectionEndBlock
|
|
6333
|
+
}), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection);
|
|
6334
|
+
return util_sliceBlocks.isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && util_sliceBlocks.isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
|
|
6335
|
+
selectedBlocks
|
|
6336
|
+
} : !1;
|
|
6337
|
+
},
|
|
6338
|
+
actions: [({
|
|
6339
|
+
snapshot
|
|
6340
|
+
}, {
|
|
6341
|
+
selectedBlocks
|
|
6342
|
+
}) => [behaviors_index.raise({
|
|
6343
|
+
type: "insert.block",
|
|
6344
|
+
block: {
|
|
6345
|
+
_type: snapshot.context.schema.block.name,
|
|
6346
|
+
children: [{
|
|
6347
|
+
_type: snapshot.context.schema.span.name,
|
|
6348
|
+
text: "",
|
|
6349
|
+
marks: []
|
|
6350
|
+
}]
|
|
6351
|
+
},
|
|
6352
|
+
placement: "before",
|
|
6353
|
+
select: "start"
|
|
6354
|
+
}), ...selectedBlocks.map((block) => behaviors_index.raise({
|
|
6355
|
+
type: "delete.block",
|
|
6356
|
+
at: block.path
|
|
6357
|
+
}))]]
|
|
6358
|
+
}), coreInsertBreakBehaviors = {
|
|
6359
|
+
breakingAtTheEndOfTextBlock,
|
|
6360
|
+
breakingAtTheStartOfTextBlock,
|
|
6361
|
+
breakingEntireDocument,
|
|
6362
|
+
breakingEntireBlocks
|
|
6363
|
+
}, MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior({
|
|
6364
|
+
on: "delete.backward",
|
|
6365
|
+
guard: ({
|
|
6366
|
+
snapshot
|
|
6367
|
+
}) => {
|
|
6368
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
6369
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
6370
|
+
focusTextBlock
|
|
6371
|
+
} : !1;
|
|
6372
|
+
},
|
|
6373
|
+
actions: [(_, {
|
|
6374
|
+
focusTextBlock
|
|
6375
|
+
}) => [behaviors_index.raise({
|
|
6376
|
+
type: "block.unset",
|
|
6377
|
+
props: ["listItem", "level"],
|
|
6378
|
+
at: focusTextBlock.path
|
|
6379
|
+
})]]
|
|
6380
|
+
}), unindentListOnBackspace = behaviors_index.defineBehavior({
|
|
6381
|
+
on: "delete.backward",
|
|
6382
|
+
guard: ({
|
|
6383
|
+
snapshot
|
|
6384
|
+
}) => {
|
|
6385
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
6386
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
6387
|
+
focusTextBlock,
|
|
6388
|
+
level: focusTextBlock.node.level - 1
|
|
6389
|
+
} : !1;
|
|
6390
|
+
},
|
|
6391
|
+
actions: [(_, {
|
|
6392
|
+
focusTextBlock,
|
|
6393
|
+
level
|
|
6394
|
+
}) => [behaviors_index.raise({
|
|
6395
|
+
type: "block.set",
|
|
6396
|
+
props: {
|
|
6397
|
+
level
|
|
6398
|
+
},
|
|
6399
|
+
at: focusTextBlock.path
|
|
6400
|
+
})]]
|
|
6401
|
+
}), clearListOnEnter = behaviors_index.defineBehavior({
|
|
6402
|
+
on: "insert.break",
|
|
6403
|
+
guard: ({
|
|
6404
|
+
snapshot
|
|
6405
|
+
}) => {
|
|
6406
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock(snapshot);
|
|
6407
|
+
return !selectionCollapsed || !focusListBlock || !util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
6408
|
+
focusListBlock
|
|
6409
|
+
};
|
|
6410
|
+
},
|
|
6411
|
+
actions: [(_, {
|
|
6412
|
+
focusListBlock
|
|
6413
|
+
}) => [behaviors_index.raise({
|
|
6414
|
+
type: "block.unset",
|
|
6415
|
+
props: ["listItem", "level"],
|
|
6416
|
+
at: focusListBlock.path
|
|
6417
|
+
})]]
|
|
6418
|
+
}), indentListOnTab = behaviors_index.defineBehavior({
|
|
6419
|
+
on: "keyboard.keydown",
|
|
6420
|
+
guard: ({
|
|
6421
|
+
snapshot,
|
|
6422
|
+
event
|
|
6423
|
+
}) => {
|
|
6424
|
+
if (!isHotkey("Tab", event.originEvent))
|
|
6425
|
+
return !1;
|
|
6426
|
+
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
|
|
6427
|
+
node: block.node,
|
|
6428
|
+
path: block.path
|
|
6429
|
+
}] : []);
|
|
6430
|
+
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
6431
|
+
selectedListBlocks
|
|
6432
|
+
} : !1;
|
|
6433
|
+
},
|
|
6434
|
+
actions: [(_, {
|
|
6435
|
+
selectedListBlocks
|
|
6436
|
+
}) => selectedListBlocks.map((selectedListBlock) => behaviors_index.raise({
|
|
6437
|
+
type: "block.set",
|
|
6438
|
+
props: {
|
|
6439
|
+
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1))
|
|
6440
|
+
},
|
|
6441
|
+
at: selectedListBlock.path
|
|
6442
|
+
}))]
|
|
6443
|
+
}), unindentListOnShiftTab = behaviors_index.defineBehavior({
|
|
6444
|
+
on: "keyboard.keydown",
|
|
6445
|
+
guard: ({
|
|
6446
|
+
snapshot,
|
|
6447
|
+
event
|
|
6448
|
+
}) => {
|
|
6449
|
+
if (!isHotkey("Shift+Tab", event.originEvent))
|
|
6450
|
+
return !1;
|
|
6451
|
+
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
|
|
6452
|
+
node: block.node,
|
|
6453
|
+
path: block.path
|
|
6454
|
+
}] : []);
|
|
6455
|
+
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
6456
|
+
selectedListBlocks
|
|
6457
|
+
} : !1;
|
|
6458
|
+
},
|
|
6459
|
+
actions: [(_, {
|
|
6460
|
+
selectedListBlocks
|
|
6461
|
+
}) => selectedListBlocks.map((selectedListBlock) => behaviors_index.raise({
|
|
6462
|
+
type: "block.set",
|
|
6463
|
+
props: {
|
|
6464
|
+
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1))
|
|
6465
|
+
},
|
|
6466
|
+
at: selectedListBlock.path
|
|
6467
|
+
}))]
|
|
6468
|
+
}), coreListBehaviors = {
|
|
6469
|
+
clearListOnBackspace,
|
|
6470
|
+
unindentListOnBackspace,
|
|
6471
|
+
clearListOnEnter,
|
|
6472
|
+
indentListOnTab,
|
|
6473
|
+
unindentListOnShiftTab
|
|
6474
|
+
}, coreBehaviors = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks], abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
5812
6475
|
on: "annotation.toggle",
|
|
5813
6476
|
guard: ({
|
|
5814
6477
|
snapshot,
|
|
@@ -5816,11 +6479,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5816
6479
|
}) => selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5817
6480
|
actions: [({
|
|
5818
6481
|
event
|
|
5819
|
-
}) => [
|
|
6482
|
+
}) => [behaviors_index.raise({
|
|
5820
6483
|
type: "annotation.remove",
|
|
5821
6484
|
annotation: event.annotation
|
|
5822
6485
|
})]]
|
|
5823
|
-
}),
|
|
6486
|
+
}), behaviors_index.defineBehavior({
|
|
5824
6487
|
on: "annotation.toggle",
|
|
5825
6488
|
guard: ({
|
|
5826
6489
|
snapshot,
|
|
@@ -5828,11 +6491,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5828
6491
|
}) => !selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5829
6492
|
actions: [({
|
|
5830
6493
|
event
|
|
5831
|
-
}) => [
|
|
6494
|
+
}) => [behaviors_index.raise({
|
|
5832
6495
|
type: "annotation.add",
|
|
5833
6496
|
annotation: event.annotation
|
|
5834
6497
|
})]]
|
|
5835
|
-
})], abstractDecoratorBehaviors = [
|
|
6498
|
+
})], abstractDecoratorBehaviors = [behaviors_index.defineBehavior({
|
|
5836
6499
|
on: "decorator.toggle",
|
|
5837
6500
|
guard: ({
|
|
5838
6501
|
snapshot,
|
|
@@ -5840,11 +6503,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5840
6503
|
}) => selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)(snapshot),
|
|
5841
6504
|
actions: [({
|
|
5842
6505
|
event
|
|
5843
|
-
}) => [
|
|
6506
|
+
}) => [behaviors_index.raise({
|
|
5844
6507
|
type: "decorator.remove",
|
|
5845
6508
|
decorator: event.decorator
|
|
5846
6509
|
})]]
|
|
5847
|
-
}),
|
|
6510
|
+
}), behaviors_index.defineBehavior({
|
|
5848
6511
|
on: "decorator.toggle",
|
|
5849
6512
|
guard: ({
|
|
5850
6513
|
snapshot,
|
|
@@ -5864,11 +6527,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5864
6527
|
},
|
|
5865
6528
|
actions: [({
|
|
5866
6529
|
event
|
|
5867
|
-
}) => [
|
|
6530
|
+
}) => [behaviors_index.raise({
|
|
5868
6531
|
...event,
|
|
5869
6532
|
type: "decorator.add"
|
|
5870
6533
|
})]]
|
|
5871
|
-
})], abstractDeleteBehaviors = [
|
|
6534
|
+
})], abstractDeleteBehaviors = [behaviors_index.defineBehavior({
|
|
5872
6535
|
on: "delete.text",
|
|
5873
6536
|
guard: ({
|
|
5874
6537
|
snapshot,
|
|
@@ -5897,37 +6560,37 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5897
6560
|
},
|
|
5898
6561
|
actions: [(_, {
|
|
5899
6562
|
selection
|
|
5900
|
-
}) => [
|
|
6563
|
+
}) => [behaviors_index.raise({
|
|
5901
6564
|
type: "delete",
|
|
5902
6565
|
at: selection
|
|
5903
6566
|
})]]
|
|
5904
|
-
})], abstractInsertBehaviors = [
|
|
6567
|
+
})], abstractInsertBehaviors = [behaviors_index.defineBehavior({
|
|
5905
6568
|
on: "insert.blocks",
|
|
5906
6569
|
guard: ({
|
|
5907
6570
|
event
|
|
5908
6571
|
}) => event.placement === "before",
|
|
5909
6572
|
actions: [({
|
|
5910
6573
|
event
|
|
5911
|
-
}) => event.blocks.map((block, index) =>
|
|
6574
|
+
}) => event.blocks.map((block, index) => behaviors_index.raise({
|
|
5912
6575
|
type: "insert.block",
|
|
5913
6576
|
block,
|
|
5914
6577
|
placement: index === 0 ? "before" : "after",
|
|
5915
6578
|
select: "end"
|
|
5916
6579
|
}))]
|
|
5917
|
-
}),
|
|
6580
|
+
}), behaviors_index.defineBehavior({
|
|
5918
6581
|
on: "insert.blocks",
|
|
5919
6582
|
guard: ({
|
|
5920
6583
|
event
|
|
5921
6584
|
}) => event.placement === "after",
|
|
5922
6585
|
actions: [({
|
|
5923
6586
|
event
|
|
5924
|
-
}) => event.blocks.map((block) =>
|
|
6587
|
+
}) => event.blocks.map((block) => behaviors_index.raise({
|
|
5925
6588
|
type: "insert.block",
|
|
5926
6589
|
block,
|
|
5927
6590
|
placement: "after",
|
|
5928
6591
|
select: "end"
|
|
5929
6592
|
}))]
|
|
5930
|
-
}),
|
|
6593
|
+
}), behaviors_index.defineBehavior({
|
|
5931
6594
|
on: "insert.blocks",
|
|
5932
6595
|
guard: ({
|
|
5933
6596
|
snapshot,
|
|
@@ -5935,7 +6598,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5935
6598
|
}) => {
|
|
5936
6599
|
if (event.placement !== "auto")
|
|
5937
6600
|
return !1;
|
|
5938
|
-
const focusTextBlock =
|
|
6601
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot);
|
|
5939
6602
|
return focusTextBlock ? {
|
|
5940
6603
|
focusTextBlock
|
|
5941
6604
|
} : !1;
|
|
@@ -5945,66 +6608,66 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5945
6608
|
event
|
|
5946
6609
|
}, {
|
|
5947
6610
|
focusTextBlock
|
|
5948
|
-
}) => event.blocks.length === 1 ? [
|
|
6611
|
+
}) => event.blocks.length === 1 ? [behaviors_index.raise({
|
|
5949
6612
|
type: "insert.block",
|
|
5950
6613
|
block: event.blocks[0],
|
|
5951
6614
|
placement: "auto",
|
|
5952
6615
|
select: "end"
|
|
5953
|
-
})] : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) =>
|
|
6616
|
+
})] : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behaviors_index.raise({
|
|
5954
6617
|
type: "insert.block",
|
|
5955
6618
|
block,
|
|
5956
6619
|
placement: index === 0 ? "auto" : "after",
|
|
5957
6620
|
select: "end"
|
|
5958
|
-
})) : event.blocks.flatMap((block, index) => index === 0 ? [
|
|
6621
|
+
})) : event.blocks.flatMap((block, index) => index === 0 ? [behaviors_index.raise({
|
|
5959
6622
|
type: "split"
|
|
5960
|
-
}),
|
|
6623
|
+
}), behaviors_index.raise({
|
|
5961
6624
|
type: "select.previous block",
|
|
5962
6625
|
select: "end"
|
|
5963
|
-
}),
|
|
6626
|
+
}), behaviors_index.raise({
|
|
5964
6627
|
type: "insert.block",
|
|
5965
6628
|
block,
|
|
5966
6629
|
placement: "auto",
|
|
5967
6630
|
select: "end"
|
|
5968
|
-
})] : index === event.blocks.length - 1 ? [
|
|
6631
|
+
})] : index === event.blocks.length - 1 ? [behaviors_index.raise({
|
|
5969
6632
|
type: "select.next block",
|
|
5970
6633
|
select: "start"
|
|
5971
|
-
}),
|
|
6634
|
+
}), behaviors_index.raise({
|
|
5972
6635
|
type: "insert.block",
|
|
5973
6636
|
block,
|
|
5974
6637
|
placement: "auto",
|
|
5975
6638
|
select: "end"
|
|
5976
|
-
})] : [
|
|
6639
|
+
})] : [behaviors_index.raise({
|
|
5977
6640
|
type: "insert.block",
|
|
5978
6641
|
block,
|
|
5979
6642
|
placement: "after",
|
|
5980
6643
|
select: "end"
|
|
5981
6644
|
})])]
|
|
5982
|
-
}),
|
|
6645
|
+
}), behaviors_index.defineBehavior({
|
|
5983
6646
|
on: "insert.blocks",
|
|
5984
6647
|
guard: ({
|
|
5985
6648
|
event
|
|
5986
6649
|
}) => event.placement === "auto",
|
|
5987
6650
|
actions: [({
|
|
5988
6651
|
event
|
|
5989
|
-
}) => event.blocks.map((block, index) =>
|
|
6652
|
+
}) => event.blocks.map((block, index) => behaviors_index.raise({
|
|
5990
6653
|
type: "insert.block",
|
|
5991
6654
|
block,
|
|
5992
6655
|
placement: index === 0 ? "auto" : "after",
|
|
5993
6656
|
select: "end"
|
|
5994
6657
|
}))]
|
|
5995
|
-
}),
|
|
6658
|
+
}), behaviors_index.defineBehavior({
|
|
5996
6659
|
on: "insert.break",
|
|
5997
|
-
actions: [() => [
|
|
6660
|
+
actions: [() => [behaviors_index.raise({
|
|
5998
6661
|
type: "split"
|
|
5999
6662
|
})]]
|
|
6000
|
-
}),
|
|
6663
|
+
}), behaviors_index.defineBehavior({
|
|
6001
6664
|
on: "insert.soft break",
|
|
6002
|
-
actions: [() => [
|
|
6665
|
+
actions: [() => [behaviors_index.raise({
|
|
6003
6666
|
type: "insert.text",
|
|
6004
6667
|
text: `
|
|
6005
6668
|
`
|
|
6006
6669
|
})]]
|
|
6007
|
-
})], abstractListItemBehaviors = [
|
|
6670
|
+
})], abstractListItemBehaviors = [behaviors_index.defineBehavior({
|
|
6008
6671
|
on: "list item.add",
|
|
6009
6672
|
guard: ({
|
|
6010
6673
|
snapshot
|
|
@@ -6015,7 +6678,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6015
6678
|
event
|
|
6016
6679
|
}, {
|
|
6017
6680
|
selectedTextBlocks
|
|
6018
|
-
}) => selectedTextBlocks.map((block) =>
|
|
6681
|
+
}) => selectedTextBlocks.map((block) => behaviors_index.raise({
|
|
6019
6682
|
type: "block.set",
|
|
6020
6683
|
at: block.path,
|
|
6021
6684
|
props: {
|
|
@@ -6023,7 +6686,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6023
6686
|
listItem: event.listItem
|
|
6024
6687
|
}
|
|
6025
6688
|
}))]
|
|
6026
|
-
}),
|
|
6689
|
+
}), behaviors_index.defineBehavior({
|
|
6027
6690
|
on: "list item.remove",
|
|
6028
6691
|
guard: ({
|
|
6029
6692
|
snapshot
|
|
@@ -6032,12 +6695,12 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6032
6695
|
}),
|
|
6033
6696
|
actions: [(_, {
|
|
6034
6697
|
selectedTextBlocks
|
|
6035
|
-
}) => selectedTextBlocks.map((block) =>
|
|
6698
|
+
}) => selectedTextBlocks.map((block) => behaviors_index.raise({
|
|
6036
6699
|
type: "block.unset",
|
|
6037
6700
|
at: block.path,
|
|
6038
6701
|
props: ["level", "listItem"]
|
|
6039
6702
|
}))]
|
|
6040
|
-
}),
|
|
6703
|
+
}), behaviors_index.defineBehavior({
|
|
6041
6704
|
on: "list item.toggle",
|
|
6042
6705
|
guard: ({
|
|
6043
6706
|
snapshot,
|
|
@@ -6045,11 +6708,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6045
6708
|
}) => selector_isSelectingEntireBlocks.isActiveListItem(event.listItem)(snapshot),
|
|
6046
6709
|
actions: [({
|
|
6047
6710
|
event
|
|
6048
|
-
}) => [
|
|
6711
|
+
}) => [behaviors_index.raise({
|
|
6049
6712
|
type: "list item.remove",
|
|
6050
6713
|
listItem: event.listItem
|
|
6051
6714
|
})]]
|
|
6052
|
-
}),
|
|
6715
|
+
}), behaviors_index.defineBehavior({
|
|
6053
6716
|
on: "list item.toggle",
|
|
6054
6717
|
guard: ({
|
|
6055
6718
|
snapshot,
|
|
@@ -6057,17 +6720,17 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6057
6720
|
}) => !selector_isSelectingEntireBlocks.isActiveListItem(event.listItem)(snapshot),
|
|
6058
6721
|
actions: [({
|
|
6059
6722
|
event
|
|
6060
|
-
}) => [
|
|
6723
|
+
}) => [behaviors_index.raise({
|
|
6061
6724
|
type: "list item.add",
|
|
6062
6725
|
listItem: event.listItem
|
|
6063
6726
|
})]]
|
|
6064
|
-
})], abstractMoveBehaviors = [
|
|
6727
|
+
})], abstractMoveBehaviors = [behaviors_index.defineBehavior({
|
|
6065
6728
|
on: "move.block up",
|
|
6066
6729
|
guard: ({
|
|
6067
6730
|
snapshot,
|
|
6068
6731
|
event
|
|
6069
6732
|
}) => {
|
|
6070
|
-
const previousBlock =
|
|
6733
|
+
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock({
|
|
6071
6734
|
context: {
|
|
6072
6735
|
...snapshot.context,
|
|
6073
6736
|
selection: {
|
|
@@ -6090,18 +6753,18 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6090
6753
|
event
|
|
6091
6754
|
}, {
|
|
6092
6755
|
previousBlock
|
|
6093
|
-
}) => [
|
|
6756
|
+
}) => [behaviors_index.raise({
|
|
6094
6757
|
type: "move.block",
|
|
6095
6758
|
at: event.at,
|
|
6096
6759
|
to: previousBlock.path
|
|
6097
6760
|
})]]
|
|
6098
|
-
}),
|
|
6761
|
+
}), behaviors_index.defineBehavior({
|
|
6099
6762
|
on: "move.block down",
|
|
6100
6763
|
guard: ({
|
|
6101
6764
|
snapshot,
|
|
6102
6765
|
event
|
|
6103
6766
|
}) => {
|
|
6104
|
-
const nextBlock =
|
|
6767
|
+
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock({
|
|
6105
6768
|
context: {
|
|
6106
6769
|
...snapshot.context,
|
|
6107
6770
|
selection: {
|
|
@@ -6124,18 +6787,18 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6124
6787
|
event
|
|
6125
6788
|
}, {
|
|
6126
6789
|
nextBlock
|
|
6127
|
-
}) => [
|
|
6790
|
+
}) => [behaviors_index.raise({
|
|
6128
6791
|
type: "move.block",
|
|
6129
6792
|
at: event.at,
|
|
6130
6793
|
to: nextBlock.path
|
|
6131
6794
|
})]]
|
|
6132
|
-
})], abstractSelectBehaviors = [
|
|
6795
|
+
})], abstractSelectBehaviors = [behaviors_index.defineBehavior({
|
|
6133
6796
|
on: "select.previous block",
|
|
6134
6797
|
guard: ({
|
|
6135
6798
|
snapshot,
|
|
6136
6799
|
event
|
|
6137
6800
|
}) => {
|
|
6138
|
-
const previousBlock =
|
|
6801
|
+
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
6139
6802
|
if (!previousBlock)
|
|
6140
6803
|
return !1;
|
|
6141
6804
|
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint({
|
|
@@ -6154,17 +6817,17 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6154
6817
|
},
|
|
6155
6818
|
actions: [(_, {
|
|
6156
6819
|
selection
|
|
6157
|
-
}) => [
|
|
6820
|
+
}) => [behaviors_index.raise({
|
|
6158
6821
|
type: "select",
|
|
6159
6822
|
at: selection
|
|
6160
6823
|
})]]
|
|
6161
|
-
}),
|
|
6824
|
+
}), behaviors_index.defineBehavior({
|
|
6162
6825
|
on: "select.next block",
|
|
6163
6826
|
guard: ({
|
|
6164
6827
|
snapshot,
|
|
6165
6828
|
event
|
|
6166
6829
|
}) => {
|
|
6167
|
-
const nextBlock =
|
|
6830
|
+
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
6168
6831
|
if (!nextBlock)
|
|
6169
6832
|
return !1;
|
|
6170
6833
|
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint({
|
|
@@ -6183,18 +6846,18 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6183
6846
|
},
|
|
6184
6847
|
actions: [(_, {
|
|
6185
6848
|
selection
|
|
6186
|
-
}) => [
|
|
6849
|
+
}) => [behaviors_index.raise({
|
|
6187
6850
|
type: "select",
|
|
6188
6851
|
at: selection
|
|
6189
6852
|
})]]
|
|
6190
|
-
})], abstractSplitBehaviors = [
|
|
6853
|
+
})], abstractSplitBehaviors = [behaviors_index.defineBehavior({
|
|
6191
6854
|
on: "split",
|
|
6192
6855
|
guard: ({
|
|
6193
6856
|
snapshot
|
|
6194
6857
|
}) => {
|
|
6195
6858
|
if (!snapshot.context.selection)
|
|
6196
6859
|
return !1;
|
|
6197
|
-
const selectionStartPoint =
|
|
6860
|
+
const selectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock({
|
|
6198
6861
|
context: {
|
|
6199
6862
|
...snapshot.context,
|
|
6200
6863
|
selection: {
|
|
@@ -6232,7 +6895,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6232
6895
|
}
|
|
6233
6896
|
};
|
|
6234
6897
|
}
|
|
6235
|
-
if (
|
|
6898
|
+
if (selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
6236
6899
|
context: {
|
|
6237
6900
|
...snapshot.context,
|
|
6238
6901
|
selection: {
|
|
@@ -6265,16 +6928,16 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6265
6928
|
actions: [(_, {
|
|
6266
6929
|
newTextBlock,
|
|
6267
6930
|
selection
|
|
6268
|
-
}) => [
|
|
6931
|
+
}) => [behaviors_index.raise({
|
|
6269
6932
|
type: "delete",
|
|
6270
6933
|
at: selection
|
|
6271
|
-
}),
|
|
6934
|
+
}), behaviors_index.raise({
|
|
6272
6935
|
type: "insert.block",
|
|
6273
6936
|
block: newTextBlock,
|
|
6274
6937
|
placement: "after",
|
|
6275
6938
|
select: "start"
|
|
6276
6939
|
})]]
|
|
6277
|
-
})], abstractStyleBehaviors = [
|
|
6940
|
+
})], abstractStyleBehaviors = [behaviors_index.defineBehavior({
|
|
6278
6941
|
on: "style.add",
|
|
6279
6942
|
guard: ({
|
|
6280
6943
|
snapshot
|
|
@@ -6285,14 +6948,14 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6285
6948
|
event
|
|
6286
6949
|
}, {
|
|
6287
6950
|
selectedTextBlocks
|
|
6288
|
-
}) => selectedTextBlocks.map((block) =>
|
|
6951
|
+
}) => selectedTextBlocks.map((block) => behaviors_index.raise({
|
|
6289
6952
|
type: "block.set",
|
|
6290
6953
|
at: block.path,
|
|
6291
6954
|
props: {
|
|
6292
6955
|
style: event.style
|
|
6293
6956
|
}
|
|
6294
6957
|
}))]
|
|
6295
|
-
}),
|
|
6958
|
+
}), behaviors_index.defineBehavior({
|
|
6296
6959
|
on: "style.remove",
|
|
6297
6960
|
guard: ({
|
|
6298
6961
|
snapshot
|
|
@@ -6301,12 +6964,12 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6301
6964
|
}),
|
|
6302
6965
|
actions: [(_, {
|
|
6303
6966
|
selectedTextBlocks
|
|
6304
|
-
}) => selectedTextBlocks.map((block) =>
|
|
6967
|
+
}) => selectedTextBlocks.map((block) => behaviors_index.raise({
|
|
6305
6968
|
type: "block.unset",
|
|
6306
6969
|
at: block.path,
|
|
6307
6970
|
props: ["style"]
|
|
6308
6971
|
}))]
|
|
6309
|
-
}),
|
|
6972
|
+
}), behaviors_index.defineBehavior({
|
|
6310
6973
|
on: "style.toggle",
|
|
6311
6974
|
guard: ({
|
|
6312
6975
|
snapshot,
|
|
@@ -6314,11 +6977,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6314
6977
|
}) => selector_isSelectingEntireBlocks.isActiveStyle(event.style)(snapshot),
|
|
6315
6978
|
actions: [({
|
|
6316
6979
|
event
|
|
6317
|
-
}) => [
|
|
6980
|
+
}) => [behaviors_index.raise({
|
|
6318
6981
|
type: "style.remove",
|
|
6319
6982
|
style: event.style
|
|
6320
6983
|
})]]
|
|
6321
|
-
}),
|
|
6984
|
+
}), behaviors_index.defineBehavior({
|
|
6322
6985
|
on: "style.toggle",
|
|
6323
6986
|
guard: ({
|
|
6324
6987
|
snapshot,
|
|
@@ -6326,21 +6989,21 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6326
6989
|
}) => !selector_isSelectingEntireBlocks.isActiveStyle(event.style)(snapshot),
|
|
6327
6990
|
actions: [({
|
|
6328
6991
|
event
|
|
6329
|
-
}) => [
|
|
6992
|
+
}) => [behaviors_index.raise({
|
|
6330
6993
|
type: "style.add",
|
|
6331
6994
|
style: event.style
|
|
6332
6995
|
})]]
|
|
6333
6996
|
})], keyIs = {
|
|
6334
6997
|
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
6335
|
-
}, raiseInsertSoftBreak =
|
|
6998
|
+
}, raiseInsertSoftBreak = behaviors_index.defineBehavior({
|
|
6336
6999
|
on: "keyboard.keydown",
|
|
6337
7000
|
guard: ({
|
|
6338
7001
|
event
|
|
6339
7002
|
}) => keyIs.lineBreak(event.originEvent),
|
|
6340
|
-
actions: [() => [
|
|
7003
|
+
actions: [() => [behaviors_index.raise({
|
|
6341
7004
|
type: "insert.soft break"
|
|
6342
7005
|
})]]
|
|
6343
|
-
}), raiseDeserializationSuccessOrFailure =
|
|
7006
|
+
}), raiseDeserializationSuccessOrFailure = behaviors_index.defineBehavior({
|
|
6344
7007
|
on: "deserialize",
|
|
6345
7008
|
guard: ({
|
|
6346
7009
|
snapshot,
|
|
@@ -6373,11 +7036,11 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6373
7036
|
},
|
|
6374
7037
|
actions: [({
|
|
6375
7038
|
event
|
|
6376
|
-
}, deserializeEvent) => [
|
|
7039
|
+
}, deserializeEvent) => [behaviors_index.raise({
|
|
6377
7040
|
...deserializeEvent,
|
|
6378
7041
|
originEvent: event.originEvent
|
|
6379
7042
|
})]]
|
|
6380
|
-
}), raiseSerializationSuccessOrFailure =
|
|
7043
|
+
}), raiseSerializationSuccessOrFailure = behaviors_index.defineBehavior({
|
|
6381
7044
|
on: "serialize",
|
|
6382
7045
|
guard: ({
|
|
6383
7046
|
snapshot,
|
|
@@ -6396,41 +7059,41 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6396
7059
|
},
|
|
6397
7060
|
actions: [({
|
|
6398
7061
|
event
|
|
6399
|
-
}, serializeEvents) => serializeEvents.map((serializeEvent) =>
|
|
7062
|
+
}, serializeEvents) => serializeEvents.map((serializeEvent) => behaviors_index.raise({
|
|
6400
7063
|
...serializeEvent,
|
|
6401
7064
|
originEvent: event.originEvent
|
|
6402
7065
|
}))]
|
|
6403
7066
|
}), defaultBehaviors = [
|
|
6404
|
-
|
|
7067
|
+
behaviors_index.defineBehavior({
|
|
6405
7068
|
on: "clipboard.copy",
|
|
6406
7069
|
guard: ({
|
|
6407
7070
|
snapshot
|
|
6408
7071
|
}) => {
|
|
6409
|
-
const focusSpan =
|
|
7072
|
+
const focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot);
|
|
6410
7073
|
return focusSpan && selectionCollapsed;
|
|
6411
7074
|
},
|
|
6412
7075
|
actions: []
|
|
6413
7076
|
}),
|
|
6414
|
-
|
|
7077
|
+
behaviors_index.defineBehavior({
|
|
6415
7078
|
on: "clipboard.copy",
|
|
6416
7079
|
actions: [({
|
|
6417
7080
|
event
|
|
6418
|
-
}) => [
|
|
7081
|
+
}) => [behaviors_index.raise({
|
|
6419
7082
|
type: "serialize",
|
|
6420
7083
|
originEvent: event
|
|
6421
7084
|
})]]
|
|
6422
7085
|
}),
|
|
6423
|
-
|
|
7086
|
+
behaviors_index.defineBehavior({
|
|
6424
7087
|
on: "clipboard.cut",
|
|
6425
7088
|
guard: ({
|
|
6426
7089
|
snapshot
|
|
6427
7090
|
}) => {
|
|
6428
|
-
const focusSpan =
|
|
7091
|
+
const focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot);
|
|
6429
7092
|
return focusSpan && selectionCollapsed;
|
|
6430
7093
|
},
|
|
6431
7094
|
actions: []
|
|
6432
7095
|
}),
|
|
6433
|
-
|
|
7096
|
+
behaviors_index.defineBehavior({
|
|
6434
7097
|
on: "clipboard.cut",
|
|
6435
7098
|
guard: ({
|
|
6436
7099
|
snapshot
|
|
@@ -6441,24 +7104,24 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6441
7104
|
event
|
|
6442
7105
|
}, {
|
|
6443
7106
|
selection
|
|
6444
|
-
}) => [
|
|
7107
|
+
}) => [behaviors_index.raise({
|
|
6445
7108
|
type: "serialize",
|
|
6446
7109
|
originEvent: event
|
|
6447
|
-
}),
|
|
7110
|
+
}), behaviors_index.raise({
|
|
6448
7111
|
type: "delete",
|
|
6449
7112
|
at: selection
|
|
6450
7113
|
})]]
|
|
6451
7114
|
}),
|
|
6452
|
-
|
|
7115
|
+
behaviors_index.defineBehavior({
|
|
6453
7116
|
on: "drag.dragstart",
|
|
6454
7117
|
actions: [({
|
|
6455
7118
|
event
|
|
6456
|
-
}) => [
|
|
7119
|
+
}) => [behaviors_index.raise({
|
|
6457
7120
|
type: "serialize",
|
|
6458
7121
|
originEvent: event
|
|
6459
7122
|
})]]
|
|
6460
7123
|
}),
|
|
6461
|
-
|
|
7124
|
+
behaviors_index.defineBehavior({
|
|
6462
7125
|
on: "serialization.success",
|
|
6463
7126
|
actions: [({
|
|
6464
7127
|
event
|
|
@@ -6469,7 +7132,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6469
7132
|
}
|
|
6470
7133
|
}]]
|
|
6471
7134
|
}),
|
|
6472
|
-
|
|
7135
|
+
behaviors_index.defineBehavior({
|
|
6473
7136
|
on: "serialization.failure",
|
|
6474
7137
|
actions: [({
|
|
6475
7138
|
event
|
|
@@ -6480,14 +7143,14 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6480
7143
|
}
|
|
6481
7144
|
}]]
|
|
6482
7145
|
}),
|
|
6483
|
-
|
|
7146
|
+
behaviors_index.defineBehavior({
|
|
6484
7147
|
on: "drag.drop",
|
|
6485
7148
|
guard: ({
|
|
6486
7149
|
snapshot,
|
|
6487
7150
|
event
|
|
6488
7151
|
}) => {
|
|
6489
7152
|
const dragOrigin = snapshot.beta.internalDrag?.origin, dropPosition = event.position.selection;
|
|
6490
|
-
return dragOrigin ?
|
|
7153
|
+
return dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
|
|
6491
7154
|
...snapshot,
|
|
6492
7155
|
context: {
|
|
6493
7156
|
...snapshot.context,
|
|
@@ -6497,19 +7160,19 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6497
7160
|
},
|
|
6498
7161
|
actions: []
|
|
6499
7162
|
}),
|
|
6500
|
-
|
|
7163
|
+
behaviors_index.defineBehavior({
|
|
6501
7164
|
on: "drag.drop",
|
|
6502
7165
|
actions: [({
|
|
6503
7166
|
event
|
|
6504
|
-
}) => [
|
|
7167
|
+
}) => [behaviors_index.raise({
|
|
6505
7168
|
type: "select",
|
|
6506
7169
|
at: event.position.selection
|
|
6507
|
-
}),
|
|
7170
|
+
}), behaviors_index.raise({
|
|
6508
7171
|
type: "deserialize",
|
|
6509
7172
|
originEvent: event
|
|
6510
7173
|
})]]
|
|
6511
7174
|
}),
|
|
6512
|
-
|
|
7175
|
+
behaviors_index.defineBehavior({
|
|
6513
7176
|
on: "deserialization.success",
|
|
6514
7177
|
guard: ({
|
|
6515
7178
|
snapshot,
|
|
@@ -6517,7 +7180,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6517
7180
|
}) => {
|
|
6518
7181
|
if (event.originEvent.type !== "drag.drop" || snapshot.beta.internalDrag === void 0)
|
|
6519
7182
|
return !1;
|
|
6520
|
-
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ?
|
|
7183
|
+
const dragOrigin = snapshot.beta.internalDrag.origin, dropPosition = event.originEvent.position.selection, droppingOnDragOrigin = dragOrigin ? selector_isSelectingEntireBlocks.isOverlappingSelection(dropPosition)({
|
|
6521
7184
|
...snapshot,
|
|
6522
7185
|
context: {
|
|
6523
7186
|
...snapshot.context,
|
|
@@ -6528,7 +7191,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6528
7191
|
...snapshot.context,
|
|
6529
7192
|
selection: dragOrigin.selection
|
|
6530
7193
|
}
|
|
6531
|
-
}), draggedBlocks =
|
|
7194
|
+
}), draggedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks({
|
|
6532
7195
|
context: {
|
|
6533
7196
|
...snapshot.context,
|
|
6534
7197
|
selection: dragOrigin.selection
|
|
@@ -6548,13 +7211,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6548
7211
|
draggedBlocks,
|
|
6549
7212
|
dragOrigin,
|
|
6550
7213
|
originEvent
|
|
6551
|
-
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) =>
|
|
7214
|
+
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behaviors_index.raise({
|
|
6552
7215
|
type: "delete.block",
|
|
6553
7216
|
at: block.path
|
|
6554
|
-
})) : [
|
|
7217
|
+
})) : [behaviors_index.raise({
|
|
6555
7218
|
type: "delete",
|
|
6556
7219
|
at: dragOrigin.selection
|
|
6557
|
-
})],
|
|
7220
|
+
})], behaviors_index.raise({
|
|
6558
7221
|
type: "insert.blocks",
|
|
6559
7222
|
blocks: event.data,
|
|
6560
7223
|
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
@@ -6565,13 +7228,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6565
7228
|
* assume that the intended behavior is that the pasted text inherits
|
|
6566
7229
|
* formatting from the text it's pasted into.
|
|
6567
7230
|
*/
|
|
6568
|
-
|
|
7231
|
+
behaviors_index.defineBehavior({
|
|
6569
7232
|
on: "deserialization.success",
|
|
6570
7233
|
guard: ({
|
|
6571
7234
|
snapshot,
|
|
6572
7235
|
event
|
|
6573
7236
|
}) => {
|
|
6574
|
-
if (
|
|
7237
|
+
if (selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
6575
7238
|
const activeDecorators = snapshot.context.activeDecorators;
|
|
6576
7239
|
return {
|
|
6577
7240
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
@@ -6585,7 +7248,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6585
7248
|
activeAnnotations,
|
|
6586
7249
|
activeDecorators,
|
|
6587
7250
|
textRuns
|
|
6588
|
-
}) => textRuns.flatMap((textRun, index) => index !== textRuns.length - 1 ? [
|
|
7251
|
+
}) => textRuns.flatMap((textRun, index) => index !== textRuns.length - 1 ? [behaviors_index.raise({
|
|
6589
7252
|
type: "insert.span",
|
|
6590
7253
|
text: textRun,
|
|
6591
7254
|
decorators: activeDecorators,
|
|
@@ -6597,9 +7260,9 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6597
7260
|
name: _type,
|
|
6598
7261
|
value
|
|
6599
7262
|
}))
|
|
6600
|
-
}),
|
|
7263
|
+
}), behaviors_index.raise({
|
|
6601
7264
|
type: "insert.break"
|
|
6602
|
-
})] : [
|
|
7265
|
+
})] : [behaviors_index.raise({
|
|
6603
7266
|
type: "insert.span",
|
|
6604
7267
|
text: textRun,
|
|
6605
7268
|
decorators: activeDecorators,
|
|
@@ -6613,17 +7276,17 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6613
7276
|
}))
|
|
6614
7277
|
})])]
|
|
6615
7278
|
}),
|
|
6616
|
-
|
|
7279
|
+
behaviors_index.defineBehavior({
|
|
6617
7280
|
on: "deserialization.success",
|
|
6618
7281
|
actions: [({
|
|
6619
7282
|
event
|
|
6620
|
-
}) => [
|
|
7283
|
+
}) => [behaviors_index.raise({
|
|
6621
7284
|
type: "insert.blocks",
|
|
6622
7285
|
blocks: event.data,
|
|
6623
7286
|
placement: "auto"
|
|
6624
7287
|
})]]
|
|
6625
7288
|
}),
|
|
6626
|
-
|
|
7289
|
+
behaviors_index.defineBehavior({
|
|
6627
7290
|
on: "deserialization.failure",
|
|
6628
7291
|
actions: [({
|
|
6629
7292
|
event
|
|
@@ -6634,39 +7297,39 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6634
7297
|
}
|
|
6635
7298
|
}]]
|
|
6636
7299
|
}),
|
|
6637
|
-
|
|
7300
|
+
behaviors_index.defineBehavior({
|
|
6638
7301
|
on: "clipboard.paste",
|
|
6639
7302
|
guard: ({
|
|
6640
7303
|
snapshot
|
|
6641
|
-
}) => snapshot.context.selection &&
|
|
7304
|
+
}) => snapshot.context.selection && selector_isSelectingEntireBlocks.isSelectionExpanded(snapshot) ? {
|
|
6642
7305
|
selection: snapshot.context.selection
|
|
6643
7306
|
} : !1,
|
|
6644
7307
|
actions: [({
|
|
6645
7308
|
event
|
|
6646
7309
|
}, {
|
|
6647
7310
|
selection
|
|
6648
|
-
}) => [
|
|
7311
|
+
}) => [behaviors_index.raise({
|
|
6649
7312
|
type: "delete",
|
|
6650
7313
|
at: selection
|
|
6651
|
-
}),
|
|
7314
|
+
}), behaviors_index.raise({
|
|
6652
7315
|
type: "deserialize",
|
|
6653
7316
|
originEvent: event
|
|
6654
7317
|
})]]
|
|
6655
7318
|
}),
|
|
6656
|
-
|
|
7319
|
+
behaviors_index.defineBehavior({
|
|
6657
7320
|
on: "clipboard.paste",
|
|
6658
7321
|
actions: [({
|
|
6659
7322
|
event
|
|
6660
|
-
}) => [
|
|
7323
|
+
}) => [behaviors_index.raise({
|
|
6661
7324
|
type: "deserialize",
|
|
6662
7325
|
originEvent: event
|
|
6663
7326
|
})]]
|
|
6664
7327
|
}),
|
|
6665
|
-
|
|
7328
|
+
behaviors_index.defineBehavior({
|
|
6666
7329
|
on: "input.*",
|
|
6667
7330
|
actions: [({
|
|
6668
7331
|
event
|
|
6669
|
-
}) => [
|
|
7332
|
+
}) => [behaviors_index.raise({
|
|
6670
7333
|
type: "deserialize",
|
|
6671
7334
|
originEvent: event
|
|
6672
7335
|
})]]
|
|
@@ -6936,11 +7599,6 @@ const editorMachine = xstate.setup({
|
|
|
6936
7599
|
event
|
|
6937
7600
|
}) => (xstate.assertEvent(event, "remove behavior"), context.behaviors.delete(event.behavior), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
6938
7601
|
}),
|
|
6939
|
-
"assign behaviors": xstate.assign({
|
|
6940
|
-
behaviors: ({
|
|
6941
|
-
event
|
|
6942
|
-
}) => (xstate.assertEvent(event, "update behaviors"), /* @__PURE__ */ new Set([...event.behaviors]))
|
|
6943
|
-
}),
|
|
6944
7602
|
"assign schema": xstate.assign({
|
|
6945
7603
|
schema: ({
|
|
6946
7604
|
event
|
|
@@ -6986,6 +7644,22 @@ const editorMachine = xstate.setup({
|
|
|
6986
7644
|
"clear pending events": xstate.assign({
|
|
6987
7645
|
pendingEvents: []
|
|
6988
7646
|
}),
|
|
7647
|
+
"defer incoming patches": xstate.assign({
|
|
7648
|
+
pendingIncomingPatchesEvents: ({
|
|
7649
|
+
context,
|
|
7650
|
+
event
|
|
7651
|
+
}) => event.type === "patches" ? [...context.pendingIncomingPatchesEvents, event] : context.pendingIncomingPatchesEvents
|
|
7652
|
+
}),
|
|
7653
|
+
"emit pending incoming patches": xstate.enqueueActions(({
|
|
7654
|
+
context,
|
|
7655
|
+
enqueue
|
|
7656
|
+
}) => {
|
|
7657
|
+
for (const event of context.pendingIncomingPatchesEvents)
|
|
7658
|
+
enqueue.emit(event);
|
|
7659
|
+
}),
|
|
7660
|
+
"clear pending incoming patches": xstate.assign({
|
|
7661
|
+
pendingIncomingPatchesEvents: []
|
|
7662
|
+
}),
|
|
6989
7663
|
"handle blur": ({
|
|
6990
7664
|
event
|
|
6991
7665
|
}) => {
|
|
@@ -7048,11 +7722,12 @@ const editorMachine = xstate.setup({
|
|
|
7048
7722
|
context: ({
|
|
7049
7723
|
input
|
|
7050
7724
|
}) => ({
|
|
7051
|
-
behaviors: /* @__PURE__ */ new Set([...
|
|
7725
|
+
behaviors: /* @__PURE__ */ new Set([...coreBehaviors]),
|
|
7052
7726
|
converters: new Set(input.converters ?? []),
|
|
7053
7727
|
getLegacySchema: input.getLegacySchema,
|
|
7054
7728
|
keyGenerator: input.keyGenerator,
|
|
7055
7729
|
pendingEvents: [],
|
|
7730
|
+
pendingIncomingPatchesEvents: [],
|
|
7056
7731
|
schema: input.schema,
|
|
7057
7732
|
selection: null,
|
|
7058
7733
|
initialReadOnly: input.readOnly ?? !1,
|
|
@@ -7136,14 +7811,6 @@ const editorMachine = xstate.setup({
|
|
|
7136
7811
|
"remove behavior": {
|
|
7137
7812
|
actions: "remove behavior from context"
|
|
7138
7813
|
},
|
|
7139
|
-
patches: {
|
|
7140
|
-
actions: xstate.emit(({
|
|
7141
|
-
event
|
|
7142
|
-
}) => event)
|
|
7143
|
-
},
|
|
7144
|
-
"update behaviors": {
|
|
7145
|
-
actions: "assign behaviors"
|
|
7146
|
-
},
|
|
7147
7814
|
"update key generator": {
|
|
7148
7815
|
actions: xstate.assign({
|
|
7149
7816
|
keyGenerator: ({
|
|
@@ -7187,7 +7854,7 @@ const editorMachine = xstate.setup({
|
|
|
7187
7854
|
states: {
|
|
7188
7855
|
"determine initial edit mode": {
|
|
7189
7856
|
on: {
|
|
7190
|
-
"done syncing
|
|
7857
|
+
"done syncing value": [{
|
|
7191
7858
|
target: "#editor.edit mode.read only.read only",
|
|
7192
7859
|
guard: ({
|
|
7193
7860
|
context
|
|
@@ -7303,7 +7970,7 @@ const editorMachine = xstate.setup({
|
|
|
7303
7970
|
initial: "setting up",
|
|
7304
7971
|
states: {
|
|
7305
7972
|
"setting up": {
|
|
7306
|
-
exit: ["emit ready"],
|
|
7973
|
+
exit: ["emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
7307
7974
|
on: {
|
|
7308
7975
|
"internal.patch": {
|
|
7309
7976
|
actions: "defer event"
|
|
@@ -7311,54 +7978,95 @@ const editorMachine = xstate.setup({
|
|
|
7311
7978
|
mutation: {
|
|
7312
7979
|
actions: "defer event"
|
|
7313
7980
|
},
|
|
7314
|
-
"done syncing
|
|
7315
|
-
target: "
|
|
7981
|
+
"done syncing value": {
|
|
7982
|
+
target: "set up"
|
|
7983
|
+
},
|
|
7984
|
+
patches: {
|
|
7985
|
+
actions: ["defer incoming patches"]
|
|
7316
7986
|
}
|
|
7317
7987
|
}
|
|
7318
7988
|
},
|
|
7319
|
-
|
|
7320
|
-
|
|
7989
|
+
"set up": {
|
|
7990
|
+
type: "parallel",
|
|
7321
7991
|
states: {
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7992
|
+
"value sync": {
|
|
7993
|
+
initial: "idle",
|
|
7994
|
+
states: {
|
|
7995
|
+
idle: {
|
|
7996
|
+
on: {
|
|
7997
|
+
patches: {
|
|
7998
|
+
actions: [xstate.emit(({
|
|
7999
|
+
event
|
|
8000
|
+
}) => event)]
|
|
8001
|
+
},
|
|
8002
|
+
"syncing value": {
|
|
8003
|
+
target: "syncing value"
|
|
8004
|
+
}
|
|
8005
|
+
}
|
|
7330
8006
|
},
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
8007
|
+
"syncing value": {
|
|
8008
|
+
exit: ["emit pending incoming patches", "clear pending incoming patches"],
|
|
8009
|
+
on: {
|
|
8010
|
+
patches: {
|
|
8011
|
+
actions: ["defer incoming patches"]
|
|
8012
|
+
},
|
|
8013
|
+
"done syncing value": {
|
|
8014
|
+
target: "idle"
|
|
8015
|
+
}
|
|
8016
|
+
}
|
|
7334
8017
|
}
|
|
7335
8018
|
}
|
|
7336
8019
|
},
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
8020
|
+
writing: {
|
|
8021
|
+
initial: "pristine",
|
|
8022
|
+
states: {
|
|
8023
|
+
pristine: {
|
|
8024
|
+
initial: "idle",
|
|
8025
|
+
states: {
|
|
8026
|
+
idle: {
|
|
8027
|
+
on: {
|
|
8028
|
+
normalizing: {
|
|
8029
|
+
target: "normalizing"
|
|
8030
|
+
},
|
|
8031
|
+
"internal.patch": {
|
|
8032
|
+
actions: "defer event",
|
|
8033
|
+
target: "#editor.setup.set up.writing.dirty"
|
|
8034
|
+
},
|
|
8035
|
+
mutation: {
|
|
8036
|
+
actions: "defer event",
|
|
8037
|
+
target: "#editor.setup.set up.writing.dirty"
|
|
8038
|
+
}
|
|
8039
|
+
}
|
|
8040
|
+
},
|
|
8041
|
+
normalizing: {
|
|
8042
|
+
on: {
|
|
8043
|
+
"done normalizing": {
|
|
8044
|
+
target: "idle"
|
|
8045
|
+
},
|
|
8046
|
+
"internal.patch": {
|
|
8047
|
+
actions: "defer event"
|
|
8048
|
+
},
|
|
8049
|
+
mutation: {
|
|
8050
|
+
actions: "defer event"
|
|
8051
|
+
}
|
|
8052
|
+
}
|
|
8053
|
+
}
|
|
8054
|
+
}
|
|
7344
8055
|
},
|
|
7345
|
-
|
|
7346
|
-
|
|
8056
|
+
dirty: {
|
|
8057
|
+
entry: ["emit pending events", "clear pending events"],
|
|
8058
|
+
on: {
|
|
8059
|
+
"internal.patch": {
|
|
8060
|
+
actions: "emit patch event"
|
|
8061
|
+
},
|
|
8062
|
+
mutation: {
|
|
8063
|
+
actions: "emit mutation event"
|
|
8064
|
+
}
|
|
8065
|
+
}
|
|
7347
8066
|
}
|
|
7348
8067
|
}
|
|
7349
8068
|
}
|
|
7350
8069
|
}
|
|
7351
|
-
},
|
|
7352
|
-
dirty: {
|
|
7353
|
-
entry: ["emit pending events", "clear pending events"],
|
|
7354
|
-
on: {
|
|
7355
|
-
"internal.patch": {
|
|
7356
|
-
actions: "emit patch event"
|
|
7357
|
-
},
|
|
7358
|
-
mutation: {
|
|
7359
|
-
actions: "emit mutation event"
|
|
7360
|
-
}
|
|
7361
|
-
}
|
|
7362
8070
|
}
|
|
7363
8071
|
}
|
|
7364
8072
|
}
|
|
@@ -7932,6 +8640,7 @@ exports.EditorActorContext = EditorActorContext;
|
|
|
7932
8640
|
exports.EditorProvider = EditorProvider;
|
|
7933
8641
|
exports.KEY_TO_VALUE_ELEMENT = KEY_TO_VALUE_ELEMENT;
|
|
7934
8642
|
exports.PortableTextEditor = PortableTextEditor;
|
|
8643
|
+
exports.coreBehaviors = coreBehaviors;
|
|
7935
8644
|
exports.debugWithName = debugWithName;
|
|
7936
8645
|
exports.defaultKeyGenerator = defaultKeyGenerator;
|
|
7937
8646
|
exports.defineSchema = defineSchema;
|
|
@@ -7941,6 +8650,7 @@ exports.getFirstBlock = getFirstBlock;
|
|
|
7941
8650
|
exports.getLastBlock = getLastBlock;
|
|
7942
8651
|
exports.getNodeBlock = getNodeBlock;
|
|
7943
8652
|
exports.isEqualToEmptyEditor = isEqualToEmptyEditor;
|
|
8653
|
+
exports.isHotkey = isHotkey;
|
|
7944
8654
|
exports.moveRangeByOperation = moveRangeByOperation;
|
|
7945
8655
|
exports.slateRangeToSelection = slateRangeToSelection;
|
|
7946
8656
|
exports.toSlateRange = toSlateRange;
|