tyrell-components 1.0.0-TC59 → 1.0.0-TC60

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.
@@ -9,18 +9,9 @@ import { computeAnchoredPosition, placementToAnchored } from "../utils/positioni
9
9
  import { isMobileTouch } from "../utils/mobile.js";
10
10
  import { TyComponent } from "../base/ty-component.js";
11
11
  import { CustomScrollbar, isCustomScrollbarEnabled, } from "../utils/custom-scrollbar.js";
12
- let elementIdCounter = 0;
13
- const elementIds = new WeakMap();
14
- function getElementHash(element) {
15
- let id = elementIds.get(element);
16
- if (id === undefined) {
17
- id = ++elementIdCounter;
18
- elementIds.set(element, id);
19
- }
20
- return id;
21
- }
22
12
  import { REQUIRED_ICON_SVG } from "../utils/icons.js";
23
13
  import { nativeMessage } from "../utils/validity.js";
14
+ let selectCount = 0;
24
15
  const SEARCH_AUTO_THRESHOLD = 7;
25
16
  const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
26
17
  <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
@@ -41,46 +32,35 @@ const CLEAR_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColo
41
32
  <line x1="18" y1="6" x2="6" y2="18"></line>
42
33
  <line x1="6" y1="6" x2="18" y2="18"></line>
