@portabletext/editor 1.21.6 → 1.23.0
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.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +4 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.get-block-start-point.cjs → util.reverse-selection.cjs} +12 -12
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +75 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/{util.get-block-start-point.js → util.reverse-selection.js} +12 -12
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +76 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -0
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +57 -0
- package/lib/behaviors/index.d.ts +57 -0
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +33 -12
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +418 -0
- package/lib/index.d.ts +418 -0
- package/lib/index.js +33 -12
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +10 -4
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +5 -0
- package/lib/selectors/index.d.ts +5 -0
- package/lib/selectors/index.js +9 -2
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +4 -3
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +11 -0
- package/lib/utils/index.d.ts +11 -0
- package/lib/utils/index.js +3 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +16 -12
- package/src/behaviors/behavior.markdown.ts +42 -0
- package/src/behaviors/behavior.types.ts +15 -0
- package/src/editor/Editable.tsx +17 -0
- package/src/editor/create-editor.ts +1 -0
- package/src/editor/define-schema.ts +24 -1
- package/src/editor/editor-event-listener.tsx +45 -0
- package/src/editor/editor-machine.ts +13 -26
- package/src/editor/editor-provider.tsx +27 -0
- package/src/editor/editor-selector.ts +21 -0
- package/src/editor/editor-snapshot.ts +37 -1
- package/src/selectors/index.ts +1 -0
- package/src/selectors/selector.get-selected-slice.ts +12 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/util.slice-blocks.test.ts +257 -0
- package/src/utils/util.slice-blocks.ts +153 -0
- package/lib/_chunks-cjs/util.get-block-start-point.cjs.map +0 -1
- package/lib/_chunks-es/util.get-block-start-point.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -86,7 +86,7 @@ function compileSchemaDefinition(definition) {
|
|
|
86
86
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
87
87
|
// fields to objects with the name `image`
|
|
88
88
|
name: blockObject.name === "image" ? "tmp-image" : blockObject.name,
|
|
89
|
-
title: blockObject.title,
|
|
89
|
+
title: blockObject.name === "image" && blockObject.title === void 0 ? "Image" : blockObject.title,
|
|
90
90
|
fields: []
|
|
91
91
|
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
92
92
|
type: "object",
|
|
@@ -5580,6 +5580,25 @@ function getActiveDecorators({
|
|
|
5580
5580
|
...Editor.marks(slateEditorInstance) ?? {}
|
|
5581
5581
|
}.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
5582
5582
|
}
|
|
5583
|
+
function createEditorSnapshot({
|
|
5584
|
+
editor,
|
|
5585
|
+
keyGenerator,
|
|
5586
|
+
schema
|
|
5587
|
+
}) {
|
|
5588
|
+
const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
|
|
5589
|
+
return {
|
|
5590
|
+
context: {
|
|
5591
|
+
activeDecorators: getActiveDecorators({
|
|
5592
|
+
schema,
|
|
5593
|
+
slateEditorInstance: editor
|
|
5594
|
+
}),
|
|
5595
|
+
keyGenerator,
|
|
5596
|
+
schema,
|
|
5597
|
+
selection,
|
|
5598
|
+
value
|
|
5599
|
+
}
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5583
5602
|
const editorMachine = setup({
|
|
5584
5603
|
types: {
|
|
5585
5604
|
context: {},
|
|
@@ -5680,26 +5699,21 @@ const editorMachine = setup({
|
|
|
5680
5699
|
}), event.editor.onChange();
|
|
5681
5700
|
return;
|
|
5682
5701
|
}
|
|
5683
|
-
const
|
|
5684
|
-
|
|
5685
|
-
schema: context.schema,
|
|
5686
|
-
slateEditorInstance: event.editor
|
|
5687
|
-
}),
|
|
5702
|
+
const editorSnapshot = createEditorSnapshot({
|
|
5703
|
+
editor: event.editor,
|
|
5688
5704
|
keyGenerator: context.keyGenerator,
|
|
5689
|
-
schema: context.schema
|
|
5690
|
-
|
|
5691
|
-
value
|
|
5692
|
-
};
|
|
5705
|
+
schema: context.schema
|
|
5706
|
+
});
|
|
5693
5707
|
let behaviorOverwritten = !1;
|
|
5694
5708
|
for (const eventBehavior of eventBehaviors) {
|
|
5695
5709
|
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
5696
|
-
context:
|
|
5710
|
+
context: editorSnapshot.context,
|
|
5697
5711
|
event: event.behaviorEvent
|
|
5698
5712
|
});
|
|
5699
5713
|
if (!shouldRun)
|
|
5700
5714
|
continue;
|
|
5701
5715
|
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
5702
|
-
context:
|
|
5716
|
+
context: editorSnapshot.context,
|
|
5703
5717
|
event: event.behaviorEvent
|
|
5704
5718
|
}, shouldRun));
|
|
5705
5719
|
for (const actionIntends of actionIntendSets)
|
|
@@ -5847,6 +5861,13 @@ const editorMachine = setup({
|
|
|
5847
5861
|
"update behaviors": {
|
|
5848
5862
|
actions: "assign behaviors"
|
|
5849
5863
|
},
|
|
5864
|
+
"update key generator": {
|
|
5865
|
+
actions: assign({
|
|
5866
|
+
keyGenerator: ({
|
|
5867
|
+
event
|
|
5868
|
+
}) => event.keyGenerator
|
|
5869
|
+
})
|
|
5870
|
+
},
|
|
5850
5871
|
"update schema": {
|
|
5851
5872
|
actions: "assign schema"
|
|
5852
5873
|
},
|