@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
package/dist/protocol.mjs DELETED
@@ -1,706 +0,0 @@
1
- import { validateProperty } from "./presentation.mjs";
2
- import {
3
- isNumber as __isNumber,
4
- isString as __isString,
5
- isBool as __isBool,
6
- isObject as __isObject,
7
- isArray as __isArray,
8
- includes as __includes,
9
- entries as __entries,
10
- add as __add,
11
- remove as __remove,
12
- requireBoolean as __requireBoolean,
13
- normalize as __normalize,
14
- finite as __finite,
15
- numericAdd as __numericAdd,
16
- boundary as __boundary,
17
- requireArity as __requireArity,
18
- } from "./.lango/runtime.mjs";
19
-
20
- class Field {
21
- name;
22
- enabled;
23
- visible;
24
- value;
25
- controls;
26
- constructor(name, value) {
27
- __requireArity(arguments.length, [0, 1], "constructor");
28
- name = __boundary(name);
29
- value = __boundary(value);
30
- this.name = name;
31
- this.value = value;
32
- this.enabled = true;
33
- this.visible = true;
34
- this.controls = null;
35
- }
36
- getValue() {
37
- if (__requireBoolean(__isArray(__normalize(this.controls)))) {
38
- return collectValues(__normalize(this.controls));
39
- }
40
- return __normalize(this.value);
41
- return null;
42
- }
43
- setValue(value) {
44
- __requireArity(arguments.length, [0], "setValue");
45
- value = __boundary(value);
46
- this.value = value;
47
- return null;
48
- return null;
49
- }
50
- }
51
-
52
- class TestRenderer {
53
- commits;
54
- constructor() {
55
- this.commits = [];
56
- }
57
- create(definition) {
58
- __requireArity(arguments.length, [0], "create");
59
- definition = __boundary(definition);
60
- let field = new Field(__normalize(definition.name), __normalize(definition.value));
61
- if (__requireBoolean(__isArray(__normalize(definition.controls)))) {
62
- field.controls = [];
63
- for (const child of __normalize(definition.controls)) {
64
- field.controls.push(this.create(child));
65
- }
66
- }
67
- return field;
68
- return null;
69
- }
70
- replace(old, replacement) {
71
- __requireArity(arguments.length, [0, 1], "replace");
72
- old = __boundary(old);
73
- replacement = __boundary(replacement);
74
- __add(this.commits, "replace");
75
- return null;
76
- }
77
- remove(control) {
78
- __requireArity(arguments.length, [0], "remove");
79
- control = __boundary(control);
80
- __add(this.commits, "remove");
81
- return null;
82
- }
83
- capture(control) {
84
- __requireArity(arguments.length, [0], "capture");
85
- control = __boundary(control);
86
- return control;
87
- return null;
88
- }
89
- restore(snapshot, operation) {
90
- __requireArity(arguments.length, [0, 1], "restore");
91
- snapshot = __boundary(snapshot);
92
- operation = __boundary(operation);
93
- __add(this.commits, "restore");
94
- return null;
95
- }
96
- focus(control) {
97
- __requireArity(arguments.length, [0], "focus");
98
- control = __boundary(control);
99
- __add(this.commits, "focus");
100
- return null;
101
- }
102
- }
103
-
104
- class FailingField extends Field {
105
- constructor(name, value) {
106
- super(name, value);
107
- __requireArity(arguments.length, [0, 1], "constructor");
108
- name = __boundary(name);
109
- value = __boundary(value);
110
- }
111
- setValue(value) {
112
- __requireArity(arguments.length, [0], "setValue");
113
- value = __boundary(value);
114
- super.setValue(value);
115
- if (__requireBoolean(value === "boom")) {
116
- throw "ExpectedValueFailure";
117
- }
118
- return null;
119
- }
120
- }
121
-
122
- class FailingStateField extends Field {
123
- constructor(name, value) {
124
- super(name, value);
125
- __requireArity(arguments.length, [0, 1], "constructor");
126
- name = __boundary(name);
127
- value = __boundary(value);
128
- }
129
- applyProperty(name, value) {
130
- __requireArity(arguments.length, [0, 1], "applyProperty");
131
- name = __boundary(name);
132
- value = __boundary(value);
133
- this.enabled = value;
134
- throw "ExpectedStateFailure";
135
- return null;
136
- }
137
- snapshotState() {
138
- return { enabled: __normalize(this.enabled), visible: __normalize(this.visible), value: this.getValue() };
139
- return null;
140
- }
141
- restoreState(snapshot) {
142
- __requireArity(arguments.length, [0], "restoreState");
143
- snapshot = __boundary(snapshot);
144
- this.enabled = __normalize(snapshot.enabled);
145
- this.visible = __normalize(snapshot.visible);
146
- this.setValue(__normalize(snapshot.value));
147
- return null;
148
- }
149
- }
150
- export function protocolVersion() {
151
- return 1;
152
- return null;
153
- }
154
-
155
- function requireProtocol(response) {
156
- __requireArity(arguments.length, [0], "requireProtocol");
157
- response = __boundary(response);
158
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(response))) || __requireBoolean(__isArray(response)))) {
159
- throw "UiClientResponseMustBeMap";
160
- }
161
- if (__requireBoolean(__includes("protocol", response))) {
162
- if (__requireBoolean(__normalize(response.protocol) !== protocolVersion())) {
163
- throw "UiProtocolUnsupported";
164
- }
165
- }
166
- return null;
167
- }
168
-
169
- function projectControls(controls, ownerControls = null) {
170
- __requireArity(arguments.length, [0], "projectControls");
171
- controls = __boundary(controls);
172
- ownerControls = __boundary(ownerControls);
173
- let owner = controls;
174
- if (__requireBoolean(ownerControls !== null)) {
175
- owner = ownerControls;
176
- }
177
- let projected = [];
178
- let names = { };
179
- for (const control of controls) {
180
- if (__requireBoolean(__requireBoolean(__normalize(control.name) !== null) && __requireBoolean(__normalize(control.name) !== ""))) {
181
- if (__requireBoolean(!__requireBoolean(__isString(__normalize(control.name))))) {
182
- throw "UiClientControlNameMustBeString";
183
- }
184
- validateName(__normalize(control.name));
185
- if (__requireBoolean(__includes(__normalize(control.name), names))) {
186
- throw `UiDuplicateControlName: ${__normalize(control.name)}`;
187
- }
188
- names[__normalize(control.name)] = true;
189
- }
190
- let children = null;
191
- if (__requireBoolean(__isArray(__normalize(control.controls)))) {
192
- children = projectControls(__normalize(control.controls));
193
- }
194
- projected[__normalize(projected.length)] = { name: __normalize(control.name), control: control, controls: children, owner: owner };
195
- }
196
- return projected;
197
- return null;
198
- }
199
-
200
- function targetPath(target) {
201
- __requireArity(arguments.length, [0], "targetPath");
202
- target = __boundary(target);
203
- if (__requireBoolean(__isString(target))) {
204
- return [target];
205
- }
206
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(target))) || __requireBoolean(__normalize(target.length) === 0))) {
207
- throw "UiClientTargetMustBePathArray";
208
- }
209
- return target;
210
- return null;
211
- }
212
-
213
- function checkConflict(paths, path) {
214
- __requireArity(arguments.length, [0, 1], "checkConflict");
215
- paths = __boundary(paths);
216
- path = __boundary(path);
217
- for (const existing of paths) {
218
- let common = true;
219
- for (const [index, name] of __entries(path)) {
220
- if (__requireBoolean(index < __normalize(existing.length))) {
221
- if (__requireBoolean(__normalize(existing[index]) !== name)) {
222
- common = false;
223
- }
224
- }
225
- }
226
- if (__requireBoolean(common)) {
227
- throw "UiClientOverlappingStructurePatches";
228
- }
229
- }
230
- paths[__normalize(paths.length)] = path;
231
- return null;
232
- return null;
233
- }
234
-
235
- function findProjected(controls, path, optional) {
236
- __requireArity(arguments.length, [0, 1, 2], "findProjected");
237
- controls = __boundary(controls);
238
- path = __boundary(path);
239
- optional = __boundary(optional);
240
- let current = controls;
241
- let node = null;
242
- for (const [index, name] of __entries(path)) {
243
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === ""))) {
244
- throw "UiClientTargetMustContainNames";
245
- }
246
- validateName(name);
247
- node = null;
248
- for (const candidate of current) {
249
- if (__requireBoolean(__normalize(candidate.name) === name)) {
250
- node = candidate;
251
- }
252
- }
253
- if (__requireBoolean(node === null)) {
254
- if (__requireBoolean(optional)) {
255
- return null;
256
- }
257
- throw `UiClientTargetNotFound: ${name}`;
258
- }
259
- if (__requireBoolean(index < __finite(__normalize(path.length) - 1))) {
260
- current = __normalize(node.controls);
261
- if (__requireBoolean(!__requireBoolean(__isArray(current)))) {
262
- throw "UiClientTargetIsNotContainer";
263
- }
264
- }
265
- }
266
- return node;
267
- return null;
268
- }
269
-
270
- function planReplacements(tree, replacements, parentPath, paths, operations, effects, preparedControls) {
271
- __requireArity(arguments.length, [0, 1, 2, 3, 4, 5, 6], "planReplacements");
272
- tree = __boundary(tree);
273
- replacements = __boundary(replacements);
274
- parentPath = __boundary(parentPath);
275
- paths = __boundary(paths);
276
- operations = __boundary(operations);
277
- effects = __boundary(effects);
278
- preparedControls = __boundary(preparedControls);
279
- for (const [name, definition] of __entries(replacements)) {
280
- validateName(name);
281
- let path = __normalize(parentPath.slice());
282
- path[__normalize(path.length)] = name;
283
- if (__requireBoolean(!__requireBoolean(__isObject(definition)))) {
284
- throw "UiClientReplacementMustBeMap";
285
- }
286
- let node = null;
287
- if (__requireBoolean(__isString(__normalize(definition.type)))) {
288
- checkConflict(paths, path);
289
- node = findProjected(tree, path, false);
290
- if (__requireBoolean(node.control.inherited === true)) {
291
- throw "UiInheritedStructureNotAllowed";
292
- }
293
- if (__requireBoolean(__requireBoolean(__normalize(effects.create) === null) || __requireBoolean(__normalize(effects.replace) === null))) {
294
- throw "UiClientStructureAdapterNotConfigured";
295
- }
296
- let prepared = { };
297
- for (const [key, value] of __entries(definition)) {
298
- prepared[key] = value;
299
- }
300
- if (__requireBoolean(__normalize(prepared.name) === null)) {
301
- prepared.name = name;
302
- }
303
- let replacement = __normalize(effects.create(prepared));
304
- __add(preparedControls, replacement);
305
- if (__requireBoolean(__normalize(replacement.name) !== name)) {
306
- throw "UiClientReplacementMustPreserveName";
307
- }
308
- let children = null;
309
- if (__requireBoolean(__isArray(__normalize(replacement.controls)))) {
310
- children = projectControls(__normalize(replacement.controls));
311
- }
312
- operations[__normalize(operations.length)] = { type: "replace", old: __normalize(node.control), new: replacement, owner: __normalize(node.owner) };
313
- node.control = replacement;
314
- node.controls = children;
315
- } else {
316
- node = findProjected(tree, path, false);
317
- if (__requireBoolean(node.control.inherited === true)) {
318
- throw "UiInheritedStructureNotAllowed";
319
- }
320
- planReplacements(tree, definition, path, paths, operations, effects, preparedControls);
321
- }
322
- }
323
- return null;
324
- return null;
325
- }
326
-
327
- function planStructure(controls, patch, effects, ownerControls, preparedControls) {
328
- __requireArity(arguments.length, [0, 1, 2, 3, 4], "planStructure");
329
- controls = __boundary(controls);
330
- patch = __boundary(patch);
331
- effects = __boundary(effects);
332
- ownerControls = __boundary(ownerControls);
333
- preparedControls = __boundary(preparedControls);
334
- let tree = projectControls(controls, ownerControls);
335
- let paths = [];
336
- let operations = [];
337
- planReplacements(tree, __normalize(patch.replace), [], paths, operations, effects, preparedControls);
338
- for (const target of __normalize(patch.remove)) {
339
- let path = targetPath(target);
340
- checkConflict(paths, path);
341
- let node = findProjected(tree, path, true);
342
- if (__requireBoolean(node !== null)) {
343
- if (__requireBoolean(node.control.inherited === true)) {
344
- throw "UiInheritedStructureNotAllowed";
345
- }
346
- if (__requireBoolean(__normalize(effects.remove) === null)) {
347
- throw "UiClientStructureAdapterNotConfigured";
348
- }
349
- operations[__normalize(operations.length)] = { type: "remove", old: __normalize(node.control), owner: __normalize(node.owner) };
350
- node.name = null;
351
- }
352
- }
353
- return { tree: tree, operations: operations };
354
- return null;
355
- }
356
-
357
- function commitStructure(operations, effects, journal) {
358
- __requireArity(arguments.length, [0, 1, 2], "commitStructure");
359
- operations = __boundary(operations);
360
- effects = __boundary(effects);
361
- journal = __boundary(journal);
362
- for (const operation of operations) {
363
- let owner = __normalize(operation.owner);
364
- let index = __normalize(owner.indexOf(__normalize(operation.old)));
365
- if (__requireBoolean(__requireBoolean(__normalize(effects.capture) === null) || __requireBoolean(__normalize(effects.restore) === null))) {
366
- throw "UiClientStructureRollbackNotConfigured";
367
- }
368
- journal[__normalize(journal.length)] = { type: "structure", operation: operation, ownerBefore: __normalize(owner.slice()), snapshot: __normalize(effects.capture(__normalize(operation.old))) };
369
- if (__requireBoolean(__normalize(operation.type) === "replace")) {
370
- __normalize(effects.replace(__normalize(operation.old), __normalize(operation.new)));
371
- __normalize(owner.splice(index, 1, __normalize(operation.new)));
372
- } else {
373
- __remove(effects, __normalize(operation.old));
374
- __normalize(owner.splice(index, 1));
375
- }
376
- }
377
- return null;
378
- return null;
379
- }
380
-
381
- function captureState(target) {
382
- __requireArity(arguments.length, [0], "captureState");
383
- target = __boundary(target);
384
- if (__requireBoolean(__normalize(target.snapshotState) !== null)) {
385
- if (__requireBoolean(__normalize(target.restoreState) === null)) {
386
- throw "UiClientStateRollbackNotConfigured";
387
- }
388
- return { custom: true, value: __normalize(target.snapshotState()) };
389
- }
390
- if (__requireBoolean(__normalize(target.applyProperty) !== null)) {
391
- throw "UiClientStateRollbackNotConfigured";
392
- }
393
- return { custom: false, value: __normalize(target.getValue()), enabled: __normalize(target.enabled), visible: __normalize(target.visible) };
394
- return null;
395
- }
396
-
397
- function restoreState(target, snapshot) {
398
- __requireArity(arguments.length, [0, 1], "restoreState");
399
- target = __boundary(target);
400
- snapshot = __boundary(snapshot);
401
- if (__requireBoolean(__normalize(snapshot.custom))) {
402
- __normalize(target.restoreState(__normalize(snapshot.value)));
403
- } else {
404
- __normalize(target.setValue(__normalize(snapshot.value)));
405
- target.enabled = __normalize(snapshot.enabled);
406
- target.visible = __normalize(snapshot.visible);
407
- }
408
- return null;
409
- return null;
410
- }
411
-
412
- function rollback(journal, effects) {
413
- __requireArity(arguments.length, [0, 1], "rollback");
414
- journal = __boundary(journal);
415
- effects = __boundary(effects);
416
- let entries = __normalize(journal.slice());
417
- __normalize(entries.reverse());
418
- let failures = 0;
419
- for (const entry of entries) {
420
- try {
421
- if (__requireBoolean(__normalize(entry.type) === "state")) {
422
- restoreState(__normalize(entry.target), __normalize(entry.snapshot));
423
- } else {
424
- let operation = __normalize(entry.operation);
425
- let owner = __normalize(operation.owner);
426
- __normalize(owner.splice(0, __normalize(owner.length)));
427
- for (const control of __normalize(entry.ownerBefore)) {
428
- __add(owner, control);
429
- }
430
- __normalize(effects.restore(__normalize(entry.snapshot), operation));
431
- }
432
- } catch (error) {
433
- failures = __numericAdd(failures, 1);
434
- }
435
- }
436
- if (__requireBoolean(failures > 0)) {
437
- throw "UiClientRollbackFailed";
438
- }
439
- return null;
440
- return null;
441
- }
442
-
443
- function applyStateCommand(change) {
444
- __requireArity(arguments.length, [0], "applyStateCommand");
445
- change = __boundary(change);
446
- let target = __normalize(change.target);
447
- let snapshot = captureState(target);
448
- try {
449
- if (__requireBoolean(__normalize(target.applyProperty) !== null)) {
450
- __normalize(target.applyProperty(__normalize(change.property), change.command.value));
451
- } else {
452
- target[__normalize(change.property)] = change.command.value;
453
- }
454
- } catch (error) {
455
- try {
456
- restoreState(target, snapshot);
457
- } catch (restoreError) {
458
- throw "UiClientRollbackFailed";
459
- }
460
- throw error;
461
- }
462
- return null;
463
- return null;
464
- }
465
-
466
- function validateName(name) {
467
- __requireArity(arguments.length, [0], "validateName");
468
- name = __boundary(name);
469
- if (__requireBoolean(__requireBoolean(__requireBoolean(name === "__proto__") || __requireBoolean(name === "constructor")) || __requireBoolean(name === "prototype"))) {
470
- throw `UiReservedControlName: ${name}`;
471
- }
472
- return null;
473
- return null;
474
- }
475
-
476
- export function collectValues(controls) {
477
- __requireArity(arguments.length, [0], "collectValues");
478
- controls = __boundary(controls);
479
- let values = { };
480
- for (const control of controls) {
481
- let name = __normalize(control.name);
482
- if (__requireBoolean(__requireBoolean(name !== null) && __requireBoolean(name !== ""))) {
483
- validateName(name);
484
- if (__requireBoolean(__includes(name, values))) {
485
- throw `UiDuplicateControlName: ${name}`;
486
- }
487
- values[name] = __normalize(control.getValue());
488
- }
489
- }
490
- return values;
491
- return null;
492
- }
493
-
494
- function findControl(controls, name) {
495
- __requireArity(arguments.length, [0, 1], "findControl");
496
- controls = __boundary(controls);
497
- name = __boundary(name);
498
- for (const control of controls) {
499
- if (__requireBoolean(__normalize(control.name) === name)) {
500
- return control;
501
- }
502
- }
503
- throw `UiClientTargetNotFound: ${name}`;
504
- return null;
505
- }
506
-
507
- function resolveTarget(controls, path) {
508
- __requireArity(arguments.length, [0, 1], "resolveTarget");
509
- controls = __boundary(controls);
510
- path = __boundary(path);
511
- let targetPath = path;
512
- if (__requireBoolean(__isString(path))) {
513
- targetPath = [path];
514
- }
515
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(targetPath))) || __requireBoolean(__normalize(targetPath.length) === 0))) {
516
- throw "UiClientTargetMustBePathArray";
517
- }
518
- let current = controls;
519
- let target = null;
520
- for (const [index, name] of __entries(targetPath)) {
521
- if (__requireBoolean(!__requireBoolean(__isString(name)))) {
522
- throw "UiClientTargetMustContainNames";
523
- }
524
- validateName(name);
525
- target = findControl(current, name);
526
- if (__requireBoolean(index < __finite(__normalize(targetPath.length) - 1))) {
527
- current = __normalize(target.controls);
528
- if (__requireBoolean(!__requireBoolean(__isArray(current)))) {
529
- throw "UiClientTargetIsNotContainer";
530
- }
531
- }
532
- }
533
- return target;
534
- return null;
535
- }
536
-
537
- function planValues(controls, values, plan) {
538
- __requireArity(arguments.length, [0, 1, 2], "planValues");
539
- controls = __boundary(controls);
540
- values = __boundary(values);
541
- plan = __boundary(plan);
542
- if (__requireBoolean(!__requireBoolean(__isObject(values)))) {
543
- throw "UiClientValuesMustBeMap";
544
- }
545
- for (const [name, value] of __entries(values)) {
546
- validateName(name);
547
- let target = findControl(controls, name);
548
- if (__requireBoolean(__requireBoolean(target.control.inherited === true) && __requireBoolean(target.control.writable !== true))) {
549
- throw "UiInheritedValueReadOnly";
550
- }
551
- let children = __normalize(target.controls);
552
- if (__requireBoolean(__isArray(children))) {
553
- if (__requireBoolean(!__requireBoolean(__isObject(value)))) {
554
- throw "UiClientContainerValuesMustBeMap";
555
- }
556
- planValues(children, value, plan);
557
- } else {
558
- plan[__normalize(plan.length)] = { target: __normalize(target.control), value: value };
559
- }
560
- }
561
- return null;
562
- return null;
563
- }
564
-
565
- function planCommand(controls, command) {
566
- __requireArity(arguments.length, [0, 1], "planCommand");
567
- controls = __boundary(controls);
568
- command = __boundary(command);
569
- if (__requireBoolean(!__requireBoolean(__isObject(command)))) {
570
- throw "UiClientCommandMustBeMap";
571
- }
572
- if (__requireBoolean(__normalize(command.type) === "toast")) {
573
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(command.text)))) || __requireBoolean(!__requireBoolean(__isString(__normalize(command.level)))))) {
574
- throw "UiClientToastRequiresTextAndLevel";
575
- }
576
- return { command: command, target: null };
577
- }
578
- let projected = resolveTarget(controls, __normalize(command.target));
579
- let target = __normalize(projected.control);
580
- if (__requireBoolean(__requireBoolean(__normalize(target.inherited) === true) && __requireBoolean(!__requireBoolean(__requireBoolean(__requireBoolean(__normalize(command.type) === "setProperty") && __requireBoolean(__requireBoolean(__normalize(command.name) === "savedValue") || __requireBoolean(__normalize(command.name) === "error"))) && __requireBoolean(__normalize(target.writable) === true))))) {
581
- throw "UiInheritedCommandNotAllowed";
582
- }
583
- if (__requireBoolean(__normalize(command.type) === "focus")) {
584
- return { command: command, target: target };
585
- }
586
- let property = __normalize(command.name);
587
- if (__requireBoolean(__normalize(command.type) === "setEnabled")) {
588
- property = "enabled";
589
- }
590
- if (__requireBoolean(__normalize(command.type) === "setVisible")) {
591
- property = "visible";
592
- }
593
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(command.type) !== "setProperty") && __requireBoolean(__normalize(command.type) !== "setEnabled")) && __requireBoolean(__normalize(command.type) !== "setVisible"))) {
594
- throw "UiClientUnknownCommand";
595
- }
596
- validateProperty(property, __normalize(command.value));
597
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(property === "classes") || __requireBoolean(property === "style")) || __requireBoolean(property === "savedValue")) || __requireBoolean(property === "error")) && __requireBoolean(__normalize(target.applyProperty) === null))) {
598
- throw "UiClientPresentationAdapterNotConfigured";
599
- }
600
- return { command: command, target: target, property: property };
601
- return null;
602
- }
603
-
604
- export function applyResponse(controls, response, formId, seqno, effects) {
605
- __requireArity(arguments.length, [0, 1, 2, 3, 4], "applyResponse");
606
- controls = __boundary(controls);
607
- response = __boundary(response);
608
- formId = __boundary(formId);
609
- seqno = __boundary(seqno);
610
- effects = __boundary(effects);
611
- return applyOwnedResponse(controls, response, formId, seqno, effects, controls);
612
- return null;
613
- }
614
-
615
- export function applyOwnedResponse(controls, response, formId, seqno, effects, ownerControls) {
616
- __requireArity(arguments.length, [0, 1, 2, 3, 4, 5], "applyOwnedResponse");
617
- controls = __boundary(controls);
618
- response = __boundary(response);
619
- formId = __boundary(formId);
620
- seqno = __boundary(seqno);
621
- effects = __boundary(effects);
622
- ownerControls = __boundary(ownerControls);
623
- requireProtocol(response);
624
- if (__requireBoolean(__requireBoolean(__normalize(response.formId) !== formId) || __requireBoolean(__normalize(response.seqno) !== seqno))) {
625
- throw "UiClientResponseDoesNotMatchRequest";
626
- }
627
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(__normalize(response.ui)))) || __requireBoolean(!__requireBoolean(__isObject(response.ui.replace)))) || __requireBoolean(!__requireBoolean(__isArray(response.ui.remove))))) {
628
- throw "UiClientInvalidStructurePatch";
629
- }
630
- let prepared = [];
631
- let journal = [];
632
- let structure = null;
633
- try {
634
- structure = prepareResponse(controls, response, effects, ownerControls, prepared);
635
- commitStructure(__normalize(structure.operations), effects, journal);
636
- for (const change of __normalize(structure.values)) {
637
- journal[__normalize(journal.length)] = { type: "state", target: __normalize(change.target), snapshot: captureState(__normalize(change.target)) };
638
- __normalize(change.target.setValue(__normalize(change.value)));
639
- }
640
- } catch (error) {
641
- try {
642
- rollback(journal, effects);
643
- } finally {
644
- releasePrepared(prepared, effects);
645
- }
646
- throw error;
647
- }
648
- for (const operation of __normalize(structure.operations)) {
649
- releasePrepared([__normalize(operation.old)], effects);
650
- }
651
- for (const change of __normalize(structure.commands)) {
652
- let command = __normalize(change.command);
653
- if (__normalize(command.type) === "toast") {
654
- __normalize(effects.toast(__normalize(command.level), __normalize(command.text)));
655
- } else if (__normalize(command.type) === "focus") {
656
- __normalize(effects.focus(__normalize(change.target)));
657
- } else {
658
- applyStateCommand(change);
659
- }
660
- }
661
- return null;
662
- return null;
663
- }
664
-
665
- function releasePrepared(controls, effects) {
666
- __requireArity(arguments.length, [0, 1], "releasePrepared");
667
- controls = __boundary(controls);
668
- effects = __boundary(effects);
669
- if (__requireBoolean(__normalize(effects.release) !== null)) {
670
- for (const control of controls) {
671
- __normalize(effects.release(control));
672
- }
673
- }
674
- return null;
675
- return null;
676
- }
677
-
678
- function prepareResponse(controls, response, effects, ownerControls, prepared) {
679
- __requireArity(arguments.length, [0, 1, 2, 3, 4], "prepareResponse");
680
- controls = __boundary(controls);
681
- response = __boundary(response);
682
- effects = __boundary(effects);
683
- ownerControls = __boundary(ownerControls);
684
- prepared = __boundary(prepared);
685
- let structure = planStructure(controls, __normalize(response.ui), effects, ownerControls, prepared);
686
- let values = [];
687
- planValues(__normalize(structure.tree), __normalize(response.vals), values);
688
- if (__requireBoolean(!__requireBoolean(__isArray(__normalize(response.cmds))))) {
689
- throw "UiClientCommandsMustBeArray";
690
- }
691
- let commands = [];
692
- for (const command of __normalize(response.cmds)) {
693
- if (__requireBoolean(__requireBoolean(__normalize(command.type) === "focus") && __requireBoolean(__normalize(effects.focus) === null))) {
694
- throw "UiClientFocusEffectNotConfigured";
695
- }
696
- if (__requireBoolean(__requireBoolean(__normalize(command.type) === "toast") && __requireBoolean(__normalize(effects.toast) === null))) {
697
- throw "UiClientToastEffectNotConfigured";
698
- }
699
- commands[__normalize(commands.length)] = planCommand(__normalize(structure.tree), command);
700
- }
701
- structure.values = values;
702
- structure.commands = commands;
703
- return structure;
704
- return null;
705
- }
706
- //# sourceMappingURL=protocol.mjs.map