wimui 0.46.0 → 0.47.1

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,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),r=require("../../../icon/chevron-right.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("../../../hooks/useMergedRef.cjs"),o=require("../Table/Table.cjs"),s=require("./layoutPivot.cjs"),c=require("./pivot-table.module.cjs");let l=require("react");l=e.__toESM(l,1);let u=require("classnames");u=e.__toESM(u,1);let d=require("react/jsx-runtime");var f=40,ee=8,te=30,p=(e,t=[])=>{for(let n of e)n.children?.length&&(t.push(n.key),p(n.children,t));return t},m=l.default.forwardRef(({rows:e,columns:m,getValue:h,rowAxisLabel:g,caption:_,expandedValues:v,defaultExpandedValues:ne,onExpandedChange:re,maxHeight:ie,stickyHeader:y=!1,stickyRowHeaders:ae=!1,virtualized:b=!1,columnSubtotals:x=!1,totalRow:S=!1,totalColumn:C=!1,labels:oe,className:se,...w},ce)=>{let{t:le}=t.useWimTranslation(`components`),T=l.default.useId(),E=oe?.total??le(`pivottable.total`),D=(0,l.useMemo)(()=>s.layoutPivotColumns(m,{subtotals:x,total:C}),[m,x,C]),[ue,de]=(0,l.useState)(()=>ne??p(e)),O=v??ue,k=(0,l.useMemo)(()=>new Set(O),[O]),fe=(0,l.useCallback)(e=>{let t=k.has(e)?O.filter(t=>t!==e):[...O,e];v===void 0&&de(t),re?.(t)},[O,k,v,re]),A=(0,l.useMemo)(()=>s.layoutPivotRows(e,e=>k.has(e)),[e,k]),j=(0,l.useMemo)(()=>p(e).length>0,[e]),M=g!=null&&g!==!1,N=`${T}corner`,pe=e=>`${T}c${e}`,P=e=>`${T}r${e}`,F=`${T}total`,I=(0,l.useMemo)(()=>D.columns.map(e=>e.headerIds.map(e=>`${T}c${e}`).join(` `)),[D,T]),L=l.default.useRef(null),R=l.default.useRef(null),[z,me]=l.default.useState(!1),[he,ge]=l.default.useState(!0);l.default.useLayoutEffect(()=>{let e=L.current,t=R.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=()=>{me(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight);let n=t.rows[0]?.cells[0];ge(!n||n.offsetWidth<=e.clientWidth/2)};n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let _e=a.useMergedRef(ce,R),B=ae&&he,V=l.default.useRef([]),[ve,ye]=(0,l.useState)([]),H=D.depth;l.default.useLayoutEffect(()=>{if(!y)return;let e=V.current.slice(0,H),t=()=>{let t=0,n=e.map(e=>{let n=t;return t+=e?.getBoundingClientRect().height??0,n});ye(e=>e.length===n.length&&e.every((e,t)=>e===n[t])?e:n)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return e.forEach(e=>e&&n.observe(e)),()=>n.disconnect()},[y,H]);let U=l.default.useRef(null),[W,be]=(0,l.useState)(0),[G,xe]=(0,l.useState)(null),[K,q]=(0,l.useState)(null),[J,Se]=(0,l.useState)([]),Ce=l.default.useRef(0),Y=(0,l.useCallback)(()=>{let e=L.current,t=U.current,n=R.current;if(!e||!t||!n)return;let r=t.querySelector(`tr[data-row-index]`)?.getBoundingClientRect().height??0;r>0&&be(e=>Math.abs(e-r)<.01?e:r);let i={scrollTop:e.scrollTop,height:e.clientHeight,bodyOffset:t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop};xe(e=>e&&e.scrollTop===i.scrollTop&&e.height===i.height&&e.bodyOffset===i.bodyOffset?e:i);let a=Array.from(n.querySelectorAll(`thead [data-column-index]`)).reduce((e,t)=>(e[Number(t.dataset.columnIndex)]=t.getBoundingClientRect().width,e),[]),o=Ce.current!==e.clientWidth;Ce.current=e.clientWidth,Se(e=>{let t=o?[]:e,n=a.map((e,n)=>(e||0)>(t[n]??0)+.01?e:t[n]??0);return n.length===e.length&&n.every((t,n)=>t===e[n])?e:n})},[]),X=A.length,we=D.columns.length;l.default.useLayoutEffect(()=>{if(!b||(Y(),typeof ResizeObserver>`u`))return;let e=new ResizeObserver(Y);return L.current&&e.observe(L.current),()=>e.disconnect()},[b,Y,X,we]);let Te=(0,l.useMemo)(()=>new Map(A.map((e,t)=>[e.key,t])),[A]),Ee=(0,l.useMemo)(()=>b?G?s.pivotRowWindow({rowCount:X,rowHeight:W||f,scrollTop:G.scrollTop,viewportHeight:G.height,bodyOffset:G.bodyOffset,overscan:ee,keep:K===null?null:Te.get(K)??null}):s.pivotRowWindow({rowCount:X,rowHeight:f,scrollTop:0,viewportHeight:Math.min(X,te)*f,bodyOffset:0,overscan:0}):null,[b,G,X,W,K,Te]),De=(0,l.useMemo)(()=>new Map(D.columns.map((e,t)=>[e.headerIds[e.headerIds.length-1],t])),[D]),Z=e=>b&&e!==void 0?{"data-column-index":e,style:J[e]?{minWidth:J[e]}:void 0}:null,Q=(e,t=!1)=>y?{top:Math.floor(ve[e]??0),zIndex:10+H-e+ +!!t}:void 0,Oe=`${T}caption`,$=_?{"aria-labelledby":Oe}:w[`aria-label`]?{"aria-label":w[`aria-label`]}:w[`aria-labelledby`]?{"aria-labelledby":w[`aria-labelledby`]}:null,ke=(e,t)=>{let a=b?P(t):[...e.ancestors.map(P),P(t)].join(` `),s=[...M?[N]:[],...b?[]:e.ancestors.map(P)].join(` `);return(0,d.jsxs)(o.Table.Row,{className:(0,u.default)(e.hasChildren&&c.default.groupRow),"data-row-index":b?t:void 0,"data-row-key":b?e.key:void 0,"aria-rowindex":b?H+t+1:void 0,children:[(0,d.jsxs)(`th`,{id:P(t),scope:`row`,headers:s||void 0,className:(0,u.default)(c.default.rowHeader,B&&c.default.stickyLeft),style:{"--wim-pivot-table-depth":e.depth},children:[b&&e.ancestors.length>0&&(0,d.jsx)(n.VisuallyHidden,{children:e.ancestors.map(e=>(0,d.jsxs)(l.default.Fragment,{children:[A[e].node.label,`, `]},e))}),e.hasChildren?(0,d.jsxs)(`button`,{type:`button`,className:c.default.toggle,"aria-expanded":e.expanded,onClick:()=>fe(e.key),children:[(0,d.jsx)(`span`,{className:(0,u.default)(c.default.chevron,e.expanded&&c.default.open),"aria-hidden":`true`,children:(0,d.jsx)(i.Icon,{component:r.default,size:`sm`})}),e.node.label]}):(0,d.jsx)(`span`,{className:(0,u.default)(j&&c.default.leafLabel),children:e.node.label})]}),D.columns.map((t,n)=>(0,d.jsx)(o.Table.Cell,{headers:`${a} ${I[n]}`,className:(0,u.default)(c.default.value,t.kind!==`leaf`&&c.default.aggregate,t.startsGroup&&!(B&&n===0)&&c.default.groupStart),children:h(e.key,t.key)},n))]},e.key)};return(0,d.jsx)(`div`,{ref:L,className:c.default.scroller,style:ie===void 0?void 0:{maxHeight:ie},tabIndex:z?0:void 0,onScroll:b?Y:void 0,...z&&$?{role:`region`,...$}:null,children:(0,d.jsxs)(`table`,{ref:_e,className:(0,u.default)(`wim-pivot-table`,c.default.root,se),"aria-rowcount":b?H+X+ +!!S:void 0,...w,children:[_&&(0,d.jsx)(`caption`,{id:Oe,className:c.default.caption,children:_}),(0,d.jsx)(`colgroup`,{}),D.groupSpans.map((e,t)=>(0,d.jsx)(`colgroup`,{span:e},t)),(0,d.jsx)(o.Table.Header,{children:D.headerRows.map((e,t)=>(0,d.jsxs)(`tr`,{"aria-rowindex":b?t+1:void 0,ref:e=>{V.current[t]=e},children:[t===0&&(M?(0,d.jsx)(`th`,{id:N,scope:`col`,rowSpan:D.depth,className:(0,u.default)(c.default.columnHeader,c.default.corner,c.default.bottom,y&&c.default.stickyTop,B&&c.default.stickyLeft),...Z(0),style:{...Q(0,!0),...Z(0)?.style},children:g}):(0,d.jsx)(`td`,{rowSpan:D.depth,className:(0,u.default)(c.default.columnHeader,c.default.bottom,y&&c.default.stickyTop,B&&c.default.stickyLeft),...Z(0),style:{...Q(0,!0),...Z(0)?.style}})),e.map((e,n)=>(0,d.jsx)(`th`,{id:pe(e.id),scope:e.kind===`group`&&e.topLevel?`colgroup`:`col`,colSpan:e.colSpan>1?e.colSpan:void 0,rowSpan:e.rowSpan>1?e.rowSpan:void 0,className:(0,u.default)(c.default.columnHeader,e.kind===`group`&&c.default.group,e.reachesBottom&&c.default.bottom,e.startsGroup&&!(B&&n===0)&&c.default.groupStart,y&&c.default.stickyTop),...e.reachesBottom?Z((De.get(e.id)??-1)+1):null,style:{...Q(t),...e.reachesBottom?Z((De.get(e.id)??-1)+1)?.style:null},children:e.kind===`group`||e.kind===`leaf`?e.node?.label:E},e.id))]},t))}),(0,d.jsx)(o.Table.Body,{ref:U,onFocus:b?e=>{let t=e.target.closest(`tr`)?.dataset.rowKey;t!==void 0&&q(t)}:void 0,onBlur:b?e=>{e.currentTarget.contains(e.relatedTarget)||q(null)}:void 0,children:(Ee??[{kind:`rows`,from:0,to:X}]).map((e,t)=>e.kind===`gap`?(0,d.jsx)(`tr`,{"aria-hidden":`true`,className:c.default.gap,children:(0,d.jsx)(`td`,{colSpan:we+1,style:{height:e.count*(W||f)}})},`gap-${t}`):A.slice(e.from,e.to).map((t,n)=>ke(t,e.from+n)))}),S&&(0,d.jsx)(o.Table.Footer,{children:(0,d.jsxs)(o.Table.Row,{className:c.default.totalRow,"aria-rowindex":b?H+X+1:void 0,children:[(0,d.jsx)(`th`,{id:F,scope:`row`,headers:M?N:void 0,className:(0,u.default)(c.default.rowHeader,B&&c.default.stickyLeft),children:(0,d.jsx)(`span`,{className:(0,u.default)(j&&c.default.leafLabel),children:E})}),D.columns.map((e,t)=>(0,d.jsx)(o.Table.Cell,{headers:`${F} ${I[t]}`,className:(0,u.default)(c.default.value,e.startsGroup&&!(B&&t===0)&&c.default.groupStart),children:h(null,e.key)},t))]})})]})})});m.displayName=`PivotTable`,exports.PivotTable=m;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),r=require("../../../icon/chevron-right.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("../../../hooks/useMergedRef.cjs"),o=require("../Table/Table.cjs"),s=require("./layoutPivot.cjs"),c=require("./pivot-table.module.cjs");let l=require("react");l=e.__toESM(l,1);let u=require("classnames");u=e.__toESM(u,1);let d=require("react/jsx-runtime");var f=40,ee=8,te=30,p=`corner`,m=(e,t=[])=>{for(let n of e)n.children?.length&&(t.push(n.key),m(n.children,t));return t},ne=(e,t,n,r)=>{let[i,a]=(0,l.useState)(()=>n??m(e)),o=t??i,s=(0,l.useMemo)(()=>new Set(o),[o]);return[s,(0,l.useCallback)(e=>{let n=s.has(e)?o.filter(t=>t!==e):[...o,e];t===void 0&&a(n),r?.(n)},[o,s,t,r])]},h=l.default.forwardRef(({rows:e,columns:h,getValue:g,rowAxisLabel:_,caption:v,expandedRowValues:re,defaultExpandedRowValues:ie,onExpandedRowChange:ae,expandedColumnValues:oe,defaultExpandedColumnValues:se,onExpandedColumnChange:ce,maxHeight:y,stickyHeader:b=!1,stickyRowHeaders:le=!1,virtualized:x=!1,columnSubtotals:S=!1,totalRow:C=!1,totalColumn:ue=!1,labels:de,className:fe,...w},pe)=>{let{t:me}=t.useWimTranslation(`components`),T=l.default.useId(),E=de?.total??me(`pivottable.total`),[D,he]=ne(e,re,ie,ae),[O,ge]=ne(h,oe,se,ce),k=(0,l.useMemo)(()=>s.layoutPivotColumns(h,{subtotals:S,total:ue,isExpanded:e=>O.has(e)}),[h,S,ue,O]),A=(0,l.useMemo)(()=>s.layoutPivotRows(e,e=>D.has(e)),[e,D]),j=(0,l.useMemo)(()=>m(e).length>0,[e]),M=(0,l.useMemo)(()=>m(h).length>0,[h]),N=_!=null&&_!==!1,P=`${T}corner`,_e=e=>`${T}c${e}`,F=e=>`${T}r${e}`,I=`${T}total`,L=(0,l.useMemo)(()=>k.columns.map(e=>e.headerIds.map(e=>`${T}c${e}`).join(` `)),[k,T]),R=l.default.useRef(null),z=l.default.useRef(null),[B,ve]=l.default.useState(!1),[ye,be]=l.default.useState(!0);l.default.useLayoutEffect(()=>{let e=R.current,t=z.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=()=>{ve(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight);let n=t.rows[0]?.cells[0];be(!n||n.offsetWidth<=e.clientWidth/2)};n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[]);let xe=a.useMergedRef(pe,z),V=le&&ye,H=l.default.useRef([]),[Se,Ce]=(0,l.useState)([]),U=k.depth;l.default.useLayoutEffect(()=>{if(!b)return;let e=H.current.slice(0,U),t=()=>{let t=0,n=e.map(e=>{let n=t;return t+=e?.getBoundingClientRect().height??0,n});Ce(e=>e.length===n.length&&e.every((e,t)=>e===n[t])?e:n)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return e.forEach(e=>e&&n.observe(e)),()=>n.disconnect()},[b,U]);let W=l.default.useRef(null),[G,we]=(0,l.useState)(0),[K,Te]=(0,l.useState)(null),[q,Ee]=(0,l.useState)(null),[De,Oe]=(0,l.useState)({}),J=l.default.useRef(0),Y=(0,l.useCallback)(()=>{let e=R.current,t=W.current,n=z.current;if(!e||!t||!n)return;let r=t.querySelector(`tr[data-row-index]`)?.getBoundingClientRect().height??0;r>0&&we(e=>Math.abs(e-r)<.01?e:r);let i={scrollTop:e.scrollTop,height:e.clientHeight,bodyOffset:t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop};Te(e=>e&&e.scrollTop===i.scrollTop&&e.height===i.height&&e.bodyOffset===i.bodyOffset?e:i);let a=Array.from(n.querySelectorAll(`thead [data-column-key]`)).map(e=>[e.dataset.columnKey,e.getBoundingClientRect().width]),o=J.current!==e.clientWidth;J.current=e.clientWidth,Oe(e=>{let t=o?{}:{...e};for(let[e,n]of a)(n||0)>(t[e]??0)+.01&&(t[e]=n);let n=Object.keys(t);return n.length===Object.keys(e).length&&n.every(n=>t[n]===e[n])?e:t})},[]),X=A.length,ke=k.columns.length,Z=(0,l.useMemo)(()=>k.columns.map(e=>`${e.kind}:${e.key??``}`),[k]),Ae=Z.join(`|`);l.default.useLayoutEffect(()=>{if(!x||(Y(),typeof ResizeObserver>`u`))return;let e=new ResizeObserver(Y);return R.current&&e.observe(R.current),()=>e.disconnect()},[x,Y,X,Ae]);let je=(0,l.useMemo)(()=>new Map(A.map((e,t)=>[e.key,t])),[A]),Me=(0,l.useMemo)(()=>x?K?s.pivotRowWindow({rowCount:X,rowHeight:G||f,scrollTop:K.scrollTop,viewportHeight:K.height,bodyOffset:K.bodyOffset,overscan:ee,keep:q===null?null:je.get(q)??null}):s.pivotRowWindow({rowCount:X,rowHeight:f,scrollTop:0,viewportHeight:Math.min(X,te)*f,bodyOffset:0,overscan:0}):null,[x,K,X,G,q,je]),Ne=(0,l.useMemo)(()=>new Map(k.columns.map((e,t)=>[e.headerIds[e.headerIds.length-1],Z[t]])),[k,Z]),Q=e=>x&&e!==void 0?{"data-column-key":e,style:De[e]?{minWidth:De[e]}:void 0}:null,$=(e,t=!1)=>b?{top:Math.floor(Se[e]??0),zIndex:10+U-e+ +!!t}:void 0,Pe=`${T}caption`,Fe=v?{"aria-labelledby":Pe}:w[`aria-label`]?{"aria-label":w[`aria-label`]}:w[`aria-labelledby`]?{"aria-labelledby":w[`aria-labelledby`]}:null,Ie=(e,t)=>{let a=x?F(t):[...e.ancestors.map(F),F(t)].join(` `),s=[...N?[P]:[],...x?[]:e.ancestors.map(F)].join(` `);return(0,d.jsxs)(o.Table.Row,{className:(0,u.default)(e.hasChildren&&c.default.groupRow),"data-row-index":x?t:void 0,"data-row-key":x?e.key:void 0,"aria-rowindex":x?U+t+1:void 0,children:[(0,d.jsxs)(`th`,{id:F(t),scope:`row`,headers:s||void 0,className:(0,u.default)(c.default.rowHeader,V&&c.default.stickyLeft),style:{"--wim-pivot-table-depth":e.depth},children:[x&&e.ancestors.length>0&&(0,d.jsx)(n.VisuallyHidden,{children:e.ancestors.map(e=>(0,d.jsxs)(l.default.Fragment,{children:[A[e].node.label,`, `]},e))}),e.hasChildren?(0,d.jsxs)(`button`,{type:`button`,className:c.default.toggle,"aria-expanded":e.expanded,onClick:()=>he(e.key),children:[(0,d.jsx)(`span`,{className:(0,u.default)(c.default.chevron,e.expanded&&c.default.open),"aria-hidden":`true`,children:(0,d.jsx)(i.Icon,{component:r.default,size:`sm`})}),e.node.label]}):(0,d.jsx)(`span`,{className:(0,u.default)(j&&c.default.leafLabel),children:e.node.label})]}),k.columns.map((t,n)=>(0,d.jsx)(o.Table.Cell,{headers:`${a} ${L[n]}`,className:(0,u.default)(c.default.value,t.kind!==`leaf`&&c.default.aggregate,t.startsGroup&&!(V&&n===0)&&c.default.groupStart),children:g(e.key,t.key)},n))]},e.key)};return(0,d.jsx)(`div`,{ref:R,className:c.default.scroller,style:y===void 0?void 0:{maxHeight:y},tabIndex:B?0:void 0,onScroll:x?Y:void 0,...B&&Fe?{role:`region`,...Fe}:null,children:(0,d.jsxs)(`table`,{ref:xe,className:(0,u.default)(`wim-pivot-table`,c.default.root,fe),"aria-rowcount":x?U+X+ +!!C:void 0,...w,children:[v&&(0,d.jsx)(`caption`,{id:Pe,className:c.default.caption,children:v}),(0,d.jsx)(`colgroup`,{}),k.groupSpans.map((e,t)=>(0,d.jsx)(`colgroup`,{span:e},t)),(0,d.jsx)(o.Table.Header,{children:k.headerRows.map((e,t)=>(0,d.jsxs)(`tr`,{"aria-rowindex":x?t+1:void 0,ref:e=>{H.current[t]=e},children:[t===0&&(N?(0,d.jsx)(`th`,{id:P,scope:`col`,rowSpan:k.depth,className:(0,u.default)(c.default.columnHeader,c.default.corner,c.default.bottom,b&&c.default.stickyTop,V&&c.default.stickyLeft),...Q(p),style:{...$(0,!0),...Q(p)?.style},children:(0,d.jsx)(`span`,{className:(0,u.default)(M&&c.default.columnLeafLabel),children:_})}):(0,d.jsx)(`td`,{rowSpan:k.depth,className:(0,u.default)(c.default.columnHeader,c.default.bottom,b&&c.default.stickyTop,V&&c.default.stickyLeft),...Q(p),style:{...$(0,!0),...Q(p)?.style}})),e.map((e,n)=>(0,d.jsx)(`th`,{id:_e(e.id),scope:e.kind===`group`&&e.topLevel?`colgroup`:`col`,colSpan:e.colSpan>1?e.colSpan:void 0,rowSpan:e.rowSpan>1?e.rowSpan:void 0,className:(0,u.default)(c.default.columnHeader,e.kind===`group`&&e.expanded&&c.default.group,e.reachesBottom&&c.default.bottom,e.startsGroup&&!(V&&n===0)&&c.default.groupStart,b&&c.default.stickyTop),...e.reachesBottom?Q(Ne.get(e.id)):null,style:{...$(t),...e.reachesBottom?Q(Ne.get(e.id))?.style:null},children:e.kind===`group`?(0,d.jsxs)(`button`,{type:`button`,className:(0,u.default)(c.default.toggle,c.default.columnToggle),"aria-expanded":e.expanded,onClick:()=>ge(e.key),children:[(0,d.jsx)(`span`,{className:(0,u.default)(c.default.chevron,e.expanded&&c.default.open),"aria-hidden":`true`,children:(0,d.jsx)(i.Icon,{component:r.default,size:`sm`})}),e.node?.label]}):(0,d.jsx)(`span`,{className:(0,u.default)(M&&c.default.columnLeafLabel),children:e.kind===`leaf`?e.node?.label:E})},`${e.kind}:${e.key??``}`))]},t))}),(0,d.jsx)(o.Table.Body,{ref:W,onFocus:x?e=>{let t=e.target.closest(`tr`)?.dataset.rowKey;t!==void 0&&Ee(t)}:void 0,onBlur:x?e=>{e.currentTarget.contains(e.relatedTarget)||Ee(null)}:void 0,children:(Me??[{kind:`rows`,from:0,to:X}]).map((e,t)=>e.kind===`gap`?(0,d.jsx)(`tr`,{"aria-hidden":`true`,className:c.default.gap,children:(0,d.jsx)(`td`,{colSpan:ke+1,style:{height:e.count*(G||f)}})},`gap-${t}`):A.slice(e.from,e.to).map((t,n)=>Ie(t,e.from+n)))}),C&&(0,d.jsx)(o.Table.Footer,{children:(0,d.jsxs)(o.Table.Row,{className:c.default.totalRow,"aria-rowindex":x?U+X+1:void 0,children:[(0,d.jsx)(`th`,{id:I,scope:`row`,headers:N?P:void 0,className:(0,u.default)(c.default.rowHeader,V&&c.default.stickyLeft),children:(0,d.jsx)(`span`,{className:(0,u.default)(j&&c.default.leafLabel),children:E})}),k.columns.map((e,t)=>(0,d.jsx)(o.Table.Cell,{headers:`${I} ${L[t]}`,className:(0,u.default)(c.default.value,e.startsGroup&&!(V&&t===0)&&c.default.groupStart),children:g(null,e.key)},t))]})})]})})});h.displayName=`PivotTable`,exports.PivotTable=h;
@@ -3,8 +3,8 @@ export type PivotTableAxisNode = {
3
3
  /** Unique within its axis. Passed back to `getValue`. */
4
4
  key: string;
5
5
  /**
6
- * Heading shown for this row or column. On the row axis the label of a group is drawn
7
- * inside its expand / collapse button, so it must not contain links or other controls.
6
+ * Heading shown for this row or column. The label of a group is drawn inside its
7
+ * expand / collapse button, so it must not contain links or other controls.
8
8
  */
9
9
  label: React.ReactNode;
10
10
  /** Nested headings. A node with children is a group; its own value is the subtotal. */
@@ -22,7 +22,9 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
22
22
  /**
23
23
  * Returns the content of one cell. The component does not aggregate: a group key asks
24
24
  * for that group's subtotal and `null` asks for the grand total of that axis. Return
25
- * `null` or `undefined` for an empty cell.
25
+ * `null` or `undefined` for an empty cell. Group keys are asked on both axes: a row
26
+ * group for its own row, a column group for its subtotal column and for the single
27
+ * column it leaves when it is collapsed.
26
28
  */
27
29
  getValue: (rowKey: string | null, columnKey: string | null) => React.ReactNode;
28
30
  /** Heading of the row axis, shown in the top-left corner. */
@@ -33,11 +35,20 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
33
35
  * Keys of the expanded row groups (controlled). A group that is not listed shows only
34
36
  * its own row, which carries its subtotal.
35
37
  */
36
- expandedValues?: string[];
38
+ expandedRowValues?: string[];
37
39
  /** Row groups expanded on first render (uncontrolled). Defaults to every group. */
38
- defaultExpandedValues?: string[];
39
- /** Called with the new list of expanded row groups when a group is expanded or collapsed. */
40
- onExpandedChange?: (values: string[]) => void;
40
+ defaultExpandedRowValues?: string[];
41
+ /** Called with the new list of expanded row groups when a row group is expanded or collapsed. */
42
+ onExpandedRowChange?: (values: string[]) => void;
43
+ /**
44
+ * Keys of the expanded column groups (controlled). A group that is not listed shows a
45
+ * single column, which carries its subtotal: `getValue` receives the group's key.
46
+ */
47
+ expandedColumnValues?: string[];
48
+ /** Column groups expanded on first render (uncontrolled). Defaults to every group. */
49
+ defaultExpandedColumnValues?: string[];
50
+ /** Called with the new list of expanded column groups when a column group is expanded or collapsed. */
51
+ onExpandedColumnChange?: (values: string[]) => void;
41
52
  /**
42
53
  * Maximum height of the table (a number is px). Past it the table scrolls vertically
43
54
  * inside its own box.
@@ -60,7 +71,7 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
60
71
  * `maxHeight`. Rows must all have the same height, so keep labels and values on one line.
61
72
  */
62
73
  virtualized?: boolean;
63
- /** Adds a subtotal column after the columns of each column group. */
74
+ /** Adds a subtotal column after the columns of each expanded column group. */
64
75
  columnSubtotals?: boolean;
65
76
  /** Adds a grand total row at the bottom. */
66
77
  totalRow?: boolean;
@@ -74,9 +85,10 @@ export type PivotTableProps = Omit<React.ComponentPropsWithoutRef<"table">, "chi
74
85
  * headings, subtotals and grand totals. It only draws: grouping and summing stay with the
75
86
  * caller, who answers `getValue(rowKey, columnKey)` for every cell.
76
87
  *
77
- * Row groups can be collapsed to their subtotal row with the button in their heading
78
- * (Enter or Space). The button is named by the group label, so the heading still reads as
79
- * the plain label when a cell announces it.
88
+ * Groups on both axes can be collapsed with the button in their heading (Enter or Space):
89
+ * a row group to its subtotal row, a column group to a single subtotal column. The button
90
+ * is named by the group label, so the heading still reads as the plain label when a cell
91
+ * announces it.
80
92
  *
81
93
  * Every cell lists the headings it belongs to in its `headers` attribute, so a screen
82
94
  * reader announces the full row path and column path of a value.
@@ -96,7 +108,9 @@ export declare const PivotTable: React.ForwardRefExoticComponent<Omit<Omit<React
96
108
  /**
97
109
  * Returns the content of one cell. The component does not aggregate: a group key asks
98
110
  * for that group's subtotal and `null` asks for the grand total of that axis. Return
99
- * `null` or `undefined` for an empty cell.
111
+ * `null` or `undefined` for an empty cell. Group keys are asked on both axes: a row
112
+ * group for its own row, a column group for its subtotal column and for the single
113
+ * column it leaves when it is collapsed.
100
114
  */
101
115
  getValue: (rowKey: string | null, columnKey: string | null) => React.ReactNode;
102
116
  /** Heading of the row axis, shown in the top-left corner. */
@@ -107,11 +121,20 @@ export declare const PivotTable: React.ForwardRefExoticComponent<Omit<Omit<React
107
121
  * Keys of the expanded row groups (controlled). A group that is not listed shows only
108
122
  * its own row, which carries its subtotal.
109
123
  */
110
- expandedValues?: string[];
124
+ expandedRowValues?: string[];
111
125
  /** Row groups expanded on first render (uncontrolled). Defaults to every group. */
112
- defaultExpandedValues?: string[];
113
- /** Called with the new list of expanded row groups when a group is expanded or collapsed. */
114
- onExpandedChange?: (values: string[]) => void;
126
+ defaultExpandedRowValues?: string[];
127
+ /** Called with the new list of expanded row groups when a row group is expanded or collapsed. */
128
+ onExpandedRowChange?: (values: string[]) => void;
129
+ /**
130
+ * Keys of the expanded column groups (controlled). A group that is not listed shows a
131
+ * single column, which carries its subtotal: `getValue` receives the group's key.
132
+ */
133
+ expandedColumnValues?: string[];
134
+ /** Column groups expanded on first render (uncontrolled). Defaults to every group. */
135
+ defaultExpandedColumnValues?: string[];
136
+ /** Called with the new list of expanded column groups when a column group is expanded or collapsed. */
137
+ onExpandedColumnChange?: (values: string[]) => void;
115
138
  /**
116
139
  * Maximum height of the table (a number is px). Past it the table scrolls vertically
117
140
  * inside its own box.
@@ -134,7 +157,7 @@ export declare const PivotTable: React.ForwardRefExoticComponent<Omit<Omit<React
134
157
  * `maxHeight`. Rows must all have the same height, so keep labels and values on one line.
135
158
  */
136
159
  virtualized?: boolean;
137
- /** Adds a subtotal column after the columns of each column group. */
160
+ /** Adds a subtotal column after the columns of each expanded column group. */
138
161
  columnSubtotals?: boolean;
139
162
  /** Adds a grand total row at the bottom. */
140
163
  totalRow?: boolean;
@@ -7,253 +7,279 @@ import { useMergedRef as i } from "../../../hooks/useMergedRef.js";
7
7
  import { Table as a } from "../Table/Table.js";
8
8
  import { layoutPivotColumns as o, layoutPivotRows as s, pivotRowWindow as ee } from "./layoutPivot.js";
9
9
  import c from "./pivot-table.module.js";
10
- import l, { useCallback as te, useMemo as u, useState as d } from "react";
11
- import f from "classnames";
12
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
10
+ import l, { useCallback as u, useMemo as d, useState as f } from "react";
11
+ import p from "classnames";
12
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
13
13
  //#region src/components/data-display/PivotTable/PivotTable.tsx
14
- var h = 40, ne = 8, re = 30, g = (e, t = []) => {
15
- for (let n of e) n.children?.length && (t.push(n.key), g(n.children, t));
14
+ var g = 40, te = 8, ne = 30, _ = "corner", v = (e, t = []) => {
15
+ for (let n of e) n.children?.length && (t.push(n.key), v(n.children, t));
16
16
  return t;
17
- }, _ = l.forwardRef(({ rows: _, columns: ie, getValue: ae, rowAxisLabel: v, caption: y, expandedValues: b, defaultExpandedValues: oe, onExpandedChange: x, maxHeight: S, stickyHeader: C = !1, stickyRowHeaders: se = !1, virtualized: w = !1, columnSubtotals: T = !1, totalRow: E = !1, totalColumn: ce = !1, labels: le, className: ue, ...D }, de) => {
18
- let { t: fe } = e("components"), O = l.useId(), pe = le?.total ?? fe("pivottable.total"), k = u(() => o(ie, {
19
- subtotals: T,
20
- total: ce
21
- }), [
22
- ie,
23
- T,
24
- ce
25
- ]), [me, he] = d(() => oe ?? g(_)), A = b ?? me, j = u(() => new Set(A), [A]), ge = te((e) => {
26
- let t = j.has(e) ? A.filter((t) => t !== e) : [...A, e];
27
- b === void 0 && he(t), x?.(t);
17
+ }, re = (e, t, n, r) => {
18
+ let [i, a] = f(() => n ?? v(e)), o = t ?? i, s = d(() => new Set(o), [o]);
19
+ return [s, u((e) => {
20
+ let n = s.has(e) ? o.filter((t) => t !== e) : [...o, e];
21
+ t === void 0 && a(n), r?.(n);
28
22
  }, [
29
- A,
30
- j,
23
+ o,
24
+ s,
25
+ t,
26
+ r
27
+ ])];
28
+ }, y = l.forwardRef(({ rows: y, columns: b, getValue: x, rowAxisLabel: S, caption: C, expandedRowValues: ie, defaultExpandedRowValues: ae, onExpandedRowChange: oe, expandedColumnValues: se, defaultExpandedColumnValues: ce, onExpandedColumnChange: le, maxHeight: ue, stickyHeader: w = !1, stickyRowHeaders: de = !1, virtualized: T = !1, columnSubtotals: fe = !1, totalRow: pe = !1, totalColumn: me = !1, labels: he, className: ge, ...E }, _e) => {
29
+ let { t: ve } = e("components"), D = l.useId(), O = he?.total ?? ve("pivottable.total"), [k, ye] = re(y, ie, ae, oe), [A, be] = re(b, se, ce, le), j = d(() => o(b, {
30
+ subtotals: fe,
31
+ total: me,
32
+ isExpanded: (e) => A.has(e)
33
+ }), [
31
34
  b,
32
- x
33
- ]), M = u(() => s(_, (e) => j.has(e)), [_, j]), N = u(() => g(_).length > 0, [_]), P = v != null && v !== !1, F = `${O}corner`, _e = (e) => `${O}c${e}`, I = (e) => `${O}r${e}`, L = `${O}total`, R = u(() => k.columns.map((e) => e.headerIds.map((e) => `${O}c${e}`).join(" ")), [k, O]), z = l.useRef(null), B = l.useRef(null), [V, ve] = l.useState(!1), [ye, be] = l.useState(!0);
35
+ fe,
36
+ me,
37
+ A
38
+ ]), M = d(() => s(y, (e) => k.has(e)), [y, k]), N = d(() => v(y).length > 0, [y]), P = d(() => v(b).length > 0, [b]), F = S != null && S !== !1, I = `${D}corner`, xe = (e) => `${D}c${e}`, L = (e) => `${D}r${e}`, R = `${D}total`, z = d(() => j.columns.map((e) => e.headerIds.map((e) => `${D}c${e}`).join(" ")), [j, D]), B = l.useRef(null), V = l.useRef(null), [Se, Ce] = l.useState(!1), [we, Te] = l.useState(!0);
34
39
  l.useLayoutEffect(() => {
35
- let e = z.current, t = B.current;
40
+ let e = B.current, t = V.current;
36
41
  if (!e || !t || typeof ResizeObserver > "u") return;
37
42
  let n = () => {
38
- ve(e.scrollWidth > e.clientWidth || e.scrollHeight > e.clientHeight);
43
+ Ce(e.scrollWidth > e.clientWidth || e.scrollHeight > e.clientHeight);
39
44
  let n = t.rows[0]?.cells[0];
40
- be(!n || n.offsetWidth <= e.clientWidth / 2);
45
+ Te(!n || n.offsetWidth <= e.clientWidth / 2);
41
46
  };
42
47
  n();
43
48
  let r = new ResizeObserver(n);
44
49
  return r.observe(e), r.observe(t), () => r.disconnect();
45
50
  }, []);
46
- let xe = i(de, B), H = se && ye, U = l.useRef([]), [Se, Ce] = d([]), W = k.depth;
51
+ let Ee = i(_e, V), H = de && we, De = l.useRef([]), [Oe, ke] = f([]), U = j.depth;
47
52
  l.useLayoutEffect(() => {
48
- if (!C) return;
49
- let e = U.current.slice(0, W), t = () => {
53
+ if (!w) return;
54
+ let e = De.current.slice(0, U), t = () => {
50
55
  let t = 0, n = e.map((e) => {
51
56
  let n = t;
52
57
  return t += e?.getBoundingClientRect().height ?? 0, n;
53
58
  });
54
- Ce((e) => e.length === n.length && e.every((e, t) => e === n[t]) ? e : n);
59
+ ke((e) => e.length === n.length && e.every((e, t) => e === n[t]) ? e : n);
55
60
  };
56
61
  if (t(), typeof ResizeObserver > "u") return;
57
62
  let n = new ResizeObserver(t);
58
63
  return e.forEach((e) => e && n.observe(e)), () => n.disconnect();
59
- }, [C, W]);
60
- let we = l.useRef(null), [G, Te] = d(0), [K, Ee] = d(null), [q, De] = d(null), [Oe, ke] = d([]), Ae = l.useRef(0), J = te(() => {
61
- let e = z.current, t = we.current, n = B.current;
64
+ }, [w, U]);
65
+ let Ae = l.useRef(null), [W, je] = f(0), [G, Me] = f(null), [K, Ne] = f(null), [Pe, Fe] = f({}), Ie = l.useRef(0), q = u(() => {
66
+ let e = B.current, t = Ae.current, n = V.current;
62
67
  if (!e || !t || !n) return;
63
68
  let r = t.querySelector("tr[data-row-index]")?.getBoundingClientRect().height ?? 0;
64
- r > 0 && Te((e) => Math.abs(e - r) < .01 ? e : r);
69
+ r > 0 && je((e) => Math.abs(e - r) < .01 ? e : r);
65
70
  let i = {
66
71
  scrollTop: e.scrollTop,
67
72
  height: e.clientHeight,
68
73
  bodyOffset: t.getBoundingClientRect().top - e.getBoundingClientRect().top + e.scrollTop
69
74
  };
70
- Ee((e) => e && e.scrollTop === i.scrollTop && e.height === i.height && e.bodyOffset === i.bodyOffset ? e : i);
71
- let a = Array.from(n.querySelectorAll("thead [data-column-index]")).reduce((e, t) => (e[Number(t.dataset.columnIndex)] = t.getBoundingClientRect().width, e), []), o = Ae.current !== e.clientWidth;
72
- Ae.current = e.clientWidth, ke((e) => {
73
- let t = o ? [] : e, n = a.map((e, n) => (e || 0) > (t[n] ?? 0) + .01 ? e : t[n] ?? 0);
74
- return n.length === e.length && n.every((t, n) => t === e[n]) ? e : n;
75
+ Me((e) => e && e.scrollTop === i.scrollTop && e.height === i.height && e.bodyOffset === i.bodyOffset ? e : i);
76
+ let a = Array.from(n.querySelectorAll("thead [data-column-key]")).map((e) => [e.dataset.columnKey, e.getBoundingClientRect().width]), o = Ie.current !== e.clientWidth;
77
+ Ie.current = e.clientWidth, Fe((e) => {
78
+ let t = o ? {} : { ...e };
79
+ for (let [e, n] of a) (n || 0) > (t[e] ?? 0) + .01 && (t[e] = n);
80
+ let n = Object.keys(t);
81
+ return n.length === Object.keys(e).length && n.every((n) => t[n] === e[n]) ? e : t;
75
82
  });
76
- }, []), Y = M.length, X = k.columns.length;
83
+ }, []), J = M.length, Le = j.columns.length, Y = d(() => j.columns.map((e) => `${e.kind}:${e.key ?? ""}`), [j]), Re = Y.join("|");
77
84
  l.useLayoutEffect(() => {
78
- if (!w || (J(), typeof ResizeObserver > "u")) return;
79
- let e = new ResizeObserver(J);
80
- return z.current && e.observe(z.current), () => e.disconnect();
85
+ if (!T || (q(), typeof ResizeObserver > "u")) return;
86
+ let e = new ResizeObserver(q);
87
+ return B.current && e.observe(B.current), () => e.disconnect();
81
88
  }, [
82
- w,
89
+ T,
90
+ q,
83
91
  J,
84
- Y,
85
- X
92
+ Re
86
93
  ]);
87
- let je = u(() => new Map(M.map((e, t) => [e.key, t])), [M]), Me = u(() => w ? ee(K ? {
88
- rowCount: Y,
89
- rowHeight: G || h,
90
- scrollTop: K.scrollTop,
91
- viewportHeight: K.height,
92
- bodyOffset: K.bodyOffset,
93
- overscan: ne,
94
- keep: q === null ? null : je.get(q) ?? null
94
+ let ze = d(() => new Map(M.map((e, t) => [e.key, t])), [M]), Be = d(() => T ? ee(G ? {
95
+ rowCount: J,
96
+ rowHeight: W || g,
97
+ scrollTop: G.scrollTop,
98
+ viewportHeight: G.height,
99
+ bodyOffset: G.bodyOffset,
100
+ overscan: te,
101
+ keep: K === null ? null : ze.get(K) ?? null
95
102
  } : {
96
- rowCount: Y,
97
- rowHeight: h,
103
+ rowCount: J,
104
+ rowHeight: g,
98
105
  scrollTop: 0,
99
- viewportHeight: Math.min(Y, re) * h,
106
+ viewportHeight: Math.min(J, ne) * g,
100
107
  bodyOffset: 0,
101
108
  overscan: 0
102
109
  }) : null, [
103
- w,
104
- K,
105
- Y,
110
+ T,
106
111
  G,
107
- q,
108
- je
109
- ]), Ne = u(() => new Map(k.columns.map((e, t) => [e.headerIds[e.headerIds.length - 1], t])), [k]), Z = (e) => w && e !== void 0 ? {
110
- "data-column-index": e,
111
- style: Oe[e] ? { minWidth: Oe[e] } : void 0
112
- } : null, Q = (e, t = !1) => C ? {
113
- top: Math.floor(Se[e] ?? 0),
114
- zIndex: 10 + W - e + +!!t
115
- } : void 0, Pe = `${O}caption`, $ = y ? { "aria-labelledby": Pe } : D["aria-label"] ? { "aria-label": D["aria-label"] } : D["aria-labelledby"] ? { "aria-labelledby": D["aria-labelledby"] } : null, Fe = (e, i) => {
116
- let o = w ? I(i) : [...e.ancestors.map(I), I(i)].join(" "), s = [...P ? [F] : [], ...w ? [] : e.ancestors.map(I)].join(" ");
117
- return /* @__PURE__ */ m(a.Row, {
118
- className: f(e.hasChildren && c.groupRow),
119
- "data-row-index": w ? i : void 0,
120
- "data-row-key": w ? e.key : void 0,
121
- "aria-rowindex": w ? W + i + 1 : void 0,
122
- children: [/* @__PURE__ */ m("th", {
123
- id: I(i),
112
+ J,
113
+ W,
114
+ K,
115
+ ze
116
+ ]), X = d(() => new Map(j.columns.map((e, t) => [e.headerIds[e.headerIds.length - 1], Y[t]])), [j, Y]), Z = (e) => T && e !== void 0 ? {
117
+ "data-column-key": e,
118
+ style: Pe[e] ? { minWidth: Pe[e] } : void 0
119
+ } : null, Q = (e, t = !1) => w ? {
120
+ top: Math.floor(Oe[e] ?? 0),
121
+ zIndex: 10 + U - e + +!!t
122
+ } : void 0, Ve = `${D}caption`, $ = C ? { "aria-labelledby": Ve } : E["aria-label"] ? { "aria-label": E["aria-label"] } : E["aria-labelledby"] ? { "aria-labelledby": E["aria-labelledby"] } : null, He = (e, i) => {
123
+ let o = T ? L(i) : [...e.ancestors.map(L), L(i)].join(" "), s = [...F ? [I] : [], ...T ? [] : e.ancestors.map(L)].join(" ");
124
+ return /* @__PURE__ */ h(a.Row, {
125
+ className: p(e.hasChildren && c.groupRow),
126
+ "data-row-index": T ? i : void 0,
127
+ "data-row-key": T ? e.key : void 0,
128
+ "aria-rowindex": T ? U + i + 1 : void 0,
129
+ children: [/* @__PURE__ */ h("th", {
130
+ id: L(i),
124
131
  scope: "row",
125
132
  headers: s || void 0,
126
- className: f(c.rowHeader, H && c.stickyLeft),
133
+ className: p(c.rowHeader, H && c.stickyLeft),
127
134
  style: { "--wim-pivot-table-depth": e.depth },
128
- children: [w && e.ancestors.length > 0 && /* @__PURE__ */ p(t, { children: e.ancestors.map((e) => /* @__PURE__ */ m(l.Fragment, { children: [M[e].node.label, ", "] }, e)) }), e.hasChildren ? /* @__PURE__ */ m("button", {
135
+ children: [T && e.ancestors.length > 0 && /* @__PURE__ */ m(t, { children: e.ancestors.map((e) => /* @__PURE__ */ h(l.Fragment, { children: [M[e].node.label, ", "] }, e)) }), e.hasChildren ? /* @__PURE__ */ h("button", {
129
136
  type: "button",
130
137
  className: c.toggle,
131
138
  "aria-expanded": e.expanded,
132
- onClick: () => ge(e.key),
133
- children: [/* @__PURE__ */ p("span", {
134
- className: f(c.chevron, e.expanded && c.open),
139
+ onClick: () => ye(e.key),
140
+ children: [/* @__PURE__ */ m("span", {
141
+ className: p(c.chevron, e.expanded && c.open),
135
142
  "aria-hidden": "true",
136
- children: /* @__PURE__ */ p(r, {
143
+ children: /* @__PURE__ */ m(r, {
137
144
  component: n,
138
145
  size: "sm"
139
146
  })
140
147
  }), e.node.label]
141
- }) : /* @__PURE__ */ p("span", {
142
- className: f(N && c.leafLabel),
148
+ }) : /* @__PURE__ */ m("span", {
149
+ className: p(N && c.leafLabel),
143
150
  children: e.node.label
144
151
  })]
145
- }), k.columns.map((t, n) => /* @__PURE__ */ p(a.Cell, {
146
- headers: `${o} ${R[n]}`,
147
- className: f(c.value, t.kind !== "leaf" && c.aggregate, t.startsGroup && !(H && n === 0) && c.groupStart),
148
- children: ae(e.key, t.key)
152
+ }), j.columns.map((t, n) => /* @__PURE__ */ m(a.Cell, {
153
+ headers: `${o} ${z[n]}`,
154
+ className: p(c.value, t.kind !== "leaf" && c.aggregate, t.startsGroup && !(H && n === 0) && c.groupStart),
155
+ children: x(e.key, t.key)
149
156
  }, n))]
150
157
  }, e.key);
151
158
  };
152
- return /* @__PURE__ */ p("div", {
153
- ref: z,
159
+ return /* @__PURE__ */ m("div", {
160
+ ref: B,
154
161
  className: c.scroller,
155
- style: S === void 0 ? void 0 : { maxHeight: S },
156
- tabIndex: V ? 0 : void 0,
157
- onScroll: w ? J : void 0,
158
- ...V && $ ? {
162
+ style: ue === void 0 ? void 0 : { maxHeight: ue },
163
+ tabIndex: Se ? 0 : void 0,
164
+ onScroll: T ? q : void 0,
165
+ ...Se && $ ? {
159
166
  role: "region",
160
167
  ...$
161
168
  } : null,
162
- children: /* @__PURE__ */ m("table", {
163
- ref: xe,
164
- className: f("wim-pivot-table", c.root, ue),
165
- "aria-rowcount": w ? W + Y + +!!E : void 0,
166
- ...D,
169
+ children: /* @__PURE__ */ h("table", {
170
+ ref: Ee,
171
+ className: p("wim-pivot-table", c.root, ge),
172
+ "aria-rowcount": T ? U + J + +!!pe : void 0,
173
+ ...E,
167
174
  children: [
168
- y && /* @__PURE__ */ p("caption", {
169
- id: Pe,
175
+ C && /* @__PURE__ */ m("caption", {
176
+ id: Ve,
170
177
  className: c.caption,
171
- children: y
178
+ children: C
172
179
  }),
173
- /* @__PURE__ */ p("colgroup", {}),
174
- k.groupSpans.map((e, t) => /* @__PURE__ */ p("colgroup", { span: e }, t)),
175
- /* @__PURE__ */ p(a.Header, { children: k.headerRows.map((e, t) => /* @__PURE__ */ m("tr", {
176
- "aria-rowindex": w ? t + 1 : void 0,
180
+ /* @__PURE__ */ m("colgroup", {}),
181
+ j.groupSpans.map((e, t) => /* @__PURE__ */ m("colgroup", { span: e }, t)),
182
+ /* @__PURE__ */ m(a.Header, { children: j.headerRows.map((e, t) => /* @__PURE__ */ h("tr", {
183
+ "aria-rowindex": T ? t + 1 : void 0,
177
184
  ref: (e) => {
178
- U.current[t] = e;
185
+ De.current[t] = e;
179
186
  },
180
- children: [t === 0 && (P ? /* @__PURE__ */ p("th", {
181
- id: F,
187
+ children: [t === 0 && (F ? /* @__PURE__ */ m("th", {
188
+ id: I,
182
189
  scope: "col",
183
- rowSpan: k.depth,
184
- className: f(c.columnHeader, c.corner, c.bottom, C && c.stickyTop, H && c.stickyLeft),
185
- ...Z(0),
190
+ rowSpan: j.depth,
191
+ className: p(c.columnHeader, c.corner, c.bottom, w && c.stickyTop, H && c.stickyLeft),
192
+ ...Z(_),
186
193
  style: {
187
194
  ...Q(0, !0),
188
- ...Z(0)?.style
195
+ ...Z(_)?.style
189
196
  },
190
- children: v
191
- }) : /* @__PURE__ */ p("td", {
192
- rowSpan: k.depth,
193
- className: f(c.columnHeader, c.bottom, C && c.stickyTop, H && c.stickyLeft),
194
- ...Z(0),
197
+ children: /* @__PURE__ */ m("span", {
198
+ className: p(P && c.columnLeafLabel),
199
+ children: S
200
+ })
201
+ }) : /* @__PURE__ */ m("td", {
202
+ rowSpan: j.depth,
203
+ className: p(c.columnHeader, c.bottom, w && c.stickyTop, H && c.stickyLeft),
204
+ ...Z(_),
195
205
  style: {
196
206
  ...Q(0, !0),
197
- ...Z(0)?.style
207
+ ...Z(_)?.style
198
208
  }
199
- })), e.map((e, n) => /* @__PURE__ */ p("th", {
200
- id: _e(e.id),
209
+ })), e.map((e, i) => /* @__PURE__ */ m("th", {
210
+ id: xe(e.id),
201
211
  scope: e.kind === "group" && e.topLevel ? "colgroup" : "col",
202
212
  colSpan: e.colSpan > 1 ? e.colSpan : void 0,
203
213
  rowSpan: e.rowSpan > 1 ? e.rowSpan : void 0,
204
- className: f(c.columnHeader, e.kind === "group" && c.group, e.reachesBottom && c.bottom, e.startsGroup && !(H && n === 0) && c.groupStart, C && c.stickyTop),
205
- ...e.reachesBottom ? Z((Ne.get(e.id) ?? -1) + 1) : null,
214
+ className: p(c.columnHeader, e.kind === "group" && e.expanded && c.group, e.reachesBottom && c.bottom, e.startsGroup && !(H && i === 0) && c.groupStart, w && c.stickyTop),
215
+ ...e.reachesBottom ? Z(X.get(e.id)) : null,
206
216
  style: {
207
217
  ...Q(t),
208
- ...e.reachesBottom ? Z((Ne.get(e.id) ?? -1) + 1)?.style : null
218
+ ...e.reachesBottom ? Z(X.get(e.id))?.style : null
209
219
  },
210
- children: e.kind === "group" || e.kind === "leaf" ? e.node?.label : pe
211
- }, e.id))]
220
+ children: e.kind === "group" ? /* @__PURE__ */ h("button", {
221
+ type: "button",
222
+ className: p(c.toggle, c.columnToggle),
223
+ "aria-expanded": e.expanded,
224
+ onClick: () => be(e.key),
225
+ children: [/* @__PURE__ */ m("span", {
226
+ className: p(c.chevron, e.expanded && c.open),
227
+ "aria-hidden": "true",
228
+ children: /* @__PURE__ */ m(r, {
229
+ component: n,
230
+ size: "sm"
231
+ })
232
+ }), e.node?.label]
233
+ }) : /* @__PURE__ */ m("span", {
234
+ className: p(P && c.columnLeafLabel),
235
+ children: e.kind === "leaf" ? e.node?.label : O
236
+ })
237
+ }, `${e.kind}:${e.key ?? ""}`))]
212
238
  }, t)) }),
213
- /* @__PURE__ */ p(a.Body, {
214
- ref: we,
215
- onFocus: w ? (e) => {
239
+ /* @__PURE__ */ m(a.Body, {
240
+ ref: Ae,
241
+ onFocus: T ? (e) => {
216
242
  let t = e.target.closest("tr")?.dataset.rowKey;
217
- t !== void 0 && De(t);
243
+ t !== void 0 && Ne(t);
218
244
  } : void 0,
219
- onBlur: w ? (e) => {
220
- e.currentTarget.contains(e.relatedTarget) || De(null);
245
+ onBlur: T ? (e) => {
246
+ e.currentTarget.contains(e.relatedTarget) || Ne(null);
221
247
  } : void 0,
222
- children: (Me ?? [{
248
+ children: (Be ?? [{
223
249
  kind: "rows",
224
250
  from: 0,
225
- to: Y
226
- }]).map((e, t) => e.kind === "gap" ? /* @__PURE__ */ p("tr", {
251
+ to: J
252
+ }]).map((e, t) => e.kind === "gap" ? /* @__PURE__ */ m("tr", {
227
253
  "aria-hidden": "true",
228
254
  className: c.gap,
229
- children: /* @__PURE__ */ p("td", {
230
- colSpan: X + 1,
231
- style: { height: e.count * (G || h) }
255
+ children: /* @__PURE__ */ m("td", {
256
+ colSpan: Le + 1,
257
+ style: { height: e.count * (W || g) }
232
258
  })
233
- }, `gap-${t}`) : M.slice(e.from, e.to).map((t, n) => Fe(t, e.from + n)))
259
+ }, `gap-${t}`) : M.slice(e.from, e.to).map((t, n) => He(t, e.from + n)))
234
260
  }),
235
- E && /* @__PURE__ */ p(a.Footer, { children: /* @__PURE__ */ m(a.Row, {
261
+ pe && /* @__PURE__ */ m(a.Footer, { children: /* @__PURE__ */ h(a.Row, {
236
262
  className: c.totalRow,
237
- "aria-rowindex": w ? W + Y + 1 : void 0,
238
- children: [/* @__PURE__ */ p("th", {
239
- id: L,
263
+ "aria-rowindex": T ? U + J + 1 : void 0,
264
+ children: [/* @__PURE__ */ m("th", {
265
+ id: R,
240
266
  scope: "row",
241
- headers: P ? F : void 0,
242
- className: f(c.rowHeader, H && c.stickyLeft),
243
- children: /* @__PURE__ */ p("span", {
244
- className: f(N && c.leafLabel),
245
- children: pe
267
+ headers: F ? I : void 0,
268
+ className: p(c.rowHeader, H && c.stickyLeft),
269
+ children: /* @__PURE__ */ m("span", {
270
+ className: p(N && c.leafLabel),
271
+ children: O
246
272
  })
247
- }), k.columns.map((e, t) => /* @__PURE__ */ p(a.Cell, {
248
- headers: `${L} ${R[t]}`,
249
- className: f(c.value, e.startsGroup && !(H && t === 0) && c.groupStart),
250
- children: ae(null, e.key)
273
+ }), j.columns.map((e, t) => /* @__PURE__ */ m(a.Cell, {
274
+ headers: `${R} ${z[t]}`,
275
+ className: p(c.value, e.startsGroup && !(H && t === 0) && c.groupStart),
276
+ children: x(null, e.key)
251
277
  }, t))]
252
278
  }) })
253
279
  ]
254
280
  })
255
281
  });
256
282
  });
257
- _.displayName = "PivotTable";
283
+ y.displayName = "PivotTable";
258
284
  //#endregion
259
- export { _ as PivotTable };
285
+ export { y as PivotTable };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e=e=>!!e.children?.length,t=n=>n.reduce((n,r)=>Math.max(n,1+(e(r)?t(r.children):0)),0);function n(n,r={}){let i=Math.max(1,t(n)),a=Array.from({length:i},()=>[]),o=[],s=[],c=0,l=(e,t,n,r,s,l)=>{let u=c++,d=e?.key??null;a[n].push({id:u,key:d,node:e,kind:t,colSpan:1,rowSpan:i-n,reachesBottom:!0,startsGroup:l,topLevel:s}),o.push({key:d,kind:t,headerIds:[...r,u],startsGroup:l})},u=(t,n,i,o)=>{let s=n===0;if(!e(t))return l(t,`leaf`,n,i,s,o),1;let d={id:c++,key:t.key,node:t,kind:`group`,colSpan:0,rowSpan:1,reachesBottom:!1,startsGroup:o,topLevel:s};a[n].push(d);let f=[...i,d.id],p=0;return t.children.forEach((e,t)=>{p+=u(e,n+1,f,o&&t===0)}),r.subtotals&&(l(t,`subtotal`,n+1,f,!1,!1),p+=1),d.colSpan=p,p};for(let e of n)s.push(u(e,0,[],!0));return r.total&&(l(null,`total`,0,[],!0,!0),s.push(1)),{headerRows:a,columns:o,depth:i,groupSpans:s}}function r(t,n=()=>!0){let r=[],i=(t,a,o)=>{for(let s of t){let t=r.length,c=e(s),l=c&&n(s.key);r.push({key:s.key,node:s,depth:a,hasChildren:c,expanded:l,ancestors:o}),l&&i(s.children,a+1,[...o,t])}};return i(t,0,[]),r}function i(e){let{rowCount:t,rowHeight:n,scrollTop:r,viewportHeight:i,bodyOffset:a,overscan:o,keep:s}=e;if(t<=0)return[];if(n<=0)return[{kind:`rows`,from:0,to:t}];let c=(e,t,n)=>Math.min(Math.max(e,t),n),l=r-a,u=c(Math.floor(l/n)-o,0,t-1),d=c(Math.ceil((l+i)/n)+o,u+1,t),f=[],p=e=>{e>0&&f.push({kind:`gap`,count:e})},m=s!=null&&s>=0&&s<t?s:null;return m!==null&&m<u?(p(m),f.push({kind:`rows`,from:m,to:m+1}),p(u-m-1)):p(u),f.push({kind:`rows`,from:u,to:d}),m!==null&&m>=d?(p(m-d),f.push({kind:`rows`,from:m,to:m+1}),p(t-m-1)):p(t-d),f}exports.layoutPivotColumns=n,exports.layoutPivotRows=r,exports.pivotRowWindow=i;
2
+ var e=e=>!!e.children?.length,t=(n,r)=>n.reduce((n,i)=>Math.max(n,1+(e(i)&&r(i.key)?t(i.children,r):0)),0);function n(n,r={}){let i=r.isExpanded??(()=>!0),a=Math.max(1,t(n,i)),o=Array.from({length:a},()=>[]),s=[],c=[],l=0,u=(e,t,n,r,i,c)=>{let u=l++,d=e?.key??null;o[n].push({id:u,key:d,node:e,kind:t,colSpan:1,rowSpan:a-n,reachesBottom:!0,startsGroup:c,topLevel:i,expanded:!1}),s.push({key:d,kind:t,headerIds:[...r,u],startsGroup:c})},d=(t,n,c,f)=>{let p=n===0;if(!e(t))return u(t,`leaf`,n,c,p,f),1;if(!i(t.key)){let e=l++;return o[n].push({id:e,key:t.key,node:t,kind:`group`,colSpan:1,rowSpan:a-n,reachesBottom:!0,startsGroup:f,topLevel:p,expanded:!1}),s.push({key:t.key,kind:`subtotal`,headerIds:[...c,e],startsGroup:f}),1}let m={id:l++,key:t.key,node:t,kind:`group`,colSpan:0,rowSpan:1,reachesBottom:!1,startsGroup:f,topLevel:p,expanded:!0};o[n].push(m);let h=[...c,m.id],g=0;return t.children.forEach((e,t)=>{g+=d(e,n+1,h,f&&t===0)}),r.subtotals&&(u(t,`subtotal`,n+1,h,!1,!1),g+=1),m.colSpan=g,g};for(let e of n)c.push(d(e,0,[],!0));return r.total&&(u(null,`total`,0,[],!0,!0),c.push(1)),{headerRows:o,columns:s,depth:a,groupSpans:c}}function r(t,n=()=>!0){let r=[],i=(t,a,o)=>{for(let s of t){let t=r.length,c=e(s),l=c&&n(s.key);r.push({key:s.key,node:s,depth:a,hasChildren:c,expanded:l,ancestors:o}),l&&i(s.children,a+1,[...o,t])}};return i(t,0,[]),r}function i(e){let{rowCount:t,rowHeight:n,scrollTop:r,viewportHeight:i,bodyOffset:a,overscan:o,keep:s}=e;if(t<=0)return[];if(n<=0)return[{kind:`rows`,from:0,to:t}];let c=(e,t,n)=>Math.min(Math.max(e,t),n),l=r-a,u=c(Math.floor(l/n)-o,0,t-1),d=c(Math.ceil((l+i)/n)+o,u+1,t),f=[],p=e=>{e>0&&f.push({kind:`gap`,count:e})},m=s!=null&&s>=0&&s<t?s:null;return m!==null&&m<u?(p(m),f.push({kind:`rows`,from:m,to:m+1}),p(u-m-1)):p(u),f.push({kind:`rows`,from:u,to:d}),m!==null&&m>=d?(p(m-d),f.push({kind:`rows`,from:m,to:m+1}),p(t-m-1)):p(t-d),f}exports.layoutPivotColumns=n,exports.layoutPivotRows=r,exports.pivotRowWindow=i;