@etsoo/materialui 1.6.22 → 1.6.24
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/lib/cjs/FabBox.js +1 -1
- package/lib/cjs/ResponsibleContainer.js +4 -9
- package/lib/cjs/ViewContainer.d.ts +1 -1
- package/lib/cjs/custom/CustomFieldViewUI.d.ts +18 -0
- package/lib/cjs/custom/CustomFieldViewUI.js +139 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/FabBox.js +1 -1
- package/lib/mjs/ResponsibleContainer.js +4 -9
- package/lib/mjs/ViewContainer.d.ts +1 -1
- package/lib/mjs/custom/CustomFieldViewUI.d.ts +18 -0
- package/lib/mjs/custom/CustomFieldViewUI.js +136 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/package.json +2 -2
- package/src/FabBox.tsx +1 -1
- package/src/ResponsibleContainer.tsx +4 -13
- package/src/ViewContainer.tsx +15 -15
- package/src/custom/CustomFieldViewUI.tsx +163 -0
- package/src/index.ts +1 -0
package/lib/cjs/FabBox.js
CHANGED
|
@@ -9,7 +9,7 @@ const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
|
9
9
|
const Paper_1 = __importDefault(require("@mui/material/Paper"));
|
|
10
10
|
const styles_1 = require("@mui/material/styles");
|
|
11
11
|
const react_1 = __importDefault(require("react"));
|
|
12
|
-
const initOpactiy = 0.
|
|
12
|
+
const initOpactiy = 0.25;
|
|
13
13
|
/**
|
|
14
14
|
* Fabs container box
|
|
15
15
|
* @param props Props
|
|
@@ -133,20 +133,15 @@ function ResponsibleContainer(props) {
|
|
|
133
133
|
return ((0, jsx_runtime_1.jsx)(Box_1.default, { className: "ListBox", sx: { height: heightLocal }, children: (0, jsx_runtime_1.jsx)(ScrollerListEx_1.ScrollerListEx, { autoLoad: !hasFields, cacheKey: cacheKey, cacheMinutes: cacheMinutes, height: heightLocal, loadData: localLoadData, mRef: mRefs, onClick: (event, data) => quickAction && react_2.ReactUtils.isSafeClick(event) && quickAction(data), rowHeight: getRowHeight(false), ...listProps }) }));
|
|
134
134
|
})();
|
|
135
135
|
const searchBar = react_1.default.useMemo(() => {
|
|
136
|
-
if (!hasFields ||
|
|
137
|
-
showDataGrid == null ||
|
|
138
|
-
rect?.width == null ||
|
|
139
|
-
rect.width < 20)
|
|
136
|
+
if (!hasFields || rect?.width == null || rect.width < 20)
|
|
140
137
|
return;
|
|
141
138
|
const f = typeof fields == "function" ? fields(searchData) : fields;
|
|
142
139
|
return ((0, jsx_runtime_1.jsx)(SearchBar_1.SearchBar, { fields: f, onSubmit: onSubmit, className: `searchBar${showDataGrid ? "Grid" : "List"}`, width: rect.width, top: searchBarTop }));
|
|
143
140
|
}, [showDataGrid, hasFields, searchBarHeight, rect?.width]);
|
|
144
141
|
// Pull container
|
|
145
|
-
const pullContainer = showDataGrid
|
|
146
|
-
?
|
|
147
|
-
:
|
|
148
|
-
? ".DataGridEx-Body"
|
|
149
|
-
: ".ScrollerListEx-Body";
|
|
142
|
+
const pullContainer = showDataGrid
|
|
143
|
+
? ".DataGridEx-Body"
|
|
144
|
+
: ".ScrollerListEx-Body";
|
|
150
145
|
// Layout
|
|
151
146
|
return ((0, jsx_runtime_1.jsxs)(Box_1.default, { sx: containerBoxSx == null
|
|
152
147
|
? undefined
|
|
@@ -6,7 +6,7 @@ import { Breakpoint } from "@mui/material/styles";
|
|
|
6
6
|
/**
|
|
7
7
|
* View page item size
|
|
8
8
|
*/
|
|
9
|
-
export type ViewPageItemSize = Record<Breakpoint, number
|
|
9
|
+
export type ViewPageItemSize = Partial<Record<Breakpoint, number>>;
|
|
10
10
|
/**
|
|
11
11
|
* View page grid item size
|
|
12
12
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CustomFieldData } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
|
+
import { ViewContainerProps } from "../ViewContainer";
|
|
4
|
+
/**
|
|
5
|
+
* Custom field view UI Props
|
|
6
|
+
*/
|
|
7
|
+
export type CustomFieldViewUIProps<T extends DataTypes.StringRecord> = Omit<ViewContainerProps<T>, "fields"> & {
|
|
8
|
+
/**
|
|
9
|
+
* Custom fields
|
|
10
|
+
*/
|
|
11
|
+
fields: CustomFieldData[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Custom field view UI
|
|
15
|
+
* @param props Props
|
|
16
|
+
* @returns Component
|
|
17
|
+
*/
|
|
18
|
+
export declare function CustomFieldViewUI<T extends DataTypes.StringRecord>(props: CustomFieldViewUIProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomFieldViewUI = CustomFieldViewUI;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const shared_1 = require("@etsoo/shared");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const ViewContainer_1 = require("../ViewContainer");
|
|
8
|
+
const ReactApp_1 = require("../app/ReactApp");
|
|
9
|
+
/**
|
|
10
|
+
* Transform custom field space
|
|
11
|
+
* @param space Space
|
|
12
|
+
* @returns Result
|
|
13
|
+
*/
|
|
14
|
+
function transformSize(space) {
|
|
15
|
+
if (space == null)
|
|
16
|
+
return undefined;
|
|
17
|
+
switch (space) {
|
|
18
|
+
case "full":
|
|
19
|
+
return true;
|
|
20
|
+
case "quater":
|
|
21
|
+
return "medium";
|
|
22
|
+
case "five":
|
|
23
|
+
return { xs: 12, sm: 12, md: 5, lg: 4, xl: 3 };
|
|
24
|
+
case "seven":
|
|
25
|
+
return { xs: 12, sm: 12, md: 7, lg: 6, xl: 5 };
|
|
26
|
+
default:
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Custom field view UI
|
|
32
|
+
* @param props Props
|
|
33
|
+
* @returns Component
|
|
34
|
+
*/
|
|
35
|
+
function CustomFieldViewUI(props) {
|
|
36
|
+
// Destruct
|
|
37
|
+
const { fields, ...rest } = props;
|
|
38
|
+
// App
|
|
39
|
+
const app = (0, ReactApp_1.useRequiredAppContext)();
|
|
40
|
+
// Mapping
|
|
41
|
+
const mappedFields = fields.map((f) => {
|
|
42
|
+
const type = f.type;
|
|
43
|
+
const label = f.label ? (app.get(f.label) ?? f.label) : undefined;
|
|
44
|
+
const singleRow = transformSize(f.space);
|
|
45
|
+
const name = f.name ?? "";
|
|
46
|
+
let item;
|
|
47
|
+
switch (type) {
|
|
48
|
+
case "amountlabel":
|
|
49
|
+
const currency = f.mainSlotProps?.currency;
|
|
50
|
+
const symbol = currency ? shared_1.NumberUtils.getCurrencySymbol(currency) : "";
|
|
51
|
+
item = {
|
|
52
|
+
label: "",
|
|
53
|
+
singleRow,
|
|
54
|
+
data: label
|
|
55
|
+
? () => `${symbol}${app.formatNumber(parseFloat(label))}`
|
|
56
|
+
: () => ""
|
|
57
|
+
};
|
|
58
|
+
break;
|
|
59
|
+
case "checkbox":
|
|
60
|
+
case "combobox":
|
|
61
|
+
case "radio":
|
|
62
|
+
case "select":
|
|
63
|
+
item = {
|
|
64
|
+
label,
|
|
65
|
+
singleRow,
|
|
66
|
+
data: (data) => {
|
|
67
|
+
const value = data[name];
|
|
68
|
+
if (value == null)
|
|
69
|
+
return undefined;
|
|
70
|
+
const values = Array.isArray(value) ? value : [value];
|
|
71
|
+
const options = f.options ?? [];
|
|
72
|
+
const selectedOptions = options.filter((o) => values.includes(o.id));
|
|
73
|
+
return selectedOptions
|
|
74
|
+
.map((o) => {
|
|
75
|
+
const label = shared_1.DataTypes.getListItemLabel(o);
|
|
76
|
+
return app.get(label) ?? label;
|
|
77
|
+
})
|
|
78
|
+
.join(", ");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
break;
|
|
82
|
+
case "date":
|
|
83
|
+
item = {
|
|
84
|
+
label,
|
|
85
|
+
singleRow,
|
|
86
|
+
data: (data) => {
|
|
87
|
+
const value = data[name];
|
|
88
|
+
if (value == null)
|
|
89
|
+
return undefined;
|
|
90
|
+
return typeof value === "string"
|
|
91
|
+
? (shared_1.DateUtils.parse(value)?.toLocaleDateString() ?? value)
|
|
92
|
+
: value instanceof Date
|
|
93
|
+
? value.toLocaleDateString()
|
|
94
|
+
: `${value}`;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
break;
|
|
98
|
+
case "divider":
|
|
99
|
+
item = {
|
|
100
|
+
label,
|
|
101
|
+
singleRow,
|
|
102
|
+
data: () => (0, jsx_runtime_1.jsx)(material_1.Divider, {})
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
case "json":
|
|
106
|
+
item = {
|
|
107
|
+
label,
|
|
108
|
+
singleRow,
|
|
109
|
+
data: (data) => {
|
|
110
|
+
const value = data[name];
|
|
111
|
+
if (value == null)
|
|
112
|
+
return undefined;
|
|
113
|
+
return JSON.stringify(value, null, 2);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
break;
|
|
117
|
+
case "number":
|
|
118
|
+
const numberCurrency = f.mainSlotProps?.currency;
|
|
119
|
+
const numberSymbol = numberCurrency
|
|
120
|
+
? shared_1.NumberUtils.getCurrencySymbol(numberCurrency)
|
|
121
|
+
: "";
|
|
122
|
+
item = {
|
|
123
|
+
label: numberCurrency ? `${label} (${numberCurrency})` : label,
|
|
124
|
+
singleRow,
|
|
125
|
+
data: (data) => {
|
|
126
|
+
const value = shared_1.NumberUtils.parse(data[name]);
|
|
127
|
+
return value == null
|
|
128
|
+
? undefined
|
|
129
|
+
: `${numberSymbol}${app.formatNumber(value)}`;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
item = { label, singleRow, data: name };
|
|
135
|
+
}
|
|
136
|
+
return item;
|
|
137
|
+
});
|
|
138
|
+
return (0, jsx_runtime_1.jsx)(ViewContainer_1.ViewContainer, { fields: mappedFields, ...rest });
|
|
139
|
+
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./custom/CustomAttributeArea";
|
|
|
10
10
|
export * from "./custom/CustomFieldUI";
|
|
11
11
|
export * from "./custom/CustomFieldUtils";
|
|
12
12
|
export * from "./custom/CustomFieldViewer";
|
|
13
|
+
export * from "./custom/CustomFieldViewUI";
|
|
13
14
|
export * from "./custom/CustomFieldWindow";
|
|
14
15
|
export * from "./html/HtmlDiv";
|
|
15
16
|
export * from "./messages/MessageUtils";
|
package/lib/cjs/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./custom/CustomAttributeArea"), exports);
|
|
|
26
26
|
__exportStar(require("./custom/CustomFieldUI"), exports);
|
|
27
27
|
__exportStar(require("./custom/CustomFieldUtils"), exports);
|
|
28
28
|
__exportStar(require("./custom/CustomFieldViewer"), exports);
|
|
29
|
+
__exportStar(require("./custom/CustomFieldViewUI"), exports);
|
|
29
30
|
__exportStar(require("./custom/CustomFieldWindow"), exports);
|
|
30
31
|
__exportStar(require("./html/HtmlDiv"), exports);
|
|
31
32
|
__exportStar(require("./messages/MessageUtils"), exports);
|
package/lib/mjs/FabBox.js
CHANGED
|
@@ -127,20 +127,15 @@ export function ResponsibleContainer(props) {
|
|
|
127
127
|
return (_jsx(Box, { className: "ListBox", sx: { height: heightLocal }, children: _jsx(ScrollerListEx, { autoLoad: !hasFields, cacheKey: cacheKey, cacheMinutes: cacheMinutes, height: heightLocal, loadData: localLoadData, mRef: mRefs, onClick: (event, data) => quickAction && ReactUtils.isSafeClick(event) && quickAction(data), rowHeight: getRowHeight(false), ...listProps }) }));
|
|
128
128
|
})();
|
|
129
129
|
const searchBar = React.useMemo(() => {
|
|
130
|
-
if (!hasFields ||
|
|
131
|
-
showDataGrid == null ||
|
|
132
|
-
rect?.width == null ||
|
|
133
|
-
rect.width < 20)
|
|
130
|
+
if (!hasFields || rect?.width == null || rect.width < 20)
|
|
134
131
|
return;
|
|
135
132
|
const f = typeof fields == "function" ? fields(searchData) : fields;
|
|
136
133
|
return (_jsx(SearchBar, { fields: f, onSubmit: onSubmit, className: `searchBar${showDataGrid ? "Grid" : "List"}`, width: rect.width, top: searchBarTop }));
|
|
137
134
|
}, [showDataGrid, hasFields, searchBarHeight, rect?.width]);
|
|
138
135
|
// Pull container
|
|
139
|
-
const pullContainer = showDataGrid
|
|
140
|
-
?
|
|
141
|
-
:
|
|
142
|
-
? ".DataGridEx-Body"
|
|
143
|
-
: ".ScrollerListEx-Body";
|
|
136
|
+
const pullContainer = showDataGrid
|
|
137
|
+
? ".DataGridEx-Body"
|
|
138
|
+
: ".ScrollerListEx-Body";
|
|
144
139
|
// Layout
|
|
145
140
|
return (_jsxs(Box, { sx: containerBoxSx == null
|
|
146
141
|
? undefined
|
|
@@ -6,7 +6,7 @@ import { Breakpoint } from "@mui/material/styles";
|
|
|
6
6
|
/**
|
|
7
7
|
* View page item size
|
|
8
8
|
*/
|
|
9
|
-
export type ViewPageItemSize = Record<Breakpoint, number
|
|
9
|
+
export type ViewPageItemSize = Partial<Record<Breakpoint, number>>;
|
|
10
10
|
/**
|
|
11
11
|
* View page grid item size
|
|
12
12
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CustomFieldData } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
|
+
import { ViewContainerProps } from "../ViewContainer";
|
|
4
|
+
/**
|
|
5
|
+
* Custom field view UI Props
|
|
6
|
+
*/
|
|
7
|
+
export type CustomFieldViewUIProps<T extends DataTypes.StringRecord> = Omit<ViewContainerProps<T>, "fields"> & {
|
|
8
|
+
/**
|
|
9
|
+
* Custom fields
|
|
10
|
+
*/
|
|
11
|
+
fields: CustomFieldData[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Custom field view UI
|
|
15
|
+
* @param props Props
|
|
16
|
+
* @returns Component
|
|
17
|
+
*/
|
|
18
|
+
export declare function CustomFieldViewUI<T extends DataTypes.StringRecord>(props: CustomFieldViewUIProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DataTypes, DateUtils, NumberUtils } from "@etsoo/shared";
|
|
3
|
+
import { Divider } from "@mui/material";
|
|
4
|
+
import { ViewContainer } from "../ViewContainer";
|
|
5
|
+
import { useRequiredAppContext } from "../app/ReactApp";
|
|
6
|
+
/**
|
|
7
|
+
* Transform custom field space
|
|
8
|
+
* @param space Space
|
|
9
|
+
* @returns Result
|
|
10
|
+
*/
|
|
11
|
+
function transformSize(space) {
|
|
12
|
+
if (space == null)
|
|
13
|
+
return undefined;
|
|
14
|
+
switch (space) {
|
|
15
|
+
case "full":
|
|
16
|
+
return true;
|
|
17
|
+
case "quater":
|
|
18
|
+
return "medium";
|
|
19
|
+
case "five":
|
|
20
|
+
return { xs: 12, sm: 12, md: 5, lg: 4, xl: 3 };
|
|
21
|
+
case "seven":
|
|
22
|
+
return { xs: 12, sm: 12, md: 7, lg: 6, xl: 5 };
|
|
23
|
+
default:
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Custom field view UI
|
|
29
|
+
* @param props Props
|
|
30
|
+
* @returns Component
|
|
31
|
+
*/
|
|
32
|
+
export function CustomFieldViewUI(props) {
|
|
33
|
+
// Destruct
|
|
34
|
+
const { fields, ...rest } = props;
|
|
35
|
+
// App
|
|
36
|
+
const app = useRequiredAppContext();
|
|
37
|
+
// Mapping
|
|
38
|
+
const mappedFields = fields.map((f) => {
|
|
39
|
+
const type = f.type;
|
|
40
|
+
const label = f.label ? (app.get(f.label) ?? f.label) : undefined;
|
|
41
|
+
const singleRow = transformSize(f.space);
|
|
42
|
+
const name = f.name ?? "";
|
|
43
|
+
let item;
|
|
44
|
+
switch (type) {
|
|
45
|
+
case "amountlabel":
|
|
46
|
+
const currency = f.mainSlotProps?.currency;
|
|
47
|
+
const symbol = currency ? NumberUtils.getCurrencySymbol(currency) : "";
|
|
48
|
+
item = {
|
|
49
|
+
label: "",
|
|
50
|
+
singleRow,
|
|
51
|
+
data: label
|
|
52
|
+
? () => `${symbol}${app.formatNumber(parseFloat(label))}`
|
|
53
|
+
: () => ""
|
|
54
|
+
};
|
|
55
|
+
break;
|
|
56
|
+
case "checkbox":
|
|
57
|
+
case "combobox":
|
|
58
|
+
case "radio":
|
|
59
|
+
case "select":
|
|
60
|
+
item = {
|
|
61
|
+
label,
|
|
62
|
+
singleRow,
|
|
63
|
+
data: (data) => {
|
|
64
|
+
const value = data[name];
|
|
65
|
+
if (value == null)
|
|
66
|
+
return undefined;
|
|
67
|
+
const values = Array.isArray(value) ? value : [value];
|
|
68
|
+
const options = f.options ?? [];
|
|
69
|
+
const selectedOptions = options.filter((o) => values.includes(o.id));
|
|
70
|
+
return selectedOptions
|
|
71
|
+
.map((o) => {
|
|
72
|
+
const label = DataTypes.getListItemLabel(o);
|
|
73
|
+
return app.get(label) ?? label;
|
|
74
|
+
})
|
|
75
|
+
.join(", ");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
break;
|
|
79
|
+
case "date":
|
|
80
|
+
item = {
|
|
81
|
+
label,
|
|
82
|
+
singleRow,
|
|
83
|
+
data: (data) => {
|
|
84
|
+
const value = data[name];
|
|
85
|
+
if (value == null)
|
|
86
|
+
return undefined;
|
|
87
|
+
return typeof value === "string"
|
|
88
|
+
? (DateUtils.parse(value)?.toLocaleDateString() ?? value)
|
|
89
|
+
: value instanceof Date
|
|
90
|
+
? value.toLocaleDateString()
|
|
91
|
+
: `${value}`;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
break;
|
|
95
|
+
case "divider":
|
|
96
|
+
item = {
|
|
97
|
+
label,
|
|
98
|
+
singleRow,
|
|
99
|
+
data: () => _jsx(Divider, {})
|
|
100
|
+
};
|
|
101
|
+
break;
|
|
102
|
+
case "json":
|
|
103
|
+
item = {
|
|
104
|
+
label,
|
|
105
|
+
singleRow,
|
|
106
|
+
data: (data) => {
|
|
107
|
+
const value = data[name];
|
|
108
|
+
if (value == null)
|
|
109
|
+
return undefined;
|
|
110
|
+
return JSON.stringify(value, null, 2);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
114
|
+
case "number":
|
|
115
|
+
const numberCurrency = f.mainSlotProps?.currency;
|
|
116
|
+
const numberSymbol = numberCurrency
|
|
117
|
+
? NumberUtils.getCurrencySymbol(numberCurrency)
|
|
118
|
+
: "";
|
|
119
|
+
item = {
|
|
120
|
+
label: numberCurrency ? `${label} (${numberCurrency})` : label,
|
|
121
|
+
singleRow,
|
|
122
|
+
data: (data) => {
|
|
123
|
+
const value = NumberUtils.parse(data[name]);
|
|
124
|
+
return value == null
|
|
125
|
+
? undefined
|
|
126
|
+
: `${numberSymbol}${app.formatNumber(value)}`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
item = { label, singleRow, data: name };
|
|
132
|
+
}
|
|
133
|
+
return item;
|
|
134
|
+
});
|
|
135
|
+
return _jsx(ViewContainer, { fields: mappedFields, ...rest });
|
|
136
|
+
}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./custom/CustomAttributeArea";
|
|
|
10
10
|
export * from "./custom/CustomFieldUI";
|
|
11
11
|
export * from "./custom/CustomFieldUtils";
|
|
12
12
|
export * from "./custom/CustomFieldViewer";
|
|
13
|
+
export * from "./custom/CustomFieldViewUI";
|
|
13
14
|
export * from "./custom/CustomFieldWindow";
|
|
14
15
|
export * from "./html/HtmlDiv";
|
|
15
16
|
export * from "./messages/MessageUtils";
|
package/lib/mjs/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./custom/CustomAttributeArea";
|
|
|
10
10
|
export * from "./custom/CustomFieldUI";
|
|
11
11
|
export * from "./custom/CustomFieldUtils";
|
|
12
12
|
export * from "./custom/CustomFieldViewer";
|
|
13
|
+
export * from "./custom/CustomFieldViewUI";
|
|
13
14
|
export * from "./custom/CustomFieldWindow";
|
|
14
15
|
export * from "./html/HtmlDiv";
|
|
15
16
|
export * from "./messages/MessageUtils";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.24",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@emotion/styled": "^11.14.1",
|
|
42
42
|
"@etsoo/appscript": "^1.6.56",
|
|
43
43
|
"@etsoo/notificationbase": "^1.1.66",
|
|
44
|
-
"@etsoo/react": "^1.8.
|
|
44
|
+
"@etsoo/react": "^1.8.79",
|
|
45
45
|
"@etsoo/shared": "^1.2.80",
|
|
46
46
|
"@mui/icons-material": "^7.3.9",
|
|
47
47
|
"@mui/material": "^7.3.9",
|
package/src/FabBox.tsx
CHANGED
|
@@ -373,13 +373,7 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
373
373
|
})();
|
|
374
374
|
|
|
375
375
|
const searchBar = React.useMemo(() => {
|
|
376
|
-
if (
|
|
377
|
-
!hasFields ||
|
|
378
|
-
showDataGrid == null ||
|
|
379
|
-
rect?.width == null ||
|
|
380
|
-
rect.width < 20
|
|
381
|
-
)
|
|
382
|
-
return;
|
|
376
|
+
if (!hasFields || rect?.width == null || rect.width < 20) return;
|
|
383
377
|
|
|
384
378
|
const f = typeof fields == "function" ? fields(searchData) : fields;
|
|
385
379
|
|
|
@@ -395,12 +389,9 @@ export function ResponsibleContainer<T extends object, F>(
|
|
|
395
389
|
}, [showDataGrid, hasFields, searchBarHeight, rect?.width]);
|
|
396
390
|
|
|
397
391
|
// Pull container
|
|
398
|
-
const pullContainer =
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
: showDataGrid
|
|
402
|
-
? ".DataGridEx-Body"
|
|
403
|
-
: ".ScrollerListEx-Body";
|
|
392
|
+
const pullContainer = showDataGrid
|
|
393
|
+
? ".DataGridEx-Body"
|
|
394
|
+
: ".ScrollerListEx-Body";
|
|
404
395
|
|
|
405
396
|
// Layout
|
|
406
397
|
return (
|
package/src/ViewContainer.tsx
CHANGED
|
@@ -25,14 +25,14 @@ function getResp(singleRow: ViewPageRowType) {
|
|
|
25
25
|
typeof singleRow === "object"
|
|
26
26
|
? singleRow
|
|
27
27
|
: singleRow === "medium"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
? ViewPageSize.medium
|
|
29
|
+
: singleRow === "large"
|
|
30
|
+
? ViewPageSize.large
|
|
31
|
+
: singleRow === true
|
|
32
|
+
? ViewPageSize.line
|
|
33
|
+
: singleRow === false
|
|
34
|
+
? ViewPageSize.smallLine
|
|
35
|
+
: ViewPageSize.small;
|
|
36
36
|
return size;
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -93,12 +93,12 @@ function getItemField<T extends object>(
|
|
|
93
93
|
fieldLabel === ""
|
|
94
94
|
? undefined
|
|
95
95
|
: fieldLabel == null && typeof fieldData === "string"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
? addLabelEnd(app.get<string>(fieldData) ?? fieldData)
|
|
97
|
+
: typeof fieldLabel === "function"
|
|
98
|
+
? fieldLabel(data)
|
|
99
|
+
: fieldLabel != null
|
|
100
|
+
? addLabelEnd(app.get<string>(fieldLabel) ?? fieldLabel)
|
|
101
|
+
: undefined;
|
|
102
102
|
} else {
|
|
103
103
|
// Single field format
|
|
104
104
|
itemData = formatItemData(app, data[field]);
|
|
@@ -126,7 +126,7 @@ function getItemSize(bp: Breakpoint, size: ViewPageItemSize) {
|
|
|
126
126
|
/**
|
|
127
127
|
* View page item size
|
|
128
128
|
*/
|
|
129
|
-
export type ViewPageItemSize = Record<Breakpoint, number
|
|
129
|
+
export type ViewPageItemSize = Partial<Record<Breakpoint, number>>;
|
|
130
130
|
|
|
131
131
|
const breakpoints: Breakpoint[] = ["xs", "sm", "md", "lg", "xl"];
|
|
132
132
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { CustomFieldData, CustomFieldSpace } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes, DateUtils, NumberUtils } from "@etsoo/shared";
|
|
3
|
+
import { Divider } from "@mui/material";
|
|
4
|
+
import {
|
|
5
|
+
ViewContainer,
|
|
6
|
+
ViewContainerProps,
|
|
7
|
+
ViewPageFieldType,
|
|
8
|
+
ViewPageRowType
|
|
9
|
+
} from "../ViewContainer";
|
|
10
|
+
import { useRequiredAppContext } from "../app/ReactApp";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom field view UI Props
|
|
14
|
+
*/
|
|
15
|
+
export type CustomFieldViewUIProps<T extends DataTypes.StringRecord> = Omit<
|
|
16
|
+
ViewContainerProps<T>,
|
|
17
|
+
"fields"
|
|
18
|
+
> & {
|
|
19
|
+
/**
|
|
20
|
+
* Custom fields
|
|
21
|
+
*/
|
|
22
|
+
fields: CustomFieldData[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Transform custom field space
|
|
27
|
+
* @param space Space
|
|
28
|
+
* @returns Result
|
|
29
|
+
*/
|
|
30
|
+
function transformSize(space?: CustomFieldSpace): ViewPageRowType | undefined {
|
|
31
|
+
if (space == null) return undefined;
|
|
32
|
+
|
|
33
|
+
switch (space) {
|
|
34
|
+
case "full":
|
|
35
|
+
return true;
|
|
36
|
+
case "quater":
|
|
37
|
+
return "medium";
|
|
38
|
+
case "five":
|
|
39
|
+
return { xs: 12, sm: 12, md: 5, lg: 4, xl: 3 };
|
|
40
|
+
case "seven":
|
|
41
|
+
return { xs: 12, sm: 12, md: 7, lg: 6, xl: 5 };
|
|
42
|
+
default:
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Custom field view UI
|
|
49
|
+
* @param props Props
|
|
50
|
+
* @returns Component
|
|
51
|
+
*/
|
|
52
|
+
export function CustomFieldViewUI<T extends DataTypes.StringRecord>(
|
|
53
|
+
props: CustomFieldViewUIProps<T>
|
|
54
|
+
) {
|
|
55
|
+
// Destruct
|
|
56
|
+
const { fields, ...rest } = props;
|
|
57
|
+
|
|
58
|
+
// App
|
|
59
|
+
const app = useRequiredAppContext();
|
|
60
|
+
|
|
61
|
+
// Mapping
|
|
62
|
+
const mappedFields = fields.map((f) => {
|
|
63
|
+
const type = f.type;
|
|
64
|
+
const label = f.label ? (app.get(f.label) ?? f.label) : undefined;
|
|
65
|
+
const singleRow = transformSize(f.space);
|
|
66
|
+
const name = f.name ?? "";
|
|
67
|
+
let item: ViewPageFieldType<T>;
|
|
68
|
+
switch (type) {
|
|
69
|
+
case "amountlabel":
|
|
70
|
+
const currency = f.mainSlotProps?.currency;
|
|
71
|
+
const symbol = currency ? NumberUtils.getCurrencySymbol(currency) : "";
|
|
72
|
+
item = {
|
|
73
|
+
label: "",
|
|
74
|
+
singleRow,
|
|
75
|
+
data: label
|
|
76
|
+
? () => `${symbol}${app.formatNumber(parseFloat(label))}`
|
|
77
|
+
: () => ""
|
|
78
|
+
};
|
|
79
|
+
break;
|
|
80
|
+
case "checkbox":
|
|
81
|
+
case "combobox":
|
|
82
|
+
case "radio":
|
|
83
|
+
case "select":
|
|
84
|
+
item = {
|
|
85
|
+
label,
|
|
86
|
+
singleRow,
|
|
87
|
+
data: (data) => {
|
|
88
|
+
const value = data[name];
|
|
89
|
+
if (value == null) return undefined;
|
|
90
|
+
|
|
91
|
+
const values = Array.isArray(value) ? value : [value];
|
|
92
|
+
const options = f.options ?? [];
|
|
93
|
+
const selectedOptions = options.filter((o) =>
|
|
94
|
+
values.includes(o.id)
|
|
95
|
+
);
|
|
96
|
+
return selectedOptions
|
|
97
|
+
.map((o) => {
|
|
98
|
+
const label = DataTypes.getListItemLabel(o);
|
|
99
|
+
return app.get(label) ?? label;
|
|
100
|
+
})
|
|
101
|
+
.join(", ");
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
case "date":
|
|
106
|
+
item = {
|
|
107
|
+
label,
|
|
108
|
+
singleRow,
|
|
109
|
+
data: (data) => {
|
|
110
|
+
const value = data[name];
|
|
111
|
+
if (value == null) return undefined;
|
|
112
|
+
|
|
113
|
+
return typeof value === "string"
|
|
114
|
+
? (DateUtils.parse(value)?.toLocaleDateString() ?? value)
|
|
115
|
+
: value instanceof Date
|
|
116
|
+
? value.toLocaleDateString()
|
|
117
|
+
: `${value}`;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
break;
|
|
121
|
+
case "divider":
|
|
122
|
+
item = {
|
|
123
|
+
label,
|
|
124
|
+
singleRow,
|
|
125
|
+
data: () => <Divider />
|
|
126
|
+
};
|
|
127
|
+
break;
|
|
128
|
+
case "json":
|
|
129
|
+
item = {
|
|
130
|
+
label,
|
|
131
|
+
singleRow,
|
|
132
|
+
data: (data) => {
|
|
133
|
+
const value = data[name];
|
|
134
|
+
if (value == null) return undefined;
|
|
135
|
+
return JSON.stringify(value, null, 2);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
break;
|
|
139
|
+
case "number":
|
|
140
|
+
const numberCurrency = f.mainSlotProps?.currency;
|
|
141
|
+
const numberSymbol = numberCurrency
|
|
142
|
+
? NumberUtils.getCurrencySymbol(numberCurrency)
|
|
143
|
+
: "";
|
|
144
|
+
item = {
|
|
145
|
+
label: numberCurrency ? `${label} (${numberCurrency})` : label,
|
|
146
|
+
singleRow,
|
|
147
|
+
data: (data) => {
|
|
148
|
+
const value = NumberUtils.parse(data[name]);
|
|
149
|
+
return value == null
|
|
150
|
+
? undefined
|
|
151
|
+
: `${numberSymbol}${app.formatNumber(value)}`;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
item = { label, singleRow, data: name };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return item;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return <ViewContainer fields={mappedFields} {...rest} />;
|
|
163
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./custom/CustomAttributeArea";
|
|
|
11
11
|
export * from "./custom/CustomFieldUI";
|
|
12
12
|
export * from "./custom/CustomFieldUtils";
|
|
13
13
|
export * from "./custom/CustomFieldViewer";
|
|
14
|
+
export * from "./custom/CustomFieldViewUI";
|
|
14
15
|
export * from "./custom/CustomFieldWindow";
|
|
15
16
|
|
|
16
17
|
export * from "./html/HtmlDiv";
|