@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
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
type ResolvedDocumentSchema,
|
|
4
4
|
type SchemaDefinition,
|
|
5
5
|
} from './schemas';
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
import {
|
|
8
8
|
normalizeV2CreateRecord,
|
|
9
9
|
V2_CREATE_POLICY_KEYS,
|
|
@@ -36,6 +36,7 @@ import { requireV2Bytes, invalidV2RequestError } from './NativeEditorResultNorma
|
|
|
36
36
|
export function normalizeV2CreatePolicy(value: Record<string, unknown>): Record<string, unknown> {
|
|
37
37
|
const policy = normalizeV2CreateRecord(value, V2_CREATE_POLICY_KEYS, 'policy');
|
|
38
38
|
const maxLength = ownV2CreateValue(policy, 'maxLength');
|
|
39
|
+
|
|
39
40
|
if (
|
|
40
41
|
maxLength !== undefined &&
|
|
41
42
|
(typeof maxLength !== 'number' ||
|
|
@@ -45,16 +46,21 @@ export function normalizeV2CreatePolicy(value: Record<string, unknown>): Record<
|
|
|
45
46
|
) {
|
|
46
47
|
invalidV2JsonValue('policy.maxLength');
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
for (const key of [ 'readOnly', 'allowBase64Images' ]) {
|
|
49
51
|
const value = ownV2CreateValue(policy, key);
|
|
52
|
+
|
|
50
53
|
if (value !== undefined && typeof value !== 'boolean') {
|
|
51
54
|
invalidV2JsonValue(`policy.${key}`);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
57
|
+
|
|
54
58
|
const inputFilter = ownV2CreateValue(policy, 'inputFilter');
|
|
59
|
+
|
|
55
60
|
if (inputFilter !== undefined && typeof inputFilter !== 'string') {
|
|
56
61
|
invalidV2JsonValue('policy.inputFilter');
|
|
57
62
|
}
|
|
63
|
+
|
|
58
64
|
return policy;
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -64,7 +70,9 @@ export function normalizeV2SnapshotMetadata(value: unknown): Record<string, unkn
|
|
|
64
70
|
V2_CREATE_SNAPSHOT_METADATA_KEYS,
|
|
65
71
|
'snapshot metadata'
|
|
66
72
|
);
|
|
73
|
+
|
|
67
74
|
const formatVersion = ownV2CreateValue(metadata, 'formatVersion');
|
|
75
|
+
|
|
68
76
|
if (
|
|
69
77
|
typeof formatVersion !== 'number' ||
|
|
70
78
|
!Number.isSafeInteger(formatVersion) ||
|
|
@@ -73,11 +81,13 @@ export function normalizeV2SnapshotMetadata(value: unknown): Record<string, unkn
|
|
|
73
81
|
) {
|
|
74
82
|
invalidV2JsonValue('snapshot metadata.formatVersion');
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
|
|
85
|
+
for (const key of [ 'documentId', 'lineageId', 'fragmentName', 'schemaFingerprint' ]) {
|
|
77
86
|
if (typeof ownV2CreateValue(metadata, key) !== 'string') {
|
|
78
87
|
invalidV2JsonValue(`snapshot metadata.${key}`);
|
|
79
88
|
}
|
|
80
89
|
}
|
|
90
|
+
|
|
81
91
|
return metadata;
|
|
82
92
|
}
|
|
83
93
|
|
|
@@ -89,17 +99,21 @@ export function buildV2CreateRequestUnchecked(config: NativeEditorCreateConfig):
|
|
|
89
99
|
if (!isV2CreateRecord(config)) {
|
|
90
100
|
throw invalidV2CreateRequestError('NativeEditorBridge: invalid v2 create config');
|
|
91
101
|
}
|
|
102
|
+
|
|
92
103
|
requireKnownV2CreateKeys(config, V2_CREATE_CONFIG_KEYS, 'config');
|
|
93
104
|
const initializationValue = ownV2CreateValue(config, 'initialization');
|
|
105
|
+
|
|
94
106
|
if (!isV2CreateRecord(initializationValue)) {
|
|
95
107
|
throw invalidV2CreateRequestError('NativeEditorBridge: invalid v2 create config');
|
|
96
108
|
}
|
|
109
|
+
|
|
97
110
|
const jsonTraversal: V2JsonNormalizationTraversal = {
|
|
98
111
|
seen: new WeakSet<object>(),
|
|
99
112
|
work: 0,
|
|
100
113
|
};
|
|
101
114
|
|
|
102
115
|
const policyValue = ownV2CreateValue(config, 'policy');
|
|
116
|
+
|
|
103
117
|
const policy =
|
|
104
118
|
policyValue === undefined
|
|
105
119
|
? undefined
|
|
@@ -107,15 +121,18 @@ export function buildV2CreateRequestUnchecked(config: NativeEditorCreateConfig):
|
|
|
107
121
|
|
|
108
122
|
const limitsValue = ownV2CreateValue(config, 'limits');
|
|
109
123
|
let limits: Record<string, unknown> | undefined;
|
|
124
|
+
|
|
110
125
|
if (limitsValue !== undefined) {
|
|
111
126
|
requireKnownV2CreateKeys(limitsValue, V2_CREATE_LIMIT_KEYS, 'limits');
|
|
112
127
|
limits = emptyV2CreateRecord();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
['
|
|
116
|
-
['
|
|
128
|
+
|
|
129
|
+
for (const [ group, keys ] of [
|
|
130
|
+
[ 'resource', V2_CREATE_RESOURCE_LIMIT_KEYS ],
|
|
131
|
+
[ 'editing', V2_CREATE_EDITING_LIMIT_KEYS ],
|
|
132
|
+
[ 'collaboration', V2_CREATE_COLLABORATION_LIMIT_KEYS ],
|
|
117
133
|
] as const) {
|
|
118
134
|
const overrides = ownV2CreateValue(limitsValue, group);
|
|
135
|
+
|
|
119
136
|
if (overrides !== undefined) {
|
|
120
137
|
limits[group] = normalizeV2CreateRecord(
|
|
121
138
|
overrides as Record<string, unknown>,
|
|
@@ -125,34 +142,47 @@ export function buildV2CreateRequestUnchecked(config: NativeEditorCreateConfig):
|
|
|
125
142
|
}
|
|
126
143
|
}
|
|
127
144
|
}
|
|
145
|
+
|
|
128
146
|
const envelope = emptyV2CreateRecord();
|
|
129
147
|
const schema = ownV2CreateValue(config, 'schema');
|
|
148
|
+
|
|
130
149
|
if (schema === null) {
|
|
131
150
|
throw invalidV2CreateRequestError('NativeEditorBridge: invalid schema for v2 create');
|
|
132
151
|
}
|
|
152
|
+
|
|
133
153
|
if (schema !== undefined) {
|
|
134
154
|
if (!isV2CreateRecord(schema)) {
|
|
135
155
|
throw invalidV2CreateRequestError('NativeEditorBridge: invalid schema for v2 create');
|
|
136
156
|
}
|
|
157
|
+
|
|
137
158
|
envelope.schema = normalizeV2JsonValue(schema, 'schema', jsonTraversal);
|
|
138
159
|
}
|
|
160
|
+
|
|
139
161
|
const fragmentName = ownV2CreateValue(config, 'fragmentName');
|
|
162
|
+
|
|
140
163
|
if (fragmentName !== undefined && typeof fragmentName !== 'string') {
|
|
141
164
|
throw invalidV2CreateRequestError('NativeEditorBridge: invalid fragmentName for v2 create');
|
|
142
165
|
}
|
|
143
|
-
|
|
166
|
+
|
|
167
|
+
if (fragmentName !== undefined) {
|
|
168
|
+
envelope.fragmentName = fragmentName;
|
|
169
|
+
}
|
|
144
170
|
|
|
145
171
|
let snapshotState: Uint8Array | null = null;
|
|
146
172
|
const initialization = initializationValue;
|
|
147
173
|
const initializationType = ownV2CreateValue(initialization, 'type');
|
|
174
|
+
|
|
148
175
|
const initializationKeys =
|
|
149
176
|
typeof initializationType === 'string'
|
|
150
177
|
? V2_CREATE_INITIALIZATION_KEYS[initializationType]
|
|
151
178
|
: undefined;
|
|
179
|
+
|
|
152
180
|
if (initializationKeys === undefined) {
|
|
153
181
|
throw invalidV2CreateRequestError('NativeEditorBridge: unknown v2 initialization type');
|
|
154
182
|
}
|
|
183
|
+
|
|
155
184
|
requireKnownV2CreateKeys(initialization, initializationKeys, 'initialization');
|
|
185
|
+
|
|
156
186
|
switch (initializationType) {
|
|
157
187
|
case 'localEmpty': {
|
|
158
188
|
const localEmpty = emptyV2CreateRecord();
|
|
@@ -160,74 +190,97 @@ export function buildV2CreateRequestUnchecked(config: NativeEditorCreateConfig):
|
|
|
160
190
|
envelope.initialization = localEmpty;
|
|
161
191
|
break;
|
|
162
192
|
}
|
|
193
|
+
|
|
163
194
|
case 'localJson': {
|
|
164
195
|
const json = ownV2CreateValue(initialization, 'json');
|
|
196
|
+
|
|
165
197
|
if (!isV2CreateRecord(json)) {
|
|
166
198
|
throw invalidV2CreateRequestError(
|
|
167
199
|
'NativeEditorBridge: invalid localJson initialization for v2 create'
|
|
168
200
|
);
|
|
169
201
|
}
|
|
202
|
+
|
|
170
203
|
const localJson = emptyV2CreateRecord();
|
|
171
204
|
localJson.type = 'localJson';
|
|
172
205
|
localJson.json = normalizeV2JsonValue(json, 'localJson initialization', jsonTraversal);
|
|
173
206
|
envelope.initialization = localJson;
|
|
174
207
|
break;
|
|
175
208
|
}
|
|
209
|
+
|
|
176
210
|
case 'localHtml': {
|
|
177
211
|
const html = ownV2CreateValue(initialization, 'html');
|
|
212
|
+
|
|
178
213
|
if (typeof html !== 'string') {
|
|
179
214
|
throw invalidV2CreateRequestError(
|
|
180
215
|
'NativeEditorBridge: invalid localHtml initialization for v2 create'
|
|
181
216
|
);
|
|
182
217
|
}
|
|
218
|
+
|
|
183
219
|
const localHtml = emptyV2CreateRecord();
|
|
184
220
|
localHtml.type = 'localHtml';
|
|
185
221
|
localHtml.html = html;
|
|
186
222
|
envelope.initialization = localHtml;
|
|
187
223
|
break;
|
|
188
224
|
}
|
|
225
|
+
|
|
189
226
|
case 'room': {
|
|
190
227
|
const documentId = ownV2CreateValue(initialization, 'documentId');
|
|
191
228
|
const lineageId = ownV2CreateValue(initialization, 'lineageId');
|
|
229
|
+
|
|
192
230
|
if (typeof documentId !== 'string' || typeof lineageId !== 'string') {
|
|
193
231
|
throw invalidV2CreateRequestError(
|
|
194
232
|
'NativeEditorBridge: invalid room initialization for v2 create'
|
|
195
233
|
);
|
|
196
234
|
}
|
|
235
|
+
|
|
197
236
|
const room = emptyV2CreateRecord();
|
|
198
237
|
room.type = 'room';
|
|
199
238
|
room.documentId = documentId;
|
|
200
239
|
room.lineageId = lineageId;
|
|
201
240
|
const snapshot = ownV2CreateValue(initialization, 'snapshot');
|
|
241
|
+
|
|
202
242
|
if (snapshot !== undefined) {
|
|
203
243
|
requireKnownV2CreateKeys(snapshot, V2_CREATE_ROOM_SNAPSHOT_KEYS, 'room snapshot');
|
|
204
244
|
const metadataValue = ownV2CreateValue(snapshot, 'metadata');
|
|
205
245
|
const metadata = normalizeV2SnapshotMetadata(metadataValue);
|
|
206
246
|
room.snapshot = metadata;
|
|
247
|
+
|
|
207
248
|
snapshotState = requireV2Bytes(
|
|
208
249
|
ownV2CreateValue(snapshot, 'encodedState'),
|
|
209
250
|
'snapshot encodedState'
|
|
210
251
|
);
|
|
211
252
|
}
|
|
253
|
+
|
|
212
254
|
envelope.initialization = room;
|
|
213
255
|
break;
|
|
214
256
|
}
|
|
257
|
+
|
|
215
258
|
default:
|
|
216
259
|
throw invalidV2CreateRequestError('NativeEditorBridge: unknown v2 initialization type');
|
|
217
260
|
}
|
|
218
|
-
|
|
219
|
-
if (
|
|
261
|
+
|
|
262
|
+
if (policy !== undefined) {
|
|
263
|
+
envelope.policy = policy;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (limits !== undefined) {
|
|
267
|
+
envelope.limits = limits;
|
|
268
|
+
}
|
|
269
|
+
|
|
220
270
|
return {
|
|
221
271
|
envelope,
|
|
222
|
-
limits
|
|
272
|
+
limits,
|
|
223
273
|
snapshotState,
|
|
224
274
|
};
|
|
225
275
|
}
|
|
226
276
|
|
|
227
277
|
export function cloneAndFreezeDescriptorValue<T>(value: T): T {
|
|
228
|
-
if (value == null || typeof value !== 'object')
|
|
278
|
+
if (value == null || typeof value !== 'object') {
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
229
281
|
|
|
230
282
|
type MutableDescriptorValue = Record<string, unknown>;
|
|
283
|
+
|
|
231
284
|
const setOwnValue = (target: MutableDescriptorValue, key: string, child: unknown): void => {
|
|
232
285
|
Object.defineProperty(target, key, {
|
|
233
286
|
value: child,
|
|
@@ -236,41 +289,55 @@ export function cloneAndFreezeDescriptorValue<T>(value: T): T {
|
|
|
236
289
|
configurable: true,
|
|
237
290
|
});
|
|
238
291
|
};
|
|
292
|
+
|
|
239
293
|
const cloneRoot: MutableDescriptorValue = (
|
|
240
294
|
Array.isArray(value) ? [] : {}
|
|
241
295
|
) as MutableDescriptorValue;
|
|
242
|
-
|
|
296
|
+
|
|
297
|
+
const clones = new Map<object, MutableDescriptorValue>([ [ value, cloneRoot ] ]);
|
|
298
|
+
|
|
243
299
|
const pending: Array<{
|
|
244
300
|
source: Record<string, unknown>;
|
|
245
301
|
target: MutableDescriptorValue;
|
|
246
|
-
}> = [{ source: value as Record<string, unknown>, target: cloneRoot }];
|
|
247
|
-
|
|
302
|
+
}> = [ { source: value as Record<string, unknown>, target: cloneRoot } ];
|
|
303
|
+
|
|
304
|
+
const created = [ cloneRoot ];
|
|
248
305
|
|
|
249
306
|
while (pending.length > 0) {
|
|
250
307
|
const current = pending.pop();
|
|
251
|
-
|
|
308
|
+
|
|
309
|
+
if (current === undefined) {
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
|
|
252
313
|
const keys = Array.isArray(current.source)
|
|
253
314
|
? Array.from({ length: (current.source as unknown[]).length }, (_, index) =>
|
|
254
|
-
|
|
255
|
-
)
|
|
315
|
+
String(index))
|
|
256
316
|
: Object.keys(current.source);
|
|
317
|
+
|
|
257
318
|
for (const key of keys) {
|
|
258
319
|
const child = current.source[key];
|
|
320
|
+
|
|
259
321
|
if (child == null || typeof child !== 'object') {
|
|
260
322
|
setOwnValue(current.target, key, child);
|
|
261
323
|
continue;
|
|
262
324
|
}
|
|
325
|
+
|
|
263
326
|
const existing = clones.get(child);
|
|
327
|
+
|
|
264
328
|
if (existing !== undefined) {
|
|
265
329
|
setOwnValue(current.target, key, existing);
|
|
266
330
|
continue;
|
|
267
331
|
}
|
|
332
|
+
|
|
268
333
|
const childClone: MutableDescriptorValue = (
|
|
269
334
|
Array.isArray(child) ? [] : {}
|
|
270
335
|
) as MutableDescriptorValue;
|
|
336
|
+
|
|
271
337
|
clones.set(child, childClone);
|
|
272
338
|
created.push(childClone);
|
|
273
339
|
setOwnValue(current.target, key, childClone);
|
|
340
|
+
|
|
274
341
|
pending.push({
|
|
275
342
|
source: child as Record<string, unknown>,
|
|
276
343
|
target: childClone,
|
|
@@ -281,6 +348,7 @@ export function cloneAndFreezeDescriptorValue<T>(value: T): T {
|
|
|
281
348
|
for (let index = created.length - 1; index >= 0; index -= 1) {
|
|
282
349
|
Object.freeze(created[index]);
|
|
283
350
|
}
|
|
351
|
+
|
|
284
352
|
return cloneRoot as T;
|
|
285
353
|
}
|
|
286
354
|
|
|
@@ -300,6 +368,7 @@ export function buildV2CreateRequest(config: NativeEditorCreateConfig): {
|
|
|
300
368
|
documentDescriptor: ResolvedDocumentSchema;
|
|
301
369
|
} {
|
|
302
370
|
let normalized: ReturnType<typeof buildV2CreateRequestUnchecked>;
|
|
371
|
+
|
|
303
372
|
try {
|
|
304
373
|
normalized = buildV2CreateRequestUnchecked(config);
|
|
305
374
|
} catch (error) {
|
|
@@ -307,18 +376,22 @@ export function buildV2CreateRequest(config: NativeEditorCreateConfig): {
|
|
|
307
376
|
error instanceof NativeEditorCreateConfigError
|
|
308
377
|
? error.message
|
|
309
378
|
: 'NativeEditorBridge: invalid v2 create config';
|
|
379
|
+
|
|
310
380
|
throw invalidV2RequestError(message);
|
|
311
381
|
}
|
|
312
382
|
|
|
313
383
|
validateV2CreateLimits(normalized.limits);
|
|
384
|
+
|
|
314
385
|
const documentDescriptor = cloneAndFreezeDocumentDescriptor(
|
|
315
386
|
resolveDocumentDescriptor(
|
|
316
387
|
normalized.envelope.schema as SchemaDefinition | undefined,
|
|
317
|
-
normalized.limits?.resource
|
|
388
|
+
normalized.limits?.resource
|
|
318
389
|
)
|
|
319
390
|
);
|
|
391
|
+
|
|
320
392
|
try {
|
|
321
393
|
const configJson = serializeV2CreateEnvelope(normalized.envelope);
|
|
394
|
+
|
|
322
395
|
return { configJson, snapshotState: normalized.snapshotState, documentDescriptor };
|
|
323
396
|
} catch {
|
|
324
397
|
throw invalidV2RequestError('NativeEditorBridge: invalid v2 create config');
|