@portabletext/editor 1.45.4 → 1.47.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 (46) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +20 -0
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +25 -25
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +69 -4
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-es/behavior.core.js +20 -0
  8. package/lib/_chunks-es/behavior.core.js.map +1 -1
  9. package/lib/_chunks-es/behavior.markdown.js +26 -26
  10. package/lib/_chunks-es/behavior.markdown.js.map +1 -1
  11. package/lib/_chunks-es/editor-provider.js +69 -4
  12. package/lib/_chunks-es/editor-provider.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
  14. package/lib/behaviors/index.cjs +37 -53
  15. package/lib/behaviors/index.cjs.map +1 -1
  16. package/lib/behaviors/index.d.cts +546 -1
  17. package/lib/behaviors/index.d.ts +546 -1
  18. package/lib/behaviors/index.js +38 -54
  19. package/lib/behaviors/index.js.map +1 -1
  20. package/lib/index.d.cts +17 -1
  21. package/lib/index.d.ts +17 -1
  22. package/lib/plugins/index.cjs +23 -29
  23. package/lib/plugins/index.cjs.map +1 -1
  24. package/lib/plugins/index.d.cts +17 -1
  25. package/lib/plugins/index.d.ts +17 -1
  26. package/lib/plugins/index.js +24 -30
  27. package/lib/plugins/index.js.map +1 -1
  28. package/lib/selectors/index.d.cts +17 -1
  29. package/lib/selectors/index.d.ts +17 -1
  30. package/lib/utils/index.d.cts +17 -1
  31. package/lib/utils/index.d.ts +17 -1
  32. package/package.json +3 -3
  33. package/src/behavior-actions/behavior.action.move.backward.ts +12 -0
  34. package/src/behavior-actions/behavior.action.move.forward.ts +11 -0
  35. package/src/behavior-actions/behavior.actions.ts +18 -0
  36. package/src/behaviors/behavior.decorator-pair.ts +16 -19
  37. package/src/behaviors/behavior.emoji-picker.ts +26 -45
  38. package/src/behaviors/behavior.links.ts +5 -4
  39. package/src/behaviors/behavior.markdown.ts +37 -34
  40. package/src/behaviors/behavior.perform-event.ts +53 -2
  41. package/src/behaviors/behavior.types.action.ts +38 -7
  42. package/src/behaviors/behavior.types.event.ts +10 -0
  43. package/src/behaviors/index.ts +3 -0
  44. package/src/editor/editor-machine.ts +2 -2
  45. package/src/plugins/plugin.decorator-shortcut.ts +6 -8
  46. package/src/plugins/plugin.one-line.tsx +4 -4
@@ -4010,7 +4010,15 @@ function insertBlock({
4010
4010
  }
4011
4011
  }
4012
4012
  }
