@portabletext/editor 1.16.0 → 1.16.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.cjs CHANGED
@@ -2282,8 +2282,8 @@ const syncValueCallback = ({
2282
2282
  actions: {
2283
2283
  "assign readOnly": xstate.assign({
2284
2284
  readOnly: ({
2285
- context
2286
- }) => !context.readOnly
2285
+ event
2286
+ }) => (xstate.assertEvent(event, "update readOnly"), event.readOnly)
2287
2287
  }),
2288
2288
  "assign pending value": xstate.assign({
2289
2289
  pendingValue: ({
@@ -2352,7 +2352,7 @@ const syncValueCallback = ({
2352
2352
  isProcessingLocalChanges: !1
2353
2353
  })
2354
2354
  },
2355
- "toggle readOnly": {
2355
+ "update readOnly": {
2356
2356
  actions: ["assign readOnly"]
2357
2357
  }
2358
2358
  },
@@ -2642,7 +2642,7 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
2642
2642
  }
2643
2643
  const debug$h = debugWithName("component:PortableTextEditor:Synchronizer");
2644
2644
  function Synchronizer(props) {
2645
- const $ = reactCompilerRuntime.c(41), {
2645
+ const $ = reactCompilerRuntime.c(40), {
2646
2646
  editorActor,
2647
2647
  slateEditor
2648
2648
  } = props, value = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
@@ -2697,23 +2697,22 @@ function Synchronizer(props) {
2697
2697
  subscription_0.unsubscribe();
2698
2698
  };
2699
2699
  }, t10 = [props.editorActor, syncActorRef], $[21] = props.editorActor, $[22] = syncActorRef, $[23] = t10, $[24] = t9) : (t10 = $[23], t9 = $[24]), React.useEffect(t9, t10);
2700
- let t11;
2701
- $[25] !== syncActorRef ? (t11 = () => {
2700
+ let t11, t12;
2701
+ $[25] !== readOnly || $[26] !== syncActorRef ? (t11 = () => {
2702
2702
  syncActorRef.send({
2703
- type: "toggle readOnly"
2703
+ type: "update readOnly",
2704
+ readOnly
2704
2705
  });
2705
- }, $[25] = syncActorRef, $[26] = t11) : t11 = $[26];
2706
- let t12;
2707
- $[27] !== readOnly || $[28] !== syncActorRef ? (t12 = [syncActorRef, readOnly], $[27] = readOnly, $[28] = syncActorRef, $[29] = t12) : t12 = $[29], React.useEffect(t11, t12);
2706
+ }, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), React.useEffect(t11, t12);
2708
2707
  let t13, t14;
2709
- $[30] !== syncActorRef || $[31] !== value ? (t13 = () => {
2708
+ $[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
2710
2709
  debug$h("Value from props changed, syncing new value"), syncActorRef.send({
2711
2710
  type: "update value",
2712
2711
  value
2713
2712
  });
2714
- }, t14 = [syncActorRef, value], $[30] = syncActorRef, $[31] = value, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
2713
+ }, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), React.useEffect(t13, t14);
2715
2714
  let t15;
2716
- $[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
2715
+ $[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
2717
2716
  debug$h("Subscribing to patch events");
2718
2717
  const sub = editorActor.on("patch", (event_1) => {
2719
2718
  mutationActorRef.send(event_1);
@@ -2721,9 +2720,9 @@ function Synchronizer(props) {
2721
2720
  return () => {
2722
2721
  debug$h("Unsubscribing to patch events"), sub.unsubscribe();
2723
2722
  };
2724
- }, $[34] = editorActor, $[35] = mutationActorRef, $[36] = t15) : t15 = $[36];
2723
+ }, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
2725
2724
  let t16;
2726
- return $[37] !== editorActor || $[38] !== mutationActorRef || $[39] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[37] = editorActor, $[38] = mutationActorRef, $[39] = slateEditor, $[40] = t16) : t16 = $[40], React.useEffect(t15, t16), null;
2725
+ return $[36] !== editorActor || $[37] !== mutationActorRef || $[38] !== slateEditor ? (t16 = [editorActor, mutationActorRef, slateEditor], $[36] = editorActor, $[37] = mutationActorRef, $[38] = slateEditor, $[39] = t16) : t16 = $[39], React.useEffect(t15, t16), null;
2727
2726
  }
2728
2727
  function _temp2(s_0) {
2729
2728
  return s_0.matches({
@@ -6179,7 +6178,10 @@ const editorMachine = xstate.setup({
6179
6178
  },
6180
6179
  "read only": {
6181
6180
  on: {
6182
- "toggle readOnly": {
6181
+ "update readOnly": {
6182
+ guard: ({
6183
+ event
6184
+ }) => !event.readOnly,
6183
6185
  target: "#editor.edit mode.editable",
6184
6186
  actions: ["emit editable"]
6185
6187
  }
@@ -6189,7 +6191,10 @@ const editorMachine = xstate.setup({
6189
6191
  },
6190
6192
  editable: {
6191
6193
  on: {
6192
- "toggle readOnly": {
6194
+ "update readOnly": {
6195
+ guard: ({
6196
+ event
6197
+ }) => event.readOnly,
6193
6198
  target: "#editor.edit mode.read only.read only",
6194
6199
  actions: ["emit read only"]
6195
6200
  },
@@ -6432,11 +6437,13 @@ class PortableTextEditor extends React.Component {
6432
6437
  }), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
6433
6438
  }
6434
6439
  componentDidUpdate(prevProps) {
6440
+ var _a;
6435
6441
  !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
6436
6442
  type: "update schema",
6437
6443
  schema: this.schemaTypes
6438
6444
  })), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
6439
- type: "toggle readOnly"
6445
+ type: "update readOnly",
6446
+ readOnly: (_a = this.props.readOnly) != null ? _a : !1
6440
6447
  }), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
6441
6448
  type: "update maxBlocks",
6442
6449
  maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)