@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,852 @@
1
+ import { Control } from "./control.mjs";
2
+ import { Form } from "./form.mjs";
3
+ import { Alert } from "./widgets.mjs";
4
+ import { appendContent } from "./content.mjs";
5
+ import { cloneMarkup, controlId } from "./templates.mjs";
6
+ import {
7
+ hostGlobal as __hostGlobal,
8
+ xmlEscape as __xmlEscape,
9
+ getClass as __getClass,
10
+ isKindof as __isKindof,
11
+ isNumber as __isNumber,
12
+ isString as __isString,
13
+ isBool as __isBool,
14
+ isObject as __isObject,
15
+ isArray as __isArray,
16
+ add as __add,
17
+ remove as __remove,
18
+ requireBoolean as __requireBoolean,
19
+ normalize as __normalize,
20
+ boundary as __boundary,
21
+ requireArity as __requireArity,
22
+ withArity as __withArity,
23
+ } from "./.lango/runtime.mjs";
24
+
25
+ export class Toast extends Control {
26
+ #closed;
27
+ #timer;
28
+ #scope;
29
+ constructor(form, props, renderer) {
30
+ super(form, props, cloneMarkup("toast", ["<div class=\"toast show\" role=\"status\" aria-live=\"polite\"><div class=\"toast-header\"></div><div class=\"toast-body\"></div></div>"].join("")));
31
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
32
+ form = __boundary(form);
33
+ props = __boundary(props);
34
+ renderer = __boundary(renderer);
35
+ this.#closed = false;
36
+ this.#timer = null;
37
+ this.#scope = new Form(__normalize(form.app), form, __normalize(form.token));
38
+ this.#scope.presentation = this;
39
+ this.#scope.inheritThrough = true;
40
+ this.#scope.element = __normalize(this.element);
41
+ try {
42
+ let header = __normalize(this.element.firstElementChild);
43
+ appendContent(__normalize(this.#scope), header, __normalize(props.header), renderer);
44
+ let button = closeButton();
45
+ __normalize(header.appendChild(button));
46
+ appendContent(__normalize(this.#scope), __normalize(this.element.lastElementChild), __normalize(props.body), renderer);
47
+ if (__requireBoolean(__normalize(props.theme) !== null)) {
48
+ __add(this.element.classList, `text-bg-${__normalize(props.theme.toLowerCase())}`);
49
+ }
50
+ if (__requireBoolean(__normalize(props.translucent) === false)) {
51
+ __normalize(this.element.style.setProperty("--bs-toast-bg", "var(--bs-body-bg)"));
52
+ __normalize(this.element.style.setProperty("--bs-bg-opacity", "1"));
53
+ }
54
+ if (__requireBoolean(__normalize(props.translucent) === true)) {
55
+ __normalize(this.element.style.setProperty("--bs-bg-opacity", ".85"));
56
+ }
57
+ let listener = () => {
58
+ this.close();
59
+ return null;
60
+ };
61
+ __normalize(button.addEventListener("click", listener));
62
+ let release = () => {
63
+ __normalize(button.removeEventListener("click", listener));
64
+ return null;
65
+ };
66
+ __add(this.release, release);
67
+ if (__requireBoolean(__normalize(props.instant) === true)) {
68
+ let action = () => {
69
+ this.close();
70
+ return null;
71
+ };
72
+ this.#timer = __normalize(form.app.schedule(action, 5000));
73
+ }
74
+ } catch (error) {
75
+ this.dispose();
76
+ throw error;
77
+ }
78
+ }
79
+ find(name) {
80
+ __requireArity(arguments.length, [0], "find");
81
+ name = __boundary(name);
82
+ return __normalize(this.#scope.find(name));
83
+ return null;
84
+ }
85
+ close() {
86
+ this.dispose();
87
+ return null;
88
+ return null;
89
+ }
90
+ dispose() {
91
+ if (__requireBoolean(!__requireBoolean(__normalize(this.#closed)))) {
92
+ this.#closed = true;
93
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
94
+ __normalize(this.form.app.cancelTimer(__normalize(this.#timer)));
95
+ this.#timer = null;
96
+ }
97
+ __normalize(this.#scope.dispose());
98
+ __normalize(this.form.unregister(this));
99
+ super.dispose();
100
+ __remove(this.element);
101
+ }
102
+ return null;
103
+ return null;
104
+ }
105
+ }
106
+
107
+ export class ToastStack extends Control {
108
+ #renderer;
109
+ #scope;
110
+ #closed;
111
+ constructor(form, props, renderer) {
112
+ super(form, props, cloneMarkup("toast-stack", ["<div class=\"toast-container lango-toast-stack\"></div>"].join("")));
113
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
114
+ form = __boundary(form);
115
+ props = __boundary(props);
116
+ renderer = __boundary(renderer);
117
+ this.#renderer = renderer;
118
+ this.#scope = new Form(__normalize(form.app), form, __normalize(form.token));
119
+ this.#scope.inheritThrough = true;
120
+ this.#scope.element = __normalize(this.element);
121
+ this.#closed = false;
122
+ try {
123
+ if (__requireBoolean(__normalize(props.toasts) !== null)) {
124
+ for (const toast of __normalize(props.toasts)) {
125
+ this.add(toast, __normalize(form.token));
126
+ }
127
+ }
128
+ } catch (error) {
129
+ this.dispose();
130
+ throw error;
131
+ }
132
+ }
133
+ add(props, token) {
134
+ __requireArity(arguments.length, [0, 1], "add");
135
+ props = __boundary(props);
136
+ token = __boundary(token);
137
+ this.#scope.token = token;
138
+ return mountToast(__normalize(this.#scope), props, __normalize(this.element), __normalize(this.#renderer));
139
+ return null;
140
+ }
141
+ find(name) {
142
+ __requireArity(arguments.length, [0], "find");
143
+ name = __boundary(name);
144
+ return __normalize(this.#scope.find(name));
145
+ return null;
146
+ }
147
+ dispose() {
148
+ if (__requireBoolean(!__requireBoolean(__normalize(this.#closed)))) {
149
+ this.#closed = true;
150
+ __normalize(this.#scope.dispose());
151
+ __normalize(this.form.unregister(this));
152
+ super.dispose();
153
+ __remove(this.element);
154
+ }
155
+ return null;
156
+ return null;
157
+ }
158
+ }
159
+
160
+ export class Dialog extends Form {
161
+ owner;
162
+ name;
163
+ modal;
164
+ #manager;
165
+ #listeners;
166
+ #focus;
167
+ #closing;
168
+ #closeUrl;
169
+ #button;
170
+ constructor(owner, props, renderer, manager, source) {
171
+ super(__normalize(owner.app), owner, __normalize(source.token));
172
+ __requireArity(arguments.length, [0, 1, 2, 3, 4], "constructor");
173
+ owner = __boundary(owner);
174
+ props = __boundary(props);
175
+ renderer = __boundary(renderer);
176
+ manager = __boundary(manager);
177
+ source = __boundary(source);
178
+ this.owner = owner;
179
+ this.presentation = this;
180
+ this.#manager = manager;
181
+ this.name = __normalize(props.name);
182
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.name) === null) && __requireBoolean(__isObject(__normalize(props.body)))) && __requireBoolean(props.body.type === "form"))) {
183
+ this.name = props.body.name;
184
+ }
185
+ this.modal = cloneMarkup("dialog", ["<dialog class=\"lango-dialog\" tabindex=\"-1\"><div class=\"modal-content\"><div class=\"modal-header\"><h2 class=\"modal-title fs-5\"></h2></div><div class=\"lango-dialog-content\"></div></div></dialog>"].join(""));
186
+ this.element = __normalize(this.modal.querySelector(".lango-dialog-content"));
187
+ this.#listeners = [];
188
+ this.#focus = null;
189
+ this.#closing = false;
190
+ this.#closeUrl = __normalize(props.closeUrl);
191
+ try {
192
+ if (__requireBoolean(__normalize(this.#closeUrl) !== null)) {
193
+ __normalize(owner.app.checkUrl(__normalize(this.#closeUrl)));
194
+ }
195
+ checkName(__normalize(this.name));
196
+ let heading = __normalize(this.modal.querySelector(".modal-title"));
197
+ heading.id = controlId();
198
+ heading.textContent = titleText(__normalize(props.title));
199
+ __normalize(this.modal.setAttribute("aria-labelledby", __normalize(heading.id)));
200
+ this.#button = closeButton();
201
+ __normalize(__normalize(this.modal.querySelector(".modal-header")).appendChild(__normalize(this.#button)));
202
+ let body = __normalize(__hostGlobal(["document"]).createElement("div"));
203
+ body.className = "modal-body";
204
+ __normalize(this.element.appendChild(body));
205
+ if (__requireBoolean(__requireBoolean(__isObject(__normalize(props.body))) && __requireBoolean(props.body.type === "form"))) {
206
+ this.inheritedNames = props.body.inheritedNames;
207
+ if (__requireBoolean(__normalize(this.inheritedNames) === null)) {
208
+ this.inheritedNames = [];
209
+ }
210
+ for (const control of props.body.controls) {
211
+ __normalize(body.appendChild(__normalize(renderer.build(this, control))));
212
+ }
213
+ } else {
214
+ appendContent(this, body, __normalize(props.body), renderer);
215
+ }
216
+ if (__requireBoolean(__normalize(props.footer) !== null)) {
217
+ let footer = __normalize(__hostGlobal(["document"]).createElement("div"));
218
+ footer.className = "modal-footer";
219
+ appendContent(this, footer, __normalize(props.footer), renderer);
220
+ __normalize(this.element.appendChild(footer));
221
+ }
222
+ if (__requireBoolean(__normalize(props.dark) === true)) {
223
+ __normalize(this.modal.setAttribute("data-bs-theme", "dark"));
224
+ }
225
+ if (__requireBoolean(__normalize(props.blur) === true)) {
226
+ __add(this.modal.classList, "lango-dialog-blur");
227
+ }
228
+ if (__requireBoolean(__normalize(props.scrollable) === true)) {
229
+ __add(this.modal.classList, "lango-dialog-scrollable");
230
+ }
231
+ if (__requireBoolean(__normalize(props.size) !== null)) {
232
+ let sizes = ["sm", "lg", "xl", "fullscreen"];
233
+ if (__requireBoolean(!__requireBoolean(__normalize(sizes.includes(__normalize(props.size)))))) {
234
+ throw "Unsupported dialog size";
235
+ }
236
+ __add(this.modal.classList, `lango-dialog-${__normalize(props.size)}`);
237
+ }
238
+ let cancel = __withArity((event) => {
239
+ event = __boundary(event);
240
+ __normalize(event.preventDefault());
241
+ this.userClose();
242
+ return null;
243
+ }, [0], "closure");
244
+ let click = () => {
245
+ this.userClose();
246
+ return null;
247
+ };
248
+ let focused = __withArity((event) => {
249
+ event = __boundary(event);
250
+ this.#focus = __normalize(event.target);
251
+ return __normalize(this.#focus);
252
+ return null;
253
+ }, [0], "closure");
254
+ __normalize(this.modal.addEventListener("cancel", cancel));
255
+ __normalize(this.#button.addEventListener("click", click));
256
+ __normalize(this.modal.addEventListener("focusin", focused));
257
+ this.#listeners = [cancel, click, focused];
258
+ } catch (error) {
259
+ this.dispose();
260
+ throw error;
261
+ }
262
+ }
263
+ open() {
264
+ let saved = __normalize(this.#focus);
265
+ if (__requireBoolean(!__requireBoolean(__normalize(this.modal.isConnected)))) {
266
+ __normalize(__hostGlobal(["document"]).body.appendChild(__normalize(this.modal)));
267
+ }
268
+ if (__requireBoolean(!__requireBoolean(__normalize(this.modal.open)))) {
269
+ __normalize(this.modal.showModal());
270
+ }
271
+ if (__requireBoolean(__requireBoolean(saved !== null) && __requireBoolean(__normalize(this.modal.contains(saved))))) {
272
+ this.#focus = saved;
273
+ }
274
+ this.focusSaved();
275
+ return null;
276
+ return null;
277
+ }
278
+ bind() {
279
+ let controls = __normalize(this.owner.controls);
280
+ if (__requireBoolean(!__requireBoolean(__normalize(this.owner.owned.includes(this))))) {
281
+ __normalize(this.owner.register(__normalize(this.name), this));
282
+ } else {
283
+ if (__requireBoolean(__normalize(this.name) !== null)) {
284
+ let existing = __normalize(controls[__normalize(this.name)]);
285
+ if (__requireBoolean(__requireBoolean(existing !== null) && __requireBoolean(existing !== this))) {
286
+ throw `Duplicate dialog name: ${__normalize(this.name)}`;
287
+ }
288
+ controls[__normalize(this.name)] = this;
289
+ }
290
+ }
291
+ return null;
292
+ return null;
293
+ }
294
+ hide() {
295
+ let controls = __normalize(this.owner.controls);
296
+ for (const name of __normalize(__hostGlobal(["Object"]).keys(controls))) {
297
+ if (__requireBoolean(__normalize(controls[name]) === this)) {
298
+ __normalize(__hostGlobal(["Reflect"]).deleteProperty(controls, name));
299
+ }
300
+ }
301
+ if (__requireBoolean(__normalize(this.modal.open))) {
302
+ __normalize(this.modal.close());
303
+ }
304
+ return null;
305
+ return null;
306
+ }
307
+ focusSaved() {
308
+ if (__requireBoolean(__requireBoolean(__normalize(this.#focus) !== null) && __requireBoolean(__normalize(this.modal.contains(__normalize(this.#focus)))))) {
309
+ __normalize(this.#focus.focus());
310
+ } else {
311
+ __normalize(this.modal.focus());
312
+ }
313
+ return null;
314
+ return null;
315
+ }
316
+ userClose() {
317
+ if (__requireBoolean(__requireBoolean(__normalize(this.disposed)) || __requireBoolean(__normalize(this.#closing)))) {
318
+ return null;
319
+ }
320
+ if (__requireBoolean(__normalize(this.#closeUrl) === null)) {
321
+ __normalize(this.#manager.closeSpecific(this));
322
+ return null;
323
+ }
324
+ this.#closing = true;
325
+ this.#button.disabled = true;
326
+ return this.send(__normalize(this.#closeUrl)).then(__withArity((ignored) => {
327
+ ignored = __boundary(ignored);
328
+ if (__requireBoolean(!__requireBoolean(__normalize(this.disposed)))) {
329
+ __normalize(this.#manager.closeSpecific(this));
330
+ }
331
+ return null;
332
+ }, [0], "closure")).catch(__withArity((error) => {
333
+ error = __boundary(error);
334
+ if (__requireBoolean(!__requireBoolean(__normalize(this.disposed)))) {
335
+ __normalize(this.app.error(this, error, "DialogCloseFailed"));
336
+ }
337
+ return null;
338
+ }, [0], "closure")).finally(() => {
339
+ this.#closing = false;
340
+ this.#button.disabled = false;
341
+ return null;
342
+ });
343
+ return null;
344
+ }
345
+ dispose() {
346
+ if (__requireBoolean(__normalize(this.disposed))) {
347
+ return null;
348
+ }
349
+ this.hide();
350
+ if (__requireBoolean(__normalize(this.#listeners.length) > 0)) {
351
+ __normalize(this.modal.removeEventListener("cancel", __normalize(this.#listeners[0])));
352
+ __normalize(this.#button.removeEventListener("click", __normalize(this.#listeners[1])));
353
+ __normalize(this.modal.removeEventListener("focusin", __normalize(this.#listeners[2])));
354
+ }
355
+ __normalize(this.owner.unregister(this));
356
+ __normalize(this.#manager.forgetDialog(this));
357
+ super.dispose();
358
+ __remove(this.modal);
359
+ return null;
360
+ return null;
361
+ }
362
+ }
363
+
364
+ export class Presentations {
365
+ #renderer;
366
+ #slots;
367
+ #regions;
368
+ constructor(renderer) {
369
+ __requireArity(arguments.length, [0], "constructor");
370
+ renderer = __boundary(renderer);
371
+ this.#renderer = renderer;
372
+ this.#slots = [];
373
+ this.#regions = [];
374
+ }
375
+ showAlert(form, command) {
376
+ __requireArity(arguments.length, [0, 1], "showAlert");
377
+ form = __boundary(form);
378
+ command = __boundary(command);
379
+ checkName(__normalize(command.name));
380
+ let parent = __normalize(form.element);
381
+ let anchor = null;
382
+ let position = "inside";
383
+ let lifetime = form;
384
+ if (__requireBoolean(__normalize(command.place) !== null)) {
385
+ let place = __normalize(command.place);
386
+ let positions = ["before", "after", "inside"];
387
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(place))) || __requireBoolean(!__requireBoolean(__isString(__normalize(place.name))))) || __requireBoolean(!__requireBoolean(__normalize(positions.includes(__normalize(place.position))))))) {
388
+ throw "Alert place requires name and position";
389
+ }
390
+ let target = __normalize(form.find(__normalize(place.name)));
391
+ anchor = __normalize(target.element);
392
+ position = __normalize(place.position);
393
+ if (__requireBoolean(__isKindof(target, Form))) {
394
+ lifetime = target;
395
+ if (__requireBoolean(__requireBoolean(position !== "inside") && __requireBoolean(__normalize(target.parent) !== null))) {
396
+ lifetime = __normalize(target.parent);
397
+ }
398
+ } else {
399
+ if (__requireBoolean(__normalize(target.form) !== null)) {
400
+ lifetime = __normalize(target.form);
401
+ }
402
+ }
403
+ if (__requireBoolean(position === "inside")) {
404
+ parent = anchor;
405
+ } else {
406
+ parent = __normalize(anchor.parentElement);
407
+ }
408
+ if (__requireBoolean(parent === null)) {
409
+ throw "Alert target is not mounted";
410
+ }
411
+ }
412
+ let old = null;
413
+ let controls = __normalize(form.controls);
414
+ let name = __normalize(command.name);
415
+ if (__requireBoolean(__normalize(command.name) !== null)) {
416
+ old = __normalize(controls[name]);
417
+ if (__requireBoolean(__requireBoolean(old !== null) && __requireBoolean(!__requireBoolean(__isKindof(old, Alert))))) {
418
+ throw "Alert name belongs to another control";
419
+ }
420
+ }
421
+ if (__requireBoolean(__requireBoolean(__requireBoolean(old !== null) && __requireBoolean(anchor === __normalize(old.element))) && __requireBoolean(position === "inside"))) {
422
+ throw "Alert cannot be placed inside itself";
423
+ }
424
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(old !== null) && __requireBoolean(anchor !== null)) && __requireBoolean(anchor !== __normalize(old.element))) && __requireBoolean(__normalize(old.element.contains(anchor))))) {
425
+ throw "Replacement Alert target is inside its previous content";
426
+ }
427
+ let previous = __normalize(form.controls);
428
+ let owned = __normalize(form.owned);
429
+ let staged = __normalize(__hostGlobal(["Object"]).assign(__normalize(__hostGlobal(["Object"]).create(null)), previous));
430
+ if (__requireBoolean(old !== null)) {
431
+ let removed = __normalize(old.contentControls());
432
+ __add(removed, old);
433
+ for (const key of __normalize(__hostGlobal(["Object"]).keys(staged))) {
434
+ if (__requireBoolean(__normalize(removed.includes(__normalize(staged[key]))))) {
435
+ __normalize(__hostGlobal(["Reflect"]).deleteProperty(staged, key));
436
+ }
437
+ }
438
+ }
439
+ form.controls = staged;
440
+ form.owned = [];
441
+ let alert = null;
442
+ try {
443
+ alert = new Alert(form, command, __normalize(this.#renderer));
444
+ __normalize(form.register(__normalize(command.name), alert));
445
+ __normalize(alert.attach(lifetime));
446
+ if (__requireBoolean(position === "before")) {
447
+ __normalize(parent.insertBefore(__normalize(alert.element), anchor));
448
+ } else {
449
+ if (__requireBoolean(position === "after")) {
450
+ __normalize(parent.insertBefore(__normalize(alert.element), __normalize(anchor.nextSibling)));
451
+ } else {
452
+ __normalize(parent.prepend(__normalize(alert.element)));
453
+ }
454
+ }
455
+ } catch (error) {
456
+ for (const child of __normalize(form.owned.slice())) {
457
+ __normalize(child.dispose());
458
+ }
459
+ form.controls = previous;
460
+ form.owned = owned;
461
+ throw error;
462
+ }
463
+ let children = __normalize(form.owned);
464
+ form.owned = owned;
465
+ if (__requireBoolean(old !== null)) {
466
+ __normalize(old.close());
467
+ }
468
+ for (const child of children) {
469
+ form.owned.push(child);
470
+ }
471
+ return null;
472
+ return null;
473
+ }
474
+ dismissAlert(form, name) {
475
+ __requireArity(arguments.length, [0, 1], "dismissAlert");
476
+ form = __boundary(form);
477
+ name = __boundary(name);
478
+ let control = null;
479
+ try {
480
+ control = __normalize(form.find(name));
481
+ } catch (error) {
482
+ if (__requireBoolean(__requireBoolean(__isString(error)) && __requireBoolean(__normalize(error.startsWith("Unknown control:"))))) {
483
+ return null;
484
+ }
485
+ throw error;
486
+ }
487
+ if (__requireBoolean(!__requireBoolean(__isKindof(control, Alert)))) {
488
+ throw "DismissAlert requires an Alert";
489
+ }
490
+ __normalize(control.close());
491
+ return null;
492
+ return null;
493
+ }
494
+ showToast(form, props, stack = null) {
495
+ __requireArity(arguments.length, [0, 1], "showToast");
496
+ form = __boundary(form);
497
+ props = __boundary(props);
498
+ stack = __boundary(stack);
499
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(props))) || __requireBoolean(__normalize(props.type) !== "toast"))) {
500
+ throw "ShowToast requires a Toast definition";
501
+ }
502
+ checkName(__normalize(props.name));
503
+ if (__requireBoolean(stack !== null)) {
504
+ let target = __normalize(form.find(stack));
505
+ if (__requireBoolean(!__requireBoolean(__isKindof(target, ToastStack)))) {
506
+ throw "ShowToast requires a ToastStack";
507
+ }
508
+ __add(target, props, __normalize(form.token));
509
+ return null;
510
+ }
511
+ let position = __normalize(props.position);
512
+ if (__requireBoolean(position === null)) {
513
+ position = "bottom-right";
514
+ }
515
+ let positions = ["top-left", "top-center", "top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", "bottom-right"];
516
+ if (__requireBoolean(!__requireBoolean(__normalize(positions.includes(position))))) {
517
+ throw "Unsupported toast position";
518
+ }
519
+ let region = null;
520
+ let created = false;
521
+ for (const current of __normalize(this.#regions)) {
522
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.form) === form) && __requireBoolean(current.element.isConnected)) && __requireBoolean(__normalize(current.position) === position))) {
523
+ region = current;
524
+ }
525
+ }
526
+ if (__requireBoolean(region === null)) {
527
+ region = new ToastRegion(form, position, this);
528
+ __add(this.#regions, region);
529
+ __normalize(form.register(null, region));
530
+ __normalize(form.element.appendChild(__normalize(region.element)));
531
+ created = true;
532
+ }
533
+ try {
534
+ mountToast(form, props, __normalize(region.element), __normalize(this.#renderer));
535
+ } catch (error) {
536
+ if (__requireBoolean(created)) {
537
+ __normalize(region.dispose());
538
+ }
539
+ throw error;
540
+ }
541
+ return null;
542
+ return null;
543
+ }
544
+ slot(owner, create = true) {
545
+ __requireArity(arguments.length, [0], "slot");
546
+ owner = __boundary(owner);
547
+ create = __boundary(create);
548
+ for (const current of __normalize(this.#slots)) {
549
+ if (__requireBoolean(__normalize(current.owner) === owner)) {
550
+ return current;
551
+ }
552
+ }
553
+ if (__requireBoolean(!__requireBoolean(create))) {
554
+ return null;
555
+ }
556
+ let result = { owner: owner, current: null, previous: null };
557
+ __add(this.#slots, result);
558
+ return result;
559
+ return null;
560
+ }
561
+ showDialog(form, props, keepPrev = false) {
562
+ __requireArity(arguments.length, [0, 1], "showDialog");
563
+ form = __boundary(form);
564
+ props = __boundary(props);
565
+ keepPrev = __boundary(keepPrev);
566
+ if (__requireBoolean(keepPrev === null)) {
567
+ keepPrev = false;
568
+ }
569
+ if (__requireBoolean(!__requireBoolean(__isBool(keepPrev)))) {
570
+ throw "Dialog keepPrev must be boolean";
571
+ }
572
+ if (__requireBoolean(props === null)) {
573
+ let current = containingDialog(form);
574
+ if (__requireBoolean(current === null)) {
575
+ let existingSlot = this.slot(form, false);
576
+ if (__requireBoolean(existingSlot !== null)) {
577
+ current = __normalize(existingSlot.current);
578
+ }
579
+ }
580
+ if (__requireBoolean(current !== null)) {
581
+ this.closeSpecific(current);
582
+ }
583
+ return null;
584
+ }
585
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(props))) || __requireBoolean(__normalize(props.type) !== "dialog"))) {
586
+ throw "ShowDialog requires a Dialog definition";
587
+ }
588
+ let owner = form;
589
+ let containing = containingDialog(form);
590
+ if (__requireBoolean(containing !== null)) {
591
+ owner = __normalize(containing.owner);
592
+ }
593
+ let currentSlot = this.slot(owner);
594
+ let candidate = new Dialog(owner, props, __normalize(this.#renderer), this, form);
595
+ let existing = null;
596
+ let controls = __normalize(owner.controls);
597
+ let name = __normalize(candidate.name);
598
+ if (__requireBoolean(__normalize(candidate.name) !== null)) {
599
+ existing = __normalize(controls[name]);
600
+ }
601
+ if (__requireBoolean(__requireBoolean(existing !== null) && __requireBoolean(existing !== __normalize(currentSlot.current)))) {
602
+ __normalize(candidate.dispose());
603
+ throw "Dialog name belongs to another control";
604
+ }
605
+ try {
606
+ __normalize(candidate.open());
607
+ } catch (error) {
608
+ __normalize(candidate.dispose());
609
+ throw error;
610
+ }
611
+ let old = __normalize(currentSlot.current);
612
+ let previous = __normalize(currentSlot.previous);
613
+ if (__requireBoolean(old !== null)) {
614
+ __normalize(old.hide());
615
+ }
616
+ __normalize(candidate.bind());
617
+ currentSlot.current = candidate;
618
+ currentSlot.previous = null;
619
+ if (__requireBoolean(keepPrev)) {
620
+ currentSlot.previous = old;
621
+ } else {
622
+ if (__requireBoolean(old !== null)) {
623
+ __normalize(old.dispose());
624
+ }
625
+ }
626
+ if (__requireBoolean(__requireBoolean(previous !== null) && __requireBoolean(previous !== old))) {
627
+ __normalize(previous.dispose());
628
+ }
629
+ __normalize(candidate.focusSaved());
630
+ return null;
631
+ return null;
632
+ }
633
+ swapDialog(form) {
634
+ __requireArity(arguments.length, [0], "swapDialog");
635
+ form = __boundary(form);
636
+ let owner = form;
637
+ let containing = containingDialog(form);
638
+ if (__requireBoolean(containing !== null)) {
639
+ owner = __normalize(containing.owner);
640
+ }
641
+ let currentSlot = this.slot(owner, false);
642
+ if (__requireBoolean(currentSlot === null)) {
643
+ return null;
644
+ }
645
+ let current = __normalize(currentSlot.current);
646
+ let previous = __normalize(currentSlot.previous);
647
+ if (__requireBoolean(__requireBoolean(current === null) || __requireBoolean(previous === null))) {
648
+ return null;
649
+ }
650
+ checkAlias(previous, current);
651
+ __normalize(current.hide());
652
+ __normalize(previous.open());
653
+ __normalize(previous.bind());
654
+ currentSlot.current = previous;
655
+ currentSlot.previous = current;
656
+ return null;
657
+ return null;
658
+ }
659
+ closeSpecific(dialog) {
660
+ __requireArity(arguments.length, [0], "closeSpecific");
661
+ dialog = __boundary(dialog);
662
+ let currentSlot = this.slot(__normalize(dialog.owner), false);
663
+ if (__requireBoolean(currentSlot === null)) {
664
+ __normalize(dialog.dispose());
665
+ return null;
666
+ }
667
+ let restore = null;
668
+ if (__requireBoolean(__normalize(currentSlot.current) === dialog)) {
669
+ restore = __normalize(currentSlot.previous);
670
+ if (__requireBoolean(restore !== null)) {
671
+ checkAlias(restore, dialog);
672
+ }
673
+ currentSlot.current = restore;
674
+ currentSlot.previous = null;
675
+ }
676
+ if (__requireBoolean(__normalize(currentSlot.previous) === dialog)) {
677
+ currentSlot.previous = null;
678
+ }
679
+ __normalize(dialog.dispose());
680
+ if (__requireBoolean(__requireBoolean(restore !== null) && __requireBoolean(!__requireBoolean(__normalize(restore.disposed))))) {
681
+ __normalize(restore.open());
682
+ __normalize(restore.bind());
683
+ }
684
+ return null;
685
+ return null;
686
+ }
687
+ forgetDialog(dialog) {
688
+ __requireArity(arguments.length, [0], "forgetDialog");
689
+ dialog = __boundary(dialog);
690
+ for (const current of __normalize(this.#slots.slice())) {
691
+ if (__requireBoolean(__normalize(current.current) === dialog)) {
692
+ current.current = null;
693
+ }
694
+ if (__requireBoolean(__normalize(current.previous) === dialog)) {
695
+ current.previous = null;
696
+ }
697
+ if (__requireBoolean(__requireBoolean(__normalize(current.current) === null) && __requireBoolean(__normalize(current.previous) === null))) {
698
+ __normalize(this.#slots.splice(__normalize(this.#slots.indexOf(current)), 1));
699
+ }
700
+ }
701
+ return null;
702
+ return null;
703
+ }
704
+ forgetRegion(region) {
705
+ __requireArity(arguments.length, [0], "forgetRegion");
706
+ region = __boundary(region);
707
+ let index = __normalize(this.#regions.indexOf(region));
708
+ if (__requireBoolean(index >= 0)) {
709
+ __normalize(this.#regions.splice(index, 1));
710
+ }
711
+ return null;
712
+ return null;
713
+ }
714
+ dismiss(form) {
715
+ __requireArity(arguments.length, [0], "dismiss");
716
+ form = __boundary(form);
717
+ let current = form;
718
+ __loop1: while (__requireBoolean(current !== null)) {
719
+ let presentation = __normalize(current.presentation);
720
+ if (__requireBoolean(presentation !== null)) {
721
+ if (__requireBoolean(__isKindof(presentation, Dialog))) {
722
+ return __normalize(presentation.userClose());
723
+ }
724
+ if (__requireBoolean(__isKindof(presentation, Toast))) {
725
+ __normalize(presentation.close());
726
+ return null;
727
+ }
728
+ }
729
+ current = __normalize(current.parent);
730
+ }
731
+ return null;
732
+ return null;
733
+ }
734
+ }
735
+
736
+ class ToastRegion extends Control {
737
+ position;
738
+ #manager;
739
+ constructor(form, position, manager) {
740
+ super(form, { }, cloneMarkup("toast-region", ["<div class=\"toast-container lango-toast-region\"></div>"].join("")));
741
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
742
+ form = __boundary(form);
743
+ position = __boundary(position);
744
+ manager = __boundary(manager);
745
+ this.position = position;
746
+ this.#manager = manager;
747
+ __normalize(this.element.setAttribute("data-position", position));
748
+ }
749
+ dispose() {
750
+ __normalize(this.form.unregister(this));
751
+ __normalize(this.#manager.forgetRegion(this));
752
+ super.dispose();
753
+ __remove(this.element);
754
+ return null;
755
+ return null;
756
+ }
757
+ }
758
+ function mountToast(form, props, parent, renderer) {
759
+ __requireArity(arguments.length, [0, 1, 2, 3], "mountToast");
760
+ form = __boundary(form);
761
+ props = __boundary(props);
762
+ parent = __boundary(parent);
763
+ renderer = __boundary(renderer);
764
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(props))) || __requireBoolean(__normalize(props.type) !== "toast"))) {
765
+ throw "ShowToast requires a Toast definition";
766
+ }
767
+ checkName(__normalize(props.name));
768
+ let old = null;
769
+ let controls = __normalize(form.controls);
770
+ let name = __normalize(props.name);
771
+ if (__requireBoolean(__normalize(props.name) !== null)) {
772
+ old = __normalize(controls[name]);
773
+ if (__requireBoolean(__requireBoolean(old !== null) && __requireBoolean(!__requireBoolean(__isKindof(old, Toast))))) {
774
+ throw "Toast name belongs to another control";
775
+ }
776
+ }
777
+ let toast = new Toast(form, props, renderer);
778
+ if (__requireBoolean(old !== null)) {
779
+ __normalize(old.close());
780
+ }
781
+ __normalize(form.register(__normalize(props.name), toast));
782
+ __normalize(parent.appendChild(__normalize(toast.element)));
783
+ return toast;
784
+ return null;
785
+ }
786
+
787
+ function titleText(value) {
788
+ __requireArity(arguments.length, [0], "titleText");
789
+ value = __boundary(value);
790
+ if (__requireBoolean(value === null)) {
791
+ return "";
792
+ }
793
+ if (__requireBoolean(__requireBoolean(__isObject(value)) && __requireBoolean(__normalize(value.type) === "text"))) {
794
+ return __normalize(value.text);
795
+ }
796
+ if (__requireBoolean(!__requireBoolean(__isString(value)))) {
797
+ throw "Dialog title must be text";
798
+ }
799
+ return value;
800
+ return null;
801
+ }
802
+
803
+ function closeButton() {
804
+ let button = __normalize(__hostGlobal(["document"]).createElement("button"));
805
+ button.type = "button";
806
+ button.className = "btn-close";
807
+ __normalize(button.setAttribute("aria-label", "×"));
808
+ return button;
809
+ return null;
810
+ }
811
+
812
+ function containingDialog(form) {
813
+ __requireArity(arguments.length, [0], "containingDialog");
814
+ form = __boundary(form);
815
+ let current = form;
816
+ __loop2: while (__requireBoolean(current !== null)) {
817
+ if (__requireBoolean(__isKindof(current, Dialog))) {
818
+ return current;
819
+ }
820
+ current = __normalize(current.parent);
821
+ }
822
+ return null;
823
+ return null;
824
+ }
825
+
826
+ function checkName(name) {
827
+ __requireArity(arguments.length, [0], "checkName");
828
+ name = __boundary(name);
829
+ if (__requireBoolean(__requireBoolean(name !== null) && __requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(__normalize(name.trim()) === "")) || __requireBoolean(__normalize(name.includes("/")))))) {
830
+ throw "Presentation name must be a single name segment";
831
+ }
832
+ return null;
833
+ return null;
834
+ }
835
+
836
+ function checkAlias(dialog, permitted) {
837
+ __requireArity(arguments.length, [0, 1], "checkAlias");
838
+ dialog = __boundary(dialog);
839
+ permitted = __boundary(permitted);
840
+ if (__requireBoolean(__normalize(dialog.name) === null)) {
841
+ return null;
842
+ }
843
+ let controls = dialog.owner.controls;
844
+ let name = __normalize(dialog.name);
845
+ let current = __normalize(controls[name]);
846
+ if (__requireBoolean(__requireBoolean(__requireBoolean(current !== null) && __requireBoolean(current !== permitted)) && __requireBoolean(current !== dialog))) {
847
+ throw "Dialog name belongs to another control";
848
+ }
849
+ return null;
850
+ return null;
851
+ }
852
+ //# sourceMappingURL=presentations.mjs.map