@sankhyalabs/ezui 4.0.3 → 4.1.0
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/dist/cjs/ez-form.cjs.entry.js +2 -2
- package/dist/cjs/ez-grid.cjs.entry.js +131 -4
- package/dist/cjs/ezui.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/ez-grid/ez-grid.css +52 -7
- package/dist/collection/components/ez-grid/ez-grid.js +105 -5
- package/dist/collection/components/ez-grid/subcomponents/selection-counter.js +23 -0
- package/dist/collection/utils/form/FormMetadata.js +2 -2
- package/dist/custom-elements/index.js +134 -7
- package/dist/esm/ez-form.entry.js +2 -2
- package/dist/esm/ez-grid.entry.js +133 -6
- package/dist/esm/ezui.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/ezui/ezui.esm.js +1 -1
- package/dist/ezui/{p-0e53898b.entry.js → p-08f4a048.entry.js} +1 -1
- package/dist/ezui/{p-dc15b6d1.entry.js → p-468799e1.entry.js} +2 -2
- package/dist/types/components/ez-grid/ez-grid.d.ts +16 -0
- package/dist/types/components/ez-grid/subcomponents/selection-counter.d.ts +12 -0
- package/dist/types/utils/form/interfaces/IFormConfig.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,c as e,h as i,f as n,H as s,g as r}from"./p-7ffd12e7.js";import{UserInterface as o,DateUtils as a,Action as l,WaitingChangeException as h,ApplicationContext as c,DataUnitAction as u,StringUtils as d,DataUnit as f,ElementIDUtils as v}from"@sankhyalabs/core";import{A as p}from"./p-efb43dd8.js";import"./p-ab574d59.js";const b=/child\[([^\]]+)\]/,m=/\$\{.+\}/;class g{constructor(){this._sheets=new Map,this._requiredFields=[],this._cleanOnCopyFields=[],this._defaultValues={}}static getDetailName(t){const e=b.exec(t);return e?e[1]:void 0}getSheet(t){return this._sheets.get(t)}getAllSheets(){return this._sheets}addSheet(t){this._sheets.set(t.name,t)}addRequiredFields(t){this._requiredFields=this._requiredFields.concat(t)}getRequiredFields(){return this._requiredFields}addCleanOnCopyFields(t){this._cleanOnCopyFields=this._cleanOnCopyFields.concat(t)}getCleanOnCopyFields(){return this._cleanOnCopyFields}addDefaultValues(t){return this._defaultValues=Object.assign(Object.assign({},this._defaultValues),t)}getDefaultValues(){const t={};return Object.entries(this._defaultValues).forEach((([e,i])=>{if("string"==typeof i){const t=m.exec(i);t&&(i=this.getDefaultVar(t[0]))}t[e]=i})),t}getDefaultVar(t){return"${data}"===t?a.getToday():"${datahora}"===t?a.getToday(!0):this._defaultVars?this._defaultVars.get(t):void 0}setDefaultVars(t){this._defaultVars=t}}const y=(t,e)=>"__main"==t[0].label?-1:(t[0].order||1e4)-(e[0].order||1e4);class _{constructor(t){this._invalidFields=new Map,this.onDataUnitEvent=t=>{var e;switch(t.type){case l.DATA_LOADED:case l.DATA_SAVED:case l.RECORDS_REMOVED:case l.RECORDS_ADDED:case l.RECORDS_COPIED:case l.EDITION_CANCELED:case l.SELECTION_CHANGED:case l.NEXT_SELECTED:case l.PREVIOUS_SELECTED:this.clearInvalid();case l.DATA_CHANGED:case l.CHANGE_UNDONE:case l.CHANGE_REDONE:case l.RECORD_LOADED:null===(e=this._fields)||void 0===e||e.forEach((t=>{this.updateValue(t.fieldName,t.field)}))}},this._fields=new Map,this._dataUnit=t,this._dataUnit.subscribe(this.onDataUnitEvent),this._dataUnit.addInterceptor(this)}bind(t,e,i,n){t.forEach((t=>{const{fieldName:i,contextName:n}=t.dataset;null!=n&&n!==e||this.updateBind(i,t)})),this._formMetadata=i,this._recordsValidator=n}onDisconnectedCallback(){this._dataUnit.unsubscribe(this.onDataUnitEvent),this._dataUnit.removeInterceptor(this)}markInvalid(t){if(this._invalidFields.set(t.name,t),this._fields.has(t.name)){const e=this._fields.get(t.name).field;e.errorMessage||this.updateErrorMessage(t.name,e)}}clearInvalid(){this._invalidFields.clear(),this._fields.forEach((t=>{t.field.errorMessage=""}))}updateValue(t,e){const i=this._fields.get(t);try{i&&(i.listen=!1),e.value=this._dataUnit.getFieldValue(t),this.updateErrorMessage(t,e)}finally{i&&(i.listen=!0)}}validate(){return new Promise(((t,e)=>{var i;const n=this._dataUnit.getModifiedRecords();for(let t=0;t<n.length;t++){const s=n[t],r=[];let o=this.validateRequired(s);if(o&&!o.isValid&&r.push(o),o=null===(i=this._recordsValidator)||void 0===i?void 0:i.validateRecord(s),o&&!o.isValid&&r.push(o),r.length>0){this.processValidationResult(r),e();break}}return t()}))}validateRequired(t){const e=this._formMetadata.getRequiredFields(),i=[];if(new Set(e).forEach((e=>{const n=t[e];if(null==n||""===n){const t=this.getErrorMessage(e);i.push(t?{name:e,message:t}:{name:e,message:"Essa informação é obrigatória"})}})),i.length>0)return{isValid:!1,invalidFields:i,infoMessage:"Há pelo menos um campo obrigatório não preenchido."}}processValidationResult(t){t.forEach((t=>{const e=t.invalidFields;if(e&&e.forEach((t=>{this.markInvalid(t)})),t.infoMessage&&p.info(t.infoMessage),t.errorMessage){const{errorTitle:e,errorMessage:i}=t;p.error(e,i)}}))}updateErrorMessage(t,e){const i=this._invalidFields.get(t);i&&(e.errorMessage=i.message)}getErrorMessage(t){if(this._fields.has(t))return this._fields.get(t).field.errorMessage||null}updateBind(t,e){const i=this._fields.get(t);i&&i.destroy(),e.value=this._dataUnit.getFieldValue(t),this.updateErrorMessage(t,e),this._fields.set(t,w.create(t,e,((t,e)=>this.changeStarted(t,e)),(t=>this.cancelWaitingChange(t)),((t,e)=>this.setFieldValue(t,e)))),this.bindSearchOptionsLoader(t,e),this.applyEzUploadContext(t,e)}changeStarted(t,e){if(0===this._dataUnit.records.length&&this._dataUnit.addRecord(),!e.blocking&&null==e.promise){const i=this._fields.get(t);i&&(e.promise=new Promise(((t,e)=>{i.waitingChangePromiseResolve=t,i.waitingChangePromiseReject=e})))}this._dataUnit.startChange(t,e)}cancelWaitingChange(t){if(this._dataUnit.waitingForChange(t)){this._dataUnit.cancelWaitingChange(t);const e=this._fields.get(t);e&&e.rejectWaitingChange(new h("Change canceled",t))}}setFieldValue(t,e){if(0===this._dataUnit.records.length&&this._dataUnit.addRecord(),this._invalidFields.delete(t),this._dataUnit.setFieldValue(t,e),this._dataUnit.waitingForChange(t)){const e=this._fields.get(t);e&&e.acceptWaitingChange()}}bindSearchOptionsLoader(t,e){if("EZ-SEARCH"===e.nodeName&&null==e.optionLoader){const i=c.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");i&&(e.optionLoader=e=>i(e,t,this._dataUnit))}}applyEzUploadContext(t,e){var i,n;if("EZ-UPLOAD"===e.nodeName){e.urlUpload=c.getContextValue("__EZUI__UPLOAD__ADD__URL__"),e.urlDelete=c.getContextValue("__EZUI__UPLOAD__DEL__URL__");const s=this._dataUnit.getField(t),r=null===(i=s.properties)||void 0===i?void 0:i.DESTINATION;r&&(e.requestHeaders={XTRAINF:`{"destination": "${r}"}`}),e.maxFiles=(null===(n=s.properties)||void 0===n?void 0:n.MAX_FILES)||0}}interceptAction(t){var e;if(t.type===l.RECORDS_COPIED){const e=this._formMetadata.getCleanOnCopyFields();if(e)return new u(l.RECORDS_COPIED,t.payload.map((t=>{const i=Object.assign({},t);return e.forEach((t=>delete i[t])),i})))}if(t.type===l.SAVING_DATA)return new Promise((e=>{this.validate().then((()=>e(t))).catch((()=>{}))}));if(t.type===l.RECORDS_ADDED){const i=null===(e=this._formMetadata)||void 0===e?void 0:e.getDefaultValues();if(i)return new u(l.RECORDS_ADDED,t.payload.map((t=>{const e=Object.assign({},t);for(const t in i){const n=this.getFormattedValue(i[t]),s="function"==typeof n?n():n;e[t]=this._dataUnit.valueFromString(t,s)}return e})))}return t}getFormattedValue(t){return null==t||"object"!=typeof t?t:"formattedValue"in t?t.formattedValue:t.value}}class w{constructor(){this.listen=!0,this.startChangeEventName="ezStartChange",this.cancelWaitingChangeEventName="ezCancelWaitingChange",this.changeEventName="ezChange"}destroy(){this.field.removeEventListener(this.startChangeEventName,this.startChangeListener),this.field.removeEventListener(this.cancelWaitingChangeEventName,this.cancelWaitingChangeListener),this.field.removeEventListener(this.changeEventName,this.changeListener)}acceptWaitingChange(){this.waitingChangePromiseResolve&&(this.waitingChangePromiseResolve(),this.waitingChangePromiseReject=void 0,this.waitingChangePromiseResolve=void 0)}rejectWaitingChange(t){this.waitingChangePromiseReject&&(this.waitingChangePromiseReject(t),this.waitingChangePromiseReject=void 0,this.waitingChangePromiseResolve=void 0)}static create(t,e,i,n,s){const r=new w;return r.field=e,r.fieldName=t,r.startChangeListener=e=>{r.listen&&i(t,e.detail)},r.field.addEventListener(r.startChangeEventName,r.startChangeListener),r.cancelWaitingChangeListener=()=>{r.listen&&n(t)},r.field.addEventListener(r.cancelWaitingChangeEventName,r.cancelWaitingChangeListener),r.changeListener=e=>{r.listen&&s(t,e.detail)},r.field.addEventListener(r.changeEventName,r.changeListener),r}}function E(t){return"Minified Redux error #"+t+"; visit https://redux.js.org/Errors?code="+t+" for the full message or use the non-minified dev environment for full errors. "}var O="function"==typeof Symbol&&Symbol.observable||"@@observable",C=function(){return Math.random().toString(36).substring(7).split("").join(".")},A={INIT:"@@redux/INIT"+C(),REPLACE:"@@redux/REPLACE"+C(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+C()}};function j(t){if("object"!=typeof t||null===t)return!1;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function R(t,e,i){var n;if("function"==typeof e&&"function"==typeof i||"function"==typeof i&&"function"==typeof arguments[3])throw new Error(E(0));if("function"==typeof e&&void 0===i&&(i=e,e=void 0),void 0!==i){if("function"!=typeof i)throw new Error(E(1));return i(R)(t,e)}if("function"!=typeof t)throw new Error(E(2));var s=t,r=e,o=[],a=o,l=!1;function h(){a===o&&(a=o.slice())}function c(){if(l)throw new Error(E(3));return r}function u(t){if("function"!=typeof t)throw new Error(E(4));if(l)throw new Error(E(5));var e=!0;return h(),a.push(t),function(){if(e){if(l)throw new Error(E(6));e=!1,h();var i=a.indexOf(t);a.splice(i,1),o=null}}}function d(t){if(!j(t))throw new Error(E(7));if(void 0===t.type)throw new Error(E(8));if(l)throw new Error(E(9));try{l=!0,r=s(r,t)}finally{l=!1}for(var e=o=a,i=0;i<e.length;i++)(0,e[i])();return t}function f(t){if("function"!=typeof t)throw new Error(E(10));s=t,d({type:A.REPLACE})}function v(){var t,e=u;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new Error(E(11));function i(){t.next&&t.next(c())}return i(),{unsubscribe:e(i)}}})[O]=function(){return this},t}return d({type:A.INIT}),(n={dispatch:d,subscribe:u,getState:c,replaceReducer:f})[O]=v,n}const z={};function D(t=z,e){switch(e.type){case M.METADATA_LOADED:return Object.assign(Object.assign({},t),{formMetadata:e.payload,currentSheet:void 0});case M.CHANGE_TAB:return Object.assign(Object.assign({},t),{currentSheet:e.payload});default:return t}}function x(t){return t.formMetadata}var M;!function(t){t.METADATA_LOADED="FORM/METADATA_LOADED",t.CHANGE_TAB="FORM/CHANGE_TAB"}(M||(M={}));const N=class{constructor(i){t(this,i),this.ezReady=e(this,"ezReady",7),this.onDataUnitAction=t=>{t.type===l.METADATA_LOADED&&this.processMetadata()},this.dataUnit=void 0,this.config=void 0,this.recordsValidator=void 0}validate(){return this._dataBinder.validate()}observeConfig(){this.processMetadata()}getDynamicContent(){var t;const e=x(this._store.getState());if(!e)return null;const n=Array.from(e.getAllSheets().values()),s=function(t){const e=function(t){return t.currentSheet}(t);return e?t.formMetadata.getSheet(e):Array.from(t.formMetadata.getAllSheets().values())[0]}(null===(t=this._store)||void 0===t?void 0:t.getState());let r=[];if(n.length>1){const t=n.map(((t,e)=>({tabKey:t.name,label:t.label,index:e}))),e="selector";r.push(i("ez-tabselector",{tabs:this.buildIdTabSelector(t),onEzChange:t=>this._store.dispatch(function(t){return{type:M.CHANGE_TAB,payload:"string"==typeof t?t:t.tabKey}}(t.detail)),selectedTab:s.name,"data-element-id":e}))}return r=r.concat(this.buildFormContent(s)),r}buildFormContent(t){const e=null==t?void 0:t.fields;if(null==t)return;const n=`${d.replaceAccentuatedChars(d.toCamelCase(null==t?void 0:t.label),!1)}_selectorContainer`;return i("div",{class:"dynamic-content","data-element-id":n},i("ez-form-view",{class:"ez-row ez-padding-vertical--small",fields:e}))}processMetadata(){if(!this.isStatic()&&this.dataUnit&&this._store){const t=((t,e,i=!1)=>{var n,s;null==t&&(t=(t=>{const e=t.metadata;let i;return e&&(i=e.fields.filter((t=>!1!==t.visible)).map((t=>({name:t.name,defaultValue:t.defaultValue})))),{fields:i}})(e));const r=new Map,a=new Map,l=[],h=[],c={};null===(n=null==t?void 0:t.tabs)||void 0===n||n.forEach((t=>{a.has(t.label)||!1!==t.visible||a.set(t.label,t)})),null===(s=null==t?void 0:t.fields)||void 0===s||s.forEach((t=>{var i,n,s;if(!1!==t.visible){const u=((t,e)=>("string"==typeof t?Array.from(e.keys()).find((e=>e.label===t)):t)||{label:t,visible:!0})(t.tab||"__main",r);if(a.has(u.label))return;const d=e.getField(t.name);if(d&&u.visible){r.has(u)||r.set(u,[]);const e=((t,e)=>{let i,n,{name:s,label:r,group:a}=Object.assign({},e),{readOnly:l,required:h}=Object.assign({},e);return t&&(r=r||t.label,s=s||t.name,h=t.required||(null==e?void 0:e.required),l=t.readOnly||(null==e?void 0:e.readOnly),i=t.properties,n=t.userInterface),{name:s,label:r,group:a,readOnly:l,required:h,props:i,userInterface:n||o.SHORTTEXT}})(d,t);r.get(u).push(e),e.required&&l.push(t.name),((null==t.cleanOnCopy?null===(i=d.properties)||void 0===i?void 0:i.cleanOnCopy:t.cleanOnCopy)||(null===(n=d.properties)||void 0===n?void 0:n.cleanOnCopy))&&h.push(t.name);let a=null==t.defaultValue?null===(s=d.properties)||void 0===s?void 0:s.defaultValue:t.defaultValue;a&&("object"==typeof a&&"V"===a.type&&(a=a.value),c[t.name]=a)}}}));const u=new g;if(u.setDefaultVars(t.defaultVars),i){const t=e.metadata;null!=t&&null!=t.children&&t.children.forEach((t=>{const{label:e,name:i,fields:n}=(t=>({name:`child[${t.name}]`,label:t.label,fields:[]}))(t);r.set({name:i,label:e},n)}))}return Array.from(r.entries()).sort(y).forEach((([t,e])=>{u.addSheet({label:"__main"===t.label?"Principal":t.label,name:t.name||t.label,fields:e})})),u.addRequiredFields(l),u.addCleanOnCopyFields(h),u.addDefaultValues(c),u})(this.config,this.dataUnit);this._store.dispatch({type:M.METADATA_LOADED,payload:t})}}isStatic(){var t;return(null===(t=this._staticFields)||void 0===t?void 0:t.length)>0}componentWillLoad(){void 0===this.dataUnit&&(this.dataUnit=new f("ez-form")),this.dataUnit.subscribe(this.onDataUnitAction),this._dataBinder=new _(this.dataUnit),this._store=R(D),this._store.subscribe((()=>n(this))),this._staticFields=Array.from(this._element.querySelectorAll("[data-field-name]")),this.processMetadata(),v.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}componentDidRender(){const t=x(this._store.getState());t.addRequiredFields(this._staticFields.filter((t=>t.dataset.required)).map((t=>t.dataset.fieldName))),this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")),this.dataUnit.dataUnitId,t,this.recordsValidator),this.ezReady.emit()}disconnectedCallback(){this.dataUnit.unsubscribe(this.onDataUnitAction),this._dataBinder.onDisconnectedCallback()}buildIdTabSelector(t){return t&&t.forEach((t=>t[v.DATA_ELEMENT_ID_ATTRIBUTE_NAME]=d.toCamelCase(t.label))),t}render(){return i(s,null,this.isStatic()?null:this.getDynamicContent())}get _element(){return r(this)}static get watchers(){return{config:["observeConfig"]}}};N.style=".sc-ez-form-h{display:flex;flex-direction:column;width:100%}.dynamic-content.sc-ez-form ez-collapsible-box.sc-ez-form{--ez-collapsible-box__header--padding-right:var(--space-small, 6px);--ez-collapsible-box__header--padding-left:var(--space-small, 6px)}";export{N as ez_form}
|
|
1
|
+
import{r as t,c as e,h as i,f as n,H as s,g as r}from"./p-7ffd12e7.js";import{UserInterface as o,DateUtils as a,Action as l,WaitingChangeException as h,ApplicationContext as c,DataUnitAction as u,StringUtils as d,DataUnit as f,ElementIDUtils as v}from"@sankhyalabs/core";import{A as p}from"./p-efb43dd8.js";import"./p-ab574d59.js";const b=/child\[([^\]]+)\]/,m=/\$\{.+\}/;class g{constructor(){this._sheets=new Map,this._requiredFields=[],this._cleanOnCopyFields=[],this._defaultValues={}}static getDetailName(t){const e=b.exec(t);return e?e[1]:void 0}getSheet(t){return this._sheets.get(t)}getAllSheets(){return this._sheets}addSheet(t){this._sheets.set(t.name,t)}addRequiredFields(t){this._requiredFields=this._requiredFields.concat(t)}getRequiredFields(){return this._requiredFields}addCleanOnCopyFields(t){this._cleanOnCopyFields=this._cleanOnCopyFields.concat(t)}getCleanOnCopyFields(){return this._cleanOnCopyFields}addDefaultValues(t){return this._defaultValues=Object.assign(Object.assign({},this._defaultValues),t)}getDefaultValues(){const t={};return Object.entries(this._defaultValues).forEach((([e,i])=>{if("string"==typeof i){const t=m.exec(i);t&&(i=this.getDefaultVar(t[0]))}t[e]=i})),t}getDefaultVar(t){return"${data}"===t?a.getToday():"${datahora}"===t?a.getToday(!0):this._defaultVars?this._defaultVars.get(t):void 0}setDefaultVars(t){this._defaultVars=t}}const y=(t,e)=>"__main"==t[0].label?-1:(t[0].order||1e4)-(e[0].order||1e4);class _{constructor(t){this._invalidFields=new Map,this.onDataUnitEvent=t=>{var e;switch(t.type){case l.DATA_LOADED:case l.DATA_SAVED:case l.RECORDS_REMOVED:case l.RECORDS_ADDED:case l.RECORDS_COPIED:case l.EDITION_CANCELED:case l.SELECTION_CHANGED:case l.NEXT_SELECTED:case l.PREVIOUS_SELECTED:this.clearInvalid();case l.DATA_CHANGED:case l.CHANGE_UNDONE:case l.CHANGE_REDONE:case l.RECORD_LOADED:null===(e=this._fields)||void 0===e||e.forEach((t=>{this.updateValue(t.fieldName,t.field)}))}},this._fields=new Map,this._dataUnit=t,this._dataUnit.subscribe(this.onDataUnitEvent),this._dataUnit.addInterceptor(this)}bind(t,e,i,n){t.forEach((t=>{const{fieldName:i,contextName:n}=t.dataset;null!=n&&n!==e||this.updateBind(i,t)})),this._formMetadata=i,this._recordsValidator=n}onDisconnectedCallback(){this._dataUnit.unsubscribe(this.onDataUnitEvent),this._dataUnit.removeInterceptor(this)}markInvalid(t){if(this._invalidFields.set(t.name,t),this._fields.has(t.name)){const e=this._fields.get(t.name).field;e.errorMessage||this.updateErrorMessage(t.name,e)}}clearInvalid(){this._invalidFields.clear(),this._fields.forEach((t=>{t.field.errorMessage=""}))}updateValue(t,e){const i=this._fields.get(t);try{i&&(i.listen=!1),e.value=this._dataUnit.getFieldValue(t),this.updateErrorMessage(t,e)}finally{i&&(i.listen=!0)}}validate(){return new Promise(((t,e)=>{var i;const n=this._dataUnit.getModifiedRecords();for(let t=0;t<n.length;t++){const s=n[t],r=[];let o=this.validateRequired(s);if(o&&!o.isValid&&r.push(o),o=null===(i=this._recordsValidator)||void 0===i?void 0:i.validateRecord(s),o&&!o.isValid&&r.push(o),r.length>0){this.processValidationResult(r),e();break}}return t()}))}validateRequired(t){const e=this._formMetadata.getRequiredFields(),i=[];if(new Set(e).forEach((e=>{const n=t[e];if(null==n||""===n){const t=this.getErrorMessage(e);i.push(t?{name:e,message:t}:{name:e,message:"Essa informação é obrigatória"})}})),i.length>0)return{isValid:!1,invalidFields:i,infoMessage:"Há pelo menos um campo obrigatório não preenchido."}}processValidationResult(t){t.forEach((t=>{const e=t.invalidFields;if(e&&e.forEach((t=>{this.markInvalid(t)})),t.infoMessage&&p.info(t.infoMessage),t.errorMessage){const{errorTitle:e,errorMessage:i}=t;p.error(e,i)}}))}updateErrorMessage(t,e){const i=this._invalidFields.get(t);i&&(e.errorMessage=i.message)}getErrorMessage(t){if(this._fields.has(t))return this._fields.get(t).field.errorMessage||null}updateBind(t,e){const i=this._fields.get(t);i&&i.destroy(),e.value=this._dataUnit.getFieldValue(t),this.updateErrorMessage(t,e),this._fields.set(t,w.create(t,e,((t,e)=>this.changeStarted(t,e)),(t=>this.cancelWaitingChange(t)),((t,e)=>this.setFieldValue(t,e)))),this.bindSearchOptionsLoader(t,e),this.applyEzUploadContext(t,e)}changeStarted(t,e){if(0===this._dataUnit.records.length&&this._dataUnit.addRecord(),!e.blocking&&null==e.promise){const i=this._fields.get(t);i&&(e.promise=new Promise(((t,e)=>{i.waitingChangePromiseResolve=t,i.waitingChangePromiseReject=e})))}this._dataUnit.startChange(t,e)}cancelWaitingChange(t){if(this._dataUnit.waitingForChange(t)){this._dataUnit.cancelWaitingChange(t);const e=this._fields.get(t);e&&e.rejectWaitingChange(new h("Change canceled",t))}}setFieldValue(t,e){if(0===this._dataUnit.records.length&&this._dataUnit.addRecord(),this._invalidFields.delete(t),this._dataUnit.setFieldValue(t,e),this._dataUnit.waitingForChange(t)){const e=this._fields.get(t);e&&e.acceptWaitingChange()}}bindSearchOptionsLoader(t,e){if("EZ-SEARCH"===e.nodeName&&null==e.optionLoader){const i=c.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");i&&(e.optionLoader=e=>i(e,t,this._dataUnit))}}applyEzUploadContext(t,e){var i,n;if("EZ-UPLOAD"===e.nodeName){e.urlUpload=c.getContextValue("__EZUI__UPLOAD__ADD__URL__"),e.urlDelete=c.getContextValue("__EZUI__UPLOAD__DEL__URL__");const s=this._dataUnit.getField(t),r=null===(i=s.properties)||void 0===i?void 0:i.DESTINATION;r&&(e.requestHeaders={XTRAINF:`{"destination": "${r}"}`}),e.maxFiles=(null===(n=s.properties)||void 0===n?void 0:n.MAX_FILES)||0}}interceptAction(t){var e;if(t.type===l.RECORDS_COPIED){const e=this._formMetadata.getCleanOnCopyFields();if(e)return new u(l.RECORDS_COPIED,t.payload.map((t=>{const i=Object.assign({},t);return e.forEach((t=>delete i[t])),i})))}if(t.type===l.SAVING_DATA)return new Promise((e=>{this.validate().then((()=>e(t))).catch((()=>{}))}));if(t.type===l.RECORDS_ADDED){const i=null===(e=this._formMetadata)||void 0===e?void 0:e.getDefaultValues();if(i)return new u(l.RECORDS_ADDED,t.payload.map((t=>{const e=Object.assign({},t);for(const t in i){const n=this.getFormattedValue(i[t]),s="function"==typeof n?n():n;e[t]=this._dataUnit.valueFromString(t,s)}return e})))}return t}getFormattedValue(t){return null==t||"object"!=typeof t?t:"formattedValue"in t?t.formattedValue:t.value}}class w{constructor(){this.listen=!0,this.startChangeEventName="ezStartChange",this.cancelWaitingChangeEventName="ezCancelWaitingChange",this.changeEventName="ezChange"}destroy(){this.field.removeEventListener(this.startChangeEventName,this.startChangeListener),this.field.removeEventListener(this.cancelWaitingChangeEventName,this.cancelWaitingChangeListener),this.field.removeEventListener(this.changeEventName,this.changeListener)}acceptWaitingChange(){this.waitingChangePromiseResolve&&(this.waitingChangePromiseResolve(),this.waitingChangePromiseReject=void 0,this.waitingChangePromiseResolve=void 0)}rejectWaitingChange(t){this.waitingChangePromiseReject&&(this.waitingChangePromiseReject(t),this.waitingChangePromiseReject=void 0,this.waitingChangePromiseResolve=void 0)}static create(t,e,i,n,s){const r=new w;return r.field=e,r.fieldName=t,r.startChangeListener=e=>{r.listen&&i(t,e.detail)},r.field.addEventListener(r.startChangeEventName,r.startChangeListener),r.cancelWaitingChangeListener=()=>{r.listen&&n(t)},r.field.addEventListener(r.cancelWaitingChangeEventName,r.cancelWaitingChangeListener),r.changeListener=e=>{r.listen&&s(t,e.detail)},r.field.addEventListener(r.changeEventName,r.changeListener),r}}function E(t){return"Minified Redux error #"+t+"; visit https://redux.js.org/Errors?code="+t+" for the full message or use the non-minified dev environment for full errors. "}var O="function"==typeof Symbol&&Symbol.observable||"@@observable",C=function(){return Math.random().toString(36).substring(7).split("").join(".")},A={INIT:"@@redux/INIT"+C(),REPLACE:"@@redux/REPLACE"+C(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+C()}};function j(t){if("object"!=typeof t||null===t)return!1;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function R(t,e,i){var n;if("function"==typeof e&&"function"==typeof i||"function"==typeof i&&"function"==typeof arguments[3])throw new Error(E(0));if("function"==typeof e&&void 0===i&&(i=e,e=void 0),void 0!==i){if("function"!=typeof i)throw new Error(E(1));return i(R)(t,e)}if("function"!=typeof t)throw new Error(E(2));var s=t,r=e,o=[],a=o,l=!1;function h(){a===o&&(a=o.slice())}function c(){if(l)throw new Error(E(3));return r}function u(t){if("function"!=typeof t)throw new Error(E(4));if(l)throw new Error(E(5));var e=!0;return h(),a.push(t),function(){if(e){if(l)throw new Error(E(6));e=!1,h();var i=a.indexOf(t);a.splice(i,1),o=null}}}function d(t){if(!j(t))throw new Error(E(7));if(void 0===t.type)throw new Error(E(8));if(l)throw new Error(E(9));try{l=!0,r=s(r,t)}finally{l=!1}for(var e=o=a,i=0;i<e.length;i++)(0,e[i])();return t}function f(t){if("function"!=typeof t)throw new Error(E(10));s=t,d({type:A.REPLACE})}function v(){var t,e=u;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new Error(E(11));function i(){t.next&&t.next(c())}return i(),{unsubscribe:e(i)}}})[O]=function(){return this},t}return d({type:A.INIT}),(n={dispatch:d,subscribe:u,getState:c,replaceReducer:f})[O]=v,n}const z={};function D(t=z,e){switch(e.type){case M.METADATA_LOADED:return Object.assign(Object.assign({},t),{formMetadata:e.payload,currentSheet:void 0});case M.CHANGE_TAB:return Object.assign(Object.assign({},t),{currentSheet:e.payload});default:return t}}function x(t){return t.formMetadata}var M;!function(t){t.METADATA_LOADED="FORM/METADATA_LOADED",t.CHANGE_TAB="FORM/CHANGE_TAB"}(M||(M={}));const N=class{constructor(i){t(this,i),this.ezReady=e(this,"ezReady",7),this.onDataUnitAction=t=>{t.type===l.METADATA_LOADED&&this.processMetadata()},this.dataUnit=void 0,this.config=void 0,this.recordsValidator=void 0}validate(){return this._dataBinder.validate()}observeConfig(){this.processMetadata()}getDynamicContent(){var t;const e=x(this._store.getState());if(!e)return null;const n=Array.from(e.getAllSheets().values()),s=function(t){const e=function(t){return t.currentSheet}(t);return e?t.formMetadata.getSheet(e):Array.from(t.formMetadata.getAllSheets().values())[0]}(null===(t=this._store)||void 0===t?void 0:t.getState());let r=[];if(n.length>1){const t=n.map(((t,e)=>({tabKey:t.name,label:t.label,index:e}))),e="selector";r.push(i("ez-tabselector",{tabs:this.buildIdTabSelector(t),onEzChange:t=>this._store.dispatch(function(t){return{type:M.CHANGE_TAB,payload:"string"==typeof t?t:t.tabKey}}(t.detail)),selectedTab:s.name,"data-element-id":e}))}return r=r.concat(this.buildFormContent(s)),r}buildFormContent(t){const e=null==t?void 0:t.fields;if(null==t)return;const n=`${d.replaceAccentuatedChars(d.toCamelCase(null==t?void 0:t.label),!1)}_selectorContainer`;return i("div",{class:"dynamic-content","data-element-id":n},i("ez-form-view",{class:"ez-row ez-padding-vertical--small",fields:e}))}processMetadata(){if(!this.isStatic()&&this.dataUnit&&this._store){const t=((t,e,i=!1)=>{var n,s;null!=t&&!0!==(null==t?void 0:t.emptyConfig)||(t=(t=>{const e=t.metadata;let i;return e&&(i=e.fields.filter((t=>!1!==t.visible)).map((t=>({name:t.name,defaultValue:t.defaultValue})))),{emptyConfig:!1,fields:i}})(e));const r=new Map,a=new Map,l=[],h=[],c={};null===(n=null==t?void 0:t.tabs)||void 0===n||n.forEach((t=>{a.has(t.label)||!1!==t.visible||a.set(t.label,t)})),null===(s=null==t?void 0:t.fields)||void 0===s||s.forEach((t=>{var i,n,s;if(!1!==t.visible){const u=((t,e)=>("string"==typeof t?Array.from(e.keys()).find((e=>e.label===t)):t)||{label:t,visible:!0})(t.tab||"__main",r);if(a.has(u.label))return;const d=e.getField(t.name);if(d&&u.visible){r.has(u)||r.set(u,[]);const e=((t,e)=>{let i,n,{name:s,label:r,group:a}=Object.assign({},e),{readOnly:l,required:h}=Object.assign({},e);return t&&(r=r||t.label,s=s||t.name,h=t.required||(null==e?void 0:e.required),l=t.readOnly||(null==e?void 0:e.readOnly),i=t.properties,n=t.userInterface),{name:s,label:r,group:a,readOnly:l,required:h,props:i,userInterface:n||o.SHORTTEXT}})(d,t);r.get(u).push(e),e.required&&l.push(t.name),((null==t.cleanOnCopy?null===(i=d.properties)||void 0===i?void 0:i.cleanOnCopy:t.cleanOnCopy)||(null===(n=d.properties)||void 0===n?void 0:n.cleanOnCopy))&&h.push(t.name);let a=null==t.defaultValue?null===(s=d.properties)||void 0===s?void 0:s.defaultValue:t.defaultValue;a&&("object"==typeof a&&"V"===a.type&&(a=a.value),c[t.name]=a)}}}));const u=new g;if(u.setDefaultVars(t.defaultVars),i){const t=e.metadata;null!=t&&null!=t.children&&t.children.forEach((t=>{const{label:e,name:i,fields:n}=(t=>({name:`child[${t.name}]`,label:t.label,fields:[]}))(t);r.set({name:i,label:e},n)}))}return Array.from(r.entries()).sort(y).forEach((([t,e])=>{u.addSheet({label:"__main"===t.label?"Principal":t.label,name:t.name||t.label,fields:e})})),u.addRequiredFields(l),u.addCleanOnCopyFields(h),u.addDefaultValues(c),u})(this.config,this.dataUnit);this._store.dispatch({type:M.METADATA_LOADED,payload:t})}}isStatic(){var t;return(null===(t=this._staticFields)||void 0===t?void 0:t.length)>0}componentWillLoad(){void 0===this.dataUnit&&(this.dataUnit=new f("ez-form")),this.dataUnit.subscribe(this.onDataUnitAction),this._dataBinder=new _(this.dataUnit),this._store=R(D),this._store.subscribe((()=>n(this))),this._staticFields=Array.from(this._element.querySelectorAll("[data-field-name]")),this.processMetadata(),v.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}componentDidRender(){const t=x(this._store.getState());t.addRequiredFields(this._staticFields.filter((t=>t.dataset.required)).map((t=>t.dataset.fieldName))),this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")),this.dataUnit.dataUnitId,t,this.recordsValidator),this.ezReady.emit()}disconnectedCallback(){this.dataUnit.unsubscribe(this.onDataUnitAction),this._dataBinder.onDisconnectedCallback()}buildIdTabSelector(t){return t&&t.forEach((t=>t[v.DATA_ELEMENT_ID_ATTRIBUTE_NAME]=d.toCamelCase(t.label))),t}render(){return i(s,null,this.isStatic()?null:this.getDynamicContent())}get _element(){return r(this)}static get watchers(){return{config:["observeConfig"]}}};N.style=".sc-ez-form-h{display:flex;flex-direction:column;width:100%}.dynamic-content.sc-ez-form ez-collapsible-box.sc-ez-form{--ez-collapsible-box__header--padding-right:var(--space-small, 6px);--ez-collapsible-box__header--padding-left:var(--space-small, 6px)}";export{N as ez_form}
|