@fctc/widget-logic 1.0.0 → 1.0.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.
@@ -0,0 +1,60 @@
1
+ interface UseArchieveProps {
2
+ data: {
3
+ method: string;
4
+ model: string;
5
+ ids: number[];
6
+ actionName: 'archieve' | 'unarchive';
7
+ };
8
+ onSuccess?: (res: any) => void;
9
+ onError?: (err: any) => void;
10
+ }
11
+ declare const useArchieveHandler: ({ data, onSuccess, onError, }: UseArchieveProps) => () => void;
12
+
13
+ interface UseDuplicateRowProps {
14
+ data: {
15
+ model: string;
16
+ ids: any;
17
+ };
18
+ onSuccess?: (res: any) => void;
19
+ onError?: (err: any) => void;
20
+ }
21
+ declare const useDuplicateRowHandler: ({ data, onSuccess, onError, }: UseDuplicateRowProps) => () => void;
22
+
23
+ interface UseGetFieldExportProps {
24
+ data: {
25
+ ids: number[];
26
+ model: string;
27
+ isShow?: boolean;
28
+ fieldType?: any;
29
+ importCompat?: boolean;
30
+ name?: string;
31
+ parentField?: any;
32
+ parentName?: string;
33
+ prefix?: any;
34
+ };
35
+ onSuccess?: (res: any) => void;
36
+ onError?: (err: any) => void;
37
+ }
38
+ declare const useGetFieldExportHandler: ({ data, onSuccess, onError, }: UseGetFieldExportProps) => () => void;
39
+
40
+ interface UseExportExcelProps {
41
+ data: {
42
+ model: string;
43
+ fields: {
44
+ name: string;
45
+ label: string;
46
+ type: string;
47
+ }[];
48
+ domain: any;
49
+ title?: string;
50
+ ids?: number[];
51
+ groupby?: any;
52
+ importCompat?: boolean;
53
+ type?: 'xlsx' | 'csv';
54
+ };
55
+ onSuccess?: (res: any) => void;
56
+ onError?: (err: any) => void;
57
+ }
58
+ declare const useExportExcelHandler: ({ data, onSuccess, onError, }: UseExportExcelProps) => () => void;
59
+
60
+ export { useArchieveHandler, useDuplicateRowHandler, useExportExcelHandler, useGetFieldExportHandler };
@@ -0,0 +1,60 @@
1
+ interface UseArchieveProps {
2
+ data: {
3
+ method: string;
4
+ model: string;
5
+ ids: number[];
6
+ actionName: 'archieve' | 'unarchive';
7
+ };
8
+ onSuccess?: (res: any) => void;
9
+ onError?: (err: any) => void;
10
+ }
11
+ declare const useArchieveHandler: ({ data, onSuccess, onError, }: UseArchieveProps) => () => void;
12
+
13
+ interface UseDuplicateRowProps {
14
+ data: {
15
+ model: string;
16
+ ids: any;
17
+ };
18
+ onSuccess?: (res: any) => void;
19
+ onError?: (err: any) => void;
20
+ }
21
+ declare const useDuplicateRowHandler: ({ data, onSuccess, onError, }: UseDuplicateRowProps) => () => void;
22
+
23
+ interface UseGetFieldExportProps {
24
+ data: {
25
+ ids: number[];
26
+ model: string;
27
+ isShow?: boolean;
28
+ fieldType?: any;
29
+ importCompat?: boolean;
30
+ name?: string;
31
+ parentField?: any;
32
+ parentName?: string;
33
+ prefix?: any;
34
+ };
35
+ onSuccess?: (res: any) => void;
36
+ onError?: (err: any) => void;
37
+ }
38
+ declare const useGetFieldExportHandler: ({ data, onSuccess, onError, }: UseGetFieldExportProps) => () => void;
39
+
40
+ interface UseExportExcelProps {
41
+ data: {
42
+ model: string;
43
+ fields: {
44
+ name: string;
45
+ label: string;
46
+ type: string;
47
+ }[];
48
+ domain: any;
49
+ title?: string;
50
+ ids?: number[];
51
+ groupby?: any;
52
+ importCompat?: boolean;
53
+ type?: 'xlsx' | 'csv';
54
+ };
55
+ onSuccess?: (res: any) => void;
56
+ onError?: (err: any) => void;
57
+ }
58
+ declare const useExportExcelHandler: ({ data, onSuccess, onError, }: UseExportExcelProps) => () => void;
59
+
60
+ export { useArchieveHandler, useDuplicateRowHandler, useExportExcelHandler, useGetFieldExportHandler };
package/dist/action.js ADDED
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/action.ts
21
+ var action_exports = {};
22
+ __export(action_exports, {
23
+ useArchieveHandler: () => useArchieveHandler,
24
+ useDuplicateRowHandler: () => useDuplicateRowHandler,
25
+ useExportExcelHandler: () => useExportExcelHandler,
26
+ useGetFieldExportHandler: () => useGetFieldExportHandler
27
+ });
28
+ module.exports = __toCommonJS(action_exports);
29
+
30
+ // src/action/use-archieve-row.tsx
31
+ var import_interface_logic = require("@fctc/interface-logic");
32
+ var useArchieveHandler = ({
33
+ data,
34
+ onSuccess,
35
+ onError
36
+ }) => {
37
+ const archieve = (0, import_interface_logic.useButton)();
38
+ const env = (0, import_interface_logic.getEnv)();
39
+ const handleDuplicateRecord = () => {
40
+ archieve.mutate(
41
+ {
42
+ method: `action_${data.actionName}`,
43
+ model: data.model,
44
+ ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
45
+ context: env.context
46
+ },
47
+ {
48
+ onSuccess,
49
+ onError
50
+ }
51
+ );
52
+ };
53
+ return handleDuplicateRecord;
54
+ };
55
+
56
+ // src/action/use-duplicate-row.tsx
57
+ var import_interface_logic2 = require("@fctc/interface-logic");
58
+ var useDuplicateRowHandler = ({
59
+ data,
60
+ onSuccess,
61
+ onError
62
+ }) => {
63
+ const duplicateRecord = (0, import_interface_logic2.useDuplicateRecord)();
64
+ const env = (0, import_interface_logic2.getEnv)();
65
+ const handleDuplicateRecord = () => {
66
+ duplicateRecord.mutate(
67
+ {
68
+ model: data.model,
69
+ id: Array.isArray(data.ids) ? [...data.ids] : data.ids,
70
+ context: env.context
71
+ },
72
+ {
73
+ onSuccess,
74
+ onError
75
+ }
76
+ );
77
+ };
78
+ return handleDuplicateRecord;
79
+ };
80
+
81
+ // src/action/use-get-field-export.tsx
82
+ var import_interface_logic3 = require("@fctc/interface-logic");
83
+ var useGetFieldExportHandler = ({
84
+ data,
85
+ onSuccess,
86
+ onError
87
+ }) => {
88
+ const fieldExport = (0, import_interface_logic3.useGetFieldExport)();
89
+ const env = (0, import_interface_logic3.getEnv)();
90
+ const handleGetFieldExport = () => {
91
+ fieldExport.mutate(
92
+ {
93
+ context: env.context,
94
+ ids: data.ids,
95
+ model: data.model,
96
+ isShow: data.isShow,
97
+ fieldType: data.fieldType,
98
+ importCompat: data.importCompat,
99
+ name: data.name,
100
+ parentField: data.parentField,
101
+ parentName: data.parentName,
102
+ prefix: data.prefix
103
+ },
104
+ {
105
+ onSuccess,
106
+ onError
107
+ }
108
+ );
109
+ };
110
+ return handleGetFieldExport;
111
+ };
112
+
113
+ // src/action/use-export-excel.tsx
114
+ var import_interface_logic4 = require("@fctc/interface-logic");
115
+ var useExportExcelHandler = ({
116
+ data,
117
+ onSuccess,
118
+ onError
119
+ }) => {
120
+ const exportExcel = (0, import_interface_logic4.useExportExcel)();
121
+ const env = (0, import_interface_logic4.getEnv)();
122
+ const handleExport = () => {
123
+ exportExcel.mutate(
124
+ {
125
+ model: data.model,
126
+ ids: data?.ids,
127
+ fields: data.fields,
128
+ domain: (0, import_interface_logic4.evalJSONDomain)(data.domain, env.context),
129
+ importCompat: data?.importCompat,
130
+ type: data.type,
131
+ context: env.context,
132
+ groupby: data?.groupby
133
+ },
134
+ {
135
+ onSuccess,
136
+ onError
137
+ }
138
+ );
139
+ };
140
+ return handleExport;
141
+ };
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ useArchieveHandler,
145
+ useDuplicateRowHandler,
146
+ useExportExcelHandler,
147
+ useGetFieldExportHandler
148
+ });
@@ -0,0 +1,118 @@
1
+ // src/action/use-archieve-row.tsx
2
+ import { getEnv, useButton } from "@fctc/interface-logic";
3
+ var useArchieveHandler = ({
4
+ data,
5
+ onSuccess,
6
+ onError
7
+ }) => {
8
+ const archieve = useButton();
9
+ const env = getEnv();
10
+ const handleDuplicateRecord = () => {
11
+ archieve.mutate(
12
+ {
13
+ method: `action_${data.actionName}`,
14
+ model: data.model,
15
+ ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
16
+ context: env.context
17
+ },
18
+ {
19
+ onSuccess,
20
+ onError
21
+ }
22
+ );
23
+ };
24
+ return handleDuplicateRecord;
25
+ };
26
+
27
+ // src/action/use-duplicate-row.tsx
28
+ import { getEnv as getEnv2, useDuplicateRecord } from "@fctc/interface-logic";
29
+ var useDuplicateRowHandler = ({
30
+ data,
31
+ onSuccess,
32
+ onError
33
+ }) => {
34
+ const duplicateRecord = useDuplicateRecord();
35
+ const env = getEnv2();
36
+ const handleDuplicateRecord = () => {
37
+ duplicateRecord.mutate(
38
+ {
39
+ model: data.model,
40
+ id: Array.isArray(data.ids) ? [...data.ids] : data.ids,
41
+ context: env.context
42
+ },
43
+ {
44
+ onSuccess,
45
+ onError
46
+ }
47
+ );
48
+ };
49
+ return handleDuplicateRecord;
50
+ };
51
+
52
+ // src/action/use-get-field-export.tsx
53
+ import { getEnv as getEnv3, useGetFieldExport } from "@fctc/interface-logic";
54
+ var useGetFieldExportHandler = ({
55
+ data,
56
+ onSuccess,
57
+ onError
58
+ }) => {
59
+ const fieldExport = useGetFieldExport();
60
+ const env = getEnv3();
61
+ const handleGetFieldExport = () => {
62
+ fieldExport.mutate(
63
+ {
64
+ context: env.context,
65
+ ids: data.ids,
66
+ model: data.model,
67
+ isShow: data.isShow,
68
+ fieldType: data.fieldType,
69
+ importCompat: data.importCompat,
70
+ name: data.name,
71
+ parentField: data.parentField,
72
+ parentName: data.parentName,
73
+ prefix: data.prefix
74
+ },
75
+ {
76
+ onSuccess,
77
+ onError
78
+ }
79
+ );
80
+ };
81
+ return handleGetFieldExport;
82
+ };
83
+
84
+ // src/action/use-export-excel.tsx
85
+ import { evalJSONDomain, getEnv as getEnv4, useExportExcel } from "@fctc/interface-logic";
86
+ var useExportExcelHandler = ({
87
+ data,
88
+ onSuccess,
89
+ onError
90
+ }) => {
91
+ const exportExcel = useExportExcel();
92
+ const env = getEnv4();
93
+ const handleExport = () => {
94
+ exportExcel.mutate(
95
+ {
96
+ model: data.model,
97
+ ids: data?.ids,
98
+ fields: data.fields,
99
+ domain: evalJSONDomain(data.domain, env.context),
100
+ importCompat: data?.importCompat,
101
+ type: data.type,
102
+ context: env.context,
103
+ groupby: data?.groupby
104
+ },
105
+ {
106
+ onSuccess,
107
+ onError
108
+ }
109
+ );
110
+ };
111
+ return handleExport;
112
+ };
113
+ export {
114
+ useArchieveHandler,
115
+ useDuplicateRowHandler,
116
+ useExportExcelHandler,
117
+ useGetFieldExportHandler
118
+ };
@@ -0,0 +1,38 @@
1
+ interface UseSaveFormProps$1 {
2
+ data: {
3
+ context: any;
4
+ model: string;
5
+ specification: any;
6
+ id: any;
7
+ nameField: any;
8
+ object: any;
9
+ };
10
+ onSuccess?: (res: any) => void;
11
+ onError?: (err: any) => void;
12
+ }
13
+ declare const UseOnChangeFormHandler: ({ data, onSuccess, onError, }: UseSaveFormProps$1) => () => void;
14
+
15
+ interface UseSaveFormProps {
16
+ data: {
17
+ context: any;
18
+ model: string;
19
+ specification: any;
20
+ id: number | string;
21
+ };
22
+ onSuccess?: (res: any) => void;
23
+ onError?: (err: any) => void;
24
+ }
25
+ declare const useSaveFormHandler: ({ data, onSuccess, onError, }: UseSaveFormProps) => () => void;
26
+
27
+ interface UseDeleteProps {
28
+ data: {
29
+ method: string;
30
+ model: string;
31
+ ids: number[];
32
+ };
33
+ onSuccess?: (res: any) => void;
34
+ onError?: (err: any) => void;
35
+ }
36
+ declare const useRemoveRowHandler: ({ data, onSuccess, onError, }: UseDeleteProps) => () => void;
37
+
38
+ export { UseOnChangeFormHandler, useRemoveRowHandler, useSaveFormHandler };
package/dist/form.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ interface UseSaveFormProps$1 {
2
+ data: {
3
+ context: any;
4
+ model: string;
5
+ specification: any;
6
+ id: any;
7
+ nameField: any;
8
+ object: any;
9
+ };
10
+ onSuccess?: (res: any) => void;
11
+ onError?: (err: any) => void;
12
+ }
13
+ declare const UseOnChangeFormHandler: ({ data, onSuccess, onError, }: UseSaveFormProps$1) => () => void;
14
+
15
+ interface UseSaveFormProps {
16
+ data: {
17
+ context: any;
18
+ model: string;
19
+ specification: any;
20
+ id: number | string;
21
+ };
22
+ onSuccess?: (res: any) => void;
23
+ onError?: (err: any) => void;
24
+ }
25
+ declare const useSaveFormHandler: ({ data, onSuccess, onError, }: UseSaveFormProps) => () => void;
26
+
27
+ interface UseDeleteProps {
28
+ data: {
29
+ method: string;
30
+ model: string;
31
+ ids: number[];
32
+ };
33
+ onSuccess?: (res: any) => void;
34
+ onError?: (err: any) => void;
35
+ }
36
+ declare const useRemoveRowHandler: ({ data, onSuccess, onError, }: UseDeleteProps) => () => void;
37
+
38
+ export { UseOnChangeFormHandler, useRemoveRowHandler, useSaveFormHandler };
package/dist/form.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/form.ts
21
+ var form_exports = {};
22
+ __export(form_exports, {
23
+ UseOnChangeFormHandler: () => UseOnChangeFormHandler,
24
+ useRemoveRowHandler: () => useRemoveRowHandler,
25
+ useSaveFormHandler: () => useSaveFormHandler
26
+ });
27
+ module.exports = __toCommonJS(form_exports);
28
+
29
+ // src/widget/form/use-on-change-form.tsx
30
+ var import_interface_logic = require("@fctc/interface-logic");
31
+ var UseOnChangeFormHandler = ({
32
+ data,
33
+ onSuccess,
34
+ onError
35
+ }) => {
36
+ const fetchOnchange = (0, import_interface_logic.useOnChangeForm)();
37
+ const handleOnChangeForm = () => {
38
+ fetchOnchange.mutate(
39
+ {
40
+ ids: data.id ? data.id : [],
41
+ model: data.model,
42
+ specification: data.specification,
43
+ context: data.context,
44
+ object: data.object,
45
+ fieldChange: [data.nameField]
46
+ },
47
+ {
48
+ onSuccess,
49
+ onError
50
+ }
51
+ );
52
+ };
53
+ return handleOnChangeForm;
54
+ };
55
+
56
+ // src/widget/form/use-save-form.tsx
57
+ var import_interface_logic2 = require("@fctc/interface-logic");
58
+ var useSaveFormHandler = ({
59
+ data,
60
+ onSuccess,
61
+ onError
62
+ }) => {
63
+ const fetchSave = (0, import_interface_logic2.useSave)();
64
+ const handleSaveForm = () => {
65
+ fetchSave.mutate(
66
+ {
67
+ ids: data.id ? [data.id] : [],
68
+ model: data.model,
69
+ data,
70
+ specification: data.specification,
71
+ context: data.context
72
+ },
73
+ {
74
+ onSuccess,
75
+ onError
76
+ }
77
+ );
78
+ };
79
+ return handleSaveForm;
80
+ };
81
+
82
+ // src/widget/form/use-remove-row.tsx
83
+ var import_interface_logic3 = require("@fctc/interface-logic");
84
+ var useRemoveRowHandler = ({
85
+ data,
86
+ onSuccess,
87
+ onError
88
+ }) => {
89
+ const remove = (0, import_interface_logic3.useRemoveRow)();
90
+ const env = (0, import_interface_logic3.getEnv)();
91
+ const handleRemoveRow = () => {
92
+ remove.mutate(
93
+ {
94
+ model: data.model,
95
+ ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
96
+ context: env.context
97
+ },
98
+ {
99
+ onSuccess,
100
+ onError
101
+ }
102
+ );
103
+ };
104
+ return handleRemoveRow;
105
+ };
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ UseOnChangeFormHandler,
109
+ useRemoveRowHandler,
110
+ useSaveFormHandler
111
+ });
package/dist/form.mjs ADDED
@@ -0,0 +1,82 @@
1
+ // src/widget/form/use-on-change-form.tsx
2
+ import { useOnChangeForm } from "@fctc/interface-logic";
3
+ var UseOnChangeFormHandler = ({
4
+ data,
5
+ onSuccess,
6
+ onError
7
+ }) => {
8
+ const fetchOnchange = useOnChangeForm();
9
+ const handleOnChangeForm = () => {
10
+ fetchOnchange.mutate(
11
+ {
12
+ ids: data.id ? data.id : [],
13
+ model: data.model,
14
+ specification: data.specification,
15
+ context: data.context,
16
+ object: data.object,
17
+ fieldChange: [data.nameField]
18
+ },
19
+ {
20
+ onSuccess,
21
+ onError
22
+ }
23
+ );
24
+ };
25
+ return handleOnChangeForm;
26
+ };
27
+
28
+ // src/widget/form/use-save-form.tsx
29
+ import { useSave } from "@fctc/interface-logic";
30
+ var useSaveFormHandler = ({
31
+ data,
32
+ onSuccess,
33
+ onError
34
+ }) => {
35
+ const fetchSave = useSave();
36
+ const handleSaveForm = () => {
37
+ fetchSave.mutate(
38
+ {
39
+ ids: data.id ? [data.id] : [],
40
+ model: data.model,
41
+ data,
42
+ specification: data.specification,
43
+ context: data.context
44
+ },
45
+ {
46
+ onSuccess,
47
+ onError
48
+ }
49
+ );
50
+ };
51
+ return handleSaveForm;
52
+ };
53
+
54
+ // src/widget/form/use-remove-row.tsx
55
+ import { getEnv, useRemoveRow } from "@fctc/interface-logic";
56
+ var useRemoveRowHandler = ({
57
+ data,
58
+ onSuccess,
59
+ onError
60
+ }) => {
61
+ const remove = useRemoveRow();
62
+ const env = getEnv();
63
+ const handleRemoveRow = () => {
64
+ remove.mutate(
65
+ {
66
+ model: data.model,
67
+ ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
68
+ context: env.context
69
+ },
70
+ {
71
+ onSuccess,
72
+ onError
73
+ }
74
+ );
75
+ };
76
+ return handleRemoveRow;
77
+ };
78
+ export {
79
+ UseOnChangeFormHandler,
80
+ useRemoveRowHandler,
81
+ useSaveFormHandler
82
+ };
package/dist/index.d.mts CHANGED
@@ -1 +1,2 @@
1
- export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType } from './validate.mjs';
1
+
2
+ export { }
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType } from './validate.js';
1
+
2
+ export { }
package/dist/index.js CHANGED
@@ -1,83 +1 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- handleGeneratePasswordMessage: () => handleGeneratePasswordMessage,
24
- handleValidateInput: () => handleValidateInput,
25
- handleValidateInputByType: () => handleValidateInputByType
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/utils/validate.ts
30
- function handleValidateInputByType(value, type) {
31
- if (type === "text") {
32
- return /^[\p{L}\s]+$/u.test(value);
33
- }
34
- if (type === "number") {
35
- return /^[0-9]+$/.test(value);
36
- }
37
- if (type === "email") {
38
- return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
39
- }
40
- if (type === "phone") {
41
- return /^(0|\+?84)[0-9]{9}$/.test(value);
42
- }
43
- return false;
44
- }
45
- function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
46
- let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
47
- if (upcase || upcase === "0") {
48
- message += `, ${upcase} ch\u1EEF in hoa`;
49
- }
50
- if (digit || digit === "0") {
51
- message += `, ${digit} s\u1ED1`;
52
- }
53
- if (special || special === "0") {
54
- message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
55
- }
56
- return message;
57
- }
58
- function handleValidateInput(props) {
59
- const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
60
- if (!value) return true;
61
- if (widget === "custom_passord") {
62
- if (regex && !new RegExp(regex)?.test(value)) {
63
- return handleGeneratePasswordMessage({
64
- min,
65
- max,
66
- upcase,
67
- digit,
68
- special
69
- });
70
- }
71
- return true;
72
- }
73
- if (!widget) return;
74
- const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
75
- if (!inputType) return;
76
- return handleValidateInputByType(value, inputType) || textValidate;
77
- }
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- handleGeneratePasswordMessage,
81
- handleValidateInput,
82
- handleValidateInputByType
83
- });
package/dist/index.mjs CHANGED
@@ -1,54 +0,0 @@
1
- // src/utils/validate.ts
2
- function handleValidateInputByType(value, type) {
3
- if (type === "text") {
4
- return /^[\p{L}\s]+$/u.test(value);
5
- }
6
- if (type === "number") {
7
- return /^[0-9]+$/.test(value);
8
- }
9
- if (type === "email") {
10
- return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
11
- }
12
- if (type === "phone") {
13
- return /^(0|\+?84)[0-9]{9}$/.test(value);
14
- }
15
- return false;
16
- }
17
- function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
18
- let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
19
- if (upcase || upcase === "0") {
20
- message += `, ${upcase} ch\u1EEF in hoa`;
21
- }
22
- if (digit || digit === "0") {
23
- message += `, ${digit} s\u1ED1`;
24
- }
25
- if (special || special === "0") {
26
- message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
27
- }
28
- return message;
29
- }
30
- function handleValidateInput(props) {
31
- const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
32
- if (!value) return true;
33
- if (widget === "custom_passord") {
34
- if (regex && !new RegExp(regex)?.test(value)) {
35
- return handleGeneratePasswordMessage({
36
- min,
37
- max,
38
- upcase,
39
- digit,
40
- special
41
- });
42
- }
43
- return true;
44
- }
45
- if (!widget) return;
46
- const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
47
- if (!inputType) return;
48
- return handleValidateInputByType(value, inputType) || textValidate;
49
- }
50
- export {
51
- handleGeneratePasswordMessage,
52
- handleValidateInput,
53
- handleValidateInputByType
54
- };
@@ -0,0 +1,8 @@
1
+ declare const useTableHandler: ({ fields, data, dataModel, context, typeTable, }: any) => {
2
+ rows: any;
3
+ columns: any;
4
+ onToggleColumnOptional: (item: any) => void;
5
+ typeTable: any;
6
+ };
7
+
8
+ export { useTableHandler };
@@ -0,0 +1,8 @@
1
+ declare const useTableHandler: ({ fields, data, dataModel, context, typeTable, }: any) => {
2
+ rows: any;
3
+ columns: any;
4
+ onToggleColumnOptional: (item: any) => void;
5
+ typeTable: any;
6
+ };
7
+
8
+ export { useTableHandler };
package/dist/table.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/table.ts
21
+ var table_exports = {};
22
+ __export(table_exports, {
23
+ useTableHandler: () => useTableHandler
24
+ });
25
+ module.exports = __toCommonJS(table_exports);
26
+
27
+ // src/widget/table/use-table.tsx
28
+ var import_interface_logic = require("@fctc/interface-logic");
29
+ var import_react = require("react");
30
+ function mergeButtons(fields) {
31
+ const buttons = fields?.filter((f) => f.type_co === "button");
32
+ const others = fields?.filter((f) => f.type_co !== "button");
33
+ if (buttons?.length) {
34
+ others.push({
35
+ type_co: "buttons",
36
+ buttons
37
+ });
38
+ }
39
+ return others;
40
+ }
41
+ var useTableHandler = ({
42
+ fields,
43
+ data,
44
+ dataModel,
45
+ context,
46
+ typeTable
47
+ }) => {
48
+ const [rows, setRows] = (0, import_react.useState)(data || []);
49
+ const [columns, setColumns] = (0, import_react.useState)([]);
50
+ const dataModelFields = fields?.map((field) => {
51
+ return {
52
+ ...dataModel?.[field?.name],
53
+ ...field,
54
+ string: field?.string || dataModel?.[field?.name]?.string
55
+ };
56
+ });
57
+ const mergeFields = mergeButtons(dataModelFields);
58
+ const transformData = (dataList) => {
59
+ if (!dataList) return;
60
+ return dataList?.map((item) => {
61
+ const transformedItem = { ...item };
62
+ Object.keys(item).forEach((field) => {
63
+ if (field !== "__domain") {
64
+ if (item[field] && typeof item[field] === "object" && item[field].display_name) {
65
+ transformedItem[field] = item[field];
66
+ } else if (Array.isArray(item[field]) && item[field].length > 0) {
67
+ if (typeTable === "group" && item[field]?.length === 2 && typeof item[field]?.[1] === "string") {
68
+ transformedItem["string"] = item[field]?.[1];
69
+ }
70
+ transformedItem[field] = item[field];
71
+ }
72
+ }
73
+ });
74
+ return item.display_name ? { ...transformedItem, item: item.display_name } : transformedItem;
75
+ });
76
+ };
77
+ (0, import_react.useEffect)(() => {
78
+ setRows(transformData(data || null));
79
+ }, [data]);
80
+ const handleGetColumns = () => {
81
+ let cols = [];
82
+ try {
83
+ cols = mergeFields?.filter((item) => {
84
+ return item?.widget !== "details_Receive_money" && !(item?.column_invisible ? import_interface_logic.domainHelper.matchDomains(context, item?.column_invisible) : item?.invisible ? import_interface_logic.domainHelper.matchDomains(context, item?.invisible) : false);
85
+ })?.map((field) => {
86
+ return {
87
+ name: field?.name,
88
+ optional: field?.optional,
89
+ title: field?.type_co === "button" ? "" : field?.string,
90
+ field: { ...field }
91
+ };
92
+ });
93
+ } catch (error) {
94
+ console.error("Error in useTable:", error);
95
+ }
96
+ return cols;
97
+ };
98
+ (0, import_react.useEffect)(() => {
99
+ const columns2 = handleGetColumns();
100
+ setColumns(columns2);
101
+ }, [data]);
102
+ const onToggleColumnOptional = (item) => {
103
+ const tempColumn = [...columns]?.map((val) => {
104
+ if (item?.name === val?.name) {
105
+ return {
106
+ ...val,
107
+ optional: item?.optional === "show" ? "hide" : "show"
108
+ };
109
+ }
110
+ return val;
111
+ });
112
+ setColumns(tempColumn);
113
+ };
114
+ return {
115
+ rows,
116
+ columns,
117
+ onToggleColumnOptional,
118
+ typeTable
119
+ };
120
+ };
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ useTableHandler
124
+ });
package/dist/table.mjs ADDED
@@ -0,0 +1,97 @@
1
+ // src/widget/table/use-table.tsx
2
+ import { domainHelper } from "@fctc/interface-logic";
3
+ import { useEffect, useState } from "react";
4
+ function mergeButtons(fields) {
5
+ const buttons = fields?.filter((f) => f.type_co === "button");
6
+ const others = fields?.filter((f) => f.type_co !== "button");
7
+ if (buttons?.length) {
8
+ others.push({
9
+ type_co: "buttons",
10
+ buttons
11
+ });
12
+ }
13
+ return others;
14
+ }
15
+ var useTableHandler = ({
16
+ fields,
17
+ data,
18
+ dataModel,
19
+ context,
20
+ typeTable
21
+ }) => {
22
+ const [rows, setRows] = useState(data || []);
23
+ const [columns, setColumns] = useState([]);
24
+ const dataModelFields = fields?.map((field) => {
25
+ return {
26
+ ...dataModel?.[field?.name],
27
+ ...field,
28
+ string: field?.string || dataModel?.[field?.name]?.string
29
+ };
30
+ });
31
+ const mergeFields = mergeButtons(dataModelFields);
32
+ const transformData = (dataList) => {
33
+ if (!dataList) return;
34
+ return dataList?.map((item) => {
35
+ const transformedItem = { ...item };
36
+ Object.keys(item).forEach((field) => {
37
+ if (field !== "__domain") {
38
+ if (item[field] && typeof item[field] === "object" && item[field].display_name) {
39
+ transformedItem[field] = item[field];
40
+ } else if (Array.isArray(item[field]) && item[field].length > 0) {
41
+ if (typeTable === "group" && item[field]?.length === 2 && typeof item[field]?.[1] === "string") {
42
+ transformedItem["string"] = item[field]?.[1];
43
+ }
44
+ transformedItem[field] = item[field];
45
+ }
46
+ }
47
+ });
48
+ return item.display_name ? { ...transformedItem, item: item.display_name } : transformedItem;
49
+ });
50
+ };
51
+ useEffect(() => {
52
+ setRows(transformData(data || null));
53
+ }, [data]);
54
+ const handleGetColumns = () => {
55
+ let cols = [];
56
+ try {
57
+ cols = mergeFields?.filter((item) => {
58
+ return item?.widget !== "details_Receive_money" && !(item?.column_invisible ? domainHelper.matchDomains(context, item?.column_invisible) : item?.invisible ? domainHelper.matchDomains(context, item?.invisible) : false);
59
+ })?.map((field) => {
60
+ return {
61
+ name: field?.name,
62
+ optional: field?.optional,
63
+ title: field?.type_co === "button" ? "" : field?.string,
64
+ field: { ...field }
65
+ };
66
+ });
67
+ } catch (error) {
68
+ console.error("Error in useTable:", error);
69
+ }
70
+ return cols;
71
+ };
72
+ useEffect(() => {
73
+ const columns2 = handleGetColumns();
74
+ setColumns(columns2);
75
+ }, [data]);
76
+ const onToggleColumnOptional = (item) => {
77
+ const tempColumn = [...columns]?.map((val) => {
78
+ if (item?.name === val?.name) {
79
+ return {
80
+ ...val,
81
+ optional: item?.optional === "show" ? "hide" : "show"
82
+ };
83
+ }
84
+ return val;
85
+ });
86
+ setColumns(tempColumn);
87
+ };
88
+ return {
89
+ rows,
90
+ columns,
91
+ onToggleColumnOptional,
92
+ typeTable
93
+ };
94
+ };
95
+ export {
96
+ useTableHandler
97
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/widget-logic",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -9,13 +9,17 @@
9
9
  "import": "./dist/index.mjs",
10
10
  "require": "./dist/index.cjs"
11
11
  },
