@portabletext/editor 2.8.0 → 2.8.2

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 (46) hide show
  1. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +10 -4
  2. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
  4. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs +3 -6
  6. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  7. package/lib/_chunks-dts/behavior.types.action.d.cts +27 -31
  8. package/lib/_chunks-dts/behavior.types.action.d.ts +18 -22
  9. package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
  10. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  11. package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
  12. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  13. package/lib/_chunks-es/util.slice-blocks.js +3 -6
  14. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  15. package/lib/index.cjs +28 -51
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.js +28 -51
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.d.cts +3 -3
  20. package/lib/utils/index.d.ts +2 -2
  21. package/package.json +5 -5
  22. package/src/behaviors/behavior.abstract.split.ts +0 -1
  23. package/src/converters/converter.portable-text.ts +0 -1
  24. package/src/converters/converter.text-html.ts +0 -1
  25. package/src/converters/converter.text-plain.ts +0 -1
  26. package/src/editor/Editable.tsx +0 -1
  27. package/src/editor/PortableTextEditor.tsx +1 -1
  28. package/src/editor/plugins/createWithEditableAPI.ts +70 -28
  29. package/src/index.ts +1 -1
  30. package/src/internal-utils/parse-blocks.test.ts +23 -23
  31. package/src/internal-utils/parse-blocks.ts +11 -23
  32. package/src/internal-utils/test-editor.tsx +15 -21
  33. package/src/operations/behavior.operation.annotation.add.ts +2 -47
  34. package/src/operations/behavior.operation.block.set.ts +1 -1
  35. package/src/operations/behavior.operation.block.unset.ts +2 -2
  36. package/src/operations/behavior.operation.insert.block.ts +1 -1
  37. package/src/operations/behavior.operations.ts +1 -2
  38. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
  39. package/src/plugins/plugin.markdown.test.tsx +12 -30
  40. package/src/selectors/selector.get-selected-value.test.ts +748 -0
  41. package/src/selectors/selector.get-selected-value.ts +28 -7
  42. package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
  43. package/src/types/editor.ts +19 -3
  44. package/src/utils/util.merge-text-blocks.ts +1 -1
  45. package/src/utils/util.slice-blocks.ts +3 -3
  46. package/src/utils/util.slice-blocks.test.ts +0 -499
package/lib/index.js CHANGED
@@ -1948,7 +1948,6 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
1948
1948
  },
1949
1949
  blocks: result_1.insert,
1950
1950
  options: {
1951
- refreshKeys: !1,
1952
1951
  validateFields: !1
1953
1952
  }
1954
1953
  }),
@@ -2413,7 +2412,6 @@ const converterJson = {
2413
2412
  context: snapshot.context,
2414
2413
  block,
2415
2414
  options: {
2416
- refreshKeys: !1,
2417
2415
  validateFields: !1
2418
2416
  }
2419
2417
  });
@@ -2476,7 +2474,6 @@ function createConverterTextHtml(legacySchema) {
2476
2474
  context: snapshot.context,
2477
2475
  block,
2478
2476
  options: {
2479
- refreshKeys: !1,
2480
2477
  validateFields: !1
2481
2478
  }
2482
2479
  });
@@ -2524,7 +2521,6 @@ function createConverterTextPlain(legacySchema) {
2524
2521
  context: snapshot.context,
2525
2522
  block,
2526
2523
  options: {
2527
- refreshKeys: !1,
2528
2524
  validateFields: !1
2529
2525
  }
2530
2526
  });
@@ -3987,7 +3983,6 @@ const addAnnotationOperationImplementation = ({
3987
3983
  },
3988
3984
  context,
3989
3985
  options: {
3990
- refreshKeys: !1,
3991
3986
  validateFields: !0
3992
3987
  }
3993
3988
  });
