@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.
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import { createContext as g, useContext as x, useRef as O, useEffect as y, Suspense as R, useState as $, useCallback as b, useMemo as f } from "react";
3
- import { motion as j, AnimatePresence as F } from "motion/react";
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
- }), V = () => x(L), I = () => x(k), S = () => x(A), z = "_parent_wmksm_1", K = {
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: u = M,
26
- children: p
25
+ motionVariants: m = M,
26
+ closePopup: p,
27
+ children: t
27
28
  }) => {
28
- const t = O(null), { closePopup: r } = V(), i = (c) => {
29
- c.target === t.current && r();
29
+ const r = D(null), i = (c) => {
30
+ c.target === r.current && p();
30
31
  };
31
32
  return /* @__PURE__ */ n(
32
- j.div,
33
+ b.div,
33
34
  {
34
- variants: u,
35
+ variants: m,
35
36
  initial: "initial",
36
37
  animate: "animate",
37
38
  exit: "exit",
38
- ref: t,
39
+ ref: r,
39
40
  className: o ?? K.parent,
40
41
  onClick: i,
41
- children: p
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: u = "popups-engine-root",
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: l, closeAllPopups: P } = V();
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 = (m) => {
72
- m.key === "Escape" && (s.at(-1)?.isCloseAll ? P : l)();
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
- l,
80
- P
80
+ a,
81
+ u
81
82
  ]), /* @__PURE__ */ n(
82
83
  "div",
83
84
  {
84
85
  className: o,
85
- id: u,
86
- children: /* @__PURE__ */ n(F, { children: s.map((e) => {
86
+ id: m,
87
+ children: /* @__PURE__ */ n(j, { children: s.map((e) => {
87
88
  const {
88
- popupID: m,
89
- variant: a,
89
+ popupID: d,
90
+ variant: l,
90
91
  popupProps: E,
91
- isCloseAll: d,
92
+ isCloseAll: P,
92
93
  components: w,
93
94
  classNames: C,
94
- motionVariants: _
95
- } = e, N = w?.wrapper || p?.wrapper || q, D = w?.loader || p?.loader || J, h = v[a];
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
- N,
98
+ _,
98
99
  {
99
100
  className: C?.wrapper || t?.wrapper,
100
- motionVariants: _ || r,
101
+ motionVariants: V || r,
102
+ closePopup: P ? u : a,
101
103
  children: /* @__PURE__ */ n(
102
- R,
104
+ O,
103
105
  {
104
- fallback: /* @__PURE__ */ n(D, { className: C?.loader || t?.loader }),
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: d ? P : l
111
+ closePopup: P ? u : a
110
112
  }
111
113
  )
112
114
  }
113
115
  )
114
116
  },
115
- m
117
+ d
116
118
  ) : null;
117
119
  }) })
118
120
  }
119
121
  );
120
122
  }, X = ({
121
123
  popups: o,
122
- children: u
124
+ children: m
123
125
  }) => {
124
- const [p, t] = $([]), r = b((e) => {
125
- const m = Object.keys(o), { variant: a } = e;
126
- a && (m.some((d) => d === a) ? t((d) => [...d, {
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 "${a}" popup`));
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]), l = f(() => ({
143
+ }), [r]), a = f(() => ({
142
144
  popupList: p
143
- }), [p]), P = f(() => ({
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: l, children: /* @__PURE__ */ n(A.Provider, { value: P, children: u }) }) });
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
- V as usePopupsEngineProvider
153
+ F as usePopupsEngineProvider
152
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barabel324/popups-engine",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/popups-engine.js",
6
6
  "types": "./dist/popups-engine.d.ts",