4013
- const moveBlockActionImplementation = ({
4013
+ const moveBackwardActionImplementation = ({
4014
+ action
4015
+ }) => {
4016
+ Transforms.move(action.editor, {
4017
+ unit: "character",
4018
+ distance: action.distance,
4019
+ reverse: !0
4020
+ });
4021
+ }, moveBlockActionImplementation = ({
4014
4022
  action
4015
4023
  }) => {
4016
4024
  const at = [toSlatePath(action.at, action.editor)[0]], to = [toSlatePath(action.to, action.editor)[0]];
@@ -4019,6 +4027,13 @@ const moveBlockActionImplementation = ({
4019
4027
  to,
4020
4028
  mode: "highest"
4021
4029
  });
4030
+ }, moveForwardActionImplementation = ({
4031
+ action
4032
+ }) => {
4033
+ Transforms.move(action.editor, {
4034
+ unit: "character",
4035
+ distance: action.distance
4036
+ });
4022
4037
  }, noopActionImplementation = () => {
4023
4038
  }, selectActionImplementation = ({
4024
4039
  action
@@ -4108,7 +4123,9 @@ const moveBlockActionImplementation = ({
4108
4123
  "insert.span": insertSpanActionImplementation,
4109
4124
  "insert.text": insertTextActionImplementation,
4110
4125
  effect: effectActionImplementation,
4126
+ "move.backward": moveBackwardActionImplementation,
4111
4127
  "move.block": moveBlockActionImplementation,
4128
+ "move.forward": moveForwardActionImplementation,
4112
4129
  noop: noopActionImplementation,
4113
4130
  select: selectActionImplementation,
4114
4131
  "split.block": splitBlockActionImplementation
@@ -4251,6 +4268,13 @@ function performAction({
4251
4268
  });
4252
4269
  break;
4253
4270
  }
4271
+ case "move.backward": {
4272
+ behaviorActionImplementations["move.backward"]({
4273
+ context,
4274
+ action
4275
+ });
4276
+ break;
4277
+ }
4254
4278
  case "move.block": {
4255
4279
  behaviorActionImplementations["move.block"]({
4256
4280
  context,
@@ -4258,6 +4282,13 @@ function performAction({
4258
4282
  });
4259
4283
  break;
4260
4284
  }
4285
+ case "move.forward": {
4286
+ behaviorActionImplementations["move.forward"]({
4287
+ context,
4288
+ action
4289
+ });
4290
+ break;
4291
+ }
4261
4292
  case "noop":
4262
4293
  break;
4263
4294
  case "split.block": {
@@ -5993,6 +6024,7 @@ function eventCategory(event) {
5993
6024
  return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
5994
6025
  }
5995
6026
  function performEvent({
6027
+ mode,
5996
6028
  behaviors,
5997
6029
  event,
5998
6030
  editor,
@@ -6006,7 +6038,7 @@ function performEvent({
6006
6038
  const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
6007
6039
  ...event,
6008
6040
  editor
6009
- }, eventBehaviors = behaviors.filter((behavior) => {
6041
+ }, eventBehaviors = (mode === "raise" ? [...behaviors, ...defaultBehaviors] : behaviors).filter((behavior) => {
6010
6042
  if (behavior.on === "*")
6011
6043
  return !0;
6012
6044
  const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
@@ -6057,7 +6089,8 @@ function performEvent({
6057
6089
  for (const action of actions) {
6058
6090
  if (action.type === "raise") {
6059
6091
  performEvent({
6060
- behaviors,
6092
+ mode,
6093
+ behaviors: mode === "execute" ? isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors : [...behaviors, ...defaultBehaviors],
6061
6094
  event: action.event,
6062
6095
  editor,
6063
6096
  keyGenerator,
@@ -6068,6 +6101,37 @@ function performEvent({
6068
6101
  });
6069
6102
  continue;
6070
6103
  }
6104
+ if (action.type === "execute") {
6105
+ if (isAbstractBehaviorEvent(action.event) || isCustomBehaviorEvent(action.event))
6106
+ performEvent({
6107
+ mode: "execute",
6108
+ behaviors: isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors,
6109
+ event: action.event,
6110
+ editor,
6111
+ keyGenerator,
6112
+ schema,
6113
+ getSnapshot,
6114
+ defaultActionCallback: void 0,
6115
+ nativeEvent: void 0
6116
+ });
6117
+ else
6118
+ try {
6119
+ performAction({
6120
+ context: {
6121
+ keyGenerator,
6122
+ schema
6123
+ },
6124
+ action: {
6125
+ ...action.event,
6126
+ editor
6127
+ }
6128
+ });
6129
+ } catch (error) {
6130
+ console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6131
+ break;
6132
+ }
6133
+ continue;
6134
+ }
6071
6135
  const internalAction = {
6072
6136
  ...action,
6073
6137
  editor
@@ -6269,7 +6333,8 @@ const editorMachine = setup({
6269
6333
  self
6270
6334
  }) => {
6271
6335
  assertEvent(event, ["behavior event"]), performEvent({
6272
- behaviors: [...context.behaviors.values(), ...defaultBehaviors],
6336
+ mode: "raise",
6337
+ behaviors: [...context.behaviors.values()],
6273
6338
  event: event.behaviorEvent,
6274
6339
  editor: event.editor,
6275
6340
  keyGenerator: context.keyGenerator,