@etsoo/materialui 1.1.39 → 1.1.41

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.
@@ -1,12 +1,12 @@
1
- import { GridColumnRenderProps, GridDataType } from '@etsoo/react';
2
- import { DataTypes } from '@etsoo/shared';
3
- import { GridProps } from '@mui/material';
4
- import React from 'react';
5
- import { CommonPageProps } from './CommonPageProps';
1
+ import { GridColumnRenderProps, GridDataType } from "@etsoo/react";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import { GridProps } from "@mui/material";
4
+ import React from "react";
5
+ import { CommonPageProps } from "./CommonPageProps";
6
6
  /**
7
7
  * View page row width type
8
8
  */
9
- export type ViewPageRowType = boolean | 'default' | 'small' | object;
9
+ export type ViewPageRowType = boolean | "default" | "small" | object;
10
10
  /**
11
11
  * View page display field
12
12
  */
@@ -40,7 +40,7 @@ export type ViewPageFieldType<T extends object> = ViewPageFieldTypeNarrow<T> | (
40
40
  /**
41
41
  * View page props
42
42
  */
43
- export interface ViewPageProps<T extends DataTypes.StringRecord> extends Omit<CommonPageProps, 'children'> {
43
+ export interface ViewPageProps<T extends DataTypes.StringRecord> extends Omit<CommonPageProps, "children"> {
44
44
  /**
45
45
  * Actions
46
46
  */
@@ -1,25 +1,27 @@
1
- import { Utils } from '@etsoo/shared';
2
- import { Grid, LinearProgress, Stack, Typography } from '@mui/material';
3
- import React from 'react';
4
- import { Labels } from '../app/Labels';
5
- import { globalApp } from '../app/ReactApp';
6
- import { GridDataFormat } from '../GridDataFormat';
7
- import { MUGlobal } from '../MUGlobal';
8
- import { PullToRefreshUI } from '../PullToRefreshUI';
9
- import { CommonPage } from './CommonPage';
1
+ import { DateUtils, Utils } from "@etsoo/shared";
2
+ import { Grid, LinearProgress, Stack, Typography } from "@mui/material";
3
+ import React from "react";
4
+ import { Labels } from "../app/Labels";
5
+ import { globalApp } from "../app/ReactApp";
6
+ import { GridDataFormat } from "../GridDataFormat";
7
+ import { MUGlobal } from "../MUGlobal";
8
+ import { PullToRefreshUI } from "../PullToRefreshUI";
9
+ import { CommonPage } from "./CommonPage";
10
10
  function formatItemData(fieldData) {
11
11
  if (fieldData == null)
12
12
  return undefined;
13
- if (typeof fieldData === 'string')
13
+ if (typeof fieldData === "string")
14
14
  return fieldData;
15
15
  if (fieldData instanceof Date)
16
- return globalApp.formatDate(fieldData, 'd');
16
+ return globalApp
17
+ ? globalApp.formatDate(fieldData, "d")
18
+ : DateUtils.format(fieldData, "d");
17
19
  return `${fieldData}`;
18
20
  }
19
21
  function getResp(singleRow) {
20
- return typeof singleRow === 'object'
22
+ return typeof singleRow === "object"
21
23
  ? singleRow
22
- : singleRow === 'default'
24
+ : singleRow === "default"
23
25
  ? { xs: 12, sm: 12, md: 12, lg: 6, xl: 6 }
24
26
  : singleRow === true
25
27
  ? { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
@@ -36,20 +38,20 @@ function getItemField(field, data) {
36
38
  // Item data and label
37
39
  let itemData, itemLabel, gridProps = {};
38
40
  if (Array.isArray(field)) {
39
- const [fieldData, fieldType, renderProps, singleRow = 'small'] = field;
41
+ const [fieldData, fieldType, renderProps, singleRow = "small"] = field;
40
42
  itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
41
- itemLabel = (_a = globalApp.get(fieldData)) !== null && _a !== void 0 ? _a : fieldData;
43
+ itemLabel = (_a = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get(fieldData)) !== null && _a !== void 0 ? _a : fieldData;
42
44
  gridProps = { ...getResp(singleRow) };
43
45
  }
44
- else if (typeof field === 'object') {
46
+ else if (typeof field === "object") {
45
47
  // Destruct
46
- const { data: fieldData, dataType, label: fieldLabel, renderProps, singleRow = 'default', ...rest } = field;
48
+ const { data: fieldData, dataType, label: fieldLabel, renderProps, singleRow = "default", ...rest } = field;
47
49
  gridProps = {
48
50
  ...rest,
49
51
  ...getResp(singleRow)
50
52
  };
51
53
  // Field data
52
- if (typeof fieldData === 'function')
54
+ if (typeof fieldData === "function")
53
55
  itemData = fieldData(data);
54
56
  else if (dataType == null)
55
57
  itemData = formatItemData(data[fieldData]);
@@ -57,15 +59,15 @@ function getItemField(field, data) {
57
59
  itemData = GridDataFormat(data[fieldData], dataType, renderProps);
58
60
  // Field label
59
61
  itemLabel =
60
- typeof fieldLabel === 'function'
62
+ typeof fieldLabel === "function"
61
63
  ? fieldLabel()
62
64
  : fieldLabel != null
63
- ? (_b = globalApp.get(fieldLabel)) !== null && _b !== void 0 ? _b : fieldLabel
65
+ ? (_b = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get(fieldLabel)) !== null && _b !== void 0 ? _b : fieldLabel
64
66
  : fieldLabel;
65
67
  }
66
68
  else {
67
69
  itemData = formatItemData(data[field]);
68
- itemLabel = (_c = globalApp.get(field)) !== null && _c !== void 0 ? _c : field;
70
+ itemLabel = (_c = globalApp === null || globalApp === void 0 ? void 0 : globalApp.get(field)) !== null && _c !== void 0 ? _c : field;
69
71
  }
70
72
  return [itemData, itemLabel, gridProps];
71
73
  }
@@ -81,7 +83,7 @@ export function ViewPage(props) {
81
83
  // Labels
82
84
  const labels = Labels.CommonPage;
83
85
  // Container
84
- const pullContainer = '#page-container';
86
+ const pullContainer = "#page-container";
85
87
  // Load data
86
88
  const refresh = async () => {
87
89
  const result = await loadData();
@@ -91,28 +93,27 @@ export function ViewPage(props) {
91
93
  };
92
94
  return (React.createElement(CommonPage, { paddings: paddings, onRefresh: supportRefresh ? refresh : undefined, onUpdate: supportRefresh ? undefined : refresh, ...rest, scrollContainer: globalThis, fabColumnDirection: fabColumnDirection, supportBack: supportBack }, data == null ? (React.createElement(LinearProgress, null)) : (React.createElement(React.Fragment, null,
93
95
  React.createElement(Grid, { container: true, justifyContent: "left", spacing: paddings, className: "ET-ViewPage", ref: gridRef, sx: {
94
- '.MuiTypography-subtitle2': {
95
- fontWeight: 'bold'
96
+ ".MuiTypography-subtitle2": {
97
+ fontWeight: "bold"
96
98
  }
97
99
  } }, fields.map((field, index) => {
98
100
  // Get data
99
- if (typeof field === 'function') {
101
+ if (typeof field === "function") {
100
102
  // Most flexible way, do whatever you want
101
103
  return field(data);
102
104
  }
103
105
  const [itemData, itemLabel, gridProps] = getItemField(field, data);
104
106
  // Some callback function may return '' instead of undefined
105
- if (itemData == null || itemData === '')
107
+ if (itemData == null || itemData === "")
106
108
  return undefined;
107
109
  // Layout
108
110
  return (React.createElement(Grid, { item: true, ...gridProps, key: index },
109
111
  itemLabel != null && (React.createElement(Typography, { variant: "caption", component: "div" },
110
112
  itemLabel,
111
113
  ":")),
112
- typeof itemData === 'object' ? (itemData) : (React.createElement(Typography, { variant: "subtitle2" }, itemData))));
114
+ typeof itemData === "object" ? (itemData) : (React.createElement(Typography, { variant: "subtitle2" }, itemData))));
113
115
  })),
114
- React.createElement(Stack, { className: "ET-ViewPage-Actions", direction: "row", width: "100%", flexWrap: "wrap", justifyContent: "flex-end", paddingTop: actions == null ? undefined : paddings, paddingBottom: paddings, gap: paddings }, actions != null &&
115
- Utils.getResult(actions, data, refresh)),
116
+ React.createElement(Stack, { className: "ET-ViewPage-Actions", direction: "row", width: "100%", flexWrap: "wrap", justifyContent: "flex-end", paddingTop: actions == null ? undefined : paddings, paddingBottom: paddings, gap: paddings }, actions != null && Utils.getResult(actions, data, refresh)),
116
117
  Utils.getResult(children, data, refresh),
117
118
  pullToRefresh && (React.createElement(PullToRefreshUI, { mainElement: pullContainer, triggerElement: pullContainer, instructionsPullToRefresh: labels.pullToRefresh, instructionsReleaseToRefresh: labels.releaseToRefresh, instructionsRefreshing: labels.refreshing, onRefresh: refresh, shouldPullToRefresh: () => {
118
119
  const container = document.querySelector(pullContainer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.39",
3
+ "version": "1.1.41",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/css": "^11.10.6",
51
51
  "@emotion/react": "^11.10.6",
52
52
  "@emotion/styled": "^11.10.6",
53
- "@etsoo/appscript": "^1.3.67",
53
+ "@etsoo/appscript": "^1.3.68",
54
54
  "@etsoo/notificationbase": "^1.1.24",
55
55
  "@etsoo/react": "^1.6.49",
56
56
  "@etsoo/shared": "^1.1.89",
@@ -1,46 +1,46 @@
1
- import { AuditLineDto } from '@etsoo/appscript';
2
- import { Utils } from '@etsoo/shared';
3
- import { Button, Divider, Theme, Typography, useTheme } from '@mui/material';
4
- import React, { CSSProperties } from 'react';
5
- import { globalApp } from './app/ReactApp';
6
- import { ListMoreDisplay, ListMoreDisplayProps } from './ListMoreDisplay';
7
- import { ShowDataComparison } from './ShowDataComparison';
1
+ import { AuditLineDto } from "@etsoo/appscript";
2
+ import { Utils } from "@etsoo/shared";
3
+ import { Button, Divider, Theme, Typography, useTheme } from "@mui/material";
4
+ import React, { CSSProperties } from "react";
5
+ import { globalApp } from "./app/ReactApp";
6
+ import { ListMoreDisplay, ListMoreDisplayProps } from "./ListMoreDisplay";
7
+ import { ShowDataComparison } from "./ShowDataComparison";
8
8
 
9
9
  /**
10
10
  * Audit display props
11
11
  */
12
12
  export interface AuditDisplayProps
13
- extends Omit<ListMoreDisplayProps<AuditLineDto>, 'children'> {
14
- /**
15
- * Get list item style callback
16
- */
17
- getItemStyle?: (index: number, theme: Theme) => CSSProperties;
13
+ extends Omit<ListMoreDisplayProps<AuditLineDto>, "children"> {
14
+ /**
15
+ * Get list item style callback
16
+ */
17
+ getItemStyle?: (index: number, theme: Theme) => CSSProperties;
18
18
 
19
- /**
20
- * Get column label
21
- */
22
- getColumnLabel?: (field: string) => string;
19
+ /**
20
+ * Get column label
21
+ */
22
+ getColumnLabel?: (field: string) => string;
23
23
 
24
- /**
25
- * Equal check
26
- */
27
- equalCheck?: boolean;
24
+ /**
25
+ * Equal check
26
+ */
27
+ equalCheck?: boolean;
28
28
 
29
- /**
30
- * Item/line renderer
31
- */
32
- itemRenderer?: (data: AuditLineDto, index: number) => React.ReactNode;
29
+ /**
30
+ * Item/line renderer
31
+ */
32
+ itemRenderer?: (data: AuditLineDto, index: number) => React.ReactNode;
33
33
  }
34
34
 
35
35
  // Get label
36
36
  const getLabel = (key: string) => {
37
- return globalApp.get(Utils.formatInitial(key)) ?? key;
37
+ return globalApp?.get(Utils.formatInitial(key)) ?? key;
38
38
  };
39
39
 
40
40
  // Format date
41
41
  const formatDate = (date: Date) => {
42
- if (typeof globalApp === 'undefined') return date.toUTCString();
43
- return globalApp.formatDate(date, 'ds');
42
+ if (globalApp) return globalApp.formatDate(date, "ds");
43
+ return date.toUTCString();
44
44
  };
45
45
 
46
46
  /**
@@ -49,79 +49,72 @@ const formatDate = (date: Date) => {
49
49
  * @returns Component
50
50
  */
51
51
  export function AuditDisplay(props: AuditDisplayProps) {
52
- // Theme
53
- const theme = useTheme();
52
+ // Theme
53
+ const theme = useTheme();
54
54
 
55
- // Title
56
- var title = getLabel('dataComparison');
55
+ // Title
56
+ var title = getLabel("dataComparison");
57
57
 
58
- // Destruct
59
- const {
60
- getItemStyle = (index, theme) => ({
61
- padding: [theme.spacing(1.5), theme.spacing(1)].join(' '),
62
- background:
63
- index % 2 === 0
64
- ? theme.palette.grey[100]
65
- : theme.palette.grey[50]
66
- }),
67
- getColumnLabel,
68
- equalCheck,
69
- itemRenderer = (data) => {
70
- const {
71
- newData,
72
- oldData,
73
- changes = { newData: newData ?? {}, oldData: oldData ?? {} }
74
- } = data;
75
- return (
76
- <React.Fragment>
77
- {changes != null && (
78
- <Button
79
- variant="outlined"
80
- size="small"
81
- onClick={() =>
82
- ShowDataComparison(
83
- changes,
84
- title,
85
- getColumnLabel,
86
- equalCheck
87
- )
88
- }
89
- sx={{
90
- marginLeft: theme.spacing(1),
91
- marginTop: theme.spacing(-0.5),
92
- float: 'right'
93
- }}
94
- >
95
- {title}
96
- </Button>
97
- )}
98
- <Typography>
99
- {formatDate(data.creation) +
100
- ', [' +
101
- getLabel(data.action) +
102
- '], ' +
103
- data.user}
104
- </Typography>
105
- </React.Fragment>
106
- );
107
- },
108
- headerTitle = (
109
- <React.Fragment>
110
- <Typography>{getLabel('audits')}</Typography>
111
- <Divider />
112
- </React.Fragment>
113
- ),
114
- ...rest
115
- } = props;
58
+ // Destruct
59
+ const {
60
+ getItemStyle = (index, theme) => ({
61
+ padding: [theme.spacing(1.5), theme.spacing(1)].join(" "),
62
+ background:
63
+ index % 2 === 0 ? theme.palette.grey[100] : theme.palette.grey[50]
64
+ }),
65
+ getColumnLabel,
66
+ equalCheck,
67
+ itemRenderer = (data) => {
68
+ const {
69
+ newData,
70
+ oldData,
71
+ changes = { newData: newData ?? {}, oldData: oldData ?? {} }
72
+ } = data;
73
+ return (
74
+ <React.Fragment>
75
+ {changes != null && (
76
+ <Button
77
+ variant="outlined"
78
+ size="small"
79
+ onClick={() =>
80
+ ShowDataComparison(changes, title, getColumnLabel, equalCheck)
81
+ }
82
+ sx={{
83
+ marginLeft: theme.spacing(1),
84
+ marginTop: theme.spacing(-0.5),
85
+ float: "right"
86
+ }}
87
+ >
88
+ {title}
89
+ </Button>
90
+ )}
91
+ <Typography>
92
+ {formatDate(data.creation) +
93
+ ", [" +
94
+ getLabel(data.action) +
95
+ "], " +
96
+ data.user}
97
+ </Typography>
98
+ </React.Fragment>
99
+ );
100
+ },
101
+ headerTitle = (
102
+ <React.Fragment>
103
+ <Typography>{getLabel("audits")}</Typography>
104
+ <Divider />
105
+ </React.Fragment>
106
+ ),
107
+ ...rest
108
+ } = props;
116
109
 
117
- // Layout
118
- return (
119
- <ListMoreDisplay<AuditLineDto> headerTitle={headerTitle} {...rest}>
120
- {(data, index) => (
121
- <div key={data.id} style={getItemStyle(index, theme)}>
122
- {itemRenderer(data, index)}
123
- </div>
124
- )}
125
- </ListMoreDisplay>
126
- );
110
+ // Layout
111
+ return (
112
+ <ListMoreDisplay<AuditLineDto> headerTitle={headerTitle} {...rest}>
113
+ {(data, index) => (
114
+ <div key={data.id} style={getItemStyle(index, theme)}>
115
+ {itemRenderer(data, index)}
116
+ </div>
117
+ )}
118
+ </ListMoreDisplay>
119
+ );
127
120
  }
@@ -1,23 +1,23 @@
1
- import { BridgeUtils, IBridgeHost } from '@etsoo/appscript';
2
- import CloseIcon from '@mui/icons-material/Close';
3
- import { Box, BoxProps, IconButton, IconButtonProps } from '@mui/material';
4
- import React from 'react';
5
- import { globalApp } from './app/ReactApp';
1
+ import { BridgeUtils, IBridgeHost } from "@etsoo/appscript";
2
+ import CloseIcon from "@mui/icons-material/Close";
3
+ import { Box, BoxProps, IconButton, IconButtonProps } from "@mui/material";
4
+ import React from "react";
5
+ import { globalApp } from "./app/ReactApp";
6
6
 
7
7
  /**
8
8
  * Bridge close button props
9
9
  */
10
10
  export interface BridgeCloseButtonProps extends IconButtonProps {
11
- /**
12
- * Box props
13
- */
14
- boxProps?: BoxProps;
11
+ /**
12
+ * Box props
13
+ */
14
+ boxProps?: BoxProps;
15
15
 
16
- /**
17
- * Validate the host
18
- * @param host Host
19
- */
20
- validate?(host: IBridgeHost): boolean;
16
+ /**
17
+ * Validate the host
18
+ * @param host Host
19
+ */
20
+ validate?(host: IBridgeHost): boolean;
21
21
  }
22
22
 
23
23
  /**
@@ -26,44 +26,42 @@ export interface BridgeCloseButtonProps extends IconButtonProps {
26
26
  * @returns Component
27
27
  */
28
28
  export function BridgeCloseButton(props: BridgeCloseButtonProps) {
29
- // Destruct
30
- const {
31
- boxProps,
32
- onClick,
33
- title = typeof globalApp === 'undefined'
34
- ? 'Close'
35
- : globalApp.get('close'),
36
- validate,
37
- ...rest
38
- } = props;
29
+ // Destruct
30
+ const {
31
+ boxProps,
32
+ onClick,
33
+ title = globalApp?.get("close") ?? "Close",
34
+ validate,
35
+ ...rest
36
+ } = props;
39
37
 
40
- // Host
41
- const host = BridgeUtils.host;
38
+ // Host
39
+ const host = BridgeUtils.host;
42
40
 
43
- if (
44
- host == null ||
45
- !host.closable() ||
46
- (validate && validate(host) === false)
47
- ) {
48
- return <React.Fragment />;
49
- }
41
+ if (
42
+ host == null ||
43
+ !host.closable() ||
44
+ (validate && validate(host) === false)
45
+ ) {
46
+ return <React.Fragment />;
47
+ }
50
48
 
51
- // Click handler
52
- const onClickLocal = (event: React.MouseEvent<HTMLButtonElement>) => {
53
- if (onClick) onClick(event);
54
- host.exit();
55
- };
49
+ // Click handler
50
+ const onClickLocal = (event: React.MouseEvent<HTMLButtonElement>) => {
51
+ if (onClick) onClick(event);
52
+ host.exit();
53
+ };
56
54
 
57
- return (
58
- <Box {...boxProps}>
59
- <IconButton
60
- aria-label="close"
61
- onClick={onClickLocal}
62
- title={title}
63
- {...rest}
64
- >
65
- <CloseIcon />
66
- </IconButton>
67
- </Box>
68
- );
55
+ return (
56
+ <Box {...boxProps}>
57
+ <IconButton
58
+ aria-label="close"
59
+ onClick={onClickLocal}
60
+ title={title}
61
+ {...rest}
62
+ >
63
+ <CloseIcon />
64
+ </IconButton>
65
+ </Box>
66
+ );
69
67
  }