@lanrenbang/basecoat-ultra 0.1.2
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/CHANGELOG-cn.md +54 -0
- package/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README-cn.md +186 -0
- package/README.md +173 -0
- package/dist/css/basecoat.cdn.css +7389 -0
- package/dist/css/basecoat.cdn.min.css +2 -0
- package/dist/css/basecoat.css +1797 -0
- package/dist/css/datepicker.css +382 -0
- package/dist/css/datepicker.min.css +1 -0
- package/dist/css/resizable.css +96 -0
- package/dist/css/resizable.min.css +1 -0
- package/dist/js/accordion.js +20 -0
- package/dist/js/accordion.min.js +13 -0
- package/dist/js/all.js +17 -0
- package/dist/js/all.min.js +17 -0
- package/dist/js/basecoat.js +75 -0
- package/dist/js/basecoat.min.js +56 -0
- package/dist/js/carousel.js +104 -0
- package/dist/js/carousel.min.js +41 -0
- package/dist/js/catppuccin-theme-switcher.js +136 -0
- package/dist/js/catppuccin-theme-switcher.min.js +73 -0
- package/dist/js/command.js +132 -0
- package/dist/js/command.min.js +76 -0
- package/dist/js/datepicker.js +2367 -0
- package/dist/js/datepicker.min.js +1422 -0
- package/dist/js/dialog.js +20 -0
- package/dist/js/dialog.min.js +11 -0
- package/dist/js/dropdown-menu.js +148 -0
- package/dist/js/dropdown-menu.min.js +75 -0
- package/dist/js/input-otp.js +94 -0
- package/dist/js/input-otp.min.js +38 -0
- package/dist/js/lighting.js +80 -0
- package/dist/js/lighting.min.js +44 -0
- package/dist/js/popover.js +72 -0
- package/dist/js/popover.min.js +34 -0
- package/dist/js/resizable.js +534 -0
- package/dist/js/resizable.min.js +284 -0
- package/dist/js/select.js +246 -0
- package/dist/js/select.min.js +131 -0
- package/dist/js/sheet.js +85 -0
- package/dist/js/sheet.min.js +40 -0
- package/dist/js/sidebar.js +87 -0
- package/dist/js/sidebar.min.js +53 -0
- package/dist/js/slider.js +18 -0
- package/dist/js/slider.min.js +10 -0
- package/dist/js/tabs.js +53 -0
- package/dist/js/tabs.min.js +40 -0
- package/dist/js/toast.js +137 -0
- package/dist/js/toast.min.js +83 -0
- package/dist/js/toggle.js +36 -0
- package/dist/js/toggle.min.js +20 -0
- package/dist/theme/catppuccin/index.css +448 -0
- package/dist/theme/catppuccin/index.min.css +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var d = typeof window < "u" ? window : null, W = d === null, N = W ? void 0 : d.document, m = "addEventListener", z = "removeEventListener", T = "getBoundingClientRect", L = "_a", h = "_b", y = "_c", k = "horizontal", g = function() {
|
|
2
|
+
return !1;
|
|
3
|
+
}, he = W ? "calc" : ["", "-webkit-", "-moz-", "-o-"].filter(function(l) {
|
|
4
|
+
var i = N.createElement("div");
|
|
5
|
+
return i.style.cssText = "width:" + l + "calc(9px)", !!i.style.length;
|
|
6
|
+
}).shift() + "calc", ne = function(l) {
|
|
7
|
+
return typeof l == "string" || l instanceof String;
|
|
8
|
+
}, re = function(l) {
|
|
9
|
+
if (ne(l)) {
|
|
10
|
+
var i = N.querySelector(l);
|
|
11
|
+
if (!i)
|
|
12
|
+
throw new Error("Selector " + l + " did not match a DOM element");
|
|
13
|
+
return i;
|
|
14
|
+
}
|
|
15
|
+
return l;
|
|
16
|
+
}, f = function(l, i, a) {
|
|
17
|
+
var s = l[i];
|
|
18
|
+
return s !== void 0 ? s : a;
|
|
19
|
+
}, G = function(l, i, a, s) {
|
|
20
|
+
if (i) {
|
|
21
|
+
if (s === "end")
|
|
22
|
+
return 0;
|
|
23
|
+
if (s === "center")
|
|
24
|
+
return l / 2;
|
|
25
|
+
} else if (a) {
|
|
26
|
+
if (s === "start")
|
|
27
|
+
return 0;
|
|
28
|
+
if (s === "center")
|
|
29
|
+
return l / 2;
|
|
30
|
+
}
|
|
31
|
+
return l;
|
|
32
|
+
}, ge = function(l, i) {
|
|
33
|
+
var a = N.createElement("div");
|
|
34
|
+
return a.className = "gutter gutter-" + i, a;
|
|
35
|
+
}, Se = function(l, i, a) {
|
|
36
|
+
var s = {};
|
|
37
|
+
return ne(i) ? s[l] = i : s[l] = he + "(" + i + "% - " + a + "px)", s;
|
|
38
|
+
}, ye = function(l, i) {
|
|
39
|
+
var a;
|
|
40
|
+
return a = {}, a[l] = i + "px", a;
|
|
41
|
+
}, pe = function(l, i) {
|
|
42
|
+
if (i === void 0 && (i = {}), W)
|
|
43
|
+
return {};
|
|
44
|
+
var a = l, s, p, E, O, S, u;
|
|
45
|
+
Array.from && (a = Array.from(a));
|
|
46
|
+
var j = re(a[0]), M = j.parentNode, X = getComputedStyle ? getComputedStyle(M) : null, Y = X ? X.flexDirection : null, B = f(i, "sizes") || a.map(function() {
|
|
47
|
+
return 100 / a.length;
|
|
48
|
+
}), R = f(i, "minSize", 100), $ = Array.isArray(R) ? R : a.map(function() {
|
|
49
|
+
return R;
|
|
50
|
+
}), q = f(i, "maxSize", 1 / 0), ie = Array.isArray(q) ? q : a.map(function() {
|
|
51
|
+
return q;
|
|
52
|
+
}), ae = f(i, "expandToMin", !1), D = f(i, "gutterSize", 10), C = f(i, "gutterAlign", "center"), P = f(i, "snapOffset", 30), se = Array.isArray(P) ? P : a.map(function() {
|
|
53
|
+
return P;
|
|
54
|
+
}), _ = f(i, "dragInterval", 1), w = f(i, "direction", k), H = f(
|
|
55
|
+
i,
|
|
56
|
+
"cursor",
|
|
57
|
+
w === k ? "col-resize" : "row-resize"
|
|
58
|
+
), le = f(i, "gutter", ge), Z = f(
|
|
59
|
+
i,
|
|
60
|
+
"elementStyle",
|
|
61
|
+
Se
|
|
62
|
+
), ue = f(i, "gutterStyle", ye);
|
|
63
|
+
w === k ? (s = "width", p = "clientX", E = "left", O = "right", S = "clientWidth") : w === "vertical" && (s = "height", p = "clientY", E = "top", O = "bottom", S = "clientHeight");
|
|
64
|
+
function A(r, e, t, n) {
|
|
65
|
+
var c = Z(s, e, t, n);
|
|
66
|
+
Object.keys(c).forEach(function(o) {
|
|
67
|
+
r.style[o] = c[o];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function oe(r, e, t) {
|
|
71
|
+
var n = ue(s, e, t);
|
|
72
|
+
Object.keys(n).forEach(function(c) {
|
|
73
|
+
r.style[c] = n[c];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function I() {
|
|
77
|
+
return u.map(function(r) {
|
|
78
|
+
return r.size;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function J(r) {
|
|
82
|
+
return "touches" in r ? r.touches[0][p] : r[p];
|
|
83
|
+
}
|
|
84
|
+
function K(r) {
|
|
85
|
+
var e = u[this.a], t = u[this.b], n = e.size + t.size;
|
|
86
|
+
e.size = r / this.size * n, t.size = n - r / this.size * n, A(e.element, e.size, this[h], e.i), A(t.element, t.size, this[y], t.i);
|
|
87
|
+
}
|
|
88
|
+
function ce(r) {
|
|
89
|
+
var e, t = u[this.a], n = u[this.b];
|
|
90
|
+
this.dragging && (e = J(r) - this.start + (this[h] - this.dragOffset), _ > 1 && (e = Math.round(e / _) * _), e <= t.minSize + t.snapOffset + this[h] ? e = t.minSize + this[h] : e >= this.size - (n.minSize + n.snapOffset + this[y]) && (e = this.size - (n.minSize + this[y])), e >= t.maxSize - t.snapOffset + this[h] ? e = t.maxSize + this[h] : e <= this.size - (n.maxSize - n.snapOffset + this[y]) && (e = this.size - (n.maxSize + this[y])), K.call(this, e), f(i, "onDrag", g)(I()));
|
|
91
|
+
}
|
|
92
|
+
function Q() {
|
|
93
|
+
var r = u[this.a].element, e = u[this.b].element, t = r[T](), n = e[T]();
|
|
94
|
+
this.size = t[s] + n[s] + this[h] + this[y], this.start = t[E], this.end = t[O];
|
|
95
|
+
}
|
|
96
|
+
function fe(r) {
|
|
97
|
+
if (!getComputedStyle)
|
|
98
|
+
return null;
|
|
99
|
+
var e = getComputedStyle(r);
|
|
100
|
+
if (!e)
|
|
101
|
+
return null;
|
|
102
|
+
var t = r[S];
|
|
103
|
+
return t === 0 ? null : (w === k ? t -= parseFloat(e.paddingLeft) + parseFloat(e.paddingRight) : t -= parseFloat(e.paddingTop) + parseFloat(e.paddingBottom), t);
|
|
104
|
+
}
|
|
105
|
+
function ee(r) {
|
|
106
|
+
var e = fe(M);
|
|
107
|
+
if (e === null || $.reduce(function(o, v) {
|
|
108
|
+
return o + v;
|
|
109
|
+
}, 0) > e)
|
|
110
|
+
return r;
|
|
111
|
+
var t = 0, n = [], c = r.map(function(o, v) {
|
|
112
|
+
var x = e * o / 100, F = G(
|
|
113
|
+
D,
|
|
114
|
+
v === 0,
|
|
115
|
+
v === r.length - 1,
|
|
116
|
+
C
|
|
117
|
+
), U = $[v] + F;
|
|
118
|
+
return x < U ? (t += U - x, n.push(0), U) : (n.push(x - U), x);
|
|
119
|
+
});
|
|
120
|
+
return t === 0 ? r : c.map(function(o, v) {
|
|
121
|
+
var x = o;
|
|
122
|
+
if (t > 0 && n[v] - t > 0) {
|
|
123
|
+
var F = Math.min(
|
|
124
|
+
t,
|
|
125
|
+
n[v] - t
|
|
126
|
+
);
|
|
127
|
+
t -= F, x = o - F;
|
|
128
|
+
}
|
|
129
|
+
return x / e * 100;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function ve() {
|
|
133
|
+
var r = this, e = u[r.a].element, t = u[r.b].element;
|
|
134
|
+
r.dragging && f(i, "onDragEnd", g)(I()), r.dragging = !1, d[z]("mouseup", r.stop), d[z]("touchend", r.stop), d[z]("touchcancel", r.stop), d[z]("mousemove", r.move), d[z]("touchmove", r.move), r.stop = null, r.move = null, e[z]("selectstart", g), e[z]("dragstart", g), t[z]("selectstart", g), t[z]("dragstart", g), e.style.userSelect = "", e.style.webkitUserSelect = "", e.style.MozUserSelect = "", e.style.pointerEvents = "", t.style.userSelect = "", t.style.webkitUserSelect = "", t.style.MozUserSelect = "", t.style.pointerEvents = "", r.gutter.style.cursor = "", r.parent.style.cursor = "", N.body.style.cursor = "";
|
|
135
|
+
}
|
|
136
|
+
function de(r) {
|
|
137
|
+
if (!("button" in r && r.button !== 0)) {
|
|
138
|
+
var e = this, t = u[e.a].element, n = u[e.b].element;
|
|
139
|
+
e.dragging || f(i, "onDragStart", g)(I()), r.preventDefault(), e.dragging = !0, e.move = ce.bind(e), e.stop = ve.bind(e), d[m]("mouseup", e.stop), d[m]("touchend", e.stop), d[m]("touchcancel", e.stop), d[m]("mousemove", e.move), d[m]("touchmove", e.move), t[m]("selectstart", g), t[m]("dragstart", g), n[m]("selectstart", g), n[m]("dragstart", g), t.style.userSelect = "none", t.style.webkitUserSelect = "none", t.style.MozUserSelect = "none", t.style.pointerEvents = "none", n.style.userSelect = "none", n.style.webkitUserSelect = "none", n.style.MozUserSelect = "none", n.style.pointerEvents = "none", e.gutter.style.cursor = H, e.parent.style.cursor = H, N.body.style.cursor = H, Q.call(e), e.dragOffset = J(r) - e.end;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
B = ee(B);
|
|
143
|
+
var b = [];
|
|
144
|
+
u = a.map(function(r, e) {
|
|
145
|
+
var t = {
|
|
146
|
+
element: re(r),
|
|
147
|
+
size: B[e],
|
|
148
|
+
minSize: $[e],
|
|
149
|
+
maxSize: ie[e],
|
|
150
|
+
snapOffset: se[e],
|
|
151
|
+
i: e
|
|
152
|
+
}, n;
|
|
153
|
+
if (e > 0 && (n = {
|
|
154
|
+
a: e - 1,
|
|
155
|
+
b: e,
|
|
156
|
+
dragging: !1,
|
|
157
|
+
direction: w,
|
|
158
|
+
parent: M
|
|
159
|
+
}, n[h] = G(
|
|
160
|
+
D,
|
|
161
|
+
e - 1 === 0,
|
|
162
|
+
!1,
|
|
163
|
+
C
|
|
164
|
+
), n[y] = G(
|
|
165
|
+
D,
|
|
166
|
+
!1,
|
|
167
|
+
e === a.length - 1,
|
|
168
|
+
C
|
|
169
|
+
), Y === "row-reverse" || Y === "column-reverse")) {
|
|
170
|
+
var c = n.a;
|
|
171
|
+
n.a = n.b, n.b = c;
|
|
172
|
+
}
|
|
173
|
+
if (e > 0) {
|
|
174
|
+
var o = le(e, w, t.element);
|
|
175
|
+
oe(o, D, e), n[L] = de.bind(n), o[m](
|
|
176
|
+
"mousedown",
|
|
177
|
+
n[L]
|
|
178
|
+
), o[m](
|
|
179
|
+
"touchstart",
|
|
180
|
+
n[L]
|
|
181
|
+
), M.insertBefore(o, t.element), n.gutter = o;
|
|
182
|
+
}
|
|
183
|
+
return A(
|
|
184
|
+
t.element,
|
|
185
|
+
t.size,
|
|
186
|
+
G(
|
|
187
|
+
D,
|
|
188
|
+
e === 0,
|
|
189
|
+
e === a.length - 1,
|
|
190
|
+
C
|
|
191
|
+
),
|
|
192
|
+
e
|
|
193
|
+
), e > 0 && b.push(n), t;
|
|
194
|
+
});
|
|
195
|
+
function te(r) {
|
|
196
|
+
var e = r.i === b.length, t = e ? b[r.i - 1] : b[r.i];
|
|
197
|
+
Q.call(t);
|
|
198
|
+
var n = e ? t.size - r.minSize - t[y] : r.minSize + t[h];
|
|
199
|
+
K.call(t, n);
|
|
200
|
+
}
|
|
201
|
+
u.forEach(function(r) {
|
|
202
|
+
var e = r.element[T]()[s];
|
|
203
|
+
e < r.minSize && (ae ? te(r) : r.minSize = e);
|
|
204
|
+
});
|
|
205
|
+
function me(r) {
|
|
206
|
+
var e = ee(r);
|
|
207
|
+
e.forEach(function(t, n) {
|
|
208
|
+
if (n > 0) {
|
|
209
|
+
var c = b[n - 1], o = u[c.a], v = u[c.b];
|
|
210
|
+
o.size = e[n - 1], v.size = t, A(o.element, o.size, c[h], o.i), A(v.element, v.size, c[y], v.i);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function ze(r, e) {
|
|
215
|
+
b.forEach(function(t) {
|
|
216
|
+
if (e !== !0 ? t.parent.removeChild(t.gutter) : (t.gutter[z](
|
|
217
|
+
"mousedown",
|
|
218
|
+
t[L]
|
|
219
|
+
), t.gutter[z](
|
|
220
|
+
"touchstart",
|
|
221
|
+
t[L]
|
|
222
|
+
)), r !== !0) {
|
|
223
|
+
var n = Z(
|
|
224
|
+
s,
|
|
225
|
+
t.a.size,
|
|
226
|
+
t[h]
|
|
227
|
+
);
|
|
228
|
+
Object.keys(n).forEach(function(c) {
|
|
229
|
+
u[t.a].element.style[c] = "", u[t.b].element.style[c] = "";
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
setSizes: me,
|
|
236
|
+
getSizes: I,
|
|
237
|
+
collapse: function(e) {
|
|
238
|
+
te(u[e]);
|
|
239
|
+
},
|
|
240
|
+
destroy: ze,
|
|
241
|
+
parent: M,
|
|
242
|
+
pairs: b
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
const V = (l = document) => {
|
|
246
|
+
l.querySelectorAll(".resizable-group").forEach((a) => {
|
|
247
|
+
if (a.dataset.splitInitialized) return;
|
|
248
|
+
const s = a.dataset.direction || "horizontal", p = Array.from(a.children).filter((S) => S.tagName === "DIV" || S.tagName === "SECTION" || S.tagName === "ASIDE");
|
|
249
|
+
if (p.length < 2) return;
|
|
250
|
+
let E;
|
|
251
|
+
a.dataset.sizes && (E = a.dataset.sizes.split(",").map(Number));
|
|
252
|
+
let O;
|
|
253
|
+
a.dataset.minSizes && (O = a.dataset.minSizes.split(",").map(Number)), pe(p, {
|
|
254
|
+
sizes: E || void 0,
|
|
255
|
+
// Default is equal
|
|
256
|
+
minSize: O || 100,
|
|
257
|
+
direction: s,
|
|
258
|
+
gutterSize: 5,
|
|
259
|
+
// 5px gutter
|
|
260
|
+
cursor: s === "horizontal" ? "col-resize" : "row-resize",
|
|
261
|
+
elementStyle: (S, u, j) => ({
|
|
262
|
+
"flex-basis": `calc(${u}% - ${j}px)`
|
|
263
|
+
}),
|
|
264
|
+
gutterStyle: (S, u) => ({
|
|
265
|
+
"flex-basis": `${u}px`
|
|
266
|
+
})
|
|
267
|
+
}), a.dataset.splitInitialized = "true";
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
if (typeof window < "u") {
|
|
271
|
+
const l = new MutationObserver((i) => {
|
|
272
|
+
i.forEach((a) => {
|
|
273
|
+
a.type === "childList" && a.addedNodes.forEach((s) => {
|
|
274
|
+
s.nodeType === 1 && (s.classList?.contains("resizable-group") ? V(s.parentNode) : s.querySelector?.(".resizable-group") && V(s));
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
279
|
+
V(), l.observe(document.body, { childList: !0, subtree: !0 });
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
export {
|
|
283
|
+
V as initResizable
|
|
284
|
+
};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const initSelect = (selectComponent) => {
|
|
3
|
+
const trigger = selectComponent.querySelector(":scope > button");
|
|
4
|
+
const selectedLabel = trigger.querySelector(":scope > span");
|
|
5
|
+
const popover = selectComponent.querySelector(":scope > [data-popover]");
|
|
6
|
+
const listbox = popover.querySelector('[role="listbox"]');
|
|
7
|
+
const input = selectComponent.querySelector(':scope > input[type="hidden"]');
|
|
8
|
+
const filter = selectComponent.querySelector('header input[type="text"]');
|
|
9
|
+
if (!trigger || !popover || !listbox || !input) {
|
|
10
|
+
const missing = [];
|
|
11
|
+
if (!trigger) missing.push("trigger");
|
|
12
|
+
if (!popover) missing.push("popover");
|
|
13
|
+
if (!listbox) missing.push("listbox");
|
|
14
|
+
if (!input) missing.push("input");
|
|
15
|
+
console.error(`Select component initialisation failed. Missing element(s): ${missing.join(", ")}`, selectComponent);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const allOptions = Array.from(listbox.querySelectorAll('[role="option"]'));
|
|
19
|
+
const options = allOptions.filter((opt) => opt.getAttribute("aria-disabled") !== "true");
|
|
20
|
+
let visibleOptions = [...options];
|
|
21
|
+
let activeIndex = -1;
|
|
22
|
+
const setActiveOption = (index) => {
|
|
23
|
+
if (activeIndex > -1 && options[activeIndex]) {
|
|
24
|
+
options[activeIndex].classList.remove("active");
|
|
25
|
+
}
|
|
26
|
+
activeIndex = index;
|
|
27
|
+
if (activeIndex > -1) {
|
|
28
|
+
const activeOption = options[activeIndex];
|
|
29
|
+
activeOption.classList.add("active");
|
|
30
|
+
if (activeOption.id) {
|
|
31
|
+
trigger.setAttribute("aria-activedescendant", activeOption.id);
|
|
32
|
+
} else {
|
|
33
|
+
trigger.removeAttribute("aria-activedescendant");
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
trigger.removeAttribute("aria-activedescendant");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const hasTransition = () => {
|
|
40
|
+
const style = getComputedStyle(popover);
|
|
41
|
+
return parseFloat(style.transitionDuration) > 0 || parseFloat(style.transitionDelay) > 0;
|
|
42
|
+
};
|
|
43
|
+
const updateValue = (option, triggerEvent = true) => {
|
|
44
|
+
if (option) {
|
|
45
|
+
selectedLabel.innerHTML = option.innerHTML;
|
|
46
|
+
input.value = option.dataset.value;
|
|
47
|
+
listbox.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected");
|
|
48
|
+
option.setAttribute("aria-selected", "true");
|
|
49
|
+
if (triggerEvent) {
|
|
50
|
+
const event = new CustomEvent("change", {
|
|
51
|
+
detail: { value: option.dataset.value },
|
|
52
|
+
bubbles: true
|
|
53
|
+
});
|
|
54
|
+
selectComponent.dispatchEvent(event);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const closePopover = (focusOnTrigger = true) => {
|
|
59
|
+
if (popover.getAttribute("aria-hidden") === "true") return;
|
|
60
|
+
if (filter) {
|
|
61
|
+
const resetFilter = () => {
|
|
62
|
+
filter.value = "";
|
|
63
|
+
visibleOptions = [...options];
|
|
64
|
+
allOptions.forEach((opt) => opt.setAttribute("aria-hidden", "false"));
|
|
65
|
+
};
|
|
66
|
+
if (hasTransition()) {
|
|
67
|
+
popover.addEventListener("transitionend", resetFilter, { once: true });
|
|
68
|
+
} else {
|
|
69
|
+
resetFilter();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (focusOnTrigger) trigger.focus();
|
|
73
|
+
popover.setAttribute("aria-hidden", "true");
|
|
74
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
75
|
+
setActiveOption(-1);
|
|
76
|
+
};
|
|
77
|
+
const selectOption = (option) => {
|
|
78
|
+
if (!option) return;
|
|
79
|
+
const oldValue = input.value;
|
|
80
|
+
const newValue = option.dataset.value;
|
|
81
|
+
if (newValue != null && newValue !== oldValue) {
|
|
82
|
+
updateValue(option);
|
|
83
|
+
}
|
|
84
|
+
closePopover();
|
|
85
|
+
};
|
|
86
|
+
const selectByValue = (value) => {
|
|
87
|
+
const option = options.find((opt) => opt.dataset.value === value);
|
|
88
|
+
selectOption(option);
|
|
89
|
+
};
|
|
90
|
+
if (filter) {
|
|
91
|
+
const filterOptions = () => {
|
|
92
|
+
const searchTerm = filter.value.trim().toLowerCase();
|
|
93
|
+
setActiveOption(-1);
|
|
94
|
+
visibleOptions = [];
|
|
95
|
+
allOptions.forEach((option) => {
|
|
96
|
+
if (option.hasAttribute("data-force")) {
|
|
97
|
+
option.setAttribute("aria-hidden", "false");
|
|
98
|
+
if (options.includes(option)) {
|
|
99
|
+
visibleOptions.push(option);
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const optionText = (option.dataset.filter || option.textContent).trim().toLowerCase();
|
|
104
|
+
const keywordList = (option.dataset.keywords || "").toLowerCase().split(/[\s,]+/).filter(Boolean);
|
|
105
|
+
const matchesKeyword = keywordList.some((keyword) => keyword.includes(searchTerm));
|
|
106
|
+
const matches = optionText.includes(searchTerm) || matchesKeyword;
|
|
107
|
+
option.setAttribute("aria-hidden", String(!matches));
|
|
108
|
+
if (matches && options.includes(option)) {
|
|
109
|
+
visibleOptions.push(option);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
filter.addEventListener("input", filterOptions);
|
|
114
|
+
}
|
|
115
|
+
let initialOption = options.find((opt) => opt.dataset.value === input.value);
|
|
116
|
+
if (!initialOption) {
|
|
117
|
+
initialOption = options.find((opt) => opt.dataset.value !== void 0) ?? options[0];
|
|
118
|
+
}
|
|
119
|
+
updateValue(initialOption, false);
|
|
120
|
+
const handleKeyNavigation = (event) => {
|
|
121
|
+
const isPopoverOpen = popover.getAttribute("aria-hidden") === "false";
|
|
122
|
+
if (!["ArrowDown", "ArrowUp", "Enter", "Home", "End", "Escape"].includes(event.key)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isPopoverOpen) {
|
|
126
|
+
if (event.key !== "Enter" && event.key !== "Escape") {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
trigger.click();
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
if (event.key === "Escape") {
|
|
134
|
+
closePopover();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (event.key === "Enter") {
|
|
138
|
+
if (activeIndex > -1) {
|
|
139
|
+
selectOption(options[activeIndex]);
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (visibleOptions.length === 0) return;
|
|
144
|
+
const currentVisibleIndex = activeIndex > -1 ? visibleOptions.indexOf(options[activeIndex]) : -1;
|
|
145
|
+
let nextVisibleIndex = currentVisibleIndex;
|
|
146
|
+
switch (event.key) {
|
|
147
|
+
case "ArrowDown":
|
|
148
|
+
if (currentVisibleIndex < visibleOptions.length - 1) {
|
|
149
|
+
nextVisibleIndex = currentVisibleIndex + 1;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case "ArrowUp":
|
|
153
|
+
if (currentVisibleIndex > 0) {
|
|
154
|
+
nextVisibleIndex = currentVisibleIndex - 1;
|
|
155
|
+
} else if (currentVisibleIndex === -1) {
|
|
156
|
+
nextVisibleIndex = 0;
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
case "Home":
|
|
160
|
+
nextVisibleIndex = 0;
|
|
161
|
+
break;
|
|
162
|
+
case "End":
|
|
163
|
+
nextVisibleIndex = visibleOptions.length - 1;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
if (nextVisibleIndex !== currentVisibleIndex) {
|
|
167
|
+
const newActiveOption = visibleOptions[nextVisibleIndex];
|
|
168
|
+
setActiveOption(options.indexOf(newActiveOption));
|
|
169
|
+
newActiveOption.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
listbox.addEventListener("mousemove", (event) => {
|
|
173
|
+
const option = event.target.closest('[role="option"]');
|
|
174
|
+
if (option && visibleOptions.includes(option)) {
|
|
175
|
+
const index = options.indexOf(option);
|
|
176
|
+
if (index !== activeIndex) {
|
|
177
|
+
setActiveOption(index);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
listbox.addEventListener("mouseleave", () => {
|
|
182
|
+
const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
|
|
183
|
+
if (selectedOption) {
|
|
184
|
+
setActiveOption(options.indexOf(selectedOption));
|
|
185
|
+
} else {
|
|
186
|
+
setActiveOption(-1);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
trigger.addEventListener("keydown", handleKeyNavigation);
|
|
190
|
+
if (filter) {
|
|
191
|
+
filter.addEventListener("keydown", handleKeyNavigation);
|
|
192
|
+
}
|
|
193
|
+
const openPopover = () => {
|
|
194
|
+
document.dispatchEvent(new CustomEvent("basecoat:popover", {
|
|
195
|
+
detail: { source: selectComponent }
|
|
196
|
+
}));
|
|
197
|
+
if (filter) {
|
|
198
|
+
if (hasTransition()) {
|
|
199
|
+
popover.addEventListener("transitionend", () => {
|
|
200
|
+
filter.focus();
|
|
201
|
+
}, { once: true });
|
|
202
|
+
} else {
|
|
203
|
+
filter.focus();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
popover.setAttribute("aria-hidden", "false");
|
|
207
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
208
|
+
const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
|
|
209
|
+
if (selectedOption) {
|
|
210
|
+
setActiveOption(options.indexOf(selectedOption));
|
|
211
|
+
selectedOption.scrollIntoView({ block: "nearest" });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
trigger.addEventListener("click", () => {
|
|
215
|
+
const isExpanded = trigger.getAttribute("aria-expanded") === "true";
|
|
216
|
+
if (isExpanded) {
|
|
217
|
+
closePopover();
|
|
218
|
+
} else {
|
|
219
|
+
openPopover();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
listbox.addEventListener("click", (event) => {
|
|
223
|
+
const clickedOption = event.target.closest('[role="option"]');
|
|
224
|
+
if (clickedOption) {
|
|
225
|
+
selectOption(clickedOption);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
document.addEventListener("click", (event) => {
|
|
229
|
+
if (!selectComponent.contains(event.target)) {
|
|
230
|
+
closePopover(false);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
document.addEventListener("basecoat:popover", (event) => {
|
|
234
|
+
if (event.detail.source !== selectComponent) {
|
|
235
|
+
closePopover(false);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
popover.setAttribute("aria-hidden", "true");
|
|
239
|
+
selectComponent.selectByValue = selectByValue;
|
|
240
|
+
selectComponent.dataset.selectInitialized = true;
|
|
241
|
+
selectComponent.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
242
|
+
};
|
|
243
|
+
if (window.basecoat) {
|
|
244
|
+
window.basecoat.register("select", "div.select:not([data-select-initialized])", initSelect);
|
|
245
|
+
}
|
|
246
|
+
})();
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const x = (a) => {
|
|
3
|
+
const r = a.querySelector(":scope > button"), L = r.querySelector(":scope > span"), n = a.querySelector(":scope > [data-popover]"), l = n.querySelector('[role="listbox"]'), v = a.querySelector(':scope > input[type="hidden"]'), c = a.querySelector('header input[type="text"]');
|
|
4
|
+
if (!r || !n || !l || !v) {
|
|
5
|
+
const e = [];
|
|
6
|
+
r || e.push("trigger"), n || e.push("popover"), l || e.push("listbox"), v || e.push("input"), console.error(`Select component initialisation failed. Missing element(s): ${e.join(", ")}`, a);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const b = Array.from(l.querySelectorAll('[role="option"]')), s = b.filter((e) => e.getAttribute("aria-disabled") !== "true");
|
|
10
|
+
let d = [...s], o = -1;
|
|
11
|
+
const f = (e) => {
|
|
12
|
+
if (o > -1 && s[o] && s[o].classList.remove("active"), o = e, o > -1) {
|
|
13
|
+
const i = s[o];
|
|
14
|
+
i.classList.add("active"), i.id ? r.setAttribute("aria-activedescendant", i.id) : r.removeAttribute("aria-activedescendant");
|
|
15
|
+
} else
|
|
16
|
+
r.removeAttribute("aria-activedescendant");
|
|
17
|
+
}, w = () => {
|
|
18
|
+
const e = getComputedStyle(n);
|
|
19
|
+
return parseFloat(e.transitionDuration) > 0 || parseFloat(e.transitionDelay) > 0;
|
|
20
|
+
}, A = (e, i = !0) => {
|
|
21
|
+
if (e && (L.innerHTML = e.innerHTML, v.value = e.dataset.value, l.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"), e.setAttribute("aria-selected", "true"), i)) {
|
|
22
|
+
const t = new CustomEvent("change", {
|
|
23
|
+
detail: { value: e.dataset.value },
|
|
24
|
+
bubbles: !0
|
|
25
|
+
});
|
|
26
|
+
a.dispatchEvent(t);
|
|
27
|
+
}
|
|
28
|
+
}, p = (e = !0) => {
|
|
29
|
+
if (n.getAttribute("aria-hidden") !== "true") {
|
|
30
|
+
if (c) {
|
|
31
|
+
const i = () => {
|
|
32
|
+
c.value = "", d = [...s], b.forEach((t) => t.setAttribute("aria-hidden", "false"));
|
|
33
|
+
};
|
|
34
|
+
w() ? n.addEventListener("transitionend", i, { once: !0 }) : i();
|
|
35
|
+
}
|
|
36
|
+
e && r.focus(), n.setAttribute("aria-hidden", "true"), r.setAttribute("aria-expanded", "false"), f(-1);
|
|
37
|
+
}
|
|
38
|
+
}, h = (e) => {
|
|
39
|
+
if (!e) return;
|
|
40
|
+
const i = v.value, t = e.dataset.value;
|
|
41
|
+
t != null && t !== i && A(e), p();
|
|
42
|
+
}, O = (e) => {
|
|
43
|
+
const i = s.find((t) => t.dataset.value === e);
|
|
44
|
+
h(i);
|
|
45
|
+
};
|
|
46
|
+
if (c) {
|
|
47
|
+
const e = () => {
|
|
48
|
+
const i = c.value.trim().toLowerCase();
|
|
49
|
+
f(-1), d = [], b.forEach((t) => {
|
|
50
|
+
if (t.hasAttribute("data-force")) {
|
|
51
|
+
t.setAttribute("aria-hidden", "false"), s.includes(t) && d.push(t);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const u = (t.dataset.filter || t.textContent).trim().toLowerCase(), S = (t.dataset.keywords || "").toLowerCase().split(/[\s,]+/).filter(Boolean).some((q) => q.includes(i)), g = u.includes(i) || S;
|
|
55
|
+
t.setAttribute("aria-hidden", String(!g)), g && s.includes(t) && d.push(t);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
c.addEventListener("input", e);
|
|
59
|
+
}
|
|
60
|
+
let y = s.find((e) => e.dataset.value === v.value);
|
|
61
|
+
y || (y = s.find((e) => e.dataset.value !== void 0) ?? s[0]), A(y, !1);
|
|
62
|
+
const k = (e) => {
|
|
63
|
+
const i = n.getAttribute("aria-hidden") === "false";
|
|
64
|
+
if (!["ArrowDown", "ArrowUp", "Enter", "Home", "End", "Escape"].includes(e.key))
|
|
65
|
+
return;
|
|
66
|
+
if (!i) {
|
|
67
|
+
e.key !== "Enter" && e.key !== "Escape" && (e.preventDefault(), r.click());
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (e.preventDefault(), e.key === "Escape") {
|
|
71
|
+
p();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (e.key === "Enter") {
|
|
75
|
+
o > -1 && h(s[o]);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (d.length === 0) return;
|
|
79
|
+
const t = o > -1 ? d.indexOf(s[o]) : -1;
|
|
80
|
+
let u = t;
|
|
81
|
+
switch (e.key) {
|
|
82
|
+
case "ArrowDown":
|
|
83
|
+
t < d.length - 1 && (u = t + 1);
|
|
84
|
+
break;
|
|
85
|
+
case "ArrowUp":
|
|
86
|
+
t > 0 ? u = t - 1 : t === -1 && (u = 0);
|
|
87
|
+
break;
|
|
88
|
+
case "Home":
|
|
89
|
+
u = 0;
|
|
90
|
+
break;
|
|
91
|
+
case "End":
|
|
92
|
+
u = d.length - 1;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (u !== t) {
|
|
96
|
+
const E = d[u];
|
|
97
|
+
f(s.indexOf(E)), E.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
l.addEventListener("mousemove", (e) => {
|
|
101
|
+
const i = e.target.closest('[role="option"]');
|
|
102
|
+
if (i && d.includes(i)) {
|
|
103
|
+
const t = s.indexOf(i);
|
|
104
|
+
t !== o && f(t);
|
|
105
|
+
}
|
|
106
|
+
}), l.addEventListener("mouseleave", () => {
|
|
107
|
+
const e = l.querySelector('[role="option"][aria-selected="true"]');
|
|
108
|
+
f(e ? s.indexOf(e) : -1);
|
|
109
|
+
}), r.addEventListener("keydown", k), c && c.addEventListener("keydown", k);
|
|
110
|
+
const m = () => {
|
|
111
|
+
document.dispatchEvent(new CustomEvent("basecoat:popover", {
|
|
112
|
+
detail: { source: a }
|
|
113
|
+
})), c && (w() ? n.addEventListener("transitionend", () => {
|
|
114
|
+
c.focus();
|
|
115
|
+
}, { once: !0 }) : c.focus()), n.setAttribute("aria-hidden", "false"), r.setAttribute("aria-expanded", "true");
|
|
116
|
+
const e = l.querySelector('[role="option"][aria-selected="true"]');
|
|
117
|
+
e && (f(s.indexOf(e)), e.scrollIntoView({ block: "nearest" }));
|
|
118
|
+
};
|
|
119
|
+
r.addEventListener("click", () => {
|
|
120
|
+
r.getAttribute("aria-expanded") === "true" ? p() : m();
|
|
121
|
+
}), l.addEventListener("click", (e) => {
|
|
122
|
+
const i = e.target.closest('[role="option"]');
|
|
123
|
+
i && h(i);
|
|
124
|
+
}), document.addEventListener("click", (e) => {
|
|
125
|
+
a.contains(e.target) || p(!1);
|
|
126
|
+
}), document.addEventListener("basecoat:popover", (e) => {
|
|
127
|
+
e.detail.source !== a && p(!1);
|
|
128
|
+
}), n.setAttribute("aria-hidden", "true"), a.selectByValue = O, a.dataset.selectInitialized = !0, a.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
129
|
+
};
|
|
130
|
+
window.basecoat && window.basecoat.register("select", "div.select:not([data-select-initialized])", x);
|
|
131
|
+
})();
|