43
34
  </svg>`;
35
+ function assign(slot, nodes) {
36
+ if (!slot)
37
+ return;
38
+ const current = slot.assignedNodes();
39
+ if (current.length === nodes.length && nodes.every((n, i) => current[i] === n))
40
+ return;
41
+ slot.assign(...nodes);
42
+ }
43
+ const NAMED_SLOTS = ["trigger", "start", "end", "loading"];
44
+ function isMarked(el) {
45
+ const attr = el.getAttribute("selected");
46
+ return attr !== null && !/^(false|0)$/i.test(attr.trim());
47
+ }
44
48
  export class TySelect extends TyComponent {
45
49
  constructor() {
46
50
  super();
47
- this._name = "";
48
- this._multiple = false;
49
- this._compact = false;
50
- this._placeholder = "Select...";
51
- this._label = "";
52
- this._disabled = false;
53
- this._readonly = false;
54
- this._required = false;
55
- this._clearable = true;
56
- this._externalSearch = false;
57
- this._allowCreate = false;
58
- this._createTransform = "none";
59
- this._notSearchable = false;
60
- this._loading = false;
61
- this._scrollLockId = null;
62
- this._size = DEFAULT_SIZE;
63
- this._availableLabel = "Available";
64
- this._selectedLabel = "Selected";
65
- this._noOptionsMessage = "No options available";
51
+ this._uid = ++selectCount;
66
52
  this._state = {
67
53
  open: false,
68
54
  search: "",
69
55
  highlightedIndex: -1,
70
56
  filteredTags: [],
71
- selectedValues: [],
72
57
  mode: "desktop",
73
58
  };
74
- this._stubClickHandler = null;
75
- this._tagClickHandler = null;
76
- this._searchInputHandler = null;
77
- this._blockSearchClick = null;
59
+ this._scrollLockId = null;
78
60
  this._keyboardHandler = null;
79
- this._debounce = 0;
80
61
  this._searchDebounceTimer = null;
81
62
  this._optionsScrollbar = null;
82
63
  this._childObserver = null;
83
- this._selectedClone = null;
84
64
  this._customFlavorSheet = null;
85
65
  this._ariaTrigger = null;
86
66
  this._ariaObserver = null;
@@ -89,51 +69,32 @@ ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
89
69
  ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
90
70
  }
91
71
  onConnect() {
92
- const shadow = this.shadowRoot;
93
- const dialogs = shadow.querySelectorAll("dialog");
94
- dialogs.forEach((dialog) => {
95
- if (dialog.open) {
96
- console.warn("⚠️ Found open dialog on connect, closing it");
97
- dialog.close();
98
- }
99
- });
72
+ this._childObserver = new MutationObserver((records) => {
73
+ if (records.some((r) => r.target !== this || r.type !== "attributes" || r.attributeName === "has-trigger")) {
100
74
  this.render();
101
- this.initializeState();
102
- this.updateFormValue();
103
- this._childObserver = new MutationObserver(() => {
104
- this.ensureOptionRoles();
105
- if (this._state.selectedValues.length > 0) {
106
- this.syncSelectedTags(this._state.selectedValues);
107
75
  }
108
- this.updateSearchVisibility();
109
- this.updateSelectionDisplay();
110
- this.updateMobileSelectedState();
111
76
  });
112
- this._childObserver.observe(this, { childList: true });
113
- this.ensureOptionRoles();
77
+ this._childObserver.observe(this, {
78
+ childList: true,
79
+ subtree: true,
80
+ characterData: true,
81
+ attributes: true,
82
+ attributeFilter: ["value", "label", "selected", "hidden", "filtered-out", "has-trigger"],
83
+ });
114
84
  this._syncCustomFlavor();
115
85
  if (!this._keyboardHandler) {
116
86
  this._keyboardHandler = this.handleKeyboard.bind(this);
117
87
  document.addEventListener("keydown", this._keyboardHandler, true);
118
88
  }
89
+ if (this._rendered)
90
+ this.render();
119
91
  }
120
92
  _syncCustomFlavor() {
121
93
  this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getProperty("flavor"), ({ base }) => selectCustomFlavorCss(base));
122
94
  }
123
95
  onDisconnect() {
124
- if (this._state.open) {
125
- if (this._state.mode === "mobile")
126
- this.closeMobileModal();
127
- else
128
- this.closeDropdown();
129
- }
130
- const shadow = this.shadowRoot;
131
- const dialogs = shadow.querySelectorAll("dialog");
132
- dialogs.forEach((dialog) => {
133
- if (dialog.open) {
134
- dialog.close();
135
- }
136
- });
96
+ if (this._state.open)
97
+ this.close();
137
98
  if (this._keyboardHandler) {
138
99
  document.removeEventListener("keydown", this._keyboardHandler, true);
139
100
  this._keyboardHandler = null;
@@ -143,106 +104,31 @@ clearTimeout(this._searchDebounceTimer);
143
104
  this._searchDebounceTimer = null;
144
105
  }
145
106
  this._destroyOptionsScrollbar();
146
- if (this._childObserver) {
147
- this._childObserver.disconnect();
107
+ this._childObserver?.disconnect();
148
108
  this._childObserver = null;
149
109
  }
150
- }
151
110
  onPropertiesChanged(changes) {
152
111
  for (const { name, newValue } of changes) {
153
112
  switch (name) {
154
- case "value":
155
- const selectedValues = this.parseValue(newValue);
156
- this._state.selectedValues = selectedValues;
157
- if (this.isConnected && this.shadowRoot) {
158
- this.syncSelectedTags(selectedValues);
159
- this.updateSelectionDisplay();
160
- this.updateMobileSelectedState();
161
- }
162
- break;
163
- case "name":
164
- this._name = newValue || "";
165
- break;
166
113
  case "flavor":
167
114
  this._syncCustomFlavor();
168
115
  break;
169
- case "multiple":
170
- this._multiple = newValue;
171
- if (!newValue && this._state.selectedValues.length > 1) {
172
- this.updateComponentValue([this._state.selectedValues[0]], false, "set", null);
116
+ case "multiple": {
117
+ const values = this.getSelectedValues();
118
+ if (!newValue && values.length > 1) {
119
+ this.updateComponentValue([values[0]]);
173
120
  }
174
121
  break;
175
- case "compact":
176
- this._compact = newValue;
177
- break;
178
- case "placeholder":
179
- this._placeholder = newValue || "Select...";
180
- if (this.isConnected && this.shadowRoot)
181
- this.updateSelectionDisplay();
182
- break;
183
- case "label":
184
- this._label = newValue || "";
185
- break;
186
- case "disabled":
187
- this._disabled = newValue;
188
- break;
189
- case "readonly":
190
- this._readonly = newValue;
191
- break;
192
- case "required":
193
- this._required = newValue;
194
- break;
195
- case "noClear":
196
- this._clearable = !newValue;
197
- if (this.isConnected && this.shadowRoot)
198
- this.updateSelectionDisplay();
199
- break;
200
- case "externalSearch":
201
- this._externalSearch = newValue;
202
- break;
203
- case "notSearchable":
204
- this._notSearchable = newValue;
205
- if (this.isConnected && this.shadowRoot)
206
- this.updateSearchVisibility();
207
- break;
208
- case "allowCreate":
209
- this._allowCreate = newValue;
210
- if (this.isConnected && this.shadowRoot)
211
- this.updateSearchVisibility();
212
- break;
213
- case "createTransform":
214
- this._createTransform = newValue;
215
- break;
216
- case "size":
217
- this._size = newValue;
218
- break;
219
- case "debounce":
220
- this._debounce = newValue;
221
- break;
222
- case "available-label":
223
- this._availableLabel = newValue || "Available";
224
- break;
225
- case "selected-label":
226
- this._selectedLabel = newValue || "Selected";
227
- break;
228
- case "no-options-message":
229
- this._noOptionsMessage = newValue || "No options available";
230
- break;
231
- case "loading":
232
- this._loading = newValue;
233
- this.applyLoadingState();
234
- break;
122
+ }
235
123
  }
236
124
  }
237
125
  }
238
126
  applyLoadingState() {
239
- const shadow = this.shadowRoot;
240
- if (!shadow)
241
- return;
242
- const svg = this._loading ? getLoaderSvg() : null;
243
- shadow.querySelectorAll(".dropdown-options-wrapper").forEach((wrapper) => {
244
- wrapper.classList.toggle("loading", this._loading);
245
- if (this._loading) {
127
+ const loading = this.getProperty("loading");
128
+ const svg = loading ? getLoaderSvg() : null;
129
+ this.shadowRoot.querySelectorAll(".dropdown-options-wrapper").forEach((wrapper) => {
130
+ wrapper.classList.toggle("loading", loading);
131
+ if (loading) {
246
132
  wrapper.setAttribute("aria-busy", "true");
247
133
  const spinner = wrapper.querySelector(".dropdown-loading-spinner");
248
134
  if (spinner && svg)
@@ -254,22 +140,21 @@ wrapper.removeAttribute("aria-busy");
254
140
  });
255
141
  }
256
142
  getFormValue() {
257
- const selectedValues = this._state.selectedValues;
258
- if (this._name && selectedValues.length > 0) {
259
- if (!this._multiple)
260
- return selectedValues[0];
261
- const formData = new FormData();
262
- selectedValues.forEach((value) => {
263
- formData.append(this._name, value);
264
- });
265
- return formData;
143
+ const name = this.name;
144
+ if (!name || this.externalSelection)
145
+ return null;
146
+ const selectedValues = this.getSelectedValues();
147
+ if (!this.multiple) {
148
+ return selectedValues[0] ?? "";
266
149
  }
267
- if (this._name && !this._multiple)
268
- return "";
150
+ if (selectedValues.length === 0)
269
151
  return null;
152
+ const formData = new FormData();
153
+ selectedValues.forEach((value) => formData.append(name, value));
154
+ return formData;
270
155
  }
271
156
  focus(options) {
272
- if (this._disabled)
157
+ if (this.disabled)
273
158
  return;
274
159
  const trigger = this.querySelector(':scope > [slot="trigger"]');
275
160
  if (trigger) {
@@ -285,44 +170,20 @@ else
285
170
  super.focus(options);
286
171
  }
287
172
  parseValue(value) {
288
- if (!value || typeof value !== "string" || value.trim() === "")
173
+ if (!value)
289
174
  return [];
290
175
  return value
291
176
  .split(",")
292
177
  .map((v) => v.trim())
293
178
  .filter((v) => v !== "");
294
179
  }
295
- initializeState() {
296
- const initialValue = this.getProperty("value") || "";
297
- if (initialValue) {
298
- const selectedValues = this.parseValue(initialValue);
299
- this._state.selectedValues = selectedValues;
300
- this.syncSelectedTags(selectedValues);
301
- this.updateSelectionDisplay();
302
- this.updateMobileSelectedState();
303
- }
304
- else {
305
- this.resolveDeclarativeSelection();
306
- }
307
- }
308
- resolveDeclarativeSelection() {
309
- if (this.getAttribute("value") || this._state.selectedValues.length > 0) {
310
- return;
311
- }
312
- const preSelectedTags = this.getTagElements()
313
- .filter((tag) => tag.hasAttribute("selected"))
314
- .map((tag) => this.getTagData(tag).value);
315
- if (preSelectedTags.length > 0) {
316
- this.updateComponentValue(preSelectedTags, false);
317
- return;
318
- }
319
- if (document.readyState === "loading") {
320
- document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
321
- this.resolveDeclarativeSelection(); }, { once: true });
322
- }
180
+ getSelectedValues() {
181
+ if (this.externalSelection)
182
+ return [];
183
+ return this.parseValue(this.getProperty("value"));
323
184
  }
324
185
  getTagElements() {
325
- return Array.from(this.querySelectorAll("ty-option:not([cloned]), ty-tag:not([cloned])"));
186
+ return Array.from(this.querySelectorAll("ty-option"));
326
187
  }
327
188
  getOfferedTags() {
328
189
  return this.getTagElements()
@@ -330,55 +191,66 @@ return this.getTagElements()
330
191
  .map((el) => this.getTagData(el));
331
192
  }
332
193
  getTagData(element) {
333
- const value = element.value ||
334
- element.getAttribute("value") ||
335
- element.textContent ||
336
- "";
194
+ const own = element.value;
195
+ const value = typeof own === "string"
196
+ ? own
197
+ : element.getAttribute("value") ?? (element.textContent || "").trim();
337
198
  const text = element.getAttribute("label") || element.textContent || "";
338
199
  return { value, text, element };
339
200
  }
340
- selectTag(tag) {
341
- tag.setAttribute("selected", "");
342
- }
343
- deselectTag(tag) {
344
- tag.removeAttribute("selected");
201
+ findOption(value) {
202
+ return this.getTagElements().find((el) => this.getTagData(el).value === value);
345
203
  }
346
- getSelectedValues() {
347
- return [...this._state.selectedValues];
348
- }
349
- syncSelectedTags(selectedValues) {
350
- const selectedSet = new Set(selectedValues);
351
- const tags = this.getTagElements();
352
- tags.forEach((tag) => {
353
- const tagValue = this.getTagData(tag).value;
354
- const shouldBeSelected = selectedSet.has(tagValue);
355
- const isSelected = tag.hasAttribute("selected");
356
- if (shouldBeSelected && !isSelected) {
357
- this.selectTag(tag);
204
+ paintOptions(shown) {
205
+ const external = this.externalSelection;
206
+ const selected = new Set(this.getSelectedValues());
207
+ for (const el of this.getTagElements()) {
208
+ el.checked = external
209
+ ? isMarked(el)
210
+ : selected.has(this.getTagData(el).value);
211
+ el.inTrigger = el === shown;
358
212
  }
359
- else if (!shouldBeSelected && isSelected) {
360
- this.deselectTag(tag);
361
213
  }
362
- tag.setAttribute("aria-selected", String(shouldBeSelected));
363
- });
214
+ shownOption() {
215
+ if (this.multiple || this._state.open)
216
+ return null;
217
+ const value = this.getSelectedValues()[0];
218
+ const option = value === undefined ? undefined : this.findOption(value);
219
+ return option && option.parentElement === this ? option : null;
364
220
  }
365
- ensureOptionRoles() {
366
- this.getTagElements().forEach((tag) => {
367
- if (!tag.hasAttribute("role"))
368
- tag.setAttribute("role", "option");
369
- if (!tag.hasAttribute("aria-selected"))
370
- tag.setAttribute("aria-selected", "false");
371
- });
221
+ assignSlots(shown) {
222
+ const shadow = this.shadowRoot;
223
+ const named = new Map(NAMED_SLOTS.map((n) => [n, []]));
224
+ const list = [];
225
+ for (const node of Array.from(this.childNodes)) {
226
+ if (node === shown)
227
+ continue;
228
+ if (node instanceof Element && named.has(node.slot))
229
+ named.get(node.slot).push(node);
230
+ else if (node instanceof Element || node instanceof Text)
231
+ list.push(node);
232
+ }
233
+ for (const [name, nodes] of named) {
234
+ assign(shadow.querySelector(`slot[name="${name}"]`), nodes);
235
+ }
236
+ assign(shadow.querySelector('slot[name="selected"]'), shown ? [shown] : []);
237
+ assign(shadow.querySelector("#options-slot"), list);
238
+ }
239
+ syncTrigger() {
240
+ const shown = this.shownOption();
241
+ this.assignSlots(shown);
242
+ this.paintOptions(shown);
243
+ this.updateSelectionDisplay(shown);
372
244
  }
373
245
  updateComponentValue(newValues, dispatchChange = false, action = "set", item = null, reveal = dispatchChange) {
374
246
  const oldValues = this.getSelectedValues();
375
- const valueStr = newValues.join(",");
376
- if (JSON.stringify(newValues.sort()) !== JSON.stringify(oldValues.sort())) {
377
- this.setProperty("value", valueStr);
378
- this.updateValidity();
247
+ const sameSet = [...newValues].sort().join("\u0000") === [...oldValues].sort().join("\u0000");
248
+ if (sameSet)
249
+ return;
250
+ this.setProperty("value", newValues.join(","));
379
251
  if (dispatchChange) {
380
252
  this.dispatchChangeEvent({
381
- value: this._multiple ? [...newValues] : (newValues[0] ?? null),
253
+ value: this.multiple ? [...newValues] : (newValues[0] ?? null),
382
254
  values: newValues,
383
255
  items: this.getSelectedItems(newValues),
384
256
  action,
@@ -388,7 +260,6 @@ if (reveal)
388
260
  this.revealValidity();
389
261
  }
390
262
  }
391
- }
392
263
  getSelectedItems(values) {
393
264
  const byValue = new Map(this.getTagElements().map((el) => [this.getTagData(el).value, el]));
394
265
  return values.map((value) => {
@@ -434,21 +305,12 @@ const positionBelow = pos.below;
434
305
  const x = pos.x - wrapPadding;
435
306
  const y = (positionBelow ? pos.topY : pos.bottomY) - wrapPadding;
436
307
  const width = popupWidth + wrapPadding + wrapPadding;
437
- this.style.setProperty("--dropdown-x", `${x}px`);
438
- this.style.setProperty("--dropdown-y", `${y}px`);
439
- this.style.setProperty("--dropdown-width", `${width}px`);
440
- this.style.setProperty("--dropdown-offset-x", "0px");
441
- this.style.setProperty("--dropdown-offset-y", "0px");
442
- this.style.setProperty("--dropdown-padding", `${wrapPadding}px`);
443
- if (positionBelow) {
444
- dialog.classList.add("position-below");
445
- dialog.classList.remove("position-above");
446
- }
447
- else {
448
- dialog.classList.add("position-above");
449
- dialog.classList.remove("position-below");
450
- }
451
- this.style.setProperty("--dropdown-direction", positionBelow ? "below" : "above");
308
+ dialog.style.setProperty("--dropdown-x", `${x}px`);
309
+ dialog.style.setProperty("--dropdown-y", `${y}px`);
310
+ dialog.style.setProperty("--dropdown-width", `${width}px`);
311
+ dialog.style.setProperty("--dropdown-padding", `${wrapPadding}px`);
312
+ dialog.classList.toggle("position-below", positionBelow);
313
+ dialog.classList.toggle("position-above", !positionBelow);
452
314
  }
453
315
  _setupOptionsScrollbar() {
454
316
  if (!isCustomScrollbarEnabled())
@@ -474,27 +336,47 @@ this._optionsScrollbar.destroy();
474
336
  this._optionsScrollbar = null;
475
337
  }
476
338
  }
339
+ open() {
340
+ if (this.disabled || this.readonly || this._state.open)
341
+ return;
342
+ if (this._state.mode === "mobile")
343
+ this.openMobileModal();
344
+ else
345
+ this.openDropdown();
346
+ }
347
+ close() {
348
+ if (this._state.mode === "mobile")
349
+ this.closeMobileModal();
350
+ else
351
+ this.closeDropdown();
352
+ }
353
+ lockPageScroll() {
354
+ this._scrollLockId = `select-${this.id || "anon"}-${this._uid}`;
355
+ lockScroll(this._scrollLockId);
356
+ }
357
+ unlockPageScroll() {
358
+ if (this._scrollLockId) {
359
+ unlockScroll(this._scrollLockId);
360
+ this._scrollLockId = null;
361
+ }
362
+ }
363
+ setExpanded(expanded) {
364
+ this.shadowRoot.querySelector(".select-stub")?.setAttribute("aria-expanded", String(expanded));
365
+ }
477
366
  openDropdown() {
478
367
  const shadow = this.shadowRoot;
479
368
  const dialog = shadow.querySelector(".dropdown-dialog");
480
369
  if (!dialog)
481
370
  return;
482
- const stubEl = shadow.querySelector(".select-stub");
483
- if (stubEl)
484
- stubEl.setAttribute("aria-expanded", "true");
485
- const lockId = `select-${this.id || "anon"}-${getElementHash(this)}`;
486
- this._scrollLockId = lockId;
487
- lockScroll(lockId);
371
+ this.setExpanded(true);
372
+ this.lockPageScroll();
373
+ this._state.open = true;
374
+ this.syncTrigger();
488
375
  dialog.showModal();
489
376
  this.calculatePosition();
490
377
  dialog.classList.add("open");
491
- this._state.open = true;
492
- const chevron = shadow.querySelector(".dropdown-chevron");
493
- if (chevron)
494
- chevron.classList.add("open");
495
- const searchChevron = shadow.querySelector(".dropdown-search-chevron");
496
- if (searchChevron)
497
- searchChevron.classList.add("open");
378
+ shadow.querySelector(".dropdown-chevron")?.classList.add("open");
379
+ shadow.querySelector(".dropdown-search-chevron")?.classList.add("open");
498
380
  this._state.filteredTags = this.getOfferedTags();
499
381
  this._state.highlightedIndex = -1;
500
382
  this.updateOptionsVisibility(true);
@@ -510,47 +392,17 @@ const shadow = this.shadowRoot;
510
392
  const dialog = shadow.querySelector(".dropdown-dialog");
511
393
  if (!dialog)
512
394
  return;
513
- const stubEl = shadow.querySelector(".select-stub");
514
- if (stubEl)
515
- stubEl.setAttribute("aria-expanded", "false");
395
+ this.setExpanded(false);
516
396
  this._destroyOptionsScrollbar();
517
- dialog.classList.remove("open");
518
- dialog.classList.remove("position-above");
519
- dialog.classList.remove("position-below");
397
+ dialog.classList.remove("open", "position-above", "position-below");
520
398
  dialog.close();
521
- if (this._scrollLockId) {
522
- unlockScroll(this._scrollLockId);
523
- this._scrollLockId = null;
524
- }
399
+ this.unlockPageScroll();
525
400
  this._state.open = false;
526
401
  this._state.highlightedIndex = -1;
527
- const chevron = shadow.querySelector(".dropdown-chevron");
528
- if (chevron)
529
- chevron.classList.remove("open");
530
- const searchChevron = shadow.querySelector(".dropdown-search-chevron");
531
- if (searchChevron)
532
- searchChevron.classList.remove("open");
533
- const hadQuery = this._state.search !== "";
534
- this._state.search = "";
535
- const searchInput = shadow.querySelector(".dropdown-search-input");
536
- if (searchInput) {
537
- searchInput.value = "";
538
- }
539
- if (this._externalSearch) {
540
- if (hadQuery) {
541
- if (this._searchDebounceTimer !== null) {
542
- clearTimeout(this._searchDebounceTimer);
543
- this._searchDebounceTimer = null;
544
- }
545
- this.fireSearchEvent("");
546
- }
547
- }
548
- else {
549
- const allTags = this.getTagElements().map((el) => this.getTagData(el));
550
- this._state.filteredTags = this.getOfferedTags();
551
- this.updateTagVisibility(allTags, allTags);
552
- this.clearHighlights(allTags);
553
- }
402
+ this.syncTrigger();
403
+ shadow.querySelector(".dropdown-chevron")?.classList.remove("open");
404
+ shadow.querySelector(".dropdown-search-chevron")?.classList.remove("open");
405
+ this.resetSearch(".dropdown-search-input");
554
406
  this.fireCloseEvent();
555
407
  }
556
408
  openMobileModal() {
@@ -558,22 +410,17 @@ const shadow = this.shadowRoot;
558
410
  const dialog = shadow.querySelector(".mobile-dialog");
559
411
  if (!dialog)
560
412
  return;
561
- const stubEl = shadow.querySelector(".select-stub");
562
- if (stubEl)
563
- stubEl.setAttribute("aria-expanded", "true");
564
- const lockId = `select-${this.id || "anon"}-${getElementHash(this)}`;
565
- this._scrollLockId = lockId;
566
- lockScroll(lockId);
413
+ this.setExpanded(true);
414
+ this.lockPageScroll();
415
+ this._state.open = true;
416
+ this.syncTrigger();
567
417
  dialog.showModal();
568
418
  dialog.getBoundingClientRect();
569
419
  dialog.classList.add("open");
570
- this._state.open = true;
571
420
  const tags = this.getTagElements().map((el) => this.getTagData(el));
572
421
  this._state.filteredTags = this.getOfferedTags();
573
422
  this.updateTagVisibility(tags, tags);
574
- requestAnimationFrame(() => {
575
- this.updateMobileSelectedState();
576
- });
423
+ requestAnimationFrame(() => this.updateMobileSelectedState());
577
424
  this.fireOpenEvent();
578
425
  }
579
426
  closeMobileModal() {
@@ -581,24 +428,23 @@ const shadow = this.shadowRoot;
581
428
  const dialog = shadow.querySelector(".mobile-dialog");
582
429
  if (!dialog)
583
430
  return;
584
- const stubEl = shadow.querySelector(".select-stub");
585
- if (stubEl)
586
- stubEl.setAttribute("aria-expanded", "false");
431
+ this.setExpanded(false);
587
432
  dialog.classList.remove("open");
588
433
  dialog.close();
589
- if (this._scrollLockId) {
590
- unlockScroll(this._scrollLockId);
591
- this._scrollLockId = null;
592
- }
434
+ this.unlockPageScroll();
593
435
  this._state.open = false;
594
436
  this._state.highlightedIndex = -1;
437
+ this.syncTrigger();
438
+ this.resetSearch(".mobile-search-input");
439
+ this.fireCloseEvent();
440
+ }
441
+ resetSearch(inputSelector) {
595
442
  const hadQuery = this._state.search !== "";
596
443
  this._state.search = "";
597
- const searchInput = shadow.querySelector(".mobile-search-input");
598
- if (searchInput) {
444
+ const searchInput = this.shadowRoot.querySelector(inputSelector);
445
+ if (searchInput)
599
446
  searchInput.value = "";
600
- }
601
- if (this._externalSearch) {
447
+ if (this.externalSearch) {
602
448
  if (hadQuery) {
603
449
  if (this._searchDebounceTimer !== null) {
604
450
  clearTimeout(this._searchDebounceTimer);
@@ -606,41 +452,38 @@ this._searchDebounceTimer = null;
606
452
  }
607
453
  this.fireSearchEvent("");
608
454
  }
455
+ return;
609
456
  }
610
- else {
611
- const allTags = this.getTagElements();
612
- allTags.forEach((el) => el.removeAttribute("filtered-out"));
613
- }
614
- this.fireCloseEvent();
457
+ const allTags = this.getTagElements().map((el) => this.getTagData(el));
458
+ this._state.filteredTags = this.getOfferedTags();
459
+ this.updateTagVisibility(allTags, allTags);
460
+ this.clearHighlights(allTags);
615
461
  }
616
462
  handleStubClick(e) {
617
463
  e.preventDefault();
618
464
  e.stopPropagation();
619
- if (this._disabled || this._readonly) {
620
- return;
621
- }
622
- this.openDropdown();
465
+ this.open();
623
466
  }
624
467
  handleClearClick(e) {
625
468
  e.preventDefault();
626
469
  e.stopPropagation();
627
- if (this._disabled || this._readonly) {
470
+ if (this.disabled || this.readonly) {
628
471
  return;
629
472
  }
630
473
  this.clear();
631
474
  this.revealValidity();
632
475
  }
633
476
  handleStubKeydown(e) {
634
- if (this._disabled || this._readonly || this._state.open)
477
+ if (this.disabled || this.readonly || this._state.open)
635
478
  return;
636
479
  if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
637
480
  e.preventDefault();
638
- this.openDropdown();
481
+ this.open();
639
482
  }
640
483
  }
641
484
  handleTagClick(e) {
642
485
  const target = e.target;
643
- const tag = target.closest("ty-option, ty-tag");
486
+ const tag = target.closest("ty-option");
644
487
  if (!tag || tag.hasAttribute("disabled"))
645
488
  return;
646
489
  e.preventDefault();
@@ -649,27 +492,35 @@ this.selectByTag(tag);
649
492
  }
650
493
  selectByTag(tag) {
651
494
  const tagValue = this.getTagData(tag).value;
652
- const currentValues = this.getSelectedValues();
653
- if (!this._multiple) {
654
- this.updateComponentValue([tagValue], true, "set", tagValue);
655
- if (this._state.mode === "mobile") {
656
- this.closeMobileModal();
657
- }
658
- else {
659
- this.closeDropdown();
495
+ if (this.externalSelection) {
496
+ const selected = !this.multiple || !isMarked(tag);
497
+ this.dispatchChangeEvent({
498
+ value: tagValue,
499
+ values: [],
500
+ items: [],
501
+ action: !this.multiple ? "set" : selected ? "add" : "remove",
502
+ item: tagValue,
503
+ selected,
504
+ });
505
+ if (!this.multiple)
506
+ this.close();
507
+ return;
660
508
  }
509
+ if (!this.multiple) {
510
+ this.updateComponentValue([tagValue], true, "set", tagValue);
511
+ this.close();
661
512
  return;
662
513
  }
514
+ const currentValues = this.getSelectedValues();
663
515
  if (currentValues.includes(tagValue)) {
664
- const newValues = currentValues.filter((v) => v !== tagValue);
665
- this.updateComponentValue(newValues, true, "remove", tagValue);
516
+ this.updateComponentValue(currentValues.filter((v) => v !== tagValue), true, "remove", tagValue);
666
517
  }
667
518
  else {
668
519
  this.updateComponentValue([...currentValues, tagValue], true, "add", tagValue);
669
520
  }
670
521
  }
671
522
  tryCreateFromSearch() {
672
- if (!this._allowCreate)
523
+ if (!this.allowCreate)
673
524
  return false;
674
525
  const query = (this._state.search || "").trim();
675
526
  if (!query)
@@ -683,7 +534,7 @@ this.selectByTag(existing.element);
683
534
  return true;
684
535
  }
685
536
  const rawLabel = query;
686
- const defaultValue = this._createTransform === "slug" ? slugify(rawLabel) : rawLabel;
537
+ const defaultValue = this.createTransform === "slug" ? slugify(rawLabel) : rawLabel;
687
538
  if (!defaultValue)
688
539
  return true;
689
540
  const detail = { value: defaultValue, label: rawLabel };
@@ -701,52 +552,44 @@ const option = document.createElement("ty-option");
701
552
  option.setAttribute("value", finalValue);
702
553
  option.textContent = rawLabel;
703
554
  this.appendChild(option);
704
- if (!this._multiple) {
705
- this.updateComponentValue([finalValue], true, "create", finalValue);
706
- if (this._state.mode === "mobile") {
707
- this.closeMobileModal();
708
- }
709
- else {
710
- this.closeDropdown();
555
+ if (this.externalSelection) {
556
+ this.selectByTag(option);
557
+ if (this.multiple)
558
+ this.clearSearchAfterCreate();
559
+ return true;
711
560
  }
561
+ if (!this.multiple) {
562
+ this.updateComponentValue([finalValue], true, "create", finalValue);
563
+ this.close();
712
564
  return true;
713
565
  }
714
- const currentValues = this.getSelectedValues();
715
- this.updateComponentValue([...currentValues, finalValue], true, "create", finalValue);
566
+ this.updateComponentValue([...this.getSelectedValues(), finalValue], true, "create", finalValue);
716
567
  this.clearSearchAfterCreate();
717
568
  return true;
718
569
  }
719
570
  clearSearchAfterCreate() {
720
571
  this._state.search = "";
721
572
  this._state.highlightedIndex = -1;
722
- const shadow = this.shadowRoot;
723
- if (!shadow)
724
- return;
725
- const desktopInput = shadow.querySelector(".dropdown-search-input");
726
- const mobileInput = shadow.querySelector(".mobile-search-input");
727
- if (desktopInput)
728
- desktopInput.value = "";
729
- if (mobileInput)
730
- mobileInput.value = "";
573
+ const input = this.searchInput();
574
+ if (input)
575
+ input.value = "";
731
576
  const allTags = this.getTagElements().map((el) => this.getTagData(el));
732
577
  this._state.filteredTags = this.getOfferedTags();
733
578
  this.updateTagVisibility(allTags, allTags);
734
579
  this.updateOptionsVisibility(true);
735
580
  this.clearHighlights(allTags);
736
581
  this.updateMobileSelectedState();
737
- (desktopInput ?? mobileInput)?.focus();
582
+ input?.focus();
738
583
  }
739
- blockSearchClick(e) {
740
- e.stopPropagation();
741
- e.preventDefault();
584
+ searchInput() {
585
+ return this.shadowRoot.querySelector(".dropdown-search-input, .mobile-search-input");
742
586
  }
743
587
  handleSearchInput(e) {
744
588
  if (this._state.mode === "mobile")
745
589
  this.expandMobileSection("available");
746
- const target = e.target;
747
- const query = target.value;
590
+ const query = e.target.value;
748
591
  this._state.search = query;
749
- if (this._externalSearch) {
592
+ if (this.externalSearch) {
750
593
  this.dispatchSearchEvent(query);
751
594
  return;
752
595
  }
@@ -762,54 +605,36 @@ this.clearHighlights(allTags);
762
605
  handleKeyboard(e) {
763
606
  if (!this._state.open)
764
607
  return;
765
- const shadow = this.shadowRoot;
766
- const searchInput = shadow.querySelector(".dropdown-search-input");
767
- const target = e.target;
768
- const shouldHandle = target === searchInput || document.activeElement !== searchInput;
769
- if (!shouldHandle)
770
- return;
771
608
  const filteredTags = this._state.filteredTags;
772
- const tagsCount = filteredTags.length;
773
- const currentHighlightedIndex = this._state.highlightedIndex;
609
+ const highlighted = this._state.highlightedIndex;
774
610
  switch (e.key) {
775
611
  case "Escape":
776
612
  e.preventDefault();
777
613
  e.stopPropagation();
778
- if (this._state.mode === "mobile") {
779
- this.closeMobileModal();
780
- }
781
- else {
782
- this.closeDropdown();
783
- }
614
+ this.close();
784
615
  this.focus();
785
616
  break;
786
617
  case "Enter":
787
618
  e.preventDefault();
788
619
  e.stopPropagation();
789
- if (currentHighlightedIndex >= 0 &&
790
- currentHighlightedIndex < tagsCount) {
791
- this.selectByTag(filteredTags[currentHighlightedIndex].element);
620
+ if (highlighted >= 0 && highlighted < filteredTags.length) {
621
+ this.selectByTag(filteredTags[highlighted].element);
792
622
  }
793
623
  else {
794
624
  this.tryCreateFromSearch();
795
625
  }
796
626
  break;
797
627
  case "ArrowUp":
628
+ case "ArrowDown": {
798
629
  e.preventDefault();
799
630
  e.stopPropagation();
800
- const newIndexUp = this.nextEnabledTagIndex(filteredTags, currentHighlightedIndex, -1);
801
- this._state.highlightedIndex = newIndexUp;
802
- this.highlightTag(filteredTags, newIndexUp);
803
- break;
804
- case "ArrowDown":
805
- e.preventDefault();
806
- e.stopPropagation();
807
- const newIndexDown = this.nextEnabledTagIndex(filteredTags, currentHighlightedIndex, 1);
808
- this._state.highlightedIndex = newIndexDown;
809
- this.highlightTag(filteredTags, newIndexDown);
631
+ const next = this.nextEnabledTagIndex(filteredTags, highlighted, e.key === "ArrowDown" ? 1 : -1);
632
+ this._state.highlightedIndex = next;
633
+ this.highlightTag(filteredTags, next);
810
634
  break;
811
635
  }
812
636
  }
637
+ }
813
638
  nextEnabledTagIndex(tags, fromIndex, direction) {
814
639
  const count = tags.length;
815
640
  if (count === 0)
@@ -839,8 +664,7 @@ element.toggleAttribute("filtered-out", !visibleValues.has(value));
839
664
  });
840
665
  }
841
666
  updateOptionsVisibility(hasOptions) {
842
- const shadow = this.shadowRoot;
843
- const options = shadow.querySelector(".dropdown-options");
667
+ const options = this.shadowRoot.querySelector(".dropdown-options");
844
668
  if (options) {
845
669
  options.style.display = hasOptions ? "" : "none";
846
670
  }
@@ -867,11 +691,12 @@ if (this._searchDebounceTimer !== null) {
867
691
  clearTimeout(this._searchDebounceTimer);
868
692
  this._searchDebounceTimer = null;
869
693
  }
870
- if (this._debounce > 0) {
694
+ const debounce = this.getProperty("debounce");
695
+ if (debounce > 0) {
871
696
  this._searchDebounceTimer = window.setTimeout(() => {
872
697
  this.fireSearchEvent(query);
873
698
  this._searchDebounceTimer = null;
874
- }, this._debounce);
699
+ }, debounce);
875
700
  }
876
701
  else {
877
702
  this.fireSearchEvent(query);
@@ -891,7 +716,7 @@ fireOpenEvent() {
891
716
  this.dispatchEvent(new CustomEvent("open", {
892
717
  detail: { mode: this._state.mode, element: this },
893
718
  }));
894
- if (this._externalSearch) {
719
+ if (this.externalSearch) {
895
720
  this.fireSearchEvent("");
896
721
  }
897
722
  }
@@ -908,39 +733,51 @@ cancelable: true,
908
733
  }));
909
734
  }
910
735
  render() {
911
- this._state.mode = isMobileTouch() ? "mobile" : "desktop";
912
- if (this._state.mode === "mobile") {
913
- this.renderMobile();
914
- }
915
- else {
916
- this.renderDesktop();
917
- }
736
+ if (!this.shadowRoot.querySelector(".select-container"))
737
+ this.build();
738
+ this.syncTrigger();
739
+ if (this._state.open)
740
+ this.refreshOpenList();
918
741
  this.updateSearchVisibility();
919
742
  this.applyLoadingState();
920
743
  this.syncFieldChrome();
744
+ this.syncTriggerSlot();
745
+ this.updateMobileSelectedState();
746
+ this.updateFormValue();
921
747
  this.updateValidity();
922
748
  }
749
+ refreshOpenList() {
750
+ const offered = this.getOfferedTags();
751
+ const filtered = this.externalSearch ? offered : this.filterTags(offered, this._state.search);
752
+ if (!this.externalSearch) {
753
+ this.updateTagVisibility(filtered, this.getTagElements().map((el) => this.getTagData(el)));
754
+ }
755
+ const highlighted = this._state.filteredTags[this._state.highlightedIndex]?.element;
756
+ this._state.filteredTags = filtered;
757
+ this._state.highlightedIndex = filtered.findIndex((t) => t.element === highlighted);
758
+ }
923
759
  syncFieldChrome() {
924
760
  const shadow = this.shadowRoot;
925
- const container = shadow?.querySelector(".select-container");
926
- if (!shadow || !container)
927
- return;
928
- const labelId = `select-label-${getElementHash(this)}`;
761
+ const container = shadow.querySelector(".select-container");
762
+ const labelText = this.label;
763
+ const required = this.required;
764
+ const disabled = this.disabled;
765
+ const labelId = `select-label-${this._uid}`;
929
766
  let label = container.querySelector(":scope > .ty-field-label");
930
- if (this._label) {
767
+ if (labelText) {
931
768
  if (!label) {
932
769
  label = document.createElement("label");
933
770
  label.className = "ty-field-label";
934
771
  label.id = labelId;
935
772
  container.prepend(label);
936
773
  }
937
- label.innerHTML = `${this._label}${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}`;
774
+ label.innerHTML = `${labelText}${required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}`;
938
775
  }
939
776
  else {
940
777
  label?.remove();
941
778
  }
942
- const error = this.getProperty("error") || "";
943
- const errorId = `select-error-${getElementHash(this)}`;
779
+ const error = this.error || "";
780
+ const errorId = `select-error-${this._uid}`;
944
781
  let errorLine = container.querySelector(":scope > .error-message");
945
782
  if (error) {
946
783
  if (!errorLine) {
@@ -955,17 +792,16 @@ else {
955
792
  errorLine?.remove();
956
793
  }
957
794
  const stub = shadow.querySelector(".select-stub");
958
- if (stub) {
959
- stub.classList.toggle("disabled", this._disabled);
960
- stub.classList.toggle("compact", this._compact);
795
+ stub.classList.toggle("disabled", disabled);
796
+ stub.classList.toggle("compact", this.compact);
961
797
  stub.classList.toggle("error", !!error);
962
- stub.tabIndex = this._disabled ? -1 : 0;
963
- stub.toggleAttribute("disabled", this._disabled);
964
- if (this._disabled)
798
+ stub.tabIndex = disabled ? -1 : 0;
799
+ stub.toggleAttribute("disabled", disabled);
800
+ if (disabled)
965
801
  stub.setAttribute("aria-disabled", "true");
966
802
  else
967
803
  stub.removeAttribute("aria-disabled");
968
- if (this._label)
804
+ if (labelText)
969
805
  stub.setAttribute("aria-labelledby", labelId);
970
806
  else
971
807
  stub.removeAttribute("aria-labelledby");
@@ -977,14 +813,13 @@ else {
977
813
  stub.removeAttribute("aria-invalid");
978
814
  stub.removeAttribute("aria-describedby");
979
815
  }
980
- }
981
816
  this.syncTriggerAria();
982
817
  shadow
983
818
  .querySelectorAll(".dropdown-search-input, .mobile-search-input")
984
- .forEach((input) => (input.disabled = this._disabled));
819
+ .forEach((input) => (input.disabled = disabled));
985
820
  }
986
821
  syncTriggerAria() {
987
- const error = this.getProperty("error") || "";
822
+ const error = this.error || "";
988
823
  const trigger = error
989
824
  ? this.querySelector(':scope > [slot="trigger"]')
990
825
  : null;
@@ -1009,328 +844,155 @@ attributeFilter: ["aria-invalid", "aria-description"],
1009
844
  }
1010
845
  }
1011
846
  updateValidity() {
1012
- if (this.disabled) {
847
+ if (this.disabled || this.externalSelection) {
1013
848
  this.applyValidity({});
1014
849
  return;
1015
850
  }
1016
851
  if (this.required && this.getSelectedValues().length === 0) {
1017
852
  const stub = this.shadowRoot?.querySelector(".select-stub");
1018
- this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this._multiple }), stub ?? undefined);
853
+ this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this.multiple }), stub ?? undefined);
1019
854
  }
1020
855
  else {
1021
856
  this.applyValidity({});
1022
857
  }
1023
858
  }
1024
- setupTriggerSlot() {
859
+ syncTriggerSlot() {
1025
860
  const shadow = this.shadowRoot;
1026
- const stub = shadow.querySelector(".select-stub");
1027
861
  const slot = shadow.querySelector('slot[name="trigger"]');
1028
- if (!stub || !slot)
1029
- return;
1030
- const sync = () => {
1031
862
  const hasTrigger = slot.assignedElements().length > 0;
1032
- stub.classList.toggle("custom-trigger", hasTrigger);
863
+ shadow.querySelector(".select-stub").classList.toggle("custom-trigger", hasTrigger);
864
+ if (this.hasAttribute("has-trigger") !== hasTrigger) {
1033
865
  this.toggleAttribute("has-trigger", hasTrigger);
1034
- };
1035
- slot.addEventListener("slotchange", () => {
1036
- sync();
1037
- this.syncFieldChrome();
1038
- });
1039
- sync();
1040
866
  }
1041
- setupEventListeners() {
1042
- const shadow = this.shadowRoot;
1043
- const stub = shadow.querySelector(".select-stub");
1044
- const optionsSlot = shadow.querySelector("#options-slot");
1045
- const searchInput = shadow.querySelector(".dropdown-search-input");
1046
- if (stub) {
1047
- this._stubClickHandler = this.handleStubClick.bind(this);
1048
- stub.addEventListener("click", this._stubClickHandler);
1049
- stub.addEventListener("keydown", this.handleStubKeydown.bind(this));
1050
- }
1051
- const clearBtn = shadow.querySelector(".select-clear");
1052
- clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
1053
- this.setupTriggerSlot();
1054
- if (optionsSlot) {
1055
- this._tagClickHandler = this.handleTagClick.bind(this);
1056
- optionsSlot.addEventListener("click", this._tagClickHandler);
1057
- }
1058
- if (searchInput) {
1059
- this._searchInputHandler = this.handleSearchInput.bind(this);
1060
- this._blockSearchClick = this.blockSearchClick.bind(this);
1061
- searchInput.addEventListener("input", this._searchInputHandler);
1062
- searchInput.addEventListener("click", this._blockSearchClick);
1063
867
  }
1064
- const dialog = shadow.querySelector(".dropdown-dialog");
1065
- if (dialog) {
1066
- dialog.addEventListener("click", (e) => {
1067
- if (e.target === dialog) {
1068
- this.closeDropdown();
1069
- }
1070
- });
1071
- dialog.addEventListener("cancel", (e) => {
1072
- e.preventDefault();
1073
- this.closeDropdown();
1074
- this.focus();
1075
- });
1076
- this.syncOnOutsideClose(dialog, () => this.closeDropdown());
1077
- }
1078
- }
1079
- buildStubClasses() {
1080
- const classes = [];
1081
- if (this._disabled)
1082
- classes.push("disabled");
1083
- if (this._compact)
1084
- classes.push("compact");
1085
- return classes.join(" ");
1086
- }
1087
- renderDesktop() {
868
+ build() {
1088
869
  const shadow = this.shadowRoot;
1089
- if (!shadow.querySelector(".select-container")) {
1090
- const stubClasses = this.buildStubClasses();
1091
- const listboxId = `select-listbox-${getElementHash(this)}`;
1092
- const labelId = `select-label-${getElementHash(this)}`;
1093
- const labelHtml = this._label
1094
- ? `
1095
- <label class="ty-field-label" id="${labelId}">
1096
- ${this._label}
1097
- ${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
1098
- </label>
1099
- `
1100
- : "";
1101
- const searchPlaceholder = "Search...";
1102
- shadow.innerHTML = `
1103
- <div class="select-container dropdown-mode-desktop">
1104
- ${labelHtml}
1105
- <div class="dropdown-wrapper">
1106
- <div class="dropdown-stub select-stub ${stubClasses}"
1107
- role="combobox"
1108
- aria-haspopup="listbox"
1109
- aria-expanded="false"
1110
- aria-controls="${listboxId}"
1111
- ${this._label ? `aria-labelledby="${labelId}"` : ""}
1112
- tabindex="${this._disabled ? "-1" : "0"}"
1113
- ${this._disabled ? 'disabled aria-disabled="true"' : ""}>
1114
- <slot name="trigger">
1115
- <slot name="start"></slot>
1116
- <slot name="selected"></slot>
1117
- <span class="dropdown-placeholder">${this._placeholder}</span>
1118
- <span class="select-count" hidden></span>
1119
- <slot name="end"></slot>
1120
- <button class="select-clear" type="button" aria-label="Clear selection" hidden>
1121
- ${CLEAR_ICON_SVG}
1122
- </button>
1123
- <div class="dropdown-chevron">
1124
- ${CHEVRON_DOWN_SVG}
1125
- </div>
1126
- </slot>
1127
- </div>
1128
- <dialog class="dropdown-dialog">
1129
- <div class="dropdown-header">
1130
- <div class="dropdown-search-icon" aria-hidden="true">
1131
- ${SEARCH_ICON_SVG}
1132
- </div>
1133
- <input
1134
- class="dropdown-search-input"
1135
- type="text"
1136
- placeholder="${searchPlaceholder}"
1137
- ${this._disabled ? "disabled" : ""}
1138
- />
1139
- <div class="dropdown-search-chevron">
1140
- ${CHEVRON_DOWN_SVG}
1141
- </div>
1142
- </div>
1143
- <div class="dropdown-options-wrapper">
1144
- <div class="dropdown-options" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
1145
- <slot id="options-slot"></slot>
1146
- </div>
870
+ const mobile = isMobileTouch();
871
+ this._state.mode = mobile ? "mobile" : "desktop";
872
+ const listboxId = `select-listbox-${this._uid}`;
873
+ const multiselectable = this.multiple ? 'aria-multiselectable="true"' : "";
874
+ const loadingHtml = `
1147
875
  <div class="dropdown-loading" aria-hidden="true">
1148
876
  <slot name="loading">
1149
877
  <span class="dropdown-loading-spinner"></span>
1150
878
  <span class="dropdown-loading-text">Searching…</span>
1151
879
  </slot>
880
+ </div>`;
881
+ const desktopPopup = `
882
+ <dialog class="dropdown-dialog">
883
+ <div class="dropdown-header">
884
+ <div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
885
+ <input class="dropdown-search-input" type="text" placeholder="Search..." />
886
+ <div class="dropdown-search-chevron">${CHEVRON_DOWN_SVG}</div>
1152
887
  </div>
888
+ <div class="dropdown-options-wrapper">
889
+ <div class="dropdown-options" id="${listboxId}" role="listbox" ${multiselectable}>
890
+ <slot id="options-slot"></slot>
1153
891
  </div>
1154
- </dialog>
1155
- </div>
892
+ ${loadingHtml}
1156
893
  </div>
1157
- `;
1158
- this.setupEventListeners();
1159
- }
1160
- this.updateSelectionDisplay();
1161
- }
1162
- renderMobile() {
1163
- const shadow = this.shadowRoot;
1164
- if (!shadow.querySelector(".select-container")) {
1165
- const stubClasses = this.buildStubClasses();
1166
- const listboxId = `select-listbox-${getElementHash(this)}`;
1167
- const labelId = `select-label-${getElementHash(this)}`;
1168
- const labelHtml = this._label
1169
- ? `
1170
- <label class="ty-field-label" id="${labelId}">
1171
- ${this._label}
1172
- ${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
1173
- </label>
1174
- `
1175
- : "";
1176
- const closeButtonSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1177
- <line x1="18" y1="6" x2="6" y2="18"></line>
1178
- <line x1="6" y1="6" x2="18" y2="18"></line>
1179
- </svg>`;
1180
- const searchPlaceholder = this._label
1181
- ? `Search ${this._label}...`
1182
- : "Search...";
1183
- const searchHeaderHtml = `
894
+ </dialog>`;
895
+ const label = this.label;
896
+ const mobilePopup = `
897
+ <dialog class="mobile-dialog">
898
+ <div class="mobile-dialog-content">
1184
899
  <div class="mobile-search-header">
1185
- ${this._label ? `<span class="mobile-header-label">${this._label}</span>` : ""}
900
+ ${label ? `<span class="mobile-header-label">${label}</span>` : ""}
1186
901
  <div class="mobile-header-content">
1187
- <div class="dropdown-search-icon" aria-hidden="true">
1188
- ${SEARCH_ICON_SVG}
902
+ <div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
903
+ <input class="mobile-search-input" type="text"
904
+ placeholder="${label ? `Search ${label}...` : "Search..."}" autofocus />
905
+ <button class="mobile-close-button" type="button" aria-label="Close">${CLEAR_ICON_SVG}</button>
1189
906
  </div>
1190
- <input
1191
- class="mobile-search-input"
1192
- type="text"
1193
- placeholder="${searchPlaceholder}"
1194
- autofocus
1195
- ${this._disabled ? "disabled" : ""}
1196
- />
1197
- <button class="mobile-close-button" type="button" aria-label="Close">
1198
- ${closeButtonSvg}
907
+ </div>
908
+ <div class="mobile-body" data-expanded="available">
909
+ <!-- Selected strip, pinned above the list; collapses when empty -->
910
+ <div class="mobile-selected-section" data-empty="true">
911
+ <button class="section-header" type="button" data-section="selected" aria-expanded="false">
912
+ <span class="section-title"></span>
913
+ ${CHEVRON_DOWN_SVG}
1199
914
  </button>
915
+ <div class="section-content mobile-selected-chips"></div>
1200
916
  </div>
917
+ <div class="mobile-available-section" data-empty="false">
918
+ <button class="section-header" type="button" data-section="available" aria-expanded="true">
919
+ <span class="section-title"></span>
920
+ ${CHEVRON_DOWN_SVG}
921
+ </button>
922
+ <div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${multiselectable}>
923
+ <slot id="options-slot"></slot>
924
+ <div class="empty-state">${this.getProperty("no-options-message")}</div>
925
+ ${loadingHtml}
1201
926
  </div>
1202
- `;
927
+ </div>
928
+ </div>
929
+ </div>
930
+ </dialog>`;
1203
931
  shadow.innerHTML = `
1204
- <div class="select-container dropdown-mode-mobile">
1205
- ${labelHtml}
932
+ <div class="select-container dropdown-mode-${this._state.mode}">
1206
933
  <div class="dropdown-wrapper">
1207
- <div class="dropdown-stub select-stub ${stubClasses}"
934
+ <div class="dropdown-stub select-stub"
1208
935
  role="combobox"
1209
936
  aria-haspopup="listbox"
1210
937
  aria-expanded="false"
1211
938
  aria-controls="${listboxId}"
1212
- ${this._label ? `aria-labelledby="${labelId}"` : ""}
1213
- tabindex="${this._disabled ? "-1" : "0"}"
1214
- ${this._disabled ? 'disabled aria-disabled="true"' : ""}>
939
+ tabindex="0">
1215
940
  <slot name="trigger">
1216
941
  <slot name="start"></slot>
1217
942
  <slot name="selected"></slot>
1218
- <span class="dropdown-placeholder">${this._placeholder}</span>
943
+ <span class="dropdown-placeholder"></span>
1219
944
  <span class="select-count" hidden></span>
1220
945
  <slot name="end"></slot>
1221
946
  <button class="select-clear" type="button" aria-label="Clear selection" hidden>
1222
947
  ${CLEAR_ICON_SVG}
1223
948
  </button>
1224
- <div class="dropdown-chevron">
1225
- ${CHEVRON_DOWN_SVG}
1226
- </div>
1227
- </slot>
1228
- </div>
1229
- <dialog class="mobile-dialog">
1230
- <div class="mobile-dialog-content">
1231
- <!-- HEADER (matches dropdown.ts) -->
1232
- ${searchHeaderHtml}
1233
- <!-- BODY: options list with toggleable selected state -->
1234
- <div class="mobile-body" data-expanded="available">
1235
- <!-- SELECTED STRIP (pinned above the list, collapses when empty) -->
1236
- <div class="mobile-selected-section" data-empty="true">
1237
- <button class="section-header" type="button" data-section="selected" aria-expanded="false">
1238
- <span class="section-title">${this._selectedLabel} <span class="section-count">(0)</span></span>
1239
- ${CHEVRON_DOWN_SVG}
1240
- </button>
1241
- <div class="section-content mobile-selected-chips"></div>
1242
- </div>
1243
- <!-- AVAILABLE LIST (always visible, takes remaining space) -->
1244
- <div class="mobile-available-section" data-empty="false">
1245
- <button class="section-header" type="button" data-section="available" aria-expanded="true">
1246
- <span class="section-title">${this._availableLabel} <span class="section-count"></span></span>
1247
- ${CHEVRON_DOWN_SVG}
1248
- </button>
1249
- <div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
1250
- <slot id="options-slot"></slot>
1251
- <div class="empty-state">${this._noOptionsMessage}</div>
1252
- <div class="dropdown-loading" aria-hidden="true">
1253
- <slot name="loading">
1254
- <span class="dropdown-loading-spinner"></span>
1255
- <span class="dropdown-loading-text">Searching…</span>
949
+ <div class="dropdown-chevron">${CHEVRON_DOWN_SVG}</div>
1256
950
  </slot>
1257
951
  </div>
1258
- </div>
1259
- </div>
1260
- </div>
1261
- </div>
1262
- </dialog>
952
+ ${mobile ? mobilePopup : desktopPopup}
1263
953
  </div>
1264
954
  </div>
1265
955
  `;
1266
- this.setupMobileEventListeners();
1267
- }
1268
- this.updateSelectionDisplay();
1269
- }
1270
- setupMobileEventListeners() {
1271
- const shadow = this.shadowRoot;
1272
956
  const stub = shadow.querySelector(".select-stub");
1273
- const optionsSlot = shadow.querySelector("#options-slot");
1274
- const searchInput = shadow.querySelector(".mobile-search-input");
1275
- const closeButton = shadow.querySelector(".mobile-close-button");
1276
- const dialog = shadow.querySelector(".mobile-dialog");
1277
- if (stub) {
1278
- stub.addEventListener("click", (e) => this.handleMobileStubClick(e));
1279
- stub.addEventListener("keydown", (e) => this.handleMobileStubKeydown(e));
1280
- }
1281
- const clearBtn = shadow.querySelector(".select-clear");
1282
- clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
1283
- this.setupTriggerSlot();
1284
- if (optionsSlot) {
1285
- optionsSlot.addEventListener("click", (e) => this.handleMobileTagClick(e));
1286
- }
1287
- if (searchInput) {
1288
- searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
1289
- }
1290
- shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
1291
- header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
957
+ stub.addEventListener("click", (e) => this.handleStubClick(e));
958
+ stub.addEventListener("keydown", (e) => this.handleStubKeydown(e));
959
+ shadow.querySelector(".select-clear").addEventListener("click", (e) => this.handleClearClick(e));
960
+ shadow.querySelector('slot[name="trigger"]').addEventListener("slotchange", () => {
961
+ this.syncTriggerSlot();
962
+ this.syncFieldChrome();
1292
963
  });
1293
- if (closeButton) {
1294
- closeButton.addEventListener("click", () => this.closeMobileModal());
1295
- }
1296
- if (dialog) {
964
+ shadow.querySelector("#options-slot").addEventListener("click", (e) => this.handleTagClick(e));
965
+ const searchInput = this.searchInput();
966
+ searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
967
+ const dialog = shadow.querySelector("dialog");
1297
968
  dialog.addEventListener("click", (e) => {
1298
- if (e.target === dialog) {
1299
- this.closeMobileModal();
1300
- }
969
+ if (e.target === dialog)
970
+ this.close();
1301
971
  });
1302
972
  dialog.addEventListener("cancel", (e) => {
1303
973
  e.preventDefault();
1304
- this.closeMobileModal();
974
+ this.close();
1305
975
  this.focus();
1306
976
  });
1307
- this.syncOnOutsideClose(dialog, () => this.closeMobileModal());
1308
- }
1309
- }
1310
- syncOnOutsideClose(dialog, close) {
1311
- new MutationObserver(() => {
1312
- if (this._state.open && !dialog.open)
1313
- close();
1314
- }).observe(dialog, { attributes: true, attributeFilter: ["open"] });
977
+ this.syncOnOutsideClose(dialog);
978
+ if (mobile) {
979
+ shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
980
+ header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
981
+ });
982
+ shadow.querySelector(".mobile-close-button").addEventListener("click", () => this.close());
1315
983
  }
