UNPKG

16.2 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("prop-types"),require("react"),require("react-dom"),require("ag-grid-community"),require("react-dom/server")):"function"==typeof define&&define.amd?define(["exports","prop-types","react","react-dom","ag-grid-community","react-dom/server"],e):e(t.AgGridReact={},t.PropTypes,t.React,t.ReactDOM,t.agGrid,t.ReactDOMServer)}(this,function(e,t,o,r,a,i){"use strict";var s=function(t,e){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function n(t,e){function n(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var p=function(){return(p=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};var c,l=(n(u,c=o.Component),u.prototype.render=function(){return null},u.mapChildColumnDefs=function(t){return o.Children.map(t,function(t){return t?u.toColDef(t.props):null})},u.toColDef=function(t){var e=t.children,t=function(t,e){var n={};for(o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]]);return n}(t,["children"]);return u.hasChildColumns(e)&&(t.children=u.mapChildColumnDefs(e)),t},u.hasChildColumns=function(t){return 0<o.Children.count(t)},u);function u(t){var e=c.call(this,t)||this;return e.props=t,e}function h(t,e){t.forEach(function(t){l[t]=e})}h(a.ColDefUtil.BOOLEAN_PROPERTIES,t.bool),h(a.ColDefUtil.STRING_PROPERTIES,t.string),h(a.ColDefUtil.OBJECT_PROPERTIES,t.object),h(a.ColDefUtil.ARRAY_PROPERTIES,t.array),h(a.ColDefUtil.NUMBER_PROPERTIES,t.number),h(a.ColDefUtil.FUNCTION_PROPERTIES,t.func),(E=e.ChangeDetectionStrategyType||(e.ChangeDetectionStrategyType={})).IdentityCheck="IdentityCheck",E.DeepValueCheck="DeepValueCheck",E.NoCheck="NoCheck";var f=(m.prototype.getStrategy=function(t){return this.strategyMap[t]},m);function m(){var t;this.strategyMap=((t={})[e.ChangeDetectionStrategyType.DeepValueCheck]=new C,t[e.ChangeDetectionStrategyType.IdentityCheck]=new y(function(t,e){return t===e}),t[e.ChangeDetectionStrategyType.NoCheck]=new y(function(t,e){return!1}),t)}var y=(d.prototype.areEqual=function(t,e){return this.strategy(t,e)},d);function d(t){this.strategy=t}var C=(g.prototype.areEqual=function(t,e){return g.areEquivalent(g.copy(t),g.copy(e))},g.unwrapStringOrNumber=function(t){return t instanceof Number||t instanceof String?t.valueOf():t},g.copy=function(t){if(!t)return t;if(Array.isArray(t)){for(var e=[],n=0;n<t.length;n++)e.push(this.copy(t[n]));return e}return"object"!=typeof t?t:[{},t].reduce(function(e,n){return Object.keys(n).forEach(function(t){e[t]=n[t]}),e},{})},g.isNaN=function(t){return Number.isNaN?Number.isNaN(t):"number"==typeof t&&isNaN(t)},g.areEquivalent=function(e,n){if(e=g.unwrapStringOrNumber(e),n=g.unwrapStringOrNumber(n),e===n)return!0;if(null===e||null===n||typeof e!=typeof n)return!1;if(g.isNaN(e)&&g.isNaN(n))return!0;if(e instanceof Date)return n instanceof Date&&e.valueOf()===n.valueOf();if("function"==typeof e)return!1;if("object"!=typeof e||e.$$typeof&&"Symbol(react.element)"===e.$$typeof.toString())return e==n;if(Object.isFrozen(e)||Object.isFrozen(n))return e===n;var t=void 0===e.areEquivPropertyTracking,r=void 0===n.areEquivPropertyTracking;try{var o=void 0;if(t)e.areEquivPropertyTracking=[];else if(e.areEquivPropertyTracking.some(function(t){return t===n}))return!0;if(r)n.areEquivPropertyTracking=[];else if(n.areEquivPropertyTracking.some(function(t){return t===e}))return!0;e.areEquivPropertyTracking.push(n),n.areEquivPropertyTracking.push(e);var i={};for(o in e)"areEquivPropertyTracking"!=o&&(i[o]=null);for(o in n)"areEquivPropertyTracking"!=o&&(i[o]=null);for(o in i)if(!this.areEquivalent(e[o],n[o]))return!1;return!0}finally{t&&delete e.areEquivPropertyTracking,r&&delete n.areEquivPropertyTracking}},g);function g(){}var v,E=(n(P,v=function(){}),P.prototype.getGui=function(){return this.eParentElement},P.prototype.destroy=function(){return this.parentComponent.destroyPortal(this.portal)},P.prototype.createParentElement=function(t){var e=document.createElement(this.parentComponent.props.componentWrappingElement||"div");return a._.addCssClass(e,"ag-react-container"),t.reactContainer=e},P.prototype.addParentContainerStyleAndClasses=function(){var e,n,r=this;this.componentInstance&&(this.componentInstance.getReactContainerStyle&&this.componentInstance.getReactContainerStyle()&&(e=this.eParentElement.style,n=this.componentInstance.getReactContainerStyle(),Object.keys(n).forEach(function(t){e[t]=n[t]})),this.componentInstance.getReactContainerClasses&&this.componentInstance.getReactContainerClasses()&&this.componentInstance.getReactContainerClasses().forEach(function(t){return a._.addCssClass(r.eParentElement,t)}))},P.prototype.statelessComponentRendered=function(){return 0<this.eParentElement.childElementCount||0<this.eParentElement.childNodes.length},P.prototype.getFrameworkComponentInstance=function(){return this.componentInstance},P.prototype.isStatelessComponent=function(){return this.statelessComponent},P.prototype.getReactComponentName=function(){return this.reactComponent.name},P.prototype.getMemoType=function(){return this.hasSymbol()?Symbol.for("react.memo"):60115},P.prototype.hasSymbol=function(){return"function"==typeof Symbol&&Symbol.for},P.prototype.isStateless=function(t){return"function"==typeof t&&!(t.prototype&&t.prototype.isReactComponent)||"object"==typeof t&&t.$$typeof===this.getMemoType()},P.prototype.hasMethod=function(t){var e=this.getFrameworkComponentInstance();return!!e&&null!==e[t]||this.fallbackMethodAvailable(t)},P.prototype.callMethod=function(t,e){var n=this,r=this.getFrameworkComponentInstance();if(this.isStatelessComponent())return this.fallbackMethod(t,e&&e[0]?e[0]:{});if(r){var o=r[t];return o?o.apply(r,e):this.fallbackMethodAvailable(t)?this.fallbackMethod(t,e&&e[0]?e[0]:{}):void 0}setTimeout(function(){return n.callMethod(t,e)})},P.prototype.addMethod=function(t,e){this[t]=e},P);function P(t,e,n){var r=v.call(this)||this;return r.portal=null,r.reactComponent=t,r.parentComponent=e,r.componentType=n,r.statelessComponent=r.isStateless(r.reactComponent),r}var R=0;function S(){return"agPortalKey_"+ ++R}var O,b=(n(k,O=E),k.prototype.init=function(e){var n=this;return this.eParentElement=this.createParentElement(e),this.renderStaticMarkup(e),new a.AgPromise(function(t){return n.createReactComponent(e,t)})},k.prototype.createReactComponent=function(t,e){var n=this;this.isStatelessComponent()||(t.ref=function(t){n.componentInstance=t,n.addParentContainerStyleAndClasses(),n.removeStaticMarkup()});t=o.createElement(this.reactComponent,t),t=r.createPortal(t,this.eParentElement,S());this.portal=t,this.parentComponent.mountReactPortal(t,this,function(t){e(t),n.isStatelessComponent()&&(n.isSlowRenderer()&&n.removeStaticMarkup(),setTimeout(function(){n.removeStaticMarkup()}))})},k.prototype.fallbackMethodAvailable=function(t){return!1},k.prototype.fallbackMethod=function(t,e){},k.prototype.isSlowRenderer=function(){return this.staticRenderTime>=k.SLOW_RENDERERING_THRESHOLD},k.prototype.isNullValue=function(){return""===this.staticMarkup},k.prototype.renderStaticMarkup=function(t){if(!(this.parentComponent.isDisableStaticMarkup()||this.componentType.isCellRenderer&&!this.componentType.isCellRenderer())){var e=console.error,t=o.createElement(this.reactComponent,t);try{console.error=function(){};var n=Date.now(),r=i.renderToStaticMarkup(t);this.staticRenderTime=Date.now()-n,console.error=e,""===r?this.staticMarkup=r:r&&(this.staticMarkup=document.createElement("span"),this.staticMarkup.innerHTML=r,this.eParentElement.appendChild(this.staticMarkup))}catch(t){}finally{console.error=e}}},k.prototype.removeStaticMarkup=function(){!this.parentComponent.isDisableStaticMarkup()&&this.componentType.isCellRenderer()&&this.staticMarkup&&(this.staticMarkup.remove?(this.staticMarkup.remove(),this.staticMarkup=null):this.eParentElement.removeChild&&(this.eParentElement.removeChild(this.staticMarkup),this.staticMarkup=null))},k.prototype.rendered=function(){return this.isNullValue()||!!this.staticMarkup||this.isStatelessComponent()&&this.statelessComponentRendered()||!(this.isStatelessComponent()||!this.getFrameworkComponentInstance())},k.SLOW_RENDERERING_THRESHOLD=3,k);function k(){var t=null!==O&&O.apply(this,arguments)||this;return t.staticMarkup=null,t.staticRenderTime=0,t}var T,D=(n(M,T=E),M.prototype.init=function(t){var e=this;return this.eParentElement=this.createParentElement(t),this.params=t,this.createOrUpdatePortal(t),new a.AgPromise(function(t){return e.createReactComponent(t)})},M.prototype.createOrUpdatePortal=function(t){var e=this;this.isStatelessComponent()||(t.ref=function(t){e.componentInstance=t,e.addParentContainerStyleAndClasses()}),this.reactElement=o.createElement(this.reactComponent,p(p({},t),{key:this.key})),this.portal=r.createPortal(this.reactElement,this.eParentElement,this.portalKey)},M.prototype.createReactComponent=function(e){this.parentComponent.mountReactPortal(this.portal,this,function(t){e(t)})},M.prototype.isNullValue=function(){return this.valueRenderedIsNull(this.params)},M.prototype.rendered=function(){return this.isStatelessComponent()&&this.statelessComponentRendered()||!(this.isStatelessComponent()||!this.getFrameworkComponentInstance())},M.prototype.valueRenderedIsNull=function(t){if(this.componentType.isCellRenderer&&!this.componentType.isCellRenderer())return!1;var e=console.error;try{return console.error=function(){},""===i.renderToStaticMarkup(o.createElement(this.reactComponent,t))}catch(t){}finally{console.error=e}return!1},M.prototype.refreshComponent=function(t){this.oldPortal=this.portal,this.createOrUpdatePortal(t),this.parentComponent.updateReactPortal(this.oldPortal,this.portal)},M.prototype.fallbackMethod=function(t,e){t=this[t+"Component"];if(t)return t.bind(this)(e)},M.prototype.fallbackMethodAvailable=function(t){return!!this[t+"Component"]},M);function M(t,e,n){n=T.call(this,t,e,n)||this;return n.oldPortal=null,n.key=S(),n.portalKey=S(),n}var N,I=(n(_,N=o.Component),_.prototype.render=function(){var e=this;return o.createElement("div",{style:this.createStyleForDiv(),className:this.props.className,ref:function(t){e.eGridDiv=t}},this.portals)},_.prototype.createStyleForDiv=function(){return p({height:"100%"},this.props.containerStyle||{})},_.prototype.componentDidMount=function(){var t=this.props.modules||[],e={providedBeanInstances:{agGridReact:this,frameworkComponentWrapper:new A(this)},modules:t},n=this.props.gridOptions||{},t=this.props.children;l.hasChildColumns(t)&&(n.columnDefs=l.mapChildColumnDefs(t)),this.gridOptions=a.ComponentUtil.copyAttributesToGridOptions(n,this.props),new a.Grid(this.eGridDiv,this.gridOptions,e),this.api=this.gridOptions.api,this.columnApi=this.gridOptions.columnApi},_.prototype.waitForInstance=function(t,e,n){var r=this;if(void 0===n&&(n=Date.now()),this.destroyed)e(null);else if(t.rendered())e(t);else{if(Date.now()-n>=this.props.maxComponentCreationTimeMs&&!this.hasPendingPortalUpdate)return t.isNullValue()?void e(t):void console.error("AG Grid: React Component '"+t.getReactComponentName()+"' not created within "+_.MAX_COMPONENT_CREATION_TIME_IN_MS+"ms");window.setTimeout(function(){r.waitForInstance(t,e,n)})}},_.prototype.mountReactPortal=function(t,e,n){this.portals=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),o=0,e=0;e<n;e++)for(var i=arguments[e],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(this.portals,[t]),this.waitForInstance(e,n),this.batchUpdate()},_.prototype.updateReactPortal=function(t,e){this.portals[this.portals.indexOf(t)]=e,this.batchUpdate()},_.prototype.batchUpdate=function(){var t=this;this.hasPendingPortalUpdate||(setTimeout(function(){t.api&&t.forceUpdate(function(){t.hasPendingPortalUpdate=!1})}),this.hasPendingPortalUpdate=!0)},_.prototype.destroyPortal=function(e){this.portals=this.portals.filter(function(t){return t!==e}),this.batchUpdate()},_.prototype.getStrategyTypeForProp=function(t){if("rowData"===t){if(this.props.rowDataChangeDetectionStrategy)return this.props.rowDataChangeDetectionStrategy;if(this.isImmutableDataActive())return e.ChangeDetectionStrategyType.IdentityCheck}return e.ChangeDetectionStrategyType.DeepValueCheck},_.prototype.isImmutableDataActive=function(){return this.props.deltaRowDataMode||this.props.immutableData||this.props.gridOptions&&(this.props.gridOptions.deltaRowDataMode||this.props.gridOptions.immutableData)},_.prototype.shouldComponentUpdate=function(t){return this.processPropsChanges(this.props,t),!1},_.prototype.componentDidUpdate=function(t){this.processPropsChanges(t,this.props)},_.prototype.processPropsChanges=function(t,e){var n={};this.extractGridPropertyChanges(t,e,n),this.extractDeclarativeColDefChanges(e,n),this.processSynchronousChanges(n),this.processAsynchronousChanges(n)},_.prototype.extractDeclarativeColDefChanges=function(t,e){var n,r,o,i;this.props.gridOptions&&this.props.gridOptions.columnDefs||this.props.columnDefs||(n=!!t.debug,r="columnDefs",o=this.gridOptions.columnDefs,l.hasChildColumns(t.children)?(i=this.changeDetectionService.getStrategy(this.getStrategyTypeForProp(r)),t=l.mapChildColumnDefs(t.children),i.areEqual(o,t)||(n&&console.log("agGridReact: colDefs definitions changed"),e[r]={previousValue:o,currentValue:t})):o&&0<o.length&&(e[r]={previousValue:o,currentValue:[]}))},_.prototype.extractGridPropertyChanges=function(e,n,r){var o=this,i=!!n.debug;Object.keys(n).forEach(function(t){a._.includes(a.ComponentUtil.ALL_PROPERTIES,t)&&(o.changeDetectionService.getStrategy(o.getStrategyTypeForProp(t)).areEqual(e[t],n[t])||(i&&console.log("agGridReact: ["+t+"] property changed"),r[t]={previousValue:e[t],currentValue:n[t]}))}),a.ComponentUtil.getEventCallbacks().forEach(function(t){o.props[t]!==n[t]&&(i&&console.log("agGridReact: ["+t+"] event callback changed"),r[t]={previousValue:e[t],currentValue:n[t]})})},_.prototype.componentWillUnmount=function(){this.api&&(this.api.destroy(),this.api=null),this.destroyed=!0},_.prototype.isDisableStaticMarkup=function(){return this.props.disableStaticMarkup},_.prototype.isLegacyComponentRendering=function(){return this.props.legacyComponentRendering},_.prototype.processSynchronousChanges=function(t){var e,n=p({},t);return 0<Object.keys(n).length&&(e={},this.SYNCHRONOUS_CHANGE_PROPERTIES.forEach(function(t){n[t]&&(e[t]=n[t],delete n.context)}),0<Object.keys(e).length&&this.api&&a.ComponentUtil.processOnChange(e,this.gridOptions,this.api,this.columnApi)),n},_.prototype.processAsynchronousChanges=function(t){var e=this;0<Object.keys(t).length&&window.setTimeout(function(){e.api&&a.ComponentUtil.processOnChange(t,e.gridOptions,e.api,e.columnApi)})},_.defaultProps={legacyComponentRendering:!1,disableStaticMarkup:!1,maxComponentCreationTimeMs:_.MAX_COMPONENT_CREATION_TIME_IN_MS=1e3},_);function _(t){var e=N.call(this,t)||this;return e.props=t,e.changeDetectionService=new f,e.api=null,e.portals=[],e.hasPendingPortalUpdate=!1,e.destroyed=!1,e.SYNCHRONOUS_CHANGE_PROPERTIES=["context"],e}function w(t,e){t.forEach(function(t){I[t]=e})}I.propTypes={gridOptions:t.object},w(a.ComponentUtil.getEventCallbacks(),t.func),w(a.ComponentUtil.BOOLEAN_PROPERTIES,t.bool),w(a.ComponentUtil.STRING_PROPERTIES,t.string),w(a.ComponentUtil.OBJECT_PROPERTIES,t.object),w(a.ComponentUtil.ARRAY_PROPERTIES,t.array),w(a.ComponentUtil.NUMBER_PROPERTIES,t.number),w(a.ComponentUtil.FUNCTION_PROPERTIES,t.func);var U,A=(n(G,U=a.BaseComponentWrapper),G.prototype.createWrapper=function(t,e){return new(this.agGridReact.isLegacyComponentRendering()?b:D)(t,this.agGridReact,e)},G);function G(t){var e=U.call(this)||this;return e.agGridReact=t,e}e.AgGridReact=I,e.AgGridColumn=l,Object.defineProperty(e,"__esModule",{value:!0})});