@lango-project/lango-client 0.2.0 → 0.4.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/LICENSE +1 -0
- package/NOTICE +5 -1
- package/README.md +571 -855
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +112 -19
- package/cli/.lango/vendor/i18next.LICENSE +21 -0
- package/cli/.lango/vendor/i18next.mjs +2434 -0
- package/cli/create.mjs +62 -0
- package/cli/create.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +112 -19
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/accordion.mjs +277 -0
- package/dist/accordion.mjs.map +1 -0
- package/dist/activities.mjs +185 -0
- package/dist/activities.mjs.map +1 -0
- package/dist/app.mjs +636 -0
- package/dist/app.mjs.map +1 -0
- package/dist/boot.mjs +24 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/bootstrap-LICENSE +21 -0
- package/dist/bootstrap.min.css +6 -0
- package/dist/bootstrap.min.css.map +1 -0
- package/dist/button.mjs +77 -0
- package/dist/button.mjs.map +1 -0
- package/dist/chip.mjs +134 -0
- package/dist/chip.mjs.map +1 -0
- package/dist/client.css +95 -0
- package/dist/collections.mjs +77 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/combo_box.mjs +408 -0
- package/dist/combo_box.mjs.map +1 -0
- package/dist/content.mjs +123 -0
- package/dist/content.mjs.map +1 -0
- package/dist/control.mjs +139 -0
- package/dist/control.mjs.map +1 -0
- package/dist/date_input.mjs +242 -0
- package/dist/date_input.mjs.map +1 -0
- package/dist/error_reporter.mjs +136 -0
- package/dist/error_reporter.mjs.map +1 -0
- package/dist/fields.mjs +454 -0
- package/dist/fields.mjs.map +1 -0
- package/dist/file_input.mjs +227 -0
- package/dist/file_input.mjs.map +1 -0
- package/dist/form.mjs +272 -0
- package/dist/form.mjs.map +1 -0
- package/dist/heartbeat.mjs +167 -254
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +18 -0
- package/dist/indicators.mjs +127 -0
- package/dist/indicators.mjs.map +1 -0
- package/dist/input_changes.mjs +58 -0
- package/dist/input_changes.mjs.map +1 -0
- package/dist/input_group.mjs +38 -0
- package/dist/input_group.mjs.map +1 -0
- package/dist/layouts.mjs +195 -0
- package/dist/layouts.mjs.map +1 -0
- package/dist/library.mjs +130 -775
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll.mjs +254 -0
- package/dist/longpoll.mjs.map +1 -0
- package/dist/main.mjs +138 -0
- package/dist/main.mjs.map +1 -0
- package/dist/markdown.mjs +61 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/menus.mjs +468 -0
- package/dist/menus.mjs.map +1 -0
- package/dist/navigation.mjs +260 -410
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +181 -0
- package/dist/numeric_input.mjs.map +1 -0
- package/dist/otp_input.mjs +113 -0
- package/dist/otp_input.mjs.map +1 -0
- package/dist/presentations.mjs +852 -0
- package/dist/presentations.mjs.map +1 -0
- package/dist/renderer.mjs +293 -0
- package/dist/renderer.mjs.map +1 -0
- package/dist/rich_content.mjs +99 -0
- package/dist/rich_content.mjs.map +1 -0
- package/dist/tables.mjs +369 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tabs.mjs +205 -0
- package/dist/tabs.mjs.map +1 -0
- package/dist/templates.mjs +46 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/vendor/DOMPurify-LICENSE +202 -0
- package/dist/vendor/dompurify.mjs +2540 -0
- package/dist/vendor/flatpickr-LICENSE.md +21 -0
- package/dist/vendor/flatpickr.min.css +13 -0
- package/dist/vendor/flatpickr.mjs +2340 -0
- package/dist/vendor/flatpickr.mjs.map +7 -0
- package/dist/vendor/marked-LICENSE.md +44 -0
- package/dist/vendor/marked.esm.js.map +7 -0
- package/dist/vendor/marked.mjs +85 -0
- package/dist/vendor/purify.es.mjs.map +1 -0
- package/dist/widgets.mjs +197 -0
- package/dist/widgets.mjs.map +1 -0
- package/docs/implementation.md +42 -0
- package/package.json +26 -40
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +508 -0
- package/src/boot.lango +12 -0
- package/src/button.lango +49 -0
- package/src/chip.lango +94 -0
- package/src/collections.lango +46 -0
- package/src/combo_box.lango +298 -0
- package/src/content.lango +75 -0
- package/src/control.lango +100 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/error_reporter.lango +95 -0
- package/src/fields.lango +327 -0
- package/src/file_input.lango +175 -0
- package/src/form.lango +195 -0
- package/src/heartbeat.lango +136 -199
- package/src/indicators.lango +94 -0
- package/src/input_changes.lango +33 -0
- package/src/input_group.lango +22 -0
- package/src/layouts.lango +137 -0
- package/src/library.lango +194 -571
- package/src/longpoll.lango +187 -0
- package/src/main.lango +109 -0
- package/src/markdown.lango +48 -0
- package/src/menus.lango +336 -0
- package/src/navigation.lango +209 -299
- package/src/numeric_input.lango +131 -0
- package/src/otp_input.lango +83 -0
- package/src/presentations.lango +617 -0
- package/src/renderer.lango +288 -0
- package/src/rich_content.lango +66 -0
- package/src/tables.lango +271 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +95 -0
- package/web/index.html +18 -0
- package/dist/application.mjs +0 -429
- package/dist/application.mjs.map +0 -1
- package/dist/coordinator.mjs +0 -91
- package/dist/coordinator.mjs.map +0 -1
- package/dist/demo.mjs +0 -110
- package/dist/demo.mjs.map +0 -1
- package/dist/demo_controls.mjs +0 -59
- package/dist/demo_controls.mjs.map +0 -1
- package/dist/errors.mjs +0 -201
- package/dist/errors.mjs.map +0 -1
- package/dist/form_state.mjs +0 -266
- package/dist/form_state.mjs.map +0 -1
- package/dist/inheritance.mjs +0 -240
- package/dist/inheritance.mjs.map +0 -1
- package/dist/input_values.mjs +0 -65
- package/dist/input_values.mjs.map +0 -1
- package/dist/node/.lango/xmldom/conventions.js +0 -429
- package/dist/node/.lango/xmldom/dom-parser.js +0 -591
- package/dist/node/.lango/xmldom/dom.js +0 -3759
- package/dist/node/.lango/xmldom/entities.js +0 -2171
- package/dist/node/.lango/xmldom/errors.js +0 -205
- package/dist/node/.lango/xmldom/grammar.js +0 -559
- package/dist/node/.lango/xmldom/index.js +0 -41
- package/dist/node/.lango/xmldom/package.json +0 -1
- package/dist/node/.lango/xmldom/sax.js +0 -983
- package/dist/node/.lango/xmldom.LICENSE.md +0 -8
- package/dist/node/browser_host.mjs +0 -351
- package/dist/node/browser_host.mjs.map +0 -1
- package/dist/node/create_app.mjs +0 -118
- package/dist/node/create_app.mjs.map +0 -1
- package/dist/presentation.mjs +0 -89
- package/dist/presentation.mjs.map +0 -1
- package/dist/protocol.mjs +0 -706
- package/dist/protocol.mjs.map +0 -1
- package/dist/session.mjs +0 -431
- package/dist/session.mjs.map +0 -1
- package/dist/tokens.mjs +0 -298
- package/dist/tokens.mjs.map +0 -1
- package/examples/contacts.lango +0 -302
- package/examples/contacts_flow.lango +0 -174
- package/examples/contacts_store.lango +0 -109
- package/examples/contacts_store_test.lango +0 -65
- package/examples/demo.css +0 -72
- package/examples/demo_test.lango +0 -356
- package/examples/index.html +0 -28
- package/examples/pages.lango +0 -180
- package/examples/server.lango +0 -189
- package/examples/worker.lango +0 -142
- package/src/application.lango +0 -327
- package/src/browser_host.lango +0 -276
- package/src/coordinator.lango +0 -57
- package/src/demo.lango +0 -110
- package/src/demo_controls.lango +0 -53
- package/src/errors.lango +0 -149
- package/src/errors_test.lango +0 -157
- package/src/form_state.lango +0 -168
- package/src/heartbeat_test.lango +0 -479
- package/src/inheritance.lango +0 -167
- package/src/input_values.lango +0 -37
- package/src/logout_test.lango +0 -564
- package/src/navigation_test.lango +0 -556
- package/src/presentation.lango +0 -55
- package/src/protocol.lango +0 -787
- package/src/renderer_test.lango +0 -1986
- package/src/session.lango +0 -313
- package/src/session_test.lango +0 -455
- package/src/tabs_test.lango +0 -216
- package/src/tokens.lango +0 -215
- package/template/.vscode/extensions.json +0 -3
- package/template/.vscode/settings.json +0 -9
- package/template/README.md +0 -40
- package/template/gitignore +0 -4
- package/template/package.json +0 -22
- package/template/public/app.css +0 -4
- package/template/public/index.html +0 -24
- package/template/src/client.lango +0 -78
- package/template/src/pages.lango +0 -55
- package/template/src/server.lango +0 -24
- package/template/src/worker.lango +0 -77
- package/template/test/app.lango +0 -9
- package/tools/create_app.lango +0 -88
- package/tools/create_app_test.lango +0 -43
- package/tools/starter_test.lango +0 -227
- /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
- /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
- /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
- /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
- /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
- /package/{dist → cli}/.lango/xmldom/index.js +0 -0
- /package/{dist → cli}/.lango/xmldom/package.json +0 -0
- /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
- /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
package/examples/server.lango
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import js "node:fs" as fs
|
|
2
|
-
import js "node:http" as http
|
|
3
|
-
import js "node:crypto" as crypto
|
|
4
|
-
import js global process
|
|
5
|
-
import js global fetch
|
|
6
|
-
import js "node:path" as path
|
|
7
|
-
import js "../../lango-api/dist/library.mjs" as api
|
|
8
|
-
|
|
9
|
-
import "./pages"
|
|
10
|
-
createPages()
|
|
11
|
-
|
|
12
|
-
export main(args)
|
|
13
|
-
|
|
14
|
-
global pages = createPages()
|
|
15
|
-
|
|
16
|
-
main(args)
|
|
17
|
-
fs.mkdirSync(".demo-server", {
|
|
18
|
-
recursive: true
|
|
19
|
-
})
|
|
20
|
-
keyFile = ".demo-server/jwt.key"
|
|
21
|
-
key = null
|
|
22
|
-
if fs.existsSync(keyFile)
|
|
23
|
-
key = fs.readFileSync(keyFile)
|
|
24
|
-
else
|
|
25
|
-
key = crypto/randomBytes(32)
|
|
26
|
-
fs.writeFileSync(keyFile, key, {
|
|
27
|
-
mode: 384
|
|
28
|
-
})
|
|
29
|
-
keysFile = path.resolve(".demo-server/keys.json")
|
|
30
|
-
fs.writeFileSync(keysFile, to_json({
|
|
31
|
-
demo: key.toString("base64")
|
|
32
|
-
}), {
|
|
33
|
-
mode: 384
|
|
34
|
-
})
|
|
35
|
-
host = new api/Host({
|
|
36
|
-
applicationName: "lango-demo"
|
|
37
|
-
appRoot: path.resolve(".")
|
|
38
|
-
stateDir: path.resolve(".demo-server")
|
|
39
|
-
mode: "server"
|
|
40
|
-
host: "127.0.0.1"
|
|
41
|
-
port: 8081
|
|
42
|
-
workers: {
|
|
43
|
-
application: path.resolve(".demo-server/worker.mjs")
|
|
44
|
-
workerFile: path.resolve("../lango-api/dist/worker_entry.mjs")
|
|
45
|
-
}
|
|
46
|
-
jwt: {
|
|
47
|
-
issuer: "lango-demo"
|
|
48
|
-
audience: "lango-demo-browser"
|
|
49
|
-
activeKeyId: "demo"
|
|
50
|
-
keysFile: keysFile
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
return host.start().then((apiServer)
|
|
54
|
-
capture host
|
|
55
|
-
return launchProxy(host)
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
launchProxy(host)
|
|
59
|
-
server = new http/Server((request, response)
|
|
60
|
-
serve(request, response)
|
|
61
|
-
)
|
|
62
|
-
server.once("close", ()
|
|
63
|
-
capture host
|
|
64
|
-
closeHost(host)
|
|
65
|
-
)
|
|
66
|
-
process.once("SIGINT", ()
|
|
67
|
-
capture server
|
|
68
|
-
server.close()
|
|
69
|
-
)
|
|
70
|
-
process.once("SIGTERM", ()
|
|
71
|
-
capture server
|
|
72
|
-
server.close()
|
|
73
|
-
)
|
|
74
|
-
server.listen(8080, "127.0.0.1")
|
|
75
|
-
println("Open http://localhost:8080/")
|
|
76
|
-
return server
|
|
77
|
-
|
|
78
|
-
serve(request, response)
|
|
79
|
-
if request.method == "GET" and request.url == "/assets/demo.css"
|
|
80
|
-
return stylesheet(request, response)
|
|
81
|
-
endpoints = ["/app/contacts/new", "/app/contacts/open", "/app/contacts/save", "/app/contacts/delete", "/app/save", "/app/preferences", "/app/url", "/_lango/start", "/_lango/ping", "/_lango/logout"]
|
|
82
|
-
if request.method == "POST" and endpoints.includes(request.url)
|
|
83
|
-
body = ""
|
|
84
|
-
authorization = request.headers.authorization
|
|
85
|
-
target = request.url
|
|
86
|
-
request.on("data", (chunk)
|
|
87
|
-
capture body
|
|
88
|
-
body = "${body}${chunk}"
|
|
89
|
-
)
|
|
90
|
-
request.on("end", ()
|
|
91
|
-
capture body
|
|
92
|
-
capture response
|
|
93
|
-
capture authorization
|
|
94
|
-
capture target
|
|
95
|
-
proxy(body, response, authorization, target)
|
|
96
|
-
)
|
|
97
|
-
return null
|
|
98
|
-
if request.method == "GET" and request.url == "/examples/index.html"
|
|
99
|
-
response.writeHead(302, {
|
|
100
|
-
Location: "/"
|
|
101
|
-
"Cache-Control": "no-store"
|
|
102
|
-
})
|
|
103
|
-
response.end()
|
|
104
|
-
return null
|
|
105
|
-
global pages
|
|
106
|
-
selected = null
|
|
107
|
-
if request.method == "GET"
|
|
108
|
-
try
|
|
109
|
-
selected = pages.match(request.url)
|
|
110
|
-
catch error
|
|
111
|
-
response.writeHead(400)
|
|
112
|
-
response.end("Invalid URL")
|
|
113
|
-
return null
|
|
114
|
-
if request.method == "GET" and (request.url == "/" or request.url.startsWith("/?") or selected != null)
|
|
115
|
-
response.writeHead(200, {
|
|
116
|
-
"Content-Type": "text/html; charset=utf-8"
|
|
117
|
-
"Cache-Control": "no-store"
|
|
118
|
-
})
|
|
119
|
-
response.end(fs.readFileSync("examples/index.html"))
|
|
120
|
-
return null
|
|
121
|
-
allowed = ["/examples/index.html", "/dist/demo.mjs", "/dist/demo_controls.mjs", "/dist/library.mjs", "/dist/presentation.mjs", "/dist/input_values.mjs", "/dist/form_state.mjs", "/dist/application.mjs", "/dist/session.mjs", "/dist/tokens.mjs", "/dist/heartbeat.mjs", "/dist/protocol.mjs", "/dist/inheritance.mjs", "/dist/coordinator.mjs", "/dist/navigation.mjs", "/dist/.lango/runtime.mjs", "/dist/.lango/bignumber.mjs"]
|
|
122
|
-
if request.method != "GET" or !allowed.includes(request.url)
|
|
123
|
-
response.writeHead(404)
|
|
124
|
-
response.end("Not found")
|
|
125
|
-
return null
|
|
126
|
-
contentType = "text/javascript; charset=utf-8"
|
|
127
|
-
if request.url == "/examples/index.html"
|
|
128
|
-
contentType = "text/html; charset=utf-8"
|
|
129
|
-
response.writeHead(200, {
|
|
130
|
-
"Content-Type": contentType
|
|
131
|
-
})
|
|
132
|
-
response.end(fs.readFileSync(".${request.url}"))
|
|
133
|
-
return null
|
|
134
|
-
|
|
135
|
-
stylesheet(request, response)
|
|
136
|
-
content = fs.readFileSync("examples/demo.css")
|
|
137
|
-
hash = crypto/createHash("sha256")
|
|
138
|
-
hash.update(content)
|
|
139
|
-
etag = "\"${hash.digest('hex')}\""
|
|
140
|
-
response.setHeader("Content-Type", "text/css; charset=utf-8")
|
|
141
|
-
response.setHeader("Cache-Control", "public, max-age=0, must-revalidate")
|
|
142
|
-
response.setHeader("ETag", etag)
|
|
143
|
-
if request.headers["if-none-match"] == etag
|
|
144
|
-
response.writeHead(304)
|
|
145
|
-
response.end()
|
|
146
|
-
return null
|
|
147
|
-
response.writeHead(200)
|
|
148
|
-
response.end(content)
|
|
149
|
-
return null
|
|
150
|
-
|
|
151
|
-
proxy(body, response, authorization, target)
|
|
152
|
-
headers = {
|
|
153
|
-
"Content-Type": "application/json"
|
|
154
|
-
}
|
|
155
|
-
if authorization != null
|
|
156
|
-
headers.Authorization = authorization
|
|
157
|
-
return fetch("http://127.0.0.1:8081${target}", {
|
|
158
|
-
method: "POST"
|
|
159
|
-
headers: headers
|
|
160
|
-
body: body
|
|
161
|
-
}).then((upstream)
|
|
162
|
-
capture response
|
|
163
|
-
return relay(upstream, response)
|
|
164
|
-
).catch((error)
|
|
165
|
-
capture response
|
|
166
|
-
response.end("{\"error\":\"DemoProxyFailed\"}")
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
relay(upstream, response)
|
|
170
|
-
headers = {
|
|
171
|
-
"Content-Type": "application/json"
|
|
172
|
-
}
|
|
173
|
-
token = upstream.headers.get("X-Lango-Token")
|
|
174
|
-
if token != null
|
|
175
|
-
headers["X-Lango-Token"] = token
|
|
176
|
-
cache = upstream.headers.get("Cache-Control")
|
|
177
|
-
if cache != null
|
|
178
|
-
headers["Cache-Control"] = cache
|
|
179
|
-
response.writeHead(upstream.status, headers)
|
|
180
|
-
return upstream.text().then((text)
|
|
181
|
-
capture response
|
|
182
|
-
response.end(text)
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
closeHost(host)
|
|
186
|
-
return host.close().catch((error)
|
|
187
|
-
context log
|
|
188
|
-
log.err("Demo API shutdown failed")
|
|
189
|
-
)
|
package/examples/worker.lango
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import js "../../lango-api/dist/library.mjs" as api
|
|
2
|
-
import js "../../lango-ui/dist/library.mjs" as ui
|
|
3
|
-
|
|
4
|
-
import "./pages"
|
|
5
|
-
createPages()
|
|
6
|
-
|
|
7
|
-
import "./contacts"
|
|
8
|
-
initializeContacts(options)
|
|
9
|
-
closeContacts()
|
|
10
|
-
newContact(input)
|
|
11
|
-
openContact(input)
|
|
12
|
-
saveContact(input)
|
|
13
|
-
deleteContact(input)
|
|
14
|
-
|
|
15
|
-
import js global RegExp
|
|
16
|
-
|
|
17
|
-
export createWorker(options)
|
|
18
|
-
|
|
19
|
-
global dispatcher = null
|
|
20
|
-
global pages = null
|
|
21
|
-
|
|
22
|
-
createWorker(options)
|
|
23
|
-
global dispatcher
|
|
24
|
-
global pages
|
|
25
|
-
pages = createPages()
|
|
26
|
-
dispatcher = new ui/Dispatcher(options.appRoot)
|
|
27
|
-
dispatcher.event({
|
|
28
|
-
path: "/app/save"
|
|
29
|
-
function: save
|
|
30
|
-
})
|
|
31
|
-
dispatcher.event({
|
|
32
|
-
path: "/app/preferences"
|
|
33
|
-
function: preferences
|
|
34
|
-
})
|
|
35
|
-
dispatcher.event({
|
|
36
|
-
path: "/app/url"
|
|
37
|
-
function: page
|
|
38
|
-
})
|
|
39
|
-
dispatcher.event({
|
|
40
|
-
path: "/app/contacts/new"
|
|
41
|
-
function: newContact
|
|
42
|
-
})
|
|
43
|
-
dispatcher.event({
|
|
44
|
-
path: "/app/contacts/open"
|
|
45
|
-
function: openContact
|
|
46
|
-
})
|
|
47
|
-
dispatcher.event({
|
|
48
|
-
path: "/app/contacts/save"
|
|
49
|
-
function: saveContact
|
|
50
|
-
})
|
|
51
|
-
dispatcher.event({
|
|
52
|
-
path: "/app/contacts/delete"
|
|
53
|
-
function: deleteContact
|
|
54
|
-
})
|
|
55
|
-
routes = new api/Routes()
|
|
56
|
-
routes.endpoint({
|
|
57
|
-
path: "/app/*"
|
|
58
|
-
function: handleEvent
|
|
59
|
-
anonymous: true
|
|
60
|
-
})
|
|
61
|
-
initializeContacts(options)
|
|
62
|
-
return {
|
|
63
|
-
close: closeContacts
|
|
64
|
-
routes: routes.values()
|
|
65
|
-
preload: [dispatcher, pages]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
handleEvent(input)
|
|
69
|
-
global dispatcher
|
|
70
|
-
context token
|
|
71
|
-
context response
|
|
72
|
-
context request
|
|
73
|
-
if !is_string(request.headers.authorization) or token == null or !is_string(token.clientId) or token.clientId == ""
|
|
74
|
-
response.status(401).send({
|
|
75
|
-
error: "BootstrapRequired"
|
|
76
|
-
})
|
|
77
|
-
return null
|
|
78
|
-
return dispatcher.handle(input)
|
|
79
|
-
|
|
80
|
-
save(input)
|
|
81
|
-
context form
|
|
82
|
-
if !validPreferences(input)
|
|
83
|
-
return null
|
|
84
|
-
email = form.email.value.trim()
|
|
85
|
-
pattern = new RegExp("^[^ @]+@[^ @]+[.][^ @]+$")
|
|
86
|
-
if !pattern.test(email) or email.length > 254
|
|
87
|
-
form.email.error = "Enter a valid email address."
|
|
88
|
-
return null
|
|
89
|
-
if email == "blocked@example.com"
|
|
90
|
-
form.email.error = "This email is unavailable in the demo."
|
|
91
|
-
return null
|
|
92
|
-
form.preferenceStatus.value = "Saved: country=${form.country.value}, updates=${form.subscribed.value}"
|
|
93
|
-
form.saveButton.enabled = false
|
|
94
|
-
form.saveButton.style = {
|
|
95
|
-
"background-color": "#64748b"
|
|
96
|
-
}
|
|
97
|
-
form.email.error = null
|
|
98
|
-
form.email.savedValue = email
|
|
99
|
-
form.country.savedValue = form.country.value
|
|
100
|
-
form.subscribed.savedValue = form.subscribed.value
|
|
101
|
-
return {
|
|
102
|
-
email: email
|
|
103
|
-
country: form.country.value
|
|
104
|
-
subscribed: form.subscribed.value
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
preferences(input)
|
|
108
|
-
context form
|
|
109
|
-
if !validPreferences(input)
|
|
110
|
-
return null
|
|
111
|
-
form.preferenceStatus.value = "Unsaved: country=${form.country.value}, updates=${form.subscribed.value}"
|
|
112
|
-
form.saveButton.enabled = true
|
|
113
|
-
form.saveButton.style = {
|
|
114
|
-
}
|
|
115
|
-
return null
|
|
116
|
-
|
|
117
|
-
validPreferences(input)
|
|
118
|
-
context response
|
|
119
|
-
values = input.values
|
|
120
|
-
countries = ["tr", "gb", ""]
|
|
121
|
-
country = values.country
|
|
122
|
-
valid = "country" in values and is_bool(values.subscribed) and is_string(values.email) and "saveButton" in values and "preferenceStatus" in values
|
|
123
|
-
if !valid or (country != null and !countries.includes(country))
|
|
124
|
-
response.status(400).send({
|
|
125
|
-
error: "InvalidPreferences"
|
|
126
|
-
})
|
|
127
|
-
return false
|
|
128
|
-
return true
|
|
129
|
-
|
|
130
|
-
page(input)
|
|
131
|
-
global pages
|
|
132
|
-
context form
|
|
133
|
-
context response
|
|
134
|
-
rendered = pages.render({
|
|
135
|
-
url: form.url.value
|
|
136
|
-
template: form.template.value
|
|
137
|
-
})
|
|
138
|
-
result = new ui/Response(input.formId, input.seqno)
|
|
139
|
-
result.replace(rendered.target, rendered.control)
|
|
140
|
-
result.value("template", rendered.template)
|
|
141
|
-
response.send(result.result())
|
|
142
|
-
return null
|
package/src/application.lango
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import js global Promise
|
|
2
|
-
import "./library"
|
|
3
|
-
mount(document, root, definition, types = null)
|
|
4
|
-
class Renderer
|
|
5
|
-
class Binding
|
|
6
|
-
class Types
|
|
7
|
-
import "./session"
|
|
8
|
-
class Session
|
|
9
|
-
import "./tokens"
|
|
10
|
-
browserTokenStore(key = "lango:last-token")
|
|
11
|
-
import "./heartbeat"
|
|
12
|
-
class Heartbeat
|
|
13
|
-
import "./inheritance"
|
|
14
|
-
inheritedControls(form, parent)
|
|
15
|
-
inheritanceResources(path, parentPath, spec)
|
|
16
|
-
import "./coordinator"
|
|
17
|
-
class Coordinator
|
|
18
|
-
|
|
19
|
-
export class Application
|
|
20
|
-
properties
|
|
21
|
-
control
|
|
22
|
-
methods
|
|
23
|
-
reconcile()
|
|
24
|
-
session(formId)
|
|
25
|
-
dispose()
|
|
26
|
-
logout()
|
|
27
|
-
pause()
|
|
28
|
-
revokeSession()
|
|
29
|
-
rememberRevocation(previousToken)
|
|
30
|
-
restartAnonymous()
|
|
31
|
-
resume(token)
|
|
32
|
-
finishLogout()
|
|
33
|
-
createHeartbeat()
|
|
34
|
-
controlsFor(form)
|
|
35
|
-
isDirty()
|
|
36
|
-
confirmDiscard(window)
|
|
37
|
-
|
|
38
|
-
Application(document, root, definition, options = null)
|
|
39
|
-
if options == null
|
|
40
|
-
options = {
|
|
41
|
-
}
|
|
42
|
-
types = options.types
|
|
43
|
-
if types == null
|
|
44
|
-
types = new Types()
|
|
45
|
-
@control = mount(document, root, definition, types)
|
|
46
|
-
@renderer = new Renderer(document, types)
|
|
47
|
-
@transport = options.transport
|
|
48
|
-
@errors = options.errors
|
|
49
|
-
@tokens = options.tokens
|
|
50
|
-
if @tokens == null
|
|
51
|
-
key = options.storageKey
|
|
52
|
-
if key == null
|
|
53
|
-
key = "lango:last-token"
|
|
54
|
-
@tokens = browserTokenStore(key)
|
|
55
|
-
if options.bootstrapPath != null
|
|
56
|
-
@tokens.initialize(options.bootstrapPath)
|
|
57
|
-
@pageToken = @tokens.latest()
|
|
58
|
-
@bindings = []
|
|
59
|
-
@coordinator = new Coordinator()
|
|
60
|
-
@disposed = false
|
|
61
|
-
@window = options.window
|
|
62
|
-
@unload = null
|
|
63
|
-
@paused = false
|
|
64
|
-
@logout = null
|
|
65
|
-
@revoked = false
|
|
66
|
-
@restartToken = null
|
|
67
|
-
@bootstrapPath = options.bootstrapPath
|
|
68
|
-
if @bootstrapPath == null
|
|
69
|
-
@bootstrapPath = "/_lango/start"
|
|
70
|
-
@logoutPath = options.logoutPath
|
|
71
|
-
if @logoutPath == null
|
|
72
|
-
@logoutPath = "/_lango/logout"
|
|
73
|
-
@heartbeat = null
|
|
74
|
-
pingEnabled = options.pingEnabled
|
|
75
|
-
if pingEnabled == null
|
|
76
|
-
pingEnabled = options.bootstrapPath != null or options.pingPath != null
|
|
77
|
-
if !is_bool(pingEnabled)
|
|
78
|
-
throw "UiPingEnabledMustBeBoolean"
|
|
79
|
-
@pingEnabled = pingEnabled
|
|
80
|
-
@heartbeatOptions = {
|
|
81
|
-
path: options.pingPath
|
|
82
|
-
idleMs: options.pingIdleMs
|
|
83
|
-
transport: options.pingTransport
|
|
84
|
-
}
|
|
85
|
-
createHeartbeat()
|
|
86
|
-
reconcile()
|
|
87
|
-
if @heartbeat != null
|
|
88
|
-
@heartbeat.start()
|
|
89
|
-
observeStartup(@heartbeat, @tokens)
|
|
90
|
-
if @window != null
|
|
91
|
-
unload = (event)
|
|
92
|
-
if isDirty()
|
|
93
|
-
event.preventDefault()
|
|
94
|
-
event.returnValue = ""
|
|
95
|
-
@unload = unload
|
|
96
|
-
@window.addEventListener("beforeunload", unload)
|
|
97
|
-
|
|
98
|
-
Application:createHeartbeat()
|
|
99
|
-
if @pingEnabled
|
|
100
|
-
@heartbeat = new Heartbeat(@heartbeatOptions)
|
|
101
|
-
return null
|
|
102
|
-
|
|
103
|
-
Application:session(formId)
|
|
104
|
-
id = formId
|
|
105
|
-
if is_array(formId)
|
|
106
|
-
id = managedFormId(formId)
|
|
107
|
-
for @bindings as entry
|
|
108
|
-
if entry.formId == id
|
|
109
|
-
return entry.session
|
|
110
|
-
return null
|
|
111
|
-
|
|
112
|
-
Application:reconcile()
|
|
113
|
-
if @disposed or @paused
|
|
114
|
-
return null
|
|
115
|
-
forms = []
|
|
116
|
-
collectForms(@control, [], forms)
|
|
117
|
-
for forms as form
|
|
118
|
-
form.resources = inheritanceResources(form.path, form.parentPath, form.control.inherit)
|
|
119
|
-
retained = []
|
|
120
|
-
for @bindings as entry
|
|
121
|
-
if retainsForm(forms, entry)
|
|
122
|
-
retained.add(entry)
|
|
123
|
-
else
|
|
124
|
-
entry.binding.dispose()
|
|
125
|
-
entry.session.dispose()
|
|
126
|
-
@bindings = retained
|
|
127
|
-
for forms as form
|
|
128
|
-
if not containsForm(@bindings, form.control)
|
|
129
|
-
session = new Session({
|
|
130
|
-
formId: form.formId
|
|
131
|
-
controls: form.control.controls
|
|
132
|
-
root: form.control.element
|
|
133
|
-
effects: @renderer
|
|
134
|
-
transport: @transport
|
|
135
|
-
lifecycle: @this
|
|
136
|
-
tokens: @tokens
|
|
137
|
-
heartbeat: @heartbeat
|
|
138
|
-
coordinator: @coordinator
|
|
139
|
-
resources: form.resources
|
|
140
|
-
form: form.control
|
|
141
|
-
parent: form.parent
|
|
142
|
-
window: @window
|
|
143
|
-
seedFromBootstrap: true
|
|
144
|
-
seedToken: @pageToken
|
|
145
|
-
})
|
|
146
|
-
binding = new Binding(form.control, session, @errors)
|
|
147
|
-
@bindings.add({
|
|
148
|
-
formId: form.formId
|
|
149
|
-
control: form.control
|
|
150
|
-
parent: form.parent
|
|
151
|
-
session: session
|
|
152
|
-
binding: binding
|
|
153
|
-
})
|
|
154
|
-
if @heartbeat != null
|
|
155
|
-
sessions = []
|
|
156
|
-
for @bindings as entry
|
|
157
|
-
sessions.add(entry.session)
|
|
158
|
-
@heartbeat.sessions(sessions)
|
|
159
|
-
return null
|
|
160
|
-
|
|
161
|
-
Application:controlsFor(form)
|
|
162
|
-
for @bindings as entry
|
|
163
|
-
if entry.control == form
|
|
164
|
-
return inheritedControls(form, entry.parent)
|
|
165
|
-
throw "UiSessionDisposed"
|
|
166
|
-
|
|
167
|
-
Application:dispose()
|
|
168
|
-
if @disposed
|
|
169
|
-
return null
|
|
170
|
-
@disposed = true
|
|
171
|
-
if @window != null
|
|
172
|
-
@window.removeEventListener("beforeunload", @unload)
|
|
173
|
-
if @paused and @tokens.cancelInitialization != null
|
|
174
|
-
@tokens.cancelInitialization()
|
|
175
|
-
if @heartbeat != null
|
|
176
|
-
@heartbeat.dispose()
|
|
177
|
-
for @bindings as entry
|
|
178
|
-
entry.binding.dispose()
|
|
179
|
-
entry.session.dispose()
|
|
180
|
-
@bindings = []
|
|
181
|
-
@renderer.release(@control)
|
|
182
|
-
return null
|
|
183
|
-
|
|
184
|
-
Application:isDirty()
|
|
185
|
-
if @disposed
|
|
186
|
-
return false
|
|
187
|
-
for @bindings as entry
|
|
188
|
-
if entry.session.isDirty()
|
|
189
|
-
return true
|
|
190
|
-
return false
|
|
191
|
-
|
|
192
|
-
Application:confirmDiscard(window)
|
|
193
|
-
if !isDirty()
|
|
194
|
-
return true
|
|
195
|
-
return window.confirm("You have unsaved changes. Discard them?")
|
|
196
|
-
|
|
197
|
-
Application:logout()
|
|
198
|
-
if @disposed
|
|
199
|
-
throw "UiApplicationDisposed"
|
|
200
|
-
if @logout != null
|
|
201
|
-
return @logout
|
|
202
|
-
if @tokens.logout == null or @tokens.cancelInitialization == null
|
|
203
|
-
throw "UiLogoutRequiresTokenStore"
|
|
204
|
-
pause()
|
|
205
|
-
ready = Promise/resolve()
|
|
206
|
-
revoked = ready.then(()
|
|
207
|
-
return revokeSession()
|
|
208
|
-
)
|
|
209
|
-
restarted = revoked.then(()
|
|
210
|
-
return restartAnonymous()
|
|
211
|
-
)
|
|
212
|
-
work = restarted.then((token)
|
|
213
|
-
return resume(token)
|
|
214
|
-
)
|
|
215
|
-
pending = work.finally(()
|
|
216
|
-
finishLogout()
|
|
217
|
-
)
|
|
218
|
-
@logout = pending
|
|
219
|
-
return pending
|
|
220
|
-
|
|
221
|
-
Application:pause()
|
|
222
|
-
@paused = true
|
|
223
|
-
if @heartbeat != null
|
|
224
|
-
@heartbeat.dispose()
|
|
225
|
-
for @bindings as entry
|
|
226
|
-
entry.binding.dispose()
|
|
227
|
-
entry.session.dispose()
|
|
228
|
-
@bindings = []
|
|
229
|
-
@control.element.inert = true
|
|
230
|
-
@control.element.setAttribute("aria-busy", "true")
|
|
231
|
-
return null
|
|
232
|
-
|
|
233
|
-
Application:revokeSession()
|
|
234
|
-
if @disposed
|
|
235
|
-
throw "UiApplicationDisposed"
|
|
236
|
-
if @revoked
|
|
237
|
-
return null
|
|
238
|
-
return @tokens.logout(@logoutPath).then((previousToken)
|
|
239
|
-
rememberRevocation(previousToken)
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
Application:rememberRevocation(previousToken)
|
|
243
|
-
@revoked = true
|
|
244
|
-
@restartToken = previousToken
|
|
245
|
-
return null
|
|
246
|
-
|
|
247
|
-
Application:restartAnonymous()
|
|
248
|
-
if @disposed
|
|
249
|
-
throw "UiApplicationDisposed"
|
|
250
|
-
return @tokens.initialize(@bootstrapPath, @restartToken)
|
|
251
|
-
|
|
252
|
-
Application:resume(token)
|
|
253
|
-
if @disposed
|
|
254
|
-
throw "UiApplicationDisposed"
|
|
255
|
-
@revoked = false
|
|
256
|
-
@restartToken = null
|
|
257
|
-
@pageToken = token
|
|
258
|
-
@paused = false
|
|
259
|
-
createHeartbeat()
|
|
260
|
-
reconcile()
|
|
261
|
-
@control.element.inert = false
|
|
262
|
-
@control.element.setAttribute("aria-busy", "false")
|
|
263
|
-
if @heartbeat != null
|
|
264
|
-
@heartbeat.start()
|
|
265
|
-
return token
|
|
266
|
-
|
|
267
|
-
Application:finishLogout()
|
|
268
|
-
@logout = null
|
|
269
|
-
return null
|
|
270
|
-
|
|
271
|
-
containsForm(forms, control)
|
|
272
|
-
for forms as form
|
|
273
|
-
if form.control == control
|
|
274
|
-
return true
|
|
275
|
-
return false
|
|
276
|
-
|
|
277
|
-
retainsForm(forms, entry)
|
|
278
|
-
for forms as form
|
|
279
|
-
if form.control == entry.control and form.formId == entry.formId and form.parent == entry.parent
|
|
280
|
-
return true
|
|
281
|
-
return false
|
|
282
|
-
|
|
283
|
-
collectForms(control, parentPath, forms, parentForm = null, parentFormPath = null)
|
|
284
|
-
path = parentPath.slice()
|
|
285
|
-
nearest = parentForm
|
|
286
|
-
nearestPath = parentFormPath
|
|
287
|
-
if control.name != null and control.name != ""
|
|
288
|
-
path.add(control.name)
|
|
289
|
-
if control.element.langoFormRoot == true
|
|
290
|
-
if control.name == null or control.name == ""
|
|
291
|
-
throw "UiManagedFormRequiresName"
|
|
292
|
-
formId = managedFormId(path)
|
|
293
|
-
for forms as existing
|
|
294
|
-
if existing.formId == formId
|
|
295
|
-
throw "UiDuplicateFormPath"
|
|
296
|
-
forms.add({
|
|
297
|
-
formId: formId
|
|
298
|
-
control: control
|
|
299
|
-
path: path
|
|
300
|
-
parent: parentForm
|
|
301
|
-
parentPath: parentFormPath
|
|
302
|
-
})
|
|
303
|
-
nearest = control
|
|
304
|
-
nearestPath = path
|
|
305
|
-
if is_array(control.controls)
|
|
306
|
-
for control.controls as child
|
|
307
|
-
collectForms(child, path, forms, nearest, nearestPath)
|
|
308
|
-
return null
|
|
309
|
-
|
|
310
|
-
managedFormId(path)
|
|
311
|
-
if path.length == 1
|
|
312
|
-
return path[0]
|
|
313
|
-
return to_json(path)
|
|
314
|
-
|
|
315
|
-
observeStartup(heartbeat, tokens)
|
|
316
|
-
if tokens.ready == null
|
|
317
|
-
return null
|
|
318
|
-
ready = tokens.ready()
|
|
319
|
-
observed = ready.then(()
|
|
320
|
-
capture heartbeat
|
|
321
|
-
heartbeat.activity()
|
|
322
|
-
)
|
|
323
|
-
observed.catch((error)
|
|
324
|
-
capture heartbeat
|
|
325
|
-
heartbeat.activity()
|
|
326
|
-
)
|
|
327
|
-
return null
|