@lango-project/lango-client 0.4.0 → 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 (77) hide show
  1. package/README.md +63 -4
  2. package/cli/.lango/runtime.mjs +24 -1
  3. package/cli/create.mjs +0 -0
  4. package/dist/.lango/runtime.mjs +24 -1
  5. package/dist/accordion.mjs +9 -8
  6. package/dist/accordion.mjs.map +1 -1
  7. package/dist/activities.mjs +8 -7
  8. package/dist/activities.mjs.map +1 -1
  9. package/dist/app.mjs +500 -50
  10. package/dist/app.mjs.map +1 -1
  11. package/dist/boot.mjs +3 -2
  12. package/dist/boot.mjs.map +1 -1
  13. package/dist/button.mjs +8 -7
  14. package/dist/button.mjs.map +1 -1
  15. package/dist/chip.mjs +5 -4
  16. package/dist/chip.mjs.map +1 -1
  17. package/dist/client.css +7 -0
  18. package/dist/combo_box.mjs +15 -14
  19. package/dist/combo_box.mjs.map +1 -1
  20. package/dist/content.mjs +9 -8
  21. package/dist/content.mjs.map +1 -1
  22. package/dist/control.mjs +2 -0
  23. package/dist/control.mjs.map +1 -1
  24. package/dist/date_input.mjs +3 -2
  25. package/dist/date_input.mjs.map +1 -1
  26. package/dist/dimensions.mjs +102 -0
  27. package/dist/dimensions.mjs.map +1 -0
  28. package/dist/error_reporter.mjs +6 -5
  29. package/dist/error_reporter.mjs.map +1 -1
  30. package/dist/fields.mjs +9 -8
  31. package/dist/fields.mjs.map +1 -1
  32. package/dist/file_input.mjs +19 -18
  33. package/dist/file_input.mjs.map +1 -1
  34. package/dist/form.mjs +15 -3
  35. package/dist/form.mjs.map +1 -1
  36. package/dist/heartbeat.mjs +12 -11
  37. package/dist/heartbeat.mjs.map +1 -1
  38. package/dist/index.html +1 -1
  39. package/dist/input_changes.mjs +5 -4
  40. package/dist/input_changes.mjs.map +1 -1
  41. package/dist/longpoll.mjs +12 -11
  42. package/dist/longpoll.mjs.map +1 -1
  43. package/dist/main.mjs +45 -19
  44. package/dist/main.mjs.map +1 -1
  45. package/dist/menus.mjs +19 -18
  46. package/dist/menus.mjs.map +1 -1
  47. package/dist/navigation.mjs +7 -6
  48. package/dist/navigation.mjs.map +1 -1
  49. package/dist/numeric_input.mjs +9 -8
  50. package/dist/numeric_input.mjs.map +1 -1
  51. package/dist/otp_input.mjs +5 -4
  52. package/dist/otp_input.mjs.map +1 -1
  53. package/dist/presentations.mjs +17 -16
  54. package/dist/presentations.mjs.map +1 -1
  55. package/dist/renderer.mjs +88 -12
  56. package/dist/renderer.mjs.map +1 -1
  57. package/dist/table_scope.mjs +167 -0
  58. package/dist/table_scope.mjs.map +1 -0
  59. package/dist/tables.mjs +809 -125
  60. package/dist/tables.mjs.map +1 -1
  61. package/dist/tabs.mjs +7 -6
  62. package/dist/tabs.mjs.map +1 -1
  63. package/dist/widgets.mjs +5 -4
  64. package/dist/widgets.mjs.map +1 -1
  65. package/docs/implementation.md +51 -0
  66. package/package.json +4 -3
  67. package/src/app.lango +358 -12
  68. package/src/control.lango +3 -0
  69. package/src/dimensions.lango +65 -0
  70. package/src/form.lango +13 -3
  71. package/src/heartbeat.lango +2 -2
  72. package/src/main.lango +24 -0
  73. package/src/renderer.lango +78 -9
  74. package/src/table_scope.lango +119 -0
  75. package/src/tables.lango +620 -105
  76. package/web/client.css +7 -0
  77. package/web/index.html +1 -1
package/README.md CHANGED
@@ -305,14 +305,15 @@ control definitions or arrays of definitions. Image accepts an HTTP(S) or image
305
305
  data URL, or base64 `content` with an image `mimeType` (default `image/png`).
306
306
 
