@fctc/widget-logic 1.1.0 → 1.1.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.
package/dist/action.mjs DELETED
@@ -1,122 +0,0 @@
1
- // src/action/use-archieve-row.tsx
2
- import { useButton } from "@fctc/interface-logic";
3
- var useArchieveHandler = ({
4
- data,
5
- onSuccess,
6
- onError,
7
- onSettled
8
- }) => {
9
- const archieve = useButton();
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: data.context
17
- },
18
- {
19
- onSuccess,
20
- onError,
21
- onSettled
22
- }
23
- );
24
- };
25
- return handleDuplicateRecord;
26
- };
27
-
28
- // src/action/use-duplicate-row.tsx
29
- import { useDuplicateRecord } from "@fctc/interface-logic";
30
- var useDuplicateRowHandler = ({
31
- data,
32
- onSuccess,
33
- onError,
34
- onSettled
35
- }) => {
36
- const duplicateRecord = useDuplicateRecord();
37
- const handleDuplicateRecord = () => {
38
- duplicateRecord.mutate(
39
- {
40
- model: data.model,
41
- id: Array.isArray(data.ids) ? [...data.ids] : data.ids,
42
- context: data.context
43
- },
44
- {
45
- onSuccess,
46
- onError,
47
- onSettled
48
- }
49
- );
50
- };
51
- return handleDuplicateRecord;
52
- };
53
-
54
- // src/action/use-get-field-export.tsx
55
- import { useGetFieldExport } from "@fctc/interface-logic";
56
- var useGetFieldExportHandler = ({
57
- data,
58
- onSuccess,
59
- onError,
60
- onSettled
61
- }) => {
62
- const fieldExport = useGetFieldExport();
63
- const handleGetFieldExport = () => {
64
- fieldExport.mutate(
65
- {
66
- context: data.context,
67
- ids: data.ids,
68
- model: data.model,
69
- isShow: data.isShow,
70
- fieldType: data.fieldType,
71
- importCompat: data.importCompat,
72
- name: data.name,
73
- parentField: data.parentField,
74
- parentName: data.parentName,
75
- prefix: data.prefix
76
- },
77
- {
78
- onSuccess,
79
- onError,
80
- onSettled
81
- }
82
- );
83
- };
84
- return handleGetFieldExport;
85
- };
86
-
87
- // src/action/use-export-excel.tsx
88
- import { evalJSONDomain, useExportExcel } from "@fctc/interface-logic";
89
- var useExportExcelHandler = ({
90
- data,
91
- onSuccess,
92
- onError,
93
- onSettled
94
- }) => {
95
- const exportExcel = useExportExcel();
96
- const handleExport = () => {
97
- exportExcel.mutate(
98
- {
99
- model: data.model,
100
- ids: data?.ids,
101
- fields: data.fields,
102
- domain: evalJSONDomain(data.domain, data.context),
103
- importCompat: data?.importCompat,
104
- type: data.type,
105
- context: data.context,
106
- groupby: data?.groupby
107
- },
108
- {
109
- onSuccess,
110
- onError,
111
- onSettled
112
- }
113
- );
114
- };
115
- return handleExport;
116
- };
117
- export {
118
- useArchieveHandler,
119
- useDuplicateRowHandler,
120
- useExportExcelHandler,
121
- useGetFieldExportHandler
122
- };
package/dist/form.d.mts DELETED
@@ -1,41 +0,0 @@
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
- onSettled?: (err: any) => void;
13
- }
14
- declare const UseOnChangeFormHandler: ({ data, onSuccess, onError, onSettled, }: UseSaveFormProps$1) => () => void;
15
-
16
- interface UseSaveFormProps {
17
- data: {
18
- context: any;
19
- model: string;
20
- specification: any;
21
- id: number | string;
22
- };
23
- onSuccess?: (res: any) => void;
24
- onError?: (err: any) => void;
25
- onSettled?: (err: any) => void;
26
- }
27
- declare const useSaveFormHandler: ({ data, onSuccess, onError, onSettled, }: UseSaveFormProps) => () => void;
28
-
29
- interface UseDeleteProps {
30
- data: {
31
- model: string;
32
- ids: number[];
33
- context: any;
34
- };
35
- onSuccess?: (res: any) => void;
36
- onError?: (err: any) => void;
37
- onSettled?: (err: any) => void;
38
- }
39
- declare const useRemoveRowHandler: ({ data, onSuccess, onError, onSettled, }: UseDeleteProps) => () => void;
40
-
41
- export { UseOnChangeFormHandler, useRemoveRowHandler, useSaveFormHandler };
package/dist/form.d.ts DELETED
@@ -1,41 +0,0 @@
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
- onSettled?: (err: any) => void;
13
- }
14
- declare const UseOnChangeFormHandler: ({ data, onSuccess, onError, onSettled, }: UseSaveFormProps$1) => () => void;
15
-
16
- interface UseSaveFormProps {
17
- data: {
18
- context: any;
19
- model: string;
20
- specification: any;
21
- id: number | string;
22
- };
23
- onSuccess?: (res: any) => void;
24
- onError?: (err: any) => void;
25
- onSettled?: (err: any) => void;
26
- }
27
- declare const useSaveFormHandler: ({ data, onSuccess, onError, onSettled, }: UseSaveFormProps) => () => void;
28
-
29
- interface UseDeleteProps {
30
- data: {
31
- model: string;
32
- ids: number[];
33
- context: any;
34
- };
35
- onSuccess?: (res: any) => void;
36
- onError?: (err: any) => void;
37
- onSettled?: (err: any) => void;
38
- }
39
- declare const useRemoveRowHandler: ({ data, onSuccess, onError, onSettled, }: UseDeleteProps) => () => void;
40
-
41
- export { UseOnChangeFormHandler, useRemoveRowHandler, useSaveFormHandler };
package/dist/form.js DELETED
@@ -1,116 +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/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
- onSettled
36
- }) => {
37
- const fetchOnchange = (0, import_interface_logic.useOnChangeForm)();
38
- const handleOnChangeForm = () => {
39
- fetchOnchange.mutate(
40
- {
41
- ids: data.id ? data.id : [],
42
- model: data.model,
43
- specification: data.specification,
44
- context: data.context,
45
- object: data.object,
46
- fieldChange: [data.nameField]
47
- },
48
- {
49
- onSuccess,
50
- onError,
51
- onSettled
52
- }
53
- );
54
- };
55
- return handleOnChangeForm;
56
- };
57
-
58
- // src/widget/form/use-save-form.tsx
59
- var import_interface_logic2 = require("@fctc/interface-logic");
60
- var useSaveFormHandler = ({
61
- data,
62
- onSuccess,
63
- onError,
64
- onSettled
65
- }) => {
66
- const fetchSave = (0, import_interface_logic2.useSave)();
67
- const handleSaveForm = () => {
68
- fetchSave.mutate(
69
- {
70
- ids: data.id ? [data.id] : [],
71
- model: data.model,
72
- data,
73
- specification: data.specification,
74
- context: data.context
75
- },
76
- {
77
- onSuccess,
78
- onError,
79
- onSettled
80
- }
81
- );
82
- };
83
- return handleSaveForm;
84
- };
85
-
86
- // src/widget/form/use-remove-row.tsx
87
- var import_interface_logic3 = require("@fctc/interface-logic");
88
- var useRemoveRowHandler = ({
89
- data,
90
- onSuccess,
91
- onError,
92
- onSettled
93
- }) => {
94
- const remove = (0, import_interface_logic3.useRemoveRow)();
95
- const handleRemoveRow = () => {
96
- remove.mutate(
97
- {
98
- model: data.model,
99
- ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
100
- context: data.context
101
- },
102
- {
103
- onSuccess,
104
- onError,
105
- onSettled
106
- }
107
- );
108
- };
109
- return handleRemoveRow;
110
- };
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- UseOnChangeFormHandler,
114
- useRemoveRowHandler,
115
- useSaveFormHandler
116
- });
package/dist/form.mjs DELETED
@@ -1,87 +0,0 @@
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
- onSettled
8
- }) => {
9
- const fetchOnchange = useOnChangeForm();
10
- const handleOnChangeForm = () => {
11
- fetchOnchange.mutate(
12
- {
13
- ids: data.id ? data.id : [],
14
- model: data.model,
15
- specification: data.specification,
16
- context: data.context,
17
- object: data.object,
18
- fieldChange: [data.nameField]
19
- },
20
- {
21
- onSuccess,
22
- onError,
23
- onSettled
24
- }
25
- );
26
- };
27
- return handleOnChangeForm;
28
- };
29
-
30
- // src/widget/form/use-save-form.tsx
31
- import { useSave } from "@fctc/interface-logic";
32
- var useSaveFormHandler = ({
33
- data,
34
- onSuccess,
35
- onError,
36
- onSettled
37
- }) => {
38
- const fetchSave = useSave();
39
- const handleSaveForm = () => {
40
- fetchSave.mutate(
41
- {
42
- ids: data.id ? [data.id] : [],
43
- model: data.model,
44
- data,
45
- specification: data.specification,
46
- context: data.context
47
- },
48
- {
49
- onSuccess,
50
- onError,
51
- onSettled
52
- }
53
- );
54
- };
55
- return handleSaveForm;
56
- };
57
-
58
- // src/widget/form/use-remove-row.tsx
59
- import { useRemoveRow } from "@fctc/interface-logic";
60
- var useRemoveRowHandler = ({
61
- data,
62
- onSuccess,
63
- onError,
64
- onSettled
65
- }) => {
66
- const remove = useRemoveRow();
67
- const handleRemoveRow = () => {
68
- remove.mutate(
69
- {
70
- model: data.model,
71
- ids: Array.isArray(data.ids) ? [...data.ids] : data.ids,
72
- context: data.context
73
- },
74
- {
75
- onSuccess,
76
- onError,
77
- onSettled
78
- }
79
- );
80
- };
81
- return handleRemoveRow;
82
- };
83
- export {
84
- UseOnChangeFormHandler,
85
- useRemoveRowHandler,
86
- useSaveFormHandler
87
- };
package/dist/table.d.mts DELETED
@@ -1,8 +0,0 @@
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.d.ts DELETED
@@ -1,8 +0,0 @@
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 DELETED
@@ -1,124 +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/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 DELETED
@@ -1,97 +0,0 @@
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
- };