@portabletext/editor 7.9.0 → 7.10.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 (39) hide show
  1. package/lib/_chunks-dts/behavior.types.action.d.ts +110 -274
  2. package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
  3. package/lib/_chunks-dts/block-offset.d.ts +10 -0
  4. package/lib/_chunks-dts/block-offset.d.ts.map +1 -0
  5. package/lib/_chunks-dts/editor-selector.d.ts +33 -0
  6. package/lib/_chunks-dts/editor-selector.d.ts.map +1 -0
  7. package/lib/_chunks-dts/editor.d.ts +99 -0
  8. package/lib/_chunks-dts/editor.d.ts.map +1 -0
  9. package/lib/_chunks-es/{get-first-child.js → get-container.js} +10 -1
  10. package/lib/_chunks-es/get-container.js.map +1 -0
  11. package/lib/_chunks-es/get-path-sub-schema.js +38 -6
  12. package/lib/_chunks-es/get-path-sub-schema.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +3 -0
  14. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  15. package/lib/_chunks-es/{util.is-empty-text-block.js → util.is-equal-selections.js} +7 -2
  16. package/lib/_chunks-es/util.is-equal-selections.js.map +1 -0
  17. package/lib/_chunks-es/util.slice-blocks.js +1 -8
  18. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  19. package/lib/behaviors/index.d.ts +1 -1
  20. package/lib/index.d.ts +67 -2
  21. package/lib/index.d.ts.map +1 -0
  22. package/lib/index.js +282 -106
  23. package/lib/index.js.map +1 -1
  24. package/lib/plugins/index.d.ts +2 -1
  25. package/lib/plugins/index.d.ts.map +1 -1
  26. package/lib/selectors/index.d.ts +3 -1
  27. package/lib/selectors/index.d.ts.map +1 -1
  28. package/lib/selectors/index.js +4 -2
  29. package/lib/selectors/index.js.map +1 -1
  30. package/lib/traversal/index.d.ts +11 -2
  31. package/lib/traversal/index.d.ts.map +1 -1
  32. package/lib/traversal/index.js +3 -2
  33. package/lib/utils/index.d.ts +3 -3
  34. package/lib/utils/index.d.ts.map +1 -1
  35. package/lib/utils/index.js +3 -6
  36. package/lib/utils/index.js.map +1 -1
  37. package/package.json +20 -20
  38. package/lib/_chunks-es/get-first-child.js.map +0 -1
  39. package/lib/_chunks-es/util.is-empty-text-block.js.map +0 -1
@@ -1,18 +1,23 @@
1
- import * as _portabletext_schema6 from "@portabletext/schema";
2
- import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition, FieldDefinition as FieldDefinition$1, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, OfDefinition, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, StyleSchemaType as StyleSchemaType$1, TypedObject, defineSchema } from "@portabletext/schema";
3
- import * as xstate31 from "xstate";
1
+ import { AnnotationSchemaType, BlockObjectSchemaType, DecoratorSchemaType, FieldDefinition, InlineObjectSchemaType, ListSchemaType, OfDefinition, PortableTextBlock, PortableTextChild, PortableTextObject, PortableTextSpan, PortableTextTextBlock, Schema, StyleSchemaType, TypedObject } from "@portabletext/schema";
2
+ import { Patch } from "@portabletext/patches";
4
3
  import { ActorRefFrom } from "xstate";
