@kakadu/components 3.2.2 → 3.2.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.
@@ -3,6 +3,7 @@ import { type DecoratorType } from './decorators';
3
3
  type InitialFocusElement = HTMLElement | null;
4
4
  type ModalProviderProperties<Data = any> = {
5
5
  isVisible: boolean;
6
+ isInteractive: boolean;
6
7
  setInitialFocus?: (initialFocus?: InitialFocusElement) => void;
7
8
  close?: (data?: Data) => void;
8
9
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),v=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),A=require("./text-button.js"),C=require("./decorators.js"),I=e.createContext({isVisible:!1}),{Provider:D}=I;function y(){return e.useContext(I)}function z(){const{close:o}=y(),c=e.useCallback(()=>{o==null||o()},[o]);return n.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:n.jsxRuntimeExports.jsx(A.default,{iconLeft:B.IconType.times,label:"Close",onClick:c})})}function G({root:o,outerDecorators:c=[],innerDecorators:u=[],label:x,maxWidth:r,className:m,isVisible:s,isFullWidth:l=!1,shouldCloseOnOutsideClick:a=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:L=!0,onClose:k,children:S}){const E=e.useRef(null),R=e.useRef(null),[M,g]=e.useState(!1),[i,f]=e.useState(!1),h=e.useCallback(t=>{E.current=t,f(!1)},[]),j=e.useRef(null),b=e.useCallback(t=>{t&&(j.current=t)},[]),[w,T]=e.useState(s??!1),N=e.useMemo(()=>({isVisible:w,setInitialFocus:b,close:h}),[w,b,h]);e.useEffect(()=>{s&&(g(!0),T(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{f(!0)},100);return()=>{clearTimeout(t)}}f(!1)},[s]),e.useEffect(()=>{if(M&&!i){const t=setTimeout(()=>{k==null||k(E.current??void 0),T(!1)},370);return()=>{clearTimeout(t)}}},[M,i,k]),e.useEffect(()=>{const t=R.current;if(s&&a&&t){const p=F=>{t===F.target&&f(!1)};return t.addEventListener("click",p),()=>{t.removeEventListener("click",p)}}},[s,a]),e.useEffect(()=>{if(!s||!d)return;const t=p=>{p.key==="Escape"&&f(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[s,d]);const _=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate:()=>{var t;return(t=j.current)==null?void 0:t.focus()}}),[]),q=n.jsxRuntimeExports.jsx(C.default,{decorators:c,children:n.jsxRuntimeExports.jsx("div",{"aria-hidden":!i,style:{"--max-width":r?`${r}px`:void 0},className:v.cx("kakadu-components-4119461136",i&&"kakadu-components-2522346797",m),children:n.jsxRuntimeExports.jsx(C.default,{decorators:u,children:n.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:i,focusTrapOptions:_,children:n.jsxRuntimeExports.jsx("div",{ref:R,className:"kakadu-components-4011815997",children:n.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":x??"Modal",className:v.cx("kakadu-components-3324483532",l&&"kakadu-components-3799971070",i&&"kakadu-components-968755580"),children:n.jsxRuntimeExports.jsxs(D,{value:N,children:[L?n.jsxRuntimeExports.jsx(z,{}):null,n.jsxRuntimeExports.jsx("div",{className:v.cx("kakadu-components-633990035",l&&"kakadu-components-171969824"),children:S})]})})})})})})});return o?P.createPortal(q,o):q}function H(o,c){const[u,x]=e.useState(!1),r=e.useRef(void 0),m=e.useCallback(async()=>(x(!0),new Promise(a=>{r.current=a})),[]),s=e.useCallback(a=>{var d;x(!1),(d=r.current)==null||d.call(r,a),r.current=void 0},[]),l=e.useMemo(()=>n.jsxRuntimeExports.jsx(o,{...c,isVisible:u,onClose:s}),[o,c,u,s]);return e.useMemo(()=>({isVisible:u,show:m,modal:l}),[u,m,l])}exports.default=G;exports.useModal=H;exports.useModalContext=y;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),v=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),A=require("./text-button.js"),q=require("./decorators.js"),C=e.createContext({isVisible:!1,isInteractive:!1}),{Provider:D}=C;function y(){return e.useContext(C)}function z(){const{isInteractive:u,close:o}=y(),r=e.useCallback(()=>{o==null||o()},[o]);return n.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:n.jsxRuntimeExports.jsx(A.default,{iconLeft:B.IconType.times,label:"Close",disabled:!u,onClick:r})})}function G({root:u,outerDecorators:o=[],innerDecorators:r=[],label:x,maxWidth:c,className:m,isVisible:s,isFullWidth:l=!1,shouldCloseOnOutsideClick:i=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:L=!0,onClose:k,children:S}){const E=e.useRef(null),R=e.useRef(null),[M,g]=e.useState(!1),[a,f]=e.useState(!1),b=e.useCallback(t=>{E.current=t,f(!1)},[]),j=e.useRef(null),h=e.useCallback(t=>{t&&(j.current=t)},[]),[I,w]=e.useState(s??!1),N=e.useMemo(()=>({isVisible:I,isInteractive:a,setInitialFocus:h,close:b}),[I,a,h,b]);e.useEffect(()=>{s&&(g(!0),w(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{f(!0)},100);return()=>{clearTimeout(t)}}f(!1)},[s]),e.useEffect(()=>{if(M&&!a){const t=setTimeout(()=>{k==null||k(E.current??void 0),w(!1)},370);return()=>{clearTimeout(t)}}},[M,a,k]),e.useEffect(()=>{const t=R.current;if(s&&i&&t){const p=F=>{t===F.target&&f(!1)};return t.addEventListener("click",p),()=>{t.removeEventListener("click",p)}}},[s,i]),e.useEffect(()=>{if(!s||!d)return;const t=p=>{p.key==="Escape"&&f(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[s,d]);const _=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate:()=>{var t;return(t=j.current)==null?void 0:t.focus()}}),[]),T=n.jsxRuntimeExports.jsx(q.default,{decorators:o,children:n.jsxRuntimeExports.jsx("div",{"aria-hidden":!a,style:{"--max-width":c?`${c}px`:void 0},className:v.cx("kakadu-components-4119461136",a&&"kakadu-components-2522346797",m),children:n.jsxRuntimeExports.jsx(q.default,{decorators:r,children:n.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:a,focusTrapOptions:_,children:n.jsxRuntimeExports.jsx("div",{ref:R,className:"kakadu-components-4011815997",children:n.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":x??"Modal",className:v.cx("kakadu-components-3324483532",l&&"kakadu-components-3799971070",a&&"kakadu-components-968755580"),children:n.jsxRuntimeExports.jsxs(D,{value:N,children:[L?n.jsxRuntimeExports.jsx(z,{}):null,n.jsxRuntimeExports.jsx("div",{className:v.cx("kakadu-components-633990035",l&&"kakadu-components-171969824"),children:S})]})})})})})})});return u?P.createPortal(T,u):T}function H(u,o){const[r,x]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(x(!0),new Promise(i=>{c.current=i})),[]),s=e.useCallback(i=>{var d;x(!1),(d=c.current)==null||d.call(c,i),c.current=void 0},[]),l=e.useMemo(()=>n.jsxRuntimeExports.jsx(u,{...o,isVisible:r,onClose:s}),[u,o,r,s]);return e.useMemo(()=>({isVisible:r,show:m,modal:l}),[r,m,l])}exports.default=G;exports.useModal=H;exports.useModalContext=y;
@@ -1,13 +1,14 @@
1
1
  import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { createContext as q, useRef as j, useState as h, useCallback as m, useMemo as w, useEffect as f, useContext as z } from "react";
