@portabletext/editor 7.1.0 → 7.2.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.
@@ -1,6 +1,5 @@
1
- import { A as ChildPath, D as Path$1, M as Path, O as AnnotationPath, _ as RegistrableNode, a as Containers, d as ResolvedContainers, g as InlineObjectConfig, i as EditorSchema, k as BlockPath, p as BlockObjectConfig, r as Node$1, x as TextBlockConfig, y as SpanConfig } from "./resolve-containers.js";
2
- import * as _portabletext_schema6 from "@portabletext/schema";
3
- import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition as FieldDefinition$1, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, 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";
1
+ import * as _portabletext_schema5 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";
4
3
  import * as xstate35 from "xstate";
5
4
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
6
5
  import * as react4 from "react";
@@ -59,6 +58,690 @@ type Deserializer<TMIMEType extends MIMEType> = ({
59
58
  snapshot: EditorSnapshot;
60
59
  event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>;
61
60
  }) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialization.success' | 'deserialization.failure'>;
61
+ /**
62
+ * A segment in a path that identifies an element by its `_key` property.
63
+ * @public
64
+ */
65
+ interface KeyedSegment {
66
+ _key: string;
67
+ }
68
+ /**
69
+ * A tuple representing a range selection, e.g., `[0, 5]` or `['', 3]`.
70
+ * @public
71
+ */
72
+ type IndexTuple = [number | '', number | ''];
73
+ /**
74
+ * A single segment in a path. Can be:
75
+ * - A string (property name)
76
+ * - A number (array index)
77
+ * - A KeyedSegment (object with `_key`)
78
+ * - An IndexTuple (range selection)
79
+ * @public
80
+ */
81
+ type PathSegment$1 = string | number | KeyedSegment | IndexTuple;
82
+ /**
83
+ * A path is an array of path segments that describes a location in a document.
84
+ * @public
85
+ */
86
+ type Path = PathSegment$1[];
87
+ /**
88
+ * A path to a block in the value.
89
+ *
90
+ * @public
91
+ */
92
+ type BlockPath = Path;
93
+ /**
94
+ * A path to an annotation markDef on a block.
95
+ *
96
+ * @public
97
+ */
98
+ type AnnotationPath = Path;
99
+ /**
100
+ * A path to a child of a text block.
101
+ *
102
+ * @public
103
+ */
104
+ type ChildPath = Path;
105
+ /**
106
+ * A path segment identifies a position in the document tree.
107
+ *
108
+ * - `KeyedSegment` (`{_key: string}`) identifies a node by its key
109
+ * - `string` identifies a child field name (e.g. 'children', 'rows', 'cells')
110
+ * - `number` identifies a position in an array (used for empty container inserts
111
+ * and rendering indexed paths)
112
+ * - `IndexTuple` (`[number | '', number | '']`) represents a range selection
113
+ */
114
+ type PathSegment = KeyedSegment | string | number | IndexTuple;
115
+ /**
116
+ * A `Path` is a list of segments that describe a node's exact position in
117
+ * the document tree. Segments alternate between keyed node references and
118
+ * field names: `[{_key: 'b1'}, 'children', {_key: 's1'}]`.
119
+ */
120
+ type Path$1 = PathSegment[];
121
+ /**
122
+ * @alpha
123
+ *
124
+ * Narrow the container node type by the registered `_type`. Containers
125
+ * always render portable text objects: `'span'` is always a leaf and
126
+ * `'block'` is always a text block; both are excluded.
127
+ */
128
+ type ContainerNodeForType<TType$1 extends string> = TType$1 extends 'span' | 'block' ? never : PortableTextObject;
129
+ /**
130
+ * @alpha
131
+ *
132
+ * A container's render function receives a node and renders an element
133
+ * that wraps its editable children. The render is positional: it fires for
134
+ * nodes of `type` whose parent permits this container at `arrayField`.
135
+ *
136
+ * `node` is `PortableTextObject` because containers cannot register the
137
+ * built-in `'span'` or `'block'` types (those are leaves and text blocks
138
+ * respectively).
139
+ */
140
+ type ContainerRenderProps = {
141
+ attributes: Record<string, unknown>;
142
+ children: ReactElement;
143
+ focused: boolean;
144
+ node: PortableTextObject;
145
+ path: Path$1;
146
+ readOnly: boolean;
147
+ selected: boolean;
148
+ /**
149
+ * Render this position with the engine's default wrapper. Call from
150
+ * inside a custom render to fall back to or wrap the default:
151
+ *
152
+ * ```ts
153
+ * render: ({renderDefault, ...rest}) => renderDefault(rest)
154
+ * ```
155
+ *
156
+ * The default is the engine's minimal wrapper. It does not chain
157
+ * back to a globally-registered render: PTE has one user layer plus
158
+ * positional overrides, and the engine default is the canonical
159
+ * fallback at any position.
160
+ */
161
+ renderDefault: (props: ContainerRenderProps) => ReactElement;
162
+ };
163
+ type ContainerRender = (props: ContainerRenderProps) => ReactElement;
164
+ /**
165
+ * @alpha
166
+ *
167
+ * A span's render function. Receives a portable text span node and
168
+ * wraps it. `children` carries the styled text already decorated by
169
+ * `renderDecorator`/`renderAnnotation`/range decorations.
170
+ */
171
+ type SpanRenderProps = {
172
+ attributes: Record<string, unknown>;
173
+ children: ReactElement;
174
+ focused: boolean;
175
+ node: PortableTextSpan;
176
+ path: Path$1;
177
+ readOnly: boolean;
178
+ selected: boolean;
179
+ /**
180
+ * Render this position with the engine's default wrapper.
181
+ * See {@link ContainerRenderProps.renderDefault}.
182
+ */
183
+ renderDefault: (props: SpanRenderProps) => ReactElement;
184
+ };
185
+ type SpanRender = (props: SpanRenderProps) => ReactElement;
186
+ /**
187
+ * @alpha
188
+ *
189
+ * A block object's render function. Receives a non-editable block-level
190
+ * portable text object. `children` carries an engine-emitted void
191
+ * spacer that the browser uses to anchor the caret next to the
192
+ * element. Dropping `children` makes the caret unable to land on the
193
+ * element.
194
+ */
195
+ type BlockObjectRenderProps = {
196
+ attributes: Record<string, unknown>;
197
+ children: ReactElement;
198
+ focused: boolean;
199
+ node: PortableTextObject;
200
+ path: Path$1;
201
+ readOnly: boolean;
202
+ selected: boolean;
203
+ /**
204
+ * Render this position with the engine's default wrapper.
205
+ * See {@link ContainerRenderProps.renderDefault}.
206
+ */
207
+ renderDefault: (props: BlockObjectRenderProps) => ReactElement;
208
+ };
209
+ type BlockObjectRender = (props: BlockObjectRenderProps) => ReactElement;
210
+ /**
211
+ * @alpha
212
+ *
213
+ * An inline object's render function. Receives a non-editable inline
214
+ * portable text object. `children` carries an engine-emitted void
215
+ * spacer that the browser uses to anchor the caret next to the
216
+ * element. Dropping `children` makes the caret unable to land on the
217
+ * element.
218
+ */
219
+ type InlineObjectRenderProps = {
220
+ attributes: Record<string, unknown>;
221
+ children: ReactElement;
222
+ focused: boolean;
223
+ node: PortableTextObject;
224
+ path: Path$1;
225
+ readOnly: boolean;
226
+ selected: boolean;
227
+ /**
228
+ * Render this position with the engine's default wrapper.
229
+ * See {@link ContainerRenderProps.renderDefault}.
230
+ */
231
+ renderDefault: (props: InlineObjectRenderProps) => ReactElement;
232
+ };
233
+ type InlineObjectRender = (props: InlineObjectRenderProps) => ReactElement;
234
+ /**
235
+ * @alpha
236
+ *
237
+ * A container registration. Identifies a block object `_type` whose value
238
+ * holds editable children in `arrayField`. The optional `of` array carries
239
+ * nested registrations that override how immediate children of this
240
+ * container render at this lexical scope.
241
+ *
242
+ * `of` overrides apply ONE level down only. Children at deeper levels fall
243
+ * through to global registrations.
244
+ *
245
+ * The `kind` field is injected by `defineContainer` and discriminates
246
+ * containers from other registration kinds at runtime.
247
+ */
248
+ type Container = {
249
+ kind: 'container';
250
+ type: string;
251
+ arrayField: string;
252
+ /**
253
+ * Outer render. Two modes:
254
+ * - omitted: fall through to global registered render (or engine default)
255
+ * - function: use this render. The function receives a `renderDefault`
256
+ * prop that returns the engine default when called.
257
+ */
258
+ render?: ContainerRender;
259
+ /**
260
+ * Block-level positional overrides. Inline-content kinds (`Span`,
261
+ * `InlineObject`) belong in `TextBlock.of`, not here.
262
+ */
263
+ of?: ReadonlyArray<Container | TextBlock | BlockObject>;
264
+ };
265
+ /**
266
+ * @alpha
267
+ *
268
+ * A text block registration. The text block `_type` is `'block'` at the
269
+ * top level. Positional overrides nested in a container's `of` array can
270
+ * register a different `_type` to render at that lexical scope.
271
+ *
272
+ * `defineTextBlock` opts the text block into the new render pipeline.
273
+ * The consumer's `render` callback owns the outer wrapper entirely:
274
+ * the engine emits `data-pt-*` attributes only - no `pt-*` CSS classes,
275
+ * no legacy `data-block-*` attributes - and the block-level
276
+ * `renderStyle`/`renderListItem`/`renderBlock` props on
277
+ * `<PortableTextEditable>` do not compose under this registration.
278
+ *
279
+ * Span-level render props - `renderDecorator`, `renderAnnotation`,
280
+ * `renderPlaceholder`, and range decorations - keep working. They fire
281
+ * on the spans inside `children` regardless of which text block outer
282
+ * wrapper renders them.
283
+ */
284
+ type TextBlock = {
285
+ kind: 'textBlock';
286
+ type: string;
287
+ /**
288
+ * Outer render. Two modes:
289
+ * - omitted: fall through to global registered render (or engine default)
290
+ * - function: use this render. The function receives a `renderDefault`
291
+ * prop that returns the engine default when called.
292
+ */
293
+ render?: TextBlockRender;
294
+ /**
295
+ * Inline-content positional overrides. A `Span` or `InlineObject`
296
+ * placed here scopes the inline render to this text block (or any
297
+ * text block of this `type` if registered at the top level).
298
+ */
299
+ of?: ReadonlyArray<Span | InlineObject>;
300
+ };
301
+ /**
302
+ * @alpha
303
+ *
304
+ * Text block render function. `children` carries the rendered spans -
305
+ * `renderDecorator`, `renderAnnotation`, `renderPlaceholder`, and range
306
+ * decorations have already fired at the leaf level. The render's job
307
+ * is the outer wrapper element and any block-level composition (style,
308
+ * list-item) the consumer wants.
309
+ */
310
+ type TextBlockRenderProps = {
311
+ attributes: Record<string, unknown>;
312
+ children: ReactElement;
313
+ focused: boolean;
314
+ node: PortableTextTextBlock;
315
+ path: Path$1;
316
+ readOnly: boolean;
317
+ selected: boolean;
318
+ /**
319
+ * Render this position with the engine's default wrapper.
320
+ * See {@link ContainerRenderProps.renderDefault}.
321
+ */
322
+ renderDefault: (props: TextBlockRenderProps) => ReactElement;
323
+ };
324
+ type TextBlockRender = (props: TextBlockRenderProps) => ReactElement;
325
+ /**
326
+ * @alpha
327
+ *
328
+ * A span registration. The span `_type` is `'span'` at the top level.
329
+ * Positional overrides nested in a container's `of` array can register
330
+ * a different `_type` for a span-like inline at that lexical scope
331
+ * (e.g. a `code-span` inside a `code-block`).
332
+ */
333
+ type Span = {
334
+ kind: 'span';
335
+ type: string;
336
+ /**
337
+ * Outer render. Two modes:
338
+ * - omitted: fall through to global registered render (or engine default)
339
+ * - function: use this render. The function receives a `renderDefault`
340
+ * prop that returns the engine default when called.
341
+ */
342
+ render?: SpanRender;
343
+ };
344
+ /**
345
+ * @alpha
346
+ *
347
+ * A non-editable block-level object registration. Identifies a `_type`
348
+ * whose value renders as a block-level void node (image, embed, etc.).
349
+ */
350
+ type BlockObject = {
351
+ kind: 'blockObject';
352
+ type: string;
353
+ /**
354
+ * Outer render. Two modes:
355
+ * - omitted: fall through to global registered render (or engine default)
356
+ * - function: use this render. The function receives a `renderDefault`
357
+ * prop that returns the engine default when called.
358
+ */
359
+ render?: BlockObjectRender;
360
+ };
361
+ /**
362
+ * @alpha
363
+ *
364
+ * A non-editable inline object registration. Identifies a `_type` whose
365
+ * value renders as an inline void node (mention, inline image, etc.).
366
+ */
367
+ type InlineObject = {
368
+ kind: 'inlineObject';
369
+ type: string;
370
+ /**
371
+ * Outer render. Two modes:
372
+ * - omitted: fall through to global registered render (or engine default)
373
+ * - function: use this render. The function receives a `renderDefault`
374
+ * prop that returns the engine default when called.
375
+ */
376
+ render?: InlineObjectRender;
377
+ };
378
+ /**
379
+ * @alpha
380
+ *
381
+ * The discriminated union of every registration accepted by
382
+ * `editor.registerNode` and the `<NodePlugin>` component.
383
+ */
384
+ type RegistrableNode = Container | TextBlock | Span | BlockObject | InlineObject;
385
+ /**
386
+ * @alpha
387
+ *
388
+ * Define a container renderer. The returned registration is mounted via
389
+ * the `<NodePlugin>` component at the top level, or nested inside
390
+ * another container's `of` array as a positional override.
391
+ *
392
+ * `type` cannot be `'span'` (use {@link defineSpan}) nor `'block'` (use
393
+ * {@link defineTextBlock}). The text block is not a container.
394
+ *
395
+ * The `node` argument of `render` narrows to a portable text object.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * defineContainer({
400
+ * type: 'table',
401
+ * arrayField: 'rows',
402
+ * render: ({children}) => (
403
+ * <table>{children}</table>
404
+ * ),
405
+ * of: [
406
+ * defineContainer({
407
+ * type: 'row',
408
+ * arrayField: 'cells',
409
+ * render: ({children}) => (
410
+ * <tr>{children}</tr>
411
+ * ),
412
+ * }),
413
+ * ],
414
+ * })
415
+ * ```
416
+ */
417
+ declare function defineContainer<const TType$1 extends string>(config: {
418
+ 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;
419
+ arrayField: string;
420
+ render?: (props: {
421
+ attributes: Record<string, unknown>;
422
+ children: ReactElement;
423
+ focused: boolean;
424
+ node: ContainerNodeForType<TType$1>;
425
+ path: Path$1;
426
+ readOnly: boolean;
427
+ selected: boolean;
428
+ renderDefault: (props: ContainerRenderProps) => ReactElement;
429
+ }) => ReactElement;
430
+ of?: ReadonlyArray<Container | TextBlock | BlockObject>;
431
+ }): Container;
432
+ /**
433
+ * @alpha
434
+ *
435
+ * Define a span renderer. The returned registration is mounted via the
436
+ * `<NodePlugin>` component at the top level, or nested inside a
437
+ * container's `of` array as a positional override.
438
+ *
439
+ * `type` is required even though there is only one top-level span type
440
+ * (`'span'`) today. Keeping `type` required leaves the door open for
441
+ * positional overrides of span-like inlines (e.g. a `code-span` inside
442
+ * a `code-block` container).
443
+ *
444
+ * @example
445
+ * ```ts
446
+ * defineSpan({
447
+ * type: 'span',
448
+ * render: ({attributes, children}) => (
449
+ * <span {...attributes}>{children}</span>
450
+ * ),
451
+ * })
452
+ * ```
453
+ */
454
+ declare function defineSpan<const TType$1 extends string>(config: {
455
+ type: TType$1 extends 'block' ? "Error: defineSpan({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1;
456
+ render?: SpanRender;
457
+ }): Span;
458
+ /**
459
+ * @alpha
460
+ *
461
+ * Define a non-editable block-level object renderer for a `_type`
462
+ * declared in the schema's `blockObjects` array.
463
+ *
464
+ * The render must always render `children` somewhere inside the outer
465
+ * element. `children` carries an engine-emitted void spacer the browser
466
+ * uses to anchor the caret next to the element. Dropping `children`
467
+ * makes the caret unable to land on the element.
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * defineBlockObject({
472
+ * type: 'image',
473
+ * render: ({attributes, children, node}) => (
474
+ * <div {...attributes}>
475
+ * {children}
476
+ * <img src={(node as {src?: string}).src} />
477
+ * </div>
478
+ * ),
479
+ * })
480
+ * ```
481
+ */
482
+ declare function defineBlockObject<const TType$1 extends string>(config: {
483
+ 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;
484
+ render?: BlockObjectRender;
485
+ }): BlockObject;
486
+ /**
487
+ * @alpha
488
+ *
489
+ * Define a non-editable inline object renderer for a `_type` declared
490
+ * in the schema's `inlineObjects` array.
491
+ *
492
+ * The render must always render `children` somewhere inside the outer
493
+ * element. `children` carries an engine-emitted void spacer the browser
494
+ * uses to anchor the caret next to the element. Dropping `children`
495
+ * makes the caret unable to land on the element.
496
+ *
497
+ * @example
498
+ * ```ts
499
+ * defineInlineObject({
500
+ * type: 'mention',
501
+ * render: ({attributes, children, node}) => (
502
+ * <span {...attributes}>
503
+ * {children}
504
+ * @{(node as {username?: string}).username}
505
+ * </span>
506
+ * ),
507
+ * })
508
+ * ```
509
+ */
510
+ declare function defineInlineObject<const TType$1 extends string>(config: {
511
+ 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;
512
+ render?: InlineObjectRender;
513
+ }): InlineObject;
514
+ /**
515
+ * @alpha
516
+ *
517
+ * Define a text block renderer. The returned registration is mounted
518
+ * via the `<NodePlugin>` component, or nested inside a container's
519
+ * `of` array as a positional override.
520
+ *
521
+ * `type` is required even though the top-level text block type is
522
+ * always `'block'`. Keeping `type` required leaves the door open for
523
+ * positional overrides of text-block-like elements (e.g. a `code-line`
524
+ * inside a `code-block` container).
525
+ *
526
+ * @example
527
+ * ```ts
528
+ * defineTextBlock({
529
+ * type: 'block',
530
+ * render: ({attributes, children}) => (
531
+ * <p {...attributes}>{children}</p>
532
+ * ),
533
+ * })
534
+ * ```
535
+ */
536
+ declare function defineTextBlock<const TType$1 extends string>(config: {
537
+ type: TType$1 extends 'span' ? "Error: defineTextBlock({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1;
538
+ render?: TextBlockRender;
539
+ of?: ReadonlyArray<Span | InlineObject>;
540
+ }): TextBlock;
541
+ /**
542
+ * @internal
543
+ *
544
+ * Resolved span config.
545
+ */
546
+ type SpanConfig = {
547
+ span: Span;
548
+ };
549
+ /**
550
+ * @internal
551
+ *
552
+ * Resolved block-object config.
553
+ */
554
+ type BlockObjectConfig = {
555
+ blockObject: BlockObject;
556
+ };
557
+ /**
558
+ * @internal
559
+ *
560
+ * Resolved inline-object config.
561
+ */
562
+ type InlineObjectConfig = {
563
+ inlineObject: InlineObject;
564
+ };
565
+ /**
566
+ * @internal
567
+ *
568
+ * Resolved container config carrying the pre-resolved `field` for the
569
+ * activation position. Dispatch reads pre-resolved data without
570
+ * re-walking the schema.
571
+ */
572
+ type ContainerConfig = {
573
+ container: Container;
574
+ field: ChildArrayField;
575
+ of?: ReadonlyArray<ContainerConfig | BlockObjectConfig | TextBlockConfig>;
576
+ };
577
+ /**
578
+ * @internal
579
+ *
580
+ * Resolved text block config. The optional `of` carries resolved
581
+ * inline-content positional overrides (spans, inline-objects) for
582
+ * children rendered inside this text block.
583
+ */
584
+ type TextBlockConfig = {
585
+ textBlock: TextBlock;
586
+ of?: ReadonlyArray<SpanConfig | InlineObjectConfig>;
587
+ };
588
+ type ChildArrayField = FieldDefinition & {
589
+ type: 'array';
590
+ of: ReadonlyArray<OfDefinition>;
591
+ };
592
+ /**
593
+ * Public view of a registered editable container, surfaced on
594
+ * {@link EditorContext.containers}.
595
+ *
596
+ * Two array properties named `of` live on the same entry with
597
+ * different semantics:
598
+ *
599
+ * - `field.of` is the SCHEMA-DECLARED list of types this container's
600
+ * child field accepts (from `@portabletext/schema`'s
601
+ * `OfDefinition`). Tells you what the schema permits as children.
602
+ * - `of` (top-level on `RegisteredContainer`) is the list of
603
+ * POSITIONAL CHILD REGISTRATIONS - nested
604
+ * {@link RegisteredContainer} or {@link RegisteredPositional}
605
+ * entries - that override the global registration when the engine
606
+ * descends into this parent. Tells you which child renderings are
607
+ * scoped to this parent.
608
+ *
609
+ * The full container registration (including the render callback)
610
+ * lives on the editor's internal {@link ResolvedContainers} map and
611
+ * is not exposed on the public context.
612
+ *
613
+ * Two top-level entries with the same `_type` cannot coexist - the
614
+ * register handler warns on duplicates. But the SAME `_type`
615
+ * registered in two different parents' `of` arrays is supported as
616
+ * a feature; `resolveContainerAt` walks the positional tree using
617
+ * the path to return the entry that applies at a given position.
618
+ *
619
+ * @alpha
620
+ */
621
+ type RegisteredContainer = {
622
+ kind: 'container';
623
+ type: string;
624
+ field: ChildArrayField;
625
+ of?: ReadonlyArray<RegisteredContainer | RegisteredPositional>;
626
+ };
627
+ /**
628
+ * Public view of a registered span, surfaced inside a containing
629
+ * {@link RegisteredContainer}'s `of` array as a positional
630
+ * registration. The render function is engine-internal.
631
+ *
632
+ * @alpha
633
+ */
634
+ type RegisteredSpan = {
635
+ kind: 'span';
636
+ type: string;
637
+ };
638
+ /**
639
+ * Public view of a registered block object, surfaced inside a
640
+ * containing {@link RegisteredContainer}'s `of` array as a positional
641
+ * registration. The render function is engine-internal.
642
+ *
643
+ * @alpha
644
+ */
645
+ type RegisteredBlockObject = {
646
+ kind: 'blockObject';
647
+ type: string;
648
+ };
649
+ /**
650
+ * Public view of a registered inline object, surfaced inside a
651
+ * containing {@link RegisteredContainer}'s `of` array as a positional
652
+ * registration. The render function is engine-internal.
653
+ *
654
+ * @alpha
655
+ */
656
+ type RegisteredInlineObject = {
657
+ kind: 'inlineObject';
658
+ type: string;
659
+ };
660
+ /**
661
+ * Union of non-container positional registrations that may appear in
662
+ * a {@link RegisteredContainer}'s `of` array. Text-block registrations
663
+ * are NOT included here; they surface on `EditorContext.textBlocks`,
664
+ * not on the containers tree.
665
+ *
666
+ * @alpha
667
+ */
668
+ type RegisteredPositional = RegisteredSpan | RegisteredBlockObject | RegisteredInlineObject;
669
+ /**
670
+ * Map of registered editable containers carried on `EditorContext`.
671
+ *
672
+ * Keyed by bare block-object `_type` (e.g. `'callout'`, `'table'`).
673
+ * Each entry is a rich {@link RegisteredContainer} carrying its
674
+ * `field` plus any positional `of` registrations.
675
+ *
676
+ * The map preserves positional structure: a `_type` declared inside
677
+ * a parent's `of` array surfaces as a nested entry on that parent's
678
+ * `of`, NOT as a separate top-level entry. Path-driven resolution
679
+ * (see `resolveContainerAt`) reaches positional entries by walking
680
+ * the tree.
681
+ *
682
+ * Top-level entries are global fallbacks: when path-driven descent
683
+ * does not find a positional override, the resolver falls back to the
684
+ * top-level entry for the type if one is registered.
685
+ *
686
+ * @alpha
687
+ */
688
+ type Containers = ReadonlyMap<string, RegisteredContainer>;
689
+ /**
690
+ * Engine-internal map carrying the fully-resolved container
691
+ * configurations - including render functions and positional `of`
692
+ * overrides. Lives on `editor.containers` and is consulted by render
693
+ * dispatch and engine-internal helpers.
694
+ *
695
+ * Not exposed on {@link EditorContext}.
696
+ */
697
+ type ResolvedContainers = Map<string, ContainerConfig>;
698
+ /**
699
+ * @public
700
+ */
701
+ type EditorSchema = Schema;
702
+ type Node$1 = PortableTextTextBlock | PortableTextObject | PortableTextSpan;
703
+ /**
704
+ * Snapshot-shaped input for traversal utilities.
705
+ *
706
+ * Mirrors the shape of `EditorSnapshot`: ambient state lives under
707
+ * `context`, the `blockIndexMap` perf cache sits as a sibling.
708
+ */
709
+ type TraversalSnapshot = {
710
+ context: {
711
+ schema: EditorSchema;
712
+ containers: Containers;
713
+ value: Array<Node$1>;
714
+ };
715
+ blockIndexMap: Map<string, number>;
716
+ };
717
+ /**
718
+ * Walk the editor value following `path` and return the
719
+ * {@link RegisteredContainer} or {@link RegisteredPositional} that applies
720
+ * at `path`'s target position.
721
+ *
722
+ * Resolution rules at each step:
723
+ *
724
+ * 1. **Positional override.** If the current parent declares the
725
+ * child's `_type` in its `of`, the positional entry wins.
726
+ * Used to resolve same-`_type` registered under different
727
+ * parents with different `field` values.
728
+ *
729
+ * 2. **Global fallback.** If the parent has no positional override,
730
+ * fall back to the top-level entry for `_type` in
731
+ * `containers`.
732
+ *
733
+ * 3. **Chain validity.** If any ancestor along the path has no
734
+ * resolved container entry (unregistered or not reachable as a
735
+ * container at its position), return `undefined`.
736
+ *
737
+ * Returns `undefined` when the target's `_type` is not registered
738
+ * at this position. Returns a {@link RegisteredPositional} when the target
739
+ * resolves to a leaf in a positional `of` (terminal node with no
740
+ * editable children).
741
+ *
742
+ * @alpha
743
+ */
744
+ declare function resolveContainerAt(containers: Containers, value: ReadonlyArray<Node$1>, path: Path$1): RegisteredContainer | RegisteredPositional | undefined;
62
745
  /**
63
746
  * @public
64
747
  * @deprecated Use `useEditor()` instead
@@ -157,7 +840,7 @@ declare class PortableTextEditor {
157
840
  */
