@portabletext/editor 1.10.0 → 1.10.1

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.
package/lib/index.js CHANGED
@@ -2936,11 +2936,10 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2936
2936
  }
2937
2937
  const debug$i = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$3 = debug$i.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
2938
2938
  function Synchronizer(props) {
2939
- const $ = reactCompilerRuntime.c(35), portableTextEditor = usePortableTextEditor(), readOnly = react$1.useSelector(props.editorActor, _temp$1), {
2939
+ const $ = reactCompilerRuntime.c(35), portableTextEditor = usePortableTextEditor(), readOnly = react$1.useSelector(props.editorActor, _temp$1), value = react$1.useSelector(props.editorActor, _temp2), {
2940
2940
  editorActor,
2941
2941
  getValue,
2942
- onChange,
2943
- value
2942
+ onChange
2944
2943
  } = props;
2945
2944
  let t0;
2946
2945
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
@@ -2992,52 +2991,52 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
2992
2991
  });
2993
2992
  debug$i("Subscribing to editor changes");
2994
2993
  const sub = editorActor.on("*", (event) => {
2995
- bb20: switch (event.type) {
2994
+ bb22: switch (event.type) {
2996
2995
  case "patch": {
2997
2996
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
2998
- break bb20;
2997
+ break bb22;
2999
2998
  }
3000
2999
  case "loading": {
3001
3000
  handleChange({
3002
3001
  type: "loading",
3003
3002
  isLoading: !0
3004
3003
  });
3005
- break bb20;
3004
+ break bb22;
3006
3005
  }
3007
3006
  case "done loading": {
3008
3007
  handleChange({
3009
3008
  type: "loading",
3010
3009
  isLoading: !1
3011
3010
  });
3012
- break bb20;
3011
+ break bb22;
3013
3012
  }
3014
3013
  case "focused": {
3015
3014
  handleChange({
3016
3015
  type: "focus",
3017
3016
  event: event.event
3018
3017
  });
3019
- break bb20;
3018
+ break bb22;
3020
3019
  }
3021
3020
  case "offline": {
3022
3021
  handleChange({
3023
3022
  type: "connection",
3024
3023
  value: "offline"
3025
3024
  });
3026
- break bb20;
3025
+ break bb22;
3027
3026
  }
3028
3027
  case "online": {
3029
3028
  handleChange({
3030
3029
  type: "connection",
3031
3030
  value: "online"
3032
3031
  });
3033
- break bb20;
3032
+ break bb22;
3034
3033
  }
3035
3034
  case "value changed": {
3036
3035
  handleChange({
3037
3036
  type: "value",
3038
3037
  value: event.value
3039
3038
  });
3040
- break bb20;
3039
+ break bb22;
3041
3040
  }
3042
3041
  case "invalid value": {
3043
3042
  handleChange({
@@ -3045,21 +3044,21 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
3045
3044
  resolution: event.resolution,
3046
3045
  value: event.value
3047
3046
  });
3048
- break bb20;
3047
+ break bb22;
3049
3048
  }
3050
3049
  case "error": {
3051
3050
  handleChange({
3052
3051
  ...event,
3053
3052
  level: "warning"
3054
3053
  });
3055
- break bb20;
3054
+ break bb22;
3056
3055
  }
3057
3056
  case "annotation.add":
3058
3057
  case "annotation.remove":
3059
3058
  case "annotation.toggle":
3060
3059
  case "focus":
3061
3060
  case "patches":
3062
- break bb20;
3061
+ break bb22;
3063
3062
  default:
3064
3063
  handleChange(event);
3065
3064
  }
@@ -3088,6 +3087,9 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
3088
3087
  }), isInitialValueFromProps.current = !1);
3089
3088
  }, t14 = [editorActor, syncValue, value], $[30] = editorActor, $[31] = syncValue, $[32] = value, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), react.useEffect(t13, t14), null;
3090
3089
  }
3090
+ function _temp2(s_0) {
3091
+ return s_0.context.value;
3092
+ }
3091
3093
  function _temp$1(s) {
3092
3094
  return s.context.readOnly;
3093
3095
  }
@@ -5705,8 +5707,8 @@ const networkLogic = xstate.fromCallback(({
5705
5707
  type: "offline"
5706
5708
  });
5707
5709
  };
