@tuya-sat/sdf-main-sdk 0.0.1-beta.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/.vscode/settings.json +5 -0
- package/README.md +1 -0
- package/antd.less.overwrite.js +56 -0
- package/color.js +140 -0
- package/dark-variable.less +1449 -0
- package/package.json +74 -0
- package/scripts/gen-localize-file.mjs +56 -0
- package/src/App.less +156 -0
- package/src/App.tsx +87 -0
- package/src/api/index.ts +52 -0
- package/src/api/req.ts +23 -0
- package/src/api/res.ts +29 -0
- package/src/api/urls.ts +30 -0
- package/src/api/utils.ts +41 -0
- package/src/assets/imgs/404.svg +194 -0
- package/src/assets/imgs/reLogin.png +0 -0
- package/src/components/404/index.tsx +44 -0
- package/src/components/500/index.tsx +49 -0
- package/src/components/BCustomNav/index.module.less +17 -0
- package/src/components/BCustomNav/index.tsx +108 -0
- package/src/components/BForgot/index.module.less +5 -0
- package/src/components/BForgot/index.tsx +96 -0
- package/src/components/BHeaderUser/account.png +0 -0
- package/src/components/BHeaderUser/app-scan-en.png +0 -0
- package/src/components/BHeaderUser/app-scan-zh.png +0 -0
- package/src/components/BHeaderUser/app-scan.png +0 -0
- package/src/components/BHeaderUser/components/BSwitchLang/index.module.less +6 -0
- package/src/components/BHeaderUser/components/BSwitchLang/index.tsx +56 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/Content.tsx +199 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/index.module.less +11 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/index.tsx +27 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/hooks.ts +104 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/index.module.less +70 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/index.tsx +184 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/table/index.tsx +184 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/table/read.tsx +67 -0
- package/src/components/BHeaderUser/components/Badge/components/Notice/tools/index.tsx +116 -0
- package/src/components/BHeaderUser/components/Badge/index.module.less +99 -0
- package/src/components/BHeaderUser/components/Badge/index.tsx +179 -0
- package/src/components/BHeaderUser/index.module.less +105 -0
- package/src/components/BHeaderUser/index.tsx +261 -0
- package/src/components/BHeaderUser/logout.tsx +26 -0
- package/src/components/BLayout/components/Header/index.module.less +27 -0
- package/src/components/BLayout/components/Header/index.tsx +36 -0
- package/src/components/BLayout/components/Layout/empty.tsx +35 -0
- package/src/components/BLayout/components/Layout/emptyPage.png +0 -0
- package/src/components/BLayout/components/Layout/index.tsx +72 -0
- package/src/components/BLayout/components/Logo.tsx +6 -0
- package/src/components/BLayout/components/Menu/collapse.tsx +41 -0
- package/src/components/BLayout/components/Menu/image/close.tsx +26 -0
- package/src/components/BLayout/components/Menu/image/closedefault.tsx +26 -0
- package/src/components/BLayout/components/Menu/image/open.tsx +38 -0
- package/src/components/BLayout/components/Menu/image/opendefault.tsx +38 -0
- package/src/components/BLayout/components/Menu/index.module.less +125 -0
- package/src/components/BLayout/components/Menu/index.tsx +244 -0
- package/src/components/BLayout/components/MenuIcon.module.less +5 -0
- package/src/components/BLayout/components/MenuIcon.tsx +46 -0
- package/src/components/BLayout/components/MultiSider/index.module.less +104 -0
- package/src/components/BLayout/components/MultiSider/index.tsx +172 -0
- package/src/components/BLayout/components/Sider/index.less +64 -0
- package/src/components/BLayout/components/Sider/index.module.less +17 -0
- package/src/components/BLayout/components/Sider/index.tsx +34 -0
- package/src/components/BLayout/index.tsx +78 -0
- package/src/components/BLayoutLogin/index.module.less +65 -0
- package/src/components/BLayoutLogin/index.tsx +68 -0
- package/src/components/BLayoutLogin/login.jpg +0 -0
- package/src/components/BLogin/component/Clause/index.module.less +25 -0
- package/src/components/BLogin/component/Clause/index.tsx +58 -0
- package/src/components/BLogin/component/ForgotBtn/index.module.less +9 -0
- package/src/components/BLogin/component/ForgotBtn/index.tsx +18 -0
- package/src/components/BLogin/component/Password/index.tsx +39 -0
- package/src/components/BLogin/component/SubmitBtn/index.tsx +30 -0
- package/src/components/BLogin/component/TenanSpace/index.tsx +28 -0
- package/src/components/BLogin/component/Title/index.module.less +6 -0
- package/src/components/BLogin/component/Title/index.tsx +12 -0
- package/src/components/BLogin/component/UserName/index.tsx +48 -0
- package/src/components/BLogin/component/VerifyCode/index.module.less +11 -0
- package/src/components/BLogin/component/VerifyCode/index.tsx +165 -0
- package/src/components/BLogin/index.module.less +31 -0
- package/src/components/BLogin/index.tsx +210 -0
- package/src/components/BRegister/components/TenantName/index.tsx +26 -0
- package/src/components/BRegister/index.module.less +5 -0
- package/src/components/BRegister/index.tsx +71 -0
- package/src/components/Back/index.tsx +25 -0
- package/src/components/IconFont/font.js +66 -0
- package/src/components/IconFont/index.tsx +18 -0
- package/src/components/MicroComponent/Header/index.module.less +7 -0
- package/src/components/MicroComponent/Header/index.tsx +220 -0
- package/src/components/PForgot/index.tsx +10 -0
- package/src/components/PLogin/index.tsx +12 -0
- package/src/components/PRegister/index.tsx +10 -0
- package/src/components/PSetting/index.module.less +53 -0
- package/src/components/PSetting/index.tsx +420 -0
- package/src/constant/chargeStatus.ts +6 -0
- package/src/constant/imgs.ts +6 -0
- package/src/constant/index.ts +293 -0
- package/src/dark-variable.less +1449 -0
- package/src/global.d.ts +54 -0
- package/src/hooks/index.ts +133 -0
- package/src/index.css +1493 -0
- package/src/index.tsx +105 -0
- package/src/lang/en.json +266 -0
- package/src/lang/index.ts +44 -0
- package/src/lang/utils.ts +285 -0
- package/src/lang/zh.json +270 -0
- package/src/micro-script/theme/index.ts +29 -0
- package/src/micro-script/theme/theme-css/static.js +73 -0
- package/src/micro-script/theme/theme-css/subscriber.ts +201 -0
- package/src/micro-script/theme/util/index.ts +58 -0
- package/src/mqtt/index.ts +121 -0
- package/src/pages/403.tsx +18 -0
- package/src/pages/404.tsx +17 -0
- package/src/pages/expiration.tsx +23 -0
- package/src/pages/forgot.tsx +9 -0
- package/src/pages/home/index.tsx +172 -0
- package/src/pages/home/setting/index.tsx +7 -0
- package/src/pages/index.ts +50 -0
- package/src/pages/login.tsx +46 -0
- package/src/pages/register.tsx +9 -0
- package/src/pages/relogin/index.module.less +0 -0
- package/src/pages/relogin/index.tsx +54 -0
- package/src/plugins/index.ts +11 -0
- package/src/public-path.js +8 -0
- package/src/qiankun/globalState.ts +6 -0
- package/src/qiankun/index.ts +174 -0
- package/src/qiankun/utils/index.ts +69 -0
- package/src/qiankun/xhook/index.ts +193 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/sentry/index.ts +33 -0
- package/src/sky/index.ts +57 -0
- package/src/theme/custom-dark.less +64 -0
- package/src/theme/custom-light.less +48 -0
- package/src/theme/index.less +327 -0
- package/src/theme/variable.less +13 -0
- package/src/utils/checkPass.ts +21 -0
- package/src/utils/common.ts +195 -0
- package/src/utils/eventBus.ts +112 -0
- package/src/utils/gt.js +293 -0
- package/src/utils/index.ts +89 -0
- package/src/utils/theme/base.ts +110 -0
- package/src/utils/theme/changeCssVariable.ts +157 -0
- package/src/utils/theme/changeMenuCssVariable.ts +176 -0
- package/src/utils/theme/index.ts +85 -0
- package/src/utils/theme/store.ts +37 -0
- package/tsconfig.json +28 -0
- package/typings.d.ts +10 -0
- package/webpack.config.js +103 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS';
|
|
2
|
+
import type {
|
|
3
|
+
Theme,
|
|
4
|
+
UserColorConfig,
|
|
5
|
+
ColorConfig,
|
|
6
|
+
UserColorConfigWithThemeAndMenu,
|
|
7
|
+
} from './base';
|
|
8
|
+
|
|
9
|
+
//相当于antd的css变量前缀
|
|
10
|
+
const MAIN_PREFIX = 'main';
|
|
11
|
+
|
|
12
|
+
//相当于动态菜单的变量前缀
|
|
13
|
+
const MAIN_MENU_PREFIX = `${MAIN_PREFIX}-app`;
|
|
14
|
+
|
|
15
|
+
const PRIMARY_COLOR_VARIABLE = `var(--${MAIN_PREFIX}-primary-color)`;
|
|
16
|
+
const PRIMARY_COLOR_ACTIVE_VARIABLE = `var(--${MAIN_PREFIX}-primary-1)`;
|
|
17
|
+
|
|
18
|
+
const LIGHT_MENU = {
|
|
19
|
+
menuBg: '#fff', //底色
|
|
20
|
+
menuText: 'rgba(0, 0, 0, 0.85)', //文案&icon色值
|
|
21
|
+
menuBgExpand: '#fff', //展开底色
|
|
22
|
+
menuTextExpand: 'rgba(0,0,0,0.85)', //展开文案&icon色值
|
|
23
|
+
menuBgActived: PRIMARY_COLOR_ACTIVE_VARIABLE, //选中底色
|
|
24
|
+
menuTextActived: PRIMARY_COLOR_VARIABLE, //选中文案&icon色值
|
|
25
|
+
// 顶部导航
|
|
26
|
+
navigateBg: '#fff',
|
|
27
|
+
navigateText: 'rgba(0, 0, 0, 0.85)',
|
|
28
|
+
navigateTextHover: PRIMARY_COLOR_VARIABLE,
|
|
29
|
+
navigateBoundary: '#f0f0f0',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const LIGHT_MENU_GROUP = {
|
|
33
|
+
...LIGHT_MENU,
|
|
34
|
+
// 分组菜单
|
|
35
|
+
menuSlideBg: '#fff',
|
|
36
|
+
menuSlideText: 'rgba(102, 102, 102, 1)',
|
|
37
|
+
menuSlideBgActived: '#fff',
|
|
38
|
+
menuSlideTextActived: PRIMARY_COLOR_VARIABLE,
|
|
39
|
+
menuSlideBoundary: '#f0f0f0',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const DARK_MENU = {
|
|
43
|
+
menuBg: '#2C303F', //底色
|
|
44
|
+
menuText: 'rgba(255, 255, 255, 0.85)', //文案&icon色值
|
|
45
|
+
menuBgExpand: '#2C303F', //展开底色
|
|
46
|
+
menuTextExpand: 'rgba(255,255,255,0.85)', //展开文案&icon色值
|
|
47
|
+
menuBgActived: '#202332', //选中底色
|
|
48
|
+
menuTextActived: '#ffffff', //选中文案&icon色值
|
|
49
|
+
// 顶部导航
|
|
50
|
+
navigateBg: '#2C303F',
|
|
51
|
+
navigateText: '#ffffff',
|
|
52
|
+
navigateTextHover: PRIMARY_COLOR_VARIABLE,
|
|
53
|
+
navigateBoundary: 'rgba(255,255,255,0.12)',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const DARK_MENU_GROUP = {
|
|
57
|
+
...DARK_MENU,
|
|
58
|
+
// 分组菜单
|
|
59
|
+
menuSlideBg: '#2C303F',
|
|
60
|
+
menuSlideText: 'rgba(255, 255, 255, 0.85)',
|
|
61
|
+
menuSlideBgActived: '#202332',
|
|
62
|
+
menuSlideTextActived: '#ffffff',
|
|
63
|
+
menuSlideBoundary: 'rgba(255,255,255,0.12)',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const DEFAULT_USER_CONFIG = {
|
|
67
|
+
normal: {
|
|
68
|
+
light: LIGHT_MENU,
|
|
69
|
+
dark: DARK_MENU,
|
|
70
|
+
},
|
|
71
|
+
group: {
|
|
72
|
+
light: LIGHT_MENU_GROUP,
|
|
73
|
+
dark: DARK_MENU_GROUP,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function hexToRgba(hex: string, opacity: number) {
|
|
78
|
+
const [, hexValue] = hex.split('#');
|
|
79
|
+
const [i, ii, iii, iv, v, vi] = hexValue.split('');
|
|
80
|
+
const r = parseInt(`${i}${ii}`, 16);
|
|
81
|
+
const g = parseInt(`${iii}${iv}`, 16);
|
|
82
|
+
const b = parseInt(`${v}${vi}`, 16);
|
|
83
|
+
return `rgba(${r},${g},${b},${opacity})`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function processUserConfig(config: UserColorConfig): ColorConfig {
|
|
87
|
+
return Object.entries(config).reduce((prev: ColorConfig, item) => {
|
|
88
|
+
const [key, value] = item;
|
|
89
|
+
const { hex, a } = value;
|
|
90
|
+
prev[key] = hexToRgba(hex, a);
|
|
91
|
+
return prev;
|
|
92
|
+
}, {});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getMenuType() {
|
|
96
|
+
return window._SDF.saas.entries.entry_mode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getDefaultConfig({
|
|
100
|
+
theme,
|
|
101
|
+
menuType,
|
|
102
|
+
}: {
|
|
103
|
+
theme: Theme;
|
|
104
|
+
menuType: `${keyof UserColorConfigWithThemeAndMenu}`;
|
|
105
|
+
}) {
|
|
106
|
+
return DEFAULT_USER_CONFIG[menuType][theme];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default function changeMenuCssVariable({
|
|
110
|
+
menuColor,
|
|
111
|
+
theme,
|
|
112
|
+
prefix = MAIN_MENU_PREFIX,
|
|
113
|
+
}: {
|
|
114
|
+
menuColor: UserColorConfigWithThemeAndMenu | null;
|
|
115
|
+
theme: Theme;
|
|
116
|
+
prefix?: string;
|
|
117
|
+
}) {
|
|
118
|
+
const menuType = getMenuType();
|
|
119
|
+
const color = menuColor?.[menuType]?.[theme] || {};
|
|
120
|
+
|
|
121
|
+
const combinedConfig = {
|
|
122
|
+
...getDefaultConfig({ theme, menuType }),
|
|
123
|
+
...processUserConfig(color),
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const {
|
|
127
|
+
menuBg,
|
|
128
|
+
menuText,
|
|
129
|
+
menuBgExpand,
|
|
130
|
+
menuTextExpand,
|
|
131
|
+
menuBgActived,
|
|
132
|
+
menuTextActived,
|
|
133
|
+
menuSlideBg,
|
|
134
|
+
menuSlideText,
|
|
135
|
+
menuSlideBgActived,
|
|
136
|
+
menuSlideTextActived,
|
|
137
|
+
menuSlideBoundary,
|
|
138
|
+
navigateBg,
|
|
139
|
+
navigateText,
|
|
140
|
+
navigateTextHover,
|
|
141
|
+
navigateBoundary,
|
|
142
|
+
} = combinedConfig;
|
|
143
|
+
|
|
144
|
+
const cssList = {
|
|
145
|
+
[`--${prefix}-menu-bg`]: menuBg, //底色
|
|
146
|
+
[`--${prefix}-menu-text`]: menuText, //文案&icon色值
|
|
147
|
+
[`--${prefix}-menu-bg-expand`]: menuBgExpand, //展开底色
|
|
148
|
+
[`--${prefix}-menu-text-expand`]: menuTextExpand, //展开文案&icon色值
|
|
149
|
+
[`--${prefix}-menu-bg-actived`]: menuBgActived, //选中底色
|
|
150
|
+
[`--${prefix}-menu-text-actived`]: menuTextActived, //选中文案&icon色值
|
|
151
|
+
// 分组菜单
|
|
152
|
+
[`--${prefix}-menu-slide-bg`]: menuSlideBg,
|
|
153
|
+
[`--${prefix}-menu-slide-text`]: menuSlideText,
|
|
154
|
+
[`--${prefix}-menu-slide-bg-actived`]: menuSlideBgActived,
|
|
155
|
+
[`--${prefix}-menu-slide-text-actived`]: menuSlideTextActived,
|
|
156
|
+
[`--${prefix}-menu-slide-boundary`]: menuSlideBoundary,
|
|
157
|
+
// 顶部导航
|
|
158
|
+
[`--${prefix}-navigate-bg`]: navigateBg,
|
|
159
|
+
[`--${prefix}-navigate-text`]: navigateText,
|
|
160
|
+
[`--${prefix}-navigate-text-hover`]: navigateTextHover,
|
|
161
|
+
[`--${prefix}-navigate-boundary`]: navigateBoundary,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const css = Object.keys(cssList).reduce((prev, key) => {
|
|
165
|
+
return `${prev}${key}:${cssList[key]};\n`;
|
|
166
|
+
}, '');
|
|
167
|
+
|
|
168
|
+
updateCSS(
|
|
169
|
+
`
|
|
170
|
+
:root {
|
|
171
|
+
${css}
|
|
172
|
+
}
|
|
173
|
+
`,
|
|
174
|
+
`-${prefix}-menu-dynamic-theme`,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { microThemeControl } from '@/micro-script/theme';
|
|
3
|
+
import { changeCssVarible } from './changeCssVariable';
|
|
4
|
+
import changeMenuCssVariable, { hexToRgba } from './changeMenuCssVariable';
|
|
5
|
+
import { themeSubscribe } from './store';
|
|
6
|
+
import type { Theme } from './base';
|
|
7
|
+
import {
|
|
8
|
+
LIGHT,
|
|
9
|
+
DARK,
|
|
10
|
+
getSupportedTheme,
|
|
11
|
+
getCssVarible,
|
|
12
|
+
getDynamicMenuTheme,
|
|
13
|
+
getRenderTheme,
|
|
14
|
+
} from './base';
|
|
15
|
+
|
|
16
|
+
function createDisableTransition() {
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.textContent = `
|
|
19
|
+
*{
|
|
20
|
+
transition:none !important;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
document.head.appendChild(style);
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
// 可能会有延迟
|
|
26
|
+
document.head.removeChild(style);
|
|
27
|
+
}, 200);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function changeMainCssLink(theme: Theme) {
|
|
31
|
+
createDisableTransition();
|
|
32
|
+
const link = document.querySelector('#macro-dark-css');
|
|
33
|
+
link.setAttribute('rel', theme === DARK ? 'stylesheet' : 'stylesheet/css');
|
|
34
|
+
document.body.setAttribute('class', theme);
|
|
35
|
+
document.querySelector('html').style['colorScheme'] = theme;
|
|
36
|
+
themeSubscribe.publish(theme);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getRenderCssVariable(theme: Theme) {
|
|
40
|
+
const supportedTheme = getSupportedTheme();
|
|
41
|
+
const { primaryColor, primaryColorInAll } = getCssVarible();
|
|
42
|
+
let _primaryColor = primaryColor;
|
|
43
|
+
if (supportedTheme === 'all' && theme === DARK && primaryColorInAll) {
|
|
44
|
+
_primaryColor = primaryColorInAll;
|
|
45
|
+
}
|
|
46
|
+
if (typeof _primaryColor === 'object') {
|
|
47
|
+
const { hex, a } = _primaryColor;
|
|
48
|
+
_primaryColor = hexToRgba(hex, a);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
primaryColor: _primaryColor as string,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function changeTheme(theme: Theme) {
|
|
56
|
+
const renderVariable = getRenderCssVariable(theme);
|
|
57
|
+
const menuColor = getDynamicMenuTheme();
|
|
58
|
+
changeMainCssLink(theme);
|
|
59
|
+
changeCssVarible(renderVariable, 'main', theme);
|
|
60
|
+
changeCssVarible(renderVariable, 'ant', theme);
|
|
61
|
+
changeMenuCssVariable({
|
|
62
|
+
menuColor,
|
|
63
|
+
theme,
|
|
64
|
+
});
|
|
65
|
+
microThemeControl.changeTheme(theme);
|
|
66
|
+
window.localStorage.setItem('theme', theme);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function useTheme() {
|
|
70
|
+
const [theme, setTheme] = useState(getRenderTheme);
|
|
71
|
+
function _changeTheme() {
|
|
72
|
+
const willRenderTheme = theme === LIGHT ? DARK : LIGHT;
|
|
73
|
+
changeTheme(willRenderTheme);
|
|
74
|
+
setTheme(willRenderTheme);
|
|
75
|
+
}
|
|
76
|
+
return { theme, changeTheme: _changeTheme };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function initalTheme(cb?: () => void) {
|
|
80
|
+
const renderTheme = getRenderTheme();
|
|
81
|
+
changeTheme(renderTheme);
|
|
82
|
+
cb && cb();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { changeTheme, useTheme, initalTheme };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import PubSub from 'pubsub-js';
|
|
2
|
+
import type { Theme } from './base';
|
|
3
|
+
import { LIGHT } from './base';
|
|
4
|
+
|
|
5
|
+
const THEME_TYPE = 'CHANGE THEME';
|
|
6
|
+
|
|
7
|
+
function createSubscribe<T, P>(initalValue: T, type: string) {
|
|
8
|
+
const state = {
|
|
9
|
+
value: initalValue,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getValue = () => state.value;
|
|
13
|
+
|
|
14
|
+
const publish = (value: T) => {
|
|
15
|
+
state.value = value;
|
|
16
|
+
PubSub.publish(type, value);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const subscribe = (cb: P, callImmediately: boolean) => {
|
|
20
|
+
PubSub.subscribe(type, cb);
|
|
21
|
+
callImmediately && publish(getValue());
|
|
22
|
+
return () => {
|
|
23
|
+
PubSub.unsubscribe(cb);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
subscribe,
|
|
29
|
+
getValue,
|
|
30
|
+
publish,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const themeSubscribe = createSubscribe<
|
|
35
|
+
Theme,
|
|
36
|
+
(type: typeof THEME_TYPE, value: Theme) => void
|
|
37
|
+
>(LIGHT, THEME_TYPE);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "./",
|
|
4
|
+
"paths": {
|
|
5
|
+
"@/*": ["./src/*"]
|
|
6
|
+
},
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"lib": ["ES2021", "DOM"],
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"target": "es6",
|
|
11
|
+
"composite": false,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"declarationDir": "dist",
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"inlineSources": false,
|
|
18
|
+
"isolatedModules": false,
|
|
19
|
+
"moduleResolution": "node",
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"noUnusedParameters": false,
|
|
22
|
+
"preserveWatchOutput": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"strict": false,
|
|
25
|
+
"resolveJsonModule": true
|
|
26
|
+
},
|
|
27
|
+
"include": ["./src", "./typings.d.ts"]
|
|
28
|
+
}
|
package/typings.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const webpack = require('webpack');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const BundleAnalyzerPlugin =
|
|
5
|
+
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
6
|
+
|
|
7
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
mode: 'development',
|
|
11
|
+
entry: path.join(__dirname, '/src/index.tsx'),
|
|
12
|
+
target: ['web', 'es5'],
|
|
13
|
+
output: {
|
|
14
|
+
filename: '[name].bundle.js',
|
|
15
|
+
chunkFilename: '[name].[hash:8].chunk.js',
|
|
16
|
+
path: path.join(__dirname, '/dist'),
|
|
17
|
+
library: {
|
|
18
|
+
type: 'commonjs2',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
externals: {
|
|
22
|
+
react: 'react',
|
|
23
|
+
antd: 'antd',
|
|
24
|
+
moment: 'moment',
|
|
25
|
+
'@tuya-sat/galaxy': '@tuya-sat/galaxy',
|
|
26
|
+
axios: 'axios',
|
|
27
|
+
},
|
|
28
|
+
resolve: {
|
|
29
|
+
extensions: ['.js', '.tsx', '.ts'],
|
|
30
|
+
fallback: {
|
|
31
|
+
url: require.resolve('url/'),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
plugins: [
|
|
35
|
+
// new BundleAnalyzerPlugin(),
|
|
36
|
+
new webpack.ProvidePlugin({
|
|
37
|
+
process: 'process/browser',
|
|
38
|
+
Buffer: ['buffer', 'Buffer'],
|
|
39
|
+
}),
|
|
40
|
+
new MiniCssExtractPlugin(),
|
|
41
|
+
],
|
|
42
|
+
resolve: {
|
|
43
|
+
extensions: ['.ts', '.tsx', '.js', 'jsx'],
|
|
44
|
+
alias: {
|
|
45
|
+
'@': path.resolve(__dirname, 'src'),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
module: {
|
|
49
|
+
rules: [
|
|
50
|
+
{
|
|
51
|
+
test: /.(ts|tsx)$/,
|
|
52
|
+
use: {
|
|
53
|
+
loader: 'babel-loader',
|
|
54
|
+
options: {
|
|
55
|
+
presets: [
|
|
56
|
+
[
|
|
57
|
+
'@babel/preset-env',
|
|
58
|
+
{
|
|
59
|
+
useBuiltIns: 'usage',
|
|
60
|
+
corejs: 3,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
['@babel/preset-react', { runtime: 'automatic' }],
|
|
64
|
+
'@babel/preset-typescript',
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
test: /\.(png|jpe?g|gif|svg)?$/,
|
|
71
|
+
type: 'asset/resource',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
test: /.(css|less)$/,
|
|
75
|
+
use: [
|
|
76
|
+
MiniCssExtractPlugin.loader,
|
|
77
|
+
'css-loader',
|
|
78
|
+
{
|
|
79
|
+
loader: 'postcss-loader',
|
|
80
|
+
options: {
|
|
81
|
+
postcssOptions: {
|
|
82
|
+
plugins: ['autoprefixer'],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
loader: 'less-loader',
|
|
88
|
+
options: {
|
|
89
|
+
lessOptions: {
|
|
90
|
+
modifyVars: {
|
|
91
|
+
'ant-prefix': 'main',
|
|
92
|
+
'macro-entry-name': 'custom-light',
|
|
93
|
+
'macro-variable-location': 'antd/lib/style/variable',
|
|
94
|
+
},
|
|
95
|
+
javascriptEnabled: true,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
};
|