@portabletext/editor 1.15.2 → 1.15.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 +5 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selectors.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +5 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selectors.js.map +1 -1
- package/lib/behaviors/index.cjs +12 -12
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +39 -45
- package/lib/behaviors/index.d.ts +39 -45
- package/lib/behaviors/index.js +12 -12
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +13 -27
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +129 -133
- package/lib/index.d.ts +129 -133
- package/lib/index.js +13 -27
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.d.cts +8 -12
- package/lib/selectors/index.d.ts +8 -12
- package/package.json +2 -2
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -5
- package/src/behavior-actions/behavior.actions.ts +6 -6
- package/src/behavior-actions/behavior.guards.ts +2 -6
- package/src/behaviors/behavior.core.block-objects.ts +1 -1
- package/src/behaviors/behavior.core.lists.ts +2 -2
- package/src/behaviors/behavior.links.ts +2 -2
- package/src/behaviors/behavior.markdown.ts +11 -19
- package/src/behaviors/behavior.types.ts +7 -7
- package/src/behaviors/index.ts +1 -0
- package/src/editor/PortableTextEditor.tsx +2 -2
- package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/define-schema.ts +8 -3
- package/src/editor/editor-machine.ts +7 -24
- package/src/editor/editor-selector.ts +1 -13
- package/src/editor/editor-snapshot.ts +4 -6
- package/src/index.ts +3 -5
- package/src/selectors/index.ts +2 -4
- package/src/utils/__tests__/operationToPatches.test.ts +2 -2
- package/src/utils/__tests__/patchToOperations.test.ts +2 -2
- package/src/utils/__tests__/values.test.ts +2 -2
package/lib/index.js
CHANGED
|
@@ -38,7 +38,7 @@ import { createGuards } from "./_chunks-es/selectors.js";
|
|
|
38
38
|
import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
39
39
|
import getRandomValues from "get-random-values-esm";
|
|
40
40
|
import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
|
|
41
|
-
function
|
|
41
|
+
function createEditorSchema(portableTextType) {
|
|
42
42
|
var _a, _b, _c;
|
|
43
43
|
if (!portableTextType)
|
|
44
44
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -166,7 +166,7 @@ function compileSchemaDefinition(definition) {
|
|
|
166
166
|
}]
|
|
167
167
|
}), schema = Schema.compile({
|
|
168
168
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
169
|
-
}).get("portable-text"), pteSchema =
|
|
169
|
+
}).get("portable-text"), pteSchema = createEditorSchema(schema);
|
|
170
170
|
return __spreadProps$j(__spreadValues$p({}, pteSchema), {
|
|
171
171
|
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
|
|
172
172
|
name: "image",
|
|
@@ -5337,7 +5337,7 @@ const behaviorActionImplementations = {
|
|
|
5337
5337
|
const newSelection = toSlateRange(action.selection, action.editor);
|
|
5338
5338
|
newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
|
|
5339
5339
|
},
|
|
5340
|
-
"select
|
|
5340
|
+
"select.previous block": ({
|
|
5341
5341
|
action
|
|
5342
5342
|
}) => {
|
|
5343
5343
|
if (!action.editor.selection) {
|
|
@@ -5352,7 +5352,7 @@ const behaviorActionImplementations = {
|
|
|
5352
5352
|
const previousBlockPath = Path.previous(blockPath);
|
|
5353
5353
|
Transforms.select(action.editor, previousBlockPath);
|
|
5354
5354
|
},
|
|
5355
|
-
"select
|
|
5355
|
+
"select.next block": ({
|
|
5356
5356
|
action
|
|
5357
5357
|
}) => {
|
|
5358
5358
|
if (!action.editor.selection) {
|
|
@@ -5458,15 +5458,15 @@ function performAction({
|
|
|
5458
5458
|
});
|
|
5459
5459
|
break;
|
|
5460
5460
|
}
|
|
5461
|
-
case "select
|
|
5462
|
-
behaviorActionImplementations["select
|
|
5461
|
+
case "select.previous block": {
|
|
5462
|
+
behaviorActionImplementations["select.previous block"]({
|
|
5463
5463
|
context,
|
|
5464
5464
|
action
|
|
5465
5465
|
});
|
|
5466
5466
|
break;
|
|
5467
5467
|
}
|
|
5468
|
-
case "select
|
|
5469
|
-
behaviorActionImplementations["select
|
|
5468
|
+
case "select.next block": {
|
|
5469
|
+
behaviorActionImplementations["select.next block"]({
|
|
5470
5470
|
context,
|
|
5471
5471
|
action
|
|
5472
5472
|
});
|
|
@@ -5706,18 +5706,7 @@ const editorMachine = setup({
|
|
|
5706
5706
|
});
|
|
5707
5707
|
return;
|
|
5708
5708
|
}
|
|
5709
|
-
const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema)
|
|
5710
|
-
if (!selection) {
|
|
5711
|
-
if (console.warn(`Unable to handle event ${event.type} due to missing selection`), !defaultAction)
|
|
5712
|
-
return;
|
|
5713
|
-
enqueue.raise({
|
|
5714
|
-
type: "behavior action intends",
|
|
5715
|
-
editor: event.editor,
|
|
5716
|
-
actionIntends: [defaultAction]
|
|
5717
|
-
});
|
|
5718
|
-
return;
|
|
5719
|
-
}
|
|
5720
|
-
const editorContext = {
|
|
5709
|
+
const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema), editorContext = {
|
|
5721
5710
|
keyGenerator: context.keyGenerator,
|
|
5722
5711
|
schema: context.schema,
|
|
5723
5712
|
selection,
|
|
@@ -5768,7 +5757,7 @@ const editorMachine = setup({
|
|
|
5768
5757
|
keyGenerator: input.keyGenerator,
|
|
5769
5758
|
pendingEvents: [],
|
|
5770
5759
|
schema: input.schema,
|
|
5771
|
-
selection:
|
|
5760
|
+
selection: null,
|
|
5772
5761
|
readOnly: (_b = input.readOnly) != null ? _b : !1,
|
|
5773
5762
|
maxBlocks: input.maxBlocks,
|
|
5774
5763
|
value: input.value
|
|
@@ -5876,10 +5865,7 @@ const editorMachine = setup({
|
|
|
5876
5865
|
actions: [assign({
|
|
5877
5866
|
selection: ({
|
|
5878
5867
|
event
|
|
5879
|
-
}) =>
|
|
5880
|
-
var _a;
|
|
5881
|
-
return (_a = event.selection) != null ? _a : void 0;
|
|
5882
|
-
}
|
|
5868
|
+
}) => event.selection
|
|
5883
5869
|
}), emit(({
|
|
5884
5870
|
event
|
|
5885
5871
|
}) => event)]
|
|
@@ -6066,7 +6052,7 @@ function editorConfigToMachineInput(config) {
|
|
|
6066
6052
|
keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6067
6053
|
maxBlocks: config.maxBlocks,
|
|
6068
6054
|
readOnly: config.readOnly,
|
|
6069
|
-
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) :
|
|
6055
|
+
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6070
6056
|
value: config.initialValue
|
|
6071
6057
|
};
|
|
6072
6058
|
}
|
|
@@ -6145,7 +6131,7 @@ class PortableTextEditor extends Component {
|
|
|
6145
6131
|
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
|
|
6146
6132
|
}
|
|
6147
6133
|
componentDidUpdate(prevProps) {
|
|
6148
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes =
|
|
6134
|
+
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
6149
6135
|
type: "update schema",
|
|
6150
6136
|
schema: this.schemaTypes
|
|
6151
6137
|
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|