@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/dist/app.mjs
ADDED
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import { Form } from "./form.mjs";
|
|
2
|
+
import { Heartbeat } from "./heartbeat.mjs";
|
|
3
|
+
import { ErrorReporter } from "./error_reporter.mjs";
|
|
4
|
+
import {
|
|
5
|
+
hostGlobal as __hostGlobal,
|
|
6
|
+
fromJson as __fromJson,
|
|
7
|
+
toJson as __toJson,
|
|
8
|
+
getClass as __getClass,
|
|
9
|
+
isKindof as __isKindof,
|
|
10
|
+
isNumber as __isNumber,
|
|
11
|
+
isString as __isString,
|
|
12
|
+
isBool as __isBool,
|
|
13
|
+
isObject as __isObject,
|
|
14
|
+
isArray as __isArray,
|
|
15
|
+
add as __add,
|
|
16
|
+
requireBoolean as __requireBoolean,
|
|
17
|
+
normalize as __normalize,
|
|
18
|
+
call as __call,
|
|
19
|
+
boundary as __boundary,
|
|
20
|
+
requireArity as __requireArity,
|
|
21
|
+
withArity as __withArity,
|
|
22
|
+
} from "./.lango/runtime.mjs";
|
|
23
|
+
|
|
24
|
+
export class App {
|
|
25
|
+
forms;
|
|
26
|
+
root;
|
|
27
|
+
renderer;
|
|
28
|
+
heartbeat;
|
|
29
|
+
resources;
|
|
30
|
+
reporter;
|
|
31
|
+
#host;
|
|
32
|
+
#queue;
|
|
33
|
+
#active;
|
|
34
|
+
#disposed;
|
|
35
|
+
#events;
|
|
36
|
+
#template;
|
|
37
|
+
#pingJob;
|
|
38
|
+
constructor(host, renderer) {
|
|
39
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
40
|
+
host = __boundary(host);
|
|
41
|
+
renderer = __boundary(renderer);
|
|
42
|
+
this.#host = host;
|
|
43
|
+
this.renderer = renderer;
|
|
44
|
+
this.forms = [];
|
|
45
|
+
this.#queue = [];
|
|
46
|
+
this.#active = [];
|
|
47
|
+
this.#disposed = false;
|
|
48
|
+
this.root = null;
|
|
49
|
+
this.#events = { };
|
|
50
|
+
this.#template = null;
|
|
51
|
+
this.heartbeat = null;
|
|
52
|
+
this.#pingJob = null;
|
|
53
|
+
this.resources = [];
|
|
54
|
+
this.reporter = null;
|
|
55
|
+
}
|
|
56
|
+
now() {
|
|
57
|
+
if (__requireBoolean(__normalize(this.#host.now) !== null)) {
|
|
58
|
+
return __normalize(this.#host.now());
|
|
59
|
+
}
|
|
60
|
+
return __normalize(__hostGlobal(["Date"]).now());
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
hostUrl() {
|
|
64
|
+
return __normalize(this.#host.location.href);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
schedule(action, delay) {
|
|
68
|
+
__requireArity(arguments.length, [0, 1], "schedule");
|
|
69
|
+
action = __boundary(action);
|
|
70
|
+
delay = __boundary(delay);
|
|
71
|
+
return __normalize(this.#host.schedule(action, delay));
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
cancelTimer(timer) {
|
|
75
|
+
__requireArity(arguments.length, [0], "cancelTimer");
|
|
76
|
+
timer = __boundary(timer);
|
|
77
|
+
__normalize(this.#host.cancelTimer(timer));
|
|
78
|
+
return null;
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
checkUrl(url) {
|
|
82
|
+
__requireArity(arguments.length, [0], "checkUrl");
|
|
83
|
+
url = __boundary(url);
|
|
84
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(__normalize(url.trim()) === ""))) {
|
|
85
|
+
throw "UI request requires a URL";
|
|
86
|
+
}
|
|
87
|
+
let target = new (__hostGlobal(["URL"]))(url, __normalize(this.#host.location.href));
|
|
88
|
+
if (__requireBoolean(__normalize(target.origin) !== __normalize(this.#host.location.origin))) {
|
|
89
|
+
throw "UI requests must use the current origin";
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
error(form, error, code = "UiFailure", name = null) {
|
|
95
|
+
__requireArity(arguments.length, [0, 1], "error");
|
|
96
|
+
form = __boundary(form);
|
|
97
|
+
error = __boundary(error);
|
|
98
|
+
code = __boundary(code);
|
|
99
|
+
name = __boundary(name);
|
|
100
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(form === null)) || __requireBoolean(__normalize(form.disposed)))) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
__normalize(this.renderer.reportError(form, error));
|
|
104
|
+
if (__requireBoolean(__normalize(this.reporter) !== null)) {
|
|
105
|
+
__normalize(this.reporter.capture("ui", code, name, form));
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
saveToken(token) {
|
|
111
|
+
__requireArity(arguments.length, [0], "saveToken");
|
|
112
|
+
token = __boundary(token);
|
|
113
|
+
try {
|
|
114
|
+
__normalize(this.#host.storage.setItem("lango.token", token));
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
post(url, input, token) {
|
|
122
|
+
__requireArity(arguments.length, [0, 1, 2], "post");
|
|
123
|
+
url = __boundary(url);
|
|
124
|
+
input = __boundary(input);
|
|
125
|
+
token = __boundary(token);
|
|
126
|
+
return this.request(url, input, token);
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
poll(url, input, token, signal) {
|
|
130
|
+
__requireArity(arguments.length, [0, 1, 2, 3], "poll");
|
|
131
|
+
url = __boundary(url);
|
|
132
|
+
input = __boundary(input);
|
|
133
|
+
token = __boundary(token);
|
|
134
|
+
signal = __boundary(signal);
|
|
135
|
+
return this.request(url, input, token, signal, true);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
request(url, input, token, signal = null, channel = false) {
|
|
139
|
+
__requireArity(arguments.length, [0, 1, 2], "request");
|
|
140
|
+
url = __boundary(url);
|
|
141
|
+
input = __boundary(input);
|
|
142
|
+
token = __boundary(token);
|
|
143
|
+
signal = __boundary(signal);
|
|
144
|
+
channel = __boundary(channel);
|
|
145
|
+
let target = this.checkUrl(url);
|
|
146
|
+
let headers = { "Content-Type": "application/json" };
|
|
147
|
+
if (__requireBoolean(token !== null)) {
|
|
148
|
+
headers.Authorization = `Bearer ${token}`;
|
|
149
|
+
}
|
|
150
|
+
let options = { method: "POST", headers: headers, body: __toJson(input) };
|
|
151
|
+
if (__requireBoolean(signal !== null)) {
|
|
152
|
+
options.signal = signal;
|
|
153
|
+
}
|
|
154
|
+
return __normalize(this.#host.fetch(`${__normalize(target.pathname)}${__normalize(target.search)}`, options)).then(__withArity((res) => {
|
|
155
|
+
res = __boundary(res);
|
|
156
|
+
if (__requireBoolean(!__requireBoolean(__normalize(res.ok)))) {
|
|
157
|
+
if (__requireBoolean(!__requireBoolean(channel))) {
|
|
158
|
+
throw `HTTP ${__normalize(res.status)}`;
|
|
159
|
+
}
|
|
160
|
+
if (__requireBoolean(__normalize(res.status) !== 409)) {
|
|
161
|
+
return { status: __normalize(res.status), retryAfter: __normalize(res.headers.get("retry-after")) };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return __normalize(res.json()).then(__withArity((body) => {
|
|
165
|
+
body = __boundary(body);
|
|
166
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(body))) || __requireBoolean(__isArray(body)))) {
|
|
167
|
+
if (__requireBoolean(channel)) {
|
|
168
|
+
throw { code: "InvalidPollResponse" };
|
|
169
|
+
}
|
|
170
|
+
throw "UI response must be a map";
|
|
171
|
+
}
|
|
172
|
+
let status = __normalize(res.status);
|
|
173
|
+
if (__requireBoolean(status === null)) {
|
|
174
|
+
status = 200;
|
|
175
|
+
}
|
|
176
|
+
return { status: status, token: __normalize(res.headers.get("x-lango-token")), body: body };
|
|
177
|
+
return null;
|
|
178
|
+
}, [0], "closure")).catch(__withArity((error) => {
|
|
179
|
+
error = __boundary(error);
|
|
180
|
+
if (__requireBoolean(channel)) {
|
|
181
|
+
throw { code: "InvalidPollResponse" };
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
return null;
|
|
185
|
+
}, [0], "closure"));
|
|
186
|
+
return null;
|
|
187
|
+
}, [0], "closure"));
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
start() {
|
|
191
|
+
let token = null;
|
|
192
|
+
try {
|
|
193
|
+
token = __normalize(this.#host.storage.getItem("lango.token"));
|
|
194
|
+
} catch (error) {
|
|
195
|
+
token = null;
|
|
196
|
+
}
|
|
197
|
+
return this.post("/", { }, token).then(__withArity((packet) => {
|
|
198
|
+
packet = __boundary(packet);
|
|
199
|
+
this.#events = __normalize(packet.body);
|
|
200
|
+
if (__requireBoolean(__normalize(this.#events.clientErrorUrl) !== null)) {
|
|
201
|
+
this.reporter = new ErrorReporter(this, __normalize(this.#events.clientErrorUrl));
|
|
202
|
+
}
|
|
203
|
+
if (__requireBoolean(__normalize(this.#events.pingUrl) !== null)) {
|
|
204
|
+
this.heartbeat = new Heartbeat(this, __normalize(this.#host), __normalize(this.#events.pingUrl));
|
|
205
|
+
}
|
|
206
|
+
this.root = new Form(this, null, __normalize(packet.token));
|
|
207
|
+
this.root.element = __normalize(this.#host.mount);
|
|
208
|
+
__normalize(this.root.setToken(__normalize(packet.token)));
|
|
209
|
+
return this.navigate(__normalize(this.#host.location.pathname), false).then(__withArity((ignored) => {
|
|
210
|
+
ignored = __boundary(ignored);
|
|
211
|
+
if (__requireBoolean(__normalize(this.heartbeat) !== null)) {
|
|
212
|
+
__normalize(this.heartbeat.start());
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
return null;
|
|
216
|
+
}, [0], "closure"));
|
|
217
|
+
return null;
|
|
218
|
+
}, [0], "closure"));
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
send(form, url, owner = null) {
|
|
222
|
+
__requireArity(arguments.length, [0, 1], "send");
|
|
223
|
+
form = __boundary(form);
|
|
224
|
+
url = __boundary(url);
|
|
225
|
+
owner = __boundary(owner);
|
|
226
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(form.disposed)))) {
|
|
227
|
+
return __normalize(__hostGlobal(["Promise"]).reject("Form is disposed"));
|
|
228
|
+
}
|
|
229
|
+
let pending = new (__hostGlobal(["Promise"]))(__withArity((resolve, reject) => {
|
|
230
|
+
resolve = __boundary(resolve);
|
|
231
|
+
reject = __boundary(reject);
|
|
232
|
+
__add(this.#queue, { kind: "send", form: form, url: url, owner: owner, resolve: resolve, reject: reject });
|
|
233
|
+
this.drain();
|
|
234
|
+
return null;
|
|
235
|
+
}, [0, 1], "closure"));
|
|
236
|
+
return pending;
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
deliver(form, action, owner, generation) {
|
|
240
|
+
__requireArity(arguments.length, [0, 1, 2, 3], "deliver");
|
|
241
|
+
form = __boundary(form);
|
|
242
|
+
action = __boundary(action);
|
|
243
|
+
owner = __boundary(owner);
|
|
244
|
+
generation = __boundary(generation);
|
|
245
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(form.disposed))) || __requireBoolean(!__requireBoolean(__normalize(owner.active))))) {
|
|
246
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
247
|
+
}
|
|
248
|
+
let deferred = __normalize(__hostGlobal(["Promise"]).withResolvers());
|
|
249
|
+
__add(this.#queue, { kind: "delivery", form: form, action: action, owner: owner, generation: generation, resolve: __normalize(deferred.resolve), reject: __normalize(deferred.reject) });
|
|
250
|
+
this.drain();
|
|
251
|
+
return __normalize(deferred.promise);
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
report(form, url, input, owner) {
|
|
255
|
+
__requireArity(arguments.length, [0, 1, 2, 3], "report");
|
|
256
|
+
form = __boundary(form);
|
|
257
|
+
url = __boundary(url);
|
|
258
|
+
input = __boundary(input);
|
|
259
|
+
owner = __boundary(owner);
|
|
260
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(form.disposed))) || __requireBoolean(!__requireBoolean(__normalize(owner.active))))) {
|
|
261
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
262
|
+
}
|
|
263
|
+
let deferred = __normalize(__hostGlobal(["Promise"]).withResolvers());
|
|
264
|
+
__add(this.#queue, { kind: "report", form: form, url: url, input: input, owner: owner, resolve: __normalize(deferred.resolve), reject: __normalize(deferred.reject) });
|
|
265
|
+
this.drain();
|
|
266
|
+
return __normalize(deferred.promise);
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
canPoll(form) {
|
|
270
|
+
__requireArity(arguments.length, [0], "canPoll");
|
|
271
|
+
form = __boundary(form);
|
|
272
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(form.disposed))) || __requireBoolean(__normalize(this.#pingJob) !== null))) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
for (const job of __normalize(this.#active)) {
|
|
276
|
+
if (__requireBoolean(__normalize(form.related(__normalize(job.form))))) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (const job of __normalize(this.#queue)) {
|
|
281
|
+
if (__requireBoolean(__normalize(form.related(__normalize(job.form))))) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
pausePolls(form = null) {
|
|
289
|
+
form = __boundary(form);
|
|
290
|
+
for (const candidate of __normalize(this.forms.slice())) {
|
|
291
|
+
if (__requireBoolean(__requireBoolean(form === null) || __requireBoolean(__normalize(form.related(candidate))))) {
|
|
292
|
+
__normalize(candidate.activity.pause());
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
resumePolls() {
|
|
299
|
+
for (const form of __normalize(this.forms.slice())) {
|
|
300
|
+
__normalize(form.activity.resume());
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
drain() {
|
|
306
|
+
if (__requireBoolean(__normalize(this.#pingJob) !== null)) {
|
|
307
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#active.length) === 0) && __requireBoolean(!__requireBoolean(__normalize(this.#pingJob.running))))) {
|
|
308
|
+
this.#pingJob.running = true;
|
|
309
|
+
this.executePing(__normalize(this.#pingJob));
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
for (const job of __normalize(this.#queue.slice())) {
|
|
314
|
+
let blocked = false;
|
|
315
|
+
for (const running of __normalize(this.#active)) {
|
|
316
|
+
if (__requireBoolean(__normalize(job.form.related(__normalize(running.form))))) {
|
|
317
|
+
blocked = true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (const earlier of __normalize(this.#queue)) {
|
|
321
|
+
if (__requireBoolean(earlier === job)) {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
if (__requireBoolean(__normalize(job.form.related(__normalize(earlier.form))))) {
|
|
325
|
+
blocked = true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (__requireBoolean(!__requireBoolean(blocked))) {
|
|
329
|
+
__normalize(this.#queue.splice(__normalize(this.#queue.indexOf(job)), 1));
|
|
330
|
+
__add(this.#active, job);
|
|
331
|
+
if (__requireBoolean(__normalize(job.kind) === "delivery")) {
|
|
332
|
+
this.executeDelivery(job);
|
|
333
|
+
} else {
|
|
334
|
+
this.pausePolls(__normalize(job.form));
|
|
335
|
+
this.execute(job);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this.resumePolls();
|
|
340
|
+
return null;
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
executeDelivery(job) {
|
|
344
|
+
__requireArity(arguments.length, [0], "executeDelivery");
|
|
345
|
+
job = __boundary(job);
|
|
346
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity((ignored) => {
|
|
347
|
+
ignored = __boundary(ignored);
|
|
348
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(job.form.disposed)) && __requireBoolean(job.owner.active)) && __requireBoolean(job.owner.generation === __normalize(job.generation)))) {
|
|
349
|
+
let action = __normalize(job.action);
|
|
350
|
+
__call(action, );
|
|
351
|
+
}
|
|
352
|
+
__normalize(job.resolve(null));
|
|
353
|
+
return null;
|
|
354
|
+
}, [0], "closure")).catch(__withArity((error) => {
|
|
355
|
+
error = __boundary(error);
|
|
356
|
+
__normalize(job.reject(error));
|
|
357
|
+
return null;
|
|
358
|
+
}, [0], "closure")).finally(() => {
|
|
359
|
+
__normalize(this.#active.splice(__normalize(this.#active.indexOf(job)), 1));
|
|
360
|
+
this.drain();
|
|
361
|
+
return null;
|
|
362
|
+
});
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
ping() {
|
|
366
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(this.heartbeat) === null))) {
|
|
367
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
368
|
+
}
|
|
369
|
+
if (__requireBoolean(__normalize(this.#pingJob) !== null)) {
|
|
370
|
+
return __normalize(this.#pingJob.promise);
|
|
371
|
+
}
|
|
372
|
+
let deferred = __normalize(__hostGlobal(["Promise"]).withResolvers());
|
|
373
|
+
this.#pingJob = { promise: __normalize(deferred.promise), resolve: __normalize(deferred.resolve), reject: __normalize(deferred.reject), running: false };
|
|
374
|
+
this.pausePolls();
|
|
375
|
+
this.drain();
|
|
376
|
+
return __normalize(deferred.promise);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
executePing(job) {
|
|
380
|
+
__requireArity(arguments.length, [0], "executePing");
|
|
381
|
+
job = __boundary(job);
|
|
382
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity((ignored) => {
|
|
383
|
+
ignored = __boundary(ignored);
|
|
384
|
+
return __normalize(this.heartbeat.exchange());
|
|
385
|
+
return null;
|
|
386
|
+
}, [0], "closure")).then(__withArity((ignored) => {
|
|
387
|
+
ignored = __boundary(ignored);
|
|
388
|
+
__normalize(job.resolve(null));
|
|
389
|
+
return null;
|
|
390
|
+
}, [0], "closure")).catch(__withArity((error) => {
|
|
391
|
+
error = __boundary(error);
|
|
392
|
+
__normalize(job.reject(error));
|
|
393
|
+
return null;
|
|
394
|
+
}, [0], "closure")).finally(() => {
|
|
395
|
+
this.#pingJob = null;
|
|
396
|
+
this.drain();
|
|
397
|
+
return null;
|
|
398
|
+
});
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
execute(job) {
|
|
402
|
+
__requireArity(arguments.length, [0], "execute");
|
|
403
|
+
job = __boundary(job);
|
|
404
|
+
let form = __normalize(job.form);
|
|
405
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity((ignored) => {
|
|
406
|
+
ignored = __boundary(ignored);
|
|
407
|
+
if (__requireBoolean(__normalize(form.disposed))) {
|
|
408
|
+
throw "Form is disposed";
|
|
409
|
+
}
|
|
410
|
+
if (__requireBoolean(__requireBoolean(__normalize(job.owner) !== null) && __requireBoolean(!__requireBoolean(job.owner.active)))) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
if (__requireBoolean(__normalize(job.kind) === "report")) {
|
|
414
|
+
return this.post(__normalize(job.url), __normalize(job.input), __normalize(form.token));
|
|
415
|
+
}
|
|
416
|
+
__normalize(form.clearValidation());
|
|
417
|
+
__normalize(this.renderer.waiting(form, true));
|
|
418
|
+
let ready = __normalize(form.prepareValue());
|
|
419
|
+
if (__requireBoolean(ready === null)) {
|
|
420
|
+
return this.post(__normalize(job.url), __normalize(form.getValue()), __normalize(form.token));
|
|
421
|
+
}
|
|
422
|
+
return ready.then(__withArity((ignored) => {
|
|
423
|
+
ignored = __boundary(ignored);
|
|
424
|
+
if (__requireBoolean(__normalize(form.disposed))) {
|
|
425
|
+
throw "Form is disposed";
|
|
426
|
+
}
|
|
427
|
+
if (__requireBoolean(__requireBoolean(__normalize(job.owner) !== null) && __requireBoolean(!__requireBoolean(job.owner.active)))) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
return this.post(__normalize(job.url), __normalize(form.getValue()), __normalize(form.token));
|
|
431
|
+
return null;
|
|
432
|
+
}, [0], "closure"));
|
|
433
|
+
return null;
|
|
434
|
+
}, [0], "closure")).then(__withArity((packet) => {
|
|
435
|
+
packet = __boundary(packet);
|
|
436
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(packet !== null) && __requireBoolean(!__requireBoolean(__normalize(form.disposed)))) && __requireBoolean(__requireBoolean(__normalize(job.owner) === null) || __requireBoolean(job.owner.active)))) {
|
|
437
|
+
if (__requireBoolean(__normalize(job.kind) === "report")) {
|
|
438
|
+
__normalize(form.setToken(__normalize(packet.token)));
|
|
439
|
+
} else {
|
|
440
|
+
__normalize(form.handle(packet));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}, [0], "closure")).then(__withArity((ignored) => {
|
|
445
|
+
ignored = __boundary(ignored);
|
|
446
|
+
__normalize(job.resolve(null));
|
|
447
|
+
return null;
|
|
448
|
+
}, [0], "closure")).catch(__withArity((error) => {
|
|
449
|
+
error = __boundary(error);
|
|
450
|
+
__normalize(job.reject(error));
|
|
451
|
+
return null;
|
|
452
|
+
}, [0], "closure")).finally(() => {
|
|
453
|
+
if (__requireBoolean(__normalize(job.kind) === "send")) {
|
|
454
|
+
__normalize(this.renderer.waiting(form, false));
|
|
455
|
+
}
|
|
456
|
+
__normalize(this.#active.splice(__normalize(this.#active.indexOf(job)), 1));
|
|
457
|
+
this.drain();
|
|
458
|
+
return null;
|
|
459
|
+
});
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
navigate(url, push = true) {
|
|
463
|
+
__requireArity(arguments.length, [0], "navigate");
|
|
464
|
+
url = __boundary(url);
|
|
465
|
+
push = __boundary(push);
|
|
466
|
+
let target = new (__hostGlobal(["URL"]))(url, __normalize(this.#host.location.href));
|
|
467
|
+
if (__requireBoolean(__normalize(target.origin) !== __normalize(this.#host.location.origin))) {
|
|
468
|
+
throw "UI navigation must use the current origin";
|
|
469
|
+
}
|
|
470
|
+
let path = __normalize(target.pathname);
|
|
471
|
+
if (__requireBoolean(path === "/")) {
|
|
472
|
+
path = "/index";
|
|
473
|
+
}
|
|
474
|
+
let template = this.selectTemplate(path);
|
|
475
|
+
let ready = __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
476
|
+
if (__requireBoolean(template !== __normalize(this.#template))) {
|
|
477
|
+
if (__requireBoolean(template !== null)) {
|
|
478
|
+
ready = __normalize(this.root.send(template));
|
|
479
|
+
} else {
|
|
480
|
+
this.#template = null;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return ready.then(__withArity((ignored) => {
|
|
484
|
+
ignored = __boundary(ignored);
|
|
485
|
+
this.#template = template;
|
|
486
|
+
let form = __normalize(this.root);
|
|
487
|
+
if (__requireBoolean(template !== null)) {
|
|
488
|
+
form = __normalize(this.root.find("__content__"));
|
|
489
|
+
if (__requireBoolean(!__requireBoolean(__isKindof(form, Form)))) {
|
|
490
|
+
throw "Template requires a __content__ form";
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return __normalize(form.send(path));
|
|
494
|
+
return null;
|
|
495
|
+
}, [0], "closure")).then(__withArity((ignored) => {
|
|
496
|
+
ignored = __boundary(ignored);
|
|
497
|
+
if (__requireBoolean(push)) {
|
|
498
|
+
__normalize(this.#host.history.pushState(null, "", `${__normalize(target.pathname)}${__normalize(target.search)}${__normalize(target.hash)}`));
|
|
499
|
+
}
|
|
500
|
+
if (__requireBoolean(__normalize(this.renderer.locationChanged) !== null)) {
|
|
501
|
+
__normalize(this.renderer.locationChanged(__normalize(target.href)));
|
|
502
|
+
}
|
|
503
|
+
return null;
|
|
504
|
+
return null;
|
|
505
|
+
}, [0], "closure"));
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
selectTemplate(path) {
|
|
509
|
+
__requireArity(arguments.length, [0], "selectTemplate");
|
|
510
|
+
path = __boundary(path);
|
|
511
|
+
let urls = __normalize(this.#events.templates);
|
|
512
|
+
if (__requireBoolean(urls === null)) {
|
|
513
|
+
urls = [];
|
|
514
|
+
}
|
|
515
|
+
let selected = __normalize(this.#events.defaultTemplate);
|
|
516
|
+
if (__requireBoolean(path === selected)) {
|
|
517
|
+
throw "Template URLs cannot be used as page URLs";
|
|
518
|
+
}
|
|
519
|
+
let best = 0;
|
|
520
|
+
for (const url of urls) {
|
|
521
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(!__requireBoolean(__normalize(url.startsWith("/"))))) || __requireBoolean(url === "/")) || __requireBoolean(__normalize(url.endsWith("/"))))) {
|
|
522
|
+
throw "Invalid template URL";
|
|
523
|
+
}
|
|
524
|
+
if (__requireBoolean(path === url)) {
|
|
525
|
+
throw "Template URLs cannot be used as page URLs";
|
|
526
|
+
}
|
|
527
|
+
if (__requireBoolean(__requireBoolean(path === url) || __requireBoolean(__normalize(path.startsWith(`${url}/`))))) {
|
|
528
|
+
if (__requireBoolean(__normalize(url.length) > best)) {
|
|
529
|
+
selected = url;
|
|
530
|
+
best = __normalize(url.length);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (__requireBoolean(path === selected)) {
|
|
535
|
+
throw "Template URLs cannot be used as page URLs";
|
|
536
|
+
}
|
|
537
|
+
return selected;
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
command(form, cmd) {
|
|
541
|
+
__requireArity(arguments.length, [0, 1], "command");
|
|
542
|
+
form = __boundary(form);
|
|
543
|
+
cmd = __boundary(cmd);
|
|
544
|
+
if (__normalize(cmd.type) === "values") {
|
|
545
|
+
__normalize(form.setValue(__normalize(cmd.values)));
|
|
546
|
+
} else if (__normalize(cmd.type) === "invalid") {
|
|
547
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).setInvalid(__normalize(cmd.message)));
|
|
548
|
+
} else if (__normalize(cmd.type) === "set") {
|
|
549
|
+
let targetForm = __normalize(form.find(__normalize(cmd.name)));
|
|
550
|
+
if (__requireBoolean(!__requireBoolean(__isKindof(targetForm, Form)))) {
|
|
551
|
+
throw "Set requires a form target";
|
|
552
|
+
}
|
|
553
|
+
__normalize(this.renderer.show(targetForm, __normalize(cmd.control)));
|
|
554
|
+
} else if (__normalize(cmd.type) === "setUrl") {
|
|
555
|
+
let target = new (__hostGlobal(["URL"]))(__normalize(cmd.url), __normalize(this.#host.location.href));
|
|
556
|
+
if (__requireBoolean(__normalize(target.origin) !== __normalize(this.#host.location.origin))) {
|
|
557
|
+
throw "UI URL must use the current origin";
|
|
558
|
+
}
|
|
559
|
+
__normalize(this.#host.history.pushState(null, "", `${__normalize(target.pathname)}${__normalize(target.search)}${__normalize(target.hash)}`));
|
|
560
|
+
if (__requireBoolean(__normalize(this.renderer.locationChanged) !== null)) {
|
|
561
|
+
__normalize(this.renderer.locationChanged(__normalize(target.href)));
|
|
562
|
+
}
|
|
563
|
+
} else if (__normalize(cmd.type) === "redirect") {
|
|
564
|
+
let action = () => {
|
|
565
|
+
this.navigate(__normalize(cmd.url)).catch(__withArity((problem) => {
|
|
566
|
+
problem = __boundary(problem);
|
|
567
|
+
this.error(form, problem);
|
|
568
|
+
return null;
|
|
569
|
+
}, [0], "closure"));
|
|
570
|
+
return null;
|
|
571
|
+
};
|
|
572
|
+
__normalize(this.#host.defer(action));
|
|
573
|
+
} else if (__normalize(cmd.type) === "disable") {
|
|
574
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).setDisabled(true));
|
|
575
|
+
} else if (__normalize(cmd.type) === "enable") {
|
|
576
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).setDisabled(false));
|
|
577
|
+
} else if (__normalize(cmd.type) === "changeCaption") {
|
|
578
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).setCaption(__normalize(cmd.caption)));
|
|
579
|
+
} else if (__normalize(cmd.type) === "activateTabItem") {
|
|
580
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).activate());
|
|
581
|
+
} else if (__normalize(cmd.type) === "setProgress") {
|
|
582
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).setRange(__normalize(cmd.min), __normalize(cmd.max), __normalize(cmd.value)));
|
|
583
|
+
} else if (__normalize(cmd.type) === "updateProgress") {
|
|
584
|
+
__normalize(__normalize(form.find(__normalize(cmd.name))).update(__normalize(cmd.value), __normalize(cmd.label)));
|
|
585
|
+
} else if (__normalize(cmd.type) === "showAlert") {
|
|
586
|
+
__normalize(this.renderer.presentations.showAlert(form, cmd));
|
|
587
|
+
} else if (__normalize(cmd.type) === "dismissAlert") {
|
|
588
|
+
__normalize(this.renderer.presentations.dismissAlert(form, __normalize(cmd.name)));
|
|
589
|
+
} else if (__normalize(cmd.type) === "showToast") {
|
|
590
|
+
__normalize(this.renderer.presentations.showToast(form, __normalize(cmd.toast), __normalize(cmd.stack)));
|
|
591
|
+
} else if (__normalize(cmd.type) === "showDialog") {
|
|
592
|
+
__normalize(this.renderer.presentations.showDialog(form, __normalize(cmd.dialog), __normalize(cmd.keepPrev)));
|
|
593
|
+
} else if (__normalize(cmd.type) === "swapDialog") {
|
|
594
|
+
__normalize(this.renderer.presentations.swapDialog(form));
|
|
595
|
+
} else if (__normalize(cmd.type) === "setTimer") {
|
|
596
|
+
__normalize(form.activity.timer(__normalize(cmd.url), __normalize(cmd.interval)));
|
|
597
|
+
} else if (__normalize(cmd.type) === "clearTimer") {
|
|
598
|
+
__normalize(form.activity.clearTimer(__normalize(cmd.url)));
|
|
599
|
+
} else if (__normalize(cmd.type) === "setInterval") {
|
|
600
|
+
__normalize(form.activity.timer(__normalize(cmd.url), __normalize(cmd.interval), true));
|
|
601
|
+
} else if (__normalize(cmd.type) === "clearInterval") {
|
|
602
|
+
__normalize(form.activity.clearTimer(__normalize(cmd.url), true));
|
|
603
|
+
} else if (__normalize(cmd.type) === "startLongPoll") {
|
|
604
|
+
__normalize(form.activity.startLongPoll(__normalize(cmd.url), __normalize(cmd.key), __normalize(cmd.cursor)));
|
|
605
|
+
} else if (__normalize(cmd.type) === "stopLongPoll") {
|
|
606
|
+
__normalize(form.activity.stopLongPoll(__normalize(cmd.url), __normalize(cmd.key)));
|
|
607
|
+
} else {
|
|
608
|
+
throw `Unsupported UI command: ${__normalize(cmd.type)}`;
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
dispose() {
|
|
614
|
+
this.#disposed = true;
|
|
615
|
+
if (__requireBoolean(__normalize(this.heartbeat) !== null)) {
|
|
616
|
+
__normalize(this.heartbeat.dispose());
|
|
617
|
+
}
|
|
618
|
+
if (__requireBoolean(__normalize(this.reporter) !== null)) {
|
|
619
|
+
__normalize(this.reporter.dispose());
|
|
620
|
+
}
|
|
621
|
+
for (const form of __normalize(this.forms.slice())) {
|
|
622
|
+
__normalize(form.dispose());
|
|
623
|
+
}
|
|
624
|
+
for (const job of __normalize(this.#queue)) {
|
|
625
|
+
__normalize(job.reject("Application is disposed"));
|
|
626
|
+
}
|
|
627
|
+
this.#queue = [];
|
|
628
|
+
for (const release of __normalize(this.resources)) {
|
|
629
|
+
__call(release, );
|
|
630
|
+
}
|
|
631
|
+
this.resources = [];
|
|
632
|
+
return null;
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
//# sourceMappingURL=app.mjs.map
|
package/dist/app.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.mjs","sources":["app.lango"],"sourcesContent":["import js global Object\nimport js global Promise\nimport js global URL\nimport js global Date\nimport \"./form\"\n class Form\nimport \"./heartbeat\"\n class Heartbeat\nimport \"./error_reporter\"\n class ErrorReporter\n\nexport class App(host, renderer)\n properties\n forms\n root\n renderer\n heartbeat\n resources\n reporter\n methods\n start()\n post(url, input, token)\n saveToken(token)\n send(form, url, owner = null)\n deliver(form, action, owner, generation)\n report(form, url, input, owner)\n executeDelivery(job)\n checkUrl(url)\n hostUrl()\n request(url, input, token, signal = null, channel = false)\n poll(url, input, token, signal)\n canPoll(form)\n pausePolls(form = null)\n resumePolls()\n schedule(action, delay)\n cancelTimer(timer)\n now()\n error(form, error, code = \"UiFailure\", name = null)\n drain()\n execute(job)\n navigate(url, push = true)\n selectTemplate(path)\n ping()\n executePing(job)\n command(form, cmd)\n dispose()\n\nApp(host, renderer)\n @host = host\n @renderer = renderer\n @forms = []\n @queue = []\n @active = []\n @disposed = false\n @root = null\n @events = {}\n @template = null\n @heartbeat = null\n @pingJob = null\n @resources = []\n @reporter = null\n\nApp:now()\n if @host.now != null\n return @host.now()\n return Date/now()\n\nApp:hostUrl()\n return @host.location.href\n\nApp:schedule(action, delay)\n return @host.schedule(action, delay)\n\nApp:cancelTimer(timer)\n @host.cancelTimer(timer)\n return null\n\nApp:checkUrl(url)\n if !is_string(url) or url.trim() == \"\"\n throw \"UI request requires a URL\"\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI requests must use the current origin\"\n return target\n\nApp:error(form, error, code = \"UiFailure\", name = null)\n if @disposed or form == null or form.disposed\n return null\n @renderer.reportError(form, error)\n if @reporter != null\n @reporter.capture(\"ui\", code, name, form)\n return null\n\nApp:saveToken(token)\n try\n @host.storage.setItem(\"lango.token\", token)\n catch error\n return null\n return null\n\nApp:post(url, input, token)\n return request(url, input, token)\n\nApp:poll(url, input, token, signal)\n return request(url, input, token, signal, true)\n\nApp:request(url, input, token, signal = null, channel = false)\n target = checkUrl(url)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n if token != null\n headers.Authorization = \"Bearer ${token}\"\n options = {\n method: \"POST\"\n headers: headers\n body: to_json(input)\n }\n if signal != null\n options.signal = signal\n return chain @host.fetch(\"${target.pathname}${target.search}\", options)\n then(res)\n capture channel\n if !res.ok\n if !channel\n throw \"HTTP ${res.status}\"\n if res.status != 409\n return {\n status: res.status\n retryAfter: res.headers.get(\"retry-after\")\n }\n return chain res.json()\n then(body)\n capture res\n capture channel\n if !is_object(body) or is_array(body)\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw \"UI response must be a map\"\n status = res.status\n if status == null\n status = 200\n return {\n status: status\n token: res.headers.get(\"x-lango-token\")\n body: body\n }\n catch(error)\n capture channel\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw error\n\nApp:start()\n token = null\n try\n token = @host.storage.getItem(\"lango.token\")\n catch error\n token = null\n return chain post(\"/\", {}, token)\n then(packet)\n @events = packet.body\n if @events.clientErrorUrl != null\n @reporter = new ErrorReporter(@this, @events.clientErrorUrl)\n if @events.pingUrl != null\n @heartbeat = new Heartbeat(@this, @host, @events.pingUrl)\n @root = new Form(@this, null, packet.token)\n @root.element = @host.mount\n @root.setToken(packet.token)\n return chain navigate(@host.location.pathname, false)\n then(ignored)\n if @heartbeat != null\n @heartbeat.start()\n return null\n\nApp:send(form, url, owner = null)\n if @disposed or form.disposed\n return Promise/reject(\"Form is disposed\")\n pending = new Promise((resolve, reject)\n capture form\n capture url\n capture owner\n @queue.add({\n kind: \"send\"\n form: form\n url: url\n owner: owner\n resolve: resolve\n reject: reject\n })\n drain()\n )\n return pending\n\nApp:deliver(form, action, owner, generation)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n kind: \"delivery\"\n form: form\n action: action\n owner: owner\n generation: generation\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:report(form, url, input, owner)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n kind: \"report\"\n form: form\n url: url\n input: input\n owner: owner\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:canPoll(form)\n if @disposed or form.disposed or @pingJob != null\n return false\n for @active as job\n if form.related(job.form)\n return false\n for @queue as job\n if form.related(job.form)\n return false\n return true\n\nApp:pausePolls(form = null)\n for @forms.slice() as candidate\n if form == null or form.related(candidate)\n candidate.activity.pause()\n return null\n\nApp:resumePolls()\n for @forms.slice() as form\n form.activity.resume()\n return null\n\nApp:drain()\n if @pingJob != null\n if @active.length == 0 and !@pingJob.running\n @pingJob.running = true\n executePing(@pingJob)\n return null\n for @queue.slice() as job\n blocked = false\n for @active as running\n if job.form.related(running.form)\n blocked = true\n for @queue as earlier\n if earlier == job\n break\n if job.form.related(earlier.form)\n blocked = true\n if !blocked\n @queue.splice(@queue.indexOf(job), 1)\n @active.add(job)\n if job.kind == \"delivery\"\n executeDelivery(job)\n else\n pausePolls(job.form)\n execute(job)\n resumePolls()\n return null\n\nApp:executeDelivery(job)\n return chain Promise/resolve(null)\n then(ignored)\n capture job\n if !job.form.disposed and job.owner.active and job.owner.generation == job.generation\n action = job.action\n action()\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n @active.splice(@active.indexOf(job), 1)\n drain()\n\nApp:ping()\n if @disposed or @heartbeat == null\n return Promise/resolve(null)\n if @pingJob != null\n return @pingJob.promise\n deferred = Promise/withResolvers()\n @pingJob = {\n promise: deferred.promise\n resolve: deferred.resolve\n reject: deferred.reject\n running: false\n }\n pausePolls()\n drain()\n return deferred.promise\n\nApp:executePing(job)\n return chain Promise/resolve(null)\n then(ignored)\n return @heartbeat.exchange()\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n @pingJob = null\n drain()\n\nApp:execute(job)\n form = job.form\n return chain Promise/resolve(null)\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if job.owner != null and !job.owner.active\n return null\n if job.kind == \"report\"\n return post(job.url, job.input, form.token)\n form.clearValidation()\n @renderer.waiting(form, true)\n ready = form.prepareValue()\n if ready == null\n return post(job.url, form.getValue(), form.token)\n return chain ready\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if job.owner != null and !job.owner.active\n return null\n return post(job.url, form.getValue(), form.token)\n then(packet)\n capture form\n capture job\n if packet != null and !form.disposed and (job.owner == null or job.owner.active)\n if job.kind == \"report\"\n form.setToken(packet.token)\n else\n form.handle(packet)\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n capture form\n if job.kind == \"send\"\n @renderer.waiting(form, false)\n @active.splice(@active.indexOf(job), 1)\n drain()\n\nApp:navigate(url, push = true)\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI navigation must use the current origin\"\n path = target.pathname\n if path == \"/\"\n path = \"/index\"\n template = selectTemplate(path)\n ready = Promise/resolve(null)\n if template != @template\n if template != null\n ready = @root.send(template)\n else\n @template = null\n return chain ready\n then(ignored)\n capture template\n capture path\n capture Form\n @template = template\n form = @root\n if template != null\n form = @root.find(\"__content__\")\n if !is_kindof(form, Form)\n throw \"Template requires a __content__ form\"\n return form.send(path)\n then(ignored)\n capture target\n capture push\n if push\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n return null\n\nApp:selectTemplate(path)\n urls = @events.templates\n if urls == null\n urls = []\n selected = @events.defaultTemplate\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n best = 0\n for urls as url\n if !is_string(url) or !url.startsWith(\"/\") or url == \"/\" or url.endsWith(\"/\")\n throw \"Invalid template URL\"\n if path == url\n throw \"Template URLs cannot be used as page URLs\"\n if path == url or path.startsWith(\"${url}/\")\n if url.length > best\n selected = url\n best = url.length\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n return selected\n\nApp:command(form, cmd)\n switch cmd.type\n case \"values\"\n form.setValue(cmd.values)\n case \"invalid\"\n form.find(cmd.name).setInvalid(cmd.message)\n case \"set\"\n targetForm = form.find(cmd.name)\n if !is_kindof(targetForm, Form)\n throw \"Set requires a form target\"\n @renderer.show(targetForm, cmd.control)\n case \"setUrl\"\n target = new URL(cmd.url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI URL must use the current origin\"\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n case \"redirect\"\n action = ()\n capture cmd\n chain navigate(cmd.url)\n catch(problem)\n capture form\n error(form, problem)\n @host.defer(action)\n case \"disable\"\n form.find(cmd.name).setDisabled(true)\n case \"enable\"\n form.find(cmd.name).setDisabled(false)\n case \"changeCaption\"\n form.find(cmd.name).setCaption(cmd.caption)\n case \"activateTabItem\"\n form.find(cmd.name).activate()\n case \"setProgress\"\n form.find(cmd.name).setRange(cmd.min, cmd.max, cmd.value)\n case \"updateProgress\"\n form.find(cmd.name).update(cmd.value, cmd.label)\n case \"showAlert\"\n @renderer.presentations.showAlert(form, cmd)\n case \"dismissAlert\"\n @renderer.presentations.dismissAlert(form, cmd.name)\n case \"showToast\"\n @renderer.presentations.showToast(form, cmd.toast, cmd.stack)\n case \"showDialog\"\n @renderer.presentations.showDialog(form, cmd.dialog, cmd.keepPrev)\n case \"swapDialog\"\n @renderer.presentations.swapDialog(form)\n case \"setTimer\"\n form.activity.timer(cmd.url, cmd.interval)\n case \"clearTimer\"\n form.activity.clearTimer(cmd.url)\n case \"setInterval\"\n form.activity.timer(cmd.url, cmd.interval, true)\n case \"clearInterval\"\n form.activity.clearTimer(cmd.url, true)\n case \"startLongPoll\"\n form.activity.startLongPoll(cmd.url, cmd.key, cmd.cursor)\n case \"stopLongPoll\"\n form.activity.stopLongPoll(cmd.url, cmd.key)\n else\n throw \"Unsupported UI command: ${cmd.type}\"\n return null\n\nApp:dispose()\n @disposed = true\n if @heartbeat != null\n @heartbeat.dispose()\n if @reporter != null\n @reporter.dispose()\n for @forms.slice() as form\n form.dispose()\n for @queue as job\n job.reject(\"Application is disposed\")\n @queue = []\n for @resources as release\n release()\n @resources = []\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|