@cronocode/react-box 3.0.10 → 3.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.
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),n=require("react"),h=require("../box.cjs"),E=require("./textbox.cjs"),z=require("./flex.cjs"),C=require("../core.cjs"),F=require("./baseSvg.cjs"),G=require("./tooltip.cjs"),Q=require("./button.cjs");function X(u,d){const{name:i,defaultValue:g,multiple:l,isSearchable:w,searchPlaceholder:H,children:j,onChange:r,...L}=u,[c,v]=n.useState(Array.isArray(g)?g:g?[g]:[]),[M,P]=n.useState(""),[m,R,S]=C.useVisibility(),b=n.useRef(null),U=n.useRef(null),[V,B]=n.useState(0),I=n.useMemo(()=>V>window.innerHeight/2,[V]),Y=n.useMemo(()=>{var e;return I?((e=S.current)==null?void 0:e.getBoundingClientRect().height)??0:0},[I,S]),p=n.useMemo(()=>Array.isArray(j)?j:[j],[j]),_=n.useMemo(()=>p.filter(e=>{var o;return((o=e.type)==null?void 0:o.displayName)==="DropdownItem"}),[p]),f=n.useMemo(()=>_.filter(e=>w&&M?N(e).toLowerCase().includes(M.toLowerCase()):!0),[w,M,p]),y=n.useMemo(()=>p.find(e=>{var o;return((o=e.type)==null?void 0:o.displayName)==="DropdownUnselect"}),[p]),O=n.useMemo(()=>p.find(e=>{var o;return((o=e.type)==null?void 0:o.displayName)==="DropdownSelectAll"}),[p]),A=n.useMemo(()=>p.find(e=>{var o;return((o=e.type)==null?void 0:o.displayName)==="DropdownEmptyItem"}),[p]),T=n.useMemo(()=>p.find(e=>{var o;return((o=e.type)==null?void 0:o.displayName)==="DropdownDisplay"}),[p]),J=n.useMemo(()=>{if(T)return T.props.children(c);const e=f.filter(t=>c.includes(t.props.value));if(l&&e.length>1)return e.map(t=>N(t)).join(", ");const o=e.at(0);return(o==null?void 0:o.props.children)??(o==null?void 0:o.props.value)??(l?null:y==null?void 0:y.props.children)},[l,f,c,y]),q=n.useCallback((e,...o)=>{if(o.length===0)v([]),r==null||r(void 0,[]);else if(l&&o.length>1){const t=o.map(a=>a.props.value);v(t),r==null||r(void 0,t)}else if(o.length===1){const t=o[0];if(l){const a=c.filter($=>$!==t.props.value);a.length===c.length&&a.push(t.props.value),v(a),r==null||r(t.props.value,a)}else v([t.props.value]),r==null||r(t.props.value,[t.props.value])}l?(e.stopPropagation(),setTimeout(()=>{var t;return(t=b.current)==null?void 0:t.focus()},0)):(R(!1),setTimeout(()=>{var t;return(t=S.current)==null?void 0:t.focus()},0))},[l,c,v]);n.useEffect(()=>{m?setTimeout(()=>{var e,o,t;(e=b.current)==null||e.focus(),(t=(o=U.current)==null?void 0:o.querySelector('[aria-selected="true"]'))==null||t.scrollIntoView({block:"nearest"})},0):P("")},[m]);const k=O&&l&&f.length>c.length,W=y&&f.length>0&&!k;return s.jsxs(h,{width:"fit-content",children:[c.map(e=>s.jsx(E,{ref:d,name:i,type:"hidden",value:JSON.stringify(e)??""},JSON.stringify(e))),s.jsxs(Q,{ref:S,component:"dropdown",...L,props:{onMouseDown:()=>R(e=>!e),tabIndex:0},children:[w&&s.jsx(E,{display:m&&w?"block":"none",clean:!0,flex1:!0,width:1,minHeight:5,placeholder:H,value:M,onChange:e=>P(e.target.value),ref:b,props:{onMouseDown:e=>{m&&w&&e.stopPropagation()}}}),s.jsx(z,{component:"dropdown.display",display:m&&w?"none":"flex",flex1:!0,minHeight:5,children:J}),s.jsx(h,{children:s.jsx(F,{viewBox:"0 0 10 6",width:"0.6rem",rotate:m?180:0,children:s.jsx("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"m1 1 4 4 4-4"})})})]}),m&&s.jsx(G,{ref:U,top:I?void 0:0,bottom:I?2:void 0,style:{transform:`translateY(-${Y}px)`},onPositionChange:e=>B(e.top-window.scrollY),children:(f.length>0||A)&&s.jsxs(h,{component:"dropdown.items",children:[W&&s.jsx(h,{component:"dropdown.unselect",selected:c.length===0,...y.props,props:{onMouseDown:e=>q(e)}}),k&&s.jsx(h,{component:"dropdown.selectAll",...O.props,props:{onMouseDown:e=>q(e,..._)}}),f.map(e=>{const{value:o,...t}=e.props;return s.jsx(h,{component:"dropdown.item",theme:l?"multiple":"single",selected:c.includes(o),...t,props:{onMouseDown:a=>q(a,e)}},o)}),f.length===0&&A&&s.jsx(h,{component:"dropdown.emptyItem",...A.props})]})})]})}function D(u){const d=i=>null;return d.displayName=u,d}const x=n.forwardRef(X);x.Item=D("DropdownItem");x.Unselect=D("DropdownUnselect");x.SelectAll=D("DropdownSelectAll");x.EmptyItem=D("DropdownEmptyItem");x.Display=D("DropdownDisplay");function N(u){var d;if(u==null)return"";if(typeof u=="object"){const i=(d=u.props)==null?void 0:d.children;return i==null?"":typeof i=="object"?(Array.isArray(i)?i:[i]).map(l=>N(l)).join(""):i.toString()}return u.toString()}module.exports=x;
1
+ "use strict";const r=require("react/jsx-runtime"),n=require("react"),h=require("../box.cjs"),L=require("./textbox.cjs"),G=require("./flex.cjs"),Q=require("../core.cjs"),X=require("./baseSvg.cjs"),Z=require("./tooltip.cjs"),K=require("./button.cjs");function ee(i,m){const{name:p,defaultValue:g,value:y,multiple:u,isSearchable:w,searchPlaceholder:B,children:A,hideArrow:H,onChange:s,...Y}=i,[J,j]=n.useState(Array.isArray(g)?g:g?[g]:[]),c="value"in i?Array.isArray(y)?y:y?[y]:[]:J,[D,R]=n.useState(""),[a,U,I]=Q.useVisibility(),q=n.useRef(null),T=n.useRef(null),[V,W]=n.useState(0),b=n.useMemo(()=>V>window.innerHeight/2,[V]),$=n.useMemo(()=>{var e;return b?((e=I.current)==null?void 0:e.getBoundingClientRect().height)??0:0},[b,I]),l=n.useMemo(()=>(Array.isArray(A)?A:[A]).flatMap(e=>e),[A]),_=n.useMemo(()=>l.filter(e=>{var t;return((t=e.type)==null?void 0:t.displayName)==="DropdownItem"}),[l]),f=n.useMemo(()=>_.filter(e=>w&&D?P(e).toLowerCase().includes(D.toLowerCase()):!0),[w,D,l]),x=n.useMemo(()=>l.find(e=>{var t;return((t=e.type)==null?void 0:t.displayName)==="DropdownUnselect"}),[l]),O=n.useMemo(()=>l.find(e=>{var t;return((t=e.type)==null?void 0:t.displayName)==="DropdownSelectAll"}),[l]),N=n.useMemo(()=>l.find(e=>{var t;return((t=e.type)==null?void 0:t.displayName)==="DropdownEmptyItem"}),[l]),C=n.useMemo(()=>l.find(e=>{var t;return((t=e.type)==null?void 0:t.displayName)==="DropdownDisplay"}),[l]),z=n.useMemo(()=>{if(C)return C.props.children(c,a);const e=f.filter(o=>c.includes(o.props.value));if(u&&e.length>1)return e.map(o=>P(o)).join(", ");const t=e.at(0);return(t==null?void 0:t.props.children)??(t==null?void 0:t.props.value)??(u?null:x==null?void 0:x.props.children)},[u,f,c,x,a]),k=n.useCallback((e,...t)=>{if(t.length===0)j([]),s==null||s(void 0,[]);else if(u&&t.length>1){const o=t.map(d=>d.props.value);j(o),s==null||s(void 0,o)}else if(t.length===1){const o=t[0];if(u){const d=c.filter(M=>M!==o.props.value);d.length===c.length&&d.push(o.props.value),j(d),s==null||s(o.props.value,d)}else j([o.props.value]),s==null||s(o.props.value,[o.props.value])}u?(e.stopPropagation(),setTimeout(()=>{var o;return(o=q.current)==null?void 0:o.focus()},0)):(U(!1),setTimeout(()=>{var o;return(o=I.current)==null?void 0:o.focus()},0))},[u,c,j]);n.useEffect(()=>{a?setTimeout(()=>{var e,t,o;(e=q.current)==null||e.focus(),(o=(t=T.current)==null?void 0:t.querySelector('[aria-selected="true"]'))==null||o.scrollIntoView({block:"nearest"})},0):R("")},[a]);const E=O&&u&&f.length>c.length,F=x&&f.length>0&&!E;return r.jsxs(h,{width:"fit-content",children:[c.map(e=>r.jsx(L,{ref:m,name:p,type:"hidden",value:JSON.stringify(e)??""},JSON.stringify(e))),r.jsxs(K,{ref:I,component:"dropdown",onClick:()=>U(e=>!e),props:{tabIndex:0},...Y,children:[w&&r.jsx(L,{display:a&&w?"block":"none",clean:!0,flex1:!0,width:1,minHeight:5,placeholder:B,value:D,onChange:e=>R(e.target.value),ref:q,props:{onClick:e=>{a&&w&&e.stopPropagation()}}}),r.jsx(G,{component:"dropdown.display",display:a&&w?"none":"flex",children:z}),!H&&r.jsx(h,{children:r.jsx(X,{viewBox:"0 0 10 6",width:"0.6rem",rotate:a?180:0,children:r.jsx("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"m1 1 4 4 4-4"})})})]}),a&&r.jsx(Z,{ref:T,top:b?void 0:0,bottom:b?2:void 0,style:{transform:`translateY(-${$}px)`},onPositionChange:e=>W(e.top-window.scrollY),children:(f.length>0||N)&&r.jsxs(h,{component:"dropdown.items",children:[F&&r.jsx(h,{component:"dropdown.unselect",selected:c.length===0,...x.props,props:{onClick:e=>k(e)}}),E&&r.jsx(h,{component:"dropdown.selectAll",...O.props,props:{onClick:e=>k(e,..._)}}),f.map(e=>{const{value:t,onClick:o,...d}=e.props;return r.jsx(h,{component:"dropdown.item",theme:u?"multiple":"single",selected:c.includes(t),...d,props:{onClick:M=>{o==null||o(M),k(M,e)}}},t)}),f.length===0&&N&&r.jsx(h,{component:"dropdown.emptyItem",...N.props})]})})]})}function S(i){const m=p=>null;return m.displayName=i,m}const v=n.forwardRef(ee);v.Item=S("DropdownItem");v.Unselect=S("DropdownUnselect");v.SelectAll=S("DropdownSelectAll");v.EmptyItem=S("DropdownEmptyItem");v.Display=S("DropdownDisplay");function P(i){var m;if(i==null)return"";if(typeof i=="object"){const p=(m=i.props)==null?void 0:m.children;return p==null?"":typeof p=="object"?(Array.isArray(p)?p:[p]).map(y=>P(y)).join(""):p.toString()}return i.toString()}module.exports=v;
@@ -1,18 +1,21 @@
1
1
  import { Ref } from 'react';
2
2
  import { BoxProps } from '../box';
3
- interface Props<TVal> extends BoxProps {
3
+ interface Props<TVal> extends BoxProps<'button'> {
4
4
  name?: string;
5
5
  defaultValue?: TVal | TVal[];
6
+ value?: TVal | TVal[];
6
7
  multiple?: boolean;
7
8
  isSearchable?: boolean;
8
9
  searchPlaceholder?: string;
10
+ hideArrow?: boolean;
9
11
  onChange?: (value: Maybe<TVal>, values: TVal[]) => void;
10
12
  }
11
13
  interface DropdownItemProps<TVal> extends BoxProps {
12
14
  value: TVal;
15
+ onClick?(e: React.MouseEvent): void;
13
16
  }
14
17
  interface DropdownDisplayProps<TVal> extends Omit<BoxProps, 'children'> {
15
- children: (selectedValues: TVal[]) => React.ReactNode;
18
+ children: (selectedValues: TVal[], isOpen: boolean) => React.ReactNode;
16
19
  }
17
20
  interface DropdownType {
18
21
  <TVal>(props: Props<TVal>, ref: Ref<HTMLInputElement>): React.ReactNode;
@@ -1,160 +1,160 @@
1
- import { jsxs as M, jsx as l } from "react/jsx-runtime";
2
- import { forwardRef as G, useState as T, useRef as Y, useMemo as c, useCallback as Q, useEffect as X } from "react";
1
+ import { jsxs as U, jsx as l } from "react/jsx-runtime";
2
+ import { forwardRef as Z, useState as B, useRef as M, useMemo as c, useCallback as K, useEffect as ee } from "react";
3
3
  import h from "../box.mjs";
4
- import J from "./textbox.mjs";
5
- import Z from "./flex.mjs";
6
- import { b as K } from "../core.mjs";
7
- import ee from "./baseSvg.mjs";
8
- import oe from "./tooltip.mjs";
9
- import te from "./button.mjs";
10
- function re(a, d) {
11
- const { name: p, defaultValue: g, multiple: n, isSearchable: w, searchPlaceholder: q, children: I, onChange: r, ...F } = a, [i, v] = T(Array.isArray(g) ? g : g ? [g] : []), [S, U] = T(""), [m, V, A] = K(), N = Y(null), O = Y(null), [R, W] = T(0), b = c(() => R > window.innerHeight / 2, [R]), _ = c(() => {
4
+ import q from "./textbox.mjs";
5
+ import te from "./flex.mjs";
6
+ import { b as oe } from "../core.mjs";
7
+ import re from "./baseSvg.mjs";
8
+ import ne from "./tooltip.mjs";
9
+ import le from "./button.mjs";
10
+ function se(s, m) {
11
+ const { name: p, defaultValue: g, value: y, multiple: a, isSearchable: w, searchPlaceholder: F, children: S, hideArrow: W, onChange: r, ..._ } = s, [$, x] = B(Array.isArray(g) ? g : g ? [g] : []), i = "value" in s ? Array.isArray(y) ? y : y ? [y] : [] : $, [I, O] = B(""), [d, R, b] = oe(), P = M(null), C = M(null), [E, z] = B(0), N = c(() => E > window.innerHeight / 2, [E]), G = c(() => {
12
12
  var e;
13
- return b ? ((e = A.current) == null ? void 0 : e.getBoundingClientRect().height) ?? 0 : 0;
14
- }, [b, A]), s = c(() => Array.isArray(I) ? I : [I], [I]), k = c(() => s.filter((e) => {
15
- var o;
16
- return ((o = e.type) == null ? void 0 : o.displayName) === "DropdownItem";
17
- }), [s]), f = c(() => k.filter((e) => w && S ? B(e).toLowerCase().includes(S.toLowerCase()) : !0), [w, S, s]), y = c(() => s.find((e) => {
18
- var o;
19
- return ((o = e.type) == null ? void 0 : o.displayName) === "DropdownUnselect";
20
- }), [s]), E = c(() => s.find((e) => {
21
- var o;
22
- return ((o = e.type) == null ? void 0 : o.displayName) === "DropdownSelectAll";
23
- }), [s]), P = c(() => s.find((e) => {
24
- var o;
25
- return ((o = e.type) == null ? void 0 : o.displayName) === "DropdownEmptyItem";
26
- }), [s]), H = c(() => s.find((e) => {
27
- var o;
28
- return ((o = e.type) == null ? void 0 : o.displayName) === "DropdownDisplay";
29
- }), [s]), $ = c(() => {
30
- if (H) return H.props.children(i);
31
- const e = f.filter((t) => i.includes(t.props.value));
32
- if (n && e.length > 1)
33
- return e.map((t) => B(t)).join(", ");
34
- const o = e.at(0);
35
- return (o == null ? void 0 : o.props.children) ?? (o == null ? void 0 : o.props.value) ?? (n ? null : y == null ? void 0 : y.props.children);
36
- }, [n, f, i, y]), j = Q(
37
- (e, ...o) => {
38
- if (o.length === 0)
39
- v([]), r == null || r(void 0, []);
40
- else if (n && o.length > 1) {
41
- const t = o.map((u) => u.props.value);
42
- v(t), r == null || r(void 0, t);
43
- } else if (o.length === 1) {
44
- const t = o[0];
45
- if (n) {
46
- const u = i.filter((C) => C !== t.props.value);
47
- u.length === i.length && u.push(t.props.value), v(u), r == null || r(t.props.value, u);
13
+ return N ? ((e = b.current) == null ? void 0 : e.getBoundingClientRect().height) ?? 0 : 0;
14
+ }, [N, b]), n = c(
15
+ () => (Array.isArray(S) ? S : [S]).flatMap((e) => e),
16
+ [S]
17
+ ), L = c(() => n.filter((e) => {
18
+ var t;
19
+ return ((t = e.type) == null ? void 0 : t.displayName) === "DropdownItem";
20
+ }), [n]), f = c(() => L.filter((e) => w && I ? V(e).toLowerCase().includes(I.toLowerCase()) : !0), [w, I, n]), v = c(() => n.find((e) => {
21
+ var t;
22
+ return ((t = e.type) == null ? void 0 : t.displayName) === "DropdownUnselect";
23
+ }), [n]), H = c(() => n.find((e) => {
24
+ var t;
25
+ return ((t = e.type) == null ? void 0 : t.displayName) === "DropdownSelectAll";
26
+ }), [n]), T = c(() => n.find((e) => {
27
+ var t;
28
+ return ((t = e.type) == null ? void 0 : t.displayName) === "DropdownEmptyItem";
29
+ }), [n]), Y = c(() => n.find((e) => {
30
+ var t;
31
+ return ((t = e.type) == null ? void 0 : t.displayName) === "DropdownDisplay";
32
+ }), [n]), Q = c(() => {
33
+ if (Y) return Y.props.children(i, d);
34
+ const e = f.filter((o) => i.includes(o.props.value));
35
+ if (a && e.length > 1)
36
+ return e.map((o) => V(o)).join(", ");
37
+ const t = e.at(0);
38
+ return (t == null ? void 0 : t.props.children) ?? (t == null ? void 0 : t.props.value) ?? (a ? null : v == null ? void 0 : v.props.children);
39
+ }, [a, f, i, v, d]), j = K(
40
+ (e, ...t) => {
41
+ if (t.length === 0)
42
+ x([]), r == null || r(void 0, []);
43
+ else if (a && t.length > 1) {
44
+ const o = t.map((u) => u.props.value);
45
+ x(o), r == null || r(void 0, o);
46
+ } else if (t.length === 1) {
47
+ const o = t[0];
48
+ if (a) {
49
+ const u = i.filter((k) => k !== o.props.value);
50
+ u.length === i.length && u.push(o.props.value), x(u), r == null || r(o.props.value, u);
48
51
  } else
49
- v([t.props.value]), r == null || r(t.props.value, [t.props.value]);
52
+ x([o.props.value]), r == null || r(o.props.value, [o.props.value]);
50
53
  }
51
- n ? (e.stopPropagation(), setTimeout(() => {
52
- var t;
53
- return (t = N.current) == null ? void 0 : t.focus();
54
- }, 0)) : (V(!1), setTimeout(() => {
55
- var t;
56
- return (t = A.current) == null ? void 0 : t.focus();
54
+ a ? (e.stopPropagation(), setTimeout(() => {
55
+ var o;
56
+ return (o = P.current) == null ? void 0 : o.focus();
57
+ }, 0)) : (R(!1), setTimeout(() => {
58
+ var o;
59
+ return (o = b.current) == null ? void 0 : o.focus();
57
60
  }, 0));
58
61
  },
59
- [n, i, v]
62
+ [a, i, x]
60
63
  );
61
- X(() => {
62
- m ? setTimeout(() => {
63
- var e, o, t;
64
- (e = N.current) == null || e.focus(), (t = (o = O.current) == null ? void 0 : o.querySelector('[aria-selected="true"]')) == null || t.scrollIntoView({ block: "nearest" });
65
- }, 0) : U("");
66
- }, [m]);
67
- const L = E && n && f.length > i.length, z = y && f.length > 0 && !L;
68
- return /* @__PURE__ */ M(h, { width: "fit-content", children: [
69
- i.map((e) => /* @__PURE__ */ l(J, { ref: d, name: p, type: "hidden", value: JSON.stringify(e) ?? "" }, JSON.stringify(e))),
70
- /* @__PURE__ */ M(te, { ref: A, component: "dropdown", ...F, props: { onMouseDown: () => V((e) => !e), tabIndex: 0 }, children: [
64
+ ee(() => {
65
+ d ? setTimeout(() => {
66
+ var e, t, o;
67
+ (e = P.current) == null || e.focus(), (o = (t = C.current) == null ? void 0 : t.querySelector('[aria-selected="true"]')) == null || o.scrollIntoView({ block: "nearest" });
68
+ }, 0) : O("");
69
+ }, [d]);
70
+ const J = H && a && f.length > i.length, X = v && f.length > 0 && !J;
71
+ return /* @__PURE__ */ U(h, { width: "fit-content", children: [
72
+ i.map((e) => /* @__PURE__ */ l(q, { ref: m, name: p, type: "hidden", value: JSON.stringify(e) ?? "" }, JSON.stringify(e))),
73
+ /* @__PURE__ */ U(le, { ref: b, component: "dropdown", onClick: () => R((e) => !e), props: { tabIndex: 0 }, ..._, children: [
71
74
  w && /* @__PURE__ */ l(
72
- J,
75
+ q,
73
76
  {
74
- display: m && w ? "block" : "none",
77
+ display: d && w ? "block" : "none",
75
78
  clean: !0,
76
79
  flex1: !0,
77
80
  width: 1,
78
81
  minHeight: 5,
79
- placeholder: q,
80
- value: S,
81
- onChange: (e) => U(e.target.value),
82
- ref: N,
82
+ placeholder: F,
83
+ value: I,
84
+ onChange: (e) => O(e.target.value),
85
+ ref: P,
83
86
  props: {
84
- onMouseDown: (e) => {
85
- m && w && e.stopPropagation();
87
+ onClick: (e) => {
88
+ d && w && e.stopPropagation();
86
89
  }
87
90
  }
88
91
  }
89
92
  ),
90
- /* @__PURE__ */ l(Z, { component: "dropdown.display", display: m && w ? "none" : "flex", flex1: !0, minHeight: 5, children: $ }),
91
- /* @__PURE__ */ l(h, { children: /* @__PURE__ */ l(ee, { viewBox: "0 0 10 6", width: "0.6rem", rotate: m ? 180 : 0, children: /* @__PURE__ */ l("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m1 1 4 4 4-4" }) }) })
93
+ /* @__PURE__ */ l(te, { component: "dropdown.display", display: d && w ? "none" : "flex", children: Q }),
94
+ !W && /* @__PURE__ */ l(h, { children: /* @__PURE__ */ l(re, { viewBox: "0 0 10 6", width: "0.6rem", rotate: d ? 180 : 0, children: /* @__PURE__ */ l("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m1 1 4 4 4-4" }) }) })
92
95
  ] }),
93
- m && /* @__PURE__ */ l(
94
- oe,
96
+ d && /* @__PURE__ */ l(
97
+ ne,
95
98
  {
96
- ref: O,
97
- top: b ? void 0 : 0,
98
- bottom: b ? 2 : void 0,
99
- style: { transform: `translateY(-${_}px)` },
100
- onPositionChange: (e) => W(e.top - window.scrollY),
101
- children: (f.length > 0 || P) && /* @__PURE__ */ M(h, { component: "dropdown.items", children: [
102
- z && /* @__PURE__ */ l(
99
+ ref: C,
100
+ top: N ? void 0 : 0,
101
+ bottom: N ? 2 : void 0,
102
+ style: { transform: `translateY(-${G}px)` },
103
+ onPositionChange: (e) => z(e.top - window.scrollY),
104
+ children: (f.length > 0 || T) && /* @__PURE__ */ U(h, { component: "dropdown.items", children: [
105
+ X && /* @__PURE__ */ l(
103
106
  h,
104
107
  {
105
108
  component: "dropdown.unselect",
106
109
  selected: i.length === 0,
107
- ...y.props,
108
- props: { onMouseDown: (e) => j(e) }
109
- }
110
- ),
111
- L && /* @__PURE__ */ l(
112
- h,
113
- {
114
- component: "dropdown.selectAll",
115
- ...E.props,
116
- props: { onMouseDown: (e) => j(e, ...k) }
110
+ ...v.props,
111
+ props: { onClick: (e) => j(e) }
117
112
  }
118
113
  ),
114
+ J && /* @__PURE__ */ l(h, { component: "dropdown.selectAll", ...H.props, props: { onClick: (e) => j(e, ...L) } }),
119
115
  f.map((e) => {
120
- const { value: o, ...t } = e.props;
116
+ const { value: t, onClick: o, ...u } = e.props;
121
117
  return /* @__PURE__ */ l(
122
118
  h,
123
119
  {
124
120
  component: "dropdown.item",
125
- theme: n ? "multiple" : "single",
126
- selected: i.includes(o),
127
- ...t,
128
- props: { onMouseDown: (u) => j(u, e) }
121
+ theme: a ? "multiple" : "single",
122
+ selected: i.includes(t),
123
+ ...u,
124
+ props: {
125
+ onClick: (k) => {
126
+ o == null || o(k), j(k, e);
127
+ }
128
+ }
129
129
  },
130
- o
130
+ t
131
131
  );
132
132
  }),
133
- f.length === 0 && P && /* @__PURE__ */ l(h, { component: "dropdown.emptyItem", ...P.props })
133
+ f.length === 0 && T && /* @__PURE__ */ l(h, { component: "dropdown.emptyItem", ...T.props })
134
134
  ] })
135
135
  }
136
136
  )
137
137
  ] });
138
138
  }
139
- function D(a) {
140
- const d = (p) => null;
141
- return d.displayName = a, d;
139
+ function A(s) {
140
+ const m = (p) => null;
141
+ return m.displayName = s, m;
142
142
  }
143
- const x = G(re);
144
- x.Item = D("DropdownItem");
145
- x.Unselect = D("DropdownUnselect");
146
- x.SelectAll = D("DropdownSelectAll");
147
- x.EmptyItem = D("DropdownEmptyItem");
148
- x.Display = D("DropdownDisplay");
149
- function B(a) {
150
- var d;
151
- if (a == null) return "";
152
- if (typeof a == "object") {
153
- const p = (d = a.props) == null ? void 0 : d.children;
154
- return p == null ? "" : typeof p == "object" ? (Array.isArray(p) ? p : [p]).map((n) => B(n)).join("") : p.toString();
143
+ const D = Z(se);
144
+ D.Item = A("DropdownItem");
145
+ D.Unselect = A("DropdownUnselect");
146
+ D.SelectAll = A("DropdownSelectAll");
147
+ D.EmptyItem = A("DropdownEmptyItem");
148
+ D.Display = A("DropdownDisplay");
149
+ function V(s) {
150
+ var m;
151
+ if (s == null) return "";
152
+ if (typeof s == "object") {
153
+ const p = (m = s.props) == null ? void 0 : m.children;
154
+ return p == null ? "" : typeof p == "object" ? (Array.isArray(p) ? p : [p]).map((y) => V(y)).join("") : p.toString();
155
155
  }
156
- return a.toString();
156
+ return s.toString();
157
157
  }
158
158
  export {
159
- x as default
159
+ D as default
160
160
  };
package/core.cjs CHANGED
@@ -4,4 +4,4 @@ body{margin: 0;line-height: var(--lineHeight);font-size: var(--fontSize);}
4
4
  a,ul{all: unset;}
5
5
  .${ue}{display: block;border: 0 solid var(--borderColor);outline: 0px solid var(--outlineColor);margin: 0;padding: 0;background-color: initial;transition: all var(--transitionTime);box-sizing: border-box;font-family: inherit;font-size: inherit;}
6
6
  .${A}{display: block;border: 0 solid var(--borderColor);outline: 0px solid var(--outlineColor);margin: 0;padding: 0;transition: all var(--svgTransitionTime);}.${A} path,.${A} circle,.${A} rect,.${A} line {transition: all var(--svgTransitionTime);}
7
- `,g=Object.entries(r);g.sort(([c],[m])=>(U[c]??0)-(U[m]??0));const b=g.reduce((c,[m,N])=>(m!=="normal"&&c.push(`@media(min-width: ${U[m]}px){`),Object.entries(N).forEach(([F,q])=>{const{__parents:ee,...de}=q,te=Object.entries(de);te.sort(([C],[R])=>l[C]-l[R]),te.forEach(([C,R])=>{R.forEach(E=>{var k,H;const h=z[C].find(V=>Array.isArray(V.values)?V.values.includes(E):typeof E==typeof V.values);if(!h)return;const j=o(C,E,+F,m),D=K[+F].map(V=>Z[V]).join(""),x=((k=h.selector)==null?void 0:k.call(h,`.${j}`,D))??`.${j}${D}`,I=Array.isArray(h.styleName)?h.styleName:[h.styleName??C],S=((H=h.valueFormat)==null?void 0:H.call(h,E,w.getVariableValue))??E;c.push(`${x}{${I.map(V=>`${V}:${S}`).join(";")}}`)})}),ee&&Object.entries(ee).forEach(([C,R])=>{const E=Object.entries(R);E.sort(([O],[h])=>l[O]-l[h]),E.forEach(([O,h])=>{h.forEach(j=>{var re,oe;const x=z[O].find(_=>Array.isArray(_.values)?_.values.includes(j):typeof j==typeof _.values);if(!x)return;const I=o(O,j,+F,m,C),[S]=K[+F],k=((re=x.selector)==null?void 0:re.call(x,`.${S}-${C}:${S} .${I}`,""))??`.${S}-${C}:${S} .${I}`,H=Array.isArray(x.styleName)?x.styleName:[x.styleName??O],V=((oe=x.valueFormat)==null?void 0:oe.call(x,j,w.getVariableValue))??j;c.push(`${k}{${H.map(_=>`${_}:${V}`).join(";")}}`)})})})}),m!=="normal"&&c.push("}"),c),[v]);b.unshift(`:root{${w.generateVariables()}}`);const s=y();s.innerHTML=b.join(""),t=!1}e.flush=i;function n(){r={}}e.clear=n;function d(l,v,g,b,s="normal",c){if(v==null)return;const m=b.reduce((F,q)=>F+ie[q],0);r[s]?r[s][m]?r[s][m][l]||(r[s][m][l]=new Set):r[s][m]={[l]:new Set}:r[s]={[m]:{[l]:new Set}},c?(r[s][m].__parents?r[s][m].__parents[c]?r[s][m].__parents[c][l]||(r[s][m].__parents[c][l]=new Set):r[s][m].__parents[c]={[l]:new Set}:r[s][m].__parents={[c]:{[l]:new Set}},r[s][m].__parents[c][l].has(v)||(r[s][m].__parents[c][l].add(v),t=!0)):r[s][m][l].has(v)||(r[s][m][l].add(v),t=!0);const N=o(l,v,m,s,c);g.push(N)}function o(l,v,g,b,s){const c=K[g],m=`${b==="normal"?"":`${b}-`}${c.map(N=>`${N}-`).join("")}${s?`${s}-`:""}${l}-${v}`;return ne?m:be.getIdentity(m)}const f="crono-styles";function y(){let l=document.getElementById(f);return l||(l=document.createElement("style"),l.setAttribute("id",f),l.setAttribute("type","text/css"),document.head.insertBefore(l,document.head.firstChild)),l}})(T||(T={}));exports.StylesContext=void 0;(e=>{e.flush=T.flush,e.clear=T.clear})(exports.StylesContext||(exports.StylesContext={}));var Y;(e=>{function t(r,a,i){return w.setUserVariables(r),Object.entries(a).forEach(([n,d])=>{z[n]=d}),Object.entries(i).forEach(([n,d])=>{const o=z[n];z[n]=o?[...d,...o]:d}),{extendedProps:a,extendedPropTypes:i}}e.extend=t})(Y||(Y={}));const pe=Y;function L(e){const{children:t,theme:r}=e,[a,i]=p.useState(r),n=p.useMemo(()=>{var l;const d=(l=L.userThemes)==null?void 0:l[a];if(!d)return B;const{components:o,...f}=d,y=o??{};return Object.entries(f).forEach(([v,g])=>{y[v]=g}),Object.keys(y).forEach(v=>{y[v].clean&&v in B&&delete B[v]}),$.mergeDeep(B,y)},[a]);return ce.jsx(P.Provider,{value:{themeStyles:n,theme:a,setTheme:i},children:t})}(e=>{e.userThemes=void 0;function t(a){e.userThemes=a}e.setup=t;function r(){const{theme:a,setTheme:i}=p.useContext(P);return[a,i]}e.useTheme=r})(L||(L={}));const xe=L,we={selected:"aria-selected"};var J;(e=>{function t(r,a,i){r!==void 0&&r!=null&&(i[we[a]??a]=Array.isArray(r)?r[0]:r)}e.assignBooleanProp=t})(J||(J={}));const Ne=J;Array.prototype.removeBy||(Array.prototype.removeBy=function(e){return this.filter(e)});function Fe(e=null){const[t,r]=p.useState(!1),a=p.useRef(null);return p.useEffect(()=>{function i(d){const o=e??a.current;(o==null?void 0:o.contains(d.target))===!1&&r(!1)}function n(d){d.key==="Escape"&&r(!1)}return t&&(window.addEventListener("mousedown",i),window.addEventListener("keydown",n)),()=>{window.removeEventListener("mousedown",i),window.removeEventListener("keydown",n)}},[e,t]),[t,r,a]}function $e(){return p.useMemo(()=>{const e="crono-box";let t=document.getElementById(e);return t||(t=document.createElement("div"),t.id=e,document.body.appendChild(t)),t},[])}var Q;(e=>{function t(a){const i=Array.from(a.elements).reduce((n,d)=>{const o=d.name;return o&&(n[o]||(n[o]=[]),n[o].push(d)),n},{});return Object.entries(i).reduce((n,[d,o])=>{if(o.length===1){const f=o[0];r(n,d,f.type==="checkbox"||f.type==="radio"?f.checked:f.value)}else{const f=o.reduce((y,l)=>(l.type==="checkbox"||l.type==="radio"?l.checked&&y.push(l.value):y.push(l.value),y),[]);r(n,d,f)}return n},{})}e.getFormEntries=t;function r(a,i,n){if(i.includes(".")){const d=i.split(".");let o=a;d.forEach((f,y)=>{if(d.length>y+1){const l=f.match(/^(.+)\[(\d)\]$/);if(l){const[,v,g]=l;o[v]=o[v]||[],o[v][g]=o[v][g]||{},o=o[v][g]}else o[f]=o[f]||{},o=o[f]}else o[f]=n})}else a[i]=n}})(Q||(Q={}));const Ce=Q;exports.BoxExtends=pe;exports.BoxUtils=Ne;exports.FormUtils=Ce;exports.ObjectUtils=$;exports.Theme=xe;exports.Variables=w;exports.classNames=ae;exports.usePortalContainer=$e;exports.useStyles=he;exports.useVisibility=Fe;
7
+ `,g=Object.entries(r);g.sort(([c],[m])=>(U[c]??0)-(U[m]??0));const b=g.reduce((c,[m,N])=>(m!=="normal"&&c.push(`@media(min-width: ${U[m]}px){`),Object.entries(N).forEach(([F,q])=>{const{__parents:ee,...de}=q,te=Object.entries(de);te.sort(([C],[R])=>l[C]-l[R]),te.forEach(([C,R])=>{R.forEach(E=>{var I,H;const h=z[C].find(V=>Array.isArray(V.values)?V.values.includes(E):typeof E==typeof V.values);if(!h)return;const j=o(C,E,+F,m),D=K[+F].map(V=>Z[V]).join(""),x=((I=h.selector)==null?void 0:I.call(h,`.${j}`,D))??`.${j}${D}`,k=Array.isArray(h.styleName)?h.styleName:[h.styleName??C],S=((H=h.valueFormat)==null?void 0:H.call(h,E,w.getVariableValue))??E;c.push(`${x}{${k.map(V=>`${V}:${S}`).join(";")}}`)})}),ee&&Object.entries(ee).forEach(([C,R])=>{const E=Object.entries(R);E.sort(([O],[h])=>l[O]-l[h]),E.forEach(([O,h])=>{h.forEach(j=>{var re,oe;const x=z[O].find(_=>Array.isArray(_.values)?_.values.includes(j):typeof j==typeof _.values);if(!x)return;const k=o(O,j,+F,m,C),[S]=K[+F],I=((re=x.selector)==null?void 0:re.call(x,`.${S}-${C}:${S} .${k}`,""))??`.${S}-${C}:${S} .${k}`,H=Array.isArray(x.styleName)?x.styleName:[x.styleName??O],V=((oe=x.valueFormat)==null?void 0:oe.call(x,j,w.getVariableValue))??j;c.push(`${I}{${H.map(_=>`${_}:${V}`).join(";")}}`)})})})}),m!=="normal"&&c.push("}"),c),[v]);b.unshift(`:root{${w.generateVariables()}}`);const s=y();s.innerHTML=b.join(""),t=!1}e.flush=i;function n(){r={}}e.clear=n;function d(l,v,g,b,s="normal",c){if(v==null)return;const m=b.reduce((F,q)=>F+ie[q],0);r[s]?r[s][m]?r[s][m][l]||(r[s][m][l]=new Set):r[s][m]={[l]:new Set}:r[s]={[m]:{[l]:new Set}},c?(r[s][m].__parents?r[s][m].__parents[c]?r[s][m].__parents[c][l]||(r[s][m].__parents[c][l]=new Set):r[s][m].__parents[c]={[l]:new Set}:r[s][m].__parents={[c]:{[l]:new Set}},r[s][m].__parents[c][l].has(v)||(r[s][m].__parents[c][l].add(v),t=!0)):r[s][m][l].has(v)||(r[s][m][l].add(v),t=!0);const N=o(l,v,m,s,c);g.push(N)}function o(l,v,g,b,s){const c=K[g],m=`${b==="normal"?"":`${b}-`}${c.map(N=>`${N}-`).join("")}${s?`${s}-`:""}${l}-${v}`;return ne?m:be.getIdentity(m)}const f="crono-styles";function y(){let l=document.getElementById(f);return l||(l=document.createElement("style"),l.setAttribute("id",f),l.setAttribute("type","text/css"),document.head.insertBefore(l,document.head.firstChild)),l}})(T||(T={}));exports.StylesContext=void 0;(e=>{e.flush=T.flush,e.clear=T.clear})(exports.StylesContext||(exports.StylesContext={}));var Y;(e=>{function t(r,a,i){return w.setUserVariables(r),Object.entries(a).forEach(([n,d])=>{z[n]=d}),Object.entries(i).forEach(([n,d])=>{const o=z[n];z[n]=o?[...d,...o]:d}),{extendedProps:a,extendedPropTypes:i}}e.extend=t})(Y||(Y={}));const pe=Y;function L(e){const{children:t,theme:r}=e,[a,i]=p.useState(r),n=p.useMemo(()=>{var l;const d=(l=L.userThemes)==null?void 0:l[a];if(!d)return B;const{components:o,...f}=d,y=o??{};return Object.entries(f).forEach(([v,g])=>{y[v]=g}),Object.keys(y).forEach(v=>{y[v].clean&&v in B&&delete B[v]}),$.mergeDeep(B,y)},[a]);return ce.jsx(P.Provider,{value:{themeStyles:n,theme:a,setTheme:i},children:t})}(e=>{e.userThemes=void 0;function t(a){e.userThemes=a}e.setup=t;function r(){const{theme:a,setTheme:i}=p.useContext(P);return[a,i]}e.useTheme=r})(L||(L={}));const xe=L,we={selected:"aria-selected"};var J;(e=>{function t(r,a,i){r!==void 0&&r!=null&&(i[we[a]??a]=Array.isArray(r)?r[0]:r)}e.assignBooleanProp=t})(J||(J={}));const Ne=J;Array.prototype.removeBy||(Array.prototype.removeBy=function(e){return this.filter(e)});function Fe(e=null){const[t,r]=p.useState(!1),a=p.useRef(null);return p.useEffect(()=>{function i(d){const o=e??a.current;(o==null?void 0:o.contains(d.target))===!1&&r(!1)}function n(d){d.key==="Escape"&&r(!1)}return t&&(window.addEventListener("click",i),window.addEventListener("keydown",n)),()=>{window.removeEventListener("click",i),window.removeEventListener("keydown",n)}},[e,t]),[t,r,a]}function $e(){return p.useMemo(()=>{const e="crono-box";let t=document.getElementById(e);return t||(t=document.createElement("div"),t.id=e,document.body.appendChild(t)),t},[])}var Q;(e=>{function t(a){const i=Array.from(a.elements).reduce((n,d)=>{const o=d.name;return o&&(n[o]||(n[o]=[]),n[o].push(d)),n},{});return Object.entries(i).reduce((n,[d,o])=>{if(o.length===1){const f=o[0];r(n,d,f.type==="checkbox"||f.type==="radio"?f.checked:f.value)}else{const f=o.reduce((y,l)=>(l.type==="checkbox"||l.type==="radio"?l.checked&&y.push(l.value):y.push(l.value),y),[]);r(n,d,f)}return n},{})}e.getFormEntries=t;function r(a,i,n){if(i.includes(".")){const d=i.split(".");let o=a;d.forEach((f,y)=>{if(d.length>y+1){const l=f.match(/^(.+)\[(\d)\]$/);if(l){const[,v,g]=l;o[v]=o[v]||[],o[v][g]=o[v][g]||{},o=o[v][g]}else o[f]=o[f]||{},o=o[f]}else o[f]=n})}else a[i]=n}})(Q||(Q={}));const Ce=Q;exports.BoxExtends=pe;exports.BoxUtils=Ne;exports.FormUtils=Ce;exports.ObjectUtils=$;exports.Theme=xe;exports.Variables=w;exports.classNames=ae;exports.usePortalContainer=$e;exports.useStyles=he;exports.useVisibility=Fe;
package/core.mjs CHANGED
@@ -1977,10 +1977,10 @@ a,ul{all: unset;}
1977
1977
  const { __parents: ee, ...me } = D, te = Object.entries(me);
1978
1978
  te.sort(([F], [T]) => a[F] - a[T]), te.forEach(([F, T]) => {
1979
1979
  T.forEach((V) => {
1980
- var I, k;
1980
+ var k, I;
1981
1981
  const h = E[F].find(($) => Array.isArray($.values) ? $.values.includes(V) : typeof V == typeof $.values);
1982
1982
  if (!h) return;
1983
- const z = o(F, V, +x, m), K = W[+x].map(($) => Z[$]).join(""), p = ((I = h.selector) == null ? void 0 : I.call(h, `.${z}`, K)) ?? `.${z}${K}`, B = Array.isArray(h.styleName) ? h.styleName : [h.styleName ?? F], O = ((k = h.valueFormat) == null ? void 0 : k.call(h, V, N.getVariableValue)) ?? V;
1983
+ const z = o(F, V, +x, m), K = W[+x].map(($) => Z[$]).join(""), p = ((k = h.selector) == null ? void 0 : k.call(h, `.${z}`, K)) ?? `.${z}${K}`, B = Array.isArray(h.styleName) ? h.styleName : [h.styleName ?? F], O = ((I = h.valueFormat) == null ? void 0 : I.call(h, V, N.getVariableValue)) ?? V;
1984
1984
  c.push(`${p}{${B.map(($) => `${$}:${O}`).join(";")}}`);
1985
1985
  });
1986
1986
  }), ee && Object.entries(ee).forEach(([F, T]) => {
@@ -1990,8 +1990,8 @@ a,ul{all: unset;}
1990
1990
  var re, oe;
1991
1991
  const p = E[j].find((_) => Array.isArray(_.values) ? _.values.includes(z) : typeof z == typeof _.values);
1992
1992
  if (!p) return;
1993
- const B = o(j, z, +x, m, F), [O] = W[+x], I = ((re = p.selector) == null ? void 0 : re.call(p, `.${O}-${F}:${O} .${B}`, "")) ?? `.${O}-${F}:${O} .${B}`, k = Array.isArray(p.styleName) ? p.styleName : [p.styleName ?? j], $ = ((oe = p.valueFormat) == null ? void 0 : oe.call(p, z, N.getVariableValue)) ?? z;
1994
- c.push(`${I}{${k.map((_) => `${_}:${$}`).join(";")}}`);
1993
+ const B = o(j, z, +x, m, F), [O] = W[+x], k = ((re = p.selector) == null ? void 0 : re.call(p, `.${O}-${F}:${O} .${B}`, "")) ?? `.${O}-${F}:${O} .${B}`, I = Array.isArray(p.styleName) ? p.styleName : [p.styleName ?? j], $ = ((oe = p.valueFormat) == null ? void 0 : oe.call(p, z, N.getVariableValue)) ?? z;
1994
+ c.push(`${k}{${I.map((_) => `${_}:${$}`).join(";")}}`);
1995
1995
  });
1996
1996
  });
1997
1997
  });
@@ -2091,8 +2091,8 @@ function Se(e = null) {
2091
2091
  function n(d) {
2092
2092
  d.key === "Escape" && r(!1);
2093
2093
  }
2094
- return t && (window.addEventListener("mousedown", i), window.addEventListener("keydown", n)), () => {
2095
- window.removeEventListener("mousedown", i), window.removeEventListener("keydown", n);
2094
+ return t && (window.addEventListener("click", i), window.addEventListener("keydown", n)), () => {
2095
+ window.removeEventListener("click", i), window.removeEventListener("keydown", n);
2096
2096
  };
2097
2097
  }, [e, t]), [t, r, l];
2098
2098
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "type": "module",
5
5
  "main": "./box.cjs",
6
6
  "module": "./box.mjs",