@syware/jlib 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +12 -8
  2. package/dist/atoms/jl-avatar.d.ts +2 -0
  3. package/dist/atoms/jl-avatar.js +11 -6
  4. package/dist/atoms/jl-button.d.ts +6 -0
  5. package/dist/atoms/jl-button.js +22 -8
  6. package/dist/atoms/jl-chip.js +2 -1
  7. package/dist/atoms/jl-input.js +3 -3
  8. package/dist/atoms/jl-link.d.ts +1 -0
  9. package/dist/atoms/jl-link.js +5 -2
  10. package/dist/atoms/jl-progress-ring.d.ts +2 -0
  11. package/dist/atoms/jl-progress-ring.js +6 -2
  12. package/dist/atoms/jl-progress.d.ts +1 -0
  13. package/dist/atoms/jl-progress.js +5 -2
  14. package/dist/atoms/jl-rating.d.ts +2 -0
  15. package/dist/atoms/jl-rating.js +11 -6
  16. package/dist/atoms/jl-select.css.js +1 -1
  17. package/dist/atoms/jl-select.d.ts +4 -0
  18. package/dist/atoms/jl-select.js +18 -2
  19. package/dist/atoms/jl-switch.css.js +1 -1
  20. package/dist/atoms/jl-textarea.js +2 -2
  21. package/dist/base/jl-form-control.d.ts +3 -2
  22. package/dist/base/jl-form-control.js +14 -4
  23. package/dist/index.d.ts +1 -0
  24. package/dist/lib/dom.d.ts +5 -0
  25. package/dist/lib/dom.js +9 -1
  26. package/dist/lib/download.js +10 -2
  27. package/dist/lib/floating.d.ts +5 -0
  28. package/dist/lib/floating.js +21 -2
  29. package/dist/lib/fuzzy.d.ts +3 -2
  30. package/dist/lib/fuzzy.js +15 -4
  31. package/dist/lib/modal.d.ts +24 -0
  32. package/dist/lib/modal.js +52 -0
  33. package/dist/lib/numeric.d.ts +5 -0
  34. package/dist/lib/numeric.js +11 -1
  35. package/dist/lib/option-filter.d.ts +2 -0
  36. package/dist/lib/option-filter.js +1 -1
  37. package/dist/lib/press.d.ts +11 -0
  38. package/dist/lib/press.js +31 -0
  39. package/dist/lib/table.js +12 -4
  40. package/dist/lib/texts-de.d.ts +12 -0
  41. package/dist/lib/texts-de.js +12 -0
  42. package/dist/lib/texts-fr.d.ts +12 -0
  43. package/dist/lib/texts-fr.js +12 -0
  44. package/dist/lib/texts.d.ts +12 -0
  45. package/dist/lib/texts.js +12 -0
  46. package/dist/molecules/jl-accordion-item.js +2 -1
  47. package/dist/molecules/jl-calendar.d.ts +4 -0
  48. package/dist/molecules/jl-calendar.js +16 -5
  49. package/dist/molecules/jl-chip-group.css.js +1 -1
  50. package/dist/molecules/jl-chip-group.js +3 -3
  51. package/dist/molecules/jl-code-block.css.js +1 -1
  52. package/dist/molecules/jl-combobox.d.ts +4 -0
  53. package/dist/molecules/jl-combobox.js +23 -11
  54. package/dist/molecules/jl-copy-button.css.js +1 -1
  55. package/dist/molecules/jl-copy-button.d.ts +11 -4
  56. package/dist/molecules/jl-copy-button.js +48 -22
  57. package/dist/molecules/jl-date-picker.d.ts +4 -0
  58. package/dist/molecules/jl-date-picker.js +18 -12
  59. package/dist/molecules/jl-field.d.ts +5 -1
  60. package/dist/molecules/jl-field.js +24 -5
  61. package/dist/molecules/jl-file-drop.css.js +1 -1
  62. package/dist/molecules/jl-file-drop.d.ts +4 -0
  63. package/dist/molecules/jl-file-drop.js +16 -8
  64. package/dist/molecules/jl-input-list.js +13 -6
  65. package/dist/molecules/jl-load-state.d.ts +8 -0
  66. package/dist/molecules/jl-load-state.js +33 -7
  67. package/dist/molecules/jl-menu.d.ts +21 -1
  68. package/dist/molecules/jl-menu.js +58 -6
  69. package/dist/molecules/jl-number-input.d.ts +2 -0
  70. package/dist/molecules/jl-number-input.js +12 -8
  71. package/dist/molecules/jl-radio-group.js +3 -2
  72. package/dist/molecules/jl-search.js +2 -2
  73. package/dist/molecules/jl-segmented.js +2 -2
  74. package/dist/molecules/jl-tabs.js +2 -2
  75. package/dist/molecules/jl-tag-input.css.js +1 -1
  76. package/dist/molecules/jl-tag-input.d.ts +4 -0
  77. package/dist/molecules/jl-tag-input.js +17 -9
  78. package/dist/molecules/jl-toast.js +8 -4
  79. package/dist/molecules/jl-tooltip.js +8 -2
  80. package/dist/organisms/jl-command-palette.css.js +1 -1
  81. package/dist/organisms/jl-command-palette.d.ts +2 -0
  82. package/dist/organisms/jl-command-palette.js +9 -3
  83. package/dist/organisms/jl-dialog.d.ts +3 -0
  84. package/dist/organisms/jl-dialog.js +13 -3
  85. package/dist/organisms/jl-drawer.d.ts +3 -0
  86. package/dist/organisms/jl-drawer.js +13 -3
  87. package/dist/organisms/jl-flow.d.ts +2 -0
  88. package/dist/organisms/jl-flow.js +29 -9
  89. package/dist/organisms/jl-table.css.js +1 -1
  90. package/dist/organisms/jl-table.d.ts +14 -3
  91. package/dist/organisms/jl-table.js +34 -15
  92. package/dist/organisms/jl-toaster.d.ts +13 -2
  93. package/dist/organisms/jl-toaster.js +47 -4
  94. package/dist/organisms/jl-tree.css.js +1 -1
  95. package/dist/organisms/jl-tree.d.ts +23 -4
  96. package/dist/organisms/jl-tree.js +74 -18
  97. package/dist/styles/base.css.js +1 -1
  98. package/dist/styles/control.css.js +1 -1
  99. package/dist/styles/tokens.css.js +1 -1
  100. package/dist/tokens.css +4 -3
  101. package/dist/types/jl-load-state.types.d.ts +7 -0
  102. package/dist/types/jl-table.types.d.ts +12 -0
  103. package/dist/types/jl-tree.types.d.ts +17 -0
  104. package/dist/types/press.types.d.ts +6 -0
  105. package/package.json +6 -4
