@lango-project/lango-client 0.0.0-stage → 0.2.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 +200 -0
- package/NOTICE +2 -0
- package/README.md +929 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/runtime.mjs +607 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/application.mjs +429 -0
- package/dist/application.mjs.map +1 -0
- package/dist/coordinator.mjs +91 -0
- package/dist/coordinator.mjs.map +1 -0
- package/dist/demo.mjs +110 -0
- package/dist/demo.mjs.map +1 -0
- package/dist/demo_controls.mjs +59 -0
- package/dist/demo_controls.mjs.map +1 -0
- package/dist/errors.mjs +201 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/form_state.mjs +266 -0
- package/dist/form_state.mjs.map +1 -0
- package/dist/heartbeat.mjs +330 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/inheritance.mjs +240 -0
- package/dist/inheritance.mjs.map +1 -0
- package/dist/input_values.mjs +65 -0
- package/dist/input_values.mjs.map +1 -0
- package/dist/library.mjs +824 -0
- package/dist/library.mjs.map +1 -0
- package/dist/navigation.mjs +466 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/node/.lango/bignumber.mjs +3119 -0
- package/dist/node/.lango/runtime.mjs +609 -0
- package/dist/node/.lango/xmldom/conventions.js +429 -0
- package/dist/node/.lango/xmldom/dom-parser.js +591 -0
- package/dist/node/.lango/xmldom/dom.js +3759 -0
- package/dist/node/.lango/xmldom/entities.js +2171 -0
- package/dist/node/.lango/xmldom/errors.js +205 -0
- package/dist/node/.lango/xmldom/grammar.js +559 -0
- package/dist/node/.lango/xmldom/index.js +41 -0
- package/dist/node/.lango/xmldom/package.json +1 -0
- package/dist/node/.lango/xmldom/sax.js +983 -0
- package/dist/node/.lango/xmldom.LICENSE.md +8 -0
- package/dist/node/browser_host.mjs +351 -0
- package/dist/node/browser_host.mjs.map +1 -0
- package/dist/node/create_app.mjs +118 -0
- package/dist/node/create_app.mjs.map +1 -0
- package/dist/presentation.mjs +89 -0
- package/dist/presentation.mjs.map +1 -0
- package/dist/protocol.mjs +706 -0
- package/dist/protocol.mjs.map +1 -0
- package/dist/session.mjs +471 -0
- package/dist/session.mjs.map +1 -0
- package/dist/tokens.mjs +298 -0
- package/dist/tokens.mjs.map +1 -0
- package/examples/contacts.lango +293 -0
- package/examples/contacts_flow.lango +174 -0
- package/examples/contacts_store.lango +109 -0
- package/examples/contacts_store_test.lango +65 -0
- package/examples/demo.css +87 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +32 -0
- package/examples/pages.lango +174 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +68 -4
- package/src/application.lango +327 -0
- package/src/browser_host.lango +276 -0
- package/src/coordinator.lango +57 -0
- package/src/demo.lango +110 -0
- package/src/demo_controls.lango +53 -0
- package/src/errors.lango +149 -0
- package/src/errors_test.lango +157 -0
- package/src/form_state.lango +168 -0
- package/src/heartbeat.lango +230 -0
- package/src/heartbeat_test.lango +479 -0
- package/src/inheritance.lango +167 -0
- package/src/input_values.lango +37 -0
- package/src/library.lango +599 -0
- package/src/logout_test.lango +564 -0
- package/src/navigation.lango +309 -0
- package/src/navigation_test.lango +556 -0
- package/src/presentation.lango +55 -0
- package/src/protocol.lango +787 -0
- package/src/renderer_test.lango +2047 -0
- package/src/session.lango +343 -0
- package/src/session_test.lango +455 -0
- package/src/tabs_test.lango +216 -0
- package/src/tokens.lango +215 -0
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +9 -0
- package/template/README.md +44 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +10 -0
- package/template/public/index.html +24 -0
- package/template/src/client.lango +78 -0
- package/template/src/pages.lango +55 -0
- package/template/src/server.lango +24 -0
- package/template/src/worker.lango +77 -0
- package/template/test/app.lango +9 -0
- package/tools/browser_runner.lango +32 -0
- package/tools/browser_test.lango +343 -0
- package/tools/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import js global crypto\nimport \"./protocol\"\n collectValues(controls)\n applyResponse(controls, response, formId, seqno, effects)\nimport \"./inheritance\"\n normalizeInheritance(spec)\nimport \"./presentation\"\n classNames(value)\n styleMap(value)\n validateProperty(name, value)\nimport \"./input_values\"\n selectItems(options)\n selectIndex(items, value)\nimport \"./form_state\"\n rulesFor(value)\n validationMessage(rules, value)\n sameValue(left, right)\n\nexport mount(document, root, definition, types = null)\n\nexport class Types\n methods\n registerType(name, type)\n create(document, definition)\n\nTypes(options = null)\n if options != null and (!is_object(options) or is_array(options))\n throw \"UiControlRegistryOptionsMustBeMap\"\n @types = {\n }\n @classes = {\n }\n @sealed = false\n if options != null and options.classes != null\n if !is_object(options.classes) or is_array(options.classes)\n throw \"UiThemeClassesMustBeMap\"\n for options.classes as name: classes\n @classes[name] = classNames(classes)\n\nTypes:registerType(name, type)\n if @sealed\n throw \"UiControlRegistrySealed\"\n if !is_string(name) or name == \"\" or name == \"__proto__\" or name == \"prototype\" or name == \"constructor\" or !is_kindof(type, Function)\n throw \"UiControlTypeRequiresNameAndConstructor\"\n if name in @types\n throw \"UiDuplicateControlType: ${name}\"\n @types[name] = type\n return @this\n\nTypes:create(document, definition)\n @sealed = true\n if !is_object(definition) or !is_string(definition.type)\n throw \"UiControlRequiresDefinition\"\n prepared = {\n }\n for definition as name: value\n prepared[name] = value\n defaults = @classes[definition.type]\n if defaults != null\n prepared.classes = classNames(defaults.concat(classNames(definition.classes)))\n type = Control\n if definition.type in @types\n type = @types[definition.type]\n control = new type(document, prepared, @this)\n if !is_kindof(control, Control)\n throw \"UiCustomControlMustExtendControl\"\n return control\n\nexport class Binding\n methods\n handle(event)\n report(error)\n dispose()\n\nBinding(form, session, errors = null)\n @form = form\n @session = session\n @errors = errors\n @disposed = false\n root = form.element\n if root.langoBinding != null\n throw \"UiFormAlreadyBound\"\n listener = (event)\n handle(event)\n @listener = listener\n for [\"click\", \"change\", \"input\"] as type\n root.addEventListener(type, listener)\n root.langoBinding = @this\n\nBinding:handle(event)\n if @disposed\n return null\n root = @form.element\n element = event.target\n target = null\n current = element\n loop while current != null\n if current.inert == true or current.disabled == true or current.hidden == true\n return null\n if current == root\n break\n if current.langoFormRoot == true\n return null\n if target == null\n target = eventTarget(@form.controls, current, [], event.type)\n current = current.parentNode\n if current != root\n return null\n if event.type == \"input\" or event.type == \"change\"\n validateEvent(@form.controls, event.target, root)\n if target == null\n return null\n try\n event.preventDefault()\n if @errors != null and @errors.clear != null\n @errors.clear()\n session = @session\n return session.send(target.url, event.type, target.name).catch((error)\n report(error)\n )\n catch error\n report(error)\n return null\n\nvalidateEvent(controls, element, root)\n current = element\n loop while current != null and current != root\n control = elementControl(controls, current)\n if control != null and control.validate != null\n control.validate()\n return null\n current = current.parentNode\n return null\n\nelementControl(controls, element)\n for controls as control\n if control.element.langoFormRoot == true\n continue\n if control.element == element\n return control\n if is_array(control.controls)\n found = elementControl(control.controls, element)\n if found != null\n return found\n return null\n\nBinding: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\nBinding:dispose()\n if @disposed\n return null\n @disposed = true\n root = @form.element\n for [\"click\", \"change\", \"input\"] as type\n root.removeEventListener(type, @listener)\n root.langoBinding = null\n return null\n\neventTarget(controls, element, parentPath, type)\n for controls as control\n path = parentPath.slice()\n if control.name != null and control.name != \"\"\n path[path.length] = control.name\n if control.element == element\n events = control.events\n if type in events\n name = path\n if path.length == 1\n name = path[0]\n if path.length == 0\n name = null\n return {\n url: events[type]\n name: name\n }\n if is_array(control.controls)\n target = eventTarget(control.controls, element, path, type)\n if target != null\n return target\n return null\n\ncontrolEvents(definition)\n events = {\n }\n if definition.event != null\n type = \"change\"\n if definition.type == \"Button\"\n type = \"click\"\n events[type] = definition.event\n if definition.events != null\n if not is_object(definition.events)\n throw \"UiClientEventsMustBeMap\"\n for definition.events as type: url\n if type != \"click\" and type != \"change\" and type != \"input\"\n throw \"UiClientUnsupportedEventType\"\n events[type] = url\n for events as type: url\n if !is_string(url) or !url.startsWith(\"/\") or url.startsWith(\"//\") or url.includes(\"\\\\\")\n throw \"UiClientEventRequiresSameOriginPath\"\n return events\n\nexport class Renderer\n methods\n create(definition)\n replace(old, replacement)\n remove(control)\n capture(control)\n restore(snapshot, operation)\n focus(control)\n toast(level, text)\n release(control)\n\nRenderer(document, types = null)\n @document = document\n @types = types\n if @types == null\n @types = new Types()\n\nRenderer:create(definition)\n return @types.create(@document, definition)\n\nRenderer:release(control)\n releaseControl(control)\n return null\n\nreleaseControl(control)\n if is_array(control.controls)\n for control.controls as child\n releaseControl(child)\n try\n if control.dispose != null\n control.dispose()\n catch error\n context log\n log.err(\"Control disposal failed: ${error}\")\n return null\n\nRenderer:replace(old, replacement)\n element = old.node\n element.parentNode.replaceChild(replacement.node, element)\n return null\n\nRenderer:remove(control)\n control.node.remove()\n return null\n\nRenderer:capture(control)\n element = control.node\n return {\n element: element\n parent: element.parentNode\n next: element.nextSibling\n }\n\nRenderer:restore(snapshot, operation)\n if operation.type == \"replace\"\n replacement = operation.new\n replacement.node.remove()\n if snapshot.parent != null\n snapshot.parent.insertBefore(snapshot.element, snapshot.next)\n return null\n\nRenderer:focus(control)\n control.element.focus()\n return null\n\nRenderer:toast(level, text)\n element = @document.createElement(\"div\")\n element.setAttribute(\"role\", \"status\")\n element.textContent = text\n @document.body.appendChild(element)\n return null\n\nexport class Control\n properties\n name\n element\n node\n controls\n events\n inherit\n validates\n confirms\n methods\n getValue()\n setValue(value)\n applyProperty(name, value)\n snapshotState()\n restoreState(snapshot)\n dispose()\n isDirty()\n markClean()\n acceptSaved(value)\n validate()\n reportValidity()\n reportPendingError()\n\nControl(document, definition, types = null, options = null)\n @name = definition.name\n @type = definition.type\n @controls = null\n @value = definition.value\n @clean = null\n @error = null\n @pendingError = false\n @rules = rulesFor(definition.validation)\n @tracked = definition.trackChanges\n if @tracked == null\n @tracked = @type == \"Text\" or @type == \"Select\" or @type == \"Checkbox\"\n if !is_bool(@tracked)\n throw \"UiTrackChangesMustBeBoolean\"\n @validates = definition.validate\n if @validates == null\n @validates = false\n if !is_bool(@validates)\n throw \"UiValidateEventMustBeBoolean\"\n @confirms = definition.confirmDirty\n if @confirms == null\n @confirms = false\n if !is_bool(@confirms)\n throw \"UiConfirmDirtyMustBeBoolean\"\n @items = []\n if @type == \"Select\"\n @items = selectItems(definition.options)\n @events = controlEvents(definition)\n @inherit = normalizeInheritance(definition.inherit)\n @classes = classNames(definition.classes)\n @style = styleMap(definition.style)\n registry = types\n if registry == null\n registry = new Types()\n if definition.inherit != null and @type != \"Form\"\n throw \"UiInheritanceRequiresForm\"\n tag = \"div\"\n if @type == \"Text\" or @type == \"Checkbox\"\n tag = \"input\"\n if @type == \"Select\"\n tag = \"select\"\n if @type == \"Button\"\n tag = \"button\"\n if options != null\n tag = options.tag\n if !is_string(tag) or tag == \"\"\n throw \"UiCustomControlRequiresTag\"\n if options == null and @type != \"Text\" and @type != \"Button\" and @type != \"Value\" and @type != \"Panel\" and @type != \"Container\" and @type != \"Form\" and @type != \"Select\" and @type != \"Checkbox\"\n throw \"UiClientUnknownControlType\"\n @element = document.createElement(tag)\n @node = @element\n @errorElement = null\n element = @element\n if @type == \"Form\"\n element.langoFormRoot = true\n if @type == \"Button\"\n element.type = \"button\"\n element.textContent = definition.text\n if @type == \"Value\"\n element.hidden = true\n if @type == \"Checkbox\"\n element.type = \"checkbox\"\n if definition.label != null\n if !is_string(definition.label)\n throw \"UiControlLabelMustBeString\"\n element.setAttribute(\"aria-label\", definition.label)\n if tag == \"input\" or tag == \"select\"\n @node = document.createElement(\"label\")\n @node.className = \"lango-field\"\n @node.setAttribute(\"data-lango-control\", @type)\n caption = document.createElement(\"span\")\n caption.className = \"lango-caption\"\n caption.textContent = definition.label\n @node.appendChild(caption)\n @node.appendChild(element)\n @errorElement = document.createElement(\"span\")\n @errorElement.className = \"lango-field-error\"\n @errorElement.id = \"lango-error-${crypto/randomUUID()}\"\n @errorElement.hidden = true\n element.setAttribute(\"aria-describedby\", @errorElement.id)\n @node.appendChild(@errorElement)\n if tag == \"input\" or tag == \"select\"\n element.setAttribute(\"aria-required\", \"${@rules.required == true}\")\n container = @type == \"Panel\" or @type == \"Container\" or @type == \"Form\"\n if options != null and options.container == true\n container = true\n if container\n @controls = []\n try\n if @type == \"Select\"\n for @items as item\n option = document.createElement(\"option\")\n option.value = item.value\n option.textContent = item.text\n option.disabled = item.disabled\n element.appendChild(option)\n if container and is_array(definition.controls)\n for definition.controls as childDefinition\n child = registry.create(document, childDefinition)\n @controls.add(child)\n element.appendChild(child.node)\n if definition.classes != null\n applyProperty(\"classes\", definition.classes)\n if definition.style != null\n applyProperty(\"style\", definition.style)\n if definition.enabled != null\n applyProperty(\"enabled\", definition.enabled)\n if definition.visible != null\n applyProperty(\"visible\", definition.visible)\n initial = definition.value\n if @type == \"Checkbox\" and initial == null\n initial = false\n setValue(initial)\n markClean()\n catch error\n if is_array(@controls)\n for @controls as child\n releaseControl(child)\n throw error\n\nControl:getValue()\n if is_array(@controls)\n return collectValues(@controls)\n switch @type\n case \"Text\"\n return @element.value\n case \"Checkbox\"\n return @element.checked\n case \"Select\"\n index = @element.selectedIndex\n if index < 0 or index >= @items.length\n return null\n return @items[index].value\n else\n return @value\n\nControl:setValue(value)\n switch @type\n case \"Text\"\n text = value\n if value == null\n text = \"\"\n @element.value = text\n case \"Checkbox\"\n if !is_bool(value)\n throw \"UiCheckboxValueMustBeBoolean\"\n @element.checked = value\n case \"Select\"\n @element.selectedIndex = selectIndex(@items, value)\n @value = value\n if @error != null\n validate()\n return null\n\nControl:isDirty()\n if is_array(@controls)\n for @controls as child\n if child.isDirty != null\n if child.isDirty()\n return true\n return false\n if !@tracked\n return false\n current = from_json(to_json(getValue()))\n return !sameValue(current, @clean)\n\nControl:markClean()\n if is_array(@controls)\n for @controls as child\n if child.markClean != null\n child.markClean()\n else\n acceptSaved(getValue())\n return null\n\nControl:acceptSaved(value)\n @clean = from_json(to_json(value))\n return null\n\nControl:validate()\n @pendingError = false\n @error = validationMessage(@rules, getValue())\n renderError()\n return @error\n\nControl:renderError()\n text = @error\n if text == null\n text = \"\"\n @element.setAttribute(\"aria-invalid\", \"${@error != null}\")\n @element.setAttribute(\"data-lango-error\", text)\n if @errorElement != null\n @errorElement.textContent = text\n @errorElement.hidden = @error == null\n if @element.setCustomValidity != null\n @element.setCustomValidity(text)\n return null\n\nControl:reportValidity()\n if @element.reportValidity != null\n return @element.reportValidity()\n return @error == null\n\nControl:reportPendingError()\n if !@pendingError\n return false\n current = @element\n loop while current != null\n if current.disabled == true or current.hidden == true or current.inert == true\n return false\n current = current.parentNode\n @pendingError = false\n reportValidity()\n return true\n\nControl:applyProperty(name, value)\n validateProperty(name, value)\n switch name\n case \"enabled\"\n @element.disabled = !value\n @element.inert = !value\n @node.inert = !value\n case \"visible\"\n @element.hidden = !value or @type == \"Value\"\n @node.hidden = @element.hidden\n case \"classes\"\n @classes = classNames(value)\n @element.className = @classes.join(\" \")\n case \"style\"\n styles = styleMap(value)\n for @style as property: text\n @element.style.removeProperty(property)\n for styles as property: text\n @element.style.setProperty(property, text)\n @style = styles\n case \"savedValue\"\n acceptSaved(value)\n case \"error\"\n @error = value\n @pendingError = value != null\n renderError()\n reportPendingError()\n return null\n\nControl:snapshotState()\n return {\n value: @value\n text: @element.value\n checked: @element.checked\n selectedIndex: @element.selectedIndex\n disabled: @element.disabled\n hidden: @element.hidden\n inert: @element.inert\n classes: @element.className\n style: @element.style.cssText\n managedStyle: @style\n managedClasses: @classes\n clean: @clean\n error: @error\n pendingError: @pendingError\n }\n\nControl:restoreState(snapshot)\n setValue(snapshot.value)\n if @type == \"Text\"\n @element.value = snapshot.text\n if @type == \"Checkbox\"\n @element.checked = snapshot.checked\n if @type == \"Select\"\n @element.selectedIndex = snapshot.selectedIndex\n @element.disabled = snapshot.disabled\n @element.hidden = snapshot.hidden\n @element.inert = snapshot.inert\n @node.hidden = snapshot.hidden\n @node.inert = snapshot.inert\n @element.className = snapshot.classes\n @element.style.cssText = snapshot.style\n @style = snapshot.managedStyle\n @classes = snapshot.managedClasses\n @clean = snapshot.clean\n @error = snapshot.error\n @pendingError = snapshot.pendingError\n renderError()\n return null\n\nControl:dispose()\n return null\n\nmount(document, root, definition, types = null)\n if types == null\n types = new Types()\n control = types.create(document, definition)\n root.appendChild(control.node)\n return control\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA7JA;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;AAwWA;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostGlobal as __hostGlobal,
|
|
3
|
+
contextGet as __contextGet,
|
|
4
|
+
contextSet as __contextSet,
|
|
5
|
+
contextRestore as __contextRestore,
|
|
6
|
+
getClass as __getClass,
|
|
7
|
+
isKindof as __isKindof,
|
|
8
|
+
isNumber as __isNumber,
|
|
9
|
+
isString as __isString,
|
|
10
|
+
isBool as __isBool,
|
|
11
|
+
isObject as __isObject,
|
|
12
|
+
isArray as __isArray,
|
|
13
|
+
entries as __entries,
|
|
14
|
+
requireBoolean as __requireBoolean,
|
|
15
|
+
normalize as __normalize,
|
|
16
|
+
finite as __finite,
|
|
17
|
+
numericAdd as __numericAdd,
|
|
18
|
+
call as __call,
|
|
19
|
+
boundary as __boundary,
|
|
20
|
+
requireArity as __requireArity,
|
|
21
|
+
withArity as __withArity,
|
|
22
|
+
} from "./.lango/runtime.mjs";
|
|
23
|
+
|
|
24
|
+
export class Navigation {
|
|
25
|
+
url;
|
|
26
|
+
#window;
|
|
27
|
+
#document;
|
|
28
|
+
#onUrl;
|
|
29
|
+
#errors;
|
|
30
|
+
#redirect;
|
|
31
|
+
#guard;
|
|
32
|
+
#owner;
|
|
33
|
+
#position;
|
|
34
|
+
#restoring;
|
|
35
|
+
#started;
|
|
36
|
+
#disposed;
|
|
37
|
+
#last;
|
|
38
|
+
#initial;
|
|
39
|
+
#tail;
|
|
40
|
+
#click;
|
|
41
|
+
#pop;
|
|
42
|
+
#hash;
|
|
43
|
+
constructor(window, options) {
|
|
44
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
45
|
+
window = __boundary(window);
|
|
46
|
+
options = __boundary(options);
|
|
47
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(options))) || __requireBoolean(!__requireBoolean(__isKindof(__normalize(options.onUrl), Function))))) {
|
|
48
|
+
throw "UiNavigationRequiresUrlHandler";
|
|
49
|
+
}
|
|
50
|
+
this.#window = window;
|
|
51
|
+
this.#document = __normalize(window.document);
|
|
52
|
+
this.#onUrl = __normalize(options.onUrl);
|
|
53
|
+
this.#errors = __normalize(options.errors);
|
|
54
|
+
this.#redirect = __normalize(options.rootRedirect);
|
|
55
|
+
this.#guard = __normalize(options.beforeNavigate);
|
|
56
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#guard) !== null) && __requireBoolean(!__requireBoolean(__isKindof(__normalize(this.#guard), Function))))) {
|
|
57
|
+
throw "UiNavigationGuardRequiresFunction";
|
|
58
|
+
}
|
|
59
|
+
this.#owner = __normalize(__hostGlobal(["crypto"]).randomUUID());
|
|
60
|
+
this.#position = 0;
|
|
61
|
+
this.#restoring = false;
|
|
62
|
+
this.#started = false;
|
|
63
|
+
this.#disposed = false;
|
|
64
|
+
this.#last = null;
|
|
65
|
+
this.url = null;
|
|
66
|
+
this.#initial = null;
|
|
67
|
+
this.#tail = __normalize(__hostGlobal(["Promise"]).resolve());
|
|
68
|
+
this.#click = null;
|
|
69
|
+
this.#pop = null;
|
|
70
|
+
this.#hash = null;
|
|
71
|
+
if (__requireBoolean(__normalize(this.#redirect) !== null)) {
|
|
72
|
+
this.#parseUrl(__normalize(this.#redirect));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
#parseUrl(value) {
|
|
76
|
+
__requireArity(arguments.length, [0], "parseUrl");
|
|
77
|
+
value = __boundary(value);
|
|
78
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(value === "")) || __requireBoolean(__normalize(value.includes("\\"))))) {
|
|
79
|
+
throw "UiNavigationRequiresSameOriginUrl";
|
|
80
|
+
}
|
|
81
|
+
let location = __normalize(this.#window.location);
|
|
82
|
+
let target = new (__hostGlobal(["URL"]))(value, __normalize(location.href));
|
|
83
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(target.origin) !== __normalize(location.origin)) || __requireBoolean(__requireBoolean(__normalize(target.protocol) !== "http:") && __requireBoolean(__normalize(target.protocol) !== "https:"))) || __requireBoolean(__normalize(target.username) !== "")) || __requireBoolean(__normalize(target.password) !== ""))) {
|
|
84
|
+
throw "UiNavigationRequiresSameOriginUrl";
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
start() {
|
|
90
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
91
|
+
throw "UiNavigationDisposed";
|
|
92
|
+
}
|
|
93
|
+
if (__requireBoolean(__normalize(this.#started))) {
|
|
94
|
+
return __normalize(this.#initial);
|
|
95
|
+
}
|
|
96
|
+
let location = __normalize(this.#window.location);
|
|
97
|
+
if (__requireBoolean(__requireBoolean(__normalize(location.pathname) === "/") && __requireBoolean(__normalize(this.#redirect) !== null))) {
|
|
98
|
+
let target = this.#parseUrl(__normalize(this.#redirect));
|
|
99
|
+
if (__requireBoolean(__normalize(target.search) === "")) {
|
|
100
|
+
target.search = __normalize(location.search);
|
|
101
|
+
}
|
|
102
|
+
if (__requireBoolean(__normalize(target.hash) === "")) {
|
|
103
|
+
target.hash = __normalize(location.hash);
|
|
104
|
+
}
|
|
105
|
+
__normalize(this.#window.history.replaceState(null, "", localUrl(target)));
|
|
106
|
+
}
|
|
107
|
+
this.#started = true;
|
|
108
|
+
__normalize(this.#window.history.replaceState(this.#historyState(0, localUrl(__normalize(this.#window.location))), "", localUrl(__normalize(this.#window.location))));
|
|
109
|
+
let click = __withArity((event) => {
|
|
110
|
+
event = __boundary(event);
|
|
111
|
+
this.#clickEvent(event);
|
|
112
|
+
return null;
|
|
113
|
+
}, [0], "closure");
|
|
114
|
+
let pop = __withArity((event) => {
|
|
115
|
+
event = __boundary(event);
|
|
116
|
+
this.#historyEvent("history");
|
|
117
|
+
return null;
|
|
118
|
+
}, [0], "closure");
|
|
119
|
+
let hash = __withArity((event) => {
|
|
120
|
+
event = __boundary(event);
|
|
121
|
+
this.#historyEvent("hash");
|
|
122
|
+
return null;
|
|
123
|
+
}, [0], "closure");
|
|
124
|
+
this.#click = click;
|
|
125
|
+
this.#pop = pop;
|
|
126
|
+
this.#hash = hash;
|
|
127
|
+
__normalize(this.#document.addEventListener("click", click));
|
|
128
|
+
__normalize(this.#window.addEventListener("popstate", pop));
|
|
129
|
+
__normalize(this.#window.addEventListener("hashchange", hash));
|
|
130
|
+
this.#initial = this.#notify("start");
|
|
131
|
+
return __normalize(this.#initial);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
navigate(url, replace = false) {
|
|
135
|
+
__requireArity(arguments.length, [0], "navigate");
|
|
136
|
+
url = __boundary(url);
|
|
137
|
+
replace = __boundary(replace);
|
|
138
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
139
|
+
throw "UiNavigationDisposed";
|
|
140
|
+
}
|
|
141
|
+
if (__requireBoolean(!__requireBoolean(__normalize(this.#started)))) {
|
|
142
|
+
throw "UiNavigationNotStarted";
|
|
143
|
+
}
|
|
144
|
+
if (__requireBoolean(__normalize(this.#restoring))) {
|
|
145
|
+
throw "UiNavigationRestoringHistory";
|
|
146
|
+
}
|
|
147
|
+
if (__requireBoolean(!__requireBoolean(__isBool(replace)))) {
|
|
148
|
+
throw "UiNavigationReplaceMustBeBoolean";
|
|
149
|
+
}
|
|
150
|
+
let target = this.#parseUrl(url);
|
|
151
|
+
let path = localUrl(target);
|
|
152
|
+
if (__requireBoolean(path === localUrl(__normalize(this.#window.location)))) {
|
|
153
|
+
if (__requireBoolean(__normalize(this.#last) === null)) {
|
|
154
|
+
if (__requireBoolean(!__requireBoolean(this.#canNavigate(path, "navigate")))) {
|
|
155
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(false));
|
|
156
|
+
}
|
|
157
|
+
return this.#notify("navigate");
|
|
158
|
+
}
|
|
159
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
160
|
+
}
|
|
161
|
+
if (__requireBoolean(!__requireBoolean(this.#canNavigate(path, "navigate")))) {
|
|
162
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(false));
|
|
163
|
+
}
|
|
164
|
+
if (__requireBoolean(replace)) {
|
|
165
|
+
__normalize(this.#window.history.replaceState(this.#historyState(__normalize(this.#position), path), "", path));
|
|
166
|
+
} else {
|
|
167
|
+
this.#position = __numericAdd(__normalize(this.#position), 1);
|
|
168
|
+
__normalize(this.#window.history.pushState(this.#historyState(__normalize(this.#position), path), "", path));
|
|
169
|
+
}
|
|
170
|
+
return this.#notify("navigate");
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
#canNavigate(path, source) {
|
|
174
|
+
__requireArity(arguments.length, [0, 1], "canNavigate");
|
|
175
|
+
path = __boundary(path);
|
|
176
|
+
source = __boundary(source);
|
|
177
|
+
if (__requireBoolean(__normalize(this.#guard) === null)) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
let callback = __normalize(this.#guard);
|
|
181
|
+
let result = __call(callback, { url: path, source: source });
|
|
182
|
+
if (__requireBoolean(!__requireBoolean(__isBool(result)))) {
|
|
183
|
+
if (__requireBoolean(__requireBoolean(result !== null) && __requireBoolean(__isKindof(__normalize(result.then), Function)))) {
|
|
184
|
+
recovered(__normalize(__hostGlobal(["Promise"]).resolve(result)));
|
|
185
|
+
}
|
|
186
|
+
throw "UiNavigationGuardMustReturnBoolean";
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
#historyState(position, path) {
|
|
192
|
+
__requireArity(arguments.length, [0, 1], "historyState");
|
|
193
|
+
position = __boundary(position);
|
|
194
|
+
path = __boundary(path);
|
|
195
|
+
let result = { };
|
|
196
|
+
let previous = __normalize(this.#window.history.state);
|
|
197
|
+
if (__requireBoolean(__requireBoolean(__isObject(previous)) && __requireBoolean(!__requireBoolean(__isArray(previous))))) {
|
|
198
|
+
for (const [name, value] of __entries(previous)) {
|
|
199
|
+
result[name] = value;
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
if (__requireBoolean(previous !== null)) {
|
|
203
|
+
result.previousState = previous;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
result["__langoNavigation"] = { owner: __normalize(this.#owner), index: position, url: path };
|
|
207
|
+
return result;
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
#historyEvent(source) {
|
|
211
|
+
__requireArity(arguments.length, [0], "historyEvent");
|
|
212
|
+
source = __boundary(source);
|
|
213
|
+
try {
|
|
214
|
+
this.#moveHistory(source);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
this.#report(error);
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
#moveHistory(source) {
|
|
222
|
+
__requireArity(arguments.length, [0], "moveHistory");
|
|
223
|
+
source = __boundary(source);
|
|
224
|
+
let path = localUrl(__normalize(this.#window.location));
|
|
225
|
+
let state = __normalize(this.#window.history.state);
|
|
226
|
+
let marker = null;
|
|
227
|
+
if (__requireBoolean(state !== null)) {
|
|
228
|
+
marker = __normalize(state["__langoNavigation"]);
|
|
229
|
+
}
|
|
230
|
+
if (__requireBoolean(__normalize(this.#restoring))) {
|
|
231
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(path === __normalize(this.url)) && __requireBoolean(marker !== null)) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner))) && __requireBoolean(__normalize(marker.index) === __normalize(this.#position)))) {
|
|
232
|
+
this.#restoring = false;
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
if (__requireBoolean(path === __normalize(this.url))) {
|
|
237
|
+
if (__requireBoolean(__requireBoolean(marker !== null) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner)))) {
|
|
238
|
+
this.#position = __normalize(marker.index);
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
let position = __numericAdd(__normalize(this.#position), 1);
|
|
243
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(marker !== null) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner))) && __requireBoolean(__normalize(marker.url) === path))) {
|
|
244
|
+
position = __normalize(marker.index);
|
|
245
|
+
}
|
|
246
|
+
let allowed = false;
|
|
247
|
+
try {
|
|
248
|
+
allowed = this.#canNavigate(path, source);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
this.#restoreHistory(position);
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
if (__requireBoolean(!__requireBoolean(allowed))) {
|
|
254
|
+
this.#restoreHistory(position);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
this.#position = position;
|
|
258
|
+
__normalize(this.#window.history.replaceState(this.#historyState(position, path), "", path));
|
|
259
|
+
this.#observe(this.#notify(source));
|
|
260
|
+
return null;
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
#restoreHistory(position) {
|
|
264
|
+
__requireArity(arguments.length, [0], "restoreHistory");
|
|
265
|
+
position = __boundary(position);
|
|
266
|
+
if (__requireBoolean(position === __normalize(this.#position))) {
|
|
267
|
+
__normalize(this.#window.history.replaceState(this.#historyState(__normalize(this.#position), __normalize(this.url)), "", __normalize(this.url)));
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
this.#restoring = true;
|
|
271
|
+
__normalize(this.#window.history.go(__finite(__normalize(this.#position) - position)));
|
|
272
|
+
return null;
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
#notify(source) {
|
|
276
|
+
__requireArity(arguments.length, [0], "notify");
|
|
277
|
+
source = __boundary(source);
|
|
278
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
279
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
280
|
+
}
|
|
281
|
+
let path = localUrl(__normalize(this.#window.location));
|
|
282
|
+
this.url = path;
|
|
283
|
+
if (__requireBoolean(path === __normalize(this.#last))) {
|
|
284
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
285
|
+
}
|
|
286
|
+
this.#last = path;
|
|
287
|
+
let work = this.#deliver(__normalize(this.#tail), { url: path, source: source });
|
|
288
|
+
this.#tail = recovered(work);
|
|
289
|
+
return work;
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
refresh() {
|
|
293
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
294
|
+
throw "UiNavigationDisposed";
|
|
295
|
+
}
|
|
296
|
+
if (__requireBoolean(!__requireBoolean(__normalize(this.#started)))) {
|
|
297
|
+
throw "UiNavigationNotStarted";
|
|
298
|
+
}
|
|
299
|
+
if (__requireBoolean(__normalize(this.#restoring))) {
|
|
300
|
+
throw "UiNavigationRestoringHistory";
|
|
301
|
+
}
|
|
302
|
+
if (__requireBoolean(!__requireBoolean(this.#canNavigate(localUrl(__normalize(this.#window.location)), "refresh")))) {
|
|
303
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(false));
|
|
304
|
+
}
|
|
305
|
+
this.#last = null;
|
|
306
|
+
return this.#notify("refresh");
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
#deliver(ready, event) {
|
|
310
|
+
__requireArity(arguments.length, [0, 1], "deliver");
|
|
311
|
+
ready = __boundary(ready);
|
|
312
|
+
event = __boundary(event);
|
|
313
|
+
return ready.then(() => {
|
|
314
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
let callback = __normalize(this.#onUrl);
|
|
318
|
+
return __call(callback, event);
|
|
319
|
+
return null;
|
|
320
|
+
}).catch(__withArity((error) => {
|
|
321
|
+
error = __boundary(error);
|
|
322
|
+
if (__requireBoolean(__normalize(this.#last) === __normalize(event.url))) {
|
|
323
|
+
this.#last = null;
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
return null;
|
|
327
|
+
}, [0], "closure"));
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
#observe(work) {
|
|
331
|
+
__requireArity(arguments.length, [0], "observe");
|
|
332
|
+
work = __boundary(work);
|
|
333
|
+
work.catch(__withArity((error) => {
|
|
334
|
+
error = __boundary(error);
|
|
335
|
+
this.#report(error);
|
|
336
|
+
return null;
|
|
337
|
+
}, [0], "closure"));
|
|
338
|
+
return null;
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
#report(error) {
|
|
342
|
+
const __contextScope = [];
|
|
343
|
+
try {
|
|
344
|
+
__requireArity(arguments.length, [0], "report");
|
|
345
|
+
error = __boundary(error);
|
|
346
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
if (__requireBoolean(__normalize(this.#errors) !== null)) {
|
|
350
|
+
__normalize(this.#errors.error(error));
|
|
351
|
+
} else {
|
|
352
|
+
__normalize(__contextGet("log").err(error));
|
|
353
|
+
}
|
|
354
|
+
return null;
|
|
355
|
+
return null;
|
|
356
|
+
} finally {
|
|
357
|
+
__contextRestore(__contextScope);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
#clickEvent(event) {
|
|
361
|
+
__requireArity(arguments.length, [0], "clickEvent");
|
|
362
|
+
event = __boundary(event);
|
|
363
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(event.defaultPrevented) === true)) || __requireBoolean(__normalize(event.metaKey) === true)) || __requireBoolean(__normalize(event.ctrlKey) === true)) || __requireBoolean(__normalize(event.shiftKey) === true)) || __requireBoolean(__normalize(event.altKey) === true))) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
if (__requireBoolean(__requireBoolean(__normalize(event.button) !== null) && __requireBoolean(__normalize(event.button) !== 0))) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
let anchor = this.#link(__normalize(event.target));
|
|
370
|
+
if (__requireBoolean(__requireBoolean(anchor === null) || __requireBoolean(__normalize(anchor.hasAttribute("download"))))) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
let href = __normalize(anchor.getAttribute("href"));
|
|
374
|
+
if (__requireBoolean(__requireBoolean(href === null) || __requireBoolean(href === ""))) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
let target = __normalize(anchor.getAttribute("target"));
|
|
378
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(target !== null) && __requireBoolean(target !== "")) && __requireBoolean(__normalize(target.toLowerCase()) !== "_self"))) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
try {
|
|
382
|
+
let destination = new (__hostGlobal(["URL"]))(href, __normalize(this.#window.location.href));
|
|
383
|
+
if (__requireBoolean(__requireBoolean(__normalize(destination.protocol) !== "http:") && __requireBoolean(__normalize(destination.protocol) !== "https:"))) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
let location = __normalize(this.#window.location);
|
|
387
|
+
if (__requireBoolean(__normalize(destination.origin) !== __normalize(location.origin))) {
|
|
388
|
+
if (__requireBoolean(target === null)) {
|
|
389
|
+
__normalize(anchor.setAttribute("target", "_blank"));
|
|
390
|
+
let rel = __normalize(anchor.getAttribute("rel"));
|
|
391
|
+
if (__requireBoolean(__requireBoolean(rel === null) || __requireBoolean(rel === ""))) {
|
|
392
|
+
rel = "noopener";
|
|
393
|
+
} else {
|
|
394
|
+
if (__requireBoolean(!__requireBoolean(__normalize(__normalize(rel.split(" ")).includes("noopener"))))) {
|
|
395
|
+
rel = `${rel} noopener`;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
__normalize(anchor.setAttribute("rel", rel));
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(destination.pathname) === __normalize(location.pathname)) && __requireBoolean(__normalize(destination.search) === __normalize(location.search))) && __requireBoolean(__requireBoolean(__normalize(destination.hash) !== __normalize(location.hash)) || __requireBoolean(__normalize(href.includes("#")))))) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
__normalize(event.preventDefault());
|
|
406
|
+
this.#observe(this.navigate(__normalize(destination.href)));
|
|
407
|
+
} catch (error) {
|
|
408
|
+
this.#report(error);
|
|
409
|
+
}
|
|
410
|
+
return null;
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
#link(element) {
|
|
414
|
+
__requireArity(arguments.length, [0], "link");
|
|
415
|
+
element = __boundary(element);
|
|
416
|
+
let current = element;
|
|
417
|
+
let found = null;
|
|
418
|
+
__loop1: while (__requireBoolean(current !== null)) {
|
|
419
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.inert) === true) || __requireBoolean(__normalize(current.hidden) === true)) || __requireBoolean(__normalize(current.disabled) === true))) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
let name = __normalize(current.tagName);
|
|
423
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(found === null) && __requireBoolean(__isString(name))) && __requireBoolean(__normalize(name.toLowerCase()) === "a"))) {
|
|
424
|
+
found = current;
|
|
425
|
+
}
|
|
426
|
+
current = __normalize(current.parentNode);
|
|
427
|
+
}
|
|
428
|
+
return found;
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
idle() {
|
|
432
|
+
return __normalize(this.#tail);
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
dispose() {
|
|
436
|
+
if (__requireBoolean(__normalize(this.#disposed))) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
this.#disposed = true;
|
|
440
|
+
if (__requireBoolean(__normalize(this.#started))) {
|
|
441
|
+
__normalize(this.#document.removeEventListener("click", __normalize(this.#click)));
|
|
442
|
+
__normalize(this.#window.removeEventListener("popstate", __normalize(this.#pop)));
|
|
443
|
+
__normalize(this.#window.removeEventListener("hashchange", __normalize(this.#hash)));
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function localUrl(target) {
|
|
450
|
+
__requireArity(arguments.length, [0], "localUrl");
|
|
451
|
+
target = __boundary(target);
|
|
452
|
+
return `${__normalize(target.pathname)}${__normalize(target.search)}${__normalize(target.hash)}`;
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function recovered(work) {
|
|
457
|
+
__requireArity(arguments.length, [0], "recovered");
|
|
458
|
+
work = __boundary(work);
|
|
459
|
+
return work.catch(__withArity((error) => {
|
|
460
|
+
error = __boundary(error);
|
|
461
|
+
return null;
|
|
462
|
+
return null;
|
|
463
|
+
}, [0], "closure"));
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
//# sourceMappingURL=navigation.mjs.map
|
|
@@ -0,0 +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;;;;;;;;;;;"}
|