@sito/dashboard 0.0.72 → 0.0.74
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.
- package/README.md +27 -3
- package/dist/{FiltersProvider-DVMj0LV0.cjs → FiltersProvider-CnrF3xWV.cjs} +1 -1
- package/dist/{FiltersProvider-BV023mmu.js → FiltersProvider-iOkSYSFZ.js} +1 -1
- package/dist/FiltersProvider.cjs +1 -1
- package/dist/FiltersProvider.js +1 -1
- package/dist/Form.cjs +1 -1
- package/dist/Form.js +1 -1
- package/dist/SelectInput-Dm7gv03Z.js +521 -0
- package/dist/SelectInput-dYjrdopP.cjs +1 -0
- package/dist/{Table-DYcrwEM-.cjs → Table-C03frnWb.cjs} +1 -1
- package/dist/{Table-ehiZ_7Qa.js → Table-DO7FFraQ.js} +3 -3
- package/dist/Table.cjs +1 -1
- package/dist/Table.js +1 -1
- package/dist/TableOptions.cjs +1 -1
- package/dist/TableOptions.js +1 -1
- package/dist/TableOptionsProvider-Dzq4dOu8.js +157 -0
- package/dist/TableOptionsProvider-bPNtpa4V.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/providers/TableOptions/TableOptionsProvider.d.ts +2 -2
- package/dist/providers/TableOptions/types.d.ts +9 -0
- package/dist/providers/TableOptions/utils.d.ts +60 -0
- package/package.json +1 -1
- package/dist/SelectInput-B9EEu-h1.cjs +0 -1
- package/dist/SelectInput-H421nC22.js +0 -525
- package/dist/TableOptionsProvider-BgnISoXx.js +0 -120
- package/dist/TableOptionsProvider-i4uVLLwH.cjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var Oe=require("./Table.css");const e=require("react/jsx-runtime"),r=require("react"),k=require("./FiltersProvider-DVMj0LV0.cjs"),O=require("./TableColumns-BjTNomZf.cjs"),P=require("./SelectInput-B9EEu-h1.cjs"),I=require("./TableOptionsProvider-i4uVLLwH.cjs"),A=require("./TranslationProvider-Czr0WIDH.cjs"),D=require("./IconButton-CVnmT2E9.cjs"),fe=require("./Badge-Z78MlGoQ.cjs"),z=require("./lib.cjs"),G=require("./Button-BlYa3uPc.cjs"),J=require("./Chip-D17UJHW6.cjs"),Y=require("./Tooltip-BSKAgRkc.cjs"),je=require("./query-81BrXp3i.cjs"),ge=require("./Dropdown-CR8mco5s.cjs"),Ce=require("./Loading-CNECRan-.cjs");function X(n){const{id:t,icon:a,tooltip:s,onClick:l,children:i,hidden:p=!1,disabled:c=!1,showText:u=!1,showTooltips:o=!0,className:m=""}=n;return p?null:e.jsxs("button",{type:"button",id:t,className:`action ${u?"text-action":"icon-action"} ${m}`,disabled:c,"aria-label":s,onClick:d=>{d.stopPropagation(),l?.()},"aria-disabled":c,"data-tooltip-id":"tooltip","data-tooltip-content":o?s:"",children:[a," ",u&&s,i]})}function Z(n){const{actions:t=[],className:a="",itemClassName:s="",actionClassName:l="",showTooltips:i=!0,showActionTexts:p=!1}=n;return e.jsx("ul",{className:`actions-container ${a}`,children:t.map(c=>e.jsx("li",{className:`actions-container-item ${s}`,children:e.jsx(X,{showTooltips:i,showText:p,className:l,...c})},c.id))})}const ee=n=>{const{actions:t=[],className:a=""}=n,{t:s}=A.useTranslation(),[l,i]=r.useState(!1),[p,c]=r.useState(null);return e.jsxs("div",{className:`actions-dropdown ${a}`,children:[e.jsx(D.IconButton,{icon:e.jsx(O.Ellipsis,{}),onClick:u=>{u.stopPropagation(),c(u.currentTarget),i(o=>!o)},onMouseDown:u=>u.stopPropagation(),className:"actions-dropdown-trigger","aria-label":s("_accessibility:buttons.openActions"),name:s("_accessibility:buttons.openActions"),"data-tooltip-id":"tooltip","data-tooltip-content":s("_accessibility:buttons.openActions")}),e.jsx(ge.Dropdown,{open:l,onClose:()=>i(!1),anchorEl:p,children:e.jsx(Z,{showActionTexts:!0,actions:t,itemClassName:"w-full",actionClassName:"action-dropdown-item",className:"actions-dropdown-list",showTooltips:!1})})]})};function K(n,t=[]){return[...n].sort((a,s)=>(s.pos??0)-(a.pos??0)).filter(a=>a.display!=="none"&&!t.includes(a.key))}function te(n){const{t}=A.useTranslation(),{entity:a="",columns:s=[],hasAction:l=!0,onSortCallback:i,selectionState:p,onToggleAllRows:c}=n,u=r.useRef(null);r.useEffect(()=>{u.current&&(u.current.indeterminate=!!(p?.hasSomeSelected&&!p?.allSelected))},[p]);const{onSort:o,sortingOrder:m,sortingBy:d,hiddenColumns:C}=I.useTableOptions(),x=r.useMemo(()=>K(s,C).map(b=>({id:b.key,label:b.label,renderHead:b.renderHead,className:b.className??"",sortable:b.sortable??!0,sortOptions:b.sortOptions})),[s,a,t,C]);return e.jsx("thead",{className:"table-headers-row",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"table-headers-column table-headers-checkbox",children:c?e.jsx("input",{type:"checkbox",ref:u,checked:p?.allSelected??!1,onChange:c,"aria-label":t("_accessibility:components.table.selectAllRows")}):null}),l&&e.jsx("th",{scope:"col",className:"table-headers-action",children:e.jsx("span",{children:t("_accessibility:labels.actions")})}),x.map(b=>e.jsx("th",{scope:"col",className:`table-headers-column ${b.className}`,children:e.jsxs(G.Button,{disabled:!b.sortable,onClick:()=>o(b.id,i),className:"table-headers-cell",children:[b.renderHead?b.renderHead():e.jsx("span",{className:"table-headers-label",children:b.label}),b.sortable&&d===b.id&&e.jsx("span",{children:m===je.SortOrder.ASC?b.sortOptions?.icons?.asc??e.jsx(O.ChevronUp,{className:b.sortOptions?.icons?.className??"table-headers-sort-indicator"}):b.sortOptions?.icons?.desc??e.jsx(O.ChevronDown,{className:b.sortOptions?.icons?.className??"table-headers-sort-indicator"})})]})},b.id))]})})}function ne(n){const{columns:t}=n,{hiddenColumns:a,toggleColumn:s}=I.useTableOptions(),{t:l}=A.useTranslation(),[i,p]=r.useState(!1),c=r.useRef(null),u=r.useMemo(()=>K(t.filter(d=>d.hideable!==!1&&d.display!=="none"),[]),[t]),o=r.useCallback(()=>{p(d=>!d)},[]),m=r.useCallback(d=>{s(d)},[s]);return u.length===0?null:e.jsxs("div",{className:"column-visibility-menu",ref:c,children:[e.jsx(D.IconButton,{icon:e.jsx(O.TableColumns,{className:"column-visibility-icon"}),className:"normal column-visibility-trigger","aria-haspopup":"true","aria-expanded":i,onClick:o,children:e.jsx("span",{className:"table-header-sr",children:l("_accessibility:buttons.columns")})}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"column-visibility-backdrop",onClick:()=>p(!1)}),e.jsx("div",{className:"column-visibility-dropdown",role:"menu",children:u.map(d=>e.jsx(P.CheckInput,{checked:!a.includes(d.key),onChange:()=>m(d.key),label:d.label??d.key,containerClassName:"column-visibility-item"},d.key))})]})]})}const se=n=>{const{items:t,text:a,id:s,onClearFilter:l}=n;return e.jsx(J.Chip,{text:`${a}: ${t.map(i=>i.value??i.name).join(", ")}`,onDelete:()=>l(s)})},le=n=>{const{end:t,start:a,text:s,id:l,onClearFilter:i}=n,p=c=>c!==null&&typeof c<"u"&&c!=="";return e.jsx(J.Chip,{text:`${s}: ${p(a)?a:"♾️"} - ${p(t)?t:"♾️"}`,onDelete:()=>i(l)})},Ne=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&("start"in n||"end"in n),ae=n=>{const{filtersDefinition:t}=n,a=r.useMemo(()=>{const c={};return t.forEach(u=>{c[u.propertyName]=u.label??u.propertyName}),c},[t]),{filters:s,clearFilters:l}=I.useTableOptions(),i=r.useMemo(()=>Object.keys(s),[s]),p=r.useCallback(c=>{const u=s[c];return Ne(u)?e.jsx(le,{id:c,text:a[c],start:u.start,end:u.end,onClearFilter:l}):Array.isArray(u)?e.jsx(se,{id:c,text:a[c],items:u,onClearFilter:l}):e.jsx(J.Chip,{text:`${a[c]}: ${u?.value??u?.name??u}`,onDelete:()=>l(c)})},[s,a,l]);return e.jsx("ul",{className:"active-filters-main",children:i?.map(c=>e.jsx("li",{children:p(c)},c))})};function ye(n){const{propertyName:t,label:a,placeholder:s,options:l,multiple:i=!0}=n,{currentFilters:p,setCurrentFilters:c}=k.useFilters(),u=r.useMemo(()=>{const m=p[t]?.value;return typeof m>"u"?null:m},[p,t]),o=r.useCallback(m=>{c({type:k.FiltersActions.update,toUpdate:{[t]:{value:m}}})},[t,c]);return e.jsx(P.AutocompleteInput,{value:u,label:a,options:l,multiple:i,helperTextClassName:"hidden",containerClassName:"options-widget-container",onChange:o,placeholder:s})}const ve=n=>{const{propertyName:t,label:a}=n,{currentFilters:s,setCurrentFilters:l}=k.useFilters(),i=r.useMemo(()=>s[t]?.value??"",[s]),p=r.useCallback(c=>{l({type:k.FiltersActions.update,toUpdate:{[t]:{value:c.target.checked}}})},[]);return e.jsx(P.CheckInput,{label:a,checked:i??!1,onChange:p})};function we(n){const{propertyName:t,options:a,label:s,placeholder:l}=n,{currentFilters:i,setCurrentFilters:p}=k.useFilters(),c=r.useMemo(()=>{const o=i[t]?.value;if(o===null||typeof o>"u")return a[0]?.id??"";if(typeof o=="object"&&!Array.isArray(o)){const m=o;return m.id??m.value??""}return o},[i,a,t]),u=r.useCallback(o=>{const m=a.find(d=>String(d.id)===o.target.value);p({type:k.FiltersActions.update,toUpdate:{[t]:{value:m?.id??o.target.value}}})},[a,t,p]);return e.jsx(P.SelectInput,{value:c,label:s,options:a,helperTextClassName:"hidden",containerClassName:"options-widget-container",onChange:u,placeholder:l})}const Te=n=>{const{propertyName:t,label:a,placeholder:s}=n,{currentFilters:l,setCurrentFilters:i}=k.useFilters(),p=r.useMemo(()=>l[t]?.value??"",[l]),c=r.useCallback(u=>{i({type:k.FiltersActions.update,toUpdate:{[t]:{value:u.target.value}}})},[]);return e.jsx(P.TextInput,{value:p??"",label:a,onChange:c,containerClassName:"input-widget-container",helperTextClassName:"",placeholder:s})},Q=n=>{const{propertyName:t,label:a,inputType:s}=n,{t:l}=A.useTranslation(),{currentFilters:i,setCurrentFilters:p}=k.useFilters(),c=r.useRef(null),u=r.useRef(null),o=r.useCallback(d=>{p({type:k.FiltersActions.update,toUpdate:{[t]:{value:{end:u?.current?.value??null,start:d.target.value}}}})},[]),m=r.useCallback(d=>{p({type:k.FiltersActions.update,toUpdate:{[t]:{value:{start:c?.current?.value??null,end:d.target.value}}}})},[]);return e.jsxs("div",{className:"range-widget-container",children:[e.jsx("p",{className:"text-input-label input-widget-label input-label-normal",children:a}),e.jsxs("div",{className:"range-widget-row",children:[e.jsx(P.TextInput,{value:i[t]?.value?.start??"",placeholder:l("_accessibility:components.table.filters.range.start"),type:s,ref:c,onChange:o,containerClassName:"input-widget-container",helperTextClassName:""}),e.jsx(P.TextInput,{value:i[t]?.value?.end??"",placeholder:l("_accessibility:components.table.filters.range.end"),type:s,ref:u,onChange:m,containerClassName:"input-widget-container",helperTextClassName:""})]})]})},ie=n=>{switch(n.type){case z.FilterTypes.text:return e.jsx(Te,{...n});case z.FilterTypes.number:return e.jsx(Q,{...n,inputType:"number"});case z.FilterTypes.date:return e.jsx(Q,{...n,inputType:"date"});case z.FilterTypes.select:return e.jsx(we,{...n});case z.FilterTypes.autocomplete:return e.jsx(ye,{...n});case z.FilterTypes.check:return e.jsx(ve,{...n})}return e.jsx(e.Fragment,{})},re=n=>{const{filters:t=[],show:a,handleShow:s}=n,{onFilterApply:l}=I.useTableOptions(),{currentFilters:i,setCurrentFilters:p}=k.useFilters(),{t:c}=A.useTranslation(),u=r.useRef(null);return r.useEffect(()=>{const o=({target:d})=>{u.current&&(d?.closest(".filter-dropdown-trigger")||!a||u.current.contains(d)||s(!1))},m=({code:d})=>{!a||d!=="Escape"||s(!1)};return document.addEventListener("click",o),document.addEventListener("keydown",m),()=>{document.removeEventListener("click",o),document.removeEventListener("keydown",m)}},[s,a]),e.jsx("div",{className:`filter-dropdown-backdrop ${a?"opened":"closed"}`,children:e.jsxs("div",{className:"filter-popup",ref:u,children:[e.jsx("div",{className:"filter-title",children:c("_accessibility:buttons.filters")}),e.jsx("ul",{className:"filter-container",children:t.map(o=>e.jsx("li",{className:"filter-container-item",children:ie(o)},o.propertyName))}),e.jsx("div",{className:"filter-footer",children:e.jsxs("ul",{className:"filter-buttons-row",children:[e.jsx("li",{children:e.jsx(G.Button,{type:"button",variant:"submit",onClick:()=>p({type:k.FiltersActions.reset,filters:t}),className:"filter-dropdown-button filter-dropdown-cancel",children:c("_accessibility:buttons.clear")})}),e.jsx("li",{children:e.jsx(G.Button,{type:"button",variant:"submit",color:"primary",className:"filter-dropdown-button filter-dropdown-submit",onClick:()=>{s(!1),l(i)},children:c("_accessibility:buttons.applyFilters")})})]})})]})})},oe=()=>{const{t:n}=A.useTranslation(),{total:t,pageSize:a,pageSizes:s,currentPage:l}=I.useTableOptions(),i=(l+1)*a>t?t:(l+1)*a;return e.jsxs("div",{className:"table-navigation-sizes",children:[s[0]<t&&e.jsx(e.Fragment,{children:e.jsxs("p",{children:[l*a+1," - ",i," ",n("_accessibility:components.table.of")]})}),e.jsx("p",{children:t})]})};function Se(){const{t:n}=A.useTranslation(),{total:t,pageSize:a,currentPage:s,setCurrentPage:l}=I.useTableOptions(),i=r.useMemo(()=>{const p=Math.ceil(t/a);return Array.from({length:p},(c,u)=>({id:u,value:u+1}))},[t,a]);return e.jsxs("div",{className:"jump-to-page",children:[e.jsx("p",{children:n("_accessibility:components.table.jumpToPage")}),e.jsx(P.SelectInput,{value:s,options:i,inputClassName:"jump-to-page-input",containerClassName:"jump-to-page-input-container",helperTextClassName:"hidden",onChange:p=>l(Number(p.target.value))})]})}const ce=()=>{const{t:n}=A.useTranslation(),{total:t,pageSize:a,currentPage:s,setCurrentPage:l}=I.useTableOptions(),i=Math.ceil(t/a),p=s<i-1;return e.jsxs("div",{className:"table-navigation-pages",children:[e.jsx(D.IconButton,{icon:e.jsx(O.ChevronLeft,{className:"table-navigation-icon"}),className:"table-navigation-buttons",disabled:s===0,"aria-label":n("_accessibility:buttons.previous"),name:n("_accessibility:buttons.previous"),onClick:()=>l(s-1)}),e.jsx(D.IconButton,{icon:e.jsx(O.ChevronRight,{className:"table-navigation-icon"}),disabled:!p,className:"table-navigation-buttons",name:n("_accessibility:buttons.next"),"aria-label":n("_accessibility:buttons.next"),onClick:()=>{p&&l(s+1)}})]})};function ue(){const{t:n}=A.useTranslation(),{pageSizes:t,pageSize:a,setPageSize:s}=I.useTableOptions(),l=r.useMemo(()=>t?.map(i=>({id:i,value:i})),[t]);return e.jsxs("div",{className:"page-size",children:[e.jsx("p",{children:n("_accessibility:components.table.pageSizes")}),e.jsx(P.SelectInput,{value:a,options:l,inputClassName:"page-size-input",containerClassName:"page-size-input-container",helperTextClassName:"hidden",onChange:i=>s(Number(i.target.value))})]})}function de(){return e.jsxs("div",{className:"table-footer",children:[e.jsx(Se,{}),e.jsx(ue,{}),e.jsx(oe,{}),e.jsx(ce,{})]})}const ke=n=>n,pe=n=>{const{t}=A.useTranslation(),{hiddenColumns:a}=I.useTableOptions(),{columns:s,softDeleteProperty:l="deletedAt",data:i,actions:p,selectedRows:c,expandedRows:u=[],onRowSelectionChange:o,onRowExpand:m}=n,d=r.useMemo(()=>K(s,a),[s,a]),C=r.useMemo(()=>new Map(u.map(x=>[x.rowId,x])),[u]);return i?.map(x=>{const b=c.has(x.id),y=C.get(x.id),R=!!y,_=d.length+1+(p?1:0);return e.jsxs(r.Fragment,{children:[e.jsxs("tr",{className:`table-row ${m?"expandable":""} ${x[l]?"deleted-class":""} ${b?"selected":""} ${R?"expanded":""}`,onClick:()=>m?.(x),children:[e.jsx("td",{className:"table-row-cell table-row-checkbox",children:e.jsx("input",{type:"checkbox",checked:b,onClick:v=>v.stopPropagation(),onChange:()=>o(x),"aria-label":t("_accessibility:components.table.selectRow")})}),p?e.jsx("td",{className:"w-px",children:e.jsx("div",{className:"table-row-cell-action",children:(()=>{const v=p(x).filter(g=>!g.hidden),j=v.filter(g=>g.sticky),w=v.filter(g=>!g.sticky);return e.jsxs(e.Fragment,{children:[j.map(g=>e.jsx(Y.Tooltip,{content:g.tooltip,children:e.jsx(X,{...g,onClick:()=>g.onClick(x),className:"row-table-action"})},g.id)),w.length>0&&e.jsx(ee,{actions:w})]})})()})}):null,d?.map((v,j)=>{const w=x[v.key],g=v.renderBody?v.renderBody(w,x):ke(w);return e.jsx("td",{className:`table-row-cell ${j===0?"basic":""} ${v.className??""}`,children:m&&j===0?e.jsxs("div",{className:"table-row-expand-content",children:[e.jsx("span",{className:"table-row-expand-indicator","aria-hidden":!0,"data-state":R?"expanded":"collapsed",children:R?e.jsx(O.ChevronUp,{className:"table-row-expand-chevron"}):e.jsx(O.ChevronDown,{className:"table-row-expand-chevron"})}),e.jsx("div",{className:"table-row-expand-value",children:g})]}):g},v.key)})]}),R&&y?.content!==null&&typeof y?.content<"u"&&e.jsx("tr",{className:"table-row-expanded",children:e.jsx("td",{className:"table-row-expanded-cell",colSpan:_,children:e.jsx("div",{className:`table-row-expanded-content ${y.isVisible?"open":"closed"}`,children:e.jsx("div",{className:"table-row-expanded-inner",children:y.content})})})})]},x.id)})};function me(){const{t:n}=A.useTranslation();return e.jsx("div",{className:"table-empty",children:e.jsx("p",{children:n("_accessibility:components.table.empty")})})}const he=n=>{const{columns:t,title:a,isLoading:s,toolbar:l,filterOptions:i,canHideColumns:p=!1,canReset:c=!1}=n,{countOfFilters:u,resetTableOptions:o}=I.useTableOptions(),{t:m}=A.useTranslation(),d=r.useMemo(()=>t?[...t].sort((j,w)=>(w.pos??0)-(j.pos??0)).filter(j=>!!j.filterOptions).map(j=>({...j.filterOptions,label:j.filterOptions?.label??j.label,propertyName:j.key})):[],[t]),[C,x]=r.useState(!1),b=r.useCallback(j=>{i?.dropdown?.setOpened?i.dropdown.setOpened(j??!1):x(j??!1)},[i]),y=r.useMemo(()=>i?.dropdown?.opened??C,[i,C]),R=d.length>0,_=R&&i?.button?.hide!==!0,v=R&&y;return e.jsxs("div",{className:`table-header ${v?"showing-filters":""}`,children:[e.jsxs("div",{children:[a&&e.jsx("h1",{className:"table-header-title",children:a}),s?null:e.jsxs("div",{className:"table-header-content",children:[l,p&&t&&e.jsx(ne,{columns:t}),c&&e.jsx(D.IconButton,{icon:e.jsx(O.BarsStaggered,{className:"reset-table-icon"}),className:"normal",onClick:o,children:e.jsx("span",{className:"table-header-sr",children:m("_accessibility:buttons.reset")})}),_&&e.jsxs(D.IconButton,{icon:i?.button?.icon??e.jsx(O.Filters,{className:"filter-dropdown-trigger-icon"}),className:"filter-dropdown-button normal filter-dropdown-trigger","aria-haspopup":"true",onClick:()=>b(!y),"aria-expanded":y,children:[e.jsx(fe.Badge,{count:u,className:`${u>0?"show":"hide"} `}),e.jsx("span",{className:"table-header-sr",children:m("_accessibility:buttons.filters")}),e.jsx("wbr",{})]})]})]}),R&&e.jsx(re,{filters:d,show:v,handleShow:b,options:i}),e.jsx(ae,{filtersDefinition:d})]})};function be({count:n,multiActions:t,onActionClick:a}){const{t:s}=A.useTranslation();return e.jsxs("div",{className:"table-selection-bar",children:[e.jsx("p",{className:"table-selection-bar-count",children:s("_accessibility:components.table.selectedCount",{count:n})}),t.length>0&&e.jsx("div",{className:"table-selection-bar-actions",children:t.map(l=>e.jsx(Y.Tooltip,{content:l.tooltip,children:e.jsx(D.IconButton,{icon:l.icon,className:"multi-table-action",onClick:()=>a(l),disabled:l.disabled,"aria-label":l.tooltip})},l.id))})]})}const W=220;function Re({data:n,allowMultipleExpandedRows:t,controlledExpandedRowId:a,onExpandedRowChange:s,onRowExpand:l,findRowById:i}){const[p,c]=r.useState(null),[u,o]=r.useState(null),[m,d]=r.useState(null),[C,x]=r.useState(null),[b,y]=r.useState(!1),[R,_]=r.useState(new Set),[v,j]=r.useState([]),w=r.useRef(null),g=r.useRef(null),q=r.useRef(new Map),E=typeof a<"u",M=t&&!E,T=E?a??null:p,V=r.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null)},[]),F=r.useCallback(h=>{if(typeof h<"u"){const f=q.current.get(h);if(!f)return;clearTimeout(f),q.current.delete(h);return}q.current.forEach(f=>clearTimeout(f)),q.current.clear()},[]),L=r.useCallback(h=>{F(h),j(f=>f.some(S=>S.rowId===h)?f.map(S=>S.rowId===h?{...S,isVisible:!1}:S):f),q.current.set(h,setTimeout(()=>{j(f=>f.filter(N=>N.rowId!==h)),q.current.delete(h)},W))},[F]),U=r.useCallback((h,f)=>{F(h),j(N=>N.some($=>$.rowId===h)?N.map($=>$.rowId===h?{...$,content:f,isVisible:!1}:$):[...N,{rowId:h,content:f,isVisible:!1}]),requestAnimationFrame(()=>{j(N=>N.map(S=>S.rowId===h?{...S,isVisible:!0}:S))})},[F]);r.useEffect(()=>{if(!M)return;const h=new Set(n.map(f=>f.id));_(f=>{const N=new Set;return f.forEach(S=>{if(h.has(S)){N.add(S);return}F(S)}),N}),j(f=>(f.forEach(N=>{h.has(N.rowId)||F(N.rowId)}),f.filter(N=>h.has(N.rowId))))},[n,M,F]),r.useEffect(()=>{if(M)return;if(T===null){o(null),E&&(w.current=null);return}i(T)||(E||c(null),o(null),E&&(w.current=null))},[n,T,i,E,M]),r.useEffect(()=>{if(!M){if(V(),T===null||u===null){if(m===null){y(!1),x(null);return}y(!1),g.current=setTimeout(()=>{d(null),x(null),g.current=null},W);return}if(m===null){d(T),x(u),requestAnimationFrame(()=>y(!0));return}if(m===T){x(u),requestAnimationFrame(()=>y(!0));return}y(!1),g.current=setTimeout(()=>{d(T),x(u),requestAnimationFrame(()=>y(!0)),g.current=null},W)}},[V,u,T,M,m]),r.useEffect(()=>()=>{V(),F()},[V,F]),r.useEffect(()=>{if(!E)return;if(T===null){o(null),w.current=null;return}const h=i(T);if(!h){o(null),w.current=null;return}const f=w.current;o(l?.(h,f)??null),w.current=h},[T,i,E,l]);const xe=r.useCallback(h=>{if(M){if(R.has(h.id)){_(H=>{const B=new Set(H);return B.delete(h.id),B}),L(h.id),s?.(null,h);return}_(H=>{const B=new Set(H);return B.add(h.id),B});const $=l?.(h,null)??null;$!==null&&typeof $<"u"?U(h.id,$):(F(h.id),j(H=>H.filter(B=>B.rowId!==h.id))),s?.(h,null);return}const f=T===h.id,N=f?h:i(T);if(E){s?.(f?null:h,N);return}if(f){c(null),o(null),s?.(null,h);return}c(h.id),o(l?.(h,N)??null),s?.(h,N)},[T,L,F,U,i,R,E,M,s,l]);return{expandedRowsToRender:r.useMemo(()=>M?v:m===null||C===null||typeof C>"u"?[]:[{rowId:m,content:C,isVisible:b}],[b,M,C,m,v]),onRowExpandChange:xe}}function Fe({actions:n,selectedRowsData:t}){const a=r.useMemo(()=>!n||!t.length?[]:t.reduce((l,i,p)=>{const c=n(i).filter(o=>o.multiple&&!o.hidden);if(p===0)return c;const u=new Map(l.map(o=>[o.id,o]));return c.reduce((o,m)=>{const d=u.get(m.id);return d&&o.push({...d,...m,disabled:m.disabled||d.disabled}),o},[])},[]),[n,t]),s=r.useCallback(l=>{if(t.length){if(l.onMultipleClick){l.onMultipleClick(t);return}t.forEach(i=>l.onClick(i))}},[t]);return{multiActions:a,handleMultipleActionClick:s}}function Ae({data:n,onRowSelect:t,onSelectedRowsChange:a}){const[s,l]=r.useState(new Set),i=r.useMemo(()=>n?.filter(o=>s.has(o.id))??[],[n,s]);r.useEffect(()=>{if(!n?.length){l(new Set);return}l(o=>{const m=new Set,d=new Set(n.map(C=>C.id));return o.forEach(C=>{d.has(C)&&m.add(C)}),m})},[n]),r.useEffect(()=>{a&&a(i)},[i,a]);const p=r.useCallback(o=>{l(m=>{const d=new Set(m);return d.has(o.id)?(d.delete(o.id),t?.(o,!1)):(d.add(o.id),t?.(o,!0)),d})},[t]),c=r.useCallback(()=>{l(o=>{const m=new Set(o),d=n??[],C=d.every(x=>m.has(x.id));return d.forEach(x=>{const b=m.has(x.id);C?b&&(m.delete(x.id),t?.(x,!1)):b||(m.add(x.id),t?.(x,!0))}),m})},[n,t]),u=r.useMemo(()=>{if(!n?.length)return{allSelected:!1,hasSomeSelected:!1};const o=n.every(d=>s.has(d.id)),m=n.some(d=>s.has(d.id));return{allSelected:o,hasSomeSelected:m}},[n,s]);return{selectedRows:s,selectedRowsData:i,selectionState:u,onRowSelectionChange:p,onToggleAllRows:c}}function Ee(n){const{data:t,onSort:a,entity:s="",isLoading:l=!1,actions:i,columns:p=[],contentClassName:c="",className:u="",softDeleteProperty:o="deletedAt",onRowSelect:m,onSelectedRowsChange:d,allowMultipleExpandedRows:C=!1,expandedRowId:x,onExpandedRowChange:b,onRowExpand:y,...R}=n,_=r.useMemo(()=>!t?.length,[t]),v=r.useCallback(L=>L===null?null:t.find(U=>U.id===L)??null,[t]),{selectedRows:j,selectedRowsData:w,selectionState:g,onRowSelectionChange:q,onToggleAllRows:E}=Ae({data:t,onRowSelect:m,onSelectedRowsChange:d}),{expandedRowsToRender:M,onRowExpandChange:T}=Re({data:t,allowMultipleExpandedRows:C,controlledExpandedRowId:x,onExpandedRowChange:b,onRowExpand:y,findRowById:v}),{multiActions:V,handleMultipleActionClick:F}=Fe({actions:i,selectedRowsData:w});return e.jsx(k.FiltersProvider,{children:e.jsxs("div",{className:`${u} table-main`,children:[e.jsx(he,{columns:p,isLoading:l,...R}),l?e.jsx(Ce.Loading,{className:"table-loading"}):e.jsx(e.Fragment,{children:_?e.jsx(me,{}):e.jsxs(e.Fragment,{children:[!!w.length&&e.jsx(be,{count:w.length,multiActions:V,onActionClick:F}),e.jsx("div",{className:`${c} table-body`,children:e.jsxs("table",{className:"table-content",children:[e.jsx(te,{entity:s,columns:p,onSortCallback:a,hasAction:!!i,selectionState:g,onToggleAllRows:E}),e.jsx("tbody",{children:e.jsx(pe,{data:t,actions:i,columns:p,softDeleteProperty:o,selectedRows:j,expandedRows:M,onRowSelectionChange:q,onRowExpand:y?T:void 0})})]})}),e.jsx(de,{})]})})]})})}exports.Action=X;exports.Actions=Z;exports.ActionsDropdown=ee;exports.ActiveFilters=ae;exports.ArrayChip=se;exports.ColumnVisibilityMenu=ne;exports.Columns=te;exports.CountOfTotal=oe;exports.FilterDropdown=re;exports.Footer=de;exports.Navigation=ce;exports.PageSize=ue;exports.RangeChip=le;exports.Rows=pe;exports.Table=Ee;exports.TableEmpty=me;exports.TableHeader=he;exports.TableSelectionBar=be;exports.renderFilterComponent=ie;
|
|
1
|
+
var Oe=require("./Table.css");const e=require("react/jsx-runtime"),r=require("react"),k=require("./FiltersProvider-CnrF3xWV.cjs"),O=require("./TableColumns-BjTNomZf.cjs"),P=require("./SelectInput-dYjrdopP.cjs"),I=require("./TableOptionsProvider-bPNtpa4V.cjs"),A=require("./TranslationProvider-Czr0WIDH.cjs"),D=require("./IconButton-CVnmT2E9.cjs"),fe=require("./Badge-Z78MlGoQ.cjs"),z=require("./lib.cjs"),G=require("./Button-BlYa3uPc.cjs"),J=require("./Chip-D17UJHW6.cjs"),Y=require("./Tooltip-BSKAgRkc.cjs"),je=require("./query-81BrXp3i.cjs"),ge=require("./Dropdown-CR8mco5s.cjs"),Ce=require("./Loading-CNECRan-.cjs");function X(n){const{id:t,icon:a,tooltip:s,onClick:l,children:i,hidden:p=!1,disabled:c=!1,showText:u=!1,showTooltips:o=!0,className:m=""}=n;return p?null:e.jsxs("button",{type:"button",id:t,className:`action ${u?"text-action":"icon-action"} ${m}`,disabled:c,"aria-label":s,onClick:d=>{d.stopPropagation(),l?.()},"aria-disabled":c,"data-tooltip-id":"tooltip","data-tooltip-content":o?s:"",children:[a," ",u&&s,i]})}function Z(n){const{actions:t=[],className:a="",itemClassName:s="",actionClassName:l="",showTooltips:i=!0,showActionTexts:p=!1}=n;return e.jsx("ul",{className:`actions-container ${a}`,children:t.map(c=>e.jsx("li",{className:`actions-container-item ${s}`,children:e.jsx(X,{showTooltips:i,showText:p,className:l,...c})},c.id))})}const ee=n=>{const{actions:t=[],className:a=""}=n,{t:s}=A.useTranslation(),[l,i]=r.useState(!1),[p,c]=r.useState(null);return e.jsxs("div",{className:`actions-dropdown ${a}`,children:[e.jsx(D.IconButton,{icon:e.jsx(O.Ellipsis,{}),onClick:u=>{u.stopPropagation(),c(u.currentTarget),i(o=>!o)},onMouseDown:u=>u.stopPropagation(),className:"actions-dropdown-trigger","aria-label":s("_accessibility:buttons.openActions"),name:s("_accessibility:buttons.openActions"),"data-tooltip-id":"tooltip","data-tooltip-content":s("_accessibility:buttons.openActions")}),e.jsx(ge.Dropdown,{open:l,onClose:()=>i(!1),anchorEl:p,children:e.jsx(Z,{showActionTexts:!0,actions:t,itemClassName:"w-full",actionClassName:"action-dropdown-item",className:"actions-dropdown-list",showTooltips:!1})})]})};function K(n,t=[]){return[...n].sort((a,s)=>(s.pos??0)-(a.pos??0)).filter(a=>a.display!=="none"&&!t.includes(a.key))}function te(n){const{t}=A.useTranslation(),{entity:a="",columns:s=[],hasAction:l=!0,onSortCallback:i,selectionState:p,onToggleAllRows:c}=n,u=r.useRef(null);r.useEffect(()=>{u.current&&(u.current.indeterminate=!!(p?.hasSomeSelected&&!p?.allSelected))},[p]);const{onSort:o,sortingOrder:m,sortingBy:d,hiddenColumns:C}=I.useTableOptions(),x=r.useMemo(()=>K(s,C).map(b=>({id:b.key,label:b.label,renderHead:b.renderHead,className:b.className??"",sortable:b.sortable??!0,sortOptions:b.sortOptions})),[s,a,t,C]);return e.jsx("thead",{className:"table-headers-row",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"table-headers-column table-headers-checkbox",children:c?e.jsx("input",{type:"checkbox",ref:u,checked:p?.allSelected??!1,onChange:c,"aria-label":t("_accessibility:components.table.selectAllRows")}):null}),l&&e.jsx("th",{scope:"col",className:"table-headers-action",children:e.jsx("span",{children:t("_accessibility:labels.actions")})}),x.map(b=>e.jsx("th",{scope:"col",className:`table-headers-column ${b.className}`,children:e.jsxs(G.Button,{disabled:!b.sortable,onClick:()=>o(b.id,i),className:"table-headers-cell",children:[b.renderHead?b.renderHead():e.jsx("span",{className:"table-headers-label",children:b.label}),b.sortable&&d===b.id&&e.jsx("span",{children:m===je.SortOrder.ASC?b.sortOptions?.icons?.asc??e.jsx(O.ChevronUp,{className:b.sortOptions?.icons?.className??"table-headers-sort-indicator"}):b.sortOptions?.icons?.desc??e.jsx(O.ChevronDown,{className:b.sortOptions?.icons?.className??"table-headers-sort-indicator"})})]})},b.id))]})})}function ne(n){const{columns:t}=n,{hiddenColumns:a,toggleColumn:s}=I.useTableOptions(),{t:l}=A.useTranslation(),[i,p]=r.useState(!1),c=r.useRef(null),u=r.useMemo(()=>K(t.filter(d=>d.hideable!==!1&&d.display!=="none"),[]),[t]),o=r.useCallback(()=>{p(d=>!d)},[]),m=r.useCallback(d=>{s(d)},[s]);return u.length===0?null:e.jsxs("div",{className:"column-visibility-menu",ref:c,children:[e.jsx(D.IconButton,{icon:e.jsx(O.TableColumns,{className:"column-visibility-icon"}),className:"normal column-visibility-trigger","aria-haspopup":"true","aria-expanded":i,onClick:o,children:e.jsx("span",{className:"table-header-sr",children:l("_accessibility:buttons.columns")})}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"column-visibility-backdrop",onClick:()=>p(!1)}),e.jsx("div",{className:"column-visibility-dropdown",role:"menu",children:u.map(d=>e.jsx(P.CheckInput,{checked:!a.includes(d.key),onChange:()=>m(d.key),label:d.label??d.key,containerClassName:"column-visibility-item"},d.key))})]})]})}const se=n=>{const{items:t,text:a,id:s,onClearFilter:l}=n;return e.jsx(J.Chip,{text:`${a}: ${t.map(i=>i.value??i.name).join(", ")}`,onDelete:()=>l(s)})},le=n=>{const{end:t,start:a,text:s,id:l,onClearFilter:i}=n,p=c=>c!==null&&typeof c<"u"&&c!=="";return e.jsx(J.Chip,{text:`${s}: ${p(a)?a:"♾️"} - ${p(t)?t:"♾️"}`,onDelete:()=>i(l)})},Ne=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&("start"in n||"end"in n),ae=n=>{const{filtersDefinition:t}=n,a=r.useMemo(()=>{const c={};return t.forEach(u=>{c[u.propertyName]=u.label??u.propertyName}),c},[t]),{filters:s,clearFilters:l}=I.useTableOptions(),i=r.useMemo(()=>Object.keys(s),[s]),p=r.useCallback(c=>{const u=s[c];return Ne(u)?e.jsx(le,{id:c,text:a[c],start:u.start,end:u.end,onClearFilter:l}):Array.isArray(u)?e.jsx(se,{id:c,text:a[c],items:u,onClearFilter:l}):e.jsx(J.Chip,{text:`${a[c]}: ${u?.value??u?.name??u}`,onDelete:()=>l(c)})},[s,a,l]);return e.jsx("ul",{className:"active-filters-main",children:i?.map(c=>e.jsx("li",{children:p(c)},c))})};function ye(n){const{propertyName:t,label:a,placeholder:s,options:l,multiple:i=!0}=n,{currentFilters:p,setCurrentFilters:c}=k.useFilters(),u=r.useMemo(()=>{const m=p[t]?.value;return typeof m>"u"?null:m},[p,t]),o=r.useCallback(m=>{c({type:k.FiltersActions.update,toUpdate:{[t]:{value:m}}})},[t,c]);return e.jsx(P.AutocompleteInput,{value:u,label:a,options:l,multiple:i,helperTextClassName:"hidden",containerClassName:"options-widget-container",onChange:o,placeholder:s})}const ve=n=>{const{propertyName:t,label:a}=n,{currentFilters:s,setCurrentFilters:l}=k.useFilters(),i=r.useMemo(()=>s[t]?.value??"",[s]),p=r.useCallback(c=>{l({type:k.FiltersActions.update,toUpdate:{[t]:{value:c.target.checked}}})},[]);return e.jsx(P.CheckInput,{label:a,checked:i??!1,onChange:p})};function we(n){const{propertyName:t,options:a,label:s,placeholder:l}=n,{currentFilters:i,setCurrentFilters:p}=k.useFilters(),c=r.useMemo(()=>{const o=i[t]?.value;if(o===null||typeof o>"u")return a[0]?.id??"";if(typeof o=="object"&&!Array.isArray(o)){const m=o;return m.id??m.value??""}return o},[i,a,t]),u=r.useCallback(o=>{const m=a.find(d=>String(d.id)===o.target.value);p({type:k.FiltersActions.update,toUpdate:{[t]:{value:m?.id??o.target.value}}})},[a,t,p]);return e.jsx(P.SelectInput,{value:c,label:s,options:a,helperTextClassName:"hidden",containerClassName:"options-widget-container",onChange:u,placeholder:l})}const Te=n=>{const{propertyName:t,label:a,placeholder:s}=n,{currentFilters:l,setCurrentFilters:i}=k.useFilters(),p=r.useMemo(()=>l[t]?.value??"",[l]),c=r.useCallback(u=>{i({type:k.FiltersActions.update,toUpdate:{[t]:{value:u.target.value}}})},[]);return e.jsx(P.TextInput,{value:p??"",label:a,onChange:c,containerClassName:"input-widget-container",helperTextClassName:"",placeholder:s})},Q=n=>{const{propertyName:t,label:a,inputType:s}=n,{t:l}=A.useTranslation(),{currentFilters:i,setCurrentFilters:p}=k.useFilters(),c=r.useRef(null),u=r.useRef(null),o=r.useCallback(d=>{p({type:k.FiltersActions.update,toUpdate:{[t]:{value:{end:u?.current?.value??null,start:d.target.value}}}})},[]),m=r.useCallback(d=>{p({type:k.FiltersActions.update,toUpdate:{[t]:{value:{start:c?.current?.value??null,end:d.target.value}}}})},[]);return e.jsxs("div",{className:"range-widget-container",children:[e.jsx("p",{className:"text-input-label input-widget-label input-label-normal",children:a}),e.jsxs("div",{className:"range-widget-row",children:[e.jsx(P.TextInput,{value:i[t]?.value?.start??"",placeholder:l("_accessibility:components.table.filters.range.start"),type:s,ref:c,onChange:o,containerClassName:"input-widget-container",helperTextClassName:""}),e.jsx(P.TextInput,{value:i[t]?.value?.end??"",placeholder:l("_accessibility:components.table.filters.range.end"),type:s,ref:u,onChange:m,containerClassName:"input-widget-container",helperTextClassName:""})]})]})},ie=n=>{switch(n.type){case z.FilterTypes.text:return e.jsx(Te,{...n});case z.FilterTypes.number:return e.jsx(Q,{...n,inputType:"number"});case z.FilterTypes.date:return e.jsx(Q,{...n,inputType:"date"});case z.FilterTypes.select:return e.jsx(we,{...n});case z.FilterTypes.autocomplete:return e.jsx(ye,{...n});case z.FilterTypes.check:return e.jsx(ve,{...n})}return e.jsx(e.Fragment,{})},re=n=>{const{filters:t=[],show:a,handleShow:s}=n,{onFilterApply:l}=I.useTableOptions(),{currentFilters:i,setCurrentFilters:p}=k.useFilters(),{t:c}=A.useTranslation(),u=r.useRef(null);return r.useEffect(()=>{const o=({target:d})=>{u.current&&(d?.closest(".filter-dropdown-trigger")||!a||u.current.contains(d)||s(!1))},m=({code:d})=>{!a||d!=="Escape"||s(!1)};return document.addEventListener("click",o),document.addEventListener("keydown",m),()=>{document.removeEventListener("click",o),document.removeEventListener("keydown",m)}},[s,a]),e.jsx("div",{className:`filter-dropdown-backdrop ${a?"opened":"closed"}`,children:e.jsxs("div",{className:"filter-popup",ref:u,children:[e.jsx("div",{className:"filter-title",children:c("_accessibility:buttons.filters")}),e.jsx("ul",{className:"filter-container",children:t.map(o=>e.jsx("li",{className:"filter-container-item",children:ie(o)},o.propertyName))}),e.jsx("div",{className:"filter-footer",children:e.jsxs("ul",{className:"filter-buttons-row",children:[e.jsx("li",{children:e.jsx(G.Button,{type:"button",variant:"submit",onClick:()=>p({type:k.FiltersActions.reset,filters:t}),className:"filter-dropdown-button filter-dropdown-cancel",children:c("_accessibility:buttons.clear")})}),e.jsx("li",{children:e.jsx(G.Button,{type:"button",variant:"submit",color:"primary",className:"filter-dropdown-button filter-dropdown-submit",onClick:()=>{s(!1),l(i)},children:c("_accessibility:buttons.applyFilters")})})]})})]})})},oe=()=>{const{t:n}=A.useTranslation(),{total:t,pageSize:a,pageSizes:s,currentPage:l}=I.useTableOptions(),i=(l+1)*a>t?t:(l+1)*a;return e.jsxs("div",{className:"table-navigation-sizes",children:[s[0]<t&&e.jsx(e.Fragment,{children:e.jsxs("p",{children:[l*a+1," - ",i," ",n("_accessibility:components.table.of")]})}),e.jsx("p",{children:t})]})};function Se(){const{t:n}=A.useTranslation(),{total:t,pageSize:a,currentPage:s,setCurrentPage:l}=I.useTableOptions(),i=r.useMemo(()=>{const p=Math.ceil(t/a);return Array.from({length:p},(c,u)=>({id:u,value:u+1}))},[t,a]);return e.jsxs("div",{className:"jump-to-page",children:[e.jsx("p",{children:n("_accessibility:components.table.jumpToPage")}),e.jsx(P.SelectInput,{value:s,options:i,inputClassName:"jump-to-page-input",containerClassName:"jump-to-page-input-container",helperTextClassName:"hidden",onChange:p=>l(Number(p.target.value))})]})}const ce=()=>{const{t:n}=A.useTranslation(),{total:t,pageSize:a,currentPage:s,setCurrentPage:l}=I.useTableOptions(),i=Math.ceil(t/a),p=s<i-1;return e.jsxs("div",{className:"table-navigation-pages",children:[e.jsx(D.IconButton,{icon:e.jsx(O.ChevronLeft,{className:"table-navigation-icon"}),className:"table-navigation-buttons",disabled:s===0,"aria-label":n("_accessibility:buttons.previous"),name:n("_accessibility:buttons.previous"),onClick:()=>l(s-1)}),e.jsx(D.IconButton,{icon:e.jsx(O.ChevronRight,{className:"table-navigation-icon"}),disabled:!p,className:"table-navigation-buttons",name:n("_accessibility:buttons.next"),"aria-label":n("_accessibility:buttons.next"),onClick:()=>{p&&l(s+1)}})]})};function ue(){const{t:n}=A.useTranslation(),{pageSizes:t,pageSize:a,setPageSize:s}=I.useTableOptions(),l=r.useMemo(()=>t?.map(i=>({id:i,value:i})),[t]);return e.jsxs("div",{className:"page-size",children:[e.jsx("p",{children:n("_accessibility:components.table.pageSizes")}),e.jsx(P.SelectInput,{value:a,options:l,inputClassName:"page-size-input",containerClassName:"page-size-input-container",helperTextClassName:"hidden",onChange:i=>s(Number(i.target.value))})]})}function de(){return e.jsxs("div",{className:"table-footer",children:[e.jsx(Se,{}),e.jsx(ue,{}),e.jsx(oe,{}),e.jsx(ce,{})]})}const ke=n=>n,pe=n=>{const{t}=A.useTranslation(),{hiddenColumns:a}=I.useTableOptions(),{columns:s,softDeleteProperty:l="deletedAt",data:i,actions:p,selectedRows:c,expandedRows:u=[],onRowSelectionChange:o,onRowExpand:m}=n,d=r.useMemo(()=>K(s,a),[s,a]),C=r.useMemo(()=>new Map(u.map(x=>[x.rowId,x])),[u]);return i?.map(x=>{const b=c.has(x.id),y=C.get(x.id),R=!!y,_=d.length+1+(p?1:0);return e.jsxs(r.Fragment,{children:[e.jsxs("tr",{className:`table-row ${m?"expandable":""} ${x[l]?"deleted-class":""} ${b?"selected":""} ${R?"expanded":""}`,onClick:()=>m?.(x),children:[e.jsx("td",{className:"table-row-cell table-row-checkbox",children:e.jsx("input",{type:"checkbox",checked:b,onClick:v=>v.stopPropagation(),onChange:()=>o(x),"aria-label":t("_accessibility:components.table.selectRow")})}),p?e.jsx("td",{className:"w-px",children:e.jsx("div",{className:"table-row-cell-action",children:(()=>{const v=p(x).filter(g=>!g.hidden),j=v.filter(g=>g.sticky),w=v.filter(g=>!g.sticky);return e.jsxs(e.Fragment,{children:[j.map(g=>e.jsx(Y.Tooltip,{content:g.tooltip,children:e.jsx(X,{...g,onClick:()=>g.onClick(x),className:"row-table-action"})},g.id)),w.length>0&&e.jsx(ee,{actions:w})]})})()})}):null,d?.map((v,j)=>{const w=x[v.key],g=v.renderBody?v.renderBody(w,x):ke(w);return e.jsx("td",{className:`table-row-cell ${j===0?"basic":""} ${v.className??""}`,children:m&&j===0?e.jsxs("div",{className:"table-row-expand-content",children:[e.jsx("span",{className:"table-row-expand-indicator","aria-hidden":!0,"data-state":R?"expanded":"collapsed",children:R?e.jsx(O.ChevronUp,{className:"table-row-expand-chevron"}):e.jsx(O.ChevronDown,{className:"table-row-expand-chevron"})}),e.jsx("div",{className:"table-row-expand-value",children:g})]}):g},v.key)})]}),R&&y?.content!==null&&typeof y?.content<"u"&&e.jsx("tr",{className:"table-row-expanded",children:e.jsx("td",{className:"table-row-expanded-cell",colSpan:_,children:e.jsx("div",{className:`table-row-expanded-content ${y.isVisible?"open":"closed"}`,children:e.jsx("div",{className:"table-row-expanded-inner",children:y.content})})})})]},x.id)})};function me(){const{t:n}=A.useTranslation();return e.jsx("div",{className:"table-empty",children:e.jsx("p",{children:n("_accessibility:components.table.empty")})})}const he=n=>{const{columns:t,title:a,isLoading:s,toolbar:l,filterOptions:i,canHideColumns:p=!1,canReset:c=!1}=n,{countOfFilters:u,resetTableOptions:o}=I.useTableOptions(),{t:m}=A.useTranslation(),d=r.useMemo(()=>t?[...t].sort((j,w)=>(w.pos??0)-(j.pos??0)).filter(j=>!!j.filterOptions).map(j=>({...j.filterOptions,label:j.filterOptions?.label??j.label,propertyName:j.key})):[],[t]),[C,x]=r.useState(!1),b=r.useCallback(j=>{i?.dropdown?.setOpened?i.dropdown.setOpened(j??!1):x(j??!1)},[i]),y=r.useMemo(()=>i?.dropdown?.opened??C,[i,C]),R=d.length>0,_=R&&i?.button?.hide!==!0,v=R&&y;return e.jsxs("div",{className:`table-header ${v?"showing-filters":""}`,children:[e.jsxs("div",{children:[a&&e.jsx("h1",{className:"table-header-title",children:a}),s?null:e.jsxs("div",{className:"table-header-content",children:[l,p&&t&&e.jsx(ne,{columns:t}),c&&e.jsx(D.IconButton,{icon:e.jsx(O.BarsStaggered,{className:"reset-table-icon"}),className:"normal",onClick:o,children:e.jsx("span",{className:"table-header-sr",children:m("_accessibility:buttons.reset")})}),_&&e.jsxs(D.IconButton,{icon:i?.button?.icon??e.jsx(O.Filters,{className:"filter-dropdown-trigger-icon"}),className:"filter-dropdown-button normal filter-dropdown-trigger","aria-haspopup":"true",onClick:()=>b(!y),"aria-expanded":y,children:[e.jsx(fe.Badge,{count:u,className:`${u>0?"show":"hide"} `}),e.jsx("span",{className:"table-header-sr",children:m("_accessibility:buttons.filters")}),e.jsx("wbr",{})]})]})]}),R&&e.jsx(re,{filters:d,show:v,handleShow:b,options:i}),e.jsx(ae,{filtersDefinition:d})]})};function be({count:n,multiActions:t,onActionClick:a}){const{t:s}=A.useTranslation();return e.jsxs("div",{className:"table-selection-bar",children:[e.jsx("p",{className:"table-selection-bar-count",children:s("_accessibility:components.table.selectedCount",{count:n})}),t.length>0&&e.jsx("div",{className:"table-selection-bar-actions",children:t.map(l=>e.jsx(Y.Tooltip,{content:l.tooltip,children:e.jsx(D.IconButton,{icon:l.icon,className:"multi-table-action",onClick:()=>a(l),disabled:l.disabled,"aria-label":l.tooltip})},l.id))})]})}const W=220;function Re({data:n,allowMultipleExpandedRows:t,controlledExpandedRowId:a,onExpandedRowChange:s,onRowExpand:l,findRowById:i}){const[p,c]=r.useState(null),[u,o]=r.useState(null),[m,d]=r.useState(null),[C,x]=r.useState(null),[b,y]=r.useState(!1),[R,_]=r.useState(new Set),[v,j]=r.useState([]),w=r.useRef(null),g=r.useRef(null),q=r.useRef(new Map),E=typeof a<"u",M=t&&!E,T=E?a??null:p,V=r.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null)},[]),F=r.useCallback(h=>{if(typeof h<"u"){const f=q.current.get(h);if(!f)return;clearTimeout(f),q.current.delete(h);return}q.current.forEach(f=>clearTimeout(f)),q.current.clear()},[]),L=r.useCallback(h=>{F(h),j(f=>f.some(S=>S.rowId===h)?f.map(S=>S.rowId===h?{...S,isVisible:!1}:S):f),q.current.set(h,setTimeout(()=>{j(f=>f.filter(N=>N.rowId!==h)),q.current.delete(h)},W))},[F]),U=r.useCallback((h,f)=>{F(h),j(N=>N.some($=>$.rowId===h)?N.map($=>$.rowId===h?{...$,content:f,isVisible:!1}:$):[...N,{rowId:h,content:f,isVisible:!1}]),requestAnimationFrame(()=>{j(N=>N.map(S=>S.rowId===h?{...S,isVisible:!0}:S))})},[F]);r.useEffect(()=>{if(!M)return;const h=new Set(n.map(f=>f.id));_(f=>{const N=new Set;return f.forEach(S=>{if(h.has(S)){N.add(S);return}F(S)}),N}),j(f=>(f.forEach(N=>{h.has(N.rowId)||F(N.rowId)}),f.filter(N=>h.has(N.rowId))))},[n,M,F]),r.useEffect(()=>{if(M)return;if(T===null){o(null),E&&(w.current=null);return}i(T)||(E||c(null),o(null),E&&(w.current=null))},[n,T,i,E,M]),r.useEffect(()=>{if(!M){if(V(),T===null||u===null){if(m===null){y(!1),x(null);return}y(!1),g.current=setTimeout(()=>{d(null),x(null),g.current=null},W);return}if(m===null){d(T),x(u),requestAnimationFrame(()=>y(!0));return}if(m===T){x(u),requestAnimationFrame(()=>y(!0));return}y(!1),g.current=setTimeout(()=>{d(T),x(u),requestAnimationFrame(()=>y(!0)),g.current=null},W)}},[V,u,T,M,m]),r.useEffect(()=>()=>{V(),F()},[V,F]),r.useEffect(()=>{if(!E)return;if(T===null){o(null),w.current=null;return}const h=i(T);if(!h){o(null),w.current=null;return}const f=w.current;o(l?.(h,f)??null),w.current=h},[T,i,E,l]);const xe=r.useCallback(h=>{if(M){if(R.has(h.id)){_(H=>{const B=new Set(H);return B.delete(h.id),B}),L(h.id),s?.(null,h);return}_(H=>{const B=new Set(H);return B.add(h.id),B});const $=l?.(h,null)??null;$!==null&&typeof $<"u"?U(h.id,$):(F(h.id),j(H=>H.filter(B=>B.rowId!==h.id))),s?.(h,null);return}const f=T===h.id,N=f?h:i(T);if(E){s?.(f?null:h,N);return}if(f){c(null),o(null),s?.(null,h);return}c(h.id),o(l?.(h,N)??null),s?.(h,N)},[T,L,F,U,i,R,E,M,s,l]);return{expandedRowsToRender:r.useMemo(()=>M?v:m===null||C===null||typeof C>"u"?[]:[{rowId:m,content:C,isVisible:b}],[b,M,C,m,v]),onRowExpandChange:xe}}function Fe({actions:n,selectedRowsData:t}){const a=r.useMemo(()=>!n||!t.length?[]:t.reduce((l,i,p)=>{const c=n(i).filter(o=>o.multiple&&!o.hidden);if(p===0)return c;const u=new Map(l.map(o=>[o.id,o]));return c.reduce((o,m)=>{const d=u.get(m.id);return d&&o.push({...d,...m,disabled:m.disabled||d.disabled}),o},[])},[]),[n,t]),s=r.useCallback(l=>{if(t.length){if(l.onMultipleClick){l.onMultipleClick(t);return}t.forEach(i=>l.onClick(i))}},[t]);return{multiActions:a,handleMultipleActionClick:s}}function Ae({data:n,onRowSelect:t,onSelectedRowsChange:a}){const[s,l]=r.useState(new Set),i=r.useMemo(()=>n?.filter(o=>s.has(o.id))??[],[n,s]);r.useEffect(()=>{if(!n?.length){l(new Set);return}l(o=>{const m=new Set,d=new Set(n.map(C=>C.id));return o.forEach(C=>{d.has(C)&&m.add(C)}),m})},[n]),r.useEffect(()=>{a&&a(i)},[i,a]);const p=r.useCallback(o=>{l(m=>{const d=new Set(m);return d.has(o.id)?(d.delete(o.id),t?.(o,!1)):(d.add(o.id),t?.(o,!0)),d})},[t]),c=r.useCallback(()=>{l(o=>{const m=new Set(o),d=n??[],C=d.every(x=>m.has(x.id));return d.forEach(x=>{const b=m.has(x.id);C?b&&(m.delete(x.id),t?.(x,!1)):b||(m.add(x.id),t?.(x,!0))}),m})},[n,t]),u=r.useMemo(()=>{if(!n?.length)return{allSelected:!1,hasSomeSelected:!1};const o=n.every(d=>s.has(d.id)),m=n.some(d=>s.has(d.id));return{allSelected:o,hasSomeSelected:m}},[n,s]);return{selectedRows:s,selectedRowsData:i,selectionState:u,onRowSelectionChange:p,onToggleAllRows:c}}function Ee(n){const{data:t,onSort:a,entity:s="",isLoading:l=!1,actions:i,columns:p=[],contentClassName:c="",className:u="",softDeleteProperty:o="deletedAt",onRowSelect:m,onSelectedRowsChange:d,allowMultipleExpandedRows:C=!1,expandedRowId:x,onExpandedRowChange:b,onRowExpand:y,...R}=n,_=r.useMemo(()=>!t?.length,[t]),v=r.useCallback(L=>L===null?null:t.find(U=>U.id===L)??null,[t]),{selectedRows:j,selectedRowsData:w,selectionState:g,onRowSelectionChange:q,onToggleAllRows:E}=Ae({data:t,onRowSelect:m,onSelectedRowsChange:d}),{expandedRowsToRender:M,onRowExpandChange:T}=Re({data:t,allowMultipleExpandedRows:C,controlledExpandedRowId:x,onExpandedRowChange:b,onRowExpand:y,findRowById:v}),{multiActions:V,handleMultipleActionClick:F}=Fe({actions:i,selectedRowsData:w});return e.jsx(k.FiltersProvider,{children:e.jsxs("div",{className:`${u} table-main`,children:[e.jsx(he,{columns:p,isLoading:l,...R}),l?e.jsx(Ce.Loading,{className:"table-loading"}):e.jsx(e.Fragment,{children:_?e.jsx(me,{}):e.jsxs(e.Fragment,{children:[!!w.length&&e.jsx(be,{count:w.length,multiActions:V,onActionClick:F}),e.jsx("div",{className:`${c} table-body`,children:e.jsxs("table",{className:"table-content",children:[e.jsx(te,{entity:s,columns:p,onSortCallback:a,hasAction:!!i,selectionState:g,onToggleAllRows:E}),e.jsx("tbody",{children:e.jsx(pe,{data:t,actions:i,columns:p,softDeleteProperty:o,selectedRows:j,expandedRows:M,onRowSelectionChange:q,onRowExpand:y?T:void 0})})]})}),e.jsx(de,{})]})})]})})}exports.Action=X;exports.Actions=Z;exports.ActionsDropdown=ee;exports.ActiveFilters=ae;exports.ArrayChip=se;exports.ColumnVisibilityMenu=ne;exports.Columns=te;exports.CountOfTotal=oe;exports.FilterDropdown=re;exports.Footer=de;exports.Navigation=ce;exports.PageSize=ue;exports.RangeChip=le;exports.Rows=pe;exports.Table=Ee;exports.TableEmpty=me;exports.TableHeader=he;exports.TableSelectionBar=be;exports.renderFilterComponent=ie;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./Table.css";
|
|
2
2
|
import { jsxs as b, jsx as e, Fragment as q } from "react/jsx-runtime";
|
|
3
3
|
import { useState as M, useRef as j, useEffect as I, useMemo as S, useCallback as x, Fragment as de } from "react";
|
|
4
|
-
import { u as G, a as B, F as ue } from "./FiltersProvider-
|
|
4
|
+
import { u as G, a as B, F as ue } from "./FiltersProvider-iOkSYSFZ.js";
|
|
5
5
|
import { E as pe, c as le, C as ae, T as me, a as he, b as fe, B as be, F as ge } from "./TableColumns-CIddkosX.js";
|
|
6
|
-
import { C as ie, A as Ne, S as ee, T as Y } from "./SelectInput-
|
|
7
|
-
import { u as P } from "./TableOptionsProvider-
|
|
6
|
+
import { C as ie, A as Ne, S as ee, T as Y } from "./SelectInput-Dm7gv03Z.js";
|
|
7
|
+
import { u as P } from "./TableOptionsProvider-Dzq4dOu8.js";
|
|
8
8
|
import { u as O } from "./TranslationProvider-BR4s--Vu.js";
|
|
9
9
|
import { I as H } from "./IconButton-BpsTEj0z.js";
|
|
10
10
|
import { B as Ce } from "./Badge-CIeYthEy.js";
|
package/dist/Table.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Table-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Table-C03frnWb.cjs");exports.ActiveFilters=e.ActiveFilters;exports.ArrayChip=e.ArrayChip;exports.ColumnVisibilityMenu=e.ColumnVisibilityMenu;exports.Columns=e.Columns;exports.CountOfTotal=e.CountOfTotal;exports.FilterDropdown=e.FilterDropdown;exports.Footer=e.Footer;exports.Navigation=e.Navigation;exports.PageSize=e.PageSize;exports.RangeChip=e.RangeChip;exports.Rows=e.Rows;exports.Table=e.Table;exports.TableEmpty=e.TableEmpty;exports.TableHeader=e.TableHeader;exports.TableSelectionBar=e.TableSelectionBar;exports.renderFilterComponent=e.renderFilterComponent;
|
package/dist/Table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as s, b as o, a as i, C as r, c as t, F as l, d as n, N as C, P as b, R as p, e as T, h as m, T as F, f as d, g, r as u } from "./Table-
|
|
1
|
+
import { A as s, b as o, a as i, C as r, c as t, F as l, d as n, N as C, P as b, R as p, e as T, h as m, T as F, f as d, g, r as u } from "./Table-DO7FFraQ.js";
|
|
2
2
|
export {
|
|
3
3
|
s as ActiveFilters,
|
|
4
4
|
o as ArrayChip,
|
package/dist/TableOptions.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./TableOptionsProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./TableOptionsProvider-bPNtpa4V.cjs");exports.TableOptionsProvider=e.TableOptionsProvider;exports.useTableOptions=e.useTableOptions;
|
package/dist/TableOptions.js
CHANGED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { jsx as tt } from "react/jsx-runtime";
|
|
2
|
+
import { S as f } from "./query-CwuehjY1.js";
|
|
3
|
+
import { createContext as et, useMemo as a, useState as l, useCallback as o, useContext as rt } from "react";
|
|
4
|
+
const Q = [20, 50, 100], nt = "id", R = (t, s) => {
|
|
5
|
+
const n = Number(t);
|
|
6
|
+
return !Number.isFinite(n) || n <= 0 ? s : Math.floor(n);
|
|
7
|
+
}, it = (t, s) => {
|
|
8
|
+
const n = Number(t);
|
|
9
|
+
return !Number.isFinite(n) || n < 0 ? s : Math.floor(n);
|
|
10
|
+
}, st = (t) => {
|
|
11
|
+
if (!Array.isArray(t)) return [...Q];
|
|
12
|
+
const s = Array.from(
|
|
13
|
+
new Set(
|
|
14
|
+
t.map((n) => Number(n)).filter((n) => Number.isFinite(n) && n > 0).map((n) => Math.floor(n))
|
|
15
|
+
)
|
|
16
|
+
);
|
|
17
|
+
return s.length ? s : [...Q];
|
|
18
|
+
}, ot = (t) => typeof t != "string" || !t.trim() ? nt : t, at = (t) => t === f.ASC || t === f.DESC ? t : f.DESC, ut = (t) => !t || typeof t != "object" ? {} : { ...t }, U = et(void 0), z = (t) => {
|
|
19
|
+
if (t === null || typeof t > "u") return !1;
|
|
20
|
+
if (typeof t == "string")
|
|
21
|
+
return t.trim().length > 0;
|
|
22
|
+
if (Array.isArray(t))
|
|
23
|
+
return t.length > 0;
|
|
24
|
+
if (typeof t == "object") {
|
|
25
|
+
const s = t;
|
|
26
|
+
return "start" in s || "end" in s ? z(s.start) || z(s.end) : !0;
|
|
27
|
+
}
|
|
28
|
+
return !0;
|
|
29
|
+
}, gt = (t) => {
|
|
30
|
+
const { children: s, defaultHiddenColumns: n = [], initialState: W } = t, {
|
|
31
|
+
currentPage: A,
|
|
32
|
+
pageSize: p,
|
|
33
|
+
pageSizes: T,
|
|
34
|
+
sortingBy: j,
|
|
35
|
+
sortingOrder: w,
|
|
36
|
+
filters: B
|
|
37
|
+
} = W ?? {}, m = a(() => {
|
|
38
|
+
const e = st(T), r = R(
|
|
39
|
+
p,
|
|
40
|
+
e[0]
|
|
41
|
+
);
|
|
42
|
+
return e.includes(r) ? e : [r, ...e];
|
|
43
|
+
}, [p, T]), X = a(() => R(p, m[0]), [p, m]), O = a(() => it(A, 0), [A]), M = a(() => ot(j), [j]), N = a(() => at(w), [w]), V = a(() => ut(B), [B]), [g, Y] = l(0), [c, Z] = l(X), [E, u] = l(O), [h, b] = l(M), [d, C] = l(N), [P, S] = l(V), [D, F] = l([
|
|
44
|
+
...n
|
|
45
|
+
]), y = o(
|
|
46
|
+
(e, r) => r <= 0 ? 0 : Math.max(0, Math.ceil(e / r) - 1),
|
|
47
|
+
[]
|
|
48
|
+
), H = o(
|
|
49
|
+
(e) => {
|
|
50
|
+
const r = Number.isFinite(e) ? Math.max(0, e) : 0;
|
|
51
|
+
Y(r), u(
|
|
52
|
+
(i) => Math.min(i, y(r, c))
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
[y, c]
|
|
56
|
+
), I = o((e) => {
|
|
57
|
+
!Number.isFinite(e) || e <= 0 || (Z(e), u(0));
|
|
58
|
+
}, []), k = o(
|
|
59
|
+
(e) => {
|
|
60
|
+
if (!Number.isFinite(e)) return;
|
|
61
|
+
const r = Math.max(0, Math.floor(e));
|
|
62
|
+
if (g <= 0) {
|
|
63
|
+
u(r);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
u(Math.min(r, y(g, c)));
|
|
67
|
+
},
|
|
68
|
+
[y, c, g]
|
|
69
|
+
), q = o(
|
|
70
|
+
(e, r) => {
|
|
71
|
+
let i = d;
|
|
72
|
+
h === e && (d === f.ASC ? i = f.DESC : i = f.ASC), b(e), C(i), r && r(e, i);
|
|
73
|
+
},
|
|
74
|
+
[h, d]
|
|
75
|
+
), v = o((e) => {
|
|
76
|
+
const r = Object.entries(e).reduce(
|
|
77
|
+
(i, [$, x]) => (x && z(x.value) && (i[$] = x.value), i),
|
|
78
|
+
{}
|
|
79
|
+
);
|
|
80
|
+
S(r), u(0);
|
|
81
|
+
}, []), G = o(
|
|
82
|
+
(e) => {
|
|
83
|
+
S(e ? (r) => {
|
|
84
|
+
const i = { ...r };
|
|
85
|
+
return delete i[e], i;
|
|
86
|
+
} : {}), u(0);
|
|
87
|
+
},
|
|
88
|
+
[S]
|
|
89
|
+
), J = a(() => Object.keys(P).length, [P]), K = o((e) => {
|
|
90
|
+
F(
|
|
91
|
+
(r) => r.includes(e) ? r.filter((i) => i !== e) : [...r, e]
|
|
92
|
+
);
|
|
93
|
+
}, []), L = o(() => {
|
|
94
|
+
F([...n]), b(M), C(N), S({ ...V }), u(O);
|
|
95
|
+
}, [
|
|
96
|
+
n,
|
|
97
|
+
O,
|
|
98
|
+
V,
|
|
99
|
+
M,
|
|
100
|
+
N
|
|
101
|
+
]), _ = a(
|
|
102
|
+
() => ({
|
|
103
|
+
onSort: q,
|
|
104
|
+
total: g,
|
|
105
|
+
setTotal: H,
|
|
106
|
+
sortingBy: h,
|
|
107
|
+
setSortingBy: b,
|
|
108
|
+
sortingOrder: d,
|
|
109
|
+
setSortingOrder: C,
|
|
110
|
+
pageSize: c,
|
|
111
|
+
pageSizes: m,
|
|
112
|
+
setPageSize: I,
|
|
113
|
+
currentPage: E,
|
|
114
|
+
setCurrentPage: k,
|
|
115
|
+
filters: P,
|
|
116
|
+
onFilterApply: v,
|
|
117
|
+
clearFilters: G,
|
|
118
|
+
countOfFilters: J,
|
|
119
|
+
hiddenColumns: D,
|
|
120
|
+
toggleColumn: K,
|
|
121
|
+
setHiddenColumns: F,
|
|
122
|
+
resetTableOptions: L
|
|
123
|
+
}),
|
|
124
|
+
[
|
|
125
|
+
q,
|
|
126
|
+
g,
|
|
127
|
+
H,
|
|
128
|
+
h,
|
|
129
|
+
b,
|
|
130
|
+
d,
|
|
131
|
+
C,
|
|
132
|
+
c,
|
|
133
|
+
m,
|
|
134
|
+
I,
|
|
135
|
+
E,
|
|
136
|
+
k,
|
|
137
|
+
P,
|
|
138
|
+
v,
|
|
139
|
+
G,
|
|
140
|
+
J,
|
|
141
|
+
D,
|
|
142
|
+
K,
|
|
143
|
+
F,
|
|
144
|
+
L
|
|
145
|
+
]
|
|
146
|
+
);
|
|
147
|
+
return /* @__PURE__ */ tt(U.Provider, { value: _, children: s });
|
|
148
|
+
}, dt = () => {
|
|
149
|
+
const t = rt(U);
|
|
150
|
+
if (!t)
|
|
151
|
+
throw new Error("tableOptionsContext must be used within a Provider");
|
|
152
|
+
return t;
|
|
153
|
+
};
|
|
154
|
+
export {
|
|
155
|
+
gt as T,
|
|
156
|
+
dt as u
|
|
157
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const _=require("react/jsx-runtime"),l=require("./query-81BrXp3i.cjs"),r=require("react"),J=[20,50,100],$="id",K=(e,o)=>{const s=Number(e);return!Number.isFinite(s)||s<=0?o:Math.floor(s)},ee=(e,o)=>{const s=Number(e);return!Number.isFinite(s)||s<0?o:Math.floor(s)},te=e=>{if(!Array.isArray(e))return[...J];const o=Array.from(new Set(e.map(s=>Number(s)).filter(s=>Number.isFinite(s)&&s>0).map(s=>Math.floor(s))));return o.length?o:[...J]},re=e=>typeof e!="string"||!e.trim()?$:e,ne=e=>e===l.SortOrder.ASC||e===l.SortOrder.DESC?e:l.SortOrder.DESC,se=e=>!e||typeof e!="object"?{}:{...e},L=r.createContext(void 0),V=e=>{if(e===null||typeof e>"u")return!1;if(typeof e=="string")return e.trim().length>0;if(Array.isArray(e))return e.length>0;if(typeof e=="object"){const o=e;return"start"in o||"end"in o?V(o.start)||V(o.end):!0}return!0},ie=e=>{const{children:o,defaultHiddenColumns:s=[],initialState:Q}=e,{currentPage:x,pageSize:g,pageSizes:z,sortingBy:A,sortingOrder:k,filters:T}=Q??{},f=r.useMemo(()=>{const t=te(z),n=K(g,t[0]);return t.includes(n)?t:[n,...t]},[g,z]),U=r.useMemo(()=>K(g,f[0]),[g,f]),M=r.useMemo(()=>ee(x,0),[x]),P=r.useMemo(()=>re(A),[A]),F=r.useMemo(()=>ne(k),[k]),y=r.useMemo(()=>se(T),[T]),[c,W]=r.useState(0),[u,X]=r.useState(U),[j,a]=r.useState(M),[m,p]=r.useState(P),[d,b]=r.useState(F),[C,S]=r.useState(y),[w,O]=r.useState([...s]),h=r.useCallback((t,n)=>n<=0?0:Math.max(0,Math.ceil(t/n)-1),[]),B=r.useCallback(t=>{const n=Number.isFinite(t)?Math.max(0,t):0;W(n),a(i=>Math.min(i,h(n,u)))},[h,u]),q=r.useCallback(t=>{!Number.isFinite(t)||t<=0||(X(t),a(0))},[]),E=r.useCallback(t=>{if(!Number.isFinite(t))return;const n=Math.max(0,Math.floor(t));if(c<=0){a(n);return}a(Math.min(n,h(c,u)))},[h,u,c]),D=r.useCallback((t,n)=>{let i=d;m===t&&(d===l.SortOrder.ASC?i=l.SortOrder.DESC:i=l.SortOrder.ASC),p(t),b(i),n&&n(t,i)},[m,d]),H=r.useCallback(t=>{const n=Object.entries(t).reduce((i,[Z,N])=>(N&&V(N.value)&&(i[Z]=N.value),i),{});S(n),a(0)},[]),I=r.useCallback(t=>{S(t?n=>{const i={...n};return delete i[t],i}:{}),a(0)},[S]),v=r.useMemo(()=>Object.keys(C).length,[C]),R=r.useCallback(t=>{O(n=>n.includes(t)?n.filter(i=>i!==t):[...n,t])},[]),G=r.useCallback(()=>{O([...s]),p(P),b(F),S({...y}),a(M)},[s,M,y,P,F]),Y=r.useMemo(()=>({onSort:D,total:c,setTotal:B,sortingBy:m,setSortingBy:p,sortingOrder:d,setSortingOrder:b,pageSize:u,pageSizes:f,setPageSize:q,currentPage:j,setCurrentPage:E,filters:C,onFilterApply:H,clearFilters:I,countOfFilters:v,hiddenColumns:w,toggleColumn:R,setHiddenColumns:O,resetTableOptions:G}),[D,c,B,m,p,d,b,u,f,q,j,E,C,H,I,v,w,R,O,G]);return _.jsx(L.Provider,{value:Y,children:o})},oe=()=>{const e=r.useContext(L);if(!e)throw new Error("tableOptionsContext must be used within a Provider");return e};exports.TableOptionsProvider=ie;exports.useTableOptions=oe;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var h=require("./index.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./lib.cjs"),s=require("./query-81BrXp3i.cjs"),e=require("./Table-
|
|
1
|
+
var h=require("./index.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./lib.cjs"),s=require("./query-81BrXp3i.cjs"),e=require("./Table-C03frnWb.cjs"),a=require("./Badge-Z78MlGoQ.cjs"),u=require("./Button-BlYa3uPc.cjs"),p=require("./Chip-D17UJHW6.cjs"),c=require("./Dropdown-CR8mco5s.cjs"),t=require("./SelectInput-dYjrdopP.cjs"),C=require("./FileInput-CqzVk1gQ.cjs"),d=require("./IconButton-CVnmT2E9.cjs"),T=require("./Loading-CNECRan-.cjs"),r=require("./TableColumns-BjTNomZf.cjs"),F=require("./Close-O9P7wJGf.cjs"),b=require("./File-_Hjw2d3F.cjs"),v=require("./Tooltip-BSKAgRkc.cjs"),o=require("./FiltersProvider-CnrF3xWV.cjs"),i=require("./TableOptionsProvider-bPNtpa4V.cjs"),n=require("./TranslationProvider-Czr0WIDH.cjs");exports.FilterTypes=l.FilterTypes;exports.SortOrder=s.SortOrder;exports.Action=e.Action;exports.Actions=e.Actions;exports.ActionsDropdown=e.ActionsDropdown;exports.ActiveFilters=e.ActiveFilters;exports.ArrayChip=e.ArrayChip;exports.ColumnVisibilityMenu=e.ColumnVisibilityMenu;exports.Columns=e.Columns;exports.CountOfTotal=e.CountOfTotal;exports.FilterDropdown=e.FilterDropdown;exports.Footer=e.Footer;exports.Navigation=e.Navigation;exports.PageSize=e.PageSize;exports.RangeChip=e.RangeChip;exports.Rows=e.Rows;exports.Table=e.Table;exports.TableEmpty=e.TableEmpty;exports.TableHeader=e.TableHeader;exports.TableSelectionBar=e.TableSelectionBar;exports.renderFilterComponent=e.renderFilterComponent;exports.Badge=a.Badge;exports.Button=u.Button;exports.Chip=p.Chip;exports.Dropdown=c.Dropdown;exports.AutocompleteInput=t.AutocompleteInput;exports.CheckInput=t.CheckInput;exports.SelectInput=t.SelectInput;exports.State=t.State;exports.TextInput=t.TextInput;exports.helperTextStateClassName=t.helperTextStateClassName;exports.inputStateClassName=t.inputStateClassName;exports.labelStateClassName=t.labelStateClassName;exports.FileInput=C.FileInput;exports.IconButton=d.IconButton;exports.Loading=T.Loading;exports.BarsStaggered=r.BarsStaggered;exports.ChevronDown=r.ChevronDown;exports.ChevronLeft=r.ChevronLeft;exports.ChevronRight=r.ChevronRight;exports.ChevronUp=r.ChevronUp;exports.Ellipsis=r.Ellipsis;exports.Filters=r.Filters;exports.TableColumns=r.TableColumns;exports.Close=F.Close;exports.File=b.File;exports.Tooltip=v.Tooltip;exports.FiltersActions=o.FiltersActions;exports.FiltersProvider=o.FiltersProvider;exports.filtersReducer=o.filtersReducer;exports.initializer=o.initializer;exports.useFilters=o.useFilters;exports.TableOptionsProvider=i.TableOptionsProvider;exports.useTableOptions=i.useTableOptions;exports.TranslationProvider=n.TranslationProvider;exports.useTranslation=n.useTranslation;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
2
|
import { FilterTypes as o } from "./lib.js";
|
|
3
3
|
import { S as t } from "./query-CwuehjY1.js";
|
|
4
|
-
import { i as p, j as l, k as n, A as m, b as f, a as C, C as u, c as x, F as T, d as F, N as d, P as c, R as h, e as b, h as S, T as g, f as v, g as A, r as B } from "./Table-
|
|
4
|
+
import { i as p, j as l, k as n, A as m, b as f, a as C, C as u, c as x, F as T, d as F, N as d, P as c, R as h, e as b, h as S, T as g, f as v, g as A, r as B } from "./Table-DO7FFraQ.js";
|
|
5
5
|
import { B as w } from "./Badge-CIeYthEy.js";
|
|
6
6
|
import { B as N } from "./Button-D73-swfo.js";
|
|
7
7
|
import { C as R } from "./Chip-C5ogKbFn.js";
|
|
8
8
|
import { D as O } from "./Dropdown-D-fYEGo2.js";
|
|
9
|
-
import { A as L, C as k, S as z, a as j, T as H, h as M, i as U, l as V } from "./SelectInput-
|
|
9
|
+
import { A as L, C as k, S as z, a as j, T as H, h as M, i as U, l as V } from "./SelectInput-Dm7gv03Z.js";
|
|
10
10
|
import { F as G } from "./FileInput-Cr4TxWUg.js";
|
|
11
11
|
import { I as K } from "./IconButton-BpsTEj0z.js";
|
|
12
12
|
import { L as W } from "./Loading-B_c_4XLr.js";
|
|
@@ -14,8 +14,8 @@ import { B as Y, C as Z, a as _, b as $, c as aa, E as ea, F as sa, T as oa } fr
|
|
|
14
14
|
import { C as ta } from "./Close-rKC9AcNX.js";
|
|
15
15
|
import { F as pa } from "./File-BuJndWMv.js";
|
|
16
16
|
import { T as na } from "./Tooltip-B4E-FRwY.js";
|
|
17
|
-
import { a as fa, F as Ca, f as ua, i as xa, u as Ta } from "./FiltersProvider-
|
|
18
|
-
import { T as da, u as ca } from "./TableOptionsProvider-
|
|
17
|
+
import { a as fa, F as Ca, f as ua, i as xa, u as Ta } from "./FiltersProvider-iOkSYSFZ.js";
|
|
18
|
+
import { T as da, u as ca } from "./TableOptionsProvider-Dzq4dOu8.js";
|
|
19
19
|
import { T as ba, u as Sa } from "./TranslationProvider-BR4s--Vu.js";
|
|
20
20
|
export {
|
|
21
21
|
p as Action,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TableOptionsProviderPropsType } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Renders the TableOptionsProvider component.
|
|
4
4
|
* @param props - props parameter.
|
|
@@ -9,5 +9,5 @@ declare const TableOptionsProvider: (props: TableOptionsProviderPropsType) => im
|
|
|
9
9
|
* Provides the useTableOptions hook.
|
|
10
10
|
* @returns Function result.
|
|
11
11
|
*/
|
|
12
|
-
declare const useTableOptions: () => TableOptionsContextType;
|
|
12
|
+
declare const useTableOptions: () => import('./types').TableOptionsContextType;
|
|
13
13
|
export { TableOptionsProvider, useTableOptions };
|
|
@@ -25,7 +25,16 @@ export type TableOptionsContextType = {
|
|
|
25
25
|
export type TableOptionsProviderPropsType = {
|
|
26
26
|
children: ReactNode;
|
|
27
27
|
defaultHiddenColumns?: string[];
|
|
28
|
+
initialState?: TableOptionsProviderInitialStateType;
|
|
28
29
|
};
|
|
29
30
|
export type TableFilters = {
|
|
30
31
|
[key: string]: any;
|
|
31
32
|
};
|
|
33
|
+
export type TableOptionsProviderInitialStateType = {
|
|
34
|
+
currentPage?: number;
|
|
35
|
+
pageSize?: number;
|
|
36
|
+
pageSizes?: number[];
|
|
37
|
+
sortingBy?: string;
|
|
38
|
+
sortingOrder?: SortOrder;
|
|
39
|
+
filters?: TableFilters;
|
|
40
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SortOrder } from '../../lib';
|
|
2
|
+
import { TableFilters, TableOptionsContextType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a value into a positive integer.
|
|
5
|
+
*
|
|
6
|
+
* Falls back when the value is not finite or is less than or equal to `0`.
|
|
7
|
+
* @param value - Candidate value to parse.
|
|
8
|
+
* @param fallback - Fallback value used for invalid input.
|
|
9
|
+
* @returns A floored positive integer.
|
|
10
|
+
*/
|
|
11
|
+
export declare const parsePositiveInteger: (value: number | undefined, fallback: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* Normalizes a value into a non-negative integer.
|
|
14
|
+
*
|
|
15
|
+
* Falls back when the value is not finite or is below `0`.
|
|
16
|
+
* @param value - Candidate value to parse.
|
|
17
|
+
* @param fallback - Fallback value used for invalid input.
|
|
18
|
+
* @returns A floored non-negative integer.
|
|
19
|
+
*/
|
|
20
|
+
export declare const parseNonNegativeInteger: (value: number | undefined, fallback: number) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Parses page-size options ensuring they are unique, finite and positive.
|
|
23
|
+
*
|
|
24
|
+
* Invalid values are removed. If the resulting array is empty, defaults are returned.
|
|
25
|
+
* @param sizes - Optional page-size candidates.
|
|
26
|
+
* @returns A sanitized page-size list.
|
|
27
|
+
*/
|
|
28
|
+
export declare const parsePageSizes: (sizes: number[] | undefined) => number[];
|
|
29
|
+
/**
|
|
30
|
+
* Returns a valid sorting key.
|
|
31
|
+
*
|
|
32
|
+
* Blank or non-string values fallback to the default sorting property.
|
|
33
|
+
* @param sortingBy - Optional sorting key.
|
|
34
|
+
* @returns A non-empty sorting key.
|
|
35
|
+
*/
|
|
36
|
+
export declare const parseSortingBy: (sortingBy: string | undefined) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Validates the sorting order enum value.
|
|
39
|
+
* @param sortingOrder - Optional sorting order value.
|
|
40
|
+
* @returns The provided order when valid, otherwise `SortOrder.DESC`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const parseSortingOrder: (sortingOrder: SortOrder | undefined) => SortOrder;
|
|
43
|
+
/**
|
|
44
|
+
* Clones the filters object when it is valid.
|
|
45
|
+
* @param filters - Optional table filters state.
|
|
46
|
+
* @returns A shallow copy of filters, or an empty object for invalid input.
|
|
47
|
+
*/
|
|
48
|
+
export declare const parseFilters: (filters: TableFilters | undefined) => {
|
|
49
|
+
[x: string]: any;
|
|
50
|
+
};
|
|
51
|
+
export declare const TableOptionsContext: import('react').Context<TableOptionsContextType | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Checks whether a filter value should be considered active.
|
|
54
|
+
*
|
|
55
|
+
* Strings are trimmed, arrays must contain at least one element, and
|
|
56
|
+
* range-like objects (`{ start, end }`) are recursively validated.
|
|
57
|
+
* @param value - Filter value candidate.
|
|
58
|
+
* @returns `true` when the value contains meaningful filter data.
|
|
59
|
+
*/
|
|
60
|
+
export declare const hasMeaningfulFilterValue: (value: unknown) => boolean;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var X=require("./SelectInput.css");const l=require("react/jsx-runtime"),r=require("react"),K=require("./Chip-D17UJHW6.cjs"),_=require("./IconButton-CVnmT2E9.cjs"),z=require("./Close-O9P7wJGf.cjs"),G=r.forwardRef(function(s,p){const{state:f,value:t,onChange:a,options:j=[],name:$="",id:S="",label:k="",containerClassName:A="",inputContainerClassName:v="",helperText:I="",placeholder:T="",multiple:h=!1,...D}=s,[u,m]=r.useState("");r.useEffect(()=>{if(!h&&t&&!Array.isArray(t)){m(String(t.value??t.name??""));return}m("")},[h,t]);const[g,x]=r.useState(!1),[C,y]=r.useState(-1),o=r.useMemo(()=>j.filter(e=>{const n=String(e.value??e.name).toLowerCase().includes(u?.toLowerCase());return Array.isArray(t)&&t.length?n&&!t.some(d=>d.id===e.id):t&&!Array.isArray(t)?n&&t.id!==e.id:n}),[j,t,u]);r.useEffect(()=>{if(!g||!o.length){y(-1);return}y(0)},[g,o]);const c=r.useRef(null),N=r.useRef(null),[E,w]=r.useState(!1),i=r.useRef(null);r.useEffect(()=>{const e=d=>{c.current&&!c.current.contains(d.target)&&x(!1)},n=d=>{d.key==="Escape"&&x(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[]);const b=r.useCallback(e=>{m(e.target.value)},[]),R=r.useCallback(e=>{e?h?(m(""),Array.isArray(t)&&t.length?a([...t,e]):a([e])):(m(String(e.name??e.value??"")),a(e)):a(null),x(!1)},[h,a,t]),B=r.useCallback(e=>{if(!o.length){e.key==="Escape"&&x(!1);return}if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!g){x(!0),y(0);return}y(n=>{const d=n>=0?n:0;return e.key==="ArrowDown"?(d+1+o.length)%o.length:(d-1+o.length)%o.length});return}if(e.key==="Enter"&&g){e.preventDefault();const n=C>=0?C:0;R(o[n]);return}e.key==="Escape"&&g&&(e.preventDefault(),x(!1))},[R,C,g,o]),F=r.useCallback(e=>{if(!Array.isArray(t)){a(null);return}const n=t.filter((d,P)=>P!==e);n.length?a(n):a(null)},[a,t]),H=r.useCallback(()=>{Array.isArray(t)&&a([t[0]])},[a,t]);return r.useLayoutEffect(()=>{const e=i.current?.offsetWidth??0,n=c.current?.offsetWidth??0;w(e>n*.4)},[t]),l.jsxs("div",{className:`autocomplete-input-container ${A}`,ref:c,children:[l.jsxs("div",{className:"autocomplete-value-input-container",children:[l.jsx(U,{state:f,name:$,id:S,value:u,onChange:b,placeholder:T,helperText:I,onFocus:()=>x(!0),onKeyDown:B,label:k,containerClassName:`autocomplete-text-input ${v}`,ref:p??N,...D,children:!h&&t&&!Array.isArray(t)&&(t.value||t.name)&&l.jsx(_.IconButton,{icon:l.jsx(z.Close,{}),className:"autocomplete-delete-button",onClick:e=>{R(),e.stopPropagation()}})}),h&&Array.isArray(t)&&t.length?l.jsx("ul",{ref:i,className:"autocomplete-value-container",children:E?l.jsxs(l.Fragment,{children:[l.jsx("li",{children:l.jsx(K.Chip,{text:t[0]?.value??t[0]?.name,onDelete:e=>{F(0),e.stopPropagation()}})}),t.length>1&&l.jsx("li",{children:l.jsx(K.Chip,{text:`+${t.length-1}`,onDelete:e=>{H(),e.stopPropagation()}})})]}):t.map((e,n)=>l.jsx("li",{children:l.jsx(K.Chip,{text:String(e.value??e.name),onDelete:d=>{F(n),d.stopPropagation()}})},e.id??e.value??e.name))}):null]}),g&&l.jsx("ul",{className:"autocomplete-suggestions-container",style:{width:c.current?.offsetWidth},children:o.map(e=>l.jsx("li",{className:`autocomplete-suggestion-item ${e.id===o[C]?.id?"highlighted":""}`,onMouseEnter:()=>y(o.findIndex(n=>n.id===e.id)),onClick:n=>{R(e),n.stopPropagation()},children:e.value??e.name},e.id??e.value??e.name))})]})});var L=(s=>(s.error="error",s.good="good",s.default="default",s))(L||{});const q=s=>{switch(s){case"error":return"input-error";case"good":return"input-good";default:return"input-normal"}},O=s=>{switch(s){case"error":return"input-label-error";case"good":return"input-label-good";default:return"input-label-normal"}},M=s=>{switch(s){case"error":return"input-helper-text-error";case"good":return"input-helper-text-good";default:return"input-helper-text-normal"}},J=r.forwardRef(function(s,p){const{checked:f,onChange:t,name:a="",id:j="",label:$="",state:S=L.default,containerClassName:k="",inputClassName:A="",labelClassName:v="",...I}=s;return l.jsxs("label",{className:`input-check-container ${k}`,children:[l.jsx("input",{id:j,ref:p,name:a,type:"checkbox",checked:f,onChange:t,className:`input-check ${q(S)} ${A}`,...I}),l.jsx("span",{className:`input-check-label ${O(S)} ${v}`,children:$})]})}),W=s=>s==null?!1:Array.isArray(s)?s.length>0:`${s}`.length>0,U=r.forwardRef(function(s,p){const{children:f,state:t=L.default,label:a="",containerClassName:j="",inputClassName:$="",labelClassName:S="",helperText:k="",helperTextClassName:A="",value:v,defaultValue:I,onChange:T,onFocus:h,onBlur:D,...u}=s,m=v!==void 0,[g,x]=r.useState(()=>W(I)),[C,y]=r.useState(!1),o=m?W(v):g,c=u.type==="date",N=!!u.placeholder||C||c,E=b=>{m||x(b.currentTarget.value.length>0),T?.(b)},w=b=>{C||y(!0),h?.(b)},i=b=>{C||y(!0),D?.(b)};return l.jsxs("div",{className:`text-input-container ${j}`,children:[l.jsx("input",{ref:p,defaultValue:I,onChange:E,onFocus:w,onBlur:i,...m?{value:v}:{},className:`text-input ${q(t)} ${$} ${o?"has-value":""} ${u.placeholder?"has-placeholder":""} ${N?"keep-label-up":""}`,...u}),!!a&&l.jsxs("label",{htmlFor:u.id,className:`text-input-label ${O(t)} ${S}`,children:[a,u.required?" *":""]}),f,!!k&&l.jsx("p",{className:`text-input-helper-text ${M(t)} ${A}`,children:k})]})}),Q=r.forwardRef(function(s,p){const{value:f,onChange:t,options:a,containerClassName:j="",inputClassName:$="",labelClassName:S="",helperText:k="",helperTextClassName:A="",label:v="",placeholder:I="",name:T="",id:h="",state:D=L.default,native:u=!0,disabled:m,required:g,autoFocus:x,children:C,...y}=s,o=r.useRef(null),[c,N]=r.useState(!1),[E,w]=r.useState(-1),i=r.useMemo(()=>a.findIndex(e=>String(e.id)===String(f??a[0]?.id??"")),[a,f]),b=r.useMemo(()=>i>=0?a[i]:void 0,[a,i]);r.useEffect(()=>{if(!(u||!c)){if(!a.length){w(-1);return}w(i>=0?i:0)}},[u,a.length,i,c]),r.useEffect(()=>{if(u)return;const e=n=>{o.current&&!o.current.contains(n.target)&&N(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[u]);const R=r.useCallback(e=>{p&&(typeof p=="function"?p(e):p.current=e)},[p]),B=r.useCallback(e=>{if(!t)return;const n={target:{value:String(e)},currentTarget:{value:String(e)}};t(n)},[t]),F=r.useCallback(e=>{const n=a[e];n&&(B(n.id),N(!1))},[B,a]),H=r.useCallback(e=>{if(a.length){if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!c){N(!0);const n=i>=0?i:0;w(n);return}w(n=>{const d=n>=0?n:i;return e.key==="ArrowDown"?(d+1+a.length)%a.length:(d-1+a.length)%a.length});return}if(e.key==="Enter"){if(!c){e.preventDefault(),N(!0),w(i>=0?i:0);return}e.preventDefault(),F(E>=0?E:0);return}e.key==="Escape"&&c&&(e.preventDefault(),N(!1))}},[E,a,F,i,c]);return u?l.jsxs("div",{className:`select-input-container ${j}`,children:[l.jsx("select",{...y,id:h,ref:R,name:T,value:f,onChange:t,className:`select-input ${q(D)} peer ${$}`,children:a?.map(e=>l.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),l.jsx("label",{htmlFor:h,className:`select-input-label ${O(D)} ${S}`,children:v}),C,k&&l.jsx("p",{className:`select-input-helper-text ${M(D)} ${A}`,children:k})]}):l.jsxs("div",{ref:o,className:`select-input-container ${j}`,children:[l.jsx("select",{...y,ref:R,name:T,id:h,value:f,onChange:t,className:"select-input-native-hidden",tabIndex:-1,"aria-hidden":!0,children:a?.map(e=>l.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),l.jsx(U,{id:h,name:T,state:D,value:String(b?.value??b?.name??""),readOnly:!0,label:v,helperText:k,containerClassName:"select-input-text-container",inputClassName:`select-input-text ${$}`,labelClassName:S,helperTextClassName:A,placeholder:I,disabled:m,required:g,autoFocus:x,onClick:()=>N(e=>!e),onKeyDown:H,onFocus:()=>N(!0),role:"combobox","aria-expanded":c,"aria-haspopup":"listbox",children:C}),c&&l.jsx("ul",{className:"select-input-options-container",role:"listbox",children:a.map((e,n)=>{const d=String(e.id)===String(f),P=n===E;return l.jsx("li",{role:"option","aria-selected":d,className:`select-input-option-item ${P?"highlighted":""}`,onMouseEnter:()=>w(n),onClick:V=>{F(n),V.stopPropagation()},children:e.value??e.name??e.id},e.id)})})]})});exports.AutocompleteInput=G;exports.CheckInput=J;exports.SelectInput=Q;exports.State=L;exports.TextInput=U;exports.helperTextStateClassName=M;exports.inputStateClassName=q;exports.labelStateClassName=O;
|