158
841
  static delete: (editor: PortableTextEditor, selection: EditorSelection, options?: EditableAPIDeleteOptions) => void;
159
842
  static findDOMNode: (editor: PortableTextEditor, element: PortableTextBlock | PortableTextChild) => Node | undefined;
160
- static findByPath: (editor: PortableTextEditor, path: Path) => [_portabletext_schema6.PortableTextTextBlock<PortableTextObject | _portabletext_schema6.PortableTextSpan> | PortableTextObject | _portabletext_schema6.PortableTextSpan | undefined, Path | undefined];
843
+ static findByPath: (editor: PortableTextEditor, path: Path) => [_portabletext_schema5.PortableTextTextBlock<PortableTextObject | _portabletext_schema5.PortableTextSpan> | PortableTextObject | _portabletext_schema5.PortableTextSpan | undefined, Path | undefined];
161
844
  /**
162
845
  * @deprecated
163
846
  * Use `editor.send(...)` instead
@@ -907,9 +1590,6 @@ interface RangeRef {
907
1590
  * by plugins that wish to add their own helpers and implement new behaviors.
908
1591
  */
909
1592
  interface BaseEditor {
910
- children: PortableTextBlock[];
911
- readonly value: PortableTextBlock[];
912
- selection: EditorSelection;
913
1593
  operations: Operation[];
914
1594
  dirtyPaths: Path$1[];
915
1595
  dirtyPathKeys: Set<string>;
@@ -1089,33 +1769,12 @@ type RemotePatch = {
1089
1769
  interface PortableTextEditorEngine extends DOMEditor {
1090
1770
  _key: 'editor';
1091
1771
  _type: 'editor';
1092
- schema: EditorSchema;
1093
- keyGenerator: () => string;
1094
- converters: Array<Converter>;
1095
- readOnly: boolean;
1096
1772
  containers: ResolvedContainers;
1097
- /**
1098
- * Narrow {@link Containers} projection of `containers`, exposed on the
1099
- * public `EditorContext.containers`. Maintained in sync with
1100
- * `containers` by the editor machine's register/unregister handlers.
1101
- */
1102
- publicContainers: Containers;
1103
1773
  blockObjects: Map<string, BlockObjectConfig>;
1104
1774
  inlineObjects: Map<string, InlineObjectConfig>;
1105
1775
  spans: Map<string, SpanConfig>;
1106
1776
  textBlocks: Map<string, TextBlockConfig>;
1107
- /**
1108
- * Snapshot-shaped view onto the editor's traversal state. Mirrors the
1109
- * shape of `EditorSnapshot.context`.
1110
- */
1111
- readonly context: {
1112
- schema: EditorSchema;
1113
- containers: Containers;
1114
- value: PortableTextBlock[];
1115
- keyGenerator: () => string;
1116
- };
1117
1777
  decoratedRanges: Array<DecoratedRange>;
1118
- decoratorState: Record<string, boolean | undefined>;
1119
1778
  blockIndexMap: Map<string, number>;
1120
1779
  history: History;
1121
1780
  listIndexMap: Map<string, number>;
@@ -2453,5 +3112,5 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
2453
3112
  event: TBehaviorEvent;
2454
3113
  dom: EditorDom;
2455
3114
  }, guardResponse: TGuardResponse) => Array<BehaviorAction>;
2456
- export { EditorSnapshot as $, PortableTextTextBlock$1 as A, PortableTextEditor as At, EditorSelector as B, ListDefinition as C, RenderListItemFunction as Ct, PortableTextChild$1 as D, PortableTextEditable as Dt, PortableTextBlock$1 as E, ScrollSelectionIntoViewFunction as Et, BlockOffset as F, EditorConfig as G, EditorProvider as H, useEditor as I, MutationEvent as J, EditorEvent as K, defaultKeyGenerator as L, StyleDefinition as M, StyleSchemaType$1 as N, PortableTextObject$1 as O, PortableTextEditableProps as Ot, defineSchema as P, EditorContext as Q, usePortableTextEditorSelection as R, InlineObjectSchemaType$1 as S, RenderEditableFunction as St, Patch$1 as T, RenderStyleFunction as Tt, EditorProviderProps as U, useEditorSelector as V, Editor as W, defineBehavior as X, Behavior as Y, BehaviorGuard as Z, BlockObjectSchemaType$1 as _, RangeDecorationOnMovedDetails as _t, forward as a, BlockRenderProps as at, FieldDefinition$1 as b, RenderChildFunction as bt, CustomBehaviorEvent as c, EditorSelection as ct, SyntheticBehaviorEvent as d, OnCopyFn as dt, AddedAnnotationPaths as et, PatchesEvent as f, OnPasteFn as ft, BlockObjectDefinition as g, RangeDecoration as gt, BaseDefinition as h, PasteData as ht, execute as i, BlockListItemRenderProps as it, SchemaDefinition$1 as j, PortableTextSpan$1 as k, HotkeyOptions as kt, InsertPlacement as l, EditorSelectionPoint as lt, AnnotationSchemaType$1 as m, OnPasteResultOrPromise as mt, BehaviorActionSet as n, BlockChildRenderProps as nt, raise as o, BlockStyleRenderProps as ot, AnnotationDefinition as p, OnPasteResult as pt, EditorEmittedEvent as q, effect as r, BlockDecoratorRenderProps as rt, BehaviorEvent as s, EditableAPIDeleteOptions as st, BehaviorAction as t, BlockAnnotationRenderProps as tt, NativeBehaviorEvent as u, InvalidValueResolution as ut, DecoratorDefinition as v, RenderAnnotationFunction as vt, ListSchemaType$1 as w, RenderPlaceholderFunction as wt, InlineObjectDefinition as x, RenderDecoratorFunction as xt, DecoratorSchemaType$1 as y, RenderBlockFunction as yt, usePortableTextEditor as z };
3115
+ export { EditorSnapshot as $, AnnotationPath as $t, PortableTextTextBlock$1 as A, PortableTextEditor as At, EditorSelector as B, RegisteredSpan as Bt, ListDefinition as C, RenderListItemFunction as Ct, PortableTextChild$1 as D, PortableTextEditable as Dt, PortableTextBlock$1 as E, ScrollSelectionIntoViewFunction as Et, BlockOffset as F, Containers as Ft, EditorConfig as G, Span as Gt, EditorProvider as H, Container as Ht, useEditor as I, RegisteredBlockObject as It, MutationEvent as J, defineContainer as Jt, EditorEvent as K, TextBlock as Kt, defaultKeyGenerator as L, RegisteredContainer as Lt, StyleDefinition as M, TraversalSnapshot as Mt, StyleSchemaType$1 as N, Node$1 as Nt, PortableTextObject$1 as O, PortableTextEditableProps as Ot, defineSchema as P, EditorSchema as Pt, EditorContext as Q, Path$1 as Qt, usePortableTextEditorSelection as R, RegisteredInlineObject as Rt, InlineObjectSchemaType$1 as S, RenderEditableFunction as St, Patch$1 as T, RenderStyleFunction as Tt, EditorProviderProps as U, InlineObject as Ut, useEditorSelector as V, BlockObject as Vt, Editor as W, RegistrableNode as Wt, defineBehavior as X, defineSpan as Xt, Behavior as Y, defineInlineObject as Yt, BehaviorGuard as Z, defineTextBlock as Zt, BlockObjectSchemaType$1 as _, RangeDecorationOnMovedDetails as _t, forward as a, BlockRenderProps as at, FieldDefinition$1 as b, RenderChildFunction as bt, CustomBehaviorEvent as c, EditorSelection as ct, SyntheticBehaviorEvent as d, OnCopyFn as dt, BlockPath as en, AddedAnnotationPaths as et, PatchesEvent as f, OnPasteFn as ft, BlockObjectDefinition as g, RangeDecoration as gt, BaseDefinition as h, PasteData as ht, execute as i, BlockListItemRenderProps as it, SchemaDefinition$1 as j, resolveContainerAt as jt, PortableTextSpan$1 as k, HotkeyOptions as kt, InsertPlacement as l, EditorSelectionPoint as lt, AnnotationSchemaType$1 as m, OnPasteResultOrPromise as mt, BehaviorActionSet as n, KeyedSegment as nn, BlockChildRenderProps as nt, raise as o, BlockStyleRenderProps as ot, AnnotationDefinition as p, OnPasteResult as pt, EditorEmittedEvent as q, defineBlockObject as qt, effect as r, Path as rn, BlockDecoratorRenderProps as rt, BehaviorEvent as s, EditableAPIDeleteOptions as st, BehaviorAction as t, ChildPath as tn, BlockAnnotationRenderProps as tt, NativeBehaviorEvent as u, InvalidValueResolution as ut, DecoratorDefinition as v, RenderAnnotationFunction as vt, ListSchemaType$1 as w, RenderPlaceholderFunction as wt, InlineObjectDefinition as x, RenderDecoratorFunction as xt, DecoratorSchemaType$1 as y, RenderBlockFunction as yt, usePortableTextEditor as z, RegisteredPositional as zt };
2457
3116
  //# sourceMappingURL=behavior.types.action.d.ts.map