@fullkekw/popup 2.0.10 → 2.0.11
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/index.es.js +86 -92
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as S, jsxs as _ } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as L, useState as g, useEffect as y, Suspense as T, useContext as N } from "react";
|
|
3
3
|
import { createPortal as A } from "react-dom";
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function M(s) {
|
|
5
|
+
return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
|
|
6
6
|
}
|
|
7
7
|
var b = { exports: {} };
|
|
8
8
|
/*!
|
|
@@ -11,156 +11,150 @@ var b = { exports: {} };
|
|
|
11
11
|
http://jedwatson.github.io/classnames
|
|
12
12
|
*/
|
|
13
13
|
var C;
|
|
14
|
-
function
|
|
15
|
-
return C || (C = 1, function(
|
|
14
|
+
function q() {
|
|
15
|
+
return C || (C = 1, function(s) {
|
|
16
16
|
(function() {
|
|
17
|
-
var
|
|
18
|
-
function
|
|
17
|
+
var m = {}.hasOwnProperty;
|
|
18
|
+
function a() {
|
|
19
19
|
for (var e = "", n = 0; n < arguments.length; n++) {
|
|
20
20
|
var u = arguments[n];
|
|
21
|
-
u && (e = r(e,
|
|
21
|
+
u && (e = r(e, f(u)));
|
|
22
22
|
}
|
|
23
23
|
return e;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function f(e) {
|
|
26
26
|
if (typeof e == "string" || typeof e == "number")
|
|
27
27
|
return e;
|
|
28
28
|
if (typeof e != "object")
|
|
29
29
|
return "";
|
|
30
30
|
if (Array.isArray(e))
|
|
31
|
-
return
|
|
31
|
+
return a.apply(null, e);
|
|
32
32
|
if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
|
|
33
33
|
return e.toString();
|
|
34
34
|
var n = "";
|
|
35
35
|
for (var u in e)
|
|
36
|
-
|
|
36
|
+
m.call(e, u) && e[u] && (n = r(n, u));
|
|
37
37
|
return n;
|
|
38
38
|
}
|
|
39
39
|
function r(e, n) {
|
|
40
40
|
return n ? e ? e + " " + n : e + n : e;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
s.exports ? (a.default = a, s.exports = a) : window.classNames = a;
|
|
43
43
|
})();
|
|
44
44
|
}(b)), b.exports;
|
|
45
45
|
}
|
|
46
|
-
var
|
|
47
|
-
const
|
|
48
|
-
function B(o, d) {
|
|
49
|
-
const p = arguments.length === 2 && d !== void 0, [c, r] = x(o);
|
|
50
|
-
return p ? [
|
|
51
|
-
o,
|
|
52
|
-
d
|
|
53
|
-
] : [c, r];
|
|
54
|
-
}
|
|
55
|
-
const N = {
|
|
46
|
+
var F = q();
|
|
47
|
+
const k = /* @__PURE__ */ M(F), P = {
|
|
56
48
|
disableScroll: !0,
|
|
57
49
|
exitOnDocument: !0,
|
|
58
50
|
exitOnEscape: !0,
|
|
59
51
|
preventStateChange: !1
|
|
60
|
-
}, h = L({}),
|
|
61
|
-
const [r] =
|
|
52
|
+
}, h = L({}), Z = ({ className: s, settings: m, children: a, ...f }) => {
|
|
53
|
+
const [r] = g(z(m ?? {}, P)), [e, n] = g([]), u = {
|
|
62
54
|
nodes: e,
|
|
63
|
-
toggleNode:
|
|
64
|
-
registerNode:
|
|
65
|
-
toggleDocument:
|
|
55
|
+
toggleNode: x,
|
|
56
|
+
registerNode: v,
|
|
57
|
+
toggleDocument: O
|
|
66
58
|
};
|
|
67
|
-
|
|
59
|
+
y(() => {
|
|
68
60
|
if (typeof window > "u") return;
|
|
69
|
-
window.addEventListener("keydown",
|
|
70
|
-
function
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
61
|
+
window.addEventListener("keydown", p);
|
|
62
|
+
function p(o) {
|
|
63
|
+
if (o.key === "Escape") {
|
|
64
|
+
const c = Math.max(...e.filter((d) => d.open).map((d) => d.zIndex)), i = e.find((d) => d.open && d.zIndex === c);
|
|
73
65
|
if (!i || !i.settings.exitOnEscape || !(r != null && r.exitOnEscape)) return;
|
|
74
|
-
|
|
66
|
+
x(i.id);
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
return () => {
|
|
78
|
-
window.removeEventListener("keydown",
|
|
70
|
+
window.removeEventListener("keydown", p);
|
|
79
71
|
};
|
|
80
72
|
}, [e]);
|
|
81
|
-
function
|
|
73
|
+
function x(p, o) {
|
|
82
74
|
let t;
|
|
83
|
-
if (typeof
|
|
84
|
-
if ((r.preventStateChange || t.settings.preventStateChange) &&
|
|
85
|
-
const
|
|
86
|
-
t.open =
|
|
75
|
+
if (typeof p == "string" ? t = { ...e.find((i) => i.id === p) } : t = { ...p }, !t.id) return;
|
|
76
|
+
if ((r.preventStateChange || t.settings.preventStateChange) && o === void 0) return console.warn("Popup action prevented");
|
|
77
|
+
const c = o ?? !(t != null && t.open);
|
|
78
|
+
t.open = c, t.zIndex = c ? Math.max(...e.map((i) => i.zIndex), 0) + 1 : 0, n((i) => [...i.filter((d) => d.id !== t.id), t]), r.disableScroll && t.settings.disableScroll && c && document.body.classList.add("fkw-popup--noScroll"), !c && !e.filter((i) => i.id !== t.id).some((i) => i.open) && document.body.classList.remove("fkw-popup--noScroll");
|
|
87
79
|
}
|
|
88
|
-
function
|
|
89
|
-
n((
|
|
80
|
+
function v(p) {
|
|
81
|
+
n((o) => [...o, p]), p.open && x(p, !0);
|
|
90
82
|
}
|
|
91
|
-
function
|
|
92
|
-
const t = { ...e.find((i) => i.id ===
|
|
93
|
-
!t.id || !t.settings.exitOnDocument ||
|
|
83
|
+
function O(p, o) {
|
|
84
|
+
const t = { ...e.find((i) => i.id === p) };
|
|
85
|
+
!t.id || !t.settings.exitOnDocument || o.target.closest(".fkw-popup") || !t.settings.exitOnDocument || !r.exitOnDocument || x(t.id);
|
|
94
86
|
}
|
|
95
|
-
return /* @__PURE__ */
|
|
96
|
-
|
|
97
|
-
/* @__PURE__ */
|
|
87
|
+
return /* @__PURE__ */ S(T, { children: /* @__PURE__ */ _(h.Provider, { value: u, children: [
|
|
88
|
+
a,
|
|
89
|
+
/* @__PURE__ */ S("section", { className: k("fkw-popup-container", s), id: "fkw-popup-container", ...f })
|
|
98
90
|
] }) });
|
|
99
|
-
},
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return S(() => {
|
|
104
|
-
l(document.querySelector("#fkw-popup-container")), s.registerNode({
|
|
91
|
+
}, B = ({ children: s, className: m, layerClassName: a, style: f, id: r, settings: e, isOpen: n, setIsOpen: u, animation: x, onExit: v, onOpen: O, ...p }) => {
|
|
92
|
+
const o = N(h), [t] = g(x ?? "scale"), [c] = g(z(e ?? {}, P)), [i, d] = g(null), [l, D] = g(n ?? !1), [E, I] = g(0);
|
|
93
|
+
return y(() => {
|
|
94
|
+
d(document.querySelector("#fkw-popup-container")), o.registerNode({
|
|
105
95
|
id: r,
|
|
106
|
-
open:
|
|
96
|
+
open: l,
|
|
107
97
|
zIndex: 0,
|
|
108
|
-
settings:
|
|
98
|
+
settings: c
|
|
109
99
|
});
|
|
110
|
-
}, []),
|
|
111
|
-
|
|
112
|
-
}, [
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
I(
|
|
100
|
+
}, []), y(() => {
|
|
101
|
+
l && O && O(), !l && v && v();
|
|
102
|
+
}, [n]), y(() => {
|
|
103
|
+
const w = o.nodes.find((j) => j.id === r);
|
|
104
|
+
w && (D(w.open), w.zIndex !== 0 ? I(w.zIndex) : setTimeout(() => {
|
|
105
|
+
I(w.zIndex);
|
|
116
106
|
}, 200));
|
|
117
|
-
}, [
|
|
107
|
+
}, [o]), y(() => {
|
|
108
|
+
u === void 0 || n === l || u(l);
|
|
109
|
+
}, [l]), y(() => {
|
|
110
|
+
n === void 0 || n === l || o.toggleNode(r, n);
|
|
111
|
+
}, [n]), i ? A(/* @__PURE__ */ S(
|
|
118
112
|
"section",
|
|
119
113
|
{
|
|
120
114
|
id: r,
|
|
121
|
-
className:
|
|
122
|
-
style: { zIndex: 1e4 + E, cursor:
|
|
123
|
-
onClick:
|
|
124
|
-
children: /* @__PURE__ */
|
|
115
|
+
className: k("fkw-popup-layer", l && "fkw-popup-layer--open", a),
|
|
116
|
+
style: { zIndex: 1e4 + E, cursor: c.exitOnDocument && !c.preventStateChange ? "pointer" : "auto", ...f },
|
|
117
|
+
onClick: c.exitOnDocument && !c.preventStateChange ? (w) => o.toggleDocument(r, w) : void 0,
|
|
118
|
+
children: /* @__PURE__ */ S(
|
|
125
119
|
"article",
|
|
126
120
|
{
|
|
127
|
-
className:
|
|
121
|
+
className: k("fkw-popup", l && "fkw-popup--open", t && `fkw-popup-animation--${t}`, m),
|
|
128
122
|
role: "dialog",
|
|
129
123
|
"aria-modal": !0,
|
|
130
|
-
"aria-hidden": !
|
|
131
|
-
...
|
|
132
|
-
children:
|
|
124
|
+
"aria-hidden": !l,
|
|
125
|
+
...p,
|
|
126
|
+
children: s
|
|
133
127
|
}
|
|
134
128
|
)
|
|
135
129
|
}
|
|
136
130
|
), i) : null;
|
|
137
|
-
},
|
|
138
|
-
const u =
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
131
|
+
}, G = ({ children: s, as: m, className: a, onClick: f, disabled: r, popupId: e, ...n }) => {
|
|
132
|
+
const u = N(h), [x, v] = g(!1), O = m ?? "button";
|
|
133
|
+
y(() => {
|
|
134
|
+
const o = u.nodes.find((t) => t.id === e);
|
|
135
|
+
o && v(o.open);
|
|
142
136
|
}, [u]);
|
|
143
|
-
function
|
|
144
|
-
u.toggleNode(e),
|
|
137
|
+
function p(o) {
|
|
138
|
+
u.toggleNode(e), f && f(o);
|
|
145
139
|
}
|
|
146
|
-
return /* @__PURE__ */
|
|
140
|
+
return /* @__PURE__ */ S(O, { className: k("fkw-popup-button", x && "fkw-popup-button--active", a), role: "button", onClick: p, "aria-haspopup": "dialog", tabIndex: 0, disabled: r, "aria-disabled": r, "data-fkw-popup-operator": e, "aria-label": x ? "Close Popup" : "Open Popup", ...n, children: s });
|
|
147
141
|
};
|
|
148
|
-
function z(
|
|
149
|
-
const
|
|
150
|
-
for (const
|
|
151
|
-
|
|
152
|
-
return
|
|
142
|
+
function z(s, m) {
|
|
143
|
+
const a = { ...m };
|
|
144
|
+
for (const f in s)
|
|
145
|
+
a[f] = s[f];
|
|
146
|
+
return a;
|
|
153
147
|
}
|
|
154
|
-
const
|
|
148
|
+
const V = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
155
149
|
__proto__: null,
|
|
156
|
-
PopupButton:
|
|
157
|
-
PopupLayer:
|
|
158
|
-
PopupWindow:
|
|
150
|
+
PopupButton: G,
|
|
151
|
+
PopupLayer: Z,
|
|
152
|
+
PopupWindow: B
|
|
159
153
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
160
154
|
export {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
G as PopupButton,
|
|
156
|
+
Z as PopupLayer,
|
|
157
|
+
B as PopupWindow,
|
|
158
|
+
V as default
|
|
165
159
|
};
|
|
166
160
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../node_modules/classnames/index.js","../src/_package/useMixedState.ts","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","'use client';\r\n\r\nimport { useState } from 'react';\r\nimport { StateSetter } from './Interfaces';\r\n\r\n\r\n\r\nexport default function useMixedState<S = undefined>(): [S | undefined, StateSetter<S | undefined>];\r\nexport default function useMixedState<S>(initialState: S | (() => S)): [S, StateSetter<S>];\r\nexport default function useMixedState<S>(state: S, setter?: StateSetter<S>): [S, StateSetter<S>];\r\n\r\n\r\n\r\n/** \r\n * Use mixed state hook\r\n * \r\n * @param initialStateOrValue Initial state, can be undefined, value or function. If externalSetter not specified, will return default state\r\n * @param externalSetter External state setter. If specified will return external state\r\n */\r\nexport default function useMixedState<S>(initialStateOrValue?: S | (() => S), externalSetter?: StateSetter<S>) {\r\n const isControlled = arguments.length === 2 && externalSetter !== undefined;\r\n\r\n const [defaultState, defaultSetter] = useState<S | undefined>(initialStateOrValue);\r\n\r\n\r\n\r\n if (isControlled) {\r\n return [\r\n initialStateOrValue as S,\r\n externalSetter as StateSetter<S>\r\n ];\r\n }\r\n\r\n return [defaultState, defaultSetter];\r\n}","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n state = useMemo(() => state ?? false, []);\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useMixedState(state, stateSetter);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: state,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [isOpen]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","useMixedState","initialStateOrValue","externalSetter","isControlled","defaultState","defaultSetter","useState","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","useMemo","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;;;;;;;;;;;;AAOA,KAAC,WAAY;AAGZ,UAAIA,IAAS,CAAA,EAAG;AAEhB,eAASC,IAAc;AAGtB,iBAFIC,IAAU,IAELC,IAAI,GAAGA,IAAI,UAAU,QAAQA,KAAK;AAC1C,cAAIC,IAAM,UAAUD,CAAC;AACrB,UAAIC,MACHF,IAAUG,EAAYH,GAASI,EAAWF,CAAG,CAAC;AAAA,QAElD;AAEE,eAAOF;AAAA,MACT;AAEC,eAASI,EAAYF,GAAK;AACzB,YAAI,OAAOA,KAAQ,YAAY,OAAOA,KAAQ;AAC7C,iBAAOA;AAGR,YAAI,OAAOA,KAAQ;AAClB,iBAAO;AAGR,YAAI,MAAM,QAAQA,CAAG;AACpB,iBAAOH,EAAW,MAAM,MAAMG,CAAG;AAGlC,YAAIA,EAAI,aAAa,OAAO,UAAU,YAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe;AAClG,iBAAOA,EAAI,SAAU;AAGtB,YAAIF,IAAU;AAEd,iBAASK,KAAOH;AACf,UAAIJ,EAAO,KAAKI,GAAKG,CAAG,KAAKH,EAAIG,CAAG,MACnCL,IAAUG,EAAYH,GAASK,CAAG;AAIpC,eAAOL;AAAA,MACT;AAEC,eAASG,EAAaG,GAAOC,GAAU;AACtC,eAAKA,IAIDD,IACIA,IAAQ,MAAMC,IAGfD,IAAQC,IAPPD;AAAA,MAQV;AAEC,MAAqCE,EAAO,WAC3CT,EAAW,UAAUA,GACrBS,YAAiBT,KAOjB,OAAO,aAAaA;AAAA,IAEtB;;;;;ACzDwB,SAAAU,EAAiBC,GAAqCC,GAAiC;AAC7G,QAAMC,IAAe,UAAU,WAAW,KAAKD,M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mC,EAAYnC,EAAK,IAAI;AAAA,EAAA,GACpB,CAACkB,CAAG,CAAC;AAIR,WAASmB,EAAOxC,GAAqB;AACnC,IAAAqB,EAAI,WAAWe,CAAO,GACtBF,KAAWA,EAAQlC,CAAC;AAAA,EAAA;AAKtB,SAAQ,gBAAAW,EAAA4B,GAAA,EAAI,WAAW3B,EAAG,oBAAoByB,KAAY,4BAA4BnD,CAAS,GAAG,MAAK,UAAS,SAASsD,GAAQ,iBAAc,UAAS,UAAU,GAAG,UAAAL,GAAoB,iBAAeA,GAAU,2BAAyBC,GAAS,cAAYC,IAAW,gBAAgB,cAAe,GAAGhD,GAC1S,UAAAD,EACH,CAAA;AACF;AAIA,SAASG,EAAekD,GAAgBC,GAAoB;AACpD,QAAAC,IAAU,EAAE,GAAGD,EAAW;AAEhC,aAAWvE,KAAOsE;AACR,IAAAE,EAAAxE,CAAG,IAAIsE,EAAOtE,CAAG;AAGpB,SAAAwE;AACT;;;;;;;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState(state ?? false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: isOpen,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [state]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;;;;;;;;;;;;AAOA,KAAC,WAAY;AAGZ,UAAIA,IAAS,CAAA,EAAG;AAEhB,eAASC,IAAc;AAGtB,iBAFIC,IAAU,IAELC,IAAI,GAAGA,IAAI,UAAU,QAAQA,KAAK;AAC1C,cAAIC,IAAM,UAAUD,CAAC;AACrB,UAAIC,MACHF,IAAUG,EAAYH,GAASI,EAAWF,CAAG,CAAC;AAAA,QAElD;AAEE,eAAOF;AAAA,MACT;AAEC,eAASI,EAAYF,GAAK;AACzB,YAAI,OAAOA,KAAQ,YAAY,OAAOA,KAAQ;AAC7C,iBAAOA;AAGR,YAAI,OAAOA,KAAQ;AAClB,iBAAO;AAGR,YAAI,MAAM,QAAQA,CAAG;AACpB,iBAAOH,EAAW,MAAM,MAAMG,CAAG;AAGlC,YAAIA,EAAI,aAAa,OAAO,UAAU,YAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe;AAClG,iBAAOA,EAAI,SAAU;AAGtB,YAAIF,IAAU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BE;AAkBzB,GAOaO,IAAqC,CAAC,EAAE,UAAA5C,GAAU,IAAA6C,GAAI,WAAA/C,GAAW,SAAAgD,GAAS,UAAAC,GAAU,SAAAC,GAAS,GAAG/C,QAAY;AACjH,QAAAiC,IAAMC,EAAWxC,CAAY,GAE7B,CAACsD,GAAUC,CAAW,IAAI/C,EAAkB,EAAK,GAEjDgD,IAAmCN,KAAM;AAK/C,EAAAlC,EAAU,MAAM;AACd,UAAMK,IAAOkB,EAAI,MAAM,KAAK,CAAMnB,MAAAA,EAAG,OAAOiC,CAAO;AACnD,IAAKhC,KAELkC,EAAYlC,EAAK,IAAI;AAAA,EAAA,GACpB,CAACkB,CAAG,CAAC;AAIR,WAASkB,EAAOvC,GAAqB;AACnC,IAAAqB,EAAI,WAAWc,CAAO,GACtBF,KAAWA,EAAQjC,CAAC;AAAA,EAAA;AAKtB,SAAQ,gBAAAW,EAAA2B,GAAA,EAAI,WAAW1B,EAAG,oBAAoBwB,KAAY,4BAA4BnD,CAAS,GAAG,MAAK,UAAS,SAASsD,GAAQ,iBAAc,UAAS,UAAU,GAAG,UAAAL,GAAoB,iBAAeA,GAAU,2BAAyBC,GAAS,cAAYC,IAAW,gBAAgB,cAAe,GAAGhD,GAC1S,UAAAD,EACH,CAAA;AACF;AAIA,SAASI,EAAeiD,GAAgBC,GAAoB;AACpD,QAAAC,IAAU,EAAE,GAAGD,EAAW;AAEhC,aAAWhE,KAAO+D;AACR,IAAAE,EAAAjE,CAAG,IAAI+D,EAAO/D,CAAG;AAGpB,SAAAiE;AACT;;;;;;;","x_google_ignoreList":[0]}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],m):(d=typeof globalThis<"u"?globalThis:d||self,m(d["@fullkekw/fkw-popup"]={},d.ReactJsxRuntime,d.React,d.ReactDOM))})(this,function(d,m,o,D){"use strict";function T(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var h={exports:{}};/*!
|
|
2
2
|
Copyright (c) 2018 Jed Watson.
|
|
3
3
|
Licensed under the MIT License (MIT), see
|
|
4
4
|
http://jedwatson.github.io/classnames
|
|
5
|
-
*/var P;function
|
|
5
|
+
*/var P;function _(){return P||(P=1,function(u){(function(){var w={}.hasOwnProperty;function c(){for(var e="",n=0;n<arguments.length;n++){var f=arguments[n];f&&(e=i(e,l(f)))}return e}function l(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return c.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var n="";for(var f in e)w.call(e,f)&&e[f]&&(n=i(n,f));return n}function i(e,n){return n?e?e+" "+n:e+n:e}u.exports?(c.default=c,u.exports=c):window.classNames=c})()}(h)),h.exports}var L=_();const O=T(L),E={disableScroll:!0,exitOnDocument:!0,exitOnEscape:!0,preventStateChange:!1},b=o.createContext({}),I=({className:u,settings:w,children:c,...l})=>{const[i]=o.useState(j(w??{},E)),[e,n]=o.useState([]),f={nodes:e,toggleNode:y,registerNode:v,toggleDocument:k};o.useEffect(()=>{if(typeof window>"u")return;window.addEventListener("keydown",p);function p(s){if(s.key==="Escape"){const a=Math.max(...e.filter(x=>x.open).map(x=>x.zIndex)),r=e.find(x=>x.open&&x.zIndex===a);if(!r||!r.settings.exitOnEscape||!(i!=null&&i.exitOnEscape))return;y(r.id)}}return()=>{window.removeEventListener("keydown",p)}},[e]);function y(p,s){let t;if(typeof p=="string"?t={...e.find(r=>r.id===p)}:t={...p},!t.id)return;if((i.preventStateChange||t.settings.preventStateChange)&&s===void 0)return console.warn("Popup action prevented");const a=s??!(t!=null&&t.open);t.open=a,t.zIndex=a?Math.max(...e.map(r=>r.zIndex),0)+1:0,n(r=>[...r.filter(x=>x.id!==t.id),t]),i.disableScroll&&t.settings.disableScroll&&a&&document.body.classList.add("fkw-popup--noScroll"),!a&&!e.filter(r=>r.id!==t.id).some(r=>r.open)&&document.body.classList.remove("fkw-popup--noScroll")}function v(p){n(s=>[...s,p]),p.open&&y(p,!0)}function k(p,s){const t={...e.find(r=>r.id===p)};!t.id||!t.settings.exitOnDocument||s.target.closest(".fkw-popup")||!t.settings.exitOnDocument||!i.exitOnDocument||y(t.id)}return m.jsx(o.Suspense,{children:m.jsxs(b.Provider,{value:f,children:[c,m.jsx("section",{className:O("fkw-popup-container",u),id:"fkw-popup-container",...l})]})})},C=({children:u,className:w,layerClassName:c,style:l,id:i,settings:e,isOpen:n,setIsOpen:f,animation:y,onExit:v,onOpen:k,...p})=>{const s=o.useContext(b),[t]=o.useState(y??"scale"),[a]=o.useState(j(e??{},E)),[r,x]=o.useState(null),[g,q]=o.useState(n??!1),[A,z]=o.useState(0);return o.useEffect(()=>{x(document.querySelector("#fkw-popup-container")),s.registerNode({id:i,open:g,zIndex:0,settings:a})},[]),o.useEffect(()=>{g&&k&&k(),!g&&v&&v()},[n]),o.useEffect(()=>{const S=s.nodes.find(B=>B.id===i);S&&(q(S.open),S.zIndex!==0?z(S.zIndex):setTimeout(()=>{z(S.zIndex)},200))},[s]),o.useEffect(()=>{f===void 0||n===g||f(g)},[g]),o.useEffect(()=>{n===void 0||n===g||s.toggleNode(i,n)},[n]),r?D.createPortal(m.jsx("section",{id:i,className:O("fkw-popup-layer",g&&"fkw-popup-layer--open",c),style:{zIndex:1e4+A,cursor:a.exitOnDocument&&!a.preventStateChange?"pointer":"auto",...l},onClick:a.exitOnDocument&&!a.preventStateChange?S=>s.toggleDocument(i,S):void 0,children:m.jsx("article",{className:O("fkw-popup",g&&"fkw-popup--open",t&&`fkw-popup-animation--${t}`,w),role:"dialog","aria-modal":!0,"aria-hidden":!g,...p,children:u})}),r):null},N=({children:u,as:w,className:c,onClick:l,disabled:i,popupId:e,...n})=>{const f=o.useContext(b),[y,v]=o.useState(!1),k=w??"button";o.useEffect(()=>{const s=f.nodes.find(t=>t.id===e);s&&v(s.open)},[f]);function p(s){f.toggleNode(e),l&&l(s)}return m.jsx(k,{className:O("fkw-popup-button",y&&"fkw-popup-button--active",c),role:"button",onClick:p,"aria-haspopup":"dialog",tabIndex:0,disabled:i,"aria-disabled":i,"data-fkw-popup-operator":e,"aria-label":y?"Close Popup":"Open Popup",...n,children:u})};function j(u,w){const c={...w};for(const l in u)c[l]=u[l];return c}const M=Object.freeze(Object.defineProperty({__proto__:null,PopupButton:N,PopupLayer:I,PopupWindow:C},Symbol.toStringTag,{value:"Module"}));d.PopupButton=N,d.PopupLayer=I,d.PopupWindow=C,d.default=M,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
6
6
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../node_modules/classnames/index.js","../src/_package/useMixedState.ts","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","'use client';\r\n\r\nimport { useState } from 'react';\r\nimport { StateSetter } from './Interfaces';\r\n\r\n\r\n\r\nexport default function useMixedState<S = undefined>(): [S | undefined, StateSetter<S | undefined>];\r\nexport default function useMixedState<S>(initialState: S | (() => S)): [S, StateSetter<S>];\r\nexport default function useMixedState<S>(state: S, setter?: StateSetter<S>): [S, StateSetter<S>];\r\n\r\n\r\n\r\n/** \r\n * Use mixed state hook\r\n * \r\n * @param initialStateOrValue Initial state, can be undefined, value or function. If externalSetter not specified, will return default state\r\n * @param externalSetter External state setter. If specified will return external state\r\n */\r\nexport default function useMixedState<S>(initialStateOrValue?: S | (() => S), externalSetter?: StateSetter<S>) {\r\n const isControlled = arguments.length === 2 && externalSetter !== undefined;\r\n\r\n const [defaultState, defaultSetter] = useState<S | undefined>(initialStateOrValue);\r\n\r\n\r\n\r\n if (isControlled) {\r\n return [\r\n initialStateOrValue as S,\r\n externalSetter as StateSetter<S>\r\n ];\r\n }\r\n\r\n return [defaultState, defaultSetter];\r\n}","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n state = useMemo(() => state ?? false, []);\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useMixedState(state, stateSetter);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: state,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [isOpen]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","useMixedState","initialStateOrValue","externalSetter","isControlled","defaultState","defaultSetter","useState","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","useMemo","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;iDAOC,UAAY,CAGZ,IAAIA,EAAS,CAAA,EAAG,eAEhB,SAASC,GAAc,CAGtB,QAFIC,EAAU,GAELC,EAAI,EAAGA,EAAI,UAAU,OAA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S,GAAItC,CAAS,EACnH,KAAK,SACL,aAAU,GACV,cAAa,CAACyC,EACb,GAAGtC,EAEH,SAAAD,CAAA,CAAA,CACH,GACUqC,CAAS,EAjBE,IAkBzB,EAOaO,EAAqC,CAAC,CAAE,SAAA5C,EAAU,GAAA6C,EAAI,UAAA/C,EAAW,QAAAgD,EAAS,SAAAC,EAAU,QAAAC,EAAS,GAAG/C,KAAY,CACjH,MAAAgC,EAAMC,aAAWvC,CAAY,EAE7B,CAACsD,EAAUC,CAAW,EAAIzD,EAAAA,SAAkB,EAAK,EAEjD0D,EAAmCN,GAAM,SAK/CnC,EAAAA,UAAU,IAAM,CACd,MAAMK,EAAOkB,EAAI,MAAM,KAAWnB,GAAAA,EAAG,KAAOkC,CAAO,EAC9CjC,GAELmC,EAAYnC,EAAK,IAAI,CAAA,EACpB,CAACkB,CAAG,CAAC,EAIR,SAASmB,EAAOxC,EAAqB,CACnCqB,EAAI,WAAWe,CAAO,EACtBF,GAAWA,EAAQlC,CAAC,CAAA,CAKtB,OAAQW,EAAA,IAAA4B,EAAA,CAAI,UAAW3B,EAAG,mBAAoByB,GAAY,2BAA4BnD,CAAS,EAAG,KAAK,SAAS,QAASsD,EAAQ,gBAAc,SAAS,SAAU,EAAG,SAAAL,EAAoB,gBAAeA,EAAU,0BAAyBC,EAAS,aAAYC,EAAW,cAAgB,aAAe,GAAGhD,EAC1S,SAAAD,CACH,CAAA,CACF,EAIA,SAASG,EAAekD,EAAgBC,EAAoB,CACpD,MAAAC,EAAU,CAAE,GAAGD,CAAW,EAEhC,UAAWvE,KAAOsE,EACRE,EAAAxE,CAAG,EAAIsE,EAAOtE,CAAG,EAGpB,OAAAwE,CACT","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState(state ?? false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: isOpen,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [state]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;iDAOC,UAAY,CAGZ,IAAIA,EAAS,CAAA,EAAG,eAEhB,SAASC,GAAc,CAGtB,QAFIC,EAAU,GAELC,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAAK,CAC1C,IAAIC,EAAM,UAAUD,CAAC,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