embedded-react 0.20.0 → 0.22.0
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/NOTICE +5 -0
- package/README.md +3 -2
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +17 -47
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +62 -10
- package/aot/compiler/collect.mjs +517 -137
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +47 -8
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1378 -97
- package/aot/compiler/handlers.mjs +1807 -354
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +203 -53
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +45 -31
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +18 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +906 -33
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +16 -3
- package/aot/compiler/package/lower.mjs +707 -176
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +20 -5
- package/aot/compiler/svg.mjs +13 -7
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +321 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/style-map.mjs +94 -3
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +85 -94
- package/cli.mjs +490 -586
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +146 -213
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +94 -116
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/Dimensions.mjs +32 -0
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +238 -5
- package/src/embedded-react/index.js +26 -17
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -148
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
|
+
- Imports
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
import { evalStatic, evalStaticOrThrow, withUndefined } from '../static-eval.mjs';
|
|
20
|
+
import { attrExpr } from '../style-text.mjs';
|
|
21
|
+
import { emitNode } from '../nodes.mjs';
|
|
22
|
+
import { attributeOf, elementOf, expressionChild, literalObject, refuseSpreads, } from './rewrite.mjs';
|
|
23
|
+
import { at } from './props.mjs';
|
|
24
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
25
|
+
- Constants
|
|
26
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
27
|
+
// Button.mts's styles. Flow B has no textAlign, so the Pressable centres the label instead.
|
|
28
|
+
const BUTTON_STYLE = {
|
|
29
|
+
backgroundColor: '#2196F3',
|
|
30
|
+
borderRadius: 2,
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
};
|
|
33
|
+
const BUTTON_DISABLED_STYLE = { backgroundColor: '#dfdfdf' };
|
|
34
|
+
const TEXT_STYLE = { color: '#ffffff', padding: 8, fontWeight: '500' };
|
|
35
|
+
const TEXT_DISABLED_STYLE = { color: '#a1a1a1' };
|
|
36
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
37
|
+
- Implementation
|
|
38
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
39
|
+
/**
|
|
40
|
+
* <Button title onPress color disabled /> → the tree Button.mts renders: a styled <Pressable> around one <Text>.
|
|
41
|
+
*
|
|
42
|
+
* @param element The <Button>, its props already checked.
|
|
43
|
+
* @param scope Compile-time constants in reach.
|
|
44
|
+
* @param output Everything emitted so far.
|
|
45
|
+
* @param environment The expression environment.
|
|
46
|
+
* @param state The component's state table.
|
|
47
|
+
* @param options How the element is placed.
|
|
48
|
+
*
|
|
49
|
+
* @returns What the <Pressable> lowers to.
|
|
50
|
+
*/
|
|
51
|
+
export function emitButton(element, scope, output, environment, state, options) {
|
|
52
|
+
refuseSpreads(element, 'Button');
|
|
53
|
+
const attributes = new Map();
|
|
54
|
+
for (const attribute of element.openingElement.attributes) {
|
|
55
|
+
attributes.set(attribute.name.name, attribute);
|
|
56
|
+
}
|
|
57
|
+
// `disabled` picks the styles and drops the press handler, so it must fold.
|
|
58
|
+
const disabledAttribute = attributes.get('disabled');
|
|
59
|
+
let disabled = false;
|
|
60
|
+
if (disabledAttribute) {
|
|
61
|
+
try {
|
|
62
|
+
disabled = !!evalStaticOrThrow(attrExpr(disabledAttribute), scope, 'AOT: <Button disabled> must be a compile-time constant', 'it picks the grey styles and drops onPress at build time. To gate on state, leave it ' +
|
|
63
|
+
'enabled and return early in the handler, or build the <Pressable> + <Text> yourself.');
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw at(error, disabledAttribute);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// A color that folds to nothing keeps the default blue, as `if (color)` does in Flow A.
|
|
70
|
+
const buttonStyles = [literalObject(BUTTON_STYLE)];
|
|
71
|
+
const textStyles = [literalObject(TEXT_STYLE)];
|
|
72
|
+
const colorAttribute = attributes.get('color');
|
|
73
|
+
if (colorAttribute && !disabled && !foldsFalsy(colorAttribute, scope)) {
|
|
74
|
+
buttonStyles.push({
|
|
75
|
+
type: 'ObjectExpression',
|
|
76
|
+
properties: [
|
|
77
|
+
{
|
|
78
|
+
type: 'ObjectProperty',
|
|
79
|
+
key: { type: 'Identifier', name: 'backgroundColor' },
|
|
80
|
+
value: attrExpr(colorAttribute),
|
|
81
|
+
computed: false,
|
|
82
|
+
shorthand: false,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (disabled) {
|
|
88
|
+
buttonStyles.push(literalObject(BUTTON_DISABLED_STYLE));
|
|
89
|
+
textStyles.push(literalObject(TEXT_DISABLED_STYLE));
|
|
90
|
+
}
|
|
91
|
+
// The label, coerced as Flow A coerces it: a missing title draws nothing.
|
|
92
|
+
const titleAttribute = attributes.get('title');
|
|
93
|
+
const label = titleAttribute
|
|
94
|
+
? [
|
|
95
|
+
expressionChild(titleText(attrExpr(titleAttribute), scope)),
|
|
96
|
+
]
|
|
97
|
+
: [];
|
|
98
|
+
const text = elementOf('Text', [attributeOf('style', { type: 'ArrayExpression', elements: textStyles })], label, element);
|
|
99
|
+
const pressableAttributes = [
|
|
100
|
+
attributeOf('style', { type: 'ArrayExpression', elements: buttonStyles }),
|
|
101
|
+
];
|
|
102
|
+
const onPress = attributes.get('onPress');
|
|
103
|
+
if (onPress && !disabled) {
|
|
104
|
+
pressableAttributes.push(onPress);
|
|
105
|
+
}
|
|
106
|
+
return emitNode(elementOf('Pressable', pressableAttributes, [text], element), scope, output, environment, state, options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A title as Button.mts draws it, `title == null ? '' : String(title)`: worked out now when it folds, else
|
|
110
|
+
* `String(title)`, so a boolean draws as "true" or "false" rather than nothing. No value worked out at run time
|
|
111
|
+
* is null, so only a ternary's branches can be, and each is worked out on its own.
|
|
112
|
+
*
|
|
113
|
+
* @param title The title.
|
|
114
|
+
* @param scope Compile-time constants in reach.
|
|
115
|
+
*
|
|
116
|
+
* @returns The label's text.
|
|
117
|
+
*/
|
|
118
|
+
function titleText(title, scope) {
|
|
119
|
+
const folded = foldedTitle(title, scope);
|
|
120
|
+
if (folded)
|
|
121
|
+
return folded;
|
|
122
|
+
if (title.type === 'ConditionalExpression')
|
|
123
|
+
return titleBranches(title, scope);
|
|
124
|
+
return {
|
|
125
|
+
type: 'CallExpression',
|
|
126
|
+
callee: { type: 'Identifier', name: 'String' },
|
|
127
|
+
arguments: [title],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A ternary title with each branch that folds as its text, `null` and `undefined` as nothing. A branch worked
|
|
132
|
+
* out at run time stays as written, since text lowers no call inside a ternary.
|
|
133
|
+
*
|
|
134
|
+
* @param title The ternary.
|
|
135
|
+
* @param scope Compile-time constants in reach.
|
|
136
|
+
*
|
|
137
|
+
* @returns The ternary of texts.
|
|
138
|
+
*/
|
|
139
|
+
function titleBranches(title, scope) {
|
|
140
|
+
const branch = (expression) => foldedTitle(expression, scope) ??
|
|
141
|
+
(expression.type === 'ConditionalExpression'
|
|
142
|
+
? titleBranches(expression, scope)
|
|
143
|
+
: expression);
|
|
144
|
+
return {
|
|
145
|
+
...title,
|
|
146
|
+
consequent: branch(title.consequent),
|
|
147
|
+
alternate: branch(title.alternate),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A title that folds, as its text.
|
|
152
|
+
*
|
|
153
|
+
* @param title The title.
|
|
154
|
+
* @param scope Compile-time constants in reach.
|
|
155
|
+
*
|
|
156
|
+
* @returns The text, or null when it is worked out at run time.
|
|
157
|
+
*/
|
|
158
|
+
function foldedTitle(title, scope) {
|
|
159
|
+
try {
|
|
160
|
+
const value = evalStatic(title, withUndefined(scope));
|
|
161
|
+
return { type: 'StringLiteral', value: value == null ? '' : String(value) };
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Whether an attribute folds to a falsy value. One that does not fold is a value worked out at run time.
|
|
169
|
+
*
|
|
170
|
+
* @param attribute The attribute.
|
|
171
|
+
* @param scope Compile-time constants in reach.
|
|
172
|
+
*
|
|
173
|
+
* @returns Whether it folds falsy.
|
|
174
|
+
*/
|
|
175
|
+
function foldsFalsy(attribute, scope) {
|
|
176
|
+
try {
|
|
177
|
+
return !evalStatic(attrExpr(attribute), scope);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
|
+
- Imports
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
import { attrExpr } from '../style-text.mjs';
|
|
20
|
+
import { emitNode } from '../nodes.mjs';
|
|
21
|
+
import { attributeOf, elementOf, literalObject, refuseSpreads, renamed, } from './rewrite.mjs';
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Constants
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
/** StyleSheet.absoluteFill: the image fills the container's padding box. */
|
|
26
|
+
const ABSOLUTE_FILL = {
|
|
27
|
+
position: 'absolute',
|
|
28
|
+
left: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
top: 0,
|
|
31
|
+
bottom: 0,
|
|
32
|
+
};
|
|
33
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
34
|
+
- Implementation
|
|
35
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
36
|
+
/**
|
|
37
|
+
* <ImageBackground style imageStyle imageRef …imageProps>children</ImageBackground> → the tree
|
|
38
|
+
* ImageBackground.mts renders: a <View> holding an <Image> that fills it, then the children. `style` and `ref`
|
|
39
|
+
* go to the View, every other prop to the Image.
|
|
40
|
+
*
|
|
41
|
+
* @param element The <ImageBackground>, its props already checked.
|
|
42
|
+
* @param scope Compile-time constants in reach.
|
|
43
|
+
* @param output Everything emitted so far.
|
|
44
|
+
* @param environment The expression environment.
|
|
45
|
+
* @param state The component's state table.
|
|
46
|
+
* @param options How the element is placed.
|
|
47
|
+
*
|
|
48
|
+
* @returns What the <View> lowers to.
|
|
49
|
+
*/
|
|
50
|
+
export function emitImageBackground(element, scope, output, environment, state, options) {
|
|
51
|
+
refuseSpreads(element, 'ImageBackground');
|
|
52
|
+
const viewAttributes = [];
|
|
53
|
+
const imageAttributes = [];
|
|
54
|
+
const imageStyles = [literalObject(ABSOLUTE_FILL)];
|
|
55
|
+
for (const attribute of element.openingElement
|
|
56
|
+
.attributes) {
|
|
57
|
+
const name = attribute.name.name;
|
|
58
|
+
if (name === 'key')
|
|
59
|
+
continue;
|
|
60
|
+
if (name === 'style' || name === 'ref') {
|
|
61
|
+
viewAttributes.push(attribute);
|
|
62
|
+
}
|
|
63
|
+
else if (name === 'imageStyle') {
|
|
64
|
+
imageStyles.push(attrExpr(attribute));
|
|
65
|
+
}
|
|
66
|
+
else if (name === 'imageRef') {
|
|
67
|
+
imageAttributes.push(renamed(attribute, 'ref'));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
imageAttributes.push(attribute);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
imageAttributes.push(attributeOf('style', { type: 'ArrayExpression', elements: imageStyles }));
|
|
74
|
+
const image = elementOf('Image', imageAttributes, [], element);
|
|
75
|
+
return emitNode(elementOf('View', viewAttributes, [image, ...element.children], element), scope, output, environment, state, options);
|
|
76
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
import { shapeOf } from '../typing.mjs';
|
|
19
20
|
import { aotError } from '../diagnostics.mjs';
|
|
20
21
|
import { at } from './props.mjs';
|
|
21
22
|
import { evalStatic, evalStaticOr } from '../static-eval.mjs';
|
|
@@ -110,7 +111,7 @@ export function resolveImageAttrs(element, environment, output) {
|
|
|
110
111
|
// Only triggered when a dynamic source is actually REACHED.
|
|
111
112
|
output.bakeAllImages = true;
|
|
112
113
|
const nameExpression = lowerExpr(sourceExpression, environment);
|
|
113
|
-
if (nameExpression
|
|
114
|
+
if (shapeOf(nameExpression) !== 'string') {
|
|
114
115
|
const error = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
|
|
115
116
|
"a string asset name, source={{ uri: 'name' }}, or a string-valued " +
|
|
116
117
|
'state / list-item field for a dynamic source.');
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import { RN_PLATFORM_NO_OPS } from '../../../src/embedded-react/warn-props.
|
|
19
|
+
import { RN_PLATFORM_NO_OPS } from '../../../src/embedded-react/warn-props.mjs';
|
|
20
20
|
import { isStyleKey } from '../../style-map.mjs';
|
|
21
21
|
import { aotError } from '../diagnostics.mjs';
|
|
22
22
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
@@ -32,6 +32,7 @@ export const EVENT_TYPES = {
|
|
|
32
32
|
onTouchMove: 'ER_EVENT_TOUCH_MOVE',
|
|
33
33
|
onTouchEnd: 'ER_EVENT_TOUCH_END',
|
|
34
34
|
onLayout: 'ER_EVENT_LAYOUT',
|
|
35
|
+
onScroll: 'ER_EVENT_SCROLL',
|
|
35
36
|
};
|
|
36
37
|
/** Style keys every node lays out by, and `transform`, which every node draws through. */
|
|
37
38
|
const LAYOUT_STYLE = [
|
|
@@ -63,6 +64,7 @@ const LAYOUT_STYLE = [
|
|
|
63
64
|
'flexGrow',
|
|
64
65
|
'flexShrink',
|
|
65
66
|
'flexDirection',
|
|
67
|
+
'flexWrap',
|
|
66
68
|
'alignItems',
|
|
67
69
|
'alignSelf',
|
|
68
70
|
'justifyContent',
|
|
@@ -75,9 +77,19 @@ const LAYOUT_STYLE = [
|
|
|
75
77
|
'zIndex',
|
|
76
78
|
'transform',
|
|
77
79
|
];
|
|
80
|
+
/** The shadow a View, ScrollView, Pressable or Modal casts. */
|
|
81
|
+
const SHADOW_STYLE = [
|
|
82
|
+
'shadowColor',
|
|
83
|
+
'shadowOffset',
|
|
84
|
+
'shadowOpacity',
|
|
85
|
+
'shadowRadius',
|
|
86
|
+
'elevation',
|
|
87
|
+
];
|
|
78
88
|
/** What the engine draws a View, ScrollView or Pressable with. */
|
|
79
89
|
const VIEW_STYLE = [
|
|
90
|
+
...SHADOW_STYLE,
|
|
80
91
|
'backgroundColor',
|
|
92
|
+
'backgroundImage',
|
|
81
93
|
'borderRadius',
|
|
82
94
|
'borderTopLeftRadius',
|
|
83
95
|
'borderTopRightRadius',
|
|
@@ -105,16 +117,18 @@ const TEXT_STYLE = [
|
|
|
105
117
|
'letterSpacing',
|
|
106
118
|
'opacity',
|
|
107
119
|
];
|
|
108
|
-
/** What the engine draws a Modal's own
|
|
109
|
-
const
|
|
120
|
+
/** What the engine draws a box with: a TextInput's, and a Modal's own. */
|
|
121
|
+
const BOX_STYLE = [
|
|
110
122
|
'backgroundColor',
|
|
111
123
|
'borderRadius',
|
|
112
124
|
'borderWidth',
|
|
113
125
|
'borderColor',
|
|
114
126
|
'opacity',
|
|
115
127
|
];
|
|
128
|
+
/** What the engine draws a Modal's own box with. */
|
|
129
|
+
const MODAL_STYLE = [...BOX_STYLE, ...SHADOW_STYLE, 'backgroundImage'];
|
|
116
130
|
/** What the engine draws a TextInput with. */
|
|
117
|
-
const TEXT_INPUT_STYLE = [...
|
|
131
|
+
const TEXT_INPUT_STYLE = [...BOX_STYLE, 'color', 'fontSize'];
|
|
118
132
|
/** The style keys the engine animates on a View, ScrollView, Pressable or Modal; `transform` animates anywhere. */
|
|
119
133
|
const VIEW_ANIMATED = ['opacity', 'backgroundColor', 'transform'];
|
|
120
134
|
/** The style keys the engine animates on a Text. */
|
|
@@ -135,13 +149,15 @@ const SVG_PAINT = [
|
|
|
135
149
|
'fillGradient',
|
|
136
150
|
'strokeGradient',
|
|
137
151
|
];
|
|
152
|
+
/** The events every host node takes; only a ScrollView scrolls. */
|
|
153
|
+
const HOST_EVENTS = Object.keys(EVENT_TYPES).filter(name => name !== 'onScroll');
|
|
138
154
|
/** The attributes every host node lowers: style, visibility, a node ref, and its events. */
|
|
139
155
|
const HOST_PROPS = [
|
|
140
156
|
'style',
|
|
141
157
|
'visible',
|
|
142
158
|
'ref',
|
|
143
159
|
'delayLongPress',
|
|
144
|
-
...
|
|
160
|
+
...HOST_EVENTS,
|
|
145
161
|
];
|
|
146
162
|
/** Why the engine's TextInput refuses a React Native prop it has no field for. */
|
|
147
163
|
const NO_TEXT_INPUT_FIELD = "the engine's TextInput has no such setting, so the device would ignore it. Remove it.";
|
|
@@ -150,8 +166,7 @@ const SVG_EVENT = 'wrap it in a <Pressable> (or a <View>) that takes the event:
|
|
|
150
166
|
/** The built-in elements, by tag. `Animated.X` resolves to X. */
|
|
151
167
|
const ELEMENTS = {
|
|
152
168
|
View: element('View', HOST_PROPS, [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {}, VIEW_ANIMATED),
|
|
153
|
-
ScrollView: element('ScrollView', HOST_PROPS, [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {
|
|
154
|
-
onScroll: 'scroll events are not lowered yet. Read the position another way, or keep this screen Flow A only.',
|
|
169
|
+
ScrollView: element('ScrollView', [...HOST_PROPS, 'onScroll'], [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {
|
|
155
170
|
horizontal: "the engine's ScrollView scrolls vertically; lay a horizontal strip out with flexDirection: 'row'.",
|
|
156
171
|
}, VIEW_ANIMATED),
|
|
157
172
|
Pressable: element('Pressable', [...HOST_PROPS, 'disabled'], [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {}, VIEW_ANIMATED),
|
|
@@ -239,9 +254,33 @@ const ELEMENTS = {
|
|
|
239
254
|
// The Flow A wrapper warns about these too, so a list that runs in the simulator also compiles.
|
|
240
255
|
takesPlatformProps: false,
|
|
241
256
|
},
|
|
257
|
+
SectionList: element('SectionList', [
|
|
258
|
+
'sections',
|
|
259
|
+
'renderItem',
|
|
260
|
+
'renderSectionHeader',
|
|
261
|
+
'renderSectionFooter',
|
|
262
|
+
'keyExtractor',
|
|
263
|
+
'style',
|
|
264
|
+
], [...LAYOUT_STYLE, ...VIEW_STYLE], 'none', {
|
|
265
|
+
ref: 'Flow A cannot pass a ref through <SectionList> either; use <ScrollView ref={…}> with .map.',
|
|
266
|
+
}),
|
|
267
|
+
Button: element('Button', ['title', 'onPress', 'color', 'disabled'], [], 'none', {
|
|
268
|
+
style: 'a Button takes no style, as in React Native. Build the same tree yourself to style it: ' +
|
|
269
|
+
'<Pressable style={…} onPress={…}><Text style={…}>title</Text></Pressable>.',
|
|
270
|
+
}),
|
|
271
|
+
// Its style and ref go to the View; every other prop goes to the Image, as in Flow A.
|
|
272
|
+
ImageBackground: element('ImageBackground', [
|
|
273
|
+
...HOST_PROPS,
|
|
274
|
+
'source',
|
|
275
|
+
'imageName',
|
|
276
|
+
'resizeMode',
|
|
277
|
+
'tintColor',
|
|
278
|
+
'imageStyle',
|
|
279
|
+
'imageRef',
|
|
280
|
+
], [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {}, VIEW_ANIMATED),
|
|
242
281
|
Svg: element('Svg', ['style', 'ref', 'width', 'height', 'viewBox', 'source', ...SVG_PAINT], LAYOUT_STYLE, 'shapes', {
|
|
243
282
|
visible: 'wrap it: <View visible={…}><Svg …/></View> — the View carries the hide and the whole subtree goes with it.',
|
|
244
|
-
...Object.fromEntries(
|
|
283
|
+
...Object.fromEntries(HOST_EVENTS.map(name => [name, SVG_EVENT])),
|
|
245
284
|
}),
|
|
246
285
|
};
|
|
247
286
|
/** The shapes inside an <Svg>, by tag; they are drawing data, so they take no ref, style or events. */
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
// Builders for the JSX the wrapper components (Button, ImageBackground, SectionList) are rewritten to.
|
|
17
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
18
|
+
- Imports
|
|
19
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
20
|
+
import { aotError } from '../diagnostics.mjs';
|
|
21
|
+
import { at } from './props.mjs';
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Implementation
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
/**
|
|
26
|
+
* Refuses a spread on a wrapper, whose props are split by name.
|
|
27
|
+
*
|
|
28
|
+
* @param element The wrapper.
|
|
29
|
+
* @param tag Its tag, for the error.
|
|
30
|
+
*/
|
|
31
|
+
export function refuseSpreads(element, tag) {
|
|
32
|
+
const spread = element.openingElement.attributes.find(attribute => attribute.type === 'JSXSpreadAttribute');
|
|
33
|
+
if (spread) {
|
|
34
|
+
throw at(aotError(`AOT: a spread {...} on <${tag}> is not supported`, 'list each prop explicitly.'), spread);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A JSX element, located at the wrapper it stands for so its errors point there.
|
|
39
|
+
*
|
|
40
|
+
* @param tag The tag.
|
|
41
|
+
* @param attributes Its attributes.
|
|
42
|
+
* @param children Its children.
|
|
43
|
+
* @param from The wrapper.
|
|
44
|
+
*
|
|
45
|
+
* @returns The element.
|
|
46
|
+
*/
|
|
47
|
+
export function elementOf(tag, attributes, children, from) {
|
|
48
|
+
const name = { type: 'JSXIdentifier', name: tag };
|
|
49
|
+
return {
|
|
50
|
+
type: 'JSXElement',
|
|
51
|
+
openingElement: {
|
|
52
|
+
type: 'JSXOpeningElement',
|
|
53
|
+
name,
|
|
54
|
+
attributes,
|
|
55
|
+
selfClosing: children.length === 0,
|
|
56
|
+
},
|
|
57
|
+
closingElement: children.length === 0 ? null : { type: 'JSXClosingElement', name },
|
|
58
|
+
children,
|
|
59
|
+
loc: from.loc,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A `name={value}` attribute.
|
|
64
|
+
*
|
|
65
|
+
* @param name The name.
|
|
66
|
+
* @param value The value.
|
|
67
|
+
*
|
|
68
|
+
* @returns The attribute.
|
|
69
|
+
*/
|
|
70
|
+
export function attributeOf(name, value) {
|
|
71
|
+
return {
|
|
72
|
+
type: 'JSXAttribute',
|
|
73
|
+
name: { type: 'JSXIdentifier', name },
|
|
74
|
+
value: { type: 'JSXExpressionContainer', expression: value },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An attribute under another name, keeping its value and location.
|
|
79
|
+
*
|
|
80
|
+
* @param attribute The attribute.
|
|
81
|
+
* @param name The new name.
|
|
82
|
+
*
|
|
83
|
+
* @returns The renamed attribute.
|
|
84
|
+
*/
|
|
85
|
+
export function renamed(attribute, name) {
|
|
86
|
+
return { ...attribute, name: { type: 'JSXIdentifier', name } };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A `{value}` child.
|
|
90
|
+
*
|
|
91
|
+
* @param value The expression.
|
|
92
|
+
*
|
|
93
|
+
* @returns The child.
|
|
94
|
+
*/
|
|
95
|
+
export function expressionChild(value) {
|
|
96
|
+
return { type: 'JSXExpressionContainer', expression: value };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* An object literal of strings and numbers.
|
|
100
|
+
*
|
|
101
|
+
* @param fields The fields.
|
|
102
|
+
*
|
|
103
|
+
* @returns The literal.
|
|
104
|
+
*/
|
|
105
|
+
export function literalObject(fields) {
|
|
106
|
+
return {
|
|
107
|
+
type: 'ObjectExpression',
|
|
108
|
+
properties: Object.entries(fields).map(([key, value]) => ({
|
|
109
|
+
type: 'ObjectProperty',
|
|
110
|
+
key: { type: 'Identifier', name: key },
|
|
111
|
+
value: typeof value === 'number'
|
|
112
|
+
? { type: 'NumericLiteral', value }
|
|
113
|
+
: { type: 'StringLiteral', value },
|
|
114
|
+
computed: false,
|
|
115
|
+
shorthand: false,
|
|
116
|
+
})),
|
|
117
|
+
};
|
|
118
|
+
}
|