@lango-project/lango-client 0.2.1 → 0.4.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 +1 -0
- package/NOTICE +5 -1
- package/README.md +603 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +120 -20
- package/cli/.lango/vendor/i18next.LICENSE +21 -0
- package/cli/.lango/vendor/i18next.mjs +2434 -0
- package/cli/create.mjs +62 -0
- package/cli/create.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +120 -20
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/accordion.mjs +277 -0
- package/dist/accordion.mjs.map +1 -0
- package/dist/activities.mjs +185 -0
- package/dist/activities.mjs.map +1 -0
- package/dist/app.mjs +671 -0
- package/dist/app.mjs.map +1 -0
- package/dist/boot.mjs +24 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/bootstrap-LICENSE +21 -0
- package/dist/bootstrap.min.css +6 -0
- package/dist/bootstrap.min.css.map +1 -0
- package/dist/button.mjs +77 -0
- package/dist/button.mjs.map +1 -0
- package/dist/chip.mjs +134 -0
- package/dist/chip.mjs.map +1 -0
- package/dist/client.css +102 -0
- package/dist/collections.mjs +77 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/combo_box.mjs +408 -0
- package/dist/combo_box.mjs.map +1 -0
- package/dist/content.mjs +123 -0
- package/dist/content.mjs.map +1 -0
- package/dist/control.mjs +141 -0
- package/dist/control.mjs.map +1 -0
- package/dist/date_input.mjs +242 -0
- package/dist/date_input.mjs.map +1 -0
- package/dist/dimensions.mjs +102 -0
- package/dist/dimensions.mjs.map +1 -0
- package/dist/error_reporter.mjs +136 -0
- package/dist/error_reporter.mjs.map +1 -0
- package/dist/fields.mjs +454 -0
- package/dist/fields.mjs.map +1 -0
- package/dist/file_input.mjs +227 -0
- package/dist/file_input.mjs.map +1 -0
- package/dist/form.mjs +272 -0
- package/dist/form.mjs.map +1 -0
- package/dist/heartbeat.mjs +167 -254
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +18 -0
- package/dist/indicators.mjs +127 -0
- package/dist/indicators.mjs.map +1 -0
- package/dist/input_changes.mjs +58 -0
- package/dist/input_changes.mjs.map +1 -0
- package/dist/input_group.mjs +38 -0
- package/dist/input_group.mjs.map +1 -0
- package/dist/layouts.mjs +195 -0
- package/dist/layouts.mjs.map +1 -0
- package/dist/library.mjs +130 -807
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll.mjs +254 -0
- package/dist/longpoll.mjs.map +1 -0
- package/dist/main.mjs +147 -0
- package/dist/main.mjs.map +1 -0
- package/dist/markdown.mjs +61 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/menus.mjs +468 -0
- package/dist/menus.mjs.map +1 -0
- package/dist/navigation.mjs +260 -410
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +181 -0
- package/dist/numeric_input.mjs.map +1 -0
- package/dist/otp_input.mjs +113 -0
- package/dist/otp_input.mjs.map +1 -0
- package/dist/presentations.mjs +852 -0
- package/dist/presentations.mjs.map +1 -0
- package/dist/renderer.mjs +295 -0
- package/dist/renderer.mjs.map +1 -0
- package/dist/rich_content.mjs +99 -0
- package/dist/rich_content.mjs.map +1 -0
- package/dist/table_scope.mjs +166 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +1052 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tabs.mjs +205 -0
- package/dist/tabs.mjs.map +1 -0
- package/dist/templates.mjs +46 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/vendor/DOMPurify-LICENSE +202 -0
- package/dist/vendor/dompurify.mjs +2454 -0
- package/dist/vendor/flatpickr-LICENSE.md +21 -0
- package/dist/vendor/flatpickr.min.css +13 -0
- package/dist/vendor/flatpickr.mjs +2340 -0
- package/dist/vendor/flatpickr.mjs.map +7 -0
- package/dist/vendor/marked-LICENSE.md +44 -0
- package/dist/vendor/marked.esm.js.map +7 -0
- package/dist/vendor/marked.mjs +85 -0
- package/dist/vendor/purify.es.mjs.map +1 -0
- package/dist/widgets.mjs +197 -0
- package/dist/widgets.mjs.map +1 -0
- package/docs/implementation.md +93 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +540 -0
- package/src/boot.lango +12 -0
- package/src/button.lango +49 -0
- package/src/chip.lango +94 -0
- package/src/collections.lango +46 -0
- package/src/combo_box.lango +298 -0
- package/src/content.lango +75 -0
- package/src/control.lango +103 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/dimensions.lango +65 -0
- package/src/error_reporter.lango +95 -0
- package/src/fields.lango +327 -0
- package/src/file_input.lango +175 -0
- package/src/form.lango +195 -0
- package/src/heartbeat.lango +136 -199
- package/src/indicators.lango +94 -0
- package/src/input_changes.lango +33 -0
- package/src/input_group.lango +22 -0
- package/src/layouts.lango +137 -0
- package/src/library.lango +194 -599
- package/src/longpoll.lango +187 -0
- package/src/main.lango +118 -0
- package/src/markdown.lango +48 -0
- package/src/menus.lango +336 -0
- package/src/navigation.lango +209 -299
- package/src/numeric_input.lango +131 -0
- package/src/otp_input.lango +83 -0
- package/src/presentations.lango +617 -0
- package/src/renderer.lango +296 -0
- package/src/rich_content.lango +66 -0
- package/src/table_scope.lango +119 -0
- package/src/tables.lango +786 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +102 -0
- package/web/index.html +18 -0
- package/dist/application.mjs +0 -429
- package/dist/application.mjs.map +0 -1
- package/dist/coordinator.mjs +0 -91
- package/dist/coordinator.mjs.map +0 -1
- package/dist/demo.mjs +0 -110
- package/dist/demo.mjs.map +0 -1
- package/dist/demo_controls.mjs +0 -59
- package/dist/demo_controls.mjs.map +0 -1
- package/dist/errors.mjs +0 -201
- package/dist/errors.mjs.map +0 -1
- package/dist/form_state.mjs +0 -266
- package/dist/form_state.mjs.map +0 -1
- package/dist/inheritance.mjs +0 -240
- package/dist/inheritance.mjs.map +0 -1
- package/dist/input_values.mjs +0 -65
- package/dist/input_values.mjs.map +0 -1
- package/dist/node/.lango/xmldom/conventions.js +0 -429
- package/dist/node/.lango/xmldom/dom-parser.js +0 -591
- package/dist/node/.lango/xmldom/dom.js +0 -3759
- package/dist/node/.lango/xmldom/entities.js +0 -2171
- package/dist/node/.lango/xmldom/errors.js +0 -205
- package/dist/node/.lango/xmldom/grammar.js +0 -559
- package/dist/node/.lango/xmldom/index.js +0 -41
- package/dist/node/.lango/xmldom/package.json +0 -1
- package/dist/node/.lango/xmldom/sax.js +0 -983
- package/dist/node/.lango/xmldom.LICENSE.md +0 -8
- package/dist/node/browser_host.mjs +0 -351
- package/dist/node/browser_host.mjs.map +0 -1
- package/dist/node/create_app.mjs +0 -118
- package/dist/node/create_app.mjs.map +0 -1
- package/dist/presentation.mjs +0 -89
- package/dist/presentation.mjs.map +0 -1
- package/dist/protocol.mjs +0 -706
- package/dist/protocol.mjs.map +0 -1
- package/dist/session.mjs +0 -471
- package/dist/session.mjs.map +0 -1
- package/dist/tokens.mjs +0 -298
- package/dist/tokens.mjs.map +0 -1
- package/examples/contacts.lango +0 -293
- package/examples/contacts_flow.lango +0 -174
- package/examples/contacts_store.lango +0 -109
- package/examples/contacts_store_test.lango +0 -65
- package/examples/demo.css +0 -87
- package/examples/demo_test.lango +0 -356
- package/examples/index.html +0 -32
- package/examples/pages.lango +0 -174
- package/examples/server.lango +0 -189
- package/examples/worker.lango +0 -142
- package/src/application.lango +0 -327
- package/src/browser_host.lango +0 -276
- package/src/coordinator.lango +0 -57
- package/src/demo.lango +0 -110
- package/src/demo_controls.lango +0 -53
- package/src/errors.lango +0 -149
- package/src/errors_test.lango +0 -157
- package/src/form_state.lango +0 -168
- package/src/heartbeat_test.lango +0 -479
- package/src/inheritance.lango +0 -167
- package/src/input_values.lango +0 -37
- package/src/logout_test.lango +0 -564
- package/src/navigation_test.lango +0 -556
- package/src/presentation.lango +0 -55
- package/src/protocol.lango +0 -787
- package/src/renderer_test.lango +0 -2047
- package/src/session.lango +0 -343
- package/src/session_test.lango +0 -455
- package/src/tabs_test.lango +0 -216
- package/src/tokens.lango +0 -215
- package/template/.vscode/extensions.json +0 -3
- package/template/.vscode/settings.json +0 -9
- package/template/README.md +0 -44
- package/template/gitignore +0 -4
- package/template/package.json +0 -22
- package/template/public/app.css +0 -10
- package/template/public/index.html +0 -24
- package/template/src/client.lango +0 -78
- package/template/src/pages.lango +0 -55
- package/template/src/server.lango +0 -24
- package/template/src/worker.lango +0 -77
- package/template/test/app.lango +0 -9
- package/tools/browser_runner.lango +0 -32
- package/tools/browser_test.lango +0 -343
- package/tools/create_app.lango +0 -88
- package/tools/create_app_test.lango +0 -43
- package/tools/starter_test.lango +0 -227
- /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
- /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
- /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
- /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
- /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
- /package/{dist → cli}/.lango/xmldom/index.js +0 -0
- /package/{dist → cli}/.lango/xmldom/package.json +0 -0
- /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
- /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
package/src/protocol.lango
DELETED
|
@@ -1,787 +0,0 @@
|
|
|
1
|
-
export collectValues(controls)
|
|
2
|
-
export applyResponse(controls, response, formId, seqno, effects)
|
|
3
|
-
export applyOwnedResponse(controls, response, formId, seqno, effects, ownerControls)
|
|
4
|
-
export protocolVersion()
|
|
5
|
-
|
|
6
|
-
protocolVersion()
|
|
7
|
-
return 1
|
|
8
|
-
|
|
9
|
-
requireProtocol(response)
|
|
10
|
-
if !is_object(response) or is_array(response)
|
|
11
|
-
throw "UiClientResponseMustBeMap"
|
|
12
|
-
if "protocol" in response
|
|
13
|
-
if response.protocol != protocolVersion()
|
|
14
|
-
throw "UiProtocolUnsupported"
|
|
15
|
-
|
|
16
|
-
import "./presentation"
|
|
17
|
-
validateProperty(name, value)
|
|
18
|
-
|
|
19
|
-
projectControls(controls, ownerControls = null)
|
|
20
|
-
owner = controls
|
|
21
|
-
if ownerControls != null
|
|
22
|
-
owner = ownerControls
|
|
23
|
-
projected = []
|
|
24
|
-
names = {
|
|
25
|
-
}
|
|
26
|
-
for controls as control
|
|
27
|
-
if control.name != null and control.name != ""
|
|
28
|
-
if not is_string(control.name)
|
|
29
|
-
throw "UiClientControlNameMustBeString"
|
|
30
|
-
validateName(control.name)
|
|
31
|
-
if control.name in names
|
|
32
|
-
throw "UiDuplicateControlName: ${control.name}"
|
|
33
|
-
names[control.name] = true
|
|
34
|
-
children = null
|
|
35
|
-
if is_array(control.controls)
|
|
36
|
-
children = projectControls(control.controls)
|
|
37
|
-
projected[projected.length] = {
|
|
38
|
-
name: control.name
|
|
39
|
-
control: control
|
|
40
|
-
controls: children
|
|
41
|
-
owner: owner
|
|
42
|
-
}
|
|
43
|
-
return projected
|
|
44
|
-
|
|
45
|
-
targetPath(target)
|
|
46
|
-
if is_string(target)
|
|
47
|
-
return [target]
|
|
48
|
-
if !is_array(target) or target.length == 0
|
|
49
|
-
throw "UiClientTargetMustBePathArray"
|
|
50
|
-
return target
|
|
51
|
-
|
|
52
|
-
checkConflict(paths, path)
|
|
53
|
-
for paths as existing
|
|
54
|
-
common = true
|
|
55
|
-
for path as index: name
|
|
56
|
-
if index < existing.length
|
|
57
|
-
if existing[index] != name
|
|
58
|
-
common = false
|
|
59
|
-
if common
|
|
60
|
-
throw "UiClientOverlappingStructurePatches"
|
|
61
|
-
paths[paths.length] = path
|
|
62
|
-
return null
|
|
63
|
-
|
|
64
|
-
findProjected(controls, path, optional)
|
|
65
|
-
current = controls
|
|
66
|
-
node = null
|
|
67
|
-
for path as index: name
|
|
68
|
-
if !is_string(name) or name == ""
|
|
69
|
-
throw "UiClientTargetMustContainNames"
|
|
70
|
-
validateName(name)
|
|
71
|
-
node = null
|
|
72
|
-
for current as candidate
|
|
73
|
-
if candidate.name == name
|
|
74
|
-
node = candidate
|
|
75
|
-
if node == null
|
|
76
|
-
if optional
|
|
77
|
-
return null
|
|
78
|
-
throw "UiClientTargetNotFound: ${name}"
|
|
79
|
-
if index < path.length - 1
|
|
80
|
-
current = node.controls
|
|
81
|
-
if not is_array(current)
|
|
82
|
-
throw "UiClientTargetIsNotContainer"
|
|
83
|
-
return node
|
|
84
|
-
|
|
85
|
-
planReplacements(tree, replacements, parentPath, paths, operations, effects, preparedControls)
|
|
86
|
-
for replacements as name: definition
|
|
87
|
-
validateName(name)
|
|
88
|
-
path = parentPath.slice()
|
|
89
|
-
path[path.length] = name
|
|
90
|
-
if not is_object(definition)
|
|
91
|
-
throw "UiClientReplacementMustBeMap"
|
|
92
|
-
node = null
|
|
93
|
-
if is_string(definition.type)
|
|
94
|
-
checkConflict(paths, path)
|
|
95
|
-
node = findProjected(tree, path, false)
|
|
96
|
-
if node.control.inherited == true
|
|
97
|
-
throw "UiInheritedStructureNotAllowed"
|
|
98
|
-
if effects.create == null or effects.replace == null
|
|
99
|
-
throw "UiClientStructureAdapterNotConfigured"
|
|
100
|
-
prepared = {
|
|
101
|
-
}
|
|
102
|
-
for definition as key: value
|
|
103
|
-
prepared[key] = value
|
|
104
|
-
if prepared.name == null
|
|
105
|
-
prepared.name = name
|
|
106
|
-
replacement = effects.create(prepared)
|
|
107
|
-
preparedControls.add(replacement)
|
|
108
|
-
if replacement.name != name
|
|
109
|
-
throw "UiClientReplacementMustPreserveName"
|
|
110
|
-
children = null
|
|
111
|
-
if is_array(replacement.controls)
|
|
112
|
-
children = projectControls(replacement.controls)
|
|
113
|
-
operations[operations.length] = {
|
|
114
|
-
type: "replace"
|
|
115
|
-
old: node.control
|
|
116
|
-
new: replacement
|
|
117
|
-
owner: node.owner
|
|
118
|
-
}
|
|
119
|
-
node.control = replacement
|
|
120
|
-
node.controls = children
|
|
121
|
-
else
|
|
122
|
-
node = findProjected(tree, path, false)
|
|
123
|
-
if node.control.inherited == true
|
|
124
|
-
throw "UiInheritedStructureNotAllowed"
|
|
125
|
-
planReplacements(tree, definition, path, paths, operations, effects, preparedControls)
|
|
126
|
-
return null
|
|
127
|
-
|
|
128
|
-
test "nested replacement maps preserve ordinary container structure"
|
|
129
|
-
address = new Field("address", null)
|
|
130
|
-
address.controls = [new Field("city", "old")]
|
|
131
|
-
effects = new TestRenderer()
|
|
132
|
-
applyResponse([address], {
|
|
133
|
-
formId: "profile"
|
|
134
|
-
seqno: 1
|
|
135
|
-
ui: {
|
|
136
|
-
replace: {
|
|
137
|
-
address: {
|
|
138
|
-
city: {
|
|
139
|
-
type: "Value"
|
|
140
|
-
value: "new"
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
remove: []
|
|
145
|
-
}
|
|
146
|
-
vals: {
|
|
147
|
-
}
|
|
148
|
-
cmds: []
|
|
149
|
-
}, "profile", 1, effects)
|
|
150
|
-
assert address.controls[0].getValue() == "new"
|
|
151
|
-
|
|
152
|
-
planStructure(controls, patch, effects, ownerControls, preparedControls)
|
|
153
|
-
tree = projectControls(controls, ownerControls)
|
|
154
|
-
paths = []
|
|
155
|
-
operations = []
|
|
156
|
-
planReplacements(tree, patch.replace, [], paths, operations, effects, preparedControls)
|
|
157
|
-
for patch.remove as target
|
|
158
|
-
path = targetPath(target)
|
|
159
|
-
checkConflict(paths, path)
|
|
160
|
-
node = findProjected(tree, path, true)
|
|
161
|
-
if node != null
|
|
162
|
-
if node.control.inherited == true
|
|
163
|
-
throw "UiInheritedStructureNotAllowed"
|
|
164
|
-
if effects.remove == null
|
|
165
|
-
throw "UiClientStructureAdapterNotConfigured"
|
|
166
|
-
operations[operations.length] = {
|
|
167
|
-
type: "remove"
|
|
168
|
-
old: node.control
|
|
169
|
-
owner: node.owner
|
|
170
|
-
}
|
|
171
|
-
node.name = null
|
|
172
|
-
return {
|
|
173
|
-
tree: tree
|
|
174
|
-
operations: operations
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
commitStructure(operations, effects, journal)
|
|
178
|
-
for operations as operation
|
|
179
|
-
owner = operation.owner
|
|
180
|
-
index = owner.indexOf(operation.old)
|
|
181
|
-
if effects.capture == null or effects.restore == null
|
|
182
|
-
throw "UiClientStructureRollbackNotConfigured"
|
|
183
|
-
journal[journal.length] = {
|
|
184
|
-
type: "structure"
|
|
185
|
-
operation: operation
|
|
186
|
-
ownerBefore: owner.slice()
|
|
187
|
-
snapshot: effects.capture(operation.old)
|
|
188
|
-
}
|
|
189
|
-
if operation.type == "replace"
|
|
190
|
-
effects.replace(operation.old, operation.new)
|
|
191
|
-
owner.splice(index, 1, operation.new)
|
|
192
|
-
else
|
|
193
|
-
effects.remove(operation.old)
|
|
194
|
-
owner.splice(index, 1)
|
|
195
|
-
return null
|
|
196
|
-
|
|
197
|
-
captureState(target)
|
|
198
|
-
if target.snapshotState != null
|
|
199
|
-
if target.restoreState == null
|
|
200
|
-
throw "UiClientStateRollbackNotConfigured"
|
|
201
|
-
return {
|
|
202
|
-
custom: true
|
|
203
|
-
value: target.snapshotState()
|
|
204
|
-
}
|
|
205
|
-
if target.applyProperty != null
|
|
206
|
-
throw "UiClientStateRollbackNotConfigured"
|
|
207
|
-
return {
|
|
208
|
-
custom: false
|
|
209
|
-
value: target.getValue()
|
|
210
|
-
enabled: target.enabled
|
|
211
|
-
visible: target.visible
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
restoreState(target, snapshot)
|
|
215
|
-
if snapshot.custom
|
|
216
|
-
target.restoreState(snapshot.value)
|
|
217
|
-
else
|
|
218
|
-
target.setValue(snapshot.value)
|
|
219
|
-
target.enabled = snapshot.enabled
|
|
220
|
-
target.visible = snapshot.visible
|
|
221
|
-
return null
|
|
222
|
-
|
|
223
|
-
rollback(journal, effects)
|
|
224
|
-
entries = journal.slice()
|
|
225
|
-
entries.reverse()
|
|
226
|
-
failures = 0
|
|
227
|
-
for entries as entry
|
|
228
|
-
try
|
|
229
|
-
if entry.type == "state"
|
|
230
|
-
restoreState(entry.target, entry.snapshot)
|
|
231
|
-
else
|
|
232
|
-
operation = entry.operation
|
|
233
|
-
owner = operation.owner
|
|
234
|
-
owner.splice(0, owner.length)
|
|
235
|
-
for entry.ownerBefore as control
|
|
236
|
-
owner.add(control)
|
|
237
|
-
effects.restore(entry.snapshot, operation)
|
|
238
|
-
catch error
|
|
239
|
-
failures++
|
|
240
|
-
if failures > 0
|
|
241
|
-
throw "UiClientRollbackFailed"
|
|
242
|
-
return null
|
|
243
|
-
|
|
244
|
-
applyStateCommand(change)
|
|
245
|
-
target = change.target
|
|
246
|
-
snapshot = captureState(target)
|
|
247
|
-
try
|
|
248
|
-
if target.applyProperty != null
|
|
249
|
-
target.applyProperty(change.property, change.command.value)
|
|
250
|
-
else
|
|
251
|
-
target[change.property] = change.command.value
|
|
252
|
-
catch error
|
|
253
|
-
try
|
|
254
|
-
restoreState(target, snapshot)
|
|
255
|
-
catch restoreError
|
|
256
|
-
throw "UiClientRollbackFailed"
|
|
257
|
-
throw error
|
|
258
|
-
return null
|
|
259
|
-
|
|
260
|
-
validateName(name)
|
|
261
|
-
if name == "__proto__" or name == "constructor" or name == "prototype"
|
|
262
|
-
throw "UiReservedControlName: ${name}"
|
|
263
|
-
return null
|
|
264
|
-
|
|
265
|
-
collectValues(controls)
|
|
266
|
-
values = {
|
|
267
|
-
}
|
|
268
|
-
for controls as control
|
|
269
|
-
name = control.name
|
|
270
|
-
if name != null and name != ""
|
|
271
|
-
validateName(name)
|
|
272
|
-
if name in values
|
|
273
|
-
throw "UiDuplicateControlName: ${name}"
|
|
274
|
-
values[name] = control.getValue()
|
|
275
|
-
return values
|
|
276
|
-
|
|
277
|
-
findControl(controls, name)
|
|
278
|
-
for controls as control
|
|
279
|
-
if control.name == name
|
|
280
|
-
return control
|
|
281
|
-
throw "UiClientTargetNotFound: ${name}"
|
|
282
|
-
|
|
283
|
-
resolveTarget(controls, path)
|
|
284
|
-
targetPath = path
|
|
285
|
-
if is_string(path)
|
|
286
|
-
targetPath = [path]
|
|
287
|
-
if !is_array(targetPath) or targetPath.length == 0
|
|
288
|
-
throw "UiClientTargetMustBePathArray"
|
|
289
|
-
current = controls
|
|
290
|
-
target = null
|
|
291
|
-
for targetPath as index: name
|
|
292
|
-
if not is_string(name)
|
|
293
|
-
throw "UiClientTargetMustContainNames"
|
|
294
|
-
validateName(name)
|
|
295
|
-
target = findControl(current, name)
|
|
296
|
-
if index < targetPath.length - 1
|
|
297
|
-
current = target.controls
|
|
298
|
-
if not is_array(current)
|
|
299
|
-
throw "UiClientTargetIsNotContainer"
|
|
300
|
-
return target
|
|
301
|
-
|
|
302
|
-
planValues(controls, values, plan)
|
|
303
|
-
if not is_object(values)
|
|
304
|
-
throw "UiClientValuesMustBeMap"
|
|
305
|
-
for values as name: value
|
|
306
|
-
validateName(name)
|
|
307
|
-
target = findControl(controls, name)
|
|
308
|
-
if target.control.inherited == true and target.control.writable != true
|
|
309
|
-
throw "UiInheritedValueReadOnly"
|
|
310
|
-
children = target.controls
|
|
311
|
-
if is_array(children)
|
|
312
|
-
if not is_object(value)
|
|
313
|
-
throw "UiClientContainerValuesMustBeMap"
|
|
314
|
-
planValues(children, value, plan)
|
|
315
|
-
else
|
|
316
|
-
plan[plan.length] = {
|
|
317
|
-
target: target.control
|
|
318
|
-
value: value
|
|
319
|
-
}
|
|
320
|
-
return null
|
|
321
|
-
|
|
322
|
-
planCommand(controls, command)
|
|
323
|
-
if not is_object(command)
|
|
324
|
-
throw "UiClientCommandMustBeMap"
|
|
325
|
-
if command.type == "toast"
|
|
326
|
-
if !is_string(command.text) or !is_string(command.level)
|
|
327
|
-
throw "UiClientToastRequiresTextAndLevel"
|
|
328
|
-
return {
|
|
329
|
-
command: command
|
|
330
|
-
target: null
|
|
331
|
-
}
|
|
332
|
-
projected = resolveTarget(controls, command.target)
|
|
333
|
-
target = projected.control
|
|
334
|
-
if target.inherited == true and !(command.type == "setProperty" and (command.name == "savedValue" or command.name == "error") and target.writable == true)
|
|
335
|
-
throw "UiInheritedCommandNotAllowed"
|
|
336
|
-
if command.type == "focus"
|
|
337
|
-
return {
|
|
338
|
-
command: command
|
|
339
|
-
target: target
|
|
340
|
-
}
|
|
341
|
-
property = command.name
|
|
342
|
-
if command.type == "setEnabled"
|
|
343
|
-
property = "enabled"
|
|
344
|
-
if command.type == "setVisible"
|
|
345
|
-
property = "visible"
|
|
346
|
-
if command.type != "setProperty" and command.type != "setEnabled" and command.type != "setVisible"
|
|
347
|
-
throw "UiClientUnknownCommand"
|
|
348
|
-
validateProperty(property, command.value)
|
|
349
|
-
if (property == "classes" or property == "style" or property == "savedValue" or property == "error") and target.applyProperty == null
|
|
350
|
-
throw "UiClientPresentationAdapterNotConfigured"
|
|
351
|
-
return {
|
|
352
|
-
command: command
|
|
353
|
-
target: target
|
|
354
|
-
property: property
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
applyResponse(controls, response, formId, seqno, effects)
|
|
358
|
-
return applyOwnedResponse(controls, response, formId, seqno, effects, controls)
|
|
359
|
-
|
|
360
|
-
applyOwnedResponse(controls, response, formId, seqno, effects, ownerControls)
|
|
361
|
-
requireProtocol(response)
|
|
362
|
-
if response.formId != formId or response.seqno != seqno
|
|
363
|
-
throw "UiClientResponseDoesNotMatchRequest"
|
|
364
|
-
if !is_object(response.ui) or !is_object(response.ui.replace) or !is_array(response.ui.remove)
|
|
365
|
-
throw "UiClientInvalidStructurePatch"
|
|
366
|
-
prepared = []
|
|
367
|
-
journal = []
|
|
368
|
-
structure = null
|
|
369
|
-
try
|
|
370
|
-
structure = prepareResponse(controls, response, effects, ownerControls, prepared)
|
|
371
|
-
commitStructure(structure.operations, effects, journal)
|
|
372
|
-
for structure.values as change
|
|
373
|
-
journal[journal.length] = {
|
|
374
|
-
type: "state"
|
|
375
|
-
target: change.target
|
|
376
|
-
snapshot: captureState(change.target)
|
|
377
|
-
}
|
|
378
|
-
change.target.setValue(change.value)
|
|
379
|
-
catch error
|
|
380
|
-
try
|
|
381
|
-
rollback(journal, effects)
|
|
382
|
-
finally
|
|
383
|
-
releasePrepared(prepared, effects)
|
|
384
|
-
throw error
|
|
385
|
-
for structure.operations as operation
|
|
386
|
-
releasePrepared([operation.old], effects)
|
|
387
|
-
for structure.commands as change
|
|
388
|
-
command = change.command
|
|
389
|
-
switch command.type
|
|
390
|
-
case "toast"
|
|
391
|
-
effects.toast(command.level, command.text)
|
|
392
|
-
case "focus"
|
|
393
|
-
effects.focus(change.target)
|
|
394
|
-
else
|
|
395
|
-
applyStateCommand(change)
|
|
396
|
-
return null
|
|
397
|
-
|
|
398
|
-
releasePrepared(controls, effects)
|
|
399
|
-
if effects.release != null
|
|
400
|
-
for controls as control
|
|
401
|
-
effects.release(control)
|
|
402
|
-
return null
|
|
403
|
-
|
|
404
|
-
prepareResponse(controls, response, effects, ownerControls, prepared)
|
|
405
|
-
structure = planStructure(controls, response.ui, effects, ownerControls, prepared)
|
|
406
|
-
values = []
|
|
407
|
-
planValues(structure.tree, response.vals, values)
|
|
408
|
-
if not is_array(response.cmds)
|
|
409
|
-
throw "UiClientCommandsMustBeArray"
|
|
410
|
-
commands = []
|
|
411
|
-
for response.cmds as command
|
|
412
|
-
if command.type == "focus" and effects.focus == null
|
|
413
|
-
throw "UiClientFocusEffectNotConfigured"
|
|
414
|
-
if command.type == "toast" and effects.toast == null
|
|
415
|
-
throw "UiClientToastEffectNotConfigured"
|
|
416
|
-
commands[commands.length] = planCommand(structure.tree, command)
|
|
417
|
-
structure.values = values
|
|
418
|
-
structure.commands = commands
|
|
419
|
-
return structure
|
|
420
|
-
|
|
421
|
-
class Field
|
|
422
|
-
properties
|
|
423
|
-
name
|
|
424
|
-
enabled
|
|
425
|
-
visible
|
|
426
|
-
value
|
|
427
|
-
controls
|
|
428
|
-
methods
|
|
429
|
-
getValue()
|
|
430
|
-
setValue(value)
|
|
431
|
-
|
|
432
|
-
Field(name, value)
|
|
433
|
-
@name = name
|
|
434
|
-
@value = value
|
|
435
|
-
@enabled = true
|
|
436
|
-
@visible = true
|
|
437
|
-
@controls = null
|
|
438
|
-
|
|
439
|
-
Field:getValue()
|
|
440
|
-
if is_array(@controls)
|
|
441
|
-
return collectValues(@controls)
|
|
442
|
-
return @value
|
|
443
|
-
|
|
444
|
-
Field:setValue(value)
|
|
445
|
-
@value = value
|
|
446
|
-
return null
|
|
447
|
-
|
|
448
|
-
class TestRenderer
|
|
449
|
-
properties
|
|
450
|
-
commits
|
|
451
|
-
methods
|
|
452
|
-
create(definition)
|
|
453
|
-
replace(old, replacement)
|
|
454
|
-
remove(control)
|
|
455
|
-
capture(control)
|
|
456
|
-
restore(snapshot, operation)
|
|
457
|
-
focus(control)
|
|
458
|
-
|
|
459
|
-
TestRenderer()
|
|
460
|
-
@commits = []
|
|
461
|
-
|
|
462
|
-
TestRenderer:create(definition)
|
|
463
|
-
field = new Field(definition.name, definition.value)
|
|
464
|
-
if is_array(definition.controls)
|
|
465
|
-
field.controls = []
|
|
466
|
-
for definition.controls as child
|
|
467
|
-
field.controls.add(create(child))
|
|
468
|
-
return field
|
|
469
|
-
|
|
470
|
-
TestRenderer:replace(old, replacement)
|
|
471
|
-
@commits.add("replace")
|
|
472
|
-
|
|
473
|
-
TestRenderer:remove(control)
|
|
474
|
-
@commits.add("remove")
|
|
475
|
-
|
|
476
|
-
TestRenderer:capture(control)
|
|
477
|
-
return control
|
|
478
|
-
|
|
479
|
-
TestRenderer:restore(snapshot, operation)
|
|
480
|
-
@commits.add("restore")
|
|
481
|
-
|
|
482
|
-
TestRenderer:focus(control)
|
|
483
|
-
@commits.add("focus")
|
|
484
|
-
|
|
485
|
-
class FailingField : Field
|
|
486
|
-
methods
|
|
487
|
-
setValue(value)
|
|
488
|
-
|
|
489
|
-
FailingField(name, value)
|
|
490
|
-
super(name, value)
|
|
491
|
-
|
|
492
|
-
FailingField:setValue(value)
|
|
493
|
-
super.setValue(value)
|
|
494
|
-
if value == "boom"
|
|
495
|
-
throw "ExpectedValueFailure"
|
|
496
|
-
|
|
497
|
-
test "value failures restore earlier values and do not run effects"
|
|
498
|
-
first = new Field("first", "before")
|
|
499
|
-
second = new FailingField("second", "before")
|
|
500
|
-
renderer = new TestRenderer()
|
|
501
|
-
try
|
|
502
|
-
applyResponse([first, second], {
|
|
503
|
-
formId: "profile"
|
|
504
|
-
seqno: 1
|
|
505
|
-
ui: {
|
|
506
|
-
replace: {
|
|
507
|
-
}
|
|
508
|
-
remove: []
|
|
509
|
-
}
|
|
510
|
-
vals: {
|
|
511
|
-
first: "updated"
|
|
512
|
-
second: "boom"
|
|
513
|
-
}
|
|
514
|
-
cmds: [{
|
|
515
|
-
type: "focus"
|
|
516
|
-
target: ["first"]
|
|
517
|
-
}]
|
|
518
|
-
}, "profile", 1, renderer)
|
|
519
|
-
assert false
|
|
520
|
-
catch error
|
|
521
|
-
assert error == "ExpectedValueFailure"
|
|
522
|
-
assert first.getValue() == "before"
|
|
523
|
-
assert second.getValue() == "before"
|
|
524
|
-
assert renderer.commits.length == 0
|
|
525
|
-
|
|
526
|
-
class FailingStateField : Field
|
|
527
|
-
methods
|
|
528
|
-
applyProperty(name, value)
|
|
529
|
-
snapshotState()
|
|
530
|
-
restoreState(snapshot)
|
|
531
|
-
|
|
532
|
-
FailingStateField(name, value)
|
|
533
|
-
super(name, value)
|
|
534
|
-
|
|
535
|
-
FailingStateField:applyProperty(name, value)
|
|
536
|
-
@enabled = value
|
|
537
|
-
throw "ExpectedStateFailure"
|
|
538
|
-
|
|
539
|
-
FailingStateField:snapshotState()
|
|
540
|
-
return {
|
|
541
|
-
enabled: @enabled
|
|
542
|
-
visible: @visible
|
|
543
|
-
value: getValue()
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
FailingStateField:restoreState(snapshot)
|
|
547
|
-
@enabled = snapshot.enabled
|
|
548
|
-
@visible = snapshot.visible
|
|
549
|
-
setValue(snapshot.value)
|
|
550
|
-
|
|
551
|
-
test "state command rollback preserves committed values and stops later effects"
|
|
552
|
-
field = new FailingStateField("text", "before")
|
|
553
|
-
renderer = new TestRenderer()
|
|
554
|
-
try
|
|
555
|
-
applyResponse([field], {
|
|
556
|
-
formId: "profile"
|
|
557
|
-
seqno: 1
|
|
558
|
-
ui: {
|
|
559
|
-
replace: {
|
|
560
|
-
}
|
|
561
|
-
remove: []
|
|
562
|
-
}
|
|
563
|
-
vals: {
|
|
564
|
-
text: "after"
|
|
565
|
-
}
|
|
566
|
-
cmds: [{
|
|
567
|
-
type: "setEnabled"
|
|
568
|
-
target: ["text"]
|
|
569
|
-
value: false
|
|
570
|
-
}, {
|
|
571
|
-
type: "focus"
|
|
572
|
-
target: ["text"]
|
|
573
|
-
}]
|
|
574
|
-
}, "profile", 1, renderer)
|
|
575
|
-
assert false
|
|
576
|
-
catch error
|
|
577
|
-
assert error == "ExpectedStateFailure"
|
|
578
|
-
assert field.enabled
|
|
579
|
-
assert field.getValue() == "after"
|
|
580
|
-
assert renderer.commits.length == 0
|
|
581
|
-
|
|
582
|
-
test "structural patches validate values and commands against the replacement tree"
|
|
583
|
-
panel = new Field("panel", null)
|
|
584
|
-
panel.controls = [new Field("old", "before")]
|
|
585
|
-
warning = new Field("warning", "obsolete")
|
|
586
|
-
controls = [panel, warning]
|
|
587
|
-
renderer = new TestRenderer()
|
|
588
|
-
response = {
|
|
589
|
-
formId: "profile"
|
|
590
|
-
seqno: 1
|
|
591
|
-
ui: {
|
|
592
|
-
replace: {
|
|
593
|
-
panel: {
|
|
594
|
-
type: "Panel"
|
|
595
|
-
controls: [{
|
|
596
|
-
type: "Text"
|
|
597
|
-
name: "new"
|
|
598
|
-
value: "initial"
|
|
599
|
-
}]
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
remove: ["warning"]
|
|
603
|
-
}
|
|
604
|
-
vals: {
|
|
605
|
-
panel: {
|
|
606
|
-
new: "updated"
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
cmds: [{
|
|
610
|
-
type: "setEnabled"
|
|
611
|
-
target: ["panel", "new"]
|
|
612
|
-
value: false
|
|
613
|
-
}]
|
|
614
|
-
}
|
|
615
|
-
applyResponse(controls, response, "profile", 1, renderer)
|
|
616
|
-
assert controls.length == 1
|
|
617
|
-
child = controls[0].controls[0]
|
|
618
|
-
assert child.getValue() == "updated"
|
|
619
|
-
assert !child.enabled
|
|
620
|
-
assert renderer.commits[0] == "replace"
|
|
621
|
-
assert renderer.commits[1] == "remove"
|
|
622
|
-
assert panel.controls[0].name == "old"
|
|
623
|
-
|
|
624
|
-
test "invalid replacement follow-up leaves the old tree untouched"
|
|
625
|
-
original = new Field("text", "before")
|
|
626
|
-
controls = [original]
|
|
627
|
-
renderer = new TestRenderer()
|
|
628
|
-
response = {
|
|
629
|
-
formId: "profile"
|
|
630
|
-
seqno: 1
|
|
631
|
-
ui: {
|
|
632
|
-
replace: {
|
|
633
|
-
text: {
|
|
634
|
-
type: "Text"
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
remove: []
|
|
638
|
-
}
|
|
639
|
-
vals: {
|
|
640
|
-
missing: "after"
|
|
641
|
-
}
|
|
642
|
-
cmds: []
|
|
643
|
-
}
|
|
644
|
-
try
|
|
645
|
-
applyResponse(controls, response, "profile", 1, renderer)
|
|
646
|
-
assert false
|
|
647
|
-
catch error
|
|
648
|
-
assert error == "UiClientTargetNotFound: missing"
|
|
649
|
-
assert controls[0] == original
|
|
650
|
-
assert original.getValue() == "before"
|
|
651
|
-
assert renderer.commits.length == 0
|
|
652
|
-
|
|
653
|
-
test "repeated removal is a no-op and overlapping paths are rejected"
|
|
654
|
-
controls = []
|
|
655
|
-
renderer = new TestRenderer()
|
|
656
|
-
response = {
|
|
657
|
-
formId: "profile"
|
|
658
|
-
seqno: 1
|
|
659
|
-
ui: {
|
|
660
|
-
replace: {
|
|
661
|
-
}
|
|
662
|
-
remove: [["missing"]]
|
|
663
|
-
}
|
|
664
|
-
vals: {
|
|
665
|
-
}
|
|
666
|
-
cmds: []
|
|
667
|
-
}
|
|
668
|
-
applyResponse(controls, response, "profile", 1, renderer)
|
|
669
|
-
applyResponse(controls, response, "profile", 1, renderer)
|
|
670
|
-
assert renderer.commits.length == 0
|
|
671
|
-
panel = new Field("panel", null)
|
|
672
|
-
panel.controls = [new Field("child", null)]
|
|
673
|
-
controls.add(panel)
|
|
674
|
-
response = {
|
|
675
|
-
formId: "profile"
|
|
676
|
-
seqno: 1
|
|
677
|
-
ui: {
|
|
678
|
-
replace: {
|
|
679
|
-
panel: {
|
|
680
|
-
type: "Panel"
|
|
681
|
-
controls: []
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
remove: [["panel", "child"]]
|
|
685
|
-
}
|
|
686
|
-
vals: {
|
|
687
|
-
}
|
|
688
|
-
cmds: []
|
|
689
|
-
}
|
|
690
|
-
try
|
|
691
|
-
applyResponse(controls, response, "profile", 1, renderer)
|
|
692
|
-
assert false
|
|
693
|
-
catch error
|
|
694
|
-
assert error == "UiClientOverlappingStructurePatches"
|
|
695
|
-
assert controls[0] == panel
|
|
696
|
-
|
|
697
|
-
test "client collection preserves hierarchical names and null control values"
|
|
698
|
-
city = new Field("city", "Ankara")
|
|
699
|
-
address = new Field("address", null)
|
|
700
|
-
address.controls = [city]
|
|
701
|
-
button = new Field("button", null)
|
|
702
|
-
unnamed = new Field(null, "ignored")
|
|
703
|
-
values = collectValues([address, button, unnamed])
|
|
704
|
-
assert values.address.city == "Ankara"
|
|
705
|
-
assert values.button == null
|
|
706
|
-
|
|
707
|
-
test "client validates all targets before applying values or commands"
|
|
708
|
-
field = new Field("text", "before")
|
|
709
|
-
response = {
|
|
710
|
-
formId: "profile"
|
|
711
|
-
seqno: 1
|
|
712
|
-
ui: {
|
|
713
|
-
replace: {
|
|
714
|
-
}
|
|
715
|
-
remove: []
|
|
716
|
-
}
|
|
717
|
-
vals: {
|
|
718
|
-
text: "after"
|
|
719
|
-
}
|
|
720
|
-
cmds: [{
|
|
721
|
-
type: "setEnabled"
|
|
722
|
-
target: ["missing"]
|
|
723
|
-
value: false
|
|
724
|
-
}]
|
|
725
|
-
}
|
|
726
|
-
try
|
|
727
|
-
applyResponse([field], response, "profile", 1, {
|
|
728
|
-
})
|
|
729
|
-
assert false
|
|
730
|
-
catch error
|
|
731
|
-
assert error == "UiClientTargetNotFound: missing"
|
|
732
|
-
assert field.value == "before"
|
|
733
|
-
assert field.enabled
|
|
734
|
-
|
|
735
|
-
test "client applies nested values and state commands"
|
|
736
|
-
field = new Field("city", "Ankara")
|
|
737
|
-
address = new Field("address", null)
|
|
738
|
-
address.controls = [field]
|
|
739
|
-
response = {
|
|
740
|
-
formId: "profile"
|
|
741
|
-
seqno: 1
|
|
742
|
-
ui: {
|
|
743
|
-
replace: {
|
|
744
|
-
}
|
|
745
|
-
remove: []
|
|
746
|
-
}
|
|
747
|
-
vals: {
|
|
748
|
-
address: {
|
|
749
|
-
city: "Istanbul"
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
cmds: [{
|
|
753
|
-
type: "setProperty"
|
|
754
|
-
target: ["address", "city"]
|
|
755
|
-
name: "enabled"
|
|
756
|
-
value: false
|
|
757
|
-
}]
|
|
758
|
-
}
|
|
759
|
-
applyResponse([address], response, "profile", 1, {
|
|
760
|
-
})
|
|
761
|
-
assert field.value == "Istanbul"
|
|
762
|
-
assert !field.enabled
|
|
763
|
-
|
|
764
|
-
test "unsupported protocol versions fail before values or structure are applied"
|
|
765
|
-
field = new Field("text", "original")
|
|
766
|
-
for [0, 2, "1", null] as version
|
|
767
|
-
failed = false
|
|
768
|
-
try
|
|
769
|
-
applyResponse([field], {
|
|
770
|
-
protocol: version
|
|
771
|
-
formId: "page"
|
|
772
|
-
seqno: 1
|
|
773
|
-
ui: {
|
|
774
|
-
replace: {
|
|
775
|
-
}
|
|
776
|
-
remove: []
|
|
777
|
-
}
|
|
778
|
-
vals: {
|
|
779
|
-
text: "must not apply"
|
|
780
|
-
}
|
|
781
|
-
cmds: []
|
|
782
|
-
}, "page", 1, new TestRenderer())
|
|
783
|
-
catch error
|
|
784
|
-
assert error == "UiProtocolUnsupported"
|
|
785
|
-
failed = true
|
|
786
|
-
assert failed
|
|
787
|
-
assert field.getValue() == "original"
|