307
307
  Cards, tables, tabs and navigation do not introduce implicit Form scopes.
308
- Controls inside them belong to the containing Form; explicit nested Forms keep
309
- their independent values and tokens. Named non-field controls contribute null.
308
+ Controls inside them send through the containing Form; explicit nested Forms keep
309
+ their independent values and tokens. Tables use local cell scopes and their
310
+ valueMode controls collection; ordinary named non-field controls contribute null.
310
311
 
311
312
  Tables consume `tableCol`, one optional `tableHeader`, `tableRow`, `tableCell`
312
313
  and `tableDivider` definitions. Header rows contain native column headings.
313
314
  `rowSpan` and `colSpan` are Cell properties; spans must be integers from 1 to
314
- 1000. Column `colSpan` uses the native column span. Numeric column widths are
315
- pixels; strings are CSS widths. Resizable columns support pointer dragging and
315
+ 1000. Column `colSpan` uses the native column span. Positive numeric column widths use character units (`ch`); -1 selects automatic
316
+ width. Resizable columns support pointer dragging and
316
317
  Left/Right keys in 10-pixel steps, with a minimum width of 24 pixels per column.
317
318
  A resizable column must end at a first-row cell boundary. Row/Cell `url` sends
318
319
  the owning Form with its current token. Inner buttons, links and fields do not
@@ -592,3 +593,61 @@ values use DOM properties. Markdown uses its separate sanitization path.
592
593
  - Query/hash history policy and additional platforms remain open. The delivery
593
594
  generator currently targets same-origin Web/Bootstrap; deep-link static hosting
594
595
  and a packed generated-application browser test are implemented.
596
+
597
+
598
+ ## Table data and row commands
599
+
600
+ Tables support `valueMode` (`none`, `cells`, `rows`, `mixed`), an optional
601
+ `tableRowTemplate` definition in `rowTemplate`, and an initial `value` array.
602
+ `values` assignments to a table replace every body row, preserving its columns,
603
+ header and configuration. Null and [] clear the body. Row maps bind to column
604
+ names; missing fields render empty. Without a template, cells show safe text
605
+ (including JSON text for structured values) and contribute null when collected.
606
+
607
+ Template cells map to columns by position. One control receives/returns a direct
608
+ value; multiple named controls receive/return a map. Each cell has a local control
609
+ scope, so repeated template field names are independent. Rows do not create
610
+ Forms or tokens. Explicit nested Forms and asynchronous File fields remain
611
+ supported. Metadata (`tableRow.data`, `setRowData`) stays out of DOM and form
612
+ values. It is client-side data and must not contain server secrets.
613
+
614
+ A named table scopes targets as `table/cell/control`. Static unnamed cells expose
615
+ their named controls in the table scope; unnamed tables expose static cell names
616
+ in their containing scope. Generated rows keep unnamed-cell controls local.
617
+ Duplicate exposed names fail, including fixed named template cells repeated
618
+ across rows. Failed row replacement leaves previous rows and names usable.
619
+ Removed/replaced rows dispose their controls, nested Forms and listeners.
620
+
621
+ The dispatcher accepts `addRow`, `insertRow`, `deleteRow`, `setRowValue`,
622
+ `setRowData`, and `setCellValue`. All use `name` as the table target. Insert uses
623
+ `beforeIndex`; other indexed commands use `index`. Cell assignment adds `column`
624
+ (a name or definition index). Values use `value`. Indices are zero based;
625
+ insertion at the row count appends. Full `values` commands retain their final
626
+ position after incremental commands. See the Lango UI package
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.
@@ -100,6 +100,9 @@ function postgresQuery(sql, parameters) {
100
100
  return { text: text + sql.slice(at), values };
101
101
  }
102
102
  export const DB = Object.freeze({ Active: "active", RollbackOnly: "rollback_only", Failed: "failed" });
103
+ const loggingStore = Symbol.for("lango.logging");
104
+ const logging = globalThis[loggingStore] ?? { verbose: false };
105
+ globalThis[loggingStore] = logging;
103
106
  const contextStore = Symbol.for("lango.contexts");
104
107
  const contexts = globalThis[contextStore] ?? new Map();
105
108
  globalThis[contextStore] = contexts;
