slim-select 4.0.1 → 4.0.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/dist/react/index.js +64 -34
- package/dist/react/index.umd.js +1 -1
- package/dist/render.d.ts +9 -0
- package/dist/slimselect.cjs.js +1 -1
- package/dist/slimselect.cjs.js.map +1 -1
- package/dist/slimselect.es.js +64 -34
- package/dist/slimselect.es.js.map +1 -1
- package/dist/slimselect.iife.js +1 -1
- package/dist/slimselect.iife.js.map +1 -1
- package/dist/slimselect.js +1 -1
- package/dist/slimselect.js.map +1 -1
- package/dist/src/docs/helpers.d.ts +14 -0
- package/dist/vue/index.js +64 -34
- package/dist/vue/index.umd.js +1 -1
- package/package.json +3 -3
package/dist/slimselect.es.js
CHANGED
|
@@ -588,6 +588,7 @@ var O = class {
|
|
|
588
588
|
classes;
|
|
589
589
|
positionObserver = null;
|
|
590
590
|
positionObserverRaf = 0;
|
|
591
|
+
overflowShiftRaf = 0;
|
|
591
592
|
modalElements = null;
|
|
592
593
|
modalSessionActive = null;
|
|
593
594
|
bodyScrollLocked = !1;
|
|
@@ -684,7 +685,7 @@ var O = class {
|
|
|
684
685
|
this.removeClasses(this.main.main, this.classes.dirAbove), this.removeClasses(this.main.main, this.classes.dirBelow), this.removeClasses(this.content.main, this.classes.dirAbove), this.removeClasses(this.content.main, this.classes.dirBelow);
|
|
685
686
|
}
|
|
686
687
|
updateClassStyles() {
|
|
687
|
-
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length) for (let e of this.settings.class) e.trim() !== "" &&
|
|
688
|
+
if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.addClasses(this.main.main, this.classes.main), this.addClasses(this.content.main, this.classes.content), this.settings.style !== "" && (this.main.main.style.cssText = this.settings.style, this.content.main.style.cssText = this.settings.style), this.settings.class.length) for (let e of this.settings.class) e.trim() !== "" && this.main.main.classList.add(e.trim());
|
|
688
689
|
(this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
|
|
689
690
|
}
|
|
690
691
|
updateAriaAttributes() {
|
|
@@ -903,14 +904,14 @@ var O = class {
|
|
|
903
904
|
}), this.observePositionTargets()));
|
|
904
905
|
}
|
|
905
906
|
stopPositionTracking() {
|
|
906
|
-
cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null;
|
|
907
|
+
cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.cancelOverflowShift();
|
|
907
908
|
}
|
|
908
909
|
observePositionTargets() {
|
|
909
910
|
if (!this.positionObserver) return;
|
|
910
911
|
let e = /* @__PURE__ */ new Set(), t = (t) => {
|
|
911
912
|
!t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
|
|
912
913
|
};
|
|
913
|
-
t(this.main.main)
|
|
914
|
+
t(this.main.main);
|
|
914
915
|
let n = this.main.main.parentElement, r = this.settings.contentLocation;
|
|
915
916
|
for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
|
|
916
917
|
}
|
|
@@ -929,12 +930,9 @@ var O = class {
|
|
|
929
930
|
case "ArrowDown": return e.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
|
|
930
931
|
case "Tab": return this.callbacks.close(), !0;
|
|
931
932
|
case "Escape": return this.callbacks.close(), !1;
|
|
932
|
-
case " ":
|
|
933
|
-
let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
934
|
-
return t ? (t.click(), !1) : !0;
|
|
935
933
|
case "Enter":
|
|
936
|
-
let
|
|
937
|
-
return
|
|
934
|
+
let t = this.content.list.querySelector("." + this.classes.getFirst("highlighted"));
|
|
935
|
+
return t ? (t.click(), !1) : this.callbacks.addable ? (n.click(), !1) : !0;
|
|
938
936
|
}
|
|
939
937
|
return !0;
|
|
940
938
|
}, e.appendChild(t), this.callbacks.addable) {
|
|
@@ -1262,7 +1260,13 @@ var O = class {
|
|
|
1262
1260
|
}), t;
|
|
1263
1261
|
}
|
|
1264
1262
|
destroy() {
|
|
1265
|
-
this.stopPositionTracking(), this.modalElements
|
|
1263
|
+
this.stopPositionTracking(), this.modalElements ? (this.unlockBodyScroll(), this.content.main.parentElement === this.modalElements.dialog && this.restoreContentOffscreen(), this.modalElements.overlay.remove(), this.modalElements = null) : this.bodyScrollLocked && this.unlockBodyScroll(), this.main.main.remove(), this.content.main.remove(), this.removeDetachedInstanceDom();
|
|
1264
|
+
}
|
|
1265
|
+
removeDetachedInstanceDom() {
|
|
1266
|
+
let e = this.settings.id, t = this.classes.getFirst("main"), n = this.classes.getFirst("content"), r = this.classes.getFirst("modalOverlay");
|
|
1267
|
+
document.querySelectorAll(`[data-id="${e}"]`).forEach((e) => {
|
|
1268
|
+
(e.classList.contains(t) || e.classList.contains(n) || e.classList.contains(r)) && e.remove();
|
|
1269
|
+
});
|
|
1266
1270
|
}
|
|
1267
1271
|
highlightText(e, t, n) {
|
|
1268
1272
|
let r = t.trim();
|
|
@@ -1293,27 +1297,53 @@ var O = class {
|
|
|
1293
1297
|
} else this.content.main.style.margin = "-1px 0px 0px 0px";
|
|
1294
1298
|
}
|
|
1295
1299
|
setContentPosition() {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
requestAnimationFrame(() => {
|
|
1314
|
-
a(), requestAnimationFrame(a);
|
|
1300
|
+
let e = this.main.main.getBoundingClientRect();
|
|
1301
|
+
if (this.settings.contentPosition === "relative") {
|
|
1302
|
+
this.applyContentWidth(e);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
this.cancelOverflowShift();
|
|
1306
|
+
let t, n;
|
|
1307
|
+
this.settings.contentPosition === "fixed" ? (t = e.top + e.height, n = e.left) : (t = e.top + window.scrollY + e.height, n = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = n + "px", this.applyContentWidth(e);
|
|
1308
|
+
let r = this.getKnownContentWidth(e);
|
|
1309
|
+
if (r !== null) {
|
|
1310
|
+
this.content.main.style.left = this.adjustLeftForOverflow(n, e.left, r) + "px";
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
this.overflowShiftRaf = requestAnimationFrame(() => {
|
|
1314
|
+
this.overflowShiftRaf = 0, this.applyOverflowShiftFromMeasure();
|
|
1315
1315
|
});
|
|
1316
1316
|
}
|
|
1317
|
+
applyContentWidth(e) {
|
|
1318
|
+
let t = this.settings.contentWidth;
|
|
1319
|
+
if (this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", !t) {
|
|
1320
|
+
this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
|
|
1324
|
+
}
|
|
1325
|
+
cancelOverflowShift() {
|
|
1326
|
+
this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
|
|
1327
|
+
}
|
|
1328
|
+
getKnownContentWidth(e) {
|
|
1329
|
+
let t = this.settings.contentWidth;
|
|
1330
|
+
if (!t) return e.width;
|
|
1331
|
+
if (t.startsWith(">") || t.startsWith("<") || t.includes("%")) return null;
|
|
1332
|
+
let n = parseFloat(t);
|
|
1333
|
+
return Number.isNaN(n) ? null : n;
|
|
1334
|
+
}
|
|
1335
|
+
adjustLeftForOverflow(e, t, n) {
|
|
1336
|
+
let r = t + n;
|
|
1337
|
+
if (r <= window.innerWidth) return e;
|
|
1338
|
+
let i = e - (r - (window.innerWidth - 20));
|
|
1339
|
+
return this.settings.contentPosition === "fixed" ? Math.max(0, i) : Math.max(window.scrollX, i);
|
|
1340
|
+
}
|
|
1341
|
+
applyOverflowShiftFromMeasure() {
|
|
1342
|
+
let e = this.content.main.getBoundingClientRect().right;
|
|
1343
|
+
if (e <= window.innerWidth) return;
|
|
1344
|
+
let t = e - (window.innerWidth - 20), n = (parseFloat(this.content.main.style.left) || 0) - t;
|
|
1345
|
+
this.settings.contentPosition === "fixed" ? this.content.main.style.left = Math.max(0, n) + "px" : this.content.main.style.left = Math.max(window.scrollX, n) + "px";
|
|
1346
|
+
}
|
|
1317
1347
|
moveContentAbove() {
|
|
1318
1348
|
this.setContentDirection("above"), this.setContentPosition();
|
|
1319
1349
|
}
|
|
@@ -1503,7 +1533,7 @@ var F = class {
|
|
|
1503
1533
|
}
|
|
1504
1534
|
}
|
|
1505
1535
|
let n = this.getSelectedOptions();
|
|
1506
|
-
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
|
|
1536
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
|
|
1507
1537
|
}
|
|
1508
1538
|
setSelectedByValue(e) {
|
|
1509
1539
|
this.changeListen(!1);
|
|
@@ -1522,7 +1552,7 @@ var F = class {
|
|
|
1522
1552
|
}
|
|
1523
1553
|
}
|
|
1524
1554
|
let n = this.getSelectedOptions();
|
|
1525
|
-
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.changeListen(!0);
|
|
1555
|
+
this.select.multiple || (this.select.value = n.length === 1 ? n[0].value : ""), this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0);
|
|
1526
1556
|
}
|
|
1527
1557
|
updateSelect(e, t, n) {
|
|
1528
1558
|
this.changeListen(!1), e && (this.select.dataset.id = e), t && (this.select.style.cssText = t), n && (this.select.className = "", n.forEach((e) => {
|
|
@@ -1867,11 +1897,11 @@ var R = class {
|
|
|
1867
1897
|
}
|
|
1868
1898
|
search(e) {
|
|
1869
1899
|
let t = e.trim();
|
|
1870
|
-
if (
|
|
1871
|
-
this.clearSearch();
|
|
1900
|
+
if (t === "") {
|
|
1901
|
+
this.render.content.search.input.value = "", this.clearSearch();
|
|
1872
1902
|
return;
|
|
1873
1903
|
}
|
|
1874
|
-
if (this.events.search) {
|
|
1904
|
+
if (this.render.content.search.input.value !== e && (this.render.content.search.input.value = e), this.events.search) {
|
|
1875
1905
|
this.runApiSearch(t);
|
|
1876
1906
|
return;
|
|
1877
1907
|
}
|
|
@@ -1922,7 +1952,7 @@ var R = class {
|
|
|
1922
1952
|
this.render.renderError("Search event must return a promise or an array of data");
|
|
1923
1953
|
}
|
|
1924
1954
|
destroy() {
|
|
1925
|
-
this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy();
|
|
1955
|
+
this.lifecycle.destroy(), this.render.stopPositionTracking(), this.globalEvents.detach({ listenScroll: this.settings.openPosition === "auto" }), this.store.setData([]), this.render.destroy(), this.select.destroy(), delete this.selectEl.slim;
|
|
1926
1956
|
}
|
|
1927
1957
|
documentClick(e) {
|
|
1928
1958
|
this.settings.isOpen && e.target && !g(e.target, this.settings.id) && this.close(e.type);
|