@simple-table/react 3.9.6 → 3.9.8
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 +1 -1
- package/dist/index.es.js +1 -1
- package/dist/types/core/src/core/SimpleTableVanilla.d.ts +8 -0
- package/dist/types/core/src/core/api/TableAPIImpl.d.ts +13 -0
- package/dist/types/core/src/hooks/handleOutsideClick.d.ts +1 -1
- package/dist/types/core/src/index.d.ts +2 -0
- package/dist/types/core/src/managers/AnimationCoordinator.d.ts +2 -0
- package/dist/types/core/src/managers/SelectionManager/types.d.ts +6 -1
- package/dist/types/core/src/types/SimpleTableConfig.d.ts +1 -0
- package/dist/types/core/src/types/SimpleTableProps.d.ts +1 -0
- package/dist/types/core/src/utils/headerCell/types.d.ts +1 -1
- package/dist/types/core/src/utils/propSyncEqual.d.ts +65 -0
- package/dist/types/core/src/utils/rowUtils.d.ts +7 -0
- package/dist/types/react/src/PortalBridge.d.ts +18 -0
- package/dist/types/react/src/utils/headersEqual.d.ts +6 -0
- package/dist/types/react/src/utils/rowsEqual.d.ts +6 -0
- package/dist/types/react/src/utils/wrapReactRenderer.d.ts +12 -0
- package/package.json +2 -2
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 i=s(t);function c(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){return p(n)?n:h(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:(i=r.components,{expandIcon:a(i.expandIcon),checkbox:a(i.checkbox),dragIcon:a(i.dragIcon),labelContent:a(i.labelContent),pinIcon:a(i.pinIcon)})});var i;return t.register(e.jsx(n,Object.assign({},s)),o),o})}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,listSection:a(r.listSection),resetSection:r.resetSection?a(r.resetSection):null});return t.register(e.jsx(n,Object.assign({},s)),o),o})}function j(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 y(t){return r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t}))}function S(e){return"function"==typeof e}function v(t,n){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:i}=t,u=c(t,["cellRenderer","headerRenderer","children","nestedTable"]),a=Object.assign({},u);if(r&&(a.cellRenderer=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})}(n,r)),o&&(a.headerRenderer=function(t,n){if(p(n))return n;let r=null;return h(o=>{const s=Object.assign(Object.assign({},o),{components:l(o.components)}),i=e.jsx(n,Object.assign({},s));return r&&t.update(r,i)||(r=document.createElement("div"),t.register(i,r)),r})}(n,o)),s&&(a.children=s.map(e=>v(e,n))),i){const e=Object.assign(Object.assign({},i),{rows:[]});a.nestedTable=O(e,n)}return a}function O(t,n){const{defaultHeaders:r,rows:o,footerRenderer:s,emptyStateRenderer:i,errorStateRenderer:u,loadingStateRenderer:a,tableEmptyStateRenderer:f,headerDropdown:O,columnEditorConfig:R,icons:E,rowButtons:x,onColumnOrderChange:C,onColumnWidthChange:w,onHeaderEdit:I,onColumnSelect:H}=t,T=c(t,["defaultHeaders","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect"]),A=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},T),{rows:o,defaultHeaders:r.map(e=>v(e,n)),onRendererHostDiscard:n.disposeHost}),C?{onColumnOrderChange:e=>C(e)}:{}),w?{onColumnWidthChange:e=>w(e)}:{}),I?{onHeaderEdit:(e,t)=>I(e,t)}:{}),H?{onColumnSelect:e=>H(e)}:{});if(void 0!==s&&(A.footerRenderer=function(t,n){return p(n)?n:h(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{nextIcon:d((i={nextIcon:r.nextIcon,prevIcon:r.prevIcon}).nextIcon),prevIcon:d(i.prevIcon)});var i;return t.register(e.jsx(n,Object.assign({},s)),o),o})}(n,s)),void 0!==i)if(S(i))A.emptyStateRenderer=m(n,i);else{const e=i;A.emptyStateRenderer=()=>j(e)}if(void 0!==u)if(S(u))A.errorStateRenderer=m(n,u);else{const e=u;A.errorStateRenderer=()=>j(e)}if(void 0!==a)if(S(a))A.loadingStateRenderer=m(n,a);else{const e=a;A.loadingStateRenderer=()=>j(e)}return void 0!==f&&(A.tableEmptyStateRenderer=null===f?null:j(f)),void 0!==O&&(A.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})}(n,O)),void 0!==R&&(A.columnEditorConfig=function(e,t){const{rowRenderer:n,customRenderer:r}=e,o=c(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),n?{rowRenderer:g(t,n)}:{}),r?{customRenderer:b(t,r)}:{})}(R,n)),void 0!==E&&(A.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:y(r));return t}(E)),void 0!==x&&(A.rowButtons=x.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})}(n,t))),A}const R="data-st-portal-id";class E{constructor(){this.entries=new Map,this.listeners=new Set,this.nextId=0,this.cachedSnapshot=[],this.snapshotDirty=!0,this.emitScheduled=!1,this.disposeHost=e=>{if("function"!=typeof e.getAttribute)return;const t=[],n=e.getAttribute(R);null!==n&&t.push(n),e.querySelectorAll(`[${R}]`).forEach(e=>{const n=e.getAttribute(R);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(R,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(R);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(){0!==this.entries.size&&(this.entries.clear(),this.emit())}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 i.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 C=i.default.forwardRef(function(r,s){const i=t.useRef(null),u=t.useRef(null);null===u.current&&(u.current=new E);const a=u.current,l=t.useRef(null),d=t.useRef(void 0),f=t.useRef(null),p=r;t.useLayoutEffect(()=>{const e=i.current;if(!e)return;const t=new n.SimpleTableVanilla(e,O(p,a));if(t.mount(),l.current=t,f.current=p,d.current=p.defaultHeaders,s){const e=t.getAPI();"function"==typeof s?s(e):s.current=e}return()=>{t.destroy(),l.current=null,d.current=void 0,f.current=null,a.clear(),s&&"function"!=typeof s&&(s.current=null)}},[]),t.useLayoutEffect(()=>{const e=l.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=O(p,a);if(d.current!==p.defaultHeaders)return d.current=p.defaultHeaders,void e.update(t);const n=c(t,["defaultHeaders"]);e.update(n)},[p]);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))}(a),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=l.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:i}),h]})});C.displayName="SimpleTable",Object.defineProperty(exports,"asRows",{enumerable:!0,get:function(){return n.asRows}}),exports.SimpleTable=C;
|
|
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 a({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 u(t){if(null!=t)return"string"==typeof t?t:t instanceof Node?e.jsx(a,{node:t}):void 0}function l(e){return{sortIcon:u(null==e?void 0:e.sortIcon),filterIcon:u(null==e?void 0:e.filterIcon),collapseIcon:u(null==e?void 0:e.collapseIcon),labelContent:u(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(a,{node:t}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const f=Symbol.for("simple-table.wrappedRenderer");function h(e){return"function"==typeof e&&Boolean(e[f])}function p(e){return e[f]=!0,e}function m(t,n){return h(n)?n:p(r=>{const o=document.createElement("div");return t.register(e.jsx(n,Object.assign({},r)),o),o})}function g(t,n){return h(n)?n:p(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:(c=r.components,{expandIcon:u(c.expandIcon),checkbox:u(c.checkbox),dragIcon:u(c.dragIcon),labelContent:u(c.labelContent),pinIcon:u(c.pinIcon)})});var c;return t.register(e.jsx(n,Object.assign({},s)),o),o})}function b(t,n){return h(n)?n:p(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?u(r.searchSection):null,listSection:u(r.listSection),resetSection:r.resetSection?u(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 j(t){return r.renderToStaticMarkup(e.jsx(e.Fragment,{children:t}))}function R(e){return"function"==typeof e}function S(t,n){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=t,a=i(t,["cellRenderer","headerRenderer","children","nestedTable"]),u=String(t.accessor),d=Object.assign({},a);if(r&&(d.cellRenderer=function(t,n,r){if(h(r))return r;const o=t.cellRendererCache.get(n);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null},c=p(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,u,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=p(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,u,o)),s&&(d.children=s.map(e=>S(e,n))),c){const e=Object.assign(Object.assign({},c),{rows:[]});d.nestedTable=v(e,n)}return d}function v(t,r){const{defaultHeaders:o,rows:s,footerRenderer:c,emptyStateRenderer:a,errorStateRenderer:u,loadingStateRenderer:f,tableEmptyStateRenderer:v,headerDropdown:O,columnEditorConfig:C,icons:w,rowButtons:E,onColumnOrderChange:x,onColumnWidthChange:I,onHeaderEdit:H,onColumnSelect:A}=t,T=i(t,["defaultHeaders","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect"]);r.pruneRendererCaches(n.collectHeaderAccessors(o));const D=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},T),{rows:s,defaultHeaders:o.map(e=>S(e,r)),onRendererHostDiscard:r.disposeHost}),x?{onColumnOrderChange:e=>x(e)}:{}),I?{onColumnWidthChange:e=>I(e)}:{}),H?{onHeaderEdit:(e,t)=>H(e,t)}:{}),A?{onColumnSelect:e=>A(e)}:{});if(void 0!==c&&(D.footerRenderer=function(t,n){return h(n)?n:p(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,c)),void 0!==a)if(R(a))D.emptyStateRenderer=m(r,a);else{const e=a;D.emptyStateRenderer=()=>y(e)}if(void 0!==u)if(R(u))D.errorStateRenderer=m(r,u);else{const e=u;D.errorStateRenderer=()=>y(e)}if(void 0!==f)if(R(f))D.loadingStateRenderer=m(r,f);else{const e=f;D.loadingStateRenderer=()=>y(e)}return void 0!==v&&(D.tableEmptyStateRenderer=null===v?null:y(v)),void 0!==O&&(D.headerDropdown=function(t,n){return h(n)?n:p(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,O)),void 0!==C&&(D.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)}:{})}(C,r)),void 0!==w&&(D.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:j(r));return t}(w)),void 0!==E&&(D.rowButtons=E.map(t=>function(t,n){return h(n)?n:p(r=>{const o=document.createElement("div");return o.style.display="contents",t.register(e.jsx(n,Object.assign({},r)),o),o})}(r,t))),D}const O="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(O);null!==n&&t.push(n),e.querySelectorAll(`[${O}]`).forEach(e=>{const n=e.getAttribute(O);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(O,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(O);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 E=c.default.forwardRef(function(r,s){const c=t.useRef(null),i=t.useRef(null);null===i.current&&(i.current=new C);const a=i.current,u=t.useRef(null),l=t.useRef(void 0),d=t.useRef(void 0),f=t.useRef(null),h=r;t.useLayoutEffect(()=>{const e=c.current;if(!e)return;const t=new n.SimpleTableVanilla(e,v(h,a));if(t.mount(),u.current=t,f.current=h,l.current=h.defaultHeaders,d.current=h.rows,s){const e=t.getAPI();"function"==typeof s?s(e):s.current=e}return()=>{t.destroy(),u.current=null,l.current=void 0,d.current=void 0,f.current=null,a.clear(),s&&"function"!=typeof s&&(s.current=null)}},[]),t.useLayoutEffect(()=>{const e=u.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,h))return;f.current=h;const t=v(h,a),r=Object.assign({},t),o=n.headersStructurallyEqual(l.current,h.defaultHeaders);l.current=h.defaultHeaders,o&&delete r.defaultHeaders;const s=n.rowsShallowUnchanged(d.current,h.rows,h.getRowId);d.current=h.rows,s&&delete r.rows,e.update(r)},[h]);const p=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))}(a),m=Array.isArray(p)&&p.length>0,g=t.useRef(!1),b=t.useRef(Boolean(h.isLoading));return t.useLayoutEffect(()=>{var e,t;const n=u.current;if(!n)return;const r=Boolean(h.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,h.isLoading]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:c}),p]})});E.displayName="SimpleTable",Object.defineProperty(exports,"asRows",{enumerable:!0,get:function(){return n.asRows}}),exports.SimpleTable=E;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,Fragment as t,jsxs as n}from"react/jsx-runtime";import r,{useRef as o,useLayoutEffect as s,useSyncExternalStore as
|
|
1
|
+
import{jsx as e,Fragment as t,jsxs as n}from"react/jsx-runtime";import r,{useRef as o,useLayoutEffect as s,useSyncExternalStore as c}from"react";import{collectHeaderAccessors as i,SimpleTableVanilla as a,headersStructurallyEqual as d,rowsShallowUnchanged as l}from"simple-table-core";export{asRows}from"simple-table-core";import{renderToStaticMarkup as u}from"react-dom/server";import{createPortal as h}from"react-dom";function p(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 f({node:t}){const n=o(null);return s(()=>{const e=n.current;if(e)return e.appendChild(t),()=>{t.parentNode===e&&e.removeChild(t)}},[t]),e("span",{ref:n,style:{display:"contents"}})}function m(t){if(null!=t)return"string"==typeof t?t:t instanceof Node?e(f,{node:t}):void 0}function g(e){return{sortIcon:m(null==e?void 0:e.sortIcon),filterIcon:m(null==e?void 0:e.filterIcon),collapseIcon:m(null==e?void 0:e.collapseIcon),labelContent:m(null==e?void 0:e.labelContent)}}function b(t){if(null!=t){if("string"==typeof t){if(""===t)return;return e("span",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:t}})}return t instanceof Node?e(f,{node:t}):void 0}}"function"==typeof SuppressedError&&SuppressedError;const y=Symbol.for("simple-table.wrappedRenderer");function S(e){return"function"==typeof e&&Boolean(e[y])}function R(e){return e[y]=!0,e}function O(t,n){return S(n)?n:R(r=>{const o=document.createElement("div");return t.register(e(n,Object.assign({},r)),o),o})}function v(t,n){return S(n)?n:R(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:(c=r.components,{expandIcon:m(c.expandIcon),checkbox:m(c.checkbox),dragIcon:m(c.dragIcon),labelContent:m(c.labelContent),pinIcon:m(c.pinIcon)})});var c;return t.register(e(n,Object.assign({},s)),o),o})}function C(t,n){return S(n)?n:R(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{searchSection:r.searchSection?m(r.searchSection):null,listSection:m(r.listSection),resetSection:r.resetSection?m(r.resetSection):null});return t.register(e(n,Object.assign({},s)),o),o})}function j(n){const r=document.createElement("div");return r.innerHTML=u(e(t,{children:n})),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}(r)}function w(n){return u(e(t,{children:n}))}function E(e){return"function"==typeof e}function I(t,n){const{cellRenderer:r,headerRenderer:o,children:s,nestedTable:c}=t,i=p(t,["cellRenderer","headerRenderer","children","nestedTable"]),a=String(t.accessor),d=Object.assign({},i);if(r&&(d.cellRenderer=function(t,n,r){if(S(r))return r;const o=t.cellRendererCache.get(n);if(o)return o.component=r,o.wrapped;const s={component:r,wrapped:null},c=R(n=>{const r=s.component,o=document.createElement("div");return o.style.display="contents",t.register(e(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(S(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=R(n=>{const r=s.component,o=Object.assign(Object.assign({},n),{components:g(n.components)}),i=e(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=>I(e,n))),c){const e=Object.assign(Object.assign({},c),{rows:[]});d.nestedTable=x(e,n)}return d}function x(t,n){const{defaultHeaders:r,rows:o,footerRenderer:s,emptyStateRenderer:c,errorStateRenderer:a,loadingStateRenderer:d,tableEmptyStateRenderer:l,headerDropdown:u,columnEditorConfig:h,icons:f,rowButtons:m,onColumnOrderChange:y,onColumnWidthChange:x,onHeaderEdit:H,onColumnSelect:A}=t,D=p(t,["defaultHeaders","rows","footerRenderer","emptyStateRenderer","errorStateRenderer","loadingStateRenderer","tableEmptyStateRenderer","headerDropdown","columnEditorConfig","icons","rowButtons","onColumnOrderChange","onColumnWidthChange","onHeaderEdit","onColumnSelect"]);n.pruneRendererCaches(i(r));const T=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},D),{rows:o,defaultHeaders:r.map(e=>I(e,n)),onRendererHostDiscard:n.disposeHost}),y?{onColumnOrderChange:e=>y(e)}:{}),x?{onColumnWidthChange:e=>x(e)}:{}),H?{onHeaderEdit:(e,t)=>H(e,t)}:{}),A?{onColumnSelect:e=>A(e)}:{});if(void 0!==s&&(T.footerRenderer=function(t,n){return S(n)?n:R(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 t.register(e(n,Object.assign({},s)),o),o})}(n,s)),void 0!==c)if(E(c))T.emptyStateRenderer=O(n,c);else{const e=c;T.emptyStateRenderer=()=>j(e)}if(void 0!==a)if(E(a))T.errorStateRenderer=O(n,a);else{const e=a;T.errorStateRenderer=()=>j(e)}if(void 0!==d)if(E(d))T.loadingStateRenderer=O(n,d);else{const e=d;T.loadingStateRenderer=()=>j(e)}return void 0!==l&&(T.tableEmptyStateRenderer=null===l?null:j(l)),void 0!==u&&(T.headerDropdown=function(t,n){return S(n)?n:R(r=>{const o=document.createElement("div"),s=Object.assign(Object.assign({},r),{components:g(r.components)});return t.register(e(n,Object.assign({},s)),o),o})}(n,u)),void 0!==h&&(T.columnEditorConfig=function(e,t){const{rowRenderer:n,customRenderer:r}=e,o=p(e,["rowRenderer","customRenderer"]);return Object.assign(Object.assign(Object.assign({},o),n?{rowRenderer:v(t,n)}:{}),r?{customRenderer:C(t,r)}:{})}(h,n)),void 0!==f&&(T.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:w(r));return t}(f)),void 0!==m&&(T.rowButtons=m.map(t=>function(t,n){return S(n)?n:R(r=>{const o=document.createElement("div");return o.style.display="contents",t.register(e(n,Object.assign({},r)),o),o})}(n,t))),T}const H="data-st-portal-id";class A{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(H);null!==n&&t.push(n),e.querySelectorAll(`[${H}]`).forEach(e=>{const n=e.getAttribute(H);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(H,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(H);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 D 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 T=r.forwardRef(function(r,i){const u=o(null),p=o(null);null===p.current&&(p.current=new A);const f=p.current,m=o(null),g=o(void 0),b=o(void 0),y=o(null),S=r;s(()=>{const e=u.current;if(!e)return;const t=new a(e,x(S,f));if(t.mount(),m.current=t,y.current=S,g.current=S.defaultHeaders,b.current=S.rows,i){const e=t.getAPI();"function"==typeof i?i(e):i.current=e}return()=>{t.destroy(),m.current=null,g.current=void 0,b.current=void 0,y.current=null,f.clear(),i&&"function"!=typeof i&&(i.current=null)}},[]),s(()=>{const e=m.current;if(!e)return;if(null!==y.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}(y.current,S))return;y.current=S;const t=x(S,f),n=Object.assign({},t),r=d(g.current,S.defaultHeaders);g.current=S.defaultHeaders,r&&delete n.defaultHeaders;const o=l(b.current,S.rows,S.getRowId);b.current=S.rows,o&&delete n.rows,e.update(n)},[S]);const R=function(t){return c(t.subscribe,t.getSnapshot,t.getSnapshot).map(t=>h(e(D,{children:t.node}),t.container,t.id))}(f),O=Array.isArray(R)&&R.length>0,v=o(!1),C=o(Boolean(S.isLoading));return s(()=>{var e,t;const n=m.current;if(!n)return;const r=Boolean(S.isLoading),o=C.current&&!r;C.current=r,o?null===(e=n.refitAutoSizeColumns)||void 0===e||e.call(n):!v.current&&O&&(v.current=!0,null===(t=n.refitAutoSizeColumns)||void 0===t||t.call(n))},[O,S.isLoading]),n(t,{children:[e("div",{ref:u}),R]})});T.displayName="SimpleTable";export{T as SimpleTable};
|
|
2
2
|
//# sourceMappingURL=index.es.js.map
|
|
@@ -69,6 +69,14 @@ export declare class SimpleTableVanilla {
|
|
|
69
69
|
private headerRegistry;
|
|
70
70
|
private rowIndexMap;
|
|
71
71
|
private animationCoordinator;
|
|
72
|
+
/**
|
|
73
|
+
* When true, the sort subscriber skips `captureAnimationSnapshot` so
|
|
74
|
+
* live-update-driven reorder/visibility changes don't FLIP-animate.
|
|
75
|
+
* User-initiated sorts leave this false and keep FLIP.
|
|
76
|
+
*/
|
|
77
|
+
private suppressNextAnimationSnapshot;
|
|
78
|
+
/** Lazily created once — callers often invoke getAPI() every live tick. */
|
|
79
|
+
private cachedAPI;
|
|
72
80
|
private autoScaleManager;
|
|
73
81
|
private dimensionManager;
|
|
74
82
|
private scrollManager;
|
|
@@ -41,6 +41,8 @@ export interface TableAPIContext {
|
|
|
41
41
|
* re-render once the animation settles.
|
|
42
42
|
*/
|
|
43
43
|
isCellAnimating?: (cellId: string) => boolean;
|
|
44
|
+
/** True while any FLIP cell transition is in flight (blocks live re-sort/re-filter). */
|
|
45
|
+
hasAnimatingCells?: () => boolean;
|
|
44
46
|
columnEditorOpen: boolean;
|
|
45
47
|
expandedDepthsManager: any;
|
|
46
48
|
selectionManager: SelectionManager | null;
|
|
@@ -50,6 +52,17 @@ export interface TableAPIContext {
|
|
|
50
52
|
getCachedFlattenResult?: () => FlattenRowsResult | null;
|
|
51
53
|
getCachedProcessedResult?: () => ProcessRowsResult | null;
|
|
52
54
|
onRender: () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Bust the flatten / body row caches so the next render re-runs quick filter
|
|
57
|
+
* (and related processing) against in-place mutated row values.
|
|
58
|
+
*/
|
|
59
|
+
invalidateRowsCache?: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Run `fn` without capturing a FLIP snapshot when sort/filter subscribers
|
|
62
|
+
* fire. Used for live-update-driven reorder/visibility changes so high-
|
|
63
|
+
* frequency ticks don't spam sort animations.
|
|
64
|
+
*/
|
|
65
|
+
runWithoutAnimationSnapshot?: (fn: () => void) => void;
|
|
53
66
|
setHeaders: (headers: HeaderObject[]) => void;
|
|
54
67
|
setCurrentPage: (page: number) => void;
|
|
55
68
|
setColumnEditorOpen: (open: boolean) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import HeaderObject from "../types/HeaderObject";
|
|
2
2
|
import Cell from "../types/Cell";
|
|
3
3
|
export interface HandleOutsideClickConfig {
|
|
4
|
-
|
|
4
|
+
selectableColumns: boolean;
|
|
5
5
|
selectedCells: Set<string>;
|
|
6
6
|
selectedColumns: Set<number>;
|
|
7
7
|
setSelectedCells: (cells: Set<string>) => void;
|
|
@@ -49,4 +49,6 @@ import type { RowId } from "./types/RowId";
|
|
|
49
49
|
import type { PinnedSectionsState } from "./types/PinnedSectionsState";
|
|
50
50
|
export { SimpleTableVanilla };
|
|
51
51
|
export { asRows } from "./utils/asRows";
|
|
52
|
+
export { headersStructurallyEqual, collectHeaderAccessors, rowsShallowUnchanged, shallowEqualRow, SHALLOW_ROW_COMPARE_MAX, } from "./utils/propSyncEqual";
|
|
53
|
+
export type { HeaderStructureLike, GetRowIdLike } from "./utils/propSyncEqual";
|
|
52
54
|
export type { Accessor, AggregationConfig, AggregationType, AnimationsConfig, BoundingBox, Cell, CellChangeProps, CellClickProps, CellRenderer, CellRendererProps, CellValue, ChartOptions, ColumnEditorConfig, ColumnEditorCustomRenderer, ColumnEditorCustomRendererProps, ColumnEditorRowRenderer, ColumnEditorRowRendererComponents, ColumnEditorRowRendererProps, ColumnEditorSearchFunction, ColumnType, ColumnVisibilityState, Comparator, ComparatorProps, CustomTheme, CustomThemeProps, DragHandlerProps, EmptyStateRenderer, EmptyStateRendererProps, EnumOption, ErrorStateRenderer, ErrorStateRendererProps, ExportToCSVProps, ExportValueGetter, ExportValueProps, FilterCondition, FilterOperator, StringFilterOperator, NumberFilterOperator, BooleanFilterOperator, DateFilterOperator, EnumFilterOperator, FooterRendererProps, FooterPosition, GetRowId, GetRowIdParams, IconsConfig, LoadingStateRenderer, LoadingStateRendererProps, HeaderDropdown, HeaderDropdownProps, HeaderObject, HeaderRenderer, HeaderRendererProps, HeaderRendererComponents, OnRowGroupExpandProps, OnSortProps, QuickFilterConfig, QuickFilterGetter, QuickFilterGetterProps, QuickFilterMode, Row, RowButtonProps, RowId, RowSelectionChangeProps, RowSelectionMode, RowState, SetHeaderRenameProps, SharedTableProps, ShowWhen, SimpleTableConfig, SimpleTableProps, SortColumn, TableAPI, TableFilterState, TableHeaderProps, TableRowProps, Theme, PinnedSectionsState, UpdateDataProps, ValueFormatter, ValueFormatterProps, ValueGetter, ValueGetterProps, };
|
|
@@ -117,6 +117,8 @@ export declare class AnimationCoordinator {
|
|
|
117
117
|
setEasing(easing: string): void;
|
|
118
118
|
isEnabled(): boolean;
|
|
119
119
|
isInFlight(cellId: string): boolean;
|
|
120
|
+
/** True while any FLIP / retained-cell transition is still running. */
|
|
121
|
+
hasInFlight(): boolean;
|
|
120
122
|
getDuration(): number;
|
|
121
123
|
getEasing(): string;
|
|
122
124
|
/**
|
|
@@ -5,8 +5,13 @@ import type Cell from "../../types/Cell";
|
|
|
5
5
|
import type { CustomTheme } from "../../types/CustomTheme";
|
|
6
6
|
export declare const createSetString: ({ rowIndex, colIndex, rowId }: Cell) => string;
|
|
7
7
|
export interface SelectionManagerConfig {
|
|
8
|
-
/** When true, enables cell selection and column header selection. */
|
|
9
8
|
selectableCells: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* When true, column header click selects columns (`st-header-selected` on headers).
|
|
11
|
+
* Cell-in-column header tint (`st-header-has-highlighted-cell`) also applies when `selectableCells` is true
|
|
12
|
+
* even if this is false.
|
|
13
|
+
*/
|
|
14
|
+
selectableColumns?: boolean;
|
|
10
15
|
headers: HeaderObject[];
|
|
11
16
|
tableRows: TableRowType[];
|
|
12
17
|
onCellEdit?: (props: any) => void;
|
|
@@ -105,6 +105,7 @@ export interface SimpleTableConfig {
|
|
|
105
105
|
rowsPerPage?: number;
|
|
106
106
|
scrollParent?: HTMLElement | "window" | (() => HTMLElement | null);
|
|
107
107
|
selectableCells?: boolean;
|
|
108
|
+
selectableColumns?: boolean;
|
|
108
109
|
serverSidePagination?: boolean;
|
|
109
110
|
shouldPaginate?: boolean;
|
|
110
111
|
tableEmptyStateRenderer?: HTMLElement | string | null;
|
|
@@ -98,6 +98,7 @@ export interface SimpleTableProps {
|
|
|
98
98
|
rowsPerPage?: number;
|
|
99
99
|
scrollParent?: HTMLElement | "window" | (() => HTMLElement | null);
|
|
100
100
|
selectableCells?: boolean;
|
|
101
|
+
selectableColumns?: boolean;
|
|
101
102
|
serverSidePagination?: boolean;
|
|
102
103
|
shouldPaginate?: boolean;
|
|
103
104
|
tableEmptyStateRenderer?: HTMLElement | string | null;
|
|
@@ -74,7 +74,7 @@ export interface HeaderRenderContext {
|
|
|
74
74
|
reverse: boolean;
|
|
75
75
|
rows: Row[];
|
|
76
76
|
selectColumns?: (columnIndices: number[]) => void;
|
|
77
|
-
|
|
77
|
+
selectableColumns?: boolean;
|
|
78
78
|
selectedColumns: Set<number>;
|
|
79
79
|
selectedRowCount?: number; /** Used for context cache invalidation when row selection changes */
|
|
80
80
|
setCollapsedHeaders: Dispatch<SetStateAction<Set<Accessor>>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared prop-sync helpers for framework adapters.
|
|
3
|
+
* Used to skip no-op `defaultHeaders` / `rows` updates when consumers rebuild
|
|
4
|
+
* column configs or shallow-clone rows every render.
|
|
5
|
+
*/
|
|
6
|
+
/** Minimal header shape for structural comparison (renderers ignored). */
|
|
7
|
+
export type HeaderStructureLike = {
|
|
8
|
+
accessor: string | number | symbol;
|
|
9
|
+
width?: number | string;
|
|
10
|
+
minWidth?: number | string;
|
|
11
|
+
maxWidth?: number | string;
|
|
12
|
+
label?: string;
|
|
13
|
+
type?: string;
|
|
14
|
+
pinned?: string | boolean | null;
|
|
15
|
+
hide?: boolean;
|
|
16
|
+
isSortable?: boolean;
|
|
17
|
+
filterable?: boolean;
|
|
18
|
+
align?: string;
|
|
19
|
+
collapsible?: boolean;
|
|
20
|
+
collapseDefault?: boolean;
|
|
21
|
+
showWhen?: string;
|
|
22
|
+
isEditable?: boolean;
|
|
23
|
+
isEssential?: boolean;
|
|
24
|
+
disableReorder?: boolean;
|
|
25
|
+
expandable?: boolean;
|
|
26
|
+
excludeFromRender?: boolean;
|
|
27
|
+
autoSizeMode?: string;
|
|
28
|
+
tooltip?: string;
|
|
29
|
+
quickFilterable?: boolean;
|
|
30
|
+
filterOperators?: ReadonlyArray<string>;
|
|
31
|
+
children?: ReadonlyArray<HeaderStructureLike>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* True when two header trees describe the same columns (accessors, widths,
|
|
35
|
+
* flags, nesting). Ignores renderer identity.
|
|
36
|
+
*/
|
|
37
|
+
export declare function headersStructurallyEqual(a: ReadonlyArray<HeaderStructureLike> | undefined, b: ReadonlyArray<HeaderStructureLike> | undefined): boolean;
|
|
38
|
+
/** Collect every accessor in a header tree (for renderer-cache pruning). */
|
|
39
|
+
export declare function collectHeaderAccessors(headers: ReadonlyArray<HeaderStructureLike>, into?: Set<string>): Set<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Shallow equality of a single row object (own enumerable keys, `===` values).
|
|
42
|
+
* Identical references are equal. In-place mutation on a shared object is
|
|
43
|
+
* invisible — callers must pass new object identities when data changes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function shallowEqualRow(a: object, b: object): boolean;
|
|
46
|
+
export type GetRowIdLike = (params: {
|
|
47
|
+
row: unknown;
|
|
48
|
+
depth?: number;
|
|
49
|
+
index?: number;
|
|
50
|
+
rowPath?: (string | number)[];
|
|
51
|
+
rowIndexPath?: number[];
|
|
52
|
+
groupingKey?: string;
|
|
53
|
+
}) => string | number | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Above this length, skip per-field shallow compares when row object identity
|
|
56
|
+
* differs. Same-array-ref and same-row-object cases stay O(1) / O(n) pointer
|
|
57
|
+
* checks. Protects huge client datasets from O(n × fields) scans.
|
|
58
|
+
*/
|
|
59
|
+
export declare const SHALLOW_ROW_COMPARE_MAX = 50000;
|
|
60
|
+
/**
|
|
61
|
+
* True when `next` is a no-op relative to `prev` for table sync:
|
|
62
|
+
* same length, matching `getRowId` sequence (when provided), and each row
|
|
63
|
+
* either the same object or shallow-equal (for modest list sizes).
|
|
64
|
+
*/
|
|
65
|
+
export declare function rowsShallowUnchanged(prev: ReadonlyArray<object> | undefined, next: ReadonlyArray<object> | undefined, getRowId?: GetRowIdLike): boolean;
|
|
@@ -55,6 +55,13 @@ export declare const calculateNestedTableHeight: ({ calculatedHeight, customHeig
|
|
|
55
55
|
* getNestedValue(row, "releaseDate[0]") returns row.releaseDate[0]
|
|
56
56
|
*/
|
|
57
57
|
export declare const getNestedValue: (obj: Row, path: Accessor) => CellValue;
|
|
58
|
+
/**
|
|
59
|
+
* True when both arrays have the same length and the same row object references
|
|
60
|
+
* at each index. Used by FilterManager / SortManager so in-place live updates
|
|
61
|
+
* that recompute filter/sort only notify subscribers when membership or order
|
|
62
|
+
* actually changed (`.filter()` / `handleSort` always allocate new arrays).
|
|
63
|
+
*/
|
|
64
|
+
export declare const rowsOrderEqual: (a: Row[], b: Row[]) => boolean;
|
|
58
65
|
/**
|
|
59
66
|
* Set a nested property value in an object using dot notation and array bracket notation
|
|
60
67
|
* Examples:
|
|
@@ -27,7 +27,16 @@ interface PortalEntry {
|
|
|
27
27
|
* tagged with {@link PORTAL_ID_ATTR} inside that host, so React unmounts exactly
|
|
28
28
|
* those subtrees. Reuse/reparent paths never signal, so a reused node keeps its
|
|
29
29
|
* portal entry (and its content) with zero churn.
|
|
30
|
+
*
|
|
31
|
+
* {@link cellRendererCache} / {@link headerRendererCache} keep one wrapped
|
|
32
|
+
* renderer per accessor so unstable column rebuilds (new Component identity,
|
|
33
|
+
* same accessor) reuse the portal host instead of remounting React state.
|
|
30
34
|
*/
|
|
35
|
+
/** Mutable slot so wrapped renderers keep a stable closure across rebuilds. */
|
|
36
|
+
export type CachedRendererSlot<T = unknown> = {
|
|
37
|
+
component: T;
|
|
38
|
+
wrapped: unknown;
|
|
39
|
+
};
|
|
31
40
|
export declare class PortalBridge {
|
|
32
41
|
private entries;
|
|
33
42
|
private listeners;
|
|
@@ -35,6 +44,10 @@ export declare class PortalBridge {
|
|
|
35
44
|
private cachedSnapshot;
|
|
36
45
|
private snapshotDirty;
|
|
37
46
|
private emitScheduled;
|
|
47
|
+
/** Per-accessor cached cellRenderer wrappers (stable across rebuildHeaders). */
|
|
48
|
+
readonly cellRendererCache: Map<string, CachedRendererSlot<unknown>>;
|
|
49
|
+
/** Per-accessor cached headerRenderer wrappers. */
|
|
50
|
+
readonly headerRendererCache: Map<string, CachedRendererSlot<unknown>>;
|
|
38
51
|
/**
|
|
39
52
|
* Register a React node to be rendered into `container`. The container is
|
|
40
53
|
* returned to core synchronously (matching the vanilla renderer contract); the
|
|
@@ -65,6 +78,11 @@ export declare class PortalBridge {
|
|
|
65
78
|
disposeHost: (host: HTMLElement) => void;
|
|
66
79
|
/** Remove all entries (used on table teardown). */
|
|
67
80
|
clear(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Drop cached wrappers for accessors no longer present in the header tree
|
|
83
|
+
* so remounted columns with the same accessor don't reuse a stale Component box.
|
|
84
|
+
*/
|
|
85
|
+
pruneRendererCaches(liveAccessors: ReadonlySet<string>): void;
|
|
68
86
|
subscribe: (listener: () => void) => (() => void);
|
|
69
87
|
getSnapshot: () => PortalEntry[];
|
|
70
88
|
private emit;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shared prop-sync helpers from core so React tests/imports that
|
|
3
|
+
* target this path keep working. Source of truth: simple-table-core.
|
|
4
|
+
*/
|
|
5
|
+
export { headersStructurallyEqual, collectHeaderAccessors, rowsShallowUnchanged, shallowEqualRow, SHALLOW_ROW_COMPARE_MAX, } from "simple-table-core";
|
|
6
|
+
export type { HeaderStructureLike, GetRowIdLike } from "simple-table-core";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shared row-sync helpers from core.
|
|
3
|
+
* Source of truth: simple-table-core `propSyncEqual`.
|
|
4
|
+
*/
|
|
5
|
+
export { rowsShallowUnchanged, shallowEqualRow, SHALLOW_ROW_COMPARE_MAX, } from "simple-table-core";
|
|
6
|
+
export type { GetRowIdLike } from "simple-table-core";
|
|
@@ -39,6 +39,18 @@ export declare function wrapReactRendererIntoFragment<P extends object>(bridge:
|
|
|
39
39
|
* the React subtree and wiping local state.
|
|
40
40
|
*/
|
|
41
41
|
export declare function wrapReactHeaderRenderer(bridge: PortalBridge, Component: React.ComponentType<VanillaHeaderRendererProps>): (props: VanillaHeaderRendererProps) => HTMLElement;
|
|
42
|
+
/**
|
|
43
|
+
* Like {@link wrapReactRendererIntoFragment}, but reuses one wrapper per
|
|
44
|
+
* `accessor` on the bridge. When the consumer rebuilds columns with a new
|
|
45
|
+
* Component identity, the slot's `component` is updated in place so the
|
|
46
|
+
* wrapped function identity stays stable across `defaultHeaders` rebuilds.
|
|
47
|
+
*/
|
|
48
|
+
export declare function wrapCachedCellRenderer<P extends object>(bridge: PortalBridge, accessor: string, Component: React.ComponentType<P>): (props: P) => HTMLElement;
|
|
49
|
+
/**
|
|
50
|
+
* Like {@link wrapReactHeaderRenderer}, but reuses one host-bearing wrapper per
|
|
51
|
+
* `accessor` so unstable column rebuilds do not remount header React state.
|
|
52
|
+
*/
|
|
53
|
+
export declare function wrapCachedHeaderRenderer(bridge: PortalBridge, accessor: string, Component: React.ComponentType<VanillaHeaderRendererProps>): (props: VanillaHeaderRendererProps) => HTMLElement;
|
|
42
54
|
/**
|
|
43
55
|
* Like {@link wrapReactHeaderRenderer} for the header dropdown, which shares the
|
|
44
56
|
* same `components` slot shape.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simple-table/react",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.8",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/types/react/src/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"react-dom": ">=18.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"simple-table-core": "3.9.
|
|
32
|
+
"simple-table-core": "3.9.8"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@rollup/plugin-alias": "^4.0.4",
|