@sankhyalabs/sankhyablocks 1.4.0-beta.6 → 1.4.0-beta.8

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 (194) hide show
  1. package/dist/cjs/{SnkMessageBuilder-b54dfb89.js → SnkMessageBuilder-6c2f7bcd.js} +87 -11
  2. package/dist/cjs/_commonjsHelpers-537d719a.js +20 -0
  3. package/dist/cjs/configurableElementsStorage-93459c72.js +20 -0
  4. package/dist/cjs/constants-aebcc2f5.js +69 -0
  5. package/dist/cjs/draggable.bundle-82a25c06.js +6886 -0
  6. package/dist/cjs/form-config-fetcher-2de7c16a.js +6895 -0
  7. package/dist/cjs/{index-6fcf07f3.js → index-188190ee.js} +2 -0
  8. package/dist/cjs/loader.cjs.js +2 -2
  9. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  10. package/dist/cjs/snk-application.cjs.entry.js +240 -6972
  11. package/dist/cjs/snk-config-modal.cjs.entry.js +62 -0
  12. package/dist/cjs/snk-config-options.cjs.entry.js +163 -0
  13. package/dist/cjs/{snk-filter-bar_5.cjs.entry.js → snk-configurator_6.cjs.entry.js} +193 -6
  14. package/dist/cjs/snk-crud.cjs.entry.js +13 -11
  15. package/dist/cjs/snk-data-unit.cjs.entry.js +2 -2
  16. package/dist/cjs/snk-field-config_2.cjs.entry.js +135 -0
  17. package/dist/cjs/snk-filter-binary-select.cjs.entry.js +1 -1
  18. package/dist/cjs/snk-filter-detail.cjs.entry.js +1 -1
  19. package/dist/cjs/snk-filter-multi-select.cjs.entry.js +1 -1
  20. package/dist/cjs/snk-filter-number.cjs.entry.js +1 -1
  21. package/dist/cjs/snk-filter-period.cjs.entry.js +1 -1
  22. package/dist/cjs/snk-filter-personalized.cjs.entry.js +1 -1
  23. package/dist/cjs/snk-filter-search.cjs.entry.js +1 -1
  24. package/dist/cjs/snk-filter-text.cjs.entry.js +1 -1
  25. package/dist/cjs/snk-form-config.cjs.entry.js +957 -0
  26. package/dist/cjs/snk-form.cjs.entry.js +146 -0
  27. package/dist/cjs/snk-pesquisa.cjs.entry.js +1 -1
  28. package/dist/cjs/snk-tab-config.cjs.entry.js +321 -0
  29. package/dist/cjs/{taskbar-elements-aedfeae6.js → taskbar-elements-4c2c6704.js} +10 -6
  30. package/dist/cjs/taskbar-processor-6bd0d35c.js +47 -0
  31. package/dist/cjs/teste-pesquisa.cjs.entry.js +1 -1
  32. package/dist/collection/collection-manifest.json +27 -1
  33. package/dist/collection/components/snk-application/errorhandler/snk-error-handler.js +1 -1
  34. package/dist/collection/components/snk-application/snk-application.js +144 -23
  35. package/dist/collection/components/snk-configurator/snk-configurator.js +261 -0
  36. package/dist/collection/components/snk-configurator/subcomponents/configModalProvider/configurableElementsStorage.js +16 -0
  37. package/dist/collection/components/snk-configurator/subcomponents/snk-config-modal/snk-config-modal.css +122 -0
  38. package/dist/collection/components/snk-configurator/subcomponents/snk-config-modal/snk-config-modal.js +137 -0
  39. package/dist/collection/components/snk-crud/snk-crud.js +15 -13
  40. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-personalized.js +33 -3
  41. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-search.js +3 -3
  42. package/dist/collection/components/snk-filter-bar/snk-filter-bar.css +1 -1
  43. package/dist/collection/components/snk-form/snk-form.css +4 -0
  44. package/dist/collection/components/snk-form/snk-form.js +108 -30
  45. package/dist/collection/components/snk-form/subcomponents/snk-config-options/snk-config-options.css +9 -0
  46. package/dist/collection/components/snk-form/subcomponents/snk-config-options/snk-config-options.js +248 -0
  47. package/dist/collection/components/snk-form/subcomponents/snk-field-config/snk-field-config.css +164 -0
  48. package/dist/collection/components/snk-form/subcomponents/snk-field-config/snk-field-config.js +140 -0
  49. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.css +185 -0
  50. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +1062 -0
  51. package/dist/collection/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.css +272 -0
  52. package/dist/collection/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.js +476 -0
  53. package/dist/collection/components/snk-grid/snk-grid.js +92 -22
  54. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +9 -5
  55. package/dist/collection/components/snk-taskbar/snk-taskbar.js +35 -3
  56. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +35 -0
  57. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +106 -3
  58. package/dist/collection/lib/http/data-fetcher/fetchers/resource-fetcher.js +9 -1
  59. package/dist/collection/lib/message/SnkMessageBuilder.js +8 -1
  60. package/dist/collection/lib/message/resources/snk-configurator.msg.js +11 -0
  61. package/dist/collection/lib/message/resources/snk-form.msg.js +59 -2
  62. package/dist/collection/lib/message/resources/snk-taskbar.msg.js +1 -1
  63. package/dist/collection/lib/utils/constants.js +58 -0
  64. package/dist/components/SnkMessageBuilder.js +87 -11
  65. package/dist/components/_commonjsHelpers.js +17 -0
  66. package/dist/components/constants.js +60 -0
  67. package/dist/components/form-config-fetcher.js +6889 -0
  68. package/dist/components/index.d.ts +6 -0
  69. package/dist/components/index.js +6 -0
  70. package/dist/components/snk-application2.js +225 -6954
  71. package/dist/components/snk-config-modal.d.ts +11 -0
  72. package/dist/components/snk-config-modal.js +6 -0
  73. package/dist/components/snk-config-modal2.js +91 -0
  74. package/dist/components/snk-config-options.d.ts +11 -0
  75. package/dist/components/snk-config-options.js +6 -0
  76. package/dist/components/snk-config-options2.js +178 -0
  77. package/dist/components/snk-configurator.d.ts +11 -0
  78. package/dist/components/snk-configurator.js +6 -0
  79. package/dist/components/snk-configurator2.js +212 -0
  80. package/dist/components/snk-crud.js +62 -25
  81. package/dist/components/snk-field-config.d.ts +11 -0
  82. package/dist/components/snk-field-config.js +6 -0
  83. package/dist/components/snk-field-config2.js +70 -0
  84. package/dist/components/snk-filter-bar2.js +1 -1
  85. package/dist/components/snk-filter-personalized.js +2 -0
  86. package/dist/components/snk-form-config.d.ts +11 -0
  87. package/dist/components/snk-form-config.js +6 -0
  88. package/dist/components/snk-form-config2.js +996 -0
  89. package/dist/components/snk-form2.js +79 -29
  90. package/dist/components/snk-grid2.js +43 -24
  91. package/dist/components/snk-tab-config.d.ts +11 -0
  92. package/dist/components/snk-tab-config.js +6 -0
  93. package/dist/components/snk-tab-config2.js +7220 -0
  94. package/dist/components/snk-taskbar2.js +27 -9
  95. package/dist/esm/{SnkMessageBuilder-d440381c.js → SnkMessageBuilder-5792c260.js} +87 -11
  96. package/dist/esm/_commonjsHelpers-9943807e.js +17 -0
  97. package/dist/esm/configurableElementsStorage-cdc144b5.js +18 -0
  98. package/dist/esm/constants-c4e3341e.js +60 -0
  99. package/dist/esm/draggable.bundle-41d56f06.js +6884 -0
  100. package/dist/esm/form-config-fetcher-96c6c2dc.js +6889 -0
  101. package/dist/esm/{index-81dda3cf.js → index-bafb2cef.js} +2 -1
  102. package/dist/esm/loader.js +2 -2
  103. package/dist/esm/sankhyablocks.js +2 -2
  104. package/dist/esm/snk-application.entry.js +224 -6956
  105. package/dist/esm/snk-config-modal.entry.js +58 -0
  106. package/dist/esm/snk-config-options.entry.js +159 -0
  107. package/dist/esm/{snk-filter-bar_5.entry.js → snk-configurator_6.entry.js} +194 -8
  108. package/dist/esm/snk-crud.entry.js +13 -11
  109. package/dist/esm/snk-data-unit.entry.js +2 -2
  110. package/dist/esm/snk-field-config_2.entry.js +130 -0
  111. package/dist/esm/snk-filter-binary-select.entry.js +1 -1
  112. package/dist/esm/snk-filter-detail.entry.js +1 -1
  113. package/dist/esm/snk-filter-multi-select.entry.js +1 -1
  114. package/dist/esm/snk-filter-number.entry.js +1 -1
  115. package/dist/esm/snk-filter-period.entry.js +1 -1
  116. package/dist/esm/snk-filter-personalized.entry.js +1 -1
  117. package/dist/esm/snk-filter-search.entry.js +1 -1
  118. package/dist/esm/snk-filter-text.entry.js +1 -1
  119. package/dist/esm/snk-form-config.entry.js +953 -0
  120. package/dist/esm/snk-form.entry.js +142 -0
  121. package/dist/esm/snk-pesquisa.entry.js +1 -1
  122. package/dist/esm/snk-tab-config.entry.js +317 -0
  123. package/dist/esm/{taskbar-elements-38eb5d51.js → taskbar-elements-2035b1c7.js} +10 -6
  124. package/dist/esm/taskbar-processor-aa6772c9.js +45 -0
  125. package/dist/esm/teste-pesquisa.entry.js +1 -1
  126. package/dist/sankhyablocks/p-03f9c407.js +1 -0
  127. package/dist/sankhyablocks/{p-ba426ea9.entry.js → p-04ad681a.entry.js} +1 -1
  128. package/dist/sankhyablocks/p-112455b1.js +1 -0
  129. package/dist/sankhyablocks/p-1963b46f.entry.js +1 -0
  130. package/dist/sankhyablocks/p-21c8929b.js +1 -0
  131. package/dist/sankhyablocks/p-26c503a6.entry.js +1 -0
  132. package/dist/sankhyablocks/{p-2e49afef.entry.js → p-31631fb6.entry.js} +1 -1
  133. package/dist/sankhyablocks/p-361299e8.js +26 -0
  134. package/dist/sankhyablocks/p-434e0dcf.entry.js +1 -0
  135. package/dist/sankhyablocks/{p-aecf3e0a.entry.js → p-6c61416a.entry.js} +1 -1
  136. package/dist/sankhyablocks/{p-49580cdd.entry.js → p-857c4735.entry.js} +1 -1
  137. package/dist/sankhyablocks/{p-4574a955.entry.js → p-8cd8977c.entry.js} +1 -1
  138. package/dist/sankhyablocks/{p-6386d720.entry.js → p-916068ff.entry.js} +1 -1
  139. package/dist/sankhyablocks/p-9f2c5fac.entry.js +1 -0
  140. package/dist/sankhyablocks/p-ad658f44.js +1 -0
  141. package/dist/sankhyablocks/p-ae302037.entry.js +75 -0
  142. package/dist/sankhyablocks/p-af11b0e7.js +1 -0
  143. package/dist/sankhyablocks/p-af306302.entry.js +1 -0
  144. package/dist/sankhyablocks/p-b6d6b172.js +1 -0
  145. package/dist/sankhyablocks/{p-40b27004.entry.js → p-cc85ba53.entry.js} +1 -1
  146. package/dist/sankhyablocks/{p-0352c0e2.entry.js → p-ccdf59eb.entry.js} +1 -1
  147. package/dist/sankhyablocks/p-ce789145.entry.js +1 -0
  148. package/dist/sankhyablocks/p-cf81e313.entry.js +1 -0
  149. package/dist/sankhyablocks/{p-0ea25487.entry.js → p-d1ae76ec.entry.js} +1 -1
  150. package/dist/sankhyablocks/p-d50651a3.js +1 -0
  151. package/dist/sankhyablocks/{p-fac2b6a9.js → p-ddb03141.js} +2 -2
  152. package/dist/sankhyablocks/p-ee906940.entry.js +1 -0
  153. package/dist/sankhyablocks/{p-5bdb8452.entry.js → p-f9084ecb.entry.js} +1 -1
  154. package/dist/sankhyablocks/p-fa75fba5.entry.js +1 -0
  155. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  156. package/dist/types/components/snk-application/snk-application.d.ts +29 -14
  157. package/dist/types/components/snk-configurator/snk-configurator.d.ts +46 -0
  158. package/dist/types/components/snk-configurator/subcomponents/configModalProvider/configurableElementsStorage.d.ts +8 -0
  159. package/dist/types/components/snk-configurator/subcomponents/snk-config-modal/snk-config-modal.d.ts +38 -0
  160. package/dist/types/components/snk-crud/snk-crud.d.ts +50 -0
  161. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +92 -0
  162. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-personalized.d.ts +8 -6
  163. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-search.d.ts +3 -3
  164. package/dist/types/components/snk-filter-bar/filter-item/snk-filter-item.d.ts +40 -0
  165. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +65 -0
  166. package/dist/types/components/snk-form/snk-form.d.ts +71 -0
  167. package/dist/types/components/snk-form/subcomponents/snk-config-options/snk-config-options.d.ts +41 -0
  168. package/dist/types/components/snk-form/subcomponents/snk-field-config/snk-field-config.d.ts +32 -0
  169. package/dist/types/components/snk-form/subcomponents/snk-form-config/snk-form-config.d.ts +139 -0
  170. package/dist/types/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.d.ts +97 -0
  171. package/dist/types/components/snk-grid/snk-grid.d.ts +59 -0
  172. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +6 -5
  173. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +11 -3
  174. package/dist/types/components.d.ts +358 -13
  175. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +1 -0
  176. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +21 -3
  177. package/dist/types/lib/http/data-fetcher/fetchers/resource-fetcher.d.ts +1 -0
  178. package/dist/types/lib/message/resources/snk-configurator.msg.d.ts +2 -0
  179. package/dist/types/lib/message/resources/snk-form.msg.d.ts +5 -2
  180. package/dist/types/lib/utils/constants.d.ts +62 -0
  181. package/dist/types/lib/utils/pesquisa.d.ts +2 -1
  182. package/package.json +4 -3
  183. package/react/components.d.ts +6 -0
  184. package/react/components.js +6 -0
  185. package/react/components.js.map +1 -1
  186. package/dist/cjs/snk-form_2.cjs.entry.js +0 -247
  187. package/dist/esm/snk-form_2.entry.js +0 -242
  188. package/dist/sankhyablocks/p-1a58f45c.entry.js +0 -74
  189. package/dist/sankhyablocks/p-21e940aa.entry.js +0 -1
  190. package/dist/sankhyablocks/p-2eea7eea.js +0 -1
  191. package/dist/sankhyablocks/p-77216252.entry.js +0 -1
  192. package/dist/sankhyablocks/p-86f15ffe.js +0 -1
  193. package/dist/sankhyablocks/p-97009a2c.entry.js +0 -1
  194. package/dist/sankhyablocks/p-a14c49db.entry.js +0 -1
