@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.
Files changed (65) hide show
  1. package/README.md +26 -0
  2. package/cli/.lango/runtime.mjs +16 -0
  3. package/dist/.lango/runtime.mjs +16 -0
  4. package/dist/accordion.mjs +9 -8
  5. package/dist/accordion.mjs.map +1 -1
  6. package/dist/activities.mjs +8 -7
  7. package/dist/activities.mjs.map +1 -1
  8. package/dist/app.mjs +465 -50
  9. package/dist/app.mjs.map +1 -1
  10. package/dist/boot.mjs +3 -2
  11. package/dist/boot.mjs.map +1 -1
  12. package/dist/button.mjs +8 -7
  13. package/dist/button.mjs.map +1 -1
  14. package/dist/chip.mjs +5 -4
  15. package/dist/chip.mjs.map +1 -1
  16. package/dist/combo_box.mjs +15 -14
  17. package/dist/combo_box.mjs.map +1 -1
  18. package/dist/content.mjs +9 -8
  19. package/dist/content.mjs.map +1 -1
  20. package/dist/date_input.mjs +3 -2
  21. package/dist/date_input.mjs.map +1 -1
  22. package/dist/error_reporter.mjs +6 -5
  23. package/dist/error_reporter.mjs.map +1 -1
  24. package/dist/fields.mjs +9 -8
  25. package/dist/fields.mjs.map +1 -1
  26. package/dist/file_input.mjs +19 -18
  27. package/dist/file_input.mjs.map +1 -1
  28. package/dist/form.mjs +14 -2
  29. package/dist/form.mjs.map +1 -1
  30. package/dist/heartbeat.mjs +12 -11
  31. package/dist/heartbeat.mjs.map +1 -1
  32. package/dist/input_changes.mjs +5 -4
  33. package/dist/input_changes.mjs.map +1 -1
  34. package/dist/longpoll.mjs +12 -11
  35. package/dist/longpoll.mjs.map +1 -1
  36. package/dist/main.mjs +35 -18
  37. package/dist/main.mjs.map +1 -1
  38. package/dist/menus.mjs +19 -18
  39. package/dist/menus.mjs.map +1 -1
  40. package/dist/navigation.mjs +7 -6
  41. package/dist/navigation.mjs.map +1 -1
  42. package/dist/numeric_input.mjs +9 -8
  43. package/dist/numeric_input.mjs.map +1 -1
  44. package/dist/otp_input.mjs +5 -4
  45. package/dist/otp_input.mjs.map +1 -1
  46. package/dist/presentations.mjs +17 -16
  47. package/dist/presentations.mjs.map +1 -1
  48. package/dist/renderer.mjs +74 -0
  49. package/dist/renderer.mjs.map +1 -1
  50. package/dist/table_scope.mjs +3 -2
  51. package/dist/table_scope.mjs.map +1 -1
  52. package/dist/tables.mjs +11 -10
  53. package/dist/tables.mjs.map +1 -1
  54. package/dist/tabs.mjs +7 -6
  55. package/dist/tabs.mjs.map +1 -1
  56. package/dist/vendor/dompurify.mjs +267 -181
  57. package/dist/vendor/purify.es.mjs.map +1 -1
  58. package/dist/widgets.mjs +5 -4
  59. package/dist/widgets.mjs.map +1 -1
  60. package/package.json +4 -3
  61. package/src/app.lango +325 -11
  62. package/src/form.lango +12 -2
  63. package/src/heartbeat.lango +2 -2
  64. package/src/main.lango +15 -0
  65. package/src/renderer.lango +61 -0
package/README.md CHANGED
@@ -625,3 +625,29 @@ The dispatcher accepts `addRow`, `insertRow`, `deleteRow`, `setRowValue`,
625
625
  insertion at the row count appends. Full `values` commands retain their final
626
626
  position after incremental commands. See the Lango UI package
627
627
  documentation for builder examples and precise collection rules.
