@syware/jlib 0.14.0 → 0.16.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 (113) hide show
  1. package/README.md +12 -8
  2. package/dist/all.js +2 -2
  3. package/dist/atoms/jl-avatar.d.ts +2 -0
  4. package/dist/atoms/jl-avatar.js +11 -6
  5. package/dist/atoms/jl-button.d.ts +6 -0
  6. package/dist/atoms/jl-button.js +22 -8
  7. package/dist/atoms/jl-chip.js +2 -1
  8. package/dist/atoms/jl-input.js +3 -3
  9. package/dist/atoms/jl-link.d.ts +1 -0
  10. package/dist/atoms/jl-link.js +5 -2
  11. package/dist/atoms/jl-progress-ring.d.ts +2 -0
  12. package/dist/atoms/jl-progress-ring.js +6 -2
  13. package/dist/atoms/jl-progress.d.ts +1 -0
  14. package/dist/atoms/jl-progress.js +5 -2
  15. package/dist/atoms/jl-rating.d.ts +2 -0
  16. package/dist/atoms/jl-rating.js +11 -6
  17. package/dist/atoms/jl-select.css.js +1 -1
  18. package/dist/atoms/jl-select.d.ts +4 -0
  19. package/dist/atoms/jl-select.js +18 -2
  20. package/dist/atoms/jl-switch.css.js +1 -1
  21. package/dist/atoms/jl-textarea.js +2 -2
  22. package/dist/base/jl-form-control.d.ts +3 -2
  23. package/dist/base/jl-form-control.js +14 -4
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +2 -2
  26. package/dist/lib/dom.d.ts +5 -0
  27. package/dist/lib/dom.js +9 -1
  28. package/dist/lib/download.js +10 -2
  29. package/dist/lib/floating.d.ts +5 -0
  30. package/dist/lib/floating.js +21 -2
  31. package/dist/lib/fuzzy.d.ts +3 -2
  32. package/dist/lib/fuzzy.js +15 -4
  33. package/dist/lib/modal.d.ts +24 -0
  34. package/dist/lib/modal.js +52 -0
  35. package/dist/lib/numeric.d.ts +5 -0
  36. package/dist/lib/numeric.js +11 -1
  37. package/dist/lib/option-filter.d.ts +2 -0
  38. package/dist/lib/option-filter.js +1 -1
  39. package/dist/lib/press.d.ts +11 -0
  40. package/dist/lib/press.js +31 -0
  41. package/dist/lib/table.js +12 -4
  42. package/dist/lib/texts-de.d.ts +12 -0
  43. package/dist/lib/texts-de.js +12 -0
  44. package/dist/lib/texts-fr.d.ts +12 -0
  45. package/dist/lib/texts-fr.js +12 -0
  46. package/dist/lib/texts.d.ts +12 -0
  47. package/dist/lib/texts.js +12 -0
  48. package/dist/molecules/jl-accordion-item.js +2 -1
  49. package/dist/molecules/jl-calendar.d.ts +4 -0
  50. package/dist/molecules/jl-calendar.js +16 -5
  51. package/dist/molecules/jl-chip-group.css.js +1 -1
  52. package/dist/molecules/jl-chip-group.js +3 -3
  53. package/dist/molecules/jl-code-block.css.js +1 -1
  54. package/dist/molecules/jl-combobox.d.ts +4 -0
  55. package/dist/molecules/jl-combobox.js +23 -11
  56. package/dist/molecules/jl-copy-button.css.js +1 -1
  57. package/dist/molecules/jl-copy-button.d.ts +11 -4
  58. package/dist/molecules/jl-copy-button.js +48 -22
  59. package/dist/molecules/jl-date-picker.d.ts +4 -0
  60. package/dist/molecules/jl-date-picker.js +18 -12
  61. package/dist/molecules/jl-field.d.ts +5 -1
  62. package/dist/molecules/jl-field.js +24 -5
  63. package/dist/molecules/jl-file-drop.css.js +1 -1
  64. package/dist/molecules/jl-file-drop.d.ts +4 -0
  65. package/dist/molecules/jl-file-drop.js +16 -8
  66. package/dist/molecules/jl-input-list.js +13 -6
  67. package/dist/molecules/jl-load-state.d.ts +8 -0
  68. package/dist/molecules/jl-load-state.js +33 -7
  69. package/dist/molecules/jl-menu.d.ts +21 -1
  70. package/dist/molecules/jl-menu.js +58 -6
  71. package/dist/molecules/jl-number-input.d.ts +2 -0
  72. package/dist/molecules/jl-number-input.js +12 -8
  73. package/dist/molecules/jl-radio-group.js +3 -2
  74. package/dist/molecules/jl-search.js +2 -2
  75. package/dist/molecules/jl-segmented.js +2 -2
  76. package/dist/molecules/jl-tabs.js +2 -2
  77. package/dist/molecules/jl-tag-input.css.js +1 -1
  78. package/dist/molecules/jl-tag-input.d.ts +4 -0
  79. package/dist/molecules/jl-tag-input.js +17 -9
  80. package/dist/molecules/jl-toast.js +8 -4
  81. package/dist/molecules/jl-tooltip.js +8 -2
  82. package/dist/organisms/jl-command-palette.css.js +1 -1
  83. package/dist/organisms/jl-command-palette.d.ts +2 -0
  84. package/dist/organisms/jl-command-palette.js +9 -3
  85. package/dist/organisms/jl-dialog.d.ts +3 -0
  86. package/dist/organisms/jl-dialog.js +13 -3
  87. package/dist/organisms/jl-drawer.d.ts +3 -0
  88. package/dist/organisms/jl-drawer.js +13 -3
  89. package/dist/organisms/jl-flow.d.ts +2 -0
  90. package/dist/organisms/jl-flow.js +29 -9
  91. package/dist/organisms/jl-side-nav.css.js +1 -1
  92. package/dist/organisms/jl-side-nav.d.ts +43 -9
  93. package/dist/organisms/jl-side-nav.js +164 -24
  94. package/dist/organisms/jl-table.css.js +1 -1
  95. package/dist/organisms/jl-table.d.ts +16 -3
  96. package/dist/organisms/jl-table.js +56 -18
  97. package/dist/organisms/jl-toaster.d.ts +13 -2
  98. package/dist/organisms/jl-toaster.js +47 -4
  99. package/dist/organisms/jl-tree.css.js +1 -1
  100. package/dist/organisms/jl-tree.d.ts +23 -4
  101. package/dist/organisms/jl-tree.js +74 -18
  102. package/dist/styles/base.css.js +1 -1
  103. package/dist/styles/control.css.js +1 -1
  104. package/dist/styles/tokens.css.js +1 -1
  105. package/dist/templates/jl-app-shell.css.js +1 -1
  106. package/dist/templates/jl-app-shell.js +2 -0
  107. package/dist/tokens.css +8 -3
  108. package/dist/types/jl-load-state.types.d.ts +7 -0
  109. package/dist/types/jl-side-nav.types.d.ts +5 -0
  110. package/dist/types/jl-table.types.d.ts +12 -0
  111. package/dist/types/jl-tree.types.d.ts +17 -0
  112. package/dist/types/press.types.d.ts +6 -0
  113. package/package.json +6 -4
