UNPKG

50.1 kBJavaScriptView Raw
1function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t}).apply(this,arguments)}var e,s,i,n,r,o,a={},l=[],h=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c(t,e){for(var s in e)t[s]=e[s];return t}function p(t){var e=t.parentNode;e&&e.removeChild(t)}function u(t,e,s){var i,n,r,o=arguments,a={};for(r in e)"key"==r?i=e[r]:"ref"==r?n=e[r]:a[r]=e[r];if(arguments.length>3)for(s=[s],r=3;r<arguments.length;r++)s.push(o[r]);if(null!=s&&(a.children=s),"function"==typeof t&&null!=t.defaultProps)for(r in t.defaultProps)void 0===a[r]&&(a[r]=t.defaultProps[r]);return d(t,a,i,n,null)}function d(t,s,i,n,r){var o={type:t,props:s,key:i,ref:n,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==r?++e.__v:r};return null!=e.vnode&&e.vnode(o),o}function f(){return{current:null}}function _(t){return t.children}function m(t,e){this.props=t,this.context=e}function g(t,e){if(null==e)return t.__?g(t.__,t.__.__k.indexOf(t)+1):null;for(var s;e<t.__k.length;e++)if(null!=(s=t.__k[e])&&null!=s.__e)return s.__e;return"function"==typeof t.type?g(t):null}function y(t){var e,s;if(null!=(t=t.__)&&null!=t.__c){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if(null!=(s=t.__k[e])&&null!=s.__e){t.__e=t.__c.base=s.__e;break}return y(t)}}function v(t){(!t.__d&&(t.__d=!0)&&i.push(t)&&!b.__r++||r!==e.debounceRendering)&&((r=e.debounceRendering)||n)(b)}function b(){for(var t;b.__r=i.length;)t=i.sort(function(t,e){return t.__v.__b-e.__v.__b}),i=[],t.some(function(t){var e,s,i,n,r,o;t.__d&&(r=(n=(e=t).__v).__e,(o=e.__P)&&(s=[],(i=c({},n)).__v=n.__v+1,E(o,n,i,e.__n,void 0!==o.ownerSVGElement,null!=n.__h?[r]:null,s,null==r?g(n):r,n.__h),F(s,n),n.__e!=r&&y(n)))})}function w(t,e,s,i,n,r,o,h,c,p){var u,f,m,y,v,b,w,C=i&&i.__k||l,k=C.length;for(s.__k=[],u=0;u<e.length;u++)if(null!=(y=s.__k[u]=null==(y=e[u])||"boolean"==typeof y?null:"string"==typeof y||"number"==typeof y||"bigint"==typeof y?d(null,y,null,null,y):Array.isArray(y)?d(_,{children:y},null,null,null):y.__b>0?d(y.type,y.props,y.key,null,y.__v):y)){if(y.__=s,y.__b=s.__b+1,null===(m=C[u])||m&&y.key==m.key&&y.type===m.type)C[u]=void 0;else for(f=0;f<k;f++){if((m=C[f])&&y.key==m.key&&y.type===m.type){C[f]=void 0;break}m=null}E(t,y,m=m||a,n,r,o,h,c,p),v=y.__e,(f=y.ref)&&m.ref!=f&&(w||(w=[]),m.ref&&w.push(m.ref,null,y),w.push(f,y.__c||v,y)),null!=v?(null==b&&(b=v),"function"==typeof y.type&&null!=y.__k&&y.__k===m.__k?y.__d=c=x(y,c,t):c=S(t,y,m,C,v,c),p||"option"!==s.type?"function"==typeof s.type&&(s.__d=c):t.value=""):c&&m.__e==c&&c.parentNode!=t&&(c=g(m))}for(s.__e=b,u=k;u--;)null!=C[u]&&("function"==typeof s.type&&null!=C[u].__e&&C[u].__e==s.__d&&(s.__d=g(i,u+1)),D(C[u],C[u]));if(w)for(u=0;u<w.length;u++)T(w[u],w[++u],w[++u])}function x(t,e,s){var i,n;for(i=0;i<t.__k.length;i++)(n=t.__k[i])&&(n.__=t,e="function"==typeof n.type?x(n,e,s):S(s,n,n,t.__k,n.__e,e));return e}function S(t,e,s,i,n,r){var o,a,l;if(void 0!==e.__d)o=e.__d,e.__d=void 0;else if(null==s||n!=r||null==n.parentNode)t:if(null==r||r.parentNode!==t)t.appendChild(n),o=null;else{for(a=r,l=0;(a=a.nextSibling)&&l<i.length;l+=2)if(a==n)break t;t.insertBefore(n,r),o=r}return void 0!==o?o:n.nextSibling}function C(t,e,s){"-"===e[0]?t.setProperty(e,s):t[e]=null==s?"":"number"!=typeof s||h.test(e)?s:s+"px"}function k(t,e,s,i,n){var r;t:if("style"===e)if("string"==typeof s)t.style.cssText=s;else{if("string"==typeof i&&(t.style.cssText=i=""),i)for(e in i)s&&e in s||C(t.style,e,"");if(s)for(e in s)i&&s[e]===i[e]||C(t.style,e,s[e])}else if("o"===e[0]&&"n"===e[1])r=e!==(e=e.replace(/Capture$/,"")),e=e.toLowerCase()in t?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=s,s?i||t.addEventListener(e,r?N:P,r):t.removeEventListener(e,r?N:P,r);else if("dangerouslySetInnerHTML"!==e){if(n)e=e.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==e&&"list"!==e&&"form"!==e&&"tabIndex"!==e&&"download"!==e&&e in t)try{t[e]=null==s?"":s;break t}catch(t){}"function"==typeof s||(null!=s&&(!1!==s||"a"===e[0]&&"r"===e[1])?t.setAttribute(e,s):t.removeAttribute(e))}}function P(t){this.l[t.type+!1](e.event?e.event(t):t)}function N(t){this.l[t.type+!0](e.event?e.event(t):t)}function E(t,s,i,n,r,o,h,u,d){var f,g,y,v,b,x,S,C,P,N,E,F=s.type;if(void 0!==s.constructor)return null;null!=i.__h&&(d=i.__h,u=s.__e=i.__e,s.__h=null,o=[u]),(f=e.__b)&&f(s);try{t:if("function"==typeof F){if(C=s.props,P=(f=F.contextType)&&n[f.__c],N=f?P?P.props.value:f.__:n,i.__c?S=(g=s.__c=i.__c).__=g.__E:("prototype"in F&&F.prototype.render?s.__c=g=new F(C,N):(s.__c=g=new m(C,N),g.constructor=F,g.render=R),P&&P.sub(g),g.props=C,g.state||(g.state={}),g.context=N,g.__n=n,y=g.__d=!0,g.__h=[]),null==g.__s&&(g.__s=g.state),null!=F.getDerivedStateFromProps&&(g.__s==g.state&&(g.__s=c({},g.__s)),c(g.__s,F.getDerivedStateFromProps(C,g.__s))),v=g.props,b=g.state,y)null==F.getDerivedStateFromProps&&null!=g.componentWillMount&&g.componentWillMount(),null!=g.componentDidMount&&g.__h.push(g.componentDidMount);else{if(null==F.getDerivedStateFromProps&&C!==v&&null!=g.componentWillReceiveProps&&g.componentWillReceiveProps(C,N),!g.__e&&null!=g.shouldComponentUpdate&&!1===g.shouldComponentUpdate(C,g.__s,N)||s.__v===i.__v){g.props=C,g.state=g.__s,s.__v!==i.__v&&(g.__d=!1),g.__v=s,s.__e=i.__e,s.__k=i.__k,s.__k.forEach(function(t){t&&(t.__=s)}),g.__h.length&&h.push(g);break t}null!=g.componentWillUpdate&&g.componentWillUpdate(C,g.__s,N),null!=g.componentDidUpdate&&g.__h.push(function(){g.componentDidUpdate(v,b,x)})}g.context=N,g.props=C,g.state=g.__s,(f=e.__r)&&f(s),g.__d=!1,g.__v=s,g.__P=t,f=g.render(g.props,g.state,g.context),g.state=g.__s,null!=g.getChildContext&&(n=c(c({},n),g.getChildContext())),y||null==g.getSnapshotBeforeUpdate||(x=g.getSnapshotBeforeUpdate(v,b)),E=null!=f&&f.type===_&&null==f.key?f.props.children:f,w(t,Array.isArray(E)?E:[E],s,i,n,r,o,h,u,d),g.base=s.__e,s.__h=null,g.__h.length&&h.push(g),S&&(g.__E=g.__=null),g.__e=!1}else null==o&&s.__v===i.__v?(s.__k=i.__k,s.__e=i.__e):s.__e=function(t,e,s,i,n,r,o,h){var c,u,d,f,_=s.props,m=e.props,g=e.type,y=0;if("svg"===g&&(n=!0),null!=r)for(;y<r.length;y++)if((c=r[y])&&(c===t||(g?c.localName==g:3==c.nodeType))){t=c,r[y]=null;break}if(null==t){if(null===g)return document.createTextNode(m);t=n?document.createElementNS("http://www.w3.org/2000/svg",g):document.createElement(g,m.is&&m),r=null,h=!1}if(null===g)_===m||h&&t.data===m||(t.data=m);else{if(r=r&&l.slice.call(t.childNodes),u=(_=s.props||a).dangerouslySetInnerHTML,d=m.dangerouslySetInnerHTML,!h){if(null!=r)for(_={},f=0;f<t.attributes.length;f++)_[t.attributes[f].name]=t.attributes[f].value;(d||u)&&(d&&(u&&d.__html==u.__html||d.__html===t.innerHTML)||(t.innerHTML=d&&d.__html||""))}if(function(t,e,s,i,n){var r;for(r in s)"children"===r||"key"===r||r in e||k(t,r,null,s[r],i);for(r in e)n&&"function"!=typeof e[r]||"children"===r||"key"===r||"value"===r||"checked"===r||s[r]===e[r]||k(t,r,e[r],s[r],i)}(t,m,_,n,h),d)e.__k=[];else if(y=e.props.children,w(t,Array.isArray(y)?y:[y],e,s,i,n&&"foreignObject"!==g,r,o,t.firstChild,h),null!=r)for(y=r.length;y--;)null!=r[y]&&p(r[y]);h||("value"in m&&void 0!==(y=m.value)&&(y!==t.value||"progress"===g&&!y)&&k(t,"value",y,_.value,!1),"checked"in m&&void 0!==(y=m.checked)&&y!==t.checked&&k(t,"checked",y,_.checked,!1))}return t}(i.__e,s,i,n,r,o,h,d);(f=e.diffed)&&f(s)}catch(t){s.__v=null,(d||null!=o)&&(s.__e=u,s.__h=!!d,o[o.indexOf(u)]=null),e.__e(t,s,i)}}function F(t,s){e.__c&&e.__c(s,t),t.some(function(s){try{t=s.__h,s.__h=[],t.some(function(t){t.call(s)})}catch(t){e.__e(t,s.__v)}})}function T(t,s,i){try{"function"==typeof t?t(s):t.current=s}catch(t){e.__e(t,i)}}function D(t,s,i){var n,r,o;if(e.unmount&&e.unmount(t),(n=t.ref)&&(n.current&&n.current!==t.__e||T(n,null,s)),i||"function"==typeof t.type||(i=null!=(r=t.__e)),t.__e=t.__d=void 0,null!=(n=t.__c)){if(n.componentWillUnmount)try{n.componentWillUnmount()}catch(t){e.__e(t,s)}n.base=n.__P=null}if(n=t.__k)for(o=0;o<n.length;o++)n[o]&&D(n[o],s,i);null!=r&&p(r)}function R(t,e,s){return this.constructor(t,s)}function L(t,s,i){var n,r,o;e.__&&e.__(t,s),r=(n="function"==typeof i)?null:i&&i.__k||s.__k,o=[],E(s,t=(!n&&i||s).__k=u(_,null,[t]),r||a,a,void 0!==s.ownerSVGElement,!n&&i?[i]:r?null:s.firstChild?l.slice.call(s.childNodes):null,o,!n&&i?i:r?r.__e:s.firstChild,n),F(o,t)}function I(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})}e={__e:function(t,e){for(var s,i,n;e=e.__;)if((s=e.__c)&&!s.__)try{if((i=s.constructor)&&null!=i.getDerivedStateFromError&&(s.setState(i.getDerivedStateFromError(t)),n=s.__d),null!=s.componentDidCatch&&(s.componentDidCatch(t),n=s.__d),n)return s.__E=s}catch(e){t=e}throw t},__v:0},s=function(t){return null!=t&&void 0===t.constructor},m.prototype.setState=function(t,e){var s;s=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c({},this.state),"function"==typeof t&&(t=t(c({},s),this.props)),t&&c(s,t),null!=t&&this.__v&&(e&&this.__h.push(e),v(this))},m.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),v(this))},m.prototype.render=_,i=[],n="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b.__r=0,o=0;class U{constructor(t){this._id=void 0,this._id=t||I()}get id(){return this._id}}var A,H={search:{placeholder:"Type a keyword..."},sort:{sortAsc:"Sort column ascending",sortDesc:"Sort column descending"},pagination:{previous:"Previous",next:"Next",navigate:(t,e)=>`Page ${t} of ${e}`,page:t=>`Page ${t}`,showing:"Showing",of:"of",to:"to",results:"results"},loading:"Loading...",noRecordsFound:"No matching records found",error:"An error happened while fetching the data"};class M{constructor(t){this._language=void 0,this._defaultLanguage=void 0,this._language=t,this._defaultLanguage=H}getString(t,e){if(!e||!t)return null;const s=t.split("."),i=s[0];if(e[i]){const t=e[i];return"string"==typeof t?()=>t:"function"==typeof t?t:this.getString(s.slice(1).join("."),t)}return null}translate(t,...e){let s;return s=this.getString(t,this._language)||this.getString(t,this._defaultLanguage),s?s(...e):t}}class O extends m{constructor(t,e){var s;super(t,e),this.config=void 0,this._=void 0,this.config=function(t){if(!t)return null;const e=Object.keys(t);return e.length?t[e[0]].props.value:null}(e),this.config&&(this._=(s=this.config.translator,function(t,...e){return s.translate(t,...e)}))}}class $ extends O{render(){return u(this.props.parentElement,{dangerouslySetInnerHTML:{__html:this.props.content}})}}function W(t,e){return u($,{content:t,parentElement:e})}$.defaultProps={parentElement:"span"};class j extends U{constructor(t){super(),this.data=void 0,this.update(t)}cast(t){return t instanceof HTMLElement?W(t.outerHTML):t}update(t){return this.data=this.cast(t),this}}class B extends U{constructor(t){super(),this._cells=void 0,this.cells=t||[]}cell(t){return this._cells[t]}get cells(){return this._cells}set cells(t){this._cells=t}toArray(){return this.cells.map(t=>t.data)}static fromCells(t){return new B(t.map(t=>new j(t.data)))}get length(){return this.cells.length}}class z extends U{constructor(t){super(),this._rows=void 0,this._length=void 0,this.rows=t instanceof Array?t:t instanceof B?[t]:[]}get rows(){return this._rows}set rows(t){this._rows=t}get length(){return this._length||this.rows.length}set length(t){this._length=t}toArray(){return this.rows.map(t=>t.toArray())}static fromRows(t){return new z(t.map(t=>B.fromCells(t.cells)))}static fromArray(t){return t=function(t){return!t[0]||t[0]instanceof Array?t:[t]}(t),new z(t.map(t=>new B(t.map(t=>new j(t)))))}}class q{constructor(){this.callbacks=void 0}init(t){this.callbacks||(this.callbacks={}),t&&!this.callbacks[t]&&(this.callbacks[t]=[])}on(t,e){return this.init(t),this.callbacks[t].push(e),this}off(t,e){const s=t;return this.init(),this.callbacks[s]&&0!==this.callbacks[s].length?(this.callbacks[s]=this.callbacks[s].filter(t=>t!=e),this):this}emit(t,...e){const s=t;return this.init(s),this.callbacks[s].length>0&&(this.callbacks[s].forEach(t=>t(...e)),!0)}}!function(t){t[t.Initiator=0]="Initiator",t[t.ServerFilter=1]="ServerFilter",t[t.ServerSort=2]="ServerSort",t[t.ServerLimit=3]="ServerLimit",t[t.Extractor=4]="Extractor",t[t.Transformer=5]="Transformer",t[t.Filter=6]="Filter",t[t.Sort=7]="Sort",t[t.Limit=8]="Limit"}(A||(A={}));class G extends q{constructor(t){super(),this.id=void 0,this._props=void 0,this._props={},this.id=I(),t&&this.setProps(t)}process(...t){this.validateProps instanceof Function&&this.validateProps(...t),this.emit("beforeProcess",...t);const e=this._process(...t);return this.emit("afterProcess",...t),e}setProps(t){return Object.assign(this._props,t),this.emit("propsUpdated",this),this}get props(){return this._props}}class X extends G{get type(){return A.Filter}_process(t){return this.props.keyword?(e=String(this.props.keyword).trim(),s=this.props.columns,i=this.props.ignoreHiddenColumns,n=t,r=this.props.selector,e=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),new z(n.rows.filter((t,n)=>t.cells.some((t,o)=>{if(!t)return!1;if(i&&s&&s[o]&&"object"==typeof s[o]&&s[o].hidden)return!1;let a="";if("function"==typeof r)a=r(t.data,n,o);else if("object"==typeof t.data){const e=t.data;e&&e.props&&e.props.content&&(a=e.props.content)}else a=String(t.data);return new RegExp(e,"gi").test(a)})))):t;var e,s,i,n,r}}function K(...t){return`gridjs${t.reduce((t,e)=>`${t}-${e}`,"")}`}function V(...t){return t.filter(t=>t).reduce((t,e)=>`${t||""} ${e}`,"").trim()||null}class Y extends q{constructor(t){super(),this._state=void 0,this.dispatcher=void 0,this.dispatcher=t,this._state=this.getInitialState(),t.register(this._handle.bind(this))}_handle(t){this.handle(t.type,t.payload)}setState(t){const e=this._state;this._state=t,this.emit("updated",t,e)}get state(){return this._state}}class Z extends Y{getInitialState(){return{keyword:null}}handle(t,e){if("SEARCH_KEYWORD"===t){const{keyword:t}=e;this.search(t)}}search(t){this.setState({keyword:t})}}class J{constructor(t){this.dispatcher=void 0,this.dispatcher=t}dispatch(t,e){this.dispatcher.dispatch({type:t,payload:e})}}class Q extends J{search(t){this.dispatch("SEARCH_KEYWORD",{keyword:t})}}class tt extends G{get type(){return A.ServerFilter}_process(e){if(!this.props.keyword)return e;const s={};return this.props.url&&(s.url=this.props.url(e.url,this.props.keyword)),this.props.body&&(s.body=this.props.body(e.body,this.props.keyword)),t({},e,s)}}var et,st,it=new class{format(t,e){return`[Grid.js] [${e.toUpperCase()}]: ${t}`}error(t,e=!1){const s=this.format(t,"error");if(e)throw Error(s);console.error(s)}warn(t){console.warn(this.format(t,"warn"))}info(t){console.info(this.format(t,"info"))}};class nt extends O{}!function(t){t[t.Header=0]="Header",t[t.Footer=1]="Footer",t[t.Cell=2]="Cell"}(et||(et={}));class rt{constructor(){this.plugins=void 0,this.plugins=[]}get(t){const e=this.plugins.filter(e=>e.id===t);return e.length>0?e[0]:null}add(t){return t.id?null!==this.get(t.id)?(it.error(`Duplicate plugin ID: ${t.id}`),this):(this.plugins.push(t),this):(it.error("Plugin ID cannot be empty"),this)}remove(t){return this.plugins.splice(this.plugins.indexOf(this.get(t)),1),this}list(t){let e;return e=null!=t||null!=t?this.plugins.filter(e=>e.position===t):this.plugins,e.sort((t,e)=>t.order-e.order)}}class ot extends O{render(){if(this.props.pluginId){const e=this.config.plugin.get(this.props.pluginId);return e?u(_,{},u(e.component,t({plugin:e},e.props,this.props.props))):null}return void 0!==this.props.position?u(_,{},this.config.plugin.list(this.props.position).map(e=>u(e.component,t({plugin:e},e.props,this.props.props)))):null}}class at extends nt{constructor(t,e){super(t,e),this.searchProcessor=void 0,this.actions=void 0,this.store=void 0,this.storeUpdatedFn=void 0,this.actions=new Q(this.config.dispatcher),this.store=new Z(this.config.dispatcher);const{enabled:s,keyword:i}=t;if(s){let e;i&&this.actions.search(i),this.storeUpdatedFn=this.storeUpdated.bind(this),this.store.on("updated",this.storeUpdatedFn),e=t.server?new tt({keyword:t.keyword,url:t.server.url,body:t.server.body}):new X({keyword:t.keyword,columns:this.config.header&&this.config.header.columns,ignoreHiddenColumns:t.ignoreHiddenColumns||void 0===t.ignoreHiddenColumns,selector:t.selector}),this.searchProcessor=e,this.config.pipeline.register(e)}}componentWillUnmount(){this.config.pipeline.unregister(this.searchProcessor),this.store.off("updated",this.storeUpdatedFn)}storeUpdated(t){this.searchProcessor.setProps({keyword:t.keyword})}onChange(t){this.actions.search(t.target.value)}render(){if(!this.props.enabled)return null;let t=this.onChange.bind(this);return this.searchProcessor instanceof tt&&(t=((t,e)=>{let s;return(...i)=>new Promise(n=>{s&&clearTimeout(s),s=setTimeout(()=>n(t(...i)),e)})})(t,this.props.debounceTimeout)),u("div",{className:K(V("search",this.config.className.search))},u("input",{type:"search",placeholder:this._("search.placeholder"),"aria-label":this._("search.placeholder"),onInput:t,className:V(K("input"),K("search","input")),value:this.store.state.keyword}))}}at.defaultProps={debounceTimeout:250};class lt extends G{validateProps(){if(isNaN(Number(this.props.limit))||isNaN(Number(this.props.page)))throw Error("Invalid parameters passed")}get type(){return A.Limit}_process(t){const e=this.props.page;return new z(t.rows.slice(e*this.props.limit,(e+1)*this.props.limit))}}class ht extends G{get type(){return A.ServerLimit}_process(e){const s={};return this.props.url&&(s.url=this.props.url(e.url,this.props.page,this.props.limit)),this.props.body&&(s.body=this.props.body(e.body,this.props.page,this.props.limit)),t({},e,s)}}class ct extends nt{constructor(t,e){super(t,e),this.processor=void 0,this.onUpdateFn=void 0,this.setTotalFromTabularFn=void 0,this.state={limit:t.limit,page:t.page||0,total:0}}componentWillMount(){if(this.props.enabled){let t;this.setTotalFromTabularFn=this.setTotalFromTabular.bind(this),this.props.server?(t=new ht({limit:this.state.limit,page:this.state.page,url:this.props.server.url,body:this.props.server.body}),this.config.pipeline.on("afterProcess",this.setTotalFromTabularFn)):(t=new lt({limit:this.state.limit,page:this.state.page}),t.on("beforeProcess",this.setTotalFromTabularFn)),this.processor=t,this.config.pipeline.register(t),this.config.pipeline.on("error",()=>{this.setState({total:0,page:0})})}}setTotalFromTabular(t){this.setTotal(t.length)}onUpdate(t){this.props.resetPageOnUpdate&&t!==this.processor&&this.setPage(0)}componentDidMount(){this.onUpdateFn=this.onUpdate.bind(this),this.config.pipeline.on("updated",this.onUpdateFn)}componentWillUnmount(){this.config.pipeline.unregister(this.processor),this.config.pipeline.off("updated",this.onUpdateFn)}get pages(){return Math.ceil(this.state.total/this.state.limit)}setPage(t){if(t>=this.pages||t<0||t===this.state.page)return null;this.setState({page:t}),this.processor.setProps({page:t})}setTotal(t){this.setState({total:t})}renderPages(){if(this.props.buttonsCount<=0)return null;const t=Math.min(this.pages,this.props.buttonsCount);let e=Math.min(this.state.page,Math.floor(t/2));return this.state.page+Math.floor(t/2)>=this.pages&&(e=t-(this.pages-this.state.page)),u(_,null,this.pages>t&&this.state.page-e>0&&u(_,null,u("button",{tabIndex:0,role:"button",onClick:this.setPage.bind(this,0),title:this._("pagination.firstPage"),"aria-label":this._("pagination.firstPage"),className:this.config.className.paginationButton},this._("1")),u("button",{tabIndex:-1,className:V(K("spread"),this.config.className.paginationButton)},"...")),Array.from(Array(t).keys()).map(t=>this.state.page+(t-e)).map(t=>u("button",{tabIndex:0,role:"button",onClick:this.setPage.bind(this,t),className:V(this.state.page===t?V(K("currentPage"),this.config.className.paginationButtonCurrent):null,this.config.className.paginationButton),title:this._("pagination.page",t+1),"aria-label":this._("pagination.page",t+1)},this._(`${t+1}`))),this.pages>t&&this.pages>this.state.page+e+1&&u(_,null,u("button",{tabIndex:-1,className:V(K("spread"),this.config.className.paginationButton)},"..."),u("button",{tabIndex:0,role:"button",onClick:this.setPage.bind(this,this.pages-1),title:this._("pagination.page",this.pages),"aria-label":this._("pagination.page",this.pages),className:this.config.className.paginationButton},this._(`${this.pages}`))))}renderSummary(){return u(_,null,this.props.summary&&this.state.total>0&&u("div",{role:"status","aria-live":"polite",className:V(K("summary"),this.config.className.paginationSummary),title:this._("pagination.navigate",this.state.page+1,this.pages)},this._("pagination.showing")," ",u("b",null,this._(""+(this.state.page*this.state.limit+1)))," ",this._("pagination.to")," ",u("b",null,this._(`${Math.min((this.state.page+1)*this.state.limit,this.state.total)}`))," ",this._("pagination.of")," ",u("b",null,this._(`${this.state.total}`))," ",this._("pagination.results")))}render(){return this.props.enabled?u("div",{className:V(K("pagination"),this.config.className.pagination)},this.renderSummary(),u("div",{className:K("pages")},this.props.prevButton&&u("button",{tabIndex:0,role:"button",disabled:0===this.state.page,onClick:this.setPage.bind(this,this.state.page-1),title:this._("pagination.previous"),"aria-label":this._("pagination.previous"),className:V(this.config.className.paginationButton,this.config.className.paginationButtonPrev)},this._("pagination.previous")),this.renderPages(),this.props.nextButton&&u("button",{tabIndex:0,role:"button",disabled:this.pages===this.state.page+1||0===this.pages,onClick:this.setPage.bind(this,this.state.page+1),title:this._("pagination.next"),"aria-label":this._("pagination.next"),className:V(this.config.className.paginationButton,this.config.className.paginationButtonNext)},this._("pagination.next")))):null}}function pt(t,e){return"string"==typeof t?t.indexOf("%")>-1?e/100*parseInt(t,10):parseInt(t,10):t}function ut(t){return t?`${Math.floor(t)}px`:""}ct.defaultProps={summary:!0,nextButton:!0,prevButton:!0,buttonsCount:3,limit:10,resetPageOnUpdate:!0};class dt extends O{constructor(t,e){super(t,e),this.tableElement=void 0,this.tableClassName=void 0,this.tableStyle=void 0,this.tableElement=this.props.tableRef.current.base.cloneNode(!0),this.tableElement.style.position="absolute",this.tableElement.style.width="100%",this.tableElement.style.zIndex="-2147483640",this.tableElement.style.visibility="hidden",this.tableClassName=this.tableElement.className,this.tableStyle=this.tableElement.style.cssText}widths(){this.tableElement.className=`${this.tableClassName} ${K("shadowTable")}`,this.tableElement.style.tableLayout="auto",this.tableElement.style.width="auto",this.tableElement.style.padding="0",this.tableElement.style.margin="0",this.tableElement.style.border="none",this.tableElement.style.outline="none";let e=Array.from(this.base.parentNode.querySelectorAll("thead th")).reduce((e,s)=>(s.style.width=`${s.clientWidth}px`,t({[s.getAttribute("data-column-id")]:{minWidth:s.clientWidth}},e)),{});return this.tableElement.className=this.tableClassName,this.tableElement.style.cssText=this.tableStyle,this.tableElement.style.tableLayout="auto",e=Array.from(this.base.parentNode.querySelectorAll("thead th")).reduce((t,e)=>(t[e.getAttribute("data-column-id")].width=e.clientWidth,t),e),e}render(){return this.props.tableRef.current?u("div",{ref:t=>{t&&t.appendChild(this.tableElement)}}):null}}function ft(t){if(!t)return"";const e=t.split(" ");return 1===e.length&&/([a-z][A-Z])+/g.test(t)?t:e.map(function(t,e){return 0==e?t.toLowerCase():t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}).join("")}class _t extends U{constructor(){super(),this._columns=void 0,this._columns=[]}get columns(){return this._columns}set columns(t){this._columns=t}get visibleColumns(){return this._columns.filter(t=>!t.hidden)}adjustWidth(t){const e=t.container,s=t.tableRef,i=t.tempRef,n=t.tempRef||!0;if(!e)return this;const r=e.clientWidth,o={current:null};let a={};if(s.current&&n){const t=u(dt,{tableRef:s});t.ref=o,L(t,i.current),a=o.current.widths()}for(const t of _t.tabularFormat(this.columns).reduce((t,e)=>t.concat(e),[]))t.columns&&t.columns.length>0||(!t.width&&n?t.id in a&&(t.width=ut(a[t.id].width),t.minWidth=ut(a[t.id].minWidth)):t.width=ut(pt(t.width,r)));return s.current&&n&&L(null,i.current),this}setSort(e,s){const i=s||this.columns||[];for(const s of i)s.columns&&s.columns.length>0&&(s.sort={enabled:!1}),void 0===s.sort&&e.sort&&(s.sort={enabled:!0}),s.sort?"object"==typeof s.sort&&(s.sort=t({enabled:!0},s.sort)):s.sort={enabled:!1},s.columns&&this.setSort(e,s.columns)}setFixedHeader(t,e){const s=e||this.columns||[];for(const e of s)void 0===e.fixedHeader&&(e.fixedHeader=t.fixedHeader),e.columns&&this.setFixedHeader(t,e.columns)}setResizable(t,e){const s=e||this.columns||[];for(const e of s)void 0===e.resizable&&(e.resizable=t.resizable),e.columns&&this.setResizable(t,e.columns)}setID(t){const e=t||this.columns||[];for(const t of e)t.id||"string"!=typeof t.name||(t.id=ft(t.name)),t.id||it.error('Could not find a valid ID for one of the columns. Make sure a valid "id" is set for all columns.'),t.columns&&this.setID(t.columns)}populatePlugins(e,s){for(const i of s)void 0!==i.plugin&&e.plugin.add(t({id:i.id,props:{}},i.plugin,{position:et.Cell}))}static fromColumns(t){const e=new _t;for(const i of t)if("string"==typeof i||s(i))e.columns.push({name:i});else if("object"==typeof i){const t=i;t.columns&&(t.columns=_t.fromColumns(t.columns).columns),"object"==typeof t.plugin&&void 0===t.data&&(t.data=null),e.columns.push(i)}return e}static fromUserConfig(t){const e=new _t;return t.from?e.columns=_t.fromHTMLTable(t.from).columns:t.columns?e.columns=_t.fromColumns(t.columns).columns:!t.data||"object"!=typeof t.data[0]||t.data[0]instanceof Array||(e.columns=Object.keys(t.data[0]).map(t=>({name:t}))),e.columns.length?(e.setID(),e.setSort(t),e.setFixedHeader(t),e.setResizable(t),e.populatePlugins(t,e.columns),e):null}static fromHTMLTable(t){const e=new _t,s=t.querySelector("thead").querySelectorAll("th");for(const t of s)e.columns.push({name:t.innerHTML,width:t.width});return e}static tabularFormat(t){let e=[];const s=t||[];let i=[];if(s&&s.length){e.push(s);for(const t of s)t.columns&&t.columns.length&&(i=i.concat(t.columns));i.length&&(e=e.concat(this.tabularFormat(i)))}return e}static leafColumns(t){let e=[];const s=t||[];if(s&&s.length)for(const t of s)t.columns&&0!==t.columns.length||e.push(t),t.columns&&(e=e.concat(this.leafColumns(t.columns)));return e}static maximumDepth(t){return this.tabularFormat([t]).length-1}}class mt{constructor(){this._callbacks=void 0,this._isDispatching=void 0,this._isHandled=void 0,this._isPending=void 0,this._lastID=void 0,this._pendingPayload=void 0,this._callbacks={},this._isDispatching=!1,this._isHandled={},this._isPending={},this._lastID=1}register(t){const e="ID_"+this._lastID++;return this._callbacks[e]=t,e}unregister(t){if(!this._callbacks[t])throw Error(`Dispatcher.unregister(...): ${t} does not map to a registered callback.`);delete this._callbacks[t]}waitFor(t){if(!this._isDispatching)throw Error("Dispatcher.waitFor(...): Must be invoked while dispatching.");for(let e=0;e<t.length;e++){const s=t[e];if(this._isPending[s]){if(!this._isHandled[s])throw Error(`Dispatcher.waitFor(...): Circular dependency detected while ' +\n 'waiting for ${s}.`)}else{if(!this._callbacks[s])throw Error(`Dispatcher.waitFor(...): ${s} does not map to a registered callback.`);this._invokeCallback(s)}}}dispatch(t){if(this._isDispatching)throw Error("Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch.");this._startDispatching(t);try{for(const t in this._callbacks)this._isPending[t]||this._invokeCallback(t)}finally{this._stopDispatching()}}isDispatching(){return this._isDispatching}_invokeCallback(t){this._isPending[t]=!0,this._callbacks[t](this._pendingPayload),this._isHandled[t]=!0}_startDispatching(t){for(const t in this._callbacks)this._isPending[t]=!1,this._isHandled[t]=!1;this._pendingPayload=t,this._isDispatching=!0}_stopDispatching(){delete this._pendingPayload,this._isDispatching=!1}}class gt{}class yt extends gt{constructor(t){super(),this.data=void 0,this.set(t)}async get(){const t=await this.data();return{data:t,total:t.length}}set(t){return t instanceof Array?this.data=()=>t:t instanceof Function&&(this.data=t),this}}class vt extends gt{constructor(t){super(),this.options=void 0,this.options=t}handler(t){return"function"==typeof this.options.handle?this.options.handle(t):t.ok?t.json():(it.error(`Could not fetch data: ${t.status} - ${t.statusText}`,!0),null)}get(e){const s=t({},this.options,e);return"function"==typeof s.data?s.data(s):fetch(s.url,s).then(this.handler.bind(this)).then(t=>({data:s.then(t),total:"function"==typeof s.total?s.total(t):void 0}))}}class bt{static createFromUserConfig(t){let e=null;return t.data&&(e=new yt(t.data)),t.from&&(e=new yt(this.tableElementToArray(t.from)),t.from.style.display="none"),t.server&&(e=new vt(t.server)),e||it.error("Could not determine the storage type",!0),e}static tableElementToArray(t){const e=[],s=t.querySelector("tbody").querySelectorAll("tr");for(const t of s){const s=t.querySelectorAll("td"),n=[];for(const t of s)1===t.childNodes.length&&t.childNodes[0].nodeType===Node.TEXT_NODE?n.push((i=t.innerHTML,(new DOMParser).parseFromString(i,"text/html").documentElement.textContent)):n.push(W(t.innerHTML));e.push(n)}var i;return e}}class wt extends q{constructor(t){super(),this._steps=new Map,this.cache=new Map,this.lastProcessorIndexUpdated=-1,t&&t.forEach(t=>this.register(t))}clearCache(){this.cache=new Map,this.lastProcessorIndexUpdated=-1}register(t,e=null){if(null===t.type)throw Error("Processor type is not defined");t.on("propsUpdated",this.processorPropsUpdated.bind(this)),this.addProcessorByPriority(t,e),this.afterRegistered(t)}unregister(t){if(!t)return;const e=this._steps.get(t.type);e&&e.length&&(this._steps.set(t.type,e.filter(e=>e!=t)),this.emit("updated",t))}addProcessorByPriority(t,e){let s=this._steps.get(t.type);if(!s){const e=[];this._steps.set(t.type,e),s=e}if(null===e||e<0)s.push(t);else if(s[e]){const i=s.slice(0,e-1),n=s.slice(e+1);this._steps.set(t.type,i.concat(t).concat(n))}else s[e]=t}get steps(){let t=[];for(const e of this.getSortedProcessorTypes()){const s=this._steps.get(e);s&&s.length&&(t=t.concat(s))}return t.filter(t=>t)}getStepsByType(t){return this.steps.filter(e=>e.type===t)}getSortedProcessorTypes(){return Object.keys(A).filter(t=>!isNaN(Number(t))).map(t=>Number(t))}async process(t){const e=this.lastProcessorIndexUpdated,s=this.steps;let i=t;try{for(const t of s)this.findProcessorIndexByID(t.id)>=e?(i=await t.process(i),this.cache.set(t.id,i)):i=this.cache.get(t.id)}catch(t){throw it.error(t),this.emit("error",i),t}return this.lastProcessorIndexUpdated=s.length,this.emit("afterProcess",i),i}findProcessorIndexByID(t){return this.steps.findIndex(e=>e.id==t)}setLastProcessorIndex(t){const e=this.findProcessorIndexByID(t.id);this.lastProcessorIndexUpdated>e&&(this.lastProcessorIndexUpdated=e)}processorPropsUpdated(t){this.setLastProcessorIndex(t),this.emit("propsUpdated"),this.emit("updated",t)}afterRegistered(t){this.setLastProcessorIndex(t),this.emit("afterRegister"),this.emit("updated",t)}}class xt extends G{get type(){return A.Extractor}async _process(t){return await this.props.storage.get(t)}}class St extends G{get type(){return A.Transformer}_process(t){const e=z.fromArray(t.data);return e.length=t.total,e}}class Ct extends G{get type(){return A.Initiator}_process(){return Object.entries(this.props.serverStorageOptions).filter(([t,e])=>"function"!=typeof e).reduce((e,[s,i])=>t({},e,{[s]:i}),{})}}class kt extends G{get type(){return A.Transformer}castData(t){if(!t||!t.length)return[];if(!this.props.header||!this.props.header.columns)return t;const e=_t.leafColumns(this.props.header.columns);return t[0]instanceof Array?t.map(t=>{let s=0;return e.map((e,i)=>void 0!==e.data?(s++,"function"==typeof e.data?e.data(t):e.data):t[i-s])}):"object"!=typeof t[0]||t[0]instanceof Array?[]:t.map(t=>e.map((e,s)=>void 0!==e.data?"function"==typeof e.data?e.data(t):e.data:e.id?t[e.id]:(it.error(`Could not find the correct cell for column at position ${s}.\n Make sure either 'id' or 'selector' is defined for all columns.`),null)))}_process(t){return{data:this.castData(t.data),total:t.total}}}class Pt{static createFromConfig(t){const e=new wt;return t.storage instanceof vt&&e.register(new Ct({serverStorageOptions:t.server})),e.register(new xt({storage:t.storage})),e.register(new kt({header:t.header})),e.register(new St),e}}class Nt{constructor(e){this._userConfig=void 0,Object.assign(this,t({},Nt.defaultConfig(),e)),this._userConfig={}}assign(t){for(const e of Object.keys(t))"_userConfig"!==e&&(this[e]=t[e]);return this}update(e){return e?(this._userConfig=t({},this._userConfig,e),this.assign(Nt.fromUserConfig(this._userConfig)),this):this}static defaultConfig(){return{plugin:new rt,dispatcher:new mt,tableRef:{current:null},tempRef:{current:null},width:"100%",height:"auto",autoWidth:!0,style:{},className:{}}}static fromUserConfig(e){const s=new Nt(e);return s._userConfig=e,"boolean"==typeof e.sort&&e.sort&&s.assign({sort:{multiColumn:!0}}),s.assign({header:_t.fromUserConfig(s)}),s.assign({storage:bt.createFromUserConfig(e)}),s.assign({pipeline:Pt.createFromConfig(s)}),s.assign({translator:new M(e.language)}),s.plugin.add({id:"search",position:et.Header,component:at,props:t({enabled:!0===e.search||e.search instanceof Object},e.search)}),s.plugin.add({id:"pagination",position:et.Footer,component:ct,props:t({enabled:!0===e.pagination||e.pagination instanceof Object},e.pagination)}),e.plugins&&e.plugins.forEach(t=>s.plugin.add(t)),s}}!function(t){t[t.Init=0]="Init",t[t.Loading=1]="Loading",t[t.Loaded=2]="Loaded",t[t.Rendered=3]="Rendered",t[t.Error=4]="Error"}(st||(st={}));class Et extends O{content(){return this.props.column&&"function"==typeof this.props.column.formatter?this.props.column.formatter(this.props.cell.data,this.props.row,this.props.column):this.props.column&&this.props.column.plugin?u(ot,{pluginId:this.props.column.id,props:{column:this.props.column,cell:this.props.cell,row:this.props.row}}):this.props.cell.data}handleClick(t){this.props.messageCell||this.config.eventEmitter.emit("cellClick",t,this.props.cell,this.props.column,this.props.row)}getCustomAttributes(t){return t?"function"==typeof t.attributes?t.attributes(this.props.cell.data,this.props.row,this.props.column):t.attributes:{}}render(){return u("td",t({role:this.props.role,colSpan:this.props.colSpan,"data-column-id":this.props.column&&this.props.column.id,className:V(K("td"),this.props.className,this.config.className.td),style:t({},this.props.style,this.config.style.td),onClick:this.handleClick.bind(this)},this.getCustomAttributes(this.props.column)),this.content())}}class Ft extends O{getColumn(t){if(this.props.header){const e=_t.leafColumns(this.props.header.columns);if(e)return e[t]}return null}handleClick(t){this.props.messageRow||this.config.eventEmitter.emit("rowClick",t,this.props.row)}getChildren(){return this.props.children?this.props.children:u(_,null,this.props.row.cells.map((t,e)=>{const s=this.getColumn(e);return s&&s.hidden?null:u(Et,{key:t.id,cell:t,row:this.props.row,column:s})}))}render(){return u("tr",{className:V(K("tr"),this.config.className.tr),onClick:this.handleClick.bind(this)},this.getChildren())}}class Tt extends O{render(){return u(Ft,{messageRow:!0},u(Et,{role:"alert",colSpan:this.props.colSpan,messageCell:!0,cell:new j(this.props.message),className:V(K("message"),this.props.className?this.props.className:null)}))}}class Dt extends O{headerLength(){return this.props.header?this.props.header.visibleColumns.length:0}render(){return u("tbody",{className:V(K("tbody"),this.config.className.tbody)},this.props.data&&this.props.data.rows.map(t=>u(Ft,{key:t.id,row:t,header:this.props.header})),this.props.status===st.Loading&&(!this.props.data||0===this.props.data.length)&&u(Tt,{message:this._("loading"),colSpan:this.headerLength(),className:V(K("loading"),this.config.className.loading)}),this.props.status===st.Rendered&&this.props.data&&0===this.props.data.length&&u(Tt,{message:this._("noRecordsFound"),colSpan:this.headerLength(),className:V(K("notfound"),this.config.className.notfound)}),this.props.status===st.Error&&u(Tt,{message:this._("error"),colSpan:this.headerLength(),className:V(K("error"),this.config.className.error)}))}}class Rt extends G{validateProps(){for(const t of this.props.columns)void 0===t.direction&&(t.direction=1),1!==t.direction&&-1!==t.direction&&it.error(`Invalid sort direction ${t.direction}`)}get type(){return A.Sort}compare(t,e){return t>e?1:t<e?-1:0}compareWrapper(t,e){let s=0;for(const i of this.props.columns){if(0!==s)break;{const n=t.cells[i.index].data,r=e.cells[i.index].data;s|="function"==typeof i.compare?i.compare(n,r)*i.direction:this.compare(n,r)*i.direction}}return s}_process(t){const e=[...t.rows];e.sort(this.compareWrapper.bind(this));const s=new z(e);return s.length=t.length,s}}class Lt extends Y{getInitialState(){return[]}handle(t,e){if("SORT_COLUMN"===t){const{index:t,direction:s,multi:i,compare:n}=e;this.sortColumn(t,s,i,n)}else if("SORT_COLUMN_TOGGLE"===t){const{index:t,multi:s,compare:i}=e;this.sortToggle(t,s,i)}}sortToggle(t,e,s){const i=[...this.state].find(e=>e.index===t);this.sortColumn(t,i&&1===i.direction?-1:1,e,s)}sortColumn(t,e,s,i){let n=[...this.state];const r=n.length,o=n.find(e=>e.index===t);let a=!1,l=!1,h=!1,c=!1;if(void 0!==o?s?-1===o.direction?h=!0:c=!0:1===r?c=!0:r>1&&(l=!0,a=!0):0===r?a=!0:r>0&&!s?(a=!0,l=!0):r>0&&s&&(a=!0),l&&(n=[]),a)n.push({index:t,direction:e,compare:i});else if(c){const t=n.indexOf(o);n[t].direction=e}else if(h){const t=n.indexOf(o);n.splice(t,1)}this.setState(n)}}class It extends J{sortColumn(t,e,s,i){this.dispatch("SORT_COLUMN",{index:t,direction:e,multi:s,compare:i})}sortToggle(t,e,s){this.dispatch("SORT_COLUMN_TOGGLE",{index:t,multi:e,compare:s})}}class Ut extends G{get type(){return A.ServerSort}_process(e){const s={};return this.props.url&&(s.url=this.props.url(e.url,this.props.columns)),this.props.body&&(s.body=this.props.body(e.body,this.props.columns)),t({},e,s)}}class At extends O{constructor(t,e){super(t,e),this.sortProcessor=void 0,this.actions=void 0,this.store=void 0,this.updateStateFn=void 0,this.updateSortProcessorFn=void 0,this.actions=new It(this.config.dispatcher),this.store=new Lt(this.config.dispatcher),t.enabled&&(this.sortProcessor=this.getOrCreateSortProcessor(),this.updateStateFn=this.updateState.bind(this),this.store.on("updated",this.updateStateFn),this.state={direction:0})}componentWillUnmount(){this.config.pipeline.unregister(this.sortProcessor),this.store.off("updated",this.updateStateFn),this.updateSortProcessorFn&&this.store.off("updated",this.updateSortProcessorFn)}updateState(){const t=this.store.state.find(t=>t.index===this.props.index);this.setState(t?{direction:t.direction}:{direction:0})}updateSortProcessor(t){this.sortProcessor.setProps({columns:t})}getOrCreateSortProcessor(){let e=A.Sort;this.config.sort&&"object"==typeof this.config.sort.server&&(e=A.ServerSort);const s=this.config.pipeline.getStepsByType(e);let i;return s.length>0?i=s[0]:(this.updateSortProcessorFn=this.updateSortProcessor.bind(this),this.store.on("updated",this.updateSortProcessorFn),i=e===A.ServerSort?new Ut(t({columns:this.store.state},this.config.sort.server)):new Rt({columns:this.store.state}),this.config.pipeline.register(i)),i}changeDirection(t){t.preventDefault(),t.stopPropagation(),this.actions.sortToggle(this.props.index,!0===t.shiftKey&&this.config.sort.multiColumn,this.props.compare)}render(){if(!this.props.enabled)return null;const t=this.state.direction;let e="neutral";return 1===t?e="asc":-1===t&&(e="desc"),u("button",{tabIndex:-1,"aria-label":this._("sort.sort"+(1===t?"Desc":"Asc")),title:this._("sort.sort"+(1===t?"Desc":"Asc")),className:V(K("sort"),K("sort",e),this.config.className.sort),onClick:this.changeDirection.bind(this)})}}class Ht extends O{constructor(...t){super(...t),this.moveFn=void 0,this.upFn=void 0}getPageX(t){return t instanceof MouseEvent?Math.floor(t.pageX):Math.floor(t.changedTouches[0].pageX)}start(t){t.stopPropagation(),this.setState({offsetStart:parseInt(this.props.thRef.current.style.width,10)-this.getPageX(t)}),this.upFn=this.end.bind(this),this.moveFn=((t,e=100)=>{let s,i,n;return(...r)=>{s?(clearTimeout(i),i=setTimeout(()=>{Date.now()-n>=e&&(t(...r),n=Date.now())},Math.max(e-(Date.now()-n),0))):(t(...r),n=Date.now(),s=!0)}})(this.move.bind(this),10),document.addEventListener("mouseup",this.upFn),document.addEventListener("touchend",this.upFn),document.addEventListener("mousemove",this.moveFn),document.addEventListener("touchmove",this.moveFn)}move(t){t.stopPropagation();const e=this.props.thRef.current;this.state.offsetStart+this.getPageX(t)>=parseInt(e.style.minWidth,10)&&(e.style.width=`${this.state.offsetStart+this.getPageX(t)}px`)}end(t){t.stopPropagation(),document.removeEventListener("mouseup",this.upFn),document.removeEventListener("mousemove",this.moveFn),document.removeEventListener("touchmove",this.moveFn),document.removeEventListener("touchend",this.upFn)}render(){return u("div",{className:V(K("th"),K("resizable")),onMouseDown:this.start.bind(this),onTouchStart:this.start.bind(this),onClick:t=>t.stopPropagation()})}}class Mt extends O{constructor(t,e){super(t,e),this.sortRef={current:null},this.thRef={current:null},this.state={style:{}}}isSortable(){return this.props.column.sort.enabled}isResizable(){return this.props.column.resizable}onClick(t){t.stopPropagation(),this.isSortable()&&this.sortRef.current.changeDirection(t)}keyDown(t){this.isSortable()&&13===t.which&&this.onClick(t)}componentDidMount(){setTimeout(()=>{if(this.props.column.fixedHeader&&this.thRef.current){const t=this.thRef.current.offsetTop;"number"==typeof t&&this.setState({style:{top:t}})}},0)}content(){return void 0!==this.props.column.name?this.props.column.name:void 0!==this.props.column.plugin?u(ot,{pluginId:this.props.column.plugin.id,props:{column:this.props.column}}):null}getCustomAttributes(){const t=this.props.column;return t?"function"==typeof t.attributes?t.attributes(null,null,this.props.column):t.attributes:{}}render(){const e={};return this.isSortable()&&(e.tabIndex=0),u("th",t({ref:this.thRef,"data-column-id":this.props.column&&this.props.column.id,className:V(K("th"),this.isSortable()?K("th","sort"):null,this.props.column.fixedHeader?K("th","fixed"):null,this.config.className.th),onClick:this.onClick.bind(this),style:t({},this.config.style.th,{minWidth:this.props.column.minWidth,width:this.props.column.width},this.state.style,this.props.style),onKeyDown:this.keyDown.bind(this),rowSpan:this.props.rowSpan>1?this.props.rowSpan:void 0,colSpan:this.props.colSpan>1?this.props.colSpan:void 0},this.getCustomAttributes(),e),u("div",{className:K("th","content")},this.content()),this.isSortable()&&u(At,t({ref:this.sortRef,index:this.props.index},this.props.column.sort)),this.isResizable()&&this.props.index<this.config.header.visibleColumns.length-1&&u(Ht,{column:this.props.column,thRef:this.thRef}))}}class Ot extends O{renderColumn(t,e,s,i){const{rowSpan:n,colSpan:r}=function(t,e,s){const i=_t.maximumDepth(t),n=s-e;return{rowSpan:Math.floor(n-i-i/n),colSpan:t.columns&&t.columns.length||1}}(t,e,i);return u(Mt,{column:t,index:s,colSpan:r,rowSpan:n})}renderRow(t,e,s){const i=_t.leafColumns(this.props.header.columns);return u(Ft,null,t.map(t=>t.hidden?null:this.renderColumn(t,e,i.indexOf(t),s)))}renderRows(){const t=_t.tabularFormat(this.props.header.columns);return t.map((e,s)=>this.renderRow(e,s,t.length))}render(){return this.props.header?u("thead",{key:this.props.header.id,className:V(K("thead"),this.config.className.thead)},this.renderRows()):null}}class $t extends O{render(){return u("table",{role:"grid",className:V(K("table"),this.config.className.table),style:t({},this.config.style.table,{height:this.props.height})},u(Ot,{header:this.props.header}),u(Dt,{data:this.props.data,status:this.props.status,header:this.props.header}))}}class Wt extends O{constructor(t,e){super(t,e),this.headerRef={current:null},this.state={isActive:!0}}componentDidMount(){0===this.headerRef.current.children.length&&this.setState({isActive:!1})}render(){return this.state.isActive?u("div",{ref:this.headerRef,className:V(K("head"),this.config.className.header),style:t({},this.config.style.header)},u(ot,{position:et.Header})):null}}class jt extends O{constructor(t,e){super(t,e),this.footerRef={current:null},this.state={isActive:!0}}componentDidMount(){0===this.footerRef.current.children.length&&this.setState({isActive:!1})}render(){return this.state.isActive?u("div",{ref:this.footerRef,className:V(K("footer"),this.config.className.footer),style:t({},this.config.style.footer)},u(ot,{position:et.Footer})):null}}class Bt extends O{constructor(t,e){super(t,e),this.configContext=void 0,this.processPipelineFn=void 0,this.configContext=function(t,e){var s={__c:e="__cC"+o++,__:null,Consumer:function(t,e){return t.children(e)},Provider:function(t){var s,i;return this.getChildContext||(s=[],(i={})[e]=this,this.getChildContext=function(){return i},this.shouldComponentUpdate=function(t){this.props.value!==t.value&&s.some(v)},this.sub=function(t){s.push(t);var e=t.componentWillUnmount;t.componentWillUnmount=function(){s.splice(s.indexOf(t),1),e&&e.call(t)}}),t.children}};return s.Provider.__=s.Consumer.contextType=s}(),this.state={status:st.Loading,header:t.header,data:null}}async processPipeline(){this.props.config.eventEmitter.emit("beforeLoad"),this.setState({status:st.Loading});try{const t=await this.props.pipeline.process();this.setState({data:t,status:st.Loaded}),this.props.config.eventEmitter.emit("load",t)}catch(t){it.error(t),this.setState({status:st.Error,data:null})}}async componentDidMount(){const t=this.props.config;await this.processPipeline(),t.header&&this.state.data&&this.state.data.length&&this.setState({header:t.header.adjustWidth(t)}),this.processPipelineFn=this.processPipeline.bind(this),this.props.pipeline.on("updated",this.processPipelineFn)}componentWillUnmount(){this.props.pipeline.off("updated",this.processPipelineFn)}componentDidUpdate(t,e){e.status!=st.Rendered&&this.state.status==st.Loaded&&(this.setState({status:st.Rendered}),this.props.config.eventEmitter.emit("ready"))}render(){return u(this.configContext.Provider,{value:this.props.config},u("div",{role:"complementary",className:V("gridjs",K("container"),this.state.status===st.Loading?K("loading"):null,this.props.config.className.container),style:t({},this.props.config.style.container,{width:this.props.width})},this.state.status===st.Loading&&u("div",{className:K("loading-bar")}),u(Wt,null),u("div",{className:K("wrapper"),style:{height:this.props.height}},u($t,{ref:this.props.config.tableRef,data:this.state.data,header:this.state.header,width:this.props.width,height:this.props.height,status:this.state.status})),u(jt,null),u("div",{ref:this.props.config.tempRef,id:"gridjs-temp",className:K("temp")})))}}class zt extends q{constructor(t){super(),this.config=void 0,this.plugin=void 0,this.config=new Nt({instance:this,eventEmitter:this}).update(t),this.plugin=this.config.plugin}updateConfig(t){return this.config.update(t),this}createElement(){return u(Bt,{config:this.config,pipeline:this.config.pipeline,header:this.config.header,width:this.config.width,height:this.config.height})}forceRender(){return this.config&&this.config.container||it.error("Container is empty. Make sure you call render() before forceRender()",!0),this.config.pipeline.clearCache(),L(null,this.config.container),L(this.createElement(),this.config.container),this}render(t){return t||it.error("Container element cannot be null",!0),t.childNodes.length>0?(it.error(`The container element ${t} is not empty. Make sure the container is empty and call render() again`),this):(this.config.container=t,L(this.createElement(),t),this)}}var qt,Gt,Xt,Kt=0,Vt=[],Yt=e.__b,Zt=e.__r,Jt=e.diffed,Qt=e.__c,te=e.unmount;function ee(t,s){e.__h&&e.__h(Gt,t,Kt||s),Kt=0;var i=Gt.__H||(Gt.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({}),i.__[t]}function se(t,s){var i=ee(qt++,3);!e.__s&&le(i.__H,s)&&(i.__=t,i.__H=s,Gt.__H.__h.push(i))}function ie(t){return Kt=5,function(t,e){var s=ee(qt++,7);return le(s.__H,e)&&(s.__=t(),s.__H=e,s.__h=t),s.__}(function(){return{current:t}},[])}function ne(){Vt.forEach(function(t){if(t.__P)try{t.__H.__h.forEach(oe),t.__H.__h.forEach(ae),t.__H.__h=[]}catch(s){t.__H.__h=[],e.__e(s,t.__v)}}),Vt=[]}e.__b=function(t){Gt=null,Yt&&Yt(t)},e.__r=function(t){Zt&&Zt(t),qt=0;var e=(Gt=t.__c).__H;e&&(e.__h.forEach(oe),e.__h.forEach(ae),e.__h=[])},e.diffed=function(t){Jt&&Jt(t);var s=t.__c;s&&s.__H&&s.__H.__h.length&&(1!==Vt.push(s)&&Xt===e.requestAnimationFrame||((Xt=e.requestAnimationFrame)||function(t){var e,s=function(){clearTimeout(i),re&&cancelAnimationFrame(e),setTimeout(t)},i=setTimeout(s,100);re&&(e=requestAnimationFrame(s))})(ne)),Gt=void 0},e.__c=function(t,s){s.some(function(t){try{t.__h.forEach(oe),t.__h=t.__h.filter(function(t){return!t.__||ae(t)})}catch(i){s.some(function(t){t.__h&&(t.__h=[])}),s=[],e.__e(i,t.__v)}}),Qt&&Qt(t,s)},e.unmount=function(t){te&&te(t);var s=t.__c;if(s&&s.__H)try{s.__H.__.forEach(oe)}catch(t){e.__e(t,s.__v)}};var re="function"==typeof requestAnimationFrame;function oe(t){var e=Gt;"function"==typeof t.__c&&t.__c(),Gt=e}function ae(t){var e=Gt;t.__c=t.__(),Gt=e}function le(t,e){return!t||t.length!==e.length||e.some(function(e,s){return e!==t[s]})}export{J as BaseActions,O as BaseComponent,Y as BaseStore,j as Cell,m as Component,Nt as Config,mt as Dispatcher,zt as Grid,nt as PluginBaseComponent,et as PluginPosition,B as Row,K as className,u as createElement,f as createRef,u as h,W as html,se as useEffect,ie as useRef};
2//# sourceMappingURL=gridjs.modern.js.map