@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,380 +1,424 @@
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
- };
125
- }
126
- function showHideNavigationButtons(buttonName, status) {
127
- return {
128
- type: 'FORM/SHOWHIDENAVBTN',
129
- payload: {
130
- buttonName,
131
- status
132
- }
133
- };
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
+ };
134
134
  }
135
135
 
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] || "";
171
- };
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] || "";
171
+ };
172
172
  const selectVisibleButtons = state => state.nonhist.visibleButtons;
173
173
 
174
- class DataUnit {
175
- constructor(name, unitLabel, cardinality = '1') {
176
- this.name = name;
177
- this.unitLabel = unitLabel;
178
- this.cardinality = cardinality;
179
- }
180
- set store(store) {
181
- this._store = store;
182
- }
183
- isLoading() {
184
- return selectLoadingData(this._store.getState(), this.name);
185
- }
186
- hasChanges() {
187
- const state = this._store.getState();
188
- return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
189
- }
190
- hasNext() {
191
- return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
192
- }
193
- hasPrevious() {
194
- return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
195
- }
196
- hasCurrentRecord() {
197
- return this.getCurrentRecord() != undefined;
198
- }
199
- previous() {
200
- this._store.dispatch(previousRecord(this.name));
201
- }
202
- next() {
203
- this._store.dispatch(nextRecord(this.name, this.records.length));
204
- }
205
- getValue(fieldName) {
206
- const currentRecord = this.getCurrentRecord();
207
- if (!currentRecord) {
208
- return undefined;
209
- }
210
- const changes = this.getRecordChanges(currentRecord);
211
- return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
212
- }
213
- getErrorMessage(fieldName) {
214
- const currentRecord = this.getCurrentRecord();
215
- return selectErrorMessage(this._store.getState(), this.name, currentRecord === null || currentRecord === void 0 ? void 0 : currentRecord.record__id, fieldName);
216
- }
217
- changeValue(fieldName, newValue) {
218
- if (this.records.length == 0) {
219
- this.insert();
220
- }
221
- if (this._changeDeboucing) {
222
- window.clearTimeout(this._changeDeboucing);
223
- }
224
- this._changeDeboucing = window.setTimeout(() => {
225
- const currentRecord = this.getCurrentRecord();
226
- this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
227
- }, 100);
228
- }
229
- cancel() {
230
- this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
231
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
232
- }
233
- insert() {
234
- const insertionIndex = this.records.length;
235
- const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
236
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
237
- this._store.dispatch(insertRecord(this.name, insertionIndex));
238
- }
239
- getChangesToSave() {
240
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
241
- if (duChanges) {
242
- const changesByRecord = Object.keys(duChanges).map(record__id => {
243
- const record = { record__id };
244
- const recordChanges = duChanges[record__id];
245
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
246
- return record;
247
- });
248
- return [{
249
- dataUnit: this.name,
250
- records: changesByRecord
251
- }];
252
- }
253
- return undefined;
254
- }
255
- save() {
256
- if (!this.validateRecords()) {
257
- return;
258
- }
259
- this._store.dispatch(savingChanges(this.name));
260
- let saveResult;
261
- if (this.saveExecutor) {
262
- saveResult = this.saveExecutor(this.getChangesToSave());
263
- }
264
- if (saveResult instanceof Promise) {
265
- saveResult.then(r => this.processSaveResult(r));
266
- }
267
- else {
268
- this.processSaveResult(saveResult);
269
- }
270
- }
271
- load() {
272
- this._store.dispatch(dataLoading(this.name));
273
- let result;
274
- if (this.loadExecutor) {
275
- result = this.loadExecutor({ dataUnit: this.name });
276
- }
277
- if (result instanceof Promise) {
278
- result.then(r => this.processLoadResult(r));
279
- }
280
- else {
281
- this.processLoadResult(result);
282
- }
283
- }
284
- remove() {
285
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
286
- this._store.dispatch(removingRecord(this.name));
287
- let removeResult;
288
- if (this.removeExecutor) {
289
- const record = this.getCurrentRecord();
290
- removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
291
- }
292
- else {
293
- removeResult = true;
294
- }
295
- if (removeResult) {
296
- if (removeResult instanceof Promise) {
297
- removeResult.then(r => this.processRemoveResult(r, currentIndex));
298
- }
299
- else {
300
- this.processRemoveResult(removeResult, currentIndex);
301
- }
302
- }
303
- }
304
- processSaveResult(result) {
305
- if (result) {
306
- if (result instanceof Array) {
307
- result.forEach(item => this.processSaveResult(item));
308
- }
309
- else {
310
- if (result.dataUnit === this.name) {
311
- result.records.forEach(savedRecord => {
312
- let rID = savedRecord.oldRecord__id;
313
- delete savedRecord.oldRecord__id;
314
- if (rID === undefined) {
315
- rID = savedRecord.record__id;
316
- }
317
- this.records.forEach((r, index) => {
318
- if (r.record__id === rID) {
319
- this.records[index] = Object.assign(r, savedRecord);
320
- }
321
- });
322
- });
323
- }
324
- }
325
- }
326
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
327
- this._store.dispatch(changesSaved(this.name));
328
- }
329
- processLoadResult(records) {
330
- this.records = records;
331
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
332
- this._store.dispatch(dataLoaded(this.name));
333
- }
334
- processRemoveResult(removed, recordIndex) {
335
- if (removed) {
336
- this.records.splice(recordIndex, 1);
337
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
338
- }
339
- this._store.dispatch(recordRemoved(this.name));
340
- }
341
- set records(records) {
342
- this._records = records;
343
- }
344
- get records() {
345
- if (!this._records) {
346
- this._records = [];
347
- }
348
- return this._records;
349
- }
350
- getCurrentRecord() {
351
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
352
- return this.records[currentIndex];
353
- }
354
- getRecordChanges(currentRecord = undefined) {
355
- if (currentRecord === undefined) {
356
- currentRecord = this.getCurrentRecord();
357
- }
358
- return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
359
- }
360
- validateRecords() {
361
- if (!this.recordsValidator) {
362
- return true;
363
- }
364
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
365
- const recordsToValidate = [];
366
- this.records.forEach((record, i) => {
367
- const changes = duChanges[record.record__id];
368
- if (changes) {
369
- recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
370
- }
371
- });
372
- const result = this.recordsValidator.validateRecords(this, recordsToValidate);
373
- if (result.message) {
374
- alert(result.message);
375
- }
376
- return result.isValid;
377
- }
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
+ }
184
+ }
185
+ set store(store) {
186
+ this._store = store;
187
+ }
188
+ isLoading() {
189
+ return selectLoadingData(this._store.getState(), this.name);
190
+ }
191
+ hasChanges() {
192
+ const state = this._store.getState();
193
+ return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
194
+ }
195
+ hasNext() {
196
+ return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
197
+ }
198
+ hasPrevious() {
199
+ return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
200
+ }
201
+ hasCurrentRecord() {
202
+ return this.getCurrentRecord() != undefined;
203
+ }
204
+ previous() {
205
+ this._store.dispatch(previousRecord(this.name));
206
+ }
207
+ next() {
208
+ this._store.dispatch(nextRecord(this.name, this.records.length));
209
+ }
210
+ getValue(fieldName) {
211
+ const currentRecord = this.getCurrentRecord();
212
+ if (!currentRecord) {
213
+ return undefined;
214
+ }
215
+ const changes = this.getRecordChanges(currentRecord);
216
+ return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
217
+ }
218
+ getErrorMessage(fieldName) {
219
+ const currentRecord = this.getCurrentRecord();
220
+ return selectErrorMessage(this._store.getState(), this.name, currentRecord === null || currentRecord === void 0 ? void 0 : currentRecord.record__id, fieldName);
221
+ }
222
+ changeValue(fieldName, newValue) {
223
+ if (this.records.length == 0) {
224
+ this.insert();
225
+ }
226
+ if (this._changeDeboucing) {
227
+ window.clearTimeout(this._changeDeboucing);
228
+ }
229
+ this._changeDeboucing = window.setTimeout(() => {
230
+ const currentRecord = this.getCurrentRecord();
231
+ this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
232
+ }, 100);
233
+ }
234
+ cancel() {
235
+ this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
236
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
237
+ }
238
+ insert() {
239
+ const insertionIndex = this.records.length;
240
+ const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
241
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
242
+ this.bindToParent(newRecord);
243
+ this.records.push(newRecord);
244
+ this._store.dispatch(insertRecord(this.name, insertionIndex));
245
+ }
246
+ buildChange(r) {
247
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
248
+ const recordChanges = duChanges[r.record__id];
249
+ let subChanges = [];
250
+ this._children.forEach(duChild => {
251
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
252
+ });
253
+ if (recordChanges || subChanges.length > 0) {
254
+ const change = {
255
+ "__data__unit": this.name,
256
+ "__record__id": r.record__id,
257
+ "__sub__changes": subChanges
258
+ };
259
+ if (recordChanges) {
260
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
261
+ }
262
+ return change;
263
+ }
264
+ return undefined;
265
+ }
266
+ getSubChanges(id) {
267
+ const result = [];
268
+ if (this._records) {
269
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
270
+ const c = this.buildChange(r);
271
+ if (c) {
272
+ result.push(c);
273
+ }
274
+ });
275
+ }
276
+ return result;
277
+ }
278
+ getChangesToSave() {
279
+ let result = [];
280
+ if (this._records) {
281
+ this._records.forEach(r => {
282
+ const change = this.buildChange(r);
283
+ result.push(change);
284
+ });
285
+ }
286
+ return result;
287
+ }
288
+ save() {
289
+ if (!this.validateRecords()) {
290
+ return;
291
+ }
292
+ this._store.dispatch(savingChanges(this.name));
293
+ let saveResult;
294
+ if (this.saveExecutor) {
295
+ saveResult = this.saveExecutor(this.getChangesToSave());
296
+ }
297
+ if (saveResult instanceof Promise) {
298
+ saveResult.then(r => this.processSaveResult(r));
299
+ }
300
+ else {
301
+ this.processSaveResult(saveResult);
302
+ }
303
+ }
304
+ load() {
305
+ this._store.dispatch(dataLoading(this.name));
306
+ let result;
307
+ if (this.loadExecutor) {
308
+ result = this.loadExecutor({ dataUnit: this.name });
309
+ }
310
+ if (result instanceof Promise) {
311
+ result.then(r => this.processLoadResult(r));
312
+ }
313
+ else {
314
+ this.processLoadResult(result);
315
+ }
316
+ }
317
+ remove() {
318
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
319
+ this._store.dispatch(removingRecord(this.name));
320
+ let removeResult;
321
+ if (this.removeExecutor) {
322
+ const record = this.getCurrentRecord();
323
+ removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
324
+ }
325
+ else {
326
+ removeResult = true;
327
+ }
328
+ if (removeResult) {
329
+ if (removeResult instanceof Promise) {
330
+ removeResult.then(r => this.processRemoveResult(r, currentIndex));
331
+ }
332
+ else {
333
+ this.processRemoveResult(removeResult, currentIndex);
334
+ }
335
+ }
336
+ }
337
+ processSaveResult(result) {
338
+ if (result) {
339
+ if (result instanceof Array) {
340
+ result.forEach(item => this.processSaveResult(item));
341
+ }
342
+ else {
343
+ if (result.dataUnit === this.name) {
344
+ result.records.forEach(savedRecord => {
345
+ let rID = savedRecord.oldRecord__id;
346
+ delete savedRecord.oldRecord__id;
347
+ if (rID === undefined) {
348
+ rID = savedRecord.record__id;
349
+ }
350
+ this.records.forEach((r, index) => {
351
+ if (r.record__id === rID) {
352
+ this.records[index] = Object.assign(r, savedRecord);
353
+ }
354
+ });
355
+ });
356
+ }
357
+ }
358
+ }
359
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
360
+ this._store.dispatch(changesSaved(this.name));
361
+ }
362
+ processLoadResult(records) {
363
+ this.records = records;
364
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
365
+ this._store.dispatch(dataLoaded(this.name));
366
+ }
367
+ processRemoveResult(removed, recordIndex) {
368
+ if (removed) {
369
+ this.records.splice(recordIndex, 1);
370
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
371
+ }
372
+ this._store.dispatch(recordRemoved(this.name));
373
+ }
374
+ set records(records) {
375
+ this._records = records;
376
+ if (this.parentDU) {
377
+ this._records.forEach(r => this.bindToParent(r));
378
+ }
379
+ }
380
+ bindToParent(r) {
381
+ if (this.parentDU) {
382
+ const parentRecord = this.parentDU.getCurrentRecord();
383
+ if (parentRecord) {
384
+ r.parent__record__id = parentRecord.record__id;
385
+ }
386
+ }
387
+ }
388
+ get records() {
389
+ if (!this._records) {
390
+ this._records = [];
391
+ }
392
+ return this._records;
393
+ }
394
+ getCurrentRecord() {
395
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
396
+ return this.records[currentIndex];
397
+ }
398
+ getRecordChanges(currentRecord = undefined) {
399
+ if (currentRecord === undefined) {
400
+ currentRecord = this.getCurrentRecord();
401
+ }
402
+ return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
403
+ }
404
+ validateRecords() {
405
+ if (!this.recordsValidator) {
406
+ return true;
407
+ }
408
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
409
+ const recordsToValidate = [];
410
+ this.records.forEach((record, i) => {
411
+ const changes = duChanges[record.record__id];
412
+ if (changes) {
413
+ recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
414
+ }
415
+ });
416
+ const result = this.recordsValidator.validateRecords(this, recordsToValidate);
417
+ if (result.message) {
418
+ alert(result.message);
419
+ }
420
+ return result.isValid;
421
+ }
378
422
  }
379
423
 
380
424
  exports.DataUnit = DataUnit;