@portabletext/editor 1.40.2 → 1.40.3

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 (58) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +37 -16
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +22 -10
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +27 -67
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +26 -0
  8. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -0
  10. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-es/behavior.core.js +37 -16
  12. package/lib/_chunks-es/behavior.core.js.map +1 -1
  13. package/lib/_chunks-es/behavior.markdown.js +22 -10
  14. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  15. package/lib/_chunks-es/editor-provider.js +27 -67
  16. package/lib/_chunks-es/editor-provider.js.map +1 -1
  17. package/lib/_chunks-es/util.merge-text-blocks.js +27 -0
  18. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -0
  19. package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -0
  20. package/lib/behaviors/index.d.cts +3881 -5053
  21. package/lib/behaviors/index.d.ts +3881 -5053
  22. package/lib/index.d.cts +3402 -4440
  23. package/lib/index.d.ts +3402 -4440
  24. package/lib/plugins/index.cjs +9 -127
  25. package/lib/plugins/index.cjs.map +1 -1
  26. package/lib/plugins/index.d.cts +3404 -4441
  27. package/lib/plugins/index.d.ts +3404 -4441
  28. package/lib/plugins/index.js +11 -129
  29. package/lib/plugins/index.js.map +1 -1
  30. package/lib/selectors/index.d.cts +3401 -4440
  31. package/lib/selectors/index.d.ts +3401 -4440
  32. package/lib/utils/index.cjs +45 -4
  33. package/lib/utils/index.cjs.map +1 -1
  34. package/lib/utils/index.d.cts +3402 -4441
  35. package/lib/utils/index.d.ts +3402 -4441
  36. package/lib/utils/index.js +45 -3
  37. package/lib/utils/index.js.map +1 -1
  38. package/package.json +7 -7
  39. package/src/behavior-actions/behavior.action.delete.block.ts +2 -2
  40. package/src/behavior-actions/behavior.actions.ts +0 -18
  41. package/src/behaviors/behavior.core.block-objects.ts +57 -7
  42. package/src/behaviors/behavior.core.insert-break.ts +0 -4
  43. package/src/behaviors/behavior.default.ts +1 -1
  44. package/src/behaviors/behavior.markdown.ts +22 -10
  45. package/src/behaviors/behavior.types.ts +171 -138
  46. package/src/editor/create-editor.ts +2 -0
  47. package/src/editor/editor-machine.ts +28 -28
  48. package/src/editor/plugins/create-with-event-listeners.ts +15 -0
  49. package/src/editor/plugins/createWithEditableAPI.ts +4 -4
  50. package/src/plugins/plugin.one-line.tsx +10 -128
  51. package/src/types/block-with-optional-key.ts +13 -0
  52. package/src/utils/util.is-text-block.ts +4 -3
  53. package/lib/_chunks-cjs/util.split-text-block.cjs +0 -68
  54. package/lib/_chunks-cjs/util.split-text-block.cjs.map +0 -1
  55. package/lib/_chunks-es/util.split-text-block.js +0 -70
  56. package/lib/_chunks-es/util.split-text-block.js.map +0 -1
  57. package/src/behavior-actions/behavior.action.insert.block-object.ts +0 -20
  58. package/src/behavior-actions/behavior.action.insert.text-block.ts +0 -33
