@lango-project/lango-client 0.0.0-stage → 0.2.1
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/LICENSE +200 -0
- package/NOTICE +2 -0
- package/README.md +929 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/runtime.mjs +607 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/application.mjs +429 -0
- package/dist/application.mjs.map +1 -0
- package/dist/coordinator.mjs +91 -0
- package/dist/coordinator.mjs.map +1 -0
- package/dist/demo.mjs +110 -0
- package/dist/demo.mjs.map +1 -0
- package/dist/demo_controls.mjs +59 -0
- package/dist/demo_controls.mjs.map +1 -0
- package/dist/errors.mjs +201 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/form_state.mjs +266 -0
- package/dist/form_state.mjs.map +1 -0
- package/dist/heartbeat.mjs +330 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/inheritance.mjs +240 -0
- package/dist/inheritance.mjs.map +1 -0
- package/dist/input_values.mjs +65 -0
- package/dist/input_values.mjs.map +1 -0
- package/dist/library.mjs +824 -0
- package/dist/library.mjs.map +1 -0
- package/dist/navigation.mjs +466 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/node/.lango/bignumber.mjs +3119 -0
- package/dist/node/.lango/runtime.mjs +609 -0
- package/dist/node/.lango/xmldom/conventions.js +429 -0
- package/dist/node/.lango/xmldom/dom-parser.js +591 -0
- package/dist/node/.lango/xmldom/dom.js +3759 -0
- package/dist/node/.lango/xmldom/entities.js +2171 -0
- package/dist/node/.lango/xmldom/errors.js +205 -0
- package/dist/node/.lango/xmldom/grammar.js +559 -0
- package/dist/node/.lango/xmldom/index.js +41 -0
- package/dist/node/.lango/xmldom/package.json +1 -0
- package/dist/node/.lango/xmldom/sax.js +983 -0
- package/dist/node/.lango/xmldom.LICENSE.md +8 -0
- package/dist/node/browser_host.mjs +351 -0
- package/dist/node/browser_host.mjs.map +1 -0
- package/dist/node/create_app.mjs +118 -0
- package/dist/node/create_app.mjs.map +1 -0
- package/dist/presentation.mjs +89 -0
- package/dist/presentation.mjs.map +1 -0
- package/dist/protocol.mjs +706 -0
- package/dist/protocol.mjs.map +1 -0
- package/dist/session.mjs +471 -0
- package/dist/session.mjs.map +1 -0
- package/dist/tokens.mjs +298 -0
- package/dist/tokens.mjs.map +1 -0
- package/examples/contacts.lango +293 -0
- package/examples/contacts_flow.lango +174 -0
- package/examples/contacts_store.lango +109 -0
- package/examples/contacts_store_test.lango +65 -0
- package/examples/demo.css +87 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +32 -0
- package/examples/pages.lango +174 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +68 -4
- package/src/application.lango +327 -0
- package/src/browser_host.lango +276 -0
- package/src/coordinator.lango +57 -0
- package/src/demo.lango +110 -0
- package/src/demo_controls.lango +53 -0
- package/src/errors.lango +149 -0
- package/src/errors_test.lango +157 -0
- package/src/form_state.lango +168 -0
- package/src/heartbeat.lango +230 -0
- package/src/heartbeat_test.lango +479 -0
- package/src/inheritance.lango +167 -0
- package/src/input_values.lango +37 -0
- package/src/library.lango +599 -0
- package/src/logout_test.lango +564 -0
- package/src/navigation.lango +309 -0
- package/src/navigation_test.lango +556 -0
- package/src/presentation.lango +55 -0
- package/src/protocol.lango +787 -0
- package/src/renderer_test.lango +2047 -0
- package/src/session.lango +343 -0
- package/src/session_test.lango +455 -0
- package/src/tabs_test.lango +216 -0
- package/src/tokens.lango +215 -0
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +9 -0
- package/template/README.md +44 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +10 -0
- package/template/public/index.html +24 -0
- package/template/src/client.lango +78 -0
- package/template/src/pages.lango +55 -0
- package/template/src/server.lango +24 -0
- package/template/src/worker.lango +77 -0
- package/template/test/app.lango +9 -0
- package/tools/browser_runner.lango +32 -0
- package/tools/browser_test.lango +343 -0
- package/tools/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
package/src/tokens.lango
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import js global Promise
|
|
2
|
+
import js global localStorage
|
|
3
|
+
import js global fetch
|
|
4
|
+
export browserTokenStore(key = "lango:last-token")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class TokenStore
|
|
8
|
+
methods
|
|
9
|
+
latest()
|
|
10
|
+
save(token)
|
|
11
|
+
initialize(path, previousToken = null)
|
|
12
|
+
ready()
|
|
13
|
+
initializing()
|
|
14
|
+
initialized(token, generation)
|
|
15
|
+
current(generation)
|
|
16
|
+
cancelInitialization()
|
|
17
|
+
clear()
|
|
18
|
+
logout(path)
|
|
19
|
+
logoutReady(path, generation)
|
|
20
|
+
loggedOut(previousToken, generation)
|
|
21
|
+
bootstrapSeed(previousToken)
|
|
22
|
+
|
|
23
|
+
TokenStore(storage = null, key = "lango:last-token")
|
|
24
|
+
if !is_string(key) or key == ""
|
|
25
|
+
throw "UiTokenStorageKeyRequired"
|
|
26
|
+
@storage = storage
|
|
27
|
+
@key = key
|
|
28
|
+
@latest = null
|
|
29
|
+
@ready = Promise/resolve()
|
|
30
|
+
@initializing = false
|
|
31
|
+
@generation = 0
|
|
32
|
+
if storage != null
|
|
33
|
+
try
|
|
34
|
+
token = storage.getItem(key)
|
|
35
|
+
if is_string(token) and token != "" and token.length <= 16384
|
|
36
|
+
@latest = token
|
|
37
|
+
catch error
|
|
38
|
+
storageUnavailable()
|
|
39
|
+
|
|
40
|
+
TokenStore:latest()
|
|
41
|
+
return @latest
|
|
42
|
+
|
|
43
|
+
TokenStore:ready()
|
|
44
|
+
return @ready
|
|
45
|
+
|
|
46
|
+
TokenStore:initializing()
|
|
47
|
+
return @initializing
|
|
48
|
+
|
|
49
|
+
TokenStore:current(generation)
|
|
50
|
+
return generation == @generation
|
|
51
|
+
|
|
52
|
+
TokenStore:initialized(token, generation)
|
|
53
|
+
if !current(generation)
|
|
54
|
+
throw "UiTokenOperationSuperseded"
|
|
55
|
+
if token != null
|
|
56
|
+
save(token)
|
|
57
|
+
@initializing = false
|
|
58
|
+
return token
|
|
59
|
+
|
|
60
|
+
TokenStore:cancelInitialization()
|
|
61
|
+
@generation++
|
|
62
|
+
@initializing = false
|
|
63
|
+
@ready = Promise/resolve(@latest)
|
|
64
|
+
return null
|
|
65
|
+
|
|
66
|
+
TokenStore:clear()
|
|
67
|
+
previous = @latest
|
|
68
|
+
cancelInitialization()
|
|
69
|
+
@latest = null
|
|
70
|
+
@ready = Promise/resolve()
|
|
71
|
+
if @storage != null
|
|
72
|
+
try
|
|
73
|
+
persisted = @storage.getItem(@key)
|
|
74
|
+
if previous != null and persisted == previous
|
|
75
|
+
@storage.removeItem(@key)
|
|
76
|
+
catch error
|
|
77
|
+
storageUnavailable()
|
|
78
|
+
return null
|
|
79
|
+
|
|
80
|
+
TokenStore:initialize(path, previousToken = null)
|
|
81
|
+
if !is_string(path) or !path.startsWith("/") or path.startsWith("//") or path.includes("\\")
|
|
82
|
+
throw "UiTokenBootstrapRequiresSameOriginPath"
|
|
83
|
+
cancelInitialization()
|
|
84
|
+
generation = @generation
|
|
85
|
+
headers = {
|
|
86
|
+
"Content-Type": "application/json"
|
|
87
|
+
}
|
|
88
|
+
previousToken = bootstrapSeed(previousToken)
|
|
89
|
+
if previousToken != null
|
|
90
|
+
headers.Authorization = "Bearer ${previousToken}"
|
|
91
|
+
@initializing = true
|
|
92
|
+
pending = fetch(path, {
|
|
93
|
+
method: "POST"
|
|
94
|
+
headers: headers
|
|
95
|
+
body: "{}"
|
|
96
|
+
cache: "no-store"
|
|
97
|
+
redirect: "error"
|
|
98
|
+
}).then((response)
|
|
99
|
+
capture generation
|
|
100
|
+
return initializedToken(@this, response, generation)
|
|
101
|
+
)
|
|
102
|
+
@ready = pending
|
|
103
|
+
pending.catch((error)
|
|
104
|
+
capture generation
|
|
105
|
+
bootstrapFailed(@this, generation)
|
|
106
|
+
)
|
|
107
|
+
return pending
|
|
108
|
+
|
|
109
|
+
TokenStore:bootstrapSeed(previousToken)
|
|
110
|
+
if previousToken != null
|
|
111
|
+
return previousToken
|
|
112
|
+
if @storage != null
|
|
113
|
+
try
|
|
114
|
+
persisted = @storage.getItem(@key)
|
|
115
|
+
if is_string(persisted) and persisted != "" and persisted.length <= 16384
|
|
116
|
+
return persisted
|
|
117
|
+
catch error
|
|
118
|
+
storageUnavailable()
|
|
119
|
+
return @latest
|
|
120
|
+
|
|
121
|
+
initializedToken(store, response, generation)
|
|
122
|
+
token = response.headers.get("X-Lango-Token")
|
|
123
|
+
if !response.ok or token == null
|
|
124
|
+
throw "UiTokenBootstrapFailed"
|
|
125
|
+
return response.json().then((body)
|
|
126
|
+
capture store
|
|
127
|
+
capture token
|
|
128
|
+
capture generation
|
|
129
|
+
return store.initialized(token, generation)
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
bootstrapFailed(store, generation)
|
|
133
|
+
context log
|
|
134
|
+
if !store.current(generation)
|
|
135
|
+
return null
|
|
136
|
+
log.err("Token bootstrap failed")
|
|
137
|
+
store.initialized(null, generation)
|
|
138
|
+
return null
|
|
139
|
+
|
|
140
|
+
TokenStore:logout(path)
|
|
141
|
+
if !is_string(path) or !path.startsWith("/") or path.startsWith("//") or path.includes("\\")
|
|
142
|
+
throw "UiLogoutRequiresSameOriginPath"
|
|
143
|
+
generation = @generation
|
|
144
|
+
waiting = @ready
|
|
145
|
+
ready = waiting.catch((error)
|
|
146
|
+
return null
|
|
147
|
+
)
|
|
148
|
+
return ready.then(()
|
|
149
|
+
capture path
|
|
150
|
+
capture generation
|
|
151
|
+
return logoutReady(path, generation)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
TokenStore:logoutReady(path, generation)
|
|
155
|
+
if !current(generation)
|
|
156
|
+
throw "UiTokenOperationSuperseded"
|
|
157
|
+
previous = @latest
|
|
158
|
+
if previous == null
|
|
159
|
+
throw "UiLogoutTokenRequired"
|
|
160
|
+
return fetch(path, {
|
|
161
|
+
method: "POST"
|
|
162
|
+
headers: {
|
|
163
|
+
"Content-Type": "application/json"
|
|
164
|
+
Authorization: "Bearer ${previous}"
|
|
165
|
+
}
|
|
166
|
+
body: "{}"
|
|
167
|
+
cache: "no-store"
|
|
168
|
+
redirect: "error"
|
|
169
|
+
}).then((response)
|
|
170
|
+
capture previous
|
|
171
|
+
capture generation
|
|
172
|
+
return readLogout(@this, response, previous, generation)
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
readLogout(store, response, previous, generation)
|
|
176
|
+
if !response.ok
|
|
177
|
+
throw "UiLogoutHttpError: ${response.status}"
|
|
178
|
+
return response.json().then((body)
|
|
179
|
+
capture store
|
|
180
|
+
capture previous
|
|
181
|
+
capture generation
|
|
182
|
+
if !is_object(body) or body.loggedOut != true
|
|
183
|
+
throw "UiInvalidLogoutResponse"
|
|
184
|
+
return store.loggedOut(previous, generation)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
TokenStore:loggedOut(previousToken, generation)
|
|
188
|
+
if !current(generation)
|
|
189
|
+
throw "UiTokenOperationSuperseded"
|
|
190
|
+
clear()
|
|
191
|
+
return previousToken
|
|
192
|
+
|
|
193
|
+
TokenStore:save(token)
|
|
194
|
+
if !is_string(token) or token == "" or token.length > 16384
|
|
195
|
+
throw "UiInvalidToken"
|
|
196
|
+
@latest = token
|
|
197
|
+
if @storage != null
|
|
198
|
+
try
|
|
199
|
+
@storage.setItem(@key, token)
|
|
200
|
+
catch error
|
|
201
|
+
storageUnavailable()
|
|
202
|
+
return null
|
|
203
|
+
|
|
204
|
+
browserTokenStore(key = "lango:last-token")
|
|
205
|
+
storage = null
|
|
206
|
+
try
|
|
207
|
+
storage = localStorage
|
|
208
|
+
catch error
|
|
209
|
+
storageUnavailable()
|
|
210
|
+
return new TokenStore(storage, key)
|
|
211
|
+
|
|
212
|
+
storageUnavailable()
|
|
213
|
+
context log
|
|
214
|
+
log.warn("Token persistence is unavailable; this session continues in memory")
|
|
215
|
+
return null
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# {{APP_NAME}}
|
|
2
|
+
|
|
3
|
+
A Lango API/UI application using protocol 1. Requires Node.js 24 or newer.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install
|
|
7
|
+
npm test
|
|
8
|
+
npm run build
|
|
9
|
+
npm start
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Open http://localhost:8080/ (or refresh http://localhost:8080/home directly).
|
|
13
|
+
Stop with Ctrl+C. Change the two local ports in `src/server.lango` if needed.
|
|
14
|
+
Rebuild and restart after changing source or assets.
|
|
15
|
+
Named fields have visible associated labels and inline validation messages.
|
|
16
|
+
Tab reaches the name field and Save; Enter on Save runs validation. A successful
|
|
17
|
+
request restores focus when the control still exists, and validation reports the
|
|
18
|
+
first invalid input. The shell uses header/main landmarks and a visible focus ring.
|
|
19
|
+
BrowserHost limits incoming bodies to 1 MiB and a 30-second upload deadline.
|
|
20
|
+
Set `bodyLimit` and `bodyTimeoutMs` in its options to change both the proxy and
|
|
21
|
+
worker API limits. The worker API's loopback port provides GET `/health`
|
|
22
|
+
(liveness) and `/ready` (admission capacity).
|
|
23
|
+
Optional `rateLimit`, `rateWindowMs` and `rateMaxClients` protect the browser
|
|
24
|
+
POST entry; the general rate limit defaults to disabled.
|
|
25
|
+
The browser's ErrorReporter sends only fixed categories and bounded repeat counts
|
|
26
|
+
to `/_lango/client-error`; raw messages, stacks, URLs and form values are omitted.
|
|
27
|
+
|
|
28
|
+
- `src/client.lango` mounts the browser application, URL handling and dirty guards.
|
|
29
|
+
- `src/pages.lango` defines the shared page/template registry.
|
|
30
|
+
- `src/worker.lango` handles synchronous API/UI events and server validation.
|
|
31
|
+
- `src/server.lango` starts the local BrowserHost with explicit asset paths.
|
|
32
|
+
- `public/` contains the HTML shell, import map and theme CSS.
|
|
33
|
+
|
|
34
|
+
Save validates the form and acknowledges the displayed name. This starter does
|
|
35
|
+
not persist business data; add a repository when saving to a database. Runtime
|
|
36
|
+
JWT keys and replay state are stored in the ignored `.lango/state/` directory.
|
|
37
|
+
Dependencies are pinned to one package release set; commit the lock
|
|
38
|
+
file produced by `npm install`. Build artifacts stay in ignored `dist/` folders.
|
|
39
|
+
|
|
40
|
+
Install the Lango VS Code extension (Marketplace or manual VSIX). The repository
|
|
41
|
+
includes extension recommendations and four-space settings.
|
|
42
|
+
|
|
43
|
+
BrowserHost listens on loopback and supplies same-origin HTML/assets/API for
|
|
44
|
+
local development. Configure external hosting separately when deploying.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{APP_NAME}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "lango build src/client.lango --out dist/browser/client.mjs --target browser && lango build src/worker.lango --out dist/server/worker.mjs && lango build src/server.lango --out dist/server/server.mjs --executable",
|
|
8
|
+
"start": "node dist/server/server.mjs",
|
|
9
|
+
"test": "lango test test/app.lango --build-dir .lango/test"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@lango-project/lango-api": "{{API_VERSION}}",
|
|
13
|
+
"@lango-project/lango-ui": "{{UI_VERSION}}",
|
|
14
|
+
"@lango-project/lango-client": "{{CLIENT_VERSION}}"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@lango-project/lango-js": "{{JS_VERSION}}"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=24"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
body { max-width: 40rem; margin: 2rem auto; padding: 0 1rem; font: 1rem system-ui, sans-serif; }
|
|
2
|
+
input, button { display: block; padding: 0.6rem; margin-block: 0.75rem; font: inherit; }
|
|
3
|
+
[aria-invalid="true"] { outline: 2px solid #b91c1c; }
|
|
4
|
+
#error { color: #b91c1c; }
|
|
5
|
+
.lango-field { display: grid; gap: 0.35rem; margin-block: 0.75rem; }
|
|
6
|
+
.lango-caption { font-weight: 600; }
|
|
7
|
+
.lango-field input, .lango-field select { box-sizing: border-box; width: 100%; margin: 0; }
|
|
8
|
+
.lango-field-error { color: #b91c1c; }
|
|
9
|
+
.lango-field-error[hidden] { display: none; }
|
|
10
|
+
:focus-visible { outline: 3px solid #0f766e; outline-offset: 3px; }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>{{APP_NAME}}</title>
|
|
7
|
+
<link rel="stylesheet" href="/assets/app.css">
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"@lango-project/lango-client/application": "/vendor/lango-client/application.mjs",
|
|
12
|
+
"@lango-project/lango-client/navigation": "/vendor/lango-client/navigation.mjs",
|
|
13
|
+
"@lango-project/lango-client/errors": "/vendor/lango-client/errors.mjs"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<header><h1>{{APP_NAME}}</h1></header>
|
|
20
|
+
<main id="app"></main>
|
|
21
|
+
<p id="error" role="alert"></p>
|
|
22
|
+
<script type="module" src="/app/client.mjs"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import js global document
|
|
2
|
+
import js global window
|
|
3
|
+
import js "@lango-project/lango-client/application" as ui
|
|
4
|
+
import js "@lango-project/lango-client/navigation" as routing
|
|
5
|
+
import js "@lango-project/lango-client/errors" as reports
|
|
6
|
+
|
|
7
|
+
global app = start()
|
|
8
|
+
|
|
9
|
+
class Errors
|
|
10
|
+
methods
|
|
11
|
+
error(error)
|
|
12
|
+
clear()
|
|
13
|
+
|
|
14
|
+
Errors(reporter)
|
|
15
|
+
@reporter = reporter
|
|
16
|
+
|
|
17
|
+
Errors:error(error)
|
|
18
|
+
@reporter.error(error)
|
|
19
|
+
element = document.getElementById("error")
|
|
20
|
+
element.textContent = "Please correct the form or try the request again."
|
|
21
|
+
|
|
22
|
+
Errors:clear()
|
|
23
|
+
element = document.getElementById("error")
|
|
24
|
+
element.textContent = ""
|
|
25
|
+
|
|
26
|
+
start()
|
|
27
|
+
reporter = new reports/ErrorReporter({
|
|
28
|
+
window: window
|
|
29
|
+
})
|
|
30
|
+
errors = new Errors(reporter)
|
|
31
|
+
application = new ui/Application(document, document.getElementById("app"), {
|
|
32
|
+
type: "Form"
|
|
33
|
+
name: "page"
|
|
34
|
+
controls: [{
|
|
35
|
+
type: "Value"
|
|
36
|
+
name: "url"
|
|
37
|
+
value: ""
|
|
38
|
+
}, {
|
|
39
|
+
type: "Value"
|
|
40
|
+
name: "template"
|
|
41
|
+
value: null
|
|
42
|
+
}, {
|
|
43
|
+
type: "Container"
|
|
44
|
+
name: "content"
|
|
45
|
+
controls: []
|
|
46
|
+
}]
|
|
47
|
+
}, {
|
|
48
|
+
bootstrapPath: "/_lango/start"
|
|
49
|
+
storageKey: "{{APP_NAME}}:token"
|
|
50
|
+
window: window
|
|
51
|
+
errors: errors
|
|
52
|
+
})
|
|
53
|
+
root = application.control
|
|
54
|
+
url = root.controls[0]
|
|
55
|
+
changed = (event)
|
|
56
|
+
capture application
|
|
57
|
+
capture url
|
|
58
|
+
url.setValue(event.url)
|
|
59
|
+
session = application.session("page")
|
|
60
|
+
return session.send("/app/url", "url", null)
|
|
61
|
+
canLeave = (event)
|
|
62
|
+
capture application
|
|
63
|
+
return application.confirmDiscard(window)
|
|
64
|
+
navigation = new routing/Navigation(window, {
|
|
65
|
+
rootRedirect: "/home"
|
|
66
|
+
onUrl: changed
|
|
67
|
+
beforeNavigate: canLeave
|
|
68
|
+
})
|
|
69
|
+
opening = navigation.start()
|
|
70
|
+
opening.catch((error)
|
|
71
|
+
capture errors
|
|
72
|
+
errors.error(error)
|
|
73
|
+
)
|
|
74
|
+
return {
|
|
75
|
+
application: application
|
|
76
|
+
navigation: navigation
|
|
77
|
+
reporter: reporter
|
|
78
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import js "@lango-project/lango-ui" as ui
|
|
2
|
+
|
|
3
|
+
export createPages()
|
|
4
|
+
|
|
5
|
+
createPages()
|
|
6
|
+
pages = new ui/Pages()
|
|
7
|
+
pages.template({
|
|
8
|
+
path: "/"
|
|
9
|
+
function: layout
|
|
10
|
+
})
|
|
11
|
+
pages.page({
|
|
12
|
+
path: "/home"
|
|
13
|
+
function: home
|
|
14
|
+
})
|
|
15
|
+
return pages
|
|
16
|
+
|
|
17
|
+
layout(selected)
|
|
18
|
+
return {
|
|
19
|
+
type: "Container"
|
|
20
|
+
controls: [{
|
|
21
|
+
type: "Container"
|
|
22
|
+
name: "__content__"
|
|
23
|
+
controls: []
|
|
24
|
+
}]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
home(selected)
|
|
28
|
+
return {
|
|
29
|
+
type: "Form"
|
|
30
|
+
name: "__content__"
|
|
31
|
+
controls: [{
|
|
32
|
+
type: "Text"
|
|
33
|
+
name: "fullName"
|
|
34
|
+
label: "Your name"
|
|
35
|
+
value: ""
|
|
36
|
+
validation: {
|
|
37
|
+
required: true
|
|
38
|
+
minLength: 2
|
|
39
|
+
maxLength: 100
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
type: "Button"
|
|
43
|
+
name: "saveButton"
|
|
44
|
+
text: "Save"
|
|
45
|
+
event: "/app/save"
|
|
46
|
+
validate: true
|
|
47
|
+
}, {
|
|
48
|
+
type: "Text"
|
|
49
|
+
name: "status"
|
|
50
|
+
label: "Save status"
|
|
51
|
+
value: "Enter your name, then save."
|
|
52
|
+
enabled: false
|
|
53
|
+
trackChanges: false
|
|
54
|
+
}]
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import js "node:path" as path
|
|
2
|
+
import js global process
|
|
3
|
+
import js "@lango-project/lango-client/host" as web
|
|
4
|
+
import "./pages"
|
|
5
|
+
createPages()
|
|
6
|
+
|
|
7
|
+
export main(args)
|
|
8
|
+
|
|
9
|
+
main(args)
|
|
10
|
+
host = new web/BrowserHost({
|
|
11
|
+
appRoot: process.cwd()
|
|
12
|
+
pages: createPages()
|
|
13
|
+
worker: "dist/server/worker.mjs"
|
|
14
|
+
shell: "public/index.html"
|
|
15
|
+
port: 8080
|
|
16
|
+
apiPort: 8081
|
|
17
|
+
assets: {
|
|
18
|
+
"/app/client.mjs": "dist/browser/client.mjs"
|
|
19
|
+
"/app/.lango/runtime.mjs": "dist/browser/.lango/runtime.mjs"
|
|
20
|
+
"/app/.lango/bignumber.mjs": "dist/browser/.lango/bignumber.mjs"
|
|
21
|
+
"/assets/app.css": "public/app.css"
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
return host.start()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import js "@lango-project/lango-api" as api
|
|
2
|
+
import js "@lango-project/lango-ui" as ui
|
|
3
|
+
import "./pages"
|
|
4
|
+
createPages()
|
|
5
|
+
|
|
6
|
+
export createWorker(options)
|
|
7
|
+
|
|
8
|
+
global dispatcher = null
|
|
9
|
+
global pages = null
|
|
10
|
+
|
|
11
|
+
createWorker(options)
|
|
12
|
+
global dispatcher
|
|
13
|
+
global pages
|
|
14
|
+
pages = createPages()
|
|
15
|
+
dispatcher = new ui/Dispatcher(options.appRoot)
|
|
16
|
+
dispatcher.event({
|
|
17
|
+
path: "/app/url"
|
|
18
|
+
function: page
|
|
19
|
+
})
|
|
20
|
+
dispatcher.event({
|
|
21
|
+
path: "/app/save"
|
|
22
|
+
function: save
|
|
23
|
+
})
|
|
24
|
+
routes = new api/Routes()
|
|
25
|
+
routes.endpoint({
|
|
26
|
+
path: "/app/*"
|
|
27
|
+
function: handle
|
|
28
|
+
anonymous: true
|
|
29
|
+
})
|
|
30
|
+
return {
|
|
31
|
+
routes: routes.values()
|
|
32
|
+
preload: [pages, dispatcher]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
handle(input)
|
|
36
|
+
global dispatcher
|
|
37
|
+
context request
|
|
38
|
+
context response
|
|
39
|
+
if !is_string(request.headers.authorization)
|
|
40
|
+
response.status(401).send({
|
|
41
|
+
error: "BootstrapRequired"
|
|
42
|
+
})
|
|
43
|
+
return null
|
|
44
|
+
return dispatcher.handle(input)
|
|
45
|
+
|
|
46
|
+
page(input)
|
|
47
|
+
global pages
|
|
48
|
+
context form
|
|
49
|
+
context response
|
|
50
|
+
rendered = pages.render({
|
|
51
|
+
url: form.url.value
|
|
52
|
+
template: form.template.value
|
|
53
|
+
})
|
|
54
|
+
result = new ui/Response(input.formId, input.seqno)
|
|
55
|
+
result.replace(rendered.target, rendered.control)
|
|
56
|
+
result.value("template", rendered.template)
|
|
57
|
+
response.send(result.result())
|
|
58
|
+
return null
|
|
59
|
+
|
|
60
|
+
save(input)
|
|
61
|
+
context form
|
|
62
|
+
context response
|
|
63
|
+
name = input.values.fullName
|
|
64
|
+
if !is_string(name)
|
|
65
|
+
response.status(400).send({
|
|
66
|
+
error: "InvalidName"
|
|
67
|
+
})
|
|
68
|
+
return null
|
|
69
|
+
name = name.trim()
|
|
70
|
+
if name.length < 2 or name.length > 100
|
|
71
|
+
form.fullName.error = "Enter a name of 2 to 100 characters."
|
|
72
|
+
return null
|
|
73
|
+
form.fullName.savedValue = name
|
|
74
|
+
form.status.value = "Saved: ${name}"
|
|
75
|
+
return {
|
|
76
|
+
fullName: name
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import js "@lango-project/lango-ui" as ui
|
|
2
|
+
|
|
3
|
+
test "UI protocol and basic response are available"
|
|
4
|
+
assert ui/protocolVersion() == 1
|
|
5
|
+
response = new ui/Response("profile", 1)
|
|
6
|
+
response.value("fullName", "Ada")
|
|
7
|
+
result = response.result()
|
|
8
|
+
assert result.protocol == 1
|
|
9
|
+
assert result.vals.fullName == "Ada"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import js "node:fs" as fs
|
|
2
|
+
import js "node:path" as path
|
|
3
|
+
import js "node:child_process" as children
|
|
4
|
+
import js global process
|
|
5
|
+
|
|
6
|
+
export main(args)
|
|
7
|
+
|
|
8
|
+
main(args)
|
|
9
|
+
environment = {
|
|
10
|
+
}
|
|
11
|
+
for process.env as name: value
|
|
12
|
+
environment[name] = value
|
|
13
|
+
environment.PLAYWRIGHT_BROWSERS_PATH = path.resolve(".test-output/browsers")
|
|
14
|
+
environment.TMPDIR = path.resolve(".test-output/browser-tmp")
|
|
15
|
+
fs.mkdirSync(environment.TMPDIR, {
|
|
16
|
+
recursive: true
|
|
17
|
+
})
|
|
18
|
+
entry = path.resolve(".test-output/browser_test.mjs")
|
|
19
|
+
command = [entry]
|
|
20
|
+
command = command.concat(args)
|
|
21
|
+
if args.length == 1 and args[0] == "install"
|
|
22
|
+
command = [path.resolve("node_modules/playwright/cli.js"), "install", "chromium", "--only-shell"]
|
|
23
|
+
result = children/spawnSync(process.execPath, command, {
|
|
24
|
+
stdio: "inherit"
|
|
25
|
+
env: environment
|
|
26
|
+
})
|
|
27
|
+
if result.error != null
|
|
28
|
+
throw "BrowserProcessFailed: ${result.error}"
|
|
29
|
+
process.exitCode = result.status
|
|
30
|
+
if result.status == null
|
|
31
|
+
process.exitCode = 1
|
|
32
|
+
return null
|