@fctc/interface-logic 5.2.5 → 5.2.7

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