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