@portabletext/editor 1.48.7 → 1.48.9
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 +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +99 -68
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +41 -45
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +75 -45
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +43 -47
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +5 -5
- package/lib/behaviors/index.d.ts +5 -5
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +3 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -6
- package/lib/selectors/index.d.ts +2 -6
- package/lib/selectors/index.js +5 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +37 -31
- package/lib/utils/index.d.ts +37 -31
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +2 -2
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$f = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"),
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), React = require("react"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), debug$f = require("debug"), isEqual = require("lodash/isEqual.js"), slate = require("slate"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), util_sliceBlocks = require("./util.slice-blocks.cjs"), getRandomValues = require("get-random-values-esm"), 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"), types = require("@sanity/types"), omit = require("lodash/omit.js"), util_selectionPointToBlockOffset = require("./util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), util_getSelectionStartPoint = require("./util.get-selection-start-point.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -279,9 +279,9 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
});
|
|
282
|
-
function validateValue(value,
|
|
282
|
+
function validateValue(value, types2, keyGenerator) {
|
|
283
283
|
let resolution = null, valid = !0;
|
|
284
|
-
const validChildTypes = [
|
|
284
|
+
const validChildTypes = [types2.span.name, ...types2.inlineObjects.map((t) => t.name)], validBlockTypes = [types2.block.name, ...types2.blockObjects.map((t) => t.name)];
|
|
285
285
|
return value === void 0 ? {
|
|
286
286
|
valid: !0,
|
|
287
287
|
resolution: null,
|
|
@@ -333,7 +333,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
333
333
|
}, !0;
|
|
334
334
|
if (!blk._type || !validBlockTypes.includes(blk._type)) {
|
|
335
335
|
if (blk._type === "block") {
|
|
336
|
-
const currentBlockTypeName =
|
|
336
|
+
const currentBlockTypeName = types2.block.name;
|
|
337
337
|
return resolution = {
|
|
338
338
|
patches: [patches.set({
|
|
339
339
|
...blk,
|
|
@@ -354,25 +354,27 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
354
354
|
}
|
|
355
355
|
}, !0;
|
|
356
356
|
}
|
|
357
|
-
return !blk._type &&
|
|
357
|
+
return !blk._type && util_sliceBlocks.isTextBlock({
|
|
358
|
+
schema: types2
|
|
359
|
+
}, {
|
|
358
360
|
...blk,
|
|
359
|
-
_type:
|
|
361
|
+
_type: types2.block.name
|
|
360
362
|
}) ? (resolution = {
|
|
361
363
|
patches: [patches.set({
|
|
362
364
|
...blk,
|
|
363
|
-
_type:
|
|
365
|
+
_type: types2.block.name
|
|
364
366
|
}, [{
|
|
365
367
|
_key: blk._key
|
|
366
368
|
}])],
|
|
367
|
-
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${
|
|
368
|
-
action: `Use type '${
|
|
369
|
+
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types2.block.name}'`,
|
|
370
|
+
action: `Use type '${types2.block.name}'`,
|
|
369
371
|
item: blk,
|
|
370
372
|
i18n: {
|
|
371
373
|
description: "inputs.portable-text.invalid-value.missing-block-type.description",
|
|
372
374
|
action: "inputs.portable-text.invalid-value.missing-block-type.action",
|
|
373
375
|
values: {
|
|
374
376
|
key: blk._key,
|
|
375
|
-
expectedTypeName:
|
|
377
|
+
expectedTypeName: types2.block.name
|
|
376
378
|
}
|
|
377
379
|
}
|
|
378
380
|
}, !0) : blk._type ? (resolution = {
|
|
@@ -406,7 +408,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
406
408
|
}
|
|
407
409
|
}, !0);
|
|
408
410
|
}
|
|
409
|
-
if (blk._type ===
|
|
411
|
+
if (blk._type === types2.block.name) {
|
|
410
412
|
const textBlock = blk;
|
|
411
413
|
if (textBlock.children && !Array.isArray(textBlock.children))
|
|
412
414
|
return resolution = {
|
|
@@ -428,7 +430,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
428
430
|
}, !0;
|
|
429
431
|
if (textBlock.children === void 0 || Array.isArray(textBlock.children) && textBlock.children.length === 0) {
|
|
430
432
|
const newSpan = {
|
|
431
|
-
_type:
|
|
433
|
+
_type: types2.span.name,
|
|
432
434
|
_key: keyGenerator(),
|
|
433
435
|
text: "",
|
|
434
436
|
marks: []
|
|
@@ -452,7 +454,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
452
454
|
}
|
|
453
455
|
}, !0;
|
|
454
456
|
}
|
|
455
|
-
const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((cld) => cld._type ===
|
|
457
|
+
const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((cld) => cld._type === types2.span.name).map((cld) => cld.marks || [])));
|
|
456
458
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
457
459
|
const unusedMarkDefs = uniq__default.default(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)));
|
|
458
460
|
if (unusedMarkDefs.length > 0)
|
|
@@ -476,9 +478,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
476
478
|
}
|
|
477
479
|
}, !0;
|
|
478
480
|
}
|
|
479
|
-
const orphanedMarks = allUsedMarks.filter((mark) => !
|
|
481
|
+
const orphanedMarks = allUsedMarks.filter((mark) => !types2.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
|
|
480
482
|
if (orphanedMarks.length > 0) {
|
|
481
|
-
const spanChildren = textBlock.children.filter((cld) => cld._type ===
|
|
483
|
+
const spanChildren = textBlock.children.filter((cld) => cld._type === types2.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
|
|
482
484
|
if (spanChildren) {
|
|
483
485
|
const orphaned = orphanedMarks.join(", ");
|
|
484
486
|
return resolution = {
|
|
@@ -543,7 +545,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
543
545
|
}
|
|
544
546
|
}, !0;
|
|
545
547
|
}
|
|
546
|
-
return child._type ? validChildTypes.includes(child._type) ? child._type ===
|
|
548
|
+
return child._type ? validChildTypes.includes(child._type) ? child._type === types2.span.name && typeof child.text != "string" ? (resolution = {
|
|
547
549
|
patches: [patches.set({
|
|
548
550
|
...child,
|
|
549
551
|
text: ""
|
|
@@ -2202,8 +2204,7 @@ const converterJson = {
|
|
|
2202
2204
|
snapshot,
|
|
2203
2205
|
event
|
|
2204
2206
|
}) => {
|
|
2205
|
-
|
|
2206
|
-
if (!selection)
|
|
2207
|
+
if (!(snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection))
|
|
2207
2208
|
return {
|
|
2208
2209
|
type: "serialization.failure",
|
|
2209
2210
|
mimeType: "application/x-portable-text",
|
|
@@ -2211,8 +2212,8 @@ const converterJson = {
|
|
|
2211
2212
|
reason: "No selection"
|
|
2212
2213
|
};
|
|
2213
2214
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2214
|
-
|
|
2215
|
-
|
|
2215
|
+
context: snapshot.context,
|
|
2216
|
+
blocks: snapshot.context.value
|
|
2216
2217
|
});
|
|
2217
2218
|
return blocks.length === 0 ? {
|
|
2218
2219
|
type: "serialization.failure",
|
|
@@ -2238,7 +2239,7 @@ const converterJson = {
|
|
|
2238
2239
|
reason: "Data is not an array"
|
|
2239
2240
|
};
|
|
2240
2241
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2241
|
-
const parsedBlock =
|
|
2242
|
+
const parsedBlock = util_sliceBlocks.parseBlock({
|
|
2242
2243
|
context: snapshot.context,
|
|
2243
2244
|
block,
|
|
2244
2245
|
options: {
|
|
@@ -2269,8 +2270,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2269
2270
|
snapshot,
|
|
2270
2271
|
event
|
|
2271
2272
|
}) => {
|
|
2272
|
-
|
|
2273
|
-
if (!selection)
|
|
2273
|
+
if (!(snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection))
|
|
2274
2274
|
return {
|
|
2275
2275
|
type: "serialization.failure",
|
|
2276
2276
|
mimeType: "text/html",
|
|
@@ -2278,8 +2278,8 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2278
2278
|
reason: "No selection"
|
|
2279
2279
|
};
|
|
2280
2280
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2281
|
-
|
|
2282
|
-
|
|
2281
|
+
context: snapshot.context,
|
|
2282
|
+
blocks: snapshot.context.value
|
|
2283
2283
|
}), html = toHtml.toHTML(blocks, {
|
|
2284
2284
|
onMissingComponent: !1,
|
|
2285
2285
|
components: {
|
|
@@ -2308,7 +2308,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2308
2308
|
keyGenerator: snapshot.context.keyGenerator,
|
|
2309
2309
|
unstable_whitespaceOnPasteMode: legacySchema.block.options.unstable_whitespaceOnPasteMode
|
|
2310
2310
|
}).flatMap((block) => {
|
|
2311
|
-
const parsedBlock =
|
|
2311
|
+
const parsedBlock = util_sliceBlocks.parseBlock({
|
|
2312
2312
|
context: snapshot.context,
|
|
2313
2313
|
block,
|
|
2314
2314
|
options: {
|
|
@@ -2335,24 +2335,21 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2335
2335
|
serialize: ({
|
|
2336
2336
|
snapshot,
|
|
2337
2337
|
event
|
|
2338
|
-
}) => {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
selection
|
|
2345
|
-
}).map((block) => types.isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2338
|
+
}) => snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection ? {
|
|
2339
|
+
type: "serialization.success",
|
|
2340
|
+
data: util_sliceBlocks.sliceBlocks({
|
|
2341
|
+
context: snapshot.context,
|
|
2342
|
+
blocks: snapshot.context.value
|
|
2343
|
+
}).map((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2346
2344
|
|
|
2347
2345
|
`),
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
};
|
|
2346
|
+
mimeType: "text/plain",
|
|
2347
|
+
originEvent: event.originEvent
|
|
2348
|
+
} : {
|
|
2349
|
+
type: "serialization.failure",
|
|
2350
|
+
mimeType: "text/plain",
|
|
2351
|
+
originEvent: event.originEvent,
|
|
2352
|
+
reason: "No selection"
|
|
2356
2353
|
},
|
|
2357
2354
|
deserialize: ({
|
|
2358
2355
|
snapshot,
|
|
@@ -2361,7 +2358,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2361
2358
|
const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`, parsedBlocks = blockTools.htmlToBlocks(textToHtml, legacySchema.portableText, {
|
|
2362
2359
|
keyGenerator: snapshot.context.keyGenerator
|
|
2363
2360
|
}).flatMap((block) => {
|
|
2364
|
-
const parsedBlock =
|
|
2361
|
+
const parsedBlock = util_sliceBlocks.parseBlock({
|
|
2365
2362
|
context: snapshot.context,
|
|
2366
2363
|
block,
|
|
2367
2364
|
options: {
|
|
@@ -3110,7 +3107,7 @@ const addAnnotationActionImplementation = ({
|
|
|
3110
3107
|
context,
|
|
3111
3108
|
action
|
|
3112
3109
|
}) => {
|
|
3113
|
-
const parsedAnnotation =
|
|
3110
|
+
const parsedAnnotation = util_sliceBlocks.parseAnnotation({
|
|
3114
3111
|
annotation: {
|
|
3115
3112
|
_type: action.annotation.name,
|
|
3116
3113
|
...action.annotation.value
|
|
@@ -3308,7 +3305,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3308
3305
|
const {
|
|
3309
3306
|
_type,
|
|
3310
3307
|
...filteredProps
|
|
3311
|
-
} = action.props, updatedBlock =
|
|
3308
|
+
} = action.props, updatedBlock = util_sliceBlocks.parseBlock({
|
|
3312
3309
|
context,
|
|
3313
3310
|
block: {
|
|
3314
3311
|
...parsedBlock,
|
|
@@ -3352,8 +3349,8 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3352
3349
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
3353
3350
|
if (!parsedBlock)
|
|
3354
3351
|
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
3355
|
-
if (
|
|
3356
|
-
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock =
|
|
3352
|
+
if (util_sliceBlocks.isTextBlock(context, parsedBlock)) {
|
|
3353
|
+
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = util_sliceBlocks.parseBlock({
|
|
3357
3354
|
context,
|
|
3358
3355
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
3359
3356
|
options: {
|
|
@@ -3370,7 +3367,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3370
3367
|
});
|
|
3371
3368
|
return;
|
|
3372
3369
|
}
|
|
3373
|
-
const updatedBlockObject =
|
|
3370
|
+
const updatedBlockObject = util_sliceBlocks.parseBlock({
|
|
3374
3371
|
context,
|
|
3375
3372
|
block: omit__default.default(parsedBlock, action.props.filter((prop) => prop !== "_type")),
|
|
3376
3373
|
options: {
|
|
@@ -3598,11 +3595,17 @@ const decoratorAddActionImplementation = ({
|
|
|
3598
3595
|
action
|
|
3599
3596
|
}) => {
|
|
3600
3597
|
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.at?.anchor ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3601
|
-
|
|
3598
|
+
context: {
|
|
3599
|
+
...context,
|
|
3600
|
+
value
|
|
3601
|
+
},
|
|
3602
3602
|
blockOffset: action.at.anchor,
|
|
3603
3603
|
direction: "backward"
|
|
3604
3604
|
}) : void 0, manualFocus = action.at?.focus ? util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
3605
|
-
|
|
3605
|
+
context: {
|
|
3606
|
+
...context,
|
|
3607
|
+
value
|
|
3608
|
+
},
|
|
3606
3609
|
blockOffset: action.at.focus,
|
|
3607
3610
|
direction: "forward"
|
|
3608
3611
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
@@ -3616,10 +3619,16 @@ const decoratorAddActionImplementation = ({
|
|
|
3616
3619
|
editor,
|
|
3617
3620
|
range: selection
|
|
3618
3621
|
}), anchorOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3619
|
-
|
|
3622
|
+
context: {
|
|
3623
|
+
...context,
|
|
3624
|
+
value
|
|
3625
|
+
},
|
|
3620
3626
|
selectionPoint: editorSelection.anchor
|
|
3621
3627
|
}) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
|
|
3622
|
-
|
|
3628
|
+
context: {
|
|
3629
|
+
...context,
|
|
3630
|
+
value
|
|
3631
|
+
},
|
|
3623
3632
|
selectionPoint: editorSelection.focus
|
|
3624
3633
|
}) : void 0;
|
|
3625
3634
|
if (!anchorOffset || !focusOffset)
|
|
@@ -3632,7 +3641,10 @@ const decoratorAddActionImplementation = ({
|
|
|
3632
3641
|
hanging: !0
|
|
3633
3642
|
});
|
|
3634
3643
|
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
3635
|
-
|
|
3644
|
+
context: {
|
|
3645
|
+
...context,
|
|
3646
|
+
value: newValue
|
|
3647
|
+
},
|
|
3636
3648
|
offsets: {
|
|
3637
3649
|
anchor: anchorOffset,
|
|
3638
3650
|
focus: focusOffset
|
|
@@ -3763,7 +3775,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3763
3775
|
context,
|
|
3764
3776
|
action
|
|
3765
3777
|
}) => {
|
|
3766
|
-
const parsedInlineObject =
|
|
3778
|
+
const parsedInlineObject = util_sliceBlocks.parseInlineObject({
|
|
3767
3779
|
context,
|
|
3768
3780
|
inlineObject: {
|
|
3769
3781
|
_type: action.inlineObject.name,
|
|
@@ -3832,7 +3844,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3832
3844
|
context,
|
|
3833
3845
|
action
|
|
3834
3846
|
}) => {
|
|
3835
|
-
const parsedBlock =
|
|
3847
|
+
const parsedBlock = util_sliceBlocks.parseBlock({
|
|
3836
3848
|
block: action.block,
|
|
3837
3849
|
context,
|
|
3838
3850
|
options: {
|
|
@@ -4931,7 +4943,7 @@ function createWithSchemaTypes({
|
|
|
4931
4943
|
editorActor
|
|
4932
4944
|
}) {
|
|
4933
4945
|
return function(editor) {
|
|
4934
|
-
editor.isTextBlock = (value) =>
|
|
4946
|
+
editor.isTextBlock = (value) => util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => util_sliceBlocks.isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => util_sliceBlocks.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4935
4947
|
const {
|
|
4936
4948
|
normalizeNode
|
|
4937
4949
|
} = editor;
|
|
@@ -5839,7 +5851,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5839
5851
|
event
|
|
5840
5852
|
}) => {
|
|
5841
5853
|
const manualSelection = event.at ? util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
5842
|
-
|
|
5854
|
+
context: snapshot.context,
|
|
5843
5855
|
offsets: event.at
|
|
5844
5856
|
}) : null;
|
|
5845
5857
|
return manualSelection ? !selector_isSelectingEntireBlocks.isActiveDecorator(event.decorator)({
|
|
@@ -5863,7 +5875,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5863
5875
|
event
|
|
5864
5876
|
}) => {
|
|
5865
5877
|
const selection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
5866
|
-
|
|
5878
|
+
context: snapshot.context,
|
|
5867
5879
|
offsets: event.at
|
|
5868
5880
|
});
|
|
5869
5881
|
if (!selection)
|
|
@@ -5929,6 +5941,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5929
5941
|
} : !1;
|
|
5930
5942
|
},
|
|
5931
5943
|
actions: [({
|
|
5944
|
+
snapshot,
|
|
5932
5945
|
event
|
|
5933
5946
|
}, {
|
|
5934
5947
|
focusTextBlock
|
|
@@ -5937,7 +5950,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5937
5950
|
block: event.blocks[0],
|
|
5938
5951
|
placement: "auto",
|
|
5939
5952
|
select: "end"
|
|
5940
|
-
})] : util_sliceBlocks.isEmptyTextBlock(focusTextBlock.node) ? event.blocks.map((block, index) => behavior_core.raise({
|
|
5953
|
+
})] : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behavior_core.raise({
|
|
5941
5954
|
type: "insert.block",
|
|
5942
5955
|
block,
|
|
5943
5956
|
placement: index === 0 ? "auto" : "after",
|
|
@@ -6125,7 +6138,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6125
6138
|
const previousBlock = selector_isOverlappingSelection.getPreviousBlock(snapshot);
|
|
6126
6139
|
if (!previousBlock)
|
|
6127
6140
|
return !1;
|
|
6128
|
-
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint(
|
|
6141
|
+
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint({
|
|
6142
|
+
context: snapshot.context,
|
|
6143
|
+
block: previousBlock
|
|
6144
|
+
}) : util_sliceBlocks.getBlockStartPoint({
|
|
6145
|
+
context: snapshot.context,
|
|
6146
|
+
block: previousBlock
|
|
6147
|
+
});
|
|
6129
6148
|
return {
|
|
6130
6149
|
selection: {
|
|
6131
6150
|
anchor: point,
|
|
@@ -6148,7 +6167,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6148
6167
|
const nextBlock = selector_isOverlappingSelection.getNextBlock(snapshot);
|
|
6149
6168
|
if (!nextBlock)
|
|
6150
6169
|
return !1;
|
|
6151
|
-
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint(
|
|
6170
|
+
const point = event.select === "end" ? util_sliceBlocks.getBlockEndPoint({
|
|
6171
|
+
context: snapshot.context,
|
|
6172
|
+
block: nextBlock
|
|
6173
|
+
}) : util_sliceBlocks.getBlockStartPoint({
|
|
6174
|
+
context: snapshot.context,
|
|
6175
|
+
block: nextBlock
|
|
6176
|
+
});
|
|
6152
6177
|
return {
|
|
6153
6178
|
selection: {
|
|
6154
6179
|
anchor: point,
|
|
@@ -6179,20 +6204,26 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6179
6204
|
}
|
|
6180
6205
|
});
|
|
6181
6206
|
if (focusTextBlock) {
|
|
6182
|
-
const blockEndPoint = util_sliceBlocks.getBlockEndPoint(
|
|
6207
|
+
const blockEndPoint = util_sliceBlocks.getBlockEndPoint({
|
|
6208
|
+
context: snapshot.context,
|
|
6209
|
+
block: focusTextBlock
|
|
6210
|
+
}), newTextBlockSelection = {
|
|
6183
6211
|
anchor: selectionEndPoint,
|
|
6184
6212
|
focus: blockEndPoint
|
|
6185
|
-
}, newTextBlock =
|
|
6213
|
+
}, newTextBlock = util_sliceBlocks.parseBlock({
|
|
6186
6214
|
block: util_sliceBlocks.sliceBlocks({
|
|
6187
|
-
|
|
6188
|
-
|
|
6215
|
+
context: {
|
|
6216
|
+
...snapshot.context,
|
|
6217
|
+
selection: newTextBlockSelection
|
|
6218
|
+
},
|
|
6219
|
+
blocks: [focusTextBlock.node]
|
|
6189
6220
|
}).at(0),
|
|
6190
6221
|
context: snapshot.context,
|
|
6191
6222
|
options: {
|
|
6192
6223
|
refreshKeys: !0
|
|
6193
6224
|
}
|
|
6194
6225
|
});
|
|
6195
|
-
return !newTextBlock || !
|
|
6226
|
+
return !newTextBlock || !util_sliceBlocks.isTextBlock(snapshot.context, newTextBlock) ? !1 : {
|
|
6196
6227
|
newTextBlock,
|
|
6197
6228
|
newTextBlockSelection,
|
|
6198
6229
|
selection: {
|
|
@@ -6210,7 +6241,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6210
6241
|
}
|
|
6211
6242
|
}
|
|
6212
6243
|
})) {
|
|
6213
|
-
const newTextBlock =
|
|
6244
|
+
const newTextBlock = util_sliceBlocks.parseBlock({
|
|
6214
6245
|
block: {
|
|
6215
6246
|
_type: snapshot.context.schema.block.name,
|
|
6216
6247
|
children: []
|
|
@@ -6545,7 +6576,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6545
6576
|
return {
|
|
6546
6577
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
6547
6578
|
activeDecorators,
|
|
6548
|
-
textRuns: event.data.flatMap((block) =>
|
|
6579
|
+
textRuns: event.data.flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? [util_sliceBlocks.getTextBlockText(block)] : [])
|
|
6549
6580
|
};
|
|
6550
6581
|
}
|
|
6551
6582
|
return !1;
|