3
- import { cx as I } from "@kuma-ui/core";
2
+ import { createContext as q, useRef as j, useState as h, useCallback as m, useMemo as I, useEffect as f, useContext as z } from "react";
3
+ import { cx as T } from "@kuma-ui/core";
4
4
  import { createPortal as G } from "react-dom";
5
5
  import { f as H } from "../focus-trap-react-DYXrtbDH.mjs";
6
6
  import { IconType as J } from "../icons/icon.mjs";
7
7
  import K from "./text-button.mjs";
8
8
  import g from "./decorators.mjs";
9
9
  const C = q({
10
- isVisible: !1
10
+ isVisible: !1,
11
+ isInteractive: !1
11
12
  }), {
12
13
  Provider: Q
13
14
  } = C;
@@ -16,38 +17,40 @@ function U() {
16
17
  }
17
18
  function V() {
18
19
  const {
19
- close: o
20
- } = U(), r = m(() => {
21
- o == null || o();
22
- }, [o]);
23
- return /* @__PURE__ */ n.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ n.jsx(K, { iconLeft: J.times, label: "Close", onClick: r }) });
20
+ isInteractive: c,
21
+ close: s
22
+ } = U(), o = m(() => {
23
+ s == null || s();
24
+ }, [s]);
25
+ return /* @__PURE__ */ n.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ n.jsx(K, { iconLeft: J.times, label: "Close", disabled: !c, onClick: o }) });
24
26
  }
