@fctc/interface-logic 5.2.4 → 5.2.5

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 (53) hide show
  1. package/dist/{chunk-Q5YXX4OR.js → chunk-CCTDGAMA.js} +11 -11
  2. package/dist/{chunk-WBGK2SHU.js → chunk-COC7NGXP.js} +1 -0
  3. package/dist/{chunk-6ARYI77N.mjs → chunk-F2VAAEVB.mjs} +2 -2
  4. package/dist/{chunk-OV7EKGYM.mjs → chunk-F4RE57FT.mjs} +171 -326
  5. package/dist/{chunk-C5QQGBN4.js → chunk-FWBYTZIV.js} +6 -6
  6. package/dist/{chunk-BPJZ3QRN.mjs → chunk-HQVNK2EW.mjs} +107 -771
  7. package/dist/{chunk-VBYRP2P7.mjs → chunk-Q3Y6RCJ4.mjs} +1 -0
  8. package/dist/{chunk-5STZNSW4.js → chunk-U2COUTK5.js} +187 -347
  9. package/dist/{chunk-JDXUTKMX.js → chunk-U4Q3MW45.js} +113 -800
  10. package/dist/{chunk-QOXPJWSN.mjs → chunk-VBVNP77T.mjs} +1 -1
  11. package/dist/{chunk-RPWKWEMA.js → chunk-WTPKTZQC.js} +2 -2
  12. package/dist/{chunk-ACSPOGTI.mjs → chunk-ZDXEWQQD.mjs} +5 -5
  13. package/dist/configs.js +3 -4
  14. package/dist/configs.mjs +2 -3
  15. package/dist/constants.d.mts +2 -1
  16. package/dist/constants.d.ts +2 -1
  17. package/dist/constants.js +17 -17
  18. package/dist/constants.mjs +1 -1
  19. package/dist/environment.d.mts +1 -1
  20. package/dist/environment.d.ts +1 -1
  21. package/dist/environment.js +6 -7
  22. package/dist/environment.mjs +3 -4
  23. package/dist/hooks.d.mts +7 -23
  24. package/dist/hooks.d.ts +7 -23
  25. package/dist/hooks.js +160 -177
  26. package/dist/hooks.mjs +5 -6
  27. package/dist/index.d.mts +4 -10
  28. package/dist/index.d.ts +4 -10
  29. package/dist/index.js +227 -636
  30. package/dist/index.mjs +6 -7
  31. package/dist/{local-storage-BPvoMGYJ.d.mts → local-storage-AbiOQTLK.d.mts} +1 -1
  32. package/dist/{local-storage-BPvoMGYJ.d.ts → local-storage-AbiOQTLK.d.ts} +1 -1
  33. package/dist/models.js +3 -3
  34. package/dist/models.mjs +2 -2
  35. package/dist/provider.d.mts +4 -12
  36. package/dist/provider.d.ts +4 -12
  37. package/dist/provider.js +14 -19
  38. package/dist/provider.mjs +5 -6
  39. package/dist/services.d.mts +6 -10
  40. package/dist/services.d.ts +6 -10
  41. package/dist/services.js +16 -17
  42. package/dist/services.mjs +5 -6
  43. package/dist/utils.d.mts +33 -61
  44. package/dist/utils.d.ts +33 -61
  45. package/dist/utils.js +26 -95
  46. package/dist/utils.mjs +1 -2
  47. package/package.json +15 -29
  48. package/dist/chunk-6LSKTACC.js +0 -687
  49. package/dist/chunk-B432GFRR.mjs +0 -606
  50. package/dist/store.d.mts +0 -382
  51. package/dist/store.d.ts +0 -382
  52. package/dist/store.js +0 -326
  53. package/dist/store.mjs +0 -1
