@portabletext/editor 6.6.4 → 7.0.1
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/lib/_chunks-dts/behavior.types.action.d.ts +683 -512
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/resolve-containers.d.ts +688 -0
- package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -0
- package/lib/_chunks-es/get-ancestor.js +192 -0
- package/lib/_chunks-es/get-ancestor.js.map +1 -0
- package/lib/_chunks-es/get-first-child.js +130 -0
- package/lib/_chunks-es/get-first-child.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +266 -0
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1021 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/use-editor.js +4 -13
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +15 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +347 -198
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5457 -5611
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +18 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +18 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +220 -5
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +62 -71
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +235 -0
- package/lib/traversal/index.d.ts.map +1 -0
- package/lib/traversal/index.js +30 -0
- package/lib/traversal/index.js.map +1 -0
- package/lib/utils/index.d.ts +11 -57
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +36 -107
- package/lib/utils/index.js.map +1 -1
- package/package.json +19 -17
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +0 -806
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/util.slice-text-block.js +0 -60
- package/lib/_chunks-es/util.slice-text-block.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { A as ChildPath, D as Path$1, M as Path, O as AnnotationPath, _ as RegistrableNode, a as Containers, d as ResolvedContainers, g as InlineObjectConfig, i as EditorSchema, k as BlockPath, p as BlockObjectConfig, r as Node$1, x as TextBlockConfig, y as SpanConfig } from "./resolve-containers.js";
|
|
1
2
|
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, 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
|
|
3
|
+
import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition as FieldDefinition$1, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, StyleSchemaType as StyleSchemaType$1, TypedObject, defineSchema } from "@portabletext/schema";
|
|
4
|
+
import * as xstate37 from "xstate";
|
|
4
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
5
6
|
import * as react4 from "react";
|
|
6
7
|
import React$1, { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
@@ -58,470 +59,6 @@ type Deserializer<TMIMEType extends MIMEType> = ({
|
|
|
58
59
|
snapshot: EditorSnapshot;
|
|
59
60
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>;
|
|
60
61
|
}) => PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialization.success' | 'deserialization.failure'>;
|
|
61
|
-
/**
|
|
62
|
-
* A segment in a path that identifies an element by its `_key` property.
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
interface KeyedSegment {
|
|
66
|
-
_key: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* A tuple representing a range selection, e.g., `[0, 5]` or `['', 3]`.
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
type IndexTuple = [number | '', number | ''];
|
|
73
|
-
/**
|
|
74
|
-
* A single segment in a path. Can be:
|
|
75
|
-
* - A string (property name)
|
|
76
|
-
* - A number (array index)
|
|
77
|
-
* - A KeyedSegment (object with `_key`)
|
|
78
|
-
* - An IndexTuple (range selection)
|
|
79
|
-
* @public
|
|
80
|
-
*/
|
|
81
|
-
type PathSegment = string | number | KeyedSegment | IndexTuple;
|
|
82
|
-
/**
|
|
83
|
-
* A path is an array of path segments that describes a location in a document.
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
type Path = PathSegment[];
|
|
87
|
-
/**
|
|
88
|
-
* @public
|
|
89
|
-
*/
|
|
90
|
-
type BlockPath = [{
|
|
91
|
-
_key: string;
|
|
92
|
-
}];
|
|
93
|
-
/**
|
|
94
|
-
* @public
|
|
95
|
-
*/
|
|
96
|
-
type AnnotationPath = [{
|
|
97
|
-
_key: string;
|
|
98
|
-
}, 'markDefs', {
|
|
99
|
-
_key: string;
|
|
100
|
-
}];
|
|
101
|
-
/**
|
|
102
|
-
* @public
|
|
103
|
-
*/
|
|
104
|
-
type ChildPath = [{
|
|
105
|
-
_key: string;
|
|
106
|
-
}, 'children', {
|
|
107
|
-
_key: string;
|
|
108
|
-
}];
|
|
109
|
-
/**
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
type EditorSchema = Schema;
|
|
113
|
-
/**
|
|
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.
|
|
117
|
-
*/
|
|
118
|
-
type Path$1 = number[];
|
|
119
|
-
type Node$1 = PortableTextTextBlock | PortableTextObject | PortableTextSpan;
|
|
120
|
-
type TextDirection = 'forward' | 'backward';
|
|
121
|
-
/**
|
|
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.
|
|
126
|
-
*/
|
|
127
|
-
interface Point {
|
|
128
|
-
path: number[];
|
|
129
|
-
offset: number;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
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.
|
|
135
|
-
*/
|
|
136
|
-
interface Range {
|
|
137
|
-
anchor: Point;
|
|
138
|
-
focus: Point;
|
|
139
|
-
}
|
|
140
|
-
type InsertNodeOperation = {
|
|
141
|
-
type: 'insert_node';
|
|
142
|
-
path: Path$1;
|
|
143
|
-
node: Node$1;
|
|
144
|
-
};
|
|
145
|
-
type InsertTextOperation = {
|
|
146
|
-
type: 'insert_text';
|
|
147
|
-
path: Path$1;
|
|
148
|
-
offset: number;
|
|
149
|
-
text: string;
|
|
150
|
-
};
|
|
151
|
-
type RemoveNodeOperation = {
|
|
152
|
-
type: 'remove_node';
|
|
153
|
-
path: Path$1;
|
|
154
|
-
node: Node$1;
|
|
155
|
-
};
|
|
156
|
-
type RemoveTextOperation = {
|
|
157
|
-
type: 'remove_text';
|
|
158
|
-
path: Path$1;
|
|
159
|
-
offset: number;
|
|
160
|
-
text: string;
|
|
161
|
-
};
|
|
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
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* The `Location` interface is a union of the ways to refer to a specific
|
|
187
|
-
* location in a Slate document: paths, points or ranges.
|
|
188
|
-
*
|
|
189
|
-
* Methods will often accept a `Location` instead of requiring only a `Path`,
|
|
190
|
-
* `Point` or `Range`. This eliminates the need for developers to manage
|
|
191
|
-
* converting between the different interfaces in their own code base.
|
|
192
|
-
*/
|
|
193
|
-
type Location = Path$1 | Point | Range;
|
|
194
|
-
/**
|
|
195
|
-
* `PathRef` objects keep a specific path in a document synced over time as new
|
|
196
|
-
* operations are applied to the editor. You can access their `current` property
|
|
197
|
-
* at any time for the up-to-date path value.
|
|
198
|
-
*/
|
|
199
|
-
interface PathRef {
|
|
200
|
-
current: Path$1 | null;
|
|
201
|
-
affinity: 'forward' | 'backward' | null;
|
|
202
|
-
unref(): Path$1 | null;
|
|
203
|
-
}
|
|
204
|
-
interface PathRefInterface {
|
|
205
|
-
transform: (ref: PathRef, op: Operation) => void;
|
|
206
|
-
}
|
|
207
|
-
declare const PathRef: PathRefInterface;
|
|
208
|
-
/**
|
|
209
|
-
* `PointRef` objects keep a specific point in a document synced over time as new
|
|
210
|
-
* operations are applied to the editor. You can access their `current` property
|
|
211
|
-
* at any time for the up-to-date point value.
|
|
212
|
-
*/
|
|
213
|
-
interface PointRef {
|
|
214
|
-
current: Point | null;
|
|
215
|
-
affinity: TextDirection | null;
|
|
216
|
-
unref(): Point | null;
|
|
217
|
-
}
|
|
218
|
-
interface PointRefInterface {
|
|
219
|
-
transform: (ref: PointRef, op: Operation) => void;
|
|
220
|
-
}
|
|
221
|
-
declare const PointRef: PointRefInterface;
|
|
222
|
-
/**
|
|
223
|
-
* `RangeRef` objects keep a specific range in a document synced over time as new
|
|
224
|
-
* operations are applied to the editor. You can access their `current` property
|
|
225
|
-
* at any time for the up-to-date range value.
|
|
226
|
-
*/
|
|
227
|
-
interface RangeRef {
|
|
228
|
-
current: Range | null;
|
|
229
|
-
affinity: 'forward' | 'backward' | 'outward' | 'inward' | null;
|
|
230
|
-
unref(): Range | null;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* The `Editor` interface stores all the state of a Slate editor. It is extended
|
|
234
|
-
* by plugins that wish to add their own helpers and implement new behaviors.
|
|
235
|
-
*/
|
|
236
|
-
interface BaseEditor {
|
|
237
|
-
children: PortableTextBlock[];
|
|
238
|
-
readonly value: PortableTextBlock[];
|
|
239
|
-
selection: Selection$1;
|
|
240
|
-
operations: Operation[];
|
|
241
|
-
marks: EditorMarks | null;
|
|
242
|
-
dirtyPaths: Path$1[];
|
|
243
|
-
dirtyPathKeys: Set<string>;
|
|
244
|
-
flushing: boolean;
|
|
245
|
-
normalizing: boolean;
|
|
246
|
-
pathRefs: Set<PathRef>;
|
|
247
|
-
pointRefs: Set<PointRef>;
|
|
248
|
-
rangeRefs: Set<RangeRef>;
|
|
249
|
-
apply: (operation: Operation) => void;
|
|
250
|
-
normalizeNode: (entry: [Editor$1 | Node$1, Path$1], options?: {
|
|
251
|
-
operation?: Operation;
|
|
252
|
-
}) => void;
|
|
253
|
-
onChange: (options?: {
|
|
254
|
-
operation?: Operation;
|
|
255
|
-
}) => void;
|
|
256
|
-
shouldNormalize: ({
|
|
257
|
-
iteration,
|
|
258
|
-
dirtyPaths,
|
|
259
|
-
operation
|
|
260
|
-
}: {
|
|
261
|
-
iteration: number;
|
|
262
|
-
initialDirtyPathsLength: number;
|
|
263
|
-
dirtyPaths: Path$1[];
|
|
264
|
-
operation?: Operation;
|
|
265
|
-
}) => boolean;
|
|
266
|
-
select: (target: Location) => void;
|
|
267
|
-
setSelection: (props: Partial<Range>) => void;
|
|
268
|
-
}
|
|
269
|
-
type Editor$1 = BaseEditor & ReactEditor & PortableTextSlateEditor;
|
|
270
|
-
type Selection$1 = Range | null;
|
|
271
|
-
type EditorMarks = Omit<PortableTextSpan, 'text'>;
|
|
272
|
-
type StringDiff = {
|
|
273
|
-
start: number;
|
|
274
|
-
end: number;
|
|
275
|
-
text: string;
|
|
276
|
-
};
|
|
277
|
-
type TextDiff = {
|
|
278
|
-
id: number;
|
|
279
|
-
path: Path$1;
|
|
280
|
-
diff: StringDiff;
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Types.
|
|
284
|
-
*/
|
|
285
|
-
type DOMNode = globalThis.Node;
|
|
286
|
-
type DOMRange = globalThis.Range;
|
|
287
|
-
type DOMSelection = globalThis.Selection;
|
|
288
|
-
type DOMStaticRange = globalThis.StaticRange;
|
|
289
|
-
declare global {
|
|
290
|
-
interface Window {
|
|
291
|
-
Selection: (typeof Selection)['constructor'];
|
|
292
|
-
DataTransfer: (typeof DataTransfer)['constructor'];
|
|
293
|
-
Node: (typeof Node)['constructor'];
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
type DOMPoint = [Node, number];
|
|
297
|
-
type Action = {
|
|
298
|
-
at?: Point | Range;
|
|
299
|
-
run: () => void;
|
|
300
|
-
};
|
|
301
|
-
/**
|
|
302
|
-
* A DOM-specific version of the `Editor` interface.
|
|
303
|
-
*/
|
|
304
|
-
interface DOMEditor extends BaseEditor {
|
|
305
|
-
hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
306
|
-
hasRange: (editor: Editor$1, range: Range) => boolean;
|
|
307
|
-
hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
308
|
-
hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
309
|
-
isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
310
|
-
isNodeMapDirty: boolean;
|
|
311
|
-
domWindow: Window | null;
|
|
312
|
-
domElement: HTMLElement | null;
|
|
313
|
-
domPlaceholder: string;
|
|
314
|
-
domPlaceholderElement: HTMLElement | null;
|
|
315
|
-
readOnly: boolean;
|
|
316
|
-
focused: boolean;
|
|
317
|
-
composing: boolean;
|
|
318
|
-
userSelection: RangeRef | null;
|
|
319
|
-
onContextChange: ((options?: {
|
|
320
|
-
operation?: Operation;
|
|
321
|
-
}) => void) | null;
|
|
322
|
-
scheduleFlush: (() => void) | null;
|
|
323
|
-
pendingInsertionMarks: EditorMarks | null;
|
|
324
|
-
userMarks: EditorMarks | null;
|
|
325
|
-
pendingDiffs: TextDiff[];
|
|
326
|
-
pendingAction: Action | null;
|
|
327
|
-
pendingSelection: Range | null;
|
|
328
|
-
forceRender: (() => void) | null;
|
|
329
|
-
}
|
|
330
|
-
interface DOMEditorInterface {
|
|
331
|
-
/**
|
|
332
|
-
* Blur the editor.
|
|
333
|
-
*/
|
|
334
|
-
blur: (editor: Editor$1) => void;
|
|
335
|
-
/**
|
|
336
|
-
* Find the DOM node that implements DocumentOrShadowRoot for the editor.
|
|
337
|
-
*/
|
|
338
|
-
findDocumentOrShadowRoot: (editor: Editor$1) => Document | ShadowRoot;
|
|
339
|
-
/**
|
|
340
|
-
* Focus the editor.
|
|
341
|
-
*/
|
|
342
|
-
focus: (editor: Editor$1, options?: {
|
|
343
|
-
retries: number;
|
|
344
|
-
}) => void;
|
|
345
|
-
/**
|
|
346
|
-
* Return the host window of the current editor.
|
|
347
|
-
*/
|
|
348
|
-
getWindow: (editor: Editor$1) => Window;
|
|
349
|
-
/**
|
|
350
|
-
* Check if a DOM node is within the editor.
|
|
351
|
-
*/
|
|
352
|
-
hasDOMNode: (editor: Editor$1, target: DOMNode, options?: {
|
|
353
|
-
editable?: boolean;
|
|
354
|
-
}) => boolean;
|
|
355
|
-
/**
|
|
356
|
-
* Check if the target is editable and in the editor.
|
|
357
|
-
*/
|
|
358
|
-
hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
359
|
-
/**
|
|
360
|
-
*
|
|
361
|
-
*/
|
|
362
|
-
hasRange: (editor: Editor$1, range: Range) => boolean;
|
|
363
|
-
/**
|
|
364
|
-
* Check if the target can be selectable
|
|
365
|
-
*/
|
|
366
|
-
hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
367
|
-
/**
|
|
368
|
-
* Check if the target is in the editor.
|
|
369
|
-
*/
|
|
370
|
-
hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
371
|
-
/**
|
|
372
|
-
* Check if the user is currently composing inside the editor.
|
|
373
|
-
*/
|
|
374
|
-
isComposing: (editor: Editor$1) => boolean;
|
|
375
|
-
/**
|
|
376
|
-
* Check if the editor is focused.
|
|
377
|
-
*/
|
|
378
|
-
isFocused: (editor: Editor$1) => boolean;
|
|
379
|
-
/**
|
|
380
|
-
* Check if the target is inside void and in an non-readonly editor.
|
|
381
|
-
*/
|
|
382
|
-
isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
383
|
-
/**
|
|
384
|
-
* Find a native DOM selection point from a Slate point.
|
|
385
|
-
*/
|
|
386
|
-
toDOMPoint: (editor: Editor$1, point: Point) => DOMPoint;
|
|
387
|
-
/**
|
|
388
|
-
* Find a native DOM range from a Slate `range`.
|
|
389
|
-
*
|
|
390
|
-
* Notice: the returned range will always be ordinal regardless of the direction of Slate `range` due to DOM API limit.
|
|
391
|
-
*
|
|
392
|
-
* there is no way to create a reverse DOM Range using Range.setStart/setEnd
|
|
393
|
-
* according to https://dom.spec.whatwg.org/#concept-range-bp-set.
|
|
394
|
-
*/
|
|
395
|
-
toDOMRange: (editor: Editor$1, range: Range) => DOMRange;
|
|
396
|
-
/**
|
|
397
|
-
* Find a Slate point from a DOM selection's `domNode` and `domOffset`.
|
|
398
|
-
*/
|
|
399
|
-
toSlatePoint: <T extends boolean>(editor: Editor$1, domPoint: DOMPoint, options: {
|
|
400
|
-
exactMatch: boolean;
|
|
401
|
-
suppressThrow: T;
|
|
402
|
-
/**
|
|
403
|
-
* The direction to search for Slate leaf nodes if `domPoint` is
|
|
404
|
-
* non-editable and non-void.
|
|
405
|
-
*/
|
|
406
|
-
searchDirection?: 'forward' | 'backward';
|
|
407
|
-
}) => T extends true ? Point | null : Point;
|
|
408
|
-
/**
|
|
409
|
-
* Find a Slate range from a DOM range or selection.
|
|
410
|
-
*/
|
|
411
|
-
toSlateRange: <T extends boolean>(editor: Editor$1, domRange: DOMRange | DOMStaticRange | DOMSelection, options: {
|
|
412
|
-
exactMatch: boolean;
|
|
413
|
-
suppressThrow: T;
|
|
414
|
-
}) => T extends true ? Range | null : Range;
|
|
415
|
-
}
|
|
416
|
-
declare const DOMEditor: DOMEditorInterface;
|
|
417
|
-
/**
|
|
418
|
-
* A React and DOM-specific version of the `Editor` interface.
|
|
419
|
-
*/
|
|
420
|
-
interface ReactEditor extends DOMEditor {}
|
|
421
|
-
interface ReactEditorInterface extends DOMEditorInterface {}
|
|
422
|
-
declare const ReactEditor: ReactEditorInterface;
|
|
423
|
-
type HistoryItem = {
|
|
424
|
-
operations: Operation[];
|
|
425
|
-
timestamp: Date;
|
|
426
|
-
};
|
|
427
|
-
interface History {
|
|
428
|
-
redos: HistoryItem[];
|
|
429
|
-
undos: HistoryItem[];
|
|
430
|
-
}
|
|
431
|
-
type RemotePatch = {
|
|
432
|
-
patch: Patch;
|
|
433
|
-
time: Date;
|
|
434
|
-
snapshot: PortableTextBlock[] | undefined;
|
|
435
|
-
previousSnapshot: PortableTextBlock[] | undefined;
|
|
436
|
-
};
|
|
437
|
-
interface PortableTextSlateEditor extends ReactEditor {
|
|
438
|
-
_key: 'editor';
|
|
439
|
-
_type: 'editor';
|
|
440
|
-
schema: EditorSchema;
|
|
441
|
-
keyGenerator: () => string;
|
|
442
|
-
editableTypes: Set<string>;
|
|
443
|
-
decoratedRanges: Array<DecoratedRange>;
|
|
444
|
-
decoratorState: Record<string, boolean | undefined>;
|
|
445
|
-
blockIndexMap: Map<string, number>;
|
|
446
|
-
history: History;
|
|
447
|
-
lastSelection: EditorSelection;
|
|
448
|
-
lastSlateSelection: Range | null;
|
|
449
|
-
listIndexMap: Map<string, number>;
|
|
450
|
-
remotePatches: Array<RemotePatch>;
|
|
451
|
-
undoStepId: string | undefined;
|
|
452
|
-
isDeferringMutations: boolean;
|
|
453
|
-
isNormalizingNode: boolean;
|
|
454
|
-
isPatching: boolean;
|
|
455
|
-
isPerformingBehaviorOperation: boolean;
|
|
456
|
-
isProcessingRemoteChanges: boolean;
|
|
457
|
-
isRedoing: boolean;
|
|
458
|
-
isUndoing: boolean;
|
|
459
|
-
withHistory: boolean;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* @public
|
|
463
|
-
*/
|
|
464
|
-
type EditorEmittedEvent = {
|
|
465
|
-
type: 'blurred';
|
|
466
|
-
event: FocusEvent<HTMLDivElement, Element>;
|
|
467
|
-
} | {
|
|
468
|
-
/**
|
|
469
|
-
* @deprecated Will be removed in the next major version
|
|
470
|
-
*/
|
|
471
|
-
type: 'done loading';
|
|
472
|
-
} | {
|
|
473
|
-
type: 'editable';
|
|
474
|
-
} | ErrorEvent | {
|
|
475
|
-
type: 'focused';
|
|
476
|
-
event: FocusEvent<HTMLDivElement, Element>;
|
|
477
|
-
} | {
|
|
478
|
-
type: 'invalid value';
|
|
479
|
-
resolution: InvalidValueResolution | null;
|
|
480
|
-
value: Array<PortableTextBlock> | undefined;
|
|
481
|
-
} | {
|
|
482
|
-
/**
|
|
483
|
-
* @deprecated Will be removed in the next major version
|
|
484
|
-
*/
|
|
485
|
-
type: 'loading';
|
|
486
|
-
} | MutationEvent | PatchEvent | {
|
|
487
|
-
type: 'read only';
|
|
488
|
-
} | {
|
|
489
|
-
type: 'ready';
|
|
490
|
-
} | {
|
|
491
|
-
type: 'selection';
|
|
492
|
-
selection: EditorSelection;
|
|
493
|
-
} | {
|
|
494
|
-
type: 'value changed';
|
|
495
|
-
value: Array<PortableTextBlock> | undefined;
|
|
496
|
-
};
|
|
497
|
-
/**
|
|
498
|
-
* @deprecated The event is no longer emitted
|
|
499
|
-
*/
|
|
500
|
-
type ErrorEvent = {
|
|
501
|
-
type: 'error';
|
|
502
|
-
name: string;
|
|
503
|
-
description: string;
|
|
504
|
-
data: unknown;
|
|
505
|
-
};
|
|
506
|
-
/**
|
|
507
|
-
* @public
|
|
508
|
-
*/
|
|
509
|
-
type MutationEvent = {
|
|
510
|
-
type: 'mutation';
|
|
511
|
-
patches: Array<Patch>;
|
|
512
|
-
value: Array<PortableTextBlock> | undefined;
|
|
513
|
-
};
|
|
514
|
-
type PatchEvent = {
|
|
515
|
-
type: 'patch';
|
|
516
|
-
patch: Patch;
|
|
517
|
-
};
|
|
518
|
-
type InternalEditor = Editor & {
|
|
519
|
-
_internal: {
|
|
520
|
-
editable: EditableAPI;
|
|
521
|
-
editorActor: EditorActor;
|
|
522
|
-
slateEditor: PortableTextSlateEditor;
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
62
|
/**
|
|
526
63
|
* @public
|
|
527
64
|
* @deprecated Use `useEditor()` instead
|
|
@@ -544,13 +81,10 @@ declare class PortableTextEditor {
|
|
|
544
81
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
545
82
|
*/
|
|
546
83
|
schemaTypes: Schema;
|
|
547
|
-
/**
|
|
548
|
-
* The editor instance
|
|
549
|
-
*/
|
|
550
|
-
private editor;
|
|
551
84
|
private editable;
|
|
552
85
|
constructor(config: {
|
|
553
|
-
|
|
86
|
+
editable: EditableAPI;
|
|
87
|
+
editorActor: EditorActor;
|
|
554
88
|
});
|
|
555
89
|
setEditable: (editable: EditableAPI) => void;
|
|
556
90
|
/**
|
|
@@ -1190,31 +724,409 @@ interface RangeDecorationOnMovedDetails {
|
|
|
1190
724
|
* @alpha */
|
|
1191
725
|
interface RangeDecoration {
|
|
1192
726
|
/**
|
|
1193
|
-
* A component for rendering the range decoration.
|
|
1194
|
-
* The component will receive the children (text) of the range decoration as its children.
|
|
727
|
+
* A component for rendering the range decoration.
|
|
728
|
+
* The component will receive the children (text) of the range decoration as its children.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```ts
|
|
732
|
+
* (rangeComponentProps: PropsWithChildren) => (
|
|
733
|
+
* <SearchResultHighlight>
|
|
734
|
+
* {rangeComponentProps.children}
|
|
735
|
+
* </SearchResultHighlight>
|
|
736
|
+
* )
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
component: (props: PropsWithChildren) => ReactElement<any>;
|
|
740
|
+
/**
|
|
741
|
+
* The editor content selection range
|
|
742
|
+
*/
|
|
743
|
+
selection: EditorSelection;
|
|
744
|
+
/**
|
|
745
|
+
* A optional callback that will be called when the range decoration potentially moves according to user edits.
|
|
746
|
+
*/
|
|
747
|
+
onMoved?: (details: RangeDecorationOnMovedDetails) => void;
|
|
748
|
+
/**
|
|
749
|
+
* A custom payload that can be set on the range decoration
|
|
750
|
+
*/
|
|
751
|
+
payload?: Record<string, unknown>;
|
|
752
|
+
}
|
|
753
|
+
type TextDirection = 'forward' | 'backward';
|
|
754
|
+
/**
|
|
755
|
+
* `Point` objects refer to a specific location in a text node in a Slate
|
|
756
|
+
* document. Its path refers to the location of the node in the tree, and its
|
|
757
|
+
* offset refers to the distance into the node's string of text. Points can
|
|
758
|
+
* only refer to `Text` nodes.
|
|
759
|
+
*/
|
|
760
|
+
interface Point {
|
|
761
|
+
path: Path$1;
|
|
762
|
+
offset: number;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* `Range` objects are a set of points that refer to a specific span of a Slate
|
|
766
|
+
* document. They can define a span inside a single node or a can span across
|
|
767
|
+
* multiple nodes.
|
|
768
|
+
*/
|
|
769
|
+
interface Range {
|
|
770
|
+
anchor: Point;
|
|
771
|
+
focus: Point;
|
|
772
|
+
}
|
|
773
|
+
type InsertOperation = {
|
|
774
|
+
type: 'insert';
|
|
775
|
+
path: Path$1;
|
|
776
|
+
node: Node$1;
|
|
777
|
+
position: 'before' | 'after';
|
|
778
|
+
inverse?: UnsetOperationData;
|
|
779
|
+
};
|
|
780
|
+
type InsertTextOperation = {
|
|
781
|
+
type: 'insert_text';
|
|
782
|
+
path: Path$1;
|
|
783
|
+
offset: number;
|
|
784
|
+
text: string;
|
|
785
|
+
};
|
|
786
|
+
type RemoveTextOperation = {
|
|
787
|
+
type: 'remove_text';
|
|
788
|
+
path: Path$1;
|
|
789
|
+
offset: number;
|
|
790
|
+
text: string;
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* Data for a `set` inverse (no nested inverse field).
|
|
794
|
+
*/
|
|
795
|
+
type SetOperationData = {
|
|
796
|
+
type: 'set';
|
|
797
|
+
path: Path$1;
|
|
798
|
+
value: unknown;
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* Data for an `insert` inverse (no nested inverse field).
|
|
802
|
+
*/
|
|
803
|
+
type InsertOperationData = {
|
|
804
|
+
type: 'insert';
|
|
805
|
+
path: Path$1;
|
|
806
|
+
node: Node$1;
|
|
807
|
+
position: 'before' | 'after';
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Data for an `unset` inverse (no nested inverse field).
|
|
811
|
+
*/
|
|
812
|
+
type UnsetOperationData = {
|
|
813
|
+
type: 'unset';
|
|
814
|
+
path: Path$1;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Set a property on a node. The path is `[...nodePath, propertyName]`.
|
|
818
|
+
*
|
|
819
|
+
* When `inverse` is provided, the operation can be undone. Remote operations
|
|
820
|
+
* (applied via `withRemoteChanges`) skip the history plugin and do not need
|
|
821
|
+
* inverse data.
|
|
822
|
+
*/
|
|
823
|
+
type SetOperation = {
|
|
824
|
+
type: 'set';
|
|
825
|
+
path: Path$1;
|
|
826
|
+
value: unknown;
|
|
827
|
+
inverse?: SetOperationData | UnsetOperationData;
|
|
828
|
+
};
|
|
829
|
+
/**
|
|
830
|
+
* Remove a property from a node, or remove a node from its parent.
|
|
831
|
+
*
|
|
832
|
+
* Property removal: path is `[...nodePath, propertyName]` (last segment is a string).
|
|
833
|
+
* Node removal: path is `[...parentPath, arrayFieldName, {_key: nodeKey}]`
|
|
834
|
+
* (last segment is a keyed segment pointing to the node to remove).
|
|
835
|
+
*/
|
|
836
|
+
type UnsetOperation = {
|
|
837
|
+
type: 'unset';
|
|
838
|
+
path: Path$1;
|
|
839
|
+
inverse?: SetOperationData | InsertOperationData;
|
|
840
|
+
};
|
|
841
|
+
type SetSelectionOperation = {
|
|
842
|
+
type: 'set_selection';
|
|
843
|
+
properties: null;
|
|
844
|
+
newProperties: Range;
|
|
845
|
+
} | {
|
|
846
|
+
type: 'set_selection';
|
|
847
|
+
properties: Partial<Range>;
|
|
848
|
+
newProperties: Partial<Range>;
|
|
849
|
+
} | {
|
|
850
|
+
type: 'set_selection';
|
|
851
|
+
properties: Range;
|
|
852
|
+
newProperties: null;
|
|
853
|
+
};
|
|
854
|
+
type Operation = InsertOperation | SetOperation | UnsetOperation | SetSelectionOperation | InsertTextOperation | RemoveTextOperation;
|
|
855
|
+
type DecoratedRange = Range & {
|
|
856
|
+
rangeDecoration: RangeDecoration;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* The `Location` interface is a union of the ways to refer to a specific
|
|
860
|
+
* location in a Slate document: paths, points or ranges.
|
|
861
|
+
*
|
|
862
|
+
* Methods will often accept a `Location` instead of requiring only a `Path`,
|
|
863
|
+
* `Point` or `Range`. This eliminates the need for developers to manage
|
|
864
|
+
* converting between the different interfaces in their own code base.
|
|
865
|
+
*/
|
|
866
|
+
type Location = Path$1 | Point | Range;
|
|
867
|
+
/**
|
|
868
|
+
* `PathRef` objects keep a specific path in a document synced over time as new
|
|
869
|
+
* operations are applied to the editor. You can access their `current` property
|
|
870
|
+
* at any time for the up-to-date path value.
|
|
871
|
+
*/
|
|
872
|
+
interface PathRef {
|
|
873
|
+
current: Path$1 | null;
|
|
874
|
+
affinity: 'forward' | 'backward' | null;
|
|
875
|
+
unref(): Path$1 | null;
|
|
876
|
+
}
|
|
877
|
+
interface PathRefInterface {
|
|
878
|
+
transform: (ref: PathRef, op: Operation) => void;
|
|
879
|
+
}
|
|
880
|
+
declare const PathRef: PathRefInterface;
|
|
881
|
+
/**
|
|
882
|
+
* `PointRef` objects keep a specific point in a document synced over time as new
|
|
883
|
+
* operations are applied to the editor. You can access their `current` property
|
|
884
|
+
* at any time for the up-to-date point value.
|
|
885
|
+
*/
|
|
886
|
+
interface PointRef {
|
|
887
|
+
current: Point | null;
|
|
888
|
+
affinity: TextDirection | null;
|
|
889
|
+
unref(): Point | null;
|
|
890
|
+
}
|
|
891
|
+
interface PointRefInterface {
|
|
892
|
+
transform: (ref: PointRef, op: Operation) => void;
|
|
893
|
+
}
|
|
894
|
+
declare const PointRef: PointRefInterface;
|
|
895
|
+
/**
|
|
896
|
+
* `RangeRef` objects keep a specific range in a document synced over time as new
|
|
897
|
+
* operations are applied to the editor. You can access their `current` property
|
|
898
|
+
* at any time for the up-to-date range value.
|
|
899
|
+
*/
|
|
900
|
+
interface RangeRef {
|
|
901
|
+
current: Range | null;
|
|
902
|
+
affinity: 'forward' | 'backward' | 'outward' | 'inward' | null;
|
|
903
|
+
unref(): Range | null;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* The `Editor` interface stores all the state of a Slate editor. It is extended
|
|
907
|
+
* by plugins that wish to add their own helpers and implement new behaviors.
|
|
908
|
+
*/
|
|
909
|
+
interface BaseEditor {
|
|
910
|
+
children: PortableTextBlock[];
|
|
911
|
+
readonly value: PortableTextBlock[];
|
|
912
|
+
selection: EditorSelection;
|
|
913
|
+
operations: Operation[];
|
|
914
|
+
dirtyPaths: Path$1[];
|
|
915
|
+
dirtyPathKeys: Set<string>;
|
|
916
|
+
flushing: boolean;
|
|
917
|
+
normalizing: boolean;
|
|
918
|
+
pathRefs: Set<PathRef>;
|
|
919
|
+
pointRefs: Set<PointRef>;
|
|
920
|
+
rangeRefs: Set<RangeRef>;
|
|
921
|
+
apply: (operation: Operation) => void;
|
|
922
|
+
normalizeNode: (entry: [Editor$1 | Node$1, Path$1], options?: {
|
|
923
|
+
operation?: Operation;
|
|
924
|
+
}) => void;
|
|
925
|
+
onChange: (options?: {
|
|
926
|
+
operation?: Operation;
|
|
927
|
+
}) => void;
|
|
928
|
+
shouldNormalize: ({
|
|
929
|
+
iteration,
|
|
930
|
+
dirtyPaths,
|
|
931
|
+
operation
|
|
932
|
+
}: {
|
|
933
|
+
iteration: number;
|
|
934
|
+
initialDirtyPathsLength: number;
|
|
935
|
+
dirtyPaths: Path$1[];
|
|
936
|
+
operation?: Operation;
|
|
937
|
+
}) => boolean;
|
|
938
|
+
select: (target: Location) => void;
|
|
939
|
+
setSelection: (props: Partial<Range>) => void;
|
|
940
|
+
}
|
|
941
|
+
type Editor$1 = BaseEditor & DOMEditor & PortableTextSlateEditor;
|
|
942
|
+
type StringDiff = {
|
|
943
|
+
start: number;
|
|
944
|
+
end: number;
|
|
945
|
+
text: string;
|
|
946
|
+
};
|
|
947
|
+
type TextDiff = {
|
|
948
|
+
id: number;
|
|
949
|
+
path: Path$1;
|
|
950
|
+
diff: StringDiff;
|
|
951
|
+
};
|
|
952
|
+
/**
|
|
953
|
+
* Types.
|
|
954
|
+
*/
|
|
955
|
+
type DOMNode = globalThis.Node;
|
|
956
|
+
type DOMRange = globalThis.Range;
|
|
957
|
+
type DOMSelection = globalThis.Selection;
|
|
958
|
+
type DOMStaticRange = globalThis.StaticRange;
|
|
959
|
+
declare global {
|
|
960
|
+
interface Window {
|
|
961
|
+
Selection: (typeof Selection)['constructor'];
|
|
962
|
+
DataTransfer: (typeof DataTransfer)['constructor'];
|
|
963
|
+
Node: (typeof Node)['constructor'];
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
type DOMPoint = [Node, number];
|
|
967
|
+
type Action = {
|
|
968
|
+
at?: Point | Range;
|
|
969
|
+
run: () => void;
|
|
970
|
+
};
|
|
971
|
+
/**
|
|
972
|
+
* A DOM-specific version of the `Editor` interface.
|
|
973
|
+
*/
|
|
974
|
+
interface DOMEditor extends BaseEditor {
|
|
975
|
+
hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
976
|
+
hasRange: (editor: Editor$1, range: Range) => boolean;
|
|
977
|
+
hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
978
|
+
hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
979
|
+
isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
980
|
+
isNodeMapDirty: boolean;
|
|
981
|
+
domWindow: Window | null;
|
|
982
|
+
domElement: HTMLElement | null;
|
|
983
|
+
readOnly: boolean;
|
|
984
|
+
focused: boolean;
|
|
985
|
+
composing: boolean;
|
|
986
|
+
userSelection: RangeRef | null;
|
|
987
|
+
onContextChange: ((options?: {
|
|
988
|
+
operation?: Operation;
|
|
989
|
+
}) => void) | null;
|
|
990
|
+
scheduleFlush: (() => void) | null;
|
|
991
|
+
pendingDiffs: TextDiff[];
|
|
992
|
+
pendingAction: Action | null;
|
|
993
|
+
pendingSelection: Range | null;
|
|
994
|
+
forceRender: (() => void) | null;
|
|
995
|
+
}
|
|
996
|
+
interface DOMEditorInterface {
|
|
997
|
+
/**
|
|
998
|
+
* Blur the editor.
|
|
999
|
+
*/
|
|
1000
|
+
blur: (editor: Editor$1) => void;
|
|
1001
|
+
/**
|
|
1002
|
+
* Find the DOM node that implements DocumentOrShadowRoot for the editor.
|
|
1003
|
+
*/
|
|
1004
|
+
findDocumentOrShadowRoot: (editor: Editor$1) => Document | ShadowRoot;
|
|
1005
|
+
/**
|
|
1006
|
+
* Focus the editor.
|
|
1007
|
+
*/
|
|
1008
|
+
focus: (editor: Editor$1, options?: {
|
|
1009
|
+
retries: number;
|
|
1010
|
+
}) => void;
|
|
1011
|
+
/**
|
|
1012
|
+
* Return the host window of the current editor.
|
|
1013
|
+
*/
|
|
1014
|
+
getWindow: (editor: Editor$1) => Window;
|
|
1015
|
+
/**
|
|
1016
|
+
* Check if a DOM node is within the editor.
|
|
1017
|
+
*/
|
|
1018
|
+
hasDOMNode: (editor: Editor$1, target: DOMNode, options?: {
|
|
1019
|
+
editable?: boolean;
|
|
1020
|
+
}) => boolean;
|
|
1021
|
+
/**
|
|
1022
|
+
* Check if the target is editable and in the editor.
|
|
1023
|
+
*/
|
|
1024
|
+
hasEditableTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
1025
|
+
/**
|
|
1195
1026
|
*
|
|
1196
|
-
* @example
|
|
1197
|
-
* ```ts
|
|
1198
|
-
* (rangeComponentProps: PropsWithChildren) => (
|
|
1199
|
-
* <SearchResultHighlight>
|
|
1200
|
-
* {rangeComponentProps.children}
|
|
1201
|
-
* </SearchResultHighlight>
|
|
1202
|
-
* )
|
|
1203
|
-
* ```
|
|
1204
1027
|
*/
|
|
1205
|
-
|
|
1028
|
+
hasRange: (editor: Editor$1, range: Range) => boolean;
|
|
1206
1029
|
/**
|
|
1207
|
-
*
|
|
1030
|
+
* Check if the target can be selectable
|
|
1208
1031
|
*/
|
|
1209
|
-
|
|
1032
|
+
hasSelectableTarget: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
1210
1033
|
/**
|
|
1211
|
-
*
|
|
1034
|
+
* Check if the target is in the editor.
|
|
1212
1035
|
*/
|
|
1213
|
-
|
|
1036
|
+
hasTarget: (editor: Editor$1, target: EventTarget | null) => target is DOMNode;
|
|
1214
1037
|
/**
|
|
1215
|
-
*
|
|
1038
|
+
* Check if the target is inside void and in an non-readonly editor.
|
|
1216
1039
|
*/
|
|
1217
|
-
|
|
1040
|
+
isTargetInsideNonReadonlyVoid: (editor: Editor$1, target: EventTarget | null) => boolean;
|
|
1041
|
+
/**
|
|
1042
|
+
* Find a native DOM selection point from a Slate point.
|
|
1043
|
+
*/
|
|
1044
|
+
toDOMPoint: (editor: Editor$1, point: Point) => DOMPoint;
|
|
1045
|
+
/**
|
|
1046
|
+
* Find a native DOM range from a Slate `range`.
|
|
1047
|
+
*
|
|
1048
|
+
* Notice: the returned range will always be ordinal regardless of the direction of Slate `range` due to DOM API limit.
|
|
1049
|
+
*
|
|
1050
|
+
* there is no way to create a reverse DOM Range using Range.setStart/setEnd
|
|
1051
|
+
* according to https://dom.spec.whatwg.org/#concept-range-bp-set.
|
|
1052
|
+
*/
|
|
1053
|
+
toDOMRange: (editor: Editor$1, range: Range) => DOMRange;
|
|
1054
|
+
/**
|
|
1055
|
+
* Find a Slate point from a DOM selection's `domNode` and `domOffset`.
|
|
1056
|
+
*/
|
|
1057
|
+
toSlatePoint: <T extends boolean>(editor: Editor$1, domPoint: DOMPoint, options: {
|
|
1058
|
+
exactMatch: boolean;
|
|
1059
|
+
suppressThrow: T;
|
|
1060
|
+
/**
|
|
1061
|
+
* The direction to search for Slate leaf nodes if `domPoint` is
|
|
1062
|
+
* non-editable and non-void.
|
|
1063
|
+
*/
|
|
1064
|
+
searchDirection?: 'forward' | 'backward';
|
|
1065
|
+
}) => T extends true ? Point | null : Point;
|
|
1066
|
+
/**
|
|
1067
|
+
* Find a Slate range from a DOM range or selection.
|
|
1068
|
+
*/
|
|
1069
|
+
toSlateRange: <T extends boolean>(editor: Editor$1, domRange: DOMRange | DOMStaticRange | DOMSelection, options: {
|
|
1070
|
+
exactMatch: boolean;
|
|
1071
|
+
suppressThrow: T;
|
|
1072
|
+
}) => T extends true ? Range | null : Range;
|
|
1073
|
+
}
|
|
1074
|
+
declare const DOMEditor: DOMEditorInterface;
|
|
1075
|
+
type HistoryItem = {
|
|
1076
|
+
operations: Operation[];
|
|
1077
|
+
timestamp: Date;
|
|
1078
|
+
};
|
|
1079
|
+
interface History {
|
|
1080
|
+
redos: HistoryItem[];
|
|
1081
|
+
undos: HistoryItem[];
|
|
1082
|
+
}
|
|
1083
|
+
type RemotePatch = {
|
|
1084
|
+
patch: Patch;
|
|
1085
|
+
time: Date;
|
|
1086
|
+
snapshot: PortableTextBlock[] | undefined;
|
|
1087
|
+
previousSnapshot: PortableTextBlock[] | undefined;
|
|
1088
|
+
};
|
|
1089
|
+
interface PortableTextSlateEditor extends DOMEditor {
|
|
1090
|
+
_key: 'editor';
|
|
1091
|
+
_type: 'editor';
|
|
1092
|
+
schema: EditorSchema;
|
|
1093
|
+
keyGenerator: () => string;
|
|
1094
|
+
containers: ResolvedContainers;
|
|
1095
|
+
/**
|
|
1096
|
+
* Narrow {@link Containers} projection of `containers`, exposed on the
|
|
1097
|
+
* public `EditorContext.containers`. Maintained in sync with
|
|
1098
|
+
* `containers` by the editor machine's register/unregister handlers.
|
|
1099
|
+
*/
|
|
1100
|
+
publicContainers: Containers;
|
|
1101
|
+
blockObjects: Map<string, BlockObjectConfig>;
|
|
1102
|
+
inlineObjects: Map<string, InlineObjectConfig>;
|
|
1103
|
+
spans: Map<string, SpanConfig>;
|
|
1104
|
+
textBlocks: Map<string, TextBlockConfig>;
|
|
1105
|
+
/**
|
|
1106
|
+
* Snapshot-shaped view onto the editor's traversal state. Mirrors the
|
|
1107
|
+
* shape of `EditorSnapshot.context`.
|
|
1108
|
+
*/
|
|
1109
|
+
readonly context: {
|
|
1110
|
+
schema: EditorSchema;
|
|
1111
|
+
containers: Containers;
|
|
1112
|
+
value: PortableTextBlock[];
|
|
1113
|
+
keyGenerator: () => string;
|
|
1114
|
+
};
|
|
1115
|
+
decoratedRanges: Array<DecoratedRange>;
|
|
1116
|
+
decoratorState: Record<string, boolean | undefined>;
|
|
1117
|
+
blockIndexMap: Map<string, number>;
|
|
1118
|
+
history: History;
|
|
1119
|
+
listIndexMap: Map<string, number>;
|
|
1120
|
+
remotePatches: Array<RemotePatch>;
|
|
1121
|
+
undoStepId: string | undefined;
|
|
1122
|
+
isDeferringMutations: boolean;
|
|
1123
|
+
isNormalizingNode: boolean;
|
|
1124
|
+
isPatching: boolean;
|
|
1125
|
+
isPerformingBehaviorOperation: boolean;
|
|
1126
|
+
isProcessingRemoteChanges: boolean;
|
|
1127
|
+
isRedoing: boolean;
|
|
1128
|
+
isUndoing: boolean;
|
|
1129
|
+
withHistory: boolean;
|
|
1218
1130
|
}
|
|
1219
1131
|
/**
|
|
1220
1132
|
* @public
|
|
@@ -1226,6 +1138,25 @@ type EditorContext = {
|
|
|
1226
1138
|
schema: EditorSchema;
|
|
1227
1139
|
selection: EditorSelection;
|
|
1228
1140
|
value: Array<PortableTextBlock>;
|
|
1141
|
+
/**
|
|
1142
|
+
* Map of registered editable containers keyed by their bare
|
|
1143
|
+
* block-object `_type` (e.g. `'callout'`, `'table'`).
|
|
1144
|
+
*
|
|
1145
|
+
* Each entry is a {@link RegisteredContainer} carrying `type`,
|
|
1146
|
+
* the array `field` that holds the container's editable children,
|
|
1147
|
+
* and (when present) the nested positional `of` registrations
|
|
1148
|
+
* consulted by {@link resolveContainerAt}. The render callback is
|
|
1149
|
+
* engine-internal and not surfaced here.
|
|
1150
|
+
*
|
|
1151
|
+
* Only top-level registrations appear as flat entries. A `_type`
|
|
1152
|
+
* registered only inside a parent's `of` is reachable through that
|
|
1153
|
+
* parent's `of`, not as a top-level entry. Use
|
|
1154
|
+
* `resolveContainerAt(containers, value, path)` for position-aware
|
|
1155
|
+
* resolution that handles both top-level and positional entries.
|
|
1156
|
+
*
|
|
1157
|
+
* @alpha
|
|
1158
|
+
*/
|
|
1159
|
+
containers: Containers;
|
|
1229
1160
|
};
|
|
1230
1161
|
/**
|
|
1231
1162
|
* @public
|
|
@@ -1282,6 +1213,63 @@ type Behavior<TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*`
|
|
|
1282
1213
|
*
|
|
1283
1214
|
*/
|
|
1284
1215
|
declare function defineBehavior<TPayload extends Record<string, unknown>, TBehaviorEventType extends '*' | `${BehaviorEventTypeNamespace}.*` | BehaviorEvent['type'] = CustomBehaviorEvent['type'], TGuardResponse = true>(behavior: Behavior<TBehaviorEventType, TGuardResponse, ResolveBehaviorEvent<TBehaviorEventType, TPayload>>): Behavior;
|
|
1216
|
+
/**
|
|
1217
|
+
* @public
|
|
1218
|
+
*/
|
|
1219
|
+
type EditorEmittedEvent = {
|
|
1220
|
+
type: 'blurred';
|
|
1221
|
+
event: FocusEvent<HTMLDivElement, Element>;
|
|
1222
|
+
} | {
|
|
1223
|
+
/**
|
|
1224
|
+
* @deprecated Will be removed in the next major version
|
|
1225
|
+
*/
|
|
1226
|
+
type: 'done loading';
|
|
1227
|
+
} | {
|
|
1228
|
+
type: 'editable';
|
|
1229
|
+
} | ErrorEvent | {
|
|
1230
|
+
type: 'focused';
|
|
1231
|
+
event: FocusEvent<HTMLDivElement, Element>;
|
|
1232
|
+
} | {
|
|
1233
|
+
type: 'invalid value';
|
|
1234
|
+
resolution: InvalidValueResolution | null;
|
|
1235
|
+
value: Array<PortableTextBlock> | undefined;
|
|
1236
|
+
} | {
|
|
1237
|
+
/**
|
|
1238
|
+
* @deprecated Will be removed in the next major version
|
|
1239
|
+
*/
|
|
1240
|
+
type: 'loading';
|
|
1241
|
+
} | MutationEvent | PatchEvent | {
|
|
1242
|
+
type: 'read only';
|
|
1243
|
+
} | {
|
|
1244
|
+
type: 'ready';
|
|
1245
|
+
} | {
|
|
1246
|
+
type: 'selection';
|
|
1247
|
+
selection: EditorSelection;
|
|
1248
|
+
} | {
|
|
1249
|
+
type: 'value changed';
|
|
1250
|
+
value: Array<PortableTextBlock> | undefined;
|
|
1251
|
+
};
|
|
1252
|
+
/**
|
|
1253
|
+
* @deprecated The event is no longer emitted
|
|
1254
|
+
*/
|
|
1255
|
+
type ErrorEvent = {
|
|
1256
|
+
type: 'error';
|
|
1257
|
+
name: string;
|
|
1258
|
+
description: string;
|
|
1259
|
+
data: unknown;
|
|
1260
|
+
};
|
|
1261
|
+
/**
|
|
1262
|
+
* @public
|
|
1263
|
+
*/
|
|
1264
|
+
type MutationEvent = {
|
|
1265
|
+
type: 'mutation';
|
|
1266
|
+
patches: Array<Patch>;
|
|
1267
|
+
value: Array<PortableTextBlock> | undefined;
|
|
1268
|
+
};
|
|
1269
|
+
type PatchEvent = {
|
|
1270
|
+
type: 'patch';
|
|
1271
|
+
patch: Patch;
|
|
1272
|
+
};
|
|
1285
1273
|
/**
|
|
1286
1274
|
* @public
|
|
1287
1275
|
*/
|
|
@@ -1313,8 +1301,36 @@ type Editor = {
|
|
|
1313
1301
|
registerBehavior: (config: {
|
|
1314
1302
|
behavior: Behavior;
|
|
1315
1303
|
}) => () => void;
|
|
1304
|
+
/**
|
|
1305
|
+
* Register a node renderer. The `node` argument is the result of one
|
|
1306
|
+
* of the `defineX` factories (`defineContainer`, `defineTextBlock`,
|
|
1307
|
+
* `defineSpan`, `defineBlockObject`, `defineInlineObject`). Returns
|
|
1308
|
+
* a function that unregisters the node when called.
|
|
1309
|
+
*
|
|
1310
|
+
* @alpha
|
|
1311
|
+
*/
|
|
1312
|
+
registerNode: (config: {
|
|
1313
|
+
node: RegistrableNode;
|
|
1314
|
+
}) => () => void;
|
|
1316
1315
|
send: (event: EditorEvent) => void;
|
|
1317
1316
|
on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on'];
|
|
1317
|
+
/**
|
|
1318
|
+
* Subscribe to editor state changes. The observer's `next` callback fires
|
|
1319
|
+
* with the current `EditorSnapshot` on every relevant transition (selection
|
|
1320
|
+
* updates, content mutations, behavior dispatch, configuration changes).
|
|
1321
|
+
*
|
|
1322
|
+
* The editor has no terminal state and no error path, so `error` and
|
|
1323
|
+
* `complete` are part of the observable contract but never fire. They are
|
|
1324
|
+
* kept for structural compatibility with `useSyncExternalStore`,
|
|
1325
|
+
* `@xstate/react`'s `useSelector`, and other observer-shaped consumers.
|
|
1326
|
+
*/
|
|
1327
|
+
subscribe(observer: {
|
|
1328
|
+
next?: (snapshot: EditorSnapshot) => void;
|
|
1329
|
+
error?: (err: unknown) => void;
|
|
1330
|
+
complete?: () => void;
|
|
1331
|
+
}): {
|
|
1332
|
+
unsubscribe: () => void;
|
|
1333
|
+
};
|
|
1318
1334
|
};
|
|
1319
1335
|
/**
|
|
1320
1336
|
* @public
|
|
@@ -1448,10 +1464,15 @@ type EditorActor = ActorRefFrom<typeof editorMachine>;
|
|
|
1448
1464
|
/**
|
|
1449
1465
|
* @internal
|
|
1450
1466
|
*/
|
|
1451
|
-
declare const editorMachine:
|
|
1467
|
+
declare const editorMachine: xstate37.StateMachine<{
|
|
1452
1468
|
behaviors: Set<BehaviorConfig>;
|
|
1453
1469
|
behaviorsSorted: boolean;
|
|
1454
|
-
|
|
1470
|
+
blockObjects: Map<string, BlockObjectConfig>;
|
|
1471
|
+
containers: ResolvedContainers;
|
|
1472
|
+
converters: Array<Converter>;
|
|
1473
|
+
inlineObjects: Map<string, InlineObjectConfig>;
|
|
1474
|
+
spans: Map<string, SpanConfig>;
|
|
1475
|
+
textBlocks: Map<string, TextBlockConfig>;
|
|
1455
1476
|
keyGenerator: () => string;
|
|
1456
1477
|
pendingEvents: Array<InternalPatchEvent | MutationEvent>;
|
|
1457
1478
|
pendingIncomingPatchesEvents: Array<PatchesEvent>;
|
|
@@ -1504,57 +1525,72 @@ declare const editorMachine: xstate73.StateMachine<{
|
|
|
1504
1525
|
type: "dragend";
|
|
1505
1526
|
} | {
|
|
1506
1527
|
type: "drop";
|
|
1528
|
+
} | {
|
|
1529
|
+
type: "register";
|
|
1530
|
+
node: RegistrableNode;
|
|
1531
|
+
} | {
|
|
1532
|
+
type: "unregister";
|
|
1533
|
+
node: RegistrableNode;
|
|
1507
1534
|
} | {
|
|
1508
1535
|
type: "add slate editor";
|
|
1509
1536
|
editor: PortableTextSlateEditor;
|
|
1510
1537
|
}, {}, never, {
|
|
1538
|
+
type: "register";
|
|
1539
|
+
params: xstate37.NonReducibleUnknown;
|
|
1540
|
+
} | {
|
|
1541
|
+
type: "unregister";
|
|
1542
|
+
params: xstate37.NonReducibleUnknown;
|
|
1543
|
+
} | {
|
|
1511
1544
|
type: "add behavior to context";
|
|
1512
|
-
params:
|
|
1545
|
+
params: xstate37.NonReducibleUnknown;
|
|
1513
1546
|
} | {
|
|
1514
1547
|
type: "remove behavior from context";
|
|
1515
|
-
params:
|
|
1548
|
+
params: xstate37.NonReducibleUnknown;
|
|
1516
1549
|
} | {
|
|
1517
1550
|
type: "add slate editor to context";
|
|
1518
|
-
params:
|
|
1551
|
+
params: xstate37.NonReducibleUnknown;
|
|
1552
|
+
} | {
|
|
1553
|
+
type: "attach maps to slate editor";
|
|
1554
|
+
params: unknown;
|
|
1519
1555
|
} | {
|
|
1520
1556
|
type: "emit patch event";
|
|
1521
|
-
params:
|
|
1557
|
+
params: xstate37.NonReducibleUnknown;
|
|
1522
1558
|
} | {
|
|
1523
1559
|
type: "emit mutation event";
|
|
1524
|
-
params:
|
|
1560
|
+
params: xstate37.NonReducibleUnknown;
|
|
1525
1561
|
} | {
|
|
1526
1562
|
type: "emit read only";
|
|
1527
|
-
params:
|
|
1563
|
+
params: xstate37.NonReducibleUnknown;
|
|
1528
1564
|
} | {
|
|
1529
1565
|
type: "emit editable";
|
|
1530
|
-
params:
|
|
1566
|
+
params: xstate37.NonReducibleUnknown;
|
|
1531
1567
|
} | {
|
|
1532
1568
|
type: "defer event";
|
|
1533
|
-
params:
|
|
1569
|
+
params: xstate37.NonReducibleUnknown;
|
|
1534
1570
|
} | {
|
|
1535
1571
|
type: "emit pending events";
|
|
1536
|
-
params:
|
|
1572
|
+
params: xstate37.NonReducibleUnknown;
|
|
1537
1573
|
} | {
|
|
1538
1574
|
type: "emit ready";
|
|
1539
|
-
params:
|
|
1575
|
+
params: xstate37.NonReducibleUnknown;
|
|
1540
1576
|
} | {
|
|
1541
1577
|
type: "clear pending events";
|
|
1542
|
-
params:
|
|
1578
|
+
params: xstate37.NonReducibleUnknown;
|
|
1543
1579
|
} | {
|
|
1544
1580
|
type: "discard conflicting pending patches";
|
|
1545
|
-
params:
|
|
1581
|
+
params: xstate37.NonReducibleUnknown;
|
|
1546
1582
|
} | {
|
|
1547
1583
|
type: "discard all pending events";
|
|
1548
|
-
params:
|
|
1584
|
+
params: xstate37.NonReducibleUnknown;
|
|
1549
1585
|
} | {
|
|
1550
1586
|
type: "defer incoming patches";
|
|
1551
|
-
params:
|
|
1587
|
+
params: xstate37.NonReducibleUnknown;
|
|
1552
1588
|
} | {
|
|
1553
1589
|
type: "emit pending incoming patches";
|
|
1554
|
-
params:
|
|
1590
|
+
params: xstate37.NonReducibleUnknown;
|
|
1555
1591
|
} | {
|
|
1556
1592
|
type: "clear pending incoming patches";
|
|
1557
|
-
params:
|
|
1593
|
+
params: xstate37.NonReducibleUnknown;
|
|
1558
1594
|
} | {
|
|
1559
1595
|
type: "handle blur";
|
|
1560
1596
|
params: unknown;
|
|
@@ -1566,7 +1602,7 @@ declare const editorMachine: xstate73.StateMachine<{
|
|
|
1566
1602
|
params: unknown;
|
|
1567
1603
|
} | {
|
|
1568
1604
|
type: "sort behaviors";
|
|
1569
|
-
params:
|
|
1605
|
+
params: xstate37.NonReducibleUnknown;
|
|
1570
1606
|
}, {
|
|
1571
1607
|
type: "slate is busy";
|
|
1572
1608
|
params: unknown;
|
|
@@ -1595,7 +1631,7 @@ declare const editorMachine: xstate73.StateMachine<{
|
|
|
1595
1631
|
readOnly?: boolean;
|
|
1596
1632
|
schema: EditorSchema;
|
|
1597
1633
|
initialValue?: Array<PortableTextBlock>;
|
|
1598
|
-
},
|
|
1634
|
+
}, xstate37.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1599
1635
|
type: "blurred";
|
|
1600
1636
|
event: react4.FocusEvent<HTMLDivElement, Element>;
|
|
1601
1637
|
} | {
|
|
@@ -1626,7 +1662,7 @@ declare const editorMachine: xstate73.StateMachine<{
|
|
|
1626
1662
|
} | {
|
|
1627
1663
|
type: "value changed";
|
|
1628
1664
|
value: Array<PortableTextBlock> | undefined;
|
|
1629
|
-
},
|
|
1665
|
+
}, xstate37.MetaObject, {
|
|
1630
1666
|
id: "editor";
|
|
1631
1667
|
states: {
|
|
1632
1668
|
readonly 'edit mode': {
|
|
@@ -1681,9 +1717,16 @@ declare const editorMachine: xstate73.StateMachine<{
|
|
|
1681
1717
|
type EventPosition = {
|
|
1682
1718
|
block: 'start' | 'end';
|
|
1683
1719
|
/**
|
|
1684
|
-
* Did the event
|
|
1720
|
+
* Did the event originate from the editor root DOM node itself, rather than
|
|
1721
|
+
* from a block inside the editor?
|
|
1685
1722
|
*/
|
|
1686
1723
|
isEditor: boolean;
|
|
1724
|
+
/**
|
|
1725
|
+
* Did the event originate from an editable container's DOM node itself (for
|
|
1726
|
+
* example a code block or a table cell), rather than from a block inside the
|
|
1727
|
+
* container?
|
|
1728
|
+
*/
|
|
1729
|
+
isContainer: boolean;
|
|
1687
1730
|
selection: NonNullable<EditorSelection>;
|
|
1688
1731
|
};
|
|
1689
1732
|
type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
|
@@ -1725,7 +1768,7 @@ type ExternalBehaviorEvent = {
|
|
|
1725
1768
|
/**************************************
|
|
1726
1769
|
* Synthetic events
|
|
1727
1770
|
**************************************/
|
|
1728
|
-
declare const syntheticBehaviorEventTypes: readonly ["annotation.add", "annotation.remove", "block.set", "block.unset", "child.set", "child.unset", "decorator.add", "decorator.remove", "delete", "history.redo", "history.undo", "insert.block", "insert.child", "insert.text", "move.backward", "move.block", "move.forward", "select"];
|
|
1771
|
+
declare const syntheticBehaviorEventTypes: readonly ["annotation.add", "annotation.remove", "block.set", "block.unset", "child.set", "child.unset", "decorator.add", "decorator.remove", "delete", "history.redo", "history.undo", "insert", "insert.block", "insert.child", "insert.text", "move.backward", "move.block", "move.forward", "remove.text", "select", "set", "unset"];
|
|
1729
1772
|
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number] | (typeof abstractBehaviorEventTypes)[number];
|
|
1730
1773
|
type SyntheticBehaviorEventNamespace = ExtractNamespace<SyntheticBehaviorEventType>;
|
|
1731
1774
|
/**
|
|
@@ -1788,6 +1831,33 @@ type SyntheticBehaviorEvent = {
|
|
|
1788
1831
|
type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>;
|
|
1789
1832
|
} | {
|
|
1790
1833
|
type: StrictExtract<SyntheticBehaviorEventType, 'history.undo'>;
|
|
1834
|
+
} | {
|
|
1835
|
+
/**
|
|
1836
|
+
* @alpha
|
|
1837
|
+
*
|
|
1838
|
+
* Primitive: insert a node into an array.
|
|
1839
|
+
*
|
|
1840
|
+
* The last segment of `at` resolves the insertion point:
|
|
1841
|
+
* - A keyed `{_key}` segment inserts relative to that sibling.
|
|
1842
|
+
* - A numeric index inserts relative to that slot.
|
|
1843
|
+
*
|
|
1844
|
+
* `position` ('before' or 'after') is always meaningful: `before: [2]`
|
|
1845
|
+
* inserts at index 2, `after: [2]` inserts at index 3.
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* ```ts
|
|
1849
|
+
* raise({
|
|
1850
|
+
* type: 'insert',
|
|
1851
|
+
* at: [{_key: 'list'}, 'items', {_key: 'item3'}],
|
|
1852
|
+
* value: newItem,
|
|
1853
|
+
* position: 'after',
|
|
1854
|
+
* })
|
|
1855
|
+
* ```
|
|
1856
|
+
*/
|
|
1857
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert'>;
|
|
1858
|
+
at: Path;
|
|
1859
|
+
value: PortableTextTextBlock | PortableTextObject | PortableTextSpan;
|
|
1860
|
+
position: 'before' | 'after';
|
|
1791
1861
|
} | {
|
|
1792
1862
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>;
|
|
1793
1863
|
block: BlockWithOptionalKey;
|
|
@@ -1798,7 +1868,33 @@ type SyntheticBehaviorEvent = {
|
|
|
1798
1868
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.child'>;
|
|
1799
1869
|
child: ChildWithOptionalKey;
|
|
1800
1870
|
} | {
|
|
1871
|
+
/**
|
|
1872
|
+
* Inserts text into a span.
|
|
1873
|
+
*
|
|
1874
|
+
* Without `at`/`offset`, text is inserted at the current caret position.
|
|
1875
|
+
* This is the form used by typing handlers.
|
|
1876
|
+
*
|
|
1877
|
+
* @alpha
|
|
1878
|
+
* With `at` and `offset`, text is inserted at the explicit position.
|
|
1879
|
+
* Recommended for plugin behaviors and collaborative-edit contexts.
|
|
1880
|
+
*
|
|
1881
|
+
* @example
|
|
1882
|
+
* ```ts
|
|
1883
|
+
* // Caret form
|
|
1884
|
+
* raise({type: 'insert.text', text: 'x'})
|
|
1885
|
+
*
|
|
1886
|
+
* // Primitive form (@alpha)
|
|
1887
|
+
* raise({
|
|
1888
|
+
* type: 'insert.text',
|
|
1889
|
+
* at: [{_key: 'b1'}, 'children', {_key: 's1'}],
|
|
1890
|
+
* offset: 5,
|
|
1891
|
+
* text: 'world',
|
|
1892
|
+
* })
|
|
1893
|
+
* ```
|
|
1894
|
+
*/
|
|
1801
1895
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>;
|
|
1896
|
+
at?: Path;
|
|
1897
|
+
offset?: number;
|
|
1802
1898
|
text: string;
|
|
1803
1899
|
} | {
|
|
1804
1900
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>;
|
|
@@ -1810,9 +1906,84 @@ type SyntheticBehaviorEvent = {
|
|
|
1810
1906
|
} | {
|
|
1811
1907
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>;
|
|
1812
1908
|
distance: number;
|
|
1909
|
+
} | {
|
|
1910
|
+
/**
|
|
1911
|
+
* @alpha
|
|
1912
|
+
*
|
|
1913
|
+
* Primitive: remove text from a span at the given offset.
|
|
1914
|
+
*
|
|
1915
|
+
* The `text` field carries the exact text being removed (matches the
|
|
1916
|
+
* apply-layer shape so the inverse can be computed without re-reading
|
|
1917
|
+
* the span).
|
|
1918
|
+
*
|
|
1919
|
+
* Recommended for collaborative-edit contexts (concurrent edits compose
|
|
1920
|
+
* cleanly under operational transform).
|
|
1921
|
+
*
|
|
1922
|
+
* @example
|
|
1923
|
+
* ```ts
|
|
1924
|
+
* raise({
|
|
1925
|
+
* type: 'remove.text',
|
|
1926
|
+
* at: [{_key: 'b1'}, 'children', {_key: 's1'}],
|
|
1927
|
+
* offset: 5,
|
|
1928
|
+
* text: 'world',
|
|
1929
|
+
* })
|
|
1930
|
+
* ```
|
|
1931
|
+
*/
|
|
1932
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'remove.text'>;
|
|
1933
|
+
at: Path;
|
|
1934
|
+
offset: number;
|
|
1935
|
+
text: string;
|
|
1813
1936
|
} | {
|
|
1814
1937
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>;
|
|
1815
1938
|
at: EditorSelection;
|
|
1939
|
+
} | {
|
|
1940
|
+
/**
|
|
1941
|
+
* @alpha
|
|
1942
|
+
*
|
|
1943
|
+
* Primitive: set a property on a node, or replace a node wholesale.
|
|
1944
|
+
*
|
|
1945
|
+
* The last segment of `at` is the property name (a string) for property
|
|
1946
|
+
* updates, OR a keyed/indexed segment for full-node replacement.
|
|
1947
|
+
*
|
|
1948
|
+
* Note: `set` on span text (`{at: [...spanPath, 'text'], value: '...'}`)
|
|
1949
|
+
* is legal but not recommended in collaborative-edit contexts. Use
|
|
1950
|
+
* `insert.text` and `remove.text` for text edits that compose under
|
|
1951
|
+
* operational transform.
|
|
1952
|
+
*
|
|
1953
|
+
* @example
|
|
1954
|
+
* ```ts
|
|
1955
|
+
* // Set a block's style
|
|
1956
|
+
* raise({type: 'set', at: [{_key: 'b1'}, 'style'], value: 'h1'})
|
|
1957
|
+
*
|
|
1958
|
+
* // Replace a block wholesale
|
|
1959
|
+
* raise({type: 'set', at: [{_key: 'b1'}], value: newBlock})
|
|
1960
|
+
* ```
|
|
1961
|
+
*/
|
|
1962
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'set'>;
|
|
1963
|
+
at: Path;
|
|
1964
|
+
value: unknown;
|
|
1965
|
+
} | {
|
|
1966
|
+
/**
|
|
1967
|
+
* @alpha
|
|
1968
|
+
*
|
|
1969
|
+
* Primitive: unset a property on an object, OR remove a node from an
|
|
1970
|
+
* array.
|
|
1971
|
+
*
|
|
1972
|
+
* When the last segment of `at` is a string, the property is removed.
|
|
1973
|
+
* When the last segment is a keyed `{_key}` segment or a numeric index,
|
|
1974
|
+
* the node at that array position is removed.
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```ts
|
|
1978
|
+
* // Remove a property
|
|
1979
|
+
* raise({type: 'unset', at: [{_key: 'b1'}, 'level']})
|
|
1980
|
+
*
|
|
1981
|
+
* // Remove a node from an array
|
|
1982
|
+
* raise({type: 'unset', at: [{_key: 'list'}, 'items', {_key: 'item3'}]})
|
|
1983
|
+
* ```
|
|
1984
|
+
*/
|
|
1985
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'unset'>;
|
|
1986
|
+
at: Path;
|
|
1816
1987
|
} | AbstractBehaviorEvent;
|
|
1817
1988
|
/**
|
|
1818
1989
|
* @beta
|
|
@@ -2275,5 +2446,5 @@ type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
2275
2446
|
event: TBehaviorEvent;
|
|
2276
2447
|
dom: EditorDom;
|
|
2277
2448
|
}, guardResponse: TGuardResponse) => Array<BehaviorAction>;
|
|
2278
|
-
export {
|
|
2449
|
+
export { EditorSnapshot as $, PortableTextTextBlock$1 as A, PortableTextEditor as At, EditorSelector as B, ListDefinition as C, RenderListItemFunction as Ct, PortableTextChild$1 as D, PortableTextEditable as Dt, PortableTextBlock$1 as E, ScrollSelectionIntoViewFunction as Et, BlockOffset as F, EditorConfig as G, EditorProvider as H, useEditor as I, MutationEvent as J, EditorEvent as K, defaultKeyGenerator as L, StyleDefinition as M, StyleSchemaType$1 as N, PortableTextObject$1 as O, PortableTextEditableProps as Ot, defineSchema as P, EditorContext as Q, usePortableTextEditorSelection as R, InlineObjectSchemaType$1 as S, RenderEditableFunction as St, Patch$1 as T, RenderStyleFunction as Tt, EditorProviderProps as U, useEditorSelector as V, Editor as W, defineBehavior as X, Behavior as Y, BehaviorGuard as Z, BlockObjectSchemaType$1 as _, RangeDecorationOnMovedDetails as _t, forward as a, BlockRenderProps as at, FieldDefinition$1 as b, RenderChildFunction as bt, CustomBehaviorEvent as c, EditorSelection as ct, SyntheticBehaviorEvent as d, OnCopyFn as dt, AddedAnnotationPaths as et, PatchesEvent as f, OnPasteFn as ft, BlockObjectDefinition as g, RangeDecoration as gt, BaseDefinition as h, PasteData as ht, execute as i, BlockListItemRenderProps as it, SchemaDefinition$1 as j, PortableTextSpan$1 as k, HotkeyOptions as kt, InsertPlacement as l, EditorSelectionPoint as lt, AnnotationSchemaType$1 as m, OnPasteResultOrPromise as mt, BehaviorActionSet as n, BlockChildRenderProps as nt, raise as o, BlockStyleRenderProps as ot, AnnotationDefinition as p, OnPasteResult as pt, EditorEmittedEvent as q, effect as r, BlockDecoratorRenderProps as rt, BehaviorEvent as s, EditableAPIDeleteOptions as st, BehaviorAction as t, BlockAnnotationRenderProps as tt, NativeBehaviorEvent as u, InvalidValueResolution as ut, DecoratorDefinition as v, RenderAnnotationFunction as vt, ListSchemaType$1 as w, RenderPlaceholderFunction as wt, InlineObjectDefinition as x, RenderDecoratorFunction as xt, DecoratorSchemaType$1 as y, RenderBlockFunction as yt, usePortableTextEditor as z };
|
|
2279
2450
|
//# sourceMappingURL=behavior.types.action.d.ts.map
|