embedded-react 0.14.1 → 0.16.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 +51 -486
- package/aot/compile.mjs +173 -8272
- package/aot/compiler/animations.mjs +1001 -0
- package/aot/compiler/assemble.mjs +806 -0
- package/aot/compiler/c/animations.mjs +362 -0
- package/aot/compiler/c/expressions.mjs +215 -0
- package/aot/compiler/c/functions.mjs +268 -0
- package/aot/compiler/c/keyboard.mjs +96 -0
- package/aot/compiler/c/nodes.mjs +282 -0
- package/aot/compiler/c/pan-responder.mjs +136 -0
- package/aot/compiler/c/statements.mjs +242 -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 +743 -0
- package/aot/compiler/control-flow.mjs +683 -0
- package/aot/compiler/diagnostics.mjs +137 -0
- package/aot/compiler/elements/activity-indicator.mjs +160 -0
- package/aot/compiler/elements/dial.mjs +343 -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 +1479 -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/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 +83 -0
- package/aot/compiler/ir/pan-responder.mjs +16 -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 +282 -0
- package/aot/compiler/nodes.mjs +683 -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 +228 -0
- package/aot/compiler/style-text.mjs +648 -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.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/FlatList.js +4 -4
- package/src/embedded-react/index.d.ts +2 -1
- package/src/props.js +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
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, lowerText } from '../expressions.mjs';
|
|
23
|
+
import { isFn } from '../collect.mjs';
|
|
24
|
+
import { attrExpr, collectStyleAssigns } from '../style-text.mjs';
|
|
25
|
+
import { lowerValueHandler } from '../handlers.mjs';
|
|
26
|
+
import { checkInterpolations, lowerEventHandler, lowerRefBinds, } from '../nodes.mjs';
|
|
27
|
+
import { elementSpec } from './props.mjs';
|
|
28
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
|
+
- Constants
|
|
30
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
31
|
+
/** The <TextInput> events that carry no value, and the engine event each one is. */
|
|
32
|
+
const INPUT_EVENTS = {
|
|
33
|
+
onSubmitEditing: 'ER_EVENT_SUBMIT_EDITING',
|
|
34
|
+
onFocus: 'ER_EVENT_FOCUS',
|
|
35
|
+
onBlur: 'ER_EVENT_BLUR',
|
|
36
|
+
};
|
|
37
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
38
|
+
- Implementation
|
|
39
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
40
|
+
/**
|
|
41
|
+
* <TextInput value={text} onChangeText={(t) => setText(t)} placeholder="…" placeholderTextColor=… style=… />
|
|
42
|
+
* → ER_NODE_TEXT_INPUT. The engine autofocuses on tap (hit_test) and edits its own buffer, firing
|
|
43
|
+
* ER_EVENT_CHANGE_TEXT with the new text — bound to the handler's param via `data->changed_text` (a string).
|
|
44
|
+
* `value` drives the text buffer (er_node_set_props → er_text_input_set_text; state → dynamic, re-synced in
|
|
45
|
+
* app_update; set_text is a no-op when unchanged, so a controlled input is safe). Desktop types via the
|
|
46
|
+
* keyboard; the touch-only CYD needs an on-screen keyboard to enter text (deferred follow-on).
|
|
47
|
+
*
|
|
48
|
+
* @param element The <TextInput>.
|
|
49
|
+
* @param scope Compile-time constants in reach.
|
|
50
|
+
* @param out Everything emitted so far.
|
|
51
|
+
* @param env The expression environment.
|
|
52
|
+
* @param state The component's state table.
|
|
53
|
+
*
|
|
54
|
+
* @returns The node's variable.
|
|
55
|
+
*/
|
|
56
|
+
export function emitTextInput(element, scope, out, env, state) {
|
|
57
|
+
// get node id
|
|
58
|
+
const nodeId = `n${out.allocateNodeId()}`;
|
|
59
|
+
// collect style assignments
|
|
60
|
+
const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, elementSpec('TextInput'));
|
|
61
|
+
// process element attributes
|
|
62
|
+
let valueNode = null;
|
|
63
|
+
let onChangeFn = null;
|
|
64
|
+
let placeholder = null;
|
|
65
|
+
const events = [];
|
|
66
|
+
for (const attr of element.openingElement.attributes) {
|
|
67
|
+
// Ensure all props are explicit named attributes.
|
|
68
|
+
// Spread props cannot be analyzed statically
|
|
69
|
+
if (attr.type !== 'JSXAttribute') {
|
|
70
|
+
throw aotError('AOT: spread props on <TextInput> are not supported');
|
|
71
|
+
}
|
|
72
|
+
// skip non-props
|
|
73
|
+
const name = attr.name.name;
|
|
74
|
+
if (name === 'style' || name === 'ref' || name === 'key')
|
|
75
|
+
continue;
|
|
76
|
+
// process props
|
|
77
|
+
const node = attrExpr(attr);
|
|
78
|
+
if (name === 'value' || name === 'defaultValue') {
|
|
79
|
+
valueNode = node;
|
|
80
|
+
}
|
|
81
|
+
else if (name === 'onChangeText') {
|
|
82
|
+
onChangeFn = node;
|
|
83
|
+
}
|
|
84
|
+
else if (name === 'placeholder') {
|
|
85
|
+
placeholder = String(evalStatic(node, scope));
|
|
86
|
+
}
|
|
87
|
+
else if (name === 'placeholderTextColor') {
|
|
88
|
+
staticAssigns.push({
|
|
89
|
+
field: 'placeholder_color',
|
|
90
|
+
expr: colorLiteral(String(evalStatic(node, scope))),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (name === 'cursorColor') {
|
|
94
|
+
staticAssigns.push({
|
|
95
|
+
field: 'cursor_color',
|
|
96
|
+
expr: colorLiteral(String(evalStatic(node, scope))),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (name === 'editable' || name === 'secureTextEntry') {
|
|
100
|
+
const field = name === 'editable' ? 'editable' : 'secure_text_entry';
|
|
101
|
+
try {
|
|
102
|
+
staticAssigns.push({
|
|
103
|
+
field,
|
|
104
|
+
expr: evalStatic(node, scope) ? '1' : '0',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
dynAssigns.push({
|
|
109
|
+
field,
|
|
110
|
+
value: {
|
|
111
|
+
kind: 'flag',
|
|
112
|
+
test: lowerExpr(node, env),
|
|
113
|
+
truthiness: 'value',
|
|
114
|
+
negate: false,
|
|
115
|
+
whenTrue: 1,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (Object.hasOwn(INPUT_EVENTS, name)) {
|
|
121
|
+
events.push(attr);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw aotError(`AOT: <TextInput> prop "${name}" is not supported`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// value → the input's text buffer (er_node_set_props → er_text_input_set_text): static literal, or a
|
|
128
|
+
// state-driven value re-synced each app_update.
|
|
129
|
+
const node = {
|
|
130
|
+
id: nodeId,
|
|
131
|
+
type: 'ER_NODE_TEXT_INPUT',
|
|
132
|
+
constantProps: staticAssigns,
|
|
133
|
+
stateProps: dynAssigns,
|
|
134
|
+
placeholder,
|
|
135
|
+
text: valueNode ? lowerText(valueNode, env, scope) : null,
|
|
136
|
+
image: null,
|
|
137
|
+
spans: null,
|
|
138
|
+
children: [],
|
|
139
|
+
wiring: binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
140
|
+
};
|
|
141
|
+
// Compile onChangeText into an ER_EVENT_CHANGE_TEXT handler that receives the edited text.
|
|
142
|
+
if (onChangeFn) {
|
|
143
|
+
if (!isFn(onChangeFn)) {
|
|
144
|
+
throw aotError('AOT: onChangeText must be an inline function', 'onChangeText={(t) => setText(t)}');
|
|
145
|
+
}
|
|
146
|
+
const handlerName = `er_handler_${out.handlers.length}`;
|
|
147
|
+
out.handlers.push({
|
|
148
|
+
kind: 'callback',
|
|
149
|
+
name: handlerName,
|
|
150
|
+
callback: lowerValueHandler(onChangeFn, 'data->changed_text', env, state, out, 'string'),
|
|
151
|
+
});
|
|
152
|
+
node.wiring.push({
|
|
153
|
+
kind: 'event',
|
|
154
|
+
event: 'ER_EVENT_CHANGE_TEXT',
|
|
155
|
+
handler: handlerName,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Return, focus and blur take no value: plain handlers, wired in source order.
|
|
159
|
+
for (const attr of events) {
|
|
160
|
+
node.wiring.push({
|
|
161
|
+
kind: 'event',
|
|
162
|
+
event: INPUT_EVENTS[attr.name.name],
|
|
163
|
+
handler: lowerEventHandler(attr, out, env, state),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
for (const slot of lowerRefBinds(element.openingElement, env)) {
|
|
167
|
+
node.wiring.push({ kind: 'ref', slot });
|
|
168
|
+
}
|
|
169
|
+
checkInterpolations(node);
|
|
170
|
+
return node;
|
|
171
|
+
}
|