react-native-divkit 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +200 -201
- package/dist/DivKit.d.ts.map +1 -1
- package/dist/DivKit.js +24 -7
- package/dist/DivKit.js.map +1 -1
- package/dist/actions/array.d.ts.map +1 -1
- package/dist/actions/array.js +1 -1
- package/dist/actions/array.js.map +1 -1
- package/dist/actions/copyToClipboard.d.ts.map +1 -1
- package/dist/actions/copyToClipboard.js +2 -1
- package/dist/actions/copyToClipboard.js.map +1 -1
- package/dist/actions/dict.d.ts.map +1 -1
- package/dist/actions/dict.js.map +1 -1
- package/dist/actions/updateStructure.d.ts.map +1 -1
- package/dist/actions/updateStructure.js.map +1 -1
- package/dist/components/container/DivContainer.d.ts.map +1 -1
- package/dist/components/container/DivContainer.js +3 -5
- package/dist/components/container/DivContainer.js.map +1 -1
- package/dist/components/image/DivImage.d.ts.map +1 -1
- package/dist/components/image/DivImage.js +1 -6
- package/dist/components/image/DivImage.js.map +1 -1
- package/dist/components/state/DivState.d.ts.map +1 -1
- package/dist/components/state/DivState.js +3 -5
- package/dist/components/state/DivState.js.map +1 -1
- package/dist/components/text/DivText.d.ts.map +1 -1
- package/dist/components/text/DivText.js +4 -4
- package/dist/components/text/DivText.js.map +1 -1
- package/dist/components/utilities/Background.d.ts +11 -0
- package/dist/components/utilities/Background.d.ts.map +1 -0
- package/dist/components/utilities/Background.js +73 -0
- package/dist/components/utilities/Background.js.map +1 -0
- package/dist/components/utilities/Outer.d.ts.map +1 -1
- package/dist/components/utilities/Outer.js +24 -10
- package/dist/components/utilities/Outer.js.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/expressions/eval.d.ts.map +1 -1
- package/dist/expressions/eval.js +19 -11
- package/dist/expressions/eval.js.map +1 -1
- package/dist/expressions/funcs/array.d.ts.map +1 -1
- package/dist/expressions/funcs/array.js +72 -168
- package/dist/expressions/funcs/array.js.map +1 -1
- package/dist/expressions/funcs/colors.d.ts.map +1 -1
- package/dist/expressions/funcs/colors.js.map +1 -1
- package/dist/expressions/funcs/customFuncs.d.ts.map +1 -1
- package/dist/expressions/funcs/customFuncs.js +6 -4
- package/dist/expressions/funcs/customFuncs.js.map +1 -1
- package/dist/expressions/funcs/datetime.d.ts.map +1 -1
- package/dist/expressions/funcs/datetime.js +1 -1
- package/dist/expressions/funcs/datetime.js.map +1 -1
- package/dist/expressions/funcs/dict.d.ts.map +1 -1
- package/dist/expressions/funcs/dict.js.map +1 -1
- package/dist/expressions/funcs/funcs.d.ts.map +1 -1
- package/dist/expressions/funcs/funcs.js +21 -13
- package/dist/expressions/funcs/funcs.js.map +1 -1
- package/dist/expressions/funcs/math.d.ts.map +1 -1
- package/dist/expressions/funcs/math.js +40 -20
- package/dist/expressions/funcs/math.js.map +1 -1
- package/dist/expressions/funcs/std.d.ts.map +1 -1
- package/dist/expressions/funcs/std.js +4 -4
- package/dist/expressions/funcs/std.js.map +1 -1
- package/dist/expressions/funcs/strings.d.ts.map +1 -1
- package/dist/expressions/funcs/strings.js +1 -2
- package/dist/expressions/funcs/strings.js.map +1 -1
- package/dist/expressions/funcs/trigonometry.js +2 -2
- package/dist/expressions/funcs/trigonometry.js.map +1 -1
- package/dist/expressions/json.d.ts +2 -2
- package/dist/expressions/json.d.ts.map +1 -1
- package/dist/expressions/json.js +6 -4
- package/dist/expressions/json.js.map +1 -1
- package/dist/expressions/utils.d.ts.map +1 -1
- package/dist/expressions/utils.js +9 -10
- package/dist/expressions/utils.js.map +1 -1
- package/dist/expressions/variable.d.ts.map +1 -1
- package/dist/expressions/variable.js +3 -7
- package/dist/expressions/variable.js.map +1 -1
- package/dist/expressions/walk.d.ts.map +1 -1
- package/dist/expressions/walk.js.map +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useAction.d.ts.map +1 -1
- package/dist/hooks/useAction.js.map +1 -1
- package/dist/hooks/useDerivedFromVars.d.ts.map +1 -1
- package/dist/hooks/useDerivedFromVars.js.map +1 -1
- package/dist/hooks/useVariable.d.ts.map +1 -1
- package/dist/hooks/useVariable.js +4 -4
- package/dist/hooks/useVariable.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/stores/createObservable.d.ts.map +1 -1
- package/dist/stores/createObservable.js.map +1 -1
- package/dist/utils/applyTemplate.d.ts +2 -2
- package/dist/utils/applyTemplate.d.ts.map +1 -1
- package/dist/utils/applyTemplate.js +13 -13
- package/dist/utils/applyTemplate.js.map +1 -1
- package/dist/utils/correctColor.d.ts.map +1 -1
- package/dist/utils/correctColor.js +8 -6
- package/dist/utils/correctColor.js.map +1 -1
- package/dist/utils/formatDate.d.ts.map +1 -1
- package/dist/utils/formatDate.js +7 -10
- package/dist/utils/formatDate.js.map +1 -1
- package/dist/utils/wrapError.d.ts.map +1 -1
- package/dist/utils/wrapError.js.map +1 -1
- package/package.json +8 -7
- package/src/DivKit.tsx +258 -220
- package/src/actions/array.ts +91 -64
- package/src/actions/copyToClipboard.ts +28 -19
- package/src/actions/dict.ts +36 -26
- package/src/actions/updateStructure.ts +86 -61
- package/src/components/README.md +38 -18
- package/src/components/container/DivContainer.tsx +4 -14
- package/src/components/image/DivImage.tsx +1 -11
- package/src/components/state/DivState.tsx +3 -9
- package/src/components/text/DivText.tsx +8 -20
- package/src/components/utilities/Background.tsx +120 -0
- package/src/components/utilities/Outer.tsx +24 -23
- package/src/components/utilities/README.md +37 -32
- package/src/context/index.ts +2 -11
- package/src/expressions/ast.d.ts +16 -9
- package/src/expressions/eval.ts +82 -37
- package/src/expressions/funcs/array.ts +129 -209
- package/src/expressions/funcs/colors.ts +1 -3
- package/src/expressions/funcs/customFuncs.ts +6 -4
- package/src/expressions/funcs/datetime.ts +10 -3
- package/src/expressions/funcs/dict.ts +16 -2
- package/src/expressions/funcs/funcs.ts +75 -89
- package/src/expressions/funcs/math.ts +103 -43
- package/src/expressions/funcs/std.ts +4 -7
- package/src/expressions/funcs/strings.ts +9 -25
- package/src/expressions/funcs/trigonometry.ts +2 -2
- package/src/expressions/json.ts +60 -53
- package/src/expressions/utils.ts +24 -22
- package/src/expressions/variable.ts +5 -21
- package/src/expressions/walk.ts +6 -3
- package/src/hooks/README.md +61 -53
- package/src/hooks/index.ts +3 -18
- package/src/hooks/useAction.ts +1 -3
- package/src/hooks/useDerivedFromVars.ts +3 -13
- package/src/hooks/useVariable.ts +7 -17
- package/src/index.ts +10 -48
- package/src/stores/createObservable.ts +35 -35
- package/src/types/alignment.d.ts +15 -6
- package/src/types/background.d.ts +6 -2
- package/src/types/base.d.ts +41 -9
- package/src/types/componentContext.d.ts +27 -22
- package/src/types/container.d.ts +1 -4
- package/src/types/text.d.ts +1 -1
- package/src/utils/applyTemplate.ts +103 -109
- package/src/utils/correctColor.ts +9 -8
- package/src/utils/formatDate.ts +175 -86
- package/src/utils/wrapError.ts +7 -4
package/src/DivKit.tsx
CHANGED
|
@@ -36,14 +36,12 @@ import { dictSetValue } from './actions/dict';
|
|
|
36
36
|
import { copyToClipboard } from './actions/copyToClipboard';
|
|
37
37
|
import { updateStructure } from './actions/updateStructure';
|
|
38
38
|
import { evalExpression } from './expressions/eval';
|
|
39
|
+
import { parse } from './expressions/expressions';
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Callback for logging statistics
|
|
42
43
|
*/
|
|
43
|
-
export type StatCallback = (stat: {
|
|
44
|
-
type: string;
|
|
45
|
-
action: Action;
|
|
46
|
-
}) => void;
|
|
44
|
+
export type StatCallback = (stat: { type: string; action: Action }) => void;
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
47
|
* Callback for custom actions (actions with URLs)
|
|
@@ -104,13 +102,16 @@ export function DivKit({
|
|
|
104
102
|
const statesMap = useRef<Map<string, StateSetter>>(new Map());
|
|
105
103
|
|
|
106
104
|
// Error logging
|
|
107
|
-
const logError = useCallback(
|
|
108
|
-
|
|
109
|
-
onError
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
const logError = useCallback(
|
|
106
|
+
(error: WrappedError) => {
|
|
107
|
+
if (onError) {
|
|
108
|
+
onError(error);
|
|
109
|
+
} else {
|
|
110
|
+
console.error('[DivKit Error]', error);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
[onError]
|
|
114
|
+
);
|
|
114
115
|
|
|
115
116
|
// Parse JSON and apply templates
|
|
116
117
|
const { rootDiv, initialVariables } = useMemo(() => {
|
|
@@ -132,15 +133,13 @@ export function DivKit({
|
|
|
132
133
|
if (divData && typeof divData === 'object' && 'type' in divData) {
|
|
133
134
|
try {
|
|
134
135
|
// Use recursive template application to handle nested templates
|
|
135
|
-
resolvedDiv = applyTemplatesRecursively(
|
|
136
|
-
divData,
|
|
137
|
-
templatesData,
|
|
138
|
-
logError
|
|
139
|
-
);
|
|
136
|
+
resolvedDiv = applyTemplatesRecursively(divData, templatesData, logError);
|
|
140
137
|
} catch (err) {
|
|
141
|
-
logError(
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
logError(
|
|
139
|
+
wrapError(err as Error, {
|
|
140
|
+
additional: { phase: 'template_resolution' }
|
|
141
|
+
})
|
|
142
|
+
);
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
|
|
@@ -161,19 +160,17 @@ export function DivKit({
|
|
|
161
160
|
return;
|
|
162
161
|
}
|
|
163
162
|
|
|
164
|
-
const variable = createVariable(
|
|
165
|
-
varData.name,
|
|
166
|
-
varData.type as VariableType,
|
|
167
|
-
varData.value
|
|
168
|
-
);
|
|
163
|
+
const variable = createVariable(varData.name, varData.type as VariableType, varData.value);
|
|
169
164
|
map.set(varData.name, variable);
|
|
170
165
|
} catch (err) {
|
|
171
|
-
logError(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
logError(
|
|
167
|
+
wrapError(err as Error, {
|
|
168
|
+
additional: {
|
|
169
|
+
variable: varData.name,
|
|
170
|
+
type: varData.type
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
);
|
|
177
174
|
}
|
|
178
175
|
});
|
|
179
176
|
|
|
@@ -186,133 +183,174 @@ export function DivKit({
|
|
|
186
183
|
}, []);
|
|
187
184
|
|
|
188
185
|
// Variable management
|
|
189
|
-
const getVariable = useCallback(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (!variable) {
|
|
196
|
-
logError(wrapError(new Error('Variable not found'), {
|
|
197
|
-
additional: { variable: name }
|
|
198
|
-
}));
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
186
|
+
const getVariable = useCallback(
|
|
187
|
+
(name: string): Variable | undefined => {
|
|
188
|
+
return variables.get(name);
|
|
189
|
+
},
|
|
190
|
+
[variables]
|
|
191
|
+
);
|
|
201
192
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
193
|
+
const setVariable = useCallback(
|
|
194
|
+
(name: string, value: unknown): void => {
|
|
195
|
+
const variable = variables.get(name);
|
|
196
|
+
if (!variable) {
|
|
197
|
+
logError(
|
|
198
|
+
wrapError(new Error('Variable not found'), {
|
|
199
|
+
additional: { variable: name }
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
variable.setValue(value);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
logError(
|
|
209
|
+
wrapError(err as Error, {
|
|
210
|
+
additional: {
|
|
211
|
+
variable: name,
|
|
212
|
+
value
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
[variables, logError]
|
|
219
|
+
);
|
|
213
220
|
|
|
214
221
|
// Action execution
|
|
215
|
-
const execAnyActions = useCallback(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
const execAnyActions = useCallback(
|
|
223
|
+
async (
|
|
224
|
+
actions: MaybeMissing<Action[]> | undefined,
|
|
225
|
+
opts?: {
|
|
226
|
+
componentContext?: ComponentContext;
|
|
227
|
+
processUrls?: boolean;
|
|
228
|
+
}
|
|
229
|
+
): Promise<void> => {
|
|
230
|
+
if (!actions || !Array.isArray(actions)) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
225
233
|
|
|
226
|
-
|
|
227
|
-
|
|
234
|
+
const processUrls = opts?.processUrls ?? true;
|
|
235
|
+
const componentContext = opts?.componentContext;
|
|
228
236
|
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
for (const action of actions) {
|
|
238
|
+
if (!action) continue;
|
|
231
239
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
// Log statistics
|
|
241
|
+
if (action.log_id && onStat) {
|
|
242
|
+
onStat({
|
|
243
|
+
type: 'action',
|
|
244
|
+
action: action as Action
|
|
245
|
+
});
|
|
246
|
+
}
|
|
239
247
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
// Handle typed actions
|
|
249
|
+
if (action.typed) {
|
|
250
|
+
const typed = action.typed;
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
switch (typed.type) {
|
|
254
|
+
case 'set_variable':
|
|
255
|
+
if (typed.variable_name && typed.value) {
|
|
256
|
+
const typedValue = typed.value;
|
|
257
|
+
let value: unknown;
|
|
258
|
+
|
|
259
|
+
// Convert typed value to raw value
|
|
260
|
+
if (
|
|
261
|
+
typeof typedValue === 'object' &&
|
|
262
|
+
typedValue !== null &&
|
|
263
|
+
'value' in typedValue
|
|
264
|
+
) {
|
|
265
|
+
value = typedValue.value;
|
|
266
|
+
} else {
|
|
267
|
+
value = typedValue;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Evaluate expression if value is a string with @{...}
|
|
271
|
+
if (typeof value === 'string' && value.includes('@{')) {
|
|
272
|
+
try {
|
|
273
|
+
const ast = parse(value, { startRule: 'JsonStringContents' });
|
|
274
|
+
|
|
275
|
+
const res = evalExpression(variables, undefined, undefined, ast);
|
|
276
|
+
|
|
277
|
+
if (res.result.type !== 'error') {
|
|
278
|
+
value = res.result.value;
|
|
279
|
+
}
|
|
280
|
+
} catch (err) {
|
|
281
|
+
logError(
|
|
282
|
+
wrapError(err as Error, {
|
|
283
|
+
additional: {
|
|
284
|
+
phase: 'set_variable_expression',
|
|
285
|
+
expression: value
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
setVariable(typed.variable_name, value);
|
|
256
293
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (setter) {
|
|
267
|
-
await setter(String(setStateAction.temporary_state_id));
|
|
294
|
+
break;
|
|
295
|
+
|
|
296
|
+
case 'set_state': {
|
|
297
|
+
const setStateAction = typed as any;
|
|
298
|
+
if (setStateAction.state_id && setStateAction.temporary_state_id) {
|
|
299
|
+
const setter = statesMap.current.get(setStateAction.state_id);
|
|
300
|
+
if (setter) {
|
|
301
|
+
await setter(String(setStateAction.temporary_state_id));
|
|
302
|
+
}
|
|
268
303
|
}
|
|
304
|
+
break;
|
|
269
305
|
}
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
306
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
307
|
+
case 'array_insert_value':
|
|
308
|
+
arrayInsert(componentContext, variables, logError, typed as any);
|
|
309
|
+
break;
|
|
276
310
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
311
|
+
case 'array_remove_value':
|
|
312
|
+
arrayRemove(componentContext, variables, logError, typed as any);
|
|
313
|
+
break;
|
|
280
314
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
315
|
+
case 'array_set_value':
|
|
316
|
+
arraySet(componentContext, variables, logError, typed as any);
|
|
317
|
+
break;
|
|
284
318
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
319
|
+
case 'dict_set_value':
|
|
320
|
+
dictSetValue(componentContext, variables, logError, typed as any);
|
|
321
|
+
break;
|
|
288
322
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
323
|
+
case 'update_structure':
|
|
324
|
+
updateStructure(componentContext, variables, logError, typed as any);
|
|
325
|
+
break;
|
|
292
326
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
327
|
+
case 'copy_to_clipboard':
|
|
328
|
+
copyToClipboard(logError, typed as any);
|
|
329
|
+
break;
|
|
296
330
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
} catch (err) {
|
|
302
|
-
logError(wrapError(err as Error, {
|
|
303
|
-
additional: {
|
|
304
|
-
action: typed.type
|
|
331
|
+
// MVP: Other action types deferred (timer, animator, etc.)
|
|
332
|
+
default:
|
|
333
|
+
break;
|
|
305
334
|
}
|
|
306
|
-
})
|
|
335
|
+
} catch (err) {
|
|
336
|
+
logError(
|
|
337
|
+
wrapError(err as Error, {
|
|
338
|
+
additional: {
|
|
339
|
+
action: typed.type
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
}
|
|
307
344
|
}
|
|
308
|
-
}
|
|
309
345
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
346
|
+
// Handle URL actions
|
|
347
|
+
if (processUrls && action.url && onCustomAction) {
|
|
348
|
+
onCustomAction(action as Action & { url: string });
|
|
349
|
+
}
|
|
313
350
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
351
|
+
},
|
|
352
|
+
[variables, logError, onStat, onCustomAction, setVariable]
|
|
353
|
+
);
|
|
316
354
|
|
|
317
355
|
// Component registration
|
|
318
356
|
const registerComponent = useCallback((_componentId: string, context: ComponentContext): void => {
|
|
@@ -324,89 +362,98 @@ export function DivKit({
|
|
|
324
362
|
}, []);
|
|
325
363
|
|
|
326
364
|
// State Context implementation
|
|
327
|
-
const stateContextValue = useMemo<StateContextValue>(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
365
|
+
const stateContextValue = useMemo<StateContextValue>(
|
|
366
|
+
() => ({
|
|
367
|
+
registerState: (componentId: string, setState: StateSetter): (() => void) => {
|
|
368
|
+
statesMap.current.set(componentId, setState);
|
|
369
|
+
return () => {
|
|
370
|
+
statesMap.current.delete(componentId);
|
|
371
|
+
};
|
|
372
|
+
},
|
|
334
373
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
374
|
+
switchState: async (stateId: string): Promise<void> => {
|
|
375
|
+
const setter = statesMap.current.get(stateId);
|
|
376
|
+
if (setter) {
|
|
377
|
+
await setter(stateId);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
341
380
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
381
|
+
getStateSetter: (componentId: string): StateSetter | undefined => {
|
|
382
|
+
return statesMap.current.get(componentId);
|
|
383
|
+
},
|
|
345
384
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
385
|
+
registerChild: (_componentId: string): void => {
|
|
386
|
+
// MVP: Simplified implementation
|
|
387
|
+
// Full transition tracking deferred
|
|
388
|
+
},
|
|
350
389
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
390
|
+
unregisterChild: (_componentId: string): void => {
|
|
391
|
+
// MVP: Simplified implementation
|
|
392
|
+
},
|
|
354
393
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
394
|
+
hasTransitionChange: (): boolean => {
|
|
395
|
+
// MVP: Always false (transitions deferred)
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
}),
|
|
399
|
+
[]
|
|
400
|
+
);
|
|
360
401
|
|
|
361
402
|
// Action Context implementation
|
|
362
|
-
const actionContextValue = useMemo<ActionContextValue>(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
403
|
+
const actionContextValue = useMemo<ActionContextValue>(
|
|
404
|
+
() => ({
|
|
405
|
+
hasAction: (): boolean => {
|
|
406
|
+
// MVP: Simplified - always return false
|
|
407
|
+
// Full action tracking deferred
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}),
|
|
411
|
+
[]
|
|
412
|
+
);
|
|
369
413
|
|
|
370
414
|
// DivKit Context implementation
|
|
371
|
-
const divKitContextValue = useMemo<DivKitContextValue>(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
onStat
|
|
375
|
-
|
|
376
|
-
|
|
415
|
+
const divKitContextValue = useMemo<DivKitContextValue>(
|
|
416
|
+
() => ({
|
|
417
|
+
logStat: (type: string, action: MaybeMissing<Action>) => {
|
|
418
|
+
if (onStat && action && action.log_id) {
|
|
419
|
+
onStat({ type, action: action as Action });
|
|
420
|
+
}
|
|
421
|
+
},
|
|
377
422
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
423
|
+
execCustomAction: (action: Action & { url: string }) => {
|
|
424
|
+
if (onCustomAction) {
|
|
425
|
+
onCustomAction(action);
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
direction,
|
|
430
|
+
platform,
|
|
431
|
+
|
|
432
|
+
variables,
|
|
433
|
+
getVariable,
|
|
434
|
+
setVariable,
|
|
435
|
+
|
|
436
|
+
registerComponent,
|
|
437
|
+
unregisterComponent,
|
|
383
438
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
variables,
|
|
403
|
-
getVariable,
|
|
404
|
-
setVariable,
|
|
405
|
-
registerComponent,
|
|
406
|
-
unregisterComponent,
|
|
407
|
-
execAnyActions,
|
|
408
|
-
genId
|
|
409
|
-
]);
|
|
439
|
+
execAnyActions,
|
|
440
|
+
|
|
441
|
+
genId
|
|
442
|
+
}),
|
|
443
|
+
[
|
|
444
|
+
onStat,
|
|
445
|
+
onCustomAction,
|
|
446
|
+
direction,
|
|
447
|
+
platform,
|
|
448
|
+
variables,
|
|
449
|
+
getVariable,
|
|
450
|
+
setVariable,
|
|
451
|
+
registerComponent,
|
|
452
|
+
unregisterComponent,
|
|
453
|
+
execAnyActions,
|
|
454
|
+
genId
|
|
455
|
+
]
|
|
456
|
+
);
|
|
410
457
|
|
|
411
458
|
// Create root component context
|
|
412
459
|
const rootComponentContext = useMemo<ComponentContext<DivBaseData> | null>(() => {
|
|
@@ -443,13 +490,8 @@ export function DivKit({
|
|
|
443
490
|
return evalExpression(allVars, undefined, store, expr, opts);
|
|
444
491
|
},
|
|
445
492
|
|
|
446
|
-
produceChildContext: (
|
|
447
|
-
|
|
448
|
-
opts?: any
|
|
449
|
-
): ComponentContext => {
|
|
450
|
-
const childPath = opts?.path !== undefined
|
|
451
|
-
? [...context.path, String(opts.path)]
|
|
452
|
-
: context.path;
|
|
493
|
+
produceChildContext: (div: MaybeMissing<DivBaseData>, opts?: any): ComponentContext => {
|
|
494
|
+
const childPath = opts?.path !== undefined ? [...context.path, String(opts.path)] : context.path;
|
|
453
495
|
|
|
454
496
|
const childContext: ComponentContext = {
|
|
455
497
|
...context,
|
|
@@ -515,11 +557,7 @@ export function DivKit({
|
|
|
515
557
|
|
|
516
558
|
// Render
|
|
517
559
|
if (!rootDiv || !rootComponentContext) {
|
|
518
|
-
return
|
|
519
|
-
<View style={[styles.container, style]}>
|
|
520
|
-
{/* Empty state - could render error UI here */}
|
|
521
|
-
</View>
|
|
522
|
-
);
|
|
560
|
+
return <View style={[styles.container, style]}>{/* Empty state - could render error UI here */}</View>;
|
|
523
561
|
}
|
|
524
562
|
|
|
525
563
|
return (
|