@sankhyalabs/ezui 1.1.7 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sankhyalabs/ezui",
3
- "version": "1.1.7",
3
+ "version": "1.1.11",
4
4
  "description": "Biblioteca de componentes Sankhya.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/custom-elements/index.js",
@@ -1 +0,0 @@
1
- function t(t,s){return{type:"FORM/CHANGETAB",payload:{formId:t,index:s}}}function s(t,s){return{type:"FORM/CLEAREDITION",payload:{dataUnit:t,recordsLimit:s}}}function i(t,s){return{type:"FORM/COLLAPSEGROUP",payload:{collapseId:t,collapsed:s}}}function e(){return{type:"FORM/LOAD"}}function h(t,s,i,e,h,r,a){return{type:"FORM/INVALIDFIELD",payload:{tabController:t,tabIndex:s,dataUnit:i,recordId:h,recordIndex:e,fieldName:r,errorMessage:a}}}function r(t,s){return{type:"FORM/SHOWHIDENAVBTN",payload:{buttonName:t,status:s}}}const a=(t,s)=>t.hist.present.currentTabIndex[s]||0,n=(t,s)=>t.hist.present.collapsedGroups[s],o=(t,s)=>t.hist.present.changes[s],d=(t,s)=>t.hist.present.currentRecordIndex[s]||0,c=(t,s)=>t.hist.present.newRecordIndex[s]||0,l=t=>t.nonhist.visibleButtons;class u{constructor(t,s,i="1"){this.name=t,this.unitLabel=s,this.cardinality=i}set store(t){this._store=t}isLoading(){return this._store.getState().nonhist.dataLoading[this.name]}hasChanges(){const t=this._store.getState();return void 0!==o(t,this.name)||c(t,this.name)>0}hasNext(){return d(this._store.getState(),this.name)<this.records.length-1}hasPrevious(){return d(this._store.getState(),this.name)>0}hasCurrentRecord(){return null!=this.getCurrentRecord()}previous(){this._store.dispatch({type:"FORM/NAVIGATE",payload:{dataUnit:this.name,limit:0,backward:!0}})}next(){this._store.dispatch({type:"FORM/NAVIGATE",payload:{dataUnit:this.name,limit:this.records.length,backward:!1}})}getValue(t){const s=this.getCurrentRecord();if(!s)return;const i=this.getRecordChanges(s);return i&&void 0!==i[t]?i[t]:s[t]||null}getErrorMessage(t){const s=this.getCurrentRecord();return((t,s,i,e)=>((t.nonhist.invalidFields[this.name]||{})[i]||{})[e]||"")(this._store.getState(),0,null==s?void 0:s.record__id,t)}changeValue(t,s){0==this.records.length&&this.insert(),this._changeDeboucing&&window.clearTimeout(this._changeDeboucing),this._changeDeboucing=window.setTimeout((()=>{const i=this.getCurrentRecord();this._store.dispatch(function(t,s,i,e){return{type:"FORM/CHANGEFIELD",payload:{dataUnit:t,recordId:s,fieldName:i,value:e}}}(this.name,i.record__id,t,s))}),100)}cancel(){this.records=this.records.filter((t=>!t.record__id.startsWith("NEW_"))),this._store.dispatch(s(this.name,this.records.length-1))}insert(){const t=this.records.length,s=c(this._store.getState(),this.name);this.records.push({record__id:"NEW_"+(s+1)}),this._store.dispatch(function(t,s){return{type:"FORM/INSERT",payload:{dataUnit:t,insertionIndex:s}}}(this.name,t))}getChangesToSave(){const t=o(this._store.getState(),this.name),s=Object.keys(t).map((s=>{const i={record__id:s},e=t[s];return Object.keys(e).forEach((t=>{i[t]=e[t]})),i}));return[{dataUnit:this.name,records:s}]}save(){if(!this.validateRecords())return;let t;this._store.dispatch({type:"FORM/SAVINGCHANGES",payload:{dataUnit:this.name}}),this.saveExecutor&&(t=this.saveExecutor(this.getChangesToSave())),t instanceof Promise?t.then((t=>this.processSaveResult(t))):this.processSaveResult(t)}load(){let t;this._store.dispatch({type:"FORM/DATALOADING",payload:{dataUnit:this.name}}),this.loadExecutor&&(t=this.loadExecutor({dataUnit:this.name})),t instanceof Promise?t.then((t=>this.processLoadResult(t))):this.processLoadResult(t)}remove(){const t=d(this._store.getState(),this.name);let s;if(this._store.dispatch({type:"FORM/REMOVINGRECORD",payload:{dataUnit:this.name}}),this.removeExecutor){const t=this.getCurrentRecord();s=this.removeExecutor({dataUnit:this.name,recordId:t.record__id,record:t})}else s=!0;s&&(s instanceof Promise?s.then((s=>this.processRemoveResult(s,t))):this.processRemoveResult(s,t))}processSaveResult(t){t&&(t instanceof Array?t.forEach((t=>this.processSaveResult(t))):t.dataUnit===this.name&&t.records.forEach((t=>{let s=t.oldRecord__id;delete t.oldRecord__id,void 0===s&&(s=t.record__id),this.records.forEach(((i,e)=>{i.record__id===s&&(this.records[e]=Object.assign(i,t))}))}))),this._store.dispatch(s(this.name,this.records.length-1)),this._store.dispatch({type:"FORM/CHANGESSAVED",payload:{dataUnit:this.name}})}processLoadResult(t){this.records=t,this._store.dispatch(s(this.name,this.records.length-1)),this._store.dispatch({type:"FORM/DATALOADED",payload:{dataUnit:this.name}})}processRemoveResult(t,i){t&&(this.records.splice(i,1),this._store.dispatch(s(this.name,this.records.length-1))),this._store.dispatch({type:"FORM/RECORDREMOVED",payload:{dataUnit:this.name}})}set records(t){this._records=t}get records(){return this._records||(this._records=[]),this._records}getCurrentRecord(){const t=d(this._store.getState(),this.name);return this.records[t]}getRecordChanges(t){return void 0===t&&(t=this.getCurrentRecord()),t?((t,s,i)=>{const e=o(t,this.name);return e?e[i]:void 0})(this._store.getState(),0,t.record__id):void 0}validateRecords(){if(!this.recordsValidator)return!0;const t=o(this._store.getState(),this.name),s=[];this.records.forEach(((i,e)=>{const h=t[i.record__id];h&&s.push(Object.assign(Object.assign(Object.assign({},i),h),{record__index:e,record__changedfields:Object.keys(h)}))}));const i=this.recordsValidator.validateRecords(this,s);return i.message&&alert(i.message),i.isValid}}export{u as D,a,l as b,i as c,t as d,r as e,e as f,h as i,n as s}