@portabletext/editor 6.0.1-canary.3 → 6.0.1-canary.4

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,8 +1,8 @@
1
1
  import * as _portabletext_schema6 from "@portabletext/schema";
2
- import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, StyleSchemaType as StyleSchemaType$1, TypedObject, defineSchema } from "@portabletext/schema";
3
- import * as xstate77 from "xstate";
2
+ import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition, 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";
3
+ import * as xstate73 from "xstate";
4
4
  import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
5
- import * as react13 from "react";
5
+ import * as react4 from "react";
6
6
  import React$1, { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
7
7
  import { Patch, Patch as Patch$1 } from "@portabletext/patches";
8
8
  type MIMEType = `${string}/${string}`;
@@ -106,1174 +106,106 @@ type ChildPath = [{
106
106
  }, 'children', {
107
107
  _key: string;
108
108
  }];
109
- type LeafEdge = 'start' | 'end';
110
- type MaximizeMode = RangeMode | 'all';
111
- type MoveUnit = 'offset' | 'character' | 'word' | 'line';
112
- type RangeDirection = TextDirection | 'outward' | 'inward';
113
- type RangeMode = 'highest' | 'lowest';
114
- type SelectionEdge = 'anchor' | 'focus' | 'start' | 'end';
115
- type SelectionMode = 'all' | 'highest' | 'lowest';
116
- type TextDirection = 'forward' | 'backward';
117
- type TextUnit = 'character' | 'word' | 'line' | 'block';
118
- type TextUnitAdjustment = TextUnit | 'offset';
119
- type OmitFirstArg<F> = F extends ((x: any, ...args: infer P) => infer R) ? (...args: P) => R : never;
120
- interface NodeInsertNodesOptions<T extends Node$1> {
121
- at?: Location;
122
- match?: NodeMatch<T>;
123
- mode?: RangeMode;
124
- hanging?: boolean;
125
- select?: boolean;
126
- voids?: boolean;
127
- batchDirty?: boolean;
128
- }
129
- interface NodeTransforms {
130
- /**
131
- * Insert nodes in the editor
132
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
133
- */
134
- insertNodes: <T extends Node$1>(editor: Editor$1, nodes: Node$1 | Node$1[], options?: NodeInsertNodesOptions<T>) => void;
135
- /**
136
- * Lift nodes at a specific location upwards in the document tree, splitting
137
- * their parent in two if necessary.
138
- */
139
- liftNodes: <T extends Node$1>(editor: Editor$1, options?: {
140
- at?: Location;
141
- match?: NodeMatch<T>;
142
- mode?: MaximizeMode;
143
- voids?: boolean;
144
- }) => void;
145
- /**
146
- * Merge a node at a location with the previous node of the same depth,
147
- * removing any empty containing nodes after the merge if necessary.
148
- */
149
- mergeNodes: <T extends Node$1>(editor: Editor$1, options?: {
150
- at?: Location;
151
- match?: NodeMatch<T>;
152
- mode?: RangeMode;
153
- hanging?: boolean;
154
- voids?: boolean;
155
- }) => void;
156
- /**
157
- * Move the nodes at a location to a new location.
158
- */
159
- moveNodes: <T extends Node$1>(editor: Editor$1, options: {
160
- at?: Location;
161
- match?: NodeMatch<T>;
162
- mode?: MaximizeMode;
163
- to: Path$1;
164
- voids?: boolean;
165
- }) => void;
166
- /**
167
- * Remove the nodes at a specific location in the document.
168
- */
169
- removeNodes: <T extends Node$1>(editor: Editor$1, options?: {
170
- at?: Location;
171
- match?: NodeMatch<T>;
172
- mode?: RangeMode;
173
- hanging?: boolean;
174
- voids?: boolean;
175
- }) => void;
176
- /**
177
- * Set new properties on the nodes at a location.
178
- */
179
- setNodes: <T extends Node$1>(editor: Editor$1, props: Partial<T>, options?: {
180
- at?: Location;
181
- match?: NodeMatch<T>;
182
- mode?: MaximizeMode;
183
- hanging?: boolean;
184
- split?: boolean;
185
- voids?: boolean;
186
- compare?: PropsCompare;
187
- merge?: PropsMerge;
188
- }) => void;
189
- /**
190
- * Split the nodes at a specific location.
191
- */
192
- splitNodes: <T extends Node$1>(editor: Editor$1, options?: {
193
- at?: Location;
194
- match?: NodeMatch<T>;
195
- mode?: RangeMode;
196
- always?: boolean;
197
- height?: number;
198
- voids?: boolean;
199
- }) => void;
200
- /**
201
- * Unset properties on the nodes at a location.
202
- */
203
- unsetNodes: <T extends Node$1>(editor: Editor$1, props: string | string[], options?: {
204
- at?: Location;
205
- match?: NodeMatch<T>;
206
- mode?: MaximizeMode;
207
- hanging?: boolean;
208
- split?: boolean;
209
- voids?: boolean;
210
- }) => void;
211
- /**
212
- * Unwrap the nodes at a location from a parent node, splitting the parent if
213
- * necessary to ensure that only the content in the range is unwrapped.
214
- */
215
- unwrapNodes: <T extends Node$1>(editor: Editor$1, options?: {
216
- at?: Location;
217
- match?: NodeMatch<T>;
218
- mode?: MaximizeMode;
219
- split?: boolean;
220
- voids?: boolean;
221
- }) => void;
222
- /**
223
- * Wrap the nodes at a location in a new container node, splitting the edges
224
- * of the range first to ensure that only the content in the range is wrapped.
225
- */
226
- wrapNodes: <T extends Node$1>(editor: Editor$1, element: Element$1, options?: {
227
- at?: Location;
228
- match?: NodeMatch<T>;
229
- mode?: MaximizeMode;
230
- split?: boolean;
231
- voids?: boolean;
232
- }) => void;
233
- }
234
- declare const NodeTransforms: NodeTransforms;
235
- interface TextDeleteOptions {
236
- at?: Location;
237
- distance?: number;
238
- unit?: TextUnit;
239
- reverse?: boolean;
240
- hanging?: boolean;
241
- voids?: boolean;
242
- }
243
- interface TextInsertFragmentOptions {
244
- at?: Location;
245
- hanging?: boolean;
246
- voids?: boolean;
247
- batchDirty?: boolean;
248
- }
249
- interface TextInsertTextOptions {
250
- at?: Location;
251
- voids?: boolean;
252
- }
253
- interface TextTransforms {
254
- /**
255
- * Delete content in the editor.
256
- */
257
- delete: (editor: Editor$1, options?: TextDeleteOptions) => void;
258
- /**
259
- * Insert a fragment in the editor
260
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
261
- */
262
- insertFragment: (editor: Editor$1, fragment: Node$1[], options?: TextInsertFragmentOptions) => void;
263
- /**
264
- * Insert a string of text in the editor
265
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
266
- */
267
- insertText: (editor: Editor$1, text: string, options?: TextInsertTextOptions) => void;
268
- }
269
- declare const TextTransforms: TextTransforms;
270
- /**
271
- * The `Editor` interface stores all the state of a Slate editor. It is extended
272
- * by plugins that wish to add their own helpers and implement new behaviors.
273
- */
274
- interface BaseEditor {
275
- children: Descendant[];
276
- selection: Selection$1;
277
- operations: Operation[];
278
- marks: EditorMarks | null;
279
- apply: (operation: Operation) => void;
280
- createSpan: () => Text$1;
281
- getDirtyPaths: (operation: Operation) => Path$1[];
282
- getFragment: () => Descendant[];
283
- isElementReadOnly: (element: Element$1) => boolean;
284
- isSelectable: (element: Element$1) => boolean;
285
- markableVoid: (element: Element$1) => boolean;
286
- normalizeNode: (entry: NodeEntry, options?: {
287
- operation?: Operation;
288
- fallbackElement?: () => Element$1;
289
- }) => void;
290
- onChange: (options?: {
291
- operation?: Operation;
292
- }) => void;
293
- shouldNormalize: ({
294
- iteration,
295
- dirtyPaths,
296
- operation
297
- }: {
298
- iteration: number;
299
- initialDirtyPathsLength: number;
300
- dirtyPaths: Path$1[];
301
- operation?: Operation;
302
- }) => boolean;
303
- addMark: OmitFirstArg<typeof Editor$1.addMark>;
304
- collapse: OmitFirstArg<typeof Transforms.collapse>;
305
- delete: OmitFirstArg<typeof Transforms.delete>;
306
- deleteBackward: (unit: TextUnit) => void;
307
- deleteForward: (unit: TextUnit) => void;
308
- deleteFragment: OmitFirstArg<typeof Editor$1.deleteFragment>;
309
- deselect: OmitFirstArg<typeof Transforms.deselect>;
310
- insertBreak: OmitFirstArg<typeof Editor$1.insertBreak>;
311
- insertFragment: OmitFirstArg<typeof Transforms.insertFragment>;
312
- insertNode: OmitFirstArg<typeof Editor$1.insertNode>;
313
- insertNodes: OmitFirstArg<typeof Transforms.insertNodes>;
314
- insertSoftBreak: OmitFirstArg<typeof Editor$1.insertSoftBreak>;
315
- insertText: OmitFirstArg<typeof Transforms.insertText>;
316
- liftNodes: OmitFirstArg<typeof Transforms.liftNodes>;
317
- mergeNodes: OmitFirstArg<typeof Transforms.mergeNodes>;
318
- move: OmitFirstArg<typeof Transforms.move>;
319
- moveNodes: OmitFirstArg<typeof Transforms.moveNodes>;
320
- normalize: OmitFirstArg<typeof Editor$1.normalize>;
321
- removeMark: OmitFirstArg<typeof Editor$1.removeMark>;
322
- removeNodes: OmitFirstArg<typeof Transforms.removeNodes>;
323
- select: OmitFirstArg<typeof Transforms.select>;
324
- setNodes: <T extends Node$1>(props: Partial<T>, options?: {
325
- at?: Location;
326
- match?: NodeMatch<T>;
327
- mode?: MaximizeMode;
328
- hanging?: boolean;
329
- split?: boolean;
330
- voids?: boolean;
331
- compare?: PropsCompare;
332
- merge?: PropsMerge;
333
- }) => void;
334
- setNormalizing: OmitFirstArg<typeof Editor$1.setNormalizing>;
335
- setPoint: OmitFirstArg<typeof Transforms.setPoint>;
336
- setSelection: OmitFirstArg<typeof Transforms.setSelection>;
337
- splitNodes: OmitFirstArg<typeof Transforms.splitNodes>;
338
- unsetNodes: OmitFirstArg<typeof Transforms.unsetNodes>;
339
- unwrapNodes: OmitFirstArg<typeof Transforms.unwrapNodes>;
340
- withoutNormalizing: OmitFirstArg<typeof Editor$1.withoutNormalizing>;
341
- wrapNodes: OmitFirstArg<typeof Transforms.wrapNodes>;
342
- above: <T extends Ancestor>(options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;
343
- after: OmitFirstArg<typeof Editor$1.after>;
344
- before: OmitFirstArg<typeof Editor$1.before>;
345
- edges: OmitFirstArg<typeof Editor$1.edges>;
346
- elementReadOnly: OmitFirstArg<typeof Editor$1.elementReadOnly>;
347
- end: OmitFirstArg<typeof Editor$1.end>;
348
- first: OmitFirstArg<typeof Editor$1.first>;
349
- fragment: OmitFirstArg<typeof Editor$1.fragment>;
350
- getMarks: OmitFirstArg<typeof Editor$1.marks>;
351
- hasBlocks: OmitFirstArg<typeof Editor$1.hasBlocks>;
352
- hasInlines: OmitFirstArg<typeof Editor$1.hasInlines>;
353
- hasPath: OmitFirstArg<typeof Editor$1.hasPath>;
354
- hasTexts: OmitFirstArg<typeof Editor$1.hasTexts>;
355
- isBlock: OmitFirstArg<typeof Editor$1.isBlock>;
356
- isEdge: OmitFirstArg<typeof Editor$1.isEdge>;
357
- isEmpty: OmitFirstArg<typeof Editor$1.isEmpty>;
358
- isEnd: OmitFirstArg<typeof Editor$1.isEnd>;
359
- isInline: OmitFirstArg<typeof Editor$1.isInline>;
360
- isNormalizing: OmitFirstArg<typeof Editor$1.isNormalizing>;
361
- isStart: OmitFirstArg<typeof Editor$1.isStart>;
362
- isVoid: OmitFirstArg<typeof Editor$1.isVoid>;
363
- last: OmitFirstArg<typeof Editor$1.last>;
364
- leaf: OmitFirstArg<typeof Editor$1.leaf>;
365
- levels: <T extends Node$1>(options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
366
- next: <T extends Descendant>(options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;
367
- node: OmitFirstArg<typeof Editor$1.node>;
368
- nodes: <T extends Node$1>(options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
369
- parent: OmitFirstArg<typeof Editor$1.parent>;
370
- path: OmitFirstArg<typeof Editor$1.path>;
371
- pathRef: OmitFirstArg<typeof Editor$1.pathRef>;
372
- pathRefs: OmitFirstArg<typeof Editor$1.pathRefs>;
373
- point: OmitFirstArg<typeof Editor$1.point>;
374
- pointRef: OmitFirstArg<typeof Editor$1.pointRef>;
375
- pointRefs: OmitFirstArg<typeof Editor$1.pointRefs>;
376
- positions: OmitFirstArg<typeof Editor$1.positions>;
377
- previous: <T extends Node$1>(options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;
378
- range: OmitFirstArg<typeof Editor$1.range>;
379
- rangeRef: OmitFirstArg<typeof Editor$1.rangeRef>;
380
- rangeRefs: OmitFirstArg<typeof Editor$1.rangeRefs>;
381
- start: OmitFirstArg<typeof Editor$1.start>;
382
- string: OmitFirstArg<typeof Editor$1.string>;
383
- unhangRange: OmitFirstArg<typeof Editor$1.unhangRange>;
384
- void: OmitFirstArg<typeof Editor$1.void>;
385
- shouldMergeNodesRemovePrevNode: OmitFirstArg<typeof Editor$1.shouldMergeNodesRemovePrevNode>;
386
- }
387
- type Editor$1 = ExtendedType<'Editor', BaseEditor>;
388
- type BaseSelection = Range | null;
389
- type Selection$1 = ExtendedType<'Selection', BaseSelection>;
390
- type EditorMarks = Omit<Text$1, 'text'>;
391
- interface EditorAboveOptions<T extends Ancestor> {
392
- at?: Location;
393
- match?: NodeMatch<T>;
394
- mode?: MaximizeMode;
395
- voids?: boolean;
396
- }
397
- interface EditorAfterOptions {
398
- distance?: number;
399
- unit?: TextUnitAdjustment;
400
- voids?: boolean;
401
- }
402
- interface EditorBeforeOptions {
403
- distance?: number;
404
- unit?: TextUnitAdjustment;
405
- voids?: boolean;
406
- }
407
- interface EditorDirectedDeletionOptions {
408
- unit?: TextUnit;
409
- }
410
- interface EditorElementReadOnlyOptions {
411
- at?: Location;
412
- mode?: MaximizeMode;
413
- voids?: boolean;
414
- }
415
- interface EditorFragmentDeletionOptions {
416
- direction?: TextDirection;
417
- }
418
- interface EditorIsEditorOptions {
419
- deep?: boolean;
420
- }
421
- interface EditorLeafOptions {
422
- depth?: number;
423
- edge?: LeafEdge;
424
- }
425
- interface EditorLevelsOptions<T extends Node$1> {
426
- at?: Location;
427
- match?: NodeMatch<T>;
428
- reverse?: boolean;
429
- voids?: boolean;
430
- }
431
- interface EditorNextOptions<T extends Descendant> {
432
- at?: Location;
433
- match?: NodeMatch<T>;
434
- mode?: SelectionMode;
435
- voids?: boolean;
436
- }
437
- interface EditorNodeOptions {
438
- depth?: number;
439
- edge?: LeafEdge;
440
- }
441
- interface EditorNodesOptions<T extends Node$1> {
442
- at?: Location | Span;
443
- match?: NodeMatch<T>;
444
- mode?: SelectionMode;
445
- universal?: boolean;
446
- reverse?: boolean;
447
- voids?: boolean;
448
- pass?: (entry: NodeEntry) => boolean;
449
- }
450
- interface EditorNormalizeOptions {
451
- force?: boolean;
452
- operation?: Operation;
453
- }
454
- interface EditorParentOptions {
455
- depth?: number;
456
- edge?: LeafEdge;
457
- }
458
- interface EditorPathOptions {
459
- depth?: number;
460
- edge?: LeafEdge;
461
- }
462
- interface EditorPathRefOptions {
463
- affinity?: TextDirection | null;
464
- }
465
- interface EditorPointOptions {
466
- edge?: LeafEdge;
467
- }
468
- interface EditorPointRefOptions {
469
- affinity?: TextDirection | null;
470
- }
471
- interface EditorPositionsOptions {
472
- at?: Location;
473
- unit?: TextUnitAdjustment;
474
- reverse?: boolean;
475
- voids?: boolean;
476
- }
477
- interface EditorPreviousOptions<T extends Node$1> {
478
- at?: Location;
479
- match?: NodeMatch<T>;
480
- mode?: SelectionMode;
481
- voids?: boolean;
482
- }
483
- interface EditorRangeRefOptions {
484
- affinity?: RangeDirection | null;
485
- }
486
- interface EditorStringOptions {
487
- voids?: boolean;
488
- }
489
- interface EditorUnhangRangeOptions {
490
- voids?: boolean;
491
- }
492
- interface EditorVoidOptions {
493
- at?: Location;
494
- mode?: MaximizeMode;
495
- voids?: boolean;
496
- }
497
- interface EditorInterface {
498
- /**
499
- * Get the ancestor above a location in the document.
500
- */
501
- above: <T extends Ancestor>(editor: Editor$1, options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;
502
- /**
503
- * Add a custom property to the leaf text nodes in the current selection.
504
- *
505
- * If the selection is currently collapsed, the marks will be added to the
506
- * `editor.marks` property instead, and applied when text is inserted next.
507
- */
508
- addMark: (editor: Editor$1, key: string, value: any) => void;
509
- /**
510
- * Get the point after a location.
511
- */
512
- after: (editor: Editor$1, at: Location, options?: EditorAfterOptions) => Point | undefined;
513
- /**
514
- * Get the point before a location.
515
- */
516
- before: (editor: Editor$1, at: Location, options?: EditorBeforeOptions) => Point | undefined;
517
- /**
518
- * Delete content in the editor backward from the current selection.
519
- */
520
- deleteBackward: (editor: Editor$1, options?: EditorDirectedDeletionOptions) => void;
521
- /**
522
- * Delete content in the editor forward from the current selection.
523
- */
524
- deleteForward: (editor: Editor$1, options?: EditorDirectedDeletionOptions) => void;
525
- /**
526
- * Delete the content in the current selection.
527
- */
528
- deleteFragment: (editor: Editor$1, options?: EditorFragmentDeletionOptions) => void;
529
- /**
530
- * Get the start and end points of a location.
531
- */
532
- edges: (editor: Editor$1, at: Location) => [Point, Point];
533
- /**
534
- * Match a read-only element in the current branch of the editor.
535
- */
536
- elementReadOnly: (editor: Editor$1, options?: EditorElementReadOnlyOptions) => NodeEntry<Element$1> | undefined;
537
- /**
538
- * Get the end point of a location.
539
- */
540
- end: (editor: Editor$1, at: Location) => Point;
541
- /**
542
- * Get the first node at a location.
543
- */
544
- first: (editor: Editor$1, at: Location) => NodeEntry;
545
- /**
546
- * Get the fragment at a location.
547
- */
548
- fragment: (editor: Editor$1, at: Location) => Descendant[];
549
- /**
550
- * Check if a node has block children.
551
- */
552
- hasBlocks: (editor: Editor$1, element: Element$1) => boolean;
553
- /**
554
- * Check if a node has inline and text children.
555
- */
556
- hasInlines: (editor: Editor$1, element: Element$1) => boolean;
557
- hasPath: (editor: Editor$1, path: Path$1) => boolean;
558
- /**
559
- * Check if a node has text children.
560
- */
561
- hasTexts: (editor: Editor$1, element: Element$1) => boolean;
562
- /**
563
- * Insert a block break at the current selection.
564
- *
565
- * If the selection is currently expanded, it will be deleted first.
566
- */
567
- insertBreak: (editor: Editor$1) => void;
568
- /**
569
- * Inserts a fragment
570
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
571
- */
572
- insertFragment: (editor: Editor$1, fragment: Node$1[], options?: TextInsertFragmentOptions) => void;
573
- /**
574
- * Atomically inserts `nodes`
575
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
576
- */
577
- insertNode: <T extends Node$1>(editor: Editor$1, node: Node$1, options?: NodeInsertNodesOptions<T>) => void;
578
- /**
579
- * Insert a soft break at the current selection.
580
- *
581
- * If the selection is currently expanded, it will be deleted first.
582
- */
583
- insertSoftBreak: (editor: Editor$1) => void;
584
- /**
585
- * Insert a string of text
586
- * at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
587
- */
588
- insertText: (editor: Editor$1, text: string, options?: TextInsertTextOptions) => void;
589
- /**
590
- * Check if a value is a block `Element` object.
591
- */
592
- isBlock: (editor: Editor$1, value: Element$1) => boolean;
593
- /**
594
- * Check if a point is an edge of a location.
595
- */
596
- isEdge: (editor: Editor$1, point: Point, at: Location) => boolean;
597
- /**
598
- * Check if a value is an `Editor` object.
599
- */
600
- isEditor: (value: any, options?: EditorIsEditorOptions) => value is Editor$1;
601
- /**
602
- * Check if a value is a read-only `Element` object.
603
- */
604
- isElementReadOnly: (editor: Editor$1, element: Element$1) => boolean;
605
- /**
606
- * Check if an element is empty, accounting for void nodes.
607
- */
608
- isEmpty: (editor: Editor$1, element: Element$1) => boolean;
609
- /**
610
- * Check if a point is the end point of a location.
611
- */
612
- isEnd: (editor: Editor$1, point: Point, at: Location) => boolean;
613
- /**
614
- * Check if a value is an inline `Element` object.
615
- */
616
- isInline: (editor: Editor$1, value: Element$1) => boolean;
617
- /**
618
- * Check if the editor is currently normalizing after each operation.
619
- */
620
- isNormalizing: (editor: Editor$1) => boolean;
621
- /**
622
- * Check if a value is a selectable `Element` object.
623
- */
624
- isSelectable: (editor: Editor$1, element: Element$1) => boolean;
625
- /**
626
- * Check if a point is the start point of a location.
627
- */
628
- isStart: (editor: Editor$1, point: Point, at: Location) => boolean;
629
- /**
630
- * Check if a value is a void `Element` object.
631
- */
632
- isVoid: (editor: Editor$1, value: Element$1) => boolean;
633
- /**
634
- * Get the last node at a location.
635
- */
636
- last: (editor: Editor$1, at: Location) => NodeEntry;
637
- /**
638
- * Get the leaf text node at a location.
639
- */
640
- leaf: (editor: Editor$1, at: Location, options?: EditorLeafOptions) => NodeEntry<Text$1>;
641
- /**
642
- * Iterate through all of the levels at a location.
643
- */
644
- levels: <T extends Node$1>(editor: Editor$1, options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
645
- /**
646
- * Get the marks that would be added to text at the current selection.
647
- */
648
- marks: (editor: Editor$1) => Omit<Text$1, 'text'> | null;
649
- /**
650
- * Get the matching node in the branch of the document after a location.
651
- */
652
- next: <T extends Descendant>(editor: Editor$1, options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;
653
- /**
654
- * Get the node at a location.
655
- */
656
- node: (editor: Editor$1, at: Location, options?: EditorNodeOptions) => NodeEntry;
657
- /**
658
- * Iterate through all of the nodes in the Editor.
659
- */
660
- nodes: <T extends Node$1>(editor: Editor$1, options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
661
- /**
662
- * Normalize any dirty objects in the editor.
663
- */
664
- normalize: (editor: Editor$1, options?: EditorNormalizeOptions) => void;
665
- /**
666
- * Get the parent node of a location.
667
- */
668
- parent: (editor: Editor$1, at: Location, options?: EditorParentOptions) => NodeEntry<Ancestor>;
669
- /**
670
- * Get the path of a location.
671
- */
672
- path: (editor: Editor$1, at: Location, options?: EditorPathOptions) => Path$1;
673
- /**
674
- * Create a mutable ref for a `Path` object, which will stay in sync as new
675
- * operations are applied to the editor.
676
- */
677
- pathRef: (editor: Editor$1, path: Path$1, options?: EditorPathRefOptions) => PathRef;
678
- /**
679
- * Get the set of currently tracked path refs of the editor.
680
- */
681
- pathRefs: (editor: Editor$1) => Set<PathRef>;
682
- /**
683
- * Get the start or end point of a location.
684
- */
685
- point: (editor: Editor$1, at: Location, options?: EditorPointOptions) => Point;
686
- /**
687
- * Create a mutable ref for a `Point` object, which will stay in sync as new
688
- * operations are applied to the editor.
689
- */
690
- pointRef: (editor: Editor$1, point: Point, options?: EditorPointRefOptions) => PointRef;
691
- /**
692
- * Get the set of currently tracked point refs of the editor.
693
- */
694
- pointRefs: (editor: Editor$1) => Set<PointRef>;
695
- /**
696
- * Return all the positions in `at` range where a `Point` can be placed.
697
- *
698
- * By default, moves forward by individual offsets at a time, but
699
- * the `unit` option can be used to to move by character, word, line, or block.
700
- *
701
- * The `reverse` option can be used to change iteration direction.
702
- *
703
- * Note: By default void nodes are treated as a single point and iteration
704
- * will not happen inside their content unless you pass in true for the
705
- * `voids` option, then iteration will occur.
706
- */
707
- positions: (editor: Editor$1, options?: EditorPositionsOptions) => Generator<Point, void, undefined>;
708
- /**
709
- * Get the matching node in the branch of the document before a location.
710
- */
711
- previous: <T extends Node$1>(editor: Editor$1, options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;
712
- /**
713
- * Get a range of a location.
714
- */
715
- range: (editor: Editor$1, at: Location, to?: Location) => Range;
716
- /**
717
- * Create a mutable ref for a `Range` object, which will stay in sync as new
718
- * operations are applied to the editor.
719
- */
720
- rangeRef: (editor: Editor$1, range: Range, options?: EditorRangeRefOptions) => RangeRef;
721
- /**
722
- * Get the set of currently tracked range refs of the editor.
723
- */
724
- rangeRefs: (editor: Editor$1) => Set<RangeRef>;
725
- /**
726
- * Remove a custom property from all of the leaf text nodes in the current
727
- * selection.
728
- *
729
- * If the selection is currently collapsed, the removal will be stored on
730
- * `editor.marks` and applied to the text inserted next.
731
- */
732
- removeMark: (editor: Editor$1, key: string) => void;
733
- /**
734
- * Manually set if the editor should currently be normalizing.
735
- *
736
- * Note: Using this incorrectly can leave the editor in an invalid state.
737
- *
738
- */
739
- setNormalizing: (editor: Editor$1, isNormalizing: boolean) => void;
740
- /**
741
- * Get the start point of a location.
742
- */
743
- start: (editor: Editor$1, at: Location) => Point;
744
- /**
745
- * Get the text string content of a location.
746
- *
747
- * Note: by default the text of void nodes is considered to be an empty
748
- * string, regardless of content, unless you pass in true for the voids option
749
- */
750
- string: (editor: Editor$1, at: Location, options?: EditorStringOptions) => string;
751
- /**
752
- * Convert a range into a non-hanging one.
753
- */
754
- unhangRange: (editor: Editor$1, range: Range, options?: EditorUnhangRangeOptions) => Range;
755
- /**
756
- * Match a void node in the current branch of the editor.
757
- */
758
- void: (editor: Editor$1, options?: EditorVoidOptions) => NodeEntry<Element$1> | undefined;
759
- /**
760
- * Call a function, deferring normalization until after it completes.
761
- */
762
- withoutNormalizing: (editor: Editor$1, fn: () => void) => void;
763
- /**
764
- * Call a function, Determine whether or not remove the previous node when merge.
765
- */
766
- shouldMergeNodesRemovePrevNode: (editor: Editor$1, prevNodeEntry: NodeEntry, curNodeEntry: NodeEntry) => boolean;
767
- }
768
- declare const Editor$1: EditorInterface;
769
- /**
770
- * A helper type for narrowing matched nodes with a predicate.
771
- */
772
- type NodeMatch<T extends Node$1> = ((node: Node$1, path: Path$1) => node is T) | ((node: Node$1, path: Path$1) => boolean);
773
- type PropsCompare = (prop: Partial<Node$1>, node: Partial<Node$1>) => boolean;
774
- type PropsMerge = (prop: Partial<Node$1>, node: Partial<Node$1>) => object;
775
109
  /**
776
- * `Element` objects are a type of node in a Slate document that contain other
777
- * element nodes or text nodes. They can be either "blocks" or "inlines"
778
- * depending on the Slate editor's configuration.
110
+ * @public
779
111
  */
780
- interface BaseElement {
781
- children: Descendant[];
782
- }
783
- type Element$1 = ExtendedType<'Element', BaseElement>;
784
- interface ElementIsElementOptions {
785
- deep?: boolean;
786
- }
787
- interface ElementInterface {
788
- /**
789
- * Check if a value implements the 'Ancestor' interface.
790
- */
791
- isAncestor: (value: any, options?: ElementIsElementOptions) => value is Ancestor;
792
- /**
793
- * Check if a value implements the `Element` interface.
794
- */
795
- isElement: (value: any, options?: ElementIsElementOptions) => value is Element$1;
796
- /**
797
- * Check if a value is an array of `Element` objects.
798
- */
799
- isElementList: (value: any, options?: ElementIsElementOptions) => value is Element$1[];
800
- /**
801
- * Check if a set of props is a partial of Element.
802
- */
803
- isElementProps: (props: any) => props is Partial<Element$1>;
804
- /**
805
- * Check if a value implements the `Element` interface and has elementKey with selected value.
806
- * Default it check to `type` key value
807
- */
808
- isElementType: <T extends Element$1>(value: any, elementVal: string, elementKey?: string) => value is T;
809
- /**
810
- * Check if an element matches set of properties.
811
- *
812
- * Note: this checks custom properties, and it does not ensure that any
813
- * children are equivalent.
814
- */
815
- matches: (element: Element$1, props: Partial<Element$1>) => boolean;
816
- }
817
- declare const Element$1: ElementInterface;
112
+ type EditorSchema = Schema;
818
113
  /**
819
- * `ElementEntry` objects refer to an `Element` and the `Path` where it can be
820
- * found inside a root node.
114
+ * `Path` arrays are a list of indexes that describe a node's exact position in
115
+ * a Slate node tree. Although they are usually relative to the root `Editor`
116
+ * object, they can be relative to any `Node` object.
821
117
  */
822
- type ElementEntry = [Element$1, Path$1];
118
+ type Path$1 = number[];
119
+ type Node$1 = PortableTextTextBlock | PortableTextObject | PortableTextSpan;
120
+ type TextDirection = 'forward' | 'backward';
823
121
  /**
824
- * The `Location` interface is a union of the ways to refer to a specific
825
- * location in a Slate document: paths, points or ranges.
826
- *
827
- * Methods will often accept a `Location` instead of requiring only a `Path`,
828
- * `Point` or `Range`. This eliminates the need for developers to manage
829
- * converting between the different interfaces in their own code base.
122
+ * `Point` objects refer to a specific location in a text node in a Slate
123
+ * document. Its path refers to the location of the node in the tree, and its
124
+ * offset refers to the distance into the node's string of text. Points can
125
+ * only refer to `Text` nodes.
830
126
  */
831
- type Location = Path$1 | Point | Range;
832
- interface LocationInterface {
833
- /**
834
- * Check if a value implements the `Location` interface.
835
- */
836
- isLocation: (value: any) => value is Location;
127
+ interface Point {
128
+ path: number[];
129
+ offset: number;
837
130
  }
838
- declare const Location: LocationInterface;
839
131
  /**
840
- * The `Span` interface is a low-level way to refer to locations in nodes
841
- * without using `Point` which requires leaf text nodes to be present.
132
+ * `Range` objects are a set of points that refer to a specific span of a Slate
133
+ * document. They can define a span inside a single node or a can span across
134
+ * multiple nodes.
842
135
  */
843
- type Span = [Path$1, Path$1];
844
- interface SpanInterface {
845
- /**
846
- * Check if a value implements the `Span` interface.
847
- */
848
- isSpan: (value: any) => value is Span;
849
- }
850
- declare const Span: SpanInterface;
851
- type Node$1 = Editor$1 | Element$1 | Text$1;
852
- interface NodeAncestorsOptions {
853
- reverse?: boolean;
854
- }
855
- interface NodeChildrenOptions {
856
- reverse?: boolean;
857
- }
858
- interface NodeDescendantsOptions {
859
- from?: Path$1;
860
- to?: Path$1;
861
- reverse?: boolean;
862
- pass?: (node: NodeEntry) => boolean;
863
- }
864
- interface NodeElementsOptions {
865
- from?: Path$1;
866
- to?: Path$1;
867
- reverse?: boolean;
868
- pass?: (node: NodeEntry) => boolean;
869
- }
870
- interface NodeIsNodeOptions {
871
- deep?: boolean;
872
- }
873
- interface NodeLevelsOptions {
874
- reverse?: boolean;
875
- }
876
- interface NodeNodesOptions {
877
- from?: Path$1;
878
- to?: Path$1;
879
- reverse?: boolean;
880
- pass?: (entry: NodeEntry) => boolean;
881
- }
882
- interface NodeTextsOptions {
883
- from?: Path$1;
884
- to?: Path$1;
885
- reverse?: boolean;
886
- pass?: (node: NodeEntry) => boolean;
887
- }
888
- interface NodeInterface {
889
- /**
890
- * Get the node at a specific path, asserting that it's an ancestor node.
891
- */
892
- ancestor: (root: Node$1, path: Path$1) => Ancestor;
893
- /**
894
- * Return a generator of all the ancestor nodes above a specific path.
895
- *
896
- * By default the order is top-down, from highest to lowest ancestor in
897
- * the tree, but you can pass the `reverse: true` option to go bottom-up.
898
- */
899
- ancestors: (root: Node$1, path: Path$1, options?: NodeAncestorsOptions) => Generator<NodeEntry<Ancestor>, void, undefined>;
900
- /**
901
- * Get the child of a node at a specific index.
902
- */
903
- child: (root: Node$1, index: number) => Descendant;
904
- /**
905
- * Iterate over the children of a node at a specific path.
906
- */
907
- children: (root: Node$1, path: Path$1, options?: NodeChildrenOptions) => Generator<NodeEntry<Descendant>, void, undefined>;
908
- /**
909
- * Get an entry for the common ancesetor node of two paths.
910
- */
911
- common: (root: Node$1, path: Path$1, another: Path$1) => NodeEntry;
912
- /**
913
- * Get the node at a specific path, asserting that it's a descendant node.
914
- */
915
- descendant: (root: Node$1, path: Path$1) => Descendant;
916
- /**
917
- * Return a generator of all the descendant node entries inside a root node.
918
- */
919
- descendants: (root: Node$1, options?: NodeDescendantsOptions) => Generator<NodeEntry<Descendant>, void, undefined>;
920
- /**
921
- * Return a generator of all the element nodes inside a root node. Each iteration
922
- * will return an `ElementEntry` tuple consisting of `[Element, Path]`. If the
923
- * root node is an element it will be included in the iteration as well.
924
- */
925
- elements: (root: Node$1, options?: NodeElementsOptions) => Generator<ElementEntry, void, undefined>;
926
- /**
927
- * Extract props from a Node.
928
- */
929
- extractProps: (node: Node$1) => NodeProps;
930
- /**
931
- * Get the first leaf node entry in a root node from a path.
932
- */
933
- first: (root: Node$1, path: Path$1) => NodeEntry;
934
- /**
935
- * Get the sliced fragment represented by a range inside a root node.
936
- */
937
- fragment: <T extends Ancestor = Editor$1>(root: T, range: Range) => T['children'];
938
- /**
939
- * Get the descendant node referred to by a specific path. If the path is an
940
- * empty array, it refers to the root node itself.
941
- */
942
- get: (root: Node$1, path: Path$1) => Node$1;
943
- /**
944
- * Similar to get, but returns undefined if the node does not exist.
945
- */
946
- getIf: (root: Node$1, path: Path$1) => Node$1 | undefined;
947
- /**
948
- * Check if a descendant node exists at a specific path.
949
- */
950
- has: (root: Node$1, path: Path$1) => boolean;
951
- /**
952
- * Check if a value implements the `Node` interface.
953
- */
954
- isNode: (value: any, options?: NodeIsNodeOptions) => value is Node$1;
955
- /**
956
- * Check if a value is a list of `Node` objects.
957
- */
958
- isNodeList: (value: any, options?: NodeIsNodeOptions) => value is Node$1[];
959
- /**
960
- * Get the last leaf node entry in a root node from a path.
961
- */
962
- last: (root: Node$1, path: Path$1) => NodeEntry;
963
- /**
964
- * Get the node at a specific path, ensuring it's a leaf text node.
965
- */
966
- leaf: (root: Node$1, path: Path$1) => Text$1;
967
- /**
968
- * Return a generator of the in a branch of the tree, from a specific path.
969
- *
970
- * By default the order is top-down, from highest to lowest node in the tree,
971
- * but you can pass the `reverse: true` option to go bottom-up.
972
- */
973
- levels: (root: Node$1, path: Path$1, options?: NodeLevelsOptions) => Generator<NodeEntry, void, undefined>;
974
- /**
975
- * Check if a node matches a set of props.
976
- */
977
- matches: (node: Node$1, props: Partial<Node$1>) => boolean;
978
- /**
979
- * Return a generator of all the node entries of a root node. Each entry is
980
- * returned as a `[Node, Path]` tuple, with the path referring to the node's
981
- * position inside the root node.
982
- */
983
- nodes: (root: Node$1, options?: NodeNodesOptions) => Generator<NodeEntry, void, undefined>;
984
- /**
985
- * Get the parent of a node at a specific path.
986
- */
987
- parent: (root: Node$1, path: Path$1) => Ancestor;
988
- /**
989
- * Get the concatenated text string of a node's content.
990
- *
991
- * Note that this will not include spaces or line breaks between block nodes.
992
- * It is not a user-facing string, but a string for performing offset-related
993
- * computations for a node.
994
- */
995
- string: (node: Node$1) => string;
996
- /**
997
- * Return a generator of all leaf text nodes in a root node.
998
- */
999
- texts: (root: Node$1, options?: NodeTextsOptions) => Generator<NodeEntry<Text$1>, void, undefined>;
136
+ interface Range {
137
+ anchor: Point;
138
+ focus: Point;
1000
139
  }
1001
- declare const Node$1: NodeInterface;
1002
- /**
1003
- * The `Descendant` union type represents nodes that are descendants in the
1004
- * tree. It is returned as a convenience in certain cases to narrow a value
1005
- * further than the more generic `Node` union.
1006
- */
1007
- type Descendant = Element$1 | Text$1;
1008
- /**
1009
- * The `Ancestor` union type represents nodes that are ancestors in the tree.
1010
- * It is returned as a convenience in certain cases to narrow a value further
1011
- * than the more generic `Node` union.
1012
- */
1013
- type Ancestor = Editor$1 | Element$1;
1014
- /**
1015
- * `NodeEntry` objects are returned when iterating over the nodes in a Slate
1016
- * document tree. They consist of the node and its `Path` relative to the root
1017
- * node in the document.
1018
- */
1019
- type NodeEntry<T extends Node$1 = Node$1> = [T, Path$1];
1020
- /**
1021
- * Convenience type for returning the props of a node.
1022
- */
1023
- type NodeProps = Omit<Editor$1, 'children'> | Omit<Element$1, 'children'> | Omit<Text$1, 'text'>;
1024
- type BaseInsertNodeOperation = {
140
+ type InsertNodeOperation = {
1025
141
  type: 'insert_node';
1026
142
  path: Path$1;
1027
143
  node: Node$1;
1028
144
  };
1029
- type InsertNodeOperation = ExtendedType<'InsertNodeOperation', BaseInsertNodeOperation>;
1030
- type BaseInsertTextOperation = {
145
+ type InsertTextOperation = {
1031
146
  type: 'insert_text';
1032
147
  path: Path$1;
1033
148
  offset: number;
1034
149
  text: string;
1035
150
  };
1036
- type InsertTextOperation = ExtendedType<'InsertTextOperation', BaseInsertTextOperation>;
1037
- type BaseMergeNodeOperation = {
1038
- type: 'merge_node';
1039
- path: Path$1;
1040
- position: number;
1041
- properties: Partial<Node$1>;
1042
- };
1043
- type MergeNodeOperation = ExtendedType<'MergeNodeOperation', BaseMergeNodeOperation>;
1044
- type BaseMoveNodeOperation = {
1045
- type: 'move_node';
1046
- path: Path$1;
1047
- newPath: Path$1;
1048
- };
1049
- type MoveNodeOperation = ExtendedType<'MoveNodeOperation', BaseMoveNodeOperation>;
1050
- type BaseRemoveNodeOperation = {
151
+ type RemoveNodeOperation = {
1051
152
  type: 'remove_node';
1052
153
  path: Path$1;
1053
154
  node: Node$1;
1054
155
  };
1055
- type RemoveNodeOperation = ExtendedType<'RemoveNodeOperation', BaseRemoveNodeOperation>;
1056
- type BaseRemoveTextOperation = {
156
+ type RemoveTextOperation = {
1057
157
  type: 'remove_text';
1058
158
  path: Path$1;
1059
159
  offset: number;
1060
160
  text: string;
1061
161
  };
1062
- type RemoveTextOperation = ExtendedType<'RemoveTextOperation', BaseRemoveTextOperation>;
1063
- type BaseSetNodeOperation = {
1064
- type: 'set_node';
1065
- path: Path$1;
1066
- properties: Partial<Node$1>;
1067
- newProperties: Partial<Node$1>;
1068
- };
1069
- type SetNodeOperation = ExtendedType<'SetNodeOperation', BaseSetNodeOperation>;
1070
- type BaseSetSelectionOperation = {
1071
- type: 'set_selection';
1072
- properties: null;
1073
- newProperties: Range;
1074
- } | {
1075
- type: 'set_selection';
1076
- properties: Partial<Range>;
1077
- newProperties: Partial<Range>;
1078
- } | {
1079
- type: 'set_selection';
1080
- properties: Range;
1081
- newProperties: null;
1082
- };
1083
- type SetSelectionOperation = ExtendedType<'SetSelectionOperation', BaseSetSelectionOperation>;
1084
- type BaseSplitNodeOperation = {
1085
- type: 'split_node';
1086
- path: Path$1;
1087
- position: number;
1088
- properties: Partial<Node$1>;
1089
- };
1090
- type SplitNodeOperation = ExtendedType<'SplitNodeOperation', BaseSplitNodeOperation>;
1091
- type NodeOperation = InsertNodeOperation | MergeNodeOperation | MoveNodeOperation | RemoveNodeOperation | SetNodeOperation | SplitNodeOperation;
1092
- type SelectionOperation = SetSelectionOperation;
1093
- type TextOperation = InsertTextOperation | RemoveTextOperation;
1094
- /**
1095
- * `Operation` objects define the low-level instructions that Slate editors use
1096
- * to apply changes to their internal state. Representing all changes as
1097
- * operations is what allows Slate editors to easily implement history,
1098
- * collaboration, and other features.
1099
- */
1100
- type BaseOperation = NodeOperation | SelectionOperation | TextOperation;
1101
- type Operation = ExtendedType<'Operation', BaseOperation>;
1102
- interface OperationInterface {
1103
- /**
1104
- * Check if a value is a `NodeOperation` object.
1105
- */
1106
- isNodeOperation: (value: any) => value is NodeOperation;
1107
- /**
1108
- * Check if a value is an `Operation` object.
1109
- */
1110
- isOperation: (value: any) => value is Operation;
1111
- /**
1112
- * Check if a value is a list of `Operation` objects.
1113
- */
1114
- isOperationList: (value: any) => value is Operation[];
1115
- /**
1116
- * Check if a value is a `SelectionOperation` object.
1117
- */
1118
- isSelectionOperation: (value: any) => value is SelectionOperation;
1119
- /**
1120
- * Check if a value is a `TextOperation` object.
1121
- */
1122
- isTextOperation: (value: any) => value is TextOperation;
1123
- /**
1124
- * Invert an operation, returning a new operation that will exactly undo the
1125
- * original when applied.
1126
- */
1127
- inverse: (op: Operation) => Operation;
1128
- }
1129
- declare const Operation: OperationInterface;
1130
- /**
1131
- * `PathRef` objects keep a specific path in a document synced over time as new
1132
- * operations are applied to the editor. You can access their `current` property
1133
- * at any time for the up-to-date path value.
1134
- */
1135
- interface PathRef {
1136
- current: Path$1 | null;
1137
- affinity: 'forward' | 'backward' | null;
1138
- unref(): Path$1 | null;
1139
- }
1140
- interface PathRefInterface {
1141
- /**
1142
- * Transform the path ref's current value by an operation.
1143
- */
1144
- transform: (ref: PathRef, op: Operation) => void;
1145
- }
1146
- declare const PathRef: PathRefInterface;
1147
- /**
1148
- * `Path` arrays are a list of indexes that describe a node's exact position in
1149
- * a Slate node tree. Although they are usually relative to the root `Editor`
1150
- * object, they can be relative to any `Node` object.
1151
- */
1152
- type Path$1 = number[];
1153
- interface PathAncestorsOptions {
1154
- reverse?: boolean;
1155
- }
1156
- interface PathLevelsOptions {
1157
- reverse?: boolean;
1158
- }
1159
- interface PathTransformOptions {
1160
- affinity?: TextDirection | null;
1161
- }
1162
- interface PathInterface {
1163
- /**
1164
- * Get a list of ancestor paths for a given path.
1165
- *
1166
- * The paths are sorted from shallowest to deepest ancestor. However, if the
1167
- * `reverse: true` option is passed, they are reversed.
1168
- */
1169
- ancestors: (path: Path$1, options?: PathAncestorsOptions) => Path$1[];
1170
- /**
1171
- * Get the common ancestor path of two paths.
1172
- */
1173
- common: (path: Path$1, another: Path$1) => Path$1;
1174
- /**
1175
- * Compare a path to another, returning an integer indicating whether the path
1176
- * was before, at, or after the other.
1177
- *
1178
- * Note: Two paths of unequal length can still receive a `0` result if one is
1179
- * directly above or below the other. If you want exact matching, use
1180
- * [[Path.equals]] instead.
1181
- */
1182
- compare: (path: Path$1, another: Path$1) => -1 | 0 | 1;
1183
- /**
1184
- * Check if a path ends after one of the indexes in another.
1185
- */
1186
- endsAfter: (path: Path$1, another: Path$1) => boolean;
1187
- /**
1188
- * Check if a path ends at one of the indexes in another.
1189
- */
1190
- endsAt: (path: Path$1, another: Path$1) => boolean;
1191
- /**
1192
- * Check if a path ends before one of the indexes in another.
1193
- */
1194
- endsBefore: (path: Path$1, another: Path$1) => boolean;
1195
- /**
1196
- * Check if a path is exactly equal to another.
1197
- */
1198
- equals: (path: Path$1, another: Path$1) => boolean;
1199
- /**
1200
- * Check if the path of previous sibling node exists
1201
- */
1202
- hasPrevious: (path: Path$1) => boolean;
1203
- /**
1204
- * Check if a path is after another.
1205
- */
1206
- isAfter: (path: Path$1, another: Path$1) => boolean;
1207
- /**
1208
- * Check if a path is an ancestor of another.
1209
- */
1210
- isAncestor: (path: Path$1, another: Path$1) => boolean;
1211
- /**
1212
- * Check if a path is before another.
1213
- */
1214
- isBefore: (path: Path$1, another: Path$1) => boolean;
1215
- /**
1216
- * Check if a path is a child of another.
1217
- */
1218
- isChild: (path: Path$1, another: Path$1) => boolean;
1219
- /**
1220
- * Check if a path is equal to or an ancestor of another.
1221
- */
1222
- isCommon: (path: Path$1, another: Path$1) => boolean;
1223
- /**
1224
- * Check if a path is a descendant of another.
1225
- */
1226
- isDescendant: (path: Path$1, another: Path$1) => boolean;
1227
- /**
1228
- * Check if a path is the parent of another.
1229
- */
1230
- isParent: (path: Path$1, another: Path$1) => boolean;
1231
- /**
1232
- * Check is a value implements the `Path` interface.
1233
- */
1234
- isPath: (value: any) => value is Path$1;
1235
- /**
1236
- * Check if a path is a sibling of another.
1237
- */
1238
- isSibling: (path: Path$1, another: Path$1) => boolean;
1239
- /**
1240
- * Get a list of paths at every level down to a path. Note: this is the same
1241
- * as `Path.ancestors`, but including the path itself.
1242
- *
1243
- * The paths are sorted from shallowest to deepest. However, if the `reverse:
1244
- * true` option is passed, they are reversed.
1245
- */
1246
- levels: (path: Path$1, options?: PathLevelsOptions) => Path$1[];
1247
- /**
1248
- * Given a path, get the path to the next sibling node.
1249
- */
1250
- next: (path: Path$1) => Path$1;
1251
- /**
1252
- * Returns whether this operation can affect paths or not. Used as an
1253
- * optimization when updating dirty paths during normalization
1254
- *
1255
- * NOTE: This *must* be kept in sync with the implementation of 'transform'
1256
- * below
1257
- */
1258
- operationCanTransformPath: (operation: Operation) => operation is InsertNodeOperation | RemoveNodeOperation | MergeNodeOperation | SplitNodeOperation | MoveNodeOperation;
1259
- /**
1260
- * Given a path, return a new path referring to the parent node above it.
1261
- */
1262
- parent: (path: Path$1) => Path$1;
1263
- /**
1264
- * Given a path, get the path to the previous sibling node.
1265
- */
1266
- previous: (path: Path$1) => Path$1;
1267
- /**
1268
- * Get a path relative to an ancestor.
1269
- */
1270
- relative: (path: Path$1, ancestor: Path$1) => Path$1;
1271
- /**
1272
- * Transform a path by an operation.
1273
- */
1274
- transform: (path: Path$1, operation: Operation, options?: PathTransformOptions) => Path$1 | null;
162
+ type SetNodeOperation = {
163
+ type: 'set_node';
164
+ path: Path$1;
165
+ properties: Partial<Node$1>;
166
+ newProperties: Partial<Node$1>;
167
+ };
168
+ type SetSelectionOperation = {
169
+ type: 'set_selection';
170
+ properties: null;
171
+ newProperties: Range;
172
+ } | {
173
+ type: 'set_selection';
174
+ properties: Partial<Range>;
175
+ newProperties: Partial<Range>;
176
+ } | {
177
+ type: 'set_selection';
178
+ properties: Range;
179
+ newProperties: null;
180
+ };
181
+ type Operation = InsertNodeOperation | RemoveNodeOperation | SetNodeOperation | SetSelectionOperation | InsertTextOperation | RemoveTextOperation;
182
+ type DecoratedRange = Range & {
183
+ rangeDecoration: RangeDecoration;
184
+ merge: (leaf: Record<string, unknown>, decoration: Record<string, unknown>) => void;
185
+ };
186
+ /**
187
+ * The `Location` interface is a union of the ways to refer to a specific
188
+ * location in a Slate document: paths, points or ranges.
189
+ *
190
+ * Methods will often accept a `Location` instead of requiring only a `Path`,
191
+ * `Point` or `Range`. This eliminates the need for developers to manage
192
+ * converting between the different interfaces in their own code base.
193
+ */
194
+ type Location = Path$1 | Point | Range;
195
+ /**
196
+ * `PathRef` objects keep a specific path in a document synced over time as new
197
+ * operations are applied to the editor. You can access their `current` property
198
+ * at any time for the up-to-date path value.
199
+ */
200
+ interface PathRef {
201
+ current: Path$1 | null;
202
+ affinity: 'forward' | 'backward' | null;
203
+ unref(): Path$1 | null;
204
+ }
205
+ interface PathRefInterface {
206
+ transform: (ref: PathRef, op: Operation) => void;
1275
207
  }
1276
- declare const Path$1: PathInterface;
208
+ declare const PathRef: PathRefInterface;
1277
209
  /**
1278
210
  * `PointRef` objects keep a specific point in a document synced over time as new
1279
211
  * operations are applied to the editor. You can access their `current` property
@@ -1285,59 +217,9 @@ interface PointRef {
1285
217
  unref(): Point | null;
1286
218
  }
1287
219
  interface PointRefInterface {
1288
- /**
1289
- * Transform the point ref's current value by an operation.
1290
- */
1291
220
  transform: (ref: PointRef, op: Operation) => void;
1292
221
  }
1293
222
  declare const PointRef: PointRefInterface;
1294
- /**
1295
- * `Point` objects refer to a specific location in a text node in a Slate
1296
- * document. Its path refers to the location of the node in the tree, and its
1297
- * offset refers to the distance into the node's string of text. Points can
1298
- * only refer to `Text` nodes.
1299
- */
1300
- interface BasePoint {
1301
- path: Path$1;
1302
- offset: number;
1303
- }
1304
- type Point = ExtendedType<'Point', BasePoint>;
1305
- interface PointTransformOptions {
1306
- affinity?: TextDirection | null;
1307
- }
1308
- interface PointInterface {
1309
- /**
1310
- * Compare a point to another, returning an integer indicating whether the
1311
- * point was before, at, or after the other.
1312
- */
1313
- compare: (point: Point, another: Point) => -1 | 0 | 1;
1314
- /**
1315
- * Check if a point is after another.
1316
- */
1317
- isAfter: (point: Point, another: Point) => boolean;
1318
- /**
1319
- * Check if a point is before another.
1320
- */
1321
- isBefore: (point: Point, another: Point) => boolean;
1322
- /**
1323
- * Check if a point is exactly equal to another.
1324
- */
1325
- equals: (point: Point, another: Point) => boolean;
1326
- /**
1327
- * Check if a value implements the `Point` interface.
1328
- */
1329
- isPoint: (value: any) => value is Point;
1330
- /**
1331
- * Transform a point by an operation.
1332
- */
1333
- transform: (point: Point, op: Operation, options?: PointTransformOptions) => Point | null;
1334
- }
1335
- declare const Point: PointInterface;
1336
- /**
1337
- * `PointEntry` objects are returned when iterating over `Point` objects that
1338
- * belong to a range.
1339
- */
1340
- type PointEntry = [Point, 'anchor' | 'focus'];
1341
223
  /**
1342
224
  * `RangeRef` objects keep a specific range in a document synced over time as new
1343
225
  * operations are applied to the editor. You can access their `current` property
@@ -1348,219 +230,46 @@ interface RangeRef {
1348
230
  affinity: 'forward' | 'backward' | 'outward' | 'inward' | null;
1349
231
  unref(): Range | null;
1350
232
  }
1351
- interface RangeRefInterface {
1352
- /**
1353
- * Transform the range ref's current value by an operation.
1354
- */
1355
- transform: (ref: RangeRef, op: Operation) => void;
1356
- }
1357
- declare const RangeRef: RangeRefInterface;
1358
- /**
1359
- * `Range` objects are a set of points that refer to a specific span of a Slate
1360
- * document. They can define a span inside a single node or a can span across
1361
- * multiple nodes.
1362
- */
1363
- interface BaseRange {
1364
- anchor: Point;
1365
- focus: Point;
1366
- }
1367
- type Range = ExtendedType<'Range', BaseRange>;
1368
- interface RangeEdgesOptions {
1369
- reverse?: boolean;
1370
- }
1371
- interface RangeTransformOptions {
1372
- affinity?: RangeDirection | null;
1373
- }
1374
- interface RangeInterface {
1375
- /**
1376
- * Get the start and end points of a range, in the order in which they appear
1377
- * in the document.
1378
- */
1379
- edges: (range: Range, options?: RangeEdgesOptions) => [Point, Point];
1380
- /**
1381
- * Get the end point of a range.
1382
- */
1383
- end: (range: Range) => Point;
1384
- /**
1385
- * Check if a range is exactly equal to another.
1386
- */
1387
- equals: (range: Range, another: Range) => boolean;
1388
- /**
1389
- * Check if a range includes a path, a point or part of another range.
1390
- */
1391
- includes: (range: Range, target: Path$1 | Point | Range) => boolean;
1392
- /**
1393
- * Check if a range includes another range.
1394
- */
1395
- surrounds: (range: Range, target: Range) => boolean;
1396
- /**
1397
- * Get the intersection of a range with another.
1398
- */
1399
- intersection: (range: Range, another: Range) => Range | null;
1400
- /**
1401
- * Check if a range is backward, meaning that its anchor point appears in the
1402
- * document _after_ its focus point.
1403
- */
1404
- isBackward: (range: Range) => boolean;
1405
- /**
1406
- * Check if a range is collapsed, meaning that both its anchor and focus
1407
- * points refer to the exact same position in the document.
1408
- */
1409
- isCollapsed: (range: Range) => boolean;
1410
- /**
1411
- * Check if a range is expanded.
1412
- *
1413
- * This is the opposite of [[Range.isCollapsed]] and is provided for legibility.
1414
- */
1415
- isExpanded: (range: Range) => boolean;
1416
- /**
1417
- * Check if a range is forward.
1418
- *
1419
- * This is the opposite of [[Range.isBackward]] and is provided for legibility.
1420
- */
1421
- isForward: (range: Range) => boolean;
1422
- /**
1423
- * Check if a value implements the [[Range]] interface.
1424
- */
1425
- isRange: (value: any) => value is Range;
1426
- /**
1427
- * Iterate through all of the point entries in a range.
1428
- */
1429
- points: (range: Range) => Generator<PointEntry, void, undefined>;
1430
- /**
1431
- * Get the start point of a range.
1432
- */
1433
- start: (range: Range) => Point;
1434
- /**
1435
- * Transform a range by an operation.
1436
- */
1437
- transform: (range: Range, op: Operation, options?: RangeTransformOptions) => Range | null;
1438
- }
1439
- declare const Range: RangeInterface;
1440
- /**
1441
- * Extendable Custom Types Interface
1442
- */
1443
- type ExtendableTypes = 'Editor' | 'Element' | 'Text' | 'Selection' | 'Range' | 'Point' | 'Operation' | 'InsertNodeOperation' | 'InsertTextOperation' | 'MergeNodeOperation' | 'MoveNodeOperation' | 'RemoveNodeOperation' | 'RemoveTextOperation' | 'SetNodeOperation' | 'SetSelectionOperation' | 'SplitNodeOperation';
1444
- interface CustomTypes {
1445
- [key: string]: unknown;
1446
- }
1447
- type ExtendedType<K$1 extends ExtendableTypes, B> = unknown extends CustomTypes[K$1] ? B : CustomTypes[K$1];
1448
233
  /**
1449
- * `Text` objects represent the nodes that contain the actual text content of a
1450
- * Slate document along with any formatting properties. They are always leaf
1451
- * nodes in the document tree as they cannot contain any children.
234
+ * The `Editor` interface stores all the state of a Slate editor. It is extended
235
+ * by plugins that wish to add their own helpers and implement new behaviors.
1452
236
  */
1453
- interface BaseText {
1454
- text: string;
1455
- }
1456
- type Text$1 = ExtendedType<'Text', BaseText>;
1457
- interface LeafPosition {
1458
- start: number;
1459
- end: number;
1460
- isFirst?: true;
1461
- isLast?: true;
1462
- }
1463
- interface TextEqualsOptions {
1464
- loose?: boolean;
1465
- }
1466
- type DecoratedRange$1 = Range & {
1467
- /**
1468
- * Customize how another decoration is merged into a text node. If not specified, `Object.assign` would be used.
1469
- * It is useful for overlapping decorations with the same key but different values.
1470
- */
1471
- merge?: (leaf: Text$1, decoration: object) => void;
1472
- };
1473
- interface TextInterface {
1474
- /**
1475
- * Check if two text nodes are equal.
1476
- *
1477
- * When loose is set, the text is not compared. This is
1478
- * used to check whether sibling text nodes can be merged.
1479
- */
1480
- equals: (text: Text$1, another: Text$1, options?: TextEqualsOptions) => boolean;
1481
- /**
1482
- * Check if a value implements the `Text` interface.
1483
- */
1484
- isText: (value: any) => value is Text$1;
1485
- /**
1486
- * Check if a value is a list of `Text` objects.
1487
- */
1488
- isTextList: (value: any) => value is Text$1[];
1489
- /**
1490
- * Check if some props are a partial of Text.
1491
- */
1492
- isTextProps: (props: any) => props is Partial<Text$1>;
1493
- /**
1494
- * Check if an text matches set of properties.
1495
- *
1496
- * Note: this is for matching custom properties, and it does not ensure that
1497
- * the `text` property are two nodes equal.
1498
- */
1499
- matches: (text: Text$1, props: Partial<Text$1>) => boolean;
1500
- /**
1501
- * Get the leaves for a text node given decorations.
1502
- */
1503
- decorations: (node: Text$1, decorations: DecoratedRange$1[]) => {
1504
- leaf: Text$1;
1505
- position?: LeafPosition;
1506
- }[];
1507
- }
1508
- declare const Text$1: TextInterface;
1509
- interface GeneralTransforms {
1510
- /**
1511
- * Transform the editor by an operation.
1512
- */
1513
- transform: (editor: Editor$1, op: Operation) => void;
1514
- }
1515
- declare const GeneralTransforms: GeneralTransforms;
1516
- interface SelectionCollapseOptions {
1517
- edge?: SelectionEdge;
1518
- }
1519
- interface SelectionMoveOptions {
1520
- distance?: number;
1521
- unit?: MoveUnit;
1522
- reverse?: boolean;
1523
- edge?: SelectionEdge;
1524
- }
1525
- interface SelectionSetPointOptions {
1526
- edge?: SelectionEdge;
1527
- }
1528
- interface SelectionTransforms {
1529
- /**
1530
- * Collapse the selection.
1531
- */
1532
- collapse: (editor: Editor$1, options?: SelectionCollapseOptions) => void;
1533
- /**
1534
- * Unset the selection.
1535
- */
1536
- deselect: (editor: Editor$1) => void;
1537
- /**
1538
- * Move the selection's point forward or backward.
1539
- */
1540
- move: (editor: Editor$1, options?: SelectionMoveOptions) => void;
1541
- /**
1542
- * Set the selection to a new value.
1543
- */
1544
- select: (editor: Editor$1, target: Location) => void;
1545
- /**
1546
- * Set new properties on one of the selection's points.
1547
- */
1548
- setPoint: (editor: Editor$1, props: Partial<Point>, options?: SelectionSetPointOptions) => void;
1549
- /**
1550
- * Set new properties on the selection.
1551
- */
1552
- setSelection: (editor: Editor$1, props: Partial<Range>) => void;
237
+ interface BaseEditor {
238
+ children: PortableTextBlock[];
239
+ readonly value: PortableTextBlock[];
240
+ selection: Selection$1;
241
+ operations: Operation[];
242
+ marks: EditorMarks | null;
243
+ dirtyPaths: Path$1[];
244
+ dirtyPathKeys: Set<string>;
245
+ flushing: boolean;
246
+ normalizing: boolean;
247
+ pathRefs: Set<PathRef>;
248
+ pointRefs: Set<PointRef>;
249
+ rangeRefs: Set<RangeRef>;
250
+ apply: (operation: Operation) => void;
251
+ normalizeNode: (entry: [Editor$1 | Node$1, Path$1], options?: {
252
+ operation?: Operation;
253
+ }) => void;
254
+ onChange: (options?: {
255
+ operation?: Operation;
256
+ }) => void;
257
+ shouldNormalize: ({
258
+ iteration,
259
+ dirtyPaths,
260
+ operation
261
+ }: {
262
+ iteration: number;
263
+ initialDirtyPathsLength: number;
264
+ dirtyPaths: Path$1[];
265
+ operation?: Operation;
266
+ }) => boolean;
267
+ select: (target: Location) => void;
268
+ setSelection: (props: Partial<Range>) => void;
1553
269
  }
1554
- declare const SelectionTransforms: SelectionTransforms;
1555
- declare const Transforms: GeneralTransforms & NodeTransforms & SelectionTransforms & TextTransforms;
1556
- /**
1557
- * @public
1558
- */
1559
- type EditorSchema = Schema;
1560
- type DecoratedRange = BaseRange & {
1561
- rangeDecoration: RangeDecoration;
1562
- merge: (leaf: Record<string, unknown>, decoration: Record<string, unknown>) => void;
1563
- };
270
+ type Editor$1 = BaseEditor & ReactEditor & PortableTextSlateEditor;
271
+ type Selection$1 = Range | null;
272
+ type EditorMarks = Omit<PortableTextSpan, 'text'>;
1564
273
  type StringDiff = {
1565
274
  start: number;
1566
275
  end: number;
@@ -1586,17 +295,10 @@ declare global {
1586
295
  }
1587
296
  }
1588
297
  type DOMPoint = [Node, number];
1589
- /**
1590
- * An auto-incrementing identifier for keys.
1591
- */
1592
- /**
1593
- * A class that keeps track of a key string. We use a full class here because we
1594
- * want to be able to use them as keys in `WeakMap` objects.
1595
- */
1596
- declare class Key {
1597
- id: string;
1598
- constructor();
1599
- }
298
+ type Action = {
299
+ at?: Point | Range;
300
+ run: () => void;
301
+ };
1600
302
  /**
1601
303
  * A DOM-specific version of the `Editor` interface.
1602
304
  */
@@ -1605,45 +307,36 @@ interface DOMEditor extends BaseEditor {
1605
307
  hasRange: (editor: Editor$1, range: Range) => boolean;
1606
308
  hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
1607
309
  hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1608
- insertData: (data: DataTransfer) => void;
1609
- insertFragmentData: (data: DataTransfer) => boolean;
1610
- insertTextData: (data: DataTransfer) => boolean;
1611
310
  isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
1612
- setFragmentData: (data: DataTransfer, originEvent?: 'drag' | 'copy' | 'cut') => void;
311
+ isNodeMapDirty: boolean;
312
+ domWindow: Window | null;
313
+ domElement: HTMLElement | null;
314
+ domPlaceholder: string;
315
+ domPlaceholderElement: HTMLElement | null;
316
+ readOnly: boolean;
317
+ focused: boolean;
318
+ composing: boolean;
319
+ userSelection: RangeRef | null;
320
+ onContextChange: ((options?: {
321
+ operation?: Operation;
322
+ }) => void) | null;
323
+ scheduleFlush: (() => void) | null;
324
+ pendingInsertionMarks: EditorMarks | null;
325
+ userMarks: EditorMarks | null;
326
+ pendingDiffs: TextDiff[];
327
+ pendingAction: Action | null;
328
+ pendingSelection: Range | null;
329
+ forceRender: (() => void) | null;
1613
330
  }
1614
331
  interface DOMEditorInterface {
1615
- /**
1616
- * Experimental and android specific: Get pending diffs
1617
- */
1618
- androidPendingDiffs: (editor: Editor$1) => TextDiff[] | undefined;
1619
- /**
1620
- * Experimental and android specific: Flush all pending diffs and cancel composition at the next possible time.
1621
- */
1622
- androidScheduleFlush: (editor: Editor$1) => void;
1623
332
  /**
1624
333
  * Blur the editor.
1625
334
  */
1626
335
  blur: (editor: Editor$1) => void;
1627
- /**
1628
- * Deselect the editor.
1629
- */
1630
- deselect: (editor: Editor$1) => void;
1631
336
  /**
1632
337
  * Find the DOM node that implements DocumentOrShadowRoot for the editor.
1633
338
  */
1634
339
  findDocumentOrShadowRoot: (editor: Editor$1) => Document | ShadowRoot;
1635
- /**
1636
- * Get the target range from a DOM `event`.
1637
- */
1638
- findEventRange: (editor: Editor$1, event: any) => Range;
1639
- /**
1640
- * Find a key for a Slate node.
1641
- */
1642
- findKey: (editor: Editor$1, node: Node$1) => Key;
1643
- /**
1644
- * Find the path of Slate node.
1645
- */
1646
- findPath: (editor: Editor$1, node: Node$1) => Path$1;
1647
340
  /**
1648
341
  * Focus the editor.
1649
342
  */
@@ -1676,18 +369,6 @@ interface DOMEditorInterface {
1676
369
  * Check if the target is in the editor.
1677
370
  */
1678
371
  hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
1679
- /**
1680
- * Insert data from a `DataTransfer` into the editor.
1681
- */
1682
- insertData: (editor: Editor$1, data: DataTransfer) => void;
1683
- /**
1684
- * Insert fragment data from a `DataTransfer` into the editor.
1685
- */
1686
- insertFragmentData: (editor: Editor$1, data: DataTransfer) => boolean;
1687
- /**
1688
- * Insert text data from a `DataTransfer` into the editor.
1689
- */
1690
- insertTextData: (editor: Editor$1, data: DataTransfer) => boolean;
1691
372
  /**
1692
373
  * Check if the user is currently composing inside the editor.
1693
374
  */
@@ -1696,22 +377,10 @@ interface DOMEditorInterface {
1696
377
  * Check if the editor is focused.
1697
378
  */
1698
379
  isFocused: (editor: Editor$1) => boolean;
1699
- /**
1700
- * Check if the editor is in read-only mode.
1701
- */
1702
- isReadOnly: (editor: Editor$1) => boolean;
1703
380
  /**
1704
381
  * Check if the target is inside void and in an non-readonly editor.
1705
382
  */
1706
383
  isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
1707
- /**
1708
- * Sets data from the currently selected fragment on a `DataTransfer`.
1709
- */
1710
- setFragmentData: (editor: Editor$1, data: DataTransfer, originEvent?: 'drag' | 'copy' | 'cut') => void;
1711
- /**
1712
- * Find the native DOM element from a Slate node.
1713
- */
1714
- toDOMNode: (editor: Editor$1, node: Node$1) => HTMLElement;
1715
384
  /**
1716
385
  * Find a native DOM selection point from a Slate point.
1717
386
  */
@@ -1725,10 +394,6 @@ interface DOMEditorInterface {
1725
394
  * according to https://dom.spec.whatwg.org/#concept-range-bp-set.
1726
395
  */
1727
396
  toDOMRange: (editor: Editor$1, range: Range) => DOMRange;
1728
- /**
1729
- * Find a Slate node from a native DOM `element`.
1730
- */
1731
- toSlateNode: (editor: Editor$1, domNode: DOMNode) => Node$1;
1732
397
  /**
1733
398
  * Find a Slate point from a DOM selection's `domNode` and `domOffset`.
1734
399
  */
@@ -1753,37 +418,14 @@ declare const DOMEditor: DOMEditorInterface;
1753
418
  /**
1754
419
  * A React and DOM-specific version of the `Editor` interface.
1755
420
  */
1756
- interface ReactEditor extends DOMEditor {
1757
- /**
1758
- * Determines the chunk size used by the children chunking optimization. If
1759
- * null is returned (which is the default), the chunking optimization is
1760
- * disabled.
1761
- */
1762
- getChunkSize: (node: Ancestor) => number | null;
1763
- }
421
+ interface ReactEditor extends DOMEditor {}
1764
422
  interface ReactEditorInterface extends DOMEditorInterface {}
1765
423
  declare const ReactEditor: ReactEditorInterface;
1766
- interface VoidElement {
1767
- _type: string;
1768
- _key: string;
1769
- children: Descendant[];
1770
- __inline: boolean;
1771
- value: Record<string, unknown>;
1772
- }
1773
- interface SlateTextBlock extends Omit<PortableTextTextBlock, 'children'> {
1774
- children: Descendant[];
1775
- }
1776
- declare module '../slate/index' {
1777
- interface CustomTypes {
1778
- Editor: BaseEditor & ReactEditor & PortableTextSlateEditor;
1779
- Element: SlateTextBlock | VoidElement;
1780
- Text: PortableTextSpan;
1781
- }
1782
- }
1783
- //# sourceMappingURL=slate.d.ts.map
1784
424
  type HistoryItem = {
1785
425
  operations: Operation[];
1786
426
  timestamp: Date;
427
+ splitContext?: SplitContext | null;
428
+ mergeContext?: MergeContext | null;
1787
429
  };
1788
430
  interface History {
1789
431
  redos: HistoryItem[];
@@ -1842,9 +484,9 @@ interface MergeContext {
1842
484
  interface PortableTextSlateEditor extends ReactEditor {
1843
485
  _key: 'editor';
1844
486
  _type: 'editor';
1845
- isTextBlock: (value: unknown) => value is PortableTextTextBlock;
1846
- isTextSpan: (value: unknown) => value is PortableTextSpan;
1847
- isListBlock: (value: unknown) => value is PortableTextListBlock;
487
+ schema: EditorSchema;
488
+ keyGenerator: () => string;
489
+ editableTypes: Set<string>;
1848
490
  decoratedRanges: Array<DecoratedRange>;
1849
491
  /**
1850
492
  * Snapshot of decoration state taken before a remote batch starts.
@@ -1872,7 +514,6 @@ interface PortableTextSlateEditor extends ReactEditor {
1872
514
  listIndexMap: Map<string, number>;
1873
515
  remotePatches: Array<RemotePatch>;
1874
516
  undoStepId: string | undefined;
1875
- value: Array<PortableTextBlock>;
1876
517
  /**
1877
518
  * Context for the current split operation.
1878
519
  * Set before delete+insert operations, cleared after.
@@ -1895,6 +536,19 @@ interface PortableTextSlateEditor extends ReactEditor {
1895
536
  anchor: boolean;
1896
537
  focus: boolean;
1897
538
  }> | null;
539
+ /**
540
+ * Accumulates decoration shift records between mutation flushes.
541
+ * Consumed and cleared by the mutation machine's `'emit mutations'`
542
+ * action so that `MutationEvent` includes `rangeDecorationShifts`.
543
+ */
544
+ pendingDecorationShifts: Array<RangeDecorationShift>;
545
+ /**
546
+ * When > 0, the decoration `sendBack` interceptor skips firing
547
+ * `slate operation` events. Used by `applyMergeNode` and `applySplitNode`
548
+ * to suppress events for their decomposed operations, which would
549
+ * otherwise double-transform or invalidate decoration ranges.
550
+ */
551
+ _suppressDecorationSendBack: number;
1898
552
  isDeferringMutations: boolean;
1899
553
  isNormalizingNode: boolean;
1900
554
  isPatching: boolean;
@@ -1903,15 +557,13 @@ interface PortableTextSlateEditor extends ReactEditor {
1903
557
  isRedoing: boolean;
1904
558
  isUndoing: boolean;
1905
559
  withHistory: boolean;
1906
- /**
1907
- * Undo
1908
- */
1909
- undo: () => void;
1910
- /**
1911
- * Redo
1912
- */
1913
- redo: () => void;
1914
560
  }
561
+ /**
562
+ * @public
563
+ */
564
+ type RangeDecorationShift = Omit<RangeDecorationOnMovedDetails, 'rangeDecoration'> & {
565
+ rangeDecoration: RangeDecoration;
566
+ };
1915
567
  /**
1916
568
  * @public
1917
569
  */
@@ -1964,20 +616,17 @@ type MutationEvent = {
1964
616
  type: 'mutation';
1965
617
  patches: Array<Patch>;
1966
618
  value: Array<PortableTextBlock> | undefined;
619
+ rangeDecorationShifts: Array<RangeDecorationShift>;
1967
620
  };
1968
621
  type PatchEvent = {
1969
622
  type: 'patch';
1970
623
  patch: Patch;
1971
624
  };
1972
- type SlateEditor = {
1973
- instance: PortableTextSlateEditor;
1974
- initialValue: Array<Descendant>;
1975
- };
1976
625
  type InternalEditor = Editor & {
1977
626
  _internal: {
1978
627
  editable: EditableAPI;
1979
628
  editorActor: EditorActor;
1980
- slateEditor: SlateEditor;
629
+ slateEditor: PortableTextSlateEditor;
1981
630
  };
1982
631
  };
1983
632
  /**
@@ -2419,7 +1068,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
2419
1068
  * ```
2420
1069
  * @group Components
2421
1070
  */
2422
- declare const PortableTextEditable: react13.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react13.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
1071
+ declare const PortableTextEditable: react4.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react4.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
2423
1072
  /** @beta */
2424
1073
  interface EditableAPIDeleteOptions {
2425
1074
  mode?: 'blocks' | 'children' | 'selected';
@@ -2476,8 +1125,8 @@ interface EditableAPI {
2476
1125
  isCollapsedSelection: () => boolean;
2477
1126
  isExpandedSelection: () => boolean;
2478
1127
  isMarkActive: (mark: string) => boolean;
2479
- isSelectionsOverlapping: (selectionA: EditorSelection, selectionB: EditorSelection) => boolean;
2480
1128
  isVoid: (element: PortableTextBlock | PortableTextChild) => boolean;
1129
+ isSelectionsOverlapping: (selectionA: EditorSelection, selectionB: EditorSelection) => boolean;
2481
1130
  marks: () => string[];
2482
1131
  redo: () => void;
2483
1132
  removeAnnotation: <TSchemaType extends {
@@ -2642,15 +1291,10 @@ interface RangeDecorationOnMovedDetails {
2642
1291
  newSelection: EditorSelection;
2643
1292
  origin: 'remote' | 'local';
2644
1293
  /**
2645
- * Why the callback fired.
2646
- *
2647
- * - `'moved'` — the range's boundary points (anchor/focus) shifted due to
2648
- * an editing operation, or the range was invalidated (`newSelection` is
2649
- * `null`).
2650
- * - `'contentChanged'` — the boundary points are unchanged, but content
2651
- * inside the range was modified (text edits, node changes, etc.).
2652
- * `previousSelection` and `newSelection` will be identical.
2653
- * The return value is ignored for this reason.
1294
+ * - `'moved'` — the range's boundary points shifted or the range was
1295
+ * invalidated.
1296
+ * - `'contentChanged'` — the boundary points are unchanged but content
1297
+ * inside the range was modified.
2654
1298
  */
2655
1299
  reason: 'moved' | 'contentChanged';
2656
1300
  }
@@ -2681,17 +1325,10 @@ interface RangeDecoration {
2681
1325
  /**
2682
1326
  * Called when the range decoration moves due to edits.
2683
1327
  *
2684
- * When `origin` is `'remote'`, the return value is honored: return an
2685
- * `EditorSelection` to override the auto-resolved position (e.g. re-resolve
2686
- * from a W3C annotation or other source of truth). This is useful because
2687
- * remote structural ops (split/merge) may truncate or invalidate the
2688
- * decoration, and the editor cannot reconstruct the full range without
2689
- * consumer knowledge.
2690
- *
2691
- * When `origin` is `'local'`, the return value is ignored — local transforms
2692
- * (split/merge context) already produce correct positions.
1328
+ * For transactional handling of moves alongside content changes, use
1329
+ * `rangeDecorationShifts` on the `'mutation'` event instead.
2693
1330
  */
2694
- onMoved?: (details: RangeDecorationOnMovedDetails) => EditorSelection | void;
1331
+ onMoved?: (details: RangeDecorationOnMovedDetails) => void;
2695
1332
  /**
2696
1333
  * Stable identifier for matching to external data (e.g., annotation/comment ID).
2697
1334
  * Set by the consumer — PTE preserves it and passes it through in onMoved details.
@@ -2934,7 +1571,7 @@ type EditorActor = ActorRefFrom<typeof editorMachine>;
2934
1571
  /**
2935
1572
  * @internal
2936
1573
  */
2937
- declare const editorMachine: xstate77.StateMachine<{
1574
+ declare const editorMachine: xstate73.StateMachine<{
2938
1575
  behaviors: Set<BehaviorConfig>;
2939
1576
  behaviorsSorted: boolean;
2940
1577
  converters: Set<Converter>;
@@ -2950,7 +1587,7 @@ declare const editorMachine: xstate77.StateMachine<{
2950
1587
  };
2951
1588
  dragGhost?: HTMLElement;
2952
1589
  slateEditor?: PortableTextSlateEditor;
2953
- }, MutationEvent | InternalPatchEvent | PatchesEvent | {
1590
+ }, InternalPatchEvent | MutationEvent | PatchesEvent | {
2954
1591
  type: "update readOnly";
2955
1592
  readOnly: boolean;
2956
1593
  } | {
@@ -2995,52 +1632,52 @@ declare const editorMachine: xstate77.StateMachine<{
2995
1632
  editor: PortableTextSlateEditor;
2996
1633
  }, {}, never, {
2997
1634
  type: "add behavior to context";
2998
- params: xstate77.NonReducibleUnknown;
1635
+ params: xstate73.NonReducibleUnknown;
2999
1636
  } | {
3000
1637
  type: "remove behavior from context";
3001
- params: xstate77.NonReducibleUnknown;
1638
+ params: xstate73.NonReducibleUnknown;
3002
1639
  } | {
3003
1640
  type: "add slate editor to context";
3004
- params: xstate77.NonReducibleUnknown;
1641
+ params: xstate73.NonReducibleUnknown;
3005
1642
  } | {
3006
1643
  type: "emit patch event";
3007
- params: xstate77.NonReducibleUnknown;
1644
+ params: xstate73.NonReducibleUnknown;
3008
1645
  } | {
3009
1646
  type: "emit mutation event";
3010
- params: xstate77.NonReducibleUnknown;
1647
+ params: xstate73.NonReducibleUnknown;
3011
1648
  } | {
3012
1649
  type: "emit read only";
3013
- params: xstate77.NonReducibleUnknown;
1650
+ params: xstate73.NonReducibleUnknown;
3014
1651
  } | {
3015
1652
  type: "emit editable";
3016
- params: xstate77.NonReducibleUnknown;
1653
+ params: xstate73.NonReducibleUnknown;
3017
1654
  } | {
3018
1655
  type: "defer event";
3019
- params: xstate77.NonReducibleUnknown;
1656
+ params: xstate73.NonReducibleUnknown;
3020
1657
  } | {
3021
1658
  type: "emit pending events";
3022
- params: xstate77.NonReducibleUnknown;
1659
+ params: xstate73.NonReducibleUnknown;
3023
1660
  } | {
3024
1661
  type: "emit ready";
3025
- params: xstate77.NonReducibleUnknown;
1662
+ params: xstate73.NonReducibleUnknown;
3026
1663
  } | {
3027
1664
  type: "clear pending events";
3028
- params: xstate77.NonReducibleUnknown;
1665
+ params: xstate73.NonReducibleUnknown;
3029
1666
  } | {
3030
1667
  type: "discard conflicting pending patches";
3031
- params: xstate77.NonReducibleUnknown;
1668
+ params: xstate73.NonReducibleUnknown;
3032
1669
  } | {
3033
1670
  type: "discard all pending events";
3034
- params: xstate77.NonReducibleUnknown;
1671
+ params: xstate73.NonReducibleUnknown;
3035
1672
  } | {
3036
1673
  type: "defer incoming patches";
3037
- params: xstate77.NonReducibleUnknown;
1674
+ params: xstate73.NonReducibleUnknown;
3038
1675
  } | {
3039
1676
  type: "emit pending incoming patches";
3040
- params: xstate77.NonReducibleUnknown;
1677
+ params: xstate73.NonReducibleUnknown;
3041
1678
  } | {
3042
1679
  type: "clear pending incoming patches";
3043
- params: xstate77.NonReducibleUnknown;
1680
+ params: xstate73.NonReducibleUnknown;
3044
1681
  } | {
3045
1682
  type: "handle blur";
3046
1683
  params: unknown;
@@ -3052,7 +1689,7 @@ declare const editorMachine: xstate77.StateMachine<{
3052
1689
  params: unknown;
3053
1690
  } | {
3054
1691
  type: "sort behaviors";
3055
- params: xstate77.NonReducibleUnknown;
1692
+ params: xstate73.NonReducibleUnknown;
3056
1693
  }, {
3057
1694
  type: "slate is busy";
3058
1695
  params: unknown;
@@ -3081,9 +1718,9 @@ declare const editorMachine: xstate77.StateMachine<{
3081
1718
  readOnly?: boolean;
3082
1719
  schema: EditorSchema;
3083
1720
  initialValue?: Array<PortableTextBlock>;
3084
- }, xstate77.NonReducibleUnknown, {
1721
+ }, xstate73.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
3085
1722
  type: "blurred";
3086
- event: react13.FocusEvent<HTMLDivElement, Element>;
1723
+ event: react4.FocusEvent<HTMLDivElement, Element>;
3087
1724
  } | {
3088
1725
  type: "done loading";
3089
1726
  } | {
@@ -3095,14 +1732,14 @@ declare const editorMachine: xstate77.StateMachine<{
3095
1732
  data: unknown;
3096
1733
  } | {
3097
1734
  type: "focused";
3098
- event: react13.FocusEvent<HTMLDivElement, Element>;
1735
+ event: react4.FocusEvent<HTMLDivElement, Element>;
3099
1736
  } | {
3100
1737
  type: "invalid value";
3101
1738
  resolution: InvalidValueResolution | null;
3102
1739
  value: Array<PortableTextBlock> | undefined;
3103
1740
  } | {
3104
1741
  type: "loading";
3105
- } | MutationEvent | {
1742
+ } | {
3106
1743
  type: "read only";
3107
1744
  } | {
3108
1745
  type: "ready";
@@ -3112,7 +1749,7 @@ declare const editorMachine: xstate77.StateMachine<{
3112
1749
  } | {
3113
1750
  type: "value changed";
3114
1751
  value: Array<PortableTextBlock> | undefined;
3115
- } | InternalPatchEvent | PatchesEvent, xstate77.MetaObject, {
1752
+ }, xstate73.MetaObject, {
3116
1753
  id: "editor";
3117
1754
  states: {
3118
1755
  readonly 'edit mode': {
@@ -3770,5 +2407,5 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
3770
2407
  event: TBehaviorEvent;
3771
2408
  dom: EditorDom;
3772
2409
  }, guardResponse: TGuardResponse) => Array<BehaviorAction>;
3773
- export { BlockAnnotationRenderProps as $, PortableTextTextBlock$1 as A, MutationEvent as At, EditorSelector as B, ListDefinition as C, RenderStyleFunction as Ct, PortableTextChild$1 as D, HotkeyOptions as Dt, PortableTextBlock$1 as E, PortableTextEditableProps as Et, BlockOffset as F, KeyedSegment as Ft, EditorConfig as G, EditorProvider as H, useEditor as I, Path as It, defineBehavior as J, EditorEvent as K, defaultKeyGenerator as L, StyleDefinition as M, AnnotationPath as Mt, StyleSchemaType$1 as N, BlockPath as Nt, PortableTextObject$1 as O, PortableTextEditor as Ot, defineSchema as P, ChildPath as Pt, AddedAnnotationPaths as Q, usePortableTextEditorSelection as R, InlineObjectSchemaType$1 as S, RenderPlaceholderFunction as St, Patch$1 as T, PortableTextEditable as Tt, EditorProviderProps as U, useEditorSelector as V, Editor as W, EditorContext as X, BehaviorGuard as Y, EditorSnapshot as Z, BlockObjectSchemaType$1 as _, RenderBlockFunction as _t, forward as a, EditableAPIDeleteOptions as at, FieldDefinition as b, RenderEditableFunction as bt, CustomBehaviorEvent as c, InvalidValueResolution as ct, SyntheticBehaviorEvent as d, OnPasteResult as dt, BlockChildRenderProps as et, PatchesEvent as f, OnPasteResultOrPromise as ft, BlockObjectDefinition as g, RenderAnnotationFunction as gt, BaseDefinition as h, RangeDecorationOnMovedDetails as ht, execute as i, BlockStyleRenderProps as it, SchemaDefinition$1 as j, EditorSchema as jt, PortableTextSpan$1 as k, EditorEmittedEvent as kt, InsertPlacement as l, OnCopyFn as lt, AnnotationSchemaType$1 as m, RangeDecoration as mt, BehaviorActionSet as n, BlockListItemRenderProps as nt, raise as o, EditorSelection as ot, AnnotationDefinition as p, PasteData as pt, Behavior as q, effect as r, BlockRenderProps as rt, BehaviorEvent as s, EditorSelectionPoint as st, BehaviorAction as t, BlockDecoratorRenderProps as tt, NativeBehaviorEvent as u, OnPasteFn as ut, DecoratorDefinition as v, RenderChildFunction as vt, ListSchemaType$1 as w, ScrollSelectionIntoViewFunction as wt, InlineObjectDefinition as x, RenderListItemFunction as xt, DecoratorSchemaType$1 as y, RenderDecoratorFunction as yt, usePortableTextEditor as z };
2410
+ export { BlockAnnotationRenderProps as $, PortableTextTextBlock$1 as A, MutationEvent as At, EditorSelector as B, ListDefinition as C, RenderStyleFunction as Ct, PortableTextChild$1 as D, HotkeyOptions as Dt, PortableTextBlock$1 as E, PortableTextEditableProps as Et, BlockOffset as F, ChildPath as Ft, EditorConfig as G, EditorProvider as H, useEditor as I, KeyedSegment as It, defineBehavior as J, EditorEvent as K, defaultKeyGenerator as L, Path as Lt, StyleDefinition as M, EditorSchema as Mt, StyleSchemaType$1 as N, AnnotationPath as Nt, PortableTextObject$1 as O, PortableTextEditor as Ot, defineSchema as P, BlockPath as Pt, AddedAnnotationPaths as Q, usePortableTextEditorSelection as R, InlineObjectSchemaType$1 as S, RenderPlaceholderFunction as St, Patch$1 as T, PortableTextEditable as Tt, EditorProviderProps as U, useEditorSelector as V, Editor as W, EditorContext as X, BehaviorGuard as Y, EditorSnapshot as Z, BlockObjectSchemaType$1 as _, RenderBlockFunction as _t, forward as a, EditableAPIDeleteOptions as at, FieldDefinition as b, RenderEditableFunction as bt, CustomBehaviorEvent as c, InvalidValueResolution as ct, SyntheticBehaviorEvent as d, OnPasteResult as dt, BlockChildRenderProps as et, PatchesEvent as f, OnPasteResultOrPromise as ft, BlockObjectDefinition as g, RenderAnnotationFunction as gt, BaseDefinition as h, RangeDecorationOnMovedDetails as ht, execute as i, BlockStyleRenderProps as it, SchemaDefinition$1 as j, RangeDecorationShift as jt, PortableTextSpan$1 as k, EditorEmittedEvent as kt, InsertPlacement as l, OnCopyFn as lt, AnnotationSchemaType$1 as m, RangeDecoration as mt, BehaviorActionSet as n, BlockListItemRenderProps as nt, raise as o, EditorSelection as ot, AnnotationDefinition as p, PasteData as pt, Behavior as q, effect as r, BlockRenderProps as rt, BehaviorEvent as s, EditorSelectionPoint as st, BehaviorAction as t, BlockDecoratorRenderProps as tt, NativeBehaviorEvent as u, OnPasteFn as ut, DecoratorDefinition as v, RenderChildFunction as vt, ListSchemaType$1 as w, ScrollSelectionIntoViewFunction as wt, InlineObjectDefinition as x, RenderListItemFunction as xt, DecoratorSchemaType$1 as y, RenderDecoratorFunction as yt, usePortableTextEditor as z };
3774
2411
  //# sourceMappingURL=behavior.types.action.d.ts.map