@toolbox-web/grid 3.8.2 → 3.8.3

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 (82) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/defaults.d.ts +1 -1
  6. package/lib/core/internal/aria.d.ts +1 -1
  7. package/lib/core/internal/config-manager.d.ts +0 -4
  8. package/lib/core/types.d.ts +6 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/clipboard/clipboard-plugin.d.ts +2 -3
  11. package/lib/plugins/clipboard/index.js +1 -1
  12. package/lib/plugins/clipboard/index.js.map +1 -1
  13. package/lib/plugins/column-virtualization/index.js +1 -1
  14. package/lib/plugins/column-virtualization/index.js.map +1 -1
  15. package/lib/plugins/context-menu/index.js +1 -1
  16. package/lib/plugins/context-menu/index.js.map +1 -1
  17. package/lib/plugins/editing/index.js +1 -1
  18. package/lib/plugins/editing/index.js.map +1 -1
  19. package/lib/plugins/export/index.js +1 -1
  20. package/lib/plugins/export/index.js.map +1 -1
  21. package/lib/plugins/filtering/index.js +1 -1
  22. package/lib/plugins/filtering/index.js.map +1 -1
  23. package/lib/plugins/grouping-columns/index.js +1 -1
  24. package/lib/plugins/grouping-columns/index.js.map +1 -1
  25. package/lib/plugins/grouping-rows/index.js +1 -1
  26. package/lib/plugins/grouping-rows/index.js.map +1 -1
  27. package/lib/plugins/master-detail/index.js +1 -1
  28. package/lib/plugins/master-detail/index.js.map +1 -1
  29. package/lib/plugins/multi-sort/index.js +1 -1
  30. package/lib/plugins/multi-sort/index.js.map +1 -1
  31. package/lib/plugins/pinned-columns/index.js +1 -1
  32. package/lib/plugins/pinned-columns/index.js.map +1 -1
  33. package/lib/plugins/pinned-rows/index.js +1 -1
  34. package/lib/plugins/pinned-rows/index.js.map +1 -1
  35. package/lib/plugins/pivot/index.js +1 -1
  36. package/lib/plugins/pivot/index.js.map +1 -1
  37. package/lib/plugins/print/index.js +1 -1
  38. package/lib/plugins/print/index.js.map +1 -1
  39. package/lib/plugins/reorder-columns/index.js +1 -1
  40. package/lib/plugins/reorder-columns/index.js.map +1 -1
  41. package/lib/plugins/responsive/index.js +1 -1
  42. package/lib/plugins/responsive/index.js.map +1 -1
  43. package/lib/plugins/row-drag-drop/index.js +1 -1
  44. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  45. package/lib/plugins/row-drag-drop/row-drag-drop-plugin.d.ts +1 -0
  46. package/lib/plugins/row-drag-drop/types.d.ts +3 -2
  47. package/lib/plugins/selection/index.js +1 -1
  48. package/lib/plugins/selection/index.js.map +1 -1
  49. package/lib/plugins/selection/selection-plugin.d.ts +2 -2
  50. package/lib/plugins/server-side/index.js +1 -1
  51. package/lib/plugins/server-side/index.js.map +1 -1
  52. package/lib/plugins/shell/index.js +1 -1
  53. package/lib/plugins/shell/index.js.map +1 -1
  54. package/lib/plugins/sticky-rows/index.js +1 -1
  55. package/lib/plugins/sticky-rows/index.js.map +1 -1
  56. package/lib/plugins/tooltip/index.js +1 -1
  57. package/lib/plugins/tooltip/index.js.map +1 -1
  58. package/lib/plugins/tree/index.js +1 -1
  59. package/lib/plugins/tree/index.js.map +1 -1
  60. package/lib/plugins/undo-redo/index.js +1 -1
  61. package/lib/plugins/undo-redo/index.js.map +1 -1
  62. package/lib/plugins/visibility/index.js +1 -1
  63. package/lib/plugins/visibility/index.js.map +1 -1
  64. package/package.json +1 -1
  65. package/umd/grid.all.umd.js +1 -1
  66. package/umd/grid.all.umd.js.map +1 -1
  67. package/umd/grid.umd.js +1 -1
  68. package/umd/grid.umd.js.map +1 -1
  69. package/umd/plugins/clipboard.umd.js +1 -1
  70. package/umd/plugins/clipboard.umd.js.map +1 -1
  71. package/umd/plugins/editing.umd.js +1 -1
  72. package/umd/plugins/editing.umd.js.map +1 -1
  73. package/umd/plugins/grouping-rows.umd.js +1 -1
  74. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  75. package/umd/plugins/row-drag-drop.umd.js +1 -1
  76. package/umd/plugins/row-drag-drop.umd.js.map +1 -1
  77. package/umd/plugins/selection.umd.js +1 -1
  78. package/umd/plugins/selection.umd.js.map +1 -1
  79. package/umd/plugins/tooltip.umd.js +1 -1
  80. package/umd/plugins/tooltip.umd.js.map +1 -1
  81. package/umd/plugins/tree.umd.js +1 -1
  82. package/umd/plugins/tree.umd.js.map +1 -1
