@apollohg/react-native-rich-text-editor 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -116
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/android/build.gradle +3 -0
- package/android/src/main/java/com/apollohg/editor/EditorEditTextImages.kt +25 -0
- package/android/src/main/java/com/apollohg/editor/EditorV2RenderValidation.kt +1 -0
- package/android/src/main/java/com/apollohg/editor/ImageResizeOverlayView.kt +101 -33
- package/android/src/main/java/com/apollohg/editor/RenderMediaSpans.kt +15 -3
- package/android/src/main/java/com/apollohg/editor/RichTextEditorView.kt +14 -0
- package/android/src/main/java/com/apollohg/editor/viewer/AndroidProseLayoutEngine.kt +1 -1
- package/app.plugin.js +42 -39
- package/dist/AtomHost.js +18 -11
- package/dist/EditorAddon.js +4 -2
- package/dist/EditorAddonNormalization.js +17 -9
- package/dist/EditorMentionThemeNormalization.js +6 -3
- package/dist/EditorMentionThemeValidation.js +28 -11
- package/dist/EditorStyleSheetNormalization.js +85 -38
- package/dist/EditorStyleSheetTypes.d.ts +1 -1
- package/dist/EditorTheme.d.ts +4 -0
- package/dist/EditorTheme.js +5 -3
- package/dist/EditorToolbarComponent.d.ts +1 -1
- package/dist/EditorToolbarComponent.js +1 -1
- package/dist/EditorToolbarRegistry.js +5 -5
- package/dist/EditorToolbarTypes.d.ts +12 -12
- package/dist/EditorToolbarVisuals.js +1 -1
- package/dist/ExternalTextComposition.js +89 -43
- package/dist/ImageLoadingPolicy.d.ts +1 -1
- package/dist/NativeEditorBoundaryError.d.ts +7 -7
- package/dist/NativeEditorBoundaryError.js +9 -5
- package/dist/NativeEditorCollaborationTransport.d.ts +7 -7
- package/dist/NativeEditorCollaborationTransport.js +28 -15
- package/dist/NativeEditorCreateConfig.js +11 -6
- package/dist/NativeEditorCreateJson.js +51 -25
- package/dist/NativeEditorCreateValidation.js +11 -6
- package/dist/NativeEditorDocumentBridge.d.ts +1 -1
- package/dist/NativeEditorDocumentBridge.js +32 -18
- package/dist/NativeEditorDocumentHandle.d.ts +4 -4
- package/dist/NativeEditorDocumentHandle.js +1 -1
- package/dist/NativeEditorLocalAwareness.js +25 -13
- package/dist/NativeEditorNativeModule.d.ts +8 -1
- package/dist/NativeEditorNativeModule.js +7 -5
- package/dist/NativeEditorRenderNormalization.js +66 -25
- package/dist/NativeEditorResultNormalization.js +53 -29
- package/dist/NativeEditorTypes.d.ts +10 -10
- package/dist/NativeEditorV2Decimal.js +6 -3
- package/dist/NativeProseViewer.js +11 -3
- package/dist/ResourceLimits.d.ts +2 -2
- package/dist/ResourceLimits.js +7 -2
- package/dist/RichTextEditor.js +1 -1
- package/dist/RichTextEditorNativeTypes.d.ts +1 -1
- package/dist/RichTextEditorNativeView.d.ts +1 -3
- package/dist/RichTextEditorSerialization.js +24 -14
- package/dist/RichTextEditorTypes.d.ts +1 -1
- package/dist/YjsCollaboration.d.ts +7 -7
- package/dist/YjsCollaboration.js +42 -26
- package/dist/addons.d.ts +4 -4
- package/dist/addons.js +3 -3
- package/dist/atomInstances.js +6 -3
- package/dist/atomUpdates.js +7 -4
- package/dist/atoms.js +20 -12
- package/dist/attributeValidation.js +55 -24
- package/dist/contentExpression.js +80 -42
- package/dist/listMarkers.d.ts +1 -1
- package/dist/listMarkers.js +1 -1
- package/dist/schemaDefinition.d.ts +1 -1
- package/dist/schemaDefinition.js +23 -14
- package/dist/schemaDocument.js +1 -1
- package/dist/schemaDocumentConstruction.js +25 -14
- package/dist/schemaNormalization.js +51 -29
- package/dist/schemaPresets.d.ts +1 -1
- package/dist/schemaPresets.js +9 -4
- package/dist/schemaResolution.js +46 -25
- package/dist/specs/PreparedProseViewerNativeComponent.d.ts +4 -0
- package/dist/useEditorToolbarInteractions.d.ts +2 -2
- package/dist/useEditorToolbarInteractions.js +45 -23
- package/dist/useEditorToolbarItems.d.ts +1 -1
- package/dist/useEditorToolbarItems.js +4 -3
- package/dist/useEditorToolbarPresentation.d.ts +3 -3
- package/dist/useEditorToolbarPresentation.js +4 -4
- package/dist/useEditorToolbarState.d.ts +1 -1
- package/dist/useEditorToolbarState.js +1 -1
- package/dist/useFocusPreservingFrames.js +11 -8
- package/dist/useNativeEditor.d.ts +1 -1
- package/dist/useNativeEditor.js +21 -11
- package/dist/useRichTextEditorCommands.d.ts +2 -2
- package/dist/useRichTextEditorCommands.js +59 -29
- package/dist/useRichTextEditorEvents.d.ts +3 -3
- package/dist/useRichTextEditorEvents.js +75 -32
- package/dist/useRichTextEditorMentions.d.ts +4 -4
- package/dist/useRichTextEditorMentions.js +48 -29
- package/dist/useRichTextEditorPresentation.d.ts +4 -4
- package/dist/useRichTextEditorPresentation.js +25 -23
- package/dist/useRichTextEditorState.d.ts +3 -3
- package/dist/useRichTextEditorState.js +20 -15
- package/dist/useRichTextEditorUpdates.d.ts +1 -1
- package/dist/useRichTextEditorUpdates.js +99 -41
- package/dist/useViewerAtoms.js +63 -36
- package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
- package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
- package/ios/EditorInteractionOverlays.swift +114 -122
- package/ios/EditorLayoutManager.swift +13 -3
- package/ios/EditorStyleSheet.swift +12 -1
- package/ios/EditorTextView+Images.swift +32 -10
- package/ios/EditorTextView.swift +1 -1
- package/ios/EditorV2Adapter+RenderValidation.swift +2 -2
- package/ios/NativeToolbar+ButtonStyle.swift +17 -5
- package/ios/NativeToolbar+Diagnostics.swift +15 -0
- package/ios/RenderBridge+Atoms.swift +0 -1
- package/ios/RenderBridge+Attachments.swift +0 -29
- package/ios/RichTextEditorView.swift +4 -12
- package/ios/Viewer/CoreTextProseLayoutEngine+AttributedText.swift +3 -2
- package/package.json +11 -3
- package/react-native.config.js +1 -1
- package/rust/android/arm64-v8a/libeditor_core.so +0 -0
- package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
- package/rust/android/x86/libeditor_core.so +0 -0
- package/rust/android/x86_64/libeditor_core.so +0 -0
- package/src/AtomHost.tsx +58 -28
- package/src/EditorAddon.ts +18 -8
- package/src/EditorAddonNormalization.ts +40 -11
- package/src/EditorMentionThemeNormalization.ts +15 -4
- package/src/EditorMentionThemeValidation.ts +51 -14
- package/src/EditorStyleSheet.ts +1 -0
- package/src/EditorStyleSheetNormalization.ts +195 -64
- package/src/EditorStyleSheetTypes.ts +1 -1
- package/src/EditorTheme.ts +13 -5
- package/src/EditorToolbarComponent.tsx +2 -1
- package/src/EditorToolbarRegistry.tsx +23 -13
- package/src/EditorToolbarTypes.tsx +12 -12
- package/src/EditorToolbarVisuals.tsx +6 -3
- package/src/EditorUpdateRevision.ts +1 -0
- package/src/ExternalTextComposition.ts +259 -49
- package/src/ImageLoadingPolicy.ts +3 -1
- package/src/NativeEditorBoundaryError.ts +38 -11
- package/src/NativeEditorCollaborationTransport.ts +108 -27
- package/src/NativeEditorCreateConfig.ts +92 -19
- package/src/NativeEditorCreateJson.ts +163 -26
- package/src/NativeEditorCreateValidation.ts +33 -12
- package/src/NativeEditorDocumentBridge.ts +111 -19
- package/src/NativeEditorDocumentHandle.ts +9 -4
- package/src/NativeEditorLocalAwareness.ts +70 -15
- package/src/NativeEditorNativeModule.ts +13 -9
- package/src/NativeEditorRenderNormalization.ts +128 -29
- package/src/NativeEditorResultNormalization.ts +143 -32
- package/src/NativeEditorTypes.ts +12 -11
- package/src/NativeEditorV2Decimal.ts +12 -3
- package/src/NativeProseViewer.tsx +46 -16
- package/src/ResourceLimits.ts +15 -8
- package/src/RichTextEditor.tsx +3 -1
- package/src/RichTextEditorNativeTypes.tsx +1 -1
- package/src/RichTextEditorNativeView.tsx +2 -8
- package/src/RichTextEditorSerialization.tsx +70 -24
- package/src/RichTextEditorTypes.tsx +1 -1
- package/src/YjsCollaboration.ts +143 -47
- package/src/addons.ts +12 -8
- package/src/atomInstances.ts +25 -5
- package/src/atomUpdates.ts +23 -6
- package/src/atoms.ts +85 -18
- package/src/attributeValidation.ts +97 -33
- package/src/contentExpression.ts +218 -63
- package/src/listMarkers.ts +1 -1
- package/src/schemaDefinition.ts +82 -20
- package/src/schemaDocument.ts +15 -1
- package/src/schemaDocumentConstruction.ts +80 -16
- package/src/schemaNormalization.ts +155 -41
- package/src/schemaPresets.ts +37 -31
- package/src/schemaResolution.ts +126 -27
- package/src/specs/PreparedProseViewerNativeComponent.ts +4 -2
- package/src/useEditorToolbarInteractions.tsx +85 -36
- package/src/useEditorToolbarItems.tsx +50 -22
- package/src/useEditorToolbarPresentation.tsx +81 -58
- package/src/useEditorToolbarState.tsx +8 -6
- package/src/useFocusPreservingFrames.ts +43 -15
- package/src/useNativeEditor.ts +111 -51
- package/src/useRichTextEditorCommands.tsx +127 -54
- package/src/useRichTextEditorEvents.tsx +144 -42
- package/src/useRichTextEditorMentions.tsx +118 -37
- package/src/useRichTextEditorPresentation.tsx +128 -114
- package/src/useRichTextEditorState.tsx +76 -40
- package/src/useRichTextEditorUpdates.tsx +207 -56
- package/src/useViewerAtoms.tsx +162 -66
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
useEditorToolbarFrames,
|
|
6
6
|
type EditorToolbarItem,
|
|
7
7
|
} from './EditorToolbar';
|
|
8
|
-
import React
|
|
8
|
+
import type React from 'react';
|
|
9
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
9
10
|
import {
|
|
10
11
|
_assertNativeEditorDocumentHandle,
|
|
11
12
|
_getNativeEditorDocumentHandleDescriptor,
|
|
@@ -84,29 +85,33 @@ export function useRichTextEditorState(
|
|
|
84
85
|
}: RichTextEditorProps,
|
|
85
86
|
ref: React.ForwardedRef<RichTextEditorRef>
|
|
86
87
|
) {
|
|
87
|
-
const addons = useMemo(() => normalizeEditorAddons(addonDescriptors), [addonDescriptors]);
|
|
88
|
+
const addons = useMemo(() => normalizeEditorAddons(addonDescriptors), [ addonDescriptors ]);
|
|
88
89
|
_assertNativeEditorDocumentHandle(documentHandle);
|
|
89
90
|
|
|
90
91
|
const documentDescriptor = _getNativeEditorDocumentHandleDescriptor(documentHandle);
|
|
91
92
|
|
|
92
|
-
const registeredAtomTypeKey = JSON.stringify((atoms ?? []).map(
|
|
93
|
+
const registeredAtomTypeKey = JSON.stringify((atoms ?? []).map(atom => atom.name));
|
|
93
94
|
|
|
94
95
|
const registeredAtomTypes = useMemo(
|
|
95
|
-
() => new Set((
|
|
96
|
-
[registeredAtomTypeKey]
|
|
96
|
+
() => new Set(JSON.parse(registeredAtomTypeKey) as string[]),
|
|
97
|
+
[ registeredAtomTypeKey ]
|
|
97
98
|
);
|
|
98
99
|
|
|
99
100
|
const atomComponents = useMemo(() => {
|
|
100
101
|
const components = new Map<string, AtomComponent>();
|
|
102
|
+
|
|
101
103
|
for (const atom of atoms ?? []) {
|
|
102
|
-
if (!components.has(atom.name))
|
|
104
|
+
if (!components.has(atom.name)) {
|
|
105
|
+
components.set(atom.name, atom.component);
|
|
106
|
+
}
|
|
103
107
|
}
|
|
108
|
+
|
|
104
109
|
return components;
|
|
105
|
-
}, [atoms]);
|
|
110
|
+
}, [ atoms ]);
|
|
106
111
|
|
|
107
112
|
const serializedValueJson = useSerializedValue(
|
|
108
113
|
valueJSON,
|
|
109
|
-
|
|
114
|
+
doc => stringifyCachedJson(normalizeDocumentJson(doc, documentDescriptor)),
|
|
110
115
|
valueJSONRevision
|
|
111
116
|
);
|
|
112
117
|
|
|
@@ -115,7 +120,7 @@ export function useRichTextEditorState(
|
|
|
115
120
|
serializedValueJson == null
|
|
116
121
|
? undefined
|
|
117
122
|
: (JSON.parse(serializedValueJson) as DocumentJSON),
|
|
118
|
-
[serializedValueJson]
|
|
123
|
+
[ serializedValueJson ]
|
|
119
124
|
);
|
|
120
125
|
|
|
121
126
|
const bridge = documentHandle.bridge;
|
|
@@ -126,7 +131,7 @@ export function useRichTextEditorState(
|
|
|
126
131
|
|
|
127
132
|
const externalCompositionManager = useMemo(
|
|
128
133
|
() => new ExternalTextCompositionManager(editorId, () => nativeViewRef.current),
|
|
129
|
-
[editorId]
|
|
134
|
+
[ editorId ]
|
|
130
135
|
);
|
|
131
136
|
|
|
132
137
|
const managerDisposalsRef = useRef(
|
|
@@ -134,33 +139,38 @@ export function useRichTextEditorState(
|
|
|
134
139
|
);
|
|
135
140
|
|
|
136
141
|
useEffect(() => {
|
|
137
|
-
const
|
|
142
|
+
const managerDisposals = managerDisposalsRef.current;
|
|
143
|
+
const pendingDisposal = managerDisposals.get(externalCompositionManager);
|
|
144
|
+
|
|
138
145
|
if (pendingDisposal != null) {
|
|
139
146
|
pendingDisposal.cancelled = true;
|
|
140
|
-
|
|
147
|
+
managerDisposals.delete(externalCompositionManager);
|
|
141
148
|
}
|
|
149
|
+
|
|
142
150
|
return () => {
|
|
143
151
|
const token: ExternalCompositionDisposalToken = { cancelled: false };
|
|
144
|
-
|
|
152
|
+
managerDisposals.set(externalCompositionManager, token);
|
|
153
|
+
|
|
145
154
|
void Promise.resolve().then(() => {
|
|
146
155
|
if (
|
|
147
156
|
token.cancelled ||
|
|
148
|
-
|
|
157
|
+
managerDisposals.get(externalCompositionManager) !== token
|
|
149
158
|
) {
|
|
150
159
|
return;
|
|
151
160
|
}
|
|
152
|
-
|
|
161
|
+
|
|
162
|
+
managerDisposals.delete(externalCompositionManager);
|
|
153
163
|
externalCompositionManager.dispose();
|
|
154
164
|
});
|
|
155
165
|
};
|
|
156
|
-
}, [externalCompositionManager]);
|
|
166
|
+
}, [ externalCompositionManager ]);
|
|
157
167
|
|
|
158
168
|
const controlledValueKey =
|
|
159
169
|
value != null
|
|
160
170
|
? `html:${value}`
|
|
161
171
|
: serializedValueJson == null
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
? null
|
|
173
|
+
: `json:${serializedValueJson}`;
|
|
164
174
|
|
|
165
175
|
const currentControlledValue: ControlledValueDelivery = {
|
|
166
176
|
manager: externalCompositionManager,
|
|
@@ -201,7 +211,7 @@ export function useRichTextEditorState(
|
|
|
201
211
|
key: string;
|
|
202
212
|
} | null>(null);
|
|
203
213
|
|
|
204
|
-
const [, setControlledResetRevision] = useState(0);
|
|
214
|
+
const [ , setControlledResetRevision ] = useState(0);
|
|
205
215
|
|
|
206
216
|
useLayoutEffect(() => {
|
|
207
217
|
if (
|
|
@@ -215,13 +225,19 @@ export function useRichTextEditorState(
|
|
|
215
225
|
) {
|
|
216
226
|
return;
|
|
217
227
|
}
|
|
228
|
+
|
|
218
229
|
const pending = { manager: externalCompositionManager };
|
|
219
230
|
pendingResetCancellationRef.current = pending;
|
|
231
|
+
|
|
220
232
|
void externalCompositionManager.cancelForDocumentChange().then(
|
|
221
233
|
() => {
|
|
222
|
-
if (pendingResetCancellationRef.current !== pending)
|
|
234
|
+
if (pendingResetCancellationRef.current !== pending) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
223
238
|
pendingResetCancellationRef.current = null;
|
|
224
239
|
const latest = latestControlledValueRef.current;
|
|
240
|
+
|
|
225
241
|
if (
|
|
226
242
|
latest.manager !== externalCompositionManager ||
|
|
227
243
|
latest.mode !== 'reset' ||
|
|
@@ -232,19 +248,26 @@ export function useRichTextEditorState(
|
|
|
232
248
|
) {
|
|
233
249
|
return;
|
|
234
250
|
}
|
|
251
|
+
|
|
235
252
|
blockedControlledResetRef.current = null;
|
|
253
|
+
|
|
236
254
|
deliveredControlledValueRef.current = {
|
|
237
255
|
manager: latest.manager,
|
|
238
256
|
key: latest.key,
|
|
239
257
|
value: latest.value,
|
|
240
258
|
valueJSON: latest.valueJSON,
|
|
241
259
|
};
|
|
242
|
-
|
|
260
|
+
|
|
261
|
+
setControlledResetRevision(revision => revision + 1);
|
|
243
262
|
},
|
|
244
263
|
(error: unknown) => {
|
|
245
|
-
if (pendingResetCancellationRef.current !== pending)
|
|
264
|
+
if (pendingResetCancellationRef.current !== pending) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
246
268
|
pendingResetCancellationRef.current = null;
|
|
247
269
|
const latest = latestControlledValueRef.current;
|
|
270
|
+
|
|
248
271
|
if (
|
|
249
272
|
latest.manager !== externalCompositionManager ||
|
|
250
273
|
latest.mode !== 'reset' ||
|
|
@@ -255,14 +278,16 @@ export function useRichTextEditorState(
|
|
|
255
278
|
) {
|
|
256
279
|
return;
|
|
257
280
|
}
|
|
281
|
+
|
|
258
282
|
blockedControlledResetRef.current = {
|
|
259
283
|
manager: externalCompositionManager,
|
|
260
284
|
key: latest.key,
|
|
261
285
|
};
|
|
286
|
+
|
|
262
287
|
latest.handle.bridge._emitAutonomousError(externalCompositionErrorPayload(error));
|
|
263
288
|
}
|
|
264
289
|
);
|
|
265
|
-
}, [controlledValueKey, externalCompositionManager, valueJSONUpdateMode]);
|
|
290
|
+
}, [ controlledValueKey, externalCompositionManager, valueJSONUpdateMode ]);
|
|
266
291
|
|
|
267
292
|
const deliveredControlledValue = deliveredControlledValueRef.current;
|
|
268
293
|
|
|
@@ -298,6 +323,7 @@ export function useRichTextEditorState(
|
|
|
298
323
|
|
|
299
324
|
useEffect(() => {
|
|
300
325
|
const currentBinding = nativeErrorBindingRef.current;
|
|
326
|
+
|
|
301
327
|
if (
|
|
302
328
|
currentBinding !== nativeErrorBinding &&
|
|
303
329
|
!currentBinding.mounted &&
|
|
@@ -307,15 +333,19 @@ export function useRichTextEditorState(
|
|
|
307
333
|
) {
|
|
308
334
|
nativeErrorBindingRef.current = nativeErrorBinding;
|
|
309
335
|
}
|
|
336
|
+
|
|
310
337
|
return () => {
|
|
311
|
-
if (nativeErrorBindingRef.current !== nativeErrorBinding)
|
|
338
|
+
if (nativeErrorBindingRef.current !== nativeErrorBinding) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
312
342
|
nativeErrorBindingRef.current = {
|
|
313
343
|
...nativeErrorBinding,
|
|
314
344
|
generation: nativeErrorBinding.generation + 1,
|
|
315
345
|
mounted: false,
|
|
316
346
|
};
|
|
317
347
|
};
|
|
318
|
-
}, [nativeErrorBinding]);
|
|
348
|
+
}, [ nativeErrorBinding ]);
|
|
319
349
|
|
|
320
350
|
const onSelectionChangeRef = useRef(onSelectionChange);
|
|
321
351
|
|
|
@@ -353,22 +383,22 @@ export function useRichTextEditorState(
|
|
|
353
383
|
|
|
354
384
|
addonsRef.current = addons;
|
|
355
385
|
|
|
356
|
-
const [activeState, setActiveState] = useState<ReadonlyActiveState>(EMPTY_ACTIVE_STATE);
|
|
386
|
+
const [ activeState, setActiveState ] = useState<ReadonlyActiveState>(EMPTY_ACTIVE_STATE);
|
|
357
387
|
|
|
358
|
-
const [pushedUpdate, setPushedUpdate] = useState<{
|
|
388
|
+
const [ pushedUpdate, setPushedUpdate ] = useState<{
|
|
359
389
|
json: string;
|
|
360
390
|
resetJson?: string;
|
|
361
391
|
revision: number;
|
|
362
392
|
editorId: string;
|
|
363
393
|
} | null>(null);
|
|
364
394
|
|
|
365
|
-
const [autoGrowHeight, setAutoGrowHeight] = useState<number | null>(null);
|
|
395
|
+
const [ autoGrowHeight, setAutoGrowHeight ] = useState<number | null>(null);
|
|
366
396
|
|
|
367
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
397
|
+
const [ isFocused, setIsFocused ] = useState(false);
|
|
368
398
|
|
|
369
|
-
const [mentionQuery, setMentionQuery] = useState<MentionQueryChangeEvent | null>(null);
|
|
399
|
+
const [ mentionQuery, setMentionQuery ] = useState<MentionQueryChangeEvent | null>(null);
|
|
370
400
|
|
|
371
|
-
const [atomState, setAtomState] = useState<AtomRenderState>({
|
|
401
|
+
const [ atomState, setAtomState ] = useState<AtomRenderState>({
|
|
372
402
|
blocks: [],
|
|
373
403
|
instanceBlocks: [],
|
|
374
404
|
instances: [],
|
|
@@ -378,15 +408,15 @@ export function useRichTextEditorState(
|
|
|
378
408
|
|
|
379
409
|
const atomStateRef = useRef(atomState);
|
|
380
410
|
|
|
381
|
-
const [selectedKeys, setSelectedKeys] = useState<ReadonlySet<string>>(new Set());
|
|
411
|
+
const [ selectedKeys, setSelectedKeys ] = useState<ReadonlySet<string>>(new Set());
|
|
382
412
|
|
|
383
|
-
const [atomContentWidth, setAtomContentWidth] = useState<number | null>(null);
|
|
413
|
+
const [ atomContentWidth, setAtomContentWidth ] = useState<number | null>(null);
|
|
384
414
|
|
|
385
|
-
const [atomPositions, setAtomPositions] = useState<ReadonlyMap<string, NativeAtomPosition>>(
|
|
415
|
+
const [ atomPositions, setAtomPositions ] = useState<ReadonlyMap<string, NativeAtomPosition>>(
|
|
386
416
|
new Map()
|
|
387
417
|
);
|
|
388
418
|
|
|
389
|
-
const [nativeAtomViewport, setNativeAtomViewport] = useState<AtomViewport>();
|
|
419
|
+
const [ nativeAtomViewport, setNativeAtomViewport ] = useState<AtomViewport>();
|
|
390
420
|
|
|
391
421
|
const warnedUnknownAtomTypesRef = useRef(new Set<string>());
|
|
392
422
|
|
|
@@ -458,6 +488,7 @@ export function useRichTextEditorState(
|
|
|
458
488
|
|
|
459
489
|
if (didRebindRevisionScope) {
|
|
460
490
|
pendingFocusedRebindRef.current = null;
|
|
491
|
+
|
|
461
492
|
if (isFocusedRef.current && document.isReady) {
|
|
462
493
|
pendingFocusedRebindRef.current = {
|
|
463
494
|
editorId,
|
|
@@ -467,6 +498,7 @@ export function useRichTextEditorState(
|
|
|
467
498
|
isFocusedRef.current = false;
|
|
468
499
|
setIsFocused(false);
|
|
469
500
|
}
|
|
501
|
+
|
|
470
502
|
pushedUpdateBindingGenerationRef.current += 1;
|
|
471
503
|
revisionScopeEditorIdRef.current = editorId;
|
|
472
504
|
latestRevisionScopeEditorIdRef.current = null;
|
|
@@ -478,6 +510,7 @@ export function useRichTextEditorState(
|
|
|
478
510
|
setActiveState(EMPTY_ACTIVE_STATE);
|
|
479
511
|
setPushedUpdate(null);
|
|
480
512
|
setAutoGrowHeight(null);
|
|
513
|
+
|
|
481
514
|
const emptyAtomState: AtomRenderState = {
|
|
482
515
|
blocks: [],
|
|
483
516
|
instanceBlocks: [],
|
|
@@ -485,6 +518,7 @@ export function useRichTextEditorState(
|
|
|
485
518
|
documentVersion: null,
|
|
486
519
|
hasOnlyStableAtomKeys: true,
|
|
487
520
|
};
|
|
521
|
+
|
|
488
522
|
atomStateRef.current = emptyAtomState;
|
|
489
523
|
atomSeedEditorIdRef.current = null;
|
|
490
524
|
setAtomState(emptyAtomState);
|
|
@@ -504,7 +538,7 @@ export function useRichTextEditorState(
|
|
|
504
538
|
if (heightBehavior !== 'autoGrow') {
|
|
505
539
|
setAutoGrowHeight(null);
|
|
506
540
|
}
|
|
507
|
-
}, [heightBehavior]);
|
|
541
|
+
}, [ heightBehavior ]);
|
|
508
542
|
|
|
509
543
|
// A changed handle initially shares the previous hook render. Do not
|
|
510
544
|
// trust that render's revision: establish the new mutation base only by
|
|
@@ -513,17 +547,19 @@ export function useRichTextEditorState(
|
|
|
513
547
|
if (latestRevisionScopeEditorIdRef.current === editorId || documentHandle.isDestroyed) {
|
|
514
548
|
return;
|
|
515
549
|
}
|
|
550
|
+
|
|
516
551
|
latestRevisionRef.current = documentHandle.bridge.getState().documentRevision;
|
|
517
552
|
latestRevisionScopeEditorIdRef.current = editorId;
|
|
518
|
-
}, [documentHandle, editorId]);
|
|
553
|
+
}, [ documentHandle, editorId ]);
|
|
519
554
|
|
|
520
555
|
useEffect(
|
|
521
556
|
() => () => {
|
|
522
557
|
setActiveEditorToolbarFrameOwnerForEditor(toolbarFrameOwnerId, false);
|
|
523
558
|
setEditorToolbarMentionState(toolbarFrameOwnerId, null);
|
|
524
559
|
},
|
|
525
|
-
[editorId, toolbarFrameOwnerId]
|
|
560
|
+
[ editorId, toolbarFrameOwnerId ]
|
|
526
561
|
);
|
|
562
|
+
|
|
527
563
|
return {
|
|
528
564
|
atomStateRef,
|
|
529
565
|
setSelectedKeys,
|
|
@@ -600,8 +636,8 @@ export function useRichTextEditorState(
|
|
|
600
636
|
toolbarItems,
|
|
601
637
|
toolbarPlacement,
|
|
602
638
|
showToolbar,
|
|
603
|
-
containerStyle
|
|
604
|
-
style
|
|
639
|
+
containerStyle,
|
|
640
|
+
style,
|
|
605
641
|
autoGrowHeight,
|
|
606
642
|
pushedUpdate,
|
|
607
643
|
registeredToolbarFrames,
|