@@ -84,6 +84,7 @@ var JlFileDrop = class extends JlFormControl {
84
84
  };
85
85
  _state = {
86
86
  depth: 0,
87
+ disabledByForm: false,
87
88
  files: [],
88
89
  refused: []
89
90
  };
@@ -108,7 +109,7 @@ var JlFileDrop = class extends JlFormControl {
108
109
  /** Opens the file chooser. */
109
110
  browse() {
110
111
  this.whenRendered(() => {
111
- if (!this.disabled.get()) this._refs.picker.click();
112
+ if (!this.isOff()) this._refs.picker.click();
112
113
  });
113
114
  }
114
115
  /**
@@ -198,12 +199,15 @@ var JlFileDrop = class extends JlFormControl {
198
199
  this.setFiles([]);
199
200
  }
200
201
  setDisabledByForm(disabled) {
201
- this.whenRendered(() => {
202
- this._refs.browse.disabled = disabled || this.disabled.get();
203
- });
202
+ this._state.disabledByForm = disabled;
203
+ this.whenRendered(() => this.drawDisabled());
204
+ }
205
+ /** Disabled by its own input, or by a `<fieldset disabled>` around it. */
206
+ isOff() {
207
+ return this.disabled.get() || this._state.disabledByForm;
204
208
  }
205
209
  canDrop(event) {
206
- return hasFiles(event) && !this.disabled.get();
210
+ return hasFiles(event) && !this.isOff();
207
211
  }
208
212
  onDragEnter(event) {
209
213
  if (!this.canDrop(event)) return;
@@ -224,7 +228,7 @@ var JlFileDrop = class extends JlFormControl {
224
228
  event.preventDefault();
225
229
  this._state.depth = 0;
226
230
  this.reflect("dragging", false);
227
- if (this.disabled.get()) return;
231
+ if (this.isOff()) return;
228
232
  this.take([...event.dataTransfer?.files ?? []]);
229
233
  }
230
234
  onPicked() {
@@ -276,7 +280,7 @@ var JlFileDrop = class extends JlFormControl {
276
280
  }
277
281
  renderFiles() {
278
282
  const files = this._state.files;
279
- const editable = !this.disabled.get();
283
+ const editable = !this.isOff();
280
284
  const locale = pageLocale();
281
285
  this._refs.files.hidden = files.length === 0;
282
286
  this._refs.files.replaceChildren(...files.map((file, index) => /* @__PURE__ */ jsxs("li", {
@@ -368,8 +372,12 @@ var JlFileDrop = class extends JlFormControl {
368
372
  this.internals.setValidity({});
369
373
  }
370
374
  renderDisabled(disabled) {
371
- this._refs.browse.disabled = disabled;
372
375
  this.reflect("disabled", disabled);
376
+ this.drawDisabled();
377
+ }
378
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
379
+ drawDisabled() {
380
+ this._refs.browse.disabled = this.isOff();
373
381
  this.renderFiles();
374
382
  }
375
383
  };
@@ -1,7 +1,7 @@
1
1
  import { jlText } from "../lib/texts.js";
2
2
  import { BASE_STYLES } from "../styles/shared.js";
3
3
  import { JlElement } from "../base/jl-element.js";
4
- import { clampedNumber, jsonOf, oneOf } from "../lib/attributes.js";
4
+ import { clampedNumber, jsonOf, oneOf, stringList } from "../lib/attributes.js";
5
5
  import { registerIcons } from "../lib/icons.js";
6
6
  import { JlButton } from "../atoms/jl-button.js";
7
7
  import { INPUT_TYPES, JlInput } from "../atoms/jl-input.js";
@@ -20,6 +20,13 @@ registerIcons({
20
20
  var NO_LIMIT = 0;
21
21
  var MAX_LIMIT = 1e3;
22
22
  /**
23
+ * Hears a row's control or button for as long as the row lives. `events.register` stops at the element's
24
+ * disconnection, and a list taken out of the page and put back keeps its rows: they heard nothing any more.
25
+ */
26
+ function hear(element, name, heard) {
27
+ element.addEventListener(name, (event) => heard(event.detail));
28
+ }
29
+ /**
23
30
  * A field with several values, each in its own row: typed in an input (or a text area when `multiline`), or picked
24
31
  * from `options`. People add a row and remove one; `max` caps how many. `values` holds those filled in, in their
25
32
  * order, and `change` fires with them. Put it in a `jl-field` for its label, hint and error.
@@ -30,7 +37,7 @@ var JlInputList = class extends JlElement {
30
37
  /** The values filled in, in their order; rows left empty are not among them. */
31
38
  values = this.useChange([], (values) => this.follow(values), {
32
39
  attribute: "values",
33
- parse: jsonOf([])
40
+ parse: stringList
34
41
  });
35
42
  /** The input of each row: text, a number, a date, a link… */
36
43
  type = this.useChange("text", () => this.drawRows(), {
@@ -133,7 +140,7 @@ var JlInputList = class extends JlElement {
133
140
  size: "sm",
134
141
  icon: "x"
135
142
  });
136
- remove.events.register("press", () => this.removeRow(index));
143
+ hear(remove, "press", () => this.removeRow(index));
137
144
  const row = {
138
145
  control,
139
146
  remove
@@ -165,13 +172,13 @@ var JlInputList = class extends JlElement {
165
172
  type: this.type.get(),
166
173
  value
167
174
  });
168
- input.events.register("input", onInput);
175
+ hear(input, "input", onInput);
169
176
  return input;
170
177
  },
171
178
  select: () => {
172
179
  const select = /* @__PURE__ */ jsx(JlSelect, { options: this.options.get() });
173
180
  select.value.set(value);
174
- select.events.register("change", onInput);
181
+ hear(select, "change", onInput);
175
182
  return select;
176
183
  },
177
184
  textarea: () => {
@@ -179,7 +186,7 @@ var JlInputList = class extends JlElement {
179
186
  value,
180
187
  autosize: true
181
188
  });
182
- area.events.register("input", onInput);
189
+ hear(area, "input", onInput);
183
190
  return area;
184
191
  }
185
192
  }[this.rowKind()]();
@@ -61,8 +61,16 @@ export declare class JlLoadState extends JlElement {
61
61
  * (a refresh), what is shown stays until the new data is there, and stays too if it fails. Resolves to whether it
62
62
  * worked: a refresh that fails says so only here, for the page to tell people. A load overtaken by a later one
63
63
  * (a search typed on, a poll during a reload) draws nothing and resolves true: the later one decides.
64
+ * @throws What `draw` or `isEmpty` throws: a mistake in the page, not a load that failed.
64
65
  */
65
66
  load<Value>(task: LoadTask<Value>): Promise<boolean>;
67
+ /** A first load that failed shows the error; a refresh that failed leaves what is shown. */
68
+ private showFailure;
69
+ /**
70
+ * Draws what was fetched. A `draw` that throws is a mistake in the page: people see the error state, and the
71
+ * exception goes on to the page and its console, where a load that failed would have hidden it.
72
+ */
73
+ private drawFetched;
66
74
  /** Tells the page the state changed: `state`, with the new one. */
67
75
  private announceState;
68
76
  /** Whether data is shown (the content or the empty state), which a refresh keeps. */
@@ -91,6 +91,17 @@ function leftLoading(state, signal) {
91
91
  }
92
92
  /** Waits for the components connected meanwhile to run their `onConnect`, a task after connecting. */
93
93
  var nextTask = () => new Promise((resolve) => setTimeout(resolve));
94
+ /** Runs a load's fetch. Only its failure is a load that failed: what `draw` throws afterwards is not caught here. */
95
+ async function fetchOf(task) {
96
+ try {
97
+ return {
98
+ failed: false,
99
+ value: await task.fetch()
100
+ };
101
+ } catch {
102
+ return { failed: true };
103
+ }
104
+ }
94
105
  /**
95
106
  * What a list or a page shows while its data comes: nothing for a moment, then a skeleton shaped like it; then the
96
107
  * data (the default slot), what to say when there is none (slot `empty`, a `jl-empty`), or, when it failed, what
@@ -152,22 +163,37 @@ var JlLoadState = class JlLoadState extends JlElement {
152
163
  * (a refresh), what is shown stays until the new data is there, and stays too if it fails. Resolves to whether it
153
164
  * worked: a refresh that fails says so only here, for the page to tell people. A load overtaken by a later one
154
165
  * (a search typed on, a poll during a reload) draws nothing and resolves true: the later one decides.
166
+ * @throws What `draw` or `isEmpty` throws: a mistake in the page, not a load that failed.
155
167
  */
156
168
  async load(task) {
157
169
  this._work.latest += 1;
158
170
  const ticket = this._work.latest;
159
171
  this._work.retry = () => this.load(task);
160
172
  if (!this.isShowing()) this.state.set("loading");
173
+ const fetched = await fetchOf(task);
174
+ if (ticket !== this._work.latest) return true;
175
+ if (fetched.failed) {
176
+ this.showFailure();
177
+ return false;
178
+ }
179
+ this.drawFetched(task, fetched.value);
180
+ return true;
181
+ }
182
+ /** A first load that failed shows the error; a refresh that failed leaves what is shown. */
183
+ showFailure() {
184
+ if (!this.isShowing()) this.state.set("error");
185
+ }
186
+ /**
187
+ * Draws what was fetched. A `draw` that throws is a mistake in the page: people see the error state, and the
188
+ * exception goes on to the page and its console, where a load that failed would have hidden it.
189
+ */
190
+ drawFetched(task, value) {
161
191
  try {
162
- const value = await task.fetch();
163
- if (ticket !== this._work.latest) return true;
164
192
  task.draw(value);
165
193
  this.state.set(task.isEmpty?.(value) === true ? "empty" : "ready");
166
- return true;
167
- } catch {
168
- if (ticket !== this._work.latest) return true;
169
- if (!this.isShowing()) this.state.set("error");
170
- return false;
194
+ } catch (error) {
195
+ this.state.set("error");
196
+ throw error;
171
197
  }
172
198
  }
173
199
  /** Tells the page the state changed: `state`, with the new one. */
@@ -4,6 +4,8 @@ import type { MenuItem } from '../types/jl-menu.types';
4
4
  /**
5
5
  * A list of actions that opens from its trigger (`slot="trigger"`, any button): on a press or with ArrowDown. Arrows,
6
6
  * Home, End and the first letter move through it; Enter chooses, Escape closes. `select` fires with the value.
7
+ * `showAt(x, y)` opens it at a point of the window instead, with no trigger: the menu of a row, where a right click
8
+ * asked for it.
7
9
  * Typed by its values, `JlMenu<'edit' | 'delete'>` takes actions of those values and gives `select` one of them:
8
10
  * a page handles them with a `Record<'edit' | 'delete', () => void>`, which misses none.
9
11
  */
@@ -33,6 +35,12 @@ export declare class JlMenu<Value extends string = string> extends JlElement {
33
35
  private readonly _refs;
34
36
  /** Opens the menu and focuses its first item. */
35
37
  show(): void;
38
+ /**
39
+ * Opens the menu at a point of the window, such as where the pointer is (`event.clientX`, `event.clientY`), and
40
+ * focuses its first item. It needs no trigger; give it a `label`. The focus goes back to what had it when the menu
41
+ * closes.
42
+ */
43
+ showAt(x: number, y: number): void;
36
44
  hide(): void;
37
45
  templateHtml(): Node;
38
46
  templateCss(): string;
@@ -57,11 +65,23 @@ export declare class JlMenu<Value extends string = string> extends JlElement {
57
65
  private actionOf;
58
66
  private onToggle;
59
67
  private focusIsInMenu;
60
- /** Keeps the menu by the trigger while it is open. */
68
+ /**
69
+ * The focus goes back to the trigger, or, for a menu opened at a point, to what had it then. The browser does that
70
+ * for a popover that closes, but not for one in a shadow root.
71
+ */
72
+ private returnFocus;
73
+ /** Keeps the menu by the trigger while it is open, or puts it at the point it was opened at. */
61
74
  private follow;
62
75
  private renderTrigger;
63
76
  private renderName;
64
77
  private renderItems;
78
+ /** The value of the item that holds the focus, when one does. */
79
+ private focusedValue;
80
+ /**
81
+ * Keeps the focus in a list drawn again while it is open: the item that held it is gone, and a focus fallen out of
82
+ * the menu closes it. The item of the same value takes it, else the first one to choose, else the menu.
83
+ */
84
+ private focusItemOf;
65
85
  private section;
66
86
  private entry;
67
87
  }
@@ -1,11 +1,11 @@
1
1
  import { BASE_STYLES, FLOATING_STYLES } from "../styles/shared.js";
2
2
  import { JlElement } from "../base/jl-element.js";
3
3
  import { jsonOf, oneOf } from "../lib/attributes.js";
4
- import { PLACEMENTS, followAnchor } from "../lib/floating.js";
4
+ import { PLACEMENTS, followAnchor, placeAtPoint } from "../lib/floating.js";
5
5
  import { JlIcon } from "../atoms/jl-icon.js";
6
6
  import { uniqueId } from "../lib/dom.js";
7
7
  import { firstIndex, lastIndex, letterIndex, stepIndex } from "../lib/roving.js";
8
- import { setTriggerAria } from "../lib/trigger.js";
8
+ import { deepActiveElement, setTriggerAria } from "../lib/trigger.js";
9
9
  import jl_menu_default from "./jl-menu.css.js";
10
10
  import { css } from "@jadis/core";
11
11
  import { Fragment, jsx, jsxs } from "@jadis/core/jsx-runtime";
@@ -44,6 +44,8 @@ var isTypeahead = (event) => event.key.length === 1 && event.key !== " " && !eve
44
44
  /**
45
45
  * A list of actions that opens from its trigger (`slot="trigger"`, any button): on a press or with ArrowDown. Arrows,
46
46
  * Home, End and the first letter move through it; Enter chooses, Escape closes. `select` fires with the value.
47
+ * `showAt(x, y)` opens it at a point of the window instead, with no trigger: the menu of a row, where a right click
48
+ * asked for it.
47
49
  * Typed by its values, `JlMenu<'edit' | 'delete'>` takes actions of those values and gives `select` one of them:
48
50
  * a page handles them with a `Record<'edit' | 'delete', () => void>`, which misses none.
49
51
  */
@@ -64,6 +66,10 @@ var JlMenu = class extends JlElement {
64
66
  /** The menu's name for screen readers; the trigger names it otherwise. */
65
67
  label = this.useChange("", () => this.renderName(), { attribute: "label" });
66
68
  _state = {
69
+ /** The point of the window the menu was opened at, when it was not opened by its trigger. */
70
+ at: void 0,
71
+ /** What had the focus when the menu opened at a point: the focus goes back to it. */
72
+ focusedBefore: null,
67
73
  following: new AbortController(),
68
74
  openAtPointerDown: false
69
75
  };
@@ -76,6 +82,22 @@ var JlMenu = class extends JlElement {
76
82
  show() {
77
83
  this.whenRendered(() => this.open(firstIndex));
78
84
  }
85
+ /**
86
+ * Opens the menu at a point of the window, such as where the pointer is (`event.clientX`, `event.clientY`), and
87
+ * focuses its first item. It needs no trigger; give it a `label`. The focus goes back to what had it when the menu
88
+ * closes.
89
+ */
90
+ showAt(x, y) {
91
+ this.whenRendered(() => {
92
+ const focused = deepActiveElement(document);
93
+ this.close();
94
+ this._state.focusedBefore = focused;
95
+ this.open(firstIndex, {
96
+ left: x,
97
+ top: y
98
+ });
99
+ });
100
+ }
79
101
  hide() {
80
102
  this.whenRendered(() => this.close());
81
103
  }
@@ -167,7 +189,7 @@ var JlMenu = class extends JlElement {
167
189
  if (event.key === "Escape") {
168
190
  event.preventDefault();
169
191
  this.close();
170
- this.triggerElement()?.focus();
192
+ this.returnFocus();
171
193
  return;
172
194
  }
173
195
  if (isTypeahead(event)) {
@@ -175,9 +197,10 @@ var JlMenu = class extends JlElement {
175
197
  this.focusItem(letterIndex(labels, this.enabledFlags(), from, event.key));
176
198
  }
177
199
  }
178
- open(focusFirst) {
200
+ open(focusFirst, at) {
179
201
  const menu = this._refs.menu;
180
202
  if (!this.isOpen()) {
203
+ this._state.at = at;
181
204
  this.renderItems();
182
205
  menu.showPopover();
183
206
  this.follow();
@@ -200,7 +223,7 @@ var JlMenu = class extends JlElement {
200
223
  if (!(item instanceof HTMLElement) || item.hasAttribute("aria-disabled")) return;
201
224
  const action = this.actionOf(item);
202
225
  this.close();
203
- this.triggerElement()?.focus();
226
+ this.returnFocus();
204
227
  if (action !== void 0) this.events.emit("select", action.value);
205
228
  }
206
229
  /** The action an item of the list draws. */
@@ -216,9 +239,23 @@ var JlMenu = class extends JlElement {
216
239
  const active = this.shadowRoot?.activeElement ?? null;
217
240
  return active !== null && this._refs.menu.contains(active);
218
241
  }
219
- /** Keeps the menu by the trigger while it is open. */
242
+ /**
243
+ * The focus goes back to the trigger, or, for a menu opened at a point, to what had it then. The browser does that
244
+ * for a popover that closes, but not for one in a shadow root.
245
+ */
246
+ returnFocus() {
247
+ const { at, focusedBefore } = this._state;
248
+ const back = at === void 0 ? this.triggerElement() : focusedBefore;
249
+ if (back instanceof HTMLElement) back.focus();
250
+ }
251
+ /** Keeps the menu by the trigger while it is open, or puts it at the point it was opened at. */
220
252
  follow() {
221
253
  this._state.following.abort();
254
+ const { at } = this._state;
255
+ if (this.isOpen() && at !== void 0) {
256
+ placeAtPoint(at, this._refs.menu);
257
+ return;
258
+ }
222
259
  const trigger = this.triggerElement();
223
260
  if (!this.isOpen() || trigger === null) return;
224
261
  this._state.following = new AbortController();
@@ -247,7 +284,22 @@ var JlMenu = class extends JlElement {
247
284
  const items = this.items.get();
248
285
  if (items === this._drawn.items) return;
249
286
  this._drawn.items = items;
287
+ const focused = this.focusedValue();
250
288
  this._refs.menu.replaceChildren(...sectionsOf(items).map((section) => this.section(section)));
289
+ if (focused !== void 0) this.focusItemOf(focused);
290
+ }
291
+ /** The value of the item that holds the focus, when one does. */
292
+ focusedValue() {
293
+ const active = this.shadowRoot?.activeElement;
294
+ return active instanceof HTMLElement && active.matches(ITEM_SELECTOR) ? active.dataset.value : void 0;
295
+ }
296
+ /**
297
+ * Keeps the focus in a list drawn again while it is open: the item that held it is gone, and a focus fallen out of
298
+ * the menu closes it. The item of the same value takes it, else the first one to choose, else the menu.
299
+ */
300
+ focusItemOf(value) {
301
+ const items = this.menuItems();
302
+ (items.find((item) => item.dataset.value === value) ?? items[0] ?? this._refs.menu).focus();
251
303
  }
252
304
  section(section) {
253
305
  const entries = section.entries.map((entry) => this.entry(entry));
@@ -75,6 +75,8 @@ export declare class JlNumberInput extends JlFormControl {
75
75
  private renderValue;
76
76
  private renderBounds;
77
77
  private renderDisabled;
78
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
79
+ private drawDisabled;
78
80
  /** A button that cannot move the value further is disabled. */
79
81
  private renderButtons;
80
82
  protected drawTexts(): void;
@@ -5,8 +5,8 @@ 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 "../atoms/jl-icon.js";
8
- import { setOrRemove } from "../lib/dom.js";
9
- import { clamp, parseNumber, stepValue } from "../lib/numeric.js";
8
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
9
+ import { clamp, parseNumber, parseTypedNumber, stepValue } from "../lib/numeric.js";
10
10
  import jl_number_input_default from "./jl-number-input.css.js";
11
11
  import { css } from "@jadis/core";
12
12
  import { Minus, Plus } from "lucide";
@@ -55,7 +55,7 @@ var JlNumberInput = class extends JlFormControl {
55
55
  parse: oneOf(CONTROL_SIZES, "md")
56
56
  });
57
57
  required = this.useChange(false, (value) => {
58
- this._refs.native.toggleAttribute("aria-required", value);
58
+ setAriaFlag(this._refs.native, "aria-required", value);
59
59
  this.reflect("required", value);
60
60
  this.renderValidity();
61
61
  }, { attribute: "required" });
@@ -63,7 +63,7 @@ var JlNumberInput = class extends JlFormControl {
63
63
  /** Draws the field in the danger colour, for an error the page found itself. */
64
64
  invalid = this.useChange(false, (value) => {
65
65
  this.reflect("invalid", value);
66
- this._refs.native.toggleAttribute("aria-invalid", value);
66
+ setAriaFlag(this._refs.native, "aria-invalid", value);
67
67
  }, { attribute: "invalid" });
68
68
  _state = { disabledByForm: false };
69
69
  _refs = this.useRefs((ref) => ({
@@ -132,7 +132,7 @@ var JlNumberInput = class extends JlFormControl {
132
132
  /** The browser calls it for a disabled fieldset and for the element's own disabled attribute, even before render. */
133
133
  setDisabledByForm(disabled) {
134
134
  this._state.disabledByForm = disabled;
135
- this.whenRendered(() => this.renderDisabled(this.disabled.get()));
135
+ this.whenRendered(() => this.drawDisabled());
136
136
  }
137
137
  onKey(event) {
138
138
  const action = (/* @__PURE__ */ new Map([
@@ -159,7 +159,7 @@ var JlNumberInput = class extends JlFormControl {
159
159
  /** The number typed so far, or the value when the text cannot be read. */
160
160
  typedNumber() {
161
161
  const text = this._refs.native.value;
162
- return text.trim() === "" ? null : parseNumber(text) ?? this.value.get();
162
+ return text.trim() === "" ? null : parseTypedNumber(text) ?? this.value.get();
163
163
  }
164
164
  /** Reads what was typed: empty gives null, unreadable text goes back to the value, a number is kept in bounds. */
165
165
  commitText() {
@@ -168,7 +168,7 @@ var JlNumberInput = class extends JlFormControl {
168
168
  this.commit(null);
169
169
  return;
170
170
  }
171
- const typed = parseNumber(text);
171
+ const typed = parseTypedNumber(text);
172
172
  if (typed === null) {
173
173
  this.renderValue(this.value.get());
174
174
  return;
@@ -197,8 +197,12 @@ var JlNumberInput = class extends JlFormControl {
197
197
  this.renderButtons();
198
198
  }
199
199
  renderDisabled(disabled) {
200
- this._refs.native.disabled = disabled || this._state.disabledByForm;
201
200
  this.reflect("disabled", disabled);
201
+ this.drawDisabled();
202
+ }
203
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
204
+ drawDisabled() {
205
+ this._refs.native.disabled = this.disabled.get() || this._state.disabledByForm;
202
206
  this.renderButtons();
203
207
  }
204
208
  /** A button that cannot move the value further is disabled. */
@@ -2,6 +2,7 @@ import { jlText } from "../lib/texts.js";
2
2
  import { BASE_STYLES } from "../styles/shared.js";
3
3
  import { JlFormControl } from "../base/jl-form-control.js";
4
4
  import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
5
+ import { setAriaFlag } from "../lib/dom.js";
5
6
  import { rovingIndex } from "../lib/roving.js";
6
7
  import jl_radio_group_default from "./jl-radio-group.css.js";
7
8
  import { css } from "@jadis/core";
@@ -58,7 +59,7 @@ var JlRadioGroup = class extends JlFormControl {
58
59
  }, { attribute: "legend" });
59
60
  required = this.useChange(false, (value) => {
60
61
  this.reflect("required", value);
61
- this._refs.group.toggleAttribute("aria-required", value);
62
+ setAriaFlag(this._refs.group, "aria-required", value);
62
63
  this.renderValidity();
63
64
  }, { attribute: "required" });
64
65
  disabled = this.useChange(false, (value) => {
@@ -184,7 +185,7 @@ var JlRadioGroup = class extends JlFormControl {
184
185
  radio.setAttribute("aria-disabled", String(disabled));
185
186
  radio.tabIndex = -1;
186
187
  }
187
- this._refs.group.toggleAttribute("aria-disabled", groupDisabled);
188
+ setAriaFlag(this._refs.group, "aria-disabled", groupDisabled);
188
189
  const stop = this.tabStop(radios, value);
189
190
  if (stop !== void 0) stop.tabIndex = 0;
190
191
  this.internals.setFormValue(value === NO_VALUE ? null : value);
@@ -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 "../atoms/jl-icon.js";
8
- import { setOrRemove } from "../lib/dom.js";
8
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
9
9
  import { JlSpinner } from "../atoms/jl-spinner.js";
10
10
  import { hasCommandModifier, matchesShortcut, parseShortcut, shortcutAria, shortcutLabels } from "../lib/key-shortcut.js";
11
11
  import jl_search_default from "./jl-search.css.js";
@@ -49,7 +49,7 @@ var JlSearch = class extends JlFormControl {
49
49
  });
50
50
  /** Shows a spinner in place of the search icon, while results are on their way. */
51
51
  loading = this.useChange(false, (value) => {
52
- this._refs.native.toggleAttribute("aria-busy", value);
52
+ setAriaFlag(this._refs.native, "aria-busy", value);
53
53
  this.reflect("loading", value);
54
54
  }, { attribute: "loading" });
55
55
  disabled = this.useChange(false, (value) => {
@@ -3,7 +3,7 @@ import { JlFormControl } from "../base/jl-form-control.js";
3
3
  import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
4
4
  import { CONTROL_SIZES } from "../lib/options.js";
5
5
  import { JlIcon } from "../atoms/jl-icon.js";
6
- import { setOrRemove } from "../lib/dom.js";
6
+ import { setAriaFlag, setOrRemove } from "../lib/dom.js";
7
7
  import { firstIndex, lastIndex, stepIndex } from "../lib/roving.js";
8
8
  import { followTarget } from "../lib/indicator.js";
9
9
  import jl_segmented_default from "./jl-segmented.css.js";
@@ -167,7 +167,7 @@ var JlSegmented = class extends JlFormControl {
167
167
  }
168
168
  renderDisabled() {
169
169
  const disabled = this.isDisabled();
170
- this._refs.group.toggleAttribute("aria-disabled", disabled);
170
+ setAriaFlag(this._refs.group, "aria-disabled", disabled);
171
171
  for (const segment of this.segments()) segment.disabled = disabled || segment.hasAttribute("data-disabled");
172
172
  }
173
173
  onKeydown(event) {
@@ -3,7 +3,7 @@ import { JlElement } from "../base/jl-element.js";
3
3
  import { oneOf } from "../lib/attributes.js";
4
4
  import { define } from "../lib/define.js";
5
5
  import { JlIcon } from "../atoms/jl-icon.js";
6
- import { setOrRemove, uniqueId } from "../lib/dom.js";
6
+ import { setAriaFlag, setOrRemove, uniqueId } from "../lib/dom.js";
7
7
  import { firstIndex, lastIndex, stepIndex } from "../lib/roving.js";
8
8
  import { followTarget } from "../lib/indicator.js";
9
9
  import { JlTabPanel } from "./jl-tab-panel.js";
@@ -144,7 +144,7 @@ var JlTabs = class extends JlElement {
144
144
  this.renderTabContent(tab, panel);
145
145
  tab.setAttribute("aria-selected", String(selected));
146
146
  tab.tabIndex = selected ? 0 : -1;
147
- tab.toggleAttribute("aria-disabled", isDisabled(panel));
147
+ setAriaFlag(tab, "aria-disabled", isDisabled(panel));
148
148
  if (panel.id === "") panel.id = uniqueId("jl-tab-panel");
149
149
  tab.ariaControlsElements = [panel];
150
150
  panel.toggleAttribute("selected", selected);
@@ -1,3 +1,3 @@
1
1
  // src/molecules/jl-tag-input.css?inline
2
- var jl_tag_input_default = ":host{--chip-height:calc(var(--height,var(--jl-control-md)) - 12px);min-width:0;display:block}.control{cursor:text;flex-wrap:wrap;gap:4px;padding:4px 6px}.tags{margin:0;padding:0;list-style:none;display:contents}.tag{max-width:100%;height:var(--chip-height);border:1px solid var(--jl-line);border-radius:var(--jl-radius-xs);background:var(--jl-surface-2);color:var(--jl-text);font-size:var(--jl-font-sm);cursor:default;align-items:center;gap:2px;padding:0 3px 0 8px;line-height:1;display:inline-flex}:host([size=sm]) .tag{font-size:var(--jl-font-xs);padding-left:6px}.tag.flash{animation:flash .6s var(--jl-ease)}.tag-text{text-overflow:ellipsis;white-space:nowrap;line-height:1.4;overflow:hidden}.tag-remove{width:18px;height:18px;color:var(--jl-faint);cursor:pointer;background:0 0;border:none;border-radius:4px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.tag-remove:hover,.tag-remove:focus-visible{background:var(--jl-surface-3);color:var(--jl-text)}.native{height:calc(var(--height,var(--jl-control-md)) - 10px);flex:1 0 80px;padding-left:6px}:host([disabled]) .tag{color:var(--jl-muted);padding-right:8px}:host([disabled]) .tag-remove{display:none}.popup{min-width:180px;padding:4px}.listbox{max-height:240px;margin:0;padding:0;list-style:none;position:relative;overflow-y:auto}.option{border-radius:var(--jl-radius-xs);color:var(--jl-text);font-size:var(--jl-font-md);white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none;padding:6px 10px;line-height:1.4}.option[aria-selected=true],.option:hover{background:var(--jl-surface-3)}mark{color:var(--jl-accent);background:0 0;font-weight:700}@keyframes flash{30%{border-color:var(--jl-accent-line);background:var(--jl-accent-soft);color:var(--jl-accent-strong)}}";
2
+ var jl_tag_input_default = ":host{--chip-height:calc(var(--height,var(--jl-control-md)) - 12px);min-width:0;display:block}.control{cursor:text;flex-wrap:wrap;gap:4px;padding:4px 6px}.tags{margin:0;padding:0;list-style:none;display:contents}.tag{max-width:100%;height:var(--chip-height);border:1px solid var(--jl-line);border-radius:var(--jl-radius-xs);background:var(--jl-surface-2);color:var(--jl-text);font-size:var(--jl-font-sm);cursor:default;align-items:center;gap:2px;padding:0 3px 0 8px;line-height:1;display:inline-flex}:host([size=sm]) .tag{font-size:var(--jl-font-xs);padding-left:6px}.tag.flash{animation:flash .6s var(--jl-ease)}.tag-text{text-overflow:ellipsis;white-space:nowrap;line-height:1.4;overflow:hidden}.tag-remove{width:18px;height:18px;color:var(--jl-faint);cursor:pointer;background:0 0;border:none;border-radius:4px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.tag-remove:hover,.tag-remove:focus-visible{background:var(--jl-surface-3);color:var(--jl-text)}.native{height:calc(var(--height,var(--jl-control-md)) - 10px);flex:1 0 80px;padding-left:6px}:host(:disabled) .tag{color:var(--jl-muted);padding-right:8px}:host(:disabled) .tag-remove{display:none}.popup{min-width:180px;padding:4px}.listbox{max-height:240px;margin:0;padding:0;list-style:none;position:relative;overflow-y:auto}.option{border-radius:var(--jl-radius-xs);color:var(--jl-text);font-size:var(--jl-font-md);white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none;padding:6px 10px;line-height:1.4}.option[aria-selected=true],.option:hover{background:var(--jl-surface-3)}mark{color:var(--jl-accent);background:0 0;font-weight:700}@keyframes flash{30%{border-color:var(--jl-accent-line);background:var(--jl-accent-soft);color:var(--jl-accent-strong)}}";
3
3
  export { jl_tag_input_default as default };
@@ -61,6 +61,8 @@ export declare class JlTagInput extends JlFormControl {
61
61
  onDisconnect(): void;
62
62
  protected resetValue(): void;
63
63
  protected setDisabledByForm(disabled: boolean): void;
64
+ /** Disabled by its own input, or by a `<fieldset disabled>` around it. */
65
+ private isOff;
64
66
  private onType;
65
67
  private onFieldKey;
66
68
  /** Enter adds the suggestion the arrows reached, or the typed text; in an empty field it submits the form. */
@@ -113,4 +115,6 @@ export declare class JlTagInput extends JlFormControl {
113
115
  private renderFormValue;
114
116
  private renderValidity;
115
117
  private renderDisabled;
118
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
119
+ private drawDisabled;
116
120
  }
@@ -6,7 +6,7 @@ import { followAnchor } from "../lib/floating.js";
6
6
  import { registerIcons } from "../lib/icons.js";
7
7
  import { CONTROL_SIZES } from "../lib/options.js";
8
8
  import { JlIcon } from "../atoms/jl-icon.js";
9
- import { setOrRemove, uniqueId } from "../lib/dom.js";
9
+ import { setAriaFlag, setOrRemove, uniqueId } from "../lib/dom.js";
10
10
  import { keepInView } from "../lib/keep-in-view.js";
11
11
  import { filterOptions, matchParts, nextEnabledIndex } from "../lib/option-filter.js";
12
12
  import { addTags, hasTag, hasTagSeparator, splitTags } from "../lib/tags.js";
@@ -56,7 +56,7 @@ var JlTagInput = class extends JlFormControl {
56
56
  parse: parseTextList
57
57
  });
58
58
  required = this.useChange(false, (value) => {
59
- this._refs.native.toggleAttribute("aria-required", value);
59
+ setAriaFlag(this._refs.native, "aria-required", value);
60
60
  this.reflect("required", value);
61
61
  this.renderValidity();
62
62
  }, { attribute: "required" });
@@ -64,7 +64,7 @@ var JlTagInput = class extends JlFormControl {
64
64
  /** Draws the field in the danger colour, for an error the page found itself. */
65
65
  invalid = this.useChange(false, (value) => {
66
66
  this.reflect("invalid", value);
67
- this._refs.native.toggleAttribute("aria-invalid", value);
67
+ setAriaFlag(this._refs.native, "aria-invalid", value);
68
68
  }, { attribute: "invalid" });
69
69
  size = this.useChange("md", (value) => this.reflect("size", value), {
70
70
  attribute: "size",
@@ -73,6 +73,7 @@ var JlTagInput = class extends JlFormControl {
73
73
  _listId = uniqueId("jl-tag-input-list");
74
74
  _state = {
75
75
  active: NONE,
76
+ disabledByForm: false,
76
77
  matches: [],
77
78
  opening: new AbortController()
78
79
  };
@@ -153,9 +154,12 @@ var JlTagInput = class extends JlFormControl {
153
154
  this.value.set(parseTextList(this.getAttribute("value")));
154
155
  }
155
156
  setDisabledByForm(disabled) {
156
- this.whenRendered(() => {
157
- this._refs.native.disabled = disabled || this.disabled.get();
158
- });
157
+ this._state.disabledByForm = disabled;
158
+ this.whenRendered(() => this.drawDisabled());
159
+ }
160
+ /** Disabled by its own input, or by a `<fieldset disabled>` around it. */
161
+ isOff() {
162
+ return this.disabled.get() || this._state.disabledByForm;
159
163
  }
160
164
  onType() {
161
165
  const native = this._refs.native;
@@ -253,7 +257,7 @@ var JlTagInput = class extends JlFormControl {
253
257
  removeAt(index) {
254
258
  const tags = this.value.get();
255
259
  const removed = tags[index];
256
- if (removed === void 0 || this.disabled.get()) return;
260
+ if (removed === void 0 || this.isOff()) return;
257
261
  const next = tags.filter((_, position) => position !== index);
258
262
  this.value.set(next);
259
263
  this.announce(jlText("removedNamed", { name: removed }));
@@ -275,7 +279,7 @@ var JlTagInput = class extends JlFormControl {
275
279
  focusLastTag() {
276
280
  const native = this._refs.native;
277
281
  const count = this.value.get().length;
278
- if (native.selectionStart !== 0 || native.selectionEnd !== 0 || count === 0 || this.disabled.get()) return false;
282
+ if (native.selectionStart !== 0 || native.selectionEnd !== 0 || count === 0 || this.isOff()) return false;
279
283
  this.focusTag(count - 1);
280
284
  return true;
281
285
  }
@@ -458,8 +462,12 @@ var JlTagInput = class extends JlFormControl {
458
462
  this.internals.setValidity({});
459
463
  }
460
464
  renderDisabled(disabled) {
461
- this._refs.native.disabled = disabled;
462
465
  this.reflect("disabled", disabled);
466
+ this.drawDisabled();
467
+ }
468
+ /** Without the attribute: the form says its state before the `disabled` input has taken the attribute's change. */
469
+ drawDisabled() {
470
+ this._refs.native.disabled = this.isOff();
463
471
  this.closeList();
464
472
  }
465
473
  };