@portabletext/editor 1.33.3 → 1.33.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +11 -204
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +7 -7
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +196 -25
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +246 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +23 -198
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +3 -3
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -135
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +138 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +9 -202
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +193 -23
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +2 -1
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +249 -0
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +12 -187
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js +1 -1
- package/lib/_chunks-es/util.reverse-selection.js +1 -136
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +140 -3
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.d.cts +1 -115
- package/lib/index.d.ts +1 -115
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +1 -115
- package/lib/plugins/index.d.ts +1 -115
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +16 -21
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +7 -11
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +13 -13
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.js +3 -3
- package/package.json +1 -1
- package/src/behaviors/behavior.core.annotations.ts +0 -24
- package/src/behaviors/behavior.core.decorators.ts +0 -19
- package/src/behaviors/behavior.core.insert-break.ts +4 -4
- package/src/behaviors/behavior.core.lists.ts +0 -30
- package/src/behaviors/behavior.core.ts +2 -17
- package/src/behaviors/behavior.default.ts +198 -0
- package/src/behaviors/behavior.foundational.ts +12 -12
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/editor/editor-machine.ts +8 -8
- package/src/selectors/selector.get-selection-text.ts +14 -89
- package/src/utils/util.slice-blocks.ts +12 -1
- package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs +0 -97
- package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-trimmed-selection.js +0 -100
- package/lib/_chunks-es/selector.get-trimmed-selection.js.map +0 -1
- package/src/behaviors/behavior.core.deserialize.ts +0 -60
- package/src/behaviors/behavior.core.serialize.ts +0 -44
- package/src/behaviors/behavior.core.style.ts +0 -19
|
@@ -15,7 +15,7 @@ import isPlainObject from "lodash/isPlainObject.js";
|
|
|
15
15
|
import uniq from "lodash/uniq.js";
|
|
16
16
|
import getRandomValues from "get-random-values-esm";
|
|
17
17
|
import { parseBlock, blockOffsetsToSelection } from "./util.block-offsets-to-selection.js";
|
|
18
|
-
import { sliceBlocks } from "./util.slice-blocks.js";
|
|
18
|
+
import { sliceBlocks, spanSelectionPointToBlockOffset } from "./util.slice-blocks.js";
|
|
19
19
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
20
20
|
import { toHTML } from "@portabletext/to-html";
|
|
21
21
|
import { Schema } from "@sanity/schema";
|
|
@@ -23,8 +23,7 @@ import get from "lodash/get.js";
|
|
|
23
23
|
import isUndefined from "lodash/isUndefined.js";
|
|
24
24
|
import omitBy from "lodash/omitBy.js";
|
|
25
25
|
import { createGuards } from "./selector.is-at-the-start-of-block.js";
|
|
26
|
-
import {
|
|
27
|
-
import { getTrimmedSelection } from "./selector.get-trimmed-selection.js";
|
|
26
|
+
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "./selector.is-active-style.js";
|
|
28
27
|
import startCase from "lodash.startcase";
|
|
29
28
|
import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
30
29
|
import { Subject } from "rxjs";
|
|
@@ -5707,24 +5706,195 @@ function createSlateEditor(config) {
|
|
|
5707
5706
|
};
|
|
5708
5707
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5709
5708
|
}
|
|
5710
|
-
const
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5709
|
+
const toggleAnnotationOff = defineBehavior({
|
|
5710
|
+
on: "annotation.toggle",
|
|
5711
|
+
guard: ({
|
|
5712
|
+
context,
|
|
5713
|
+
event
|
|
5714
|
+
}) => isActiveAnnotation(event.annotation.name)({
|
|
5715
|
+
context
|
|
5716
|
+
}),
|
|
5717
|
+
actions: [({
|
|
5718
|
+
event
|
|
5719
|
+
}) => [raise({
|
|
5720
|
+
type: "annotation.remove",
|
|
5721
|
+
annotation: event.annotation
|
|
5722
|
+
})]]
|
|
5723
|
+
}), toggleAnnotationOn = defineBehavior({
|
|
5724
|
+
on: "annotation.toggle",
|
|
5725
|
+
guard: ({
|
|
5726
|
+
context,
|
|
5727
|
+
event
|
|
5728
|
+
}) => !isActiveAnnotation(event.annotation.name)({
|
|
5729
|
+
context
|
|
5730
|
+
}),
|
|
5731
|
+
actions: [({
|
|
5732
|
+
event
|
|
5733
|
+
}) => [raise({
|
|
5734
|
+
type: "annotation.add",
|
|
5735
|
+
annotation: event.annotation
|
|
5736
|
+
})]]
|
|
5737
|
+
}), toggleDecoratorOff = defineBehavior({
|
|
5738
|
+
on: "decorator.toggle",
|
|
5739
|
+
guard: ({
|
|
5740
|
+
context,
|
|
5741
|
+
event
|
|
5742
|
+
}) => isActiveDecorator(event.decorator)({
|
|
5743
|
+
context
|
|
5744
|
+
}),
|
|
5745
|
+
actions: [({
|
|
5746
|
+
event
|
|
5747
|
+
}) => [raise({
|
|
5748
|
+
type: "decorator.remove",
|
|
5749
|
+
decorator: event.decorator
|
|
5750
|
+
})]]
|
|
5751
|
+
}), toggleDecoratorOn = defineBehavior({
|
|
5752
|
+
on: "decorator.toggle",
|
|
5753
|
+
guard: ({
|
|
5754
|
+
context,
|
|
5755
|
+
event
|
|
5756
|
+
}) => !isActiveDecorator(event.decorator)({
|
|
5757
|
+
context
|
|
5758
|
+
}),
|
|
5759
|
+
actions: [({
|
|
5760
|
+
event
|
|
5761
|
+
}) => [raise({
|
|
5762
|
+
type: "decorator.add",
|
|
5763
|
+
decorator: event.decorator
|
|
5764
|
+
})]]
|
|
5765
|
+
}), toggleListItemOff = defineBehavior({
|
|
5766
|
+
on: "list item.toggle",
|
|
5767
|
+
guard: ({
|
|
5768
|
+
context,
|
|
5769
|
+
event
|
|
5770
|
+
}) => isActiveListItem(event.listItem)({
|
|
5771
|
+
context
|
|
5772
|
+
}),
|
|
5773
|
+
actions: [({
|
|
5774
|
+
event
|
|
5775
|
+
}) => [raise({
|
|
5776
|
+
type: "list item.remove",
|
|
5777
|
+
listItem: event.listItem
|
|
5778
|
+
})]]
|
|
5779
|
+
}), toggleListItemOn = defineBehavior({
|
|
5780
|
+
on: "list item.toggle",
|
|
5781
|
+
guard: ({
|
|
5782
|
+
context,
|
|
5783
|
+
event
|
|
5784
|
+
}) => !isActiveListItem(event.listItem)({
|
|
5785
|
+
context
|
|
5786
|
+
}),
|
|
5787
|
+
actions: [({
|
|
5788
|
+
event
|
|
5789
|
+
}) => [raise({
|
|
5790
|
+
type: "list item.add",
|
|
5791
|
+
listItem: event.listItem
|
|
5792
|
+
})]]
|
|
5793
|
+
}), toggleStyleOff = defineBehavior({
|
|
5794
|
+
on: "style.toggle",
|
|
5795
|
+
guard: ({
|
|
5796
|
+
context,
|
|
5797
|
+
event
|
|
5798
|
+
}) => isActiveStyle(event.style)({
|
|
5799
|
+
context
|
|
5800
|
+
}),
|
|
5801
|
+
actions: [({
|
|
5802
|
+
event
|
|
5803
|
+
}) => [raise({
|
|
5804
|
+
type: "style.remove",
|
|
5805
|
+
style: event.style
|
|
5806
|
+
})]]
|
|
5807
|
+
}), toggleStyleOn = defineBehavior({
|
|
5808
|
+
on: "style.toggle",
|
|
5809
|
+
guard: ({
|
|
5810
|
+
context,
|
|
5811
|
+
event
|
|
5812
|
+
}) => !isActiveStyle(event.style)({
|
|
5813
|
+
context
|
|
5814
|
+
}),
|
|
5815
|
+
actions: [({
|
|
5816
|
+
event
|
|
5817
|
+
}) => [raise({
|
|
5818
|
+
type: "style.add",
|
|
5819
|
+
style: event.style
|
|
5820
|
+
})]]
|
|
5821
|
+
}), raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
5822
|
+
on: "deserialize",
|
|
5823
|
+
guard: ({
|
|
5824
|
+
context,
|
|
5825
|
+
event
|
|
5826
|
+
}) => {
|
|
5827
|
+
const deserializeEvents = context.converters.flatMap((converter) => {
|
|
5828
|
+
const data = event.dataTransfer.getData(converter.mimeType);
|
|
5829
|
+
return data ? [converter.deserialize({
|
|
5830
|
+
context,
|
|
5831
|
+
event: {
|
|
5832
|
+
type: "deserialize",
|
|
5833
|
+
data
|
|
5834
|
+
}
|
|
5835
|
+
})] : [];
|
|
5836
|
+
});
|
|
5837
|
+
return deserializeEvents.find((deserializeEvent) => deserializeEvent.type === "deserialization.success") || {
|
|
5838
|
+
type: "deserialization.failure",
|
|
5839
|
+
mimeType: "*/*",
|
|
5840
|
+
reason: deserializeEvents.map((deserializeEvent) => deserializeEvent.type === "deserialization.failure" ? deserializeEvent.reason : "").join(", ")
|
|
5841
|
+
};
|
|
5842
|
+
},
|
|
5843
|
+
actions: [({
|
|
5844
|
+
event
|
|
5845
|
+
}, deserializeEvent) => [raise({
|
|
5846
|
+
...deserializeEvent,
|
|
5847
|
+
dataTransfer: event.dataTransfer
|
|
5848
|
+
})]]
|
|
5849
|
+
}), raiseInsertBlocks = defineBehavior({
|
|
5850
|
+
on: "deserialization.success",
|
|
5851
|
+
actions: [({
|
|
5852
|
+
event
|
|
5853
|
+
}) => [raise({
|
|
5854
|
+
type: "insert.blocks",
|
|
5855
|
+
blocks: event.data
|
|
5856
|
+
})]]
|
|
5857
|
+
}), raiseSerializationSuccessOrFailure = defineBehavior({
|
|
5858
|
+
on: "serialize",
|
|
5859
|
+
guard: ({
|
|
5860
|
+
context,
|
|
5861
|
+
event
|
|
5862
|
+
}) => {
|
|
5863
|
+
if (context.converters.length === 0)
|
|
5864
|
+
return !1;
|
|
5865
|
+
const serializeEvents = context.converters.map((converter) => converter.serialize({
|
|
5866
|
+
context,
|
|
5721
5867
|
event
|
|
5722
|
-
})
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5868
|
+
}));
|
|
5869
|
+
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
5870
|
+
},
|
|
5871
|
+
actions: [({
|
|
5872
|
+
event
|
|
5873
|
+
}, serializeEvents) => serializeEvents.map((serializeEvent) => raise({
|
|
5874
|
+
...serializeEvent,
|
|
5875
|
+
dataTransfer: event.dataTransfer
|
|
5876
|
+
}))]
|
|
5877
|
+
}), raiseDataTransferSet = defineBehavior({
|
|
5878
|
+
on: "serialization.success",
|
|
5879
|
+
actions: [({
|
|
5880
|
+
event
|
|
5881
|
+
}) => [raise({
|
|
5882
|
+
type: "data transfer.set",
|
|
5883
|
+
data: event.data,
|
|
5884
|
+
dataTransfer: event.dataTransfer,
|
|
5885
|
+
mimeType: event.mimeType
|
|
5886
|
+
})]]
|
|
5887
|
+
}), defaultBehaviors = [toggleAnnotationOff, toggleAnnotationOn, toggleDecoratorOff, toggleDecoratorOn, toggleListItemOff, toggleListItemOn, toggleStyleOff, toggleStyleOn, raiseDeserializationSuccessOrFailure, raiseInsertBlocks, raiseSerializationSuccessOrFailure, raiseDataTransferSet], keyIs = {
|
|
5888
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
5889
|
+
}, raiseSoftBreak = defineBehavior({
|
|
5890
|
+
on: "key.down",
|
|
5891
|
+
guard: ({
|
|
5892
|
+
event
|
|
5893
|
+
}) => keyIs.lineBreak(event.keyboardEvent),
|
|
5894
|
+
actions: [() => [raise({
|
|
5895
|
+
type: "insert.soft break"
|
|
5896
|
+
})]]
|
|
5897
|
+
}), foundationalBehaviors = [raiseSoftBreak];
|
|
5728
5898
|
function getActiveDecorators({
|
|
5729
5899
|
schema,
|
|
5730
5900
|
slateEditorInstance
|
|
@@ -5778,7 +5948,7 @@ const editorMachine = setup({
|
|
|
5778
5948
|
"assign behaviors": assign({
|
|
5779
5949
|
behaviors: ({
|
|
5780
5950
|
event
|
|
5781
|
-
}) => (assertEvent(event, "update behaviors"), /* @__PURE__ */ new Set([...
|
|
5951
|
+
}) => (assertEvent(event, "update behaviors"), /* @__PURE__ */ new Set([...event.behaviors]))
|
|
5782
5952
|
}),
|
|
5783
5953
|
"assign schema": assign({
|
|
5784
5954
|
schema: ({
|
|
@@ -5825,7 +5995,7 @@ const editorMachine = setup({
|
|
|
5825
5995
|
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
5826
5996
|
...event.behaviorEvent,
|
|
5827
5997
|
editor: event.editor
|
|
5828
|
-
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5998
|
+
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...foundationalBehaviors, ...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5829
5999
|
if (eventBehaviors.length === 0) {
|
|
5830
6000
|
if (defaultActionCallback) {
|
|
5831
6001
|
withApplyingBehaviorActions(event.editor, () => {
|
|
@@ -5935,7 +6105,7 @@ const editorMachine = setup({
|
|
|
5935
6105
|
context: ({
|
|
5936
6106
|
input
|
|
5937
6107
|
}) => ({
|
|
5938
|
-
behaviors: /* @__PURE__ */ new Set([...
|
|
6108
|
+
behaviors: /* @__PURE__ */ new Set([...input.behaviors ?? coreBehaviors]),
|
|
5939
6109
|
converters: new Set(input.converters ?? []),
|
|
5940
6110
|
keyGenerator: input.keyGenerator,
|
|
5941
6111
|
pendingEvents: [],
|