3 lines
12 KiB
JavaScript
3 lines
12 KiB
JavaScript
import{r as k,j as i,s as y,t as b,v as p,T as xe}from"./index-TNj5auBr.js";import{a as pe}from"./EmptyState-DGz1kDMS.js";const A=120;function he(e){let t=0,n=0;const l=[];for(const c of e){const a=c.width;if((a==null?void 0:a.type)==="pixel")n+=a.value;else{const d=(a==null?void 0:a.value)??1,u=a!=null?a.minWidth??A:0;t+=d,l.push({key:c.key,proportion:d,minWidth:u})}}let s=0;if(t>0)for(const c of l){const a=c.minWidth*t/c.proportion;a>s&&(s=a)}const r=n+s,o=new Map;for(const c of e){const a=c.width,d={};if((a==null?void 0:a.type)==="pixel")d.width=`${a.value}px`,d.minWidth=`${a.value}px`;else{const u=(a==null?void 0:a.value)??1;if(t>0&&(d.width=`${u/t*100}%`),a!=null){const m=a.minWidth??A;d.minWidth=`${m}px`}}o.set(c.key,{style:d})}return{columns:o,tableMinWidth:r}}function ye(e=1,t){return{type:"proportional",value:e,minWidth:(t==null?void 0:t.minWidth)??A}}function tt(e){return{type:"pixel",value:e}}function F(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function be(e,t){const n=e[t];return n==null?"":n instanceof Date?n.toISOString():typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):""}function ke(e){return e==null?0:typeof e=="string"?e.length:typeof e=="number"||typeof e=="boolean"?String(e).length:0}function ge(e){if(e==null||typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")return 0;const t=String(e);let n=0,l=0;for(let s=0;s<=t.length;s++)s===t.length||t[s]===" "||t[s]===" "||t[s]===`
|
|
`?(l>n&&(n=l),l=0):l++;return n}const we=60,$e=8;function Ce(e){if(e.length===0)return[];const t=e[0],n=Object.keys(t),l=e.slice(0,Math.min(5,e.length));return n.map(r=>{const o=F(r).length;let c=o,a=o;for(const d of l){const u=ke(d[r]);u>c&&(c=u);const m=ge(d[r]);m>a&&(a=m)}return{key:r,headerLen:o,maxContentLen:c,maxWordLen:a}}).map(r=>{const o=r.maxContentLen<=6?1:r.maxContentLen<=15?2:3,c=Math.max(Math.max(r.headerLen,r.maxWordLen)*$e,we);return{key:r.key,header:F(r.key),width:ye(o,{minWidth:c})}})}const Y={x139im0d:"x139im0d",$$css:!0},X={cell:{kVQacm:"xb3r6kr",kg5iWk:"xlyipyv",khDVqt:"xuxw1ft",ks0D6T:"x1m189uc",$$css:!0}},Te={cell:{kVQacm:"xb3r6kr",kHjlTd:"x1mzt3pk",kTgw9:"x13faqbe",ks0D6T:"x1m189uc",$$css:!0}},Q={compact:{kZCmMZ:"x5uh4xs",kwRFfy:"xbg7gas",$$css:!0},balanced:{kZCmMZ:"x9bi00s",kwRFfy:"xpilulx",$$css:!0},spacious:{kZCmMZ:"x18c6q21",kwRFfy:"x1wzlfcn",$$css:!0}},N=k.createContext(null);N.displayName="TableContext";const Re={row:{kWkggS:"x1dnou9g","--table-row-overlay":"x1rht92",$$css:!0}},je={row:{kWkggS:"xe9uy6x","--table-row-overlay":"x1pkcbo2",k1ekBW:"x15406qy",kIyJzY:"xuedmi6",kAMwcw:"xlr8y92",$$css:!0}},Pe={row:{kWkggS:"x1dnou9g xe9uy6x","--table-row-overlay":"x1rht92 x1pkcbo2",k1ekBW:"x15406qy",kIyJzY:"xuedmi6",kAMwcw:"xlr8y92",$$css:!0}};function Z({children:e,xstyle:t,ref:n,isHeaderRow:l=!1,...s}){const r=k.use(N);if(!r)return i.jsx("tr",{ref:n,...s,...y(p("table-row"),b(Y,t)),children:e});const o=[];return l||(r.isStriped&&r.hasHover?o.push(Pe.row):r.isStriped?o.push(Re.row):r.hasHover&&o.push(je.row)),r.dividers==="rows"||r.dividers,t&&o.push(...t),i.jsx("tr",{ref:n,...s,...y(p("table-row"),b(Y,...o)),children:e})}Z.displayName="TableRow";function We(e,t,n){const l=[];return(e.dividers==="rows"||e.dividers==="grid")&&l.push(t),(e.dividers==="columns"||e.dividers==="grid")&&l.push(n),l}function K(e,t){return t?Array.isArray(t)?[...e,...t]:[...e,t]:e}function J(){return k.use(N)}const Se={compact:{k8WAf4:"xu0wf1k",kg3NbH:"xf314gf",kGuDYH:"xjm74w1",kB7OPa:"x9f619",$$css:!0},balanced:{k8WAf4:"xce4md1",kg3NbH:"xrrkdod",kGuDYH:"xjm74w1",kB7OPa:"x9f619",$$css:!0},spacious:{k8WAf4:"x8o8v82",kg3NbH:"x1pzlopt",kGuDYH:"xjm74w1",kB7OPa:"x9f619",$$css:!0}},ve={cell:{kt9PQ7:"x92x3c3 x1wp2rvj",kfdmCh:"x1q0q8m5",kL6WhQ:"xw8gpjh",$$css:!0}},He={cell:{kWqL5O:"x1pcaw5z x1lpyac",kSWEuD:"x32b0ac",k26BEO:"xtgwc6q",$$css:!0}},Me={middle:{kXLuUW:"xxymvpz",$$css:!0},top:{kXLuUW:"x16dsc37",$$css:!0},bottom:{kXLuUW:"x3ajldb",$$css:!0}};function ee({children:e,xstyle:t,ref:n,className:l,style:s,...r}){const o=J();if(!o)return i.jsx("td",{ref:n,...r,...y(p("table-cell"),b(t),l,s),children:e});const c=[Se[o.density],o.textOverflow==="truncate"?X.cell:Te.cell,Q[o.density],Me[o.verticalAlign],...We(o,ve.cell,He.cell)];return i.jsx("td",{ref:n,...r,...y(p("table-cell"),b(...K(c,t)),l,s),children:e})}ee.displayName="TableCell";const Ne={compact:{k8WAf4:"xu0wf1k",kg3NbH:"xf314gf",kGuDYH:"xcr08ib",kB7OPa:"x9f619",$$css:!0},balanced:{k8WAf4:"xce4md1",kg3NbH:"xrrkdod",kGuDYH:"xcr08ib",kB7OPa:"x9f619",$$css:!0},spacious:{k8WAf4:"x8o8v82",kg3NbH:"x1pzlopt",kGuDYH:"xcr08ib",kB7OPa:"x9f619",$$css:!0}},Le={cell:{k63SB2:"x2mo6ok",kMwMTN:"xv1l7n4",k9WMMc:"x1yc453h",$$css:!0}},Oe={cell:{kt9PQ7:"x92x3c3",kfdmCh:"x1q0q8m5",kL6WhQ:"xw8gpjh",$$css:!0}},Be={cell:{kWqL5O:"x1pcaw5z x1lpyac",kSWEuD:"x32b0ac",k26BEO:"xtgwc6q",$$css:!0}};function te({children:e,xstyle:t,ref:n,className:l,style:s,...r}){const o=J();if(!o)return i.jsx("th",{ref:n,...r,...y(p("table-header-cell"),b(t),l,s),children:e});const c=[Le.cell,Ne[o.density],Oe.cell,X.cell,Q[o.density]];return(o.dividers==="columns"||o.dividers==="grid")&&c.push(Be.cell),i.jsx("th",{ref:n,...r,...y(p("table-header-cell"),b(...K(c,t)),l,s),children:e})}te.displayName="TableHeaderCell";function ne({ref:e,children:t,xstyle:n}){return i.jsx("thead",{ref:e,...y(p("table-header"),b(n)),children:t})}ne.displayName="TableHeader";function re({ref:e,children:t,xstyle:n}){return i.jsx("tbody",{ref:e,...y(p("table-body"),b(n)),children:t})}re.displayName="TableBody";const B={table:{kzqmXN:"xh8yej3",kLvRdT:"x1mwwwfo",kheTzg:"x1gukg7c",kPzzVL:"x140o2bo",$$css:!0},tableAutoLayout:{kPzzVL:"x1drmoe9",$$css:!0}};function $(e,t,n,...l){return e.reduce((s,r,o)=>{const c=t(r);if(!c)return s;try{return c(s,...l)}catch(a){return console.error(`[Table] Plugin at index ${o} threw in transform:`,a),s}},n)}const Ae=[];function De(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function qe({item:e,rowIndex:t,rowKey:n,columns:l,plugins:s,textOverflow:r,RowComponent:o,CellComponent:c}){const a=l.map((u,m)=>{var j;const C={};u.align&&(C.style={textAlign:u.align});const T=$(s,P=>P.transformBodyCell,{htmlProps:C,styles:[],columnIndex:m,columns:l},u,e,m,l),R=!u.renderCell,g=R?be(e,u.key):((j=u.renderCell)==null?void 0:j.call(u,e))??null;let x;return R&&r==="truncate"&&typeof g=="string"&&g.length>0?x=i.jsx(xe,{type:"body",maxLines:1,children:g}):x=g,i.jsx(c,{...T.htmlProps,xstyle:T.styles,children:x},u.key)}),d=$(s,u=>u.transformBodyRow,{htmlProps:{},styles:[],children:i.jsx(i.Fragment,{children:a})},e,t);return i.jsx(o,{ref:d.ref,...d.htmlProps,xstyle:d.styles,children:d.children},n)}function ze(e,t){if(e.rowKey!==t.rowKey||e.rowIndex!==t.rowIndex||e.columns!==t.columns||e.plugins!==t.plugins||e.textOverflow!==t.textOverflow||e.RowComponent!==t.RowComponent||e.CellComponent!==t.CellComponent)return!1;if(e.item===t.item)return!0;const n=e.item,l=t.item,s=Object.keys(l);for(const r of s)if(n[r]!==l[r])return!1;return!0}const Ee=k.memo(qe,ze);function Ie({data:e,columns:t,idKey:n,plugins:l,children:s,tableProps:r,textOverflow:o="wrap",scrollWrapper:c,emptyState:a,ref:d}){const u=l??Ae,m=Z,C=ee,H=te,T=t??(e?Ce(e):[]),R=$(u,f=>f.transformColumns,T),g=k.useRef(R);De(g.current,R)||(g.current=R);const x=g.current,j=he(x),P=$(u,f=>f.transformTable,{htmlProps:{...r},styles:s?[B.table,B.tableAutoLayout]:[B.table]}),oe=x.map((f,h)=>{var U;const w=f.header??f.key,D={"data-column-key":f.key};f.align&&(D.style={textAlign:f.align});const v=$(u,me=>me.transformHeaderCell,{htmlProps:D,styles:[],content:w,columnIndex:h,columns:x},f,h,x),q=((U=j.columns.get(f.key))==null?void 0:U.style)??{},z=v.htmlProps.style,ue={...v.htmlProps,style:z?{...q,...z}:q},W=v.content??w,fe=typeof W=="string"&&W.length>0?{title:W}:{},{before:E,after:O,overlay:I,below:_}=v,de=E!=null||O!=null||I!=null||_!=null;return i.jsx(H,{...ue,...fe,xstyle:v.styles,children:de?i.jsxs(i.Fragment,{children:[E,O!=null?i.jsxs("div",{className:"x3nfvp2 x6s0dn4 xzye2dw xeuugli",children:[W,O]}):W,I,_]}):W},f.key)}),L=$(u,f=>f.transformHeaderRow,{htmlProps:{},styles:[],children:i.jsx(i.Fragment,{children:oe})}),ae=e!=null&&e.length>0,ie=x.length>0,ce={...P.htmlProps.style,minWidth:j.tableMinWidth>0?`${j.tableMinWidth}px`:void 0};let S=i.jsx("table",{ref:d,...P.htmlProps,...y(p("base-table"),b(...P.styles),P.htmlProps.className),style:ce,children:s||i.jsxs(i.Fragment,{children:[ie&&i.jsx(ne,{children:i.jsx(m,{...L.htmlProps,isHeaderRow:!0,xstyle:L.styles,children:L.children})}),i.jsx(re,{children:ae?e.map((f,h)=>{const w=n==null?h:typeof n=="function"?n(f):String(f[n]);return i.jsx(Ee,{item:f,rowIndex:h,rowKey:w,columns:x,plugins:u,textOverflow:o,RowComponent:m,CellComponent:C},w)}):e!=null&&a!==!1&&i.jsx("tr",{children:i.jsx("td",{colSpan:x.length,children:a??i.jsx(pe,{title:"No data",isCompact:!0})})})})]})});if(c){const f=$(u,h=>h.transformScrollWrapper,{htmlProps:{},styles:[]});S=i.jsx(c,{htmlProps:f.htmlProps,styles:f.styles,beforeTable:f.beforeTable,afterTable:f.afterTable,children:S})}for(let f=u.length-1;f>=0;f--){const h=u[f];if(h.transformTableContext)try{S=h.transformTableContext(S)}catch(w){console.error("[Table] Plugin threw in transformTableContext:",w)}}return S}const se=Ie;se.displayName="BaseTable";const le=["columnSettings","sort","selection","pagination"],G=new Map(le.map((e,t)=>[e,t]));function _e(e){const t=le.length;return e.sort(([n],[l])=>{const s=G.get(n)??t,r=G.get(l)??t;return s-r})}const M=new Set(["transformColumns","transformTable","transformHeaderRow","transformHeaderCell","transformBodyRow","transformBodyCell","transformScrollWrapper","transformTableContext"]);function Ue(e,t){const n=Object.keys(t);for(const s of n)M.has(s)||console.warn(`[Table] Plugin "${e}" has unknown key "${s}". Valid keys: ${[...M].join(", ")}. This key will be ignored.`);for(const s of n)if(M.has(s)){const r=t[s];r!=null&&typeof r!="function"&&console.warn(`[Table] Plugin "${e}" has non-function value for "${s}" (got ${typeof r}). Transform will be skipped.`)}n.some(s=>M.has(s)&&typeof t[s]=="function")||console.warn(`[Table] Plugin "${e}" has no transform methods. It will be included in the pipeline but won't do anything.`)}function Fe(e,t){const n=k.useRef(null);if(n.current!=null){const r=n.current;if(r.basePlugins===e&&r.userPlugins===t)return r.result;if(r.basePlugins===e&&Ye(r.userPlugins,t))return r.userPlugins=t,r.result}const l=t?_e(Object.entries(t)).map(([,r])=>r):[],s=[...e,...l];if(t)for(const[r,o]of Object.entries(t))Ue(r,o);return n.current={basePlugins:e,userPlugins:t,result:s},s}function Ye(e,t){if(e===t)return!0;if(e==null||t==null)return!1;const n=Object.keys(e),l=Object.keys(t);if(n.length!==l.length)return!1;for(const s of n)if(e[s]!==t[s])return!1;return!0}const Ge={base:{kMv6JI:"xjb2p0i",kMwMTN:"x1tgivj0",$$css:!0}},V={base:{kXHlph:"xw2csxc",kuHK5b:"x5lxg6s",$$css:!0},containerBleed:{keTefX:"xojxgvx",k71WvV:"x1fcf3bl",kzqmXN:"xx6qvi6",keoZOQ:"xkibk3",k1K539:"xlayyun",$$css:!0}};function Ve({children:e,htmlProps:t,styles:n,beforeTable:l,afterTable:s}){const{ref:r,...o}=t??{};return i.jsxs("div",{ref:r,...o,...y(p("table-scroll-wrapper"),b(V.base,V.containerBleed,...n??[])),children:[l,e,s]})}function Xe(){return{transformTable(e){const t=e.htmlProps.className??"",n=p("table").className;return{...e,htmlProps:{...e.htmlProps,className:t?`${t} ${n}`:n},styles:[...e.styles,Ge.base]}}}}function Qe({density:e="balanced",dividers:t="rows",isStriped:n=!1,hasHover:l=!1,verticalAlign:s="middle",textOverflow:r="wrap",plugins:o,columns:c,data:a,ref:d,...u}){const m=k.useMemo(()=>Xe(),[]),C=k.useMemo(()=>[m],[m]),H=Fe(C,o),T=k.useMemo(()=>({density:e,dividers:t,isStriped:n,hasHover:l,verticalAlign:s,textOverflow:r}),[e,t,n,l,s,r]);return i.jsx(N,{value:T,children:i.jsx(se,{ref:d,data:a,columns:c,plugins:H,textOverflow:r,scrollWrapper:Ve,...u})})}const Ze=Qe;Ze.displayName="Table";export{Ze as T,tt as a,ne as b,Z as c,te as d,re as e,ee as f,ye as p};
|