@portabletext/editor 7.10.19 → 7.12.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.
- package/README.md +57 -64
- package/lib/{behavior.types.action-CYtiRDck.d.ts → behavior.types.action-DH6ujvaH.d.ts} +409 -109
- package/lib/behavior.types.action-DH6ujvaH.d.ts.map +1 -0
- package/lib/{behavior.types.behavior-B_77VtQR.js → behavior.types.behavior-BxSLb73I.js} +5 -5
- package/lib/behavior.types.behavior-BxSLb73I.js.map +1 -0
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +1 -1
- package/lib/{get-container-BeXYKpoi.js → get-container-D1nM_ww9.js} +14 -14
- package/lib/get-container-D1nM_ww9.js.map +1 -0
- package/lib/{get-parent-51Kzgaf9.js → get-parent-Ci5241qs.js} +3 -3
- package/lib/get-parent-Ci5241qs.js.map +1 -0
- package/lib/{get-path-sub-schema--2I4NJbG.js → get-path-sub-schema-CZd9VcVM.js} +10 -10
- package/lib/get-path-sub-schema-CZd9VcVM.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +294 -101
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +6 -6
- package/lib/plugins/index.js +5 -5
- package/lib/plugins/index.js.map +1 -1
- package/lib/{selector.is-at-the-start-of-block-gJIMWRpU.js → selector.is-at-the-start-of-block-D0boZbDu.js} +4 -4
- package/lib/selector.is-at-the-start-of-block-D0boZbDu.js.map +1 -0
- package/lib/selectors/index.d.ts +6 -6
- package/lib/selectors/index.js +6 -6
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +31 -31
- package/lib/traversal/index.js +4 -4
- package/lib/traversal/index.js.map +1 -1
- package/lib/{util.is-equal-selections-BF4WJtz5.js → util.is-equal-selections-N1hxVUbE.js} +2 -2
- package/lib/{util.is-equal-selections-BF4WJtz5.js.map → util.is-equal-selections-N1hxVUbE.js.map} +1 -1
- package/lib/{util.slice-blocks-DQnr9X2s.js → util.slice-blocks-B2fZcNok.js} +2 -2
- package/lib/{util.slice-blocks-DQnr9X2s.js.map → util.slice-blocks-B2fZcNok.js.map} +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +3 -3
- package/package.json +3 -3
- package/lib/behavior.types.action-CYtiRDck.d.ts.map +0 -1
- package/lib/behavior.types.behavior-B_77VtQR.js.map +0 -1
- package/lib/get-container-BeXYKpoi.js.map +0 -1
- package/lib/get-parent-51Kzgaf9.js.map +0 -1
- package/lib/get-path-sub-schema--2I4NJbG.js.map +0 -1
- package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React$1, { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
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";
|
|
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, OfDefinition as OfDefinition$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";
|
|
3
3
|
import { ActorRefFrom } from "xstate";
|
|
4
4
|
import { Patch, Patch as Patch$1 } from "@portabletext/patches";
|
|
5
5
|
type MIMEType = `${string}/${string}`;
|
|
@@ -94,15 +94,7 @@ type AnnotationPath = Path;
|
|
|
94
94
|
*/
|
|
95
95
|
type ChildPath = Path;
|
|
96
96
|
/**
|
|
97
|
-
* @
|
|
98
|
-
*
|
|
99
|
-
* Narrow the container node type by the registered `_type`. Containers
|
|
100
|
-
* always render portable text objects: `'span'` is always a leaf and
|
|
101
|
-
* `'block'` is always a text block; both are excluded.
|
|
102
|
-
*/
|
|
103
|
-
type ContainerNodeForType<TType extends string> = TType extends 'span' | 'block' ? never : PortableTextObject;
|
|
104
|
-
/**
|
|
105
|
-
* @alpha
|
|
97
|
+
* @public
|
|
106
98
|
*
|
|
107
99
|
* A container's render function receives a node and renders an element
|
|
108
100
|
* that wraps its editable children. The render is positional: it fires for
|
|
@@ -125,7 +117,7 @@ type ContainerRenderProps = {
|
|
|
125
117
|
* inside a custom render to fall back to or wrap the default:
|
|
126
118
|
*
|
|
127
119
|
* ```ts
|
|
128
|
-
* render: (
|
|
120
|
+
* render: (props) => props.renderDefault(props)
|
|
129
121
|
* ```
|
|
130
122
|
*
|
|
131
123
|
* The default is the engine's minimal wrapper. It does not chain
|
|
@@ -136,15 +128,18 @@ type ContainerRenderProps = {
|
|
|
136
128
|
renderDefault: (props: ContainerRenderProps) => ReactElement;
|
|
137
129
|
};
|
|
138
130
|
/**
|
|
139
|
-
* @
|
|
131
|
+
* @public
|
|
140
132
|
*/
|
|
141
133
|
type ContainerRender = (props: ContainerRenderProps) => ReactElement;
|
|
142
134
|
/**
|
|
143
|
-
* @
|
|
135
|
+
* @public
|
|
144
136
|
*
|
|
145
137
|
* A span's render function. Receives a portable text span node and
|
|
146
138
|
* wraps it. `children` carries the styled text already decorated by
|
|
147
|
-
* `
|
|
139
|
+
* the decorator/annotation renders (registered via `defineDecorator`/
|
|
140
|
+
* `defineAnnotation`, or the legacy `renderDecorator`/`renderAnnotation`
|
|
141
|
+
* props). Range decorations wrap this render's output from the
|
|
142
|
+
* outside, so they are not part of `children`.
|
|
148
143
|
*/
|
|
149
144
|
type SpanRenderProps = {
|
|
150
145
|
attributes: Record<string, unknown>;
|
|
@@ -161,11 +156,88 @@ type SpanRenderProps = {
|
|
|
161
156
|
renderDefault: (props: SpanRenderProps) => ReactElement;
|
|
162
157
|
};
|
|
163
158
|
/**
|
|
164
|
-
* @
|
|
159
|
+
* @public
|
|
165
160
|
*/
|
|
166
161
|
type SpanRender = (props: SpanRenderProps) => ReactElement;
|
|
167
162
|
/**
|
|
168
|
-
* @
|
|
163
|
+
* @public
|
|
164
|
+
*
|
|
165
|
+
* A decorator's render function. Receives the decorator name and
|
|
166
|
+
* wraps the styled text it applies to. Range and selection decorations
|
|
167
|
+
* can split one span into several leaves, so this fires once per
|
|
168
|
+
* decorator on each leaf, not once per span, nested in the span's
|
|
169
|
+
* `marks` order alongside any decorators still rendered by the legacy
|
|
170
|
+
* `renderDecorator` prop.
|
|
171
|
+
*
|
|
172
|
+
* The render is a plain function call, not a component: do not call
|
|
173
|
+
* hooks in it. When you need hooks, return an element of your own
|
|
174
|
+
* component: `render: (props) => <MyDecorator {...props} />`.
|
|
175
|
+
*/
|
|
176
|
+
type DecoratorRenderProps = {
|
|
177
|
+
children: ReactElement;
|
|
178
|
+
/**
|
|
179
|
+
* The decorator name, e.g. `'strong'`. A `'*'` render
|
|
180
|
+
* discriminates on this.
|
|
181
|
+
*/
|
|
182
|
+
decorator: string;
|
|
183
|
+
focused: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Path of the span carrying the decorator.
|
|
186
|
+
*/
|
|
187
|
+
path: Path;
|
|
188
|
+
readOnly: boolean;
|
|
189
|
+
selected: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Render this position with the engine's default wrapper.
|
|
192
|
+
* See {@link ContainerRenderProps.renderDefault}. The default is
|
|
193
|
+
* identity: the engine applies no decorator markup of its own.
|
|
194
|
+
*/
|
|
195
|
+
renderDefault: (props: DecoratorRenderProps) => ReactElement;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
type DecoratorRender = (props: DecoratorRenderProps) => ReactElement;
|
|
201
|
+
/**
|
|
202
|
+
* @public
|
|
203
|
+
*
|
|
204
|
+
* An annotation's render function. Receives the annotation's `markDef`
|
|
205
|
+
* object and wraps the styled text it applies to. The engine anchors
|
|
206
|
+
* the text in a `<span>` outside this render regardless of whether a
|
|
207
|
+
* render is registered, kept for structural parity with the legacy
|
|
208
|
+
* `renderAnnotation` path (which hands that anchor to consumers as
|
|
209
|
+
* `editorElementRef`); this render's job is the styling wrapper only.
|
|
210
|
+
*
|
|
211
|
+
* The render is a plain function call, not a component: do not call
|
|
212
|
+
* hooks in it. When you need hooks, return an element of your own
|
|
213
|
+
* component: `render: (props) => <MyAnnotation {...props} />`.
|
|
214
|
+
*/
|
|
215
|
+
type AnnotationRenderProps = {
|
|
216
|
+
/**
|
|
217
|
+
* The annotation's `markDef` object: `{_key, _type, ...fields}`.
|
|
218
|
+
* Named `annotation`, not `node`, because `path` addresses the span
|
|
219
|
+
* leaf carrying the annotation; the markDef itself lives in the block's
|
|
220
|
+
* `markDefs` array.
|
|
221
|
+
*/
|
|
222
|
+
annotation: PortableTextObject;
|
|
223
|
+
children: ReactElement;
|
|
224
|
+
focused: boolean;
|
|
225
|
+
path: Path;
|
|
226
|
+
readOnly: boolean;
|
|
227
|
+
selected: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Render this position with the engine's default wrapper.
|
|
230
|
+
* See {@link ContainerRenderProps.renderDefault}. The default is
|
|
231
|
+
* identity: the engine applies no annotation markup of its own.
|
|
232
|
+
*/
|
|
233
|
+
renderDefault: (props: AnnotationRenderProps) => ReactElement;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
type AnnotationRender = (props: AnnotationRenderProps) => ReactElement;
|
|
239
|
+
/**
|
|
240
|
+
* @public
|
|
169
241
|
*
|
|
170
242
|
* A block object's render function. Receives a non-editable block-level
|
|
171
243
|
* portable text object. `children` carries an engine-emitted void
|
|
@@ -188,11 +260,11 @@ type BlockObjectRenderProps = {
|
|
|
188
260
|
renderDefault: (props: BlockObjectRenderProps) => ReactElement;
|
|
189
261
|
};
|
|
190
262
|
/**
|
|
191
|
-
* @
|
|
263
|
+
* @public
|
|
192
264
|
*/
|
|
193
265
|
type BlockObjectRender = (props: BlockObjectRenderProps) => ReactElement;
|
|
194
266
|
/**
|
|
195
|
-
* @
|
|
267
|
+
* @public
|
|
196
268
|
*
|
|
197
269
|
* An inline object's render function. Receives a non-editable inline
|
|
198
270
|
* portable text object. `children` carries an engine-emitted void
|
|
@@ -215,11 +287,11 @@ type InlineObjectRenderProps = {
|
|
|
215
287
|
renderDefault: (props: InlineObjectRenderProps) => ReactElement;
|
|
216
288
|
};
|
|
217
289
|
/**
|
|
218
|
-
* @
|
|
290
|
+
* @public
|
|
219
291
|
*/
|
|
220
292
|
type InlineObjectRender = (props: InlineObjectRenderProps) => ReactElement;
|
|
221
293
|
/**
|
|
222
|
-
* @
|
|
294
|
+
* @public
|
|
223
295
|
*
|
|
224
296
|
* A container registration. Identifies a block object `_type` whose value
|
|
225
297
|
* holds editable children in `arrayField`. The optional `of` array carries
|
|
@@ -250,7 +322,7 @@ type Container = {
|
|
|
250
322
|
of?: ReadonlyArray<Container | TextBlock | BlockObject>;
|
|
251
323
|
};
|
|
252
324
|
/**
|
|
253
|
-
* @
|
|
325
|
+
* @public
|
|
254
326
|
*
|
|
255
327
|
* A text block registration. The text block `_type` is `'block'` at the
|
|
256
328
|
* top level. Positional overrides nested in a container's `of` array can
|
|
@@ -282,11 +354,16 @@ type TextBlock = {
|
|
|
282
354
|
* Inline-content positional overrides. A `Span` or `InlineObject`
|
|
283
355
|
* placed here scopes the inline render to this text block (or any
|
|
284
356
|
* text block of this `type` if registered at the top level).
|
|
357
|
+
* `Decorator` and `Annotation` entries scope those renders the
|
|
358
|
+
* same way: the decorator or annotation renders through this entry
|
|
359
|
+
* inside the text block, and through the global registration (or
|
|
360
|
+
* the legacy `renderDecorator`/`renderAnnotation` prop) everywhere
|
|
361
|
+
* else.
|
|
285
362
|
*/
|
|
286
|
-
of?: ReadonlyArray<Span | InlineObject>;
|
|
363
|
+
of?: ReadonlyArray<Span | InlineObject | Decorator | Annotation>;
|
|
287
364
|
};
|
|
288
365
|
/**
|
|
289
|
-
* @
|
|
366
|
+
* @public
|
|
290
367
|
*
|
|
291
368
|
* Text block render function. `children` carries the rendered spans -
|
|
292
369
|
* `renderDecorator`, `renderAnnotation`, `renderPlaceholder`, and range
|
|
@@ -309,11 +386,11 @@ type TextBlockRenderProps = {
|
|
|
309
386
|
renderDefault: (props: TextBlockRenderProps) => ReactElement;
|
|
310
387
|
};
|
|
311
388
|
/**
|
|
312
|
-
* @
|
|
389
|
+
* @public
|
|
313
390
|
*/
|
|
314
391
|
type TextBlockRender = (props: TextBlockRenderProps) => ReactElement;
|
|
315
392
|
/**
|
|
316
|
-
* @
|
|
393
|
+
* @public
|
|
317
394
|
*
|
|
318
395
|
* A span registration. The span `_type` is `'span'` at the top level.
|
|
319
396
|
* Positional overrides nested in a container's `of` array can register
|
|
@@ -332,7 +409,44 @@ type Span = {
|
|
|
332
409
|
render?: SpanRender;
|
|
333
410
|
};
|
|
334
411
|
/**
|
|
335
|
-
* @
|
|
412
|
+
* @public
|
|
413
|
+
*
|
|
414
|
+
* A decorator registration. `type` is a decorator name declared in
|
|
415
|
+
* the schema's `decorators` array, or `'*'` to match every decorator.
|
|
416
|
+
*/
|
|
417
|
+
type Decorator = {
|
|
418
|
+
kind: 'decorator';
|
|
419
|
+
type: string;
|
|
420
|
+
/**
|
|
421
|
+
* Outer render. Two modes:
|
|
422
|
+
* - omitted: fall through to global registered render (or identity,
|
|
423
|
+
* the engine default, if no global registration exists)
|
|
424
|
+
* - function: use this render. The function receives a `renderDefault`
|
|
425
|
+
* prop that returns identity when called.
|
|
426
|
+
*/
|
|
427
|
+
render?: DecoratorRender;
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* @public
|
|
431
|
+
*
|
|
432
|
+
* An annotation registration. `type` is an annotation `_type` declared
|
|
433
|
+
* in the schema's `annotations` array, or `'*'` to match every
|
|
434
|
+
* annotation type.
|
|
435
|
+
*/
|
|
436
|
+
type Annotation = {
|
|
437
|
+
kind: 'annotation';
|
|
438
|
+
type: string;
|
|
439
|
+
/**
|
|
440
|
+
* Outer render. Two modes:
|
|
441
|
+
* - omitted: fall through to global registered render (or identity,
|
|
442
|
+
* the engine default, if no global registration exists)
|
|
443
|
+
* - function: use this render. The function receives a `renderDefault`
|
|
444
|
+
* prop that returns identity when called.
|
|
445
|
+
*/
|
|
446
|
+
render?: AnnotationRender;
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* @public
|
|
336
450
|
*
|
|
337
451
|
* A non-editable block-level object registration. Identifies a `_type`
|
|
338
452
|
* whose value renders as a block-level void node (image, embed, etc.).
|
|
@@ -349,7 +463,7 @@ type BlockObject = {
|
|
|
349
463
|
render?: BlockObjectRender;
|
|
350
464
|
};
|
|
351
465
|
/**
|
|
352
|
-
* @
|
|
466
|
+
* @public
|
|
353
467
|
*
|
|
354
468
|
* A non-editable inline object registration. Identifies a `_type` whose
|
|
355
469
|
* value renders as an inline void node (mention, inline image, etc.).
|
|
@@ -366,14 +480,14 @@ type InlineObject = {
|
|
|
366
480
|
render?: InlineObjectRender;
|
|
367
481
|
};
|
|
368
482
|
/**
|
|
369
|
-
* @
|
|
483
|
+
* @public
|
|
370
484
|
*
|
|
371
485
|
* The discriminated union of every registration accepted by
|
|
372
486
|
* `editor.registerNode` and the `<NodePlugin>` component.
|
|
373
487
|
*/
|
|
374
|
-
type RegistrableNode = Container | TextBlock | Span | BlockObject | InlineObject;
|
|
488
|
+
type RegistrableNode = Container | TextBlock | Span | BlockObject | InlineObject | Decorator | Annotation;
|
|
375
489
|
/**
|
|
376
|
-
* @
|
|
490
|
+
* @public
|
|
377
491
|
*
|
|
378
492
|
* Define a container renderer. The returned registration is mounted via
|
|
379
493
|
* the `<NodePlugin>` component at the top level, or nested inside
|
|
@@ -411,7 +525,7 @@ declare function defineContainer<const TType extends string>(config: {
|
|
|
411
525
|
attributes: Record<string, unknown>;
|
|
412
526
|
children: ReactElement;
|
|
413
527
|
focused: boolean;
|
|
414
|
-
node:
|
|
528
|
+
node: TType extends 'span' | 'block' ? never : PortableTextObject;
|
|
415
529
|
path: Path;
|
|
416
530
|
readOnly: boolean;
|
|
417
531
|
selected: boolean;
|
|
@@ -420,7 +534,7 @@ declare function defineContainer<const TType extends string>(config: {
|
|
|
420
534
|
of?: ReadonlyArray<Container | TextBlock | BlockObject>;
|
|
421
535
|
}): Container;
|
|
422
536
|
/**
|
|
423
|
-
* @
|
|
537
|
+
* @public
|
|
424
538
|
*
|
|
425
539
|
* Define a span renderer. The returned registration is mounted via the
|
|
426
540
|
* `<NodePlugin>` component at the top level, or nested inside a
|
|
@@ -446,7 +560,57 @@ declare function defineSpan<const TType extends string>(config: {
|
|
|
446
560
|
render?: SpanRender;
|
|
447
561
|
}): Span;
|
|
448
562
|
/**
|
|
449
|
-
* @
|
|
563
|
+
* @public
|
|
564
|
+
*
|
|
565
|
+
* Define a decorator renderer for a decorator name declared in the
|
|
566
|
+
* schema's `decorators` array, or `'*'` to match every decorator.
|
|
567
|
+
* The returned registration is mounted via the `<NodePlugin>`
|
|
568
|
+
* component.
|
|
569
|
+
*
|
|
570
|
+
* Decorator names live in a different namespace than node
|
|
571
|
+
* `_type`s, so `type` has no forbidden values here (unlike
|
|
572
|
+
* `defineSpan`/`defineTextBlock`).
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* defineDecorator({
|
|
577
|
+
* type: 'strong',
|
|
578
|
+
* render: ({children}) => <strong>{children}</strong>,
|
|
579
|
+
* })
|
|
580
|
+
* ```
|
|
581
|
+
*/
|
|
582
|
+
declare function defineDecorator(config: {
|
|
583
|
+
type: string;
|
|
584
|
+
render?: DecoratorRender;
|
|
585
|
+
}): Decorator;
|
|
586
|
+
/**
|
|
587
|
+
* @public
|
|
588
|
+
*
|
|
589
|
+
* Define an annotation renderer for a `_type` declared in the
|
|
590
|
+
* schema's `annotations` array, or `'*'` to match every annotation
|
|
591
|
+
* type. The returned registration is mounted via the `<NodePlugin>`
|
|
592
|
+
* component.
|
|
593
|
+
*
|
|
594
|
+
* Annotation `_type`s live in a different namespace than node
|
|
595
|
+
* `_type`s, so `type` has no forbidden values here (unlike
|
|
596
|
+
* `defineInlineObject`/`defineBlockObject`).
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```ts
|
|
600
|
+
* defineAnnotation({
|
|
601
|
+
* type: 'link',
|
|
602
|
+
* render: ({annotation, children}) => (
|
|
603
|
+
* <a href={(annotation as {href?: string}).href}>{children}</a>
|
|
604
|
+
* ),
|
|
605
|
+
* })
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
declare function defineAnnotation(config: {
|
|
609
|
+
type: string;
|
|
610
|
+
render?: AnnotationRender;
|
|
611
|
+
}): Annotation;
|
|
612
|
+
/**
|
|
613
|
+
* @public
|
|
450
614
|
*
|
|
451
615
|
* Define a non-editable block-level object renderer for a `_type`
|
|
452
616
|
* declared in the schema's `blockObjects` array.
|
|
@@ -474,7 +638,7 @@ declare function defineBlockObject<const TType extends string>(config: {
|
|
|
474
638
|
render?: BlockObjectRender;
|
|
475
639
|
}): BlockObject;
|
|
476
640
|
/**
|
|
477
|
-
* @
|
|
641
|
+
* @public
|
|
478
642
|
*
|
|
479
643
|
* Define a non-editable inline object renderer for a `_type` declared
|
|
480
644
|
* in the schema's `inlineObjects` array.
|
|
@@ -502,7 +666,7 @@ declare function defineInlineObject<const TType extends string>(config: {
|
|
|
502
666
|
render?: InlineObjectRender;
|
|
503
667
|
}): InlineObject;
|
|
504
668
|
/**
|
|
505
|
-
* @
|
|
669
|
+
* @public
|
|
506
670
|
*
|
|
507
671
|
* Define a text block renderer. The returned registration is mounted
|
|
508
672
|
* via the `<NodePlugin>` component, or nested inside a container's
|
|
@@ -526,7 +690,7 @@ declare function defineInlineObject<const TType extends string>(config: {
|
|
|
526
690
|
declare function defineTextBlock<const TType extends string>(config: {
|
|
527
691
|
type: TType extends 'span' ? "Error: defineTextBlock({type: 'span'}) is forbidden -- 'span' is always a span, use defineSpan" : TType;
|
|
528
692
|
render?: TextBlockRender;
|
|
529
|
-
of?: ReadonlyArray<Span | InlineObject>;
|
|
693
|
+
of?: ReadonlyArray<Span | InlineObject | Decorator | Annotation>;
|
|
530
694
|
}): TextBlock;
|
|
531
695
|
/**
|
|
532
696
|
* @internal
|
|
@@ -536,6 +700,22 @@ declare function defineTextBlock<const TType extends string>(config: {
|
|
|
536
700
|
type SpanConfig = {
|
|
537
701
|
span: Span;
|
|
538
702
|
};
|
|
703
|
+
/**
|
|
704
|
+
* @internal
|
|
705
|
+
*
|
|
706
|
+
* Resolved decorator config.
|
|
707
|
+
*/
|
|
708
|
+
type DecoratorConfig = {
|
|
709
|
+
decorator: Decorator;
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* @internal
|
|
713
|
+
*
|
|
714
|
+
* Resolved annotation config.
|
|
715
|
+
*/
|
|
716
|
+
type AnnotationConfig = {
|
|
717
|
+
annotation: Annotation;
|
|
718
|
+
};
|
|
539
719
|
/**
|
|
540
720
|
* @internal
|
|
541
721
|
*
|
|
@@ -568,16 +748,13 @@ type ContainerConfig = {
|
|
|
568
748
|
* @internal
|
|
569
749
|
*
|
|
570
750
|
* Resolved text block config. The optional `of` carries resolved
|
|
571
|
-
* inline-content positional overrides (spans, inline-objects
|
|
572
|
-
*
|
|
751
|
+
* inline-content positional overrides (spans, inline-objects, and
|
|
752
|
+
* per-decorator and per-annotation overrides) for children rendered
|
|
753
|
+
* inside this text block.
|
|
573
754
|
*/
|
|
574
755
|
type TextBlockConfig = {
|
|
575
756
|
textBlock: TextBlock;
|
|
576
|
-
of?: ReadonlyArray<SpanConfig | InlineObjectConfig>;
|
|
577
|
-
};
|
|
578
|
-
type ChildArrayField = FieldDefinition & {
|
|
579
|
-
type: 'array';
|
|
580
|
-
of: ReadonlyArray<OfDefinition>;
|
|
757
|
+
of?: ReadonlyArray<SpanConfig | InlineObjectConfig | DecoratorConfig | AnnotationConfig>;
|
|
581
758
|
};
|
|
582
759
|
/**
|
|
583
760
|
* Public view of a registered editable container, surfaced on
|
|
@@ -597,8 +774,8 @@ type ChildArrayField = FieldDefinition & {
|
|
|
597
774
|
* scoped to this parent.
|
|
598
775
|
*
|
|
599
776
|
* The full container registration (including the render callback)
|
|
600
|
-
* lives on
|
|
601
|
-
*
|
|
777
|
+
* lives on an engine-internal map and is not exposed on the public
|
|
778
|
+
* context.
|
|
602
779
|
*
|
|
603
780
|
* Two top-level entries with the same `_type` cannot coexist - the
|
|
604
781
|
* register handler warns on duplicates. But the SAME `_type`
|
|
@@ -606,20 +783,24 @@ type ChildArrayField = FieldDefinition & {
|
|
|
606
783
|
* a feature; `resolveContainerAt` walks the positional tree using
|
|
607
784
|
* the path to return the entry that applies at a given position.
|
|
608
785
|
*
|
|
609
|
-
* @
|
|
786
|
+
* @public
|
|
610
787
|
*/
|
|
611
788
|
type RegisteredContainer = {
|
|
612
789
|
kind: 'container';
|
|
613
790
|
type: string;
|
|
614
|
-
field:
|
|
791
|
+
field: FieldDefinition & {
|
|
792
|
+
type: 'array';
|
|
793
|
+
of: ReadonlyArray<OfDefinition>;
|
|
794
|
+
};
|
|
615
795
|
of?: ReadonlyArray<RegisteredContainer | RegisteredPositional>;
|
|
616
796
|
};
|
|
797
|
+
type ChildArrayField = RegisteredContainer['field'];
|
|
617
798
|
/**
|
|
618
799
|
* Public view of a registered span, surfaced inside a containing
|
|
619
800
|
* {@link RegisteredContainer}'s `of` array as a positional
|
|
620
801
|
* registration. The render function is engine-internal.
|
|
621
802
|
*
|
|
622
|
-
* @
|
|
803
|
+
* @public
|
|
623
804
|
*/
|
|
624
805
|
type RegisteredSpan = {
|
|
625
806
|
kind: 'span';
|
|
@@ -630,7 +811,7 @@ type RegisteredSpan = {
|
|
|
630
811
|
* containing {@link RegisteredContainer}'s `of` array as a positional
|
|
631
812
|
* registration. The render function is engine-internal.
|
|
632
813
|
*
|
|
633
|
-
* @
|
|
814
|
+
* @public
|
|
634
815
|
*/
|
|
635
816
|
type RegisteredBlockObject = {
|
|
636
817
|
kind: 'blockObject';
|
|
@@ -641,7 +822,7 @@ type RegisteredBlockObject = {
|
|
|
641
822
|
* containing {@link RegisteredContainer}'s `of` array as a positional
|
|
642
823
|
* registration. The render function is engine-internal.
|
|
643
824
|
*
|
|
644
|
-
* @
|
|
825
|
+
* @public
|
|
645
826
|
*/
|
|
646
827
|
type RegisteredInlineObject = {
|
|
647
828
|
kind: 'inlineObject';
|
|
@@ -650,10 +831,9 @@ type RegisteredInlineObject = {
|
|
|
650
831
|
/**
|
|
651
832
|
* Union of non-container positional registrations that may appear in
|
|
652
833
|
* a {@link RegisteredContainer}'s `of` array. Text-block registrations
|
|
653
|
-
* are NOT included here
|
|
654
|
-
* not on the containers tree.
|
|
834
|
+
* are NOT included here and do not appear on the containers tree.
|
|
655
835
|
*
|
|
656
|
-
* @
|
|
836
|
+
* @public
|
|
657
837
|
*/
|
|
658
838
|
type RegisteredPositional = RegisteredSpan | RegisteredBlockObject | RegisteredInlineObject;
|
|
659
839
|
/**
|
|
@@ -673,7 +853,7 @@ type RegisteredPositional = RegisteredSpan | RegisteredBlockObject | RegisteredI
|
|
|
673
853
|
* does not find a positional override, the resolver falls back to the
|
|
674
854
|
* top-level entry for the type if one is registered.
|
|
675
855
|
*
|
|
676
|
-
* @
|
|
856
|
+
* @public
|
|
677
857
|
*/
|
|
678
858
|
type Containers = ReadonlyMap<string, RegisteredContainer>;
|
|
679
859
|
/**
|
|
@@ -1137,12 +1317,45 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
1137
1317
|
onPaste?: OnPasteFn;
|
|
1138
1318
|
onCopy?: OnCopyFn;
|
|
1139
1319
|
rangeDecorations?: RangeDecoration[];
|
|
1320
|
+
/**
|
|
1321
|
+
* @deprecated Register your annotations with `defineAnnotation`
|
|
1322
|
+
* mounted through `NodePlugin` instead. See the migration guide:
|
|
1323
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1324
|
+
*/
|
|
1140
1325
|
renderAnnotation?: RenderAnnotationFunction;
|
|
1326
|
+
/**
|
|
1327
|
+
* @deprecated Register your block objects and text blocks with
|
|
1328
|
+
* `defineBlockObject` / `defineTextBlock` mounted through `NodePlugin`
|
|
1329
|
+
* instead. See the migration guide:
|
|
1330
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1331
|
+
*/
|
|
1141
1332
|
renderBlock?: RenderBlockFunction;
|
|
1333
|
+
/**
|
|
1334
|
+
* @deprecated Register your inline objects and spans with
|
|
1335
|
+
* `defineInlineObject` / `defineSpan` mounted through `NodePlugin`
|
|
1336
|
+
* instead. See the migration guide:
|
|
1337
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1338
|
+
*/
|
|
1142
1339
|
renderChild?: RenderChildFunction;
|
|
1340
|
+
/**
|
|
1341
|
+
* @deprecated Register your decorators with `defineDecorator` mounted
|
|
1342
|
+
* through `NodePlugin` instead. See the migration guide:
|
|
1343
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1344
|
+
*/
|
|
1143
1345
|
renderDecorator?: RenderDecoratorFunction;
|
|
1346
|
+
/**
|
|
1347
|
+
* @deprecated Render list items with `defineTextBlock` mounted through
|
|
1348
|
+
* `NodePlugin`, with list numbering from
|
|
1349
|
+
* `@portabletext/plugin-list-index`. See the migration guide:
|
|
1350
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1351
|
+
*/
|
|
1144
1352
|
renderListItem?: RenderListItemFunction;
|
|
1145
1353
|
renderPlaceholder?: RenderPlaceholderFunction;
|
|
1354
|
+
/**
|
|
1355
|
+
* @deprecated Render text-block styles with `defineTextBlock` mounted
|
|
1356
|
+
* through `NodePlugin` instead. See the migration guide:
|
|
1357
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1358
|
+
*/
|
|
1146
1359
|
renderStyle?: RenderStyleFunction;
|
|
1147
1360
|
scrollSelectionIntoView?: ScrollSelectionIntoViewFunction;
|
|
1148
1361
|
selection?: EditorSelection;
|
|
@@ -1169,7 +1382,12 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
1169
1382
|
* @group Components
|
|
1170
1383
|
*/
|
|
1171
1384
|
declare const PortableTextEditable: import("react").ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & import("react").RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
1172
|
-
/**
|
|
1385
|
+
/**
|
|
1386
|
+
* @beta
|
|
1387
|
+
* @deprecated `EditableAPIDeleteOptions` is deprecated together with the
|
|
1388
|
+
* `PortableTextEditor.delete` static. Send a `delete` behavior event (with
|
|
1389
|
+
* an optional `unit`) or a `delete.block` event via `editor.send` instead.
|
|
1390
|
+
*/
|
|
1173
1391
|
interface EditableAPIDeleteOptions {
|
|
1174
1392
|
mode?: 'blocks' | 'children' | 'selected';
|
|
1175
1393
|
}
|
|
@@ -1190,7 +1408,7 @@ type AddedAnnotationPaths = {
|
|
|
1190
1408
|
*/
|
|
1191
1409
|
spanPath: Path;
|
|
1192
1410
|
};
|
|
1193
|
-
/** @
|
|
1411
|
+
/** @internal */
|
|
1194
1412
|
interface EditableAPI {
|
|
1195
1413
|
activeAnnotations: () => PortableTextObject[];
|
|
1196
1414
|
isAnnotationActive: (annotationType: PortableTextObject['_type']) => boolean;
|
|
@@ -1251,7 +1469,7 @@ type EditorSelection = {
|
|
|
1251
1469
|
} | null;
|
|
1252
1470
|
/**
|
|
1253
1471
|
* The editor has invalid data in the value that can be resolved by the user
|
|
1254
|
-
* @
|
|
1472
|
+
* @public */
|
|
1255
1473
|
type InvalidValueResolution = {
|
|
1256
1474
|
autoResolve?: boolean;
|
|
1257
1475
|
patches: Patch[];
|
|
@@ -1296,7 +1514,14 @@ interface PasteData {
|
|
|
1296
1514
|
type OnPasteFn = (data: PasteData) => OnPasteResultOrPromise;
|
|
1297
1515
|
/** @beta */
|
|
1298
1516
|
type OnCopyFn = (event: ClipboardEvent$1<HTMLDivElement | HTMLSpanElement>) => undefined | unknown;
|
|
1299
|
-
/**
|
|
1517
|
+
/**
|
|
1518
|
+
* @beta
|
|
1519
|
+
* @deprecated `BlockRenderProps` is deprecated together with the
|
|
1520
|
+
* `renderBlock` render prop it serves. Type against
|
|
1521
|
+
* `BlockObjectRenderProps` / `TextBlockRenderProps` from the node
|
|
1522
|
+
* registration API instead. See the migration guide:
|
|
1523
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1524
|
+
*/
|
|
1300
1525
|
interface BlockRenderProps {
|
|
1301
1526
|
children: ReactElement<any>;
|
|
1302
1527
|
editorElementRef: RefObject<HTMLElement | null>;
|
|
@@ -1309,7 +1534,14 @@ interface BlockRenderProps {
|
|
|
1309
1534
|
schemaType: BlockObjectSchemaType;
|
|
1310
1535
|
value: PortableTextBlock;
|
|
1311
1536
|
}
|
|
1312
|
-
/**
|
|
1537
|
+
/**
|
|
1538
|
+
* @beta
|
|
1539
|
+
* @deprecated `BlockChildRenderProps` is deprecated together with the
|
|
1540
|
+
* `renderChild` render prop it serves. Type against
|
|
1541
|
+
* `InlineObjectRenderProps` / `SpanRenderProps` from the node
|
|
1542
|
+
* registration API instead. See the migration guide:
|
|
1543
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1544
|
+
*/
|
|
1313
1545
|
interface BlockChildRenderProps {
|
|
1314
1546
|
annotations: PortableTextObject[];
|
|
1315
1547
|
children: ReactElement<any>;
|
|
@@ -1320,7 +1552,14 @@ interface BlockChildRenderProps {
|
|
|
1320
1552
|
schemaType: InlineObjectSchemaType;
|
|
1321
1553
|
value: PortableTextChild;
|
|
1322
1554
|
}
|
|
1323
|
-
/**
|
|
1555
|
+
/**
|
|
1556
|
+
* @beta
|
|
1557
|
+
* @deprecated `BlockAnnotationRenderProps` is deprecated together with the
|
|
1558
|
+
* `renderAnnotation` render prop it serves. Type against
|
|
1559
|
+
* `AnnotationRenderProps` from the node registration API instead. See the
|
|
1560
|
+
* migration guide:
|
|
1561
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1562
|
+
*/
|
|
1324
1563
|
interface BlockAnnotationRenderProps {
|
|
1325
1564
|
block: PortableTextBlock;
|
|
1326
1565
|
children: ReactElement<any>;
|
|
@@ -1331,7 +1570,14 @@ interface BlockAnnotationRenderProps {
|
|
|
1331
1570
|
selected: boolean;
|
|
1332
1571
|
value: PortableTextObject;
|
|
1333
1572
|
}
|
|
1334
|
-
/**
|
|
1573
|
+
/**
|
|
1574
|
+
* @beta
|
|
1575
|
+
* @deprecated `BlockDecoratorRenderProps` is deprecated together with the
|
|
1576
|
+
* `renderDecorator` render prop it serves. Type against
|
|
1577
|
+
* `DecoratorRenderProps` from the node registration API instead. See the
|
|
1578
|
+
* migration guide:
|
|
1579
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1580
|
+
*/
|
|
1335
1581
|
interface BlockDecoratorRenderProps {
|
|
1336
1582
|
children: ReactElement<any>;
|
|
1337
1583
|
editorElementRef: RefObject<HTMLElement | null>;
|
|
@@ -1341,7 +1587,14 @@ interface BlockDecoratorRenderProps {
|
|
|
1341
1587
|
selected: boolean;
|
|
1342
1588
|
value: string;
|
|
1343
1589
|
}
|
|
1344
|
-
/**
|
|
1590
|
+
/**
|
|
1591
|
+
* @beta
|
|
1592
|
+
* @deprecated `BlockListItemRenderProps` is deprecated together with the
|
|
1593
|
+
* `renderListItem` render prop it serves. Render list items with
|
|
1594
|
+
* `defineTextBlock` mounted through `NodePlugin` instead. See the
|
|
1595
|
+
* migration guide:
|
|
1596
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1597
|
+
*/
|
|
1345
1598
|
interface BlockListItemRenderProps {
|
|
1346
1599
|
block: PortableTextTextBlock;
|
|
1347
1600
|
children: ReactElement<any>;
|
|
@@ -1353,19 +1606,51 @@ interface BlockListItemRenderProps {
|
|
|
1353
1606
|
selected: boolean;
|
|
1354
1607
|
value: string;
|
|
1355
1608
|
}
|
|
1356
|
-
/**
|
|
1609
|
+
/**
|
|
1610
|
+
* @beta
|
|
1611
|
+
* @deprecated The `renderBlock` render prop is deprecated. Register your
|
|
1612
|
+
* block objects and text blocks with `defineBlockObject` /
|
|
1613
|
+
* `defineTextBlock` mounted through `NodePlugin` instead. See the
|
|
1614
|
+
* migration guide:
|
|
1615
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1616
|
+
*/
|
|
1357
1617
|
type RenderBlockFunction = (props: BlockRenderProps) => JSX.Element;
|
|
1358
|
-
/**
|
|
1618
|
+
/**
|
|
1619
|
+
* @beta
|
|
1620
|
+
* @deprecated The `renderChild` render prop is deprecated. Register your
|
|
1621
|
+
* inline objects and spans with `defineInlineObject` / `defineSpan`
|
|
1622
|
+
* mounted through `NodePlugin` instead. See the migration guide:
|
|
1623
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1624
|
+
*/
|
|
1359
1625
|
type RenderChildFunction = (props: BlockChildRenderProps) => JSX.Element;
|
|
1360
|
-
/** @
|
|
1626
|
+
/** @public */
|
|
1361
1627
|
type RenderEditableFunction = (props: PortableTextEditableProps) => JSX.Element;
|
|
1362
|
-
/**
|
|
1628
|
+
/**
|
|
1629
|
+
* @beta
|
|
1630
|
+
* @deprecated The `renderAnnotation` render prop is deprecated. Register
|
|
1631
|
+
* your annotations with `defineAnnotation` mounted through `NodePlugin`
|
|
1632
|
+
* instead. See the migration guide:
|
|
1633
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1634
|
+
*/
|
|
1363
1635
|
type RenderAnnotationFunction = (props: BlockAnnotationRenderProps) => JSX.Element;
|
|
1364
|
-
/** @
|
|
1636
|
+
/** @public */
|
|
1365
1637
|
type RenderPlaceholderFunction = () => React.ReactNode;
|
|
1366
|
-
/**
|
|
1638
|
+
/**
|
|
1639
|
+
* @beta
|
|
1640
|
+
* @deprecated The `renderStyle` render prop is deprecated. Render
|
|
1641
|
+
* text-block styles with `defineTextBlock` mounted through `NodePlugin`
|
|
1642
|
+
* instead. See the migration guide:
|
|
1643
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1644
|
+
*/
|
|
1367
1645
|
type RenderStyleFunction = (props: BlockStyleRenderProps) => JSX.Element;
|
|
1368
|
-
/**
|
|
1646
|
+
/**
|
|
1647
|
+
* @beta
|
|
1648
|
+
* @deprecated `BlockStyleRenderProps` is deprecated together with the
|
|
1649
|
+
* `renderStyle` render prop it serves. Render text-block styles with
|
|
1650
|
+
* `defineTextBlock` mounted through `NodePlugin` instead. See the
|
|
1651
|
+
* migration guide:
|
|
1652
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1653
|
+
*/
|
|
1369
1654
|
interface BlockStyleRenderProps {
|
|
1370
1655
|
block: PortableTextTextBlock;
|
|
1371
1656
|
children: ReactElement<any>;
|
|
@@ -1376,32 +1661,45 @@ interface BlockStyleRenderProps {
|
|
|
1376
1661
|
schemaType: StyleSchemaType;
|
|
1377
1662
|
value: string;
|
|
1378
1663
|
}
|
|
1379
|
-
/**
|
|
1664
|
+
/**
|
|
1665
|
+
* @beta
|
|
1666
|
+
* @deprecated The `renderListItem` render prop is deprecated. Render list
|
|
1667
|
+
* items with `defineTextBlock` mounted through `NodePlugin`, with list
|
|
1668
|
+
* numbering from `@portabletext/plugin-list-index`. See the migration
|
|
1669
|
+
* guide:
|
|
1670
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1671
|
+
*/
|
|
1380
1672
|
type RenderListItemFunction = (props: BlockListItemRenderProps) => JSX.Element;
|
|
1381
|
-
/**
|
|
1673
|
+
/**
|
|
1674
|
+
* @beta
|
|
1675
|
+
* @deprecated The `renderDecorator` render prop is deprecated. Register
|
|
1676
|
+
* your decorators with `defineDecorator` mounted through `NodePlugin`
|
|
1677
|
+
* instead. See the migration guide:
|
|
1678
|
+
* https://www.portabletext.org/editor/guides/migrate-render-props/
|
|
1679
|
+
*/
|
|
1382
1680
|
type RenderDecoratorFunction = (props: BlockDecoratorRenderProps) => JSX.Element;
|
|
1383
|
-
/** @
|
|
1681
|
+
/** @public */
|
|
1384
1682
|
type ScrollSelectionIntoViewFunction = (editor: PortableTextEditor, domRange: globalThis.Range) => void;
|
|
1385
1683
|
/**
|
|
1386
|
-
*
|
|
1387
|
-
* @
|
|
1684
|
+
* Details passed to a `RangeDecoration`'s `onMoved` callback.
|
|
1685
|
+
* @public */
|
|
1388
1686
|
interface RangeDecorationOnMovedDetails {
|
|
1389
1687
|
rangeDecoration: RangeDecoration;
|
|
1390
1688
|
newSelection: EditorSelection;
|
|
1391
1689
|
origin: 'remote' | 'local';
|
|
1392
1690
|
}
|
|
1393
1691
|
/**
|
|
1394
|
-
* A
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1397
|
-
* @
|
|
1692
|
+
* A UI affordance that wraps a selection range in the editor with a custom
|
|
1693
|
+
* component, for example to highlight search results, mark validation
|
|
1694
|
+
* errors on specific words, or draw user presence.
|
|
1695
|
+
* @public */
|
|
1398
1696
|
interface RangeDecoration {
|
|
1399
1697
|
/**
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1698
|
+
* The component that renders the range decoration. It receives the
|
|
1699
|
+
* decorated text as its children.
|
|
1402
1700
|
*
|
|
1403
1701
|
* @example
|
|
1404
|
-
* ```
|
|
1702
|
+
* ```tsx
|
|
1405
1703
|
* (rangeComponentProps: PropsWithChildren) => (
|
|
1406
1704
|
* <SearchResultHighlight>
|
|
1407
1705
|
* {rangeComponentProps.children}
|
|
@@ -1411,15 +1709,17 @@ interface RangeDecoration {
|
|
|
1411
1709
|
*/
|
|
1412
1710
|
component: (props: PropsWithChildren) => ReactElement<any>;
|
|
1413
1711
|
/**
|
|
1414
|
-
* The editor content selection range
|
|
1712
|
+
* The editor content selection range to decorate.
|
|
1415
1713
|
*/
|
|
1416
1714
|
selection: EditorSelection;
|
|
1417
1715
|
/**
|
|
1418
|
-
*
|
|
1716
|
+
* Called when edits move the decorated range. The details carry the new
|
|
1717
|
+
* selection (`null` when the range is lost) and whether the edit was
|
|
1718
|
+
* `local` or `remote`.
|
|
1419
1719
|
*/
|
|
1420
1720
|
onMoved?: (details: RangeDecorationOnMovedDetails) => void;
|
|
1421
1721
|
/**
|
|
1422
|
-
* A custom payload that can be set on the range decoration
|
|
1722
|
+
* A custom payload that can be set on the range decoration.
|
|
1423
1723
|
*/
|
|
1424
1724
|
payload?: Record<string, unknown>;
|
|
1425
1725
|
}
|
|
@@ -1854,7 +2154,9 @@ interface PortableTextEditorEngine extends DOMEditor {
|
|
|
1854
2154
|
_key: 'editor';
|
|
1855
2155
|
_type: 'editor';
|
|
1856
2156
|
containers: ResolvedContainers;
|
|
2157
|
+
annotations: Map<string, AnnotationConfig>;
|
|
1857
2158
|
blockObjects: Map<string, BlockObjectConfig>;
|
|
2159
|
+
decorators: Map<string, DecoratorConfig>;
|
|
1858
2160
|
inlineObjects: Map<string, InlineObjectConfig>;
|
|
1859
2161
|
spans: Map<string, SpanConfig>;
|
|
1860
2162
|
textBlocks: Map<string, TextBlockConfig>;
|
|
@@ -1959,7 +2261,7 @@ type EditorContext = {
|
|
|
1959
2261
|
* `resolveContainerAt(containers, value, path)` for position-aware
|
|
1960
2262
|
* resolution that handles both top-level and positional entries.
|
|
1961
2263
|
*
|
|
1962
|
-
* @
|
|
2264
|
+
* @public
|
|
1963
2265
|
*/
|
|
1964
2266
|
containers: Containers;
|
|
1965
2267
|
};
|
|
@@ -1976,7 +2278,7 @@ type EditorSnapshot = {
|
|
|
1976
2278
|
decoratorState: Record<string, boolean | undefined>;
|
|
1977
2279
|
};
|
|
1978
2280
|
/**
|
|
1979
|
-
* @
|
|
2281
|
+
* @public
|
|
1980
2282
|
*/
|
|
1981
2283
|
type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
1982
2284
|
snapshot: EditorSnapshot;
|
|
@@ -1984,7 +2286,7 @@ type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
1984
2286
|
dom: EditorDom;
|
|
1985
2287
|
}) => TGuardResponse | false;
|
|
1986
2288
|
/**
|
|
1987
|
-
* @
|
|
2289
|
+
* @public
|
|
1988
2290
|
*/
|
|
1989
2291
|
type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'], TGuardResponse = true, TBehaviorEvent extends ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>> = {
|
|
1990
2292
|
/**
|
|
@@ -2004,7 +2306,7 @@ type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*`
|
|
|
2004
2306
|
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>;
|
|
2005
2307
|
};
|
|
2006
2308
|
/**
|
|
2007
|
-
* @
|
|
2309
|
+
* @public
|
|
2008
2310
|
*
|
|
2009
2311
|
* @example
|
|
2010
2312
|
*
|
|
@@ -2134,9 +2436,6 @@ type PatchEvent = {
|
|
|
2134
2436
|
* @public
|
|
2135
2437
|
*/
|
|
2136
2438
|
type EditorConfig = {
|
|
2137
|
-
/**
|
|
2138
|
-
* @beta
|
|
2139
|
-
*/
|
|
2140
2439
|
keyGenerator?: () => string;
|
|
2141
2440
|
readOnly?: boolean;
|
|
2142
2441
|
initialValue?: Array<PortableTextBlock>;
|
|
@@ -2176,7 +2475,7 @@ type Editor = {
|
|
|
2176
2475
|
dom: EditorDom;
|
|
2177
2476
|
getSnapshot: () => EditorSnapshot;
|
|
2178
2477
|
/**
|
|
2179
|
-
* @
|
|
2478
|
+
* @public
|
|
2180
2479
|
*/
|
|
2181
2480
|
registerBehavior: (config: {
|
|
2182
2481
|
behavior: Behavior;
|
|
@@ -2184,10 +2483,11 @@ type Editor = {
|
|
|
2184
2483
|
/**
|
|
2185
2484
|
* Register a node renderer. The `node` argument is the result of one
|
|
2186
2485
|
* of the `defineX` factories (`defineContainer`, `defineTextBlock`,
|
|
2187
|
-
* `defineSpan`, `defineBlockObject`, `defineInlineObject
|
|
2188
|
-
* a function that
|
|
2486
|
+
* `defineSpan`, `defineBlockObject`, `defineInlineObject`,
|
|
2487
|
+
* `defineDecorator`, `defineAnnotation`). Returns a function that
|
|
2488
|
+
* unregisters the node when called.
|
|
2189
2489
|
*
|
|
2190
|
-
* @
|
|
2490
|
+
* @public
|
|
2191
2491
|
*/
|
|
2192
2492
|
registerNode: (config: {
|
|
2193
2493
|
node: RegistrableNode;
|
|
@@ -2333,7 +2633,7 @@ declare const defaultKeyGenerator: () => string;
|
|
|
2333
2633
|
*/
|
|
2334
2634
|
declare function useEditor(): Editor;
|
|
2335
2635
|
/**
|
|
2336
|
-
* @
|
|
2636
|
+
* @public
|
|
2337
2637
|
*/
|
|
2338
2638
|
type BlockOffset = {
|
|
2339
2639
|
path: BlockPath;
|
|
@@ -2652,7 +2952,7 @@ type SpanWithOptionalKey = Omit<PortableTextSpan, '_key'> & {
|
|
|
2652
2952
|
};
|
|
2653
2953
|
type ChildWithOptionalKey = SpanWithOptionalKey | ObjectBlockWithOptionalKey;
|
|
2654
2954
|
/**
|
|
2655
|
-
* @
|
|
2955
|
+
* @public
|
|
2656
2956
|
*/
|
|
2657
2957
|
type BehaviorEvent = SyntheticBehaviorEvent | NativeBehaviorEvent | CustomBehaviorEvent;
|
|
2658
2958
|
type BehaviorEventTypeNamespace = SyntheticBehaviorEventNamespace | NativeBehaviorEventNamespace | CustomBehaviorEventNamespace;
|
|
@@ -2683,7 +2983,7 @@ declare const syntheticBehaviorEventTypes: readonly ["annotation.add", "annotati
|
|
|
2683
2983
|
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number] | (typeof abstractBehaviorEventTypes)[number];
|
|
2684
2984
|
type SyntheticBehaviorEventNamespace = ExtractNamespace<SyntheticBehaviorEventType>;
|
|
2685
2985
|
/**
|
|
2686
|
-
* @
|
|
2986
|
+
* @public
|
|
2687
2987
|
*/
|
|
2688
2988
|
type SyntheticBehaviorEvent = {
|
|
2689
2989
|
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.add'>;
|
|
@@ -2893,7 +3193,7 @@ type SyntheticBehaviorEvent = {
|
|
|
2893
3193
|
at: Path;
|
|
2894
3194
|
} | AbstractBehaviorEvent;
|
|
2895
3195
|
/**
|
|
2896
|
-
* @
|
|
3196
|
+
* @public
|
|
2897
3197
|
*/
|
|
2898
3198
|
type InsertPlacement = 'auto' | 'after' | 'before';
|
|
2899
3199
|
/**************************************
|
|
@@ -3043,7 +3343,7 @@ declare const nativeBehaviorEventTypes: readonly ["clipboard.copy", "clipboard.c
|
|
|
3043
3343
|
type NativeBehaviorEventType = (typeof nativeBehaviorEventTypes)[number];
|
|
3044
3344
|
type NativeBehaviorEventNamespace = ExtractNamespace<NativeBehaviorEventType>;
|
|
3045
3345
|
/**
|
|
3046
|
-
* @
|
|
3346
|
+
* @public
|
|
3047
3347
|
*/
|
|
3048
3348
|
type NativeBehaviorEvent = ClipboardBehaviorEvent | DragBehaviorEvent | InputBehaviorEvent | KeyboardBehaviorEvent | MouseBehaviorEvent;
|
|
3049
3349
|
type ClipboardBehaviorEvent = {
|
|
@@ -3143,7 +3443,7 @@ type MouseBehaviorEvent = {
|
|
|
3143
3443
|
type CustomBehaviorEventNamespace = 'custom';
|
|
3144
3444
|
type CustomBehaviorEventType<TNamespace extends CustomBehaviorEventNamespace, TType extends string = ''> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`;
|
|
3145
3445
|
/**
|
|
3146
|
-
* @
|
|
3446
|
+
* @public
|
|
3147
3447
|
*/
|
|
3148
3448
|
type CustomBehaviorEvent<TPayload extends Record<string, unknown> = Record<string, unknown>, TType extends string = string, TInternalType extends CustomBehaviorEventType<'custom', TType> = CustomBehaviorEventType<'custom', TType>> = {
|
|
3149
3449
|
type: TInternalType;
|
|
@@ -3189,7 +3489,7 @@ type EditorDom = {
|
|
|
3189
3489
|
}) => void;
|
|
3190
3490
|
};
|
|
3191
3491
|
/**
|
|
3192
|
-
* @
|
|
3492
|
+
* @public
|
|
3193
3493
|
*/
|
|
3194
3494
|
type BehaviorAction = {
|
|
3195
3495
|
type: 'execute';
|
|
@@ -3243,7 +3543,7 @@ type BehaviorAction = {
|
|
|
3243
3543
|
* })
|
|
3244
3544
|
* ```
|
|
3245
3545
|
*
|
|
3246
|
-
* @
|
|
3546
|
+
* @public
|
|
3247
3547
|
*/
|
|
3248
3548
|
declare function execute(event: SyntheticBehaviorEvent): PickFromUnion<BehaviorAction, 'type', 'execute'>;
|
|
3249
3549
|
/**
|
|
@@ -3281,7 +3581,7 @@ declare function execute(event: SyntheticBehaviorEvent): PickFromUnion<BehaviorA
|
|
|
3281
3581
|
* })
|
|
3282
3582
|
* ```
|
|
3283
3583
|
*
|
|
3284
|
-
* @
|
|
3584
|
+
* @public
|
|
3285
3585
|
*/
|
|
3286
3586
|
declare function forward(event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent): PickFromUnion<BehaviorAction, 'type', 'forward'>;
|
|
3287
3587
|
/**
|
|
@@ -3315,7 +3615,7 @@ declare function forward(event: NativeBehaviorEvent | SyntheticBehaviorEvent | C
|
|
|
3315
3615
|
* })
|
|
3316
3616
|
* ```
|
|
3317
3617
|
*
|
|
3318
|
-
* @
|
|
3618
|
+
* @public
|
|
3319
3619
|
*/
|
|
3320
3620
|
declare function raise$1(event: SyntheticBehaviorEvent | CustomBehaviorEvent): PickFromUnion<BehaviorAction, 'type', 'raise'>;
|
|
3321
3621
|
/**
|
|
@@ -3358,16 +3658,16 @@ declare function raise$1(event: SyntheticBehaviorEvent | CustomBehaviorEvent): P
|
|
|
3358
3658
|
* })
|
|
3359
3659
|
* ```
|
|
3360
3660
|
*
|
|
3361
|
-
* @
|
|
3661
|
+
* @public
|
|
3362
3662
|
*/
|
|
3363
3663
|
declare function effect(effect: PickFromUnion<BehaviorAction, 'type', 'effect'>['effect']): PickFromUnion<BehaviorAction, 'type', 'effect'>;
|
|
3364
3664
|
/**
|
|
3365
|
-
* @
|
|
3665
|
+
* @public
|
|
3366
3666
|
*/
|
|
3367
3667
|
type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
3368
3668
|
snapshot: EditorSnapshot;
|
|
3369
3669
|
event: TBehaviorEvent;
|
|
3370
3670
|
dom: EditorDom;
|
|
3371
3671
|
}, guardResponse: TGuardResponse) => Array<BehaviorAction>;
|
|
3372
|
-
export {
|
|
3373
|
-
//# sourceMappingURL=behavior.types.action-
|
|
3672
|
+
export { BehaviorGuard as $, DecoratorRender as $t, PortableTextSpan$1 as A, PortableTextEditableProps as At, usePortableTextEditor as B, RegisteredInlineObject as Bt, ListDefinition as C, PathSegment as Cn, RenderDecoratorFunction as Ct, PortableTextBlock$1 as D, RenderStyleFunction as Dt, Patch$1 as E, RenderPlaceholderFunction as Et, defineSchema as F, Node$1 as Ft, Editor as G, AnnotationRenderProps as Gt, useEditorSelector as H, RegisteredSpan as Ht, BlockOffset as I, EditorSchema as It, EditorEmittedEvent as J, BlockObjectRenderProps as Jt, EditorConfig as K, BlockObject as Kt, useEditor as L, Containers as Lt, SchemaDefinition$1 as M, PortableTextEditor as Mt, StyleDefinition as N, resolveContainerAt as Nt, PortableTextChild$1 as O, ScrollSelectionIntoViewFunction as Ot, StyleSchemaType$1 as P, TraversalSnapshot as Pt, defineBehavior as Q, Decorator as Qt, defaultKeyGenerator as R, RegisteredBlockObject as Rt, InlineObjectSchemaType$1 as S, Path as Sn, RenderChildFunction as St, OfDefinition$1 as T, RenderListItemFunction as Tt, EditorProvider as U, Annotation as Ut, EditorSelector as V, RegisteredPositional as Vt, EditorProviderProps as W, AnnotationRender as Wt, Operation as X, ContainerRender as Xt, MutationEvent as Y, Container as Yt, Behavior as Z, ContainerRenderProps as Zt, BlockObjectSchemaType$1 as _, defineTextBlock as _n, PasteData as _t, forward as a, Span as an, BlockDecoratorRenderProps as at, FieldDefinition$1 as b, ChildPath as bn, RenderAnnotationFunction as bt, CustomBehaviorEvent as c, TextBlock as cn, BlockStyleRenderProps as ct, SyntheticBehaviorEvent as d, defineAnnotation as dn, EditorSelectionPoint as dt, DecoratorRenderProps as en, EditorContext as et, PatchesEvent as f, defineBlockObject as fn, InvalidValueResolution as ft, BlockObjectDefinition as g, defineSpan as gn, OnPasteResultOrPromise as gt, BaseDefinition as h, defineInlineObject as hn, OnPasteResult as ht, execute as i, RegistrableNode as in, BlockChildRenderProps as it, PortableTextTextBlock$1 as j, HotkeyOptions as jt, PortableTextObject$1 as k, PortableTextEditable as kt, InsertPlacement as l, TextBlockRender as ln, EditableAPIDeleteOptions as lt, AnnotationSchemaType$1 as m, defineDecorator as mn, OnPasteFn as mt, BehaviorActionSet as n, InlineObjectRender as nn, AddedAnnotationPaths as nt, raise$1 as o, SpanRender as on, BlockListItemRenderProps as ot, AnnotationDefinition as p, defineContainer as pn, OnCopyFn as pt, EditorEvent as q, BlockObjectRender as qt, effect as r, InlineObjectRenderProps as rn, BlockAnnotationRenderProps as rt, BehaviorEvent as s, SpanRenderProps as sn, BlockRenderProps as st, BehaviorAction as t, InlineObject as tn, EditorSnapshot as tt, NativeBehaviorEvent as u, TextBlockRenderProps as un, EditorSelection as ut, DecoratorDefinition as v, AnnotationPath as vn, RangeDecoration as vt, ListSchemaType$1 as w, RenderEditableFunction as wt, InlineObjectDefinition as x, KeyedSegment as xn, RenderBlockFunction as xt, DecoratorSchemaType$1 as y, BlockPath as yn, RangeDecorationOnMovedDetails as yt, usePortableTextEditorSelection as z, RegisteredContainer as zt };
|
|
3673
|
+
//# sourceMappingURL=behavior.types.action-DH6ujvaH.d.ts.map
|