@portabletext/editor 2.1.1 → 2.1.3

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.
@@ -4,7 +4,7 @@ import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDe
4
4
  import * as xstate227 from "xstate";
5
5
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
6
6
  import { BaseRange, Descendant, Operation } from "slate";
7
- import * as react20 from "react";
7
+ import * as react22 from "react";
8
8
  import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
9
9
  import * as xstate_guards12 from "xstate/guards";
10
10
  import { Observable, Subject } from "rxjs";
@@ -352,7 +352,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
352
352
  componentDidUpdate(prevProps: PortableTextEditorProps): void;
353
353
  componentWillUnmount(): void;
354
354
  setEditable: (editable: EditableAPI) => void;
355
- render(): react20.JSX.Element;
355
+ render(): react22.JSX.Element;
356
356
  /**
357
357
  * @deprecated
358
358
  * Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
@@ -747,7 +747,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
747
747
  * ```
748
748
  * @group Components
749
749
  */
750
- declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
750
+ declare const PortableTextEditable: react22.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react22.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
751
751
  type DecoratedRange = BaseRange & {
752
752
  rangeDecoration: RangeDecoration;
753
753
  };
@@ -1476,7 +1476,7 @@ declare const editorMachine: xstate227.StateMachine<{
1476
1476
  initialValue?: Array<PortableTextBlock>;
1477
1477
  }, xstate227.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
1478
1478
  type: "blurred";
