1 | import { Ancestor, Descendant, Element, ExtendedType, Location, Node, NodeEntry, Operation, Path, PathRef, Point, PointRef, Range, RangeRef, Span, Text, Transforms } from '..';
|
2 | import { LeafEdge, MaximizeMode, RangeDirection, SelectionMode, TextDirection, TextUnit, TextUnitAdjustment } from '../types/types';
|
3 | import { OmitFirstArg } from '../utils/types';
|
4 | import { TextInsertFragmentOptions, TextInsertTextOptions } from './transforms/text';
|
5 | import { NodeInsertNodesOptions } from './transforms/node';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export interface BaseEditor {
|
11 | children: Descendant[];
|
12 | selection: Selection;
|
13 | operations: Operation[];
|
14 | marks: EditorMarks | null;
|
15 | apply: (operation: Operation) => void;
|
16 | getDirtyPaths: (operation: Operation) => Path[];
|
17 | getFragment: () => Descendant[];
|
18 | isElementReadOnly: (element: Element) => boolean;
|
19 | isSelectable: (element: Element) => boolean;
|
20 | markableVoid: (element: Element) => boolean;
|
21 | normalizeNode: (entry: NodeEntry, options?: {
|
22 | operation?: Operation;
|
23 | }) => void;
|
24 | onChange: (options?: {
|
25 | operation?: Operation;
|
26 | }) => void;
|
27 | shouldNormalize: ({ iteration, dirtyPaths, operation, }: {
|
28 | iteration: number;
|
29 | initialDirtyPathsLength: number;
|
30 | dirtyPaths: Path[];
|
31 | operation?: Operation;
|
32 | }) => boolean;
|
33 | addMark: OmitFirstArg<typeof Editor.addMark>;
|
34 | collapse: OmitFirstArg<typeof Transforms.collapse>;
|
35 | delete: OmitFirstArg<typeof Transforms.delete>;
|
36 | deleteBackward: (unit: TextUnit) => void;
|
37 | deleteForward: (unit: TextUnit) => void;
|
38 | deleteFragment: OmitFirstArg<typeof Editor.deleteFragment>;
|
39 | deselect: OmitFirstArg<typeof Transforms.deselect>;
|
40 | insertBreak: OmitFirstArg<typeof Editor.insertBreak>;
|
41 | insertFragment: OmitFirstArg<typeof Transforms.insertFragment>;
|
42 | insertNode: OmitFirstArg<typeof Editor.insertNode>;
|
43 | insertNodes: OmitFirstArg<typeof Transforms.insertNodes>;
|
44 | insertSoftBreak: OmitFirstArg<typeof Editor.insertSoftBreak>;
|
45 | insertText: OmitFirstArg<typeof Transforms.insertText>;
|
46 | liftNodes: OmitFirstArg<typeof Transforms.liftNodes>;
|
47 | mergeNodes: OmitFirstArg<typeof Transforms.mergeNodes>;
|
48 | move: OmitFirstArg<typeof Transforms.move>;
|
49 | moveNodes: OmitFirstArg<typeof Transforms.moveNodes>;
|
50 | normalize: OmitFirstArg<typeof Editor.normalize>;
|
51 | removeMark: OmitFirstArg<typeof Editor.removeMark>;
|
52 | removeNodes: OmitFirstArg<typeof Transforms.removeNodes>;
|
53 | select: OmitFirstArg<typeof Transforms.select>;
|
54 | setNodes: <T extends Node>(props: Partial<T>, options?: {
|
55 | at?: Location;
|
56 | match?: NodeMatch<T>;
|
57 | mode?: MaximizeMode;
|
58 | hanging?: boolean;
|
59 | split?: boolean;
|
60 | voids?: boolean;
|
61 | compare?: PropsCompare;
|
62 | merge?: PropsMerge;
|
63 | }) => void;
|
64 | setNormalizing: OmitFirstArg<typeof Editor.setNormalizing>;
|
65 | setPoint: OmitFirstArg<typeof Transforms.setPoint>;
|
66 | setSelection: OmitFirstArg<typeof Transforms.setSelection>;
|
67 | splitNodes: OmitFirstArg<typeof Transforms.splitNodes>;
|
68 | unsetNodes: OmitFirstArg<typeof Transforms.unsetNodes>;
|
69 | unwrapNodes: OmitFirstArg<typeof Transforms.unwrapNodes>;
|
70 | withoutNormalizing: OmitFirstArg<typeof Editor.withoutNormalizing>;
|
71 | wrapNodes: OmitFirstArg<typeof Transforms.wrapNodes>;
|
72 | above: <T extends Ancestor>(options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;
|
73 | after: OmitFirstArg<typeof Editor.after>;
|
74 | before: OmitFirstArg<typeof Editor.before>;
|
75 | edges: OmitFirstArg<typeof Editor.edges>;
|
76 | elementReadOnly: OmitFirstArg<typeof Editor.elementReadOnly>;
|
77 | end: OmitFirstArg<typeof Editor.end>;
|
78 | first: OmitFirstArg<typeof Editor.first>;
|
79 | fragment: OmitFirstArg<typeof Editor.fragment>;
|
80 | getMarks: OmitFirstArg<typeof Editor.marks>;
|
81 | hasBlocks: OmitFirstArg<typeof Editor.hasBlocks>;
|
82 | hasInlines: OmitFirstArg<typeof Editor.hasInlines>;
|
83 | hasPath: OmitFirstArg<typeof Editor.hasPath>;
|
84 | hasTexts: OmitFirstArg<typeof Editor.hasTexts>;
|
85 | isBlock: OmitFirstArg<typeof Editor.isBlock>;
|
86 | isEdge: OmitFirstArg<typeof Editor.isEdge>;
|
87 | isEmpty: OmitFirstArg<typeof Editor.isEmpty>;
|
88 | isEnd: OmitFirstArg<typeof Editor.isEnd>;
|
89 | isInline: OmitFirstArg<typeof Editor.isInline>;
|
90 | isNormalizing: OmitFirstArg<typeof Editor.isNormalizing>;
|
91 | isStart: OmitFirstArg<typeof Editor.isStart>;
|
92 | isVoid: OmitFirstArg<typeof Editor.isVoid>;
|
93 | last: OmitFirstArg<typeof Editor.last>;
|
94 | leaf: OmitFirstArg<typeof Editor.leaf>;
|
95 | levels: <T extends Node>(options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
96 | next: <T extends Descendant>(options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;
|
97 | node: OmitFirstArg<typeof Editor.node>;
|
98 | nodes: <T extends Node>(options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
99 | parent: OmitFirstArg<typeof Editor.parent>;
|
100 | path: OmitFirstArg<typeof Editor.path>;
|
101 | pathRef: OmitFirstArg<typeof Editor.pathRef>;
|
102 | pathRefs: OmitFirstArg<typeof Editor.pathRefs>;
|
103 | point: OmitFirstArg<typeof Editor.point>;
|
104 | pointRef: OmitFirstArg<typeof Editor.pointRef>;
|
105 | pointRefs: OmitFirstArg<typeof Editor.pointRefs>;
|
106 | positions: OmitFirstArg<typeof Editor.positions>;
|
107 | previous: <T extends Node>(options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;
|
108 | range: OmitFirstArg<typeof Editor.range>;
|
109 | rangeRef: OmitFirstArg<typeof Editor.rangeRef>;
|
110 | rangeRefs: OmitFirstArg<typeof Editor.rangeRefs>;
|
111 | start: OmitFirstArg<typeof Editor.start>;
|
112 | string: OmitFirstArg<typeof Editor.string>;
|
113 | unhangRange: OmitFirstArg<typeof Editor.unhangRange>;
|
114 | void: OmitFirstArg<typeof Editor.void>;
|
115 | }
|
116 | export type Editor = ExtendedType<'Editor', BaseEditor>;
|
117 | export type BaseSelection = Range | null;
|
118 | export type Selection = ExtendedType<'Selection', BaseSelection>;
|
119 | export type EditorMarks = Omit<Text, 'text'>;
|
120 | export interface EditorAboveOptions<T extends Ancestor> {
|
121 | at?: Location;
|
122 | match?: NodeMatch<T>;
|
123 | mode?: MaximizeMode;
|
124 | voids?: boolean;
|
125 | }
|
126 | export interface EditorAfterOptions {
|
127 | distance?: number;
|
128 | unit?: TextUnitAdjustment;
|
129 | voids?: boolean;
|
130 | }
|
131 | export interface EditorBeforeOptions {
|
132 | distance?: number;
|
133 | unit?: TextUnitAdjustment;
|
134 | voids?: boolean;
|
135 | }
|
136 | export interface EditorDirectedDeletionOptions {
|
137 | unit?: TextUnit;
|
138 | }
|
139 | export interface EditorElementReadOnlyOptions {
|
140 | at?: Location;
|
141 | mode?: MaximizeMode;
|
142 | voids?: boolean;
|
143 | }
|
144 | export interface EditorFragmentDeletionOptions {
|
145 | direction?: TextDirection;
|
146 | }
|
147 | export interface EditorLeafOptions {
|
148 | depth?: number;
|
149 | edge?: LeafEdge;
|
150 | }
|
151 | export interface EditorLevelsOptions<T extends Node> {
|
152 | at?: Location;
|
153 | match?: NodeMatch<T>;
|
154 | reverse?: boolean;
|
155 | voids?: boolean;
|
156 | }
|
157 | export interface EditorNextOptions<T extends Descendant> {
|
158 | at?: Location;
|
159 | match?: NodeMatch<T>;
|
160 | mode?: SelectionMode;
|
161 | voids?: boolean;
|
162 | }
|
163 | export interface EditorNodeOptions {
|
164 | depth?: number;
|
165 | edge?: LeafEdge;
|
166 | }
|
167 | export interface EditorNodesOptions<T extends Node> {
|
168 | at?: Location | Span;
|
169 | match?: NodeMatch<T>;
|
170 | mode?: SelectionMode;
|
171 | universal?: boolean;
|
172 | reverse?: boolean;
|
173 | voids?: boolean;
|
174 | ignoreNonSelectable?: boolean;
|
175 | }
|
176 | export interface EditorNormalizeOptions {
|
177 | force?: boolean;
|
178 | operation?: Operation;
|
179 | }
|
180 | export interface EditorParentOptions {
|
181 | depth?: number;
|
182 | edge?: LeafEdge;
|
183 | }
|
184 | export interface EditorPathOptions {
|
185 | depth?: number;
|
186 | edge?: LeafEdge;
|
187 | }
|
188 | export interface EditorPathRefOptions {
|
189 | affinity?: TextDirection | null;
|
190 | }
|
191 | export interface EditorPointOptions {
|
192 | edge?: LeafEdge;
|
193 | }
|
194 | export interface EditorPointRefOptions {
|
195 | affinity?: TextDirection | null;
|
196 | }
|
197 | export interface EditorPositionsOptions {
|
198 | at?: Location;
|
199 | unit?: TextUnitAdjustment;
|
200 | reverse?: boolean;
|
201 | voids?: boolean;
|
202 | ignoreNonSelectable?: boolean;
|
203 | }
|
204 | export interface EditorPreviousOptions<T extends Node> {
|
205 | at?: Location;
|
206 | match?: NodeMatch<T>;
|
207 | mode?: SelectionMode;
|
208 | voids?: boolean;
|
209 | }
|
210 | export interface EditorRangeRefOptions {
|
211 | affinity?: RangeDirection | null;
|
212 | }
|
213 | export interface EditorStringOptions {
|
214 | voids?: boolean;
|
215 | }
|
216 | export interface EditorUnhangRangeOptions {
|
217 | voids?: boolean;
|
218 | }
|
219 | export interface EditorVoidOptions {
|
220 | at?: Location;
|
221 | mode?: MaximizeMode;
|
222 | voids?: boolean;
|
223 | }
|
224 | export interface EditorInterface {
|
225 | |
226 |
|
227 |
|
228 | above: <T extends Ancestor>(editor: Editor, options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;
|
229 | |
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | addMark: (editor: Editor, key: string, value: any) => void;
|
236 | |
237 |
|
238 |
|
239 | after: (editor: Editor, at: Location, options?: EditorAfterOptions) => Point | undefined;
|
240 | |
241 |
|
242 |
|
243 | before: (editor: Editor, at: Location, options?: EditorBeforeOptions) => Point | undefined;
|
244 | |
245 |
|
246 |
|
247 | deleteBackward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;
|
248 | |
249 |
|
250 |
|
251 | deleteForward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;
|
252 | |
253 |
|
254 |
|
255 | deleteFragment: (editor: Editor, options?: EditorFragmentDeletionOptions) => void;
|
256 | |
257 |
|
258 |
|
259 | edges: (editor: Editor, at: Location) => [Point, Point];
|
260 | |
261 |
|
262 |
|
263 | elementReadOnly: (editor: Editor, options?: EditorElementReadOnlyOptions) => NodeEntry<Element> | undefined;
|
264 | |
265 |
|
266 |
|
267 | end: (editor: Editor, at: Location) => Point;
|
268 | |
269 |
|
270 |
|
271 | first: (editor: Editor, at: Location) => NodeEntry;
|
272 | |
273 |
|
274 |
|
275 | fragment: (editor: Editor, at: Location) => Descendant[];
|
276 | |
277 |
|
278 |
|
279 | hasBlocks: (editor: Editor, element: Element) => boolean;
|
280 | |
281 |
|
282 |
|
283 | hasInlines: (editor: Editor, element: Element) => boolean;
|
284 | hasPath: (editor: Editor, path: Path) => boolean;
|
285 | |
286 |
|
287 |
|
288 | hasTexts: (editor: Editor, element: Element) => boolean;
|
289 | |
290 |
|
291 |
|
292 |
|
293 |
|
294 | insertBreak: (editor: Editor) => void;
|
295 | |
296 |
|
297 |
|
298 |
|
299 | insertFragment: (editor: Editor, fragment: Node[], options?: TextInsertFragmentOptions) => void;
|
300 | |
301 |
|
302 |
|
303 |
|
304 | insertNode: <T extends Node>(editor: Editor, node: Node, options?: NodeInsertNodesOptions<T>) => void;
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 | insertSoftBreak: (editor: Editor) => void;
|
311 | |
312 |
|
313 |
|
314 |
|
315 | insertText: (editor: Editor, text: string, options?: TextInsertTextOptions) => void;
|
316 | |
317 |
|
318 |
|
319 | isBlock: (editor: Editor, value: Element) => boolean;
|
320 | |
321 |
|
322 |
|
323 | isEdge: (editor: Editor, point: Point, at: Location) => boolean;
|
324 | |
325 |
|
326 |
|
327 | isEditor: (value: any) => value is Editor;
|
328 | |
329 |
|
330 |
|
331 | isElementReadOnly: (editor: Editor, element: Element) => boolean;
|
332 | |
333 |
|
334 |
|
335 | isEmpty: (editor: Editor, element: Element) => boolean;
|
336 | |
337 |
|
338 |
|
339 | isEnd: (editor: Editor, point: Point, at: Location) => boolean;
|
340 | |
341 |
|
342 |
|
343 | isInline: (editor: Editor, value: Element) => boolean;
|
344 | |
345 |
|
346 |
|
347 | isNormalizing: (editor: Editor) => boolean;
|
348 | |
349 |
|
350 |
|
351 | isSelectable: (editor: Editor, element: Element) => boolean;
|
352 | |
353 |
|
354 |
|
355 | isStart: (editor: Editor, point: Point, at: Location) => boolean;
|
356 | |
357 |
|
358 |
|
359 | isVoid: (editor: Editor, value: Element) => boolean;
|
360 | |
361 |
|
362 |
|
363 | last: (editor: Editor, at: Location) => NodeEntry;
|
364 | |
365 |
|
366 |
|
367 | leaf: (editor: Editor, at: Location, options?: EditorLeafOptions) => NodeEntry<Text>;
|
368 | |
369 |
|
370 |
|
371 | levels: <T extends Node>(editor: Editor, options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
372 | |
373 |
|
374 |
|
375 | marks: (editor: Editor) => Omit<Text, 'text'> | null;
|
376 | |
377 |
|
378 |
|
379 | next: <T extends Descendant>(editor: Editor, options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;
|
380 | |
381 |
|
382 |
|
383 | node: (editor: Editor, at: Location, options?: EditorNodeOptions) => NodeEntry;
|
384 | |
385 |
|
386 |
|
387 | nodes: <T extends Node>(editor: Editor, options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
388 | |
389 |
|
390 |
|
391 | normalize: (editor: Editor, options?: EditorNormalizeOptions) => void;
|
392 | |
393 |
|
394 |
|
395 | parent: (editor: Editor, at: Location, options?: EditorParentOptions) => NodeEntry<Ancestor>;
|
396 | |
397 |
|
398 |
|
399 | path: (editor: Editor, at: Location, options?: EditorPathOptions) => Path;
|
400 | |
401 |
|
402 |
|
403 |
|
404 | pathRef: (editor: Editor, path: Path, options?: EditorPathRefOptions) => PathRef;
|
405 | |
406 |
|
407 |
|
408 | pathRefs: (editor: Editor) => Set<PathRef>;
|
409 | |
410 |
|
411 |
|
412 | point: (editor: Editor, at: Location, options?: EditorPointOptions) => Point;
|
413 | |
414 |
|
415 |
|
416 |
|
417 | pointRef: (editor: Editor, point: Point, options?: EditorPointRefOptions) => PointRef;
|
418 | |
419 |
|
420 |
|
421 | pointRefs: (editor: Editor) => Set<PointRef>;
|
422 | |
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 | positions: (editor: Editor, options?: EditorPositionsOptions) => Generator<Point, void, undefined>;
|
435 | |
436 |
|
437 |
|
438 | previous: <T extends Node>(editor: Editor, options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;
|
439 | |
440 |
|
441 |
|
442 | range: (editor: Editor, at: Location, to?: Location) => Range;
|
443 | |
444 |
|
445 |
|
446 |
|
447 | rangeRef: (editor: Editor, range: Range, options?: EditorRangeRefOptions) => RangeRef;
|
448 | |
449 |
|
450 |
|
451 | rangeRefs: (editor: Editor) => Set<RangeRef>;
|
452 | |
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 | removeMark: (editor: Editor, key: string) => void;
|
460 | |
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | setNormalizing: (editor: Editor, isNormalizing: boolean) => void;
|
467 | |
468 |
|
469 |
|
470 | start: (editor: Editor, at: Location) => Point;
|
471 | |
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 | string: (editor: Editor, at: Location, options?: EditorStringOptions) => string;
|
478 | |
479 |
|
480 |
|
481 | unhangRange: (editor: Editor, range: Range, options?: EditorUnhangRangeOptions) => Range;
|
482 | |
483 |
|
484 |
|
485 | void: (editor: Editor, options?: EditorVoidOptions) => NodeEntry<Element> | undefined;
|
486 | |
487 |
|
488 |
|
489 | withoutNormalizing: (editor: Editor, fn: () => void) => void;
|
490 | }
|
491 | export declare const Editor: EditorInterface;
|
492 |
|
493 |
|
494 |
|
495 | export type NodeMatch<T extends Node> = ((node: Node, path: Path) => node is T) | ((node: Node, path: Path) => boolean);
|
496 | export type PropsCompare = (prop: Partial<Node>, node: Partial<Node>) => boolean;
|
497 | export type PropsMerge = (prop: Partial<Node>, node: Partial<Node>) => object;
|
498 |
|
\ | No newline at end of file |