@portabletext/editor 1.33.4 → 1.33.6
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 +14 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +20 -12
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +82 -68
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +103 -46
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +14 -8
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +20 -12
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +87 -72
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js +102 -46
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/behaviors/index.d.cts +1 -33
- package/lib/behaviors/index.d.ts +1 -33
- package/lib/index.d.cts +162 -1496
- package/lib/index.d.ts +162 -1496
- package/lib/plugins/index.d.cts +162 -1496
- package/lib/plugins/index.d.ts +162 -1496
- package/package.json +9 -9
- package/src/behavior-actions/behavior.action.block.set.ts +48 -5
- package/src/behavior-actions/behavior.action.block.unset.ts +77 -3
- package/src/behavior-actions/behavior.actions.ts +1 -18
- package/src/behaviors/behavior.core.lists.ts +18 -14
- package/src/behaviors/behavior.markdown.ts +14 -12
- package/src/behaviors/behavior.types.ts +1 -13
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -2
- package/src/internal-utils/parse-blocks.test.ts +455 -0
- package/src/internal-utils/parse-blocks.ts +202 -87
- package/src/behavior-actions/behavior.action.text-block.set.ts +0 -25
- package/src/behavior-actions/behavior.action.text-block.unset.ts +0 -17
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_blockOffsetsToSelection = require("./util.block-offsets-to-selection.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs");
|
|
2
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), jsxRuntime = require("react/jsx-runtime"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_blockOffsetsToSelection = require("./util.block-offsets-to-selection.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), omit = require("lodash/omit.js"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
6
|
-
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$e), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
|
|
6
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$e), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase);
|
|
7
7
|
function createEditorSchema(portableTextType) {
|
|
8
8
|
if (!portableTextType)
|
|
9
9
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -3982,6 +3982,7 @@ function insertBlock({
|
|
|
3982
3982
|
}
|
|
3983
3983
|
}
|
|
3984
3984
|
const blockSetBehaviorActionImplementation = ({
|
|
3985
|
+
context,
|
|
3985
3986
|
action
|
|
3986
3987
|
}) => {
|
|
3987
3988
|
const location = toSlateRange({
|
|
@@ -3995,17 +3996,40 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3995
3996
|
}
|
|
3996
3997
|
}, action.editor);
|
|
3997
3998
|
if (!location)
|
|
3998
|
-
|
|
3999
|
+
throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
|
|
4000
|
+
const block = slate.Editor.node(action.editor, location, {
|
|
4001
|
+
depth: 1
|
|
4002
|
+
})?.[0];
|
|
4003
|
+
if (!block)
|
|
4004
|
+
throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
|
|
4005
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4006
|
+
if (!parsedBlock)
|
|
4007
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
3999
4008
|
const {
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4009
|
+
_type,
|
|
4010
|
+
...filteredProps
|
|
4011
|
+
} = action.props, updatedBlock = util_blockOffsetsToSelection.parseBlock({
|
|
4012
|
+
context,
|
|
4013
|
+
block: {
|
|
4014
|
+
...parsedBlock,
|
|
4015
|
+
...filteredProps
|
|
4016
|
+
},
|
|
4017
|
+
options: {
|
|
4018
|
+
refreshKeys: !1
|
|
4019
|
+
}
|
|
4020
|
+
});
|
|
4021
|
+
if (!updatedBlock)
|
|
4022
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4023
|
+
const slateBlock = toSlateValue([updatedBlock], {
|
|
4024
|
+
schemaTypes: context.schema
|
|
4025
|
+
})?.at(0);
|
|
4026
|
+
if (!slateBlock)
|
|
4027
|
+
throw new Error("Unable to convert block to Slate value");
|
|
4028
|
+
slate.Transforms.setNodes(action.editor, slateBlock, {
|
|
4006
4029
|
at: location
|
|
4007
4030
|
});
|
|
4008
4031
|
}, blockUnsetBehaviorActionImplementation = ({
|
|
4032
|
+
context,
|
|
4009
4033
|
action
|
|
4010
4034
|
}) => {
|
|
4011
4035
|
const location = toSlateRange({
|
|
@@ -4018,7 +4042,53 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4018
4042
|
offset: 0
|
|
4019
4043
|
}
|
|
4020
4044
|
}, action.editor);
|
|
4021
|
-
|
|
4045
|
+
if (!location)
|
|
4046
|
+
throw new Error(`Unable to convert ${JSON.stringify(action.at)} into a Slate Range`);
|
|
4047
|
+
const block = slate.Editor.node(action.editor, location, {
|
|
4048
|
+
depth: 1
|
|
4049
|
+
})?.[0];
|
|
4050
|
+
if (!block)
|
|
4051
|
+
throw new Error(`Unable to find block at ${JSON.stringify(action.at)}`);
|
|
4052
|
+
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
4053
|
+
if (!parsedBlock)
|
|
4054
|
+
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
4055
|
+
if (util_blockOffsetsToSelection.isTextBlock(context.schema, parsedBlock)) {
|
|
4056
|
+
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_blockOffsetsToSelection.parseBlock({
|
|
4057
|
+
context,
|
|
4058
|
+
block: omit__default.default(parsedBlock, propsToRemove),
|
|
4059
|
+
options: {
|
|
4060
|
+
refreshKeys: !1
|
|
4061
|
+
}
|
|
4062
|
+
});
|
|
4063
|
+
if (!updatedTextBlock)
|
|
4064
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4065
|
+
const propsToSet = {};
|
|
4066
|
+
for (const prop of propsToRemove)
|
|
4067
|
+
prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
|
|
4068
|
+
slate.Transforms.setNodes(action.editor, propsToSet, {
|
|
4069
|
+
at: location
|
|
4070
|
+
});
|
|
4071
|
+
return;
|
|
4072
|
+
}
|
|
4073
|
+
const updatedBlockObject = util_blockOffsetsToSelection.parseBlock({
|
|
4074
|
+
context,
|
|
4075
|
+
block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
4076
|
+
options: {
|
|
4077
|
+
refreshKeys: !1
|
|
4078
|
+
}
|
|
4079
|
+
});
|
|
4080
|
+
if (!updatedBlockObject)
|
|
4081
|
+
throw new Error(`Unable to update block at ${JSON.stringify(action.at)}`);
|
|
4082
|
+
const {
|
|
4083
|
+
_type,
|
|
4084
|
+
_key,
|
|
4085
|
+
...props
|
|
4086
|
+
} = updatedBlockObject;
|
|
4087
|
+
slate.Transforms.setNodes(action.editor, {
|
|
4088
|
+
_type,
|
|
4089
|
+
_key,
|
|
4090
|
+
value: props
|
|
4091
|
+
}, {
|
|
4022
4092
|
at: location
|
|
4023
4093
|
});
|
|
4024
4094
|
}, dataTransferSetActionImplementation = ({
|
|
@@ -4198,48 +4268,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4198
4268
|
editor: action.editor,
|
|
4199
4269
|
schema: context.schema
|
|
4200
4270
|
});
|
|
4201
|
-
}, textBlockSetActionImplementation = ({
|
|
4202
|
-
action
|
|
4203
|
-
}) => {
|
|
4204
|
-
const at = toSlateRange({
|
|
4205
|
-
anchor: {
|
|
4206
|
-
path: action.at,
|
|
4207
|
-
offset: 0
|
|
4208
|
-
},
|
|
4209
|
-
focus: {
|
|
4210
|
-
path: action.at,
|
|
4211
|
-
offset: 0
|
|
4212
|
-
}
|
|
4213
|
-
}, action.editor);
|
|
4214
|
-
slate.Transforms.setNodes(action.editor, {
|
|
4215
|
-
...action.style ? {
|
|
4216
|
-
style: action.style
|
|
4217
|
-
} : {},
|
|
4218
|
-
...action.listItem ? {
|
|
4219
|
-
listItem: action.listItem
|
|
4220
|
-
} : {},
|
|
4221
|
-
...action.level ? {
|
|
4222
|
-
level: action.level
|
|
4223
|
-
} : {}
|
|
4224
|
-
}, {
|
|
4225
|
-
at
|
|
4226
|
-
});
|
|
4227
|
-
}, textBlockUnsetActionImplementation = ({
|
|
4228
|
-
action
|
|
4229
|
-
}) => {
|
|
4230
|
-
const at = toSlateRange({
|
|
4231
|
-
anchor: {
|
|
4232
|
-
path: action.at,
|
|
4233
|
-
offset: 0
|
|
4234
|
-
},
|
|
4235
|
-
focus: {
|
|
4236
|
-
path: action.at,
|
|
4237
|
-
offset: 0
|
|
4238
|
-
}
|
|
4239
|
-
}, action.editor);
|
|
4240
|
-
slate.Transforms.unsetNodes(action.editor, action.props, {
|
|
4241
|
-
at
|
|
4242
|
-
});
|
|
4243
4271
|
}, behaviorActionImplementations = {
|
|
4244
4272
|
"annotation.add": addAnnotationActionImplementation,
|
|
4245
4273
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -4445,9 +4473,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4445
4473
|
},
|
|
4446
4474
|
"style.toggle": toggleStyleActionImplementation,
|
|
4447
4475
|
"style.add": addStyleActionImplementation,
|
|
4448
|
-
"style.remove": removeStyleActionImplementation
|
|
4449
|
-
"text block.set": textBlockSetActionImplementation,
|
|
4450
|
-
"text block.unset": textBlockUnsetActionImplementation
|
|
4476
|
+
"style.remove": removeStyleActionImplementation
|
|
4451
4477
|
};
|
|
4452
4478
|
function performAction({
|
|
4453
4479
|
context,
|
|
@@ -4769,25 +4795,13 @@ function performDefaultAction({
|
|
|
4769
4795
|
});
|
|
4770
4796
|
break;
|
|
4771
4797
|
}
|
|
4772
|
-
|
|
4798
|
+
default: {
|
|
4773
4799
|
behaviorActionImplementations["style.toggle"]({
|
|
4774
4800
|
context,
|
|
4775
4801
|
action
|
|
4776
4802
|
});
|
|
4777
4803
|
break;
|
|
4778
4804
|
}
|
|
4779
|
-
case "text block.set": {
|
|
4780
|
-
behaviorActionImplementations["text block.set"]({
|
|
4781
|
-
context,
|
|
4782
|
-
action
|
|
4783
|
-
});
|
|
4784
|
-
break;
|
|
4785
|
-
}
|
|
4786
|
-
default:
|
|
4787
|
-
behaviorActionImplementations["text block.unset"]({
|
|
4788
|
-
context,
|
|
4789
|
-
action
|
|
4790
|
-
});
|
|
4791
4805
|
}
|
|
4792
4806
|
}
|
|
4793
4807
|
function createWithEventListeners(editorActor, subscriptions) {
|