@portabletext/editor 1.44.14 → 1.44.16
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 +107 -97
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +113 -103
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +814 -600
- package/lib/behaviors/index.d.ts +814 -600
- package/lib/index.d.cts +12 -8
- package/lib/index.d.ts +12 -8
- package/lib/plugins/index.cjs +9 -0
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +12 -8
- package/lib/plugins/index.d.ts +12 -8
- package/lib/plugins/index.js +9 -0
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +12 -8
- package/lib/selectors/index.d.ts +12 -8
- package/lib/utils/index.d.cts +12 -8
- package/lib/utils/index.d.ts +12 -8
- package/package.json +5 -5
- package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
- package/src/behavior-actions/behavior.actions.ts +9 -20
- package/src/behaviors/behavior.abstract.insert.ts +9 -1
- package/src/behaviors/behavior.default.ts +30 -28
- package/src/behaviors/behavior.types.event.ts +12 -8
- package/src/editor/plugins/create-with-event-listeners.ts +3 -3
- package/src/plugins/plugin.one-line.tsx +7 -0
|
@@ -2670,74 +2670,10 @@ function createOperationToPatches(types2) {
|
|
|
2670
2670
|
splitNodePatch
|
|
2671
2671
|
};
|
|
2672
2672
|
}
|
|
2673
|
-
const
|
|
2674
|
-
context,
|
|
2675
|
-
action
|
|
2676
|
-
}) => {
|
|
2677
|
-
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
2678
|
-
if (!editor.selection)
|
|
2679
|
-
return;
|
|
2680
|
-
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
2681
|
-
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
2682
|
-
slate.Transforms.splitNodes(editor, {
|
|
2683
|
-
at: editor.selection,
|
|
2684
|
-
always: !0
|
|
2685
|
-
});
|
|
2686
|
-
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
2687
|
-
depth: 1
|
|
2688
|
-
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
2689
|
-
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
2690
|
-
_key: context.keyGenerator(),
|
|
2691
|
-
_type: "span",
|
|
2692
|
-
text: "",
|
|
2693
|
-
marks: []
|
|
2694
|
-
}, {
|
|
2695
|
-
at: [nextBlockPath[0], 0]
|
|
2696
|
-
}), slate.Transforms.setSelection(editor, {
|
|
2697
|
-
anchor: {
|
|
2698
|
-
path: [...nextBlockPath, 0],
|
|
2699
|
-
offset: 0
|
|
2700
|
-
},
|
|
2701
|
-
focus: {
|
|
2702
|
-
path: [...nextBlockPath, 0],
|
|
2703
|
-
offset: 0
|
|
2704
|
-
}
|
|
2705
|
-
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
2706
|
-
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextBlockPath);
|
|
2707
|
-
for (const [child, childPath] of children) {
|
|
2708
|
-
if (!editor.isTextSpan(child))
|
|
2709
|
-
continue;
|
|
2710
|
-
const marks = child.marks ?? [];
|
|
2711
|
-
for (const mark of marks)
|
|
2712
|
-
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
2713
|
-
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
2714
|
-
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
2715
|
-
marks: newMarks
|
|
2716
|
-
}, {
|
|
2717
|
-
at: childPath
|
|
2718
|
-
});
|
|
2719
|
-
}
|
|
2720
|
-
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
2721
|
-
...markDef,
|
|
2722
|
-
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
2723
|
-
}));
|
|
2724
|
-
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
2725
|
-
markDefs: newMarkDefs
|
|
2726
|
-
}, {
|
|
2727
|
-
at: nextBlockPath,
|
|
2728
|
-
match: (node) => editor.isTextBlock(node)
|
|
2729
|
-
});
|
|
2730
|
-
}
|
|
2731
|
-
return;
|
|
2732
|
-
}
|
|
2733
|
-
slate.Transforms.splitNodes(editor, {
|
|
2734
|
-
always: !0
|
|
2735
|
-
});
|
|
2736
|
-
}, insertSoftBreakActionImplementation = ({
|
|
2673
|
+
const insertTextActionImplementation = ({
|
|
2737
2674
|
action
|
|
2738
2675
|
}) => {
|
|
2739
|
-
|
|
2740
|
-
`);
|
|
2676
|
+
action.editor.insertText(action.text);
|
|
2741
2677
|
};
|
|
2742
2678
|
function isPortableTextSpan(node) {
|
|
2743
2679
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
@@ -4063,11 +3999,7 @@ function insertBlock({
|
|
|
4063
3999
|
}
|
|
4064
4000
|
}
|
|
4065
4001
|
}
|
|
4066
|
-
const
|
|
4067
|
-
action
|
|
4068
|
-
}) => {
|
|
4069
|
-
action.editor.insertText(action.text);
|
|
4070
|
-
}, moveBlockActionImplementation = ({
|
|
4002
|
+
const moveBlockActionImplementation = ({
|
|
4071
4003
|
action
|
|
4072
4004
|
}) => {
|
|
4073
4005
|
const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
|
|
@@ -4082,6 +4014,69 @@ const insertTextActionImplementation = ({
|
|
|
4082
4014
|
}) => {
|
|
4083
4015
|
const newSelection = toSlateRange(action.selection, action.editor);
|
|
4084
4016
|
newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
|
|
4017
|
+
}, splitBlockActionImplementation = ({
|
|
4018
|
+
context,
|
|
4019
|
+
action
|
|
4020
|
+
}) => {
|
|
4021
|
+
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
4022
|
+
if (!editor.selection)
|
|
4023
|
+
return;
|
|
4024
|
+
const anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
4025
|
+
if (editor.isTextBlock(focusBlock) && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
4026
|
+
slate.Transforms.splitNodes(editor, {
|
|
4027
|
+
at: editor.selection,
|
|
4028
|
+
always: !0
|
|
4029
|
+
});
|
|
4030
|
+
const [nextBlock, nextBlockPath] = slate.Editor.node(editor, slate.Path.next(focusBlockPath), {
|
|
4031
|
+
depth: 1
|
|
4032
|
+
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
4033
|
+
if (!editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(editor, {
|
|
4034
|
+
_key: context.keyGenerator(),
|
|
4035
|
+
_type: "span",
|
|
4036
|
+
text: "",
|
|
4037
|
+
marks: []
|
|
4038
|
+
}, {
|
|
4039
|
+
at: [nextBlockPath[0], 0]
|
|
4040
|
+
}), slate.Transforms.setSelection(editor, {
|
|
4041
|
+
anchor: {
|
|
4042
|
+
path: [...nextBlockPath, 0],
|
|
4043
|
+
offset: 0
|
|
4044
|
+
},
|
|
4045
|
+
focus: {
|
|
4046
|
+
path: [...nextBlockPath, 0],
|
|
4047
|
+
offset: 0
|
|
4048
|
+
}
|
|
4049
|
+
}), editor.isTextBlock(nextBlock) && nextBlock.markDefs && nextBlock.markDefs.length > 0) {
|
|
4050
|
+
const newMarkDefKeys = /* @__PURE__ */ new Map(), prevNodeSpans = Array.from(slate.Node.children(editor, focusBlockPath)).map((entry) => entry[0]).filter((node) => editor.isTextSpan(node)), children = slate.Node.children(editor, nextBlockPath);
|
|
4051
|
+
for (const [child, childPath] of children) {
|
|
4052
|
+
if (!editor.isTextSpan(child))
|
|
4053
|
+
continue;
|
|
4054
|
+
const marks = child.marks ?? [];
|
|
4055
|
+
for (const mark of marks)
|
|
4056
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4057
|
+
const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
|
|
4058
|
+
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
4059
|
+
marks: newMarks
|
|
4060
|
+
}, {
|
|
4061
|
+
at: childPath
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
4064
|
+
const newMarkDefs = nextBlock.markDefs.map((markDef) => ({
|
|
4065
|
+
...markDef,
|
|
4066
|
+
_key: newMarkDefKeys.get(markDef._key) ?? markDef._key
|
|
4067
|
+
}));
|
|
4068
|
+
isEqual__default.default(nextBlock.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
4069
|
+
markDefs: newMarkDefs
|
|
4070
|
+
}, {
|
|
4071
|
+
at: nextBlockPath,
|
|
4072
|
+
match: (node) => editor.isTextBlock(node)
|
|
4073
|
+
});
|
|
4074
|
+
}
|
|
4075
|
+
return;
|
|
4076
|
+
}
|
|
4077
|
+
slate.Transforms.splitNodes(editor, {
|
|
4078
|
+
always: !0
|
|
4079
|
+
});
|
|
4085
4080
|
}, debug$a = debugWithName("behaviors:action"), behaviorActionImplementations = {
|
|
4086
4081
|
"annotation.add": addAnnotationActionImplementation,
|
|
4087
4082
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4099,15 +4094,14 @@ const insertTextActionImplementation = ({
|
|
|
4099
4094
|
"history.redo": historyRedoActionImplementation,
|
|
4100
4095
|
"history.undo": historyUndoActionImplementation,
|
|
4101
4096
|
"insert.block": insertBlockActionImplementation,
|
|
4102
|
-
"insert.break": insertBreakActionImplementation,
|
|
4103
4097
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4104
|
-
"insert.soft break": insertSoftBreakActionImplementation,
|
|
4105
4098
|
"insert.span": insertSpanActionImplementation,
|
|
4106
4099
|
"insert.text": insertTextActionImplementation,
|
|
4107
4100
|
effect: effectActionImplementation,
|
|
4108
4101
|
"move.block": moveBlockActionImplementation,
|
|
4109
4102
|
noop: noopActionImplementation,
|
|
4110
|
-
select: selectActionImplementation
|
|
4103
|
+
select: selectActionImplementation,
|
|
4104
|
+
"split.block": splitBlockActionImplementation
|
|
4111
4105
|
};
|
|
4112
4106
|
function performAction({
|
|
4113
4107
|
context,
|
|
@@ -4240,20 +4234,6 @@ function performAction({
|
|
|
4240
4234
|
});
|
|
4241
4235
|
break;
|
|
4242
4236
|
}
|
|
4243
|
-
case "insert.break": {
|
|
4244
|
-
behaviorActionImplementations["insert.break"]({
|
|
4245
|
-
context,
|
|
4246
|
-
action
|
|
4247
|
-
});
|
|
4248
|
-
break;
|
|
4249
|
-
}
|
|
4250
|
-
case "insert.soft break": {
|
|
4251
|
-
behaviorActionImplementations["insert.soft break"]({
|
|
4252
|
-
context,
|
|
4253
|
-
action
|
|
4254
|
-
});
|
|
4255
|
-
break;
|
|
4256
|
-
}
|
|
4257
4237
|
case "insert.span": {
|
|
4258
4238
|
behaviorActionImplementations["insert.span"]({
|
|
4259
4239
|
context,
|
|
@@ -4277,6 +4257,13 @@ function performAction({
|
|
|
4277
4257
|
}
|
|
4278
4258
|
case "noop":
|
|
4279
4259
|
break;
|
|
4260
|
+
case "split.block": {
|
|
4261
|
+
behaviorActionImplementations["split.block"]({
|
|
4262
|
+
context,
|
|
4263
|
+
action
|
|
4264
|
+
});
|
|
4265
|
+
break;
|
|
4266
|
+
}
|
|
4280
4267
|
default: {
|
|
4281
4268
|
behaviorActionImplementations.select({
|
|
4282
4269
|
context,
|
|
@@ -4350,12 +4337,14 @@ function createWithEventListeners(editorActor) {
|
|
|
4350
4337
|
});
|
|
4351
4338
|
}, editor.insertSoftBreak = () => {
|
|
4352
4339
|
if (isApplyingBehaviorActions(editor)) {
|
|
4353
|
-
|
|
4340
|
+
insertTextActionImplementation({
|
|
4354
4341
|
context: {
|
|
4355
4342
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4356
4343
|
schema: editorActor.getSnapshot().context.schema
|
|
4357
4344
|
},
|
|
4358
4345
|
action: {
|
|
4346
|
+
text: `
|
|
4347
|
+
`,
|
|
4359
4348
|
editor
|
|
4360
4349
|
}
|
|
4361
4350
|
});
|
|
@@ -5309,7 +5298,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5309
5298
|
placement: "auto",
|
|
5310
5299
|
select: "end"
|
|
5311
5300
|
})] : event.blocks.flatMap((block, index) => index === 0 ? [behavior_core.raise({
|
|
5312
|
-
type: "
|
|
5301
|
+
type: "split.block"
|
|
5313
5302
|
}), behavior_core.raise({
|
|
5314
5303
|
type: "select.previous block",
|
|
5315
5304
|
select: "end"
|
|
@@ -5345,6 +5334,18 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5345
5334
|
placement: index === 0 ? "auto" : "after",
|
|
5346
5335
|
select: "end"
|
|
5347
5336
|
}))]
|
|
5337
|
+
}), behavior_core.defineBehavior({
|
|
5338
|
+
on: "insert.break",
|
|
5339
|
+
actions: [() => [behavior_core.raise({
|
|
5340
|
+
type: "split.block"
|
|
5341
|
+
})]]
|
|
5342
|
+
}), behavior_core.defineBehavior({
|
|
5343
|
+
on: "insert.soft break",
|
|
5344
|
+
actions: [() => [behavior_core.raise({
|
|
5345
|
+
type: "insert.text",
|
|
5346
|
+
text: `
|
|
5347
|
+
`
|
|
5348
|
+
})]]
|
|
5348
5349
|
})], abstractListItemBehaviors = [behavior_core.defineBehavior({
|
|
5349
5350
|
on: "list item.add",
|
|
5350
5351
|
guard: ({
|
|
@@ -5588,20 +5589,29 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5588
5589
|
snapshot,
|
|
5589
5590
|
event
|
|
5590
5591
|
}) => {
|
|
5591
|
-
|
|
5592
|
+
let success;
|
|
5593
|
+
const failures = [];
|
|
5594
|
+
for (const converter of snapshot.context.converters) {
|
|
5592
5595
|
const data = event.originEvent.originEvent.dataTransfer.getData(converter.mimeType);
|
|
5593
|
-
|
|
5596
|
+
if (!data)
|
|
5597
|
+
continue;
|
|
5598
|
+
const deserializeEvent = converter.deserialize({
|
|
5594
5599
|
snapshot,
|
|
5595
5600
|
event: {
|
|
5596
5601
|
type: "deserialize",
|
|
5597
5602
|
data
|
|
5598
5603
|
}
|
|
5599
|
-
})
|
|
5600
|
-
|
|
5601
|
-
|
|
5604
|
+
});
|
|
5605
|
+
if (deserializeEvent.type === "deserialization.success") {
|
|
5606
|
+
success = deserializeEvent;
|
|
5607
|
+
break;
|
|
5608
|
+
} else
|
|
5609
|
+
failures.push(deserializeEvent);
|
|
5610
|
+
}
|
|
5611
|
+
return success || {
|
|
5602
5612
|
type: "deserialization.failure",
|
|
5603
5613
|
mimeType: "*/*",
|
|
5604
|
-
reason:
|
|
5614
|
+
reason: failures.map((failure) => failure.reason).join(", ")
|
|
5605
5615
|
};
|
|
5606
5616
|
},
|
|
5607
5617
|
actions: [({
|
|
@@ -5920,7 +5930,7 @@ const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
|
5920
5930
|
raiseDeserializationSuccessOrFailure,
|
|
5921
5931
|
raiseSerializationSuccessOrFailure,
|
|
5922
5932
|
raiseInsertSoftBreak
|
|
5923
|
-
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
|
|
5933
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
|
|
5924
5934
|
function isAbstractBehaviorEvent(event) {
|
|
5925
5935
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
5926
5936
|
}
|