@lango-project/lango-client 0.4.0 → 0.4.2
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 +63 -4
- package/cli/.lango/runtime.mjs +24 -1
- package/cli/create.mjs +0 -0
- package/dist/.lango/runtime.mjs +24 -1
- package/dist/accordion.mjs +9 -8
- package/dist/accordion.mjs.map +1 -1
- package/dist/activities.mjs +8 -7
- package/dist/activities.mjs.map +1 -1
- package/dist/app.mjs +500 -50
- package/dist/app.mjs.map +1 -1
- package/dist/boot.mjs +3 -2
- package/dist/boot.mjs.map +1 -1
- package/dist/button.mjs +8 -7
- package/dist/button.mjs.map +1 -1
- package/dist/chip.mjs +5 -4
- package/dist/chip.mjs.map +1 -1
- package/dist/client.css +7 -0
- package/dist/combo_box.mjs +15 -14
- package/dist/combo_box.mjs.map +1 -1
- package/dist/content.mjs +9 -8
- package/dist/content.mjs.map +1 -1
- package/dist/control.mjs +2 -0
- package/dist/control.mjs.map +1 -1
- package/dist/date_input.mjs +3 -2
- package/dist/date_input.mjs.map +1 -1
- package/dist/dimensions.mjs +102 -0
- package/dist/dimensions.mjs.map +1 -0
- package/dist/error_reporter.mjs +6 -5
- package/dist/error_reporter.mjs.map +1 -1
- package/dist/fields.mjs +9 -8
- package/dist/fields.mjs.map +1 -1
- package/dist/file_input.mjs +19 -18
- package/dist/file_input.mjs.map +1 -1
- package/dist/form.mjs +15 -3
- package/dist/form.mjs.map +1 -1
- package/dist/heartbeat.mjs +12 -11
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +1 -1
- package/dist/input_changes.mjs +5 -4
- package/dist/input_changes.mjs.map +1 -1
- package/dist/longpoll.mjs +12 -11
- package/dist/longpoll.mjs.map +1 -1
- package/dist/main.mjs +45 -19
- package/dist/main.mjs.map +1 -1
- package/dist/menus.mjs +19 -18
- package/dist/menus.mjs.map +1 -1
- package/dist/navigation.mjs +7 -6
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +9 -8
- package/dist/numeric_input.mjs.map +1 -1
- package/dist/otp_input.mjs +5 -4
- package/dist/otp_input.mjs.map +1 -1
- package/dist/presentations.mjs +17 -16
- package/dist/presentations.mjs.map +1 -1
- package/dist/renderer.mjs +88 -12
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +167 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +809 -125
- package/dist/tables.mjs.map +1 -1
- package/dist/tabs.mjs +7 -6
- package/dist/tabs.mjs.map +1 -1
- package/dist/widgets.mjs +5 -4
- package/dist/widgets.mjs.map +1 -1
- package/docs/implementation.md +51 -0
- package/package.json +4 -3
- package/src/app.lango +358 -12
- package/src/control.lango +3 -0
- package/src/dimensions.lango +65 -0
- package/src/form.lango +13 -3
- package/src/heartbeat.lango +2 -2
- package/src/main.lango +24 -0
- package/src/renderer.lango +78 -9
- package/src/table_scope.lango +119 -0
- package/src/tables.lango +620 -105
- package/web/client.css +7 -0
- package/web/index.html +1 -1
package/src/app.lango
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import js global crypto
|
|
2
|
+
import js global Error
|
|
1
3
|
import js global Object
|
|
2
4
|
import js global Promise
|
|
3
5
|
import js global URL
|
|
@@ -19,15 +21,30 @@ export class App(host, renderer)
|
|
|
19
21
|
reporter
|
|
20
22
|
methods
|
|
21
23
|
start()
|
|
24
|
+
acceptEvents(events)
|
|
22
25
|
post(url, input, token)
|
|
23
26
|
saveToken(token)
|
|
27
|
+
clearSavedToken()
|
|
24
28
|
send(form, url, owner = null)
|
|
25
29
|
deliver(form, action, owner, generation)
|
|
26
30
|
report(form, url, input, owner)
|
|
27
31
|
executeDelivery(job)
|
|
28
32
|
checkUrl(url)
|
|
29
33
|
hostUrl()
|
|
30
|
-
request(url, input, token, signal = null, channel = false)
|
|
34
|
+
request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)
|
|
35
|
+
sendInput(job, input)
|
|
36
|
+
resumeInput(job, input, challenge)
|
|
37
|
+
needLogin(job, challenge)
|
|
38
|
+
finishLogin(form, userId)
|
|
39
|
+
completeLogin(form)
|
|
40
|
+
beginLoginResponse(form, packet)
|
|
41
|
+
observeAuthentication(form, previous, packet)
|
|
42
|
+
commitAuthentication(source, previous, token, change)
|
|
43
|
+
externalAuthentication(change)
|
|
44
|
+
invalidateForm(form)
|
|
45
|
+
reloadSession()
|
|
46
|
+
cancelLogin(problem = "LoginCancelled")
|
|
47
|
+
loginScopeDisposed(form)
|
|
31
48
|
poll(url, input, token, signal)
|
|
32
49
|
canPoll(form)
|
|
33
50
|
pausePolls(form = null)
|
|
@@ -59,6 +76,18 @@ App(host, renderer)
|
|
|
59
76
|
@pingJob = null
|
|
60
77
|
@resources = []
|
|
61
78
|
@reporter = null
|
|
79
|
+
@login = null
|
|
80
|
+
@committingAuthentication = false
|
|
81
|
+
@authVersion = 0
|
|
82
|
+
@authChanges = []
|
|
83
|
+
@externalStale = false
|
|
84
|
+
@storageChange = null
|
|
85
|
+
try
|
|
86
|
+
@storageChange = @host.storage.getItem("lango.authChange")
|
|
87
|
+
if !is_string(@storageChange) or !@storageChange.startsWith("v1:")
|
|
88
|
+
@storageChange = null
|
|
89
|
+
catch problem
|
|
90
|
+
@storageChange = null
|
|
62
91
|
|
|
63
92
|
App:now()
|
|
64
93
|
if @host.now != null
|
|
@@ -84,6 +113,8 @@ App:checkUrl(url)
|
|
|
84
113
|
return target
|
|
85
114
|
|
|
86
115
|
App:error(form, error, code = "UiFailure", name = null)
|
|
116
|
+
if form != null and form.requestForm != null
|
|
117
|
+
form = form.requestForm
|
|
87
118
|
if @disposed or form == null or form.disposed
|
|
88
119
|
return null
|
|
89
120
|
@renderer.reportError(form, error)
|
|
@@ -92,25 +123,49 @@ App:error(form, error, code = "UiFailure", name = null)
|
|
|
92
123
|
return null
|
|
93
124
|
|
|
94
125
|
App:saveToken(token)
|
|
126
|
+
if @externalStale
|
|
127
|
+
return false
|
|
95
128
|
try
|
|
96
|
-
@host.storage
|
|
129
|
+
storage = @host.storage
|
|
130
|
+
if storage.getItem != null
|
|
131
|
+
current = storage.getItem("lango.authChange")
|
|
132
|
+
if !@committingAuthentication and is_string(current) and current.startsWith("v1:") and current != @storageChange
|
|
133
|
+
externalAuthentication(current)
|
|
134
|
+
return false
|
|
135
|
+
if @storageChange != null
|
|
136
|
+
storage.setItem("lango.token:${@storageChange}", token)
|
|
137
|
+
storage.setItem("lango.token", token)
|
|
97
138
|
catch error
|
|
98
139
|
return null
|
|
99
140
|
return null
|
|
100
141
|
|
|
142
|
+
App:clearSavedToken()
|
|
143
|
+
try
|
|
144
|
+
@host.storage.removeItem("lango.token")
|
|
145
|
+
if @storageChange != null
|
|
146
|
+
@host.storage.removeItem("lango.token:${@storageChange}")
|
|
147
|
+
return true
|
|
148
|
+
catch error
|
|
149
|
+
return false
|
|
150
|
+
|
|
101
151
|
App:post(url, input, token)
|
|
102
152
|
return request(url, input, token)
|
|
103
153
|
|
|
104
154
|
App:poll(url, input, token, signal)
|
|
105
155
|
return request(url, input, token, signal, true)
|
|
106
156
|
|
|
107
|
-
App:request(url, input, token, signal = null, channel = false)
|
|
157
|
+
App:request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)
|
|
108
158
|
target = checkUrl(url)
|
|
109
159
|
headers = {
|
|
110
160
|
"Content-Type": "application/json"
|
|
111
161
|
}
|
|
162
|
+
headers["X-Lango-Screen"] = "wide"
|
|
163
|
+
if @host.screen != null
|
|
164
|
+
headers["X-Lango-Screen"] = @host.screen()
|
|
112
165
|
if token != null
|
|
113
166
|
headers.Authorization = "Bearer ${token}"
|
|
167
|
+
if expected != null
|
|
168
|
+
headers["X-Lango-Expected-User"] = to_json(expected)
|
|
114
169
|
options = {
|
|
115
170
|
method: "POST"
|
|
116
171
|
headers: headers
|
|
@@ -120,8 +175,23 @@ App:request(url, input, token, signal = null, channel = false)
|
|
|
120
175
|
options.signal = signal
|
|
121
176
|
return chain @host.fetch("${target.pathname}${target.search}", options)
|
|
122
177
|
then(res)
|
|
178
|
+
capture recover
|
|
123
179
|
capture channel
|
|
180
|
+
capture opening
|
|
181
|
+
capture token
|
|
124
182
|
if !res.ok
|
|
183
|
+
if recover and (res.status == 401 or res.status == 403) and res.headers != null and res.headers.get("x-lango-need-login") == "1"
|
|
184
|
+
return chain res.json()
|
|
185
|
+
then(body)
|
|
186
|
+
if !is_object(body) or !is_object(body.needLogin) or (body.error != "LoginRequired" and body.error != "ReauthenticationRequired") or body.needLogin.reason != body.error
|
|
187
|
+
throw "Invalid login challenge"
|
|
188
|
+
return {
|
|
189
|
+
needLogin: body.needLogin
|
|
190
|
+
}
|
|
191
|
+
if opening and res.status == 401 and token != null
|
|
192
|
+
if clearSavedToken()
|
|
193
|
+
throw new Error("Startup HTTP 401: saved token was rejected and cleared. Reload the page to start a new session.")
|
|
194
|
+
throw new Error("Startup HTTP 401: saved token was rejected but storage could not be cleared. Clear this site's local storage and reload.")
|
|
125
195
|
if !channel
|
|
126
196
|
throw "HTTP ${res.status}"
|
|
127
197
|
if res.status != 409
|
|
@@ -143,6 +213,7 @@ App:request(url, input, token, signal = null, channel = false)
|
|
|
143
213
|
if status == null
|
|
144
214
|
status = 200
|
|
145
215
|
return {
|
|
216
|
+
authChange: res.headers.get("x-lango-auth-change")
|
|
146
217
|
status: status
|
|
147
218
|
token: res.headers.get("x-lango-token")
|
|
148
219
|
body: body
|
|
@@ -158,16 +229,29 @@ App:request(url, input, token, signal = null, channel = false)
|
|
|
158
229
|
App:start()
|
|
159
230
|
token = null
|
|
160
231
|
try
|
|
161
|
-
|
|
232
|
+
@storageChange = @host.storage.getItem("lango.authChange")
|
|
233
|
+
if !is_string(@storageChange) or !@storageChange.startsWith("v1:")
|
|
234
|
+
@storageChange = null
|
|
235
|
+
token = null
|
|
236
|
+
if @storageChange != null
|
|
237
|
+
token = @host.storage.getItem("lango.token:${@storageChange}")
|
|
238
|
+
if token == null
|
|
239
|
+
token = @host.storage.getItem("lango.token")
|
|
162
240
|
catch error
|
|
163
241
|
token = null
|
|
164
|
-
return chain
|
|
242
|
+
return chain request("/", {}, token, null, false, true)
|
|
165
243
|
then(packet)
|
|
166
|
-
|
|
244
|
+
acceptEvents(packet.body)
|
|
167
245
|
if @events.clientErrorUrl != null
|
|
168
246
|
@reporter = new ErrorReporter(@this, @events.clientErrorUrl)
|
|
169
247
|
if @events.pingUrl != null
|
|
170
248
|
@heartbeat = new Heartbeat(@this, @host, @events.pingUrl)
|
|
249
|
+
if @externalStale
|
|
250
|
+
if @root == null
|
|
251
|
+
@root = new Form(@this)
|
|
252
|
+
@root.element = @host.mount
|
|
253
|
+
invalidateForm(@root)
|
|
254
|
+
return null
|
|
171
255
|
@root = new Form(@this, null, packet.token)
|
|
172
256
|
@root.element = @host.mount
|
|
173
257
|
@root.setToken(packet.token)
|
|
@@ -176,15 +260,22 @@ App:start()
|
|
|
176
260
|
if @heartbeat != null
|
|
177
261
|
@heartbeat.start()
|
|
178
262
|
return null
|
|
263
|
+
catch(problem)
|
|
264
|
+
if @externalStale
|
|
265
|
+
return null
|
|
266
|
+
throw problem
|
|
179
267
|
|
|
180
268
|
App:send(form, url, owner = null)
|
|
181
269
|
if @disposed or form.disposed
|
|
182
270
|
return Promise/reject("Form is disposed")
|
|
271
|
+
if form.stale or @externalStale
|
|
272
|
+
return Promise/reject("SessionChanged: reload the page")
|
|
183
273
|
pending = new Promise((resolve, reject)
|
|
184
274
|
capture form
|
|
185
275
|
capture url
|
|
186
276
|
capture owner
|
|
187
277
|
@queue.add({
|
|
278
|
+
authVersion: @authVersion
|
|
188
279
|
kind: "send"
|
|
189
280
|
form: form
|
|
190
281
|
url: url
|
|
@@ -201,6 +292,7 @@ App:deliver(form, action, owner, generation)
|
|
|
201
292
|
return Promise/resolve(null)
|
|
202
293
|
deferred = Promise/withResolvers()
|
|
203
294
|
@queue.add({
|
|
295
|
+
authVersion: @authVersion
|
|
204
296
|
kind: "delivery"
|
|
205
297
|
form: form
|
|
206
298
|
action: action
|
|
@@ -217,6 +309,7 @@ App:report(form, url, input, owner)
|
|
|
217
309
|
return Promise/resolve(null)
|
|
218
310
|
deferred = Promise/withResolvers()
|
|
219
311
|
@queue.add({
|
|
312
|
+
authVersion: @authVersion
|
|
220
313
|
kind: "report"
|
|
221
314
|
form: form
|
|
222
315
|
url: url
|
|
@@ -229,7 +322,7 @@ App:report(form, url, input, owner)
|
|
|
229
322
|
return deferred.promise
|
|
230
323
|
|
|
231
324
|
App:canPoll(form)
|
|
232
|
-
if @disposed or form.disposed or @pingJob != null
|
|
325
|
+
if @disposed or form.disposed or form.stale or @externalStale or @pingJob != null or @login != null
|
|
233
326
|
return false
|
|
234
327
|
for @active as job
|
|
235
328
|
if form.related(job.form)
|
|
@@ -251,12 +344,20 @@ App:resumePolls()
|
|
|
251
344
|
return null
|
|
252
345
|
|
|
253
346
|
App:drain()
|
|
254
|
-
if @
|
|
347
|
+
if @disposed
|
|
348
|
+
return null
|
|
349
|
+
if @pingJob != null and @login == null
|
|
255
350
|
if @active.length == 0 and !@pingJob.running
|
|
256
351
|
@pingJob.running = true
|
|
257
352
|
executePing(@pingJob)
|
|
258
353
|
return null
|
|
259
354
|
for @queue.slice() as job
|
|
355
|
+
if job.authVersion != @authVersion or job.form.stale or @externalStale
|
|
356
|
+
@queue.splice(@queue.indexOf(job), 1)
|
|
357
|
+
job.reject("SessionChanged: queued request cancelled")
|
|
358
|
+
continue
|
|
359
|
+
if @login != null and !@login.form.related(job.form)
|
|
360
|
+
continue
|
|
260
361
|
blocked = false
|
|
261
362
|
for @active as running
|
|
262
363
|
if job.form.related(running.form)
|
|
@@ -290,7 +391,9 @@ App:executeDelivery(job)
|
|
|
290
391
|
job.reject(error)
|
|
291
392
|
finally
|
|
292
393
|
capture job
|
|
293
|
-
@active.
|
|
394
|
+
index = @active.indexOf(job)
|
|
395
|
+
if index >= 0
|
|
396
|
+
@active.splice(index, 1)
|
|
294
397
|
drain()
|
|
295
398
|
|
|
296
399
|
App:ping()
|
|
@@ -331,6 +434,8 @@ App:execute(job)
|
|
|
331
434
|
capture job
|
|
332
435
|
if form.disposed
|
|
333
436
|
throw "Form is disposed"
|
|
437
|
+
if form.stale or @externalStale
|
|
438
|
+
throw "SessionChanged: reload the page"
|
|
334
439
|
if job.owner != null and !job.owner.active
|
|
335
440
|
return null
|
|
336
441
|
if job.kind == "report"
|
|
@@ -339,7 +444,7 @@ App:execute(job)
|
|
|
339
444
|
@renderer.waiting(form, true)
|
|
340
445
|
ready = form.prepareValue()
|
|
341
446
|
if ready == null
|
|
342
|
-
return
|
|
447
|
+
return sendInput(job, from_json(to_json(form.getValue())))
|
|
343
448
|
return chain ready
|
|
344
449
|
then(ignored)
|
|
345
450
|
capture form
|
|
@@ -348,15 +453,19 @@ App:execute(job)
|
|
|
348
453
|
throw "Form is disposed"
|
|
349
454
|
if job.owner != null and !job.owner.active
|
|
350
455
|
return null
|
|
351
|
-
return
|
|
456
|
+
return sendInput(job, from_json(to_json(form.getValue())))
|
|
352
457
|
then(packet)
|
|
353
458
|
capture form
|
|
354
459
|
capture job
|
|
460
|
+
if job.authVersion != @authVersion or form.stale or @externalStale
|
|
461
|
+
throw "SessionChanged: response discarded"
|
|
355
462
|
if packet != null and !form.disposed and (job.owner == null or job.owner.active)
|
|
356
463
|
if job.kind == "report"
|
|
357
464
|
form.setToken(packet.token)
|
|
358
465
|
else
|
|
359
466
|
form.handle(packet)
|
|
467
|
+
if form.stale or @externalStale
|
|
468
|
+
throw "SessionChanged: response discarded"
|
|
360
469
|
then(ignored)
|
|
361
470
|
capture job
|
|
362
471
|
job.resolve(null)
|
|
@@ -368,7 +477,9 @@ App:execute(job)
|
|
|
368
477
|
capture form
|
|
369
478
|
if job.kind == "send"
|
|
370
479
|
@renderer.waiting(form, false)
|
|
371
|
-
@active.
|
|
480
|
+
index = @active.indexOf(job)
|
|
481
|
+
if index >= 0
|
|
482
|
+
@active.splice(index, 1)
|
|
372
483
|
drain()
|
|
373
484
|
|
|
374
485
|
App:navigate(url, push = true)
|
|
@@ -429,8 +540,26 @@ App:selectTemplate(path)
|
|
|
429
540
|
|
|
430
541
|
App:command(form, cmd)
|
|
431
542
|
switch cmd.type
|
|
543
|
+
case "loginSatisfied"
|
|
544
|
+
finishLogin(form, cmd.userId)
|
|
545
|
+
case "cancelLogin"
|
|
546
|
+
if @login == null or !@login.form.related(form)
|
|
547
|
+
throw "cancelLogin requires the active login form"
|
|
548
|
+
@login.cancelled = true
|
|
432
549
|
case "values"
|
|
433
550
|
form.setValue(cmd.values)
|
|
551
|
+
case "addRow"
|
|
552
|
+
form.find(cmd.name).addRow(cmd.value)
|
|
553
|
+
case "insertRow"
|
|
554
|
+
form.find(cmd.name).insertRow(cmd.beforeIndex, cmd.value)
|
|
555
|
+
case "deleteRow"
|
|
556
|
+
form.find(cmd.name).deleteRow(cmd.index)
|
|
557
|
+
case "setRowValue"
|
|
558
|
+
form.find(cmd.name).setRowValue(cmd.index, cmd.value)
|
|
559
|
+
case "setRowData"
|
|
560
|
+
form.find(cmd.name).setRowData(cmd.index, cmd.value)
|
|
561
|
+
case "setCellValue"
|
|
562
|
+
form.find(cmd.name).setCellValue(cmd.index, cmd.column, cmd.value)
|
|
434
563
|
case "invalid"
|
|
435
564
|
form.find(cmd.name).setInvalid(cmd.message)
|
|
436
565
|
case "set"
|
|
@@ -493,6 +622,7 @@ App:command(form, cmd)
|
|
|
493
622
|
|
|
494
623
|
App:dispose()
|
|
495
624
|
@disposed = true
|
|
625
|
+
cancelLogin()
|
|
496
626
|
if @heartbeat != null
|
|
497
627
|
@heartbeat.dispose()
|
|
498
628
|
if @reporter != null
|
|
@@ -506,3 +636,219 @@ App:dispose()
|
|
|
506
636
|
release()
|
|
507
637
|
@resources = []
|
|
508
638
|
return null
|
|
639
|
+
|
|
640
|
+
App:sendInput(job, input)
|
|
641
|
+
form = job.form
|
|
642
|
+
recover = @login == null or !@login.form.related(form)
|
|
643
|
+
return chain request(job.url, input, form.token, null, false, false, recover)
|
|
644
|
+
then(packet)
|
|
645
|
+
capture job
|
|
646
|
+
capture input
|
|
647
|
+
if packet.needLogin == null
|
|
648
|
+
return packet
|
|
649
|
+
return resumeInput(job, input, packet.needLogin)
|
|
650
|
+
|
|
651
|
+
App:resumeInput(job, input, challenge)
|
|
652
|
+
return chain needLogin(job, challenge)
|
|
653
|
+
then(identity)
|
|
654
|
+
capture job
|
|
655
|
+
capture input
|
|
656
|
+
form = job.form
|
|
657
|
+
if form.disposed or form.stale or @externalStale or (job.owner != null and !job.owner.active)
|
|
658
|
+
throw "Pending login request is no longer active"
|
|
659
|
+
job.authVersion = @authVersion
|
|
660
|
+
return request(job.url, input, identity.token, null, false, false, false, identity.expected)
|
|
661
|
+
|
|
662
|
+
App:needLogin(job, challenge)
|
|
663
|
+
if @events.needLoginUrl == null
|
|
664
|
+
throw "Login is required but no needLogin event is configured"
|
|
665
|
+
session = @login
|
|
666
|
+
if session != null and session.originalToken != job.form.token
|
|
667
|
+
invalidateForm(job.form)
|
|
668
|
+
throw "SessionChanged: another form is awaiting login"
|
|
669
|
+
if session == null
|
|
670
|
+
deferred = Promise/withResolvers()
|
|
671
|
+
scope = new Form(@this, null, job.form.token)
|
|
672
|
+
session = {
|
|
673
|
+
form: scope
|
|
674
|
+
source: job.form
|
|
675
|
+
promise: deferred.promise
|
|
676
|
+
resolve: deferred.resolve
|
|
677
|
+
reject: deferred.reject
|
|
678
|
+
release: null
|
|
679
|
+
ready: null
|
|
680
|
+
cancelled: false
|
|
681
|
+
change: null
|
|
682
|
+
originalToken: job.form.token
|
|
683
|
+
}
|
|
684
|
+
chain session.promise
|
|
685
|
+
catch(problem)
|
|
686
|
+
return null
|
|
687
|
+
@login = session
|
|
688
|
+
pausePolls()
|
|
689
|
+
try
|
|
690
|
+
cancel = ()
|
|
691
|
+
cancelLogin()
|
|
692
|
+
session.release = @renderer.openLogin(scope, cancel)
|
|
693
|
+
chain post(@events.needLoginUrl, challenge, scope.token)
|
|
694
|
+
then(packet)
|
|
695
|
+
capture session
|
|
696
|
+
if @login == session and !session.form.disposed
|
|
697
|
+
session.form.handle(packet)
|
|
698
|
+
catch(problem)
|
|
699
|
+
capture session
|
|
700
|
+
if @login == session
|
|
701
|
+
cancelLogin(problem)
|
|
702
|
+
catch problem
|
|
703
|
+
cancelLogin(problem)
|
|
704
|
+
return chain session.promise
|
|
705
|
+
then(identity)
|
|
706
|
+
capture challenge
|
|
707
|
+
if challenge.userId != null and identity.userId != challenge.userId
|
|
708
|
+
for @forms.slice() as form
|
|
709
|
+
invalidateForm(form)
|
|
710
|
+
throw "IdentityChanged"
|
|
711
|
+
return {
|
|
712
|
+
token: identity.token
|
|
713
|
+
expected: challenge.userId
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
App:finishLogin(form, userId)
|
|
717
|
+
session = @login
|
|
718
|
+
if session == null or !session.form.related(form) or form.token == null
|
|
719
|
+
throw "loginSatisfied requires an active login form and token"
|
|
720
|
+
if @active.length == 0
|
|
721
|
+
throw "No request is waiting for login"
|
|
722
|
+
session.ready = {
|
|
723
|
+
token: form.token
|
|
724
|
+
userId: userId
|
|
725
|
+
}
|
|
726
|
+
return null
|
|
727
|
+
|
|
728
|
+
App:completeLogin(form)
|
|
729
|
+
session = @login
|
|
730
|
+
if session == null or !session.form.related(form)
|
|
731
|
+
return null
|
|
732
|
+
if session.cancelled
|
|
733
|
+
return cancelLogin()
|
|
734
|
+
if session.ready == null
|
|
735
|
+
return null
|
|
736
|
+
@login = null
|
|
737
|
+
identity = session.ready
|
|
738
|
+
change = session.change
|
|
739
|
+
if !is_string(change) or !change.startsWith("v1:")
|
|
740
|
+
change = "v1:${crypto/randomUUID()}"
|
|
741
|
+
commitAuthentication(session.source, session.originalToken, identity.token, change)
|
|
742
|
+
session.resolve(identity)
|
|
743
|
+
if session.release != null
|
|
744
|
+
release = session.release
|
|
745
|
+
release()
|
|
746
|
+
session.form.dispose()
|
|
747
|
+
drain()
|
|
748
|
+
return null
|
|
749
|
+
|
|
750
|
+
App:cancelLogin(problem = "LoginCancelled")
|
|
751
|
+
session = @login
|
|
752
|
+
if session == null
|
|
753
|
+
return null
|
|
754
|
+
@login = null
|
|
755
|
+
session.reject(problem)
|
|
756
|
+
if session.release != null
|
|
757
|
+
release = session.release
|
|
758
|
+
release()
|
|
759
|
+
session.form.dispose()
|
|
760
|
+
drain()
|
|
761
|
+
return null
|
|
762
|
+
|
|
763
|
+
App:loginScopeDisposed(form)
|
|
764
|
+
if @login != null and (@login.form == form or @login.source == form)
|
|
765
|
+
cancelLogin()
|
|
766
|
+
return null
|
|
767
|
+
|
|
768
|
+
App:acceptEvents(events)
|
|
769
|
+
if !is_object(events) or is_array(events)
|
|
770
|
+
throw "Startup events must be a map"
|
|
771
|
+
if events.needLoginUrl != null
|
|
772
|
+
checkUrl(events.needLoginUrl)
|
|
773
|
+
@events = events
|
|
774
|
+
return null
|
|
775
|
+
|
|
776
|
+
App:beginLoginResponse(form, packet)
|
|
777
|
+
if @login != null and @login.form.related(form)
|
|
778
|
+
@login.change = packet.authChange
|
|
779
|
+
@login.ready = null
|
|
780
|
+
@login.cancelled = false
|
|
781
|
+
return null
|
|
782
|
+
|
|
783
|
+
App:observeAuthentication(form, previous, packet)
|
|
784
|
+
change = packet.authChange
|
|
785
|
+
if @login != null and @login.form.related(form)
|
|
786
|
+
return null
|
|
787
|
+
if is_string(change) and change.startsWith("v1:") and !@authChanges.includes(change)
|
|
788
|
+
commitAuthentication(form, previous, packet.token, change)
|
|
789
|
+
return null
|
|
790
|
+
|
|
791
|
+
App:commitAuthentication(source, previous, token, change)
|
|
792
|
+
if @disposed or @authChanges.includes(change)
|
|
793
|
+
return null
|
|
794
|
+
previousChange = @storageChange
|
|
795
|
+
@storageChange = change
|
|
796
|
+
@authChanges.add(change)
|
|
797
|
+
if @authChanges.length > 64
|
|
798
|
+
@authChanges.shift()
|
|
799
|
+
@authVersion = @authVersion + 1
|
|
800
|
+
@committingAuthentication = true
|
|
801
|
+
for @forms.slice() as form
|
|
802
|
+
if form.disposed or form.stale
|
|
803
|
+
continue
|
|
804
|
+
if form == source or form.token == previous or form.token == token
|
|
805
|
+
form.setToken(token)
|
|
806
|
+
else
|
|
807
|
+
invalidateForm(form)
|
|
808
|
+
@committingAuthentication = false
|
|
809
|
+
try
|
|
810
|
+
@host.storage.setItem("lango.authChange", change)
|
|
811
|
+
if previousChange != null and @host.storage.removeItem != null
|
|
812
|
+
@host.storage.removeItem("lango.token:${previousChange}")
|
|
813
|
+
catch problem
|
|
814
|
+
return null
|
|
815
|
+
return null
|
|
816
|
+
|
|
817
|
+
App:externalAuthentication(change)
|
|
818
|
+
if @disposed or !is_string(change) or !change.startsWith("v1:") or @authChanges.includes(change)
|
|
819
|
+
return null
|
|
820
|
+
@authChanges.add(change)
|
|
821
|
+
if @authChanges.length > 64
|
|
822
|
+
@authChanges.shift()
|
|
823
|
+
@storageChange = change
|
|
824
|
+
@externalStale = true
|
|
825
|
+
@authVersion = @authVersion + 1
|
|
826
|
+
cancelLogin("SessionChanged: authentication changed in another tab")
|
|
827
|
+
if @heartbeat != null
|
|
828
|
+
@heartbeat.dispose()
|
|
829
|
+
if @root == null and @host.mount != null
|
|
830
|
+
@root = new Form(@this)
|
|
831
|
+
@root.element = @host.mount
|
|
832
|
+
for @forms.slice() as form
|
|
833
|
+
invalidateForm(form)
|
|
834
|
+
return null
|
|
835
|
+
|
|
836
|
+
App:invalidateForm(form)
|
|
837
|
+
if form.disposed or form.stale
|
|
838
|
+
return null
|
|
839
|
+
form.stale = true
|
|
840
|
+
form.activity.clear()
|
|
841
|
+
parent = form.parent
|
|
842
|
+
loop while parent != null
|
|
843
|
+
if parent.stale
|
|
844
|
+
return null
|
|
845
|
+
parent = parent.parent
|
|
846
|
+
if @renderer.sessionChanged != null
|
|
847
|
+
@renderer.sessionChanged(form)
|
|
848
|
+
return null
|
|
849
|
+
|
|
850
|
+
App:reloadSession()
|
|
851
|
+
if @host.reload == null
|
|
852
|
+
throw "Reload the page to continue"
|
|
853
|
+
@host.reload()
|
|
854
|
+
return null
|
package/src/control.lango
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./dimensions"
|
|
2
|
+
applyDimensions(element, props)
|
|
1
3
|
import js global document
|
|
2
4
|
import "./templates"
|
|
3
5
|
controlId()
|
|
@@ -20,6 +22,7 @@ export class Control(form, props, element)
|
|
|
20
22
|
Control(form, props, element)
|
|
21
23
|
@form = form
|
|
22
24
|
@element = element
|
|
25
|
+
applyDimensions(element, props)
|
|
23
26
|
@value = props.value
|
|
24
27
|
@release = []
|
|
25
28
|
@feedback = null
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import js global Number
|
|
2
|
+
|
|
3
|
+
export measure(value, unit)
|
|
4
|
+
export applyDimensions(element, props)
|
|
5
|
+
export applyLayout(element, props)
|
|
6
|
+
|
|
7
|
+
measure(value, unit)
|
|
8
|
+
if value == null or value == -1
|
|
9
|
+
return null
|
|
10
|
+
if !is_number(value) or !Number/isFinite(value) or value <= 0
|
|
11
|
+
throw "Control dimensions must be positive numbers or -1 for automatic sizing"
|
|
12
|
+
return "${value}${unit}"
|
|
13
|
+
|
|
14
|
+
applyDimensions(element, props)
|
|
15
|
+
width = measure(props.width, "ch")
|
|
16
|
+
height = measure(props.height, "lh")
|
|
17
|
+
if width != null
|
|
18
|
+
element.style.width = width
|
|
19
|
+
element.style.maxWidth = "100%"
|
|
20
|
+
element.style.boxSizing = "border-box"
|
|
21
|
+
if height != null
|
|
22
|
+
element.style.height = height
|
|
23
|
+
return null
|
|
24
|
+
|
|
25
|
+
applyLayout(element, props)
|
|
26
|
+
switch props.type
|
|
27
|
+
case "container"
|
|
28
|
+
fluid = props.fluid
|
|
29
|
+
if fluid == null
|
|
30
|
+
fluid = false
|
|
31
|
+
if !is_bool(fluid)
|
|
32
|
+
throw "Container fluid must be boolean"
|
|
33
|
+
if fluid
|
|
34
|
+
element.classList.add("container-fluid")
|
|
35
|
+
else
|
|
36
|
+
element.classList.add("container")
|
|
37
|
+
case "row"
|
|
38
|
+
element.classList.add("lango-row")
|
|
39
|
+
gap = props.gap
|
|
40
|
+
if gap == null
|
|
41
|
+
gap = "normal"
|
|
42
|
+
switch gap
|
|
43
|
+
case "small"
|
|
44
|
+
element.style.setProperty("--lango-gap", ".5rem")
|
|
45
|
+
case "normal"
|
|
46
|
+
element.style.setProperty("--lango-gap", "1rem")
|
|
47
|
+
case "large"
|
|
48
|
+
element.style.setProperty("--lango-gap", "1.5rem")
|
|
49
|
+
else
|
|
50
|
+
throw "Row gap must be small, normal or large"
|
|
51
|
+
case "col"
|
|
52
|
+
element.classList.add("lango-col")
|
|
53
|
+
basis = measure(props.width, "ch")
|
|
54
|
+
grow = props.grow
|
|
55
|
+
if grow == null
|
|
56
|
+
grow = basis == null
|
|
57
|
+
if !is_bool(grow)
|
|
58
|
+
throw "Col grow must be boolean"
|
|
59
|
+
if basis != null
|
|
60
|
+
element.style.setProperty("--lango-basis", basis)
|
|
61
|
+
if grow
|
|
62
|
+
element.style.setProperty("--lango-grow", "1")
|
|
63
|
+
else
|
|
64
|
+
element.style.setProperty("--lango-grow", "0")
|
|
65
|
+
return null
|
package/src/form.lango
CHANGED
|
@@ -13,6 +13,7 @@ export class Form(app, parent = null, token = null)
|
|
|
13
13
|
owned
|
|
14
14
|
inheritedNames
|
|
15
15
|
disposed
|
|
16
|
+
stale
|
|
16
17
|
element
|
|
17
18
|
resources
|
|
18
19
|
activity
|
|
@@ -44,6 +45,7 @@ Form(app, parent = null, token = null)
|
|
|
44
45
|
@owned = []
|
|
45
46
|
@inheritedNames = []
|
|
46
47
|
@disposed = false
|
|
48
|
+
@stale = false
|
|
47
49
|
@element = null
|
|
48
50
|
@resources = []
|
|
49
51
|
@activity = new Activities(@this)
|
|
@@ -105,7 +107,7 @@ Form:getValue()
|
|
|
105
107
|
|
|
106
108
|
Form:prepareValue()
|
|
107
109
|
pending = []
|
|
108
|
-
for @
|
|
110
|
+
for @owned as control
|
|
109
111
|
if control.prepareValue != null
|
|
110
112
|
ready = control.prepareValue()
|
|
111
113
|
if ready != null
|
|
@@ -145,8 +147,9 @@ Form:clearResources()
|
|
|
145
147
|
|
|
146
148
|
Form:setToken(token)
|
|
147
149
|
if token != null
|
|
150
|
+
if @app.saveToken(token) == false
|
|
151
|
+
return @this
|
|
148
152
|
@token = token
|
|
149
|
-
@app.saveToken(token)
|
|
150
153
|
if @app.heartbeat != null
|
|
151
154
|
@app.heartbeat.observe(token)
|
|
152
155
|
return @this
|
|
@@ -155,15 +158,21 @@ Form:send(url)
|
|
|
155
158
|
return @app.send(@this, url)
|
|
156
159
|
|
|
157
160
|
Form:handle(packet)
|
|
158
|
-
if @disposed
|
|
161
|
+
if @disposed or @stale
|
|
159
162
|
return null
|
|
163
|
+
previous = @token
|
|
164
|
+
@app.beginLoginResponse(@this, packet)
|
|
160
165
|
setToken(packet.token)
|
|
166
|
+
if @stale
|
|
167
|
+
return null
|
|
161
168
|
body = packet.body
|
|
162
169
|
if body.view != null
|
|
163
170
|
@app.renderer.show(@this, body.view)
|
|
164
171
|
if body.cmds != null
|
|
165
172
|
for body.cmds as cmd
|
|
166
173
|
@app.command(@this, cmd)
|
|
174
|
+
@app.completeLogin(@this)
|
|
175
|
+
@app.observeAuthentication(@this, previous, packet)
|
|
167
176
|
return null
|
|
168
177
|
|
|
169
178
|
Form:related(other)
|
|
@@ -183,6 +192,7 @@ Form:dispose()
|
|
|
183
192
|
if @disposed
|
|
184
193
|
return null
|
|
185
194
|
@disposed = true
|
|
195
|
+
@app.loginScopeDisposed(@this)
|
|
186
196
|
for @owned.slice() as control
|
|
187
197
|
control.dispose()
|
|
188
198
|
clearResources()
|