@@ -257,8 +257,8 @@ export declare class SelectionPlugin extends BaseGridPlugin<SelectionConfig> {
257
257
  * Select all selectable rows (row mode) or all cells (range mode).
258
258
  *
259
259
  * In row mode, selects every row where `isSelectable` returns true (or all rows if no callback).
260
- * In range mode, creates a single range spanning all rows and columns.
261
- * Has no effect in cell mode.
260
+ * In range mode, creates a single range spanning all rows and visible columns.
261
+ * Array modes resolve to their row/range axis. Has no effect in cell mode.
262
262
  *
263
263
  * @example
264
264
  * ```ts
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}var e="TBW140";function o(e,o,r,s){return`${t(r,s)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function r(t,e,r,s){console.debug(o(t,e,r,s))}function s(t,e,r,s){console.error(o(t,e,r,s))}var n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},i=/* @__PURE__ */new WeakMap;function a(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var l=/* @__PURE__ */new Map;function c(t){if(-1===t.indexOf("."))return null;let e=l.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),l.set(t,e)),e}function d(t,e){let o=t;for(let r=0;r<e.length;r++){if(null==o||"object"!=typeof o)return;const t=e[r];if(a(t))return;o=o[t]}return o}function u(t){const e=c(t);return null===e?a(t)?()=>{}:e=>null==e?void 0:e[t]:o=>{if(null==o)return;const r=o;return Object.prototype.hasOwnProperty.call(r,t)?r[t]:d(r,e)}}function h(t,e,o=-1){if(!e.valueAccessor)return function(t,e){if(null==t)return;const o=c(e),r=t;return null===o?a(e)?void 0:r[e]:Object.prototype.hasOwnProperty.call(r,e)?r[e]:d(r,o)}(t,e.field);if("object"!=typeof t||null===t)return e.valueAccessor({row:t,column:e,rowIndex:o});const r=t,s=e.field;let n=i.get(r);if(n){const t=n.get(s);if(void 0!==t)return t.v}else n=/* @__PURE__ */new Map,i.set(r,n);const l=e.valueAccessor({row:t,column:e,rowIndex:o});return n.set(s,{v:l}),l}function g(t,e,o){const r=[...t];return function(t,e,o,r){const s=r.find(t=>t.field===e),n=s?.sortComparator;if(n)if(s?.valueAccessor)t.sort((t,e)=>n(h(t,s),h(e,s),t,e)*o);else{const r=u(e);t.sort((t,e)=>n(r(t),r(e),t,e)*o)}else s?.valueAccessor?function(t,e,o){f(t,t=>h(t,e),o)}(t,s,o):function(t,e,o){if(function(t){return-1===t.indexOf(".")&&!a(t)}(e))return void t.sort((t,r)=>{const s=function(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}(t,r);if(0!==s)return s;const n=t[e],i=r[e];return null==n&&null==i?0:null==n?-o:null==i||n>i?o:n<i?-o:0});f(t,u(e),o)}(t,e,o)}(r,e.field,e.direction,o),r}function f(t,e,o){const r=t.length;if(r<2)return;const s=new Array(r),n=new Uint8Array(r),i=new Array(r);for(let l=0;l<r;l++){const o=t[l];i[l]=l,s[l]=e(o),n[l]=!0===o?.__loading?1:0}i.sort((t,e)=>{const r=n[t];if(r!==n[e])return r?1:-1;const i=s[t],a=s[e];return null==i&&null==a?0:null==i?-o:null==a||i>a?o:i<a?-o:0});const a=new Array(r);for(let l=0;l<r;l++)a[l]=t[i[l]];for(let l=0;l<r;l++)t[l]=a[l]}var m="__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(t=>t.split("").reverse().join("")),p=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),b=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),C=/^\s*(javascript|vbscript|data|blob):/i;function v(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const r of o){const t=r.tagName.toLowerCase();if(p.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>b.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const o=[];for(const e of r.attributes){const t=e.name.toLowerCase();b.test(t)?o.push(e.name):"is"!==t?(w.has(t)&&C.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name):o.push(e.name)}o.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var S=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},r={};for(const o of Object.keys(e))r[o]=this;for(const s of t){const t=s.userConfig;for(const[n,i]of Object.entries(t)){if(void 0===i)continue;if(!(n in e)){e[n]=i,r[n]=s;continue}if(e[n]===i)continue;const t=r[n]?.constructor.name??this.constructor.name,a=s.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,o={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,o)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const o=this.grid?.query?.(t,e);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...n,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);var s,n;void 0!==r?"string"==typeof r?(s=t,(n=r)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?s.replaceChildren(v(n)):s.textContent=n:s.replaceChildren()):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(e,r){void 0!==r?console.warn(o(e,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(t,e){throw new Error(o(t,e,this.gridElement.id,this.name))}};function k(t,e){return Math.floor(t/e)}function N(){return new DOMException("Aborted","AbortError")}function y(t,e,o,r,s){const n=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return function(t,e){return e.aborted?Promise.reject(N()):"object"!=typeof(o=t)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const s=()=>r(N());e.addEventListener("abort",s,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",s),o(t)},t=>{e.removeEventListener("abort",s),r(t)})}):new Promise((o,r)=>{let s=!1;const n=t.subscribe({next:t=>{s||(s=!0,o(t),n.unsubscribe())},error:t=>{s||(s=!0,r(t))},complete:()=>{s||(s=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});s||e.addEventListener("abort",()=>{s||(s=!0,n.unsubscribe(),r(N()))},{once:!0})});var o}(t.getRows({startNode:n.start,endNode:n.end,pageSize:n.end-n.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:s}),s)}function B(t,e,o){const r=k(t,e),s=o.get(r);if(s)return s[t%e]}function R(t){let e=null;return{async getRows({startNode:o,endNode:r,signal:s}){const{rows:n,total:i}=await(o=>(e||(e=fetch(t,{signal:o}).then(async e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const o=await e.json();if(Array.isArray(o))return{rows:o,total:o.length};const r=o??{},s=Array.isArray(r.rows)?r.rows:[];return{rows:s,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:s.length}}).catch(t=>{throw e=null,t})),e))(s);return{rows:n.slice(o,r),totalNodeCount:i}}}}var M=class extends S{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-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=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){if(super.attach(t),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 e=this.gridElement?.getAttribute("data-src");e&&this.setDataSource(R(e))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.abortAllBlocks(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const t of this.blockControllers.values())t.abort();this.blockControllers.clear()}getEnrichmentParams(){const t="local"===this.config.sortMode,e="local"===this.config.filterMode,o=t?void 0:this.grid?.query?.("sort:get-model",null),r=e?void 0:this.grid?.query?.("filter:get-model",null);let s=o?.[0];const n=this.grid;if(!t&&!s&&n?._sortState){const{field:t,direction:e}=n._sortState;s=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:s,filterModel:r?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},r=this.grid?.query?.("datasource:viewport-mapping",o);return r?.[0]?r[0]:{startNode:t,endNode:e,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(t,e,o){void 0!==t.lastNode?(this.totalNodeCount=t.lastNode+1,this.infiniteScrollMode=!1):-1===t.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=t.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&t.rows.length<o&&(this.totalNodeCount=e*o+t.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(t){let e=0;for(const[o,r]of this.loadedBlocks){const s=o*t+r.length;s>e&&(e=s)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:t}=this.grid,o=this.config.pageSize??100,n=this.getViewportMapping(t.start,t.end),i=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,n.startNode-i),l=this.totalNodeCount>0?this.totalNodeCount:1/0,c=Math.min(l,n.endNode+i);if(c<=a)return;const d=function(t,e,o){const r=k(t,o),s=k(e-1,o),n=[];for(let i=r;i<=s;i++)n.push(i);return n}(a,c,o),u=this.getEnrichmentParams(),h=this.grid?.getAttribute?.("id")??void 0;for(const g of d){if(this.loadedBlocks.has(g)||this.loadingBlocks.has(g))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){r("TBW143","Concurrent request limit reached, deferring block load",h);break}this.loadingBlocks.add(g);const t=new AbortController;this.blockControllers.set(g,t),this.broadcast("datasource:loading",{loading:!0}),y(this.dataSource,g,o,u,t.signal).then(e=>{if(this.blockControllers.delete(g),t.signal.aborted)return this.loadingBlocks.delete(g),void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(g,e.rows);const r=this.managedNodes.length;this.applyServerResult(e,g,o),this.loadingBlocks.delete(g);const s=g*o;for(let t=0;t<e.rows.length;t++)s+t<this.managedNodes.length&&(this.managedNodes[s+t]=e.rows[t]);const n={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:s,endNode:s+e.rows.length,claimed:!1};this.broadcast("datasource:data",n),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||n.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?this.requestRender():this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(o=>{if(this.blockControllers.delete(g),this.loadingBlocks.delete(g),t.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const r=o instanceof Error?o:new Error(String(o));s(e,`getRows() failed: ${r.message}`,h),this.broadcast("datasource:error",{error:r}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.pageSize??100,o=this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let s=0;s<o;s++){const t=B(s,e,this.loadedBlocks);t&&(this.managedNodes[s]=t)}const r=this.grid;if("local"===this.config.sortMode&&r?._sortState){const t=r._columns??[],e=(r.effectiveConfig?.sortHandler??g)(this.managedNodes,r._sortState,t);return e&&"function"==typeof e.then?(e.catch(()=>{}),this.managedNodes):e}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const e=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void function(t,e,r,s){console.warn(o(t,e,r,s))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const r=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:r.sortModel,filterModel:r.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(o=>{const r=o instanceof Error?o:new Error(String(o));s("TBW141",`getChildRows() failed: ${r.message}`,e),this.broadcast("datasource:error",{error:r,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.abortAllBlocks(),this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1;const o=this.config.pageSize??100,r=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0,i=new AbortController;this.blockControllers.set(0,i),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),y(t,0,o,r,i.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,o);const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender(),(this.config.loadThreshold??0)>0&&this.loadRequiredBlocks()}).catch(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const o=t instanceof Error?t:new Error(String(t));s(e,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(t)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(t){const e=k(t,this.config.pageSize??100);return this.loadedBlocks.has(e)}getLoadedBlockCount(){return this.loadedBlocks.size}};export{M as ServerSidePlugin};
1
+ function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}var e="TBW140";function o(e,o,r,s){return`${t(r,s)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function r(t,e,r,s){console.debug(o(t,e,r,s))}function s(t,e,r,s){console.error(o(t,e,r,s))}var n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},i=/* @__PURE__ */new WeakMap;function a(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var l=/* @__PURE__ */new Map;function c(t){if(-1===t.indexOf("."))return null;let e=l.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),l.set(t,e)),e}function d(t,e){let o=t;for(let r=0;r<e.length;r++){if(null==o||"object"!=typeof o)return;const t=e[r];if(a(t))return;o=o[t]}return o}function u(t){const e=c(t);return null===e?a(t)?()=>{}:e=>null==e?void 0:e[t]:o=>{if(null==o)return;const r=o;return Object.prototype.hasOwnProperty.call(r,t)?r[t]:d(r,e)}}function h(t,e,o=-1){if(!e.valueAccessor)return function(t,e){if(null==t)return;const o=c(e),r=t;return null===o?a(e)?void 0:r[e]:Object.prototype.hasOwnProperty.call(r,e)?r[e]:d(r,o)}(t,e.field);if("object"!=typeof t||null===t)return e.valueAccessor({row:t,column:e,rowIndex:o});const r=t,s=e.field;let n=i.get(r);if(n){const t=n.get(s);if(void 0!==t)return t.v}else n=/* @__PURE__ */new Map,i.set(r,n);const l=e.valueAccessor({row:t,column:e,rowIndex:o});return n.set(s,{v:l}),l}function g(t,e,o){const r=[...t];return function(t,e,o,r){const s=r.find(t=>t.field===e),n=s?.sortComparator;if(n)if(s?.valueAccessor)t.sort((t,e)=>n(h(t,s),h(e,s),t,e)*o);else{const r=u(e);t.sort((t,e)=>n(r(t),r(e),t,e)*o)}else s?.valueAccessor?function(t,e,o){f(t,t=>h(t,e),o)}(t,s,o):function(t,e,o){if(function(t){return-1===t.indexOf(".")&&!a(t)}(e))return void t.sort((t,r)=>{const s=function(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}(t,r);if(0!==s)return s;const n=t[e],i=r[e];return null==n&&null==i?0:null==n?-o:null==i||n>i?o:n<i?-o:0});f(t,u(e),o)}(t,e,o)}(r,e.field,e.direction,o),r}function f(t,e,o){const r=t.length;if(r<2)return;const s=new Array(r),n=new Uint8Array(r),i=new Array(r);for(let l=0;l<r;l++){const o=t[l];i[l]=l,s[l]=e(o),n[l]=!0===o?.__loading?1:0}i.sort((t,e)=>{const r=n[t];if(r!==n[e])return r?1:-1;const i=s[t],a=s[e];return null==i&&null==a?0:null==i?-o:null==a||i>a?o:i<a?-o:0});const a=new Array(r);for(let l=0;l<r;l++)a[l]=t[i[l]];for(let l=0;l<r;l++)t[l]=a[l]}var m="__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(t=>t.split("").reverse().join("")),p=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),b=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),C=/^\s*(javascript|vbscript|data|blob):/i;function v(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const r of o){const t=r.tagName.toLowerCase();if(p.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>b.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const o=[];for(const e of r.attributes){const t=e.name.toLowerCase();b.test(t)?o.push(e.name):"is"!==t?(w.has(t)&&C.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name):o.push(e.name)}o.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var S=class{static dependencies;static manifest;aliases;version="3.8.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},r={};for(const o of Object.keys(e))r[o]=this;for(const s of t){const t=s.userConfig;for(const[n,i]of Object.entries(t)){if(void 0===i)continue;if(!(n in e)){e[n]=i,r[n]=s;continue}if(e[n]===i)continue;const t=r[n]?.constructor.name??this.constructor.name,a=s.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,o={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,o)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const o=this.grid?.query?.(t,e);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...n,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);var s,n;void 0!==r?"string"==typeof r?(s=t,(n=r)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?s.replaceChildren(v(n)):s.textContent=n:s.replaceChildren()):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(e,r){void 0!==r?console.warn(o(e,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(t,e){throw new Error(o(t,e,this.gridElement.id,this.name))}};function k(t,e){return Math.floor(t/e)}function N(){return new DOMException("Aborted","AbortError")}function y(t,e,o,r,s){const n=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return function(t,e){return e.aborted?Promise.reject(N()):"object"!=typeof(o=t)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const s=()=>r(N());e.addEventListener("abort",s,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",s),o(t)},t=>{e.removeEventListener("abort",s),r(t)})}):new Promise((o,r)=>{let s=!1;const n=t.subscribe({next:t=>{s||(s=!0,o(t),n.unsubscribe())},error:t=>{s||(s=!0,r(t))},complete:()=>{s||(s=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});s||e.addEventListener("abort",()=>{s||(s=!0,n.unsubscribe(),r(N()))},{once:!0})});var o}(t.getRows({startNode:n.start,endNode:n.end,pageSize:n.end-n.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:s}),s)}function B(t,e,o){const r=k(t,e),s=o.get(r);if(s)return s[t%e]}function R(t){let e=null;return{async getRows({startNode:o,endNode:r,signal:s}){const{rows:n,total:i}=await(o=>(e||(e=fetch(t,{signal:o}).then(async e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const o=await e.json();if(Array.isArray(o))return{rows:o,total:o.length};const r=o??{},s=Array.isArray(r.rows)?r.rows:[];return{rows:s,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:s.length}}).catch(t=>{throw e=null,t})),e))(s);return{rows:n.slice(o,r),totalNodeCount:i}}}}var M=class extends S{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-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=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){if(super.attach(t),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 e=this.gridElement?.getAttribute("data-src");e&&this.setDataSource(R(e))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.abortAllBlocks(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const t of this.blockControllers.values())t.abort();this.blockControllers.clear()}getEnrichmentParams(){const t="local"===this.config.sortMode,e="local"===this.config.filterMode,o=t?void 0:this.grid?.query?.("sort:get-model",null),r=e?void 0:this.grid?.query?.("filter:get-model",null);let s=o?.[0];const n=this.grid;if(!t&&!s&&n?._sortState){const{field:t,direction:e}=n._sortState;s=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:s,filterModel:r?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},r=this.grid?.query?.("datasource:viewport-mapping",o);return r?.[0]?r[0]:{startNode:t,endNode:e,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(t,e,o){void 0!==t.lastNode?(this.totalNodeCount=t.lastNode+1,this.infiniteScrollMode=!1):-1===t.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=t.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&t.rows.length<o&&(this.totalNodeCount=e*o+t.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(t){let e=0;for(const[o,r]of this.loadedBlocks){const s=o*t+r.length;s>e&&(e=s)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:t}=this.grid,o=this.config.pageSize??100,n=this.getViewportMapping(t.start,t.end),i=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,n.startNode-i),l=this.totalNodeCount>0?this.totalNodeCount:1/0,c=Math.min(l,n.endNode+i);if(c<=a)return;const d=function(t,e,o){const r=k(t,o),s=k(e-1,o),n=[];for(let i=r;i<=s;i++)n.push(i);return n}(a,c,o),u=this.getEnrichmentParams(),h=this.grid?.getAttribute?.("id")??void 0;for(const g of d){if(this.loadedBlocks.has(g)||this.loadingBlocks.has(g))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){r("TBW143","Concurrent request limit reached, deferring block load",h);break}this.loadingBlocks.add(g);const t=new AbortController;this.blockControllers.set(g,t),this.broadcast("datasource:loading",{loading:!0}),y(this.dataSource,g,o,u,t.signal).then(e=>{if(this.blockControllers.delete(g),t.signal.aborted)return this.loadingBlocks.delete(g),void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(g,e.rows);const r=this.managedNodes.length;this.applyServerResult(e,g,o),this.loadingBlocks.delete(g);const s=g*o;for(let t=0;t<e.rows.length;t++)s+t<this.managedNodes.length&&(this.managedNodes[s+t]=e.rows[t]);const n={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:s,endNode:s+e.rows.length,claimed:!1};this.broadcast("datasource:data",n),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||n.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?this.requestRender():this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(o=>{if(this.blockControllers.delete(g),this.loadingBlocks.delete(g),t.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const r=o instanceof Error?o:new Error(String(o));s(e,`getRows() failed: ${r.message}`,h),this.broadcast("datasource:error",{error:r}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.pageSize??100,o=this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let s=0;s<o;s++){const t=B(s,e,this.loadedBlocks);t&&(this.managedNodes[s]=t)}const r=this.grid;if("local"===this.config.sortMode&&r?._sortState){const t=r._columns??[],e=(r.effectiveConfig?.sortHandler??g)(this.managedNodes,r._sortState,t);return e&&"function"==typeof e.then?(e.catch(()=>{}),this.managedNodes):e}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const e=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void function(t,e,r,s){console.warn(o(t,e,r,s))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const r=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:r.sortModel,filterModel:r.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(o=>{const r=o instanceof Error?o:new Error(String(o));s("TBW141",`getChildRows() failed: ${r.message}`,e),this.broadcast("datasource:error",{error:r,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.abortAllBlocks(),this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1;const o=this.config.pageSize??100,r=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0,i=new AbortController;this.blockControllers.set(0,i),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),y(t,0,o,r,i.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,o);const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender(),(this.config.loadThreshold??0)>0&&this.loadRequiredBlocks()}).catch(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const o=t instanceof Error?t:new Error(String(t));s(e,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(t)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(t){const e=k(t,this.config.pageSize??100);return this.loadedBlocks.has(e)}getLoadedBlockCount(){return this.loadedBlocks.size}};export{M as ServerSidePlugin};
2
2
  //# sourceMappingURL=index.js.map