@@ -1,314 +1,80 @@
1
- import moment from 'moment';
2
- import { useState, useEffect } from 'react';
3
-
4
- // src/utils/error-handler.ts
5
- var WesapError = class extends Error {
6
- code;
7
- constructor(message, code) {
8
- super(message);
9
- this.code = code;
10
- }
11
- };
12
- function handleError(error, env) {
13
- if (error instanceof WesapError) {
14
- env.services.notification.error(error.message);
15
- } else {
16
- env.services.notification.error("An unexpected error occurred");
17
- }
18
- }
19
- var formatCurrency = (amount, currency = "USD") => {
20
- const formatter = new Intl.NumberFormat("vi-VN", {
21
- style: "currency",
22
- currency,
23
- minimumFractionDigits: 0
24
- });
25
- return formatter.format(amount).replaceAll(".", ",");
26
- };
27
- var formatDate = (date, locale = "en-US") => {
28
- return new Intl.DateTimeFormat(locale).format(new Date(date));
29
- };
30
- var validateAndParseDate = (input, isDateTime = false) => {
31
- if (!input || typeof input !== "string") return null;
32
- const cleanInput = input.replace(/[^0-9-\/:\s]/g, "");
33
- const dateFormat = "YYYY-MM-DD";
34
- const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
35
- const currentDay = moment().format("DD");
36
- const currentMonth = moment().format("MM");
37
- const currentYear = moment().format("YYYY");
38
- const defaultTime = "00:00:00";
39
- const maxYear = parseInt(currentYear) + 10;
40
- const isValidDate = (day, month, year) => {
41
- const date = moment(`${day}-${month}-${year}`, "DD-MM-YYYY", true);
42
- return date.isValid();
1
+ // src/utils/storage/local-storage.ts
2
+ var localStorageUtils = () => {
3
+ const setToken = async (access_token) => {
4
+ localStorage.setItem("accessToken", access_token);
43
5
  };
44
- const isValidTime = (hour, minute = "00", second = "00") => {
45
- const h = parseInt(hour, 10);
46
- const m = parseInt(minute, 10);
47
- const s = parseInt(second, 10);
48
- return h >= 0 && h <= 23 && m >= 0 && m <= 59 && s >= 0 && s <= 59;
6
+ const setRefreshToken = async (refresh_token) => {
7
+ localStorage.setItem("refreshToken", refresh_token);
49
8
  };
50
- const formatOutput = (day, month, year, time = defaultTime) => {
51
- let result = moment(
52
- `${day}-${month}-${year} ${time}`,
53
- "DD-MM-YYYY HH:mm:ss"
54
- );
55
- if (!result.isValid()) return null;
56
- if (isDateTime) {
57
- result = result.subtract(7, "hours");
58
- return result.format(dateTimeFormat);
59
- }
60
- return result.format(dateFormat);
9
+ const getAccessToken = async () => {
10
+ return localStorage.getItem("accessToken");
11
+ };
12
+ const getRefreshToken = async () => {
13
+ return localStorage.getItem("refreshToken");
14
+ };
15
+ const clearToken = async () => {
16
+ localStorage.removeItem("accessToken");
17
+ localStorage.removeItem("refreshToken");
18
+ };
19
+ return {
20
+ setToken,
21
+ setRefreshToken,
22
+ getAccessToken,
23
+ getRefreshToken,
24
+ clearToken
61
25
  };
62
- if (isDateTime && input.match(
63
- /^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}\s+\d{1,2}(:\d{1,2}(:\d{1,2})?)?$/
64
- )) {
65
- const [datePart, timePart] = input.split(/\s+/);
66
- const dateParts = datePart.split(/[\/-]/);
67
- const timeParts = timePart.split(":");
68
- const day = dateParts[0].padStart(2, "0");
69
- const month = dateParts[1].padStart(2, "0");
70
- const year = dateParts[2].length <= 2 ? `20${dateParts[2].padStart(2, "0")}` : dateParts[2].padStart(4, "0");
71
- const hour = timeParts[0].padStart(2, "0");
72
- const minute = timeParts[1] ? timeParts[1].padStart(2, "0") : "00";
73
- const second = timeParts[2] ? timeParts[2].padStart(2, "0") : "00";
74
- if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
75
- let result = moment(
76
- `${day}-${month}-${year} ${hour}:${minute}:${second}`,
77
- "DD-MM-YYYY HH:mm:ss"
78
- );
79
- if (!result.isValid()) return null;
80
- result = result.subtract(7, "hours");
81
- return result.format(dateTimeFormat);
82
- }
83
- return null;
84
- }
85
- if (cleanInput.match(/^\d{4}-\d{2}-\d{2}$/)) {
86
- const [year, month, day] = cleanInput.split("-");
87
- if (isValidDate(day, month, year)) {
88
- return formatOutput(day, month, year);
89
- }
90
- return null;
91
- }
92
- if (cleanInput.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/)) {
93
- const [day, month, year] = cleanInput.split("/");
94
- const paddedDay = day.padStart(2, "0");
95
- const paddedMonth = month.padStart(2, "0");
96
- const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
97
- if (isValidDate(paddedDay, paddedMonth, fullYear)) {
98
- return formatOutput(paddedDay, paddedMonth, fullYear);
99
- }
100
- return null;
101
- }
102
- if (cleanInput.match(/^\d{1,2}-\d{1,2}-\d{2,4}$/)) {
103
- const [day, month, year] = cleanInput.split("-");
104
- const paddedDay = day.padStart(2, "0");
105
- const paddedMonth = month.padStart(2, "0");
106
- const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
107
- if (isValidDate(paddedDay, paddedMonth, fullYear)) {
108
- return formatOutput(paddedDay, paddedMonth, fullYear);
109
- }
110
- return null;
111
- }
112
- if (cleanInput.match(/^\d{1,2}[\/-]\d{1,2}$/)) {
113
- const [day, month] = cleanInput.split(/[\/-]/);
114
- const paddedDay = day.padStart(2, "0");
115
- const paddedMonth = month.padStart(2, "0");
116
- if (isValidDate(paddedDay, paddedMonth, currentYear)) {
117
- return formatOutput(paddedDay, paddedMonth, currentYear);
118
- }
119
- return null;
120
- }
121
- if (cleanInput.match(/^\d{4}$/)) {
122
- const num = parseInt(cleanInput, 10);
123
- if (num >= 2e3 && num <= maxYear) {
124
- if (isValidDate(currentDay, currentMonth, num.toString())) {
125
- return formatOutput(currentDay, currentMonth, num.toString());
126
- }
127
- return null;
128
- }
129
- const day = cleanInput.slice(0, 2);
130
- const month = cleanInput.slice(2, 4);
131
- if (isValidDate(day, month, currentYear)) {
132
- return formatOutput(day, month, currentYear);
133
- }
134
- return null;
135
- }
136
- if (cleanInput.startsWith("-") && /^\-\d+$/.test(cleanInput)) {
137
- const daysToSubtract = Math.abs(parseInt(cleanInput, 10));
138
- let result = moment().subtract(daysToSubtract, "days");
139
- if (isDateTime) {
140
- result = result.subtract(7, "hours");
141
- }
142
- if (result.isValid()) {
143
- return isDateTime ? result.format(dateTimeFormat) : result.format(dateFormat);
144
- }
145
- return null;
146
- }
147
- if (input.match(/^\d{1,2}[^0-9-\/]+\d{1,2}[^0-9-\/]+\d{2,4}.*$/)) {
148
- const parts = input.split(/[^0-9-\/]+/).filter(Boolean);
149
- const day = parts[0].padStart(2, "0");
150
- const month = parts[1].padStart(2, "0");
151
- let year = parts[2];
152
- year = year.length === 2 ? `20${year}` : year.padStart(4, "0");
153
- if (isValidDate(day, month, year)) {
154
- return formatOutput(day, month, year);
155
- }
156
- return null;
157
- }
158
- if (isDateTime) {
159
- if (cleanInput.length === 9) {
160
- const day = cleanInput.slice(0, 2);
161
- const month = cleanInput.slice(2, 4);
162
- const year = cleanInput.slice(4, 8);
163
- const hour = cleanInput.slice(8, 9).padStart(2, "0");
164
- if (isValidDate(day, month, year) && isValidTime(hour)) {
165
- let result = moment(
166
- `${day}-${month}-${year} ${hour}:00:00`,
167
- "DD-MM-YYYY HH:mm:ss"
168
- );
169
- if (!result.isValid()) return null;
170
- result = result.subtract(7, "hours");
171
- return result.format(dateTimeFormat);
172
- }
173
- return null;
174
- }
175
- if (cleanInput.length === 10) {
176
- const day = cleanInput.slice(0, 2);
177
- const month = cleanInput.slice(2, 4);
178
- const year = cleanInput.slice(4, 8);
179
- const hour = cleanInput.slice(8, 10);
180
- if (isValidDate(day, month, year) && isValidTime(hour)) {
181
- let result = moment(
182
- `${day}-${month}-${year} ${hour}:00:00`,
183
- "DD-MM-YYYY HH:mm:ss"
184
- );
185
- if (!result.isValid()) return null;
186
- result = result.subtract(7, "hours");
187
- return result.format(dateTimeFormat);
188
- }
189
- return null;
190
- }
191
- if (cleanInput.length === 11) {
192
- const day = cleanInput.slice(0, 2);
193
- const month = cleanInput.slice(2, 4);
194
- const year = cleanInput.slice(4, 8);
195
- const hour = cleanInput.slice(8, 10);
196
- const minute = cleanInput.slice(10, 11).padStart(2, "0");
197
- if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
198
- let result = moment(
199
- `${day}-${month}-${year} ${hour}:${minute}:00`,
200
- "DD-MM-YYYY HH:mm:ss"
201
- );
202
- if (!result.isValid()) return null;
203
- result = result.subtract(7, "hours");
204
- return result.format(dateTimeFormat);
205
- }
206
- return null;
207
- }
208
- if (cleanInput.length === 12) {
209
- const day = cleanInput.slice(0, 2);
210
- const month = cleanInput.slice(2, 4);
211
- const year = cleanInput.slice(4, 8);
212
- const hour = cleanInput.slice(8, 10);
213
- const minute = cleanInput.slice(10, 12);
214
- if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
215
- let result = moment(
216
- `${day}-${month}-${year} ${hour}:${minute}:00`,
217
- "DD-MM-YYYY HH:mm:ss"
218
- );
219
- if (!result.isValid()) return null;
220
- result = result.subtract(7, "hours");
221
- return result.format(dateTimeFormat);
222
- }
223
- return null;
224
- }
225
- if (cleanInput.length === 13) {
226
- const day = cleanInput.slice(0, 2);
227
- const month = cleanInput.slice(2, 4);
228
- const year = cleanInput.slice(4, 8);
229
- const hour = cleanInput.slice(8, 10);
230
- const minute = cleanInput.slice(10, 12);
231
- const second = cleanInput.slice(12, 13).padStart(2, "0");
232
- if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
233
- let result = moment(
234
- `${day}-${month}-${year} ${hour}:${minute}:${second}`,
235
- "DD-MM-YYYY HH:mm:ss"
236
- );
237
- if (!result.isValid()) return null;
238
- result = result.subtract(7, "hours");
239
- return result.format(dateTimeFormat);
240
- }
241
- return null;
242
- }
243
- if (cleanInput.length === 14) {
244
- const day = cleanInput.slice(0, 2);
245
- const month = cleanInput.slice(2, 4);
246
- const year = cleanInput.slice(4, 8);
247
- const hour = cleanInput.slice(8, 10);
248
- const minute = cleanInput.slice(10, 12);
249
- const second = cleanInput.slice(12, 14);
250
- if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
251
- let result = moment(
252
- `${day}-${month}-${year} ${hour}:${minute}:${second}`,
253
- "DD-MM-YYYY HH:mm:ss"
254
- );
255
- if (!result.isValid()) return null;
256
- result = result.subtract(7, "hours");
257
- return result.format(dateTimeFormat);
258
- }
259
- return null;
260
- }
261
- }
262
- const len = cleanInput.length;
263
- if (len === 1 || len === 2) {
264
- const paddedDay = cleanInput.padStart(2, "0");
265
- if (isValidDate(paddedDay, currentMonth, currentYear)) {
266
- return formatOutput(paddedDay, currentMonth, currentYear);
267
- }
268
- return null;
269
- }
270
- if (len === 3) {
271
- const day = cleanInput.slice(0, 2);
272
- const month = cleanInput.slice(2, 3).padStart(2, "0");
273
- if (isValidDate(day, month, currentYear)) {
274
- return formatOutput(day, month, currentYear);
275
- }
276
- return null;
277
- }
278
- if (len === 6) {
279
- const day = cleanInput.slice(0, 2);
280
- const month = cleanInput.slice(2, 4);
281
- let year = cleanInput.slice(4, 6);
282
- year = `20${year}`;
283
- if (parseInt(month) > 12) {
284
- if (isValidDate(day, currentMonth, currentYear)) {
285
- return formatOutput(day, currentMonth, currentYear);
286
- }
287
- return null;
288
- }
289
- if (isValidDate(day, month, year)) {
290
- return formatOutput(day, month, year);
291
- }
292
- return null;
293
- }
294
- if (len === 7) {
295
- return null;
296
- }
297
- if (len === 8) {
298
- const day = cleanInput.slice(0, 2);
299
- const month = cleanInput.slice(2, 4);
300
- const year = cleanInput.slice(4, 8);
301
- if (isValidDate(day, month, year)) {
302
- return formatOutput(day, month, year);
303
- }
304
- return null;
305
- }
306
- if (len > 8 && !isDateTime) {
307
- return null;
308
- }
309
- return null;
310
26
  };
