@portabletext/editor 1.45.3 → 1.46.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 (45) 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 +93 -59
  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 +93 -59
  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 +52 -37
  17. package/lib/behaviors/index.d.ts +52 -37
  18. package/lib/behaviors/index.js +38 -54
  19. package/lib/behaviors/index.js.map +1 -1
  20. package/lib/index.d.cts +33 -37
  21. package/lib/index.d.ts +33 -37
  22. package/lib/plugins/index.cjs +23 -29
  23. package/lib/plugins/index.cjs.map +1 -1
  24. package/lib/plugins/index.d.cts +33 -37
  25. package/lib/plugins/index.d.ts +33 -37
  26. package/lib/plugins/index.js +24 -30
  27. package/lib/plugins/index.js.map +1 -1
  28. package/lib/selectors/index.d.cts +33 -37
  29. package/lib/selectors/index.d.ts +33 -37
  30. package/lib/utils/index.d.cts +33 -37
  31. package/lib/utils/index.d.ts +33 -37
  32. package/package.json +1 -1
  33. package/src/behaviors/behavior.decorator-pair.ts +16 -19
  34. package/src/behaviors/behavior.emoji-picker.ts +26 -45
  35. package/src/behaviors/behavior.links.ts +5 -4
  36. package/src/behaviors/behavior.markdown.ts +37 -34
  37. package/src/behaviors/behavior.perform-event.ts +67 -18
  38. package/src/behaviors/behavior.types.action.ts +39 -13
  39. package/src/behaviors/behavior.types.guard.ts +1 -6
  40. package/src/behaviors/index.ts +3 -0
  41. package/src/editor/components/Synchronizer.tsx +6 -3
  42. package/src/editor/create-editor.ts +1 -1
  43. package/src/editor/editor-machine.ts +8 -6
  44. package/src/plugins/plugin.decorator-shortcut.ts +6 -8
  45. package/src/plugins/plugin.one-line.tsx +4 -4
@@ -2038,7 +2038,7 @@ function Synchronizer(props) {
2038
2038
  const $ = reactCompilerRuntime.c(41), {
2039
2039
  editorActor,
2040
2040
  slateEditor
2041
- } = props, value = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
2041
+ } = props, incomingValue = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
2042
2042
  let t0;
2043
2043
  $[0] !== props.editorActor ? (t0 = props.editorActor.getSnapshot(), $[0] = props.editorActor, $[1] = t0) : t0 = $[1];
2044
2044
  const t1 = t0.context.keyGenerator;
@@ -2128,12 +2128,12 @@ function Synchronizer(props) {
2128
2128
  });
2129
2129
  }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
2130
2130
  let t13, t14;
2131
- $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2131
+ $[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
2132
2132
  debug$d("Value from props changed, syncing new value"), syncActorRef.send({
2133
2133
  type: "update value",
2134
- value
2134
+ value: incomingValue
2135
2135
  });
2136
- }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
2136
+ }, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
2137
2137
  let t15;
2138
2138
  $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2139
2139
  debug$d("Subscribing to patch events");
@@ -2156,7 +2156,7 @@ function _temp2(s_0) {
2156
2156
  });
2157
2157
  }
2158
2158
  function _temp(s) {
2159
- return s.context.value;
2159
+ return s.context.incomingValue;
2160
2160
  }
2161
2161
  Synchronizer.displayName = "Synchronizer";
2162
2162
  const converterJson = {
@@ -5967,6 +5967,7 @@ function eventCategory(event) {
5967
5967
  return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
5968
5968
  }
5969
5969
  function performEvent({
5970
+ mode,
5970
5971
  behaviors,
5971
5972
  event,
5972
5973
  editor,
@@ -5980,7 +5981,7 @@ function performEvent({
5980
5981
  const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
5981
5982
  ...event,
5982
5983
  editor
5983
- }, eventBehaviors = behaviors.filter((behavior) => {
5984
+ }, eventBehaviors = (mode === "raise" ? [...behaviors, ...defaultBehaviors] : behaviors).filter((behavior) => {
5984
5985
  if (behavior.on === "*")
5985
5986
  return !0;
5986
5987
  const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
@@ -6007,65 +6008,97 @@ function performEvent({
6007
6008
  schema: schema2
6008
6009
  },
6009
6010
  action: defaultAction
6010
- });
6011
+ }), editor.onChange();
6011
6012
  } catch (error) {
6012
6013
  console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6013
6014
  }
6014
- }), editor.onChange();
6015
+ });
6015
6016
  return;
6016
6017
  }
6017
- const editorSnapshot = getSnapshot();
6018
+ const guardSnapshot = getSnapshot();
6018
6019
  let behaviorOverwritten = !1;
6019
6020
  for (const eventBehavior of eventBehaviors) {
6020
6021
  const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
6021
- context: editorSnapshot.context,
6022
- snapshot: editorSnapshot,
6022
+ snapshot: guardSnapshot,
6023
6023
  event
6024
6024
  });
