@portabletext/editor 7.1.1 → 7.3.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
1
  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";
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,705 @@ 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
+ /**
164
+ * @alpha
165
+ */
166
+ type ContainerRender = (props: ContainerRenderProps) => ReactElement;
167
+ /**
168
+ * @alpha
169
+ *
170
+ * A span's render function. Receives a portable text span node and
171
+ * wraps it. `children` carries the styled text already decorated by
172
+ * `renderDecorator`/`renderAnnotation`/range decorations.
173
+ */
174
+ type SpanRenderProps = {
175
+ attributes: Record<string, unknown>;
176
+ children: ReactElement;
177
+ focused: boolean;
178
+ node: PortableTextSpan;
179
+ path: Path$1;
180
+ readOnly: boolean;
181
+ selected: boolean;
182
+ /**
183
+ * Render this position with the engine's default wrapper.
184
+ * See {@link ContainerRenderProps.renderDefault}.
185
+ */
186
+ renderDefault: (props: SpanRenderProps) => ReactElement;
187
+ };
188
+ /**
189
+ * @alpha
190
+ */
191
+ type SpanRender = (props: SpanRenderProps) => ReactElement;
192
+ /**
193
+ * @alpha
194
+ *
195
+ * A block object's render function. Receives a non-editable block-level
196
+ * portable text object. `children` carries an engine-emitted void
197
+ * spacer that the browser uses to anchor the caret next to the
198
+ * element. Dropping `children` makes the caret unable to land on the
199
+ * element.
200
+ */
201
+ type BlockObjectRenderProps = {
202
+ attributes: Record<string, unknown>;
203
+ children: ReactElement;
204
+ focused: boolean;
205
+ node: PortableTextObject;
206
+ path: Path$1;
207
+ readOnly: boolean;
208
+ selected: boolean;
209
+ /**
210
+ * Render this position with the engine's default wrapper.
211
+ * See {@link ContainerRenderProps.renderDefault}.
212
+ */
213
+ renderDefault: (props: BlockObjectRenderProps) => ReactElement;
214
+ };
215
+ /**
216
+ * @alpha
217
+ */
218
+ type BlockObjectRender = (props: BlockObjectRenderProps) => ReactElement;
219
+ /**
220
+ * @alpha
221
+ *
222
+ * An inline object's render function. Receives a non-editable inline
223
+ * portable text object. `children` carries an engine-emitted void
224
+ * spacer that the browser uses to anchor the caret next to the
225
+ * element. Dropping `children` makes the caret unable to land on the
226
+ * element.
227
+ */
228
+ type InlineObjectRenderProps = {
229
+ attributes: Record<string, unknown>;
230
+ children: ReactElement;
231
+ focused: boolean;
232
+ node: PortableTextObject;
233
+ path: Path$1;
234
+ readOnly: boolean;
235
+ selected: boolean;
236
+ /**
237
+ * Render this position with the engine's default wrapper.
238
+ * See {@link ContainerRenderProps.renderDefault}.
239
+ */
240
+ renderDefault: (props: InlineObjectRenderProps) => ReactElement;
241
+ };
242
+ /**
243
+ * @alpha
244
+ */
245
+ type InlineObjectRender = (props: InlineObjectRenderProps) => ReactElement;
246
+ /**
247
+ * @alpha
248
+ *
249
+ * A container registration. Identifies a block object `_type` whose value
250
+ * holds editable children in `arrayField`. The optional `of` array carries
251
+ * nested registrations that override how immediate children of this
252
+ * container render at this lexical scope.
253
+ *
254
+ * `of` overrides apply ONE level down only. Children at deeper levels fall
255
+ * through to global registrations.
256
+ *
257
+ * The `kind` field is injected by `defineContainer` and discriminates
258
+ * containers from other registration kinds at runtime.
259
+ */
260
+ type Container = {
261
+ kind: 'container';
262
+ type: string;
263
+ arrayField: string;
264
+ /**
265
+ * Outer render. Two modes:
266
+ * - omitted: fall through to global registered render (or engine default)
267
+ * - function: use this render. The function receives a `renderDefault`
268
+ * prop that returns the engine default when called.
269
+ */
270
+ render?: ContainerRender;
271
+ /**
272
+ * Block-level positional overrides. Inline-content kinds (`Span`,
273
+ * `InlineObject`) belong in `TextBlock.of`, not here.
274
+ */
275
+ of?: ReadonlyArray<Container | TextBlock | BlockObject>;
276
+ };
277
+ /**
278
+ * @alpha
279
+ *
280
+ * A text block registration. The text block `_type` is `'block'` at the
281
+ * top level. Positional overrides nested in a container's `of` array can
282
+ * register a different `_type` to render at that lexical scope.
283
+ *
284
+ * `defineTextBlock` opts the text block into the new render pipeline.
285
+ * The consumer's `render` callback owns the outer wrapper entirely:
286
+ * the engine emits `data-pt-*` attributes only - no `pt-*` CSS classes,
287
+ * no legacy `data-block-*` attributes - and the block-level
288
+ * `renderStyle`/`renderListItem`/`renderBlock` props on
289
+ * `<PortableTextEditable>` do not compose under this registration.
290
+ *
291
+ * Span-level render props - `renderDecorator`, `renderAnnotation`,
292
+ * `renderPlaceholder`, and range decorations - keep working. They fire
293
+ * on the spans inside `children` regardless of which text block outer
294
+ * wrapper renders them.
295
+ */
296
+ type TextBlock = {
297
+ kind: 'textBlock';
298
+ type: string;
299
+ /**
300
+ * Outer render. Two modes:
301
+ * - omitted: fall through to global registered render (or engine default)
302
+ * - function: use this render. The function receives a `renderDefault`
303
+ * prop that returns the engine default when called.
304
+ */
305
+ render?: TextBlockRender;
306
+ /**
307
+ * Inline-content positional overrides. A `Span` or `InlineObject`
308
+ * placed here scopes the inline render to this text block (or any
309
+ * text block of this `type` if registered at the top level).
310
+ */
311
+ of?: ReadonlyArray<Span | InlineObject>;
312
+ };
313
+ /**
314
+ * @alpha
315
+ *
316
+ * Text block render function. `children` carries the rendered spans -
317
+ * `renderDecorator`, `renderAnnotation`, `renderPlaceholder`, and range
318
+ * decorations have already fired at the leaf level. The render's job
319
+ * is the outer wrapper element and any block-level composition (style,
320
+ * list-item) the consumer wants.
321
+ */
322
+ type TextBlockRenderProps = {
323
+ attributes: Record<string, unknown>;
324
+ children: ReactElement;
325
+ focused: boolean;
326
+ node: PortableTextTextBlock;
327
+ path: Path$1;
328
+ readOnly: boolean;
329
+ selected: boolean;
330
+ /**
331
+ * Render this position with the engine's default wrapper.
332
+ * See {@link ContainerRenderProps.renderDefault}.
333
+ */
334
+ renderDefault: (props: TextBlockRenderProps) => ReactElement;
335
+ };
336
+ /**
337
+ * @alpha
338
+ */
339
+ type TextBlockRender = (props: TextBlockRenderProps) => ReactElement;
340
+ /**
341
+ * @alpha
342
+ *
343
+ * A span registration. The span `_type` is `'span'` at the top level.
344
+ * Positional overrides nested in a container's `of` array can register
345
+ * a different `_type` for a span-like inline at that lexical scope
346
+ * (e.g. a `code-span` inside a `code-block`).
347
+ */
348
+ type Span = {
349
+ kind: 'span';
350
+ type: string;
351
+ /**
352
+ * Outer render. Two modes:
353
+ * - omitted: fall through to global registered render (or engine default)
354
+ * - function: use this render. The function receives a `renderDefault`
355
+ * prop that returns the engine default when called.
356
+ */
357
+ render?: SpanRender;
358
+ };
359
+ /**
360
+ * @alpha
361
+ *
362
+ * A non-editable block-level object registration. Identifies a `_type`
363
+ * whose value renders as a block-level void node (image, embed, etc.).
364
+ */
365
+ type BlockObject = {
366
+ kind: 'blockObject';
367
+ type: string;
368
+ /**
369
+ * Outer render. Two modes:
370
+ * - omitted: fall through to global registered render (or engine default)
371
+ * - function: use this render. The function receives a `renderDefault`
372
+ * prop that returns the engine default when called.
373
+ */
374
+ render?: BlockObjectRender;
375
+ };
376
+ /**
377
+ * @alpha
378
+ *
379
+ * A non-editable inline object registration. Identifies a `_type` whose
380
+ * value renders as an inline void node (mention, inline image, etc.).
381
+ */
382
+ type InlineObject = {
383
+ kind: 'inlineObject';
384
+ type: string;
385
+ /**
386
+ * Outer render. Two modes:
387
+ * - omitted: fall through to global registered render (or engine default)
388
+ * - function: use this render. The function receives a `renderDefault`
389
+ * prop that returns the engine default when called.
390
+ */
391
+ render?: InlineObjectRender;
392
+ };
393
+ /**
394
+ * @alpha
395
+ *
396
+ * The discriminated union of every registration accepted by
397
+ * `editor.registerNode` and the `<NodePlugin>` component.
398
+ */
399
+ type RegistrableNode = Container | TextBlock | Span | BlockObject | InlineObject;
400
+ /**
401
+ * @alpha
402
+ *
403
+ * Define a container renderer. The returned registration is mounted via
404
+ * the `<NodePlugin>` component at the top level, or nested inside
405
+ * another container's `of` array as a positional override.
406
+ *
407
+ * `type` cannot be `'span'` (use {@link defineSpan}) nor `'block'` (use
408
+ * {@link defineTextBlock}). The text block is not a container.
409
+ *
410
+ * The `node` argument of `render` narrows to a portable text object.
411
+ *
412
+ * @example
413
+ * ```ts
414
+ * defineContainer({
415
+ * type: 'table',
416
+ * arrayField: 'rows',
417
+ * render: ({children}) => (
418
+ * <table>{children}</table>
419
+ * ),
420
+ * of: [
421
+ * defineContainer({
422
+ * type: 'row',
423
+ * arrayField: 'cells',
424
+ * render: ({children}) => (
425
+ * <tr>{children}</tr>
426
+ * ),
427
+ * }),
428
+ * ],
429
+ * })
430
+ * ```
431
+ */
432
+ declare function defineContainer<const TType$1 extends string>(config: {
433
+ 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;
434
+ arrayField: string;
435
+ render?: (props: {
436
+ attributes: Record<string, unknown>;
437
+ children: ReactElement;
438
+ focused: boolean;
439
+ node: ContainerNodeForType<TType$1>;
440
+ path: Path$1;
441
+ readOnly: boolean;
442
+ selected: boolean;
443
+ renderDefault: (props: ContainerRenderProps) => ReactElement;
444
+ }) => ReactElement;
445
+ of?: ReadonlyArray<Container | TextBlock | BlockObject>;
446
+ }): Container;
447
+ /**
448
+ * @alpha
449
+ *
450
+ * Define a span renderer. The returned registration is mounted via the
451
+ * `<NodePlugin>` component at the top level, or nested inside a
452
+ * container's `of` array as a positional override.
453
+ *
454
+ * `type` is required even though there is only one top-level span type
455
+ * (`'span'`) today. Keeping `type` required leaves the door open for
456
+ * positional overrides of span-like inlines (e.g. a `code-span` inside
457
+ * a `code-block` container).
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * defineSpan({
462
+ * type: 'span',
463
+ * render: ({attributes, children}) => (
464
+ * <span {...attributes}>{children}</span>
465
+ * ),
466
+ * })
467
+ * ```
468
+ */
469
+ declare function defineSpan<const TType$1 extends string>(config: {
470
+ type: TType$1 extends 'block' ? "Error: defineSpan({type: 'block'}) is forbidden -- 'block' is always a text block, use defineTextBlock" : TType$1;
471
+ render?: SpanRender;
472
+ }): Span;
473
+ /**
474
+ * @alpha
475
+ *
476
+ * Define a non-editable block-level object renderer for a `_type`
477
+ * declared in the schema's `blockObjects` array.
478
+ *
479
+ * The render must always render `children` somewhere inside the outer
480
+ * element. `children` carries an engine-emitted void spacer the browser
481
+ * uses to anchor the caret next to the element. Dropping `children`
482
+ * makes the caret unable to land on the element.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * defineBlockObject({
487
+ * type: 'image',
488
+ * render: ({attributes, children, node}) => (
489
+ * <div {...attributes}>
490
+ * {children}
491
+ * <img src={(node as {src?: string}).src} />
492
+ * </div>
493
+ * ),
494
+ * })
495
+ * ```
496
+ */
497
+ declare function defineBlockObject<const TType$1 extends string>(config: {
498
+ 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;
499
+ render?: BlockObjectRender;
500
+ }): BlockObject;
501
+ /**
502
+ * @alpha
503
+ *
504
+ * Define a non-editable inline object renderer for a `_type` declared
505
+ * in the schema's `inlineObjects` array.
506
+ *
507
+ * The render must always render `children` somewhere inside the outer
508
+ * element. `children` carries an engine-emitted void spacer the browser
509
+ * uses to anchor the caret next to the element. Dropping `children`
510
+ * makes the caret unable to land on the element.
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * defineInlineObject({
515
+ * type: 'mention',
516
+ * render: ({attributes, children, node}) => (
517
+ * <span {...attributes}>
518
+ * {children}
519
+ * @{(node as {username?: string}).username}
520
+ * </span>
521
+ * ),
522
+ * })
523
+ * ```
524
+ */
525
+ declare function defineInlineObject<const TType$1 extends string>(config: {
526
+ 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;
527
+ render?: InlineObjectRender;
528
+ }): InlineObject;
529
+ /**
530
+ * @alpha
531
+ *
532
+ * Define a text block renderer. The returned registration is mounted
533
+ * via the `<NodePlugin>` component, or nested inside a container's
534
+ * `of` array as a positional override.
535
+ *
536
+ * `type` is required even though the top-level text block type is
537
+ * always `'block'`. Keeping `type` required leaves the door open for
538
+ * positional overrides of text-block-like elements (e.g. a `code-line`
539
+ * inside a `code-block` container).
540
+ *
541
+ * @example
542
+ * ```ts
543
+ * defineTextBlock({
544
+ * type: 'block',
545
+ * render: ({attributes, children}) => (
546
+ * <p {...attributes}>{children}</p>
547
+ * ),
548
+ * })
549
+ * ```
550
+ */
551
+ declare function defineTextBlock<const TType$1 extends string>(config: {
552
+ type: TType$1 extends 'span' ? "Error: defineTextBlock({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType$1;
553
+ render?: TextBlockRender;
554
+ of?: ReadonlyArray<Span | InlineObject>;
555
+ }): TextBlock;
556
+ /**
557
+ * @internal
558
+ *
559
+ * Resolved span config.
560
+ */
561
+ type SpanConfig = {
562
+ span: Span;
563
+ };
564
+ /**
565
+ * @internal
566
+ *
567
+ * Resolved block-object config.
568
+ */
569
+ type BlockObjectConfig = {
570
+ blockObject: BlockObject;
571
+ };
572
+ /**
573
+ * @internal
574
+ *
575
+ * Resolved inline-object config.
576
+ */
577
+ type InlineObjectConfig = {
578
+ inlineObject: InlineObject;
579
+ };
580
+ /**
581
+ * @internal
582
+ *
583
+ * Resolved container config carrying the pre-resolved `field` for the
584
+ * activation position. Dispatch reads pre-resolved data without
585
+ * re-walking the schema.
586
+ */
587
+ type ContainerConfig = {
588
+ container: Container;
589
+ field: ChildArrayField;
590
+ of?: ReadonlyArray<ContainerConfig | BlockObjectConfig | TextBlockConfig>;
591
+ };
592
+ /**
593
+ * @internal
594
+ *
595
+ * Resolved text block config. The optional `of` carries resolved
596
+ * inline-content positional overrides (spans, inline-objects) for
597
+ * children rendered inside this text block.
598
+ */
599
+ type TextBlockConfig = {
600
+ textBlock: TextBlock;
601
+ of?: ReadonlyArray<SpanConfig | InlineObjectConfig>;
602
+ };
603
+ type ChildArrayField = FieldDefinition & {
604
+ type: 'array';
605
+ of: ReadonlyArray<OfDefinition>;
606
+ };
607
+ /**
608
+ * Public view of a registered editable container, surfaced on
609
+ * {@link EditorContext.containers}.
610
+ *
611
+ * Two array properties named `of` live on the same entry with
612
+ * different semantics:
613
+ *
614
+ * - `field.of` is the SCHEMA-DECLARED list of types this container's
615
+ * child field accepts (from `@portabletext/schema`'s
616
+ * `OfDefinition`). Tells you what the schema permits as children.
617
+ * - `of` (top-level on `RegisteredContainer`) is the list of
618
+ * POSITIONAL CHILD REGISTRATIONS - nested
619
+ * {@link RegisteredContainer} or {@link RegisteredPositional}
620
+ * entries - that override the global registration when the engine
621
+ * descends into this parent. Tells you which child renderings are
622
+ * scoped to this parent.
623
+ *
624
+ * The full container registration (including the render callback)
625
+ * lives on the editor's internal {@link ResolvedContainers} map and
626
+ * is not exposed on the public context.
627
+ *
628
+ * Two top-level entries with the same `_type` cannot coexist - the
629
+ * register handler warns on duplicates. But the SAME `_type`
630
+ * registered in two different parents' `of` arrays is supported as
631
+ * a feature; `resolveContainerAt` walks the positional tree using
632
+ * the path to return the entry that applies at a given position.
633
+ *
634
+ * @alpha
635
+ */
636
+ type RegisteredContainer = {
637
+ kind: 'container';
638
+ type: string;
639
+ field: ChildArrayField;
640
+ of?: ReadonlyArray<RegisteredContainer | RegisteredPositional>;
641
+ };
642
+ /**
643
+ * Public view of a registered span, surfaced inside a containing
644
+ * {@link RegisteredContainer}'s `of` array as a positional
645
+ * registration. The render function is engine-internal.
646
+ *
647
+ * @alpha
648
+ */
649
+ type RegisteredSpan = {
650
+ kind: 'span';
651
+ type: string;
652
+ };
653
+ /**
654
+ * Public view of a registered block object, surfaced inside a
655
+ * containing {@link RegisteredContainer}'s `of` array as a positional
656
+ * registration. The render function is engine-internal.
657
+ *
658
+ * @alpha
659
+ */
660
+ type RegisteredBlockObject = {
661
+ kind: 'blockObject';
662
+ type: string;
663
+ };
664
+ /**
665
+ * Public view of a registered inline object, surfaced inside a
666
+ * containing {@link RegisteredContainer}'s `of` array as a positional
667
+ * registration. The render function is engine-internal.
668
+ *
669
+ * @alpha
670
+ */
671
+ type RegisteredInlineObject = {
672
+ kind: 'inlineObject';
673
+ type: string;
674
+ };
675
+ /**
676
+ * Union of non-container positional registrations that may appear in
677
+ * a {@link RegisteredContainer}'s `of` array. Text-block registrations
678
+ * are NOT included here; they surface on `EditorContext.textBlocks`,
679
+ * not on the containers tree.
680
+ *
681
+ * @alpha
682
+ */
683
+ type RegisteredPositional = RegisteredSpan | RegisteredBlockObject | RegisteredInlineObject;
684
+ /**
685
+ * Map of registered editable containers carried on `EditorContext`.
686
+ *
687
+ * Keyed by bare block-object `_type` (e.g. `'callout'`, `'table'`).
688
+ * Each entry is a rich {@link RegisteredContainer} carrying its
689
+ * `field` plus any positional `of` registrations.
690
+ *
691
+ * The map preserves positional structure: a `_type` declared inside
692
+ * a parent's `of` array surfaces as a nested entry on that parent's
693
+ * `of`, NOT as a separate top-level entry. Path-driven resolution
694
+ * (see `resolveContainerAt`) reaches positional entries by walking
695
+ * the tree.
696
+ *
697
+ * Top-level entries are global fallbacks: when path-driven descent
698
+ * does not find a positional override, the resolver falls back to the
699
+ * top-level entry for the type if one is registered.
700
+ *
701
+ * @alpha
702
+ */
703
+ type Containers = ReadonlyMap<string, RegisteredContainer>;
704
+ /**
705
+ * Engine-internal map carrying the fully-resolved container
706
+ * configurations - including render functions and positional `of`
707
+ * overrides. Lives on `editor.containers` and is consulted by render
708
+ * dispatch and engine-internal helpers.
709
+ *
710
+ * Not exposed on {@link EditorContext}.
711
+ */
712
+ type ResolvedContainers = Map<string, ContainerConfig>;
713
+ /**
714
+ * @public
715
+ */
716
+ type EditorSchema = Schema;
717
+ type Node$1 = PortableTextTextBlock | PortableTextObject | PortableTextSpan;
718
+ /**
719
+ * Snapshot-shaped input for traversal utilities.
720
+ *
721
+ * Mirrors the shape of `EditorSnapshot`: ambient state lives under
722
+ * `context`, the `blockIndexMap` perf cache sits as a sibling.
723
+ */
724
+ type TraversalSnapshot = {
725
+ context: {
726
+ schema: EditorSchema;
727
+ containers: Containers;
728
+ value: Array<Node$1>;
729
+ };
730
+ blockIndexMap: Map<string, number>;
731
+ };
732
+ /**
733
+ * Walk the editor value following `path` and return the
734
+ * {@link RegisteredContainer} or {@link RegisteredPositional} that applies
735
+ * at `path`'s target position.
736
+ *
737
+ * Resolution rules at each step:
738
+ *
739
+ * 1. **Positional override.** If the current parent declares the
740
+ * child's `_type` in its `of`, the positional entry wins.
741
+ * Used to resolve same-`_type` registered under different
742
+ * parents with different `field` values.
743
+ *
744
+ * 2. **Global fallback.** If the parent has no positional override,
745
+ * fall back to the top-level entry for `_type` in
746
+ * `containers`.
747
+ *
748
+ * 3. **Chain validity.** If any ancestor along the path has no
749
+ * resolved container entry (unregistered or not reachable as a
750
+ * container at its position), return `undefined`.
751
+ *
752
+ * Returns `undefined` when the target's `_type` is not registered
753
+ * at this position. Returns a {@link RegisteredPositional} when the target
754
+ * resolves to a leaf in a positional `of` (terminal node with no
755
+ * editable children).
756
+ *
757
+ * @alpha
758
+ */
759
+ declare function resolveContainerAt(containers: Containers, value: ReadonlyArray<Node$1>, path: Path$1): RegisteredContainer | RegisteredPositional | undefined;
62
760
  /**
63
761
  * @public
64
762
  * @deprecated Use `useEditor()` instead
@@ -907,9 +1605,6 @@ interface RangeRef {
907
1605
  * by plugins that wish to add their own helpers and implement new behaviors.
908
1606
  */