311
27
 
28
+ // src/utils/storage/session-storage.ts
29
+ var sessionStorageUtils = /* @__PURE__ */ (() => {
30
+ const getMenuFocus = () => {
31
+ const menuFocus = sessionStorage.getItem("menuFocus");
32
+ return menuFocus ? JSON.parse(menuFocus) : {
33
+ id: void 0,
34
+ service: ""
35
+ };
36
+ };
37
+ const setMenuFocus = (menuTree) => {
38
+ sessionStorage.setItem("menuFocus", JSON.stringify({ ...menuTree }));
39
+ };
40
+ const getActionData = () => {
41
+ const actionData = sessionStorage.getItem("actionData");
42
+ return actionData ? JSON.parse(actionData) : {};
43
+ };
44
+ const setActionData = (actData) => {
45
+ sessionStorage.setItem("actionData", JSON.stringify(actData));
46
+ };
47
+ const getViewData = () => {
48
+ const viewData = sessionStorage.getItem("viewData");
49
+ return viewData ? JSON.parse(viewData) : {};
50
+ };
51
+ const getBrowserSession = () => {
52
+ const actionData = sessionStorage.getItem("browserSession");
53
+ return actionData ? JSON.parse(actionData) : null;
54
+ };
55
+ const setViewData = (viewData) => {
56
+ sessionStorage.setItem("viewData", JSON.stringify(viewData));
57
+ };
58
+ const getXNode = () => {
59
+ const xNode = sessionStorage.getItem("xNode");
60
+ return xNode;
61
+ };
62
+ const setXNode = (xNode) => {
63
+ sessionStorage.setItem("xNode", xNode);
64
+ };
65
+ return {
66
+ getMenuFocus,
67
+ setMenuFocus,
68
+ setActionData,
69
+ getActionData,
70
+ getViewData,
71
+ setViewData,
72
+ getBrowserSession,
73
+ getXNode,
74
+ setXNode
75
+ };
76
+ })();
77
+
312
78
  // src/utils/domain/py_tokenizer.ts
