@sankhyalabs/ezui 1.1.6 → 1.1.10

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 (149) hide show
  1. package/README.md +72 -72
  2. package/dist/cjs/{DataUnit-09a6e7be.js → DataUnit-95368a67.js} +418 -361
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1933 -1847
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +102 -95
  7. package/dist/cjs/ez-number-input.cjs.entry.js +236 -236
  8. package/dist/cjs/ez-time-input.cjs.entry.js +168 -168
  9. package/dist/cjs/ezui.cjs.js +1 -1
  10. package/dist/cjs/form-metadata.cjs.entry.js +65 -65
  11. package/dist/cjs/loader.cjs.js +1 -1
  12. package/dist/collection/components/ez-action-chip/ez-action-chip.css +82 -82
  13. package/dist/collection/components/ez-action-chip/ez-action-chip.js +109 -109
  14. package/dist/collection/components/ez-button/ez-button.css +94 -94
  15. package/dist/collection/components/ez-button/ez-button.js +125 -125
  16. package/dist/collection/components/ez-calendar/ez-calendar.css +210 -210
  17. package/dist/collection/components/ez-calendar/ez-calendar.js +215 -215
  18. package/dist/collection/components/ez-check/ez-check.css +265 -265
  19. package/dist/collection/components/ez-check/ez-check.js +168 -168
  20. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.css +67 -67
  21. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.js +108 -108
  22. package/dist/collection/components/ez-combo-box/ez-combo-box-interfaces.js +2 -2
  23. package/dist/collection/components/ez-combo-box/ez-combo-box.css +167 -167
  24. package/dist/collection/components/ez-combo-box/ez-combo-box.js +363 -363
  25. package/dist/collection/components/ez-date-input/ez-date-input.css +38 -38
  26. package/dist/collection/components/ez-date-input/ez-date-input.js +172 -172
  27. package/dist/collection/components/ez-form/ez-form.css +19 -19
  28. package/dist/collection/components/ez-form/ez-form.js +390 -289
  29. package/dist/collection/components/ez-form/store/Form.actions.js +132 -123
  30. package/dist/collection/components/ez-form/store/Form.reducer.js +194 -174
  31. package/dist/collection/components/ez-form/store/Form.selectors.js +44 -43
  32. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +252 -207
  33. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +16 -16
  34. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +23 -23
  35. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +173 -173
  36. package/dist/collection/components/ez-form/subcomponents/place-holder.js +14 -14
  37. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +71 -71
  38. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +27 -27
  39. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +40 -33
  40. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +27 -18
  41. package/dist/collection/components/ez-icon/ez-icon.css +36 -36
  42. package/dist/collection/components/ez-icon/ez-icon.js +56 -56
  43. package/dist/collection/components/ez-label-chip/ez-label-chip.css +117 -117
  44. package/dist/collection/components/ez-label-chip/ez-label-chip.js +276 -276
  45. package/dist/collection/components/ez-modal/ez-modal.css +86 -86
  46. package/dist/collection/components/ez-modal/ez-modal.js +222 -200
  47. package/dist/collection/components/ez-number-input/ez-number-input.css +144 -144
  48. package/dist/collection/components/ez-number-input/ez-number-input.js +465 -465
  49. package/dist/collection/components/ez-popover/ez-popover.css +38 -38
  50. package/dist/collection/components/ez-popover/ez-popover.js +323 -323
  51. package/dist/collection/components/ez-search/ez-search.css +295 -295
  52. package/dist/collection/components/ez-search/ez-search.js +527 -527
  53. package/dist/collection/components/ez-tabselector/ez-tabselector.css +125 -125
  54. package/dist/collection/components/ez-tabselector/ez-tabselector.js +283 -283
  55. package/dist/collection/components/ez-text-area/ez-text-area.css +139 -139
  56. package/dist/collection/components/ez-text-area/ez-text-area.js +267 -267
  57. package/dist/collection/components/ez-text-input/ez-text-input.css +169 -169
  58. package/dist/collection/components/ez-text-input/ez-text-input.js +395 -395
  59. package/dist/collection/components/ez-time-input/ez-time-input.css +155 -155
  60. package/dist/collection/components/ez-time-input/ez-time-input.js +326 -326
  61. package/dist/collection/index.js +1 -1
  62. package/dist/collection/servidor.js +100 -100
  63. package/dist/collection/utils/FloatingManager.js +15 -15
  64. package/dist/collection/utils/utils.js +6 -6
  65. package/dist/custom-elements/index.js +3146 -2998
  66. package/dist/esm/{DataUnit-7a983910.js → DataUnit-4bb6a396.js} +417 -362
  67. package/dist/esm/ez-action-chip.entry.js +41 -41
  68. package/dist/esm/ez-button_14.entry.js +1933 -1847
  69. package/dist/esm/ez-label-chip.entry.js +120 -120
  70. package/dist/esm/ez-modal.entry.js +103 -96
  71. package/dist/esm/ez-number-input.entry.js +236 -236
  72. package/dist/esm/ez-time-input.entry.js +168 -168
  73. package/dist/esm/ezui.js +1 -1
  74. package/dist/esm/form-metadata.entry.js +65 -65
  75. package/dist/esm/loader.js +1 -1
  76. package/dist/esm/polyfills/core-js.js +0 -0
  77. package/dist/esm/polyfills/dom.js +0 -0
  78. package/dist/esm/polyfills/es5-html-element.js +0 -0
  79. package/dist/esm/polyfills/index.js +0 -0
  80. package/dist/esm/polyfills/system.js +0 -0
  81. package/dist/ezui/ezui.esm.js +1 -1
  82. package/dist/ezui/p-11d20338.js +1 -0
  83. package/dist/ezui/{p-3c3a43aa.entry.js → p-5d30e51c.entry.js} +1 -1
  84. package/dist/ezui/p-77fdb4fd.entry.js +1 -0
  85. package/dist/ezui/p-e056fb23.entry.js +1 -0
  86. package/dist/types/components/ez-action-chip/ez-action-chip.d.ts +16 -16
  87. package/dist/types/components/ez-button/ez-button.d.ts +20 -20
  88. package/dist/types/components/ez-calendar/ez-calendar.d.ts +42 -42
  89. package/dist/types/components/ez-check/ez-check.d.ts +32 -32
  90. package/dist/types/components/ez-collapsable-box/ez-collapsable-box.d.ts +18 -18
  91. package/dist/types/components/ez-combo-box/ez-combo-box-interfaces.d.ts +4 -4
  92. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +68 -68
  93. package/dist/types/components/ez-date-input/ez-date-input.d.ts +31 -31
  94. package/dist/types/components/ez-form/ez-form.d.ts +27 -27
  95. package/dist/types/components/ez-form/store/Form.actions.d.ts +111 -104
  96. package/dist/types/components/ez-form/store/Form.reducer.d.ts +20 -11
  97. package/dist/types/components/ez-form/store/Form.selectors.d.ts +14 -13
  98. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +61 -48
  99. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +41 -41
  100. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +15 -15
  101. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +3 -3
  102. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +10 -10
  103. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +12 -12
  104. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +13 -13
  105. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +17 -7
  106. package/dist/types/components/ez-icon/ez-icon.d.ts +5 -5
  107. package/dist/types/components/ez-label-chip/ez-label-chip.d.ts +40 -40
  108. package/dist/types/components/ez-modal/ez-modal.d.ts +32 -26
  109. package/dist/types/components/ez-number-input/ez-number-input.d.ts +73 -73
  110. package/dist/types/components/ez-popover/ez-popover.d.ts +52 -52
  111. package/dist/types/components/ez-search/ez-search.d.ts +95 -95
  112. package/dist/types/components/ez-tabselector/ez-tabselector.d.ts +31 -31
  113. package/dist/types/components/ez-text-area/ez-text-area.d.ts +49 -49
  114. package/dist/types/components/ez-text-input/ez-text-input.d.ts +64 -64
  115. package/dist/types/components/ez-time-input/ez-time-input.d.ts +53 -53
  116. package/dist/types/components.d.ts +8 -0
  117. package/dist/types/index.d.ts +1 -1
  118. package/dist/types/utils/utils.d.ts +2 -2
  119. package/package.json +114 -114
  120. package/react/components.d.ts +22 -0
  121. package/react/components.js +25 -0
  122. package/react/components.js.map +1 -0
  123. package/react/react-component-lib/createComponent.d.ts +10 -0
  124. package/react/react-component-lib/createComponent.js +59 -0
  125. package/react/react-component-lib/createComponent.js.map +1 -0
  126. package/react/react-component-lib/createOverlayComponent.d.ts +20 -0
  127. package/react/react-component-lib/createOverlayComponent.js +89 -0
  128. package/react/react-component-lib/createOverlayComponent.js.map +1 -0
  129. package/react/react-component-lib/index.d.ts +2 -0
  130. package/react/react-component-lib/index.js +3 -0
  131. package/react/react-component-lib/index.js.map +1 -0
  132. package/react/react-component-lib/interfaces.d.ts +29 -0
  133. package/react/react-component-lib/interfaces.js +1 -0
  134. package/react/react-component-lib/interfaces.js.map +1 -0
  135. package/react/react-component-lib/utils/attachProps.d.ts +12 -0
  136. package/react/react-component-lib/utils/attachProps.js +96 -0
  137. package/react/react-component-lib/utils/attachProps.js.map +1 -0
  138. package/react/react-component-lib/utils/case.d.ts +2 -0
  139. package/react/react-component-lib/utils/case.js +7 -0
  140. package/react/react-component-lib/utils/case.js.map +1 -0
  141. package/react/react-component-lib/utils/dev.d.ts +2 -0
  142. package/react/react-component-lib/utils/dev.js +13 -0
  143. package/react/react-component-lib/utils/dev.js.map +1 -0
  144. package/react/react-component-lib/utils/index.d.ts +7 -0
  145. package/react/react-component-lib/utils/index.js +21 -0
  146. package/react/react-component-lib/utils/index.js.map +1 -0
  147. package/dist/ezui/p-5185cbf1.entry.js +0 -1
  148. package/dist/ezui/p-5d600057.entry.js +0 -1
  149. package/dist/ezui/p-9f819174.js +0 -1
