@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.
Files changed (110) hide show
  1. package/LICENSE +200 -0
  2. package/NOTICE +2 -0
  3. package/README.md +877 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/runtime.mjs +607 -0
  6. package/dist/.lango/xmldom/conventions.js +429 -0
  7. package/dist/.lango/xmldom/dom-parser.js +591 -0
  8. package/dist/.lango/xmldom/dom.js +3759 -0
  9. package/dist/.lango/xmldom/entities.js +2171 -0
  10. package/dist/.lango/xmldom/errors.js +205 -0
  11. package/dist/.lango/xmldom/grammar.js +559 -0
  12. package/dist/.lango/xmldom/index.js +41 -0
  13. package/dist/.lango/xmldom/package.json +1 -0
  14. package/dist/.lango/xmldom/sax.js +983 -0
  15. package/dist/.lango/xmldom.LICENSE.md +8 -0
  16. package/dist/application.mjs +429 -0
  17. package/dist/application.mjs.map +1 -0
  18. package/dist/coordinator.mjs +91 -0
  19. package/dist/coordinator.mjs.map +1 -0
  20. package/dist/demo.mjs +110 -0
  21. package/dist/demo.mjs.map +1 -0
  22. package/dist/demo_controls.mjs +59 -0
  23. package/dist/demo_controls.mjs.map +1 -0
  24. package/dist/errors.mjs +201 -0
  25. package/dist/errors.mjs.map +1 -0
  26. package/dist/form_state.mjs +266 -0
  27. package/dist/form_state.mjs.map +1 -0
  28. package/dist/heartbeat.mjs +330 -0
  29. package/dist/heartbeat.mjs.map +1 -0
  30. package/dist/inheritance.mjs +240 -0
  31. package/dist/inheritance.mjs.map +1 -0
  32. package/dist/input_values.mjs +65 -0
  33. package/dist/input_values.mjs.map +1 -0
  34. package/dist/library.mjs +792 -0
  35. package/dist/library.mjs.map +1 -0
  36. package/dist/navigation.mjs +466 -0
  37. package/dist/navigation.mjs.map +1 -0
  38. package/dist/node/.lango/bignumber.mjs +3119 -0
  39. package/dist/node/.lango/runtime.mjs +609 -0
  40. package/dist/node/.lango/xmldom/conventions.js +429 -0
  41. package/dist/node/.lango/xmldom/dom-parser.js +591 -0
  42. package/dist/node/.lango/xmldom/dom.js +3759 -0
  43. package/dist/node/.lango/xmldom/entities.js +2171 -0
  44. package/dist/node/.lango/xmldom/errors.js +205 -0
  45. package/dist/node/.lango/xmldom/grammar.js +559 -0
  46. package/dist/node/.lango/xmldom/index.js +41 -0
  47. package/dist/node/.lango/xmldom/package.json +1 -0
  48. package/dist/node/.lango/xmldom/sax.js +983 -0
  49. package/dist/node/.lango/xmldom.LICENSE.md +8 -0
  50. package/dist/node/browser_host.mjs +351 -0
  51. package/dist/node/browser_host.mjs.map +1 -0
  52. package/dist/node/create_app.mjs +118 -0
  53. package/dist/node/create_app.mjs.map +1 -0
  54. package/dist/presentation.mjs +89 -0
  55. package/dist/presentation.mjs.map +1 -0
  56. package/dist/protocol.mjs +706 -0
  57. package/dist/protocol.mjs.map +1 -0
  58. package/dist/session.mjs +431 -0
  59. package/dist/session.mjs.map +1 -0
  60. package/dist/tokens.mjs +298 -0
  61. package/dist/tokens.mjs.map +1 -0
  62. package/examples/contacts.lango +302 -0
  63. package/examples/contacts_flow.lango +174 -0
  64. package/examples/contacts_store.lango +109 -0
  65. package/examples/contacts_store_test.lango +65 -0
  66. package/examples/demo.css +72 -0
  67. package/examples/demo_test.lango +356 -0
  68. package/examples/index.html +28 -0
  69. package/examples/pages.lango +180 -0
  70. package/examples/server.lango +189 -0
  71. package/examples/worker.lango +142 -0
  72. package/package.json +64 -4
  73. package/src/application.lango +327 -0
  74. package/src/browser_host.lango +276 -0
  75. package/src/coordinator.lango +57 -0
  76. package/src/demo.lango +110 -0
  77. package/src/demo_controls.lango +53 -0
  78. package/src/errors.lango +149 -0
  79. package/src/errors_test.lango +157 -0
  80. package/src/form_state.lango +168 -0
  81. package/src/heartbeat.lango +230 -0
  82. package/src/heartbeat_test.lango +479 -0
  83. package/src/inheritance.lango +167 -0
  84. package/src/input_values.lango +37 -0
  85. package/src/library.lango +571 -0
  86. package/src/logout_test.lango +564 -0
  87. package/src/navigation.lango +309 -0
  88. package/src/navigation_test.lango +556 -0
  89. package/src/presentation.lango +55 -0
  90. package/src/protocol.lango +787 -0
  91. package/src/renderer_test.lango +1986 -0
  92. package/src/session.lango +313 -0
  93. package/src/session_test.lango +455 -0
  94. package/src/tabs_test.lango +216 -0
  95. package/src/tokens.lango +215 -0
  96. package/template/.vscode/extensions.json +3 -0
  97. package/template/.vscode/settings.json +9 -0
  98. package/template/README.md +40 -0
  99. package/template/gitignore +4 -0
  100. package/template/package.json +22 -0
  101. package/template/public/app.css +4 -0
  102. package/template/public/index.html +24 -0
  103. package/template/src/client.lango +78 -0
  104. package/template/src/pages.lango +55 -0
  105. package/template/src/server.lango +24 -0
  106. package/template/src/worker.lango +77 -0
  107. package/template/test/app.lango +9 -0
  108. package/tools/create_app.lango +88 -0
  109. package/tools/create_app_test.lango +43 -0
  110. package/tools/starter_test.lango +227 -0
