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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ActionArrayInsertValue, ActionArrayRemoveValue, ActionArraySetValue, WrappedError } from '../../typings/common';
|
|
2
|
+
import type { ArrayVariable, Variable } from '../../typings/variables';
|
|
3
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
4
|
+
import { convertTypedValue } from '../expressions/utils';
|
|
5
|
+
import type { ComponentContext } from '../types/componentContext';
|
|
6
|
+
import { wrapError } from '../utils/wrapError';
|
|
7
|
+
|
|
8
|
+
export function arrayInsert(
|
|
9
|
+
componentContext: ComponentContext | undefined,
|
|
10
|
+
variables: Map<string, Variable>,
|
|
11
|
+
logError: (error: WrappedError) => void,
|
|
12
|
+
actionTyped: MaybeMissing<ActionArrayInsertValue>
|
|
13
|
+
): void {
|
|
14
|
+
const { variable_name: name, index, value } = actionTyped;
|
|
15
|
+
|
|
16
|
+
if (!value || typeof index !== 'number' && index !== undefined) {
|
|
17
|
+
logError(wrapError(new Error('Incorrect array_insert_value action'), {
|
|
18
|
+
additional: {
|
|
19
|
+
name
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
26
|
+
const list = variableInstance.getValue();
|
|
27
|
+
if (typeof index === 'number' && (index < 0 || index > list.length)) {
|
|
28
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
29
|
+
additional: {
|
|
30
|
+
name,
|
|
31
|
+
index,
|
|
32
|
+
length: list.length
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
} else if (!value.type) {
|
|
36
|
+
logError(wrapError(new Error('Incorrect value type'), {
|
|
37
|
+
additional: {
|
|
38
|
+
name
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
} else {
|
|
42
|
+
const newList = list.slice();
|
|
43
|
+
const val = convertTypedValue(value);
|
|
44
|
+
if (typeof index === 'number') {
|
|
45
|
+
newList.splice(index, 0, val);
|
|
46
|
+
} else {
|
|
47
|
+
newList.push(val);
|
|
48
|
+
}
|
|
49
|
+
variableInstance.setValue(newList);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function arrayRemove(
|
|
55
|
+
componentContext: ComponentContext | undefined,
|
|
56
|
+
variables: Map<string, Variable>,
|
|
57
|
+
logError: (error: WrappedError) => void,
|
|
58
|
+
actionTyped: MaybeMissing<ActionArrayRemoveValue>
|
|
59
|
+
): void {
|
|
60
|
+
const { variable_name: name, index } = actionTyped;
|
|
61
|
+
|
|
62
|
+
if (typeof index !== 'number') {
|
|
63
|
+
logError(wrapError(new Error('Incorrect array_remove_value action'), {
|
|
64
|
+
additional: {
|
|
65
|
+
name
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
72
|
+
const list = variableInstance.getValue();
|
|
73
|
+
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
74
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
75
|
+
additional: {
|
|
76
|
+
name,
|
|
77
|
+
index,
|
|
78
|
+
length: list.length
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
} else {
|
|
82
|
+
const newList = list.slice();
|
|
83
|
+
newList.splice(index, 1);
|
|
84
|
+
variableInstance.setValue(newList);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function arraySet(
|
|
90
|
+
componentContext: ComponentContext | undefined,
|
|
91
|
+
variables: Map<string, Variable>,
|
|
92
|
+
logError: (error: WrappedError) => void,
|
|
93
|
+
actionTyped: MaybeMissing<ActionArraySetValue>
|
|
94
|
+
): void {
|
|
95
|
+
const { variable_name: name, index, value } = actionTyped;
|
|
96
|
+
|
|
97
|
+
if (!value || typeof index !== 'number') {
|
|
98
|
+
logError(wrapError(new Error('Incorrect array_set_value action'), {
|
|
99
|
+
additional: {
|
|
100
|
+
name
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
handle(componentContext, variables, logError, actionTyped, variableInstance => {
|
|
107
|
+
const list = variableInstance.getValue();
|
|
108
|
+
if (typeof index === 'number' && (index < 0 || index >= list.length)) {
|
|
109
|
+
logError(wrapError(new Error(`Index out of bound for mutation ${actionTyped.type}`), {
|
|
110
|
+
additional: {
|
|
111
|
+
name,
|
|
112
|
+
index,
|
|
113
|
+
length: list.length
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
} else if (!value.type) {
|
|
117
|
+
logError(wrapError(new Error('Incorrect value type'), {
|
|
118
|
+
additional: {
|
|
119
|
+
name
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
} else {
|
|
123
|
+
const newList = list.slice();
|
|
124
|
+
newList[index] = convertTypedValue(value);
|
|
125
|
+
variableInstance.setValue(newList);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function handle(
|
|
131
|
+
componentContext: ComponentContext | undefined,
|
|
132
|
+
variables: Map<string, Variable>,
|
|
133
|
+
logError: (error: WrappedError) => void,
|
|
134
|
+
actionTyped: MaybeMissing<ActionArrayRemoveValue | ActionArrayInsertValue | ActionArraySetValue>,
|
|
135
|
+
cb: (variableInstance: ArrayVariable) => void
|
|
136
|
+
): void {
|
|
137
|
+
const { variable_name: name } = actionTyped;
|
|
138
|
+
|
|
139
|
+
if (!name) {
|
|
140
|
+
logError(wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
141
|
+
additional: {
|
|
142
|
+
name
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
149
|
+
|
|
150
|
+
if (!variableInstance) {
|
|
151
|
+
logError(wrapError(new Error('Cannot find variable'), {
|
|
152
|
+
additional: {
|
|
153
|
+
name
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const type = variableInstance.getType();
|
|
160
|
+
if (type === 'array') {
|
|
161
|
+
cb(variableInstance as ArrayVariable);
|
|
162
|
+
} else {
|
|
163
|
+
logError(wrapError(new Error('Trying to insert value into the non-array'), {
|
|
164
|
+
additional: {
|
|
165
|
+
name,
|
|
166
|
+
type
|
|
167
|
+
}
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ActionCopyToClipboard, WrappedError } from '../../typings/common';
|
|
2
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
3
|
+
import { wrapError } from '../utils/wrapError';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Clipboard interface for React Native
|
|
7
|
+
* Uses @react-native-clipboard/clipboard when available
|
|
8
|
+
*/
|
|
9
|
+
interface ClipboardInterface {
|
|
10
|
+
setString: (content: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Optional clipboard module - will be undefined if not installed
|
|
14
|
+
let Clipboard: ClipboardInterface | undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize clipboard module
|
|
18
|
+
* This function attempts to load @react-native-clipboard/clipboard
|
|
19
|
+
* Returns true if clipboard is available
|
|
20
|
+
*/
|
|
21
|
+
export function initClipboard(clipboardModule?: ClipboardInterface): boolean {
|
|
22
|
+
if (clipboardModule) {
|
|
23
|
+
Clipboard = clipboardModule;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Try to dynamically require the clipboard module
|
|
28
|
+
try {
|
|
29
|
+
// This will work if @react-native-clipboard/clipboard is installed
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
31
|
+
Clipboard = require('@react-native-clipboard/clipboard').default;
|
|
32
|
+
return true;
|
|
33
|
+
} catch {
|
|
34
|
+
// Clipboard module not installed
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Copy content to clipboard
|
|
41
|
+
* Requires @react-native-clipboard/clipboard to be installed
|
|
42
|
+
*/
|
|
43
|
+
export function copyToClipboard(
|
|
44
|
+
logError: (error: WrappedError) => void,
|
|
45
|
+
actionTyped: MaybeMissing<ActionCopyToClipboard>
|
|
46
|
+
): void {
|
|
47
|
+
if (!(
|
|
48
|
+
actionTyped.content && (actionTyped.content.type === 'text' || actionTyped.content.type === 'url') &&
|
|
49
|
+
typeof actionTyped.content.value === 'string'
|
|
50
|
+
)) {
|
|
51
|
+
logError(wrapError(new Error('Incorrect action'), {
|
|
52
|
+
additional: {
|
|
53
|
+
action: actionTyped
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Ensure clipboard is initialized
|
|
60
|
+
if (!Clipboard) {
|
|
61
|
+
initClipboard();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!Clipboard) {
|
|
65
|
+
logError(wrapError(new Error('Clipboard is unavailable. Install @react-native-clipboard/clipboard'), {
|
|
66
|
+
additional: {
|
|
67
|
+
action: actionTyped
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
Clipboard.setString(actionTyped.content.value);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
logError(wrapError(new Error('Failed to copy to the clipboard'), {
|
|
77
|
+
additional: {
|
|
78
|
+
originalError: String(err)
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ActionDictSetValue, WrappedError } from '../../typings/common';
|
|
2
|
+
import type { Variable } from '../../typings/variables';
|
|
3
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
4
|
+
import { convertTypedValue } from '../expressions/utils';
|
|
5
|
+
import type { ComponentContext } from '../types/componentContext';
|
|
6
|
+
import { wrapError } from '../utils/wrapError';
|
|
7
|
+
|
|
8
|
+
export function dictSetValue(
|
|
9
|
+
componentContext: ComponentContext | undefined,
|
|
10
|
+
variables: Map<string, Variable>,
|
|
11
|
+
logError: (error: WrappedError) => void,
|
|
12
|
+
actionTyped: MaybeMissing<ActionDictSetValue>
|
|
13
|
+
): void {
|
|
14
|
+
const { variable_name: name, key, value } = actionTyped;
|
|
15
|
+
|
|
16
|
+
if (typeof key !== 'string') {
|
|
17
|
+
logError(wrapError(new Error('Incorrect dict_set_value action'), {
|
|
18
|
+
additional: {
|
|
19
|
+
name
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!name) {
|
|
26
|
+
logError(wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
27
|
+
additional: {
|
|
28
|
+
name
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (value && !value.type) {
|
|
35
|
+
logError(wrapError(new Error('Incorrect value type'), {
|
|
36
|
+
additional: {
|
|
37
|
+
name
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
43
|
+
|
|
44
|
+
if (!variableInstance) {
|
|
45
|
+
logError(wrapError(new Error('Cannot find variable'), {
|
|
46
|
+
additional: {
|
|
47
|
+
name
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const type = variableInstance.getType();
|
|
54
|
+
if (type === 'dict') {
|
|
55
|
+
const dict = variableInstance.getValue() as Record<string, unknown>;
|
|
56
|
+
const newDict = { ...dict };
|
|
57
|
+
if (value) {
|
|
58
|
+
newDict[key] = convertTypedValue(value);
|
|
59
|
+
} else {
|
|
60
|
+
delete newDict[key];
|
|
61
|
+
}
|
|
62
|
+
variableInstance.setValue(newDict);
|
|
63
|
+
} else {
|
|
64
|
+
logError(wrapError(new Error('Trying to set value into the non-dict'), {
|
|
65
|
+
additional: {
|
|
66
|
+
name,
|
|
67
|
+
type
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action handlers for DivKit React Native
|
|
3
|
+
*
|
|
4
|
+
* These handlers execute typed actions from DivKit JSON.
|
|
5
|
+
* Ported from Web implementation with React Native adaptations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { arrayInsert, arrayRemove, arraySet } from './array';
|
|
9
|
+
export { dictSetValue } from './dict';
|
|
10
|
+
export { copyToClipboard, initClipboard } from './copyToClipboard';
|
|
11
|
+
export { updateStructure } from './updateStructure';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { ActionUpdateStructure, WrappedError } from '../../typings/common';
|
|
2
|
+
import type { Variable } from '../../typings/variables';
|
|
3
|
+
import type { MaybeMissing } from '../expressions/json';
|
|
4
|
+
import { convertTypedValue } from '../expressions/utils';
|
|
5
|
+
import type { ComponentContext } from '../types/componentContext';
|
|
6
|
+
import { wrapError } from '../utils/wrapError';
|
|
7
|
+
|
|
8
|
+
export function updateStructure(
|
|
9
|
+
componentContext: ComponentContext | undefined,
|
|
10
|
+
variables: Map<string, Variable>,
|
|
11
|
+
logError: (error: WrappedError) => void,
|
|
12
|
+
actionTyped: MaybeMissing<ActionUpdateStructure>
|
|
13
|
+
): void {
|
|
14
|
+
const { variable_name: name, path, value } = actionTyped;
|
|
15
|
+
|
|
16
|
+
if (!value?.value) {
|
|
17
|
+
logError(wrapError(new Error('Missing value for an action'), {
|
|
18
|
+
additional: {
|
|
19
|
+
name
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof path !== 'string' || !path || path.charAt(0) === '/' || path.charAt(path.length - 1) === '/') {
|
|
26
|
+
logError(wrapError(new Error(`Value '${path}' for key 'path' is not valid`), {
|
|
27
|
+
additional: {
|
|
28
|
+
name
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!name) {
|
|
35
|
+
logError(wrapError(new Error(`Incorrect ${actionTyped.type} action`), {
|
|
36
|
+
additional: {
|
|
37
|
+
name
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const variableInstance = componentContext?.getVariable(name) || variables.get(name);
|
|
44
|
+
|
|
45
|
+
if (!variableInstance) {
|
|
46
|
+
logError(wrapError(new Error('Cannot find variable'), {
|
|
47
|
+
additional: {
|
|
48
|
+
name
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const type = variableInstance.getType();
|
|
55
|
+
if (type === 'dict' || type === 'array') {
|
|
56
|
+
const obj = variableInstance.getValue() as Record<string, unknown>;
|
|
57
|
+
const processed = path.replace(/\/+/g, '/');
|
|
58
|
+
if (processed === '/') {
|
|
59
|
+
logError(wrapError(new Error(`Value '${path}' for key 'path' is not valid`), {
|
|
60
|
+
additional: {
|
|
61
|
+
name,
|
|
62
|
+
type,
|
|
63
|
+
path
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const parts = processed.split('/');
|
|
69
|
+
const newObj = type === 'array' ? (obj as unknown as unknown[]).slice() : { ...obj };
|
|
70
|
+
let temp: any = newObj;
|
|
71
|
+
for (let i = 0; i < parts.length; ++i) {
|
|
72
|
+
const part = parts[i];
|
|
73
|
+
|
|
74
|
+
if (!part) {
|
|
75
|
+
logError(wrapError(new Error('Path is empty'), {
|
|
76
|
+
additional: {
|
|
77
|
+
name,
|
|
78
|
+
type,
|
|
79
|
+
path
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!temp || typeof temp !== 'object') {
|
|
86
|
+
logError(wrapError(new Error(`Element with path '${parts.slice(0, i).join('/')}' is not ${temp === undefined ? 'found' : 'a structure'}`), {
|
|
87
|
+
additional: {
|
|
88
|
+
name,
|
|
89
|
+
type,
|
|
90
|
+
path
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(temp)) {
|
|
96
|
+
const int = Number(part);
|
|
97
|
+
if (Number.isNaN(int)) {
|
|
98
|
+
logError(wrapError(new Error(`Unable to use '${part}' as array index`), {
|
|
99
|
+
additional: {
|
|
100
|
+
name,
|
|
101
|
+
type,
|
|
102
|
+
path
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (i + 1 === parts.length && (int < 0 || int > temp.length)) {
|
|
108
|
+
logError(wrapError(new Error(`Position '${int}' is out of array bounds`), {
|
|
109
|
+
additional: {
|
|
110
|
+
name,
|
|
111
|
+
type,
|
|
112
|
+
path
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (i + 1 < parts.length) {
|
|
120
|
+
temp = temp[part];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
temp[parts[parts.length - 1]] = convertTypedValue(value);
|
|
125
|
+
variableInstance.setValue(newObj);
|
|
126
|
+
} else {
|
|
127
|
+
logError(wrapError(new Error('Action requires array or dictionary variable'), {
|
|
128
|
+
additional: {
|
|
129
|
+
name,
|
|
130
|
+
type
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ComponentContext } from '../types/componentContext';
|
|
3
|
+
import type { DivBaseData } from '../types/base';
|
|
4
|
+
import { DivText } from './text';
|
|
5
|
+
import { DivContainer } from './container';
|
|
6
|
+
import { DivImage } from './image';
|
|
7
|
+
import { DivState } from './state';
|
|
8
|
+
import { Unknown } from './utilities/Unknown';
|
|
9
|
+
|
|
10
|
+
export interface DivComponentProps {
|
|
11
|
+
componentContext: ComponentContext<DivBaseData>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* DivComponent - Universal component router
|
|
16
|
+
* Routes to the appropriate component based on the `type` field
|
|
17
|
+
*
|
|
18
|
+
* MVP Components:
|
|
19
|
+
* - text: DivText
|
|
20
|
+
* - container: DivContainer
|
|
21
|
+
* - image: DivImage
|
|
22
|
+
* - gif: DivImage (treated as image)
|
|
23
|
+
* - state: DivState
|
|
24
|
+
*
|
|
25
|
+
* Deferred for post-MVP:
|
|
26
|
+
* - gallery, pager, tabs
|
|
27
|
+
* - slider, indicator
|
|
28
|
+
* - input, select, switch
|
|
29
|
+
* - video, custom
|
|
30
|
+
* - separator
|
|
31
|
+
* - grid
|
|
32
|
+
*
|
|
33
|
+
* Based on Web component resolution logic
|
|
34
|
+
*/
|
|
35
|
+
export function DivComponent({ componentContext }: DivComponentProps) {
|
|
36
|
+
const { json } = componentContext;
|
|
37
|
+
|
|
38
|
+
if (!json || !json.type) {
|
|
39
|
+
return <Unknown type={json?.type || 'undefined'} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Route to appropriate component based on type
|
|
43
|
+
switch (json.type) {
|
|
44
|
+
case 'text':
|
|
45
|
+
return <DivText componentContext={componentContext as any} />;
|
|
46
|
+
|
|
47
|
+
case 'container':
|
|
48
|
+
return <DivContainer componentContext={componentContext as any} />;
|
|
49
|
+
|
|
50
|
+
case 'image':
|
|
51
|
+
case 'gif':
|
|
52
|
+
return <DivImage componentContext={componentContext as any} />;
|
|
53
|
+
|
|
54
|
+
case 'state':
|
|
55
|
+
return <DivState componentContext={componentContext as any} />;
|
|
56
|
+
|
|
57
|
+
// Future components (post-MVP)
|
|
58
|
+
case 'gallery':
|
|
59
|
+
case 'pager':
|
|
60
|
+
case 'tabs':
|
|
61
|
+
case 'slider':
|
|
62
|
+
case 'indicator':
|
|
63
|
+
case 'input':
|
|
64
|
+
case 'select':
|
|
65
|
+
case 'switch':
|
|
66
|
+
case 'video':
|
|
67
|
+
case 'custom':
|
|
68
|
+
case 'separator':
|
|
69
|
+
case 'grid':
|
|
70
|
+
return <Unknown type={json.type} />;
|
|
71
|
+
|
|
72
|
+
default:
|
|
73
|
+
return <Unknown type={json.type} />;
|
|
74
|
+
}
|
|
75
|
+
}
|