5708
- return window.addEventListener("online", onlineHandler), window.addEventListener("offline", offlineHandler), () => {
5709
- window.removeEventListener("online", onlineHandler), window.removeEventListener("offline", offlineHandler);
5710
+ return window && (window.addEventListener("online", onlineHandler), window.addEventListener("offline", offlineHandler)), () => {
5711
+ window && (window.removeEventListener("online", onlineHandler), window.removeEventListener("offline", offlineHandler));
5710
5712
  };
5711
5713
  }), editorMachine = xstate.setup({
5712
5714
  types: {
@@ -5821,7 +5823,8 @@ const networkLogic = xstate.fromCallback(({
5821
5823
  pendingEvents: [],
5822
5824
  schema: input.schema,
5823
5825
  readOnly: !1,
5824
- maxBlocks: void 0
5826
+ maxBlocks: void 0,
5827
+ value: input.value
5825
5828
  }),
5826
5829
  invoke: {
5827
5830
  id: "networkLogic",
@@ -5931,6 +5934,13 @@ const networkLogic = xstate.fromCallback(({
5931
5934
  "update schema": {
5932
5935
  actions: "assign schema"
5933
5936
  },
5937
+ "update value": {
5938
+ actions: xstate.assign({
5939
+ value: ({
5940
+ event
5941
+ }) => event.value
5942
+ })
5943
+ },
5934
5944
  "toggle readOnly": {
5935
5945
  actions: xstate.assign({
5936
5946
  readOnly: ({
@@ -6092,7 +6102,8 @@ class PortableTextEditor extends react.Component {
6092
6102
  props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = xstate.createActor(editorMachine, {
6093
6103
  input: {
6094
6104
  keyGenerator: props.keyGenerator || defaultKeyGenerator,
6095
- schema: this.schemaTypes
6105
+ schema: this.schemaTypes,
6106
+ value: props.value
6096
6107
  }
6097
6108
  }), this.editorActor.start(), this.slateEditor = createSlateEditor({
6098
6109
  editorActor: this.editorActor
@@ -6114,7 +6125,10 @@ class PortableTextEditor extends react.Component {
6114
6125
  }), this.props.maxBlocks !== prevProps.maxBlocks && this.editorActor.send({
6115
6126
  type: "update maxBlocks",
6116
6127
  maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
6117
- })), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
6128
+ }), this.props.value !== prevProps.value && this.editorActor.send({
6129
+ type: "update value",
6130
+ value: this.props.value
6131
+ }), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
6118
6132
  }
6119
6133
  setEditable = (editable) => {
6120
6134
  this.editable = {
@@ -6133,7 +6147,7 @@ class PortableTextEditor extends react.Component {
6133
6147
  /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.slateEditor.instance, initialValue: this.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
6134
6148
  /* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
6135
6149
  this.props.editor || this.props.onChange(change), this.change$.next(change);
6136
- }, value: this.props.value }),
6150
+ } }),
6137
6151
  this.props.children
6138
6152
  ] }) }) }) })
6139
6153
  ] });
@@ -6899,39 +6913,40 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6899
6913
  });
6900
6914
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
6901
6915
  function useEditor(config) {
6902
- const $ = reactCompilerRuntime.c(20), t0 = config.keyGenerator ?? defaultKeyGenerator;
6916
+ const $ = reactCompilerRuntime.c(21), t0 = config.keyGenerator ?? defaultKeyGenerator;
6903
6917
  let t1;
6904
6918
  $[0] !== config.schema || $[1] !== config.schemaDefinition ? (t1 = config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), $[0] = config.schema, $[1] = config.schemaDefinition, $[2] = t1) : t1 = $[2];
6905
6919
  let t2;
6906
- $[3] !== config.behaviors || $[4] !== t0 || $[5] !== t1 ? (t2 = {
6920
+ $[3] !== config.behaviors || $[4] !== config.initialValue || $[5] !== t0 || $[6] !== t1 ? (t2 = {
6907
6921
  input: {
6908
6922
  behaviors: config.behaviors,
6909
6923
  keyGenerator: t0,
6910
- schema: t1
6924
+ schema: t1,
6925
+ value: config.initialValue
6911
6926
  }
6912
- }, $[3] = config.behaviors, $[4] = t0, $[5] = t1, $[6] = t2) : t2 = $[6];
6927
+ }, $[3] = config.behaviors, $[4] = config.initialValue, $[5] = t0, $[6] = t1, $[7] = t2) : t2 = $[7];
6913
6928
  const editorActor = react$1.useActorRef(editorMachine, t2);
6914
6929
  let t3;
6915
- $[7] !== editorActor ? (t3 = createSlateEditor({
6930
+ $[8] !== editorActor ? (t3 = createSlateEditor({
6916
6931
  editorActor
6917
- }), $[7] = editorActor, $[8] = t3) : t3 = $[8];
6932
+ }), $[8] = editorActor, $[9] = t3) : t3 = $[9];
6918
6933
  const slateEditor = t3, readOnly = react$1.useSelector(editorActor, _temp);
6919
6934
  let t4, t5;
6920
- $[9] !== editorActor ? (t4 = (event) => {
6935
+ $[10] !== editorActor ? (t4 = (event) => {
6921
6936
  editorActor.send(event);
6922
- }, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[9] = editorActor, $[10] = t4, $[11] = t5) : (t4 = $[10], t5 = $[11]);
6937
+ }, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[10] = editorActor, $[11] = t4, $[12] = t5) : (t4 = $[11], t5 = $[12]);
6923
6938
  let t6;
6924
- $[12] !== editorActor || $[13] !== slateEditor ? (t6 = {
6939
+ $[13] !== editorActor || $[14] !== slateEditor ? (t6 = {
6925
6940
  editorActor,
6926
6941
  slateEditor
6927
- }, $[12] = editorActor, $[13] = slateEditor, $[14] = t6) : t6 = $[14];
6942
+ }, $[13] = editorActor, $[14] = slateEditor, $[15] = t6) : t6 = $[15];
6928
6943
  let t7;
6929
- return $[15] !== readOnly || $[16] !== t4 || $[17] !== t5 || $[18] !== t6 ? (t7 = {
6944
+ return $[16] !== readOnly || $[17] !== t4 || $[18] !== t5 || $[19] !== t6 ? (t7 = {
6930
6945
  send: t4,
6931
6946
  on: t5,
6932
6947
  readOnly,
6933
6948
  _internal: t6
6934
- }, $[15] = readOnly, $[16] = t4, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
6949
+ }, $[16] = readOnly, $[17] = t4, $[18] = t5, $[19] = t6, $[20] = t7) : t7 = $[20], t7;
6935
6950
  }
6936
6951
  function _temp(s) {
6937
6952
  return s.context.readOnly;