25
27
  function ne({
26
- root: o,
27
- outerDecorators: r = [],
28
- innerDecorators: a = [],
28
+ root: c,
29
+ outerDecorators: s = [],
30
+ innerDecorators: o = [],
29
31
  label: k,
30
- maxWidth: s,
32
+ maxWidth: r,
31
33
  className: x,
32
34
  isVisible: t,
33
35
  isFullWidth: u = !1,
34
- shouldCloseOnOutsideClick: c = !0,
36
+ shouldCloseOnOutsideClick: i = !0,
35
37
  shouldCloseOnEscapePress: l = !0,
36
38
  showCloseButton: B = !0,
37
39
  onClose: p,
38
40
  children: P
39
41
  }) {
40
- const E = j(null), y = j(null), [L, A] = h(!1), [i, d] = h(!1), M = m((e) => {
42
+ const E = j(null), y = j(null), [L, A] = h(!1), [a, d] = h(!1), M = m((e) => {
41
43
  E.current = e, d(!1);
42
- }, []), T = j(null), R = m((e) => {
43
- e && (T.current = e);
44
- }, []), [N, b] = h(t ?? !1), D = w(() => ({
45
- isVisible: N,
44
+ }, []), w = j(null), R = m((e) => {
45
+ e && (w.current = e);
46
+ }, []), [b, N] = h(t ?? !1), D = I(() => ({
47
+ isVisible: b,
48
+ isInteractive: a,
46
49
  setInitialFocus: R,
47
50
  close: M
48
- }), [N, R, M]);
51
+ }), [b, a, R, M]);
49
52
  f(() => {
50
- t && (A(!0), b(!0));
53
+ t && (A(!0), N(!0));
51
54
  }, [t]), f(() => {
52
55
  if (t) {
53
56
  const e = setTimeout(() => {
@@ -59,17 +62,17 @@ function ne({
59
62
  }
60
63
  d(!1);
61
64
  }, [t]), f(() => {
62
- if (L && !i) {
65
+ if (L && !a) {
63
66
  const e = setTimeout(() => {
64
- p == null || p(E.current ?? void 0), b(!1);
67
+ p == null || p(E.current ?? void 0), N(!1);
65
68
  }, 370);
66
69
  return () => {
67
70
  clearTimeout(e);
68
71
  };
69
72
  }
70
- }, [L, i, p]), f(() => {
73
+ }, [L, a, p]), f(() => {
71
74
  const e = y.current;
72
- if (t && c && e) {
75
+ if (t && i && e) {
73
76
  const v = ($) => {
74
77
  e === $.target && d(!1);
75
78
  };
@@ -77,7 +80,7 @@ function ne({
77
80
  e.removeEventListener("click", v);
78
81
  };
79
82
  }
80
- }, [t, c]), f(() => {
83
+ }, [t, i]), f(() => {
81
84
  if (!t || !l)
82
85
  return;
83
86
  const e = (v) => {
@@ -87,35 +90,35 @@ function ne({
87
90
  window.removeEventListener("keydown", e);
88
91
  };
89
92
  }, [t, l]);
90
- const S = w(() => ({
91
- initialFocus: () => T.current ?? void 0,
93
+ const S = I(() => ({
94
+ initialFocus: () => w.current ?? void 0,
92
95
  onActivate: () => {
93
96
  var e;
94
- return (e = T.current) == null ? void 0 : e.focus();
97
+ return (e = w.current) == null ? void 0 : e.focus();
95
98
  }
96
- }), []), F = /* @__PURE__ */ n.jsx(g, { decorators: r, children: /* @__PURE__ */ n.jsx("div", { "aria-hidden": !i, style: {
97
- "--max-width": s ? `${s}px` : void 0
98
- }, className: I("kakadu-components-4119461136", i && "kakadu-components-2522346797", x), children: /* @__PURE__ */ n.jsx(g, { decorators: a, children: /* @__PURE__ */ n.jsx(H.FocusTrap, { active: i, focusTrapOptions: S, children: /* @__PURE__ */ n.jsx("div", { ref: y, className: "kakadu-components-4011815997", children: /* @__PURE__ */ n.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": k ?? "Modal", className: I("kakadu-components-3324483532", u && "kakadu-components-3799971070", i && "kakadu-components-968755580"), children: /* @__PURE__ */ n.jsxs(Q, { value: D, children: [
99
+ }), []), F = /* @__PURE__ */ n.jsx(g, { decorators: s, children: /* @__PURE__ */ n.jsx("div", { "aria-hidden": !a, style: {
100
+ "--max-width": r ? `${r}px` : void 0
101
+ }, className: T("kakadu-components-4119461136", a && "kakadu-components-2522346797", x), children: /* @__PURE__ */ n.jsx(g, { decorators: o, children: /* @__PURE__ */ n.jsx(H.FocusTrap, { active: a, focusTrapOptions: S, children: /* @__PURE__ */ n.jsx("div", { ref: y, className: "kakadu-components-4011815997", children: /* @__PURE__ */ n.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": k ?? "Modal", className: T("kakadu-components-3324483532", u && "kakadu-components-3799971070", a && "kakadu-components-968755580"), children: /* @__PURE__ */ n.jsxs(Q, { value: D, children: [
99
102
  B ? /* @__PURE__ */ n.jsx(V, {}) : null,
100
- /* @__PURE__ */ n.jsx("div", { className: I("kakadu-components-633990035", u && "kakadu-components-171969824"), children: P })
103
+ /* @__PURE__ */ n.jsx("div", { className: T("kakadu-components-633990035", u && "kakadu-components-171969824"), children: P })
101
104
  ] }) }) }) }) }) }) });
102
- return o ? G(F, o) : F;
105
+ return c ? G(F, c) : F;
103
106
  }
104
- function oe(o, r) {
105
- const [a, k] = h(!1), s = j(void 0), x = m(async () => (k(!0), new Promise((c) => {
106
- s.current = c;
107
- })), []), t = m((c) => {
107
+ function se(c, s) {
108
+ const [o, k] = h(!1), r = j(void 0), x = m(async () => (k(!0), new Promise((i) => {
109
+ r.current = i;
110
+ })), []), t = m((i) => {
108
111
  var l;
109
- k(!1), (l = s.current) == null || l.call(s, c), s.current = void 0;
110
- }, []), u = w(() => /* @__PURE__ */ n.jsx(o, { ...r, isVisible: a, onClose: t }), [o, r, a, t]);
111
- return w(() => ({
112
- isVisible: a,
112
+ k(!1), (l = r.current) == null || l.call(r, i), r.current = void 0;
113
+ }, []), u = I(() => /* @__PURE__ */ n.jsx(c, { ...s, isVisible: o, onClose: t }), [c, s, o, t]);
114
+ return I(() => ({
115
+ isVisible: o,
113
116
  show: x,
114
117
  modal: u
115
- }), [a, x, u]);
118
+ }), [o, x, u]);
116
119
  }
117
120
  export {
118
121
  ne as default,
119
- oe as useModal,
122
+ se as useModal,
120
123
  U as useModalContext
121
124
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),M=require("@kuma-ui/core"),a=require("react"),b=require("../theme.js"),k=require("../icons/icon.js"),j=require("./popover.js"),q=require("./atom.js"),g=require("./text.js"),R=require("./hover-gradient.js"),P=require("./click-ripples.js"),I=require("./separator.js"),N=require("./decorators.js"),E=new Set;function h(){const[e,n]=a.useState(!1),r=a.useCallback(s=>{n(s);for(const i of E)i(s)},[]);return a.useEffect(()=>{const s=i=>{n(i)};return E.add(s),()=>{E.delete(s)}},[]),a.useMemo(()=>({isKeyboardNavigating:e,setIsKeyboardNavigating:r}),[e,r])}function S({label:e,iconLeft:n,iconRight:r,href:s,shouldCloseOnClick:i=!0,decorators:v=[],submenu:x,className:u,onClick:o,...m}){const{isFocused:l,close:c}=j.usePopoverContext(),{isKeyboardNavigating:f}=h(),d=a.useCallback(w=>{l&&(o==null||o(w),x?x.show():i&&(c==null||c()))},[l,o,i,c,x]),p=a.useMemo(()=>t.jsxRuntimeExports.jsxs(q.default,{as:s?"a":"button",...m,type:s?void 0:"button",role:"menuitem",href:s,className:M.cx(b.buttonResetStyles,"kakadu-components-3114599304",f?"kakadu-components-4096376656":"kakadu-components-2554182777",u),onClick:d,children:[t.jsxRuntimeExports.jsxs(g.Span,{className:"kakadu-components-1109353535",children:[n?t.jsxRuntimeExports.jsx(k.default,{width:12,height:12,type:n}):null,t.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:e}),r?t.jsxRuntimeExports.jsx(k.default,{width:12,height:12,type:r}):null]}),f?null:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(R.default,{size:150,className:R.normalBlendStyles}),t.jsxRuntimeExports.jsx(P.default,{size:100})]})]}),[f,m,s,u,d,n,e,r]);return t.jsxRuntimeExports.jsx(N.default,{decorators:v,children:x?t.jsxRuntimeExports.jsx(y,{menu:x.popoverMenu,className:"kakadu-components-1861176543",children:p}):p})}function _(e){if("type"in e){if(e.type==="separator")return t.jsxRuntimeExports.jsx(I.default,{});if(e.type==="group")return t.jsxRuntimeExports.jsx(g.Span,{className:"kakadu-components-1499037363",children:e.label})}return t.jsxRuntimeExports.jsx(S,{...e})}function K({items:e}){const{isFocused:n}=j.usePopoverContext(),[r,s]=a.useState([]),{setIsKeyboardNavigating:i}=h(),v=a.useCallback(u=>{u&&s(o=>o.includes(u)?o:[...o,u])},[]),x=a.useCallback(u=>{n&&(u.currentTarget.focus(),i(!1))},[n,i]);return a.useEffect(()=>{if(!n)return;const u=o=>{const m=r.filter(p=>p.isConnected),l=m.length;if(l===0)return;let c;const f=document.activeElement;let d=f?m.indexOf(f):-1;switch(d===-1&&(d=0),o.key){case"ArrowDown":{c=(d+1)%l;break}case"ArrowUp":{c=(d-1+l)%l;break}case"Home":{c=0;break}case"End":{c=l-1;break}}if(c!==void 0){o.preventDefault(),o.stopPropagation();const p=m[c];p&&(p.focus(),i(!0))}};return window.addEventListener("keydown",u,{capture:!0}),()=>{window.removeEventListener("keydown",u,{capture:!0})}},[n,r,i]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:e.map((u,o)=>t.jsxRuntimeExports.jsx(_,{...u,reference:v,onMouseEnter:x},o))})}function C({items:e,...n}){return t.jsxRuntimeExports.jsx(j.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:t.jsxRuntimeExports.jsx(K,{items:e})})}function F(e){const n=a.useMemo(()=>({items:e}),[e]),{show:r,popover:s}=j.usePopover(C,n);return a.useMemo(()=>({show:r,popoverMenu:s}),[r,s])}function y({menu:e,className:n,children:r}){return t.jsxRuntimeExports.jsxs(j.PopoverContainer,{className:n,children:[r,e]})}exports.default=y;exports.usePopoverMenu=F;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),M=require("@kuma-ui/core"),a=require("react"),q=require("../theme.js"),R=require("../icons/icon.js"),f=require("./popover.js"),P=require("./atom.js"),h=require("./text.js"),g=require("./hover-gradient.js"),I=require("./click-ripples.js"),N=require("./separator.js"),S=require("./decorators.js"),E=new Set;function y(){const[e,n]=a.useState(!1),r=a.useCallback(s=>{n(s);for(const i of E)i(s)},[]);return a.useEffect(()=>{const s=i=>{n(i)};return E.add(s),()=>{E.delete(s)}},[]),a.useMemo(()=>({isKeyboardNavigating:e,setIsKeyboardNavigating:r}),[e,r])}function _({label:e,iconLeft:n,iconRight:r,href:s,shouldCloseOnClick:i=!0,decorators:v=[],submenu:x,className:u,onClick:o,...j}){const{isVisible:l,isFocused:c,close:p}=f.usePopoverContext(),{isKeyboardNavigating:d}=y(),m=a.useCallback(w=>{c&&(o==null||o(w),x?x.show():i&&(p==null||p()))},[c,o,x,i,p]),k=a.useMemo(()=>t.jsxRuntimeExports.jsxs(P.default,{as:s?"a":"button",...j,type:s?void 0:"button",role:"menuitem",href:s,disabled:s?void 0:!l,className:M.cx(q.buttonResetStyles,"kakadu-components-3114599304",d?"kakadu-components-4096376656":"kakadu-components-2554182777",u),onClick:m,children:[t.jsxRuntimeExports.jsxs(h.Span,{className:"kakadu-components-1109353535",children:[n?t.jsxRuntimeExports.jsx(R.default,{width:12,height:12,type:n}):null,t.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:e}),r?t.jsxRuntimeExports.jsx(R.default,{width:12,height:12,type:r}):null]}),d?null:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(g.default,{size:150,className:g.normalBlendStyles}),t.jsxRuntimeExports.jsx(I.default,{size:100})]})]}),[s,j,l,d,u,m,n,e,r]);return t.jsxRuntimeExports.jsx(S.default,{decorators:v,children:x?t.jsxRuntimeExports.jsx(b,{menu:x.popoverMenu,className:"kakadu-components-1861176543",children:k}):k})}function K(e){if("type"in e){if(e.type==="separator")return t.jsxRuntimeExports.jsx(N.default,{});if(e.type==="group")return t.jsxRuntimeExports.jsx(h.Span,{className:"kakadu-components-1499037363",children:e.label})}return t.jsxRuntimeExports.jsx(_,{...e})}function C({items:e}){const{isFocused:n}=f.usePopoverContext(),[r,s]=a.useState([]),{setIsKeyboardNavigating:i}=y(),v=a.useCallback(u=>{u&&s(o=>o.includes(u)?o:[...o,u])},[]),x=a.useCallback(u=>{n&&(u.currentTarget.focus(),i(!1))},[n,i]);return a.useEffect(()=>{if(!n)return;const u=o=>{const j=r.filter(m=>m.isConnected),l=j.length;if(l===0)return;let c;const p=document.activeElement;let d=p?j.indexOf(p):-1;switch(d===-1&&(d=0),o.key){case"ArrowDown":{c=(d+1)%l;break}case"ArrowUp":{c=(d-1+l)%l;break}case"Home":{c=0;break}case"End":{c=l-1;break}}if(c!==void 0){o.preventDefault(),o.stopPropagation();const m=j[c];m&&(m.focus(),i(!0))}};return window.addEventListener("keydown",u,{capture:!0}),()=>{window.removeEventListener("keydown",u,{capture:!0})}},[n,r,i]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:e.map((u,o)=>t.jsxRuntimeExports.jsx(K,{...u,reference:v,onMouseEnter:x},o))})}function F({items:e,...n}){return t.jsxRuntimeExports.jsx(f.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:t.jsxRuntimeExports.jsx(C,{items:e})})}function z(e){const n=a.useMemo(()=>({items:e}),[e]),{show:r,popover:s}=f.usePopover(F,n);return a.useMemo(()=>({show:r,popoverMenu:s}),[r,s])}function b({menu:e,className:n,children:r}){return t.jsxRuntimeExports.jsxs(f.PopoverContainer,{className:n,children:[r,e]})}exports.default=b;exports.usePopoverMenu=z;
@@ -1,23 +1,23 @@
1
1
  import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { cx as b } from "@kuma-ui/core";
