@lango-project/lango-client 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/NOTICE +5 -1
- package/README.md +570 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +112 -19
- 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 +112 -19
- 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 +636 -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 +95 -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 +139 -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/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 +138 -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 +293 -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/tables.mjs +369 -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 +2540 -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 +42 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +508 -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 +100 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -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 +109 -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 +288 -0
- package/src/rich_content.lango +66 -0
- package/src/tables.lango +271 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +95 -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/navigation.lango
CHANGED
|
@@ -1,309 +1,219 @@
|
|
|
1
|
-
import js global
|
|
1
|
+
import js global document
|
|
2
2
|
import js global URL
|
|
3
|
-
import js global
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import js global ResizeObserver
|
|
4
|
+
import js global RegExp
|
|
5
|
+
import "./control"
|
|
6
|
+
class Control
|
|
7
|
+
import "./templates"
|
|
8
|
+
cloneMarkup(name, xml)
|
|
9
|
+
import "./content"
|
|
10
|
+
appendContent(form, element, content, renderer)
|
|
11
|
+
decorate(control, props)
|
|
12
|
+
|
|
13
|
+
export navigationMatch(url, current)
|
|
14
|
+
|
|
15
|
+
navigationMatch(url, current)
|
|
16
|
+
target = new URL(url, current)
|
|
17
|
+
location = new URL(current)
|
|
18
|
+
if target.origin != location.origin
|
|
19
|
+
return -1
|
|
20
|
+
path = target.pathname
|
|
21
|
+
if path == location.pathname
|
|
22
|
+
return path.length
|
|
23
|
+
if path != "/" and location.pathname.startsWith("${path.replace(new RegExp("/+$"), "")}/")
|
|
24
|
+
return path.length
|
|
25
|
+
return -1
|
|
26
|
+
|
|
27
|
+
export class Nav(form, props, renderer, navigationBar = false) : Control
|
|
8
28
|
methods
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if !canNavigate(path, "navigate")
|
|
97
|
-
return Promise/resolve(false)
|
|
98
|
-
return notify("navigate")
|
|
99
|
-
return Promise/resolve(null)
|
|
100
|
-
if !canNavigate(path, "navigate")
|
|
101
|
-
return Promise/resolve(false)
|
|
102
|
-
if replace
|
|
103
|
-
@window.history.replaceState(historyState(@position, path), "", path)
|
|
104
|
-
else
|
|
105
|
-
@position++
|
|
106
|
-
@window.history.pushState(historyState(@position, path), "", path)
|
|
107
|
-
return notify("navigate")
|
|
108
|
-
|
|
109
|
-
Navigation:canNavigate(path, source)
|
|
110
|
-
if @guard == null
|
|
111
|
-
return true
|
|
112
|
-
callback = @guard
|
|
113
|
-
result = callback({
|
|
114
|
-
url: path
|
|
115
|
-
source: source
|
|
116
|
-
})
|
|
117
|
-
if !is_bool(result)
|
|
118
|
-
if result != null and is_kindof(result.then, Function)
|
|
119
|
-
recovered(Promise/resolve(result))
|
|
120
|
-
throw "UiNavigationGuardMustReturnBoolean"
|
|
121
|
-
return result
|
|
122
|
-
|
|
123
|
-
Navigation:historyState(position, path)
|
|
124
|
-
result = {
|
|
125
|
-
}
|
|
126
|
-
previous = @window.history.state
|
|
127
|
-
if is_object(previous) and !is_array(previous)
|
|
128
|
-
for previous as name: value
|
|
129
|
-
result[name] = value
|
|
130
|
-
else
|
|
131
|
-
if previous != null
|
|
132
|
-
result.previousState = previous
|
|
133
|
-
result["__langoNavigation"] = {
|
|
134
|
-
owner: @owner
|
|
135
|
-
index: position
|
|
136
|
-
url: path
|
|
137
|
-
}
|
|
138
|
-
return result
|
|
139
|
-
|
|
140
|
-
Navigation:historyEvent(source)
|
|
141
|
-
try
|
|
142
|
-
moveHistory(source)
|
|
143
|
-
catch error
|
|
144
|
-
report(error)
|
|
145
|
-
return null
|
|
146
|
-
|
|
147
|
-
Navigation:moveHistory(source)
|
|
148
|
-
path = localUrl(@window.location)
|
|
149
|
-
state = @window.history.state
|
|
150
|
-
marker = null
|
|
151
|
-
if state != null
|
|
152
|
-
marker = state["__langoNavigation"]
|
|
153
|
-
if @restoring
|
|
154
|
-
if path == @url and marker != null and marker.owner == @owner and marker.index == @position
|
|
155
|
-
@restoring = false
|
|
156
|
-
return null
|
|
157
|
-
if path == @url
|
|
158
|
-
if marker != null and marker.owner == @owner
|
|
159
|
-
@position = marker.index
|
|
160
|
-
return null
|
|
161
|
-
position = @position + 1
|
|
162
|
-
if marker != null and marker.owner == @owner and marker.url == path
|
|
163
|
-
position = marker.index
|
|
164
|
-
allowed = false
|
|
165
|
-
try
|
|
166
|
-
allowed = canNavigate(path, source)
|
|
167
|
-
catch error
|
|
168
|
-
restoreHistory(position)
|
|
169
|
-
throw error
|
|
170
|
-
if !allowed
|
|
171
|
-
restoreHistory(position)
|
|
172
|
-
return null
|
|
173
|
-
@position = position
|
|
174
|
-
@window.history.replaceState(historyState(position, path), "", path)
|
|
175
|
-
observe(notify(source))
|
|
176
|
-
return null
|
|
177
|
-
|
|
178
|
-
Navigation:restoreHistory(position)
|
|
179
|
-
if position == @position
|
|
180
|
-
@window.history.replaceState(historyState(@position, @url), "", @url)
|
|
181
|
-
return null
|
|
182
|
-
@restoring = true
|
|
183
|
-
@window.history.go(@position - position)
|
|
29
|
+
locationChanged(url)
|
|
30
|
+
fit()
|
|
31
|
+
|
|
32
|
+
Nav(form, props, renderer, navigationBar = false)
|
|
33
|
+
super(form, props, cloneMarkup("nav", <nav class="nav lango-nav"></nav>))
|
|
34
|
+
@items = []
|
|
35
|
+
@overflow = props.overflow != null
|
|
36
|
+
@url = form.app.hostUrl()
|
|
37
|
+
if navigationBar
|
|
38
|
+
@element.classList.add("navbar")
|
|
39
|
+
if props.brand != null
|
|
40
|
+
brand = document/createElement("div")
|
|
41
|
+
brand.className = "navbar-brand"
|
|
42
|
+
appendContent(form, brand, props.brand, renderer)
|
|
43
|
+
@element.appendChild(brand)
|
|
44
|
+
switch props.alignment
|
|
45
|
+
case "center"
|
|
46
|
+
@element.classList.add("justify-content-center")
|
|
47
|
+
case "end"
|
|
48
|
+
@element.classList.add("justify-content-end")
|
|
49
|
+
case "vertical"
|
|
50
|
+
@element.classList.add("flex-column")
|
|
51
|
+
case "fill"
|
|
52
|
+
@element.classList.add("nav-fill")
|
|
53
|
+
placement = null
|
|
54
|
+
if props.items != null
|
|
55
|
+
for props.items as definition
|
|
56
|
+
if definition.type != "navItem" and definition.type != "navBarItem"
|
|
57
|
+
throw "Nav accepts NavItem definitions"
|
|
58
|
+
item = new NavItem(form, definition, renderer)
|
|
59
|
+
form.register(definition.name, item)
|
|
60
|
+
@items.add(item)
|
|
61
|
+
@element.appendChild(item.element)
|
|
62
|
+
if definition.placement != null
|
|
63
|
+
if placement != null and placement != definition.placement
|
|
64
|
+
throw "Navbar items must agree on placement"
|
|
65
|
+
placement = definition.placement
|
|
66
|
+
switch definition.placement
|
|
67
|
+
case "fixed-top"
|
|
68
|
+
case "fixed-bottom"
|
|
69
|
+
case "sticky-top"
|
|
70
|
+
case "sticky-bottom"
|
|
71
|
+
@element.classList.add(definition.placement)
|
|
72
|
+
else
|
|
73
|
+
throw "Unknown navbar placement: ${definition.placement}"
|
|
74
|
+
locationChanged(@url)
|
|
75
|
+
groups = renderer.navigation
|
|
76
|
+
groups.add(@this)
|
|
77
|
+
release = ()
|
|
78
|
+
capture groups
|
|
79
|
+
index = groups.indexOf(@this)
|
|
80
|
+
if index >= 0
|
|
81
|
+
groups.splice(index, 1)
|
|
82
|
+
@release.add(release)
|
|
83
|
+
if @overflow
|
|
84
|
+
observer = new ResizeObserver(()
|
|
85
|
+
fit()
|
|
86
|
+
)
|
|
87
|
+
observer.observe(@element)
|
|
88
|
+
stop = ()
|
|
89
|
+
capture observer
|
|
90
|
+
observer.disconnect()
|
|
91
|
+
@release.add(stop)
|
|
92
|
+
|
|
93
|
+
export class NavBar(form, props, renderer) : Nav
|
|
94
|
+
|
|
95
|
+
NavBar(form, props, renderer)
|
|
96
|
+
super(form, props, renderer, true)
|
|
97
|
+
|
|
98
|
+
Nav:locationChanged(url)
|
|
99
|
+
best = -1
|
|
100
|
+
selected = null
|
|
101
|
+
for @items as item
|
|
102
|
+
if item.url != null
|
|
103
|
+
score = navigationMatch(item.url, url)
|
|
104
|
+
if score > best
|
|
105
|
+
best = score
|
|
106
|
+
selected = item
|
|
107
|
+
for @items as item
|
|
108
|
+
active = item.initial
|
|
109
|
+
if item.url != null
|
|
110
|
+
active = item == selected
|
|
111
|
+
item.element.classList.toggle("active", active)
|
|
112
|
+
if active
|
|
113
|
+
item.element.setAttribute("aria-current", "page")
|
|
114
|
+
else
|
|
115
|
+
item.element.removeAttribute("aria-current")
|
|
184
116
|
return null
|
|
185
117
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
@url = path
|
|
191
|
-
if path == @last
|
|
192
|
-
return Promise/resolve(null)
|
|
193
|
-
@last = path
|
|
194
|
-
work = deliver(@tail, {
|
|
195
|
-
url: path
|
|
196
|
-
source: source
|
|
197
|
-
})
|
|
198
|
-
@tail = recovered(work)
|
|
199
|
-
return work
|
|
200
|
-
|
|
201
|
-
Navigation:refresh()
|
|
202
|
-
if @disposed
|
|
203
|
-
throw "UiNavigationDisposed"
|
|
204
|
-
if !@started
|
|
205
|
-
throw "UiNavigationNotStarted"
|
|
206
|
-
if @restoring
|
|
207
|
-
throw "UiNavigationRestoringHistory"
|
|
208
|
-
if !canNavigate(localUrl(@window.location), "refresh")
|
|
209
|
-
return Promise/resolve(false)
|
|
210
|
-
@last = null
|
|
211
|
-
return notify("refresh")
|
|
212
|
-
|
|
213
|
-
Navigation:deliver(ready, event)
|
|
214
|
-
return ready.then(()
|
|
215
|
-
capture event
|
|
216
|
-
if @disposed
|
|
217
|
-
return null
|
|
218
|
-
callback = @onUrl
|
|
219
|
-
return callback(event)
|
|
220
|
-
).catch((error)
|
|
221
|
-
capture event
|
|
222
|
-
if @last == event.url
|
|
223
|
-
@last = null
|
|
224
|
-
throw error
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
Navigation:observe(work)
|
|
228
|
-
work.catch((error)
|
|
229
|
-
report(error)
|
|
230
|
-
)
|
|
118
|
+
Nav:fit()
|
|
119
|
+
@element.classList.remove("lango-nav-compact")
|
|
120
|
+
if @element.scrollWidth > @element.clientWidth
|
|
121
|
+
@element.classList.add("lango-nav-compact")
|
|
231
122
|
return null
|
|
232
123
|
|
|
233
|
-
|
|
234
|
-
|
|
124
|
+
export class NavItem(form, props, renderer) : Control
|
|
125
|
+
properties
|
|
126
|
+
url
|
|
127
|
+
initial
|
|
128
|
+
methods
|
|
129
|
+
setCaption(value)
|
|
130
|
+
|
|
131
|
+
NavItem(form, props, renderer)
|
|
132
|
+
super(form, props, navElement(props.url))
|
|
133
|
+
@url = props.url
|
|
134
|
+
@initial = props.active == true
|
|
135
|
+
@element.classList.add("nav-link")
|
|
136
|
+
appendNavContent(form, @element, props.content, renderer)
|
|
137
|
+
if @url != null and @element.querySelector("a, button, input, select, textarea, [contenteditable]") != null
|
|
138
|
+
throw "A linked NavItem cannot contain interactive controls"
|
|
139
|
+
@element.setAttribute("aria-label", @element.textContent)
|
|
140
|
+
@element.title = @element.textContent
|
|
141
|
+
decorate(@this, props)
|
|
142
|
+
if props.keepVisible == true or @element.querySelector("img, svg, i, .bi") == null
|
|
143
|
+
@element.classList.add("lango-nav-keep")
|
|
144
|
+
if props.theme != null
|
|
145
|
+
@element.classList.add("text-bg-${props.theme.toLowerCase()}")
|
|
146
|
+
if props.dark == true
|
|
147
|
+
@element.setAttribute("data-bs-theme", "dark")
|
|
148
|
+
if props.translucent == true
|
|
149
|
+
@element.style.setProperty("--bs-bg-opacity", ".85")
|
|
150
|
+
|
|
151
|
+
NavItem:setCaption(value)
|
|
152
|
+
@element.textContent = value
|
|
153
|
+
@element.setAttribute("aria-label", value)
|
|
154
|
+
@element.title = value
|
|
155
|
+
@element.classList.add("lango-nav-keep")
|
|
156
|
+
return @this
|
|
157
|
+
|
|
158
|
+
export class NavBarItem(form, props, renderer) : NavItem
|
|
159
|
+
|
|
160
|
+
NavBarItem(form, props, renderer)
|
|
161
|
+
super(form, props, renderer)
|
|
162
|
+
|
|
163
|
+
navElement(url)
|
|
164
|
+
if url == null
|
|
165
|
+
return cloneMarkup("nav-content", <div></div>)
|
|
166
|
+
if !is_string(url) or url.trim() == ""
|
|
167
|
+
throw "NavItem URL must be nonempty text"
|
|
168
|
+
target = new URL(url, document.baseURI)
|
|
169
|
+
if target.protocol != "http:" and target.protocol != "https:"
|
|
170
|
+
throw "Unsupported navigation URL"
|
|
171
|
+
element = document/createElement("a")
|
|
172
|
+
element.href = target.href
|
|
173
|
+
return element
|
|
174
|
+
|
|
175
|
+
appendNavContent(form, element, content, renderer)
|
|
176
|
+
if content == null
|
|
235
177
|
return null
|
|
236
|
-
if
|
|
237
|
-
|
|
178
|
+
if is_array(content)
|
|
179
|
+
for content as child
|
|
180
|
+
appendNavContent(form, element, child, renderer)
|
|
238
181
|
else
|
|
239
|
-
|
|
240
|
-
|
|
182
|
+
if is_string(content) or is_number(content)
|
|
183
|
+
label = document/createElement("span")
|
|
184
|
+
label.className = "lango-nav-label"
|
|
185
|
+
label.textContent = "${content}"
|
|
186
|
+
element.appendChild(label)
|
|
187
|
+
else
|
|
188
|
+
child = renderer.build(form, content)
|
|
189
|
+
if content.type == "text"
|
|
190
|
+
child.classList.add("lango-nav-label")
|
|
191
|
+
element.appendChild(child)
|
|
241
192
|
return null
|
|
242
193
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if !rel.split(" ").includes("noopener")
|
|
270
|
-
rel = "${rel} noopener"
|
|
271
|
-
anchor.setAttribute("rel", rel)
|
|
272
|
-
return null
|
|
273
|
-
if destination.pathname == location.pathname and destination.search == location.search and (destination.hash != location.hash or href.includes("#"))
|
|
274
|
-
return null
|
|
275
|
-
event.preventDefault()
|
|
276
|
-
observe(navigate(destination.href))
|
|
277
|
-
catch error
|
|
278
|
-
report(error)
|
|
279
|
-
return null
|
|
280
|
-
|
|
281
|
-
Navigation:link(element)
|
|
282
|
-
current = element
|
|
283
|
-
found = null
|
|
284
|
-
loop while current != null
|
|
285
|
-
if current.inert == true or current.hidden == true or current.disabled == true
|
|
286
|
-
return null
|
|
287
|
-
name = current.tagName
|
|
288
|
-
if found == null and is_string(name) and name.toLowerCase() == "a"
|
|
289
|
-
found = current
|
|
290
|
-
current = current.parentNode
|
|
291
|
-
return found
|
|
292
|
-
|
|
293
|
-
Navigation:idle()
|
|
294
|
-
return @tail
|
|
295
|
-
|
|
296
|
-
Navigation:dispose()
|
|
297
|
-
if @disposed
|
|
298
|
-
return null
|
|
299
|
-
@disposed = true
|
|
300
|
-
if @started
|
|
301
|
-
@document.removeEventListener("click", @click)
|
|
302
|
-
@window.removeEventListener("popstate", @pop)
|
|
303
|
-
@window.removeEventListener("hashchange", @hash)
|
|
304
|
-
return null
|
|
305
|
-
|
|
306
|
-
recovered(work)
|
|
307
|
-
return work.catch((error)
|
|
308
|
-
return null
|
|
309
|
-
)
|
|
194
|
+
export class Breadcrumb(form, props, renderer) : Control
|
|
195
|
+
|
|
196
|
+
Breadcrumb(form, props, renderer)
|
|
197
|
+
super(form, props, cloneMarkup("breadcrumb", <nav><ol class="breadcrumb"></ol></nav>))
|
|
198
|
+
list = @element.firstElementChild
|
|
199
|
+
if props.divider != null
|
|
200
|
+
list.style.setProperty("--bs-breadcrumb-divider", to_json("${props.divider}"))
|
|
201
|
+
if props.items != null
|
|
202
|
+
for props.items as definition
|
|
203
|
+
if definition.type != "breadcrumbItem"
|
|
204
|
+
throw "Breadcrumb accepts BreadcrumbItem definitions"
|
|
205
|
+
item = new BreadcrumbItem(form, definition)
|
|
206
|
+
form.register(definition.name, item)
|
|
207
|
+
list.appendChild(item.element)
|
|
208
|
+
if list.lastElementChild != null
|
|
209
|
+
list.lastElementChild.classList.add("active")
|
|
210
|
+
list.lastElementChild.setAttribute("aria-current", "page")
|
|
211
|
+
|
|
212
|
+
export class BreadcrumbItem(form, props) : Control
|
|
213
|
+
|
|
214
|
+
BreadcrumbItem(form, props)
|
|
215
|
+
super(form, props, cloneMarkup("breadcrumb-item", <li class="breadcrumb-item"></li>))
|
|
216
|
+
decorate(@this, props)
|
|
217
|
+
content = navElement(props.url)
|
|
218
|
+
content.textContent = props.text
|
|
219
|
+
@element.appendChild(content)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import js global Intl
|
|
2
|
+
import js global Object
|
|
3
|
+
import js global Reflect
|
|
4
|
+
import js global Number
|
|
5
|
+
import js global RegExp
|
|
6
|
+
import js global document
|
|
7
|
+
import "./fields"
|
|
8
|
+
class Field
|
|
9
|
+
import "./templates"
|
|
10
|
+
cloneMarkup(name, xml)
|
|
11
|
+
import "./input_changes"
|
|
12
|
+
class InputChanges
|
|
13
|
+
|
|
14
|
+
export decimalText(value)
|
|
15
|
+
export numericFormatter(format, money = false)
|
|
16
|
+
|
|
17
|
+
decimalText(value)
|
|
18
|
+
if value == null
|
|
19
|
+
return ""
|
|
20
|
+
if is_number(value)
|
|
21
|
+
value = "${value}"
|
|
22
|
+
if !is_string(value)
|
|
23
|
+
throw "Numeric value must be a number or decimal text"
|
|
24
|
+
value = value.trim()
|
|
25
|
+
if value == ""
|
|
26
|
+
return ""
|
|
27
|
+
valid = new RegExp("^[+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$")
|
|
28
|
+
if !valid.test(value)
|
|
29
|
+
throw "Numeric value requires decimal text with a dot separator"
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
numericFormatter(format, money = false)
|
|
33
|
+
if !is_object(format) or is_array(format)
|
|
34
|
+
throw "Numeric format must be an options map"
|
|
35
|
+
options = Object/assign({}, format)
|
|
36
|
+
locale = options.locale
|
|
37
|
+
if locale == null
|
|
38
|
+
locale = []
|
|
39
|
+
Reflect/deleteProperty(options, "locale")
|
|
40
|
+
if money and options.currency != null and options.style == null
|
|
41
|
+
options.style = "currency"
|
|
42
|
+
return new Intl/NumberFormat(locale, options)
|
|
43
|
+
|
|
44
|
+
export class NumericInput(form, props) : Field
|
|
45
|
+
methods
|
|
46
|
+
getValue()
|
|
47
|
+
setValue(value)
|
|
48
|
+
dispose()
|
|
49
|
+
|
|
50
|
+
NumericInput(form, props)
|
|
51
|
+
super(form, props, cloneMarkup("numeric-input", <input type="text" class="form-control" inputmode="decimal" />))
|
|
52
|
+
@number = props.variant.toLowerCase() == "number"
|
|
53
|
+
@formatter = numericFormatter(props.format, props.variant.toLowerCase() == "money")
|
|
54
|
+
@changes = new InputChanges(form, props.url)
|
|
55
|
+
@separator = "."
|
|
56
|
+
settings = @formatter.resolvedOptions()
|
|
57
|
+
decimalFormat = new Intl/NumberFormat(settings.locale, {
|
|
58
|
+
minimumFractionDigits: 1
|
|
59
|
+
})
|
|
60
|
+
for decimalFormat.formatToParts(1.1) as part
|
|
61
|
+
if part.type == "decimal"
|
|
62
|
+
@separator = part.value
|
|
63
|
+
if props.placeholder != null
|
|
64
|
+
@input.placeholder = props.placeholder
|
|
65
|
+
if props.maxLength != null
|
|
66
|
+
@input.maxLength = props.maxLength
|
|
67
|
+
@raw = ""
|
|
68
|
+
setValue(props.value)
|
|
69
|
+
focus = ()
|
|
70
|
+
@input.value = @raw
|
|
71
|
+
blur = ()
|
|
72
|
+
display()
|
|
73
|
+
change = ()
|
|
74
|
+
@raw = @input.value.replaceAll(@separator, ".")
|
|
75
|
+
@changes.changed()
|
|
76
|
+
@input.addEventListener("focus", focus)
|
|
77
|
+
@input.addEventListener("blur", blur)
|
|
78
|
+
@input.addEventListener("input", change)
|
|
79
|
+
release = ()
|
|
80
|
+
capture focus
|
|
81
|
+
capture blur
|
|
82
|
+
capture change
|
|
83
|
+
@input.removeEventListener("focus", focus)
|
|
84
|
+
@input.removeEventListener("blur", blur)
|
|
85
|
+
@input.removeEventListener("input", change)
|
|
86
|
+
@release.add(release)
|
|
87
|
+
|
|
88
|
+
NumericInput:formatted(value)
|
|
89
|
+
for @formatter.formatToParts(value) as part
|
|
90
|
+
if part.type == "infinity" or part.type == "nan"
|
|
91
|
+
throw "Numeric value is outside the supported formatting range"
|
|
92
|
+
return @formatter.format(value)
|
|
93
|
+
|
|
94
|
+
NumericInput:display()
|
|
95
|
+
if @raw == ""
|
|
96
|
+
@input.value = ""
|
|
97
|
+
return null
|
|
98
|
+
try
|
|
99
|
+
@input.value = formatted(decimalText(@raw))
|
|
100
|
+
catch error
|
|
101
|
+
@input.value = @raw
|
|
102
|
+
return null
|
|
103
|
+
|
|
104
|
+
NumericInput:getValue()
|
|
105
|
+
value = decimalText(@raw)
|
|
106
|
+
if @number
|
|
107
|
+
if value == ""
|
|
108
|
+
return null
|
|
109
|
+
return Number/parseFloat(value)
|
|
110
|
+
if value != ""
|
|
111
|
+
formatted(value)
|
|
112
|
+
return value
|
|
113
|
+
|
|
114
|
+
NumericInput:setValue(value)
|
|
115
|
+
raw = decimalText(value)
|
|
116
|
+
rendered = ""
|
|
117
|
+
if raw != ""
|
|
118
|
+
rendered = formatted(raw)
|
|
119
|
+
if @number
|
|
120
|
+
Number/parseFloat(raw)
|
|
121
|
+
@raw = raw
|
|
122
|
+
if document.activeElement == @input
|
|
123
|
+
@input.value = raw
|
|
124
|
+
else
|
|
125
|
+
@input.value = rendered
|
|
126
|
+
return @this
|
|
127
|
+
|
|
128
|
+
NumericInput:dispose()
|
|
129
|
+
@changes.dispose()
|
|
130
|
+
super.dispose()
|
|
131
|
+
return null
|