1 | import * as Immutable from "immutable";
|
2 | import * as React from "react";
|
3 |
|
4 | type SyntheticClipboardEvent = React.ClipboardEvent<{}>;
|
5 | type SyntheticKeyboardEvent = React.KeyboardEvent<{}>;
|
6 | type SyntheticEvent = React.SyntheticEvent<{}>;
|
7 | export as namespace Draft;
|
8 | declare namespace Draft {
|
9 | namespace Component {
|
10 | namespace Base {
|
11 | import DraftEditorCommand = Draft.Model.Constants.DraftEditorCommand;
|
12 | import DraftBlockType = Draft.Model.Constants.DraftBlockType;
|
13 | import DraftDragType = Draft.Model.Constants.DraftDragType;
|
14 | import DraftHandleValue = Draft.Model.Constants.DraftHandleValue;
|
15 |
|
16 | import EditorState = Draft.Model.ImmutableData.EditorState;
|
17 | import ContentBlock = Draft.Model.ImmutableData.ContentBlock;
|
18 | import SelectionState = Draft.Model.ImmutableData.SelectionState;
|
19 | import DraftInlineStyle = Draft.Model.ImmutableData.DraftInlineStyle;
|
20 |
|
21 | import DraftBlockRenderConfig = Draft.Model.ImmutableData.DraftBlockRenderConfig;
|
22 |
|
23 | type DraftBlockRenderMap = Immutable.Map<DraftBlockType, DraftBlockRenderConfig>;
|
24 |
|
25 | type DraftStyleMap = {
|
26 | [styleName: string]: React.CSSProperties;
|
27 | };
|
28 |
|
29 | type EditorCommand = DraftEditorCommand | string;
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 | class DraftEditor extends React.Component<DraftEditorProps, {}> {
|
37 | editor: HTMLElement | null | undefined;
|
38 | editorContainer: HTMLElement | null | undefined;
|
39 | getEditorKey(): string;
|
40 |
|
41 |
|
42 | focus(): void;
|
43 |
|
44 | blur(): void;
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | export interface DraftEditorProps {
|
58 | editorState: EditorState;
|
59 | onChange(editorState: EditorState): void;
|
60 |
|
61 | placeholder?: string | undefined;
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 | textAlignment?: DraftTextAlignment | undefined;
|
68 |
|
69 | |
70 |
|
71 |
|
72 |
|
73 | textDirectionality?: DraftTextDirectionality | undefined;
|
74 |
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 | blockRendererFn?(block: ContentBlock): any;
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | blockRenderMap?: DraftBlockRenderMap | undefined;
|
88 |
|
89 | |
90 |
|
91 |
|
92 | blockStyleFn?(block: ContentBlock): string;
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 | customStyleMap?: DraftStyleMap | undefined;
|
99 |
|
100 | |
101 |
|
102 |
|
103 |
|
104 | customStyleFn?: ((style: DraftInlineStyle, block: ContentBlock) => React.CSSProperties) | undefined;
|
105 |
|
106 | /**
|
107 | * A function that accepts a synthetic key event and returns
|
108 | * the matching DraftEditorCommand constant, or null if no command should
|
109 | * be invoked.
|
110 | */
|
111 | keyBindingFn?(e: SyntheticKeyboardEvent): EditorCommand | null;
|
112 |
|
113 | /**
|
114 | * Set whether the `DraftEditor` component should be editable. Useful for
|
115 | * temporarily disabling edit behavior or allowing `DraftEditor` rendering
|
116 | * to be used for consumption purposes.
|
117 | */
|
118 | readOnly?: boolean | undefined;
|
119 |
|
120 | /**
|
121 | * Note: spellcheck is always disabled for IE. If enabled in Safari, OSX
|
122 | * autocorrect is enabled as well.
|
123 | */
|
124 | spellCheck?: boolean | undefined;
|
125 |
|
126 | /**
|
127 | * When the Editor loses focus (blurs) text selections are cleared
|
128 | * by default to mimic <textarea> behaviour, however in some situations
|
129 | * users may wish to preserve native behaviour.
|
130 | */
|
131 | preserveSelectionOnBlur?: boolean | undefined;
|
132 |
|
133 | /**
|
134 | * Set whether to remove all style information from pasted content. If your
|
135 | * use case should not have any block or inline styles, it is recommended
|
136 | * that you set this to `true`.
|
137 | */
|
138 | stripPastedStyles?: boolean | undefined;
|
139 | formatPastedText?:
|
140 | | ((text: string, html?: string) => { text: string; html: string | undefined })
|
141 | | undefined;
|
142 |
|
143 | tabIndex?: number | undefined;
|
144 |
|
145 | // exposed especially to help improve mobile web behaviors
|
146 | autoCapitalize?: string | undefined;
|
147 | autoComplete?: string | undefined;
|
148 | autoCorrect?: string | undefined;
|
149 |
|
150 | ariaActiveDescendantID?: string | undefined;
|
151 | ariaAutoComplete?: string | undefined;
|
152 | ariaControls?: string | undefined;
|
153 | ariaDescribedBy?: string | undefined;
|
154 | ariaExpanded?: boolean | undefined;
|
155 | ariaLabel?: string | undefined;
|
156 | ariaLabelledBy?: string | undefined;
|
157 | ariaMultiline?: boolean | undefined;
|
158 | ariaOwneeID?: string | undefined;
|
159 |
|
160 | role?: string | undefined;
|
161 |
|
162 | webDriverTestID?: string | undefined;
|
163 |
|
164 | /**
|
165 | * If using server-side rendering, this prop is required to be set to
|
166 | * avoid client/server mismatches.
|
167 | */
|
168 | editorKey?: string | undefined;
|
169 |
|
170 | // Cancelable event handlers, handled from the top level down. A handler
|
171 | // that returns `handled` will be the last handler to execute for that event.
|
172 |
|
173 | /**
|
174 | * Useful for managing special behavior for pressing the `Return` key. E.g.
|
175 | * removing the style from an empty list item.
|
176 | */
|
177 | handleReturn?(e: SyntheticKeyboardEvent, editorState: EditorState): DraftHandleValue;
|
178 |
|
179 | /**
|
180 | * Map a key command string provided by your key binding function to a
|
181 | * specified behavior.
|
182 | */
|
183 | handleKeyCommand?(
|
184 | command: EditorCommand,
|
185 | editorState: EditorState,
|
186 | eventTimeStamp: number,
|
187 | ): DraftHandleValue;
|
188 |
|
189 | /**
|
190 | * Handle intended text insertion before the insertion occurs. This may be
|
191 | * useful in cases where the user has entered characters that you would like
|
192 | * to trigger some special behavior. E.g. immediately converting `:)` to an
|
193 | * emoji Unicode character, or replacing ASCII quote characters with smart
|
194 | * quotes.
|
195 | */
|
196 | handleBeforeInput?(chars: string, editorState: EditorState, eventTimeStamp: number): DraftHandleValue;
|
197 |
|
198 | handlePastedText?(text: string, html: string | undefined, editorState: EditorState): DraftHandleValue;
|
199 |
|
200 | handlePastedFiles?(files: Blob[]): DraftHandleValue;
|
201 |
|
202 | /** Handle dropped files */
|
203 | handleDroppedFiles?(selection: SelectionState, files: Blob[]): DraftHandleValue;
|
204 |
|
205 | /** Handle other drops to prevent default text movement/insertion behaviour */
|
206 | handleDrop?(
|
207 | selection: SelectionState,
|
208 | dataTransfer: Object,
|
209 | isInternal: DraftDragType,
|
210 | ): DraftHandleValue;
|
211 |
|
212 | // Non-cancelable event triggers.
|
213 | onEscape?(e: SyntheticKeyboardEvent): void;
|
214 | onTab?(e: SyntheticKeyboardEvent): void;
|
215 | onUpArrow?(e: SyntheticKeyboardEvent): void;
|
216 | onDownArrow?(e: SyntheticKeyboardEvent): void;
|
217 | onRightArrow?(e: SyntheticKeyboardEvent): void;
|
218 | onLeftArrow?(e: SyntheticKeyboardEvent): void;
|
219 |
|
220 | onBlur?(e: SyntheticEvent): void;
|
221 | onFocus?(e: SyntheticEvent): void;
|
222 | onCopy?(editor: Editor, e: SyntheticClipboardEvent): void;
|
223 | onCut?(editor: Editor, e: SyntheticClipboardEvent): void;
|
224 | }
|
225 |
|
226 | type DraftTextAlignment = "left" | "center" | "right";
|
227 |
|
228 | type DraftTextDirectionality = "LTR" | "RTL" | "NEUTRAL";
|
229 | }
|
230 |
|
231 | namespace Components {
|
232 | class DraftEditorBlock extends React.Component<any, {}> {}
|
233 | }
|
234 |
|
235 | namespace Selection {
|
236 | interface FakeClientRect {
|
237 | left: number;
|
238 | width: number;
|
239 | right: number;
|
240 | top: number;
|
241 | bottom: number;
|
242 | height: number;
|
243 | }
|
244 |
|
245 | /**
|
246 | * Return the bounding ClientRect for the visible DOM selection, if any.
|
247 | * In cases where there are no selected ranges or the bounding rect is
|
248 | * temporarily invalid, return null.
|
249 | */
|
250 | function getVisibleSelectionRect(global: any): FakeClientRect;
|
251 | }
|
252 |
|
253 | namespace Utils {
|
254 | import DraftEditorCommand = Draft.Model.Constants.DraftEditorCommand;
|
255 |
|
256 | class KeyBindingUtil {
|
257 | /**
|
258 | * Check whether the ctrlKey modifier is *not* being used in conjunction with
|
259 | * the altKey modifier. If they are combined, the result is an `altGraph`
|
260 | * key modifier, which should not be handled by this set of key bindings.
|
261 | */
|
262 | static isCtrlKeyCommand(e: SyntheticKeyboardEvent): boolean;
|
263 |
|
264 | static isOptionKeyCommand(e: SyntheticKeyboardEvent): boolean;
|
265 |
|
266 | static hasCommandModifier(e: SyntheticKeyboardEvent): boolean;
|
267 |
|
268 | static isSoftNewlineEvent(e: SyntheticKeyboardEvent): boolean;
|
269 |
|
270 | /**
|
271 | * Check whether heuristics that only apply to macOS are used
|
272 | * internally, for example when determining the key combination
|
273 | * used as command modifier.
|
274 | */
|
275 | static usesMacOSHeuristics(): boolean;
|
276 | }
|
277 |
|
278 | /**
|
279 | * Retrieve a bound key command for the given event.
|
280 | */
|
281 | function getDefaultKeyBinding(e: SyntheticKeyboardEvent): DraftEditorCommand | null;
|
282 | }
|
283 | }
|
284 |
|
285 | namespace Model {
|
286 | namespace Constants {
|
287 | /**
|
288 | * A set of editor commands that may be invoked by keyboard commands or UI
|
289 | * controls. These commands should map to operations that modify content or
|
290 | * selection state and update the editor state accordingly.
|
291 | */
|
292 | type DraftEditorCommand =
|
293 | /**
|
294 | * Self-explanatory.
|
295 | */
|
296 | | "undo"
|
297 | | "redo"
|
298 | /**
|
299 | * Perform a forward deletion.
|
300 | */
|
301 | | "delete"
|
302 | /**
|
303 | * Perform a forward deletion to the next word boundary after the selection.
|
304 | */
|
305 | | "delete-word"
|
306 | /**
|
307 | * Perform a backward deletion.
|
308 | */
|
309 | | "backspace"
|
310 | /**
|
311 | * Perform a backward deletion to the previous word boundary before the
|
312 | * selection.
|
313 | */
|
314 | | "backspace-word"
|
315 | /**
|
316 | * Perform a backward deletion to the beginning of the current line.
|
317 | */
|
318 | | "backspace-to-start-of-line"
|
319 | /**
|
320 | * Toggle styles. Commands may be intepreted to modify inline text ranges
|
321 | * or block types.
|
322 | */
|
323 | | "bold"
|
324 | | "code"
|
325 | | "italic"
|
326 | | "strikethrough"
|
327 | | "underline"
|
328 | /**
|
329 | * Split a block in two.
|
330 | */
|
331 | | "split-block"
|
332 | /**
|
333 | * Self-explanatory.
|
334 | */
|
335 | | "transpose-characters"
|
336 | | "move-selection-to-start-of-block"
|
337 | | "move-selection-to-end-of-block"
|
338 | /**
|
339 | * Commands to support the "secondary" clipboard provided by certain
|
340 | * browsers and operating systems.
|
341 | */
|
342 | | "secondary-cut"
|
343 | | "secondary-paste";
|
344 |
|
345 | /**
|
346 | * A type that allows us to avoid passing boolean arguments
|
347 | * around to indicate whether a drag type is internal or external.
|
348 | */
|
349 | type DraftDragType = "internal" | "external";
|
350 |
|
351 | /**
|
352 | * The list of [default valid block types](https:
|
353 | * according to the [`DefaultDraftBlockRenderMap`](https:
|
354 | */
|
355 | type CoreDraftBlockType =
|
356 | | "header-one"
|
357 | | "header-two"
|
358 | | "header-three"
|
359 | | "header-four"
|
360 | | "header-five"
|
361 | | "header-six"
|
362 | | "section"
|
363 | | "article"
|
364 | | "unordered-list-item"
|
365 | | "ordered-list-item"
|
366 | | "blockquote"
|
367 | | "atomic"
|
368 | | "code-block"
|
369 | | "unstyled";
|
370 |
|
371 | type CustomBlockType = string;
|
372 |
|
373 | type DraftBlockType = CoreDraftBlockType | CustomBlockType;
|
374 |
|
375 | |
376 |
|
377 |
|
378 |
|
379 | type DraftRemovalDirection = "backward" | "forward";
|
380 |
|
381 | |
382 |
|
383 |
|
384 |
|
385 | type DraftHandleValue = "handled" | "not-handled";
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 | type DraftInsertionType = "replace" | "before" | "after";
|
392 |
|
393 | |
394 |
|
395 |
|
396 | type DraftInlineStyleType = "BOLD" | "CODE" | "ITALIC" | "STRIKETHROUGH" | "UNDERLINE";
|
397 |
|
398 | |
399 |
|
400 |
|
401 | type DraftEntityType = string;
|
402 |
|
403 | |
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 | type DraftEntityMutability = "MUTABLE" | "IMMUTABLE" | "SEGMENTED";
|
430 | }
|
431 |
|
432 | namespace Decorators {
|
433 | import ContentBlock = Draft.Model.ImmutableData.ContentBlock;
|
434 |
|
435 | |
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 | interface DraftDecoratorType {
|
442 | |
443 |
|
444 |
|
445 | getDecorations(block: ContentBlock, contentState: ContentState): Immutable.List<string>;
|
446 |
|
447 | |
448 |
|
449 |
|
450 |
|
451 | getComponentForKey(key: string): Function;
|
452 |
|
453 | |
454 |
|
455 |
|
456 |
|
457 | getPropsForKey(key: string): any;
|
458 | }
|
459 |
|
460 | |
461 |
|
462 |
|
463 |
|
464 |
|
465 | interface DraftDecoratorComponentProps {
|
466 | blockKey: string;
|
467 | children?: React.ReactNode[];
|
468 | contentState: ContentState;
|
469 | decoratedText: string;
|
470 | dir: "ltr" | "rtl" | undefined;
|
471 | end: number;
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | entityKey: string | undefined;
|
480 | offsetKey: string;
|
481 | start: number;
|
482 | }
|
483 |
|
484 | |
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 | interface DraftDecorator<P = any> {
|
501 | strategy: (
|
502 | block: ContentBlock,
|
503 | callback: (start: number, end: number) => void,
|
504 | contentState: ContentState,
|
505 | ) => void;
|
506 | component:
|
507 | | React.Component
|
508 | | React.ComponentClass<any>
|
509 | | ((props: DraftDecoratorComponentProps & P) => React.ReactNode);
|
510 | props?: P | undefined;
|
511 | }
|
512 |
|
513 | |
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 | class CompositeDraftDecorator {
|
533 | constructor(decorators: DraftDecorator[]);
|
534 |
|
535 | getDecorations(block: ContentBlock, contentState: ContentState): Immutable.List<string>;
|
536 | getComponentForKey(key: string): Function;
|
537 | getPropsForKey(key: string): Object;
|
538 | }
|
539 | }
|
540 |
|
541 | namespace Encoding {
|
542 | import DraftInlineStyleType = Draft.Model.Constants.DraftInlineStyleType;
|
543 | import DraftBlockType = Draft.Model.Constants.DraftBlockType;
|
544 | import DraftEntityMutability = Draft.Model.Constants.DraftEntityMutability;
|
545 | import DraftEntityType = Draft.Model.Constants.DraftEntityType;
|
546 |
|
547 | import ContentBlock = Draft.Model.ImmutableData.ContentBlock;
|
548 | import ContentState = Draft.Model.ImmutableData.ContentState;
|
549 |
|
550 | import DraftBlockRenderMap = Draft.Component.Base.DraftBlockRenderMap;
|
551 |
|
552 | |
553 |
|
554 |
|
555 | interface RawDraftInlineStyleRange {
|
556 | style: DraftInlineStyleType;
|
557 | offset: number;
|
558 | length: number;
|
559 | }
|
560 |
|
561 | |
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 | interface RawDraftEntityRange {
|
568 | key: number;
|
569 | offset: number;
|
570 | length: number;
|
571 | }
|
572 |
|
573 | |
574 |
|
575 |
|
576 | interface RawDraftEntity<T = { [key: string]: any }> {
|
577 | type: DraftEntityType;
|
578 | mutability: DraftEntityMutability;
|
579 | data: T;
|
580 | }
|
581 |
|
582 | |
583 |
|
584 |
|
585 |
|
586 | interface RawDraftContentBlock {
|
587 | key: string;
|
588 | type: DraftBlockType;
|
589 | text: string;
|
590 | depth: number;
|
591 | inlineStyleRanges: RawDraftInlineStyleRange[];
|
592 | entityRanges: RawDraftEntityRange[];
|
593 | data?: { [key: string]: any } | undefined;
|
594 | }
|
595 |
|
596 | |
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 | interface RawDraftContentState {
|
606 | blocks: RawDraftContentBlock[];
|
607 | entityMap: { [key: string]: RawDraftEntity };
|
608 | }
|
609 |
|
610 | function convertFromHTMLtoContentBlocks(
|
611 | html: string,
|
612 | DOMBuilder?: Function,
|
613 | blockRenderMap?: DraftBlockRenderMap,
|
614 | ): { contentBlocks: ContentBlock[]; entityMap: any };
|
615 | function convertFromRawToDraftState(rawState: RawDraftContentState): ContentState;
|
616 | function convertFromDraftStateToRaw(contentState: ContentState): RawDraftContentState;
|
617 | }
|
618 |
|
619 | namespace Entity {
|
620 | import DraftEntityMutability = Draft.Model.Constants.DraftEntityMutability;
|
621 | import DraftEntityType = Draft.Model.Constants.DraftEntityType;
|
622 |
|
623 | |
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 | class DraftEntity {
|
637 | |
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 | static create(type: DraftEntityType, mutability: DraftEntityMutability, data?: Object): string;
|
645 |
|
646 | |
647 |
|
648 |
|
649 |
|
650 | static add(instance: DraftEntityInstance): string;
|
651 |
|
652 | |
653 |
|
654 |
|
655 | static get(key: string): DraftEntityInstance;
|
656 |
|
657 | |
658 |
|
659 |
|
660 |
|
661 |
|
662 | static mergeData(key: string, toMerge: { [key: string]: any }): DraftEntityInstance;
|
663 |
|
664 | |
665 |
|
666 |
|
667 | static replaceData(key: string, newData: { [key: string]: any }): DraftEntityInstance;
|
668 | }
|
669 |
|
670 | |
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 | interface DraftEntityInstance {
|
682 | getType(): DraftEntityType;
|
683 | getMutability(): DraftEntityMutability;
|
684 | getData(): any;
|
685 | }
|
686 | }
|
687 |
|
688 | namespace ImmutableData {
|
689 | import DraftBlockType = Draft.Model.Constants.DraftBlockType;
|
690 | import DraftEntityMutability = Draft.Model.Constants.DraftEntityMutability;
|
691 | import DraftEntityType = Draft.Model.Constants.DraftEntityType;
|
692 | import DraftEntityInstance = Draft.Model.Entity.DraftEntityInstance;
|
693 |
|
694 | import DraftDecoratorType = Draft.Model.Decorators.DraftDecoratorType;
|
695 |
|
696 | type DraftInlineStyle = Immutable.OrderedSet<string>;
|
697 | type BlockMap = Immutable.OrderedMap<string, Draft.Model.ImmutableData.ContentBlock>;
|
698 |
|
699 | var Record: Immutable.Record.Class;
|
700 |
|
701 | interface DraftBlockRenderConfig {
|
702 | element: string;
|
703 | wrapper?: React.ReactNode | undefined;
|
704 | }
|
705 |
|
706 | class EditorState extends Record {
|
707 | static createEmpty(decorator?: DraftDecoratorType): EditorState;
|
708 | static createWithContent(contentState: ContentState, decorator?: DraftDecoratorType): EditorState;
|
709 | static create(config: Object): EditorState;
|
710 | static set(editorState: EditorState, put: Object): EditorState;
|
711 |
|
712 | |
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 | static acceptSelection(editorState: EditorState, selection: SelectionState): EditorState;
|
721 |
|
722 | |
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 | static forceSelection(editorState: EditorState, selection: SelectionState): EditorState;
|
735 |
|
736 | |
737 |
|
738 |
|
739 | static moveSelectionToEnd(editorState: EditorState): EditorState;
|
740 |
|
741 | |
742 |
|
743 |
|
744 |
|
745 |
|
746 | static moveFocusToEnd(editorState: EditorState): EditorState;
|
747 |
|
748 | |
749 |
|
750 |
|
751 |
|
752 |
|
753 | static push(
|
754 | editorState: EditorState,
|
755 | contentState: ContentState,
|
756 | changeType: EditorChangeType,
|
757 | ): EditorState;
|
758 |
|
759 | |
760 |
|
761 |
|
762 |
|
763 | static undo(editorState: EditorState): EditorState;
|
764 |
|
765 | |
766 |
|
767 |
|
768 |
|
769 | static redo(editorState: EditorState): EditorState;
|
770 |
|
771 | toJS(): Object;
|
772 | getAllowUndo(): boolean;
|
773 | getCurrentContent(): ContentState;
|
774 | getUndoStack(): Immutable.Stack<ContentState>;
|
775 | getRedoStack(): Immutable.Stack<ContentState>;
|
776 | getSelection(): SelectionState;
|
777 | getDecorator(): DraftDecoratorType;
|
778 | isInCompositionMode(): boolean;
|
779 | mustForceSelection(): boolean;
|
780 | getNativelyRenderedContent(): ContentState;
|
781 | getLastChangeType(): EditorChangeType;
|
782 |
|
783 | |
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 | getInlineStyleOverride(): DraftInlineStyle;
|
792 |
|
793 | static setInlineStyleOverride(
|
794 | editorState: EditorState,
|
795 | inlineStyleOverride: DraftInlineStyle,
|
796 | ): EditorState;
|
797 |
|
798 | |
799 |
|
800 |
|
801 |
|
802 |
|
803 | getCurrentInlineStyle(): DraftInlineStyle;
|
804 |
|
805 | getBlockTree(blockKey: string): Immutable.List<any>;
|
806 | isSelectionAtStartOfContent(): boolean;
|
807 | isSelectionAtEndOfContent(): boolean;
|
808 | getDirectionMap(): Immutable.OrderedMap<any, any>;
|
809 | }
|
810 |
|
811 | class ContentBlock extends Record {
|
812 | getKey(): string;
|
813 |
|
814 | getType(): DraftBlockType;
|
815 |
|
816 | getText(): string;
|
817 | getCharacterList(): Immutable.List<CharacterMetadata>;
|
818 | getLength(): number;
|
819 | getDepth(): number;
|
820 | getData(): Immutable.Map<any, any>;
|
821 | getInlineStyleAt(offset: number): DraftInlineStyle;
|
822 | getEntityAt(offset: number): string;
|
823 |
|
824 | |
825 |
|
826 |
|
827 | findStyleRanges(
|
828 | filterFn: (value: CharacterMetadata) => boolean,
|
829 | callback: (start: number, end: number) => void,
|
830 | ): void;
|
831 |
|
832 | |
833 |
|
834 |
|
835 | findEntityRanges(
|
836 | filterFn: (value: CharacterMetadata) => boolean,
|
837 | callback: (start: number, end: number) => void,
|
838 | ): void;
|
839 | }
|
840 |
|
841 | class ContentState extends Record {
|
842 | static createFromBlockArray(blocks: ContentBlock[], entityMap?: any): ContentState;
|
843 | static createFromText(text: string, delimiter?: string): ContentState;
|
844 |
|
845 | createEntity(type: DraftEntityType, mutability: DraftEntityMutability, data?: Object): ContentState;
|
846 | getEntity(key: string): EntityInstance;
|
847 | getEntityMap(): any;
|
848 | getAllEntities(): Immutable.OrderedMap<string, DraftEntityInstance>;
|
849 | getLastCreatedEntityKey(): string;
|
850 | mergeEntityData(key: string, toMerge: { [key: string]: any }): ContentState;
|
851 | replaceEntityData(key: string, toMerge: { [key: string]: any }): ContentState;
|
852 | addEntity(instance: DraftEntityInstance): ContentState;
|
853 |
|
854 | getBlockMap(): BlockMap;
|
855 | getSelectionBefore(): SelectionState;
|
856 | getSelectionAfter(): SelectionState;
|
857 | getBlockForKey(key: string): ContentBlock;
|
858 |
|
859 | getKeyBefore(key: string): string;
|
860 | getKeyAfter(key: string): string;
|
861 | getBlockAfter(key: string): ContentBlock | undefined;
|
862 | getBlockBefore(key: string): ContentBlock | undefined;
|
863 |
|
864 | getBlocksAsArray(): ContentBlock[];
|
865 | getFirstBlock(): ContentBlock;
|
866 | getLastBlock(): ContentBlock;
|
867 | getPlainText(delimiter?: string): string;
|
868 | hasText(): boolean;
|
869 | }
|
870 |
|
871 | interface SelectionStateProperties {
|
872 | anchorKey: string;
|
873 | anchorOffset: number;
|
874 | focusKey: string;
|
875 | focusOffset: number;
|
876 | isBackward: boolean;
|
877 | hasFocus: boolean;
|
878 | }
|
879 |
|
880 | class SelectionState extends Record {
|
881 | static createEmpty(key: string): SelectionState;
|
882 |
|
883 | merge(
|
884 | ...iterables: Array<
|
885 | Immutable.Iterable<
|
886 | keyof SelectionStateProperties,
|
887 | SelectionStateProperties[keyof SelectionStateProperties]
|
888 | >
|
889 | >
|
890 | ): SelectionState;
|
891 | merge(...iterables: Array<Partial<SelectionStateProperties>>): SelectionState;
|
892 |
|
893 | serialize(): string;
|
894 | getAnchorKey(): string;
|
895 | getAnchorOffset(): number;
|
896 | getFocusKey(): string;
|
897 | getFocusOffset(): number;
|
898 | getIsBackward(): boolean;
|
899 | getHasFocus(): boolean;
|
900 | |
901 |
|
902 |
|
903 |
|
904 | hasEdgeWithin(blockKey: string, start: number, end: number): boolean;
|
905 | isCollapsed(): boolean;
|
906 | getStartKey(): string;
|
907 | getStartOffset(): number;
|
908 | getEndKey(): string;
|
909 | getEndOffset(): number;
|
910 | }
|
911 |
|
912 | class CharacterMetadata {
|
913 | static applyStyle(record: CharacterMetadata, style: string): CharacterMetadata;
|
914 | static removeStyle(record: CharacterMetadata, style: string): CharacterMetadata;
|
915 | static applyEntity(record: CharacterMetadata, entityKey: string | null): CharacterMetadata;
|
916 | static applyEntity(record: CharacterMetadata): CharacterMetadata;
|
917 | |
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 | static create(config?: CharacterMetadataConfig): CharacterMetadata;
|
924 | static create(): CharacterMetadata;
|
925 |
|
926 | getStyle(): DraftInlineStyle;
|
927 | getEntity(): string;
|
928 | hasStyle(style: string): boolean;
|
929 | }
|
930 |
|
931 | interface CharacterMetadataConfig {
|
932 | style?: DraftInlineStyle | undefined;
|
933 | entity?: string | undefined;
|
934 | }
|
935 |
|
936 | type EditorChangeType =
|
937 | | "adjust-depth"
|
938 | | "apply-entity"
|
939 | | "backspace-character"
|
940 | | "change-block-data"
|
941 | | "change-block-type"
|
942 | | "change-inline-style"
|
943 | | "move-block"
|
944 | | "delete-character"
|
945 | | "insert-characters"
|
946 | | "insert-fragment"
|
947 | | "redo"
|
948 | | "remove-range"
|
949 | | "spellcheck-change"
|
950 | | "split-block"
|
951 | | "undo";
|
952 |
|
953 | class BlockMapBuilder {
|
954 | static createFromArray(blocks: ContentBlock[]): BlockMap;
|
955 | }
|
956 |
|
957 | const DefaultDraftBlockRenderMap: Immutable.Map<any, any>;
|
958 | const DefaultDraftInlineStyle: Immutable.Map<any, any>;
|
959 | }
|
960 |
|
961 | namespace Keys {
|
962 | function generateRandomKey(): string;
|
963 | }
|
964 |
|
965 | namespace Modifier {
|
966 | import EditorState = Draft.Model.ImmutableData.EditorState;
|
967 | import ContentState = Draft.Model.ImmutableData.ContentState;
|
968 | import SelectionState = Draft.Model.ImmutableData.SelectionState;
|
969 |
|
970 | import BlockMap = Draft.Model.ImmutableData.BlockMap;
|
971 | import DraftInlineStyle = Draft.Model.ImmutableData.DraftInlineStyle;
|
972 |
|
973 | import DraftRemovalDirection = Draft.Model.Constants.DraftRemovalDirection;
|
974 | import DraftBlockType = Draft.Model.Constants.DraftBlockType;
|
975 |
|
976 | import DraftEditorCommand = Draft.Model.Constants.DraftEditorCommand;
|
977 |
|
978 | type URI = any;
|
979 |
|
980 | class AtomicBlockUtils {
|
981 | static insertAtomicBlock(editorState: EditorState, entityKey: string, character: string): EditorState;
|
982 | static moveAtomicBlock(
|
983 | editorState: EditorState,
|
984 | atomicBlock: ContentBlock,
|
985 | targetRange: SelectionState,
|
986 | insertionMode?: DraftInsertionType,
|
987 | ): EditorState;
|
988 | }
|
989 |
|
990 | |
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 | class DraftModifier {
|
1001 | static replaceText(
|
1002 | contentState: ContentState,
|
1003 | rangeToReplace: SelectionState,
|
1004 | text: string,
|
1005 | inlineStyle?: DraftInlineStyle,
|
1006 | entityKey?: string,
|
1007 | ): ContentState;
|
1008 | static insertText(
|
1009 | contentState: ContentState,
|
1010 | targetRange: SelectionState,
|
1011 | text: string,
|
1012 | inlineStyle?: DraftInlineStyle,
|
1013 | entityKey?: string,
|
1014 | ): ContentState;
|
1015 | static moveText(
|
1016 | contentState: ContentState,
|
1017 | removalRange: SelectionState,
|
1018 | targetRange: SelectionState,
|
1019 | ): ContentState;
|
1020 | static replaceWithFragment(
|
1021 | contentState: ContentState,
|
1022 | targetRange: SelectionState,
|
1023 | fragment: BlockMap,
|
1024 | ): ContentState;
|
1025 |
|
1026 | static removeRange(
|
1027 | contentState: ContentState,
|
1028 | rangeToRemove: SelectionState,
|
1029 | removalDirection: DraftRemovalDirection,
|
1030 | ): ContentState;
|
1031 |
|
1032 | static splitBlock(contentState: ContentState, selectionState: SelectionState): ContentState;
|
1033 | static applyInlineStyle(
|
1034 | contentState: ContentState,
|
1035 | selectionState: SelectionState,
|
1036 | inlineStyle: string,
|
1037 | ): ContentState;
|
1038 | static removeInlineStyle(
|
1039 | contentState: ContentState,
|
1040 | selectionState: SelectionState,
|
1041 | inlineStyle: string,
|
1042 | ): ContentState;
|
1043 |
|
1044 | static setBlockType(
|
1045 | contentState: ContentState,
|
1046 | selectionState: SelectionState,
|
1047 | blockType: DraftBlockType,
|
1048 | ): ContentState;
|
1049 | static setBlockType(
|
1050 | contentState: ContentState,
|
1051 | selectionState: SelectionState,
|
1052 | blockType: string,
|
1053 | ): ContentState;
|
1054 |
|
1055 | static setBlockData(
|
1056 | contentState: ContentState,
|
1057 | selectionState: SelectionState,
|
1058 | blockData: Immutable.Map<any, any>,
|
1059 | ): ContentState;
|
1060 | static mergeBlockData(
|
1061 | contentState: ContentState,
|
1062 | selectionState: SelectionState,
|
1063 | blockData: Immutable.Map<any, any>,
|
1064 | ): ContentState;
|
1065 | static applyEntity(
|
1066 | contentState: ContentState,
|
1067 | selectionState: SelectionState,
|
1068 | entityKey: string | null,
|
1069 | ): ContentState;
|
1070 | }
|
1071 |
|
1072 | class RichTextEditorUtil {
|
1073 | static currentBlockContainsLink(editorState: EditorState): boolean;
|
1074 | static getCurrentBlockType(editorState: EditorState): DraftBlockType;
|
1075 | static getCurrentBlockType(editorState: EditorState): string;
|
1076 | static getDataObjectForLinkURL(uri: URI): Object;
|
1077 |
|
1078 | static handleKeyCommand(editorState: EditorState, command: DraftEditorCommand): EditorState | null;
|
1079 | static handleKeyCommand(editorState: EditorState, command: string): null;
|
1080 |
|
1081 | static insertSoftNewline(editorState: EditorState): EditorState;
|
1082 |
|
1083 | |
1084 |
|
1085 |
|
1086 |
|
1087 | static onBackspace(editorState: EditorState): EditorState | null;
|
1088 | static onDelete(editorState: EditorState): EditorState | null;
|
1089 | static onTab(event: SyntheticKeyboardEvent, editorState: EditorState, maxDepth: number): EditorState;
|
1090 |
|
1091 | static toggleBlockType(editorState: EditorState, blockType: DraftBlockType): EditorState;
|
1092 | static toggleBlockType(editorState: EditorState, blockType: string): EditorState;
|
1093 |
|
1094 | static toggleCode(editorState: EditorState): EditorState;
|
1095 |
|
1096 | |
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | static toggleInlineStyle(editorState: EditorState, inlineStyle: string): EditorState;
|
1103 |
|
1104 | static toggleLink(
|
1105 | editorState: EditorState,
|
1106 | targetSelection: SelectionState,
|
1107 | entityKey: string | null,
|
1108 | ): EditorState;
|
1109 |
|
1110 | |
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 | static tryToRemoveBlockStyle(editorState: EditorState): ContentState | null;
|
1116 | }
|
1117 | }
|
1118 | }
|
1119 | }
|
1120 |
|
1121 | import Editor = Draft.Component.Base.DraftEditor;
|
1122 | import EditorProps = Draft.Component.Base.DraftEditorProps;
|
1123 | import EditorBlock = Draft.Component.Components.DraftEditorBlock;
|
1124 | import EditorState = Draft.Model.ImmutableData.EditorState;
|
1125 | import EditorChangeType = Draft.Model.ImmutableData.EditorChangeType;
|
1126 | import EditorCommand = Draft.Component.Base.EditorCommand;
|
1127 |
|
1128 | import DraftDecoratorComponentProps = Draft.Model.Decorators.DraftDecoratorComponentProps;
|
1129 | import DraftDecoratorType = Draft.Model.Decorators.DraftDecoratorType;
|
1130 | import DraftDecorator = Draft.Model.Decorators.DraftDecorator;
|
1131 | import CompositeDecorator = Draft.Model.Decorators.CompositeDraftDecorator;
|
1132 | import Entity = Draft.Model.Entity.DraftEntity;
|
1133 | import EntityInstance = Draft.Model.Entity.DraftEntityInstance;
|
1134 |
|
1135 | import BlockMapBuilder = Draft.Model.ImmutableData.BlockMapBuilder;
|
1136 | import CharacterMetadata = Draft.Model.ImmutableData.CharacterMetadata;
|
1137 | import ContentBlock = Draft.Model.ImmutableData.ContentBlock;
|
1138 | import ContentState = Draft.Model.ImmutableData.ContentState;
|
1139 | import SelectionState = Draft.Model.ImmutableData.SelectionState;
|
1140 | import DraftInlineStyle = Draft.Model.ImmutableData.DraftInlineStyle;
|
1141 | import BlockMap = Draft.Model.ImmutableData.BlockMap;
|
1142 |
|
1143 | import AtomicBlockUtils = Draft.Model.Modifier.AtomicBlockUtils;
|
1144 | import KeyBindingUtil = Draft.Component.Utils.KeyBindingUtil;
|
1145 | import Modifier = Draft.Model.Modifier.DraftModifier;
|
1146 | import RichUtils = Draft.Model.Modifier.RichTextEditorUtil;
|
1147 |
|
1148 | import DefaultDraftBlockRenderMap = Draft.Model.ImmutableData.DefaultDraftBlockRenderMap;
|
1149 | import DefaultDraftInlineStyle = Draft.Model.ImmutableData.DefaultDraftInlineStyle;
|
1150 |
|
1151 | import RawDraftInlineStyleRange = Draft.Model.Encoding.RawDraftInlineStyleRange;
|
1152 | import RawDraftEntityRange = Draft.Model.Encoding.RawDraftEntityRange;
|
1153 | import RawDraftEntity = Draft.Model.Encoding.RawDraftEntity;
|
1154 | import RawDraftContentBlock = Draft.Model.Encoding.RawDraftContentBlock;
|
1155 | import RawDraftContentState = Draft.Model.Encoding.RawDraftContentState;
|
1156 | import convertFromRaw = Draft.Model.Encoding.convertFromRawToDraftState;
|
1157 | import convertToRaw = Draft.Model.Encoding.convertFromDraftStateToRaw;
|
1158 | import convertFromHTML = Draft.Model.Encoding.convertFromHTMLtoContentBlocks;
|
1159 |
|
1160 | import genKey = Draft.Model.Keys.generateRandomKey;
|
1161 | import getDefaultKeyBinding = Draft.Component.Utils.getDefaultKeyBinding;
|
1162 | import getVisibleSelectionRect = Draft.Component.Selection.getVisibleSelectionRect;
|
1163 |
|
1164 | import DraftEditorCommand = Draft.Model.Constants.DraftEditorCommand;
|
1165 | import DraftDragType = Draft.Model.Constants.DraftDragType;
|
1166 | import DraftBlockType = Draft.Model.Constants.DraftBlockType;
|
1167 | import DraftBlockRenderConfig = Draft.Model.ImmutableData.DraftBlockRenderConfig;
|
1168 | import DraftBlockRenderMap = Draft.Component.Base.DraftBlockRenderMap;
|
1169 | import DraftInlineStyleType = Draft.Model.Constants.DraftInlineStyleType;
|
1170 | import DraftEntityMutability = Draft.Model.Constants.DraftEntityMutability;
|
1171 | import DraftEntityType = Draft.Model.Constants.DraftEntityType;
|
1172 | import DraftRemovalDirection = Draft.Model.Constants.DraftRemovalDirection;
|
1173 | import DraftHandleValue = Draft.Model.Constants.DraftHandleValue;
|
1174 | import DraftInsertionType = Draft.Model.Constants.DraftInsertionType;
|
1175 | import DraftStyleMap = Draft.Component.Base.DraftStyleMap;
|
1176 |
|
1177 | import DraftModel = Draft.Model;
|
1178 | import DraftComponent = Draft.Component;
|
1179 |
|
1180 | export {
|
1181 | AtomicBlockUtils,
|
1182 | BlockMap,
|
1183 | BlockMapBuilder,
|
1184 | CharacterMetadata,
|
1185 | CompositeDecorator,
|
1186 | ContentBlock,
|
1187 | ContentState,
|
1188 | convertFromHTML,
|
1189 | convertFromRaw,
|
1190 | convertToRaw,
|
1191 | DefaultDraftBlockRenderMap,
|
1192 | DefaultDraftInlineStyle,
|
1193 | DraftBlockRenderConfig,
|
1194 | DraftBlockRenderMap,
|
1195 | DraftBlockType,
|
1196 | DraftComponent,
|
1197 | DraftDecorator,
|
1198 | DraftDecoratorComponentProps,
|
1199 | DraftDecoratorType,
|
1200 | DraftDragType,
|
1201 | DraftEditorCommand,
|
1202 | DraftEntityMutability,
|
1203 | DraftEntityType,
|
1204 | DraftHandleValue,
|
1205 | DraftInlineStyle,
|
1206 | DraftInlineStyleType,
|
1207 | DraftInsertionType,
|
1208 | DraftModel,
|
1209 | DraftRemovalDirection,
|
1210 | DraftStyleMap,
|
1211 | Editor,
|
1212 | EditorBlock,
|
1213 | EditorChangeType,
|
1214 | EditorCommand,
|
1215 | EditorProps,
|
1216 | EditorState,
|
1217 | Entity,
|
1218 | EntityInstance,
|
1219 | genKey,
|
1220 | getDefaultKeyBinding,
|
1221 | getVisibleSelectionRect,
|
1222 | KeyBindingUtil,
|
1223 | Modifier,
|
1224 | RawDraftContentBlock,
|
1225 | RawDraftContentState,
|
1226 | RawDraftEntity,
|
1227 | RawDraftEntityRange,
|
1228 | RawDraftInlineStyleRange,
|
1229 | RichUtils,
|
1230 | SelectionState,
|
1231 | };
|
1232 |
|
\ | No newline at end of file |