@sankhyalabs/ezui 1.1.8 → 1.1.9

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