@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
@@ -2064,7 +2064,7 @@ function Synchronizer(props) {
2064
2064
  const $ = c(41), {
2065
2065
  editorActor,
2066
2066
  slateEditor
2067
- } = props, value = useSelector(props.editorActor, _temp), readOnly = useSelector(props.editorActor, _temp2);
2067
+ } = props, incomingValue = useSelector(props.editorActor, _temp), readOnly = useSelector(props.editorActor, _temp2);
2068
2068
  let t0;
2069
2069
  $[0] !== props.editorActor ? (t0 = props.editorActor.getSnapshot(), $[0] = props.editorActor, $[1] = t0) : t0 = $[1];
2070
2070
  const t1 = t0.context.keyGenerator;
@@ -2154,12 +2154,12 @@ function Synchronizer(props) {
2154
2154
  });
2155
2155
  }, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), useEffect(t11, t12);
2156
2156
  let t13, t14;
2157
- $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2157
+ $[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
2158
2158
  debug$d("Value from props changed, syncing new value"), syncActorRef.send({
2159
2159
  type: "update value",
2160
- value
2160
+ value: incomingValue
2161
2161
  });
2162
- }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
2162
+ }, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), useEffect(t13, t14);
2163
2163
  let t15;
2164
2164
  $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2165
2165
  debug$d("Subscribing to patch events");
@@ -2182,7 +2182,7 @@ function _temp2(s_0) {
2182
2182
  });
2183
2183
  }
2184
2184
  function _temp(s) {
2185
- return s.context.value;
2185
+ return s.context.incomingValue;
2186
2186
  }
2187
2187
  Synchronizer.displayName = "Synchronizer";
2188
2188
  const converterJson = {
@@ -5993,6 +5993,7 @@ function eventCategory(event) {
5993
5993
  return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
5994
5994
  }
5995
5995
  function performEvent({
5996
+ mode,
5996
5997
  behaviors,
5997
5998
  event,
5998
5999
  editor,
@@ -6006,7 +6007,7 @@ function performEvent({
6006
6007
  const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
6007
6008
  ...event,
6008
6009
  editor
6009
- }, eventBehaviors = behaviors.filter((behavior) => {
6010
+ }, eventBehaviors = (mode === "raise" ? [...behaviors, ...defaultBehaviors] : behaviors).filter((behavior) => {
6010
6011
  if (behavior.on === "*")
6011
6012
  return !0;
6012
6013
  const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
@@ -6033,65 +6034,97 @@ function performEvent({
6033
6034
  schema
6034
6035
  },
6035
6036
  action: defaultAction
6036
- });
6037
+ }), editor.onChange();
6037
6038
  } catch (error) {
6038
6039
  console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6039
6040
  }
6040
- }), editor.onChange();
6041
+ });
6041
6042
  return;
6042
6043
  }
6043
- const editorSnapshot = getSnapshot();
6044
+ const guardSnapshot = getSnapshot();
6044
6045
  let behaviorOverwritten = !1;
6045
6046
  for (const eventBehavior of eventBehaviors) {
6046
6047
  const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
6047
- context: editorSnapshot.context,
6048
- snapshot: editorSnapshot,
6048
+ snapshot: guardSnapshot,
6049
6049
  event
6050
6050
  });
