@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
|
@@ -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
|
|
@@ -27,16 +27,18 @@ function invalidLocalAwarenessIntent(message = 'invalid local awareness intent')
|
|
|
27
27
|
function createNativeEditorLocalAwarenessSelection(anchor, head) {
|
|
28
28
|
const acceptedAnchor = (0, NativeEditorResultNormalization_1.nativeEditorV2U32)(anchor);
|
|
29
29
|
const acceptedHead = (0, NativeEditorResultNormalization_1.nativeEditorV2U32)(head);
|
|
30
|
-
if (acceptedAnchor == null || acceptedHead == null)
|
|
30
|
+
if (acceptedAnchor == null || acceptedHead == null) {
|
|
31
31
|
invalidLocalAwarenessIntent();
|
|
32
|
+
}
|
|
32
33
|
const selection = new NativeEditorTypes_1.NativeEditorLocalAwarenessSelectionValue(acceptedAnchor, acceptedHead);
|
|
33
34
|
Object.freeze(selection);
|
|
34
35
|
exports.LOCAL_AWARENESS_SELECTION_VALUES.set(selection, selection);
|
|
35
36
|
return selection;
|
|
36
37
|
}
|
|
37
38
|
function isLocalAwarenessRecord(value) {
|
|
38
|
-
if (value == null || typeof value !== 'object' || Array.isArray(value))
|
|
39
|
+
if (value == null || typeof value !== 'object' || Array.isArray(value)) {
|
|
39
40
|
return false;
|
|
41
|
+
}
|
|
40
42
|
const prototype = Object.getPrototypeOf(value);
|
|
41
43
|
return prototype === Object.prototype || prototype === null;
|
|
42
44
|
}
|
|
@@ -48,14 +50,16 @@ function localAwarenessOwnDataValue(record, key) {
|
|
|
48
50
|
return descriptor.value;
|
|
49
51
|
}
|
|
50
52
|
function validateLocalAwarenessSelection(selection) {
|
|
51
|
-
if (selection == null || typeof selection !== 'object')
|
|
53
|
+
if (selection == null || typeof selection !== 'object') {
|
|
52
54
|
invalidLocalAwarenessIntent();
|
|
55
|
+
}
|
|
53
56
|
// Do not inspect caller-held values before provenance succeeds: a Proxy
|
|
54
57
|
// can imitate every structural and own-data check, but it cannot inherit
|
|
55
58
|
// this module's WeakMap identity.
|
|
56
59
|
const factoryValue = exports.LOCAL_AWARENESS_SELECTION_VALUES.get(selection);
|
|
57
|
-
if (factoryValue === undefined)
|
|
60
|
+
if (factoryValue === undefined) {
|
|
58
61
|
invalidLocalAwarenessIntent();
|
|
62
|
+
}
|
|
59
63
|
const anchor = (0, NativeEditorResultNormalization_1.nativeEditorV2U32)(factoryValue.anchor);
|
|
60
64
|
const head = (0, NativeEditorResultNormalization_1.nativeEditorV2U32)(factoryValue.head);
|
|
61
65
|
if (anchor == null || head == null) {
|
|
@@ -69,17 +73,21 @@ function rejectReservedAwarenessCursor(value) {
|
|
|
69
73
|
const seen = new WeakSet();
|
|
70
74
|
while (pending.length > 0) {
|
|
71
75
|
const current = pending.pop();
|
|
72
|
-
if (current == null || typeof current !== 'object')
|
|
76
|
+
if (current == null || typeof current !== 'object') {
|
|
73
77
|
continue;
|
|
74
|
-
|
|
78
|
+
}
|
|
79
|
+
if (seen.has(current)) {
|
|
75
80
|
continue;
|
|
81
|
+
}
|
|
76
82
|
seen.add(current);
|
|
77
83
|
for (const key of Reflect.ownKeys(current)) {
|
|
78
|
-
if (key === 'cursor')
|
|
84
|
+
if (key === 'cursor') {
|
|
79
85
|
invalidLocalAwarenessIntent('reserved cursor key is not allowed');
|
|
86
|
+
}
|
|
80
87
|
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
81
|
-
if (descriptor == null || !('value' in descriptor))
|
|
88
|
+
if (descriptor == null || !('value' in descriptor)) {
|
|
82
89
|
invalidLocalAwarenessIntent();
|
|
90
|
+
}
|
|
83
91
|
pending.push(descriptor.value);
|
|
84
92
|
}
|
|
85
93
|
}
|
|
@@ -97,36 +105,40 @@ function normalizeLocalAwarenessState(value) {
|
|
|
97
105
|
return normalized;
|
|
98
106
|
}
|
|
99
107
|
catch (error) {
|
|
100
|
-
if (error instanceof NativeEditorBoundaryError_1.NativeEditorEngineBoundaryError)
|
|
108
|
+
if (error instanceof NativeEditorBoundaryError_1.NativeEditorEngineBoundaryError) {
|
|
101
109
|
throw error;
|
|
110
|
+
}
|
|
102
111
|
invalidLocalAwarenessIntent();
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
114
|
function validateLocalAwarenessIntent(intent) {
|
|
106
115
|
try {
|
|
107
116
|
if (!isLocalAwarenessRecord(intent) ||
|
|
108
|
-
Reflect.ownKeys(intent).some(
|
|
117
|
+
Reflect.ownKeys(intent).some(key => typeof key !== 'string' || !exports.LOCAL_AWARENESS_INTENT_KEYS.has(key)) ||
|
|
109
118
|
!Object.prototype.hasOwnProperty.call(intent, 'state') ||
|
|
110
119
|
!Object.prototype.hasOwnProperty.call(intent, 'focused')) {
|
|
111
120
|
invalidLocalAwarenessIntent();
|
|
112
121
|
}
|
|
113
122
|
const state = normalizeLocalAwarenessState(localAwarenessOwnDataValue(intent, 'state'));
|
|
114
123
|
const focused = localAwarenessOwnDataValue(intent, 'focused');
|
|
115
|
-
if (typeof focused !== 'boolean')
|
|
124
|
+
if (typeof focused !== 'boolean') {
|
|
116
125
|
invalidLocalAwarenessIntent();
|
|
126
|
+
}
|
|
117
127
|
if (!Object.prototype.hasOwnProperty.call(intent, 'selection')) {
|
|
118
128
|
// Absent: retain whatever cursor Rust already holds.
|
|
119
129
|
return { state, focused };
|
|
120
130
|
}
|
|
121
131
|
const rawSelection = localAwarenessOwnDataValue(intent, 'selection');
|
|
122
|
-
if (rawSelection === null)
|
|
132
|
+
if (rawSelection === null) {
|
|
123
133
|
return { state, focused, selection: null };
|
|
134
|
+
}
|
|
124
135
|
const selection = validateLocalAwarenessSelection(rawSelection);
|
|
125
136
|
return { state, focused, selection: { type: 'text', ...selection } };
|
|
126
137
|
}
|
|
127
138
|
catch (error) {
|
|
128
|
-
if (error instanceof NativeEditorBoundaryError_1.NativeEditorEngineBoundaryError)
|
|
139
|
+
if (error instanceof NativeEditorBoundaryError_1.NativeEditorEngineBoundaryError) {
|
|
129
140
|
throw error;
|
|
141
|
+
}
|
|
130
142
|
invalidLocalAwarenessIntent();
|
|
131
143
|
}
|
|
132
144
|
}
|
|
@@ -3,11 +3,18 @@ export declare let _nativeModule: NativeEditorModule | null;
|
|
|
3
3
|
export declare function getNativeModule(): NativeEditorModule;
|
|
4
4
|
/** @internal Reset the cached native module reference. For testing only. */
|
|
5
5
|
export declare function _resetNativeModuleCache(): void;
|
|
6
|
+
/**
|
|
7
|
+
* The only construction path. Consumes the frozen v2 result records
|
|
8
|
+
* ({ value, error }, exactly one side set), normalizes them at the JS boundary
|
|
9
|
+
* (decimal-string u64s, direct binaries, unsafe-integer rejection), and raises
|
|
10
|
+
* typed per-domain errors with a non-retryable class for
|
|
11
|
+
* ENGINE_INVARIANT_FAILED and destroyed lifecycles.
|
|
12
|
+
*/
|
|
6
13
|
export declare const ERR_V2_NATIVE_RESPONSE = "NativeEditorBridge: invalid v2 result record from native module";
|
|
7
14
|
export declare const ERR_V2_DESTROYED = "NativeEditorBridge: v2 editor handle has been destroyed";
|
|
8
15
|
export declare const V2_ENVELOPE_VERSION = 1;
|
|
9
16
|
/**
|
|
10
|
-
* The v2 surface of the NativeEditor native module
|
|
17
|
+
* The v2 surface of the NativeEditor native module : the complete
|
|
11
18
|
* production ABI. Every call resolves the method lazily and fails clearly
|
|
12
19
|
* when the v2 surface is absent. Decimal-string identifiers keep full u64
|
|
13
20
|
* fidelity across the JavaScript boundary, and binaries travel as direct
|
|
@@ -16,11 +16,13 @@ function getNativeModule() {
|
|
|
16
16
|
function _resetNativeModuleCache() {
|
|
17
17
|
exports._nativeModule = null;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The only construction path. Consumes the frozen v2 result records
|
|
21
|
+
* ({ value, error }, exactly one side set), normalizes them at the JS boundary
|
|
22
|
+
* (decimal-string u64s, direct binaries, unsafe-integer rejection), and raises
|
|
23
|
+
* typed per-domain errors with a non-retryable class for
|
|
24
|
+
* ENGINE_INVARIANT_FAILED and destroyed lifecycles.
|
|
25
|
+
*/
|
|
24
26
|
exports.ERR_V2_NATIVE_RESPONSE = 'NativeEditorBridge: invalid v2 result record from native module';
|
|
25
27
|
exports.ERR_V2_DESTROYED = 'NativeEditorBridge: v2 editor handle has been destroyed';
|
|
26
28
|
exports.V2_ENVELOPE_VERSION = 1;
|