metatable-react
Version:
Library for creating table interfaces based on metaprogramming concepts
33 lines (29 loc) • 27.1 kB
JavaScript
(function(L,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],p):(L=typeof globalThis<"u"?globalThis:L||self,p(L["react-metatable"]={},L.React))})(this,function(L,p){"use strict";var fe={exports:{}},G={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var xe;function st(){if(xe)return G;xe=1;var t=p,r=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,l=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function v(u,d,m){var f,E={},b=null,O=null;m!==void 0&&(b=""+m),d.key!==void 0&&(b=""+d.key),d.ref!==void 0&&(O=d.ref);for(f in d)o.call(d,f)&&!c.hasOwnProperty(f)&&(E[f]=d[f]);if(u&&u.defaultProps)for(f in d=u.defaultProps,d)E[f]===void 0&&(E[f]=d[f]);return{$$typeof:r,type:u,key:b,ref:O,props:E,_owner:l.current}}return G.Fragment=a,G.jsx=v,G.jsxs=v,G}var K={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Pe;function lt(){return Pe||(Pe=1,process.env.NODE_ENV!=="production"&&function(){var t=p,r=Symbol.for("react.element"),a=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),v=Symbol.for("react.provider"),u=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),O=Symbol.for("react.offscreen"),z=Symbol.iterator,J="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var n=z&&e[z]||e[J];return typeof n=="function"?n:null}var A=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(e){{for(var n=arguments.length,i=new Array(n>1?n-1:0),h=1;h<n;h++)i[h-1]=arguments[h];ae("error",e,i)}}function ae(e,n,i){{var h=A.ReactDebugCurrentFrame,y=h.getStackAddendum();y!==""&&(n+="%s",i=i.concat([y]));var S=i.map(function(_){return String(_)});S.unshift("Warning: "+n),Function.prototype.apply.call(console[e],console,S)}}var U=!1,oe=!1,T=!1,k=!1,I=!1,Z;Z=Symbol.for("react.module.reference");function ie(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===c||I||e===l||e===m||e===f||k||e===O||U||oe||T||typeof e=="object"&&e!==null&&(e.$$typeof===b||e.$$typeof===E||e.$$typeof===v||e.$$typeof===u||e.$$typeof===d||e.$$typeof===Z||e.getModuleId!==void 0))}function W(e,n,i){var h=e.displayName;if(h)return h;var y=n.displayName||n.name||"";return y!==""?i+"("+y+")":i}function Le(e){return e.displayName||"Context"}function M(e){if(e==null)return null;if(typeof e.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case a:return"Portal";case c:return"Profiler";case l:return"StrictMode";case m:return"Suspense";case f:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case u:var n=e;return Le(n)+".Consumer";case v:var i=e;return Le(i._context)+".Provider";case d:return W(e,e.render,"ForwardRef");case E:var h=e.displayName||null;return h!==null?h:M(e.type)||"Memo";case b:{var y=e,S=y._payload,_=y._init;try{return M(_(S))}catch{return null}}}return null}var B=Object.assign,X=0,Ve,We,$e,Ue,Be,Ye,ze;function He(){}He.__reactDisabledLog=!0;function sr(){{if(X===0){Ve=console.log,We=console.info,$e=console.warn,Ue=console.error,Be=console.group,Ye=console.groupCollapsed,ze=console.groupEnd;var e={configurable:!0,enumerable:!0,value:He,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}X++}}function lr(){{if(X--,X===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:B({},e,{value:Ve}),info:B({},e,{value:We}),warn:B({},e,{value:$e}),error:B({},e,{value:Ue}),group:B({},e,{value:Be}),groupCollapsed:B({},e,{value:Ye}),groupEnd:B({},e,{value:ze})})}X<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ge=A.ReactCurrentDispatcher,_e;function se(e,n,i){{if(_e===void 0)try{throw Error()}catch(y){var h=y.stack.trim().match(/\n( *(at )?)/);_e=h&&h[1]||""}return`
`+_e+e}}var be=!1,le;{var cr=typeof WeakMap=="function"?WeakMap:Map;le=new cr}function qe(e,n){if(!e||be)return"";{var i=le.get(e);if(i!==void 0)return i}var h;be=!0;var y=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var S;S=ge.current,ge.current=null,sr();try{if(n){var _=function(){throw Error()};if(Object.defineProperty(_.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(_,[])}catch(D){h=D}Reflect.construct(e,[],_)}else{try{_.call()}catch(D){h=D}e.call(_.prototype)}}else{try{throw Error()}catch(D){h=D}e()}}catch(D){if(D&&h&&typeof D.stack=="string"){for(var g=D.stack.split(`
`),R=h.stack.split(`
`),C=g.length-1,w=R.length-1;C>=1&&w>=0&&g[C]!==R[w];)w--;for(;C>=1&&w>=0;C--,w--)if(g[C]!==R[w]){if(C!==1||w!==1)do if(C--,w--,w<0||g[C]!==R[w]){var j=`
`+g[C].replace(" at new "," at ");return e.displayName&&j.includes("<anonymous>")&&(j=j.replace("<anonymous>",e.displayName)),typeof e=="function"&&le.set(e,j),j}while(C>=1&&w>=0);break}}}finally{be=!1,ge.current=S,lr(),Error.prepareStackTrace=y}var q=e?e.displayName||e.name:"",Y=q?se(q):"";return typeof e=="function"&&le.set(e,Y),Y}function ur(e,n,i){return qe(e,!1)}function fr(e){var n=e.prototype;return!!(n&&n.isReactComponent)}function ce(e,n,i){if(e==null)return"";if(typeof e=="function")return qe(e,fr(e));if(typeof e=="string")return se(e);switch(e){case m:return se("Suspense");case f:return se("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return ur(e.render);case E:return ce(e.type,n,i);case b:{var h=e,y=h._payload,S=h._init;try{return ce(S(y),n,i)}catch{}}}return""}var Q=Object.prototype.hasOwnProperty,Ge={},Ke=A.ReactDebugCurrentFrame;function ue(e){if(e){var n=e._owner,i=ce(e.type,e._source,n?n.type:null);Ke.setExtraStackFrame(i)}else Ke.setExtraStackFrame(null)}function dr(e,n,i,h,y){{var S=Function.call.bind(Q);for(var _ in e)if(S(e,_)){var g=void 0;try{if(typeof e[_]!="function"){var R=Error((h||"React class")+": "+i+" type `"+_+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[_]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw R.name="Invariant Violation",R}g=e[_](n,_,h,i,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(C){g=C}g&&!(g instanceof Error)&&(ue(y),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",h||"React class",i,_,typeof g),ue(null)),g instanceof Error&&!(g.message in Ge)&&(Ge[g.message]=!0,ue(y),x("Failed %s type: %s",i,g.message),ue(null))}}}var hr=Array.isArray;function ye(e){return hr(e)}function vr(e){{var n=typeof Symbol=="function"&&Symbol.toStringTag,i=n&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i}}function pr(e){try{return Je(e),!1}catch{return!0}}function Je(e){return""+e}function Ze(e){if(pr(e))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",vr(e)),Je(e)}var ee=A.ReactCurrentOwner,mr={key:!0,ref:!0,__self:!0,__source:!0},Xe,Qe,Ee;Ee={};function gr(e){if(Q.call(e,"ref")){var n=Object.getOwnPropertyDescriptor(e,"ref").get;if(n&&n.isReactWarning)return!1}return e.ref!==void 0}function _r(e){if(Q.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function br(e,n){if(typeof e.ref=="string"&&ee.current&&n&&ee.current.stateNode!==n){var i=M(ee.current.type);Ee[i]||(x('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',M(ee.current.type),e.ref),Ee[i]=!0)}}function yr(e,n){{var i=function(){Xe||(Xe=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}}function Er(e,n){{var i=function(){Qe||(Qe=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};i.isReactWarning=!0,Object.defineProperty(e,"ref",{get:i,configurable:!0})}}var Sr=function(e,n,i,h,y,S,_){var g={$$typeof:r,type:e,key:n,ref:i,props:_,_owner:S};return g._store={},Object.defineProperty(g._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(g,"_self",{configurable:!1,enumerable:!1,writable:!1,value:h}),Object.defineProperty(g,"_source",{configurable:!1,enumerable:!1,writable:!1,value:y}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g};function Cr(e,n,i,h,y){{var S,_={},g=null,R=null;i!==void 0&&(Ze(i),g=""+i),_r(n)&&(Ze(n.key),g=""+n.key),gr(n)&&(R=n.ref,br(n,y));for(S in n)Q.call(n,S)&&!mr.hasOwnProperty(S)&&(_[S]=n[S]);if(e&&e.defaultProps){var C=e.defaultProps;for(S in C)_[S]===void 0&&(_[S]=C[S])}if(g||R){var w=typeof e=="function"?e.displayName||e.name||"Unknown":e;g&&yr(_,w),R&&Er(_,w)}return Sr(e,g,R,y,h,ee.current,_)}}var Se=A.ReactCurrentOwner,et=A.ReactDebugCurrentFrame;function H(e){if(e){var n=e._owner,i=ce(e.type,e._source,n?n.type:null);et.setExtraStackFrame(i)}else et.setExtraStackFrame(null)}var Ce;Ce=!1;function we(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function tt(){{if(Se.current){var e=M(Se.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function wr(e){{if(e!==void 0){var n=e.fileName.replace(/^.*[\\\/]/,""),i=e.lineNumber;return`
Check your code at `+n+":"+i+"."}return""}}var rt={};function Tr(e){{var n=tt();if(!n){var i=typeof e=="string"?e:e.displayName||e.name;i&&(n=`
Check the top-level render call using <`+i+">.")}return n}}function nt(e,n){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var i=Tr(n);if(rt[i])return;rt[i]=!0;var h="";e&&e._owner&&e._owner!==Se.current&&(h=" It was passed a child from "+M(e._owner.type)+"."),H(e),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,h),H(null)}}function at(e,n){{if(typeof e!="object")return;if(ye(e))for(var i=0;i<e.length;i++){var h=e[i];we(h)&&nt(h,n)}else if(we(e))e._store&&(e._store.validated=!0);else if(e){var y=V(e);if(typeof y=="function"&&y!==e.entries)for(var S=y.call(e),_;!(_=S.next()).done;)we(_.value)&&nt(_.value,n)}}}function xr(e){{var n=e.type;if(n==null||typeof n=="string")return;var i;if(typeof n=="function")i=n.propTypes;else if(typeof n=="object"&&(n.$$typeof===d||n.$$typeof===E))i=n.propTypes;else return;if(i){var h=M(n);dr(i,e.props,"prop",h,e)}else if(n.PropTypes!==void 0&&!Ce){Ce=!0;var y=M(n);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",y||"Unknown")}typeof n.getDefaultProps=="function"&&!n.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Pr(e){{for(var n=Object.keys(e.props),i=0;i<n.length;i++){var h=n[i];if(h!=="children"&&h!=="key"){H(e),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),H(null);break}}e.ref!==null&&(H(e),x("Invalid attribute `ref` supplied to `React.Fragment`."),H(null))}}var ot={};function it(e,n,i,h,y,S){{var _=ie(e);if(!_){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var R=wr(y);R?g+=R:g+=tt();var C;e===null?C="null":ye(e)?C="array":e!==void 0&&e.$$typeof===r?(C="<"+(M(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):C=typeof e,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",C,g)}var w=Cr(e,n,i,y,S);if(w==null)return w;if(_){var j=n.children;if(j!==void 0)if(h)if(ye(j)){for(var q=0;q<j.length;q++)at(j[q],e);Object.freeze&&Object.freeze(j)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else at(j,e)}if(Q.call(n,"key")){var Y=M(e),D=Object.keys(n).filter(function(kr){return kr!=="key"}),Te=D.length>0?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}";if(!ot[Y+Te]){var Ar=D.length>0?"{"+D.join(": ..., ")+": ...}":"{}";x(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,Te,Y,Ar,Y),ot[Y+Te]=!0}}return e===o?Pr(w):xr(w),w}}function Rr(e,n,i){return it(e,n,i,!0)}function Dr(e,n,i){return it(e,n,i,!1)}var Fr=Dr,Or=Rr;K.Fragment=o,K.jsx=Fr,K.jsxs=Or}()),K}process.env.NODE_ENV==="production"?fe.exports=st():fe.exports=lt();var de=fe.exports;const he=de.Fragment,s=de.jsx,P=de.jsxs;class N{static pipeline(...r){return(...a)=>r.reduce((o,l)=>l.apply(null,Array.isArray(o)?o:[o]),a)}static range(r,a){const o=a-r+1;return Array.from({length:o},(l,c)=>c+r)}static async request(r,a){const o=await fetch(r,a);if(o.status!==200)throw new Error(o.statusText);return await o.json()}static isFunction(r){return typeof r=="function"}static createCacheMap(){const r=new Map;return{set(a,o){r.set(a,o)},get:a=>r.get(a),clear:()=>r.clear()}}}const ct=t=>s("div",{children:t.value}),ut=({value:t})=>s(he,{children:t}),ft="en-US",dt=()=>{var t;return((t=window==null?void 0:window.navigator)==null?void 0:t.language)||ft},ht=t=>{const r=p.useMemo(()=>t.locale||dt(),[]),a=new Date(t.value),o=a instanceof Date&&!isNaN(a==null?void 0:a.getTime());return s("div",{children:o?a.toLocaleDateString(r,t.options||{}):"-"})},vt={sortable:{},filter:{}},Re=p.createContext(null),te=()=>p.useContext(Re),De=({children:t})=>{const[r,a]=p.useState(vt);return s(Re.Provider,{value:{state:r,setState:a},children:t})},Fe=p.createContext(null),pt=N.createCacheMap(),mt=t=>{const{children:r}=t;return s(Fe.Provider,{value:pt,children:r})},gt=()=>p.useContext(Fe),_t=t=>{const{cellSettings:{fetch:r},tableData:a}=t,[o,l]=p.useState(void 0),c=gt();p.useEffect(()=>{const u=r.paramsType==="path",d=String(a[r.fieldNameWithDataForFetching]),m=u?`${r.url}/${d}`:r.url,f=new URL(m);u||f.searchParams.append(r.fieldNameWithDataForFetching,d);const E=c.get(f.href);if(E){l(E);return}N.request(f,{headers:r.extraHeaders}).then(b=>{c.set(f.href,b),l(b)}).catch(console.error)},[]);const v=o?String(o[r.fieldNameReceivedObject]):"-";return s("div",{children:v})},bt=Object.assign({},{text:ct,number:ut,date:ht,reference:t=>p.createElement(mt,{},p.createElement(_t,{...t}))}),Nr="",yt=()=>s("svg",{width:"15",height:"15",viewBox:"0 0 1920 1920",xmlns:"http://www.w3.org/2000/svg",children:s("path",{d:"M1539 215v1250l299-299 82 82-439 439-439-439 82-82 299 299V215h116ZM439 160l439 439-82 82-299-299v1249H381V382L82 681 0 599l439-439Z",fillRule:"evenodd"})}),Et=()=>s("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s("path",{d:"M4 17h12M4 12h9M4 7h6m8 6V5m0 0 3 3m-3-3-3 3",stroke:"#000",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),St=()=>s("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s("path",{d:"M4 17h6m-6-5h9m5-1v8m0 0 3-3m-3 3-3-3M4 7h12",stroke:"#000",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}),F={DESC:"DESC",ASC:"ASC",DEFAULT:"DEFAULT"},ve={[F.DESC]:s(St,{}),[F.ASC]:s(Et,{}),[F.DEFAULT]:s(yt,{})},Ct=t=>t===F.DEFAULT?F.ASC:t===F.ASC?F.DESC:t===F.DESC?F.DEFAULT:F.ASC,wt=(t,r)=>{const[a]=Object.entries(t.sortable);if(!a)return r;const[o,l]=a;if(!o||!Object.keys(F).includes(l)||l===F.DEFAULT)return r;const v=[...r].sort((u,d)=>{const m=u[o],f=d[o];return m>f?1:m<f?-1:0});return l===F.ASC?v:v.reverse()},Tt=t=>{const{cellValue:r,id:a,icon:o}=t,{setState:l,state:c}=te();if(!r)return null;const v=p.useCallback(()=>{l(m=>({...m,sortable:{[a]:Ct(m.sortable[a])}}))},[]),u=c.sortable[a],d=o?o(u||ve.DEFAULT):ve[u]||ve.DEFAULT;return P("span",{className:"sort-cell",children:[s("span",{className:"sort-cell__value",children:r}),s("span",{className:"sort-cell__button",onClick:v,children:d})]})},Oe=p.memo(Tt);Oe.displayName="WithSortCell";var $=(t=>(t.Text="text",t.Enum="enum",t.Reference="reference",t))($||{});const xt=({setFilter:t})=>{const[r,a]=p.useState("");return s("input",{type:"text",value:r,placeholder:"Enter text",onChange:l=>{const c=l.target.value;c&&(a(c),t(c))}})},Pt=t=>$.Enum===t.type,Ae=({filterSetting:t,setFilter:r})=>{const[a,o]=p.useState([]),l=c=>{const v=c.target.value;if(!v)return;const u=a.includes(v)?a.filter(d=>d!==v):[...a,v];o(u),r(u)};return Pt(t)?s("div",{className:"filter-enum",children:s("ul",{className:"filter-enum__list",children:t.options.map(c=>s("li",{className:"filter-enum__item",children:P("label",{className:"filter-enum__label",children:[s("input",{className:"filter-enum__input",checked:a.includes(String(c)),onChange:l,name:"enum-checkboxes-filter",value:c,type:"checkbox"}),c]},c)},c))})}):null},pe=t=>$.Reference===t.type,Rt=({filterSetting:t,setFilter:r})=>{const a=p.useRef(),[o,l]=p.useState([]);p.useEffect(()=>{if(!pe(t)||o.length)return;const u=new URL(t.fetch.url);N.request(u).then(d=>{a.current=d,l(d.map(m=>m[t.fetch.fieldNameReceivedObject]))}).catch(console.error)},[]);const c=p.useMemo(()=>({type:$.Enum,options:o}),[o]),v=u=>{if(!pe(t)||!a.current)return;const d=a.current.filter(m=>{const f=m[t.fetch.fieldNameReceivedObject];return u.includes(f)}).map(m=>m[t.fetch.fieldNameToFilterValue]);r(d)};return!pe(t)||!o.length?null:s(Ae,{filterSetting:c,setFilter:v})},Dt={[$.Text]:xt,[$.Enum]:Ae,[$.Reference]:Rt},Ft=t=>{const{filterSetting:r,id:a,customDD:o,toggleFilterBody:l}=t,[c,v]=p.useState(""),{setState:u,state:d}=te(),[m]=Object.keys(d.filter),f=m===a,E=()=>{f&&u(V=>({...V,filter:{}}))},b=()=>u(V=>({...V,filter:{[a]:c}})),O=p.useMemo(()=>o&&o({filterSetting:r,close:l,confirm:V=>u(A=>({...A,filter:{[a]:V}}))}),[]),z=p.useMemo(()=>Dt[r.type],[r.type]),J=Array.isArray(c)?c.length:c;return s("div",{className:"filter-dialog",children:O||P(he,{children:[s("div",{className:"filter-dialog__body",children:s(z,{filterSetting:r,setFilter:v})}),P("div",{className:"filter-dialog__footer",children:[s("button",{className:"filter-dialog__footer-action",disabled:!J,onClick:b,children:"filter"}),s("button",{className:"filter-dialog__footer-action",disabled:!f,onClick:E,children:"clearFilter"})]})]})})},Ir="",Ot=()=>s("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",className:"icon glyph",children:s("path",{d:"M21 8H3a1 1 0 0 1 0-2h18a1 1 0 0 1 0 2ZM19 13H5a1 1 0 0 1 0-2h14a1 1 0 0 1 0 2ZM17 18H7a1 1 0 0 1 0-2h10a1 1 0 0 1 0 2Z",fill:"#231f20"})}),At=()=>s("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:P("g",{fill:"none",fillRule:"evenodd",children:[s("path",{d:"M0 0h24v24H0z"}),s("path",{stroke:"#0C0310",strokeWidth:2,strokeLinecap:"round",d:"M17 7 7 17M7 7l10 10"})]})}),kt=t=>t?s(At,{}):s(Ot,{}),jt=t=>t.preventDefault(),Nt=t=>{const{cellValue:r,id:a,filterSetting:o,icon:l,filterDD:c}=t,{state:v}=te(),[u,d]=p.useState(!1);if(!r)return null;const m=()=>d(b=>!b);if(!o)return null;const f=Object.values(v.filter).some(Boolean),E=l?l(f,u):kt(u);return P("details",{className:"filter-cell",open:u,children:[P("summary",{onClick:jt,className:"filter-cell__content",children:[s("span",{className:"filter-cell__value",children:r}),s("span",{onClick:m,className:"filter-cell__button",children:E})]}),u&&s("div",{className:"filter-cell__body",children:s(Ft,{toggleFilterBody:m,customDD:c,id:a,filterSetting:o})})]})};function It(t,r){const[a]=Object.keys(t.filter);if(!a)return r;const o=t.filter[a];return o?Array.isArray(o)?Mt(r,o,a):Lt(r,o,a):r}function Mt(t,r,a){const o=r.map(l=>String(l).toLocaleLowerCase());return t.filter(l=>{const c=l[a];if(!c)return!0;const v=String(c).toLocaleLowerCase();return o.includes(v)})}function Lt(t,r,a){const o=String(r).toLocaleLowerCase();return t.filter(l=>{const c=l[a];return c?String(c).toLocaleLowerCase().includes(o):!0})}const ke=p.memo(Nt);ke.displayName="WithFilterCell";const Vt=t=>s(he,{children:t}),Wt=t=>"displayName"in t?t.displayName:"",je=t=>["WithFilterCell","WithSortCell"].includes(t),Ne=t=>t==="WithSortCell",$t=(t,r,a)=>{var o,l;je(t)&&(a.icon=Ne(t)?(o=r.sort)==null?void 0:o.sortIcon:(l=r.filter)==null?void 0:l.filterIcon)},Ut=(t,r,a)=>{var o;!je(t)&&Ne(t)||(a.filterDD=(o=r.filter)==null?void 0:o.filterDD)},Bt={filter:ke,sortable:Oe},Yt=t=>{const{locale:r={},metaData:a}=t;return p.useMemo(()=>({columns:Object.entries(a).map(([o,l])=>{const{cell:c,...v}=l;return{id:o,headerModel:zt(o,r[o]||o,v),bodyModel:Ht(o,c)}})}),[])},zt=(t,r,a)=>o=>N.pipeline(...Object.entries(a).map(l=>{const[c,v]=l,u=c,d=a[u];if(!v)return Vt;const m=Bt[u],f=Wt(m),E={};return[$t,Ut].forEach(b=>b(f,o,E)),b=>p.cloneElement(s(m,{filterSetting:typeof d=="boolean"?void 0:d,cellValue:b,id:t}),{...E})}))(r),Ht=(t,r)=>{const a=bt[r.type];return a?o=>s(a,{cellSettings:r,tableData:o,value:o[t]||void 0}):null},re="...",qt=({currentPage:t,pageSize:r,siblingCount:a=1,totalCount:o})=>{const l=Math.ceil(o/r);if(a+5>=l)return N.range(1,l);const v=Math.max(t-a,1),u=Math.min(t+a,l),d=v>2,m=u<l-2,f=1,E=l;if(!d&&m){const b=3+2*a;return[...N.range(1,b),re,l]}if(d&&!m){let b=3+2*a,O=N.range(l-b+1,l);return[f,re,...O]}if(d&&m){let b=N.range(v,u);return[f,re,...b,re,E]}return[]},Gt=t=>qt(t),Kt=(t,r)=>t.find(({value:a})=>r===a),Jt=t=>{const{options:r,defaultValue:a,onChange:o,titlePrefix:l}=t,[c,v]=p.useState(!1),[u,d]=p.useState(()=>Kt(r,a));return P("details",{onClick:f=>{f.preventDefault(),v(E=>!E)},className:"menu",open:c,children:[P("summary",{className:"menu__title",children:[l,s("span",{className:"menu__title-text",children:u==null?void 0:u.title})]}),s("ul",{className:"menu__items",children:r.map(({title:f,value:E},b)=>s("li",{className:"menu__item",onClick:()=>{d(r[b]),o(r[b])},children:f},E))})]})},Ie=t=>s("svg",{xmlns:"http://www.w3.org/2000/svg",height:"10",width:"10",viewBox:"0 0 330 330",xmlSpace:"preserve",...t,children:s("path",{d:"M325.607 79.393c-5.857-5.857-15.355-5.858-21.213.001l-139.39 139.393L25.607 79.393c-5.857-5.857-15.355-5.858-21.213.001-5.858 5.858-5.858 15.355 0 21.213l150.004 150a14.999 14.999 0 0 0 21.212-.001l149.996-150c5.859-5.857 5.859-15.355.001-21.213z"})}),Zt=[10,25,50],Xt={pageSize:10},Qt=Zt.map(t=>({value:t,title:t})),er=t=>{const{onChangePage:r,onPageSizeChange:a,currentPage:o,pageSize:l,totalCount:c}=t,[v,u]=p.useState(l||Xt.pageSize),d=Gt({currentPage:o,totalCount:c,pageSize:v});return P("div",{className:"pagination",children:[s("div",{className:"pagination__page-size-selector",children:s(Jt,{titlePrefix:s(Ie,{}),onChange:({value:f})=>{typeof f=="number"&&(u(f),a(f))},defaultValue:v,options:Qt})}),s("ul",{className:"pagination__items",children:d.map((f,E)=>{const b=t.currentPage===f;return typeof f=="string"?s("li",{className:"pagination__item",children:f},f+E):s("li",{className:`pagination__item ${b?"pagination__item--active":""}`,onClick:()=>r(f),children:f},f)})})]})},me=({children:t})=>s("tr",{className:"meta-table__row",children:t}),ne=({children:t,className:r,...a})=>s("td",{className:`meta-table__body-cell ${r||""}`,...a,children:t}),Me=({children:t,className:r,...a})=>s("th",{className:`meta-table__header-cell ${r||""}`,...a,children:t}),tr={transform:"rotate(180deg)"},rr=t=>{const{rowId:r,toggleExpandRow:a,isExpandRow:o,isOpen:l,expandable:c}=t,v=p.useCallback(()=>{a(d=>d.includes(r)?d.filter(f=>f!==r):[...d,r])},[r]);if(!o)return s(ne,{className:"meta-table__body-cell-expand-toggle"});const u=N.isFunction(c==null?void 0:c.expandIcon)?c==null?void 0:c.expandIcon(l):s(Ie,{style:l?tr:void 0});return s(ne,{onClick:v,className:"meta-table__body-cell-expand-toggle",children:s("div",{className:"meta-table__cell-content-wrapper",children:u})})},Mr="",nr=(t,r,a)=>t.slice((a-1)*r,r*a),ar=(t,r)=>{const{columns:a,data:o,...l}=t,{className:c,pagination:v,expandable:u,...d}=l,{state:m,setState:f}=te(),[E,b]=p.useState(1),[O,z]=p.useState(10),[J,V]=p.useState([]);p.useImperativeHandle(r,()=>({setFilter:(T,k)=>f(I=>({...I,filter:{[T]:k}})),setSort:(T,k)=>f(I=>({...I,sortable:{[T]:k}})),setPage:T=>b(T)}),[f]);const A=It(m,o),x=v?nr(A,O,E):A,ae=wt(m,x),U=u&&ae.map((T,k)=>(N.isFunction(u.isExpandRow)?u.isExpandRow(T):u.isExpandRow)?T.id||String(k):!1).filter(Boolean),oe=Array.isArray(U)&&U.length>0;return P("div",{className:"meta-table-wrapper",children:[P("table",{className:`meta-table ${c||""}`,children:[s("thead",{className:"meta-table__header",children:P(me,{children:[oe&&s(Me,{children:u==null?void 0:u.columnTitle}),a.map((T,k)=>s(Me,{children:T.headerModel(d)},`header-cell-${k}`))]})}),s("tbody",{className:"meta-table__body",children:ae.map((T,k)=>{const I=T.id||k,Z=!!(U!=null&&U.includes(I)),ie=J.includes(I);return P(p.Fragment,{children:[P(me,{children:[oe&&s(rr,{rowId:I,isExpandRow:Z,isOpen:ie,toggleExpandRow:V,expandable:u}),a.map(W=>s(ne,{children:(W==null?void 0:W.bodyModel)&&(W==null?void 0:W.bodyModel(T))},`body-cell-${W.id}`))]}),Z&&ie&&s(me,{children:s(ne,{colSpan:a.length+1,children:s("div",{className:"meta-table__cell-content-wrapper",children:u.render(T)})})})]},`body-row-${T==null?void 0:T.id}${k}`)})})]}),v&&s(er,{onChangePage:b,onPageSizeChange:z,totalCount:A.length,pageSize:O,currentPage:E})]})},or=p.forwardRef(ar),ir=t=>{const{tableApi:r,...a}=t;return s(De,{children:s(or,{...a,ref:r})})};L.MetaTable=ir,L.TableStateProvider=De,L.useGetTableColumns=Yt,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});