@sankhyalabs/sankhyablocks 10.1.0-dev.54 → 10.1.0-dev.55

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.
Files changed (98) hide show
  1. package/dist/cjs/{ConfigStorage-4201dd3d.js → ConfigStorage-a28eceb2.js} +2 -2
  2. package/dist/cjs/{DataFetcher-b3a8075d.js → DataFetcher-98d95e8f.js} +0 -39
  3. package/dist/cjs/{ISave-4674c283.js → ISave-a9815bb3.js} +1 -1
  4. package/dist/cjs/{SnkFormConfigManager-c3a49038.js → SnkFormConfigManager-af47ba2f.js} +2 -2
  5. package/dist/cjs/{SnkMultiSelectionListDataSource-3a13fd34.js → SnkMultiSelectionListDataSource-83065af6.js} +4 -4
  6. package/dist/cjs/{auth-fetcher-0ecc53ff.js → auth-fetcher-9c257a1f.js} +1 -1
  7. package/dist/cjs/{dataunit-fetcher-c7e66f0d.js → dataunit-fetcher-afc246d8.js} +17 -105
  8. package/dist/cjs/{form-config-fetcher-f80dbc3b.js → form-config-fetcher-1ce4125c.js} +1 -1
  9. package/dist/cjs/pesquisa-grid_2.cjs.entry.js +4 -4
  10. package/dist/cjs/snk-actions-button_9.cjs.entry.js +5 -5
  11. package/dist/cjs/snk-application.cjs.entry.js +6 -6
  12. package/dist/cjs/snk-attach_11.cjs.entry.js +8 -8
  13. package/dist/cjs/snk-crud.cjs.entry.js +6 -6
  14. package/dist/cjs/snk-data-exporter.cjs.entry.js +5 -5
  15. package/dist/cjs/{snk-data-unit-35f10e01.js → snk-data-unit-ab570f87.js} +2 -2
  16. package/dist/cjs/snk-data-unit.cjs.entry.js +3 -3
  17. package/dist/cjs/snk-detail-view.cjs.entry.js +7 -7
  18. package/dist/cjs/snk-dynaform-detail-view_2.cjs.entry.js +7 -7
  19. package/dist/cjs/{snk-dynaform-guides-view-e98f7f3a.js → snk-dynaform-guides-view-30ce5a8c.js} +2 -2
  20. package/dist/cjs/snk-dynaform-guides-view.cjs.entry.js +4 -4
  21. package/dist/cjs/snk-dynaform.cjs.entry.js +6 -6
  22. package/dist/cjs/snk-filter-bar_4.cjs.entry.js +3 -3
  23. package/dist/cjs/snk-form_2.cjs.entry.js +4 -4
  24. package/dist/cjs/snk-grid.cjs.entry.js +6 -6
  25. package/dist/cjs/{snk-guides-viewer-3054d541.js → snk-guides-viewer-2a55fa3a.js} +1 -1
  26. package/dist/cjs/snk-guides-viewer.cjs.entry.js +5 -5
  27. package/dist/cjs/snk-layout-form-config.cjs.entry.js +4 -4
  28. package/dist/cjs/snk-pesquisa.cjs.entry.js +4 -4
  29. package/dist/cjs/{taskbarUtils-383c596e.js → taskbarUtils-4ca4235e.js} +4 -4
  30. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +1 -1
  31. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.js +15 -104
  32. package/dist/collection/lib/message/resources/en-us/dataUnitDataLoaderHelper.msg.js +0 -13
  33. package/dist/collection/lib/message/resources/es-es/dataUnitDataLoaderHelper.msg.js +0 -13
  34. package/dist/collection/lib/message/resources/pt-br/dataUnitDataLoaderHelper.msg.js +0 -13
  35. package/dist/components/SnkMessageBuilder.js +0 -39
  36. package/dist/components/dataunit-fetcher.js +16 -105
  37. package/dist/esm/{ConfigStorage-e834d1ea.js → ConfigStorage-346d781d.js} +2 -2
  38. package/dist/esm/{DataFetcher-5ed0a377.js → DataFetcher-7d8df5a2.js} +0 -39
  39. package/dist/esm/{ISave-5b46d691.js → ISave-2117075a.js} +1 -1
  40. package/dist/esm/{SnkFormConfigManager-bfd575c2.js → SnkFormConfigManager-066d370b.js} +2 -2
  41. package/dist/esm/{SnkMultiSelectionListDataSource-22b50dd6.js → SnkMultiSelectionListDataSource-c6c48bc9.js} +4 -4
  42. package/dist/esm/{auth-fetcher-5283045d.js → auth-fetcher-5891e22c.js} +1 -1
  43. package/dist/esm/{dataunit-fetcher-2200fdd6.js → dataunit-fetcher-5dcb0e89.js} +17 -105
  44. package/dist/esm/{form-config-fetcher-db1bf140.js → form-config-fetcher-8e2082f3.js} +1 -1
  45. package/dist/esm/pesquisa-grid_2.entry.js +4 -4
  46. package/dist/esm/snk-actions-button_9.entry.js +5 -5
  47. package/dist/esm/snk-application.entry.js +6 -6
  48. package/dist/esm/snk-attach_11.entry.js +8 -8
  49. package/dist/esm/snk-crud.entry.js +6 -6
  50. package/dist/esm/snk-data-exporter.entry.js +5 -5
  51. package/dist/esm/{snk-data-unit-e8bd4143.js → snk-data-unit-f697345b.js} +2 -2
  52. package/dist/esm/snk-data-unit.entry.js +3 -3
  53. package/dist/esm/snk-detail-view.entry.js +7 -7
  54. package/dist/esm/snk-dynaform-detail-view_2.entry.js +7 -7
  55. package/dist/esm/{snk-dynaform-guides-view-1f1455d6.js → snk-dynaform-guides-view-6aae38f7.js} +2 -2
  56. package/dist/esm/snk-dynaform-guides-view.entry.js +4 -4
  57. package/dist/esm/snk-dynaform.entry.js +6 -6
  58. package/dist/esm/snk-filter-bar_4.entry.js +3 -3
  59. package/dist/esm/snk-form_2.entry.js +4 -4
  60. package/dist/esm/snk-grid.entry.js +6 -6
  61. package/dist/esm/{snk-guides-viewer-95fefcaa.js → snk-guides-viewer-3ea7e312.js} +1 -1
  62. package/dist/esm/snk-guides-viewer.entry.js +5 -5
  63. package/dist/esm/snk-layout-form-config.entry.js +4 -4
  64. package/dist/esm/snk-pesquisa.entry.js +4 -4
  65. package/dist/esm/{taskbarUtils-682ca78c.js → taskbarUtils-a43e4bba.js} +4 -4
  66. package/dist/sankhyablocks/{p-5d02c032.js → p-10d883b0.js} +1 -1
  67. package/dist/sankhyablocks/{p-51e853f2.js → p-13f91e7e.js} +1 -1
  68. package/dist/sankhyablocks/{p-e5362a5c.js → p-1bc6849e.js} +1 -1
  69. package/dist/sankhyablocks/{p-06b6c284.entry.js → p-2d63e79d.entry.js} +1 -1
  70. package/dist/sankhyablocks/{p-b1bf9564.js → p-3190ac29.js} +2 -2
  71. package/dist/sankhyablocks/{p-c538bd6c.entry.js → p-3630a5ae.entry.js} +1 -1
  72. package/dist/sankhyablocks/{p-eff38390.entry.js → p-3cc67d50.entry.js} +1 -1
  73. package/dist/sankhyablocks/{p-92c71225.entry.js → p-4a53fbeb.entry.js} +1 -1
  74. package/dist/sankhyablocks/{p-1a04f537.js → p-4cc1d58b.js} +1 -1
  75. package/dist/sankhyablocks/{p-51f1485c.entry.js → p-536b988a.entry.js} +1 -1
  76. package/dist/sankhyablocks/{p-2b581179.entry.js → p-58e0f14b.entry.js} +1 -1
  77. package/dist/sankhyablocks/{p-09e2255b.entry.js → p-5a8390f9.entry.js} +1 -1
  78. package/dist/sankhyablocks/{p-670c43e3.entry.js → p-6f2de911.entry.js} +1 -1
  79. package/dist/sankhyablocks/{p-ccd61eb8.entry.js → p-741f1ad0.entry.js} +1 -1
  80. package/dist/sankhyablocks/{p-9c89a76a.entry.js → p-7827871d.entry.js} +1 -1
  81. package/dist/sankhyablocks/{p-22ddc1a5.entry.js → p-7e63af25.entry.js} +1 -1
  82. package/dist/sankhyablocks/{p-1cc4cf61.js → p-8d513b64.js} +1 -1
  83. package/dist/sankhyablocks/{p-589016e2.entry.js → p-a8a93568.entry.js} +1 -1
  84. package/dist/sankhyablocks/{p-dc45e9e5.entry.js → p-aa9d61fa.entry.js} +1 -1
  85. package/dist/sankhyablocks/{p-edd44079.entry.js → p-acd3adf9.entry.js} +1 -1
  86. package/dist/sankhyablocks/{p-dc83c70f.entry.js → p-b3762105.entry.js} +1 -1
  87. package/dist/sankhyablocks/p-c1e168a2.js +60 -0
  88. package/dist/sankhyablocks/{p-d5810110.js → p-c3bc693a.js} +1 -1
  89. package/dist/sankhyablocks/{p-70c2ee5c.js → p-c5889dae.js} +1 -1
  90. package/dist/sankhyablocks/{p-451b5bcc.entry.js → p-c6b6567f.entry.js} +1 -1
  91. package/dist/sankhyablocks/{p-d88278f8.js → p-d7657667.js} +1 -1
  92. package/dist/sankhyablocks/{p-2040953e.js → p-e91bd00e.js} +1 -1
  93. package/dist/sankhyablocks/{p-77c26de0.js → p-ed1b1b14.js} +1 -1
  94. package/dist/sankhyablocks/{p-ff28e5e4.entry.js → p-ee192f06.entry.js} +1 -1
  95. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  96. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/helpers/DataUnitDataLoaderHelper.d.ts +3 -1
  97. package/package.json +1 -1
  98. package/dist/sankhyablocks/p-5c6eede7.js +0 -60
