@apollohg/react-native-rich-text-editor 2.0.0 → 2.0.1
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 +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/android/build.gradle +3 -0
- 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 +84 -37
- 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/Info.plist +5 -5
- 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/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/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
|
@@ -27,7 +27,7 @@ function collaborationProtocolAdapterDescriptor(value) {
|
|
|
27
27
|
typeof value.onMessage !== 'function') {
|
|
28
28
|
throw (0, NativeEditorResultNormalization_1.invalidV2RequestError)('NativeEditorBridge: invalid collaboration protocol adapter');
|
|
29
29
|
}
|
|
30
|
-
const protocols = value.protocols.map(
|
|
30
|
+
const protocols = value.protocols.map(protocol => {
|
|
31
31
|
if (typeof protocol !== 'string' ||
|
|
32
32
|
protocol.length === 0 ||
|
|
33
33
|
(0, NativeEditorCreateJson_1.utf8V2JsonByteLength)(protocol) > exports.MAX_COLLABORATION_PROTOCOL_BYTES ||
|
|
@@ -49,7 +49,7 @@ function collaborationProtocolAdapterDescriptor(value) {
|
|
|
49
49
|
const rawTerminalCloseCodes = value.terminalCloseCodes;
|
|
50
50
|
if (rawTerminalCloseCodes !== undefined &&
|
|
51
51
|
(!Array.isArray(rawTerminalCloseCodes) ||
|
|
52
|
-
rawTerminalCloseCodes.some(
|
|
52
|
+
rawTerminalCloseCodes.some(code => !Number.isSafeInteger(code) || code < 1000 || code > 4999))) {
|
|
53
53
|
throw (0, NativeEditorResultNormalization_1.invalidV2RequestError)('NativeEditorBridge: invalid collaboration terminal close code');
|
|
54
54
|
}
|
|
55
55
|
const terminalCloseCodes = rawTerminalCloseCodes === undefined ? undefined : [...rawTerminalCloseCodes];
|
|
@@ -115,8 +115,9 @@ function serializeCollaborationProtocolAdapterResult(value) {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
function normalizeNativeCollaborationTransportDiagnostics(value) {
|
|
118
|
-
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value))
|
|
118
|
+
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value)) {
|
|
119
119
|
return null;
|
|
120
|
+
}
|
|
120
121
|
const transportState = (0, NativeEditorResultNormalization_1.whitelisted)(value.transportState, NativeEditorResultNormalization_1.V2_TRANSPORT_STATES);
|
|
121
122
|
const nextDeadlineMillis = value.nextDeadlineMillis === null
|
|
122
123
|
? null
|
|
@@ -160,11 +161,13 @@ function encodeNativeCollaborationProtocolBytes(bytes) {
|
|
|
160
161
|
return encoded;
|
|
161
162
|
}
|
|
162
163
|
function decodeNativeCollaborationProtocolBytes(value) {
|
|
163
|
-
if (value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(value))
|
|
164
|
+
if (value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(value)) {
|
|
164
165
|
return null;
|
|
166
|
+
}
|
|
165
167
|
const firstPadding = value.indexOf('=');
|
|
166
|
-
if (firstPadding >= 0 && firstPadding < value.length - 2)
|
|
168
|
+
if (firstPadding >= 0 && firstPadding < value.length - 2) {
|
|
167
169
|
return null;
|
|
170
|
+
}
|
|
168
171
|
const outputLength = (value.length / 4) * 3 - (value.endsWith('==') ? 2 : value.endsWith('=') ? 1 : 0);
|
|
169
172
|
const bytes = new Uint8Array(outputLength);
|
|
170
173
|
let outputIndex = 0;
|
|
@@ -173,21 +176,26 @@ function decodeNativeCollaborationProtocolBytes(value) {
|
|
|
173
176
|
const second = exports.BASE64_ALPHABET.indexOf(value[index + 1]);
|
|
174
177
|
const third = value[index + 2] === '=' ? 0 : exports.BASE64_ALPHABET.indexOf(value[index + 2]);
|
|
175
178
|
const fourth = value[index + 3] === '=' ? 0 : exports.BASE64_ALPHABET.indexOf(value[index + 3]);
|
|
176
|
-
if (first < 0 || second < 0 || third < 0 || fourth < 0)
|
|
179
|
+
if (first < 0 || second < 0 || third < 0 || fourth < 0) {
|
|
177
180
|
return null;
|
|
181
|
+
}
|
|
178
182
|
const decoded = (first << 18) | (second << 12) | (third << 6) | fourth;
|
|
179
|
-
if (outputIndex < outputLength)
|
|
183
|
+
if (outputIndex < outputLength) {
|
|
180
184
|
bytes[outputIndex++] = (decoded >>> 16) & 0xff;
|
|
181
|
-
|
|
185
|
+
}
|
|
186
|
+
if (outputIndex < outputLength) {
|
|
182
187
|
bytes[outputIndex++] = (decoded >>> 8) & 0xff;
|
|
183
|
-
|
|
188
|
+
}
|
|
189
|
+
if (outputIndex < outputLength) {
|
|
184
190
|
bytes[outputIndex++] = decoded & 0xff;
|
|
191
|
+
}
|
|
185
192
|
}
|
|
186
193
|
return bytes;
|
|
187
194
|
}
|
|
188
195
|
function normalizeNativeCollaborationTransportEvent(value) {
|
|
189
|
-
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value))
|
|
196
|
+
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value)) {
|
|
190
197
|
return null;
|
|
198
|
+
}
|
|
191
199
|
const editorId = (0, NativeEditorResultNormalization_1.normalizeNativeEditorV2DecimalId)(value.editorId);
|
|
192
200
|
const eventSequence = (0, NativeEditorResultNormalization_1.normalizeNativeEditorV2DecimalId)(value.eventSequence);
|
|
193
201
|
const generation = value.generation === null ? null : (0, NativeEditorResultNormalization_1.normalizeNativeEditorV2DecimalId)(value.generation);
|
|
@@ -202,8 +210,9 @@ function normalizeNativeCollaborationTransportEvent(value) {
|
|
|
202
210
|
const state = (0, NativeEditorResultNormalization_1.normalizeNativeEditorV2StateValue)(value.state);
|
|
203
211
|
const peers = (0, NativeEditorResultNormalization_1.normalizeNativeEditorV2PeersValue)({ peers: value.peers });
|
|
204
212
|
const diagnostics = normalizeNativeCollaborationTransportDiagnostics(value.diagnostics);
|
|
205
|
-
if (state == null || peers == null || diagnostics == null)
|
|
213
|
+
if (state == null || peers == null || diagnostics == null) {
|
|
206
214
|
return null;
|
|
215
|
+
}
|
|
207
216
|
return {
|
|
208
217
|
editorId,
|
|
209
218
|
eventSequence,
|
|
@@ -216,8 +225,9 @@ function normalizeNativeCollaborationTransportEvent(value) {
|
|
|
216
225
|
}
|
|
217
226
|
if (value.kind === 'error') {
|
|
218
227
|
const error = (0, NativeEditorBoundaryError_1.normalizeNativeEditorV2Error)({ error: value.error });
|
|
219
|
-
if (error == null)
|
|
228
|
+
if (error == null) {
|
|
220
229
|
return null;
|
|
230
|
+
}
|
|
221
231
|
return {
|
|
222
232
|
editorId,
|
|
223
233
|
eventSequence,
|
|
@@ -247,12 +257,14 @@ function normalizeNativeCollaborationTransportEvent(value) {
|
|
|
247
257
|
negotiatedProtocol: value.negotiatedProtocol,
|
|
248
258
|
};
|
|
249
259
|
if (value.phase === 'open') {
|
|
250
|
-
if (value.frame !== undefined)
|
|
260
|
+
if (value.frame !== undefined) {
|
|
251
261
|
return null;
|
|
262
|
+
}
|
|
252
263
|
return { ...base, phase: 'open' };
|
|
253
264
|
}
|
|
254
|
-
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value.frame) || typeof value.frame.data !== 'string')
|
|
265
|
+
if (!(0, NativeEditorResultNormalization_1.isPlainRecord)(value.frame) || typeof value.frame.data !== 'string') {
|
|
255
266
|
return null;
|
|
267
|
+
}
|
|
256
268
|
if (value.frame.type === 'text') {
|
|
257
269
|
return {
|
|
258
270
|
...base,
|
|
@@ -262,8 +274,9 @@ function normalizeNativeCollaborationTransportEvent(value) {
|
|
|
262
274
|
}
|
|
263
275
|
if (value.frame.type === 'binary') {
|
|
264
276
|
const data = decodeNativeCollaborationProtocolBytes(value.frame.data);
|
|
265
|
-
if (data == null)
|
|
277
|
+
if (data == null) {
|
|
266
278
|
return null;
|
|
279
|
+
}
|
|
267
280
|
return {
|
|
268
281
|
...base,
|
|
269
282
|
phase: 'message',
|
|
@@ -96,8 +96,9 @@ function buildV2CreateRequestUnchecked(config) {
|
|
|
96
96
|
if (fragmentName !== undefined && typeof fragmentName !== 'string') {
|
|
97
97
|
throw (0, NativeEditorCreateValidation_1.invalidV2CreateRequestError)('NativeEditorBridge: invalid fragmentName for v2 create');
|
|
98
98
|
}
|
|
99
|
-
if (fragmentName !== undefined)
|
|
99
|
+
if (fragmentName !== undefined) {
|
|
100
100
|
envelope.fragmentName = fragmentName;
|
|
101
|
+
}
|
|
101
102
|
let snapshotState = null;
|
|
102
103
|
const initialization = initializationValue;
|
|
103
104
|
const initializationType = (0, NativeEditorCreateValidation_1.ownV2CreateValue)(initialization, 'type');
|
|
@@ -161,19 +162,22 @@ function buildV2CreateRequestUnchecked(config) {
|
|
|
161
162
|
default:
|
|
162
163
|
throw (0, NativeEditorCreateValidation_1.invalidV2CreateRequestError)('NativeEditorBridge: unknown v2 initialization type');
|
|
163
164
|
}
|
|
164
|
-
if (policy !== undefined)
|
|
165
|
+
if (policy !== undefined) {
|
|
165
166
|
envelope.policy = policy;
|
|
166
|
-
|
|
167
|
+
}
|
|
168
|
+
if (limits !== undefined) {
|
|
167
169
|
envelope.limits = limits;
|
|
170
|
+
}
|
|
168
171
|
return {
|
|
169
172
|
envelope,
|
|
170
|
-
limits
|
|
173
|
+
limits,
|
|
171
174
|
snapshotState,
|
|
172
175
|
};
|
|
173
176
|
}
|
|
174
177
|
function cloneAndFreezeDescriptorValue(value) {
|
|
175
|
-
if (value == null || typeof value !== 'object')
|
|
178
|
+
if (value == null || typeof value !== 'object') {
|
|
176
179
|
return value;
|
|
180
|
+
}
|
|
177
181
|
const setOwnValue = (target, key, child) => {
|
|
178
182
|
Object.defineProperty(target, key, {
|
|
179
183
|
value: child,
|
|
@@ -188,8 +192,9 @@ function cloneAndFreezeDescriptorValue(value) {
|
|
|
188
192
|
const created = [cloneRoot];
|
|
189
193
|
while (pending.length > 0) {
|
|
190
194
|
const current = pending.pop();
|
|
191
|
-
if (current === undefined)
|
|
195
|
+
if (current === undefined) {
|
|
192
196
|
break;
|
|
197
|
+
}
|
|
193
198
|
const keys = Array.isArray(current.source)
|
|
194
199
|
? Array.from({ length: current.source.length }, (_, index) => String(index))
|
|
195
200
|
: Object.keys(current.source);
|
|
@@ -17,8 +17,9 @@ function invalidV2JsonValue(label) {
|
|
|
17
17
|
throw (0, NativeEditorCreateValidation_1.invalidV2CreateRequestError)(`NativeEditorBridge: invalid ${label} for v2 create`);
|
|
18
18
|
}
|
|
19
19
|
function chargeV2JsonWork(state, label) {
|
|
20
|
-
if (state.work >= NativeEditorCreateValidation_1.V2_CREATE_JSON_MAX_WORK)
|
|
20
|
+
if (state.work >= NativeEditorCreateValidation_1.V2_CREATE_JSON_MAX_WORK) {
|
|
21
21
|
invalidV2JsonValue(label);
|
|
22
|
+
}
|
|
22
23
|
state.work += 1;
|
|
23
24
|
}
|
|
24
25
|
function chargeV2JsonBytes(budget, amount, label) {
|
|
@@ -30,8 +31,9 @@ function chargeV2JsonBytes(budget, amount, label) {
|
|
|
30
31
|
budget.bytes += amount;
|
|
31
32
|
}
|
|
32
33
|
function chargeV2JsonSerializationWork(state, label) {
|
|
33
|
-
if (state.work >= NativeEditorCreateValidation_1.V2_CREATE_WIRE_MAX_BYTES)
|
|
34
|
+
if (state.work >= NativeEditorCreateValidation_1.V2_CREATE_WIRE_MAX_BYTES) {
|
|
34
35
|
invalidV2JsonValue(label);
|
|
36
|
+
}
|
|
35
37
|
state.work += 1;
|
|
36
38
|
}
|
|
37
39
|
function chargeV2JsonSerializationBytes(state, amount, label) {
|
|
@@ -71,8 +73,9 @@ function utf8V2JsonByteLength(value) {
|
|
|
71
73
|
return bytes;
|
|
72
74
|
}
|
|
73
75
|
function serializeV2JsonNumber(value, label) {
|
|
74
|
-
if (!Number.isFinite(value))
|
|
76
|
+
if (!Number.isFinite(value)) {
|
|
75
77
|
invalidV2JsonValue(label);
|
|
78
|
+
}
|
|
76
79
|
return value === 0 ? '0' : NativeEditorCreateValidation_1.V2_CREATE_NUMBER_TO_STRING.call(value);
|
|
77
80
|
}
|
|
78
81
|
function chargeV2JsonStringBytes(value, budget, label) {
|
|
@@ -117,15 +120,18 @@ function chargeV2JsonStringBytes(value, budget, label) {
|
|
|
117
120
|
function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
118
121
|
let normalizedRoot;
|
|
119
122
|
const frames = [
|
|
120
|
-
{
|
|
123
|
+
{
|
|
124
|
+
type: 'value', value, depth: 0, target: null, key: null,
|
|
125
|
+
},
|
|
121
126
|
];
|
|
122
127
|
const installNormalizedValue = (target, key, normalized) => {
|
|
123
128
|
if (target === null) {
|
|
124
129
|
normalizedRoot = normalized;
|
|
125
130
|
return;
|
|
126
131
|
}
|
|
127
|
-
if (key === null)
|
|
132
|
+
if (key === null) {
|
|
128
133
|
invalidV2JsonValue(label);
|
|
134
|
+
}
|
|
129
135
|
Object.defineProperty(target, key, {
|
|
130
136
|
configurable: true,
|
|
131
137
|
enumerable: true,
|
|
@@ -135,12 +141,14 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
135
141
|
};
|
|
136
142
|
while (frames.length > 0) {
|
|
137
143
|
const frame = frames.pop();
|
|
138
|
-
if (frame === undefined)
|
|
144
|
+
if (frame === undefined) {
|
|
139
145
|
invalidV2JsonValue(label);
|
|
146
|
+
}
|
|
140
147
|
if (frame.type === 'array') {
|
|
141
148
|
if (frame.nextKeyIndex === frame.keys.length) {
|
|
142
|
-
if (frame.elementCount !== frame.length)
|
|
149
|
+
if (frame.elementCount !== frame.length) {
|
|
143
150
|
invalidV2JsonValue(label);
|
|
151
|
+
}
|
|
144
152
|
Object.setPrototypeOf(frame.normalized, null);
|
|
145
153
|
continue;
|
|
146
154
|
}
|
|
@@ -165,8 +173,9 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
165
173
|
descriptor.enumerable !== true) {
|
|
166
174
|
invalidV2JsonValue(label);
|
|
167
175
|
}
|
|
168
|
-
if (frame.elementCount > 0)
|
|
176
|
+
if (frame.elementCount > 0) {
|
|
169
177
|
chargeV2JsonBytes(budget, 1, label);
|
|
178
|
+
}
|
|
170
179
|
frames.push({
|
|
171
180
|
...frame,
|
|
172
181
|
nextKeyIndex: frame.nextKeyIndex + 1,
|
|
@@ -182,11 +191,13 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
182
191
|
continue;
|
|
183
192
|
}
|
|
184
193
|
if (frame.type === 'object') {
|
|
185
|
-
if (frame.nextKeyIndex === frame.keys.length)
|
|
194
|
+
if (frame.nextKeyIndex === frame.keys.length) {
|
|
186
195
|
continue;
|
|
196
|
+
}
|
|
187
197
|
const key = frame.keys[frame.nextKeyIndex];
|
|
188
|
-
if (typeof key !== 'string')
|
|
198
|
+
if (typeof key !== 'string') {
|
|
189
199
|
invalidV2JsonValue(label);
|
|
200
|
+
}
|
|
190
201
|
const descriptor = Object.getOwnPropertyDescriptor(frame.value, key);
|
|
191
202
|
if (descriptor === undefined ||
|
|
192
203
|
!('value' in descriptor) ||
|
|
@@ -200,8 +211,9 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
200
211
|
});
|
|
201
212
|
continue;
|
|
202
213
|
}
|
|
203
|
-
if (frame.fieldCount > 0)
|
|
214
|
+
if (frame.fieldCount > 0) {
|
|
204
215
|
chargeV2JsonBytes(budget, 1, label);
|
|
216
|
+
}
|
|
205
217
|
chargeV2JsonStringBytes(key, budget, label);
|
|
206
218
|
chargeV2JsonBytes(budget, 1, label);
|
|
207
219
|
frames.push({
|
|
@@ -218,8 +230,9 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
218
230
|
});
|
|
219
231
|
continue;
|
|
220
232
|
}
|
|
221
|
-
if (frame.depth > NativeEditorCreateValidation_1.V2_CREATE_JSON_MAX_DEPTH)
|
|
233
|
+
if (frame.depth > NativeEditorCreateValidation_1.V2_CREATE_JSON_MAX_DEPTH) {
|
|
222
234
|
invalidV2JsonValue(label);
|
|
235
|
+
}
|
|
223
236
|
chargeV2JsonWork(traversal, label);
|
|
224
237
|
if (frame.value === null) {
|
|
225
238
|
chargeV2JsonBytes(budget, 4, label);
|
|
@@ -242,17 +255,20 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
242
255
|
installNormalizedValue(frame.target, frame.key, frame.value);
|
|
243
256
|
continue;
|
|
244
257
|
}
|
|
245
|
-
if (typeof frame.value !== 'object')
|
|
258
|
+
if (typeof frame.value !== 'object') {
|
|
246
259
|
invalidV2JsonValue(label);
|
|
247
|
-
|
|
260
|
+
}
|
|
261
|
+
if (traversal.seen.has(frame.value)) {
|
|
248
262
|
invalidV2JsonValue(label);
|
|
263
|
+
}
|
|
249
264
|
traversal.seen.add(frame.value);
|
|
250
265
|
chargeV2JsonBytes(budget, 2, label);
|
|
251
266
|
const childDepth = frame.depth + 1;
|
|
252
267
|
if (Array.isArray(frame.value)) {
|
|
253
268
|
const prototype = Object.getPrototypeOf(frame.value);
|
|
254
|
-
if (prototype !== Array.prototype && prototype !== null)
|
|
269
|
+
if (prototype !== Array.prototype && prototype !== null) {
|
|
255
270
|
invalidV2JsonValue(label);
|
|
271
|
+
}
|
|
256
272
|
const lengthDescriptor = Object.getOwnPropertyDescriptor(frame.value, 'length');
|
|
257
273
|
if (lengthDescriptor === undefined ||
|
|
258
274
|
!('value' in lengthDescriptor) ||
|
|
@@ -273,8 +289,9 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
273
289
|
});
|
|
274
290
|
continue;
|
|
275
291
|
}
|
|
276
|
-
if (!(0, NativeEditorCreateValidation_1.isV2CreateRecord)(frame.value))
|
|
292
|
+
if (!(0, NativeEditorCreateValidation_1.isV2CreateRecord)(frame.value)) {
|
|
277
293
|
invalidV2JsonValue(label);
|
|
294
|
+
}
|
|
278
295
|
const normalized = (0, NativeEditorCreateValidation_1.emptyV2CreateRecord)();
|
|
279
296
|
installNormalizedValue(frame.target, frame.key, normalized);
|
|
280
297
|
frames.push({
|
|
@@ -287,8 +304,9 @@ function normalizeV2JsonValue(value, label, traversal, budget = { bytes: 0 }) {
|
|
|
287
304
|
fieldCount: 0,
|
|
288
305
|
});
|
|
289
306
|
}
|
|
290
|
-
if (normalizedRoot === undefined)
|
|
307
|
+
if (normalizedRoot === undefined) {
|
|
291
308
|
invalidV2JsonValue(label);
|
|
309
|
+
}
|
|
292
310
|
return normalizedRoot;
|
|
293
311
|
}
|
|
294
312
|
class V2JsonSerializationWriter {
|
|
@@ -305,8 +323,9 @@ class V2JsonSerializationWriter {
|
|
|
305
323
|
}
|
|
306
324
|
}
|
|
307
325
|
finish() {
|
|
308
|
-
if (this._current.length > 0)
|
|
326
|
+
if (this._current.length > 0) {
|
|
309
327
|
this._chunks.push(this._current);
|
|
328
|
+
}
|
|
310
329
|
return this._chunks.join('');
|
|
311
330
|
}
|
|
312
331
|
}
|
|
@@ -361,8 +380,9 @@ function appendV2JsonString(writer, value, state, label) {
|
|
|
361
380
|
}
|
|
362
381
|
break;
|
|
363
382
|
}
|
|
364
|
-
if (escape === undefined)
|
|
383
|
+
if (escape === undefined) {
|
|
365
384
|
continue;
|
|
385
|
+
}
|
|
366
386
|
if (segmentStart < index) {
|
|
367
387
|
writer.append(NativeEditorCreateValidation_1.V2_CREATE_STRING_SLICE.call(value, segmentStart, index), state, label);
|
|
368
388
|
}
|
|
@@ -381,15 +401,17 @@ function serializeV2CreateEnvelope(value) {
|
|
|
381
401
|
const frames = [{ type: 'value', value, depth: 0 }];
|
|
382
402
|
while (frames.length > 0) {
|
|
383
403
|
const frame = frames.pop();
|
|
384
|
-
if (frame === undefined)
|
|
404
|
+
if (frame === undefined) {
|
|
385
405
|
invalidV2JsonValue(label);
|
|
406
|
+
}
|
|
386
407
|
if (frame.type === 'array') {
|
|
387
408
|
if (frame.index === frame.length) {
|
|
388
409
|
writer.append(']', state, label);
|
|
389
410
|
continue;
|
|
390
411
|
}
|
|
391
|
-
if (frame.index > 0)
|
|
412
|
+
if (frame.index > 0) {
|
|
392
413
|
writer.append(',', state, label);
|
|
414
|
+
}
|
|
393
415
|
const descriptor = Object.getOwnPropertyDescriptor(frame.value, String(frame.index));
|
|
394
416
|
if (descriptor === undefined ||
|
|
395
417
|
!('value' in descriptor) ||
|
|
@@ -405,8 +427,9 @@ function serializeV2CreateEnvelope(value) {
|
|
|
405
427
|
writer.append('}', state, label);
|
|
406
428
|
continue;
|
|
407
429
|
}
|
|
408
|
-
if (frame.index > 0)
|
|
430
|
+
if (frame.index > 0) {
|
|
409
431
|
writer.append(',', state, label);
|
|
432
|
+
}
|
|
410
433
|
const key = frame.keys[frame.index];
|
|
411
434
|
const descriptor = Object.getOwnPropertyDescriptor(frame.value, key);
|
|
412
435
|
if (descriptor === undefined ||
|
|
@@ -420,8 +443,9 @@ function serializeV2CreateEnvelope(value) {
|
|
|
420
443
|
frames.push({ type: 'value', value: descriptor.value, depth: frame.depth + 1 });
|
|
421
444
|
continue;
|
|
422
445
|
}
|
|
423
|
-
if (frame.depth > NativeEditorCreateValidation_1.V2_CREATE_ENVELOPE_JSON_MAX_DEPTH)
|
|
446
|
+
if (frame.depth > NativeEditorCreateValidation_1.V2_CREATE_ENVELOPE_JSON_MAX_DEPTH) {
|
|
424
447
|
invalidV2JsonValue(label);
|
|
448
|
+
}
|
|
425
449
|
chargeV2JsonSerializationWork(state, label);
|
|
426
450
|
if (frame.value === null) {
|
|
427
451
|
writer.append('null', state, label);
|
|
@@ -436,8 +460,9 @@ function serializeV2CreateEnvelope(value) {
|
|
|
436
460
|
writer.append(serializeV2JsonNumber(frame.value, label), state, label);
|
|
437
461
|
}
|
|
438
462
|
else if (Array.isArray(frame.value)) {
|
|
439
|
-
if (Object.getPrototypeOf(frame.value) !== null)
|
|
463
|
+
if (Object.getPrototypeOf(frame.value) !== null) {
|
|
440
464
|
invalidV2JsonValue(label);
|
|
465
|
+
}
|
|
441
466
|
const lengthDescriptor = Object.getOwnPropertyDescriptor(frame.value, 'length');
|
|
442
467
|
if (lengthDescriptor === undefined ||
|
|
443
468
|
!('value' in lengthDescriptor) ||
|
|
@@ -455,8 +480,9 @@ function serializeV2CreateEnvelope(value) {
|
|
|
455
480
|
}
|
|
456
481
|
else if ((0, NativeEditorCreateValidation_1.isV2CreateRecord)(frame.value) && Object.getPrototypeOf(frame.value) === null) {
|
|
457
482
|
const keys = Reflect.ownKeys(frame.value);
|
|
458
|
-
if (keys.some(
|
|
483
|
+
if (keys.some(key => typeof key !== 'string')) {
|
|
459
484
|
invalidV2JsonValue(label);
|
|
485
|
+
}
|
|
460
486
|
writer.append('{', state, label);
|
|
461
487
|
frames.push({
|
|
462
488
|
type: 'object',
|
|
@@ -92,8 +92,9 @@ function validateV2CreateLimits(limits) {
|
|
|
92
92
|
(0, ResourceLimits_1.validateEditorCreateLimits)(limits);
|
|
93
93
|
}
|
|
94
94
|
catch (error) {
|
|
95
|
-
if (!(error instanceof NativeEditorBoundaryError_1.NativeEditorBoundaryError))
|
|
95
|
+
if (!(error instanceof NativeEditorBoundaryError_1.NativeEditorBoundaryError)) {
|
|
96
96
|
throw error;
|
|
97
|
+
}
|
|
97
98
|
throw new NativeEditorBoundaryError_1.NativeEditorEngineBoundaryError({
|
|
98
99
|
domain: 'boundary',
|
|
99
100
|
code: error.code,
|
|
@@ -110,8 +111,9 @@ function emptyV2CreateRecord() {
|
|
|
110
111
|
return Object.create(null);
|
|
111
112
|
}
|
|
112
113
|
function isV2CreateRecord(value) {
|
|
113
|
-
if (value == null || typeof value !== 'object' || Array.isArray(value))
|
|
114
|
+
if (value == null || typeof value !== 'object' || Array.isArray(value)) {
|
|
114
115
|
return false;
|
|
116
|
+
}
|
|
115
117
|
const prototype = Object.getPrototypeOf(value);
|
|
116
118
|
return prototype === Object.prototype || prototype === null;
|
|
117
119
|
}
|
|
@@ -120,8 +122,9 @@ function hasOwnV2CreateKey(value, key) {
|
|
|
120
122
|
}
|
|
121
123
|
function ownV2CreateValue(value, key) {
|
|
122
124
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
123
|
-
if (descriptor === undefined)
|
|
125
|
+
if (descriptor === undefined) {
|
|
124
126
|
return undefined;
|
|
127
|
+
}
|
|
125
128
|
if (!('value' in descriptor)) {
|
|
126
129
|
throw invalidV2CreateRequestError(`NativeEditorBridge: accessor ${key} is not allowed for v2 create`);
|
|
127
130
|
}
|
|
@@ -129,7 +132,7 @@ function ownV2CreateValue(value, key) {
|
|
|
129
132
|
}
|
|
130
133
|
function requireKnownV2CreateKeys(value, allowed, label) {
|
|
131
134
|
if (!isV2CreateRecord(value) ||
|
|
132
|
-
Reflect.ownKeys(value).some(
|
|
135
|
+
Reflect.ownKeys(value).some(key => typeof key !== 'string' || !allowed.has(key))) {
|
|
133
136
|
throw invalidV2CreateRequestError(`NativeEditorBridge: invalid ${label} for v2 create`);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
@@ -137,14 +140,16 @@ function normalizeV2CreateRecord(value, allowed, label) {
|
|
|
137
140
|
requireKnownV2CreateKeys(value, allowed, label);
|
|
138
141
|
const normalized = emptyV2CreateRecord();
|
|
139
142
|
for (const key of allowed) {
|
|
140
|
-
if (!hasOwnV2CreateKey(value, key))
|
|
143
|
+
if (!hasOwnV2CreateKey(value, key)) {
|
|
141
144
|
continue;
|
|
145
|
+
}
|
|
142
146
|
const fieldValue = ownV2CreateValue(value, key);
|
|
143
147
|
if (fieldValue === null) {
|
|
144
148
|
throw invalidV2CreateRequestError(`NativeEditorBridge: invalid ${label} for v2 create`);
|
|
145
149
|
}
|
|
146
|
-
if (fieldValue !== undefined)
|
|
150
|
+
if (fieldValue !== undefined) {
|
|
147
151
|
normalized[key] = fieldValue;
|
|
152
|
+
}
|
|
148
153
|
}
|
|
149
154
|
return normalized;
|
|
150
155
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeEditorErrorBase } from './NativeEditorBoundaryError';
|
|
1
|
+
import { type NativeEditorErrorBase } from './NativeEditorBoundaryError';
|
|
2
2
|
import { type NativeCollaborationTransportConfig, type NativeCollaborationTransportEvent } from './NativeEditorCollaborationTransport';
|
|
3
3
|
import { type NativeEditorState, type NativeEditorCommitInfo, type NativeEditorMutationOutcome } from './NativeEditorResultNormalization';
|
|
4
4
|
import { type DocumentJSON, type ContentSnapshot, type NativeEditorAtomicRenderSnapshot, type NativeEditorReplaceDocumentRequest, type NativeEditorInputRequest, type NativeEditorCommandRequest, type NativeEditorLocalApiRequest, type NativeEditorSelectionRequest, type NativeEditorSnapshotMetadata, type NativeEditorLocalAwarenessIntent } from './NativeEditorTypes';
|
|
@@ -32,16 +32,18 @@ class NativeEditorDocumentBridge {
|
|
|
32
32
|
return this._destroyed;
|
|
33
33
|
}
|
|
34
34
|
assertAlive() {
|
|
35
|
-
if (this._destroyed)
|
|
35
|
+
if (this._destroyed) {
|
|
36
36
|
throw (0, NativeEditorResultNormalization_1.destroyedHandleError)();
|
|
37
|
+
}
|
|
37
38
|
}
|
|
38
39
|
callV2(invoke, normalizeValue) {
|
|
39
40
|
this.assertAlive();
|
|
40
41
|
const raw = invoke();
|
|
41
42
|
// A re-entrant destroy racing the native call makes any result
|
|
42
43
|
// arriving now a result for a destroyed handle: non-retryable.
|
|
43
|
-
if (this._destroyed)
|
|
44
|
+
if (this._destroyed) {
|
|
44
45
|
throw (0, NativeEditorResultNormalization_1.destroyedHandleError)();
|
|
46
|
+
}
|
|
45
47
|
return (0, NativeEditorResultNormalization_1.unwrapNativeEditorV2Result)(raw, normalizeValue);
|
|
46
48
|
}
|
|
47
49
|
nextRequestId() {
|
|
@@ -65,14 +67,16 @@ class NativeEditorDocumentBridge {
|
|
|
65
67
|
}
|
|
66
68
|
const payloadJson = JSON.stringify(payload);
|
|
67
69
|
const inner = payloadJson.slice(1, payloadJson.length - 1);
|
|
68
|
-
if (inner.length > 0)
|
|
70
|
+
if (inner.length > 0) {
|
|
69
71
|
parts.push(inner);
|
|
72
|
+
}
|
|
70
73
|
return `{${parts.join(',')}}`;
|
|
71
74
|
}
|
|
72
75
|
/** Destroy the session. Repeated destroy is safe. */
|
|
73
76
|
destroy() {
|
|
74
|
-
if (this._destroyed)
|
|
77
|
+
if (this._destroyed) {
|
|
75
78
|
return;
|
|
79
|
+
}
|
|
76
80
|
try {
|
|
77
81
|
(0, NativeEditorResultNormalization_1.unwrapNativeEditorV2Result)((0, NativeEditorNativeModule_1.invokeNativeEditorV2)('editorV2Destroy', this._editorId), NativeEditorResultNormalization_1.normalizeNativeEditorV2Unit);
|
|
78
82
|
}
|
|
@@ -108,8 +112,9 @@ class NativeEditorDocumentBridge {
|
|
|
108
112
|
* contract violation so the view stays usable.
|
|
109
113
|
*/
|
|
110
114
|
_emitAutonomousError(raw) {
|
|
111
|
-
if (this._destroyed)
|
|
115
|
+
if (this._destroyed) {
|
|
112
116
|
return;
|
|
117
|
+
}
|
|
113
118
|
const candidate = (0, NativeEditorResultNormalization_1.isPlainRecord)(raw) && 'error' in raw ? raw : { error: raw };
|
|
114
119
|
const normalized = (0, NativeEditorBoundaryError_1.normalizeNativeEditorV2Error)(candidate);
|
|
115
120
|
const exception = normalized == null
|
|
@@ -144,19 +149,23 @@ class NativeEditorDocumentBridge {
|
|
|
144
149
|
if ((mirrorAnchor == null) !== (mirrorHead == null)) {
|
|
145
150
|
throw (0, NativeEditorResultNormalization_1.invalidV2RequestError)('NativeEditorBridge: render update mirror requires both scalar anchor and head');
|
|
146
151
|
}
|
|
147
|
-
if (mirrorAnchor != null)
|
|
152
|
+
if (mirrorAnchor != null) {
|
|
148
153
|
(0, NativeEditorResultNormalization_1.requireNativeEditorV2U32)(mirrorAnchor, 'mirrorScalarAnchor');
|
|
149
|
-
|
|
154
|
+
}
|
|
155
|
+
if (mirrorHead != null) {
|
|
150
156
|
(0, NativeEditorResultNormalization_1.requireNativeEditorV2U32)(mirrorHead, 'mirrorScalarHead');
|
|
157
|
+
}
|
|
151
158
|
return this.callV2(() => (0, NativeEditorNativeModule_1.invokeNativeEditorV2)('editorV2RenderUpdate', this._editorId, mirrorAnchor, mirrorHead), NativeEditorRenderNormalization_1.normalizeNativeEditorV2RenderUpdateValue);
|
|
152
159
|
}
|
|
153
160
|
replaceDocument(request) {
|
|
154
161
|
this.assertAlive();
|
|
155
162
|
const payload = {};
|
|
156
|
-
if (request.setJson !== undefined)
|
|
163
|
+
if (request.setJson !== undefined) {
|
|
157
164
|
payload.setJson = request.setJson;
|
|
158
|
-
|
|
165
|
+
}
|
|
166
|
+
if (request.setHtml !== undefined) {
|
|
159
167
|
payload.setHtml = request.setHtml;
|
|
168
|
+
}
|
|
160
169
|
payload.history = request.history;
|
|
161
170
|
const requestJson = this.buildEnvelopeJson(payload);
|
|
162
171
|
const result = this.callV2(() => (0, NativeEditorNativeModule_1.invokeNativeEditorV2)('editorV2ReplaceDocument', this._editorId, requestJson), NativeEditorResultNormalization_1.normalizeNativeEditorV2CommitValue);
|
|
@@ -183,10 +192,12 @@ class NativeEditorDocumentBridge {
|
|
|
183
192
|
applyLocalApi(request) {
|
|
184
193
|
this.assertAlive();
|
|
185
194
|
const payload = {};
|
|
186
|
-
if (request.setJson !== undefined)
|
|
195
|
+
if (request.setJson !== undefined) {
|
|
187
196
|
payload.setJson = request.setJson;
|
|
188
|
-
|
|
197
|
+
}
|
|
198
|
+
if (request.setHtml !== undefined) {
|
|
189
199
|
payload.setHtml = request.setHtml;
|
|
200
|
+
}
|
|
190
201
|
payload.history = request.history;
|
|
191
202
|
const requestJson = this.buildEnvelopeJson(payload, request.baseDocumentRevision);
|
|
192
203
|
const result = this.callV2(() => (0, NativeEditorNativeModule_1.invokeNativeEditorV2)('editorV2ApplyLocalApi', this._editorId, requestJson), NativeEditorResultNormalization_1.normalizeNativeEditorV2MutationOutcomeValue);
|
|
@@ -229,7 +240,7 @@ class NativeEditorDocumentBridge {
|
|
|
229
240
|
const previousAdapter = this._collaborationProtocolAdapter;
|
|
230
241
|
const nextAdapter = config?.protocolAdapter ?? null;
|
|
231
242
|
if (nextAdapter !== null && this._collaborationProtocolAdapterSubscription === null) {
|
|
232
|
-
this._collaborationProtocolAdapterSubscription = (0, NativeEditorNativeModule_1.getNativeModule)().addListener('onCollaborationTransportEvent',
|
|
243
|
+
this._collaborationProtocolAdapterSubscription = (0, NativeEditorNativeModule_1.getNativeModule)().addListener('onCollaborationTransportEvent', rawEvent => this.handleCollaborationProtocolAdapterEvent(rawEvent));
|
|
233
244
|
}
|
|
234
245
|
this._collaborationProtocolAdapter = nextAdapter;
|
|
235
246
|
try {
|
|
@@ -250,8 +261,9 @@ class NativeEditorDocumentBridge {
|
|
|
250
261
|
}
|
|
251
262
|
}
|
|
252
263
|
handleCollaborationProtocolAdapterEvent(rawEvent) {
|
|
253
|
-
if (this._destroyed || this._collaborationProtocolAdapter === null)
|
|
264
|
+
if (this._destroyed || this._collaborationProtocolAdapter === null) {
|
|
254
265
|
return;
|
|
266
|
+
}
|
|
255
267
|
const event = (0, NativeEditorCollaborationTransport_1.normalizeNativeCollaborationTransportEvent)(rawEvent);
|
|
256
268
|
if (event?.editorId !== this._editorId || event.kind !== 'protocolAdapter') {
|
|
257
269
|
return;
|
|
@@ -267,11 +279,12 @@ class NativeEditorDocumentBridge {
|
|
|
267
279
|
: () => adapter.onMessage(context, event.frame);
|
|
268
280
|
void Promise.resolve()
|
|
269
281
|
.then(callback)
|
|
270
|
-
.then(
|
|
282
|
+
.then(result => (0, NativeEditorCollaborationTransport_1.serializeCollaborationProtocolAdapterResult)(result))
|
|
271
283
|
.catch(() => '{"action":"reject"}')
|
|
272
|
-
.then(
|
|
273
|
-
if (this._destroyed)
|
|
284
|
+
.then(responseJson => {
|
|
285
|
+
if (this._destroyed) {
|
|
274
286
|
return;
|
|
287
|
+
}
|
|
275
288
|
try {
|
|
276
289
|
this.callV2(() => (0, NativeEditorNativeModule_1.invokeNativeEditorV2)('editorV2CollaborationResolveProtocolAdapter', this._editorId, event.attemptId, event.eventId, responseJson), NativeEditorResultNormalization_1.normalizeNativeEditorV2Unit);
|
|
277
290
|
}
|
|
@@ -291,9 +304,10 @@ class NativeEditorDocumentBridge {
|
|
|
291
304
|
}
|
|
292
305
|
addCollaborationTransportListener(listener) {
|
|
293
306
|
this.assertAlive();
|
|
294
|
-
const subscription = (0, NativeEditorNativeModule_1.getNativeModule)().addListener('onCollaborationTransportEvent',
|
|
295
|
-
if (this._destroyed)
|
|
307
|
+
const subscription = (0, NativeEditorNativeModule_1.getNativeModule)().addListener('onCollaborationTransportEvent', rawEvent => {
|
|
308
|
+
if (this._destroyed) {
|
|
296
309
|
return;
|
|
310
|
+
}
|
|
297
311
|
const event = (0, NativeEditorCollaborationTransport_1.normalizeNativeCollaborationTransportEvent)(rawEvent);
|
|
298
312
|
if (event?.editorId === this._editorId) {
|
|
299
313
|
listener(event);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ResolvedDocumentSchema } from './schemas';
|
|
2
|
-
import { NativeEditorErrorBase } from './NativeEditorBoundaryError';
|
|
2
|
+
import { type NativeEditorErrorBase } from './NativeEditorBoundaryError';
|
|
3
3
|
import { NativeEditorDocumentBridge } from './NativeEditorDocumentBridge';
|
|
4
4
|
import { type NativeCollaborationTransportConfig, type NativeCollaborationTransportEvent } from './NativeEditorCollaborationTransport';
|
|
5
5
|
import { type NativeEditorLocalAwarenessIntent, type NativeEditorCreateConfig } from './NativeEditorTypes';
|
|
@@ -11,8 +11,8 @@ export declare const NATIVE_EDITOR_DOCUMENT_HANDLE_DESCRIPTORS: WeakMap<object,
|
|
|
11
11
|
* One native document session, shared by everything that touches the
|
|
12
12
|
* document: the editor view, the headless `useNativeEditorDocument` binding,
|
|
13
13
|
* and the collaboration controller. Obtain one from
|
|
14
|
-
* {@link createNativeEditorDocumentHandle}
|
|
15
|
-
* directly
|
|
14
|
+
* {@link createNativeEditorDocumentHandle} : it cannot be constructed
|
|
15
|
+
* directly : and `destroy()` it when its owner unmounts.
|
|
16
16
|
*/
|
|
17
17
|
export interface NativeEditorDocumentHandle {
|
|
18
18
|
readonly [NATIVE_EDITOR_DOCUMENT_HANDLE_BRAND]: true;
|
|
@@ -50,7 +50,7 @@ export declare function _getNativeEditorDocumentHandleDescriptor(handle: NativeE
|
|
|
50
50
|
export declare function _assertNativeEditorDocumentHandle(value: unknown): asserts value is NativeEditorDocumentHandle;
|
|
51
51
|
/**
|
|
52
52
|
* Create the native document session every other API binds to. Create it once
|
|
53
|
-
* per document
|
|
53
|
+
* per document : `useMemo`, not on each render : and destroy it when its
|
|
54
54
|
* owner unmounts.
|
|
55
55
|
*
|
|
56
56
|
* @throws NativeEditorErrorBase when the config is rejected: a malformed
|
|
@@ -65,7 +65,7 @@ function _assertNativeEditorDocumentHandle(value) {
|
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Create the native document session every other API binds to. Create it once
|
|
68
|
-
* per document
|
|
68
|
+
* per document : `useMemo`, not on each render : and destroy it when its
|
|
69
69
|
* owner unmounts.
|
|
70
70
|
*
|
|
71
71
|
* @throws NativeEditorErrorBase when the config is rejected: a malformed
|