orvyn-lang 0.1.1 → 0.2.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/LANGUAGE.md +139 -3
- package/README.md +136 -1
- package/package.json +1 -1
- package/src/cli/orvyn.js +31 -480
- package/src/lang/codegen.js +90 -27
- package/src/lang/form.js +99 -0
- package/src/lang/native/android/OrvynRenderer.kt +5 -0
- package/src/lang/native/ios/OrvynEngine.swift +2 -0
- package/src/lang/native/ios/OrvynViews.swift +3 -0
- package/src/lang/native-runtime.js +22 -6
- package/src/lang/runtime-shared.js +28 -0
- package/src/lang/runtime.js +14 -1
- package/src/lang/validation.js +55 -0
- package/src/core/context.js +0 -19
- package/src/core/lifecycle.js +0 -8
- package/src/core/resource.js +0 -27
- package/src/core/router.js +0 -20
- package/src/core/theme.js +0 -10
- package/src/devtools/devicePreview/PreviewFrame.js +0 -214
- package/src/devtools/devicePreview/index.js +0 -6
- package/src/devtools/overlay.js +0 -105
- package/src/runtime/createRenderer.js +0 -22
- package/src/runtime/h.js +0 -93
- package/src/runtime/hydrate.js +0 -59
- package/src/runtime/jsx-dev-runtime.js +0 -7
- package/src/runtime/jsx-runtime.js +0 -13
- package/src/runtime/partialHydration.js +0 -154
- package/src/runtime/platform.js +0 -135
- package/src/runtime/renderToStream.js +0 -127
- package/src/runtime/renderToString.js +0 -121
- package/src/runtime/resume.js +0 -62
package/LANGUAGE.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# The Orvyn Language (v0.1)
|
|
2
2
|
|
|
3
|
-
Orvyn files end in `.orv`.
|
|
4
|
-
|
|
3
|
+
Orvyn files end in `.orv`. The compiler turns your code into JavaScript. The web
|
|
4
|
+
runtime renders browser elements; generated iOS and Android projects run the
|
|
5
|
+
same logic with native views.
|
|
5
6
|
|
|
6
7
|
```orv
|
|
7
8
|
state count = 0
|
|
@@ -75,7 +76,32 @@ Mistakes show in red on the phone and in the terminal, with the line number.
|
|
|
75
76
|
| `screen Name { ... }` | A screen of your app. `App` (or the first screen) is shown first. |
|
|
76
77
|
| `component Name(param) { ... }` | A reusable piece of UI. |
|
|
77
78
|
| `start { ... }` | Runs once when the app opens (load data here). |
|
|
78
|
-
| `use Card, Badge from "./ui"` | Use components or
|
|
79
|
+
| `use Card, Badge from "./ui"` | Use components, functions, values, or state from another `.orv` file. |
|
|
80
|
+
|
|
81
|
+
### Share state between files
|
|
82
|
+
|
|
83
|
+
Every top-level declaration is exported automatically. Import state with `use`
|
|
84
|
+
and read or change it with the same syntax as local state:
|
|
85
|
+
|
|
86
|
+
```orv
|
|
87
|
+
// store.orv
|
|
88
|
+
state count = 0
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```orv
|
|
92
|
+
// app.orv
|
|
93
|
+
use count from "./store"
|
|
94
|
+
|
|
95
|
+
screen Home {
|
|
96
|
+
Column gap: 16 {
|
|
97
|
+
Text "Count: {count}"
|
|
98
|
+
Button "Add", onTap: count += 1
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Imported state stays reactive. Assigning to an imported fixed value or function
|
|
104
|
+
reports a runtime error explaining that the declaration must use `state`.
|
|
79
105
|
|
|
80
106
|
## Statements (inside `fn` and handlers)
|
|
81
107
|
|
|
@@ -133,6 +159,32 @@ start {
|
|
|
133
159
|
`fetch` gives back the JSON directly. To send data: `fetch(url, { method: "POST", body: { name: "A" } })`.
|
|
134
160
|
`wait` pauses until it's done: use it with `fetch` and `sleep(1000)`.
|
|
135
161
|
|
|
162
|
+
Use `wait` inside a function, `start` block, event handler block, or lambda.
|
|
163
|
+
The compiler makes that function async automatically. A lambda containing
|
|
164
|
+
`wait` returns a promise; using it in `map` produces a list of promises, not
|
|
165
|
+
finished results. For sequential work, use `for` inside a function instead.
|
|
166
|
+
Top-level initializers and screen rendering cannot use `wait` directly.
|
|
167
|
+
|
|
168
|
+
```orv
|
|
169
|
+
state status = "Ready"
|
|
170
|
+
|
|
171
|
+
screen Home {
|
|
172
|
+
Button "Pause", onTap: {
|
|
173
|
+
status = "Waiting"
|
|
174
|
+
wait sleep(1000)
|
|
175
|
+
status = "Done"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Try a complete offline app
|
|
181
|
+
|
|
182
|
+
From this repository, run `npm run dev` and open `/lang.html?app=todo`.
|
|
183
|
+
`examples/todo.orv` includes blank-input validation, saved tasks, completion
|
|
184
|
+
toggles, removal, clearing completed tasks, and navigation to an About screen.
|
|
185
|
+
It works without a network request. Saved tasks belong to the current browser
|
|
186
|
+
origin or installed app; they do not sync between devices.
|
|
187
|
+
|
|
136
188
|
### Built-in functions
|
|
137
189
|
|
|
138
190
|
| Function | Does |
|
|
@@ -156,6 +208,88 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
156
208
|
|
|
157
209
|
## Elements
|
|
158
210
|
|
|
211
|
+
### Forms and validation
|
|
212
|
+
|
|
213
|
+
Use `bind` to show state in an input and update it when the user types:
|
|
214
|
+
|
|
215
|
+
```orv
|
|
216
|
+
state name = ""
|
|
217
|
+
|
|
218
|
+
screen Home {
|
|
219
|
+
Input "Your name", bind: name
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`bind: name` replaces `value: name, onChange: { name = value }`. It works
|
|
224
|
+
with state names, one object field (`bind: profile.name`), or a list entry
|
|
225
|
+
(`bind: items[0]`), including imported state. Input values are text. Do not
|
|
226
|
+
combine `bind` with `value` or `onChange`. For a custom change handler, use the
|
|
227
|
+
explicit `value` and `onChange` form instead.
|
|
228
|
+
|
|
229
|
+
Put inputs inside `Form` and give it an `onSubmit` action. `SubmitButton` runs
|
|
230
|
+
that action; the browser form stays on the current page. Ordinary `Button`
|
|
231
|
+
elements default to `type: "button"`, so they do not submit a form accidentally.
|
|
232
|
+
On native, tapping `SubmitButton` runs the enclosing form's action. Put submission
|
|
233
|
+
logic on `Form onSubmit`, rather than adding an `onTap` to `SubmitButton`.
|
|
234
|
+
|
|
235
|
+
Put rules directly on your inputs. Orvyn displays field errors and runs your
|
|
236
|
+
submit action only when every field passes. You do not need an errors state,
|
|
237
|
+
a separate rules object, or a validation function for this:
|
|
238
|
+
|
|
239
|
+
```orv
|
|
240
|
+
state profile = { name: "", email: "" }
|
|
241
|
+
|
|
242
|
+
fn save() {
|
|
243
|
+
print("Ready to save", profile)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
screen Home {
|
|
247
|
+
Form gap: 12, padding: 24, onSubmit: save {
|
|
248
|
+
Input "Name", bind: profile.name, required: true, minLength: 2
|
|
249
|
+
Input "Email", bind: profile.email, type: "email", required: true
|
|
250
|
+
SubmitButton "Save"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Errors appear after the first submission attempt. After that, they update as
|
|
256
|
+
users edit the fields. `type: "email"` also enables email validation and requests
|
|
257
|
+
an email keyboard in the generated iOS and Android apps. For a friendlier error,
|
|
258
|
+
add `label: "Full name"` or `message: "Please enter your full name"` to the input.
|
|
259
|
+
The placeholder is the default label used in automatic error messages.
|
|
260
|
+
|
|
261
|
+
Use `bind` for these fields, or explicit `value` and `onChange` props. A validated
|
|
262
|
+
input needs an update handler. Separate forms keep their own errors. If you render
|
|
263
|
+
repeated forms with the same state, give each Form a distinct string or numeric
|
|
264
|
+
`key` to keep their validation state separate. Do not nest forms.
|
|
265
|
+
|
|
266
|
+
For complete control of your own validation UI, `validate()` remains available.
|
|
267
|
+
See `examples/form-manual.orv` for the explicit version with a rules object and
|
|
268
|
+
manual error rendering.
|
|
269
|
+
|
|
270
|
+
`validate(values, rules)` returns `{ valid, errors }`. `valid` is true when
|
|
271
|
+
every field passes. `errors` contains one message per failing field and no entry
|
|
272
|
+
for passing fields. The same validator runs on web, iOS, and Android.
|
|
273
|
+
|
|
274
|
+
| Rule | Meaning |
|
|
275
|
+
|---|---|
|
|
276
|
+
| `required: true` | Reject missing, null, empty, or whitespace-only text. |
|
|
277
|
+
| `minLength: 2` | Require at least this many Unicode code points. |
|
|
278
|
+
| `maxLength: 40` | Allow at most this many Unicode code points. |
|
|
279
|
+
| `email: true` | Check a basic email format; does not verify the mailbox exists. |
|
|
280
|
+
| `label: "Name"` | Use this name in default messages, such as “Name is required.” |
|
|
281
|
+
| `message: "Enter your name"` | Replace the default message for this field. |
|
|
282
|
+
|
|
283
|
+
Validation checks trimmed text without changing your state. Optional empty fields
|
|
284
|
+
skip length and email checks. Length limits are non-negative whole numbers;
|
|
285
|
+
unknown or invalid rules produce an error explaining what to fix. These rules
|
|
286
|
+
validate text fields; numeric and cross-field rules are not included yet.
|
|
287
|
+
|
|
288
|
+
Standalone `validate()` runs only when called. Forms with inline input rules
|
|
289
|
+
handle submission checks and error display automatically.
|
|
290
|
+
To try the complete example, run `npm run dev` here and open `/lang.html?app=form`.
|
|
291
|
+
The example validates locally; it does not send data to a server.
|
|
292
|
+
|
|
159
293
|
`Element firstArgument, name: value, name: value { children }`
|
|
160
294
|
|
|
161
295
|
| Element | First argument | Renders as |
|
|
@@ -165,6 +299,8 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
165
299
|
| `Box` | — | container |
|
|
166
300
|
| `Text`, `Heading` | text | text |
|
|
167
301
|
| `Button` | label | button |
|
|
302
|
+
| `Form` | — | form container with `onSubmit` |
|
|
303
|
+
| `SubmitButton` | label | submits the enclosing form |
|
|
168
304
|
| `Input` | placeholder | text field |
|
|
169
305
|
| `Image` | source URL | image |
|
|
170
306
|
| `Link` | text | link (`href: "..."`) |
|
package/README.md
CHANGED
|
@@ -34,7 +34,32 @@ screen Home {
|
|
|
34
34
|
| `screen Name { ... }` | A screen of your app. `App` (or the first screen) is shown first. |
|
|
35
35
|
| `component Name(param) { ... }` | A reusable piece of UI. |
|
|
36
36
|
| `start { ... }` | Runs once when the app opens (load data here). |
|
|
37
|
-
| `use Card, Badge from "./ui"` | Use components or
|
|
37
|
+
| `use Card, Badge from "./ui"` | Use components, functions, values, or state from another `.orv` file. |
|
|
38
|
+
|
|
39
|
+
### Share state between files
|
|
40
|
+
|
|
41
|
+
Every top-level declaration is exported automatically. Import state with `use`
|
|
42
|
+
and read or change it with the same syntax as local state:
|
|
43
|
+
|
|
44
|
+
```orv
|
|
45
|
+
// store.orv
|
|
46
|
+
state count = 0
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```orv
|
|
50
|
+
// app.orv
|
|
51
|
+
use count from "./store"
|
|
52
|
+
|
|
53
|
+
screen Home {
|
|
54
|
+
Column gap: 16 {
|
|
55
|
+
Text "Count: {count}"
|
|
56
|
+
Button "Add", onTap: count += 1
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Imported state stays reactive. Assigning to an imported fixed value or function
|
|
62
|
+
reports a runtime error explaining that the declaration must use `state`.
|
|
38
63
|
|
|
39
64
|
## Statements (inside `fn` and handlers)
|
|
40
65
|
|
|
@@ -92,6 +117,32 @@ start {
|
|
|
92
117
|
`fetch` gives back the JSON directly. To send data: `fetch(url, { method: "POST", body: { name: "A" } })`.
|
|
93
118
|
`wait` pauses until it's done: use it with `fetch` and `sleep(1000)`.
|
|
94
119
|
|
|
120
|
+
Use `wait` inside a function, `start` block, event handler block, or lambda.
|
|
121
|
+
The compiler makes that function async automatically. A lambda containing
|
|
122
|
+
`wait` returns a promise; using it in `map` produces a list of promises, not
|
|
123
|
+
finished results. For sequential work, use `for` inside a function instead.
|
|
124
|
+
Top-level initializers and screen rendering cannot use `wait` directly.
|
|
125
|
+
|
|
126
|
+
```orv
|
|
127
|
+
state status = "Ready"
|
|
128
|
+
|
|
129
|
+
screen Home {
|
|
130
|
+
Button "Pause", onTap: {
|
|
131
|
+
status = "Waiting"
|
|
132
|
+
wait sleep(1000)
|
|
133
|
+
status = "Done"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Try a complete offline app
|
|
139
|
+
|
|
140
|
+
From this repository, run `npm run dev` and open `/lang.html?app=todo`.
|
|
141
|
+
`examples/todo.orv` includes blank-input validation, saved tasks, completion
|
|
142
|
+
toggles, removal, clearing completed tasks, and navigation to an About screen.
|
|
143
|
+
It works without a network request. Saved tasks belong to the current browser
|
|
144
|
+
origin or installed app; they do not sync between devices.
|
|
145
|
+
|
|
95
146
|
### Built-in functions
|
|
96
147
|
|
|
97
148
|
| Function | Does |
|
|
@@ -115,6 +166,88 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
115
166
|
|
|
116
167
|
## Elements
|
|
117
168
|
|
|
169
|
+
### Forms and validation
|
|
170
|
+
|
|
171
|
+
Use `bind` to show state in an input and update it when the user types:
|
|
172
|
+
|
|
173
|
+
```orv
|
|
174
|
+
state name = ""
|
|
175
|
+
|
|
176
|
+
screen Home {
|
|
177
|
+
Input "Your name", bind: name
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`bind: name` replaces `value: name, onChange: { name = value }`. It works
|
|
182
|
+
with state names, one object field (`bind: profile.name`), or a list entry
|
|
183
|
+
(`bind: items[0]`), including imported state. Input values are text. Do not
|
|
184
|
+
combine `bind` with `value` or `onChange`. For a custom change handler, use the
|
|
185
|
+
explicit `value` and `onChange` form instead.
|
|
186
|
+
|
|
187
|
+
Put inputs inside `Form` and give it an `onSubmit` action. `SubmitButton` runs
|
|
188
|
+
that action; the browser form stays on the current page. Ordinary `Button`
|
|
189
|
+
elements default to `type: "button"`, so they do not submit a form accidentally.
|
|
190
|
+
On native, tapping `SubmitButton` runs the enclosing form's action. Put submission
|
|
191
|
+
logic on `Form onSubmit`, rather than adding an `onTap` to `SubmitButton`.
|
|
192
|
+
|
|
193
|
+
Put rules directly on your inputs. Orvyn displays field errors and runs your
|
|
194
|
+
submit action only when every field passes. You do not need an errors state,
|
|
195
|
+
a separate rules object, or a validation function for this:
|
|
196
|
+
|
|
197
|
+
```orv
|
|
198
|
+
state profile = { name: "", email: "" }
|
|
199
|
+
|
|
200
|
+
fn save() {
|
|
201
|
+
print("Ready to save", profile)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
screen Home {
|
|
205
|
+
Form gap: 12, padding: 24, onSubmit: save {
|
|
206
|
+
Input "Name", bind: profile.name, required: true, minLength: 2
|
|
207
|
+
Input "Email", bind: profile.email, type: "email", required: true
|
|
208
|
+
SubmitButton "Save"
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Errors appear after the first submission attempt. After that, they update as
|
|
214
|
+
users edit the fields. `type: "email"` also enables email validation and requests
|
|
215
|
+
an email keyboard in the generated iOS and Android apps. For a friendlier error,
|
|
216
|
+
add `label: "Full name"` or `message: "Please enter your full name"` to the input.
|
|
217
|
+
The placeholder is the default label used in automatic error messages.
|
|
218
|
+
|
|
219
|
+
Use `bind` for these fields, or explicit `value` and `onChange` props. A validated
|
|
220
|
+
input needs an update handler. Separate forms keep their own errors. If you render
|
|
221
|
+
repeated forms with the same state, give each Form a distinct string or numeric
|
|
222
|
+
`key` to keep their validation state separate. Do not nest forms.
|
|
223
|
+
|
|
224
|
+
For complete control of your own validation UI, `validate()` remains available.
|
|
225
|
+
See `examples/form-manual.orv` for the explicit version with a rules object and
|
|
226
|
+
manual error rendering.
|
|
227
|
+
|
|
228
|
+
`validate(values, rules)` returns `{ valid, errors }`. `valid` is true when
|
|
229
|
+
every field passes. `errors` contains one message per failing field and no entry
|
|
230
|
+
for passing fields. The same validator runs on web, iOS, and Android.
|
|
231
|
+
|
|
232
|
+
| Rule | Meaning |
|
|
233
|
+
|---|---|
|
|
234
|
+
| `required: true` | Reject missing, null, empty, or whitespace-only text. |
|
|
235
|
+
| `minLength: 2` | Require at least this many Unicode code points. |
|
|
236
|
+
| `maxLength: 40` | Allow at most this many Unicode code points. |
|
|
237
|
+
| `email: true` | Check a basic email format; does not verify the mailbox exists. |
|
|
238
|
+
| `label: "Name"` | Use this name in default messages, such as “Name is required.” |
|
|
239
|
+
| `message: "Enter your name"` | Replace the default message for this field. |
|
|
240
|
+
|
|
241
|
+
Validation checks trimmed text without changing your state. Optional empty fields
|
|
242
|
+
skip length and email checks. Length limits are non-negative whole numbers;
|
|
243
|
+
unknown or invalid rules produce an error explaining what to fix. These rules
|
|
244
|
+
validate text fields; numeric and cross-field rules are not included yet.
|
|
245
|
+
|
|
246
|
+
Standalone `validate()` runs only when called. Forms with inline input rules
|
|
247
|
+
handle submission checks and error display automatically.
|
|
248
|
+
To try the complete example, run `npm run dev` here and open `/lang.html?app=form`.
|
|
249
|
+
The example validates locally; it does not send data to a server.
|
|
250
|
+
|
|
118
251
|
`Element firstArgument, name: value, name: value { children }`
|
|
119
252
|
|
|
120
253
|
| Element | First argument | Renders as |
|
|
@@ -124,6 +257,8 @@ Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
|
|
|
124
257
|
| `Box` | — | container |
|
|
125
258
|
| `Text`, `Heading` | text | text |
|
|
126
259
|
| `Button` | label | button |
|
|
260
|
+
| `Form` | — | form container with `onSubmit` |
|
|
261
|
+
| `SubmitButton` | label | submits the enclosing form |
|
|
127
262
|
| `Input` | placeholder | text field |
|
|
128
263
|
| `Image` | source URL | image |
|
|
129
264
|
| `Link` | text | link (`href: "..."`) |
|