1479
- event: react20.FocusEvent<HTMLDivElement, Element>;
1479
+ event: react22.FocusEvent<HTMLDivElement, Element>;
1480
1480
  } | {
1481
1481
  type: "done loading";
1482
1482
  } | {
@@ -1488,7 +1488,7 @@ declare const editorMachine: xstate227.StateMachine<{
1488
1488
  data: unknown;
1489
1489
  } | {
1490
1490
  type: "focused";
1491
- event: react20.FocusEvent<HTMLDivElement, Element>;
1491
+ event: react22.FocusEvent<HTMLDivElement, Element>;
1492
1492
  } | {
1493
1493
  type: "invalid value";
1494
1494
  resolution: InvalidValueResolution | null;
@@ -2135,7 +2135,7 @@ declare const editorMachine: xstate227.StateMachine<{
2135
2135
  type: "drop";
2136
2136
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
2137
2137
  type: "blurred";
2138
- event: react20.FocusEvent<HTMLDivElement, Element>;
2138
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2139
2139
  } | {
2140
2140
  type: "done loading";
2141
2141
  } | {
@@ -2147,7 +2147,7 @@ declare const editorMachine: xstate227.StateMachine<{
2147
2147
  data: unknown;
2148
2148
  } | {
2149
2149
  type: "focused";
2150
- event: react20.FocusEvent<HTMLDivElement, Element>;
2150
+ event: react22.FocusEvent<HTMLDivElement, Element>;
2151
2151
  } | {
2152
2152
  type: "invalid value";
2153
2153
  resolution: InvalidValueResolution | null;
@@ -3018,7 +3018,7 @@ declare const editorMachine: xstate227.StateMachine<{
3018
3018
  type: "drop";
3019
3019
  }, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
3020
3020
  type: "blurred";
3021
- event: react20.FocusEvent<HTMLDivElement, Element>;
3021
+ event: react22.FocusEvent<HTMLDivElement, Element>;
3022
3022
  } | {
3023
3023
  type: "done loading";
3024
3024
  } | {
@@ -3030,7 +3030,7 @@ declare const editorMachine: xstate227.StateMachine<{
3030
3030
  data: unknown;
3031
3031
  } | {
3032
3032
  type: "focused";
3033
- event: react20.FocusEvent<HTMLDivElement, Element>;
3033
+ event: react22.FocusEvent<HTMLDivElement, Element>;
3034
3034
  } | {
3035
3035
  type: "invalid value";
3036
3036
  resolution: InvalidValueResolution | null;
package/lib/index.cjs CHANGED
@@ -6757,10 +6757,11 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
6757
6757
  ], abstractListItemBehaviors = [behaviors_index.defineBehavior({
6758
6758
  on: "list item.add",
6759
6759
  guard: ({
6760
- snapshot
6761
- }) => ({
6760
+ snapshot,
6761
+ event
6762
+ }) => snapshot.context.schema.lists.some((list) => list.name === event.listItem) ? {
6762
6763
  selectedTextBlocks: selector_isSelectingEntireBlocks.getSelectedTextBlocks(snapshot)
6763
- }),
6764
+ } : !1,
6764
6765
  actions: [({
6765
6766
  event
6766
6767
  }, {
@@ -6769,7 +6770,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
6769
6770
  type: "block.set",
6770
6771
  at: block.path,
6771
6772
  props: {
6772
- level: 1,
6773
+ level: block.node.level ?? 1,
6773
6774
  listItem: event.listItem
6774
6775
  }
6775
6776
  }))]
@@ -10084,25 +10085,6 @@ function createActors(config) {
10084
10085
  syncActor
10085
10086
  };
10086
10087
  }
10087
- const RelayActorContext = React.createContext({});
10088
- function RouteEventsToChanges(props) {
10089
- const $ = reactCompilerRuntime.c(7);
10090
- let t0;
10091
- $[0] !== props ? (t0 = (change) => props.onChange(change), $[0] = props, $[1] = t0) : t0 = $[1];
10092
- const handleChange = useEffectEvent.useEffectEvent(t0);
10093
- let t1;
10094
- $[2] !== handleChange || $[3] !== props.relayActor ? (t1 = () => {
10095
- const sub = props.relayActor.on("*", (event) => {
10096
- const change_0 = eventToChange(event);
10097
- change_0 && handleChange(change_0);
10098
- });
10099
- return () => {
10100
- sub.unsubscribe();
10101
- };
10102
- }, $[2] = handleChange, $[3] = props.relayActor, $[4] = t1) : t1 = $[4];
10103
- let t2;
10104
- return $[5] !== props.relayActor ? (t2 = [props.relayActor], $[5] = props.relayActor, $[6] = t2) : t2 = $[6], React.useEffect(t1, t2), null;
10105
- }
10106
10088
  function eventToChange(event) {
10107
10089
  switch (event.type) {
10108
10090
  case "blurred":
@@ -10148,7 +10130,7 @@ function eventToChange(event) {
10148
10130
  return event;
10149
10131
  }
10150
10132
  }
10151
- const debug$2 = debugWithName("component:PortableTextEditor");
10133
+ const RelayActorContext = React.createContext({}), debug$2 = debugWithName("component:PortableTextEditor");
10152
10134
  class PortableTextEditor extends React.Component {
10153
10135
  static displayName = "PortableTextEditor";
10154
10136
  /**
@@ -11709,7 +11691,7 @@ function useConstant(factory) {
11709
11691
  }), ref.current.constant;
11710
11692
  }
11711
11693
  function EditorProvider(props) {
11712
- const $ = reactCompilerRuntime.c(32);
11694
+ const $ = reactCompilerRuntime.c(28);
11713
11695
  let t0;
11714
11696
  $[0] !== props.initialConfig ? (t0 = () => {
11715
11697
  const internalEditor = createInternalEditor(props.initialConfig), portableTextEditor = new PortableTextEditor({
@@ -11725,37 +11707,32 @@ function EditorProvider(props) {
11725
11707
  portableTextEditor: portableTextEditor_0
11726
11708
  } = useConstant(t0);
11727
11709
  let t1;
11728
- $[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.subscriptions ? (t1 = () => {
11710
+ $[2] !== internalEditor_0.actors.editorActor || $[3] !== internalEditor_0.actors.mutationActor || $[4] !== internalEditor_0.actors.relayActor || $[5] !== internalEditor_0.actors.syncActor || $[6] !== internalEditor_0.subscriptions || $[7] !== portableTextEditor_0 ? (t1 = () => {
11729
11711
  const unsubscribers = [];
11730
11712
  for (const subscription of internalEditor_0.subscriptions)
11731
11713
  unsubscribers.push(subscription());
11732
- return internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
11714
+ const relayActorSubscription = internalEditor_0.actors.relayActor.on("*", (event) => {
11715
+ const change = eventToChange(event);
11716
+ change && portableTextEditor_0.change$.next(change);
11717
+ });
11718
+ return unsubscribers.push(relayActorSubscription.unsubscribe), internalEditor_0.actors.editorActor.start(), internalEditor_0.actors.mutationActor.start(), internalEditor_0.actors.relayActor.start(), internalEditor_0.actors.syncActor.start(), () => {
11733
11719
  for (const unsubscribe of unsubscribers)
11734
11720
  unsubscribe();
11735
11721
  stopActor(internalEditor_0.actors.editorActor), stopActor(internalEditor_0.actors.mutationActor), stopActor(internalEditor_0.actors.relayActor), stopActor(internalEditor_0.actors.syncActor);
11736
11722
  };
11737
- }, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.subscriptions, $[7] = t1) : t1 = $[7];
11723
+ }, $[2] = internalEditor_0.actors.editorActor, $[3] = internalEditor_0.actors.mutationActor, $[4] = internalEditor_0.actors.relayActor, $[5] = internalEditor_0.actors.syncActor, $[6] = internalEditor_0.subscriptions, $[7] = portableTextEditor_0, $[8] = t1) : t1 = $[8];
11738
11724
  let t2;
11739
- $[8] !== internalEditor_0 ? (t2 = [internalEditor_0], $[8] = internalEditor_0, $[9] = t2) : t2 = $[9], React.useEffect(t1, t2);
11725
+ $[9] !== internalEditor_0 || $[10] !== portableTextEditor_0 ? (t2 = [internalEditor_0, portableTextEditor_0], $[9] = internalEditor_0, $[10] = portableTextEditor_0, $[11] = t2) : t2 = $[11], React.useEffect(t1, t2);
11740
11726
  let t3;
11741
- $[10] !== portableTextEditor_0.change$ ? (t3 = (change) => {
11742
- portableTextEditor_0.change$.next(change);
11743
- }, $[10] = portableTextEditor_0.change$, $[11] = t3) : t3 = $[11];
11727
+ $[12] !== portableTextEditor_0 || $[13] !== props.children ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: props.children }), $[12] = portableTextEditor_0, $[13] = props.children, $[14] = t3) : t3 = $[14];
11744
11728
  let t4;
11745
- $[12] !== internalEditor_0.actors.relayActor || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { relayActor: internalEditor_0.actors.relayActor, onChange: t3 }), $[12] = internalEditor_0.actors.relayActor, $[13] = t3, $[14] = t4) : t4 = $[14];
11729
+ $[15] !== internalEditor_0.editor._internal.slateEditor.initialValue || $[16] !== internalEditor_0.editor._internal.slateEditor.instance || $[17] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: internalEditor_0.editor._internal.slateEditor.instance, initialValue: internalEditor_0.editor._internal.slateEditor.initialValue, children: t3 }), $[15] = internalEditor_0.editor._internal.slateEditor.initialValue, $[16] = internalEditor_0.editor._internal.slateEditor.instance, $[17] = t3, $[18] = t4) : t4 = $[18];
11746
11730
  let t5;
11747
- $[15] !== portableTextEditor_0 || $[16] !== props.children ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor_0, children: props.children }), $[15] = portableTextEditor_0, $[16] = props.children, $[17] = t5) : t5 = $[17];
11731
+ $[19] !== internalEditor_0.actors.relayActor || $[20] !== t4 ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t4 }), $[19] = internalEditor_0.actors.relayActor, $[20] = t4, $[21] = t5) : t5 = $[21];
11748
11732
  let t6;
11749
- $[18] !== internalEditor_0.editor._internal.slateEditor.initialValue || $[19] !== internalEditor_0.editor._internal.slateEditor.instance || $[20] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: internalEditor_0.editor._internal.slateEditor.instance, initialValue: internalEditor_0.editor._internal.slateEditor.initialValue, children: t5 }), $[18] = internalEditor_0.editor._internal.slateEditor.initialValue, $[19] = internalEditor_0.editor._internal.slateEditor.instance, $[20] = t5, $[21] = t6) : t6 = $[21];
11733
+ $[22] !== internalEditor_0.actors.editorActor || $[23] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: internalEditor_0.actors.editorActor, children: t5 }), $[22] = internalEditor_0.actors.editorActor, $[23] = t5, $[24] = t6) : t6 = $[24];
11750
11734
  let t7;
11751
- $[22] !== internalEditor_0.actors.relayActor || $[23] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(RelayActorContext.Provider, { value: internalEditor_0.actors.relayActor, children: t6 }), $[22] = internalEditor_0.actors.relayActor, $[23] = t6, $[24] = t7) : t7 = $[24];
11752
- let t8;
11753
- $[25] !== internalEditor_0.actors.editorActor || $[26] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: internalEditor_0.actors.editorActor, children: t7 }), $[25] = internalEditor_0.actors.editorActor, $[26] = t7, $[27] = t8) : t8 = $[27];
11754
- let t9;
11755
- return $[28] !== internalEditor_0.editor || $[29] !== t4 || $[30] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsxs(useEditor.EditorContext.Provider, { value: internalEditor_0.editor, children: [
11756
- t4,
11757
- t8
11758
- ] }), $[28] = internalEditor_0.editor, $[29] = t4, $[30] = t8, $[31] = t9) : t9 = $[31], t9;
11735
+ return $[25] !== internalEditor_0.editor || $[26] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(useEditor.EditorContext.Provider, { value: internalEditor_0.editor, children: t6 }), $[25] = internalEditor_0.editor, $[26] = t6, $[27] = t7) : t7 = $[27], t7;
11759
11736
  }
11760
11737
  function defineSchema(definition) {
11761
11738
  return definition;