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