313
79
  var TokenizerError = class extends Error {
314
80
  };
@@ -463,7 +229,7 @@ var IntNumber = DecNumber;
463
229
  var Exponent = "[eE][+-]?\\d+";
464
230
  var PointFloat = group(`\\d+\\.\\d*(${Exponent})?`, `\\.\\d+(${Exponent})?`);
465
231
  var FloatNumber = group(PointFloat, `\\d+${Exponent}`);
466
- var Number2 = group(FloatNumber, IntNumber);
232
+ var Number = group(FloatNumber, IntNumber);
467
233
  var Operator = group(
468
234
  "\\*\\*=?",
469
235
  ">>=?",
@@ -481,8 +247,8 @@ var ContStr = group(
481
247
  "([uU])?'([^\\n'\\\\]*(?:\\\\.[^\\n'\\\\]*)*)'",
482
248
  '([uU])?"([^\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*)"'
483
249
  );
484
- var PseudoToken = Whitespace + group(Number2, Funny, ContStr, Name);
485
- var NumberPattern = new RegExp("^" + Number2 + "$");
250
+ var PseudoToken = Whitespace + group(Number, Funny, ContStr, Name);
251
+ var NumberPattern = new RegExp("^" + Number + "$");
486
252
  var StringPattern = new RegExp("^" + ContStr + "$");
487
253
  var NamePattern = new RegExp("^" + Name + "$");
488
254
  var strip = new RegExp("^" + Whitespace);
@@ -2110,6 +1876,18 @@ function evaluateBooleanExpr(expr, context = {}) {
2110
1876
  }
2111
1877
 
2112
1878
  // src/utils/domain/context.ts
1879
+ function makeContext(contexts, initialEvaluationContext) {
1880
+ const evaluationContext = Object.assign({}, initialEvaluationContext);
1881
+ const context = {};
1882
+ for (let ctx of contexts) {
1883
+ if (ctx !== "") {
1884
+ ctx = typeof ctx === "string" ? evaluateExpr(ctx, evaluationContext) : ctx || {};
1885
+ Object.assign(context, ctx);
1886
+ Object.assign(evaluationContext, context);
1887
+ }
1888
+ }
1889
+ return context;
1890
+ }
2113
1891
  function evalPartialContext(_context, evaluationContext = {}) {
2114
1892
  const ast = parseExpr(_context);
2115
1893
  const context = {};
@@ -2264,6 +2042,12 @@ var Domain = class _Domain {
2264
2042
  }
2265
2043
  }
2266
2044
  };
