1 | import type { EditorState, EditorView, PrimitiveSelection, Shape, Transaction } from '@remirror/core-types';
|
2 | import type { BuiltinPreset, UpdatableViewProps } from '../builtins';
|
3 | import type { AnyExtension } from '../extension';
|
4 | import type { RemirrorManager } from '../manager';
|
5 | import type { FocusType } from '../types';
|
6 | import type { AddFrameworkHandler, BaseFramework, CreateStateFromContent, FrameworkOptions, FrameworkOutput, FrameworkProps, ListenerProps, RemirrorEventListenerProps, UpdatableViewPropsObject, UpdateStateProps } from './base-framework';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare abstract class Framework<Extension extends AnyExtension = BuiltinPreset, Props extends FrameworkProps<Extension> = FrameworkProps<Extension>, Output extends FrameworkOutput<Extension> = FrameworkOutput<Extension>> implements BaseFramework<Extension> {
|
19 | #private;
|
20 | |
21 |
|
22 |
|
23 | protected previousStateOverride?: EditorState;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | protected get addHandler(): AddFrameworkHandler<Extension>;
|
34 | |
35 |
|
36 |
|
37 | protected get updatableViewProps(): UpdatableViewPropsObject;
|
38 | |
39 |
|
40 |
|
41 | protected get firstRender(): boolean;
|
42 | |
43 |
|
44 |
|
45 | abstract get name(): string;
|
46 | |
47 |
|
48 |
|
49 | get props(): Props;
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 | protected get previousState(): EditorState;
|
56 | |
57 |
|
58 |
|
59 | protected get manager(): RemirrorManager<Extension>;
|
60 | |
61 |
|
62 |
|
63 | protected get view(): EditorView;
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | protected get uid(): string;
|
71 | |
72 |
|
73 |
|
74 | get initialEditorState(): EditorState;
|
75 | constructor(options: FrameworkOptions<Extension, Props>);
|
76 | /**
|
77 | * Setup the manager event listeners which are disposed of when the manager is
|
78 | * destroyed.
|
79 | */
|
80 | private updateListener;
|
81 | /**
|
82 | * Update the constructor props passed in. Useful for frameworks like react
|
83 | * where props are constantly changing and when using hooks function closures
|
84 | * can become stale.
|
85 | *
|
86 | * You can call the update method with the new `props` to update the internal
|
87 | * state of this instance.
|
88 | */
|
89 | update(options: FrameworkOptions<Extension, Props>): this;
|
90 | /**
|
91 | * Retrieve the editor state.
|
92 | */
|
93 | protected readonly getState: () => EditorState;
|
94 | /**
|
95 | * Retrieve the previous editor state.
|
96 | */
|
97 | protected readonly getPreviousState: () => EditorState;
|
98 | /**
|
99 | * This method must be implement by the extending framework class. It returns
|
100 | * an [[`EditorView`]] which is added to the [[`RemirrorManager`]].
|
101 | */
|
102 | protected abstract createView(state: EditorState, element?: Element): EditorView;
|
103 | /**
|
104 | * This is used to implement how the state updates are used within your
|
105 | * application instance.
|
106 | *
|
107 | * It must be implemented.
|
108 | */
|
109 | protected abstract updateState(props: UpdateStateProps): void;
|
110 | /**
|
111 | * Update the view props.
|
112 | */
|
113 | protected updateViewProps(...keys: UpdatableViewProps[]): void;
|
114 | /**
|
115 | * This sets the attributes for the ProseMirror Dom node.
|
116 | */
|
117 | protected getAttributes(ssr?: false): Record<string, string>;
|
118 | protected getAttributes(ssr: true): Shape;
|
119 | /**
|
120 | * Part of the Prosemirror API and is called whenever there is state change in
|
121 | * the editor.
|
122 | *
|
123 | * @internalremarks
|
124 | * How does it work when transactions are dispatched one after the other.
|
125 | */
|
126 | protected readonly dispatchTransaction: (tr: Transaction) => void;
|
127 | /**
|
128 | * Adds `onBlur` and `onFocus` listeners.
|
129 | *
|
130 | * When extending this class make sure to call this method once
|
131 | * `ProsemirrorView` has been added to the dom.
|
132 | */
|
133 | protected addFocusListeners(): void;
|
134 | /**
|
135 | * Remove `onBlur` and `onFocus` listeners.
|
136 | *
|
137 | * When extending this class in your framework, make sure to call this just
|
138 | * before the view is destroyed.
|
139 | */
|
140 | protected removeFocusListeners(): void;
|
141 | /**
|
142 | * Called when the component unmounts and is responsible for cleanup.
|
143 | *
|
144 | * @remarks
|
145 | *
|
146 | * - Removes listeners for the editor `blur` and `focus` events
|
147 | */
|
148 | destroy(): void;
|
149 | /**
|
150 | * Use this method in the `onUpdate` event to run all change handlers.
|
151 | */
|
152 | readonly onChange: (props?: ListenerProps) => void;
|
153 | /**
|
154 | * Listener for editor 'blur' events
|
155 | */
|
156 | private readonly onBlur;
|
157 | /**
|
158 | * Listener for editor 'focus' events
|
159 | */
|
160 | private readonly onFocus;
|
161 | /**
|
162 | * Sets the content of the editor. This bypasses the update function.
|
163 | *
|
164 | * @param content
|
165 | * @param triggerChange
|
166 | */
|
167 | private readonly setContent;
|
168 | /**
|
169 | * Clear the content of the editor (reset to the default empty node).
|
170 | *
|
171 | * @param triggerChange - whether to notify the onChange handler that the
|
172 | * content has been reset
|
173 | */
|
174 | private readonly clearContent;
|
175 | /**
|
176 | * Creates the props passed into all event listener handlers. e.g.
|
177 | * `onChange`
|
178 | */
|
179 | protected eventListenerProps(props?: ListenerProps): RemirrorEventListenerProps<Extension>;
|
180 | protected readonly createStateFromContent: CreateStateFromContent;
|
181 | /**
|
182 | * Focus the editor.
|
183 | */
|
184 | protected readonly focus: (position?: FocusType) => void;
|
185 | /**
|
186 | * Blur the editor.
|
187 | */
|
188 | protected readonly blur: (position?: PrimitiveSelection) => void;
|
189 | /**
|
190 | * Methods and properties which are made available to all consumers of the
|
191 | * `Framework` class.
|
192 | */
|
193 | protected get baseOutput(): FrameworkOutput<Extension>;
|
194 | /**
|
195 | * Every framework implementation must provide it's own custom output.
|
196 | */
|
197 | abstract get frameworkOutput(): Output;
|
198 | }
|