package/README.md CHANGED
@@ -48,18 +48,22 @@ button.events.register('press', () => save());
48
48
 
49
49
  ## Components
50
50
 
51
- - **Atoms**: avatar, badge, button, checkbox, chip, divider, icon, input, kbd, link, progress, progress ring, rating,
52
- select, skeleton, slider, spinner, switch, textarea.
53
- - **Molecules**: accordion, alert, avatar group, breadcrumb, calendar, card, code block, combobox, copy button, date
54
- picker, empty state, field, file drop, list item, menu, number input, pagination, popover, radio group, search,
55
- segmented control, stat, steps, tabs, tag input, timeline, toast, tooltip.
56
- - **Organisms**: command palette, confirm, dialog, drawer, navbar, page header, side nav, table, toaster, tree.
57
- - **Templates**: app shell, split view.
51
+ - **Atoms**: app icon, avatar, badge, button, checkbox, chip, divider, icon, input, kbd, link, loading bar,
52
+ progress, progress ring, rating, select, skeleton, slider, spinner, switch, textarea.
53
+ - **Molecules**: accordion, accordion item, account button, alert, avatar group, breadcrumb, calendar, card, chip
54
+ group, code block, combobox, copy button, date picker, empty state, facts, field, file drop, input list, list
55
+ item, load more, load state, menu, number input, pagination, popover, radio group, search, search button,
56
+ segmented control, stat, steps, tab panel, tabs, tag input, timeline, toast, tooltip.
57
+ - **Organisms**: command palette, confirm, dialog, drawer, flow, navbar, page header, page outlet, side nav, tab
58
+ bar, table, toaster, tree.
59
+ - **Templates**: app shell, auth layout, page, split view, stack.
58
60
 
59
61
  ## Icons
60
62
 