@@ -1,370 +1,425 @@
1
1
  'use strict';
2
2
 
3
- function changeFieldValue(dataUnit, recordId, fieldName, value) {
4
- return {
5
- type: 'FORM/CHANGEFIELD',
6
- payload: { dataUnit, recordId, fieldName, value }
7
- };
8
- }
9
- function changeTab(formId, index) {
10
- return {
11
- type: 'FORM/CHANGETAB',
12
- payload: { formId, index }
13
- };
14
- }
15
- function clearEdition(dataUnit, recordsLimit) {
16
- return {
17
- type: 'FORM/CLEAREDITION',
18
- payload: {
19
- dataUnit,
20
- recordsLimit
21
- }
22
- };
23
- }
24
- function collapseExpandGroup(collapseId, collapsed) {
25
- return {
26
- type: 'FORM/COLLAPSEGROUP',
27
- payload: { collapseId, collapsed }
28
- };
29
- }
30
- function previousRecord(dataUnit) {
31
- return {
32
- type: 'FORM/NAVIGATE',
33
- payload: {
34
- dataUnit,
35
- limit: 0,
36
- backward: true
37
- }
38
- };
39
- }
40
- function nextRecord(dataUnit, limit) {
41
- return {
42
- type: 'FORM/NAVIGATE',
43
- payload: {
44
- dataUnit,
45
- limit,
46
- backward: false
47
- }
48
- };
49
- }
50
- function insertRecord(dataUnit, insertionIndex) {
51
- return {
52
- type: 'FORM/INSERT',
53
- payload: {
54
- dataUnit,
55
- insertionIndex
56
- }
57
- };
58
- }
59
- function formLoad() {
60
- return {
61
- type: 'FORM/LOAD'
62
- };
63
- }
64
- function dataLoading(dataUnit) {
65
- return {
66
- type: 'FORM/DATALOADING',
67
- payload: {
68
- dataUnit
69
- }
70
- };
71
- }
72
- function savingChanges(dataUnit) {
73
- return {
74
- type: 'FORM/SAVINGCHANGES',
75
- payload: {
76
- dataUnit
77
- }
78
- };
79
- }
80
- function dataLoaded(dataUnit) {
81
- return {
82
- type: 'FORM/DATALOADED',
83
- payload: {
84
- dataUnit
85
- }
86
- };
87
- }
88
- function changesSaved(dataUnit) {
89
- return {
90
- type: 'FORM/CHANGESSAVED',
91
- payload: {
92
- dataUnit
93
- }
94
- };
95
- }
96
- function removingRecord(dataUnit) {
97
- return {
98
- type: 'FORM/REMOVINGRECORD',
99
- payload: {
100
- dataUnit
101
- }
102
- };
103
- }
104
- function recordRemoved(dataUnit) {
105
- return {
106
- type: 'FORM/RECORDREMOVED',
107
- payload: {
108
- dataUnit
109
- }
110
- };
111
- }
112
- function invalidField(tabController, tabIndex, dataUnit, recordIndex, recordId, fieldName, errorMessage) {
113
- return {
114
- type: 'FORM/INVALIDFIELD',
115
- payload: {
116
- tabController,
117
- tabIndex,
118
- dataUnit,
119
- recordId,
120
- recordIndex,
121
- fieldName,
122
- errorMessage
123
- }
124
- };
3
+ function changeFieldValue(dataUnit, recordId, fieldName, value) {
4
+ return {
5
+ type: 'FORM/CHANGEFIELD',
6
+ payload: { dataUnit, recordId, fieldName, value }
7
+ };
8
+ }
9
+ function changeTab(formId, index) {
10
+ return {
11
+ type: 'FORM/CHANGETAB',
12
+ payload: { formId, index }
13
+ };
14
+ }
15
+ function clearEdition(dataUnit, recordsLimit) {
16
+ return {
17
+ type: 'FORM/CLEAREDITION',
18
+ payload: {
19
+ dataUnit,
20
+ recordsLimit
21
+ }
22
+ };
23
+ }
24
+ function collapseExpandGroup(collapseId, collapsed) {
25
+ return {
26
+ type: 'FORM/COLLAPSEGROUP',
27
+ payload: { collapseId, collapsed }
28
+ };
29
+ }
30
+ function previousRecord(dataUnit) {
31
+ return {
32
+ type: 'FORM/NAVIGATE',
33
+ payload: {
34
+ dataUnit,
35
+ limit: 0,
36
+ backward: true
37
+ }
38
+ };
39
+ }
40
+ function nextRecord(dataUnit, limit) {
41
+ return {
42
+ type: 'FORM/NAVIGATE',
43
+ payload: {
44
+ dataUnit,
45
+ limit,
46
+ backward: false
47
+ }
48
+ };
49
+ }
50
+ function insertRecord(dataUnit, insertionIndex) {
51
+ return {
52
+ type: 'FORM/INSERT',
53
+ payload: {
54
+ dataUnit,
55
+ insertionIndex
56
+ }
57
+ };
58
+ }
59
+ function formLoad() {
60
+ return {
61
+ type: 'FORM/LOAD'
62
+ };
63
+ }
64
+ function dataLoading(dataUnit) {
65
+ return {
66
+ type: 'FORM/DATALOADING',
67
+ payload: {
68
+ dataUnit
69
+ }
70
+ };
71
+ }
72
+ function savingChanges(dataUnit) {
73
+ return {
74
+ type: 'FORM/SAVINGCHANGES',
75
+ payload: {
76
+ dataUnit
77
+ }
78
+ };
79
+ }
80
+ function dataLoaded(dataUnit) {
81
+ return {
82
+ type: 'FORM/DATALOADED',
83
+ payload: {
84
+ dataUnit
85
+ }
86
+ };
87
+ }
88
+ function changesSaved(dataUnit) {
89
+ return {
90
+ type: 'FORM/CHANGESSAVED',
91
+ payload: {
92
+ dataUnit
93
+ }
94
+ };
95
+ }
96
+ function removingRecord(dataUnit) {
97
+ return {
98
+ type: 'FORM/REMOVINGRECORD',
99
+ payload: {
100
+ dataUnit
101
+ }
102
+ };
103
+ }
104
+ function recordRemoved(dataUnit) {
105
+ return {
106
+ type: 'FORM/RECORDREMOVED',
107
+ payload: {
108
+ dataUnit
109
+ }
110
+ };
111
+ }
112
+ function invalidField(tabController, tabIndex, dataUnit, recordIndex, recordId, fieldName, errorMessage) {
113
+ return {
114
+ type: 'FORM/INVALIDFIELD',
115
+ payload: {
116
+ tabController,
117
+ tabIndex,
118
+ dataUnit,
119
+ recordId,
120
+ recordIndex,
121
+ fieldName,
122
+ errorMessage
123
+ }
124
+ };
125
+ }
126
+ function showHideNavigationButtons(buttonName, status) {
127
+ return {
128
+ type: 'FORM/SHOWHIDENAVBTN',
129
+ payload: {
130
+ buttonName,
131
+ status
132
+ }
133
+ };
125
134
  }
126
135
 
127
- //histórico
128
- const selectCurrentTab = (state, formName) => {
129
- const data = state.hist.present.currentTabIndex;
130
- return data[formName] || 0;
131
- };
132
- const selectIsCollapsedFieldSet = (state, fieldSetName) => {
133
- const data = state.hist.present.collapsedGroups;
134
- return data[fieldSetName];
135
- };
136
- const selectRecordChanges = (state, dataUnit, recordId) => {
137
- const data = selectDataUnitChanges(state, dataUnit);
138
- return data ? data[recordId] : undefined;
139
- };
140
- const selectDataUnitChanges = (state, dataUnit) => {
141
- const data = state.hist.present.changes;
142
- return data[dataUnit];
143
- };
144
- const selectCurrentRecordIndex = (state, dataUnit) => {
145
- const data = state.hist.present.currentRecordIndex;
146
- return data[dataUnit] || 0;
147
- };
148
- const selectNewRecordIndex = (state, dataUnit) => {
149
- const data = state.hist.present.newRecordIndex;
150
- return data[dataUnit] || 0;
151
- };
152
- //não histórico
153
- const selectLoadingData = (state, dataUnit) => {
154
- const data = state.nonhist.dataLoading;
155
- return data[dataUnit];
156
- };
157
- const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
158
- const data = state.nonhist.invalidFields;
159
- const dataUnitMessages = data[dataUnit] || {};
160
- const recordMessages = dataUnitMessages[recordId] || {};
161
- return recordMessages[fieldName] || "";
136
+ //histórico
137
+ const selectCurrentTab = (state, formName) => {
138
+ const data = state.hist.present.currentTabIndex;
139
+ return data[formName] || 0;
140
+ };
141
+ const selectIsCollapsedFieldSet = (state, fieldSetName) => {
142
+ const data = state.hist.present.collapsedGroups;
143
+ return data[fieldSetName];
144
+ };
145
+ const selectRecordChanges = (state, dataUnit, recordId) => {
146
+ const data = selectDataUnitChanges(state, dataUnit);
147
+ return data ? data[recordId] : undefined;
148
+ };
149
+ const selectDataUnitChanges = (state, dataUnit) => {
150
+ const data = state.hist.present.changes;
151
+ return data[dataUnit];
152
+ };
153
+ const selectCurrentRecordIndex = (state, dataUnit) => {
154
+ const data = state.hist.present.currentRecordIndex;
155
+ return data[dataUnit] || 0;
156
+ };
157
+ const selectNewRecordIndex = (state, dataUnit) => {
158
+ const data = state.hist.present.newRecordIndex;
159
+ return data[dataUnit] || 0;
160
+ };
161
+ //não histórico
162
+ const selectLoadingData = (state, dataUnit) => {
163
+ const data = state.nonhist.dataLoading;
164
+ return data[dataUnit];
165
+ };
166
+ const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
167
+ const data = state.nonhist.invalidFields;
168
+ const dataUnitMessages = data[dataUnit] || {};
169
+ const recordMessages = dataUnitMessages[recordId] || {};
170
+ return recordMessages[fieldName] || "";
162
171
  };