3
- import { useMemo as v, useState as h, useCallback as x, useEffect as y } from "react";
4
- import { buttonResetStyles as M } from "../theme.mjs";
5
- import g from "../icons/icon.mjs";
6
- import E, { PopoverContainer as S, usePopover as K, usePopoverContext as w } from "./popover.mjs";
7
- import F from "./atom.mjs";
8
- import { Span as I } from "./text.mjs";
9
- import A, { normalBlendStyles as D } from "./hover-gradient.mjs";
10
- import H from "./click-ripples.mjs";
11
- import z from "./separator.mjs";
12
- import C from "./decorators.mjs";
2
+ import { cx as M } from "@kuma-ui/core";
3
+ import { useMemo as v, useState as y, useCallback as x, useEffect as w } from "react";
4
+ import { buttonResetStyles as E } from "../theme.mjs";
5
+ import h from "../icons/icon.mjs";
6
+ import S, { PopoverContainer as K, usePopover as F, usePopoverContext as I } from "./popover.mjs";
7
+ import A from "./atom.mjs";
8
+ import { Span as b } from "./text.mjs";
9
+ import D, { normalBlendStyles as H } from "./hover-gradient.mjs";
10
+ import z from "./click-ripples.mjs";
11
+ import C from "./separator.mjs";
12
+ import L from "./decorators.mjs";
13
13
  const j = /* @__PURE__ */ new Set();
