@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.
Files changed (232) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +571 -855
  4. package/cli/.lango/localization.mjs +108 -0
  5. package/{dist/node → cli}/.lango/runtime.mjs +112 -19
  6. package/cli/.lango/vendor/i18next.LICENSE +21 -0
  7. package/cli/.lango/vendor/i18next.mjs +2434 -0
  8. package/cli/create.mjs +62 -0
  9. package/cli/create.mjs.map +1 -0
  10. package/dist/.lango/localization.mjs +108 -0
  11. package/dist/.lango/runtime.mjs +112 -19
  12. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  13. package/dist/.lango/vendor/i18next.mjs +2434 -0
  14. package/dist/accordion.mjs +277 -0
  15. package/dist/accordion.mjs.map +1 -0
  16. package/dist/activities.mjs +185 -0
  17. package/dist/activities.mjs.map +1 -0
  18. package/dist/app.mjs +636 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/boot.mjs +24 -0
  21. package/dist/boot.mjs.map +1 -0
  22. package/dist/bootstrap-LICENSE +21 -0
  23. package/dist/bootstrap.min.css +6 -0
  24. package/dist/bootstrap.min.css.map +1 -0
  25. package/dist/button.mjs +77 -0
  26. package/dist/button.mjs.map +1 -0
  27. package/dist/chip.mjs +134 -0
  28. package/dist/chip.mjs.map +1 -0
  29. package/dist/client.css +95 -0
  30. package/dist/collections.mjs +77 -0
  31. package/dist/collections.mjs.map +1 -0
  32. package/dist/combo_box.mjs +408 -0
  33. package/dist/combo_box.mjs.map +1 -0
  34. package/dist/content.mjs +123 -0
  35. package/dist/content.mjs.map +1 -0
  36. package/dist/control.mjs +139 -0
  37. package/dist/control.mjs.map +1 -0
  38. package/dist/date_input.mjs +242 -0
  39. package/dist/date_input.mjs.map +1 -0
  40. package/dist/error_reporter.mjs +136 -0
  41. package/dist/error_reporter.mjs.map +1 -0
  42. package/dist/fields.mjs +454 -0
  43. package/dist/fields.mjs.map +1 -0
  44. package/dist/file_input.mjs +227 -0
  45. package/dist/file_input.mjs.map +1 -0
  46. package/dist/form.mjs +272 -0
  47. package/dist/form.mjs.map +1 -0
  48. package/dist/heartbeat.mjs +167 -254
  49. package/dist/heartbeat.mjs.map +1 -1
  50. package/dist/index.html +18 -0
  51. package/dist/indicators.mjs +127 -0
  52. package/dist/indicators.mjs.map +1 -0
  53. package/dist/input_changes.mjs +58 -0
  54. package/dist/input_changes.mjs.map +1 -0
  55. package/dist/input_group.mjs +38 -0
  56. package/dist/input_group.mjs.map +1 -0
  57. package/dist/layouts.mjs +195 -0
  58. package/dist/layouts.mjs.map +1 -0
  59. package/dist/library.mjs +130 -775
  60. package/dist/library.mjs.map +1 -1
  61. package/dist/longpoll.mjs +254 -0
  62. package/dist/longpoll.mjs.map +1 -0
  63. package/dist/main.mjs +138 -0
  64. package/dist/main.mjs.map +1 -0
  65. package/dist/markdown.mjs +61 -0
  66. package/dist/markdown.mjs.map +1 -0
  67. package/dist/menus.mjs +468 -0
  68. package/dist/menus.mjs.map +1 -0
  69. package/dist/navigation.mjs +260 -410
  70. package/dist/navigation.mjs.map +1 -1
  71. package/dist/numeric_input.mjs +181 -0
  72. package/dist/numeric_input.mjs.map +1 -0
  73. package/dist/otp_input.mjs +113 -0
  74. package/dist/otp_input.mjs.map +1 -0
  75. package/dist/presentations.mjs +852 -0
  76. package/dist/presentations.mjs.map +1 -0
  77. package/dist/renderer.mjs +293 -0
  78. package/dist/renderer.mjs.map +1 -0
  79. package/dist/rich_content.mjs +99 -0
  80. package/dist/rich_content.mjs.map +1 -0
  81. package/dist/tables.mjs +369 -0
  82. package/dist/tables.mjs.map +1 -0
  83. package/dist/tabs.mjs +205 -0
  84. package/dist/tabs.mjs.map +1 -0
  85. package/dist/templates.mjs +46 -0
  86. package/dist/templates.mjs.map +1 -0
  87. package/dist/vendor/DOMPurify-LICENSE +202 -0
  88. package/dist/vendor/dompurify.mjs +2540 -0
  89. package/dist/vendor/flatpickr-LICENSE.md +21 -0
  90. package/dist/vendor/flatpickr.min.css +13 -0
  91. package/dist/vendor/flatpickr.mjs +2340 -0
  92. package/dist/vendor/flatpickr.mjs.map +7 -0
  93. package/dist/vendor/marked-LICENSE.md +44 -0
  94. package/dist/vendor/marked.esm.js.map +7 -0
  95. package/dist/vendor/marked.mjs +85 -0
  96. package/dist/vendor/purify.es.mjs.map +1 -0
  97. package/dist/widgets.mjs +197 -0
  98. package/dist/widgets.mjs.map +1 -0
  99. package/docs/implementation.md +42 -0
  100. package/package.json +26 -40
  101. package/src/accordion.lango +198 -0
  102. package/src/activities.lango +132 -0
  103. package/src/app.lango +508 -0
  104. package/src/boot.lango +12 -0
  105. package/src/button.lango +49 -0
  106. package/src/chip.lango +94 -0
  107. package/src/collections.lango +46 -0
  108. package/src/combo_box.lango +298 -0
  109. package/src/content.lango +75 -0
  110. package/src/control.lango +100 -0
  111. package/src/create.lango +42 -0
  112. package/src/date_input.lango +215 -0
  113. package/src/error_reporter.lango +95 -0
  114. package/src/fields.lango +327 -0
  115. package/src/file_input.lango +175 -0
  116. package/src/form.lango +195 -0
  117. package/src/heartbeat.lango +136 -199
  118. package/src/indicators.lango +94 -0
  119. package/src/input_changes.lango +33 -0
  120. package/src/input_group.lango +22 -0
  121. package/src/layouts.lango +137 -0
  122. package/src/library.lango +194 -571
  123. package/src/longpoll.lango +187 -0
  124. package/src/main.lango +109 -0
  125. package/src/markdown.lango +48 -0
  126. package/src/menus.lango +336 -0
  127. package/src/navigation.lango +209 -299
  128. package/src/numeric_input.lango +131 -0
  129. package/src/otp_input.lango +83 -0
  130. package/src/presentations.lango +617 -0
  131. package/src/renderer.lango +288 -0
  132. package/src/rich_content.lango +66 -0
  133. package/src/tables.lango +271 -0
  134. package/src/tabs.lango +144 -0
  135. package/src/templates.lango +29 -0
  136. package/src/widgets.lango +141 -0
  137. package/web/client.css +95 -0
  138. package/web/index.html +18 -0
  139. package/dist/application.mjs +0 -429
  140. package/dist/application.mjs.map +0 -1
  141. package/dist/coordinator.mjs +0 -91
  142. package/dist/coordinator.mjs.map +0 -1
  143. package/dist/demo.mjs +0 -110
  144. package/dist/demo.mjs.map +0 -1
  145. package/dist/demo_controls.mjs +0 -59
  146. package/dist/demo_controls.mjs.map +0 -1
  147. package/dist/errors.mjs +0 -201
  148. package/dist/errors.mjs.map +0 -1
  149. package/dist/form_state.mjs +0 -266
  150. package/dist/form_state.mjs.map +0 -1
  151. package/dist/inheritance.mjs +0 -240
  152. package/dist/inheritance.mjs.map +0 -1
  153. package/dist/input_values.mjs +0 -65
  154. package/dist/input_values.mjs.map +0 -1
  155. package/dist/node/.lango/xmldom/conventions.js +0 -429
  156. package/dist/node/.lango/xmldom/dom-parser.js +0 -591
  157. package/dist/node/.lango/xmldom/dom.js +0 -3759
  158. package/dist/node/.lango/xmldom/entities.js +0 -2171
  159. package/dist/node/.lango/xmldom/errors.js +0 -205
  160. package/dist/node/.lango/xmldom/grammar.js +0 -559
  161. package/dist/node/.lango/xmldom/index.js +0 -41
  162. package/dist/node/.lango/xmldom/package.json +0 -1
  163. package/dist/node/.lango/xmldom/sax.js +0 -983
  164. package/dist/node/.lango/xmldom.LICENSE.md +0 -8
  165. package/dist/node/browser_host.mjs +0 -351
  166. package/dist/node/browser_host.mjs.map +0 -1
  167. package/dist/node/create_app.mjs +0 -118
  168. package/dist/node/create_app.mjs.map +0 -1
  169. package/dist/presentation.mjs +0 -89
  170. package/dist/presentation.mjs.map +0 -1
  171. package/dist/protocol.mjs +0 -706
  172. package/dist/protocol.mjs.map +0 -1
  173. package/dist/session.mjs +0 -431
  174. package/dist/session.mjs.map +0 -1
  175. package/dist/tokens.mjs +0 -298
  176. package/dist/tokens.mjs.map +0 -1
  177. package/examples/contacts.lango +0 -302
  178. package/examples/contacts_flow.lango +0 -174
  179. package/examples/contacts_store.lango +0 -109
  180. package/examples/contacts_store_test.lango +0 -65
  181. package/examples/demo.css +0 -72
  182. package/examples/demo_test.lango +0 -356
  183. package/examples/index.html +0 -28
  184. package/examples/pages.lango +0 -180
  185. package/examples/server.lango +0 -189
  186. package/examples/worker.lango +0 -142
  187. package/src/application.lango +0 -327
  188. package/src/browser_host.lango +0 -276
  189. package/src/coordinator.lango +0 -57
  190. package/src/demo.lango +0 -110
  191. package/src/demo_controls.lango +0 -53
  192. package/src/errors.lango +0 -149
  193. package/src/errors_test.lango +0 -157
  194. package/src/form_state.lango +0 -168
  195. package/src/heartbeat_test.lango +0 -479
  196. package/src/inheritance.lango +0 -167
  197. package/src/input_values.lango +0 -37
  198. package/src/logout_test.lango +0 -564
  199. package/src/navigation_test.lango +0 -556
  200. package/src/presentation.lango +0 -55
  201. package/src/protocol.lango +0 -787
  202. package/src/renderer_test.lango +0 -1986
  203. package/src/session.lango +0 -313
  204. package/src/session_test.lango +0 -455
  205. package/src/tabs_test.lango +0 -216
  206. package/src/tokens.lango +0 -215
  207. package/template/.vscode/extensions.json +0 -3
  208. package/template/.vscode/settings.json +0 -9
  209. package/template/README.md +0 -40
  210. package/template/gitignore +0 -4
  211. package/template/package.json +0 -22
  212. package/template/public/app.css +0 -4
  213. package/template/public/index.html +0 -24
  214. package/template/src/client.lango +0 -78
  215. package/template/src/pages.lango +0 -55
  216. package/template/src/server.lango +0 -24
  217. package/template/src/worker.lango +0 -77
  218. package/template/test/app.lango +0 -9
  219. package/tools/create_app.lango +0 -88
  220. package/tools/create_app_test.lango +0 -43
  221. package/tools/starter_test.lango +0 -227
  222. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  223. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  224. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  225. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  226. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  227. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  228. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  229. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  230. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  231. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  232. /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