@@ -0,0 +1,1062 @@
1
+ import { h, Host } from "@stencil/core";
2
+ import { Sortable } from '@shopify/draggable';
3
+ import { ApplicationContext, ObjectUtils, ArrayUtils } from '@sankhyalabs/core';
4
+ import { ApplicationUtils, DialogType } from "@sankhyalabs/ezui/dist/collection/utils";
5
+ import { ACTION_CONFIG, CONFIG_EVENTS, TAB_NAMES } from "../../../../lib/utils/constants";
6
+ import { UserConfigType } from "../../../../lib/http/data-fetcher/fetchers/form-config-fetcher";
7
+ const CONTAINER_ID = {
8
+ collapsibleBox: "EZ-COLLAPSIBLE-BOX",
9
+ withoutGroup: "fieldsWithoutGroupContainer",
10
+ fieldsAvailable: "fieldsAvailableContainer",
11
+ addNewGroup: "addNewGroupContainer"
12
+ };
13
+ export class SnkFormConfig {
14
+ constructor() {
15
+ this._listEnabledFields = [];
16
+ this._renderTimer = 500;
17
+ this._sortableTimer = 100;
18
+ this._tabSelected = 1;
19
+ this._labelNewGroup = "Novo grupo";
20
+ this._mouseOnFieldConfig = false;
21
+ this._mouseOnConfigOptions = false;
22
+ this._editingTitleGroup = false;
23
+ this._newGroupBoxes = [];
24
+ this._currentGroupBoxes = [];
25
+ this._formFieldsStyle = "ez-col ez-col--sd-12 ez-col--tb-4 ez-padding-right--small ez-padding-bottom--medium sc-snk-form-config";
26
+ this._fieldsAvailableStyle = "ez-col ez-col--sd-12 ez-col--tb-12 ez-margin-bottom--medium ez-margin-right--medium sc-snk-form-config";
27
+ this._fieldFloatingStyle = "form-config__field-config--dragged";
28
+ this._formConfigOptions = [];
29
+ this._formConfig = {};
30
+ this._formConfigChanged = false;
31
+ this._optionFormConfigChanged = false;
32
+ this._tempGroups = [];
33
+ /**
34
+ * Campos de configuração de formulário.
35
+ */
36
+ this.formConfig = {};
37
+ }
38
+ observeFormConfig() {
39
+ this.loadConfig(this._sortableTimer);
40
+ }
41
+ loadFields(updateTimer = 0) {
42
+ this._layoutFormConfig = [];
43
+ // this._layoutFormConfig ? this._layoutFormConfig.length = 0 : this._layoutFormConfig = [];
44
+ /*
45
+ TODO: Validar a possibilidade de fazer diretamente this._layoutFormConfig.length = 0
46
+ sem a necessidade do ternario abaixo, para isso definir um default para o this._layoutFormConfig
47
+ na declaração da variavel
48
+ - Impactou:
49
+ - Inserir um field, alterar a tab de lugar e inserir um novo campo
50
+ - Ocultar/Deletar sequencialmente mais de uma aba
51
+ */
52
+ if (updateTimer > 0) {
53
+ setTimeout(() => {
54
+ this.buildFields();
55
+ }, updateTimer);
56
+ }
57
+ else {
58
+ this.buildFields();
59
+ }
60
+ }
61
+ buildFields() {
62
+ this.buildFormConfig();
63
+ this.buildAvailableFields();
64
+ }
65
+ loadFormConfig(updateTimer) {
66
+ var _a;
67
+ this._formConfig = ObjectUtils.copy(this.formConfig);
68
+ this.loadFields(updateTimer);
69
+ this.controlFieldConfig();
70
+ if (((_a = this._filterFieldsAvailable) === null || _a === void 0 ? void 0 : _a.value) != undefined) {
71
+ this._filterFieldsAvailable.value = "";
72
+ }
73
+ }
74
+ cancelChangeConfig() {
75
+ if (this._formConfigChanged === true) {
76
+ this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((canCancel) => {
77
+ if (canCancel) {
78
+ this._formConfigChanged = false;
79
+ this.resetChangeConfig();
80
+ }
81
+ });
82
+ }
83
+ else {
84
+ this.resetChangeConfig();
85
+ }
86
+ }
87
+ cancelChangeOptionConfig() {
88
+ if (this._optionFormConfigChanged === true) {
89
+ this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((canCancel) => {
90
+ if (canCancel) {
91
+ this._optionFormConfigChanged = false;
92
+ this.resetChangeOptionConfig();
93
+ }
94
+ });
95
+ }
96
+ else {
97
+ this.resetChangeOptionConfig();
98
+ }
99
+ }
100
+ resetChangeConfig() {
101
+ this.loadFormConfig(this._sortableTimer);
102
+ this.clearTempGroups();
103
+ }
104
+ resetChangeOptionConfig() {
105
+ this._formConfigChanged = false;
106
+ this.loadConfig(this._sortableTimer);
107
+ this.clearTempGroups();
108
+ }
109
+ getTabsToSave() {
110
+ return this._layoutFormConfig
111
+ .map((layoutConfig, index) => {
112
+ return {
113
+ label: layoutConfig.tab,
114
+ order: index,
115
+ visible: layoutConfig.visible
116
+ };
117
+ });
118
+ }
119
+ getFieldsToSave() {
120
+ const fields = [];
121
+ const snkFieldConfigs = this._formContainer.querySelectorAll('snk-field-config');
122
+ snkFieldConfigs.forEach((snkField) => {
123
+ const fieldConfig = snkField.fieldConfig;
124
+ if (fieldConfig) {
125
+ const fieldToSave = {
126
+ cleanOnCopy: fieldConfig.cleanOnCopy || false,
127
+ group: fieldConfig.group,
128
+ label: fieldConfig.label,
129
+ name: fieldConfig.name,
130
+ required: fieldConfig.required,
131
+ readOnly: fieldConfig.readOnly,
132
+ tab: fieldConfig.tab,
133
+ defaultValue: fieldConfig.defaultValue
134
+ };
135
+ fields.push(fieldToSave);
136
+ }
137
+ });
138
+ return fields;
139
+ }
140
+ isDefaultConfiguration() {
141
+ var _a;
142
+ const optionSelected = (_a = this._optionFormConfigSelected) === null || _a === void 0 ? void 0 : _a.origin;
143
+ return optionSelected === UserConfigType.DEFAULT
144
+ && this._optionFormConfigChanged === true
145
+ && this._formConfigChanged === false;
146
+ }
147
+ saveConfig() {
148
+ var _a;
149
+ if (((_a = this._tempGroups) === null || _a === void 0 ? void 0 : _a.length) > 0) {
150
+ ApplicationUtils.alert(this.getMessage("snkFormConfig.confirm.title"), this.getMessage("snkFormConfig.confirm.group"));
151
+ return;
152
+ }
153
+ const isDefault = this.isDefaultConfiguration();
154
+ let formConfig = {};
155
+ if (isDefault) {
156
+ formConfig = ObjectUtils.copy(this.formConfig);
157
+ }
158
+ else {
159
+ formConfig = ObjectUtils.copy(this._formConfig);
160
+ }
161
+ if (isDefault === false) {
162
+ const tabs = this.getTabsToSave();
163
+ if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) > 0) {
164
+ formConfig.tabs = tabs;
165
+ }
166
+ const fields = this.getFieldsToSave();
167
+ if ((fields === null || fields === void 0 ? void 0 : fields.length) > 0) {
168
+ formConfig.fields = fields;
169
+ }
170
+ }
171
+ formConfig.defaultConfiguration = isDefault;
172
+ this.configChange.emit(formConfig);
173
+ this._formConfigChanged = false;
174
+ this._optionFormConfigChanged = false;
175
+ }
176
+ applyOptionConfig() {
177
+ if (this._optionFormConfigChanged === true && this._optionFormConfigSelected != undefined) {
178
+ const name = this._optionFormConfigSelected.name || "configuração selecionada";
179
+ const origin = this._optionFormConfigSelected.origin === UserConfigType.DEFAULT ? "pessoal" : "padrão";
180
+ const msg = this.getMessage("snkFormConfig.confirm.apply").replace('{0}', name).replace('{1}', origin);
181
+ this.openConfirmDialog(msg).then((canCancel) => {
182
+ if (canCancel) {
183
+ this.saveConfig();
184
+ }
185
+ });
186
+ }
187
+ else {
188
+ this.saveConfig();
189
+ }
190
+ }
191
+ controlFieldConfig(fieldConfig = undefined) {
192
+ var _a;
193
+ if (fieldConfig == undefined) {
194
+ this._fieldConfigSelected = undefined;
195
+ return;
196
+ }
197
+ if (((_a = this._fieldConfigSelected) === null || _a === void 0 ? void 0 : _a.name) === (fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.name)) {
198
+ this._fieldConfigSelected = undefined;
199
+ }
200
+ else {
201
+ this._fieldConfigSelected = fieldConfig;
202
+ }
203
+ }
204
+ getFieldConfigStyle(fieldConfig) {
205
+ var _a;
206
+ return this._formFieldsStyle +
207
+ (((_a = this._fieldConfigSelected) === null || _a === void 0 ? void 0 : _a.name) === fieldConfig.name ? " form-config__field-config--selected" : "");
208
+ }
209
+ getFieldsByGroup(group) {
210
+ var _a;
211
+ return ((_a = group.fields) === null || _a === void 0 ? void 0 : _a.length) ? group.fields.map((field) => {
212
+ var _a, _b;
213
+ return h("div", { key: field.name, class: this.getFieldConfigStyle(field), "data-draggable-element": "field", onMouseDown: (evt) => this.controlMoveField(evt) }, h("snk-field-config", { onEzClickIcon: (evt) => { this.handleFieldConfigChange(evt); }, modeInsertion: false, fieldConfig: field, isConfigActive: ((_a = this._fieldConfigSelected) === null || _a === void 0 ? void 0 : _a.name) === field.name }), ((_b = this._fieldConfigSelected) === null || _b === void 0 ? void 0 : _b.name) === field.name &&
214
+ h("div", { class: "ez-flex form-config__config-options" }, h("snk-config-options", { idConfig: field.name, dataUnit: this.dataUnit, fieldConfig: this._fieldConfigSelected, onConfigOptionsChanged: (ev) => this.handleconfigOptionsChanged(ev.detail) })));
215
+ }) : h("div", { class: "form-config__add-group-container" }, h("div", { class: "form-config__add-group-content" }, h("div", { class: "form-config__add-group-label" }, h("label", { class: "ez-text ez-text--center ez-text--medium ez-text--primary ez-text--bold" }, this.getMessage("snkFormConfig.form.labelDropField")))));
216
+ }
217
+ handleconfigOptionsChanged(fieldEdited) {
218
+ var _a;
219
+ (_a = this._formConfig.fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
220
+ if (field.name === fieldEdited.name) {
221
+ field = fieldEdited;
222
+ }
223
+ });
224
+ this._formConfigChanged = true;
225
+ }
226
+ closeFormConfig() {
227
+ if (this._formConfigChanged === true || this._optionFormConfigChanged === true) {
228
+ this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.exit")).then((canClose) => {
229
+ if (canClose) {
230
+ this._formConfigChanged = false;
231
+ this.setShowFormConfig(false);
232
+ }
233
+ });
234
+ }
235
+ else {
236
+ this.setShowFormConfig(false);
237
+ }
238
+ }
239
+ openConfirmDialog(msg = "", title = this.getMessage("snkFormConfig.confirm.title")) {
240
+ return ApplicationUtils.confirm(title, msg);
241
+ }
242
+ controlMoveField(evt) {
243
+ const element = evt === null || evt === void 0 ? void 0 : evt.target;
244
+ if ((element === null || element === void 0 ? void 0 : element.closest('[data-draggable-element="field"]')) != undefined) {
245
+ this._mouseOnFieldConfig = true;
246
+ if ((element === null || element === void 0 ? void 0 : element.closest(".form-config__config-options")) != undefined || (element === null || element === void 0 ? void 0 : element.closest('.field-config__options')) != undefined) {
247
+ this._mouseOnConfigOptions = true;
248
+ }
249
+ else {
250
+ const iconList = ['minus', 'settings-inverted', 'chevron-up'];
251
+ const iconName = element === null || element === void 0 ? void 0 : element.iconName;
252
+ if (iconList.includes(iconName) === false) {
253
+ this.controlFieldConfig();
254
+ }
255
+ }
256
+ }
257
+ }
258
+ controlStartDraggingField(evt) {
259
+ var _a, _b, _c;
260
+ if (this._mouseOnConfigOptions) {
261
+ evt === null || evt === void 0 ? void 0 : evt.cancel();
262
+ this._mouseOnConfigOptions = false;
263
+ }
264
+ else {
265
+ const sourceContainer = (_c = (_b = (_a = evt === null || evt === void 0 ? void 0 : evt.data) === null || _a === void 0 ? void 0 : _a.dragEvent) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.sourceContainer;
266
+ if (sourceContainer != undefined) {
267
+ sourceContainer.classList.add(this._fieldFloatingStyle);
268
+ }
269
+ }
270
+ }
271
+ controlSortedDraggingField(evt) {
272
+ var _a, _b, _c, _d, _e, _f, _g, _h;
273
+ const oldContainer = (_a = evt === null || evt === void 0 ? void 0 : evt.data) === null || _a === void 0 ? void 0 : _a.oldContainer;
274
+ const newContainer = (_b = evt === null || evt === void 0 ? void 0 : evt.data) === null || _b === void 0 ? void 0 : _b.newContainer;
275
+ const draggingElement = (_e = (_d = (_c = evt === null || evt === void 0 ? void 0 : evt.data) === null || _c === void 0 ? void 0 : _c.dragEvent) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.source;
276
+ const originalElement = (_h = (_g = (_f = evt === null || evt === void 0 ? void 0 : evt.data) === null || _f === void 0 ? void 0 : _f.dragEvent) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.originalSource;
277
+ if (oldContainer != undefined && newContainer != undefined && draggingElement != undefined && originalElement != undefined) {
278
+ if ((newContainer.tagName === CONTAINER_ID.collapsibleBox
279
+ || newContainer.id === CONTAINER_ID.withoutGroup)
280
+ && oldContainer.id === CONTAINER_ID.fieldsAvailable) {
281
+ draggingElement.className = this._formFieldsStyle;
282
+ draggingElement.querySelector('snk-field-config').modeInsertion = false;
283
+ originalElement.className = this._formFieldsStyle;
284
+ originalElement.querySelector('snk-field-config').modeInsertion = false;
285
+ }
286
+ else if ((oldContainer.tagName === CONTAINER_ID.collapsibleBox
287
+ || oldContainer.id === CONTAINER_ID.withoutGroup)
288
+ && newContainer.id === CONTAINER_ID.fieldsAvailable) {
289
+ draggingElement.className = this._fieldsAvailableStyle;
290
+ draggingElement.querySelector('snk-field-config').modeInsertion = true;
291
+ originalElement.className = this._fieldsAvailableStyle;
292
+ originalElement.querySelector('snk-field-config').modeInsertion = true;
293
+ }
294
+ }
295
+ }
296
+ isCancelDragAvailableField(newContainer, oldContainer, evt) {
297
+ var _a, _b;
298
+ if (newContainer == undefined || oldContainer == undefined || evt == undefined) {
299
+ return false;
300
+ }
301
+ if (((_a = evt.data) === null || _a === void 0 ? void 0 : _a.newIndex) !== ((_b = evt.data) === null || _b === void 0 ? void 0 : _b.oldIndex)
302
+ && newContainer.id === CONTAINER_ID.fieldsAvailable
303
+ && oldContainer.id === newContainer.id) {
304
+ evt.cancel();
305
+ this._fieldsAvailable = [];
306
+ setTimeout(() => {
307
+ this.buildAvailableFields();
308
+ }, this._sortableTimer);
309
+ return true;
310
+ }
311
+ return false;
312
+ }
313
+ isRemoveField(newContainer, oldContainer, fieldConfig) {
314
+ if (newContainer == undefined || oldContainer == undefined || fieldConfig == undefined) {
315
+ return false;
316
+ }
317
+ if ((oldContainer.tagName === CONTAINER_ID.collapsibleBox
318
+ || oldContainer.id === CONTAINER_ID.withoutGroup)
319
+ && newContainer.id === CONTAINER_ID.fieldsAvailable) {
320
+ const eventDetail = {
321
+ detail: {
322
+ field: fieldConfig,
323
+ type: ACTION_CONFIG.remove
324
+ }
325
+ };
326
+ setTimeout(() => {
327
+ this.handleFieldConfigChange(eventDetail, this._sortableTimer);
328
+ }, this._renderTimer);
329
+ return true;
330
+ }
331
+ return false;
332
+ }
333
+ isAddOrMoveField(newContainer, oldContainer, fieldConfig, data) {
334
+ var _a;
335
+ if (newContainer == undefined || oldContainer == undefined || fieldConfig == undefined || data == undefined) {
336
+ return false;
337
+ }
338
+ if (data.newIndex !== data.oldIndex
339
+ || oldContainer.dataset.groupName !== newContainer.dataset.groupName
340
+ || (newContainer.id === CONTAINER_ID.withoutGroup
341
+ && oldContainer.id === CONTAINER_ID.fieldsAvailable)) {
342
+ if (this.isFieldAvailable(newContainer, oldContainer)) {
343
+ fieldConfig.tab = (_a = this._tabConfig) === null || _a === void 0 ? void 0 : _a.selectedTab;
344
+ }
345
+ fieldConfig.group = newContainer.dataset.groupName;
346
+ setTimeout(() => {
347
+ const isNewGroup = newContainer.id.includes(CONTAINER_ID.addNewGroup);
348
+ if (isNewGroup) {
349
+ this.clearTempGroups(true);
350
+ }
351
+ const sortableTimer = oldContainer.dataset.groupName !== newContainer.dataset.groupName
352
+ || (newContainer.id === CONTAINER_ID.withoutGroup && oldContainer.id === CONTAINER_ID.fieldsAvailable)
353
+ ? this._sortableTimer
354
+ : 0;
355
+ this.updateFieldsToSave(sortableTimer);
356
+ }, this._renderTimer);
357
+ return true;
358
+ }
359
+ return false;
360
+ }
361
+ isFieldAvailable(newContainer, oldContainer) {
362
+ if (newContainer == undefined || oldContainer == undefined) {
363
+ return false;
364
+ }
365
+ return (newContainer.tagName === CONTAINER_ID.collapsibleBox
366
+ || newContainer.id === CONTAINER_ID.withoutGroup)
367
+ && oldContainer.id === CONTAINER_ID.fieldsAvailable;
368
+ }
369
+ controlStopDraggingField(evt) {
370
+ var _a, _b, _c, _d, _e, _f;
371
+ const oldContainer = (_a = evt === null || evt === void 0 ? void 0 : evt.data) === null || _a === void 0 ? void 0 : _a.oldContainer;
372
+ const newContainer = (_b = evt === null || evt === void 0 ? void 0 : evt.data) === null || _b === void 0 ? void 0 : _b.newContainer;
373
+ if (this.isCancelDragAvailableField(newContainer, oldContainer, evt)) {
374
+ return;
375
+ }
376
+ const originalElement = (_e = (_d = (_c = evt === null || evt === void 0 ? void 0 : evt.data) === null || _c === void 0 ? void 0 : _c.dragEvent) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.originalSource;
377
+ const fieldConfig = (_f = originalElement === null || originalElement === void 0 ? void 0 : originalElement.querySelector('snk-field-config')) === null || _f === void 0 ? void 0 : _f.fieldConfig;
378
+ if (this.isRemoveField(newContainer, oldContainer, fieldConfig)) {
379
+ return;
380
+ }
381
+ if (this.isAddOrMoveField(newContainer, oldContainer, fieldConfig, evt === null || evt === void 0 ? void 0 : evt.data)) {
382
+ return;
383
+ }
384
+ }
385
+ updateFieldsToSave(updateTimer = 0) {
386
+ const fields = this.getFieldsToSave();
387
+ if ((fields === null || fields === void 0 ? void 0 : fields.length) > 0) {
388
+ this._formConfig.fields = fields;
389
+ }
390
+ this.loadFields(updateTimer);
391
+ this._formConfigChanged = true;
392
+ }
393
+ controlSortableField() {
394
+ if (this._sortableContainer == undefined) {
395
+ return;
396
+ }
397
+ if (this._sortableField) {
398
+ this._sortableField.destroy();
399
+ }
400
+ this._sortableField = new Sortable(this._sortableContainer.querySelectorAll('[data-draggable-parent="field"]'), {
401
+ draggable: '[data-draggable-element="field"]',
402
+ mirror: {
403
+ constrainDimensions: true
404
+ }
405
+ });
406
+ this._sortableField.on(CONFIG_EVENTS.dragStart, (evt) => this.controlStartDraggingField(evt));
407
+ this._sortableField.on(CONFIG_EVENTS.dragSorted, (evt) => this.controlSortedDraggingField(evt));
408
+ this._sortableField.on(CONFIG_EVENTS.dragStop, (evt) => this.controlStopDraggingField(evt));
409
+ }
410
+ controlStartDraggingGroup(evt) {
411
+ if (this._mouseOnFieldConfig || this._editingTitleGroup) {
412
+ evt === null || evt === void 0 ? void 0 : evt.cancel();
413
+ this._mouseOnFieldConfig = false;
414
+ }
415
+ }
416
+ controlStopDraggingGroup(evt) {
417
+ if (evt.data.newIndex !== evt.data.oldIndex) {
418
+ setTimeout(() => {
419
+ this.updateFieldsToSave(this._sortableTimer);
420
+ }, this._renderTimer);
421
+ }
422
+ }
423
+ controlSortableGroup() {
424
+ if (this._sortableContainer == undefined) {
425
+ return;
426
+ }
427
+ if (this._sortableGroup) {
428
+ this._sortableGroup.destroy();
429
+ }
430
+ this._sortableGroup = new Sortable(this._sortableContainer.querySelectorAll('[data-draggable-parent="group"]'), {
431
+ draggable: '[data-draggable-element="group"]',
432
+ mirror: {
433
+ constrainDimensions: true
434
+ }
435
+ });
436
+ this._sortableGroup.on(CONFIG_EVENTS.dragStart, (evt) => this.controlStartDraggingGroup(evt));
437
+ this._sortableGroup.on(CONFIG_EVENTS.dragStop, (evt) => this.controlStopDraggingGroup(evt));
438
+ }
439
+ loadUserConfig() {
440
+ var _a;
441
+ if (this._application != undefined) {
442
+ this._application.fetchUserAvailableConfigs((_a = this.parentForm) === null || _a === void 0 ? void 0 : _a.configName)
443
+ .then((userConfig) => {
444
+ this._formConfigOptions = userConfig;
445
+ let isDefault = this._formConfig != undefined ? this._formConfig.defaultConfiguration : true;
446
+ const selectedOption = userConfig
447
+ .find((config) => {
448
+ return config.origin === (isDefault ? UserConfigType.DEFAULT : UserConfigType.USER);
449
+ });
450
+ this.setFormConfig(selectedOption);
451
+ });
452
+ }
453
+ }
454
+ setFormConfig(config) {
455
+ this._optionFormConfigSelected = config;
456
+ }
457
+ controlSelectFormConfig(evt) {
458
+ const action = evt === null || evt === void 0 ? void 0 : evt.detail;
459
+ const selectedOption = this._formConfigOptions
460
+ .find((config) => {
461
+ return config.origin === (action === null || action === void 0 ? void 0 : action.value);
462
+ });
463
+ this.setFormConfig(selectedOption);
464
+ this._optionFormConfigChanged = true;
465
+ this.loadConfigByUser();
466
+ }
467
+ changeTabOrder(newIndex) {
468
+ const tabs = [];
469
+ const tabConfigs = this._tabConfig.querySelectorAll('.tab-config__tab');
470
+ this._tabSelected = newIndex;
471
+ tabConfigs.forEach((tabConfig, index) => {
472
+ var _a;
473
+ if (index) {
474
+ const label = (_a = tabConfig.querySelector('.tab-config__tab-label')) === null || _a === void 0 ? void 0 : _a.getAttribute('title');
475
+ tabs.push({
476
+ label,
477
+ order: (index - 1)
478
+ });
479
+ }
480
+ });
481
+ this._layoutFormConfig.map((tabLayout) => {
482
+ tabs.forEach((tab) => {
483
+ tab.label === tabLayout.tab && (tab.visible = tabLayout.visible);
484
+ });
485
+ });
486
+ if (tabs.length > 0) {
487
+ this._formConfig.tabs = tabs;
488
+ this.loadFields(this._sortableTimer);
489
+ this.controlFieldConfig();
490
+ this._formConfigChanged = true;
491
+ }
492
+ }
493
+ loadConfigByUser() {
494
+ var _a;
495
+ if (this._application != undefined) {
496
+ const option = this._optionFormConfigSelected;
497
+ const fetchActionName = (option === null || option === void 0 ? void 0 : option.origin) === UserConfigType.DEFAULT ? "fetchDefaultConfig" :
498
+ (option === null || option === void 0 ? void 0 : option.origin) === UserConfigType.USER ? "fetchLegacyConfig" :
499
+ undefined;
500
+ if (fetchActionName != undefined) {
501
+ this._application[fetchActionName]((_a = this.parentForm) === null || _a === void 0 ? void 0 : _a.configName)
502
+ .then((formConfig) => {
503
+ if (formConfig != undefined) {
504
+ this._formConfig = formConfig;
505
+ this._tabSelected = 1;
506
+ this.loadFields(this._sortableTimer);
507
+ this.controlFieldConfig();
508
+ this.clearTempGroups();
509
+ }
510
+ });
511
+ }
512
+ }
513
+ }
514
+ loadConfig(updateTimer = 0) {
515
+ this.loadFormConfig(updateTimer);
516
+ this.loadUserConfig();
517
+ }
518
+ addNewGroup() {
519
+ var _a, _b;
520
+ const tab = (_a = this._tabConfig) === null || _a === void 0 ? void 0 : _a.selectedTab;
521
+ const hasGroup = (_b = this._tempGroups) === null || _b === void 0 ? void 0 : _b.find((tempGroup) => {
522
+ return tempGroup.tab === tab && tempGroup.group.includes(this._labelNewGroup);
523
+ });
524
+ if (hasGroup == undefined) {
525
+ this._tempGroups.push({
526
+ tab,
527
+ group: this.handleDuplicateGroups(this._labelNewGroup, this._tabConfig.selectedTab)
528
+ });
529
+ this.loadFields();
530
+ this.controlFieldConfig();
531
+ this._formConfigChanged = true;
532
+ }
533
+ }
534
+ clearTempGroups(clearInTab = false) {
535
+ var _a;
536
+ if (((_a = this._tempGroups) === null || _a === void 0 ? void 0 : _a.length) > 0) {
537
+ if (clearInTab) {
538
+ this._tempGroups = this._tempGroups.filter((tempGroup) => {
539
+ return tempGroup.tab !== this._tabConfig.selectedTab;
540
+ });
541
+ }
542
+ else {
543
+ this._tempGroups = [];
544
+ }
545
+ }
546
+ }
547
+ removeGroup(indexTempGroup = undefined) {
548
+ if (indexTempGroup != undefined) {
549
+ this._tempGroups = this._tempGroups.filter((tempGroup, index) => {
550
+ return (index !== indexTempGroup
551
+ && tempGroup.tab === this._tabConfig.selectedTab)
552
+ || tempGroup.tab !== this._tabConfig.selectedTab;
553
+ });
554
+ }
555
+ else {
556
+ this.updateFieldsToSave(this._sortableTimer);
557
+ }
558
+ }
559
+ checkGroupExists(newLabel, indexGroup, isTempGroup = false) {
560
+ var _a, _b, _c;
561
+ const tabName = (_a = this._tabConfig) === null || _a === void 0 ? void 0 : _a.selectedTab;
562
+ const currentTab = (_b = this._layoutFormConfig) === null || _b === void 0 ? void 0 : _b.find(tab => tab.tab === tabName);
563
+ const tabGroupsNames = (_c = currentTab === null || currentTab === void 0 ? void 0 : currentTab.groups) === null || _c === void 0 ? void 0 : _c.map(tab => { var _a; return (_a = tab.group) === null || _a === void 0 ? void 0 : _a.toLowerCase(); });
564
+ if (tabGroupsNames === null || tabGroupsNames === void 0 ? void 0 : tabGroupsNames.includes(newLabel === null || newLabel === void 0 ? void 0 : newLabel.toLowerCase())) {
565
+ const title = this.getMessage("snkFormConfig.confirm.title");
566
+ const message = `
567
+ ${this.getMessage("snkFormConfig.alert.titleGroupExists")}
568
+ <b>${newLabel}</b>
569
+ ${this.getMessage("snkFormConfig.alert.inTab")}
570
+ <b>${tabName === TAB_NAMES.main ? this.getMessage("snkFormConfig.form.mainArea") : tabName}</b>.
571
+ <br/><br/>
572
+ ${this.getMessage("snkFormConfig.alert.infoValidTitle")}
573
+ `;
574
+ ApplicationUtils.alert(title, message)
575
+ .then(() => {
576
+ var _a, _b;
577
+ if (isTempGroup) {
578
+ (_a = this._newGroupBoxes[indexGroup]) === null || _a === void 0 ? void 0 : _a.applyFocusTextEdit();
579
+ }
580
+ else {
581
+ (_b = this._currentGroupBoxes[tabName][indexGroup]) === null || _b === void 0 ? void 0 : _b.applyFocusTextEdit();
582
+ }
583
+ });
584
+ return false;
585
+ }
586
+ return true;
587
+ }
588
+ saveEditLabelTempGroup(editDetails, index) {
589
+ const { newValue: newLabel } = editDetails.detail;
590
+ if (this._newGroupBoxes != undefined && this._newGroupBoxes[index] != undefined) {
591
+ this._newGroupBoxes[index].dataset.groupName = newLabel;
592
+ }
593
+ }
594
+ saveEditLabelGroup(editDetails) {
595
+ var _a;
596
+ const { value: oldLabel, newValue: newLabel } = editDetails.detail;
597
+ (_a = this._formConfig.fields) === null || _a === void 0 ? void 0 : _a.forEach((field) => {
598
+ if (field.group === oldLabel) {
599
+ field.group = newLabel;
600
+ }
601
+ });
602
+ this.loadFields(this._sortableTimer);
603
+ this.controlFieldConfig();
604
+ this._formConfigChanged = true;
605
+ }
606
+ renderTempGroupByTab(tabName) {
607
+ return this._tempGroups.map((tempGroup, indexGroup) => {
608
+ if (tempGroup.tab === tabName) {
609
+ return h("ez-collapsible-box", { ref: ref => this._newGroupBoxes[indexGroup] = ref, id: `${CONTAINER_ID.addNewGroup}-${indexGroup}`, editable: true, removable: true, "header-size": "large", label: tempGroup.group, "icon-placement": "left", "data-group-name": tempGroup.group, "data-draggable-parent": "field", class: "form-config__add-group", onEzRemove: () => this.removeGroup(indexGroup), onEzSaveEditLabel: (evt) => this.saveEditLabelTempGroup(evt, indexGroup), onEzEditLabelMode: (evt) => this._editingTitleGroup = evt.detail, conditionalSave: (newLabel) => this.checkGroupExists(newLabel, indexGroup, true) }, this.getFieldsByGroup(tempGroup));
610
+ }
611
+ });
612
+ }
613
+ handleDuplicateGroups(titleNewGroup, currentTab) {
614
+ var _a;
615
+ const selectedTabGroups = this._layoutFormConfig[this._tabConfig.selectedIndex].groups.map(tab => tab.group);
616
+ if (selectedTabGroups != undefined) {
617
+ (_a = this._layoutFormConfig) === null || _a === void 0 ? void 0 : _a.map(tab => {
618
+ if (tab.tab === currentTab) {
619
+ if (tab.groups.some(groups => groups.group === titleNewGroup)) {
620
+ titleNewGroup += `${this.captureHighestValueTitle(selectedTabGroups)}`;
621
+ }
622
+ }
623
+ });
624
+ }
625
+ return titleNewGroup;
626
+ }
627
+ captureHighestValueTitle(groupsTemp) {
628
+ let valuesNumericTitle = [];
629
+ groupsTemp === null || groupsTemp === void 0 ? void 0 : groupsTemp.map(group => {
630
+ if (group != undefined) {
631
+ valuesNumericTitle.push(group.replace(/[^0-9]/g, ''));
632
+ }
633
+ });
634
+ if (Math.max.apply(null, valuesNumericTitle) > 0) {
635
+ return ` (${Math.max.apply(null, valuesNumericTitle) + 1})`;
636
+ }
637
+ else {
638
+ return ' (1)';
639
+ }
640
+ }
641
+ getLayoutFormConfig() {
642
+ var _a, _b;
643
+ if (((_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.fields) == undefined) {
644
+ return;
645
+ }
646
+ let layoutFormConfig = [];
647
+ let fields = [];
648
+ for (const field of this._formConfig.fields) {
649
+ const hasField = fields.find((fieldTemp) => {
650
+ return field.name === fieldTemp.name && field.tab === fieldTemp.tab;
651
+ });
652
+ if (hasField == undefined) {
653
+ fields.push(field);
654
+ const fieldMD = this.dataUnit.getField(field.name);
655
+ if (fieldMD === null || fieldMD === void 0 ? void 0 : fieldMD.visible) {
656
+ if (field.label == undefined || field.label === "") {
657
+ field.label = fieldMD.label;
658
+ }
659
+ let tab = layoutFormConfig.find(value => value.tab === field.tab);
660
+ if (tab == undefined) {
661
+ let visible = null;
662
+ if (this._formConfig.tabs != undefined) {
663
+ const configTabs = this._formConfig.tabs.filter(configTab => configTab.label === field.tab);
664
+ if (configTabs.length > 0) {
665
+ visible = configTabs[0].visible;
666
+ }
667
+ }
668
+ const tabLabel = ((_b = field.tab) === null || _b === void 0 ? void 0 : _b.label) || field.tab;
669
+ if (visible !== null) {
670
+ tab = { tab: tabLabel, groups: [], visible };
671
+ }
672
+ else {
673
+ tab = { tab: tabLabel, groups: [], visible: true };
674
+ }
675
+ layoutFormConfig.push(tab);
676
+ }
677
+ const group = tab.groups.find(value => value.group === field.group);
678
+ if (group) {
679
+ group.fields.push(field);
680
+ }
681
+ else {
682
+ const newGroup = { group: field.group, fields: [field] };
683
+ if (field.group === undefined) {
684
+ tab.groups.unshift(newGroup);
685
+ }
686
+ else {
687
+ tab.groups.push(newGroup);
688
+ }
689
+ }
690
+ }
691
+ }
692
+ }
693
+ return layoutFormConfig;
694
+ }
695
+ configureTabs(layoutFormConfig) {
696
+ var _a;
697
+ if (((_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.tabs) == undefined) {
698
+ return layoutFormConfig;
699
+ }
700
+ if (layoutFormConfig == undefined) {
701
+ layoutFormConfig = [];
702
+ }
703
+ return this._formConfig.tabs.map((tab) => {
704
+ return layoutFormConfig.find(config => { var _a, _b; return ((_a = tab.label) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = config.tab) === null || _b === void 0 ? void 0 : _b.toLowerCase()); })
705
+ || { tab: tab.label, groups: [], visible: tab.visible };
706
+ }).filter((layoutConfig) => {
707
+ return (layoutConfig === null || layoutConfig === void 0 ? void 0 : layoutConfig.tab) != undefined;
708
+ });
709
+ }
710
+ configureTabMain(layoutFormConfig) {
711
+ if (layoutFormConfig == undefined) {
712
+ layoutFormConfig = [];
713
+ }
714
+ const hasTabMain = layoutFormConfig.find((layoutTab) => {
715
+ return layoutTab.tab === TAB_NAMES.main;
716
+ });
717
+ if (hasTabMain == undefined) {
718
+ layoutFormConfig.unshift({ tab: TAB_NAMES.main, groups: [], visible: true });
719
+ }
720
+ return layoutFormConfig;
721
+ }
722
+ updateTabs() {
723
+ const tabs = this.getTabsToSave();
724
+ if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) > 0) {
725
+ this._formConfig.tabs = tabs;
726
+ }
727
+ }
728
+ buildFormConfig() {
729
+ var _a;
730
+ if (((_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.fields) == undefined) {
731
+ return;
732
+ }
733
+ let layoutFormConfig = this.getLayoutFormConfig();
734
+ layoutFormConfig = this.configureTabs(layoutFormConfig);
735
+ layoutFormConfig = this.configureTabMain(layoutFormConfig);
736
+ this._layoutFormConfig = layoutFormConfig;
737
+ this.updateTabs();
738
+ }
739
+ buildAvailableFields() {
740
+ var _a, _b;
741
+ if (((_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.fields) == undefined) {
742
+ return;
743
+ }
744
+ let fieldsFormConfig = [];
745
+ let fieldsMetadata = this.dataUnit.metadata.fields;
746
+ for (const field of this._formConfig.fields) {
747
+ fieldsFormConfig.push(field);
748
+ }
749
+ const listFieldsAvailable = fieldsMetadata.filter(({ name: _nameFieldMetadado, visible: _visibleMetadado }) => _visibleMetadado === true
750
+ && fieldsFormConfig.some(({ name: _nameFieldForm }) => _nameFieldForm === _nameFieldMetadado) === false);
751
+ this._fieldsAvailable = listFieldsAvailable;
752
+ this._listEnabledFields = listFieldsAvailable;
753
+ if (((_b = this._filterFieldsAvailable) === null || _b === void 0 ? void 0 : _b.value) != undefined) {
754
+ const filterValue = this._filterFieldsAvailable.value;
755
+ this.onFilterChange(filterValue);
756
+ }
757
+ }
758
+ setShowFormConfig(value) {
759
+ this.parentForm.setShowFormConfig(value);
760
+ }
761
+ changeTabSelected(tabSelected) {
762
+ this._tabSelected = tabSelected.index;
763
+ const selectorTab = this._formContainer.querySelector("div#tab" + tabSelected.index);
764
+ this._formContainer.querySelectorAll(".form-config__tab-content").forEach(container => container.className = "form-config__hide-content sc-snk-form-config");
765
+ if (selectorTab) {
766
+ selectorTab.className = "form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium sc-snk-form-config";
767
+ }
768
+ }
769
+ onFilterChange(value) {
770
+ this._fieldsAvailable = ArrayUtils.applyStringFilter(value, this._listEnabledFields, true, "label");
771
+ }
772
+ orderFieldsAvailable(fields) {
773
+ return ArrayUtils.sortAlphabetically(fields);
774
+ }
775
+ handleLabelCounter(sizeList) {
776
+ const labels = [this.getMessage("snkFormConfig.availableFields.labelNoFields"), this.getMessage("snkFormConfig.availableFields.labelOneField")];
777
+ return sizeList > 1 ? `${sizeList} ${this.getMessage("snkFormConfig.availableFields.labelAvailableFields")}` : labels[sizeList];
778
+ }
779
+ controlAddFieldConfig(fieldConfig) {
780
+ var _a;
781
+ this._formConfigChanged = false;
782
+ if (fieldConfig == undefined) {
783
+ return;
784
+ }
785
+ if (this._formConfig.fields == undefined) {
786
+ this._formConfig.fields = [];
787
+ }
788
+ const fieldFinded = this._formConfig.fields.filter((field) => {
789
+ return field.name === fieldConfig.name && field.tab && fieldConfig.tab;
790
+ });
791
+ if (fieldFinded.length > 0) {
792
+ fieldFinded.forEach((field) => {
793
+ field.name = fieldConfig.name;
794
+ field.label = fieldConfig.label;
795
+ field.required = fieldConfig.required;
796
+ field.readOnly = fieldConfig.readOnly;
797
+ field.group = fieldConfig.group;
798
+ });
799
+ }
800
+ else {
801
+ this._formConfig.fields.push({
802
+ name: fieldConfig.name,
803
+ label: fieldConfig.label,
804
+ required: fieldConfig.required,
805
+ readOnly: fieldConfig.readOnly,
806
+ group: fieldConfig.group,
807
+ tab: (_a = this._tabConfig) === null || _a === void 0 ? void 0 : _a.selectedTab
808
+ });
809
+ }
810
+ this.loadFields();
811
+ this.controlFieldConfig();
812
+ this._formConfigChanged = true;
813
+ this.resetSortables();
814
+ }
815
+ controlRemoveFieldConfig(fieldConfig, updateTimer) {
816
+ var _a;
817
+ this._formConfigChanged = false;
818
+ if (fieldConfig == undefined) {
819
+ return;
820
+ }
821
+ this._formConfig.fields = (_a = this._formConfig.fields) === null || _a === void 0 ? void 0 : _a.filter((field) => field.name !== fieldConfig.name);
822
+ this.loadFields(updateTimer);
823
+ this.controlFieldConfig();
824
+ this._formConfigChanged = true;
825
+ this.resetSortables();
826
+ }
827
+ resetSortables() {
828
+ this.controlSortableField();
829
+ this.controlSortableGroup();
830
+ }
831
+ handleFieldConfigChange(evt, updateTimer = 0) {
832
+ const { field: fieldConfig, type: actionType } = evt.detail;
833
+ if (actionType === ACTION_CONFIG.configuration) {
834
+ this.controlFieldConfig(fieldConfig);
835
+ return;
836
+ }
837
+ if (actionType === ACTION_CONFIG.remove) {
838
+ this.controlRemoveFieldConfig(fieldConfig, updateTimer);
839
+ return;
840
+ }
841
+ if (actionType === ACTION_CONFIG.add) {
842
+ this.controlAddFieldConfig(fieldConfig);
843
+ return;
844
+ }
845
+ }
846
+ changeTabLabel(editDetails) {
847
+ var _a, _b;
848
+ const { value: oldLabel, newValue: newLabel } = editDetails.detail.detail;
849
+ (_a = this._formConfig.fields) === null || _a === void 0 ? void 0 : _a.forEach((field) => {
850
+ if (field.tab === oldLabel) {
851
+ field.tab = newLabel;
852
+ }
853
+ });
854
+ (_b = this._formConfig.tabs) === null || _b === void 0 ? void 0 : _b.forEach((tab) => {
855
+ if (tab.label === oldLabel) {
856
+ tab.label = newLabel;
857
+ }
858
+ });
859
+ this.loadFields(this._sortableTimer);
860
+ this.controlFieldConfig();
861
+ this._formConfigChanged = true;
862
+ }
863
+ handleDeleteTab(tabSelected) {
864
+ let options = {
865
+ canClose: false,
866
+ labelCancel: this.getMessage("snkFormConfig.confirm.labelNo"),
867
+ labelConfirm: this.getMessage("snkFormConfig.confirm.labelYes"),
868
+ btnConfirmDanger: false
869
+ };
870
+ const title = this.getMessage("snkFormConfig.confirm.title");
871
+ const deleteTab = this.getMessage("snkFormConfig.confirm.deleteTab");
872
+ ApplicationUtils.confirm(title, `${deleteTab} <b>${tabSelected.detail.label}</b>?`, "delete", DialogType.WARN, options)
873
+ .then(response => {
874
+ var _a;
875
+ if (response) {
876
+ this._formConfig.tabs = (_a = this._formConfig.tabs) === null || _a === void 0 ? void 0 : _a.filter((tab) => {
877
+ return tab.label !== tabSelected.detail.label;
878
+ });
879
+ this.loadFields(this._sortableTimer);
880
+ this.controlFieldConfig();
881
+ this._formConfigChanged = true;
882
+ }
883
+ });
884
+ }
885
+ changeHideTab(tabSelected) {
886
+ var _a;
887
+ (_a = this._formConfig.tabs) === null || _a === void 0 ? void 0 : _a.forEach((tab) => {
888
+ if (tab.label === tabSelected.detail.label) {
889
+ tab.visible = !tab.visible;
890
+ }
891
+ });
892
+ this.loadFields(this._sortableTimer);
893
+ this.controlFieldConfig();
894
+ this._formConfigChanged = true;
895
+ }
896
+ handleCanStartDragTab() {
897
+ var _a, _b;
898
+ const tabs = this._layoutFormConfig.map(tab => tab.tab);
899
+ for (const tab of tabs) {
900
+ (_a = this._currentGroupBoxes[tab]) === null || _a === void 0 ? void 0 : _a.map(collapsibleBox => collapsibleBox === null || collapsibleBox === void 0 ? void 0 : collapsibleBox.cancelEdition());
901
+ }
902
+ (_b = this._newGroupBoxes) === null || _b === void 0 ? void 0 : _b.map(collapsibleBox => collapsibleBox === null || collapsibleBox === void 0 ? void 0 : collapsibleBox.cancelEdition());
903
+ }
904
+ /**
905
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
906
+ * através de um pequeno modulo na estrutura da aplicação:
907
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
908
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-form.msg.ts"
909
+ */
910
+ getMessage(key, params) {
911
+ return this._application.messagesBuilder.getMessage(key, params);
912
+ }
913
+ componentDidRender() {
914
+ this.controlSortableField();
915
+ this.controlSortableGroup();
916
+ }
917
+ componentWillLoad() {
918
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
919
+ this.loadConfig();
920
+ }
921
+ render() {
922
+ var _a, _b, _c, _d;
923
+ const configOptions = this._formConfigOptions.map((option) => {
924
+ return { value: option.origin, label: option.name };
925
+ });
926
+ return (h(Host, null, h("div", { class: "ez-row ez-padding--medium" }, h("div", { class: "ez-col ez-col--sd-7 ez-col--tb-9 ez-align--middle" }, h("ez-button", { mode: "icon", iconName: "arrow_back", class: "ez-padding--small", size: "small", onClick: () => this.closeFormConfig() }), h("h1", { class: "ez-title ez-title--extra-large ez-padding--small" }, this.getMessage("snkFormConfig.title")), h("ez-actions-button", { class: "form-config__actions-button ez-margin-left--medium", value: (_a = this._optionFormConfigSelected) === null || _a === void 0 ? void 0 : _a.origin, showLabel: true, iconName: "chevron-down", checkOption: true, size: "small", actions: configOptions, onEzAction: (evt) => this.controlSelectFormConfig(evt) })), h("div", { class: "ez-col ez-col--sd-5 ez-col--tb-3 ez-align--middle ez-align--right" }, this._formConfigChanged === true && this._optionFormConfigChanged === false &&
927
+ h("div", { class: "ez-row ez-align--middle ez-align--right" }, h("ez-button", { label: "Cancelar", class: "ez-padding-left--medium", size: "small", onClick: () => this.cancelChangeConfig() }), h("ez-button", { label: "Salvar", class: "ez-button--primary ez-padding-left--medium", size: "small", onClick: () => this.saveConfig() }, h("ez-icon", { class: "ez-margin-right--small", slot: "leftIcon", iconName: "save" }))), this._optionFormConfigChanged === true &&
928
+ h("div", { class: "ez-row ez-align--middle ez-align--right" }, h("ez-button", { label: "Cancelar", class: "ez-padding-left--medium", size: "small", onClick: () => this.cancelChangeOptionConfig() }), h("ez-button", { label: this.getMessage("snkFormConfig.applyConfig"), class: "ez-button--primary ez-padding-left--medium", size: "small", onClick: () => this.applyOptionConfig() })))), h("div", { class: "ez-row ez-padding--medium", ref: ref => this._sortableContainer = ref }, h("div", { class: "form-config__tab-container ez-col ez-col--sd-9 ez-col--tb-9 ez-padding-right--medium" }, ((_b = this._layoutFormConfig) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
929
+ h("section", { class: "ez-box__container", ref: ref => this._formContainer = ref }, h("snk-tab-config", { ref: ref => this._tabConfig = ref, selectedIndex: this._tabSelected, onEzTabChange: (ev) => this.changeTabSelected(ev.detail), onEzOrderChange: (ev) => this.changeTabOrder(ev.detail), onEditionTitleTab: (ev) => this.changeTabLabel(ev), onDeleteTab: (ev) => this.handleDeleteTab(ev), onHideTab: (ev) => this.changeHideTab(ev), onCanStartDrag: () => this.handleCanStartDragTab() }, this._layoutFormConfig.map((tab) => h("snk-tab", { tabKey: tab.tab || "Geral", label: tab.tab || this.getMessage("snkFormConfig.form.tabGeneral"), visible: tab.visible }))), this._layoutFormConfig.map((tab, indexTab) => h("div", { id: "tab" + indexTab, "data-draggable-parent": "group", class: this._tabSelected === indexTab
930
+ ? "form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium"
931
+ : "form-config__hide-content" }, tab.groups.map((group, indexGroup) => {
932
+ if (group.group) {
933
+ if (this._currentGroupBoxes[tab.tab] == undefined) {
934
+ this._currentGroupBoxes[tab.tab] = [];
935
+ }
936
+ return h("ez-collapsible-box", { ref: ref => this._currentGroupBoxes[tab.tab][indexGroup] = ref, editable: true, removable: true, "header-size": "large", label: group.group, "icon-placement": "left", "data-group-name": group.group, "data-draggable-parent": "field", "data-draggable-element": "group", onEzRemove: () => this.removeGroup(), onEzSaveEditLabel: (evt) => this.saveEditLabelGroup(evt), onEzEditLabelMode: (evt) => this._editingTitleGroup = evt.detail, conditionalSave: (newLabel) => this.checkGroupExists(newLabel, indexGroup) }, this.getFieldsByGroup(group));
937
+ }
938
+ else {
939
+ return h("div", { class: "ez-flex ez-flex--column ez-size-width--full" }, h("label", { class: "ez-text ez-text--secondary ez-margin-vertical--small" }, this.getMessage("snkFormConfig.form.subTitleInfo")), h("div", { id: CONTAINER_ID.withoutGroup, class: "ez-row", "data-draggable-parent": "field" }, this.getFieldsByGroup(group)), h("hr", { class: "ez-divider-horizontal ez-margin-vertical--medium" }));
940
+ }
941
+ }), this.renderTempGroupByTab(tab.tab))), h("div", { class: "form-config__btn-add-group ez-row" }, h("div", { class: "form-config__btn-add-group-container ez-col ez-col--sd-12 ez-col--tb-12 ez-align--center" }, h("ez-button", { label: this.getMessage("snkFormConfig.form.labelNewGroup"), class: "ez-padding-horizontal--small ez-button--primary", size: "small", onClick: () => this.addNewGroup() }, h("ez-icon", { class: "ez-margin-right--small", slot: "leftIcon", iconName: "plus" })))))), h("div", { class: "form-config__fields-available ez-col ez-col--sd-3 ez-col--tb-3" }, h("section", { class: "ez-box__container ez-col ez-col--pn-12" }, h("h1", { class: "ez-title ez-title--large ez-title--primary ez-padding-bottom--medium" }, this.getMessage("snkFormConfig.availableFields.title")), h("ez-filter-input", { ref: ref => this._filterFieldsAvailable = ref, label: this.getMessage("snkFormConfig.availableFields.labelSearchField"), onEzChange: evt => this.onFilterChange(evt.detail) }), h("span", { class: "ez-box__label-counter ez-text ez-text--medium ez-text--primary ez-margin-bottom--medium" }, this.handleLabelCounter((_c = this._fieldsAvailable) === null || _c === void 0 ? void 0 : _c.length)), ((_d = this._layoutFormConfig) === null || _d === void 0 ? void 0 : _d.length) > 0 &&
942
+ h("div", { id: CONTAINER_ID.fieldsAvailable, class: "ez-row", "data-draggable-parent": "field" }, this.orderFieldsAvailable(this._fieldsAvailable).map((field) => h("div", { key: field.name, class: this._fieldsAvailableStyle, "data-draggable-element": "field", onMouseDown: (evt) => this.controlMoveField(evt) }, h("snk-field-config", { onEzClickIcon: (evt) => { this.handleFieldConfigChange(evt); }, fieldConfig: field })))))))));
943
+ }
944
+ static get is() { return "snk-form-config"; }
945
+ static get encapsulation() { return "scoped"; }
946
+ static get originalStyleUrls() {
947
+ return {
948
+ "$": ["snk-form-config.css"]
949
+ };
950
+ }
951
+ static get styleUrls() {
952
+ return {
953
+ "$": ["snk-form-config.css"]
954
+ };
955
+ }
956
+ static get properties() {
957
+ return {
958
+ "dataUnit": {
959
+ "type": "unknown",
960
+ "mutable": false,
961
+ "complexType": {
962
+ "original": "DataUnit",
963
+ "resolved": "DataUnit",
964
+ "references": {
965
+ "DataUnit": {
966
+ "location": "import",
967
+ "path": "@sankhyalabs/core"
968
+ }
969
+ }
970
+ },
971
+ "required": false,
972
+ "optional": false,
973
+ "docs": {
974
+ "tags": [],
975
+ "text": "Reposit\u00F3rio de dados, controla a manipula\u00E7\u00E3o dos dados"
976
+ }
977
+ },
978
+ "formConfig": {
979
+ "type": "unknown",
980
+ "mutable": false,
981
+ "complexType": {
982
+ "original": "IFormConfig",
983
+ "resolved": "IFormConfig",
984
+ "references": {
985
+ "IFormConfig": {
986
+ "location": "import",
987
+ "path": "@sankhyalabs/ezui/dist/types/components/ez-form/ez-form"
988
+ }
989
+ }
990
+ },
991
+ "required": false,
992
+ "optional": false,
993
+ "docs": {
994
+ "tags": [],
995
+ "text": "Campos de configura\u00E7\u00E3o de formul\u00E1rio."
996
+ },
997
+ "defaultValue": "{} as IFormConfig"
998
+ },
999
+ "parentForm": {
1000
+ "type": "unknown",
1001
+ "mutable": false,
1002
+ "complexType": {
1003
+ "original": "HTMLSnkFormElement",
1004
+ "resolved": "HTMLSnkFormElement",
1005
+ "references": {
1006
+ "HTMLSnkFormElement": {
1007
+ "location": "global"
1008
+ }
1009
+ }
1010
+ },
1011
+ "required": false,
1012
+ "optional": false,
1013
+ "docs": {
1014
+ "tags": [],
1015
+ "text": "Representa o elemento pai do componente."
1016
+ }
1017
+ }
1018
+ };
1019
+ }
1020
+ static get states() {
1021
+ return {
1022
+ "_formConfigOptions": {},
1023
+ "_fieldConfigSelected": {},
1024
+ "_layoutFormConfig": {},
1025
+ "_fieldsAvailable": {},
1026
+ "_formConfig": {},
1027
+ "_formConfigChanged": {},
1028
+ "_optionFormConfigSelected": {},
1029
+ "_optionFormConfigChanged": {},
1030
+ "_tempGroups": {}
1031
+ };
1032
+ }
1033
+ static get events() {
1034
+ return [{
1035
+ "method": "configChange",
1036
+ "name": "configChange",
1037
+ "bubbles": true,
1038
+ "cancelable": true,
1039
+ "composed": true,
1040
+ "docs": {
1041
+ "tags": [],
1042
+ "text": "Evento disparado ao salvar as configura\u00E7\u00F5es."
1043
+ },
1044
+ "complexType": {
1045
+ "original": "IFormConfig",
1046
+ "resolved": "IFormConfig",
1047
+ "references": {
1048
+ "IFormConfig": {
1049
+ "location": "import",
1050
+ "path": "@sankhyalabs/ezui/dist/types/components/ez-form/ez-form"
1051
+ }
1052
+ }
1053
+ }
1054
+ }];
1055
+ }
1056
+ static get watchers() {
1057
+ return [{
1058
+ "propName": "formConfig",
1059
+ "methodName": "observeFormConfig"
1060
+ }];
1061
+ }
1062
+ }