172
+ const selectVisibleButtons = state => state.nonhist.visibleButtons;
163
173
 
164
- class DataUnit {
165
- constructor(name, cardinality = '1') {
166
- this.name = name;
167
- this.cardinality = cardinality;
168
- }
169
- set store(store) {
170
- this._store = store;
171
- }
172
- isLoading() {
173
- return selectLoadingData(this._store.getState(), this.name);
174
- }
175
- hasChanges() {
176
- const state = this._store.getState();
177
- return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
178
- }
179
- hasNext() {
180
- return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
181
- }
182
- hasPrevious() {
183
- return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
184
- }
185
- hasCurrentRecord() {
186
- return this.getCurrentRecord() != undefined;
187
- }
188
- previous() {
189
- this._store.dispatch(previousRecord(this.name));
190
- }
191
- next() {
192
- this._store.dispatch(nextRecord(this.name, this.records.length));
193
- }
194
- getValue(fieldName) {
195
- const currentRecord = this.getCurrentRecord();
196
- if (!currentRecord) {
197
- return undefined;
198
- }
199
- const changes = this.getRecordChanges(currentRecord);
200
- return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
201
- }
202
- getErrorMessage(fieldName) {
203
- const currentRecord = this.getCurrentRecord();
204
- if (!currentRecord) {
205
- return "";
206
- }
207
- return selectErrorMessage(this._store.getState(), this.name, currentRecord.record__id, fieldName);
208
- }
209
- changeValue(fieldName, newValue) {
210
- if (this.records.length == 0) {
211
- this.insert();
212
- }
213
- if (this._changeDeboucing) {
214
- window.clearTimeout(this._changeDeboucing);
215
- }
216
- this._changeDeboucing = window.setTimeout(() => {
217
- const currentRecord = this.getCurrentRecord();
218
- this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
219
- }, 100);
220
- }
221
- cancel() {
222
- this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
223
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
224
- }
225
- insert() {
226
- const insertionIndex = this.records.length;
227
- const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
228
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
229
- this._store.dispatch(insertRecord(this.name, insertionIndex));
230
- }
231
- save() {
232
- if (!this.validateRecords()) {
233
- return;
234
- }
235
- this._store.dispatch(savingChanges(this.name));
236
- let saveResult;
237
- if (this.saveExecutor) {
238
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
239
- const changesByRecord = Object.keys(duChanges).map(record__id => {
240
- const record = { record__id };
241
- const recordChanges = duChanges[record__id];
242
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
243
- return record;
244
- });
245
- const changesToSave = [{
246
- dataUnit: this.name,
247
- records: changesByRecord
248
- }];
249
- saveResult = this.saveExecutor(changesToSave);
250
- }
251
- if (saveResult instanceof Promise) {
252
- saveResult.then(r => this.processSaveResult(r));
253
- }
254
- else {
255
- this.processSaveResult(saveResult);
256
- }
257
- }
258
- load() {
259
- this._store.dispatch(dataLoading(this.name));
260
- let result;
261
- if (this.loadExecutor) {
262
- result = this.loadExecutor({ dataUnit: this.name });
263
- }
264
- if (result instanceof Promise) {
265
- result.then(r => this.processLoadResult(r));
266
- }
267
- else {
268
- this.processLoadResult(result);
269
- }
270
- }
271
- remove() {
272
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
273
- this._store.dispatch(removingRecord(this.name));
274
- let removeResult;
275
- if (this.removeExecutor) {
276
- const record = this.getCurrentRecord();
277
- removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
278
- }
279
- else {
280
- removeResult = true;
281
- }
282
- if (removeResult) {
283
- if (removeResult instanceof Promise) {
284
- removeResult.then(r => this.processRemoveResult(r, currentIndex));
285
- }
286
- else {
287
- this.processRemoveResult(removeResult, currentIndex);
288
- }
289
- }
290
- }
291
- processSaveResult(result) {
292
- if (result) {
293
- if (result instanceof Array) {
294
- result.forEach(item => this.processSaveResult(item));
295
- }
296
- else {
297
- if (result.dataUnit === this.name) {
298
- result.records.forEach(savedRecord => {
299
- let rID = savedRecord.oldRecord__id;
300
- delete savedRecord.oldRecord__id;
301
- if (rID === undefined) {
302
- rID = savedRecord.record__id;
303
- }
304
- this.records.forEach((r, index) => {
305
- if (r.record__id === rID) {
306
- this.records[index] = Object.assign(r, savedRecord);
307
- }
308
- });
309
- });
310
- }
311
- }
312
- }
313
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
314
- this._store.dispatch(changesSaved(this.name));
315
- }
316
- processLoadResult(records) {
317
- this.records = records;
318
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
319
- this._store.dispatch(dataLoaded(this.name));
320
- }
321
- processRemoveResult(removed, recordIndex) {
322
- if (removed) {
323
- this.records.splice(recordIndex, 1);
324
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
325
- }
326
- this._store.dispatch(recordRemoved(this.name));
327
- }
328
- set records(records) {
329
- this._records = records;
330
- }
331
- get records() {
332
- if (!this._records) {
333
- this._records = [];
334
- }
335
- return this._records;
336
- }
337
- getCurrentRecord() {
338
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
339
- return this.records[currentIndex];
340
- }
341
- getRecordChanges(currentRecord = undefined) {
342
- if (currentRecord === undefined) {
343
- currentRecord = this.getCurrentRecord();
344
- }
345
- return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
346
- }
347
- validateRecords() {
348
- if (!this.recordsValidator) {
349
- return true;
350
- }
351
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
352
- const recordsToValidate = [];
353
- this.records.forEach((record, i) => {
354
- const changes = duChanges[record.record__id];
355
- if (changes) {
356
- recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
357
- }
358
- });
359
- if (recordsToValidate.length == 0) {
360
- return true;
361
- }
362
- const result = this.recordsValidator.validateRecords(this, recordsToValidate);
363
- if (result.message) {
364
- alert(result.message);
365
- }
366
- return result.isValid;
367
- }
174
+ class DataUnit {
175
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
176
+ this.name = name;
177
+ this.unitLabel = unitLabel;
178
+ this.cardinality = cardinality;
179
+ this._children = [];
180
+ if (parentDU != null) {
181
+ parentDU._children.push(this);
182
+ this.parentDU = parentDU;
183
+ this.parentDUName = parentDU.name;
184
+ }
185
+ }
186
+ set store(store) {
187
+ this._store = store;
188
+ }
189
+ isLoading() {
190
+ return selectLoadingData(this._store.getState(), this.name);
191
+ }
192
+ hasChanges() {
193
+ const state = this._store.getState();
194
+ return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
195
+ }
196
+ hasNext() {
197
+ return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
198
+ }
199
+ hasPrevious() {
200
+ return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
201
+ }
202
+ hasCurrentRecord() {
203
+ return this.getCurrentRecord() != undefined;
204
+ }
205
+ previous() {
206
+ this._store.dispatch(previousRecord(this.name));
207
+ }
208
+ next() {
209
+ this._store.dispatch(nextRecord(this.name, this.records.length));
210
+ }
211
+ getValue(fieldName) {
212
+ const currentRecord = this.getCurrentRecord();
213
+ if (!currentRecord) {
214
+ return undefined;
215
+ }
216
+ const changes = this.getRecordChanges(currentRecord);
217
+ return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
218
+ }
219
+ getErrorMessage(fieldName) {
220
+ const currentRecord = this.getCurrentRecord();
221
+ return selectErrorMessage(this._store.getState(), this.name, currentRecord === null || currentRecord === void 0 ? void 0 : currentRecord.record__id, fieldName);
222
+ }
223
+ changeValue(fieldName, newValue) {
224
+ if (this.records.length == 0) {
225
+ this.insert();
226
+ }
227
+ if (this._changeDeboucing) {
228
+ window.clearTimeout(this._changeDeboucing);
229
+ }
230
+ this._changeDeboucing = window.setTimeout(() => {
231
+ const currentRecord = this.getCurrentRecord();
232
+ this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
233
+ }, 100);
234
+ }
235
+ cancel() {
236
+ this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
237
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
238
+ }
239
+ insert() {
240
+ const insertionIndex = this.records.length;
241
+ const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
242
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
243
+ this.bindToParent(newRecord);
244
+ this.records.push(newRecord);
245
+ this._store.dispatch(insertRecord(this.name, insertionIndex));
246
+ }
247
+ buildChange(r) {
248
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
249
+ const recordChanges = duChanges[r.record__id];
250
+ let subChanges = [];
251
+ this._children.forEach(duChild => {
252
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
253
+ });
254
+ if (recordChanges || subChanges.length > 0) {
255
+ const change = {
256
+ "__data__unit": this.name,
257
+ "__record__id": r.record__id,
258
+ "__sub__changes": subChanges
259
+ };
260
+ if (recordChanges) {
261
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
262
+ }
263
+ return change;
264
+ }
265
+ return undefined;
266
+ }
267
+ getSubChanges(id) {
268
+ const result = [];
269
+ if (this._records) {
270
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
271
+ const c = this.buildChange(r);
272
+ if (c) {
273
+ result.push(c);
274
+ }
275
+ });
276
+ }
277
+ return result;
278
+ }
279
+ getChangesToSave() {
280
+ let result = [];
281
+ if (this._records) {
282
+ this._records.forEach(r => {
283
+ const change = this.buildChange(r);
284
+ result.push(change);
285
+ });
286
+ }
287
+ return result;
288
+ }
289
+ save() {
290
+ if (!this.validateRecords()) {
291
+ return;
292
+ }
293
+ this._store.dispatch(savingChanges(this.name));
294
+ let saveResult;
295
+ if (this.saveExecutor) {
296
+ saveResult = this.saveExecutor(this.getChangesToSave());
297
+ }
298
+ if (saveResult instanceof Promise) {
299
+ saveResult.then(r => this.processSaveResult(r));
300
+ }
301
+ else {
302
+ this.processSaveResult(saveResult);
303
+ }
304
+ }
305
+ load() {
306
+ this._store.dispatch(dataLoading(this.name));
307
+ let result;
308
+ if (this.loadExecutor) {
309
+ result = this.loadExecutor({ dataUnit: this.name });
310
+ }
311
+ if (result instanceof Promise) {
312
+ result.then(r => this.processLoadResult(r));
313
+ }
314
+ else {
315
+ this.processLoadResult(result);
316
+ }
317
+ }
318
+ remove() {
319
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
320
+ this._store.dispatch(removingRecord(this.name));
321
+ let removeResult;
322
+ if (this.removeExecutor) {
323
+ const record = this.getCurrentRecord();
324
+ removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
325
+ }
326
+ else {
327
+ removeResult = true;
328
+ }
329
+ if (removeResult) {
330
+ if (removeResult instanceof Promise) {
331
+ removeResult.then(r => this.processRemoveResult(r, currentIndex));
332
+ }
333
+ else {
334
+ this.processRemoveResult(removeResult, currentIndex);
335
+ }
336
+ }
337
+ }
338
+ processSaveResult(result) {
339
+ if (result) {
340
+ if (result instanceof Array) {
341
+ result.forEach(item => this.processSaveResult(item));
342
+ }
343
+ else {
344
+ if (result.dataUnit === this.name) {
345
+ result.records.forEach(savedRecord => {
346
+ let rID = savedRecord.oldRecord__id;
347
+ delete savedRecord.oldRecord__id;
348
+ if (rID === undefined) {
349
+ rID = savedRecord.record__id;
350
+ }
351
+ this.records.forEach((r, index) => {
352
+ if (r.record__id === rID) {
353
+ this.records[index] = Object.assign(r, savedRecord);
354
+ }
355
+ });
356
+ });
357
+ }
358
+ }
359
+ }
360
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
361
+ this._store.dispatch(changesSaved(this.name));
362
+ }
363
+ processLoadResult(records) {
364
+ this.records = records;
365
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
366
+ this._store.dispatch(dataLoaded(this.name));
367
+ }
368
+ processRemoveResult(removed, recordIndex) {
369
+ if (removed) {
370
+ this.records.splice(recordIndex, 1);
371
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
372
+ }
373
+ this._store.dispatch(recordRemoved(this.name));
374
+ }
375
+ set records(records) {
376
+ this._records = records;
377
+ if (this.parentDU) {
378
+ this._records.forEach(r => this.bindToParent(r));
379
+ }
380
+ }
381
+ bindToParent(r) {
382
+ if (this.parentDU) {
383
+ const parentRecord = this.parentDU.getCurrentRecord();
384
+ if (parentRecord) {
385
+ r.parent__record__id = parentRecord.record__id;
386
+ }
387
+ }
388
+ }
389
+ get records() {
390
+ if (!this._records) {
391
+ this._records = [];
392
+ }
393
+ return this._records;
394
+ }
395
+ getCurrentRecord() {
396
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
397
+ return this.records[currentIndex];
398
+ }
399
+ getRecordChanges(currentRecord = undefined) {
400
+ if (currentRecord === undefined) {
401
+ currentRecord = this.getCurrentRecord();
402
+ }
403
+ return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
404
+ }
405
+ validateRecords() {
406
+ if (!this.recordsValidator) {
407
+ return true;
408
+ }
409
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
410
+ const recordsToValidate = [];
411
+ this.records.forEach((record, i) => {
412
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
413
+ if (changes) {
414
+ recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
415
+ }
416
+ });
417
+ const result = this.recordsValidator.validateRecords(this, recordsToValidate);
418
+ if (result.message) {
419
+ alert(result.message);
420
+ }
421
+ return result.isValid;
422
+ }
368
423
  }
369
424
 
370
425
  exports.DataUnit = DataUnit;
@@ -374,3 +429,5 @@ exports.formLoad = formLoad;
374
429
  exports.invalidField = invalidField;
375
430
  exports.selectCurrentTab = selectCurrentTab;
376
431
  exports.selectIsCollapsedFieldSet = selectIsCollapsedFieldSet;
432
+ exports.selectVisibleButtons = selectVisibleButtons;
433
+ exports.showHideNavigationButtons = showHideNavigationButtons;