@portabletext/editor 2.21.3 → 3.0.0

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.
Files changed (78) hide show
  1. package/lib/_chunks-dts/index.d.ts +49 -209
  2. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +103 -20
  3. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  4. package/lib/_chunks-es/{util.get-text-block-text.js → util.slice-blocks.js} +29 -5
  5. package/lib/_chunks-es/util.slice-blocks.js.map +1 -0
  6. package/lib/_chunks-es/util.slice-text-block.js +13 -2
  7. package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
  8. package/lib/behaviors/index.d.ts +1 -1
  9. package/lib/index.d.ts +2 -2
  10. package/lib/index.js +297 -320
  11. package/lib/index.js.map +1 -1
  12. package/lib/plugins/index.d.ts +2 -133
  13. package/lib/plugins/index.js +2 -796
  14. package/lib/plugins/index.js.map +1 -1
  15. package/lib/selectors/index.d.ts +2 -24
  16. package/lib/selectors/index.js +28 -130
  17. package/lib/selectors/index.js.map +1 -1
  18. package/lib/utils/index.d.ts +3 -3
  19. package/lib/utils/index.js +97 -9
  20. package/lib/utils/index.js.map +1 -1
  21. package/package.json +3 -5
  22. package/src/behaviors/behavior.perform-event.ts +7 -7
  23. package/src/editor/PortableTextEditor.tsx +0 -19
  24. package/src/editor/create-editor.ts +0 -3
  25. package/src/editor/editor-machine.ts +0 -10
  26. package/src/editor/event-to-change.tsx +5 -1
  27. package/src/editor/plugins/create-with-event-listeners.ts +0 -4
  28. package/src/editor/plugins/createWithObjectKeys.ts +2 -1
  29. package/src/editor/plugins/createWithPatches.ts +3 -3
  30. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -1
  31. package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -1
  32. package/src/editor/plugins/with-plugins.ts +10 -14
  33. package/src/editor/relay-machine.ts +0 -4
  34. package/src/editor/sync-machine.ts +2 -2
  35. package/src/editor.ts +0 -4
  36. package/src/history/behavior.operation.history.redo.ts +67 -0
  37. package/src/history/behavior.operation.history.undo.ts +71 -0
  38. package/src/history/event.history.undo.test.tsx +672 -0
  39. package/src/history/history.preserving-keys.test.tsx +112 -0
  40. package/src/history/remote-patches.ts +20 -0
  41. package/src/history/slate-plugin.history.ts +146 -0
  42. package/src/history/slate-plugin.redoing.ts +21 -0
  43. package/src/history/slate-plugin.undoing.ts +21 -0
  44. package/src/history/slate-plugin.without-history.ts +23 -0
  45. package/src/history/transform-operation.ts +245 -0
  46. package/src/history/undo-redo-collaboration.test.tsx +541 -0
  47. package/src/history/undo-redo.feature +125 -0
  48. package/src/history/undo-redo.test.tsx +195 -0
  49. package/src/history/undo-step.ts +148 -0
  50. package/src/index.ts +0 -1
  51. package/src/operations/behavior.operations.ts +2 -4
  52. package/src/plugins/index.ts +0 -3
  53. package/src/selectors/index.ts +0 -3
  54. package/src/test/vitest/step-definitions.tsx +55 -0
  55. package/src/test/vitest/test-editor.tsx +1 -1
  56. package/lib/_chunks-es/selector.get-selection-text.js +0 -92
  57. package/lib/_chunks-es/selector.get-selection-text.js.map +0 -1
  58. package/lib/_chunks-es/selector.get-text-before.js +0 -36
  59. package/lib/_chunks-es/selector.get-text-before.js.map +0 -1
  60. package/lib/_chunks-es/util.get-text-block-text.js.map +0 -1
  61. package/lib/_chunks-es/util.is-empty-text-block.js +0 -40
  62. package/lib/_chunks-es/util.is-empty-text-block.js.map +0 -1
  63. package/lib/_chunks-es/util.merge-text-blocks.js +0 -101
  64. package/lib/_chunks-es/util.merge-text-blocks.js.map +0 -1
  65. package/src/editor/plugins/createWithMaxBlocks.ts +0 -53
  66. package/src/editor/plugins/createWithUndoRedo.ts +0 -628
  67. package/src/editor/with-undo-step.ts +0 -37
  68. package/src/editor/withUndoRedo.ts +0 -34
  69. package/src/editor-event-listener.tsx +0 -28
  70. package/src/plugins/plugin.decorator-shortcut.ts +0 -238
  71. package/src/plugins/plugin.markdown.test.tsx +0 -42
  72. package/src/plugins/plugin.markdown.tsx +0 -131
  73. package/src/plugins/plugin.one-line.tsx +0 -123
  74. package/src/selectors/selector.get-list-state.test.ts +0 -189
  75. package/src/selectors/selector.get-list-state.ts +0 -96
  76. package/src/selectors/selector.get-selected-slice.ts +0 -13
  77. package/src/selectors/selector.get-trimmed-selection.test.ts +0 -657
  78. package/src/selectors/selector.get-trimmed-selection.ts +0 -189
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.get-text-block-text.js","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.selection-point.ts","../../src/utils/util.block-offset.ts","../../src/utils/asserters.ts","../../src/utils/parse-blocks.ts","../../src/utils/key-generator.ts","../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.slice-blocks.ts","../../src/utils/util.get-text-block-text.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint: {path: ChildPath; offset: number} | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const spanKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nexport function parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key === '_type' ||\n key === '_key' ||\n key === 'children' ||\n key === 'markDefs' ||\n key === 'style' ||\n key === 'listItem' ||\n key === 'level'\n ) {\n continue\n }\n\n if (options.validateFields) {\n if (context.schema.block.fields?.some((field) => field.name === key)) {\n customFields[key] = block[key]\n }\n } else {\n customFields[key] = block[key]\n }\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key =\n typeof block._key === 'string' ? block._key : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n const marks = children.flatMap((child) => child.marks ?? [])\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: options.removeUnusedMarkDefs\n ? markDefs.filter((markDef) => marks.includes(markDef._key))\n : markDefs,\n ...customFields,\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: typeof span._key === 'string' ? span._key : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {validateFields: boolean}\n}): PortableTextObject {\n const {_type, _key, ...customFields} = object\n\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = options.validateFields\n ? context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n : customFields\n\n return {\n _type: context.schemaType.name,\n _key:\n typeof object._key === 'string' ? object._key : context.keyGenerator(),\n ...values,\n }\n}\n","/**\n * @public\n */\nexport const defaultKeyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {defaultKeyGenerator} from './key-generator'\nimport {parseBlock} from './parse-blocks'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (block._key === endBlockKey && startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(\n parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n }) ?? block,\n )\n }\n }\n\n const parsedStartBlock = startBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: startBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n const parsedEndBlock = endBlock\n ? parseBlock({\n context: {\n ...context,\n keyGenerator: defaultKeyGenerator,\n },\n block: endBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n : undefined\n\n return [\n ...(parsedStartBlock ? [parsedStartBlock] : []),\n ...middleBlocks,\n ...(parsedEndBlock ? [parsedEndBlock] : []),\n ]\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n"],"names":["getBlockStartPoint","context","block","isTextBlock","node","path","_key","children","offset","isKeyedSegment","segment","getBlockKeyFromSelectionPoint","point","blockPathSegment","at","getChildKeyFromSelectionPoint","childPathSegment","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","selectionPoint","skippedInlineObject","value","child","isSpan","text","length","spanSelectionPointToBlockOffset","blockKey","spanKey","isTypedObject","object","isRecord","_type","parseBlocks","blocks","options","Array","isArray","flatMap","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","level","undefined","listItem","customFields","key","Object","keys","validateFields","fields","some","field","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","map","parseSpan","span","parseInlineObject","inlineObject","filter","marks","removeUnusedMarkDefs","includes","style","styles","defaultStyle","console","error","lists","list","mark","markDefKey","get","decorators","decorator","inlineObjects","parseAnnotation","annotation","values","reduce","fieldValues","fieldValue","defaultKeyGenerator","randomKey","getByteHexTable","table","i","toString","slice","whatwgRNG","rnds8","Uint8Array","crypto","getRandomValues","str","n","getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","sliceBlocks","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","startChildKey","endBlockKey","endChildKey","push","parsedStartBlock","parsedEndBlock","getTextBlockText","join"],"mappings":";AASO,SAASA,mBAAmB;AAAA,EACjCC;AAAAA,EACAC;AAOF,GAAyB;AACvB,SAAIC,YAAYF,SAASC,MAAME,IAAI,IAC1B;AAAA,IACLC,MAAM,CAAC,GAAGH,MAAMG,MAAM,YAAY;AAAA,MAACC,MAAMJ,MAAME,KAA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AAA,IAEhBnG,OAAOwH;AAAAA,IACPrF,SAAS;AAAA,MAAC2C,sBAAsB;AAAA,MAAMnB,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D,IACDN,QAEE8E,iBAAiBT,WACnBlF,WAAW;AAAA,IACTzC,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHmD,cAAciD;AAAAA,IAAAA;AAAAA,IAEhBnG,OAAO0H;AAAAA,IACPvF,SAAS;AAAA,MAAC2C,sBAAsB;AAAA,MAAMnB,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D,IACDN;AAEJ,SAAO,CACL,GAAI6E,mBAAmB,CAACA,gBAAgB,IAAI,CAAA,GAC5C,GAAGT,cACH,GAAIU,iBAAiB,CAACA,cAAc,IAAI,CAAA,CAAG;AAE/C;ACzMO,SAASC,iBAAiBpI,OAA8B;AAC7D,SAAOA,MAAMK,SAASkE,IAAKjD,CAAAA,UAAUA,MAAME,QAAQ,EAAE,EAAE6G,KAAK,EAAE;AAChE;"}
@@ -1,40 +0,0 @@
1
- import { isTextBlock, isSpan } from "@portabletext/schema";
2
- import { getTextBlockText } from "./util.get-text-block-text.js";
3
- function getBlockEndPoint({
4
- context,
5
- block
6
- }) {
7
- if (isTextBlock(context, block.node)) {
8
- const lastChild = block.node.children[block.node.children.length - 1];
9
- if (lastChild)
10
- return {
11
- path: [...block.path, "children", {
12
- _key: lastChild._key
13
- }],
14
- offset: isSpan(context, lastChild) ? lastChild.text.length : 0
15
- };
16
- }
17
- return {
18
- path: block.path,
19
- offset: 0
20
- };
21
- }
22
- function isSelectionCollapsed(selection) {
23
- return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
24
- }
25
- function isEqualSelectionPoints(a, b) {
26
- return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
27
- }
28
- function isEmptyTextBlock(context, block) {
29
- if (!isTextBlock(context, block))
30
- return !1;
31
- const onlyText = block.children.every((child) => isSpan(context, child)), blockText = getTextBlockText(block);
32
- return onlyText && blockText === "";
33
- }
34
- export {
35
- getBlockEndPoint,
36
- isEmptyTextBlock,
37
- isEqualSelectionPoints,
38
- isSelectionCollapsed
39
- };
40
- //# sourceMappingURL=util.is-empty-text-block.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.is-empty-text-block.js","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isSelectionCollapsed","selection","JSON","stringify","anchor","focus","isEqualSelectionPoints","a","b","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText"],"mappings":";;AASO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,YAAYF,SAASC,MAAME,IAAI,GAAG;AACpC,UAAMC,YAAYH,MAAME,KAAKE,SAASJ,MAAME,KAAKE,SAASC,SAAS,CAAC;AAEpE,QAAIF;AACF,aAAO;AAAA,QACLG,MAAM,CAAC,GAAGN,MAAMM,MAAM,YAAY;AAAA,UAACC,MAAMJ,UAAUI;AAAAA,QAAAA,CAAK;AAAA,QACxDC,QAAQC,OAAOV,SAASI,SAAS,IAAIA,UAAUO,KAAKL,SAAS;AAAA,MAAA;AAAA,EAGnE;AAEA,SAAO;AAAA,IACLC,MAAMN,MAAMM;AAAAA,IACZE,QAAQ;AAAA,EAAA;AAEZ;AC7BO,SAASG,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHC,KAAKC,UAAUF,UAAUG,OAAOT,IAAI,MAClCO,KAAKC,UAAUF,UAAUI,MAAMV,IAAI,KACrCM,UAAUG,OAAOP,WAAWI,UAAUI,MAAMR,SANrC;AAQX;ACVO,SAASS,uBACdC,GACAC,GACA;AACA,SACED,EAAEV,WAAWW,EAAEX,UAAUK,KAAKC,UAAUI,EAAEZ,IAAI,MAAMO,KAAKC,UAAUK,EAAEb,IAAI;AAE7E;ACJO,SAASc,iBACdrB,SACAC,OACA;AACA,MAAI,CAACC,YAAYF,SAASC,KAAK;AAC7B,WAAO;AAGT,QAAMqB,WAAWrB,MAAMI,SAASkB,MAAOC,CAAAA,UAAUd,OAAOV,SAASwB,KAAK,CAAC,GACjEC,YAAYC,iBAAiBzB,KAAK;AAExC,SAAOqB,YAAYG,cAAc;AACnC;"}
@@ -1,101 +0,0 @@
1
- import { blockOffsetToSpanSelectionPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, parseBlock } from "./util.get-text-block-text.js";
2
- import { isTextBlock, isSpan } from "@portabletext/schema";
3
- function blockOffsetToBlockSelectionPoint({
4
- context,
5
- blockOffset
6
- }) {
7
- let selectionPoint;
8
- for (const block of context.value)
9
- if (block._key === blockOffset.path[0]._key) {
10
- selectionPoint = {
11
- path: [{
12
- _key: block._key
13
- }],
14
- offset: blockOffset.offset
15
- };
16
- break;
17
- }
18
- return selectionPoint;
19
- }
20
- function blockOffsetToSelectionPoint({
21
- context,
22
- blockOffset,
23
- direction
24
- }) {
25
- return blockOffsetToSpanSelectionPoint({
26
- context,
27
- blockOffset,
28
- direction
29
- }) || blockOffsetToBlockSelectionPoint({
30
- context,
31
- blockOffset
32
- });
33
- }
34
- function blockOffsetsToSelection({
35
- context,
36
- offsets,
37
- backward
38
- }) {
39
- const anchor = blockOffsetToSelectionPoint({
40
- context,
41
- blockOffset: offsets.anchor,
42
- direction: backward ? "backward" : "forward"
43
- }), focus = blockOffsetToSelectionPoint({
44
- context,
45
- blockOffset: offsets.focus,
46
- direction: backward ? "forward" : "backward"
47
- });
48
- return !anchor || !focus ? null : {
49
- anchor,
50
- focus,
51
- backward
52
- };
53
- }
54
- function childSelectionPointToBlockOffset({
55
- context,
56
- selectionPoint
57
- }) {
58
- let offset = 0;
59
- const blockKey = getBlockKeyFromSelectionPoint(selectionPoint), childKey = getChildKeyFromSelectionPoint(selectionPoint);
60
- if (!(!blockKey || !childKey)) {
61
- for (const block of context.value)
62
- if (block._key === blockKey && isTextBlock(context, block))
63
- for (const child of block.children) {
64
- if (child._key === childKey)
65
- return {
66
- path: [{
67
- _key: block._key
68
- }],
69
- offset: offset + selectionPoint.offset
70
- };
71
- isSpan(context, child) && (offset += child.text.length);
72
- }
73
- }
74
- }
75
- function mergeTextBlocks({
76
- context,
77
- targetBlock,
78
- incomingBlock
79
- }) {
80
- const parsedIncomingBlock = parseBlock({
81
- context,
82
- block: incomingBlock,
83
- options: {
84
- removeUnusedMarkDefs: !0,
85
- validateFields: !1
86
- }
87
- });
88
- return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
89
- ...targetBlock,
90
- children: [...targetBlock.children, ...parsedIncomingBlock.children],
91
- markDefs: [...targetBlock.markDefs ?? [], ...parsedIncomingBlock.markDefs ?? []]
92
- };
93
- }
94
- export {
95
- blockOffsetToBlockSelectionPoint,
96
- blockOffsetToSelectionPoint,
97
- blockOffsetsToSelection,
98
- childSelectionPointToBlockOffset,
99
- mergeTextBlocks
100
- };
101
- //# sourceMappingURL=util.merge-text-blocks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.merge-text-blocks.js","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n}: {\n context: Pick<EditorContext, 'value'>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of context.value) {\n if (block._key === blockOffset.path[0]._key) {\n selectionPoint = {\n path: [{_key: block._key}],\n offset: blockOffset.offset,\n }\n break\n }\n }\n\n return selectionPoint\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n context,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n context,\n offsets,\n backward,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n context,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n const childKey = getChildKeyFromSelectionPoint(selectionPoint)\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isSpan(context, child)) {\n offset += child.text.length\n }\n }\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {parseBlock} from './parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["blockOffsetToBlockSelectionPoint","context","blockOffset","selectionPoint","block","value","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","getBlockKeyFromSelectionPoint","childKey","getChildKeyFromSelectionPoint","isTextBlock","child","children","isSpan","text","length","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","removeUnusedMarkDefs","validateFields","markDefs"],"mappings":";;AAOO,SAAS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mBAAWmB,SAASnB,MAAMoB,UAAU;AAClC,cAAID,MAAMjB,SAASc;AACjB,mBAAO;AAAA,cACLb,MAAM,CAAC;AAAA,gBAACD,MAAMF,MAAME;AAAAA,cAAAA,CAAK;AAAA,cACzBE,QAAQA,SAASL,eAAeK;AAAAA,YAAAA;AAIhCiB,iBAAOxB,SAASsB,KAAK,MACvBf,UAAUe,MAAMG,KAAKC;AAAAA,QAEzB;AAAA;AAEJ;AC1CO,SAASC,gBAAgB;AAAA,EAC9B3B;AAAAA,EACA4B;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrC/B;AAAAA,IACAG,OAAO0B;AAAAA,IACPG,SAAS;AAAA,MAACC,sBAAsB;AAAA,MAAMC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D;AAED,SAAI,CAACJ,uBAAuB,CAACT,YAAYrB,SAAS8B,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHL,UAAU,CAAC,GAAGK,YAAYL,UAAU,GAAGO,oBAAoBP,QAAQ;AAAA,IACnEY,UAAU,CACR,GAAIP,YAAYO,YAAY,CAAA,GAC5B,GAAIL,oBAAoBK,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;"}
@@ -1,53 +0,0 @@
1
- import type {PortableTextSlateEditor} from '../../types/editor'
2
- import type {EditorActor} from '../editor-machine'
3
- import {isChangingRemotely} from '../withChanges'
4
- import {isRedoing, isUndoing} from '../withUndoRedo'
5
-
6
- /**
7
- * This plugin makes sure that the PTE maxBlocks prop is respected
8
- *
9
- */
10
- export function createWithMaxBlocks(editorActor: EditorActor) {
11
- return function withMaxBlocks(
12
- editor: PortableTextSlateEditor,
13
- ): PortableTextSlateEditor {
14
- const {apply} = editor
15
- editor.apply = (operation) => {
16
- if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
17
- apply(operation)
18
- return
19
- }
20
-
21
- /**
22
- * We don't want to run any side effects when the editor is processing
23
- * remote changes.
24
- */
25
- if (isChangingRemotely(editor)) {
26
- apply(operation)
27
- return
28
- }
29
-
30
- /**
31
- * We don't want to run any side effects when the editor is undoing or
32
- * redoing operations.
33
- */
34
- if (isUndoing(editor) || isRedoing(editor)) {
35
- apply(operation)
36
- return
37
- }
38
-
39
- const rows = editorActor.getSnapshot().context.maxBlocks ?? -1
40
- if (rows > 0 && editor.children.length >= rows) {
41
- if (
42
- (operation.type === 'insert_node' ||
43
- operation.type === 'split_node') &&
44
- operation.path.length === 1
45
- ) {
46
- return
47
- }
48
- }
49
- apply(operation)
50
- }
51
- return editor
52
- }
53
- }