@warkypublic/oranguru 0.0.17 → 0.0.18
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/dist/lib.cjs.js +1 -1
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.es.js +65 -67
- package/dist/lib.es.js.map +1 -1
- package/package.json +1 -1
package/dist/lib.cjs.js
CHANGED
|
@@ -31,7 +31,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
31
31
|
d="M15 17.5a.5.5 0 0 1-1 0V3.707l-2.146 2.147a.5.5 0 0 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L15 3.707zM2.5 16a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM5 12.5a.5.5 0 0 0 .5.5h6a.5.5 0 0 0 0-1h-6a.5.5 0 0 0-.5.5M8.5 10a.5.5 0 0 1 0-1h3a.5.5 0 0 1 0 1z"
|
|
32
32
|
></path>
|
|
33
33
|
</svg>
|
|
34
|
-
`,re=o=>g.jsx("img",{alt:o.alt??"Sprite Image",src:`data:image/svg+xml;utf8,${o.sprite({...o,sprite:void 0})}`}),{Provider:De,useStore:L}=Se.createSyncStore((o,s)=>({_events:new EventTarget,_loadingList:O.CompactSelection.empty(),_page_data:{},_refresh:()=>{const e=s();e.loadPage(0,"all").then(()=>{e.refreshCells(),e.reload?.()})},_visibleArea:{height:1e4,width:1e3,x:0,y:0},_visiblePages:{height:0,width:0,x:0,y:0},addError:(e,...t)=>{const n=s();console.log("Gridler Error",n.uniqueid,e,t),o(J.produce(r=>{r.errors=[...r.errors,e]}))},errors:[],get:()=>s(),getCellContent:e=>{const t=s(),[n,r]=e,a=t.getRowBuffer(r);return a!==void 0?t.toCell(a,n):{allowOverlay:!1,kind:O.GridCellKind.Loading}},getCellsForSelection:(e,t)=>async()=>{const n=s();await n.setStateFN("_visibleArea",a=>e);const r=[];for(let a=e.y;a<e.y+e.height;a++){const i=[];for(let c=e.x;c<e.x+e.width;c++)i.push(n.getCellContent([c,a]));r.push(i)}return r},getGridSelectedRows:()=>{const e=s(),t=[],n=e._page_data,r=e.pageSize;if(e._gridSelectionRows)for(const a of e._gridSelectionRows){let i;for(const c in n)for(const u in n[c]){const f=Number(c)*r+Number(u);if(!isNaN(f)){if(Number(n[c][u]?._rownumber)===a+1){i=n[c][u];break}else if(f===a+1){i=n[c][u];break}}}i!==void 0&&t.push(i)}return t},getRowBuffer:e=>{const t=s();if(t.data&&t.data.length>0)return t.data[e]===void 0?{allowOverlay:!1,kind:O.GridCellKind.Loading}:t.data[e];const n=Math.max(0,Math.floor(e/t.pageSize)),r=t.pageSize*n,a=e-r;return t._page_data?.[n]?.[a]},getRowIndexByKey:async e=>{const t=s();let n=-1;if(t.ready){const r=t._page_data,a=t.pageSize,i=t.keyField??"id";for(const c in r){for(const u in r[c]){const f=Number(c)*a+Number(u);if(String(r[c][u]?.[i])===String(e)){n=r[c][u]?._rownumber>0?r[c][u]?._rownumber:f>0?f:-1;break}}if(n>0)return console.log("Local row index",n,e),n}if(n>0)return n;if(typeof t.askAPIRowNumber=="function"){const c=await t.askAPIRowNumber(String(e));if(c&&c>=0)return console.log("Remote row index",n,e),c}}},getState:e=>s()[e],hasLocalData:!1,isEmpty:!0,keyField:"id",loadPage:async(e,t)=>{const n=s(),r=e<0?0:e;if(!n._events.dispatchEvent(new CustomEvent("before_loadPage",{detail:{clearMode:t,page:e,state:n}})))return;const i=[],c=Object.keys(n.renderColumns??[1,2,3]).length,u=n.pageSize*r,f=n._page_data?.[r]?.length>0;if(t==="all"){n._active_requests?.forEach(d=>{d.controller?.abort?.()}),n.setState("_page_data",{}),n.setState("_active_requests",[]),n.loadPage(r);return}if(!n.useAPIQuery){console.warn("No useAPIQuery function defined, cannot load page",r);return}!f&&t!=="page"&&n.useAPIQuery?.(r).then(d=>{n.setStateFN("_page_data",v=>({...v,[r]:d}));for(let v=r;v<=u+n.pageSize;v++)for(let w=0;w<=c;w++)i.push({cell:[w,v]});n._glideref?.updateCells(i),n._events.dispatchEvent(new CustomEvent("loadPage",{detail:{clearMode:t,data:d,page:e,state:n}}))}).catch(d=>{console.error("loadPage Error: ",r,d),n._events.dispatchEvent(new CustomEvent("loadPage_error",{detail:{clearMode:t,error:d,page:e,state:n}}))})},maxConcurrency:1,mounted:!1,onCellActivated:e=>{const t=s(),[n,r]=e;t._events.dispatchEvent(new CustomEvent("onCellActivated",{detail:{cell:e,col:n,row:r,state:t}})),t.glideProps?.onCellActivated?.(e)},onCellClicked:(e,t)=>{const n=s(),[r,a]=e;n.glideProps?.onCellClicked?.(e,t),n._events.dispatchEvent(new CustomEvent("onCellClicked",{detail:{cell:e,col:r,row:a,state:n}}))},onCellEdited:(e,t)=>{const n=s(),[,r]=e;n._events.dispatchEvent(new CustomEvent("onCellEdited",{detail:{cell:e,newVal:t,row:r,state:n}})),n.glideProps?.onCellEdited?.(e,t)},onColumnMoved:(e,t)=>{const n=s(),r=n.renderColumns?.[e],a=n.renderColumns?.[t];r?.disableMove||a?.disableMove||n.setStateFN("colOrder",i=>{const c=i??n.renderColumns?.map((u,f)=>[u.id,f]).reduce((u,[f,d])=>({...u,[f]:d}),{});return!r?.id||!a?.id?c:{...c,[r?.id]:t,[a?.id]:e}})},onColumnProposeMove:(e,t)=>{const n=s(),r=n.renderColumns?.[e],a=n.renderColumns?.[t];return!(r?.disableMove||a?.disableMove)},onColumnResize:(e,t,n,r)=>{const a=s(),i=a.renderColumns?.find(c=>c.id===e.id);i?.disableResize||i?.maxWidth&&t<i?.maxWidth||i&&a.setStateFN("colSize",c=>c&&i&&c[i.id]===t?c:{...c,[i.id]:t})},onContextClick:(e,t,n,r)=>{const a=s(),i=a.renderColumns?.[n??-1],c=e==="menu"?[{leftSection:g.jsx(z.IconGrid4x4,{size:16}),title:a.title??"Grid"}]:i?[{leftSection:g.jsx(z.IconGrid4x4,{size:16}),title:a.title??"Grid"},{items:[{label:"Sort Ascending",leftSection:g.jsx(re,{sprite:se}),onClick:()=>{a.setStateFN("colSort",u=>{const f=[...u??[]],d=f.findIndex(w=>w.id===i.id),v="asc";if(d<0){const w={direction:v,id:i.id,order:f?.length};f.push(w)}else d>=0&&(f[d].direction=v);return f})}},{label:"Sort Descending",leftSection:g.jsx(re,{sprite:ae}),onClick:()=>{a.setStateFN("colSort",u=>{const f=[...u??[]],d=f.findIndex(w=>w.id===i.id),v="desc";if(d<0){const w={direction:v,id:i.id,order:f?.length};f.push(w)}else d>=0&&(f[d].direction=v);return f})}},{label:`Filter ${i?.title??i?.id}`},{renderer:g.jsx(ie,{column:i,storeState:s()})}],label:`Column Settings for ${i?.title??i?.id}`,leftSection:g.jsx(z.IconGrid4x4,{size:16})}]:[];a.hideMenu?.(e),a.showMenu?.(e,{items:i?.getMenuItems?.(e,a,n&&r?a.getRowBuffer(r):void 0,i,c)??a.getMenuItems?.(e,a,n&&r?a.getRowBuffer(r):void 0,i,c)??c,x:t.clientX??t.bounds?.x,y:t.clientY??t.bounds?.y})},onHeaderClicked:(e,t)=>{const n=s();t.preventDefault();const r=n.renderColumns?.[e];r&&(r.disableSort||n.setStateFN("colSort",a=>{const i=[...a??[]],c=i.findIndex(u=>u.id===r.id);if(c<0){const u={direction:"asc",id:r.id,order:i?.length};i.push(u)}else c>=0&&i[c].direction==="asc"?i[c].direction="desc":c>=0&&i[c].direction==="desc"&&i.splice(c,1);return i}))},onHeaderMenuClick:(e,t)=>{const n=s(),r=n.renderColumns?.[e];if(!r)return;const a=[{label:`Sort ${r?.title??r?.id}`},{label:"Sort Ascending",leftSection:g.jsx(re,{sprite:se}),onClick:()=>{n.setStateFN("colSort",c=>{const u=[...c??[]],f=u.findIndex(v=>v.id===r.id),d="asc";if(f<0){const v={direction:d,id:r.id,order:u?.length};u.push(v)}else f>=0&&(u[f].direction=d);return u})}},{label:"Sort Descending",leftSection:g.jsx(re,{sprite:ae}),onClick:()=>{n.setStateFN("colSort",c=>{const u=[...c??[]],f=u.findIndex(v=>v.id===r.id),d="desc";if(f<0){const v={direction:d,id:r.id,order:u?.length};u.push(v)}else f>=0&&(u[f].direction=d);return u})}},{isDivider:!0}],i=[...r.disableSort?[]:a,{label:`Filter ${r?.title??r?.id}`},{renderer:g.jsx(ie,{column:r,storeState:s()})},{isDivider:!0},{label:"Refresh",onClickAsync:async()=>{await n._refresh?.()}}];n.hideMenu?.("header-menu"),n.showMenu?.("header-menu",{items:r?.getMenuItems?.("header-menu",n,void 0,r,i)??n.getMenuItems?.("header-menu",n,void 0,r,i),x:t.x,y:t.y})},onItemHovered:e=>{const t=s();if(t.setState("_activeTooltip",void 0),e.kind==="cell"){const n=t.renderColumns?.[e.location[0]];if(n?.tooltip&&typeof n?.tooltip=="string")t.setState("_activeTooltip",n?.tooltip);else if(n?.tooltip&&typeof n?.tooltip=="function"){const r=t.getRowBuffer(e.location[1]);t.setState("_activeTooltip",n?.tooltip(r,e.location[1],e.location[0]))}}},onVisibleRegionChanged:(e,t,n,r)=>{const a=s();a._scrollTimeout&&clearTimeout(a._scrollTimeout);const i=()=>{const c=s(),u=Math.max(0,Math.floor(e.y/c.pageSize)),f=Math.max(0,Math.floor(c._visiblePages.y/c.pageSize)),d=u-f;if(c.progressiveScroll&&d>1){const v=s(),w=(f+2)*v.pageSize*(v.rowHeight??22);v._glideref?.scrollTo(0,{amount:w,unit:"px"},"vertical");return}c.setState("_visiblePages",e)};a.setState("_scrollTimeout",setTimeout(()=>{i()},100))},pageSize:50,ready:!1,refreshCells:(e,t,n)=>{const r=s(),a=[],i=Object.keys(r.renderColumns??[1,2,3]).length,c=e&&e>0?e:0,u=t&&t>=c?t:c+r.pageSize;for(let f=c;f<=u;f++)if(n&&n>0)a.push({cell:[n,f]});else for(let d=0;d<=i;d++)a.push({cell:[d,f]});r._glideref?.updateCells(a)},setState:(e,t)=>{o(J.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((r,a)=>{o(J.produce(i=>{if(typeof t=="function")i[e]=t(i[e]);else throw a(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),r()}),toCell:(e,t)=>{const n=s(),a=n.renderColumns?.[t],i=a?.id??a?.title??String(t);if(i==null||e===void 0||e===null)return a?.Cell?a?.Cell(e,t,i,void 0,n):n.RenderCell?n.RenderCell(e,t,i,void 0,n):{allowOverlay:!1,kind:O.GridCellKind.Loading};try{const c=String(i).includes(".")?Ne(i,e)??"":e?.[i];return a?.Cell?{kind:O.GridCellKind.Text,...a?.Cell(e,t,i,c,n)}:n.RenderCell?n.RenderCell(e,t,i,c,n):{allowOverlay:!0,data:c??"",displayData:String(c??""),kind:O.GridCellKind.Text}}catch{return n.RenderCell?n.RenderCell(e,t,i,e?.[i??""],n):{allowOverlay:!1,kind:O.GridCellKind.Loading,skeletonWidthVariability:50}}},total_rows:1e3,uniqueid:ve.getUUID()}),o=>{const[s,e]=o.useStore(n=>[n.setState,n.getState]),t=ce();return S.useEffect(()=>{const n=e("onMounted");if(typeof n=="function"&&n(e,s),s("mounted",!0),window&&window.document&&!window.document.getElementById("portal")){const a=window.document.createElement("div");a.id="portal",a.setAttribute("data-gridler-portal",o.uniqueid),window.document.body.appendChild(a)}return e("_events").dispatchEvent(new CustomEvent("mounted",{detail:{}})),()=>{const r=e("onUnMounted");s("mounted",!1),e("_events").dispatchEvent(new CustomEvent("unmounted",{detail:{}})),typeof r=="function"&&r()}},[s,e]),e("_events").addEventListener("reload",n=>{e("_refresh")?.()}),{...o,colSort:o.defaultSort??e("colSort")??[],hideMenu:o.hideMenu??t.hide,scrollToRowKey:o.scrollToRowKey??o.selectedRowKey??e("scrollToRowKey"),showMenu:o.showMenu??t.show,total_rows:e("total_rows")??o.total_rows}});function Ge(o){const[s,e,t,n,r,a]=L(u=>[u.setStateFN,u.setState,u.getState,u.addError,u.mounted,u.loadPage]),i=S.useCallback(async u=>{const f=t("columns"),d=t("colSort"),v=t("pageSize"),w=t("colFilters"),P=t("searchStr"),y=t("searchFields"),R=t("_active_requests");e("loadingData",!0);try{if(o&&o.url){const k=new Headers;k.set("Authorization",`Token ${o.authtoken}`);const F=[{type:"limit",value:String(v??50)},{type:"offset",value:String((v??50)*u)}];d?.length&&d.length>0&&F.push({type:"sort",value:d?.map(m=>`${m.id} ${m.direction}`).reduce((m,x)=>`${m},${x}`)}),w?.filter(m=>m.value?.length>0)?.forEach(m=>{m.value&&m.value!==""&&F.push({name:`${m.id}`,op:m.operator,type:"searchop",value:m.value})}),P&&P!==""&&f?.filter(m=>!m.disableFilter&&!m.disableSearch&&!m.virtual&&((y??[]).length==0||y?.includes(m.id)))?.forEach(m=>{F.push({name:`${m.id}`,op:"contains",type:"searchor",value:P})}),o.filter&&o.filter!==""&&F.push({name:"sql_filter",type:"custom-sql-w",value:o.filter}),(o.options??[]).length>0&&F.push(...o.options??[]);const M=f?.filter(m=>!m.virtual)?.map(m=>m.id)??[];if(o.hotfields&&o.hotfields.length>0&&M?.push(o.hotfields.join(",")),M&&M.length>0&&F.push({type:"select-fields",value:M.join(",")}),F&&F.length>0){const m=V(F);for(const x in V(F))k.set(x,m[x])}const B=R?.findIndex(m=>m.page===u)??-1;if(R?.forEach(m=>{(m.page>=0&&m.page<u-2||u>=0&&m.page>u+2)&&m.controller?.abort?.()}),R&&B>=0&&R[B]){e("loadingData",!1);return}const _=new AbortController;await s("_active_requests",m=>[...m??[],{controller:_,page:u}]);const C=await fetch(`${o.url}?x-limit=${String(v??50)}&x-offset=${String((v??50)*u)}`,{headers:k,method:"GET",signal:_?.signal});if(C.ok){const m=C.headers.get("Content-Range")?.split("/");m?.[1]&&parseInt(m[1],10)>0&&e("total_rows",parseInt(m[1],10));const x=await C.json();return e("loadingData",!1),x??[]}n(`${C.status} ${C.statusText}`,"api",o.url),await s("_active_requests",m=>[...(m??[]).filter(x=>x.page!==u)])}}catch{}return e("loadingData",!1),[]},[t,o.authtoken,o.url,o.filter,JSON.stringify(o.options),e,s,n]),c=S.useCallback(async u=>{const f=t("colFilters");if(o&&o.url){const d=new Headers,v=[{type:"limit",value:String(10)},{type:"fetch-rownumber",value:u}];if(d.set("Authorization",`Token ${o.authtoken}`),f?.length&&f.length>0&&f?.filter(y=>y.value?.length>0)?.forEach(y=>{y.value&&y.value!==""&&d.set(`x-searchop-${y.operator}-${y.id}`,`${y.value}`)}),o.filter&&o.filter!==""&&v.push({name:"sql_filter",type:"custom-sql-w",value:o.filter}),o.options&&o.options.length>0){const y=V(o.options);for(const R in y)d.set(R,y[R])}if(v&&v.length>0){const y=V(v);for(const R in V(v))d.set(R,y[R])}const w=new AbortController,P=await fetch(`${o.url}?x-fetch-rownumber=${u}}`,{headers:d,method:"GET",signal:w?.signal});if(P.ok){const y=await P.json();return y?.[0]?._rownumber??y?._rownumber??0}n(`${P.status} ${P.statusText}`,"api",o.url)}return[]},[o.url,o.authtoken,o.filter,o.options,t,n]);return S.useEffect(()=>{a(0,"all").then(()=>{const u=t("onChange"),f=t("getGridSelectedRows");if(u&&typeof u=="function"){const d=f?.();u(d)}})},[JSON.stringify(o.options),o.filter,o.url,o.authtoken]),S.useEffect(()=>{e("useAPIQuery",i),e("askAPIRowNumber",c)},[o.url,o.authtoken,o.filter,JSON.stringify(o.options),r,e]),g.jsx(g.Fragment,{})}const xe=S.memo(Ge);xe.displayName="Gridler-GlidlerAPIAdaptorForGoLangv2";function Re(o){const[s,e,t,n,r]=L(i=>[i.getState,i.mounted,i.setState,i.reload,i._events]);S.useEffect(()=>{if(e&&o.changeOnActiveClick){const i=c=>{const{row:u,state:f}=c.detail,d=f.getRowBuffer;if(d){const v=d(u);if(!v)return;o.onRequestForm("change",v)}};return r?.addEventListener("onCellActivated",i),()=>{i&&r?.removeEventListener("onCellActivated",i)}}},[o.changeOnActiveClick,e,r]);const a=S.useCallback((i,c,u,f,d)=>{if(i==="header-menu")return d||[];const v=[];v.push(...d);const w=s("_gridSelection")?.rows.toArray()??[],P=w.length>1;if(!u){const k=w[0];k!==void 0&&(u=c.getRowBuffer(k))}const y=typeof o.descriptionField=="string"?u?.[o.descriptionField]:typeof o.descriptionField=="function"&&u?o.descriptionField(u):void 0;i==="other"&&v.push({c:"blue",label:"Add",onClick:()=>{o.onRequestForm("insert",u)}}),i==="cell"&&u||i==="menu"&&u?(v.push({c:"teal",label:"Add",leftSection:g.jsx(z.IconSquarePlus,{color:"teal",size:16}),onClick:()=>{o.onRequestForm("insert",u)}}),P?(v.push({c:"green",label:`Modify All Selected (${w.length})`,leftSection:g.jsx(z.IconEdit,{color:"green",size:16}),onClick:()=>{o.onRequestForm("change",w.map(k=>c.getRowBuffer(k)))}}),v.push({c:"red",label:`Remove All Selected (${w.length})`,leftSection:g.jsx(z.IconTrashX,{color:"maroon",size:16}),onClick:()=>{o.onRequestForm("delete",w.map(k=>c.getRowBuffer(k)))}})):(v.push({c:"green",label:`Modify${y&&o.showDescriptionInMenu?` (${y})`:""}`,leftSection:g.jsx(z.IconEdit,{color:"green",size:16}),onClick:()=>{o.onRequestForm("change",u)}}),v.push({c:"red",label:`Remove${y&&o.showDescriptionInMenu?` (${y})`:""}`,leftSection:g.jsx(z.IconTrashX,{color:"maroon",size:16}),onClick:()=>{o.onRequestForm("delete",u)}})),v.push({isDivider:!0})):(i==="cell"&&!u||i==="menu"&&!u)&&v.push({c:"red",label:"Nothing Selected",leftSection:g.jsx(z.IconExclamationMark,{color:"yellow",size:16})}),v.push({c:"orange",label:"Refresh",leftSection:g.jsx(z.IconRefresh,{color:"orange",size:16}),onClick:()=>{n?.()}});const R=o.getMenuItems?o.getMenuItems(i,c,u,f,v):v;return!v||v.length===0?d||[]:R},[o.onRequestForm,s]);return S.useEffect(()=>(e&&typeof t=="function"&&s("getMenuItems")!==a&&t("getMenuItems",a),()=>{}),[o.getMenuItems,e]),g.jsx(g.Fragment,{})}function ze(o){const[s,e,t]=L(f=>[f.setState,f.getState,f.mounted]),{colFilters:n,colSort:r,columns:a,searchStr:i}=L(f=>({colFilters:f.colFilters,colOrder:f.colOrder,colSize:f.colSize,colSort:f.colSort,columns:f.columns,searchStr:f.searchStr})),c=S.useRef({colFilters:n,colSort:r,searchStr:i}),u=async f=>{const d=e("pageSize");return o.data&&Array.isArray(o.data)?(s("total_rows",o.data.length),o.data.slice(f*(d??50),(f+1)*(d??50))):[]};return S.useEffect(()=>{s("useAPIQuery",u)},[t,s]),S.useEffect(()=>{if(o.onColumnSort&&r!==c?.current?.colSort){const f=o.onColumnSort(r,a,o.data);s("total_rows",f.length),s("data",f),c.current.colSort=r,e("refreshCells")?.()}},[r,o.onColumnSort]),S.useEffect(()=>{if(o.onColumnFilter&&n!==c?.current?.colFilters){const f=o.onColumnFilter(n,a,o.data);s("total_rows",f.length),s("data",f),c.current.colFilters=n,e("refreshCells")?.()}},[n,o.onColumnFilter]),S.useEffect(()=>{if(o.onSearch&&i!==c?.current?.searchStr){const f=o.onSearch(i,a,o.data);s("total_rows",f.length),s("data",f),c.current.colFilters=n,e("refreshCells")?.()}},[i,o.onSearch]),g.jsx(g.Fragment,{})}const ue=S.memo(ze);ue.displayName="Gridler-GlidlerLocalDataAdaptor";function pe(){const{loadingData:o,onContextClick:s}=L(e=>({loadingData:e.loadingData,onContextClick:e.onContextClick}));return g.jsx(E.ActionIcon,{loading:o,mr:"xs",mt:"2px",onClick:e=>s("menu",e),variant:"subtle",children:g.jsx(z.IconMenu2,{})})}function Le(o,s){const[e,t]=L(n=>[n.setStateFN,n.getState]);return S.useImperativeHandle(s,()=>({getGlideRef:()=>t("_glideref"),getState:t,isEmpty:()=>t("isEmpty"),refresh:async n=>{const r=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{r?.()})},reload:async n=>{const r=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{r?.()})},reloadRow:async n=>{const r=t("refreshCells"),i=await t("getRowIndexByKey")?.(String(n));i&&i>=0&&r?.(i,i+1)},scrollToRow:async n=>{n&&Number(n)>=0&&e("scrollToRowKey",r=>Number(n??r))},selectRow:async n=>{n&&Number(n)>=0&&e("selectedRowKey",r=>Number(n??r))},setStateFN:e}),[]),g.jsx(g.Fragment,{children:o.children})}const qe=S.forwardRef(Le);function He(){const{_activeTooltip:o,tooltipBarProps:s}=L(e=>({_activeTooltip:e._activeTooltip,tooltipBarProps:e.tooltipBarProps}));return g.jsx("div",{"data-tooltip-bar":!0,style:{minHeight:"24px"},...s,children:o})}const Ee=S.memo(()=>{const o=S.useRef(0),s=S.useRef(""),e=S.useRef(null),{_glideref:t,_gridSelectionRows:n,colFilters:r,colOrder:a,colSize:i,colSort:c,columns:u,getRowIndexByKey:f,getState:d,loadPage:v,ready:w,scrollToRowKey:P,searchStr:y,selectedRowKey:R,setState:k,setStateFN:F,values:M}=L(_=>({_glideref:_._glideref,_gridSelectionRows:_._gridSelectionRows,colFilters:_.colFilters,colOrder:_.colOrder,colSize:_.colSize,colSort:_.colSort,columns:_.columns,getRowIndexByKey:_.getRowIndexByKey,getState:_.getState,loadPage:_.loadPage,ready:_.ready,scrollToRowKey:_.scrollToRowKey,searchStr:_.searchStr,selectedRowKey:_.selectedRowKey,setState:_.setState,setStateFN:_.setStateFN,uniqueid:_.uniqueid,values:_.values})),B=Q.useDebouncedCallback(_=>{v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onSearched",{detail:{search:_}}))})},{delay:300,leading:!1});return S.useEffect(()=>{M&&(async()=>{const C=d("_page_data"),m=d("pageSize"),x=d("keyField")??"id",j=[];for(const $ in M){let N=-1;const D=String(typeof M?.[$]=="object"?M?.[$]?.[x]:typeof M?.[$]=="string"?M?.[$]:void 0);for(const T in C){for(const H in C[T]){const G=Number(T)*m+Number(H);if(String(C[T][H]?.[x])===D){N=G;break}}if(N>=0){j.push(N);break}}if(!(N>=0)){const T=await f(D);T&&j.push(T)}}return j})().then(C=>{let m=O.CompactSelection.empty();C.forEach(x=>{m=m.add(x)}),F("_gridSelectionRows",()=>m),F("_gridSelection",x=>({columns:x?.columns??O.CompactSelection.empty(),...x,rows:m}))})},[M]),S.useEffect(()=>{const _=d("onChange");if(_&&typeof _=="function"){const m=d("getGridSelectedRows")(),x=d("values");JSON.stringify(x)!==JSON.stringify(m)&&_(m)}},[JSON.stringify(n),d]),S.useEffect(()=>{k("renderColumns",u?.map(_=>({..._,hasMenu:_?.hasMenu??!0,icon:"sort"})))},[u]),S.useEffect(()=>{if(y==null){s.current="";return}s.current!==y&&(B(y),s.current=y)},[y]),S.useEffect(()=>{c&&(k("_gridSelection",{columns:O.CompactSelection.empty(),current:void 0,rows:O.CompactSelection.empty()}),k("_gridSelectionRows",O.CompactSelection.empty()),F("renderColumns",_=>_?.map(C=>({...C,icon:C.id&&c?.find(m=>m.id===C.id)?.direction?c?.find(m=>m.id===C.id)?.direction==="asc"?"sortup":"sortdown":C.defaultIcon??"sort"}))).then(()=>{v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onColumnSorted",{detail:{cols:c}}))})}))},[c]),S.useEffect(()=>{r&&JSON.stringify(e.current)!==JSON.stringify(r)&&(v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onColumnFiltered",{detail:{filters:r}}))}),e.current=r)},[r]),S.useEffect(()=>{i&&F("renderColumns",_=>_?.map(C=>({...C,width:C.id&&i?.[C.id]?i?.[C.id]:C.width}))).then(()=>{d("refreshCells")?.()})},[i]),S.useEffect(()=>{a&&F("renderColumns",_=>_?.sort((m,x)=>a[m.id]>a[x.id]?1:-1)).then(()=>{d("refreshCells")?.()})},[a]),S.useEffect(()=>{t&&(o.current>0||(o.current=1,v(0).then(()=>{d("refreshCells")?.()})))},[w,v]),S.useEffect(()=>{const _=d("_events"),C=()=>{const m=d("selectFirstRowOnMount");if(w&&m){const x=d("scrollToRowKey");if(x&&x>=0)return;const j=d("keyField")??"id",N=d("_page_data")?.[0]?.[0],D=N?.[j],T=d("values")??[];if(D&&D>0&&(T.length??0)===0){const H=[N,...T],G=d("onChange");G?G(H):k("values",H),k("scrollToRowKey",D)}}};return _?.addEventListener("loadPage",C),()=>{_?.removeEventListener("loadPage",C)}},[w]),S.useEffect(()=>{const _=d("ready"),C=d("_glideref"),m=d("getRowIndexByKey"),x=R??P;x&&C&&_&&m?.(x).then(j=>{if(j!==void 0){if(R){const $=d("onChange"),N=[{[d("keyField")??"id"]:R}];$?$(N):k("values",N)}C.scrollTo(0,j),d("_events").dispatchEvent(new CustomEvent("scrollToRowKeyFound",{detail:{rowNumber:j,scrollToRowKey:P,selectedRowKey:R}}))}})},[P,R]),g.jsx(g.Fragment,{})});Ee.displayName="Gridler-Computer";function Be(o,s,e=1){let t;if(s===void 0?(t=0,s=o):t=o,e===0)throw new Error("Step cannot be zero");const n=[];if(e>0)for(let r=t;r<s;r+=e)n.push(r);else for(let r=t;r>s;r+=e)n.push(r);return n}const ke=S.memo(()=>{const[o,s,e,t,n,r,a,i]=L(c=>[c.setState,c.getState,c._glideref,c._visiblePages,c.pageSize,c.loadPage,c._loadingList,c.hasLocalData]);return S.useEffect(()=>{e&&o("mounted",!0)},[o]),S.useEffect(()=>{if(!e)return;const c=Math.max(0,Math.floor(t.y/n)),u=Math.floor((t.y+t.height)/n);for(const f of Be(c,u+1,1))r(f).then(()=>{const d=s("_page_data")?.[0]??{};o("isEmpty",d&&d.length>0)})},[r,n,t,e,a,i]),g.jsx(g.Fragment,{})});ke.displayName="Gridler-Pager";const Ke=o=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
34
|
+
`,re=o=>g.jsx("img",{alt:o.alt??"Sprite Image",src:`data:image/svg+xml;utf8,${o.sprite({...o,sprite:void 0})}`}),{Provider:De,useStore:L}=Se.createSyncStore((o,s)=>({_events:new EventTarget,_loadingList:O.CompactSelection.empty(),_page_data:{},_refresh:()=>{const e=s();e.loadPage(0,"all").then(()=>{e.refreshCells(),e.reload?.()})},_visibleArea:{height:1e4,width:1e3,x:0,y:0},_visiblePages:{height:0,width:0,x:0,y:0},addError:(e,...t)=>{const n=s();console.log("Gridler Error",n.uniqueid,e,t),o(J.produce(r=>{r.errors=[...r.errors,e]}))},errors:[],get:()=>s(),getCellContent:e=>{const t=s(),[n,r]=e,a=t.getRowBuffer(r);return a!==void 0?t.toCell(a,n):{allowOverlay:!1,kind:O.GridCellKind.Loading}},getCellsForSelection:(e,t)=>async()=>{const n=s();await n.setStateFN("_visibleArea",a=>e);const r=[];for(let a=e.y;a<e.y+e.height;a++){const i=[];for(let c=e.x;c<e.x+e.width;c++)i.push(n.getCellContent([c,a]));r.push(i)}return r},getGridSelectedRows:()=>{const e=s(),t=[],n=e._page_data,r=e.pageSize;if(e._gridSelectionRows)for(const a of e._gridSelectionRows){let i;for(const c in n)for(const u in n[c]){const f=Number(c)*r+Number(u);if(!isNaN(f)){if(Number(n[c][u]?._rownumber)===a+1){i=n[c][u];break}else if(f===a+1){i=n[c][u];break}}}i!==void 0&&t.push(i)}return t},getRowBuffer:e=>{const t=s();if(t.data&&t.data.length>0)return t.data[e]===void 0?{allowOverlay:!1,kind:O.GridCellKind.Loading}:t.data[e];const n=Math.max(0,Math.floor(e/t.pageSize)),r=t.pageSize*n,a=e-r;return t._page_data?.[n]?.[a]},getRowIndexByKey:async e=>{const t=s();let n=-1;if(t.ready){const r=t._page_data,a=t.pageSize,i=t.keyField??"id";for(const c in r){for(const u in r[c]){const f=Number(c)*a+Number(u);if(String(r[c][u]?.[i])===String(e)){n=r[c][u]?._rownumber>0?r[c][u]?._rownumber:f>0?f:-1;break}}if(n>0)return console.log("Local row index",n,e),n}if(n>0)return n;if(typeof t.askAPIRowNumber=="function"){const c=await t.askAPIRowNumber(String(e));if(c&&c>=0)return console.log("Remote row index",n,e),c}}},getState:e=>s()[e],hasLocalData:!1,isEmpty:!0,keyField:"id",loadPage:async(e,t)=>{const n=s(),r=e<0?0:e;if(!n._events.dispatchEvent(new CustomEvent("before_loadPage",{detail:{clearMode:t,page:e,state:n}})))return;const i=[],c=Object.keys(n.renderColumns??[1,2,3]).length,u=n.pageSize*r,f=n._page_data?.[r]?.length>0;if(t==="all"){n._active_requests?.forEach(d=>{d.controller?.abort?.()}),n.setState("_page_data",{}),n.setState("_active_requests",[]),n.loadPage(r);return}if(!n.useAPIQuery){console.warn("No useAPIQuery function defined, cannot load page",r);return}!f&&t!=="page"&&n.useAPIQuery?.(r).then(d=>{n.setStateFN("_page_data",v=>({...v,[r]:d}));for(let v=r;v<=u+n.pageSize;v++)for(let w=0;w<=c;w++)i.push({cell:[w,v]});n._glideref?.updateCells(i),n._events.dispatchEvent(new CustomEvent("loadPage",{detail:{clearMode:t,data:d,page:e,state:n}}))}).catch(d=>{console.error("loadPage Error: ",r,d),n._events.dispatchEvent(new CustomEvent("loadPage_error",{detail:{clearMode:t,error:d,page:e,state:n}}))})},maxConcurrency:1,mounted:!1,onCellActivated:e=>{const t=s(),[n,r]=e;t._events.dispatchEvent(new CustomEvent("onCellActivated",{detail:{cell:e,col:n,row:r,state:t}})),t.glideProps?.onCellActivated?.(e)},onCellClicked:(e,t)=>{const n=s(),[r,a]=e;n.glideProps?.onCellClicked?.(e,t),n._events.dispatchEvent(new CustomEvent("onCellClicked",{detail:{cell:e,col:r,row:a,state:n}}))},onCellEdited:(e,t)=>{const n=s(),[,r]=e;n._events.dispatchEvent(new CustomEvent("onCellEdited",{detail:{cell:e,newVal:t,row:r,state:n}})),n.glideProps?.onCellEdited?.(e,t)},onColumnMoved:(e,t)=>{const n=s(),r=n.renderColumns?.[e],a=n.renderColumns?.[t];r?.disableMove||a?.disableMove||n.setStateFN("colOrder",i=>{const c=i??n.renderColumns?.map((u,f)=>[u.id,f]).reduce((u,[f,d])=>({...u,[f]:d}),{});return!r?.id||!a?.id?c:{...c,[r?.id]:t,[a?.id]:e}})},onColumnProposeMove:(e,t)=>{const n=s(),r=n.renderColumns?.[e],a=n.renderColumns?.[t];return!(r?.disableMove||a?.disableMove)},onColumnResize:(e,t,n,r)=>{const a=s(),i=a.renderColumns?.find(c=>c.id===e.id);i?.disableResize||i?.maxWidth&&t<i?.maxWidth||i&&a.setStateFN("colSize",c=>c&&i&&c[i.id]===t?c:{...c,[i.id]:t})},onContextClick:(e,t,n,r)=>{const a=s(),i=a.renderColumns?.[n??-1],c=e==="menu"?[{leftSection:g.jsx(z.IconGrid4x4,{size:16}),title:a.title??"Grid"}]:i?[{leftSection:g.jsx(z.IconGrid4x4,{size:16}),title:a.title??"Grid"},{items:[{label:"Sort Ascending",leftSection:g.jsx(re,{sprite:se}),onClick:()=>{a.setStateFN("colSort",u=>{const f=[...u??[]],d=f.findIndex(w=>w.id===i.id),v="asc";if(d<0){const w={direction:v,id:i.id,order:f?.length};f.push(w)}else d>=0&&(f[d].direction=v);return f})}},{label:"Sort Descending",leftSection:g.jsx(re,{sprite:ae}),onClick:()=>{a.setStateFN("colSort",u=>{const f=[...u??[]],d=f.findIndex(w=>w.id===i.id),v="desc";if(d<0){const w={direction:v,id:i.id,order:f?.length};f.push(w)}else d>=0&&(f[d].direction=v);return f})}},{label:`Filter ${i?.title??i?.id}`},{renderer:g.jsx(ie,{column:i,storeState:s()})}],label:`Column Settings for ${i?.title??i?.id}`,leftSection:g.jsx(z.IconGrid4x4,{size:16})}]:[];a.hideMenu?.(e),a.showMenu?.(e,{items:i?.getMenuItems?.(e,a,n&&r?a.getRowBuffer(r):void 0,i,c)??a.getMenuItems?.(e,a,n&&r?a.getRowBuffer(r):void 0,i,c)??c,x:t.clientX??t.bounds?.x,y:t.clientY??t.bounds?.y})},onHeaderClicked:(e,t)=>{const n=s();t.preventDefault();const r=n.renderColumns?.[e];r&&(r.disableSort||n.setStateFN("colSort",a=>{const i=[...a??[]],c=i.findIndex(u=>u.id===r.id);if(c<0){const u={direction:"asc",id:r.id,order:i?.length};i.push(u)}else c>=0&&i[c].direction==="asc"?i[c].direction="desc":c>=0&&i[c].direction==="desc"&&i.splice(c,1);return i}))},onHeaderMenuClick:(e,t)=>{const n=s(),r=n.renderColumns?.[e];if(!r)return;const a=[{label:`Sort ${r?.title??r?.id}`},{label:"Sort Ascending",leftSection:g.jsx(re,{sprite:se}),onClick:()=>{n.setStateFN("colSort",c=>{const u=[...c??[]],f=u.findIndex(v=>v.id===r.id),d="asc";if(f<0){const v={direction:d,id:r.id,order:u?.length};u.push(v)}else f>=0&&(u[f].direction=d);return u})}},{label:"Sort Descending",leftSection:g.jsx(re,{sprite:ae}),onClick:()=>{n.setStateFN("colSort",c=>{const u=[...c??[]],f=u.findIndex(v=>v.id===r.id),d="desc";if(f<0){const v={direction:d,id:r.id,order:u?.length};u.push(v)}else f>=0&&(u[f].direction=d);return u})}},{isDivider:!0}],i=[...r.disableSort?[]:a,{label:`Filter ${r?.title??r?.id}`},{renderer:g.jsx(ie,{column:r,storeState:s()})},{isDivider:!0},{label:"Refresh",onClickAsync:async()=>{await n._refresh?.()}}];n.hideMenu?.("header-menu"),n.showMenu?.("header-menu",{items:r?.getMenuItems?.("header-menu",n,void 0,r,i)??n.getMenuItems?.("header-menu",n,void 0,r,i),x:t.x,y:t.y})},onItemHovered:e=>{const t=s();if(t.setState("_activeTooltip",void 0),e.kind==="cell"){const n=t.renderColumns?.[e.location[0]];if(n?.tooltip&&typeof n?.tooltip=="string")t.setState("_activeTooltip",n?.tooltip);else if(n?.tooltip&&typeof n?.tooltip=="function"){const r=t.getRowBuffer(e.location[1]);t.setState("_activeTooltip",n?.tooltip(r,e.location[1],e.location[0]))}}},onVisibleRegionChanged:(e,t,n,r)=>{const a=s();a._scrollTimeout&&clearTimeout(a._scrollTimeout);const i=()=>{const c=s(),u=Math.max(0,Math.floor(e.y/c.pageSize)),f=Math.max(0,Math.floor(c._visiblePages.y/c.pageSize)),d=u-f;if(c.progressiveScroll&&d>1){const v=s(),w=(f+2)*v.pageSize*(v.rowHeight??22);v._glideref?.scrollTo(0,{amount:w,unit:"px"},"vertical");return}c.setState("_visiblePages",e)};a.setState("_scrollTimeout",setTimeout(()=>{i()},100))},pageSize:50,ready:!1,refreshCells:(e,t,n)=>{const r=s(),a=[],i=Object.keys(r.renderColumns??[1,2,3]).length,c=e&&e>0?e:0,u=t&&t>=c?t:c+r.pageSize;for(let f=c;f<=u;f++)if(n&&n>0)a.push({cell:[n,f]});else for(let d=0;d<=i;d++)a.push({cell:[d,f]});r._glideref?.updateCells(a)},setState:(e,t)=>{o(J.produce(n=>{n[e]=t}))},setStateFN:(e,t)=>new Promise((r,a)=>{o(J.produce(i=>{if(typeof t=="function")i[e]=t(i[e]);else throw a(new Error(`Not a function ${t}`)),Error(`Not a function ${t}`)})),r()}),toCell:(e,t)=>{const n=s(),a=n.renderColumns?.[t],i=a?.id??a?.title??String(t);if(i==null||e===void 0||e===null)return a?.Cell?a?.Cell(e,t,i,void 0,n):n.RenderCell?n.RenderCell(e,t,i,void 0,n):{allowOverlay:!1,kind:O.GridCellKind.Loading};try{const c=String(i).includes(".")?Ne(i,e)??"":e?.[i];return a?.Cell?{kind:O.GridCellKind.Text,...a?.Cell(e,t,i,c,n)}:n.RenderCell?n.RenderCell(e,t,i,c,n):{allowOverlay:!0,data:c??"",displayData:String(c??""),kind:O.GridCellKind.Text}}catch{return n.RenderCell?n.RenderCell(e,t,i,e?.[i??""],n):{allowOverlay:!1,kind:O.GridCellKind.Loading,skeletonWidthVariability:50}}},total_rows:1e3,uniqueid:ve.getUUID()}),o=>{const[s,e]=o.useStore(n=>[n.setState,n.getState]),t=ce();return S.useEffect(()=>{const n=e("onMounted");if(typeof n=="function"&&n(e,s),s("mounted",!0),window&&window.document&&!window.document.getElementById("portal")){const a=window.document.createElement("div");a.id="portal",a.setAttribute("data-gridler-portal",o.uniqueid),window.document.body.appendChild(a)}return e("_events").dispatchEvent(new CustomEvent("mounted",{detail:{}})),()=>{const r=e("onUnMounted");s("mounted",!1),e("_events").dispatchEvent(new CustomEvent("unmounted",{detail:{}})),typeof r=="function"&&r()}},[s,e]),e("_events").addEventListener("reload",n=>{e("_refresh")?.()}),{...o,colSort:o.defaultSort??e("colSort")??[],hideMenu:o.hideMenu??t.hide,scrollToRowKey:o.scrollToRowKey??o.selectedRowKey??e("scrollToRowKey"),showMenu:o.showMenu??t.show,total_rows:e("total_rows")??o.total_rows}});function Ge(o){const[s,e,t,n,r,a]=L(u=>[u.setStateFN,u.setState,u.getState,u.addError,u.mounted,u.loadPage]),i=S.useCallback(async u=>{const f=t("columns"),d=t("colSort"),v=t("pageSize"),w=t("colFilters"),P=t("searchStr"),y=t("searchFields"),R=t("_active_requests");e("loadingData",!0);try{if(o&&o.url){const k=new Headers;k.set("Authorization",`Token ${o.authtoken}`);const F=[{type:"limit",value:String(v??50)},{type:"offset",value:String((v??50)*u)}];d?.length&&d.length>0&&F.push({type:"sort",value:d?.map(m=>`${m.id} ${m.direction}`).reduce((m,x)=>`${m},${x}`)}),w?.filter(m=>m.value?.length>0)?.forEach(m=>{m.value&&m.value!==""&&F.push({name:`${m.id}`,op:m.operator,type:"searchop",value:m.value})}),P&&P!==""&&f?.filter(m=>!m.disableFilter&&!m.disableSearch&&!m.virtual&&((y??[]).length==0||y?.includes(m.id)))?.forEach(m=>{F.push({name:`${m.id}`,op:"contains",type:"searchor",value:P})}),o.filter&&o.filter!==""&&F.push({name:"sql_filter",type:"custom-sql-w",value:o.filter}),(o.options??[]).length>0&&F.push(...o.options??[]);const M=f?.filter(m=>!m.virtual)?.map(m=>m.id)??[];if(o.hotfields&&o.hotfields.length>0&&M?.push(o.hotfields.join(",")),M&&M.length>0&&F.push({type:"select-fields",value:M.join(",")}),F&&F.length>0){const m=V(F);for(const x in V(F))k.set(x,m[x])}const B=R?.findIndex(m=>m.page===u)??-1;if(R?.forEach(m=>{(m.page>=0&&m.page<u-2||u>=0&&m.page>u+2)&&m.controller?.abort?.()}),R&&B>=0&&R[B]){e("loadingData",!1);return}const _=new AbortController;await s("_active_requests",m=>[...m??[],{controller:_,page:u}]);const C=await fetch(`${o.url}?x-limit=${String(v??50)}&x-offset=${String((v??50)*u)}`,{headers:k,method:"GET",signal:_?.signal});if(C.ok){const m=C.headers.get("Content-Range")?.split("/");m?.[1]&&parseInt(m[1],10)>0&&e("total_rows",parseInt(m[1],10));const x=await C.json();return e("loadingData",!1),x??[]}n(`${C.status} ${C.statusText}`,"api",o.url),await s("_active_requests",m=>[...(m??[]).filter(x=>x.page!==u)])}}catch{}return e("loadingData",!1),[]},[t,o.authtoken,o.url,o.filter,JSON.stringify(o.options),e,s,n]),c=S.useCallback(async u=>{const f=t("colFilters");if(o&&o.url){const d=new Headers,v=[{type:"limit",value:String(10)},{type:"fetch-rownumber",value:u}];if(d.set("Authorization",`Token ${o.authtoken}`),f?.length&&f.length>0&&f?.filter(y=>y.value?.length>0)?.forEach(y=>{y.value&&y.value!==""&&d.set(`x-searchop-${y.operator}-${y.id}`,`${y.value}`)}),o.filter&&o.filter!==""&&v.push({name:"sql_filter",type:"custom-sql-w",value:o.filter}),o.options&&o.options.length>0){const y=V(o.options);for(const R in y)d.set(R,y[R])}if(v&&v.length>0){const y=V(v);for(const R in V(v))d.set(R,y[R])}const w=new AbortController,P=await fetch(`${o.url}?x-fetch-rownumber=${u}}`,{headers:d,method:"GET",signal:w?.signal});if(P.ok){const y=await P.json();return y?.[0]?._rownumber??y?._rownumber??0}n(`${P.status} ${P.statusText}`,"api",o.url)}return[]},[o.url,o.authtoken,o.filter,o.options,t,n]);return S.useEffect(()=>{e("useAPIQuery",i),e("askAPIRowNumber",c),a(0,"all").then(()=>{const u=t("onChange"),f=t("getGridSelectedRows");if(u&&typeof u=="function"){const d=f?.();u(d)}})},[o.url,o.authtoken,o.filter,JSON.stringify(o.options),r,e]),g.jsx(g.Fragment,{})}const xe=S.memo(Ge);xe.displayName="Gridler-GlidlerAPIAdaptorForGoLangv2";function Re(o){const[s,e,t,n,r]=L(i=>[i.getState,i.mounted,i.setState,i.reload,i._events]);S.useEffect(()=>{if(e&&o.changeOnActiveClick){const i=c=>{const{row:u,state:f}=c.detail,d=f.getRowBuffer;if(d){const v=d(u);if(!v)return;o.onRequestForm("change",v)}};return r?.addEventListener("onCellActivated",i),()=>{i&&r?.removeEventListener("onCellActivated",i)}}},[o.changeOnActiveClick,e,r]);const a=S.useCallback((i,c,u,f,d)=>{if(i==="header-menu")return d||[];const v=[];v.push(...d);const w=s("_gridSelection")?.rows.toArray()??[],P=w.length>1;if(!u){const k=w[0];k!==void 0&&(u=c.getRowBuffer(k))}const y=typeof o.descriptionField=="string"?u?.[o.descriptionField]:typeof o.descriptionField=="function"&&u?o.descriptionField(u):void 0;i==="other"&&v.push({c:"blue",label:"Add",onClick:()=>{o.onRequestForm("insert",u)}}),i==="cell"&&u||i==="menu"&&u?(v.push({c:"teal",label:"Add",leftSection:g.jsx(z.IconSquarePlus,{color:"teal",size:16}),onClick:()=>{o.onRequestForm("insert",u)}}),P?(v.push({c:"green",label:`Modify All Selected (${w.length})`,leftSection:g.jsx(z.IconEdit,{color:"green",size:16}),onClick:()=>{o.onRequestForm("change",w.map(k=>c.getRowBuffer(k)))}}),v.push({c:"red",label:`Remove All Selected (${w.length})`,leftSection:g.jsx(z.IconTrashX,{color:"maroon",size:16}),onClick:()=>{o.onRequestForm("delete",w.map(k=>c.getRowBuffer(k)))}})):(v.push({c:"green",label:`Modify${y&&o.showDescriptionInMenu?` (${y})`:""}`,leftSection:g.jsx(z.IconEdit,{color:"green",size:16}),onClick:()=>{o.onRequestForm("change",u)}}),v.push({c:"red",label:`Remove${y&&o.showDescriptionInMenu?` (${y})`:""}`,leftSection:g.jsx(z.IconTrashX,{color:"maroon",size:16}),onClick:()=>{o.onRequestForm("delete",u)}})),v.push({isDivider:!0})):(i==="cell"&&!u||i==="menu"&&!u)&&v.push({c:"red",label:"Nothing Selected",leftSection:g.jsx(z.IconExclamationMark,{color:"yellow",size:16})}),v.push({c:"orange",label:"Refresh",leftSection:g.jsx(z.IconRefresh,{color:"orange",size:16}),onClick:()=>{n?.()}});const R=o.getMenuItems?o.getMenuItems(i,c,u,f,v):v;return!v||v.length===0?d||[]:R},[o.onRequestForm,s]);return S.useEffect(()=>(e&&typeof t=="function"&&s("getMenuItems")!==a&&t("getMenuItems",a),()=>{}),[o.getMenuItems,e]),g.jsx(g.Fragment,{})}function ze(o){const[s,e,t]=L(f=>[f.setState,f.getState,f.mounted]),{colFilters:n,colSort:r,columns:a,searchStr:i}=L(f=>({colFilters:f.colFilters,colOrder:f.colOrder,colSize:f.colSize,colSort:f.colSort,columns:f.columns,searchStr:f.searchStr})),c=S.useRef({colFilters:n,colSort:r,searchStr:i}),u=async f=>{const d=e("pageSize");return o.data&&Array.isArray(o.data)?(s("total_rows",o.data.length),o.data.slice(f*(d??50),(f+1)*(d??50))):[]};return S.useEffect(()=>{s("useAPIQuery",u)},[t,s]),S.useEffect(()=>{if(o.onColumnSort&&r!==c?.current?.colSort){const f=o.onColumnSort(r,a,o.data);s("total_rows",f.length),s("data",f),c.current.colSort=r,e("refreshCells")?.()}},[r,o.onColumnSort]),S.useEffect(()=>{if(o.onColumnFilter&&n!==c?.current?.colFilters){const f=o.onColumnFilter(n,a,o.data);s("total_rows",f.length),s("data",f),c.current.colFilters=n,e("refreshCells")?.()}},[n,o.onColumnFilter]),S.useEffect(()=>{if(o.onSearch&&i!==c?.current?.searchStr){const f=o.onSearch(i,a,o.data);s("total_rows",f.length),s("data",f),c.current.colFilters=n,e("refreshCells")?.()}},[i,o.onSearch]),g.jsx(g.Fragment,{})}const ue=S.memo(ze);ue.displayName="Gridler-GlidlerLocalDataAdaptor";function pe(){const{loadingData:o,onContextClick:s}=L(e=>({loadingData:e.loadingData,onContextClick:e.onContextClick}));return g.jsx(E.ActionIcon,{loading:o,mr:"xs",mt:"2px",onClick:e=>s("menu",e),variant:"subtle",children:g.jsx(z.IconMenu2,{})})}function Le(o,s){const[e,t]=L(n=>[n.setStateFN,n.getState]);return S.useImperativeHandle(s,()=>({getGlideRef:()=>t("_glideref"),getState:t,isEmpty:()=>t("isEmpty"),refresh:async n=>{const r=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{r?.()})},reload:async n=>{const r=t("refreshCells");t("loadPage")?.(n?.pageIndex??0,"all").then(()=>{r?.()})},reloadRow:async n=>{const r=t("refreshCells"),i=await t("getRowIndexByKey")?.(String(n));i&&i>=0&&r?.(i,i+1)},scrollToRow:async n=>{n&&Number(n)>=0&&e("scrollToRowKey",r=>Number(n??r))},selectRow:async n=>{n&&Number(n)>=0&&e("selectedRowKey",r=>Number(n??r))},setStateFN:e}),[]),g.jsx(g.Fragment,{children:o.children})}const qe=S.forwardRef(Le);function He(){const{_activeTooltip:o,tooltipBarProps:s}=L(e=>({_activeTooltip:e._activeTooltip,tooltipBarProps:e.tooltipBarProps}));return g.jsx("div",{"data-tooltip-bar":!0,style:{minHeight:"24px"},...s,children:o})}const Ee=S.memo(()=>{const o=S.useRef(0),s=S.useRef(""),e=S.useRef(null),{_glideref:t,_gridSelectionRows:n,colFilters:r,colOrder:a,colSize:i,colSort:c,columns:u,getRowIndexByKey:f,getState:d,loadPage:v,ready:w,scrollToRowKey:P,searchStr:y,selectedRowKey:R,setState:k,setStateFN:F,values:M}=L(_=>({_glideref:_._glideref,_gridSelectionRows:_._gridSelectionRows,colFilters:_.colFilters,colOrder:_.colOrder,colSize:_.colSize,colSort:_.colSort,columns:_.columns,getRowIndexByKey:_.getRowIndexByKey,getState:_.getState,loadPage:_.loadPage,ready:_.ready,scrollToRowKey:_.scrollToRowKey,searchStr:_.searchStr,selectedRowKey:_.selectedRowKey,setState:_.setState,setStateFN:_.setStateFN,uniqueid:_.uniqueid,values:_.values})),B=Q.useDebouncedCallback(_=>{v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onSearched",{detail:{search:_}}))})},{delay:300,leading:!1});return S.useEffect(()=>{M&&(async()=>{const C=d("_page_data"),m=d("pageSize"),x=d("keyField")??"id",j=[];for(const $ in M){let N=-1;const D=String(typeof M?.[$]=="object"?M?.[$]?.[x]:typeof M?.[$]=="string"?M?.[$]:void 0);for(const T in C){for(const H in C[T]){const G=Number(T)*m+Number(H);if(String(C[T][H]?.[x])===D){N=G;break}}if(N>=0){j.push(N);break}}if(!(N>=0)){const T=await f(D);T&&j.push(T)}}return j})().then(C=>{let m=O.CompactSelection.empty();C.forEach(x=>{m=m.add(x)}),F("_gridSelectionRows",()=>m),F("_gridSelection",x=>({columns:x?.columns??O.CompactSelection.empty(),...x,rows:m}))})},[M]),S.useEffect(()=>{const _=d("onChange");if(_&&typeof _=="function"){const m=d("getGridSelectedRows")(),x=d("values");JSON.stringify(x)!==JSON.stringify(m)&&_(m)}},[JSON.stringify(n),d]),S.useEffect(()=>{k("renderColumns",u?.map(_=>({..._,hasMenu:_?.hasMenu??!0,icon:"sort"})))},[u]),S.useEffect(()=>{if(y==null){s.current="";return}s.current!==y&&(B(y),s.current=y)},[y]),S.useEffect(()=>{c&&(k("_gridSelection",{columns:O.CompactSelection.empty(),current:void 0,rows:O.CompactSelection.empty()}),k("_gridSelectionRows",O.CompactSelection.empty()),F("renderColumns",_=>_?.map(C=>({...C,icon:C.id&&c?.find(m=>m.id===C.id)?.direction?c?.find(m=>m.id===C.id)?.direction==="asc"?"sortup":"sortdown":C.defaultIcon??"sort"}))).then(()=>{v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onColumnSorted",{detail:{cols:c}}))})}))},[c]),S.useEffect(()=>{r&&JSON.stringify(e.current)!==JSON.stringify(r)&&(v(0,"all").then(()=>{d("refreshCells")?.(),d("_events")?.dispatchEvent?.(new CustomEvent("onColumnFiltered",{detail:{filters:r}}))}),e.current=r)},[r]),S.useEffect(()=>{i&&F("renderColumns",_=>_?.map(C=>({...C,width:C.id&&i?.[C.id]?i?.[C.id]:C.width}))).then(()=>{d("refreshCells")?.()})},[i]),S.useEffect(()=>{a&&F("renderColumns",_=>_?.sort((m,x)=>a[m.id]>a[x.id]?1:-1)).then(()=>{d("refreshCells")?.()})},[a]),S.useEffect(()=>{t&&(o.current>0||(o.current=1,v(0).then(()=>{d("refreshCells")?.()})))},[w,v]),S.useEffect(()=>{const _=d("_events"),C=()=>{const m=d("selectFirstRowOnMount");if(w&&m){const x=d("scrollToRowKey");if(x&&x>=0)return;const j=d("keyField")??"id",N=d("_page_data")?.[0]?.[0],D=N?.[j],T=d("values")??[];if(D&&D>0&&(T.length??0)===0){const H=[N,...T],G=d("onChange");G?G(H):k("values",H),k("scrollToRowKey",D)}}};return _?.addEventListener("loadPage",C),()=>{_?.removeEventListener("loadPage",C)}},[w]),S.useEffect(()=>{const _=d("ready"),C=d("_glideref"),m=d("getRowIndexByKey"),x=R??P;x&&C&&_&&m?.(x).then(j=>{if(j!==void 0){if(R){const $=d("onChange"),N=[{[d("keyField")??"id"]:R}];$?$(N):k("values",N)}C.scrollTo(0,j),d("_events").dispatchEvent(new CustomEvent("scrollToRowKeyFound",{detail:{rowNumber:j,scrollToRowKey:P,selectedRowKey:R}}))}})},[P,R]),g.jsx(g.Fragment,{})});Ee.displayName="Gridler-Computer";function Be(o,s,e=1){let t;if(s===void 0?(t=0,s=o):t=o,e===0)throw new Error("Step cannot be zero");const n=[];if(e>0)for(let r=t;r<s;r+=e)n.push(r);else for(let r=t;r>s;r+=e)n.push(r);return n}const ke=S.memo(()=>{const[o,s,e,t,n,r,a,i]=L(c=>[c.setState,c.getState,c._glideref,c._visiblePages,c.pageSize,c.loadPage,c._loadingList,c.hasLocalData]);return S.useEffect(()=>{e&&o("mounted",!0)},[o]),S.useEffect(()=>{if(!e)return;const c=Math.max(0,Math.floor(t.y/n)),u=Math.floor((t.y+t.height)/n);for(const f of Be(c,u+1,1))r(f).then(()=>{const d=s("_page_data")?.[0]??{};o("isEmpty",d&&d.length>0)})},[r,n,t,e,a,i]),g.jsx(g.Fragment,{})});ke.displayName="Gridler-Pager";const Ke=o=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="none">
|
|
35
35
|
<path
|
|
36
36
|
fill="${o.fgColor??"currentColor"}"
|
|
37
37
|
d="M2.22 9.967L7.97 4.22l.085-.074l.058-.038l.072-.039l.105-.04l.105-.022l.052-.005L8.5 4l.057.002l.092.013l.107.03l.085.037l.054.03l.063.044l.072.064l5.75 5.747a.75.75 0 0 1-.976 1.133l-.084-.072L9.25 6.56v16.69a.75.75 0 0 1-1.493.102l-.007-.102V6.56l-4.47 4.468a.75.75 0 0 1-.976.072l-.084-.072a.75.75 0 0 1-.073-.977zM19.5 4a.75.75 0 0 1 .743.648l.007.102v16.687l4.47-4.467l.084-.073a.75.75 0 0 1 1.049 1.05l-.073.083l-5.728 5.727a.75.75 0 0 1-1.031.07l-.073-.07l-5.728-5.727l-.073-.084a.75.75 0 0 1-.007-.882l.08-.094l.084-.073a.75.75 0 0 1 .882-.007l.094.08l4.47 4.469V4.75l.007-.102A.75.75 0 0 1 19.5 4"
|