12
- "./require": {
13
- "import": "./dist/require.mjs",
14
- "require": "./dist/require.cjs"
12
+ "./action": {
13
+ "import": "./dist/action.mjs",
14
+ "require": "./dist/action.cjs"
15
15
  },
16
- "./validate": {
17
- "import": "./dist/validate.mjs",
18
- "require": "./dist/validate.cjs"
16
+ "./form": {
17
+ "import": "./dist/form.mjs",
18
+ "require": "./dist/form.cjs"
19
+ },
20
+ "./table": {
21
+ "import": "./dist/table.mjs",
22
+ "require": "./dist/table.cjs"
19
23
  }
20
24
  },
21
25
  "files": [
@@ -26,6 +30,10 @@
26
30
  "test": "jest"
27
31
  },
28
32
  "dependencies": {
33
+ "@fctc/interface-logic": "^1.0.1",
34
+ "@types/react": "^19.1.8",
35
+ "react": "18.0.0",
36
+ "react-dom": "18.0.0",
29
37
  "tslib": "^2.8.1"
30
38
  },
31
39
  "devDependencies": {
@@ -1,6 +0,0 @@
1
- declare function handleRequire(props: any): false | {
2
- value: boolean;
3
- message: string;
4
- };
5
-
6
- export { handleRequire };
package/dist/require.d.ts DELETED
@@ -1,6 +0,0 @@
1
- declare function handleRequire(props: any): false | {
2
- value: boolean;
3
- message: string;
4
- };
5
-
6
- export { handleRequire };
package/dist/require.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/require.ts
21
- var require_exports = {};
22
- __export(require_exports, {
23
- handleRequire: () => handleRequire
24
- });
25
- module.exports = __toCommonJS(require_exports);
26
-
27
- // src/utils/require.ts
28
- function handleRequire(props) {
29
- const { required, invisible, string, textRequired } = props;
30
- if (required && !invisible) {
31
- return {
32
- value: true,
33
- message: `${string} ${textRequired}`
34
- };
35
- }
36
- return false;
37
- }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- handleRequire
41
- });
package/dist/require.mjs DELETED
@@ -1,14 +0,0 @@
1
- // src/utils/require.ts
2
- function handleRequire(props) {
3
- const { required, invisible, string, textRequired } = props;
4
- if (required && !invisible) {
5
- return {
6
- value: true,
7
- message: `${string} ${textRequired}`
8
- };
9
- }
10
- return false;
11
- }
12
- export {
13
- handleRequire
14
- };
@@ -1,11 +0,0 @@
1
- declare function handleValidateInputByType(value: string, type: 'text' | 'number' | 'phone' | 'email'): boolean;
2
- declare function handleGeneratePasswordMessage({ min, max, upcase, digit, special }: {
3
- min?: string;
4
- max?: string;
5
- upcase?: string;
6
- digit?: string;
7
- special?: string;
8
- }): string;
9
- declare function handleValidateInput(props: any): any;
10
-
11
- export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType };
@@ -1,11 +0,0 @@
1
- declare function handleValidateInputByType(value: string, type: 'text' | 'number' | 'phone' | 'email'): boolean;
2
- declare function handleGeneratePasswordMessage({ min, max, upcase, digit, special }: {
3
- min?: string;
4
- max?: string;
5
- upcase?: string;
6
- digit?: string;
7
- special?: string;
8
- }): string;
9
- declare function handleValidateInput(props: any): any;
10
-
11
- export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType };
package/dist/validate.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/validate.ts
21
- var validate_exports = {};
22
- __export(validate_exports, {
23
- handleGeneratePasswordMessage: () => handleGeneratePasswordMessage,
24
- handleValidateInput: () => handleValidateInput,
25
- handleValidateInputByType: () => handleValidateInputByType
26
- });
27
- module.exports = __toCommonJS(validate_exports);
28
-
29
- // src/utils/validate.ts
30
- function handleValidateInputByType(value, type) {
31
- if (type === "text") {
32
- return /^[\p{L}\s]+$/u.test(value);
33
- }
34
- if (type === "number") {
35
- return /^[0-9]+$/.test(value);
36
- }
37
- if (type === "email") {
38
- return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
39
- }
40
- if (type === "phone") {
41
- return /^(0|\+?84)[0-9]{9}$/.test(value);
42
- }
43
- return false;
44
- }
45
- function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
46
- let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
47
- if (upcase || upcase === "0") {
48
- message += `, ${upcase} ch\u1EEF in hoa`;
49
- }
50
- if (digit || digit === "0") {
51
- message += `, ${digit} s\u1ED1`;
52
- }
53
- if (special || special === "0") {
54
- message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
55
- }
56
- return message;
57
- }
58
- function handleValidateInput(props) {
59
- const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
60
- if (!value) return true;
61
- if (widget === "custom_passord") {
62
- if (regex && !new RegExp(regex)?.test(value)) {
63
- return handleGeneratePasswordMessage({
64
- min,
65
- max,
66
- upcase,
67
- digit,
68
- special
69
- });
70
- }
71
- return true;
72
- }
73
- if (!widget) return;
74
- const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
75
- if (!inputType) return;
76
- return handleValidateInputByType(value, inputType) || textValidate;
77
- }
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- handleGeneratePasswordMessage,
81
- handleValidateInput,
82
- handleValidateInputByType
83
- });
package/dist/validate.mjs DELETED
@@ -1,54 +0,0 @@
1
- // src/utils/validate.ts
2
- function handleValidateInputByType(value, type) {
3
- if (type === "text") {
4
- return /^[\p{L}\s]+$/u.test(value);
5
- }
6
- if (type === "number") {
7
- return /^[0-9]+$/.test(value);
8
- }
9
- if (type === "email") {
10
- return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
11
- }
12
- if (type === "phone") {
13
- return /^(0|\+?84)[0-9]{9}$/.test(value);
14
- }
15
- return false;
16
- }
17
- function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
18
- let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
19
- if (upcase || upcase === "0") {
20
- message += `, ${upcase} ch\u1EEF in hoa`;
21
- }
22
- if (digit || digit === "0") {
23
- message += `, ${digit} s\u1ED1`;
24
- }
25
- if (special || special === "0") {
26
- message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
27
- }
28
- return message;
29
- }
30
- function handleValidateInput(props) {
31
- const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
32
- if (!value) return true;
33
- if (widget === "custom_passord") {
34
- if (regex && !new RegExp(regex)?.test(value)) {
35
- return handleGeneratePasswordMessage({
36
- min,
37
- max,
38
- upcase,
39
- digit,
40
- special
41
- });
42
- }
43
- return true;
44
- }
45
- if (!widget) return;
46
- const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
47
- if (!inputType) return;
48
- return handleValidateInputByType(value, inputType) || textValidate;
49
- }
50
- export {
51
- handleGeneratePasswordMessage,
52
- handleValidateInput,
53
- handleValidateInputByType
54
- };