react-native-divkit 0.1.0-alpha.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/LICENSE +176 -0
- package/README.md +340 -0
- package/dist/DivKit.d.ts +68 -0
- package/dist/DivKit.d.ts.map +1 -0
- package/dist/DivKit.js +400 -0
- package/dist/DivKit.js.map +1 -0
- package/dist/actions/array.d.ts +8 -0
- package/dist/actions/array.d.ts.map +1 -0
- package/dist/actions/array.js +139 -0
- package/dist/actions/array.js.map +1 -0
- package/dist/actions/copyToClipboard.d.ts +22 -0
- package/dist/actions/copyToClipboard.d.ts.map +1 -0
- package/dist/actions/copyToClipboard.js +63 -0
- package/dist/actions/copyToClipboard.js.map +1 -0
- package/dist/actions/dict.d.ts +6 -0
- package/dist/actions/dict.d.ts.map +1 -0
- package/dist/actions/dict.js +58 -0
- package/dist/actions/dict.js.map +1 -0
- package/dist/actions/index.d.ts +11 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +11 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/updateStructure.d.ts +6 -0
- package/dist/actions/updateStructure.d.ts.map +1 -0
- package/dist/actions/updateStructure.js +116 -0
- package/dist/actions/updateStructure.js.map +1 -0
- package/dist/components/DivComponent.d.ts +29 -0
- package/dist/components/DivComponent.d.ts.map +1 -0
- package/dist/components/DivComponent.js +62 -0
- package/dist/components/DivComponent.js.map +1 -0
- package/dist/components/container/DivContainer.d.ts +26 -0
- package/dist/components/container/DivContainer.d.ts.map +1 -0
- package/dist/components/container/DivContainer.js +172 -0
- package/dist/components/container/DivContainer.js.map +1 -0
- package/dist/components/container/index.d.ts +3 -0
- package/dist/components/container/index.d.ts.map +1 -0
- package/dist/components/container/index.js +2 -0
- package/dist/components/container/index.js.map +1 -0
- package/dist/components/image/DivImage.d.ts +29 -0
- package/dist/components/image/DivImage.d.ts.map +1 -0
- package/dist/components/image/DivImage.js +122 -0
- package/dist/components/image/DivImage.js.map +1 -0
- package/dist/components/image/index.d.ts +3 -0
- package/dist/components/image/index.d.ts.map +1 -0
- package/dist/components/image/index.js +2 -0
- package/dist/components/image/index.js.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +11 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/state/DivState.d.ts +26 -0
- package/dist/components/state/DivState.d.ts.map +1 -0
- package/dist/components/state/DivState.js +121 -0
- package/dist/components/state/DivState.js.map +1 -0
- package/dist/components/state/index.d.ts +3 -0
- package/dist/components/state/index.d.ts.map +1 -0
- package/dist/components/state/index.js +2 -0
- package/dist/components/state/index.js.map +1 -0
- package/dist/components/text/DivText.d.ts +28 -0
- package/dist/components/text/DivText.d.ts.map +1 -0
- package/dist/components/text/DivText.js +143 -0
- package/dist/components/text/DivText.js.map +1 -0
- package/dist/components/text/index.d.ts +3 -0
- package/dist/components/text/index.d.ts.map +1 -0
- package/dist/components/text/index.js +2 -0
- package/dist/components/text/index.js.map +1 -0
- package/dist/components/utilities/Outer.d.ts +17 -0
- package/dist/components/utilities/Outer.d.ts.map +1 -0
- package/dist/components/utilities/Outer.js +210 -0
- package/dist/components/utilities/Outer.js.map +1 -0
- package/dist/components/utilities/Unknown.d.ts +11 -0
- package/dist/components/utilities/Unknown.d.ts.map +1 -0
- package/dist/components/utilities/Unknown.js +50 -0
- package/dist/components/utilities/Unknown.js.map +1 -0
- package/dist/components/utilities/index.d.ts +5 -0
- package/dist/components/utilities/index.d.ts.map +1 -0
- package/dist/components/utilities/index.js +3 -0
- package/dist/components/utilities/index.js.map +1 -0
- package/dist/context/ActionContext.d.ts +25 -0
- package/dist/context/ActionContext.d.ts.map +1 -0
- package/dist/context/ActionContext.js +20 -0
- package/dist/context/ActionContext.js.map +1 -0
- package/dist/context/DivKitContext.d.ts +33 -0
- package/dist/context/DivKitContext.d.ts.map +1 -0
- package/dist/context/DivKitContext.js +14 -0
- package/dist/context/DivKitContext.js.map +1 -0
- package/dist/context/EnabledContext.d.ts +31 -0
- package/dist/context/EnabledContext.d.ts.map +1 -0
- package/dist/context/EnabledContext.js +31 -0
- package/dist/context/EnabledContext.js.map +1 -0
- package/dist/context/StateContext.d.ts +57 -0
- package/dist/context/StateContext.d.ts.map +1 -0
- package/dist/context/StateContext.js +20 -0
- package/dist/context/StateContext.js.map +1 -0
- package/dist/context/index.d.ts +9 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/expressions/bigint.d.ts +8 -0
- package/dist/expressions/bigint.d.ts.map +1 -0
- package/dist/expressions/bigint.js +31 -0
- package/dist/expressions/bigint.js.map +1 -0
- package/dist/expressions/const.d.ts +15 -0
- package/dist/expressions/const.d.ts.map +1 -0
- package/dist/expressions/const.js +15 -0
- package/dist/expressions/const.js.map +1 -0
- package/dist/expressions/eval.d.ts +77 -0
- package/dist/expressions/eval.d.ts.map +1 -0
- package/dist/expressions/eval.js +459 -0
- package/dist/expressions/eval.js.map +1 -0
- package/dist/expressions/expressions.d.ts +7 -0
- package/dist/expressions/expressions.d.ts.map +1 -0
- package/dist/expressions/expressions.js +3191 -0
- package/dist/expressions/expressions.js.map +1 -0
- package/dist/expressions/funcs/array.d.ts +2 -0
- package/dist/expressions/funcs/array.d.ts.map +1 -0
- package/dist/expressions/funcs/array.js +381 -0
- package/dist/expressions/funcs/array.js.map +1 -0
- package/dist/expressions/funcs/colors.d.ts +2 -0
- package/dist/expressions/funcs/colors.d.ts.map +1 -0
- package/dist/expressions/funcs/colors.js +75 -0
- package/dist/expressions/funcs/colors.js.map +1 -0
- package/dist/expressions/funcs/customFuncs.d.ts +8 -0
- package/dist/expressions/funcs/customFuncs.d.ts.map +1 -0
- package/dist/expressions/funcs/customFuncs.js +114 -0
- package/dist/expressions/funcs/customFuncs.js.map +1 -0
- package/dist/expressions/funcs/datetime.d.ts +2 -0
- package/dist/expressions/funcs/datetime.d.ts.map +1 -0
- package/dist/expressions/funcs/datetime.js +182 -0
- package/dist/expressions/funcs/datetime.js.map +1 -0
- package/dist/expressions/funcs/dict.d.ts +2 -0
- package/dist/expressions/funcs/dict.d.ts.map +1 -0
- package/dist/expressions/funcs/dict.js +170 -0
- package/dist/expressions/funcs/dict.js.map +1 -0
- package/dist/expressions/funcs/funcs.d.ts +80 -0
- package/dist/expressions/funcs/funcs.d.ts.map +1 -0
- package/dist/expressions/funcs/funcs.js +146 -0
- package/dist/expressions/funcs/funcs.js.map +1 -0
- package/dist/expressions/funcs/index.d.ts +2 -0
- package/dist/expressions/funcs/index.d.ts.map +1 -0
- package/dist/expressions/funcs/index.js +23 -0
- package/dist/expressions/funcs/index.js.map +1 -0
- package/dist/expressions/funcs/interval.d.ts +2 -0
- package/dist/expressions/funcs/interval.d.ts.map +1 -0
- package/dist/expressions/funcs/interval.js +61 -0
- package/dist/expressions/funcs/interval.js.map +1 -0
- package/dist/expressions/funcs/math.d.ts +2 -0
- package/dist/expressions/funcs/math.d.ts.map +1 -0
- package/dist/expressions/funcs/math.js +324 -0
- package/dist/expressions/funcs/math.js.map +1 -0
- package/dist/expressions/funcs/std.d.ts +2 -0
- package/dist/expressions/funcs/std.d.ts.map +1 -0
- package/dist/expressions/funcs/std.js +293 -0
- package/dist/expressions/funcs/std.js.map +1 -0
- package/dist/expressions/funcs/stored.d.ts +4 -0
- package/dist/expressions/funcs/stored.d.ts.map +1 -0
- package/dist/expressions/funcs/stored.js +62 -0
- package/dist/expressions/funcs/stored.js.map +1 -0
- package/dist/expressions/funcs/strings.d.ts +2 -0
- package/dist/expressions/funcs/strings.d.ts.map +1 -0
- package/dist/expressions/funcs/strings.js +158 -0
- package/dist/expressions/funcs/strings.js.map +1 -0
- package/dist/expressions/funcs/trigonometry.d.ts +2 -0
- package/dist/expressions/funcs/trigonometry.d.ts.map +1 -0
- package/dist/expressions/funcs/trigonometry.js +92 -0
- package/dist/expressions/funcs/trigonometry.js.map +1 -0
- package/dist/expressions/json.d.ts +18 -0
- package/dist/expressions/json.d.ts.map +1 -0
- package/dist/expressions/json.js +271 -0
- package/dist/expressions/json.js.map +1 -0
- package/dist/expressions/parserCache.d.ts +4 -0
- package/dist/expressions/parserCache.d.ts.map +1 -0
- package/dist/expressions/parserCache.js +23 -0
- package/dist/expressions/parserCache.js.map +1 -0
- package/dist/expressions/simpleUnescapeString.d.ts +2 -0
- package/dist/expressions/simpleUnescapeString.d.ts.map +1 -0
- package/dist/expressions/simpleUnescapeString.js +61 -0
- package/dist/expressions/simpleUnescapeString.js.map +1 -0
- package/dist/expressions/utils.d.ts +29 -0
- package/dist/expressions/utils.d.ts.map +1 -0
- package/dist/expressions/utils.js +236 -0
- package/dist/expressions/utils.js.map +1 -0
- package/dist/expressions/variable.d.ts +82 -0
- package/dist/expressions/variable.d.ts.map +1 -0
- package/dist/expressions/variable.js +337 -0
- package/dist/expressions/variable.js.map +1 -0
- package/dist/expressions/walk.d.ts +7 -0
- package/dist/expressions/walk.d.ts.map +1 -0
- package/dist/expressions/walk.js +39 -0
- package/dist/expressions/walk.js.map +1 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +11 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAction.d.ts +102 -0
- package/dist/hooks/useAction.d.ts.map +1 -0
- package/dist/hooks/useAction.js +116 -0
- package/dist/hooks/useAction.js.map +1 -0
- package/dist/hooks/useDerivedFromVars.d.ts +72 -0
- package/dist/hooks/useDerivedFromVars.d.ts.map +1 -0
- package/dist/hooks/useDerivedFromVars.js +100 -0
- package/dist/hooks/useDerivedFromVars.js.map +1 -0
- package/dist/hooks/useVariable.d.ts +86 -0
- package/dist/hooks/useVariable.d.ts.map +1 -0
- package/dist/hooks/useVariable.js +130 -0
- package/dist/hooks/useVariable.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/createObservable.d.ts +38 -0
- package/dist/stores/createObservable.d.ts.map +1 -0
- package/dist/stores/createObservable.js +49 -0
- package/dist/stores/createObservable.js.map +1 -0
- package/dist/utils/applyTemplate.d.ts +8 -0
- package/dist/utils/applyTemplate.d.ts.map +1 -0
- package/dist/utils/applyTemplate.js +94 -0
- package/dist/utils/applyTemplate.js.map +1 -0
- package/dist/utils/correctColor.d.ts +18 -0
- package/dist/utils/correctColor.d.ts.map +1 -0
- package/dist/utils/correctColor.js +79 -0
- package/dist/utils/correctColor.js.map +1 -0
- package/dist/utils/escapeRegExp.d.ts +2 -0
- package/dist/utils/escapeRegExp.d.ts.map +1 -0
- package/dist/utils/escapeRegExp.js +4 -0
- package/dist/utils/escapeRegExp.js.map +1 -0
- package/dist/utils/formatDate.d.ts +6 -0
- package/dist/utils/formatDate.d.ts.map +1 -0
- package/dist/utils/formatDate.js +325 -0
- package/dist/utils/formatDate.js.map +1 -0
- package/dist/utils/padLeft.d.ts +2 -0
- package/dist/utils/padLeft.d.ts.map +1 -0
- package/dist/utils/padLeft.js +7 -0
- package/dist/utils/padLeft.js.map +1 -0
- package/dist/utils/uniq.d.ts +2 -0
- package/dist/utils/uniq.d.ts.map +1 -0
- package/dist/utils/uniq.js +4 -0
- package/dist/utils/uniq.js.map +1 -0
- package/dist/utils/wrapError.d.ts +10 -0
- package/dist/utils/wrapError.d.ts.map +1 -0
- package/dist/utils/wrapError.js +9 -0
- package/dist/utils/wrapError.js.map +1 -0
- package/package.json +58 -0
- package/src/DivKit.tsx +542 -0
- package/src/actions/array.ts +170 -0
- package/src/actions/copyToClipboard.ts +82 -0
- package/src/actions/dict.ts +71 -0
- package/src/actions/index.ts +11 -0
- package/src/actions/updateStructure.ts +134 -0
- package/src/components/DivComponent.tsx +75 -0
- package/src/components/README.md +230 -0
- package/src/components/container/DivContainer.tsx +222 -0
- package/src/components/container/index.ts +2 -0
- package/src/components/image/DivImage.tsx +172 -0
- package/src/components/image/index.ts +2 -0
- package/src/components/index.ts +20 -0
- package/src/components/state/DivState.tsx +146 -0
- package/src/components/state/index.ts +2 -0
- package/src/components/text/DivText.tsx +186 -0
- package/src/components/text/index.ts +2 -0
- package/src/components/utilities/Outer.tsx +239 -0
- package/src/components/utilities/README.md +175 -0
- package/src/components/utilities/Unknown.tsx +60 -0
- package/src/components/utilities/index.ts +4 -0
- package/src/context/ActionContext.tsx +37 -0
- package/src/context/DivKitContext.tsx +54 -0
- package/src/context/EnabledContext.tsx +50 -0
- package/src/context/StateContext.tsx +75 -0
- package/src/context/index.ts +33 -0
- package/src/expressions/ast.d.ts +101 -0
- package/src/expressions/bigint.ts +38 -0
- package/src/expressions/const.ts +16 -0
- package/src/expressions/eval.ts +669 -0
- package/src/expressions/expressions.peggy +235 -0
- package/src/expressions/expressions.ts +2854 -0
- package/src/expressions/funcs/array.ts +412 -0
- package/src/expressions/funcs/colors.ts +100 -0
- package/src/expressions/funcs/customFuncs.ts +139 -0
- package/src/expressions/funcs/datetime.ts +232 -0
- package/src/expressions/funcs/dict.ts +207 -0
- package/src/expressions/funcs/funcs.ts +323 -0
- package/src/expressions/funcs/index.ts +23 -0
- package/src/expressions/funcs/interval.ts +76 -0
- package/src/expressions/funcs/math.ts +395 -0
- package/src/expressions/funcs/std.ts +392 -0
- package/src/expressions/funcs/stored.ts +62 -0
- package/src/expressions/funcs/strings.ts +200 -0
- package/src/expressions/funcs/trigonometry.ts +108 -0
- package/src/expressions/json.ts +367 -0
- package/src/expressions/parserCache.ts +32 -0
- package/src/expressions/simpleUnescapeString.ts +57 -0
- package/src/expressions/utils.ts +271 -0
- package/src/expressions/variable.ts +429 -0
- package/src/expressions/walk.ts +43 -0
- package/src/hooks/README.md +265 -0
- package/src/hooks/index.ts +28 -0
- package/src/hooks/useAction.ts +152 -0
- package/src/hooks/useDerivedFromVars.ts +187 -0
- package/src/hooks/useVariable.ts +157 -0
- package/src/index.ts +97 -0
- package/src/stores/createObservable.ts +64 -0
- package/src/types/alignment.d.ts +13 -0
- package/src/types/background.d.ts +71 -0
- package/src/types/base.d.ts +224 -0
- package/src/types/border.d.ts +46 -0
- package/src/types/componentContext.d.ts +98 -0
- package/src/types/container.d.ts +40 -0
- package/src/types/edgeInserts.d.ts +9 -0
- package/src/types/general.d.ts +3 -0
- package/src/types/image.d.ts +33 -0
- package/src/types/imageScale.d.ts +1 -0
- package/src/types/layoutParams.d.ts +27 -0
- package/src/types/sizes.d.ts +37 -0
- package/src/types/state.d.ts +19 -0
- package/src/types/text.d.ts +126 -0
- package/src/utils/applyTemplate.ts +145 -0
- package/src/utils/correctColor.ts +102 -0
- package/src/utils/escapeRegExp.ts +3 -0
- package/src/utils/formatDate.ts +385 -0
- package/src/utils/padLeft.ts +6 -0
- package/src/utils/uniq.ts +3 -0
- package/src/utils/wrapError.ts +21 -0
package/dist/DivKit.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DivKit - Main entry point component for React Native
|
|
3
|
+
*
|
|
4
|
+
* Based on Root.svelte from Web implementation
|
|
5
|
+
* Provides context setup, variable management, and component rendering
|
|
6
|
+
*
|
|
7
|
+
* MVP Scope:
|
|
8
|
+
* - 4 basic components (Text, Container, Image, State)
|
|
9
|
+
* - Variable system with reactive updates
|
|
10
|
+
* - Action execution
|
|
11
|
+
* - Template resolution
|
|
12
|
+
*
|
|
13
|
+
* Deferred for post-MVP:
|
|
14
|
+
* - Timers
|
|
15
|
+
* - Variable triggers
|
|
16
|
+
* - Complex animations
|
|
17
|
+
* - Custom components
|
|
18
|
+
* - Extensions
|
|
19
|
+
*/
|
|
20
|
+
import React, { useMemo, useCallback, useRef } from 'react';
|
|
21
|
+
import { View, StyleSheet } from 'react-native';
|
|
22
|
+
import { DivKitContext } from './context/DivKitContext';
|
|
23
|
+
import { ActionContext } from './context/ActionContext';
|
|
24
|
+
import { StateContext } from './context/StateContext';
|
|
25
|
+
import { DivComponent } from './components/DivComponent';
|
|
26
|
+
import { createVariable } from './expressions/variable';
|
|
27
|
+
import { applyTemplatesRecursively } from './utils/applyTemplate';
|
|
28
|
+
import { wrapError } from './utils/wrapError';
|
|
29
|
+
import { arrayInsert, arrayRemove, arraySet } from './actions/array';
|
|
30
|
+
import { dictSetValue } from './actions/dict';
|
|
31
|
+
import { copyToClipboard } from './actions/copyToClipboard';
|
|
32
|
+
import { updateStructure } from './actions/updateStructure';
|
|
33
|
+
import { evalExpression } from './expressions/eval';
|
|
34
|
+
/**
|
|
35
|
+
* DivKit - Main component
|
|
36
|
+
*
|
|
37
|
+
* Renders DivKit JSON as React Native components
|
|
38
|
+
*/
|
|
39
|
+
export function DivKit({ data, onStat, onCustomAction, onError, direction = 'ltr', platform = 'touch', style, id = 'root' }) {
|
|
40
|
+
const componentIdCounter = useRef(0);
|
|
41
|
+
const componentsMap = useRef(new Map());
|
|
42
|
+
const statesMap = useRef(new Map());
|
|
43
|
+
// Error logging
|
|
44
|
+
const logError = useCallback((error) => {
|
|
45
|
+
if (onError) {
|
|
46
|
+
onError(error);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.error('[DivKit Error]', error);
|
|
50
|
+
}
|
|
51
|
+
}, [onError]);
|
|
52
|
+
// Parse JSON and apply templates
|
|
53
|
+
const { rootDiv, initialVariables } = useMemo(() => {
|
|
54
|
+
const card = data.card;
|
|
55
|
+
if (!card || !card.states || card.states.length === 0) {
|
|
56
|
+
logError(wrapError(new Error('Invalid DivKit JSON: missing card or states')));
|
|
57
|
+
return {
|
|
58
|
+
rootDiv: null,
|
|
59
|
+
initialVariables: []
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const state = card.states[0];
|
|
63
|
+
const divData = state.div;
|
|
64
|
+
const templatesData = data.templates || {};
|
|
65
|
+
// Apply template if needed
|
|
66
|
+
let resolvedDiv = divData;
|
|
67
|
+
if (divData && typeof divData === 'object' && 'type' in divData) {
|
|
68
|
+
try {
|
|
69
|
+
// Use recursive template application to handle nested templates
|
|
70
|
+
resolvedDiv = applyTemplatesRecursively(divData, templatesData, logError);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
logError(wrapError(err, {
|
|
74
|
+
additional: { phase: 'template_resolution' }
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
rootDiv: resolvedDiv,
|
|
80
|
+
initialVariables: card.variables || []
|
|
81
|
+
};
|
|
82
|
+
}, [data, logError]);
|
|
83
|
+
// Initialize variables
|
|
84
|
+
const variables = useMemo(() => {
|
|
85
|
+
const map = new Map();
|
|
86
|
+
initialVariables.forEach((varData) => {
|
|
87
|
+
try {
|
|
88
|
+
// Skip property variables for MVP (complex feature)
|
|
89
|
+
if (varData.type === 'property') {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const variable = createVariable(varData.name, varData.type, varData.value);
|
|
93
|
+
map.set(varData.name, variable);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
logError(wrapError(err, {
|
|
97
|
+
additional: {
|
|
98
|
+
variable: varData.name,
|
|
99
|
+
type: varData.type
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return map;
|
|
105
|
+
}, [initialVariables, logError]);
|
|
106
|
+
// Generate unique component IDs
|
|
107
|
+
const genId = useCallback((key) => {
|
|
108
|
+
return `${key}_${componentIdCounter.current++}`;
|
|
109
|
+
}, []);
|
|
110
|
+
// Variable management
|
|
111
|
+
const getVariable = useCallback((name) => {
|
|
112
|
+
return variables.get(name);
|
|
113
|
+
}, [variables]);
|
|
114
|
+
const setVariable = useCallback((name, value) => {
|
|
115
|
+
const variable = variables.get(name);
|
|
116
|
+
if (!variable) {
|
|
117
|
+
logError(wrapError(new Error('Variable not found'), {
|
|
118
|
+
additional: { variable: name }
|
|
119
|
+
}));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
variable.setValue(value);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
logError(wrapError(err, {
|
|
127
|
+
additional: {
|
|
128
|
+
variable: name,
|
|
129
|
+
value
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
}, [variables, logError]);
|
|
134
|
+
// Action execution
|
|
135
|
+
const execAnyActions = useCallback(async (actions, opts) => {
|
|
136
|
+
if (!actions || !Array.isArray(actions)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const processUrls = opts?.processUrls ?? true;
|
|
140
|
+
const componentContext = opts?.componentContext;
|
|
141
|
+
for (const action of actions) {
|
|
142
|
+
if (!action)
|
|
143
|
+
continue;
|
|
144
|
+
// Log statistics
|
|
145
|
+
if (action.log_id && onStat) {
|
|
146
|
+
onStat({
|
|
147
|
+
type: 'action',
|
|
148
|
+
action: action
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Handle typed actions
|
|
152
|
+
if (action.typed) {
|
|
153
|
+
const typed = action.typed;
|
|
154
|
+
try {
|
|
155
|
+
switch (typed.type) {
|
|
156
|
+
case 'set_variable':
|
|
157
|
+
if (typed.variable_name && typed.value) {
|
|
158
|
+
const typedValue = typed.value;
|
|
159
|
+
let value;
|
|
160
|
+
// Convert typed value to raw value
|
|
161
|
+
if (typeof typedValue === 'object' && typedValue !== null && 'value' in typedValue) {
|
|
162
|
+
value = typedValue.value;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
value = typedValue;
|
|
166
|
+
}
|
|
167
|
+
setVariable(typed.variable_name, value);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case 'set_state': {
|
|
171
|
+
const setStateAction = typed;
|
|
172
|
+
if (setStateAction.state_id && setStateAction.temporary_state_id) {
|
|
173
|
+
const setter = statesMap.current.get(setStateAction.state_id);
|
|
174
|
+
if (setter) {
|
|
175
|
+
await setter(String(setStateAction.temporary_state_id));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'array_insert_value':
|
|
181
|
+
arrayInsert(componentContext, variables, logError, typed);
|
|
182
|
+
break;
|
|
183
|
+
case 'array_remove_value':
|
|
184
|
+
arrayRemove(componentContext, variables, logError, typed);
|
|
185
|
+
break;
|
|
186
|
+
case 'array_set_value':
|
|
187
|
+
arraySet(componentContext, variables, logError, typed);
|
|
188
|
+
break;
|
|
189
|
+
case 'dict_set_value':
|
|
190
|
+
dictSetValue(componentContext, variables, logError, typed);
|
|
191
|
+
break;
|
|
192
|
+
case 'update_structure':
|
|
193
|
+
updateStructure(componentContext, variables, logError, typed);
|
|
194
|
+
break;
|
|
195
|
+
case 'copy_to_clipboard':
|
|
196
|
+
copyToClipboard(logError, typed);
|
|
197
|
+
break;
|
|
198
|
+
// MVP: Other action types deferred (timer, animator, etc.)
|
|
199
|
+
default:
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
logError(wrapError(err, {
|
|
205
|
+
additional: {
|
|
206
|
+
action: typed.type
|
|
207
|
+
}
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Handle URL actions
|
|
212
|
+
if (processUrls && action.url && onCustomAction) {
|
|
213
|
+
onCustomAction(action);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}, [variables, logError, onStat, onCustomAction, setVariable]);
|
|
217
|
+
// Component registration
|
|
218
|
+
const registerComponent = useCallback((_componentId, context) => {
|
|
219
|
+
componentsMap.current.set(context.id, context);
|
|
220
|
+
}, []);
|
|
221
|
+
const unregisterComponent = useCallback((_componentId) => {
|
|
222
|
+
// Component cleanup
|
|
223
|
+
}, []);
|
|
224
|
+
// State Context implementation
|
|
225
|
+
const stateContextValue = useMemo(() => ({
|
|
226
|
+
registerState: (componentId, setState) => {
|
|
227
|
+
statesMap.current.set(componentId, setState);
|
|
228
|
+
return () => {
|
|
229
|
+
statesMap.current.delete(componentId);
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
switchState: async (stateId) => {
|
|
233
|
+
const setter = statesMap.current.get(stateId);
|
|
234
|
+
if (setter) {
|
|
235
|
+
await setter(stateId);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
getStateSetter: (componentId) => {
|
|
239
|
+
return statesMap.current.get(componentId);
|
|
240
|
+
},
|
|
241
|
+
registerChild: (_componentId) => {
|
|
242
|
+
// MVP: Simplified implementation
|
|
243
|
+
// Full transition tracking deferred
|
|
244
|
+
},
|
|
245
|
+
unregisterChild: (_componentId) => {
|
|
246
|
+
// MVP: Simplified implementation
|
|
247
|
+
},
|
|
248
|
+
hasTransitionChange: () => {
|
|
249
|
+
// MVP: Always false (transitions deferred)
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}), []);
|
|
253
|
+
// Action Context implementation
|
|
254
|
+
const actionContextValue = useMemo(() => ({
|
|
255
|
+
hasAction: () => {
|
|
256
|
+
// MVP: Simplified - always return false
|
|
257
|
+
// Full action tracking deferred
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}), []);
|
|
261
|
+
// DivKit Context implementation
|
|
262
|
+
const divKitContextValue = useMemo(() => ({
|
|
263
|
+
logStat: (type, action) => {
|
|
264
|
+
if (onStat && action && action.log_id) {
|
|
265
|
+
onStat({ type, action: action });
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
execCustomAction: (action) => {
|
|
269
|
+
if (onCustomAction) {
|
|
270
|
+
onCustomAction(action);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
direction,
|
|
274
|
+
platform,
|
|
275
|
+
variables,
|
|
276
|
+
getVariable,
|
|
277
|
+
setVariable,
|
|
278
|
+
registerComponent,
|
|
279
|
+
unregisterComponent,
|
|
280
|
+
execAnyActions,
|
|
281
|
+
genId
|
|
282
|
+
}), [
|
|
283
|
+
onStat,
|
|
284
|
+
onCustomAction,
|
|
285
|
+
direction,
|
|
286
|
+
platform,
|
|
287
|
+
variables,
|
|
288
|
+
getVariable,
|
|
289
|
+
setVariable,
|
|
290
|
+
registerComponent,
|
|
291
|
+
unregisterComponent,
|
|
292
|
+
execAnyActions,
|
|
293
|
+
genId
|
|
294
|
+
]);
|
|
295
|
+
// Create root component context
|
|
296
|
+
const rootComponentContext = useMemo(() => {
|
|
297
|
+
if (!rootDiv) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
const context = {
|
|
301
|
+
path: [],
|
|
302
|
+
json: rootDiv,
|
|
303
|
+
origJson: rootDiv,
|
|
304
|
+
templateContext: {},
|
|
305
|
+
variables,
|
|
306
|
+
id: genId(id),
|
|
307
|
+
logError,
|
|
308
|
+
execAnyActions,
|
|
309
|
+
// MVP: Simplified implementations
|
|
310
|
+
getDerivedFromVars: (jsonProp) => {
|
|
311
|
+
// This is a placeholder for Svelte's readable store
|
|
312
|
+
// In React Native, we use hooks instead (useDerivedFromVars)
|
|
313
|
+
return jsonProp;
|
|
314
|
+
},
|
|
315
|
+
getJsonWithVars: (jsonProp) => {
|
|
316
|
+
// Simplified implementation for MVP
|
|
317
|
+
return jsonProp;
|
|
318
|
+
},
|
|
319
|
+
evalExpression: (store, expr, opts) => {
|
|
320
|
+
const allVars = variables;
|
|
321
|
+
return evalExpression(allVars, undefined, store, expr, opts);
|
|
322
|
+
},
|
|
323
|
+
produceChildContext: (div, opts) => {
|
|
324
|
+
const childPath = opts?.path !== undefined
|
|
325
|
+
? [...context.path, String(opts.path)]
|
|
326
|
+
: context.path;
|
|
327
|
+
const childContext = {
|
|
328
|
+
...context,
|
|
329
|
+
path: childPath,
|
|
330
|
+
parent: context,
|
|
331
|
+
json: div,
|
|
332
|
+
origJson: opts?.origJson || div,
|
|
333
|
+
id: opts?.id || genId('component'),
|
|
334
|
+
variables: opts?.variables || variables,
|
|
335
|
+
isRootState: opts?.isRootState,
|
|
336
|
+
isTooltipRoot: opts?.isTooltipRoot,
|
|
337
|
+
key: opts?.key
|
|
338
|
+
};
|
|
339
|
+
return childContext;
|
|
340
|
+
},
|
|
341
|
+
dup: (fakeReason) => {
|
|
342
|
+
return {
|
|
343
|
+
...context,
|
|
344
|
+
fakeElement: fakeReason
|
|
345
|
+
};
|
|
346
|
+
},
|
|
347
|
+
getVariable: (varName) => {
|
|
348
|
+
return variables.get(varName);
|
|
349
|
+
},
|
|
350
|
+
getAnimator: () => {
|
|
351
|
+
// MVP: Animators deferred
|
|
352
|
+
return undefined;
|
|
353
|
+
},
|
|
354
|
+
registerState: (stateId, setState) => {
|
|
355
|
+
// Convert ComponentContext StateSetter to StateContext StateSetter
|
|
356
|
+
const wrappedSetState = async (id) => {
|
|
357
|
+
await setState(id);
|
|
358
|
+
return undefined;
|
|
359
|
+
};
|
|
360
|
+
return stateContextValue.registerState(stateId, wrappedSetState);
|
|
361
|
+
},
|
|
362
|
+
registerPager: () => {
|
|
363
|
+
// MVP: Pagers deferred
|
|
364
|
+
return {
|
|
365
|
+
update: () => { },
|
|
366
|
+
destroy: () => { }
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
listenPager: () => {
|
|
370
|
+
// MVP: Pagers deferred
|
|
371
|
+
return () => { };
|
|
372
|
+
},
|
|
373
|
+
destroy: () => {
|
|
374
|
+
// Cleanup if needed
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
return context;
|
|
378
|
+
}, [rootDiv, variables, logError, execAnyActions, genId, id, stateContextValue]);
|
|
379
|
+
// Render
|
|
380
|
+
if (!rootDiv || !rootComponentContext) {
|
|
381
|
+
return (<View style={[styles.container, style]}>
|
|
382
|
+
{/* Empty state - could render error UI here */}
|
|
383
|
+
</View>);
|
|
384
|
+
}
|
|
385
|
+
return (<DivKitContext.Provider value={divKitContextValue}>
|
|
386
|
+
<ActionContext.Provider value={actionContextValue}>
|
|
387
|
+
<StateContext.Provider value={stateContextValue}>
|
|
388
|
+
<View style={[styles.container, style]}>
|
|
389
|
+
<DivComponent componentContext={rootComponentContext}/>
|
|
390
|
+
</View>
|
|
391
|
+
</StateContext.Provider>
|
|
392
|
+
</ActionContext.Provider>
|
|
393
|
+
</DivKitContext.Provider>);
|
|
394
|
+
}
|
|
395
|
+
const styles = StyleSheet.create({
|
|
396
|
+
container: {
|
|
397
|
+
flex: 1
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
//# sourceMappingURL=DivKit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DivKit.js","sourceRoot":"","sources":["../src/DivKit.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAC;AAKhE,OAAO,EAAE,aAAa,EAA2B,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,aAAa,EAA2B,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,YAAY,EAA4C,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAA+B,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAqB,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAiDpD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,EACnB,IAAI,EACJ,MAAM,EACN,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AE,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAEjF,SAAS;IACT,IAAI,CAAC,OAAO,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACpC,OAAO,CACH,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CACnC;gBAAA,CAAC,8CAA8C,CACnD;YAAA,EAAE,IAAI,CAAC,CACV,CAAC;IACN,CAAC;IAED,OAAO,CACH,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAC9C;YAAA,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,CAC9C;gBAAA,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC,CAC5C;oBAAA,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CACnC;wBAAA,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,EACzD;oBAAA,EAAE,IAAI,CACV;gBAAA,EAAE,YAAY,CAAC,QAAQ,CAC3B;YAAA,EAAE,aAAa,CAAC,QAAQ,CAC5B;QAAA,EAAE,aAAa,CAAC,QAAQ,CAAC,CAC5B,CAAC;AACN,CAAC;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE;QACP,IAAI,EAAE,CAAC;KACV;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionArrayInsertValue, ActionArrayRemoveValue, ActionArraySetValue, WrappedError } from '../../typings/common';
|
|
2
|
+
import type { Variable } from '../../typings/variables';
|
|
3
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
4
|
+
import type { ComponentContext } from '../types/componentContext';
|
|
5
|
+
export declare function arrayInsert(componentContext: ComponentContext | undefined, variables: Map<string, Variable>, logError: (error: WrappedError) => void, actionTyped: MaybeMissing<ActionArrayInsertValue>): void;
|
|
6
|
+
export declare function arrayRemove(componentContext: ComponentContext | undefined, variables: Map<string, Variable>, logError: (error: WrappedError) => void, actionTyped: MaybeMissing<ActionArrayRemoveValue>): void;
|
|
7
|
+
export declare function arraySet(componentContext: ComponentContext | undefined, variables: Map<string, Variable>, logError: (error: WrappedError) => void, actionTyped: MaybeMissing<ActionArraySetValue>): void;
|
|
8
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/actions/array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9H,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,wBAAgB,WAAW,CACvB,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,EAC9C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,WAAW,EAAE,YAAY,CAAC,sBAAsB,CAAC,GAClD,IAAI,CAuCN;AAED,wBAAgB,WAAW,CACvB,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,EAC9C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,WAAW,EAAE,YAAY,CAAC,sBAAsB,CAAC,GAClD,IAAI,CA4BN;AAED,wBAAgB,QAAQ,CACpB,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,EAC9C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,WAAW,EAAE,YAAY,CAAC,mBAAmB,CAAC,GAC/C,IAAI,CAkCN"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { convertTypedValue } from '../expressions/utils';
|
|
2
|
+
import { wrapError } from '../utils/wrapError';
|
|
3
|
+
export function arrayInsert(componentContext, variables, logError, actionTyped) {
|
|
4
|
+
const { variable_name: name, index, value } = actionTyped;
|
|
5
|
+
if (!value || typeof index !== 'number' && index !== undefined) {
|
|
6
|
+
logError(wrapError(new Error('Incorrect array_insert_value action'), {
|
|
7
|
+
additional: {
|
|
8
|
+
name
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
14
|
+
const list = variableInstance.getValue();
|
|
15
|
+
if (typeof index === 'number' && (index < 0 || index > list.length)) {
|
|
16
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
17
|
+
additional: {
|
|
18
|
+
name,
|
|
19
|
+
index,
|
|
20
|
+
length: list.length
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
else if (!value.type) {
|
|
25
|
+
logError(wrapError(new Error('Incorrect value type'), {
|
|
26
|
+
additional: {
|
|
27
|
+
name
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const newList = list.slice();
|
|
33
|
+
const val = convertTypedValue(value);
|
|
34
|
+
if (typeof index === 'number') {
|
|
35
|
+
newList.splice(index, 0, val);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
newList.push(val);
|
|
39
|
+
}
|
|
40
|
+
variableInstance.setValue(newList);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function arrayRemove(componentContext, variables, logError, actionTyped) {
|
|
45
|
+
const { variable_name: name, index } = actionTyped;
|
|
46
|
+
if (typeof index !== 'number') {
|
|
47
|
+
logError(wrapError(new Error('Incorrect array_remove_value action'), {
|
|
48
|
+
additional: {
|
|
49
|
+
name
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
55
|
+
const list = variableInstance.getValue();
|
|
56
|
+
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
57
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
58
|
+
additional: {
|
|
59
|
+
name,
|
|
60
|
+
index,
|
|
61
|
+
length: list.length
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const newList = list.slice();
|
|
67
|
+
newList.splice(index, 1);
|
|
68
|
+
variableInstance.setValue(newList);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function arraySet(componentContext, variables, logError, actionTyped) {
|
|
73
|
+
const { variable_name: name, index, value } = actionTyped;
|
|
74
|
+
if (!value || typeof index !== 'number') {
|
|
75
|
+
logError(wrapError(new Error('Incorrect array_set_value action'), {
|
|
76
|
+
additional: {
|
|
77
|
+
name
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
83
|
+
const list = variableInstance.getValue();
|
|
84
|
+
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
85
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
86
|
+
additional: {
|
|
87
|
+
name,
|
|
88
|
+
index,
|
|
89
|
+
length: list.length
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
else if (!value.type) {
|
|
94
|
+
logError(wrapError(new Error('Incorrect value type'), {
|
|
95
|
+
additional: {
|
|
96
|
+
name
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const newList = list.slice();
|
|
102
|
+
newList[index] = convertTypedValue(value);
|
|
103
|
+
variableInstance.setValue(newList);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function handle(componentContext, variables, logError, actionTyped, cb) {
|
|
108
|
+
const { variable_name: name } = actionTyped;
|
|
109
|
+
if (!name) {
|
|
110
|
+
logError(wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
111
|
+
additional: {
|
|
112
|
+
name
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
118
|
+
if (!variableInstance) {
|
|
119
|
+
logError(wrapError(new Error('Cannot find variable'), {
|
|
120
|
+
additional: {
|
|
121
|
+
name
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const type = variableInstance.getType();
|
|
127
|
+
if (type === 'array') {
|
|
128
|
+
cb(variableInstance);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
logError(wrapError(new Error('Trying to insert value into the non-array'), {
|
|
132
|
+
additional: {
|
|
133
|
+
name,
|
|
134
|
+
type
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/actions/array.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,U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|
|
2
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
3
|
+
/**
|
|
4
|
+
* Clipboard interface for React Native
|
|
5
|
+
* Uses @react-native-clipboard/clipboard when available
|
|
6
|
+
*/
|
|
7
|
+
interface ClipboardInterface {
|
|
8
|
+
setString: (content: string) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Initialize clipboard module
|
|
12
|
+
* This function attempts to load @react-native-clipboard/clipboard
|
|
13
|
+
* Returns true if clipboard is available
|
|
14
|
+
*/
|
|
15
|
+
export declare function initClipboard(clipboardModule?: ClipboardInterface): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Copy content to clipboard
|
|
18
|
+
* Requires @react-native-clipboard/clipboard to be installed
|
|
19
|
+
*/
|
|
20
|
+
export declare function copyToClipboard(logError: (error: WrappedError) => void, actionTyped: MaybeMissing<ActionCopyToClipboard>): void;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=copyToClipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyToClipboard.d.ts","sourceRoot":"","sources":["../../src/actions/copyToClipboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;GAGG;AACH,UAAU,kBAAkB;IACxB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAKD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,eAAe,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAgB3E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,WAAW,EAAE,YAAY,CAAC,qBAAqB,CAAC,GACjD,IAAI,CAoCN"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { wrapError } from '../utils/wrapError';
|
|
2
|
+
// Optional clipboard module - will be undefined if not installed
|
|
3
|
+
let Clipboard;
|
|
4
|
+
/**
|
|
5
|
+
* Initialize clipboard module
|
|
6
|
+
* This function attempts to load @react-native-clipboard/clipboard
|
|
7
|
+
* Returns true if clipboard is available
|
|
8
|
+
*/
|
|
9
|
+
export function initClipboard(clipboardModule) {
|
|
10
|
+
if (clipboardModule) {
|
|
11
|
+
Clipboard = clipboardModule;
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// Try to dynamically require the clipboard module
|
|
15
|
+
try {
|
|
16
|
+
// This will work if @react-native-clipboard/clipboard is installed
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
+
Clipboard = require('@react-native-clipboard/clipboard').default;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Clipboard module not installed
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Copy content to clipboard
|
|
28
|
+
* Requires @react-native-clipboard/clipboard to be installed
|
|
29
|
+
*/
|
|
30
|
+
export function copyToClipboard(logError, actionTyped) {
|
|
31
|
+
if (!(actionTyped.content && (actionTyped.content.type === 'text' || actionTyped.content.type === 'url') &&
|
|
32
|
+
typeof actionTyped.content.value === 'string')) {
|
|
33
|
+
logError(wrapError(new Error('Incorrect action'), {
|
|
34
|
+
additional: {
|
|
35
|
+
action: actionTyped
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Ensure clipboard is initialized
|
|
41
|
+
if (!Clipboard) {
|
|
42
|
+
initClipboard();
|
|
43
|
+
}
|
|
44
|
+
if (!Clipboard) {
|
|
45
|
+
logError(wrapError(new Error('Clipboard is unavailable. Install @react-native-clipboard/clipboard'), {
|
|
46
|
+
additional: {
|
|
47
|
+
action: actionTyped
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
Clipboard.setString(actionTyped.content.value);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
logError(wrapError(new Error('Failed to copy to the clipboard'), {
|
|
57
|
+
additional: {
|
|
58
|
+
originalError: String(err)
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=copyToClipboard.js.map
|