UNPKG

@syncfusion/ej2-react-base

Version:

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

10 lines 13.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. */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React"),require("ReactDOM"),require("SyncfusionBase")):"function"==typeof define&&define.amd?define(["React","ReactDOM","SyncfusionBase"],t):"object"==typeof exports?exports.SyncfusionReactBase=t(require("React"),require("ReactDOM"),require("SyncfusionBase")):e.SyncfusionReactBase=t(e.React,e.ReactDOM,e.SyncfusionBase)}(self,(e,t,r)=>(()=>{"use strict";var i={24:t=>{t.exports=e},314:e=>{e.exports=t},766:e=>{e.exports=r}},s={};function o(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return i[e](r,r.exports,o),r.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{ComplexBase:()=>u,ComponentBase:()=>h,Inject:()=>m,applyMixins:()=>c,compile:()=>g});var e,t=o(24),r=o(314),i=o(766),s=(e=function(t,r){return e=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,r)},function(t,r){function i(){this.constructor=t}e(t,r),t.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(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.mountingState=!1,t.attrKeys=[],t.cachedTimeOut=0,t.isAppendCalled=!1,t.initRenderCalled=!1,t.isReactForeceUpdate=!1,t.isReact=!0,t.isshouldComponentUpdateCalled=!1,t.isCreated=!1,t}return s(o,e),o.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)},o.prototype.componentDidUpdate=function(e){this.isshouldComponentUpdateCalled||!this.initRenderCalled||this.isReactForeceUpdate||e!==this.props&&(this.isshouldComponentUpdateCalled=!0,this.updateProperties(this.props,!1,e))},o.prototype.renderReactComponent=function(){var e=this.reactElement;e&&!this.isAppendCalled&&(this.isAppendCalled=!0,this.appendTo(e))},o.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),!0):(this.updateProperties(e,!0),!0)},o.prototype.updateProperties=function(e,t,r){for(var s=this,o=(0,i.extend)({},e),n=Object.keys(e),a=(0,i.extend)({},r||this.props),p=(0,i.isNullOrUndefined)(a.statelessTemplates)?(0,i.isNullOrUndefined)(this.statelessTemplateProps)?[]:this.statelessTemplateProps:a.statelessTemplates,l=0,h=n;l<h.length;l++){var c=h[l],d="className"===c;if("children"!==c)if(d||(0,i.isNullOrUndefined)(this.htmlattributes[""+c])||this.htmlattributes[""+c]===o[""+c]||(this.htmlattributes[""+c]=o[""+c]),this.compareValues(a[""+c],e[""+c]))delete o[""+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=o[""+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 o[""+c];else("value"===c&&e[""+c]===this[""+c]||p.indexOf(c)>-1&&("content"===c&&"function"==typeof o[""+c]||e[""+c].toString()===this[""+c].toString()))&&delete o[""+c]}o.children&&delete o.children,this.initRenderCalled&&(this.canDelayUpdate||a.delayUpdate)?setTimeout(function(){s.refreshProperties(o,e,t)}):this.refreshProperties(o,e,t)},o.prototype.refreshProperties=function(e,t,r){var s=(0,i.isNullOrUndefined)(this.props.statelessTemplates)?[]:this.props.statelessTemplates;Object.keys(e).length&&(r||this.processComplexTemplate(e,this),this.setProperties(e,r)),-1===s.indexOf("directiveTemplates")&&this.refreshChild(r,t)},o.prototype.processComplexTemplate=function(e,t){var r=t.complexTemplate;if(r)for(var s in r)if(Object.prototype.hasOwnProperty.call(r,s)){var o=r[""+s];e[""+s]&&(0,i.setValue)(o,(0,i.getValue)(s,e),e)}},o.prototype.getDefaultAttributes=function(){var e=this;this.isReact=!0;var t=Object.keys(this.props),r=["children","statelessTemplates","immediateRender","isLegacyTemplate","delayUpdate"];this.htmlattributes||(this.htmlattributes={}),this.attrKeys=a.concat(this.controlAttributes||[]);for(var i=0,s=t;i<s.length;i++){var n=s[i];(-1!==n.indexOf("data-")||-1!==n.indexOf("aria-")||-1!==this.attrKeys.indexOf(n)||-1===Object.keys(this.properties).indexOf(""+n)&&-1===r.indexOf(""+n))&&this.htmlattributes[""+n]!==this.props[""+n]&&(this.htmlattributes[""+n]=this.props[""+n])}if(!this.htmlattributes.ref){this.htmlattributes.ref=function(t){e.reactElement=t};-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=""+o.reactUid,o.reactUid++,this.type&&!this.htmlattributes.type&&(this.htmlattributes.type=this.multiline?"hidden":this.type),this.name&&!this.htmlattributes.name&&(this.htmlattributes.name=this.name))}if(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},o.prototype.trigger=function(e,t,r){var s=this;if(!0!==this.isDestroyed&&this.modelObserver){if(l.test(e)){var o=(0,i.getValue)(e,this);o?(o.call(this,t),r&&r.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});var n=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=n}},o.prototype.compareValues=function(e,t){if(typeof e===typeof t){if(e===t)return!0;if((!(0,i.isNullOrUndefined)(e)&&e.constructor)!==(!(0,i.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((0,i.isObject)(e)||Array.isArray(e)){var r=e,s=t;return(0,i.isObject)(r)&&(r=[e],s=[t]),this.compareObjects(r,s).status}if(e.moduleName&&e.moduleName===t.moduleName&&("query"===e.moduleName||"datamanager"===e.moduleName)&&JSON.stringify(e)===JSON.stringify(t))return!0}return!1},o.prototype.compareObjects=function(e,t,r){var s=!0,o=e.length===t.length,n=[],a=(0,i.isNullOrUndefined)(this.templateProps)?[]:this.templateProps;if(o)for(var p=0,l=t.length;p<l;p++){var h={},c=e[parseInt(p.toString(),10)],d=t[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(t[parseInt(p.toString(),10)]===e[parseInt(p.toString(),10)])s=!0;else{if(!r)return{status:!1};s=!1}"grid"===this.getModuleName()&&"columns"===r&&(0,i.isNullOrUndefined)(h.field)&&(h.field=void 0),Object.keys(h).length&&n.push({index:p,value:h,key:r})}else s=!1;return{status:s,changedProperties:n}},o.prototype.refreshChild=function(e,t){if(this.checkInjectedModules){for(var r=this.getInjectedModules()||[],s=0,o=this.getInjectedServices()||[];s<o.length;s++){var n=o[s];-1===r.indexOf(n)&&r.push(n)}this.injectedModules=r}if(this.directivekeys){var a=[],p="",l=this.validateChildren({},this.directivekeys,t||this.props);if(l&&Object.keys(l).length){if(!e&&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=(0,i.extend)(this.prevProperties,m)}}}else this.prevProperties=(0,i.extend)({},l,{},!0);if(a.length)if("grid"===this.getModuleName()&&"columns"===p)for(var y=0,g=this.columns;y<g.length;y++){if((0,i.getValue)("field",g[parseInt(y.toString(),10)])===(0,i.getValue)(y+".value.field",a))(b=(0,i.getValue)(a[parseInt(y.toString(),10)].key+"."+a[parseInt(y.toString(),10)].index,this))&&b.setProperties?b.setProperties(a[parseInt(y.toString(),10)].value):(0,i.extend)(b,a[parseInt(y.toString(),10)].value);else this.setProperties(l,e)}else for(var v=0,O=a;v<O.length;v++){var b,x=O[v];(b=(0,i.getValue)(x.key+"."+x.index,this))&&b.setProperties?b.setProperties(x.value):(0,i.extend)(b,x.value)}else this.setProperties(l,e)}}},o.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(),i.onIntlChange.offIntlEvents()},o.prototype.appendReactElement=function(e,t){var i=r.createPortal(e,t);this.portals?this.portals.push(i):this.portals=[i]},o.prototype.renderReactTemplates=function(e){this.isReactForeceUpdate=!0,e?this.forceUpdate(e):this.forceUpdate(),this.isReactForeceUpdate=!1},o.prototype.clearTemplate=function(e,t,r){var s=this,o=[];e&&e.length?Array.prototype.forEach.call(e,function(e){var r=0;if(s.portals.forEach(function(t){t.propName===e&&(o.push(r),r++)}),!(0,i.isNullOrUndefined)(t)&&s.portals[t]&&s.portals[t].propName===e)s.portals.splice(t,1);else for(var n=0;n<s.portals.length;n++)s.portals[parseInt(n.toString(),10)].propName===e&&(s.portals.splice(n,1),n--)}):this.portals=[],this.renderReactTemplates(r)},o.prototype.validateChildren=function(e,r,i){for(var s=!1,o=0,n=t.Children.toArray(i.children);o<n.length;o++){var a=n[o],p=this.getChildType(a),l=r[""+p];if(p&&r){var h=this.getChildProps(t.Children.toArray(a.props.children),l);h.length&&(s=!0,e[a.type.propertyName||p]=h)}}return s?e:null},o.prototype.getChildType=function(e){return e.type&&e.type.isDirective&&e.type.moduleName||""},o.prototype.getChildProps=function(e,t){for(var r=[],s=0,o=e;s<o.length;s++){var n=o[s],a=!1,p=void 0;"string"==typeof t?(a=!0,p=t):p=Object.keys(t)[0];var l=n.props;if(this.getChildType(n)===p)if(a||!l.children){var h=(0,i.extend)({},l,{},!0);this.processComplexTemplate(h,n.type),r.push(h)}else{var c=this.validateChildren((0,i.extend)({},l),t[""+p],l)||l;c.children&&delete c.children,this.processComplexTemplate(c,n.type),r.push(c)}}return r},o.prototype.getInjectedServices=function(){for(var e=0,r=t.Children.toArray(this.props.children);e<r.length;e++){var i=r[e];if(i.type&&i.type.isService)return i.props.services}return[]},o.reactUid=1,o}(t.Component);function c(e,t){t.forEach(function(t){Object.getOwnPropertyNames(t.prototype).forEach(function(r){"isMounted"!==r&&"replaceState"!==r&&"render"!==r&&(e.prototype[""+r]=t.prototype[""+r])})})}var d=function(){var e=function(t,r){return e=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,r)};return function(t,r){function i(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}(),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return d(t,e),t.prototype.render=function(){return null},t.isDirective=!0,t}(t.PureComponent),f=function(){var e=function(t,r){return e=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,r)};return function(t,r){function i(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}(),m=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return f(t,e),t.prototype.render=function(){return null},t.isService=!0,t}(t.PureComponent),y=(0,i.getTemplateEngine)();function g(e,s){return"string"==typeof e||e.prototype&&e.prototype.CSPTemplate&&"function"==typeof e?y(e,s):function(s,o,n,a){var p,l=e,h=s;"object"==typeof l&&(l=e.template,h=(0,i.extend)({},s,e.data||{})),p=a||document.createElement("div");var c=t.createElement(l,h),d=r.createPortal(c,p);if(d.propName=n,o.portals?o.portals.push(d):o.portals=[d],!a)return[p]}}(0,i.setTemplateEngine)({compile:g})})(),n})());