@simple-table/react 4.1.8 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("simple-table-core"),r=require("react-dom/server"),o=require("react-dom");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=s(t);function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function u({node:n}){const r=t.useRef(null);return t.useLayoutEffect(()=>{const e=r.current;if(e)return e.appendChild(n),()=>{n.parentNode===e&&e.removeChild(n)}},[n]),e.jsx("span",{ref:r,style:{display:"contents"}})}function a(t){if(null!=t)return"string"==typeof t?t:t instanceof Node?e.jsx(u,{node:t}):void 0}function l(e){return{sortIcon:a(null==e?void 0:e.sortIcon),filterIcon:a(null==e?void 0:e.filterIcon),collapseIcon:a(null==e?void 0:e.collapseIcon),labelContent:a(null==e?void 0:e.labelContent)}}function d(t){if(null!=t){if("string"==typeof t){if(""===t)return;return e.jsx("span",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:t}})}return t instanceof Node?e.jsx(u,{node:t}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const f=Symbol.for("simple-table.wrappedRenderer");function p(e){return"function"==typeof e&&Boolean(e[f])}function h(e){return e[f]=!0,e}function m(t,n){return p(n)?n:h(r=>{const o=document.createElement("div");return t.register(e.jsx(n,Object.assign({},r)),o),o})}function g(t,n){if(p(n))return n;const r=new Map;return h(o=>{const s=Object.assign(Object.assign({},o),{components:(c=o.components,{expandIcon:a(c.expandIcon),checkbox:a(c.checkbox),dragIcon:a(c.dragIcon),labelContent:a(c.labelContent),pinIcon:a(c.pinIcon)})});var c;const i=e.jsx(n,Object.assign({},s)),u=String(o.accessor),l=r.get(u);if(l&&t.update(l,i))return l;const d=document.createElement("div");return t.register(i,d),r.set(u,d),d})}function b(t,n){return p(n)?n:h(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?a(r.searchSection):null,pivotSection:r.pivotSection?a(r.pivotSection):null,listSection:a(r.listSection),resetSection:r.resetSection?a(r.resetSection):null});return t.register(e.jsx(n,Object.assign({},s)),o),o})}function R(t){const n=document.createElement("div");return n.innerHTML=r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t})),function(e){const t=Array.from(e.childNodes).filter(e=>e.nodeType!==Node.TEXT_NODE||null!=e.textContent&&""!==e.textContent.trim());return 1===t.length&&t[0]instanceof HTMLElement?(e.removeChild(t[0]),t[0]):e}(n)}function S(t){return r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t}))}function y(e){return"function"==typeof e}function O(t,n){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=t,u=i(t,["cellRenderer","headerRenderer","children","nestedTable"]),a=String(t.accessor),d=Object.assign({},u);if(r&&(d.cellRenderer=function(t,n,r){if(p(r))return r;const o=t.cellRendererCache.get(n);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null},c=h(n=>{const r=s.component,o=document.createElement("div");return o.style.display="contents",t.register(e.jsx(r,Object.assign({},n)),o),o});return s.wrapped=c,t.cellRendererCache.set(n,s),c}(n,a,r)),o&&(d.headerRenderer=function(t,n,r){if(p(r))return r;const o=t.headerRendererCache.get(n);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null};let c=null;const i=h(n=>{const r=s.component,o=Object.assign(Object.assign({},n),{components:l(n.components)}),i=e.jsx(r,Object.assign({},o));return c&&t.update(c,i)||(c=document.createElement("div"),t.register(i,c)),c});return s.wrapped=i,t.headerRendererCache.set(n,s),i}(n,a,o)),s&&(d.children=s.map(e=>O(e,n))),c){const e=Object.assign(Object.assign({},c),{rows:[]});d.nestedTable=v(e,n)}return d}function j(e){const t=e.columns;if(!t)throw new Error("SimpleTable requires `columns`");return t}function v(t,r){const{rows:o,footerRenderer:s,emptyStateRenderer:c,errorStateRenderer:u,loadingStateRenderer:a,tableEmptyStateRenderer:f,headerDropdown:v,columnEditorConfig:E,icons:C,rowButtons:w,onColumnOrderChange:x,onColumnWidthChange:I,onHeaderEdit:T,onColumnSelect:P,enableColumnEditor:A,enableColumnEditorInitOpen:B,enablePagination:L,onTableReady:_,hoverRowBackground:k,oddColumnBackground:M,oddEvenRowBackground:D}=t,H=i(t,["columns","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect","enableColumnEditor","enableColumnEditorInitOpen","enablePagination","onTableReady","hoverRowBackground","oddColumnBackground","oddEvenRowBackground"]),q=j(t);r.pruneRendererCaches(n.collectHeaderAccessors(q));const N=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},H),{rows:o,columns:q.map(e=>O(e,r)),enableColumnEditor:A,enableColumnEditorInitOpen:B,enablePagination:L,onTableReady:_,hoverRowBackground:k,oddColumnBackground:M,oddEvenRowBackground:D,onRendererHostDiscard:r.disposeHost}),x?{onColumnOrderChange:e=>x(e)}:{}),I?{onColumnWidthChange:e=>I(e)}:{}),T?{onHeaderEdit:(e,t)=>T(e,t)}:{}),P?{onColumnSelect:e=>P(e)}:{});if(void 0!==s&&(N.footerRenderer=function(t,n){return p(n)?n:h(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{nextIcon:d((c={nextIcon:r.nextIcon,prevIcon:r.prevIcon}).nextIcon),prevIcon:d(c.prevIcon)});var c;return t.register(e.jsx(n,Object.assign({},s)),o),o})}(r,s)),void 0!==c)if(y(c))N.emptyStateRenderer=m(r,c);else{const e=c;N.emptyStateRenderer=()=>R(e)}if(void 0!==u)if(y(u))N.errorStateRenderer=m(r,u);else{const e=u;N.errorStateRenderer=()=>R(e)}if(void 0!==a)if(y(a))N.loadingStateRenderer=m(r,a);else{const e=a;N.loadingStateRenderer=()=>R(e)}return void 0!==f&&(N.tableEmptyStateRenderer=null===f?null:R(f)),void 0!==v&&(N.headerDropdown=function(t,n){return p(n)?n:h(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:l(r.components)});return t.register(e.jsx(n,Object.assign({},s)),o),o})}(r,v)),void 0!==E&&(N.columnEditorConfig=function(e,t){const{rowRenderer:n,customRenderer:r}=e,o=i(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),n?{rowRenderer:g(t,n)}:{}),r?{customRenderer:b(t,r)}:{})}(E,r)),void 0!==C&&(N.icons=function(e){const t={};for(const[n,r]of Object.entries(e))null!=r&&(t[n]="string"==typeof r||r instanceof HTMLElement||r instanceof SVGElement?r:S(r));return t}(C)),void 0!==w&&(N.rowButtons=w.map(t=>function(t,n){return p(n)?n:h(r=>{const o=document.createElement("div");return o.style.display="contents",t.register(e.jsx(n,Object.assign({},r)),o),o})}(r,t))),N}const E="data-st-portal-id";class C{constructor(){this.entries=new Map,this.listeners=new Set,this.nextId=0,this.cachedSnapshot=[],this.snapshotDirty=!0,this.emitScheduled=!1,this.cellRendererCache=new Map,this.headerRendererCache=new Map,this.disposeHost=e=>{if("function"!=typeof e.getAttribute)return;const t=[],n=e.getAttribute(E);null!==n&&t.push(n),e.querySelectorAll(`[${E}]`).forEach(e=>{const n=e.getAttribute(E);null!==n&&t.push(n)});for(const e of t)this.unregister(e)},this.subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}),this.getSnapshot=()=>(this.snapshotDirty&&(this.cachedSnapshot=Array.from(this.entries.values()),this.snapshotDirty=!1),this.cachedSnapshot)}register(e,t){const n="st-portal-"+this.nextId++;return t.setAttribute(E,n),this.entries.set(n,{id:n,container:t,node:e}),this.scheduleEmit(),{id:n,unregister:()=>this.unregister(n)}}update(e,t){const n=e.getAttribute(E);if(null===n)return!1;const r=this.entries.get(n);return!(!r||r.container!==e||(r.node=t,this.scheduleEmit(),0))}unregister(e){this.entries.delete(e)&&this.scheduleEmit()}clear(){this.cellRendererCache.clear(),this.headerRendererCache.clear(),0!==this.entries.size&&(this.entries.clear(),this.emit())}pruneRendererCaches(e){for(const t of this.cellRendererCache.keys())e.has(t)||this.cellRendererCache.delete(t);for(const t of this.headerRendererCache.keys())e.has(t)||this.headerRendererCache.delete(t)}emit(){this.snapshotDirty=!0;for(const e of this.listeners)e()}scheduleEmit(){this.emitScheduled||(this.emitScheduled=!0,queueMicrotask(()=>{this.emitScheduled=!1,this.emit()}))}}class w extends c.default.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[simple-table] A custom renderer threw while rendering:",e)}render(){return this.state.hasError?null:this.props.children}}const x=c.default.forwardRef(function(r,s){const c=t.useRef(null),i=t.useRef(null);null===i.current&&(i.current=new C);const u=i.current,a=t.useRef(null),l=t.useRef(void 0),d=t.useRef(void 0),f=t.useRef(null),p=r;t.useLayoutEffect(()=>{const e=c.current;if(!e)return;const t=new n.SimpleTableVanilla(e,v(p,u));if(t.mount(),a.current=t,f.current=p,l.current=j(p),d.current=p.rows,s){const e=t.getAPI();"function"==typeof s?s(e):s.current=e}return()=>{t.destroy(),a.current=null,l.current=void 0,d.current=void 0,f.current=null,u.clear(),s&&"function"!=typeof s&&(s.current=null)}},[]),t.useLayoutEffect(()=>{const e=a.current;if(!e)return;if(null!==f.current&&!function(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!0;return!1}(f.current,p))return;f.current=p;const t=v(p,u),r=Object.assign({},t),o=j(p),s=n.headersStructurallyEqual(l.current,o);l.current=o,s&&delete r.columns;const c=n.rowsShallowUnchanged(d.current,p.rows,p.getRowId);d.current=p.rows,c&&delete r.rows,e.update(r)},[p]);const h=function(n){return t.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot).map(t=>o.createPortal(e.jsx(w,{children:t.node}),t.container,t.id))}(u),m=Array.isArray(h)&&h.length>0,g=t.useRef(!1),b=t.useRef(Boolean(p.isLoading));return t.useLayoutEffect(()=>{var e,t;const n=a.current;if(!n)return;const r=Boolean(p.isLoading),o=b.current&&!r;b.current=r,o?null===(e=n.refitAutoSizeColumns)||void 0===e||e.call(n):!g.current&&m&&(g.current=!0,null===(t=n.refitAutoSizeColumns)||void 0===t||t.call(n))},[m,p.isLoading]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:c}),h]})});x.displayName="SimpleTable",Object.defineProperty(exports,"PIVOT_ACCESSOR_PREFIX",{enumerable:!0,get:function(){return n.PIVOT_ACCESSOR_PREFIX}}),Object.defineProperty(exports,"PIVOT_BLANK_LABEL",{enumerable:!0,get:function(){return n.PIVOT_BLANK_LABEL}}),Object.defineProperty(exports,"PIVOT_IS_TOTAL_KEY",{enumerable:!0,get:function(){return n.PIVOT_IS_TOTAL_KEY}}),Object.defineProperty(exports,"asRows",{enumerable:!0,get:function(){return n.asRows}}),Object.defineProperty(exports,"buildPivotAccessor",{enumerable:!0,get:function(){return n.buildPivotAccessor}}),Object.defineProperty(exports,"buildPivotRowTotalAccessor",{enumerable:!0,get:function(){return n.buildPivotRowTotalAccessor}}),Object.defineProperty(exports,"pivotRows",{enumerable:!0,get:function(){return n.pivotRows}}),exports.SimpleTable=x;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("simple-table-core"),r=require("react-dom/server"),o=require("react-dom");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=s(t);function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function u({node:n}){const r=t.useRef(null);return t.useLayoutEffect(()=>{const e=r.current;if(e)return e.appendChild(n),()=>{n.parentNode===e&&e.removeChild(n)}},[n]),e.jsx("span",{ref:r,style:{display:"contents"}})}function a(t){if(null!=t)return"string"==typeof t?t:t instanceof Node?e.jsx(u,{node:t}):void 0}function l(e){return{sortIcon:a(null==e?void 0:e.sortIcon),filterIcon:a(null==e?void 0:e.filterIcon),collapseIcon:a(null==e?void 0:e.collapseIcon),labelContent:a(null==e?void 0:e.labelContent)}}function d(t){if(null!=t){if("string"==typeof t){if(""===t)return;return e.jsx("span",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:t}})}return t instanceof Node?e.jsx(u,{node:t}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const p=Symbol.for("simple-table.wrappedRenderer"),f=Symbol.for("simple-table.rendererGeneration");function h(e){return"function"==typeof e&&Boolean(e[p])}function m(e){return e[p]=!0,e}function g(t,n){return h(n)?n:m(r=>{const o=document.createElement("div");return t.register(e.jsx(n,Object.assign({},r)),o),o})}function b(t,n){if(h(n))return n;const r=new Map;return m(o=>{const s=Object.assign(Object.assign({},o),{components:(c=o.components,{expandIcon:a(c.expandIcon),checkbox:a(c.checkbox),dragIcon:a(c.dragIcon),labelContent:a(c.labelContent),pinIcon:a(c.pinIcon)})});var c;const i=e.jsx(n,Object.assign({},s)),u=String(o.accessor),l=r.get(u);if(l&&t.update(l,i))return l;const d=document.createElement("div");return t.register(i,d),r.set(u,d),d})}function R(t,n){return h(n)?n:m(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?a(r.searchSection):null,pivotSection:r.pivotSection?a(r.pivotSection):null,listSection:a(r.listSection),resetSection:r.resetSection?a(r.resetSection):null});return t.register(e.jsx(n,Object.assign({},s)),o),o})}function y(t){const n=document.createElement("div");return n.innerHTML=r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t})),function(e){const t=Array.from(e.childNodes).filter(e=>e.nodeType!==Node.TEXT_NODE||null!=e.textContent&&""!==e.textContent.trim());return 1===t.length&&t[0]instanceof HTMLElement?(e.removeChild(t[0]),t[0]):e}(n)}function S(t){return r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t}))}function O(e){return"function"==typeof e}function j(t,n){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=t,u=i(t,["cellRenderer","headerRenderer","children","nestedTable"]),a=String(t.accessor),d=Object.assign({},u);if(r&&(d.cellRenderer=function(t,n,r){if(h(r))return r;const o=t.cellRendererCache.get(n);if(o){if(o.component!==r){o.component=r;const e=o.wrapped[f];o.wrapped[f]=("number"==typeof e?e:0)+1}return o.wrapped}const s={component:r,wrapped:null},c=m(n=>{const r=s.component,o=document.createElement("div");return o.style.display="contents",t.register(e.jsx(r,Object.assign({},n)),o),o});return s.wrapped=c,c[f]=0,t.cellRendererCache.set(n,s),c}(n,a,r)),o&&(d.headerRenderer=function(t,n,r){if(h(r))return r;const o=t.headerRendererCache.get(n);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null};let c=null;const i=m(n=>{const r=s.component,o=Object.assign(Object.assign({},n),{components:l(n.components)}),i=e.jsx(r,Object.assign({},o));return c&&t.update(c,i)||(c=document.createElement("div"),t.register(i,c)),c});return s.wrapped=i,t.headerRendererCache.set(n,s),i}(n,a,o)),s&&(d.children=s.map(e=>j(e,n))),c){const e=Object.assign(Object.assign({},c),{rows:[]});d.nestedTable=E(e,n)}return d}function v(e){const t=e.columns;if(!t)throw new Error("SimpleTable requires `columns`");return t}function E(t,r){const{rows:o,footerRenderer:s,emptyStateRenderer:c,errorStateRenderer:u,loadingStateRenderer:a,tableEmptyStateRenderer:p,headerDropdown:f,columnEditorConfig:E,icons:C,rowButtons:w,onColumnOrderChange:x,onColumnWidthChange:I,onHeaderEdit:T,onColumnSelect:P,enableColumnEditor:A,enableColumnEditorInitOpen:B,enablePagination:L,onTableReady:_,hoverRowBackground:k,oddColumnBackground:M,oddEvenRowBackground:D}=t,H=i(t,["columns","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect","enableColumnEditor","enableColumnEditorInitOpen","enablePagination","onTableReady","hoverRowBackground","oddColumnBackground","oddEvenRowBackground"]),q=v(t);r.pruneRendererCaches(n.collectHeaderAccessors(q));const N=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},H),{rows:o,columns:q.map(e=>j(e,r)),enableColumnEditor:A,enableColumnEditorInitOpen:B,enablePagination:L,onTableReady:_,hoverRowBackground:k,oddColumnBackground:M,oddEvenRowBackground:D,onRendererHostDiscard:r.disposeHost}),x?{onColumnOrderChange:e=>x(e)}:{}),I?{onColumnWidthChange:e=>I(e)}:{}),T?{onHeaderEdit:(e,t)=>T(e,t)}:{}),P?{onColumnSelect:e=>P(e)}:{});if(void 0!==s&&(N.footerRenderer=function(t,n){return h(n)?n:m(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{nextIcon:d((c={nextIcon:r.nextIcon,prevIcon:r.prevIcon}).nextIcon),prevIcon:d(c.prevIcon)});var c;return t.register(e.jsx(n,Object.assign({},s)),o),o})}(r,s)),void 0!==c)if(O(c))N.emptyStateRenderer=g(r,c);else{const e=c;N.emptyStateRenderer=()=>y(e)}if(void 0!==u)if(O(u))N.errorStateRenderer=g(r,u);else{const e=u;N.errorStateRenderer=()=>y(e)}if(void 0!==a)if(O(a))N.loadingStateRenderer=g(r,a);else{const e=a;N.loadingStateRenderer=()=>y(e)}return void 0!==p&&(N.tableEmptyStateRenderer=null===p?null:y(p)),void 0!==f&&(N.headerDropdown=function(t,n){return h(n)?n:m(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:l(r.components)});return t.register(e.jsx(n,Object.assign({},s)),o),o})}(r,f)),void 0!==E&&(N.columnEditorConfig=function(e,t){const{rowRenderer:n,customRenderer:r}=e,o=i(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),n?{rowRenderer:b(t,n)}:{}),r?{customRenderer:R(t,r)}:{})}(E,r)),void 0!==C&&(N.icons=function(e){const t={};for(const[n,r]of Object.entries(e))null!=r&&(t[n]="string"==typeof r||r instanceof HTMLElement||r instanceof SVGElement?r:S(r));return t}(C)),void 0!==w&&(N.rowButtons=w.map(t=>function(t,n){return h(n)?n:m(r=>{const o=document.createElement("div");return o.style.display="contents",t.register(e.jsx(n,Object.assign({},r)),o),o})}(r,t))),N}const C="data-st-portal-id";class w{constructor(){this.entries=new Map,this.listeners=new Set,this.nextId=0,this.cachedSnapshot=[],this.snapshotDirty=!0,this.emitScheduled=!1,this.cellRendererCache=new Map,this.headerRendererCache=new Map,this.disposeHost=e=>{if("function"!=typeof e.getAttribute)return;const t=[],n=e.getAttribute(C);null!==n&&t.push(n),e.querySelectorAll(`[${C}]`).forEach(e=>{const n=e.getAttribute(C);null!==n&&t.push(n)});for(const e of t)this.unregister(e)},this.subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}),this.getSnapshot=()=>(this.snapshotDirty&&(this.cachedSnapshot=Array.from(this.entries.values()),this.snapshotDirty=!1),this.cachedSnapshot)}register(e,t){const n="st-portal-"+this.nextId++;return t.setAttribute(C,n),this.entries.set(n,{id:n,container:t,node:e}),this.scheduleEmit(),{id:n,unregister:()=>this.unregister(n)}}update(e,t){const n=e.getAttribute(C);if(null===n)return!1;const r=this.entries.get(n);return!(!r||r.container!==e||(r.node=t,this.scheduleEmit(),0))}unregister(e){this.entries.delete(e)&&this.scheduleEmit()}clear(){this.cellRendererCache.clear(),this.headerRendererCache.clear(),0!==this.entries.size&&(this.entries.clear(),this.emit())}pruneRendererCaches(e){for(const t of this.cellRendererCache.keys())e.has(t)||this.cellRendererCache.delete(t);for(const t of this.headerRendererCache.keys())e.has(t)||this.headerRendererCache.delete(t)}emit(){this.snapshotDirty=!0;for(const e of this.listeners)e()}scheduleEmit(){this.emitScheduled||(this.emitScheduled=!0,queueMicrotask(()=>{this.emitScheduled=!1,this.emit()}))}}class x extends c.default.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[simple-table] A custom renderer threw while rendering:",e)}render(){return this.state.hasError?null:this.props.children}}const I=c.default.forwardRef(function(r,s){const c=t.useRef(null),i=t.useRef(null);null===i.current&&(i.current=new w);const u=i.current,a=t.useRef(null),l=t.useRef(void 0),d=t.useRef(void 0),p=t.useRef(null),f=r;t.useLayoutEffect(()=>{const e=c.current;if(!e)return;const t=new n.SimpleTableVanilla(e,E(f,u));if(t.mount(),a.current=t,p.current=f,l.current=v(f),d.current=f.rows,s){const e=t.getAPI();"function"==typeof s?s(e):s.current=e}return()=>{t.destroy(),a.current=null,l.current=void 0,d.current=void 0,p.current=null,u.clear(),s&&"function"!=typeof s&&(s.current=null)}},[]),t.useLayoutEffect(()=>{const e=a.current;if(!e)return;if(null!==p.current&&!function(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n)if(e[r]!==t[r])return!0;return!1}(p.current,f))return;p.current=f;const t=E(f,u),r=Object.assign({},t),o=v(f),s=n.headersStructurallyEqual(l.current,o);l.current=o,s&&delete r.columns;const c=n.rowsShallowUnchanged(d.current,f.rows,f.getRowId);d.current=f.rows,c&&delete r.rows,e.update(r)},[f]);const h=function(n){return t.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot).map(t=>o.createPortal(e.jsx(x,{children:t.node}),t.container,t.id))}(u),m=Array.isArray(h)&&h.length>0,g=t.useRef(!1),b=t.useRef(Boolean(f.isLoading));return t.useLayoutEffect(()=>{var e,t;const n=a.current;if(!n)return;const r=Boolean(f.isLoading),o=b.current&&!r;b.current=r,o?null===(e=n.refitAutoSizeColumns)||void 0===e||e.call(n):!g.current&&m&&(g.current=!0,null===(t=n.refitAutoSizeColumns)||void 0===t||t.call(n))},[m,f.isLoading]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:c}),h]})});I.displayName="SimpleTable",Object.defineProperty(exports,"PIVOT_ACCESSOR_PREFIX",{enumerable:!0,get:function(){return n.PIVOT_ACCESSOR_PREFIX}}),Object.defineProperty(exports,"PIVOT_BLANK_LABEL",{enumerable:!0,get:function(){return n.PIVOT_BLANK_LABEL}}),Object.defineProperty(exports,"PIVOT_IS_TOTAL_KEY",{enumerable:!0,get:function(){return n.PIVOT_IS_TOTAL_KEY}}),Object.defineProperty(exports,"asRows",{enumerable:!0,get:function(){return n.asRows}}),Object.defineProperty(exports,"buildPivotAccessor",{enumerable:!0,get:function(){return n.buildPivotAccessor}}),Object.defineProperty(exports,"buildPivotRowTotalAccessor",{enumerable:!0,get:function(){return n.buildPivotRowTotalAccessor}}),Object.defineProperty(exports,"pivotRows",{enumerable:!0,get:function(){return n.pivotRows}}),exports.SimpleTable=I;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import{jsx as e,Fragment as n,jsxs as t}from"react/jsx-runtime";import r,{useRef as o,useLayoutEffect as s,useSyncExternalStore as c}from"react";import{collectHeaderAccessors as i,SimpleTableVanilla as l,headersStructurallyEqual as a,rowsShallowUnchanged as d}from"simple-table-core";export{PIVOT_ACCESSOR_PREFIX,PIVOT_BLANK_LABEL,PIVOT_IS_TOTAL_KEY,asRows,buildPivotAccessor,buildPivotRowTotalAccessor,pivotRows}from"simple-table-core";import{renderToStaticMarkup as u}from"react-dom/server";import{createPortal as h}from"react-dom";function p(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}function m({node:n}){const t=o(null);return s(()=>{const e=t.current;if(e)return e.appendChild(n),()=>{n.parentNode===e&&e.removeChild(n)}},[n]),e("span",{ref:t,style:{display:"contents"}})}function f(n){if(null!=n)return"string"==typeof n?n:n instanceof Node?e(m,{node:n}):void 0}function g(e){return{sortIcon:f(null==e?void 0:e.sortIcon),filterIcon:f(null==e?void 0:e.filterIcon),collapseIcon:f(null==e?void 0:e.collapseIcon),labelContent:f(null==e?void 0:e.labelContent)}}function b(n){if(null!=n){if("string"==typeof n){if(""===n)return;return e("span",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:n}})}return n instanceof Node?e(m,{node:n}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const R=Symbol.for("simple-table.wrappedRenderer");function S(e){return"function"==typeof e&&Boolean(e[R])}function v(e){return e[R]=!0,e}function C(n,t){return S(t)?t:v(r=>{const o=document.createElement("div");return n.register(e(t,Object.assign({},r)),o),o})}function O(n,t){if(S(t))return t;const r=new Map;return v(o=>{const s=Object.assign(Object.assign({},o),{components:(c=o.components,{expandIcon:f(c.expandIcon),checkbox:f(c.checkbox),dragIcon:f(c.dragIcon),labelContent:f(c.labelContent),pinIcon:f(c.pinIcon)})});var c;const i=e(t,Object.assign({},s)),l=String(o.accessor),a=r.get(l);if(a&&n.update(a,i))return a;const d=document.createElement("div");return n.register(i,d),r.set(l,d),d})}function y(n,t){return S(t)?t:v(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?f(r.searchSection):null,pivotSection:r.pivotSection?f(r.pivotSection):null,listSection:f(r.listSection),resetSection:r.resetSection?f(r.resetSection):null});return n.register(e(t,Object.assign({},s)),o),o})}function w(t){const r=document.createElement("div");return r.innerHTML=u(e(n,{children:t})),function(e){const n=Array.from(e.childNodes).filter(e=>e.nodeType!==Node.TEXT_NODE||null!=e.textContent&&""!==e.textContent.trim());return 1===n.length&&n[0]instanceof HTMLElement?(e.removeChild(n[0]),n[0]):e}(r)}function E(t){return u(e(n,{children:t}))}function j(e){return"function"==typeof e}function I(n,t){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=n,i=p(n,["cellRenderer","headerRenderer","children","nestedTable"]),l=String(n.accessor),a=Object.assign({},i);if(r&&(a.cellRenderer=function(n,t,r){if(S(r))return r;const o=n.cellRendererCache.get(t);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null},c=v(t=>{const r=s.component,o=document.createElement("div");return o.style.display="contents",n.register(e(r,Object.assign({},t)),o),o});return s.wrapped=c,n.cellRendererCache.set(t,s),c}(t,l,r)),o&&(a.headerRenderer=function(n,t,r){if(S(r))return r;const o=n.headerRendererCache.get(t);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null};let c=null;const i=v(t=>{const r=s.component,o=Object.assign(Object.assign({},t),{components:g(t.components)}),i=e(r,Object.assign({},o));return c&&n.update(c,i)||(c=document.createElement("div"),n.register(i,c)),c});return s.wrapped=i,n.headerRendererCache.set(t,s),i}(t,l,o)),s&&(a.children=s.map(e=>I(e,t))),c){const e=Object.assign(Object.assign({},c),{rows:[]});a.nestedTable=A(e,t)}return a}function T(e){const n=e.columns;if(!n)throw new Error("SimpleTable requires `columns`");return n}function A(n,t){const{rows:r,footerRenderer:o,emptyStateRenderer:s,errorStateRenderer:c,loadingStateRenderer:l,tableEmptyStateRenderer:a,headerDropdown:d,columnEditorConfig:u,icons:h,rowButtons:m,onColumnOrderChange:f,onColumnWidthChange:R,onHeaderEdit:A,onColumnSelect:x,enableColumnEditor:B,enableColumnEditorInitOpen:k,enablePagination:P,onTableReady:D,hoverRowBackground:L,oddColumnBackground:H,oddEvenRowBackground:_}=n,M=p(n,["columns","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect","enableColumnEditor","enableColumnEditorInitOpen","enablePagination","onTableReady","hoverRowBackground","oddColumnBackground","oddEvenRowBackground"]),N=T(n);t.pruneRendererCaches(i(N));const V=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},M),{rows:r,columns:N.map(e=>I(e,t)),enableColumnEditor:B,enableColumnEditorInitOpen:k,enablePagination:P,onTableReady:D,hoverRowBackground:L,oddColumnBackground:H,oddEvenRowBackground:_,onRendererHostDiscard:t.disposeHost}),f?{onColumnOrderChange:e=>f(e)}:{}),R?{onColumnWidthChange:e=>R(e)}:{}),A?{onHeaderEdit:(e,n)=>A(e,n)}:{}),x?{onColumnSelect:e=>x(e)}:{});if(void 0!==o&&(V.footerRenderer=function(n,t){return S(t)?t:v(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{nextIcon:b((c={nextIcon:r.nextIcon,prevIcon:r.prevIcon}).nextIcon),prevIcon:b(c.prevIcon)});var c;return n.register(e(t,Object.assign({},s)),o),o})}(t,o)),void 0!==s)if(j(s))V.emptyStateRenderer=C(t,s);else{const e=s;V.emptyStateRenderer=()=>w(e)}if(void 0!==c)if(j(c))V.errorStateRenderer=C(t,c);else{const e=c;V.errorStateRenderer=()=>w(e)}if(void 0!==l)if(j(l))V.loadingStateRenderer=C(t,l);else{const e=l;V.loadingStateRenderer=()=>w(e)}return void 0!==a&&(V.tableEmptyStateRenderer=null===a?null:w(a)),void 0!==d&&(V.headerDropdown=function(n,t){return S(t)?t:v(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:g(r.components)});return n.register(e(t,Object.assign({},s)),o),o})}(t,d)),void 0!==u&&(V.columnEditorConfig=function(e,n){const{rowRenderer:t,customRenderer:r}=e,o=p(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),t?{rowRenderer:O(n,t)}:{}),r?{customRenderer:y(n,r)}:{})}(u,t)),void 0!==h&&(V.icons=function(e){const n={};for(const[t,r]of Object.entries(e))null!=r&&(n[t]="string"==typeof r||r instanceof HTMLElement||r instanceof SVGElement?r:E(r));return n}(h)),void 0!==m&&(V.rowButtons=m.map(n=>function(n,t){return S(t)?t:v(r=>{const o=document.createElement("div");return o.style.display="contents",n.register(e(t,Object.assign({},r)),o),o})}(t,n))),V}const x="data-st-portal-id";class B{constructor(){this.entries=new Map,this.listeners=new Set,this.nextId=0,this.cachedSnapshot=[],this.snapshotDirty=!0,this.emitScheduled=!1,this.cellRendererCache=new Map,this.headerRendererCache=new Map,this.disposeHost=e=>{if("function"!=typeof e.getAttribute)return;const n=[],t=e.getAttribute(x);null!==t&&n.push(t),e.querySelectorAll(`[${x}]`).forEach(e=>{const t=e.getAttribute(x);null!==t&&n.push(t)});for(const e of n)this.unregister(e)},this.subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}),this.getSnapshot=()=>(this.snapshotDirty&&(this.cachedSnapshot=Array.from(this.entries.values()),this.snapshotDirty=!1),this.cachedSnapshot)}register(e,n){const t="st-portal-"+this.nextId++;return n.setAttribute(x,t),this.entries.set(t,{id:t,container:n,node:e}),this.scheduleEmit(),{id:t,unregister:()=>this.unregister(t)}}update(e,n){const t=e.getAttribute(x);if(null===t)return!1;const r=this.entries.get(t);return!(!r||r.container!==e||(r.node=n,this.scheduleEmit(),0))}unregister(e){this.entries.delete(e)&&this.scheduleEmit()}clear(){this.cellRendererCache.clear(),this.headerRendererCache.clear(),0!==this.entries.size&&(this.entries.clear(),this.emit())}pruneRendererCaches(e){for(const n of this.cellRendererCache.keys())e.has(n)||this.cellRendererCache.delete(n);for(const n of this.headerRendererCache.keys())e.has(n)||this.headerRendererCache.delete(n)}emit(){this.snapshotDirty=!0;for(const e of this.listeners)e()}scheduleEmit(){this.emitScheduled||(this.emitScheduled=!0,queueMicrotask(()=>{this.emitScheduled=!1,this.emit()}))}}class k extends r.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[simple-table] A custom renderer threw while rendering:",e)}render(){return this.state.hasError?null:this.props.children}}const P=r.forwardRef(function(r,i){const u=o(null),p=o(null);null===p.current&&(p.current=new B);const m=p.current,f=o(null),g=o(void 0),b=o(void 0),R=o(null),S=r;s(()=>{const e=u.current;if(!e)return;const n=new l(e,A(S,m));if(n.mount(),f.current=n,R.current=S,g.current=T(S),b.current=S.rows,i){const e=n.getAPI();"function"==typeof i?i(e):i.current=e}return()=>{n.destroy(),f.current=null,g.current=void 0,b.current=void 0,R.current=null,m.clear(),i&&"function"!=typeof i&&(i.current=null)}},[]),s(()=>{const e=f.current;if(!e)return;if(null!==R.current&&!function(e,n){const t=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of t)if(e[r]!==n[r])return!0;return!1}(R.current,S))return;R.current=S;const n=A(S,m),t=Object.assign({},n),r=T(S),o=a(g.current,r);g.current=r,o&&delete t.columns;const s=d(b.current,S.rows,S.getRowId);b.current=S.rows,s&&delete t.rows,e.update(t)},[S]);const v=function(n){return c(n.subscribe,n.getSnapshot,n.getSnapshot).map(n=>h(e(k,{children:n.node}),n.container,n.id))}(m),C=Array.isArray(v)&&v.length>0,O=o(!1),y=o(Boolean(S.isLoading));return s(()=>{var e,n;const t=f.current;if(!t)return;const r=Boolean(S.isLoading),o=y.current&&!r;y.current=r,o?null===(e=t.refitAutoSizeColumns)||void 0===e||e.call(t):!O.current&&C&&(O.current=!0,null===(n=t.refitAutoSizeColumns)||void 0===n||n.call(t))},[C,S.isLoading]),t(n,{children:[e("div",{ref:u}),v]})});P.displayName="SimpleTable";export{P as SimpleTable};
1
+ import{jsx as e,Fragment as n,jsxs as t}from"react/jsx-runtime";import r,{useRef as o,useLayoutEffect as s,useSyncExternalStore as c}from"react";import{collectHeaderAccessors as i,SimpleTableVanilla as l,headersStructurallyEqual as a,rowsShallowUnchanged as d}from"simple-table-core";export{PIVOT_ACCESSOR_PREFIX,PIVOT_BLANK_LABEL,PIVOT_IS_TOTAL_KEY,asRows,buildPivotAccessor,buildPivotRowTotalAccessor,pivotRows}from"simple-table-core";import{renderToStaticMarkup as u}from"react-dom/server";import{createPortal as p}from"react-dom";function h(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}function m({node:n}){const t=o(null);return s(()=>{const e=t.current;if(e)return e.appendChild(n),()=>{n.parentNode===e&&e.removeChild(n)}},[n]),e("span",{ref:t,style:{display:"contents"}})}function f(n){if(null!=n)return"string"==typeof n?n:n instanceof Node?e(m,{node:n}):void 0}function g(e){return{sortIcon:f(null==e?void 0:e.sortIcon),filterIcon:f(null==e?void 0:e.filterIcon),collapseIcon:f(null==e?void 0:e.collapseIcon),labelContent:f(null==e?void 0:e.labelContent)}}function b(n){if(null!=n){if("string"==typeof n){if(""===n)return;return e("span",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:n}})}return n instanceof Node?e(m,{node:n}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const R=Symbol.for("simple-table.wrappedRenderer"),S=Symbol.for("simple-table.rendererGeneration");function v(e){return"function"==typeof e&&Boolean(e[R])}function y(e){return e[R]=!0,e}function C(n,t){return v(t)?t:y(r=>{const o=document.createElement("div");return n.register(e(t,Object.assign({},r)),o),o})}function O(n,t){if(v(t))return t;const r=new Map;return y(o=>{const s=Object.assign(Object.assign({},o),{components:(c=o.components,{expandIcon:f(c.expandIcon),checkbox:f(c.checkbox),dragIcon:f(c.dragIcon),labelContent:f(c.labelContent),pinIcon:f(c.pinIcon)})});var c;const i=e(t,Object.assign({},s)),l=String(o.accessor),a=r.get(l);if(a&&n.update(a,i))return a;const d=document.createElement("div");return n.register(i,d),r.set(l,d),d})}function w(n,t){return v(t)?t:y(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?f(r.searchSection):null,pivotSection:r.pivotSection?f(r.pivotSection):null,listSection:f(r.listSection),resetSection:r.resetSection?f(r.resetSection):null});return n.register(e(t,Object.assign({},s)),o),o})}function E(t){const r=document.createElement("div");return r.innerHTML=u(e(n,{children:t})),function(e){const n=Array.from(e.childNodes).filter(e=>e.nodeType!==Node.TEXT_NODE||null!=e.textContent&&""!==e.textContent.trim());return 1===n.length&&n[0]instanceof HTMLElement?(e.removeChild(n[0]),n[0]):e}(r)}function j(t){return u(e(n,{children:t}))}function I(e){return"function"==typeof e}function T(n,t){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=n,i=h(n,["cellRenderer","headerRenderer","children","nestedTable"]),l=String(n.accessor),a=Object.assign({},i);if(r&&(a.cellRenderer=function(n,t,r){if(v(r))return r;const o=n.cellRendererCache.get(t);if(o){if(o.component!==r){o.component=r;const e=o.wrapped[S];o.wrapped[S]=("number"==typeof e?e:0)+1}return o.wrapped}const s={component:r,wrapped:null},c=y(t=>{const r=s.component,o=document.createElement("div");return o.style.display="contents",n.register(e(r,Object.assign({},t)),o),o});return s.wrapped=c,c[S]=0,n.cellRendererCache.set(t,s),c}(t,l,r)),o&&(a.headerRenderer=function(n,t,r){if(v(r))return r;const o=n.headerRendererCache.get(t);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null};let c=null;const i=y(t=>{const r=s.component,o=Object.assign(Object.assign({},t),{components:g(t.components)}),i=e(r,Object.assign({},o));return c&&n.update(c,i)||(c=document.createElement("div"),n.register(i,c)),c});return s.wrapped=i,n.headerRendererCache.set(t,s),i}(t,l,o)),s&&(a.children=s.map(e=>T(e,t))),c){const e=Object.assign(Object.assign({},c),{rows:[]});a.nestedTable=x(e,t)}return a}function A(e){const n=e.columns;if(!n)throw new Error("SimpleTable requires `columns`");return n}function x(n,t){const{rows:r,footerRenderer:o,emptyStateRenderer:s,errorStateRenderer:c,loadingStateRenderer:l,tableEmptyStateRenderer:a,headerDropdown:d,columnEditorConfig:u,icons:p,rowButtons:m,onColumnOrderChange:f,onColumnWidthChange:R,onHeaderEdit:S,onColumnSelect:x,enableColumnEditor:B,enableColumnEditorInitOpen:k,enablePagination:P,onTableReady:D,hoverRowBackground:L,oddColumnBackground:H,oddEvenRowBackground:_}=n,M=h(n,["columns","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect","enableColumnEditor","enableColumnEditorInitOpen","enablePagination","onTableReady","hoverRowBackground","oddColumnBackground","oddEvenRowBackground"]),N=A(n);t.pruneRendererCaches(i(N));const V=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},M),{rows:r,columns:N.map(e=>T(e,t)),enableColumnEditor:B,enableColumnEditorInitOpen:k,enablePagination:P,onTableReady:D,hoverRowBackground:L,oddColumnBackground:H,oddEvenRowBackground:_,onRendererHostDiscard:t.disposeHost}),f?{onColumnOrderChange:e=>f(e)}:{}),R?{onColumnWidthChange:e=>R(e)}:{}),S?{onHeaderEdit:(e,n)=>S(e,n)}:{}),x?{onColumnSelect:e=>x(e)}:{});if(void 0!==o&&(V.footerRenderer=function(n,t){return v(t)?t:y(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{nextIcon:b((c={nextIcon:r.nextIcon,prevIcon:r.prevIcon}).nextIcon),prevIcon:b(c.prevIcon)});var c;return n.register(e(t,Object.assign({},s)),o),o})}(t,o)),void 0!==s)if(I(s))V.emptyStateRenderer=C(t,s);else{const e=s;V.emptyStateRenderer=()=>E(e)}if(void 0!==c)if(I(c))V.errorStateRenderer=C(t,c);else{const e=c;V.errorStateRenderer=()=>E(e)}if(void 0!==l)if(I(l))V.loadingStateRenderer=C(t,l);else{const e=l;V.loadingStateRenderer=()=>E(e)}return void 0!==a&&(V.tableEmptyStateRenderer=null===a?null:E(a)),void 0!==d&&(V.headerDropdown=function(n,t){return v(t)?t:y(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:g(r.components)});return n.register(e(t,Object.assign({},s)),o),o})}(t,d)),void 0!==u&&(V.columnEditorConfig=function(e,n){const{rowRenderer:t,customRenderer:r}=e,o=h(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),t?{rowRenderer:O(n,t)}:{}),r?{customRenderer:w(n,r)}:{})}(u,t)),void 0!==p&&(V.icons=function(e){const n={};for(const[t,r]of Object.entries(e))null!=r&&(n[t]="string"==typeof r||r instanceof HTMLElement||r instanceof SVGElement?r:j(r));return n}(p)),void 0!==m&&(V.rowButtons=m.map(n=>function(n,t){return v(t)?t:y(r=>{const o=document.createElement("div");return o.style.display="contents",n.register(e(t,Object.assign({},r)),o),o})}(t,n))),V}const B="data-st-portal-id";class k{constructor(){this.entries=new Map,this.listeners=new Set,this.nextId=0,this.cachedSnapshot=[],this.snapshotDirty=!0,this.emitScheduled=!1,this.cellRendererCache=new Map,this.headerRendererCache=new Map,this.disposeHost=e=>{if("function"!=typeof e.getAttribute)return;const n=[],t=e.getAttribute(B);null!==t&&n.push(t),e.querySelectorAll(`[${B}]`).forEach(e=>{const t=e.getAttribute(B);null!==t&&n.push(t)});for(const e of n)this.unregister(e)},this.subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}),this.getSnapshot=()=>(this.snapshotDirty&&(this.cachedSnapshot=Array.from(this.entries.values()),this.snapshotDirty=!1),this.cachedSnapshot)}register(e,n){const t="st-portal-"+this.nextId++;return n.setAttribute(B,t),this.entries.set(t,{id:t,container:n,node:e}),this.scheduleEmit(),{id:t,unregister:()=>this.unregister(t)}}update(e,n){const t=e.getAttribute(B);if(null===t)return!1;const r=this.entries.get(t);return!(!r||r.container!==e||(r.node=n,this.scheduleEmit(),0))}unregister(e){this.entries.delete(e)&&this.scheduleEmit()}clear(){this.cellRendererCache.clear(),this.headerRendererCache.clear(),0!==this.entries.size&&(this.entries.clear(),this.emit())}pruneRendererCaches(e){for(const n of this.cellRendererCache.keys())e.has(n)||this.cellRendererCache.delete(n);for(const n of this.headerRendererCache.keys())e.has(n)||this.headerRendererCache.delete(n)}emit(){this.snapshotDirty=!0;for(const e of this.listeners)e()}scheduleEmit(){this.emitScheduled||(this.emitScheduled=!0,queueMicrotask(()=>{this.emitScheduled=!1,this.emit()}))}}class P extends r.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[simple-table] A custom renderer threw while rendering:",e)}render(){return this.state.hasError?null:this.props.children}}const D=r.forwardRef(function(r,i){const u=o(null),h=o(null);null===h.current&&(h.current=new k);const m=h.current,f=o(null),g=o(void 0),b=o(void 0),R=o(null),S=r;s(()=>{const e=u.current;if(!e)return;const n=new l(e,x(S,m));if(n.mount(),f.current=n,R.current=S,g.current=A(S),b.current=S.rows,i){const e=n.getAPI();"function"==typeof i?i(e):i.current=e}return()=>{n.destroy(),f.current=null,g.current=void 0,b.current=void 0,R.current=null,m.clear(),i&&"function"!=typeof i&&(i.current=null)}},[]),s(()=>{const e=f.current;if(!e)return;if(null!==R.current&&!function(e,n){const t=new Set([...Object.keys(e),...Object.keys(n)]);for(const r of t)if(e[r]!==n[r])return!0;return!1}(R.current,S))return;R.current=S;const n=x(S,m),t=Object.assign({},n),r=A(S),o=a(g.current,r);g.current=r,o&&delete t.columns;const s=d(b.current,S.rows,S.getRowId);b.current=S.rows,s&&delete t.rows,e.update(t)},[S]);const v=function(n){return c(n.subscribe,n.getSnapshot,n.getSnapshot).map(n=>p(e(P,{children:n.node}),n.container,n.id))}(m),y=Array.isArray(v)&&v.length>0,C=o(!1),O=o(Boolean(S.isLoading));return s(()=>{var e,n;const t=f.current;if(!t)return;const r=Boolean(S.isLoading),o=O.current&&!r;O.current=r,o?null===(e=t.refitAutoSizeColumns)||void 0===e||e.call(t):!C.current&&y&&(C.current=!0,null===(n=t.refitAutoSizeColumns)||void 0===n||n.call(t))},[y,S.isLoading]),t(n,{children:[e("div",{ref:u}),v]})});D.displayName="SimpleTable";export{D as SimpleTable};
2
2
  //# sourceMappingURL=index.es.js.map
@@ -9,6 +9,8 @@ import type { PortalBridge } from "../PortalBridge";
9
9
  * wrapper), which can freeze the page after autofit / width sync.
10
10
  */
11
11
  export declare const ST_WRAPPED_RENDERER: unique symbol;
12
+ /** Bumped on a cached cellRenderer wrapper when the React component identity changes. */
13
+ export declare const ST_RENDERER_GENERATION: unique symbol;
12
14
  /** True when `fn` was produced by one of the wrap helpers in this module. */
13
15
  export declare function isWrappedRenderer(fn: unknown): boolean;
14
16
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simple-table/react",
3
- "version": "4.1.8",
3
+ "version": "4.2.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "react-dom": ">=18.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "simple-table-core": "4.1.8"
36
+ "simple-table-core": "4.2.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@rollup/plugin-alias": "^4.0.4",