@lango-project/lango-client 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -782,11 +782,11 @@ versions; there is no automatic downgrade or feature negotiation.
782
782
 
783
783
  ## Create a complete API/UI application
784
784
 
785
- The release set for this starter is `lango-js` 0.1.10 and `lango-api`, `lango-ui`,
786
- `lango-client` 0.2.0. Once those package versions are published:
785
+ The updated starter release set is `lango-js` 0.1.11, `lango-client` 0.2.1,
786
+ and `lango-api`/`lango-ui` 0.2.0. Once the patch versions are published:
787
787
 
788
788
  ```sh
789
- npx --package @lango-project/lango-client@0.2.0 lango-create-app my-app
789
+ npx --package @lango-project/lango-client@0.2.1 lango-create-app my-app
790
790
  cd my-app
791
791
  npm install
792
792
  npm test
@@ -833,6 +833,58 @@ The API's separate telemetry quota still applies. Rejections return
833
833
  429/Retry-After and close the connection. Counts are bounded, process-local and
834
834
  reset on restart; a distributed ingress policy remains separate.
835
835
 
836
+ ## Labels, errors and keyboard focus
837
+
838
+ Built-in Text, Select and Checkbox controls with a `label` render a visible,
839
+ implicitly associated HTML label as well as their accessible name. Inline errors
840
+ are visible text connected through `aria-describedby`; required fields expose
841
+ `aria-required`. Hiding or replacing a control includes its label and error text,
842
+ and structural rollback restores the complete wrapper.
843
+
844
+ `control.element` remains the native input/select for value access and focus.
845
+ `control.node` is its structural DOM root (the label wrapper for labeled fields,
846
+ otherwise the element itself). Custom renderers should replace/remove/capture
847
+ node and focus element. Native input classes/styles remain on element; style
848
+ `.lango-field`, `.lango-caption` and `.lango-field-error` for the surrounding UI.
849
+ Label content uses textContent, including when supplied text contains markup.
850
+
851
+ A queued request temporarily makes its form inert. When work finishes, the
852
+ previous focus is restored if the element is still attached and enabled and the
853
+ user has not focused something elsewhere. Removed/disabled/hidden targets are
854
+ not focused. Server field errors and client validation then focus/report the
855
+ invalid input using the existing native validity behavior.
856
+
857
+ ## Chromium and accessibility checks
858
+
859
+ Browser checks are Lango programs using Playwright and axe. They are separate
860
+ from `npm test`, so ordinary tests do not require a browser download:
861
+
862
+ ```sh
863
+ npm install
864
+ npm run browser:install
865
+ npm run build
866
+ npm run build:demo-server
867
+ npm run test:browser
868
+ ```
869
+
870
+ Build the sibling API/UI projects before running the demo server. To test a
871
+ built starter instead, run `npm run test:browser -- /absolute/app/path starter`.
872
+ The runner stores its browser and download scratch files in ignored
873
+ `.test-output/` (also on Windows). The fixture uses ports 8080/8081 and shuts
874
+ down after success/failure. Screenshots and complete axe results are written to
875
+ `.test-output/browser-demo/` and `.test-output/browser-starter/`; failures also
876
+ include page errors, console/server output, DOM and a screenshot. Fixture content
877
+ is synthetic; do not point these artifact-producing checks at personal data.
878
+
879
+ The starter check covers real startup, visible labels, Tab/Enter, validation
880
+ without a request, canonical save, focus restoration, reload and a 390px viewport.
881
+ The demo check covers contact saving, checkbox label activation, dirty-navigation
882
+ cancellation, server field errors, Back/Forward and reload. Axe scans the tested
883
+ screens without suppressing rules. Chromium coverage does not establish full
884
+ accessibility compliance or cross-browser support; screen-reader/manual checks
885
+ and Firefox/WebKit coverage remain separate. See the
886
+ [Playwright accessibility guide](https://playwright.dev/docs/accessibility-testing).
887
+
836
888
  ## Private error reports
837
889
 
838
890
  The optional `./errors` entry exports `ErrorReporter(options)`. Supply `window`
package/dist/library.mjs CHANGED
@@ -4,6 +4,7 @@ import { classNames, styleMap, validateProperty } from "./presentation.mjs";
4
4
  import { selectItems, selectIndex } from "./input_values.mjs";
5
5
  import { rulesFor, validationMessage, sameValue } from "./form_state.mjs";
6
6
  import {
7
+ hostGlobal as __hostGlobal,
7
8
  contextGet as __contextGet,
8
9
  contextSet as __contextSet,
9
10
  contextRestore as __contextRestore,
@@ -239,22 +240,22 @@ export class Renderer {
239
240
  __requireArity(arguments.length, [0, 1], "replace");
240
241
  old = __boundary(old);
241
242
  replacement = __boundary(replacement);
242
- let element = __normalize(old.element);
243
- __normalize(element.parentNode.replaceChild(__normalize(replacement.element), element));
243
+ let element = __normalize(old.node);
244
+ __normalize(element.parentNode.replaceChild(__normalize(replacement.node), element));
244
245
  return null;
245
246
  return null;
246
247
  }
247
248
  remove(control) {
248
249
  __requireArity(arguments.length, [0], "remove");
249
250
  control = __boundary(control);
250
- __remove(control.element);
251
+ __remove(control.node);
251
252
  return null;
252
253
  return null;
253
254
  }
254
255
  capture(control) {
255
256
  __requireArity(arguments.length, [0], "capture");
256
257
  control = __boundary(control);
257
- let element = __normalize(control.element);
258
+ let element = __normalize(control.node);
258
259
  return { element: element, parent: __normalize(element.parentNode), next: __normalize(element.nextSibling) };
259
260
  return null;
260
261
  }
@@ -264,7 +265,7 @@ export class Renderer {
264
265
  operation = __boundary(operation);
265
266
  if (__requireBoolean(__normalize(operation.type) === "replace")) {
266
267
  let replacement = __normalize(operation.new);
267
- __remove(replacement.element);
268
+ __remove(replacement.node);
268
269
  }
269
270
  if (__requireBoolean(__normalize(snapshot.parent) !== null)) {
270
271
  __normalize(snapshot.parent.insertBefore(__normalize(snapshot.element), __normalize(snapshot.next)));
@@ -295,6 +296,7 @@ export class Renderer {
295
296
  export class Control {
296
297
  name;
297
298
  element;
299
+ node;
298
300
  controls;
299
301
  events;
300
302
  inherit;
@@ -310,6 +312,7 @@ export class Control {
310
312
  #items;
311
313
  #classes;
312
314
  #style;
315
+ #errorElement;
313
316
  constructor(document, definition, types = null, options = null) {
314
317
  __requireArity(arguments.length, [0, 1], "constructor");
315
318
  document = __boundary(document);
@@ -380,6 +383,8 @@ export class Control {
380
383
  throw "UiClientUnknownControlType";
381
384
  }
382
385
  this.element = __normalize(document.createElement(tag));
386
+ this.node = __normalize(this.element);
387
+ this.#errorElement = null;
383
388
  let element = __normalize(this.element);
384
389
  if (__requireBoolean(__normalize(this.#type) === "Form")) {
385
390
  element.langoFormRoot = true;
@@ -399,6 +404,25 @@ export class Control {
399
404
  throw "UiControlLabelMustBeString";
400
405
  }
401
406
  __normalize(element.setAttribute("aria-label", __normalize(definition.label)));
407
+ if (__requireBoolean(__requireBoolean(tag === "input") || __requireBoolean(tag === "select"))) {
408
+ this.node = __normalize(document.createElement("label"));
409
+ this.node.className = "lango-field";
410
+ __normalize(this.node.setAttribute("data-lango-control", __normalize(this.#type)));
411
+ let caption = __normalize(document.createElement("span"));
412
+ caption.className = "lango-caption";
413
+ caption.textContent = __normalize(definition.label);
414
+ __normalize(this.node.appendChild(caption));
415
+ __normalize(this.node.appendChild(element));
416
+ this.#errorElement = __normalize(document.createElement("span"));
417
+ this.#errorElement.className = "lango-field-error";
418
+ this.#errorElement.id = `lango-error-${__normalize(__hostGlobal(["crypto"]).randomUUID())}`;
419
+ this.#errorElement.hidden = true;
420
+ __normalize(element.setAttribute("aria-describedby", __normalize(this.#errorElement.id)));
421
+ __normalize(this.node.appendChild(__normalize(this.#errorElement)));
422
+ }
423
+ }
424
+ if (__requireBoolean(__requireBoolean(tag === "input") || __requireBoolean(tag === "select"))) {
425
+ __normalize(element.setAttribute("aria-required", `${__normalize(this.#rules.required) === true}`));
402
426
  }
403
427
  let container = __requireBoolean(__requireBoolean(__normalize(this.#type) === "Panel") || __requireBoolean(__normalize(this.#type) === "Container")) || __requireBoolean(__normalize(this.#type) === "Form");
404
428
  if (__requireBoolean(__requireBoolean(options !== null) && __requireBoolean(__normalize(options.container) === true))) {
@@ -421,7 +445,7 @@ export class Control {
421
445
  for (const childDefinition of __normalize(definition.controls)) {
422
446
  let child = __normalize(registry.create(document, childDefinition));
423
447
  this.controls.push(child);
424
- __normalize(element.appendChild(__normalize(child.element)));
448
+ __normalize(element.appendChild(__normalize(child.node)));
425
449
  }
426
450
  }
427
451
  if (__requireBoolean(__normalize(definition.classes) !== null)) {
@@ -546,6 +570,10 @@ export class Control {
546
570
  }
547
571
  __normalize(this.element.setAttribute("aria-invalid", `${__normalize(this.#error) !== null}`));
548
572
  __normalize(this.element.setAttribute("data-lango-error", text));
573
+ if (__requireBoolean(__normalize(this.#errorElement) !== null)) {
574
+ this.#errorElement.textContent = text;
575
+ this.#errorElement.hidden = __normalize(this.#error) === null;
576
+ }
549
577
  if (__requireBoolean(__normalize(this.element.setCustomValidity) !== null)) {
550
578
  __normalize(this.element.setCustomValidity(text));
551
579
  }
@@ -583,8 +611,10 @@ export class Control {
583
611
  if (name === "enabled") {
584
612
  this.element.disabled = !__requireBoolean(value);
585
613
  this.element.inert = !__requireBoolean(value);
614
+ this.node.inert = !__requireBoolean(value);
586
615
  } else if (name === "visible") {
587
616
  this.element.hidden = __requireBoolean(!__requireBoolean(value)) || __requireBoolean(__normalize(this.#type) === "Value");
617
+ this.node.hidden = __normalize(this.element.hidden);
588
618
  } else if (name === "classes") {
589
619
  this.#classes = classNames(value);
590
620
  this.element.className = __normalize(this.#classes.join(" "));
@@ -628,6 +658,8 @@ export class Control {
628
658
  this.element.disabled = __normalize(snapshot.disabled);
629
659
  this.element.hidden = __normalize(snapshot.hidden);
630
660
  this.element.inert = __normalize(snapshot.inert);
661
+ this.node.hidden = __normalize(snapshot.hidden);
662
+ this.node.inert = __normalize(snapshot.inert);
631
663
  this.element.className = __normalize(snapshot.classes);
632
664
  this.element.style.cssText = __normalize(snapshot.style);
633
665
  this.#style = __normalize(snapshot.managedStyle);
@@ -785,7 +817,7 @@ export function mount(document, root, definition, types = null) {
785
817
  types = new Types();
786
818
  }
787
819
  let control = __normalize(types.create(document, definition));
788
- __normalize(root.appendChild(__normalize(control.element)));
820
+ __normalize(root.appendChild(__normalize(control.node)));
789
821
  return control;
790
822
  return null;
791
823
  }
@@ -1 +1 @@
1
- {"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import \"./protocol\"\n collectValues(controls)\n applyResponse(controls, response, formId, seqno, effects)\nimport \"./inheritance\"\n normalizeInheritance(spec)\nimport \"./presentation\"\n classNames(value)\n styleMap(value)\n validateProperty(name, value)\nimport \"./input_values\"\n selectItems(options)\n selectIndex(items, value)\nimport \"./form_state\"\n rulesFor(value)\n validationMessage(rules, value)\n sameValue(left, right)\n\nexport mount(document, root, definition, types = null)\n\nexport class Types\n methods\n registerType(name, type)\n create(document, definition)\n\nTypes(options = null)\n if options != null and (!is_object(options) or is_array(options))\n throw \"UiControlRegistryOptionsMustBeMap\"\n @types = {\n }\n @classes = {\n }\n @sealed = false\n if options != null and options.classes != null\n if !is_object(options.classes) or is_array(options.classes)\n throw \"UiThemeClassesMustBeMap\"\n for options.classes as name: classes\n @classes[name] = classNames(classes)\n\nTypes:registerType(name, type)\n if @sealed\n throw \"UiControlRegistrySealed\"\n if !is_string(name) or name == \"\" or name == \"__proto__\" or name == \"prototype\" or name == \"constructor\" or !is_kindof(type, Function)\n throw \"UiControlTypeRequiresNameAndConstructor\"\n if name in @types\n throw \"UiDuplicateControlType: ${name}\"\n @types[name] = type\n return @this\n\nTypes:create(document, definition)\n @sealed = true\n if !is_object(definition) or !is_string(definition.type)\n throw \"UiControlRequiresDefinition\"\n prepared = {\n }\n for definition as name: value\n prepared[name] = value\n defaults = @classes[definition.type]\n if defaults != null\n prepared.classes = classNames(defaults.concat(classNames(definition.classes)))\n type = Control\n if definition.type in @types\n type = @types[definition.type]\n control = new type(document, prepared, @this)\n if !is_kindof(control, Control)\n throw \"UiCustomControlMustExtendControl\"\n return control\n\nexport class Binding\n methods\n handle(event)\n report(error)\n dispose()\n\nBinding(form, session, errors = null)\n @form = form\n @session = session\n @errors = errors\n @disposed = false\n root = form.element\n if root.langoBinding != null\n throw \"UiFormAlreadyBound\"\n listener = (event)\n handle(event)\n @listener = listener\n for [\"click\", \"change\", \"input\"] as type\n root.addEventListener(type, listener)\n root.langoBinding = @this\n\nBinding:handle(event)\n if @disposed\n return null\n root = @form.element\n element = event.target\n target = null\n current = element\n loop while current != null\n if current.inert == true or current.disabled == true or current.hidden == true\n return null\n if current == root\n break\n if current.langoFormRoot == true\n return null\n if target == null\n target = eventTarget(@form.controls, current, [], event.type)\n current = current.parentNode\n if current != root\n return null\n if event.type == \"input\" or event.type == \"change\"\n validateEvent(@form.controls, event.target, root)\n if target == null\n return null\n try\n event.preventDefault()\n if @errors != null and @errors.clear != null\n @errors.clear()\n session = @session\n return session.send(target.url, event.type, target.name).catch((error)\n report(error)\n )\n catch error\n report(error)\n return null\n\nvalidateEvent(controls, element, root)\n current = element\n loop while current != null and current != root\n control = elementControl(controls, current)\n if control != null and control.validate != null\n control.validate()\n return null\n current = current.parentNode\n return null\n\nelementControl(controls, element)\n for controls as control\n if control.element.langoFormRoot == true\n continue\n if control.element == element\n return control\n if is_array(control.controls)\n found = elementControl(control.controls, element)\n if found != null\n return found\n return null\n\nBinding:report(error)\n if @disposed\n return null\n if @errors != null\n @errors.error(error)\n else\n context log\n log.err(error)\n return null\n\nBinding:dispose()\n if @disposed\n return null\n @disposed = true\n root = @form.element\n for [\"click\", \"change\", \"input\"] as type\n root.removeEventListener(type, @listener)\n root.langoBinding = null\n return null\n\neventTarget(controls, element, parentPath, type)\n for controls as control\n path = parentPath.slice()\n if control.name != null and control.name != \"\"\n path[path.length] = control.name\n if control.element == element\n events = control.events\n if type in events\n name = path\n if path.length == 1\n name = path[0]\n if path.length == 0\n name = null\n return {\n url: events[type]\n name: name\n }\n if is_array(control.controls)\n target = eventTarget(control.controls, element, path, type)\n if target != null\n return target\n return null\n\ncontrolEvents(definition)\n events = {\n }\n if definition.event != null\n type = \"change\"\n if definition.type == \"Button\"\n type = \"click\"\n events[type] = definition.event\n if definition.events != null\n if not is_object(definition.events)\n throw \"UiClientEventsMustBeMap\"\n for definition.events as type: url\n if type != \"click\" and type != \"change\" and type != \"input\"\n throw \"UiClientUnsupportedEventType\"\n events[type] = url\n for events as type: url\n if !is_string(url) or !url.startsWith(\"/\") or url.startsWith(\"//\") or url.includes(\"\\\\\")\n throw \"UiClientEventRequiresSameOriginPath\"\n return events\n\nexport class Renderer\n methods\n create(definition)\n replace(old, replacement)\n remove(control)\n capture(control)\n restore(snapshot, operation)\n focus(control)\n toast(level, text)\n release(control)\n\nRenderer(document, types = null)\n @document = document\n @types = types\n if @types == null\n @types = new Types()\n\nRenderer:create(definition)\n return @types.create(@document, definition)\n\nRenderer:release(control)\n releaseControl(control)\n return null\n\nreleaseControl(control)\n if is_array(control.controls)\n for control.controls as child\n releaseControl(child)\n try\n if control.dispose != null\n control.dispose()\n catch error\n context log\n log.err(\"Control disposal failed: ${error}\")\n return null\n\nRenderer:replace(old, replacement)\n element = old.element\n element.parentNode.replaceChild(replacement.element, element)\n return null\n\nRenderer:remove(control)\n control.element.remove()\n return null\n\nRenderer:capture(control)\n element = control.element\n return {\n element: element\n parent: element.parentNode\n next: element.nextSibling\n }\n\nRenderer:restore(snapshot, operation)\n if operation.type == \"replace\"\n replacement = operation.new\n replacement.element.remove()\n if snapshot.parent != null\n snapshot.parent.insertBefore(snapshot.element, snapshot.next)\n return null\n\nRenderer:focus(control)\n control.element.focus()\n return null\n\nRenderer:toast(level, text)\n element = @document.createElement(\"div\")\n element.setAttribute(\"role\", \"status\")\n element.textContent = text\n @document.body.appendChild(element)\n return null\n\nexport class Control\n properties\n name\n element\n controls\n events\n inherit\n validates\n confirms\n methods\n getValue()\n setValue(value)\n applyProperty(name, value)\n snapshotState()\n restoreState(snapshot)\n dispose()\n isDirty()\n markClean()\n acceptSaved(value)\n validate()\n reportValidity()\n reportPendingError()\n\nControl(document, definition, types = null, options = null)\n @name = definition.name\n @type = definition.type\n @controls = null\n @value = definition.value\n @clean = null\n @error = null\n @pendingError = false\n @rules = rulesFor(definition.validation)\n @tracked = definition.trackChanges\n if @tracked == null\n @tracked = @type == \"Text\" or @type == \"Select\" or @type == \"Checkbox\"\n if !is_bool(@tracked)\n throw \"UiTrackChangesMustBeBoolean\"\n @validates = definition.validate\n if @validates == null\n @validates = false\n if !is_bool(@validates)\n throw \"UiValidateEventMustBeBoolean\"\n @confirms = definition.confirmDirty\n if @confirms == null\n @confirms = false\n if !is_bool(@confirms)\n throw \"UiConfirmDirtyMustBeBoolean\"\n @items = []\n if @type == \"Select\"\n @items = selectItems(definition.options)\n @events = controlEvents(definition)\n @inherit = normalizeInheritance(definition.inherit)\n @classes = classNames(definition.classes)\n @style = styleMap(definition.style)\n registry = types\n if registry == null\n registry = new Types()\n if definition.inherit != null and @type != \"Form\"\n throw \"UiInheritanceRequiresForm\"\n tag = \"div\"\n if @type == \"Text\" or @type == \"Checkbox\"\n tag = \"input\"\n if @type == \"Select\"\n tag = \"select\"\n if @type == \"Button\"\n tag = \"button\"\n if options != null\n tag = options.tag\n if !is_string(tag) or tag == \"\"\n throw \"UiCustomControlRequiresTag\"\n if options == null and @type != \"Text\" and @type != \"Button\" and @type != \"Value\" and @type != \"Panel\" and @type != \"Container\" and @type != \"Form\" and @type != \"Select\" and @type != \"Checkbox\"\n throw \"UiClientUnknownControlType\"\n @element = document.createElement(tag)\n element = @element\n if @type == \"Form\"\n element.langoFormRoot = true\n if @type == \"Button\"\n element.type = \"button\"\n element.textContent = definition.text\n if @type == \"Value\"\n element.hidden = true\n if @type == \"Checkbox\"\n element.type = \"checkbox\"\n if definition.label != null\n if !is_string(definition.label)\n throw \"UiControlLabelMustBeString\"\n element.setAttribute(\"aria-label\", definition.label)\n container = @type == \"Panel\" or @type == \"Container\" or @type == \"Form\"\n if options != null and options.container == true\n container = true\n if container\n @controls = []\n try\n if @type == \"Select\"\n for @items as item\n option = document.createElement(\"option\")\n option.value = item.value\n option.textContent = item.text\n option.disabled = item.disabled\n element.appendChild(option)\n if container and is_array(definition.controls)\n for definition.controls as childDefinition\n child = registry.create(document, childDefinition)\n @controls.add(child)\n element.appendChild(child.element)\n if definition.classes != null\n applyProperty(\"classes\", definition.classes)\n if definition.style != null\n applyProperty(\"style\", definition.style)\n if definition.enabled != null\n applyProperty(\"enabled\", definition.enabled)\n if definition.visible != null\n applyProperty(\"visible\", definition.visible)\n initial = definition.value\n if @type == \"Checkbox\" and initial == null\n initial = false\n setValue(initial)\n markClean()\n catch error\n if is_array(@controls)\n for @controls as child\n releaseControl(child)\n throw error\n\nControl:getValue()\n if is_array(@controls)\n return collectValues(@controls)\n switch @type\n case \"Text\"\n return @element.value\n case \"Checkbox\"\n return @element.checked\n case \"Select\"\n index = @element.selectedIndex\n if index < 0 or index >= @items.length\n return null\n return @items[index].value\n else\n return @value\n\nControl:setValue(value)\n switch @type\n case \"Text\"\n text = value\n if value == null\n text = \"\"\n @element.value = text\n case \"Checkbox\"\n if !is_bool(value)\n throw \"UiCheckboxValueMustBeBoolean\"\n @element.checked = value\n case \"Select\"\n @element.selectedIndex = selectIndex(@items, value)\n @value = value\n if @error != null\n validate()\n return null\n\nControl:isDirty()\n if is_array(@controls)\n for @controls as child\n if child.isDirty != null\n if child.isDirty()\n return true\n return false\n if !@tracked\n return false\n current = from_json(to_json(getValue()))\n return !sameValue(current, @clean)\n\nControl:markClean()\n if is_array(@controls)\n for @controls as child\n if child.markClean != null\n child.markClean()\n else\n acceptSaved(getValue())\n return null\n\nControl:acceptSaved(value)\n @clean = from_json(to_json(value))\n return null\n\nControl:validate()\n @pendingError = false\n @error = validationMessage(@rules, getValue())\n renderError()\n return @error\n\nControl:renderError()\n text = @error\n if text == null\n text = \"\"\n @element.setAttribute(\"aria-invalid\", \"${@error != null}\")\n @element.setAttribute(\"data-lango-error\", text)\n if @element.setCustomValidity != null\n @element.setCustomValidity(text)\n return null\n\nControl:reportValidity()\n if @element.reportValidity != null\n return @element.reportValidity()\n return @error == null\n\nControl:reportPendingError()\n if !@pendingError\n return false\n current = @element\n loop while current != null\n if current.disabled == true or current.hidden == true or current.inert == true\n return false\n current = current.parentNode\n @pendingError = false\n reportValidity()\n return true\n\nControl:applyProperty(name, value)\n validateProperty(name, value)\n switch name\n case \"enabled\"\n @element.disabled = !value\n @element.inert = !value\n case \"visible\"\n @element.hidden = !value or @type == \"Value\"\n case \"classes\"\n @classes = classNames(value)\n @element.className = @classes.join(\" \")\n case \"style\"\n styles = styleMap(value)\n for @style as property: text\n @element.style.removeProperty(property)\n for styles as property: text\n @element.style.setProperty(property, text)\n @style = styles\n case \"savedValue\"\n acceptSaved(value)\n case \"error\"\n @error = value\n @pendingError = value != null\n renderError()\n reportPendingError()\n return null\n\nControl:snapshotState()\n return {\n value: @value\n text: @element.value\n checked: @element.checked\n selectedIndex: @element.selectedIndex\n disabled: @element.disabled\n hidden: @element.hidden\n inert: @element.inert\n classes: @element.className\n style: @element.style.cssText\n managedStyle: @style\n managedClasses: @classes\n clean: @clean\n error: @error\n pendingError: @pendingError\n }\n\nControl:restoreState(snapshot)\n setValue(snapshot.value)\n if @type == \"Text\"\n @element.value = snapshot.text\n if @type == \"Checkbox\"\n @element.checked = snapshot.checked\n if @type == \"Select\"\n @element.selectedIndex = snapshot.selectedIndex\n @element.disabled = snapshot.disabled\n @element.hidden = snapshot.hidden\n @element.inert = snapshot.inert\n @element.className = snapshot.classes\n @element.style.cssText = snapshot.style\n @style = snapshot.managedStyle\n @classes = snapshot.managedClasses\n @clean = snapshot.clean\n @error = snapshot.error\n @pendingError = snapshot.pendingError\n renderError()\n return null\n\nControl:dispose()\n return null\n\nmount(document, root, definition, types = null)\n if types == null\n types = new Types()\n control = types.create(document, definition)\n root.appendChild(control.element)\n return control\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA7JA;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;AA6UA;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import js global crypto\nimport \"./protocol\"\n collectValues(controls)\n applyResponse(controls, response, formId, seqno, effects)\nimport \"./inheritance\"\n normalizeInheritance(spec)\nimport \"./presentation\"\n classNames(value)\n styleMap(value)\n validateProperty(name, value)\nimport \"./input_values\"\n selectItems(options)\n selectIndex(items, value)\nimport \"./form_state\"\n rulesFor(value)\n validationMessage(rules, value)\n sameValue(left, right)\n\nexport mount(document, root, definition, types = null)\n\nexport class Types\n methods\n registerType(name, type)\n create(document, definition)\n\nTypes(options = null)\n if options != null and (!is_object(options) or is_array(options))\n throw \"UiControlRegistryOptionsMustBeMap\"\n @types = {\n }\n @classes = {\n }\n @sealed = false\n if options != null and options.classes != null\n if !is_object(options.classes) or is_array(options.classes)\n throw \"UiThemeClassesMustBeMap\"\n for options.classes as name: classes\n @classes[name] = classNames(classes)\n\nTypes:registerType(name, type)\n if @sealed\n throw \"UiControlRegistrySealed\"\n if !is_string(name) or name == \"\" or name == \"__proto__\" or name == \"prototype\" or name == \"constructor\" or !is_kindof(type, Function)\n throw \"UiControlTypeRequiresNameAndConstructor\"\n if name in @types\n throw \"UiDuplicateControlType: ${name}\"\n @types[name] = type\n return @this\n\nTypes:create(document, definition)\n @sealed = true\n if !is_object(definition) or !is_string(definition.type)\n throw \"UiControlRequiresDefinition\"\n prepared = {\n }\n for definition as name: value\n prepared[name] = value\n defaults = @classes[definition.type]\n if defaults != null\n prepared.classes = classNames(defaults.concat(classNames(definition.classes)))\n type = Control\n if definition.type in @types\n type = @types[definition.type]\n control = new type(document, prepared, @this)\n if !is_kindof(control, Control)\n throw \"UiCustomControlMustExtendControl\"\n return control\n\nexport class Binding\n methods\n handle(event)\n report(error)\n dispose()\n\nBinding(form, session, errors = null)\n @form = form\n @session = session\n @errors = errors\n @disposed = false\n root = form.element\n if root.langoBinding != null\n throw \"UiFormAlreadyBound\"\n listener = (event)\n handle(event)\n @listener = listener\n for [\"click\", \"change\", \"input\"] as type\n root.addEventListener(type, listener)\n root.langoBinding = @this\n\nBinding:handle(event)\n if @disposed\n return null\n root = @form.element\n element = event.target\n target = null\n current = element\n loop while current != null\n if current.inert == true or current.disabled == true or current.hidden == true\n return null\n if current == root\n break\n if current.langoFormRoot == true\n return null\n if target == null\n target = eventTarget(@form.controls, current, [], event.type)\n current = current.parentNode\n if current != root\n return null\n if event.type == \"input\" or event.type == \"change\"\n validateEvent(@form.controls, event.target, root)\n if target == null\n return null\n try\n event.preventDefault()\n if @errors != null and @errors.clear != null\n @errors.clear()\n session = @session\n return session.send(target.url, event.type, target.name).catch((error)\n report(error)\n )\n catch error\n report(error)\n return null\n\nvalidateEvent(controls, element, root)\n current = element\n loop while current != null and current != root\n control = elementControl(controls, current)\n if control != null and control.validate != null\n control.validate()\n return null\n current = current.parentNode\n return null\n\nelementControl(controls, element)\n for controls as control\n if control.element.langoFormRoot == true\n continue\n if control.element == element\n return control\n if is_array(control.controls)\n found = elementControl(control.controls, element)\n if found != null\n return found\n return null\n\nBinding:report(error)\n if @disposed\n return null\n if @errors != null\n @errors.error(error)\n else\n context log\n log.err(error)\n return null\n\nBinding:dispose()\n if @disposed\n return null\n @disposed = true\n root = @form.element\n for [\"click\", \"change\", \"input\"] as type\n root.removeEventListener(type, @listener)\n root.langoBinding = null\n return null\n\neventTarget(controls, element, parentPath, type)\n for controls as control\n path = parentPath.slice()\n if control.name != null and control.name != \"\"\n path[path.length] = control.name\n if control.element == element\n events = control.events\n if type in events\n name = path\n if path.length == 1\n name = path[0]\n if path.length == 0\n name = null\n return {\n url: events[type]\n name: name\n }\n if is_array(control.controls)\n target = eventTarget(control.controls, element, path, type)\n if target != null\n return target\n return null\n\ncontrolEvents(definition)\n events = {\n }\n if definition.event != null\n type = \"change\"\n if definition.type == \"Button\"\n type = \"click\"\n events[type] = definition.event\n if definition.events != null\n if not is_object(definition.events)\n throw \"UiClientEventsMustBeMap\"\n for definition.events as type: url\n if type != \"click\" and type != \"change\" and type != \"input\"\n throw \"UiClientUnsupportedEventType\"\n events[type] = url\n for events as type: url\n if !is_string(url) or !url.startsWith(\"/\") or url.startsWith(\"//\") or url.includes(\"\\\\\")\n throw \"UiClientEventRequiresSameOriginPath\"\n return events\n\nexport class Renderer\n methods\n create(definition)\n replace(old, replacement)\n remove(control)\n capture(control)\n restore(snapshot, operation)\n focus(control)\n toast(level, text)\n release(control)\n\nRenderer(document, types = null)\n @document = document\n @types = types\n if @types == null\n @types = new Types()\n\nRenderer:create(definition)\n return @types.create(@document, definition)\n\nRenderer:release(control)\n releaseControl(control)\n return null\n\nreleaseControl(control)\n if is_array(control.controls)\n for control.controls as child\n releaseControl(child)\n try\n if control.dispose != null\n control.dispose()\n catch error\n context log\n log.err(\"Control disposal failed: ${error}\")\n return null\n\nRenderer:replace(old, replacement)\n element = old.node\n element.parentNode.replaceChild(replacement.node, element)\n return null\n\nRenderer:remove(control)\n control.node.remove()\n return null\n\nRenderer:capture(control)\n element = control.node\n return {\n element: element\n parent: element.parentNode\n next: element.nextSibling\n }\n\nRenderer:restore(snapshot, operation)\n if operation.type == \"replace\"\n replacement = operation.new\n replacement.node.remove()\n if snapshot.parent != null\n snapshot.parent.insertBefore(snapshot.element, snapshot.next)\n return null\n\nRenderer:focus(control)\n control.element.focus()\n return null\n\nRenderer:toast(level, text)\n element = @document.createElement(\"div\")\n element.setAttribute(\"role\", \"status\")\n element.textContent = text\n @document.body.appendChild(element)\n return null\n\nexport class Control\n properties\n name\n element\n node\n controls\n events\n inherit\n validates\n confirms\n methods\n getValue()\n setValue(value)\n applyProperty(name, value)\n snapshotState()\n restoreState(snapshot)\n dispose()\n isDirty()\n markClean()\n acceptSaved(value)\n validate()\n reportValidity()\n reportPendingError()\n\nControl(document, definition, types = null, options = null)\n @name = definition.name\n @type = definition.type\n @controls = null\n @value = definition.value\n @clean = null\n @error = null\n @pendingError = false\n @rules = rulesFor(definition.validation)\n @tracked = definition.trackChanges\n if @tracked == null\n @tracked = @type == \"Text\" or @type == \"Select\" or @type == \"Checkbox\"\n if !is_bool(@tracked)\n throw \"UiTrackChangesMustBeBoolean\"\n @validates = definition.validate\n if @validates == null\n @validates = false\n if !is_bool(@validates)\n throw \"UiValidateEventMustBeBoolean\"\n @confirms = definition.confirmDirty\n if @confirms == null\n @confirms = false\n if !is_bool(@confirms)\n throw \"UiConfirmDirtyMustBeBoolean\"\n @items = []\n if @type == \"Select\"\n @items = selectItems(definition.options)\n @events = controlEvents(definition)\n @inherit = normalizeInheritance(definition.inherit)\n @classes = classNames(definition.classes)\n @style = styleMap(definition.style)\n registry = types\n if registry == null\n registry = new Types()\n if definition.inherit != null and @type != \"Form\"\n throw \"UiInheritanceRequiresForm\"\n tag = \"div\"\n if @type == \"Text\" or @type == \"Checkbox\"\n tag = \"input\"\n if @type == \"Select\"\n tag = \"select\"\n if @type == \"Button\"\n tag = \"button\"\n if options != null\n tag = options.tag\n if !is_string(tag) or tag == \"\"\n throw \"UiCustomControlRequiresTag\"\n if options == null and @type != \"Text\" and @type != \"Button\" and @type != \"Value\" and @type != \"Panel\" and @type != \"Container\" and @type != \"Form\" and @type != \"Select\" and @type != \"Checkbox\"\n throw \"UiClientUnknownControlType\"\n @element = document.createElement(tag)\n @node = @element\n @errorElement = null\n element = @element\n if @type == \"Form\"\n element.langoFormRoot = true\n if @type == \"Button\"\n element.type = \"button\"\n element.textContent = definition.text\n if @type == \"Value\"\n element.hidden = true\n if @type == \"Checkbox\"\n element.type = \"checkbox\"\n if definition.label != null\n if !is_string(definition.label)\n throw \"UiControlLabelMustBeString\"\n element.setAttribute(\"aria-label\", definition.label)\n if tag == \"input\" or tag == \"select\"\n @node = document.createElement(\"label\")\n @node.className = \"lango-field\"\n @node.setAttribute(\"data-lango-control\", @type)\n caption = document.createElement(\"span\")\n caption.className = \"lango-caption\"\n caption.textContent = definition.label\n @node.appendChild(caption)\n @node.appendChild(element)\n @errorElement = document.createElement(\"span\")\n @errorElement.className = \"lango-field-error\"\n @errorElement.id = \"lango-error-${crypto/randomUUID()}\"\n @errorElement.hidden = true\n element.setAttribute(\"aria-describedby\", @errorElement.id)\n @node.appendChild(@errorElement)\n if tag == \"input\" or tag == \"select\"\n element.setAttribute(\"aria-required\", \"${@rules.required == true}\")\n container = @type == \"Panel\" or @type == \"Container\" or @type == \"Form\"\n if options != null and options.container == true\n container = true\n if container\n @controls = []\n try\n if @type == \"Select\"\n for @items as item\n option = document.createElement(\"option\")\n option.value = item.value\n option.textContent = item.text\n option.disabled = item.disabled\n element.appendChild(option)\n if container and is_array(definition.controls)\n for definition.controls as childDefinition\n child = registry.create(document, childDefinition)\n @controls.add(child)\n element.appendChild(child.node)\n if definition.classes != null\n applyProperty(\"classes\", definition.classes)\n if definition.style != null\n applyProperty(\"style\", definition.style)\n if definition.enabled != null\n applyProperty(\"enabled\", definition.enabled)\n if definition.visible != null\n applyProperty(\"visible\", definition.visible)\n initial = definition.value\n if @type == \"Checkbox\" and initial == null\n initial = false\n setValue(initial)\n markClean()\n catch error\n if is_array(@controls)\n for @controls as child\n releaseControl(child)\n throw error\n\nControl:getValue()\n if is_array(@controls)\n return collectValues(@controls)\n switch @type\n case \"Text\"\n return @element.value\n case \"Checkbox\"\n return @element.checked\n case \"Select\"\n index = @element.selectedIndex\n if index < 0 or index >= @items.length\n return null\n return @items[index].value\n else\n return @value\n\nControl:setValue(value)\n switch @type\n case \"Text\"\n text = value\n if value == null\n text = \"\"\n @element.value = text\n case \"Checkbox\"\n if !is_bool(value)\n throw \"UiCheckboxValueMustBeBoolean\"\n @element.checked = value\n case \"Select\"\n @element.selectedIndex = selectIndex(@items, value)\n @value = value\n if @error != null\n validate()\n return null\n\nControl:isDirty()\n if is_array(@controls)\n for @controls as child\n if child.isDirty != null\n if child.isDirty()\n return true\n return false\n if !@tracked\n return false\n current = from_json(to_json(getValue()))\n return !sameValue(current, @clean)\n\nControl:markClean()\n if is_array(@controls)\n for @controls as child\n if child.markClean != null\n child.markClean()\n else\n acceptSaved(getValue())\n return null\n\nControl:acceptSaved(value)\n @clean = from_json(to_json(value))\n return null\n\nControl:validate()\n @pendingError = false\n @error = validationMessage(@rules, getValue())\n renderError()\n return @error\n\nControl:renderError()\n text = @error\n if text == null\n text = \"\"\n @element.setAttribute(\"aria-invalid\", \"${@error != null}\")\n @element.setAttribute(\"data-lango-error\", text)\n if @errorElement != null\n @errorElement.textContent = text\n @errorElement.hidden = @error == null\n if @element.setCustomValidity != null\n @element.setCustomValidity(text)\n return null\n\nControl:reportValidity()\n if @element.reportValidity != null\n return @element.reportValidity()\n return @error == null\n\nControl:reportPendingError()\n if !@pendingError\n return false\n current = @element\n loop while current != null\n if current.disabled == true or current.hidden == true or current.inert == true\n return false\n current = current.parentNode\n @pendingError = false\n reportValidity()\n return true\n\nControl:applyProperty(name, value)\n validateProperty(name, value)\n switch name\n case \"enabled\"\n @element.disabled = !value\n @element.inert = !value\n @node.inert = !value\n case \"visible\"\n @element.hidden = !value or @type == \"Value\"\n @node.hidden = @element.hidden\n case \"classes\"\n @classes = classNames(value)\n @element.className = @classes.join(\" \")\n case \"style\"\n styles = styleMap(value)\n for @style as property: text\n @element.style.removeProperty(property)\n for styles as property: text\n @element.style.setProperty(property, text)\n @style = styles\n case \"savedValue\"\n acceptSaved(value)\n case \"error\"\n @error = value\n @pendingError = value != null\n renderError()\n reportPendingError()\n return null\n\nControl:snapshotState()\n return {\n value: @value\n text: @element.value\n checked: @element.checked\n selectedIndex: @element.selectedIndex\n disabled: @element.disabled\n hidden: @element.hidden\n inert: @element.inert\n classes: @element.className\n style: @element.style.cssText\n managedStyle: @style\n managedClasses: @classes\n clean: @clean\n error: @error\n pendingError: @pendingError\n }\n\nControl:restoreState(snapshot)\n setValue(snapshot.value)\n if @type == \"Text\"\n @element.value = snapshot.text\n if @type == \"Checkbox\"\n @element.checked = snapshot.checked\n if @type == \"Select\"\n @element.selectedIndex = snapshot.selectedIndex\n @element.disabled = snapshot.disabled\n @element.hidden = snapshot.hidden\n @element.inert = snapshot.inert\n @node.hidden = snapshot.hidden\n @node.inert = snapshot.inert\n @element.className = snapshot.classes\n @element.style.cssText = snapshot.style\n @style = snapshot.managedStyle\n @classes = snapshot.managedClasses\n @clean = snapshot.clean\n @error = snapshot.error\n @pendingError = snapshot.pendingError\n renderError()\n return null\n\nControl:dispose()\n return null\n\nmount(document, root, definition, types = null)\n if types == null\n types = new Types()\n control = types.create(document, definition)\n root.appendChild(control.node)\n return control\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA7JA;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;AAwWA;;;;;;;;;;;;;;;"}
package/dist/session.mjs CHANGED
@@ -45,6 +45,7 @@ export class Session {
45
45
  #disposed;
46
46
  #seqno;
47
47
  #pending;
48
+ #focus;
48
49
  #tail;
49
50
  constructor(options) {
50
51
  __requireArity(arguments.length, [0], "constructor");
@@ -82,6 +83,7 @@ export class Session {
82
83
  this.#disposed = false;
83
84
  this.#seqno = 0;
84
85
  this.#pending = 0;
86
+ this.#focus = null;
85
87
  this.#tail = __normalize(__hostGlobal(["Promise"]).resolve());
86
88
  }
87
89
  send(path, event, name) {
@@ -111,6 +113,9 @@ export class Session {
111
113
  reservation = __normalize(this.#coordinator.reserve(__normalize(this.#resources)));
112
114
  __add(this.#reservations, reservation);
113
115
  }
116
+ if (__requireBoolean(__normalize(this.#pending) === 0)) {
117
+ this.#rememberFocus();
118
+ }
114
119
  this.#pending = __numericAdd(__normalize(this.#pending), 1);
115
120
  if (__requireBoolean(__normalize(this.#root) !== null)) {
116
121
  this.#root.inert = true;
@@ -165,11 +170,45 @@ export class Session {
165
170
  __normalize(this.#root.setAttribute("aria-busy", "false"));
166
171
  }
167
172
  if (__requireBoolean(__normalize(this.#pending) === 0)) {
173
+ this.#restoreFocus();
168
174
  this.reportErrors();
169
175
  }
170
176
  return null;
171
177
  return null;
172
178
  }
179
+ #rememberFocus() {
180
+ this.#focus = null;
181
+ if (__requireBoolean(__normalize(this.#root) === null)) {
182
+ return null;
183
+ }
184
+ let document = __normalize(this.#root.ownerDocument);
185
+ if (__requireBoolean(__requireBoolean(document !== null) && __requireBoolean(__normalize(this.#root.contains(__normalize(document.activeElement)))))) {
186
+ this.#focus = __normalize(document.activeElement);
187
+ }
188
+ return null;
189
+ return null;
190
+ }
191
+ #restoreFocus() {
192
+ let target = __normalize(this.#focus);
193
+ this.#focus = null;
194
+ if (__requireBoolean(__requireBoolean(target === null) || __requireBoolean(__normalize(target.isConnected) !== true))) {
195
+ return null;
196
+ }
197
+ let document = __normalize(target.ownerDocument);
198
+ if (__requireBoolean(__requireBoolean(__normalize(document.activeElement) !== __normalize(document.body)) && __requireBoolean(__normalize(document.activeElement) !== null))) {
199
+ return null;
200
+ }
201
+ let current = target;
202
+ __loop1: while (__requireBoolean(current !== null)) {
203
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.inert) === true) || __requireBoolean(__normalize(current.disabled) === true)) || __requireBoolean(__normalize(current.hidden) === true))) {
204
+ return null;
205
+ }
206
+ current = __normalize(current.parentNode);
207
+ }
208
+ __normalize(target.focus());
209
+ return null;
210
+ return null;
211
+ }
173
212
  perform(path, event, name) {
174
213
  __requireArity(arguments.length, [0, 1, 2], "perform");
175
214
  path = __boundary(path);
@@ -371,6 +410,7 @@ export class Session {
371
410
  return null;
372
411
  }
373
412
  this.#disposed = true;
413
+ this.#focus = null;
374
414
  if (__requireBoolean(__normalize(this.#coordinator) !== null)) {
375
415
  for (const reservation of __normalize(this.#reservations)) {
376
416
  __normalize(this.#coordinator.release(reservation));
@@ -1 +1 @@
1
- {"version":3,"file":"session.mjs","sources":["session.lango"],"sourcesContent":["import js global Promise\nimport js global fetch\nimport js global crypto\nimport \"./protocol\"\n collectValues(controls)\n applyOwnedResponse(controls, response, formId, seqno, effects, ownerControls)\n protocolVersion()\nimport \"./tokens\"\n browserTokenStore(key = \"lango:last-token\")\nimport \"./form_state\"\n dirtyFields(controls)\n validateFields(controls)\n validatesRequest(controls, name)\n confirmsRequest(controls, name)\n ownedFields(controls)\n\n\nexport class Session\n methods\n send(path, event, name)\n perform(path, event, name)\n finish(reservation = null)\n accept(response, seqno, controls = null)\n dispose()\n receiveToken(token)\n performReady(path, event, name, bootstrapToken = null)\n initializeToken(bootstrapToken)\n reservePing(gate)\n preparePing()\n pingEntry(bootstrapToken = null)\n isDirty()\n validate(report = true)\n currentControls()\n reportErrors()\n\nSession(options)\n if !is_string(options.formId) or options.formId == \"\"\n throw \"UiSessionRequiresFormId\"\n @formId = options.formId\n @formInstanceId = crypto.randomUUID()\n @controls = options.controls\n @root = options.root\n @effects = options.effects\n @transport = options.transport\n @tokens = options.tokens\n if @tokens == null\n @tokens = browserTokenStore()\n @token = @tokens.latest()\n @seedFromBootstrap = options.seedFromBootstrap == true\n if @seedFromBootstrap\n @token = options.seedToken\n @initialized = false\n @awaitingBootstrap = false\n if @tokens.initializing != null\n @awaitingBootstrap = @tokens.initializing()\n @lifecycle = options.lifecycle\n @heartbeat = options.heartbeat\n @coordinator = options.coordinator\n @resources = options.resources\n @form = options.form\n @window = options.window\n @reservations = []\n @disposed = false\n @seqno = 0\n @pending = 0\n @tail = Promise/resolve()\n\nSession:send(path, event, name)\n if @disposed\n throw \"UiSessionDisposed\"\n if !is_string(path) or !path.startsWith(\"/\") or path.startsWith(\"//\") or path.includes(\"\\\\\")\n throw \"UiSessionRequiresSameOriginPath\"\n if confirmsRequest(currentControls(), name) and isDirty()\n if @window == null or !is_kindof(@window.confirm, Function)\n throw \"UiDiscardConfirmationUnavailable\"\n if !@window.confirm(\"You have unsaved changes. Discard them?\")\n return Promise/resolve(false)\n if @heartbeat != null\n @heartbeat.activity()\n reservation = null\n if @coordinator != null\n reservation = @coordinator.reserve(@resources)\n @reservations.add(reservation)\n @pending++\n if @root != null\n @root.inert = true\n @root.setAttribute(\"aria-busy\", \"true\")\n waiting = [@tail]\n if reservation != null\n waiting.add(reservation.ready)\n ready = Promise/all(waiting)\n work = ready.then(()\n capture path\n capture event\n capture name\n return perform(path, event, name)\n )\n recovered = work.catch((error)\n ignoreFailure(error)\n )\n @tail = recovered\n return work.finally(()\n capture reservation\n finish(reservation)\n ).catch((error)\n if error == \"UiValidationFailed\" and !@disposed and @pending == 0\n validate()\n throw error\n )\n\nignoreFailure(error)\n return null\n\nSession:finish(reservation = null)\n if reservation != null\n @coordinator.release(reservation)\n index = @reservations.indexOf(reservation)\n if index >= 0\n @reservations.splice(index, 1)\n @pending--\n if @disposed\n return null\n if @heartbeat != null\n @heartbeat.activity()\n if @pending == 0 and @root != null\n @root.inert = false\n @root.setAttribute(\"aria-busy\", \"false\")\n if @pending == 0\n reportErrors()\n return null\n\nSession:perform(path, event, name)\n if @tokens.ready != null\n return @tokens.ready().then((bootstrapToken)\n capture path\n capture event\n capture name\n return performReady(path, event, name, bootstrapToken)\n )\n return performReady(path, event, name)\n\nSession:performReady(path, event, name, bootstrapToken = null)\n if @disposed\n throw \"UiSessionDisposed\"\n initializeToken(bootstrapToken)\n controls = currentControls()\n if validatesRequest(controls, name)\n issues = validate(false)\n if issues.length != 0\n throw \"UiValidationFailed\"\n @seqno++\n if @seqno > 9007199254740991\n throw \"UiSessionSequenceExhausted\"\n seqno = @seqno\n formId = @formId\n input = {\n protocol: protocolVersion()\n formId: formId\n formInstanceId: @formInstanceId\n seqno: seqno\n event: event\n name: name\n values: collectValues(controls)\n }\n transport = @transport\n result = null\n if transport == null\n result = post(path, input, @token, @this)\n else\n result = transport.send(path, input, @token)\n return result.then((response)\n capture seqno\n capture controls\n return accept(response, seqno, controls)\n )\n\nSession:currentControls()\n if @disposed\n throw \"UiSessionDisposed\"\n if @form != null and @lifecycle != null\n return @lifecycle.controlsFor(@form)\n return @controls\n\nSession:isDirty()\n if @disposed\n return false\n return dirtyFields(currentControls())\n\nSession:validate(report = true)\n issues = validateFields(currentControls())\n if report and issues.length != 0\n first = issues[0].control\n if first.reportValidity != null\n first.reportValidity()\n return issues\n\nSession:reportErrors()\n fields = ownedFields(currentControls())\n for fields as field\n control = field.control\n if is_kindof(control.reportPendingError, Function)\n if control.reportPendingError()\n return null\n return null\n\nSession:initializeToken(bootstrapToken)\n if !@initialized\n if @awaitingBootstrap\n @token = bootstrapToken\n else\n if @seedFromBootstrap and bootstrapToken != null\n @token = bootstrapToken\n @initialized = true\n return null\n\nSession:reservePing(gate)\n if @disposed\n return Promise/resolve(null)\n ready = @tail\n @tail = gate\n return ready.then(()\n return preparePing()\n )\n\nSession:preparePing()\n if @disposed\n return null\n if @tokens.ready != null\n return @tokens.ready().then((bootstrapToken)\n return pingEntry(bootstrapToken)\n )\n return pingEntry()\n\nSession:pingEntry(bootstrapToken = null)\n if @disposed\n return null\n initializeToken(bootstrapToken)\n if @token == null\n return null\n return {\n formId: @formId\n token: @token\n }\n\nSession:accept(response, seqno, controls = null)\n if @disposed\n throw \"UiSessionDisposed\"\n body = response\n receivedToken = null\n if response.body != null\n body = response.body\n receivedToken = response.token\n if receivedToken != null\n receiveToken(receivedToken)\n if body.formId != @formId or body.seqno != seqno\n throw \"UiClientResponseDoesNotMatchRequest\"\n effective = controls\n if effective == null\n effective = @controls\n try\n applyOwnedResponse(effective, body, @formId, seqno, @effects, @controls)\n finally\n if @lifecycle != null\n @lifecycle.reconcile()\n return body\n\nSession:receiveToken(token)\n if @disposed\n return null\n @tokens.save(token)\n @token = token\n return null\n\nSession:dispose()\n if @disposed\n return null\n @disposed = true\n if @coordinator != null\n for @reservations as reservation\n @coordinator.release(reservation)\n @reservations = []\n if @root != null\n @root.inert = false\n @root.setAttribute(\"aria-busy\", \"false\")\n return null\n\npost(path, input, token, client)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n if token != null\n headers.Authorization = \"Bearer ${token}\"\n return fetch(path, {\n method: \"POST\"\n headers: headers\n body: to_json(input)\n cache: \"no-store\"\n redirect: \"error\"\n }).then((response)\n capture client\n return readResponse(response, client)\n )\n\nreadResponse(response, client)\n token = response.headers.get(\"X-Lango-Token\")\n if token != null\n client.receiveToken(token)\n return response.json().then((body)\n capture response\n if !response.ok\n throw \"UiHttpError: ${response.status}: ${body.error}\"\n return body\n )\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA;;;;;;;AAgLA;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"session.mjs","sources":["session.lango"],"sourcesContent":["import js global Promise\nimport js global fetch\nimport js global crypto\nimport \"./protocol\"\n collectValues(controls)\n applyOwnedResponse(controls, response, formId, seqno, effects, ownerControls)\n protocolVersion()\nimport \"./tokens\"\n browserTokenStore(key = \"lango:last-token\")\nimport \"./form_state\"\n dirtyFields(controls)\n validateFields(controls)\n validatesRequest(controls, name)\n confirmsRequest(controls, name)\n ownedFields(controls)\n\n\nexport class Session\n methods\n send(path, event, name)\n perform(path, event, name)\n finish(reservation = null)\n accept(response, seqno, controls = null)\n dispose()\n receiveToken(token)\n performReady(path, event, name, bootstrapToken = null)\n initializeToken(bootstrapToken)\n reservePing(gate)\n preparePing()\n pingEntry(bootstrapToken = null)\n isDirty()\n validate(report = true)\n currentControls()\n reportErrors()\n\nSession(options)\n if !is_string(options.formId) or options.formId == \"\"\n throw \"UiSessionRequiresFormId\"\n @formId = options.formId\n @formInstanceId = crypto.randomUUID()\n @controls = options.controls\n @root = options.root\n @effects = options.effects\n @transport = options.transport\n @tokens = options.tokens\n if @tokens == null\n @tokens = browserTokenStore()\n @token = @tokens.latest()\n @seedFromBootstrap = options.seedFromBootstrap == true\n if @seedFromBootstrap\n @token = options.seedToken\n @initialized = false\n @awaitingBootstrap = false\n if @tokens.initializing != null\n @awaitingBootstrap = @tokens.initializing()\n @lifecycle = options.lifecycle\n @heartbeat = options.heartbeat\n @coordinator = options.coordinator\n @resources = options.resources\n @form = options.form\n @window = options.window\n @reservations = []\n @disposed = false\n @seqno = 0\n @pending = 0\n @focus = null\n @tail = Promise/resolve()\n\nSession:send(path, event, name)\n if @disposed\n throw \"UiSessionDisposed\"\n if !is_string(path) or !path.startsWith(\"/\") or path.startsWith(\"//\") or path.includes(\"\\\\\")\n throw \"UiSessionRequiresSameOriginPath\"\n if confirmsRequest(currentControls(), name) and isDirty()\n if @window == null or !is_kindof(@window.confirm, Function)\n throw \"UiDiscardConfirmationUnavailable\"\n if !@window.confirm(\"You have unsaved changes. Discard them?\")\n return Promise/resolve(false)\n if @heartbeat != null\n @heartbeat.activity()\n reservation = null\n if @coordinator != null\n reservation = @coordinator.reserve(@resources)\n @reservations.add(reservation)\n if @pending == 0\n rememberFocus()\n @pending++\n if @root != null\n @root.inert = true\n @root.setAttribute(\"aria-busy\", \"true\")\n waiting = [@tail]\n if reservation != null\n waiting.add(reservation.ready)\n ready = Promise/all(waiting)\n work = ready.then(()\n capture path\n capture event\n capture name\n return perform(path, event, name)\n )\n recovered = work.catch((error)\n ignoreFailure(error)\n )\n @tail = recovered\n return work.finally(()\n capture reservation\n finish(reservation)\n ).catch((error)\n if error == \"UiValidationFailed\" and !@disposed and @pending == 0\n validate()\n throw error\n )\n\nignoreFailure(error)\n return null\n\nSession:finish(reservation = null)\n if reservation != null\n @coordinator.release(reservation)\n index = @reservations.indexOf(reservation)\n if index >= 0\n @reservations.splice(index, 1)\n @pending--\n if @disposed\n return null\n if @heartbeat != null\n @heartbeat.activity()\n if @pending == 0 and @root != null\n @root.inert = false\n @root.setAttribute(\"aria-busy\", \"false\")\n if @pending == 0\n restoreFocus()\n reportErrors()\n return null\n\nSession:rememberFocus()\n @focus = null\n if @root == null\n return null\n document = @root.ownerDocument\n if document != null and @root.contains(document.activeElement)\n @focus = document.activeElement\n return null\n\nSession:restoreFocus()\n target = @focus\n @focus = null\n if target == null or target.isConnected != true\n return null\n document = target.ownerDocument\n if document.activeElement != document.body and document.activeElement != null\n return null\n current = target\n loop while current != null\n if current.inert == true or current.disabled == true or current.hidden == true\n return null\n current = current.parentNode\n target.focus()\n return null\n\nSession:perform(path, event, name)\n if @tokens.ready != null\n return @tokens.ready().then((bootstrapToken)\n capture path\n capture event\n capture name\n return performReady(path, event, name, bootstrapToken)\n )\n return performReady(path, event, name)\n\nSession:performReady(path, event, name, bootstrapToken = null)\n if @disposed\n throw \"UiSessionDisposed\"\n initializeToken(bootstrapToken)\n controls = currentControls()\n if validatesRequest(controls, name)\n issues = validate(false)\n if issues.length != 0\n throw \"UiValidationFailed\"\n @seqno++\n if @seqno > 9007199254740991\n throw \"UiSessionSequenceExhausted\"\n seqno = @seqno\n formId = @formId\n input = {\n protocol: protocolVersion()\n formId: formId\n formInstanceId: @formInstanceId\n seqno: seqno\n event: event\n name: name\n values: collectValues(controls)\n }\n transport = @transport\n result = null\n if transport == null\n result = post(path, input, @token, @this)\n else\n result = transport.send(path, input, @token)\n return result.then((response)\n capture seqno\n capture controls\n return accept(response, seqno, controls)\n )\n\nSession:currentControls()\n if @disposed\n throw \"UiSessionDisposed\"\n if @form != null and @lifecycle != null\n return @lifecycle.controlsFor(@form)\n return @controls\n\nSession:isDirty()\n if @disposed\n return false\n return dirtyFields(currentControls())\n\nSession:validate(report = true)\n issues = validateFields(currentControls())\n if report and issues.length != 0\n first = issues[0].control\n if first.reportValidity != null\n first.reportValidity()\n return issues\n\nSession:reportErrors()\n fields = ownedFields(currentControls())\n for fields as field\n control = field.control\n if is_kindof(control.reportPendingError, Function)\n if control.reportPendingError()\n return null\n return null\n\nSession:initializeToken(bootstrapToken)\n if !@initialized\n if @awaitingBootstrap\n @token = bootstrapToken\n else\n if @seedFromBootstrap and bootstrapToken != null\n @token = bootstrapToken\n @initialized = true\n return null\n\nSession:reservePing(gate)\n if @disposed\n return Promise/resolve(null)\n ready = @tail\n @tail = gate\n return ready.then(()\n return preparePing()\n )\n\nSession:preparePing()\n if @disposed\n return null\n if @tokens.ready != null\n return @tokens.ready().then((bootstrapToken)\n return pingEntry(bootstrapToken)\n )\n return pingEntry()\n\nSession:pingEntry(bootstrapToken = null)\n if @disposed\n return null\n initializeToken(bootstrapToken)\n if @token == null\n return null\n return {\n formId: @formId\n token: @token\n }\n\nSession:accept(response, seqno, controls = null)\n if @disposed\n throw \"UiSessionDisposed\"\n body = response\n receivedToken = null\n if response.body != null\n body = response.body\n receivedToken = response.token\n if receivedToken != null\n receiveToken(receivedToken)\n if body.formId != @formId or body.seqno != seqno\n throw \"UiClientResponseDoesNotMatchRequest\"\n effective = controls\n if effective == null\n effective = @controls\n try\n applyOwnedResponse(effective, body, @formId, seqno, @effects, @controls)\n finally\n if @lifecycle != null\n @lifecycle.reconcile()\n return body\n\nSession:receiveToken(token)\n if @disposed\n return null\n @tokens.save(token)\n @token = token\n return null\n\nSession:dispose()\n if @disposed\n return null\n @disposed = true\n @focus = null\n if @coordinator != null\n for @reservations as reservation\n @coordinator.release(reservation)\n @reservations = []\n if @root != null\n @root.inert = false\n @root.setAttribute(\"aria-busy\", \"false\")\n return null\n\npost(path, input, token, client)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n if token != null\n headers.Authorization = \"Bearer ${token}\"\n return fetch(path, {\n method: \"POST\"\n headers: headers\n body: to_json(input)\n cache: \"no-store\"\n redirect: \"error\"\n }).then((response)\n capture client\n return readResponse(response, client)\n )\n\nreadResponse(response, client)\n token = response.headers.get(\"X-Lango-Token\")\n if token != null\n client.receiveToken(token)\n return response.json().then((body)\n capture response\n if !response.ok\n throw \"UiHttpError: ${response.status}: ${body.error}\"\n return body\n )\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA;;;;;;;AA2MA;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;;"}
@@ -99,9 +99,6 @@ editor(record)
99
99
  type: "Value"
100
100
  name: "version"
101
101
  value: record.version
102
- }, {
103
- type: "Label"
104
- value: "Full name"
105
102
  }, {
106
103
  type: "Text"
107
104
  name: "fullName"
@@ -111,9 +108,6 @@ editor(record)
111
108
  required: true
112
109
  maxLength: 100
113
110
  }
114
- }, {
115
- type: "Label"
116
- value: "Email"
117
111
  }, {
118
112
  type: "Text"
119
113
  name: "email"
@@ -140,9 +134,6 @@ editor(record)
140
134
  value: "gb"
141
135
  text: "United Kingdom"
142
136
  }]
143
- }, {
144
- type: "Label"
145
- value: "Receive updates"
146
137
  }, {
147
138
  type: "Checkbox"
148
139
  name: "subscribed"
package/examples/demo.css CHANGED
@@ -70,3 +70,18 @@ nav {
70
70
  padding-block-start: 1rem;
71
71
  border-top: 1px solid #cbd5e1;
72
72
  }
73
+
74
+ .lango-field {
75
+ display: grid;
76
+ gap: 0.35rem;
77
+ }
78
+
79
+ .lango-caption { font-weight: 600; }
80
+ .lango-field-error { color: #b91c1c; }
81
+ .lango-field-error[hidden] { display: none; }
82
+ .lango-field input, .lango-field select { box-sizing: border-box; max-width: 100%; }
83
+ .lango-field[data-lango-control="Checkbox"] { grid-template-columns: auto 1fr; align-items: center; }
84
+ .lango-field[data-lango-control="Checkbox"] input { grid-column: 1; grid-row: 1; }
85
+ .lango-field[data-lango-control="Checkbox"] .lango-caption { grid-column: 2; grid-row: 1; }
86
+ .lango-field[data-lango-control="Checkbox"] .lango-field-error { grid-column: 1 / -1; }
87
+ :focus-visible { outline: 3px solid #0f766e; outline-offset: 3px; }
@@ -7,6 +7,7 @@
7
7
  <link rel="stylesheet" href="/assets/demo.css">
8
8
  </head>
9
9
  <body>
10
+ <header>
10
11
  <h1>Lango client demo</h1>
11
12
  <nav aria-label="Pages">
12
13
  <a href="/contacts">Contact book</a>
@@ -19,10 +20,13 @@
19
20
  <p>Country and update preferences use native Select/Checkbox controls; changing either sends a typed form event and re-enables Save.</p>
20
21
  <p>Save sends the form to the Lango API, updates the email field and disables the button.</p>
21
22
  <p>The nested form inherits the email value; its Save button updates the same field through writable inheritance.</p>
23
+ </header>
22
24
  <main id="app"></main>
25
+ <footer>
23
26
  <p id="form-status" role="alert"></p>
24
27
  <p><button id="logout" type="button">Log out</button></p>
25
28
  <p id="session-status" role="status"></p>
29
+ </footer>
26
30
  <script type="module" src="/dist/demo.mjs"></script>
27
31
  </body>
28
32
  </html>
@@ -72,10 +72,7 @@ profilePage()
72
72
  pattern: "[^ @]+@[^ @]+[.][^ @]+"
73
73
  message: "Enter a valid email address."
74
74
  }
75
- }, countryControl(), {
76
- type: "Label"
77
- value: "Receive updates"
78
- }, subscriptionControl(), {
75
+ }, countryControl(), subscriptionControl(), {
79
76
  type: "Label"
80
77
  name: "preferenceStatus"
81
78
  value: "Change your country or update preference, then save."
@@ -135,10 +132,7 @@ detailsPage()
135
132
  pattern: "[^ @]+@[^ @]+[.][^ @]+"
136
133
  message: "Enter a valid email address."
137
134
  }
138
- }, countryControl(), {
139
- type: "Label"
140
- value: "Receive updates"
141
- }, subscriptionControl(), {
135
+ }, countryControl(), subscriptionControl(), {
142
136
  type: "Label"
143
137
  name: "preferenceStatus"
144
138
  value: "Change your preferences, then save."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lango-project/lango-client",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Browser controls and protocol runtime for Lango server-driven UI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -35,14 +35,18 @@
35
35
  "demo": "node .demo-server/server.mjs",
36
36
  "test:demo": "npm run build && npm run build:demo-server && lango build examples/demo_test.lango --out .demo-server/demo_test.mjs --executable && node .demo-server/demo_test.mjs",
37
37
  "test:create": "lango build tools/create_app.lango --out dist/node/create_app.mjs --executable && lango build tools/create_app_test.lango --out .test-output/create_app_test.mjs --executable && node .test-output/create_app_test.mjs",
38
- "test:starter": "lango build tools/starter_test.lango --out .test-output/starter_test.mjs --executable && node .test-output/starter_test.mjs"
38
+ "test:starter": "lango build tools/starter_test.lango --out .test-output/starter_test.mjs --executable && node .test-output/starter_test.mjs",
39
+ "browser:install": "lango run tools/browser_runner.lango -- install",
40
+ "test:browser": "lango build tools/browser_test.lango --out .test-output/browser_test.mjs --executable && lango run tools/browser_runner.lango --"
39
41
  },
40
42
  "lango": {
41
43
  "source": "src/library.lango",
42
44
  "output": "dist/library.mjs"
43
45
  },
44
46
  "devDependencies": {
45
- "@lango-project/lango-js": "^0.1.8"
47
+ "@axe-core/playwright": "^4.14.0",
48
+ "@lango-project/lango-js": "^0.1.10",
49
+ "playwright": "^1.65.0"
46
50
  },
47
51
  "engines": {
48
52
  "node": ">=24"
@@ -59,7 +63,7 @@
59
63
  }
60
64
  },
61
65
  "langoStarter": {
62
- "compiler": "0.1.10",
66
+ "compiler": "0.1.11",
63
67
  "api": "0.2.0",
64
68
  "ui": "0.2.0"
65
69
  }
package/src/library.lango CHANGED
@@ -1,3 +1,4 @@
1
+ import js global crypto
1
2
  import "./protocol"
2
3
  collectValues(controls)
3
4
  applyResponse(controls, response, formId, seqno, effects)
@@ -243,16 +244,16 @@ releaseControl(control)
243
244
  return null
244
245
 
245
246
  Renderer:replace(old, replacement)
246
- element = old.element
247
- element.parentNode.replaceChild(replacement.element, element)
247
+ element = old.node
248
+ element.parentNode.replaceChild(replacement.node, element)
248
249
  return null
249
250
 
250
251
  Renderer:remove(control)
251
- control.element.remove()
252
+ control.node.remove()
252
253
  return null
253
254
 
254
255
  Renderer:capture(control)
255
- element = control.element
256
+ element = control.node
256
257
  return {
257
258
  element: element
258
259
  parent: element.parentNode
@@ -262,7 +263,7 @@ Renderer:capture(control)
262
263
  Renderer:restore(snapshot, operation)
263
264
  if operation.type == "replace"
264
265
  replacement = operation.new
265
- replacement.element.remove()
266
+ replacement.node.remove()
266
267
  if snapshot.parent != null
267
268
  snapshot.parent.insertBefore(snapshot.element, snapshot.next)
268
269
  return null
@@ -282,6 +283,7 @@ export class Control
282
283
  properties
283
284
  name
284
285
  element
286
+ node
285
287
  controls
286
288
  events
287
289
  inherit
@@ -351,6 +353,8 @@ Control(document, definition, types = null, options = null)
351
353
  if options == null and @type != "Text" and @type != "Button" and @type != "Value" and @type != "Panel" and @type != "Container" and @type != "Form" and @type != "Select" and @type != "Checkbox"
352
354
  throw "UiClientUnknownControlType"
353
355
  @element = document.createElement(tag)
356
+ @node = @element
357
+ @errorElement = null
354
358
  element = @element
355
359
  if @type == "Form"
356
360
  element.langoFormRoot = true
@@ -365,6 +369,23 @@ Control(document, definition, types = null, options = null)
365
369
  if !is_string(definition.label)
366
370
  throw "UiControlLabelMustBeString"
367
371
  element.setAttribute("aria-label", definition.label)
372
+ if tag == "input" or tag == "select"
373
+ @node = document.createElement("label")
374
+ @node.className = "lango-field"
375
+ @node.setAttribute("data-lango-control", @type)
376
+ caption = document.createElement("span")
377
+ caption.className = "lango-caption"
378
+ caption.textContent = definition.label
379
+ @node.appendChild(caption)
380
+ @node.appendChild(element)
381
+ @errorElement = document.createElement("span")
382
+ @errorElement.className = "lango-field-error"
383
+ @errorElement.id = "lango-error-${crypto/randomUUID()}"
384
+ @errorElement.hidden = true
385
+ element.setAttribute("aria-describedby", @errorElement.id)
386
+ @node.appendChild(@errorElement)
387
+ if tag == "input" or tag == "select"
388
+ element.setAttribute("aria-required", "${@rules.required == true}")
368
389
  container = @type == "Panel" or @type == "Container" or @type == "Form"
369
390
  if options != null and options.container == true
370
391
  container = true
@@ -382,7 +403,7 @@ Control(document, definition, types = null, options = null)
382
403
  for definition.controls as childDefinition
383
404
  child = registry.create(document, childDefinition)
384
405
  @controls.add(child)
385
- element.appendChild(child.element)
406
+ element.appendChild(child.node)
386
407
  if definition.classes != null
387
408
  applyProperty("classes", definition.classes)
388
409
  if definition.style != null
@@ -473,6 +494,9 @@ Control:renderError()
473
494
  text = ""
474
495
  @element.setAttribute("aria-invalid", "${@error != null}")
475
496
  @element.setAttribute("data-lango-error", text)
497
+ if @errorElement != null
498
+ @errorElement.textContent = text
499
+ @errorElement.hidden = @error == null
476
500
  if @element.setCustomValidity != null
477
501
  @element.setCustomValidity(text)
478
502
  return null
@@ -500,8 +524,10 @@ Control:applyProperty(name, value)
500
524
  case "enabled"
501
525
  @element.disabled = !value
502
526
  @element.inert = !value
527
+ @node.inert = !value
503
528
  case "visible"
504
529
  @element.hidden = !value or @type == "Value"
530
+ @node.hidden = @element.hidden
505
531
  case "classes"
506
532
  @classes = classNames(value)
507
533
  @element.className = @classes.join(" ")
@@ -550,6 +576,8 @@ Control:restoreState(snapshot)
550
576
  @element.disabled = snapshot.disabled
551
577
  @element.hidden = snapshot.hidden
552
578
  @element.inert = snapshot.inert
579
+ @node.hidden = snapshot.hidden
580
+ @node.inert = snapshot.inert
553
581
  @element.className = snapshot.classes
554
582
  @element.style.cssText = snapshot.style
555
583
  @style = snapshot.managedStyle
@@ -567,5 +595,5 @@ mount(document, root, definition, types = null)
567
595
  if types == null
568
596
  types = new Types()
569
597
  control = types.create(document, definition)
570
- root.appendChild(control.element)
598
+ root.appendChild(control.node)
571
599
  return control
@@ -289,6 +289,67 @@ test "partial DOM failure restores replaced and removed nodes in their original
289
289
  assert form.element.children[0] == first.element
290
290
  assert form.element.children[1] == second.element
291
291
 
292
+ test "visible labels and error descriptions survive visibility changes and structural rollback"
293
+ document = new Document()
294
+ form = mount(document, new Element(), {
295
+ type: "Form"
296
+ name: "profile"
297
+ controls: [{
298
+ type: "Text"
299
+ name: "first"
300
+ label: "Full name"
301
+ validation: {
302
+ required: true
303
+ }
304
+ }, {
305
+ type: "Text"
306
+ name: "second"
307
+ label: "Email"
308
+ }]
309
+ })
310
+ first = form.controls[0]
311
+ second = form.controls[1]
312
+ assert first.node.tagName == "label"
313
+ assert first.node.children[0].textContent == "Full name"
314
+ assert first.element.parentNode == first.node
315
+ errorText = first.node.children[2]
316
+ assert errorText.hidden
317
+ assert first.element.attributes["aria-describedby"] == errorText.id
318
+ assert first.element.attributes["aria-required"] == "true"
319
+ first.validate()
320
+ assert !errorText.hidden
321
+ assert errorText.textContent != ""
322
+ snapshot = first.snapshotState()
323
+ first.applyProperty("visible", false)
324
+ assert first.node.hidden
325
+ first.restoreState(snapshot)
326
+ assert !first.node.hidden
327
+ try
328
+ applyResponse(form.controls, {
329
+ formId: "profile"
330
+ seqno: 1
331
+ ui: {
332
+ replace: {
333
+ first: {
334
+ type: "Text"
335
+ label: "Replacement"
336
+ }
337
+ }
338
+ remove: ["second"]
339
+ }
340
+ vals: {
341
+ }
342
+ cmds: []
343
+ }, "profile", 1, new FailingRenderer(document))
344
+ assert false
345
+ catch error
346
+ assert error == "ExpectedDOMFailure"
347
+ assert form.element.children.length == 2
348
+ assert form.element.children[0] == first.node
349
+ assert form.element.children[1] == second.node
350
+ assert first.element.parentNode == first.node
351
+ assert first.node.children[2] == errorText
352
+
292
353
  test "renderer commits replacement and removal to the DOM and value model"
293
354
  document = new Document()
294
355
  root = new Element()
@@ -1557,7 +1618,7 @@ test "replacement options and values commit together and invalid selections reta
1557
1618
  failed = true
1558
1619
  assert failed
1559
1620
  assert form.controls[0] == old
1560
- assert old.element.parentNode == form.element
1621
+ assert old.node.parentNode == form.element
1561
1622
  applyResponse(form.controls, body("preferences", 2, {
1562
1623
  country: null
1563
1624
  }, patch), "preferences", 2, new Renderer(document))
package/src/session.lango CHANGED
@@ -63,6 +63,7 @@ Session(options)
63
63
  @disposed = false
64
64
  @seqno = 0
65
65
  @pending = 0
66
+ @focus = null
66
67
  @tail = Promise/resolve()
67
68
 
68
69
  Session:send(path, event, name)
@@ -81,6 +82,8 @@ Session:send(path, event, name)
81
82
  if @coordinator != null
82
83
  reservation = @coordinator.reserve(@resources)
83
84
  @reservations.add(reservation)
85
+ if @pending == 0
86
+ rememberFocus()
84
87
  @pending++
85
88
  if @root != null
86
89
  @root.inert = true
@@ -126,9 +129,35 @@ Session:finish(reservation = null)
126
129
  @root.inert = false
127
130
  @root.setAttribute("aria-busy", "false")
128
131
  if @pending == 0
132
+ restoreFocus()
129
133
  reportErrors()
130
134
  return null
131
135
 
136
+ Session:rememberFocus()
137
+ @focus = null
138
+ if @root == null
139
+ return null
140
+ document = @root.ownerDocument
141
+ if document != null and @root.contains(document.activeElement)
142
+ @focus = document.activeElement
143
+ return null
144
+
145
+ Session:restoreFocus()
146
+ target = @focus
147
+ @focus = null
148
+ if target == null or target.isConnected != true
149
+ return null
150
+ document = target.ownerDocument
151
+ if document.activeElement != document.body and document.activeElement != null
152
+ return null
153
+ current = target
154
+ loop while current != null
155
+ if current.inert == true or current.disabled == true or current.hidden == true
156
+ return null
157
+ current = current.parentNode
158
+ target.focus()
159
+ return null
160
+
132
161
  Session:perform(path, event, name)
133
162
  if @tokens.ready != null
134
163
  return @tokens.ready().then((bootstrapToken)
@@ -275,6 +304,7 @@ Session:dispose()
275
304
  if @disposed
276
305
  return null
277
306
  @disposed = true
307
+ @focus = null
278
308
  if @coordinator != null
279
309
  for @reservations as reservation
280
310
  @coordinator.release(reservation)
@@ -12,6 +12,10 @@ npm start
12
12
  Open http://localhost:8080/ (or refresh http://localhost:8080/home directly).
13
13
  Stop with Ctrl+C. Change the two local ports in `src/server.lango` if needed.
14
14
  Rebuild and restart after changing source or assets.
15
+ Named fields have visible associated labels and inline validation messages.
16
+ Tab reaches the name field and Save; Enter on Save runs validation. A successful
17
+ request restores focus when the control still exists, and validation reports the
18
+ first invalid input. The shell uses header/main landmarks and a visible focus ring.
15
19
  BrowserHost limits incoming bodies to 1 MiB and a 30-second upload deadline.
16
20
  Set `bodyLimit` and `bodyTimeoutMs` in its options to change both the proxy and
17
21
  worker API limits. The worker API's loopback port provides GET `/health`
@@ -2,3 +2,9 @@ body { max-width: 40rem; margin: 2rem auto; padding: 0 1rem; font: 1rem system-u
2
2
  input, button { display: block; padding: 0.6rem; margin-block: 0.75rem; font: inherit; }
3
3
  [aria-invalid="true"] { outline: 2px solid #b91c1c; }
4
4
  #error { color: #b91c1c; }
5
+ .lango-field { display: grid; gap: 0.35rem; margin-block: 0.75rem; }
6
+ .lango-caption { font-weight: 600; }
7
+ .lango-field input, .lango-field select { box-sizing: border-box; width: 100%; margin: 0; }
8
+ .lango-field-error { color: #b91c1c; }
9
+ .lango-field-error[hidden] { display: none; }
10
+ :focus-visible { outline: 3px solid #0f766e; outline-offset: 3px; }
@@ -16,7 +16,7 @@
16
16
  </script>
17
17
  </head>
18
18
  <body>
19
- <h1>{{APP_NAME}}</h1>
19
+ <header><h1>{{APP_NAME}}</h1></header>
20
20
  <main id="app"></main>
21
21
  <p id="error" role="alert"></p>
22
22
  <script type="module" src="/app/client.mjs"></script>
@@ -0,0 +1,32 @@
1
+ import js "node:fs" as fs
2
+ import js "node:path" as path
3
+ import js "node:child_process" as children
4
+ import js global process
5
+
6
+ export main(args)
7
+
8
+ main(args)
9
+ environment = {
10
+ }
11
+ for process.env as name: value
12
+ environment[name] = value
13
+ environment.PLAYWRIGHT_BROWSERS_PATH = path.resolve(".test-output/browsers")
14
+ environment.TMPDIR = path.resolve(".test-output/browser-tmp")
15
+ fs.mkdirSync(environment.TMPDIR, {
16
+ recursive: true
17
+ })
18
+ entry = path.resolve(".test-output/browser_test.mjs")
19
+ command = [entry]
20
+ command = command.concat(args)
21
+ if args.length == 1 and args[0] == "install"
22
+ command = [path.resolve("node_modules/playwright/cli.js"), "install", "chromium", "--only-shell"]
23
+ result = children/spawnSync(process.execPath, command, {
24
+ stdio: "inherit"
25
+ env: environment
26
+ })
27
+ if result.error != null
28
+ throw "BrowserProcessFailed: ${result.error}"
29
+ process.exitCode = result.status
30
+ if result.status == null
31
+ process.exitCode = 1
32
+ return null
@@ -0,0 +1,343 @@
1
+ import js "playwright" as browsers
2
+ import js "@axe-core/playwright" as axe
3
+ import js "node:child_process" as children
4
+ import js "node:path" as path
5
+ import js "node:fs" as fs
6
+ import js global Promise
7
+ import js global process
8
+ import js global setTimeout
9
+ import js global clearTimeout
10
+
11
+ export main(args)
12
+
13
+ class BrowserCheck
14
+ methods
15
+ run()
16
+
17
+ BrowserCheck(root, kind)
18
+ @root = root
19
+ @kind = kind
20
+ @browser = null
21
+ @page = null
22
+ @child = null
23
+ @errors = []
24
+ @console = []
25
+ @saves = 0
26
+ @output = ""
27
+ @ready = Promise/withResolvers()
28
+ @exited = Promise/withResolvers()
29
+ @closing = false
30
+ @artifacts = path.resolve(".test-output/browser-${kind}")
31
+ fs.mkdirSync(@artifacts, {
32
+ recursive: true
33
+ })
34
+ for ["failure.json", "failure.html", "failure.png"] as file
35
+ fs.rmSync(path.join(@artifacts, file), {
36
+ force: true
37
+ })
38
+
39
+ BrowserCheck:run()
40
+ entry = "dist/server/server.mjs"
41
+ if @kind == "demo"
42
+ entry = ".demo-server/server.mjs"
43
+ @child = children/spawn(process.execPath, [entry], {
44
+ cwd: @root
45
+ stdio: ["ignore", "pipe", "pipe"]
46
+ })
47
+ child = @child
48
+ child.stdout.on("data", (chunk)
49
+ @output = "${@output}${chunk}"
50
+ if @output.includes("Open http")
51
+ ready = @ready
52
+ ready.resolve(null)
53
+ )
54
+ child.stderr.on("data", (chunk)
55
+ @output = "${@output}${chunk}"
56
+ )
57
+ child.on("error", (error)
58
+ ready = @ready
59
+ ready.reject(error)
60
+ )
61
+ child.once("close", (code)
62
+ ready = @ready
63
+ exited = @exited
64
+ if !@closing
65
+ ready.reject("Browser fixture exited ${code}: ${@output}")
66
+ exited.resolve(code)
67
+ )
68
+ expired = ()
69
+ ready = @ready
70
+ ready.reject("Browser fixture timed out: ${@output}")
71
+ if @browser != null
72
+ @browser.close()
73
+ @child.kill("SIGTERM")
74
+ @timer = setTimeout(expired, 60000)
75
+ ready = @ready
76
+ return ready.promise.then(()
77
+ capture browsers
78
+ return browsers/chromium/launch({
79
+ headless: true
80
+ })
81
+ ).then((browser)
82
+ @browser = browser
83
+ return browser.newContext({
84
+ viewport: {
85
+ width: 1280
86
+ height: 900
87
+ }
88
+ })
89
+ ).then((context)
90
+ return context.newPage()
91
+ ).then((page)
92
+ @page = page
93
+ page.setDefaultTimeout(10000)
94
+ page.on("pageerror", (error)
95
+ @errors.add("${error}")
96
+ )
97
+ page.on("console", (message)
98
+ @console.add(message.text())
99
+ )
100
+ page.on("request", (request)
101
+ if request.url().endsWith("/app/save") or request.url().endsWith("/app/contacts/save")
102
+ @saves++
103
+ )
104
+ if @kind == "starter"
105
+ return starter()
106
+ return demo()
107
+ ).then(()
108
+ assert @errors.length == 0
109
+ println("PASS Chromium ${@kind}: interaction and accessibility checks")
110
+ ).catch((error)
111
+ return diagnose(error)
112
+ ).finally(()
113
+ return close()
114
+ )
115
+
116
+ BrowserCheck:diagnose(error)
117
+ fs.writeFileSync(path.join(@artifacts, "failure.json"), to_json({
118
+ error: "${error}"
119
+ pageErrors: @errors
120
+ console: @console
121
+ server: @output
122
+ }))
123
+ if @page == null
124
+ throw error
125
+ return @page.screenshot({
126
+ path: path.join(@artifacts, "failure.png")
127
+ fullPage: true
128
+ }).then(()
129
+ return @page.content()
130
+ ).then((html)
131
+ capture error
132
+ capture fs
133
+ capture path
134
+ fs.writeFileSync(path.join(@artifacts, "failure.html"), html)
135
+ throw error
136
+ )
137
+
138
+ BrowserCheck:close()
139
+ clearTimeout(@timer)
140
+ @closing = true
141
+ closing = Promise/resolve(null)
142
+ if @browser != null
143
+ closing = @browser.close()
144
+ return closing.finally(()
145
+ @child.kill("SIGTERM")
146
+ exited = @exited
147
+ return exited.promise
148
+ )
149
+
150
+ BrowserCheck:audit(name)
151
+ page = @page
152
+ scan = new axe/AxeBuilder({
153
+ page: page
154
+ })
155
+ return page.screenshot({
156
+ path: path.join(@artifacts, "${name}.png")
157
+ fullPage: true
158
+ }).then(()
159
+ capture scan
160
+ return scan.analyze()
161
+ ).then((result)
162
+ capture name
163
+ capture fs
164
+ capture path
165
+ fs.writeFileSync(path.join(@artifacts, "${name}-axe.json"), to_json(result))
166
+ issues = []
167
+ for result.violations as violation
168
+ issues.add("${violation.id}: ${violation.help}")
169
+ if issues.length > 0
170
+ throw "Accessibility failures: ${to_json(issues)}"
171
+ )
172
+
173
+ BrowserCheck:starter()
174
+ page = @page
175
+ return page.goto("http://127.0.0.1:8080/home").then(()
176
+ page = @page
177
+ return page.getByRole("textbox", {
178
+ name: "Your name"
179
+ exact: true
180
+ }).waitFor()
181
+ ).then(()
182
+ return audit("home")
183
+ ).then(()
184
+ page = @page
185
+ return page.getByText("Your name", {
186
+ exact: true
187
+ }).waitFor()
188
+ ).then(()
189
+ return @page.keyboard.press("Tab")
190
+ ).then(()
191
+ return @page.locator("input[aria-label='Your name']:focus").count()
192
+ ).then((count)
193
+ assert count == 1
194
+ return @page.keyboard.press("Tab")
195
+ ).then(()
196
+ return @page.keyboard.press("Enter")
197
+ ).then(()
198
+ return @page.locator("input[aria-label='Your name'][aria-invalid='true']:focus").waitFor()
199
+ ).then(()
200
+ assert @saves == 0
201
+ return @page.locator(".lango-field-error:not([hidden])").count()
202
+ ).then((count)
203
+ assert count == 1
204
+ return textbox("Your name").fill(" Ada ")
205
+ ).then(()
206
+ return clickResponse("Save", "/app/save")
207
+ ).then((response)
208
+ assert response.status() == 200
209
+ return idle()
210
+ ).then(()
211
+ return textbox("Your name").inputValue()
212
+ ).then((value)
213
+ assert value == "Ada"
214
+ return @page.locator("button:focus").textContent()
215
+ ).then((text)
216
+ assert text == "Save"
217
+ return @page.reload()
218
+ ).then(()
219
+ return textbox("Your name").waitFor()
220
+ ).then(()
221
+ return @page.setViewportSize({
222
+ width: 390
223
+ height: 844
224
+ })
225
+ ).then(()
226
+ return textbox("Your name").boundingBox()
227
+ ).then((bounds)
228
+ assert bounds.x >= 0 and bounds.x + bounds.width <= 390
229
+ return audit("home-mobile")
230
+ )
231
+
232
+ BrowserCheck:textbox(name)
233
+ return @page.getByRole("textbox", {
234
+ name: name
235
+ exact: true
236
+ })
237
+
238
+ BrowserCheck:idle()
239
+ return @page.locator("[aria-busy='true']").waitFor({
240
+ state: "hidden"
241
+ })
242
+
243
+ BrowserCheck:clickResponse(name, endpoint)
244
+ response = @page.waitForResponse("**${endpoint}")
245
+ return @page.getByRole("button", {
246
+ name: name
247
+ exact: true
248
+ }).click().then(()
249
+ capture response
250
+ return response
251
+ )
252
+
253
+ BrowserCheck:demo()
254
+ page = @page
255
+ return page.goto("http://127.0.0.1:8080/contacts").then(()
256
+ page = @page
257
+ return page.getByRole("textbox", {
258
+ name: "Full name"
259
+ exact: true
260
+ }).waitFor()
261
+ ).then(()
262
+ return audit("contacts")
263
+ ).then(()
264
+ return textbox("Full name").fill("Browser Contact")
265
+ ).then(()
266
+ return textbox("Email").fill("browser@example.com")
267
+ ).then(()
268
+ return @page.getByText("Receive updates", {
269
+ exact: true
270
+ }).click()
271
+ ).then(()
272
+ return clickResponse("Save contact", "/app/contacts/save")
273
+ ).then((response)
274
+ assert response.status() == 200
275
+ return idle()
276
+ ).then(()
277
+ return @page.getByRole("combobox", {
278
+ name: "Saved contacts"
279
+ }).textContent()
280
+ ).then((text)
281
+ assert text.includes("Browser Contact")
282
+ return textbox("Full name").fill("Unsaved Contact")
283
+ ).then(()
284
+ page = @page
285
+ page.once("dialog", (dialog)
286
+ dialog.dismiss()
287
+ )
288
+ return page.getByRole("link", {
289
+ name: "Profile"
290
+ exact: true
291
+ }).click()
292
+ ).then(()
293
+ assert @page.url().endsWith("/contacts")
294
+ return textbox("Full name").inputValue()
295
+ ).then((value)
296
+ assert value == "Unsaved Contact"
297
+ return textbox("Full name").fill("Browser Contact")
298
+ ).then(()
299
+ return @page.getByRole("link", {
300
+ name: "Profile"
301
+ exact: true
302
+ }).click()
303
+ ).then(()
304
+ return textbox("Email").waitFor()
305
+ ).then(()
306
+ return idle()
307
+ ).then(()
308
+ assert @page.url().endsWith("/profile")
309
+ return textbox("Email").fill("blocked@example.com")
310
+ ).then(()
311
+ return clickResponse("Save", "/app/save")
312
+ ).then(()
313
+ return @page.locator("input[aria-label='Email'][aria-invalid='true']:focus").waitFor()
314
+ ).then(()
315
+ return audit("profile-error")
316
+ ).then(()
317
+ return textbox("Email").fill("ada@example.com")
318
+ ).then(()
319
+ return @page.goBack()
320
+ ).then(()
321
+ return textbox("Full name").waitFor()
322
+ ).then(()
323
+ return @page.goForward()
324
+ ).then(()
325
+ return textbox("Email").waitFor()
326
+ ).then(()
327
+ return @page.reload()
328
+ ).then(()
329
+ return textbox("Email").waitFor()
330
+ )
331
+
332
+ main(args)
333
+ root = path.resolve(".")
334
+ kind = "demo"
335
+ if args.length > 0
336
+ root = path.resolve(args[0])
337
+ kind = "starter"
338
+ if args.length > 1
339
+ kind = args[1]
340
+ if args.length > 2 or (kind != "starter" and kind != "demo")
341
+ throw "Usage: npm run test:browser -- [built-app-directory] [starter|demo]"
342
+ check = new BrowserCheck(root, kind)
343
+ return check.run()
@@ -21,8 +21,8 @@ main(args)
21
21
  assert result.status == 0
22
22
  manifest = from_json(fs.readFileSync(path.join(target, "package.json"), "utf8"))
23
23
  assert manifest.name == "my-app"
24
- assert manifest.dependencies["@lango-project/lango-client"] == "0.2.0"
25
- assert manifest.devDependencies["@lango-project/lango-js"] == "0.1.10"
24
+ assert manifest.dependencies["@lango-project/lango-client"] == "0.2.1"
25
+ assert manifest.devDependencies["@lango-project/lango-js"] == "0.1.11"
26
26
  assert fs.existsSync(path.join(target, ".gitignore"))
27
27
  assert fs.existsSync(path.join(target, "src", "worker.lango"))
28
28
  assert fs.existsSync(path.join(target, ".vscode", "settings.json"))