@lango-project/lango-client 0.4.1 → 0.4.2
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/README.md +26 -0
- package/cli/.lango/runtime.mjs +16 -0
- package/dist/.lango/runtime.mjs +16 -0
- package/dist/accordion.mjs +9 -8
- package/dist/accordion.mjs.map +1 -1
- package/dist/activities.mjs +8 -7
- package/dist/activities.mjs.map +1 -1
- package/dist/app.mjs +465 -50
- package/dist/app.mjs.map +1 -1
- package/dist/boot.mjs +3 -2
- package/dist/boot.mjs.map +1 -1
- package/dist/button.mjs +8 -7
- package/dist/button.mjs.map +1 -1
- package/dist/chip.mjs +5 -4
- package/dist/chip.mjs.map +1 -1
- package/dist/combo_box.mjs +15 -14
- package/dist/combo_box.mjs.map +1 -1
- package/dist/content.mjs +9 -8
- package/dist/content.mjs.map +1 -1
- package/dist/date_input.mjs +3 -2
- package/dist/date_input.mjs.map +1 -1
- package/dist/error_reporter.mjs +6 -5
- package/dist/error_reporter.mjs.map +1 -1
- package/dist/fields.mjs +9 -8
- package/dist/fields.mjs.map +1 -1
- package/dist/file_input.mjs +19 -18
- package/dist/file_input.mjs.map +1 -1
- package/dist/form.mjs +14 -2
- package/dist/form.mjs.map +1 -1
- package/dist/heartbeat.mjs +12 -11
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/input_changes.mjs +5 -4
- package/dist/input_changes.mjs.map +1 -1
- package/dist/longpoll.mjs +12 -11
- package/dist/longpoll.mjs.map +1 -1
- package/dist/main.mjs +35 -18
- package/dist/main.mjs.map +1 -1
- package/dist/menus.mjs +19 -18
- package/dist/menus.mjs.map +1 -1
- package/dist/navigation.mjs +7 -6
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +9 -8
- package/dist/numeric_input.mjs.map +1 -1
- package/dist/otp_input.mjs +5 -4
- package/dist/otp_input.mjs.map +1 -1
- package/dist/presentations.mjs +17 -16
- package/dist/presentations.mjs.map +1 -1
- package/dist/renderer.mjs +74 -0
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +3 -2
- package/dist/table_scope.mjs.map +1 -1
- package/dist/tables.mjs +11 -10
- package/dist/tables.mjs.map +1 -1
- package/dist/tabs.mjs +7 -6
- package/dist/tabs.mjs.map +1 -1
- package/dist/vendor/dompurify.mjs +267 -181
- package/dist/vendor/purify.es.mjs.map +1 -1
- package/dist/widgets.mjs +5 -4
- package/dist/widgets.mjs.map +1 -1
- package/package.json +4 -3
- package/src/app.lango +325 -11
- package/src/form.lango +12 -2
- package/src/heartbeat.lango +2 -2
- package/src/main.lango +15 -0
- package/src/renderer.lango +61 -0
package/dist/app.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.mjs","sources":["app.lango"],"sourcesContent":["import js global Error\nimport js global Object\nimport js global Promise\nimport js global URL\nimport js global Date\nimport \"./form\"\n class Form\nimport \"./heartbeat\"\n class Heartbeat\nimport \"./error_reporter\"\n class ErrorReporter\n\nexport class App(host, renderer)\n properties\n forms\n root\n renderer\n heartbeat\n resources\n reporter\n methods\n start()\n post(url, input, token)\n saveToken(token)\n clearSavedToken()\n send(form, url, owner = null)\n deliver(form, action, owner, generation)\n report(form, url, input, owner)\n executeDelivery(job)\n checkUrl(url)\n hostUrl()\n request(url, input, token, signal = null, channel = false, opening = false)\n poll(url, input, token, signal)\n canPoll(form)\n pausePolls(form = null)\n resumePolls()\n schedule(action, delay)\n cancelTimer(timer)\n now()\n error(form, error, code = \"UiFailure\", name = null)\n drain()\n execute(job)\n navigate(url, push = true)\n selectTemplate(path)\n ping()\n executePing(job)\n command(form, cmd)\n dispose()\n\nApp(host, renderer)\n @host = host\n @renderer = renderer\n @forms = []\n @queue = []\n @active = []\n @disposed = false\n @root = null\n @events = {}\n @template = null\n @heartbeat = null\n @pingJob = null\n @resources = []\n @reporter = null\n\nApp:now()\n if @host.now != null\n return @host.now()\n return Date/now()\n\nApp:hostUrl()\n return @host.location.href\n\nApp:schedule(action, delay)\n return @host.schedule(action, delay)\n\nApp:cancelTimer(timer)\n @host.cancelTimer(timer)\n return null\n\nApp:checkUrl(url)\n if !is_string(url) or url.trim() == \"\"\n throw \"UI request requires a URL\"\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI requests must use the current origin\"\n return target\n\nApp:error(form, error, code = \"UiFailure\", name = null)\n if form != null and form.requestForm != null\n form = form.requestForm\n if @disposed or form == null or form.disposed\n return null\n @renderer.reportError(form, error)\n if @reporter != null\n @reporter.capture(\"ui\", code, name, form)\n return null\n\nApp:saveToken(token)\n try\n @host.storage.setItem(\"lango.token\", token)\n catch error\n return null\n return null\n\nApp:clearSavedToken()\n try\n @host.storage.removeItem(\"lango.token\")\n return true\n catch error\n return false\n\nApp:post(url, input, token)\n return request(url, input, token)\n\nApp:poll(url, input, token, signal)\n return request(url, input, token, signal, true)\n\nApp:request(url, input, token, signal = null, channel = false, opening = false)\n target = checkUrl(url)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n headers[\"X-Lango-Screen\"] = \"wide\"\n if @host.screen != null\n headers[\"X-Lango-Screen\"] = @host.screen()\n if token != null\n headers.Authorization = \"Bearer ${token}\"\n options = {\n method: \"POST\"\n headers: headers\n body: to_json(input)\n }\n if signal != null\n options.signal = signal\n return chain @host.fetch(\"${target.pathname}${target.search}\", options)\n then(res)\n capture channel\n capture opening\n capture token\n if !res.ok\n if opening and res.status == 401 and token != null\n if clearSavedToken()\n throw new Error(\"Startup HTTP 401: saved token was rejected and cleared. Reload the page to start a new session.\")\n throw new Error(\"Startup HTTP 401: saved token was rejected but storage could not be cleared. Clear this site's local storage and reload.\")\n if !channel\n throw \"HTTP ${res.status}\"\n if res.status != 409\n return {\n status: res.status\n retryAfter: res.headers.get(\"retry-after\")\n }\n return chain res.json()\n then(body)\n capture res\n capture channel\n if !is_object(body) or is_array(body)\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw \"UI response must be a map\"\n status = res.status\n if status == null\n status = 200\n return {\n status: status\n token: res.headers.get(\"x-lango-token\")\n body: body\n }\n catch(error)\n capture channel\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw error\n\nApp:start()\n token = null\n try\n token = @host.storage.getItem(\"lango.token\")\n catch error\n token = null\n return chain request(\"/\", {}, token, null, false, true)\n then(packet)\n @events = packet.body\n if @events.clientErrorUrl != null\n @reporter = new ErrorReporter(@this, @events.clientErrorUrl)\n if @events.pingUrl != null\n @heartbeat = new Heartbeat(@this, @host, @events.pingUrl)\n @root = new Form(@this, null, packet.token)\n @root.element = @host.mount\n @root.setToken(packet.token)\n return chain navigate(@host.location.pathname, false)\n then(ignored)\n if @heartbeat != null\n @heartbeat.start()\n return null\n\nApp:send(form, url, owner = null)\n if @disposed or form.disposed\n return Promise/reject(\"Form is disposed\")\n pending = new Promise((resolve, reject)\n capture form\n capture url\n capture owner\n @queue.add({\n kind: \"send\"\n form: form\n url: url\n owner: owner\n resolve: resolve\n reject: reject\n })\n drain()\n )\n return pending\n\nApp:deliver(form, action, owner, generation)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n kind: \"delivery\"\n form: form\n action: action\n owner: owner\n generation: generation\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:report(form, url, input, owner)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n kind: \"report\"\n form: form\n url: url\n input: input\n owner: owner\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:canPoll(form)\n if @disposed or form.disposed or @pingJob != null\n return false\n for @active as job\n if form.related(job.form)\n return false\n for @queue as job\n if form.related(job.form)\n return false\n return true\n\nApp:pausePolls(form = null)\n for @forms.slice() as candidate\n if form == null or form.related(candidate)\n candidate.activity.pause()\n return null\n\nApp:resumePolls()\n for @forms.slice() as form\n form.activity.resume()\n return null\n\nApp:drain()\n if @pingJob != null\n if @active.length == 0 and !@pingJob.running\n @pingJob.running = true\n executePing(@pingJob)\n return null\n for @queue.slice() as job\n blocked = false\n for @active as running\n if job.form.related(running.form)\n blocked = true\n for @queue as earlier\n if earlier == job\n break\n if job.form.related(earlier.form)\n blocked = true\n if !blocked\n @queue.splice(@queue.indexOf(job), 1)\n @active.add(job)\n if job.kind == \"delivery\"\n executeDelivery(job)\n else\n pausePolls(job.form)\n execute(job)\n resumePolls()\n return null\n\nApp:executeDelivery(job)\n return chain Promise/resolve(null)\n then(ignored)\n capture job\n if !job.form.disposed and job.owner.active and job.owner.generation == job.generation\n action = job.action\n action()\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n @active.splice(@active.indexOf(job), 1)\n drain()\n\nApp:ping()\n if @disposed or @heartbeat == null\n return Promise/resolve(null)\n if @pingJob != null\n return @pingJob.promise\n deferred = Promise/withResolvers()\n @pingJob = {\n promise: deferred.promise\n resolve: deferred.resolve\n reject: deferred.reject\n running: false\n }\n pausePolls()\n drain()\n return deferred.promise\n\nApp:executePing(job)\n return chain Promise/resolve(null)\n then(ignored)\n return @heartbeat.exchange()\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n @pingJob = null\n drain()\n\nApp:execute(job)\n form = job.form\n return chain Promise/resolve(null)\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if job.owner != null and !job.owner.active\n return null\n if job.kind == \"report\"\n return post(job.url, job.input, form.token)\n form.clearValidation()\n @renderer.waiting(form, true)\n ready = form.prepareValue()\n if ready == null\n return post(job.url, form.getValue(), form.token)\n return chain ready\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if job.owner != null and !job.owner.active\n return null\n return post(job.url, form.getValue(), form.token)\n then(packet)\n capture form\n capture job\n if packet != null and !form.disposed and (job.owner == null or job.owner.active)\n if job.kind == \"report\"\n form.setToken(packet.token)\n else\n form.handle(packet)\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n capture form\n if job.kind == \"send\"\n @renderer.waiting(form, false)\n @active.splice(@active.indexOf(job), 1)\n drain()\n\nApp:navigate(url, push = true)\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI navigation must use the current origin\"\n path = target.pathname\n if path == \"/\"\n path = \"/index\"\n template = selectTemplate(path)\n ready = Promise/resolve(null)\n if template != @template\n if template != null\n ready = @root.send(template)\n else\n @template = null\n return chain ready\n then(ignored)\n capture template\n capture path\n capture Form\n @template = template\n form = @root\n if template != null\n form = @root.find(\"__content__\")\n if !is_kindof(form, Form)\n throw \"Template requires a __content__ form\"\n return form.send(path)\n then(ignored)\n capture target\n capture push\n if push\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n return null\n\nApp:selectTemplate(path)\n urls = @events.templates\n if urls == null\n urls = []\n selected = @events.defaultTemplate\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n best = 0\n for urls as url\n if !is_string(url) or !url.startsWith(\"/\") or url == \"/\" or url.endsWith(\"/\")\n throw \"Invalid template URL\"\n if path == url\n throw \"Template URLs cannot be used as page URLs\"\n if path == url or path.startsWith(\"${url}/\")\n if url.length > best\n selected = url\n best = url.length\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n return selected\n\nApp:command(form, cmd)\n switch cmd.type\n case \"values\"\n form.setValue(cmd.values)\n case \"addRow\"\n form.find(cmd.name).addRow(cmd.value)\n case \"insertRow\"\n form.find(cmd.name).insertRow(cmd.beforeIndex, cmd.value)\n case \"deleteRow\"\n form.find(cmd.name).deleteRow(cmd.index)\n case \"setRowValue\"\n form.find(cmd.name).setRowValue(cmd.index, cmd.value)\n case \"setRowData\"\n form.find(cmd.name).setRowData(cmd.index, cmd.value)\n case \"setCellValue\"\n form.find(cmd.name).setCellValue(cmd.index, cmd.column, cmd.value)\n case \"invalid\"\n form.find(cmd.name).setInvalid(cmd.message)\n case \"set\"\n targetForm = form.find(cmd.name)\n if !is_kindof(targetForm, Form)\n throw \"Set requires a form target\"\n @renderer.show(targetForm, cmd.control)\n case \"setUrl\"\n target = new URL(cmd.url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI URL must use the current origin\"\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n case \"redirect\"\n action = ()\n capture cmd\n chain navigate(cmd.url)\n catch(problem)\n capture form\n error(form, problem)\n @host.defer(action)\n case \"disable\"\n form.find(cmd.name).setDisabled(true)\n case \"enable\"\n form.find(cmd.name).setDisabled(false)\n case \"changeCaption\"\n form.find(cmd.name).setCaption(cmd.caption)\n case \"activateTabItem\"\n form.find(cmd.name).activate()\n case \"setProgress\"\n form.find(cmd.name).setRange(cmd.min, cmd.max, cmd.value)\n case \"updateProgress\"\n form.find(cmd.name).update(cmd.value, cmd.label)\n case \"showAlert\"\n @renderer.presentations.showAlert(form, cmd)\n case \"dismissAlert\"\n @renderer.presentations.dismissAlert(form, cmd.name)\n case \"showToast\"\n @renderer.presentations.showToast(form, cmd.toast, cmd.stack)\n case \"showDialog\"\n @renderer.presentations.showDialog(form, cmd.dialog, cmd.keepPrev)\n case \"swapDialog\"\n @renderer.presentations.swapDialog(form)\n case \"setTimer\"\n form.activity.timer(cmd.url, cmd.interval)\n case \"clearTimer\"\n form.activity.clearTimer(cmd.url)\n case \"setInterval\"\n form.activity.timer(cmd.url, cmd.interval, true)\n case \"clearInterval\"\n form.activity.clearTimer(cmd.url, true)\n case \"startLongPoll\"\n form.activity.startLongPoll(cmd.url, cmd.key, cmd.cursor)\n case \"stopLongPoll\"\n form.activity.stopLongPoll(cmd.url, cmd.key)\n else\n throw \"Unsupported UI command: ${cmd.type}\"\n return null\n\nApp:dispose()\n @disposed = true\n if @heartbeat != null\n @heartbeat.dispose()\n if @reporter != null\n @reporter.dispose()\n for @forms.slice() as form\n form.dispose()\n for @queue as job\n job.reject(\"Application is disposed\")\n @queue = []\n for @resources as release\n release()\n @resources = []\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"app.mjs","sources":["app.lango"],"sourcesContent":["import js global crypto\nimport js global Error\nimport js global Object\nimport js global Promise\nimport js global URL\nimport js global Date\nimport \"./form\"\n class Form\nimport \"./heartbeat\"\n class Heartbeat\nimport \"./error_reporter\"\n class ErrorReporter\n\nexport class App(host, renderer)\n properties\n forms\n root\n renderer\n heartbeat\n resources\n reporter\n methods\n start()\n acceptEvents(events)\n post(url, input, token)\n saveToken(token)\n clearSavedToken()\n send(form, url, owner = null)\n deliver(form, action, owner, generation)\n report(form, url, input, owner)\n executeDelivery(job)\n checkUrl(url)\n hostUrl()\n request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)\n sendInput(job, input)\n resumeInput(job, input, challenge)\n needLogin(job, challenge)\n finishLogin(form, userId)\n completeLogin(form)\n beginLoginResponse(form, packet)\n observeAuthentication(form, previous, packet)\n commitAuthentication(source, previous, token, change)\n externalAuthentication(change)\n invalidateForm(form)\n reloadSession()\n cancelLogin(problem = \"LoginCancelled\")\n loginScopeDisposed(form)\n poll(url, input, token, signal)\n canPoll(form)\n pausePolls(form = null)\n resumePolls()\n schedule(action, delay)\n cancelTimer(timer)\n now()\n error(form, error, code = \"UiFailure\", name = null)\n drain()\n execute(job)\n navigate(url, push = true)\n selectTemplate(path)\n ping()\n executePing(job)\n command(form, cmd)\n dispose()\n\nApp(host, renderer)\n @host = host\n @renderer = renderer\n @forms = []\n @queue = []\n @active = []\n @disposed = false\n @root = null\n @events = {}\n @template = null\n @heartbeat = null\n @pingJob = null\n @resources = []\n @reporter = null\n @login = null\n @committingAuthentication = false\n @authVersion = 0\n @authChanges = []\n @externalStale = false\n @storageChange = null\n try\n @storageChange = @host.storage.getItem(\"lango.authChange\")\n if !is_string(@storageChange) or !@storageChange.startsWith(\"v1:\")\n @storageChange = null\n catch problem\n @storageChange = null\n\nApp:now()\n if @host.now != null\n return @host.now()\n return Date/now()\n\nApp:hostUrl()\n return @host.location.href\n\nApp:schedule(action, delay)\n return @host.schedule(action, delay)\n\nApp:cancelTimer(timer)\n @host.cancelTimer(timer)\n return null\n\nApp:checkUrl(url)\n if !is_string(url) or url.trim() == \"\"\n throw \"UI request requires a URL\"\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI requests must use the current origin\"\n return target\n\nApp:error(form, error, code = \"UiFailure\", name = null)\n if form != null and form.requestForm != null\n form = form.requestForm\n if @disposed or form == null or form.disposed\n return null\n @renderer.reportError(form, error)\n if @reporter != null\n @reporter.capture(\"ui\", code, name, form)\n return null\n\nApp:saveToken(token)\n if @externalStale\n return false\n try\n storage = @host.storage\n if storage.getItem != null\n current = storage.getItem(\"lango.authChange\")\n if !@committingAuthentication and is_string(current) and current.startsWith(\"v1:\") and current != @storageChange\n externalAuthentication(current)\n return false\n if @storageChange != null\n storage.setItem(\"lango.token:${@storageChange}\", token)\n storage.setItem(\"lango.token\", token)\n catch error\n return null\n return null\n\nApp:clearSavedToken()\n try\n @host.storage.removeItem(\"lango.token\")\n if @storageChange != null\n @host.storage.removeItem(\"lango.token:${@storageChange}\")\n return true\n catch error\n return false\n\nApp:post(url, input, token)\n return request(url, input, token)\n\nApp:poll(url, input, token, signal)\n return request(url, input, token, signal, true)\n\nApp:request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)\n target = checkUrl(url)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n headers[\"X-Lango-Screen\"] = \"wide\"\n if @host.screen != null\n headers[\"X-Lango-Screen\"] = @host.screen()\n if token != null\n headers.Authorization = \"Bearer ${token}\"\n if expected != null\n headers[\"X-Lango-Expected-User\"] = to_json(expected)\n options = {\n method: \"POST\"\n headers: headers\n body: to_json(input)\n }\n if signal != null\n options.signal = signal\n return chain @host.fetch(\"${target.pathname}${target.search}\", options)\n then(res)\n capture recover\n capture channel\n capture opening\n capture token\n if !res.ok\n if recover and (res.status == 401 or res.status == 403) and res.headers != null and res.headers.get(\"x-lango-need-login\") == \"1\"\n return chain res.json()\n then(body)\n if !is_object(body) or !is_object(body.needLogin) or (body.error != \"LoginRequired\" and body.error != \"ReauthenticationRequired\") or body.needLogin.reason != body.error\n throw \"Invalid login challenge\"\n return {\n needLogin: body.needLogin\n }\n if opening and res.status == 401 and token != null\n if clearSavedToken()\n throw new Error(\"Startup HTTP 401: saved token was rejected and cleared. Reload the page to start a new session.\")\n throw new Error(\"Startup HTTP 401: saved token was rejected but storage could not be cleared. Clear this site's local storage and reload.\")\n if !channel\n throw \"HTTP ${res.status}\"\n if res.status != 409\n return {\n status: res.status\n retryAfter: res.headers.get(\"retry-after\")\n }\n return chain res.json()\n then(body)\n capture res\n capture channel\n if !is_object(body) or is_array(body)\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw \"UI response must be a map\"\n status = res.status\n if status == null\n status = 200\n return {\n authChange: res.headers.get(\"x-lango-auth-change\")\n status: status\n token: res.headers.get(\"x-lango-token\")\n body: body\n }\n catch(error)\n capture channel\n if channel\n throw {\n code: \"InvalidPollResponse\"\n }\n throw error\n\nApp:start()\n token = null\n try\n @storageChange = @host.storage.getItem(\"lango.authChange\")\n if !is_string(@storageChange) or !@storageChange.startsWith(\"v1:\")\n @storageChange = null\n token = null\n if @storageChange != null\n token = @host.storage.getItem(\"lango.token:${@storageChange}\")\n if token == null\n token = @host.storage.getItem(\"lango.token\")\n catch error\n token = null\n return chain request(\"/\", {}, token, null, false, true)\n then(packet)\n acceptEvents(packet.body)\n if @events.clientErrorUrl != null\n @reporter = new ErrorReporter(@this, @events.clientErrorUrl)\n if @events.pingUrl != null\n @heartbeat = new Heartbeat(@this, @host, @events.pingUrl)\n if @externalStale\n if @root == null\n @root = new Form(@this)\n @root.element = @host.mount\n invalidateForm(@root)\n return null\n @root = new Form(@this, null, packet.token)\n @root.element = @host.mount\n @root.setToken(packet.token)\n return chain navigate(@host.location.pathname, false)\n then(ignored)\n if @heartbeat != null\n @heartbeat.start()\n return null\n catch(problem)\n if @externalStale\n return null\n throw problem\n\nApp:send(form, url, owner = null)\n if @disposed or form.disposed\n return Promise/reject(\"Form is disposed\")\n if form.stale or @externalStale\n return Promise/reject(\"SessionChanged: reload the page\")\n pending = new Promise((resolve, reject)\n capture form\n capture url\n capture owner\n @queue.add({\n authVersion: @authVersion\n kind: \"send\"\n form: form\n url: url\n owner: owner\n resolve: resolve\n reject: reject\n })\n drain()\n )\n return pending\n\nApp:deliver(form, action, owner, generation)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n authVersion: @authVersion\n kind: \"delivery\"\n form: form\n action: action\n owner: owner\n generation: generation\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:report(form, url, input, owner)\n if @disposed or form.disposed or !owner.active\n return Promise/resolve(null)\n deferred = Promise/withResolvers()\n @queue.add({\n authVersion: @authVersion\n kind: \"report\"\n form: form\n url: url\n input: input\n owner: owner\n resolve: deferred.resolve\n reject: deferred.reject\n })\n drain()\n return deferred.promise\n\nApp:canPoll(form)\n if @disposed or form.disposed or form.stale or @externalStale or @pingJob != null or @login != null\n return false\n for @active as job\n if form.related(job.form)\n return false\n for @queue as job\n if form.related(job.form)\n return false\n return true\n\nApp:pausePolls(form = null)\n for @forms.slice() as candidate\n if form == null or form.related(candidate)\n candidate.activity.pause()\n return null\n\nApp:resumePolls()\n for @forms.slice() as form\n form.activity.resume()\n return null\n\nApp:drain()\n if @disposed\n return null\n if @pingJob != null and @login == null\n if @active.length == 0 and !@pingJob.running\n @pingJob.running = true\n executePing(@pingJob)\n return null\n for @queue.slice() as job\n if job.authVersion != @authVersion or job.form.stale or @externalStale\n @queue.splice(@queue.indexOf(job), 1)\n job.reject(\"SessionChanged: queued request cancelled\")\n continue\n if @login != null and !@login.form.related(job.form)\n continue\n blocked = false\n for @active as running\n if job.form.related(running.form)\n blocked = true\n for @queue as earlier\n if earlier == job\n break\n if job.form.related(earlier.form)\n blocked = true\n if !blocked\n @queue.splice(@queue.indexOf(job), 1)\n @active.add(job)\n if job.kind == \"delivery\"\n executeDelivery(job)\n else\n pausePolls(job.form)\n execute(job)\n resumePolls()\n return null\n\nApp:executeDelivery(job)\n return chain Promise/resolve(null)\n then(ignored)\n capture job\n if !job.form.disposed and job.owner.active and job.owner.generation == job.generation\n action = job.action\n action()\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n index = @active.indexOf(job)\n if index >= 0\n @active.splice(index, 1)\n drain()\n\nApp:ping()\n if @disposed or @heartbeat == null\n return Promise/resolve(null)\n if @pingJob != null\n return @pingJob.promise\n deferred = Promise/withResolvers()\n @pingJob = {\n promise: deferred.promise\n resolve: deferred.resolve\n reject: deferred.reject\n running: false\n }\n pausePolls()\n drain()\n return deferred.promise\n\nApp:executePing(job)\n return chain Promise/resolve(null)\n then(ignored)\n return @heartbeat.exchange()\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n @pingJob = null\n drain()\n\nApp:execute(job)\n form = job.form\n return chain Promise/resolve(null)\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if form.stale or @externalStale\n throw \"SessionChanged: reload the page\"\n if job.owner != null and !job.owner.active\n return null\n if job.kind == \"report\"\n return post(job.url, job.input, form.token)\n form.clearValidation()\n @renderer.waiting(form, true)\n ready = form.prepareValue()\n if ready == null\n return sendInput(job, from_json(to_json(form.getValue())))\n return chain ready\n then(ignored)\n capture form\n capture job\n if form.disposed\n throw \"Form is disposed\"\n if job.owner != null and !job.owner.active\n return null\n return sendInput(job, from_json(to_json(form.getValue())))\n then(packet)\n capture form\n capture job\n if job.authVersion != @authVersion or form.stale or @externalStale\n throw \"SessionChanged: response discarded\"\n if packet != null and !form.disposed and (job.owner == null or job.owner.active)\n if job.kind == \"report\"\n form.setToken(packet.token)\n else\n form.handle(packet)\n if form.stale or @externalStale\n throw \"SessionChanged: response discarded\"\n then(ignored)\n capture job\n job.resolve(null)\n catch(error)\n capture job\n job.reject(error)\n finally\n capture job\n capture form\n if job.kind == \"send\"\n @renderer.waiting(form, false)\n index = @active.indexOf(job)\n if index >= 0\n @active.splice(index, 1)\n drain()\n\nApp:navigate(url, push = true)\n target = new URL(url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI navigation must use the current origin\"\n path = target.pathname\n if path == \"/\"\n path = \"/index\"\n template = selectTemplate(path)\n ready = Promise/resolve(null)\n if template != @template\n if template != null\n ready = @root.send(template)\n else\n @template = null\n return chain ready\n then(ignored)\n capture template\n capture path\n capture Form\n @template = template\n form = @root\n if template != null\n form = @root.find(\"__content__\")\n if !is_kindof(form, Form)\n throw \"Template requires a __content__ form\"\n return form.send(path)\n then(ignored)\n capture target\n capture push\n if push\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n return null\n\nApp:selectTemplate(path)\n urls = @events.templates\n if urls == null\n urls = []\n selected = @events.defaultTemplate\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n best = 0\n for urls as url\n if !is_string(url) or !url.startsWith(\"/\") or url == \"/\" or url.endsWith(\"/\")\n throw \"Invalid template URL\"\n if path == url\n throw \"Template URLs cannot be used as page URLs\"\n if path == url or path.startsWith(\"${url}/\")\n if url.length > best\n selected = url\n best = url.length\n if path == selected\n throw \"Template URLs cannot be used as page URLs\"\n return selected\n\nApp:command(form, cmd)\n switch cmd.type\n case \"loginSatisfied\"\n finishLogin(form, cmd.userId)\n case \"cancelLogin\"\n if @login == null or !@login.form.related(form)\n throw \"cancelLogin requires the active login form\"\n @login.cancelled = true\n case \"values\"\n form.setValue(cmd.values)\n case \"addRow\"\n form.find(cmd.name).addRow(cmd.value)\n case \"insertRow\"\n form.find(cmd.name).insertRow(cmd.beforeIndex, cmd.value)\n case \"deleteRow\"\n form.find(cmd.name).deleteRow(cmd.index)\n case \"setRowValue\"\n form.find(cmd.name).setRowValue(cmd.index, cmd.value)\n case \"setRowData\"\n form.find(cmd.name).setRowData(cmd.index, cmd.value)\n case \"setCellValue\"\n form.find(cmd.name).setCellValue(cmd.index, cmd.column, cmd.value)\n case \"invalid\"\n form.find(cmd.name).setInvalid(cmd.message)\n case \"set\"\n targetForm = form.find(cmd.name)\n if !is_kindof(targetForm, Form)\n throw \"Set requires a form target\"\n @renderer.show(targetForm, cmd.control)\n case \"setUrl\"\n target = new URL(cmd.url, @host.location.href)\n if target.origin != @host.location.origin\n throw \"UI URL must use the current origin\"\n @host.history.pushState(null, \"\", \"${target.pathname}${target.search}${target.hash}\")\n if @renderer.locationChanged != null\n @renderer.locationChanged(target.href)\n case \"redirect\"\n action = ()\n capture cmd\n chain navigate(cmd.url)\n catch(problem)\n capture form\n error(form, problem)\n @host.defer(action)\n case \"disable\"\n form.find(cmd.name).setDisabled(true)\n case \"enable\"\n form.find(cmd.name).setDisabled(false)\n case \"changeCaption\"\n form.find(cmd.name).setCaption(cmd.caption)\n case \"activateTabItem\"\n form.find(cmd.name).activate()\n case \"setProgress\"\n form.find(cmd.name).setRange(cmd.min, cmd.max, cmd.value)\n case \"updateProgress\"\n form.find(cmd.name).update(cmd.value, cmd.label)\n case \"showAlert\"\n @renderer.presentations.showAlert(form, cmd)\n case \"dismissAlert\"\n @renderer.presentations.dismissAlert(form, cmd.name)\n case \"showToast\"\n @renderer.presentations.showToast(form, cmd.toast, cmd.stack)\n case \"showDialog\"\n @renderer.presentations.showDialog(form, cmd.dialog, cmd.keepPrev)\n case \"swapDialog\"\n @renderer.presentations.swapDialog(form)\n case \"setTimer\"\n form.activity.timer(cmd.url, cmd.interval)\n case \"clearTimer\"\n form.activity.clearTimer(cmd.url)\n case \"setInterval\"\n form.activity.timer(cmd.url, cmd.interval, true)\n case \"clearInterval\"\n form.activity.clearTimer(cmd.url, true)\n case \"startLongPoll\"\n form.activity.startLongPoll(cmd.url, cmd.key, cmd.cursor)\n case \"stopLongPoll\"\n form.activity.stopLongPoll(cmd.url, cmd.key)\n else\n throw \"Unsupported UI command: ${cmd.type}\"\n return null\n\nApp:dispose()\n @disposed = true\n cancelLogin()\n if @heartbeat != null\n @heartbeat.dispose()\n if @reporter != null\n @reporter.dispose()\n for @forms.slice() as form\n form.dispose()\n for @queue as job\n job.reject(\"Application is disposed\")\n @queue = []\n for @resources as release\n release()\n @resources = []\n return null\n\nApp:sendInput(job, input)\n form = job.form\n recover = @login == null or !@login.form.related(form)\n return chain request(job.url, input, form.token, null, false, false, recover)\n then(packet)\n capture job\n capture input\n if packet.needLogin == null\n return packet\n return resumeInput(job, input, packet.needLogin)\n\nApp:resumeInput(job, input, challenge)\n return chain needLogin(job, challenge)\n then(identity)\n capture job\n capture input\n form = job.form\n if form.disposed or form.stale or @externalStale or (job.owner != null and !job.owner.active)\n throw \"Pending login request is no longer active\"\n job.authVersion = @authVersion\n return request(job.url, input, identity.token, null, false, false, false, identity.expected)\n\nApp:needLogin(job, challenge)\n if @events.needLoginUrl == null\n throw \"Login is required but no needLogin event is configured\"\n session = @login\n if session != null and session.originalToken != job.form.token\n invalidateForm(job.form)\n throw \"SessionChanged: another form is awaiting login\"\n if session == null\n deferred = Promise/withResolvers()\n scope = new Form(@this, null, job.form.token)\n session = {\n form: scope\n source: job.form\n promise: deferred.promise\n resolve: deferred.resolve\n reject: deferred.reject\n release: null\n ready: null\n cancelled: false\n change: null\n originalToken: job.form.token\n }\n chain session.promise\n catch(problem)\n return null\n @login = session\n pausePolls()\n try\n cancel = ()\n cancelLogin()\n session.release = @renderer.openLogin(scope, cancel)\n chain post(@events.needLoginUrl, challenge, scope.token)\n then(packet)\n capture session\n if @login == session and !session.form.disposed\n session.form.handle(packet)\n catch(problem)\n capture session\n if @login == session\n cancelLogin(problem)\n catch problem\n cancelLogin(problem)\n return chain session.promise\n then(identity)\n capture challenge\n if challenge.userId != null and identity.userId != challenge.userId\n for @forms.slice() as form\n invalidateForm(form)\n throw \"IdentityChanged\"\n return {\n token: identity.token\n expected: challenge.userId\n }\n\nApp:finishLogin(form, userId)\n session = @login\n if session == null or !session.form.related(form) or form.token == null\n throw \"loginSatisfied requires an active login form and token\"\n if @active.length == 0\n throw \"No request is waiting for login\"\n session.ready = {\n token: form.token\n userId: userId\n }\n return null\n\nApp:completeLogin(form)\n session = @login\n if session == null or !session.form.related(form)\n return null\n if session.cancelled\n return cancelLogin()\n if session.ready == null\n return null\n @login = null\n identity = session.ready\n change = session.change\n if !is_string(change) or !change.startsWith(\"v1:\")\n change = \"v1:${crypto/randomUUID()}\"\n commitAuthentication(session.source, session.originalToken, identity.token, change)\n session.resolve(identity)\n if session.release != null\n release = session.release\n release()\n session.form.dispose()\n drain()\n return null\n\nApp:cancelLogin(problem = \"LoginCancelled\")\n session = @login\n if session == null\n return null\n @login = null\n session.reject(problem)\n if session.release != null\n release = session.release\n release()\n session.form.dispose()\n drain()\n return null\n\nApp:loginScopeDisposed(form)\n if @login != null and (@login.form == form or @login.source == form)\n cancelLogin()\n return null\n\nApp:acceptEvents(events)\n if !is_object(events) or is_array(events)\n throw \"Startup events must be a map\"\n if events.needLoginUrl != null\n checkUrl(events.needLoginUrl)\n @events = events\n return null\n\nApp:beginLoginResponse(form, packet)\n if @login != null and @login.form.related(form)\n @login.change = packet.authChange\n @login.ready = null\n @login.cancelled = false\n return null\n\nApp:observeAuthentication(form, previous, packet)\n change = packet.authChange\n if @login != null and @login.form.related(form)\n return null\n if is_string(change) and change.startsWith(\"v1:\") and !@authChanges.includes(change)\n commitAuthentication(form, previous, packet.token, change)\n return null\n\nApp:commitAuthentication(source, previous, token, change)\n if @disposed or @authChanges.includes(change)\n return null\n previousChange = @storageChange\n @storageChange = change\n @authChanges.add(change)\n if @authChanges.length > 64\n @authChanges.shift()\n @authVersion = @authVersion + 1\n @committingAuthentication = true\n for @forms.slice() as form\n if form.disposed or form.stale\n continue\n if form == source or form.token == previous or form.token == token\n form.setToken(token)\n else\n invalidateForm(form)\n @committingAuthentication = false\n try\n @host.storage.setItem(\"lango.authChange\", change)\n if previousChange != null and @host.storage.removeItem != null\n @host.storage.removeItem(\"lango.token:${previousChange}\")\n catch problem\n return null\n return null\n\nApp:externalAuthentication(change)\n if @disposed or !is_string(change) or !change.startsWith(\"v1:\") or @authChanges.includes(change)\n return null\n @authChanges.add(change)\n if @authChanges.length > 64\n @authChanges.shift()\n @storageChange = change\n @externalStale = true\n @authVersion = @authVersion + 1\n cancelLogin(\"SessionChanged: authentication changed in another tab\")\n if @heartbeat != null\n @heartbeat.dispose()\n if @root == null and @host.mount != null\n @root = new Form(@this)\n @root.element = @host.mount\n for @forms.slice() as form\n invalidateForm(form)\n return null\n\nApp:invalidateForm(form)\n if form.disposed or form.stale\n return null\n form.stale = true\n form.activity.clear()\n parent = form.parent\n loop while parent != null\n if parent.stale\n return null\n parent = parent.parent\n if @renderer.sessionChanged != null\n @renderer.sessionChanged(form)\n return null\n\nApp:reloadSession()\n if @host.reload == null\n throw \"Reload the page to continue\"\n @host.reload()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/boot.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { start } from "./main.mjs";
|
|
2
2
|
import {
|
|
3
|
+
bindContexts as __bindContexts,
|
|
3
4
|
boundary as __boundary,
|
|
4
5
|
requireArity as __requireArity,
|
|
5
6
|
withArity as __withArity,
|
|
@@ -7,11 +8,11 @@ import {
|
|
|
7
8
|
|
|
8
9
|
let application = launch();
|
|
9
10
|
function launch() {
|
|
10
|
-
return start().catch(__withArity((error) => {
|
|
11
|
+
return start().catch(__withArity(__bindContexts((error) => {
|
|
11
12
|
error = __boundary(error);
|
|
12
13
|
importFailure(error);
|
|
13
14
|
return null;
|
|
14
|
-
}, [0], "closure"));
|
|
15
|
+
}), [0], "closure"));
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
18
|
|
package/dist/boot.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boot.mjs","sources":["boot.lango"],"sourcesContent":["import \"./main\"\n start()\n\nglobal application = launch()\n\nlaunch()\n return chain start()\n catch(error)\n importFailure(error)\n\nimportFailure(error)\n throw error\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"boot.mjs","sources":["boot.lango"],"sourcesContent":["import \"./main\"\n start()\n\nglobal application = launch()\n\nlaunch()\n return chain start()\n catch(error)\n importFailure(error)\n\nimportFailure(error)\n throw error\n"],"names":[],"mappings":";;;;;;;;AAGA;AAEA;;;;;;;;;AAKA;;;;;;;"}
|
package/dist/button.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { cloneMarkup } from "./templates.mjs";
|
|
|
3
3
|
import { RichContent } from "./rich_content.mjs";
|
|
4
4
|
import {
|
|
5
5
|
xmlEscape as __xmlEscape,
|
|
6
|
+
bindContexts as __bindContexts,
|
|
6
7
|
add as __add,
|
|
7
8
|
requireBoolean as __requireBoolean,
|
|
8
9
|
normalize as __normalize,
|
|
@@ -34,29 +35,29 @@ export class Button extends Control {
|
|
|
34
35
|
this.element.disabled = __normalize(props.disabled) === true;
|
|
35
36
|
this.setCaption(__normalize(props.caption));
|
|
36
37
|
if (__requireBoolean(__requireBoolean(__normalize(this.#url) !== null) || __requireBoolean(__normalize(this.#dismiss)))) {
|
|
37
|
-
let listener = () => {
|
|
38
|
+
let listener = __bindContexts(() => {
|
|
38
39
|
if (__requireBoolean(__normalize(this.#url) === null)) {
|
|
39
40
|
__normalize(this.#presentations.dismiss(__normalize(this.form)));
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
42
|
-
__normalize(this.form.send(__normalize(this.#url))).then(__withArity((ignored) => {
|
|
43
|
+
__normalize(this.form.send(__normalize(this.#url))).then(__withArity(__bindContexts((ignored) => {
|
|
43
44
|
ignored = __boundary(ignored);
|
|
44
45
|
if (__requireBoolean(__normalize(this.#dismiss))) {
|
|
45
46
|
__normalize(this.#presentations.dismiss(__normalize(this.form)));
|
|
46
47
|
}
|
|
47
48
|
return null;
|
|
48
|
-
}, [0], "closure")).catch(__withArity((error) => {
|
|
49
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
49
50
|
error = __boundary(error);
|
|
50
51
|
__normalize(this.form.app.error(__normalize(this.form), error));
|
|
51
52
|
return null;
|
|
52
|
-
}, [0], "closure"));
|
|
53
|
+
}), [0], "closure"));
|
|
53
54
|
return null;
|
|
54
|
-
};
|
|
55
|
+
});
|
|
55
56
|
__normalize(this.element.addEventListener("click", listener));
|
|
56
|
-
let release = () => {
|
|
57
|
+
let release = __bindContexts(() => {
|
|
57
58
|
__normalize(this.element.removeEventListener("click", listener));
|
|
58
59
|
return null;
|
|
59
|
-
};
|
|
60
|
+
});
|
|
60
61
|
__add(this.release, release);
|
|
61
62
|
}
|
|
62
63
|
}
|
package/dist/button.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.mjs","sources":["button.lango"],"sourcesContent":["import \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./rich_content\"\n class RichContent\n\nexport class Button(form, props, renderer) : Control\n methods\n setCaption(value)\n dispose()\n\nButton(form, props, renderer)\n super(form, props, cloneMarkup(\"button\", <button type=\"button\" class=\"btn\"></button>))\n @presentations = renderer.presentations\n @url = props.url\n @dismiss = props.dismiss == true\n @content = new RichContent(form, @element, renderer, false)\n theme = props.theme\n if theme == null\n theme = \"primary\"\n @element.classList.add(\"btn-${theme.toLowerCase()}\")\n @element.disabled = props.disabled == true\n setCaption(props.caption)\n if @url != null or @dismiss\n listener = ()\n if @url == null\n @presentations.dismiss(@form)\n return null\n chain @form.send(@url)\n then(ignored)\n if @dismiss\n @presentations.dismiss(@form)\n catch(error)\n @form.app.error(@form, error)\n @element.addEventListener(\"click\", listener)\n release = ()\n capture listener\n @element.removeEventListener(\"click\", listener)\n @release.add(release)\n\nButton:setCaption(value)\n @content.replace(value)\n return @this\n\nButton:dispose()\n @content.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"button.mjs","sources":["button.lango"],"sourcesContent":["import \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./rich_content\"\n class RichContent\n\nexport class Button(form, props, renderer) : Control\n methods\n setCaption(value)\n dispose()\n\nButton(form, props, renderer)\n super(form, props, cloneMarkup(\"button\", <button type=\"button\" class=\"btn\"></button>))\n @presentations = renderer.presentations\n @url = props.url\n @dismiss = props.dismiss == true\n @content = new RichContent(form, @element, renderer, false)\n theme = props.theme\n if theme == null\n theme = \"primary\"\n @element.classList.add(\"btn-${theme.toLowerCase()}\")\n @element.disabled = props.disabled == true\n setCaption(props.caption)\n if @url != null or @dismiss\n listener = ()\n if @url == null\n @presentations.dismiss(@form)\n return null\n chain @form.send(@url)\n then(ignored)\n if @dismiss\n @presentations.dismiss(@form)\n catch(error)\n @form.app.error(@form, error)\n @element.addEventListener(\"click\", listener)\n release = ()\n capture listener\n @element.removeEventListener(\"click\", listener)\n @release.add(release)\n\nButton:setCaption(value)\n @content.replace(value)\n return @this\n\nButton:dispose()\n @content.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/chip.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { RichContent } from "./rich_content.mjs";
|
|
|
4
4
|
import {
|
|
5
5
|
hostGlobal as __hostGlobal,
|
|
6
6
|
xmlEscape as __xmlEscape,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
7
8
|
isNumber as __isNumber,
|
|
8
9
|
isString as __isString,
|
|
9
10
|
isBool as __isBool,
|
|
@@ -66,16 +67,16 @@ export class Chip extends Field {
|
|
|
66
67
|
__normalize(this.#action.replace(__normalize(props.button)));
|
|
67
68
|
}
|
|
68
69
|
this.setDisabled(__normalize(props.disabled) === true);
|
|
69
|
-
let click = () => {
|
|
70
|
+
let click = __bindContexts(() => {
|
|
70
71
|
this.#active = !__requireBoolean(__normalize(this.#active));
|
|
71
72
|
this.#paint();
|
|
72
73
|
return null;
|
|
73
|
-
};
|
|
74
|
+
});
|
|
74
75
|
__normalize(this.input.addEventListener("click", click));
|
|
75
|
-
let release = () => {
|
|
76
|
+
let release = __bindContexts(() => {
|
|
76
77
|
__normalize(this.input.removeEventListener("click", click));
|
|
77
78
|
return null;
|
|
78
|
-
};
|
|
79
|
+
});
|
|
79
80
|
__add(this.release, release);
|
|
80
81
|
}
|
|
81
82
|
#paint() {
|
package/dist/chip.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chip.mjs","sources":["chip.lango"],"sourcesContent":["import js global document\nimport \"./fields\"\n class Field\n sameValue(first, second)\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./rich_content\"\n class RichContent\n\nexport class Chip(form, props, renderer) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n setCaption(value)\n dispose()\n\nChip(form, props, renderer)\n super(form, props, cloneMarkup(\"chip\", <button type=\"button\" class=\"btn rounded-pill lango-chip\"><span class=\"lango-chip-icon\" aria-hidden=\"true\"></span><span></span></button>))\n @locked = props.readonly == true\n @payload = props.value\n @active = props.active == true\n @input.setAttribute(\"aria-pressed\", \"${@active}\")\n @input.classList.toggle(\"active\", @active)\n theme = props.theme\n if theme == null\n theme = \"secondary\"\n @input.classList.add(\"btn-outline-${theme.toLowerCase()}\")\n if @labelElement != null\n @labelElement.className = \"visually-hidden\"\n @icon = new RichContent(form, @input.firstElementChild, renderer, false, \"Chip icon\")\n if is_string(props.icon)\n symbol = document/createElement(\"i\")\n symbol.className = props.icon\n @input.firstElementChild.appendChild(symbol)\n else\n @icon.replace(props.icon)\n caption = props.label\n if caption == null and is_string(props.value)\n caption = props.value\n setCaption(caption)\n @action = null\n if props.button != null\n if !is_object(props.button) or props.button.type != \"button\"\n throw \"Chip button requires a Button definition\"\n action = document/createElement(\"span\")\n action.className = \"lango-chip-action\"\n @element.insertBefore(action, @input.nextSibling)\n @action = new RichContent(form, action, renderer)\n @action.replace(props.button)\n setDisabled(props.disabled == true)\n click = ()\n @active = !@active\n paint()\n @input.addEventListener(\"click\", click)\n release = ()\n capture click\n @input.removeEventListener(\"click\", click)\n @release.add(release)\n\nChip:paint()\n @input.setAttribute(\"aria-pressed\", \"${@active}\")\n @input.classList.toggle(\"active\", @active)\n return null\n\nChip:getValue()\n if @active\n return @payload\n return null\n\nChip:setValue(value)\n if value != null and !sameValue(value, @payload)\n throw \"Chip value does not match its configured value\"\n @active = value != null\n paint()\n return @this\n\nChip:setDisabled(value)\n @input.disabled = value or @locked == true\n return @this\n\nChip:setCaption(value)\n @input.lastElementChild.textContent = value\n if @labelElement != null\n @labelElement.textContent = value\n return @this\n\nChip:dispose()\n if @icon != null\n @icon.dispose()\n if @action != null\n @action.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chip.mjs","sources":["chip.lango"],"sourcesContent":["import js global document\nimport \"./fields\"\n class Field\n sameValue(first, second)\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./rich_content\"\n class RichContent\n\nexport class Chip(form, props, renderer) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n setCaption(value)\n dispose()\n\nChip(form, props, renderer)\n super(form, props, cloneMarkup(\"chip\", <button type=\"button\" class=\"btn rounded-pill lango-chip\"><span class=\"lango-chip-icon\" aria-hidden=\"true\"></span><span></span></button>))\n @locked = props.readonly == true\n @payload = props.value\n @active = props.active == true\n @input.setAttribute(\"aria-pressed\", \"${@active}\")\n @input.classList.toggle(\"active\", @active)\n theme = props.theme\n if theme == null\n theme = \"secondary\"\n @input.classList.add(\"btn-outline-${theme.toLowerCase()}\")\n if @labelElement != null\n @labelElement.className = \"visually-hidden\"\n @icon = new RichContent(form, @input.firstElementChild, renderer, false, \"Chip icon\")\n if is_string(props.icon)\n symbol = document/createElement(\"i\")\n symbol.className = props.icon\n @input.firstElementChild.appendChild(symbol)\n else\n @icon.replace(props.icon)\n caption = props.label\n if caption == null and is_string(props.value)\n caption = props.value\n setCaption(caption)\n @action = null\n if props.button != null\n if !is_object(props.button) or props.button.type != \"button\"\n throw \"Chip button requires a Button definition\"\n action = document/createElement(\"span\")\n action.className = \"lango-chip-action\"\n @element.insertBefore(action, @input.nextSibling)\n @action = new RichContent(form, action, renderer)\n @action.replace(props.button)\n setDisabled(props.disabled == true)\n click = ()\n @active = !@active\n paint()\n @input.addEventListener(\"click\", click)\n release = ()\n capture click\n @input.removeEventListener(\"click\", click)\n @release.add(release)\n\nChip:paint()\n @input.setAttribute(\"aria-pressed\", \"${@active}\")\n @input.classList.toggle(\"active\", @active)\n return null\n\nChip:getValue()\n if @active\n return @payload\n return null\n\nChip:setValue(value)\n if value != null and !sameValue(value, @payload)\n throw \"Chip value does not match its configured value\"\n @active = value != null\n paint()\n return @this\n\nChip:setDisabled(value)\n @input.disabled = value or @locked == true\n return @this\n\nChip:setCaption(value)\n @input.lastElementChild.textContent = value\n if @labelElement != null\n @labelElement.textContent = value\n return @this\n\nChip:dispose()\n if @icon != null\n @icon.dispose()\n if @action != null\n @action.dispose()\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/combo_box.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { RichContent } from "./rich_content.mjs";
|
|
|
4
4
|
import {
|
|
5
5
|
hostGlobal as __hostGlobal,
|
|
6
6
|
xmlEscape as __xmlEscape,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
7
8
|
isNumber as __isNumber,
|
|
8
9
|
isString as __isString,
|
|
9
10
|
isBool as __isBool,
|
|
@@ -115,18 +116,18 @@ export class ComboBox extends Field {
|
|
|
115
116
|
__normalize(group.appendChild(item));
|
|
116
117
|
this.#elements.push(item);
|
|
117
118
|
let choice = index;
|
|
118
|
-
let click = __withArity((event) => {
|
|
119
|
+
let click = __withArity(__bindContexts((event) => {
|
|
119
120
|
event = __boundary(event);
|
|
120
121
|
__normalize(event.preventDefault());
|
|
121
122
|
__normalize(event.stopPropagation());
|
|
122
123
|
this.choose(choice);
|
|
123
124
|
return null;
|
|
124
|
-
}, [0], "closure");
|
|
125
|
-
let key = __withArity((event) => {
|
|
125
|
+
}), [0], "closure");
|
|
126
|
+
let key = __withArity(__bindContexts((event) => {
|
|
126
127
|
event = __boundary(event);
|
|
127
128
|
this.#handleKey(event, choice);
|
|
128
129
|
return null;
|
|
129
|
-
}, [0], "closure");
|
|
130
|
+
}), [0], "closure");
|
|
130
131
|
this.#listen(item, "click", click);
|
|
131
132
|
this.#listen(item, "keydown", key);
|
|
132
133
|
}
|
|
@@ -134,26 +135,26 @@ export class ComboBox extends Field {
|
|
|
134
135
|
}
|
|
135
136
|
this.setValue(__normalize(props.value));
|
|
136
137
|
this.setDisabled(__normalize(props.disabled) === true);
|
|
137
|
-
let toggle = () => {
|
|
138
|
+
let toggle = __bindContexts(() => {
|
|
138
139
|
if (__requireBoolean(__normalize(this.#panel.hidden))) {
|
|
139
140
|
this.open();
|
|
140
141
|
} else {
|
|
141
142
|
this.close();
|
|
142
143
|
}
|
|
143
144
|
return null;
|
|
144
|
-
};
|
|
145
|
-
let key = __withArity((event) => {
|
|
145
|
+
});
|
|
146
|
+
let key = __withArity(__bindContexts((event) => {
|
|
146
147
|
event = __boundary(event);
|
|
147
148
|
this.#handleKey(event, __finite(-1));
|
|
148
149
|
return null;
|
|
149
|
-
}, [0], "closure");
|
|
150
|
-
let outside = __withArity((event) => {
|
|
150
|
+
}), [0], "closure");
|
|
151
|
+
let outside = __withArity(__bindContexts((event) => {
|
|
151
152
|
event = __boundary(event);
|
|
152
153
|
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(this.#panel.hidden))) && __requireBoolean(!__requireBoolean(__normalize(this.element.contains(__normalize(event.target))))))) {
|
|
153
154
|
this.close();
|
|
154
155
|
}
|
|
155
156
|
return null;
|
|
156
|
-
}, [0], "closure");
|
|
157
|
+
}), [0], "closure");
|
|
157
158
|
this.#listen(__normalize(this.input), "click", toggle);
|
|
158
159
|
this.#listen(__normalize(this.input), "keydown", key);
|
|
159
160
|
this.#listen(__normalize(__hostGlobal(["document"])), "pointerdown", outside);
|
|
@@ -165,10 +166,10 @@ export class ComboBox extends Field {
|
|
|
165
166
|
type = __boundary(type);
|
|
166
167
|
listener = __boundary(listener);
|
|
167
168
|
__normalize(element.addEventListener(type, listener));
|
|
168
|
-
let release = () => {
|
|
169
|
+
let release = __bindContexts(() => {
|
|
169
170
|
__normalize(element.removeEventListener(type, listener));
|
|
170
171
|
return null;
|
|
171
|
-
};
|
|
172
|
+
});
|
|
172
173
|
__add(this.release, release);
|
|
173
174
|
return null;
|
|
174
175
|
return null;
|
|
@@ -298,11 +299,11 @@ export class ComboBox extends Field {
|
|
|
298
299
|
this.close(true);
|
|
299
300
|
}
|
|
300
301
|
if (__requireBoolean(__normalize(option.url) !== null)) {
|
|
301
|
-
return __normalize(this.form.send(__normalize(option.url))).catch(__withArity((error) => {
|
|
302
|
+
return __normalize(this.form.send(__normalize(option.url))).catch(__withArity(__bindContexts((error) => {
|
|
302
303
|
error = __boundary(error);
|
|
303
304
|
__normalize(this.form.app.error(__normalize(this.form), error));
|
|
304
305
|
return null;
|
|
305
|
-
}, [0], "closure"));
|
|
306
|
+
}), [0], "closure"));
|
|
306
307
|
}
|
|
307
308
|
return null;
|
|
308
309
|
return null;
|
package/dist/combo_box.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combo_box.mjs","sources":["combo_box.lango"],"sourcesContent":["import js global document\nimport \"./fields\"\n class Field\n sameValue(first, second)\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\nimport \"./rich_content\"\n class RichContent\n\nexport comboSelection(options, value, multi)\n\ncomboSelection(options, value, multi)\n requested = []\n if value != null\n if multi\n if !is_array(value)\n throw \"Multi ComboBox value must be an array\"\n requested = value\n else\n requested.add(value)\n selected = []\n for requested as candidate\n found = -1\n index = 0\n for options as option\n if option.value != null and sameValue(option.value, candidate)\n found = index\n break\n index = index + 1\n if found < 0\n throw \"ComboBox value does not identify an option\"\n if !selected.includes(found)\n selected.add(found)\n return selected\n\nexport class ComboBox(form, props, renderer) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n open(last = false)\n close(focus = false)\n choose(index)\n dispose()\n\nComboBox(form, props, renderer)\n super(form, props, cloneMarkup(\"combo-button\", <button type=\"button\" class=\"form-select text-start\" role=\"combobox\" aria-haspopup=\"listbox\" aria-expanded=\"false\"></button>))\n @locked = props.readonly == true\n @multi = props.multi == true\n @options = props.options\n if @options == null\n @options = []\n @selected = []\n @elements = []\n @slots = []\n @cursor = -1\n @element.classList.add(\"lango-combo\")\n @panel = cloneMarkup(\"combo-panel\", <div class=\"lango-combo-panel\" hidden=\"hidden\"><ul class=\"list-group\" role=\"listbox\"></ul></div>)\n list = @panel.firstElementChild\n list.id = controlId()\n if props.aria != null and props.aria.label != null\n list.setAttribute(\"aria-label\", props.aria.label)\n else\n if props.label != null\n list.setAttribute(\"aria-label\", props.label)\n if @multi\n list.setAttribute(\"aria-multiselectable\", \"true\")\n @input.setAttribute(\"aria-controls\", list.id)\n @element.insertBefore(@panel, @input.nextSibling)\n group = list\n index = 0\n for @options as option\n if !is_object(option)\n throw \"ComboBox options require value/control maps\"\n if option.url != null\n if option.value == null\n throw \"ComboBox group cannot have a URL\"\n form.app.checkUrl(option.url)\n item = document/createElement(\"li\")\n slot = null\n if option.value == null\n item.setAttribute(\"role\", \"presentation\")\n heading = document/createElement(\"div\")\n heading.id = controlId()\n heading.className = \"lango-combo-heading\"\n slot = new RichContent(form, heading, renderer, false, \"ComboBox group\")\n slot.replace(option.control)\n @slots.add(slot)\n item.appendChild(heading)\n group = cloneMarkup(\"combo-group\", <ul class=\"list-group\" role=\"group\"></ul>)\n group.setAttribute(\"aria-labelledby\", heading.id)\n item.appendChild(group)\n list.appendChild(item)\n @elements.add(null)\n else\n item.className = \"list-group-item list-group-item-action\"\n item.setAttribute(\"role\", \"option\")\n item.tabIndex = -1\n item.id = controlId()\n slot = new RichContent(form, item, renderer, false, \"ComboBox option\")\n slot.replace(option.control)\n label = item.textContent.trim()\n content = item.firstElementChild\n if content != null and content.hasAttribute(\"aria-label\")\n label = content.getAttribute(\"aria-label\")\n if label == \"\"\n labels = []\n for item.querySelectorAll(\"img[alt]\") as image\n labels.add(image.alt)\n label = labels.join(\" \").trim()\n if label == \"\"\n throw \"ComboBox option requires text or an accessible label\"\n item.setAttribute(\"aria-label\", label)\n @slots.add(slot)\n group.appendChild(item)\n @elements.add(item)\n choice = index\n click = (event)\n capture choice\n event.preventDefault()\n event.stopPropagation()\n choose(choice)\n key = (event)\n capture choice\n handleKey(event, choice)\n listen(item, \"click\", click)\n listen(item, \"keydown\", key)\n index = index + 1\n setValue(props.value)\n setDisabled(props.disabled == true)\n toggle = ()\n if @panel.hidden\n open()\n else\n close()\n key = (event)\n handleKey(event, -1)\n outside = (event)\n if !@panel.hidden and !@element.contains(event.target)\n close()\n listen(@input, \"click\", toggle)\n listen(@input, \"keydown\", key)\n listen(document, \"pointerdown\", outside)\n listen(document, \"focusin\", outside)\n\nComboBox:listen(element, type, listener)\n element.addEventListener(type, listener)\n release = ()\n capture element\n capture type\n capture listener\n element.removeEventListener(type, listener)\n @release.add(release)\n return null\n\nComboBox:getValue()\n values = []\n for @selected as index\n option = @options[index]\n values.add(option.value)\n if @multi\n return values\n if values.length > 0\n return values[0]\n return null\n\nComboBox:setValue(value)\n selected = comboSelection(@options, value, @multi)\n @selected = selected\n paint()\n return @this\n\nComboBox:paint()\n labels = []\n index = 0\n for @elements as item\n if item != null\n selected = @selected.includes(index)\n item.setAttribute(\"aria-selected\", \"${selected}\")\n item.classList.toggle(\"active\", selected)\n index = index + 1\n for @selected as choice\n selectedItem = @elements[choice]\n labels.add(selectedItem.getAttribute(\"aria-label\"))\n @input.textContent = labels.join(\", \")\n return null\n\nComboBox:setDisabled(value)\n @input.disabled = value or @locked == true\n if @input.disabled and @panel != null\n close()\n return @this\n\nComboBox:open(last = false)\n if @input.disabled\n return @this\n @panel.hidden = false\n @input.setAttribute(\"aria-expanded\", \"true\")\n candidates = []\n index = 0\n for @elements as item\n if item != null\n candidates.add(index)\n index = index + 1\n if candidates.length > 0\n position = 0\n if last\n position = candidates.length - 1\n @cursor = candidates[position]\n if !last and @selected.length > 0\n @cursor = @selected[0]\n focusChoice(@cursor)\n return @this\n\nComboBox:close(focus = false)\n @panel.hidden = true\n @input.setAttribute(\"aria-expanded\", \"false\")\n if focus\n @input.focus()\n return @this\n\nComboBox:focusChoice(index)\n item = @elements[index]\n item.focus()\n return null\n\nComboBox:choose(index)\n if @input.disabled\n return null\n option = @options[index]\n if option.value == null\n return null\n if @multi\n position = @selected.indexOf(index)\n if position < 0\n @selected.add(index)\n else\n @selected.splice(position, 1)\n else\n @selected = [index]\n paint()\n if !@multi\n close(true)\n if option.url != null\n return chain @form.send(option.url)\n catch(error)\n @form.app.error(@form, error)\n return null\n\nComboBox:handleKey(event, index)\n if event.key == \"Escape\"\n event.preventDefault()\n event.stopPropagation()\n close(true)\n return null\n if index < 0\n switch event.key\n case \"ArrowDown\"\n event.preventDefault()\n open()\n case \"ArrowUp\"\n event.preventDefault()\n open(true)\n return null\n if event.key == \"Enter\" or event.key == \" \"\n event.preventDefault()\n choose(index)\n return null\n candidates = []\n position = 0\n for @elements as item\n if item != null\n candidates.add(position)\n position = position + 1\n target = candidates.indexOf(index)\n switch event.key\n case \"ArrowDown\"\n target = (target + 1) % candidates.length\n case \"ArrowUp\"\n target = (target + candidates.length - 1) % candidates.length\n case \"Home\"\n target = 0\n case \"End\"\n target = candidates.length - 1\n else\n return null\n event.preventDefault()\n @cursor = candidates[target]\n focusChoice(@cursor)\n return null\n\nComboBox:dispose()\n for @slots as slot\n slot.dispose()\n @slots = []\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAxBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"combo_box.mjs","sources":["combo_box.lango"],"sourcesContent":["import js global document\nimport \"./fields\"\n class Field\n sameValue(first, second)\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\nimport \"./rich_content\"\n class RichContent\n\nexport comboSelection(options, value, multi)\n\ncomboSelection(options, value, multi)\n requested = []\n if value != null\n if multi\n if !is_array(value)\n throw \"Multi ComboBox value must be an array\"\n requested = value\n else\n requested.add(value)\n selected = []\n for requested as candidate\n found = -1\n index = 0\n for options as option\n if option.value != null and sameValue(option.value, candidate)\n found = index\n break\n index = index + 1\n if found < 0\n throw \"ComboBox value does not identify an option\"\n if !selected.includes(found)\n selected.add(found)\n return selected\n\nexport class ComboBox(form, props, renderer) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n open(last = false)\n close(focus = false)\n choose(index)\n dispose()\n\nComboBox(form, props, renderer)\n super(form, props, cloneMarkup(\"combo-button\", <button type=\"button\" class=\"form-select text-start\" role=\"combobox\" aria-haspopup=\"listbox\" aria-expanded=\"false\"></button>))\n @locked = props.readonly == true\n @multi = props.multi == true\n @options = props.options\n if @options == null\n @options = []\n @selected = []\n @elements = []\n @slots = []\n @cursor = -1\n @element.classList.add(\"lango-combo\")\n @panel = cloneMarkup(\"combo-panel\", <div class=\"lango-combo-panel\" hidden=\"hidden\"><ul class=\"list-group\" role=\"listbox\"></ul></div>)\n list = @panel.firstElementChild\n list.id = controlId()\n if props.aria != null and props.aria.label != null\n list.setAttribute(\"aria-label\", props.aria.label)\n else\n if props.label != null\n list.setAttribute(\"aria-label\", props.label)\n if @multi\n list.setAttribute(\"aria-multiselectable\", \"true\")\n @input.setAttribute(\"aria-controls\", list.id)\n @element.insertBefore(@panel, @input.nextSibling)\n group = list\n index = 0\n for @options as option\n if !is_object(option)\n throw \"ComboBox options require value/control maps\"\n if option.url != null\n if option.value == null\n throw \"ComboBox group cannot have a URL\"\n form.app.checkUrl(option.url)\n item = document/createElement(\"li\")\n slot = null\n if option.value == null\n item.setAttribute(\"role\", \"presentation\")\n heading = document/createElement(\"div\")\n heading.id = controlId()\n heading.className = \"lango-combo-heading\"\n slot = new RichContent(form, heading, renderer, false, \"ComboBox group\")\n slot.replace(option.control)\n @slots.add(slot)\n item.appendChild(heading)\n group = cloneMarkup(\"combo-group\", <ul class=\"list-group\" role=\"group\"></ul>)\n group.setAttribute(\"aria-labelledby\", heading.id)\n item.appendChild(group)\n list.appendChild(item)\n @elements.add(null)\n else\n item.className = \"list-group-item list-group-item-action\"\n item.setAttribute(\"role\", \"option\")\n item.tabIndex = -1\n item.id = controlId()\n slot = new RichContent(form, item, renderer, false, \"ComboBox option\")\n slot.replace(option.control)\n label = item.textContent.trim()\n content = item.firstElementChild\n if content != null and content.hasAttribute(\"aria-label\")\n label = content.getAttribute(\"aria-label\")\n if label == \"\"\n labels = []\n for item.querySelectorAll(\"img[alt]\") as image\n labels.add(image.alt)\n label = labels.join(\" \").trim()\n if label == \"\"\n throw \"ComboBox option requires text or an accessible label\"\n item.setAttribute(\"aria-label\", label)\n @slots.add(slot)\n group.appendChild(item)\n @elements.add(item)\n choice = index\n click = (event)\n capture choice\n event.preventDefault()\n event.stopPropagation()\n choose(choice)\n key = (event)\n capture choice\n handleKey(event, choice)\n listen(item, \"click\", click)\n listen(item, \"keydown\", key)\n index = index + 1\n setValue(props.value)\n setDisabled(props.disabled == true)\n toggle = ()\n if @panel.hidden\n open()\n else\n close()\n key = (event)\n handleKey(event, -1)\n outside = (event)\n if !@panel.hidden and !@element.contains(event.target)\n close()\n listen(@input, \"click\", toggle)\n listen(@input, \"keydown\", key)\n listen(document, \"pointerdown\", outside)\n listen(document, \"focusin\", outside)\n\nComboBox:listen(element, type, listener)\n element.addEventListener(type, listener)\n release = ()\n capture element\n capture type\n capture listener\n element.removeEventListener(type, listener)\n @release.add(release)\n return null\n\nComboBox:getValue()\n values = []\n for @selected as index\n option = @options[index]\n values.add(option.value)\n if @multi\n return values\n if values.length > 0\n return values[0]\n return null\n\nComboBox:setValue(value)\n selected = comboSelection(@options, value, @multi)\n @selected = selected\n paint()\n return @this\n\nComboBox:paint()\n labels = []\n index = 0\n for @elements as item\n if item != null\n selected = @selected.includes(index)\n item.setAttribute(\"aria-selected\", \"${selected}\")\n item.classList.toggle(\"active\", selected)\n index = index + 1\n for @selected as choice\n selectedItem = @elements[choice]\n labels.add(selectedItem.getAttribute(\"aria-label\"))\n @input.textContent = labels.join(\", \")\n return null\n\nComboBox:setDisabled(value)\n @input.disabled = value or @locked == true\n if @input.disabled and @panel != null\n close()\n return @this\n\nComboBox:open(last = false)\n if @input.disabled\n return @this\n @panel.hidden = false\n @input.setAttribute(\"aria-expanded\", \"true\")\n candidates = []\n index = 0\n for @elements as item\n if item != null\n candidates.add(index)\n index = index + 1\n if candidates.length > 0\n position = 0\n if last\n position = candidates.length - 1\n @cursor = candidates[position]\n if !last and @selected.length > 0\n @cursor = @selected[0]\n focusChoice(@cursor)\n return @this\n\nComboBox:close(focus = false)\n @panel.hidden = true\n @input.setAttribute(\"aria-expanded\", \"false\")\n if focus\n @input.focus()\n return @this\n\nComboBox:focusChoice(index)\n item = @elements[index]\n item.focus()\n return null\n\nComboBox:choose(index)\n if @input.disabled\n return null\n option = @options[index]\n if option.value == null\n return null\n if @multi\n position = @selected.indexOf(index)\n if position < 0\n @selected.add(index)\n else\n @selected.splice(position, 1)\n else\n @selected = [index]\n paint()\n if !@multi\n close(true)\n if option.url != null\n return chain @form.send(option.url)\n catch(error)\n @form.app.error(@form, error)\n return null\n\nComboBox:handleKey(event, index)\n if event.key == \"Escape\"\n event.preventDefault()\n event.stopPropagation()\n close(true)\n return null\n if index < 0\n switch event.key\n case \"ArrowDown\"\n event.preventDefault()\n open()\n case \"ArrowUp\"\n event.preventDefault()\n open(true)\n return null\n if event.key == \"Enter\" or event.key == \" \"\n event.preventDefault()\n choose(index)\n return null\n candidates = []\n position = 0\n for @elements as item\n if item != null\n candidates.add(position)\n position = position + 1\n target = candidates.indexOf(index)\n switch event.key\n case \"ArrowDown\"\n target = (target + 1) % candidates.length\n case \"ArrowUp\"\n target = (target + candidates.length - 1) % candidates.length\n case \"Home\"\n target = 0\n case \"End\"\n target = candidates.length - 1\n else\n return null\n event.preventDefault()\n @cursor = candidates[target]\n focusChoice(@cursor)\n return null\n\nComboBox:dispose()\n for @slots as slot\n slot.dispose()\n @slots = []\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAxBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/content.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hostGlobal as __hostGlobal,
|
|
3
|
+
bindContexts as __bindContexts,
|
|
3
4
|
isNumber as __isNumber,
|
|
4
5
|
isString as __isString,
|
|
5
6
|
isBool as __isBool,
|
|
@@ -72,7 +73,7 @@ export function bindAction(control, element, url) {
|
|
|
72
73
|
}
|
|
73
74
|
__normalize(control.form.app.checkUrl(url));
|
|
74
75
|
element.tabIndex = 0;
|
|
75
|
-
let click = __withArity((event) => {
|
|
76
|
+
let click = __withArity(__bindContexts((event) => {
|
|
76
77
|
event = __boundary(event);
|
|
77
78
|
if (__requireBoolean(__normalize(event.defaultPrevented))) {
|
|
78
79
|
return null;
|
|
@@ -85,8 +86,8 @@ export function bindAction(control, element, url) {
|
|
|
85
86
|
__normalize(event.stopPropagation());
|
|
86
87
|
sendAction(control, url);
|
|
87
88
|
return null;
|
|
88
|
-
}, [0], "closure");
|
|
89
|
-
let key = __withArity((event) => {
|
|
89
|
+
}), [0], "closure");
|
|
90
|
+
let key = __withArity(__bindContexts((event) => {
|
|
90
91
|
event = __boundary(event);
|
|
91
92
|
if (__requireBoolean(__requireBoolean(__normalize(event.target) !== element) || __requireBoolean(__requireBoolean(__normalize(event.key) !== "Enter") && __requireBoolean(__normalize(event.key) !== " ")))) {
|
|
92
93
|
return null;
|
|
@@ -95,14 +96,14 @@ export function bindAction(control, element, url) {
|
|
|
95
96
|
__normalize(event.stopPropagation());
|
|
96
97
|
sendAction(control, url);
|
|
97
98
|
return null;
|
|
98
|
-
}, [0], "closure");
|
|
99
|
+
}), [0], "closure");
|
|
99
100
|
__normalize(element.addEventListener("click", click));
|
|
100
101
|
__normalize(element.addEventListener("keydown", key));
|
|
101
|
-
let release = () => {
|
|
102
|
+
let release = __bindContexts(() => {
|
|
102
103
|
__normalize(element.removeEventListener("click", click));
|
|
103
104
|
__normalize(element.removeEventListener("keydown", key));
|
|
104
105
|
return null;
|
|
105
|
-
};
|
|
106
|
+
});
|
|
106
107
|
let releases = __normalize(control.release);
|
|
107
108
|
__add(releases, release);
|
|
108
109
|
return null;
|
|
@@ -113,11 +114,11 @@ function sendAction(control, url) {
|
|
|
113
114
|
__requireArity(arguments.length, [0, 1], "sendAction");
|
|
114
115
|
control = __boundary(control);
|
|
115
116
|
url = __boundary(url);
|
|
116
|
-
return __normalize(control.form.send(url)).catch(__withArity((error) => {
|
|
117
|
+
return __normalize(control.form.send(url)).catch(__withArity(__bindContexts((error) => {
|
|
117
118
|
error = __boundary(error);
|
|
118
119
|
__normalize(control.form.app.error(__normalize(control.form), error));
|
|
119
120
|
return null;
|
|
120
|
-
}, [0], "closure"));
|
|
121
|
+
}), [0], "closure"));
|
|
121
122
|
return null;
|
|
122
123
|
}
|
|
123
124
|
//# sourceMappingURL=content.mjs.map
|
package/dist/content.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.mjs","sources":["content.lango"],"sourcesContent":["import js global document\n\nexport appendContent(form, element, content, renderer)\nexport bindAction(control, element, url)\nexport decorate(control, props)\n\ndecorate(control, props)\n if props.style != null\n for props.style as name: value\n control.element.style.setProperty(name, value)\n if props.aria != null\n for props.aria as name: value\n control.element.setAttribute(\"aria-${name}\", value)\n return null\n\nappendContent(form, element, content, renderer)\n if content == null\n return null\n if is_array(content)\n for content as value\n appendContent(form, element, value, renderer)\n else\n if is_object(content) and is_string(content.type)\n if renderer == null\n throw \"Control content requires a renderer\"\n element.appendChild(renderer.build(form, content))\n else\n if !is_string(content) and !is_number(content)\n throw \"Content must be text or a control\"\n element.appendChild(document/createTextNode(\"${content}\"))\n return null\n\nbindAction(control, element, url)\n if url == null\n return null\n control.form.app.checkUrl(url)\n element.tabIndex = 0\n click = (event)\n capture control\n capture element\n capture url\n if event.defaultPrevented\n return null\n interactive = event.target.closest(\"button, a, input, select, textarea, label, [role=button], [role=tab], [contenteditable=true]\")\n if interactive != null and interactive != element\n return null\n event.preventDefault()\n event.stopPropagation()\n sendAction(control, url)\n key = (event)\n capture control\n capture element\n capture url\n if event.target != element or (event.key != \"Enter\" and event.key != \" \")\n return null\n event.preventDefault()\n event.stopPropagation()\n sendAction(control, url)\n element.addEventListener(\"click\", click)\n element.addEventListener(\"keydown\", key)\n release = ()\n capture element\n capture click\n capture key\n element.removeEventListener(\"click\", click)\n element.removeEventListener(\"keydown\", key)\n releases = control.release\n releases.add(release)\n return null\n\nsendAction(control, url)\n return chain control.form.send(url)\n catch(error)\n capture control\n control.form.app.error(control.form, error)\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content.mjs","sources":["content.lango"],"sourcesContent":["import js global document\n\nexport appendContent(form, element, content, renderer)\nexport bindAction(control, element, url)\nexport decorate(control, props)\n\ndecorate(control, props)\n if props.style != null\n for props.style as name: value\n control.element.style.setProperty(name, value)\n if props.aria != null\n for props.aria as name: value\n control.element.setAttribute(\"aria-${name}\", value)\n return null\n\nappendContent(form, element, content, renderer)\n if content == null\n return null\n if is_array(content)\n for content as value\n appendContent(form, element, value, renderer)\n else\n if is_object(content) and is_string(content.type)\n if renderer == null\n throw \"Control content requires a renderer\"\n element.appendChild(renderer.build(form, content))\n else\n if !is_string(content) and !is_number(content)\n throw \"Content must be text or a control\"\n element.appendChild(document/createTextNode(\"${content}\"))\n return null\n\nbindAction(control, element, url)\n if url == null\n return null\n control.form.app.checkUrl(url)\n element.tabIndex = 0\n click = (event)\n capture control\n capture element\n capture url\n if event.defaultPrevented\n return null\n interactive = event.target.closest(\"button, a, input, select, textarea, label, [role=button], [role=tab], [contenteditable=true]\")\n if interactive != null and interactive != element\n return null\n event.preventDefault()\n event.stopPropagation()\n sendAction(control, url)\n key = (event)\n capture control\n capture element\n capture url\n if event.target != element or (event.key != \"Enter\" and event.key != \" \")\n return null\n event.preventDefault()\n event.stopPropagation()\n sendAction(control, url)\n element.addEventListener(\"click\", click)\n element.addEventListener(\"keydown\", key)\n release = ()\n capture element\n capture click\n capture key\n element.removeEventListener(\"click\", click)\n element.removeEventListener(\"keydown\", key)\n releases = control.release\n releases.add(release)\n return null\n\nsendAction(control, url)\n return chain control.form.send(url)\n catch(error)\n capture control\n control.form.app.error(control.form, error)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA;;;;;;;;;;;;"}
|
package/dist/date_input.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import * as picker from "flatpickr";
|
|
|
5
5
|
import {
|
|
6
6
|
hostGlobal as __hostGlobal,
|
|
7
7
|
xmlEscape as __xmlEscape,
|
|
8
|
+
bindContexts as __bindContexts,
|
|
8
9
|
isNumber as __isNumber,
|
|
9
10
|
isString as __isString,
|
|
10
11
|
isBool as __isBool,
|
|
@@ -79,7 +80,7 @@ export class DateInput extends Field {
|
|
|
79
80
|
locale = __normalize(__hostGlobal(["Object"]).assign(locale, __normalize(format.calendar)));
|
|
80
81
|
}
|
|
81
82
|
let createPicker = __normalize(picker.default);
|
|
82
|
-
let change = __withArity((dates) => {
|
|
83
|
+
let change = __withArity(__bindContexts((dates) => {
|
|
83
84
|
dates = __boundary(dates);
|
|
84
85
|
if (__requireBoolean(__normalize(this.input.disabled))) {
|
|
85
86
|
this.setValue(__normalize(this.#range));
|
|
@@ -96,7 +97,7 @@ export class DateInput extends Field {
|
|
|
96
97
|
this.#range = dateRange({ start: start, end: end }, __normalize(this.#min), __normalize(this.#max));
|
|
97
98
|
__normalize(this.#changes.changed());
|
|
98
99
|
return null;
|
|
99
|
-
}, [0], "closure");
|
|
100
|
+
}), [0], "closure");
|
|
100
101
|
let options = { mode: "range", dateFormat: display, showMonths: months, locale: locale, inline: __normalize(props.inline) === true, appendTo: __normalize(this.element), disableMobile: true, allowInput: false, onChange: change };
|
|
101
102
|
if (__requireBoolean(__normalize(this.#min) !== null)) {
|
|
102
103
|
options.minDate = __normalize(createPicker.parseDate(__normalize(this.#min), "Y-m-d"));
|
package/dist/date_input.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date_input.mjs","sources":["date_input.lango"],"sourcesContent":["import js \"flatpickr\" as picker\nimport js global Intl\nimport js global Date\nimport js global Number\nimport js global RegExp\nimport js global Object\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport dateText(value)\nexport dateRange(value, min = null, max = null)\n\ndateText(value)\n if value == null or value == \"\"\n return null\n pattern = new RegExp(\"^[0-9]{4}-[0-9]{2}-[0-9]{2}$\")\n if !is_string(value) or !pattern.test(value)\n throw \"Date requires YYYY-MM-DD calendar text\"\n year = Number/parseInt(value.slice(0, 4), 10)\n month = Number/parseInt(value.slice(5, 7), 10)\n day = Number/parseInt(value.slice(8, 10), 10)\n days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n if year < 1 or month < 1 or month > 12\n throw \"Invalid calendar date\"\n if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)\n days[1] = 29\n index = month - 1\n if day < 1 or day > days[index]\n throw \"Invalid calendar date\"\n return value\n\ndateRange(value, min = null, max = null)\n if value == null\n value = {}\n if !is_object(value) or is_array(value)\n throw \"Date value requires a start/end map\"\n start = dateText(value.start)\n end = dateText(value.end)\n if end != null and (start == null or end.localeCompare(start) < 0)\n throw \"Date range end must not precede its start\"\n for [start, end] as date\n if date != null and ((min != null and date.localeCompare(min) < 0) or (max != null and date.localeCompare(max) > 0))\n throw \"Date is outside its min/max range\"\n return {\n start: start\n end: end\n }\n\ncalendarLocale(options)\n locale = options.locale\n if locale == null\n locale = []\n months = []\n shortMonths = []\n weekdays = []\n shortWeekdays = []\n month = new Intl/DateTimeFormat(locale, {\n month: \"long\"\n timeZone: \"UTC\"\n })\n shortMonth = new Intl/DateTimeFormat(locale, {\n month: \"short\"\n timeZone: \"UTC\"\n })\n day = new Intl/DateTimeFormat(locale, {\n weekday: \"long\"\n timeZone: \"UTC\"\n })\n shortDay = new Intl/DateTimeFormat(locale, {\n weekday: \"short\"\n timeZone: \"UTC\"\n })\n index = 0\n stamp = null\n loop while index < 12\n stamp = Date/UTC(2020, index, 1)\n months.add(month.format(stamp))\n shortMonths.add(shortMonth.format(stamp))\n index = index + 1\n index = 1\n loop while index <= 7\n stamp = Date/UTC(2020, 10, index)\n weekdays.add(day.format(stamp))\n shortWeekdays.add(shortDay.format(stamp))\n index = index + 1\n return {\n weekdays: {\n longhand: weekdays\n shorthand: shortWeekdays\n }\n months: {\n longhand: months\n shorthand: shortMonths\n }\n rangeSeparator: \" – \"\n monthAriaLabel: \"\"\n yearAriaLabel: \"\"\n }\n\nexport class DateInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n dispose()\n\nDateInput(form, props)\n super(form, props, cloneMarkup(\"date-input\", <input type=\"text\" class=\"form-control\" />))\n @changes = new InputChanges(form, props.url)\n @locked = props.readonly == true\n @min = dateText(props.min)\n @max = dateText(props.max)\n if @min != null and @max != null and @min.localeCompare(@max) > 0\n throw \"Date min must not exceed max\"\n @range = dateRange(props.value, @min, @max)\n months = props.multiMonth\n if months == null\n months = 1\n if !is_number(months) or !Number/isInteger(months) or months < 1 or months > 12\n throw \"Date multiMonth must be an integer between 1 and 12\"\n first = props.firstWeekDay\n if first == null\n first = 1\n if !is_number(first) or !Number/isInteger(first) or first < 0 or first > 6\n throw \"Date firstWeekDay must be an integer between 0 and 6\"\n format = {}\n if is_string(props.format)\n format.display = props.format\n else\n if props.format != null\n if !is_object(props.format) or is_array(props.format)\n throw \"Date format must be a display format or options map\"\n format = Object/assign({}, props.format)\n display = format.display\n if display == null\n display = \"Y-m-d\"\n locale = calendarLocale(format)\n locale.firstDayOfWeek = first\n if props.label != null\n locale.monthAriaLabel = props.label\n locale.yearAriaLabel = props.label\n if format.calendar != null\n locale = Object/assign(locale, format.calendar)\n createPicker = picker.default\n change = (dates)\n if @input.disabled\n setValue(@range)\n return null\n start = null\n end = null\n if dates.length > 0\n start = @picker.formatDate(dates[0], \"Y-m-d\")\n if dates.length > 1\n end = @picker.formatDate(dates[1], \"Y-m-d\")\n @range = dateRange({\n start: start\n end: end\n }, @min, @max)\n @changes.changed()\n options = {\n mode: \"range\"\n dateFormat: display\n showMonths: months\n locale: locale\n inline: props.inline == true\n appendTo: @element\n disableMobile: true\n allowInput: false\n onChange: change\n }\n if @min != null\n options.minDate = createPicker.parseDate(@min, \"Y-m-d\")\n if @max != null\n options.maxDate = createPicker.parseDate(@max, \"Y-m-d\")\n @picker = createPicker(@input, options)\n if props.button == true\n @input.className = \"btn btn-outline-secondary\"\n setValue(@range)\n setDisabled(props.disabled == true)\n\nDateInput:getValue()\n return {\n start: @range.start\n end: @range.end\n }\n\nDateInput:setValue(value)\n range = dateRange(value, @min, @max)\n dates = []\n if range.start != null\n dates.add(range.start)\n if range.end != null\n dates.add(range.end)\n @picker.setDate(dates, false, \"Y-m-d\")\n @range = range\n return @this\n\nDateInput:setDisabled(value)\n @input.disabled = value or @locked == true\n if @picker != null\n calendar = @picker.calendarContainer\n calendar.inert = @input.disabled\n if @input.disabled\n @picker.close()\n return @this\n\nDateInput:dispose()\n @changes.dispose()\n @picker.destroy()\n super.dispose()\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date_input.mjs","sources":["date_input.lango"],"sourcesContent":["import js \"flatpickr\" as picker\nimport js global Intl\nimport js global Date\nimport js global Number\nimport js global RegExp\nimport js global Object\nimport \"./fields\"\n class Field\nimport \"./templates\"\n cloneMarkup(name, xml)\nimport \"./input_changes\"\n class InputChanges\n\nexport dateText(value)\nexport dateRange(value, min = null, max = null)\n\ndateText(value)\n if value == null or value == \"\"\n return null\n pattern = new RegExp(\"^[0-9]{4}-[0-9]{2}-[0-9]{2}$\")\n if !is_string(value) or !pattern.test(value)\n throw \"Date requires YYYY-MM-DD calendar text\"\n year = Number/parseInt(value.slice(0, 4), 10)\n month = Number/parseInt(value.slice(5, 7), 10)\n day = Number/parseInt(value.slice(8, 10), 10)\n days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n if year < 1 or month < 1 or month > 12\n throw \"Invalid calendar date\"\n if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)\n days[1] = 29\n index = month - 1\n if day < 1 or day > days[index]\n throw \"Invalid calendar date\"\n return value\n\ndateRange(value, min = null, max = null)\n if value == null\n value = {}\n if !is_object(value) or is_array(value)\n throw \"Date value requires a start/end map\"\n start = dateText(value.start)\n end = dateText(value.end)\n if end != null and (start == null or end.localeCompare(start) < 0)\n throw \"Date range end must not precede its start\"\n for [start, end] as date\n if date != null and ((min != null and date.localeCompare(min) < 0) or (max != null and date.localeCompare(max) > 0))\n throw \"Date is outside its min/max range\"\n return {\n start: start\n end: end\n }\n\ncalendarLocale(options)\n locale = options.locale\n if locale == null\n locale = []\n months = []\n shortMonths = []\n weekdays = []\n shortWeekdays = []\n month = new Intl/DateTimeFormat(locale, {\n month: \"long\"\n timeZone: \"UTC\"\n })\n shortMonth = new Intl/DateTimeFormat(locale, {\n month: \"short\"\n timeZone: \"UTC\"\n })\n day = new Intl/DateTimeFormat(locale, {\n weekday: \"long\"\n timeZone: \"UTC\"\n })\n shortDay = new Intl/DateTimeFormat(locale, {\n weekday: \"short\"\n timeZone: \"UTC\"\n })\n index = 0\n stamp = null\n loop while index < 12\n stamp = Date/UTC(2020, index, 1)\n months.add(month.format(stamp))\n shortMonths.add(shortMonth.format(stamp))\n index = index + 1\n index = 1\n loop while index <= 7\n stamp = Date/UTC(2020, 10, index)\n weekdays.add(day.format(stamp))\n shortWeekdays.add(shortDay.format(stamp))\n index = index + 1\n return {\n weekdays: {\n longhand: weekdays\n shorthand: shortWeekdays\n }\n months: {\n longhand: months\n shorthand: shortMonths\n }\n rangeSeparator: \" – \"\n monthAriaLabel: \"\"\n yearAriaLabel: \"\"\n }\n\nexport class DateInput(form, props) : Field\n methods\n getValue()\n setValue(value)\n setDisabled(value)\n dispose()\n\nDateInput(form, props)\n super(form, props, cloneMarkup(\"date-input\", <input type=\"text\" class=\"form-control\" />))\n @changes = new InputChanges(form, props.url)\n @locked = props.readonly == true\n @min = dateText(props.min)\n @max = dateText(props.max)\n if @min != null and @max != null and @min.localeCompare(@max) > 0\n throw \"Date min must not exceed max\"\n @range = dateRange(props.value, @min, @max)\n months = props.multiMonth\n if months == null\n months = 1\n if !is_number(months) or !Number/isInteger(months) or months < 1 or months > 12\n throw \"Date multiMonth must be an integer between 1 and 12\"\n first = props.firstWeekDay\n if first == null\n first = 1\n if !is_number(first) or !Number/isInteger(first) or first < 0 or first > 6\n throw \"Date firstWeekDay must be an integer between 0 and 6\"\n format = {}\n if is_string(props.format)\n format.display = props.format\n else\n if props.format != null\n if !is_object(props.format) or is_array(props.format)\n throw \"Date format must be a display format or options map\"\n format = Object/assign({}, props.format)\n display = format.display\n if display == null\n display = \"Y-m-d\"\n locale = calendarLocale(format)\n locale.firstDayOfWeek = first\n if props.label != null\n locale.monthAriaLabel = props.label\n locale.yearAriaLabel = props.label\n if format.calendar != null\n locale = Object/assign(locale, format.calendar)\n createPicker = picker.default\n change = (dates)\n if @input.disabled\n setValue(@range)\n return null\n start = null\n end = null\n if dates.length > 0\n start = @picker.formatDate(dates[0], \"Y-m-d\")\n if dates.length > 1\n end = @picker.formatDate(dates[1], \"Y-m-d\")\n @range = dateRange({\n start: start\n end: end\n }, @min, @max)\n @changes.changed()\n options = {\n mode: \"range\"\n dateFormat: display\n showMonths: months\n locale: locale\n inline: props.inline == true\n appendTo: @element\n disableMobile: true\n allowInput: false\n onChange: change\n }\n if @min != null\n options.minDate = createPicker.parseDate(@min, \"Y-m-d\")\n if @max != null\n options.maxDate = createPicker.parseDate(@max, \"Y-m-d\")\n @picker = createPicker(@input, options)\n if props.button == true\n @input.className = \"btn btn-outline-secondary\"\n setValue(@range)\n setDisabled(props.disabled == true)\n\nDateInput:getValue()\n return {\n start: @range.start\n end: @range.end\n }\n\nDateInput:setValue(value)\n range = dateRange(value, @min, @max)\n dates = []\n if range.start != null\n dates.add(range.start)\n if range.end != null\n dates.add(range.end)\n @picker.setDate(dates, false, \"Y-m-d\")\n @range = range\n return @this\n\nDateInput:setDisabled(value)\n @input.disabled = value or @locked == true\n if @picker != null\n calendar = @picker.calendarContainer\n calendar.inert = @input.disabled\n if @input.disabled\n @picker.close()\n return @this\n\nDateInput:dispose()\n @changes.dispose()\n @picker.destroy()\n super.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAvFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/error_reporter.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hostGlobal as __hostGlobal,
|
|
3
|
+
bindContexts as __bindContexts,
|
|
3
4
|
isNumber as __isNumber,
|
|
4
5
|
isString as __isString,
|
|
5
6
|
isBool as __isBool,
|
|
@@ -83,11 +84,11 @@ export class ErrorReporter {
|
|
|
83
84
|
}
|
|
84
85
|
schedule() {
|
|
85
86
|
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.active)) && __requireBoolean(!__requireBoolean(__normalize(this.#flight)))) && __requireBoolean(__normalize(this.#timer) === null)) && __requireBoolean(__normalize(this.#pending.length) > 0))) {
|
|
86
|
-
let action = () => {
|
|
87
|
+
let action = __bindContexts(() => {
|
|
87
88
|
this.#timer = null;
|
|
88
89
|
this.flush();
|
|
89
90
|
return null;
|
|
90
|
-
};
|
|
91
|
+
});
|
|
91
92
|
this.#timer = __normalize(this.#app.schedule(action, 0));
|
|
92
93
|
}
|
|
93
94
|
return null;
|
|
@@ -111,15 +112,15 @@ export class ErrorReporter {
|
|
|
111
112
|
}
|
|
112
113
|
this.#sent = __numericAdd(__normalize(this.#sent), 1);
|
|
113
114
|
this.#flight = true;
|
|
114
|
-
return __normalize(this.#app.report(__normalize(entry.form), __normalize(this.#url), __normalize(entry.report), this)).catch(__withArity((error) => {
|
|
115
|
+
return __normalize(this.#app.report(__normalize(entry.form), __normalize(this.#url), __normalize(entry.report), this)).catch(__withArity(__bindContexts((error) => {
|
|
115
116
|
error = __boundary(error);
|
|
116
117
|
return null;
|
|
117
118
|
return null;
|
|
118
|
-
}, [0], "closure")).finally(() => {
|
|
119
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
119
120
|
this.#flight = false;
|
|
120
121
|
this.schedule();
|
|
121
122
|
return null;
|
|
122
|
-
});
|
|
123
|
+
}));
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
125
126
|
dispose() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_reporter.mjs","sources":["error_reporter.lango"],"sourcesContent":["import js global Promise\nimport js global Math\nimport js global RegExp\n\nexport class ErrorReporter(app, url)\n properties\n active\n methods\n capture(source, code, name, form)\n schedule()\n flush()\n dispose()\n\nErrorReporter(app, url)\n app.checkUrl(url)\n @app = app\n @url = url\n @active = true\n @pending = []\n @timer = null\n @flight = false\n @window = app.now()\n @sent = 0\n\nErrorReporter:capture(source, code, name, form)\n if !@active or form == null or form.disposed\n return null\n if @app.now() - @window >= 60000\n @window = @app.now()\n @sent = 0\n if @sent >= 10\n return null\n sources = [\"ui\", \"window\", \"promise\"]\n valid = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !sources.includes(source) or !is_string(code) or !valid.test(code)\n return null\n if !is_string(name) or name.trim() == \"\" or name.length > 256\n name = null\n for @pending as entry\n previous = entry.report\n if entry.form == form and previous.source == source and previous.code == code and previous.name == name\n previous.count = Math/min(100, previous.count + 1)\n return null\n if @pending.length >= 20\n return null\n report = {\n source: source\n code: code\n count: 1\n }\n if name != null\n report.name = name\n @pending.add({\n form: form\n report: report\n })\n schedule()\n return null\n\nErrorReporter:schedule()\n if @active and !@flight and @timer == null and @pending.length > 0\n action = ()\n @timer = null\n flush()\n @timer = @app.schedule(action, 0)\n return null\n\nErrorReporter:flush()\n if !@active or @flight\n return Promise/resolve(null)\n if @sent >= 10\n @pending = []\n return Promise/resolve(null)\n entry = @pending.shift()\n if entry == null\n return Promise/resolve(null)\n if entry.form.disposed\n schedule()\n return Promise/resolve(null)\n @sent = @sent + 1\n @flight = true\n return chain @app.report(entry.form, @url, entry.report, @this)\n catch(error)\n return null\n finally\n @flight = false\n schedule()\n\nErrorReporter:dispose()\n @active = false\n @pending = []\n if @timer != null\n @app.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error_reporter.mjs","sources":["error_reporter.lango"],"sourcesContent":["import js global Promise\nimport js global Math\nimport js global RegExp\n\nexport class ErrorReporter(app, url)\n properties\n active\n methods\n capture(source, code, name, form)\n schedule()\n flush()\n dispose()\n\nErrorReporter(app, url)\n app.checkUrl(url)\n @app = app\n @url = url\n @active = true\n @pending = []\n @timer = null\n @flight = false\n @window = app.now()\n @sent = 0\n\nErrorReporter:capture(source, code, name, form)\n if !@active or form == null or form.disposed\n return null\n if @app.now() - @window >= 60000\n @window = @app.now()\n @sent = 0\n if @sent >= 10\n return null\n sources = [\"ui\", \"window\", \"promise\"]\n valid = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !sources.includes(source) or !is_string(code) or !valid.test(code)\n return null\n if !is_string(name) or name.trim() == \"\" or name.length > 256\n name = null\n for @pending as entry\n previous = entry.report\n if entry.form == form and previous.source == source and previous.code == code and previous.name == name\n previous.count = Math/min(100, previous.count + 1)\n return null\n if @pending.length >= 20\n return null\n report = {\n source: source\n code: code\n count: 1\n }\n if name != null\n report.name = name\n @pending.add({\n form: form\n report: report\n })\n schedule()\n return null\n\nErrorReporter:schedule()\n if @active and !@flight and @timer == null and @pending.length > 0\n action = ()\n @timer = null\n flush()\n @timer = @app.schedule(action, 0)\n return null\n\nErrorReporter:flush()\n if !@active or @flight\n return Promise/resolve(null)\n if @sent >= 10\n @pending = []\n return Promise/resolve(null)\n entry = @pending.shift()\n if entry == null\n return Promise/resolve(null)\n if entry.form.disposed\n schedule()\n return Promise/resolve(null)\n @sent = @sent + 1\n @flight = true\n return chain @app.report(entry.form, @url, entry.report, @this)\n catch(error)\n return null\n finally\n @flight = false\n schedule()\n\nErrorReporter:dispose()\n @active = false\n @pending = []\n if @timer != null\n @app.cancelTimer(@timer)\n @timer = null\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|