@etsoo/materialui 1.0.1
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/.eslintignore +3 -0
- package/.eslintrc.json +38 -0
- package/.gitattributes +2 -0
- package/.github/workflows/main.yml +48 -0
- package/.prettierignore +5 -0
- package/.prettierrc +6 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/__tests__/ComboBox.tsx +30 -0
- package/__tests__/MUGlobalTests.tsx +58 -0
- package/__tests__/NotifierMUTests.tsx +217 -0
- package/__tests__/SelectEx.tsx +26 -0
- package/__tests__/tsconfig.json +19 -0
- package/babel.config.json +11 -0
- package/lib/AuditDisplay.d.ts +33 -0
- package/lib/AuditDisplay.js +52 -0
- package/lib/AutocompleteExtendedProps.d.ts +64 -0
- package/lib/AutocompleteExtendedProps.js +1 -0
- package/lib/BackButton.d.ts +13 -0
- package/lib/BackButton.js +33 -0
- package/lib/BridgeCloseButton.d.ts +23 -0
- package/lib/BridgeCloseButton.js +32 -0
- package/lib/ButtonLink.d.ts +17 -0
- package/lib/ButtonLink.js +19 -0
- package/lib/ComboBox.d.ts +38 -0
- package/lib/ComboBox.js +108 -0
- package/lib/CountdownButton.d.ts +23 -0
- package/lib/CountdownButton.js +81 -0
- package/lib/CustomFabProps.d.ts +27 -0
- package/lib/CustomFabProps.js +1 -0
- package/lib/DataGridEx.d.ts +94 -0
- package/lib/DataGridEx.js +329 -0
- package/lib/DataGridRenderers.d.ts +22 -0
- package/lib/DataGridRenderers.js +99 -0
- package/lib/DialogButton.d.ts +54 -0
- package/lib/DialogButton.js +45 -0
- package/lib/DnDList.d.ts +87 -0
- package/lib/DnDList.js +153 -0
- package/lib/DraggablePaperComponent.d.ts +8 -0
- package/lib/DraggablePaperComponent.js +12 -0
- package/lib/EmailInput.d.ts +11 -0
- package/lib/EmailInput.js +15 -0
- package/lib/FabBox.d.ts +21 -0
- package/lib/FabBox.js +31 -0
- package/lib/FlexBox.d.ts +14 -0
- package/lib/FlexBox.js +18 -0
- package/lib/GridDataFormat.d.ts +10 -0
- package/lib/GridDataFormat.js +43 -0
- package/lib/IconButtonLink.d.ts +17 -0
- package/lib/IconButtonLink.js +16 -0
- package/lib/InputField.d.ts +21 -0
- package/lib/InputField.js +39 -0
- package/lib/ItemList.d.ts +56 -0
- package/lib/ItemList.js +69 -0
- package/lib/ListItemRightIcon.d.ts +4 -0
- package/lib/ListItemRightIcon.js +8 -0
- package/lib/ListMoreDisplay.d.ts +35 -0
- package/lib/ListMoreDisplay.js +99 -0
- package/lib/LoadingButton.d.ts +16 -0
- package/lib/LoadingButton.js +41 -0
- package/lib/MUGlobal.d.ts +102 -0
- package/lib/MUGlobal.js +184 -0
- package/lib/MaskInput.d.ts +34 -0
- package/lib/MaskInput.js +43 -0
- package/lib/MobileListItemRenderer.d.ts +17 -0
- package/lib/MobileListItemRenderer.js +35 -0
- package/lib/MoreFab.d.ts +45 -0
- package/lib/MoreFab.js +95 -0
- package/lib/NotifierMU.d.ts +47 -0
- package/lib/NotifierMU.js +387 -0
- package/lib/NotifierPromptProps.d.ts +22 -0
- package/lib/NotifierPromptProps.js +1 -0
- package/lib/OptionGroup.d.ts +58 -0
- package/lib/OptionGroup.js +81 -0
- package/lib/PList.d.ts +15 -0
- package/lib/PList.js +12 -0
- package/lib/ProgressCount.d.ts +44 -0
- package/lib/ProgressCount.js +79 -0
- package/lib/PullToRefreshUI.d.ts +9 -0
- package/lib/PullToRefreshUI.js +18 -0
- package/lib/RLink.d.ts +14 -0
- package/lib/RLink.js +37 -0
- package/lib/ResponsibleContainer.d.ts +87 -0
- package/lib/ResponsibleContainer.js +156 -0
- package/lib/ScrollTopFab.d.ts +7 -0
- package/lib/ScrollTopFab.js +25 -0
- package/lib/ScrollerListEx.d.ts +81 -0
- package/lib/ScrollerListEx.js +167 -0
- package/lib/SearchBar.d.ts +29 -0
- package/lib/SearchBar.js +260 -0
- package/lib/SearchField.d.ts +21 -0
- package/lib/SearchField.js +39 -0
- package/lib/SearchOptionGroup.d.ts +9 -0
- package/lib/SearchOptionGroup.js +14 -0
- package/lib/SelectBool.d.ts +13 -0
- package/lib/SelectBool.js +22 -0
- package/lib/SelectEx.d.ts +50 -0
- package/lib/SelectEx.js +156 -0
- package/lib/ShowDataComparison.d.ts +20 -0
- package/lib/ShowDataComparison.js +58 -0
- package/lib/Switch.d.ts +29 -0
- package/lib/Switch.js +34 -0
- package/lib/SwitchAnt.d.ts +25 -0
- package/lib/SwitchAnt.js +40 -0
- package/lib/TabBox.d.ts +54 -0
- package/lib/TabBox.js +31 -0
- package/lib/TableEx.d.ts +65 -0
- package/lib/TableEx.js +270 -0
- package/lib/TextFieldEx.d.ts +101 -0
- package/lib/TextFieldEx.js +126 -0
- package/lib/Tiplist.d.ts +18 -0
- package/lib/Tiplist.js +157 -0
- package/lib/TooltipClick.d.ts +15 -0
- package/lib/TooltipClick.js +40 -0
- package/lib/UserAvatar.d.ts +24 -0
- package/lib/UserAvatar.js +25 -0
- package/lib/UserAvatarEditor.d.ts +53 -0
- package/lib/UserAvatarEditor.js +129 -0
- package/lib/app/CommonApp.d.ts +38 -0
- package/lib/app/CommonApp.js +149 -0
- package/lib/app/IServiceAppSettings.d.ts +11 -0
- package/lib/app/IServiceAppSettings.js +1 -0
- package/lib/app/IServicePage.d.ts +6 -0
- package/lib/app/IServicePage.js +1 -0
- package/lib/app/IServiceUser.d.ts +14 -0
- package/lib/app/IServiceUser.js +1 -0
- package/lib/app/ISmartERPUser.d.ts +14 -0
- package/lib/app/ISmartERPUser.js +1 -0
- package/lib/app/Labels.d.ts +65 -0
- package/lib/app/Labels.js +62 -0
- package/lib/app/ReactApp.d.ts +195 -0
- package/lib/app/ReactApp.js +296 -0
- package/lib/app/ServiceApp.d.ts +78 -0
- package/lib/app/ServiceApp.js +244 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.js +74 -0
- package/lib/pages/CommonPage.d.ts +11 -0
- package/lib/pages/CommonPage.js +60 -0
- package/lib/pages/CommonPageProps.d.ts +59 -0
- package/lib/pages/CommonPageProps.js +1 -0
- package/lib/pages/DataGridPage.d.ts +9 -0
- package/lib/pages/DataGridPage.js +79 -0
- package/lib/pages/DataGridPageProps.d.ts +17 -0
- package/lib/pages/DataGridPageProps.js +1 -0
- package/lib/pages/EditPage.d.ts +33 -0
- package/lib/pages/EditPage.js +29 -0
- package/lib/pages/FixedListPage.d.ts +15 -0
- package/lib/pages/FixedListPage.js +70 -0
- package/lib/pages/ListPage.d.ts +9 -0
- package/lib/pages/ListPage.js +50 -0
- package/lib/pages/ListPageProps.d.ts +7 -0
- package/lib/pages/ListPageProps.js +1 -0
- package/lib/pages/ResponsivePage.d.ts +9 -0
- package/lib/pages/ResponsivePage.js +45 -0
- package/lib/pages/ResponsivePageProps.d.ts +39 -0
- package/lib/pages/ResponsivePageProps.js +1 -0
- package/lib/pages/SearchPageProps.d.ts +30 -0
- package/lib/pages/SearchPageProps.js +1 -0
- package/lib/pages/TablePage.d.ts +9 -0
- package/lib/pages/TablePage.js +69 -0
- package/lib/pages/TablePageProps.d.ts +7 -0
- package/lib/pages/TablePageProps.js +1 -0
- package/lib/pages/ViewPage.d.ts +66 -0
- package/lib/pages/ViewPage.js +105 -0
- package/lib/texts/DateText.d.ts +34 -0
- package/lib/texts/DateText.js +25 -0
- package/lib/texts/MoneyText.d.ts +21 -0
- package/lib/texts/MoneyText.js +14 -0
- package/lib/texts/NumberText.d.ts +25 -0
- package/lib/texts/NumberText.js +14 -0
- package/package.json +97 -0
- package/src/AuditDisplay.tsx +114 -0
- package/src/AutocompleteExtendedProps.ts +83 -0
- package/src/BackButton.tsx +55 -0
- package/src/BridgeCloseButton.tsx +69 -0
- package/src/ButtonLink.tsx +32 -0
- package/src/ComboBox.tsx +251 -0
- package/src/CountdownButton.tsx +119 -0
- package/src/CustomFabProps.ts +32 -0
- package/src/DataGridEx.tsx +713 -0
- package/src/DataGridRenderers.tsx +140 -0
- package/src/DialogButton.tsx +163 -0
- package/src/DnDList.tsx +344 -0
- package/src/DraggablePaperComponent.tsx +19 -0
- package/src/EmailInput.tsx +24 -0
- package/src/FabBox.tsx +51 -0
- package/src/FlexBox.tsx +20 -0
- package/src/GridDataFormat.tsx +77 -0
- package/src/IconButtonLink.tsx +29 -0
- package/src/InputField.tsx +82 -0
- package/src/ItemList.tsx +204 -0
- package/src/ListItemRightIcon.tsx +9 -0
- package/src/ListMoreDisplay.tsx +205 -0
- package/src/LoadingButton.tsx +75 -0
- package/src/MUGlobal.ts +220 -0
- package/src/MaskInput.tsx +107 -0
- package/src/MobileListItemRenderer.tsx +79 -0
- package/src/MoreFab.tsx +211 -0
- package/src/NotifierMU.tsx +654 -0
- package/src/NotifierPromptProps.ts +24 -0
- package/src/OptionGroup.tsx +223 -0
- package/src/PList.tsx +27 -0
- package/src/ProgressCount.tsx +166 -0
- package/src/PullToRefreshUI.tsx +21 -0
- package/src/RLink.tsx +64 -0
- package/src/ResponsibleContainer.tsx +394 -0
- package/src/ScrollTopFab.tsx +34 -0
- package/src/ScrollerListEx.tsx +387 -0
- package/src/SearchBar.tsx +396 -0
- package/src/SearchField.tsx +82 -0
- package/src/SearchOptionGroup.tsx +31 -0
- package/src/SelectBool.tsx +33 -0
- package/src/SelectEx.tsx +290 -0
- package/src/ShowDataComparison.tsx +106 -0
- package/src/Switch.tsx +94 -0
- package/src/SwitchAnt.tsx +95 -0
- package/src/TabBox.tsx +118 -0
- package/src/TableEx.tsx +558 -0
- package/src/TextFieldEx.tsx +249 -0
- package/src/Tiplist.tsx +303 -0
- package/src/TooltipClick.tsx +84 -0
- package/src/UserAvatar.tsx +64 -0
- package/src/UserAvatarEditor.tsx +287 -0
- package/src/app/CommonApp.ts +223 -0
- package/src/app/IServiceAppSettings.ts +13 -0
- package/src/app/IServicePage.ts +6 -0
- package/src/app/IServiceUser.ts +17 -0
- package/src/app/ISmartERPUser.ts +16 -0
- package/src/app/Labels.ts +77 -0
- package/src/app/ReactApp.ts +504 -0
- package/src/app/ServiceApp.ts +352 -0
- package/src/index.ts +77 -0
- package/src/pages/CommonPage.tsx +128 -0
- package/src/pages/CommonPageProps.ts +70 -0
- package/src/pages/DataGridPage.tsx +140 -0
- package/src/pages/DataGridPageProps.ts +24 -0
- package/src/pages/EditPage.tsx +114 -0
- package/src/pages/FixedListPage.tsx +141 -0
- package/src/pages/ListPage.tsx +90 -0
- package/src/pages/ListPageProps.ts +12 -0
- package/src/pages/ResponsivePage.tsx +68 -0
- package/src/pages/ResponsivePageProps.ts +57 -0
- package/src/pages/SearchPageProps.ts +39 -0
- package/src/pages/TablePage.tsx +126 -0
- package/src/pages/TablePageProps.ts +12 -0
- package/src/pages/ViewPage.tsx +282 -0
- package/src/texts/DateText.tsx +74 -0
- package/src/texts/MoneyText.tsx +49 -0
- package/src/texts/NumberText.tsx +40 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IActionResult, IUser } from '@etsoo/appscript';
|
|
2
|
+
/**
|
|
3
|
+
* SmartERP user interface
|
|
4
|
+
*/
|
|
5
|
+
export interface ISmartERPUser extends IUser {
|
|
6
|
+
/**
|
|
7
|
+
* Service refresh token
|
|
8
|
+
*/
|
|
9
|
+
readonly serviceToken?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SmartERP user login result
|
|
13
|
+
*/
|
|
14
|
+
export declare type SmartERPLoginResult = IActionResult<ISmartERPUser>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Labels
|
|
4
|
+
*/
|
|
5
|
+
export declare namespace Labels {
|
|
6
|
+
/**
|
|
7
|
+
* Common page labels
|
|
8
|
+
*/
|
|
9
|
+
const CommonPage: {
|
|
10
|
+
add: string;
|
|
11
|
+
back: string;
|
|
12
|
+
delete: string;
|
|
13
|
+
more: string;
|
|
14
|
+
pullToRefresh: string;
|
|
15
|
+
refresh: string;
|
|
16
|
+
refreshing: string;
|
|
17
|
+
releaseToRefresh: string;
|
|
18
|
+
reset: string;
|
|
19
|
+
save: string;
|
|
20
|
+
scrollTop: string;
|
|
21
|
+
submit: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Notification MU labels
|
|
25
|
+
*/
|
|
26
|
+
const NotificationMU: {
|
|
27
|
+
alertTitle: string;
|
|
28
|
+
alertOK: string;
|
|
29
|
+
confirmTitle: string;
|
|
30
|
+
confirmYes: string;
|
|
31
|
+
confirmNo: string;
|
|
32
|
+
promptTitle: string;
|
|
33
|
+
promptCancel: string;
|
|
34
|
+
promptOK: string;
|
|
35
|
+
loading: string;
|
|
36
|
+
success: string;
|
|
37
|
+
warning: string;
|
|
38
|
+
info: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* UserAvatarEditor labels
|
|
42
|
+
*/
|
|
43
|
+
const UserAvatarEditor: {
|
|
44
|
+
done: string;
|
|
45
|
+
reset: string;
|
|
46
|
+
rotateLeft: string;
|
|
47
|
+
rotateRight: string;
|
|
48
|
+
upload: string;
|
|
49
|
+
zoom: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* setLabelReference key reference
|
|
53
|
+
*/
|
|
54
|
+
interface setLabelsReference {
|
|
55
|
+
commonPage?: DataTypes.StringDictionary;
|
|
56
|
+
notificationMU?: DataTypes.StringDictionary;
|
|
57
|
+
userAvatarEditor?: DataTypes.StringDictionary;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set components' labels
|
|
61
|
+
* @param labels Labels
|
|
62
|
+
* @param reference Key reference
|
|
63
|
+
*/
|
|
64
|
+
const setLabels: (labels: DataTypes.StringRecord, reference?: setLabelsReference) => void;
|
|
65
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Utils } from '@etsoo/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Labels
|
|
4
|
+
*/
|
|
5
|
+
export var Labels;
|
|
6
|
+
(function (Labels) {
|
|
7
|
+
/**
|
|
8
|
+
* Common page labels
|
|
9
|
+
*/
|
|
10
|
+
Labels.CommonPage = {
|
|
11
|
+
add: 'Add',
|
|
12
|
+
back: 'Back',
|
|
13
|
+
delete: 'Delete',
|
|
14
|
+
more: 'More',
|
|
15
|
+
pullToRefresh: 'Pull down to refresh',
|
|
16
|
+
refresh: 'Refresh',
|
|
17
|
+
refreshing: 'Refreshing',
|
|
18
|
+
releaseToRefresh: 'Release to refresh',
|
|
19
|
+
reset: 'Reset',
|
|
20
|
+
save: 'Save',
|
|
21
|
+
scrollTop: 'Scroll to top',
|
|
22
|
+
submit: 'Submit'
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Notification MU labels
|
|
26
|
+
*/
|
|
27
|
+
Labels.NotificationMU = {
|
|
28
|
+
alertTitle: 'Warning',
|
|
29
|
+
alertOK: 'OK',
|
|
30
|
+
confirmTitle: 'Confirm',
|
|
31
|
+
confirmYes: 'OK',
|
|
32
|
+
confirmNo: 'Cancel',
|
|
33
|
+
promptTitle: 'Input',
|
|
34
|
+
promptCancel: 'Cancel',
|
|
35
|
+
promptOK: 'OK',
|
|
36
|
+
loading: 'Loading',
|
|
37
|
+
success: 'Success',
|
|
38
|
+
warning: 'Warning',
|
|
39
|
+
info: 'Information'
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* UserAvatarEditor labels
|
|
43
|
+
*/
|
|
44
|
+
Labels.UserAvatarEditor = {
|
|
45
|
+
done: 'Done',
|
|
46
|
+
reset: 'Reset',
|
|
47
|
+
rotateLeft: 'Rotate left 90°',
|
|
48
|
+
rotateRight: 'Rotate right 90°',
|
|
49
|
+
upload: 'Upload',
|
|
50
|
+
zoom: 'Zoom'
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Set components' labels
|
|
54
|
+
* @param labels Labels
|
|
55
|
+
* @param reference Key reference
|
|
56
|
+
*/
|
|
57
|
+
Labels.setLabels = (labels, reference = {}) => {
|
|
58
|
+
Utils.setLabels(Labels.CommonPage, labels, reference.commonPage);
|
|
59
|
+
Utils.setLabels(Labels.NotificationMU, labels, reference.notificationMU);
|
|
60
|
+
Utils.setLabels(Labels.UserAvatarEditor, labels, reference.userAvatarEditor);
|
|
61
|
+
};
|
|
62
|
+
})(Labels || (Labels = {}));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { CoreApp, IActionResult, IApp, IAppSettings, ICoreApp, IUser } from '@etsoo/appscript';
|
|
2
|
+
import { NotificationRenderProps, NotificationReturn } from '@etsoo/notificationbase';
|
|
3
|
+
import { DataTypes } from '@etsoo/shared';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { History } from 'history';
|
|
6
|
+
import { CultureAction, CultureState, INotificationReact, InputDialogProps, IPageData, IStateProps, NotificationReactCallProps, PageAction, PageState, UserAction, UserState } from '@etsoo/react';
|
|
7
|
+
/**
|
|
8
|
+
* Global application
|
|
9
|
+
*/
|
|
10
|
+
export declare let globalApp: IApp & IReactAppBase;
|
|
11
|
+
/**
|
|
12
|
+
* React app state detector
|
|
13
|
+
* Case 1: undefined, when refresh the whole page
|
|
14
|
+
* Case 2: false, unauthorized
|
|
15
|
+
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
16
|
+
* Case 4: property or properties changed
|
|
17
|
+
* @param props Props
|
|
18
|
+
* @returns Component
|
|
19
|
+
*/
|
|
20
|
+
export declare function ReactAppStateDetector(props: IStateProps): React.FunctionComponentElement<{
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* React implemented base
|
|
25
|
+
*/
|
|
26
|
+
export interface IReactAppBase {
|
|
27
|
+
/**
|
|
28
|
+
* User state
|
|
29
|
+
*/
|
|
30
|
+
readonly userState: UserState<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Router history
|
|
33
|
+
*/
|
|
34
|
+
readonly history: History;
|
|
35
|
+
/**
|
|
36
|
+
* Set page data
|
|
37
|
+
* @param data Page data
|
|
38
|
+
*/
|
|
39
|
+
setPageData(data: IPageData): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set page title and data
|
|
42
|
+
* @param key Page title resource key
|
|
43
|
+
*/
|
|
44
|
+
setPageKey(key: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set page title and data
|
|
47
|
+
* @param title Page title
|
|
48
|
+
*/
|
|
49
|
+
setPageTitle(title: string): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Core application interface
|
|
53
|
+
*/
|
|
54
|
+
export interface IReactApp<S extends IAppSettings, D extends IUser, P extends IPageData> extends ICoreApp<D, S, React.ReactNode, NotificationReactCallProps>, IReactAppBase {
|
|
55
|
+
/**
|
|
56
|
+
* User state
|
|
57
|
+
*/
|
|
58
|
+
readonly userState: UserState<D>;
|
|
59
|
+
/**
|
|
60
|
+
* Set page data
|
|
61
|
+
* @param data Page data
|
|
62
|
+
*/
|
|
63
|
+
setPageData(data: P): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* React application
|
|
67
|
+
*/
|
|
68
|
+
export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends IPageData> extends CoreApp<D, S, React.ReactNode, NotificationReactCallProps> implements IReactApp<S, D, P> {
|
|
69
|
+
private static _notifierProvider;
|
|
70
|
+
/**
|
|
71
|
+
* Get notifier provider
|
|
72
|
+
*/
|
|
73
|
+
static get notifierProvider(): React.FunctionComponent<NotificationRenderProps>;
|
|
74
|
+
private static createApi;
|
|
75
|
+
private static createNotifier;
|
|
76
|
+
/**
|
|
77
|
+
* Culture state
|
|
78
|
+
*/
|
|
79
|
+
readonly cultureState: CultureState;
|
|
80
|
+
/**
|
|
81
|
+
* Router history
|
|
82
|
+
*/
|
|
83
|
+
readonly history: History;
|
|
84
|
+
/**
|
|
85
|
+
* Page state
|
|
86
|
+
*/
|
|
87
|
+
readonly pageState: PageState<P>;
|
|
88
|
+
/**
|
|
89
|
+
* User state
|
|
90
|
+
*/
|
|
91
|
+
readonly userState: UserState<D>;
|
|
92
|
+
/**
|
|
93
|
+
* Is screen size down 'sm'
|
|
94
|
+
*/
|
|
95
|
+
smDown?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Is screen size up 'md'
|
|
98
|
+
*/
|
|
99
|
+
mdUp?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Page state dispatch
|
|
102
|
+
*/
|
|
103
|
+
pageStateDispatch?: React.Dispatch<PageAction<P>>;
|
|
104
|
+
/**
|
|
105
|
+
* User state dispatch
|
|
106
|
+
*/
|
|
107
|
+
userStateDispatch?: React.Dispatch<UserAction<D>>;
|
|
108
|
+
/**
|
|
109
|
+
* Constructor
|
|
110
|
+
* @param settings Settings
|
|
111
|
+
* @param name Application name
|
|
112
|
+
*/
|
|
113
|
+
constructor(settings: S, name: string);
|
|
114
|
+
/**
|
|
115
|
+
* Override alert action result
|
|
116
|
+
* @param result Action result
|
|
117
|
+
* @param callback Callback
|
|
118
|
+
*/
|
|
119
|
+
alertResult(result: IActionResult, callback?: NotificationReturn<void>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Change culture
|
|
122
|
+
* @param culture New culture definition
|
|
123
|
+
*/
|
|
124
|
+
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
125
|
+
/**
|
|
126
|
+
* Change culture extended
|
|
127
|
+
* @param dispatch Dispatch method
|
|
128
|
+
* @param culture New culture definition
|
|
129
|
+
*/
|
|
130
|
+
changeCultureEx(dispatch: React.Dispatch<CultureAction>, culture: DataTypes.CultureDefinition): void;
|
|
131
|
+
/**
|
|
132
|
+
* Get date format props
|
|
133
|
+
* @returns Props
|
|
134
|
+
*/
|
|
135
|
+
getDateFormatProps(): {
|
|
136
|
+
culture: string;
|
|
137
|
+
timeZone: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Get money format props
|
|
141
|
+
* @param currency Currency, if undefined, default currency applied
|
|
142
|
+
* @returns Props
|
|
143
|
+
*/
|
|
144
|
+
getMoneyFormatProps(currency?: string): {
|
|
145
|
+
culture: string;
|
|
146
|
+
currency: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Fresh countdown UI
|
|
150
|
+
* @param callback Callback
|
|
151
|
+
*/
|
|
152
|
+
freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
153
|
+
/**
|
|
154
|
+
* Redirect to the Url
|
|
155
|
+
* @param url Url
|
|
156
|
+
*/
|
|
157
|
+
redirectTo(url: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* Set page data
|
|
160
|
+
* @param data Page data
|
|
161
|
+
*/
|
|
162
|
+
setPageData(data: P): void;
|
|
163
|
+
/**
|
|
164
|
+
* Set page title and data
|
|
165
|
+
* @param title Page title
|
|
166
|
+
*/
|
|
167
|
+
setPageTitle(title: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Set page title and data
|
|
170
|
+
* @param key Page title resource key
|
|
171
|
+
*/
|
|
172
|
+
setPageKey(key: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Show input dialog
|
|
175
|
+
* @param props Props
|
|
176
|
+
*/
|
|
177
|
+
showInputDialog({ title, message, callback, ...rest }: InputDialogProps): INotificationReact;
|
|
178
|
+
/**
|
|
179
|
+
* User login extended
|
|
180
|
+
* @param user New user
|
|
181
|
+
* @param refreshToken Refresh token
|
|
182
|
+
* @param keep Keep in local storage or not
|
|
183
|
+
* @param dispatch User state dispatch
|
|
184
|
+
*/
|
|
185
|
+
userLogin(user: D, refreshToken: string, keep?: boolean, dispatch?: boolean): void;
|
|
186
|
+
/**
|
|
187
|
+
* User logout
|
|
188
|
+
* @param clearToken Clear refresh token or not
|
|
189
|
+
*/
|
|
190
|
+
userLogout(clearToken?: boolean): void;
|
|
191
|
+
/**
|
|
192
|
+
* User unauthorized
|
|
193
|
+
*/
|
|
194
|
+
userUnauthorized(): void;
|
|
195
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { BridgeUtils, CoreApp, createClient } from '@etsoo/appscript';
|
|
2
|
+
import { NotificationMessageType } from '@etsoo/notificationbase';
|
|
3
|
+
import { WindowStorage } from '@etsoo/shared';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { NotifierMU } from '../NotifierMU';
|
|
6
|
+
import { ProgressCount } from '../ProgressCount';
|
|
7
|
+
import { Labels } from './Labels';
|
|
8
|
+
import { createBrowserHistory, createMemoryHistory } from 'history';
|
|
9
|
+
import { CultureState, PageActionType, PageState, UserActionType, UserState } from '@etsoo/react';
|
|
10
|
+
/**
|
|
11
|
+
* Global application
|
|
12
|
+
*/
|
|
13
|
+
export let globalApp;
|
|
14
|
+
/**
|
|
15
|
+
* React app state detector
|
|
16
|
+
* Case 1: undefined, when refresh the whole page
|
|
17
|
+
* Case 2: false, unauthorized
|
|
18
|
+
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
19
|
+
* Case 4: property or properties changed
|
|
20
|
+
* @param props Props
|
|
21
|
+
* @returns Component
|
|
22
|
+
*/
|
|
23
|
+
export function ReactAppStateDetector(props) {
|
|
24
|
+
// Destruct
|
|
25
|
+
const { targetFields, update } = props;
|
|
26
|
+
// Context
|
|
27
|
+
const { state } = globalApp == null
|
|
28
|
+
? {}
|
|
29
|
+
: React.useContext(globalApp.userState.context);
|
|
30
|
+
// Ready
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
// Match fields
|
|
33
|
+
const changedFields = state.lastChangedFields;
|
|
34
|
+
let matchedFields;
|
|
35
|
+
if (targetFields == null || changedFields == null) {
|
|
36
|
+
matchedFields = changedFields;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
matchedFields = [];
|
|
40
|
+
targetFields.forEach((targetField) => {
|
|
41
|
+
if (changedFields.includes(targetField))
|
|
42
|
+
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Callback
|
|
46
|
+
update(state.authorized, matchedFields);
|
|
47
|
+
}, [state]);
|
|
48
|
+
// return
|
|
49
|
+
return React.createElement(React.Fragment);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* React application
|
|
53
|
+
*/
|
|
54
|
+
export class ReactApp extends CoreApp {
|
|
55
|
+
/**
|
|
56
|
+
* Constructor
|
|
57
|
+
* @param settings Settings
|
|
58
|
+
* @param name Application name
|
|
59
|
+
*/
|
|
60
|
+
constructor(settings, name) {
|
|
61
|
+
super(settings, ReactApp.createApi(settings), ReactApp.createNotifier(), new WindowStorage(), name);
|
|
62
|
+
/**
|
|
63
|
+
* User state
|
|
64
|
+
*/
|
|
65
|
+
this.userState = new UserState();
|
|
66
|
+
if (BridgeUtils.host) {
|
|
67
|
+
const startUrl = BridgeUtils.host.getStartUrl();
|
|
68
|
+
this.history = createMemoryHistory({
|
|
69
|
+
initialEntries: startUrl == null ? undefined : [startUrl]
|
|
70
|
+
});
|
|
71
|
+
BridgeUtils.host.onUpdate((app, version) => {
|
|
72
|
+
this.notifier.message(NotificationMessageType.Success, this.get('updateTip') + `(${[app, version].join(', ')})`, this.get('updateReady'));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.history = createBrowserHistory();
|
|
77
|
+
}
|
|
78
|
+
this.cultureState = new CultureState(settings.currentCulture);
|
|
79
|
+
this.pageState = new PageState();
|
|
80
|
+
globalApp = this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get notifier provider
|
|
84
|
+
*/
|
|
85
|
+
static get notifierProvider() {
|
|
86
|
+
return this._notifierProvider;
|
|
87
|
+
}
|
|
88
|
+
static createApi(settings) {
|
|
89
|
+
// API
|
|
90
|
+
// Support to replace {hostname} with current hostname
|
|
91
|
+
const api = createClient();
|
|
92
|
+
api.baseUrl = settings.endpoint;
|
|
93
|
+
return api;
|
|
94
|
+
}
|
|
95
|
+
static createNotifier() {
|
|
96
|
+
// Notifier
|
|
97
|
+
ReactApp._notifierProvider = NotifierMU.setup();
|
|
98
|
+
return NotifierMU.instance;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Override alert action result
|
|
102
|
+
* @param result Action result
|
|
103
|
+
* @param callback Callback
|
|
104
|
+
*/
|
|
105
|
+
alertResult(result, callback) {
|
|
106
|
+
const message = this.formatResult(result);
|
|
107
|
+
if (message.endsWith(')')) {
|
|
108
|
+
const startPos = message.lastIndexOf('(');
|
|
109
|
+
if (startPos > 0) {
|
|
110
|
+
const main = message.substring(0, startPos).trim();
|
|
111
|
+
const tip = message.substring(startPos);
|
|
112
|
+
const titleNode = React.createElement(React.Fragment, null, main, React.createElement('br'), React.createElement('span', { style: { fontSize: '9px' } }, tip));
|
|
113
|
+
this.notifier.alert(titleNode, callback);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
this.notifier.alert(message, callback);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Change culture
|
|
121
|
+
* @param culture New culture definition
|
|
122
|
+
*/
|
|
123
|
+
changeCulture(culture) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
// Super call to update cultrue
|
|
126
|
+
super.changeCulture(culture);
|
|
127
|
+
// Update component labels
|
|
128
|
+
Labels.setLabels(culture.resources, {
|
|
129
|
+
notificationMU: {
|
|
130
|
+
alertTitle: 'warning',
|
|
131
|
+
alertOK: 'ok',
|
|
132
|
+
confirmTitle: 'confirm',
|
|
133
|
+
confirmYes: 'ok',
|
|
134
|
+
confirmNo: 'cancel',
|
|
135
|
+
promptTitle: 'prompt',
|
|
136
|
+
promptCancel: 'cancel',
|
|
137
|
+
promptOK: 'ok'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// Notify host
|
|
141
|
+
(_a = BridgeUtils.host) === null || _a === void 0 ? void 0 : _a.changeCulture(culture.name);
|
|
142
|
+
// Document title
|
|
143
|
+
document.title = (_b = this.get(this.name)) !== null && _b !== void 0 ? _b : this.name;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Change culture extended
|
|
147
|
+
* @param dispatch Dispatch method
|
|
148
|
+
* @param culture New culture definition
|
|
149
|
+
*/
|
|
150
|
+
changeCultureEx(dispatch, culture) {
|
|
151
|
+
// Same?
|
|
152
|
+
if (culture.name === this.culture)
|
|
153
|
+
return;
|
|
154
|
+
// Dispatch action
|
|
155
|
+
dispatch(culture);
|
|
156
|
+
// Super call
|
|
157
|
+
this.changeCulture(culture);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get date format props
|
|
161
|
+
* @returns Props
|
|
162
|
+
*/
|
|
163
|
+
getDateFormatProps() {
|
|
164
|
+
return { culture: this.culture, timeZone: this.getTimeZone() };
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get money format props
|
|
168
|
+
* @param currency Currency, if undefined, default currency applied
|
|
169
|
+
* @returns Props
|
|
170
|
+
*/
|
|
171
|
+
getMoneyFormatProps(currency) {
|
|
172
|
+
return { culture: this.culture, currency: currency !== null && currency !== void 0 ? currency : this.currency };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Fresh countdown UI
|
|
176
|
+
* @param callback Callback
|
|
177
|
+
*/
|
|
178
|
+
freshCountdownUI(callback) {
|
|
179
|
+
// Labels
|
|
180
|
+
const labels = this.getLabels('cancel', 'tokenExpiry');
|
|
181
|
+
// Progress
|
|
182
|
+
const progress = React.createElement(ProgressCount, {
|
|
183
|
+
seconds: 30,
|
|
184
|
+
valueUnit: 's',
|
|
185
|
+
onComplete: () => {
|
|
186
|
+
// Stop the progress
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
// Popup
|
|
191
|
+
this.notifier.alert(labels.tokenExpiry, async () => {
|
|
192
|
+
if (callback)
|
|
193
|
+
await callback();
|
|
194
|
+
else
|
|
195
|
+
await this.tryLogin();
|
|
196
|
+
}, undefined, {
|
|
197
|
+
okLabel: labels.cancel,
|
|
198
|
+
primaryButton: { fullWidth: true, autoFocus: false },
|
|
199
|
+
inputs: progress
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Redirect to the Url
|
|
204
|
+
* @param url Url
|
|
205
|
+
*/
|
|
206
|
+
redirectTo(url) {
|
|
207
|
+
this.history.push(url);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Set page data
|
|
211
|
+
* @param data Page data
|
|
212
|
+
*/
|
|
213
|
+
setPageData(data) {
|
|
214
|
+
// Dispatch the change
|
|
215
|
+
if (this.pageStateDispatch != null) {
|
|
216
|
+
this.pageStateDispatch({
|
|
217
|
+
type: PageActionType.Data,
|
|
218
|
+
data
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Set page title and data
|
|
224
|
+
* @param title Page title
|
|
225
|
+
*/
|
|
226
|
+
setPageTitle(title) {
|
|
227
|
+
// Data
|
|
228
|
+
const data = { title };
|
|
229
|
+
// Dispatch the change
|
|
230
|
+
if (this.pageStateDispatch != null) {
|
|
231
|
+
this.pageStateDispatch({
|
|
232
|
+
type: PageActionType.Title,
|
|
233
|
+
data
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Set page title and data
|
|
239
|
+
* @param key Page title resource key
|
|
240
|
+
*/
|
|
241
|
+
setPageKey(key) {
|
|
242
|
+
var _a;
|
|
243
|
+
this.setPageTitle((_a = this.get(key)) !== null && _a !== void 0 ? _a : '');
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Show input dialog
|
|
247
|
+
* @param props Props
|
|
248
|
+
*/
|
|
249
|
+
showInputDialog({ title, message, callback, ...rest }) {
|
|
250
|
+
return this.notifier.prompt(message, callback, title, rest);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* User login extended
|
|
254
|
+
* @param user New user
|
|
255
|
+
* @param refreshToken Refresh token
|
|
256
|
+
* @param keep Keep in local storage or not
|
|
257
|
+
* @param dispatch User state dispatch
|
|
258
|
+
*/
|
|
259
|
+
userLogin(user, refreshToken, keep, dispatch) {
|
|
260
|
+
// Super call, set token
|
|
261
|
+
super.userLogin(user, refreshToken, keep);
|
|
262
|
+
// Dispatch action
|
|
263
|
+
if (this.userStateDispatch != null && dispatch !== false)
|
|
264
|
+
this.userStateDispatch({
|
|
265
|
+
type: UserActionType.Login,
|
|
266
|
+
user
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* User logout
|
|
271
|
+
* @param clearToken Clear refresh token or not
|
|
272
|
+
*/
|
|
273
|
+
userLogout(clearToken = true) {
|
|
274
|
+
// Super call
|
|
275
|
+
super.userLogout(clearToken);
|
|
276
|
+
// Dispatch action
|
|
277
|
+
if (this.userStateDispatch != null)
|
|
278
|
+
this.userStateDispatch({
|
|
279
|
+
type: UserActionType.Logout
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* User unauthorized
|
|
284
|
+
*/
|
|
285
|
+
userUnauthorized() {
|
|
286
|
+
// Super call
|
|
287
|
+
super.userUnauthorized();
|
|
288
|
+
if (this.userStateDispatch != null) {
|
|
289
|
+
// There is delay during state update
|
|
290
|
+
// Not a good idea to try login multiple times with API calls
|
|
291
|
+
this.userStateDispatch({
|
|
292
|
+
type: UserActionType.Unauthorized
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|