@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.
Files changed (120) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +20 -8
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +99 -68
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +41 -45
  10. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  11. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
  12. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
  16. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  17. package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
  18. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  19. package/lib/_chunks-es/behavior.core.js +21 -10
  20. package/lib/_chunks-es/behavior.core.js.map +1 -1
  21. package/lib/_chunks-es/behavior.markdown.js +5 -6
  22. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  23. package/lib/_chunks-es/editor-provider.js +75 -45
  24. package/lib/_chunks-es/editor-provider.js.map +1 -1
  25. package/lib/_chunks-es/selector.get-text-before.js +7 -4
  26. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  27. package/lib/_chunks-es/selector.is-overlapping-selection.js +43 -47
  28. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  29. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
  30. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  31. package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
  32. package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
  33. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  34. package/lib/_chunks-es/util.slice-blocks.js +258 -38
  35. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  36. package/lib/behaviors/index.d.cts +5 -5
  37. package/lib/behaviors/index.d.ts +5 -5
  38. package/lib/index.cjs +45 -21
  39. package/lib/index.cjs.map +1 -1
  40. package/lib/index.js +44 -21
  41. package/lib/index.js.map +1 -1
  42. package/lib/plugins/index.cjs +16 -7
  43. package/lib/plugins/index.cjs.map +1 -1
  44. package/lib/plugins/index.js +16 -7
  45. package/lib/plugins/index.js.map +1 -1
  46. package/lib/selectors/index.cjs +3 -3
  47. package/lib/selectors/index.cjs.map +1 -1
  48. package/lib/selectors/index.d.cts +2 -6
  49. package/lib/selectors/index.d.ts +2 -6
  50. package/lib/selectors/index.js +5 -5
  51. package/lib/selectors/index.js.map +1 -1
  52. package/lib/utils/index.cjs +30 -24
  53. package/lib/utils/index.cjs.map +1 -1
  54. package/lib/utils/index.d.cts +37 -31
  55. package/lib/utils/index.d.ts +37 -31
  56. package/lib/utils/index.js +30 -24
  57. package/lib/utils/index.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
  60. package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
  61. package/src/behaviors/behavior.abstract.decorator.ts +1 -1
  62. package/src/behaviors/behavior.abstract.delete.ts +1 -1
  63. package/src/behaviors/behavior.abstract.insert.ts +2 -2
  64. package/src/behaviors/behavior.abstract.select.ts +16 -4
  65. package/src/behaviors/behavior.abstract.split.ts +9 -6
  66. package/src/behaviors/behavior.core.block-objects.ts +5 -5
  67. package/src/behaviors/behavior.core.insert-break.ts +16 -4
  68. package/src/behaviors/behavior.core.lists.ts +4 -6
  69. package/src/behaviors/behavior.decorator-pair.ts +13 -4
  70. package/src/behaviors/behavior.default.ts +1 -1
  71. package/src/behaviors/behavior.markdown.ts +5 -5
  72. package/src/converters/converter.portable-text.ts +1 -1
  73. package/src/converters/converter.text-html.ts +1 -1
  74. package/src/converters/converter.text-plain.ts +4 -4
  75. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
  76. package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
  77. package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
  78. package/src/internal-utils/drag-selection.ts +16 -4
  79. package/src/internal-utils/event-position.ts +20 -8
  80. package/src/internal-utils/parse-blocks.ts +17 -5
  81. package/src/internal-utils/validateValue.ts +6 -6
  82. package/src/plugins/plugin.decorator-shortcut.ts +2 -2
  83. package/src/selectors/selector.get-active-annotations.ts +5 -2
  84. package/src/selectors/selector.get-active-list-item.ts +4 -3
  85. package/src/selectors/selector.get-active-style.ts +4 -3
  86. package/src/selectors/selector.get-anchor-text-block.ts +3 -6
  87. package/src/selectors/selector.get-block-offsets.ts +2 -2
  88. package/src/selectors/selector.get-caret-word-selection.ts +11 -5
  89. package/src/selectors/selector.get-selected-slice.ts +1 -1
  90. package/src/selectors/selector.get-selected-spans.ts +11 -15
  91. package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
  92. package/src/selectors/selector.get-selection-text.ts +3 -3
  93. package/src/selectors/selector.get-text-before.ts +5 -2
  94. package/src/selectors/selector.get-trimmed-selection.ts +20 -14
  95. package/src/selectors/selector.is-active-annotation.ts +4 -2
  96. package/src/selectors/selector.is-active-decorator.test.ts +3 -3
  97. package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
  98. package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
  99. package/src/selectors/selector.is-point-after-selection.ts +7 -6
  100. package/src/selectors/selector.is-point-before-selection.ts +7 -6
  101. package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
  102. package/src/selectors/selectors.ts +25 -28
  103. package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
  104. package/src/utils/util.block-offset-to-selection-point.ts +5 -5
  105. package/src/utils/util.block-offset.test.ts +219 -156
  106. package/src/utils/util.block-offset.ts +14 -17
  107. package/src/utils/util.block-offsets-to-selection.ts +5 -5
  108. package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
  109. package/src/utils/util.get-block-end-point.ts +15 -15
  110. package/src/utils/util.get-block-start-point.ts +13 -12
  111. package/src/utils/util.is-empty-text-block.ts +9 -8
  112. package/src/utils/util.selection-point-to-block-offset.ts +4 -4
  113. package/src/utils/util.slice-blocks.test.ts +178 -121
  114. package/src/utils/util.slice-blocks.ts +25 -24
  115. package/src/utils/util.split-text-block.ts +18 -12
  116. package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
  117. package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
  118. package/lib/_chunks-es/parse-blocks.js +0 -206
  119. package/lib/_chunks-es/parse-blocks.js.map +0 -1
  120. 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"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), parseBlocks = require("./parse-blocks.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), 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");
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, types$1, keyGenerator) {
282
+ function validateValue(value, types2, keyGenerator) {
283
283
  let resolution = null, valid = !0;
284
- const validChildTypes = [types$1.span.name, ...types$1.inlineObjects.map((t) => t.name)], validBlockTypes = [types$1.block.name, ...types$1.blockObjects.map((t) => t.name)];
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 = types$1.block.name;
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 && types.isPortableTextTextBlock({
357
+ return !blk._type && util_sliceBlocks.isTextBlock({
358
+ schema: types2
359
+ }, {
358
360
  ...blk,
359
- _type: types$1.block.name
361
+ _type: types2.block.name
360
362
  }) ? (resolution = {
361
363
  patches: [patches.set({
362
364
  ...blk,
363
- _type: types$1.block.name
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 '${types$1.block.name}'`,
368
- action: `Use type '${types$1.block.name}'`,
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: types$1.block.name
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 === types$1.block.name) {
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: types$1.span.name,
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 === types$1.span.name).map((cld) => cld.marks || [])));
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) => !types$1.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === 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 === types$1.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
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 === types$1.span.name && typeof child.text != "string" ? (resolution = {
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
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
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
- blocks: snapshot.context.value,
2215
- selection
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 = parseBlocks.parseBlock({
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
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
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
- blocks: snapshot.context.value,
2282
- selection
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 = parseBlocks.parseBlock({
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
- const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
2340
- return selection ? {
2341
- type: "serialization.success",
2342
- data: util_sliceBlocks.sliceBlocks({
2343
- blocks: snapshot.context.value,
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
- mimeType: "text/plain",
2349
- originEvent: event.originEvent
2350
- } : {
2351
- type: "serialization.failure",
2352
- mimeType: "text/plain",
2353
- originEvent: event.originEvent,
2354
- reason: "No selection"
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 = parseBlocks.parseBlock({
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 = parseBlocks.parseAnnotation({
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 = parseBlocks.parseBlock({
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 (parseBlocks.isTextBlock(context.schema, parsedBlock)) {
3356
- const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlocks.parseBlock({
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 = parseBlocks.parseBlock({
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
- value,
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
- value,
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
- value,
3622
+ context: {
3623
+ ...context,
3624
+ value
3625
+ },
3620
3626
  selectionPoint: editorSelection.anchor
3621
3627
  }) : void 0, focusOffset = editorSelection ? util_selectionPointToBlockOffset.selectionPointToBlockOffset({
3622
- value,
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
- value: newValue,
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 = parseBlocks.parseInlineObject({
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 = parseBlocks.parseBlock({
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) => types.isPortableTextTextBlock(value) && value._type === editorActor.getSnapshot().context.schema.block.name, editor.isTextSpan = (value) => types.isPortableTextSpan(value) && value._type === editorActor.getSnapshot().context.schema.span.name, editor.isListBlock = (value) => types.isPortableTextListBlock(value) && value._type === editorActor.getSnapshot().context.schema.block.name, 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;
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
- value: snapshot.context.value,
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
- value: snapshot.context.value,
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(previousBlock) : util_sliceBlocks.getBlockStartPoint(previousBlock);
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(nextBlock) : util_sliceBlocks.getBlockStartPoint(nextBlock);
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(focusTextBlock), newTextBlockSelection = {
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 = parseBlocks.parseBlock({
6213
+ }, newTextBlock = util_sliceBlocks.parseBlock({
6186
6214
  block: util_sliceBlocks.sliceBlocks({
6187
- blocks: [focusTextBlock.node],
6188
- selection: newTextBlockSelection
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 || !parseBlocks.isTextBlock(snapshot.context.schema, newTextBlock) ? !1 : {
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 = parseBlocks.parseBlock({
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) => parseBlocks.isTextBlock(snapshot.context.schema, block) ? [util_sliceBlocks.getTextBlockText(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;