@@ -3996,8 +3991,7 @@ const addAnnotationOperationImplementation = ({
3996
3991
  const editor = operation.editor;
3997
3992
  if (!editor.selection || Range.isCollapsed(editor.selection))
3998
3993
  return;
3999
- let paths, spanPath, markDefPath;
4000
- const markDefPaths = [], selectedBlocks = Editor.nodes(editor, {
3994
+ const selectedBlocks = Editor.nodes(editor, {
4001
3995
  at: editor.selection,
4002
3996
  match: (node) => editor.isTextBlock(node),
4003
3997
  reverse: Range.isBackward(editor.selection)
@@ -4007,18 +4001,14 @@ const addAnnotationOperationImplementation = ({
4007
4001
  if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
4008
4002
  continue;
4009
4003
  const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
4010
- markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
4004
+ markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && Transforms.setNodes(editor, {
4011
4005
  markDefs: [...markDefs, {
4012
4006
  ...parsedAnnotation,
4013
4007
  _key: annotationKey
4014
4008
  }]
4015
4009
  }, {
4016
4010
  at: blockPath
4017
- }), markDefPath = [{
4018
- _key: block._key
4019
- }, "markDefs", {
4020
- _key: annotationKey
4021
- }], Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), Transforms.setNodes(editor, {}, {
4011
+ }), Transforms.setNodes(editor, {}, {
4022
4012
  match: Text.isText,
4023
4013
  split: !0
4024
4014
  });
@@ -4031,19 +4021,10 @@ const addAnnotationOperationImplementation = ({
4031
4021
  marks: [...marks, annotationKey]
4032
4022
  }, {
4033
4023
  at: path
4034
- }), spanPath = [{
4035
- _key: block._key
4036
- }, "children", {
4037
- _key: span._key
4038
- }];
4024
+ });
4039
4025
  }
4040
4026
  blockIndex++;
4041
4027
  }
4042
- return markDefPath && spanPath && (paths = {
4043
- markDefPath,
4044
- markDefPaths,
4045
- spanPath
4046
- }), paths;
4047
4028
  }, removeAnnotationOperationImplementation = ({
4048
4029
  operation
4049
4030
  }) => {
@@ -4150,7 +4131,6 @@ const addAnnotationOperationImplementation = ({
4150
4131
  ...filteredProps
4151
4132
  },
4152
4133
  options: {
4153
- refreshKeys: !1,
4154
4134
  validateFields: !0
4155
4135
  }
4156
4136
  });
@@ -4200,7 +4180,6 @@ const addAnnotationOperationImplementation = ({
4200
4180
  context,
4201
4181
  block: omit(parsedBlock, propsToRemove),
4202
4182
  options: {
4203
- refreshKeys: !1,
4204
4183
  validateFields: !0
4205
4184
  }
4206
4185
  });
@@ -4218,7 +4197,6 @@ const addAnnotationOperationImplementation = ({
4218
4197
  context,
4219
4198
  block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
4220
4199
  options: {
4221
- refreshKeys: !1,
4222
4200
  validateFields: !0
4223
4201
  }
4224
4202
  });
@@ -4607,7 +4585,6 @@ const insertBlockOperationImplementation = ({
4607
4585
  block: operation.block,
4608
4586
  context,
4609
4587
  options: {
4610
- refreshKeys: !1,
4611
4588
  validateFields: !0
4612
4589
  }
4613
4590
  });
@@ -8880,7 +8857,6 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
8880
8857
  }),
8881
8858
  context: snapshot.context,
8882
8859
  options: {
8883
- refreshKeys: !1,
8884
8860
  validateFields: !1
8885
8861
  }
8886
8862
  });
@@ -10327,37 +10303,38 @@ function createEditableAPI(editor, editorActor) {
10327
10303
  return isActiveAnnotation(annotationType)(snapshot);
10328
10304
  },
10329
10305
  addAnnotation: (type, value) => {
10330
- let paths;
10331
- const snapshot = getEditorSnapshot({
10306
+ const snapshotBefore = getEditorSnapshot({
10332
10307
  editorActorSnapshot: editorActor.getSnapshot(),
10333
10308
  slateEditorInstance: editor
10334
- });
10335
- return isActiveAnnotation(type.name, {
10336
- mode: "partial"
10337
- })(snapshot) && editorActor.send({
10309
+ }), selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan$1(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
10310
+ editorActor.send({
10338
10311
  type: "behavior event",
10339
10312
  behaviorEvent: {
10340
- type: "annotation.remove",
10313
+ type: "annotation.add",
10341
10314
  annotation: {
10342
- name: type.name
10315
+ name: type.name,
10316
+ value: value ?? {}
10343
10317
  }
10344
10318
  },
10345
10319
  editor
10346
- }), Editor.withoutNormalizing(editor, () => {
10347
- paths = addAnnotationOperationImplementation({
10348
- context: {
10349
- keyGenerator: editorActor.getSnapshot().context.keyGenerator,
10350
- schema: types
10351
- },
10352
- operation: {
10353
- annotation: {
10354
- name: type.name,
10355
- value: value ?? {}
10356
- },
10357
- editor
10358
- }
10359
- });
10360
- }), editor.onChange(), paths;
10320
+ });
10321
+ const snapshotAfter = getEditorSnapshot({
10322
+ editorActorSnapshot: editorActor.getSnapshot(),
10323
+ slateEditorInstance: editor
10324
+ }), selectedValueAfter = getSelectedValue(snapshotAfter), focusBlockAfter = getFocusBlock$1(snapshotAfter), focusSpanAfter = getFocusSpan$1(snapshotAfter), newMarkDefKeysOnFocusSpan = focusSpanAfter?.node.marks?.filter((mark) => !focusSpanBefore?.node.marks?.includes(mark) && !snapshotAfter.context.schema.decorators.map((decorator) => decorator.name).includes(mark)), markDefs = selectedValueAfter.flatMap((block) => isTextBlock(snapshotAfter.context, block) ? block.markDefs?.map((markDef2) => ({
10325
+ markDef: markDef2,
10326
+ path: [{
10327
+ _key: block._key
10328
+ }, "markDefs", {
10329
+ _key: markDef2._key
10330
+ }]
10331
+ })) ?? [] : []).filter((markDef2) => !markDefsBefore.some((markDefBefore) => markDefBefore._key === markDef2.markDef._key)), spanPath = focusSpanAfter?.path, markDef = markDefs.find((markDef2) => newMarkDefKeysOnFocusSpan?.some((mark) => mark === markDef2.markDef._key));
10332
+ if (focusBlockAfter && spanPath && markDef)
10333
+ return {
10334
+ markDefPath: markDef.path,
10335
+ markDefPaths: markDefs.map((markDef2) => markDef2.path),
10336
+ spanPath
10337
+ };
10361
10338
  },
10362
10339
  delete: (selection, options) => {
10363
10340
  if (selection) {