@portabletext/editor 1.48.8 → 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/editor-provider.cjs +38 -38
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +3 -23
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +2 -1
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +2 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +1 -20
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.d.cts +228 -2529
- package/lib/behaviors/index.d.ts +228 -2529
- package/lib/index.d.cts +26 -2325
- package/lib/index.d.ts +26 -2325
- package/lib/plugins/index.d.cts +16 -2316
- package/lib/plugins/index.d.ts +16 -2316
- package/lib/selectors/index.cjs +2 -2
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +22 -2319
- package/lib/selectors/index.d.ts +22 -2319
- package/lib/selectors/index.js +2 -1
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +21 -2321
- package/lib/utils/index.d.ts +21 -2321
- package/package.json +2 -1
|
@@ -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"), 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"),
|
|
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, 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,
|
|
@@ -355,26 +355,26 @@ function validateValue(value, types, keyGenerator) {
|
|
|
355
355
|
}, !0;
|
|
356
356
|
}
|
|
357
357
|
return !blk._type && util_sliceBlocks.isTextBlock({
|
|
358
|
-
schema:
|
|
358
|
+
schema: types2
|
|
359
359
|
}, {
|
|
360
360
|
...blk,
|
|
361
|
-
_type:
|
|
361
|
+
_type: types2.block.name
|
|
362
362
|
}) ? (resolution = {
|
|
363
363
|
patches: [patches.set({
|
|
364
364
|
...blk,
|
|
365
|
-
_type:
|
|
365
|
+
_type: types2.block.name
|
|
366
366
|
}, [{
|
|
367
367
|
_key: blk._key
|
|
368
368
|
}])],
|
|
369
|
-
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${
|
|
370
|
-
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}'`,
|
|
371
371
|
item: blk,
|
|
372
372
|
i18n: {
|
|
373
373
|
description: "inputs.portable-text.invalid-value.missing-block-type.description",
|
|
374
374
|
action: "inputs.portable-text.invalid-value.missing-block-type.action",
|
|
375
375
|
values: {
|
|
376
376
|
key: blk._key,
|
|
377
|
-
expectedTypeName:
|
|
377
|
+
expectedTypeName: types2.block.name
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
}, !0) : blk._type ? (resolution = {
|
|
@@ -408,7 +408,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
408
408
|
}
|
|
409
409
|
}, !0);
|
|
410
410
|
}
|
|
411
|
-
if (blk._type ===
|
|
411
|
+
if (blk._type === types2.block.name) {
|
|
412
412
|
const textBlock = blk;
|
|
413
413
|
if (textBlock.children && !Array.isArray(textBlock.children))
|
|
414
414
|
return resolution = {
|
|
@@ -430,7 +430,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
430
430
|
}, !0;
|
|
431
431
|
if (textBlock.children === void 0 || Array.isArray(textBlock.children) && textBlock.children.length === 0) {
|
|
432
432
|
const newSpan = {
|
|
433
|
-
_type:
|
|
433
|
+
_type: types2.span.name,
|
|
434
434
|
_key: keyGenerator(),
|
|
435
435
|
text: "",
|
|
436
436
|
marks: []
|
|
@@ -454,7 +454,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
454
454
|
}
|
|
455
455
|
}, !0;
|
|
456
456
|
}
|
|
457
|
-
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 || [])));
|
|
458
458
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
459
459
|
const unusedMarkDefs = uniq__default.default(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)));
|
|
460
460
|
if (unusedMarkDefs.length > 0)
|
|
@@ -478,9 +478,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
478
478
|
}
|
|
479
479
|
}, !0;
|
|
480
480
|
}
|
|
481
|
-
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));
|
|
482
482
|
if (orphanedMarks.length > 0) {
|
|
483
|
-
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)));
|
|
484
484
|
if (spanChildren) {
|
|
485
485
|
const orphaned = orphanedMarks.join(", ");
|
|
486
486
|
return resolution = {
|
|
@@ -545,7 +545,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
545
545
|
}
|
|
546
546
|
}, !0;
|
|
547
547
|
}
|
|
548
|
-
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 = {
|
|
549
549
|
patches: [patches.set({
|
|
550
550
|
...child,
|
|
551
551
|
text: ""
|
|
@@ -3241,7 +3241,7 @@ function toSlatePath(path, editor) {
|
|
|
3241
3241
|
return [];
|
|
3242
3242
|
const [block, blockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
3243
3243
|
at: [],
|
|
3244
|
-
match: (n) =>
|
|
3244
|
+
match: (n) => types.isKeySegment(path[0]) && n._key === path[0]._key
|
|
3245
3245
|
}))[0] || [void 0, void 0];
|
|
3246
3246
|
if (!block || !slate.Element.isElement(block))
|
|
3247
3247
|
return [];
|
|
@@ -5163,7 +5163,7 @@ function legacySchemaToEditorSchema(schema2) {
|
|
|
5163
5163
|
};
|
|
5164
5164
|
}
|
|
5165
5165
|
function compileSchemaDefinitionToLegacySchema(definition) {
|
|
5166
|
-
const blockObjects = definition?.blockObjects?.map((blockObject) =>
|
|
5166
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
5167
5167
|
type: "object",
|
|
5168
5168
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5169
5169
|
// fields to objects with certain names.
|
|
@@ -5176,7 +5176,7 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
5176
5176
|
name: field.name,
|
|
5177
5177
|
type: field.type
|
|
5178
5178
|
})) ?? []
|
|
5179
|
-
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) =>
|
|
5179
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
5180
5180
|
type: "object",
|
|
5181
5181
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5182
5182
|
// fields to objects with certain names.
|
|
@@ -5189,7 +5189,7 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
5189
5189
|
name: field.name,
|
|
5190
5190
|
type: field.type
|
|
5191
5191
|
})) ?? []
|
|
5192
|
-
})) ?? [], portableTextSchema =
|
|
5192
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
5193
5193
|
type: "array",
|
|
5194
5194
|
name: "portable-text",
|
|
5195
5195
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -5321,7 +5321,7 @@ function getEditorSnapshot({
|
|
|
5321
5321
|
}
|
|
5322
5322
|
const debug$3 = debugWithName("API:editable");
|
|
5323
5323
|
function createEditableAPI(editor, editorActor) {
|
|
5324
|
-
const
|
|
5324
|
+
const types2 = editorActor.getSnapshot().context.schema;
|
|
5325
5325
|
return {
|
|
5326
5326
|
focus: () => {
|
|
5327
5327
|
editorActor.send({
|
|
@@ -5404,18 +5404,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5404
5404
|
if (editor.selection) {
|
|
5405
5405
|
const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
5406
5406
|
if (block)
|
|
5407
|
-
return fromSlateValue([block],
|
|
5407
|
+
return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
5408
5408
|
}
|
|
5409
5409
|
},
|
|
5410
5410
|
focusChild: () => {
|
|
5411
5411
|
if (editor.selection) {
|
|
5412
5412
|
const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
5413
5413
|
if (block && editor.isTextBlock(block))
|
|
5414
|
-
return fromSlateValue([block],
|
|
5414
|
+
return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
|
|
5415
5415
|
}
|
|
5416
5416
|
},
|
|
5417
5417
|
insertChild: (type, value) => {
|
|
5418
|
-
if (type.name !==
|
|
5418
|
+
if (type.name !== types2.span.name)
|
|
5419
5419
|
return editorActor.send({
|
|
5420
5420
|
type: "behavior event",
|
|
5421
5421
|
behaviorEvent: {
|
|
@@ -5435,15 +5435,15 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5435
5435
|
throw new Error("The editor has no selection");
|
|
5436
5436
|
const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
|
|
5437
5437
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5438
|
-
match: (n) => n._type ===
|
|
5438
|
+
match: (n) => n._type === types2.block.name
|
|
5439
5439
|
}))[0] || [void 0];
|
|
5440
5440
|
if (!focusBlock)
|
|
5441
5441
|
throw new Error("No focused text block");
|
|
5442
|
-
if (type.name !==
|
|
5442
|
+
if (type.name !== types2.span.name && !types2.inlineObjects.some((t) => t.name === type.name))
|
|
5443
5443
|
throw new Error("This type cannot be inserted as a child to a text block");
|
|
5444
5444
|
const child = toSlateValue([{
|
|
5445
5445
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5446
|
-
_type:
|
|
5446
|
+
_type: types2.block.name,
|
|
5447
5447
|
children: [{
|
|
5448
5448
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5449
5449
|
_type: type.name,
|
|
@@ -5451,8 +5451,8 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5451
5451
|
}]
|
|
5452
5452
|
}], {
|
|
5453
5453
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5454
|
-
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type ===
|
|
5455
|
-
return isSpanNode && focusNode._type !==
|
|
5454
|
+
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
5455
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$3("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
5456
5456
|
distance: 1,
|
|
5457
5457
|
unit: "character"
|
|
5458
5458
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -5500,7 +5500,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5500
5500
|
return !1;
|
|
5501
5501
|
}
|
|
5502
5502
|
},
|
|
5503
|
-
isVoid: (element) => ![
|
|
5503
|
+
isVoid: (element) => ![types2.block.name, types2.span.name].includes(element._type),
|
|
5504
5504
|
findByPath: (path) => {
|
|
5505
5505
|
const slatePath = toSlateRange({
|
|
5506
5506
|
focus: {
|
|
@@ -5516,10 +5516,10 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5516
5516
|
const [block, blockPath] = slate.Editor.node(editor, slatePath.focus.path.slice(0, 1));
|
|
5517
5517
|
if (block && blockPath && typeof block._key == "string") {
|
|
5518
5518
|
if (path.length === 1 && slatePath.focus.path.length === 1)
|
|
5519
|
-
return [fromSlateValue([block],
|
|
5519
|
+
return [fromSlateValue([block], types2.block.name)[0], [{
|
|
5520
5520
|
_key: block._key
|
|
5521
5521
|
}]];
|
|
5522
|
-
const ptBlock = fromSlateValue([block],
|
|
5522
|
+
const ptBlock = fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
5523
5523
|
if (editor.isTextBlock(ptBlock)) {
|
|
5524
5524
|
const ptChild = ptBlock.children[slatePath.focus.path[1]];
|
|
5525
5525
|
if (ptChild)
|
|
@@ -5578,7 +5578,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5578
5578
|
paths = addAnnotationActionImplementation({
|
|
5579
5579
|
context: {
|
|
5580
5580
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5581
|
-
schema:
|
|
5581
|
+
schema: types2
|
|
5582
5582
|
},
|
|
5583
5583
|
action: {
|
|
5584
5584
|
annotation: {
|
|
@@ -5611,7 +5611,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5611
5611
|
})), options?.mode === "children" && (debug$3("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
5612
5612
|
at: range,
|
|
5613
5613
|
voids: !0,
|
|
5614
|
-
match: (node) => node._type ===
|
|
5614
|
+
match: (node) => node._type === types2.span.name || // Text children
|
|
5615
5615
|
!editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
5616
5616
|
})), editor.children.length === 0 && (editor.children = [editor.pteCreateTextBlock({
|
|
5617
5617
|
decorators: []
|
|
@@ -5645,13 +5645,13 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5645
5645
|
}
|
|
5646
5646
|
return ptRange;
|
|
5647
5647
|
},
|
|
5648
|
-
getValue: () => fromSlateValue(editor.children,
|
|
5648
|
+
getValue: () => fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
5649
5649
|
isCollapsedSelection: () => !!editor.selection && slate.Range.isCollapsed(editor.selection),
|
|
5650
5650
|
isExpandedSelection: () => !!editor.selection && slate.Range.isExpanded(editor.selection),
|
|
5651
5651
|
insertBreak: () => {
|
|
5652
5652
|
editor.insertBreak(), editor.onChange();
|
|
5653
5653
|
},
|
|
5654
|
-
getFragment: () => fromSlateValue(editor.getFragment(),
|
|
5654
|
+
getFragment: () => fromSlateValue(editor.getFragment(), types2.block.name),
|
|
5655
5655
|
isSelectionsOverlapping: (selectionA, selectionB) => {
|
|
5656
5656
|
const rangeA = toSlateRange(selectionA, editor), rangeB = toSlateRange(selectionB, editor);
|
|
5657
5657
|
return slate.Range.isRange(rangeA) && slate.Range.isRange(rangeB) && slate.Range.includes(rangeA, rangeB);
|
|
@@ -5669,14 +5669,14 @@ function isAnnotationActive({
|
|
|
5669
5669
|
at: editor.selection,
|
|
5670
5670
|
match: (node) => slate.Text.isText(node)
|
|
5671
5671
|
})];
|
|
5672
|
-
if (spans.length === 0 || spans.some(([span]) => !
|
|
5672
|
+
if (spans.length === 0 || spans.some(([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
5673
5673
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5674
5674
|
const [block] = slate.Editor.node(editor, path, {
|
|
5675
5675
|
depth: 1
|
|
5676
5676
|
});
|
|
5677
5677
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5678
5678
|
}, []);
|
|
5679
|
-
return spans.every(([span]) =>
|
|
5679
|
+
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
5680
5680
|
} catch {
|
|
5681
5681
|
return !1;
|
|
5682
5682
|
}
|