@portabletext/editor 1.48.8 → 1.48.10
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 +141 -85
- 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 +105 -48
- 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 +751 -2891
- package/lib/behaviors/index.d.ts +751 -2891
- package/lib/index.d.cts +554 -2692
- package/lib/index.d.ts +554 -2692
- package/lib/plugins/index.d.cts +547 -2686
- package/lib/plugins/index.d.ts +547 -2686
- package/lib/selectors/index.cjs +2 -2
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +563 -2699
- package/lib/selectors/index.d.ts +563 -2699
- package/lib/selectors/index.js +2 -1
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +565 -2704
- package/lib/utils/index.d.ts +565 -2704
- package/package.json +4 -3
- package/src/editor/editor-machine.ts +104 -39
- package/src/editor/sync-machine.ts +10 -4
|
@@ -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: ""
|
|
@@ -1626,8 +1626,11 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1626
1626
|
event
|
|
1627
1627
|
}) => (xstate.assertEvent(event, "done syncing"), event.value)
|
|
1628
1628
|
}),
|
|
1629
|
-
"emit done syncing
|
|
1630
|
-
type: "done syncing
|
|
1629
|
+
"emit done syncing value": xstate.emit({
|
|
1630
|
+
type: "done syncing value"
|
|
1631
|
+
}),
|
|
1632
|
+
"emit syncing value": xstate.emit({
|
|
1633
|
+
type: "syncing value"
|
|
1631
1634
|
})
|
|
1632
1635
|
},
|
|
1633
1636
|
guards: {
|
|
@@ -1703,7 +1706,7 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1703
1706
|
}
|
|
1704
1707
|
},
|
|
1705
1708
|
"done syncing initial value": {
|
|
1706
|
-
entry: ["emit done syncing
|
|
1709
|
+
entry: ["emit done syncing value", () => {
|
|
1707
1710
|
debug$d("entry: done syncing initial value");
|
|
1708
1711
|
}],
|
|
1709
1712
|
exit: [() => {
|
|
@@ -1762,10 +1765,10 @@ const debug$d = debugWithName("sync machine"), syncValueCallback = ({
|
|
|
1762
1765
|
syncing: {
|
|
1763
1766
|
entry: [() => {
|
|
1764
1767
|
debug$d("entry: syncing->syncing");
|
|
1765
|
-
}],
|
|
1768
|
+
}, "emit syncing value"],
|
|
1766
1769
|
exit: [() => {
|
|
1767
1770
|
debug$d("exit: syncing->syncing");
|
|
1768
|
-
}],
|
|
1771
|
+
}, "emit done syncing value"],
|
|
1769
1772
|
always: {
|
|
1770
1773
|
guard: "pending value equals previous value",
|
|
1771
1774
|
target: "idle",
|
|
@@ -3241,7 +3244,7 @@ function toSlatePath(path, editor) {
|
|
|
3241
3244
|
return [];
|
|
3242
3245
|
const [block, blockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
3243
3246
|
at: [],
|
|
3244
|
-
match: (n) =>
|
|
3247
|
+
match: (n) => types.isKeySegment(path[0]) && n._key === path[0]._key
|
|
3245
3248
|
}))[0] || [void 0, void 0];
|
|
3246
3249
|
if (!block || !slate.Element.isElement(block))
|
|
3247
3250
|
return [];
|
|
@@ -5163,7 +5166,7 @@ function legacySchemaToEditorSchema(schema2) {
|
|
|
5163
5166
|
};
|
|
5164
5167
|
}
|
|
5165
5168
|
function compileSchemaDefinitionToLegacySchema(definition) {
|
|
5166
|
-
const blockObjects = definition?.blockObjects?.map((blockObject) =>
|
|
5169
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
5167
5170
|
type: "object",
|
|
5168
5171
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5169
5172
|
// fields to objects with certain names.
|
|
@@ -5176,7 +5179,7 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
5176
5179
|
name: field.name,
|
|
5177
5180
|
type: field.type
|
|
5178
5181
|
})) ?? []
|
|
5179
|
-
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) =>
|
|
5182
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
5180
5183
|
type: "object",
|
|
5181
5184
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
5182
5185
|
// fields to objects with certain names.
|
|
@@ -5189,7 +5192,7 @@ function compileSchemaDefinitionToLegacySchema(definition) {
|
|
|
5189
5192
|
name: field.name,
|
|
5190
5193
|
type: field.type
|
|
5191
5194
|
})) ?? []
|
|
5192
|
-
})) ?? [], portableTextSchema =
|
|
5195
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
5193
5196
|
type: "array",
|
|
5194
5197
|
name: "portable-text",
|
|
5195
5198
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -5321,7 +5324,7 @@ function getEditorSnapshot({
|
|
|
5321
5324
|
}
|
|
5322
5325
|
const debug$3 = debugWithName("API:editable");
|
|
5323
5326
|
function createEditableAPI(editor, editorActor) {
|
|
5324
|
-
const
|
|
5327
|
+
const types2 = editorActor.getSnapshot().context.schema;
|
|
5325
5328
|
return {
|
|
5326
5329
|
focus: () => {
|
|
5327
5330
|
editorActor.send({
|
|
@@ -5404,18 +5407,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5404
5407
|
if (editor.selection) {
|
|
5405
5408
|
const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
5406
5409
|
if (block)
|
|
5407
|
-
return fromSlateValue([block],
|
|
5410
|
+
return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
5408
5411
|
}
|
|
5409
5412
|
},
|
|
5410
5413
|
focusChild: () => {
|
|
5411
5414
|
if (editor.selection) {
|
|
5412
5415
|
const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
5413
5416
|
if (block && editor.isTextBlock(block))
|
|
5414
|
-
return fromSlateValue([block],
|
|
5417
|
+
return fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
|
|
5415
5418
|
}
|
|
5416
5419
|
},
|
|
5417
5420
|
insertChild: (type, value) => {
|
|
5418
|
-
if (type.name !==
|
|
5421
|
+
if (type.name !== types2.span.name)
|
|
5419
5422
|
return editorActor.send({
|
|
5420
5423
|
type: "behavior event",
|
|
5421
5424
|
behaviorEvent: {
|
|
@@ -5435,15 +5438,15 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5435
5438
|
throw new Error("The editor has no selection");
|
|
5436
5439
|
const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
|
|
5437
5440
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5438
|
-
match: (n) => n._type ===
|
|
5441
|
+
match: (n) => n._type === types2.block.name
|
|
5439
5442
|
}))[0] || [void 0];
|
|
5440
5443
|
if (!focusBlock)
|
|
5441
5444
|
throw new Error("No focused text block");
|
|
5442
|
-
if (type.name !==
|
|
5445
|
+
if (type.name !== types2.span.name && !types2.inlineObjects.some((t) => t.name === type.name))
|
|
5443
5446
|
throw new Error("This type cannot be inserted as a child to a text block");
|
|
5444
5447
|
const child = toSlateValue([{
|
|
5445
5448
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5446
|
-
_type:
|
|
5449
|
+
_type: types2.block.name,
|
|
5447
5450
|
children: [{
|
|
5448
5451
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5449
5452
|
_type: type.name,
|
|
@@ -5451,8 +5454,8 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5451
5454
|
}]
|
|
5452
5455
|
}], {
|
|
5453
5456
|
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 !==
|
|
5457
|
+
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
5458
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$3("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
5456
5459
|
distance: 1,
|
|
5457
5460
|
unit: "character"
|
|
5458
5461
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -5500,7 +5503,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5500
5503
|
return !1;
|
|
5501
5504
|
}
|
|
5502
5505
|
},
|
|
5503
|
-
isVoid: (element) => ![
|
|
5506
|
+
isVoid: (element) => ![types2.block.name, types2.span.name].includes(element._type),
|
|
5504
5507
|
findByPath: (path) => {
|
|
5505
5508
|
const slatePath = toSlateRange({
|
|
5506
5509
|
focus: {
|
|
@@ -5516,10 +5519,10 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5516
5519
|
const [block, blockPath] = slate.Editor.node(editor, slatePath.focus.path.slice(0, 1));
|
|
5517
5520
|
if (block && blockPath && typeof block._key == "string") {
|
|
5518
5521
|
if (path.length === 1 && slatePath.focus.path.length === 1)
|
|
5519
|
-
return [fromSlateValue([block],
|
|
5522
|
+
return [fromSlateValue([block], types2.block.name)[0], [{
|
|
5520
5523
|
_key: block._key
|
|
5521
5524
|
}]];
|
|
5522
|
-
const ptBlock = fromSlateValue([block],
|
|
5525
|
+
const ptBlock = fromSlateValue([block], types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
5523
5526
|
if (editor.isTextBlock(ptBlock)) {
|
|
5524
5527
|
const ptChild = ptBlock.children[slatePath.focus.path[1]];
|
|
5525
5528
|
if (ptChild)
|
|
@@ -5578,7 +5581,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5578
5581
|
paths = addAnnotationActionImplementation({
|
|
5579
5582
|
context: {
|
|
5580
5583
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5581
|
-
schema:
|
|
5584
|
+
schema: types2
|
|
5582
5585
|
},
|
|
5583
5586
|
action: {
|
|
5584
5587
|
annotation: {
|
|
@@ -5611,7 +5614,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5611
5614
|
})), options?.mode === "children" && (debug$3("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
5612
5615
|
at: range,
|
|
5613
5616
|
voids: !0,
|
|
5614
|
-
match: (node) => node._type ===
|
|
5617
|
+
match: (node) => node._type === types2.span.name || // Text children
|
|
5615
5618
|
!editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
5616
5619
|
})), editor.children.length === 0 && (editor.children = [editor.pteCreateTextBlock({
|
|
5617
5620
|
decorators: []
|
|
@@ -5645,13 +5648,13 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5645
5648
|
}
|
|
5646
5649
|
return ptRange;
|
|
5647
5650
|
},
|
|
5648
|
-
getValue: () => fromSlateValue(editor.children,
|
|
5651
|
+
getValue: () => fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
5649
5652
|
isCollapsedSelection: () => !!editor.selection && slate.Range.isCollapsed(editor.selection),
|
|
5650
5653
|
isExpandedSelection: () => !!editor.selection && slate.Range.isExpanded(editor.selection),
|
|
5651
5654
|
insertBreak: () => {
|
|
5652
5655
|
editor.insertBreak(), editor.onChange();
|
|
5653
5656
|
},
|
|
5654
|
-
getFragment: () => fromSlateValue(editor.getFragment(),
|
|
5657
|
+
getFragment: () => fromSlateValue(editor.getFragment(), types2.block.name),
|
|
5655
5658
|
isSelectionsOverlapping: (selectionA, selectionB) => {
|
|
5656
5659
|
const rangeA = toSlateRange(selectionA, editor), rangeB = toSlateRange(selectionB, editor);
|
|
5657
5660
|
return slate.Range.isRange(rangeA) && slate.Range.isRange(rangeB) && slate.Range.includes(rangeA, rangeB);
|
|
@@ -5669,14 +5672,14 @@ function isAnnotationActive({
|
|
|
5669
5672
|
at: editor.selection,
|
|
5670
5673
|
match: (node) => slate.Text.isText(node)
|
|
5671
5674
|
})];
|
|
5672
|
-
if (spans.length === 0 || spans.some(([span]) => !
|
|
5675
|
+
if (spans.length === 0 || spans.some(([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
5673
5676
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5674
5677
|
const [block] = slate.Editor.node(editor, path, {
|
|
5675
5678
|
depth: 1
|
|
5676
5679
|
});
|
|
5677
5680
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5678
5681
|
}, []);
|
|
5679
|
-
return spans.every(([span]) =>
|
|
5682
|
+
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
5680
5683
|
} catch {
|
|
5681
5684
|
return !1;
|
|
5682
5685
|
}
|
|
@@ -6986,6 +6989,22 @@ const editorMachine = xstate.setup({
|
|
|
6986
6989
|
"clear pending events": xstate.assign({
|
|
6987
6990
|
pendingEvents: []
|
|
6988
6991
|
}),
|
|
6992
|
+
"defer incoming patches": xstate.assign({
|
|
6993
|
+
pendingIncomingPatchesEvents: ({
|
|
6994
|
+
context,
|
|
6995
|
+
event
|
|
6996
|
+
}) => event.type === "patches" ? [...context.pendingIncomingPatchesEvents, event] : context.pendingIncomingPatchesEvents
|
|
6997
|
+
}),
|
|
6998
|
+
"emit pending incoming patches": xstate.enqueueActions(({
|
|
6999
|
+
context,
|
|
7000
|
+
enqueue
|
|
7001
|
+
}) => {
|
|
7002
|
+
for (const event of context.pendingIncomingPatchesEvents)
|
|
7003
|
+
enqueue.emit(event);
|
|
7004
|
+
}),
|
|
7005
|
+
"clear pending incoming patches": xstate.assign({
|
|
7006
|
+
pendingIncomingPatchesEvents: []
|
|
7007
|
+
}),
|
|
6989
7008
|
"handle blur": ({
|
|
6990
7009
|
event
|
|
6991
7010
|
}) => {
|
|
@@ -7053,6 +7072,7 @@ const editorMachine = xstate.setup({
|
|
|
7053
7072
|
getLegacySchema: input.getLegacySchema,
|
|
7054
7073
|
keyGenerator: input.keyGenerator,
|
|
7055
7074
|
pendingEvents: [],
|
|
7075
|
+
pendingIncomingPatchesEvents: [],
|
|
7056
7076
|
schema: input.schema,
|
|
7057
7077
|
selection: null,
|
|
7058
7078
|
initialReadOnly: input.readOnly ?? !1,
|
|
@@ -7136,11 +7156,6 @@ const editorMachine = xstate.setup({
|
|
|
7136
7156
|
"remove behavior": {
|
|
7137
7157
|
actions: "remove behavior from context"
|
|
7138
7158
|
},
|
|
7139
|
-
patches: {
|
|
7140
|
-
actions: xstate.emit(({
|
|
7141
|
-
event
|
|
7142
|
-
}) => event)
|
|
7143
|
-
},
|
|
7144
7159
|
"update behaviors": {
|
|
7145
7160
|
actions: "assign behaviors"
|
|
7146
7161
|
},
|
|
@@ -7187,7 +7202,7 @@ const editorMachine = xstate.setup({
|
|
|
7187
7202
|
states: {
|
|
7188
7203
|
"determine initial edit mode": {
|
|
7189
7204
|
on: {
|
|
7190
|
-
"done syncing
|
|
7205
|
+
"done syncing value": [{
|
|
7191
7206
|
target: "#editor.edit mode.read only.read only",
|
|
7192
7207
|
guard: ({
|
|
7193
7208
|
context
|
|
@@ -7303,7 +7318,7 @@ const editorMachine = xstate.setup({
|
|
|
7303
7318
|
initial: "setting up",
|
|
7304
7319
|
states: {
|
|
7305
7320
|
"setting up": {
|
|
7306
|
-
exit: ["emit ready"],
|
|
7321
|
+
exit: ["emit ready", "emit pending incoming patches", "clear pending incoming patches"],
|
|
7307
7322
|
on: {
|
|
7308
7323
|
"internal.patch": {
|
|
7309
7324
|
actions: "defer event"
|
|
@@ -7311,54 +7326,95 @@ const editorMachine = xstate.setup({
|
|
|
7311
7326
|
mutation: {
|
|
7312
7327
|
actions: "defer event"
|
|
7313
7328
|
},
|
|
7314
|
-
"done syncing
|
|
7315
|
-
target: "
|
|
7329
|
+
"done syncing value": {
|
|
7330
|
+
target: "set up"
|
|
7331
|
+
},
|
|
7332
|
+
patches: {
|
|
7333
|
+
actions: ["defer incoming patches"]
|
|
7316
7334
|
}
|
|
7317
7335
|
}
|
|
7318
7336
|
},
|
|
7319
|
-
|
|
7320
|
-
|
|
7337
|
+
"set up": {
|
|
7338
|
+
type: "parallel",
|
|
7321
7339
|
states: {
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7340
|
+
"value sync": {
|
|
7341
|
+
initial: "idle",
|
|
7342
|
+
states: {
|
|
7343
|
+
idle: {
|
|
7344
|
+
on: {
|
|
7345
|
+
patches: {
|
|
7346
|
+
actions: [xstate.emit(({
|
|
7347
|
+
event
|
|
7348
|
+
}) => event)]
|
|
7349
|
+
},
|
|
7350
|
+
"syncing value": {
|
|
7351
|
+
target: "syncing value"
|
|
7352
|
+
}
|
|
7353
|
+
}
|
|
7330
7354
|
},
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7355
|
+
"syncing value": {
|
|
7356
|
+
exit: ["emit pending incoming patches", "clear pending incoming patches"],
|
|
7357
|
+
on: {
|
|
7358
|
+
patches: {
|
|
7359
|
+
actions: ["defer incoming patches"]
|
|
7360
|
+
},
|
|
7361
|
+
"done syncing value": {
|
|
7362
|
+
target: "idle"
|
|
7363
|
+
}
|
|
7364
|
+
}
|
|
7334
7365
|
}
|
|
7335
7366
|
}
|
|
7336
7367
|
},
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7368
|
+
writing: {
|
|
7369
|
+
initial: "pristine",
|
|
7370
|
+
states: {
|
|
7371
|
+
pristine: {
|
|
7372
|
+
initial: "idle",
|
|
7373
|
+
states: {
|
|
7374
|
+
idle: {
|
|
7375
|
+
on: {
|
|
7376
|
+
normalizing: {
|
|
7377
|
+
target: "normalizing"
|
|
7378
|
+
},
|
|
7379
|
+
"internal.patch": {
|
|
7380
|
+
actions: "defer event",
|
|
7381
|
+
target: "#editor.setup.set up.writing.dirty"
|
|
7382
|
+
},
|
|
7383
|
+
mutation: {
|
|
7384
|
+
actions: "defer event",
|
|
7385
|
+
target: "#editor.setup.set up.writing.dirty"
|
|
7386
|
+
}
|
|
7387
|
+
}
|
|
7388
|
+
},
|
|
7389
|
+
normalizing: {
|
|
7390
|
+
on: {
|
|
7391
|
+
"done normalizing": {
|
|
7392
|
+
target: "idle"
|
|
7393
|
+
},
|
|
7394
|
+
"internal.patch": {
|
|
7395
|
+
actions: "defer event"
|
|
7396
|
+
},
|
|
7397
|
+
mutation: {
|
|
7398
|
+
actions: "defer event"
|
|
7399
|
+
}
|
|
7400
|
+
}
|
|
7401
|
+
}
|
|
7402
|
+
}
|
|
7344
7403
|
},
|
|
7345
|
-
|
|
7346
|
-
|
|
7404
|
+
dirty: {
|
|
7405
|
+
entry: ["emit pending events", "clear pending events"],
|
|
7406
|
+
on: {
|
|
7407
|
+
"internal.patch": {
|
|
7408
|
+
actions: "emit patch event"
|
|
7409
|
+
},
|
|
7410
|
+
mutation: {
|
|
7411
|
+
actions: "emit mutation event"
|
|
7412
|
+
}
|
|
7413
|
+
}
|
|
7347
7414
|
}
|
|
7348
7415
|
}
|
|
7349
7416
|
}
|
|
7350
7417
|
}
|
|
7351
|
-
},
|
|
7352
|
-
dirty: {
|
|
7353
|
-
entry: ["emit pending events", "clear pending events"],
|
|
7354
|
-
on: {
|
|
7355
|
-
"internal.patch": {
|
|
7356
|
-
actions: "emit patch event"
|
|
7357
|
-
},
|
|
7358
|
-
mutation: {
|
|
7359
|
-
actions: "emit mutation event"
|
|
7360
|
-
}
|
|
7361
|
-
}
|
|
7362
7418
|
}
|
|
7363
7419
|
}
|
|
7364
7420
|
}
|