@cas-smartdesign/token-selector 0.20.0 → 0.21.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,17 +1,18 @@
1
- import { LitElement as x, unsafeCSS as T, html as m, nothing as I } from "lit";
2
- import { property as a } from "lit/decorators/property.js";
1
+ import { LitElement as w, unsafeCSS as T, html as v, nothing as x } from "lit";
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";
5
5
  import { generator as _ } from "@cas-smartdesign/list-item";
6
6
  import L from "@cas-smartdesign/popover";
7
7
  import y from "@cas-smartdesign/virtual-list";
8
- import { KeyDownDelegator as C } from "@cas-smartdesign/element-utils";
9
- import { ifDefined as A } from "lit/directives/if-defined.js";
8
+ import { KeyDownDelegator as A } from "@cas-smartdesign/element-utils";
9
+ import { ifDefined as C } from "lit/directives/if-defined.js";
10
10
  import { unsafeSVG as P } from "lit/directives/unsafe-svg.js";
11
11
  import D from "@cas-smartdesign/image-tools";
12
- class O {
13
- constructor(e, t, i, n) {
14
- this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback = n, this.filter = (s, o) => s ? o.filter((d) => d.disabled || d.deactivated ? !1 : d.caption && d.caption.toLowerCase().includes(s)) : o, y.ensureDefined(), this._tokenList = new y(), this._tokenList.style.minWidth = "250px", this._tokenList.style.maxHeight = "49vh", this._tokenList.itemHeight = 50, this._tokenList.addEventListener("pointerdown", () => {
12
+ let O = 0;
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", () => {
15
16
  this.pointerDown = !0, window.addEventListener(
16
17
  "pointerup",
17
18
  () => {
@@ -19,16 +20,16 @@ class O {
19
20
  },
20
21
  { once: !0, capture: !0 }
21
22
  );
22
- }), this._tokenList.addEventListener("selection", (s) => {
23
- const o = s.detail.index, d = this._suggestItems[o];
24
- i(d), this.hide();
25
- }), this._tokenList.addEventListener("data-request", (s) => {
26
- this.lastRequestedStartIndex = s.detail.startIndex, this.lastRequestedStopIndex = s.detail.stopIndex, this.pointerDown || this._tokenList.increaseWidthOnNextRenderIfNeeded(), this._tokenList.items = this._suggestItems.slice(
23
+ }), this._tokenList.addEventListener("selection", (n) => {
24
+ const o = n.detail.index, a = this._suggestItems[o];
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(
27
28
  this.lastRequestedStartIndex,
28
29
  this.lastRequestedStopIndex + 1
29
30
  );
30
- }), new C(this._tokenList, (s, o, d) => {
31
- this._tokenList.dispatchEvent(new KeyboardEvent(s.type, s)), !d && !this.isOpened && this.show();
31
+ }), new A(this._tokenList, (n, o, a) => {
32
+ this._tokenList.dispatchEvent(new KeyboardEvent(n.type, n)), !a && !this.isOpened && this.show();
32
33
  }).connect(e);
33
34
  }
34
35
  show() {
@@ -67,25 +68,25 @@ class O {
67
68
  return this._suggestItems[this._tokenList.focusIndex];
68
69
  }
69
70
  }
70
- const q = `:host{flex-shrink:0;max-width:100%}:host([aria-checked=true]){position:relative}:host([aria-checked=true]):before{content:"";position:absolute;left:0;top:0;height:12px;width:12px;background:#1467ba url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='12'%20fill='none'%3e%3cpath%20stroke='%23FFF'%20stroke-width='2'%20d='M9%204%205%208%203%206'/%3e%3c/svg%3e") no-repeat center center}.container{display:flex;height:28px;background-color:var(--sd-token-background-color, #f3f3f3);border:var(--sd-token-focused-border, var(--sd-token-border));box-sizing:border-box}.container .icon-wrapper{display:flex;flex-shrink:0;justify-content:center;align-items:center;width:28px;height:100%;overflow:hidden;background-color:var(--sd-token-icon-background-color, transparent)}.container .icon-wrapper .icon{height:100%;width:100%;object-fit:contain;background-size:cover;background-repeat:no-repeat;background-position:center}.container .value{display:inline-block;align-self:center;padding:0 8px;font-family:Segoe UI,Lucida Sans,Arial,sans-serif;font-size:16px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.container .delete-button-wrapper{display:flex;align-self:center;height:16px;width:16px;padding-right:8px;opacity:.5}.container .delete-button-wrapper:hover{cursor:pointer;filter:brightness(10%);opacity:1}`, M = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">\r
71
+ const M = `:host{flex-shrink:0;max-width:100%;height:28px}:host([aria-checked=true]){position:relative}:host([aria-checked=true]):before{content:"";position:absolute;left:0;top:0;height:12px;width:12px;background:#1467ba url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='12'%20fill='none'%3e%3cpath%20stroke='%23FFF'%20stroke-width='2'%20d='M9%204%205%208%203%206'/%3e%3c/svg%3e") no-repeat center center}.container{display:flex;height:100%;background-color:var(--sd-token-background-color, #f3f3f3);border:var(--sd-token-focused-border, var(--sd-token-border));box-sizing:border-box}.container .icon-wrapper{display:flex;flex-shrink:0;justify-content:center;align-items:center;width:28px;height:100%;overflow:hidden;background-color:var(--sd-token-icon-background-color, transparent)}.container .icon-wrapper .icon{height:100%;width:100%;object-fit:contain;background-size:cover;background-repeat:no-repeat;background-position:center}.container .value{display:inline-block;align-self:center;padding:0 8px;font-family:Segoe UI,Lucida Sans,Arial,sans-serif;font-size:16px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.container .delete-button-wrapper{display:flex;align-self:center;height:16px;width:16px;padding-right:8px;opacity:.5}.container .delete-button-wrapper:hover{cursor:pointer;filter:brightness(10%);opacity:1}`, $ = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">\r
71
72
  <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
72
73
  </svg>`;
73
- var $ = Object.defineProperty, R = Object.getOwnPropertyDescriptor, g = (r, e, t, i) => {
74
- for (var n = i > 1 ? void 0 : i ? R(e, t) : e, s = r.length - 1, o; s >= 0; s--)
75
- (o = r[s]) && (n = (i ? o(e, t, n) : o(n)) || n);
76
- return i && n && $(e, t, n), n;
74
+ 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
78
  };
78
- const w = {
79
+ const I = {
79
80
  fromAttribute: (r) => r == "true",
80
81
  toAttribute: (r) => r
81
82
  };
82
83
  var u;
83
- const p = (u = class extends x {
84
+ const p = (u = class extends w {
84
85
  constructor() {
85
86
  super(...arguments), this.value = "", this.type = "", this.icon = "", this.iconPlaceholder = "", this.iconBackgroundColor = "", this._checked = !1;
86
87
  }
87
88
  static get styles() {
88
- return T(q);
89
+ return T(M);
89
90
  }
90
91
  set checked(e) {
91
92
  const t = this._checked;
@@ -96,7 +97,12 @@ const p = (u = class extends x {
96
97
  }
97
98
  firstUpdated(e) {
98
99
  super.firstUpdated(e), this.tabIndex = -1, this.setAttribute("role", "option"), this.setAttribute("aria-selected", "true"), this.addEventListener("click", (i) => {
99
- i.stopPropagation(), i.getModifierState("Control") ? this.checked = !this.checked : (this.checked = !0, this._tokenClickHandler && this._tokenClickHandler(this.index));
100
+ const s = window.getSelection();
101
+ if (s && s.type == "Range" || this.disabled)
102
+ return;
103
+ i.stopPropagation();
104
+ const n = i.getModifierState("Control");
105
+ n ? this.checked = !this.checked : this.checked = !0, this._tokenClickHandler && this._tokenClickHandler(this.index, n);
100
106
  });
101
107
  const t = this.shadowRoot.querySelector(".delete-button-wrapper");
102
108
  t && t.addEventListener("click", (i) => {
@@ -104,26 +110,26 @@ const p = (u = class extends x {
104
110
  });
105
111
  }
106
112
  render() {
107
- return m`
113
+ return v`
108
114
  <div class="container">
109
115
  <slot name="before-icon"></slot>
110
116
  ${this.renderIcon()}
111
117
  <slot name="after-icon"></slot>
112
118
  <div class="value">${this.value}</div>
113
- ${this.disabled ? I : m` <div class="delete-button-wrapper">${P(M)}</div> `}
119
+ ${this.disabled ? x : v` <div class="delete-button-wrapper">${P($)}</div> `}
114
120
  </div>
115
121
  `;
116
122
  }
117
123
  renderIcon() {
118
124
  if (this.icon || this.iconPlaceholder) {
119
125
  const e = this.iconBackgroundColor != null ? `--sd-token-icon-background-color: ${this.iconBackgroundColor}` : void 0;
120
- return m`
121
- <div class="icon-wrapper" style="${A(e)}" role="img">
126
+ return v`
127
+ <div class="icon-wrapper" style="${C(e)}" role="img">
122
128
  <div part="icon" class="icon"></div>
123
129
  </div>
124
130
  `;
125
131
  }
126
- return I;
132
+ return x;
127
133
  }
128
134
  updated(e) {
129
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);
@@ -137,41 +143,42 @@ const p = (u = class extends x {
137
143
  }, u.ID = "sd-token", u.ensureDefined = () => {
138
144
  customElements.get(u.ID) || customElements.define(u.ID, u);
139
145
  }, u);
140
- g([
141
- a({ type: String, attribute: !0, reflect: !0 })
146
+ f([
147
+ d({ type: String, attribute: !0, reflect: !0 })
142
148
  ], p.prototype, "value", 2);
143
- g([
144
- a({ type: String, attribute: !0, reflect: !0 })
149
+ f([
150
+ d({ type: String, attribute: !0, reflect: !0 })
145
151
  ], p.prototype, "type", 2);
146
- g([
147
- a({ type: String })
152
+ f([
153
+ d({ type: String })
148
154
  ], p.prototype, "icon", 2);
149
- g([
150
- a({ type: String })
155
+ f([
156
+ d({ type: String })
151
157
  ], p.prototype, "iconPlaceholder", 2);
152
- g([
153
- a({ type: String })
158
+ f([
159
+ d({ type: String })
154
160
  ], p.prototype, "iconBackgroundColor", 2);
155
- g([
156
- a({ converter: w, reflect: !0, attribute: "aria-disabled" })
161
+ f([
162
+ d({ converter: I, reflect: !0, attribute: "aria-disabled" })
157
163
  ], p.prototype, "disabled", 2);
158
- g([
159
- a({ converter: w, reflect: !0, attribute: "aria-current" })
164
+ f([
165
+ d({ converter: I, reflect: !0, attribute: "aria-current" })
160
166
  ], p.prototype, "current", 2);
161
- g([
162
- a({ converter: w, reflect: !0, attribute: "aria-checked" })
167
+ f([
168
+ d({ converter: I, reflect: !0, attribute: "aria-checked" })
163
169
  ], p.prototype, "checked", 1);
164
170
  let b = p;
165
- const N = (r, e) => {
171
+ const F = (r, e) => {
166
172
  const t = document.createElement(b.ID);
167
173
  return r && (t.value = r.caption, t.type = r.type, t.icon = r.icon, t.iconPlaceholder = r.iconPlaceholder, t.iconBackgroundColor = r.iconBackgroundColor, t.disabled = r.disabled, t.index = e), t;
168
174
  };
169
175
  b.ensureDefined();
170
176
  const k = "web application/json";
171
- class F {
177
+ class G {
172
178
  constructor(e, t, i) {
173
179
  navigator.clipboard && (e.addEventListener("copy", () => {
174
- t() || this.writeToClipboard(e);
180
+ const s = window.getSelection();
181
+ (!s || s.type != "Range") && !t() && this.writeToClipboard(e);
175
182
  }), e.addEventListener("cut", () => {
176
183
  t() || (e.removeSelectionOrActiveToken(), this.writeToClipboard(e));
177
184
  }), e.addEventListener("paste", () => {
@@ -181,16 +188,16 @@ class F {
181
188
  writeToClipboard(e) {
182
189
  const t = e.querySelectorAll("[slot='items'][aria-checked='true']"), i = [];
183
190
  if (t.length > 0)
184
- t.forEach((n) => i.push(n.index));
191
+ t.forEach((s) => i.push(s.index));
185
192
  else if (e.activeTokenIndex != -1) {
186
- const n = e.activeTokenElement;
187
- n && i.push(n.index);
193
+ const s = e.activeTokenElement;
194
+ s && i.push(s.index);
188
195
  }
189
196
  if (i.length > 0) {
190
- const n = JSON.stringify(i.map((o) => e.items[o])), s = new Blob([n], { type: k });
197
+ const s = JSON.stringify(i.map((o) => e.items[o])), n = new Blob([s], { type: k });
191
198
  navigator.clipboard.write([
192
199
  new ClipboardItem({
193
- [k]: s
200
+ [k]: n
194
201
  })
195
202
  ]);
196
203
  }
@@ -199,56 +206,56 @@ class F {
199
206
  const t = await navigator.clipboard.read();
200
207
  for (const i of t)
201
208
  if (i.types.includes(k)) {
202
- const s = await (await i.getType(k)).text(), o = JSON.parse(s);
209
+ const n = await (await i.getType(k)).text(), o = JSON.parse(n);
203
210
  Array.isArray(o) && e(o);
204
211
  }
205
212
  }
206
213
  }
207
- 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:2px}.input:focus-within ::slotted(sd-token[aria-current=true]),.container:focus-within ::slotted(sd-token[aria-current=true]){outline:2px solid #1467ba;--sd-token-focused-border: 1px solid #fff}.container{outline:none;display:flex;flex-wrap:wrap;gap:4px;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:8px}";
208
- class H {
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}.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 {
209
216
  constructor(e, t) {
210
217
  this.tokenSelector = e;
211
- const i = /* @__PURE__ */ new Map(), n = (s) => {
212
- const o = s.target;
218
+ const i = /* @__PURE__ */ new Map(), s = (n) => {
219
+ const o = n.target;
213
220
  if (e.removeAttribute("drag-source"), !e.contains(o)) {
214
- const d = s.addedIndexes;
215
- d && e.removeTokens(d.map((v) => i.get(v)));
221
+ const a = n.addedIndexes;
222
+ a && e.removeTokens(a.map((m) => i.get(m)));
216
223
  }
217
224
  i.clear();
218
225
  };
219
- e.addEventListener("dragstart", (s) => {
220
- const o = s.target;
226
+ e.addEventListener("dragstart", (n) => {
227
+ const o = n.target;
221
228
  if (o instanceof b) {
222
229
  if (o.disabled) {
223
- s.preventDefault();
230
+ n.preventDefault();
224
231
  return;
225
232
  }
226
233
  e.setAttribute("drag-source", ""), o.setAttribute("aria-checked", "true");
227
- const d = e.querySelectorAll("[slot='items'][aria-checked='true']");
228
- if (d.length > 0) {
229
- const v = Array.from(d).filter((f) => !f.disabled).map((f, E) => (i.set(E, f.index), e.items[f.index]));
230
- if (s.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), s.dataTransfer.dropEffect = "move", s.dataTransfer.effectAllowed = "move", d.length > 1) {
231
- const f = this.createCustomDragImage(o, v.length);
232
- s.dataTransfer.setDragImage(f, -14, -14);
234
+ const a = e.querySelectorAll("[slot='items'][aria-checked='true']");
235
+ if (a.length > 0) {
236
+ const m = 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(m)), n.dataTransfer.dropEffect = "move", n.dataTransfer.effectAllowed = "move", a.length > 1) {
238
+ const g = this.createCustomDragImage(o, m.length);
239
+ n.dataTransfer.setDragImage(g, -14, -14);
233
240
  }
234
- window.addEventListener("drop", n, { once: !0 });
241
+ window.addEventListener("drop", s, { once: !0 });
235
242
  }
236
243
  }
237
- }), e.addEventListener("dragenter", (s) => {
238
- e.setAttribute("drop", ""), s.preventDefault();
239
- }), e.addEventListener("dragover", (s) => s.preventDefault()), e.addEventListener("dragleave", (s) => {
240
- s.target == e && e.removeAttribute("drop");
241
- }), e.addEventListener("drop", (s) => {
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) => {
242
249
  e.removeAttribute("drop");
243
- const o = s.dataTransfer.getData("text/sd-token-selector");
250
+ const o = n.dataTransfer.getData("text/sd-token-selector");
244
251
  if (o)
245
252
  try {
246
- const d = JSON.parse(o);
247
- Array.isArray(d) && (s.addedIndexes = t(d), s.preventDefault());
253
+ const a = JSON.parse(o);
254
+ Array.isArray(a) && (n.addedIndexes = t(a), n.preventDefault());
248
255
  } catch {
249
256
  }
250
257
  }), e.addEventListener("dragend", () => {
251
- window.removeEventListener("drop", n), e.removeAttribute("drag-source"), i.clear();
258
+ window.removeEventListener("drop", s), e.removeAttribute("drag-source"), i.clear();
252
259
  });
253
260
  }
254
261
  createCustomDragImage(e, t) {
@@ -256,14 +263,14 @@ class H {
256
263
  if (i.setAttribute("aria-disabled", "true"), this.tokenSelector.tokenType)
257
264
  i.value = t + " " + this.tokenSelector.tokenType;
258
265
  else {
259
- const n = document.createElement("div");
260
- n.innerText = "+" + (t - 1), Object.assign(n.style, {
266
+ const s = document.createElement("div");
267
+ s.innerText = "+" + (t - 1), Object.assign(s.style, {
261
268
  position: "absolute",
262
269
  left: "90%",
263
270
  top: "75%"
264
271
  });
265
- const s = document.createElement("div");
266
- s.appendChild(i), s.appendChild(n), i = s;
272
+ const n = document.createElement("div");
273
+ n.appendChild(i), n.appendChild(s), i = n;
267
274
  }
268
275
  return Object.assign(i.style, {
269
276
  height: e.offsetHeight,
@@ -277,23 +284,23 @@ class H {
277
284
  }), i.slot = "items", this.tokenSelector.appendChild(i), requestAnimationFrame(() => i.remove()), i;
278
285
  }
279
286
  }
280
- var B = Object.defineProperty, V = Object.getOwnPropertyDescriptor, h = (r, e, t, i) => {
281
- for (var n = i > 1 ? void 0 : i ? V(e, t) : e, s = r.length - 1, o; s >= 0; s--)
282
- (o = r[s]) && (n = (i ? o(e, t, n) : o(n)) || n);
283
- return i && n && B(e, t, n), n;
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;
284
291
  };
285
- function K(r, e) {
292
+ function j(r, e) {
286
293
  let t;
287
294
  return function(...i) {
288
295
  t != null && clearTimeout(t), t = window.setTimeout(() => r(...i), e);
289
296
  };
290
297
  }
291
- var j = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(j || {}), c;
292
- const l = (c = class extends x {
298
+ var U = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(U || {}), h;
299
+ const l = (h = class extends w {
293
300
  constructor() {
294
- super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = N, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
301
+ super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = F, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
295
302
  if ((e.key === "Enter" || this.additionalTokenCommittingKeys.includes(e.key)) && t.value) {
296
- e.preventDefault(), e.stopPropagation(), this.commitTokenValue(t.value);
303
+ e.preventDefault(), e.stopPropagation(), this.commitTokenValue(t.value), this.inputElement.removeAttribute("focus-visible");
297
304
  return;
298
305
  }
299
306
  switch (e.key) {
@@ -302,7 +309,7 @@ const l = (c = class extends x {
302
309
  break;
303
310
  }
304
311
  case "Tab": {
305
- this.commitTokenValue(t.value), this.tokenSuggestPopover.hide();
312
+ this.commitTokenValue(t.value), this.tokenSuggestPopover.hide(), this.inputElement.removeAttribute("focus-visible");
306
313
  break;
307
314
  }
308
315
  default:
@@ -320,8 +327,8 @@ const l = (c = class extends x {
320
327
  }
321
328
  case "Enter": {
322
329
  if (!this.hasInputValue && this.activeTokenIndex != -1) {
323
- const t = this.activeTokenElement;
324
- e.getModifierState("Control") ? t.checked = !t.checked : (t.checked = !0, this.onTokenClick(t, !1)), document.activeElement != this && this.focus();
330
+ const t = this.activeTokenElement, i = e.getModifierState("Control");
331
+ i ? t.checked = !t.checked : t.checked = !0, this.onTokenClick(t, !1, i), document.activeElement != this && this.focus();
325
332
  }
326
333
  break;
327
334
  }
@@ -340,23 +347,23 @@ const l = (c = class extends x {
340
347
  }
341
348
  }
342
349
  }, this.selectOrAddItems = (e) => {
343
- const t = [], i = e.map((n, s) => {
344
- const o = n.caption == null ? -1 : this.findIndex(n);
345
- return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(s), o) : -1;
346
- }).filter((n) => n != -1);
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);
347
354
  return i.length > 0 && this.handleTokenSelection(i), t;
348
355
  }, this.handleWindowPointerDown = (e) => {
349
356
  const t = this.inputElement;
350
357
  if (!t || !t.value)
351
358
  return;
352
- e.composedPath().some((n) => {
353
- if (n instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || n.getAttribute("popover-for") === "token-autosuggest-popover"))
359
+ e.composedPath().some((s) => {
360
+ if (s instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || s.getAttribute("popover-for") === "token-autosuggest-popover"))
354
361
  return !0;
355
362
  }) || this.commitTokenValue(t.value);
356
- }, this.debouncedShowTokenSuggestPopover = K(this.showFilteredTokenSuggestions.bind(this), 200);
363
+ }, this.debouncedShowTokenSuggestPopover = j(this.showFilteredTokenSuggestions.bind(this), 200);
357
364
  }
358
365
  static get styles() {
359
- return T(G);
366
+ return T(H);
360
367
  }
361
368
  get tokenGenerator() {
362
369
  return this._tokenGenerator;
@@ -377,17 +384,18 @@ const l = (c = class extends x {
377
384
  this.inputElement && (this.focus(), this.tokenSuggestPopover.show());
378
385
  }
379
386
  focus() {
380
- this.inputElement ? this.inputElement.focus() : this.shadowRoot.querySelector(".container").focus();
387
+ const e = this.inputElement;
388
+ e ? e.focus() : this.shadowRoot.querySelector(".container").focus();
381
389
  }
382
390
  render() {
383
- return this.selectionMode == "remove-only" ? m`<div class="container" tabindex="0">
391
+ return this.selectionMode == "remove-only" ? v`<div class="container" tabindex="${this.disabled ? -1 : 0}">
384
392
  <slot name="items"
385
- >${this.placeholder ? m`<span part="remove-only-placeholder" class="placeholder"
393
+ >${this.placeholder ? v`<span part="remove-only-placeholder" class="placeholder"
386
394
  >${this.placeholder}</span
387
- >` : I}</slot
395
+ >` : x}</slot
388
396
  >
389
397
  </div>
390
- <slot class="additonal-content" name="additional-content" @focusin=${this.clearCheckedTokens}></slot>` : m`
398
+ <slot class="additonal-content" name="additional-content" @focusin=${this.clearCheckedTokens}></slot>` : v`
391
399
  <sd-lit-input
392
400
  class="input"
393
401
  .extendedPrefix=${!0}
@@ -398,31 +406,35 @@ const l = (c = class extends x {
398
406
  .alwaysFloatLabel=${this.selectedIndexes.length > 0}
399
407
  .placeholder=${this.selectedIndexes.length == 0 ? this.placeholder : ""}
400
408
  .disabled=${this.disabled}
409
+ aria-autocomplete="list"
401
410
  tabindex="0"
411
+ @focus=${(e) => e.target.setAttribute("focused", "")}
402
412
  ><div class="token-wrapper" slot="prefix"><slot name="items"></slot></div>
403
413
  </sd-lit-input>
404
414
  <slot class="additonal-content" name="additional-content" @focusin=${this.clearCheckedTokens}></slot>
405
415
  `;
406
416
  }
407
417
  firstUpdated(e) {
408
- super.firstUpdated(e), this.setAttribute("role", "listbox"), this.setAttribute("aria-multiselectable", "true"), this.hasAttribute("tabIndex") || (this.tabIndex = 0), this.addEventListener("focusout", (t) => {
418
+ super.firstUpdated(e), this.setAttribute("role", "listbox"), this.setAttribute("aria-multiselectable", "true"), !this.hasAttribute("tabIndex") && !this.disabled && (this.tabIndex = 0), this.addEventListener("focusout", (t) => {
409
419
  const i = t.relatedTarget;
410
420
  !this.contains(i) && !this.shadowRoot.contains(i) && this.clearCheckedTokens();
411
421
  }), this.addEventListener("focusin", () => {
412
- this.selectionMode == "remove-only" && this.activeTokenIndex == -1 && this.items.length > 0 && (this.activeTokenIndex = 0);
413
- }), new F(
422
+ this.selectionMode == "remove-only" && this.activeTokenIndex == -1 && this.items.length > 0 && !this.disabled && (this.activeTokenIndex = 0);
423
+ }), new G(
414
424
  this,
415
425
  () => {
416
426
  var t;
417
427
  return (t = this.inputElement) == null ? void 0 : t.value;
418
428
  },
419
429
  (t) => this.selectOrAddItems(t)
420
- ), new H(this, (t) => this.selectOrAddItems(t));
430
+ ), new B(this, (t) => this.selectOrAddItems(t));
421
431
  }
422
432
  clearCheckedTokens() {
423
433
  this.querySelectorAll("[slot='items'][aria-checked='true']").forEach(
424
- (e) => e.checked = !1
434
+ (t) => t.checked = !1
425
435
  );
436
+ const e = this.inputElement;
437
+ e && (e.removeAttribute("focus-visible"), e.removeAttribute("focused"));
426
438
  }
427
439
  removeSelectionOrActiveToken() {
428
440
  if (!this.disabled) {
@@ -437,10 +449,13 @@ const l = (c = class extends x {
437
449
  }
438
450
  }
439
451
  updateActiveToken(e) {
452
+ var i;
453
+ if (this.disabled)
454
+ return;
440
455
  const t = this.querySelectorAll("[slot='items']").length - 1;
441
- 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.scrollHeight > this.offsetHeight) {
442
- const i = this.activeTokenElement;
443
- i.scrollIntoViewIfNeeded ? i.scrollIntoViewIfNeeded() : i.scrollIntoView();
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();
444
459
  }
445
460
  }
446
461
  commitTokenValue(e) {
@@ -450,8 +465,8 @@ const l = (c = class extends x {
450
465
  const i = this.tokenSuggestPopover.focusedSuggestToken;
451
466
  if (i) {
452
467
  if (!i.disabled) {
453
- const n = this.findIndex(i);
454
- this.handleTokenSelection([n]), this.tokenSuggestPopover.hide();
468
+ const s = this.findIndex(i);
469
+ this.handleTokenSelection([s]), this.tokenSuggestPopover.hide();
455
470
  }
456
471
  return;
457
472
  }
@@ -471,7 +486,7 @@ const l = (c = class extends x {
471
486
  t.addEventListener("immediate-value-change", (i) => this.handleInputValueChange(i)), t.addEventListener("keydown", (i) => this.handleInputKeyDown(i, t)), window.queueMicrotask(() => this.tokenSuggestPopover);
472
487
  } else
473
488
  this.removeAttribute("aria-haspopup"), this.addEventListener("keydown", this.handleKeyDown), this._tokenSuggestPopover && (this._tokenSuggestPopover.popover.remove(), this._tokenSuggestPopover = null);
474
- (e.size == 0 || e.has("selectionMode") || e.has("items") || e.has("selectedIndexes") || e.has("disabled")) && this.updateItems();
489
+ (e.size == 0 || e.has("selectionMode") || e.has("items") || e.has("selectedIndexes") || e.has("disabled")) && this.updateItems(), e.has("inputLabel") && (this.inputLabel ? this.setAttribute("aria-label", this.inputLabel) : this.removeAttribute("aria-label"));
475
490
  }
476
491
  handleInputValueChange(e) {
477
492
  e.detail.value ? (this.activeTokenIndex = -1, this.cancelSearch = !1, this.debouncedShowTokenSuggestPopover(), window.addEventListener("pointerdown", this.handleWindowPointerDown)) : (this.tokenSuggestPopover.hide(), this.cancelSearch = !0);
@@ -483,7 +498,7 @@ const l = (c = class extends x {
483
498
  return !this.selectedIndexes.includes(e);
484
499
  }
485
500
  get tokenSuggestPopover() {
486
- return !this._tokenSuggestPopover && this.inputElement && (this._tokenSuggestPopover = new O(
501
+ return !this._tokenSuggestPopover && this.inputElement && (this._tokenSuggestPopover = new q(
487
502
  this.inputElement,
488
503
  () => this.items.filter((e, t) => !e.disabled && this.isTokenNotSelected(t)),
489
504
  (e) => {
@@ -491,7 +506,7 @@ const l = (c = class extends x {
491
506
  this.handleTokenSelection([t]), window.removeEventListener("pointerdown", this.handleWindowPointerDown);
492
507
  },
493
508
  (e) => {
494
- this.appendChild(e.popover), this.dispatchEvent(new CustomEvent("auto-suggest-initialized")), e.popover.addEventListener("close", () => {
509
+ this.appendChild(e.popover), this.inputElement.setAttribute("aria-controls", e.list.id), this.dispatchEvent(new CustomEvent("auto-suggest-initialized")), e.popover.addEventListener("close", () => {
495
510
  this.inputElement.value && !this.contains(document.activeElement) && (this.inputElement.value = "");
496
511
  });
497
512
  }
@@ -502,18 +517,21 @@ const l = (c = class extends x {
502
517
  return;
503
518
  this.activeTokenIndex = -1;
504
519
  const e = this.inputElement;
505
- e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((n) => {
506
- this.removeChild(n);
520
+ e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((s) => {
521
+ this.removeChild(s);
507
522
  });
508
523
  const t = document.createDocumentFragment();
509
524
  let i = [];
510
- this.selectionMode == "remove-only" ? i = this.items.map((n) => this.disableIfNeeded(n)) : this.selectedIndexes.forEach((n) => {
511
- i.push(this.disableIfNeeded(this.items[n]));
512
- }), i.forEach((n) => {
513
- const s = this.tokenGenerator(n, this.findIndex(n));
514
- s.slot = "items", t.appendChild(s), s.id || (s.id = window.crypto.getRandomValues(new Uint32Array(1))[0].toString(16)), s.setClickHandler(() => this.onTokenClick(s, !0)), s.addEventListener("click", () => {
515
- document.activeElement != this && this.focus();
516
- }), s.setDeleteHandler((o) => this.removeTokens([o]));
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");
532
+ const o = window.getSelection();
533
+ (!o || o.type != "Range") && document.activeElement != this && this.focus();
534
+ }), n.setDeleteHandler((o) => this.removeTokens([o]));
517
535
  }), this.appendChild(t), this._tokenSuggestPopover && this._tokenSuggestPopover.refreshItems();
518
536
  }
519
537
  removeTokens(e) {
@@ -538,11 +556,11 @@ const l = (c = class extends x {
538
556
  ));
539
557
  }
540
558
  }
541
- onTokenClick(e, t) {
542
- let i;
543
- this.querySelectorAll("[slot='items']").forEach((n, s) => {
544
- e == n ? i = s : n.setAttribute("aria-checked", "false");
545
- }), this.activeTokenIndex = i, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), this.dispatchEvent(
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(
546
564
  new CustomEvent("token-clicked", {
547
565
  detail: {
548
566
  index: e.index,
@@ -605,32 +623,32 @@ const l = (c = class extends x {
605
623
  var e;
606
624
  return !!((e = this.inputElement) != null && e.value);
607
625
  }
608
- }, c.ID = "sd-token-selector", c.ensureDefined = () => {
609
- b.ensureDefined(), customElements.get(c.ID) || customElements.define(c.ID, c);
610
- }, c.shadowRootOptions = {
611
- ...x.shadowRootOptions,
626
+ }, h.ID = "sd-token-selector", h.ensureDefined = () => {
627
+ b.ensureDefined(), customElements.get(h.ID) || customElements.define(h.ID, h);
628
+ }, h.shadowRootOptions = {
629
+ ...w.shadowRootOptions,
612
630
  delegatesFocus: !0
613
- }, c);
614
- h([
615
- a({ type: String, attribute: "selection-mode", reflect: !0 })
631
+ }, h);
632
+ c([
633
+ d({ type: String, attribute: "selection-mode", reflect: !0 })
616
634
  ], l.prototype, "selectionMode", 2);
617
- h([
618
- a({ type: Array, attribute: !1 })
635
+ c([
636
+ d({ type: Array, attribute: !1 })
619
637
  ], l.prototype, "items", 2);
620
- h([
621
- a({ type: Array, attribute: !1 })
638
+ c([
639
+ d({ type: Array, attribute: !1 })
622
640
  ], l.prototype, "selectedIndexes", 2);
623
- h([
624
- a({ type: String, reflect: !0 })
641
+ c([
642
+ d({ type: String, reflect: !0 })
625
643
  ], l.prototype, "placeholder", 2);
626
- h([
627
- a({ type: String, reflect: !0, attribute: "suggest-list-class" })
644
+ c([
645
+ d({ type: String, reflect: !0, attribute: "suggest-list-class" })
628
646
  ], l.prototype, "suggestListClass", 2);
629
- h([
630
- a({ type: String, reflect: !0, attribute: "input-label" })
647
+ c([
648
+ d({ type: String, reflect: !0, attribute: "input-label" })
631
649
  ], l.prototype, "inputLabel", 2);
632
- h([
633
- a({
650
+ c([
651
+ d({
634
652
  converter: {
635
653
  fromAttribute: (r) => r == "true",
636
654
  toAttribute: (r) => r
@@ -639,25 +657,25 @@ h([
639
657
  attribute: "aria-disabled"
640
658
  })
641
659
  ], l.prototype, "disabled", 2);
642
- h([
643
- a({ type: String, attribute: !0 })
660
+ c([
661
+ d({ type: String, attribute: !0 })
644
662
  ], l.prototype, "validationMessage", 2);
645
- h([
646
- a({ type: String, attribute: !0 })
663
+ c([
664
+ d({ type: String, attribute: !0 })
647
665
  ], l.prototype, "validationIconSrc", 2);
648
- h([
649
- a({ converter: S.levelConverter, attribute: !0, reflect: !0 })
666
+ c([
667
+ d({ converter: S.levelConverter, attribute: !0, reflect: !0 })
650
668
  ], l.prototype, "validationLevel", 2);
651
- h([
652
- a({ type: String, reflect: !0, attribute: "token-type" })
669
+ c([
670
+ d({ type: String, reflect: !0, attribute: "token-type" })
653
671
  ], l.prototype, "tokenType", 2);
654
- h([
655
- a({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
672
+ c([
673
+ d({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
656
674
  ], l.prototype, "caseSensitive", 2);
657
- let se = l;
675
+ let ne = l;
658
676
  export {
659
- j as SelectionMode,
660
- se as default,
661
- N as generator
677
+ U as SelectionMode,
678
+ ne as default,
679
+ F as generator
662
680
  };
663
681
  //# sourceMappingURL=token-selector.mjs.map