61
63
  Components draw their own icons with no setup. The names a page writes (`<jl-icon name="settings">`,
62
- `icon="plus"` on a button) are registered once, so a bundle holds only the icons in use:
64
+ `icon="plus"` on a button) are registered once, so a bundle holds only the icons in use: Icons are
65
+ [lucide](https://lucide.dev)'s: an app that imports some by name installs it itself (`npm install lucide`), as a
66
+ strict package manager (pnpm) gives an app only the packages it names.
63
67
 
64
68
  ```ts
65
69
  import { Coffee } from 'lucide';
@@ -48,5 +48,7 @@ export declare class JlAvatar extends JlElement {
48
48
  private renderFace;
49
49
  private renderSize;
50
50
  private renderStatus;
51
+ /** The status is said in jlib's language. */
52
+ protected drawTexts(): void;
51
53
  private renderLabel;
52
54
  }
@@ -1,3 +1,4 @@
1
+ import { jlText } from "../lib/texts.js";
1
2
  import { BASE_STYLES } from "../styles/shared.js";
2
3
  import { JlElement } from "../base/jl-element.js";
3
4
  import { oneOf } from "../lib/attributes.js";
@@ -34,11 +35,11 @@ var NAME_TONES = [
34
35
  "neutral"
35
36
  ];
36
37
  var NO_NAME_TONE = "neutral";
37
- var STATUS_LABELS = {
38
- away: "away",
39
- busy: "busy",
40
- offline: "offline",
41
- online: "online"
38
+ var STATUS_TEXTS = {
39
+ away: "statusAway",
40
+ busy: "statusBusy",
41
+ offline: "statusOffline",
42
+ online: "statusOnline"
42
43
  };
43
44
  var FALLBACK_ICON = "user";
44
45
  /**
@@ -147,10 +148,14 @@ var JlAvatar = class extends JlElement {
147
148
  this.reflect("status", status);
148
149
  this.renderLabel();
149
150
  }
151
+ /** The status is said in jlib's language. */
152
+ drawTexts() {
153
+ this.renderLabel();
154
+ }
150
155
  renderLabel() {
151
156
  const name = this.label.get() || this.name.get().trim();
152
157
  const status = this.status.get();
153
- const spoken = status === "" ? name : [name, STATUS_LABELS[status]].filter((part) => part !== "").join(", ");
158
+ const spoken = [name, status === "" ? "" : jlText(STATUS_TEXTS[status])].filter((part) => part !== "").join(", ");
154
159
  const avatar = this._refs.avatar;
155
160
  setOrRemove(avatar, "aria-label", spoken);
156
161
  avatar.setAttribute("role", spoken === "" ? "presentation" : "img");
@@ -73,12 +73,18 @@ export declare class JlButton extends JlElement {
73
73
  set(setter: string | ((prevState: string) => string)): void;
74
74
  }>>;
75
75
  private readonly _internals;
76
+ private readonly _form;
76
77
  private readonly _refs;
77
78
  focus(options?: FocusOptions): void;
78
79
  templateHtml(): Node;
79
80
  templateCss(): string;
81
+ /** Called by the browser when a `<fieldset disabled>` around the button changes: it presses and submits no more. */
82
+ formDisabledCallback(disabled: boolean): void;
80
83
  onConnect(): void;
81
84
  private canPress;
85
+ /** Disabled by its own input, or by a `<fieldset disabled>` around it. */
86
+ private isOff;
87
+ private renderDisabled;
82
88
  /** The element that takes focus and clicks: the link with an `href`, the button otherwise. */
83
89
  private control;
84
90
  /**
@@ -4,7 +4,7 @@ import { elementInternals } from "../lib/internals.js";
4
4
  import { oneOf } from "../lib/attributes.js";
5
5
  import { CONTROL_SIZES } from "../lib/options.js";
6
6
  import { JlIcon } from "./jl-icon.js";
7
- import { setOrRemove } from "../lib/dom.js";
7
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
8
8
  import jl_button_default from "./jl-button.css.js";
9
9
  import { JlSpinner } from "./jl-spinner.js";
10
10
  import { css } from "@jadis/core";
@@ -54,16 +54,15 @@ var JlButton = class extends JlElement {
54
54
  parse: oneOf(BUTTON_TYPES, "button")
55
55
  });
56
56
  disabled = this.useChange(false, (value) => {
57
- this._refs.button.disabled = value;
58
- this.renderLink();
59
57
  this.reflect("disabled", value);
58
+ this.renderDisabled();
60
59
  }, { attribute: "disabled" });
61
60
  /** Shows a spinner in place of the icon and ignores presses, while the work it started runs. */
62
61
  loading = this.useChange(false, (value) => {
63
62
  this._refs.spinner.hidden = !value;
64
63
  this._refs.start.hidden = value || this.icon.get() === "";
65
- this._refs.button.toggleAttribute("aria-busy", value);
66
- this._refs.link.toggleAttribute("aria-busy", value);
64
+ setAriaFlag(this._refs.button, "aria-busy", value);
65
+ setAriaFlag(this._refs.link, "aria-busy", value);
67
66
  this.reflect("loading", value);
68
67
  }, { attribute: "loading" });
69
68
  /** The tooltip; also the button's name for screen readers when it only has an icon. */
@@ -77,6 +76,7 @@ var JlButton = class extends JlElement {
77
76
  /** With an `href`, saves what it points to as a file of this name instead of opening it. */
78
77
  download = this.useChange("", () => this.renderLink(), { attribute: "download" });
79
78
  _internals = elementInternals(this);
79
+ _form = { disabled: false };
80
80
  _refs = this.useRefs((ref) => ({
81
81
  button: ref("button"),
82
82
  content: ref(".content"),
@@ -120,7 +120,13 @@ var JlButton = class extends JlElement {
120
120
  templateCss() {
121
121
  return css`${BASE_STYLES}${jl_button_default}`;
122
122
  }
123
+ /** Called by the browser when a `<fieldset disabled>` around the button changes: it presses and submits no more. */
124
+ formDisabledCallback(disabled) {
125
+ this._form.disabled = disabled;
126
+ this.whenRendered(() => this.renderDisabled());
127
+ }
123
128
  onConnect() {
129
+ this.renderLabel();
124
130
  this.on(this._refs.slot, "slotchange", () => this.renderLabel());
125
131
  this.on(this._refs.button, "click", () => {
126
132
  if (!this.canPress()) return;
@@ -136,7 +142,15 @@ var JlButton = class extends JlElement {
136
142
  });
137
143
  }
138
144
  canPress() {
139
- return !(this.disabled.get() || this.loading.get());
145
+ return !(this.isOff() || this.loading.get());
146
+ }
147
+ /** Disabled by its own input, or by a `<fieldset disabled>` around it. */
148
+ isOff() {
149
+ return this.disabled.get() || this._form.disabled;
150
+ }
151
+ renderDisabled() {
152
+ this._refs.button.disabled = this.isOff();
153
+ this.renderLink();
140
154
  }
141
155
  /** The element that takes focus and clicks: the link with an `href`, the button otherwise. */
142
156
  control() {
@@ -151,7 +165,7 @@ var JlButton = class extends JlElement {
151
165
  const href = this.href.get();
152
166
  const isLink = href !== "";
153
167
  const target = this.target.get();
154
- const off = isLink && this.disabled.get();
168
+ const off = isLink && this.isOff();
155
169
  const control = this.control();
156
170
  if (content.parentNode !== control) control.append(content);
157
171
  button.hidden = isLink;
@@ -188,7 +202,7 @@ var JlButton = class extends JlElement {
188
202
  const label = this.label.get();
189
203
  const hint = this.hint.get();
190
204
  const iconOnly = label === "" && !this.hasSlottedContent();
191
- this._refs.label.textContent = label;
205
+ if (this._refs.label.textContent !== label) this._refs.label.textContent = label;
192
206
  this.reflect("icon-only", iconOnly);
193
207
  for (const control of [this._refs.button, this._refs.link]) {
194
208
  setOrRemove(control, "title", hint);
@@ -4,6 +4,7 @@ import { JlElement } from "../base/jl-element.js";
4
4
  import { oneOf } from "../lib/attributes.js";
5
5
  import { registerIcons } from "../lib/icons.js";
6
6
  import { JlIcon } from "./jl-icon.js";
7
+ import { setAriaFlag } from "../lib/dom.js";
7
8
  import { isActivationKey } from "../lib/surface.js";
8
9
  import jl_chip_default from "./jl-chip.css.js";
9
10
  import { css } from "@jadis/core";
@@ -129,7 +130,7 @@ var JlChip = class extends JlElement {
129
130
  }
130
131
  main.setAttribute("role", "button");
131
132
  main.setAttribute("aria-pressed", String(this.selected.get()));
132
- main.toggleAttribute("aria-disabled", disabled);
133
+ setAriaFlag(main, "aria-disabled", disabled);
133
134
  if (disabled) {
134
135
  main.removeAttribute("tabindex");
135
136
  return;
@@ -5,7 +5,7 @@ import { oneOf } from "../lib/attributes.js";
5
5
  import { registerIcons } from "../lib/icons.js";
6
6
  import { CONTROL_SIZES } from "../lib/options.js";
7
7
  import { JlIcon } from "./jl-icon.js";
8
- import { setOrRemove } from "../lib/dom.js";
8
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
9
9
  import jl_input_default from "./jl-input.css.js";
10
10
  import { css } from "@jadis/core";
11
11
  import { Eye, EyeOff, X } from "lucide";
@@ -65,7 +65,7 @@ var JlInput = class extends JlFormControl {
65
65
  /** Draws the field in the danger colour, for an error the page found itself. */
66
66
  invalid = this.useChange(false, (value) => {
67
67
  this.reflect("invalid", value);
68
- this._refs.native.toggleAttribute("aria-invalid", value);
68
+ setAriaFlag(this._refs.native, "aria-invalid", value);
69
69
  }, { attribute: "invalid" });
70
70
  size = this.useChange("md", (value) => this.reflect("size", value), {
71
71
  attribute: "size",
@@ -193,7 +193,7 @@ var JlInput = class extends JlFormControl {
193
193
  }
194
194
  /** The × shows while an editable field holds text; its SVG is drawn the first time it does. */
195
195
  renderClear() {
196
- const editable = !this.disabled.get() && !this.readonly.get();
196
+ const editable = !this._refs.native.disabled && !this.readonly.get();
197
197
  const clear = this._refs.clear;
198
198
  clear.hidden = !(this.clearable.get() && editable && this.value.get() !== "");
199
199
  if (!clear.hidden) this._refs.clearIcon.name.set("x");
@@ -43,6 +43,7 @@ export declare class JlLink extends JlElement {
43
43
  templateHtml(): Node;
44
44
  templateCss(): string;
45
45
  onConnect(): void;
46
+ protected drawTexts(): void;
46
47
  /** An interactive link without an address fires `press`; one with an address leaves it to the browser. */
47
48
  private pressable;
48
49
  /** Followed by the app, the link is still a link to the keyboard and to screen readers. */
@@ -1,3 +1,4 @@
1
+ import { jlText } from "../lib/texts.js";
1
2
  import { BASE_STYLES } from "../styles/shared.js";
2
3
  import { JlElement } from "../base/jl-element.js";
3
4
  import { oneOf } from "../lib/attributes.js";
@@ -66,8 +67,7 @@ var JlLink = class extends JlElement {
66
67
  }),
67
68
  /* @__PURE__ */ jsx("span", {
68
69
  class: "new-tab sr-only",
69
- hidden: true,
70
- children: "(opens in a new tab)"
70
+ hidden: true
71
71
  })
72
72
  ]
73
73
  });
@@ -87,6 +87,9 @@ var JlLink = class extends JlElement {
87
87
  }
88
88
  });
89
89
  }
90
+ drawTexts() {
91
+ this._refs.newTab.textContent = jlText("opensInNewTab");
92
+ }
90
93
  /** An interactive link without an address fires `press`; one with an address leaves it to the browser. */
91
94
  pressable() {
92
95
  return this.interactive.get() && this.href.get() === "";
@@ -43,6 +43,8 @@ export declare class JlProgressRing extends JlElement {
43
43
  private readonly _svg;
44
44
  templateHtml(): Node;
45
45
  templateCss(): string;
46
+ /** The ring's name: its label, or what screen readers call a ring without one, in jlib's language. */
47
+ protected drawTexts(): void;
46
48
  private buildSvg;
47
49
  private renderGeometry;
48
50
  private renderValue;
@@ -1,3 +1,4 @@
1
+ import { jlText } from "../lib/texts.js";
1
2
  import { BASE_STYLES } from "../styles/shared.js";
2
3
  import { JlElement } from "../base/jl-element.js";
3
4
  import { oneOf } from "../lib/attributes.js";
@@ -13,7 +14,6 @@ var DEFAULT_MAX = 100;
13
14
  var DEFAULT_SIZE = 40;
14
15
  var DEFAULT_THICKNESS = 4;
15
16
  var PATH_LENGTH = 100;
16
- var DEFAULT_NAME = "Progress";
17
17
  /**
18
18
  * How far a task has gone, as a ring: `value` out of `max`, the percentage in its centre with `show-value`.
19
19
  * Without a value, the ring turns: the work has no known end. Fits in buttons, cards and table cells.
@@ -39,7 +39,7 @@ var JlProgressRing = class extends JlElement {
39
39
  this._refs.percent.hidden = !value;
40
40
  }, { attribute: "show-value" });
41
41
  /** The ring's name for screen readers: what is in progress. */
42
- label = this.useChange("", (value) => this._refs.ring.setAttribute("aria-label", value === "" ? DEFAULT_NAME : value), { attribute: "label" });
42
+ label = this.useChange("", () => this.drawTexts(), { attribute: "label" });
43
43
  _refs = this.useRefs((ref) => ({
44
44
  percent: ref(".percent"),
45
45
  ring: ref(".ring")
@@ -67,6 +67,10 @@ var JlProgressRing = class extends JlElement {
67
67
  templateCss() {
68
68
  return css`${BASE_STYLES}${jl_progress_ring_default}`;
69
69
  }
70
+ /** The ring's name: its label, or what screen readers call a ring without one, in jlib's language. */
71
+ drawTexts() {
72
+ this._refs.ring.setAttribute("aria-label", this.label.get() || jlText("progress"));
73
+ }
70
74
  buildSvg() {
71
75
  const root = svgElement("svg", {
72
76
  "aria-hidden": "true",
@@ -39,5 +39,6 @@ export declare class JlProgress extends JlElement {
39
39
  templateHtml(): Node;
40
40
  templateCss(): string;
41
41
  private render;
42
+ protected drawTexts(): void;
42
43
  private renderHeader;
43
44
  }
@@ -1,3 +1,4 @@
1
+ import { jlText } from "../lib/texts.js";
1
2
  import { BASE_STYLES } from "../styles/shared.js";
2
3
  import { JlElement } from "../base/jl-element.js";
3
4
  import { oneOf } from "../lib/attributes.js";
@@ -15,7 +16,6 @@ var PROGRESS_TONES = [
15
16
  ];
16
17
  var PROGRESS_SIZES = ["md", "sm"];
17
18
  var DEFAULT_MAX = 100;
18
- var DEFAULT_NAME = "Progress";
19
19
  /**
20
20
  * How far a task has gone, as a bar: `value` out of `max`. Without a value, the work has no known end and the bar
21
21
  * runs back and forth. A `label` above names it; `show-value` prints the percentage.
@@ -91,6 +91,9 @@ var JlProgress = class extends JlElement {
91
91
  this._refs.bar.style.width = `${percentOf(ratio)}%`;
92
92
  this._refs.percent.textContent = percentLabel(ratio);
93
93
  }
94
+ drawTexts() {
95
+ this.renderHeader();
96
+ }
94
97
  renderHeader() {
95
98
  const label = this.label.get();
96
99
  const track = this._refs.track;
@@ -99,7 +102,7 @@ var JlProgress = class extends JlElement {
99
102
  this._refs.header.hidden = label === "" && !this.showValue.get();
100
103
  if (label === "") {
101
104
  track.removeAttribute("aria-labelledby");
102
- track.setAttribute("aria-label", DEFAULT_NAME);
105
+ track.setAttribute("aria-label", jlText("progress"));
103
106
  return;
104
107
  }
105
108
  track.removeAttribute("aria-label");
@@ -72,4 +72,6 @@ export declare class JlRating extends JlFormControl {
72
72
  private renderValue;
73
73
  private renderValidity;
74
74
  private renderDisabled;
75
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
76
+ private drawDisabled;
75
77
  }
@@ -4,6 +4,7 @@ import { JlFormControl } from "../base/jl-form-control.js";
4
4
  import { clampedNumber, oneOf } from "../lib/attributes.js";
5
5
  import { iconElement, registerIcons } from "../lib/icons.js";
6
6
  import { CONTROL_SIZES } from "../lib/options.js";
7
+ import { setAriaFlag } from "../lib/dom.js";
7
8
  import { ratingAfterChoice, ratingAfterKey } from "../lib/rating.js";
8
9
  import jl_rating_default from "./jl-rating.css.js";
9
10
  import { css } from "@jadis/core";
@@ -34,7 +35,7 @@ var JlRating = class extends JlFormControl {
34
35
  /** Shows a score that cannot be changed: an average, a review. */
35
36
  readonly = this.useChange(false, (value) => {
36
37
  this.reflect("readonly", value);
37
- this._refs.slider.toggleAttribute("aria-readonly", value);
38
+ setAriaFlag(this._refs.slider, "aria-readonly", value);
38
39
  }, { attribute: "readonly" });
39
40
  icon = this.useChange(DEFAULT_ICON, () => this.renderIcons(), { attribute: "icon" });
40
41
  size = this.useChange("md", (value) => this.reflect("size", value), {
@@ -44,14 +45,14 @@ var JlRating = class extends JlFormControl {
44
45
  /** The name screen readers give the scale. */
45
46
  label = this.useChange("", () => this.renderLabel(), { attribute: "label" });
46
47
  required = this.useChange(false, (value) => {
47
- this._refs.slider.toggleAttribute("aria-required", value);
48
+ setAriaFlag(this._refs.slider, "aria-required", value);
48
49
  this.renderValidity();
49
50
  }, { attribute: "required" });
50
51
  disabled = this.useChange(false, (value) => this.renderDisabled(value), { attribute: "disabled" });
51
52
  /** Draws the empty icons in the danger colour, for an error the page found itself. */
52
53
  invalid = this.useChange(false, (value) => {
53
54
  this.reflect("invalid", value);
54
- this._refs.slider.toggleAttribute("aria-invalid", value);
55
+ setAriaFlag(this._refs.slider, "aria-invalid", value);
55
56
  }, { attribute: "invalid" });
56
57
  _state = {
57
58
  drawnIcon: "",
@@ -88,7 +89,7 @@ var JlRating = class extends JlFormControl {
88
89
  }
89
90
  setDisabledByForm(disabled) {
90
91
  this._state.formDisabled = disabled;
91
- this.whenRendered(() => this.renderDisabled(this.disabled.get()));
92
+ this.whenRendered(() => this.drawDisabled());
92
93
  }
93
94
  canChange() {
94
95
  return !this.readonly.get() && !this.disabled.get() && !this._state.formDisabled;
@@ -163,10 +164,14 @@ var JlRating = class extends JlFormControl {
163
164
  this.internals.setValidity({});
164
165
  }
165
166
  renderDisabled(disabled) {
166
- const off = disabled || this._state.formDisabled;
167
167
  this.reflect("disabled", disabled);
168
+ this.drawDisabled();
169
+ }
170
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
171
+ drawDisabled() {
172
+ const off = this.disabled.get() || this._state.formDisabled;
168
173
  this._refs.slider.tabIndex = off ? -1 : 0;
169
- this._refs.slider.toggleAttribute("aria-disabled", off);
174
+ setAriaFlag(this._refs.slider, "aria-disabled", off);
170
175
  }
171
176
  };
172
177
  JlRating.register();
@@ -1,3 +1,3 @@
1
1
  // src/atoms/jl-select.css?inline
2
- var jl_select_default = ":host{display:block}.control{padding:0;position:relative}.native{border-radius:inherit;text-overflow:ellipsis;cursor:pointer;appearance:none;padding:0 36px 0 12px}.native:disabled{cursor:not-allowed}:host([placeholder-shown]) .native{color:var(--jl-faint)}option,optgroup{background:var(--jl-surface);color:var(--jl-text)}.chevron{color:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease);position:absolute;right:12px}.native:open+.chevron{transform:rotate(180deg)}:host([disabled]) .chevron{color:var(--jl-faint)}@media (hover:hover) and (pointer:fine){@supports (appearance:base-select){.control{anchor-name:--frame}.native{appearance:base-select}.native::picker(select){appearance:base-select}.native{-webkit-line-clamp:1;padding-block:calc((var(--height,var(--jl-control-md)) - 2px - 1lh) / 2);overflow-clip-margin:content-box;-webkit-box-orient:vertical;display:-webkit-box;overflow:clip}.native::picker-icon{display:none}.native::picker(select){position-anchor:--frame;position-try-order:normal;box-sizing:border-box;min-inline-size:anchor-size(self-inline);border:1px solid var(--jl-line);border-radius:var(--jl-radius);background:var(--jl-surface);max-block-size:274px;color:var(--jl-text);box-shadow:var(--jl-shadow-lg);animation:jl-float-in var(--jl-fast) var(--jl-ease);margin-block:6px;padding:4px}optgroup{color:var(--jl-muted);font-size:var(--jl-font-xs);text-indent:calc(10px - .5em);padding-block-start:8px;font-weight:600}optgroup>option:first-of-type{margin-block-start:4px}option{box-sizing:border-box;border-radius:var(--jl-radius-xs);min-block-size:34px;font-size:var(--jl-font-md);text-indent:0;cursor:pointer;gap:10px;padding:6px 10px;font-weight:400;line-height:1.35}option:enabled:is(:hover,:focus-visible){background:var(--jl-surface-3);box-shadow:none}option:checked{font-weight:600}option:disabled{color:var(--jl-faint);cursor:not-allowed}option::checkmark{background:var(--jl-accent);content:\"\";order:1;width:14px;height:14px;margin-inline-start:auto;-webkit-mask:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E\") 50%/contain no-repeat;mask:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E\") 50%/contain no-repeat}}}";
2
+ var jl_select_default = ":host{display:block}.control{padding:0;position:relative}.native{border-radius:inherit;text-overflow:ellipsis;cursor:pointer;appearance:none;padding:0 36px 0 12px}.native:disabled{cursor:not-allowed}:host([placeholder-shown]) .native{color:var(--jl-muted)}option,optgroup{background:var(--jl-surface);color:var(--jl-text)}.chevron{color:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease);position:absolute;right:12px}.native:open+.chevron{transform:rotate(180deg)}:host([disabled]) .chevron{color:var(--jl-faint)}@media (hover:hover) and (pointer:fine){@supports (appearance:base-select){.control{anchor-name:--frame}.native{appearance:base-select}.native::picker(select){appearance:base-select}.native{-webkit-line-clamp:1;padding-block:calc((var(--height,var(--jl-control-md)) - 2px - 1lh) / 2);overflow-clip-margin:content-box;-webkit-box-orient:vertical;display:-webkit-box;overflow:clip}.native::picker-icon{display:none}.native::picker(select){position-anchor:--frame;position-try-order:normal;box-sizing:border-box;min-inline-size:anchor-size(self-inline);border:1px solid var(--jl-line);border-radius:var(--jl-radius);background:var(--jl-surface);max-block-size:274px;color:var(--jl-text);box-shadow:var(--jl-shadow-lg);animation:jl-float-in var(--jl-fast) var(--jl-ease);margin-block:6px;padding:4px}optgroup{color:var(--jl-muted);font-size:var(--jl-font-xs);text-indent:calc(10px - .5em);padding-block-start:8px;font-weight:600}optgroup>option:first-of-type{margin-block-start:4px}option{box-sizing:border-box;border-radius:var(--jl-radius-xs);min-block-size:34px;font-size:var(--jl-font-md);text-indent:0;cursor:pointer;gap:10px;padding:6px 10px;font-weight:400;line-height:1.35}option:enabled:is(:hover,:focus-visible){background:var(--jl-surface-3);box-shadow:none}option:checked{font-weight:600}option:disabled{color:var(--jl-faint);cursor:not-allowed}option::checkmark{background:var(--jl-accent);content:\"\";order:1;width:14px;height:14px;margin-inline-start:auto;-webkit-mask:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E\") 50%/contain no-repeat;mask:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E\") 50%/contain no-repeat}}}";
3
3
  export { jl_select_default as default };
@@ -52,11 +52,15 @@ export declare class JlSelect<Value extends string = string> extends JlFormContr
52
52
  private readonly _form;
53
53
  private _kept;
54
54
  private readonly _drawn;
55
+ private readonly _lightWatch;
55
56
  private readonly _refs;
56
57
  focus(options?: FocusOptions): void;
57
58
  templateHtml(): Node;
58
59
  templateCss(): string;
59
60
  onConnect(): void;
61
+ onDisconnect(): void;
62
+ /** Draws the page's options again when one came, left or changed. The select's own attributes are its inputs. */
63
+ private onLightChange;
60
64
  protected resetValue(): void;
61
65
  /** The browser calls it for a disabled fieldset and for the element's own disabled attribute, even before render. */
62
66
  protected setDisabledByForm(disabled: boolean): void;
@@ -4,7 +4,7 @@ import { asValue, jsonOf, oneOf, textOf } from "../lib/attributes.js";
4
4
  import { registerIcons } from "../lib/icons.js";
5
5
  import { CONTROL_SIZES } from "../lib/options.js";
6
6
  import { JlIcon } from "./jl-icon.js";
7
- import { setOrRemove } from "../lib/dom.js";
7
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
8
8
  import { groupOptions } from "../lib/option-groups.js";
9
9
  import jl_select_default from "./jl-select.css.js";
10
10
  import { css } from "@jadis/core";
@@ -68,11 +68,12 @@ var JlSelect = class extends JlFormControl {
68
68
  /** Draws the field in the danger colour, for an error the page found itself. */
69
69
  invalid = this.useChange(false, (value) => {
70
70
  this.reflect("invalid", value);
71
- this._refs.native.toggleAttribute("aria-invalid", value);
71
+ setAriaFlag(this._refs.native, "aria-invalid", value);
72
72
  }, { attribute: "invalid" });
73
73
  _form = { disabled: false };
74
74
  _kept;
75
75
  _drawn = { light: [] };
76
+ _lightWatch = new MutationObserver((records) => this.onLightChange(records));
76
77
  _refs = this.useRefs((ref) => ({ native: ref("select") }));
77
78
  focus(options) {
78
79
  this._refs.native.focus(options);
@@ -102,6 +103,21 @@ var JlSelect = class extends JlFormControl {
102
103
  this.events.emit("change", value);
103
104
  });
104
105
  this.renderOptions();
106
+ this._lightWatch.observe(this, {
107
+ attributes: true,
108
+ characterData: true,
109
+ childList: true,
110
+ subtree: true
111
+ });
112
+ }
113
+ onDisconnect() {
114
+ this._lightWatch.disconnect();
115
+ }
116
+ /** Draws the page's options again when one came, left or changed. The select's own attributes are its inputs. */
117
+ onLightChange(records) {
118
+ if (records.every((record) => record.target === this && record.type === "attributes")) return;
119
+ this._drawn.light = [];
120
+ this.renderOptions();
105
121
  }
106
122
  resetValue() {
107
123
  this.value.set(textOf(NO_VALUE)(this.getAttribute("value")));
@@ -1,3 +1,3 @@
1
1
  // src/atoms/jl-switch.css?inline
2
- var jl_switch_default = ":host{vertical-align:middle;--track-width:36px;--track-height:20px;--thumb:14px;display:inline-flex}:host([size=sm]){--track-width:28px;--track-height:16px;--thumb:10px}.wrap{color:var(--jl-text);font-size:var(--jl-font-md);cursor:pointer;align-items:flex-start;gap:10px;line-height:20px;display:inline-flex}:host([size=sm]) .wrap{font-size:var(--jl-font-sm)}.track{width:var(--track-width);height:var(--track-height);margin-top:calc((20px - var(--track-height)) / 2);flex:none;display:inline-flex;position:relative}.native{border:1px solid var(--jl-line-strong);border-radius:var(--jl-radius-pill);background:var(--jl-surface-3);width:100%;height:100%;cursor:inherit;appearance:none;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease), box-shadow var(--jl-fast) var(--jl-ease);margin:0;position:absolute;inset:0}.wrap:hover .native:not(:disabled){border-color:color-mix(in srgb, var(--jl-line-strong) 60%, var(--jl-text) 18%)}.native:checked{border-color:var(--jl-accent);background:var(--jl-accent)}.wrap:hover .native:checked:not(:disabled){border-color:var(--jl-accent-strong);background:var(--jl-accent-strong)}.thumb{top:calc((var(--track-height) - var(--thumb)) / 2);left:calc((var(--track-height) - var(--thumb)) / 2);width:var(--thumb);height:var(--thumb);background:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease), background var(--jl-fast) var(--jl-ease);border-radius:50%;position:absolute}.native:checked+.thumb{background:var(--jl-on-accent);transform:translateX(calc(var(--track-width) - var(--track-height)))}.text{align-self:baseline;gap:2px;display:grid}.label:empty,.description:empty{display:none}.description{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:18px}:host([disabled]) .wrap,:host(:disabled) .wrap{cursor:not-allowed;opacity:.5}";
2
+ var jl_switch_default = ":host{vertical-align:middle;--track-width:36px;--track-height:20px;--thumb:14px;display:inline-flex}:host([size=sm]){--track-width:28px;--track-height:16px;--thumb:10px}.wrap{color:var(--jl-text);font-size:var(--jl-font-md);cursor:pointer;align-items:flex-start;gap:10px;line-height:20px;display:inline-flex}:host([size=sm]) .wrap{font-size:var(--jl-font-sm)}.track{width:var(--track-width);height:var(--track-height);margin-top:calc((20px - var(--track-height)) / 2);flex:none;display:inline-flex;position:relative}.native{border:1px solid var(--jl-line-strong);border-radius:var(--jl-radius-pill);background:var(--jl-surface-3);width:100%;height:100%;cursor:inherit;appearance:none;transition:background var(--jl-fast) var(--jl-ease), border-color var(--jl-fast) var(--jl-ease), box-shadow var(--jl-fast) var(--jl-ease);margin:0;position:absolute;inset:0}.wrap:hover .native:not(:disabled){border-color:color-mix(in srgb, var(--jl-line-strong) 60%, var(--jl-text) 18%)}.native:checked{border-color:var(--jl-accent);background:var(--jl-accent)}.wrap:hover .native:checked:not(:disabled){border-color:var(--jl-accent-strong);background:var(--jl-accent-strong)}.thumb{top:calc((var(--track-height) - var(--thumb)) / 2);left:calc((var(--track-height) - var(--thumb)) / 2);width:var(--thumb);height:var(--thumb);background:var(--jl-muted);pointer-events:none;transition:transform var(--jl-fast) var(--jl-ease), background var(--jl-fast) var(--jl-ease);border-radius:50%;position:absolute}.native:checked+.thumb{background:var(--jl-on-accent);transform:translateX(calc(var(--track-width) - var(--track-height)))}@media (forced-colors:active){.native,.thumb{forced-color-adjust:none}.native{background:canvas;border-color:buttontext}.thumb{background:buttontext}.native:checked{background:highlight;border-color:highlight}.native:checked+.thumb{background:highlighttext}}.text{align-self:baseline;gap:2px;display:grid}.label:empty,.description:empty{display:none}.description{color:var(--jl-muted);font-size:var(--jl-font-sm);line-height:18px}:host([disabled]) .wrap,:host(:disabled) .wrap{cursor:not-allowed;opacity:.5}";
3
3
  export { jl_switch_default as default };
@@ -1,6 +1,6 @@
1
1
  import { BASE_STYLES, CONTROL_STYLES } from "../styles/shared.js";
2
2
  import { JlFormControl } from "../base/jl-form-control.js";
3
- import { setOrRemove } from "../lib/dom.js";
3
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
4
4
  import jl_textarea_default from "./jl-textarea.css.js";
5
5
  import { css } from "@jadis/core";
6
6
  import { jsx, jsxs } from "@jadis/core/jsx-runtime";
@@ -39,7 +39,7 @@ var JlTextarea = class extends JlFormControl {
39
39
  /** Draws the field in the danger colour, for an error the page found itself. */
40
40
  invalid = this.useChange(false, (value) => {
41
41
  this.reflect("invalid", value);
42
- this._refs.native.toggleAttribute("aria-invalid", value);
42
+ setAriaFlag(this._refs.native, "aria-invalid", value);
43
43
  }, { attribute: "invalid" });
44
44
  _form = { disabled: false };
45
45
  _refs = this.useRefs((ref) => ({
@@ -26,8 +26,9 @@ export declare abstract class JlFormControl extends JlElement {
26
26
  /**
27
27
  * Submits the form the field belongs to, as Enter in a native field of one line does. The native field inside the
28
28
  * shadow root belongs to no form, so the browser's own implicit submission never reaches the page's: each field of
29
- * one line calls this for an Enter it did not use itself. Nothing during a composition (an IME choosing a word), or
30
- * outside a form; `requestSubmit` checks the form's fields first, as a submit button does.
29
+ * one line calls this for an Enter it did not use itself. Nothing during a composition (an IME choosing a word),
30
+ * outside a form, or when the form's submit button cannot be pressed; `requestSubmit` checks the form's fields
31
+ * first, as a submit button does.
31
32
  */
32
33
  protected submitImplicitly(event: KeyboardEvent): void;
33
34
  /** Copies the native field's validity, so the form sees the same errors the browser would show. */
@@ -1,6 +1,12 @@
1
1
  import { JlElement } from "./jl-element.js";
2
2
  import { formInternals } from "../lib/internals.js";
3
3
  // src/base/jl-form-control.ts
4
+ var SUBMIT_BUTTONS = "button:not([type]), button[type=\"submit\"], input[type=\"submit\"], input[type=\"image\"], jl-button[type=\"submit\"]";
5
+ var UNPRESSABLE = ":disabled, [loading]";
6
+ /** The button Enter presses in a form: the first of its submit buttons, as the browser chooses it. */
7
+ var submitButtonOf = (form) => [...form.elements].find((element) => element.matches(SUBMIT_BUTTONS));
8
+ /** A button the browser takes as a submission's submitter: `jl-button` is not one, and submits without. */
9
+ var isNativeSubmitter = (button) => button instanceof HTMLButtonElement || button instanceof HTMLInputElement;
4
10
  /**
5
11
  * The base of the components a form submits: they take part in `<form>` like native fields (their `name`, their
6
12
  * value in `FormData`, `required`, reset, a disabled `<fieldset>`), through the element's internals.
@@ -36,12 +42,16 @@ var JlFormControl = class extends JlElement {
36
42
  /**
37
43
  * Submits the form the field belongs to, as Enter in a native field of one line does. The native field inside the
38
44
  * shadow root belongs to no form, so the browser's own implicit submission never reaches the page's: each field of
39
- * one line calls this for an Enter it did not use itself. Nothing during a composition (an IME choosing a word), or
40
- * outside a form; `requestSubmit` checks the form's fields first, as a submit button does.
45
+ * one line calls this for an Enter it did not use itself. Nothing during a composition (an IME choosing a word),
46
+ * outside a form, or when the form's submit button cannot be pressed; `requestSubmit` checks the form's fields
47
+ * first, as a submit button does.
41
48
  */
42
49
  submitImplicitly(event) {
43
- if (event.isComposing) return;
44
- this.internals.form?.requestSubmit();
50
+ const form = this.internals.form;
51
+ if (event.isComposing || form === null) return;
52
+ const button = submitButtonOf(form);
53
+ if (button?.matches(UNPRESSABLE)) return;
54
+ form.requestSubmit(isNativeSubmitter(button) ? button : void 0);
45
55
  }
46
56
  /** Copies the native field's validity, so the form sees the same errors the browser would show. */
47
57
  mirrorValidity(native) {
package/dist/index.d.ts CHANGED
@@ -66,6 +66,7 @@ export type * from './types/keycaps.types';
66
66
  export type * from './types/option-filter.types';
67
67
  export type * from './types/options.types';
68
68
  export type * from './types/pagination.types';
69
+ export type * from './types/press.types';
69
70
  export type * from './types/roving.types';
70
71
  export type * from './types/sparkline.types';
71
72
  export type * from './types/texts.types';
package/dist/lib/dom.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  /** Sets an attribute, or removes it when the value is empty. */
2
2
  export declare function setOrRemove(element: Element, name: string, value: string): void;
3
+ /**
4
+ * Says an ARIA state is on, or removes it: `aria-invalid`, `aria-required`, `aria-disabled`, `aria-busy`. A bare
5
+ * attribute, as `toggleAttribute` writes it (`aria-invalid=""`), is one browsers read as false.
6
+ */
7
+ export declare function setAriaFlag(element: Element, name: `aria-${string}`, on: boolean): void;
3
8
  /** A unique id within the page, for wiring `aria-controls`, `aria-labelledby` and the like inside a shadow root. */
4
9
  export declare function uniqueId(prefix: string): string;
5
10
  /** An SVG element with its attributes: JSX makes HTML elements only. */
package/dist/lib/dom.js CHANGED
@@ -7,6 +7,14 @@ function setOrRemove(element, name, value) {
7
7
  }
8
8
  element.setAttribute(name, value);
9
9
  }
10
+ var ARIA_TRUE = "true";
11
+ /**
12
+ * Says an ARIA state is on, or removes it: `aria-invalid`, `aria-required`, `aria-disabled`, `aria-busy`. A bare
13
+ * attribute, as `toggleAttribute` writes it (`aria-invalid=""`), is one browsers read as false.
14
+ */
15
+ function setAriaFlag(element, name, on) {
16
+ setOrRemove(element, name, on ? ARIA_TRUE : "");
17
+ }
10
18
  var sequence = { next: 0 };
11
19
  /** A unique id within the page, for wiring `aria-controls`, `aria-labelledby` and the like inside a shadow root. */
12
20
  function uniqueId(prefix) {
@@ -22,4 +30,4 @@ function svgElement(tag, attributes) {
22
30
  }
23
31
  /** Whether a click asks the browser for something of its own: a new tab or window, a download. */
24
32
  var isModifiedClick = (event) => event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || event.button !== 0;
25
- export { isModifiedClick, setOrRemove, svgElement, uniqueId };
33
+ export { isModifiedClick, setAriaFlag, setOrRemove, svgElement, uniqueId };