UNPKG

@syncfusion/ej2-react-base

Version:

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

12 lines (11 loc) 12.8 kB
/*! * filename: ej2-react-base.min.js * version : 32.1.20 * 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. */ this.ej=this.ej||{},this.ej.reactbase=function(t,e,r,i){"use strict";function s(t,e){e.forEach(function(e){Object.getOwnPropertyNames(e.prototype).forEach(function(r){"isMounted"!==r&&"replaceState"!==r&&"render"!==r&&(t.prototype[""+r]=e.prototype[""+r])})})}function n(t,s){return"string"==typeof t||t.prototype&&t.prototype.CSPTemplate&&"function"==typeof t?m(t,s):function(s,n,o,a){var p=t,l=s;"object"==typeof p&&(p=t.template,l=i.extend({},s,t.data||{}));var h;h=a||document.createElement("div");var c=e.createElement(p,l),d=r.createPortal(c,h);if(d.propName=o,n.portals?n.portals.push(d):n.portals=[d],!a)return[h]}}var o=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}(),a=["alt","className","disabled","form","id","readOnly","style","tabIndex","title","type","name","onClick","onFocus","onBlur"],p=["accordion","tab","splitter"],l=/\]/,h=function(t){function s(){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}return o(s,t),s.prototype.componentDidMount=function(){this.refreshChild(!0),this.canDelayUpdate=-1!==p.indexOf(this.getModuleName()),this.renderReactComponent(),this.portals&&this.portals.length&&(this.mountingState=!0,this.renderReactTemplates(),this.mountingState=!1)},s.prototype.componentDidUpdate=function(t){this.isshouldComponentUpdateCalled||!this.initRenderCalled||this.isReactForeceUpdate||t!==this.props&&(this.isshouldComponentUpdateCalled=!0,this.updateProperties(this.props,!1,t))},s.prototype.renderReactComponent=function(){var t=this.reactElement;t&&!this.isAppendCalled&&(this.isAppendCalled=!0,this.appendTo(t))},s.prototype.shouldComponentUpdate=function(t){return this.isshouldComponentUpdateCalled=!0,this.initRenderCalled?(this.isAppendCalled||(clearTimeout(this.cachedTimeOut),this.isAppendCalled=!0,this.appendTo(this.reactElement)),this.updateProperties(t),!0):(this.updateProperties(t,!0),!0)},s.prototype.updateProperties=function(t,e,r){for(var s=this,n=i.extend({},t),o=Object.keys(t),a=i.extend({},r||this.props),p=i.isNullOrUndefined(a.statelessTemplates)?i.isNullOrUndefined(this.statelessTemplateProps)?[]:this.statelessTemplateProps:a.statelessTemplates,l=0,h=o;l<h.length;l++){var c=h[l],d="className"===c;if("children"!==c)if(d||i.isNullOrUndefined(this.htmlattributes[""+c])||this.htmlattributes[""+c]===n[""+c]||(this.htmlattributes[""+c]=n[""+c]),this.compareValues(a[""+c],t[""+c]))delete n[""+c];else if(-1!==this.attrKeys.indexOf(c))if(d){this.clsName=!0;for(var u=a[""+c].split(" "),f=0;f<u.length;f++)this.element.classList.remove(u[parseInt(f.toString(),10)]);for(var m=n[""+c].split(" "),y=0;y<m.length;y++)this.element.classList.add(m[parseInt(y.toString(),10)])}else"disabled"===c||Object.prototype.hasOwnProperty.call(this.properties,c)||delete n[""+c];else"value"===c&&t[""+c]===this[""+c]?delete n[""+c]:p.indexOf(c)>-1&&("content"===c&&"function"==typeof n[""+c]||t[""+c].toString()===this[""+c].toString())&&delete n[""+c]}n.children&&delete n.children,this.initRenderCalled&&(this.canDelayUpdate||a.delayUpdate)?setTimeout(function(){s.refreshProperties(n,t,e)}):this.refreshProperties(n,t,e)},s.prototype.refreshProperties=function(t,e,r){var s=i.isNullOrUndefined(this.props.statelessTemplates)?[]:this.props.statelessTemplates;Object.keys(t).length&&(r||this.processComplexTemplate(t,this),this.setProperties(t,r)),-1===s.indexOf("directiveTemplates")&&this.refreshChild(r,e)},s.prototype.processComplexTemplate=function(t,e){var r=e.complexTemplate;if(r)for(var s in r)if(Object.prototype.hasOwnProperty.call(r,s)){var n=r[""+s];t[""+s]&&i.setValue(n,i.getValue(s,t),t)}},s.prototype.getDefaultAttributes=function(){var t=this;this.isReact=!0;var e=Object.keys(this.props),r=["children","statelessTemplates","immediateRender","isLegacyTemplate","delayUpdate"];this.htmlattributes||(this.htmlattributes={}),this.attrKeys=a.concat(this.controlAttributes||[]);for(var i=0,n=e;i<n.length;i++){var o=n[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=""+s.reactUid,s.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 p=this.element.classList,l=this.htmlattributes.className,h=0;h<p.length;h++)-1===l.indexOf(p[parseInt(h.toString(),10)])&&(this.htmlattributes.className=this.htmlattributes.className+" "+p[parseInt(h.toString(),10)]);return this.htmlattributes},s.prototype.trigger=function(t,e,r){var s=this;if(!0!==this.isDestroyed&&this.modelObserver){if(l.test(t)){var n=i.getValue(t,this);n?(n.call(this,e),r&&r.call(this,e)):r&&r.call(this,e)}"change"!==t&&"input"!==t||this.props.onChange&&e.event&&this.props.onChange.call(void 0,{syntheticEvent:e.event,nativeEvent:{text:e.value},value:e.value,target:this});var o=this.isProtectedOnChange;this.isProtectedOnChange=!1,"created"===t?setTimeout(function(){s.isCreated=!0,s.isDestroyed||s.modelObserver.notify(t,e,r)},10):this.modelObserver.notify(t,e,r),this.isProtectedOnChange=o}},s.prototype.compareValues=function(t,e){if(typeof t===typeof e){if(t===e)return!0;if((!i.isNullOrUndefined(t)&&t.constructor)!==(!i.isNullOrUndefined(e)&&e.constructor))return!1;if(t instanceof Date||t instanceof RegExp||t instanceof String||t instanceof Number)return t.toString()===e.toString();if(i.isObject(t)||Array.isArray(t)){var r=t,s=e;return i.isObject(r)&&(r=[t],s=[e]),this.compareObjects(r,s).status}if(t.moduleName&&t.moduleName===e.moduleName&&("query"===t.moduleName||"datamanager"===t.moduleName)&&JSON.stringify(t)===JSON.stringify(e))return!0}return!1},s.prototype.compareObjects=function(t,e,r){var s=!0,n=t.length===e.length,o=[],a=i.isNullOrUndefined(this.templateProps)?[]:this.templateProps;if(n)for(var p=0,l=e.length;p<l;p++){var h={},c=t[parseInt(p.toString(),10)],d=e[parseInt(p.toString(),10)],u=Object.keys(d);if(0!==u.length)for(var f=0,m=u;f<m.length;f++){var y=m[f],g=c[""+y],v=d[""+y];if("items"===y)for(var O=0;O<v.length;O++)if("richtexteditor"===this.getModuleName()&&"object"==typeof v[parseInt(O.toString(),10)])return{status:!0};if("grid"===this.getModuleName()&&"field"===y&&(h[""+y]=v),!Object.prototype.hasOwnProperty.call(c,y)||!(a.length>0&&-1===a.indexOf(""+y)&&"function"==typeof v?this.compareValues(null!=g?g.toString():g,v.toString()):this.compareValues(g,v))){if(!r)return{status:!1};s=!1,h[""+y]=v}}else if(e[parseInt(p.toString(),10)]===t[parseInt(p.toString(),10)])s=!0;else{if(!r)return{status:!1};s=!1}"grid"===this.getModuleName()&&"columns"===r&&i.isNullOrUndefined(h.field)&&(h.field=void 0),Object.keys(h).length&&o.push({index:p,value:h,key:r})}else s=!1;return{status:s,changedProperties:o}},s.prototype.refreshChild=function(t,e){if(this.checkInjectedModules){for(var r=this.getInjectedModules()||[],s=0,n=this.getInjectedServices()||[];s<n.length;s++){var o=n[s];-1===r.indexOf(o)&&r.push(o)}this.injectedModules=r}if(this.directivekeys){var a=[],p="",l=this.validateChildren({},this.directivekeys,e||this.props);if(l&&Object.keys(l).length){if(!t&&this.skipRefresh)for(var h=0,c=this.skipRefresh;h<c.length;h++)delete l[""+c[h]];if(this.prevProperties){for(var d=Object.keys(this.prevProperties),u=0;u<d.length;u++)if(p=d[parseInt(u.toString(),10)],Object.prototype.hasOwnProperty.call(l,p)){var f=this.compareObjects(this.prevProperties[""+p],l[""+p],p);if(f.status)delete l[""+p];else{f.changedProperties.length&&(a=a.concat(f.changedProperties));var m={};m[""+p]=l[""+p],this.prevProperties=i.extend(this.prevProperties,m)}}}else this.prevProperties=i.extend({},l,{},!0);if(a.length)if("grid"===this.getModuleName()&&"columns"===p)for(var y=0,g=this.columns;y<g.length;y++)i.getValue("field",g[parseInt(y.toString(),10)])===i.getValue(y+".value.field",a)?(C=i.getValue(a[parseInt(y.toString(),10)].key+"."+a[parseInt(y.toString(),10)].index,this))&&C.setProperties?C.setProperties(a[parseInt(y.toString(),10)].value):i.extend(C,a[parseInt(y.toString(),10)].value):this.setProperties(l,t);else for(var v=0,O=a;v<O.length;v++){var b=O[v],C=i.getValue(b.key+"."+b.index,this);C&&C.setProperties?C.setProperties(b.value):i.extend(C,b.value)}else this.setProperties(l,t)}}},s.prototype.componentWillUnmount=function(){clearTimeout(this.cachedTimeOut);var t=!!["dropdowntree","checkbox"].indexOf(this.getModuleName())||document.body.contains(this.element);this.initRenderCalled&&this.isAppendCalled&&this.element&&t&&!this.isDestroyed&&this.isCreated&&this.destroy(),i.onIntlChange.offIntlEvents()},s.prototype.appendReactElement=function(t,e){var i=r.createPortal(t,e);this.portals?this.portals.push(i):this.portals=[i]},s.prototype.renderReactTemplates=function(t){this.isReactForeceUpdate=!0,t?this.forceUpdate(t):this.forceUpdate(),this.isReactForeceUpdate=!1},s.prototype.clearTemplate=function(t,e,r){var s=this;t&&t.length?Array.prototype.forEach.call(t,function(t){if(s.portals.forEach(function(t){t.propName}),!i.isNullOrUndefined(e)&&s.portals[e]&&s.portals[e].propName===t)s.portals.splice(e,1);else for(var r=0;r<s.portals.length;r++)s.portals[parseInt(r.toString(),10)].propName===t&&(s.portals.splice(r,1),r--)}):this.portals=[],this.renderReactTemplates(r)},s.prototype.validateChildren=function(t,r,i){for(var s=!1,n=0,o=e.Children.toArray(i.children);n<o.length;n++){var a=o[n],p=this.getChildType(a),l=r[""+p];if(p&&r){var h=this.getChildProps(e.Children.toArray(a.props.children),l);h.length&&(s=!0,t[a.type.propertyName||p]=h)}}return s?t:null},s.prototype.getChildType=function(t){return t.type&&t.type.isDirective?t.type.moduleName||"":""},s.prototype.getChildProps=function(t,e){for(var r=[],s=0,n=t;s<n.length;s++){var o=n[s],a=!1,p=void 0;"string"==typeof e?(a=!0,p=e):p=Object.keys(e)[0];var l=o.props;if(this.getChildType(o)===p)if(a||!l.children){var h=i.extend({},l,{},!0);this.processComplexTemplate(h,o.type),r.push(h)}else{var c=this.validateChildren(i.extend({},l),e[""+p],l)||l;c.children&&delete c.children,this.processComplexTemplate(c,o.type),r.push(c)}}return r},s.prototype.getInjectedServices=function(){for(var t=0,r=e.Children.toArray(this.props.children);t<r.length;t++){var i=r[t];if(i.type&&i.type.isService)return i.props.services}return[]},s.reactUid=1,s}(e.Component),c=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}(),d=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return c(e,t),e.prototype.render=function(){return null},e.isDirective=!0,e}(e.PureComponent),u=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}(),f=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return u(e,t),e.prototype.render=function(){return null},e.isService=!0,e}(e.PureComponent),m=i.getTemplateEngine();return i.setTemplateEngine({compile:n}),t.ComplexBase=d,t.ComponentBase=h,t.Inject=f,t.applyMixins=s,t.compile=n,t}({},React,ReactDOM,ej.base),this.ejs=ej; //# sourceMappingURL=ej2-react-base.min.js.map