@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.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/custom-elements.json +2 -2
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +8 -4
- package/lib/core/plugin/base-plugin.d.ts +7 -0
- package/lib/core/types.d.ts +2 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/context-menu/context-menu-plugin.d.ts +9 -4
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +8 -4
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +2 -1
- package/lib/plugins/filtering/filter-model.d.ts +2 -1
- package/lib/plugins/filtering/filtering-plugin.d.ts +5 -2
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +7 -14
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +48 -0
- package/lib/plugins/grouping-rows/index.d.ts +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +21 -0
- package/lib/plugins/master-detail/index.d.ts +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/master-detail-plugin.d.ts +28 -6
- package/lib/plugins/master-detail/master-detail.d.ts +0 -8
- package/lib/plugins/master-detail/types.d.ts +25 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/selection-plugin.d.ts +8 -1
- package/lib/plugins/server-side/datasource-types.d.ts +28 -0
- package/lib/plugins/server-side/datasource.d.ts +7 -0
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/server-side-plugin.d.ts +61 -8
- package/lib/plugins/server-side/types.d.ts +9 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/tree-plugin.d.ts +5 -11
- package/lib/plugins/tree/types.d.ts +22 -6
- package/lib/plugins/undo-redo/history.d.ts +2 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +13 -1
- package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +15 -2
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
|
@@ -282,9 +282,16 @@ export declare class SelectionPlugin extends BaseGridPlugin<SelectionConfig> {
|
|
|
282
282
|
*/
|
|
283
283
|
selectRows(indices: number[]): void;
|
|
284
284
|
/**
|
|
285
|
-
* Get the indices of all
|
|
285
|
+
* Get the indices of all rows touched by the current selection.
|
|
286
286
|
* Returns indices sorted in ascending order.
|
|
287
287
|
*
|
|
288
|
+
* Works across all selection modes:
|
|
289
|
+
* - **Row mode**: The selected row indices.
|
|
290
|
+
* - **Cell mode**: The row index of the selected cell, or `[]`.
|
|
291
|
+
* - **Range mode**: The unique row indices that intersect any selected range.
|
|
292
|
+
*
|
|
293
|
+
* Indices refer to the grid's processed (sorted/filtered) row array.
|
|
294
|
+
*
|
|
288
295
|
* @example
|
|
289
296
|
* ```ts
|
|
290
297
|
* const plugin = grid.getPluginByName('selection');
|
|
@@ -102,6 +102,17 @@ export interface GetChildRowsParams extends DataRequestModel {
|
|
|
102
102
|
source: string;
|
|
103
103
|
[key: string]: unknown;
|
|
104
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Cancellation signal for the request. Aborted when:
|
|
107
|
+
* - the requesting plugin supersedes the request (TreePlugin: the parent row was
|
|
108
|
+
* replaced by a refetch and the replacement rendered before the children arrived)
|
|
109
|
+
* - the plugin detaches or the grid disconnects
|
|
110
|
+
*
|
|
111
|
+
* A result for an aborted request is discarded. Pass it to `fetch(url, { signal })`
|
|
112
|
+
* to cancel the HTTP request; data sources that ignore it keep working.
|
|
113
|
+
* @since 3.9.2
|
|
114
|
+
*/
|
|
115
|
+
signal: AbortSignal;
|
|
105
116
|
}
|
|
106
117
|
/**
|
|
107
118
|
* Result returned from {@link ServerSideDataSource.getChildRows}.
|
|
@@ -211,6 +222,16 @@ export interface DataSourceDataDetail<TRow = unknown> {
|
|
|
211
222
|
endNode: number;
|
|
212
223
|
/** Mutable flag — structural plugins set this to `true` when they consume the data. */
|
|
213
224
|
claimed: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Cache generation the block belongs to. It changes whenever ServerSide discards its
|
|
227
|
+
* cache (`setDataSource()`, `refresh()`, `purgeCache()`, a server-side sort/filter
|
|
228
|
+
* change). Blocks with the same generation are slices of one dataset that a consumer
|
|
229
|
+
* merges at `startNode`; a changed generation means every earlier block is gone.
|
|
230
|
+
* Omitted by emitters that predate it — treat such a block as a full replacement.
|
|
231
|
+
*
|
|
232
|
+
* @since 3.9.2
|
|
233
|
+
*/
|
|
234
|
+
generation?: number;
|
|
214
235
|
}
|
|
215
236
|
/**
|
|
216
237
|
* Detail for `datasource:children` broadcast events.
|
|
@@ -279,4 +300,11 @@ export interface FetchChildrenQuery {
|
|
|
279
300
|
source: string;
|
|
280
301
|
[key: string]: unknown;
|
|
281
302
|
};
|
|
303
|
+
/**
|
|
304
|
+
* Requester-owned cancellation. Aborting it aborts the
|
|
305
|
+
* {@link GetChildRowsParams.signal} and discards the result (no
|
|
306
|
+
* `datasource:children` / `datasource:error` broadcast).
|
|
307
|
+
* @since 3.9.2
|
|
308
|
+
*/
|
|
309
|
+
signal?: AbortSignal;
|
|
282
310
|
}
|
|
@@ -37,3 +37,10 @@ export declare function isBlockLoading(blockNumber: number, loadingBlocks: Set<n
|
|
|
37
37
|
* @internal
|
|
38
38
|
*/
|
|
39
39
|
export declare function createUrlDataSource(url: string): ServerSideDataSource;
|
|
40
|
+
/**
|
|
41
|
+
* Whether `source` was built by {@link createUrlDataSource}. Such a source only
|
|
42
|
+
* slices a cached dataset and ignores `sortModel` / `filterModel`, so the grid
|
|
43
|
+
* must sort and filter its rows locally.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function isUrlDataSource(source: ServerSideDataSource | null): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BaseGridPlugin as t,builtInSort as e}from"@toolbox-web/grid";function o(t){return{__loading:!0,__index:t,__rowCacheKey:`__loading:${t}`}}function r(t){return null!=t&&"object"==typeof t&&!0===t.__loading&&"number"==typeof t.__index}var i="TBW140";function s(t,e,o,r){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(o,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}function n(t,e,o,r){console.debug(s(t,e,o,r))}function a(t,e,o,r){console.error(s(t,e,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(t=>t.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(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(d.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>c.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();c.test(t)?o.push(e.name):"is"!==t?(h.has(t)&&u.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}function f(t,e){if(e){const i=e({size:t});if("string"==typeof i){const t=document.createElement("div");return o=t,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?o.replaceChildren(g(r)):o.textContent=r:o.replaceChildren(),t}return i}var o,r;return function(t){const e=document.createElement("div");return e.className=`tbw-spinner tbw-spinner--${t}`,e.setAttribute("role","progressbar"),e.setAttribute("aria-label","Loading"),e}(t)}function m(t,e){if(!t.firstElementChild)return;const o=t.querySelector(":scope > .tbw-cell-loading-overlay");o&&(e?.unmount?.(o),o.remove())}function p(t,e){if(!t.firstElementChild)return;const o=t.querySelector(":scope > .tbw-row-loading-overlay");o&&(e?.unmount?.(o),o.remove())}function b(t,e,o,r){const i=e;if(function(t,e,o,r){const{style:i}=e;i.getPropertyValue("--tbw-row-height")&&i.removeProperty("--tbw-row-height");const s=t._getPluginRowHeight?.(o,r),n=void 0!==s&&s>0?`${s}px`:"";i.height!==n&&(i.height=n)}(t,i,o,r),i.__rowDataRef===o&&i.__isCustomRow&&i.classList.contains("tbw-row-loading"))return;!function(t,e){e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy");const o=t.__frameworkAdapter;if(o?.releaseCell||o?.unmount){o.beginBatch?.(t);try{p(e,o);const t=e.children;for(let e=t.length-1;e>=0;e--){const r=t[e];m(r,o),o.releaseCell?.(r)}e.innerHTML=""}finally{o.endBatch?.(t)}}else e.innerHTML=""}(t,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(t,e,o,r){if(e){if(t.classList.add("tbw-row-loading"),t.setAttribute("aria-busy","true"),!t.querySelector(":scope > .tbw-row-loading-overlay")){const e=document.createElement("div");if(e.className="tbw-row-loading-overlay",e.setAttribute("aria-hidden","true"),o)e.appendChild(f("small",o));else{const t=document.createElement("div");t.className="tbw-row-loading-spinner",e.appendChild(t)}t.appendChild(e)}}else t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy"),p(t,r)}(i,!0,t.effectiveConfig?.loadingRenderer)}function w(t,e){return Math.floor(t/e)}function C(){return new DOMException("Aborted","AbortError")}function v(t,e,o,r,i){const s=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return function(t,e){return e.aborted?Promise.reject(C()):"object"!=typeof(o=t)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const i=()=>r(C());e.addEventListener("abort",i,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",i),o(t)},t=>{e.removeEventListener("abort",i),r(t)})}):new Promise((o,r)=>{let i=!1;const s=t.subscribe({next:t=>{i||(i=!0,o(t),s.unsubscribe())},error:t=>{i||(i=!0,r(t))},complete:()=>{i||(i=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});i||e.addEventListener("abort",()=>{i||(i=!0,s.unsubscribe(),r(C()))},{once:!0})});var o}(t.getRows({startNode:s.start,endNode:s.end,pageSize:s.end-s.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:i}),i)}function k(t,e,o){const r=w(t,e),i=o.get(r);if(i)return i[t%e]}function S(t){let e=null;return{async getRows({startNode:o,endNode:r,signal:i}){const{rows:s,total:n}=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??{},i=Array.isArray(r.rows)?r.rows:[];return{rows:i,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:i.length}}).catch(t=>{throw e=null,t})),e))(i);return{rows:s.slice(o,r),totalNodeCount:n}}}}var N=class extends t{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=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;lastRequestId=0;scrollDebounceTimer;pendingViewportCheck=!1;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(S(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.pendingViewportCheck=!1,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 i=o?.[0];const s=this.grid;if(!t&&!i&&s?._sortState){const{field:t,direction:e}=s._sortState;i=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:i,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 i=o*t+r.length;i>e&&(e=i)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:t}=this.grid,e=this.config.pageSize??100,o=this.getViewportMapping(t.start,t.end),r=Math.max(0,this.config.loadThreshold??0),s=Math.max(0,o.startNode-r),l=this.totalNodeCount>0?this.totalNodeCount:1/0,d=Math.min(l,o.endNode+r);if(d<=s)return;const c=function(t,e,o){const r=w(t,o),i=w(e-1,o),s=[];for(let n=r;n<=i;n++)s.push(n);return s}(s,d,e),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 t=new AbortController;this.blockControllers.set(g,t),this.broadcast("datasource:loading",{loading:!0}),v(this.dataSource,g,e,h,t.signal).then(o=>{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,o.rows);const r=this.managedNodes.length;this.applyServerResult(o,g,e),this.loadingBlocks.delete(g);const i=g*e;for(let t=0;t<o.rows.length;t++)i+t<this.managedNodes.length&&(this.managedNodes[i+t]=o.rows[t]);const s={rows:o.rows,totalNodeCount:o.totalNodeCount,startNode:i,endNode:i+o.rows.length,claimed:!1};this.broadcast("datasource:data",s),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||s.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?(this.pendingViewportCheck=!0,this.requestRender()):this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(e=>{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 o=e instanceof Error?e:new Error(String(e));a(i,`getRows() failed: ${o.message}`,u),this.broadcast("datasource:error",{error:o}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const r=this.config.pageSize??100,i=this.infiniteScrollMode?this.getInfiniteScrollEstimate(r):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<i;)this.managedNodes.push(o(this.managedNodes.length));this.managedNodes.length=i;for(let e=0;e<i;e++){const t=k(e,r,this.loadedBlocks);t&&(this.managedNodes[e]=t)}const s=this.grid;if("local"===this.config.sortMode&&s?._sortState){const t=s._columns??[],o=(s.effectiveConfig?.sortHandler??e)(this.managedNodes,s._sortState,t);return o&&"function"==typeof o.then?(o.catch(()=>{}),this.managedNodes):o}return this.managedNodes}renderRow(t,e,o){return!(!r(t)||"columns"===this.config.placeholderRendering)&&(b(this.grid,e,t,o),!0)}afterRender(){this.pendingViewportCheck&&(this.pendingViewportCheck=!1,this.loadRequiredBlocks())}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,o,r){console.warn(s(t,e,o,r))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const o=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:o.sortModel,filterModel:o.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));a("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,this.pendingViewportCheck=!1;const e=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}),v(t,0,e,o,s.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),s.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,e);const o={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",o),this.broadcast("datasource:loading",{loading:!1}),this.pendingViewportCheck=!0,this.requestRender()}).catch(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),s.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const e=t instanceof Error?t:new Error(String(t));a(i,`getRows() failed: ${e.message}`,r),this.broadcast("datasource:error",{error:e}),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=[],this.pendingViewportCheck=!1}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(t){const e=w(t,this.config.pageSize??100);return this.loadedBlocks.has(e)}getLoadedBlockCount(){return this.loadedBlocks.size}};export{N as ServerSidePlugin,r as isLoadingPlaceholder};
|
|
1
|
+
import{BaseGridPlugin as e,builtInSort as t}from"@toolbox-web/grid";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}var s="TBW140";function i(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(i(e,t,o,r))}function a(e,t,o,r){console.error(i(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 s=t({size:e});if("string"==typeof s){const e=document.createElement("div");return o=e,(r=s)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?o.replaceChildren(g(r)):o.textContent=r:o.replaceChildren(),e}return s}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 s=t;if(function(e,t,o,r){const{style:s}=t;s.getPropertyValue("--tbw-row-height")&&s.removeProperty("--tbw-row-height");const i=e._getPluginRowHeight?.(o,r),n=void 0!==i&&i>0?`${i}px`:"";s.height!==n&&(s.height=n)}(e,s,o,r),s.__rowDataRef===o&&s.__isCustomRow&&s.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,s),s.className="data-grid-row placeholder-row",s.__isCustomRow=!0;const i=document.createElement("div");i.className="cell",i.style.gridColumn="1 / -1",i.setAttribute("role","gridcell"),i.textContent=" ",s.appendChild(i),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)}(s,!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,s){const i=function(e,t){return{start:e*t,end:(e+1)*t}}(t,o);let n;try{n=e.getRows({startNode:i.start,endNode:i.end,pageSize:i.end-i.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:s})}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 s=()=>r(v());t.addEventListener("abort",s,{once:!0}),Promise.resolve(e).then(e=>{t.removeEventListener("abort",s),o(e)},e=>{t.removeEventListener("abort",s),r(e)})}):new Promise((o,r)=>{let s=!1;const i=e.subscribe({next:e=>{s||(s=!0,o(e),i.unsubscribe())},error:e=>{s||(s=!0,r(e))},complete:()=>{s||(s=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});s||t.addEventListener("abort",()=>{s||(s=!0,i.unsubscribe(),r(v()))},{once:!0})});var o}(n,s)}function k(e,t,o){const r=w(e,t),s=o.get(r);if(s)return s[e%t]}var S=/* @__PURE__ */new WeakSet;function N(e){let t=null;const o={async getRows({startNode:o,endNode:r,signal:s}){const{rows:i,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??{},s=Array.isArray(r.rows)?r.rows:[];return{rows:s,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:s.length}}).catch(e=>{throw t=null,e})),t))(s);return{rows:i.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,s){const i=Math.max(0,t),n=Math.min(s,o);if(n>i)for(const a of function(e,t,o){const r=w(e,o),s=w(t-1,o),i=[];for(let n=r;n<=s;n++)i.push(n);return i}(i,n,r))e.add(a)}var M=class extends e{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=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;childControllers=/* @__PURE__ */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 s=o?.[0];const i=this.grid;if(!e&&!s&&i?._sortState){const{field:e,direction:t}=i._sortState;s=[{field:e,direction:1===t?"asc":"desc"}]}return{sortModel:s,filterModel:r?.[0]}}getRequiredBlockNumbers(e,t,o,r){const s=this.knownTotal,i=/* @__PURE__ */new Set,n=this.queryViewportMapping(e,t),a=this.displayDiffers;if(n||!a){const a=n??{startNode:e,endNode:t};B(i,a.startNode-o,a.endNode+o,r,s)}return a&&this.addPlaceholderBlocks(i,e-o,t+o,r,s),[...i].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,s,i){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<i&&e.add(w(t.__index,s))}}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 s=o*e+r.length;s>t&&(t=s)}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 i=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,i,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 s=d*t;for(let e=0;e<o.rows.length;e++)s+e<this.managedNodes.length&&(this.managedNodes[s+e]=o.rows[e]);const i={rows:o.rows,totalNodeCount:o.totalNodeCount,startNode:s,endNode:s+o.rows.length,claimed:!1,generation:this.#e};this.broadcast("datasource:data",i),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||i.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(s,`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,s=this.getNodeCount(r);for(;this.managedNodes.length<s;)this.managedNodes.push(o(this.managedNodes.length));this.managedNodes.length=s;for(let t=0;t<s;t++){const e=k(t,r,this.loadedBlocks);e&&(this.managedNodes[t]=e)}const i=this.grid;if("local"===this.sortMode&&i?._sortState){const e=i._columns??[],o=(i.effectiveConfig?.sortHandler??t)(this.managedNodes,i._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(i(e,t,o,r))}("TBW142",t,o),void this.broadcast("datasource:error",{error:new Error(t),context:e})}const r=this.getEnrichmentParams(),s=new AbortController,n=()=>s.abort(),l=()=>{this.childControllers.delete(s),t?.removeEventListener("abort",n),s.signal.removeEventListener("abort",l)};s.signal.addEventListener("abort",l,{once:!0}),t?.addEventListener("abort",n,{once:!0}),this.childControllers.add(s);const d=()=>(l(),!s.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:s.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,i=new AbortController;this.blockControllers.set(0,i),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),C(e,0,t,o,i.signal).then(e=>{if(this.releaseBlock(0,i),i.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,i),i.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(s,`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}};export{M as ServerSidePlugin,r as isLoadingPlaceholder};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|