@barabel324/popups-engine 0.0.8 → 0.0.9
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/popups-engine.d.ts +2 -0
- package/dist/popups-engine.js +41 -39
- package/package.json +1 -1
package/dist/popups-engine.d.ts
CHANGED
|
@@ -112,6 +112,8 @@ declare type TPEWrapper = FCClass<{
|
|
|
112
112
|
* Варианты анимации обертки для motion
|
|
113
113
|
*/
|
|
114
114
|
motionVariants?: TPEMotionVariants;
|
|
115
|
+
/** функция закрытия текущего попапа */
|
|
116
|
+
closePopup: () => void;
|
|
115
117
|
}>;
|
|
116
118
|
|
|
117
119
|
export declare const usePopupsEngineProvider: () => TPEContext;
|
package/dist/popups-engine.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as g, useContext as x, useRef as
|
|
3
|
-
import { motion as
|
|
2
|
+
import { createContext as g, useContext as x, useRef as D, useEffect as y, Suspense as O, useState as R, useCallback as $, useMemo as f } from "react";
|
|
3
|
+
import { motion as b, AnimatePresence as j } from "motion/react";
|
|
4
4
|
const L = g({
|
|
5
5
|
openPopup: () => {
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@ const L = g({
|
|
|
14
14
|
popupList: []
|
|
15
15
|
}), A = g({
|
|
16
16
|
popups: {}
|
|
17
|
-
}),
|
|
17
|
+
}), F = () => x(L), I = () => x(k), S = () => x(A), z = "_parent_wmksm_1", K = {
|
|
18
18
|
parent: z
|
|
19
19
|
}, M = {
|
|
20
20
|
initial: { opacity: 0 },
|
|
@@ -22,23 +22,24 @@ const L = g({
|
|
|
22
22
|
exit: { opacity: 0 }
|
|
23
23
|
}, q = ({
|
|
24
24
|
className: o,
|
|
25
|
-
motionVariants:
|
|
26
|
-
|
|
25
|
+
motionVariants: m = M,
|
|
26
|
+
closePopup: p,
|
|
27
|
+
children: t
|
|
27
28
|
}) => {
|
|
28
|
-
const
|
|
29
|
-
c.target ===
|
|
29
|
+
const r = D(null), i = (c) => {
|
|
30
|
+
c.target === r.current && p();
|
|
30
31
|
};
|
|
31
32
|
return /* @__PURE__ */ n(
|
|
32
|
-
|
|
33
|
+
b.div,
|
|
33
34
|
{
|
|
34
|
-
variants:
|
|
35
|
+
variants: m,
|
|
35
36
|
initial: "initial",
|
|
36
37
|
animate: "animate",
|
|
37
38
|
exit: "exit",
|
|
38
|
-
ref:
|
|
39
|
+
ref: r,
|
|
39
40
|
className: o ?? K.parent,
|
|
40
41
|
onClick: i,
|
|
41
|
-
children:
|
|
42
|
+
children: t
|
|
42
43
|
}
|
|
43
44
|
);
|
|
44
45
|
}, G = "_parent_1ud1o_1", H = {
|
|
@@ -53,14 +54,14 @@ const L = g({
|
|
|
53
54
|
}
|
|
54
55
|
), W = ({
|
|
55
56
|
className: o,
|
|
56
|
-
id:
|
|
57
|
+
id: m = "popups-engine-root",
|
|
57
58
|
components: p,
|
|
58
59
|
classNames: t,
|
|
59
60
|
motionVariants: r,
|
|
60
61
|
enableBodyScroll: i,
|
|
61
62
|
lockBodyScroll: c
|
|
62
63
|
}) => {
|
|
63
|
-
const { popupList: s } = I(), { popups: v } = S(), { closePopup:
|
|
64
|
+
const { popupList: s } = I(), { popups: v } = S(), { closePopup: a, closeAllPopups: u } = F();
|
|
64
65
|
return y(() => (s.length > 0 && c?.(), () => {
|
|
65
66
|
s.length > 0 && i?.();
|
|
66
67
|
}), [
|
|
@@ -68,65 +69,66 @@ const L = g({
|
|
|
68
69
|
i,
|
|
69
70
|
c
|
|
70
71
|
]), y(() => {
|
|
71
|
-
const e = (
|
|
72
|
-
|
|
72
|
+
const e = (d) => {
|
|
73
|
+
d.key === "Escape" && (s.at(-1)?.isCloseAll ? u : a)();
|
|
73
74
|
};
|
|
74
75
|
return s.length > 0 && window.addEventListener("keydown", e), () => {
|
|
75
76
|
window.removeEventListener("keydown", e);
|
|
76
77
|
};
|
|
77
78
|
}, [
|
|
78
79
|
s,
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
a,
|
|
81
|
+
u
|
|
81
82
|
]), /* @__PURE__ */ n(
|
|
82
83
|
"div",
|
|
83
84
|
{
|
|
84
85
|
className: o,
|
|
85
|
-
id:
|
|
86
|
-
children: /* @__PURE__ */ n(
|
|
86
|
+
id: m,
|
|
87
|
+
children: /* @__PURE__ */ n(j, { children: s.map((e) => {
|
|
87
88
|
const {
|
|
88
|
-
popupID:
|
|
89
|
-
variant:
|
|
89
|
+
popupID: d,
|
|
90
|
+
variant: l,
|
|
90
91
|
popupProps: E,
|
|
91
|
-
isCloseAll:
|
|
92
|
+
isCloseAll: P,
|
|
92
93
|
components: w,
|
|
93
94
|
classNames: C,
|
|
94
|
-
motionVariants:
|
|
95
|
-
} = e,
|
|
95
|
+
motionVariants: V
|
|
96
|
+
} = e, _ = w?.wrapper || p?.wrapper || q, N = w?.loader || p?.loader || J, h = v[l];
|
|
96
97
|
return h ? /* @__PURE__ */ n(
|
|
97
|
-
|
|
98
|
+
_,
|
|
98
99
|
{
|
|
99
100
|
className: C?.wrapper || t?.wrapper,
|
|
100
|
-
motionVariants:
|
|
101
|
+
motionVariants: V || r,
|
|
102
|
+
closePopup: P ? u : a,
|
|
101
103
|
children: /* @__PURE__ */ n(
|
|
102
|
-
|
|
104
|
+
O,
|
|
103
105
|
{
|
|
104
|
-
fallback: /* @__PURE__ */ n(
|
|
106
|
+
fallback: /* @__PURE__ */ n(N, { className: C?.loader || t?.loader }),
|
|
105
107
|
children: /* @__PURE__ */ n(
|
|
106
108
|
h,
|
|
107
109
|
{
|
|
108
110
|
...E,
|
|
109
|
-
closePopup:
|
|
111
|
+
closePopup: P ? u : a
|
|
110
112
|
}
|
|
111
113
|
)
|
|
112
114
|
}
|
|
113
115
|
)
|
|
114
116
|
},
|
|
115
|
-
|
|
117
|
+
d
|
|
116
118
|
) : null;
|
|
117
119
|
}) })
|
|
118
120
|
}
|
|
119
121
|
);
|
|
120
122
|
}, X = ({
|
|
121
123
|
popups: o,
|
|
122
|
-
children:
|
|
124
|
+
children: m
|
|
123
125
|
}) => {
|
|
124
|
-
const [p, t] =
|
|
125
|
-
const
|
|
126
|
-
|
|
126
|
+
const [p, t] = R([]), r = $((e) => {
|
|
127
|
+
const d = Object.keys(o), { variant: l } = e;
|
|
128
|
+
l && (d.some((P) => P === l) ? t((P) => [...P, {
|
|
127
129
|
...e,
|
|
128
130
|
popupID: Date.now()
|
|
129
|
-
}]) : console.error(`there are no "${
|
|
131
|
+
}]) : console.error(`there are no "${l}" popup`));
|
|
130
132
|
}, [o]), i = () => {
|
|
131
133
|
t((e) => e.slice(0, -1));
|
|
132
134
|
}, c = () => {
|
|
@@ -138,15 +140,15 @@ const L = g({
|
|
|
138
140
|
closePopup: i,
|
|
139
141
|
closeFirstPopup: c,
|
|
140
142
|
closeAllPopups: s
|
|
141
|
-
}), [r]),
|
|
143
|
+
}), [r]), a = f(() => ({
|
|
142
144
|
popupList: p
|
|
143
|
-
}), [p]),
|
|
145
|
+
}), [p]), u = f(() => ({
|
|
144
146
|
popups: o
|
|
145
147
|
}), [o]);
|
|
146
|
-
return /* @__PURE__ */ n(L.Provider, { value: v, children: /* @__PURE__ */ n(k.Provider, { value:
|
|
148
|
+
return /* @__PURE__ */ n(L.Provider, { value: v, children: /* @__PURE__ */ n(k.Provider, { value: a, children: /* @__PURE__ */ n(A.Provider, { value: u, children: m }) }) });
|
|
147
149
|
};
|
|
148
150
|
export {
|
|
149
151
|
X as PopupsEngineProvider,
|
|
150
152
|
W as PopupsEngineRoot,
|
|
151
|
-
|
|
153
|
+
F as usePopupsEngineProvider
|
|
152
154
|
};
|