6025
- if (!shouldRun)
6026
- continue;
6027
- const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
6028
- context: editorSnapshot.context,
6029
- snapshot: editorSnapshot,
6030
- event
6031
- }, shouldRun));
6032
- for (const actionSet of actionSets)
6033
- actionSet.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
6034
- for (const action of actionSet) {
6035
- if (action.type === "raise") {
6036
- performEvent({
6037
- behaviors,
6038
- event: action.event,
6039
- editor,
6040
- keyGenerator,
6041
- schema: schema2,
6042
- getSnapshot,
6043
- defaultActionCallback: void 0,
6044
- nativeEvent: void 0
6045
- });
6046
- continue;
6047
- }
6048
- const internalAction = {
6049
- ...action,
6050
- editor
6051
- };
6052
- try {
6053
- performAction({
6054
- context: {
6025
+ if (shouldRun) {
6026
+ for (const actionSet of eventBehavior.actions) {
6027
+ const actionsSnapshot = getSnapshot(), actions = actionSet({
6028
+ snapshot: actionsSnapshot,
6029
+ event
6030
+ }, shouldRun);
6031
+ actions.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actions.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
6032
+ for (const action of actions) {
6033
+ if (action.type === "raise") {
6034
+ performEvent({
6035
+ mode,
6036
+ behaviors: mode === "execute" ? isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors : [...behaviors, ...defaultBehaviors],
6037
+ event: action.event,
6038
+ editor,
6055
6039
  keyGenerator,
6056
- schema: schema2
6057
- },
6058
- action: internalAction
6059
- });
6060
- } catch (error) {
6061
- console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6062
- break;
6040
+ schema: schema2,
6041
+ getSnapshot,
6042
+ defaultActionCallback: void 0,
6043
+ nativeEvent: void 0
6044
+ });
6045
+ continue;
6046
+ }
6047
+ if (action.type === "execute") {
6048
+ if (isAbstractBehaviorEvent(action.event) || isCustomBehaviorEvent(action.event))
6049
+ performEvent({
6050
+ mode: "execute",
6051
+ behaviors: isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors,
6052
+ event: action.event,
6053
+ editor,
6054
+ keyGenerator,
6055
+ schema: schema2,
6056
+ getSnapshot,
6057
+ defaultActionCallback: void 0,
6058
+ nativeEvent: void 0
6059
+ });
6060
+ else
6061
+ try {
6062
+ performAction({
6063
+ context: {
6064
+ keyGenerator,
6065
+ schema: schema2
6066
+ },
6067
+ action: {
6068
+ ...action.event,
6069
+ editor
6070
+ }
6071
+ });
6072
+ } catch (error) {
6073
+ console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6074
+ break;
6075
+ }
6076
+ continue;
6077
+ }
6078
+ const internalAction = {
6079
+ ...action,
6080
+ editor
6081
+ };
6082
+ try {
6083
+ performAction({
6084
+ context: {
6085
+ keyGenerator,
6086
+ schema: schema2
6087
+ },
6088
+ action: internalAction
6089
+ });
6090
+ } catch (error) {
6091
+ console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6092
+ break;
6093
+ }
6063
6094
  }
6064
- }
6065
- }), editor.onChange());
6066
- if (behaviorOverwritten) {
6067
- nativeEvent?.preventDefault();
6068
- break;
6095
+ editor.onChange();
6096
+ }));
6097
+ }
6098
+ if (behaviorOverwritten) {
6099
+ nativeEvent?.preventDefault();
6100
+ break;
6101
+ }
6069
6102
  }
6070
6103
  }
6071
6104
  if (!behaviorOverwritten) {
@@ -6089,11 +6122,11 @@ function performEvent({
6089
6122
  schema: schema2
6090
6123
  },
6091
6124
  action: defaultAction
6092
- });
6125
+ }), editor.onChange();
6093
6126
  } catch (error) {
6094
6127
  console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6095
6128
  }
6096
- }), editor.onChange();
6129
+ });
6097
6130
  }
6098
6131
  }
6099
6132
  function slateChildrenToBlocks(schema2, value) {
@@ -6243,7 +6276,8 @@ const editorMachine = xstate.setup({
6243
6276
  self
6244
6277
  }) => {
6245
6278
  xstate.assertEvent(event, ["behavior event"]), performEvent({
6246
- behaviors: [...context.behaviors.values(), ...defaultBehaviors],
6279
+ mode: "raise",
6280
+ behaviors: [...context.behaviors.values()],
6247
6281
  event: event.behaviorEvent,
6248
6282
  editor: event.editor,
6249
6283
  keyGenerator: context.keyGenerator,
@@ -6277,7 +6311,7 @@ const editorMachine = xstate.setup({
6277
6311
  selection: null,
6278
6312
  initialReadOnly: input.readOnly ?? !1,
6279
6313
  maxBlocks: input.maxBlocks,
6280
- value: input.value
6314
+ incomingValue: input.initialValue
6281
6315
  }),
6282
6316
  on: {
6283
6317
  "notify.blurred": {
@@ -6376,7 +6410,7 @@ const editorMachine = xstate.setup({
6376
6410
  },
6377
6411
  "update value": {
6378
6412
  actions: xstate.assign({
6379
- value: ({
6413
+ incomingValue: ({
6380
6414
  event
6381
6415
  }) => event.value
6382
6416
  })
@@ -6985,7 +7019,7 @@ function editorConfigToMachineInput(config) {
6985
7019
  maxBlocks: config.maxBlocks,
6986
7020
  readOnly: config.readOnly,
6987
7021
  schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
6988
- value: config.initialValue
7022
+ initialValue: config.initialValue
6989
7023
  };
6990
7024
  }
6991
7025
  function createInternalEditorFromActor(editorActor) {