5
- import * as react7 from "react";
6
- import React$1, { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
7
- import { Patch, Patch as Patch$1 } from "@portabletext/patches";
4
+ import { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
5
+ type EditorPriority = {
6
+ id: string;
7
+ name?: string;
8
+ reference?: {
9
+ priority: EditorPriority;
10
+ importance: 'higher' | 'lower';
11
+ };
12
+ };
8
13
  type MIMEType = `${string}/${string}`;
9
14
  /**
10
15
  * @internal
11
16
  */
12
17
  type PickFromUnion<TUnion, TTagKey extends keyof TUnion, TPickedTags extends TUnion[TTagKey]> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never;
13
- type NamespaceEvent<TEvent, TNamespace$1 extends string> = TEvent extends {
18
+ type NamespaceEvent<TEvent, TNamespace extends string> = TEvent extends {
14
19
  type: infer TEventType;
15
- } ? { [K in keyof TEvent]: K extends 'type' ? `${TNamespace$1}.${TEventType & string}` : TEvent[K] } : never;
20
+ } ? { [K in keyof TEvent]: K extends 'type' ? `${TNamespace}.${TEventType & string}` : TEvent[K] } : never;
16
21
  type StrictExtract<T, U extends T> = U;
17
22
  type Converter<TMIMEType extends MIMEType = MIMEType> = {
18
23
  mimeType: TMIMEType;
@@ -109,7 +114,7 @@ type ChildPath = Path;
109
114
  * always render portable text objects: `'span'` is always a leaf and
110
115
  * `'block'` is always a text block; both are excluded.
111
116
  */
112
- type ContainerNodeForType<TType$1 extends string> = TType$1 extends 'span' | 'block' ? never : PortableTextObject;
117
+ type ContainerNodeForType<TType extends string> = TType extends 'span' | 'block' ? never : PortableTextObject;
113
118
  /**
114
119
  * @alpha
115
120
  *
@@ -413,14 +418,14 @@ type RegistrableNode = Container | TextBlock | Span | BlockObject | InlineObject
413
418
  * })
414
419
  * ```
415
420
  */
416
- declare function defineContainer<const TType$1 extends string>(config: {
417
- type: TType$1 extends 'span' ? "Error: defineContainer({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1 extends 'block' ? "Error: defineContainer({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1 extends '*' ? "Error: defineContainer({type: '*'}) is forbidden -- containers cannot be registered by wildcard" : TType$1;
421
+ declare function defineContainer<const TType extends string>(config: {
422
+ type: TType extends 'span' ? "Error: defineContainer({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType extends 'block' ? "Error: defineContainer({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType extends '*' ? "Error: defineContainer({type: '*'}) is forbidden -- containers cannot be registered by wildcard" : TType;
418
423
  arrayField: string;
419
424
  render?: (props: {
420
425
  attributes: Record<string, unknown>;
421
426
  children: ReactElement;
422
427
  focused: boolean;
423
- node: ContainerNodeForType<TType$1>;
428
+ node: ContainerNodeForType<TType>;
424
429
  path: Path;
425
430
  readOnly: boolean;
426
431
  selected: boolean;
@@ -450,8 +455,8 @@ declare function defineContainer<const TType$1 extends string>(config: {
450
455
  * })
451
456
  * ```
452
457
  */
453
- declare function defineSpan<const TType$1 extends string>(config: {
454
- type: TType$1 extends 'block' ? "Error: defineSpan({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1;
458
+ declare function defineSpan<const TType extends string>(config: {
459
+ type: TType extends 'block' ? "Error: defineSpan({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType;
455
460
  render?: SpanRender;
456
461
  }): Span;
457
462
  /**
@@ -478,8 +483,8 @@ declare function defineSpan<const TType$1 extends string>(config: {
478
483
  * })
479
484
  * ```
480
485
  */
481
- declare function defineBlockObject<const TType$1 extends string>(config: {
482
- type: TType$1 extends 'block' ? "Error: defineBlockObject({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1 extends 'span' ? "Error: defineBlockObject({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1;
486
+ declare function defineBlockObject<const TType extends string>(config: {
487
+ type: TType extends 'block' ? "Error: defineBlockObject({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType extends 'span' ? "Error: defineBlockObject({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType;
483
488
  render?: BlockObjectRender;
484
489
  }): BlockObject;
485
490
  /**
@@ -506,8 +511,8 @@ declare function defineBlockObject<const TType$1 extends string>(config: {
506
511
  * })
507
512
  * ```
508
513
  */
509
- declare function defineInlineObject<const TType$1 extends string>(config: {
510
- type: TType$1 extends 'block' ? "Error: defineInlineObject({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1 extends 'span' ? "Error: defineInlineObject({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1;
514
+ declare function defineInlineObject<const TType extends string>(config: {
515
+ type: TType extends 'block' ? "Error: defineInlineObject({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType extends 'span' ? "Error: defineInlineObject({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType;
511
516
  render?: InlineObjectRender;
512
517
  }): InlineObject;
513
518
  /**
@@ -532,8 +537,8 @@ declare function defineInlineObject<const TType$1 extends string>(config: {
532
537
  * })
533
538
  * ```
534
539
  */
535
- declare function defineTextBlock<const TType$1 extends string>(config: {
536
- type: TType$1 extends 'span' ? "Error: defineTextBlock({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1;
540
+ declare function defineTextBlock<const TType extends string>(config: {
541
+ type: TType extends 'span' ? "Error: defineTextBlock({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType;
537
542
  render?: TextBlockRender;
538
543
  of?: ReadonlyArray<Span | InlineObject>;
539
544
  }): TextBlock;
@@ -839,7 +844,7 @@ declare class PortableTextEditor {
839
844
  */
840
845
  static delete: (editor: PortableTextEditor, selection: EditorSelection, options?: EditableAPIDeleteOptions) => void;
841
846
  static findDOMNode: (editor: PortableTextEditor, element: PortableTextBlock | PortableTextChild) => Node | undefined;
842
- static findByPath: (editor: PortableTextEditor, path: Path) => [_portabletext_schema6.PortableTextTextBlock<PortableTextObject | _portabletext_schema6.PortableTextSpan> | PortableTextObject | _portabletext_schema6.PortableTextSpan | undefined, Path | undefined];
847
+ static findByPath: (editor: PortableTextEditor, path: Path) => [import("@portabletext/schema").PortableTextTextBlock<PortableTextObject | import("@portabletext/schema").PortableTextSpan> | PortableTextObject | import("@portabletext/schema").PortableTextSpan | undefined, Path | undefined];
843
848
  /**
844
849
  * @deprecated
845
850
  * Use `editor.send(...)` instead
@@ -1177,7 +1182,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
1177
1182
  * ```
1178
1183
  * @group Components
1179
1184
  */
1180
- declare const PortableTextEditable: react7.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react7.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
1185
+ declare const PortableTextEditable: import("react").ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & import("react").RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
1181
1186
  /** @beta */
1182
1187
  interface EditableAPIDeleteOptions {
1183
1188
  mode?: 'blocks' | 'children' | 'selected';
@@ -1696,7 +1701,7 @@ interface BaseEditor {
1696
1701
  pointRefs: Set<PointRef>;
1697
1702
  rangeRefs: Set<RangeRef>;
1698
1703
  apply: (operation: EngineOperation) => void;
1699
- normalizeNode: (entry: [Editor$1 | Node$1, Path], options?: {
1704
+ normalizeNode: (entry: [Editor | Node$1, Path], options?: {
1700
1705
  operation?: EngineOperation;
1701
1706
  }) => void;
1702
1707
  onChange: (options?: {
@@ -1715,7 +1720,7 @@ interface BaseEditor {
1715
1720
  select: (target: Location) => void;
1716
1721
  setSelection: (props: Partial<Range>) => void;
1717
1722
  }
1718
- type Editor$1 = BaseEditor & DOMEditor & PortableTextEditorEngine;
1723
+ type Editor = BaseEditor & DOMEditor & PortableTextEditorEngine;
1719
1724
  type StringDiff = {
1720
1725
  start: number;
1721
1726
  end: number;
@@ -1749,11 +1754,11 @@ type Action = {
1749
1754
  * A DOM-specific version of the `Editor` interface.
1750
1755
  */
1751
1756
  interface DOMEditor extends BaseEditor {
1752
- hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1753
- hasRange: (editor: Editor$1, range: Range) => boolean;
1754
- hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
1755
- hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1756
- isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
1757
+ hasEditableTarget: (editor: Editor, target: EventTarget | null) => target is DOMNode;
1758
+ hasRange: (editor: Editor, range: Range) => boolean;
1759
+ hasSelectableTarget: (editor: Editor, target: EventTarget | null) => boolean;
1760
+ hasTarget: (editor: Editor, target: EventTarget | null) => target is DOMNode;
1761
+ isTargetInsideNonReadonlyVoid: (editor: Editor, target: EventTarget | null) => boolean;
1757
1762
  isNodeMapDirty: boolean;
1758
1763
  domWindow: Window | null;
1759
1764
  domElement: HTMLElement | null;
@@ -1774,51 +1779,51 @@ interface DOMEditorInterface {
1774
1779
  /**
1775
1780
  * Blur the editor.
1776
1781
  */
1777
- blur: (editor: Editor$1) => void;
1782
+ blur: (editor: Editor) => void;
1778
1783
  /**
1779
1784
  * Find the DOM node that implements DocumentOrShadowRoot for the editor.
1780
1785
  */
1781
- findDocumentOrShadowRoot: (editor: Editor$1) => Document | ShadowRoot;
1786
+ findDocumentOrShadowRoot: (editor: Editor) => Document | ShadowRoot;
1782
1787
  /**
1783
1788
  * Focus the editor.
1784
1789
  */
1785
- focus: (editor: Editor$1, options?: {
1790
+ focus: (editor: Editor, options?: {
1786
1791
  retries: number;
1787
1792
  }) => void;
1788
1793
  /**
1789
1794
  * Return the host window of the current editor.
1790
1795
  */
1791
- getWindow: (editor: Editor$1) => Window;
1796
+ getWindow: (editor: Editor) => Window;
1792
1797
  /**
1793
1798
  * Check if a DOM node is within the editor.
1794
1799
  */
1795
- hasDOMNode: (editor: Editor$1, target: DOMNode, options?: {
1800
+ hasDOMNode: (editor: Editor, target: DOMNode, options?: {
1796
1801
  editable?: boolean;
1797
1802
  }) => boolean;
1798
1803
  /**
1799
1804
  * Check if the target is editable and in the editor.
1800
1805
  */
1801
- hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1806
+ hasEditableTarget: (editor: Editor, target: EventTarget | null) => target is DOMNode;
1802
1807
  /**
1803
1808
  *
1804
1809
  */
1805
- hasRange: (editor: Editor$1, range: Range) => boolean;
1810
+ hasRange: (editor: Editor, range: Range) => boolean;
1806
1811
  /**
1807
1812
  * Check if the target can be selectable
1808
1813
  */
1809
- hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
1814
+ hasSelectableTarget: (editor: Editor, target: EventTarget | null) => boolean;
1810
1815
  /**
1811
1816
  * Check if the target is in the editor.
1812
1817
  */
1813
- hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1818
+ hasTarget: (editor: Editor, target: EventTarget | null) => target is DOMNode;
1814
1819
  /**
1815
1820
  * Check if the target is inside void and in an non-readonly editor.
1816
1821
  */
1817
- isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
1822
+ isTargetInsideNonReadonlyVoid: (editor: Editor, target: EventTarget | null) => boolean;
1818
1823
  /**
1819
1824
  * Find a native DOM selection point from a point.
1820
1825
  */
1821
- toDOMPoint: (editor: Editor$1, point: Point) => DOMPoint;
1826
+ toDOMPoint: (editor: Editor, point: Point) => DOMPoint;
1822
1827
  /**
1823
1828
  * Find a native DOM range from a `range`.
1824
1829
  *
@@ -1827,11 +1832,11 @@ interface DOMEditorInterface {
1827
1832
  * there is no way to create a reverse DOM Range using Range.setStart/setEnd
1828
1833
  * according to https://dom.spec.whatwg.org/#concept-range-bp-set.
1829
1834
  */
1830
- toDOMRange: (editor: Editor$1, range: Range) => DOMRange;
1835
+ toDOMRange: (editor: Editor, range: Range) => DOMRange;
1831
1836
  /**
1832
1837
  * Find a point from a DOM selection's `domNode` and `domOffset`.
1833
1838
  */
1834
- toSelectionPoint: <T extends boolean>(editor: Editor$1, domPoint: DOMPoint, options: {
1839
+ toSelectionPoint: <T extends boolean>(editor: Editor, domPoint: DOMPoint, options: {
1835
1840
  exactMatch: boolean;
1836
1841
  suppressThrow: T;
1837
1842
  /**
@@ -1843,7 +1848,7 @@ interface DOMEditorInterface {
1843
1848
  /**
1844
1849
  * Find a range from a DOM range or selection.
1845
1850
  */
1846
- toEditorSelection: <T extends boolean>(editor: Editor$1, domRange: DOMRange | DOMStaticRange | DOMSelection, options: {
1851
+ toEditorSelection: <T extends boolean>(editor: Editor, domRange: DOMRange | DOMStaticRange | DOMSelection, options: {
1847
1852
  exactMatch: boolean;
1848
1853
  suppressThrow: T;
1849
1854
  }) => T extends true ? Range | null : Range;
@@ -1884,6 +1889,19 @@ interface PortableTextEditorEngine extends DOMEditor {
1884
1889
  * per render, regardless of how many operations a batch applied.
1885
1890
  */
1886
1891
  listIndexMapDirty: boolean;
1892
+ /**
1893
+ * Per-notify pending flags for the segmented selector channels
1894
+ * (`EngineSelectorChannel`). Set where the corresponding state mutates
1895
+ * (registration map swaps in `register-node-on-engine.ts`, list-index
1896
+ * invalidation in the update-value subscriber) and consumed by the
1897
+ * React layer's `onContextChange` dispatch. Separate from
1898
+ * `listIndexMapDirty`, which any read clears via `getListIndexMap`;
1899
+ * these are cleared only when the notification is delivered.
1900
+ */
1901
+ selectorChannelsPending: {
1902
+ registrations: boolean;
1903
+ listIndex: boolean;
1904
+ };
1887
1905
  /**
1888
1906
  * Serialized paths of sibling groups (a node's keyed child array, or the
1889
1907
  * root value array as `''`) whose children have been verified to carry no
@@ -2003,6 +2021,10 @@ type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*`
2003
2021
  *
2004
2022
  */
2005
2023
  declare function defineBehavior<TPayload extends Record<string, unknown>, TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = CustomBehaviorEvent['type'], TGuardResponse = true>(behavior: Behavior<TBehaviorEventType, TGuardResponse, ResolveBehaviorEvent<TBehaviorEventType, TPayload>>): Behavior;
2024
+ type BehaviorConfig = {
2025
+ behavior: Behavior;
2026
+ priority: EditorPriority;
2027
+ };
2006
2028
  /**
2007
2029
  * The document-changing operations emitted through
2008
2030
  * `editor.on('operation', ...)`. Every change to the editor (local edits,
@@ -2115,207 +2137,6 @@ type PatchEvent = {
2115
2137
  type: 'patch';
2116
2138
  patch: Patch;
2117
2139
  };
2118
- /**
2119
- * @public
2120
- */
2121
- type EditorConfig = {
2122
- /**
2123
- * @beta
2124
- */
2125
- keyGenerator?: () => string;
2126
- readOnly?: boolean;
2127
- initialValue?: Array<PortableTextBlock>;
2128
- schemaDefinition: SchemaDefinition;
2129
- };
2130
- /**
2131
- * @public
2132
- */
2133
- type EditorEvent = ExternalEditorEvent | ExternalBehaviorEvent | {
2134
- type: 'update value';
2135
- value: Array<PortableTextBlock> | undefined;
2136
- };
2137
- /**
2138
- * @public
2139
- */
2140
- type Editor = {
2141
- dom: EditorDom;
2142
- getSnapshot: () => EditorSnapshot;
2143
- /**
2144
- * @beta
2145
- */
2146
- registerBehavior: (config: {
2147
- behavior: Behavior;
2148
- }) => () => void;
2149
- /**
2150
- * Register a node renderer. The `node` argument is the result of one
2151
- * of the `defineX` factories (`defineContainer`, `defineTextBlock`,
2152
- * `defineSpan`, `defineBlockObject`, `defineInlineObject`). Returns
2153
- * a function that unregisters the node when called.
2154
- *
2155
- * @alpha
2156
- */
2157
- registerNode: (config: {
2158
- node: RegistrableNode;
2159
- }) => () => void;
2160
- send: (event: EditorEvent) => void;
2161
- /**
2162
- * Register an event listener.
2163
- *
2164
- * With `{batch: true}` the listener is called once per burst with
2165
- * `Array<Event>`, every matching event emitted before control returns to the
2166
- * event loop (one synchronous `editor.send` worth, normalization included),
2167
- * in delivery order, on the trailing microtask. That is the same boundary at
2168
- * which the editor settles its own state, so each call is one fully-applied,
2169
- * normalized change. Without it (the default), the listener runs
2170
- * synchronously for every event and receives a single event.
2171
- */
2172
- on: {
2173
- <TType$1 extends EditorEmittedEvent['type'] | '*'>(type: TType$1, listener: (events: Array<EditorEmittedEvent & (TType$1 extends '*' ? unknown : {
2174
- type: TType$1;
2175
- })>) => void, options: {
2176
- batch: true;
2177
- }): {
2178
- unsubscribe: () => void;
2179
- };
2180
- <TType$1 extends EditorEmittedEvent['type'] | '*'>(type: TType$1, listener: (event: EditorEmittedEvent & (TType$1 extends '*' ? unknown : {
2181
- type: TType$1;
2182
- })) => void, options?: {
2183
- batch?: false;
2184
- }): {
2185
- unsubscribe: () => void;
2186
- };
2187
- };
2188
- /**
2189
- * Subscribe to editor state changes. The observer's `next` callback fires
2190
- * with the current `EditorSnapshot` on relevant transitions (selection
2191
- * updates, content mutations, behavior dispatch, configuration changes).
2192
- *
2193
- * Notifications are coalesced: a synchronous burst of transitions (e.g. the
2194
- * many operations one action applies, like undoing a large delete) delivers
2195
- * a single `next` with the settled snapshot on the next microtask, rather
2196
- * than one `next` per transition. The snapshot is cumulative, so only
2197
- * intermediate per-transition states are skipped. To observe every
2198
- * operation, use `editor.on('operation', ...)`.
2199
- *
2200
- * The editor has no terminal state and no error path, so `error` and
2201
- * `complete` are part of the observable contract but never fire. They are
2202
- * kept for structural compatibility with `useSyncExternalStore`,
2203
- * `@xstate/react`'s `useSelector`, and other observer-shaped consumers.
2204
- */
2205
- subscribe(observer: {
2206
- next?: (snapshot: EditorSnapshot) => void;
2207
- error?: (err: unknown) => void;
2208
- complete?: () => void;
2209
- }): {
2210
- unsubscribe: () => void;
2211
- };
2212
- };
2213
- /**
2214
- * @public
2215
- */
2216
- type EditorProviderProps = {
2217
- initialConfig: EditorConfig;
2218
- children?: React$1.ReactNode;
2219
- };
2220
- /**
2221
- * @public
2222
- * The EditorProvider component is used to set up the editor context and configure the Portable Text Editor.
2223
- * @example
2224
- * ```tsx
2225
- * import {EditorProvider} from '@portabletext/editor'
2226
- *
2227
- * function App() {
2228
- * return (
2229
- * <EditorProvider initialConfig={{ ... }} >
2230
- * ...
2231
- * </EditorProvider>
2232
- * )
2233
- * }
2234
- *
2235
- * ```
2236
- * @group Components
2237
- */
2238
- declare function EditorProvider(props: EditorProviderProps): React$1.JSX.Element;
2239
- /**
2240
- * @public
2241
- */
2242
- type EditorSelector<TSelected> = (snapshot: EditorSnapshot) => TSelected;
2243
- /**
2244
- * @public
2245
- * Hook to select a value from the editor state.
2246
- * @example
2247
- * Pass a selector as the second argument
2248
- * ```tsx
2249
- * import { useEditorSelector } from '@portabletext/editor'
2250
- *
2251
- * function MyComponent(editor) {
2252
- * const value = useEditorSelector(editor, selector)
2253
- * }
2254
- * ```
2255
- * @example
2256
- * Pass an inline selector as the second argument.
2257
- * In this case, use the editor context to obtain the schema.
2258
- * ```tsx
2259
- * import { useEditorSelector } from '@portabletext/editor'
2260
- *
2261
- * function MyComponent(editor) {
2262
- * const schema = useEditorSelector(editor, (snapshot) => snapshot.context.schema)
2263
- * }
2264
- * ```
2265
- * @group Hooks
2266
- */
2267
- declare function useEditorSelector<TSelected>(editor: Editor, selector: EditorSelector<TSelected>, compare?: (a: TSelected, b: TSelected) => boolean): TSelected;
2268
- /**
2269
- * @deprecated Use `useEditor` to get the current editor instance.
2270
- * @public
2271
- * Get the current editor object from the React context.
2272
- */
2273
- declare const usePortableTextEditor: () => PortableTextEditor;
2274
- /**
2275
- * @deprecated Use `useEditorSelector` to get the current editor selection.
2276
- * @public
2277
- * Get the current editor selection from the React context.
2278
- */
2279
- declare const usePortableTextEditorSelection: () => EditorSelection;
2280
- /**
2281
- * @public
2282
- */
2283
- declare const defaultKeyGenerator: () => string;
2284
- /**
2285
- * @public
2286
- * Get the current editor context from the `EditorProvider`.
2287
- * Must be used inside the `EditorProvider` component.
2288
- * @returns The current editor object.
2289
- * @example
2290
- * ```tsx
2291
- * import { useEditor } from '@portabletext/editor'
2292
- *
2293
- * function MyComponent() {
2294
- * const editor = useEditor()
2295
- * }
2296
- * ```
2297
- * @group Hooks
2298
- */
2299
- declare function useEditor(): Editor;
2300
- /**
2301
- * @beta
2302
- */
2303
- type BlockOffset = {
2304
- path: BlockPath;
2305
- offset: number;
2306
- };
2307
- type EditorPriority = {
2308
- id: string;
2309
- name?: string;
2310
- reference?: {
2311
- priority: EditorPriority;
2312
- importance: 'higher' | 'lower';
2313
- };
2314
- };
2315
- type BehaviorConfig = {
2316
- behavior: Behavior;
2317
- priority: EditorPriority;
2318
- };
2319
2140
  /**
2320
2141
  * @public
2321
2142
  */
@@ -2342,7 +2163,7 @@ type EditorActor = ActorRefFrom<typeof editorMachine>;
2342
2163
  /**
2343
2164
  * @internal
2344
2165
  */
2345
- declare const editorMachine: xstate31.StateMachine<{
2166
+ declare const editorMachine: import("xstate").StateMachine<{
2346
2167
  behaviors: Set<BehaviorConfig>;
2347
2168
  behaviorsSorted: boolean;
2348
2169
  initialConverters: Array<Converter>;
@@ -2415,55 +2236,55 @@ declare const editorMachine: xstate31.StateMachine<{
2415
2236
  params: unknown;
2416
2237
  } | {
2417
2238
  type: "add behavior to context";
2418
- params: xstate31.NonReducibleUnknown;
2239
+ params: import("xstate").NonReducibleUnknown;
2419
2240
  } | {
2420
2241
  type: "remove behavior from context";
2421
- params: xstate31.NonReducibleUnknown;
2242
+ params: import("xstate").NonReducibleUnknown;
2422
2243
  } | {
2423
2244
  type: "add editor engine to context";
2424
- params: xstate31.NonReducibleUnknown;
2245
+ params: import("xstate").NonReducibleUnknown;
2425
2246
  } | {
2426
2247
  type: "attach maps to editor engine";
2427
2248
  params: unknown;
2428
2249
  } | {
2429
2250
  type: "emit patch event";
2430
- params: xstate31.NonReducibleUnknown;
2251
+ params: import("xstate").NonReducibleUnknown;
2431
2252
  } | {
2432
2253
  type: "emit mutation event";
2433
- params: xstate31.NonReducibleUnknown;
2254
+ params: import("xstate").NonReducibleUnknown;
2434
2255
  } | {
2435
2256
  type: "emit read only";
2436
- params: xstate31.NonReducibleUnknown;
2257
+ params: import("xstate").NonReducibleUnknown;
2437
2258
  } | {
2438
2259
  type: "emit editable";
2439
- params: xstate31.NonReducibleUnknown;
2260
+ params: import("xstate").NonReducibleUnknown;
2440
2261
  } | {
2441
2262
  type: "defer event";
2442
- params: xstate31.NonReducibleUnknown;
2263
+ params: import("xstate").NonReducibleUnknown;
2443
2264
  } | {
2444
2265
  type: "emit pending events";
2445
- params: xstate31.NonReducibleUnknown;
2266
+ params: import("xstate").NonReducibleUnknown;
2446
2267
  } | {
2447
2268
  type: "emit ready";
2448
- params: xstate31.NonReducibleUnknown;
2269
+ params: import("xstate").NonReducibleUnknown;
2449
2270
  } | {
2450
2271
  type: "clear pending events";
2451
- params: xstate31.NonReducibleUnknown;
2272
+ params: import("xstate").NonReducibleUnknown;
2452
2273
  } | {
2453
2274
  type: "discard conflicting pending patches";
2454
- params: xstate31.NonReducibleUnknown;
2275
+ params: import("xstate").NonReducibleUnknown;
2455
2276
  } | {
2456
2277
  type: "discard all pending events";
2457
- params: xstate31.NonReducibleUnknown;
2278
+ params: import("xstate").NonReducibleUnknown;
2458
2279
  } | {
2459
2280
  type: "defer incoming patches";
2460
- params: xstate31.NonReducibleUnknown;
2281
+ params: import("xstate").NonReducibleUnknown;
2461
2282
  } | {
2462
2283
  type: "emit pending incoming patches";
2463
- params: xstate31.NonReducibleUnknown;
2284
+ params: import("xstate").NonReducibleUnknown;
2464
2285
  } | {
2465
2286
  type: "clear pending incoming patches";
2466
- params: xstate31.NonReducibleUnknown;
2287
+ params: import("xstate").NonReducibleUnknown;
2467
2288
  } | {
2468
2289
  type: "handle blur";
2469
2290
  params: unknown;
@@ -2475,7 +2296,7 @@ declare const editorMachine: xstate31.StateMachine<{
2475
2296
  params: unknown;
2476
2297
  } | {
2477
2298
  type: "sort behaviors";
2478
- params: xstate31.NonReducibleUnknown;
2299
+ params: import("xstate").NonReducibleUnknown;
2479
2300
  }, {
2480
2301
  type: "engine is busy";
2481
2302
  params: unknown;
@@ -2504,9 +2325,9 @@ declare const editorMachine: xstate31.StateMachine<{
2504
2325
  readOnly?: boolean;
2505
2326
  schema: EditorSchema;
2506
2327
  initialValue?: Array<PortableTextBlock>;
2507
- }, xstate31.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
2328
+ }, import("xstate").NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
2508
2329
  type: "blurred";
2509
- event: react7.FocusEvent<HTMLDivElement, Element>;
2330
+ event: import("react").FocusEvent<HTMLDivElement, Element>;
2510
2331
  } | {
2511
2332
  type: "done loading";
2512
2333
  } | {
@@ -2518,16 +2339,16 @@ declare const editorMachine: xstate31.StateMachine<{
2518
2339
  data: unknown;
2519
2340
  } | {
2520
2341
  type: "focused";
2521
- event: react7.FocusEvent<HTMLDivElement, Element>;
2342
+ event: import("react").FocusEvent<HTMLDivElement, Element>;
2522
2343
  } | {
2523
2344
  type: "invalid value";
2524
- resolution: InvalidValueResolution | null;
2345
+ resolution: import("..").InvalidValueResolution | null;
2525
2346
  value: Array<PortableTextBlock> | undefined;
2526
2347
  } | {
2527
2348
  type: "loading";
2528
2349
  } | {
2529
2350
  type: "operation";
2530
- operation: Operation;
2351
+ operation: import("..").Operation;
2531
2352
  } | {
2532
2353
  type: "read only";
2533
2354
  } | {
@@ -2538,7 +2359,7 @@ declare const editorMachine: xstate31.StateMachine<{
2538
2359
  } | {
2539
2360
  type: "value changed";
2540
2361
  value: Array<PortableTextBlock> | undefined;
2541
- }, xstate31.MetaObject, {
2362
+ }, import("xstate").MetaObject, {
2542
2363
  id: "editor";
2543
2364
  states: {
2544
2365
  readonly 'edit mode': {
@@ -2621,12 +2442,12 @@ type ChildWithOptionalKey = SpanWithOptionalKey | ObjectBlockWithOptionalKey;
2621
2442
  */
2622
2443
  type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent | CustomBehaviorEvent;
2623
2444
  type BehaviorEventTypeNamespace = SyntheticBehaviorEventNamespace | NativeBehaviorEventNamespace | CustomBehaviorEventNamespace;
2624
- type NamespacedBehaviorEventType<TNamespace$1 extends BehaviorEventTypeNamespace | ''> = TNamespace$1 extends '' ? BehaviorEvent['type'] : Extract<BehaviorEvent['type'], TNamespace$1 | `${TNamespace$1}.${string}`>;
2445
+ type NamespacedBehaviorEventType<TNamespace extends BehaviorEventTypeNamespace | ''> = TNamespace extends '' ? BehaviorEvent['type'] : Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>;
2625
2446
  /**************************************
2626
2447
  * External events
2627
2448
  **************************************/
2628
2449
  type ExternalBehaviorEventNamespace = 'blur' | 'focus' | 'insert';
2629
- type ExternalBehaviorEventType<TNamespace$1 extends ExternalBehaviorEventNamespace, TType$1 extends string = ''> = TType$1 extends '' ? `${TNamespace$1}` : `${TNamespace$1}.${TType$1}`;
2450
+ type ExternalBehaviorEventType<TNamespace extends ExternalBehaviorEventNamespace, TType extends string = ''> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`;
2630
2451
  type ExternalBehaviorEvent = {
2631
2452
  type: ExternalBehaviorEventType<'blur'>;
2632
2453
  } | {
@@ -3106,23 +2927,38 @@ type MouseBehaviorEvent = {
3106
2927
  * Custom events
3107
2928
  **************************************/
3108
2929
  type CustomBehaviorEventNamespace = 'custom';
3109
- type CustomBehaviorEventType<TNamespace$1 extends CustomBehaviorEventNamespace, TType$1 extends string = ''> = TType$1 extends '' ? `${TNamespace$1}` : `${TNamespace$1}.${TType$1}`;
2930
+ type CustomBehaviorEventType<TNamespace extends CustomBehaviorEventNamespace, TType extends string = ''> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`;
3110
2931
  /**
3111
2932
  * @beta
3112
2933
  */
3113
- type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<string, unknown>, TType$1 extends string = string, TInternalType extends CustomBehaviorEventType<'custom', TType$1> = CustomBehaviorEventType<'custom', TType$1>> = {
2934
+ type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<string, unknown>, TType extends string = string, TInternalType extends CustomBehaviorEventType<'custom', TType> = CustomBehaviorEventType<'custom', TType>> = {
3114
2935
  type: TInternalType;
3115
2936
  } & TPayload;
3116
2937
  /**************************************
3117
2938
  * Resolve behavior event
3118
2939
  **************************************/
3119
2940
  type ResolveBehaviorEvent<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TPayload extends Record<string, unknown> = Record<string, unknown>> = TBehaviorEventType extends '*' ? BehaviorEvent : TBehaviorEventType extends `${infer TNamespace}.*` ? TNamespace extends BehaviorEventTypeNamespace ? PickFromUnion<BehaviorEvent, 'type', NamespacedBehaviorEventType<TNamespace>> : never : TBehaviorEventType extends `custom.${infer TType}` ? CustomBehaviorEvent<TPayload, TType> : TBehaviorEventType extends BehaviorEvent['type'] ? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType> : never;
3120
- type ExtractNamespace<TType$1 extends string> = TType$1 extends `${infer Namespace}.${string}` ? Namespace : TType$1;
2941
+ type ExtractNamespace<TType extends string> = TType extends `${infer Namespace}.${string}` ? Namespace : TType;
3121
2942
  type EditorDom = {
3122
2943
  getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>;
3123
2944
  getChildNodes: (snapshot: EditorSnapshot) => Array<Node>;
3124
2945
  getEditorElement: () => Element | undefined;
2946
+ /**
2947
+ * The bounding rect of the snapshot's selection. A collapsed selection gives
2948
+ * a caret rect.
2949
+ */
3125
2950
  getSelectionRect: (snapshot: EditorSnapshot) => DOMRect | null;
2951
+ /**
2952
+ * Resolves viewport (client) coordinates to the editor point where a click
2953
+ * at those coordinates would place the caret. The browser snaps to the
2954
+ * nearest position within the element at the coordinates. Returns `null`
2955
+ * when the coordinates don't resolve to a position inside the editor's
2956
+ * content.
2957
+ */
2958
+ getPointAtCoordinates: (coordinates: {
2959
+ x: number;
2960
+ y: number;
2961
+ }) => EditorSelectionPoint | null;
3126
2962
  getStartBlockElement: (snapshot: EditorSnapshot) => Element | null;
3127
2963
  getEndBlockElement: (snapshot: EditorSnapshot) => Element | null;
3128
2964
  /**
@@ -3322,5 +3158,5 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
3322
3158
  event: TBehaviorEvent;
3323
3159
  dom: EditorDom;
3324
3160
  }, guardResponse: TGuardResponse) => Array<BehaviorAction>;
3325
- export { EditorContext as $, SpanRender as $t, PortableTextTextBlock$1 as A, HotkeyOptions as At, EditorSelector as B, RegisteredPositional as Bt, ListDefinition as C, RenderEditableFunction as Ct, PortableTextChild$1 as D, ScrollSelectionIntoViewFunction as Dt, PortableTextBlock$1 as E, RenderStyleFunction as Et, BlockOffset as F, EditorSchema as Ft, EditorConfig as G, Container as Gt, EditorProvider as H, BlockObject as Ht, useEditor as I, Containers as It, MutationEvent as J, InlineObject as Jt, EditorEvent as K, ContainerRender as Kt, defaultKeyGenerator as L, RegisteredBlockObject as Lt, StyleDefinition as M, resolveContainerAt as Mt, StyleSchemaType$1 as N, TraversalSnapshot as Nt, PortableTextObject$1 as O, PortableTextEditable as Ot, defineSchema as P, Node$1 as Pt, BehaviorGuard as Q, Span as Qt, usePortableTextEditorSelection as R, RegisteredContainer as Rt, InlineObjectSchemaType$1 as S, RenderDecoratorFunction as St, Patch$1 as T, RenderPlaceholderFunction as Tt, EditorProviderProps as U, BlockObjectRender as Ut, useEditorSelector as V, RegisteredSpan as Vt, Editor as W, BlockObjectRenderProps as Wt, Behavior as X, InlineObjectRenderProps as Xt, Operation as Y, InlineObjectRender as Yt, defineBehavior as Z, RegistrableNode as Zt, BlockObjectSchemaType$1 as _, RangeDecoration as _t, forward as a, defineContainer as an, BlockListItemRenderProps as at, FieldDefinition$1 as b, RenderBlockFunction as bt, CustomBehaviorEvent as c, defineTextBlock as cn, EditableAPIDeleteOptions as ct, SyntheticBehaviorEvent as d, ChildPath as dn, InvalidValueResolution as dt, SpanRenderProps as en, EditorSnapshot as et, PatchesEvent as f, KeyedSegment as fn, OnCopyFn as ft, BlockObjectDefinition as g, PasteData as gt, BaseDefinition as h, OnPasteResultOrPromise as ht, execute as i, defineBlockObject as in, BlockDecoratorRenderProps as it, SchemaDefinition$1 as j, PortableTextEditor as jt, PortableTextSpan$1 as k, PortableTextEditableProps as kt, InsertPlacement as l, AnnotationPath as ln, EditorSelection as lt, AnnotationSchemaType$1 as m, OnPasteResult as mt, BehaviorActionSet as n, TextBlockRender as nn, BlockAnnotationRenderProps as nt, raise as o, defineInlineObject as on, BlockRenderProps as ot, AnnotationDefinition as p, Path as pn, OnPasteFn as pt, EditorEmittedEvent as q, ContainerRenderProps as qt, effect as r, TextBlockRenderProps as rn, BlockChildRenderProps as rt, BehaviorEvent as s, defineSpan as sn, BlockStyleRenderProps as st, BehaviorAction as t, TextBlock as tn, AddedAnnotationPaths as tt, NativeBehaviorEvent as u, BlockPath as un, EditorSelectionPoint as ut, DecoratorDefinition as v, RangeDecorationOnMovedDetails as vt, ListSchemaType$1 as w, RenderListItemFunction as wt, InlineObjectDefinition as x, RenderChildFunction as xt, DecoratorSchemaType$1 as y, RenderAnnotationFunction as yt, usePortableTextEditor as z, RegisteredInlineObject as zt };
3161
+ export { HotkeyOptions as $, BlockStyleRenderProps as A, defineSpan as At, RangeDecoration as B, EditorSnapshot as C, SpanRenderProps as Ct, BlockDecoratorRenderProps as D, defineBlockObject as Dt, BlockChildRenderProps as E, TextBlockRenderProps as Et, OnCopyFn as F, KeyedSegment as Ft, RenderDecoratorFunction as G, RenderAnnotationFunction as H, OnPasteFn as I, Path as It, RenderPlaceholderFunction as J, RenderEditableFunction as K, OnPasteResult as L, EditorSelection as M, AnnotationPath as Mt, EditorSelectionPoint as N, BlockPath as Nt, BlockListItemRenderProps as O, defineContainer as Ot, InvalidValueResolution as P, ChildPath as Pt, PortableTextEditableProps as Q, OnPasteResultOrPromise as R, EditorContext as S, SpanRender as St, BlockAnnotationRenderProps as T, TextBlockRender as Tt, RenderBlockFunction as U, RangeDecorationOnMovedDetails as V, RenderChildFunction as W, ScrollSelectionIntoViewFunction as X, RenderStyleFunction as Y, PortableTextEditable as Z, MutationEvent as _, InlineObject as _t, forward as a, Containers as at, defineBehavior as b, RegistrableNode as bt, BehaviorEvent as c, RegisteredInlineObject as ct, InsertPlacement as d, BlockObject as dt, PortableTextEditor as et, NativeBehaviorEvent as f, BlockObjectRender as ft, EditorEmittedEvent as g, ContainerRenderProps as gt, PatchesEvent as h, ContainerRender as ht, execute as i, EditorSchema as it, EditableAPIDeleteOptions as j, defineTextBlock as jt, BlockRenderProps as k, defineInlineObject as kt, CustomBehaviorEvent as l, RegisteredPositional as lt, ExternalEditorEvent as m, Container as mt, BehaviorActionSet as n, TraversalSnapshot as nt, raise as o, RegisteredBlockObject as ot, SyntheticBehaviorEvent as p, BlockObjectRenderProps as pt, RenderListItemFunction as q, effect as r, Node$1 as rt, EditorDom as s, RegisteredContainer as st, BehaviorAction as t, resolveContainerAt as tt, ExternalBehaviorEvent as u, RegisteredSpan as ut, Operation as v, InlineObjectRender as vt, AddedAnnotationPaths as w, TextBlock as wt, BehaviorGuard as x, Span as xt, Behavior as y, InlineObjectRenderProps as yt, PasteData as z };
3326
3162
  //# sourceMappingURL=behavior.types.action.d.ts.map