@lango-project/lango-client 0.0.0-stage → 0.2.1
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.
- package/LICENSE +200 -0
- package/NOTICE +2 -0
- package/README.md +929 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/runtime.mjs +607 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/application.mjs +429 -0
- package/dist/application.mjs.map +1 -0
- package/dist/coordinator.mjs +91 -0
- package/dist/coordinator.mjs.map +1 -0
- package/dist/demo.mjs +110 -0
- package/dist/demo.mjs.map +1 -0
- package/dist/demo_controls.mjs +59 -0
- package/dist/demo_controls.mjs.map +1 -0
- package/dist/errors.mjs +201 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/form_state.mjs +266 -0
- package/dist/form_state.mjs.map +1 -0
- package/dist/heartbeat.mjs +330 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/inheritance.mjs +240 -0
- package/dist/inheritance.mjs.map +1 -0
- package/dist/input_values.mjs +65 -0
- package/dist/input_values.mjs.map +1 -0
- package/dist/library.mjs +824 -0
- package/dist/library.mjs.map +1 -0
- package/dist/navigation.mjs +466 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/node/.lango/bignumber.mjs +3119 -0
- package/dist/node/.lango/runtime.mjs +609 -0
- package/dist/node/.lango/xmldom/conventions.js +429 -0
- package/dist/node/.lango/xmldom/dom-parser.js +591 -0
- package/dist/node/.lango/xmldom/dom.js +3759 -0
- package/dist/node/.lango/xmldom/entities.js +2171 -0
- package/dist/node/.lango/xmldom/errors.js +205 -0
- package/dist/node/.lango/xmldom/grammar.js +559 -0
- package/dist/node/.lango/xmldom/index.js +41 -0
- package/dist/node/.lango/xmldom/package.json +1 -0
- package/dist/node/.lango/xmldom/sax.js +983 -0
- package/dist/node/.lango/xmldom.LICENSE.md +8 -0
- package/dist/node/browser_host.mjs +351 -0
- package/dist/node/browser_host.mjs.map +1 -0
- package/dist/node/create_app.mjs +118 -0
- package/dist/node/create_app.mjs.map +1 -0
- package/dist/presentation.mjs +89 -0
- package/dist/presentation.mjs.map +1 -0
- package/dist/protocol.mjs +706 -0
- package/dist/protocol.mjs.map +1 -0
- package/dist/session.mjs +471 -0
- package/dist/session.mjs.map +1 -0
- package/dist/tokens.mjs +298 -0
- package/dist/tokens.mjs.map +1 -0
- package/examples/contacts.lango +293 -0
- package/examples/contacts_flow.lango +174 -0
- package/examples/contacts_store.lango +109 -0
- package/examples/contacts_store_test.lango +65 -0
- package/examples/demo.css +87 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +32 -0
- package/examples/pages.lango +174 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +68 -4
- package/src/application.lango +327 -0
- package/src/browser_host.lango +276 -0
- package/src/coordinator.lango +57 -0
- package/src/demo.lango +110 -0
- package/src/demo_controls.lango +53 -0
- package/src/errors.lango +149 -0
- package/src/errors_test.lango +157 -0
- package/src/form_state.lango +168 -0
- package/src/heartbeat.lango +230 -0
- package/src/heartbeat_test.lango +479 -0
- package/src/inheritance.lango +167 -0
- package/src/input_values.lango +37 -0
- package/src/library.lango +599 -0
- package/src/logout_test.lango +564 -0
- package/src/navigation.lango +309 -0
- package/src/navigation_test.lango +556 -0
- package/src/presentation.lango +55 -0
- package/src/protocol.lango +787 -0
- package/src/renderer_test.lango +2047 -0
- package/src/session.lango +343 -0
- package/src/session_test.lango +455 -0
- package/src/tabs_test.lango +216 -0
- package/src/tokens.lango +215 -0
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +9 -0
- package/template/README.md +44 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +10 -0
- package/template/public/index.html +24 -0
- package/template/src/client.lango +78 -0
- package/template/src/pages.lango +55 -0
- package/template/src/server.lango +24 -0
- package/template/src/worker.lango +77 -0
- package/template/test/app.lango +9 -0
- package/tools/browser_runner.lango +32 -0
- package/tools/browser_test.lango +343 -0
- package/tools/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
|
@@ -0,0 +1,706 @@
|
|
|
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
|