2045
+ function evalDomain(modifier, evalContext) {
2046
+ if (modifier && typeof modifier !== "boolean") {
2047
+ modifier = new Domain(modifier).contains(evalContext);
2048
+ }
2049
+ return Boolean(modifier);
2050
+ }
2267
2051
  var TRUE_LEAF = [1, "=", 1];
2268
2052
  var FALSE_LEAF = [0, "=", 1];
2269
2053
  var TRUE_DOMAIN = new Domain([TRUE_LEAF]);
@@ -2489,6 +2273,13 @@ var matchDomains = (context, domains) => {
2489
2273
  } else return checkDomain(context, domains);
2490
2274
  return false;
2491
2275
  };
2276
+
2277
+ // src/utils/function/index.ts
2278
+ var domainHelper = {
2279
+ checkDomain,
2280
+ matchDomains,
2281
+ Domain
2282
+ };
2492
2283
  var evalJSONContext = (_context, context = {}) => {
2493
2284
  try {
2494
2285
  return evalPartialContext(
@@ -2533,316 +2324,20 @@ var formatSortingString = (input) => {
2533
2324
  return `${key} ${sortOrder}`;
2534
2325
  }).join(", ");
2535
2326
  };
2536
- var domainHelper = {
2537
- checkDomain,
2538
- matchDomains,
2539
- Domain
2540
- };
2541
2327
  var toQueryString = (params) => {
2542
2328
  return Object.keys(params).map(
2543
2329
  (key) => encodeURIComponent(key) + "=" + encodeURIComponent(params[key].toString())
2544
2330
  ).join("&");
2545
2331
  };
2546
- var convertFloatToTime = (floatValue) => {
2547
- const hours = Math.floor(floatValue);
2548
- const minutes = Math.round((floatValue - hours) * 60);
2549
- const formattedHours = String(hours).padStart(2, "0");
2550
- const formattedMinutes = String(minutes).padStart(2, "0");
2551
- return `${formattedHours}:${formattedMinutes}`;
2552
- };
2553
- var convertTimeToFloat = (timeString) => {
2554
- const [hours, minutes] = timeString.split(":").map(Number);
2555
- return hours + minutes / 60;
2556
- };
2557
- var stringToColor = (name, id) => {
2558
- const combined = name + id / 2;
2559
- let hash = 0;
2560
- for (let i = 0; i < combined.length; i++) {
2561
- hash = combined.charCodeAt(i) + ((hash << 5) - hash);
2562
- }
2563
- const r = hash >> 16 & 255;
2564
- const g = hash >> 8 & 255;
2565
- const b = hash & 255;
2566
- const rNorm = r / 255;
2567
- const gNorm = g / 255;
2568
- const bNorm = b / 255;
2569
- const max = Math.max(rNorm, gNorm, bNorm);
2570
- const min = Math.min(rNorm, gNorm, bNorm);
2571
- const delta = max - min;
2572
- let h = 0;
2573
- if (delta !== 0) {
2574
- if (max === rNorm) h = (gNorm - bNorm) / delta % 6;
2575
- else if (max === gNorm) h = (bNorm - rNorm) / delta + 2;
2576
- else h = (rNorm - gNorm) / delta + 4;
2577
- }
2578
- h = Math.round(h * 60);
2579
- if (h < 0) h += 360;
2580
- let l = (max + min) / 2;
2581
- let s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
2582
- s = Math.min(1, s * 1.8);
2583
- l = Math.min(0.75, l * 1.05);
2584
- const c = (1 - Math.abs(2 * l - 1)) * s;
2585
- const x = c * (1 - Math.abs(h / 60 % 2 - 1));
2586
- const m = l - c / 2;
2587
- let r2 = 0, g2 = 0, b2 = 0;
2588
- if (0 <= h && h < 60) [r2, g2, b2] = [c, x, 0];
2589
- else if (60 <= h && h < 120) [r2, g2, b2] = [x, c, 0];
2590
- else if (120 <= h && h < 180) [r2, g2, b2] = [0, c, x];
2591
- else if (180 <= h && h < 240) [r2, g2, b2] = [0, x, c];
2592
- else if (240 <= h && h < 300) [r2, g2, b2] = [x, 0, c];
2593
- else [r2, g2, b2] = [c, 0, x];
2594
- const finalR = Math.round((r2 + m) * 255);
2595
- const finalG = Math.round((g2 + m) * 255);
2596
- const finalB = Math.round((b2 + m) * 255);
2597
- return `#${finalR.toString(16).padStart(2, "0")}${finalG.toString(16).padStart(2, "0")}${finalB.toString(16).padStart(2, "0")}`;
2598
- };
2599
- var getFieldsOnChange = (fields) => {
2600
- const result = [];
2601
- function traverse(items) {
2602
- for (const item of items) {
2603
- if (item) {
2604
- if (item?.type_co === "field" && matchDomains(fields, item?.on_change)) {
2605
- result.push(item.name);
2606
- }
2607
- if (item?.fields && Array.isArray(item?.fields)) {
2608
- traverse(item?.fields);
2609
- }
2610
- }
2332
+ function cleanObject(obj) {
2333
+ const result = {};
2334
+ for (const [k, v] of Object.entries(obj)) {
2335
+ if (v !== null && v !== void 0) {
2336
+ result[k] = v;
2611
2337
  }
2612
2338
  }
2613
- traverse(fields);
2614
2339
  return result;
2615
- };
2616
- var filterFieldDirty = ({
2617
- id,
2618
- viewData,
2619
- formValues,
2620
- dirtyFields,
2621
- model,
2622
- defaultData,
2623
- keepZeroValue = false
2624
- }) => {
2625
- const data = id ? { ...dirtyFields } : { ...formValues };
2626
- for (const key in data) {
2627
- if (viewData?.models?.[model]?.[key]?.type === "one2many" /* ONE2MANY */) {
2628
- const lineData = [];
2629
- (formValues[key] ?? []).forEach((itemData, index) => {
2630
- if (typeof itemData?.id === "string" && itemData?.id.includes("virtual")) {
2631
- delete itemData?.id;
2632
- }
2633
- if (!itemData?.id) {
2634
- lineData.push([
2635
- 0 /* CREATE */,
2636
- `virtual_${index}`,
2637
- filterFieldDirty({
2638
- id: itemData?.id,
2639
- viewData,
2640
- formValues: itemData,
2641
- dirtyFields: {},
2642
- model: viewData?.models?.[model]?.[key]?.relation,
2643
- defaultData,
2644
- keepZeroValue
2645
- })
2646
- ]);
2647
- } else if (dirtyFields[key]?.length) {
2648
- dirtyFields[key].forEach((itemDirty, indexDirty) => {
2649
- if (Object.values(itemDirty).includes(true) && indexDirty === index) {
2650
- lineData.push([
2651
- 1 /* UPDATE */,
2652
- itemData?.id,
2653
- filterFieldDirty({
2654
- id: itemData?.id,
2655
- viewData,
2656
- formValues: itemData,
2657
- dirtyFields: itemDirty,
2658
- model: viewData?.models?.[model]?.[key]?.relation,
2659
- defaultData: {},
2660
- keepZeroValue
2661
- })
2662
- ]);
2663
- }
2664
- });
2665
- }
2666
- });
2667
- (defaultData[key] ?? []).forEach((item) => {
2668
- if (!(formValues[key] ?? []).find(
2669
- (itemData) => itemData?.id === item?.id
2670
- )) {
2671
- lineData.push([2 /* DELETE */, item?.id, item]);
2672
- }
2673
- });
2674
- data[key] = lineData;
2675
- } else if (viewData?.models?.[model]?.[key]?.type === "many2many" /* MANY2MANY */) {
2676
- const lineData = [];
2677
- (formValues[key] || []).forEach((itemData) => {
2678
- if (itemData?.id) {
2679
- lineData.push([4 /* NO_CHANGE */, itemData?.id]);
2680
- }
2681
- });
2682
- (defaultData[key] ?? []).forEach((item) => {
2683
- if (!(formValues[key] ?? []).find(
2684
- (itemData) => itemData?.id === item?.id
2685
- )) {
2686
- lineData.push([3 /* UNLINK */, item?.id]);
2687
- }
2688
- });
2689
- data[key] = lineData;
2690
- } else {
2691
- if (id && (typeof dirtyFields?.[key] === "object" && !dirtyFields?.[key]?.id || typeof dirtyFields[key] !== "object" && !dirtyFields[key])) {
2692
- if (!(keepZeroValue && (formValues[key] === 0 || formValues[key] === "0"))) {
2693
- delete data[key];
2694
- }
2695
- } else {
2696
- if (!data[key] && !(keepZeroValue && (data[key] === 0 || data[key] === "0"))) {
2697
- delete data[key];
2698
- } else {
2699
- data[key] = formValues?.[key]?.display_name ? formValues?.[key]?.id : formValues?.[key];
2700
- }
2701
- }
2702
- }
2703
- }
2704
- return data;
2705
- };
2706
- var mergeObjects = (object1, object2) => {
2707
- if (!object1 || !object2) return void 0;
2708
- const mergedObject = { ...object2 };
2709
- Object.keys(object1).forEach((key) => {
2710
- if (Array.isArray(object1[key]) && Array.isArray(object2[key])) {
2711
- mergedObject[key] = object2[key].map((item, index) => {
2712
- if (object1[key][index]) {
2713
- return {
2714
- ...item,
2715
- ...object1[key][index]
2716
- };
2717
- }
2718
- return item;
2719
- });
2720
- } else if (typeof object1[key] === "object" && typeof object2[key] === "object" && object1[key] !== null && object2[key] !== null) {
2721
- mergedObject[key] = mergeObjects(object1[key], object2[key]);
2722
- } else {
2723
- mergedObject[key] = object1[key] !== void 0 ? object1[key] : object2[key];
2724
- }
2725
- });
2726
- if (object2) {
2727
- Object.keys(object2).forEach((key) => {
2728
- if (!mergedObject.hasOwnProperty(key)) {
2729
- mergedObject[key] = object2[key];
2730
- }
2731
- });
2732
- }
2733
- return mergedObject;
2734
- };
2735
- var formatUrlPath = ({
2736
- viewType,
2737
- aid,
2738
- model,
2739
- id,
2740
- actionPath
2741
- }) => {
2742
- let _url = `/${viewType}/${actionPath}?aid=${aid}&model=${model}`;
2743
- if (id) {
2744
- _url += `&id=${id}`;
2745
- }
2746
- return _url;
2747
- };
2748
- var removeUndefinedFields = (obj) => {
2749
- const newObj = {};
2750
- for (const key in obj) {
2751
- if (obj[key] !== void 0) {
2752
- newObj[key] = obj[key];
2753
- }
2754
- }
2755
- return newObj;
2756
- };
2757
- var useTabModel = (viewData, onchangeData) => {
2758
- const tabsData = viewData?.views?.form?.tabs?.filter((val) => {
2759
- if (!val) return null;
2760
- const hide = checkDomain(onchangeData, val.invisible);
2761
- if (!hide) {
2762
- return val;
2763
- }
2764
- return false;
2765
- }) || [];
2766
- return tabsData;
2767
- };
2768
- var isBase64File = (str) => {
2769
- try {
2770
- const dataUriPattern = /^data:([a-zA-Z]+\/[a-zA-Z0-9-.+]+)?;base64,/;
2771
- if (dataUriPattern.test(str)) {
2772
- return true;
2773
- }
2774
- const base64Pattern = (
2775
- // eslint-disable-next-line no-useless-escape
2776
- /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$/
2777
- );
2778
- return base64Pattern.test(str);
2779
- } catch (e) {
2780
- return false;
2781
- }
2782
- };
2783
- var isBase64Image = (str) => {
2784
- const base64Regex = /^data:image\/(png|jpeg|jpg|gif|webp);base64,/;
2785
- if (!base64Regex.test(str)) {
2786
- return false;
2787
- }
2788
- try {
2789
- const base64Data = str.split(",")[1];
2790
- return !!base64Data && atob(base64Data).length > 0;
2791
- } catch (error) {
2792
- return false;
2793
- }
2794
- };
2795
- var checkIsImageLink = (url) => {
2796
- const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff|ico)$/i;
2797
- return imageExtensions.test(url) || isBase64Image(url);
2798
- };
2799
- var formatFileSize = (size) => {
2800
- if (size < 1024) return `${size} B`;
2801
- const i = Math.floor(Math.log(size) / Math.log(1024));
2802
- const sizes = ["B", "KB", "MB", "GB", "TB"];
2803
- return `${(size / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`;
2804
- };
2805
- var getSubdomain = (url = window.location.href) => {
2806
- const parts = url?.split(".");
2807
- if (parts.length > 2) {
2808
- return parts[0].replace("https://", "").replace("http://", "");
2809
- }
2810
- return null;
2811
- };
2812
- var resequence = (arr, start, end) => {
2813
- if (start < 0 || start >= arr.length || end < 0 || end >= arr.length) {
2814
- return [];
2815
- }
2816
- const [element] = arr.splice(start, 1);
2817
- arr.splice(end, 0, element);
2818
- return arr.slice(Math.min(start, end), Math.max(start, end) + 1);
2819
- };
2820
- var getOffSet = (arr, start, end) => {
2821
- if (start < 0 || start >= arr.length || end < 0 || end >= arr.length) {
2822
- return 0;
2823
- }
2824
- if (start > end) {
2825
- return end;
2826
- }
2827
- return arr.slice(0, start).length;
2828
- };
2829
- var copyTextToClipboard = async (text) => {
2830
- if ("clipboard" in navigator) {
2831
- return await navigator.clipboard.writeText(text);
2832
- } else {
2833
- const textArea = document.createElement("textarea");
2834
- textArea.value = text;
2835
- textArea.style.position = "fixed";
2836
- document.body.appendChild(textArea);
2837
- textArea.focus();
2838
- textArea.select();
2839
- try {
2840
- document.execCommand("copy");
2841
- } finally {
2842
- document.body.removeChild(textArea);
2843
- }
2844
- }
2845
- };
2340
+ }
2846
2341
  var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2847
2342
  if (!originalRequest.data) return originalRequest.data;
2848
2343
  if (typeof originalRequest.data === "string") {
@@ -2862,164 +2357,5 @@ var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2862
2357
  }
2863
2358
  return originalRequest.data;
2864
2359
  };
2865
- var isObjectEmpty = (obj) => {
2866
- return Object.keys(obj).length === 0;
2867
- };
2868
- var useField = (props) => {
2869
- const [invisible, setInvisible] = useState(true);
2870
- const [required, setRequired] = useState(false);
2871
- const [readonly, setReadOnly] = useState(false);
2872
- const {
2873
- invisible: inv,
2874
- required: req,
2875
- readonly: rea,
2876
- onchangeData,
2877
- rootField,
2878
- index,
2879
- name
2880
- } = props;
2881
- const nameField = rootField ? `${rootField?.name}.${index}.${name}` : null;
2882
- useEffect(() => {
2883
- if (onchangeData && Object.keys(onchangeData).length > 0) {
2884
- setRequired(
2885
- typeof req === "object" ? matchDomains(onchangeData, req) : checkDomain(onchangeData, req)
2886
- );
2887
- setInvisible(matchDomains(onchangeData, inv));
2888
- setReadOnly(
2889
- typeof req === "object" ? matchDomains(onchangeData, rea) : checkDomain(onchangeData, rea)
2890
- );
2891
- }
2892
- }, [onchangeData]);
2893
- return {
2894
- invisible,
2895
- required,
2896
- readonly,
2897
- nameField
2898
- };
2899
- };
2900
- var downloadFile = async (url, filename) => {
2901
- try {
2902
- const response = await fetch(url);
2903
- if (!response.ok) throw new Error(`Failed to fetch ${url}`);
2904
- const contentType = response.headers.get("Content-Type") || "";
2905
- let ext = "";
2906
- if (contentType.includes("pdf")) ext = ".pdf";
2907
- else if (contentType.includes("png")) ext = ".png";
2908
- else if (contentType.includes("jpeg") || contentType.includes("jpg"))
2909
- ext = ".jpg";
2910
- else if (contentType.includes("zip")) ext = ".zip";
2911
- else if (contentType.includes("msword")) ext = ".doc";
2912
- else if (contentType.includes("spreadsheet")) ext = ".xls";
2913
- else if (contentType.includes("json")) ext = ".json";
2914
- else if (contentType.includes("text")) ext = ".txt";
2915
- else {
2916
- ext = "";
2917
- }
2918
- const blob = await response.blob();
2919
- const urlBlob = window.URL.createObjectURL(blob);
2920
- const link = document.createElement("a");
2921
- link.href = urlBlob;
2922
- link.download = (filename || "file") + ext;
2923
- document.body.appendChild(link);
2924
- link.click();
2925
- document.body.removeChild(link);
2926
- window.URL.revokeObjectURL(urlBlob);
2927
- } catch (error) {
2928
- console.error("File download failed:", error);
2929
- }
2930
- };
2931
- function cleanObject(obj) {
2932
- const result = {};
2933
- for (const [k, v] of Object.entries(obj)) {
2934
- if (v !== null && v !== void 0) {
2935
- result[k] = v;
2936
- }
2937
- }
2938
- return result;
2939
- }
2940
- var extractIdFromDomain = (domain) => {
2941
- if (!domain || !Array.isArray(domain)) return null;
2942
- const idCond = domain.find(
2943
- ([field, operator]) => field === "id" && operator === "="
2944
- );
2945
- return idCond ? Number(idCond[2]) : null;
2946
- };
2947
-
2948
- // src/utils/storage/local-storage.ts
2949
- var localStorageUtils = () => {
2950
- const setToken = async (access_token) => {
2951
- localStorage.setItem("accessToken", access_token);
2952
- };
2953
- const setRefreshToken = async (refresh_token) => {
2954
- localStorage.setItem("refreshToken", refresh_token);
2955
- };
2956
- const getAccessToken = async () => {
2957
- return localStorage.getItem("accessToken");
2958
- };
2959
- const getRefreshToken = async () => {
2960
- return localStorage.getItem("refreshToken");
2961
- };
2962
- const clearToken = async () => {
2963
- localStorage.removeItem("accessToken");
2964
- localStorage.removeItem("refreshToken");
2965
- };
2966
- return {
2967
- setToken,
2968
- setRefreshToken,
2969
- getAccessToken,
2970
- getRefreshToken,
2971
- clearToken
2972
- };
2973
- };
2974
-
2975
- // src/utils/storage/session-storage.ts
2976
- var sessionStorageUtils = /* @__PURE__ */ (() => {
2977
- const getMenuFocus = () => {
2978
- const menuFocus = sessionStorage.getItem("menuFocus");
2979
- return menuFocus ? JSON.parse(menuFocus) : {
2980
- id: void 0,
2981
- service: ""
2982
- };
2983
- };
2984
- const setMenuFocus = (menuTree) => {
2985
- sessionStorage.setItem("menuFocus", JSON.stringify({ ...menuTree }));
2986
- };
2987
- const getActionData = () => {
2988
- const actionData = sessionStorage.getItem("actionData");
2989
- return actionData ? JSON.parse(actionData) : {};
2990
- };
2991
- const setActionData = (actData) => {
2992
- sessionStorage.setItem("actionData", JSON.stringify(actData));
2993
- };
2994
- const getViewData = () => {
2995
- const viewData = sessionStorage.getItem("viewData");
2996
- return viewData ? JSON.parse(viewData) : {};
2997
- };
2998
- const getBrowserSession = () => {
2999
- const actionData = sessionStorage.getItem("browserSession");
3000
- return actionData ? JSON.parse(actionData) : null;
3001
- };
3002
- const setViewData = (viewData) => {
3003
- sessionStorage.setItem("viewData", JSON.stringify(viewData));
3004
- };
3005
- const getXNode = () => {
3006
- const xNode = sessionStorage.getItem("xNode");
3007
- return xNode;
3008
- };
3009
- const setXNode = (xNode) => {
3010
- sessionStorage.setItem("xNode", xNode);
3011
- };
3012
- return {
3013
- getMenuFocus,
3014
- setMenuFocus,
3015
- setActionData,
3016
- getActionData,
3017
- getViewData,
3018
- setViewData,
3019
- getBrowserSession,
3020
- getXNode,
3021
- setXNode
3022
- };
3023
- })();
3024
2360
 
3025
- export { WesapError, checkIsImageLink, cleanObject, convertFloatToTime, convertTimeToFloat, copyTextToClipboard, domainHelper, downloadFile, evalJSONContext, evalJSONDomain, extractIdFromDomain, filterFieldDirty, formatCurrency, formatDate, formatFileSize, formatSortingString, formatUrlPath, getFieldsOnChange, getOffSet, getSubdomain, handleError, isBase64File, isBase64Image, isObjectEmpty, localStorageUtils, mergeObjects, removeUndefinedFields, resequence, sessionStorageUtils, stringToColor, toQueryString, updateTokenParamInOriginalRequest, useField, useTabModel, validateAndParseDate };
2361
+ export { Domain, InvalidDomainError, checkDomain, cleanObject, domainHelper, evalDomain, evalJSONContext, evalJSONDomain, evalPartialContext, formatSortingString, localStorageUtils, makeContext, matchDomains, sessionStorageUtils, toQueryString, updateTokenParamInOriginalRequest };