@lango-project/lango-client 0.0.0-stage → 0.2.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.
- package/LICENSE +200 -0
- package/NOTICE +2 -0
- package/README.md +877 -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 +792 -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 +431 -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 +302 -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 +72 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +28 -0
- package/examples/pages.lango +180 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +64 -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 +571 -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 +1986 -0
- package/src/session.lango +313 -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 +40 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +4 -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/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import "./protocol"
|
|
2
|
+
collectValues(controls)
|
|
3
|
+
applyResponse(controls, response, formId, seqno, effects)
|
|
4
|
+
import "./inheritance"
|
|
5
|
+
normalizeInheritance(spec)
|
|
6
|
+
import "./presentation"
|
|
7
|
+
classNames(value)
|
|
8
|
+
styleMap(value)
|
|
9
|
+
validateProperty(name, value)
|
|
10
|
+
import "./input_values"
|
|
11
|
+
selectItems(options)
|
|
12
|
+
selectIndex(items, value)
|
|
13
|
+
import "./form_state"
|
|
14
|
+
rulesFor(value)
|
|
15
|
+
validationMessage(rules, value)
|
|
16
|
+
sameValue(left, right)
|
|
17
|
+
|
|
18
|
+
export mount(document, root, definition, types = null)
|
|
19
|
+
|
|
20
|
+
export class Types
|
|
21
|
+
methods
|
|
22
|
+
registerType(name, type)
|
|
23
|
+
create(document, definition)
|
|
24
|
+
|
|
25
|
+
Types(options = null)
|
|
26
|
+
if options != null and (!is_object(options) or is_array(options))
|
|
27
|
+
throw "UiControlRegistryOptionsMustBeMap"
|
|
28
|
+
@types = {
|
|
29
|
+
}
|
|
30
|
+
@classes = {
|
|
31
|
+
}
|
|
32
|
+
@sealed = false
|
|
33
|
+
if options != null and options.classes != null
|
|
34
|
+
if !is_object(options.classes) or is_array(options.classes)
|
|
35
|
+
throw "UiThemeClassesMustBeMap"
|
|
36
|
+
for options.classes as name: classes
|
|
37
|
+
@classes[name] = classNames(classes)
|
|
38
|
+
|
|
39
|
+
Types:registerType(name, type)
|
|
40
|
+
if @sealed
|
|
41
|
+
throw "UiControlRegistrySealed"
|
|
42
|
+
if !is_string(name) or name == "" or name == "__proto__" or name == "prototype" or name == "constructor" or !is_kindof(type, Function)
|
|
43
|
+
throw "UiControlTypeRequiresNameAndConstructor"
|
|
44
|
+
if name in @types
|
|
45
|
+
throw "UiDuplicateControlType: ${name}"
|
|
46
|
+
@types[name] = type
|
|
47
|
+
return @this
|
|
48
|
+
|
|
49
|
+
Types:create(document, definition)
|
|
50
|
+
@sealed = true
|
|
51
|
+
if !is_object(definition) or !is_string(definition.type)
|
|
52
|
+
throw "UiControlRequiresDefinition"
|
|
53
|
+
prepared = {
|
|
54
|
+
}
|
|
55
|
+
for definition as name: value
|
|
56
|
+
prepared[name] = value
|
|
57
|
+
defaults = @classes[definition.type]
|
|
58
|
+
if defaults != null
|
|
59
|
+
prepared.classes = classNames(defaults.concat(classNames(definition.classes)))
|
|
60
|
+
type = Control
|
|
61
|
+
if definition.type in @types
|
|
62
|
+
type = @types[definition.type]
|
|
63
|
+
control = new type(document, prepared, @this)
|
|
64
|
+
if !is_kindof(control, Control)
|
|
65
|
+
throw "UiCustomControlMustExtendControl"
|
|
66
|
+
return control
|
|
67
|
+
|
|
68
|
+
export class Binding
|
|
69
|
+
methods
|
|
70
|
+
handle(event)
|
|
71
|
+
report(error)
|
|
72
|
+
dispose()
|
|
73
|
+
|
|
74
|
+
Binding(form, session, errors = null)
|
|
75
|
+
@form = form
|
|
76
|
+
@session = session
|
|
77
|
+
@errors = errors
|
|
78
|
+
@disposed = false
|
|
79
|
+
root = form.element
|
|
80
|
+
if root.langoBinding != null
|
|
81
|
+
throw "UiFormAlreadyBound"
|
|
82
|
+
listener = (event)
|
|
83
|
+
handle(event)
|
|
84
|
+
@listener = listener
|
|
85
|
+
for ["click", "change", "input"] as type
|
|
86
|
+
root.addEventListener(type, listener)
|
|
87
|
+
root.langoBinding = @this
|
|
88
|
+
|
|
89
|
+
Binding:handle(event)
|
|
90
|
+
if @disposed
|
|
91
|
+
return null
|
|
92
|
+
root = @form.element
|
|
93
|
+
element = event.target
|
|
94
|
+
target = null
|
|
95
|
+
current = element
|
|
96
|
+
loop while current != null
|
|
97
|
+
if current.inert == true or current.disabled == true or current.hidden == true
|
|
98
|
+
return null
|
|
99
|
+
if current == root
|
|
100
|
+
break
|
|
101
|
+
if current.langoFormRoot == true
|
|
102
|
+
return null
|
|
103
|
+
if target == null
|
|
104
|
+
target = eventTarget(@form.controls, current, [], event.type)
|
|
105
|
+
current = current.parentNode
|
|
106
|
+
if current != root
|
|
107
|
+
return null
|
|
108
|
+
if event.type == "input" or event.type == "change"
|
|
109
|
+
validateEvent(@form.controls, event.target, root)
|
|
110
|
+
if target == null
|
|
111
|
+
return null
|
|
112
|
+
try
|
|
113
|
+
event.preventDefault()
|
|
114
|
+
if @errors != null and @errors.clear != null
|
|
115
|
+
@errors.clear()
|
|
116
|
+
session = @session
|
|
117
|
+
return session.send(target.url, event.type, target.name).catch((error)
|
|
118
|
+
report(error)
|
|
119
|
+
)
|
|
120
|
+
catch error
|
|
121
|
+
report(error)
|
|
122
|
+
return null
|
|
123
|
+
|
|
124
|
+
validateEvent(controls, element, root)
|
|
125
|
+
current = element
|
|
126
|
+
loop while current != null and current != root
|
|
127
|
+
control = elementControl(controls, current)
|
|
128
|
+
if control != null and control.validate != null
|
|
129
|
+
control.validate()
|
|
130
|
+
return null
|
|
131
|
+
current = current.parentNode
|
|
132
|
+
return null
|
|
133
|
+
|
|
134
|
+
elementControl(controls, element)
|
|
135
|
+
for controls as control
|
|
136
|
+
if control.element.langoFormRoot == true
|
|
137
|
+
continue
|
|
138
|
+
if control.element == element
|
|
139
|
+
return control
|
|
140
|
+
if is_array(control.controls)
|
|
141
|
+
found = elementControl(control.controls, element)
|
|
142
|
+
if found != null
|
|
143
|
+
return found
|
|
144
|
+
return null
|
|
145
|
+
|
|
146
|
+
Binding:report(error)
|
|
147
|
+
if @disposed
|
|
148
|
+
return null
|
|
149
|
+
if @errors != null
|
|
150
|
+
@errors.error(error)
|
|
151
|
+
else
|
|
152
|
+
context log
|
|
153
|
+
log.err(error)
|
|
154
|
+
return null
|
|
155
|
+
|
|
156
|
+
Binding:dispose()
|
|
157
|
+
if @disposed
|
|
158
|
+
return null
|
|
159
|
+
@disposed = true
|
|
160
|
+
root = @form.element
|
|
161
|
+
for ["click", "change", "input"] as type
|
|
162
|
+
root.removeEventListener(type, @listener)
|
|
163
|
+
root.langoBinding = null
|
|
164
|
+
return null
|
|
165
|
+
|
|
166
|
+
eventTarget(controls, element, parentPath, type)
|
|
167
|
+
for controls as control
|
|
168
|
+
path = parentPath.slice()
|
|
169
|
+
if control.name != null and control.name != ""
|
|
170
|
+
path[path.length] = control.name
|
|
171
|
+
if control.element == element
|
|
172
|
+
events = control.events
|
|
173
|
+
if type in events
|
|
174
|
+
name = path
|
|
175
|
+
if path.length == 1
|
|
176
|
+
name = path[0]
|
|
177
|
+
if path.length == 0
|
|
178
|
+
name = null
|
|
179
|
+
return {
|
|
180
|
+
url: events[type]
|
|
181
|
+
name: name
|
|
182
|
+
}
|
|
183
|
+
if is_array(control.controls)
|
|
184
|
+
target = eventTarget(control.controls, element, path, type)
|
|
185
|
+
if target != null
|
|
186
|
+
return target
|
|
187
|
+
return null
|
|
188
|
+
|
|
189
|
+
controlEvents(definition)
|
|
190
|
+
events = {
|
|
191
|
+
}
|
|
192
|
+
if definition.event != null
|
|
193
|
+
type = "change"
|
|
194
|
+
if definition.type == "Button"
|
|
195
|
+
type = "click"
|
|
196
|
+
events[type] = definition.event
|
|
197
|
+
if definition.events != null
|
|
198
|
+
if not is_object(definition.events)
|
|
199
|
+
throw "UiClientEventsMustBeMap"
|
|
200
|
+
for definition.events as type: url
|
|
201
|
+
if type != "click" and type != "change" and type != "input"
|
|
202
|
+
throw "UiClientUnsupportedEventType"
|
|
203
|
+
events[type] = url
|
|
204
|
+
for events as type: url
|
|
205
|
+
if !is_string(url) or !url.startsWith("/") or url.startsWith("//") or url.includes("\\")
|
|
206
|
+
throw "UiClientEventRequiresSameOriginPath"
|
|
207
|
+
return events
|
|
208
|
+
|
|
209
|
+
export class Renderer
|
|
210
|
+
methods
|
|
211
|
+
create(definition)
|
|
212
|
+
replace(old, replacement)
|
|
213
|
+
remove(control)
|
|
214
|
+
capture(control)
|
|
215
|
+
restore(snapshot, operation)
|
|
216
|
+
focus(control)
|
|
217
|
+
toast(level, text)
|
|
218
|
+
release(control)
|
|
219
|
+
|
|
220
|
+
Renderer(document, types = null)
|
|
221
|
+
@document = document
|
|
222
|
+
@types = types
|
|
223
|
+
if @types == null
|
|
224
|
+
@types = new Types()
|
|
225
|
+
|
|
226
|
+
Renderer:create(definition)
|
|
227
|
+
return @types.create(@document, definition)
|
|
228
|
+
|
|
229
|
+
Renderer:release(control)
|
|
230
|
+
releaseControl(control)
|
|
231
|
+
return null
|
|
232
|
+
|
|
233
|
+
releaseControl(control)
|
|
234
|
+
if is_array(control.controls)
|
|
235
|
+
for control.controls as child
|
|
236
|
+
releaseControl(child)
|
|
237
|
+
try
|
|
238
|
+
if control.dispose != null
|
|
239
|
+
control.dispose()
|
|
240
|
+
catch error
|
|
241
|
+
context log
|
|
242
|
+
log.err("Control disposal failed: ${error}")
|
|
243
|
+
return null
|
|
244
|
+
|
|
245
|
+
Renderer:replace(old, replacement)
|
|
246
|
+
element = old.element
|
|
247
|
+
element.parentNode.replaceChild(replacement.element, element)
|
|
248
|
+
return null
|
|
249
|
+
|
|
250
|
+
Renderer:remove(control)
|
|
251
|
+
control.element.remove()
|
|
252
|
+
return null
|
|
253
|
+
|
|
254
|
+
Renderer:capture(control)
|
|
255
|
+
element = control.element
|
|
256
|
+
return {
|
|
257
|
+
element: element
|
|
258
|
+
parent: element.parentNode
|
|
259
|
+
next: element.nextSibling
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
Renderer:restore(snapshot, operation)
|
|
263
|
+
if operation.type == "replace"
|
|
264
|
+
replacement = operation.new
|
|
265
|
+
replacement.element.remove()
|
|
266
|
+
if snapshot.parent != null
|
|
267
|
+
snapshot.parent.insertBefore(snapshot.element, snapshot.next)
|
|
268
|
+
return null
|
|
269
|
+
|
|
270
|
+
Renderer:focus(control)
|
|
271
|
+
control.element.focus()
|
|
272
|
+
return null
|
|
273
|
+
|
|
274
|
+
Renderer:toast(level, text)
|
|
275
|
+
element = @document.createElement("div")
|
|
276
|
+
element.setAttribute("role", "status")
|
|
277
|
+
element.textContent = text
|
|
278
|
+
@document.body.appendChild(element)
|
|
279
|
+
return null
|
|
280
|
+
|
|
281
|
+
export class Control
|
|
282
|
+
properties
|
|
283
|
+
name
|
|
284
|
+
element
|
|
285
|
+
controls
|
|
286
|
+
events
|
|
287
|
+
inherit
|
|
288
|
+
validates
|
|
289
|
+
confirms
|
|
290
|
+
methods
|
|
291
|
+
getValue()
|
|
292
|
+
setValue(value)
|
|
293
|
+
applyProperty(name, value)
|
|
294
|
+
snapshotState()
|
|
295
|
+
restoreState(snapshot)
|
|
296
|
+
dispose()
|
|
297
|
+
isDirty()
|
|
298
|
+
markClean()
|
|
299
|
+
acceptSaved(value)
|
|
300
|
+
validate()
|
|
301
|
+
reportValidity()
|
|
302
|
+
reportPendingError()
|
|
303
|
+
|
|
304
|
+
Control(document, definition, types = null, options = null)
|
|
305
|
+
@name = definition.name
|
|
306
|
+
@type = definition.type
|
|
307
|
+
@controls = null
|
|
308
|
+
@value = definition.value
|
|
309
|
+
@clean = null
|
|
310
|
+
@error = null
|
|
311
|
+
@pendingError = false
|
|
312
|
+
@rules = rulesFor(definition.validation)
|
|
313
|
+
@tracked = definition.trackChanges
|
|
314
|
+
if @tracked == null
|
|
315
|
+
@tracked = @type == "Text" or @type == "Select" or @type == "Checkbox"
|
|
316
|
+
if !is_bool(@tracked)
|
|
317
|
+
throw "UiTrackChangesMustBeBoolean"
|
|
318
|
+
@validates = definition.validate
|
|
319
|
+
if @validates == null
|
|
320
|
+
@validates = false
|
|
321
|
+
if !is_bool(@validates)
|
|
322
|
+
throw "UiValidateEventMustBeBoolean"
|
|
323
|
+
@confirms = definition.confirmDirty
|
|
324
|
+
if @confirms == null
|
|
325
|
+
@confirms = false
|
|
326
|
+
if !is_bool(@confirms)
|
|
327
|
+
throw "UiConfirmDirtyMustBeBoolean"
|
|
328
|
+
@items = []
|
|
329
|
+
if @type == "Select"
|
|
330
|
+
@items = selectItems(definition.options)
|
|
331
|
+
@events = controlEvents(definition)
|
|
332
|
+
@inherit = normalizeInheritance(definition.inherit)
|
|
333
|
+
@classes = classNames(definition.classes)
|
|
334
|
+
@style = styleMap(definition.style)
|
|
335
|
+
registry = types
|
|
336
|
+
if registry == null
|
|
337
|
+
registry = new Types()
|
|
338
|
+
if definition.inherit != null and @type != "Form"
|
|
339
|
+
throw "UiInheritanceRequiresForm"
|
|
340
|
+
tag = "div"
|
|
341
|
+
if @type == "Text" or @type == "Checkbox"
|
|
342
|
+
tag = "input"
|
|
343
|
+
if @type == "Select"
|
|
344
|
+
tag = "select"
|
|
345
|
+
if @type == "Button"
|
|
346
|
+
tag = "button"
|
|
347
|
+
if options != null
|
|
348
|
+
tag = options.tag
|
|
349
|
+
if !is_string(tag) or tag == ""
|
|
350
|
+
throw "UiCustomControlRequiresTag"
|
|
351
|
+
if options == null and @type != "Text" and @type != "Button" and @type != "Value" and @type != "Panel" and @type != "Container" and @type != "Form" and @type != "Select" and @type != "Checkbox"
|
|
352
|
+
throw "UiClientUnknownControlType"
|
|
353
|
+
@element = document.createElement(tag)
|
|
354
|
+
element = @element
|
|
355
|
+
if @type == "Form"
|
|
356
|
+
element.langoFormRoot = true
|
|
357
|
+
if @type == "Button"
|
|
358
|
+
element.type = "button"
|
|
359
|
+
element.textContent = definition.text
|
|
360
|
+
if @type == "Value"
|
|
361
|
+
element.hidden = true
|
|
362
|
+
if @type == "Checkbox"
|
|
363
|
+
element.type = "checkbox"
|
|
364
|
+
if definition.label != null
|
|
365
|
+
if !is_string(definition.label)
|
|
366
|
+
throw "UiControlLabelMustBeString"
|
|
367
|
+
element.setAttribute("aria-label", definition.label)
|
|
368
|
+
container = @type == "Panel" or @type == "Container" or @type == "Form"
|
|
369
|
+
if options != null and options.container == true
|
|
370
|
+
container = true
|
|
371
|
+
if container
|
|
372
|
+
@controls = []
|
|
373
|
+
try
|
|
374
|
+
if @type == "Select"
|
|
375
|
+
for @items as item
|
|
376
|
+
option = document.createElement("option")
|
|
377
|
+
option.value = item.value
|
|
378
|
+
option.textContent = item.text
|
|
379
|
+
option.disabled = item.disabled
|
|
380
|
+
element.appendChild(option)
|
|
381
|
+
if container and is_array(definition.controls)
|
|
382
|
+
for definition.controls as childDefinition
|
|
383
|
+
child = registry.create(document, childDefinition)
|
|
384
|
+
@controls.add(child)
|
|
385
|
+
element.appendChild(child.element)
|
|
386
|
+
if definition.classes != null
|
|
387
|
+
applyProperty("classes", definition.classes)
|
|
388
|
+
if definition.style != null
|
|
389
|
+
applyProperty("style", definition.style)
|
|
390
|
+
if definition.enabled != null
|
|
391
|
+
applyProperty("enabled", definition.enabled)
|
|
392
|
+
if definition.visible != null
|
|
393
|
+
applyProperty("visible", definition.visible)
|
|
394
|
+
initial = definition.value
|
|
395
|
+
if @type == "Checkbox" and initial == null
|
|
396
|
+
initial = false
|
|
397
|
+
setValue(initial)
|
|
398
|
+
markClean()
|
|
399
|
+
catch error
|
|
400
|
+
if is_array(@controls)
|
|
401
|
+
for @controls as child
|
|
402
|
+
releaseControl(child)
|
|
403
|
+
throw error
|
|
404
|
+
|
|
405
|
+
Control:getValue()
|
|
406
|
+
if is_array(@controls)
|
|
407
|
+
return collectValues(@controls)
|
|
408
|
+
switch @type
|
|
409
|
+
case "Text"
|
|
410
|
+
return @element.value
|
|
411
|
+
case "Checkbox"
|
|
412
|
+
return @element.checked
|
|
413
|
+
case "Select"
|
|
414
|
+
index = @element.selectedIndex
|
|
415
|
+
if index < 0 or index >= @items.length
|
|
416
|
+
return null
|
|
417
|
+
return @items[index].value
|
|
418
|
+
else
|
|
419
|
+
return @value
|
|
420
|
+
|
|
421
|
+
Control:setValue(value)
|
|
422
|
+
switch @type
|
|
423
|
+
case "Text"
|
|
424
|
+
text = value
|
|
425
|
+
if value == null
|
|
426
|
+
text = ""
|
|
427
|
+
@element.value = text
|
|
428
|
+
case "Checkbox"
|
|
429
|
+
if !is_bool(value)
|
|
430
|
+
throw "UiCheckboxValueMustBeBoolean"
|
|
431
|
+
@element.checked = value
|
|
432
|
+
case "Select"
|
|
433
|
+
@element.selectedIndex = selectIndex(@items, value)
|
|
434
|
+
@value = value
|
|
435
|
+
if @error != null
|
|
436
|
+
validate()
|
|
437
|
+
return null
|
|
438
|
+
|
|
439
|
+
Control:isDirty()
|
|
440
|
+
if is_array(@controls)
|
|
441
|
+
for @controls as child
|
|
442
|
+
if child.isDirty != null
|
|
443
|
+
if child.isDirty()
|
|
444
|
+
return true
|
|
445
|
+
return false
|
|
446
|
+
if !@tracked
|
|
447
|
+
return false
|
|
448
|
+
current = from_json(to_json(getValue()))
|
|
449
|
+
return !sameValue(current, @clean)
|
|
450
|
+
|
|
451
|
+
Control:markClean()
|
|
452
|
+
if is_array(@controls)
|
|
453
|
+
for @controls as child
|
|
454
|
+
if child.markClean != null
|
|
455
|
+
child.markClean()
|
|
456
|
+
else
|
|
457
|
+
acceptSaved(getValue())
|
|
458
|
+
return null
|
|
459
|
+
|
|
460
|
+
Control:acceptSaved(value)
|
|
461
|
+
@clean = from_json(to_json(value))
|
|
462
|
+
return null
|
|
463
|
+
|
|
464
|
+
Control:validate()
|
|
465
|
+
@pendingError = false
|
|
466
|
+
@error = validationMessage(@rules, getValue())
|
|
467
|
+
renderError()
|
|
468
|
+
return @error
|
|
469
|
+
|
|
470
|
+
Control:renderError()
|
|
471
|
+
text = @error
|
|
472
|
+
if text == null
|
|
473
|
+
text = ""
|
|
474
|
+
@element.setAttribute("aria-invalid", "${@error != null}")
|
|
475
|
+
@element.setAttribute("data-lango-error", text)
|
|
476
|
+
if @element.setCustomValidity != null
|
|
477
|
+
@element.setCustomValidity(text)
|
|
478
|
+
return null
|
|
479
|
+
|
|
480
|
+
Control:reportValidity()
|
|
481
|
+
if @element.reportValidity != null
|
|
482
|
+
return @element.reportValidity()
|
|
483
|
+
return @error == null
|
|
484
|
+
|
|
485
|
+
Control:reportPendingError()
|
|
486
|
+
if !@pendingError
|
|
487
|
+
return false
|
|
488
|
+
current = @element
|
|
489
|
+
loop while current != null
|
|
490
|
+
if current.disabled == true or current.hidden == true or current.inert == true
|
|
491
|
+
return false
|
|
492
|
+
current = current.parentNode
|
|
493
|
+
@pendingError = false
|
|
494
|
+
reportValidity()
|
|
495
|
+
return true
|
|
496
|
+
|
|
497
|
+
Control:applyProperty(name, value)
|
|
498
|
+
validateProperty(name, value)
|
|
499
|
+
switch name
|
|
500
|
+
case "enabled"
|
|
501
|
+
@element.disabled = !value
|
|
502
|
+
@element.inert = !value
|
|
503
|
+
case "visible"
|
|
504
|
+
@element.hidden = !value or @type == "Value"
|
|
505
|
+
case "classes"
|
|
506
|
+
@classes = classNames(value)
|
|
507
|
+
@element.className = @classes.join(" ")
|
|
508
|
+
case "style"
|
|
509
|
+
styles = styleMap(value)
|
|
510
|
+
for @style as property: text
|
|
511
|
+
@element.style.removeProperty(property)
|
|
512
|
+
for styles as property: text
|
|
513
|
+
@element.style.setProperty(property, text)
|
|
514
|
+
@style = styles
|
|
515
|
+
case "savedValue"
|
|
516
|
+
acceptSaved(value)
|
|
517
|
+
case "error"
|
|
518
|
+
@error = value
|
|
519
|
+
@pendingError = value != null
|
|
520
|
+
renderError()
|
|
521
|
+
reportPendingError()
|
|
522
|
+
return null
|
|
523
|
+
|
|
524
|
+
Control:snapshotState()
|
|
525
|
+
return {
|
|
526
|
+
value: @value
|
|
527
|
+
text: @element.value
|
|
528
|
+
checked: @element.checked
|
|
529
|
+
selectedIndex: @element.selectedIndex
|
|
530
|
+
disabled: @element.disabled
|
|
531
|
+
hidden: @element.hidden
|
|
532
|
+
inert: @element.inert
|
|
533
|
+
classes: @element.className
|
|
534
|
+
style: @element.style.cssText
|
|
535
|
+
managedStyle: @style
|
|
536
|
+
managedClasses: @classes
|
|
537
|
+
clean: @clean
|
|
538
|
+
error: @error
|
|
539
|
+
pendingError: @pendingError
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
Control:restoreState(snapshot)
|
|
543
|
+
setValue(snapshot.value)
|
|
544
|
+
if @type == "Text"
|
|
545
|
+
@element.value = snapshot.text
|
|
546
|
+
if @type == "Checkbox"
|
|
547
|
+
@element.checked = snapshot.checked
|
|
548
|
+
if @type == "Select"
|
|
549
|
+
@element.selectedIndex = snapshot.selectedIndex
|
|
550
|
+
@element.disabled = snapshot.disabled
|
|
551
|
+
@element.hidden = snapshot.hidden
|
|
552
|
+
@element.inert = snapshot.inert
|
|
553
|
+
@element.className = snapshot.classes
|
|
554
|
+
@element.style.cssText = snapshot.style
|
|
555
|
+
@style = snapshot.managedStyle
|
|
556
|
+
@classes = snapshot.managedClasses
|
|
557
|
+
@clean = snapshot.clean
|
|
558
|
+
@error = snapshot.error
|
|
559
|
+
@pendingError = snapshot.pendingError
|
|
560
|
+
renderError()
|
|
561
|
+
return null
|
|
562
|
+
|
|
563
|
+
Control:dispose()
|
|
564
|
+
return null
|
|
565
|
+
|
|
566
|
+
mount(document, root, definition, types = null)
|
|
567
|
+
if types == null
|
|
568
|
+
types = new Types()
|
|
569
|
+
control = types.create(document, definition)
|
|
570
|
+
root.appendChild(control.element)
|
|
571
|
+
return control
|