stimeo-ui 0.18.2 → 0.19.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/dist/controllers/alert_dialog_controller.js +246 -42
  4. data/dist/controllers/auto_submit_controller.js +26 -5
  5. data/dist/controllers/avatar_controller.js +29 -9
  6. data/dist/controllers/breadcrumb_controller.js +205 -17
  7. data/dist/controllers/bulk_select_controller.js +25 -4
  8. data/dist/controllers/calendar_controller.js +242 -7
  9. data/dist/controllers/carousel_controller.js +70 -15
  10. data/dist/controllers/character_counter_controller.js +26 -5
  11. data/dist/controllers/collapsible_controller.js +35 -8
  12. data/dist/controllers/combobox_controller.js +84 -20
  13. data/dist/controllers/command_palette_controller.js +296 -77
  14. data/dist/controllers/confirm_controller.js +225 -34
  15. data/dist/controllers/context_menu_controller.js +58 -29
  16. data/dist/controllers/currency_input_controller.js +1 -1
  17. data/dist/controllers/data_grid_controller.js +196 -9
  18. data/dist/controllers/date_range_picker_controller.js +25 -4
  19. data/dist/controllers/dialog_controller.js +252 -45
  20. data/dist/controllers/dismissible_controller.js +57 -11
  21. data/dist/controllers/drawer_controller.js +284 -58
  22. data/dist/controllers/dropdown_controller.js +63 -51
  23. data/dist/controllers/editable_controller.js +69 -6
  24. data/dist/controllers/empty_state_controller.js +187 -4
  25. data/dist/controllers/file_dropzone_controller.js +300 -12
  26. data/dist/controllers/filter_controller.js +194 -5
  27. data/dist/controllers/flash_controller.js +199 -12
  28. data/dist/controllers/focus_controller.js +195 -23
  29. data/dist/controllers/form_field_controller.js +65 -9
  30. data/dist/controllers/frame_loading_controller.js +25 -4
  31. data/dist/controllers/hover_card_controller.js +107 -38
  32. data/dist/controllers/input_mask_controller.js +1 -1
  33. data/dist/controllers/listbox_controller.js +94 -36
  34. data/dist/controllers/menu_controller.js +44 -23
  35. data/dist/controllers/menubar_controller.js +228 -46
  36. data/dist/controllers/meter_controller.js +25 -4
  37. data/dist/controllers/multi_select_controller.js +110 -42
  38. data/dist/controllers/nested_form_controller.js +258 -9
  39. data/dist/controllers/network_status_controller.js +25 -4
  40. data/dist/controllers/number_input_controller.js +26 -5
  41. data/dist/controllers/otp_controller.js +26 -5
  42. data/dist/controllers/overflow_menu_controller.js +183 -22
  43. data/dist/controllers/pagination_controller.js +179 -22
  44. data/dist/controllers/password_reveal_controller.js +25 -4
  45. data/dist/controllers/popover_controller.js +454 -34
  46. data/dist/controllers/progress_controller.js +25 -4
  47. data/dist/controllers/radio_group_controller.js +195 -40
  48. data/dist/controllers/rating_controller.js +58 -10
  49. data/dist/controllers/read_more_controller.js +191 -25
  50. data/dist/controllers/roving_controller.js +197 -6
  51. data/dist/controllers/scroll_area_controller.js +50 -12
  52. data/dist/controllers/scroll_visibility_controller.js +25 -4
  53. data/dist/controllers/scrollspy_controller.js +179 -3
  54. data/dist/controllers/separator_controller.js +25 -4
  55. data/dist/controllers/sidebar_controller.js +290 -93
  56. data/dist/controllers/skeleton_controller.js +25 -4
  57. data/dist/controllers/spinner_controller.js +25 -4
  58. data/dist/controllers/step_indicator_controller.js +181 -6
  59. data/dist/controllers/stepper_controller.js +188 -6
  60. data/dist/controllers/sticky_observer_controller.js +25 -4
  61. data/dist/controllers/submit_once_controller.js +25 -4
  62. data/dist/controllers/tabs_controller.js +189 -3
  63. data/dist/controllers/tags_input_controller.js +210 -9
  64. data/dist/controllers/theme_controller.js +192 -5
  65. data/dist/controllers/toast_controller.js +478 -16
  66. data/dist/controllers/toggle_group_controller.js +198 -35
  67. data/dist/controllers/toolbar_controller.js +198 -7
  68. data/dist/controllers/tooltip_controller.js +243 -45
  69. data/dist/controllers/tree_view_controller.js +200 -8
  70. data/dist/index.js +1764 -739
  71. data/lib/stimeo/ui/version.rb +1 -1
  72. metadata +2 -2
