@lanrenbang/basecoat-ultra 0.1.7 → 0.2.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/{LICENSE → LICENSE.md} +2 -2
- package/README.md +77 -147
- package/dist/css/basecoat.cdn.css +134 -1726
- package/dist/css/basecoat.cdn.min.css +1 -1
- package/dist/css/basecoat.css +34 -24
- package/dist/css/datepicker.css +277 -1080
- package/dist/css/datepicker.min.css +2 -1
- package/dist/css/resizable.css +39 -60
- package/dist/css/resizable.min.css +1 -1
- package/dist/js/all.js +1 -0
- package/dist/js/all.min.js +1 -0
- package/dist/js/basecoat.js +6 -4
- package/dist/js/basecoat.min.js +12 -12
- package/dist/js/carousel.js +8 -0
- package/dist/js/carousel.min.js +24 -17
- package/dist/js/catppuccin-theme-switcher.js +41 -6
- package/dist/js/catppuccin-theme-switcher.min.js +62 -47
- package/dist/js/datepicker.js +211 -46
- package/dist/js/datepicker.min.js +566 -423
- package/dist/js/input-otp.js +69 -79
- package/dist/js/input-otp.min.js +30 -35
- package/dist/js/pagination.js +107 -0
- package/dist/js/pagination.min.js +43 -0
- package/dist/js/resizable.js +35 -46
- package/dist/js/resizable.min.js +180 -182
- package/dist/js/sheet.js +28 -26
- package/dist/js/sheet.min.js +34 -34
- package/dist/js/toast.js +17 -35
- package/dist/js/toast.min.js +35 -56
- package/dist/js/toggle.js +5 -0
- package/dist/js/toggle.min.js +15 -10
- package/package.json +28 -14
- package/CHANGELOG-cn.md +0 -54
- package/CHANGELOG.md +0 -54
- package/README-cn.md +0 -202
package/dist/js/input-otp.js
CHANGED
|
@@ -1,93 +1,83 @@
|
|
|
1
|
-
const initOTP = (
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
const initOTP = (container) => {
|
|
2
|
+
const inputs = Array.from(container.querySelectorAll("input"));
|
|
3
|
+
const getOTPValue = () => inputs.map((input) => input.value).join("");
|
|
4
|
+
const dispatchChange = () => {
|
|
5
|
+
container.dispatchEvent(new CustomEvent("change", {
|
|
6
|
+
bubbles: true,
|
|
7
|
+
detail: { value: getOTPValue() }
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
inputs.forEach((input, index) => {
|
|
11
|
+
input.type = "text";
|
|
12
|
+
input.inputMode = "text";
|
|
13
|
+
input.setAttribute("maxlength", "1");
|
|
14
|
+
input.setAttribute("autocomplete", "one-time-code");
|
|
15
|
+
input.addEventListener("focus", () => {
|
|
16
|
+
input.select();
|
|
17
|
+
});
|
|
18
|
+
input.addEventListener("input", (e) => {
|
|
19
|
+
const val = e.target.value;
|
|
20
|
+
if (val === "") {
|
|
21
|
+
dispatchChange();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (val.length > 1) {
|
|
25
|
+
input.value = val.slice(-1);
|
|
26
|
+
}
|
|
27
|
+
dispatchChange();
|
|
28
|
+
if (input.value.length === 1 && index < inputs.length - 1) {
|
|
29
|
+
inputs[index + 1].focus();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
input.addEventListener("keydown", (e) => {
|
|
33
|
+
if (e.key === "Backspace") {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
if (input.value !== "") {
|
|
36
|
+
input.value = "";
|
|
37
|
+
dispatchChange();
|
|
38
|
+
} else if (index > 0) {
|
|
39
|
+
inputs[index - 1].focus();
|
|
18
40
|
}
|
|
19
|
-
|
|
20
|
-
|
|
41
|
+
} else if (e.key === "ArrowLeft") {
|
|
42
|
+
if (index > 0) {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
inputs[index - 1].focus();
|
|
21
45
|
}
|
|
22
|
-
|
|
46
|
+
} else if (e.key === "ArrowRight") {
|
|
47
|
+
if (index < inputs.length - 1) {
|
|
48
|
+
e.preventDefault();
|
|
23
49
|
inputs[index + 1].focus();
|
|
24
50
|
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
e.preventDefault();
|
|
29
|
-
if (input.value !== "") {
|
|
30
|
-
input.value = "";
|
|
31
|
-
} else if (index > 0) {
|
|
32
|
-
inputs[index - 1].focus();
|
|
33
|
-
}
|
|
34
|
-
} else if (e.key === "ArrowLeft") {
|
|
35
|
-
if (index > 0) {
|
|
36
|
-
e.preventDefault();
|
|
37
|
-
inputs[index - 1].focus();
|
|
38
|
-
}
|
|
39
|
-
} else if (e.key === "ArrowRight") {
|
|
40
|
-
if (index < inputs.length - 1) {
|
|
41
|
-
e.preventDefault();
|
|
42
|
-
inputs[index + 1].focus();
|
|
43
|
-
}
|
|
44
|
-
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
45
|
-
if (input.value.length >= 1 && input.selectionStart === input.selectionEnd) {
|
|
46
|
-
input.value = "";
|
|
47
|
-
}
|
|
51
|
+
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
52
|
+
if (input.value.length >= 1 && input.selectionStart === input.selectionEnd) {
|
|
53
|
+
input.value = "";
|
|
48
54
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
inputs[currentIndex].value = char;
|
|
58
|
-
currentIndex++;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
input.addEventListener("paste", (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
const pasteData = (e.clipboardData || window.clipboardData).getData("text");
|
|
60
|
+
const chars = pasteData.split("");
|
|
61
|
+
let currentIndex = index;
|
|
62
|
+
chars.forEach((char) => {
|
|
61
63
|
if (currentIndex < inputs.length) {
|
|
62
|
-
inputs[currentIndex].
|
|
63
|
-
|
|
64
|
-
inputs[inputs.length - 1].focus();
|
|
64
|
+
inputs[currentIndex].value = char;
|
|
65
|
+
currentIndex++;
|
|
65
66
|
}
|
|
66
67
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const observer = new MutationObserver((mutations) => {
|
|
73
|
-
mutations.forEach((mutation) => {
|
|
74
|
-
if (mutation.type === "childList") {
|
|
75
|
-
mutation.addedNodes.forEach((node) => {
|
|
76
|
-
if (node.nodeType === 1) {
|
|
77
|
-
if (node.classList?.contains("input-otp")) {
|
|
78
|
-
initOTP(node.parentNode);
|
|
79
|
-
} else if (node.querySelector?.(".input-otp")) {
|
|
80
|
-
initOTP(node);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
68
|
+
dispatchChange();
|
|
69
|
+
if (currentIndex < inputs.length) {
|
|
70
|
+
inputs[currentIndex].focus();
|
|
71
|
+
} else {
|
|
72
|
+
inputs[inputs.length - 1].focus();
|
|
84
73
|
}
|
|
85
74
|
});
|
|
86
75
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
container.dataset.inputOtpInitialized = true;
|
|
77
|
+
container.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
78
|
+
};
|
|
79
|
+
if (window.basecoat) {
|
|
80
|
+
window.basecoat.register("input-otp", ".input-otp:not([data-input-otp-initialized])", initOTP);
|
|
91
81
|
}
|
|
92
82
|
export {
|
|
93
83
|
initOTP
|
package/dist/js/input-otp.min.js
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
s.type === "childList" && s.addedNodes.forEach((e) => {
|
|
28
|
-
e.nodeType === 1 && (e.classList?.contains("input-otp") ? f(e.parentNode) : e.querySelector?.(".input-otp") && f(e));
|
|
29
|
-
});
|
|
1
|
+
const u = (o) => {
|
|
2
|
+
const a = Array.from(o.querySelectorAll("input")), i = () => a.map((e) => e.value).join(""), c = () => {
|
|
3
|
+
o.dispatchEvent(new CustomEvent("change", {
|
|
4
|
+
bubbles: !0,
|
|
5
|
+
detail: { value: i() }
|
|
6
|
+
}));
|
|
7
|
+
};
|
|
8
|
+
a.forEach((e, l) => {
|
|
9
|
+
e.type = "text", e.inputMode = "text", e.setAttribute("maxlength", "1"), e.setAttribute("autocomplete", "one-time-code"), e.addEventListener("focus", () => {
|
|
10
|
+
e.select();
|
|
11
|
+
}), e.addEventListener("input", (t) => {
|
|
12
|
+
const r = t.target.value;
|
|
13
|
+
if (r === "") {
|
|
14
|
+
c();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
r.length > 1 && (e.value = r.slice(-1)), c(), e.value.length === 1 && l < a.length - 1 && a[l + 1].focus();
|
|
18
|
+
}), e.addEventListener("keydown", (t) => {
|
|
19
|
+
t.key === "Backspace" ? (t.preventDefault(), e.value !== "" ? (e.value = "", c()) : l > 0 && a[l - 1].focus()) : t.key === "ArrowLeft" ? l > 0 && (t.preventDefault(), a[l - 1].focus()) : t.key === "ArrowRight" ? l < a.length - 1 && (t.preventDefault(), a[l + 1].focus()) : t.key.length === 1 && !t.ctrlKey && !t.metaKey && !t.altKey && e.value.length >= 1 && e.selectionStart === e.selectionEnd && (e.value = "");
|
|
20
|
+
}), e.addEventListener("paste", (t) => {
|
|
21
|
+
t.preventDefault();
|
|
22
|
+
const n = (t.clipboardData || window.clipboardData).getData("text").split("");
|
|
23
|
+
let s = l;
|
|
24
|
+
n.forEach((f) => {
|
|
25
|
+
s < a.length && (a[s].value = f, s++);
|
|
26
|
+
}), c(), s < a.length ? a[s].focus() : a[a.length - 1].focus();
|
|
30
27
|
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
}
|
|
28
|
+
}), o.dataset.inputOtpInitialized = !0, o.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
29
|
+
};
|
|
30
|
+
window.basecoat && window.basecoat.register("input-otp", ".input-otp:not([data-input-otp-initialized])", u);
|
|
36
31
|
export {
|
|
37
|
-
|
|
32
|
+
u as initOTP
|
|
38
33
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const initPagination = (container) => {
|
|
3
|
+
const prevBtn = container.querySelector("[data-pagination-prev]");
|
|
4
|
+
const nextBtn = container.querySelector("[data-pagination-next]");
|
|
5
|
+
const pageButtons = container.querySelectorAll("[data-pagination-page]");
|
|
6
|
+
if (!prevBtn || !nextBtn || pageButtons.length === 0) {
|
|
7
|
+
console.error("Pagination: Missing required elements (prev, next, or page buttons)", container);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let totalPages = parseInt(container.dataset.totalPages, 10) || pageButtons.length;
|
|
11
|
+
let currentPage = 1;
|
|
12
|
+
const initialCurrent = container.querySelector('[aria-current="page"]') || container.querySelector("[data-pagination-page].btn-outline");
|
|
13
|
+
if (initialCurrent) {
|
|
14
|
+
currentPage = parseInt(initialCurrent.dataset.paginationPage, 10) || 1;
|
|
15
|
+
}
|
|
16
|
+
const updateUI = () => {
|
|
17
|
+
if (currentPage <= 1) {
|
|
18
|
+
prevBtn.setAttribute("disabled", "");
|
|
19
|
+
prevBtn.setAttribute("aria-disabled", "true");
|
|
20
|
+
} else {
|
|
21
|
+
prevBtn.removeAttribute("disabled");
|
|
22
|
+
prevBtn.removeAttribute("aria-disabled");
|
|
23
|
+
}
|
|
24
|
+
if (currentPage >= totalPages) {
|
|
25
|
+
nextBtn.setAttribute("disabled", "");
|
|
26
|
+
nextBtn.setAttribute("aria-disabled", "true");
|
|
27
|
+
} else {
|
|
28
|
+
nextBtn.removeAttribute("disabled");
|
|
29
|
+
nextBtn.removeAttribute("aria-disabled");
|
|
30
|
+
}
|
|
31
|
+
pageButtons.forEach((btn) => {
|
|
32
|
+
const page = parseInt(btn.dataset.paginationPage, 10);
|
|
33
|
+
if (page === currentPage) {
|
|
34
|
+
btn.setAttribute("aria-current", "page");
|
|
35
|
+
btn.classList.remove("btn-ghost");
|
|
36
|
+
btn.classList.add("btn-outline");
|
|
37
|
+
} else {
|
|
38
|
+
btn.removeAttribute("aria-current");
|
|
39
|
+
btn.classList.remove("btn-outline");
|
|
40
|
+
btn.classList.add("btn-ghost");
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const goToPage = (page, triggerEvent = true) => {
|
|
45
|
+
if (page < 1 || page > totalPages || page === currentPage) return;
|
|
46
|
+
const oldPage = currentPage;
|
|
47
|
+
currentPage = page;
|
|
48
|
+
updateUI();
|
|
49
|
+
if (triggerEvent) {
|
|
50
|
+
container.dispatchEvent(new CustomEvent("change", {
|
|
51
|
+
bubbles: true,
|
|
52
|
+
detail: {
|
|
53
|
+
page: currentPage,
|
|
54
|
+
previousPage: oldPage,
|
|
55
|
+
totalPages
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
prevBtn.addEventListener("click", () => {
|
|
61
|
+
goToPage(currentPage - 1);
|
|
62
|
+
});
|
|
63
|
+
nextBtn.addEventListener("click", () => {
|
|
64
|
+
goToPage(currentPage + 1);
|
|
65
|
+
});
|
|
66
|
+
pageButtons.forEach((btn) => {
|
|
67
|
+
btn.addEventListener("click", () => {
|
|
68
|
+
const page = parseInt(btn.dataset.paginationPage, 10);
|
|
69
|
+
if (!isNaN(page)) {
|
|
70
|
+
goToPage(page);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
container.addEventListener("keydown", (e) => {
|
|
75
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
goToPage(currentPage - 1);
|
|
78
|
+
} else if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
goToPage(currentPage + 1);
|
|
81
|
+
} else if (e.key === "Home") {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
goToPage(1);
|
|
84
|
+
} else if (e.key === "End") {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
goToPage(totalPages);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
updateUI();
|
|
90
|
+
container.goToPage = (page) => goToPage(page);
|
|
91
|
+
container.getCurrentPage = () => currentPage;
|
|
92
|
+
container.getTotalPages = () => totalPages;
|
|
93
|
+
container.setTotalPages = (total) => {
|
|
94
|
+
totalPages = total;
|
|
95
|
+
if (currentPage > totalPages) {
|
|
96
|
+
goToPage(totalPages);
|
|
97
|
+
} else {
|
|
98
|
+
updateUI();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
container.dataset.paginationInitialized = true;
|
|
102
|
+
container.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
103
|
+
};
|
|
104
|
+
if (window.basecoat) {
|
|
105
|
+
window.basecoat.register("pagination", "nav.pagination:not([data-pagination-initialized])", initPagination);
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const u = (t) => {
|
|
3
|
+
const r = t.querySelector("[data-pagination-prev]"), n = t.querySelector("[data-pagination-next]"), l = t.querySelectorAll("[data-pagination-page]");
|
|
4
|
+
if (!r || !n || l.length === 0) {
|
|
5
|
+
console.error("Pagination: Missing required elements (prev, next, or page buttons)", t);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
let s = parseInt(t.dataset.totalPages, 10) || l.length, a = 1;
|
|
9
|
+
const g = t.querySelector('[aria-current="page"]') || t.querySelector("[data-pagination-page].btn-outline");
|
|
10
|
+
g && (a = parseInt(g.dataset.paginationPage, 10) || 1);
|
|
11
|
+
const d = () => {
|
|
12
|
+
a <= 1 ? (r.setAttribute("disabled", ""), r.setAttribute("aria-disabled", "true")) : (r.removeAttribute("disabled"), r.removeAttribute("aria-disabled")), a >= s ? (n.setAttribute("disabled", ""), n.setAttribute("aria-disabled", "true")) : (n.removeAttribute("disabled"), n.removeAttribute("aria-disabled")), l.forEach((e) => {
|
|
13
|
+
parseInt(e.dataset.paginationPage, 10) === a ? (e.setAttribute("aria-current", "page"), e.classList.remove("btn-ghost"), e.classList.add("btn-outline")) : (e.removeAttribute("aria-current"), e.classList.remove("btn-outline"), e.classList.add("btn-ghost"));
|
|
14
|
+
});
|
|
15
|
+
}, i = (e, o = !0) => {
|
|
16
|
+
if (e < 1 || e > s || e === a) return;
|
|
17
|
+
const p = a;
|
|
18
|
+
a = e, d(), o && t.dispatchEvent(new CustomEvent("change", {
|
|
19
|
+
bubbles: !0,
|
|
20
|
+
detail: {
|
|
21
|
+
page: a,
|
|
22
|
+
previousPage: p,
|
|
23
|
+
totalPages: s
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
r.addEventListener("click", () => {
|
|
28
|
+
i(a - 1);
|
|
29
|
+
}), n.addEventListener("click", () => {
|
|
30
|
+
i(a + 1);
|
|
31
|
+
}), l.forEach((e) => {
|
|
32
|
+
e.addEventListener("click", () => {
|
|
33
|
+
const o = parseInt(e.dataset.paginationPage, 10);
|
|
34
|
+
isNaN(o) || i(o);
|
|
35
|
+
});
|
|
36
|
+
}), t.addEventListener("keydown", (e) => {
|
|
37
|
+
e.key === "ArrowLeft" || e.key === "ArrowUp" ? (e.preventDefault(), i(a - 1)) : e.key === "ArrowRight" || e.key === "ArrowDown" ? (e.preventDefault(), i(a + 1)) : e.key === "Home" ? (e.preventDefault(), i(1)) : e.key === "End" && (e.preventDefault(), i(s));
|
|
38
|
+
}), d(), t.goToPage = (e) => i(e), t.getCurrentPage = () => a, t.getTotalPages = () => s, t.setTotalPages = (e) => {
|
|
39
|
+
s = e, a > s ? i(s) : d();
|
|
40
|
+
}, t.dataset.paginationInitialized = !0, t.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
41
|
+
};
|
|
42
|
+
window.basecoat && window.basecoat.register("pagination", "nav.pagination:not([data-pagination-initialized])", u);
|
|
43
|
+
})();
|
package/dist/js/resizable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var global = typeof window !== "undefined" ? window : null;
|
|
2
2
|
var ssr = global === null;
|
|
3
|
-
var document
|
|
3
|
+
var document = !ssr ? global.document : void 0;
|
|
4
4
|
var addEventListener = "addEventListener";
|
|
5
5
|
var removeEventListener = "removeEventListener";
|
|
6
6
|
var getBoundingClientRect = "getBoundingClientRect";
|
|
@@ -12,7 +12,7 @@ var NOOP = function() {
|
|
|
12
12
|
return false;
|
|
13
13
|
};
|
|
14
14
|
var calc = ssr ? "calc" : ["", "-webkit-", "-moz-", "-o-"].filter(function(prefix) {
|
|
15
|
-
var el = document
|
|
15
|
+
var el = document.createElement("div");
|
|
16
16
|
el.style.cssText = "width:" + prefix + "calc(9px)";
|
|
17
17
|
return !!el.style.length;
|
|
18
18
|
}).shift() + "calc";
|
|
@@ -21,7 +21,7 @@ var isString = function(v) {
|
|
|
21
21
|
};
|
|
22
22
|
var elementOrSelector = function(el) {
|
|
23
23
|
if (isString(el)) {
|
|
24
|
-
var ele = document
|
|
24
|
+
var ele = document.querySelector(el);
|
|
25
25
|
if (!ele) {
|
|
26
26
|
throw new Error("Selector " + el + " did not match a DOM element");
|
|
27
27
|
}
|
|
@@ -55,7 +55,7 @@ var getGutterSize = function(gutterSize, isFirst, isLast, gutterAlign) {
|
|
|
55
55
|
return gutterSize;
|
|
56
56
|
};
|
|
57
57
|
var defaultGutterFn = function(i, gutterDirection) {
|
|
58
|
-
var gut = document
|
|
58
|
+
var gut = document.createElement("div");
|
|
59
59
|
gut.className = "gutter gutter-" + gutterDirection;
|
|
60
60
|
return gut;
|
|
61
61
|
};
|
|
@@ -294,7 +294,7 @@ var Split = function(idsOption, options) {
|
|
|
294
294
|
b.style.pointerEvents = "";
|
|
295
295
|
self.gutter.style.cursor = "";
|
|
296
296
|
self.parent.style.cursor = "";
|
|
297
|
-
document
|
|
297
|
+
document.body.style.cursor = "";
|
|
298
298
|
}
|
|
299
299
|
function startDragging(e) {
|
|
300
300
|
if ("button" in e && e.button !== 0) {
|
|
@@ -329,7 +329,7 @@ var Split = function(idsOption, options) {
|
|
|
329
329
|
b.style.pointerEvents = "none";
|
|
330
330
|
self.gutter.style.cursor = cursor;
|
|
331
331
|
self.parent.style.cursor = cursor;
|
|
332
|
-
document
|
|
332
|
+
document.body.style.cursor = cursor;
|
|
333
333
|
calculateSizes.call(self);
|
|
334
334
|
self.dragOffset = getMousePosition(e) - self.end;
|
|
335
335
|
}
|
|
@@ -471,29 +471,33 @@ var Split = function(idsOption, options) {
|
|
|
471
471
|
pairs
|
|
472
472
|
};
|
|
473
473
|
};
|
|
474
|
-
const initResizable = (
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
474
|
+
const initResizable = (group) => {
|
|
475
|
+
const direction = group.dataset.direction || "horizontal";
|
|
476
|
+
const children = Array.from(group.children).filter(
|
|
477
|
+
(el) => (el.tagName === "DIV" || el.tagName === "SECTION" || el.tagName === "ASIDE") && !el.classList.contains("gutter")
|
|
478
|
+
);
|
|
479
|
+
if (children.length < 2) return;
|
|
480
|
+
let sizes;
|
|
481
|
+
if (group.dataset.sizes) {
|
|
482
|
+
sizes = group.dataset.sizes.split(",").map(Number);
|
|
483
|
+
}
|
|
484
|
+
let minSizes;
|
|
485
|
+
if (group.dataset.minSizes) {
|
|
486
|
+
minSizes = group.dataset.minSizes.split(",").map(Number);
|
|
487
|
+
}
|
|
488
|
+
try {
|
|
489
489
|
Split(children, {
|
|
490
490
|
sizes: sizes || void 0,
|
|
491
|
-
// Default is equal
|
|
492
491
|
minSize: minSizes || 100,
|
|
493
492
|
direction,
|
|
494
|
-
gutterSize:
|
|
495
|
-
// 5px gutter
|
|
493
|
+
gutterSize: 1,
|
|
496
494
|
cursor: direction === "horizontal" ? "col-resize" : "row-resize",
|
|
495
|
+
onDragEnd: (newSizes) => {
|
|
496
|
+
group.dispatchEvent(new CustomEvent("change", {
|
|
497
|
+
bubbles: true,
|
|
498
|
+
detail: { value: newSizes }
|
|
499
|
+
}));
|
|
500
|
+
},
|
|
497
501
|
elementStyle: (dimension, size, gutterSize) => {
|
|
498
502
|
return {
|
|
499
503
|
"flex-basis": `calc(${size}% - ${gutterSize}px)`
|
|
@@ -505,29 +509,14 @@ const initResizable = (root = document) => {
|
|
|
505
509
|
};
|
|
506
510
|
}
|
|
507
511
|
});
|
|
508
|
-
|
|
509
|
-
|
|
512
|
+
} catch (e) {
|
|
513
|
+
console.error("Basecoat: Resizable initialization failed", e);
|
|
514
|
+
}
|
|
515
|
+
group.dataset.resizableInitialized = true;
|
|
516
|
+
group.dispatchEvent(new CustomEvent("basecoat:initialized"));
|
|
510
517
|
};
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
mutations.forEach((mutation) => {
|
|
514
|
-
if (mutation.type === "childList") {
|
|
515
|
-
mutation.addedNodes.forEach((node) => {
|
|
516
|
-
if (node.nodeType === 1) {
|
|
517
|
-
if (node.classList?.contains("resizable-group")) {
|
|
518
|
-
initResizable(node.parentNode);
|
|
519
|
-
} else if (node.querySelector?.(".resizable-group")) {
|
|
520
|
-
initResizable(node);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
528
|
-
initResizable();
|
|
529
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
530
|
-
});
|
|
518
|
+
if (window.basecoat) {
|
|
519
|
+
window.basecoat.register("resizable", ".resizable-group:not([data-resizable-initialized])", initResizable);
|
|
531
520
|
}
|
|
532
521
|
export {
|
|
533
522
|
initResizable
|