@@ -0,0 +1,330 @@
1
+ import {
2
+ hostGlobal as __hostGlobal,
3
+ hostGlobalCall as __hostGlobalCall,
4
+ contextGet as __contextGet,
5
+ contextSet as __contextSet,
6
+ contextRestore as __contextRestore,
7
+ fromJson as __fromJson,
8
+ toJson as __toJson,
9
+ isNumber as __isNumber,
10
+ isString as __isString,
11
+ isBool as __isBool,
12
+ isObject as __isObject,
13
+ isArray as __isArray,
14
+ entries as __entries,
15
+ requireBoolean as __requireBoolean,
16
+ normalize as __normalize,
17
+ finite as __finite,
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 Heartbeat {
25
+ #path;
26
+ #idleMs;
27
+ #clock;
28
+ #transport;
29
+ #sessions;
30
+ #timer;
31
+ #running;
32
+ #resume;
33
+ #started;
34
+ #disposed;
35
+ #lastActivity;
36
+ constructor(options) {
37
+ __requireArity(arguments.length, [0], "constructor");
38
+ options = __boundary(options);
39
+ this.#path = __normalize(options.path);
40
+ if (__requireBoolean(__normalize(this.#path) === null)) {
41
+ this.#path = "/_lango/ping";
42
+ }
43
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(this.#path)))) || __requireBoolean(!__requireBoolean(__normalize(this.#path.startsWith("/"))))) || __requireBoolean(__normalize(this.#path.startsWith("//")))) || __requireBoolean(__normalize(this.#path.includes("\\"))))) {
44
+ throw "UiPingRequiresSameOriginPath";
45
+ }
46
+ this.#idleMs = __normalize(options.idleMs);
47
+ if (__requireBoolean(__normalize(this.#idleMs) === null)) {
48
+ this.#idleMs = 60000;
49
+ }
50
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(__normalize(this.#idleMs)))) || __requireBoolean(__normalize(this.#idleMs) < 1)) || __requireBoolean(__finite(__normalize(this.#idleMs) % 1) !== 0))) {
51
+ throw "UiPingIdleMustBePositiveMilliseconds";
52
+ }
53
+ this.#clock = __normalize(options.clock);
54
+ if (__requireBoolean(__normalize(this.#clock) === null)) {
55
+ this.#clock = new SystemClock();
56
+ }
57
+ this.#transport = __normalize(options.transport);
58
+ this.#sessions = [];
59
+ this.#timer = null;
60
+ this.#running = null;
61
+ this.#resume = null;
62
+ this.#started = false;
63
+ this.#disposed = false;
64
+ this.#lastActivity = __normalize(this.#clock.now());
65
+ }
66
+ sessions(sessions) {
67
+ __requireArity(arguments.length, [0], "sessions");
68
+ sessions = __boundary(sessions);
69
+ this.#sessions = __normalize(sessions.slice());
70
+ return null;
71
+ return null;
72
+ }
73
+ start() {
74
+ if (__requireBoolean(__normalize(this.#disposed))) {
75
+ throw "UiPingDisposed";
76
+ }
77
+ this.#started = true;
78
+ return this.schedule();
79
+ return null;
80
+ }
81
+ activity() {
82
+ this.#lastActivity = __normalize(this.#clock.now());
83
+ return this.schedule();
84
+ return null;
85
+ }
86
+ schedule() {
87
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
88
+ __normalize(this.#clock.cancel(__normalize(this.#timer)));
89
+ this.#timer = null;
90
+ }
91
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(!__requireBoolean(__normalize(this.#started)))) || __requireBoolean(__normalize(this.#running) !== null))) {
92
+ return null;
93
+ }
94
+ let delay = __finite(__normalize(this.#idleMs) - __finite(__normalize(this.#clock.now()) - __normalize(this.#lastActivity)));
95
+ if (__requireBoolean(delay < 1)) {
96
+ delay = 1;
97
+ }
98
+ let callback = () => {
99
+ this.tick();
100
+ return null;
101
+ };
102
+ this.#timer = __normalize(this.#clock.schedule(callback, delay));
103
+ return null;
104
+ return null;
105
+ }
106
+ tick() {
107
+ this.#timer = null;
108
+ if (__requireBoolean(__normalize(this.#disposed))) {
109
+ return null;
110
+ }
111
+ if (__requireBoolean(__finite(__normalize(this.#clock.now()) - __normalize(this.#lastActivity)) < __normalize(this.#idleMs))) {
112
+ return this.schedule();
113
+ }
114
+ return this.ping().catch(__withArity((error) => {
115
+ const __contextScope = [];
116
+ try {
117
+ error = __boundary(error);
118
+ __normalize(__contextGet("log").warn("Token ping failed; existing form tokens are retained"));
119
+ return null;
120
+ } finally {
121
+ __contextRestore(__contextScope);
122
+ }
123
+ }, [0], "closure"));
124
+ return null;
125
+ }
126
+ ping() {
127
+ if (__requireBoolean(__normalize(this.#disposed))) {
128
+ return __normalize(__hostGlobal(["Promise"]).resolve());
129
+ }
130
+ if (__requireBoolean(__normalize(this.#running) !== null)) {
131
+ return __normalize(this.#running);
132
+ }
133
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
134
+ __normalize(this.#clock.cancel(__normalize(this.#timer)));
135
+ this.#timer = null;
136
+ }
137
+ let participants = __normalize(this.#sessions.slice());
138
+ let barrier = this.gate();
139
+ let waiting = [];
140
+ for (const session of participants) {
141
+ waiting.push(__normalize(session.reservePing(barrier)));
142
+ }
143
+ let ready = __normalize(__hostGlobal(["Promise"]).all(waiting));
144
+ let work = __normalize(ready.then(__withArity((entries) => {
145
+ entries = __boundary(entries);
146
+ return this.renew(entries, participants);
147
+ return null;
148
+ }, [0], "closure")));
149
+ let running = __normalize(work.finally(() => {
150
+ this.finish();
151
+ return null;
152
+ }));
153
+ this.#running = running;
154
+ return running;
155
+ return null;
156
+ }
157
+ gate() {
158
+ let gate = new (__hostGlobal(["Promise"]))(__withArity((resolve, reject) => {
159
+ resolve = __boundary(resolve);
160
+ reject = __boundary(reject);
161
+ this.suspend(resolve);
162
+ return null;
163
+ }, [0, 1], "closure"));
164
+ return gate;
165
+ return null;
166
+ }
167
+ suspend(resolve) {
168
+ __requireArity(arguments.length, [0], "suspend");
169
+ resolve = __boundary(resolve);
170
+ this.#resume = resolve;
171
+ return null;
172
+ return null;
173
+ }
174
+ renew(entries, participants) {
175
+ __requireArity(arguments.length, [0, 1], "renew");
176
+ entries = __boundary(entries);
177
+ participants = __boundary(participants);
178
+ if (__requireBoolean(__normalize(this.#disposed))) {
179
+ return null;
180
+ }
181
+ let forms = [];
182
+ let selected = [];
183
+ for (const [index, entry] of __entries(entries)) {
184
+ if (__requireBoolean(entry !== null)) {
185
+ forms.push(entry);
186
+ selected.push(__normalize(participants[index]));
187
+ }
188
+ }
189
+ if (__requireBoolean(__normalize(forms.length) === 0)) {
190
+ return null;
191
+ }
192
+ if (__requireBoolean(__normalize(forms.length) > 256)) {
193
+ throw "UiPingTooManyForms";
194
+ }
195
+ let input = { forms: forms };
196
+ let pending = null;
197
+ if (__requireBoolean(__normalize(this.#transport) === null)) {
198
+ pending = postPing(__normalize(this.#path), input);
199
+ } else {
200
+ pending = __normalize(this.#transport.send(__normalize(this.#path), input));
201
+ }
202
+ return pending.then(__withArity((result) => {
203
+ result = __boundary(result);
204
+ return this.accept(result, forms, selected);
205
+ return null;
206
+ }, [0], "closure"));
207
+ return null;
208
+ }
209
+ accept(result, forms, participants) {
210
+ __requireArity(arguments.length, [0, 1, 2], "accept");
211
+ result = __boundary(result);
212
+ forms = __boundary(forms);
213
+ participants = __boundary(participants);
214
+ if (__requireBoolean(__normalize(this.#disposed))) {
215
+ return null;
216
+ }
217
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(result))) || __requireBoolean(!__requireBoolean(__isArray(__normalize(result.forms)))))) {
218
+ throw "UiInvalidPingResponse";
219
+ }
220
+ let renewed = __normalize(result.forms);
221
+ if (__requireBoolean(__normalize(renewed.length) !== __normalize(forms.length))) {
222
+ throw "UiInvalidPingResponse";
223
+ }
224
+ let tokens = [];
225
+ for (const form of forms) {
226
+ let matched = null;
227
+ for (const candidate of renewed) {
228
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(candidate))) || __requireBoolean(!__requireBoolean(__isString(__normalize(candidate.token))))) || __requireBoolean(__normalize(candidate.token) === "")) || __requireBoolean(candidate.token.length > 16384))) {
229
+ throw "UiInvalidPingResponse";
230
+ }
231
+ if (__requireBoolean(__normalize(candidate.formId) === __normalize(form.formId))) {
232
+ if (__requireBoolean(matched !== null)) {
233
+ throw "UiInvalidPingResponse";
234
+ }
235
+ matched = __normalize(candidate.token);
236
+ }
237
+ }
238
+ if (__requireBoolean(matched === null)) {
239
+ throw "UiInvalidPingResponse";
240
+ }
241
+ tokens.push(matched);
242
+ }
243
+ for (const [index, session] of __entries(participants)) {
244
+ __normalize(session.receiveToken(__normalize(tokens[index])));
245
+ }
246
+ return result;
247
+ return null;
248
+ }
249
+ finish() {
250
+ this.#running = null;
251
+ this.#lastActivity = __normalize(this.#clock.now());
252
+ this.release();
253
+ return this.schedule();
254
+ return null;
255
+ }
256
+ release() {
257
+ let resume = __normalize(this.#resume);
258
+ this.#resume = null;
259
+ if (__requireBoolean(resume !== null)) {
260
+ __call(resume, null);
261
+ }
262
+ return null;
263
+ return null;
264
+ }
265
+ dispose() {
266
+ this.#disposed = true;
267
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
268
+ __normalize(this.#clock.cancel(__normalize(this.#timer)));
269
+ this.#timer = null;
270
+ }
271
+ this.release();
272
+ return null;
273
+ return null;
274
+ }
275
+ }
276
+
277
+ class SystemClock {
278
+ now() {
279
+ return __normalize(__hostGlobal(["performance"]).now());
280
+ return null;
281
+ }
282
+ schedule(callback, delay) {
283
+ __requireArity(arguments.length, [0, 1], "schedule");
284
+ callback = __boundary(callback);
285
+ delay = __boundary(delay);
286
+ return __hostGlobalCall(["setTimeout"], callback, delay);
287
+ return null;
288
+ }
289
+ cancel(timer) {
290
+ __requireArity(arguments.length, [0], "cancel");
291
+ timer = __boundary(timer);
292
+ __hostGlobalCall(["clearTimeout"], timer);
293
+ return null;
294
+ return null;
295
+ }
296
+ }
297
+ function postPing(path, input) {
298
+ __requireArity(arguments.length, [0, 1], "postPing");
299
+ path = __boundary(path);
300
+ input = __boundary(input);
301
+ return __hostGlobalCall(["fetch"], path, { method: "POST", headers: { "Content-Type": "application/json" }, body: __toJson(input), cache: "no-store", redirect: "error" }).then(__withArity((response) => {
302
+ response = __boundary(response);
303
+ return readPingResponse(response);
304
+ return null;
305
+ }, [0], "closure"));
306
+ return null;
307
+ }
308
+
309
+ function readPingResponse(response) {
310
+ __requireArity(arguments.length, [0], "readPingResponse");
311
+ response = __boundary(response);
312
+ return __normalize(response.json()).then(__withArity((body) => {
313
+ body = __boundary(body);
314
+ return pingBody(response, body);
315
+ return null;
316
+ }, [0], "closure"));
317
+ return null;
318
+ }
319
+
320
+ function pingBody(response, body) {
321
+ __requireArity(arguments.length, [0, 1], "pingBody");
322
+ response = __boundary(response);
323
+ body = __boundary(body);
324
+ if (__requireBoolean(!__requireBoolean(__normalize(response.ok)))) {
325
+ throw `UiPingHttpError: ${__normalize(response.status)}`;
326
+ }
327
+ return body;
328
+ return null;
329
+ }
330
+ //# sourceMappingURL=heartbeat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heartbeat.mjs","sources":["heartbeat.lango"],"sourcesContent":["import js global Promise\nimport js global performance\nimport js global setTimeout\nimport js global clearTimeout\nimport js global fetch\n\nexport class Heartbeat\n methods\n sessions(sessions)\n start()\n activity()\n schedule()\n tick()\n ping()\n gate()\n suspend(resolve)\n renew(entries, participants)\n accept(result, forms, participants)\n finish()\n release()\n dispose()\n\nHeartbeat(options)\n @path = options.path\n if @path == null\n @path = \"/_lango/ping\"\n if !is_string(@path) or !@path.startsWith(\"/\") or @path.startsWith(\"//\") or @path.includes(\"\\\\\")\n throw \"UiPingRequiresSameOriginPath\"\n @idleMs = options.idleMs\n if @idleMs == null\n @idleMs = 60000\n if !is_number(@idleMs) or @idleMs < 1 or @idleMs % 1 != 0\n throw \"UiPingIdleMustBePositiveMilliseconds\"\n @clock = options.clock\n if @clock == null\n @clock = new SystemClock()\n @transport = options.transport\n @sessions = []\n @timer = null\n @running = null\n @resume = null\n @started = false\n @disposed = false\n @lastActivity = @clock.now()\n\nHeartbeat:sessions(sessions)\n @sessions = sessions.slice()\n return null\n\nHeartbeat:start()\n if @disposed\n throw \"UiPingDisposed\"\n @started = true\n return schedule()\n\nHeartbeat:activity()\n @lastActivity = @clock.now()\n return schedule()\n\nHeartbeat:schedule()\n if @timer != null\n @clock.cancel(@timer)\n @timer = null\n if @disposed or !@started or @running != null\n return null\n delay = @idleMs - (@clock.now() - @lastActivity)\n if delay < 1\n delay = 1\n callback = ()\n tick()\n @timer = @clock.schedule(callback, delay)\n return null\n\nHeartbeat:tick()\n @timer = null\n if @disposed\n return null\n if @clock.now() - @lastActivity < @idleMs\n return schedule()\n return ping().catch((error)\n context log\n log.warn(\"Token ping failed; existing form tokens are retained\")\n )\n\nHeartbeat:ping()\n if @disposed\n return Promise/resolve()\n if @running != null\n return @running\n if @timer != null\n @clock.cancel(@timer)\n @timer = null\n participants = @sessions.slice()\n barrier = gate()\n waiting = []\n for participants as session\n waiting.add(session.reservePing(barrier))\n ready = Promise/all(waiting)\n work = ready.then((entries)\n capture participants\n return renew(entries, participants)\n )\n running = work.finally(()\n finish()\n )\n @running = running\n return running\n\nHeartbeat:gate()\n gate = new Promise((resolve, reject)\n suspend(resolve)\n )\n return gate\n\nHeartbeat:suspend(resolve)\n @resume = resolve\n return null\n\nHeartbeat:renew(entries, participants)\n if @disposed\n return null\n forms = []\n selected = []\n for entries as index: entry\n if entry != null\n forms.add(entry)\n selected.add(participants[index])\n if forms.length == 0\n return null\n if forms.length > 256\n throw \"UiPingTooManyForms\"\n input = {\n forms: forms\n }\n pending = null\n if @transport == null\n pending = postPing(@path, input)\n else\n pending = @transport.send(@path, input)\n return pending.then((result)\n capture forms\n capture selected\n return accept(result, forms, selected)\n )\n\nHeartbeat:accept(result, forms, participants)\n if @disposed\n return null\n if !is_object(result) or !is_array(result.forms)\n throw \"UiInvalidPingResponse\"\n renewed = result.forms\n if renewed.length != forms.length\n throw \"UiInvalidPingResponse\"\n tokens = []\n for forms as form\n matched = null\n for renewed as candidate\n if !is_object(candidate) or !is_string(candidate.token) or candidate.token == \"\" or candidate.token.length > 16384\n throw \"UiInvalidPingResponse\"\n if candidate.formId == form.formId\n if matched != null\n throw \"UiInvalidPingResponse\"\n matched = candidate.token\n if matched == null\n throw \"UiInvalidPingResponse\"\n tokens.add(matched)\n for participants as index: session\n session.receiveToken(tokens[index])\n return result\n\nHeartbeat:finish()\n @running = null\n @lastActivity = @clock.now()\n release()\n return schedule()\n\nHeartbeat:release()\n resume = @resume\n @resume = null\n if resume != null\n resume(null)\n return null\n\nHeartbeat:dispose()\n @disposed = true\n if @timer != null\n @clock.cancel(@timer)\n @timer = null\n release()\n return null\n\npostPing(path, input)\n return fetch(path, {\n method: \"POST\"\n headers: {\n \"Content-Type\": \"application/json\"\n }\n body: to_json(input)\n cache: \"no-store\"\n redirect: \"error\"\n }).then((response)\n return readPingResponse(response)\n )\n\nreadPingResponse(response)\n return response.json().then((body)\n capture response\n return pingBody(response, body)\n )\n\npingBody(response, body)\n if !response.ok\n throw \"UiPingHttpError: ${response.status}\"\n return body\n\nclass SystemClock\n methods\n now()\n schedule(callback, delay)\n cancel(timer)\n\nSystemClock:now()\n return performance.now()\n\nSystemClock:schedule(callback, delay)\n return setTimeout(callback, delay)\n\nSystemClock:cancel(timer)\n clearTimeout(timer)\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNA;;;;;;;;;;;;;;;;;;;;AAxBA;;;;;;;;;;;;AAaA;;;;;;;;;;;AAMA;;;;;;;;;;;"}
@@ -0,0 +1,240 @@
1
+ import {
2
+ fromJson as __fromJson,
3
+ toJson as __toJson,
4
+ isNumber as __isNumber,
5
+ isString as __isString,
6
+ isBool as __isBool,
7
+ isObject as __isObject,
8
+ isArray as __isArray,
9
+ entries as __entries,
10
+ add as __add,
11
+ requireBoolean as __requireBoolean,
12
+ normalize as __normalize,
13
+ finite as __finite,
14
+ boundary as __boundary,
15
+ requireArity as __requireArity,
16
+ } from "./.lango/runtime.mjs";
17
+
18
+ class InheritedValue {
19
+ name;
20
+ controls;
21
+ inherited;
22
+ writable;
23
+ #source;
24
+ constructor(name, source, writable) {
25
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
26
+ name = __boundary(name);
27
+ source = __boundary(source);
28
+ writable = __boundary(writable);
29
+ this.name = name;
30
+ this.#source = source;
31
+ this.inherited = true;
32
+ this.writable = writable;
33
+ this.controls = null;
34
+ if (__requireBoolean(source.element.langoFormRoot === true)) {
35
+ throw "UiInheritanceCrossesFormBoundary";
36
+ }
37
+ if (__requireBoolean(__isArray(__normalize(source.controls)))) {
38
+ this.controls = [];
39
+ for (const child of __normalize(source.controls)) {
40
+ this.controls.push(new InheritedValue(__normalize(child.name), child, writable));
41
+ }
42
+ }
43
+ }
44
+ getValue() {
45
+ return __fromJson(__toJson(__normalize(this.#source.getValue())));
46
+ return null;
47
+ }
48
+ setValue(value) {
49
+ __requireArity(arguments.length, [0], "setValue");
50
+ value = __boundary(value);
51
+ if (__requireBoolean(!__requireBoolean(__normalize(this.writable)))) {
52
+ throw "UiInheritedValueReadOnly";
53
+ }
54
+ __normalize(this.#source.setValue(__fromJson(__toJson(value))));
55
+ return null;
56
+ return null;
57
+ }
58
+ snapshotState() {
59
+ if (__requireBoolean(__normalize(this.#source.snapshotState) !== null)) {
60
+ return { custom: true, value: __normalize(this.#source.snapshotState()) };
61
+ }
62
+ return { custom: false, value: this.getValue() };
63
+ return null;
64
+ }
65
+ restoreState(snapshot) {
66
+ __requireArity(arguments.length, [0], "restoreState");
67
+ snapshot = __boundary(snapshot);
68
+ if (__requireBoolean(__normalize(snapshot.custom))) {
69
+ return __normalize(this.#source.restoreState(__normalize(snapshot.value)));
70
+ }
71
+ return this.setValue(__normalize(snapshot.value));
72
+ return null;
73
+ }
74
+ isDirty() {
75
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.writable))) || __requireBoolean(__normalize(this.#source.isDirty) === null))) {
76
+ return false;
77
+ }
78
+ return __normalize(this.#source.isDirty());
79
+ return null;
80
+ }
81
+ validate() {
82
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.writable))) || __requireBoolean(__normalize(this.#source.validate) === null))) {
83
+ return null;
84
+ }
85
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#source.element.disabled) === true) || __requireBoolean(__normalize(this.#source.element.hidden) === true)) || __requireBoolean(__normalize(this.#source.element.inert) === true))) {
86
+ return null;
87
+ }
88
+ return __normalize(this.#source.validate());
89
+ return null;
90
+ }
91
+ reportValidity() {
92
+ if (__requireBoolean(__normalize(this.#source.reportValidity) !== null)) {
93
+ return __normalize(this.#source.reportValidity());
94
+ }
95
+ return true;
96
+ return null;
97
+ }
98
+ reportPendingError() {
99
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.writable))) || __requireBoolean(__normalize(this.#source.reportPendingError) === null))) {
100
+ return false;
101
+ }
102
+ return __normalize(this.#source.reportPendingError());
103
+ return null;
104
+ }
105
+ applyProperty(name, value) {
106
+ __requireArity(arguments.length, [0, 1], "applyProperty");
107
+ name = __boundary(name);
108
+ value = __boundary(value);
109
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.writable))) || __requireBoolean(__requireBoolean(name !== "savedValue") && __requireBoolean(name !== "error"))) || __requireBoolean(__normalize(this.#source.applyProperty) === null))) {
110
+ throw "UiInheritedCommandNotAllowed";
111
+ }
112
+ return __normalize(this.#source.applyProperty(name, value));
113
+ return null;
114
+ }
115
+ }
116
+ function validName(name) {
117
+ __requireArity(arguments.length, [0], "validName");
118
+ name = __boundary(name);
119
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(name === "__proto__")) || __requireBoolean(name === "constructor")) || __requireBoolean(name === "prototype")) || __requireBoolean(name === "value")) || __requireBoolean(name === "then"))) {
120
+ throw "UiInvalidInheritedName";
121
+ }
122
+ return null;
123
+ return null;
124
+ }
125
+
126
+ export function normalizeInheritance(spec) {
127
+ __requireArity(arguments.length, [0], "normalizeInheritance");
128
+ spec = __boundary(spec);
129
+ let result = { };
130
+ if (__requireBoolean(spec === null)) {
131
+ return result;
132
+ }
133
+ if (__requireBoolean(!__requireBoolean(__isObject(spec)))) {
134
+ throw "UiInheritanceMustBeMap";
135
+ }
136
+ for (const [alias, entry] of __entries(spec)) {
137
+ validName(alias);
138
+ let path = entry;
139
+ let writable = false;
140
+ if (__requireBoolean(__isObject(entry))) {
141
+ for (const [name, value] of __entries(entry)) {
142
+ if (__requireBoolean(__requireBoolean(name !== "path") && __requireBoolean(name !== "writable"))) {
143
+ throw "UiUnknownInheritanceOption";
144
+ }
145
+ }
146
+ path = __normalize(entry.path);
147
+ if (__requireBoolean(__normalize(entry.writable) !== null)) {
148
+ if (__requireBoolean(!__requireBoolean(__isBool(__normalize(entry.writable))))) {
149
+ throw "UiInheritanceWritableMustBeBoolean";
150
+ }
151
+ writable = __normalize(entry.writable);
152
+ }
153
+ }
154
+ if (__requireBoolean(__isString(path))) {
155
+ path = [path];
156
+ }
157
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(path))) || __requireBoolean(__normalize(path.length) === 0))) {
158
+ throw "UiInheritanceRequiresPath";
159
+ }
160
+ for (const name of path) {
161
+ validName(name);
162
+ }
163
+ result[alias] = { path: __normalize(path.slice()), writable: writable };
164
+ }
165
+ return result;
166
+ return null;
167
+ }
168
+
169
+ export function inheritedControls(form, parent) {
170
+ __requireArity(arguments.length, [0, 1], "inheritedControls");
171
+ form = __boundary(form);
172
+ parent = __boundary(parent);
173
+ let result = __normalize(form.controls.slice());
174
+ for (const [alias, entry] of __entries(__normalize(form.inherit))) {
175
+ if (__requireBoolean(parent === null)) {
176
+ throw "UiInheritanceRequiresParentForm";
177
+ }
178
+ for (const control of __normalize(form.controls)) {
179
+ if (__requireBoolean(__normalize(control.name) === alias)) {
180
+ throw `UiInheritedNameCollision: ${alias}`;
181
+ }
182
+ }
183
+ let source = findSource(__normalize(parent.controls), __normalize(entry.path));
184
+ __add(result, new InheritedValue(alias, source, __normalize(entry.writable)));
185
+ }
186
+ return result;
187
+ return null;
188
+ }
189
+
190
+ function findSource(controls, path) {
191
+ __requireArity(arguments.length, [0, 1], "findSource");
192
+ controls = __boundary(controls);
193
+ path = __boundary(path);
194
+ let current = controls;
195
+ let target = null;
196
+ for (const [index, name] of __entries(path)) {
197
+ target = null;
198
+ for (const control of current) {
199
+ if (__requireBoolean(__normalize(control.name) === name)) {
200
+ target = control;
201
+ }
202
+ }
203
+ if (__requireBoolean(target === null)) {
204
+ throw `UiInheritedSourceNotFound: ${name}`;
205
+ }
206
+ if (__requireBoolean(target.element.langoFormRoot === true)) {
207
+ throw "UiInheritanceCrossesFormBoundary";
208
+ }
209
+ if (__requireBoolean(index < __finite(__normalize(path.length) - 1))) {
210
+ current = __normalize(target.controls);
211
+ if (__requireBoolean(!__requireBoolean(__isArray(current)))) {
212
+ throw "UiInheritedSourceIsNotContainer";
213
+ }
214
+ }
215
+ }
216
+ return target;
217
+ return null;
218
+ }
219
+
220
+ export function inheritanceResources(path, parentPath, spec) {
221
+ __requireArity(arguments.length, [0, 1, 2], "inheritanceResources");
222
+ path = __boundary(path);
223
+ parentPath = __boundary(parentPath);
224
+ spec = __boundary(spec);
225
+ let reads = [];
226
+ let writes = [path];
227
+ for (const [alias, entry] of __entries(spec)) {
228
+ if (__requireBoolean(parentPath === null)) {
229
+ throw "UiInheritanceRequiresParentForm";
230
+ }
231
+ let source = __normalize(parentPath.concat(__normalize(entry.path)));
232
+ reads.push(source);
233
+ if (__requireBoolean(__normalize(entry.writable))) {
234
+ writes.push(source);
235
+ }
236
+ }
237
+ return { reads: reads, writes: writes };
238
+ return null;
239
+ }
240
+ //# sourceMappingURL=inheritance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inheritance.mjs","sources":["inheritance.lango"],"sourcesContent":["export normalizeInheritance(spec)\nexport inheritedControls(form, parent)\nexport inheritanceResources(path, parentPath, spec)\n\nvalidName(name)\n if !is_string(name) or name == \"\" or name == \"__proto__\" or name == \"constructor\" or name == \"prototype\" or name == \"value\" or name == \"then\"\n throw \"UiInvalidInheritedName\"\n return null\n\nnormalizeInheritance(spec)\n result = {\n }\n if spec == null\n return result\n if !is_object(spec)\n throw \"UiInheritanceMustBeMap\"\n for spec as alias: entry\n validName(alias)\n path = entry\n writable = false\n if is_object(entry)\n for entry as name: value\n if name != \"path\" and name != \"writable\"\n throw \"UiUnknownInheritanceOption\"\n path = entry.path\n if entry.writable != null\n if !is_bool(entry.writable)\n throw \"UiInheritanceWritableMustBeBoolean\"\n writable = entry.writable\n if is_string(path)\n path = [path]\n if !is_array(path) or path.length == 0\n throw \"UiInheritanceRequiresPath\"\n for path as name\n validName(name)\n result[alias] = {\n path: path.slice()\n writable: writable\n }\n return result\n\ninheritedControls(form, parent)\n result = form.controls.slice()\n for form.inherit as alias: entry\n if parent == null\n throw \"UiInheritanceRequiresParentForm\"\n for form.controls as control\n if control.name == alias\n throw \"UiInheritedNameCollision: ${alias}\"\n source = findSource(parent.controls, entry.path)\n result.add(new InheritedValue(alias, source, entry.writable))\n return result\n\nfindSource(controls, path)\n current = controls\n target = null\n for path as index: name\n target = null\n for current as control\n if control.name == name\n target = control\n if target == null\n throw \"UiInheritedSourceNotFound: ${name}\"\n if target.element.langoFormRoot == true\n throw \"UiInheritanceCrossesFormBoundary\"\n if index < path.length - 1\n current = target.controls\n if !is_array(current)\n throw \"UiInheritedSourceIsNotContainer\"\n return target\n\ninheritanceResources(path, parentPath, spec)\n reads = []\n writes = [path]\n for spec as alias: entry\n if parentPath == null\n throw \"UiInheritanceRequiresParentForm\"\n source = parentPath.concat(entry.path)\n reads.add(source)\n if entry.writable\n writes.add(source)\n return {\n reads: reads\n writes: writes\n }\n\nclass InheritedValue\n properties\n name\n controls\n inherited\n writable\n methods\n getValue()\n setValue(value)\n snapshotState()\n restoreState(snapshot)\n isDirty()\n validate()\n reportValidity()\n reportPendingError()\n applyProperty(name, value)\n\nInheritedValue(name, source, writable)\n @name = name\n @source = source\n @inherited = true\n @writable = writable\n @controls = null\n if source.element.langoFormRoot == true\n throw \"UiInheritanceCrossesFormBoundary\"\n if is_array(source.controls)\n @controls = []\n for source.controls as child\n @controls.add(new InheritedValue(child.name, child, writable))\n\nInheritedValue:getValue()\n return from_json(to_json(@source.getValue()))\n\nInheritedValue:setValue(value)\n if !@writable\n throw \"UiInheritedValueReadOnly\"\n @source.setValue(from_json(to_json(value)))\n return null\n\nInheritedValue:snapshotState()\n if @source.snapshotState != null\n return {\n custom: true\n value: @source.snapshotState()\n }\n return {\n custom: false\n value: getValue()\n }\n\nInheritedValue:restoreState(snapshot)\n if snapshot.custom\n return @source.restoreState(snapshot.value)\n return setValue(snapshot.value)\n\nInheritedValue:isDirty()\n if !@writable or @source.isDirty == null\n return false\n return @source.isDirty()\n\nInheritedValue:validate()\n if !@writable or @source.validate == null\n return null\n if @source.element.disabled == true or @source.element.hidden == true or @source.element.inert == true\n return null\n return @source.validate()\n\nInheritedValue:reportValidity()\n if @source.reportValidity != null\n return @source.reportValidity()\n return true\n\nInheritedValue:reportPendingError()\n if !@writable or @source.reportPendingError == null\n return false\n return @source.reportPendingError()\n\nInheritedValue:applyProperty(name, value)\n if !@writable or (name != \"savedValue\" and name != \"error\") or @source.applyProperty == null\n throw \"UiInheritedCommandNotAllowed\"\n return @source.applyProperty(name, value)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAsFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAlFA;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,65 @@
1
+ import {
2
+ isNumber as __isNumber,
3
+ isString as __isString,
4
+ isBool as __isBool,
5
+ isObject as __isObject,
6
+ isArray as __isArray,
7
+ entries as __entries,
8
+ requireBoolean as __requireBoolean,
9
+ normalize as __normalize,
10
+ finite as __finite,
11
+ boundary as __boundary,
12
+ requireArity as __requireArity,
13
+ } from "./.lango/runtime.mjs";
14
+
15
+ export function selectItems(options) {
16
+ __requireArity(arguments.length, [0], "selectItems");
17
+ options = __boundary(options);
18
+ if (__requireBoolean(options === null)) {
19
+ return [];
20
+ }
21
+ if (__requireBoolean(!__requireBoolean(__isArray(options)))) {
22
+ throw "UiSelectOptionsMustBeArray";
23
+ }
24
+ let items = [];
25
+ let values = [];
26
+ for (const option of options) {
27
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(option))) || __requireBoolean(!__requireBoolean(__isString(__normalize(option.value))))) || __requireBoolean(!__requireBoolean(__isString(__normalize(option.text)))))) {
28
+ throw "UiSelectOptionRequiresValueAndText";
29
+ }
30
+ if (__requireBoolean(__normalize(values.includes(__normalize(option.value))))) {
31
+ throw "UiSelectDuplicateValue";
32
+ }
33
+ let disabled = __normalize(option.disabled);
34
+ if (__requireBoolean(disabled === null)) {
35
+ disabled = false;
36
+ }
37
+ if (__requireBoolean(!__requireBoolean(__isBool(disabled)))) {
38
+ throw "UiSelectOptionDisabledMustBeBoolean";
39
+ }
40
+ values.push(__normalize(option.value));
41
+ items.push({ value: __normalize(option.value), text: __normalize(option.text), disabled: disabled });
42
+ }
43
+ return items;
44
+ return null;
45
+ }
46
+
47
+ export function selectIndex(items, value) {
48
+ __requireArity(arguments.length, [0, 1], "selectIndex");
49
+ items = __boundary(items);
50
+ value = __boundary(value);
51
+ if (__requireBoolean(value === null)) {
52
+ return __finite(-1);
53
+ }
54
+ if (__requireBoolean(!__requireBoolean(__isString(value)))) {
55
+ throw "UiSelectValueMustBeStringOrNull";
56
+ }
57
+ for (const [index, item] of __entries(items)) {
58
+ if (__requireBoolean(__normalize(item.value) === value)) {
59
+ return index;
60
+ }
61
+ }
62
+ throw "UiSelectValueNotInOptions";
63
+ return null;
64
+ }
65
+ //# sourceMappingURL=input_values.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input_values.mjs","sources":["input_values.lango"],"sourcesContent":["export selectItems(options)\nexport selectIndex(items, value)\n\nselectItems(options)\n if options == null\n return []\n if !is_array(options)\n throw \"UiSelectOptionsMustBeArray\"\n items = []\n values = []\n for options as option\n if !is_object(option) or !is_string(option.value) or !is_string(option.text)\n throw \"UiSelectOptionRequiresValueAndText\"\n if values.includes(option.value)\n throw \"UiSelectDuplicateValue\"\n disabled = option.disabled\n if disabled == null\n disabled = false\n if !is_bool(disabled)\n throw \"UiSelectOptionDisabledMustBeBoolean\"\n values.add(option.value)\n items.add({\n value: option.value\n text: option.text\n disabled: disabled\n })\n return items\n\nselectIndex(items, value)\n if value == null\n return -1\n if !is_string(value)\n throw \"UiSelectValueMustBeStringOrNull\"\n for items as index: item\n if item.value == value\n return index\n throw \"UiSelectValueNotInOptions\"\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;;;;;;;"}