@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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import js global Number
|
|
2
|
+
import js global RegExp
|
|
3
|
+
import "./fields"
|
|
4
|
+
class Field
|
|
5
|
+
import "./templates"
|
|
6
|
+
cloneMarkup(name, xml)
|
|
7
|
+
import "./input_changes"
|
|
8
|
+
class InputChanges
|
|
9
|
+
|
|
10
|
+
export otpSettings(length = null, characters = null)
|
|
11
|
+
export otpText(value, settings, strict = false)
|
|
12
|
+
|
|
13
|
+
otpSettings(length = null, characters = null)
|
|
14
|
+
if length == null
|
|
15
|
+
length = 6
|
|
16
|
+
if !is_number(length) or !Number/isInteger(length) or length < 1 or length > 64
|
|
17
|
+
throw "OTP length must be an integer between 1 and 64"
|
|
18
|
+
if characters == null
|
|
19
|
+
characters = "numeric"
|
|
20
|
+
pattern = null
|
|
21
|
+
switch characters
|
|
22
|
+
case "numeric"
|
|
23
|
+
pattern = "[^0-9]"
|
|
24
|
+
case "alpha"
|
|
25
|
+
pattern = "[^A-Za-z]"
|
|
26
|
+
case "alphanumeric"
|
|
27
|
+
pattern = "[^A-Za-z0-9]"
|
|
28
|
+
else
|
|
29
|
+
throw "Unknown OTP characters: ${characters}"
|
|
30
|
+
return {
|
|
31
|
+
length: length
|
|
32
|
+
characters: characters
|
|
33
|
+
pattern: pattern
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
otpText(value, settings, strict = false)
|
|
37
|
+
if value == null
|
|
38
|
+
value = ""
|
|
39
|
+
if !is_string(value)
|
|
40
|
+
throw "OTP value must be text"
|
|
41
|
+
filtered = value.replace(new RegExp(settings.pattern, "g"), "").slice(0, settings.length)
|
|
42
|
+
if strict and filtered != value
|
|
43
|
+
throw "OTP value contains unsupported characters or exceeds its length"
|
|
44
|
+
return filtered
|
|
45
|
+
|
|
46
|
+
export class OTPInput(form, props) : Field
|
|
47
|
+
methods
|
|
48
|
+
getValue()
|
|
49
|
+
setValue(value)
|
|
50
|
+
dispose()
|
|
51
|
+
|
|
52
|
+
OTPInput(form, props)
|
|
53
|
+
super(form, props, cloneMarkup("otp-input", <input type="text" class="form-control lango-otp" />))
|
|
54
|
+
@settings = otpSettings(props.length, props.characters)
|
|
55
|
+
@changes = new InputChanges(form, props.url)
|
|
56
|
+
@input.spellcheck = false
|
|
57
|
+
@input.autocapitalize = "off"
|
|
58
|
+
if props.disableAutoComplete != true
|
|
59
|
+
@input.autocomplete = "one-time-code"
|
|
60
|
+
if @settings.characters == "numeric"
|
|
61
|
+
@input.inputMode = "numeric"
|
|
62
|
+
setValue(props.value)
|
|
63
|
+
listener = ()
|
|
64
|
+
@input.value = otpText(@input.value, @settings)
|
|
65
|
+
@changes.changed()
|
|
66
|
+
@input.addEventListener("input", listener)
|
|
67
|
+
release = ()
|
|
68
|
+
capture listener
|
|
69
|
+
@input.removeEventListener("input", listener)
|
|
70
|
+
@release.add(release)
|
|
71
|
+
|
|
72
|
+
OTPInput:getValue()
|
|
73
|
+
return @input.value
|
|
74
|
+
|
|
75
|
+
OTPInput:setValue(value)
|
|
76
|
+
next = otpText(value, @settings, true)
|
|
77
|
+
@input.value = next
|
|
78
|
+
return @this
|
|
79
|
+
|
|
80
|
+
OTPInput:dispose()
|
|
81
|
+
@changes.dispose()
|
|
82
|
+
super.dispose()
|
|
83
|
+
return null
|
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import js global document
|
|
2
|
+
import js global Object
|
|
3
|
+
import js global Reflect
|
|
4
|
+
import "./control"
|
|
5
|
+
class Control
|
|
6
|
+
import "./form"
|
|
7
|
+
class Form
|
|
8
|
+
import "./widgets"
|
|
9
|
+
class Alert
|
|
10
|
+
import "./content"
|
|
11
|
+
appendContent(form, element, content, renderer)
|
|
12
|
+
import "./templates"
|
|
13
|
+
cloneMarkup(name, xml)
|
|
14
|
+
controlId()
|
|
15
|
+
|
|
16
|
+
export class Toast(form, props, renderer) : Control
|
|
17
|
+
methods
|
|
18
|
+
find(name)
|
|
19
|
+
close()
|
|
20
|
+
dispose()
|
|
21
|
+
|
|
22
|
+
Toast(form, props, renderer)
|
|
23
|
+
super(form, props, cloneMarkup("toast", <div class="toast show" role="status" aria-live="polite"><div class="toast-header"></div><div class="toast-body"></div></div>))
|
|
24
|
+
@closed = false
|
|
25
|
+
@timer = null
|
|
26
|
+
@scope = new Form(form.app, form, form.token)
|
|
27
|
+
@scope.presentation = @this
|
|
28
|
+
@scope.inheritThrough = true
|
|
29
|
+
@scope.element = @element
|
|
30
|
+
try
|
|
31
|
+
header = @element.firstElementChild
|
|
32
|
+
appendContent(@scope, header, props.header, renderer)
|
|
33
|
+
button = closeButton()
|
|
34
|
+
header.appendChild(button)
|
|
35
|
+
appendContent(@scope, @element.lastElementChild, props.body, renderer)
|
|
36
|
+
if props.theme != null
|
|
37
|
+
@element.classList.add("text-bg-${props.theme.toLowerCase()}")
|
|
38
|
+
if props.translucent == false
|
|
39
|
+
@element.style.setProperty("--bs-toast-bg", "var(--bs-body-bg)")
|
|
40
|
+
@element.style.setProperty("--bs-bg-opacity", "1")
|
|
41
|
+
if props.translucent == true
|
|
42
|
+
@element.style.setProperty("--bs-bg-opacity", ".85")
|
|
43
|
+
listener = ()
|
|
44
|
+
close()
|
|
45
|
+
button.addEventListener("click", listener)
|
|
46
|
+
release = ()
|
|
47
|
+
capture button
|
|
48
|
+
capture listener
|
|
49
|
+
button.removeEventListener("click", listener)
|
|
50
|
+
@release.add(release)
|
|
51
|
+
if props.instant == true
|
|
52
|
+
action = ()
|
|
53
|
+
close()
|
|
54
|
+
@timer = form.app.schedule(action, 5000)
|
|
55
|
+
catch error
|
|
56
|
+
dispose()
|
|
57
|
+
throw error
|
|
58
|
+
|
|
59
|
+
Toast:find(name)
|
|
60
|
+
return @scope.find(name)
|
|
61
|
+
|
|
62
|
+
Toast:close()
|
|
63
|
+
dispose()
|
|
64
|
+
return null
|
|
65
|
+
|
|
66
|
+
Toast:dispose()
|
|
67
|
+
if !@closed
|
|
68
|
+
@closed = true
|
|
69
|
+
if @timer != null
|
|
70
|
+
@form.app.cancelTimer(@timer)
|
|
71
|
+
@timer = null
|
|
72
|
+
@scope.dispose()
|
|
73
|
+
@form.unregister(@this)
|
|
74
|
+
super.dispose()
|
|
75
|
+
@element.remove()
|
|
76
|
+
return null
|
|
77
|
+
|
|
78
|
+
export class ToastStack(form, props, renderer) : Control
|
|
79
|
+
methods
|
|
80
|
+
add(props, token)
|
|
81
|
+
find(name)
|
|
82
|
+
dispose()
|
|
83
|
+
|
|
84
|
+
ToastStack(form, props, renderer)
|
|
85
|
+
super(form, props, cloneMarkup("toast-stack", <div class="toast-container lango-toast-stack"></div>))
|
|
86
|
+
@renderer = renderer
|
|
87
|
+
@scope = new Form(form.app, form, form.token)
|
|
88
|
+
@scope.inheritThrough = true
|
|
89
|
+
@scope.element = @element
|
|
90
|
+
@closed = false
|
|
91
|
+
try
|
|
92
|
+
if props.toasts != null
|
|
93
|
+
for props.toasts as toast
|
|
94
|
+
add(toast, form.token)
|
|
95
|
+
catch error
|
|
96
|
+
dispose()
|
|
97
|
+
throw error
|
|
98
|
+
|
|
99
|
+
ToastStack:add(props, token)
|
|
100
|
+
@scope.token = token
|
|
101
|
+
return mountToast(@scope, props, @element, @renderer)
|
|
102
|
+
|
|
103
|
+
ToastStack:find(name)
|
|
104
|
+
return @scope.find(name)
|
|
105
|
+
|
|
106
|
+
ToastStack:dispose()
|
|
107
|
+
if !@closed
|
|
108
|
+
@closed = true
|
|
109
|
+
@scope.dispose()
|
|
110
|
+
@form.unregister(@this)
|
|
111
|
+
super.dispose()
|
|
112
|
+
@element.remove()
|
|
113
|
+
return null
|
|
114
|
+
|
|
115
|
+
export class Dialog(owner, props, renderer, manager, source) : Form
|
|
116
|
+
properties
|
|
117
|
+
owner
|
|
118
|
+
name
|
|
119
|
+
modal
|
|
120
|
+
methods
|
|
121
|
+
open()
|
|
122
|
+
bind()
|
|
123
|
+
hide()
|
|
124
|
+
focusSaved()
|
|
125
|
+
userClose()
|
|
126
|
+
dispose()
|
|
127
|
+
|
|
128
|
+
Dialog(owner, props, renderer, manager, source)
|
|
129
|
+
super(owner.app, owner, source.token)
|
|
130
|
+
@owner = owner
|
|
131
|
+
@presentation = @this
|
|
132
|
+
@manager = manager
|
|
133
|
+
@name = props.name
|
|
134
|
+
if @name == null and is_object(props.body) and props.body.type == "form"
|
|
135
|
+
@name = props.body.name
|
|
136
|
+
@modal = cloneMarkup("dialog", <dialog class="lango-dialog" tabindex="-1"><div class="modal-content"><div class="modal-header"><h2 class="modal-title fs-5"></h2></div><div class="lango-dialog-content"></div></div></dialog>)
|
|
137
|
+
@element = @modal.querySelector(".lango-dialog-content")
|
|
138
|
+
@listeners = []
|
|
139
|
+
@focus = null
|
|
140
|
+
@closing = false
|
|
141
|
+
@closeUrl = props.closeUrl
|
|
142
|
+
try
|
|
143
|
+
if @closeUrl != null
|
|
144
|
+
owner.app.checkUrl(@closeUrl)
|
|
145
|
+
checkName(@name)
|
|
146
|
+
heading = @modal.querySelector(".modal-title")
|
|
147
|
+
heading.id = controlId()
|
|
148
|
+
heading.textContent = titleText(props.title)
|
|
149
|
+
@modal.setAttribute("aria-labelledby", heading.id)
|
|
150
|
+
@button = closeButton()
|
|
151
|
+
@modal.querySelector(".modal-header").appendChild(@button)
|
|
152
|
+
body = document/createElement("div")
|
|
153
|
+
body.className = "modal-body"
|
|
154
|
+
@element.appendChild(body)
|
|
155
|
+
if is_object(props.body) and props.body.type == "form"
|
|
156
|
+
@inheritedNames = props.body.inheritedNames
|
|
157
|
+
if @inheritedNames == null
|
|
158
|
+
@inheritedNames = []
|
|
159
|
+
for props.body.controls as control
|
|
160
|
+
body.appendChild(renderer.build(@this, control))
|
|
161
|
+
else
|
|
162
|
+
appendContent(@this, body, props.body, renderer)
|
|
163
|
+
if props.footer != null
|
|
164
|
+
footer = document/createElement("div")
|
|
165
|
+
footer.className = "modal-footer"
|
|
166
|
+
appendContent(@this, footer, props.footer, renderer)
|
|
167
|
+
@element.appendChild(footer)
|
|
168
|
+
if props.dark == true
|
|
169
|
+
@modal.setAttribute("data-bs-theme", "dark")
|
|
170
|
+
if props.blur == true
|
|
171
|
+
@modal.classList.add("lango-dialog-blur")
|
|
172
|
+
if props.scrollable == true
|
|
173
|
+
@modal.classList.add("lango-dialog-scrollable")
|
|
174
|
+
if props.size != null
|
|
175
|
+
sizes = ["sm", "lg", "xl", "fullscreen"]
|
|
176
|
+
if !sizes.includes(props.size)
|
|
177
|
+
throw "Unsupported dialog size"
|
|
178
|
+
@modal.classList.add("lango-dialog-${props.size}")
|
|
179
|
+
cancel = (event)
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
userClose()
|
|
182
|
+
click = ()
|
|
183
|
+
userClose()
|
|
184
|
+
focused = (event)
|
|
185
|
+
@focus = event.target
|
|
186
|
+
return @focus
|
|
187
|
+
@modal.addEventListener("cancel", cancel)
|
|
188
|
+
@button.addEventListener("click", click)
|
|
189
|
+
@modal.addEventListener("focusin", focused)
|
|
190
|
+
@listeners = [cancel, click, focused]
|
|
191
|
+
catch error
|
|
192
|
+
dispose()
|
|
193
|
+
throw error
|
|
194
|
+
|
|
195
|
+
Dialog:open()
|
|
196
|
+
saved = @focus
|
|
197
|
+
if !@modal.isConnected
|
|
198
|
+
document/body/appendChild(@modal)
|
|
199
|
+
if !@modal.open
|
|
200
|
+
@modal.showModal()
|
|
201
|
+
if saved != null and @modal.contains(saved)
|
|
202
|
+
@focus = saved
|
|
203
|
+
focusSaved()
|
|
204
|
+
return null
|
|
205
|
+
|
|
206
|
+
Dialog:bind()
|
|
207
|
+
controls = @owner.controls
|
|
208
|
+
if !@owner.owned.includes(@this)
|
|
209
|
+
@owner.register(@name, @this)
|
|
210
|
+
else
|
|
211
|
+
if @name != null
|
|
212
|
+
existing = controls[@name]
|
|
213
|
+
if existing != null and existing != @this
|
|
214
|
+
throw "Duplicate dialog name: ${@name}"
|
|
215
|
+
controls[@name] = @this
|
|
216
|
+
return null
|
|
217
|
+
|
|
218
|
+
Dialog:hide()
|
|
219
|
+
controls = @owner.controls
|
|
220
|
+
for Object/keys(controls) as name
|
|
221
|
+
if controls[name] == @this
|
|
222
|
+
Reflect/deleteProperty(controls, name)
|
|
223
|
+
if @modal.open
|
|
224
|
+
@modal.close()
|
|
225
|
+
return null
|
|
226
|
+
|
|
227
|
+
Dialog:focusSaved()
|
|
228
|
+
if @focus != null and @modal.contains(@focus)
|
|
229
|
+
@focus.focus()
|
|
230
|
+
else
|
|
231
|
+
@modal.focus()
|
|
232
|
+
return null
|
|
233
|
+
|
|
234
|
+
Dialog:userClose()
|
|
235
|
+
if @disposed or @closing
|
|
236
|
+
return null
|
|
237
|
+
if @closeUrl == null
|
|
238
|
+
@manager.closeSpecific(@this)
|
|
239
|
+
return null
|
|
240
|
+
@closing = true
|
|
241
|
+
@button.disabled = true
|
|
242
|
+
return chain send(@closeUrl)
|
|
243
|
+
then(ignored)
|
|
244
|
+
if !@disposed
|
|
245
|
+
@manager.closeSpecific(@this)
|
|
246
|
+
catch(error)
|
|
247
|
+
if !@disposed
|
|
248
|
+
@app.error(@this, error, "DialogCloseFailed")
|
|
249
|
+
finally
|
|
250
|
+
@closing = false
|
|
251
|
+
@button.disabled = false
|
|
252
|
+
|
|
253
|
+
Dialog:dispose()
|
|
254
|
+
if @disposed
|
|
255
|
+
return null
|
|
256
|
+
hide()
|
|
257
|
+
if @listeners.length > 0
|
|
258
|
+
@modal.removeEventListener("cancel", @listeners[0])
|
|
259
|
+
@button.removeEventListener("click", @listeners[1])
|
|
260
|
+
@modal.removeEventListener("focusin", @listeners[2])
|
|
261
|
+
@owner.unregister(@this)
|
|
262
|
+
@manager.forgetDialog(@this)
|
|
263
|
+
super.dispose()
|
|
264
|
+
@modal.remove()
|
|
265
|
+
return null
|
|
266
|
+
|
|
267
|
+
export class Presentations(renderer)
|
|
268
|
+
methods
|
|
269
|
+
showAlert(form, command)
|
|
270
|
+
dismissAlert(form, name)
|
|
271
|
+
showToast(form, props, stack = null)
|
|
272
|
+
showDialog(form, props, keepPrev = false)
|
|
273
|
+
swapDialog(form)
|
|
274
|
+
closeSpecific(dialog)
|
|
275
|
+
forgetDialog(dialog)
|
|
276
|
+
forgetRegion(region)
|
|
277
|
+
dismiss(form)
|
|
278
|
+
slot(owner, create = true)
|
|
279
|
+
|
|
280
|
+
Presentations(renderer)
|
|
281
|
+
@renderer = renderer
|
|
282
|
+
@slots = []
|
|
283
|
+
@regions = []
|
|
284
|
+
|
|
285
|
+
Presentations:showAlert(form, command)
|
|
286
|
+
checkName(command.name)
|
|
287
|
+
parent = form.element
|
|
288
|
+
anchor = null
|
|
289
|
+
position = "inside"
|
|
290
|
+
lifetime = form
|
|
291
|
+
if command.place != null
|
|
292
|
+
place = command.place
|
|
293
|
+
positions = ["before", "after", "inside"]
|
|
294
|
+
if !is_object(place) or !is_string(place.name) or !positions.includes(place.position)
|
|
295
|
+
throw "Alert place requires name and position"
|
|
296
|
+
target = form.find(place.name)
|
|
297
|
+
anchor = target.element
|
|
298
|
+
position = place.position
|
|
299
|
+
if is_kindof(target, Form)
|
|
300
|
+
lifetime = target
|
|
301
|
+
if position != "inside" and target.parent != null
|
|
302
|
+
lifetime = target.parent
|
|
303
|
+
else
|
|
304
|
+
if target.form != null
|
|
305
|
+
lifetime = target.form
|
|
306
|
+
if position == "inside"
|
|
307
|
+
parent = anchor
|
|
308
|
+
else
|
|
309
|
+
parent = anchor.parentElement
|
|
310
|
+
if parent == null
|
|
311
|
+
throw "Alert target is not mounted"
|
|
312
|
+
old = null
|
|
313
|
+
controls = form.controls
|
|
314
|
+
name = command.name
|
|
315
|
+
if command.name != null
|
|
316
|
+
old = controls[name]
|
|
317
|
+
if old != null and !is_kindof(old, Alert)
|
|
318
|
+
throw "Alert name belongs to another control"
|
|
319
|
+
if old != null and anchor == old.element and position == "inside"
|
|
320
|
+
throw "Alert cannot be placed inside itself"
|
|
321
|
+
if old != null and anchor != null and anchor != old.element and old.element.contains(anchor)
|
|
322
|
+
throw "Replacement Alert target is inside its previous content"
|
|
323
|
+
previous = form.controls
|
|
324
|
+
owned = form.owned
|
|
325
|
+
staged = Object/assign(Object/create(null), previous)
|
|
326
|
+
if old != null
|
|
327
|
+
removed = old.contentControls()
|
|
328
|
+
removed.add(old)
|
|
329
|
+
for Object/keys(staged) as key
|
|
330
|
+
if removed.includes(staged[key])
|
|
331
|
+
Reflect/deleteProperty(staged, key)
|
|
332
|
+
form.controls = staged
|
|
333
|
+
form.owned = []
|
|
334
|
+
alert = null
|
|
335
|
+
try
|
|
336
|
+
alert = new Alert(form, command, @renderer)
|
|
337
|
+
form.register(command.name, alert)
|
|
338
|
+
alert.attach(lifetime)
|
|
339
|
+
if position == "before"
|
|
340
|
+
parent.insertBefore(alert.element, anchor)
|
|
341
|
+
else
|
|
342
|
+
if position == "after"
|
|
343
|
+
parent.insertBefore(alert.element, anchor.nextSibling)
|
|
344
|
+
else
|
|
345
|
+
parent.prepend(alert.element)
|
|
346
|
+
catch error
|
|
347
|
+
for form.owned.slice() as child
|
|
348
|
+
child.dispose()
|
|
349
|
+
form.controls = previous
|
|
350
|
+
form.owned = owned
|
|
351
|
+
throw error
|
|
352
|
+
children = form.owned
|
|
353
|
+
form.owned = owned
|
|
354
|
+
if old != null
|
|
355
|
+
old.close()
|
|
356
|
+
for children as child
|
|
357
|
+
form.owned.add(child)
|
|
358
|
+
return null
|
|
359
|
+
|
|
360
|
+
Presentations:dismissAlert(form, name)
|
|
361
|
+
control = null
|
|
362
|
+
try
|
|
363
|
+
control = form.find(name)
|
|
364
|
+
catch error
|
|
365
|
+
if is_string(error) and error.startsWith("Unknown control:")
|
|
366
|
+
return null
|
|
367
|
+
throw error
|
|
368
|
+
if !is_kindof(control, Alert)
|
|
369
|
+
throw "DismissAlert requires an Alert"
|
|
370
|
+
control.close()
|
|
371
|
+
return null
|
|
372
|
+
|
|
373
|
+
Presentations:showToast(form, props, stack = null)
|
|
374
|
+
if !is_object(props) or props.type != "toast"
|
|
375
|
+
throw "ShowToast requires a Toast definition"
|
|
376
|
+
checkName(props.name)
|
|
377
|
+
if stack != null
|
|
378
|
+
target = form.find(stack)
|
|
379
|
+
if !is_kindof(target, ToastStack)
|
|
380
|
+
throw "ShowToast requires a ToastStack"
|
|
381
|
+
target.add(props, form.token)
|
|
382
|
+
return null
|
|
383
|
+
position = props.position
|
|
384
|
+
if position == null
|
|
385
|
+
position = "bottom-right"
|
|
386
|
+
positions = ["top-left", "top-center", "top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", "bottom-right"]
|
|
387
|
+
if !positions.includes(position)
|
|
388
|
+
throw "Unsupported toast position"
|
|
389
|
+
region = null
|
|
390
|
+
created = false
|
|
391
|
+
for @regions as current
|
|
392
|
+
if current.form == form and current.element.isConnected and current.position == position
|
|
393
|
+
region = current
|
|
394
|
+
if region == null
|
|
395
|
+
region = new ToastRegion(form, position, @this)
|
|
396
|
+
@regions.add(region)
|
|
397
|
+
form.register(null, region)
|
|
398
|
+
form.element.appendChild(region.element)
|
|
399
|
+
created = true
|
|
400
|
+
try
|
|
401
|
+
mountToast(form, props, region.element, @renderer)
|
|
402
|
+
catch error
|
|
403
|
+
if created
|
|
404
|
+
region.dispose()
|
|
405
|
+
throw error
|
|
406
|
+
return null
|
|
407
|
+
|
|
408
|
+
Presentations:slot(owner, create = true)
|
|
409
|
+
for @slots as current
|
|
410
|
+
if current.owner == owner
|
|
411
|
+
return current
|
|
412
|
+
if !create
|
|
413
|
+
return null
|
|
414
|
+
result = {
|
|
415
|
+
owner: owner
|
|
416
|
+
current: null
|
|
417
|
+
previous: null
|
|
418
|
+
}
|
|
419
|
+
@slots.add(result)
|
|
420
|
+
return result
|
|
421
|
+
|
|
422
|
+
Presentations:showDialog(form, props, keepPrev = false)
|
|
423
|
+
if keepPrev == null
|
|
424
|
+
keepPrev = false
|
|
425
|
+
if !is_bool(keepPrev)
|
|
426
|
+
throw "Dialog keepPrev must be boolean"
|
|
427
|
+
if props == null
|
|
428
|
+
current = containingDialog(form)
|
|
429
|
+
if current == null
|
|
430
|
+
existingSlot = slot(form, false)
|
|
431
|
+
if existingSlot != null
|
|
432
|
+
current = existingSlot.current
|
|
433
|
+
if current != null
|
|
434
|
+
closeSpecific(current)
|
|
435
|
+
return null
|
|
436
|
+
if !is_object(props) or props.type != "dialog"
|
|
437
|
+
throw "ShowDialog requires a Dialog definition"
|
|
438
|
+
owner = form
|
|
439
|
+
containing = containingDialog(form)
|
|
440
|
+
if containing != null
|
|
441
|
+
owner = containing.owner
|
|
442
|
+
currentSlot = slot(owner)
|
|
443
|
+
candidate = new Dialog(owner, props, @renderer, @this, form)
|
|
444
|
+
existing = null
|
|
445
|
+
controls = owner.controls
|
|
446
|
+
name = candidate.name
|
|
447
|
+
if candidate.name != null
|
|
448
|
+
existing = controls[name]
|
|
449
|
+
if existing != null and existing != currentSlot.current
|
|
450
|
+
candidate.dispose()
|
|
451
|
+
throw "Dialog name belongs to another control"
|
|
452
|
+
try
|
|
453
|
+
candidate.open()
|
|
454
|
+
catch error
|
|
455
|
+
candidate.dispose()
|
|
456
|
+
throw error
|
|
457
|
+
old = currentSlot.current
|
|
458
|
+
previous = currentSlot.previous
|
|
459
|
+
if old != null
|
|
460
|
+
old.hide()
|
|
461
|
+
candidate.bind()
|
|
462
|
+
currentSlot.current = candidate
|
|
463
|
+
currentSlot.previous = null
|
|
464
|
+
if keepPrev
|
|
465
|
+
currentSlot.previous = old
|
|
466
|
+
else
|
|
467
|
+
if old != null
|
|
468
|
+
old.dispose()
|
|
469
|
+
if previous != null and previous != old
|
|
470
|
+
previous.dispose()
|
|
471
|
+
candidate.focusSaved()
|
|
472
|
+
return null
|
|
473
|
+
|
|
474
|
+
Presentations:swapDialog(form)
|
|
475
|
+
owner = form
|
|
476
|
+
containing = containingDialog(form)
|
|
477
|
+
if containing != null
|
|
478
|
+
owner = containing.owner
|
|
479
|
+
currentSlot = slot(owner, false)
|
|
480
|
+
if currentSlot == null
|
|
481
|
+
return null
|
|
482
|
+
current = currentSlot.current
|
|
483
|
+
previous = currentSlot.previous
|
|
484
|
+
if current == null or previous == null
|
|
485
|
+
return null
|
|
486
|
+
checkAlias(previous, current)
|
|
487
|
+
current.hide()
|
|
488
|
+
previous.open()
|
|
489
|
+
previous.bind()
|
|
490
|
+
currentSlot.current = previous
|
|
491
|
+
currentSlot.previous = current
|
|
492
|
+
return null
|
|
493
|
+
|
|
494
|
+
Presentations:closeSpecific(dialog)
|
|
495
|
+
currentSlot = slot(dialog.owner, false)
|
|
496
|
+
if currentSlot == null
|
|
497
|
+
dialog.dispose()
|
|
498
|
+
return null
|
|
499
|
+
restore = null
|
|
500
|
+
if currentSlot.current == dialog
|
|
501
|
+
restore = currentSlot.previous
|
|
502
|
+
if restore != null
|
|
503
|
+
checkAlias(restore, dialog)
|
|
504
|
+
currentSlot.current = restore
|
|
505
|
+
currentSlot.previous = null
|
|
506
|
+
if currentSlot.previous == dialog
|
|
507
|
+
currentSlot.previous = null
|
|
508
|
+
dialog.dispose()
|
|
509
|
+
if restore != null and !restore.disposed
|
|
510
|
+
restore.open()
|
|
511
|
+
restore.bind()
|
|
512
|
+
return null
|
|
513
|
+
|
|
514
|
+
Presentations:forgetDialog(dialog)
|
|
515
|
+
for @slots.slice() as current
|
|
516
|
+
if current.current == dialog
|
|
517
|
+
current.current = null
|
|
518
|
+
if current.previous == dialog
|
|
519
|
+
current.previous = null
|
|
520
|
+
if current.current == null and current.previous == null
|
|
521
|
+
@slots.splice(@slots.indexOf(current), 1)
|
|
522
|
+
return null
|
|
523
|
+
|
|
524
|
+
Presentations:forgetRegion(region)
|
|
525
|
+
index = @regions.indexOf(region)
|
|
526
|
+
if index >= 0
|
|
527
|
+
@regions.splice(index, 1)
|
|
528
|
+
return null
|
|
529
|
+
|
|
530
|
+
Presentations:dismiss(form)
|
|
531
|
+
current = form
|
|
532
|
+
loop while current != null
|
|
533
|
+
presentation = current.presentation
|
|
534
|
+
if presentation != null
|
|
535
|
+
if is_kindof(presentation, Dialog)
|
|
536
|
+
return presentation.userClose()
|
|
537
|
+
if is_kindof(presentation, Toast)
|
|
538
|
+
presentation.close()
|
|
539
|
+
return null
|
|
540
|
+
current = current.parent
|
|
541
|
+
return null
|
|
542
|
+
|
|
543
|
+
class ToastRegion(form, position, manager) : Control
|
|
544
|
+
properties
|
|
545
|
+
position
|
|
546
|
+
methods
|
|
547
|
+
dispose()
|
|
548
|
+
|
|
549
|
+
ToastRegion(form, position, manager)
|
|
550
|
+
super(form, {}, cloneMarkup("toast-region", <div class="toast-container lango-toast-region"></div>))
|
|
551
|
+
@position = position
|
|
552
|
+
@manager = manager
|
|
553
|
+
@element.setAttribute("data-position", position)
|
|
554
|
+
|
|
555
|
+
ToastRegion:dispose()
|
|
556
|
+
@form.unregister(@this)
|
|
557
|
+
@manager.forgetRegion(@this)
|
|
558
|
+
super.dispose()
|
|
559
|
+
@element.remove()
|
|
560
|
+
return null
|
|
561
|
+
|
|
562
|
+
mountToast(form, props, parent, renderer)
|
|
563
|
+
if !is_object(props) or props.type != "toast"
|
|
564
|
+
throw "ShowToast requires a Toast definition"
|
|
565
|
+
checkName(props.name)
|
|
566
|
+
old = null
|
|
567
|
+
controls = form.controls
|
|
568
|
+
name = props.name
|
|
569
|
+
if props.name != null
|
|
570
|
+
old = controls[name]
|
|
571
|
+
if old != null and !is_kindof(old, Toast)
|
|
572
|
+
throw "Toast name belongs to another control"
|
|
573
|
+
toast = new Toast(form, props, renderer)
|
|
574
|
+
if old != null
|
|
575
|
+
old.close()
|
|
576
|
+
form.register(props.name, toast)
|
|
577
|
+
parent.appendChild(toast.element)
|
|
578
|
+
return toast
|
|
579
|
+
|
|
580
|
+
titleText(value)
|
|
581
|
+
if value == null
|
|
582
|
+
return ""
|
|
583
|
+
if is_object(value) and value.type == "text"
|
|
584
|
+
return value.text
|
|
585
|
+
if !is_string(value)
|
|
586
|
+
throw "Dialog title must be text"
|
|
587
|
+
return value
|
|
588
|
+
|
|
589
|
+
closeButton()
|
|
590
|
+
button = document/createElement("button")
|
|
591
|
+
button.type = "button"
|
|
592
|
+
button.className = "btn-close"
|
|
593
|
+
button.setAttribute("aria-label", "×")
|
|
594
|
+
return button
|
|
595
|
+
|
|
596
|
+
containingDialog(form)
|
|
597
|
+
current = form
|
|
598
|
+
loop while current != null
|
|
599
|
+
if is_kindof(current, Dialog)
|
|
600
|
+
return current
|
|
601
|
+
current = current.parent
|
|
602
|
+
return null
|
|
603
|
+
|
|
604
|
+
checkName(name)
|
|
605
|
+
if name != null and (!is_string(name) or name.trim() == "" or name.includes("/"))
|
|
606
|
+
throw "Presentation name must be a single name segment"
|
|
607
|
+
return null
|
|
608
|
+
|
|
609
|
+
checkAlias(dialog, permitted)
|
|
610
|
+
if dialog.name == null
|
|
611
|
+
return null
|
|
612
|
+
controls = dialog.owner.controls
|
|
613
|
+
name = dialog.name
|
|
614
|
+
current = controls[name]
|
|
615
|
+
if current != null and current != permitted and current != dialog
|
|
616
|
+
throw "Dialog name belongs to another control"
|
|
617
|
+
return null
|