909
1607
  interface BaseEditor {
910
- children: PortableTextBlock[];
911
- readonly value: PortableTextBlock[];
912
- selection: EditorSelection;
913
1608
  operations: Operation[];
914
1609
  dirtyPaths: Path$1[];
915
1610
  dirtyPathKeys: Set<string>;
@@ -1089,33 +1784,12 @@ type RemotePatch = {
1089
1784
  interface PortableTextEditorEngine extends DOMEditor {
1090
1785
  _key: 'editor';
1091
1786
  _type: 'editor';
1092
- schema: EditorSchema;
1093
- keyGenerator: () => string;
1094
- converters: Array<Converter>;
1095
- readOnly: boolean;
1096
1787
  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
1788
  blockObjects: Map<string, BlockObjectConfig>;
1104
1789
  inlineObjects: Map<string, InlineObjectConfig>;
1105
1790
  spans: Map<string, SpanConfig>;
1106
1791
  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
1792
  decoratedRanges: Array<DecoratedRange>;
1118
- decoratorState: Record<string, boolean | undefined>;
1119
1793
  blockIndexMap: Map<string, number>;
1120
1794
  history: History;
1121
1795
  listIndexMap: Map<string, number>;
@@ -2453,5 +3127,5 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
2453
3127
  event: TBehaviorEvent;
2454
3128
  dom: EditorDom;
2455
3129
  }, 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 };
3130
+ export { EditorSnapshot as $, SpanRenderProps 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, ContainerRender as Gt, EditorProvider as H, BlockObjectRender as Ht, useEditor as I, RegisteredBlockObject as It, MutationEvent as J, InlineObjectRender as Jt, EditorEvent as K, ContainerRenderProps 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, SpanRender 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, BlockObjectRenderProps as Ut, useEditorSelector as V, BlockObject as Vt, Editor as W, Container as Wt, defineBehavior as X, RegistrableNode as Xt, Behavior as Y, InlineObjectRenderProps as Yt, BehaviorGuard as Z, Span as Zt, BlockObjectSchemaType$1 as _, RangeDecorationOnMovedDetails as _t, forward as a, defineInlineObject as an, BlockRenderProps as at, FieldDefinition$1 as b, RenderChildFunction as bt, CustomBehaviorEvent as c, Path$1 as cn, EditorSelection as ct, SyntheticBehaviorEvent as d, ChildPath as dn, OnCopyFn as dt, TextBlock as en, AddedAnnotationPaths as et, PatchesEvent as f, KeyedSegment as fn, OnPasteFn as ft, BlockObjectDefinition as g, RangeDecoration as gt, BaseDefinition as h, PasteData as ht, execute as i, defineContainer as in, BlockListItemRenderProps as it, SchemaDefinition$1 as j, resolveContainerAt as jt, PortableTextSpan$1 as k, HotkeyOptions as kt, InsertPlacement as l, AnnotationPath as ln, EditorSelectionPoint as lt, AnnotationSchemaType$1 as m, OnPasteResultOrPromise as mt, BehaviorActionSet as n, TextBlockRenderProps as nn, BlockChildRenderProps as nt, raise as o, defineSpan as on, BlockStyleRenderProps as ot, AnnotationDefinition as p, Path as pn, OnPasteResult as pt, EditorEmittedEvent as q, InlineObject as qt, effect as r, defineBlockObject as rn, BlockDecoratorRenderProps as rt, BehaviorEvent as s, defineTextBlock as sn, EditableAPIDeleteOptions as st, BehaviorAction as t, TextBlockRender as tn, BlockAnnotationRenderProps as tt, NativeBehaviorEvent as u, BlockPath as un, 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
3131
  //# sourceMappingURL=behavior.types.action.d.ts.map