@toolbox-web/grid 3.9.1 → 3.9.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.
Files changed (77) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/custom-elements.json +2 -2
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +8 -4
  7. package/lib/core/plugin/base-plugin.d.ts +7 -0
  8. package/lib/core/types.d.ts +2 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/context-menu/context-menu-plugin.d.ts +9 -4
  11. package/lib/plugins/context-menu/index.js +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/context-menu/types.d.ts +8 -4
  14. package/lib/plugins/editing/index.js +1 -1
  15. package/lib/plugins/editing/index.js.map +1 -1
  16. package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +2 -1
  17. package/lib/plugins/filtering/filter-model.d.ts +2 -1
  18. package/lib/plugins/filtering/filtering-plugin.d.ts +5 -2
  19. package/lib/plugins/filtering/index.js +1 -1
  20. package/lib/plugins/filtering/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +7 -14
  22. package/lib/plugins/grouping-rows/grouping-rows.d.ts +48 -0
  23. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  24. package/lib/plugins/grouping-rows/index.js +1 -1
  25. package/lib/plugins/grouping-rows/index.js.map +1 -1
  26. package/lib/plugins/grouping-rows/types.d.ts +21 -0
  27. package/lib/plugins/master-detail/index.d.ts +1 -1
  28. package/lib/plugins/master-detail/index.js +1 -1
  29. package/lib/plugins/master-detail/index.js.map +1 -1
  30. package/lib/plugins/master-detail/master-detail-plugin.d.ts +28 -6
  31. package/lib/plugins/master-detail/master-detail.d.ts +0 -8
  32. package/lib/plugins/master-detail/types.d.ts +25 -1
  33. package/lib/plugins/multi-sort/index.js +1 -1
  34. package/lib/plugins/multi-sort/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js +1 -1
  36. package/lib/plugins/selection/index.js.map +1 -1
  37. package/lib/plugins/selection/selection-plugin.d.ts +8 -1
  38. package/lib/plugins/server-side/datasource-types.d.ts +28 -0
  39. package/lib/plugins/server-side/datasource.d.ts +7 -0
  40. package/lib/plugins/server-side/index.js +1 -1
  41. package/lib/plugins/server-side/index.js.map +1 -1
  42. package/lib/plugins/server-side/server-side-plugin.d.ts +61 -8
  43. package/lib/plugins/server-side/types.d.ts +9 -1
  44. package/lib/plugins/tree/index.js +1 -1
  45. package/lib/plugins/tree/index.js.map +1 -1
  46. package/lib/plugins/tree/tree-plugin.d.ts +5 -11
  47. package/lib/plugins/tree/types.d.ts +22 -6
  48. package/lib/plugins/undo-redo/history.d.ts +2 -1
  49. package/lib/plugins/undo-redo/index.js +1 -1
  50. package/lib/plugins/undo-redo/index.js.map +1 -1
  51. package/lib/plugins/undo-redo/types.d.ts +13 -1
  52. package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +15 -2
  53. package/package.json +1 -1
  54. package/umd/grid.all.umd.js +1 -1
  55. package/umd/grid.all.umd.js.map +1 -1
  56. package/umd/grid.umd.js +1 -1
  57. package/umd/grid.umd.js.map +1 -1
  58. package/umd/plugins/context-menu.umd.js +1 -1
  59. package/umd/plugins/context-menu.umd.js.map +1 -1
  60. package/umd/plugins/editing.umd.js +1 -1
  61. package/umd/plugins/editing.umd.js.map +1 -1
  62. package/umd/plugins/filtering.umd.js +1 -1
  63. package/umd/plugins/filtering.umd.js.map +1 -1
  64. package/umd/plugins/grouping-rows.umd.js +1 -1
  65. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  66. package/umd/plugins/master-detail.umd.js +1 -1
  67. package/umd/plugins/master-detail.umd.js.map +1 -1
  68. package/umd/plugins/multi-sort.umd.js +1 -1
  69. package/umd/plugins/multi-sort.umd.js.map +1 -1
  70. package/umd/plugins/selection.umd.js +1 -1
  71. package/umd/plugins/selection.umd.js.map +1 -1
  72. package/umd/plugins/server-side.umd.js +1 -1
  73. package/umd/plugins/server-side.umd.js.map +1 -1
  74. package/umd/plugins/tree.umd.js +1 -1
  75. package/umd/plugins/tree.umd.js.map +1 -1
  76. package/umd/plugins/undo-redo.umd.js +1 -1
  77. package/umd/plugins/undo-redo.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_serverSide={},e.TbwGrid)}(this,function(e,t){function o(e){return{__loading:!0,__index:e,__rowCacheKey:`__loading:${e}`}}function i(e){return null!=e&&"object"==typeof e&&!0===e.__loading&&"number"==typeof e.__index}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var r="TBW140";function s(e,t,o,i){return`${function(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}(o,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}function n(e,t,o,i){console.debug(s(e,t,o,i))}function a(e,t,o,i){console.error(s(e,t,o,i))}var l="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),d=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),c=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function g(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const i of o){const e=i.tagName.toLowerCase();if(d.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>c.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();c.test(e)?o.push(t.name):"is"!==e?(h.has(e)&&u.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function f(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return o=e,(i=r)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?o.replaceChildren(g(i)):o.textContent=i:o.replaceChildren(),e}return r}var o,i;return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function p(e,t){if(!e.firstElementChild)return;const o=e.querySelector(":scope > .tbw-cell-loading-overlay");o&&(t?.unmount?.(o),o.remove())}function m(e,t){if(!e.firstElementChild)return;const o=e.querySelector(":scope > .tbw-row-loading-overlay");o&&(t?.unmount?.(o),o.remove())}function b(e,t,o,i){const r=t;if(function(e,t,o,i){const{style:r}=t;r.getPropertyValue("--tbw-row-height")&&r.removeProperty("--tbw-row-height");const s=e._getPluginRowHeight?.(o,i),n=void 0!==s&&s>0?`${s}px`:"";r.height!==n&&(r.height=n)}(e,r,o,i),r.__rowDataRef===o&&r.__isCustomRow&&r.classList.contains("tbw-row-loading"))return;!function(e,t){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const o=e.__frameworkAdapter;if(o?.releaseCell||o?.unmount){o.beginBatch?.(e);try{m(t,o);const e=t.children;for(let t=e.length-1;t>=0;t--){const i=e[t];p(i,o),o.releaseCell?.(i)}t.innerHTML=""}finally{o.endBatch?.(e)}}else t.innerHTML=""}(e,r),r.className="data-grid-row placeholder-row",r.__isCustomRow=!0;const s=document.createElement("div");s.className="cell",s.style.gridColumn="1 / -1",s.setAttribute("role","gridcell"),s.textContent=" ",r.appendChild(s),function(e,t,o,i){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(":scope > .tbw-row-loading-overlay")){const t=document.createElement("div");if(t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true"),o)t.appendChild(f("small",o));else{const e=document.createElement("div");e.className="tbw-row-loading-spinner",t.appendChild(e)}e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),m(e,i)}(r,!0,e.effectiveConfig?.loadingRenderer)}function w(e,t){return Math.floor(e/t)}function C(){return new DOMException("Aborted","AbortError")}function v(e,t,o,i,r){const s=function(e,t){return{start:e*t,end:(e+1)*t}}(t,o);return function(e,t){return t.aborted?Promise.reject(C()):"object"!=typeof(o=e)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,i)=>{const r=()=>i(C());t.addEventListener("abort",r,{once:!0}),Promise.resolve(e).then(e=>{t.removeEventListener("abort",r),o(e)},e=>{t.removeEventListener("abort",r),i(e)})}):new Promise((o,i)=>{let r=!1;const s=e.subscribe({next:e=>{r||(r=!0,o(e),s.unsubscribe())},error:e=>{r||(r=!0,i(e))},complete:()=>{r||(r=!0,i(new Error("getRows observable completed without emitting a value")))}});r||t.addEventListener("abort",()=>{r||(r=!0,s.unsubscribe(),i(C()))},{once:!0})});var o}(e.getRows({startNode:s.start,endNode:s.end,pageSize:s.end-s.start,sortModel:i.sortModel,filterModel:i.filterModel,signal:r}),r)}function k(e,t,o){const i=w(e,t),r=o.get(i);if(r)return r[e%t]}function S(e){let t=null;return{async getRows({startNode:o,endNode:i,signal:r}){const{rows:s,total:n}=await(o=>(t||(t=fetch(e,{signal:o}).then(async t=>{if(!t.ok)throw new Error(`Failed to fetch "${e}": ${t.status} ${t.statusText}`);const o=await t.json();if(Array.isArray(o))return{rows:o,total:o.length};const i=o??{},r=Array.isArray(i.rows)?i.rows:[];return{rows:r,total:"number"==typeof i.totalNodeCount?i.totalNodeCount:r.length}}).catch(e=>{throw t=null,e})),t))(r);return{rows:s.slice(o,i),totalNodeCount:n}}}}var N=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10,renderRow:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"}]};name="serverSide";get defaultConfig(){return{maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;infiniteScrollMode=!1;loadedBlocks=new Map;loadingBlocks=new Set;blockControllers=new Map;lastRequestId=0;scrollDebounceTimer;pendingViewportCheck=!1;managedNodes=[];attach(e){if(super.attach(e),this.on("sort-change",()=>{"local"===this.config.sortMode?this.requestRender():this.onModelChange()}),this.on("filter-change",()=>{"local"===this.config.filterMode?this.requestRender():this.onModelChange()}),this.config.dataSource)return void this.setDataSource(this.config.dataSource);const t=this.gridElement?.getAttribute("data-src");t&&this.setDataSource(S(t))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.abortAllBlocks(),this.managedNodes=[],this.lastRequestId=0,this.pendingViewportCheck=!1,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const e of this.blockControllers.values())e.abort();this.blockControllers.clear()}getEnrichmentParams(){const e="local"===this.config.sortMode,t="local"===this.config.filterMode,o=e?void 0:this.grid?.query?.("sort:get-model",null),i=t?void 0:this.grid?.query?.("filter:get-model",null);let r=o?.[0];const s=this.grid;if(!e&&!r&&s?._sortState){const{field:e,direction:t}=s._sortState;r=[{field:e,direction:1===t?"asc":"desc"}]}return{sortModel:r,filterModel:i?.[0]}}getViewportMapping(e,t){const o={viewportStart:e,viewportEnd:t},i=this.grid?.query?.("datasource:viewport-mapping",o);return i?.[0]?i[0]:{startNode:e,endNode:t,totalLoadedNodes:this.totalNodeCount}}onModelChange(){this.dataSource&&(this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.requestRender(),this.loadRequiredBlocks())}applyServerResult(e,t,o){void 0!==e.lastNode?(this.totalNodeCount=e.lastNode+1,this.infiniteScrollMode=!1):-1===e.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=e.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&e.rows.length<o&&(this.totalNodeCount=t*o+e.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(e){let t=0;for(const[o,i]of this.loadedBlocks){const r=o*e+i.length;r>t&&(t=r)}return t+e}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:e}=this.grid,t=this.config.pageSize??100,o=this.getViewportMapping(e.start,e.end),i=Math.max(0,this.config.loadThreshold??0),s=Math.max(0,o.startNode-i),l=this.totalNodeCount>0?this.totalNodeCount:1/0,d=Math.min(l,o.endNode+i);if(d<=s)return;const c=function(e,t,o){const i=w(e,o),r=w(t-1,o),s=[];for(let n=i;n<=r;n++)s.push(n);return s}(s,d,t),h=this.getEnrichmentParams(),u=this.grid?.getAttribute?.("id")??void 0;for(const g of c){if(this.loadedBlocks.has(g)||this.loadingBlocks.has(g))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){n("TBW143","Concurrent request limit reached, deferring block load",u);break}this.loadingBlocks.add(g);const e=new AbortController;this.blockControllers.set(g,e),this.broadcast("datasource:loading",{loading:!0}),v(this.dataSource,g,t,h,e.signal).then(o=>{if(this.blockControllers.delete(g),e.signal.aborted)return this.loadingBlocks.delete(g),void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(g,o.rows);const i=this.managedNodes.length;this.applyServerResult(o,g,t),this.loadingBlocks.delete(g);const r=g*t;for(let e=0;e<o.rows.length;e++)r+e<this.managedNodes.length&&(this.managedNodes[r+e]=o.rows[e]);const s={rows:o.rows,totalNodeCount:o.totalNodeCount,startNode:r,endNode:r+o.rows.length,claimed:!1};this.broadcast("datasource:data",s),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===i||s.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?(this.pendingViewportCheck=!0,this.requestRender()):this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(t=>{if(this.blockControllers.delete(g),this.loadingBlocks.delete(g),e.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const o=t instanceof Error?t:new Error(String(t));a(r,`getRows() failed: ${o.message}`,u),this.broadcast("datasource:error",{error:o}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(e){if(!this.dataSource)return[...e];const i=this.config.pageSize??100,r=this.infiniteScrollMode?this.getInfiniteScrollEstimate(i):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<r;)this.managedNodes.push(o(this.managedNodes.length));this.managedNodes.length=r;for(let t=0;t<r;t++){const e=k(t,i,this.loadedBlocks);e&&(this.managedNodes[t]=e)}const s=this.grid;if("local"===this.config.sortMode&&s?._sortState){const e=s._columns??[],o=(s.effectiveConfig?.sortHandler??t.builtInSort)(this.managedNodes,s._sortState,e);return o&&"function"==typeof o.then?(o.catch(()=>{}),this.managedNodes):o}return this.managedNodes}renderRow(e,t,o){return!(!i(e)||"columns"===this.config.placeholderRendering)&&(b(this.grid,t,e,o),!0)}afterRender(){this.pendingViewportCheck&&(this.pendingViewportCheck=!1,this.loadRequiredBlocks())}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(e){switch(e.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:t}=e.context;return void this.fetchChildren(t)}}}fetchChildren(e){if(!this.dataSource)return;const t=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void function(e,t,o,i){console.warn(s(e,t,o,i))}("TBW142",`Plugin "${e.source}" requested child rows but getChildRows() is not implemented on the dataSource`,t);const o=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:e}),this.dataSource.getChildRows({context:e,sortModel:o.sortModel,filterModel:o.filterModel}).then(t=>{const o={rows:t.rows,context:e,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:e})}).catch(o=>{const i=o instanceof Error?o:new Error(String(o));a("TBW141",`getChildRows() failed: ${i.message}`,t),this.broadcast("datasource:error",{error:i,context:e}),this.broadcast("datasource:loading",{loading:!1,context:e})})}setDataSource(e){this.abortAllBlocks(),this.dataSource=e,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.pendingViewportCheck=!1;const t=this.config.pageSize??100,o=this.getEnrichmentParams(),i=this.grid?.getAttribute?.("id")??void 0,s=new AbortController;this.blockControllers.set(0,s),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),v(e,0,t,o,s.signal).then(e=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),s.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,e.rows),this.applyServerResult(e,0,t);const o={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:0,endNode:e.rows.length,claimed:!1};this.broadcast("datasource:data",o),this.broadcast("datasource:loading",{loading:!1}),this.pendingViewportCheck=!0,this.requestRender()}).catch(e=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),s.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const t=e instanceof Error?e:new Error(String(e));a(r,`getRows() failed: ${t.message}`,i),this.broadcast("datasource:error",{error:t}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const e=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(e)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.managedNodes=[],this.pendingViewportCheck=!1}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(e){const t=w(e,this.config.pageSize??100);return this.loadedBlocks.has(t)}getLoadedBlockCount(){return this.loadedBlocks.size}};e.ServerSidePlugin=N,e.isLoadingPlaceholder=i});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_serverSide={},e.TbwGrid)}(this,function(e,t){function o(e){return{__loading:!0,__index:e,__rowCacheKey:`__loading:${e}`}}function r(e){return null!=e&&"object"==typeof e&&!0===e.__loading&&"number"==typeof e.__index}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var i="TBW140";function s(e,t,o,r){return`${function(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}(o,r)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}function n(e,t,o,r){console.debug(s(e,t,o,r))}function a(e,t,o,r){console.error(s(e,t,o,r))}var l="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),d=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),c=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function g(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const r of o){const e=r.tagName.toLowerCase();if(d.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>c.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const o=[];for(const t of r.attributes){const e=t.name.toLowerCase();c.test(e)?o.push(t.name):"is"!==e?(h.has(e)&&u.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function f(e,t){if(t){const i=t({size:e});if("string"==typeof i){const e=document.createElement("div");return o=e,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?o.replaceChildren(g(r)):o.textContent=r:o.replaceChildren(),e}return i}var o,r;return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function m(e,t){if(!e.firstElementChild)return;const o=e.querySelector(":scope > .tbw-cell-loading-overlay");o&&(t?.unmount?.(o),o.remove())}function p(e,t){if(!e.firstElementChild)return;const o=e.querySelector(":scope > .tbw-row-loading-overlay");o&&(t?.unmount?.(o),o.remove())}function b(e,t,o,r){const i=t;if(function(e,t,o,r){const{style:i}=t;i.getPropertyValue("--tbw-row-height")&&i.removeProperty("--tbw-row-height");const s=e._getPluginRowHeight?.(o,r),n=void 0!==s&&s>0?`${s}px`:"";i.height!==n&&(i.height=n)}(e,i,o,r),i.__rowDataRef===o&&i.__isCustomRow&&i.classList.contains("tbw-row-loading"))return;!function(e,t){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const o=e.__frameworkAdapter;if(o?.releaseCell||o?.unmount){o.beginBatch?.(e);try{p(t,o);const e=t.children;for(let t=e.length-1;t>=0;t--){const r=e[t];m(r,o),o.releaseCell?.(r)}t.innerHTML=""}finally{o.endBatch?.(e)}}else t.innerHTML=""}(e,i),i.className="data-grid-row placeholder-row",i.__isCustomRow=!0;const s=document.createElement("div");s.className="cell",s.style.gridColumn="1 / -1",s.setAttribute("role","gridcell"),s.textContent=" ",i.appendChild(s),function(e,t,o,r){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(":scope > .tbw-row-loading-overlay")){const t=document.createElement("div");if(t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true"),o)t.appendChild(f("small",o));else{const e=document.createElement("div");e.className="tbw-row-loading-spinner",t.appendChild(e)}e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),p(e,r)}(i,!0,e.effectiveConfig?.loadingRenderer)}function w(e,t){return Math.floor(e/t)}function v(){return new DOMException("Aborted","AbortError")}function C(e,t,o,r,i){const s=function(e,t){return{start:e*t,end:(e+1)*t}}(t,o);let n;try{n=e.getRows({startNode:s.start,endNode:s.end,pageSize:s.end-s.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:i})}catch(a){return Promise.reject(a)}return function(e,t){return t.aborted?Promise.reject(v()):"object"!=typeof(o=e)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const i=()=>r(v());t.addEventListener("abort",i,{once:!0}),Promise.resolve(e).then(e=>{t.removeEventListener("abort",i),o(e)},e=>{t.removeEventListener("abort",i),r(e)})}):new Promise((o,r)=>{let i=!1;const s=e.subscribe({next:e=>{i||(i=!0,o(e),s.unsubscribe())},error:e=>{i||(i=!0,r(e))},complete:()=>{i||(i=!0,r(new Error("getRows observable completed without emitting a value")))}});i||t.addEventListener("abort",()=>{i||(i=!0,s.unsubscribe(),r(v()))},{once:!0})});var o}(n,i)}function k(e,t,o){const r=w(e,t),i=o.get(r);if(i)return i[e%t]}var S=new WeakSet;function N(e){let t=null;const o={async getRows({startNode:o,endNode:r,signal:i}){const{rows:s,total:n}=await(o=>(t||(t=fetch(e,{signal:o}).then(async t=>{if(!t.ok)throw new Error(`Failed to fetch "${e}": ${t.status} ${t.statusText}`);const o=await t.json();if(Array.isArray(o))return{rows:o,total:o.length};const r=o??{},i=Array.isArray(r.rows)?r.rows:[];return{rows:i,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:i.length}}).catch(e=>{throw t=null,e})),t))(i);return{rows:s.slice(o,r),totalNodeCount:n}}};return S.add(o),o}function y(e){return null!=e&&S.has(e)}function B(e,t,o,r,i){const s=Math.max(0,t),n=Math.min(i,o);if(n>s)for(const a of function(e,t,o){const r=w(e,o),i=w(t-1,o),s=[];for(let n=r;n<=i;n++)s.push(n);return s}(s,n,r))e.add(a)}var M=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10,renderRow:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"},{type:"datasource:filter-mode",description:"Who filters rows while a data source is active: 'server' (data source) or 'local' (grid)"},{type:"datasource:sort-mode",description:"Who sorts rows while a data source is active: 'server' (data source) or 'local' (grid)"}]};name="serverSide";get defaultConfig(){return{maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;infiniteScrollMode=!1;loadedBlocks=new Map;loadingBlocks=new Set;blockControllers=new Map;childControllers=new Set;scrollDebounceTimer;pendingViewportCheck=!1;managedNodes=[];#e=0;attach(e){if(super.attach(e),this.on("sort-change",()=>{"local"===this.sortMode?this.requestRender():this.onModelChange()}),this.on("filter-change",()=>{"local"===this.filterMode?(this.pendingViewportCheck=!0,this.requestRender()):this.onModelChange()}),this.config.dataSource)return void this.setDataSource(this.config.dataSource);const t=this.gridElement?.getAttribute("data-src");t&&this.setDataSource(N(t))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.#e++,this.abortAllBlocks();for(const e of this.childControllers)e.abort();this.childControllers.clear(),this.managedNodes=[],this.pendingViewportCheck=!1,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const e of this.blockControllers.values())e.abort();this.blockControllers.clear(),this.loadingBlocks.clear()}releaseBlock(e,t){this.blockControllers.get(e)===t&&(this.blockControllers.delete(e),this.loadingBlocks.delete(e))}get sortMode(){return y(this.dataSource)?"local":this.config.sortMode??"server"}get filterMode(){return y(this.dataSource)?"local":this.config.filterMode??"server"}getEnrichmentParams(){const e="local"===this.sortMode,t="local"===this.filterMode,o=e?void 0:this.grid?.query?.("sort:get-model",null),r=t?void 0:this.grid?.query?.("filter:get-model",null);let i=o?.[0];const s=this.grid;if(!e&&!i&&s?._sortState){const{field:e,direction:t}=s._sortState;i=[{field:e,direction:1===t?"asc":"desc"}]}return{sortModel:i,filterModel:r?.[0]}}getRequiredBlockNumbers(e,t,o,r){const i=this.knownTotal,s=new Set,n=this.queryViewportMapping(e,t),a=this.displayDiffers;if(n||!a){const a=n??{startNode:e,endNode:t};B(s,a.startNode-o,a.endNode+o,r,i)}return a&&this.addPlaceholderBlocks(s,e-o,t+o,r,i),[...s].sort((e,t)=>e-t)}get knownTotal(){return this.totalNodeCount>0?this.totalNodeCount:1/0}get displayDiffers(){return this.rows!==this.managedNodes&&this.managedNodes.length>0}queryViewportMapping(e,t){const o={viewportStart:e,viewportEnd:t};return(this.grid?.query?.("datasource:viewport-mapping",o))?.[0]}addPlaceholderBlocks(e,t,o,i,s){const n=this.rows,a=Math.min(n.length,Math.ceil(o));for(let l=Math.max(0,Math.floor(t));l<a;l++){const t=n[l];r(t)&&t.__index<s&&e.add(w(t.__index,i))}}onModelChange(){this.dataSource&&(this.abortAllBlocks(),this.loadedBlocks.clear(),this.#e++,this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.requestRender(),this.loadRequiredBlocks())}applyServerResult(e,t,o){void 0!==e.lastNode?(this.totalNodeCount=e.lastNode+1,this.infiniteScrollMode=!1):-1===e.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=e.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&e.rows.length<o&&(this.totalNodeCount=t*o+e.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(e){let t=0;for(const[o,r]of this.loadedBlocks){const i=o*e+r.length;i>t&&(t=i)}return t+e}getNodeCount(e){return this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:e}=this.grid,t=this.config.pageSize??100,o=Math.max(0,this.config.loadThreshold??0),r=this.getRequiredBlockNumbers(e.start,e.end,o,t);if(0===r.length)return;const s=this.getEnrichmentParams(),l=this.grid?.getAttribute?.("id")??void 0;for(const d of r){if(this.loadedBlocks.has(d)||this.loadingBlocks.has(d))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){n("TBW143","Concurrent request limit reached, deferring block load",l);break}this.loadingBlocks.add(d);const e=new AbortController;this.blockControllers.set(d,e),this.broadcast("datasource:loading",{loading:!0}),C(this.dataSource,d,t,s,e.signal).then(o=>{if(this.releaseBlock(d,e),e.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(d,o.rows);const r=this.managedNodes.length;this.applyServerResult(o,d,t);const i=d*t;for(let e=0;e<o.rows.length;e++)i+e<this.managedNodes.length&&(this.managedNodes[i+e]=o.rows[e]);const s={rows:o.rows,totalNodeCount:o.totalNodeCount,startNode:i,endNode:i+o.rows.length,claimed:!1,generation:this.#e};this.broadcast("datasource:data",s),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||s.claimed||this.rows!==this.managedNodes||this.managedNodes.length!==this.getNodeCount(t)||!0===this.grid._virtualization?.variableHeights?(this.managedNodes=this.managedNodes.slice(),this.pendingViewportCheck=!0,this.requestRender()):this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(t=>{if(this.releaseBlock(d,e),e.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const o=t instanceof Error?t:new Error(String(t));a(i,`getRows() failed: ${o.message}`,l),this.broadcast("datasource:error",{error:o}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(e){if(!this.dataSource)return[...e];const r=this.config.pageSize??100,i=this.getNodeCount(r);for(;this.managedNodes.length<i;)this.managedNodes.push(o(this.managedNodes.length));this.managedNodes.length=i;for(let t=0;t<i;t++){const e=k(t,r,this.loadedBlocks);e&&(this.managedNodes[t]=e)}const s=this.grid;if("local"===this.sortMode&&s?._sortState){const e=s._columns??[],o=(s.effectiveConfig?.sortHandler??t.builtInSort)(this.managedNodes,s._sortState,e);return o&&"function"==typeof o.then?(o.catch(()=>{}),this.managedNodes):o}return this.managedNodes}renderRow(e,t,o){return!(!r(e)||"columns"===this.config.placeholderRendering)&&(b(this.grid,t,e,o),!0)}afterRender(){this.pendingViewportCheck&&(this.pendingViewportCheck=!1,this.loadRequiredBlocks())}onScroll(e){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(e){switch(e.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:filter-mode":return this.dataSource?this.filterMode:void 0;case"datasource:sort-mode":return this.dataSource?this.sortMode:void 0;case"datasource:fetch-children":{const{context:t,signal:o}=e.context;return void this.fetchChildren(t,o)}}}fetchChildren(e,t){if(!this.dataSource)return;if(t?.aborted)return;const o=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows){const t=`Plugin "${e.source}" requested child rows but getChildRows() is not implemented on the dataSource`;return function(e,t,o,r){console.warn(s(e,t,o,r))}("TBW142",t,o),void this.broadcast("datasource:error",{error:new Error(t),context:e})}const r=this.getEnrichmentParams(),i=new AbortController,n=()=>i.abort(),l=()=>{this.childControllers.delete(i),t?.removeEventListener("abort",n),i.signal.removeEventListener("abort",l)};i.signal.addEventListener("abort",l,{once:!0}),t?.addEventListener("abort",n,{once:!0}),this.childControllers.add(i);const d=()=>(l(),!i.signal.aborted||(this.broadcast("datasource:loading",{loading:!1,context:e}),!1));let c;this.broadcast("datasource:loading",{loading:!0,context:e});try{c=this.dataSource.getChildRows({context:e,sortModel:r.sortModel,filterModel:r.filterModel,signal:i.signal})}catch(h){c=Promise.reject(h)}c.then(t=>{if(!d())return;const o={rows:t.rows,context:e,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:e})}).catch(t=>{if(!d())return;const r=t instanceof Error?t:new Error(String(t));a("TBW141",`getChildRows() failed: ${r.message}`,o),this.broadcast("datasource:error",{error:r,context:e}),this.broadcast("datasource:loading",{loading:!1,context:e})})}setDataSource(e){this.abortAllBlocks(),this.dataSource=e,this.loadedBlocks.clear(),this.#e++,this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.pendingViewportCheck=!1;const t=this.config.pageSize??100,o=this.getEnrichmentParams(),r=this.grid?.getAttribute?.("id")??void 0,s=new AbortController;this.blockControllers.set(0,s),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),C(e,0,t,o,s.signal).then(e=>{if(this.releaseBlock(0,s),s.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(0,e.rows),this.applyServerResult(e,0,t);const o={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:0,endNode:e.rows.length,claimed:!1,generation:this.#e};this.broadcast("datasource:data",o),this.broadcast("datasource:loading",{loading:!1}),this.pendingViewportCheck=!0,this.managedNodes=this.managedNodes.slice(),this.requestRender()}).catch(e=>{if(this.releaseBlock(0,s),s.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const t=e instanceof Error?e:new Error(String(e));a(i,`getRows() failed: ${t.message}`,r),this.broadcast("datasource:error",{error:t}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const e=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(e)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.#e++,this.managedNodes=[],this.pendingViewportCheck=!1}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(e){const t=w(e,this.config.pageSize??100);return this.loadedBlocks.has(t)}getLoadedBlockCount(){return this.loadedBlocks.size}};e.ServerSidePlugin=M,e.isLoadingPlaceholder=r});
2
2
  //# sourceMappingURL=server-side.umd.js.map