@cas-smartdesign/token-selector 0.21.4 → 0.22.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.
- package/dist/docs/1_remove_only.js +1 -1
- package/dist/docs/2_multi_select.js +1 -1
- package/dist/docs/3_editable_input_attributes.js +1 -1
- package/dist/docs/4_dnd.js +1 -1
- package/dist/docs/5_other.js +1 -1
- package/dist/docs/button.mjs +2 -2
- package/dist/docs/doc.css +1 -1
- package/dist/docs/doc.mjs +99 -101
- package/dist/docs/token-provider.mjs +1 -1
- package/dist/token-selector-with-externals.js +41 -77
- package/dist/token-selector-with-externals.js.map +4 -4
- package/dist/token-selector.mjs +113 -118
- package/dist/token-selector.mjs.map +1 -1
- package/dist/token-suggest-popover.d.ts +1 -0
- package/npm-third-party-licenses.json +52 -47
- package/package.json +13 -13
package/dist/token-selector.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement as
|
|
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";
|
|
@@ -11,8 +11,8 @@ import { unsafeSVG as P } from "lit/directives/unsafe-svg.js";
|
|
|
11
11
|
import D from "@cas-smartdesign/image-tools";
|
|
12
12
|
let O = 0;
|
|
13
13
|
class q {
|
|
14
|
-
constructor(e, t, i,
|
|
15
|
-
this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback =
|
|
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", (
|
|
24
|
-
const 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", (
|
|
27
|
-
this.lastRequestedStartIndex =
|
|
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, (
|
|
32
|
-
this._tokenList.dispatchEvent(new KeyboardEvent(
|
|
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.
|
|
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
|
-
|
|
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.
|
|
60
|
+
return this.ensurePopover(), this._popover;
|
|
59
61
|
}
|
|
60
62
|
createPopover() {
|
|
61
63
|
const e = new L();
|
|
@@ -68,20 +70,20 @@ class q {
|
|
|
68
70
|
return this._suggestItems[this._tokenList.focusIndex];
|
|
69
71
|
}
|
|
70
72
|
}
|
|
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}`,
|
|
73
|
+
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}`, R = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">\r
|
|
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
|
-
var
|
|
75
|
-
for (var
|
|
76
|
-
(o = r[
|
|
77
|
-
return i &&
|
|
76
|
+
var $ = Object.defineProperty, N = Object.getOwnPropertyDescriptor, f = (r, e, t, i) => {
|
|
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 && $(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
|
|
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
|
|
101
|
-
if (
|
|
102
|
+
const n = window.getSelection();
|
|
103
|
+
if (n && n.type == "Range")
|
|
102
104
|
return;
|
|
103
105
|
i.stopPropagation();
|
|
104
|
-
const
|
|
105
|
-
this.disabled || (
|
|
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 ?
|
|
121
|
+
${this.disabled ? w : m` <div class="delete-button-wrapper">${P(R)}</div> `}
|
|
120
122
|
</div>
|
|
121
123
|
`;
|
|
122
124
|
}
|
|
@@ -129,7 +131,7 @@ const p = (u = class extends w {
|
|
|
129
131
|
</div>
|
|
130
132
|
`;
|
|
131
133
|
}
|
|
132
|
-
return
|
|
134
|
+
return w;
|
|
133
135
|
}
|
|
134
136
|
updated(e) {
|
|
135
137
|
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);
|
|
@@ -174,11 +176,11 @@ const F = (r, e) => {
|
|
|
174
176
|
};
|
|
175
177
|
b.ensureDefined();
|
|
176
178
|
const k = "web application/json";
|
|
177
|
-
class
|
|
179
|
+
class V {
|
|
178
180
|
constructor(e, t, i) {
|
|
179
181
|
navigator.clipboard && (e.addEventListener("copy", () => {
|
|
180
|
-
const
|
|
181
|
-
(!
|
|
182
|
+
const n = window.getSelection();
|
|
183
|
+
(!n || n.type != "Range") && !t() && this.writeToClipboard(e);
|
|
182
184
|
}), e.addEventListener("cut", () => {
|
|
183
185
|
t() || (e.removeSelectionOrActiveToken(), this.writeToClipboard(e));
|
|
184
186
|
}), e.addEventListener("paste", () => {
|
|
@@ -188,16 +190,16 @@ class G {
|
|
|
188
190
|
writeToClipboard(e) {
|
|
189
191
|
const t = e.querySelectorAll("[slot='items'][aria-checked='true']"), i = [];
|
|
190
192
|
if (t.length > 0)
|
|
191
|
-
t.forEach((
|
|
193
|
+
t.forEach((n) => i.push(n.index));
|
|
192
194
|
else if (e.activeTokenIndex != -1) {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
+
const n = e.activeTokenElement;
|
|
196
|
+
n && i.push(n.index);
|
|
195
197
|
}
|
|
196
198
|
if (i.length > 0) {
|
|
197
|
-
const
|
|
199
|
+
const n = JSON.stringify(i.map((o) => e.items[o])), s = new Blob([n], { type: k });
|
|
198
200
|
navigator.clipboard.write([
|
|
199
201
|
new ClipboardItem({
|
|
200
|
-
[k]:
|
|
202
|
+
[k]: s
|
|
201
203
|
})
|
|
202
204
|
]);
|
|
203
205
|
}
|
|
@@ -206,56 +208,56 @@ class G {
|
|
|
206
208
|
const t = await navigator.clipboard.read();
|
|
207
209
|
for (const i of t)
|
|
208
210
|
if (i.types.includes(k)) {
|
|
209
|
-
const
|
|
211
|
+
const s = await (await i.getType(k)).text(), o = JSON.parse(s);
|
|
210
212
|
Array.isArray(o) && e(o);
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
|
-
const
|
|
215
|
-
class
|
|
216
|
+
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}";
|
|
217
|
+
class H {
|
|
216
218
|
constructor(e, t) {
|
|
217
219
|
this.tokenSelector = e;
|
|
218
|
-
const i = /* @__PURE__ */ new Map(),
|
|
219
|
-
const o =
|
|
220
|
+
const i = /* @__PURE__ */ new Map(), n = (s) => {
|
|
221
|
+
const o = s.target;
|
|
220
222
|
if (e.removeAttribute("drag-source"), !e.contains(o)) {
|
|
221
|
-
const a =
|
|
223
|
+
const a = s.addedIndexes;
|
|
222
224
|
a && e.removeTokens(a.map((v) => i.get(v)));
|
|
223
225
|
}
|
|
224
226
|
i.clear();
|
|
225
227
|
};
|
|
226
|
-
e.addEventListener("dragstart", (
|
|
227
|
-
const o =
|
|
228
|
+
e.addEventListener("dragstart", (s) => {
|
|
229
|
+
const o = s.target;
|
|
228
230
|
if (o instanceof b) {
|
|
229
231
|
if (o.disabled) {
|
|
230
|
-
|
|
232
|
+
s.preventDefault();
|
|
231
233
|
return;
|
|
232
234
|
}
|
|
233
235
|
e.setAttribute("drag-source", ""), o.setAttribute("aria-checked", "true");
|
|
234
236
|
const a = e.querySelectorAll("[slot='items'][aria-checked='true']");
|
|
235
237
|
if (a.length > 0) {
|
|
236
238
|
const v = Array.from(a).filter((g) => !g.disabled).map((g, E) => (i.set(E, g.index), e.items[g.index]));
|
|
237
|
-
if (
|
|
239
|
+
if (s.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), s.dataTransfer.dropEffect = "move", s.dataTransfer.effectAllowed = "move", a.length > 1) {
|
|
238
240
|
const g = this.createCustomDragImage(o, v.length);
|
|
239
|
-
|
|
241
|
+
s.dataTransfer.setDragImage(g, -14, -14);
|
|
240
242
|
}
|
|
241
|
-
window.addEventListener("drop",
|
|
243
|
+
window.addEventListener("drop", n, { once: !0 });
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
|
-
}), e.addEventListener("dragenter", (
|
|
245
|
-
e.setAttribute("drop", ""),
|
|
246
|
-
}), e.addEventListener("dragover", (
|
|
247
|
-
|
|
248
|
-
}), e.addEventListener("drop", (
|
|
246
|
+
}), e.addEventListener("dragenter", (s) => {
|
|
247
|
+
e.setAttribute("drop", ""), s.preventDefault();
|
|
248
|
+
}), e.addEventListener("dragover", (s) => s.preventDefault()), e.addEventListener("dragleave", (s) => {
|
|
249
|
+
s.target == e && e.removeAttribute("drop");
|
|
250
|
+
}), e.addEventListener("drop", (s) => {
|
|
249
251
|
e.removeAttribute("drop");
|
|
250
|
-
const o =
|
|
252
|
+
const o = s.dataTransfer.getData("text/sd-token-selector");
|
|
251
253
|
if (o)
|
|
252
254
|
try {
|
|
253
255
|
const a = JSON.parse(o);
|
|
254
|
-
Array.isArray(a) && (
|
|
256
|
+
Array.isArray(a) && (s.addedIndexes = t(a), s.preventDefault());
|
|
255
257
|
} catch {
|
|
256
258
|
}
|
|
257
259
|
}), e.addEventListener("dragend", () => {
|
|
258
|
-
window.removeEventListener("drop",
|
|
260
|
+
window.removeEventListener("drop", n), e.removeAttribute("drag-source"), i.clear();
|
|
259
261
|
});
|
|
260
262
|
}
|
|
261
263
|
createCustomDragImage(e, t) {
|
|
@@ -263,14 +265,14 @@ class B {
|
|
|
263
265
|
if (i.setAttribute("aria-disabled", "true"), this.tokenSelector.tokenType)
|
|
264
266
|
i.value = t + " " + this.tokenSelector.tokenType;
|
|
265
267
|
else {
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
+
const n = document.createElement("div");
|
|
269
|
+
n.innerText = "+" + (t - 1), Object.assign(n.style, {
|
|
268
270
|
position: "absolute",
|
|
269
271
|
left: "90%",
|
|
270
272
|
top: "75%"
|
|
271
273
|
});
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
+
const s = document.createElement("div");
|
|
275
|
+
s.appendChild(i), s.appendChild(n), i = s;
|
|
274
276
|
}
|
|
275
277
|
return Object.assign(i.style, {
|
|
276
278
|
height: e.offsetHeight,
|
|
@@ -284,19 +286,19 @@ class B {
|
|
|
284
286
|
}), i.slot = "items", this.tokenSelector.appendChild(i), requestAnimationFrame(() => i.remove()), i;
|
|
285
287
|
}
|
|
286
288
|
}
|
|
287
|
-
var
|
|
288
|
-
for (var
|
|
289
|
-
(o = r[
|
|
290
|
-
return
|
|
289
|
+
var B = Object.defineProperty, c = (r, e, t, i) => {
|
|
290
|
+
for (var n = void 0, s = r.length - 1, o; s >= 0; s--)
|
|
291
|
+
(o = r[s]) && (n = o(e, t, n) || n);
|
|
292
|
+
return n && B(e, t, n), n;
|
|
291
293
|
};
|
|
292
|
-
function
|
|
294
|
+
function K(r, e) {
|
|
293
295
|
let t;
|
|
294
296
|
return function(...i) {
|
|
295
297
|
t != null && clearTimeout(t), t = window.setTimeout(() => r(...i), e);
|
|
296
298
|
};
|
|
297
299
|
}
|
|
298
300
|
var U = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(U || {}), h;
|
|
299
|
-
const l = (h = class extends
|
|
301
|
+
const l = (h = class extends x {
|
|
300
302
|
constructor() {
|
|
301
303
|
super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = F, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
|
|
302
304
|
if ((e.key === "Enter" || this.additionalTokenCommittingKeys.includes(e.key)) && t.value) {
|
|
@@ -347,23 +349,22 @@ const l = (h = class extends w {
|
|
|
347
349
|
}
|
|
348
350
|
}
|
|
349
351
|
}, this.selectOrAddItems = (e) => {
|
|
350
|
-
const t = [], i = e.map((
|
|
351
|
-
const o =
|
|
352
|
-
return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(
|
|
353
|
-
}).filter((
|
|
352
|
+
const t = [], i = e.map((n, s) => {
|
|
353
|
+
const o = n.caption == null ? -1 : this.findIndex(n);
|
|
354
|
+
return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(s), o) : -1;
|
|
355
|
+
}).filter((n) => n != -1);
|
|
354
356
|
return i.length > 0 && this.handleTokenSelection(i), t;
|
|
355
357
|
}, this.handleWindowPointerDown = (e) => {
|
|
356
358
|
const t = this.inputElement;
|
|
357
|
-
if (!t || !t.value)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (s instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || s.getAttribute("popover-for") === "token-autosuggest-popover"))
|
|
359
|
+
if (!t || !t.value) return;
|
|
360
|
+
e.composedPath().some((n) => {
|
|
361
|
+
if (n instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || n.getAttribute("popover-for") === "token-autosuggest-popover"))
|
|
361
362
|
return !0;
|
|
362
363
|
}) || this.commitTokenValue(t.value);
|
|
363
|
-
}, this.debouncedShowTokenSuggestPopover =
|
|
364
|
+
}, this.debouncedShowTokenSuggestPopover = K(this.showFilteredTokenSuggestions.bind(this), 200);
|
|
364
365
|
}
|
|
365
366
|
static get styles() {
|
|
366
|
-
return T(
|
|
367
|
+
return T(G);
|
|
367
368
|
}
|
|
368
369
|
get tokenGenerator() {
|
|
369
370
|
return this._tokenGenerator;
|
|
@@ -392,7 +393,7 @@ const l = (h = class extends w {
|
|
|
392
393
|
<slot name="items"
|
|
393
394
|
>${this.placeholder ? m`<span part="remove-only-placeholder" class="placeholder"
|
|
394
395
|
>${this.placeholder}</span
|
|
395
|
-
>` :
|
|
396
|
+
>` : w}</slot
|
|
396
397
|
>
|
|
397
398
|
</div>
|
|
398
399
|
<slot class="additonal-content" name="additional-content" @focusin=${this.clearCheckedTokens}></slot>` : m`
|
|
@@ -420,14 +421,11 @@ const l = (h = class extends w {
|
|
|
420
421
|
!this.contains(i) && !this.shadowRoot.contains(i) && this.clearCheckedTokens();
|
|
421
422
|
}), this.addEventListener("focusin", () => {
|
|
422
423
|
this.selectionMode == "remove-only" && this.activeTokenIndex == -1 && this.items.length > 0 && !this.disabled && (this.activeTokenIndex = 0);
|
|
423
|
-
}), new
|
|
424
|
+
}), new V(
|
|
424
425
|
this,
|
|
425
|
-
() =>
|
|
426
|
-
var t;
|
|
427
|
-
return (t = this.inputElement) == null ? void 0 : t.value;
|
|
428
|
-
},
|
|
426
|
+
() => this.inputElement?.value,
|
|
429
427
|
(t) => this.selectOrAddItems(t)
|
|
430
|
-
), new
|
|
428
|
+
), new H(this, (t) => this.selectOrAddItems(t));
|
|
431
429
|
}
|
|
432
430
|
clearCheckedTokens() {
|
|
433
431
|
this.querySelectorAll("[slot='items'][aria-checked='true']").forEach(
|
|
@@ -449,13 +447,12 @@ const l = (h = class extends w {
|
|
|
449
447
|
}
|
|
450
448
|
}
|
|
451
449
|
updateActiveToken(e) {
|
|
452
|
-
var i;
|
|
453
450
|
if (this.disabled)
|
|
454
451
|
return;
|
|
455
452
|
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 && (
|
|
457
|
-
const
|
|
458
|
-
|
|
453
|
+
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)) {
|
|
454
|
+
const i = this.activeTokenElement;
|
|
455
|
+
i.scrollIntoViewIfNeeded ? i.scrollIntoViewIfNeeded() : i.scrollIntoView();
|
|
459
456
|
}
|
|
460
457
|
}
|
|
461
458
|
commitTokenValue(e) {
|
|
@@ -465,13 +462,13 @@ const l = (h = class extends w {
|
|
|
465
462
|
const i = this.tokenSuggestPopover.focusedSuggestToken;
|
|
466
463
|
if (i) {
|
|
467
464
|
if (!i.disabled) {
|
|
468
|
-
const
|
|
469
|
-
this.handleTokenSelection([
|
|
465
|
+
const n = this.findIndex(i);
|
|
466
|
+
this.handleTokenSelection([n]), this.tokenSuggestPopover.hide();
|
|
470
467
|
}
|
|
471
468
|
return;
|
|
472
469
|
}
|
|
473
470
|
}
|
|
474
|
-
if (!
|
|
471
|
+
if (!e?.trim())
|
|
475
472
|
return;
|
|
476
473
|
const t = this.items.findIndex(
|
|
477
474
|
(i) => this.caseSensitive ? i.caption == e : i.caption.toLowerCase() == e.toLowerCase()
|
|
@@ -517,21 +514,20 @@ const l = (h = class extends w {
|
|
|
517
514
|
return;
|
|
518
515
|
this.activeTokenIndex = -1;
|
|
519
516
|
const e = this.inputElement;
|
|
520
|
-
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((
|
|
521
|
-
this.removeChild(
|
|
517
|
+
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((n) => {
|
|
518
|
+
this.removeChild(n);
|
|
522
519
|
});
|
|
523
520
|
const t = document.createDocumentFragment();
|
|
524
521
|
let i = [];
|
|
525
|
-
this.selectionMode == "remove-only" ? i = this.items.map((
|
|
526
|
-
i.push(this.disableIfNeeded(this.items[
|
|
527
|
-
}), i.forEach((
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
(a = this.inputElement) == null || a.removeAttribute("focus-visible");
|
|
522
|
+
this.selectionMode == "remove-only" ? i = this.items.map((n) => this.disableIfNeeded(n)) : this.selectedIndexes.forEach((n) => {
|
|
523
|
+
i.push(this.disableIfNeeded(this.items[n]));
|
|
524
|
+
}), i.forEach((n) => {
|
|
525
|
+
const s = this.tokenGenerator(n, this.findIndex(n));
|
|
526
|
+
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", () => {
|
|
527
|
+
this.inputElement?.removeAttribute("focus-visible");
|
|
532
528
|
const o = window.getSelection();
|
|
533
529
|
(!o || o.type != "Range") && document.activeElement != this && this.focus();
|
|
534
|
-
}),
|
|
530
|
+
}), s.setDeleteHandler((o) => this.removeTokens([o]));
|
|
535
531
|
}), this.appendChild(t), this._tokenSuggestPopover && this._tokenSuggestPopover.refreshItems();
|
|
536
532
|
}
|
|
537
533
|
removeTokens(e) {
|
|
@@ -557,10 +553,10 @@ const l = (h = class extends w {
|
|
|
557
553
|
}
|
|
558
554
|
}
|
|
559
555
|
onTokenClick(e, t, i) {
|
|
560
|
-
let
|
|
561
|
-
this.querySelectorAll("[slot='items']").forEach((
|
|
562
|
-
e ==
|
|
563
|
-
}), this.activeTokenIndex =
|
|
556
|
+
let n;
|
|
557
|
+
this.querySelectorAll("[slot='items']").forEach((s, o) => {
|
|
558
|
+
e == s ? n = o : i || s.setAttribute("aria-checked", "false");
|
|
559
|
+
}), this.activeTokenIndex = n, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), i || this.dispatchEvent(
|
|
564
560
|
new CustomEvent("token-clicked", {
|
|
565
561
|
detail: {
|
|
566
562
|
index: e.index,
|
|
@@ -620,33 +616,32 @@ const l = (h = class extends w {
|
|
|
620
616
|
}
|
|
621
617
|
}
|
|
622
618
|
get hasInputValue() {
|
|
623
|
-
|
|
624
|
-
return !!((e = this.inputElement) != null && e.value);
|
|
619
|
+
return !!this.inputElement?.value;
|
|
625
620
|
}
|
|
626
621
|
}, h.ID = "sd-token-selector", h.ensureDefined = () => {
|
|
627
622
|
b.ensureDefined(), customElements.get(h.ID) || customElements.define(h.ID, h);
|
|
628
623
|
}, h.shadowRootOptions = {
|
|
629
|
-
...
|
|
624
|
+
...x.shadowRootOptions,
|
|
630
625
|
delegatesFocus: !0
|
|
631
626
|
}, h);
|
|
632
627
|
c([
|
|
633
628
|
d({ type: String, attribute: "selection-mode", reflect: !0 })
|
|
634
|
-
], l.prototype, "selectionMode"
|
|
629
|
+
], l.prototype, "selectionMode");
|
|
635
630
|
c([
|
|
636
631
|
d({ type: Array, attribute: !1 })
|
|
637
|
-
], l.prototype, "items"
|
|
632
|
+
], l.prototype, "items");
|
|
638
633
|
c([
|
|
639
634
|
d({ type: Array, attribute: !1 })
|
|
640
|
-
], l.prototype, "selectedIndexes"
|
|
635
|
+
], l.prototype, "selectedIndexes");
|
|
641
636
|
c([
|
|
642
637
|
d({ type: String, reflect: !0 })
|
|
643
|
-
], l.prototype, "placeholder"
|
|
638
|
+
], l.prototype, "placeholder");
|
|
644
639
|
c([
|
|
645
640
|
d({ type: String, reflect: !0, attribute: "suggest-list-class" })
|
|
646
|
-
], l.prototype, "suggestListClass"
|
|
641
|
+
], l.prototype, "suggestListClass");
|
|
647
642
|
c([
|
|
648
643
|
d({ type: String, reflect: !0, attribute: "input-label" })
|
|
649
|
-
], l.prototype, "inputLabel"
|
|
644
|
+
], l.prototype, "inputLabel");
|
|
650
645
|
c([
|
|
651
646
|
d({
|
|
652
647
|
converter: {
|
|
@@ -656,26 +651,26 @@ c([
|
|
|
656
651
|
reflect: !0,
|
|
657
652
|
attribute: "aria-disabled"
|
|
658
653
|
})
|
|
659
|
-
], l.prototype, "disabled"
|
|
654
|
+
], l.prototype, "disabled");
|
|
660
655
|
c([
|
|
661
656
|
d({ type: String, attribute: !0 })
|
|
662
|
-
], l.prototype, "validationMessage"
|
|
657
|
+
], l.prototype, "validationMessage");
|
|
663
658
|
c([
|
|
664
659
|
d({ type: String, attribute: !0 })
|
|
665
|
-
], l.prototype, "validationIconSrc"
|
|
660
|
+
], l.prototype, "validationIconSrc");
|
|
666
661
|
c([
|
|
667
662
|
d({ converter: S.levelConverter, attribute: !0, reflect: !0 })
|
|
668
|
-
], l.prototype, "validationLevel"
|
|
663
|
+
], l.prototype, "validationLevel");
|
|
669
664
|
c([
|
|
670
665
|
d({ type: String, reflect: !0, attribute: "token-type" })
|
|
671
|
-
], l.prototype, "tokenType"
|
|
666
|
+
], l.prototype, "tokenType");
|
|
672
667
|
c([
|
|
673
668
|
d({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
|
|
674
|
-
], l.prototype, "caseSensitive"
|
|
675
|
-
let
|
|
669
|
+
], l.prototype, "caseSensitive");
|
|
670
|
+
let se = l;
|
|
676
671
|
export {
|
|
677
672
|
U as SelectionMode,
|
|
678
|
-
|
|
673
|
+
se as default,
|
|
679
674
|
F as generator
|
|
680
675
|
};
|
|
681
676
|
//# sourceMappingURL=token-selector.mjs.map
|