embedded-react 0.15.0 → 0.17.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/aot/compile.mjs +173 -8272
- package/aot/compiler/animations.mjs +1001 -0
- package/aot/compiler/assemble.mjs +922 -0
- package/aot/compiler/boot.mjs +441 -0
- package/aot/compiler/branch-merge.mjs +319 -0
- package/aot/compiler/c/animations.mjs +362 -0
- package/aot/compiler/c/boot.mjs +127 -0
- package/aot/compiler/c/expressions.mjs +270 -0
- package/aot/compiler/c/functions.mjs +268 -0
- package/aot/compiler/c/keyboard.mjs +96 -0
- package/aot/compiler/c/nodes.mjs +294 -0
- package/aot/compiler/c/pan-responder.mjs +136 -0
- package/aot/compiler/c/statements.mjs +271 -0
- package/aot/compiler/c/text.mjs +83 -0
- package/aot/compiler/c/vectors.mjs +381 -0
- package/aot/compiler/c-syntax.mjs +127 -0
- package/aot/compiler/check.mjs +165 -0
- package/aot/compiler/collect.mjs +785 -0
- package/aot/compiler/control-flow.mjs +696 -0
- package/aot/compiler/diagnostics.mjs +137 -0
- package/aot/compiler/elements/activity-indicator.mjs +160 -0
- package/aot/compiler/elements/dial.mjs +346 -0
- package/aot/compiler/elements/flat-list.mjs +139 -0
- package/aot/compiler/elements/image.mjs +151 -0
- package/aot/compiler/elements/modal.mjs +158 -0
- package/aot/compiler/elements/props.mjs +474 -0
- package/aot/compiler/elements/switch.mjs +183 -0
- package/aot/compiler/elements/text-input.mjs +171 -0
- package/aot/compiler/expressions.mjs +1579 -0
- package/aot/compiler/handlers.mjs +1072 -0
- package/aot/compiler/ir/animations.mjs +16 -0
- package/aot/compiler/ir/app.mjs +16 -0
- package/aot/compiler/ir/boot.mjs +16 -0
- package/aot/compiler/ir/expressions.mjs +16 -0
- package/aot/compiler/ir/functions.mjs +16 -0
- package/aot/compiler/ir/keyboard.mjs +16 -0
- package/aot/compiler/ir/nodes.mjs +107 -0
- package/aot/compiler/ir/pan-responder.mjs +16 -0
- package/aot/compiler/ir/reads.mjs +351 -0
- package/aot/compiler/ir/source.mjs +16 -0
- package/aot/compiler/ir/statements.mjs +16 -0
- package/aot/compiler/ir/text.mjs +16 -0
- package/aot/compiler/ir/types.mjs +185 -0
- package/aot/compiler/ir/vectors.mjs +16 -0
- package/aot/compiler/keyboard.mjs +152 -0
- package/aot/compiler/lower.mjs +311 -0
- package/aot/compiler/nodes.mjs +688 -0
- package/aot/compiler/options.mjs +55 -0
- package/aot/compiler/out.mjs +94 -0
- package/aot/compiler/pan-responder.mjs +354 -0
- package/aot/compiler/parse.mjs +300 -0
- package/aot/compiler/static-eval.mjs +454 -0
- package/aot/compiler/style-text.mjs +807 -0
- package/aot/compiler/svg.mjs +1167 -0
- package/aot/compiler/types.mjs +16 -0
- package/aot/screenshot-smoke.mjs +95 -55
- package/aot/style-map.mjs +366 -304
- package/cli.mjs +5 -8
- package/package.json +14 -6
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/FlatList.js +4 -4
- package/src/props.js +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
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 { aotError } from '../diagnostics.mjs';
|
|
20
|
+
import { isFn } from '../collect.mjs';
|
|
21
|
+
import { attrExpr } from '../style-text.mjs';
|
|
22
|
+
import { emitNode } from '../nodes.mjs';
|
|
23
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
24
|
+
- Implementation
|
|
25
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
26
|
+
/**
|
|
27
|
+
* <FlatList data={items} renderItem={({ item, index }) => <Row …/>} keyExtractor=… style=… /> → the SAME as
|
|
28
|
+
* <ScrollView style=…>{items.map((item, index) => <Row …/>)}</ScrollView>. The engine's FlatList IS a
|
|
29
|
+
* ScrollView (no virtualization), and the AOT already unrolls a .map (static or state-list), so this is a thin
|
|
30
|
+
* API-compat rewrite: synthesize that ScrollView+map AST and emit it. keyExtractor is ignored (no reconciler).
|
|
31
|
+
*
|
|
32
|
+
* @param element The <FlatList>.
|
|
33
|
+
* @param scope Compile-time constants in reach.
|
|
34
|
+
* @param out Everything emitted so far.
|
|
35
|
+
* @param env The expression environment.
|
|
36
|
+
* @param state The component's state table.
|
|
37
|
+
* @param opts How the element is placed.
|
|
38
|
+
*
|
|
39
|
+
* @returns The variable of the <ScrollView> node it lowers to.
|
|
40
|
+
*/
|
|
41
|
+
export function emitFlatList(element, scope, out, env, state, opts) {
|
|
42
|
+
// Collect the supported <FlatList> props, rejecting anything the AOT rewrite cannot statically lower.
|
|
43
|
+
let dataNode = null;
|
|
44
|
+
let renderItem = null;
|
|
45
|
+
let styleAttr = null;
|
|
46
|
+
for (const attr of element.openingElement.attributes) {
|
|
47
|
+
// Ensure all props are explicit named attributes.
|
|
48
|
+
// Spread props cannot be analyzed statically
|
|
49
|
+
if (attr.type !== 'JSXAttribute') {
|
|
50
|
+
throw aotError('AOT: spread props on <FlatList> are not supported');
|
|
51
|
+
}
|
|
52
|
+
// skip non-props
|
|
53
|
+
const name = attr.name.name;
|
|
54
|
+
if (name === 'keyExtractor' || name === 'key')
|
|
55
|
+
continue;
|
|
56
|
+
// process props
|
|
57
|
+
if (name === 'data') {
|
|
58
|
+
dataNode = attrExpr(attr);
|
|
59
|
+
}
|
|
60
|
+
else if (name === 'renderItem') {
|
|
61
|
+
renderItem = attrExpr(attr);
|
|
62
|
+
}
|
|
63
|
+
else if (name === 'style') {
|
|
64
|
+
styleAttr = attr;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw aotError(`AOT: <FlatList> prop "${name}" is not supported`, 'supported: data, renderItem, keyExtractor, style. For headers/footers/horizontal/onEndReached etc., use <ScrollView> + .map directly.');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Require the FlatList inputs needed for the rewrite: a data source and a renderItem callback that destructures its row info.
|
|
71
|
+
if (!dataNode) {
|
|
72
|
+
throw aotError('AOT: <FlatList> needs a data prop', '<FlatList data={items} renderItem={({ item }) => <Row item={item} />} />');
|
|
73
|
+
}
|
|
74
|
+
if (!renderItem || !isFn(renderItem)) {
|
|
75
|
+
throw aotError('AOT: <FlatList> needs a renderItem function', 'renderItem={({ item, index }) => <Row item={item} />}');
|
|
76
|
+
}
|
|
77
|
+
const param = renderItem.params[0];
|
|
78
|
+
if (!param || param.type !== 'ObjectPattern') {
|
|
79
|
+
throw aotError('AOT: FlatList renderItem must destructure ({ item, index })', 'renderItem={({ item }) => <Row item={item} />}');
|
|
80
|
+
}
|
|
81
|
+
// Extract the local item/index names from renderItem's destructured parameter, rejecting any unsupported row fields or patterns.
|
|
82
|
+
let itemName = null;
|
|
83
|
+
let indexName = null;
|
|
84
|
+
for (const prop of param.properties) {
|
|
85
|
+
if (prop.type !== 'ObjectProperty' || prop.value.type !== 'Identifier') {
|
|
86
|
+
throw aotError('AOT: FlatList renderItem may destructure only item / index (to plain names)');
|
|
87
|
+
}
|
|
88
|
+
if (prop.key.name === 'item') {
|
|
89
|
+
itemName = prop.value.name;
|
|
90
|
+
}
|
|
91
|
+
else if (prop.key.name === 'index') {
|
|
92
|
+
indexName = prop.value.name;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw aotError(`AOT: FlatList renderItem cannot destructure "${prop.key.name}" (only item / index)`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Ensure renderItem binds the required item value; index is optional for the generated map callback.
|
|
99
|
+
if (!itemName) {
|
|
100
|
+
throw aotError('AOT: FlatList renderItem must destructure item', 'renderItem={({ item }) => …}');
|
|
101
|
+
}
|
|
102
|
+
// Rewrite renderItem `({ item, index }) => BODY` → a positional `.map` callback `(item, index) => BODY`.
|
|
103
|
+
const cbParams = [{ type: 'Identifier', name: itemName }];
|
|
104
|
+
if (indexName) {
|
|
105
|
+
cbParams.push({ type: 'Identifier', name: indexName });
|
|
106
|
+
}
|
|
107
|
+
const cb = {
|
|
108
|
+
type: 'ArrowFunctionExpression',
|
|
109
|
+
params: cbParams,
|
|
110
|
+
body: renderItem.body,
|
|
111
|
+
async: false,
|
|
112
|
+
expression: renderItem.body.type !== 'BlockStatement',
|
|
113
|
+
};
|
|
114
|
+
const mapCall = {
|
|
115
|
+
type: 'CallExpression',
|
|
116
|
+
callee: {
|
|
117
|
+
type: 'MemberExpression',
|
|
118
|
+
object: dataNode,
|
|
119
|
+
property: { type: 'Identifier', name: 'map' },
|
|
120
|
+
computed: false,
|
|
121
|
+
},
|
|
122
|
+
arguments: [cb],
|
|
123
|
+
};
|
|
124
|
+
const scrollView = {
|
|
125
|
+
type: 'JSXElement',
|
|
126
|
+
openingElement: {
|
|
127
|
+
type: 'JSXOpeningElement',
|
|
128
|
+
name: { type: 'JSXIdentifier', name: 'ScrollView' },
|
|
129
|
+
attributes: styleAttr ? [styleAttr] : [],
|
|
130
|
+
selfClosing: false,
|
|
131
|
+
},
|
|
132
|
+
closingElement: {
|
|
133
|
+
type: 'JSXClosingElement',
|
|
134
|
+
name: { type: 'JSXIdentifier', name: 'ScrollView' },
|
|
135
|
+
},
|
|
136
|
+
children: [{ type: 'JSXExpressionContainer', expression: mapCall }],
|
|
137
|
+
};
|
|
138
|
+
return emitNode(scrollView, scope, out, env, state, opts);
|
|
139
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
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 { aotError } from '../diagnostics.mjs';
|
|
20
|
+
import { at } from './props.mjs';
|
|
21
|
+
import { evalStatic, evalStaticOr } from '../static-eval.mjs';
|
|
22
|
+
import { lowerExpr } from '../expressions.mjs';
|
|
23
|
+
import { attrExpr, argbLiteral } from '../style-text.mjs';
|
|
24
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
25
|
+
- Constants
|
|
26
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
27
|
+
const RESIZE_MODES = {
|
|
28
|
+
cover: 'ER_RESIZE_COVER',
|
|
29
|
+
contain: 'ER_RESIZE_CONTAIN',
|
|
30
|
+
stretch: 'ER_RESIZE_STRETCH',
|
|
31
|
+
repeat: 'ER_RESIZE_REPEAT',
|
|
32
|
+
center: 'ER_RESIZE_CENTER',
|
|
33
|
+
};
|
|
34
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
35
|
+
- Implementation
|
|
36
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
37
|
+
/**
|
|
38
|
+
* Resolves an <Image source>/imageName expression to its baked asset NAME (a string) if it folds at compile
|
|
39
|
+
* time, else null (a runtime/dynamic source — the caller emits a dynamic image_name). Image imports live in
|
|
40
|
+
* the const scope as their asset-name string, so this folds `wxSun`, `item.icon` (unrolled map), and static
|
|
41
|
+
* ternaries; `{ uri }` is the explicit remote-shape escape.
|
|
42
|
+
*
|
|
43
|
+
* @param expr The source expression, if there is one.
|
|
44
|
+
* @param env The expression environment.
|
|
45
|
+
*
|
|
46
|
+
* @returns The asset's name, or null when the source does not fold.
|
|
47
|
+
*/
|
|
48
|
+
export function imageNameFromSource(expr, env) {
|
|
49
|
+
// No source expression was provided.
|
|
50
|
+
if (!expr)
|
|
51
|
+
return null;
|
|
52
|
+
// Try to resolve the source as a compile-time constant.
|
|
53
|
+
try {
|
|
54
|
+
const value = evalStatic(expr, env.consts ?? {});
|
|
55
|
+
if (typeof value === 'string')
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
/* not a compile-time constant — fall through to {uri}, else dynamic */
|
|
60
|
+
}
|
|
61
|
+
// Handle React Native-style object sources: source={{ uri: 'asset_name' }}.
|
|
62
|
+
if (expr.type === 'ObjectExpression') {
|
|
63
|
+
const uri = expr.properties.find((property) => property.type === 'ObjectProperty' &&
|
|
64
|
+
(property.key.name === 'uri' ||
|
|
65
|
+
property.key.value === 'uri'));
|
|
66
|
+
if (uri?.value?.type === 'StringLiteral')
|
|
67
|
+
return uri.value.value;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolves an <Image>'s source/imageName/resizeMode/tintColor for the node props (static name, a dynamic
|
|
73
|
+
* name expr, resize mode, tint). Records baking intent in `out`: a static name that matches an import is
|
|
74
|
+
* marked used (out.images); a dynamic source flips out.bakeAllImages (its asset can't be enumerated). So
|
|
75
|
+
* only REACHED images are baked — an import used solely in a folded-away branch costs no flash.
|
|
76
|
+
*
|
|
77
|
+
* @param element The <Image>.
|
|
78
|
+
* @param env The expression environment.
|
|
79
|
+
* @param out Everything emitted so far.
|
|
80
|
+
*
|
|
81
|
+
* @returns The resolved props.
|
|
82
|
+
*/
|
|
83
|
+
export function resolveImageAttrs(element, env, out) {
|
|
84
|
+
// Find the image source prop, preferring imageName over source.
|
|
85
|
+
const attrs = element.openingElement.attributes;
|
|
86
|
+
const find = (attrName) => attrs.find((attr) => attr.type === 'JSXAttribute' && attr.name.name === attrName);
|
|
87
|
+
const imAttr = find('imageName');
|
|
88
|
+
const srcAttr = find('source');
|
|
89
|
+
const srcExpr = imAttr
|
|
90
|
+
? attrExpr(imAttr)
|
|
91
|
+
: srcAttr
|
|
92
|
+
? attrExpr(srcAttr)
|
|
93
|
+
: null;
|
|
94
|
+
let imageName = null; // static asset name (a literal), OR …
|
|
95
|
+
let imageNameDyn = null; // … a runtime string (a list-item field / state) set in app_update.
|
|
96
|
+
// Resolve static sources immediately and mark imported assets for baking.
|
|
97
|
+
if (srcExpr) {
|
|
98
|
+
imageName = imageNameFromSource(srcExpr, env);
|
|
99
|
+
if (imageName != null) {
|
|
100
|
+
const path = env.imageNames?.get(imageName); // a baked import (vs. a bare {uri} name the app supplies)
|
|
101
|
+
if (path) {
|
|
102
|
+
out.images.set(imageName, path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Fall back to a dynamic runtime image name when the source cannot be folded.
|
|
107
|
+
// Emits it as a runtime string. The engine resolves it against the image registry by name each frame,
|
|
108
|
+
// so the candidate assets must be baked. They can't be enumerated, so bake them ALL (out.bakeAllImages).
|
|
109
|
+
// Only triggered when a dynamic source is actually REACHED.
|
|
110
|
+
out.bakeAllImages = true;
|
|
111
|
+
const nameExpr = lowerExpr(srcExpr, env);
|
|
112
|
+
if (nameExpr.type.kind !== 'string') {
|
|
113
|
+
const err = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
|
|
114
|
+
"a string asset name, source={{ uri: 'name' }}, or a string-valued " +
|
|
115
|
+
'state / list-item field for a dynamic source.');
|
|
116
|
+
if (srcExpr.loc) {
|
|
117
|
+
err.aotLoc = srcExpr.loc.start;
|
|
118
|
+
}
|
|
119
|
+
{
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
imageNameDyn = nameExpr;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Resolve the optional resize mode and validate it against the supported engine modes.
|
|
127
|
+
let resizeMode = null;
|
|
128
|
+
const rmAttr = find('resizeMode');
|
|
129
|
+
if (rmAttr) {
|
|
130
|
+
const rm = evalStaticOr(attrExpr(rmAttr), env, null);
|
|
131
|
+
resizeMode = RESIZE_MODES[rm];
|
|
132
|
+
if (!resizeMode) {
|
|
133
|
+
const e = aotError(`AOT: unsupported <Image resizeMode> "${rm}"`, `resizeMode must be one of: ${Object.keys(RESIZE_MODES).join(' / ')}.`);
|
|
134
|
+
if (rmAttr.loc) {
|
|
135
|
+
e.aotLoc = rmAttr.loc.start;
|
|
136
|
+
}
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Resolve the optional tint color into the ARGB literal expected by the engine.
|
|
141
|
+
let tintColor = null;
|
|
142
|
+
const tcAttr = find('tintColor');
|
|
143
|
+
if (tcAttr) {
|
|
144
|
+
const tc = evalStaticOr(attrExpr(tcAttr), env, null);
|
|
145
|
+
if (typeof tc !== 'string' && typeof tc !== 'number') {
|
|
146
|
+
throw at(aotError('AOT: <Image tintColor> must be a constant color', 'the tint is baked into the node when it is built; a state-driven one is not lowered yet.'), tcAttr);
|
|
147
|
+
}
|
|
148
|
+
tintColor = argbLiteral(tc);
|
|
149
|
+
}
|
|
150
|
+
return { imageName, imageNameDyn, resizeMode, tintColor };
|
|
151
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 { colorLiteral } from '../../style-map.mjs';
|
|
20
|
+
import { aotError } from '../diagnostics.mjs';
|
|
21
|
+
import { evalStatic } from '../static-eval.mjs';
|
|
22
|
+
import { lowerExpr } from '../expressions.mjs';
|
|
23
|
+
import { attrExpr, styleWrites, collectStyleAssigns } from '../style-text.mjs';
|
|
24
|
+
import { emitChildren } from '../control-flow.mjs';
|
|
25
|
+
import { checkInterpolations, lowerRefBinds } from '../nodes.mjs';
|
|
26
|
+
import { at, elementSpec } from './props.mjs';
|
|
27
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
28
|
+
- Constants
|
|
29
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
30
|
+
// Overlay defaults: absolute, fill the parent via four 0 insets (the robust "stretch" for an absolute
|
|
31
|
+
// node), center the content. The user's style overrides any of these.
|
|
32
|
+
const DEFAULTS = [
|
|
33
|
+
['position', 'ER_POS_ABSOLUTE'],
|
|
34
|
+
['left', '0'],
|
|
35
|
+
['top', '0'],
|
|
36
|
+
['right', '0'],
|
|
37
|
+
['bottom', '0'],
|
|
38
|
+
['align_items', 'ER_ALIGN_CENTER'],
|
|
39
|
+
['justify_content', 'ER_JUSTIFY_CENTER'],
|
|
40
|
+
];
|
|
41
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
42
|
+
- Implementation
|
|
43
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
44
|
+
/**
|
|
45
|
+
* <Modal visible={show} backdropColor=… style=…>{content}</Modal> → ER_NODE_MODAL. The engine draws a
|
|
46
|
+
* full-screen backdrop then the modal and its children when visible, and toggles the node's layout display
|
|
47
|
+
* from `visible`. Defaults to an absolute full-screen overlay centring its content (style can override).
|
|
48
|
+
* onRequestClose and statusBarTranslucent lower to nothing (no back button, no status bar), and animationType
|
|
49
|
+
* may only be 'none'.
|
|
50
|
+
*
|
|
51
|
+
* @param element The <Modal>.
|
|
52
|
+
* @param scope Compile-time constants in reach.
|
|
53
|
+
* @param out Everything emitted so far.
|
|
54
|
+
* @param env The expression environment.
|
|
55
|
+
* @param state The component's state table.
|
|
56
|
+
*
|
|
57
|
+
* @returns The node's variable.
|
|
58
|
+
*/
|
|
59
|
+
export function emitModal(element, scope, out, env, state) {
|
|
60
|
+
// get node id
|
|
61
|
+
const nodeId = `n${out.allocateNodeId()}`;
|
|
62
|
+
// collect style assignments
|
|
63
|
+
const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, elementSpec('Modal'));
|
|
64
|
+
const hasField = (f) => styleWrites(staticAssigns, dynAssigns, f);
|
|
65
|
+
// Apply modal overlay defaults only for fields the user's style has not already set.
|
|
66
|
+
for (const [field, expr] of DEFAULTS) {
|
|
67
|
+
if (!hasField(field)) {
|
|
68
|
+
staticAssigns.push({ field: field, expr });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// process element attributes
|
|
72
|
+
let visibleNode = null;
|
|
73
|
+
for (const attr of element.openingElement.attributes) {
|
|
74
|
+
// Ensure all props are explicit named attributes.
|
|
75
|
+
// Spread props cannot be analyzed statically
|
|
76
|
+
if (attr.type !== 'JSXAttribute') {
|
|
77
|
+
throw aotError('AOT: spread props on <Modal> are not supported');
|
|
78
|
+
}
|
|
79
|
+
// skip non-props
|
|
80
|
+
const name = attr.name.name;
|
|
81
|
+
if (name === 'style' || name === 'ref' || name === 'key')
|
|
82
|
+
continue;
|
|
83
|
+
// process props
|
|
84
|
+
const node = attrExpr(attr);
|
|
85
|
+
if (name === 'visible') {
|
|
86
|
+
visibleNode = node;
|
|
87
|
+
}
|
|
88
|
+
else if (name === 'backdropColor') {
|
|
89
|
+
staticAssigns.push({
|
|
90
|
+
field: 'backdrop_color',
|
|
91
|
+
expr: colorLiteral(String(evalStatic(node, scope))),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else if (name === 'animationType') {
|
|
95
|
+
// The engine shows and hides a Modal at once, which is RN's 'none'.
|
|
96
|
+
let animationType;
|
|
97
|
+
try {
|
|
98
|
+
animationType = evalStatic(node, scope);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
/* state-driven: refused below */
|
|
102
|
+
}
|
|
103
|
+
if (animationType !== 'none') {
|
|
104
|
+
throw at(aotError(`AOT: <Modal animationType> ${typeof animationType === 'string' ? `"${animationType}"` : 'from state'} is not supported`, 'the engine shows and hides a Modal at once; use animationType="none", or drop the prop.'), attr);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (name === 'onRequestClose' || name === 'statusBarTranslucent') {
|
|
108
|
+
// Nothing on a panel asks a Modal to close, and there is no status bar: both lower to nothing at all.
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
throw aotError(`AOT: <Modal> prop "${name}" is not supported`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Require `visible` and lower it to the engine's modal_visible flag, folding constants when possible.
|
|
115
|
+
if (!visibleNode) {
|
|
116
|
+
throw aotError('AOT: a <Modal> needs a visible prop', '<Modal visible={show}>…</Modal>');
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
staticAssigns.push({
|
|
120
|
+
field: 'modal_visible',
|
|
121
|
+
expr: evalStatic(visibleNode, scope) ? '1' : '0',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
dynAssigns.push({
|
|
126
|
+
field: 'modal_visible',
|
|
127
|
+
value: {
|
|
128
|
+
kind: 'flag',
|
|
129
|
+
test: lowerExpr(visibleNode, env),
|
|
130
|
+
truthiness: 'value',
|
|
131
|
+
negate: false,
|
|
132
|
+
whenTrue: 1,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const node = {
|
|
137
|
+
id: nodeId,
|
|
138
|
+
type: 'ER_NODE_MODAL',
|
|
139
|
+
constantProps: staticAssigns,
|
|
140
|
+
stateProps: dynAssigns,
|
|
141
|
+
placeholder: null,
|
|
142
|
+
text: null,
|
|
143
|
+
image: null,
|
|
144
|
+
spans: null,
|
|
145
|
+
children: [],
|
|
146
|
+
wiring: [
|
|
147
|
+
...binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
148
|
+
...lowerRefBinds(element.openingElement, env).map(slot => ({
|
|
149
|
+
kind: 'ref',
|
|
150
|
+
slot,
|
|
151
|
+
})),
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
checkInterpolations(node);
|
|
155
|
+
// The modal's content, shown and hidden with the modal.
|
|
156
|
+
node.children = emitChildren(element.children, scope, out, env, state);
|
|
157
|
+
return node;
|
|
158
|
+
}
|