@kakadu/components 3.10.0 → 3.11.0

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.
@@ -11,9 +11,10 @@ type SkeletonProperties = {
11
11
  readonly isAnimated?: boolean;
12
12
  } & HTMLAttributes<HTMLDivElement>;
13
13
  export declare function SkeletonInstance({ label, width, height, className, children, isAnimated, ...parameters }: SkeletonProperties): import("react/jsx-runtime").JSX.Element;
14
- export default function Skeleton({ label, lines, isAnimated, }: {
14
+ export default function Skeleton({ label, lines, isDeterministic, isAnimated, }: {
15
15
  readonly label?: string;
16
16
  readonly lines?: number;
17
+ readonly isDeterministic?: boolean;
17
18
  readonly isAnimated?: boolean;
18
19
  }): import("react/jsx-runtime").JSX.Element | null;
19
20
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../jsx-runtime-BB_1_6y_.js"),l=require("react"),x=require("@kuma-ui/core");function h(u,e,{minimum:t,maximum:o}){const n=u*374761393+e*668265263+2147483647,r=Math.imul(n,1274126177),a=o-t+1;return t+Math.abs(r)%a}function i({label:u,width:e,height:t,className:o,children:n,isAnimated:r=!0,...a}){return s.jsxRuntimeExports.jsx("span",{...a,"aria-label":u,className:x.cx("kakadu-components-4254676273",r&&"kakadu-components-574297718",o),style:{width:e,height:t},children:n??s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{children:" "})})}const c="kakadu-components-3140855657";function m({label:u,lines:e=1,isAnimated:t=!0}){const o=l.useMemo(()=>{const n=[];if(e<=1)return n;for(let r=1;r<e;r+=1)n.push(s.jsxRuntimeExports.jsx(i,{"aria-hidden":!0,width:"100%",height:"1em",isAnimated:t,className:c},r));return n},[e,t]);return e<1?null:e===1?s.jsxRuntimeExports.jsx(i,{"aria-busy":!0,label:u,width:"100%",height:"1em",isAnimated:t,role:"status",className:c}):s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[o,s.jsxRuntimeExports.jsx(i,{"aria-busy":!0,label:u,width:"60%",height:"1em",isAnimated:t,role:"status",className:c})]})}exports.SkeletonInstance=i;exports.default=m;exports.getDeterministicSkeletonWidth=h;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),x=require("react"),l=require("@kuma-ui/core");function c(o,e,{minimum:t,maximum:s}){const a=o*374761393+e*668265263+2147483647,u=Math.imul(a,1274126177),r=s-t+1;return t+Math.abs(u)%r}function i({label:o,width:e,height:t,className:s,children:a,isAnimated:u=!0,...r}){return n.jsxRuntimeExports.jsx("span",{...r,"aria-label":o,className:l.cx("kakadu-components-4254676273",u&&"kakadu-components-574297718",s),style:{width:e,height:t},children:a??n.jsxRuntimeExports.jsx(n.jsxRuntimeExports.Fragment,{children:" "})})}const m="kakadu-components-3140855657";function h({label:o,lines:e=1,isDeterministic:t=!1,isAnimated:s=!0}){const a=x.useMemo(()=>{const u=[];if(e<=1)return u;for(let r=1;r<e;r+=1)u.push(n.jsxRuntimeExports.jsx(i,{"aria-hidden":!0,width:t?`${c(r,e,{minimum:90,maximum:100})}%`:"100%",height:"1em",isAnimated:s,className:m},r));return u},[e,t,s]);return e<1?null:e===1?n.jsxRuntimeExports.jsx(i,{"aria-busy":!0,label:o,width:"100%",height:"1em",isAnimated:s,role:"status",className:m}):n.jsxRuntimeExports.jsxs(n.jsxRuntimeExports.Fragment,{children:[a,n.jsxRuntimeExports.jsx(i,{"aria-busy":!0,label:o,width:t?`${c(e,e,{minimum:50,maximum:60})}%`:"60%",height:"1em",isAnimated:s,role:"status",className:m})]})}exports.SkeletonInstance=i;exports.default=h;exports.getDeterministicSkeletonWidth=c;
@@ -1,48 +1,55 @@
1
1
  import { j as s } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { useMemo as h } from "react";
3
- import { cx as l } from "@kuma-ui/core";
4
- function k(a, t, {
2
+ import { useMemo as l } from "react";
3
+ import { cx as i } from "@kuma-ui/core";
4
+ function h(o, t, {
5
5
  minimum: e,
6
- maximum: o
6
+ maximum: r
7
7
  }) {
8
- const r = a * 374761393 + t * 668265263 + 2147483647, n = Math.imul(r, 1274126177), u = o - e + 1;
9
- return e + Math.abs(n) % u;
8
+ const u = o * 374761393 + t * 668265263 + 2147483647, n = Math.imul(u, 1274126177), a = r - e + 1;
9
+ return e + Math.abs(n) % a;
10
10
  }
11
- function c({
12
- label: a,
11
+ function m({
12
+ label: o,
13
13
  width: t,
14
14
  height: e,
15
- className: o,
16
- children: r,
15
+ className: r,
16
+ children: u,
17
17
  isAnimated: n = !0,
18
- ...u
18
+ ...a
19
19
  }) {
20
- return /* @__PURE__ */ s.jsx("span", { ...u, "aria-label": a, className: l("kakadu-components-4254676273", n && "kakadu-components-574297718", o), style: {
20
+ return /* @__PURE__ */ s.jsx("span", { ...a, "aria-label": o, className: i("kakadu-components-4254676273", n && "kakadu-components-574297718", r), style: {
21
21
  width: t,
22
22
  height: e
23
- }, children: r ?? /* @__PURE__ */ s.jsx(s.Fragment, { children: " " }) });
23
+ }, children: u ?? /* @__PURE__ */ s.jsx(s.Fragment, { children: " " }) });
24
24
  }
25
- const i = "kakadu-components-3140855657";
26
- function p({
27
- label: a,
25
+ const c = "kakadu-components-3140855657";
26
+ function k({
27
+ label: o,
28
28
  lines: t = 1,
29
- isAnimated: e = !0
29
+ isDeterministic: e = !1,
30
+ isAnimated: r = !0
30
31
  }) {
31
- const o = h(() => {
32
- const r = [];
32
+ const u = l(() => {
33
+ const n = [];
33
34
  if (t <= 1)
34
- return r;
35
- for (let n = 1; n < t; n += 1)
36
- r.push(/* @__PURE__ */ s.jsx(c, { "aria-hidden": !0, width: "100%", height: "1em", isAnimated: e, className: i }, n));
37
- return r;
38
- }, [t, e]);
39
- return t < 1 ? null : t === 1 ? /* @__PURE__ */ s.jsx(c, { "aria-busy": !0, label: a, width: "100%", height: "1em", isAnimated: e, role: "status", className: i }) : /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
40
- o,
41
- /* @__PURE__ */ s.jsx(c, { "aria-busy": !0, label: a, width: "60%", height: "1em", isAnimated: e, role: "status", className: i })
35
+ return n;
36
+ for (let a = 1; a < t; a += 1)
37
+ n.push(/* @__PURE__ */ s.jsx(m, { "aria-hidden": !0, width: e ? `${h(a, t, {
38
+ minimum: 90,
39
+ maximum: 100
40
+ })}%` : "100%", height: "1em", isAnimated: r, className: c }, a));
41
+ return n;
42
+ }, [t, e, r]);
43
+ return t < 1 ? null : t === 1 ? /* @__PURE__ */ s.jsx(m, { "aria-busy": !0, label: o, width: "100%", height: "1em", isAnimated: r, role: "status", className: c }) : /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
44
+ u,
45
+ /* @__PURE__ */ s.jsx(m, { "aria-busy": !0, label: o, width: e ? `${h(t, t, {
46
+ minimum: 50,
47
+ maximum: 60
48
+ })}%` : "60%", height: "1em", isAnimated: r, role: "status", className: c })
42
49
  ] });
43
50
  }
44
51
  export {
45
- c as SkeletonInstance,
46
- p as default,
47
- k as getDeterministicSkeletonWidth
52
+ m as SkeletonInstance,
53
+ k as default,
54
+ h as getDeterministicSkeletonWidth
48
55
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react"),C=new Map,M=new Map,L=new Map,p=new Map;function R(t,s){let e=L.get(t);return e||(e=new Set,L.set(t,e)),e.add(s),()=>{e==null||e.delete(s),e&&e.size===0&&L.delete(t)}}function I(t,s){M.set(t,{timestamp:Date.now(),response:s});const e=L.get(t);if(e)for(const a of e)a(s)}function G(t,s){let e=p.get(t);return e||(e=new Set,p.set(t,e)),e.add(s),()=>{e==null||e.delete(s),e&&e.size===0&&p.delete(t)}}function U(t){M.delete(t);const s=p.get(t);if(s)for(const e of s)e()}function q(t){const[s,e]=n.useState(!1),[a,v]=n.useState(),[f,d]=n.useState(),g=n.useCallback(async(b,S)=>{try{d(void 0),e(!0);const l=await fetch(b,S),u=t?await t(l):l;return v(u),u}catch(l){const u=l instanceof Error?l:new Error("Unknown error");throw d(u),u}finally{e(!1)}},[t]);return n.useMemo(()=>({isLoading:s,fetch:g,response:a,error:f}),[s,g,a,f])}function k(t){const s=n.useCallback(async e=>{const a=await e.json();return t?t(a):a},[t]);return q(s)}function J(t,s,e,a){const{cacheLifetime:v=1e3*30,shouldFetch:f=!0}=a??{},[d,g]=n.useState(0),[b,S]=n.useState(()=>!!t),[l,u]=n.useState(()=>!!t&&f),o=n.useMemo(()=>t?JSON.stringify({url:t,options:s}):"",[t,s]),w=n.useCallback(()=>{if(!o)return;const c=M.get(o);if(c){if(Date.now()-c.timestamp>v){M.delete(o);return}return c.response}},[o,v]),[F,E]=n.useState(()=>w()),[y,m]=n.useState(),h=n.useMemo(()=>{var c;return((c=s==null?void 0:s.method)==null?void 0:c.toUpperCase())??"GET"},[s])==="GET";n.useEffect(()=>{if(!h)return;let c;const i=()=>{clearTimeout(c),!document.hidden&&(c=setTimeout(()=>{g(r=>r+1)},0))};return document.addEventListener("visibilitychange",i),window.addEventListener("focus",i),()=>{document.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i),clearTimeout(c)}},[h]),n.useEffect(()=>{if(!t||!o){S(!1),E(void 0);return}const c=w();S(!0),c===void 0?(E(void 0),m(void 0)):(E(c),m(void 0));const i=R(o,r=>{E(r),m(void 0)});return()=>{i()}},[t,o,w]),n.useEffect(()=>{if(!t||!o)return;const c=G(o,()=>{g(i=>i+1)});return()=>{c()}},[t,o]),n.useEffect(()=>{if(!t||!o||d<0||!f){u(!1);return}if(h&&w()!==void 0){u(!1);return}let c=!0;m(void 0),u(!0);let i=h&&C.has(o)?C.get(o):void 0;if(!i){const r=fetch(t,s);C.set(o,r),r.then(()=>{C.delete(o)}),i=r}return i.then(async r=>{if(c){const j=e?await e(r):r;h&&I(o,j),E(j),m(void 0)}}).catch(r=>{c&&m(r)}).finally(()=>{c&&u(!1)}),()=>{c=!1}},[t,o,d,f,h,w,s,e]);const T=n.useCallback(()=>{h&&o&&U(o)},[o,h]);return n.useMemo(()=>({isReady:b,isLoading:l,response:F,error:y,purge:T}),[b,l,F,y,T])}function z(t,s,e,a){const v=n.useCallback(async f=>{const d=await f.json();return e?e(d):d},[e]);return J(t,s,v,a)}exports.default=J;exports.useFetcher=q;exports.useJsonFetch=z;exports.useJsonFetcher=k;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react"),C=new Map,M=new Map,L=new Map,p=new Map;function R(t,s){let e=L.get(t);return e||(e=new Set,L.set(t,e)),e.add(s),()=>{e==null||e.delete(s),e&&e.size===0&&L.delete(t)}}function I(t,s){M.set(t,{timestamp:Date.now(),response:s});const e=L.get(t);if(e)for(const a of e)a(s)}function G(t,s){let e=p.get(t);return e||(e=new Set,p.set(t,e)),e.add(s),()=>{e==null||e.delete(s),e&&e.size===0&&p.delete(t)}}function U(t){M.delete(t);const s=p.get(t);if(s)for(const e of s)e()}function q(t){const[s,e]=n.useState(!1),[a,v]=n.useState(),[f,d]=n.useState(),g=n.useCallback(async(b,S)=>{try{d(void 0),e(!0);const l=await fetch(b,S),u=t?await t(l):l;return v(u),u}catch(l){const u=l instanceof Error?l:new Error("Unknown error");throw d(u),u}finally{e(!1)}},[t]);return n.useMemo(()=>({isLoading:s,fetch:g,response:a,error:f}),[s,g,a,f])}function k(t){const s=n.useCallback(async e=>{const a=await e.json();return t?t(a):a},[t]);return q(s)}function J(t,s,e,a){const{cacheLifetime:v=1e3*30,shouldFetch:f=!0}=a??{},[d,g]=n.useState(0),[b,S]=n.useState(()=>!!t),[l,u]=n.useState(()=>!!t&&f),o=n.useMemo(()=>t?JSON.stringify({url:t,options:s}):"",[t,s]),w=n.useCallback(()=>{if(!o)return;const c=M.get(o);if(c){if(Date.now()-c.timestamp>v){M.delete(o);return}return c.response}},[o,v]),[F,E]=n.useState(()=>w()),[y,m]=n.useState(),h=n.useMemo(()=>{var c;return((c=s==null?void 0:s.method)==null?void 0:c.toUpperCase())??"GET"},[s])==="GET";n.useEffect(()=>{if(!h)return;let c;const i=()=>{clearTimeout(c),!document.hidden&&(c=setTimeout(()=>{g(r=>r+1)},0))};return document.addEventListener("visibilitychange",i),window.addEventListener("focus",i),()=>{document.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i),clearTimeout(c)}},[h]),n.useEffect(()=>{if(!t||!o){S(!1),E(void 0);return}const c=w();S(!0),c===void 0?(E(void 0),m(void 0)):(E(c),m(void 0));const i=R(o,r=>{E(r),m(void 0)});return()=>{i()}},[t,o,w]),n.useEffect(()=>{if(!t||!o)return;const c=G(o,()=>{g(i=>i+1)});return()=>{c()}},[t,o]),n.useEffect(()=>{if(!t||!o||d<0||!f){u(!1);return}if(h&&w()!==void 0){u(!1);return}let c=!0;m(void 0),u(!0);let i=h&&C.has(o)?C.get(o):void 0;if(!i){const r=fetch(t,s);C.set(o,r),r.then(()=>{C.delete(o)}),i=r}return i.then(async r=>{if(c){const j=e?await e(r):r;h&&I(o,j),E(j),m(void 0)}}).catch(r=>{c&&m(r)}).finally(()=>{c&&u(!1)}),()=>{c=!1}},[t,o,d,f,h,w,s,e]);const T=n.useCallback(()=>{h&&o&&U(o)},[o,h]);return n.useMemo(()=>({isReady:b,isLoading:l,response:F,error:y,purge:T}),[b,l,F,y,T])}function z(t,s,e,a){const v=n.useCallback(async f=>{const d=await f.clone().json();return e?e(d):d},[e]);return J(t,s,v,a)}exports.default=J;exports.useFetcher=q;exports.useJsonFetch=z;exports.useJsonFetcher=k;
@@ -27,12 +27,12 @@ function z(t) {
27
27
  e();
28
28
  }
29
29
  function B(t) {
30
- const [n, e] = v(!1), [i, m] = v(), [u, f] = v(), g = p(
30
+ const [n, e] = v(!1), [i, l] = v(), [u, f] = v(), w = p(
31
31
  async (L, C) => {
32
32
  try {
33
33
  f(void 0), e(!0);
34
34
  const d = await fetch(L, C), a = t ? await t(d) : d;
35
- return m(a), a;
35
+ return l(a), a;
36
36
  } catch (d) {
37
37
  const a = d instanceof Error ? d : new Error("Unknown error");
38
38
  throw f(a), a;
@@ -43,8 +43,8 @@ function B(t) {
43
43
  [t]
44
44
  );
45
45
  return F(
46
- () => ({ isLoading: n, fetch: g, response: i, error: u }),
47
- [n, g, i, u]
46
+ () => ({ isLoading: n, fetch: w, response: i, error: u }),
47
+ [n, w, i, u]
48
48
  );
49
49
  }
50
50
  function N(t) {
@@ -58,21 +58,21 @@ function N(t) {
58
58
  return B(n);
59
59
  }
60
60
  function D(t, n, e, i) {
61
- const { cacheLifetime: m = 1e3 * 30, shouldFetch: u = !0 } = i ?? {}, [f, g] = v(0), [L, C] = v(() => !!t), [d, a] = v(() => !!t && u), s = F(
61
+ const { cacheLifetime: l = 1e3 * 30, shouldFetch: u = !0 } = i ?? {}, [f, w] = v(0), [L, C] = v(() => !!t), [d, a] = v(() => !!t && u), s = F(
62
62
  () => t ? JSON.stringify({ url: t, options: n }) : "",
63
63
  [t, n]
64
- ), l = p(() => {
64
+ ), g = p(() => {
65
65
  if (!s)
66
66
  return;
67
67
  const o = T.get(s);
68
68
  if (o) {
69
- if (Date.now() - o.timestamp > m) {
69
+ if (Date.now() - o.timestamp > l) {
70
70
  T.delete(s);
71
71
  return;
72
72
  }
73
73
  return o.response;
74
74
  }
75
- }, [s, m]), [j, E] = v(() => l()), [I, w] = v(), h = F(
75
+ }, [s, l]), [j, E] = v(() => g()), [I, m] = v(), h = F(
76
76
  () => {
77
77
  var o;
78
78
  return ((o = n == null ? void 0 : n.method) == null ? void 0 : o.toUpperCase()) ?? "GET";
@@ -83,32 +83,32 @@ function D(t, n, e, i) {
83
83
  if (!h)
84
84
  return;
85
85
  let o;
86
- const c = () => {
86
+ const r = () => {
87
87
  clearTimeout(o), !document.hidden && (o = setTimeout(() => {
88
- g((r) => r + 1);
88
+ w((c) => c + 1);
89
89
  }, 0));
90
90
  };
91
- return document.addEventListener("visibilitychange", c), window.addEventListener("focus", c), () => {
92
- document.removeEventListener("visibilitychange", c), window.removeEventListener("focus", c), clearTimeout(o);
91
+ return document.addEventListener("visibilitychange", r), window.addEventListener("focus", r), () => {
92
+ document.removeEventListener("visibilitychange", r), window.removeEventListener("focus", r), clearTimeout(o);
93
93
  };
94
94
  }, [h]), b(() => {
95
95
  if (!t || !s) {
96
96
  C(!1), E(void 0);
97
97
  return;
98
98
  }
99
- const o = l();
100
- C(!0), o === void 0 ? (E(void 0), w(void 0)) : (E(o), w(void 0));
101
- const c = G(s, (r) => {
102
- E(r), w(void 0);
99
+ const o = g();
100
+ C(!0), o === void 0 ? (E(void 0), m(void 0)) : (E(o), m(void 0));
101
+ const r = G(s, (c) => {
102
+ E(c), m(void 0);
103
103
  });
104
104
  return () => {
105
- c();
105
+ r();
106
106
  };
107
- }, [t, s, l]), b(() => {
107
+ }, [t, s, g]), b(() => {
108
108
  if (!t || !s)
109
109
  return;
110
110
  const o = U(s, () => {
111
- g((c) => c + 1);
111
+ w((r) => r + 1);
112
112
  });
113
113
  return () => {
114
114
  o();
@@ -118,32 +118,32 @@ function D(t, n, e, i) {
118
118
  a(!1);
119
119
  return;
120
120
  }
121
- if (h && l() !== void 0) {
121
+ if (h && g() !== void 0) {
122
122
  a(!1);
123
123
  return;
124
124
  }
125
125
  let o = !0;
126
- w(void 0), a(!0);
127
- let c = h && y.has(s) ? y.get(s) : void 0;
128
- if (!c) {
129
- const r = fetch(t, n);
130
- y.set(s, r), r.then(() => {
126
+ m(void 0), a(!0);
127
+ let r = h && y.has(s) ? y.get(s) : void 0;
128
+ if (!r) {
129
+ const c = fetch(t, n);
130
+ y.set(s, c), c.then(() => {
131
131
  y.delete(s);
132
- }), c = r;
132
+ }), r = c;
133
133
  }
134
- return c.then(async (r) => {
134
+ return r.then(async (c) => {
135
135
  if (o) {
136
- const q = e ? await e(r) : r;
137
- h && J(s, q), E(q), w(void 0);
136
+ const q = e ? await e(c) : c;
137
+ h && J(s, q), E(q), m(void 0);
138
138
  }
139
- }).catch((r) => {
140
- o && w(r);
139
+ }).catch((c) => {
140
+ o && m(c);
141
141
  }).finally(() => {
142
142
  o && a(!1);
143
143
  }), () => {
144
144
  o = !1;
145
145
  };
146
- }, [t, s, f, u, h, l, n, e]);
146
+ }, [t, s, f, u, h, g, n, e]);
147
147
  const S = p(() => {
148
148
  h && s && z(s);
149
149
  }, [s, h]);
@@ -153,14 +153,14 @@ function D(t, n, e, i) {
153
153
  );
154
154
  }
155
155
  function O(t, n, e, i) {
156
- const m = p(
156
+ const l = p(
157
157
  async (u) => {
158
- const f = await u.json();
158
+ const f = await u.clone().json();
159
159
  return e ? e(f) : f;
160
160
  },
161
161
  [e]
162
162
  );
163
- return D(t, n, m, i);
163
+ return D(t, n, l, i);
164
164
  }
165
165
  export {
166
166
  D as default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",