@lango-project/lango-client 0.2.1 → 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 (234) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +570 -906
  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 -807
  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 +25 -43
  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 -599
  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 -471
  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 -293
  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 -87
  182. package/examples/demo_test.lango +0 -356
  183. package/examples/index.html +0 -32
  184. package/examples/pages.lango +0 -174
  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 -2047
  203. package/src/session.lango +0 -343
  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 -44
  210. package/template/gitignore +0 -4
  211. package/template/package.json +0 -22
  212. package/template/public/app.css +0 -10
  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/browser_runner.lango +0 -32
  220. package/tools/browser_test.lango +0 -343
  221. package/tools/create_app.lango +0 -88
  222. package/tools/create_app_test.lango +0 -43
  223. package/tools/starter_test.lango +0 -227
  224. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  225. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  226. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  227. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  228. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  229. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  230. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  231. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  232. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  233. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  234. /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
@@ -0,0 +1,227 @@
1
+ import { Field } from "./fields.mjs";
2
+ import { cloneMarkup } from "./templates.mjs";
3
+ import { InputChanges } from "./input_changes.mjs";
4
+ import {
5
+ hostGlobal as __hostGlobal,
6
+ xmlEscape as __xmlEscape,
7
+ isNumber as __isNumber,
8
+ isString as __isString,
9
+ isBool as __isBool,
10
+ isObject as __isObject,
11
+ isArray as __isArray,
12
+ add as __add,
13
+ requireBoolean as __requireBoolean,
14
+ normalize as __normalize,
15
+ numericAdd as __numericAdd,
16
+ call as __call,
17
+ boundary as __boundary,
18
+ requireArity as __requireArity,
19
+ withArity as __withArity,
20
+ } from "./.lango/runtime.mjs";
21
+
22
+ export class FileInput extends Field {
23
+ #limit;
24
+ #locked;
25
+ #changes;
26
+ #generation;
27
+ #pending;
28
+ #reader;
29
+ #data;
30
+ #failure;
31
+ #closed;
32
+ constructor(form, props) {
33
+ super(form, props, cloneMarkup("file-input", ["<input type=\"file\" class=\"form-control\" />"].join("")));
34
+ __requireArity(arguments.length, [0, 1], "constructor");
35
+ form = __boundary(form);
36
+ props = __boundary(props);
37
+ this.#limit = fileLimit(__normalize(props.maxBytes));
38
+ this.#locked = __normalize(props.readonly) === true;
39
+ this.#changes = new InputChanges(form, __normalize(props.url));
40
+ this.#generation = 0;
41
+ this.#pending = null;
42
+ this.#reader = null;
43
+ this.#data = null;
44
+ this.#failure = null;
45
+ this.#closed = false;
46
+ if (__requireBoolean(__normalize(props.accept) !== null)) {
47
+ if (__requireBoolean(!__requireBoolean(__isString(__normalize(props.accept))))) {
48
+ throw "File accept must be text";
49
+ }
50
+ this.input.accept = __normalize(props.accept);
51
+ }
52
+ this.setValue(__normalize(props.value));
53
+ this.setDisabled(__normalize(props.disabled) === true);
54
+ let listener = () => {
55
+ this.#changed();
56
+ return null;
57
+ };
58
+ __normalize(this.input.addEventListener("change", listener));
59
+ let release = () => {
60
+ __normalize(this.input.removeEventListener("change", listener));
61
+ return null;
62
+ };
63
+ __add(this.release, release);
64
+ }
65
+ #clear() {
66
+ this.#generation = __numericAdd(__normalize(this.#generation), 1);
67
+ if (__requireBoolean(__normalize(this.#reader) !== null)) {
68
+ __normalize(this.#reader.abort());
69
+ this.#reader = null;
70
+ }
71
+ this.#pending = null;
72
+ this.#data = null;
73
+ this.#failure = null;
74
+ return null;
75
+ return null;
76
+ }
77
+ setValue(value) {
78
+ __requireArity(arguments.length, [0], "setValue");
79
+ value = __boundary(value);
80
+ if (__requireBoolean(value !== null)) {
81
+ throw "File values can only be cleared programmatically";
82
+ }
83
+ this.#clear();
84
+ this.input.value = "";
85
+ return this;
86
+ return null;
87
+ }
88
+ setDisabled(value) {
89
+ __requireArity(arguments.length, [0], "setDisabled");
90
+ value = __boundary(value);
91
+ this.input.disabled = __requireBoolean(value) || __requireBoolean(__normalize(this.#locked) === true);
92
+ return this;
93
+ return null;
94
+ }
95
+ #changed() {
96
+ this.#clear();
97
+ let files = __normalize(this.input.files);
98
+ if (__requireBoolean(__normalize(files.length) === 0)) {
99
+ __normalize(this.#changes.changed());
100
+ return null;
101
+ }
102
+ let file = __normalize(files[0]);
103
+ if (__requireBoolean(__normalize(file.size) > __normalize(this.#limit))) {
104
+ this.#failure = `File exceeds its ${__normalize(this.#limit)}-byte limit`;
105
+ __normalize(this.form.app.error(__normalize(this.form), __normalize(this.#failure)));
106
+ return null;
107
+ }
108
+ let generation = __normalize(this.#generation);
109
+ let reader = new (__hostGlobal(["FileReader"]))();
110
+ this.#reader = reader;
111
+ this.#pending = readFile(reader, file);
112
+ __normalize(this.#pending).then(__withArity((data) => {
113
+ data = __boundary(data);
114
+ if (__requireBoolean(__requireBoolean(generation === __normalize(this.#generation)) && __requireBoolean(!__requireBoolean(__normalize(this.#closed))))) {
115
+ this.#reader = null;
116
+ this.#data = data;
117
+ __normalize(this.#changes.changed());
118
+ }
119
+ return null;
120
+ }, [0], "closure")).catch(__withArity((error) => {
121
+ error = __boundary(error);
122
+ if (__requireBoolean(__requireBoolean(generation === __normalize(this.#generation)) && __requireBoolean(!__requireBoolean(__normalize(this.#closed))))) {
123
+ this.#reader = null;
124
+ this.#failure = error;
125
+ __normalize(this.form.app.error(__normalize(this.form), error));
126
+ }
127
+ return null;
128
+ }, [0], "closure"));
129
+ return null;
130
+ return null;
131
+ }
132
+ prepareValue() {
133
+ if (__requireBoolean(__normalize(this.#closed))) {
134
+ return __normalize(__hostGlobal(["Promise"]).reject("File field is disposed"));
135
+ }
136
+ if (__requireBoolean(__normalize(this.#failure) !== null)) {
137
+ return __normalize(__hostGlobal(["Promise"]).reject(__normalize(this.#failure)));
138
+ }
139
+ if (__requireBoolean(__normalize(this.#pending) === null)) {
140
+ return __normalize(__hostGlobal(["Promise"]).resolve(null));
141
+ }
142
+ let pending = __normalize(this.#pending);
143
+ return pending.catch(__withArity((error) => {
144
+ error = __boundary(error);
145
+ if (__requireBoolean(pending === __normalize(this.#pending))) {
146
+ throw error;
147
+ }
148
+ return null;
149
+ }, [0], "closure")).then(__withArity((ignored) => {
150
+ ignored = __boundary(ignored);
151
+ if (__requireBoolean(pending !== __normalize(this.#pending))) {
152
+ return this.prepareValue();
153
+ }
154
+ if (__requireBoolean(__normalize(this.#closed))) {
155
+ throw "File field is disposed";
156
+ }
157
+ return null;
158
+ return null;
159
+ }, [0], "closure"));
160
+ return null;
161
+ }
162
+ getValue() {
163
+ if (__requireBoolean(__normalize(this.#failure) !== null)) {
164
+ throw __normalize(this.#failure);
165
+ }
166
+ if (__requireBoolean(__normalize(this.#reader) !== null)) {
167
+ throw "File is still being read";
168
+ }
169
+ return __normalize(this.#data);
170
+ return null;
171
+ }
172
+ dispose() {
173
+ this.#closed = true;
174
+ this.#clear();
175
+ __normalize(this.#changes.dispose());
176
+ super.dispose();
177
+ return null;
178
+ return null;
179
+ }
180
+ }
181
+ export function fileLimit(value = null) {
182
+ value = __boundary(value);
183
+ if (__requireBoolean(value === null)) {
184
+ return 1048576;
185
+ }
186
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(value))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(value))))) || __requireBoolean(value < 1))) {
187
+ throw "File maxBytes must be a positive safe integer";
188
+ }
189
+ return value;
190
+ return null;
191
+ }
192
+
193
+ function readFile(reader, file) {
194
+ __requireArity(arguments.length, [0, 1], "readFile");
195
+ reader = __boundary(reader);
196
+ file = __boundary(file);
197
+ let pending = new (__hostGlobal(["Promise"]))(__withArity((resolve, reject) => {
198
+ resolve = __boundary(resolve);
199
+ reject = __boundary(reject);
200
+ let load = () => {
201
+ let value = __normalize(reader.result);
202
+ let comma = __normalize(value.indexOf(","));
203
+ let mime = __normalize(file.type);
204
+ if (__requireBoolean(mime === "")) {
205
+ mime = "application/octet-stream";
206
+ }
207
+ __call(resolve, { name: __normalize(file.name), mimeType: mime, size: __normalize(file.size), content: __normalize(value.slice(__numericAdd(comma, 1))) });
208
+ return null;
209
+ };
210
+ let fail = () => {
211
+ __call(reject, "File could not be read");
212
+ return null;
213
+ };
214
+ let abort = () => {
215
+ __call(reject, "File read cancelled");
216
+ return null;
217
+ };
218
+ __normalize(reader.addEventListener("load", load, { once: true }));
219
+ __normalize(reader.addEventListener("error", fail, { once: true }));
220
+ __normalize(reader.addEventListener("abort", abort, { once: true }));
221
+ __normalize(reader.readAsDataURL(file));
222
+ return null;
223
+ }, [0, 1], "closure"));
224
+ return pending;
225
+ return null;
226
+ }
227
+ //# sourceMappingURL=file_input.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file_input.mjs","sources":["file_input.lango"],"sourcesContent":["import js global FileReader\nimport js global Promise\nimport js global Number\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport fileLimit(value = null)\n\nfileLimit(value = null)\n if value == null\n return 1048576\n if !is_number(value) or !Number/isSafeInteger(value) or value < 1\n throw \"File maxBytes must be a positive safe integer\"\n return value\n\nexport class FileInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n prepareValue()\n dispose()\n\nFileInput(form, props)\n super(form, props, cloneMarkup(\"file-input\", <input type=\"file\" class=\"form-control\" />))\n @limit = fileLimit(props.maxBytes)\n @locked = props.readonly == true\n @changes = new InputChanges(form, props.url)\n @generation = 0\n @pending = null\n @reader = null\n @data = null\n @failure = null\n @closed = false\n if props.accept != null\n if !is_string(props.accept)\n throw \"File accept must be text\"\n @input.accept = props.accept\n setValue(props.value)\n setDisabled(props.disabled == true)\n listener = ()\n changed()\n @input.addEventListener(\"change\", listener)\n release = ()\n capture listener\n @input.removeEventListener(\"change\", listener)\n @release.add(release)\n\nFileInput:clear()\n @generation = @generation + 1\n if @reader != null\n @reader.abort()\n @reader = null\n @pending = null\n @data = null\n @failure = null\n return null\n\nFileInput:setValue(value)\n if value != null\n throw \"File values can only be cleared programmatically\"\n clear()\n @input.value = \"\"\n return @this\n\nFileInput:setDisabled(value)\n @input.disabled = value or @locked == true\n return @this\n\nFileInput:changed()\n clear()\n files = @input.files\n if files.length == 0\n @changes.changed()\n return null\n file = files[0]\n if file.size > @limit\n @failure = \"File exceeds its ${@limit}-byte limit\"\n @form.app.error(@form, @failure)\n return null\n generation = @generation\n reader = new FileReader()\n @reader = reader\n @pending = readFile(reader, file)\n chain @pending\n then(data)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @data = data\n @changes.changed()\n catch(error)\n capture generation\n if generation == @generation and !@closed\n @reader = null\n @failure = error\n @form.app.error(@form, error)\n return null\n\nFileInput:prepareValue()\n if @closed\n return Promise/reject(\"File field is disposed\")\n if @failure != null\n return Promise/reject(@failure)\n if @pending == null\n return Promise/resolve(null)\n pending = @pending\n return chain pending\n catch(error)\n capture pending\n if pending == @pending\n throw error\n then(ignored)\n capture pending\n if pending != @pending\n return prepareValue()\n if @closed\n throw \"File field is disposed\"\n return null\n\nFileInput:getValue()\n if @failure != null\n throw @failure\n if @reader != null\n throw \"File is still being read\"\n return @data\n\nFileInput:dispose()\n @closed = true\n clear()\n @changes.dispose()\n super.dispose()\n return null\n\nreadFile(reader, file)\n pending = new Promise((resolve, reject)\n capture reader\n capture file\n load = ()\n capture reader\n capture file\n capture resolve\n value = reader.result\n comma = value.indexOf(\",\")\n mime = file.type\n if mime == \"\"\n mime = \"application/octet-stream\"\n resolve({\n name: file.name\n mimeType: mime\n size: file.size\n content: value.slice(comma + 1)\n })\n fail = ()\n capture reject\n reject(\"File could not be read\")\n abort = ()\n capture reject\n reject(\"File read cancelled\")\n reader.addEventListener(\"load\", load, {\n once: true\n })\n reader.addEventListener(\"error\", fail, {\n once: true\n })\n reader.addEventListener(\"abort\", abort, {\n once: true\n })\n reader.readAsDataURL(file)\n )\n return pending\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPA;;;;;;;;;;;;AA8HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/form.mjs ADDED
@@ -0,0 +1,272 @@
1
+ import { Activities } from "./activities.mjs";
2
+ import {
3
+ hostGlobal as __hostGlobal,
4
+ isNumber as __isNumber,
5
+ isString as __isString,
6
+ isBool as __isBool,
7
+ isObject as __isObject,
8
+ isArray as __isArray,
9
+ includes as __includes,
10
+ entries as __entries,
11
+ add as __add,
12
+ clear as __clear,
13
+ requireBoolean as __requireBoolean,
14
+ normalize as __normalize,
15
+ call as __call,
16
+ boundary as __boundary,
17
+ requireArity as __requireArity,
18
+ } from "./.lango/runtime.mjs";
19
+
20
+ export class Form {
21
+ app;
22
+ parent;
23
+ token;
24
+ controls;
25
+ owned;
26
+ inheritedNames;
27
+ disposed;
28
+ element;
29
+ resources;
30
+ activity;
31
+ presentation;
32
+ inheritThrough;
33
+ spinner;
34
+ waiting;
35
+ constructor(app, parent = null, token = null) {
36
+ __requireArity(arguments.length, [0], "constructor");
37
+ app = __boundary(app);
38
+ parent = __boundary(parent);
39
+ token = __boundary(token);
40
+ this.app = app;
41
+ this.parent = parent;
42
+ this.token = token;
43
+ this.controls = __normalize(__hostGlobal(["Object"]).create(null));
44
+ this.owned = [];
45
+ this.inheritedNames = [];
46
+ this.disposed = false;
47
+ this.element = null;
48
+ this.resources = [];
49
+ this.activity = new Activities(this);
50
+ this.presentation = null;
51
+ this.inheritThrough = false;
52
+ this.spinner = null;
53
+ this.waiting = false;
54
+ __add(app.forms, this);
55
+ }
56
+ register(name, control) {
57
+ __requireArity(arguments.length, [0, 1], "register");
58
+ name = __boundary(name);
59
+ control = __boundary(control);
60
+ __add(this.owned, control);
61
+ if (__requireBoolean(name === null)) {
62
+ return control;
63
+ }
64
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(__normalize(name.includes("/")))) || __requireBoolean(__includes(name, __normalize(this.controls))))) {
65
+ throw `Invalid or duplicate control name: ${name}`;
66
+ }
67
+ this.controls[name] = control;
68
+ return control;
69
+ return null;
70
+ }
71
+ unregister(control) {
72
+ __requireArity(arguments.length, [0], "unregister");
73
+ control = __boundary(control);
74
+ for (const name of __normalize(__hostGlobal(["Object"]).keys(__normalize(this.controls)))) {
75
+ if (__requireBoolean(__normalize(this.controls[name]) === control)) {
76
+ __normalize(__hostGlobal(["Reflect"]).deleteProperty(__normalize(this.controls), name));
77
+ }
78
+ }
79
+ let index = __normalize(this.owned.indexOf(control));
80
+ if (__requireBoolean(index >= 0)) {
81
+ __normalize(this.owned.splice(index, 1));
82
+ }
83
+ return null;
84
+ return null;
85
+ }
86
+ find(name) {
87
+ __requireArity(arguments.length, [0], "find");
88
+ name = __boundary(name);
89
+ let parts = __normalize(name.split("/"));
90
+ let current = __normalize(this.controls[__normalize(parts.shift())]);
91
+ if (__requireBoolean(current === null)) {
92
+ if (__requireBoolean(__requireBoolean(__normalize(this.inheritedNames.includes(name))) && __requireBoolean(__normalize(this.parent) !== null))) {
93
+ return this.inherited(name);
94
+ }
95
+ throw `Unknown control: ${name}`;
96
+ }
97
+ if (__requireBoolean(__normalize(parts.length) > 0)) {
98
+ if (__requireBoolean(__normalize(current.find) === null)) {
99
+ throw `Control has no named children: ${name}`;
100
+ }
101
+ return __normalize(current.find(__normalize(parts.join("/"))));
102
+ }
103
+ return current;
104
+ return null;
105
+ }
106
+ inherited(name) {
107
+ __requireArity(arguments.length, [0], "inherited");
108
+ name = __boundary(name);
109
+ let parent = __normalize(this.parent);
110
+ __loop1: while (__requireBoolean(__requireBoolean(parent !== null) && __requireBoolean(__normalize(parent.inheritThrough)))) {
111
+ parent = __normalize(parent.parent);
112
+ }
113
+ if (__requireBoolean(parent === null)) {
114
+ throw `Inherited value has no parent: ${name}`;
115
+ }
116
+ return __normalize(parent.find(name));
117
+ return null;
118
+ }
119
+ getValue() {
120
+ let result = __normalize(__hostGlobal(["Object"]).create(null));
121
+ for (const [name, control] of __entries(__normalize(this.controls))) {
122
+ result[name] = __normalize(control.getValue());
123
+ }
124
+ for (const name of __normalize(this.inheritedNames)) {
125
+ if (__requireBoolean(__requireBoolean(__normalize(this.parent) === null) || __requireBoolean(__includes(name, result)))) {
126
+ throw `Invalid inherited name: ${name}`;
127
+ }
128
+ let source = this.inherited(name);
129
+ result[name] = __normalize(source.getValue());
130
+ }
131
+ return result;
132
+ return null;
133
+ }
134
+ prepareValue() {
135
+ let pending = [];
136
+ for (const [name, control] of __entries(__normalize(this.controls))) {
137
+ if (__requireBoolean(__normalize(control.prepareValue) !== null)) {
138
+ let ready = __normalize(control.prepareValue());
139
+ if (__requireBoolean(ready !== null)) {
140
+ pending.push(ready);
141
+ }
142
+ }
143
+ }
144
+ for (const name of __normalize(this.inheritedNames)) {
145
+ let source = this.inherited(name);
146
+ if (__requireBoolean(__normalize(source.prepareValue) !== null)) {
147
+ let inheritedReady = __normalize(source.prepareValue());
148
+ if (__requireBoolean(inheritedReady !== null)) {
149
+ pending.push(inheritedReady);
150
+ }
151
+ }
152
+ }
153
+ if (__requireBoolean(__normalize(pending.length) === 0)) {
154
+ return null;
155
+ }
156
+ return __normalize(__hostGlobal(["Promise"]).all(pending));
157
+ return null;
158
+ }
159
+ setValue(values) {
160
+ __requireArity(arguments.length, [0], "setValue");
161
+ values = __boundary(values);
162
+ for (const [name, value] of __entries(values)) {
163
+ __normalize(this.find(name).setValue(value));
164
+ }
165
+ return this;
166
+ return null;
167
+ }
168
+ clearValidation() {
169
+ for (const [name, control] of __entries(__normalize(this.controls))) {
170
+ if (__requireBoolean(__normalize(control.clearValidation) !== null)) {
171
+ __normalize(control.clearValidation());
172
+ }
173
+ }
174
+ for (const name of __normalize(this.inheritedNames)) {
175
+ let source = this.find(name);
176
+ if (__requireBoolean(__normalize(source.clearValidation) !== null)) {
177
+ __normalize(source.clearValidation());
178
+ }
179
+ }
180
+ return null;
181
+ return null;
182
+ }
183
+ clearResources() {
184
+ __clear(this.activity);
185
+ let resources = __normalize(this.resources);
186
+ this.resources = [];
187
+ for (const release of resources) {
188
+ __call(release, );
189
+ }
190
+ return null;
191
+ return null;
192
+ }
193
+ setToken(token) {
194
+ __requireArity(arguments.length, [0], "setToken");
195
+ token = __boundary(token);
196
+ if (__requireBoolean(token !== null)) {
197
+ this.token = token;
198
+ __normalize(this.app.saveToken(token));
199
+ if (__requireBoolean(__normalize(this.app.heartbeat) !== null)) {
200
+ __normalize(this.app.heartbeat.observe(token));
201
+ }
202
+ }
203
+ return this;
204
+ return null;
205
+ }
206
+ send(url) {
207
+ __requireArity(arguments.length, [0], "send");
208
+ url = __boundary(url);
209
+ return __normalize(this.app.send(this, url));
210
+ return null;
211
+ }
212
+ handle(packet) {
213
+ __requireArity(arguments.length, [0], "handle");
214
+ packet = __boundary(packet);
215
+ if (__requireBoolean(__normalize(this.disposed))) {
216
+ return null;
217
+ }
218
+ this.setToken(__normalize(packet.token));
219
+ let body = __normalize(packet.body);
220
+ if (__requireBoolean(__normalize(body.view) !== null)) {
221
+ __normalize(this.app.renderer.show(this, __normalize(body.view)));
222
+ }
223
+ if (__requireBoolean(__normalize(body.cmds) !== null)) {
224
+ for (const cmd of __normalize(body.cmds)) {
225
+ __normalize(this.app.command(this, cmd));
226
+ }
227
+ }
228
+ return null;
229
+ return null;
230
+ }
231
+ related(other) {
232
+ __requireArity(arguments.length, [0], "related");
233
+ other = __boundary(other);
234
+ let node = other;
235
+ __loop2: while (__requireBoolean(node !== null)) {
236
+ if (__requireBoolean(node === this)) {
237
+ return true;
238
+ }
239
+ node = __normalize(node.parent);
240
+ }
241
+ node = this;
242
+ __loop3: while (__requireBoolean(node !== null)) {
243
+ if (__requireBoolean(node === other)) {
244
+ return true;
245
+ }
246
+ node = __normalize(node.parent);
247
+ }
248
+ return false;
249
+ return null;
250
+ }
251
+ dispose() {
252
+ if (__requireBoolean(__normalize(this.disposed))) {
253
+ return null;
254
+ }
255
+ this.disposed = true;
256
+ for (const control of __normalize(this.owned.slice())) {
257
+ __normalize(control.dispose());
258
+ }
259
+ this.clearResources();
260
+ this.controls = __normalize(__hostGlobal(["Object"]).create(null));
261
+ let alive = [];
262
+ for (const form of __normalize(this.app.forms)) {
263
+ if (__requireBoolean(form !== this)) {
264
+ alive.push(form);
265
+ }
266
+ }
267
+ this.app.forms = alive;
268
+ return null;
269
+ return null;
270
+ }
271
+ }
272
+ //# sourceMappingURL=form.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.mjs","sources":["form.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global Promise\nimport \"./activities\"\n class Activities\n\nexport class Form(app, parent = null, token = null)\n properties\n app\n parent\n token\n controls\n owned\n inheritedNames\n disposed\n element\n resources\n activity\n presentation\n inheritThrough\n spinner\n waiting\n methods\n register(name, control)\n unregister(control)\n find(name)\n inherited(name)\n getValue()\n prepareValue()\n setValue(values)\n setToken(token)\n send(url)\n handle(packet)\n related(other)\n clearValidation()\n clearResources()\n dispose()\n\nForm(app, parent = null, token = null)\n @app = app\n @parent = parent\n @token = token\n @controls = Object/create(null)\n @owned = []\n @inheritedNames = []\n @disposed = false\n @element = null\n @resources = []\n @activity = new Activities(@this)\n @presentation = null\n @inheritThrough = false\n @spinner = null\n @waiting = false\n app.forms.add(@this)\n\nForm:register(name, control)\n @owned.add(control)\n if name == null\n return control\n if !is_string(name) or name == \"\" or name.includes(\"/\") or name in @controls\n throw \"Invalid or duplicate control name: ${name}\"\n @controls[name] = control\n return control\n\nForm:unregister(control)\n for Object/keys(@controls) as name\n if @controls[name] == control\n Reflect/deleteProperty(@controls, name)\n index = @owned.indexOf(control)\n if index >= 0\n @owned.splice(index, 1)\n return null\n\nForm:find(name)\n parts = name.split(\"/\")\n current = @controls[parts.shift()]\n if current == null\n if @inheritedNames.includes(name) and @parent != null\n return inherited(name)\n throw \"Unknown control: ${name}\"\n if parts.length > 0\n if current.find == null\n throw \"Control has no named children: ${name}\"\n return current.find(parts.join(\"/\"))\n return current\n\nForm:inherited(name)\n parent = @parent\n loop while parent != null and parent.inheritThrough\n parent = parent.parent\n if parent == null\n throw \"Inherited value has no parent: ${name}\"\n return parent.find(name)\n\nForm:getValue()\n result = Object/create(null)\n for @controls as name: control\n result[name] = control.getValue()\n for @inheritedNames as name\n if @parent == null or name in result\n throw \"Invalid inherited name: ${name}\"\n source = inherited(name)\n result[name] = source.getValue()\n return result\n\nForm:prepareValue()\n pending = []\n for @controls as name: control\n if control.prepareValue != null\n ready = control.prepareValue()\n if ready != null\n pending.add(ready)\n for @inheritedNames as name\n source = inherited(name)\n if source.prepareValue != null\n inheritedReady = source.prepareValue()\n if inheritedReady != null\n pending.add(inheritedReady)\n if pending.length == 0\n return null\n return Promise/all(pending)\n\nForm:setValue(values)\n for values as name: value\n find(name).setValue(value)\n return @this\n\nForm:clearValidation()\n for @controls as name: control\n if control.clearValidation != null\n control.clearValidation()\n for @inheritedNames as name\n source = find(name)\n if source.clearValidation != null\n source.clearValidation()\n return null\n\nForm:clearResources()\n @activity.clear()\n resources = @resources\n @resources = []\n for resources as release\n release()\n return null\n\nForm:setToken(token)\n if token != null\n @token = token\n @app.saveToken(token)\n if @app.heartbeat != null\n @app.heartbeat.observe(token)\n return @this\n\nForm:send(url)\n return @app.send(@this, url)\n\nForm:handle(packet)\n if @disposed\n return null\n setToken(packet.token)\n body = packet.body\n if body.view != null\n @app.renderer.show(@this, body.view)\n if body.cmds != null\n for body.cmds as cmd\n @app.command(@this, cmd)\n return null\n\nForm:related(other)\n node = other\n loop while node != null\n if node == @this\n return true\n node = node.parent\n node = @this\n loop while node != null\n if node == other\n return true\n node = node.parent\n return false\n\nForm:dispose()\n if @disposed\n return null\n @disposed = true\n for @owned.slice() as control\n control.dispose()\n clearResources()\n @controls = Object/create(null)\n alive = []\n for @app.forms as form\n if form != @this\n alive.add(form)\n @app.forms = alive\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}