@fctc/widget-logic 1.4.0 → 1.4.2

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 (61) hide show
  1. package/dist/config.d.mts +6 -0
  2. package/dist/config.d.ts +6 -0
  3. package/dist/config.js +24 -0
  4. package/dist/config.mjs +2 -0
  5. package/dist/constants.d.mts +1 -0
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.js +24 -0
  8. package/dist/constants.mjs +2 -0
  9. package/dist/environment.d.mts +1 -0
  10. package/dist/environment.d.ts +1 -0
  11. package/dist/environment.js +24 -0
  12. package/dist/environment.mjs +2 -0
  13. package/dist/hooks.d.mts +969 -0
  14. package/dist/hooks.d.ts +969 -0
  15. package/dist/hooks.js +743 -0
  16. package/dist/hooks.mjs +717 -0
  17. package/dist/icons.d.mts +9 -0
  18. package/dist/icons.d.ts +9 -0
  19. package/dist/icons.js +139 -0
  20. package/dist/icons.mjs +110 -0
  21. package/dist/index.d.mts +15 -4
  22. package/dist/index.d.ts +15 -4
  23. package/dist/index.js +7227 -230
  24. package/dist/index.mjs +7312 -218
  25. package/dist/provider.d.mts +1 -0
  26. package/dist/provider.d.ts +1 -0
  27. package/dist/provider.js +24 -0
  28. package/dist/provider.mjs +2 -0
  29. package/dist/services.d.mts +1 -0
  30. package/dist/services.d.ts +1 -0
  31. package/dist/services.js +24 -0
  32. package/dist/services.mjs +2 -0
  33. package/dist/store.d.mts +1 -0
  34. package/dist/store.d.ts +1 -0
  35. package/dist/store.js +24 -0
  36. package/dist/store.mjs +2 -0
  37. package/dist/utils.d.mts +38 -0
  38. package/dist/utils.d.ts +38 -0
  39. package/dist/utils.js +282 -0
  40. package/dist/utils.mjs +242 -0
  41. package/dist/widget.d.mts +325 -0
  42. package/dist/widget.d.ts +325 -0
  43. package/dist/widget.js +7079 -0
  44. package/dist/widget.mjs +7111 -0
  45. package/package.json +64 -23
  46. package/dist/action.d.mts +0 -68
  47. package/dist/action.d.ts +0 -68
  48. package/dist/action.js +0 -152
  49. package/dist/action.mjs +0 -122
  50. package/dist/common.d.mts +0 -13
  51. package/dist/common.d.ts +0 -13
  52. package/dist/common.js +0 -60
  53. package/dist/common.mjs +0 -33
  54. package/dist/form.d.mts +0 -41
  55. package/dist/form.d.ts +0 -41
  56. package/dist/form.js +0 -116
  57. package/dist/form.mjs +0 -87
  58. package/dist/table.d.mts +0 -22
  59. package/dist/table.d.ts +0 -22
  60. package/dist/table.js +0 -118
  61. package/dist/table.mjs +0 -91
