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