@@ -114,6 +117,8 @@ export class RuntimeConfigurationError extends Error {
114
117
  export function configure(options = {}) {
115
118
  if (options === null || typeof options !== "object" || Array.isArray(options))
116
119
  throw new RuntimeConfigurationError("runtime configuration must be an object");
120
+ if (options.verbose !== undefined && typeof options.verbose !== "boolean")
121
+ throw new RuntimeConfigurationError("runtime verbose must be boolean");
117
122
  const nextCatalog = options.catalog ?? {};
118
123
  const nextOutput = options.output ?? null;
119
124
  const nextDatabase = options.database_adapter ?? null;
@@ -135,6 +140,7 @@ export function configure(options = {}) {
135
140
  } catch (error) {
136
141
  throw new RuntimeConfigurationError(error.message);
137
142
  }
143
+ if (options.verbose !== undefined) logging.verbose = options.verbose;
138
144
  defaultI18n = nextI18n;
139
145
  output = nextOutput;
140
146
  if (database !== null) failedTransactions.delete(database);
@@ -341,7 +347,8 @@ export function println(value) {
341
347
  }
342
348
 
343
349
  const defaultLog = Object.freeze({
344
- debug(value) { return writeLog(process.stdout, "DEBUG", value); },
350
+ get verbose() { return logging.verbose || process.env.LANGO_VERBOSE === "1"; },
351
+ debug(value) { if (!defaultLog.verbose) return null; return writeLog(process.stdout, "DEBUG", value); },
345
352
  info(value) { return writeLog(process.stdout, "INFO", value); },
346
353
  warn(value) { return writeLog(process.stderr, "WARN", value); },
347
354
  err(value) { return writeLog(process.stderr, "ERROR", value); },
@@ -675,6 +682,22 @@ export function withArity(callback, requiredPositions, name) {
675
682
  };
676
683
  }
677
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
+
678
701
  export function contextGet(name) {
679
702
  const stack = contexts.get(name);
680
703
  if ((!stack || stack.length === 0) && name === "log") return defaultLog;
package/cli/create.mjs CHANGED
File without changes
@@ -98,6 +98,9 @@ function postgresQuery(sql, parameters) {
98
98
  return { text: text + sql.slice(at), values };
99
99
  }
100
100
  export const DB = Object.freeze({ Active: "active", RollbackOnly: "rollback_only", Failed: "failed" });
101
+ const loggingStore = Symbol.for("lango.logging");
102
+ const logging = globalThis[loggingStore] ?? { verbose: false };
103
+ globalThis[loggingStore] = logging;
101
104
  const contextStore = Symbol.for("lango.contexts");
102
105
  const contexts = globalThis[contextStore] ?? new Map();
103
106
  globalThis[contextStore] = contexts;
@@ -112,6 +115,8 @@ export class RuntimeConfigurationError extends Error {
112
115
  export function configure(options = {}) {
113
116
  if (options === null || typeof options !== "object" || Array.isArray(options))
114
117
  throw new RuntimeConfigurationError("runtime configuration must be an object");
118
+ if (options.verbose !== undefined && typeof options.verbose !== "boolean")
119
+ throw new RuntimeConfigurationError("runtime verbose must be boolean");
115
120
  const nextCatalog = options.catalog ?? {};
116
121
  const nextOutput = options.output ?? null;
117
122
  const nextDatabase = options.database_adapter ?? null;
@@ -133,6 +138,7 @@ export function configure(options = {}) {
133
138
  } catch (error) {
134
139
  throw new RuntimeConfigurationError(error.message);
135
140
  }
141
+ if (options.verbose !== undefined) logging.verbose = options.verbose;
136
142
  defaultI18n = nextI18n;
137
143
  output = nextOutput;
138
144
  if (database !== null) failedTransactions.delete(database);
@@ -339,7 +345,8 @@ export function println(value) {
339
345
  }
340
346
 
341
347
  const defaultLog = Object.freeze({
342
- debug(value) { console.debug(String(value)); return null; },
348
+ get verbose() { return logging.verbose || false; },
349
+ debug(value) { if (!defaultLog.verbose) return null; console.debug(String(value)); return null; },
343
350
  info(value) { console.info(String(value)); return null; },
344
351
  warn(value) { console.warn(String(value)); return null; },
345
352
  err(value) { console.error(String(value)); return null; },
@@ -673,6 +680,22 @@ export function withArity(callback, requiredPositions, name) {
673
680
  };
674
681
  }
675
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
+
676
699
  export function contextGet(name) {
677
700
  const stack = contexts.get(name);
678
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}