@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
@@ -0,0 +1,454 @@
1
+ import { Control } from "./control.mjs";
2
+ import { cloneMarkup, controlId } from "./templates.mjs";
3
+ import {
4
+ hostGlobal as __hostGlobal,
5
+ hostGlobalCall as __hostGlobalCall,
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
+ entries as __entries,
13
+ add as __add,
14
+ requireBoolean as __requireBoolean,
15
+ normalize as __normalize,
16
+ finite as __finite,
17
+ numericAdd as __numericAdd,
18
+ boundary as __boundary,
19
+ requireArity as __requireArity,
20
+ withArity as __withArity,
21
+ } from "./.lango/runtime.mjs";
22
+
23
+ export class Field extends Control {
24
+ input;
25
+ labelElement;
26
+ #readonly;
27
+ constructor(form, props, input) {
28
+ super(form, props, cloneMarkup("field", ["<div class=\"mb-3\"></div>"].join("")));
29
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
30
+ form = __boundary(form);
31
+ props = __boundary(props);
32
+ input = __boundary(input);
33
+ let element = __normalize(this.element);
34
+ this.input = input;
35
+ this.#readonly = __normalize(props.readonly) === true;
36
+ this.labelElement = null;
37
+ input.id = controlId();
38
+ if (__requireBoolean(__normalize(props.label) !== null)) {
39
+ this.labelElement = __normalize(__hostGlobal(["document"]).createElement("label"));
40
+ this.labelElement.htmlFor = __normalize(input.id);
41
+ this.labelElement.className = "form-label";
42
+ this.labelElement.textContent = __normalize(props.label);
43
+ __normalize(element.appendChild(__normalize(this.labelElement)));
44
+ }
45
+ __normalize(element.appendChild(input));
46
+ if (__requireBoolean(__normalize(props.description) !== null)) {
47
+ let description = __normalize(__hostGlobal(["document"]).createElement("div"));
48
+ description.id = controlId();
49
+ description.className = "form-text";
50
+ description.textContent = __normalize(props.description);
51
+ __normalize(element.appendChild(description));
52
+ __normalize(input.setAttribute("aria-describedby", __normalize(description.id)));
53
+ }
54
+ if (__requireBoolean(__normalize(props.aria) !== null)) {
55
+ for (const [name, value] of __entries(__normalize(props.aria))) {
56
+ __normalize(input.setAttribute(`aria-${name}`, value));
57
+ }
58
+ }
59
+ input.required = __normalize(props.required) === true;
60
+ input.readOnly = __normalize(this.#readonly);
61
+ if (__requireBoolean(__normalize(props.disableAutoComplete) === true)) {
62
+ input.autocomplete = "off";
63
+ }
64
+ input.disabled = __normalize(props.disabled) === true;
65
+ if (__requireBoolean(__requireBoolean(__normalize(this.#readonly)) && __requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(input.tagName) === "SELECT") || __requireBoolean(__normalize(input.tagName) === "FIELDSET")) || __requireBoolean(__normalize(input.type) === "checkbox")) || __requireBoolean(__normalize(input.type) === "range")))) {
66
+ input.disabled = true;
67
+ }
68
+ this.validationTarget(input);
69
+ }
70
+ setDisabled(value) {
71
+ __requireArity(arguments.length, [0], "setDisabled");
72
+ value = __boundary(value);
73
+ this.input.disabled = value;
74
+ if (__requireBoolean(__requireBoolean(__normalize(this.#readonly)) && __requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.input.tagName) === "SELECT") || __requireBoolean(__normalize(this.input.tagName) === "FIELDSET")) || __requireBoolean(__normalize(this.input.type) === "checkbox")) || __requireBoolean(__normalize(this.input.type) === "range")))) {
75
+ this.input.disabled = true;
76
+ }
77
+ return this;
78
+ return null;
79
+ }
80
+ }
81
+
82
+ export class Input extends Field {
83
+ #numeric;
84
+ #timer;
85
+ #url;
86
+ constructor(form, props) {
87
+ super(form, props, inputElement(props));
88
+ __requireArity(arguments.length, [0, 1], "constructor");
89
+ form = __boundary(form);
90
+ props = __boundary(props);
91
+ let input = __normalize(this.input);
92
+ this.#numeric = __normalize(input.type) === "number";
93
+ this.#timer = null;
94
+ this.form = form;
95
+ this.#url = __normalize(props.url);
96
+ if (__requireBoolean(__normalize(props.placeholder) !== null)) {
97
+ input.placeholder = __normalize(props.placeholder);
98
+ }
99
+ if (__requireBoolean(__normalize(props.maxLength) !== null)) {
100
+ input.maxLength = __normalize(props.maxLength);
101
+ }
102
+ if (__requireBoolean(__normalize(props.min) !== null)) {
103
+ input.min = __normalize(props.min);
104
+ }
105
+ if (__requireBoolean(__normalize(props.max) !== null)) {
106
+ input.max = __normalize(props.max);
107
+ }
108
+ this.setValue(__normalize(props.value));
109
+ if (__requireBoolean(__normalize(this.#url) !== null)) {
110
+ let listener = () => {
111
+ this.changed();
112
+ return null;
113
+ };
114
+ __normalize(input.addEventListener("input", listener));
115
+ let release = () => {
116
+ __normalize(input.removeEventListener("input", listener));
117
+ return null;
118
+ };
119
+ __add(this.release, release);
120
+ }
121
+ }
122
+ getValue() {
123
+ if (__requireBoolean(__normalize(this.#numeric))) {
124
+ if (__requireBoolean(__requireBoolean(__normalize(this.input.value) === "") || __requireBoolean(__normalize(this.input.validity.badInput)))) {
125
+ return null;
126
+ }
127
+ try {
128
+ return __normalize(this.input.valueAsNumber);
129
+ } catch (error) {
130
+ if (__requireBoolean(__normalize(error.message) === "NonFiniteNumber")) {
131
+ return null;
132
+ }
133
+ throw error;
134
+ }
135
+ }
136
+ return __normalize(this.input.value);
137
+ return null;
138
+ }
139
+ setValue(value) {
140
+ __requireArity(arguments.length, [0], "setValue");
141
+ value = __boundary(value);
142
+ if (__requireBoolean(value === null)) {
143
+ this.input.value = "";
144
+ } else {
145
+ this.input.value = `${value}`;
146
+ }
147
+ return this;
148
+ return null;
149
+ }
150
+ changed() {
151
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
152
+ __hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
153
+ }
154
+ let action = () => {
155
+ this.#timer = null;
156
+ if (__requireBoolean(!__requireBoolean(__normalize(this.form.disposed)))) {
157
+ __normalize(this.form.send(__normalize(this.#url))).catch(__withArity((error) => {
158
+ error = __boundary(error);
159
+ __normalize(this.form.app.error(__normalize(this.form), error));
160
+ return null;
161
+ }, [0], "closure"));
162
+ }
163
+ return null;
164
+ };
165
+ this.#timer = __hostGlobalCall(["setTimeout"], action, 500);
166
+ return null;
167
+ return null;
168
+ }
169
+ dispose() {
170
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
171
+ __hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
172
+ this.#timer = null;
173
+ }
174
+ return super.dispose();
175
+ return null;
176
+ }
177
+ }
178
+
179
+ export class Checkbox extends Field {
180
+ constructor(form, props) {
181
+ super(form, props, cloneMarkup("checkbox", ["<input type=\"checkbox\" class=\"form-check-input\" />"].join("")));
182
+ __requireArity(arguments.length, [0, 1], "constructor");
183
+ form = __boundary(form);
184
+ props = __boundary(props);
185
+ let input = __normalize(this.input);
186
+ __add(this.element.classList, "form-check");
187
+ if (__requireBoolean(__normalize(this.labelElement) !== null)) {
188
+ this.labelElement.className = "form-check-label";
189
+ __normalize(this.element.insertBefore(input, __normalize(this.labelElement)));
190
+ }
191
+ let initial = __normalize(props.value);
192
+ if (__requireBoolean(__normalize(props.indeterminate) === true)) {
193
+ initial = null;
194
+ }
195
+ this.setValue(initial);
196
+ }
197
+ getValue() {
198
+ if (__requireBoolean(__normalize(this.input.indeterminate))) {
199
+ return null;
200
+ }
201
+ return __normalize(this.input.checked);
202
+ return null;
203
+ }
204
+ setValue(value) {
205
+ __requireArity(arguments.length, [0], "setValue");
206
+ value = __boundary(value);
207
+ if (__requireBoolean(__requireBoolean(value !== null) && __requireBoolean(!__requireBoolean(__isBool(value))))) {
208
+ throw "Checkbox value must be boolean or null";
209
+ }
210
+ this.input.indeterminate = value === null;
211
+ this.input.checked = value === true;
212
+ return this;
213
+ return null;
214
+ }
215
+ }
216
+
217
+ export class Switch extends Checkbox {
218
+ constructor(form, props) {
219
+ super(form, props);
220
+ __requireArity(arguments.length, [0, 1], "constructor");
221
+ form = __boundary(form);
222
+ props = __boundary(props);
223
+ __add(this.element.classList, "form-switch");
224
+ __normalize(this.input.setAttribute("role", "switch"));
225
+ this.setValue(__normalize(props.value));
226
+ }
227
+ setValue(value) {
228
+ __requireArity(arguments.length, [0], "setValue");
229
+ value = __boundary(value);
230
+ if (__requireBoolean(value === null)) {
231
+ value = false;
232
+ }
233
+ if (__requireBoolean(!__requireBoolean(__isBool(value)))) {
234
+ throw "Switch value must be boolean";
235
+ }
236
+ return super.setValue(value);
237
+ return null;
238
+ }
239
+ }
240
+
241
+ export class Range extends Field {
242
+ constructor(form, props) {
243
+ super(form, props, cloneMarkup("range", ["<input type=\"range\" class=\"form-range\" />"].join("")));
244
+ __requireArity(arguments.length, [0, 1], "constructor");
245
+ form = __boundary(form);
246
+ props = __boundary(props);
247
+ let input = __normalize(this.input);
248
+ if (__requireBoolean(__normalize(props.min) !== null)) {
249
+ input.min = __normalize(props.min);
250
+ }
251
+ if (__requireBoolean(__normalize(props.max) !== null)) {
252
+ input.max = __normalize(props.max);
253
+ }
254
+ if (__requireBoolean(__normalize(props.steps) !== null)) {
255
+ input.step = __normalize(props.steps);
256
+ }
257
+ if (__requireBoolean(__normalize(props.value) !== null)) {
258
+ this.setValue(__normalize(props.value));
259
+ }
260
+ }
261
+ getValue() {
262
+ return __normalize(this.input.valueAsNumber);
263
+ return null;
264
+ }
265
+ setValue(value) {
266
+ __requireArity(arguments.length, [0], "setValue");
267
+ value = __boundary(value);
268
+ if (__requireBoolean(!__requireBoolean(__isNumber(value)))) {
269
+ throw "Range value must be a number";
270
+ }
271
+ this.input.value = `${value}`;
272
+ return this;
273
+ return null;
274
+ }
275
+ }
276
+
277
+ export class Select extends Field {
278
+ #options;
279
+ constructor(form, props) {
280
+ super(form, props, cloneMarkup("select", ["<select class=\"form-select\"></select>"].join("")));
281
+ __requireArity(arguments.length, [0, 1], "constructor");
282
+ form = __boundary(form);
283
+ props = __boundary(props);
284
+ let input = __normalize(this.input);
285
+ this.#options = __normalize(props.options);
286
+ if (__requireBoolean(__normalize(this.#options) === null)) {
287
+ this.#options = [];
288
+ }
289
+ for (const option of __normalize(this.#options)) {
290
+ let node = __normalize(__hostGlobal(["document"]).createElement("option"));
291
+ node.textContent = __normalize(option.label);
292
+ __normalize(input.appendChild(node));
293
+ }
294
+ this.setValue(__normalize(props.value));
295
+ }
296
+ getValue() {
297
+ if (__requireBoolean(__normalize(this.input.selectedIndex) < 0)) {
298
+ return null;
299
+ }
300
+ return __normalize(__normalize(this.#options[__normalize(this.input.selectedIndex)]).value);
301
+ return null;
302
+ }
303
+ setValue(value) {
304
+ __requireArity(arguments.length, [0], "setValue");
305
+ value = __boundary(value);
306
+ this.input.selectedIndex = __finite(-1);
307
+ let index = 0;
308
+ for (const option of __normalize(this.#options)) {
309
+ if (__requireBoolean(sameValue(__normalize(option.value), value))) {
310
+ this.input.selectedIndex = index;
311
+ break;
312
+ }
313
+ index = __numericAdd(index, 1);
314
+ }
315
+ return this;
316
+ return null;
317
+ }
318
+ }
319
+
320
+ export class Radio extends Field {
321
+ #options;
322
+ #choices;
323
+ constructor(form, props) {
324
+ super(form, props, cloneMarkup("radio", ["<fieldset role=\"radiogroup\"></fieldset>"].join("")));
325
+ __requireArity(arguments.length, [0, 1], "constructor");
326
+ form = __boundary(form);
327
+ props = __boundary(props);
328
+ let input = __normalize(this.input);
329
+ if (__requireBoolean(__normalize(props.label) !== null)) {
330
+ __normalize(input.setAttribute("aria-label", __normalize(props.label)));
331
+ }
332
+ this.#options = __normalize(props.options);
333
+ if (__requireBoolean(__normalize(this.#options) === null)) {
334
+ this.#options = [];
335
+ }
336
+ this.#choices = [];
337
+ for (const option of __normalize(this.#options)) {
338
+ let choice = cloneMarkup("radio-choice", ["<input type=\"radio\" class=\"form-check-input\" />"].join(""));
339
+ choice.id = controlId();
340
+ choice.name = __normalize(input.id);
341
+ choice.disabled = __normalize(option.enabled) === false;
342
+ choice.required = __normalize(props.required) === true;
343
+ let label = __normalize(__hostGlobal(["document"]).createElement("label"));
344
+ label.htmlFor = __normalize(choice.id);
345
+ label.className = "form-check-label";
346
+ label.textContent = __normalize(option.label);
347
+ let row = cloneMarkup("radio-row", ["<div class=\"form-check\"></div>"].join(""));
348
+ __normalize(row.appendChild(choice));
349
+ __normalize(row.appendChild(label));
350
+ __normalize(input.appendChild(row));
351
+ this.#choices.push(choice);
352
+ }
353
+ if (__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(props, "value")))) {
354
+ this.setValue(__normalize(props.value));
355
+ } else {
356
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(props.selectedIndex) !== null) && __requireBoolean(__normalize(props.selectedIndex) >= 0)) && __requireBoolean(__normalize(props.selectedIndex) < __normalize(this.#choices.length)))) {
357
+ let selected = __normalize(this.#choices[__normalize(props.selectedIndex)]);
358
+ selected.checked = true;
359
+ }
360
+ }
361
+ }
362
+ getValue() {
363
+ let index = 0;
364
+ for (const choice of __normalize(this.#choices)) {
365
+ if (__requireBoolean(__normalize(choice.checked))) {
366
+ return __normalize(__normalize(this.#options[index]).value);
367
+ }
368
+ index = __numericAdd(index, 1);
369
+ }
370
+ return null;
371
+ return null;
372
+ }
373
+ setValue(value) {
374
+ __requireArity(arguments.length, [0], "setValue");
375
+ value = __boundary(value);
376
+ let selected = false;
377
+ let index = 0;
378
+ for (const choice of __normalize(this.#choices)) {
379
+ choice.checked = __requireBoolean(!__requireBoolean(selected)) && __requireBoolean(sameValue(__normalize(__normalize(this.#options[index]).value), value));
380
+ if (__requireBoolean(__normalize(choice.checked))) {
381
+ selected = true;
382
+ }
383
+ index = __numericAdd(index, 1);
384
+ }
385
+ return this;
386
+ return null;
387
+ }
388
+ }
389
+ export function sameValue(first, second) {
390
+ __requireArity(arguments.length, [0, 1], "sameValue");
391
+ first = __boundary(first);
392
+ second = __boundary(second);
393
+ let index;
394
+ if (__requireBoolean(__isArray(first))) {
395
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(second))) || __requireBoolean(__normalize(first.length) !== __normalize(second.length)))) {
396
+ return false;
397
+ }
398
+ index = 0;
399
+ for (const item of first) {
400
+ if (__requireBoolean(!__requireBoolean(sameValue(item, __normalize(second[index]))))) {
401
+ return false;
402
+ }
403
+ index = __numericAdd(index, 1);
404
+ }
405
+ return true;
406
+ }
407
+ if (__requireBoolean(__isObject(first))) {
408
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(second))) || __requireBoolean(__isArray(second))) || __requireBoolean(__normalize(__normalize(__hostGlobal(["Object"]).keys(first)).length) !== __normalize(__normalize(__hostGlobal(["Object"]).keys(second)).length)))) {
409
+ return false;
410
+ }
411
+ for (const [name, value] of __entries(first)) {
412
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(second, name)))) || __requireBoolean(!__requireBoolean(sameValue(value, __normalize(second[name])))))) {
413
+ return false;
414
+ }
415
+ }
416
+ return true;
417
+ }
418
+ return first === second;
419
+ return null;
420
+ }
421
+
422
+ function inputElement(props) {
423
+ __requireArity(arguments.length, [0], "inputElement");
424
+ props = __boundary(props);
425
+ let input = cloneMarkup("input", ["<input class=\"form-control\" />"].join(""));
426
+ let variant = __normalize(props.variant);
427
+ if (__requireBoolean(variant === null)) {
428
+ variant = "text";
429
+ }
430
+ variant = __normalize(variant.toLowerCase());
431
+ if (__requireBoolean(variant === "string")) {
432
+ variant = "text";
433
+ }
434
+ let allowed = ["text", "email", "password", "search", "tel", "url", "number", "decimal", "money"];
435
+ if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(variant))))) {
436
+ throw `Unsupported input variant: ${variant}`;
437
+ }
438
+ if (__requireBoolean(__requireBoolean(__normalize(props.lines) !== null) && __requireBoolean(__normalize(props.lines) > 1))) {
439
+ if (__requireBoolean(variant !== "text")) {
440
+ throw "Multiline input requires text or String";
441
+ }
442
+ input = cloneMarkup("textarea", ["<textarea class=\"form-control\"></textarea>"].join(""));
443
+ input.rows = __normalize(props.lines);
444
+ } else {
445
+ input.type = variant;
446
+ if (__requireBoolean(__requireBoolean(variant === "decimal") || __requireBoolean(variant === "money"))) {
447
+ input.type = "text";
448
+ input.inputMode = "decimal";
449
+ }
450
+ }
451
+ return input;
452
+ return null;
453
+ }
454
+ //# sourceMappingURL=fields.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.mjs","sources":["fields.lango"],"sourcesContent":["import js global document\nimport js global Object\nimport js global setTimeout\nimport js global clearTimeout\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\n\nexport sameValue(first, second)\nexport class Field(form, props, input) : Control\n properties\n input\n labelElement\n methods\n setDisabled(value)\n\nField(form, props, input)\n super(form, props, cloneMarkup(\"field\", <div class=\"mb-3\"></div>))\n element = @element\n @input = input\n @readonly = props.readonly == true\n @labelElement = null\n input.id = controlId()\n if props.label != null\n @labelElement = document/createElement(\"label\")\n @labelElement.htmlFor = input.id\n @labelElement.className = \"form-label\"\n @labelElement.textContent = props.label\n element.appendChild(@labelElement)\n element.appendChild(input)\n if props.description != null\n description = document/createElement(\"div\")\n description.id = controlId()\n description.className = \"form-text\"\n description.textContent = props.description\n element.appendChild(description)\n input.setAttribute(\"aria-describedby\", description.id)\n if props.aria != null\n for props.aria as name: value\n input.setAttribute(\"aria-${name}\", value)\n input.required = props.required == true\n input.readOnly = @readonly\n if props.disableAutoComplete == true\n input.autocomplete = \"off\"\n # Derived fields are not initialized until this constructor returns.\n input.disabled = props.disabled == true\n if @readonly and (input.tagName == \"SELECT\" or input.tagName == \"FIELDSET\" or input.type == \"checkbox\" or input.type == \"range\")\n input.disabled = true\n validationTarget(input)\n\nField:setDisabled(value)\n @input.disabled = value\n if @readonly and (@input.tagName == \"SELECT\" or @input.tagName == \"FIELDSET\" or @input.type == \"checkbox\" or @input.type == \"range\")\n @input.disabled = true\n return @this\n\nexport class Input(form, props) : Field\n methods\n getValue()\n setValue(value)\n changed()\n dispose()\n\nInput(form, props)\n super(form, props, inputElement(props))\n input = @input\n @numeric = input.type == \"number\"\n @timer = null\n @form = form\n @url = props.url\n if props.placeholder != null\n input.placeholder = props.placeholder\n if props.maxLength != null\n input.maxLength = props.maxLength\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n setValue(props.value)\n if @url != null\n listener = ()\n changed()\n input.addEventListener(\"input\", listener)\n release = ()\n capture input\n capture listener\n input.removeEventListener(\"input\", listener)\n @release.add(release)\n\nInput:getValue()\n if @numeric\n if @input.value == \"\" or @input.validity.badInput\n return null\n try\n return @input.valueAsNumber\n catch error\n if error.message == \"NonFiniteNumber\"\n return null\n throw error\n return @input.value\n\nInput:setValue(value)\n if value == null\n @input.value = \"\"\n else\n @input.value = \"${value}\"\n return @this\n\nInput:changed()\n if @timer != null\n clearTimeout(@timer)\n action = ()\n @timer = null\n if !@form.disposed\n chain @form.send(@url)\n catch(error)\n @form.app.error(@form, error)\n @timer = setTimeout(action, 500)\n return null\n\nInput:dispose()\n if @timer != null\n clearTimeout(@timer)\n @timer = null\n return super.dispose()\n\nexport class Checkbox(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nCheckbox(form, props)\n super(form, props, cloneMarkup(\"checkbox\", <input type=\"checkbox\" class=\"form-check-input\" />))\n input = @input\n @element.classList.add(\"form-check\")\n if @labelElement != null\n @labelElement.className = \"form-check-label\"\n @element.insertBefore(input, @labelElement)\n initial = props.value\n if props.indeterminate == true\n initial = null\n setValue(initial)\n\nCheckbox:getValue()\n if @input.indeterminate\n return null\n return @input.checked\n\nCheckbox:setValue(value)\n if value != null and !is_bool(value)\n throw \"Checkbox value must be boolean or null\"\n @input.indeterminate = value == null\n @input.checked = value == true\n return @this\n\nexport class Switch(form, props) : Checkbox\n methods\n setValue(value)\n\nSwitch(form, props)\n super(form, props)\n @element.classList.add(\"form-switch\")\n @input.setAttribute(\"role\", \"switch\")\n setValue(props.value)\n\nSwitch:setValue(value)\n if value == null\n value = false\n if !is_bool(value)\n throw \"Switch value must be boolean\"\n return super.setValue(value)\n\nexport class Range(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRange(form, props)\n super(form, props, cloneMarkup(\"range\", <input type=\"range\" class=\"form-range\" />))\n input = @input\n if props.min != null\n input.min = props.min\n if props.max != null\n input.max = props.max\n if props.steps != null\n input.step = props.steps\n if props.value != null\n setValue(props.value)\n\nRange:getValue()\n return @input.valueAsNumber\n\nRange:setValue(value)\n if !is_number(value)\n throw \"Range value must be a number\"\n @input.value = \"${value}\"\n return @this\n\nexport class Select(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nSelect(form, props)\n super(form, props, cloneMarkup(\"select\", <select class=\"form-select\"></select>))\n input = @input\n @options = props.options\n if @options == null\n @options = []\n for @options as option\n node = document/createElement(\"option\")\n node.textContent = option.label\n input.appendChild(node)\n setValue(props.value)\n\nSelect:getValue()\n if @input.selectedIndex < 0\n return null\n return @options[@input.selectedIndex].value\n\nSelect:setValue(value)\n @input.selectedIndex = -1\n index = 0\n for @options as option\n if sameValue(option.value, value)\n @input.selectedIndex = index\n break\n index = index + 1\n return @this\n\nexport class Radio(form, props) : Field\n methods\n getValue()\n setValue(value)\n\nRadio(form, props)\n super(form, props, cloneMarkup(\"radio\", <fieldset role=\"radiogroup\"></fieldset>))\n input = @input\n if props.label != null\n input.setAttribute(\"aria-label\", props.label)\n @options = props.options\n if @options == null\n @options = []\n @choices = []\n for @options as option\n choice = cloneMarkup(\"radio-choice\", <input type=\"radio\" class=\"form-check-input\" />)\n choice.id = controlId()\n choice.name = input.id\n choice.disabled = option.enabled == false\n choice.required = props.required == true\n label = document/createElement(\"label\")\n label.htmlFor = choice.id\n label.className = \"form-check-label\"\n label.textContent = option.label\n row = cloneMarkup(\"radio-row\", <div class=\"form-check\"></div>)\n row.appendChild(choice)\n row.appendChild(label)\n input.appendChild(row)\n @choices.add(choice)\n if Object/hasOwn(props, \"value\")\n setValue(props.value)\n else\n if props.selectedIndex != null and props.selectedIndex >= 0 and props.selectedIndex < @choices.length\n selected = @choices[props.selectedIndex]\n selected.checked = true\n\nRadio:getValue()\n index = 0\n for @choices as choice\n if choice.checked\n return @options[index].value\n index = index + 1\n return null\n\nRadio:setValue(value)\n selected = false\n index = 0\n for @choices as choice\n choice.checked = !selected and sameValue(@options[index].value, value)\n if choice.checked\n selected = true\n index = index + 1\n return @this\n\nsameValue(first, second)\n if is_array(first)\n if !is_array(second) or first.length != second.length\n return false\n index = 0\n for first as item\n if !sameValue(item, second[index])\n return false\n index = index + 1\n return true\n if is_object(first)\n if !is_object(second) or is_array(second) or Object/keys(first).length != Object/keys(second).length\n return false\n for first as name: value\n if !Object/hasOwn(second, name) or !sameValue(value, second[name])\n return false\n return true\n return first == second\n\ninputElement(props)\n input = cloneMarkup(\"input\", <input class=\"form-control\" />)\n variant = props.variant\n if variant == null\n variant = \"text\"\n variant = variant.toLowerCase()\n if variant == \"string\"\n variant = \"text\"\n allowed = [\"text\", \"email\", \"password\", \"search\", \"tel\", \"url\", \"number\", \"decimal\", \"money\"]\n if !allowed.includes(variant)\n throw \"Unsupported input variant: ${variant}\"\n if props.lines != null and props.lines > 1\n if variant != \"text\"\n throw \"Multiline input requires text or String\"\n input = cloneMarkup(\"textarea\", <textarea class=\"form-control\"></textarea>)\n input.rows = props.lines\n else\n input.type = variant\n if variant == \"decimal\" or variant == \"money\"\n input.type = \"text\"\n input.inputMode = \"decimal\"\n return input\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}