628
+
629
+
630
+ Login recovery is optional: bootstrap may advertise `needLoginUrl`. A marked
631
+ Server policy challenge suspends the exact form submission and opens an isolated
632
+ login form using that UI handler. `loginSatisfied` closes the form and replays the
633
+ submission once with the new token; `cancelLogin` or closing the modal abandons it.
634
+ An account change during reauthentication prevents replay. Ordinary HTTP errors,
635
+ invalid tokens, transport failures and handler failures are never retried.
636
+ The startup invalid-token clear-and-reload behavior remains unchanged.
637
+
638
+
639
+ After a successful authentication transition, forms sharing the original token
640
+ adopt the new token. Distinct form scopes and other same-origin tabs retain their
641
+ visible inputs and show an explicit reload notice; stale requests are blocked.
642
+ Only an opaque change identifier is broadcast through localStorage. Pending old
643
+ requests are canceled and late responses cannot overwrite current state. An
644
+ already dispatched server operation may still have executed and is never retried
645
+ automatically. Startup prefers the token saved for the current authentication
646
+ generation, preventing a racing old tab from restoring an obsolete saved token.
647
+
648
+
649
+ `npm run test:security` runs the complete Secure notes application from
650
+ `lango-ui/examples/security`. It installs local package archives offline and uses
651
+ real SQLite accounts, HTTPS/Secure cookies and Chromium to check login replay,
652
+ password confirmation, logout, transaction rollback and ban across clients.
653
+ The application starts after its compiler dependency has been removed.
@@ -682,6 +682,22 @@ export function withArity(callback, requiredPositions, name) {
682
682
  };
683
683
  }
684
684
 
685
+ // Capture the environment even when context use is hidden in a downstream call.
686
+ // Each invocation uses fresh stack arrays and restores the caller synchronously.
687
+ export function bindContexts(callback) {
688
+ const captured = new Map([...contexts].map(([name, stack]) => [name, stack.at(-1)]));
689
+ return function (...args) {
690
+ const previous = new Map(contexts);
691
+ for (const [name, value] of captured) contexts.set(name, [value]);
692
+ try {
693
+ return Reflect.apply(callback, this, args);
694
+ } finally {
695
+ contexts.clear();
696
+ for (const [name, stack] of previous) contexts.set(name, stack);
697
+ }
698
+ };
699
+ }
700
+
685
701
  export function contextGet(name) {
686
702
  const stack = contexts.get(name);
687
703
  if ((!stack || stack.length === 0) && name === "log") return defaultLog;
@@ -680,6 +680,22 @@ export function withArity(callback, requiredPositions, name) {
680
680
  };
681
681
  }
682
682
 
