@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/dist/navigation.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.mjs","sources":["navigation.lango"],"sourcesContent":["import js global Promise\nimport js global URL\nimport js global crypto\n\nexport class Navigation\n properties\n url\n methods\n start()\n navigate(url, replace = false)\n refresh()\n idle()\n dispose()\n\nNavigation(window, options)\n if !is_object(options) or !is_kindof(options.onUrl, Function)\n throw \"UiNavigationRequiresUrlHandler\"\n @window = window\n @document = window.document\n @onUrl = options.onUrl\n @errors = options.errors\n @redirect = options.rootRedirect\n @guard = options.beforeNavigate\n if @guard != null and !is_kindof(@guard, Function)\n throw \"UiNavigationGuardRequiresFunction\"\n @owner = crypto/randomUUID()\n @position = 0\n @restoring = false\n @started = false\n @disposed = false\n @last = null\n @url = null\n @initial = null\n @tail = Promise/resolve()\n @click = null\n @pop = null\n @hash = null\n if @redirect != null\n parseUrl(@redirect)\n\nNavigation:parseUrl(value)\n if !is_string(value) or value == \"\" or value.includes(\"\\\\\")\n throw \"UiNavigationRequiresSameOriginUrl\"\n location = @window.location\n target = new URL(value, location.href)\n if target.origin != location.origin or (target.protocol != \"http:\" and target.protocol != \"https:\") or target.username != \"\" or target.password != \"\"\n throw \"UiNavigationRequiresSameOriginUrl\"\n return target\n\nlocalUrl(target)\n return \"${target.pathname}${target.search}${target.hash}\"\n\nNavigation:start()\n if @disposed\n throw \"UiNavigationDisposed\"\n if @started\n return @initial\n location = @window.location\n if location.pathname == \"/\" and @redirect != null\n target = parseUrl(@redirect)\n if target.search == \"\"\n target.search = location.search\n if target.hash == \"\"\n target.hash = location.hash\n @window.history.replaceState(null, \"\", localUrl(target))\n @started = true\n @window.history.replaceState(historyState(0, localUrl(@window.location)), \"\", localUrl(@window.location))\n click = (event)\n clickEvent(event)\n pop = (event)\n historyEvent(\"history\")\n hash = (event)\n historyEvent(\"hash\")\n @click = click\n @pop = pop\n @hash = hash\n @document.addEventListener(\"click\", click)\n @window.addEventListener(\"popstate\", pop)\n @window.addEventListener(\"hashchange\", hash)\n @initial = notify(\"start\")\n return @initial\n\nNavigation:navigate(url, replace = false)\n if @disposed\n throw \"UiNavigationDisposed\"\n if !@started\n throw \"UiNavigationNotStarted\"\n if @restoring\n throw \"UiNavigationRestoringHistory\"\n if !is_bool(replace)\n throw \"UiNavigationReplaceMustBeBoolean\"\n target = parseUrl(url)\n path = localUrl(target)\n if path == localUrl(@window.location)\n if @last == null\n if !canNavigate(path, \"navigate\")\n return Promise/resolve(false)\n return notify(\"navigate\")\n return Promise/resolve(null)\n if !canNavigate(path, \"navigate\")\n return Promise/resolve(false)\n if replace\n @window.history.replaceState(historyState(@position, path), \"\", path)\n else\n @position++\n @window.history.pushState(historyState(@position, path), \"\", path)\n return notify(\"navigate\")\n\nNavigation:canNavigate(path, source)\n if @guard == null\n return true\n callback = @guard\n result = callback({\n url: path\n source: source\n })\n if !is_bool(result)\n if result != null and is_kindof(result.then, Function)\n recovered(Promise/resolve(result))\n throw \"UiNavigationGuardMustReturnBoolean\"\n return result\n\nNavigation:historyState(position, path)\n result = {\n }\n previous = @window.history.state\n if is_object(previous) and !is_array(previous)\n for previous as name: value\n result[name] = value\n else\n if previous != null\n result.previousState = previous\n result[\"__langoNavigation\"] = {\n owner: @owner\n index: position\n url: path\n }\n return result\n\nNavigation:historyEvent(source)\n try\n moveHistory(source)\n catch error\n report(error)\n return null\n\nNavigation:moveHistory(source)\n path = localUrl(@window.location)\n state = @window.history.state\n marker = null\n if state != null\n marker = state[\"__langoNavigation\"]\n if @restoring\n if path == @url and marker != null and marker.owner == @owner and marker.index == @position\n @restoring = false\n return null\n if path == @url\n if marker != null and marker.owner == @owner\n @position = marker.index\n return null\n position = @position + 1\n if marker != null and marker.owner == @owner and marker.url == path\n position = marker.index\n allowed = false\n try\n allowed = canNavigate(path, source)\n catch error\n restoreHistory(position)\n throw error\n if !allowed\n restoreHistory(position)\n return null\n @position = position\n @window.history.replaceState(historyState(position, path), \"\", path)\n observe(notify(source))\n return null\n\nNavigation:restoreHistory(position)\n if position == @position\n @window.history.replaceState(historyState(@position, @url), \"\", @url)\n return null\n @restoring = true\n @window.history.go(@position - position)\n return null\n\nNavigation:notify(source)\n if @disposed\n return Promise/resolve(null)\n path = localUrl(@window.location)\n @url = path\n if path == @last\n return Promise/resolve(null)\n @last = path\n work = deliver(@tail, {\n url: path\n source: source\n })\n @tail = recovered(work)\n return work\n\nNavigation:refresh()\n if @disposed\n throw \"UiNavigationDisposed\"\n if !@started\n throw \"UiNavigationNotStarted\"\n if @restoring\n throw \"UiNavigationRestoringHistory\"\n if !canNavigate(localUrl(@window.location), \"refresh\")\n return Promise/resolve(false)\n @last = null\n return notify(\"refresh\")\n\nNavigation:deliver(ready, event)\n return ready.then(()\n capture event\n if @disposed\n return null\n callback = @onUrl\n return callback(event)\n ).catch((error)\n capture event\n if @last == event.url\n @last = null\n throw error\n )\n\nNavigation:observe(work)\n work.catch((error)\n report(error)\n )\n return null\n\nNavigation:report(error)\n if @disposed\n return null\n if @errors != null\n @errors.error(error)\n else\n context log\n log.err(error)\n return null\n\nNavigation:clickEvent(event)\n if @disposed or event.defaultPrevented == true or event.metaKey == true or event.ctrlKey == true or event.shiftKey == true or event.altKey == true\n return null\n if event.button != null and event.button != 0\n return null\n anchor = link(event.target)\n if anchor == null or anchor.hasAttribute(\"download\")\n return null\n href = anchor.getAttribute(\"href\")\n if href == null or href == \"\"\n return null\n target = anchor.getAttribute(\"target\")\n if target != null and target != \"\" and target.toLowerCase() != \"_self\"\n return null\n try\n destination = new URL(href, @window.location.href)\n if destination.protocol != \"http:\" and destination.protocol != \"https:\"\n return null\n location = @window.location\n if destination.origin != location.origin\n if target == null\n anchor.setAttribute(\"target\", \"_blank\")\n rel = anchor.getAttribute(\"rel\")\n if rel == null or rel == \"\"\n rel = \"noopener\"\n else\n if !rel.split(\" \").includes(\"noopener\")\n rel = \"${rel} noopener\"\n anchor.setAttribute(\"rel\", rel)\n return null\n if destination.pathname == location.pathname and destination.search == location.search and (destination.hash != location.hash or href.includes(\"#\"))\n return null\n event.preventDefault()\n observe(navigate(destination.href))\n catch error\n report(error)\n return null\n\nNavigation:link(element)\n current = element\n found = null\n loop while current != null\n if current.inert == true or current.hidden == true or current.disabled == true\n return null\n name = current.tagName\n if found == null and is_string(name) and name.toLowerCase() == \"a\"\n found = current\n current = current.parentNode\n return found\n\nNavigation:idle()\n return @tail\n\nNavigation:dispose()\n if @disposed\n return null\n @disposed = true\n if @started\n @document.removeEventListener(\"click\", @click)\n @window.removeEventListener(\"popstate\", @pop)\n @window.removeEventListener(\"hashchange\", @hash)\n return null\n\nrecovered(work)\n return work.catch((error)\n return null\n )\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA;;;;;;;AAgQA;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"navigation.mjs","sources":["navigation.lango"],"sourcesContent":["import js global document\nimport js global URL\nimport js global ResizeObserver\nimport js global RegExp\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./content\"\n appendContent(form, element, content, renderer)\n decorate(control, props)\n\nexport navigationMatch(url, current)\n\nnavigationMatch(url, current)\n target = new URL(url, current)\n location = new URL(current)\n if target.origin != location.origin\n return -1\n path = target.pathname\n if path == location.pathname\n return path.length\n if path != \"/\" and location.pathname.startsWith(\"${path.replace(new RegExp(\"/+$\"), \"\")}/\")\n return path.length\n return -1\n\nexport class Nav(form, props, renderer, navigationBar = false) : Control\n methods\n locationChanged(url)\n fit()\n\nNav(form, props, renderer, navigationBar = false)\n super(form, props, cloneMarkup(\"nav\", <nav class=\"nav lango-nav\"></nav>))\n @items = []\n @overflow = props.overflow != null\n @url = form.app.hostUrl()\n if navigationBar\n @element.classList.add(\"navbar\")\n if props.brand != null\n brand = document/createElement(\"div\")\n brand.className = \"navbar-brand\"\n appendContent(form, brand, props.brand, renderer)\n @element.appendChild(brand)\n switch props.alignment\n case \"center\"\n @element.classList.add(\"justify-content-center\")\n case \"end\"\n @element.classList.add(\"justify-content-end\")\n case \"vertical\"\n @element.classList.add(\"flex-column\")\n case \"fill\"\n @element.classList.add(\"nav-fill\")\n placement = null\n if props.items != null\n for props.items as definition\n if definition.type != \"navItem\" and definition.type != \"navBarItem\"\n throw \"Nav accepts NavItem definitions\"\n item = new NavItem(form, definition, renderer)\n form.register(definition.name, item)\n @items.add(item)\n @element.appendChild(item.element)\n if definition.placement != null\n if placement != null and placement != definition.placement\n throw \"Navbar items must agree on placement\"\n placement = definition.placement\n switch definition.placement\n case \"fixed-top\"\n case \"fixed-bottom\"\n case \"sticky-top\"\n case \"sticky-bottom\"\n @element.classList.add(definition.placement)\n else\n throw \"Unknown navbar placement: ${definition.placement}\"\n locationChanged(@url)\n groups = renderer.navigation\n groups.add(@this)\n release = ()\n capture groups\n index = groups.indexOf(@this)\n if index >= 0\n groups.splice(index, 1)\n @release.add(release)\n if @overflow\n observer = new ResizeObserver(()\n fit()\n )\n observer.observe(@element)\n stop = ()\n capture observer\n observer.disconnect()\n @release.add(stop)\n\nexport class NavBar(form, props, renderer) : Nav\n\nNavBar(form, props, renderer)\n super(form, props, renderer, true)\n\nNav:locationChanged(url)\n best = -1\n selected = null\n for @items as item\n if item.url != null\n score = navigationMatch(item.url, url)\n if score > best\n best = score\n selected = item\n for @items as item\n active = item.initial\n if item.url != null\n active = item == selected\n item.element.classList.toggle(\"active\", active)\n if active\n item.element.setAttribute(\"aria-current\", \"page\")\n else\n item.element.removeAttribute(\"aria-current\")\n return null\n\nNav:fit()\n @element.classList.remove(\"lango-nav-compact\")\n if @element.scrollWidth > @element.clientWidth\n @element.classList.add(\"lango-nav-compact\")\n return null\n\nexport class NavItem(form, props, renderer) : Control\n properties\n url\n initial\n methods\n setCaption(value)\n\nNavItem(form, props, renderer)\n super(form, props, navElement(props.url))\n @url = props.url\n @initial = props.active == true\n @element.classList.add(\"nav-link\")\n appendNavContent(form, @element, props.content, renderer)\n if @url != null and @element.querySelector(\"a, button, input, select, textarea, [contenteditable]\") != null\n throw \"A linked NavItem cannot contain interactive controls\"\n @element.setAttribute(\"aria-label\", @element.textContent)\n @element.title = @element.textContent\n decorate(@this, props)\n if props.keepVisible == true or @element.querySelector(\"img, svg, i, .bi\") == null\n @element.classList.add(\"lango-nav-keep\")\n if props.theme != null\n @element.classList.add(\"text-bg-${props.theme.toLowerCase()}\")\n if props.dark == true\n @element.setAttribute(\"data-bs-theme\", \"dark\")\n if props.translucent == true\n @element.style.setProperty(\"--bs-bg-opacity\", \".85\")\n\nNavItem:setCaption(value)\n @element.textContent = value\n @element.setAttribute(\"aria-label\", value)\n @element.title = value\n @element.classList.add(\"lango-nav-keep\")\n return @this\n\nexport class NavBarItem(form, props, renderer) : NavItem\n\nNavBarItem(form, props, renderer)\n super(form, props, renderer)\n\nnavElement(url)\n if url == null\n return cloneMarkup(\"nav-content\", <div></div>)\n if !is_string(url) or url.trim() == \"\"\n throw \"NavItem URL must be nonempty text\"\n target = new URL(url, document.baseURI)\n if target.protocol != \"http:\" and target.protocol != \"https:\"\n throw \"Unsupported navigation URL\"\n element = document/createElement(\"a\")\n element.href = target.href\n return element\n\nappendNavContent(form, element, content, renderer)\n if content == null\n return null\n if is_array(content)\n for content as child\n appendNavContent(form, element, child, renderer)\n else\n if is_string(content) or is_number(content)\n label = document/createElement(\"span\")\n label.className = \"lango-nav-label\"\n label.textContent = \"${content}\"\n element.appendChild(label)\n else\n child = renderer.build(form, content)\n if content.type == \"text\"\n child.classList.add(\"lango-nav-label\")\n element.appendChild(child)\n return null\n\nexport class Breadcrumb(form, props, renderer) : Control\n\nBreadcrumb(form, props, renderer)\n super(form, props, cloneMarkup(\"breadcrumb\", <nav><ol class=\"breadcrumb\"></ol></nav>))\n list = @element.firstElementChild\n if props.divider != null\n list.style.setProperty(\"--bs-breadcrumb-divider\", to_json(\"${props.divider}\"))\n if props.items != null\n for props.items as definition\n if definition.type != \"breadcrumbItem\"\n throw \"Breadcrumb accepts BreadcrumbItem definitions\"\n item = new BreadcrumbItem(form, definition)\n form.register(definition.name, item)\n list.appendChild(item.element)\n if list.lastElementChild != null\n list.lastElementChild.classList.add(\"active\")\n list.lastElementChild.setAttribute(\"aria-current\", \"page\")\n\nexport class BreadcrumbItem(form, props) : Control\n\nBreadcrumbItem(form, props)\n super(form, props, cloneMarkup(\"breadcrumb-item\", <li class=\"breadcrumb-item\"></li>))\n decorate(@this, props)\n content = navElement(props.url)\n content.textContent = props.text\n @element.appendChild(content)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA;;;;;;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA;;;;;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;AArMA;;;;;;;;;;;;;;;;;;;;AAoJA;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Field } from "./fields.mjs";
|
|
2
|
+
import { cloneMarkup } from "./templates.mjs";
|
|
3
|
+
import { InputChanges } from "./input_changes.mjs";
|
|
4
|
+
import {
|
|
5
|
+
hostGlobal as __hostGlobal,
|
|
6
|
+
xmlEscape as __xmlEscape,
|
|
7
|
+
isNumber as __isNumber,
|
|
8
|
+
isString as __isString,
|
|
9
|
+
isBool as __isBool,
|
|
10
|
+
isObject as __isObject,
|
|
11
|
+
isArray as __isArray,
|
|
12
|
+
add as __add,
|
|
13
|
+
requireBoolean as __requireBoolean,
|
|
14
|
+
normalize as __normalize,
|
|
15
|
+
boundary as __boundary,
|
|
16
|
+
requireArity as __requireArity,
|
|
17
|
+
} from "./.lango/runtime.mjs";
|
|
18
|
+
|
|
19
|
+
export class NumericInput extends Field {
|
|
20
|
+
#number;
|
|
21
|
+
#formatter;
|
|
22
|
+
#changes;
|
|
23
|
+
#separator;
|
|
24
|
+
#raw;
|
|
25
|
+
constructor(form, props) {
|
|
26
|
+
super(form, props, cloneMarkup("numeric-input", ["<input type=\"text\" class=\"form-control\" inputmode=\"decimal\" />"].join("")));
|
|
27
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
28
|
+
form = __boundary(form);
|
|
29
|
+
props = __boundary(props);
|
|
30
|
+
this.#number = __normalize(props.variant.toLowerCase()) === "number";
|
|
31
|
+
this.#formatter = numericFormatter(__normalize(props.format), __normalize(props.variant.toLowerCase()) === "money");
|
|
32
|
+
this.#changes = new InputChanges(form, __normalize(props.url));
|
|
33
|
+
this.#separator = ".";
|
|
34
|
+
let settings = __normalize(this.#formatter.resolvedOptions());
|
|
35
|
+
let decimalFormat = new (__hostGlobal(["Intl"]).NumberFormat)(__normalize(settings.locale), { minimumFractionDigits: 1 });
|
|
36
|
+
for (const part of __normalize(decimalFormat.formatToParts(1.1))) {
|
|
37
|
+
if (__requireBoolean(__normalize(part.type) === "decimal")) {
|
|
38
|
+
this.#separator = __normalize(part.value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (__requireBoolean(__normalize(props.placeholder) !== null)) {
|
|
42
|
+
this.input.placeholder = __normalize(props.placeholder);
|
|
43
|
+
}
|
|
44
|
+
if (__requireBoolean(__normalize(props.maxLength) !== null)) {
|
|
45
|
+
this.input.maxLength = __normalize(props.maxLength);
|
|
46
|
+
}
|
|
47
|
+
this.#raw = "";
|
|
48
|
+
this.setValue(__normalize(props.value));
|
|
49
|
+
let focus = () => {
|
|
50
|
+
this.input.value = __normalize(this.#raw);
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
let blur = () => {
|
|
54
|
+
this.#display();
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
let change = () => {
|
|
58
|
+
this.#raw = __normalize(this.input.value.replaceAll(__normalize(this.#separator), "."));
|
|
59
|
+
__normalize(this.#changes.changed());
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
__normalize(this.input.addEventListener("focus", focus));
|
|
63
|
+
__normalize(this.input.addEventListener("blur", blur));
|
|
64
|
+
__normalize(this.input.addEventListener("input", change));
|
|
65
|
+
let release = () => {
|
|
66
|
+
__normalize(this.input.removeEventListener("focus", focus));
|
|
67
|
+
__normalize(this.input.removeEventListener("blur", blur));
|
|
68
|
+
__normalize(this.input.removeEventListener("input", change));
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
__add(this.release, release);
|
|
72
|
+
}
|
|
73
|
+
#formatted(value) {
|
|
74
|
+
__requireArity(arguments.length, [0], "formatted");
|
|
75
|
+
value = __boundary(value);
|
|
76
|
+
for (const part of __normalize(this.#formatter.formatToParts(value))) {
|
|
77
|
+
if (__requireBoolean(__requireBoolean(__normalize(part.type) === "infinity") || __requireBoolean(__normalize(part.type) === "nan"))) {
|
|
78
|
+
throw "Numeric value is outside the supported formatting range";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return __normalize(this.#formatter.format(value));
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
#display() {
|
|
85
|
+
if (__requireBoolean(__normalize(this.#raw) === "")) {
|
|
86
|
+
this.input.value = "";
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
this.input.value = this.#formatted(decimalText(__normalize(this.#raw)));
|
|
91
|
+
} catch (error) {
|
|
92
|
+
this.input.value = __normalize(this.#raw);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
getValue() {
|
|
98
|
+
let value = decimalText(__normalize(this.#raw));
|
|
99
|
+
if (__requireBoolean(__normalize(this.#number))) {
|
|
100
|
+
if (__requireBoolean(value === "")) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return __normalize(__hostGlobal(["Number"]).parseFloat(value));
|
|
104
|
+
}
|
|
105
|
+
if (__requireBoolean(value !== "")) {
|
|
106
|
+
this.#formatted(value);
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
setValue(value) {
|
|
112
|
+
__requireArity(arguments.length, [0], "setValue");
|
|
113
|
+
value = __boundary(value);
|
|
114
|
+
let raw = decimalText(value);
|
|
115
|
+
let rendered = "";
|
|
116
|
+
if (__requireBoolean(raw !== "")) {
|
|
117
|
+
rendered = this.#formatted(raw);
|
|
118
|
+
if (__requireBoolean(__normalize(this.#number))) {
|
|
119
|
+
__normalize(__hostGlobal(["Number"]).parseFloat(raw));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
this.#raw = raw;
|
|
123
|
+
if (__requireBoolean(__normalize(__hostGlobal(["document"]).activeElement) === __normalize(this.input))) {
|
|
124
|
+
this.input.value = raw;
|
|
125
|
+
} else {
|
|
126
|
+
this.input.value = rendered;
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
dispose() {
|
|
132
|
+
__normalize(this.#changes.dispose());
|
|
133
|
+
super.dispose();
|
|
134
|
+
return null;
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function decimalText(value) {
|
|
139
|
+
__requireArity(arguments.length, [0], "decimalText");
|
|
140
|
+
value = __boundary(value);
|
|
141
|
+
if (__requireBoolean(value === null)) {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
if (__requireBoolean(__isNumber(value))) {
|
|
145
|
+
value = `${value}`;
|
|
146
|
+
}
|
|
147
|
+
if (__requireBoolean(!__requireBoolean(__isString(value)))) {
|
|
148
|
+
throw "Numeric value must be a number or decimal text";
|
|
149
|
+
}
|
|
150
|
+
value = __normalize(value.trim());
|
|
151
|
+
if (__requireBoolean(value === "")) {
|
|
152
|
+
return "";
|
|
153
|
+
}
|
|
154
|
+
let valid = new (__hostGlobal(["RegExp"]))("^[+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$");
|
|
155
|
+
if (__requireBoolean(!__requireBoolean(__normalize(valid.test(value))))) {
|
|
156
|
+
throw "Numeric value requires decimal text with a dot separator";
|
|
157
|
+
}
|
|
158
|
+
return value;
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function numericFormatter(format, money = false) {
|
|
163
|
+
__requireArity(arguments.length, [0], "numericFormatter");
|
|
164
|
+
format = __boundary(format);
|
|
165
|
+
money = __boundary(money);
|
|
166
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(format))) || __requireBoolean(__isArray(format)))) {
|
|
167
|
+
throw "Numeric format must be an options map";
|
|
168
|
+
}
|
|
169
|
+
let options = __normalize(__hostGlobal(["Object"]).assign({ }, format));
|
|
170
|
+
let locale = __normalize(options.locale);
|
|
171
|
+
if (__requireBoolean(locale === null)) {
|
|
172
|
+
locale = [];
|
|
173
|
+
}
|
|
174
|
+
__normalize(__hostGlobal(["Reflect"]).deleteProperty(options, "locale"));
|
|
175
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(money) && __requireBoolean(__normalize(options.currency) !== null)) && __requireBoolean(__normalize(options.style) === null))) {
|
|
176
|
+
options.style = "currency";
|
|
177
|
+
}
|
|
178
|
+
return new (__hostGlobal(["Intl"]).NumberFormat)(locale, options);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=numeric_input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric_input.mjs","sources":["numeric_input.lango"],"sourcesContent":["import js global Intl\nimport js global Object\nimport js global Reflect\nimport js global Number\nimport js global RegExp\nimport js global document\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport decimalText(value)\nexport numericFormatter(format, money = false)\n\ndecimalText(value)\n if value == null\n return \"\"\n if is_number(value)\n value = \"${value}\"\n if !is_string(value)\n throw \"Numeric value must be a number or decimal text\"\n value = value.trim()\n if value == \"\"\n return \"\"\n valid = new RegExp(\"^[+-]?(?:[0-9]+(?:\\\\.[0-9]*)?|\\\\.[0-9]+)(?:[eE][+-]?[0-9]+)?$\")\n if !valid.test(value)\n throw \"Numeric value requires decimal text with a dot separator\"\n return value\n\nnumericFormatter(format, money = false)\n if !is_object(format) or is_array(format)\n throw \"Numeric format must be an options map\"\n options = Object/assign({}, format)\n locale = options.locale\n if locale == null\n locale = []\n Reflect/deleteProperty(options, \"locale\")\n if money and options.currency != null and options.style == null\n options.style = \"currency\"\n return new Intl/NumberFormat(locale, options)\n\nexport class NumericInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n dispose()\n\nNumericInput(form, props)\n super(form, props, cloneMarkup(\"numeric-input\", <input type=\"text\" class=\"form-control\" inputmode=\"decimal\" />))\n @number = props.variant.toLowerCase() == \"number\"\n @formatter = numericFormatter(props.format, props.variant.toLowerCase() == \"money\")\n @changes = new InputChanges(form, props.url)\n @separator = \".\"\n settings = @formatter.resolvedOptions()\n decimalFormat = new Intl/NumberFormat(settings.locale, {\n minimumFractionDigits: 1\n })\n for decimalFormat.formatToParts(1.1) as part\n if part.type == \"decimal\"\n @separator = part.value\n if props.placeholder != null\n @input.placeholder = props.placeholder\n if props.maxLength != null\n @input.maxLength = props.maxLength\n @raw = \"\"\n setValue(props.value)\n focus = ()\n @input.value = @raw\n blur = ()\n display()\n change = ()\n @raw = @input.value.replaceAll(@separator, \".\")\n @changes.changed()\n @input.addEventListener(\"focus\", focus)\n @input.addEventListener(\"blur\", blur)\n @input.addEventListener(\"input\", change)\n release = ()\n capture focus\n capture blur\n capture change\n @input.removeEventListener(\"focus\", focus)\n @input.removeEventListener(\"blur\", blur)\n @input.removeEventListener(\"input\", change)\n @release.add(release)\n\nNumericInput:formatted(value)\n for @formatter.formatToParts(value) as part\n if part.type == \"infinity\" or part.type == \"nan\"\n throw \"Numeric value is outside the supported formatting range\"\n return @formatter.format(value)\n\nNumericInput:display()\n if @raw == \"\"\n @input.value = \"\"\n return null\n try\n @input.value = formatted(decimalText(@raw))\n catch error\n @input.value = @raw\n return null\n\nNumericInput:getValue()\n value = decimalText(@raw)\n if @number\n if value == \"\"\n return null\n return Number/parseFloat(value)\n if value != \"\"\n formatted(value)\n return value\n\nNumericInput:setValue(value)\n raw = decimalText(value)\n rendered = \"\"\n if raw != \"\"\n rendered = formatted(raw)\n if @number\n Number/parseFloat(raw)\n @raw = raw\n if document.activeElement == @input\n @input.value = raw\n else\n @input.value = rendered\n return @this\n\nNumericInput:dispose()\n @changes.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA3BA;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Field } from "./fields.mjs";
|
|
2
|
+
import { cloneMarkup } from "./templates.mjs";
|
|
3
|
+
import { InputChanges } from "./input_changes.mjs";
|
|
4
|
+
import {
|
|
5
|
+
hostGlobal as __hostGlobal,
|
|
6
|
+
xmlEscape as __xmlEscape,
|
|
7
|
+
isNumber as __isNumber,
|
|
8
|
+
isString as __isString,
|
|
9
|
+
isBool as __isBool,
|
|
10
|
+
isObject as __isObject,
|
|
11
|
+
isArray as __isArray,
|
|
12
|
+
add as __add,
|
|
13
|
+
requireBoolean as __requireBoolean,
|
|
14
|
+
normalize as __normalize,
|
|
15
|
+
boundary as __boundary,
|
|
16
|
+
requireArity as __requireArity,
|
|
17
|
+
} from "./.lango/runtime.mjs";
|
|
18
|
+
|
|
19
|
+
export class OTPInput extends Field {
|
|
20
|
+
#settings;
|
|
21
|
+
#changes;
|
|
22
|
+
constructor(form, props) {
|
|
23
|
+
super(form, props, cloneMarkup("otp-input", ["<input type=\"text\" class=\"form-control lango-otp\" />"].join("")));
|
|
24
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
25
|
+
form = __boundary(form);
|
|
26
|
+
props = __boundary(props);
|
|
27
|
+
this.#settings = otpSettings(__normalize(props.length), __normalize(props.characters));
|
|
28
|
+
this.#changes = new InputChanges(form, __normalize(props.url));
|
|
29
|
+
this.input.spellcheck = false;
|
|
30
|
+
this.input.autocapitalize = "off";
|
|
31
|
+
if (__requireBoolean(__normalize(props.disableAutoComplete) !== true)) {
|
|
32
|
+
this.input.autocomplete = "one-time-code";
|
|
33
|
+
}
|
|
34
|
+
if (__requireBoolean(__normalize(this.#settings.characters) === "numeric")) {
|
|
35
|
+
this.input.inputMode = "numeric";
|
|
36
|
+
}
|
|
37
|
+
this.setValue(__normalize(props.value));
|
|
38
|
+
let listener = () => {
|
|
39
|
+
this.input.value = otpText(__normalize(this.input.value), __normalize(this.#settings));
|
|
40
|
+
__normalize(this.#changes.changed());
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
__normalize(this.input.addEventListener("input", listener));
|
|
44
|
+
let release = () => {
|
|
45
|
+
__normalize(this.input.removeEventListener("input", listener));
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
__add(this.release, release);
|
|
49
|
+
}
|
|
50
|
+
getValue() {
|
|
51
|
+
return __normalize(this.input.value);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
setValue(value) {
|
|
55
|
+
__requireArity(arguments.length, [0], "setValue");
|
|
56
|
+
value = __boundary(value);
|
|
57
|
+
let next = otpText(value, __normalize(this.#settings), true);
|
|
58
|
+
this.input.value = next;
|
|
59
|
+
return this;
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
dispose() {
|
|
63
|
+
__normalize(this.#changes.dispose());
|
|
64
|
+
super.dispose();
|
|
65
|
+
return null;
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function otpSettings(length = null, characters = null) {
|
|
70
|
+
length = __boundary(length);
|
|
71
|
+
characters = __boundary(characters);
|
|
72
|
+
if (__requireBoolean(length === null)) {
|
|
73
|
+
length = 6;
|
|
74
|
+
}
|
|
75
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(length))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isInteger(length))))) || __requireBoolean(length < 1)) || __requireBoolean(length > 64))) {
|
|
76
|
+
throw "OTP length must be an integer between 1 and 64";
|
|
77
|
+
}
|
|
78
|
+
if (__requireBoolean(characters === null)) {
|
|
79
|
+
characters = "numeric";
|
|
80
|
+
}
|
|
81
|
+
let pattern = null;
|
|
82
|
+
if (characters === "numeric") {
|
|
83
|
+
pattern = "[^0-9]";
|
|
84
|
+
} else if (characters === "alpha") {
|
|
85
|
+
pattern = "[^A-Za-z]";
|
|
86
|
+
} else if (characters === "alphanumeric") {
|
|
87
|
+
pattern = "[^A-Za-z0-9]";
|
|
88
|
+
} else {
|
|
89
|
+
throw `Unknown OTP characters: ${characters}`;
|
|
90
|
+
}
|
|
91
|
+
return { length: length, characters: characters, pattern: pattern };
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function otpText(value, settings, strict = false) {
|
|
96
|
+
__requireArity(arguments.length, [0, 1], "otpText");
|
|
97
|
+
value = __boundary(value);
|
|
98
|
+
settings = __boundary(settings);
|
|
99
|
+
strict = __boundary(strict);
|
|
100
|
+
if (__requireBoolean(value === null)) {
|
|
101
|
+
value = "";
|
|
102
|
+
}
|
|
103
|
+
if (__requireBoolean(!__requireBoolean(__isString(value)))) {
|
|
104
|
+
throw "OTP value must be text";
|
|
105
|
+
}
|
|
106
|
+
let filtered = __normalize(__normalize(value.replace(new (__hostGlobal(["RegExp"]))(__normalize(settings.pattern), "g"), "")).slice(0, __normalize(settings.length)));
|
|
107
|
+
if (__requireBoolean(__requireBoolean(strict) && __requireBoolean(filtered !== value))) {
|
|
108
|
+
throw "OTP value contains unsupported characters or exceeds its length";
|
|
109
|
+
}
|
|
110
|
+
return filtered;
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=otp_input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp_input.mjs","sources":["otp_input.lango"],"sourcesContent":["import js global Number\nimport js global RegExp\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport otpSettings(length = null, characters = null)\nexport otpText(value, settings, strict = false)\n\notpSettings(length = null, characters = null)\n if length == null\n length = 6\n if !is_number(length) or !Number/isInteger(length) or length < 1 or length > 64\n throw \"OTP length must be an integer between 1 and 64\"\n if characters == null\n characters = \"numeric\"\n pattern = null\n switch characters\n case \"numeric\"\n pattern = \"[^0-9]\"\n case \"alpha\"\n pattern = \"[^A-Za-z]\"\n case \"alphanumeric\"\n pattern = \"[^A-Za-z0-9]\"\n else\n throw \"Unknown OTP characters: ${characters}\"\n return {\n length: length\n characters: characters\n pattern: pattern\n }\n\notpText(value, settings, strict = false)\n if value == null\n value = \"\"\n if !is_string(value)\n throw \"OTP value must be text\"\n filtered = value.replace(new RegExp(settings.pattern, \"g\"), \"\").slice(0, settings.length)\n if strict and filtered != value\n throw \"OTP value contains unsupported characters or exceeds its length\"\n return filtered\n\nexport class OTPInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n dispose()\n\nOTPInput(form, props)\n super(form, props, cloneMarkup(\"otp-input\", <input type=\"text\" class=\"form-control lango-otp\" />))\n @settings = otpSettings(props.length, props.characters)\n @changes = new InputChanges(form, props.url)\n @input.spellcheck = false\n @input.autocapitalize = \"off\"\n if props.disableAutoComplete != true\n @input.autocomplete = \"one-time-code\"\n if @settings.characters == \"numeric\"\n @input.inputMode = \"numeric\"\n setValue(props.value)\n listener = ()\n @input.value = otpText(@input.value, @settings)\n @changes.changed()\n @input.addEventListener(\"input\", listener)\n release = ()\n capture listener\n @input.removeEventListener(\"input\", listener)\n @release.add(release)\n\nOTPInput:getValue()\n return @input.value\n\nOTPInput:setValue(value)\n next = otpText(value, @settings, true)\n @input.value = next\n return @this\n\nOTPInput:dispose()\n @changes.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAjCA;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;"}
|