@lango-project/lango-client 0.0.0-stage → 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/LICENSE +200 -0
- package/NOTICE +2 -0
- package/README.md +877 -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 +792 -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 +431 -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 +302 -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 +72 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +28 -0
- package/examples/pages.lango +180 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +64 -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 +571 -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 +1986 -0
- package/src/session.lango +313 -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 +40 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +4 -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/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import js global Promise
|
|
2
|
+
import js global URL
|
|
3
|
+
import js global crypto
|
|
4
|
+
|
|
5
|
+
export class Navigation
|
|
6
|
+
properties
|
|
7
|
+
url
|
|
8
|
+
methods
|
|
9
|
+
start()
|
|
10
|
+
navigate(url, replace = false)
|
|
11
|
+
refresh()
|
|
12
|
+
idle()
|
|
13
|
+
dispose()
|
|
14
|
+
|
|
15
|
+
Navigation(window, options)
|
|
16
|
+
if !is_object(options) or !is_kindof(options.onUrl, Function)
|
|
17
|
+
throw "UiNavigationRequiresUrlHandler"
|
|
18
|
+
@window = window
|
|
19
|
+
@document = window.document
|
|
20
|
+
@onUrl = options.onUrl
|
|
21
|
+
@errors = options.errors
|
|
22
|
+
@redirect = options.rootRedirect
|
|
23
|
+
@guard = options.beforeNavigate
|
|
24
|
+
if @guard != null and !is_kindof(@guard, Function)
|
|
25
|
+
throw "UiNavigationGuardRequiresFunction"
|
|
26
|
+
@owner = crypto/randomUUID()
|
|
27
|
+
@position = 0
|
|
28
|
+
@restoring = false
|
|
29
|
+
@started = false
|
|
30
|
+
@disposed = false
|
|
31
|
+
@last = null
|
|
32
|
+
@url = null
|
|
33
|
+
@initial = null
|
|
34
|
+
@tail = Promise/resolve()
|
|
35
|
+
@click = null
|
|
36
|
+
@pop = null
|
|
37
|
+
@hash = null
|
|
38
|
+
if @redirect != null
|
|
39
|
+
parseUrl(@redirect)
|
|
40
|
+
|
|
41
|
+
Navigation:parseUrl(value)
|
|
42
|
+
if !is_string(value) or value == "" or value.includes("\\")
|
|
43
|
+
throw "UiNavigationRequiresSameOriginUrl"
|
|
44
|
+
location = @window.location
|
|
45
|
+
target = new URL(value, location.href)
|
|
46
|
+
if target.origin != location.origin or (target.protocol != "http:" and target.protocol != "https:") or target.username != "" or target.password != ""
|
|
47
|
+
throw "UiNavigationRequiresSameOriginUrl"
|
|
48
|
+
return target
|
|
49
|
+
|
|
50
|
+
localUrl(target)
|
|
51
|
+
return "${target.pathname}${target.search}${target.hash}"
|
|
52
|
+
|
|
53
|
+
Navigation:start()
|
|
54
|
+
if @disposed
|
|
55
|
+
throw "UiNavigationDisposed"
|
|
56
|
+
if @started
|
|
57
|
+
return @initial
|
|
58
|
+
location = @window.location
|
|
59
|
+
if location.pathname == "/" and @redirect != null
|
|
60
|
+
target = parseUrl(@redirect)
|
|
61
|
+
if target.search == ""
|
|
62
|
+
target.search = location.search
|
|
63
|
+
if target.hash == ""
|
|
64
|
+
target.hash = location.hash
|
|
65
|
+
@window.history.replaceState(null, "", localUrl(target))
|
|
66
|
+
@started = true
|
|
67
|
+
@window.history.replaceState(historyState(0, localUrl(@window.location)), "", localUrl(@window.location))
|
|
68
|
+
click = (event)
|
|
69
|
+
clickEvent(event)
|
|
70
|
+
pop = (event)
|
|
71
|
+
historyEvent("history")
|
|
72
|
+
hash = (event)
|
|
73
|
+
historyEvent("hash")
|
|
74
|
+
@click = click
|
|
75
|
+
@pop = pop
|
|
76
|
+
@hash = hash
|
|
77
|
+
@document.addEventListener("click", click)
|
|
78
|
+
@window.addEventListener("popstate", pop)
|
|
79
|
+
@window.addEventListener("hashchange", hash)
|
|
80
|
+
@initial = notify("start")
|
|
81
|
+
return @initial
|
|
82
|
+
|
|
83
|
+
Navigation:navigate(url, replace = false)
|
|
84
|
+
if @disposed
|
|
85
|
+
throw "UiNavigationDisposed"
|
|
86
|
+
if !@started
|
|
87
|
+
throw "UiNavigationNotStarted"
|
|
88
|
+
if @restoring
|
|
89
|
+
throw "UiNavigationRestoringHistory"
|
|
90
|
+
if !is_bool(replace)
|
|
91
|
+
throw "UiNavigationReplaceMustBeBoolean"
|
|
92
|
+
target = parseUrl(url)
|
|
93
|
+
path = localUrl(target)
|
|
94
|
+
if path == localUrl(@window.location)
|
|
95
|
+
if @last == null
|
|
96
|
+
if !canNavigate(path, "navigate")
|
|
97
|
+
return Promise/resolve(false)
|
|
98
|
+
return notify("navigate")
|
|
99
|
+
return Promise/resolve(null)
|
|
100
|
+
if !canNavigate(path, "navigate")
|
|
101
|
+
return Promise/resolve(false)
|
|
102
|
+
if replace
|
|
103
|
+
@window.history.replaceState(historyState(@position, path), "", path)
|
|
104
|
+
else
|
|
105
|
+
@position++
|
|
106
|
+
@window.history.pushState(historyState(@position, path), "", path)
|
|
107
|
+
return notify("navigate")
|
|
108
|
+
|
|
109
|
+
Navigation:canNavigate(path, source)
|
|
110
|
+
if @guard == null
|
|
111
|
+
return true
|
|
112
|
+
callback = @guard
|
|
113
|
+
result = callback({
|
|
114
|
+
url: path
|
|
115
|
+
source: source
|
|
116
|
+
})
|
|
117
|
+
if !is_bool(result)
|
|
118
|
+
if result != null and is_kindof(result.then, Function)
|
|
119
|
+
recovered(Promise/resolve(result))
|
|
120
|
+
throw "UiNavigationGuardMustReturnBoolean"
|
|
121
|
+
return result
|
|
122
|
+
|
|
123
|
+
Navigation:historyState(position, path)
|
|
124
|
+
result = {
|
|
125
|
+
}
|
|
126
|
+
previous = @window.history.state
|
|
127
|
+
if is_object(previous) and !is_array(previous)
|
|
128
|
+
for previous as name: value
|
|
129
|
+
result[name] = value
|
|
130
|
+
else
|
|
131
|
+
if previous != null
|
|
132
|
+
result.previousState = previous
|
|
133
|
+
result["__langoNavigation"] = {
|
|
134
|
+
owner: @owner
|
|
135
|
+
index: position
|
|
136
|
+
url: path
|
|
137
|
+
}
|
|
138
|
+
return result
|
|
139
|
+
|
|
140
|
+
Navigation:historyEvent(source)
|
|
141
|
+
try
|
|
142
|
+
moveHistory(source)
|
|
143
|
+
catch error
|
|
144
|
+
report(error)
|
|
145
|
+
return null
|
|
146
|
+
|
|
147
|
+
Navigation:moveHistory(source)
|
|
148
|
+
path = localUrl(@window.location)
|
|
149
|
+
state = @window.history.state
|
|
150
|
+
marker = null
|
|
151
|
+
if state != null
|
|
152
|
+
marker = state["__langoNavigation"]
|
|
153
|
+
if @restoring
|
|
154
|
+
if path == @url and marker != null and marker.owner == @owner and marker.index == @position
|
|
155
|
+
@restoring = false
|
|
156
|
+
return null
|
|
157
|
+
if path == @url
|
|
158
|
+
if marker != null and marker.owner == @owner
|
|
159
|
+
@position = marker.index
|
|
160
|
+
return null
|
|
161
|
+
position = @position + 1
|
|
162
|
+
if marker != null and marker.owner == @owner and marker.url == path
|
|
163
|
+
position = marker.index
|
|
164
|
+
allowed = false
|
|
165
|
+
try
|
|
166
|
+
allowed = canNavigate(path, source)
|
|
167
|
+
catch error
|
|
168
|
+
restoreHistory(position)
|
|
169
|
+
throw error
|
|
170
|
+
if !allowed
|
|
171
|
+
restoreHistory(position)
|
|
172
|
+
return null
|
|
173
|
+
@position = position
|
|
174
|
+
@window.history.replaceState(historyState(position, path), "", path)
|
|
175
|
+
observe(notify(source))
|
|
176
|
+
return null
|
|
177
|
+
|
|
178
|
+
Navigation:restoreHistory(position)
|
|
179
|
+
if position == @position
|
|
180
|
+
@window.history.replaceState(historyState(@position, @url), "", @url)
|
|
181
|
+
return null
|
|
182
|
+
@restoring = true
|
|
183
|
+
@window.history.go(@position - position)
|
|
184
|
+
return null
|
|
185
|
+
|
|
186
|
+
Navigation:notify(source)
|
|
187
|
+
if @disposed
|
|
188
|
+
return Promise/resolve(null)
|
|
189
|
+
path = localUrl(@window.location)
|
|
190
|
+
@url = path
|
|
191
|
+
if path == @last
|
|
192
|
+
return Promise/resolve(null)
|
|
193
|
+
@last = path
|
|
194
|
+
work = deliver(@tail, {
|
|
195
|
+
url: path
|
|
196
|
+
source: source
|
|
197
|
+
})
|
|
198
|
+
@tail = recovered(work)
|
|
199
|
+
return work
|
|
200
|
+
|
|
201
|
+
Navigation:refresh()
|
|
202
|
+
if @disposed
|
|
203
|
+
throw "UiNavigationDisposed"
|
|
204
|
+
if !@started
|
|
205
|
+
throw "UiNavigationNotStarted"
|
|
206
|
+
if @restoring
|
|
207
|
+
throw "UiNavigationRestoringHistory"
|
|
208
|
+
if !canNavigate(localUrl(@window.location), "refresh")
|
|
209
|
+
return Promise/resolve(false)
|
|
210
|
+
@last = null
|
|
211
|
+
return notify("refresh")
|
|
212
|
+
|
|
213
|
+
Navigation:deliver(ready, event)
|
|
214
|
+
return ready.then(()
|
|
215
|
+
capture event
|
|
216
|
+
if @disposed
|
|
217
|
+
return null
|
|
218
|
+
callback = @onUrl
|
|
219
|
+
return callback(event)
|
|
220
|
+
).catch((error)
|
|
221
|
+
capture event
|
|
222
|
+
if @last == event.url
|
|
223
|
+
@last = null
|
|
224
|
+
throw error
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
Navigation:observe(work)
|
|
228
|
+
work.catch((error)
|
|
229
|
+
report(error)
|
|
230
|
+
)
|
|
231
|
+
return null
|
|
232
|
+
|
|
233
|
+
Navigation:report(error)
|
|
234
|
+
if @disposed
|
|
235
|
+
return null
|
|
236
|
+
if @errors != null
|
|
237
|
+
@errors.error(error)
|
|
238
|
+
else
|
|
239
|
+
context log
|
|
240
|
+
log.err(error)
|
|
241
|
+
return null
|
|
242
|
+
|
|
243
|
+
Navigation:clickEvent(event)
|
|
244
|
+
if @disposed or event.defaultPrevented == true or event.metaKey == true or event.ctrlKey == true or event.shiftKey == true or event.altKey == true
|
|
245
|
+
return null
|
|
246
|
+
if event.button != null and event.button != 0
|
|
247
|
+
return null
|
|
248
|
+
anchor = link(event.target)
|
|
249
|
+
if anchor == null or anchor.hasAttribute("download")
|
|
250
|
+
return null
|
|
251
|
+
href = anchor.getAttribute("href")
|
|
252
|
+
if href == null or href == ""
|
|
253
|
+
return null
|
|
254
|
+
target = anchor.getAttribute("target")
|
|
255
|
+
if target != null and target != "" and target.toLowerCase() != "_self"
|
|
256
|
+
return null
|
|
257
|
+
try
|
|
258
|
+
destination = new URL(href, @window.location.href)
|
|
259
|
+
if destination.protocol != "http:" and destination.protocol != "https:"
|
|
260
|
+
return null
|
|
261
|
+
location = @window.location
|
|
262
|
+
if destination.origin != location.origin
|
|
263
|
+
if target == null
|
|
264
|
+
anchor.setAttribute("target", "_blank")
|
|
265
|
+
rel = anchor.getAttribute("rel")
|
|
266
|
+
if rel == null or rel == ""
|
|
267
|
+
rel = "noopener"
|
|
268
|
+
else
|
|
269
|
+
if !rel.split(" ").includes("noopener")
|
|
270
|
+
rel = "${rel} noopener"
|
|
271
|
+
anchor.setAttribute("rel", rel)
|
|
272
|
+
return null
|
|
273
|
+
if destination.pathname == location.pathname and destination.search == location.search and (destination.hash != location.hash or href.includes("#"))
|
|
274
|
+
return null
|
|
275
|
+
event.preventDefault()
|
|
276
|
+
observe(navigate(destination.href))
|
|
277
|
+
catch error
|
|
278
|
+
report(error)
|
|
279
|
+
return null
|
|
280
|
+
|
|
281
|
+
Navigation:link(element)
|
|
282
|
+
current = element
|
|
283
|
+
found = null
|
|
284
|
+
loop while current != null
|
|
285
|
+
if current.inert == true or current.hidden == true or current.disabled == true
|
|
286
|
+
return null
|
|
287
|
+
name = current.tagName
|
|
288
|
+
if found == null and is_string(name) and name.toLowerCase() == "a"
|
|
289
|
+
found = current
|
|
290
|
+
current = current.parentNode
|
|
291
|
+
return found
|
|
292
|
+
|
|
293
|
+
Navigation:idle()
|
|
294
|
+
return @tail
|
|
295
|
+
|
|
296
|
+
Navigation:dispose()
|
|
297
|
+
if @disposed
|
|
298
|
+
return null
|
|
299
|
+
@disposed = true
|
|
300
|
+
if @started
|
|
301
|
+
@document.removeEventListener("click", @click)
|
|
302
|
+
@window.removeEventListener("popstate", @pop)
|
|
303
|
+
@window.removeEventListener("hashchange", @hash)
|
|
304
|
+
return null
|
|
305
|
+
|
|
306
|
+
recovered(work)
|
|
307
|
+
return work.catch((error)
|
|
308
|
+
return null
|
|
309
|
+
)
|