@@ -3731,10 +3731,10 @@ function createEditableAPI(editor, editorActor) {
3731
3731
  insertBlock: (type, value) => (editorActor.send({
3732
3732
  type: "behavior event",
3733
3733
  behaviorEvent: {
3734
- type: "insert.block object",
3735
- blockObject: {
3736
- name: type.name,
3737
- value
3734
+ type: "insert.block",
3735
+ block: {
3736
+ _type: type.name,
3737
+ ...value || {}
3738
3738
  },
3739
3739
  placement: "auto"
3740
3740
  },
@@ -4216,11 +4216,11 @@ const addAnnotationActionImplementation = ({
4216
4216
  }) => {
4217
4217
  const range = toSlateRange({
4218
4218
  anchor: {
4219
- path: action.blockPath,
4219
+ path: action.at,
4220
4220
  offset: 0
4221
4221
  },
4222
4222
  focus: {
4223
- path: action.blockPath,
4223
+ path: action.at,
4224
4224
  offset: 0
4225
4225
  }
4226
4226
  }, action.editor);
@@ -4682,53 +4682,10 @@ const selectActionImplementation = ({
4682
4682
  text: action.text,
4683
4683
  marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
4684
4684
  });
4685
- }, insertBlockObjectActionImplementation = ({
4686
- context,
4687
- action
4688
- }) => {
4689
- insertBlockActionImplementation({
4690
- context,
4691
- action: {
4692
- block: {
4693
- _key: context.keyGenerator(),
4694
- _type: action.blockObject.name,
4695
- ...action.blockObject.value ? action.blockObject.value : {}
4696
- },
4697
- editor: action.editor,
4698
- placement: action.placement
4699
- }
4700
- });
4701
4685
  }, insertTextActionImplementation = ({
4702
4686
  action
4703
4687
  }) => {
4704
4688
  action.editor.insertText(action.text);
4705
- }, insertTextBlockActionImplementation = ({
4706
- context,
4707
- action
4708
- }) => {
4709
- insertBlockActionImplementation({
4710
- context,
4711
- action: {
4712
- block: {
4713
- _key: context.keyGenerator(),
4714
- _type: context.schema.block.name,
4715
- children: action.textBlock?.children?.map((child) => ({
4716
- ...child,
4717
- _key: context.keyGenerator()
4718
- })) ?? [{
4719
- _type: context.schema.span.name,
4720
- _key: context.keyGenerator(),
4721
- text: "",
4722
- marks: []
4723
- }],
4724
- markDefs: [],
4725
- style: context.schema.styles[0].value ?? "normal"
4726
- },
4727
- editor: action.editor,
4728
- placement: action.placement,
4729
- select: "start"
4730
- }
4731
- });
4732
4689
  }, moveBlockActionImplementation = ({
4733
4690
  action
4734
4691
  }) => {
@@ -4834,13 +4791,11 @@ const selectActionImplementation = ({
4834
4791
  "history.undo": historyUndoActionImplementation,
4835
4792
  "insert.block": insertBlockActionImplementation,
4836
4793
  "insert.blocks": insertBlocksActionImplementation,
4837
- "insert.block object": insertBlockObjectActionImplementation,
4838
4794
  "insert.break": insertBreakActionImplementation,
4839
4795
  "insert.inline object": insertInlineObjectActionImplementation,
4840
4796
  "insert.soft break": insertSoftBreakActionImplementation,
4841
4797
  "insert.span": insertSpanActionImplementation,
4842
4798
  "insert.text": insertTextActionImplementation,
4843
- "insert.text block": insertTextBlockActionImplementation,
4844
4799
  effect: effectActionImplementation,
4845
4800
  "list item.add": addListItemActionImplementation,
4846
4801
  "list item.remove": removeListItemActionImplementation,
@@ -5024,13 +4979,6 @@ function performAction({
5024
4979
  });
5025
4980
  break;
5026
4981
  }
5027
- case "insert.block object": {
5028
- behaviorActionImplementations["insert.block object"]({
5029
- context,
5030
- action
5031
- });
5032
- break;
5033
- }
5034
4982
  case "insert.inline object": {
5035
4983
  behaviorActionImplementations["insert.inline object"]({
5036
4984
  context,
@@ -5066,13 +5014,6 @@ function performAction({
5066
5014
  });
5067
5015
  break;
5068
5016
  }
5069
- case "insert.text block": {
5070
- behaviorActionImplementations["insert.text block"]({
5071
- context,
5072
- action
5073
- });
5074
- break;
5075
- }
5076
5017
  case "list item.add": {
5077
5018
  behaviorActionImplementations["list item.add"]({
5078
5019
  context,
@@ -5207,6 +5148,20 @@ function createWithEventListeners(editorActor, subscriptions) {
5207
5148
  editor
5208
5149
  });
5209
5150
  break;
5151
+ case "insert.block object":
5152
+ editorActor.send({
5153
+ type: "behavior event",
5154
+ behaviorEvent: {
5155
+ type: "insert.block",
5156
+ block: {
5157
+ _type: event.blockObject.name,
5158
+ ...event.blockObject.value ?? {}
5159
+ },
5160
+ placement: event.placement
5161
+ },
5162
+ editor
5163
+ });
5164
+ break;
5210
5165
  default:
5211
5166
  editorActor.send({
5212
5167
  type: "behavior event",
@@ -6355,7 +6310,7 @@ const keyIs = {
6355
6310
  originEvent
6356
6311
  }) => [...draggingEntireBlocks ? draggedBlocks.map((block) => behavior_core.raise({
6357
6312
  type: "delete.block",
6358
- blockPath: block.path
6313
+ at: block.path
6359
6314
  })) : [behavior_core.raise({
6360
6315
  type: "delete",
6361
6316
  selection: dragOrigin.selection
@@ -6527,7 +6482,12 @@ const editorMachine = xstate.setup({
6527
6482
  const defaultAction = event.type === "custom behavior event" || behavior_core.isClipboardBehaviorEvent(event.behaviorEvent) || behavior_core.isDragBehaviorEvent(event.behaviorEvent) || behavior_core.isInputBehaviorEvent(event.behaviorEvent) || behavior_core.isKeyboardBehaviorEvent(event.behaviorEvent) || behavior_core.isMouseBehaviorEvent(event.behaviorEvent) || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "serialize" ? void 0 : {
6528
6483
  ...event.behaviorEvent,
6529
6484
  editor: event.editor
6530
- }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => behavior.on === "*" ? !0 : behavior_core.isClipboardBehaviorEvent(event.behaviorEvent) ? behavior.on === "clipboard.*" || behavior.on === event.behaviorEvent.type : behavior_core.isDragBehaviorEvent(event.behaviorEvent) ? behavior.on === "drag.*" || behavior.on === event.behaviorEvent.type : behavior_core.isInputBehaviorEvent(event.behaviorEvent) ? behavior.on === "input.*" : behavior_core.isKeyboardBehaviorEvent(event.behaviorEvent) ? behavior.on === "keyboard.*" || behavior.on === event.behaviorEvent.type : behavior_core.isMouseBehaviorEvent(event.behaviorEvent) && behavior.on === "mouse.*" || behavior.on === event.behaviorEvent.type);
6485
+ }, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values(), ...defaultBehaviors].filter((behavior) => {
6486
+ if (behavior.on === "*")
6487
+ return !0;
6488
+ const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.behaviorEvent.type.includes(".") ? event.behaviorEvent.type.split(".") : [void 0];
6489
+ return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.behaviorEvent.type ? !0 : behavior.on === event.behaviorEvent.type;
6490
+ });
6531
6491
  if (eventBehaviors.length === 0) {
6532
6492
  if (defaultActionCallback) {
6533
6493
  withApplyingBehaviorActions(event.editor, () => {