@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
|
@@ -2,9 +2,9 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { PixelRatio, Platform, type NativeSyntheticEvent } from 'react-native';
|
|
3
3
|
import { normalizeNativeEditorV2DecimalId, type Selection } from './NativeEditorBridge';
|
|
4
4
|
import { setActiveEditorToolbarFrameOwnerForEditor } from './EditorToolbar';
|
|
5
|
-
import { useRichTextEditorState } from './useRichTextEditorState';
|
|
6
|
-
import { useRichTextEditorUpdates } from './useRichTextEditorUpdates';
|
|
7
|
-
import { useRichTextEditorCommands } from './useRichTextEditorCommands';
|
|
5
|
+
import { type useRichTextEditorState } from './useRichTextEditorState';
|
|
6
|
+
import { type useRichTextEditorUpdates } from './useRichTextEditorUpdates';
|
|
7
|
+
import { type useRichTextEditorCommands } from './useRichTextEditorCommands';
|
|
8
8
|
import {
|
|
9
9
|
type NativeUpdateEvent,
|
|
10
10
|
type NativeEditorErrorBinding,
|
|
@@ -96,18 +96,25 @@ export function useRichTextEditorEvents(
|
|
|
96
96
|
|
|
97
97
|
const isForThisEditor = useCallback(
|
|
98
98
|
(payload: { editorId: string }) => payload.editorId === editorId,
|
|
99
|
-
[editorId]
|
|
99
|
+
[ editorId ]
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
const handleEditorUpdate = useCallback(
|
|
103
103
|
(event: NativeSyntheticEvent<NativeUpdateEvent>) => {
|
|
104
|
-
if (documentHandle.isDestroyed)
|
|
104
|
+
if (documentHandle.isDestroyed) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
105
108
|
const accepted = acceptNativeCommitPayload(
|
|
106
109
|
event.nativeEvent,
|
|
107
110
|
documentHandle.editorId,
|
|
108
111
|
lastAcceptedNativeCommitRevisionRef.current
|
|
109
112
|
);
|
|
110
|
-
|
|
113
|
+
|
|
114
|
+
if (accepted == null) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
111
118
|
// Record both native-scoped revisions before any observable
|
|
112
119
|
// state/callback/refresh work. This makes duplicate delivery and
|
|
113
120
|
// the handle's same-revision signal deterministic.
|
|
@@ -119,13 +126,24 @@ export function useRichTextEditorEvents(
|
|
|
119
126
|
document.refresh();
|
|
120
127
|
onLocalCommitRef.current?.();
|
|
121
128
|
},
|
|
122
|
-
[applyTypedUpdateState,
|
|
129
|
+
[ applyTypedUpdateState,
|
|
130
|
+
document,
|
|
131
|
+
documentHandle.editorId,
|
|
132
|
+
documentHandle.isDestroyed,
|
|
133
|
+
lastAcceptedNativeCommitRevisionRef,
|
|
134
|
+
lastNativeDrivenRevisionRef,
|
|
135
|
+
onLocalCommitRef,
|
|
136
|
+
refreshAtomsFromUpdate ]
|
|
123
137
|
);
|
|
124
138
|
|
|
125
139
|
const admitNativeBindingEvent = useCallback(
|
|
126
140
|
(payload: unknown): NativeEditorErrorBinding | null => {
|
|
127
|
-
if (!isRecord(payload))
|
|
141
|
+
if (!isRecord(payload)) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
128
145
|
const currentBinding = nativeErrorBindingRef.current;
|
|
146
|
+
|
|
129
147
|
if (
|
|
130
148
|
currentBinding !== nativeErrorBinding ||
|
|
131
149
|
!currentBinding.mounted ||
|
|
@@ -136,7 +154,9 @@ export function useRichTextEditorEvents(
|
|
|
136
154
|
) {
|
|
137
155
|
return null;
|
|
138
156
|
}
|
|
157
|
+
|
|
139
158
|
const presentedEditorId = payload.editorId;
|
|
159
|
+
|
|
140
160
|
if (
|
|
141
161
|
typeof presentedEditorId !== 'string' ||
|
|
142
162
|
normalizeNativeEditorV2DecimalId(presentedEditorId) !== presentedEditorId ||
|
|
@@ -144,106 +164,162 @@ export function useRichTextEditorEvents(
|
|
|
144
164
|
) {
|
|
145
165
|
return null;
|
|
146
166
|
}
|
|
167
|
+
|
|
147
168
|
return currentBinding;
|
|
148
169
|
},
|
|
149
|
-
[nativeErrorBinding]
|
|
170
|
+
[ nativeErrorBinding, nativeErrorBindingRef ]
|
|
150
171
|
);
|
|
151
172
|
|
|
152
173
|
const handleEditorError = useCallback(
|
|
153
174
|
(event: NativeSyntheticEvent<NativeErrorEvent>) => {
|
|
154
175
|
const payload = event?.nativeEvent;
|
|
155
176
|
const binding = admitNativeBindingEvent(payload);
|
|
156
|
-
|
|
177
|
+
|
|
178
|
+
if (binding == null || !isRecord(payload)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
157
182
|
binding.handle.bridge._emitAutonomousError(payload.error);
|
|
158
183
|
},
|
|
159
|
-
[admitNativeBindingEvent]
|
|
184
|
+
[ admitNativeBindingEvent ]
|
|
160
185
|
);
|
|
161
186
|
|
|
162
187
|
const handleExternalTextCompositionEnd = useCallback(
|
|
163
188
|
(event: NativeSyntheticEvent<NativeExternalTextCompositionEvent>) => {
|
|
164
189
|
const payload = event?.nativeEvent;
|
|
165
190
|
const binding = admitNativeBindingEvent(payload);
|
|
166
|
-
|
|
167
|
-
if (
|
|
191
|
+
|
|
192
|
+
if (binding == null || !isRecord(payload)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (typeof payload.resultJson !== 'string') {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
168
200
|
try {
|
|
169
201
|
externalCompositionManager.handleNativeEnd(binding.editorId, payload.resultJson);
|
|
170
202
|
} catch (error) {
|
|
171
203
|
binding.handle.bridge._emitAutonomousError(externalCompositionErrorPayload(error));
|
|
172
204
|
}
|
|
173
205
|
},
|
|
174
|
-
[admitNativeBindingEvent, externalCompositionManager]
|
|
206
|
+
[ admitNativeBindingEvent, externalCompositionManager ]
|
|
175
207
|
);
|
|
176
208
|
|
|
177
209
|
const handleSelectionChange = useCallback(
|
|
178
210
|
(event: NativeSyntheticEvent<NativeSelectionEvent>) => {
|
|
179
|
-
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent))
|
|
211
|
+
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
180
215
|
const { anchor, head, stateJson } = event.nativeEvent;
|
|
181
216
|
scalarSelectionRef.current = { anchor, head };
|
|
182
217
|
let selection: Selection = { type: 'text', anchor, head };
|
|
183
218
|
const parsed = applyUpdateState(stateJson);
|
|
184
219
|
const parsedSelection = parseSelectionFromUpdate(parsed?.selection);
|
|
220
|
+
|
|
185
221
|
if (parsedSelection) {
|
|
186
222
|
selection = parsedSelection;
|
|
187
223
|
}
|
|
224
|
+
|
|
188
225
|
selectionRef.current = selection;
|
|
189
226
|
updateAtomSelection(selection);
|
|
190
227
|
onSelectionChangeRef.current?.(selection);
|
|
191
228
|
},
|
|
192
|
-
[applyUpdateState,
|
|
229
|
+
[ applyUpdateState,
|
|
230
|
+
documentHandle.isDestroyed,
|
|
231
|
+
isForThisEditor,
|
|
232
|
+
onSelectionChangeRef,
|
|
233
|
+
scalarSelectionRef,
|
|
234
|
+
selectionRef,
|
|
235
|
+
updateAtomSelection ]
|
|
193
236
|
);
|
|
194
237
|
|
|
195
238
|
const handleFocusChange = useCallback(
|
|
196
239
|
(event: NativeSyntheticEvent<NativeFocusEvent>) => {
|
|
197
|
-
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent))
|
|
240
|
+
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent)) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
198
244
|
const focused = event.nativeEvent.isFocused;
|
|
199
245
|
const wasFocused = isFocusedRef.current;
|
|
200
246
|
isFocusedRef.current = focused;
|
|
201
247
|
setActiveEditorToolbarFrameOwnerForEditor(toolbarFrameOwnerId, focused);
|
|
202
248
|
setIsFocused(focused);
|
|
249
|
+
|
|
203
250
|
if (focused && !wasFocused) {
|
|
204
251
|
onFocusRef.current?.();
|
|
205
252
|
} else if (!focused && wasFocused) {
|
|
206
253
|
onBlurRef.current?.();
|
|
207
254
|
}
|
|
208
255
|
},
|
|
209
|
-
[documentHandle,
|
|
256
|
+
[ documentHandle.isDestroyed,
|
|
257
|
+
isFocusedRef,
|
|
258
|
+
isForThisEditor,
|
|
259
|
+
onBlurRef,
|
|
260
|
+
onFocusRef,
|
|
261
|
+
setIsFocused,
|
|
262
|
+
toolbarFrameOwnerId ]
|
|
210
263
|
);
|
|
211
264
|
|
|
212
265
|
const handleContentHeightChange = useCallback(
|
|
213
266
|
(event: NativeSyntheticEvent<NativeContentHeightEvent>) => {
|
|
214
|
-
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent))
|
|
215
|
-
|
|
267
|
+
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (heightBehavior !== 'autoGrow') {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
216
275
|
const density = Platform.OS === 'android' ? PixelRatio.get() : 1;
|
|
217
276
|
const nextHeight = Math.ceil(event.nativeEvent.contentHeight / density);
|
|
218
|
-
|
|
219
|
-
|
|
277
|
+
|
|
278
|
+
if (!(nextHeight > 0)) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
setAutoGrowHeight(prev => (prev === nextHeight ? prev : nextHeight));
|
|
220
283
|
},
|
|
221
|
-
[documentHandle, heightBehavior, isForThisEditor]
|
|
284
|
+
[ documentHandle.isDestroyed, heightBehavior, isForThisEditor, setAutoGrowHeight ]
|
|
222
285
|
);
|
|
223
286
|
|
|
224
287
|
const handleAtomLayout = useCallback(
|
|
225
288
|
(event: NativeSyntheticEvent<NativeAtomLayoutEvent>) => {
|
|
226
|
-
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent))
|
|
289
|
+
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent)) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
227
293
|
const width = event.nativeEvent.width;
|
|
228
|
-
|
|
229
|
-
|
|
294
|
+
|
|
295
|
+
if (!Number.isFinite(width) || width < 0) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
setAtomContentWidth(current => (current === width ? current : width));
|
|
230
300
|
const viewport = event.nativeEvent.viewport;
|
|
301
|
+
|
|
231
302
|
if (
|
|
232
303
|
viewport &&
|
|
233
304
|
Number.isFinite(viewport.y) &&
|
|
234
305
|
Number.isFinite(viewport.height) &&
|
|
235
306
|
viewport.height >= 0
|
|
236
307
|
) {
|
|
237
|
-
setNativeAtomViewport(
|
|
308
|
+
setNativeAtomViewport(previous =>
|
|
238
309
|
previous?.y === viewport.y && previous.height === viewport.height
|
|
239
310
|
? previous
|
|
240
|
-
: viewport
|
|
241
|
-
);
|
|
311
|
+
: viewport);
|
|
242
312
|
}
|
|
313
|
+
|
|
243
314
|
const positions = event.nativeEvent.positions;
|
|
244
|
-
|
|
315
|
+
|
|
316
|
+
if (!Array.isArray(positions)) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
245
320
|
const next = new Map<string, NativeAtomPosition>();
|
|
246
|
-
|
|
321
|
+
|
|
322
|
+
for (const position of positions as NativeAtomPosition[]) {
|
|
247
323
|
if (
|
|
248
324
|
typeof position?.key !== 'string' ||
|
|
249
325
|
!Number.isFinite(position.x) ||
|
|
@@ -255,12 +331,18 @@ export function useRichTextEditorEvents(
|
|
|
255
331
|
) {
|
|
256
332
|
continue;
|
|
257
333
|
}
|
|
334
|
+
|
|
258
335
|
next.set(position.key, position);
|
|
259
336
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
337
|
+
|
|
338
|
+
setAtomPositions(current => {
|
|
339
|
+
if (current.size !== next.size) {
|
|
340
|
+
return next;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
for (const [ key, position ] of next) {
|
|
263
344
|
const previous = current.get(key);
|
|
345
|
+
|
|
264
346
|
if (
|
|
265
347
|
previous?.x !== position.x ||
|
|
266
348
|
previous.hostX !== position.hostX ||
|
|
@@ -268,19 +350,29 @@ export function useRichTextEditorEvents(
|
|
|
268
350
|
previous.y !== position.y ||
|
|
269
351
|
previous.height !== position.height ||
|
|
270
352
|
previous.width !== position.width
|
|
271
|
-
)
|
|
353
|
+
) {
|
|
272
354
|
return next;
|
|
355
|
+
}
|
|
273
356
|
}
|
|
357
|
+
|
|
274
358
|
return current;
|
|
275
359
|
});
|
|
276
360
|
},
|
|
277
|
-
[documentHandle,
|
|
361
|
+
[ documentHandle.isDestroyed,
|
|
362
|
+
isForThisEditor,
|
|
363
|
+
setAtomContentWidth,
|
|
364
|
+
setAtomPositions,
|
|
365
|
+
setNativeAtomViewport ]
|
|
278
366
|
);
|
|
279
367
|
|
|
280
368
|
const handleToolbarAction = useCallback(
|
|
281
369
|
(event: NativeSyntheticEvent<NativeToolbarActionEvent>) => {
|
|
282
|
-
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent))
|
|
370
|
+
if (documentHandle.isDestroyed || !isForThisEditor(event.nativeEvent)) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
283
374
|
const { key, updateJson, stateJson, documentRevision } = event.nativeEvent;
|
|
375
|
+
|
|
284
376
|
// A toolbar event carrying update data is a native commit. It
|
|
285
377
|
// must satisfy the same atomic admission path as typing; a pure
|
|
286
378
|
// action (link/image/custom key) has no commit to refresh.
|
|
@@ -295,6 +387,7 @@ export function useRichTextEditorEvents(
|
|
|
295
387
|
documentHandle.editorId,
|
|
296
388
|
lastAcceptedNativeCommitRevisionRef.current
|
|
297
389
|
);
|
|
390
|
+
|
|
298
391
|
if (accepted != null) {
|
|
299
392
|
lastAcceptedNativeCommitRevisionRef.current = accepted.documentRevision;
|
|
300
393
|
lastNativeDrivenRevisionRef.current = accepted.documentRevision;
|
|
@@ -307,27 +400,36 @@ export function useRichTextEditorEvents(
|
|
|
307
400
|
} else if (typeof stateJson === 'string') {
|
|
308
401
|
applyUpdateState(stateJson);
|
|
309
402
|
}
|
|
403
|
+
|
|
310
404
|
if (key === LINK_TOOLBAR_ACTION_KEY) {
|
|
311
405
|
openLinkRequest();
|
|
406
|
+
|
|
312
407
|
return;
|
|
313
408
|
}
|
|
409
|
+
|
|
314
410
|
if (key === IMAGE_TOOLBAR_ACTION_KEY) {
|
|
315
411
|
openImageRequest();
|
|
412
|
+
|
|
316
413
|
return;
|
|
317
414
|
}
|
|
415
|
+
|
|
318
416
|
onToolbarActionRef.current?.(key);
|
|
319
417
|
},
|
|
320
|
-
[
|
|
321
|
-
applyTypedUpdateState,
|
|
418
|
+
[ applyTypedUpdateState,
|
|
322
419
|
applyUpdateState,
|
|
323
420
|
document,
|
|
324
|
-
documentHandle,
|
|
421
|
+
documentHandle.editorId,
|
|
422
|
+
documentHandle.isDestroyed,
|
|
325
423
|
isForThisEditor,
|
|
424
|
+
lastAcceptedNativeCommitRevisionRef,
|
|
425
|
+
lastNativeDrivenRevisionRef,
|
|
426
|
+
onLocalCommitRef,
|
|
427
|
+
onToolbarActionRef,
|
|
326
428
|
openImageRequest,
|
|
327
429
|
openLinkRequest,
|
|
328
|
-
refreshAtomsFromUpdate
|
|
329
|
-
]
|
|
430
|
+
refreshAtomsFromUpdate ]
|
|
330
431
|
);
|
|
432
|
+
|
|
331
433
|
return {
|
|
332
434
|
isForThisEditor,
|
|
333
435
|
handleEditorUpdate,
|