@cas-smartdesign/token-selector 0.16.1 → 0.17.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/4_dnd.js +1 -1
- package/dist/docs/5_other.js +1 -1
- package/dist/docs/button.mjs +2 -2
- package/dist/docs/doc.mjs +95 -102
- package/dist/docs/index.html +3 -1
- package/dist/drag-and-drop-extension.d.ts +1 -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 +163 -150
- package/dist/token-selector.mjs.map +1 -1
- package/dist/token-suggest-popover.d.ts +4 -2
- package/package.json +6 -6
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
|
|
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
|
-
import
|
|
5
|
-
import { generator as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { KeyDownDelegator as
|
|
4
|
+
import S from "@cas-smartdesign/field-validation-message";
|
|
5
|
+
import { generator as _ } from "@cas-smartdesign/list-item";
|
|
6
|
+
import C from "@cas-smartdesign/popover";
|
|
7
|
+
import y from "@cas-smartdesign/virtual-list";
|
|
8
|
+
import { KeyDownDelegator as L } from "@cas-smartdesign/element-utils";
|
|
9
9
|
import { ifDefined as A } from "lit/directives/if-defined.js";
|
|
10
10
|
import { unsafeSVG as P } from "lit/directives/unsafe-svg.js";
|
|
11
|
-
import
|
|
12
|
-
class
|
|
13
|
-
constructor(e, t, i,
|
|
14
|
-
this.inputElement = e, this.notSelectedTokensProvider = t, this.initializeCallback =
|
|
15
|
-
const
|
|
16
|
-
i(
|
|
17
|
-
}),
|
|
18
|
-
this.
|
|
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("selection", (s) => {
|
|
15
|
+
const o = s.detail.index, d = this._suggestItems[o];
|
|
16
|
+
i(d), this.hide();
|
|
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 D {
|
|
|
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;
|
|
@@ -41,7 +51,7 @@ class D {
|
|
|
41
51
|
return this._popover || (this._popover = this.createPopover(), this.initializeCallback(this)), this._popover;
|
|
42
52
|
}
|
|
43
53
|
createPopover() {
|
|
44
|
-
const e = new
|
|
54
|
+
const e = new C();
|
|
45
55
|
return e.setAttribute("trigger-type", "manual"), e.setAttribute("placement", "bottom-start"), e.setAttribute("modal", ""), e.setAttribute("popover-for", "token-autosuggest-popover"), e.setAttribute("offset", "-2"), e.targetElement = this.inputElement, e.appendChild(this._tokenList), e;
|
|
46
56
|
}
|
|
47
57
|
get isOpened() {
|
|
@@ -51,25 +61,25 @@ class D {
|
|
|
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 $ = Object.defineProperty,
|
|
58
|
-
for (var
|
|
59
|
-
(
|
|
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
|
|
63
|
-
fromAttribute: (
|
|
64
|
-
toAttribute: (
|
|
72
|
+
const w = {
|
|
73
|
+
fromAttribute: (r) => r == "true",
|
|
74
|
+
toAttribute: (r) => r
|
|
65
75
|
};
|
|
66
76
|
var u;
|
|
67
|
-
const p = (u = class extends
|
|
77
|
+
const p = (u = class extends x {
|
|
68
78
|
constructor() {
|
|
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;
|
|
@@ -88,29 +98,29 @@ const p = (u = class extends b {
|
|
|
88
98
|
});
|
|
89
99
|
}
|
|
90
100
|
render() {
|
|
91
|
-
return
|
|
101
|
+
return m`
|
|
92
102
|
<div class="container">
|
|
93
103
|
<slot name="before-icon"></slot>
|
|
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
|
}
|
|
101
111
|
renderIcon() {
|
|
102
112
|
if (this.icon || this.iconPlaceholder) {
|
|
103
113
|
const e = this.iconBackgroundColor != null ? `--token-icon-background-color: ${this.iconBackgroundColor}` : void 0;
|
|
104
|
-
return
|
|
114
|
+
return m`
|
|
105
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
|
-
super.updated(e), (e.has("icon") || e.has("iconPlaceholder")) && (this.icon || this.iconPlaceholder) &&
|
|
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);
|
|
114
124
|
}
|
|
115
125
|
setClickHandler(e) {
|
|
116
126
|
this._tokenClickHandler = e;
|
|
@@ -137,21 +147,21 @@ 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
|
-
let
|
|
149
|
-
const G = (
|
|
150
|
-
const t = document.createElement(
|
|
151
|
-
return
|
|
158
|
+
let b = p;
|
|
159
|
+
const G = (r, e) => {
|
|
160
|
+
const t = document.createElement(b.ID);
|
|
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
|
-
|
|
154
|
-
const
|
|
163
|
+
b.ensureDefined();
|
|
164
|
+
const k = "web application/json";
|
|
155
165
|
class B {
|
|
156
166
|
constructor(e, t, i) {
|
|
157
167
|
navigator.clipboard && (e.addEventListener("copy", () => {
|
|
@@ -165,16 +175,16 @@ class B {
|
|
|
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
|
-
[
|
|
187
|
+
[k]: s
|
|
178
188
|
})
|
|
179
189
|
]);
|
|
180
190
|
}
|
|
@@ -182,9 +192,9 @@ class B {
|
|
|
182
192
|
async readFromClipboard(e) {
|
|
183
193
|
const t = await navigator.clipboard.read();
|
|
184
194
|
for (const i of t)
|
|
185
|
-
if (i.types.includes(
|
|
186
|
-
const
|
|
187
|
-
Array.isArray(
|
|
195
|
+
if (i.types.includes(k)) {
|
|
196
|
+
const s = await (await i.getType(k)).text(), o = JSON.parse(s);
|
|
197
|
+
Array.isArray(o) && e(o);
|
|
188
198
|
}
|
|
189
199
|
}
|
|
190
200
|
}
|
|
@@ -192,44 +202,47 @@ const F = ":host{display:flex;contain:layout style}:host .additonal-content::slo
|
|
|
192
202
|
class H {
|
|
193
203
|
constructor(e, t) {
|
|
194
204
|
this.tokenSelector = e;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
205
|
+
const i = /* @__PURE__ */ new Map(), n = (s) => {
|
|
206
|
+
const o = s.target;
|
|
207
|
+
if (!e.contains(o)) {
|
|
208
|
+
const d = s.addedIndexes;
|
|
209
|
+
d && e.removeTokens(d.map((v) => i.get(v)));
|
|
210
|
+
}
|
|
211
|
+
i.clear();
|
|
199
212
|
};
|
|
200
|
-
e.addEventListener("dragstart", (
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
if (
|
|
204
|
-
|
|
213
|
+
e.addEventListener("dragstart", (s) => {
|
|
214
|
+
const o = s.target;
|
|
215
|
+
if (o instanceof b) {
|
|
216
|
+
if (o.disabled) {
|
|
217
|
+
s.preventDefault();
|
|
205
218
|
return;
|
|
206
219
|
}
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
const f = this.createCustomDragImage(
|
|
213
|
-
|
|
220
|
+
o.setAttribute("aria-checked", "true");
|
|
221
|
+
const d = e.querySelectorAll("[slot='items'][aria-checked='true']");
|
|
222
|
+
if (d.length > 0) {
|
|
223
|
+
const v = Array.from(d).filter((f) => !f.disabled).map((f, E) => (i.set(E, f.index), e.items[f.index]));
|
|
224
|
+
if (s.dataTransfer.setData("text/sd-token-selector", JSON.stringify(v)), s.dataTransfer.dropEffect = "move", s.dataTransfer.effectAllowed = "move", d.length > 1) {
|
|
225
|
+
const f = this.createCustomDragImage(o, v.length);
|
|
226
|
+
s.dataTransfer.setDragImage(f, -14, -14);
|
|
214
227
|
}
|
|
215
|
-
window.addEventListener("drop",
|
|
228
|
+
window.addEventListener("drop", n, { once: !0 });
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
|
-
}), e.addEventListener("dragenter", (
|
|
219
|
-
e.setAttribute("drop", ""),
|
|
220
|
-
}), e.addEventListener("dragover", (
|
|
221
|
-
|
|
222
|
-
}), 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) => {
|
|
223
236
|
e.removeAttribute("drop");
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
237
|
+
const o = s.dataTransfer.getData("text/sd-token-selector");
|
|
238
|
+
if (o)
|
|
226
239
|
try {
|
|
227
|
-
const
|
|
228
|
-
Array.isArray(
|
|
240
|
+
const d = JSON.parse(o);
|
|
241
|
+
Array.isArray(d) && (s.addedIndexes = t(d), s.preventDefault());
|
|
229
242
|
} catch {
|
|
230
243
|
}
|
|
231
244
|
}), e.addEventListener("dragend", () => {
|
|
232
|
-
window.removeEventListener("drop",
|
|
245
|
+
window.removeEventListener("drop", n), i.clear();
|
|
233
246
|
});
|
|
234
247
|
}
|
|
235
248
|
createCustomDragImage(e, t) {
|
|
@@ -237,14 +250,14 @@ class H {
|
|
|
237
250
|
if (i.setAttribute("aria-disabled", "true"), this.tokenSelector.tokenType)
|
|
238
251
|
i.value = t + " " + this.tokenSelector.tokenType;
|
|
239
252
|
else {
|
|
240
|
-
const
|
|
241
|
-
|
|
253
|
+
const n = document.createElement("div");
|
|
254
|
+
n.innerText = "+" + (t - 1), Object.assign(n.style, {
|
|
242
255
|
position: "absolute",
|
|
243
256
|
left: "90%",
|
|
244
257
|
top: "75%"
|
|
245
258
|
});
|
|
246
|
-
const
|
|
247
|
-
|
|
259
|
+
const s = document.createElement("div");
|
|
260
|
+
s.appendChild(i), s.appendChild(n), i = s;
|
|
248
261
|
}
|
|
249
262
|
return Object.assign(i.style, {
|
|
250
263
|
height: e.offsetHeight,
|
|
@@ -258,21 +271,21 @@ class H {
|
|
|
258
271
|
}), i.slot = "items", this.tokenSelector.appendChild(i), requestAnimationFrame(() => i.remove()), i;
|
|
259
272
|
}
|
|
260
273
|
}
|
|
261
|
-
var N = Object.defineProperty, j = Object.getOwnPropertyDescriptor,
|
|
262
|
-
for (var
|
|
263
|
-
(
|
|
264
|
-
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;
|
|
265
278
|
};
|
|
266
|
-
function K(
|
|
279
|
+
function K(r, e) {
|
|
267
280
|
let t;
|
|
268
281
|
return function(...i) {
|
|
269
|
-
t != null && clearTimeout(t), t = window.setTimeout(() =>
|
|
282
|
+
t != null && clearTimeout(t), t = window.setTimeout(() => r(...i), e);
|
|
270
283
|
};
|
|
271
284
|
}
|
|
272
|
-
var
|
|
273
|
-
const
|
|
285
|
+
var V = /* @__PURE__ */ ((r) => (r.RemoveOnly = "remove-only", r.Multi = "multi", r))(V || {}), c;
|
|
286
|
+
const l = (c = class extends x {
|
|
274
287
|
constructor() {
|
|
275
|
-
super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = G, this._autoSuggestItemGenerator =
|
|
288
|
+
super(...arguments), this.selectionMode = "multi", this.items = [], this.selectedIndexes = [], this._tokenGenerator = G, this._autoSuggestItemGenerator = _, this.additionalTokenCommittingKeys = [], this._activeTokenIndex = -1, this.handleInputKeyDown = (e, t) => {
|
|
276
289
|
if ((e.key === "Enter" || this.additionalTokenCommittingKeys.includes(e.key)) && t.value) {
|
|
277
290
|
e.preventDefault(), e.stopPropagation(), this.commitTokenValue(t.value);
|
|
278
291
|
return;
|
|
@@ -324,8 +337,8 @@ const d = (h = class extends b {
|
|
|
324
337
|
const t = this.inputElement;
|
|
325
338
|
if (!t || !t.value)
|
|
326
339
|
return;
|
|
327
|
-
e.composedPath().some((
|
|
328
|
-
if (
|
|
340
|
+
e.composedPath().some((n) => {
|
|
341
|
+
if (n instanceof HTMLElement && (e.composedPath().indexOf(t) > -1 || n.getAttribute("popover-for") === "token-autosuggest-popover"))
|
|
329
342
|
return !0;
|
|
330
343
|
}) || this.commitTokenValue(t.value);
|
|
331
344
|
}, this.debouncedShowTokenSuggestPopover = K(this.showFilteredTokenSuggestions.bind(this), 200);
|
|
@@ -355,14 +368,14 @@ const d = (h = class extends b {
|
|
|
355
368
|
this.inputElement ? this.inputElement.focus() : this.shadowRoot.querySelector(".container").focus();
|
|
356
369
|
}
|
|
357
370
|
render() {
|
|
358
|
-
return this.selectionMode == "remove-only" ?
|
|
371
|
+
return this.selectionMode == "remove-only" ? m`<div class="container" tabindex="0">
|
|
359
372
|
<slot name="items"
|
|
360
|
-
>${this.placeholder ?
|
|
373
|
+
>${this.placeholder ? m`<span part="remove-only-placeholder" class="placeholder"
|
|
361
374
|
>${this.placeholder}</span
|
|
362
|
-
>` :
|
|
375
|
+
>` : I}</slot
|
|
363
376
|
>
|
|
364
377
|
</div>
|
|
365
|
-
<slot class="additonal-content" name="additional-content"></slot>` :
|
|
378
|
+
<slot class="additonal-content" name="additional-content"></slot>` : m`
|
|
366
379
|
<sd-lit-input
|
|
367
380
|
class="input"
|
|
368
381
|
.extendedPrefix=${!0}
|
|
@@ -383,7 +396,7 @@ const d = (h = class extends b {
|
|
|
383
396
|
super.firstUpdated(e), this.setAttribute("role", "listbox"), this.setAttribute("aria-multiselectable", "true"), this.hasAttribute("tabIndex") || (this.tabIndex = 0), this.addEventListener("focusout", (t) => {
|
|
384
397
|
const i = t.relatedTarget;
|
|
385
398
|
!this.contains(i) && !this.shadowRoot.contains(i) && this.querySelectorAll("[slot='items'][aria-checked='true']").forEach(
|
|
386
|
-
(
|
|
399
|
+
(n) => n.checked = !1
|
|
387
400
|
);
|
|
388
401
|
}), new B(
|
|
389
402
|
this,
|
|
@@ -395,11 +408,11 @@ const d = (h = class extends b {
|
|
|
395
408
|
), new H(this, (t) => this.addMatchingItems(t));
|
|
396
409
|
}
|
|
397
410
|
addMatchingItems(e) {
|
|
398
|
-
const t = e.map((
|
|
399
|
-
const
|
|
400
|
-
return
|
|
401
|
-
}).filter((
|
|
402
|
-
|
|
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);
|
|
415
|
+
return i.length > 0 && this.handleTokenSelection(i), t;
|
|
403
416
|
}
|
|
404
417
|
removeSelectionOrActiveToken() {
|
|
405
418
|
if (!this.disabled) {
|
|
@@ -424,8 +437,8 @@ const d = (h = class extends b {
|
|
|
424
437
|
const i = this.tokenSuggestPopover.focusedSuggestToken;
|
|
425
438
|
if (i) {
|
|
426
439
|
if (!i.disabled) {
|
|
427
|
-
const
|
|
428
|
-
this.handleTokenSelection([
|
|
440
|
+
const n = this.findIndex(i);
|
|
441
|
+
this.handleTokenSelection([n]), this.tokenSuggestPopover.hide();
|
|
429
442
|
}
|
|
430
443
|
return;
|
|
431
444
|
}
|
|
@@ -457,7 +470,7 @@ const d = (h = class extends b {
|
|
|
457
470
|
return !this.selectedIndexes.includes(e);
|
|
458
471
|
}
|
|
459
472
|
get tokenSuggestPopover() {
|
|
460
|
-
return !this._tokenSuggestPopover && this.inputElement && (this._tokenSuggestPopover = new
|
|
473
|
+
return !this._tokenSuggestPopover && this.inputElement && (this._tokenSuggestPopover = new O(
|
|
461
474
|
this.inputElement,
|
|
462
475
|
() => this.items.filter((e, t) => !e.disabled && this.isTokenNotSelected(t)),
|
|
463
476
|
(e) => {
|
|
@@ -475,18 +488,18 @@ const d = (h = class extends b {
|
|
|
475
488
|
if (!this.isConnected || !this.items)
|
|
476
489
|
return;
|
|
477
490
|
const e = this.inputElement;
|
|
478
|
-
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((
|
|
479
|
-
this.removeChild(
|
|
491
|
+
e && (!this._tokenSuggestPopover || !this._tokenSuggestPopover.isOpened) && (e.value = ""), this.querySelectorAll("[slot='items']").forEach((n) => {
|
|
492
|
+
this.removeChild(n);
|
|
480
493
|
});
|
|
481
494
|
const t = document.createDocumentFragment();
|
|
482
495
|
let i = [];
|
|
483
|
-
this.selectionMode == "remove-only" ? i = this.items.map((
|
|
484
|
-
i.push(this.disableIfNeeded(this.items[
|
|
485
|
-
}), i.forEach((
|
|
486
|
-
const
|
|
487
|
-
|
|
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", () => {
|
|
488
501
|
document.activeElement != this && this.focus();
|
|
489
|
-
}),
|
|
502
|
+
}), s.setDeleteHandler((o) => this.removeTokens([o]));
|
|
490
503
|
}), this.appendChild(t), this._tokenSuggestPopover && this._tokenSuggestPopover.refreshItems();
|
|
491
504
|
}
|
|
492
505
|
removeTokens(e) {
|
|
@@ -507,8 +520,8 @@ const d = (h = class extends b {
|
|
|
507
520
|
}
|
|
508
521
|
onTokenClick(e, t) {
|
|
509
522
|
let i;
|
|
510
|
-
this.querySelectorAll("[slot='items']").forEach((
|
|
511
|
-
e ==
|
|
523
|
+
this.querySelectorAll("[slot='items']").forEach((n, s) => {
|
|
524
|
+
e == n ? i = s : n.setAttribute("aria-checked", "false");
|
|
512
525
|
}), this.activeTokenIndex = i, this.setAttribute("aria-activedescendant", this.activeTokenElement.id), this._tokenSuggestPopover && this._tokenSuggestPopover.isOpened && this._tokenSuggestPopover.hide(), this.dispatchEvent(
|
|
513
526
|
new CustomEvent("token-clicked", {
|
|
514
527
|
detail: {
|
|
@@ -572,59 +585,59 @@ const d = (h = class extends b {
|
|
|
572
585
|
var e;
|
|
573
586
|
return !!((e = this.inputElement) != null && e.value);
|
|
574
587
|
}
|
|
575
|
-
},
|
|
576
|
-
|
|
577
|
-
},
|
|
578
|
-
...
|
|
588
|
+
}, c.ID = "sd-token-selector", c.ensureDefined = () => {
|
|
589
|
+
b.ensureDefined(), customElements.get(c.ID) || customElements.define(c.ID, c);
|
|
590
|
+
}, c.shadowRootOptions = {
|
|
591
|
+
...x.shadowRootOptions,
|
|
579
592
|
delegatesFocus: !0
|
|
580
|
-
},
|
|
581
|
-
|
|
593
|
+
}, c);
|
|
594
|
+
h([
|
|
582
595
|
a({ type: String, attribute: "selection-mode", reflect: !0 })
|
|
583
|
-
],
|
|
584
|
-
|
|
596
|
+
], l.prototype, "selectionMode", 2);
|
|
597
|
+
h([
|
|
585
598
|
a({ type: Array, attribute: !1 })
|
|
586
|
-
],
|
|
587
|
-
|
|
599
|
+
], l.prototype, "items", 2);
|
|
600
|
+
h([
|
|
588
601
|
a({ type: Array, attribute: !1 })
|
|
589
|
-
],
|
|
590
|
-
|
|
602
|
+
], l.prototype, "selectedIndexes", 2);
|
|
603
|
+
h([
|
|
591
604
|
a({ type: String, reflect: !0 })
|
|
592
|
-
],
|
|
593
|
-
|
|
605
|
+
], l.prototype, "placeholder", 2);
|
|
606
|
+
h([
|
|
594
607
|
a({ type: String, reflect: !0, attribute: "suggest-list-class" })
|
|
595
|
-
],
|
|
596
|
-
|
|
608
|
+
], l.prototype, "suggestListClass", 2);
|
|
609
|
+
h([
|
|
597
610
|
a({ type: String, reflect: !0, attribute: "input-label" })
|
|
598
|
-
],
|
|
599
|
-
|
|
611
|
+
], l.prototype, "inputLabel", 2);
|
|
612
|
+
h([
|
|
600
613
|
a({
|
|
601
614
|
converter: {
|
|
602
|
-
fromAttribute: (
|
|
603
|
-
toAttribute: (
|
|
615
|
+
fromAttribute: (r) => r == "true",
|
|
616
|
+
toAttribute: (r) => r
|
|
604
617
|
},
|
|
605
618
|
reflect: !0,
|
|
606
619
|
attribute: "aria-disabled"
|
|
607
620
|
})
|
|
608
|
-
],
|
|
609
|
-
|
|
621
|
+
], l.prototype, "disabled", 2);
|
|
622
|
+
h([
|
|
610
623
|
a({ type: String, attribute: !0 })
|
|
611
|
-
],
|
|
612
|
-
|
|
624
|
+
], l.prototype, "validationMessage", 2);
|
|
625
|
+
h([
|
|
613
626
|
a({ type: String, attribute: !0 })
|
|
614
|
-
],
|
|
615
|
-
|
|
616
|
-
a({ converter:
|
|
617
|
-
],
|
|
618
|
-
|
|
627
|
+
], l.prototype, "validationIconSrc", 2);
|
|
628
|
+
h([
|
|
629
|
+
a({ converter: S.levelConverter, attribute: !0, reflect: !0 })
|
|
630
|
+
], l.prototype, "validationLevel", 2);
|
|
631
|
+
h([
|
|
619
632
|
a({ type: String, reflect: !0, attribute: "token-type" })
|
|
620
|
-
],
|
|
621
|
-
|
|
633
|
+
], l.prototype, "tokenType", 2);
|
|
634
|
+
h([
|
|
622
635
|
a({ type: Boolean, reflect: !0, attribute: "case-sensitive" })
|
|
623
|
-
],
|
|
624
|
-
let
|
|
636
|
+
], l.prototype, "caseSensitive", 2);
|
|
637
|
+
let se = l;
|
|
625
638
|
export {
|
|
626
|
-
|
|
627
|
-
|
|
639
|
+
V as SelectionMode,
|
|
640
|
+
se as default,
|
|
628
641
|
G as generator
|
|
629
642
|
};
|
|
630
643
|
//# sourceMappingURL=token-selector.mjs.map
|