@canonical/maas-react-components 1.33.1 → 1.33.2
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.
|
@@ -5858,7 +5858,7 @@ const Wr = ({
|
|
|
5858
5858
|
children: [
|
|
5859
5859
|
/* @__PURE__ */ p("thead", { children: oe.getHeaderGroups().map((y) => /* @__PURE__ */ p("tr", { role: "row", children: y.headers.filter(l).map((k, F) => /* @__PURE__ */ U($n, { children: [
|
|
5860
5860
|
/* @__PURE__ */ p(Dr, { header: k }),
|
|
5861
|
-
F === 2 ? /* @__PURE__ */ p(
|
|
5861
|
+
n && c && F === 2 ? /* @__PURE__ */ p(
|
|
5862
5862
|
"th",
|
|
5863
5863
|
{
|
|
5864
5864
|
className: "p-generic-table__select-alignment",
|
|
@@ -52,4 +52,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
52
52
|
* LICENSE.md file in the root directory of this source tree.
|
|
53
53
|
*
|
|
54
54
|
* @license MIT
|
|
55
|
-
*/function zt(e,n){return e?Ga(e)?ce.createElement(e,n):e:null}function Ga(e){return Ba(e)||typeof e=="function"||Ua(e)}function Ba(e){return typeof e=="function"&&(()=>{const n=Object.getPrototypeOf(e);return n.prototype&&n.prototype.isReactComponent})()}function Ua(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Ka(e){const n={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[t]=ce.useState(()=>({current:za(n)})),[i,o]=ce.useState(()=>t.current.initialState);return t.current.setOptions(a=>({...a,...e,state:{...i,...e.state},onStateChange:r=>{o(r),e.onStateChange==null||e.onStateChange(r)}})),t.current}const Wa=({header:e})=>{var n;return{asc:c.jsx(H.Icon,{name:"chevron-up",children:"ascending"}),desc:c.jsx(H.Icon,{name:"chevron-down",children:"descending"})}[(n=e==null?void 0:e.column)==null?void 0:n.getIsSorted()]??null},Ya=({header:e})=>c.jsx("th",{className:U(`${e.column.id}`),children:e.column.getCanSort()?c.jsx(H.Button,{appearance:"link",className:"table-header-label p-button--table-header",onClick:e.column.getToggleSortingHandler(),type:"button",children:c.jsxs(c.Fragment,{children:[zt(e.column.columnDef.header,e.getContext()),c.jsx(Wa,{header:e})]})}):zt(e.column.columnDef.header,e.getContext())},e.id),Re=({children:e})=>c.jsx("section",{className:"controls-bar u-flex u-flex--justify-between u-flex--wrap",children:c.jsx("div",{className:"p-form p-form--inline",children:e})}),Xa=({children:e})=>c.jsx("strong",{className:"controls-bar__description",children:e}),Qa=({children:e})=>c.jsx("div",{className:"u-flex u-flex--wrap u-flex--column-x-small controls-bar__right",children:e});Re.Left=Xa,Re.Right=Qa;const Ja=({currentPage:e,itemsPerPage:n,totalItems:t,handlePageSizeChange:i,dataContext:o,setCurrentPage:a,isPending:r,pageSizes:l=[20,30,50,100]})=>{const s=h.useMemo(()=>l,[]),p=h.useMemo(()=>s.map(u=>({label:`${u}/page`,value:u})),[s]),d=Math.ceil(t/n),f=u=>{const{value:m}=u.target;i(Number(m))},g=()=>e===d?n-(d*n-t):e<d?n:0;return c.jsxs(Re,{children:[c.jsxs(Re.Left,{children:["Showing ",g()," out of ",t," ",o]}),c.jsxs(Re.Right,{children:[c.jsx(ln,{currentPage:e,disabled:r,paginate:a,totalPages:d}),c.jsx(H.Select,{"aria-label":"Items per page",className:"u-no-margin--bottom",name:"Items per page",onChange:f,options:p,value:n})]})]})},Za=({table:e,...n})=>{if(!e)return null;const t=e.getCoreRowModel().rows.filter(o=>o.getCanSelect());let i;return e.getSelectedRowModel().rows.length===0?i="false":e.getSelectedRowModel().rows.length<t.length?i="mixed":i="true",c.jsxs("label",{className:"p-checkbox--inline p-table-checkbox--all",children:[c.jsx("input",{"aria-checked":i,"aria-label":"select all",className:"p-checkbox__input",disabled:t.length===0,type:"checkbox",checked:i==="true",onChange:()=>{const o=e.getCoreRowModel().rows.filter(r=>r.getCanSelect()),a=o.every(r=>r.getIsSelected());o.forEach(r=>r.toggleSelected(!a))},...n}),c.jsx("span",{className:"p-checkbox__label"})]})},er=({row:e,...n})=>{if(!e)return null;const t=e.subRows.filter(r=>r.getCanSelect()),i=t.filter(r=>r.getIsSelected()).length,o=t.length>0&&i===t.length,a=i>0&&!o;return c.jsxs("label",{"aria-disabled":!e.getCanSelect(),className:"p-checkbox--inline p-table-checkbox--group",children:[c.jsx("input",{"aria-checked":a?"mixed":void 0,className:"p-checkbox__input",type:"checkbox",checked:o,disabled:!e.getCanSelect()&&t.length===0,onChange:()=>{const r=!o;t.forEach(l=>l.toggleSelected(r))},...n}),c.jsx("span",{className:"p-checkbox__label"})]})},Pe=({row:e,disabledTooltip:n,isNested:t=!1,...i})=>{if(!e)return null;const o=typeof n=="string"?n:n(e);return c.jsx(H.Tooltip,{message:!e.getCanSelect()&&o,position:"btm-right",children:c.jsxs("label",{"aria-disabled":!e.getCanSelect(),className:"p-checkbox--inline p-table-checkbox",children:[c.jsx("input",{className:"p-checkbox__input",type:"checkbox",checked:e.getIsSelected(),disabled:!e.getCanSelect()||t,onChange:e.getToggleSelectedHandler(),...i}),c.jsx("span",{className:"p-checkbox__label"})]})})};Pe.All=Za,Pe.Group=er;const tr=({className:e,canSelect:n=!1,disabledSelectionTooltip:t,columns:i,containerRef:o,data:a,filterCells:r=()=>!0,filterHeaders:l=()=>!0,getSubRows:s,groupBy:p,isLoading:d,noData:f,pagination:g,pinGroup:u,sortBy:m,rowSelection:v,setRowSelection:k,variant:w="full-height",...R})=>{const E=h.useRef(null),[j,x]=h.useState("auto"),[N,q]=h.useState(!1),[W,ee]=h.useState(p??[]),[pe,ue]=h.useState(!0),[ge,D]=h.useState(m??[]),C=h.useMemo(()=>{if(!n||d)return i;const b=[{id:"p-generic-table__select",accessorKey:"id",enableSorting:!1,header:({table:P})=>p?"":c.jsx(Pe.All,{table:P}),cell:({row:P})=>P.getIsGrouped()?null:c.jsx(Pe,{row:P,disabledTooltip:t??"",isNested:s!==void 0&&!!P.parentId})},...i];return p?[{id:"p-generic-table__group-select",accessorKey:"id",enableSorting:!1,header:({table:P})=>c.jsx(Pe.All,{table:P}),cell:({row:P})=>P.getIsGrouped()?c.jsx(Pe.Group,{row:P}):null},...b]:b},[n,i,d,p]),G=h.useMemo(()=>W.length?[...a].sort((b,P)=>{for(const I of W){const F=b[I]??null,$=P[I]??null;if(F===null)return 1;if($===null||F<$)return-1;if(F>$)return 1}return 0}):a,[a,W]),J=h.useMemo(()=>G.length?[...G].sort((b,P)=>{if(u!=null&&u.length&&W.length)for(const{value:I,isTop:F}of u){const $=W[0],M=b[$]??null,z=P[$]??null;if(M===I&&z!==I)return F?-1:1;if(z===I&&M!==I)return F?1:-1}for(const{id:I,desc:F}of ge){const $=b[I]??null,M=P[I]??null;if($===null&&M===null)return 0;if($===null)return F?-1:1;if(M===null||$<M)return F?1:-1;if($>M)return F?-1:1}return 0}):[],[G,ge,u,W]);h.useLayoutEffect(()=>{const b=()=>{const F=E.current;if(!F)return;const $=(o==null?void 0:o.current)||document.querySelector("main");if(!$)return;const M=$.getBoundingClientRect(),z=F.getBoundingClientRect(),V=M.bottom-z.top,L=F.scrollHeight>V;q(L),x(L?`${V}px`:"auto")};b();const P=new ResizeObserver(b),I=E.current;return I&&P.observe(I),window.addEventListener("resize",b),()=>{window.removeEventListener("resize",b),I&&P.unobserve(I)}},[o,J.length,d]);const te=w==="full-height"&&N?"full-height":"regular",re=Ka({data:J,columns:C,state:{grouping:W,expanded:pe,sorting:ge,rowSelection:v},manualPagination:!0,autoResetExpanded:!1,onExpandedChange:ue,onSortingChange:D,onGroupingChange:ee,onRowSelectionChange:k,manualSorting:!0,enableSorting:!0,enableExpanding:!0,getSubRows:s,getExpandedRowModel:Na(),getCoreRowModel:Va(),getGroupedRowModel:Ha(),groupedColumnMode:!1,enableRowSelection:n,enableMultiRowSelection:n,getRowId:b=>b.id.toString()}),ne=()=>c.jsx("tr",{children:c.jsx("td",{className:"p-generic-table__loading",colSpan:C.length,children:c.jsx(H.Spinner,{text:"Loading..."})})}),y=()=>re.getRowModel().rows.length<1?c.jsx("tr",{children:c.jsx("td",{className:"p-generic-table__no-data",colSpan:C.length,children:f})}):re.getRowModel().rows.map(b=>{const{getIsGrouped:P,id:I,getVisibleCells:F,parentId:$}=b,M=!P(),z=v!==void 0&&Object.keys(v).includes(I);return c.jsx("tr",{"aria-rowindex":parseInt(I.replace(/\D/g,"")||"0",10)+1,"aria-selected":z,className:U({"p-generic-table__individual-row":M,"p-generic-table__group-row":!M,"p-generic-table__nested-row":s!==void 0&&!!$}),role:"row",children:F().filter(V=>!M&&V.column.id==="p-generic-table__group-select"?!0:r(b,V.column)).map(V=>c.jsx("td",{className:U(`${V.column.id}`),children:zt(V.column.columnDef.cell,V.getContext())},V.id))},I)});return c.jsxs("div",{className:U("p-generic-table",e),"data-testid":"p-generic-table",...R,children:[g&&c.jsx(Ja,{currentPage:g.currentPage,dataContext:g.dataContext,handlePageSizeChange:g.handlePageSizeChange,isPending:g.isPending,itemsPerPage:g.itemsPerPage,setCurrentPage:g.setCurrentPage,totalItems:g.totalItems,pageSizes:g.pageSizes}),c.jsxs("table",{"aria-busy":d,"aria-label":R["aria-label"],"aria-describedby":"generic-table-description","aria-rowcount":J.length+1,className:U("p-generic-table__table",{"p-generic-table__is-full-height":te==="full-height","p-generic-table__is-selectable":n,"p-generic-table__is-grouped":p!==void 0}),role:"grid",children:[c.jsx("thead",{children:re.getHeaderGroups().map(b=>c.jsx("tr",{role:"row",children:b.headers.filter(l).map((P,I)=>c.jsxs(h.Fragment,{children:[c.jsx(Ya,{header:P}),I===2?c.jsx("th",{className:"p-generic-table__select-alignment",role:"columnheader"}):null]},P.id))},b.id))}),c.jsx("tbody",{ref:E,style:{overflowY:"auto",maxHeight:j},children:d?ne():y()})]})]})},nr=({row:e})=>c.jsx(H.Button,{appearance:"base",dense:!0,hasIcon:!0,onClick:()=>{e.toggleExpanded()},type:"button",children:e.getIsExpanded()?c.jsx(H.Icon,{name:"minus",children:"Collapse"}):c.jsx(H.Icon,{name:"plus",children:"Expand"})}),li={DEFAULT:4,EXPANDED:15},xe={OPEN_PAREN:"(",CLOSE_PAREN:")",EQUALS:"=",COLON:":",COMMA:","},Xe=(e,n=e.length)=>{const t=ir(e,n),{token:i,tokenStart:o,tokenEnd:a}=or(e,n);return{context:t,token:i,tokenStart:o,tokenEnd:a}},ir=(e,n)=>{let t=0;for(let i=n-1;i>=0;i--){const o=e[i];if(o===xe.CLOSE_PAREN)t++;else if(o===xe.OPEN_PAREN){if(t===0){const r=e.slice(0,i).trimEnd().match(/([a-zA-Z0-9_-]+)\s*:\s*$/);return(r==null?void 0:r[1])||""}t--}}return""},or=(e,n)=>{let t=n,i=n;for(;i<e.length&&/[^\s=(),]/.test(e[i]);)i++;for(;t>0&&/[^\s=(),]/.test(e[t-1]);)t--;return{token:e.slice(t,i),tokenStart:t,tokenEnd:i}},si=(e,n)=>{const t=e.charAt(n-1);return n>0&&(t===xe.CLOSE_PAREN||t===xe.COMMA)},ar=({className:e,disabled:n=!1,search:t,setSearch:i,context:o,setContext:a,setToken:r,suggestions:l,isLoading:s=!1,placeholder:p,...d})=>{const[f,g]=h.useState({isVisible:!1,highlightedIndex:-1,showingMore:!1,cursorPosition:0}),u=h.useRef(null),m=h.useRef(null),v=h.useRef(null),k=h.useMemo(()=>{const D=f.showingMore?li.EXPANDED:li.DEFAULT,C=l.slice(0,D);return!f.showingMore&&l.length>D?[...C,{value:"Show more...",type:"more"}]:C},[l,f.showingMore]),w=h.useCallback(D=>{g(typeof D=="function"?C=>({...C,...D(C)}):C=>({...C,...D}))},[]),R=h.useCallback(D=>{u.current&&!u.current.contains(D.target)&&w({isVisible:!1,highlightedIndex:-1})},[w]),E=h.useCallback((D,C)=>{const{tokenStart:G,tokenEnd:J}=C;if(D.type==="filter"){const re=D.value+xe.COLON+xe.OPEN_PAREN;return t.slice(0,G)+re+t.slice(J)}if(o.length===0){const re=D.type+xe.COLON+xe.OPEN_PAREN+xe.EQUALS+D.value;return t.slice(0,G)+re+t.slice(J)}const te=t.charAt(G-1)===xe.EQUALS?D.value:xe.EQUALS+D.value;return t.slice(0,G)+te+t.slice(J)},[t,o]),j=h.useCallback(D=>{const C=k[D];if(!C)return;if(C.type==="more"){w({showingMore:!0});return}const G=Xe(t,f.cursorPosition),J=E(C,G),te=G.tokenStart+(C.type==="filter"?C.value.length+2:o.length===0?C.type.length+C.value.length+3:C.value.length+1),{context:re,token:ne}=Xe(J,te);a(re),r(ne),i(J),setTimeout(()=>{v.current&&(v.current.focus(),v.current.setSelectionRange(te,te))},0),w({highlightedIndex:0,showingMore:!1,isVisible:C.type==="filter",cursorPosition:te})},[k,E,t,f.cursorPosition,o,a,r,i,w]),x=h.useCallback(()=>{if(!v.current)return;const D=v.current.selectionStart||0,{context:C,token:G}=Xe(t,D);a(C),r(G),w(J=>({...J,isVisible:!si(t,D),cursorPosition:D}))},[t,a,r,w]),N=h.useCallback(D=>{const{key:C}=D;if(f.isVisible){const G=k.length;switch(C){case"Tab":case"ArrowDown":D.preventDefault(),w({highlightedIndex:(f.highlightedIndex+1)%G});return;case"ArrowUp":D.preventDefault(),w({highlightedIndex:f.highlightedIndex<=0?G-1:f.highlightedIndex-1});return;case"Enter":D.preventDefault(),f.highlightedIndex>=0?j(f.highlightedIndex):w({isVisible:!1});return;case"Escape":D.preventDefault(),w({isVisible:!1,highlightedIndex:-1});return}}(C==="ArrowLeft"||C==="ArrowRight"||C==="Home"||C==="End")&&setTimeout(x,0)},[f,k.length,w,j,x]),q=h.useCallback(D=>{const{key:C}=D;(C==="ArrowLeft"||C==="ArrowRight"||C==="Home"||C==="End")&&x()},[x]),W=h.useCallback(()=>{w({isVisible:!0,highlightedIndex:0})},[w]),ee=h.useCallback(D=>{var te;const C=((te=v.current)==null?void 0:te.selectionStart)||D.length,{context:G,token:J}=Xe(D,C);a(G),r(J),i(D),w({highlightedIndex:0,isVisible:!si(D,C),showingMore:!1,cursorPosition:C})},[a,r,i,w]),pe=h.useCallback(()=>{setTimeout(x,0)},[x]),ue=h.useCallback(()=>{w({isVisible:!1,highlightedIndex:-1})},[w]),ge=h.useCallback(D=>{w({highlightedIndex:D})},[w]);return h.useEffect(()=>(document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)),[R]),c.jsxs("div",{className:U("p-query-input",e),"data-testid":"p-query-input",ref:u,...d,children:[c.jsx(H.SearchBox,{disabled:n,placeholder:p,value:t,externallyControlled:!0,autoComplete:"off",id:"query-input",name:"query-input",ref:v,onFocus:W,onChange:ee,onKeyDown:N,onKeyUp:q,onClear:ue,onClick:pe,"aria-disabled":n,"aria-expanded":f.isVisible,"aria-haspopup":"listbox","aria-owns":"query-suggestions"}),f.isVisible&&l.length>0&&c.jsx("ul",{className:"p-query-input__list",ref:m,id:"query-suggestions",role:"listbox","aria-label":"Search suggestions",children:s?c.jsx("div",{className:"p-query-input__loading",children:c.jsx(H.Spinner,{text:"Loading..."})}):k.map((D,C)=>c.jsxs("li",{className:U("p-query-input__item",{highlight:C===f.highlightedIndex}),onClick:()=>j(C),onKeyDown:()=>j(C),onMouseEnter:()=>ge(C),role:"option","aria-selected":C===f.highlightedIndex,tabIndex:-1,children:[c.jsxs("span",{className:"p-query-input__item-label",children:[c.jsx("span",{className:U({"u-text--muted":D.type==="more"}),children:D.value}),D.type==="filter"&&c.jsx("span",{className:"u-text--muted",children:":()"})]}),D.type!=="more"&&c.jsx("span",{className:"u-text--muted u-align-text--right",children:D.type})]},`${D.value}-${C}`))})]})},rr=({value:e,unit:n},{binary:t=!1,convertTo:i,decimals:o=2,roundFunc:a="round"}={})=>{const r=e<0,l=Math.abs(e);if(l===0)return{value:0,unit:i||"B"};const s=t?1024:1e3,p=t?["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]:["B","KB","MB","GB","TB","PB","EB","ZB","YB"],d=p.findIndex(v=>v===n)||0,f=l*Math.pow(s,d),g=i?p.findIndex(v=>v===i):Math.floor(Math.log(f)/Math.log(s));let u=f/Math.pow(s,g);if(u%1!==0){const v=Math.pow(10,o);u=Math[a](u*v)/v}return{value:r?-u:u,unit:p[g]}};B.ContentSection=De,B.DynamicTable=bt,B.ExternalLink=hi,B.FileUpload=qn,B.FileUploadContainer=ia,B.FormSection=ze,B.GenericTable=tr,B.GroupRowActions=nr,B.InputGroup=ot,B.MainToolbar=at,B.Meter=Jt,B.MultiSelect=ra,B.MultiSelectDropdown=Bn,B.Navigation=oe,B.NavigationBar=tn,B.NestedFormGroup=Xi,B.Pagination=rn,B.PaginationContainer=ln,B.Placeholder=en,B.ProgressIndicator=Zt,B.QueryInput=ar,B.Stepper=Qi,B.TableCaption=St,B.defaultFilledColors=gi,B.formatBytes=rr,B.meterColor=ye,B.testIds=Ce,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
|
55
|
+
*/function zt(e,n){return e?Ga(e)?ce.createElement(e,n):e:null}function Ga(e){return Ba(e)||typeof e=="function"||Ua(e)}function Ba(e){return typeof e=="function"&&(()=>{const n=Object.getPrototypeOf(e);return n.prototype&&n.prototype.isReactComponent})()}function Ua(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Ka(e){const n={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[t]=ce.useState(()=>({current:za(n)})),[i,o]=ce.useState(()=>t.current.initialState);return t.current.setOptions(a=>({...a,...e,state:{...i,...e.state},onStateChange:r=>{o(r),e.onStateChange==null||e.onStateChange(r)}})),t.current}const Wa=({header:e})=>{var n;return{asc:c.jsx(H.Icon,{name:"chevron-up",children:"ascending"}),desc:c.jsx(H.Icon,{name:"chevron-down",children:"descending"})}[(n=e==null?void 0:e.column)==null?void 0:n.getIsSorted()]??null},Ya=({header:e})=>c.jsx("th",{className:U(`${e.column.id}`),children:e.column.getCanSort()?c.jsx(H.Button,{appearance:"link",className:"table-header-label p-button--table-header",onClick:e.column.getToggleSortingHandler(),type:"button",children:c.jsxs(c.Fragment,{children:[zt(e.column.columnDef.header,e.getContext()),c.jsx(Wa,{header:e})]})}):zt(e.column.columnDef.header,e.getContext())},e.id),Re=({children:e})=>c.jsx("section",{className:"controls-bar u-flex u-flex--justify-between u-flex--wrap",children:c.jsx("div",{className:"p-form p-form--inline",children:e})}),Xa=({children:e})=>c.jsx("strong",{className:"controls-bar__description",children:e}),Qa=({children:e})=>c.jsx("div",{className:"u-flex u-flex--wrap u-flex--column-x-small controls-bar__right",children:e});Re.Left=Xa,Re.Right=Qa;const Ja=({currentPage:e,itemsPerPage:n,totalItems:t,handlePageSizeChange:i,dataContext:o,setCurrentPage:a,isPending:r,pageSizes:l=[20,30,50,100]})=>{const s=h.useMemo(()=>l,[]),p=h.useMemo(()=>s.map(u=>({label:`${u}/page`,value:u})),[s]),d=Math.ceil(t/n),f=u=>{const{value:m}=u.target;i(Number(m))},g=()=>e===d?n-(d*n-t):e<d?n:0;return c.jsxs(Re,{children:[c.jsxs(Re.Left,{children:["Showing ",g()," out of ",t," ",o]}),c.jsxs(Re.Right,{children:[c.jsx(ln,{currentPage:e,disabled:r,paginate:a,totalPages:d}),c.jsx(H.Select,{"aria-label":"Items per page",className:"u-no-margin--bottom",name:"Items per page",onChange:f,options:p,value:n})]})]})},Za=({table:e,...n})=>{if(!e)return null;const t=e.getCoreRowModel().rows.filter(o=>o.getCanSelect());let i;return e.getSelectedRowModel().rows.length===0?i="false":e.getSelectedRowModel().rows.length<t.length?i="mixed":i="true",c.jsxs("label",{className:"p-checkbox--inline p-table-checkbox--all",children:[c.jsx("input",{"aria-checked":i,"aria-label":"select all",className:"p-checkbox__input",disabled:t.length===0,type:"checkbox",checked:i==="true",onChange:()=>{const o=e.getCoreRowModel().rows.filter(r=>r.getCanSelect()),a=o.every(r=>r.getIsSelected());o.forEach(r=>r.toggleSelected(!a))},...n}),c.jsx("span",{className:"p-checkbox__label"})]})},er=({row:e,...n})=>{if(!e)return null;const t=e.subRows.filter(r=>r.getCanSelect()),i=t.filter(r=>r.getIsSelected()).length,o=t.length>0&&i===t.length,a=i>0&&!o;return c.jsxs("label",{"aria-disabled":!e.getCanSelect(),className:"p-checkbox--inline p-table-checkbox--group",children:[c.jsx("input",{"aria-checked":a?"mixed":void 0,className:"p-checkbox__input",type:"checkbox",checked:o,disabled:!e.getCanSelect()&&t.length===0,onChange:()=>{const r=!o;t.forEach(l=>l.toggleSelected(r))},...n}),c.jsx("span",{className:"p-checkbox__label"})]})},Pe=({row:e,disabledTooltip:n,isNested:t=!1,...i})=>{if(!e)return null;const o=typeof n=="string"?n:n(e);return c.jsx(H.Tooltip,{message:!e.getCanSelect()&&o,position:"btm-right",children:c.jsxs("label",{"aria-disabled":!e.getCanSelect(),className:"p-checkbox--inline p-table-checkbox",children:[c.jsx("input",{className:"p-checkbox__input",type:"checkbox",checked:e.getIsSelected(),disabled:!e.getCanSelect()||t,onChange:e.getToggleSelectedHandler(),...i}),c.jsx("span",{className:"p-checkbox__label"})]})})};Pe.All=Za,Pe.Group=er;const tr=({className:e,canSelect:n=!1,disabledSelectionTooltip:t,columns:i,containerRef:o,data:a,filterCells:r=()=>!0,filterHeaders:l=()=>!0,getSubRows:s,groupBy:p,isLoading:d,noData:f,pagination:g,pinGroup:u,sortBy:m,rowSelection:v,setRowSelection:k,variant:w="full-height",...R})=>{const E=h.useRef(null),[j,x]=h.useState("auto"),[N,q]=h.useState(!1),[W,ee]=h.useState(p??[]),[pe,ue]=h.useState(!0),[ge,D]=h.useState(m??[]),C=h.useMemo(()=>{if(!n||d)return i;const b=[{id:"p-generic-table__select",accessorKey:"id",enableSorting:!1,header:({table:P})=>p?"":c.jsx(Pe.All,{table:P}),cell:({row:P})=>P.getIsGrouped()?null:c.jsx(Pe,{row:P,disabledTooltip:t??"",isNested:s!==void 0&&!!P.parentId})},...i];return p?[{id:"p-generic-table__group-select",accessorKey:"id",enableSorting:!1,header:({table:P})=>c.jsx(Pe.All,{table:P}),cell:({row:P})=>P.getIsGrouped()?c.jsx(Pe.Group,{row:P}):null},...b]:b},[n,i,d,p]),G=h.useMemo(()=>W.length?[...a].sort((b,P)=>{for(const I of W){const F=b[I]??null,$=P[I]??null;if(F===null)return 1;if($===null||F<$)return-1;if(F>$)return 1}return 0}):a,[a,W]),J=h.useMemo(()=>G.length?[...G].sort((b,P)=>{if(u!=null&&u.length&&W.length)for(const{value:I,isTop:F}of u){const $=W[0],M=b[$]??null,z=P[$]??null;if(M===I&&z!==I)return F?-1:1;if(z===I&&M!==I)return F?1:-1}for(const{id:I,desc:F}of ge){const $=b[I]??null,M=P[I]??null;if($===null&&M===null)return 0;if($===null)return F?-1:1;if(M===null||$<M)return F?1:-1;if($>M)return F?-1:1}return 0}):[],[G,ge,u,W]);h.useLayoutEffect(()=>{const b=()=>{const F=E.current;if(!F)return;const $=(o==null?void 0:o.current)||document.querySelector("main");if(!$)return;const M=$.getBoundingClientRect(),z=F.getBoundingClientRect(),V=M.bottom-z.top,L=F.scrollHeight>V;q(L),x(L?`${V}px`:"auto")};b();const P=new ResizeObserver(b),I=E.current;return I&&P.observe(I),window.addEventListener("resize",b),()=>{window.removeEventListener("resize",b),I&&P.unobserve(I)}},[o,J.length,d]);const te=w==="full-height"&&N?"full-height":"regular",re=Ka({data:J,columns:C,state:{grouping:W,expanded:pe,sorting:ge,rowSelection:v},manualPagination:!0,autoResetExpanded:!1,onExpandedChange:ue,onSortingChange:D,onGroupingChange:ee,onRowSelectionChange:k,manualSorting:!0,enableSorting:!0,enableExpanding:!0,getSubRows:s,getExpandedRowModel:Na(),getCoreRowModel:Va(),getGroupedRowModel:Ha(),groupedColumnMode:!1,enableRowSelection:n,enableMultiRowSelection:n,getRowId:b=>b.id.toString()}),ne=()=>c.jsx("tr",{children:c.jsx("td",{className:"p-generic-table__loading",colSpan:C.length,children:c.jsx(H.Spinner,{text:"Loading..."})})}),y=()=>re.getRowModel().rows.length<1?c.jsx("tr",{children:c.jsx("td",{className:"p-generic-table__no-data",colSpan:C.length,children:f})}):re.getRowModel().rows.map(b=>{const{getIsGrouped:P,id:I,getVisibleCells:F,parentId:$}=b,M=!P(),z=v!==void 0&&Object.keys(v).includes(I);return c.jsx("tr",{"aria-rowindex":parseInt(I.replace(/\D/g,"")||"0",10)+1,"aria-selected":z,className:U({"p-generic-table__individual-row":M,"p-generic-table__group-row":!M,"p-generic-table__nested-row":s!==void 0&&!!$}),role:"row",children:F().filter(V=>!M&&V.column.id==="p-generic-table__group-select"?!0:r(b,V.column)).map(V=>c.jsx("td",{className:U(`${V.column.id}`),children:zt(V.column.columnDef.cell,V.getContext())},V.id))},I)});return c.jsxs("div",{className:U("p-generic-table",e),"data-testid":"p-generic-table",...R,children:[g&&c.jsx(Ja,{currentPage:g.currentPage,dataContext:g.dataContext,handlePageSizeChange:g.handlePageSizeChange,isPending:g.isPending,itemsPerPage:g.itemsPerPage,setCurrentPage:g.setCurrentPage,totalItems:g.totalItems,pageSizes:g.pageSizes}),c.jsxs("table",{"aria-busy":d,"aria-label":R["aria-label"],"aria-describedby":"generic-table-description","aria-rowcount":J.length+1,className:U("p-generic-table__table",{"p-generic-table__is-full-height":te==="full-height","p-generic-table__is-selectable":n,"p-generic-table__is-grouped":p!==void 0}),role:"grid",children:[c.jsx("thead",{children:re.getHeaderGroups().map(b=>c.jsx("tr",{role:"row",children:b.headers.filter(l).map((P,I)=>c.jsxs(h.Fragment,{children:[c.jsx(Ya,{header:P}),n&&p&&I===2?c.jsx("th",{className:"p-generic-table__select-alignment",role:"columnheader"}):null]},P.id))},b.id))}),c.jsx("tbody",{ref:E,style:{overflowY:"auto",maxHeight:j},children:d?ne():y()})]})]})},nr=({row:e})=>c.jsx(H.Button,{appearance:"base",dense:!0,hasIcon:!0,onClick:()=>{e.toggleExpanded()},type:"button",children:e.getIsExpanded()?c.jsx(H.Icon,{name:"minus",children:"Collapse"}):c.jsx(H.Icon,{name:"plus",children:"Expand"})}),li={DEFAULT:4,EXPANDED:15},xe={OPEN_PAREN:"(",CLOSE_PAREN:")",EQUALS:"=",COLON:":",COMMA:","},Xe=(e,n=e.length)=>{const t=ir(e,n),{token:i,tokenStart:o,tokenEnd:a}=or(e,n);return{context:t,token:i,tokenStart:o,tokenEnd:a}},ir=(e,n)=>{let t=0;for(let i=n-1;i>=0;i--){const o=e[i];if(o===xe.CLOSE_PAREN)t++;else if(o===xe.OPEN_PAREN){if(t===0){const r=e.slice(0,i).trimEnd().match(/([a-zA-Z0-9_-]+)\s*:\s*$/);return(r==null?void 0:r[1])||""}t--}}return""},or=(e,n)=>{let t=n,i=n;for(;i<e.length&&/[^\s=(),]/.test(e[i]);)i++;for(;t>0&&/[^\s=(),]/.test(e[t-1]);)t--;return{token:e.slice(t,i),tokenStart:t,tokenEnd:i}},si=(e,n)=>{const t=e.charAt(n-1);return n>0&&(t===xe.CLOSE_PAREN||t===xe.COMMA)},ar=({className:e,disabled:n=!1,search:t,setSearch:i,context:o,setContext:a,setToken:r,suggestions:l,isLoading:s=!1,placeholder:p,...d})=>{const[f,g]=h.useState({isVisible:!1,highlightedIndex:-1,showingMore:!1,cursorPosition:0}),u=h.useRef(null),m=h.useRef(null),v=h.useRef(null),k=h.useMemo(()=>{const D=f.showingMore?li.EXPANDED:li.DEFAULT,C=l.slice(0,D);return!f.showingMore&&l.length>D?[...C,{value:"Show more...",type:"more"}]:C},[l,f.showingMore]),w=h.useCallback(D=>{g(typeof D=="function"?C=>({...C,...D(C)}):C=>({...C,...D}))},[]),R=h.useCallback(D=>{u.current&&!u.current.contains(D.target)&&w({isVisible:!1,highlightedIndex:-1})},[w]),E=h.useCallback((D,C)=>{const{tokenStart:G,tokenEnd:J}=C;if(D.type==="filter"){const re=D.value+xe.COLON+xe.OPEN_PAREN;return t.slice(0,G)+re+t.slice(J)}if(o.length===0){const re=D.type+xe.COLON+xe.OPEN_PAREN+xe.EQUALS+D.value;return t.slice(0,G)+re+t.slice(J)}const te=t.charAt(G-1)===xe.EQUALS?D.value:xe.EQUALS+D.value;return t.slice(0,G)+te+t.slice(J)},[t,o]),j=h.useCallback(D=>{const C=k[D];if(!C)return;if(C.type==="more"){w({showingMore:!0});return}const G=Xe(t,f.cursorPosition),J=E(C,G),te=G.tokenStart+(C.type==="filter"?C.value.length+2:o.length===0?C.type.length+C.value.length+3:C.value.length+1),{context:re,token:ne}=Xe(J,te);a(re),r(ne),i(J),setTimeout(()=>{v.current&&(v.current.focus(),v.current.setSelectionRange(te,te))},0),w({highlightedIndex:0,showingMore:!1,isVisible:C.type==="filter",cursorPosition:te})},[k,E,t,f.cursorPosition,o,a,r,i,w]),x=h.useCallback(()=>{if(!v.current)return;const D=v.current.selectionStart||0,{context:C,token:G}=Xe(t,D);a(C),r(G),w(J=>({...J,isVisible:!si(t,D),cursorPosition:D}))},[t,a,r,w]),N=h.useCallback(D=>{const{key:C}=D;if(f.isVisible){const G=k.length;switch(C){case"Tab":case"ArrowDown":D.preventDefault(),w({highlightedIndex:(f.highlightedIndex+1)%G});return;case"ArrowUp":D.preventDefault(),w({highlightedIndex:f.highlightedIndex<=0?G-1:f.highlightedIndex-1});return;case"Enter":D.preventDefault(),f.highlightedIndex>=0?j(f.highlightedIndex):w({isVisible:!1});return;case"Escape":D.preventDefault(),w({isVisible:!1,highlightedIndex:-1});return}}(C==="ArrowLeft"||C==="ArrowRight"||C==="Home"||C==="End")&&setTimeout(x,0)},[f,k.length,w,j,x]),q=h.useCallback(D=>{const{key:C}=D;(C==="ArrowLeft"||C==="ArrowRight"||C==="Home"||C==="End")&&x()},[x]),W=h.useCallback(()=>{w({isVisible:!0,highlightedIndex:0})},[w]),ee=h.useCallback(D=>{var te;const C=((te=v.current)==null?void 0:te.selectionStart)||D.length,{context:G,token:J}=Xe(D,C);a(G),r(J),i(D),w({highlightedIndex:0,isVisible:!si(D,C),showingMore:!1,cursorPosition:C})},[a,r,i,w]),pe=h.useCallback(()=>{setTimeout(x,0)},[x]),ue=h.useCallback(()=>{w({isVisible:!1,highlightedIndex:-1})},[w]),ge=h.useCallback(D=>{w({highlightedIndex:D})},[w]);return h.useEffect(()=>(document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)),[R]),c.jsxs("div",{className:U("p-query-input",e),"data-testid":"p-query-input",ref:u,...d,children:[c.jsx(H.SearchBox,{disabled:n,placeholder:p,value:t,externallyControlled:!0,autoComplete:"off",id:"query-input",name:"query-input",ref:v,onFocus:W,onChange:ee,onKeyDown:N,onKeyUp:q,onClear:ue,onClick:pe,"aria-disabled":n,"aria-expanded":f.isVisible,"aria-haspopup":"listbox","aria-owns":"query-suggestions"}),f.isVisible&&l.length>0&&c.jsx("ul",{className:"p-query-input__list",ref:m,id:"query-suggestions",role:"listbox","aria-label":"Search suggestions",children:s?c.jsx("div",{className:"p-query-input__loading",children:c.jsx(H.Spinner,{text:"Loading..."})}):k.map((D,C)=>c.jsxs("li",{className:U("p-query-input__item",{highlight:C===f.highlightedIndex}),onClick:()=>j(C),onKeyDown:()=>j(C),onMouseEnter:()=>ge(C),role:"option","aria-selected":C===f.highlightedIndex,tabIndex:-1,children:[c.jsxs("span",{className:"p-query-input__item-label",children:[c.jsx("span",{className:U({"u-text--muted":D.type==="more"}),children:D.value}),D.type==="filter"&&c.jsx("span",{className:"u-text--muted",children:":()"})]}),D.type!=="more"&&c.jsx("span",{className:"u-text--muted u-align-text--right",children:D.type})]},`${D.value}-${C}`))})]})},rr=({value:e,unit:n},{binary:t=!1,convertTo:i,decimals:o=2,roundFunc:a="round"}={})=>{const r=e<0,l=Math.abs(e);if(l===0)return{value:0,unit:i||"B"};const s=t?1024:1e3,p=t?["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]:["B","KB","MB","GB","TB","PB","EB","ZB","YB"],d=p.findIndex(v=>v===n)||0,f=l*Math.pow(s,d),g=i?p.findIndex(v=>v===i):Math.floor(Math.log(f)/Math.log(s));let u=f/Math.pow(s,g);if(u%1!==0){const v=Math.pow(10,o);u=Math[a](u*v)/v}return{value:r?-u:u,unit:p[g]}};B.ContentSection=De,B.DynamicTable=bt,B.ExternalLink=hi,B.FileUpload=qn,B.FileUploadContainer=ia,B.FormSection=ze,B.GenericTable=tr,B.GroupRowActions=nr,B.InputGroup=ot,B.MainToolbar=at,B.Meter=Jt,B.MultiSelect=ra,B.MultiSelectDropdown=Bn,B.Navigation=oe,B.NavigationBar=tn,B.NestedFormGroup=Xi,B.Pagination=rn,B.PaginationContainer=ln,B.Placeholder=en,B.ProgressIndicator=Zt,B.QueryInput=ar,B.Stepper=Qi,B.TableCaption=St,B.defaultFilledColors=gi,B.formatBytes=rr,B.meterColor=ye,B.testIds=Ce,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/maas-react-components",
|
|
3
3
|
"description": "React components for use in MAAS UI projects.",
|
|
4
|
-
"version": "1.33.
|
|
4
|
+
"version": "1.33.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/canonical/maas-react-components.git"
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
],
|
|
30
30
|
"license": "AGPL-3.0",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"prepare": "husky install",
|
|
33
32
|
"build": "tsc && vite build",
|
|
34
33
|
"build:run": "npm run build",
|
|
35
34
|
"build:watch": "tsc && vite build --watch",
|
|
@@ -77,7 +76,6 @@
|
|
|
77
76
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
78
77
|
"eslint-plugin-storybook": "^0.12.0",
|
|
79
78
|
"eslint-plugin-unused-imports": "^3.2.0",
|
|
80
|
-
"husky": "8.0.3",
|
|
81
79
|
"jsdom": "^26.0.0",
|
|
82
80
|
"plop": "^4.0.0",
|
|
83
81
|
"prettier": "^3.5.3",
|