@michalrakus/x-react-web-lib 1.11.1 → 1.13.0

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 (47) hide show
  1. package/XUtilsConversions.d.ts +1 -1
  2. package/XUtilsConversions.js +1 -1
  3. package/XUtilsMetadataCommon.d.ts +3 -0
  4. package/XUtilsMetadataCommon.js +5 -0
  5. package/gulpfile.js +3 -2
  6. package/lib/components/XAutoComplete.d.ts +3 -1
  7. package/lib/components/XAutoComplete.js +14 -8
  8. package/lib/components/XAutoCompleteBase.d.ts +4 -0
  9. package/lib/components/XAutoCompleteBase.js +33 -2
  10. package/lib/components/XAutoCompleteDT.js +4 -4
  11. package/lib/components/XCalendar.js +1 -1
  12. package/lib/components/XDropdown.js +2 -2
  13. package/lib/components/XDropdownDT.js +4 -4
  14. package/lib/components/XDropdownDTFilter.js +2 -2
  15. package/lib/components/XDropdownForEntity.js +2 -2
  16. package/lib/components/XEditBrowse.js +4 -3
  17. package/lib/components/XExportRowsDialog.js +1 -1
  18. package/lib/components/XFieldSelector.js +4 -4
  19. package/lib/components/XFormDataTable2.js +13 -12
  20. package/lib/components/XFtsInput.d.ts +9 -0
  21. package/lib/components/XFtsInput.js +30 -0
  22. package/lib/components/XInput.js +2 -2
  23. package/lib/components/XInputDT.js +2 -2
  24. package/lib/components/XInputDateDT.js +1 -1
  25. package/lib/components/XInputFileList.js +6 -6
  26. package/lib/components/XInputIntervalBase.js +1 -1
  27. package/lib/components/XInputText.js +1 -1
  28. package/lib/components/XInputTextDT.js +3 -3
  29. package/lib/components/XInputTextarea.js +1 -1
  30. package/lib/components/XLazyDataTable.d.ts +11 -0
  31. package/lib/components/XLazyDataTable.js +58 -55
  32. package/lib/components/XSearchButton.js +4 -4
  33. package/lib/components/XSearchButtonDT.js +3 -3
  34. package/lib/components/XSearchButtonOld.js +5 -5
  35. package/lib/components/XToOneAssocButton.js +3 -3
  36. package/lib/components/XUtils.js +2 -1
  37. package/lib/components/XUtilsMetadata.d.ts +1 -19
  38. package/lib/components/XUtilsMetadata.js +8 -186
  39. package/lib/components/locale/x-en.json +4 -1
  40. package/lib/serverApi/ExportImportParam.d.ts +2 -1
  41. package/lib/serverApi/FindParam.d.ts +6 -0
  42. package/lib/{components → serverApi}/XUtilsConversions.d.ts +18 -1
  43. package/lib/serverApi/XUtilsConversions.js +330 -0
  44. package/lib/serverApi/XUtilsMetadataCommon.d.ts +30 -0
  45. package/lib/serverApi/XUtilsMetadataCommon.js +208 -0
  46. package/package.json +2 -2
  47. package/lib/components/XUtilsConversions.js +0 -177
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __values = (this && this.__values) || function(o) {
19
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20
+ if (m) return m.call(o);
21
+ if (o && typeof o.length === "number") return {
22
+ next: function () {
23
+ if (o && i >= o.length) o = void 0;
24
+ return { value: o && o[i++], done: !o };
25
+ }
26
+ };
27
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.XUtilsMetadataCommon = void 0;
31
+ var XUtilsCommon_1 = require("./XUtilsCommon");
32
+ /**
33
+ * spolocna funkcionalita pre entity metadata vyuzivana na frontend-e aj backend-e
34
+ * vznikla na zaklade XEntityMetadataService
35
+ * tato funkcionalita by este mohla ist do tried XEntity, XField
36
+ */
37
+ var XUtilsMetadataCommon = /** @class */ (function () {
38
+ function XUtilsMetadataCommon() {
39
+ }
40
+ XUtilsMetadataCommon.getXEntityMap = function () {
41
+ return XUtilsMetadataCommon.xEntityMap;
42
+ };
43
+ XUtilsMetadataCommon.setXEntityMap = function (xEntityMap) {
44
+ XUtilsMetadataCommon.xEntityMap = xEntityMap;
45
+ };
46
+ XUtilsMetadataCommon.getXEntity = function (entity) {
47
+ if (!XUtilsMetadataCommon.xEntityMap) {
48
+ throw "Unexpected error: XUtilsMetadataCommon.xEntityMap not initialised. Call XUtilsMetadataCommon.setXEntityMap first.";
49
+ }
50
+ var xEntity = XUtilsMetadataCommon.xEntityMap[entity];
51
+ if (xEntity === undefined) {
52
+ throw "Entity ".concat(entity, " was not found in entity metadata");
53
+ }
54
+ return xEntity;
55
+ };
56
+ XUtilsMetadataCommon.getXFieldBase = function (xEntity, field) {
57
+ // TODO - pozor, vo fieldMap su aj asociacie, trebalo by zmenit vytvaranie metadat tak aby tam tie asociacie neboli
58
+ return xEntity.fieldMap[field];
59
+ };
60
+ XUtilsMetadataCommon.getXField = function (xEntity, field) {
61
+ var xField = XUtilsMetadataCommon.getXFieldBase(xEntity, field);
62
+ if (xField === undefined) {
63
+ throw "Field ".concat(field, " was not found in entity ").concat(xEntity.name);
64
+ }
65
+ return xField;
66
+ };
67
+ XUtilsMetadataCommon.getXFieldByPath = function (xEntity, path) {
68
+ var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
69
+ if (restPath === null) {
70
+ return XUtilsMetadataCommon.getXField(xEntity, field);
71
+ }
72
+ else {
73
+ var xAssoc = XUtilsMetadataCommon.getXAssoc(xEntity, field);
74
+ var xAssocEntity = XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
75
+ return XUtilsMetadataCommon.getXFieldByPath(xAssocEntity, restPath);
76
+ }
77
+ };
78
+ XUtilsMetadataCommon.getXFieldByPathStr = function (entity, path) {
79
+ return XUtilsMetadataCommon.getXFieldByPath(XUtilsMetadataCommon.getXEntity(entity), path);
80
+ };
81
+ XUtilsMetadataCommon.getXAssocBase = function (xEntity, assocField) {
82
+ return xEntity.assocMap[assocField];
83
+ };
84
+ XUtilsMetadataCommon.getXAssocByPath = function (xEntity, path) {
85
+ var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
86
+ if (restPath === null) {
87
+ return XUtilsMetadataCommon.getXAssoc(xEntity, field);
88
+ }
89
+ else {
90
+ var xAssoc = XUtilsMetadataCommon.getXAssoc(xEntity, field);
91
+ var xAssocEntity = XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
92
+ return XUtilsMetadataCommon.getXAssocByPath(xAssocEntity, restPath);
93
+ }
94
+ };
95
+ // for path assoc1.assoc2.field returns assoc2 (last assoc before field)
96
+ XUtilsMetadataCommon.getLastXAssocByPath = function (xEntity, path) {
97
+ var pathToAssoc = XUtilsCommon_1.XUtilsCommon.getPathToAssoc(path);
98
+ return XUtilsMetadataCommon.getXAssocByPath(xEntity, pathToAssoc);
99
+ };
100
+ XUtilsMetadataCommon.getXAssocToOne = function (xEntity, assocField) {
101
+ return XUtilsMetadataCommon.getXAssoc(xEntity, assocField, ["many-to-one", "one-to-one"]);
102
+ };
103
+ XUtilsMetadataCommon.getXAssocToMany = function (xEntity, assocField) {
104
+ return XUtilsMetadataCommon.getXAssoc(xEntity, assocField, ["one-to-many", "many-to-many"]);
105
+ };
106
+ XUtilsMetadataCommon.getXAssocToOneByAssocEntity = function (xEntity, assocEntityName) {
107
+ return XUtilsMetadataCommon.getXAssocByAssocEntity(xEntity, assocEntityName, ["many-to-one", "one-to-one"]);
108
+ };
109
+ XUtilsMetadataCommon.getXAssocToManyByAssocEntity = function (xEntity, assocEntityName) {
110
+ return XUtilsMetadataCommon.getXAssocByAssocEntity(xEntity, assocEntityName, ["one-to-many", "many-to-many"]);
111
+ };
112
+ XUtilsMetadataCommon.getXEntityForAssocToOne = function (xEntity, assocField) {
113
+ return XUtilsMetadataCommon.getXEntityForAssoc(XUtilsMetadataCommon.getXAssocToOne(xEntity, assocField));
114
+ };
115
+ XUtilsMetadataCommon.getXEntityForAssocToMany = function (xEntity, assocField) {
116
+ return XUtilsMetadataCommon.getXEntityForAssoc(XUtilsMetadataCommon.getXAssocToMany(xEntity, assocField));
117
+ };
118
+ XUtilsMetadataCommon.getXFieldList = function (xEntity) {
119
+ var e_1, _a;
120
+ var xFieldList = [];
121
+ try {
122
+ for (var _b = __values(Object.entries(xEntity.fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
123
+ var _d = __read(_c.value, 2), key = _d[0], xField = _d[1];
124
+ // assoc fieldy sa nachadzaju aj v xEntity.fieldMap ako typ number (netusim preco), preto ich vyfiltrujeme
125
+ if (xEntity.assocMap[xField.name] === undefined) {
126
+ xFieldList.push(xField);
127
+ }
128
+ }
129
+ }
130
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
131
+ finally {
132
+ try {
133
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
134
+ }
135
+ finally { if (e_1) throw e_1.error; }
136
+ }
137
+ return xFieldList;
138
+ };
139
+ XUtilsMetadataCommon.getXAssocList = function (xEntity, relationTypeList) {
140
+ var e_2, _a;
141
+ //const xAssocList: XAssoc[] = Array.from(xEntity.assocMap, (v: XAssoc, k: string) => v);
142
+ var xAssocList = [];
143
+ try {
144
+ for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
145
+ var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
146
+ if (relationTypeList === undefined || relationTypeList.includes(xAssoc.relationType)) {
147
+ xAssocList.push(xAssoc);
148
+ }
149
+ }
150
+ }
151
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
152
+ finally {
153
+ try {
154
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
155
+ }
156
+ finally { if (e_2) throw e_2.error; }
157
+ }
158
+ return xAssocList;
159
+ };
160
+ XUtilsMetadataCommon.getXAssoc = function (xEntity, assocField, relationTypeList) {
161
+ var xAssoc = XUtilsMetadataCommon.getXAssocBase(xEntity, assocField);
162
+ if (xAssoc === undefined) {
163
+ throw "Assoc ".concat(assocField, " was not found in entity = ").concat(xEntity.name);
164
+ }
165
+ // relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
166
+ if (relationTypeList !== undefined && !relationTypeList.includes(xAssoc.relationType)) {
167
+ throw "Assoc ".concat(assocField, " in entity ").concat(xEntity.name, " is of type ").concat(xAssoc.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
168
+ }
169
+ return xAssoc;
170
+ };
171
+ XUtilsMetadataCommon.getXAssocByAssocEntity = function (xEntity, assocEntityName, relationTypeList) {
172
+ var e_3, _a;
173
+ var xAssocFound = undefined;
174
+ try {
175
+ for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
176
+ var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
177
+ if (xAssoc.entityName === assocEntityName) {
178
+ if (xAssocFound === undefined) {
179
+ xAssocFound = xAssoc;
180
+ }
181
+ else {
182
+ throw "In entity ".concat(xEntity.name, " found more then 1 assoc for assocEntityName = ").concat(assocEntityName);
183
+ }
184
+ }
185
+ }
186
+ }
187
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
188
+ finally {
189
+ try {
190
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
191
+ }
192
+ finally { if (e_3) throw e_3.error; }
193
+ }
194
+ if (xAssocFound === undefined) {
195
+ throw "Assoc for assocEntityName = ".concat(assocEntityName, " not found in entity ").concat(xEntity.name);
196
+ }
197
+ // relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
198
+ if (relationTypeList !== undefined && !relationTypeList.includes(xAssocFound.relationType)) {
199
+ throw "Assoc for assocEntityName = ".concat(assocEntityName, " in entity ").concat(xEntity.name, " is of type ").concat(xAssocFound.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
200
+ }
201
+ return xAssocFound;
202
+ };
203
+ XUtilsMetadataCommon.getXEntityForAssoc = function (xAssoc) {
204
+ return XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
205
+ };
206
+ return XUtilsMetadataCommon;
207
+ }());
208
+ exports.XUtilsMetadataCommon = XUtilsMetadataCommon;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.11.1",
3
+ "version": "1.13.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",
@@ -28,7 +28,7 @@
28
28
  "@testing-library/react": "^14.0.0",
29
29
  "@testing-library/user-event": "^14.4.3",
30
30
  "@types/jest": "^29.5.0",
31
- "@types/lodash": "^4.14.191",
31
+ "@types/lodash": "^4.14.202",
32
32
  "@types/node": "^18.15.3",
33
33
  "@types/react": "^18.0.28",
34
34
  "@types/react-dom": "^18.0.11",
@@ -1,177 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.intervalAsUI = exports.intervalFromUI = exports.datetimeFormatUI = exports.dateFormatCalendar = exports.dateFormatUI = exports.timeFromModel = exports.datetimeAsUI = exports.dateAsUI = exports.dateFromModel = exports.numberFromModel = exports.numberAsUI = exports.numberFromUI = exports.stringAsUI = exports.stringFromUI = void 0;
4
- var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
5
- function stringFromUI(stringValue) {
6
- var value;
7
- if (stringValue === '') {
8
- value = null;
9
- }
10
- else {
11
- value = stringValue;
12
- }
13
- return value;
14
- }
15
- exports.stringFromUI = stringFromUI;
16
- function stringAsUI(value) {
17
- return value !== null ? value : "";
18
- }
19
- exports.stringAsUI = stringAsUI;
20
- function numberFromUI(stringValue) {
21
- var value;
22
- if (stringValue === '') {
23
- value = null;
24
- }
25
- else {
26
- value = parseInt(stringValue, 10);
27
- }
28
- return value;
29
- }
30
- exports.numberFromUI = numberFromUI;
31
- function numberAsUI(value, fractionDigits) {
32
- if (fractionDigits === undefined) {
33
- fractionDigits = 2; // default
34
- }
35
- if (value !== null) {
36
- return value.toLocaleString('de-DE', { style: 'decimal', minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits });
37
- }
38
- else {
39
- return "";
40
- }
41
- }
42
- exports.numberAsUI = numberAsUI;
43
- // v modeli na klientovi by mal byt vzdy number, teraz je tam niekedy string (z json-u zo servera) a niekedy number (z komponentu)
44
- // provizorne zatial takato konverzia
45
- function numberFromModel(value) {
46
- var numberValue = null;
47
- if (typeof value === 'string') {
48
- numberValue = parseFloat(value);
49
- }
50
- else if (typeof value === 'number') {
51
- numberValue = value;
52
- }
53
- return numberValue;
54
- }
55
- exports.numberFromModel = numberFromModel;
56
- // v modeli na klientovi by mal byt vzdy Date, teraz je tam niekedy string (z json-u zo servera) a niekedy Date (z komponentu)
57
- // provizorne zatial takato konverzia
58
- function dateFromModel(value) {
59
- var dateValue = null;
60
- if (typeof value === 'string') {
61
- dateValue = new Date(value);
62
- }
63
- else if (typeof value === 'object' && value instanceof Date) {
64
- dateValue = value;
65
- }
66
- return dateValue;
67
- }
68
- exports.dateFromModel = dateFromModel;
69
- function dateAsUI(value) {
70
- if (value !== null) {
71
- return (0, XUtilsCommon_1.dateFormat)(value, dateFormatUI());
72
- }
73
- else {
74
- return "";
75
- }
76
- }
77
- exports.dateAsUI = dateAsUI;
78
- function datetimeAsUI(value) {
79
- if (value !== null) {
80
- return (0, XUtilsCommon_1.dateFormat)(value, datetimeFormatUI());
81
- }
82
- else {
83
- return "";
84
- }
85
- }
86
- exports.datetimeAsUI = datetimeAsUI;
87
- // provizorne zatial takato konverzia
88
- function timeFromModel(value) {
89
- var timeValue = null;
90
- if (typeof value === 'string') {
91
- // ak prichadza cas priamo z databazy, pride '19:30:00'
92
- // ak prichadza reloadnuty objekt (napr. cez webservis saveRow), pride '2021-06-07 19:30:00'
93
- var rowDataCasStr = value;
94
- if (rowDataCasStr.length < 10) {
95
- // mame '19:30:00' -> pridame hociaky rok aby sme skonvertovali na validny Date
96
- rowDataCasStr = '1970-01-01 ' + rowDataCasStr;
97
- }
98
- // na safari nefunguje konverzia new Date('2021-06-07 19:30:00') - vrati NaN
99
- // preto string prehodime na '2021-06-07T19:30:00+01:00'
100
- // 19:30:00 je cas z timezony Central Europe (taka je nastavena na nodejs)), preto oznacime tento cas touto timezonou
101
- // (spravne riesenie je posielat time cez json vzdy vo formate '2021-06-07T18:30:00Z', v tomto formate chodia aj datetime atributy)
102
- rowDataCasStr = rowDataCasStr.replace(' ', 'T');
103
- if (!rowDataCasStr.endsWith('Z') && rowDataCasStr.indexOf('+') === -1) {
104
- rowDataCasStr += '+01:00'; // Central Europe timezone
105
- }
106
- timeValue = new Date(rowDataCasStr);
107
- }
108
- else if (typeof value === 'object' && value instanceof Date) {
109
- timeValue = value;
110
- }
111
- return timeValue;
112
- }
113
- exports.timeFromModel = timeFromModel;
114
- function dateFormatUI() {
115
- return "dd.mm.yyyy";
116
- }
117
- exports.dateFormatUI = dateFormatUI;
118
- function dateFormatCalendar() {
119
- return "dd.mm.yy";
120
- }
121
- exports.dateFormatCalendar = dateFormatCalendar;
122
- function datetimeFormatUI() {
123
- return "dd.mm.yyyy HH:MM:ss";
124
- }
125
- exports.datetimeFormatUI = datetimeFormatUI;
126
- function intervalFromUI(valueString) {
127
- // convert e.target.value (e.g. 10:29) into IPostgresInterval (e.g. {hours: 10, minutes: 29})
128
- // if stringValue is invalid, returns undefined
129
- var valueInterval = undefined;
130
- if (valueString === '') {
131
- valueInterval = null;
132
- }
133
- else {
134
- var posColon = valueString.indexOf(':');
135
- if (posColon === -1) {
136
- var minutes = parseInt(valueString);
137
- if (!isNaN(minutes)) {
138
- var hours = Math.floor(minutes / 60);
139
- minutes = minutes - (hours * 60);
140
- valueInterval = { hours: hours, minutes: minutes };
141
- }
142
- }
143
- else {
144
- var hours = parseInt(valueString.substring(0, posColon));
145
- var minutes = parseInt(valueString.substring(posColon + 1));
146
- if (!isNaN(hours) && !isNaN(minutes)) {
147
- if (minutes >= 60) {
148
- var hoursFromMinutes = Math.floor(minutes / 60);
149
- hours += hoursFromMinutes;
150
- minutes = minutes - (hoursFromMinutes * 60);
151
- }
152
- valueInterval = { hours: hours, minutes: minutes };
153
- }
154
- }
155
- }
156
- return valueInterval;
157
- }
158
- exports.intervalFromUI = intervalFromUI;
159
- function intervalAsUI(valueInterval) {
160
- var _a, _b;
161
- // conversion e.g. {hours: 10, minutes: 29} => '10:29'
162
- var valueString;
163
- if (valueInterval !== null) {
164
- var hours = (_a = valueInterval.hours) !== null && _a !== void 0 ? _a : 0;
165
- var minutes = (_b = valueInterval.minutes) !== null && _b !== void 0 ? _b : 0;
166
- //const seconds: number = value.seconds ?? 0;
167
- if (valueInterval.days) {
168
- hours += valueInterval.days * 24;
169
- }
170
- valueString = "".concat(hours.toString(), ":").concat(minutes.toString().padStart(2, '0'));
171
- }
172
- else {
173
- valueString = ''; // null
174
- }
175
- return valueString;
176
- }
177
- exports.intervalAsUI = intervalAsUI;