package/dist/utils.mjs ADDED
@@ -0,0 +1,242 @@
1
+ // src/utils/constants.ts
2
+ var languages = [
3
+ { id: "vi_VN", name: "VIE" },
4
+ { id: "en_US", name: "ENG" }
5
+ ];
6
+ var API_PRESCHOOL_URL = {
7
+ baseURL: "https://preschool.vitrust.app"
8
+ };
9
+ var API_APP_URL = {
10
+ baseUrl: "https://api.vitrust.app",
11
+ c2: "https://api.vitrust.app/c2",
12
+ apiV2: "https://api.vitrust.app/c2/api/v2"
13
+ };
14
+
15
+ // src/utils/function.ts
16
+ import { useCallback, useEffect, useReducer, useRef, useState } from "react";
17
+ var countSum = (data, field) => {
18
+ if (!data || !field) return 0;
19
+ return data.reduce(
20
+ (total, item) => total + (item?.[`${field}_count`] || 0),
21
+ 0
22
+ );
23
+ };
24
+ function mergeButtons(fields) {
25
+ const buttons = fields?.filter((f) => f.type_co === "button");
26
+ const others = fields?.filter((f) => f.type_co !== "button");
27
+ if (buttons?.length) {
28
+ others.push({
29
+ type_co: "buttons",
30
+ buttons
31
+ });
32
+ }
33
+ return others;
34
+ }
35
+ function isElementVisible(el) {
36
+ const style = window.getComputedStyle(el);
37
+ return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
38
+ }
39
+ function arraysAreEqual(a, b) {
40
+ if (a.length !== b.length) return false;
41
+ const setA = new Set(a);
42
+ const setB = new Set(b);
43
+ if (setA.size !== setB.size) return false;
44
+ for (const val of setA) {
45
+ if (!setB.has(val)) return false;
46
+ }
47
+ return true;
48
+ }
49
+ function useGetRowIds(tableRef) {
50
+ const [rowIds, setRowIds] = useState([]);
51
+ const lastRowIdsRef = useRef([]);
52
+ const updateVisibleRowIds = useCallback(() => {
53
+ const table = tableRef?.current;
54
+ if (!table) return;
55
+ const rows = table.querySelectorAll("tr[data-row-id]");
56
+ const ids = [];
57
+ rows.forEach((row) => {
58
+ const el = row;
59
+ if (isElementVisible(el)) {
60
+ const id = el.getAttribute("data-row-id");
61
+ if (id) ids.push(id);
62
+ }
63
+ });
64
+ const uniqueIds = Array.from(new Set(ids));
65
+ if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
66
+ lastRowIdsRef.current = uniqueIds;
67
+ setRowIds(uniqueIds);
68
+ }
69
+ }, [tableRef]);
70
+ useEffect(() => {
71
+ const table = tableRef?.current;
72
+ if (!table) return;
73
+ const observer = new MutationObserver(() => {
74
+ updateVisibleRowIds();
75
+ });
76
+ observer.observe(table, {
77
+ childList: true,
78
+ subtree: true,
79
+ attributes: true,
80
+ attributeFilter: ["style", "class"]
81
+ });
82
+ updateVisibleRowIds();
83
+ return () => {
84
+ observer.disconnect();
85
+ };
86
+ }, [updateVisibleRowIds, tableRef]);
87
+ return { rowIds, refresh: updateVisibleRowIds };
88
+ }
89
+ var getDateRange = (currentDate, unit) => {
90
+ const date = new Date(currentDate);
91
+ let dateStart, dateEnd;
92
+ function formatDate(d) {
93
+ return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0") + " " + String(d.getHours()).padStart(2, "0") + ":" + String(d.getMinutes()).padStart(2, "0") + ":" + String(d.getSeconds()).padStart(2, "0");
94
+ }
95
+ switch (unit) {
96
+ case "month":
97
+ dateStart = new Date(
98
+ date.getFullYear(),
99
+ date.getMonth() + 1,
100
+ date.getDate(),
101
+ 23,
102
+ 59,
103
+ 59
104
+ );
105
+ dateStart.setHours(dateStart.getHours() - 7);
106
+ dateEnd = new Date(date.getFullYear(), date.getMonth(), 0, 0, 0, 0);
107
+ dateEnd.setHours(dateEnd.getHours() - 7);
108
+ break;
109
+ case "day":
110
+ dateStart = new Date(
111
+ date.getFullYear(),
112
+ date.getMonth(),
113
+ date.getDate(),
114
+ 23,
115
+ 59,
116
+ 59
117
+ );
118
+ dateStart.setHours(dateStart.getHours() - 7);
119
+ dateEnd = new Date(
120
+ date.getFullYear(),
121
+ date.getMonth(),
122
+ date.getDate(),
123
+ 0,
124
+ 0,
125
+ 0
126
+ );
127
+ dateEnd.setHours(dateEnd.getHours() - 7);
128
+ break;
129
+ case "week":
130
+ const dayOfWeek = date.getDay();
131
+ const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
132
+ const daysToSunday = dayOfWeek === 0 ? 0 : 7 - dayOfWeek;
133
+ dateStart = new Date(
134
+ date.getFullYear(),
135
+ date.getMonth(),
136
+ date.getDate() + daysToSunday,
137
+ 23,
138
+ 59,
139
+ 59
140
+ );
141
+ dateStart.setHours(dateStart.getHours() - 7);
142
+ dateEnd = new Date(
143
+ date.getFullYear(),
144
+ date.getMonth(),
145
+ date.getDate() + daysToMonday,
146
+ 0,
147
+ 0,
148
+ 0
149
+ );
150
+ dateEnd.setHours(dateEnd.getHours() - 7);
151
+ break;
152
+ case "year":
153
+ dateStart = new Date(date.getFullYear(), 11, 31, 23, 59, 59);
154
+ dateStart.setHours(dateStart.getHours() - 7);
155
+ dateEnd = new Date(date.getFullYear() - 1, 11, 31, 0, 0, 0);
156
+ dateEnd.setHours(dateEnd.getHours() - 7);
157
+ break;
158
+ default:
159
+ throw new Error(
160
+ "\u0110\u01A1n v\u1ECB kh\xF4ng h\u1EE3p l\u1EC7. Ch\u1EC9 ch\u1EA5p nh\u1EADn: week, day, month, year"
161
+ );
162
+ }
163
+ return [
164
+ ["date_start", "<=", formatDate(dateStart)],
165
+ ["date_end", ">=", formatDate(dateEnd)]
166
+ ];
167
+ };
168
+ var convertFieldsToArray = (fields) => {
169
+ const defaultFields = ["display_name", "date_start", "date_end"];
170
+ if (!fields || !Array.isArray(fields)) {
171
+ return defaultFields;
172
+ }
173
+ const inputFields = fields.filter((field) => field && field.type_co === "field").map((field) => field.name);
174
+ return [...defaultFields, ...inputFields];
175
+ };
176
+ function combineContexts(contexts) {
177
+ if (contexts.some((context) => !context)) {
178
+ return void 0;
179
+ } else {
180
+ const res = contexts.reduce((acc, context) => {
181
+ return { ...acc, ...context };
182
+ }, {});
183
+ return res;
184
+ }
185
+ }
186
+ var STORAGES = {
187
+ TOKEN: "accessToken",
188
+ USER_INFO: "USER_INFO"
189
+ };
190
+ function useAsyncState(initialValue = [true, null]) {
191
+ return useReducer(
192
+ (_state, action = null) => [false, action],
193
+ initialValue
194
+ );
195
+ }
196
+ async function setStorageItemAsync(key, value) {
197
+ try {
198
+ if (value === null) {
199
+ localStorage.removeItem(key);
200
+ } else {
201
+ localStorage.setItem(key, value);
202
+ }
203
+ } catch (e) {
204
+ console.error("Local storage is unavailable:", e);
205
+ }
206
+ }
207
+ function useStorageState(key) {
208
+ const [state, setState] = useAsyncState();
209
+ useEffect(() => {
210
+ try {
211
+ const storedValue = localStorage.getItem(key);
212
+ setState(storedValue);
213
+ } catch (e) {
214
+ console.error("Local storage is unavailable:", e);
215
+ }
216
+ }, [key]);
217
+ const setValue = useCallback(
218
+ (value) => {
219
+ setState(value);
220
+ setStorageItemAsync(key, value);
221
+ },
222
+ [key]
223
+ );
224
+ return [state, setValue];
225
+ }
226
+
227
+ // src/utils.ts
228
+ export * from "@fctc/interface-logic/utils";
229
+ export {
230
+ API_APP_URL,
231
+ API_PRESCHOOL_URL,
232
+ STORAGES,
233
+ combineContexts,
234
+ convertFieldsToArray,
235
+ countSum,
236
+ getDateRange,
237
+ languages,
238
+ mergeButtons,
239
+ setStorageItemAsync,
240
+ useGetRowIds,
241
+ useStorageState
242
+ };
@@ -0,0 +1,325 @@
1
+ import * as react from 'react';
2
+ import { ChangeEvent } from 'react';
3
+ import moment from 'moment';
4
+
5
+ interface ValuePropsType {
6
+ id: number | string;
7
+ display_name: number | string;
8
+ [key: string]: any;
9
+ }
10
+ interface IInputFieldProps {
11
+ name?: string;
12
+ type?: string;
13
+ readonly?: boolean;
14
+ required?: boolean;
15
+ placeholder?: string;
16
+ defaultValue?: string | number | ValuePropsType;
17
+ invisible?: boolean;
18
+ methods?: any;
19
+ onChange?: (name: string, value: any) => void;
20
+ onBlur?: Function;
21
+ onRefetch?: Function;
22
+ isForm?: boolean;
23
+ className?: string;
24
+ value?: string | number | ValuePropsType | null | Record<any, any> | any;
25
+ string?: string;
26
+ isEditTable?: boolean;
27
+ formValues?: any;
28
+ model?: string;
29
+ relation?: string;
30
+ domain?: any;
31
+ }
32
+
33
+ type TStatus = 'normal' | 'done' | 'blocked';
34
+ interface TStatusDropdownFieldProps extends IInputFieldProps {
35
+ state: any;
36
+ selection: any;
37
+ id: any;
38
+ }
39
+
40
+ declare const statusDropdownController: (props: TStatusDropdownFieldProps) => {
41
+ handleClick: (status: any) => Promise<void>;
42
+ buttonRef: react.RefObject<HTMLDivElement>;
43
+ isForm: boolean | undefined;
44
+ setIsOpen: react.Dispatch<react.SetStateAction<boolean>>;
45
+ isOpen: boolean;
46
+ selection: any;
47
+ state: any;
48
+ colors: Record<TStatus, string>;
49
+ };
50
+
51
+ interface IMany2OneProps extends IInputFieldProps {
52
+ context?: any;
53
+ options?: any;
54
+ showDetail?: boolean;
55
+ actionData?: any;
56
+ }
57
+
58
+ declare const many2oneFieldController: (props: IMany2OneProps) => {
59
+ allowShowDetail: boolean;
60
+ handleClose: () => void;
61
+ handleChooseRecord: (idRecord: number) => void;
62
+ handleSelectChange: (selectedOption: any) => void;
63
+ initValue: any;
64
+ isFetching: boolean;
65
+ isShowModalMany2Many: boolean;
66
+ options: any[];
67
+ fetchMoreOptions: () => void;
68
+ domainModal: any;
69
+ tempSelectedOption: any;
70
+ setTempSelectedOption: React.Dispatch<React.SetStateAction<any>>;
71
+ setDomainModal: React.Dispatch<React.SetStateAction<any>>;
72
+ dataOfSelection: any;
73
+ refetch: () => void;
74
+ selectOptions: any[];
75
+ optionsObject: any;
76
+ contextObject: any;
77
+ actionId: any;
78
+ setIsShowModalMany2Many: React.Dispatch<React.SetStateAction<boolean>>;
79
+ };
80
+
81
+ type Option = {
82
+ value: number;
83
+ label: string;
84
+ };
85
+ declare const many2oneButtonController: (props: any) => {
86
+ options: Option[];
87
+ };
88
+
89
+ interface IMany2ManyControllerProps extends IInputFieldProps {
90
+ context: any;
91
+ tab: any;
92
+ aid: number;
93
+ setSelectedRowKeys: any;
94
+ fields: any;
95
+ setFields: any;
96
+ groupByDomain: any;
97
+ page: number;
98
+ options: any;
99
+ sessionStorageUtils: any;
100
+ }
101
+
102
+ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {};
103
+
104
+ interface IMany2ManyTagFieldProps extends IInputFieldProps {
105
+ options: any;
106
+ widget: string;
107
+ placeholderNoOption: string;
108
+ }
109
+
110
+ declare const many2manyTagsController: (props: IMany2ManyTagFieldProps) => {
111
+ options: any;
112
+ customNoOptionsMessage: () => string;
113
+ tranfer: (data: any) => any;
114
+ dataOfSelection: any;
115
+ isUser: boolean;
116
+ };
117
+
118
+ interface IDurationFieldProps extends IInputFieldProps {
119
+ id: any;
120
+ }
121
+
122
+ declare const durationController: (props: IDurationFieldProps) => {
123
+ defaultValue: string | number | ValuePropsType | undefined;
124
+ dataResponse: any;
125
+ handleClick: (stage_id: any) => Promise<void>;
126
+ disabled: boolean;
127
+ modelStatus: boolean;
128
+ setModalStatus: react.Dispatch<react.SetStateAction<boolean>>;
129
+ };
130
+
131
+ interface IPriorityFieldProps extends IInputFieldProps {
132
+ selection: any;
133
+ id: any;
134
+ actionData: any;
135
+ viewData: any;
136
+ context: any;
137
+ }
138
+
139
+ declare const priorityFieldController: (props: IPriorityFieldProps) => {
140
+ selection: any;
141
+ isForm: boolean | undefined;
142
+ methods: any;
143
+ defaultPriority: number;
144
+ savePriorities: ({ value, resetPriority, }: {
145
+ value: number;
146
+ resetPriority?: () => void;
147
+ }) => Promise<void>;
148
+ label: any;
149
+ id: any;
150
+ onChange: ((name: string, value: any) => void) | undefined;
151
+ };
152
+
153
+ declare const floatTimeFiledController: ({ onChange: fieldOnChange, onBlur, value, isDirty, props, }: {
154
+ onChange: any;
155
+ onBlur: any;
156
+ value: any;
157
+ error: any;
158
+ isDirty: any;
159
+ props: IInputFieldProps;
160
+ }) => {
161
+ handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
162
+ handleBlur: () => void;
163
+ handleKeyDown: (e: any) => void;
164
+ input: string;
165
+ errors: string;
166
+ };
167
+
168
+ declare const floatController: ({ onChange, value, props, }: {
169
+ onChange: any;
170
+ value: any;
171
+ props: IInputFieldProps;
172
+ }) => {
173
+ handleInputMouseLeave: () => void;
174
+ handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
175
+ useFormatFloatNumber: (value: number | string) => string;
176
+ inputRef: react.MutableRefObject<HTMLInputElement | null>;
177
+ inputValue: string;
178
+ };
179
+
180
+ declare const downloadFileController: () => {
181
+ inputId: string;
182
+ file: any;
183
+ handleFileChange: (e: any) => void;
184
+ handleFileDownload: () => void;
185
+ };
186
+
187
+ declare const downLoadBinaryController: (props: IInputFieldProps) => {
188
+ handleFileDownload: (e: any) => Promise<void>;
189
+ };
190
+
191
+ interface IDateFieldProps extends IInputFieldProps {
192
+ showTime: boolean;
193
+ widget: string;
194
+ min: number | string;
195
+ max: number | string;
196
+ viewData: any;
197
+ }
198
+
199
+ declare const dateFieldController: (props: IDateFieldProps) => {
200
+ formatDate: string;
201
+ formatDateParse: string;
202
+ range: (start: number, end: number, step?: number) => number[];
203
+ years: number[];
204
+ months_vi: string[];
205
+ months_en: string[];
206
+ customValidateMinMax: (date: any) => string | false;
207
+ minNowValue: boolean | moment.Moment | null;
208
+ maxNowValue: boolean | moment.Moment | null;
209
+ };
210
+
211
+ declare const copyLinkButtonController: (props: IInputFieldProps) => {
212
+ isCopied: boolean;
213
+ handleCopyToClipboard: (value: string) => Promise<void>;
214
+ propValue: any;
215
+ };
216
+
217
+ interface IColorFieldProps extends IInputFieldProps {
218
+ actionData: any;
219
+ idForm: number | string;
220
+ }
221
+
222
+ declare const colorFieldController: (props: IColorFieldProps) => {
223
+ savePickColor: (colorObject: any) => Promise<void>;
224
+ };
225
+
226
+ declare const binaryFieldController: (props: IInputFieldProps) => {
227
+ inputId: string;
228
+ selectedImage: string | null;
229
+ initialImage: any;
230
+ isInsideTable: boolean;
231
+ binaryRef: react.RefObject<HTMLDivElement>;
232
+ handleImageChange: (e: ChangeEvent<HTMLInputElement>, onChange: (file: File | null) => void) => Promise<void>;
233
+ handleRemoveImage: (onChange: (file: File | null) => void) => void;
234
+ checkIsImageLink: (url: string) => boolean;
235
+ getImageBase64WithMimeType: (base64: any) => string | null;
236
+ };
237
+
238
+ interface ITableBodyProps {
239
+ checkedAll: any;
240
+ checkboxRef: any;
241
+ setIsAutoSelect: any;
242
+ selectedRowKeys: any;
243
+ row: any;
244
+ isAutoSelect: any;
245
+ selectedRowKeysRef: any;
246
+ onClickRow: any;
247
+ }
248
+
249
+ declare const tableBodyController: (props: ITableBodyProps) => {
250
+ handleCheckBoxSingle: (event: React.ChangeEvent<HTMLInputElement>) => void;
251
+ checked: any;
252
+ handleClickRow: (col: any, row: any) => void;
253
+ };
254
+
255
+ interface ITableHeadProps {
256
+ typeTable: string;
257
+ rows: any[];
258
+ selectedRowKeysRef: any;
259
+ }
260
+
261
+ declare const tableHeadController: (props: ITableHeadProps) => {
262
+ handleCheckBoxAll: (event: React.ChangeEvent<HTMLInputElement>) => void;
263
+ };
264
+
265
+ interface ITableProps {
266
+ data: {
267
+ fields: any[];
268
+ records: any[];
269
+ dataModel: {
270
+ [fieldName: string]: {
271
+ string?: string;
272
+ [key: string]: any;
273
+ };
274
+ };
275
+ context: any;
276
+ typeTable?: 'list' | 'group' | 'calendar';
277
+ };
278
+ }
279
+ interface ISelctionStateProps {
280
+ typeTable?: string;
281
+ tableRef: any;
282
+ rows?: any[];
283
+ }
284
+
285
+ declare const tableController: ({ data }: ITableProps) => {
286
+ rows: any[];
287
+ columns: any;
288
+ onToggleColumnOptional: (item: any) => void;
289
+ typeTable: "group" | "list" | "calendar" | undefined;
290
+ };
291
+
292
+ declare const tableGroupController: (props: any) => {
293
+ handleExpandChildGroup: () => void;
294
+ colEmptyGroup: {
295
+ fromStart: number;
296
+ fromEnd: number;
297
+ };
298
+ leftPadding: string;
299
+ isShowGroup: boolean;
300
+ isQueryFetched: boolean;
301
+ nameGroupWithCount: string;
302
+ columns: any;
303
+ row: any;
304
+ isPlaceholderData: boolean;
305
+ columnsGroup: any;
306
+ indexRow: any;
307
+ rowsGroup: any[];
308
+ model: any;
309
+ viewData: any;
310
+ renderField: any;
311
+ level: any;
312
+ specification: any;
313
+ context: any;
314
+ checkedAll: any;
315
+ isDisplayCheckbox: any;
316
+ isAutoSelect: any;
317
+ setIsAutoSelect: any;
318
+ selectedRowKeysRef: any;
319
+ initVal: Record<string, any>;
320
+ dataResponse: any;
321
+ pageGroup: any;
322
+ setPageGroup: react.Dispatch<any>;
323
+ };
324
+
325
+ export { type ISelctionStateProps, type ITableBodyProps, type ITableHeadProps, type ITableProps, binaryFieldController, colorFieldController, copyLinkButtonController, dateFieldController, downLoadBinaryController, downloadFileController, durationController, floatController, floatTimeFiledController, many2manyFieldController, many2manyTagsController, many2oneButtonController, many2oneFieldController, priorityFieldController, statusDropdownController, tableBodyController, tableController, tableGroupController, tableHeadController };