@toolbox-web/grid 2.13.1 → 2.14.1
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 +2 -2
- package/all.js.map +1 -1
- package/custom-elements.json +18 -0
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +23 -0
- package/lib/core/internal/style-injector.d.ts +0 -8
- package/lib/features/registry.js +1 -1
- package/lib/features/registry.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +0 -28
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +0 -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/types.d.ts +0 -2
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/responsive/types.d.ts +11 -2
- package/lib/plugins/server-side/datasource-types.d.ts +8 -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/types.d.ts +9 -10
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/lib/plugins/visibility/types.d.ts +5 -10
- package/lib/plugins/visibility/visibility.d.ts +5 -3
- package/package.json +1 -1
- package/themes/dg-theme-bootstrap.css +2 -2
- package/themes/dg-theme-contrast.css +1 -1
- package/themes/dg-theme-large.css +1 -1
- package/themes/dg-theme-material.css +2 -2
- package/themes/dg-theme-standard.css +1 -1
- package/themes/dg-theme-vibrant.css +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/filtering.umd.js +1 -1
- package/umd/plugins/filtering.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/responsive.umd.js +1 -1
- package/umd/plugins/responsive.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/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -82,8 +82,17 @@ export interface ResponsivePluginConfig<T = unknown> {
|
|
|
82
82
|
*/
|
|
83
83
|
cardRenderer?: (row: T, rowIndex: number, column?: ColumnConfig) => HTMLElement;
|
|
84
84
|
/**
|
|
85
|
-
* Whether to hide the
|
|
86
|
-
*
|
|
85
|
+
* Whether to hide the per-field label rendered inside each card.
|
|
86
|
+
*
|
|
87
|
+
* In card mode each cell renders its column header as a label
|
|
88
|
+
* (e.g. `Name: Alice`) via the `data-header` attribute. Set this to
|
|
89
|
+
* `true` to suppress that label — only the value is shown.
|
|
90
|
+
*
|
|
91
|
+
* Note: this does NOT control the column header *row* at the top of
|
|
92
|
+
* the grid; that row is always hidden in card mode (a card layout
|
|
93
|
+
* has no use for a tabular header).
|
|
94
|
+
*
|
|
95
|
+
* @default false
|
|
87
96
|
*/
|
|
88
97
|
hideHeader?: boolean;
|
|
89
98
|
/**
|
|
@@ -25,6 +25,14 @@ export interface GetRowsParams extends DataRequestModel {
|
|
|
25
25
|
startNode: number;
|
|
26
26
|
/** Zero-based index of the last node to fetch (exclusive). `endNode - startNode` equals the block size. */
|
|
27
27
|
endNode: number;
|
|
28
|
+
/**
|
|
29
|
+
* Number of nodes requested in this fetch. Equal to `endNode - startNode`.
|
|
30
|
+
*
|
|
31
|
+
* Provided as a convenience for backends that expect an explicit page-size
|
|
32
|
+
* query parameter (e.g. `?start=0&pageSize=100`) rather than a start/end
|
|
33
|
+
* range. The value matches the configured `cacheBlockSize`.
|
|
34
|
+
*/
|
|
35
|
+
pageSize: number;
|
|
28
36
|
/**
|
|
29
37
|
* Cancellation signal for the request. The grid aborts the signal when:
|
|
30
38
|
* - a newer request supersedes the same block (sort/filter change, refresh, purgeCache)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}const 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))}const i={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},n="__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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`);const a=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".split("|")),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const r of o){const t=r.tagName.toLowerCase();if(a.has(t)){e.push(r);continue}if("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(t=>l.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();l.test(t)?o.push(e.name):(d.has(t)&&c.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name)}o.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}class h{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}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[i,n]of Object.entries(t)){if(void 0===n)continue;if(!(i in e)){e[i]=n,r[i]=s;continue}if(e[i]===n)continue;const t=r[i]?.constructor.name??this.constructor.name,a=s.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" 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)}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)}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{...i,...t}}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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}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);void 0!==r?"string"==typeof r?t.innerHTML=u(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(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))}}const g=/* @__PURE__ */new WeakMap;function f(t,e,o=-1){if(!e.valueAccessor)return 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 i=g.get(r);if(i){const t=i.get(s);if(void 0!==t)return t.v}else i=/* @__PURE__ */new Map,g.set(r,i);const n=e.valueAccessor({row:t,column:e,rowIndex:o});return i.set(s,{v:n}),n}function m(t,e,o){const r=o.find(t=>t.field===e.field),s=r?.sortComparator,{field:i,direction:n}=e,a=[...t];return s?r?.valueAccessor?a.sort((t,e)=>s(f(t,r),f(e,r),t,e)*n):a.sort((t,e)=>s(t[i],e[i],t,e)*n):r?.valueAccessor?function(t,e,o){t.sort((t,r)=>{const s=b(t,r);if(0!==s)return s;const i=f(t,e),n=f(r,e);return null==i&&null==n?0:null==i?-o:null==n||i>n?o:i<n?-o:0})}(a,r,n):function(t,e,o){t.sort((t,r)=>{const s=b(t,r);if(0!==s)return s;const i=t[e],n=r[e];return null==i&&null==n?0:null==i?-o:null==n||i>n?o:i<n?-o:0})}(a,i,n),a}function b(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}function p(t,e){return Math.floor(t/e)}function C(){return new DOMException("Aborted","AbortError")}function v(t,e,o,r,s){const i=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 s=()=>r(C());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 i=t.subscribe({next:t=>{s||(s=!0,o(t),i.unsubscribe())},error:t=>{s||(s=!0,r(t))},complete:()=>{s||(s=!0,r(new Error("getRows observable completed without emitting a value")))}});s||e.addEventListener("abort",()=>{s||(s=!0,i.unsubscribe(),r(C()))},{once:!0})});var o}(t.getRows({startNode:i.start,endNode:i.end,sortModel:r.sortModel,filterModel:r.filterModel,signal:s}),s)}function w(t,e,o){const r=p(t,e),s=o.get(r);if(!s)return;return s[t%e]}class S extends h{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{pageSize:100,cacheBlockSize:100,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){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&&this.setDataSource(this.config.dataSource)}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 i=this.grid;if(!t&&!s&&i?._sortState){const{field:t,direction:e}=i._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 t=this.grid,o=this.config.cacheBlockSize??100,i=this.getViewportMapping(t._virtualization.start,t._virtualization.end),n=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,i.startNode-n),l=this.totalNodeCount>0?this.totalNodeCount:1/0,d=Math.min(l,i.endNode+n);if(d<=a)return;const c=function(t,e,o){const r=p(t,o),s=p(e-1,o),i=[];for(let n=r;n<=s;n++)i.push(n);return i}(a,d,o),u=this.getEnrichmentParams(),h=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)){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}),v(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 i={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:s,endNode:s+e.rows.length,claimed:!1};this.broadcast("datasource:data",i),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1});0===r||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.cacheBlockSize??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=w(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??m)(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.cacheBlockSize??100,r=this.getEnrichmentParams(),i=this.grid?.getAttribute?.("id")??void 0,n=new AbortController;this.blockControllers.set(0,n),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),v(t,0,o,r,n.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),n.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),n.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}`,i),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}getTotalRowCount(){return this.totalNodeCount}isNodeLoaded(t){const e=p(t,this.config.cacheBlockSize??100);return this.loadedBlocks.has(e)}isRowLoaded(t){return this.isNodeLoaded(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}export{S as ServerSidePlugin};
|
|
1
|
+
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}const e="TBW140";function o(e,o,i,r){return`${t(i,r)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function i(t,e,i,r){console.debug(o(t,e,i,r))}function r(t,e,i,r){console.error(o(t,e,i,r))}const s={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},n="__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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`);const a=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".split("|")),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const i of o){const t=i.tagName.toLowerCase();if(a.has(t)){e.push(i);continue}if("svg"===t||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(i);continue}}const o=[];for(const e of i.attributes){const t=e.name.toLowerCase();l.test(t)?o.push(e.name):(d.has(t)&&c.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name)}o.forEach(t=>i.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}class h{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},i={};for(const o of Object.keys(e))i[o]=this;for(const r of t){const t=r.userConfig;for(const[s,n]of Object.entries(t)){if(void 0===n)continue;if(!(s in e)){e[s]=n,i[s]=r;continue}if(e[s]===n)continue;const t=i[s]?.constructor.name??this.constructor.name,a=r.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${s}" 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)}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)}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{...s,...t}}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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}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 i=this.#e(e,o);void 0!==i?"string"==typeof i?t.innerHTML=u(i):i instanceof HTMLElement&&(t.innerHTML="",t.appendChild(i.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 i=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return i?t.insertBefore(o,i):t.appendChild(o),o}warn(e,i){void 0!==i?console.warn(o(e,i,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))}}const g=/* @__PURE__ */new WeakMap;function f(t,e,o=-1){if(!e.valueAccessor)return t?.[e.field];if("object"!=typeof t||null===t)return e.valueAccessor({row:t,column:e,rowIndex:o});const i=t,r=e.field;let s=g.get(i);if(s){const t=s.get(r);if(void 0!==t)return t.v}else s=/* @__PURE__ */new Map,g.set(i,s);const n=e.valueAccessor({row:t,column:e,rowIndex:o});return s.set(r,{v:n}),n}function m(t,e,o){const i=o.find(t=>t.field===e.field),r=i?.sortComparator,{field:s,direction:n}=e,a=[...t];return r?i?.valueAccessor?a.sort((t,e)=>r(f(t,i),f(e,i),t,e)*n):a.sort((t,e)=>r(t[s],e[s],t,e)*n):i?.valueAccessor?function(t,e,o){t.sort((t,i)=>{const r=b(t,i);if(0!==r)return r;const s=f(t,e),n=f(i,e);return null==s&&null==n?0:null==s?-o:null==n||s>n?o:s<n?-o:0})}(a,i,n):function(t,e,o){t.sort((t,i)=>{const r=b(t,i);if(0!==r)return r;const s=t[e],n=i[e];return null==s&&null==n?0:null==s?-o:null==n||s>n?o:s<n?-o:0})}(a,s,n),a}function b(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}function p(t,e){return Math.floor(t/e)}function C(){return new DOMException("Aborted","AbortError")}function v(t,e,o,i,r){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,i)=>{const r=()=>i(C());e.addEventListener("abort",r,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",r),o(t)},t=>{e.removeEventListener("abort",r),i(t)})}):new Promise((o,i)=>{let r=!1;const s=t.subscribe({next:t=>{r||(r=!0,o(t),s.unsubscribe())},error:t=>{r||(r=!0,i(t))},complete:()=>{r||(r=!0,i(new Error("getRows observable completed without emitting a value")))}});r||e.addEventListener("abort",()=>{r||(r=!0,s.unsubscribe(),i(C()))},{once:!0})});var o}(t.getRows({startNode:s.start,endNode:s.end,pageSize:s.end-s.start,sortModel:i.sortModel,filterModel:i.filterModel,signal:r}),r)}function w(t,e,o){const i=p(t,e),r=o.get(i);if(!r)return;return r[t%e]}class S extends h{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){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&&this.setDataSource(this.config.dataSource)}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),i=e?void 0:this.grid?.query?.("filter:get-model",null);let r=o?.[0];const s=this.grid;if(!t&&!r&&s?._sortState){const{field:t,direction:e}=s._sortState;r=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:r,filterModel:i?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},i=this.grid?.query?.("datasource:viewport-mapping",o);return i?.[0]?i[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,i]of this.loadedBlocks){const r=o*t+i.length;r>e&&(e=r)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const t=this.grid,o=this.config.pageSize??this.config.cacheBlockSize??100,s=this.getViewportMapping(t._virtualization.start,t._virtualization.end),n=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,s.startNode-n),l=this.totalNodeCount>0?this.totalNodeCount:1/0,d=Math.min(l,s.endNode+n);if(d<=a)return;const c=function(t,e,o){const i=p(t,o),r=p(e-1,o),s=[];for(let n=i;n<=r;n++)s.push(n);return s}(a,d,o),u=this.getEnrichmentParams(),h=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)){i("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}),v(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 i=this.managedNodes.length;this.applyServerResult(e,g,o),this.loadingBlocks.delete(g);const r=g*o;for(let t=0;t<e.rows.length;t++)r+t<this.managedNodes.length&&(this.managedNodes[r+t]=e.rows[t]);const s={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:r,endNode:r+e.rows.length,claimed:!1};this.broadcast("datasource:data",s),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1});0===i||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 i=o instanceof Error?o:new Error(String(o));r(e,`getRows() failed: ${i.message}`,h),this.broadcast("datasource:error",{error:i}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.pageSize??this.config.cacheBlockSize??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 r=0;r<o;r++){const t=w(r,e,this.loadedBlocks);t&&(this.managedNodes[r]=t)}const i=this.grid;if("local"===this.config.sortMode&&i?._sortState){const t=i._columns??[],e=(i.effectiveConfig?.sortHandler??m)(this.managedNodes,i._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,i,r){console.warn(o(t,e,i,r))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const i=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:i.sortModel,filterModel:i.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 i=o instanceof Error?o:new Error(String(o));r("TBW141",`getChildRows() failed: ${i.message}`,e),this.broadcast("datasource:error",{error:i,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??this.config.cacheBlockSize??100,i=this.getEnrichmentParams(),s=this.grid?.getAttribute?.("id")??void 0,n=new AbortController;this.blockControllers.set(0,n),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),v(t,0,o,i,n.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),n.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),n.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const o=t instanceof Error?t:new Error(String(t));r(e,`getRows() failed: ${o.message}`,s),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}getTotalRowCount(){return this.totalNodeCount}isNodeLoaded(t){const e=p(t,this.config.pageSize??this.config.cacheBlockSize??100);return this.loadedBlocks.has(e)}isRowLoaded(t){return this.isNodeLoaded(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}export{S as ServerSidePlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|