@@ -1 +1 @@
1
- import{r as i,i as t,h as s,f as e,g as o,e as a}from"./p-2c9d0870.js";import{Action as n,StringUtils as r,KeyboardManager as d,ObjectUtils as h,ApplicationContext as l}from"@sankhyalabs/core";import{S as c,a as u}from"./p-77c26de0.js";import{buildFormMetadata as v,FormMetadata as f,buildFormConfigFromDataUnit as m}from"@sankhyalabs/ezui/dist/collection/utils/form";import{S as g}from"./p-5d02c032.js";import"./p-b1bf9564.js";import{P as p}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-5c6eede7.js";import"./p-ff1990ad.js";import{U as b}from"./p-d88278f8.js";import{V as y,a as k,G as w}from"./p-9019a32f.js";import{T as C}from"./p-3072136e.js";import{buildFieldSearch as S,SHORTCUT_SEARCH_FIELD as x,ApplicationUtils as _}from"@sankhyalabs/ezui/dist/collection/utils";import{S as F,D as A,g as T}from"./p-e5362a5c.js";import{b as z,a as D,c as G,d as E,g as L,u as N,e as M}from"./p-46d7e2de.js";import"./p-51e853f2.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-a73b6b00.js";const I=class{constructor(t){i(this,t),this._taskbarProcessor=new F(A),this._currentView=0,this.attachmentRegisterKey=void 0,this._fieldToGetFocus=void 0,this._hasToCreateFieldSearch=!0,this._selectedSheet=void 0,this._internalErrorTabs=new Set,this._selectedRecordPKDisplay=void 0,this.formConfigManager=void 0,this.dataUnitName=void 0,this.resourceID=void 0,this.entityName=void 0,this.label=void 0,this.dataUnit=void 0,this.selectedForm=void 0,this.dataState=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.customEditors=void 0,this.customRenders=void 0,this.presentationMode=p.SECONDARY}observeDataUnit(i,t){null==i||i.subscribe(this.dataUnitActionHandler.bind(this)),null==t||t.unsubscribe(this.dataUnitActionHandler)}observerDataState(i,t){const s=!(null==t?void 0:t.insertionMode)&&(null==i?void 0:i.insertionMode),e=(null==t?void 0:t.insertionMode)&&!(null==i?void 0:i.insertionMode);(s||e)&&this.loadMetadata(),null!=this._formMetadata&&(this.selectedSheetIsDetail()||(s&&setTimeout((()=>{this.changeViewMode(y.FORM)}),0),e&&this.changeViewMode(y.GRID)))}async changeViewMode(i){this._viewStack&&(this._viewStack.show(i),this._currentView=i)}async configGrid(){this._snkGrid&&this._snkGrid.showConfig()}async showUp(){this._snkFormView&&this._snkFormView.showUp(),this._snkGrid&&this._snkGrid.scrollIntoView({behavior:"smooth",block:"start"})}async addCustomEditor(i,t){var s,e;const o=this.normalizeDataUnitName();null===(s=this._snkGrid)||void 0===s||s.addCustomEditor(i,t,o),null===(e=this._snkFormView)||void 0===e||e.addCustomEditor(i,t,o)}async observerPropsCustomEditor(i){for(const t in i)await this.addCustomEditor(t,i[t])}async addGridCustomRender(i,t){var s;const e=this.normalizeDataUnitName();await(null===(s=this._snkGrid)||void 0===s?void 0:s.addGridCustomRender(i,t,e))}onContentCardChanged(i){c.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this.formConfigManager).then((()=>t(this))),i.stopPropagation()}async observeCustomRenders(i){for(const t in i){const s=i[t];await this.addGridCustomRender(t,s)}}loadMetadata(){if(!this.dataUnit||!this.formConfigManager)return;if(!this.formConfigManager.isLoaded)return;const i=this.formConfigManager.getConfig(this.dataUnit);this._formMetadata=v(null==i||0===i.fields.length?void 0:i,this.dataUnit,!0),this.initSelectedSheet()}initSelectedSheet(){if(!this._formMetadata)return void(this._selectedSheet=void 0);const i=this._formMetadata.getAllSheets();if(i&&0!==i.size){if(this._selectedSheet&&this._selectedSheet.name!==I.MAIN_TAB){const t=i.get(this._selectedSheet.name);if(t)return void(this._selectedSheet=t)}this._selectedSheet=this.getFirstNonMainSheet(i)}else this._selectedSheet=void 0}getFirstNonMainSheet(i){for(const[t,s]of i)if(t!==I.MAIN_TAB)return s}dataUnitReadyHandler(i){this.dataUnit=i.detail,this.loadMetadata()}getFormFields(){var i,t,s;const e=null===(t=null===(i=this._formMetadata)||void 0===i?void 0:i.getAllSheets())||void 0===t?void 0:t.get(I.MAIN_TAB);return null!==(s=null==e?void 0:e.fields)&&void 0!==s?s:[]}hasNonMainSheets(){if(!this._formMetadata)return!1;for(const i of this._formMetadata.getAllSheets().keys())if(i!==I.MAIN_TAB)return!0;return!1}selectedSheetIsDetail(){return!!this._selectedSheet&&null!=f.getDetailName(this._selectedSheet.name)}isSheetDisabled(i){var t;if(null==f.getDetailName(i.name))return!1;const s=null===(t=this.dataUnit)||void 0===t?void 0:t.getSelectedRecord();return!s||!this.dataUnit||this.dataUnit.isNewRecord(s.__record__id__)||this.dataUnit.isMultipleEdition}buildInternalTabItems(){return this._formMetadata?Array.from(this._formMetadata.getAllSheets().values()).filter((i=>i.name!==I.MAIN_TAB)).map(((i,t)=>({tabKey:i.name,label:i.label,index:t,disabled:this.isSheetDisabled(i),rightIcon:this._internalErrorTabs.has(i.name)?"alert-circle-inverted":void 0}))):[]}onInternalTabChange(i){var t,s;if(i.tabKey===I.MAIN_TAB)return;const e=null===(s=null===(t=this._formMetadata)||void 0===t?void 0:t.getAllSheets())||void 0===s?void 0:s.get(i.tabKey);e&&!this.isSheetDisabled(e)&&(this._selectedSheet=e)}executeActionHandler(i){var t;i.detail===C.GRID_MODE&&(this.changeViewMode(y.GRID),i.stopPropagation()),i.detail===C.UPDATE_MULTIPLE&&this.dataUnit&&(this.dataUnit.isMultipleEdition=!0,this.changeViewMode(y.FORM),i.stopPropagation()),i.detail!==C.FORM_MODE&&i.detail!==C.UPDATE&&i.detail!==C.INSERT||(this.changeViewMode(y.FORM),i.stopPropagation()),i.detail===C.ATTACH&&(null===(t=this._snkAttach)||void 0===t||t.open(),i.stopPropagation())}async getAttachmentRegisterKey(){if(this._snkDataUnit)return(await this._snkDataUnit.getSelectedRecordsIDsInfo()).map((({value:i})=>i)).join("_")}async handleDataStateChange({detail:i}){var t;this.dataState=i,void 0!==i.selectedRecord&&this._snkDataUnit&&(this.attachmentRegisterKey=null!==(t=await this.getAttachmentRegisterKey())&&void 0!==t?t:void 0),this._selectedRecordPKDisplay=this.buildSelectedRecordPKDisplay()}buildSelectedRecordPKDisplay(){var i,t,s,e,o,a,n;if(!this.dataUnit)return;if(null===(i=this.dataState)||void 0===i?void 0:i.insertionMode){const i=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkCrud.newRecord");return i?{message:i}:void 0}const r=this.dataUnit.getSelectedRecord();if(!r)return;const d=[],h=null!==(e=null===(s=this.dataUnit.metadata)||void 0===s?void 0:s.fields)&&void 0!==e?e:[];for(const i of h){if("true"!==(null===(o=i.properties)||void 0===o?void 0:o.isPrimaryKey))continue;const t=r[i.name],s=null!==(a=null==t?void 0:t.value)&&void 0!==a?a:t;null!=s&&""!==s&&d.push({label:null!==(n=i.label)&&void 0!==n?n:i.name,value:String(s)})}return d.length?{items:d}:void 0}renderSelectedRecordHeader(){var i;if(!this.label&&!this._selectedRecordPKDisplay)return;const t=this._selectedRecordPKDisplay;if(t){if(t.message)return s("div",{class:"selected-record-header selected-record-header--message"},s("span",{class:"selected-record-header__message"},t.message));if(null===(i=t.items)||void 0===i?void 0:i.length)return s("div",{class:"selected-record-header",role:"group"},t.items.map(((i,t)=>[t>0&&s("span",{class:"selected-record-header__separator","aria-hidden":"true"}),s("div",{class:"selected-record-header__chip"},s("span",{class:"selected-record-header__label"},i.label,":"),s("span",{class:"selected-record-header__value"},i.value))])))}}componentWillLoad(){var i;this._configName=`dynaform.${this.entityName}`,this.formConfigManager=new u(this._configName,null!==(i=this.resourceID)&&void 0!==i?i:"",(()=>this.loadMetadata()),this.dataUnit),this.formConfigManager.loadConfig(),null==this.messagesBuilder&&(this.messagesBuilder=new g(this.entityName))}componentWillRender(){this.initializeTaskbarProcessor()}initializeTaskbarProcessor(){if(!this.dataState)return;const i=this.buildDetailTaskbarManager(),t=T(this.dataState,this.presentationMode);this._taskbarProcessor.process(t,i,this.dataState,[],[])}buildDetailTaskbarManager(){const i=[C.CANCEL,C.SAVE],t=this._currentView;return{getButtons:(s,e,o)=>{var a,n,r;if(!s)return[];if((null==e?void 0:e.insertionMode)||(null==e?void 0:e.isDirty))return i;let d=[...o];if(t===y.FORM){const i=d.indexOf(C.FORM_MODE);i>-1&&(d=[...d.slice(0,i),C.GRID_MODE,...d.slice(i+1)])}if((null!==(r=null===(n=null===(a=null==e?void 0:e.selectionInfo)||void 0===a?void 0:a.records)||void 0===n?void 0:n.length)&&void 0!==r?r:0)>1){const i=d.indexOf(C.UPDATE);i>-1&&(d=[...d.slice(0,i),C.UPDATE_MULTIPLE,...d.slice(i+1)])}return d},isEnabled:(i,t,s,e)=>t?!(void 0===t.selectedRecord&&[C.UPDATE,C.REMOVE,C.ATTACH,C.CLONE].includes(s))&&!(s===C.PREVIOUS&&!t.hasPrevious)&&!(s===C.NEXT&&!t.hasNext)&&(s!==C.INSERT||!t.insertionMode)&&e:e}}async componentDidLoad(){this.customEditors&&await this.observerPropsCustomEditor(this.customEditors),this.customRenders&&await this.observeCustomRenders(this.customRenders),this.initKeyboardManager()}disconnectedCallback(){var i;null===(i=this._keyboardManager)||void 0===i||i.unbindAllShortcutKeys()}async dataUnitActionHandler(i){var t;if(i.type===n.FIELD_INVALIDATED){const s=this.findSheetOfField(null===(t=i.payload)||void 0===t?void 0:t.fieldName);s&&(this._internalErrorTabs=new Set([...this._internalErrorTabs,s]))}}findSheetOfField(i){var t;if(!i||!this._formMetadata)return;const s=this._formMetadata.getAllSheets();for(const[e,o]of s)if(null===(t=o.fields)||void 0===t?void 0:t.some((t=>t.name===i)))return e}normalizeDataUnitName(){var i,t;return null!==(t=null===(i=this.dataUnitName)||void 0===i?void 0:i.replace(/\//g,">"))&&void 0!==t?t:""}getSettingsListForm(){var i,t;return[{value:r.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkCrud.findColumn",void 0))&&void 0!==t?t:"",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getFieldsSearch(t)}]}getFieldsSearch(i){var t;return(void 0===this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._fieldSearch=S(i,(({argument:i})=>this.fieldsOptionLoader(i)),(i=>this.onSelectField(i)))),null!==(t=this._fieldSearch)&&void 0!==t?t:document.createElement("div")}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;if(i)return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>{if(i)return{value:i.name,label:i.label}}));return Promise.resolve(s)}onSelectField(i){null!=i&&(this._fieldToGetFocus=i.value)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}getColumnSearch(i){var t;return void 0!==this._columnSearch?this._columnSearch:(this._columnSearch=S(i,(({argument:i})=>new Promise((t=>{var s;null===(s=this._snkGrid)||void 0===s||s.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(i=>{var t;null!=i&&(null===(t=this._snkGrid)||void 0===t||t.locateColumn(i.value))})),null!==(t=this._columnSearch)&&void 0!==t?t:document.createElement("div"))}buildTaskbarCustomActionsList(){return[this.buildSearchColumnTaskbarAction()]}buildSearchColumnTaskbarAction(){var i,t;return{value:r.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkGrid.findColumn",{}))&&void 0!==t?t:"",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>{var s;return null!==(s=this.getColumnSearch(t))&&void 0!==s?s:document.createElement("div")}}}async initKeyboardManager(){var i;this._keyboardManager=new d({propagate:!1,element:this._element}),this._keyboardManager.bind(x,(async()=>{var i;await(null===(i=this._snkFormView)||void 0===i?void 0:i.showSearchField())}),{description:null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findFields"),element:this._element})}renderTabSelector(){if(!this.hasNonMainSheets())return;const i=this._selectedSheet&&this._selectedSheet.name!==I.MAIN_TAB?this._selectedSheet.name:void 0;return s("ez-tabselector",{class:"ez-tabselector-internal",tabs:this.buildInternalTabItems(),selectedTab:i,onEzChange:i=>this.onInternalTabChange(i.detail)})}renderSelectedSheetContent(){if(!this._selectedSheet||this._selectedSheet.name===I.MAIN_TAB)return;const i=f.getDetailName(this._selectedSheet.name);return i?s("snk-dynaform-detail-view",{key:`sub_${this.dataUnitName}_${this._selectedSheet.name}`,dataUnitName:`${this.dataUnitName}/${i}`,entityName:i,label:this._selectedSheet.label,resourceID:this.resourceID,canEdit:this.canEdit,messagesBuilder:this.messagesBuilder,customEditors:this.customEditors,customRenders:this.customRenders,presentationMode:this.presentationMode,taskbarCustomContainerId:this.taskbarCustomContainerId}):s("snk-dynaform-form-view",{key:`sheet_${this._selectedSheet.name}`,name:this._selectedSheet.name,formMetadata:this._formMetadata,dataUnit:this.dataUnit,fields:this._selectedSheet.fields,fieldToFocus:this._fieldToGetFocus,label:this._selectedSheet.label,onSnkRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),fieldSearch:this._fieldSearch})}renderViewStack(){var i,t;return s("ez-view-stack",{ref:i=>this._viewStack=i},s("stack-item",{class:"ez-size-width--full ez-size-height--full"},s("snk-grid",{class:"ez-size-width--full ez-size-height--full",ref:i=>{i&&(this._snkGrid=i)},configName:this._configName,messagesBuilder:this.messagesBuilder,onGridDoubleClick:()=>this.changeViewMode(y.FORM),onActionClick:i=>this.executeActionHandler(i),presentationMode:this.presentationMode,canEdit:this.canEdit,isDetail:!0,taskbarCustomContainerId:this.taskbarCustomContainerId,gridHeaderCustomSlotId:"DETAIL_GRID_HEADER_CUSTOM_ELEMENTS",topTaskbarCustomSlotId:"DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS",outlineMode:!0,enableGridInsert:!0,autoLoad:!0,multipleEditionEnabled:!0,multipleSelection:!0,hideHeader:!0,hideGridTaskbar:!0})),s("stack-item",{class:"ez-size-width--full ez-size-height--full grid-container"},s("div",{class:"form-and-detail-container"},s("snk-dynaform-form-view",{ref:i=>{i&&(this._snkFormView=i)},name:I.MAIN_TAB,formMetadata:this._formMetadata,dataUnit:this.dataUnit,fields:this.getFormFields(),fieldToFocus:this._fieldToGetFocus,label:this.label,onSnkRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),fieldSearch:this._fieldSearch},this.renderSelectedRecordHeader()),this.renderTabSelector(),this.renderSelectedSheetContent())),s("snk-attach",{ref:i=>this._snkAttach=i,registerKey:null!==(i=this.attachmentRegisterKey)&&void 0!==i?i:"",messagesBuilder:this.messagesBuilder,entityName:null!==(t=this.entityName)&&void 0!==t?t:""}))}render(){return s(e,null,s("snk-data-unit",{ref:i=>{i&&(this._snkDataUnit=i)},dataUnitName:`${this.dataUnitName}`,onDataUnitReady:i=>this.dataUnitReadyHandler(i),entityName:this.entityName,onDataStateChange:this.handleDataStateChange.bind(this),ignoreSaveMessage:this._currentView===y.GRID,messagesBuilder:this.messagesBuilder,configName:this._configName},s("snk-taskbar",{key:"detailViewTaskbar",class:"form-taskbar","data-element-id":"detail_top",configName:this._configName,messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,primaryButton:"INSERT",overflowStrategy:"hiddenItems",alignRigth:!0,sizeButtons:"small",presentationMode:this.presentationMode,onActionClick:i=>this.executeActionHandler(i),dataUnit:this.dataUnit,resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:"DETAIL_TASKBAR_CUSTOM_ELEMENTS",actionsSettingsList:this.getSettingsListForm(),customActionsList:this.buildTaskbarCustomActionsList()},s("slot",{name:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"})),this.renderViewStack()))}get _element(){return o(this)}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observerDataState"],customEditors:["observerPropsCustomEditor"],customRenders:["observeCustomRenders"]}}};I.MAIN_TAB="__main",I.style=".sc-snk-dynaform-detail-view-h{display:flex;row-gap:24px;flex-direction:column;width:100%;height:100%;overflow:hidden}.level-path.sc-snk-dynaform-detail-view{color:var(--color--title-primary, #2B3A54);font-weight:var(--text-weight--medium, 400);padding-right:3px}.grid-container.sc-snk-dynaform-detail-view{min-height:100px;height:100%;width:100%;display:flex;flex-wrap:wrap;text-decoration:none;border-radius:var(--border--radius-medium);background-color:var(--color--gray-70, #FFFFFF);border:1px solid var(--color--petroleum-100, #C8CCD3)}.detail-header.sc-snk-dynaform-detail-view{padding-bottom:0}snk-data-unit.sc-snk-dynaform-detail-view{flex:1;gap:var(--space--12, 12px);display:flex;flex-direction:column}snk-grid.sc-snk-dynaform-detail-view{height:100%;--snk-grid-margin:0px;--snk-grid-box-shadow:none}.form-and-detail-container.sc-snk-dynaform-detail-view{display:flex;flex-direction:column;height:100%;width:100%;overflow:auto;padding:var(--space--12, 12px)}.ez-tabselector-internal.sc-snk-dynaform-detail-view{margin:var(--space--8, 8px) 0}.selected-record-header.sc-snk-dynaform-detail-view{display:flex;align-items:center;flex-wrap:wrap;gap:var(--space--8, 8px) var(--space--12, 12px);padding:var(--space--12, 12px) var(--space--16, 16px);margin-bottom:var(--space--12, 12px);background:var(--color--gray-80, #F9F9F9);border-radius:var(--border--radius-12, 12px);font-family:var(--font--pattern);border:1px solid var(--color--petroleum-100, #C8CCD3);border-left:4px solid var(--color--ocean-green-500, #00B07E)}.selected-record-header--message.sc-snk-dynaform-detail-view{border-left-color:var(--color--primary, #007EFF)}.selected-record-header__message.sc-snk-dynaform-detail-view{font-size:var(--font-size--default, 14px);font-weight:var(--font-weight--medium, 500);color:var(--color--title-primary, #2B3A54)}.selected-record-header__chip.sc-snk-dynaform-detail-view{display:inline-flex;flex-direction:row;align-items:center;gap:var(--space--4, 4px);min-width:0}.selected-record-header__label.sc-snk-dynaform-detail-view{font-size:var(--font-size--xs, 11px);font-weight:var(--font-weight--medium, 500);text-transform:uppercase;letter-spacing:0.04em;color:var(--color--text-secondary, #6E7A8A)}.selected-record-header__value.sc-snk-dynaform-detail-view{font-size:var(--font-size--md, 15px);font-weight:var(--font-weight--semibold, 600);color:var(--color--ocean-green-1000, #00281D);line-height:1.2;word-break:break-word}.selected-record-header__separator.sc-snk-dynaform-detail-view{display:inline-block;align-self:stretch;width:1px;background:var(--color--petroleum-100, #C8CCD3);margin:0 var(--space--4, 4px)}";const R=class{constructor(t){i(this,t),this.configClose=a(this,"configClose",7),this.configChange=a(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.mainGuide=void 0,this.mainGroupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0,this.customGuidesConfig=[]}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,this.selectedGuide=void 0,await this.loadConfigByUser(),this.optionConfigChanged=!h.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===b.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t,s;const e=this.selectedGuide&&!this.selectedGuide.isCustom&&!this.selectedGuide.isDetail;e||!this.selectedGuide||!this.selectedGuide.isCustom&&!this.selectedGuide.isDetail?e||this.mainGuide?(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],e?await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i)):await(null===(s=this.refMainFieldsLayout)||void 0===s?void 0:s.addFieldToLayout(i))):this.showNoGuideSelectedDialog():this.showCanNotAddFieldToGuideDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t,s;if((null==i?void 0:i.name)&&(null===(t=this.mainGuide)||void 0===t?void 0:t.name)&&i.name===this.mainGuide.name)return void(this.selectedGuide=void 0);const e=null!==(s=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==s?s:[];this.groupsList=[...e]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");_.alert(i,t)}showCanNotAddFieldToGuideDialog(){const i=this.getMessage("snkFormConfig.canNotAddFieldToGuide.title"),t=this.getMessage("snkFormConfig.canNotAddFieldToGuide.message");_.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?b.DEFAULT:b.USER;this.configSelected=null==i?void 0:i.find((i=>i.origin===t)),this.originalConfigSelected=null==i?void 0:i.find((i=>i.origin===t))}catch(i){console.error(this.getMessage("snkFormConfig.errors.failFetchUserConfig")),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===b.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const o=t.some((({name:t})=>t===i));return o||!0!==e.visibleOnConfig||s?!0===s&&!1===o:e.visibleOnConfig}))}getInitialOrder(i){var t,s;return Array.isArray(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?null===(s=this._formConfig.tabs)||void 0===s?void 0:s.length:i.length>0?Math.max(...i.map((i=>i.order))):0}loadGuides(){var i,t,s,e;this.guidesList=[],this.guidesList.push(...z(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"),this.dataUnit,k.general)),this.guidesList.push(...D(this.dataUnit,this.getInitialOrder(this.guidesList),this.guidesList)),this.guidesList.push(...G(this.customGuidesConfig,this.guidesList)),this.guidesMap=E(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,k.general),this.mainGuide=this.guidesList.find((i=>i.name===k.main)),this.mainGroupsList=(null===(t=this.mainGuide)||void 0===t?void 0:t.name)?[...null!==(e=null===(s=this.guidesMap)||void 0===s?void 0:s.get(this.mainGuide.name))&&void 0!==e?e:[]]:[],this.ensureSelectedGuide()}ensureSelectedGuide(){if(this.selectedGuide&&this.guidesList.some((i=>i.name===this.selectedGuide.name)))return;const i=this.guidesList.filter((i=>{var t;return i.visible&&i.name!==(null===(t=this.mainGuide)||void 0===t?void 0:t.name)})).sort(((i,t)=>{var s,e;return(null!==(s=i.order)&&void 0!==s?s:Number.MAX_VALUE)-(null!==(e=t.order)&&void 0!==e?e:Number.MAX_VALUE)}))[0];this.selectedGuide=i}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=m(this.dataUnit)),h.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.selectedGuide&&(this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i]))}handleMainLayoutChanged({detail:i}){var t;(null===(t=this.mainGuide)||void 0===t?void 0:t.name)&&(this.hasChanges=!0,this.mainGroupsList=[...i],this.guidesMap.set(this.mainGuide.name,[...i]))}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===k.main?i.name:i.label,order:i.name===k.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?b.USER:b.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,_.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){const i=h.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=L(this.guidesMap),i.defaultConfiguration=this.getIsDefaultConfig(),i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,o=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=[];o.forEach((i=>a.push(...i.fields))),this.availableFields=[...this.availableFields,...a],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0,this.ensureSelectedGuide()),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=this.selectedGuide;if(!(null==s?void 0:s.name))return;const e=s.name,o=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=N(o,i);this.guidesMap.delete(e),this.guidesMap.set(i,a);const n={name:i,label:i,visible:s.visible,order:s.order};this.guidesList=[...this.guidesList.map((i=>i.name===e?n:i))],this.groupsList=[...a],this.selectedGuide=n,this.hasChanges=!0}handleCreateNewGuide(){const i=M(this.guidesList,this.getMessage.bind(this)),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:w.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=l.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){var i;return s(e,null,s("snk-dynaform-config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"form-config-body"},s("div",{class:"form-config-layout"},s("snk-dynaform-fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this),messagesBuilder:this.messagesBuilder}),s("div",{class:"main-editing-area"},this.mainGuide&&s("div",{class:"main-fields-section"},s("snk-dynaform-fields-layout",{ref:i=>this.refMainFieldsLayout=i,selectedGuide:this.mainGuide,guideNames:this.getGuideNames(),groupsList:this.mainGroupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,isMainSection:!0,onLayoutChanged:this.handleMainLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)})),s("snk-dynaform-guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,mainGuideName:null===(i=this.mainGuide)||void 0===i?void 0:i.name,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("snk-dynaform-fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)})))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};R.style='.sc-snk-dynaform-form-config-h{display:flex;flex-direction:column;height:100vh;width:100%;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.form-config-body.sc-snk-dynaform-form-config{height:var(--snk-form-config-container-height);overflow:hidden;padding-top:var(--space--12, 12px)}.form-config-layout.sc-snk-dynaform-form-config{display:flex;flex-direction:row;height:100%;gap:20px;align-items:stretch}.main-editing-area.sc-snk-dynaform-form-config{display:flex;flex-direction:column;flex:1;min-width:0;height:100%;overflow:hidden;gap:12px}.main-editing-area.sc-snk-dynaform-form-config>snk-dynaform-fields-layout.sc-snk-dynaform-form-config{flex:1 1 auto;min-height:0;overflow:auto;flex-direction:row}.main-editing-area.sc-snk-dynaform-form-config>snk-dynaform-guides-configurator.sc-snk-dynaform-form-config{flex:0 0 auto}.main-fields-section.sc-snk-dynaform-form-config{flex:0 0 40vh;display:flex;flex-direction:column;min-height:0;overflow:hidden}.guide-header.sc-snk-dynaform-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{I as snk_dynaform_detail_view,R as snk_dynaform_form_config}
1
+ import{r as i,i as t,h as s,f as e,g as o,e as a}from"./p-2c9d0870.js";import{Action as n,StringUtils as r,KeyboardManager as d,ObjectUtils as h,ApplicationContext as l}from"@sankhyalabs/core";import{S as c,a as u}from"./p-ed1b1b14.js";import{buildFormMetadata as v,FormMetadata as f,buildFormConfigFromDataUnit as m}from"@sankhyalabs/ezui/dist/collection/utils/form";import{S as g}from"./p-10d883b0.js";import"./p-3190ac29.js";import{P as p}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-c1e168a2.js";import"./p-ff1990ad.js";import{U as b}from"./p-d7657667.js";import{V as y,a as k,G as w}from"./p-9019a32f.js";import{T as C}from"./p-3072136e.js";import{buildFieldSearch as S,SHORTCUT_SEARCH_FIELD as x,ApplicationUtils as _}from"@sankhyalabs/ezui/dist/collection/utils";import{S as F,D as A,g as T}from"./p-1bc6849e.js";import{b as z,a as D,c as G,d as E,g as L,u as N,e as M}from"./p-46d7e2de.js";import"./p-13f91e7e.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-a73b6b00.js";const I=class{constructor(t){i(this,t),this._taskbarProcessor=new F(A),this._currentView=0,this.attachmentRegisterKey=void 0,this._fieldToGetFocus=void 0,this._hasToCreateFieldSearch=!0,this._selectedSheet=void 0,this._internalErrorTabs=new Set,this._selectedRecordPKDisplay=void 0,this.formConfigManager=void 0,this.dataUnitName=void 0,this.resourceID=void 0,this.entityName=void 0,this.label=void 0,this.dataUnit=void 0,this.selectedForm=void 0,this.dataState=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.customEditors=void 0,this.customRenders=void 0,this.presentationMode=p.SECONDARY}observeDataUnit(i,t){null==i||i.subscribe(this.dataUnitActionHandler.bind(this)),null==t||t.unsubscribe(this.dataUnitActionHandler)}observerDataState(i,t){const s=!(null==t?void 0:t.insertionMode)&&(null==i?void 0:i.insertionMode),e=(null==t?void 0:t.insertionMode)&&!(null==i?void 0:i.insertionMode);(s||e)&&this.loadMetadata(),null!=this._formMetadata&&(this.selectedSheetIsDetail()||(s&&setTimeout((()=>{this.changeViewMode(y.FORM)}),0),e&&this.changeViewMode(y.GRID)))}async changeViewMode(i){this._viewStack&&(this._viewStack.show(i),this._currentView=i)}async configGrid(){this._snkGrid&&this._snkGrid.showConfig()}async showUp(){this._snkFormView&&this._snkFormView.showUp(),this._snkGrid&&this._snkGrid.scrollIntoView({behavior:"smooth",block:"start"})}async addCustomEditor(i,t){var s,e;const o=this.normalizeDataUnitName();null===(s=this._snkGrid)||void 0===s||s.addCustomEditor(i,t,o),null===(e=this._snkFormView)||void 0===e||e.addCustomEditor(i,t,o)}async observerPropsCustomEditor(i){for(const t in i)await this.addCustomEditor(t,i[t])}async addGridCustomRender(i,t){var s;const e=this.normalizeDataUnitName();await(null===(s=this._snkGrid)||void 0===s?void 0:s.addGridCustomRender(i,t,e))}onContentCardChanged(i){c.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this.formConfigManager).then((()=>t(this))),i.stopPropagation()}async observeCustomRenders(i){for(const t in i){const s=i[t];await this.addGridCustomRender(t,s)}}loadMetadata(){if(!this.dataUnit||!this.formConfigManager)return;if(!this.formConfigManager.isLoaded)return;const i=this.formConfigManager.getConfig(this.dataUnit);this._formMetadata=v(null==i||0===i.fields.length?void 0:i,this.dataUnit,!0),this.initSelectedSheet()}initSelectedSheet(){if(!this._formMetadata)return void(this._selectedSheet=void 0);const i=this._formMetadata.getAllSheets();if(i&&0!==i.size){if(this._selectedSheet&&this._selectedSheet.name!==I.MAIN_TAB){const t=i.get(this._selectedSheet.name);if(t)return void(this._selectedSheet=t)}this._selectedSheet=this.getFirstNonMainSheet(i)}else this._selectedSheet=void 0}getFirstNonMainSheet(i){for(const[t,s]of i)if(t!==I.MAIN_TAB)return s}dataUnitReadyHandler(i){this.dataUnit=i.detail,this.loadMetadata()}getFormFields(){var i,t,s;const e=null===(t=null===(i=this._formMetadata)||void 0===i?void 0:i.getAllSheets())||void 0===t?void 0:t.get(I.MAIN_TAB);return null!==(s=null==e?void 0:e.fields)&&void 0!==s?s:[]}hasNonMainSheets(){if(!this._formMetadata)return!1;for(const i of this._formMetadata.getAllSheets().keys())if(i!==I.MAIN_TAB)return!0;return!1}selectedSheetIsDetail(){return!!this._selectedSheet&&null!=f.getDetailName(this._selectedSheet.name)}isSheetDisabled(i){var t;if(null==f.getDetailName(i.name))return!1;const s=null===(t=this.dataUnit)||void 0===t?void 0:t.getSelectedRecord();return!s||!this.dataUnit||this.dataUnit.isNewRecord(s.__record__id__)||this.dataUnit.isMultipleEdition}buildInternalTabItems(){return this._formMetadata?Array.from(this._formMetadata.getAllSheets().values()).filter((i=>i.name!==I.MAIN_TAB)).map(((i,t)=>({tabKey:i.name,label:i.label,index:t,disabled:this.isSheetDisabled(i),rightIcon:this._internalErrorTabs.has(i.name)?"alert-circle-inverted":void 0}))):[]}onInternalTabChange(i){var t,s;if(i.tabKey===I.MAIN_TAB)return;const e=null===(s=null===(t=this._formMetadata)||void 0===t?void 0:t.getAllSheets())||void 0===s?void 0:s.get(i.tabKey);e&&!this.isSheetDisabled(e)&&(this._selectedSheet=e)}executeActionHandler(i){var t;i.detail===C.GRID_MODE&&(this.changeViewMode(y.GRID),i.stopPropagation()),i.detail===C.UPDATE_MULTIPLE&&this.dataUnit&&(this.dataUnit.isMultipleEdition=!0,this.changeViewMode(y.FORM),i.stopPropagation()),i.detail!==C.FORM_MODE&&i.detail!==C.UPDATE&&i.detail!==C.INSERT||(this.changeViewMode(y.FORM),i.stopPropagation()),i.detail===C.ATTACH&&(null===(t=this._snkAttach)||void 0===t||t.open(),i.stopPropagation())}async getAttachmentRegisterKey(){if(this._snkDataUnit)return(await this._snkDataUnit.getSelectedRecordsIDsInfo()).map((({value:i})=>i)).join("_")}async handleDataStateChange({detail:i}){var t;this.dataState=i,void 0!==i.selectedRecord&&this._snkDataUnit&&(this.attachmentRegisterKey=null!==(t=await this.getAttachmentRegisterKey())&&void 0!==t?t:void 0),this._selectedRecordPKDisplay=this.buildSelectedRecordPKDisplay()}buildSelectedRecordPKDisplay(){var i,t,s,e,o,a,n;if(!this.dataUnit)return;if(null===(i=this.dataState)||void 0===i?void 0:i.insertionMode){const i=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkCrud.newRecord");return i?{message:i}:void 0}const r=this.dataUnit.getSelectedRecord();if(!r)return;const d=[],h=null!==(e=null===(s=this.dataUnit.metadata)||void 0===s?void 0:s.fields)&&void 0!==e?e:[];for(const i of h){if("true"!==(null===(o=i.properties)||void 0===o?void 0:o.isPrimaryKey))continue;const t=r[i.name],s=null!==(a=null==t?void 0:t.value)&&void 0!==a?a:t;null!=s&&""!==s&&d.push({label:null!==(n=i.label)&&void 0!==n?n:i.name,value:String(s)})}return d.length?{items:d}:void 0}renderSelectedRecordHeader(){var i;if(!this.label&&!this._selectedRecordPKDisplay)return;const t=this._selectedRecordPKDisplay;if(t){if(t.message)return s("div",{class:"selected-record-header selected-record-header--message"},s("span",{class:"selected-record-header__message"},t.message));if(null===(i=t.items)||void 0===i?void 0:i.length)return s("div",{class:"selected-record-header",role:"group"},t.items.map(((i,t)=>[t>0&&s("span",{class:"selected-record-header__separator","aria-hidden":"true"}),s("div",{class:"selected-record-header__chip"},s("span",{class:"selected-record-header__label"},i.label,":"),s("span",{class:"selected-record-header__value"},i.value))])))}}componentWillLoad(){var i;this._configName=`dynaform.${this.entityName}`,this.formConfigManager=new u(this._configName,null!==(i=this.resourceID)&&void 0!==i?i:"",(()=>this.loadMetadata()),this.dataUnit),this.formConfigManager.loadConfig(),null==this.messagesBuilder&&(this.messagesBuilder=new g(this.entityName))}componentWillRender(){this.initializeTaskbarProcessor()}initializeTaskbarProcessor(){if(!this.dataState)return;const i=this.buildDetailTaskbarManager(),t=T(this.dataState,this.presentationMode);this._taskbarProcessor.process(t,i,this.dataState,[],[])}buildDetailTaskbarManager(){const i=[C.CANCEL,C.SAVE],t=this._currentView;return{getButtons:(s,e,o)=>{var a,n,r;if(!s)return[];if((null==e?void 0:e.insertionMode)||(null==e?void 0:e.isDirty))return i;let d=[...o];if(t===y.FORM){const i=d.indexOf(C.FORM_MODE);i>-1&&(d=[...d.slice(0,i),C.GRID_MODE,...d.slice(i+1)])}if((null!==(r=null===(n=null===(a=null==e?void 0:e.selectionInfo)||void 0===a?void 0:a.records)||void 0===n?void 0:n.length)&&void 0!==r?r:0)>1){const i=d.indexOf(C.UPDATE);i>-1&&(d=[...d.slice(0,i),C.UPDATE_MULTIPLE,...d.slice(i+1)])}return d},isEnabled:(i,t,s,e)=>t?!(void 0===t.selectedRecord&&[C.UPDATE,C.REMOVE,C.ATTACH,C.CLONE].includes(s))&&!(s===C.PREVIOUS&&!t.hasPrevious)&&!(s===C.NEXT&&!t.hasNext)&&(s!==C.INSERT||!t.insertionMode)&&e:e}}async componentDidLoad(){this.customEditors&&await this.observerPropsCustomEditor(this.customEditors),this.customRenders&&await this.observeCustomRenders(this.customRenders),this.initKeyboardManager()}disconnectedCallback(){var i;null===(i=this._keyboardManager)||void 0===i||i.unbindAllShortcutKeys()}async dataUnitActionHandler(i){var t;if(i.type===n.FIELD_INVALIDATED){const s=this.findSheetOfField(null===(t=i.payload)||void 0===t?void 0:t.fieldName);s&&(this._internalErrorTabs=new Set([...this._internalErrorTabs,s]))}}findSheetOfField(i){var t;if(!i||!this._formMetadata)return;const s=this._formMetadata.getAllSheets();for(const[e,o]of s)if(null===(t=o.fields)||void 0===t?void 0:t.some((t=>t.name===i)))return e}normalizeDataUnitName(){var i,t;return null!==(t=null===(i=this.dataUnitName)||void 0===i?void 0:i.replace(/\//g,">"))&&void 0!==t?t:""}getSettingsListForm(){var i,t;return[{value:r.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkCrud.findColumn",void 0))&&void 0!==t?t:"",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getFieldsSearch(t)}]}getFieldsSearch(i){var t;return(void 0===this._fieldSearch||this._hasToCreateFieldSearch)&&(this._hasToCreateFieldSearch=!1,this._fieldSearch=S(i,(({argument:i})=>this.fieldsOptionLoader(i)),(i=>this.onSelectField(i)))),null!==(t=this._fieldSearch)&&void 0!==t?t:document.createElement("div")}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;if(i)return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>{if(i)return{value:i.name,label:i.label}}));return Promise.resolve(s)}onSelectField(i){null!=i&&(this._fieldToGetFocus=i.value)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}getColumnSearch(i){var t;return void 0!==this._columnSearch?this._columnSearch:(this._columnSearch=S(i,(({argument:i})=>new Promise((t=>{var s;null===(s=this._snkGrid)||void 0===s||s.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(i=>{var t;null!=i&&(null===(t=this._snkGrid)||void 0===t||t.locateColumn(i.value))})),null!==(t=this._columnSearch)&&void 0!==t?t:document.createElement("div"))}buildTaskbarCustomActionsList(){return[this.buildSearchColumnTaskbarAction()]}buildSearchColumnTaskbarAction(){var i,t;return{value:r.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkGrid.findColumn",{}))&&void 0!==t?t:"",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>{var s;return null!==(s=this.getColumnSearch(t))&&void 0!==s?s:document.createElement("div")}}}async initKeyboardManager(){var i;this._keyboardManager=new d({propagate:!1,element:this._element}),this._keyboardManager.bind(x,(async()=>{var i;await(null===(i=this._snkFormView)||void 0===i?void 0:i.showSearchField())}),{description:null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findFields"),element:this._element})}renderTabSelector(){if(!this.hasNonMainSheets())return;const i=this._selectedSheet&&this._selectedSheet.name!==I.MAIN_TAB?this._selectedSheet.name:void 0;return s("ez-tabselector",{class:"ez-tabselector-internal",tabs:this.buildInternalTabItems(),selectedTab:i,onEzChange:i=>this.onInternalTabChange(i.detail)})}renderSelectedSheetContent(){if(!this._selectedSheet||this._selectedSheet.name===I.MAIN_TAB)return;const i=f.getDetailName(this._selectedSheet.name);return i?s("snk-dynaform-detail-view",{key:`sub_${this.dataUnitName}_${this._selectedSheet.name}`,dataUnitName:`${this.dataUnitName}/${i}`,entityName:i,label:this._selectedSheet.label,resourceID:this.resourceID,canEdit:this.canEdit,messagesBuilder:this.messagesBuilder,customEditors:this.customEditors,customRenders:this.customRenders,presentationMode:this.presentationMode,taskbarCustomContainerId:this.taskbarCustomContainerId}):s("snk-dynaform-form-view",{key:`sheet_${this._selectedSheet.name}`,name:this._selectedSheet.name,formMetadata:this._formMetadata,dataUnit:this.dataUnit,fields:this._selectedSheet.fields,fieldToFocus:this._fieldToGetFocus,label:this._selectedSheet.label,onSnkRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),fieldSearch:this._fieldSearch})}renderViewStack(){var i,t;return s("ez-view-stack",{ref:i=>this._viewStack=i},s("stack-item",{class:"ez-size-width--full ez-size-height--full"},s("snk-grid",{class:"ez-size-width--full ez-size-height--full",ref:i=>{i&&(this._snkGrid=i)},configName:this._configName,messagesBuilder:this.messagesBuilder,onGridDoubleClick:()=>this.changeViewMode(y.FORM),onActionClick:i=>this.executeActionHandler(i),presentationMode:this.presentationMode,canEdit:this.canEdit,isDetail:!0,taskbarCustomContainerId:this.taskbarCustomContainerId,gridHeaderCustomSlotId:"DETAIL_GRID_HEADER_CUSTOM_ELEMENTS",topTaskbarCustomSlotId:"DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS",outlineMode:!0,enableGridInsert:!0,autoLoad:!0,multipleEditionEnabled:!0,multipleSelection:!0,hideHeader:!0,hideGridTaskbar:!0})),s("stack-item",{class:"ez-size-width--full ez-size-height--full grid-container"},s("div",{class:"form-and-detail-container"},s("snk-dynaform-form-view",{ref:i=>{i&&(this._snkFormView=i)},name:I.MAIN_TAB,formMetadata:this._formMetadata,dataUnit:this.dataUnit,fields:this.getFormFields(),fieldToFocus:this._fieldToGetFocus,label:this.label,onSnkRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),fieldSearch:this._fieldSearch},this.renderSelectedRecordHeader()),this.renderTabSelector(),this.renderSelectedSheetContent())),s("snk-attach",{ref:i=>this._snkAttach=i,registerKey:null!==(i=this.attachmentRegisterKey)&&void 0!==i?i:"",messagesBuilder:this.messagesBuilder,entityName:null!==(t=this.entityName)&&void 0!==t?t:""}))}render(){return s(e,null,s("snk-data-unit",{ref:i=>{i&&(this._snkDataUnit=i)},dataUnitName:`${this.dataUnitName}`,onDataUnitReady:i=>this.dataUnitReadyHandler(i),entityName:this.entityName,onDataStateChange:this.handleDataStateChange.bind(this),ignoreSaveMessage:this._currentView===y.GRID,messagesBuilder:this.messagesBuilder,configName:this._configName},s("snk-taskbar",{key:"detailViewTaskbar",class:"form-taskbar","data-element-id":"detail_top",configName:this._configName,messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,primaryButton:"INSERT",overflowStrategy:"hiddenItems",alignRigth:!0,sizeButtons:"small",presentationMode:this.presentationMode,onActionClick:i=>this.executeActionHandler(i),dataUnit:this.dataUnit,resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:"DETAIL_TASKBAR_CUSTOM_ELEMENTS",actionsSettingsList:this.getSettingsListForm(),customActionsList:this.buildTaskbarCustomActionsList()},s("slot",{name:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"})),this.renderViewStack()))}get _element(){return o(this)}static get watchers(){return{dataUnit:["observeDataUnit"],dataState:["observerDataState"],customEditors:["observerPropsCustomEditor"],customRenders:["observeCustomRenders"]}}};I.MAIN_TAB="__main",I.style=".sc-snk-dynaform-detail-view-h{display:flex;row-gap:24px;flex-direction:column;width:100%;height:100%;overflow:hidden}.level-path.sc-snk-dynaform-detail-view{color:var(--color--title-primary, #2B3A54);font-weight:var(--text-weight--medium, 400);padding-right:3px}.grid-container.sc-snk-dynaform-detail-view{min-height:100px;height:100%;width:100%;display:flex;flex-wrap:wrap;text-decoration:none;border-radius:var(--border--radius-medium);background-color:var(--color--gray-70, #FFFFFF);border:1px solid var(--color--petroleum-100, #C8CCD3)}.detail-header.sc-snk-dynaform-detail-view{padding-bottom:0}snk-data-unit.sc-snk-dynaform-detail-view{flex:1;gap:var(--space--12, 12px);display:flex;flex-direction:column}snk-grid.sc-snk-dynaform-detail-view{height:100%;--snk-grid-margin:0px;--snk-grid-box-shadow:none}.form-and-detail-container.sc-snk-dynaform-detail-view{display:flex;flex-direction:column;height:100%;width:100%;overflow:auto;padding:var(--space--12, 12px)}.ez-tabselector-internal.sc-snk-dynaform-detail-view{margin:var(--space--8, 8px) 0}.selected-record-header.sc-snk-dynaform-detail-view{display:flex;align-items:center;flex-wrap:wrap;gap:var(--space--8, 8px) var(--space--12, 12px);padding:var(--space--12, 12px) var(--space--16, 16px);margin-bottom:var(--space--12, 12px);background:var(--color--gray-80, #F9F9F9);border-radius:var(--border--radius-12, 12px);font-family:var(--font--pattern);border:1px solid var(--color--petroleum-100, #C8CCD3);border-left:4px solid var(--color--ocean-green-500, #00B07E)}.selected-record-header--message.sc-snk-dynaform-detail-view{border-left-color:var(--color--primary, #007EFF)}.selected-record-header__message.sc-snk-dynaform-detail-view{font-size:var(--font-size--default, 14px);font-weight:var(--font-weight--medium, 500);color:var(--color--title-primary, #2B3A54)}.selected-record-header__chip.sc-snk-dynaform-detail-view{display:inline-flex;flex-direction:row;align-items:center;gap:var(--space--4, 4px);min-width:0}.selected-record-header__label.sc-snk-dynaform-detail-view{font-size:var(--font-size--xs, 11px);font-weight:var(--font-weight--medium, 500);text-transform:uppercase;letter-spacing:0.04em;color:var(--color--text-secondary, #6E7A8A)}.selected-record-header__value.sc-snk-dynaform-detail-view{font-size:var(--font-size--md, 15px);font-weight:var(--font-weight--semibold, 600);color:var(--color--ocean-green-1000, #00281D);line-height:1.2;word-break:break-word}.selected-record-header__separator.sc-snk-dynaform-detail-view{display:inline-block;align-self:stretch;width:1px;background:var(--color--petroleum-100, #C8CCD3);margin:0 var(--space--4, 4px)}";const R=class{constructor(t){i(this,t),this.configClose=a(this,"configClose",7),this.configChange=a(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.mainGuide=void 0,this.mainGroupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0,this.customGuidesConfig=[]}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,this.selectedGuide=void 0,await this.loadConfigByUser(),this.optionConfigChanged=!h.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===b.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t,s;const e=this.selectedGuide&&!this.selectedGuide.isCustom&&!this.selectedGuide.isDetail;e||!this.selectedGuide||!this.selectedGuide.isCustom&&!this.selectedGuide.isDetail?e||this.mainGuide?(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],e?await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i)):await(null===(s=this.refMainFieldsLayout)||void 0===s?void 0:s.addFieldToLayout(i))):this.showNoGuideSelectedDialog():this.showCanNotAddFieldToGuideDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t,s;if((null==i?void 0:i.name)&&(null===(t=this.mainGuide)||void 0===t?void 0:t.name)&&i.name===this.mainGuide.name)return void(this.selectedGuide=void 0);const e=null!==(s=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==s?s:[];this.groupsList=[...e]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");_.alert(i,t)}showCanNotAddFieldToGuideDialog(){const i=this.getMessage("snkFormConfig.canNotAddFieldToGuide.title"),t=this.getMessage("snkFormConfig.canNotAddFieldToGuide.message");_.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?b.DEFAULT:b.USER;this.configSelected=null==i?void 0:i.find((i=>i.origin===t)),this.originalConfigSelected=null==i?void 0:i.find((i=>i.origin===t))}catch(i){console.error(this.getMessage("snkFormConfig.errors.failFetchUserConfig")),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===b.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const o=t.some((({name:t})=>t===i));return o||!0!==e.visibleOnConfig||s?!0===s&&!1===o:e.visibleOnConfig}))}getInitialOrder(i){var t,s;return Array.isArray(null===(t=this._formConfig)||void 0===t?void 0:t.tabs)?null===(s=this._formConfig.tabs)||void 0===s?void 0:s.length:i.length>0?Math.max(...i.map((i=>i.order))):0}loadGuides(){var i,t,s,e;this.guidesList=[],this.guidesList.push(...z(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"),this.dataUnit,k.general)),this.guidesList.push(...D(this.dataUnit,this.getInitialOrder(this.guidesList),this.guidesList)),this.guidesList.push(...G(this.customGuidesConfig,this.guidesList)),this.guidesMap=E(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,k.general),this.mainGuide=this.guidesList.find((i=>i.name===k.main)),this.mainGroupsList=(null===(t=this.mainGuide)||void 0===t?void 0:t.name)?[...null!==(e=null===(s=this.guidesMap)||void 0===s?void 0:s.get(this.mainGuide.name))&&void 0!==e?e:[]]:[],this.ensureSelectedGuide()}ensureSelectedGuide(){if(this.selectedGuide&&this.guidesList.some((i=>i.name===this.selectedGuide.name)))return;const i=this.guidesList.filter((i=>{var t;return i.visible&&i.name!==(null===(t=this.mainGuide)||void 0===t?void 0:t.name)})).sort(((i,t)=>{var s,e;return(null!==(s=i.order)&&void 0!==s?s:Number.MAX_VALUE)-(null!==(e=t.order)&&void 0!==e?e:Number.MAX_VALUE)}))[0];this.selectedGuide=i}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=m(this.dataUnit)),h.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.selectedGuide&&(this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i]))}handleMainLayoutChanged({detail:i}){var t;(null===(t=this.mainGuide)||void 0===t?void 0:t.name)&&(this.hasChanges=!0,this.mainGroupsList=[...i],this.guidesMap.set(this.mainGuide.name,[...i]))}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===k.main?i.name:i.label,order:i.name===k.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?b.USER:b.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,_.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){const i=h.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=L(this.guidesMap),i.defaultConfiguration=this.getIsDefaultConfig(),i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,o=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=[];o.forEach((i=>a.push(...i.fields))),this.availableFields=[...this.availableFields,...a],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0,this.ensureSelectedGuide()),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=this.selectedGuide;if(!(null==s?void 0:s.name))return;const e=s.name,o=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=N(o,i);this.guidesMap.delete(e),this.guidesMap.set(i,a);const n={name:i,label:i,visible:s.visible,order:s.order};this.guidesList=[...this.guidesList.map((i=>i.name===e?n:i))],this.groupsList=[...a],this.selectedGuide=n,this.hasChanges=!0}handleCreateNewGuide(){const i=M(this.guidesList,this.getMessage.bind(this)),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:w.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=l.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){var i;return s(e,null,s("snk-dynaform-config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"form-config-body"},s("div",{class:"form-config-layout"},s("snk-dynaform-fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this),messagesBuilder:this.messagesBuilder}),s("div",{class:"main-editing-area"},this.mainGuide&&s("div",{class:"main-fields-section"},s("snk-dynaform-fields-layout",{ref:i=>this.refMainFieldsLayout=i,selectedGuide:this.mainGuide,guideNames:this.getGuideNames(),groupsList:this.mainGroupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,isMainSection:!0,onLayoutChanged:this.handleMainLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)})),s("snk-dynaform-guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,mainGuideName:null===(i=this.mainGuide)||void 0===i?void 0:i.name,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("snk-dynaform-fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)})))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};R.style='.sc-snk-dynaform-form-config-h{display:flex;flex-direction:column;height:100vh;width:100%;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.form-config-body.sc-snk-dynaform-form-config{height:var(--snk-form-config-container-height);overflow:hidden;padding-top:var(--space--12, 12px)}.form-config-layout.sc-snk-dynaform-form-config{display:flex;flex-direction:row;height:100%;gap:20px;align-items:stretch}.main-editing-area.sc-snk-dynaform-form-config{display:flex;flex-direction:column;flex:1;min-width:0;height:100%;overflow:hidden;gap:12px}.main-editing-area.sc-snk-dynaform-form-config>snk-dynaform-fields-layout.sc-snk-dynaform-form-config{flex:1 1 auto;min-height:0;overflow:auto;flex-direction:row}.main-editing-area.sc-snk-dynaform-form-config>snk-dynaform-guides-configurator.sc-snk-dynaform-form-config{flex:0 0 auto}.main-fields-section.sc-snk-dynaform-form-config{flex:0 0 40vh;display:flex;flex-direction:column;min-height:0;overflow:hidden}.guide-header.sc-snk-dynaform-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{I as snk_dynaform_detail_view,R as snk_dynaform_form_config}
@@ -1,4 +1,4 @@
1
- import{r as t,e,h as i,f as s,g as n}from"./p-2c9d0870.js";import{DateUtils as r,StringUtils as a,ObjectUtils as o,WaitingChangeException as h,SilentException as l,WarningException as c,ErrorException as d,ElementIDUtils as u,SearchUtils as p,ArrayUtils as m,KeyboardManager as g,OnboardingUtils as w,DependencyType as y,DataType as v,ApplicationContext as f,ErrorTracking as P,UserAgentUtils as k,LockManager as z,LockManagerOperation as _}from"@sankhyalabs/core";import{ApplicationUtils as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C as A}from"./p-51e853f2.js";import{d as S,D as b,U as I,S as T}from"./p-5d02c032.js";import{A as O,a as L}from"./p-d5810110.js";import{P as N,D as E}from"./p-5c6eede7.js";import{P as C}from"./p-b1bf9564.js";import{T as D}from"./p-9019a32f.js";import"./p-0f3698af.js";import"./p-ff1990ad.js";import{F as R}from"./p-d88278f8.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class F{static webConnectionCaller(t,e,i){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,e,i)}}const M=U;function U(t,e){const i=j();return(U=function(t){return i[t-=378]})(t,e)}function j(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(j=function(){return t})()}!function(){const t=U,e=j();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class ${[M(397)](t){const e=M;if(typeof(t=utxt(t[e(390)]))==e(392)&&(t=JSON[e(400)](t)),null==t)throw Error(e(395));const i=new H("S"===t[e(402)]||!0===t[e(402)]);return Array[e(394)](t[e(391)])&&t[e(391)][e(385)]((t=>i.putAccess(t[e(382)],String(t.status)==e(398)))),i}}class H{constructor(t){const e=M;this.isSup=t,this[e(384)]={}}[M(378)](t,e){this[M(384)][t]=e}[M(393)](t){const e=M;if(this[e(402)])return!0;let i=!0;return this[e(384)][e(380)](t)&&(i=this.actions[t]),i}isUserSup(){return this.isSup}}class B{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[e,i]=t.split("__=__");this._embeddedParams.set(e,i)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",S.gql`query($name: String!) {
1
+ import{r as t,e,h as i,f as s,g as n}from"./p-2c9d0870.js";import{DateUtils as r,StringUtils as a,ObjectUtils as o,WaitingChangeException as h,SilentException as l,WarningException as c,ErrorException as d,ElementIDUtils as u,SearchUtils as p,ArrayUtils as m,KeyboardManager as g,OnboardingUtils as w,DependencyType as y,DataType as v,ApplicationContext as f,ErrorTracking as P,UserAgentUtils as k,LockManager as z,LockManagerOperation as _}from"@sankhyalabs/core";import{ApplicationUtils as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C as A}from"./p-13f91e7e.js";import{d as S,D as b,U as I,S as T}from"./p-10d883b0.js";import{A as O,a as L}from"./p-c3bc693a.js";import{P as N,D as E}from"./p-c1e168a2.js";import{P as C}from"./p-3190ac29.js";import{T as D}from"./p-9019a32f.js";import"./p-0f3698af.js";import"./p-ff1990ad.js";import{F as R}from"./p-d7657667.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class F{static webConnectionCaller(t,e,i){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,e,i)}}const M=U;function U(t,e){const i=j();return(U=function(t){return i[t-=378]})(t,e)}function j(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(j=function(){return t})()}!function(){const t=U,e=j();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class ${[M(397)](t){const e=M;if(typeof(t=utxt(t[e(390)]))==e(392)&&(t=JSON[e(400)](t)),null==t)throw Error(e(395));const i=new H("S"===t[e(402)]||!0===t[e(402)]);return Array[e(394)](t[e(391)])&&t[e(391)][e(385)]((t=>i.putAccess(t[e(382)],String(t.status)==e(398)))),i}}class H{constructor(t){const e=M;this.isSup=t,this[e(384)]={}}[M(378)](t,e){this[M(384)][t]=e}[M(393)](t){const e=M;if(this[e(402)])return!0;let i=!0;return this[e(384)][e(380)](t)&&(i=this.actions[t]),i}isUserSup(){return this.isSup}}class B{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[e,i]=t.split("__=__");this._embeddedParams.set(e,i)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",S.gql`query($name: String!) {
2
2
  $queryAlias$: fetchResource(name: $name){
3
3
  name
4
4
  resource
@@ -0,0 +1,60 @@
1
+ import{ObjectUtils as t,DataUnit as e,DataUnitInMemoryLoader as r,ApplicationContext as n,StringUtils as a,UserInterface as s,DataUnitStorage as i,DataType as o,ChangeOperation as l}from"@sankhyalabs/core";import{D as c,d as u}from"./p-10d883b0.js";import{DISTINCT_FILTER_NAME_PREFIX as d}from"@sankhyalabs/ezui/dist/collection/utils/constants";import{DataUnitTransient as h}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{ColumnFilterManager as m}from"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import f from"@sankhyalabs/core/dist/utils/SortingUtils";import{R as _}from"./p-688dcb4c.js";class g{constructor(t){this._list=[],this._listCopy=[],this._listLastUpdate=0,this._listCopyLastUpdate=0,this._equalsFunction=t}async load(t,e,r,n){let a=[].concat(this._list);null!=t&&(a=this._list.filter((e=>t(e)))),null!=e&&(a=a.sort(e));const s=a.length;if(null!=n){const t=r||0;a=a.slice(t,n?t+n:a.length)}return Promise.resolve({result:a,count:s})}async distict(t){const e=[];let r=!1;for(const n of this._list){const a=t(n);null!=a&&(null!=a.value?e.push(a):r=!0)}return r&&e.push({key:"",value:null}),Promise.resolve(new Map(e.map((t=>[t.key,t.value]))))}async push(t){this.updateList([...this._list,...t])}async clear(){this.updateList([])}async delete(t){const e=this._list.filter((e=>{for(const r of t)if(this._equalsFunction(e,r))return!1;return!0}));this.updateList(e)}async update(t){const e=this._list.map((e=>{const r=t.find((t=>this._equalsFunction(e,t)));return null==r?e:r}));this.updateList(e)}async insert(t,e){const r=this._list.indexOf(t);if(-1==r)return void this.push(e);const n=this._list.slice(0,r).concat(e).concat(this._list.slice(r));this.updateList(n)}isOperating(){return!0}async isEmpty(){return Promise.resolve(0===this._list.length)}async count(){return Promise.resolve(this._list.length)}getFromCache(){return this._listLastUpdate>this._listCopyLastUpdate&&(this._listCopyLastUpdate=this._listLastUpdate,this._listCopy=t.copy(this._list)),this._listCopy}updateList(t){this._list=t,this._listLastUpdate=Date.now()}}class p{static setLoadingStatus(t,e){this._loadingStatus.set(t.name,e)}static isCacheEnabled(t){return!0}static cacheRecords(t,e,r,n){p.setLoadingStatus(t,n),p.isCacheEnabled(t)?this.getRepository(t).push(e):r&&this._repositories.delete(t.name)}static getSortingFunction(t,e){return f.getSortingFunction(t,e)}static async getDistinct(t,e,r=!1){if(!p.isCacheEnabled(t))return Promise.resolve(m.compileDistinct(e,t));let n;const a=t.getLastLoadRequest();if(null!=a){const r=m.getColumnFilters(a.filters,e);n=m.getFilterFunction(t,Array.from(r.values()))}return r?Promise.resolve(this.compileDistinctByLabel(t,e,n)):new Promise(((r,a)=>{p.getRepository(t).distict((r=>{if(null!=n&&!n(r))return;const a=r[e];if(null==a)return{key:null,value:null};let s=null!=a.value?a.value:a;return{key:t.getFormattedValue(e,a),value:s}})).then((t=>{r(null!=t?Array.from(t.entries()).map((([t,e])=>({label:t,value:e,check:!0}))):void 0)})).catch((t=>a(t)))}))}static compileDistinctByLabel(t,e,r){const n=new Map;return p.getRepository(t).getFromCache().forEach((a=>{if(null!=r&&!r(a))return;const s=a[e];if(null==s){const t="";return void(n.has(t)||n.set(t,{values:new Set([null]),option:{label:null,value:null,check:!0}}))}const i=null!=s.value?s.value:s,o=(null==s?void 0:s.label)?s.label:t.getFormattedValue(e,s),l=String(null!=o?o:"");let c=n.get(l);c||(c={values:new Set,option:{label:o,value:i,check:!0}},n.set(l,c)),c.values.add(i)})),Array.from(n.values()).map((t=>(t.option.__multiValues=Array.from(t.values.values()),t.option)))}static async loadData(t,r,n){try{if(p.isCacheEnabled(t)){if(["EZ_GRID_LOADING_SOURCE",e.CHANGING_PAGE_LOADING_SOURCE,e.ALL_RECORDS_SELECTION_SOURCE].includes(r.source)&&!await p.getRepository(t).isEmpty())return p.loadFromCache(t,r);p.getRepository(t).clear().catch((()=>{}))}return n(t,r)}catch(t){return console.error(t),Promise.reject(t)}}static insertRecords(t,e,r){p.isCacheEnabled(t)&&p.getRepository(t).insert(e,r)}static updateRecords(t,e){p.isCacheEnabled(t)&&p.getRepository(t).update(e)}static removeRecords(t,e){p.isCacheEnabled(t)&&p.getRepository(t).delete(e)}static async countRecords(t){return p.isCacheEnabled(t)?p.getRepository(t).count():Promise.resolve(0)}static getRepository(t){const e=t.name;return p._repositories.has(e)||p._repositories.set(e,new g(((t,e)=>t.__record__id__===e.__record__id__))),p._repositories.get(e)}static async loadFromCache(t,e){return new Promise(((r,n)=>{const a=m.getColumnFilters(e.filters,""),{limit:s,offset:i,sort:o}=e;p.getRepository(t).load(m.getFilterFunction(t,Array.from(a.values())),p.getSortingFunction(t,o),i,s).then((e=>{const n=p._loadingStatus.get(t.name),{count:a,result:o}=e,l=0==a?0:i+1,c=i+Math.min(o.length,s);r({records:o,paginationInfo:{count:a,currentPage:i/s,firstRecord:l,lastRecord:c,hasMore:n||c<a,total:n?void 0:a}})})).catch((t=>n(t)))}))}static getCachedRecords(t){const e=p.getRepository(t).getFromCache(),r=t.getLastLoadRequest();if(null==r)return e;const n=m.getColumnFilters(r.filters,""),a=m.getFilterFunction(t,Array.from(n.values()));return null==a?e:e.filter(a)}}p._repositories=new Map,p._loadingStatus=new Map;class v{constructor(t,e,n){this._dataUnitInMemoryLoader=new r(t,e,n)}get dataUnit(){return this._dataUnitInMemoryLoader.dataUnit}get records(){return this._dataUnitInMemoryLoader.records}set records(t){this._dataUnitInMemoryLoader.records=t}get metadata(){return this._dataUnitInMemoryLoader.metadata}set metadata(t){this._dataUnitInMemoryLoader.metadata=t}removeLoader(t,e){return this._dataUnitInMemoryLoader.removeLoader(t,e)}static getConvertedValue(t,e,n){return r.getConvertedValue(t,e,n)}}function y(t,e){var r,n;return void 0!==(null===(r=t[e])||void 0===r?void 0:r.value)?null===(n=t[e])||void 0===n?void 0:n.value:t[e]}v.IN_MEMORY_DATA_UNIT_NAME=r.IN_MEMORY_DATA_UNIT_NAME;class b{canSlice(){return!1}processSortingSide(t,e,r){var n;const a=[],i=[];if(null!=t.sort){if(0===r.length)return{localSorting:t.sort,serverSorting:[]};for(const r of t.sort){const t=e.getField(r.field);"true"===(null===(n=null==t?void 0:t.properties)||void 0===n?void 0:n.calculated)||(null==t?void 0:t.userInterface)===s.LONGTEXT?a.push(r):i.push(r)}}return{localSorting:a,serverSorting:i}}async load(t,e,r){var n,a;if(null==t.metadata)return Promise.resolve({records:[],loadingInfo:r});try{const s=null!==(a=null===(n=e.filters)||void 0===n?void 0:n.filter((t=>!t.name.startsWith("FILTRO_COLUNA_"))))&&void 0!==a?a:[],{localSorting:i,serverSorting:o}=this.processSortingSide(e,t,s),l=this.getFieldsList(t),u="DatasetSP.loadRecords",d=this.buildRequestBody(u,l,t,e,r,o,s),h=r.quiet?{urlParams:{quietMode:"true"}}:void 0,{result:m,pagerID:f,askRowsLimit:_}=await c.get().callServiceBroker(u,d,h),g=this.processRecords(t,l,m),p=null!=f,v=r.count+g.length,y=t.hasNewRecord(),b=i.length>0,P=!p&&b;return P&&y&&t.setWaitingToReload(!0),Promise.resolve({records:g,loadingInfo:Object.assign(Object.assign({},r),{pagerId:f,loadingInProgress:p,total:p?void 0:v,count:v,needReload:P&&!y,askRowsLimit:_,hasLocalSorting:b})})}catch(t){return console.error(t),Promise.reject(t)}}async loadRowMetadata(t,e,r,n={}){try{const a="DatasetSP.loadRowMetadata",s=await this.buildRequestBodyLoadRowMetadata({snkDataUnit:t,fieldName:e,metadataName:r,serviceName:a,updatedFields:n});return await c.get().callServiceBroker(a,s)}catch(t){return console.error(t),Promise.reject(t)}}async buildRequestBodyLoadRowMetadata({snkDataUnit:t,serviceName:e,fieldName:r,metadataName:n,updatedFields:a}){const s=t.dataUnit,i=R.parseDataUnitName(s.name).entityName,o=(await t.getSelectedRecordsIDsInfo()).reduce(((t,e)=>(t[e.name]=e.value,t)),{}),l=s.getSelectedRecord(),c=s.metadata.fields.filter((({standAlone:t,name:e})=>!t&&!e.includes("."))).map((({name:t})=>t)),u=c.reduce(((t,e,r)=>{const n=y(l,e),s=y(a,e);return t[r]=void 0!==s?s:n,t}),{});return JSON.stringify({serviceName:e,requestBody:{dataSetID:s.dataUnitId,entityName:i,standAlone:!1,metadataName:n,fieldName:r,fields:c,record:{pk:o,oldPk:o,values:u}}})}getFieldsList(t){let e=["__record__id__","__record__label__"];return t.metadata.fields.forEach((t=>{t.standAlone||(e=e.concat(this.getFieldNames(t)))})),e}getStandAloneFieldsList(t){let e={};return t.metadata.fields.forEach((t=>{t.standAlone&&(e=Object.assign(Object.assign({},e),{[t.name]:{fieldType:t.dataType,userType:t.userInterface}}))})),e}getFieldNames(t){const e=this.getSearchDescriptionField(t);return null==e?t.name:[t.name,e]}buildRequestBody(t,e,r,n,a,s,i){const o=r.dataUnitId,l=R.parseDataUnitName(r.name).entityName,c=!(!n.limit&&!n.offset),u={serviceName:t,requestBody:{dataSetID:o,fields:e,entityName:l,pageNumber:a.pageNumber,totalRecordsCount:a.count,pagerID:a.pagerId,standAlone:!1,standAloneFieldsMD:Object.assign({__record__id__:{fieldType:"S",userType:"P"},__record__label__:{fieldType:"S",userType:"P"}},this.getStandAloneFieldsList(r)),tryJoinedFields:!0,parallelLoader:c,crudListener:`br.com.sankhya.bff.${this.getModuleName()}.BFFDataUnitDatasetAdapter`,txProperties:this.getTxProperties(r,n,s,i),useDefaultRowsLimit:!1}};return JSON.stringify(u)}getModuleName(){return n.getContextValue("__SNK__APPLICATION__").getModuleName().replace("-bff","")}getTxProperties(t,e,r,n){const a={"__DATA_UNIT_ADAPTER__[dataUnitName]":t.name};0!==n.length&&(a["__DATA_UNIT_ADAPTER__[criteria]"]=JSON.stringify(n)),null!=r&&0!==r.length&&(a["__DATA_UNIT_ADAPTER__[sorting]"]=JSON.stringify(r)),null!=e.parentRecordId&&(a["__DATA_UNIT_ADAPTER__[parentRecordId]"]=e.parentRecordId);const s=t.getGlobalLoaderProps();return null==s||0===s.size||Array.from(s.entries()).forEach((([t,e])=>{a[t]=e})),a}processRecords(t,e,r){return r.map((r=>{const n={__record__id__:r[0],__record__label__:r[1],__record__metadata__:r[r.length-1]._rmd};return t.metadata.fields.forEach((t=>{n[t.name]=this.buildFieldValue(t,e,r)})),n}))}buildFieldValue(t,e,r){const n=e.indexOf(t.name);if(n<0)return null;const i=r[n];if(a.isEmpty(i))return null;const o=this.getSearchDescriptionField(t);if(null!=o){const t=e.indexOf(o);if(t>=0)return{value:i,label:r[t]}}return t.userInterface===s.SEARCH?isNaN(Number(i))?i:Number(i):v.getConvertedValue(t,i)}getSearchDescriptionField(t){if(![s.SEARCH,s.SEARCHPLUS].includes(t.userInterface))return;if(!t.properties)return;const{ENTITYNAME:e,mergedFrom:r,DESCRIPTIONFIELD:n}=t.properties;return a.isEmpty(n)?void 0:null!=r?`${r}.${e}.${n}`:`${e}.${n}`}}var P;!function(t){t.CANCEL="CANCEL",t.CONTINUE="CONTINUE",t.LOAD_ALL="LOAD_ALL"}(P||(P={}));class D{constructor(){}static async debounce(t,e){const r=t.name;D._debouncingTimeouts[r]&&(clearTimeout(D._debouncingTimeouts[r]),delete D._debouncingTimeouts[r]),D._debouncingTimeouts[r]=setTimeout((()=>{delete D._debouncingTimeouts[r],e()}),100)}static async loadData(t,e){return new Promise(((r,n)=>{D.debounce(t,(()=>{p.loadData(t,e,this.loadFromServer).then((t=>r(t))).catch((t=>n(t)))}))}))}static getCachedRecords(t){return p.getCachedRecords(t)}static async loadFromServer(t,e,r){try{r=D.registryLoading(t,r);const n=await D.callLoader(t,e,r);if(null==n)return;const a=n.records,s=D.buildPaginationInfo(a.length,e,n.loadingInfo),i=null==s?a:a.slice(0,s.lastRecord);return Promise.resolve({records:i,paginationInfo:s})}catch(t){return console.error(t),Promise.reject(t)}}static async callLoader(t,e,r,n){null==n&&(n=new b);const a=await n.load(t,e,r),s=a.loadingInfo;if(D.isOldRequest(t,s))return Promise.resolve(void 0);if(this.handleCache(n,s,t,a.records),t.cancelPagination)return this.handlePaginationCanceled(t,a);if(this.canFinishPagination(t,s))return Promise.resolve(a);const i=Object.assign(Object.assign({},e),{offset:s.count});let o=this.buildNewLoadingInfo(s);if(this.canProceedPagination(s))return this.recallLoader(t,i,o,n,a);const l=await async function(t){return new Promise((e=>{const r=new CustomEvent("ez-grid-pagination:ask-cancel",{detail:{dataUnitName:null==t?void 0:t.name,resolve:e},bubbles:!1,composed:!1});document.dispatchEvent(r)}))}(t);return l===P.CANCEL?this.handlePaginationCanceled(t,a):(l===P.LOAD_ALL&&(o=Object.assign(Object.assign({},o),{loadAllRecords:!0})),o=Object.assign(Object.assign({},o),{lastRowLimitAsked:o.count}),this.recallLoader(t,i,o,n,a))}static buildNewLoadingInfo(t){return Object.assign(Object.assign({},t),{pageNumber:(t.pageNumber||0)+1,quiet:!0})}static handleCache(t,e,r,n){const a=!t.canSlice()||0===e.count;p.cacheRecords(r,n,a,e.loadingInProgress)}static recallLoader(t,e,r,n,a){return this.callLoader(t,e,r,n).then((e=>D.afterLoadingPage(t,e.loadingInfo))).catch((t=>console.error(t))),Promise.resolve(a)}static canFinishPagination(t,e){return!p.isCacheEnabled(t)||!e.loadingInProgress}static canProceedPagination(t){const{count:e,askRowsLimit:r,loadAllRecords:n,lastRowLimitAsked:a}=t;if(n)return!0;if(!e||!r)return!0;const s=Number(r);return e<s||e<s+(a||0)}static handlePaginationCanceled(t,e){t.cancelPagination=!1;let r=e.loadingInfo;return r=Object.assign(Object.assign({},r),{total:r.count,loadingInProgress:!1,pagerId:void 0,needReload:r.hasLocalSorting}),Promise.resolve({records:e.records,loadingInfo:r})}static afterLoadingPage(t,e){p.setLoadingStatus(t,e.loadingInProgress);const r=t.getPaginationInfo();if(null==r)return;const n=e.count;e.loadingInProgress?t.updatePagination(Object.assign(Object.assign({},r),{count:n,loadingInProgress:!0})):e.needReload?t.gotoPage(0):t.updatePagination(Object.assign(Object.assign({},r),{total:n,count:n,loadingInProgress:!1}))}static registryLoading(t,e){return null==e&&(e={requestTime:(new Date).getTime(),count:0}),D._requestTimeByDataUnit.set(t.name,e.requestTime),e}static isOldRequest(t,e){return D._requestTimeByDataUnit.get(t.name)>e.requestTime}static buildPaginationInfo(t,e,r){let{limit:n,offset:a}=e;if(!n)return;1===r.pageNumber&&(a=0);const{total:s,count:i,loadingInProgress:o,askRowsLimit:l}=r,c=0===i||0===t?0:a+1,u=a+Math.min(t,n);return{total:s,count:i,lastRecord:u,firstRecord:c,currentPage:a/n,hasMore:u<i||o,askRowsLimit:l}}}D._requestTimeByDataUnit=new Map,D._debouncingTimeouts={};const N=/dd:\/\/([^/]+)\/([^/?]+)/;class R{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchDataUnit",u.gql`query($name: String!) {
2
+ $queryAlias$: fetchDataUnit(name: $name){
3
+ name
4
+ fields{
5
+ name
6
+ defaultValue
7
+ label
8
+ visible
9
+ standAlone
10
+ readOnly
11
+ required
12
+ dataType
13
+ userInterface
14
+ calculated
15
+ group
16
+ order
17
+ properties{
18
+ name
19
+ value
20
+ }
21
+ dependencies{
22
+ masterFields
23
+ type
24
+ expression
25
+ }
26
+ }
27
+ children{
28
+ name
29
+ label
30
+ links{
31
+ source
32
+ target
33
+ }
34
+ }
35
+ }
36
+ }`),this.templateByQuery.set("saveData",u.gql`mutation($changes: [InputBatchChange!]!) {
37
+ $queryAlias$: batchOperationDataUnit(changes: $changes){
38
+ oldId
39
+ id
40
+ label
41
+ ownerDataUnitName
42
+ fields {
43
+ name
44
+ value
45
+ }
46
+ }
47
+ }`),this.templateByQuery.set("fetchDataRecord",u.gql`query($dataunit: String! $recordID: [String!]) {
48
+ $queryAlias$: fetchDataUnit(name: $dataunit){
49
+ record(id: $recordID){
50
+ id
51
+ label
52
+ fields {
53
+ name
54
+ value
55
+ }
56
+ }
57
+ }
58
+ }`),this.templateByQuery.set("fetchDistinctColumn",u.gql`query($dataUnit: String!, $fieldName: String!, $argument: String, $filters: [InputFilter], $parentRecordId: String) {
59
+ $queryAlias$: selectDistinct(dataUnit: $dataUnit, fieldName: $fieldName, argument: $argument, filters: $filters, parentRecordId: $parentRecordId)
60
+ }`)}static parseDataUnitName(t){if(null==t)return;const e=N.exec(t);return e?{entityName:e[1],resourceID:e[2]}:void 0}getDataUnit(t,r,n,a){null==p.applicationResourceID&&_.getResourceID().then((t=>p.applicationResourceID=t));const s=`dd://${t}/${r}${a?"/"+a:""}`,i=null!=n?n.getChildDataunit(s):new e(s);return i.metadataLoader=t=>this.loadMetadata(t),i.dataLoader=(t,e)=>D.loadData(t,e),i.saveLoader=(t,e)=>this.saveData(i,e),i.removeLoader=(t,e)=>this.removeRecords(t,e),i.recordLoader=(t,e)=>this.loadRecord(t,e),i.allRecordsLoader=t=>D.getCachedRecords(t),i}loadMetadata(t){return new Promise(((e,r)=>{c.get().callGraphQL({values:{name:t.name},query:this.templateByQuery.get("fetchDataUnit")}).then((t=>{var r;const n={name:t.name,label:t.name,children:[...t.children],fields:[]};null===(r=t.fields)||void 0===r||r.forEach((t=>{let e;Array.isArray(t.properties)&&(e={},t.calculated&&(e.gridHeaderTooltip="Campos calculados não podem ser ordenados"),t.properties.forEach((t=>e[t.name]=t.value))),n.fields.push(Object.assign(Object.assign({},t),{properties:e}))})),n.fields.sort(((t,e)=>this.sortFieldsByGroup(t,e))),e(n)})).catch((t=>{r(t)}))}))}sortFieldsByGroup(t,e){const r=t.name.includes("."),n=e.name.includes(".");if(r!==n)return r?1:-1;if(r&&n){const r=t.name.split(".")[0],n=e.name.split(".")[0];if(r!==n)return r.localeCompare(n)}return t.order-e.order}loadSelectDistinct(t,e,r){const{parentRecordId:n,filters:a}=t.getLastLoadRequest()||{},s=a.filter((t=>t.name!==`${d}${e}`)),i={dataUnit:t.name,argument:r,fieldName:e,parentRecordId:n,filters:s};return new Promise(((t,e)=>{c.get().callGraphQL({values:i,query:this.templateByQuery.get("fetchDistinctColumn")}).then((e=>{t(e)})).catch((t=>{e(t)}))}))}addTransientProperties(t,e){const r=t.getGlobalLoaderProps();return null==r||0===r.size||(null==e&&(e={}),Array.from(r.entries()).forEach((([t,r])=>{e[`transient.${t}`]=r}))),e}getUpdatingFields(t,e){if(null==e)return;const r=Object.assign({},e);return Object.keys(r).forEach((e=>{const n=t.getField(e);null!=n&&n.standAlone&&delete r[e]})),this.addTransientProperties(t,r)}saveData(t,e){const r=[],n=[],a=e.map((e=>{const{dataUnit:a,record:s,operation:c}=e,u=i.get(a),d=this.getUpdatingFields(u,e.updatingFields);let h;null!=d&&(h=Object.entries(d).map((([t,e])=>{const r=u.getField(t);return{fieldName:t,dataType:r?r.dataType:o.TEXT,value:u.valueToString(t,e)}}))),a===t.name&&(c===l.INSERT||c===l.COPY?n.push(s.__record__id__):r.push(s.__record__id__));const m={dataUnit:a,fields:h,operation:c,recordId:s.__record__id__};return e.sourceId&&(m.sourceId=e.sourceId),s.__parent__record__id__&&(m.parentRecordId=s.__parent__record__id__),m}));return new Promise(((e,s)=>{const o=a.map((t=>function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(r[n[a]]=t[n[a]])}return r}(t,[])));c.get().callGraphQL({values:{changes:o},query:this.templateByQuery.get("saveData")}).then((a=>{const s=[];null==a||a.forEach((e=>{const r={__record__id__:e.id,__record__label__:e.label,__owner__dataunit__name__:e.ownerDataUnitName},n=i.get(r.__owner__dataunit__name__)||t;e.oldId&&(r.__old__id__=e.oldId),e.fields.forEach((({name:t,value:e})=>{var a;const s=null===(a=null==n?void 0:n.valueFromString)||void 0===a?void 0:a.call(n,t,e);r[t]=void 0!==s?s:e})),s.push(r)})),this.updateCache(t,s,r,n),e(s)})).catch((t=>{s(t)}))}))}updateCache(t,e,r,n){const a=new Map(e.map((t=>[t.__old__id__||t.__record__id__,t]))),s=n.map((t=>{const e=Object.assign({},a.get(t));return delete e.__old__id__,e}));s.length>0&&p.insertRecords(t,t.records[0],s);const i=r.map((t=>Object.assign({},a.get(t))));p.updateRecords(t,i)}getTransientInfo(t,e){const{records:r}=t.getSelectionInfo();return Object.entries(r.filter((t=>t.__record__id__==e))[0]).filter((([t])=>t.startsWith(h.DATA_UNIT_TRANSIENT_PREFIX_NAME))).map((([t,e])=>({fieldName:t,value:e,dataType:o.TEXT})))}removeRecords(t,e){const r=e.map((e=>({dataUnit:t.name,operation:l.DELETE,recordId:e,fields:this.getTransientInfo(t,e)})));return new Promise(((n,a)=>{c.get().callGraphQL({values:{changes:r},query:this.templateByQuery.get("saveData")}).then((()=>{p.removeRecords(t,t.records.filter((t=>e.includes(t.__record__id__)))),n(e)})).catch((t=>{a(t)}))}))}loadRecord(t,e){return new Promise(((r,n)=>{c.get().callGraphQL({values:{recordID:e,dataunit:t.name},query:this.templateByQuery.get("fetchDataRecord")}).then((e=>{const n=[];e.record.forEach((e=>{const r={__record__id__:e.id,__record__label__:e.label};e.fields.forEach((({name:e,value:n})=>{r[e]=t.valueFromString(e,n)})),n.push(r)})),r(n)})).catch((t=>{n(t)}))}))}}export{R as D,v as I,p as P,b as a,y as g}
@@ -1 +1 @@
1
- import{ObjectUtils as t}from"@sankhyalabs/core";import{R as a}from"./p-d88278f8.js";class s extends a{getData(a){const s=`cfg://auth/${a}`;return new Promise(((a,e)=>{this.loadResource(s).then((s=>{let e=t.stringToObject(s);e&&"object"==typeof e&&a(e)})).catch((t=>{e(t)}))}))}}var e;!function(t){t.INSERT="I",t.UPDATE="A",t.REMOVE="E",t.SHOW="C",t.CONFIG="F",t.CONFIG_NUMBER="N",t.CLONE="D",t.CONFIG_GRID="G"}(e||(e={}));export{e as A,s as a}
1
+ import{ObjectUtils as t}from"@sankhyalabs/core";import{R as a}from"./p-d7657667.js";class s extends a{getData(a){const s=`cfg://auth/${a}`;return new Promise(((a,e)=>{this.loadResource(s).then((s=>{let e=t.stringToObject(s);e&&"object"==typeof e&&a(e)})).catch((t=>{e(t)}))}))}}var e;!function(t){t.INSERT="I",t.UPDATE="A",t.REMOVE="E",t.SHOW="C",t.CONFIG="F",t.CONFIG_NUMBER="N",t.CLONE="D",t.CONFIG_GRID="G"}(e||(e={}));export{e as A,s as a}
@@ -1 +1 @@
1
- import{r as i,e,h as s,F as t,g as r}from"./p-2c9d0870.js";import{ObjectUtils as n,Action as a,KeyboardManager as d}from"@sankhyalabs/core";import{buildFieldSearch as o,SHORTCUT_SEARCH_FIELD as h}from"@sankhyalabs/ezui/dist/collection/utils";import{buildFormMetadata as l,FormMetadata as u}from"@sankhyalabs/ezui/dist/collection/utils/form";import{V as v}from"./p-9019a32f.js";import{S as c}from"./p-1cc4cf61.js";import{T as g}from"./p-3072136e.js";const m="__FORM:",f=class{constructor(s){i(this,s),this.snkShowGuide=e(this,"snkShowGuide",7),this.snkMasterFormConfigChange=e(this,"snkMasterFormConfigChange",7),this.formConfigVisibilityChanged=e(this,"formConfigVisibilityChanged",7),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this.customGuidesConfig=[],this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={},this._mainForm=void 0}observeDataUnit(){this.loadGuides(!0)}async observeFormConfigManager(i){const e=!!i;await this._viewStack.show(e?k.CONFIG:k.GUIDES),this.formConfigVisibilityChanged.emit(e)}observeDataState(i,e){var s,t,r,a,d,o;const h=null!==(t=null===(s=null==i?void 0:i.selectionInfo)||void 0===s?void 0:s.recordIds)&&void 0!==t?t:null===(r=null==i?void 0:i.selectedRecord)||void 0===r?void 0:r.__record__id__,l=null!==(d=null===(a=null==e?void 0:e.selectionInfo)||void 0===a?void 0:a.recordIds)&&void 0!==d?d:null===(o=null==e?void 0:e.selectedRecord)||void 0===o?void 0:o.__record__id__;n.equals(h,l)||this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected()),this.snkMasterFormConfigChange.emit(this.masterFormConfig)}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,s){const t={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:s})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),t)}async setFocus(){var i;null===(i=this._container)||void 0===i||i.focus({preventScroll:!0})}async reloadGuides(){this.loadGuides(!1)}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===g.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){f.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){var e,s;if(this.dataUnit.isMultipleEdition){const i=null!==(s=null===(e=this.dataUnit.getSelectionInfo())||void 0===e?void 0:e.records)&&void 0!==s?s:[];return this.messagesBuilder.getMessage("snkCrud.multipleEdition.editing",{COUNT:i.length})}return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=l(this.masterFormConfig,this.dataUnit,!0,this.customGuidesConfig);const e=this._masterFormMetadata.getAllSheets(),s=this.dataUnit.getSelectedRecord(),t=this.hasToDisableDetails(s),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&t&&(e.tooltip=this.getMessage("snkCrud.detail.tooltip.needSingleSelection"),e.disabled=!0),i.isCustom&&i.ctxProps&&Object.entries(i.ctxProps).forEach((([i,s])=>{void 0!==s&&(e[i]=s)})),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}hasToDisableDetails(i){return!i||this.dataUnit.isNewRecord(i.__record__id__)||this.dataUnit.isMultipleEdition}isDetail(i){return null!=u.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}static updateContentCard(i,e,s,t){return t.saveCardState(i,e,s)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return s(t,null,Array.from(r.entries()).filter((([e,s])=>(null==s?void 0:s.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,t])=>{var r,n;const a=i.formMetadata.getSheet(e);if(null!=a)return s("snk-form-view",{levelPath:i.levelPath,label:a.label,name:e,fields:a.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==t?void 0:t.presentation),fixed:null==t?void 0:t.fixed,summaryFields:null===(n=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===n?void 0:n.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps,entityPath:i.entityPath})})))}wrapDetail(i,e){if(0===i.length)return e;const t=i.pop(),r=u.getDetailName(t);return r?this.wrapDetail(i,s("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const s=i.map((i=>u.getDetailName(i)));return`${this.entityPath}/${s.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){if(!this.selectedGuide)return void this.snkShowGuide.emit(void 0);const i=this.selectedGuide.id;if(this.snkShowGuide.emit(i),this.isCustomGuide(i))return s("slot",{name:i});const e=i.split("::"),t=e.pop(),r=u.getDetailName(t);let n=i;return this.isDetailGuide(r,e)?this.buildDetailGuideContent(i,n,e,r):this.buildFormViewGuideContent(i)}buildFormViewGuideContent(i){var e,t,r,n;const a=this._masterFormMetadata.getSheet(i);if(!a)return;const d=null===(t=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===t?void 0:t.get(i);return s("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==d?void 0:d.fixed,summaryFields:null===(n=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===n?void 0:n.get(i),name:i,label:a.label,fields:a.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:i,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps,fieldSearch:this._fieldSearch,entityPath:this.entityPath})}isDetailGuide(i,e){return i||e.length>0}buildDetailGuideContent(i,e,t,r){var n;let a,d;if(i.includes(m)){[e,a]=i.split(m);const s=(null===(n=this._breadcrumbItems)||void 0===n?void 0:n.length)||0;d=s>1?this._breadcrumbItems[s-2]:this.selectedGuide}else d=this.selectedGuide;return this.wrapDetail(t,s("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(t,r),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:r,selectedForm:a,branchGuide:d,guideItemPath:this._breadcrumbItems,key:`detail${e}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders,presentationMode:this.presentationMode}))}isCustomGuide(i){var e;return null===(e=this.customGuidesConfig)||void 0===e?void 0:e.map((i=>i.id)).includes(i)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;i&&(this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))])}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error(this.getMessage("snkCrud.errors.resourceIDNotProvided"));this._configManager=new c(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(window.scrollTo(0,0),this._guideHasChanged=!1)}async dataUnitActionHandler(i){var e;switch(i.type){case a.EDITION_CANCELED:case a.DATA_SAVED:this.dataUnit.isMultipleEdition&&(this.exitViewer(),this.dataUnit.isMultipleEdition=!1);break;case a.FIELD_INVALIDATED:const s=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(s),await this.openGuideNavigator(s);break;case a.METADATA_LOADED:case a.MULTIPLE_EDITION_CHANGED:this.loadGuides(this.noGuideSelected())}}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var s;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(s=i.badge)&&void 0!==s?s:null}getGuideName(i){var e;for(const s of this._masterFormMetadata.getAllSheets()){const t=null===(e=s[1])||void 0===e?void 0:e.fields;for(const e of t)if(e.name===i)return s[0]}return""}getCustomGuidesConfig(){return this._currentDetail?[]:this.customGuidesConfig}getFieldsSearch(){if(null==this._fieldSearch||this._hasToCreateFieldSearch){this._hasToCreateFieldSearch=!1;const i={label:this.getMessage("snkSimpleCrud.findFields"),value:"findFields"};this._fieldSearch=o(i,(({argument:i})=>this.fieldsOptionLoader(i)),(i=>this.onSelectField(i)))}return this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}onSelectField(i){if(null==i)return;this._fieldToGetFocus=i.value;const e=this.getGuideName(i.value);e!==this.selectedGuide.id&&this.changeGuideHandler(e)}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this)),this.initKeyboardManager(),this.getFieldsSearch()}disconnectedCallback(){var i;null===(i=this._keyboardManager)||void 0===i||i.unbindAllShortcutKeys()}async initKeyboardManager(){this._keyboardManager=new d({propagate:!1,element:this._element}),this._keyboardManager.bind(h,(async()=>{this._mainForm&&await this._mainForm.showSearchField()}),{description:this.getMessage("snkSimpleCrud.findFields"),element:this._element})}renderFormConfig(){if(null!=this._formEditorConfigManager)return s("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,customGuidesConfig:this.getCustomGuidesConfig()})}renderGuidesNavigator(i){var e;return s("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabIndex:-1},s("div",{class:"snk-guides-viewer__container"},i?s("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):s("div",null),s("div",{class:"snk-guides-viewer__detail-container"},f.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps,entityPath:this.entityPath}),this.getContent())),s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID,layoutFormConfig:!1,disableNumberingConfig:!0}))}render(){if(this.dataUnit&&this._configManager.isLoaded)return s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"guides-viewer-stack"},s("stack-item",null,this.renderGuidesNavigator(this._guides&&this._guides.length>1)),s("stack-item",null,this.renderFormConfig()))}get _element(){return r(this)}static get watchers(){return{dataUnit:["observeDataUnit"],_formEditorConfigManager:["observeFormConfigManager"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};var k;!function(i){i[i.GUIDES=0]="GUIDES",i[i.CONFIG=1]="CONFIG"}(k||(k={})),f.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:132px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;--snk-workspace--header-height:40px;display:block;outline:none}ez-guide-navigator.sc-snk-guides-viewer{--ez-guide-navigator--border-radius:var(--space--12, 12px)}snk-form-view.sc-snk-guides-viewer{width:100%}stack-item.snk-guides-viewer.sc-snk-guides-viewer{display:grid}stack-item.sc-snk-guides-viewer.sc-snk-guides-viewer{display:grid;min-height:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding:0 var(--snk-guides-viewer--space-small);padding-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column;max-height:calc(100vh - var(--snk-guides-viewer__header--min-height));overflow-y:auto}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:var(--snk-guides-viewer--space-small);height:calc(100vh - var(--snk-guides-viewer__header--min-height))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{f as S}
1
+ import{r as i,e,h as s,F as t,g as r}from"./p-2c9d0870.js";import{ObjectUtils as n,Action as a,KeyboardManager as d}from"@sankhyalabs/core";import{buildFieldSearch as o,SHORTCUT_SEARCH_FIELD as h}from"@sankhyalabs/ezui/dist/collection/utils";import{buildFormMetadata as l,FormMetadata as u}from"@sankhyalabs/ezui/dist/collection/utils/form";import{V as v}from"./p-9019a32f.js";import{S as c}from"./p-8d513b64.js";import{T as g}from"./p-3072136e.js";const m="__FORM:",f=class{constructor(s){i(this,s),this.snkShowGuide=e(this,"snkShowGuide",7),this.snkMasterFormConfigChange=e(this,"snkMasterFormConfigChange",7),this.formConfigVisibilityChanged=e(this,"formConfigVisibilityChanged",7),this.exit=e(this,"exit",7),this.actionClick=e(this,"actionClick",7),this.formItemsReady=e(this,"formItemsReady",7),this._guideBuilders=new Map,this.dataUnit=void 0,this.dataState=void 0,this.configName=void 0,this.entityPath=void 0,this.actionsList=void 0,this.recordsValidator=void 0,this.masterFormConfig=void 0,this.selectedGuide=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.canEdit=!0,this.presentationMode=void 0,this.resourceID=void 0,this.detailTaskbarCustomContainerId=void 0,this.formLegacyConfigName=void 0,this.enableGridInsert=!1,this.ignoreReadOnlyFormFields=void 0,this.getCustomTitle=void 0,this.customGuidesConfig=[],this._hasToCreateFieldSearch=!0,this._breadcrumbItems=[],this._guides=void 0,this._formEditorConfigManager=void 0,this._formEditorDataUnit=void 0,this._fieldToGetFocus=void 0,this._customEditors=void 0,this._customRenders=void 0,this._fieldsProps={},this._mainForm=void 0}observeDataUnit(){this.loadGuides(!0)}async observeFormConfigManager(i){const e=!!i;await this._viewStack.show(e?k.CONFIG:k.GUIDES),this.formConfigVisibilityChanged.emit(e)}observeDataState(i,e){var s,t,r,a,d,o;const h=null!==(t=null===(s=null==i?void 0:i.selectionInfo)||void 0===s?void 0:s.recordIds)&&void 0!==t?t:null===(r=null==i?void 0:i.selectedRecord)||void 0===r?void 0:r.__record__id__,l=null!==(d=null===(a=null==e?void 0:e.selectionInfo)||void 0===a?void 0:a.recordIds)&&void 0!==d?d:null===(o=null==e?void 0:e.selectedRecord)||void 0===o?void 0:o.__record__id__;n.equals(h,l)||this.loadGuides((null==e?void 0:e.insertionMode)!=(null==i?void 0:i.insertionMode))}observeMasterFormConfig(){this.loadGuides(this.noGuideSelected()),this.snkMasterFormConfigChange.emit(this.masterFormConfig)}async showFormConfig(i=!1){const e=!i||null==this._currentDetail;this._formEditorConfigManager=e?this._configManager:this._currentDetail.formConfigManager,this._formEditorDataUnit=e?this.dataUnit:this._currentDetail.dataUnit}async addCustomEditor(i,e){this._customEditors=Object.assign(Object.assign({},this._customEditors),{[i]:e})}async addGridCustomRender(i,e){this._customRenders=Object.assign(Object.assign({},this._customRenders),{[i]:e})}async setFieldProp(i,e,s){const t={[i]:Object.assign(Object.assign({},this._fieldsProps[i]),{[e]:s})};this._fieldsProps=Object.assign(Object.assign({},this._fieldsProps),t)}async setFocus(){var i;null===(i=this._container)||void 0===i||i.focus({preventScroll:!0})}async reloadGuides(){this.loadGuides(!1)}exitViewer(){!this.enableGridInsert&&this.dataUnit.isDirty()?this.dataUnit.cancelEdition({after:()=>this.exit.emit()}):this.exit.emit()}onActionClick(i){i.detail===g.CONFIGURATOR&&"master"!=i.target.dataset.taskbarOwner&&(this._snkConfigurator.open(),i.stopImmediatePropagation(),i.stopPropagation())}onContentCardChanged(i){f.updateContentCard(i.detail.formName,i.detail.cardConfig,i.detail.propertyChanged,this._configManager).then((()=>this.masterFormConfig=this._configManager.getConfig(this.dataUnit)))}getMessage(i){var e,s;if(this.dataUnit.isMultipleEdition){const i=null!==(s=null===(e=this.dataUnit.getSelectionInfo())||void 0===e?void 0:e.records)&&void 0!==s?s:[];return this.messagesBuilder.getMessage("snkCrud.multipleEdition.editing",{COUNT:i.length})}return this.messagesBuilder.getMessage(i,this.dataUnit.getSelectedRecord())}loadGuides(i){if(!this.dataUnit)return;if(!this._configManager.isLoaded)return;this._masterFormMetadata=l(this.masterFormConfig,this.dataUnit,!0,this.customGuidesConfig);const e=this._masterFormMetadata.getAllSheets(),s=this.dataUnit.getSelectedRecord(),t=this.hasToDisableDetails(s),r=[];Array.from(e.values()).forEach((i=>{const e={id:i.name,label:i.label};this.isDetail(i.name)&&t&&(e.tooltip=this.getMessage("snkCrud.detail.tooltip.needSingleSelection"),e.disabled=!0),i.isCustom&&i.ctxProps&&Object.entries(i.ctxProps).forEach((([i,s])=>{void 0!==s&&(e[i]=s)})),r.push(e)})),this._guides=r,this._guideNavigator&&this._guideNavigator.updateItem(this._guides),i&&(this.selectedGuide=this._guides.length>0?this._guides[0]:void 0)}hasToDisableDetails(i){return!i||this.dataUnit.isNewRecord(i.__record__id__)||this.dataUnit.isMultipleEdition}isDetail(i){return null!=u.getDetailName(i)}updateGuide(i){this._guideBuilders.set(i.id,i);const e=i.buildGuideItem(this._guideBuilders);this._guideNavigator&&(this._guideNavigator.updateItem(e).then((()=>{this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i}))})),this._guides=this._guides.map((i=>i.id===e.id?Object.assign(Object.assign(Object.assign({},i),e),void 0!==e.children?{}:{children:void 0}):i)))}static updateContentCard(i,e,s,t){return t.saveCardState(i,e,s)}static buildFixedForms(i){var e;const r=null===(e=i.formConfig)||void 0===e?void 0:e.cardsState;if(null!=r)return s(t,null,Array.from(r.entries()).filter((([e,s])=>(null==s?void 0:s.fixed)&&e!=i.selectedForm)).sort((([,i],[,e])=>((null==i?void 0:i.fixSequence)||0)-((null==e?void 0:e.fixSequence)||0))).map((([e,t])=>{var r,n;const a=i.formMetadata.getSheet(e);if(null!=a)return s("snk-form-view",{levelPath:i.levelPath,label:a.label,name:e,fields:a.fields,formMetadata:i.formMetadata,dataUnit:i.dataUnit,recordsValidator:i.recordsValidator,contracted:"CONTRACTED"===(null==t?void 0:t.presentation),fixed:null==t?void 0:t.fixed,summaryFields:null===(n=null===(r=i.formConfig)||void 0===r?void 0:r.summary)||void 0===n?void 0:n.get(e),fieldToFocus:i.fieldToFocus,key:e,onSnkRequestClearFieldToFocus:()=>{var e;return null===(e=i.onRequestClearFieldToFocus)||void 0===e?void 0:e.call(i)},customEditors:i.propsCustomEditor,fieldsProps:i.fieldsProps,entityPath:i.entityPath})})))}wrapDetail(i,e){if(0===i.length)return e;const t=i.pop(),r=u.getDetailName(t);return r?this.wrapDetail(i,s("snk-data-unit",{dataUnitName:`${this.getDataUnitName(i,r)}`,entityName:r},e)):void 0}getDataUnitName(i,e){if(i.length>0){const s=i.map((i=>u.getDetailName(i)));return`${this.entityPath}/${s.join("/")}/${e}`}return`${this.entityPath}/${e}`}getContent(){if(!this.selectedGuide)return void this.snkShowGuide.emit(void 0);const i=this.selectedGuide.id;if(this.snkShowGuide.emit(i),this.isCustomGuide(i))return s("slot",{name:i});const e=i.split("::"),t=e.pop(),r=u.getDetailName(t);let n=i;return this.isDetailGuide(r,e)?this.buildDetailGuideContent(i,n,e,r):this.buildFormViewGuideContent(i)}buildFormViewGuideContent(i){var e,t,r,n;const a=this._masterFormMetadata.getSheet(i);if(!a)return;const d=null===(t=null===(e=this.masterFormConfig)||void 0===e?void 0:e.cardsState)||void 0===t?void 0:t.get(i);return s("snk-form-view",{ref:i=>this._mainForm=i,fixed:null==d?void 0:d.fixed,summaryFields:null===(n=null===(r=this.masterFormConfig)||void 0===r?void 0:r.summary)||void 0===n?void 0:n.get(i),name:i,label:a.label,fields:a.fields,dataUnit:this.dataUnit,formMetadata:this._masterFormMetadata,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,key:i,onSnkRequestClearFieldToFocus:()=>this.clearFieldToFocusHandler(),customEditors:this._customEditors,fieldsProps:this._fieldsProps,fieldSearch:this._fieldSearch,entityPath:this.entityPath})}isDetailGuide(i,e){return i||e.length>0}buildDetailGuideContent(i,e,t,r){var n;let a,d;if(i.includes(m)){[e,a]=i.split(m);const s=(null===(n=this._breadcrumbItems)||void 0===n?void 0:n.length)||0;d=s>1?this._breadcrumbItems[s-2]:this.selectedGuide}else d=this.selectedGuide;return this.wrapDetail(t,s("snk-detail-view",{ref:i=>this._currentDetail=i,dataUnitName:this.getDataUnitName(t,r),onSnkDetailGuidesChange:i=>this.updateGuide(i.detail),entityName:r,selectedForm:a,branchGuide:d,guideItemPath:this._breadcrumbItems,key:`detail${e}`,canEdit:this.canEdit,onSnkSwitchGuide:i=>this._guideNavigator.selectGuide(i.detail),resourceID:this.resourceID,taskbarCustomContainerId:this.detailTaskbarCustomContainerId,customEditors:this._customEditors,customRenders:this._customRenders,presentationMode:this.presentationMode}))}isCustomGuide(i){var e;return null===(e=this.customGuidesConfig)||void 0===e?void 0:e.map((i=>i.id)).includes(i)}updateSelectedGuideHandler(i){this._guideHasChanged=this.selectedGuide!=i,this.selectedGuide=i,this._guideNavigator.getCurrentPath().then((i=>{this._breadcrumbItems=i})),this.resetGuideBadge(i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}resetGuideBadge(i){var e;i&&(this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>this.canClearGuideBadge(e,i.id)?Object.assign(Object.assign({},e),{badge:null}):e))])}canClearGuideBadge(i,e){return i.id===e||this.isIncludedInChildrenList(i,e)}isIncludedInChildrenList(i,e){return this.hasChildren(i)&&this.getChildrenIdList(i).includes(e)}hasChildren(i){return i.children&&Array.isArray(i.children)}getChildrenIdList(i){return i.children.map((i=>i.id))}getConfigViewMode(){return v.GRID}changeConfigViewMode(i){this._currentDetail&&this._currentDetail.changeViewMode(i)}openConfig(i){this._snkConfigurator.close(),this._currentDetail&&(i===v.FORM?this.showFormConfig(!0):this._currentDetail.configGrid())}noGuideSelected(){var i;return void 0===this.selectedGuide||"__main"===(null===(i=this.selectedGuide)||void 0===i?void 0:i.id)}addFormLegacyConfigName(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}setMasterFormConfig(i){this.masterFormConfig=i}componentWillLoad(){if(null==this.resourceID)throw new Error(this.getMessage("snkCrud.errors.resourceIDNotProvided"));this._configManager=new c(this.configName,this.resourceID,this.setMasterFormConfig.bind(this),this.dataUnit),this.addFormLegacyConfigName(),this._configManager.loadConfig()}componentDidRender(){this._guideHasChanged&&(window.scrollTo(0,0),this._guideHasChanged=!1)}async dataUnitActionHandler(i){var e;switch(i.type){case a.EDITION_CANCELED:case a.DATA_SAVED:this.dataUnit.isMultipleEdition&&(this.exitViewer(),this.dataUnit.isMultipleEdition=!1);break;case a.FIELD_INVALIDATED:const s=this.getGuideName(null===(e=i.payload)||void 0===e?void 0:e.fieldName);await this.addErrorBadgeToGuide(s),await this.openGuideNavigator(s);break;case a.METADATA_LOADED:case a.MULTIPLE_EDITION_CHANGED:this.loadGuides(this.noGuideSelected())}}async addErrorBadgeToGuide(i){var e;this._guides=[...null===(e=this._guides)||void 0===e?void 0:e.map((e=>Object.assign(Object.assign({},e),{badge:this.getBadge(e,i)})))]}async openGuideNavigator(i){this.selectedGuide.id!==i&&await this._guideNavigator.openGuideNavidator()}getBadge(i,e){var s;return this.selectedGuide.id===e?null:e===i.id?"error":null!==(s=i.badge)&&void 0!==s?s:null}getGuideName(i){var e;for(const s of this._masterFormMetadata.getAllSheets()){const t=null===(e=s[1])||void 0===e?void 0:e.fields;for(const e of t)if(e.name===i)return s[0]}return""}getCustomGuidesConfig(){return this._currentDetail?[]:this.customGuidesConfig}getFieldsSearch(){if(null==this._fieldSearch||this._hasToCreateFieldSearch){this._hasToCreateFieldSearch=!1;const i={label:this.getMessage("snkSimpleCrud.findFields"),value:"findFields"};this._fieldSearch=o(i,(({argument:i})=>this.fieldsOptionLoader(i)),(i=>this.onSelectField(i)))}return this._fieldSearch}fieldsOptionLoader(i){return Promise.resolve(this._configManager.getFieldsList(i).map((i=>({value:i.name,label:i.label}))))}changeGuideHandler(i){var e;null===(e=this._guideNavigator)||void 0===e||e.selectGuide(i)}onSelectField(i){if(null==i)return;this._fieldToGetFocus=i.value;const e=this.getGuideName(i.value);e!==this.selectedGuide.id&&this.changeGuideHandler(e)}componentDidLoad(){this.dataUnit.subscribe(this.dataUnitActionHandler.bind(this)),this.initKeyboardManager(),this.getFieldsSearch()}disconnectedCallback(){var i;null===(i=this._keyboardManager)||void 0===i||i.unbindAllShortcutKeys()}async initKeyboardManager(){this._keyboardManager=new d({propagate:!1,element:this._element}),this._keyboardManager.bind(h,(async()=>{this._mainForm&&await this._mainForm.showSearchField()}),{description:this.getMessage("snkSimpleCrud.findFields"),element:this._element})}renderFormConfig(){if(null!=this._formEditorConfigManager)return s("snk-form-config",{ref:i=>this._container=i,tabindex:-1,dataUnit:this._formEditorDataUnit,messagesBuilder:this.messagesBuilder,configManager:this._formEditorConfigManager,onConfigClose:()=>this._formEditorConfigManager=null,customGuidesConfig:this.getCustomGuidesConfig()})}renderGuidesNavigator(i){var e;return s("section",{class:"snk-guides-viewer",ref:i=>this._container=i,tabIndex:-1},s("div",{class:"snk-guides-viewer__container"},i?s("ez-guide-navigator",{ref:i=>this._guideNavigator=i,class:"snk-guides-viewer__guide-navigator",items:this._guides,selectedId:this.selectedGuide?this.selectedGuide.id:void 0,onEzSelectionChange:i=>this.updateSelectedGuideHandler(i.detail)}):s("div",null),s("div",{class:"snk-guides-viewer__detail-container"},f.buildFixedForms({formConfig:this.masterFormConfig,formMetadata:this._masterFormMetadata,selectedForm:null===(e=this.selectedGuide)||void 0===e?void 0:e.id,dataUnit:this.dataUnit,recordsValidator:this.recordsValidator,fieldToFocus:this._fieldToGetFocus,onRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this),propsCustomEditor:this._customEditors,fieldsProps:this._fieldsProps,entityPath:this.entityPath}),this.getContent())),s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this.getConfigViewMode(),onConfigSelected:i=>this.changeConfigViewMode(i.detail),messagesBuilder:this.messagesBuilder,onOpenConfig:i=>this.openConfig(i.detail),resourceID:this.resourceID,layoutFormConfig:!1,disableNumberingConfig:!0}))}render(){if(this.dataUnit&&this._configManager.isLoaded)return s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"guides-viewer-stack"},s("stack-item",null,this.renderGuidesNavigator(this._guides&&this._guides.length>1)),s("stack-item",null,this.renderFormConfig()))}get _element(){return r(this)}static get watchers(){return{dataUnit:["observeDataUnit"],_formEditorConfigManager:["observeFormConfigManager"],dataState:["observeDataState"],masterFormConfig:["observeMasterFormConfig"]}}};var k;!function(i){i[i.GUIDES=0]="GUIDES",i[i.CONFIG=1]="CONFIG"}(k||(k={})),f.style=".sc-snk-guides-viewer-h{--snk-guides-viewer--space-large:var(--space--large, 24px);--snk-guides-viewer--space-small:var(--space--2xs, 8px);--snk-guides-viewer__header--min-height:132px;--snk-guides-viewer__header--z-index:var(--more-visible, 2);--snk-guides-viewer__header--background-color:var(--background--body, #fafcff);--snk-guides-viewer__guide-navigator--width:340px;--snk-workspace--header-height:40px;display:block;outline:none}ez-guide-navigator.sc-snk-guides-viewer{--ez-guide-navigator--border-radius:var(--space--12, 12px)}snk-form-view.sc-snk-guides-viewer{width:100%}stack-item.snk-guides-viewer.sc-snk-guides-viewer{display:grid}stack-item.sc-snk-guides-viewer.sc-snk-guides-viewer{display:grid;min-height:100%}.snk-guides-viewer.sc-snk-guides-viewer{position:relative;padding:0 var(--snk-guides-viewer--space-small);padding-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__detail-container.sc-snk-guides-viewer{display:flex;row-gap:24px;flex-direction:column;max-height:calc(100vh - var(--snk-guides-viewer__header--min-height));overflow-y:auto}.snk-guides-viewer__header.sc-snk-guides-viewer{position:sticky;align-items:center;top:0;z-index:var(--snk-guides-viewer__header--z-index);background-color:var(--snk-guides-viewer__header--background-color);min-height:var(--snk-guides-viewer__header--min-height);width:calc(100% + (var(--snk-guides-viewer--space-large) * 2));padding-left:var(--snk-guides-viewer--space-large);padding-right:var(--snk-guides-viewer--space-large);padding-top:var(--snk-guides-viewer--space-large);padding-bottom:var(--snk-guides-viewer--space-small);margin-left:calc(var(--snk-guides-viewer--space-large) * -1);margin-right:calc(var(--snk-guides-viewer--space-large) * -1);margin-bottom:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__header-breadcrumb.sc-snk-guides-viewer{width:25%;display:flex}.snk-guides-viewer__header-taskbar.sc-snk-guides-viewer{width:75%}.snk-guides-viewer__container.sc-snk-guides-viewer{display:grid;grid-template-columns:minmax(0, auto) minmax(0, 100%);height:100%;column-gap:var(--snk-guides-viewer--space-small)}.snk-guides-viewer__guide-navigator.sc-snk-guides-viewer{position:sticky;top:var(--snk-guides-viewer--space-small);height:calc(100vh - var(--snk-guides-viewer__header--min-height))}.snk-guides-viewer__guide-navigator[open].sc-snk-guides-viewer{width:var(--snk-guides-viewer__guide-navigator--width);max-width:var(--snk-guides-viewer__guide-navigator--width);min-width:var(--snk-guides-viewer__guide-navigator--width)}.snk-guides-viewer__detail-content.sc-snk-guides-viewer{min-height:100%;align-items:flex-start;align-content:flex-start}";export{f as S}
@@ -1 +1 @@
1
- export{S as snk_guides_viewer}from"./p-70c2ee5c.js";import"./p-2c9d0870.js";import"@sankhyalabs/core";import"@sankhyalabs/ezui/dist/collection/utils";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-9019a32f.js";import"./p-1cc4cf61.js";import"./p-51e853f2.js";import"./p-d88278f8.js";import"./p-5d02c032.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"./p-3072136e.js";import"./p-0f3698af.js";import"./p-a73b6b00.js";
1
+ export{S as snk_guides_viewer}from"./p-c5889dae.js";import"./p-2c9d0870.js";import"@sankhyalabs/core";import"@sankhyalabs/ezui/dist/collection/utils";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-9019a32f.js";import"./p-8d513b64.js";import"./p-13f91e7e.js";import"./p-d7657667.js";import"./p-10d883b0.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"./p-3072136e.js";import"./p-0f3698af.js";import"./p-a73b6b00.js";
@@ -1,4 +1,4 @@
1
- import{d as e,D as t}from"./p-5d02c032.js";import{ObjectUtils as r}from"@sankhyalabs/core";class n{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchResource",e.gql`query($name: String!) {
1
+ import{d as e,D as t}from"./p-10d883b0.js";import{ObjectUtils as r}from"@sankhyalabs/core";class n{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchResource",e.gql`query($name: String!) {
2
2
  $queryAlias$: fetchResource(name: $name){
3
3
  resource
4
4
  }
@@ -1 +1 @@
1
- import{r as t,e as i,h as s,g as e,f as n}from"./p-2c9d0870.js";import{ApplicationContext as a,Action as r,ObjectUtils as o,DataUnitAction as h,StringUtils as d}from"@sankhyalabs/core";import{ApplicationUtils as l,DialogType as c}from"@sankhyalabs/ezui/dist/collection/utils";import{O as u,S as v}from"./p-5d02c032.js";import{g as m,a as f}from"./p-5c6eede7.js";import{convertType as p}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{g as b}from"./p-7dd49d15.js";const g="__NO_TAB_NAME__";const w=class{constructor(s){t(this,s),this.dataStateChange=i(this,"dataStateChange",3),this.dataUnitReady=i(this,"dataUnitReady",3),this.messagesBuilderUpdated=i(this,"messagesBuilderUpdated",3),this.dataUnitFieldsHidded=i(this,"dataUnitFieldsHidded",7),this.insertionMode=i(this,"insertionMode",3),this.cancelEdition=i(this,"cancelEdition",3),this._onDataUnitResolve=[],this._openedAlert=!1,this._fieldsWithRmp=[],this._fieldsWithRmPrecision=[],this._metadataByRow=new Map,this._rowMetadataCache=new Map,this._formFieldsConfig=[],this._internalDataStateChange=!1,this.REGEX_DATAUNIT_NAME=/dd:\/\/(.+?)\//,this._dataUnitObserver=async t=>{const i=await this.buildDataState(t.type);switch(this.dataState=i,this.messagesBuilder.currentOperation=this.getMessageOperation(),t.type){case r.DATA_SAVED:await this.handleDataSaved(t);break;case r.RECORDS_ADDED:case r.RECORDS_COPIED:this.insertionMode.emit();break;case r.EDITION_CANCELED:this.cancelEdition.emit();break;case r.RECORDS_REMOVED:this.handleRecordsRemoved(t);break;case r.METADATA_LOADED:this.fillFieldsWithRmp(this.dataUnit.metadata),this.fillFieldsWithRmPrecision(this.dataUnit.metadata)}},this.fieldsToLink=[],this.dataState=void 0,this.messagesBuilder=void 0,this.dataUnitName=void 0,this.entityName=void 0,this.pageSize=150,this.dataUnit=void 0,this.beforeSave=void 0,this.afterSave=void 0,this.useCancelConfirm=!0,this.ignoreSaveMessage=void 0,this.configName=void 0,this.resourceID=void 0,this.domainMessagesBuilder=void 0}observePageSize(){this.dataUnit&&(this.dataUnit.pageSize=this.pageSize)}observeDataUnitName(t,i){i!=t&&(this.dataUnit?this._application.updateDataunitCache(i,this.dataUnitName,this.dataUnit):this.loadDataUnit())}observeEntityName(t,i){i!=t&&(this.dataUnit=void 0,this.entityName=t,this.loadDataUnit())}observeDataState(t,i){o.objectToString(i)!=o.objectToString(t)&&this.dataStateChange.emit(t)}observeDataUnit(){this.handlerLinkFields(),this.dataUnitReady.emit(this.dataUnit)}observeMessagesBuilder(t){t&&this.messagesBuilderUpdated.emit(t)}onMasterFormConfigChange({detail:t}){var i;this._formFieldsConfig=null!==(i=null==t?void 0:t.fields)&&void 0!==i?i:[]}async getDataUnit(){return new Promise((t=>{this.dataUnit?t(this.dataUnit):this._onDataUnitResolve.push(t)}))}async getSelectedRecordsIDsInfo(){return b(this.dataUnit)}async getFieldsWithRmp(){return this._fieldsWithRmp}async getFieldsWithRmPrecision(){return this._fieldsWithRmPrecision}async getRowMetadata(t){return this.doGetRowMetadata(t)}async doGetRowMetadata(t){const i=this.dataUnit.getSelectedRecord();if(!t&&!i)return;const s=t||i,e="string"==typeof s?s:s.__record__id__;let n=this._metadataByRow.get(e);return this.dataUnit.isNewRecord(e)&&!n&&(n=await this.handleLoadRowMetadata(i)),n?(n.getProp=this.buildGetPropRowMetadata(n),Object.assign({},n)):void 0}buildGetPropRowMetadata(t){return(i,s)=>("rm_precision"===i&&(i=this.resolvePrecisionFromMetadata(s)),o.getProp(t,i))}resolvePrecisionFromMetadata(t){var i,s;if(!t)return void l.error(this.getMessage("snkDataUnit.fieldNameRequired"));const e=null===(s=null===(i=this.dataUnit.getField(t))||void 0===i?void 0:i.properties)||void 0===s?void 0:s.rm_precision;return e?e.split(".").filter(((t,i)=>1!==i)).join("."):""}getCleanOnCopyFields(){var t;return null===(t=this.dataUnit.metadata)||void 0===t?void 0:t.fields.filter((t=>{var i;return null===(i=t.properties)||void 0===i?void 0:i.cleanOnCopy})).map((t=>t.name))}fillFieldsWithRmp(t){t.fields.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rmp)&&!this._fieldsWithRmp.includes(t.name)&&this._fieldsWithRmp.push(t.name)}))}fillFieldsWithRmPrecision(t){t.fields.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rm_precision)&&!this._fieldsWithRmPrecision.includes(t.name)&&this._fieldsWithRmPrecision.push(t.name)}))}getCacheName(t,i,s){return[t,i,s].join("_")}updateDataStateRmp(t){const i=Object.assign({},t);this.dataState.rowMetadata=i}saveCacheRmd(t){const i=t.__record__metadata__,s=Object.keys(i);s.shift(),s.forEach((s=>{const e=m(t,s),n=this.getCacheName(s,i.provider,e);this._rowMetadataCache.set(n,Object.assign({},i))}))}getMetadataByRow(t){var i;if(!(null===(i=t.records)||void 0===i?void 0:i.length))return t;if(!this._fieldsWithRmp.length){const i=t.records.map((t=>(delete t.__record__metadata__,t)));return Object.assign(Object.assign({},t),{records:i})}const s=t.records.map((t=>{if(!t.__record__metadata__)return t;this.saveCacheRmd(t);const i=Object.assign({},t.__record__metadata__);return i.getProp=this.buildGetPropRowMetadata(i),this._metadataByRow.set(t.__record__id__,i),delete t.__record__metadata__,t}));return Object.assign(Object.assign({},t),{records:s})}interceptRecordsAdded(t){if(this.isAllowed("INSERT"))return new h(r.RECORDS_ADDED,this.handleLinksWithParent(t.payload));l.info(this.getMessage("snkDataUnit.forbiddenInsert"))}interceptRecordsCopied(t){if(this.isAllowed("CLONE"))return new h(r.RECORDS_COPIED,this.handleRecordsCopied(t.payload));l.info(this.getMessage("snkDataUnit.forbiddenClone"))}async interceptDataChange(t){var i;const s=null===(i=this.dataUnit.getSelectedRecord())||void 0===i?void 0:i.__record__id__;if(this.isAllowed("UPDATE")||this.dataUnit.isNewRecord(s))return t;if(this._internalDataStateChange)this._internalDataStateChange=!1;else{if(this._openedAlert)return this._internalDataStateChange=!0,void await this.dataUnit.cancelEdition();this._openedAlert=!0,this._internalDataStateChange=!0,await this.dataUnit.cancelEdition(),await l.alert(this.getMessage("snkDataUnit.forbidden"),this.getMessage("snkDataUnit.forbiddenUpdate")),this._openedAlert=!1}}async interceptSavingData(t){if(this.dataUnit.isMultipleEdition&&!await this.confirmMultipleSavingData())return;if(!this.beforeSave)return t;const i=this.beforeSave(this.dataUnit);return i instanceof Promise?await i?t:void 0:i?t:void 0}async confirmMultipleSavingData(){const t=this.dataUnit.getSelectionInfo().records,i=this.getMessage("snkDataUnit.multipleUpdateConfirmationTitle"),s=this.getMessage("snkDataUnit.multipleUpdateConfirmationMessage",{size:t.length}),e=this.getMessage("snkDataUnit.confirm.cancel"),n=this.getMessage("snkDataUnit.confirm.updateMultipleConfirm");return await async function({title:t,labelBtnConfirm:i,labelBtnCancel:s,message:e,changingFields:n}){return new Promise((r=>{const o=function(t,i){const s=document.createElement("ez-popup");return s.opened=!0,s.size="small",s.ezTitle=t,s.heightMode="auto",s.addEventListener("ezClosePopup",(()=>{document.body.removeChild(s),i(!1)}),{once:!0}),s.addEventListener("ezPopupAction",(()=>{document.body.removeChild(s),i(!1)}),{once:!0}),s}(t,r),h=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.fontFamily="var(--font-pattern, Roboto)",t.style.fontSize="var(--text--medium, 14px)",t}();h.appendChild(function(t){const i=document.createElement("p");return i.textContent=t,i.style.fontSize="var(--text--medium, 14px)",i}(e)),h.appendChild(function(t){const i=document.createElement("div");i.style.flexDirection="column",i.style.display="flex",i.style.overflow="auto",i.style.maxHeight="300px";const s=function(t){const i=new Map;return t.forEach((t=>{var s;const e=null!==(s=t.tabName)&&void 0!==s?s:g;i.has(e)||i.set(e,[]),i.get(e).push(t)})),i}(t);return s.forEach(((t,s)=>{i.appendChild(function(t,i){const s=document.createElement("span");s.innerText=function(t){const i=a.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage("snkDataUnit.main");switch(t){case g:return"";case"__main":return i;default:return t}}(t),s.style.display="block",s.style.fontWeight="var(--text-weight--large, 500)",s.style.fontSize="var(--text--medium, 14px)",s.style.marginBottom="var(--space--small, 6px)";const e=document.createElement("div");return e.style.padding="var(--space--medium, 12px) 0",e.style.borderTop="1px solid var(--color--disable-secondary, #f2f5f8)",e.appendChild(s),i.forEach((t=>{const i=document.createElement("span");i.innerHTML=`${t.label}: <span style="color: var(--text--primary, #626e82)">${t.value}</span>`,i.style.display="block",i.style.marginBottom="var(--space--extra-small, 3px)",e.appendChild(i)})),e}(s,t))})),i}(n));const d=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="row",t.style.justifyContent="flex-end",t.style.gap="5px",t}();d.appendChild(function(t,i,s){const e=document.createElement("ez-button");return e.label=i,e.size="medium",e.onclick=()=>{document.body.removeChild(t),s(!1)},e}(o,s,r)),d.appendChild(function(t,i,s){const e=document.createElement("ez-button");return e.label=i,e.size="medium",e.classList.add("ez-button--primary"),e.onclick=()=>{document.body.removeChild(t),s(!0)},e}(o,i,r)),h.appendChild(d),o.appendChild(h),document.body.appendChild(o)}))}({title:i,message:s,labelBtnConfirm:n,labelBtnCancel:e,changingFields:this.getChangingFields()})}getChangingFields(){const t=this.dataUnit.buildChangesToSave();if(!(null==t?void 0:t.length))return[];const i=t[0];return Object.keys(i.updatingFields).map((t=>this.buildChangingField(t,i[t])))}buildChangingField(t,i){return{label:this.dataUnit.getField(t).label,value:this.dataUnit.getFormattedValue(t,i),tabName:this.getFieldTabName(t)}}getFieldTabName(t){var i;const s=null===(i=this._formFieldsConfig.find((i=>i.name===t)))||void 0===i?void 0:i.tab;if(s)return"string"==typeof s?s:s.label}interceptDataSaved(t){if(!this.afterSave)return t;this.afterSave(this.dataUnit)}async interceptEditionCanceled(t){var i,s;if(!this.useCancelConfirm||!this.dataState.hasDirtyRecords||(null===(i=t.payload)||void 0===i?void 0:i.fromParent)||(null===(s=t.payload)||void 0===s?void 0:s.silent))return t;const e=this.getMessage("snkDataUnit.cancelConfirmation");if(null==e)return this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo")),t;const n=this.getMessage("snkDataUnit.cancelConfirmationTitle"),a=await l.confirm(n,e);if(a){let t;if(this.dataUnit.isMultipleEdition){const i=this.dataUnit.getSelectionInfo().records;t=this.buildMultipleUpdateMessage(i,!0)}else t=this.getMessage("snkDataUnit.cancelInfo");this.showSuccessMessage(t)}return a?t:void 0}async interceptRemovingRecords(t){var i,s,e;if(!this.isAllowed("REMOVE"))return void l.info(this.getMessage("snkDataUnit.forbiddenRemove"));let n=!1,a=!(null===(i=t.payload)||void 0===i?void 0:i.silent)&&this.getMessage("snkDataUnit.removeConfirmation");const r=null===(s=this.dataUnit)||void 0===s?void 0:s.getSelectionInfo();if(!(null===(e=t.payload)||void 0===e?void 0:e.silent)&&(null==r?void 0:r.length)>1&&(a=this.getMessage("snkDataUnit.removeAllConfirmation",{size:r.length}),n=!0),!a)return t;const o={canClose:!1,labelCancel:this.getMessage("snkDataUnit.confirm."+(n?"no":"cancel")),labelConfirm:this.getMessage("snkDataUnit.confirm."+(n?"yes":"delete")),btnConfirmDanger:!1},h=this.getMessage("snkDataUnit.removeConfirmationTitle");return await l.confirm(h,a,null,c.WARN,o)?t:void 0}interceptDataLoaded(t){const i=this.getMetadataByRow(t.payload);return new h(r.DATA_LOADED,i)}interceptMetadataLoaded(t){return this.fillFieldsWithRmp(t.payload),this.fillFieldsWithRmPrecision(t.payload),new h(r.METADATA_LOADED,this.handleDULinksOnMetadataLoaded(t.payload))}async interceptAction(t){switch(t.type){case r.RECORDS_ADDED:return this.interceptRecordsAdded(t);case r.RECORDS_COPIED:return this.interceptRecordsCopied(t);case r.DATA_CHANGED:return await this.handleLoadRowMetadata(t.payload),await this.interceptDataChange(t);case r.CHANGING_DATA:return await this.interceptDataChange(t);case r.SAVING_DATA:return await this.interceptSavingData(t);case r.DATA_SAVED:return this.interceptDataSaved(t);case r.EDITION_CANCELED:return await this.interceptEditionCanceled(t);case r.REMOVING_RECORDS:return await this.interceptRemovingRecords(t);case r.DATA_LOADED:return this.interceptDataLoaded(t);case r.METADATA_LOADED:return this.interceptMetadataLoaded(t);default:return t}}async handleLoadRowMetadata(t){if(!t)return;const i=Object.keys(t).find((t=>this._fieldsWithRmp.includes(t)));if(i){const s=this.dataUnit.getField(i).properties.rmp,e=m(t,i);return await this.updateRowMetadata({fieldName:i,fieldValue:e,metadataName:s,updatedFields:t})}}async updateRowMetadata({fieldName:t,fieldValue:i,metadataName:s,updatedFields:e}){const n=this.getCacheName(t,s,i),a=this._rowMetadataCache.get(n);if(a)return this.updateDataStateRmp(a),a;{const i=new f,a=await i.loadRowMetadata(this,t,s,e);return this.updateDataStateRmp(a._rmd),this._rowMetadataCache.set(n,Object.assign({},a._rmd)),Object.assign({},a._rmd)}}handleDULinksOnMetadataLoaded(t){const i=Object.assign({},t);return this.processLinks(i),i}handleRecordsCopied(t){let i=[...t];return i=this.handleCleanOnCopy(i),this.handleLinksWithParent(i)}handleLinksWithParent(t){var i,s;const e=null!==(i=this._parentDataUnit)&&void 0!==i?i:null===(s=this.dataUnit)||void 0===s?void 0:s.getParentDataUnit();if(!e)return t;const n=e.getSelectedRecord(),a=null==e?void 0:e.getChildInfo(this.getCleanDataUnitName());if(!a)return t;const{links:r}=a;return r&&0!==r.length?t.map((t=>this.buildRecordWithLinkedFields(t,r,n))):t}buildRecordWithLinkedFields(t,i,s){const e=Object.assign({},t);return i.forEach((t=>{const i=p(this.dataUnit.getField(t.target).dataType,s[t.source]);e[t.target]=i})),e}handleCleanOnCopy(t){const i=this.getCleanOnCopyFields();return i.length>0&&(t=t.map((t=>this.buildCopyWithCleanedFields(t,i)))),t}buildCopyWithCleanedFields(t,i){const s=Object.assign({},t);return i.forEach((t=>delete s[t])),s}showSuccessMessage(t){l.info(t,{iconName:"check"})}isAllowed(t){return!!this._permissions&&(this._permissions.isSup||this._permissions[t])}async buildDataState(t){var i;const s=this.dataUnit.getSelectionInfo(),e=(this.dataUnit.hasDirtyRecords()||this.dataUnit.hasWaitingChanges())&&(null==s?void 0:s.isEmpty()),n=this.dataUnit.getSelectedRecord();let a=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata;return!n||a&&![r.SELECTION_CHANGED,r.EDITION_CANCELED,r.NEXT_SELECTED,r.PREVIOUS_SELECTED].includes(t)?a&&(a.getProp=this.buildGetPropRowMetadata(a)):a=await this.doGetRowMetadata(n),new D({insertionMode:this.dataUnit.hasNewRecord(),isStartingInsertionMode:e,hasNext:this.dataUnit.hasNext(),hasPrevious:this.dataUnit.hasPrevious(),copyMode:this.dataUnit.hasCopiedRecord(),isDirty:this.dataUnit.isDirty(),hasDirtyRecords:this.dataUnit.hasDirtyRecords(),selectedRecords:void 0,selectionInfo:s,selectedRecord:n,recordsIsEmpty:0===this.dataUnit.records.length,metadataByRow:this._metadataByRow,rowMetadata:a})}async handleDataSaved(t){var i,s,e;const n=null===(i=null==t?void 0:t.payload)||void 0===i?void 0:i.changes,a=null===(s=null==t?void 0:t.payload)||void 0===s?void 0:s.records,r=await this.handleLoadRowMetadata(null===(e=null==n?void 0:n[0])||void 0===e?void 0:e.record);r&&(r.getProp=this.buildGetPropRowMetadata(r)),this._metadataByRow.set(a[0].__record__id__,r),this.dataState=await this.buildDataState();let o=n[0]._operation.toLowerCase();if("copy"==o&&(o=u.CLONE),this.canIgnoreOperationMessage(o))return;let h=this.buildOperationMessage(o,a);null!=h&&this.showSuccessMessage(h)}canIgnoreOperationMessage(t){return this.ignoreSaveMessage&&!this.isCloneOrInsertOperation(t)}isCloneOrInsertOperation(t){return[u.CLONE,u.INSERT].includes(t)}buildOperationMessage(t,i){return this.isMultiplesUpdate(t,i)?this.buildMultipleUpdateMessage(i):this.getMessage("snkDataUnit.saveInfo",i[0],t)}buildMultipleUpdateMessage(t,i){return this.getMessage("snkDataUnit."+(i?"cancelInfo":"saveInfo"),{records:t},u.UPDATE_MULTIPLES)}isMultiplesUpdate(t,i){return t===u.UPDATE&&i.length>1}handleRecordsRemoved(t){var i,s;let e=this.buildRemoveFinishMessage(t);null!=e&&this.showSuccessMessage(e);const n=null!==(s=null===(i=this.dataUnit.records)||void 0===i?void 0:i.length)&&void 0!==s?s:0,a=this.dataUnit.getPaginationInfo();a&&this.dataUnit.gotoPage(n>0||a.hasMore?a.currentPage:0)}buildRemoveFinishMessage(t){const i=t.payload.records;if(i&&i.length)return(null==i?void 0:i.length)>1?this.getMessage("snkDataUnit.removeAllInfo",{size:i.length}):this.getMessage("snkDataUnit.removeInfo",i)}getMessage(t,i,s){return i||(i=this.getMessageParams()),s&&(this.messagesBuilder.currentOperation=s),this.messagesBuilder.getMessage(t,i)}getMessageParams(){return this.dataState.selectedRecord}getMessageOperation(){return this.dataState.copyMode?u.CLONE:this.dataState.insertionMode||this.dataState.isStartingInsertionMode?u.INSERT:this.dataState.isDirty?u.UPDATE:u.CLEAN}async getDataUnitParentOrChild(){var t;const i=this.dataUnitName?this.dataUnitName:this.entityName;return this._parentSnkDataUnit?(this._parentDataUnit=await(null===(t=this._parentSnkDataUnit)||void 0===t?void 0:t.getDataUnit()),await this._application.getDataUnit(this.entityName,i,this._parentDataUnit,this.configName,this.resourceID)):await this._application.getDataUnit(this.entityName,i,null,this.configName,this.resourceID)}updateMetadataWithRMP(){this.fillFieldsWithRmp(this.dataUnit.metadata),this.fillFieldsWithRmPrecision(this.dataUnit.metadata);const t=this.handleDULinksOnMetadataLoaded(this.dataUnit.metadata);this.dataUnit.metadata=t}async loadDataUnit(){var t,i;if(null==this.dataUnit&&this._application&&this.entityName&&(this.dataUnit=await this.getDataUnitParentOrChild()),this.dataUnit){if(this.dataUnit.pageSize=this.pageSize,this.dataUnit.unsubscribe(this._dataUnitObserver),this.dataUnit.subscribe(this._dataUnitObserver),(null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)&&this.updateMetadataWithRMP(),this.dataUnit.addInterceptor(this),null===(i=this.dataUnit.records)||void 0===i?void 0:i.length){const{records:t}=this.getMetadataByRow(this.dataUnit);this.dataUnit.setRecordsKeepingSelection(t)}let s;for(this.dataState=await this.buildDataState();s=this._onDataUnitResolve.pop();)s(this.dataUnit)}}getParentSnkDataUnit(){let t=this.element;for(;t.parentNode;){if("SNK-DATA-UNIT"===t.parentNode.nodeName)return t.parentNode;t=t.parentNode}}handlerLinkFields(){var t,i,s,e;const n=null!==(t=this._parentDataUnit)&&void 0!==t?t:null===(i=this.dataUnit)||void 0===i?void 0:i.getParentDataUnit();if(!n)return;const a=null!==(s=this.entityName)&&void 0!==s?s:this.getCleanDataUnitName(),r=n.getChildInfo(a);if(!r)return;const o=null===(e=null==r?void 0:r.links)||void 0===e?void 0:e.map((t=>t.target));this.handleDUWithLinks(o)}handleDUWithLinks(t){this.fieldsToLink=t;const i=Object.assign({},this.dataUnit.metadata);this.processLinks(i),this.dataUnit.metadata=i,this.dataUnitFieldsHidded.emit()}processLinks(t){var i;null===(i=null==t?void 0:t.fields)||void 0===i||i.forEach((t=>{var i;(null===(i=this.fieldsToLink)||void 0===i?void 0:i.includes(t.name))&&(t.visible=!1)}))}getCleanDataUnitName(){var t;const i=this.dataUnit.name;if(d.isEmpty(i))return i;const s=this.REGEX_DATAUNIT_NAME.exec(i);return null!==(t=null==s?void 0:s[1])&&void 0!==t?t:i}static getNearestInstance(t){let i=t.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase())return i;i=i.parentElement}}instanceMessagesBuilder(){var t;this.messagesBuilder||(this.messagesBuilder=new v(null!==(t=this.domainMessagesBuilder)&&void 0!==t?t:this.entityName))}componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),this._application.getAllAccess(this.resourceID).then((t=>this._permissions=t)),this._parentSnkDataUnit=this.getParentSnkDataUnit(),this.instanceMessagesBuilder()}disconnectedCallback(){this.dataUnit&&this.dataUnit.releaseCallbacks()}async componentDidLoad(){await this.loadDataUnit(),this.handlerLinkFields()}render(){return s(n,null)}get element(){return e(this)}static get watchers(){return{pageSize:["observePageSize"],dataUnitName:["observeDataUnitName"],entityName:["observeEntityName"],dataState:["observeDataState"],dataUnit:["observeDataUnit"],messagesBuilder:["observeMessagesBuilder"]}}};class D{constructor(t){this.copyMode=t.copyMode,this.insertionMode=t.insertionMode,this.isStartingInsertionMode=t.isStartingInsertionMode,this.isDirty=t.isDirty,this.hasDirtyRecords=t.hasDirtyRecords,this.hasNext=t.hasNext,this.hasPrevious=t.hasPrevious,this.selectionInfo=t.selectionInfo,this.selectedRecord=t.selectedRecord,this.recordsIsEmpty=t.recordsIsEmpty,this.metadataByRow=t.metadataByRow,this.rowMetadata=t.rowMetadata}}export{w as S}
1
+ import{r as t,e as i,h as s,g as e,f as n}from"./p-2c9d0870.js";import{ApplicationContext as a,Action as r,ObjectUtils as o,DataUnitAction as h,StringUtils as d}from"@sankhyalabs/core";import{ApplicationUtils as l,DialogType as c}from"@sankhyalabs/ezui/dist/collection/utils";import{O as u,S as v}from"./p-10d883b0.js";import{g as m,a as f}from"./p-c1e168a2.js";import{convertType as p}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{g as b}from"./p-7dd49d15.js";const g="__NO_TAB_NAME__";const w=class{constructor(s){t(this,s),this.dataStateChange=i(this,"dataStateChange",3),this.dataUnitReady=i(this,"dataUnitReady",3),this.messagesBuilderUpdated=i(this,"messagesBuilderUpdated",3),this.dataUnitFieldsHidded=i(this,"dataUnitFieldsHidded",7),this.insertionMode=i(this,"insertionMode",3),this.cancelEdition=i(this,"cancelEdition",3),this._onDataUnitResolve=[],this._openedAlert=!1,this._fieldsWithRmp=[],this._fieldsWithRmPrecision=[],this._metadataByRow=new Map,this._rowMetadataCache=new Map,this._formFieldsConfig=[],this._internalDataStateChange=!1,this.REGEX_DATAUNIT_NAME=/dd:\/\/(.+?)\//,this._dataUnitObserver=async t=>{const i=await this.buildDataState(t.type);switch(this.dataState=i,this.messagesBuilder.currentOperation=this.getMessageOperation(),t.type){case r.DATA_SAVED:await this.handleDataSaved(t);break;case r.RECORDS_ADDED:case r.RECORDS_COPIED:this.insertionMode.emit();break;case r.EDITION_CANCELED:this.cancelEdition.emit();break;case r.RECORDS_REMOVED:this.handleRecordsRemoved(t);break;case r.METADATA_LOADED:this.fillFieldsWithRmp(this.dataUnit.metadata),this.fillFieldsWithRmPrecision(this.dataUnit.metadata)}},this.fieldsToLink=[],this.dataState=void 0,this.messagesBuilder=void 0,this.dataUnitName=void 0,this.entityName=void 0,this.pageSize=150,this.dataUnit=void 0,this.beforeSave=void 0,this.afterSave=void 0,this.useCancelConfirm=!0,this.ignoreSaveMessage=void 0,this.configName=void 0,this.resourceID=void 0,this.domainMessagesBuilder=void 0}observePageSize(){this.dataUnit&&(this.dataUnit.pageSize=this.pageSize)}observeDataUnitName(t,i){i!=t&&(this.dataUnit?this._application.updateDataunitCache(i,this.dataUnitName,this.dataUnit):this.loadDataUnit())}observeEntityName(t,i){i!=t&&(this.dataUnit=void 0,this.entityName=t,this.loadDataUnit())}observeDataState(t,i){o.objectToString(i)!=o.objectToString(t)&&this.dataStateChange.emit(t)}observeDataUnit(){this.handlerLinkFields(),this.dataUnitReady.emit(this.dataUnit)}observeMessagesBuilder(t){t&&this.messagesBuilderUpdated.emit(t)}onMasterFormConfigChange({detail:t}){var i;this._formFieldsConfig=null!==(i=null==t?void 0:t.fields)&&void 0!==i?i:[]}async getDataUnit(){return new Promise((t=>{this.dataUnit?t(this.dataUnit):this._onDataUnitResolve.push(t)}))}async getSelectedRecordsIDsInfo(){return b(this.dataUnit)}async getFieldsWithRmp(){return this._fieldsWithRmp}async getFieldsWithRmPrecision(){return this._fieldsWithRmPrecision}async getRowMetadata(t){return this.doGetRowMetadata(t)}async doGetRowMetadata(t){const i=this.dataUnit.getSelectedRecord();if(!t&&!i)return;const s=t||i,e="string"==typeof s?s:s.__record__id__;let n=this._metadataByRow.get(e);return this.dataUnit.isNewRecord(e)&&!n&&(n=await this.handleLoadRowMetadata(i)),n?(n.getProp=this.buildGetPropRowMetadata(n),Object.assign({},n)):void 0}buildGetPropRowMetadata(t){return(i,s)=>("rm_precision"===i&&(i=this.resolvePrecisionFromMetadata(s)),o.getProp(t,i))}resolvePrecisionFromMetadata(t){var i,s;if(!t)return void l.error(this.getMessage("snkDataUnit.fieldNameRequired"));const e=null===(s=null===(i=this.dataUnit.getField(t))||void 0===i?void 0:i.properties)||void 0===s?void 0:s.rm_precision;return e?e.split(".").filter(((t,i)=>1!==i)).join("."):""}getCleanOnCopyFields(){var t;return null===(t=this.dataUnit.metadata)||void 0===t?void 0:t.fields.filter((t=>{var i;return null===(i=t.properties)||void 0===i?void 0:i.cleanOnCopy})).map((t=>t.name))}fillFieldsWithRmp(t){t.fields.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rmp)&&!this._fieldsWithRmp.includes(t.name)&&this._fieldsWithRmp.push(t.name)}))}fillFieldsWithRmPrecision(t){t.fields.forEach((t=>{var i;(null===(i=t.properties)||void 0===i?void 0:i.rm_precision)&&!this._fieldsWithRmPrecision.includes(t.name)&&this._fieldsWithRmPrecision.push(t.name)}))}getCacheName(t,i,s){return[t,i,s].join("_")}updateDataStateRmp(t){const i=Object.assign({},t);this.dataState.rowMetadata=i}saveCacheRmd(t){const i=t.__record__metadata__,s=Object.keys(i);s.shift(),s.forEach((s=>{const e=m(t,s),n=this.getCacheName(s,i.provider,e);this._rowMetadataCache.set(n,Object.assign({},i))}))}getMetadataByRow(t){var i;if(!(null===(i=t.records)||void 0===i?void 0:i.length))return t;if(!this._fieldsWithRmp.length){const i=t.records.map((t=>(delete t.__record__metadata__,t)));return Object.assign(Object.assign({},t),{records:i})}const s=t.records.map((t=>{if(!t.__record__metadata__)return t;this.saveCacheRmd(t);const i=Object.assign({},t.__record__metadata__);return i.getProp=this.buildGetPropRowMetadata(i),this._metadataByRow.set(t.__record__id__,i),delete t.__record__metadata__,t}));return Object.assign(Object.assign({},t),{records:s})}interceptRecordsAdded(t){if(this.isAllowed("INSERT"))return new h(r.RECORDS_ADDED,this.handleLinksWithParent(t.payload));l.info(this.getMessage("snkDataUnit.forbiddenInsert"))}interceptRecordsCopied(t){if(this.isAllowed("CLONE"))return new h(r.RECORDS_COPIED,this.handleRecordsCopied(t.payload));l.info(this.getMessage("snkDataUnit.forbiddenClone"))}async interceptDataChange(t){var i;const s=null===(i=this.dataUnit.getSelectedRecord())||void 0===i?void 0:i.__record__id__;if(this.isAllowed("UPDATE")||this.dataUnit.isNewRecord(s))return t;if(this._internalDataStateChange)this._internalDataStateChange=!1;else{if(this._openedAlert)return this._internalDataStateChange=!0,void await this.dataUnit.cancelEdition();this._openedAlert=!0,this._internalDataStateChange=!0,await this.dataUnit.cancelEdition(),await l.alert(this.getMessage("snkDataUnit.forbidden"),this.getMessage("snkDataUnit.forbiddenUpdate")),this._openedAlert=!1}}async interceptSavingData(t){if(this.dataUnit.isMultipleEdition&&!await this.confirmMultipleSavingData())return;if(!this.beforeSave)return t;const i=this.beforeSave(this.dataUnit);return i instanceof Promise?await i?t:void 0:i?t:void 0}async confirmMultipleSavingData(){const t=this.dataUnit.getSelectionInfo().records,i=this.getMessage("snkDataUnit.multipleUpdateConfirmationTitle"),s=this.getMessage("snkDataUnit.multipleUpdateConfirmationMessage",{size:t.length}),e=this.getMessage("snkDataUnit.confirm.cancel"),n=this.getMessage("snkDataUnit.confirm.updateMultipleConfirm");return await async function({title:t,labelBtnConfirm:i,labelBtnCancel:s,message:e,changingFields:n}){return new Promise((r=>{const o=function(t,i){const s=document.createElement("ez-popup");return s.opened=!0,s.size="small",s.ezTitle=t,s.heightMode="auto",s.addEventListener("ezClosePopup",(()=>{document.body.removeChild(s),i(!1)}),{once:!0}),s.addEventListener("ezPopupAction",(()=>{document.body.removeChild(s),i(!1)}),{once:!0}),s}(t,r),h=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.fontFamily="var(--font-pattern, Roboto)",t.style.fontSize="var(--text--medium, 14px)",t}();h.appendChild(function(t){const i=document.createElement("p");return i.textContent=t,i.style.fontSize="var(--text--medium, 14px)",i}(e)),h.appendChild(function(t){const i=document.createElement("div");i.style.flexDirection="column",i.style.display="flex",i.style.overflow="auto",i.style.maxHeight="300px";const s=function(t){const i=new Map;return t.forEach((t=>{var s;const e=null!==(s=t.tabName)&&void 0!==s?s:g;i.has(e)||i.set(e,[]),i.get(e).push(t)})),i}(t);return s.forEach(((t,s)=>{i.appendChild(function(t,i){const s=document.createElement("span");s.innerText=function(t){const i=a.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage("snkDataUnit.main");switch(t){case g:return"";case"__main":return i;default:return t}}(t),s.style.display="block",s.style.fontWeight="var(--text-weight--large, 500)",s.style.fontSize="var(--text--medium, 14px)",s.style.marginBottom="var(--space--small, 6px)";const e=document.createElement("div");return e.style.padding="var(--space--medium, 12px) 0",e.style.borderTop="1px solid var(--color--disable-secondary, #f2f5f8)",e.appendChild(s),i.forEach((t=>{const i=document.createElement("span");i.innerHTML=`${t.label}: <span style="color: var(--text--primary, #626e82)">${t.value}</span>`,i.style.display="block",i.style.marginBottom="var(--space--extra-small, 3px)",e.appendChild(i)})),e}(s,t))})),i}(n));const d=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="row",t.style.justifyContent="flex-end",t.style.gap="5px",t}();d.appendChild(function(t,i,s){const e=document.createElement("ez-button");return e.label=i,e.size="medium",e.onclick=()=>{document.body.removeChild(t),s(!1)},e}(o,s,r)),d.appendChild(function(t,i,s){const e=document.createElement("ez-button");return e.label=i,e.size="medium",e.classList.add("ez-button--primary"),e.onclick=()=>{document.body.removeChild(t),s(!0)},e}(o,i,r)),h.appendChild(d),o.appendChild(h),document.body.appendChild(o)}))}({title:i,message:s,labelBtnConfirm:n,labelBtnCancel:e,changingFields:this.getChangingFields()})}getChangingFields(){const t=this.dataUnit.buildChangesToSave();if(!(null==t?void 0:t.length))return[];const i=t[0];return Object.keys(i.updatingFields).map((t=>this.buildChangingField(t,i[t])))}buildChangingField(t,i){return{label:this.dataUnit.getField(t).label,value:this.dataUnit.getFormattedValue(t,i),tabName:this.getFieldTabName(t)}}getFieldTabName(t){var i;const s=null===(i=this._formFieldsConfig.find((i=>i.name===t)))||void 0===i?void 0:i.tab;if(s)return"string"==typeof s?s:s.label}interceptDataSaved(t){if(!this.afterSave)return t;this.afterSave(this.dataUnit)}async interceptEditionCanceled(t){var i,s;if(!this.useCancelConfirm||!this.dataState.hasDirtyRecords||(null===(i=t.payload)||void 0===i?void 0:i.fromParent)||(null===(s=t.payload)||void 0===s?void 0:s.silent))return t;const e=this.getMessage("snkDataUnit.cancelConfirmation");if(null==e)return this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo")),t;const n=this.getMessage("snkDataUnit.cancelConfirmationTitle"),a=await l.confirm(n,e);if(a){let t;if(this.dataUnit.isMultipleEdition){const i=this.dataUnit.getSelectionInfo().records;t=this.buildMultipleUpdateMessage(i,!0)}else t=this.getMessage("snkDataUnit.cancelInfo");this.showSuccessMessage(t)}return a?t:void 0}async interceptRemovingRecords(t){var i,s,e;if(!this.isAllowed("REMOVE"))return void l.info(this.getMessage("snkDataUnit.forbiddenRemove"));let n=!1,a=!(null===(i=t.payload)||void 0===i?void 0:i.silent)&&this.getMessage("snkDataUnit.removeConfirmation");const r=null===(s=this.dataUnit)||void 0===s?void 0:s.getSelectionInfo();if(!(null===(e=t.payload)||void 0===e?void 0:e.silent)&&(null==r?void 0:r.length)>1&&(a=this.getMessage("snkDataUnit.removeAllConfirmation",{size:r.length}),n=!0),!a)return t;const o={canClose:!1,labelCancel:this.getMessage("snkDataUnit.confirm."+(n?"no":"cancel")),labelConfirm:this.getMessage("snkDataUnit.confirm."+(n?"yes":"delete")),btnConfirmDanger:!1},h=this.getMessage("snkDataUnit.removeConfirmationTitle");return await l.confirm(h,a,null,c.WARN,o)?t:void 0}interceptDataLoaded(t){const i=this.getMetadataByRow(t.payload);return new h(r.DATA_LOADED,i)}interceptMetadataLoaded(t){return this.fillFieldsWithRmp(t.payload),this.fillFieldsWithRmPrecision(t.payload),new h(r.METADATA_LOADED,this.handleDULinksOnMetadataLoaded(t.payload))}async interceptAction(t){switch(t.type){case r.RECORDS_ADDED:return this.interceptRecordsAdded(t);case r.RECORDS_COPIED:return this.interceptRecordsCopied(t);case r.DATA_CHANGED:return await this.handleLoadRowMetadata(t.payload),await this.interceptDataChange(t);case r.CHANGING_DATA:return await this.interceptDataChange(t);case r.SAVING_DATA:return await this.interceptSavingData(t);case r.DATA_SAVED:return this.interceptDataSaved(t);case r.EDITION_CANCELED:return await this.interceptEditionCanceled(t);case r.REMOVING_RECORDS:return await this.interceptRemovingRecords(t);case r.DATA_LOADED:return this.interceptDataLoaded(t);case r.METADATA_LOADED:return this.interceptMetadataLoaded(t);default:return t}}async handleLoadRowMetadata(t){if(!t)return;const i=Object.keys(t).find((t=>this._fieldsWithRmp.includes(t)));if(i){const s=this.dataUnit.getField(i).properties.rmp,e=m(t,i);return await this.updateRowMetadata({fieldName:i,fieldValue:e,metadataName:s,updatedFields:t})}}async updateRowMetadata({fieldName:t,fieldValue:i,metadataName:s,updatedFields:e}){const n=this.getCacheName(t,s,i),a=this._rowMetadataCache.get(n);if(a)return this.updateDataStateRmp(a),a;{const i=new f,a=await i.loadRowMetadata(this,t,s,e);return this.updateDataStateRmp(a._rmd),this._rowMetadataCache.set(n,Object.assign({},a._rmd)),Object.assign({},a._rmd)}}handleDULinksOnMetadataLoaded(t){const i=Object.assign({},t);return this.processLinks(i),i}handleRecordsCopied(t){let i=[...t];return i=this.handleCleanOnCopy(i),this.handleLinksWithParent(i)}handleLinksWithParent(t){var i,s;const e=null!==(i=this._parentDataUnit)&&void 0!==i?i:null===(s=this.dataUnit)||void 0===s?void 0:s.getParentDataUnit();if(!e)return t;const n=e.getSelectedRecord(),a=null==e?void 0:e.getChildInfo(this.getCleanDataUnitName());if(!a)return t;const{links:r}=a;return r&&0!==r.length?t.map((t=>this.buildRecordWithLinkedFields(t,r,n))):t}buildRecordWithLinkedFields(t,i,s){const e=Object.assign({},t);return i.forEach((t=>{const i=p(this.dataUnit.getField(t.target).dataType,s[t.source]);e[t.target]=i})),e}handleCleanOnCopy(t){const i=this.getCleanOnCopyFields();return i.length>0&&(t=t.map((t=>this.buildCopyWithCleanedFields(t,i)))),t}buildCopyWithCleanedFields(t,i){const s=Object.assign({},t);return i.forEach((t=>delete s[t])),s}showSuccessMessage(t){l.info(t,{iconName:"check"})}isAllowed(t){return!!this._permissions&&(this._permissions.isSup||this._permissions[t])}async buildDataState(t){var i;const s=this.dataUnit.getSelectionInfo(),e=(this.dataUnit.hasDirtyRecords()||this.dataUnit.hasWaitingChanges())&&(null==s?void 0:s.isEmpty()),n=this.dataUnit.getSelectedRecord();let a=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata;return!n||a&&![r.SELECTION_CHANGED,r.EDITION_CANCELED,r.NEXT_SELECTED,r.PREVIOUS_SELECTED].includes(t)?a&&(a.getProp=this.buildGetPropRowMetadata(a)):a=await this.doGetRowMetadata(n),new D({insertionMode:this.dataUnit.hasNewRecord(),isStartingInsertionMode:e,hasNext:this.dataUnit.hasNext(),hasPrevious:this.dataUnit.hasPrevious(),copyMode:this.dataUnit.hasCopiedRecord(),isDirty:this.dataUnit.isDirty(),hasDirtyRecords:this.dataUnit.hasDirtyRecords(),selectedRecords:void 0,selectionInfo:s,selectedRecord:n,recordsIsEmpty:0===this.dataUnit.records.length,metadataByRow:this._metadataByRow,rowMetadata:a})}async handleDataSaved(t){var i,s,e;const n=null===(i=null==t?void 0:t.payload)||void 0===i?void 0:i.changes,a=null===(s=null==t?void 0:t.payload)||void 0===s?void 0:s.records,r=await this.handleLoadRowMetadata(null===(e=null==n?void 0:n[0])||void 0===e?void 0:e.record);r&&(r.getProp=this.buildGetPropRowMetadata(r)),this._metadataByRow.set(a[0].__record__id__,r),this.dataState=await this.buildDataState();let o=n[0]._operation.toLowerCase();if("copy"==o&&(o=u.CLONE),this.canIgnoreOperationMessage(o))return;let h=this.buildOperationMessage(o,a);null!=h&&this.showSuccessMessage(h)}canIgnoreOperationMessage(t){return this.ignoreSaveMessage&&!this.isCloneOrInsertOperation(t)}isCloneOrInsertOperation(t){return[u.CLONE,u.INSERT].includes(t)}buildOperationMessage(t,i){return this.isMultiplesUpdate(t,i)?this.buildMultipleUpdateMessage(i):this.getMessage("snkDataUnit.saveInfo",i[0],t)}buildMultipleUpdateMessage(t,i){return this.getMessage("snkDataUnit."+(i?"cancelInfo":"saveInfo"),{records:t},u.UPDATE_MULTIPLES)}isMultiplesUpdate(t,i){return t===u.UPDATE&&i.length>1}handleRecordsRemoved(t){var i,s;let e=this.buildRemoveFinishMessage(t);null!=e&&this.showSuccessMessage(e);const n=null!==(s=null===(i=this.dataUnit.records)||void 0===i?void 0:i.length)&&void 0!==s?s:0,a=this.dataUnit.getPaginationInfo();a&&this.dataUnit.gotoPage(n>0||a.hasMore?a.currentPage:0)}buildRemoveFinishMessage(t){const i=t.payload.records;if(i&&i.length)return(null==i?void 0:i.length)>1?this.getMessage("snkDataUnit.removeAllInfo",{size:i.length}):this.getMessage("snkDataUnit.removeInfo",i)}getMessage(t,i,s){return i||(i=this.getMessageParams()),s&&(this.messagesBuilder.currentOperation=s),this.messagesBuilder.getMessage(t,i)}getMessageParams(){return this.dataState.selectedRecord}getMessageOperation(){return this.dataState.copyMode?u.CLONE:this.dataState.insertionMode||this.dataState.isStartingInsertionMode?u.INSERT:this.dataState.isDirty?u.UPDATE:u.CLEAN}async getDataUnitParentOrChild(){var t;const i=this.dataUnitName?this.dataUnitName:this.entityName;return this._parentSnkDataUnit?(this._parentDataUnit=await(null===(t=this._parentSnkDataUnit)||void 0===t?void 0:t.getDataUnit()),await this._application.getDataUnit(this.entityName,i,this._parentDataUnit,this.configName,this.resourceID)):await this._application.getDataUnit(this.entityName,i,null,this.configName,this.resourceID)}updateMetadataWithRMP(){this.fillFieldsWithRmp(this.dataUnit.metadata),this.fillFieldsWithRmPrecision(this.dataUnit.metadata);const t=this.handleDULinksOnMetadataLoaded(this.dataUnit.metadata);this.dataUnit.metadata=t}async loadDataUnit(){var t,i;if(null==this.dataUnit&&this._application&&this.entityName&&(this.dataUnit=await this.getDataUnitParentOrChild()),this.dataUnit){if(this.dataUnit.pageSize=this.pageSize,this.dataUnit.unsubscribe(this._dataUnitObserver),this.dataUnit.subscribe(this._dataUnitObserver),(null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)&&this.updateMetadataWithRMP(),this.dataUnit.addInterceptor(this),null===(i=this.dataUnit.records)||void 0===i?void 0:i.length){const{records:t}=this.getMetadataByRow(this.dataUnit);this.dataUnit.setRecordsKeepingSelection(t)}let s;for(this.dataState=await this.buildDataState();s=this._onDataUnitResolve.pop();)s(this.dataUnit)}}getParentSnkDataUnit(){let t=this.element;for(;t.parentNode;){if("SNK-DATA-UNIT"===t.parentNode.nodeName)return t.parentNode;t=t.parentNode}}handlerLinkFields(){var t,i,s,e;const n=null!==(t=this._parentDataUnit)&&void 0!==t?t:null===(i=this.dataUnit)||void 0===i?void 0:i.getParentDataUnit();if(!n)return;const a=null!==(s=this.entityName)&&void 0!==s?s:this.getCleanDataUnitName(),r=n.getChildInfo(a);if(!r)return;const o=null===(e=null==r?void 0:r.links)||void 0===e?void 0:e.map((t=>t.target));this.handleDUWithLinks(o)}handleDUWithLinks(t){this.fieldsToLink=t;const i=Object.assign({},this.dataUnit.metadata);this.processLinks(i),this.dataUnit.metadata=i,this.dataUnitFieldsHidded.emit()}processLinks(t){var i;null===(i=null==t?void 0:t.fields)||void 0===i||i.forEach((t=>{var i;(null===(i=this.fieldsToLink)||void 0===i?void 0:i.includes(t.name))&&(t.visible=!1)}))}getCleanDataUnitName(){var t;const i=this.dataUnit.name;if(d.isEmpty(i))return i;const s=this.REGEX_DATAUNIT_NAME.exec(i);return null!==(t=null==s?void 0:s[1])&&void 0!==t?t:i}static getNearestInstance(t){let i=t.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase())return i;i=i.parentElement}}instanceMessagesBuilder(){var t;this.messagesBuilder||(this.messagesBuilder=new v(null!==(t=this.domainMessagesBuilder)&&void 0!==t?t:this.entityName))}componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),this._application.getAllAccess(this.resourceID).then((t=>this._permissions=t)),this._parentSnkDataUnit=this.getParentSnkDataUnit(),this.instanceMessagesBuilder()}disconnectedCallback(){this.dataUnit&&this.dataUnit.releaseCallbacks()}async componentDidLoad(){await this.loadDataUnit(),this.handlerLinkFields()}render(){return s(n,null)}get element(){return e(this)}static get watchers(){return{pageSize:["observePageSize"],dataUnitName:["observeDataUnitName"],entityName:["observeEntityName"],dataState:["observeDataState"],dataUnit:["observeDataUnit"],messagesBuilder:["observeMessagesBuilder"]}}};class D{constructor(t){this.copyMode=t.copyMode,this.insertionMode=t.insertionMode,this.isStartingInsertionMode=t.isStartingInsertionMode,this.isDirty=t.isDirty,this.hasDirtyRecords=t.hasDirtyRecords,this.hasNext=t.hasNext,this.hasPrevious=t.hasPrevious,this.selectionInfo=t.selectionInfo,this.selectedRecord=t.selectedRecord,this.recordsIsEmpty=t.recordsIsEmpty,this.metadataByRow=t.metadataByRow,this.rowMetadata=t.rowMetadata}}export{w as S}