UNPKG

@syncfusion/ej2-react-base

Version:

A common package of Essential JS 2 React base, methods and class definitions

12 lines (11 loc) 12.9 kB
/*! * filename: ej2-react-base.umd.min.js * version : 31.2.2 * Copyright Syncfusion Inc. 2001 - 2025. All rights reserved. * Use of this code is subject to the terms of our license. * A copy of the current license can be obtained at any time by e-mailing * licensing@syncfusion.com. Any infringement will be prosecuted under * applicable laws. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom"),require("@syncfusion/ej2-base")):"function"==typeof define&&define.amd?define(["exports","react","react-dom","@syncfusion/ej2-base"],t):t((e=e||self).ej={},e.React,e.ReactDOM,e.ej2Base)}(this,function(e,l,a,b){"use strict";i=function(e,t){return(i=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}))(e,t)};var i,t,r=function(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},h=["alt","className","disabled","form","id","readOnly","style","tabIndex","title","type","name","onClick","onFocus","onBlur"],s=["accordion","tab","splitter"],o=/\]/,r=(t=l.Component,r(c,t),c.prototype.componentDidMount=function(){this.refreshChild(!0),this.canDelayUpdate=-1!==s.indexOf(this.getModuleName()),this.renderReactComponent(),this.portals&&this.portals.length&&(this.mountingState=!0,this.renderReactTemplates(),this.mountingState=!1)},c.prototype.componentDidUpdate=function(e){this.isshouldComponentUpdateCalled||!this.initRenderCalled||this.isReactForeceUpdate||e!==this.props&&(this.isshouldComponentUpdateCalled=!0,this.updateProperties(this.props,!1,e))},c.prototype.renderReactComponent=function(){var e=this.reactElement;e&&!this.isAppendCalled&&(this.isAppendCalled=!0,this.appendTo(e))},c.prototype.shouldComponentUpdate=function(e){return this.isshouldComponentUpdateCalled=!0,this.initRenderCalled?(this.isAppendCalled||(clearTimeout(this.cachedTimeOut),this.isAppendCalled=!0,this.appendTo(this.reactElement)),this.updateProperties(e)):this.updateProperties(e,!0),!0},c.prototype.updateProperties=function(e,t,r){for(var i=this,s=b.extend({},e),o=Object.keys(e),n=b.extend({},r||this.props),a=b.isNullOrUndefined(n.statelessTemplates)?b.isNullOrUndefined(this.statelessTemplateProps)?[]:this.statelessTemplateProps:n.statelessTemplates,p=0,l=o;p<l.length;p++){var h=l[p],c="className"===h;if("children"!==h)if(c||b.isNullOrUndefined(this.htmlattributes[""+h])||this.htmlattributes[""+h]===s[""+h]||(this.htmlattributes[""+h]=s[""+h]),this.compareValues(n[""+h],e[""+h]))delete s[""+h];else if(-1!==this.attrKeys.indexOf(h))if(c){this.clsName=!0;for(var d=n[""+h].split(" "),u=0;u<d.length;u++)this.element.classList.remove(d[parseInt(u.toString(),10)]);for(var f=s[""+h].split(" "),m=0;m<f.length;m++)this.element.classList.add(f[parseInt(m.toString(),10)])}else"disabled"===h||Object.prototype.hasOwnProperty.call(this.properties,h)||delete s[""+h];else("value"===h&&e[""+h]===this[""+h]||-1<a.indexOf(h)&&("content"===h&&"function"==typeof s[""+h]||e[""+h].toString()===this[""+h].toString()))&&delete s[""+h]}s.children&&delete s.children,this.initRenderCalled&&(this.canDelayUpdate||n.delayUpdate)?setTimeout(function(){i.refreshProperties(s,e,t)}):this.refreshProperties(s,e,t)},c.prototype.refreshProperties=function(e,t,r){var i=b.isNullOrUndefined(this.props.statelessTemplates)?[]:this.props.statelessTemplates;Object.keys(e).length&&(r||this.processComplexTemplate(e,this),this.setProperties(e,r)),-1===i.indexOf("directiveTemplates")&&this.refreshChild(r,t)},c.prototype.processComplexTemplate=function(e,t){var r,i=t.complexTemplate;if(i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r=i[""+s],e[""+s])&&b.setValue(r,b.getValue(s,e),e)},c.prototype.getDefaultAttributes=function(){var t=this,e=(this.isReact=!0,Object.keys(this.props)),r=["children","statelessTemplates","immediateRender","isLegacyTemplate","delayUpdate"];this.htmlattributes||(this.htmlattributes={}),this.attrKeys=h.concat(this.controlAttributes||[]);for(var i=0,s=e;i<s.length;i++){var o=s[i];(-1!==o.indexOf("data-")||-1!==o.indexOf("aria-")||-1!==this.attrKeys.indexOf(o)||-1===Object.keys(this.properties).indexOf(""+o)&&-1===r.indexOf(""+o))&&this.htmlattributes[""+o]!==this.props[""+o]&&(this.htmlattributes[""+o]=this.props[""+o])}if(this.htmlattributes.ref||(this.htmlattributes.ref=function(e){t.reactElement=e},-1!==["autocomplete","combobox","dropdownlist","dropdowntree","multiselect","listbox","colorpicker","numerictextbox","textbox","smarttextarea","uploader","maskedtextbox","slider","datepicker","datetimepicker","daterangepicker","timepicker","checkbox","switch","radio","rating","textarea","multicolumncombobox"].indexOf(this.getModuleName())&&(this.htmlattributes.key=""+c.reactUid,c.reactUid++,this.type&&!this.htmlattributes.type&&(this.htmlattributes.type=this.multiline?"hidden":this.type),this.name)&&!this.htmlattributes.name&&(this.htmlattributes.name=this.name)),this.clsName)for(var n=this.element.classList,a=this.htmlattributes.className,p=0;p<n.length;p++)-1===a.indexOf(n[parseInt(p.toString(),10)])&&(this.htmlattributes.className=this.htmlattributes.className+" "+n[parseInt(p.toString(),10)]);return this.htmlattributes},c.prototype.trigger=function(e,t,r){var i,s=this;!0!==this.isDestroyed&&this.modelObserver&&(o.test(e)&&((i=b.getValue(e,this))&&i.call(this,t),r)&&r.call(this,t),"change"!==e&&"input"!==e||this.props.onChange&&t.event&&this.props.onChange.call(void 0,{syntheticEvent:t.event,nativeEvent:{text:t.value},value:t.value,target:this}),i=this.isProtectedOnChange,this.isProtectedOnChange=!1,"created"===e?setTimeout(function(){s.isCreated=!0,s.isDestroyed||s.modelObserver.notify(e,t,r)},10):this.modelObserver.notify(e,t,r),this.isProtectedOnChange=i)},c.prototype.compareValues=function(e,t){var r,i;if(typeof e==typeof t){if(e===t)return!0;if((!b.isNullOrUndefined(e)&&e.constructor)!==(!b.isNullOrUndefined(t)&&t.constructor))return!1;if(e instanceof Date||e instanceof RegExp||e instanceof String||e instanceof Number)return e.toString()===t.toString();if(b.isObject(e)||Array.isArray(e))return i=t,b.isObject(r=e)&&(r=[e],i=[t]),this.compareObjects(r,i).status;if(e.moduleName&&e.moduleName===t.moduleName&&("query"===e.moduleName||"datamanager"===e.moduleName)&&JSON.stringify(e)===JSON.stringify(t))return!0}return!1},c.prototype.compareObjects=function(e,t,r){var i=!0,s=e.length===t.length,o=[],n=b.isNullOrUndefined(this.templateProps)?[]:this.templateProps;if(s)for(var a=0,p=t.length;a<p;a++){var l={},h=e[parseInt(a.toString(),10)],c=t[parseInt(a.toString(),10)],d=Object.keys(c);if(0!==d.length)for(var u=0,f=d;u<f.length;u++){var m=f[u],y=h[""+m],g=c[""+m];if("items"===m)for(var v=0;v<g.length;v++)if("richtexteditor"===this.getModuleName()&&"object"==typeof g[parseInt(v.toString(),10)])return{status:!0};if("grid"===this.getModuleName()&&"field"===m&&(l[""+m]=g),!Object.prototype.hasOwnProperty.call(h,m)||!(0<n.length&&-1===n.indexOf(""+m)&&"function"==typeof g?this.compareValues(y.toString(),g.toString()):this.compareValues(y,g))){if(!r)return{status:!1};i=!1,l[""+m]=g}}else if(t[parseInt(a.toString(),10)]===e[parseInt(a.toString(),10)])i=!0;else{if(!r)return{status:!1};i=!1}"grid"===this.getModuleName()&&"columns"===r&&b.isNullOrUndefined(l.field)&&(l.field=void 0),Object.keys(l).length&&o.push({index:a,value:l,key:r})}else i=!1;return{status:i,changedProperties:o}},c.prototype.refreshChild=function(e,t){if(this.checkInjectedModules){for(var r=this.getInjectedModules()||[],i=0,s=this.getInjectedServices()||[];i<s.length;i++){var o=s[i];-1===r.indexOf(o)&&r.push(o)}this.injectedModules=r}if(this.directivekeys){var n=[],a="",p=this.validateChildren({},this.directivekeys,t||this.props);if(p&&Object.keys(p).length){if(!e&&this.skipRefresh)for(var l=0,h=this.skipRefresh;l<h.length;l++)delete p[""+h[l]];if(this.prevProperties)for(var c=Object.keys(this.prevProperties),d=0;d<c.length;d++){var u,a=c[parseInt(d.toString(),10)];Object.prototype.hasOwnProperty.call(p,a)&&((u=this.compareObjects(this.prevProperties[""+a],p[""+a],a)).status?delete p[""+a]:(u.changedProperties.length&&(n=n.concat(u.changedProperties)),(u={})[""+a]=p[""+a],this.prevProperties=b.extend(this.prevProperties,u)))}else this.prevProperties=b.extend({},p,{},!0);if(n.length)if("grid"===this.getModuleName()&&"columns"===a)for(var f=0,m=this.columns;f<m.length;f++)b.getValue("field",m[parseInt(f.toString(),10)])===b.getValue(f+".value.field",n)?(v=b.getValue(n[parseInt(f.toString(),10)].key+"."+n[parseInt(f.toString(),10)].index,this))&&v.setProperties?v.setProperties(n[parseInt(f.toString(),10)].value):b.extend(v,n[parseInt(f.toString(),10)].value):this.setProperties(p,e);else for(var y=0,g=n;y<g.length;y++){var v,O=g[y];(v=b.getValue(O.key+"."+O.index,this))&&v.setProperties?v.setProperties(O.value):b.extend(v,O.value)}else this.setProperties(p,e)}}},c.prototype.componentWillUnmount=function(){clearTimeout(this.cachedTimeOut);var e=!!["dropdowntree","checkbox"].indexOf(this.getModuleName())||document.body.contains(this.element);this.initRenderCalled&&this.isAppendCalled&&this.element&&e&&!this.isDestroyed&&this.isCreated&&this.destroy(),b.onIntlChange.offIntlEvents()},c.prototype.appendReactElement=function(e,t){e=a.createPortal(e,t);this.portals?this.portals.push(e):this.portals=[e]},c.prototype.renderReactTemplates=function(e){this.isReactForeceUpdate=!0,e?this.forceUpdate(e):this.forceUpdate(),this.isReactForeceUpdate=!1},c.prototype.clearTemplate=function(e,r,t){var i=this;e&&e.length?Array.prototype.forEach.call(e,function(e){if(i.portals.forEach(function(e){e.propName}),!b.isNullOrUndefined(r)&&i.portals[r]&&i.portals[r].propName===e)i.portals.splice(r,1);else for(var t=0;t<i.portals.length;t++)i.portals[parseInt(t.toString(),10)].propName===e&&(i.portals.splice(t,1),t--)}):this.portals=[],this.renderReactTemplates(t)},c.prototype.validateChildren=function(e,t,r){for(var i=!1,s=0,o=l.Children.toArray(r.children);s<o.length;s++){var n=o[s],a=this.getChildType(n),p=t[""+a];a&&t&&(p=this.getChildProps(l.Children.toArray(n.props.children),p)).length&&(i=!0,e[n.type.propertyName||a]=p)}return i?e:null},c.prototype.getChildType=function(e){return e.type&&e.type.isDirective&&e.type.moduleName||""},c.prototype.getChildProps=function(e,t){for(var r=[],i=0,s=e;i<s.length;i++){var o=s[i],n=!1,a=void 0,a="string"==typeof t?(n=!0,t):Object.keys(t)[0],p=o.props;this.getChildType(o)===a&&(n||!p.children?(n=b.extend({},p,{},!0),this.processComplexTemplate(n,o.type),r.push(n)):((n=this.validateChildren(b.extend({},p),t[""+a],p)||p).children&&delete n.children,this.processComplexTemplate(n,o.type),r.push(n)))}return r},c.prototype.getInjectedServices=function(){for(var e=0,t=l.Children.toArray(this.props.children);e<t.length;e++){var r=t[e];if(r.type&&r.type.isService)return r.props.services}return[]},c.reactUid=1,c);function c(){var e=null!==t&&t.apply(this,arguments)||this;return e.mountingState=!1,e.attrKeys=[],e.cachedTimeOut=0,e.isAppendCalled=!1,e.initRenderCalled=!1,e.isReactForeceUpdate=!1,e.isReact=!0,e.isshouldComponentUpdateCalled=!1,e.isCreated=!1,e}n=function(e,t){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}))(e,t)};var n,p,d=function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},d=(p=l.PureComponent,d(u,p),u.prototype.render=function(){return null},u.isDirective=!0,u);function u(){return null!==p&&p.apply(this,arguments)||this}f=function(e,t){return(f=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}))(e,t)};var f,m,y=function(e,t){function r(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},y=(m=l.PureComponent,y(g,m),g.prototype.render=function(){return null},g.isService=!0,g);function g(){return null!==m&&m.apply(this,arguments)||this}var v=b.getTemplateEngine();function O(n,e){return"string"==typeof n||n.prototype&&n.prototype.CSPTemplate&&"function"==typeof n?v(n,e):function(e,t,r,i){var s=n,o=e,s=("object"==typeof n&&(s=n.template,o=b.extend({},e,n.data||{})),e=i||document.createElement("div"),l.createElement(s,o)),o=a.createPortal(s,e);if(o.propName=r,t.portals?t.portals.push(o):t.portals=[o],!i)return[e]}}b.setTemplateEngine({compile:O}),e.ComplexBase=d,e.ComponentBase=r,e.Inject=y,e.applyMixins=function(r,e){e.forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(e){"isMounted"!==e&&"replaceState"!==e&&"render"!==e&&(r.prototype[""+e]=t.prototype[""+e])})})},e.compile=O,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ej2-react-base.umd.min.js.map