683
+ // Capture the environment even when context use is hidden in a downstream call.
684
+ // Each invocation uses fresh stack arrays and restores the caller synchronously.
685
+ export function bindContexts(callback) {
686
+ const captured = new Map([...contexts].map(([name, stack]) => [name, stack.at(-1)]));
687
+ return function (...args) {
688
+ const previous = new Map(contexts);
689
+ for (const [name, value] of captured) contexts.set(name, [value]);
690
+ try {
691
+ return Reflect.apply(callback, this, args);
692
+ } finally {
693
+ contexts.clear();
694
+ for (const [name, stack] of previous) contexts.set(name, stack);
695
+ }
696
+ };
697
+ }
698
+
683
699
  export function contextGet(name) {
684
700
  const stack = contexts.get(name);
685
701
  if ((!stack || stack.length === 0) && name === "log") return defaultLog;
@@ -4,6 +4,7 @@ import { appendContent, decorate } from "./content.mjs";
4
4
  import { sameValue } from "./fields.mjs";
5
5
  import {
6
6
  xmlEscape as __xmlEscape,
7
+ bindContexts as __bindContexts,
7
8
  isNumber as __isNumber,
8
9
  isString as __isString,
9
10
  isBool as __isBool,
@@ -85,11 +86,11 @@ export class Accordion extends Control {
85
86
  }
86
87
  __normalize(item.apply(opened));
87
88
  if (__requireBoolean(__normalize(this.#url) !== null)) {
88
- return __normalize(this.form.send(__normalize(this.#url))).catch(__withArity((error) => {
89
+ return __normalize(this.form.send(__normalize(this.#url))).catch(__withArity(__bindContexts((error) => {
89
90
  error = __boundary(error);
90
91
  __normalize(this.form.app.error(__normalize(this.form), error));
91
92
  return null;
92
- }, [0], "closure"));
93
+ }), [0], "closure"));
93
94
  }
94
95
  return null;
95
96
  return null;
@@ -222,24 +223,24 @@ export class AccordionItem extends Control {
222
223
  }
223
224
  decorate(this, props);
224
225
  this.apply(__normalize(props.opened) === true);
225
- let click = () => {
226
+ let click = __bindContexts(() => {
226
227
  __normalize(this.#owner.toggle(this));
227
228
  return null;
228
- };
229
- let key = __withArity((event) => {
229
+ });
230
+ let key = __withArity(__bindContexts((event) => {
230
231
  event = __boundary(event);
231
232
  if (__requireBoolean(__normalize(this.#owner.move(this, __normalize(event.key))))) {
232
233
  __normalize(event.preventDefault());
233
234
  }
234
235
  return null;
235
- }, [0], "closure");
236
+ }), [0], "closure");
236
237
  __normalize(this.button.addEventListener("click", click));
237
238
  __normalize(this.button.addEventListener("keydown", key));
238
- let release = () => {
239
+ let release = __bindContexts(() => {
239
240
  __normalize(this.button.removeEventListener("click", click));
240
241
  __normalize(this.button.removeEventListener("keydown", key));
241
242
  return null;
242
- };
243
+ });
243
244
  __add(this.release, release);
244
245
  }
245
246
  apply(opened) {
@@ -1 +1 @@
1
- {"version":3,"file":"accordion.mjs","sources":["accordion.lango"],"sourcesContent":["import js global document\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\nimport \"./content\"\n appendContent(form, element, content, renderer)\n decorate(control, props)\nimport \"./fields\"\n sameValue(first, second)\n\nexport class Accordion(form, props, renderer) : Control\n properties\n disabled\n methods\n toggle(item)\n getValue()\n setValue(value)\n setDisabled(value)\n move(item, key)\n\nAccordion(form, props, renderer)\n super(form, props, cloneMarkup(\"accordion\", <div class=\"accordion\"></div>))\n @items = []\n @multi = props.multi == true\n @disabled = false\n @url = props.url\n if @url != null\n form.app.checkUrl(@url)\n if props.small == true\n @element.classList.add(\"lango-accordion-small\")\n if props.gap != null and props.gap != false\n @element.classList.add(\"lango-accordion-gap\")\n gap = props.gap\n if gap == true\n gap = \".5rem\"\n else\n if is_number(gap)\n gap = \"${gap}px\"\n @element.style.gap = gap\n opened = false\n if props.items != null\n for props.items as definition\n if !is_object(definition) or definition.type != \"accordionItem\"\n throw \"Accordion accepts AccordionItem definitions\"\n if definition.opened == true and !@multi\n if opened\n throw \"Single Accordion accepts only one initially opened item\"\n opened = true\n item = new AccordionItem(form, definition, renderer, @this)\n form.register(definition.name, item)\n @items.add(item)\n @element.appendChild(item.element)\n\nAccordion:toggle(item)\n if @disabled or item.button.disabled\n return null\n opened = !item.opened\n if opened and !@multi\n for @items as sibling\n sibling.apply(false)\n item.apply(opened)\n if @url != null\n return chain @form.send(@url)\n catch(error)\n @form.app.error(@form, error)\n return null\n\nAccordion:getValue()\n values = []\n for @items as item\n if item.opened\n if !@multi\n return item.value\n values.add(item.value)\n if @multi\n return values\n return null\n\nAccordion:setValue(value)\n values = value\n if !@multi\n values = []\n if value != null\n values.add(value)\n else\n if !is_array(values)\n throw \"Multi Accordion value must be an array\"\n selected = []\n for values as candidate\n found = null\n for @items as item\n if sameValue(item.value, candidate)\n found = item\n break\n if found == null\n throw \"Accordion value does not identify an item\"\n if !selected.includes(found)\n selected.add(found)\n for @items as item\n item.apply(selected.includes(item))\n return @this\n\nAccordion:setDisabled(value)\n @disabled = value\n for @items as item\n item.syncDisabled()\n return @this\n\nAccordion:move(item, key)\n items = []\n for @items as candidate\n if !candidate.button.disabled\n items.add(candidate)\n if items.length == 0\n return false\n index = items.indexOf(item)\n switch key\n case \"ArrowDown\"\n index = (index + 1) % items.length\n case \"ArrowUp\"\n index = (index + items.length - 1) % items.length\n case \"Home\"\n index = 0\n case \"End\"\n index = items.length - 1\n else\n return false\n target = items[index]\n target.button.focus()\n return true\n\nexport class AccordionItem(form, props, renderer, owner) : Control\n properties\n button\n opened\n value\n methods\n apply(opened)\n setDisabled(value)\n syncDisabled()\n setCaption(value)\n\nAccordionItem(form, props, renderer, owner)\n super(form, props, cloneMarkup(\"accordion-item\", <div class=\"accordion-item\"><h3 class=\"accordion-header\"><button type=\"button\" class=\"accordion-button\"></button></h3><div class=\"accordion-collapse collapse\"><div class=\"accordion-body\"></div></div></div>))\n @owner = owner\n @disabled = false\n @value = props.value\n @button = @element.firstElementChild.firstElementChild\n @panel = @element.lastElementChild\n @button.id = controlId()\n @panel.id = controlId()\n @button.setAttribute(\"aria-controls\", @panel.id)\n @panel.setAttribute(\"aria-labelledby\", @button.id)\n @panel.setAttribute(\"role\", \"region\")\n appendContent(form, @button, props.summary, renderer)\n if @button.querySelector(\"button, a, input, select, textarea, [contenteditable]\") != null\n throw \"Accordion summary cannot contain interactive controls\"\n appendContent(form, @panel.firstElementChild, props.body, renderer)\n if props.theme != null\n @element.classList.add(\"text-bg-${props.theme.toLowerCase()}\")\n decorate(@this, props)\n apply(props.opened == true)\n click = ()\n @owner.toggle(@this)\n key = (event)\n if @owner.move(@this, event.key)\n event.preventDefault()\n @button.addEventListener(\"click\", click)\n @button.addEventListener(\"keydown\", key)\n release = ()\n capture click\n capture key\n @button.removeEventListener(\"click\", click)\n @button.removeEventListener(\"keydown\", key)\n @release.add(release)\n\nAccordionItem:apply(opened)\n @opened = opened\n @button.setAttribute(\"aria-expanded\", \"${opened}\")\n @button.classList.toggle(\"collapsed\", !opened)\n @panel.hidden = !opened\n @panel.classList.toggle(\"show\", opened)\n return @this\n\nAccordionItem:setDisabled(value)\n @disabled = value\n syncDisabled()\n return @this\n\nAccordionItem:syncDisabled()\n @button.disabled = @disabled or @owner.disabled\n return null\n\nAccordionItem:setCaption(value)\n @button.textContent = value\n return @this\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"accordion.mjs","sources":["accordion.lango"],"sourcesContent":["import js global document\nimport \"./control\"\n class Control\nimport \"./templates\"\n cloneMarkup(name, xml)\n controlId()\nimport \"./content\"\n appendContent(form, element, content, renderer)\n decorate(control, props)\nimport \"./fields\"\n sameValue(first, second)\n\nexport class Accordion(form, props, renderer) : Control\n properties\n disabled\n methods\n toggle(item)\n getValue()\n setValue(value)\n setDisabled(value)\n move(item, key)\n\nAccordion(form, props, renderer)\n super(form, props, cloneMarkup(\"accordion\", <div class=\"accordion\"></div>))\n @items = []\n @multi = props.multi == true\n @disabled = false\n @url = props.url\n if @url != null\n form.app.checkUrl(@url)\n if props.small == true\n @element.classList.add(\"lango-accordion-small\")\n if props.gap != null and props.gap != false\n @element.classList.add(\"lango-accordion-gap\")\n gap = props.gap\n if gap == true\n gap = \".5rem\"\n else\n if is_number(gap)\n gap = \"${gap}px\"\n @element.style.gap = gap\n opened = false\n if props.items != null\n for props.items as definition\n if !is_object(definition) or definition.type != \"accordionItem\"\n throw \"Accordion accepts AccordionItem definitions\"\n if definition.opened == true and !@multi\n if opened\n throw \"Single Accordion accepts only one initially opened item\"\n opened = true\n item = new AccordionItem(form, definition, renderer, @this)\n form.register(definition.name, item)\n @items.add(item)\n @element.appendChild(item.element)\n\nAccordion:toggle(item)\n if @disabled or item.button.disabled\n return null\n opened = !item.opened\n if opened and !@multi\n for @items as sibling\n sibling.apply(false)\n item.apply(opened)\n if @url != null\n return chain @form.send(@url)\n catch(error)\n @form.app.error(@form, error)\n return null\n\nAccordion:getValue()\n values = []\n for @items as item\n if item.opened\n if !@multi\n return item.value\n values.add(item.value)\n if @multi\n return values\n return null\n\nAccordion:setValue(value)\n values = value\n if !@multi\n values = []\n if value != null\n values.add(value)\n else\n if !is_array(values)\n throw \"Multi Accordion value must be an array\"\n selected = []\n for values as candidate\n found = null\n for @items as item\n if sameValue(item.value, candidate)\n found = item\n break\n if found == null\n throw \"Accordion value does not identify an item\"\n if !selected.includes(found)\n selected.add(found)\n for @items as item\n item.apply(selected.includes(item))\n return @this\n\nAccordion:setDisabled(value)\n @disabled = value\n for @items as item\n item.syncDisabled()\n return @this\n\nAccordion:move(item, key)\n items = []\n for @items as candidate\n if !candidate.button.disabled\n items.add(candidate)\n if items.length == 0\n return false\n index = items.indexOf(item)\n switch key\n case \"ArrowDown\"\n index = (index + 1) % items.length\n case \"ArrowUp\"\n index = (index + items.length - 1) % items.length\n case \"Home\"\n index = 0\n case \"End\"\n index = items.length - 1\n else\n return false\n target = items[index]\n target.button.focus()\n return true\n\nexport class AccordionItem(form, props, renderer, owner) : Control\n properties\n button\n opened\n value\n methods\n apply(opened)\n setDisabled(value)\n syncDisabled()\n setCaption(value)\n\nAccordionItem(form, props, renderer, owner)\n super(form, props, cloneMarkup(\"accordion-item\", <div class=\"accordion-item\"><h3 class=\"accordion-header\"><button type=\"button\" class=\"accordion-button\"></button></h3><div class=\"accordion-collapse collapse\"><div class=\"accordion-body\"></div></div></div>))\n @owner = owner\n @disabled = false\n @value = props.value\n @button = @element.firstElementChild.firstElementChild\n @panel = @element.lastElementChild\n @button.id = controlId()\n @panel.id = controlId()\n @button.setAttribute(\"aria-controls\", @panel.id)\n @panel.setAttribute(\"aria-labelledby\", @button.id)\n @panel.setAttribute(\"role\", \"region\")\n appendContent(form, @button, props.summary, renderer)\n if @button.querySelector(\"button, a, input, select, textarea, [contenteditable]\") != null\n throw \"Accordion summary cannot contain interactive controls\"\n appendContent(form, @panel.firstElementChild, props.body, renderer)\n if props.theme != null\n @element.classList.add(\"text-bg-${props.theme.toLowerCase()}\")\n decorate(@this, props)\n apply(props.opened == true)\n click = ()\n @owner.toggle(@this)\n key = (event)\n if @owner.move(@this, event.key)\n event.preventDefault()\n @button.addEventListener(\"click\", click)\n @button.addEventListener(\"keydown\", key)\n release = ()\n capture click\n capture key\n @button.removeEventListener(\"click\", click)\n @button.removeEventListener(\"keydown\", key)\n @release.add(release)\n\nAccordionItem:apply(opened)\n @opened = opened\n @button.setAttribute(\"aria-expanded\", \"${opened}\")\n @button.classList.toggle(\"collapsed\", !opened)\n @panel.hidden = !opened\n @panel.classList.toggle(\"show\", opened)\n return @this\n\nAccordionItem:setDisabled(value)\n @disabled = value\n syncDisabled()\n return @this\n\nAccordionItem:syncDisabled()\n @button.disabled = @disabled or @owner.disabled\n return null\n\nAccordionItem:setCaption(value)\n @button.textContent = value\n return @this\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { LongPoll } from "./longpoll.mjs";
2
2
  import {
3
3
  hostGlobal as __hostGlobal,
4
+ bindContexts as __bindContexts,
4
5
  isNumber as __isNumber,
5
6
  isString as __isString,
6
7
  isBool as __isBool,
@@ -43,10 +44,10 @@ export class Activities {
43
44
  }
44
45
  let record = { url: url, delay: delay, repeating: repeating, active: true, timer: null };
45
46
  registry[url] = record;
46
- let action = () => {
47
+ let action = __bindContexts(() => {
47
48
  this.fire(record, registry);
48
49
  return null;
49
- };
50
+ });
50
51
  record.timer = __normalize(this.#form.app.schedule(action, delay));
51
52
  return null;
52
53
  return null;
@@ -79,18 +80,18 @@ export class Activities {
79
80
  if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(record.active))) || __requireBoolean(__normalize(this.#form.disposed)))) {
80
81
  return null;
81
82
  }
82
- return __normalize(this.#form.app.send(__normalize(this.#form), __normalize(record.url), record)).catch(__withArity((error) => {
83
+ return __normalize(this.#form.app.send(__normalize(this.#form), __normalize(record.url), record)).catch(__withArity(__bindContexts((error) => {
83
84
  error = __boundary(error);
84
85
  if (__requireBoolean(__requireBoolean(__normalize(record.active)) && __requireBoolean(!__requireBoolean(__normalize(this.#form.disposed))))) {
85
86
  __normalize(this.#form.app.error(__normalize(this.#form), error, "TimerFailed"));
86
87
  }
87
88
  return null;
88
- }, [0], "closure")).finally(() => {
89
+ }), [0], "closure")).finally(__bindContexts(() => {
89
90
  if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(record.active)) && __requireBoolean(__normalize(record.repeating))) && __requireBoolean(!__requireBoolean(__normalize(this.#form.disposed))))) {
90
- let action = () => {
91
+ let action = __bindContexts(() => {
91
92
  this.fire(record, registry);
92
93
  return null;
93
- };
94
+ });
94
95
  record.timer = __normalize(this.#form.app.schedule(action, __normalize(record.delay)));
95
96
  } else {
96
97
  record.active = false;
@@ -99,7 +100,7 @@ export class Activities {
99
100
  }
100
101
  }
101
102
  return null;
102
- });
103
+ }));
103
104
  return null;
104
105
  }
105
106
  startLongPoll(url, key, cursor = null) {
@@ -1 +1 @@
1
- {"version":3,"file":"activities.mjs","sources":["activities.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global TextEncoder\nimport \"./longpoll\"\n class LongPoll\n\nexport class Activities(form)\n methods\n timer(url, delay, repeating = false)\n clearTimer(url, repeating = false)\n fire(record, registry)\n startLongPoll(url, key, cursor = null)\n stopLongPoll(url, key)\n forgetPoll(poll)\n pause()\n resume()\n clear()\n\nActivities(form)\n @form = form\n @timers = Object/create(null)\n @intervals = Object/create(null)\n @polls = []\n\nActivities:timer(url, delay, repeating = false)\n @form.app.checkUrl(url)\n if !is_number(delay) or delay <= 0 or delay > 2147483647\n throw \"Timer delay must be between 0 and 2147483647 milliseconds\"\n clearTimer(url, repeating)\n registry = @timers\n if repeating\n registry = @intervals\n record = {\n url: url\n delay: delay\n repeating: repeating\n active: true\n timer: null\n }\n registry[url] = record\n action = ()\n capture record\n capture registry\n fire(record, registry)\n record.timer = @form.app.schedule(action, delay)\n return null\n\nActivities:clearTimer(url, repeating = false)\n registry = @timers\n if repeating\n registry = @intervals\n record = registry[url]\n if record != null\n record.active = false\n if record.timer != null\n @form.app.cancelTimer(record.timer)\n record.timer = null\n Reflect/deleteProperty(registry, url)\n return null\n\nActivities:fire(record, registry)\n record.timer = null\n if !record.active or @form.disposed\n return null\n return chain @form.app.send(@form, record.url, record)\n catch(error)\n capture record\n if record.active and !@form.disposed\n @form.app.error(@form, error, \"TimerFailed\")\n finally\n capture record\n capture registry\n if record.active and record.repeating and !@form.disposed\n action = ()\n capture record\n capture registry\n fire(record, registry)\n record.timer = @form.app.schedule(action, record.delay)\n else\n record.active = false\n if registry[record.url] == record\n Reflect/deleteProperty(registry, record.url)\n\nActivities:startLongPoll(url, key, cursor = null)\n @form.app.checkUrl(url)\n if !is_string(key) or key == \"\"\n throw \"Longpoll requires a key\"\n encoder = new TextEncoder()\n if encoder.encode(key).length > 1024\n throw \"Longpoll key exceeds 1024 bytes\"\n if cursor != null and (!is_string(cursor) or cursor == \"\")\n throw \"Longpoll cursor must be a nonempty string or null\"\n for @polls.slice() as current\n if current.url == url and current.key == key\n if cursor == null and current.active and !current.recovering\n return null\n current.dispose()\n poll = new LongPoll(@form, url, key, cursor)\n @polls.add(poll)\n poll.resume()\n return null\n\nActivities:stopLongPoll(url, key)\n for @polls.slice() as poll\n if poll.url == url and poll.key == key\n poll.dispose()\n return null\n\nActivities:forgetPoll(poll)\n index = @polls.indexOf(poll)\n if index >= 0\n @polls.splice(index, 1)\n return null\n\nActivities:pause()\n for @polls.slice() as poll\n poll.pause()\n return null\n\nActivities:resume()\n for @polls.slice() as poll\n poll.resume()\n return null\n\nActivities:clear()\n for Object/keys(@timers) as url\n clearTimer(url)\n for Object/keys(@intervals) as url\n clearTimer(url, true)\n for @polls.slice() as poll\n poll.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"activities.mjs","sources":["activities.lango"],"sourcesContent":["import js global Object\nimport js global Reflect\nimport js global TextEncoder\nimport \"./longpoll\"\n class LongPoll\n\nexport class Activities(form)\n methods\n timer(url, delay, repeating = false)\n clearTimer(url, repeating = false)\n fire(record, registry)\n startLongPoll(url, key, cursor = null)\n stopLongPoll(url, key)\n forgetPoll(poll)\n pause()\n resume()\n clear()\n\nActivities(form)\n @form = form\n @timers = Object/create(null)\n @intervals = Object/create(null)\n @polls = []\n\nActivities:timer(url, delay, repeating = false)\n @form.app.checkUrl(url)\n if !is_number(delay) or delay <= 0 or delay > 2147483647\n throw \"Timer delay must be between 0 and 2147483647 milliseconds\"\n clearTimer(url, repeating)\n registry = @timers\n if repeating\n registry = @intervals\n record = {\n url: url\n delay: delay\n repeating: repeating\n active: true\n timer: null\n }\n registry[url] = record\n action = ()\n capture record\n capture registry\n fire(record, registry)\n record.timer = @form.app.schedule(action, delay)\n return null\n\nActivities:clearTimer(url, repeating = false)\n registry = @timers\n if repeating\n registry = @intervals\n record = registry[url]\n if record != null\n record.active = false\n if record.timer != null\n @form.app.cancelTimer(record.timer)\n record.timer = null\n Reflect/deleteProperty(registry, url)\n return null\n\nActivities:fire(record, registry)\n record.timer = null\n if !record.active or @form.disposed\n return null\n return chain @form.app.send(@form, record.url, record)\n catch(error)\n capture record\n if record.active and !@form.disposed\n @form.app.error(@form, error, \"TimerFailed\")\n finally\n capture record\n capture registry\n if record.active and record.repeating and !@form.disposed\n action = ()\n capture record\n capture registry\n fire(record, registry)\n record.timer = @form.app.schedule(action, record.delay)\n else\n record.active = false\n if registry[record.url] == record\n Reflect/deleteProperty(registry, record.url)\n\nActivities:startLongPoll(url, key, cursor = null)\n @form.app.checkUrl(url)\n if !is_string(key) or key == \"\"\n throw \"Longpoll requires a key\"\n encoder = new TextEncoder()\n if encoder.encode(key).length > 1024\n throw \"Longpoll key exceeds 1024 bytes\"\n if cursor != null and (!is_string(cursor) or cursor == \"\")\n throw \"Longpoll cursor must be a nonempty string or null\"\n for @polls.slice() as current\n if current.url == url and current.key == key\n if cursor == null and current.active and !current.recovering\n return null\n current.dispose()\n poll = new LongPoll(@form, url, key, cursor)\n @polls.add(poll)\n poll.resume()\n return null\n\nActivities:stopLongPoll(url, key)\n for @polls.slice() as poll\n if poll.url == url and poll.key == key\n poll.dispose()\n return null\n\nActivities:forgetPoll(poll)\n index = @polls.indexOf(poll)\n if index >= 0\n @polls.splice(index, 1)\n return null\n\nActivities:pause()\n for @polls.slice() as poll\n poll.pause()\n return null\n\nActivities:resume()\n for @polls.slice() as poll\n poll.resume()\n return null\n\nActivities:clear()\n for Object/keys(@timers) as url\n clearTimer(url)\n for Object/keys(@intervals) as url\n clearTimer(url, true)\n for @polls.slice() as poll\n poll.dispose()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}