14
14
  function N() {
15
- const [e, t] = h(!1), s = x((o) => {
15
+ const [e, t] = y(!1), s = x((o) => {
16
16
  t(o);
17
17
  for (const i of j)
18
18
  i(o);
19
19
  }, []);
20
- return y(() => {
20
+ return w(() => {
21
21
  const o = (i) => {
22
22
  t(i);
23
23
  };
@@ -29,76 +29,77 @@ function N() {
29
29
  setIsKeyboardNavigating: s
30
30
  }), [e, s]);
31
31
  }
32
- function L({
32
+ function R({
33
33
  label: e,
34
34
  iconLeft: t,
35
35
  iconRight: s,
36
36
  href: o,
37
37
  shouldCloseOnClick: i = !0,
38
38
  decorators: k = [],
39
- submenu: d,
39
+ submenu: m,
40
40
  className: a,
41
41
  onClick: r,
42
- ...p
42
+ ...f
43
43
  }) {
44
44
  const {
45
- isFocused: u,
46
- close: c
47
- } = w(), {
48
- isKeyboardNavigating: f
49
- } = N(), m = x((P) => {
50
- u && (r == null || r(P), d ? d.show() : i && (c == null || c()));
51
- }, [u, r, i, c, d]), l = v(() => /* @__PURE__ */ n.jsxs(F, { as: o ? "a" : "button", ...p, type: o ? void 0 : "button", role: "menuitem", href: o, className: b(M, "kakadu-components-3114599304", f ? "kakadu-components-4096376656" : "kakadu-components-2554182777", a), onClick: m, children: [
52
- /* @__PURE__ */ n.jsxs(I, { className: "kakadu-components-1109353535", children: [
53
- t ? /* @__PURE__ */ n.jsx(g, { width: 12, height: 12, type: t }) : null,
45
+ isVisible: u,
46
+ isFocused: c,
47
+ close: l
48
+ } = I(), {
49
+ isKeyboardNavigating: d
50
+ } = N(), p = x((P) => {
51
+ c && (r == null || r(P), m ? m.show() : i && (l == null || l()));
52
+ }, [c, r, m, i, l]), g = v(() => /* @__PURE__ */ n.jsxs(A, { as: o ? "a" : "button", ...f, type: o ? void 0 : "button", role: "menuitem", href: o, disabled: o ? void 0 : !u, className: M(E, "kakadu-components-3114599304", d ? "kakadu-components-4096376656" : "kakadu-components-2554182777", a), onClick: p, children: [
53
+ /* @__PURE__ */ n.jsxs(b, { className: "kakadu-components-1109353535", children: [
54
+ t ? /* @__PURE__ */ n.jsx(h, { width: 12, height: 12, type: t }) : null,
54
55
  /* @__PURE__ */ n.jsx("span", { className: "kakadu-components-913703148", children: e }),
55
- s ? /* @__PURE__ */ n.jsx(g, { width: 12, height: 12, type: s }) : null
56
+ s ? /* @__PURE__ */ n.jsx(h, { width: 12, height: 12, type: s }) : null
56
57
  ] }),
57
- f ? null : /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
58
- /* @__PURE__ */ n.jsx(A, { size: 150, className: D }),
59
- /* @__PURE__ */ n.jsx(H, { size: 100 })
58
+ d ? null : /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
59
+ /* @__PURE__ */ n.jsx(D, { size: 150, className: H }),
60
+ /* @__PURE__ */ n.jsx(z, { size: 100 })
60
61
  ] })
61
- ] }), [f, p, o, a, m, t, e, s]);
62
- return /* @__PURE__ */ n.jsx(C, { decorators: k, children: d ? /* @__PURE__ */ n.jsx(T, { menu: d.popoverMenu, className: "kakadu-components-1861176543", children: l }) : l });
62
+ ] }), [o, f, u, d, a, p, t, e, s]);
63
+ return /* @__PURE__ */ n.jsx(L, { decorators: k, children: m ? /* @__PURE__ */ n.jsx(U, { menu: m.popoverMenu, className: "kakadu-components-1861176543", children: g }) : g });
63
64
  }
64
- function R(e) {
65
+ function B(e) {
65
66
  if ("type" in e) {
66
67
  if (e.type === "separator")
67
- return /* @__PURE__ */ n.jsx(z, {});
68
+ return /* @__PURE__ */ n.jsx(C, {});
68
69
  if (e.type === "group")
69
- return /* @__PURE__ */ n.jsx(I, { className: "kakadu-components-1499037363", children: e.label });
70
+ return /* @__PURE__ */ n.jsx(b, { className: "kakadu-components-1499037363", children: e.label });
70
71
  }
71
- return /* @__PURE__ */ n.jsx(L, { ...e });
72
+ return /* @__PURE__ */ n.jsx(R, { ...e });
72
73
  }
73
- function B({
74
+ function G({
74
75
  items: e
75
76
  }) {
76
77
  const {
77
78
  isFocused: t
78
- } = w(), [s, o] = h([]), {
79
+ } = I(), [s, o] = y([]), {
79
80
  setIsKeyboardNavigating: i
80
81
  } = N(), k = x((a) => {
81
82
  a && o((r) => r.includes(a) ? r : [...r, a]);
82
- }, []), d = x((a) => {
83
+ }, []), m = x((a) => {
83
84
  t && (a.currentTarget.focus(), i(!1));
84
85
  }, [t, i]);
85
- return y(() => {
86
+ return w(() => {
86
87
  if (!t)
87
88
  return;
88
89
  const a = (r) => {
89
- const p = s.filter((l) => l.isConnected), u = p.length;
90
+ const f = s.filter((p) => p.isConnected), u = f.length;
90
91
  if (u === 0)
91
92
  return;
92
93
  let c;
93
- const f = document.activeElement;
94
- let m = f ? p.indexOf(f) : -1;
95
- switch (m === -1 && (m = 0), r.key) {
94
+ const l = document.activeElement;
95
+ let d = l ? f.indexOf(l) : -1;
96
+ switch (d === -1 && (d = 0), r.key) {
96
97
  case "ArrowDown": {
97
- c = (m + 1) % u;
98
+ c = (d + 1) % u;
98
99
  break;
99
100
  }
100
101
  case "ArrowUp": {
101
- c = (m - 1 + u) % u;
102
+ c = (d - 1 + u) % u;
102
103
  break;
103
104
  }
104
105
  case "Home": {
@@ -112,8 +113,8 @@ function B({
112
113
  }
113
114
  if (c !== void 0) {
114
115
  r.preventDefault(), r.stopPropagation();
115
- const l = p[c];
116
- l && (l.focus(), i(!0));
116
+ const p = f[c];
117
+ p && (p.focus(), i(!0));
117
118
  }
118
119
  };
119
120
  return window.addEventListener("keydown", a, {
@@ -124,44 +125,44 @@ function B({
124
125
  });
125
126
  };
126
127
  }, [t, s, i]), /* @__PURE__ */ n.jsx(n.Fragment, { children: e.map((a, r) => /* @__PURE__ */ n.jsx(
127
- R,
128
+ B,
128
129
  {
129
130
  ...a,
130
131
  reference: k,
131
- onMouseEnter: d
132
+ onMouseEnter: m
132
133
  },
133
134
  r
134
135
  )) });
135
136
  }
136
- function G({
137
+ function T({
137
138
  items: e,
138
139
  ...t
139
140
  }) {
140
- return /* @__PURE__ */ n.jsx(E, { ...t, as: "nav", role: "menu", innerClassName: "kakadu-components-3600436535", children: /* @__PURE__ */ n.jsx(B, { items: e }) });
141
+ return /* @__PURE__ */ n.jsx(S, { ...t, as: "nav", role: "menu", innerClassName: "kakadu-components-3600436535", children: /* @__PURE__ */ n.jsx(G, { items: e }) });
141
142
  }
142
- function ee(e) {
143
+ function ne(e) {
143
144
  const t = v(() => ({
144
145
  items: e
145
146
  }), [e]), {
146
147
  show: s,
147
148
  popover: o
148
- } = K(G, t);
149
+ } = F(T, t);
149
150
  return v(() => ({
150
151
  show: s,
151
152
  popoverMenu: o
152
153
  }), [s, o]);
153
154
  }
154
- function T({
155
+ function U({
155
156
  menu: e,
156
157
  className: t,
157
158
  children: s
158
159
  }) {
159
- return /* @__PURE__ */ n.jsxs(S, { className: t, children: [
160
+ return /* @__PURE__ */ n.jsxs(K, { className: t, children: [
160
161
  s,
161
162
  e
162
163
  ] });
163
164
  }
164
165
  export {
165
- T as default,
166
- ee as usePopoverMenu
166
+ U as default,
167
+ ne as usePopoverMenu
167
168
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),l=require("@kuma-ui/core"),e=require("react"),H=require("../focus-trap-react-CcpTuiJi.js"),g=require("./atom.js"),z=e.createContext({isVisible:!1,isFocused:!1}),{Provider:U}=z;function G(){return e.useContext(z)}function J({as:r,className:s,...o}){return n.jsxRuntimeExports.jsx(g.default,{as:r??g.defaultAtomElementType,...o,className:l.cx("kakadu-components-2845019685",s)})}function K({as:r,isVisible:s,label:o,shouldCloseOnOutsideClick:f=!0,shouldCloseOnEscapePress:c=!0,children:m,className:p,innerClassName:x,onClose:a,...v}){const b=e.useRef(null),F=e.useRef(null),[I,k]=e.useState(!1),[S,B]=e.useState(!1),[u,R]=e.useState(!1),C=e.useCallback(t=>{b.current=t,R(!1)},[]),j=e.useRef(null),M=e.useCallback(t=>{t&&(j.current=t)},[]),W=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate(){var t;(t=j.current)==null||t.focus(),k(!0)},clickOutsideDeactivates:f,escapeDeactivates:c,onUnpause(){k(!0)},onPause(){k(!1)},onDeactivate(){R(!1),k(!1)}}),[f,c]),[q,N]=e.useState(s??!1),$=e.useMemo(()=>({isVisible:q,isFocused:I,setInitialFocus:M,close:C}),[q,I,M,C]),[i,L]=e.useState("center");return e.useEffect(()=>{const t=F.current;if(t){const w=()=>{const O=t.offsetParent,E=O instanceof HTMLElement?O.getBoundingClientRect():null,y=t.getBoundingClientRect();if(!E){L("center");return}const P=16,D=window.innerWidth-P,T=E.left+E.width/2-y.width/2,V=T+y.width,A=T<P,_=V>D;let d="center";if(A&&_){const h=P-T;d=V-D>h?"right":"left"}else _?d="right":A&&(d="left");L(h=>h===d?h:d)};return w(),window.addEventListener("resize",w),()=>{window.removeEventListener("resize",w)}}},[]),e.useEffect(()=>{s&&(B(!0),N(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{R(!0)},100);return()=>{clearTimeout(t)}}R(!1)},[s]),e.useEffect(()=>{if(S&&!u){const t=setTimeout(()=>{a==null||a(b.current??void 0),N(!1)},370);return()=>{clearTimeout(t)}}},[S,u,a]),n.jsxRuntimeExports.jsx(g.default,{reference:F,as:r??g.defaultAtomElementType,role:"dialog","aria-hidden":!u,"aria-label":o??"Popover",...v,className:l.cx("kakadu-components-3920007758",i==="left"&&"kakadu-components-611400930",i==="right"&&"kakadu-components-944244368",u&&"kakadu-components-1399012551",p),children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-1118152266",u&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-1951789226",i==="left"&&"kakadu-components-1495725644",i==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(H.focusTrapReactExports.FocusTrap,{active:u,focusTrapOptions:W,children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-2488426662",x),children:[n.jsxRuntimeExports.jsx(U,{value:$,children:m}),n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-3252390100",i==="left"&&"kakadu-components-3754561431",i==="right"&&"kakadu-components-2265262600")})]})})]})})}function Q(r,s){const[o,f]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(f(!0),new Promise(a=>{c.current=a})),[]),p=e.useCallback(a=>{var v;f(!1),(v=c.current)==null||v.call(c,a),c.current=void 0},[]),x=e.useMemo(()=>n.jsxRuntimeExports.jsx(r,{...s,isVisible:o,onClose:p}),[r,s,o,p]);return e.useMemo(()=>({isVisible:o,show:m,popover:x}),[o,m,x])}exports.PopoverContainer=J;exports.default=K;exports.usePopover=Q;exports.usePopoverContext=G;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),l=require("@kuma-ui/core"),e=require("react"),H=require("../focus-trap-react-CcpTuiJi.js"),g=require("./atom.js"),z=e.createContext({isVisible:!1,isFocused:!1}),{Provider:U}=z;function G(){return e.useContext(z)}function J({as:r,className:s,...o}){return n.jsxRuntimeExports.jsx(g.default,{as:r??g.defaultAtomElementType,...o,className:l.cx("kakadu-components-2845019685",s)})}function K({as:r,isVisible:s,label:o,shouldCloseOnOutsideClick:f=!0,shouldCloseOnEscapePress:c=!0,children:m,className:p,innerClassName:x,onClose:a,...v}){const b=e.useRef(null),F=e.useRef(null),[I,k]=e.useState(!1),[S,B]=e.useState(!1),[u,R]=e.useState(!1),C=e.useCallback(t=>{b.current=t,R(!1)},[]),j=e.useRef(null),M=e.useCallback(t=>{t&&(j.current=t)},[]),W=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate(){var t;k(!0),(t=j.current)==null||t.focus()},clickOutsideDeactivates:f,escapeDeactivates:c,onUnpause(){k(!0)},onPause(){k(!1)},onDeactivate(){R(!1),k(!1)}}),[f,c]),[q,N]=e.useState(s??!1),$=e.useMemo(()=>({isVisible:q,isFocused:I,setInitialFocus:M,close:C}),[q,I,M,C]),[i,L]=e.useState("center");return e.useEffect(()=>{const t=F.current;if(t){const w=()=>{const O=t.offsetParent,E=O instanceof HTMLElement?O.getBoundingClientRect():null,y=t.getBoundingClientRect();if(!E){L("center");return}const P=16,D=window.innerWidth-P,T=E.left+E.width/2-y.width/2,V=T+y.width,A=T<P,_=V>D;let d="center";if(A&&_){const h=P-T;d=V-D>h?"right":"left"}else _?d="right":A&&(d="left");L(h=>h===d?h:d)};return w(),window.addEventListener("resize",w),()=>{window.removeEventListener("resize",w)}}},[]),e.useEffect(()=>{s&&(B(!0),N(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{R(!0)},100);return()=>{clearTimeout(t)}}R(!1)},[s]),e.useEffect(()=>{if(S&&!u){const t=setTimeout(()=>{a==null||a(b.current??void 0),N(!1)},370);return()=>{clearTimeout(t)}}},[S,u,a]),n.jsxRuntimeExports.jsx(g.default,{reference:F,as:r??g.defaultAtomElementType,role:"dialog","aria-hidden":!u,"aria-label":o??"Popover",...v,className:l.cx("kakadu-components-3920007758",i==="left"&&"kakadu-components-611400930",i==="right"&&"kakadu-components-944244368",u&&"kakadu-components-1399012551",p),children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-1118152266",u&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-1951789226",i==="left"&&"kakadu-components-1495725644",i==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(H.focusTrapReactExports.FocusTrap,{active:u,focusTrapOptions:W,children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-2488426662",x),children:[n.jsxRuntimeExports.jsx(U,{value:$,children:m}),n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-3252390100",i==="left"&&"kakadu-components-3754561431",i==="right"&&"kakadu-components-2265262600")})]})})]})})}function Q(r,s){const[o,f]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(f(!0),new Promise(a=>{c.current=a})),[]),p=e.useCallback(a=>{var v;f(!1),(v=c.current)==null||v.call(c,a),c.current=void 0},[]),x=e.useMemo(()=>n.jsxRuntimeExports.jsx(r,{...s,isVisible:o,onClose:p}),[r,s,o,p]);return e.useMemo(()=>({isVisible:o,show:m,popover:x}),[o,m,x])}exports.PopoverContainer=J;exports.default=K;exports.usePopover=Q;exports.usePopoverContext=G;
@@ -39,7 +39,7 @@ function ie({
39
39
  initialFocus: () => T.current ?? void 0,
40
40
  onActivate() {
41
41
  var e;
42
- (e = T.current) == null || e.focus(), h(!0);
42
+ h(!0), (e = T.current) == null || e.focus();
43
43
  },
44
44
  clickOutsideDeactivates: d,
45
45
  escapeDeactivates: o,
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react"),b=new Map,C=new Map,y=new Map;function j(e,s){let t=y.get(e);return t||(t=new Set,y.set(e,t)),t.add(s),()=>{t==null||t.delete(s),t&&t.size===0&&y.delete(e)}}function q(e,s){C.set(e,{timestamp:Date.now(),response:s});const t=y.get(e);if(t)for(const r of t)r(s)}function L(e){const[s,t]=n.useState(!1),[r,l]=n.useState(),[d,h]=n.useState(),g=n.useCallback(async(v,o)=>{try{h(void 0),t(!0);const a=await fetch(v,o),u=e?await e(a):a;return l(u),u}catch(a){const u=a instanceof Error?a:new Error("Unknown error");throw h(u),u}finally{t(!1)}},[e]);return n.useMemo(()=>({isLoading:s,fetch:g,response:r,error:d}),[s,g,r,d])}function J(e){const s=n.useCallback(async t=>{const r=await t.json();return e?e(r):r},[e]);return L(s)}function p(e,s,t,r){const{cacheLifetime:l=1e3*60}=r??{},[d,h]=n.useState(0),[g,v]=n.useState(()=>!!e),o=n.useMemo(()=>e?JSON.stringify({url:e,options:s}):"",[e,s]),a=n.useCallback(()=>{if(!o)return;const c=C.get(o);if(c){if(Date.now()-c.timestamp>l){C.delete(o);return}return c.response}},[o,l]),[u,w]=n.useState(()=>a()),[M,m]=n.useState(),S=n.useMemo(()=>{var c;return((c=s==null?void 0:s.method)==null?void 0:c.toUpperCase())??"GET"},[s]);return n.useEffect(()=>{if(S!=="GET")return;const c=()=>{document.hidden||h(f=>f+1)};return document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c)}},[S]),n.useEffect(()=>{if(!e||!o){w(void 0);return}const c=a();c===void 0?(w(void 0),m(void 0)):(w(c),m(void 0));const f=j(o,E=>{w(E),m(void 0)});return()=>{f()}},[e,o,a]),n.useEffect(()=>{if(!e||!o){v(!1);return}if(d<0)return;const c=S==="GET";if(c&&a()!==void 0){v(!1);return}let f=!0;m(void 0),v(!0);let E=c&&b.has(o)?b.get(o):void 0;if(!E){const i=fetch(e,s);b.set(o,i),i.then(()=>{b.delete(o)}),E=i}return E.then(async i=>{if(f){const F=t?await t(i):i;c&&q(o,F),w(F),m(void 0)}}).catch(i=>{f&&m(i)}).finally(()=>{f&&v(!1)}),()=>{f=!1}},[e,s,d,t,o,S,a]),n.useMemo(()=>({isLoading:g,response:u,error:M}),[g,u,M])}function k(e,s,t,r){const l=n.useCallback(async d=>{const h=await d.json();return t?t(h):h},[t]);return p(e,s,l,r)}exports.default=p;exports.useFetcher=L;exports.useJsonFetch=k;exports.useJsonFetcher=J;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react"),b=new Map,C=new Map,y=new Map;function j(e,s){let t=y.get(e);return t||(t=new Set,y.set(e,t)),t.add(s),()=>{t==null||t.delete(s),t&&t.size===0&&y.delete(e)}}function q(e,s){C.set(e,{timestamp:Date.now(),response:s});const t=y.get(e);if(t)for(const r of t)r(s)}function L(e){const[s,t]=n.useState(!1),[r,l]=n.useState(),[d,h]=n.useState(),g=n.useCallback(async(v,o)=>{try{h(void 0),t(!0);const a=await fetch(v,o),u=e?await e(a):a;return l(u),u}catch(a){const u=a instanceof Error?a:new Error("Unknown error");throw h(u),u}finally{t(!1)}},[e]);return n.useMemo(()=>({isLoading:s,fetch:g,response:r,error:d}),[s,g,r,d])}function J(e){const s=n.useCallback(async t=>{const r=await t.json();return e?e(r):r},[e]);return L(s)}function p(e,s,t,r){const{cacheLifetime:l=1e3*60}=r??{},[d,h]=n.useState(0),[g,v]=n.useState(()=>!!e),o=n.useMemo(()=>e?JSON.stringify({url:e,options:s}):"",[e,s]),a=n.useCallback(()=>{if(!o)return;const c=C.get(o);if(c){if(Date.now()-c.timestamp>l){C.delete(o);return}return c.response}},[o,l]),[u,w]=n.useState(()=>a()),[M,m]=n.useState(),S=n.useMemo(()=>{var c;return((c=s==null?void 0:s.method)==null?void 0:c.toUpperCase())??"GET"},[s]);return n.useEffect(()=>{if(S!=="GET")return;const c=()=>{document.hidden||h(f=>f+1)};return document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c)}},[S]),n.useEffect(()=>{if(!e||!o){w(void 0);return}const c=a();c===void 0?(w(void 0),m(void 0)):(w(c),m(void 0));const f=j(o,E=>{w(E),m(void 0)});return()=>{f()}},[e,o,a]),n.useEffect(()=>{if(!e||!o){v(!1);return}if(d<0)return;const c=S==="GET";if(c&&a()!==void 0){v(!1);return}let f=!0;m(void 0),v(!0);let E=c&&b.has(o)?b.get(o):void 0;if(!E){const i=fetch(e,s);b.set(o,i),i.then(()=>{b.delete(o)}),E=i}return E.then(async i=>{if(f){const F=t?await t(i):i;c&&q(o,F),w(F),m(void 0)}}).catch(i=>{f&&m(i)}).finally(()=>{f&&v(!1)}),()=>{f=!1}},[e,o,d,S,a,s,t]),n.useMemo(()=>({isLoading:g,response:u,error:M}),[g,u,M])}function k(e,s,t,r){const l=n.useCallback(async d=>{const h=await d.json();return t?t(h):h},[t]);return p(e,s,l,r)}exports.default=p;exports.useFetcher=L;exports.useJsonFetch=k;exports.useJsonFetcher=J;
@@ -121,7 +121,7 @@ function R(e, n, t, r) {
121
121
  }), () => {
122
122
  f = !1;
123
123
  };
124
- }, [e, n, u, t, s, y, c]), L(
124
+ }, [e, s, u, y, c, n, t]), L(
125
125
  () => ({ isLoading: l, response: a, error: G }),
126
126
  [l, a, G]
127
127
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "3.2.2",
3
+ "version": "3.2.4",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",