@kakadu/components 2.3.3 → 2.3.4

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),f=require("@kuma-ui/core"),e=require("react"),L=require("../focus-trap-react-CcpTuiJi.js"),R=require("./atom.js"),C=e.createContext({isVisible:!1}),{Provider:O}=C;function V(){return e.useContext(C)}function A({as:r,className:s,...o}){return n.jsxRuntimeExports.jsx(R.default,{as:r??R.defaultAtomElementType,...o,className:f.cx("kakadu-components-2845019685",s)})}function D({as:r,isVisible:s,label:o,shouldCloseOnOutsideClick:d=!0,shouldCloseOnEscapePress:u=!0,children:i,className:p,innerClassName:v,onClose:a,...m}){const c=e.useRef(null),x=e.useRef(null),[b,q]=e.useState(!1),[l,k]=e.useState(!1),h=e.useCallback(t=>{c.current=t,k(!1)},[]),j=e.useRef(null),T=e.useCallback(t=>{t&&(j.current=t)},[]),M=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate:()=>{var t;return(t=j.current)==null?void 0:t.focus()},clickOutsideDeactivates:d,escapeDeactivates:u,onDeactivate(){k(!1)}}),[d,u]),[P,I]=e.useState(s??!1),N=e.useMemo(()=>({isVisible:P,setInitialFocus:T,close:h}),[P,T,h]),[E,F]=e.useState(!1),[w,y]=e.useState(!1);return e.useEffect(()=>{const t=x.current;if(t){const g=()=>{const S=t.getBoundingClientRect();F(S.left<0),y(S.right>window.innerWidth)};return g(),window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g)}}},[]),e.useEffect(()=>{s&&(q(!0),I(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{k(!0)},100);return()=>{clearTimeout(t)}}k(!1)},[s]),e.useEffect(()=>{if(b&&!l){const t=setTimeout(()=>{a==null||a(c.current??void 0),I(!1)},370);return()=>{clearTimeout(t)}}},[b,l,a]),n.jsxRuntimeExports.jsx(R.default,{reference:x,as:r??R.defaultAtomElementType,role:"dialog","aria-hidden":!l,"aria-label":o??"Popover",...m,className:f.cx("kakadu-components-3920007758",E&&"kakadu-components-611400930",w&&"kakadu-components-944244368",l&&"kakadu-components-1399012551",p),children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-1118152266",l&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-2899069338",E&&"kakadu-components-1495725644",w&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(L.focusTrapReactExports.FocusTrap,{active:l,focusTrapOptions:M,children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-3905822111",v),children:[n.jsxRuntimeExports.jsx(O,{value:N,children:i}),n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-3328048824",E&&"kakadu-components-3754561431",w&&"kakadu-components-2265262600")})]})})]})})}function _(r,s){const[o,d]=e.useState(!1),u=e.useRef(void 0),i=e.useRef(null),p=e.useCallback(async m=>(d(!0),i.current=m??document.activeElement,new Promise(c=>{u.current=c})),[]),v=e.useCallback(m=>{var c;if(d(!1),(c=u.current)==null||c.call(u,m),u.current=void 0,i.current){const x=i.current;x.isConnected&&x.focus(),i.current=null}},[]),a=e.useMemo(()=>n.jsxRuntimeExports.jsx(r,{...s,isVisible:o,onClose:v}),[r,s,o,v]);return e.useMemo(()=>({isVisible:o,show:p,popover:a}),[o,p,a])}exports.PopoverContainer=A;exports.default=D;exports.usePopover=_;exports.usePopoverContext=V;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../jsx-runtime-BB_1_6y_.js"),d=require("@kuma-ui/core"),e=require("react"),_=require("../focus-trap-react-CcpTuiJi.js"),w=require("./atom.js"),D=e.createContext({isVisible:!1}),{Provider:z}=D;function B(){return e.useContext(D)}function $({as:i,className:n,...o}){return s.jsxRuntimeExports.jsx(w.default,{as:i??w.defaultAtomElementType,...o,className:d.cx("kakadu-components-2845019685",n)})}function H({as:i,isVisible:n,label:o,shouldCloseOnOutsideClick:m=!0,shouldCloseOnEscapePress:r=!0,children:u,className:k,innerClassName:R,onClose:c,...p}){const a=e.useRef(null),x=e.useRef(null),[T,V]=e.useState(!1),[l,h]=e.useState(!1),C=e.useCallback(t=>{a.current=t,h(!1)},[]),E=e.useRef(null),M=e.useCallback(t=>{t&&(E.current=t)},[]),A=e.useMemo(()=>({initialFocus:()=>E.current??void 0,onActivate:()=>{var t;return(t=E.current)==null?void 0:t.focus()},clickOutsideDeactivates:m,escapeDeactivates:r,onDeactivate(){h(!1)}}),[m,r]),[I,S]=e.useState(n??!1),W=e.useMemo(()=>({isVisible:I,setInitialFocus:M,close:C}),[I,M,C]),[f,q]=e.useState("center");return e.useEffect(()=>{const t=x.current;if(t){const g=()=>{const N=t.offsetParent,b=N instanceof HTMLElement?N.getBoundingClientRect():null,F=t.getBoundingClientRect();if(!b){q("center");return}const P=b.left+b.width/2-F.width/2,L=P+F.width,O=P<0,y=L>window.innerWidth;let v="center";if(O&&y){const j=Math.abs(P);v=L-window.innerWidth>j?"right":"left"}else y?v="right":O&&(v="left");q(j=>j===v?j:v)};return g(),window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g)}}},[]),e.useEffect(()=>{n&&(V(!0),S(!0))},[n]),e.useEffect(()=>{if(n){const t=setTimeout(()=>{h(!0)},100);return()=>{clearTimeout(t)}}h(!1)},[n]),e.useEffect(()=>{if(T&&!l){const t=setTimeout(()=>{c==null||c(a.current??void 0),S(!1)},370);return()=>{clearTimeout(t)}}},[T,l,c]),s.jsxRuntimeExports.jsx(w.default,{reference:x,as:i??w.defaultAtomElementType,role:"dialog","aria-hidden":!l,"aria-label":o??"Popover",...p,className:d.cx("kakadu-components-3920007758",f==="left"&&"kakadu-components-611400930",f==="right"&&"kakadu-components-944244368",l&&"kakadu-components-1399012551",k),children:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-1118152266",l&&"kakadu-components-231244945"),children:[s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-2899069338",f==="left"&&"kakadu-components-1495725644",f==="right"&&"kakadu-components-4235689197")}),s.jsxRuntimeExports.jsx(_.focusTrapReactExports.FocusTrap,{active:l,focusTrapOptions:A,children:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-3905822111",R),children:[s.jsxRuntimeExports.jsx(z,{value:W,children:u}),s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-3328048824",f==="left"&&"kakadu-components-3754561431",f==="right"&&"kakadu-components-2265262600")})]})})]})})}function G(i,n){const[o,m]=e.useState(!1),r=e.useRef(void 0),u=e.useRef(null),k=e.useCallback(async p=>(m(!0),u.current=p??document.activeElement,new Promise(a=>{r.current=a})),[]),R=e.useCallback(p=>{var a;if(m(!1),(a=r.current)==null||a.call(r,p),r.current=void 0,u.current){const x=u.current;x.isConnected&&x.focus(),u.current=null}},[]),c=e.useMemo(()=>s.jsxRuntimeExports.jsx(i,{...n,isVisible:o,onClose:R}),[i,n,o,R]);return e.useMemo(()=>({isVisible:o,show:k,popover:c}),[o,k,c])}exports.PopoverContainer=$;exports.default=H;exports.usePopover=G;exports.usePopoverContext=B;
@@ -1,114 +1,124 @@
1
1
  import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { cx as l } from "@kuma-ui/core";
3
- import { createContext as M, useRef as k, useState as d, useCallback as j, useMemo as g, useEffect as h, useContext as S } from "react";
4
- import { f as q } from "../focus-trap-react-DYXrtbDH.mjs";
5
- import A, { defaultAtomElementType as D } from "./atom.mjs";
6
- const O = M({
2
+ import { cx as f } from "@kuma-ui/core";
3
+ import { createContext as K, useRef as h, useState as v, useCallback as T, useMemo as P, useEffect as R, useContext as Q } from "react";
4
+ import { f as U } from "../focus-trap-react-DYXrtbDH.mjs";
5
+ import B, { defaultAtomElementType as H } from "./atom.mjs";
6
+ const S = K({
7
7
  isVisible: !1
8
8
  }), {
9
- Provider: G
10
- } = O;
11
- function X() {
12
- return S(O);
9
+ Provider: X
10
+ } = S;
11
+ function ne() {
12
+ return Q(S);
13
13
  }
14
- function Y({
15
- as: c,
14
+ function se({
15
+ as: i,
16
16
  className: t,
17
17
  ...s
18
18
  }) {
19
- return /* @__PURE__ */ n.jsx(A, { as: c ?? D, ...s, className: l("kakadu-components-2845019685", t) });
19
+ return /* @__PURE__ */ n.jsx(B, { as: i ?? H, ...s, className: f("kakadu-components-2845019685", t) });
20
20
  }
21
- function Z({
22
- as: c,
21
+ function oe({
22
+ as: i,
23
23
  isVisible: t,
24
24
  label: s,
25
- shouldCloseOnOutsideClick: f = !0,
25
+ shouldCloseOnOutsideClick: d = !0,
26
26
  shouldCloseOnEscapePress: o = !0,
27
- children: i,
28
- className: v,
27
+ children: a,
28
+ className: w,
29
29
  innerClassName: x,
30
- onClose: a,
30
+ onClose: r,
31
31
  ...m
32
32
  }) {
33
- const r = k(null), p = k(null), [E, y] = d(!1), [u, w] = d(!1), N = j((e) => {
34
- r.current = e, w(!1);
35
- }, []), I = k(null), P = j((e) => {
36
- e && (I.current = e);
37
- }, []), z = g(() => ({
38
- initialFocus: () => I.current ?? void 0,
33
+ const c = h(null), p = h(null), [F, q] = v(!1), [u, g] = v(!1), L = T((e) => {
34
+ c.current = e, g(!1);
35
+ }, []), b = h(null), D = T((e) => {
36
+ e && (b.current = e);
37
+ }, []), G = P(() => ({
38
+ initialFocus: () => b.current ?? void 0,
39
39
  onActivate: () => {
40
40
  var e;
41
- return (e = I.current) == null ? void 0 : e.focus();
41
+ return (e = b.current) == null ? void 0 : e.focus();
42
42
  },
43
- clickOutsideDeactivates: f,
43
+ clickOutsideDeactivates: d,
44
44
  escapeDeactivates: o,
45
45
  onDeactivate() {
46
- w(!1);
46
+ g(!1);
47
47
  }
48
- }), [f, o]), [F, L] = d(t ?? !1), C = g(() => ({
49
- isVisible: F,
50
- setInitialFocus: P,
51
- close: N
52
- }), [F, P, N]), [R, W] = d(!1), [T, B] = d(!1);
53
- return h(() => {
48
+ }), [d, o]), [O, V] = v(t ?? !1), J = P(() => ({
49
+ isVisible: O,
50
+ setInitialFocus: D,
51
+ close: L
52
+ }), [O, D, L]), [l, A] = v("center");
53
+ return R(() => {
54
54
  const e = p.current;
55
55
  if (e) {
56
- const b = () => {
57
- const V = e.getBoundingClientRect();
58
- W(V.left < 0), B(V.right > window.innerWidth);
56
+ const E = () => {
57
+ const C = e.offsetParent, I = C instanceof HTMLElement ? C.getBoundingClientRect() : null, M = e.getBoundingClientRect();
58
+ if (!I) {
59
+ A("center");
60
+ return;
61
+ }
62
+ const N = I.left + I.width / 2 - M.width / 2, W = N + M.width, y = N < 0, z = W > window.innerWidth;
63
+ let k = "center";
64
+ if (y && z) {
65
+ const j = Math.abs(N);
66
+ k = W - window.innerWidth > j ? "right" : "left";
67
+ } else z ? k = "right" : y && (k = "left");
68
+ A((j) => j === k ? j : k);
59
69
  };
60
- return b(), window.addEventListener("resize", b), () => {
61
- window.removeEventListener("resize", b);
70
+ return E(), window.addEventListener("resize", E), () => {
71
+ window.removeEventListener("resize", E);
62
72
  };
63
73
  }
64
- }, []), h(() => {
65
- t && (y(!0), L(!0));
66
- }, [t]), h(() => {
74
+ }, []), R(() => {
75
+ t && (q(!0), V(!0));
76
+ }, [t]), R(() => {
67
77
  if (t) {
68
78
  const e = setTimeout(() => {
69
- w(!0);
79
+ g(!0);
70
80
  }, 100);
71
81
  return () => {
72
82
  clearTimeout(e);
73
83
  };
74
84
  }
75
- w(!1);
76
- }, [t]), h(() => {
77
- if (E && !u) {
85
+ g(!1);
86
+ }, [t]), R(() => {
87
+ if (F && !u) {
78
88
  const e = setTimeout(() => {
79
- a == null || a(r.current ?? void 0), L(!1);
89
+ r == null || r(c.current ?? void 0), V(!1);
80
90
  }, 370);
81
91
  return () => {
82
92
  clearTimeout(e);
83
93
  };
84
94
  }
85
- }, [E, u, a]), /* @__PURE__ */ n.jsx(A, { reference: p, as: c ?? D, role: "dialog", "aria-hidden": !u, "aria-label": s ?? "Popover", ...m, className: l("kakadu-components-3920007758", R && "kakadu-components-611400930", T && "kakadu-components-944244368", u && "kakadu-components-1399012551", v), children: /* @__PURE__ */ n.jsxs("div", { className: l("kakadu-components-1118152266", u && "kakadu-components-231244945"), children: [
86
- /* @__PURE__ */ n.jsx("div", { className: l("kakadu-components-2899069338", R && "kakadu-components-1495725644", T && "kakadu-components-4235689197") }),
87
- /* @__PURE__ */ n.jsx(q.FocusTrap, { active: u, focusTrapOptions: z, children: /* @__PURE__ */ n.jsxs("div", { className: l("kakadu-components-3905822111", x), children: [
88
- /* @__PURE__ */ n.jsx(G, { value: C, children: i }),
89
- /* @__PURE__ */ n.jsx("div", { className: l("kakadu-components-3328048824", R && "kakadu-components-3754561431", T && "kakadu-components-2265262600") })
95
+ }, [F, u, r]), /* @__PURE__ */ n.jsx(B, { reference: p, as: i ?? H, role: "dialog", "aria-hidden": !u, "aria-label": s ?? "Popover", ...m, className: f("kakadu-components-3920007758", l === "left" && "kakadu-components-611400930", l === "right" && "kakadu-components-944244368", u && "kakadu-components-1399012551", w), children: /* @__PURE__ */ n.jsxs("div", { className: f("kakadu-components-1118152266", u && "kakadu-components-231244945"), children: [
96
+ /* @__PURE__ */ n.jsx("div", { className: f("kakadu-components-2899069338", l === "left" && "kakadu-components-1495725644", l === "right" && "kakadu-components-4235689197") }),
97
+ /* @__PURE__ */ n.jsx(U.FocusTrap, { active: u, focusTrapOptions: G, children: /* @__PURE__ */ n.jsxs("div", { className: f("kakadu-components-3905822111", x), children: [
98
+ /* @__PURE__ */ n.jsx(X, { value: J, children: a }),
99
+ /* @__PURE__ */ n.jsx("div", { className: f("kakadu-components-3328048824", l === "left" && "kakadu-components-3754561431", l === "right" && "kakadu-components-2265262600") })
90
100
  ] }) })
91
101
  ] }) });
92
102
  }
93
- function _(c, t) {
94
- const [s, f] = d(!1), o = k(void 0), i = k(null), v = j(async (m) => (f(!0), i.current = m ?? document.activeElement, new Promise((r) => {
95
- o.current = r;
96
- })), []), x = j((m) => {
97
- var r;
98
- if (f(!1), (r = o.current) == null || r.call(o, m), o.current = void 0, i.current) {
99
- const p = i.current;
100
- p.isConnected && p.focus(), i.current = null;
103
+ function re(i, t) {
104
+ const [s, d] = v(!1), o = h(void 0), a = h(null), w = T(async (m) => (d(!0), a.current = m ?? document.activeElement, new Promise((c) => {
105
+ o.current = c;
106
+ })), []), x = T((m) => {
107
+ var c;
108
+ if (d(!1), (c = o.current) == null || c.call(o, m), o.current = void 0, a.current) {
109
+ const p = a.current;
110
+ p.isConnected && p.focus(), a.current = null;
101
111
  }
102
- }, []), a = g(() => /* @__PURE__ */ n.jsx(c, { ...t, isVisible: s, onClose: x }), [c, t, s, x]);
103
- return g(() => ({
112
+ }, []), r = P(() => /* @__PURE__ */ n.jsx(i, { ...t, isVisible: s, onClose: x }), [i, t, s, x]);
113
+ return P(() => ({
104
114
  isVisible: s,
105
- show: v,
106
- popover: a
107
- }), [s, v, a]);
115
+ show: w,
116
+ popover: r
117
+ }), [s, w, r]);
108
118
  }
109
119
  export {
110
- Y as PopoverContainer,
111
- Z as default,
112
- _ as usePopover,
113
- X as usePopoverContext
120
+ se as PopoverContainer,
121
+ oe as default,
122
+ re as usePopover,
123
+ ne as usePopoverContext
114
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",