embedded-react 0.19.0 → 0.20.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/README.md +7 -3
- package/aot/compile.mjs +178 -58
- package/aot/compiler/animations.mjs +290 -281
- package/aot/compiler/boot.mjs +70 -33
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +9 -9
- package/aot/compiler/collect.mjs +324 -205
- package/aot/compiler/control-flow.mjs +209 -197
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image.mjs +51 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +23 -23
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +372 -333
- package/aot/compiler/handlers.mjs +473 -387
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +4 -4
- package/aot/compiler/ir/reads.mjs +19 -19
- package/aot/compiler/ir/types.mjs +14 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/lower.mjs +77 -80
- package/aot/compiler/nodes.mjs +169 -152
- package/aot/compiler/options.mjs +35 -30
- package/aot/compiler/out.mjs +18 -22
- package/aot/compiler/package/animations.mjs +669 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +177 -0
- package/aot/compiler/package/bytecode.mjs +286 -0
- package/aot/compiler/package/checks.mjs +1022 -0
- package/aot/compiler/package/codegen.mjs +1329 -0
- package/aot/compiler/package/enums.mjs +138 -0
- package/aot/compiler/package/format.mjs +760 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +1606 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/tables.mjs +103 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +664 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +21 -21
- package/aot/compiler/static-eval.mjs +25 -23
- package/aot/compiler/style-text.mjs +161 -172
- package/aot/compiler/svg.mjs +477 -251
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +102 -90
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +14 -12
- package/cli.mjs +359 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +46 -37
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +28 -20
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +101 -82
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +6 -6
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +5 -5
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
|
@@ -16,15 +16,22 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import {
|
|
20
|
-
import { aotError } from '../diagnostics.mjs';
|
|
19
|
+
import { parseColorValue } from '../../style-map.mjs';
|
|
20
|
+
import { aotError, currentLoc } from '../diagnostics.mjs';
|
|
21
21
|
import { evalStatic } from '../static-eval.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { lowerExpr } from '../expressions.mjs';
|
|
23
|
+
import { BOOL } from '../ir/types.mjs';
|
|
23
24
|
import { isFn } from '../collect.mjs';
|
|
24
25
|
import { attrExpr, styleWrites, collectStyleAssigns } from '../style-text.mjs';
|
|
25
26
|
import { lowerValueHandler } from '../handlers.mjs';
|
|
26
27
|
import { checkInterpolations, lowerRefBinds } from '../nodes.mjs';
|
|
27
28
|
import { at, elementSpec } from './props.mjs';
|
|
29
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
30
|
+
- Constants
|
|
31
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
32
|
+
/** A <Switch>'s size when its style sets none, as iOS draws it. */
|
|
33
|
+
const DEFAULT_WIDTH = 51;
|
|
34
|
+
const DEFAULT_HEIGHT = 31;
|
|
28
35
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
36
|
- Implementation
|
|
30
37
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -36,49 +43,49 @@ import { at, elementSpec } from './props.mjs';
|
|
|
36
43
|
*
|
|
37
44
|
* @param element The <Switch>.
|
|
38
45
|
* @param scope Compile-time constants in reach.
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
46
|
+
* @param output Everything emitted so far.
|
|
47
|
+
* @param environment The expression environment.
|
|
41
48
|
* @param state The component's state table.
|
|
42
49
|
*
|
|
43
50
|
* @returns The node's variable.
|
|
44
51
|
*/
|
|
45
|
-
export function emitSwitch(element, scope,
|
|
52
|
+
export function emitSwitch(element, scope, output, environment, state) {
|
|
46
53
|
// get node id
|
|
47
|
-
const nodeId = `n${
|
|
54
|
+
const nodeId = `n${output.allocateNodeId()}`;
|
|
48
55
|
// collect style assignments
|
|
49
|
-
const { staticAssigns,
|
|
50
|
-
const hasField = (
|
|
56
|
+
const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, elementSpec('Switch'));
|
|
57
|
+
const hasField = (field) => styleWrites(staticAssigns, dynamicAssigns, field);
|
|
51
58
|
if (!hasField('width')) {
|
|
52
|
-
staticAssigns.push({ field: 'width',
|
|
59
|
+
staticAssigns.push({ field: 'width', value: DEFAULT_WIDTH });
|
|
53
60
|
}
|
|
54
61
|
if (!hasField('height')) {
|
|
55
|
-
staticAssigns.push({ field: 'height',
|
|
62
|
+
staticAssigns.push({ field: 'height', value: DEFAULT_HEIGHT });
|
|
56
63
|
}
|
|
57
64
|
// process element attributes
|
|
58
65
|
let valueNode = null;
|
|
59
|
-
let
|
|
60
|
-
for (const
|
|
66
|
+
let onChangeFunction = null;
|
|
67
|
+
for (const attribute of element.openingElement.attributes) {
|
|
61
68
|
// Ensure all props are explicit named attributes.
|
|
62
69
|
// Spread props cannot be analyzed statically
|
|
63
|
-
if (
|
|
70
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
64
71
|
throw aotError('AOT: spread props on <Switch> are not supported');
|
|
65
72
|
}
|
|
66
73
|
// skip non-props
|
|
67
|
-
const name =
|
|
74
|
+
const name = attribute.name.name;
|
|
68
75
|
if (name === 'style' || name === 'ref' || name === 'key')
|
|
69
76
|
continue;
|
|
70
77
|
// process props
|
|
71
|
-
const node = attrExpr(
|
|
78
|
+
const node = attrExpr(attribute);
|
|
72
79
|
if (name === 'value') {
|
|
73
80
|
valueNode = node;
|
|
74
81
|
}
|
|
75
82
|
else if (name === 'onValueChange') {
|
|
76
|
-
|
|
83
|
+
onChangeFunction = node;
|
|
77
84
|
}
|
|
78
85
|
else if (name === 'thumbColor') {
|
|
79
86
|
staticAssigns.push({
|
|
80
87
|
field: 'thumb_color',
|
|
81
|
-
|
|
88
|
+
value: parseColorValue(String(evalStatic(node, scope))),
|
|
82
89
|
});
|
|
83
90
|
}
|
|
84
91
|
else if (name === 'trackColor') {
|
|
@@ -86,18 +93,18 @@ export function emitSwitch(element, scope, out, env, state) {
|
|
|
86
93
|
if (trackColor == null ||
|
|
87
94
|
typeof trackColor !== 'object' ||
|
|
88
95
|
Object.keys(trackColor).some(key => key !== 'false' && key !== 'true')) {
|
|
89
|
-
throw at(aotError('AOT: <Switch trackColor> must be an object of two colors', "trackColor={{false: '#767577', true: '#81b0ff'}}"),
|
|
96
|
+
throw at(aotError('AOT: <Switch trackColor> must be an object of two colors', "trackColor={{false: '#767577', true: '#81b0ff'}}"), attribute);
|
|
90
97
|
}
|
|
91
98
|
if (trackColor.false != null) {
|
|
92
99
|
staticAssigns.push({
|
|
93
100
|
field: 'track_color_false',
|
|
94
|
-
|
|
101
|
+
value: parseColorValue(String(trackColor.false)),
|
|
95
102
|
});
|
|
96
103
|
}
|
|
97
104
|
if (trackColor.true != null) {
|
|
98
105
|
staticAssigns.push({
|
|
99
106
|
field: 'track_color_true',
|
|
100
|
-
|
|
107
|
+
value: parseColorValue(String(trackColor.true)),
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
}
|
|
@@ -112,27 +119,27 @@ export function emitSwitch(element, scope, out, env, state) {
|
|
|
112
119
|
}
|
|
113
120
|
if (disabled !== false) {
|
|
114
121
|
throw at(aotError('AOT: a disabled <Switch> is not supported', 'the engine flips a Switch on every press and has no disabled state. Leave it enabled and ' +
|
|
115
|
-
'ignore the change in onValueChange while it should not move.'),
|
|
122
|
+
'ignore the change in onValueChange while it should not move.'), attribute);
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
else {
|
|
119
126
|
throw aotError(`AOT: <Switch> prop "${name}" is not supported`, 'supported props: value, onValueChange, trackColor, thumbColor, style.');
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
|
-
// value → switch_value (static or, when state-driven, recomputed in
|
|
129
|
+
// value → switch_value (static or, when state-driven, recomputed in the update).
|
|
123
130
|
if (valueNode) {
|
|
124
131
|
try {
|
|
125
132
|
staticAssigns.push({
|
|
126
133
|
field: 'switch_value',
|
|
127
|
-
|
|
134
|
+
value: evalStatic(valueNode, scope) ? 1 : 0,
|
|
128
135
|
});
|
|
129
136
|
}
|
|
130
137
|
catch {
|
|
131
|
-
|
|
138
|
+
dynamicAssigns.push({
|
|
132
139
|
field: 'switch_value',
|
|
133
140
|
value: {
|
|
134
141
|
kind: 'flag',
|
|
135
|
-
test: lowerExpr(valueNode,
|
|
142
|
+
test: lowerExpr(valueNode, environment),
|
|
136
143
|
truthiness: 'condition',
|
|
137
144
|
negate: false,
|
|
138
145
|
whenTrue: 1,
|
|
@@ -142,9 +149,10 @@ export function emitSwitch(element, scope, out, env, state) {
|
|
|
142
149
|
}
|
|
143
150
|
const node = {
|
|
144
151
|
id: nodeId,
|
|
152
|
+
location: currentLoc(),
|
|
145
153
|
type: 'ER_NODE_SWITCH',
|
|
146
154
|
constantProps: staticAssigns,
|
|
147
|
-
stateProps:
|
|
155
|
+
stateProps: dynamicAssigns,
|
|
148
156
|
placeholder: null,
|
|
149
157
|
text: null,
|
|
150
158
|
image: null,
|
|
@@ -153,21 +161,21 @@ export function emitSwitch(element, scope, out, env, state) {
|
|
|
153
161
|
wiring: binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
154
162
|
};
|
|
155
163
|
// Compile onValueChange into a press handler that receives the toggled switch value.
|
|
156
|
-
if (
|
|
164
|
+
if (onChangeFunction) {
|
|
157
165
|
// Require a controlled switch so onValueChange can receive the next value.
|
|
158
|
-
if (!isFn(
|
|
166
|
+
if (!isFn(onChangeFunction)) {
|
|
159
167
|
throw aotError('AOT: onValueChange must be an inline function', 'onValueChange={(v) => setX(v)}');
|
|
160
168
|
}
|
|
161
169
|
if (!valueNode) {
|
|
162
170
|
throw aotError('AOT: a <Switch> with onValueChange needs a value prop', 'controlled switch: <Switch value={on} onValueChange={(v) => setOn(v)} />');
|
|
163
171
|
}
|
|
164
172
|
// Compile onValueChange into an ER_EVENT_PRESS handler, passing the next switch value.
|
|
165
|
-
const handlerName = `
|
|
166
|
-
const
|
|
167
|
-
|
|
173
|
+
const handlerName = `handler_${output.handlers.length}`;
|
|
174
|
+
const value = lowerExpr(valueNode, environment);
|
|
175
|
+
output.handlers.push({
|
|
168
176
|
kind: 'callback',
|
|
169
177
|
name: handlerName,
|
|
170
|
-
callback: lowerValueHandler(
|
|
178
|
+
callback: lowerValueHandler(onChangeFunction, environment, state, output, 'int', true, { kind: 'unary', operator: '!', operand: value, type: BOOL }),
|
|
171
179
|
});
|
|
172
180
|
node.wiring.push({
|
|
173
181
|
kind: 'event',
|
|
@@ -175,7 +183,7 @@ export function emitSwitch(element, scope, out, env, state) {
|
|
|
175
183
|
handler: handlerName,
|
|
176
184
|
});
|
|
177
185
|
}
|
|
178
|
-
for (const slot of lowerRefBinds(element.openingElement,
|
|
186
|
+
for (const slot of lowerRefBinds(element.openingElement, environment)) {
|
|
179
187
|
node.wiring.push({ kind: 'ref', slot });
|
|
180
188
|
}
|
|
181
189
|
checkInterpolations(node);
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import {
|
|
20
|
-
import { aotError, checkEngineString, constantText } from '../diagnostics.mjs';
|
|
19
|
+
import { parseColorValue } from '../../style-map.mjs';
|
|
20
|
+
import { aotError, currentLoc, checkEngineString, constantText, } from '../diagnostics.mjs';
|
|
21
21
|
import { evalStatic } from '../static-eval.mjs';
|
|
22
22
|
import { lowerExpr, lowerText } from '../expressions.mjs';
|
|
23
23
|
import { isFn } from '../collect.mjs';
|
|
@@ -25,6 +25,7 @@ import { attrExpr, collectStyleAssigns } from '../style-text.mjs';
|
|
|
25
25
|
import { lowerValueHandler } from '../handlers.mjs';
|
|
26
26
|
import { checkInterpolations, lowerEventHandler, lowerRefBinds, } from '../nodes.mjs';
|
|
27
27
|
import { elementSpec } from './props.mjs';
|
|
28
|
+
import { STRING } from '../ir/types.mjs';
|
|
28
29
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
30
|
- Constants
|
|
30
31
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -42,44 +43,44 @@ const INPUT_EVENTS = {
|
|
|
42
43
|
* → ER_NODE_TEXT_INPUT. The engine autofocuses on tap (hit_test) and edits its own buffer, firing
|
|
43
44
|
* ER_EVENT_CHANGE_TEXT with the new text — bound to the handler's param via `data->changed_text` (a string).
|
|
44
45
|
* `value` drives the text buffer (er_node_set_props → er_text_input_set_text; state → dynamic, re-synced in
|
|
45
|
-
*
|
|
46
|
+
* the update; set_text is a no-op when unchanged, so a controlled input is safe). Desktop types via the
|
|
46
47
|
* keyboard; the touch-only CYD needs an on-screen keyboard to enter text (deferred follow-on).
|
|
47
48
|
*
|
|
48
49
|
* @param element The <TextInput>.
|
|
49
50
|
* @param scope Compile-time constants in reach.
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
51
|
+
* @param output Everything emitted so far.
|
|
52
|
+
* @param environment The expression environment.
|
|
52
53
|
* @param state The component's state table.
|
|
53
54
|
*
|
|
54
55
|
* @returns The node's variable.
|
|
55
56
|
*/
|
|
56
|
-
export function emitTextInput(element, scope,
|
|
57
|
+
export function emitTextInput(element, scope, output, environment, state) {
|
|
57
58
|
// get node id
|
|
58
|
-
const nodeId = `n${
|
|
59
|
+
const nodeId = `n${output.allocateNodeId()}`;
|
|
59
60
|
// collect style assignments
|
|
60
|
-
const { staticAssigns,
|
|
61
|
+
const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, elementSpec('TextInput'));
|
|
61
62
|
// process element attributes
|
|
62
63
|
let valueNode = null;
|
|
63
|
-
let
|
|
64
|
+
let onChangeFunction = null;
|
|
64
65
|
let placeholder = null;
|
|
65
66
|
const events = [];
|
|
66
|
-
for (const
|
|
67
|
+
for (const attribute of element.openingElement.attributes) {
|
|
67
68
|
// Ensure all props are explicit named attributes.
|
|
68
69
|
// Spread props cannot be analyzed statically
|
|
69
|
-
if (
|
|
70
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
70
71
|
throw aotError('AOT: spread props on <TextInput> are not supported');
|
|
71
72
|
}
|
|
72
73
|
// skip non-props
|
|
73
|
-
const name =
|
|
74
|
+
const name = attribute.name.name;
|
|
74
75
|
if (name === 'style' || name === 'ref' || name === 'key')
|
|
75
76
|
continue;
|
|
76
77
|
// process props
|
|
77
|
-
const node = attrExpr(
|
|
78
|
+
const node = attrExpr(attribute);
|
|
78
79
|
if (name === 'value' || name === 'defaultValue') {
|
|
79
80
|
valueNode = node;
|
|
80
81
|
}
|
|
81
82
|
else if (name === 'onChangeText') {
|
|
82
|
-
|
|
83
|
+
onChangeFunction = node;
|
|
83
84
|
}
|
|
84
85
|
else if (name === 'placeholder') {
|
|
85
86
|
placeholder = String(evalStatic(node, scope));
|
|
@@ -88,13 +89,13 @@ export function emitTextInput(element, scope, out, env, state) {
|
|
|
88
89
|
else if (name === 'placeholderTextColor') {
|
|
89
90
|
staticAssigns.push({
|
|
90
91
|
field: 'placeholder_color',
|
|
91
|
-
|
|
92
|
+
value: parseColorValue(String(evalStatic(node, scope))),
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
else if (name === 'cursorColor') {
|
|
95
96
|
staticAssigns.push({
|
|
96
97
|
field: 'cursor_color',
|
|
97
|
-
|
|
98
|
+
value: parseColorValue(String(evalStatic(node, scope))),
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
101
|
else if (name === 'editable' || name === 'secureTextEntry') {
|
|
@@ -102,15 +103,15 @@ export function emitTextInput(element, scope, out, env, state) {
|
|
|
102
103
|
try {
|
|
103
104
|
staticAssigns.push({
|
|
104
105
|
field,
|
|
105
|
-
|
|
106
|
+
value: evalStatic(node, scope) ? 1 : 0,
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
catch {
|
|
109
|
-
|
|
110
|
+
dynamicAssigns.push({
|
|
110
111
|
field,
|
|
111
112
|
value: {
|
|
112
113
|
kind: 'flag',
|
|
113
|
-
test: lowerExpr(node,
|
|
114
|
+
test: lowerExpr(node, environment),
|
|
114
115
|
truthiness: 'value',
|
|
115
116
|
negate: false,
|
|
116
117
|
whenTrue: 1,
|
|
@@ -119,23 +120,24 @@ export function emitTextInput(element, scope, out, env, state) {
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
else if (Object.hasOwn(INPUT_EVENTS, name)) {
|
|
122
|
-
events.push(
|
|
123
|
+
events.push(attribute);
|
|
123
124
|
}
|
|
124
125
|
else {
|
|
125
126
|
throw aotError(`AOT: <TextInput> prop "${name}" is not supported`);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
const text = valueNode ? lowerText(valueNode,
|
|
129
|
+
const text = valueNode ? lowerText(valueNode, environment, scope) : null;
|
|
129
130
|
if (text) {
|
|
130
131
|
checkEngineString(constantText(text), 'ER_TEXT_MAX', 'a <TextInput> value');
|
|
131
132
|
}
|
|
132
133
|
// value → the input's text buffer (er_node_set_props → er_text_input_set_text): static literal, or a
|
|
133
|
-
// state-driven value re-synced each
|
|
134
|
+
// state-driven value re-synced each update.
|
|
134
135
|
const node = {
|
|
135
136
|
id: nodeId,
|
|
137
|
+
location: currentLoc(),
|
|
136
138
|
type: 'ER_NODE_TEXT_INPUT',
|
|
137
139
|
constantProps: staticAssigns,
|
|
138
|
-
stateProps:
|
|
140
|
+
stateProps: dynamicAssigns,
|
|
139
141
|
placeholder,
|
|
140
142
|
text,
|
|
141
143
|
image: null,
|
|
@@ -144,15 +146,15 @@ export function emitTextInput(element, scope, out, env, state) {
|
|
|
144
146
|
wiring: binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
145
147
|
};
|
|
146
148
|
// Compile onChangeText into an ER_EVENT_CHANGE_TEXT handler that receives the edited text.
|
|
147
|
-
if (
|
|
148
|
-
if (!isFn(
|
|
149
|
+
if (onChangeFunction) {
|
|
150
|
+
if (!isFn(onChangeFunction)) {
|
|
149
151
|
throw aotError('AOT: onChangeText must be an inline function', 'onChangeText={(t) => setText(t)}');
|
|
150
152
|
}
|
|
151
|
-
const handlerName = `
|
|
152
|
-
|
|
153
|
+
const handlerName = `handler_${output.handlers.length}`;
|
|
154
|
+
output.handlers.push({
|
|
153
155
|
kind: 'callback',
|
|
154
156
|
name: handlerName,
|
|
155
|
-
callback: lowerValueHandler(
|
|
157
|
+
callback: lowerValueHandler(onChangeFunction, environment, state, output, 'string', false, { kind: 'event', field: 'changed_text', type: STRING }),
|
|
156
158
|
});
|
|
157
159
|
node.wiring.push({
|
|
158
160
|
kind: 'event',
|
|
@@ -161,14 +163,14 @@ export function emitTextInput(element, scope, out, env, state) {
|
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
// Return, focus and blur take no value: plain handlers, wired in source order.
|
|
164
|
-
for (const
|
|
166
|
+
for (const attribute of events) {
|
|
165
167
|
node.wiring.push({
|
|
166
168
|
kind: 'event',
|
|
167
|
-
event: INPUT_EVENTS[
|
|
168
|
-
handler: lowerEventHandler(
|
|
169
|
+
event: INPUT_EVENTS[attribute.name.name],
|
|
170
|
+
handler: lowerEventHandler(attribute, output, environment, state),
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
|
-
for (const slot of lowerRefBinds(element.openingElement,
|
|
173
|
+
for (const slot of lowerRefBinds(element.openingElement, environment)) {
|
|
172
174
|
node.wiring.push({ kind: 'ref', slot });
|
|
173
175
|
}
|
|
174
176
|
checkInterpolations(node);
|