@etsoo/materialui 1.6.21 → 1.6.23
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/ViewContainer.d.ts +1 -1
- package/lib/cjs/custom/CustomAttributeArea.js +4 -1
- package/lib/cjs/custom/CustomFieldUI.js +4 -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/ViewContainer.d.ts +1 -1
- package/lib/mjs/custom/CustomAttributeArea.js +4 -1
- package/lib/mjs/custom/CustomFieldUI.js +4 -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 +5 -5
- package/src/ViewContainer.tsx +15 -15
- package/src/custom/CustomAttributeArea.tsx +4 -1
- package/src/custom/CustomFieldUI.tsx +6 -1
- package/src/custom/CustomFieldViewUI.tsx +163 -0
- package/src/index.ts +1 -0
|
@@ -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
|
*/
|
|
@@ -44,7 +44,10 @@ function InputItemUIs({ data }) {
|
|
|
44
44
|
return ((0, jsx_runtime_1.jsxs)(Grid_1.default, { container: true, spacing: 2, marginTop: 1, children: [(0, jsx_runtime_1.jsx)(Grid_1.default, { size: { xs: 12, sm: 6 }, children: (0, jsx_runtime_1.jsx)(ComboBox_1.ComboBox, { name: "type", label: labels.type, inputRequired: true, size: "small", loadData: () => Promise.resolve(types.map((t) => ({ id: t, label: t }))), onValueChange: (item) => {
|
|
45
45
|
const type = item?.id;
|
|
46
46
|
optionsRef.current.disabled =
|
|
47
|
-
type !== "combobox" &&
|
|
47
|
+
type !== "combobox" &&
|
|
48
|
+
type !== "select" &&
|
|
49
|
+
type !== "checkbox" &&
|
|
50
|
+
type !== "radio";
|
|
48
51
|
const nameInput = nameRef.current;
|
|
49
52
|
if (nameInput.value === "" &&
|
|
50
53
|
(type === "amountlabel" || type === "divider" || type === "label")) {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.CustomFieldUI = CustomFieldUI;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const CustomFieldUtils_1 = require("./CustomFieldUtils");
|
|
9
|
+
const ReactApp_1 = require("../app/ReactApp");
|
|
9
10
|
/**
|
|
10
11
|
* CustomFieldUI component
|
|
11
12
|
* @param props Props
|
|
@@ -14,6 +15,8 @@ const CustomFieldUtils_1 = require("./CustomFieldUtils");
|
|
|
14
15
|
function CustomFieldUI(props) {
|
|
15
16
|
// Destruct
|
|
16
17
|
const { fields, initialValue, mref, onChange } = props;
|
|
18
|
+
// App
|
|
19
|
+
const app = (0, ReactApp_1.useAppContext)();
|
|
17
20
|
// Field component collections
|
|
18
21
|
const collections = {};
|
|
19
22
|
// Value reference
|
|
@@ -36,5 +39,5 @@ function CustomFieldUI(props) {
|
|
|
36
39
|
}, (name, fieldValue) => {
|
|
37
40
|
valueRef.current[name] = fieldValue;
|
|
38
41
|
onChange?.(valueRef.current, name, fieldValue);
|
|
39
|
-
});
|
|
42
|
+
}, (input) => app?.get(input) ?? input);
|
|
40
43
|
}
|
|
@@ -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);
|
|
@@ -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
|
*/
|
|
@@ -38,7 +38,10 @@ function InputItemUIs({ data }) {
|
|
|
38
38
|
return (_jsxs(Grid, { container: true, spacing: 2, marginTop: 1, children: [_jsx(Grid, { size: { xs: 12, sm: 6 }, children: _jsx(ComboBox, { name: "type", label: labels.type, inputRequired: true, size: "small", loadData: () => Promise.resolve(types.map((t) => ({ id: t, label: t }))), onValueChange: (item) => {
|
|
39
39
|
const type = item?.id;
|
|
40
40
|
optionsRef.current.disabled =
|
|
41
|
-
type !== "combobox" &&
|
|
41
|
+
type !== "combobox" &&
|
|
42
|
+
type !== "select" &&
|
|
43
|
+
type !== "checkbox" &&
|
|
44
|
+
type !== "radio";
|
|
42
45
|
const nameInput = nameRef.current;
|
|
43
46
|
if (nameInput.value === "" &&
|
|
44
47
|
(type === "amountlabel" || type === "divider" || type === "label")) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CustomFieldUtils } from "./CustomFieldUtils";
|
|
3
|
+
import { useAppContext } from "../app/ReactApp";
|
|
3
4
|
/**
|
|
4
5
|
* CustomFieldUI component
|
|
5
6
|
* @param props Props
|
|
@@ -8,6 +9,8 @@ import { CustomFieldUtils } from "./CustomFieldUtils";
|
|
|
8
9
|
export function CustomFieldUI(props) {
|
|
9
10
|
// Destruct
|
|
10
11
|
const { fields, initialValue, mref, onChange } = props;
|
|
12
|
+
// App
|
|
13
|
+
const app = useAppContext();
|
|
11
14
|
// Field component collections
|
|
12
15
|
const collections = {};
|
|
13
16
|
// Value reference
|
|
@@ -30,5 +33,5 @@ export function CustomFieldUI(props) {
|
|
|
30
33
|
}, (name, fieldValue) => {
|
|
31
34
|
valueRef.current[name] = fieldValue;
|
|
32
35
|
onChange?.(valueRef.current, name, fieldValue);
|
|
33
|
-
});
|
|
36
|
+
}, (input) => app?.get(input) ?? input);
|
|
34
37
|
}
|
|
@@ -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.23",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"@etsoo/notificationbase": "^1.1.66",
|
|
44
44
|
"@etsoo/react": "^1.8.78",
|
|
45
45
|
"@etsoo/shared": "^1.2.80",
|
|
46
|
-
"@mui/icons-material": "^7.3.
|
|
47
|
-
"@mui/material": "^7.3.
|
|
48
|
-
"@mui/x-data-grid": "^8.27.
|
|
46
|
+
"@mui/icons-material": "^7.3.9",
|
|
47
|
+
"@mui/material": "^7.3.9",
|
|
48
|
+
"@mui/x-data-grid": "^8.27.4",
|
|
49
49
|
"chart.js": "^4.5.1",
|
|
50
50
|
"chartjs-plugin-datalabels": "^2.2.0",
|
|
51
|
-
"dompurify": "^3.3.
|
|
51
|
+
"dompurify": "^3.3.2",
|
|
52
52
|
"eventemitter3": "^5.0.4",
|
|
53
53
|
"pica": "^9.0.1",
|
|
54
54
|
"pulltorefreshjs": "^0.1.22",
|
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
|
|
|
@@ -68,7 +68,10 @@ function InputItemUIs({ data }: { data?: CustomFieldData }) {
|
|
|
68
68
|
onValueChange={(item) => {
|
|
69
69
|
const type = item?.id;
|
|
70
70
|
optionsRef.current!.disabled =
|
|
71
|
-
type !== "combobox" &&
|
|
71
|
+
type !== "combobox" &&
|
|
72
|
+
type !== "select" &&
|
|
73
|
+
type !== "checkbox" &&
|
|
74
|
+
type !== "radio";
|
|
72
75
|
|
|
73
76
|
const nameInput = nameRef.current!;
|
|
74
77
|
if (
|
|
@@ -2,6 +2,7 @@ import { CustomFieldData, CustomFieldRef } from "@etsoo/appscript";
|
|
|
2
2
|
import { CustomFieldReactCollection } from "@etsoo/react";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { CustomFieldUtils } from "./CustomFieldUtils";
|
|
5
|
+
import { useAppContext } from "../app/ReactApp";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* CustomFieldUI component props
|
|
@@ -46,6 +47,9 @@ export function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(
|
|
|
46
47
|
// Destruct
|
|
47
48
|
const { fields, initialValue, mref, onChange } = props;
|
|
48
49
|
|
|
50
|
+
// App
|
|
51
|
+
const app = useAppContext();
|
|
52
|
+
|
|
49
53
|
// Field component collections
|
|
50
54
|
const collections: CustomFieldReactCollection<D> = {};
|
|
51
55
|
|
|
@@ -78,6 +82,7 @@ export function CustomFieldUI<D extends CustomFieldData = CustomFieldData>(
|
|
|
78
82
|
(name, fieldValue) => {
|
|
79
83
|
valueRef.current[name] = fieldValue;
|
|
80
84
|
onChange?.(valueRef.current, name, fieldValue);
|
|
81
|
-
}
|
|
85
|
+
},
|
|
86
|
+
(input) => app?.get(input) ?? input
|
|
82
87
|
);
|
|
83
88
|
}
|
|
@@ -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";
|