6051
- if (!shouldRun)
6052
- continue;
6053
- const actionSets = eventBehavior.actions.map((actionSet) => actionSet({
6054
- context: editorSnapshot.context,
6055
- snapshot: editorSnapshot,
6056
- event
6057
- }, shouldRun));
6058
- for (const actionSet of actionSets)
6059
- actionSet.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actionSet.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
6060
- for (const action of actionSet) {
6061
- if (action.type === "raise") {
6062
- performEvent({
6063
- behaviors,
6064
- event: action.event,
6065
- editor,
6066
- keyGenerator,
6067
- schema,
6068
- getSnapshot,
6069
- defaultActionCallback: void 0,
6070
- nativeEvent: void 0
6071
- });
6072
- continue;
6073
- }
6074
- const internalAction = {
6075
- ...action,
6076
- editor
6077
- };
6078
- try {
6079
- performAction({
6080
- context: {
6051
+ if (shouldRun) {
6052
+ for (const actionSet of eventBehavior.actions) {
6053
+ const actionsSnapshot = getSnapshot(), actions = actionSet({
6054
+ snapshot: actionsSnapshot,
6055
+ event
6056
+ }, shouldRun);
6057
+ actions.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actions.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
6058
+ for (const action of actions) {
6059
+ if (action.type === "raise") {
6060
+ performEvent({
6061
+ mode,
6062
+ behaviors: mode === "execute" ? isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors : [...behaviors, ...defaultBehaviors],
6063
+ event: action.event,
6064
+ editor,
6081
6065
  keyGenerator,
6082
- schema
6083
- },
6084
- action: internalAction
6085
- });
6086
- } catch (error) {
6087
- console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6088
- break;
6066
+ schema,
6067
+ getSnapshot,
6068
+ defaultActionCallback: void 0,
6069
+ nativeEvent: void 0
6070
+ });
6071
+ continue;
6072
+ }
6073
+ if (action.type === "execute") {
6074
+ if (isAbstractBehaviorEvent(action.event) || isCustomBehaviorEvent(action.event))
6075
+ performEvent({
6076
+ mode: "execute",
6077
+ behaviors: isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors,
6078
+ event: action.event,
6079
+ editor,
6080
+ keyGenerator,
6081
+ schema,
6082
+ getSnapshot,
6083
+ defaultActionCallback: void 0,
6084
+ nativeEvent: void 0
6085
+ });
6086
+ else
6087
+ try {
6088
+ performAction({
6089
+ context: {
6090
+ keyGenerator,
6091
+ schema
6092
+ },
6093
+ action: {
6094
+ ...action.event,
6095
+ editor
6096
+ }
6097
+ });
6098
+ } catch (error) {
6099
+ console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6100
+ break;
6101
+ }
6102
+ continue;
6103
+ }
6104
+ const internalAction = {
6105
+ ...action,
6106
+ editor
6107
+ };
6108
+ try {
6109
+ performAction({
6110
+ context: {
6111
+ keyGenerator,
6112
+ schema
6113
+ },
6114
+ action: internalAction
6115
+ });
6116
+ } catch (error) {
6117
+ console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6118
+ break;
6119
+ }
6089
6120
  }
6090
- }
6091
- }), editor.onChange());
6092
- if (behaviorOverwritten) {
6093
- nativeEvent?.preventDefault();
6094
- break;
6121
+ editor.onChange();
6122
+ }));
6123
+ }
6124
+ if (behaviorOverwritten) {
6125
+ nativeEvent?.preventDefault();
6126
+ break;
6127
+ }
6095
6128
  }
6096
6129
  }
6097
6130
  if (!behaviorOverwritten) {
@@ -6115,11 +6148,11 @@ function performEvent({
6115
6148
  schema
6116
6149
  },
6117
6150
  action: defaultAction
6118
- });
6151
+ }), editor.onChange();
6119
6152
  } catch (error) {
6120
6153
  console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
6121
6154
  }
6122
- }), editor.onChange();
6155
+ });
6123
6156
  }
6124
6157
  }
6125
6158
  function slateChildrenToBlocks(schema, value) {
@@ -6269,7 +6302,8 @@ const editorMachine = setup({
6269
6302
  self
6270
6303
  }) => {
6271
6304
  assertEvent(event, ["behavior event"]), performEvent({
6272
- behaviors: [...context.behaviors.values(), ...defaultBehaviors],
6305
+ mode: "raise",
6306
+ behaviors: [...context.behaviors.values()],
6273
6307
  event: event.behaviorEvent,
6274
6308
  editor: event.editor,
6275
6309
  keyGenerator: context.keyGenerator,
@@ -6303,7 +6337,7 @@ const editorMachine = setup({
6303
6337
  selection: null,
6304
6338
  initialReadOnly: input.readOnly ?? !1,
6305
6339
  maxBlocks: input.maxBlocks,
6306
- value: input.value
6340
+ incomingValue: input.initialValue
6307
6341
  }),
6308
6342
  on: {
6309
6343
  "notify.blurred": {
@@ -6402,7 +6436,7 @@ const editorMachine = setup({
6402
6436
  },
6403
6437
  "update value": {
6404
6438
  actions: assign({
6405
- value: ({
6439
+ incomingValue: ({
6406
6440
  event
6407
6441
  }) => event.value
6408
6442
  })
@@ -7011,7 +7045,7 @@ function editorConfigToMachineInput(config) {
7011
7045
  maxBlocks: config.maxBlocks,
7012
7046
  readOnly: config.readOnly,
7013
7047
  schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
7014
- value: config.initialValue
7048
+ initialValue: config.initialValue
7015
7049
  };
7016
7050
  }
7017
7051
  function createInternalEditorFromActor(editorActor) {