@cas-smartdesign/token-selector 0.21.4 → 1.0.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.
@@ -1,4 +1,4 @@
1
- import { LitElement as w, unsafeCSS as T, html as m, nothing as x } from "lit";
1
+ import { LitElement as x, unsafeCSS as T, nothing as w, html as m } from "lit";
2
2
  import { property as d } from "lit/decorators/property.js";
3
3
  import "@cas-smartdesign/lit-input";
4
4
  import S from "@cas-smartdesign/field-validation-message";
@@ -8,11 +8,11 @@ import y from "@cas-smartdesign/virtual-list";
8
8
  import { KeyDownDelegator as A } from "@cas-smartdesign/element-utils";
9
9
  import { ifDefined as C } from "lit/directives/if-defined.js";
10
10
  import { unsafeSVG as P } from "lit/directives/unsafe-svg.js";
11
- import D from "@cas-smartdesign/image-tools";
11
+ import { placeholderDirective as D } from "@cas-smartdesign/image-tools";
12
12
  let O = 0;
13
13
  class q {
14
- constructor(e, t, i, s) {
15
- this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback = s, this.filter = (n, o) => n ? o.filter((a) => a.disabled || a.deactivated ? !1 : a.caption && a.caption.toLowerCase().includes(n)) : o, y.ensureDefined(), this._tokenList = new y(), this._tokenList.id = "sd_token_suggest_popover_list_" + O++, this._tokenList.style.minWidth = "250px", this._tokenList.style.maxHeight = "49vh", this._tokenList.itemHeight = 50, this._tokenList.addEventListener("pointerdown", () => {
14
+ constructor(e, t, i, n) {
15
+ this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback = n, this.filter = (s, o) => s ? o.filter((a) => a.disabled || a.deactivated ? !1 : a.caption && a.caption.toLowerCase().includes(s)) : o, y.ensureDefined(), this._tokenList = new y(), this._tokenList.id = "sd_token_suggest_popover_list_" + O++, this._tokenList.style.minWidth = "250px", this._tokenList.style.maxHeight = "49vh", this._tokenList.itemHeight = 50, this._tokenList.addEventListener("pointerdown", () => {
16
16
  this.pointerDown = !0, window.addEventListener(
17
17
  "pointerup",
18
18
  () => {
@@ -20,20 +20,20 @@ class q {
20
20
  },
21
21
  { once: !0, capture: !0 }
22
22
  );
23
- }), this._tokenList.addEventListener("selection", (n) => {
24
- const o = n.detail.index, a = this._suggestItems[o];
23
+ }), this._tokenList.addEventListener("selection", (s) => {
24
+ const o = s.detail.index, a = this._suggestItems[o];
25
25
  i(a), this.hide();
26
- }), this._tokenList.addEventListener("data-request", (n) => {
27
- this.lastRequestedStartIndex = n.detail.startIndex, this.lastRequestedStopIndex = n.detail.stopIndex, this.pointerDown || this._tokenList.increaseWidthOnNextRenderIfNeeded(), this._tokenList.items = this._suggestItems.slice(
26
+ }), this._tokenList.addEventListener("data-request", (s) => {
27
+ this.lastRequestedStartIndex = s.detail.startIndex, this.lastRequestedStopIndex = s.detail.stopIndex, this.pointerDown || this._tokenList.increaseWidthOnNextRenderIfNeeded(), this._tokenList.items = this._suggestItems.slice(
28
28
  this.lastRequestedStartIndex,
29
29
  this.lastRequestedStopIndex + 1
30
30
  );
31
- }), new A(this._tokenList, (n, o, a) => {
32
- this._tokenList.dispatchEvent(new KeyboardEvent(n.type, n)), !a && !this.isOpened && this.show();
31
+ }), new A(this._tokenList, (s, o, a) => {
32
+ this._tokenList.dispatchEvent(new KeyboardEvent(s.type, s)), !a && !this.isOpened && this.show();
33
33
  }).connect(e);
34
34
  }
35
35
  show() {
36
- this.inputElement.effectiveDisabled || (this.popover, this._suggestItems = this.filterItems((this.inputElement.value || "").toLowerCase()), this._suggestItems.length == 0 ? this.hide() : (this._tokenList.itemCount = this._suggestItems.length, this._tokenList.focusIndex = -1, this._tokenList.style.width = null, requestAnimationFrame(() => {
36
+ this.inputElement.effectiveDisabled || (this.ensurePopover(), this._suggestItems = this.filterItems((this.inputElement.value || "").toLowerCase()), this._suggestItems.length == 0 ? this.hide() : (this._tokenList.itemCount = this._suggestItems.length, this._tokenList.focusIndex = -1, this._tokenList.style.width = null, requestAnimationFrame(() => {
37
37
  this.lastRequestedStartIndex != null && (this._tokenList.increaseWidthOnNextRenderIfNeeded(), this._tokenList.items = this._suggestItems.slice(
38
38
  this.lastRequestedStartIndex,
39
39
  this.lastRequestedStopIndex + 1
@@ -47,15 +47,17 @@ class q {
47
47
  const t = this.notSelectedTokensProvider();
48
48
  return this.filter(e, t);
49
49
  }
50
+ ensurePopover() {
51
+ this._popover || (this._popover = this.createPopover(), this.initializeCallback(this));
52
+ }
50
53
  hide() {
51
- var e;
52
- this._suggestItems = [], this._tokenList.itemCount = 0, this._tokenList.items = [], (e = this._popover) == null || e.hide();
54
+ this._suggestItems = [], this._tokenList.itemCount = 0, this._tokenList.items = [], this._popover?.hide();
53
55
  }
54
56
  get list() {
55
57
  return this._tokenList;
56
58
  }
57
59
  get popover() {
58
- return this._popover || (this._popover = this.createPopover(), this.initializeCallback(this)), this._popover;
60
+ return this.ensurePopover(), this._popover;
59
61
  }
60
62
  createPopover() {
61
63
  const e = new L();
@@ -72,16 +74,16 @@ const M = `:host{flex-shrink:0;max-width:100%;height:28px}:host([aria-checked=tr
72
74
  <path d="m3.5 12.5 9-9m-9 0 9 9" style="fill:none;stroke:#333;stroke-linecap:square;stroke-width:1.1px"/>\r
73
75
  </svg>`;
74
76
  var R = Object.defineProperty, N = Object.getOwnPropertyDescriptor, f = (r, e, t, i) => {
75
- for (var s = i > 1 ? void 0 : i ? N(e, t) : e, n = r.length - 1, o; n >= 0; n--)
76
- (o = r[n]) && (s = (i ? o(e, t, s) : o(s)) || s);
77
- return i && s && R(e, t, s), s;
77
+ for (var n = i > 1 ? void 0 : i ? N(e, t) : e, s = r.length - 1, o; s >= 0; s--)
78
+ (o = r[s]) && (n = (i ? o(e, t, n) : o(n)) || n);
79
+ return i && n && R(e, t, n), n;
78
80
  };
79
81
  const I = {
80
82
  fromAttribute: (r) => r == "true",
81
83
  toAttribute: (r) => r
82
84
  };
83
85
  var u;
84
- const p = (u = class extends w {
86
+ const p = (u = class extends x {
85
87
  constructor() {
86
88
  super(...arguments), this.value = "", this.type = "", this.icon = "", this.iconPlaceholder = "", this.iconBackgroundColor = "", this._checked = !1;
87
89
  }
@@ -97,12 +99,12 @@ const p = (u = class extends w {
97
99
  }
98
100
  firstUpdated(e) {
99
101
  super.firstUpdated(e), this.tabIndex = -1, this.setAttribute("role", "option"), this.setAttribute("aria-selected", "true"), this.addEventListener("click", (i) => {
100
- const s = window.getSelection();
101
- if (s && s.type == "Range")
102
+ const n = window.getSelection();
103
+ if (n && n.type == "Range")
102
104
  return;
103
105
  i.stopPropagation();
104
- const n = i.getModifierState("Control");
105
- this.disabled || (n ? this.checked = !this.checked : this.checked = !0), this._tokenClickHandler && this._tokenClickHandler(this.index, n);
106
+ const s = i.getModifierState("Control");
107
+ this.disabled || (s ? this.checked = !this.checked : this.checked = !0), this._tokenClickHandler && this._tokenClickHandler(this.index, s);
106
108
  });
107
109
  const t = this.shadowRoot.querySelector(".delete-button-wrapper");
108
110
  t && t.addEventListener("click", (i) => {
@@ -116,7 +118,7 @@ const p = (u = class extends w {
116
118
  ${this.renderIcon()}
117
119
  <slot name="after-icon"></slot>
118
120
  <div class="value">${this.value}</div>
119
- ${this.disabled ? x : m` <div class="delete-button-wrapper">${P($)}</div> `}
121
+ ${this.disabled ? w : m` <div class="delete-button-wrapper">${P($)}</div> `}
120
122
  </div>
121
123
  `;
122
124
  }
@@ -125,14 +127,18 @@ const p = (u = class extends w {
125
127
  const e = this.iconBackgroundColor != null ? `--sd-token-icon-background-color: ${this.iconBackgroundColor}` : void 0;
126
128
  return m`
127
129
  <div class="icon-wrapper" style="${C(e)}" role="img">
128
- <div part="icon" class="icon"></div>
130
+ <div
131
+ part="icon"
132
+ class="icon"
133
+ style="background-image:${D(this.icon, this.iconPlaceholder)}"
134
+ ></div>
129
135
  </div>
130
136
  `;
131
137
  }
132
- return x;
138
+ return w;
133
139
  }
134
140
  updated(e) {
135
- super.updated(e), (e.has("icon") || e.has("iconPlaceholder")) && (this.icon || this.iconPlaceholder) && D.showImage(this.shadowRoot.querySelector(".icon"), this.icon, this.iconPlaceholder), e.has("disabled") && !this.disabled && this.checked && (this.checked = !1);
141
+ super.updated(e), e.has("disabled") && !this.disabled && this.checked && (this.checked = !1);
136
142
  }
137
143
  setClickHandler(e) {
138
144
  this._tokenClickHandler = e;
@@ -174,11 +180,11 @@ const F = (r, e) => {
174
180
  };
175
181
  b.ensureDefined();
176
182
  const k = "web application/json";
177
- class G {
183
+ class V {
178
184
  constructor(e, t, i) {
179
185
  navigator.clipboard && (e.addEventListener("copy", () => {
180
- const s = window.getSelection();
181
- (!s || s.type != "Range") && !t() && this.writeToClipboard(e);
186
+ const n = window.getSelection();
187
+ (!n || n.type != "Range") && !t() && this.writeToClipboard(e);
182
188
  }), e.addEventListener("cut", () => {
183
189
  t() || (e.removeSelectionOrActiveToken(), this.writeToClipboard(e));
184
190
  }), e.addEventListener("paste", () => {
@@ -188,16 +194,16 @@ class G {
188
194
  writeToClipboard(e) {
189
195
  const t = e.querySelectorAll("[slot='items'][aria-checked='true']"), i = [];
190
196
  if (t.length > 0)
191
- t.forEach((s) => i.push(s.index));
197
+ t.forEach((n) => i.push(n.index));
192
198
  else if (e.activeTokenIndex != -1) {
193
- const s = e.activeTokenElement;
194
- s && i.push(s.index);
199
+ const n = e.activeTokenElement;
200
+ n && i.push(n.index);
195
201
  }
196
202
  if (i.length > 0) {
197
- const s = JSON.stringify(i.map((o) => e.items[o])), n = new Blob([s], { type: k });
203
+ const n = JSON.stringify(i.map((o) => e.items[o])), s = new Blob([n], { type: k });
198
204
  navigator.clipboard.write([
199
205
  new ClipboardItem({
200
- [k]: n
206
+ [k]: s
201
207
  })
202
208
  ]);
203
209
  }
@@ -206,56 +212,56 @@ class G {
206
212
  const t = await navigator.clipboard.read();
207
213
  for (const i of t)
208
214
  if (i.types.includes(k)) {
209
- const n = await (await i.getType(k)).text(), o = JSON.parse(n);
215
+ const s = await (await i.getType(k)).text(), o = JSON.parse(s);
210
216
  Array.isArray(o) && e(o);
211
217
  }
212
218
  }
213
219
  }
214
- const H = ":host{display:flex;contain:layout style}:host .additonal-content::slotted(*){align-self:end;flex-shrink:0}:host([drop]) ::slotted(*){pointer-events:none}:host(:not([readonly])) ::slotted(sd-token:last-of-type){max-width:calc(100% - 24px);margin-right:24px;margin-bottom:4px}:host ::slotted(sd-token){--sd-token-border: 1px solid transparent;margin:1px}:host([selection-mode=multi][aria-disabled=true]){opacity:.6}:host([selection-mode=multi][aria-disabled=true]) .input[effective-disabled]{opacity:1}:host([selection-mode=multi][aria-disabled=true]) ::slotted([aria-disabled=true]){opacity:1}.input[focus-visible]:focus-within ::slotted(sd-token[aria-current=true]),.container:focus-visible ::slotted(sd-token[aria-current=true]){outline:1px solid #1467ba;--sd-token-focused-border: 1px solid #fff}.input[focus-visible]:focus-within ::slotted(sd-token[aria-current=true][aria-disabled=true]:not([aria-haspopup])),.container:focus-visible ::slotted(sd-token[aria-current=true][aria-disabled=true]:not([aria-haspopup])){outline-color:#767676}.container{outline:none;display:flex;flex-wrap:wrap;gap:6px;flex-grow:1;min-width:0;margin-top:auto}.container .placeholder{color:#767676;line-height:24px;align-self:flex-end}.input{flex-grow:1;min-width:0;width:100%;margin-top:auto}.input .token-wrapper{display:flex;flex-wrap:wrap;flex:1 0 auto;width:100%;gap:6px}";
215
- class B {
220
+ const G = ":host{display:flex;contain:layout style}:host .additonal-content::slotted(*){align-self:end;flex-shrink:0}:host([drop]) ::slotted(*){pointer-events:none}:host(:not([readonly])) ::slotted(sd-token:last-of-type){max-width:calc(100% - 24px);margin-right:24px;margin-bottom:4px}:host ::slotted(sd-token){--sd-token-border: 1px solid transparent;margin:1px}:host([selection-mode=multi][aria-disabled=true]){opacity:.6}:host([selection-mode=multi][aria-disabled=true]) .input[effective-disabled]{opacity:1}:host([selection-mode=multi][aria-disabled=true]) ::slotted([aria-disabled=true]){opacity:1}.input[focus-visible]:focus-within ::slotted(sd-token[aria-current=true]),.container:focus-visible ::slotted(sd-token[aria-current=true]){outline:1px solid #1467ba;--sd-token-focused-border: 1px solid #fff}.input[focus-visible]:focus-within ::slotted(sd-token[aria-current=true][aria-disabled=true]:not([aria-haspopup])),.container:focus-visible ::slotted(sd-token[aria-current=true][aria-disabled=true]:not([aria-haspopup])){outline-color:#767676}.container{outline:none;display:flex;flex-wrap:wrap;gap:6px;flex-grow:1;min-width:0;margin-top:auto}.container .placeholder{color:#767676;line-height:24px;align-self:flex-end}.input{flex-grow:1;min-width:0;width:100%;margin-top:auto}.input .token-wrapper{display:flex;flex-wrap:wrap;flex:1 0 auto;width:100%;gap:6px}";
221
+ class H {
216
222
  constructor(e, t) {
217
223
  this.tokenSelector = e;
218
- const i = /* @__PURE__ */ new Map(), s = (n) => {
219
- const o = n.target;
224
+ const i = /* @__PURE__ */ new Map(), n = (s) => {
225
+ const o = s.target;
220
226
  if (e.removeAttribute("drag-source"), !e.contains(o)) {
221
- const a = n.addedIndexes;
227
+ const a = s.addedIndexes;
222
228
  a && e.removeTokens(a.map((v) => i.get(v)));
223
229
  }
224
230
  i.clear();
225
231
  };
226
- e.addEventListener("dragstart", (n) => {
227
- const o = n.target;
232
+ e.addEventListener("dragstart", (s) => {
233
+ const o = s.target;
228
234
  if (o instanceof b) {
229
235
  if (o.disabled) {
230
- n.preventDefault();
236
+ s.preventDefault();
231
237
  return;
232
238
  }
233
239
  e.setAttribute("drag-source", ""), o.setAttribute("aria-checked", "true");
234
240
  const a = e.querySelectorAll("[slot='items'][aria-checked='true']");
235
241
  if (a.length > 0) {
236
242
  const v = Array.from(a).filter((g) => !g.disabled).map((g, E) => (i.set(E, g.index), e.items[g.index]));
237
- if (n.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), n.dataTransfer.dropEffect = "move", n.dataTransfer.effectAllowed = "move", a.length > 1) {
243
+ if (s.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), s.dataTransfer.dropEffect = "move", s.dataTransfer.effectAllowed = "move", a.length > 1) {
238
244
  const g = this.createCustomDragImage(o, v.length);
239
- n.dataTransfer.setDragImage(g, -14, -14);
245
+ s.dataTransfer.setDragImage(g, -14, -14);
240
246
  }
241
- window.addEventListener("drop", s, { once: !0 });
247
+ window.addEventListener("drop", n, { once: !0 });
242
248
  }
243
249
  }
244
- }), e.addEventListener("dragenter", (n) => {
245
- e.setAttribute("drop", ""), n.preventDefault();
246
- }), e.addEventListener("dragover", (n) => n.preventDefault()), e.addEventListener("dragleave", (n) => {
247
- n.target == e && e.removeAttribute("drop");
248
- }), e.addEventListener("drop", (n) => {
250
+ }), e.addEventListener("dragenter", (s) => {
251
+ e.setAttribute("drop", ""), s.preventDefault();
252
+ }), e.addEventListener("dragover", (s) => s.preventDefault()), e.addEventListener("dragleave", (s) => {
253
+ s.target == e && e.removeAttribute("drop");
254
+ }), e.addEventListener("drop", (s) => {
249
255
  e.removeAttribute("drop");
250
- const o = n.dataTransfer.getData("text/sd-token-selector");
256
+ const o = s.dataTransfer.getData("text/sd-token-selector");
251
257
  if (o)
252
258
  try {
253
259
  const a = JSON.parse(o);
254
- Array.isArray(a) && (n.addedIndexes = t(a), n.preventDefault());
260
+ Array.isArray(a) && (s.addedIndexes = t(a), s.preventDefault());
255
261
  } catch {
256
262
  }
257
263
  }), e.addEventListener("dragend", () => {
258
- window.removeEventListener("drop", s), e.removeAttribute("drag-source"), i.clear();
264
+ window.removeEventListener("drop", n), e.removeAttribute("drag-source"), i.clear();
259
265
  });
260
266
  }
261
267
  createCustomDragImage(e, t) {
@@ -263,14 +269,14 @@ class B {
263
269
  if (i.setAttribute("aria-disabled", "true"), this.tokenSelector.tokenType)
264
270
  i.value = t + " " + this.tokenSelector.tokenType;
265
271
  else {
266
- const s = document.createElement("div");
267
- s.innerText = "+" + (t - 1), Object.assign(s.style, {
272
+ const n = document.createElement("div");
273
+ n.innerText = "+" + (t - 1), Object.assign(n.style, {
268
274
  position: "absolute",
269
275
  left: "90%",
270
276
  top: "75%"
271
277
  });
272
- const n = document.createElement("div");
273
- n.appendChild(i), n.appendChild(s), i = n;
278
+ const s = document.createElement("div");
279
+ s.appendChild(i), s.appendChild(n), i = s;
274
280
  }
275
281
  return Object.assign(i.style, {
276
282
  height: e.offsetHeight,
@@ -284,19 +290,19 @@ class B {
284
290
  }), i.slot = "items", this.tokenSelector.appendChild(i), requestAnimationFrame(() => i.remove()), i;
285
291
  }
286
292
  }
287
- var V = Object.defineProperty, K = Object.getOwnPropertyDescriptor, c = (r, e, t, i) => {
288
- for (var s = i > 1 ? void 0 : i ? K(e, t) : e, n = r.length - 1, o; n >= 0; n--)
289
- (o = r[n]) && (s = (i ? o(e, t, s) : o(s)) || s);
290
- return i && s && V(e, t, s), s;
293
+ var B = Object.defineProperty, c = (r, e, t, i) => {
294
+ for (var n = void 0, s = r.length - 1, o; s >= 0; s--)
295
+ (o = r[s]) && (n = o(e, t, n) || n);
296
+ return n && B(e, t, n), n;
291
297
  };
292
- function j(r, e) {
298
+ function K(r, e) {
293
299
  let t;
294
300
  return function(...i) {
295
301
  t != null && clearTimeout(t), t = window.setTimeout(() => r(...i), e);
296
302
  };
297
303
  }
298
304
  var U = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(U || {}), h;
299
- const l = (h = class extends w {
305
+ const l = (h = class extends x {
300
306
  constructor() {
301
307
  super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = F, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
302
308
  if ((e.key === "Enter" || this.additionalTokenCommittingKeys.includes(e.key)) && t.value) {
@@ -347,23 +353,22 @@ const l = (h = class extends w {
347
353
  }
348
354
  }
349
355
  }, this.selectOrAddItems = (e) => {
350
- const t = [], i = e.map((s, n) => {
351
- const o = s.caption == null ? -1 : this.findIndex(s);
352
- return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(n), o) : -1;
353
- }).filter((s) => s != -1);
356
+ const t = [], i = e.map((n, s) => {
357
+ const o = n.caption == null ? -1 : this.findIndex(n);
358
+ return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(s), o) : -1;
359
+ }).filter((n) => n != -1);
354
360
  return i.length > 0 && this.handleTokenSelection(i), t;
355
361
  }, this.handleWindowPointerDown = (e) => {
356
362
  const t = this.inputElement;
357
- if (!t || !t.value)
358
- return;
359
- e.composedPath().some((s) => {
360
- if (s instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || s.getAttribute("popover-for") === "token-autosuggest-popover"))
363
+ if (!t || !t.value) return;
364
+ e.composedPath().some((n) => {
365
+ if (n instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || n.getAttribute("popover-for") === "token-autosuggest-popover"))
361
366
  return !0;
362
367
  }) || this.commitTokenValue(t.value);
363
- }, this.debouncedShowTokenSuggestPopover = j(this.showFilteredTokenSuggestions.bind(this), 200);
368
+ }, this.debouncedShowTokenSuggestPopover = K(this.showFilteredTokenSuggestions.bind(this), 200);
364
369
  }
365
370
  static get styles() {
366
- return T(H);
371
+ return T(G);
367
372
  }
368
373
  get tokenGenerator() {
369
374
  return this._tokenGenerator;
@@ -392,7 +397,7 @@ const l = (h = class extends w {
392
397
  <slot name="items"
393
398
  >${this.placeholder ? m`<span part="remove-only-placeholder" class="placeholder"
394
399
  >${this.placeholder}</span
395
- >` : x}</slot
400
+ >` : w}</slot
396
401
  >
397
402
  </div>
398
403
  <slot class="additonal-content" name="additional-content" @focusin=${this.clearCheckedTokens}></slot>` : m`
@@ -420,14 +425,11 @@ const l = (h = class extends w {
420
425
  !this.contains(i) && !this.shadowRoot.contains(i) && this.clearCheckedTokens();
421
426
  }), this.addEventListener("focusin", () => {
422
427
  this.selectionMode == "remove-only" && this.activeTokenIndex == -1 && this.items.length > 0 && !this.disabled && (this.activeTokenIndex = 0);
423
- }), new G(
428
+ }), new V(
424
429
  this,
425
- () => {
426
- var t;
427
- return (t = this.inputElement) == null ? void 0 : t.value;
428
- },
430
+ () => this.inputElement?.value,
429
431
  (t) => this.selectOrAddItems(t)
430
- ), new B(this, (t) => this.selectOrAddItems(t));
432
+ ), new H(this, (t) => this.selectOrAddItems(t));
431
433
  }
432
434
  clearCheckedTokens() {
433
435
  this.querySelectorAll("[slot='items'][aria-checked='true']").forEach(
@@ -449,13 +451,12 @@ const l = (h = class extends w {
449
451
  }
450
452
  }
451
453
  updateActiveToken(e) {
452
- var i;
453
454
  if (this.disabled)
454
455
  return;
455
456
  const t = this.querySelectorAll("[slot='items']").length - 1;
456
- if (this.activeTokenIndex == -1 ? e < 0 && (this.activeTokenIndex = t) : this.activeTokenIndex == t && e > 0 && this.selectionMode == "multi" ? (this.activeTokenIndex = -1, this.focus()) : this.activeTokenIndex = Math.max(0, Math.min(t, this.activeTokenIndex + e)), this.activeTokenIndex > -1 && ((i = this.inputElement) == null || i.setAttribute("focus-visible", ""), this.scrollHeight > this.offsetHeight)) {
457
- const s = this.activeTokenElement;
458
- s.scrollIntoViewIfNeeded ? s.scrollIntoViewIfNeeded() : s.scrollIntoView();
457
+ if (this.activeTokenIndex == -1 ? e < 0 && (this.activeTokenIndex = t) : this.activeTokenIndex == t && e > 0 && this.selectionMode == "multi" ? (this.activeTokenIndex = -1, this.focus()) : this.activeTokenIndex = Math.max(0, Math.min(t, this.activeTokenIndex + e)), this.activeTokenIndex > -1 && (this.inputElement?.setAttribute("focus-visible", ""), this.scrollHeight > this.offsetHeight)) {
458
+ const i = this.activeTokenElement;
459
+ i.scrollIntoViewIfNeeded ? i.scrollIntoViewIfNeeded() : i.scrollIntoView();
459
460
  }
460
461
  }
461
462
  commitTokenValue(e) {
@@ -465,13 +466,13 @@ const l = (h = class extends w {
465
466
  const i = this.tokenSuggestPopover.focusedSuggestToken;
466
467
  if (i) {
467
468
  if (!i.disabled) {
468
- const s = this.findIndex(i);
469
- this.handleTokenSelection([s]), this.tokenSuggestPopover.hide();
469
+ const n = this.findIndex(i);
470
+ this.handleTokenSelection([n]), this.tokenSuggestPopover.hide();
470
471
  }
471
472
  return;
472
473
  }
473
474
  }
474
- if (!(e != null && e.trim()))
475
+ if (!e?.trim())
475
476
  return;
476
477
  const t = this.items.findIndex(
477
478
  (i) => this.caseSensitive ? i.caption == e : i.caption.toLowerCase() == e.toLowerCase()
@@ -517,21 +518,20 @@ const l = (h = class extends w {
517
518
  return;
518
519
  this.activeTokenIndex = -1;
519
520
  const e = this.inputElement;
520
- e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((s) => {
521
- this.removeChild(s);
521
+ e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((n) => {
522
+ this.removeChild(n);
522
523
  });
523
524
  const t = document.createDocumentFragment();
524
525
  let i = [];
525
- this.selectionMode == "remove-only" ? i = this.items.map((s) => this.disableIfNeeded(s)) : this.selectedIndexes.forEach((s) => {
526
- i.push(this.disableIfNeeded(this.items[s]));
527
- }), i.forEach((s) => {
528
- const n = this.tokenGenerator(s, this.findIndex(s));
529
- n.slot = "items", t.appendChild(n), n.id || (n.id = window.crypto.getRandomValues(new Uint32Array(1))[0].toString(16)), n.setClickHandler((o, a) => this.onTokenClick(n, !0, a)), n.addEventListener("click", () => {
530
- var a;
531
- (a = this.inputElement) == null || a.removeAttribute("focus-visible");
526
+ this.selectionMode == "remove-only" ? i = this.items.map((n) => this.disableIfNeeded(n)) : this.selectedIndexes.forEach((n) => {
527
+ i.push(this.disableIfNeeded(this.items[n]));
528
+ }), i.forEach((n) => {
529
+ const s = this.tokenGenerator(n, this.findIndex(n));
530
+ s.slot = "items", t.appendChild(s), s.id || (s.id = window.crypto.getRandomValues(new Uint32Array(1))[0].toString(16)), s.setClickHandler((o, a) => this.onTokenClick(s, !0, a)), s.addEventListener("click", () => {
531
+ this.inputElement?.removeAttribute("focus-visible");
532
532
  const o = window.getSelection();
533
533
  (!o || o.type != "Range") && document.activeElement != this && this.focus();
534
- }), n.setDeleteHandler((o) => this.removeTokens([o]));
534
+ }), s.setDeleteHandler((o) => this.removeTokens([o]));
535
535
  }), this.appendChild(t), this._tokenSuggestPopover && this._tokenSuggestPopover.refreshItems();
536
536
  }
537
537
  removeTokens(e) {
@@ -557,10 +557,10 @@ const l = (h = class extends w {
557
557
  }
558
558
  }
559
559
  onTokenClick(e, t, i) {
560
- let s;
561
- this.querySelectorAll("[slot='items']").forEach((n, o) => {
562
- e == n ? s = o : i || n.setAttribute("aria-checked", "false");
563
- }), this.activeTokenIndex = s, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), i || this.dispatchEvent(
560
+ let n;
561
+ this.querySelectorAll("[slot='items']").forEach((s, o) => {
562
+ e == s ? n = o : i || s.setAttribute("aria-checked", "false");
563
+ }), this.activeTokenIndex = n, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), i || this.dispatchEvent(
564
564
  new CustomEvent("token-clicked", {
565
565
  detail: {
566
566
  index: e.index,
@@ -620,33 +620,32 @@ const l = (h = class extends w {
620
620
  }
621
621
  }
622
622
  get hasInputValue() {
623
- var e;
624
- return !!((e = this.inputElement) != null && e.value);
623
+ return !!this.inputElement?.value;
625
624
  }
626
625
  }, h.ID = "sd-token-selector", h.ensureDefined = () => {
627
626
  b.ensureDefined(), customElements.get(h.ID) || customElements.define(h.ID, h);
628
627
  }, h.shadowRootOptions = {
629
- ...w.shadowRootOptions,
628
+ ...x.shadowRootOptions,
630
629
  delegatesFocus: !0
631
630
  }, h);
632
631
  c([
633
632
  d({ type: String, attribute: "selection-mode", reflect: !0 })
634
- ], l.prototype, "selectionMode", 2);
633
+ ], l.prototype, "selectionMode");
635
634
  c([
636
635
  d({ type: Array, attribute: !1 })
637
- ], l.prototype, "items", 2);
636
+ ], l.prototype, "items");
638
637
  c([
639
638
  d({ type: Array, attribute: !1 })
640
- ], l.prototype, "selectedIndexes", 2);
639
+ ], l.prototype, "selectedIndexes");
641
640
  c([
642
641
  d({ type: String, reflect: !0 })
643
- ], l.prototype, "placeholder", 2);
642
+ ], l.prototype, "placeholder");
644
643
  c([
645
644
  d({ type: String, reflect: !0, attribute: "suggest-list-class" })
646
- ], l.prototype, "suggestListClass", 2);
645
+ ], l.prototype, "suggestListClass");
647
646
  c([
648
647
  d({ type: String, reflect: !0, attribute: "input-label" })
649
- ], l.prototype, "inputLabel", 2);
648
+ ], l.prototype, "inputLabel");
650
649
  c([
651
650
  d({
652
651
  converter: {
@@ -656,26 +655,26 @@ c([
656
655
  reflect: !0,
657
656
  attribute: "aria-disabled"
658
657
  })
659
- ], l.prototype, "disabled", 2);
658
+ ], l.prototype, "disabled");
660
659
  c([
661
660
  d({ type: String, attribute: !0 })
662
- ], l.prototype, "validationMessage", 2);
661
+ ], l.prototype, "validationMessage");
663
662
  c([
664
663
  d({ type: String, attribute: !0 })
665
- ], l.prototype, "validationIconSrc", 2);
664
+ ], l.prototype, "validationIconSrc");
666
665
  c([
667
666
  d({ converter: S.levelConverter, attribute: !0, reflect: !0 })
668
- ], l.prototype, "validationLevel", 2);
667
+ ], l.prototype, "validationLevel");
669
668
  c([
670
669
  d({ type: String, reflect: !0, attribute: "token-type" })
671
- ], l.prototype, "tokenType", 2);
670
+ ], l.prototype, "tokenType");
672
671
  c([
673
672
  d({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
674
- ], l.prototype, "caseSensitive", 2);
675
- let ne = l;
673
+ ], l.prototype, "caseSensitive");
674
+ let se = l;
676
675
  export {
677
676
  U as SelectionMode,
678
- ne as default,
677
+ se as default,
679
678
  F as generator
680
679
  };
681
680
  //# sourceMappingURL=token-selector.mjs.map