@@ -1,59 +0,0 @@
1
- import { Control, Types } from "./library.mjs";
2
- import {
3
- requireBoolean as __requireBoolean,
4
- normalize as __normalize,
5
- boundary as __boundary,
6
- requireArity as __requireArity,
7
- } from "./.lango/runtime.mjs";
8
-
9
- export class DemoErrors {
10
- #element;
11
- constructor(element) {
12
- __requireArity(arguments.length, [0], "constructor");
13
- element = __boundary(element);
14
- this.#element = element;
15
- }
16
- clear() {
17
- this.#element.textContent = "";
18
- return null;
19
- }
20
- error(error) {
21
- __requireArity(arguments.length, [0], "error");
22
- error = __boundary(error);
23
- let text = "The request failed. Please try again.";
24
- if (__requireBoolean(error === "UiValidationFailed")) {
25
- text = "Please correct the highlighted fields before saving.";
26
- }
27
- this.#element.textContent = text;
28
- return null;
29
- }
30
- }
31
-
32
- class Label extends Control {
33
- constructor(document, definition, types) {
34
- super(document, definition, types, { tag: "p" });
35
- __requireArity(arguments.length, [0, 1, 2], "constructor");
36
- document = __boundary(document);
37
- definition = __boundary(definition);
38
- types = __boundary(types);
39
- }
40
- setValue(value) {
41
- __requireArity(arguments.length, [0], "setValue");
42
- value = __boundary(value);
43
- super.setValue(value);
44
- let text = value;
45
- if (__requireBoolean(text === null)) {
46
- text = "";
47
- }
48
- this.element.textContent = text;
49
- return null;
50
- return null;
51
- }
52
- }
53
- export function demoTypes() {
54
- let types = new Types({ classes: { Form: ["demo-form"], Text: ["demo-input"], Select: ["demo-input"], Checkbox: ["demo-checkbox"], Button: ["demo-button"], Label: ["demo-label"] } });
55
- __normalize(types.registerType("Label", Label));
56
- return types;
57
- return null;
58
- }
59
- //# sourceMappingURL=demo_controls.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"demo_controls.mjs","sources":["demo_controls.lango"],"sourcesContent":["import \"./library\"\n class Control\n class Types\n\nexport demoTypes()\n\nexport class DemoErrors\n methods\n clear()\n error(error)\n\nDemoErrors(element)\n @element = element\n\nDemoErrors:clear()\n @element.textContent = \"\"\n\nDemoErrors:error(error)\n text = \"The request failed. Please try again.\"\n if error == \"UiValidationFailed\"\n text = \"Please correct the highlighted fields before saving.\"\n @element.textContent = text\n\ndemoTypes()\n types = new Types({\n classes: {\n Form: [\"demo-form\"]\n Text: [\"demo-input\"]\n Select: [\"demo-input\"]\n Checkbox: [\"demo-checkbox\"]\n Button: [\"demo-button\"]\n Label: [\"demo-label\"]\n }\n })\n types.registerType(\"Label\", Label)\n return types\n\nclass Label : Control\n methods\n setValue(value)\n\nLabel(document, definition, types)\n super(document, definition, types, {\n tag: \"p\"\n })\n\nLabel:setValue(value)\n super.setValue(value)\n text = value\n if text == null\n text = \"\"\n @element.textContent = text\n return null\n"],"names":[],"mappings":";;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;AAdA;;;;;;;"}
package/dist/errors.mjs DELETED
@@ -1,201 +0,0 @@
1
- import {
2
- hostGlobal as __hostGlobal,
3
- hostGlobalCall as __hostGlobalCall,
4
- fromJson as __fromJson,
5
- toJson as __toJson,
6
- isNumber as __isNumber,
7
- isString as __isString,
8
- isBool as __isBool,
9
- isObject as __isObject,
10
- isArray as __isArray,
11
- add as __add,
12
- requireBoolean as __requireBoolean,
13
- normalize as __normalize,
14
- numericAdd as __numericAdd,
15
- boundary as __boundary,
16
- requireArity as __requireArity,
17
- withArity as __withArity,
18
- } from "./.lango/runtime.mjs";
19
-
20
- export class ErrorReporter {
21
- #window;
22
- #transport;
23
- #pending;
24
- #timer;
25
- #running;
26
- #disposed;
27
- #until;
28
- #sent;
29
- #onError;
30
- #onRejection;
31
- constructor(options) {
32
- __requireArity(arguments.length, [0], "constructor");
33
- options = __boundary(options);
34
- this.#window = __normalize(options.window);
35
- this.#transport = __normalize(options.transport);
36
- if (__requireBoolean(__normalize(this.#transport) === null)) {
37
- this.#transport = new ReportTransport();
38
- }
39
- this.#pending = [];
40
- this.#timer = null;
41
- this.#running = null;
42
- this.#disposed = false;
43
- this.#until = 0;
44
- this.#sent = 0;
45
- let onError = __withArity((event) => {
46
- event = __boundary(event);
47
- this.report("window");
48
- return null;
49
- }, [0], "closure");
50
- let onRejection = __withArity((event) => {
51
- event = __boundary(event);
52
- this.report("promise");
53
- return null;
54
- }, [0], "closure");
55
- this.#onError = onError;
56
- this.#onRejection = onRejection;
57
- if (__requireBoolean(__normalize(this.#window) !== null)) {
58
- __normalize(this.#window.addEventListener("error", __normalize(this.#onError)));
59
- __normalize(this.#window.addEventListener("unhandledrejection", __normalize(this.#onRejection)));
60
- }
61
- }
62
- error(error) {
63
- __requireArity(arguments.length, [0], "error");
64
- error = __boundary(error);
65
- let code = "UnexpectedError";
66
- if (__requireBoolean(__isString(error))) {
67
- if (__requireBoolean(__requireBoolean(error === "UiValidationFailed") || __requireBoolean(error === "UiSessionDisposed"))) {
68
- return null;
69
- }
70
- if (__requireBoolean(error === "UiProtocolUnsupported")) {
71
- code = "UiProtocolUnsupported";
72
- }
73
- if (__requireBoolean(__normalize(error.startsWith("UiHttpError:")))) {
74
- code = "UiHttpError";
75
- }
76
- }
77
- return this.report("ui", code);
78
- return null;
79
- }
80
- clear() {
81
- return null;
82
- return null;
83
- }
84
- report(source, code = "UnexpectedError") {
85
- __requireArity(arguments.length, [0], "report");
86
- source = __boundary(source);
87
- code = __boundary(code);
88
- if (__requireBoolean(__normalize(this.#disposed))) {
89
- return null;
90
- }
91
- let sources = ["window", "promise", "ui"];
92
- let codes = ["UnexpectedError", "UiProtocolUnsupported", "UiHttpError"];
93
- let origin = source;
94
- let category = code;
95
- if (__requireBoolean(!__requireBoolean(__normalize(sources.includes(origin))))) {
96
- origin = "ui";
97
- }
98
- if (__requireBoolean(!__requireBoolean(__normalize(codes.includes(category))))) {
99
- category = "UnexpectedError";
100
- }
101
- for (const entry of __normalize(this.#pending)) {
102
- if (__requireBoolean(__requireBoolean(__normalize(entry.source) === origin) && __requireBoolean(__normalize(entry.code) === category))) {
103
- if (__requireBoolean(__normalize(entry.count) < 100)) {
104
- entry.count = __numericAdd(__normalize(entry.count), 1);
105
- }
106
- this.#schedule();
107
- return null;
108
- }
109
- }
110
- __add(this.#pending, { version: 1, source: origin, code: category, count: 1 });
111
- this.#schedule();
112
- return null;
113
- return null;
114
- }
115
- #schedule() {
116
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(this.#timer) !== null)) || __requireBoolean(__normalize(this.#running) !== null)) || __requireBoolean(__normalize(this.#pending.length) === 0))) {
117
- return null;
118
- }
119
- let send = () => {
120
- this.flush();
121
- return null;
122
- };
123
- this.#timer = __hostGlobalCall(["setTimeout"], send, 1000);
124
- return null;
125
- return null;
126
- }
127
- flush() {
128
- __hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
129
- this.#timer = null;
130
- if (__requireBoolean(__normalize(this.#disposed))) {
131
- return __normalize(__hostGlobal(["Promise"]).resolve(null));
132
- }
133
- if (__requireBoolean(__normalize(this.#running) !== null)) {
134
- return __normalize(this.#running);
135
- }
136
- let now = __normalize(__hostGlobal(["performance"]).now());
137
- if (__requireBoolean(now >= __normalize(this.#until))) {
138
- this.#until = __numericAdd(now, 60000);
139
- this.#sent = 0;
140
- }
141
- let reports = __normalize(this.#pending);
142
- this.#pending = [];
143
- let pending = [];
144
- for (const entry of reports) {
145
- if (__requireBoolean(__normalize(this.#sent) < 10)) {
146
- this.#sent = __numericAdd(__normalize(this.#sent), 1);
147
- pending.push(sendReport(__normalize(this.#transport), entry));
148
- }
149
- }
150
- let joined = __normalize(__hostGlobal(["Promise"]).all(pending));
151
- let running = __normalize(joined.finally(() => {
152
- this.#running = null;
153
- this.#schedule();
154
- return null;
155
- }));
156
- this.#running = running;
157
- return __normalize(this.#running);
158
- return null;
159
- }
160
- dispose() {
161
- this.#disposed = true;
162
- __hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
163
- this.#timer = null;
164
- this.#pending = [];
165
- if (__requireBoolean(__normalize(this.#window) !== null)) {
166
- __normalize(this.#window.removeEventListener("error", __normalize(this.#onError)));
167
- __normalize(this.#window.removeEventListener("unhandledrejection", __normalize(this.#onRejection)));
168
- }
169
- return null;
170
- return null;
171
- }
172
- }
173
-
174
- class ReportTransport {
175
- send(report) {
176
- __requireArity(arguments.length, [0], "send");
177
- report = __boundary(report);
178
- let signal = __normalize(__hostGlobal(["AbortSignal"]).timeout(5000));
179
- return __hostGlobalCall(["fetch"], "/_lango/client-error", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "omit", cache: "no-store", referrerPolicy: "no-referrer", redirect: "error", signal: signal, body: __toJson(report) }).then(__withArity((response) => {
180
- response = __boundary(response);
181
- return null;
182
- return null;
183
- }, [0], "closure"));
184
- return null;
185
- }
186
- }
187
- function sendReport(transport, entry) {
188
- __requireArity(arguments.length, [0, 1], "sendReport");
189
- transport = __boundary(transport);
190
- entry = __boundary(entry);
191
- return __normalize(__hostGlobal(["Promise"]).resolve()).then(() => {
192
- return __normalize(transport.send(entry));
193
- return null;
194
- }).catch(__withArity((error) => {
195
- error = __boundary(error);
196
- return null;
197
- return null;
198
- }, [0], "closure"));
199
- return null;
200
- }
201
- //# sourceMappingURL=errors.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.mjs","sources":["errors.lango"],"sourcesContent":["import js global Promise\nimport js global performance\nimport js global setTimeout\nimport js global clearTimeout\nimport js global fetch\nimport js global AbortSignal\n\nexport class ErrorReporter\n methods\n error(error)\n clear()\n report(source, code = \"UnexpectedError\")\n flush()\n dispose()\n\nErrorReporter(options)\n @window = options.window\n @transport = options.transport\n if @transport == null\n @transport = new ReportTransport()\n @pending = []\n @timer = null\n @running = null\n @disposed = false\n @until = 0\n @sent = 0\n onError = (event)\n report(\"window\")\n onRejection = (event)\n report(\"promise\")\n @onError = onError\n @onRejection = onRejection\n if @window != null\n @window.addEventListener(\"error\", @onError)\n @window.addEventListener(\"unhandledrejection\", @onRejection)\n\nErrorReporter:error(error)\n code = \"UnexpectedError\"\n if is_string(error)\n if error == \"UiValidationFailed\" or error == \"UiSessionDisposed\"\n return null\n if error == \"UiProtocolUnsupported\"\n code = \"UiProtocolUnsupported\"\n if error.startsWith(\"UiHttpError:\")\n code = \"UiHttpError\"\n return report(\"ui\", code)\n\nErrorReporter:clear()\n return null\n\nErrorReporter:report(source, code = \"UnexpectedError\")\n if @disposed\n return null\n sources = [\"window\", \"promise\", \"ui\"]\n codes = [\"UnexpectedError\", \"UiProtocolUnsupported\", \"UiHttpError\"]\n origin = source\n category = code\n if !sources.includes(origin)\n origin = \"ui\"\n if !codes.includes(category)\n category = \"UnexpectedError\"\n for @pending as entry\n if entry.source == origin and entry.code == category\n if entry.count < 100\n entry.count = entry.count + 1\n schedule()\n return null\n @pending.add({\n version: 1\n source: origin\n code: category\n count: 1\n })\n schedule()\n return null\n\nErrorReporter:schedule()\n if @disposed or @timer != null or @running != null or @pending.length == 0\n return null\n send = ()\n flush()\n @timer = setTimeout(send, 1000)\n return null\n\nErrorReporter:flush()\n clearTimeout(@timer)\n @timer = null\n if @disposed\n return Promise/resolve(null)\n if @running != null\n return @running\n now = performance.now()\n if now >= @until\n @until = now + 60000\n @sent = 0\n reports = @pending\n @pending = []\n pending = []\n for reports as entry\n if @sent < 10\n @sent = @sent + 1\n pending.add(sendReport(@transport, entry))\n joined = Promise/all(pending)\n running = joined.finally(()\n @running = null\n schedule()\n )\n @running = running\n return @running\n\nsendReport(transport, entry)\n return Promise/resolve().then(()\n capture transport\n capture entry\n return transport.send(entry)\n ).catch((error)\n return null\n )\n\nErrorReporter:dispose()\n @disposed = true\n clearTimeout(@timer)\n @timer = null\n @pending = []\n if @window != null\n @window.removeEventListener(\"error\", @onError)\n @window.removeEventListener(\"unhandledrejection\", @onRejection)\n return null\n\nclass ReportTransport\n methods\n send(report)\n\nReportTransport:send(report)\n signal = AbortSignal/timeout(5000)\n return fetch(\"/_lango/client-error\", {\n method: \"POST\"\n headers: {\n \"Content-Type\": \"application/json\"\n }\n credentials: \"omit\"\n cache: \"no-store\"\n referrerPolicy: \"no-referrer\"\n redirect: \"error\"\n signal: signal\n body: to_json(report)\n }).then((response)\n return null\n )\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA;;;;;;;;;;;;;AAnBA;;;;;;;;;;;;;;;"}
@@ -1,266 +0,0 @@
1
- import {
2
- hostGlobal as __hostGlobal,
3
- getClass as __getClass,
4
- isKindof as __isKindof,
5
- isNumber as __isNumber,
6
- isString as __isString,
7
- isBool as __isBool,
8
- isObject as __isObject,
9
- isArray as __isArray,
10
- includes as __includes,
11
- entries as __entries,
12
- add as __add,
13
- requireBoolean as __requireBoolean,
14
- normalize as __normalize,
15
- finite as __finite,
16
- numericAdd as __numericAdd,
17
- boundary as __boundary,
18
- requireArity as __requireArity,
19
- } from "./.lango/runtime.mjs";
20
-
21
- export function rulesFor(value) {
22
- __requireArity(arguments.length, [0], "rulesFor");
23
- value = __boundary(value);
24
- if (__requireBoolean(value === null)) {
25
- return { };
26
- }
27
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(value))) || __requireBoolean(__isArray(value)))) {
28
- throw "UiValidationRequiresMap";
29
- }
30
- let rules = { };
31
- for (const [name, item] of __entries(value)) {
32
- if (name === "required") {
33
- if (__requireBoolean(!__requireBoolean(__isBool(item)))) {
34
- throw "UiValidationRequiredMustBeBoolean";
35
- }
36
- } else if (name === "minLength") {
37
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(item))) || __requireBoolean(item < 0)) || __requireBoolean(__finite(item % 1) !== 0))) {
38
- throw "UiValidationLengthMustBeNonnegativeInteger";
39
- }
40
- } else if (name === "maxLength") {
41
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(item))) || __requireBoolean(item < 0)) || __requireBoolean(__finite(item % 1) !== 0))) {
42
- throw "UiValidationLengthMustBeNonnegativeInteger";
43
- }
44
- } else if (name === "pattern") {
45
- if (__requireBoolean(!__requireBoolean(__isString(item)))) {
46
- throw "UiValidationPatternMustBeString";
47
- }
48
- let expression = new (__hostGlobal(["RegExp"]))(`^(?:${item})$`);
49
- } else if (name === "message") {
50
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(item))) || __requireBoolean(item === ""))) {
51
- throw "UiValidationMessageMustBeString";
52
- }
53
- } else {
54
- throw `UiUnknownValidationRule: ${name}`;
55
- }
56
- rules[name] = item;
57
- }
58
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(rules.minLength) !== null) && __requireBoolean(__normalize(rules.maxLength) !== null)) && __requireBoolean(__normalize(rules.minLength) > __normalize(rules.maxLength)))) {
59
- throw "UiValidationLengthRangeInvalid";
60
- }
61
- return rules;
62
- return null;
63
- }
64
-
65
- export function validationMessage(rules, value) {
66
- __requireArity(arguments.length, [0, 1], "validationMessage");
67
- rules = __boundary(rules);
68
- value = __boundary(value);
69
- let pattern;
70
- let empty = __requireBoolean(value === null) || __requireBoolean(value === false);
71
- if (__requireBoolean(__isString(value))) {
72
- empty = __normalize(value.trim()) === "";
73
- }
74
- let message = null;
75
- if (__requireBoolean(__requireBoolean(__normalize(rules.required) === true) && __requireBoolean(empty))) {
76
- message = "This field is required.";
77
- }
78
- if (__requireBoolean(!__requireBoolean(empty))) {
79
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(rules.minLength) !== null) || __requireBoolean(__normalize(rules.maxLength) !== null)) || __requireBoolean(__normalize(rules.pattern) !== null))) {
80
- if (__requireBoolean(!__requireBoolean(__isString(value)))) {
81
- message = "This value must be text.";
82
- } else {
83
- if (__requireBoolean(__requireBoolean(__normalize(rules.minLength) !== null) && __requireBoolean(__normalize(value.length) < __normalize(rules.minLength)))) {
84
- message = `Enter at least ${__normalize(rules.minLength)} characters.`;
85
- }
86
- if (__requireBoolean(__requireBoolean(__normalize(rules.maxLength) !== null) && __requireBoolean(__normalize(value.length) > __normalize(rules.maxLength)))) {
87
- message = `Enter at most ${__normalize(rules.maxLength)} characters.`;
88
- }
89
- if (__requireBoolean(__normalize(rules.pattern) !== null)) {
90
- pattern = new (__hostGlobal(["RegExp"]))(`^(?:${__normalize(rules.pattern)})$`);
91
- if (__requireBoolean(!__requireBoolean(__normalize(pattern.test(value))))) {
92
- message = "Enter a value in the required format.";
93
- }
94
- }
95
- }
96
- }
97
- }
98
- if (__requireBoolean(__requireBoolean(message !== null) && __requireBoolean(__normalize(rules.message) !== null))) {
99
- return __normalize(rules.message);
100
- }
101
- return message;
102
- return null;
103
- }
104
-
105
- export function sameValue(left, right) {
106
- __requireArity(arguments.length, [0, 1], "sameValue");
107
- left = __boundary(left);
108
- right = __boundary(right);
109
- let count;
110
- let other;
111
- if (__requireBoolean(__isArray(left))) {
112
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(right))) || __requireBoolean(__normalize(left.length) !== __normalize(right.length)))) {
113
- return false;
114
- }
115
- for (const [index, value] of __entries(left)) {
116
- if (__requireBoolean(!__requireBoolean(sameValue(value, __normalize(right[index]))))) {
117
- return false;
118
- }
119
- }
120
- return true;
121
- }
122
- if (__requireBoolean(__isObject(left))) {
123
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(right))) || __requireBoolean(__isArray(right)))) {
124
- return false;
125
- }
126
- count = 0;
127
- other = 0;
128
- for (const [name, value] of __entries(left)) {
129
- count = __numericAdd(count, 1);
130
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__includes(name, right))) || __requireBoolean(!__requireBoolean(sameValue(value, __normalize(right[name])))))) {
131
- return false;
132
- }
133
- }
134
- for (const [name, value] of __entries(right)) {
135
- other = __numericAdd(other, 1);
136
- }
137
- return count === other;
138
- }
139
- return left === right;
140
- return null;
141
- }
142
-
143
- export function ownedFields(controls) {
144
- __requireArity(arguments.length, [0], "ownedFields");
145
- controls = __boundary(controls);
146
- let result = [];
147
- collectFields(controls, [], result, false);
148
- return result;
149
- return null;
150
- }
151
-
152
- function collectFields(controls, parent, result, blocked) {
153
- __requireArity(arguments.length, [0, 1, 2, 3], "collectFields");
154
- controls = __boundary(controls);
155
- parent = __boundary(parent);
156
- result = __boundary(result);
157
- blocked = __boundary(blocked);
158
- for (const control of controls) {
159
- if (__requireBoolean(__requireBoolean(__normalize(control.element) !== null) && __requireBoolean(control.element.langoFormRoot === true))) {
160
- continue;
161
- }
162
- let path = __normalize(parent.slice());
163
- let unavailable = blocked;
164
- if (__requireBoolean(__normalize(control.element) !== null)) {
165
- unavailable = __requireBoolean(__requireBoolean(__requireBoolean(unavailable) || __requireBoolean(control.element.disabled === true)) || __requireBoolean(control.element.hidden === true)) || __requireBoolean(control.element.inert === true);
166
- }
167
- if (__requireBoolean(__requireBoolean(__normalize(control.name) !== null) && __requireBoolean(__normalize(control.name) !== ""))) {
168
- __add(path, __normalize(control.name));
169
- }
170
- if (__requireBoolean(__isArray(__normalize(control.controls)))) {
171
- collectFields(__normalize(control.controls), path, result, unavailable);
172
- } else {
173
- __add(result, { control: control, path: path, blocked: unavailable });
174
- }
175
- }
176
- return null;
177
- }
178
-
179
- export function dirtyFields(controls) {
180
- __requireArity(arguments.length, [0], "dirtyFields");
181
- controls = __boundary(controls);
182
- let fields = ownedFields(controls);
183
- for (const field of fields) {
184
- let control = __normalize(field.control);
185
- if (__requireBoolean(__isKindof(__normalize(control.isDirty), Function))) {
186
- if (__requireBoolean(__normalize(control.isDirty()))) {
187
- return true;
188
- }
189
- }
190
- }
191
- return false;
192
- return null;
193
- }
194
-
195
- export function validateFields(controls) {
196
- __requireArity(arguments.length, [0], "validateFields");
197
- controls = __boundary(controls);
198
- let issues = [];
199
- let fields = ownedFields(controls);
200
- for (const field of fields) {
201
- if (__requireBoolean(__normalize(field.blocked))) {
202
- continue;
203
- }
204
- let control = __normalize(field.control);
205
- if (__requireBoolean(__isKindof(__normalize(control.validate), Function))) {
206
- let message = __normalize(control.validate());
207
- if (__requireBoolean(message !== null)) {
208
- issues.push({ path: __normalize(field.path), message: message, control: __normalize(field.control) });
209
- }
210
- }
211
- }
212
- return issues;
213
- return null;
214
- }
215
-
216
- export function validatesRequest(controls, name) {
217
- __requireArity(arguments.length, [0, 1], "validatesRequest");
218
- controls = __boundary(controls);
219
- name = __boundary(name);
220
- let target = requestSource(controls, name);
221
- return __requireBoolean(target !== null) && __requireBoolean(__normalize(target.validates) === true);
222
- return null;
223
- }
224
-
225
- export function confirmsRequest(controls, name) {
226
- __requireArity(arguments.length, [0, 1], "confirmsRequest");
227
- controls = __boundary(controls);
228
- name = __boundary(name);
229
- let target = requestSource(controls, name);
230
- return __requireBoolean(target !== null) && __requireBoolean(__normalize(target.confirms) === true);
231
- return null;
232
- }
233
-
234
- function requestSource(controls, name) {
235
- __requireArity(arguments.length, [0, 1], "requestSource");
236
- controls = __boundary(controls);
237
- name = __boundary(name);
238
- let path = name;
239
- if (__requireBoolean(__isString(path))) {
240
- path = [path];
241
- }
242
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(path))) || __requireBoolean(__normalize(path.length) === 0))) {
243
- return null;
244
- }
245
- let current = controls;
246
- let target = null;
247
- for (const part of path) {
248
- if (__requireBoolean(!__requireBoolean(__isArray(current)))) {
249
- return null;
250
- }
251
- target = null;
252
- for (const control of current) {
253
- if (__requireBoolean(__normalize(control.name) === part)) {
254
- target = control;
255
- break;
256
- }
257
- }
258
- if (__requireBoolean(target === null)) {
259
- return null;
260
- }
261
- current = __normalize(target.controls);
262
- }
263
- return target;
264
- return null;
265
- }
266
- //# sourceMappingURL=form_state.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"form_state.mjs","sources":["form_state.lango"],"sourcesContent":["import js global RegExp\n\nexport rulesFor(value)\nexport validationMessage(rules, value)\nexport sameValue(left, right)\nexport ownedFields(controls)\nexport dirtyFields(controls)\nexport validateFields(controls)\nexport validatesRequest(controls, name)\nexport confirmsRequest(controls, name)\n\nrulesFor(value)\n if value == null\n return {\n }\n if !is_object(value) or is_array(value)\n throw \"UiValidationRequiresMap\"\n rules = {\n }\n for value as name: item\n switch name\n case \"required\"\n if !is_bool(item)\n throw \"UiValidationRequiredMustBeBoolean\"\n case \"minLength\"\n if !is_number(item) or item < 0 or item % 1 != 0\n throw \"UiValidationLengthMustBeNonnegativeInteger\"\n case \"maxLength\"\n if !is_number(item) or item < 0 or item % 1 != 0\n throw \"UiValidationLengthMustBeNonnegativeInteger\"\n case \"pattern\"\n if !is_string(item)\n throw \"UiValidationPatternMustBeString\"\n expression = new RegExp(\"^(?:${item})$\")\n case \"message\"\n if !is_string(item) or item == \"\"\n throw \"UiValidationMessageMustBeString\"\n else\n throw \"UiUnknownValidationRule: ${name}\"\n rules[name] = item\n if rules.minLength != null and rules.maxLength != null and rules.minLength > rules.maxLength\n throw \"UiValidationLengthRangeInvalid\"\n return rules\n\nvalidationMessage(rules, value)\n empty = value == null or value == false\n if is_string(value)\n empty = value.trim() == \"\"\n message = null\n if rules.required == true and empty\n message = \"This field is required.\"\n if !empty\n if rules.minLength != null or rules.maxLength != null or rules.pattern != null\n if !is_string(value)\n message = \"This value must be text.\"\n else\n if rules.minLength != null and value.length < rules.minLength\n message = \"Enter at least ${rules.minLength} characters.\"\n if rules.maxLength != null and value.length > rules.maxLength\n message = \"Enter at most ${rules.maxLength} characters.\"\n if rules.pattern != null\n pattern = new RegExp(\"^(?:${rules.pattern})$\")\n if !pattern.test(value)\n message = \"Enter a value in the required format.\"\n if message != null and rules.message != null\n return rules.message\n return message\n\nsameValue(left, right)\n if is_array(left)\n if !is_array(right) or left.length != right.length\n return false\n for left as index: value\n if !sameValue(value, right[index])\n return false\n return true\n if is_object(left)\n if !is_object(right) or is_array(right)\n return false\n count = 0\n other = 0\n for left as name: value\n count++\n if !(name in right) or !sameValue(value, right[name])\n return false\n for right as name: value\n other++\n return count == other\n return left == right\n\nownedFields(controls)\n result = []\n collectFields(controls, [], result, false)\n return result\n\ncollectFields(controls, parent, result, blocked)\n for controls as control\n if control.element != null and control.element.langoFormRoot == true\n continue\n path = parent.slice()\n unavailable = blocked\n if control.element != null\n unavailable = unavailable or control.element.disabled == true or control.element.hidden == true or control.element.inert == true\n if control.name != null and control.name != \"\"\n path.add(control.name)\n if is_array(control.controls)\n collectFields(control.controls, path, result, unavailable)\n else\n result.add({\n control: control\n path: path\n blocked: unavailable\n })\n\ndirtyFields(controls)\n fields = ownedFields(controls)\n for fields as field\n control = field.control\n if is_kindof(control.isDirty, Function)\n if control.isDirty()\n return true\n return false\n\nvalidateFields(controls)\n issues = []\n fields = ownedFields(controls)\n for fields as field\n if field.blocked\n continue\n control = field.control\n if is_kindof(control.validate, Function)\n message = control.validate()\n if message != null\n issues.add({\n path: field.path\n message: message\n control: field.control\n })\n return issues\n\nvalidatesRequest(controls, name)\n target = requestSource(controls, name)\n return target != null and target.validates == true\n\nconfirmsRequest(controls, name)\n target = requestSource(controls, name)\n return target != null and target.confirms == true\n\nrequestSource(controls, name)\n path = name\n if is_string(path)\n path = [path]\n if !is_array(path) or path.length == 0\n return null\n current = controls\n target = null\n for path as part\n if !is_array(current)\n return null\n target = null\n for current as control\n if control.name == part\n target = control\n break\n if target == null\n return null\n current = target.controls\n return target\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;AAIA;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}