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