@paciu/ui 0.0.61 → 0.0.62
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/provider.es.js +76 -67
- package/package.json +1 -1
package/dist/provider.es.js
CHANGED
|
@@ -1,93 +1,102 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs as S, jsx as x } from "react/jsx-runtime";
|
|
3
|
-
import { createContext as M, useState as m, useRef as j, useCallback as p, useMemo as O, useEffect as
|
|
3
|
+
import { createContext as M, useState as m, useRef as j, useCallback as p, useMemo as O, useEffect as l, useContext as Q } from "react";
|
|
4
4
|
import { createPortal as $ } from "react-dom";
|
|
5
|
-
import { a as
|
|
6
|
-
const
|
|
7
|
-
const [
|
|
5
|
+
import { a as s, T as a, D as z, c as B, s as u } from "./chunks/index.es.js";
|
|
6
|
+
const T = M(void 0), H = () => Q(T), Y = ({ children: r, initialTheme: f, defaultDialogPosition: v }) => {
|
|
7
|
+
const [w, D] = m(!1), [c, L] = m(f || null), [d, k] = m(f || null), [i, g] = m([]), E = j(0), C = p((e) => {
|
|
8
8
|
document.documentElement.dataset.theme = e || void 0, L(e);
|
|
9
|
-
}, []), y = p((e,
|
|
10
|
-
g((
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
if ([
|
|
14
|
-
return
|
|
9
|
+
}, []), y = p((e, t) => {
|
|
10
|
+
g((n) => {
|
|
11
|
+
if (n.length > 0) {
|
|
12
|
+
const o = [...n], I = o.length - 1;
|
|
13
|
+
if ([s.Closing, s.Opening].includes(o[I].status))
|
|
14
|
+
return n;
|
|
15
15
|
}
|
|
16
|
-
return [...
|
|
16
|
+
return [...n, { id: ++E.current, status: s.Opening, node: e, options: t }];
|
|
17
17
|
});
|
|
18
18
|
}, []), h = p((e) => {
|
|
19
|
-
g((
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
22
|
-
const
|
|
23
|
-
return [
|
|
19
|
+
g((t) => {
|
|
20
|
+
if (t.length === 0)
|
|
21
|
+
return t;
|
|
22
|
+
const n = [...t], o = n.length - 1;
|
|
23
|
+
return [s.Closing, s.Opening].includes(n[o].status) || (e?.esc || e?.outside) && n[o]?.options?.unClosable ? t : (n[o] = { ...n[o], status: s.Closing }, n);
|
|
24
24
|
});
|
|
25
25
|
}, []), P = O(() => {
|
|
26
|
-
const e =
|
|
26
|
+
const e = c || d;
|
|
27
27
|
return e ? e === a.Light ? a.Dark : a.Light : null;
|
|
28
|
-
}, [
|
|
29
|
-
() => ({ theme:
|
|
30
|
-
[
|
|
28
|
+
}, [c, d]), b = O(
|
|
29
|
+
() => ({ theme: c, nextTheme: P, systemTheme: d, toggleTheme: C, openDialog: y, closeDialog: h, dialogsQueue: i }),
|
|
30
|
+
[c, P, d, C, y, h, i]
|
|
31
31
|
);
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
return l(() => {
|
|
33
|
+
const e = [];
|
|
34
|
+
if (i.length) {
|
|
35
|
+
const t = i[i.length - 1];
|
|
36
|
+
t.status === s.Opening && (t?.options?.onOpen && t.options.onOpen(), e.push(
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
g((n) => {
|
|
39
|
+
const o = [...n];
|
|
40
|
+
return o[o.length - 1].status = s.Opened, o;
|
|
41
|
+
}), t?.options?.onOpened && t.options.onOpened();
|
|
42
|
+
}, 240)
|
|
43
|
+
)), t.status === s.Closing && (t?.options?.onClose && t.options.onClose(), e.push(
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
g((n) => n.slice(0, -1)), t?.options?.onClosed && t.options.onClosed();
|
|
46
|
+
}, 240)
|
|
47
|
+
));
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
return () => {
|
|
50
|
+
for (const t of e)
|
|
51
|
+
clearTimeout(t);
|
|
47
52
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
}, [i]), l(() => {
|
|
54
|
+
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = (n) => {
|
|
55
|
+
k(n.matches ? a.Dark : a.Light);
|
|
56
|
+
};
|
|
57
|
+
return t(e), e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
58
|
+
}, []), l(() => {
|
|
59
|
+
document.body.style.overflowY = i.length ? "hidden" : "";
|
|
60
|
+
}, [i]), l(() => {
|
|
61
|
+
const e = (o) => {
|
|
62
|
+
o.key === "Escape" && (o.stopPropagation(), h({ esc: !0 }));
|
|
56
63
|
}, t = () => {
|
|
64
|
+
document.addEventListener("keydown", e);
|
|
65
|
+
}, n = () => {
|
|
57
66
|
document.removeEventListener("keydown", e);
|
|
58
67
|
};
|
|
59
|
-
return
|
|
60
|
-
|
|
68
|
+
return t(), () => {
|
|
69
|
+
n();
|
|
61
70
|
};
|
|
62
|
-
}, []),
|
|
71
|
+
}, []), l(() => {
|
|
63
72
|
D(!0);
|
|
64
|
-
}), /* @__PURE__ */ S(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/* @__PURE__ */ x("div", { id: "paciu-ui-dialogs", children:
|
|
68
|
-
const
|
|
73
|
+
}), /* @__PURE__ */ S(T.Provider, { value: b, children: [
|
|
74
|
+
r,
|
|
75
|
+
w && $(
|
|
76
|
+
/* @__PURE__ */ x("div", { id: "paciu-ui-dialogs", children: i.map((e, t) => {
|
|
77
|
+
const n = e?.options?.position || v || z.Center;
|
|
69
78
|
return /* @__PURE__ */ x(
|
|
70
79
|
"div",
|
|
71
80
|
{
|
|
72
|
-
className: B(
|
|
73
|
-
[
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
className: B(u["dialog-overlay"], {
|
|
82
|
+
[u["animated-opening"]]: [
|
|
83
|
+
s.Opening,
|
|
84
|
+
s.Opened
|
|
76
85
|
].includes(e.status),
|
|
77
|
-
[
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
[u["animated-closing"]]: [
|
|
87
|
+
s.Closing,
|
|
88
|
+
s.Closed
|
|
80
89
|
].includes(e.status),
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
90
|
+
[u.active]: t === i.length - 1,
|
|
91
|
+
[u["full-height"]]: e?.options?.fullHeight,
|
|
92
|
+
[u["full-width"]]: e?.options?.fullWidth,
|
|
93
|
+
[u["un-closable"]]: e?.options?.unClosable,
|
|
94
|
+
[u[`position-${n}`]]: !!n
|
|
86
95
|
}),
|
|
87
96
|
onClick: () => h({ outside: !0 }),
|
|
88
97
|
style: {
|
|
89
|
-
zIndex:
|
|
90
|
-
transform: `scale(calc(1 - ${(
|
|
98
|
+
zIndex: t + 1e3,
|
|
99
|
+
transform: `scale(calc(1 - ${(i.length - t - 1) * 0.02}))`
|
|
91
100
|
},
|
|
92
101
|
children: e.node()
|
|
93
102
|
},
|
|
@@ -98,9 +107,9 @@ const v = M(void 0), H = () => Q(v), Y = ({ children: c, initialTheme: f, defaul
|
|
|
98
107
|
)
|
|
99
108
|
] });
|
|
100
109
|
}, q = () => {
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
return
|
|
110
|
+
const r = H();
|
|
111
|
+
if (!r) throw new Error("usePaciu must be used within PaciuProvider");
|
|
112
|
+
return r;
|
|
104
113
|
};
|
|
105
114
|
export {
|
|
106
115
|
Y as PaciuProvider,
|