@portabletext/editor 1.40.1 → 1.40.3
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 +37 -16
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +22 -10
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +27 -67
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +3 -2
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +26 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +37 -16
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +22 -10
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +27 -67
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +3 -2
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +27 -0
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -0
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -0
- package/lib/behaviors/index.d.cts +3881 -5053
- package/lib/behaviors/index.d.ts +3881 -5053
- package/lib/index.d.cts +3402 -4440
- package/lib/index.d.ts +3402 -4440
- package/lib/plugins/index.cjs +9 -127
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3404 -4441
- package/lib/plugins/index.d.ts +3404 -4441
- package/lib/plugins/index.js +11 -129
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +3401 -4440
- package/lib/selectors/index.d.ts +3401 -4440
- package/lib/utils/index.cjs +45 -4
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3402 -4441
- package/lib/utils/index.d.ts +3402 -4441
- package/lib/utils/index.js +45 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +8 -8
- package/src/behavior-actions/behavior.action.delete.block.ts +2 -2
- package/src/behavior-actions/behavior.actions.ts +0 -18
- package/src/behaviors/behavior.core.block-objects.ts +57 -7
- package/src/behaviors/behavior.core.insert-break.ts +0 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +22 -10
- package/src/behaviors/behavior.types.ts +171 -138
- package/src/editor/create-editor.ts +2 -0
- package/src/editor/editor-machine.ts +28 -28
- package/src/editor/plugins/create-with-event-listeners.ts +15 -0
- package/src/editor/plugins/createWithEditableAPI.ts +4 -4
- package/src/plugins/plugin.one-line.tsx +10 -128
- package/src/selectors/selector.get-selected-spans.test.ts +33 -0
- package/src/selectors/selector.get-selected-spans.ts +7 -1
- package/src/selectors/selector.is-active-decorator.test.ts +100 -27
- package/src/types/block-with-optional-key.ts +13 -0
- package/src/utils/util.is-text-block.ts +4 -3
- package/lib/_chunks-cjs/util.split-text-block.cjs +0 -68
- package/lib/_chunks-cjs/util.split-text-block.cjs.map +0 -1
- package/lib/_chunks-es/util.split-text-block.js +0 -70
- package/lib/_chunks-es/util.split-text-block.js.map +0 -1
- package/src/behavior-actions/behavior.action.insert.block-object.ts +0 -20
- package/src/behavior-actions/behavior.action.insert.text-block.ts +0 -33
|
@@ -3756,10 +3756,10 @@ function createEditableAPI(editor, editorActor) {
|
|
|
3756
3756
|
insertBlock: (type, value) => (editorActor.send({
|
|
3757
3757
|
type: "behavior event",
|
|
3758
3758
|
behaviorEvent: {
|
|
3759
|
-
type: "insert.block
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
value
|
|
3759
|
+
type: "insert.block",
|
|
3760
|
+
block: {
|
|
3761
|
+
_type: type.name,
|
|
3762
|
+
...value || {}
|
|
3763
3763
|
},
|
|
3764
3764
|
placement: "auto"
|
|
3765
3765
|
},
|
|
@@ -4241,11 +4241,11 @@ const addAnnotationActionImplementation = ({
|
|
|
4241
4241
|
}) => {
|
|
4242
4242
|
const range = toSlateRange({
|
|
4243
4243
|
anchor: {
|
|
4244
|
-
path: action.
|
|
4244
|
+
path: action.at,
|
|
4245
4245
|
offset: 0
|
|
4246
4246
|
},
|
|
4247
4247
|
focus: {
|
|
4248
|
-
path: action.
|
|
4248
|
+
path: action.at,
|
|
4249
4249
|
offset: 0
|
|
4250
4250
|
}
|
|
4251
4251
|
}, action.editor);
|
|
@@ -4707,53 +4707,10 @@ const selectActionImplementation = ({
|
|
|
4707
4707
|
text: action.text,
|
|
4708
4708
|
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
4709
4709
|
});
|
|
4710
|
-
}, insertBlockObjectActionImplementation = ({
|
|
4711
|
-
context,
|
|
4712
|
-
action
|
|
4713
|
-
}) => {
|
|
4714
|
-
insertBlockActionImplementation({
|
|
4715
|
-
context,
|
|
4716
|
-
action: {
|
|
4717
|
-
block: {
|
|
4718
|
-
_key: context.keyGenerator(),
|
|
4719
|
-
_type: action.blockObject.name,
|
|
4720
|
-
...action.blockObject.value ? action.blockObject.value : {}
|
|
4721
|
-
},
|
|
4722
|
-
editor: action.editor,
|
|
4723
|
-
placement: action.placement
|
|
4724
|
-
}
|
|
4725
|
-
});
|
|
4726
4710
|
}, insertTextActionImplementation = ({
|
|
4727
4711
|
action
|
|
4728
4712
|
}) => {
|
|
4729
4713
|
action.editor.insertText(action.text);
|
|
4730
|
-
}, insertTextBlockActionImplementation = ({
|
|
4731
|
-
context,
|
|
4732
|
-
action
|
|
4733
|
-
}) => {
|
|
4734
|
-
insertBlockActionImplementation({
|
|
4735
|
-
context,
|
|
4736
|
-
action: {
|
|
4737
|
-
block: {
|
|
4738
|
-
_key: context.keyGenerator(),
|
|
4739
|
-
_type: context.schema.block.name,
|
|
4740
|
-
children: action.textBlock?.children?.map((child) => ({
|
|
4741
|
-
...child,
|
|
4742
|
-
_key: context.keyGenerator()
|
|
4743
|
-
})) ?? [{
|
|
4744
|
-
_type: context.schema.span.name,
|
|
4745
|
-
_key: context.keyGenerator(),
|
|
4746
|
-
text: "",
|
|
4747
|
-
marks: []
|
|
4748
|
-
}],
|
|
4749
|
-
markDefs: [],
|
|
4750
|
-
style: context.schema.styles[0].value ?? "normal"
|
|
4751
|
-
},
|
|
4752
|
-
editor: action.editor,
|
|
4753
|
-
placement: action.placement,
|
|
4754
|
-
select: "start"
|
|
4755
|
-
}
|
|
4756
|
-
});
|
|
4757
4714
|
}, moveBlockActionImplementation = ({
|
|
4758
4715
|
action
|
|
4759
4716
|
}) => {
|
|
@@ -4859,13 +4816,11 @@ const selectActionImplementation = ({
|
|
|
4859
4816
|
"history.undo": historyUndoActionImplementation,
|
|
4860
4817
|
"insert.block": insertBlockActionImplementation,
|
|
4861
4818
|
"insert.blocks": insertBlocksActionImplementation,
|
|
4862
|
-
"insert.block object": insertBlockObjectActionImplementation,
|
|
4863
4819
|
"insert.break": insertBreakActionImplementation,
|
|
4864
4820
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4865
4821
|
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4866
4822
|
"insert.span": insertSpanActionImplementation,
|
|
4867
4823
|
"insert.text": insertTextActionImplementation,
|
|
4868
|
-
"insert.text block": insertTextBlockActionImplementation,
|
|
4869
4824
|
effect: effectActionImplementation,
|
|
4870
4825
|
"list item.add": addListItemActionImplementation,
|
|
4871
4826
|
"list item.remove": removeListItemActionImplementation,
|
|
@@ -5049,13 +5004,6 @@ function performAction({
|
|
|
5049
5004
|
});
|
|
5050
5005
|
break;
|
|
5051
5006
|
}
|
|
5052
|
-
case "insert.block object": {
|
|
5053
|
-
behaviorActionImplementations["insert.block object"]({
|
|
5054
|
-
context,
|
|
5055
|
-
action
|
|
5056
|
-
});
|
|
5057
|
-
break;
|
|
5058
|
-
}
|
|
5059
5007
|
case "insert.inline object": {
|
|
5060
5008
|
behaviorActionImplementations["insert.inline object"]({
|
|
5061
5009
|
context,
|
|
@@ -5091,13 +5039,6 @@ function performAction({
|
|
|
5091
5039
|
});
|
|
5092
5040
|
break;
|
|
5093
5041
|
}
|
|
5094
|
-
case "insert.text block": {
|
|
5095
|
-
behaviorActionImplementations["insert.text block"]({
|
|
5096
|
-
context,
|
|
5097
|
-
action
|
|
5098
|
-
});
|
|
5099
|
-
break;
|
|
5100
|
-
}
|
|
5101
5042
|
case "list item.add": {
|
|
5102
5043
|
behaviorActionImplementations["list item.add"]({
|
|
5103
5044
|
context,
|
|
@@ -5232,6 +5173,20 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
5232
5173
|
editor
|
|
5233
5174
|
});
|
|
5234
5175
|
break;
|
|
5176
|
+
case "insert.block object":
|
|
5177
|
+
editorActor.send({
|
|
5178
|
+
type: "behavior event",
|
|
5179
|
+
behaviorEvent: {
|
|
5180
|
+
type: "insert.block",
|
|
5181
|
+
block: {
|
|
5182
|
+
_type: event.blockObject.name,
|
|
5183
|
+
...event.blockObject.value ?? {}
|
|
5184
|
+
},
|
|
5185
|
+
placement: event.placement
|
|
5186
|
+
},
|
|
5187
|
+
editor
|
|
5188
|
+
});
|
|
5189
|
+
break;
|
|
5235
5190
|
default:
|
|
5236
5191
|
editorActor.send({
|
|
5237
5192
|
type: "behavior event",
|
|
@@ -6380,7 +6335,7 @@ const keyIs = {
|
|
|
6380
6335
|
originEvent
|
|
6381
6336
|
}) => [...draggingEntireBlocks ? draggedBlocks.map((block) => raise({
|
|
6382
6337
|
type: "delete.block",
|
|
6383
|
-
|
|
6338
|
+
at: block.path
|
|
6384
6339
|
})) : [raise({
|
|
6385
6340
|
type: "delete",
|
|
6386
6341
|
selection: dragOrigin.selection
|
|
@@ -6552,7 +6507,12 @@ const editorMachine = setup({
|
|
|
6552
6507
|
const defaultAction = event.type === "custom behavior event" || isClipboardBehaviorEvent(event.behaviorEvent) || isDragBehaviorEvent(event.behaviorEvent) || isInputBehaviorEvent(event.behaviorEvent) || isKeyboardBehaviorEvent(event.behaviorEvent) || isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
6553
6508
|
...event.behaviorEvent,
|
|
6554
6509
|
editor: event.editor
|
|
6555
|
-
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) =>
|
|
6510
|
+
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => {
|
|
6511
|
+
if (behavior.on === "*")
|
|
6512
|
+
return !0;
|
|
6513
|
+
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.behaviorEvent.type.includes(".") ? event.behaviorEvent.type.split(".") : [void 0];
|
|
6514
|
+
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.behaviorEvent.type ? !0 : behavior.on === event.behaviorEvent.type;
|
|
6515
|
+
});
|
|
6556
6516
|
if (eventBehaviors.length === 0) {
|
|
6557
6517
|
if (defaultActionCallback) {
|
|
6558
6518
|
withApplyingBehaviorActions(event.editor, () => {
|