@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,43 +1,44 @@
1
- //histórico
2
- export const selectCurrentTab = (state, formName) => {
3
- const data = state.hist.present.currentTabIndex;
4
- return data[formName] || 0;
5
- };
6
- export const selectIsCollapsedFieldSet = (state, fieldSetName) => {
7
- const data = state.hist.present.collapsedGroups;
8
- return data[fieldSetName];
9
- };
10
- export const selectRecordChanges = (state, dataUnit, recordId) => {
11
- const data = selectDataUnitChanges(state, dataUnit);
12
- return data ? data[recordId] : undefined;
13
- };
14
- export const selectDataUnitChanges = (state, dataUnit) => {
15
- const data = state.hist.present.changes;
16
- return data[dataUnit];
17
- };
18
- export const selectCurrentRecordIndex = (state, dataUnit) => {
19
- const data = state.hist.present.currentRecordIndex;
20
- return data[dataUnit] || 0;
21
- };
22
- export const selectNewRecordIndex = (state, dataUnit) => {
23
- const data = state.hist.present.newRecordIndex;
24
- return data[dataUnit] || 0;
25
- };
26
- export const selectUndoState = state => { return { canUndo: state.hist.past.length > 0, canRedo: state.hist.future.length > 0 }; };
27
- //não histórico
28
- export const selectLoadingData = (state, dataUnit) => {
29
- const data = state.nonhist.dataLoading;
30
- return data[dataUnit];
31
- };
32
- export const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
33
- const data = state.nonhist.invalidFields;
34
- const dataUnitMessages = data[dataUnit] || {};
35
- const recordMessages = dataUnitMessages[recordId] || {};
36
- return recordMessages[fieldName] || "";
37
- };
38
- export const selectInvalidFields = (state, dataUnit, recordId) => {
39
- const data = state.nonhist.invalidFields;
40
- const dataUnitMessages = data[dataUnit] || {};
41
- const recordMessages = dataUnitMessages[recordId] || {};
42
- return Object.keys(recordMessages);
43
- };
1
+ //histórico
2
+ export const selectCurrentTab = (state, formName) => {
3
+ const data = state.hist.present.currentTabIndex;
4
+ return data[formName] || 0;
5
+ };
6
+ export const selectIsCollapsedFieldSet = (state, fieldSetName) => {
7
+ const data = state.hist.present.collapsedGroups;
8
+ return data[fieldSetName];
9
+ };
10
+ export const selectRecordChanges = (state, dataUnit, recordId) => {
11
+ const data = selectDataUnitChanges(state, dataUnit);
12
+ return data ? data[recordId] : undefined;
13
+ };
14
+ export const selectDataUnitChanges = (state, dataUnit) => {
15
+ const data = state.hist.present.changes;
16
+ return data[dataUnit];
17
+ };
18
+ export const selectCurrentRecordIndex = (state, dataUnit) => {
19
+ const data = state.hist.present.currentRecordIndex;
20
+ return data[dataUnit] || 0;
21
+ };
22
+ export const selectNewRecordIndex = (state, dataUnit) => {
23
+ const data = state.hist.present.newRecordIndex;
24
+ return data[dataUnit] || 0;
25
+ };
26
+ export const selectUndoState = state => { return { canUndo: state.hist.past.length > 0, canRedo: state.hist.future.length > 0 }; };
27
+ //não histórico
28
+ export const selectLoadingData = (state, dataUnit) => {
29
+ const data = state.nonhist.dataLoading;
30
+ return data[dataUnit];
31
+ };
32
+ export const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
33
+ const data = state.nonhist.invalidFields;
34
+ const dataUnitMessages = data[dataUnit] || {};
35
+ const recordMessages = dataUnitMessages[recordId] || {};
36
+ return recordMessages[fieldName] || "";
37
+ };
38
+ export const selectInvalidFields = (state, dataUnit, recordId) => {
39
+ const data = state.nonhist.invalidFields;
40
+ const dataUnitMessages = data[dataUnit] || {};
41
+ const recordMessages = dataUnitMessages[recordId] || {};
42
+ return Object.keys(recordMessages);
43
+ };
44
+ export const selectVisibleButtons = state => state.nonhist.visibleButtons;
@@ -1,207 +1,252 @@
1
- import { changeFieldValue, changesSaved, clearEdition, dataLoaded, dataLoading, insertRecord, nextRecord, previousRecord, recordRemoved, removingRecord, savingChanges } from '../store/Form.actions';
2
- import { selectRecordChanges, selectCurrentRecordIndex, selectLoadingData, selectNewRecordIndex, selectDataUnitChanges, selectErrorMessage } from '../store/Form.selectors';
3
- export default class DataUnit {
4
- constructor(name, cardinality = '1') {
5
- this.name = name;
6
- this.cardinality = cardinality;
7
- }
8
- set store(store) {
9
- this._store = store;
10
- }
11
- isLoading() {
12
- return selectLoadingData(this._store.getState(), this.name);
13
- }
14
- hasChanges() {
15
- const state = this._store.getState();
16
- return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
17
- }
18
- hasNext() {
19
- return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
20
- }
21
- hasPrevious() {
22
- return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
23
- }
24
- hasCurrentRecord() {
25
- return this.getCurrentRecord() != undefined;
26
- }
27
- previous() {
28
- this._store.dispatch(previousRecord(this.name));
29
- }
30
- next() {
31
- this._store.dispatch(nextRecord(this.name, this.records.length));
32
- }
33
- getValue(fieldName) {
34
- const currentRecord = this.getCurrentRecord();
35
- if (!currentRecord) {
36
- return undefined;
37
- }
38
- const changes = this.getRecordChanges(currentRecord);
39
- return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
40
- }
41
- getErrorMessage(fieldName) {
42
- const currentRecord = this.getCurrentRecord();
43
- if (!currentRecord) {
44
- return "";
45
- }
46
- return selectErrorMessage(this._store.getState(), this.name, currentRecord.record__id, fieldName);
47
- }
48
- changeValue(fieldName, newValue) {
49
- if (this.records.length == 0) {
50
- this.insert();
51
- }
52
- if (this._changeDeboucing) {
53
- window.clearTimeout(this._changeDeboucing);
54
- }
55
- this._changeDeboucing = window.setTimeout(() => {
56
- const currentRecord = this.getCurrentRecord();
57
- this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
58
- }, 100);
59
- }
60
- cancel() {
61
- this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
62
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
63
- }
64
- insert() {
65
- const insertionIndex = this.records.length;
66
- const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
67
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
68
- this._store.dispatch(insertRecord(this.name, insertionIndex));
69
- }
70
- save() {
71
- if (!this.validateRecords()) {
72
- return;
73
- }
74
- this._store.dispatch(savingChanges(this.name));
75
- let saveResult;
76
- if (this.saveExecutor) {
77
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
78
- const changesByRecord = Object.keys(duChanges).map(record__id => {
79
- const record = { record__id };
80
- const recordChanges = duChanges[record__id];
81
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
82
- return record;
83
- });
84
- const changesToSave = [{
85
- dataUnit: this.name,
86
- records: changesByRecord
87
- }];
88
- saveResult = this.saveExecutor(changesToSave);
89
- }
90
- if (saveResult instanceof Promise) {
91
- saveResult.then(r => this.processSaveResult(r));
92
- }
93
- else {
94
- this.processSaveResult(saveResult);
95
- }
96
- }
97
- load() {
98
- this._store.dispatch(dataLoading(this.name));
99
- let result;
100
- if (this.loadExecutor) {
101
- result = this.loadExecutor({ dataUnit: this.name });
102
- }
103
- if (result instanceof Promise) {
104
- result.then(r => this.processLoadResult(r));
105
- }
106
- else {
107
- this.processLoadResult(result);
108
- }
109
- }
110
- remove() {
111
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
112
- this._store.dispatch(removingRecord(this.name));
113
- let removeResult;
114
- if (this.removeExecutor) {
115
- const record = this.getCurrentRecord();
116
- removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
117
- }
118
- else {
119
- removeResult = true;
120
- }
121
- if (removeResult) {
122
- if (removeResult instanceof Promise) {
123
- removeResult.then(r => this.processRemoveResult(r, currentIndex));
124
- }
125
- else {
126
- this.processRemoveResult(removeResult, currentIndex);
127
- }
128
- }
129
- }
130
- processSaveResult(result) {
131
- if (result) {
132
- if (result instanceof Array) {
133
- result.forEach(item => this.processSaveResult(item));
134
- }
135
- else {
136
- if (result.dataUnit === this.name) {
137
- result.records.forEach(savedRecord => {
138
- let rID = savedRecord.oldRecord__id;
139
- delete savedRecord.oldRecord__id;
140
- if (rID === undefined) {
141
- rID = savedRecord.record__id;
142
- }
143
- this.records.forEach((r, index) => {
144
- if (r.record__id === rID) {
145
- this.records[index] = Object.assign(r, savedRecord);
146
- }
147
- });
148
- });
149
- }
150
- }
151
- }
152
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
153
- this._store.dispatch(changesSaved(this.name));
154
- }
155
- processLoadResult(records) {
156
- this.records = records;
157
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
158
- this._store.dispatch(dataLoaded(this.name));
159
- }
160
- processRemoveResult(removed, recordIndex) {
161
- if (removed) {
162
- this.records.splice(recordIndex, 1);
163
- this._store.dispatch(clearEdition(this.name, this.records.length - 1));
164
- }
165
- this._store.dispatch(recordRemoved(this.name));
166
- }
167
- set records(records) {
168
- this._records = records;
169
- }
170
- get records() {
171
- if (!this._records) {
172
- this._records = [];
173
- }
174
- return this._records;
175
- }
176
- getCurrentRecord() {
177
- const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
178
- return this.records[currentIndex];
179
- }
180
- getRecordChanges(currentRecord = undefined) {
181
- if (currentRecord === undefined) {
182
- currentRecord = this.getCurrentRecord();
183
- }
184
- return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
185
- }
186
- validateRecords() {
187
- if (!this.recordsValidator) {
188
- return true;
189
- }
190
- const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
191
- const recordsToValidate = [];
192
- this.records.forEach((record, i) => {
193
- const changes = duChanges[record.record__id];
194
- if (changes) {
195
- recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
196
- }
197
- });
198
- if (recordsToValidate.length == 0) {
199
- return true;
200
- }
201
- const result = this.recordsValidator.validateRecords(this, recordsToValidate);
202
- if (result.message) {
203
- alert(result.message);
204
- }
205
- return result.isValid;
206
- }
207
- }
1
+ import { changeFieldValue, changesSaved, clearEdition, dataLoaded, dataLoading, insertRecord, nextRecord, previousRecord, recordRemoved, removingRecord, savingChanges } from '../store/Form.actions';
2
+ import { selectRecordChanges, selectCurrentRecordIndex, selectLoadingData, selectNewRecordIndex, selectDataUnitChanges, selectErrorMessage } from '../store/Form.selectors';
3
+ export default class DataUnit {
4
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
5
+ this.name = name;
6
+ this.unitLabel = unitLabel;
7
+ this.cardinality = cardinality;
8
+ this._children = [];
9
+ if (parentDU != null) {
10
+ parentDU._children.push(this);
11
+ this.parentDU = parentDU;
12
+ this.parentDUName = parentDU.name;
13
+ }
14
+ }
15
+ set store(store) {
16
+ this._store = store;
17
+ }
18
+ isLoading() {
19
+ return selectLoadingData(this._store.getState(), this.name);
20
+ }
21
+ hasChanges() {
22
+ const state = this._store.getState();
23
+ return selectDataUnitChanges(state, this.name) !== undefined || selectNewRecordIndex(state, this.name) > 0;
24
+ }
25
+ hasNext() {
26
+ return selectCurrentRecordIndex(this._store.getState(), this.name) < (this.records.length - 1);
27
+ }
28
+ hasPrevious() {
29
+ return selectCurrentRecordIndex(this._store.getState(), this.name) > 0;
30
+ }
31
+ hasCurrentRecord() {
32
+ return this.getCurrentRecord() != undefined;
33
+ }
34
+ previous() {
35
+ this._store.dispatch(previousRecord(this.name));
36
+ }
37
+ next() {
38
+ this._store.dispatch(nextRecord(this.name, this.records.length));
39
+ }
40
+ getValue(fieldName) {
41
+ const currentRecord = this.getCurrentRecord();
42
+ if (!currentRecord) {
43
+ return undefined;
44
+ }
45
+ const changes = this.getRecordChanges(currentRecord);
46
+ return changes && changes[fieldName] !== undefined ? changes[fieldName] : currentRecord[fieldName] || null;
47
+ }
48
+ getErrorMessage(fieldName) {
49
+ const currentRecord = this.getCurrentRecord();
50
+ return selectErrorMessage(this._store.getState(), this.name, currentRecord === null || currentRecord === void 0 ? void 0 : currentRecord.record__id, fieldName);
51
+ }
52
+ changeValue(fieldName, newValue) {
53
+ if (this.records.length == 0) {
54
+ this.insert();
55
+ }
56
+ if (this._changeDeboucing) {
57
+ window.clearTimeout(this._changeDeboucing);
58
+ }
59
+ this._changeDeboucing = window.setTimeout(() => {
60
+ const currentRecord = this.getCurrentRecord();
61
+ this._store.dispatch(changeFieldValue(this.name, currentRecord.record__id, fieldName, newValue));
62
+ }, 100);
63
+ }
64
+ cancel() {
65
+ this.records = this.records.filter(r => !r.record__id.startsWith('NEW_'));
66
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
67
+ }
68
+ insert() {
69
+ const insertionIndex = this.records.length;
70
+ const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
71
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
72
+ this.bindToParent(newRecord);
73
+ this.records.push(newRecord);
74
+ this._store.dispatch(insertRecord(this.name, insertionIndex));
75
+ }
76
+ buildChange(r) {
77
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
78
+ const recordChanges = duChanges[r.record__id];
79
+ let subChanges = [];
80
+ this._children.forEach(duChild => {
81
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
82
+ });
83
+ if (recordChanges || subChanges.length > 0) {
84
+ const change = {
85
+ "__data__unit": this.name,
86
+ "__record__id": r.record__id,
87
+ "__sub__changes": subChanges
88
+ };
89
+ if (recordChanges) {
90
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
91
+ }
92
+ return change;
93
+ }
94
+ return undefined;
95
+ }
96
+ getSubChanges(id) {
97
+ const result = [];
98
+ if (this._records) {
99
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
100
+ const c = this.buildChange(r);
101
+ if (c) {
102
+ result.push(c);
103
+ }
104
+ });
105
+ }
106
+ return result;
107
+ }
108
+ getChangesToSave() {
109
+ let result = [];
110
+ if (this._records) {
111
+ this._records.forEach(r => {
112
+ const change = this.buildChange(r);
113
+ result.push(change);
114
+ });
115
+ }
116
+ return result;
117
+ }
118
+ save() {
119
+ if (!this.validateRecords()) {
120
+ return;
121
+ }
122
+ this._store.dispatch(savingChanges(this.name));
123
+ let saveResult;
124
+ if (this.saveExecutor) {
125
+ saveResult = this.saveExecutor(this.getChangesToSave());
126
+ }
127
+ if (saveResult instanceof Promise) {
128
+ saveResult.then(r => this.processSaveResult(r));
129
+ }
130
+ else {
131
+ this.processSaveResult(saveResult);
132
+ }
133
+ }
134
+ load() {
135
+ this._store.dispatch(dataLoading(this.name));
136
+ let result;
137
+ if (this.loadExecutor) {
138
+ result = this.loadExecutor({ dataUnit: this.name });
139
+ }
140
+ if (result instanceof Promise) {
141
+ result.then(r => this.processLoadResult(r));
142
+ }
143
+ else {
144
+ this.processLoadResult(result);
145
+ }
146
+ }
147
+ remove() {
148
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
149
+ this._store.dispatch(removingRecord(this.name));
150
+ let removeResult;
151
+ if (this.removeExecutor) {
152
+ const record = this.getCurrentRecord();
153
+ removeResult = this.removeExecutor({ dataUnit: this.name, recordId: record.record__id, record });
154
+ }
155
+ else {
156
+ removeResult = true;
157
+ }
158
+ if (removeResult) {
159
+ if (removeResult instanceof Promise) {
160
+ removeResult.then(r => this.processRemoveResult(r, currentIndex));
161
+ }
162
+ else {
163
+ this.processRemoveResult(removeResult, currentIndex);
164
+ }
165
+ }
166
+ }
167
+ processSaveResult(result) {
168
+ if (result) {
169
+ if (result instanceof Array) {
170
+ result.forEach(item => this.processSaveResult(item));
171
+ }
172
+ else {
173
+ if (result.dataUnit === this.name) {
174
+ result.records.forEach(savedRecord => {
175
+ let rID = savedRecord.oldRecord__id;
176
+ delete savedRecord.oldRecord__id;
177
+ if (rID === undefined) {
178
+ rID = savedRecord.record__id;
179
+ }
180
+ this.records.forEach((r, index) => {
181
+ if (r.record__id === rID) {
182
+ this.records[index] = Object.assign(r, savedRecord);
183
+ }
184
+ });
185
+ });
186
+ }
187
+ }
188
+ }
189
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
190
+ this._store.dispatch(changesSaved(this.name));
191
+ }
192
+ processLoadResult(records) {
193
+ this.records = records;
194
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
195
+ this._store.dispatch(dataLoaded(this.name));
196
+ }
197
+ processRemoveResult(removed, recordIndex) {
198
+ if (removed) {
199
+ this.records.splice(recordIndex, 1);
200
+ this._store.dispatch(clearEdition(this.name, this.records.length - 1));
201
+ }
202
+ this._store.dispatch(recordRemoved(this.name));
203
+ }
204
+ set records(records) {
205
+ this._records = records;
206
+ if (this.parentDU) {
207
+ this._records.forEach(r => this.bindToParent(r));
208
+ }
209
+ }
210
+ bindToParent(r) {
211
+ if (this.parentDU) {
212
+ const parentRecord = this.parentDU.getCurrentRecord();
213
+ if (parentRecord) {
214
+ r.parent__record__id = parentRecord.record__id;
215
+ }
216
+ }
217
+ }
218
+ get records() {
219
+ if (!this._records) {
220
+ this._records = [];
221
+ }
222
+ return this._records;
223
+ }
224
+ getCurrentRecord() {
225
+ const currentIndex = selectCurrentRecordIndex(this._store.getState(), this.name);
226
+ return this.records[currentIndex];
227
+ }
228
+ getRecordChanges(currentRecord = undefined) {
229
+ if (currentRecord === undefined) {
230
+ currentRecord = this.getCurrentRecord();
231
+ }
232
+ return currentRecord ? selectRecordChanges(this._store.getState(), this.name, currentRecord.record__id) : undefined;
233
+ }
234
+ validateRecords() {
235
+ if (!this.recordsValidator) {
236
+ return true;
237
+ }
238
+ const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
239
+ const recordsToValidate = [];
240
+ this.records.forEach((record, i) => {
241
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
242
+ if (changes) {
243
+ recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
244
+ }
245
+ });
246
+ const result = this.recordsValidator.validateRecords(this, recordsToValidate);
247
+ if (result.message) {
248
+ alert(result.message);
249
+ }
250
+ return result.isValid;
251
+ }
252
+ }
@@ -1,16 +1,16 @@
1
- export class Form {
2
- }
3
- export class Field {
4
- }
5
- export class FieldSet {
6
- }
7
- export class UIProperty {
8
- }
9
- export class FieldDependency {
10
- }
11
- export var DependencyType;
12
- (function (DependencyType) {
13
- DependencyType["SEARCHING"] = "SEARCHING";
14
- DependencyType["REQUIREMENT"] = "REQUIREMENT";
15
- DependencyType["VISIBILITY"] = "REQUIREMENT";
16
- })(DependencyType || (DependencyType = {}));
1
+ export class Form {
2
+ }
3
+ export class Field {
4
+ }
5
+ export class FieldSet {
6
+ }
7
+ export class UIProperty {
8
+ }
9
+ export class FieldDependency {
10
+ }
11
+ export var DependencyType;
12
+ (function (DependencyType) {
13
+ DependencyType["SEARCHING"] = "SEARCHING";
14
+ DependencyType["REQUIREMENT"] = "REQUIREMENT";
15
+ DependencyType["VISIBILITY"] = "REQUIREMENT";
16
+ })(DependencyType || (DependencyType = {}));
@@ -1,24 +1,24 @@
1
- :host {
2
- display: flex;
3
- width: 100%;
4
- height: 42px;
5
- border-radius: 12px;
6
- background: var(--background--medium);
7
- background-image: linear-gradient(to right, var(--background--medium) 0%, var(--background--strong) 20%, var(--background--medium) 40%, var(--background--medium) 100%);
8
- background-repeat: no-repeat;
9
- background-size: 800px 1000px;
10
- animation-duration: 1s;
11
- animation-fill-mode: forwards;
12
- animation-iteration-count: infinite;
13
- animation-name: placeholderShimmer;
14
- animation-timing-function: linear;
15
- }
16
-
17
- @keyframes placeholderShimmer{
18
- 0%{
19
- background-position: -800px 0;
20
- }
21
- 100%{
22
- background-position: 800px 0;
23
- }
1
+ :host {
2
+ display: flex;
3
+ width: 100%;
4
+ height: 42px;
5
+ border-radius: 12px;
6
+ background: var(--background--medium);
7
+ background-image: linear-gradient(to right, var(--background--medium) 0%, var(--background--strong) 20%, var(--background--medium) 40%, var(--background--medium) 100%);
8
+ background-repeat: no-repeat;
9
+ background-size: 800px 1000px;
10
+ animation-duration: 1s;
11
+ animation-fill-mode: forwards;
12
+ animation-iteration-count: infinite;
13
+ animation-name: placeholderShimmer;
14
+ animation-timing-function: linear;
15
+ }
16
+
17
+ @keyframes placeholderShimmer{
18
+ 0%{
19
+ background-position: -800px 0;
20
+ }
21
+ 100%{
22
+ background-position: 800px 0;
23
+ }
24
24
  }