1316
- handleMobileStubClick(e) {
1317
- e.preventDefault();
984
+ else {
985
+ searchInput.addEventListener("click", (e) => {
1318
986
  e.stopPropagation();
1319
- if (this._disabled || this._readonly) {
1320
- return;
1321
- }
1322
- this.openMobileModal();
1323
- }
1324
- handleMobileStubKeydown(e) {
1325
- if (this._disabled || this._readonly || this._state.open)
1326
- return;
1327
- if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
1328
987
  e.preventDefault();
1329
- this.openMobileModal();
988
+ });
1330
989
  }
1331
990
  }
1332
- handleMobileTagClick(e) {
1333
- this.handleTagClick(e);
991
+ syncOnOutsideClose(dialog) {
992
+ new MutationObserver(() => {
993
+ if (this._state.open && !dialog.open)
994
+ this.close();
995
+ }).observe(dialog, { attributes: true, attributeFilter: ["open"] });
1334
996
  }
1335
997
  updateMobileSelectedState() {
1336
998
  if (this._state.mode !== "mobile")
@@ -1339,9 +1001,11 @@ const shadow = this.shadowRoot;
1339
1001
  this.renderMobileSelectedChips();
1340
1002
  const availableSection = shadow.querySelector(".mobile-available-section");
1341
1003
  if (availableSection) {
1342
- const visibleAvailable = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out") && !element.hasAttribute("selected")).length;
1343
- availableSection.setAttribute("data-empty", String(visibleAvailable === 0));
1344
- this.setMobileSectionTitle(availableSection, this._availableLabel, visibleAvailable);
1004
+ const selected = new Set(this.getSelectedValues());
1005
+ const shown = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out"));
1006
+ const visibleAvailable = shown.filter(({ value }) => !selected.has(value)).length;
1007
+ availableSection.setAttribute("data-empty", String(shown.length === 0));
1008
+ this.setMobileSectionTitle(availableSection, this.getProperty("available-label"), visibleAvailable);
1345
1009
  }
1346
1010
  }
1347
1011
  setMobileSectionTitle(section, label, n) {
@@ -1358,7 +1022,7 @@ const shadow = this.shadowRoot;
1358
1022
  const body = shadow?.querySelector(".mobile-body");
1359
1023
  if (!body)
1360
1024
  return;
1361
- if (section === "selected" && this._state.selectedValues.length === 0)
1025
+ if (section === "selected" && this.getSelectedValues().length === 0)
1362
1026
  return;
1363
1027
  body.dataset.expanded = section;
1364
1028
  shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
@@ -1372,24 +1036,20 @@ const section = shadow.querySelector(".mobile-selected-section");
1372
1036
  const host = shadow.querySelector(".mobile-selected-chips");
1373
1037
  if (!section || !host)
1374
1038
  return;
1375
- const selected = this._state.selectedValues;
1039
+ const selected = this.getSelectedValues();
1376
1040
  section.setAttribute("data-empty", String(selected.length === 0));
1377
- this.setMobileSectionTitle(section, this._selectedLabel, selected.length);
1041
+ this.setMobileSectionTitle(section, this.getProperty("selected-label"), selected.length);
1378
1042
  if (selected.length === 0)
1379
1043
  this.expandMobileSection("available");
1380
- const labelFor = (value) => {
1381
- const option = this.getTagElements().find((tag) => this.getTagData(tag).value === value);
1382
- return option ? this.getTagData(option).text : value;
1383
- };
1384
1044
  host.textContent = "";
1385
- for (const value of selected) {
1045
+ for (const { value, label } of this.getSelectedItems(selected)) {
1386
1046
  const chip = document.createElement("button");
1387
1047
  chip.type = "button";
1388
1048
  chip.className = "mobile-selected-chip";
1389
1049
  chip.dataset.value = value;
1390
- chip.setAttribute("aria-label", `Remove ${labelFor(value)}`);
1050
+ chip.setAttribute("aria-label", `Remove ${label}`);
1391
1051
  chip.innerHTML = `<span class="chip-label"></span>${CLEAR_ICON_SVG}`;
1392
- chip.querySelector(".chip-label").textContent = labelFor(value);
1052
+ chip.querySelector(".chip-label").textContent = label;
1393
1053
  chip.addEventListener("click", (e) => {
1394
1054
  e.preventDefault();
1395
1055
  e.stopPropagation();
@@ -1399,107 +1059,40 @@ host.appendChild(chip);
1399
1059
  }
1400
1060
  }
1401
1061
  shouldShowSearch() {
1402
- if (this._externalSearch)
1062
+ if (this.externalSearch || this.allowCreate)
1403
1063
  return true;
1404
- if (this._allowCreate)
1405
- return true;
1406
- if (this._notSearchable)
1064
+ if (this.notSearchable)
1407
1065
  return false;
1408
1066
  return this.getTagElements().length > SEARCH_AUTO_THRESHOLD;
1409
1067
  }
1410
1068
  updateSearchVisibility() {
1411
1069
  const shadow = this.shadowRoot;
1412
- if (!shadow)
1413
- return;
1414
1070
  const show = this.shouldShowSearch();
1415
1071
  const header = shadow.querySelector(".dropdown-header");
1416
1072
  if (header)
1417
1073
  header.hidden = !show;
1418
- const mobileInput = shadow.querySelector(".mobile-search-input");
1419
- if (mobileInput)
1420
- mobileInput.hidden = !show;
1421
- const mobileIcon = shadow.querySelector(".mobile-header-content .dropdown-search-icon");
1422
- if (mobileIcon)
1423
- mobileIcon.hidden = !show;
1424
- }
1425
- updateSelectionDisplay() {
1426
- const shadow = this.shadowRoot;
1427
- const stub = shadow.querySelector(".select-stub");
1428
- if (!stub)
1429
- return;
1430
- const values = this._state.selectedValues;
1074
+ shadow
1075
+ .querySelectorAll(".mobile-search-input, .mobile-header-content .dropdown-search-icon")
1076
+ .forEach((el) => (el.hidden = !show));
1077
+ }
1078
+ updateSelectionDisplay(shown) {
1079
+ const stub = this.shadowRoot.querySelector(".select-stub");
1080
+ const values = this.getSelectedValues();
1431
1081
  const count = values.length;
1432
1082
  stub.classList.toggle("has-selection", count > 0);
1433
- stub.classList.toggle("compact", this._compact);
1083
+ stub.classList.toggle("has-option", shown !== null);
1434
1084
  const badge = stub.querySelector(".select-count");
1435
- if (badge) {
1436
1085
  badge.textContent = String(count);
1437
- badge.hidden = count === 0 || !this._multiple || !this._compact;
1438
- }
1086
+ badge.hidden = count === 0 || !this.multiple || !this.compact;
1439
1087
  const clearBtn = stub.querySelector(".select-clear");
1440
- if (clearBtn) {
1441
- clearBtn.hidden = !(count > 0 && this._clearable && !this._disabled && !this._readonly);
1442
- }
1443
- const wantClone = !this._multiple && count > 0 ? values[0] : null;
1444
- this.syncSelectedClone(wantClone);
1445
- const hasClone = this._selectedClone !== null;
1446
- stub.classList.toggle("has-clone", hasClone);
1088
+ clearBtn.hidden = !(count > 0 && !this.noClear && !this.disabled && !this.readonly);
1447
1089
  const textEl = stub.querySelector(".dropdown-placeholder");
1448
- if (textEl) {
1449
- textEl.hidden = hasClone;
1450
- const showLabels = count > 0 && this._multiple && !this._compact;
1451
- if (showLabels) {
1452
- textEl.textContent = this.getSelectedItems(values)
1453
- .map((i) => i.label)
1454
- .join(", ");
1455
- textEl.classList.remove("placeholder-shown");
1456
- }
1457
- else if (wantClone !== null) {
1458
- textEl.textContent = values.join(", ");
1459
- textEl.classList.remove("placeholder-shown");
1460
- }
1461
- else {
1462
- textEl.textContent = this._placeholder;
1463
- textEl.classList.add("placeholder-shown");
1464
- }
1465
- }
1466
- }
1467
- syncSelectedClone(value) {
1468
- const existing = this.querySelector(':scope > [cloned][slot="selected"]');
1469
- if (existing?.getAttribute("value") === value) {
1470
- const stale = value !== null &&
1471
- existing.childNodes.length === 0 &&
1472
- (this.getTagElements().find((el) => this.getTagData(el).value === value)?.childNodes.length ?? 0) > 0;
1473
- if (!stale) {
1474
- this._selectedClone = existing;
1475
- return;
1476
- }
1477
- }
1478
- existing?.remove();
1479
- if (value === null) {
1480
- this._selectedClone = null;
1481
- return;
1482
- }
1483
- const option = this.getTagElements().find((el) => this.getTagData(el).value === value);
1484
- if (option) {
1485
- const clone = option.cloneNode(true);
1486
- clone.removeAttribute("selected");
1487
- clone.removeAttribute("hidden");
1488
- clone.removeAttribute("filtered-out");
1489
- clone.setAttribute("slot", "selected");
1490
- clone.setAttribute("cloned", "true");
1491
- this.appendChild(clone);
1492
- this._selectedClone = clone;
1493
- if (option.childNodes.length === 0 && document.readyState === "loading") {
1494
- document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
1495
- this.updateSelectionDisplay(); }, { once: true });
1496
- }
1497
- }
1498
- else if (this._selectedClone?.getAttribute("value") === value) {
1499
- const restored = this._selectedClone.cloneNode(true);
1500
- this.appendChild(restored);
1501
- this._selectedClone = restored;
1502
- }
1090
+ textEl.hidden = shown !== null;
1091
+ const text = this._state.open || count === 0 || (this.multiple && this.compact)
1092
+ ? null
1093
+ : this.getSelectedItems(values).map((i) => i.label).join(", ");
1094
+ textEl.textContent = text ?? this.placeholder;
1095
+ textEl.classList.toggle("placeholder-shown", text === null);
1503
1096
  }
1504
1097
  deselectValue(value) {
1505
1098
  const current = this.getSelectedValues();
@@ -1594,6 +1187,24 @@ return this.getProperty("externalSearch");
1594
1187
  set externalSearch(value) {
1595
1188
  this.setProperty("externalSearch", value);
1596
1189
  }
1190
+ get externalSelection() {
1191
+ return this.getProperty("externalSelection");
1192
+ }
1193
+ set externalSelection(value) {
1194
+ this.setProperty("externalSelection", value);
1195
+ }
1196
+ get allowCreate() {
1197
+ return this.getProperty("allowCreate");
1198
+ }
1199
+ set allowCreate(value) {
1200
+ this.setProperty("allowCreate", value);
1201
+ }
1202
+ get createTransform() {
1203
+ return this.getProperty("createTransform");
1204
+ }
1205
+ set createTransform(value) {
1206
+ this.setProperty("createTransform", value);
1207
+ }
1597
1208
  get debounce() {
1598
1209
  return this.getProperty("debounce");
1599
1210
  }
@@ -1629,6 +1240,7 @@ get form() {
1629
1240
  return this._internals.form;
1630
1241
  }
1631
1242
  }
1243
+ TySelect.slotAssignment = "manual";
1632
1244
  TySelect.properties = {
1633
1245
  value: {
1634
1246
  type: "string",
@@ -1699,19 +1311,21 @@ externalSearch: {
1699
1311
  type: "boolean",
1700
1312
  visual: true,
1701
1313
  default: false,
1702
- aliases: { "external-search": true },
1314
+ },
1315
+ externalSelection: {
1316
+ type: "boolean",
1317
+ visual: true,
1318
+ default: false,
1703
1319
  },
1704
1320
  allowCreate: {
1705
1321
  type: "boolean",
1706
1322
  visual: true,
1707
1323
  default: false,
1708
- aliases: { "allow-create": true },
1709
1324
  },
1710
1325
  createTransform: {
1711
1326
  type: "string",
1712
1327
  visual: false,
1713
1328
  default: "none",
1714
- aliases: { "create-transform": true },
1715
1329
  coerce: (v) => (v === "slug" ? "slug" : "none"),
1716
1330
  },
1717
1331
  notSearchable: {