@cas-smartdesign/token-selector 0.16.2 → 0.17.1
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/5_other.js +1 -1
- package/dist/docs/button.mjs +2 -2
- package/dist/docs/doc.mjs +78 -96
- package/dist/docs/index.html +3 -1
- package/dist/token-selector-with-externals.js +35 -61
- package/dist/token-selector-with-externals.js.map +4 -4
- package/dist/token-selector.d.ts +1 -1
- package/dist/token-selector.mjs +116 -106
- package/dist/token-selector.mjs.map +1 -1
- package/dist/token-suggest-popover.d.ts +4 -2
- package/package.json +12 -12
- package/readme.md +0 -2
package/dist/token-selector.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LitElement, TemplateResult, CSSResult, PropertyValues } from "lit";
|
|
2
2
|
import "@cas-smartdesign/lit-input";
|
|
3
3
|
import { ValidationLevel } from "@cas-smartdesign/field-validation-message";
|
|
4
|
-
import { ItemGenerator } from "@cas-smartdesign/list";
|
|
4
|
+
import { ItemGenerator } from "@cas-smartdesign/virtual-list";
|
|
5
5
|
import { Filter } from "./token-suggest-popover";
|
|
6
6
|
import Token, { TokenData } from "./token";
|
|
7
7
|
export type { Filter as InMemoryFilter } from "./token-suggest-popover";
|
package/dist/token-selector.mjs
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
import { LitElement as x, unsafeCSS as T, html as m, nothing as
|
|
1
|
+
import { LitElement as x, unsafeCSS as T, html as m, nothing as I } from "lit";
|
|
2
2
|
import { property as a } 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 C from "@cas-smartdesign/popover";
|
|
7
|
-
import
|
|
8
|
-
import { KeyDownDelegator as
|
|
9
|
-
import { ifDefined as
|
|
10
|
-
import { unsafeSVG as
|
|
7
|
+
import y from "@cas-smartdesign/virtual-list";
|
|
8
|
+
import { KeyDownDelegator as L } from "@cas-smartdesign/element-utils";
|
|
9
|
+
import { ifDefined as A } from "lit/directives/if-defined.js";
|
|
10
|
+
import { unsafeSVG as P } from "lit/directives/unsafe-svg.js";
|
|
11
11
|
import D from "@cas-smartdesign/image-tools";
|
|
12
12
|
class O {
|
|
13
|
-
constructor(e, t, i,
|
|
14
|
-
this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback =
|
|
15
|
-
const 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("selection", (s) => {
|
|
15
|
+
const o = s.detail.index, d = this._suggestItems[o];
|
|
16
16
|
i(d), this.hide();
|
|
17
|
-
}),
|
|
18
|
-
this.
|
|
17
|
+
}), this._tokenList.addEventListener("data-request", (s) => {
|
|
18
|
+
this.lastRequestedStartIndex = s.detail.startIndex, this.lastRequestedStopIndex = s.detail.stopIndex, this._tokenList.items = this._suggestItems.slice(
|
|
19
|
+
this.lastRequestedStartIndex,
|
|
20
|
+
this.lastRequestedStopIndex + 1
|
|
21
|
+
);
|
|
22
|
+
}), new L(this._tokenList, (s, o, d) => {
|
|
23
|
+
this._tokenList.dispatchEvent(new KeyboardEvent(s.type, s)), !d && !this.isOpened && this.show();
|
|
19
24
|
}).connect(e);
|
|
20
25
|
}
|
|
21
26
|
show() {
|
|
22
|
-
this.inputElement.effectiveDisabled || (this.popover, this._suggestItems = this.filterItems((this.inputElement.value || "").toLowerCase()), this._suggestItems.length == 0 ? this.hide() : (this._tokenList.
|
|
27
|
+
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, requestAnimationFrame(() => {
|
|
28
|
+
this.lastRequestedStartIndex != null && (this._tokenList.items = this._suggestItems.slice(
|
|
29
|
+
this.lastRequestedStartIndex,
|
|
30
|
+
this.lastRequestedStopIndex + 1
|
|
31
|
+
));
|
|
32
|
+
}), Object.assign(this._tokenList.style, {
|
|
23
33
|
minWidth: `${Math.max(this.popover.targetElement.offsetWidth, 250)}px`
|
|
24
34
|
}), this.popover.show()));
|
|
25
35
|
}
|
|
26
36
|
refreshItems() {
|
|
27
|
-
this.isOpened && (this._suggestItems = this.filterItems((this.inputElement.value || "").toLowerCase()), this._suggestItems.length == 0 ? this.hide() : this._tokenList.
|
|
37
|
+
this.isOpened && (this._suggestItems = this.filterItems((this.inputElement.value || "").toLowerCase()), this._suggestItems.length == 0 ? this.hide() : (this._tokenList.itemCount = this._suggestItems.length, this._tokenList.items = []));
|
|
28
38
|
}
|
|
29
39
|
filterItems(e) {
|
|
30
40
|
const t = this.notSelectedTokensProvider();
|
|
@@ -32,7 +42,7 @@ class O {
|
|
|
32
42
|
}
|
|
33
43
|
hide() {
|
|
34
44
|
var e;
|
|
35
|
-
this._suggestItems = [], this._tokenList.items = [], (e = this._popover) == null || e.hide();
|
|
45
|
+
this._suggestItems = [], this._tokenList.itemCount = 0, this._tokenList.items = [], (e = this._popover) == null || e.hide();
|
|
36
46
|
}
|
|
37
47
|
get list() {
|
|
38
48
|
return this._tokenList;
|
|
@@ -51,15 +61,15 @@ class O {
|
|
|
51
61
|
return this._suggestItems[this._tokenList.focusIndex];
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
|
-
const
|
|
64
|
+
const q = ":host{flex-shrink:0;max-width:100%}.container{display:flex;height:28px;background-color:var(--token-background-color, #f3f3f3);border:var(--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(--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
|
|
55
65
|
<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
|
|
56
66
|
</svg>`;
|
|
57
|
-
var
|
|
58
|
-
for (var
|
|
59
|
-
(o = r[
|
|
60
|
-
return i &&
|
|
67
|
+
var $ = Object.defineProperty, R = Object.getOwnPropertyDescriptor, g = (r, e, t, i) => {
|
|
68
|
+
for (var n = i > 1 ? void 0 : i ? R(e, t) : e, s = r.length - 1, o; s >= 0; s--)
|
|
69
|
+
(o = r[s]) && (n = (i ? o(e, t, n) : o(n)) || n);
|
|
70
|
+
return i && n && $(e, t, n), n;
|
|
61
71
|
};
|
|
62
|
-
const
|
|
72
|
+
const w = {
|
|
63
73
|
fromAttribute: (r) => r == "true",
|
|
64
74
|
toAttribute: (r) => r
|
|
65
75
|
};
|
|
@@ -69,7 +79,7 @@ const p = (u = class extends x {
|
|
|
69
79
|
super(...arguments), this.value = "", this.type = "", this.icon = "", this.iconPlaceholder = "", this.iconBackgroundColor = "", this._checked = !1;
|
|
70
80
|
}
|
|
71
81
|
static get styles() {
|
|
72
|
-
return T(
|
|
82
|
+
return T(q);
|
|
73
83
|
}
|
|
74
84
|
set checked(e) {
|
|
75
85
|
const t = this._checked;
|
|
@@ -94,7 +104,7 @@ const p = (u = class extends x {
|
|
|
94
104
|
${this.renderIcon()}
|
|
95
105
|
<slot name="after-icon"></slot>
|
|
96
106
|
<div class="value">${this.value}</div>
|
|
97
|
-
${this.disabled ?
|
|
107
|
+
${this.disabled ? I : m` <div class="delete-button-wrapper">${P(M)}</div> `}
|
|
98
108
|
</div>
|
|
99
109
|
`;
|
|
100
110
|
}
|
|
@@ -102,12 +112,12 @@ const p = (u = class extends x {
|
|
|
102
112
|
if (this.icon || this.iconPlaceholder) {
|
|
103
113
|
const e = this.iconBackgroundColor != null ? `--token-icon-background-color: ${this.iconBackgroundColor}` : void 0;
|
|
104
114
|
return m`
|
|
105
|
-
<div class="icon-wrapper" style="${
|
|
115
|
+
<div class="icon-wrapper" style="${A(e)}" role="img">
|
|
106
116
|
<div class="icon"></div>
|
|
107
117
|
</div>
|
|
108
118
|
`;
|
|
109
119
|
}
|
|
110
|
-
return
|
|
120
|
+
return I;
|
|
111
121
|
}
|
|
112
122
|
updated(e) {
|
|
113
123
|
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,22 +147,22 @@ g([
|
|
|
137
147
|
a({ type: String })
|
|
138
148
|
], p.prototype, "iconBackgroundColor", 2);
|
|
139
149
|
g([
|
|
140
|
-
a({ converter:
|
|
150
|
+
a({ converter: w, reflect: !0, attribute: "aria-disabled" })
|
|
141
151
|
], p.prototype, "disabled", 2);
|
|
142
152
|
g([
|
|
143
|
-
a({ converter:
|
|
153
|
+
a({ converter: w, reflect: !0, attribute: "aria-current" })
|
|
144
154
|
], p.prototype, "current", 2);
|
|
145
155
|
g([
|
|
146
|
-
a({ converter:
|
|
156
|
+
a({ converter: w, reflect: !0, attribute: "aria-checked" })
|
|
147
157
|
], p.prototype, "checked", 1);
|
|
148
158
|
let b = p;
|
|
149
|
-
const
|
|
159
|
+
const G = (r, e) => {
|
|
150
160
|
const t = document.createElement(b.ID);
|
|
151
161
|
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;
|
|
152
162
|
};
|
|
153
163
|
b.ensureDefined();
|
|
154
164
|
const k = "web application/json";
|
|
155
|
-
class
|
|
165
|
+
class B {
|
|
156
166
|
constructor(e, t, i) {
|
|
157
167
|
navigator.clipboard && (e.addEventListener("copy", () => {
|
|
158
168
|
t() || this.writeToClipboard(e);
|
|
@@ -165,16 +175,16 @@ class F {
|
|
|
165
175
|
writeToClipboard(e) {
|
|
166
176
|
const t = e.querySelectorAll("[slot='items'][aria-checked='true']"), i = [];
|
|
167
177
|
if (t.length > 0)
|
|
168
|
-
t.forEach((
|
|
178
|
+
t.forEach((n) => i.push(n.index));
|
|
169
179
|
else if (e.activeTokenIndex != -1) {
|
|
170
|
-
const
|
|
171
|
-
|
|
180
|
+
const n = e.activeTokenElement;
|
|
181
|
+
n && i.push(n.index);
|
|
172
182
|
}
|
|
173
183
|
if (i.length > 0) {
|
|
174
|
-
const
|
|
184
|
+
const n = JSON.stringify(i.map((o) => e.items[o])), s = new Blob([n], { type: k });
|
|
175
185
|
navigator.clipboard.write([
|
|
176
186
|
new ClipboardItem({
|
|
177
|
-
[k]:
|
|
187
|
+
[k]: s
|
|
178
188
|
})
|
|
179
189
|
]);
|
|
180
190
|
}
|
|
@@ -183,56 +193,56 @@ class F {
|
|
|
183
193
|
const t = await navigator.clipboard.read();
|
|
184
194
|
for (const i of t)
|
|
185
195
|
if (i.types.includes(k)) {
|
|
186
|
-
const
|
|
196
|
+
const s = await (await i.getType(k)).text(), o = JSON.parse(s);
|
|
187
197
|
Array.isArray(o) && e(o);
|
|
188
198
|
}
|
|
189
199
|
}
|
|
190
200
|
}
|
|
191
|
-
const
|
|
192
|
-
class
|
|
201
|
+
const F = ":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){margin-right:24px;margin-bottom:4px}.container{display:flex;flex-wrap:wrap;gap:8px;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}";
|
|
202
|
+
class H {
|
|
193
203
|
constructor(e, t) {
|
|
194
204
|
this.tokenSelector = e;
|
|
195
|
-
const i = /* @__PURE__ */ new Map(),
|
|
196
|
-
const o =
|
|
205
|
+
const i = /* @__PURE__ */ new Map(), n = (s) => {
|
|
206
|
+
const o = s.target;
|
|
197
207
|
if (!e.contains(o)) {
|
|
198
|
-
const d =
|
|
208
|
+
const d = s.addedIndexes;
|
|
199
209
|
d && e.removeTokens(d.map((v) => i.get(v)));
|
|
200
210
|
}
|
|
201
211
|
i.clear();
|
|
202
212
|
};
|
|
203
|
-
e.addEventListener("dragstart", (
|
|
204
|
-
const o =
|
|
213
|
+
e.addEventListener("dragstart", (s) => {
|
|
214
|
+
const o = s.target;
|
|
205
215
|
if (o instanceof b) {
|
|
206
216
|
if (o.disabled) {
|
|
207
|
-
|
|
217
|
+
s.preventDefault();
|
|
208
218
|
return;
|
|
209
219
|
}
|
|
210
220
|
o.setAttribute("aria-checked", "true");
|
|
211
221
|
const d = e.querySelectorAll("[slot='items'][aria-checked='true']");
|
|
212
222
|
if (d.length > 0) {
|
|
213
223
|
const v = Array.from(d).filter((f) => !f.disabled).map((f, E) => (i.set(E, f.index), e.items[f.index]));
|
|
214
|
-
if (
|
|
224
|
+
if (s.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), s.dataTransfer.dropEffect = "move", s.dataTransfer.effectAllowed = "move", d.length > 1) {
|
|
215
225
|
const f = this.createCustomDragImage(o, v.length);
|
|
216
|
-
|
|
226
|
+
s.dataTransfer.setDragImage(f, -14, -14);
|
|
217
227
|
}
|
|
218
|
-
window.addEventListener("drop",
|
|
228
|
+
window.addEventListener("drop", n, { once: !0 });
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
|
-
}), e.addEventListener("dragenter", (
|
|
222
|
-
e.setAttribute("drop", ""),
|
|
223
|
-
}), e.addEventListener("dragover", (
|
|
224
|
-
|
|
225
|
-
}), e.addEventListener("drop", (
|
|
231
|
+
}), e.addEventListener("dragenter", (s) => {
|
|
232
|
+
e.setAttribute("drop", ""), s.preventDefault();
|
|
233
|
+
}), e.addEventListener("dragover", (s) => s.preventDefault()), e.addEventListener("dragleave", (s) => {
|
|
234
|
+
s.target == e && e.removeAttribute("drop");
|
|
235
|
+
}), e.addEventListener("drop", (s) => {
|
|
226
236
|
e.removeAttribute("drop");
|
|
227
|
-
const o =
|
|
237
|
+
const o = s.dataTransfer.getData("text/sd-token-selector");
|
|
228
238
|
if (o)
|
|
229
239
|
try {
|
|
230
240
|
const d = JSON.parse(o);
|
|
231
|
-
Array.isArray(d) && (
|
|
241
|
+
Array.isArray(d) && (s.addedIndexes = t(d), s.preventDefault());
|
|
232
242
|
} catch {
|
|
233
243
|
}
|
|
234
244
|
}), e.addEventListener("dragend", () => {
|
|
235
|
-
window.removeEventListener("drop",
|
|
245
|
+
window.removeEventListener("drop", n), i.clear();
|
|
236
246
|
});
|
|
237
247
|
}
|
|
238
248
|
createCustomDragImage(e, t) {
|
|
@@ -240,14 +250,14 @@ class N {
|
|
|
240
250
|
if (i.setAttribute("aria-disabled", "true"), this.tokenSelector.tokenType)
|
|
241
251
|
i.value = t + " " + this.tokenSelector.tokenType;
|
|
242
252
|
else {
|
|
243
|
-
const
|
|
244
|
-
|
|
253
|
+
const n = document.createElement("div");
|
|
254
|
+
n.innerText = "+" + (t - 1), Object.assign(n.style, {
|
|
245
255
|
position: "absolute",
|
|
246
256
|
left: "90%",
|
|
247
257
|
top: "75%"
|
|
248
258
|
});
|
|
249
|
-
const
|
|
250
|
-
|
|
259
|
+
const s = document.createElement("div");
|
|
260
|
+
s.appendChild(i), s.appendChild(n), i = s;
|
|
251
261
|
}
|
|
252
262
|
return Object.assign(i.style, {
|
|
253
263
|
height: e.offsetHeight,
|
|
@@ -261,21 +271,21 @@ class N {
|
|
|
261
271
|
}), i.slot = "items", this.tokenSelector.appendChild(i), requestAnimationFrame(() => i.remove()), i;
|
|
262
272
|
}
|
|
263
273
|
}
|
|
264
|
-
var
|
|
265
|
-
for (var
|
|
266
|
-
(o = r[
|
|
267
|
-
return i &&
|
|
274
|
+
var N = Object.defineProperty, j = Object.getOwnPropertyDescriptor, h = (r, e, t, i) => {
|
|
275
|
+
for (var n = i > 1 ? void 0 : i ? j(e, t) : e, s = r.length - 1, o; s >= 0; s--)
|
|
276
|
+
(o = r[s]) && (n = (i ? o(e, t, n) : o(n)) || n);
|
|
277
|
+
return i && n && N(e, t, n), n;
|
|
268
278
|
};
|
|
269
|
-
function
|
|
279
|
+
function K(r, e) {
|
|
270
280
|
let t;
|
|
271
281
|
return function(...i) {
|
|
272
282
|
t != null && clearTimeout(t), t = window.setTimeout(() => r(...i), e);
|
|
273
283
|
};
|
|
274
284
|
}
|
|
275
|
-
var V = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(V || {}),
|
|
276
|
-
const l = (
|
|
285
|
+
var V = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(V || {}), c;
|
|
286
|
+
const l = (c = class extends x {
|
|
277
287
|
constructor() {
|
|
278
|
-
super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator =
|
|
288
|
+
super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = G, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
|
|
279
289
|
if ((e.key === "Enter" || this.additionalTokenCommittingKeys.includes(e.key)) && t.value) {
|
|
280
290
|
e.preventDefault(), e.stopPropagation(), this.commitTokenValue(t.value);
|
|
281
291
|
return;
|
|
@@ -327,14 +337,14 @@ const l = (h = class extends x {
|
|
|
327
337
|
const t = this.inputElement;
|
|
328
338
|
if (!t || !t.value)
|
|
329
339
|
return;
|
|
330
|
-
e.composedPath().some((
|
|
331
|
-
if (
|
|
340
|
+
e.composedPath().some((n) => {
|
|
341
|
+
if (n instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || n.getAttribute("popover-for") === "token-autosuggest-popover"))
|
|
332
342
|
return !0;
|
|
333
343
|
}) || this.commitTokenValue(t.value);
|
|
334
|
-
}, this.debouncedShowTokenSuggestPopover =
|
|
344
|
+
}, this.debouncedShowTokenSuggestPopover = K(this.showFilteredTokenSuggestions.bind(this), 200);
|
|
335
345
|
}
|
|
336
346
|
static get styles() {
|
|
337
|
-
return T(
|
|
347
|
+
return T(F);
|
|
338
348
|
}
|
|
339
349
|
get tokenGenerator() {
|
|
340
350
|
return this._tokenGenerator;
|
|
@@ -362,7 +372,7 @@ const l = (h = class extends x {
|
|
|
362
372
|
<slot name="items"
|
|
363
373
|
>${this.placeholder ? m`<span part="remove-only-placeholder" class="placeholder"
|
|
364
374
|
>${this.placeholder}</span
|
|
365
|
-
>` :
|
|
375
|
+
>` : I}</slot
|
|
366
376
|
>
|
|
367
377
|
</div>
|
|
368
378
|
<slot class="additonal-content" name="additional-content"></slot>` : m`
|
|
@@ -386,22 +396,22 @@ const l = (h = class extends x {
|
|
|
386
396
|
super.firstUpdated(e), this.setAttribute("role", "listbox"), this.setAttribute("aria-multiselectable", "true"), this.hasAttribute("tabIndex") || (this.tabIndex = 0), this.addEventListener("focusout", (t) => {
|
|
387
397
|
const i = t.relatedTarget;
|
|
388
398
|
!this.contains(i) && !this.shadowRoot.contains(i) && this.querySelectorAll("[slot='items'][aria-checked='true']").forEach(
|
|
389
|
-
(
|
|
399
|
+
(n) => n.checked = !1
|
|
390
400
|
);
|
|
391
|
-
}), new
|
|
401
|
+
}), new B(
|
|
392
402
|
this,
|
|
393
403
|
() => {
|
|
394
404
|
var t;
|
|
395
405
|
return (t = this.inputElement) == null ? void 0 : t.value;
|
|
396
406
|
},
|
|
397
407
|
(t) => this.addMatchingItems(t)
|
|
398
|
-
), new
|
|
408
|
+
), new H(this, (t) => this.addMatchingItems(t));
|
|
399
409
|
}
|
|
400
410
|
addMatchingItems(e) {
|
|
401
|
-
const t = [], i = e.map((
|
|
402
|
-
const o =
|
|
403
|
-
return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(
|
|
404
|
-
}).filter((
|
|
411
|
+
const t = [], i = e.map((n, s) => {
|
|
412
|
+
const o = n.caption == null ? -1 : this.findIndex(n);
|
|
413
|
+
return o != -1 && !this.items[o].disabled && !this.selectedIndexes.includes(o) ? (t.push(s), o) : -1;
|
|
414
|
+
}).filter((n) => n != -1);
|
|
405
415
|
return i.length > 0 && this.handleTokenSelection(i), t;
|
|
406
416
|
}
|
|
407
417
|
removeSelectionOrActiveToken() {
|
|
@@ -427,8 +437,8 @@ const l = (h = class extends x {
|
|
|
427
437
|
const i = this.tokenSuggestPopover.focusedSuggestToken;
|
|
428
438
|
if (i) {
|
|
429
439
|
if (!i.disabled) {
|
|
430
|
-
const
|
|
431
|
-
this.handleTokenSelection([
|
|
440
|
+
const n = this.findIndex(i);
|
|
441
|
+
this.handleTokenSelection([n]), this.tokenSuggestPopover.hide();
|
|
432
442
|
}
|
|
433
443
|
return;
|
|
434
444
|
}
|
|
@@ -478,18 +488,18 @@ const l = (h = class extends x {
|
|
|
478
488
|
if (!this.isConnected || !this.items)
|
|
479
489
|
return;
|
|
480
490
|
const e = this.inputElement;
|
|
481
|
-
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((
|
|
482
|
-
this.removeChild(
|
|
491
|
+
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((n) => {
|
|
492
|
+
this.removeChild(n);
|
|
483
493
|
});
|
|
484
494
|
const t = document.createDocumentFragment();
|
|
485
495
|
let i = [];
|
|
486
|
-
this.selectionMode == "remove-only" ? i = this.items.map((
|
|
487
|
-
i.push(this.disableIfNeeded(this.items[
|
|
488
|
-
}), i.forEach((
|
|
489
|
-
const
|
|
490
|
-
|
|
496
|
+
this.selectionMode == "remove-only" ? i = this.items.map((n) => this.disableIfNeeded(n)) : this.selectedIndexes.forEach((n) => {
|
|
497
|
+
i.push(this.disableIfNeeded(this.items[n]));
|
|
498
|
+
}), i.forEach((n) => {
|
|
499
|
+
const s = this.tokenGenerator(n, this.findIndex(n));
|
|
500
|
+
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", () => {
|
|
491
501
|
document.activeElement != this && this.focus();
|
|
492
|
-
}),
|
|
502
|
+
}), s.setDeleteHandler((o) => this.removeTokens([o]));
|
|
493
503
|
}), this.appendChild(t), this._tokenSuggestPopover && this._tokenSuggestPopover.refreshItems();
|
|
494
504
|
}
|
|
495
505
|
removeTokens(e) {
|
|
@@ -510,8 +520,8 @@ const l = (h = class extends x {
|
|
|
510
520
|
}
|
|
511
521
|
onTokenClick(e, t) {
|
|
512
522
|
let i;
|
|
513
|
-
this.querySelectorAll("[slot='items']").forEach((
|
|
514
|
-
e ==
|
|
523
|
+
this.querySelectorAll("[slot='items']").forEach((n, s) => {
|
|
524
|
+
e == n ? i = s : n.setAttribute("aria-checked", "false");
|
|
515
525
|
}), this.activeTokenIndex = i, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), this.dispatchEvent(
|
|
516
526
|
new CustomEvent("token-clicked", {
|
|
517
527
|
detail: {
|
|
@@ -575,31 +585,31 @@ const l = (h = class extends x {
|
|
|
575
585
|
var e;
|
|
576
586
|
return !!((e = this.inputElement) != null && e.value);
|
|
577
587
|
}
|
|
578
|
-
},
|
|
579
|
-
b.ensureDefined(), customElements.get(
|
|
580
|
-
},
|
|
588
|
+
}, c.ID = "sd-token-selector", c.ensureDefined = () => {
|
|
589
|
+
b.ensureDefined(), customElements.get(c.ID) || customElements.define(c.ID, c);
|
|
590
|
+
}, c.shadowRootOptions = {
|
|
581
591
|
...x.shadowRootOptions,
|
|
582
592
|
delegatesFocus: !0
|
|
583
|
-
},
|
|
584
|
-
|
|
593
|
+
}, c);
|
|
594
|
+
h([
|
|
585
595
|
a({ type: String, attribute: "selection-mode", reflect: !0 })
|
|
586
596
|
], l.prototype, "selectionMode", 2);
|
|
587
|
-
|
|
597
|
+
h([
|
|
588
598
|
a({ type: Array, attribute: !1 })
|
|
589
599
|
], l.prototype, "items", 2);
|
|
590
|
-
|
|
600
|
+
h([
|
|
591
601
|
a({ type: Array, attribute: !1 })
|
|
592
602
|
], l.prototype, "selectedIndexes", 2);
|
|
593
|
-
|
|
603
|
+
h([
|
|
594
604
|
a({ type: String, reflect: !0 })
|
|
595
605
|
], l.prototype, "placeholder", 2);
|
|
596
|
-
|
|
606
|
+
h([
|
|
597
607
|
a({ type: String, reflect: !0, attribute: "suggest-list-class" })
|
|
598
608
|
], l.prototype, "suggestListClass", 2);
|
|
599
|
-
|
|
609
|
+
h([
|
|
600
610
|
a({ type: String, reflect: !0, attribute: "input-label" })
|
|
601
611
|
], l.prototype, "inputLabel", 2);
|
|
602
|
-
|
|
612
|
+
h([
|
|
603
613
|
a({
|
|
604
614
|
converter: {
|
|
605
615
|
fromAttribute: (r) => r == "true",
|
|
@@ -609,25 +619,25 @@ c([
|
|
|
609
619
|
attribute: "aria-disabled"
|
|
610
620
|
})
|
|
611
621
|
], l.prototype, "disabled", 2);
|
|
612
|
-
|
|
622
|
+
h([
|
|
613
623
|
a({ type: String, attribute: !0 })
|
|
614
624
|
], l.prototype, "validationMessage", 2);
|
|
615
|
-
|
|
625
|
+
h([
|
|
616
626
|
a({ type: String, attribute: !0 })
|
|
617
627
|
], l.prototype, "validationIconSrc", 2);
|
|
618
|
-
|
|
628
|
+
h([
|
|
619
629
|
a({ converter: S.levelConverter, attribute: !0, reflect: !0 })
|
|
620
630
|
], l.prototype, "validationLevel", 2);
|
|
621
|
-
|
|
631
|
+
h([
|
|
622
632
|
a({ type: String, reflect: !0, attribute: "token-type" })
|
|
623
633
|
], l.prototype, "tokenType", 2);
|
|
624
|
-
|
|
634
|
+
h([
|
|
625
635
|
a({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
|
|
626
636
|
], l.prototype, "caseSensitive", 2);
|
|
627
637
|
let se = l;
|
|
628
638
|
export {
|
|
629
639
|
V as SelectionMode,
|
|
630
640
|
se as default,
|
|
631
|
-
|
|
641
|
+
G as generator
|
|
632
642
|
};
|
|
633
643
|
//# sourceMappingURL=token-selector.mjs.map
|