@@ -34,6 +34,180 @@ function hasModifierChord(event) {
34
34
  return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
35
35
  }
36
36
 
37
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
38
+ if (element.getAttribute(name) === value) return false;
39
+ beforeWrite?.();
40
+ if (value === null) element.removeAttribute(name);
41
+ else element.setAttribute(name, value);
42
+ return true;
43
+ }
44
+
45
+ function sharedRegistry(key, create) {
46
+ const symbol = Symbol.for(key);
47
+ const scope = globalThis;
48
+ const existing = scope[symbol];
49
+ if (existing !== void 0) return existing;
50
+ const registry2 = create();
51
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
52
+ return registry2;
53
+ }
54
+
55
+ var registry = sharedRegistry(
56
+ "stimeo-ui.attribute-lease.registry.v1",
57
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
58
+ );
59
+ function isAttributeValue(value) {
60
+ return value === null || typeof value === "string";
61
+ }
62
+ function readLeaseRecord(element, record) {
63
+ try {
64
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
65
+ if (!Array.isArray(parsed)) return void 0;
66
+ const [original, written, ...rest] = parsed;
67
+ const linked = rest[0] !== false;
68
+ const beneath = linked ? rest : rest.slice(1);
69
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
70
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
71
+ } catch {
72
+ return void 0;
73
+ }
74
+ }
75
+ function attributeStack(element, attribute) {
76
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
77
+ registry.stacks.set(element, byAttribute);
78
+ const known = byAttribute.get(attribute);
79
+ if (known) return known;
80
+ const found = [];
81
+ for (const record of registry.names.get(attribute) ?? []) {
82
+ const read = readLeaseRecord(element, record);
83
+ if (read) found.push({ ...read, record });
84
+ }
85
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
86
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
87
+ lease: null,
88
+ record,
89
+ written,
90
+ original,
91
+ linked: linked && index > 0
92
+ }));
93
+ byAttribute.set(attribute, stack);
94
+ return stack;
95
+ }
96
+ function findHold(stack, lease, record) {
97
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
98
+ }
99
+ var AttributeLease = class {
100
+ #attribute;
101
+ #record;
102
+ #base;
103
+ #preserveAuthor;
104
+ #held = /* @__PURE__ */ new Set();
105
+ constructor(attribute, owner, options = {}) {
106
+ this.#attribute = attribute;
107
+ this.#record = `data-${owner}-${attribute}-lease`;
108
+ this.#base = options.base === true;
109
+ this.#preserveAuthor = options.preserveAuthor === true;
110
+ const names = registry.names;
111
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
112
+ }
113
+ write(element, value, beforeWrite) {
114
+ const stack = attributeStack(element, this.#attribute);
115
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
116
+ this.#held.add(element);
117
+ const shows = !this.#covered(element, stack, hold);
118
+ hold.written = value;
119
+ this.#mark(element, stack);
120
+ if (shows) this.#reflect(element, value, beforeWrite);
121
+ }
122
+ adopt(element, options = {}) {
123
+ const known = registry.stacks.get(element)?.has(this.#attribute);
124
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
125
+ const stack = attributeStack(element, this.#attribute);
126
+ const hold = this.#take(stack);
127
+ if (!hold) return false;
128
+ const current = element.getAttribute(this.#attribute);
129
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
130
+ return false;
131
+ }
132
+ this.#held.add(element);
133
+ hold.original = current;
134
+ hold.linked = false;
135
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
136
+ if (!above.linked) break;
137
+ above.original = current;
138
+ }
139
+ this.#mark(element, stack);
140
+ return true;
141
+ }
142
+ return(element) {
143
+ const held = this.#held.delete(element);
144
+ const known = registry.stacks.get(element)?.has(this.#attribute);
145
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
146
+ const hold = this.#take(stack);
147
+ if (!hold) return false;
148
+ const carries = element.getAttribute(this.#attribute) === hold.written;
149
+ const owns = carries && !this.#covered(element, stack, hold);
150
+ const index = stack.indexOf(hold);
151
+ stack.splice(index, 1);
152
+ const above = stack[index];
153
+ if (above) above.linked &&= hold.linked;
154
+ this.#mark(element, stack);
155
+ if (!owns) return true;
156
+ const below = hold.linked ? stack[index - 1] : void 0;
157
+ this.#reflect(element, below ? below.written : hold.original);
158
+ return true;
159
+ }
160
+ returnAll() {
161
+ for (const element of Array.from(this.#held)) this.return(element);
162
+ }
163
+ #take(stack) {
164
+ const hold = findHold(stack, this, this.#record);
165
+ if (hold) hold.lease = this;
166
+ return hold;
167
+ }
168
+ #acquire(element, stack) {
169
+ const current = element.getAttribute(this.#attribute);
170
+ const top = stack.at(-1);
171
+ const bottom = stack[0];
172
+ const over = top?.written === current ? top : void 0;
173
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
174
+ const hold = {
175
+ lease: this,
176
+ record: this.#record,
177
+ written: current,
178
+ original: from ? from.original : current,
179
+ linked: !this.#base && over !== void 0
180
+ };
181
+ if (this.#base && bottom) {
182
+ bottom.linked = true;
183
+ stack.unshift(hold);
184
+ } else stack.push(hold);
185
+ return hold;
186
+ }
187
+ #covered(element, stack, hold) {
188
+ const current = element.getAttribute(this.#attribute);
189
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
190
+ }
191
+ #mark(element, stack) {
192
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
193
+ stack.forEach((hold, index) => {
194
+ const names = stack.slice(0, index).map((under) => under.record);
195
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
196
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
197
+ records.set(
198
+ hold.record,
199
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
200
+ );
201
+ });
202
+ for (const [name, recorded] of records) {
203
+ setAttributeIfChanged(element, name, recorded);
204
+ }
205
+ }
206
+ #reflect(element, value, beforeWrite) {
207
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
208
+ }
209
+ };
210
+
37
211
  function targetSelector(identifier, name) {
38
212
  return `[data-${identifier}-target~="${name}"]`;
39
213
  }
@@ -42,6 +216,9 @@ var TabsController = class extends Controller {
42
216
  static targets = ["tab", "panel", "list"];
43
217
  static actions = ["onKeydown", "select"];
44
218
  static events = ["change"];
219
+ #selected = new AttributeLease("aria-selected", this.identifier);
220
+ #tabindex = new AttributeLease("tabindex", this.identifier);
221
+ #hidden = new AttributeLease("hidden", this.identifier);
45
222
  #reporting = false;
46
223
  connect() {
47
224
  const preselected = this.tabTargets.findIndex(
@@ -53,6 +230,15 @@ var TabsController = class extends Controller {
53
230
  disconnect() {
54
231
  this.#reporting = false;
55
232
  }
233
+ tabTargetDisconnected(tab) {
234
+ if (this.scope.containsElement(tab) && this.tabTargets.includes(tab)) return;
235
+ this.#selected.return(tab);
236
+ this.#tabindex.return(tab);
237
+ }
238
+ panelTargetDisconnected(panel) {
239
+ if (this.scope.containsElement(panel) && this.panelTargets.includes(panel)) return;
240
+ this.#hidden.return(panel);
241
+ }
56
242
  select(source) {
57
243
  const { host, origin, reason } = actionSource(source);
58
244
  const tab = host?.closest(targetSelector(this.identifier, "tab"));
@@ -96,11 +282,11 @@ var TabsController = class extends Controller {
96
282
  const previous = tabs.findIndex((tab) => tab.getAttribute("aria-selected") === "true");
97
283
  tabs.forEach((tab, i) => {
98
284
  const selected = i === index;
99
- tab.setAttribute("aria-selected", selected ? "true" : "false");
100
- tab.tabIndex = selected ? 0 : -1;
285
+ this.#selected.write(tab, selected ? "true" : "false");
286
+ this.#tabindex.write(tab, selected ? "0" : "-1");
101
287
  });
102
288
  this.panelTargets.forEach((panel, i) => {
103
- panel.hidden = i !== index;
289
+ this.#hidden.write(panel, i !== index ? "" : null);
104
290
  });
105
291
  if (previous !== index && this.#reporting) {
106
292
  this.dispatch("change", {
@@ -32,6 +32,180 @@ function isReservedArrowChord(event, allow = []) {
32
32
  return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
33
33
  }
34
34
 
35
+ function setAttributeIfChanged(element, name, value, beforeWrite) {
36
+ if (element.getAttribute(name) === value) return false;
37
+ beforeWrite?.();
38
+ if (value === null) element.removeAttribute(name);
39
+ else element.setAttribute(name, value);
40
+ return true;
41
+ }
42
+
43
+ function sharedRegistry(key, create) {
44
+ const symbol = Symbol.for(key);
45
+ const scope = globalThis;
46
+ const existing = scope[symbol];
47
+ if (existing !== void 0) return existing;
48
+ const registry2 = create();
49
+ Object.defineProperty(globalThis, symbol, { value: registry2 });
50
+ return registry2;
51
+ }
52
+
53
+ var registry = sharedRegistry(
54
+ "stimeo-ui.attribute-lease.registry.v1",
55
+ () => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
56
+ );
57
+ function isAttributeValue(value) {
58
+ return value === null || typeof value === "string";
59
+ }
60
+ function readLeaseRecord(element, record) {
61
+ try {
62
+ const parsed = JSON.parse(element.getAttribute(record) ?? "null");
63
+ if (!Array.isArray(parsed)) return void 0;
64
+ const [original, written, ...rest] = parsed;
65
+ const linked = rest[0] !== false;
66
+ const beneath = linked ? rest : rest.slice(1);
67
+ if (!beneath.every((under) => typeof under === "string")) return void 0;
68
+ return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
69
+ } catch {
70
+ return void 0;
71
+ }
72
+ }
73
+ function attributeStack(element, attribute) {
74
+ const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
75
+ registry.stacks.set(element, byAttribute);
76
+ const known = byAttribute.get(attribute);
77
+ if (known) return known;
78
+ const found = [];
79
+ for (const record of registry.names.get(attribute) ?? []) {
80
+ const read = readLeaseRecord(element, record);
81
+ if (read) found.push({ ...read, record });
82
+ }
83
+ const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
84
+ const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
85
+ lease: null,
86
+ record,
87
+ written,
88
+ original,
89
+ linked: linked && index > 0
90
+ }));
91
+ byAttribute.set(attribute, stack);
92
+ return stack;
93
+ }
94
+ function findHold(stack, lease, record) {
95
+ return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
96
+ }
97
+ var AttributeLease = class {
98
+ #attribute;
99
+ #record;
100
+ #base;
101
+ #preserveAuthor;
102
+ #held = /* @__PURE__ */ new Set();
103
+ constructor(attribute, owner, options = {}) {
104
+ this.#attribute = attribute;
105
+ this.#record = `data-${owner}-${attribute}-lease`;
106
+ this.#base = options.base === true;
107
+ this.#preserveAuthor = options.preserveAuthor === true;
108
+ const names = registry.names;
109
+ names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
110
+ }
111
+ write(element, value, beforeWrite) {
112
+ const stack = attributeStack(element, this.#attribute);
113
+ const hold = this.#take(stack) ?? this.#acquire(element, stack);
114
+ this.#held.add(element);
115
+ const shows = !this.#covered(element, stack, hold);
116
+ hold.written = value;
117
+ this.#mark(element, stack);
118
+ if (shows) this.#reflect(element, value, beforeWrite);
119
+ }
120
+ adopt(element, options = {}) {
121
+ const known = registry.stacks.get(element)?.has(this.#attribute);
122
+ if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
123
+ const stack = attributeStack(element, this.#attribute);
124
+ const hold = this.#take(stack);
125
+ if (!hold) return false;
126
+ const current = element.getAttribute(this.#attribute);
127
+ if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
128
+ return false;
129
+ }
130
+ this.#held.add(element);
131
+ hold.original = current;
132
+ hold.linked = false;
133
+ for (const above of stack.slice(stack.indexOf(hold) + 1)) {
134
+ if (!above.linked) break;
135
+ above.original = current;
136
+ }
137
+ this.#mark(element, stack);
138
+ return true;
139
+ }
140
+ return(element) {
141
+ const held = this.#held.delete(element);
142
+ const known = registry.stacks.get(element)?.has(this.#attribute);
143
+ const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
144
+ const hold = this.#take(stack);
145
+ if (!hold) return false;
146
+ const carries = element.getAttribute(this.#attribute) === hold.written;
147
+ const owns = carries && !this.#covered(element, stack, hold);
148
+ const index = stack.indexOf(hold);
149
+ stack.splice(index, 1);
150
+ const above = stack[index];
151
+ if (above) above.linked &&= hold.linked;
152
+ this.#mark(element, stack);
153
+ if (!owns) return true;
154
+ const below = hold.linked ? stack[index - 1] : void 0;
155
+ this.#reflect(element, below ? below.written : hold.original);
156
+ return true;
157
+ }
158
+ returnAll() {
159
+ for (const element of Array.from(this.#held)) this.return(element);
160
+ }
161
+ #take(stack) {
162
+ const hold = findHold(stack, this, this.#record);
163
+ if (hold) hold.lease = this;
164
+ return hold;
165
+ }
166
+ #acquire(element, stack) {
167
+ const current = element.getAttribute(this.#attribute);
168
+ const top = stack.at(-1);
169
+ const bottom = stack[0];
170
+ const over = top?.written === current ? top : void 0;
171
+ const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
172
+ const hold = {
173
+ lease: this,
174
+ record: this.#record,
175
+ written: current,
176
+ original: from ? from.original : current,
177
+ linked: !this.#base && over !== void 0
178
+ };
179
+ if (this.#base && bottom) {
180
+ bottom.linked = true;
181
+ stack.unshift(hold);
182
+ } else stack.push(hold);
183
+ return hold;
184
+ }
185
+ #covered(element, stack, hold) {
186
+ const current = element.getAttribute(this.#attribute);
187
+ return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
188
+ }
189
+ #mark(element, stack) {
190
+ const records = /* @__PURE__ */ new Map([[this.#record, null]]);
191
+ stack.forEach((hold, index) => {
192
+ const names = stack.slice(0, index).map((under) => under.record);
193
+ const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
194
+ const marker = hold.linked || beneath.length === 0 ? [] : [false];
195
+ records.set(
196
+ hold.record,
197
+ hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
198
+ );
199
+ });
200
+ for (const [name, recorded] of records) {
201
+ setAttributeIfChanged(element, name, recorded);
202
+ }
203
+ }
204
+ #reflect(element, value, beforeWrite) {
205
+ setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
206
+ }
207
+ };
208
+
35
209
  function matchingPart(root, selector) {
36
210
  return root.matches(selector) ? root : root.querySelector(selector);
37
211
  }
@@ -48,8 +222,12 @@ function writeLabel(slot, text) {
48
222
 
49
223
  var RovingTabindex = class {
50
224
  #getItems;
51
- constructor(getItems) {
225
+ #write;
226
+ constructor(getItems, write = (item, tabindex) => {
227
+ item.tabIndex = tabindex;
228
+ }) {
52
229
  this.#getItems = getItems;
230
+ this.#write = write;
53
231
  }
54
232
  get activeIndex() {
55
233
  return this.#getItems().findIndex((item) => item.tabIndex === 0);
@@ -58,7 +236,7 @@ var RovingTabindex = class {
58
236
  const { focus = false } = options;
59
237
  const items = options.items ?? this.#getItems();
60
238
  items.forEach((item, i) => {
61
- item.tabIndex = i === index ? 0 : -1;
239
+ this.#write(item, i === index ? 0 : -1);
62
240
  });
63
241
  if (focus) items[index]?.focus();
64
242
  }
@@ -292,7 +470,7 @@ var CompositionTracker = class {
292
470
  this.#confirmedTarget = null;
293
471
  if (confirmed === null || confirmed !== event.target) return false;
294
472
  const inputType = event.inputType;
295
- return !inputType || isCompositionInputType(inputType);
473
+ return inputType ? isCompositionInputType(inputType) : event.isTrusted === true;
296
474
  }
297
475
  #release(target) {
298
476
  target.removeEventListener("compositionstart", this.#handleStart);
@@ -668,9 +846,10 @@ var TagsInputController = class _TagsInputController extends Controller {
668
846
  noun: "chip template"
669
847
  });
670
848
  #reconcile = new MorphRenderWatcher(() => this.#reconcileTags());
849
+ #rowInert = new AttributeLease("inert", this.identifier);
671
850
  #chipRow = new ChipRow({
672
851
  getDirectionElement: () => this.#chipDirectionElement,
673
- getItems: () => this.tagTargets,
852
+ getItems: () => this.#chips,
674
853
  getButton: (tag) => matchingPart(tag, `button${this.#rows.selector("remove")}`),
675
854
  onRemove: (index) => this.#removeAt(index),
676
855
  focusAfterEnd: () => this.#focusInput()
@@ -679,7 +858,7 @@ var TagsInputController = class _TagsInputController extends Controller {
679
858
  connect() {
680
859
  this.#rows.connect();
681
860
  if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
682
- if (this.hasTagsTarget) this.#chipRow.connect(this.tagsTarget);
861
+ this.#settleTagsRows();
683
862
  const tags = this.#values;
684
863
  this.#syncState(tags);
685
864
  this.#tagValues = tags;
@@ -700,6 +879,9 @@ var TagsInputController = class _TagsInputController extends Controller {
700
879
  this.#reconcile.schedule();
701
880
  }
702
881
  tagsTargetDisconnected(tags) {
882
+ if (!this.scope.containsElement(tags) || !this.tagsTargets.includes(tags)) {
883
+ this.#rowInert.return(tags);
884
+ }
703
885
  this.#chipRow.disconnect(tags);
704
886
  this.#reconcile.schedule();
705
887
  }
@@ -755,7 +937,7 @@ var TagsInputController = class _TagsInputController extends Controller {
755
937
  this.#reject(value, "empty");
756
938
  return;
757
939
  }
758
- if (this.#safeMax > 0 && this.tagTargets.length >= this.#safeMax) {
940
+ if (this.#safeMax > 0 && this.#chips.length >= this.#safeMax) {
759
941
  this.#reject(value, "max");
760
942
  return;
761
943
  }
@@ -783,7 +965,7 @@ var TagsInputController = class _TagsInputController extends Controller {
783
965
  return true;
784
966
  }
785
967
  #removeAt(index, focus = "neighbor") {
786
- const tag = this.tagTargets[index];
968
+ const tag = this.#chips[index];
787
969
  if (!tag) return;
788
970
  const value = tag.dataset.value ?? "";
789
971
  tag.remove();
@@ -796,6 +978,25 @@ var TagsInputController = class _TagsInputController extends Controller {
796
978
  }
797
979
  if (!this.#chipRow.focusAfterRemoval(index)) this.#focusInput();
798
980
  }
981
+ get #chips() {
982
+ if (!this.hasTagsTarget) return this.tagTargets;
983
+ const row = this.tagsTarget;
984
+ const selector = this.#rows.selector("tags");
985
+ return this.tagTargets.filter((tag) => tag.closest(selector) === row);
986
+ }
987
+ #settleTagsRows() {
988
+ const [current, ...behind] = this.tagsTargets;
989
+ if (!current) {
990
+ this.#chipRow.disconnect();
991
+ return;
992
+ }
993
+ this.#rowInert.return(current);
994
+ this.#chipRow.connect(current);
995
+ for (const row of behind) {
996
+ if (row.contains(document.activeElement)) this.#focusInput();
997
+ this.#rowInert.write(row, "");
998
+ }
999
+ }
799
1000
  get #chipDirectionElement() {
800
1001
  return this.hasTagsTarget ? this.tagsTarget : this.element;
801
1002
  }
@@ -827,7 +1028,7 @@ var TagsInputController = class _TagsInputController extends Controller {
827
1028
  return this.#moves.isLatest(token);
828
1029
  }
829
1030
  #reconcileTags() {
830
- if (this.hasTagsTarget) this.#chipRow.connect(this.tagsTarget);
1031
+ this.#settleTagsRows();
831
1032
  const tags = this.#values;
832
1033
  this.#syncState(tags);
833
1034
  const changed = !this.#sameTags(this.#tagValues, tags);
@@ -844,7 +1045,7 @@ var TagsInputController = class _TagsInputController extends Controller {
844
1045
  this.dispatch("reject", { detail: { value, reason } });
845
1046
  }
846
1047
  get #values() {
847
- return this.tagTargets.map((tag) => tag.dataset.value ?? "");
1048
+ return this.#chips.map((tag) => tag.dataset.value ?? "");
848
1049
  }
849
1050
  #sameTags(left, right) {
850
1051
  return left.length === right.length && left.every((value, index) => value === right[index]);