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 | shouldMergeNodesRemovePrevNode: OmitFirstArg<typeof Editor.shouldMergeNodesRemovePrevNode>;
|
116 | }
|
117 | export type Editor = ExtendedType<'Editor', BaseEditor>;
|
118 | export type BaseSelection = Range | null;
|
119 | export type Selection = ExtendedType<'Selection', BaseSelection>;
|
120 | export type EditorMarks = Omit<Text, 'text'>;
|
121 | export interface EditorAboveOptions<T extends Ancestor> {
|
122 | at?: Location;
|
123 | match?: NodeMatch<T>;
|
124 | mode?: MaximizeMode;
|
125 | voids?: boolean;
|
126 | }
|
127 | export interface EditorAfterOptions {
|
128 | distance?: number;
|
129 | unit?: TextUnitAdjustment;
|
130 | voids?: boolean;
|
131 | }
|
132 | export interface EditorBeforeOptions {
|
133 | distance?: number;
|
134 | unit?: TextUnitAdjustment;
|
135 | voids?: boolean;
|
136 | }
|
137 | export interface EditorDirectedDeletionOptions {
|
138 | unit?: TextUnit;
|
139 | }
|
140 | export interface EditorElementReadOnlyOptions {
|
141 | at?: Location;
|
142 | mode?: MaximizeMode;
|
143 | voids?: boolean;
|
144 | }
|
145 | export interface EditorFragmentDeletionOptions {
|
146 | direction?: TextDirection;
|
147 | }
|
148 | export interface EditorLeafOptions {
|
149 | depth?: number;
|
150 | edge?: LeafEdge;
|
151 | }
|
152 | export interface EditorLevelsOptions<T extends Node> {
|
153 | at?: Location;
|
154 | match?: NodeMatch<T>;
|
155 | reverse?: boolean;
|
156 | voids?: boolean;
|
157 | }
|
158 | export interface EditorNextOptions<T extends Descendant> {
|
159 | at?: Location;
|
160 | match?: NodeMatch<T>;
|
161 | mode?: SelectionMode;
|
162 | voids?: boolean;
|
163 | }
|
164 | export interface EditorNodeOptions {
|
165 | depth?: number;
|
166 | edge?: LeafEdge;
|
167 | }
|
168 | export interface EditorNodesOptions<T extends Node> {
|
169 | at?: Location | Span;
|
170 | match?: NodeMatch<T>;
|
171 | mode?: SelectionMode;
|
172 | universal?: boolean;
|
173 | reverse?: boolean;
|
174 | voids?: boolean;
|
175 | ignoreNonSelectable?: boolean;
|
176 | }
|
177 | export interface EditorNormalizeOptions {
|
178 | force?: boolean;
|
179 | operation?: Operation;
|
180 | }
|
181 | export interface EditorParentOptions {
|
182 | depth?: number;
|
183 | edge?: LeafEdge;
|
184 | }
|
185 | export interface EditorPathOptions {
|
186 | depth?: number;
|
187 | edge?: LeafEdge;
|
188 | }
|
189 | export interface EditorPathRefOptions {
|
190 | affinity?: TextDirection | null;
|
191 | }
|
192 | export interface EditorPointOptions {
|
193 | edge?: LeafEdge;
|
194 | }
|
195 | export interface EditorPointRefOptions {
|
196 | affinity?: TextDirection | null;
|
197 | }
|
198 | export interface EditorPositionsOptions {
|
199 | at?: Location;
|
200 | unit?: TextUnitAdjustment;
|
201 | reverse?: boolean;
|
202 | voids?: boolean;
|
203 | ignoreNonSelectable?: boolean;
|
204 | }
|
205 | export interface EditorPreviousOptions<T extends Node> {
|
206 | at?: Location;
|
207 | match?: NodeMatch<T>;
|
208 | mode?: SelectionMode;
|
209 | voids?: boolean;
|
210 | }
|
211 | export interface EditorRangeRefOptions {
|
212 | affinity?: RangeDirection | null;
|
213 | }
|
214 | export interface EditorStringOptions {
|
215 | voids?: boolean;
|
216 | }
|
217 | export interface EditorUnhangRangeOptions {
|
218 | voids?: boolean;
|
219 | }
|
220 | export interface EditorVoidOptions {
|
221 | at?: Location;
|
222 | mode?: MaximizeMode;
|
223 | voids?: boolean;
|
224 | }
|
225 | export interface EditorInterface {
|
226 | |
227 |
|
228 |
|
229 | above: <T extends Ancestor>(editor: Editor, options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | addMark: (editor: Editor, key: string, value: any) => void;
|
237 | |
238 |
|
239 |
|
240 | after: (editor: Editor, at: Location, options?: EditorAfterOptions) => Point | undefined;
|
241 | |
242 |
|
243 |
|
244 | before: (editor: Editor, at: Location, options?: EditorBeforeOptions) => Point | undefined;
|
245 | |
246 |
|
247 |
|
248 | deleteBackward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;
|
249 | |
250 |
|
251 |
|
252 | deleteForward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;
|
253 | |
254 |
|
255 |
|
256 | deleteFragment: (editor: Editor, options?: EditorFragmentDeletionOptions) => void;
|
257 | |
258 |
|
259 |
|
260 | edges: (editor: Editor, at: Location) => [Point, Point];
|
261 | |
262 |
|
263 |
|
264 | elementReadOnly: (editor: Editor, options?: EditorElementReadOnlyOptions) => NodeEntry<Element> | undefined;
|
265 | |
266 |
|
267 |
|
268 | end: (editor: Editor, at: Location) => Point;
|
269 | |
270 |
|
271 |
|
272 | first: (editor: Editor, at: Location) => NodeEntry;
|
273 | |
274 |
|
275 |
|
276 | fragment: (editor: Editor, at: Location) => Descendant[];
|
277 | |
278 |
|
279 |
|
280 | hasBlocks: (editor: Editor, element: Element) => boolean;
|
281 | |
282 |
|
283 |
|
284 | hasInlines: (editor: Editor, element: Element) => boolean;
|
285 | hasPath: (editor: Editor, path: Path) => boolean;
|
286 | |
287 |
|
288 |
|
289 | hasTexts: (editor: Editor, element: Element) => boolean;
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 | insertBreak: (editor: Editor) => void;
|
296 | |
297 |
|
298 |
|
299 |
|
300 | insertFragment: (editor: Editor, fragment: Node[], options?: TextInsertFragmentOptions) => void;
|
301 | |
302 |
|
303 |
|
304 |
|
305 | insertNode: <T extends Node>(editor: Editor, node: Node, options?: NodeInsertNodesOptions<T>) => void;
|
306 | |
307 |
|
308 |
|
309 |
|
310 |
|
311 | insertSoftBreak: (editor: Editor) => void;
|
312 | |
313 |
|
314 |
|
315 |
|
316 | insertText: (editor: Editor, text: string, options?: TextInsertTextOptions) => void;
|
317 | |
318 |
|
319 |
|
320 | isBlock: (editor: Editor, value: Element) => boolean;
|
321 | |
322 |
|
323 |
|
324 | isEdge: (editor: Editor, point: Point, at: Location) => boolean;
|
325 | |
326 |
|
327 |
|
328 | isEditor: (value: any) => value is Editor;
|
329 | |
330 |
|
331 |
|
332 | isElementReadOnly: (editor: Editor, element: Element) => boolean;
|
333 | |
334 |
|
335 |
|
336 | isEmpty: (editor: Editor, element: Element) => boolean;
|
337 | |
338 |
|
339 |
|
340 | isEnd: (editor: Editor, point: Point, at: Location) => boolean;
|
341 | |
342 |
|
343 |
|
344 | isInline: (editor: Editor, value: Element) => boolean;
|
345 | |
346 |
|
347 |
|
348 | isNormalizing: (editor: Editor) => boolean;
|
349 | |
350 |
|
351 |
|
352 | isSelectable: (editor: Editor, element: Element) => boolean;
|
353 | |
354 |
|
355 |
|
356 | isStart: (editor: Editor, point: Point, at: Location) => boolean;
|
357 | |
358 |
|
359 |
|
360 | isVoid: (editor: Editor, value: Element) => boolean;
|
361 | |
362 |
|
363 |
|
364 | last: (editor: Editor, at: Location) => NodeEntry;
|
365 | |
366 |
|
367 |
|
368 | leaf: (editor: Editor, at: Location, options?: EditorLeafOptions) => NodeEntry<Text>;
|
369 | |
370 |
|
371 |
|
372 | levels: <T extends Node>(editor: Editor, options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
373 | |
374 |
|
375 |
|
376 | marks: (editor: Editor) => Omit<Text, 'text'> | null;
|
377 | |
378 |
|
379 |
|
380 | next: <T extends Descendant>(editor: Editor, options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;
|
381 | |
382 |
|
383 |
|
384 | node: (editor: Editor, at: Location, options?: EditorNodeOptions) => NodeEntry;
|
385 | |
386 |
|
387 |
|
388 | nodes: <T extends Node>(editor: Editor, options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;
|
389 | |
390 |
|
391 |
|
392 | normalize: (editor: Editor, options?: EditorNormalizeOptions) => void;
|
393 | |
394 |
|
395 |
|
396 | parent: (editor: Editor, at: Location, options?: EditorParentOptions) => NodeEntry<Ancestor>;
|
397 | |
398 |
|
399 |
|
400 | path: (editor: Editor, at: Location, options?: EditorPathOptions) => Path;
|
401 | |
402 |
|
403 |
|
404 |
|
405 | pathRef: (editor: Editor, path: Path, options?: EditorPathRefOptions) => PathRef;
|
406 | |
407 |
|
408 |
|
409 | pathRefs: (editor: Editor) => Set<PathRef>;
|
410 | |
411 |
|
412 |
|
413 | point: (editor: Editor, at: Location, options?: EditorPointOptions) => Point;
|
414 | |
415 |
|
416 |
|
417 |
|
418 | pointRef: (editor: Editor, point: Point, options?: EditorPointRefOptions) => PointRef;
|
419 | |
420 |
|
421 |
|
422 | pointRefs: (editor: Editor) => Set<PointRef>;
|
423 | |
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 | positions: (editor: Editor, options?: EditorPositionsOptions) => Generator<Point, void, undefined>;
|
436 | |
437 |
|
438 |
|
439 | previous: <T extends Node>(editor: Editor, options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;
|
440 | |
441 |
|
442 |
|
443 | range: (editor: Editor, at: Location, to?: Location) => Range;
|
444 | |
445 |
|
446 |
|
447 |
|
448 | rangeRef: (editor: Editor, range: Range, options?: EditorRangeRefOptions) => RangeRef;
|
449 | |
450 |
|
451 |
|
452 | rangeRefs: (editor: Editor) => Set<RangeRef>;
|
453 | |
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 | removeMark: (editor: Editor, key: string) => void;
|
461 | |
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | setNormalizing: (editor: Editor, isNormalizing: boolean) => void;
|
468 | |
469 |
|
470 |
|
471 | start: (editor: Editor, at: Location) => Point;
|
472 | |
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 | string: (editor: Editor, at: Location, options?: EditorStringOptions) => string;
|
479 | |
480 |
|
481 |
|
482 | unhangRange: (editor: Editor, range: Range, options?: EditorUnhangRangeOptions) => Range;
|
483 | |
484 |
|
485 |
|
486 | void: (editor: Editor, options?: EditorVoidOptions) => NodeEntry<Element> | undefined;
|
487 | |
488 |
|
489 |
|
490 | withoutNormalizing: (editor: Editor, fn: () => void) => void;
|
491 | |
492 |
|
493 |
|
494 | shouldMergeNodesRemovePrevNode: (editor: Editor, prevNodeEntry: NodeEntry, curNodeEntry: NodeEntry) => boolean;
|
495 | }
|
496 | export declare const Editor: EditorInterface;
|
497 |
|
498 |
|
499 |
|
500 | export type NodeMatch<T extends Node> = ((node: Node, path: Path) => node is T) | ((node: Node, path: Path) => boolean);
|
501 | export type PropsCompare = (prop: Partial<Node>, node: Partial<Node>) => boolean;
|
502 | export type PropsMerge = (prop: Partial<Node>, node: Partial<Node>) => object;
|
503 |
|
\ | No newline at end of file |