create-packer 1.39.4 → 1.41.0
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/package.json +1 -1
- package/template/web-app/react-rsbuild/index.html +0 -1
- package/template/web-app/react-rsbuild/rsbuild.config.ts +9 -8
- package/template/web-app/vue/router/index.ts +2 -2
- package/template/web-app/vue-rsbuild/.env +2 -0
- package/template/web-app/vue-rsbuild/.env.development +2 -0
- package/template/web-app/{react-webpack → vue-rsbuild}/.gitignore +1 -1
- package/template/web-app/{react-webpack → vue-rsbuild}/.stylelintrc +9 -4
- package/template/web-app/{react-webpack → vue-rsbuild}/.vscode/extensions.json +3 -2
- package/template/web-app/vue-rsbuild/README.md +14 -0
- package/template/web-app/{react-webpack/commitlint.config.js → vue-rsbuild/commitlint.config.cjs} +1 -1
- package/template/web-app/vue-rsbuild/domain/app/app.ts +4 -0
- package/template/web-app/vue-rsbuild/domain/app/components/app.vue +18 -0
- package/template/web-app/vue-rsbuild/domain/app/components/index.ts +1 -0
- package/template/web-app/vue-rsbuild/domain/app/createComponentInstance.ts +44 -0
- package/template/web-app/vue-rsbuild/domain/app/index.ts +3 -0
- package/template/web-app/vue-rsbuild/env.d.ts +17 -0
- package/template/web-app/{react-webpack → vue-rsbuild}/eslint.config.js +25 -20
- package/template/web-app/{react-webpack → vue-rsbuild}/index.html +3 -3
- package/template/web-app/vue-rsbuild/main.ts +7 -0
- package/template/web-app/vue-rsbuild/package.json +73 -0
- package/template/web-app/vue-rsbuild/pages/home/index.ts +1 -0
- package/template/web-app/vue-rsbuild/pages/home/view.vue +16 -0
- package/template/web-app/vue-rsbuild/pages/index.ts +1 -0
- package/template/web-app/vue-rsbuild/pages/index.vue +3 -0
- package/template/web-app/vue-rsbuild/pages/not-found.vue +3 -0
- package/template/web-app/{react-webpack/postcss.config.js → vue-rsbuild/postcss.config.cjs} +9 -7
- package/template/web-app/vue-rsbuild/public/vite.svg +1 -0
- package/template/web-app/{react-webpack/domain → vue-rsbuild}/router/home/index.ts +1 -1
- package/template/web-app/vue-rsbuild/router/home/routes.ts +8 -0
- package/template/web-app/vue-rsbuild/router/index.ts +26 -0
- package/template/web-app/vue-rsbuild/router/names.ts +5 -0
- package/template/web-app/vue-rsbuild/rsbuild.config.ts +74 -0
- package/template/web-app/vue-rsbuild/scripts/createChunks.ts +26 -0
- package/template/web-app/vue-rsbuild/scripts/index.ts +1 -0
- package/template/web-app/vue-rsbuild/shared/assets/vue.svg +1 -0
- package/template/web-app/vue-rsbuild/shared/hooks/index.ts +2 -0
- package/template/web-app/vue-rsbuild/shared/hooks/useList.ts +104 -0
- package/template/web-app/{react-webpack → vue-rsbuild}/shared/hooks/useVisible.ts +4 -4
- package/template/web-app/vue-rsbuild/shared/service/api.ts +1 -0
- package/template/web-app/vue-rsbuild/shared/service/home.ts +10 -0
- package/template/web-app/{react-webpack → vue-rsbuild}/shared/service/index.ts +1 -0
- package/template/web-app/vue-rsbuild/shared/service/request.ts +5 -0
- package/template/web-app/vue-rsbuild/shared/tools/index.ts +0 -0
- package/template/web-app/vue-rsbuild/tailwind.config.cjs +18 -0
- package/template/web-app/{react-webpack → vue-rsbuild}/tsconfig.json +10 -13
- package/template/web-app/vue-rsbuild/tsconfig.node.json +10 -0
- package/template/web-app/react-webpack/.env +0 -2
- package/template/web-app/react-webpack/.env.dev +0 -2
- package/template/web-app/react-webpack/.vscode/settings.json +0 -4
- package/template/web-app/react-webpack/README.md +0 -13
- package/template/web-app/react-webpack/domain/app/app.model.ts +0 -7
- package/template/web-app/react-webpack/domain/app/app.styled.ts +0 -3
- package/template/web-app/react-webpack/domain/app/components/app-context.tsx +0 -17
- package/template/web-app/react-webpack/domain/app/components/app.tsx +0 -24
- package/template/web-app/react-webpack/domain/app/components/index.ts +0 -1
- package/template/web-app/react-webpack/domain/app/index.ts +0 -2
- package/template/web-app/react-webpack/domain/router/components/index.ts +0 -2
- package/template/web-app/react-webpack/domain/router/components/route-layout.tsx +0 -19
- package/template/web-app/react-webpack/domain/router/components/sub-route-outlet.tsx +0 -22
- package/template/web-app/react-webpack/domain/router/home/routes.tsx +0 -13
- package/template/web-app/react-webpack/domain/router/ids.ts +0 -6
- package/template/web-app/react-webpack/domain/router/index.ts +0 -4
- package/template/web-app/react-webpack/domain/router/router.tsx +0 -28
- package/template/web-app/react-webpack/domain/router/router.types.ts +0 -3
- package/template/web-app/react-webpack/global.d.ts +0 -26
- package/template/web-app/react-webpack/main.tsx +0 -4
- package/template/web-app/react-webpack/package.json +0 -84
- package/template/web-app/react-webpack/pages/home/index.ts +0 -1
- package/template/web-app/react-webpack/pages/home/view.styled.ts +0 -7
- package/template/web-app/react-webpack/pages/home/view.tsx +0 -10
- package/template/web-app/react-webpack/pages/index.tsx +0 -18
- package/template/web-app/react-webpack/pages/not-found.tsx +0 -3
- package/template/web-app/react-webpack/public/react.svg +0 -1
- package/template/web-app/react-webpack/shared/assets/react.svg +0 -1
- package/template/web-app/react-webpack/shared/components/componentInstance.tsx +0 -78
- package/template/web-app/react-webpack/shared/components/index.ts +0 -1
- package/template/web-app/react-webpack/shared/hooks/defineRouter/defineRouter.types.ts +0 -33
- package/template/web-app/react-webpack/shared/hooks/defineRouter/deineRouter.tsx +0 -160
- package/template/web-app/react-webpack/shared/hooks/defineRouter/index.ts +0 -2
- package/template/web-app/react-webpack/shared/hooks/index.ts +0 -6
- package/template/web-app/react-webpack/shared/hooks/useInterval.ts +0 -26
- package/template/web-app/react-webpack/shared/hooks/useLoadingAction.ts +0 -27
- package/template/web-app/react-webpack/shared/hooks/useLowPriorityState.ts +0 -26
- package/template/web-app/react-webpack/shared/hooks/useSyncState.ts +0 -15
- package/template/web-app/react-webpack/shared/service/home.ts +0 -8
- package/template/web-app/react-webpack/shared/service/request.ts +0 -5
- package/template/web-app/react-webpack/shared/theme/index.ts +0 -1
- package/template/web-app/react-webpack/shared/theme/theme.styled.ts +0 -56
- package/template/web-app/react-webpack/shared/types/index.ts +0 -1
- package/template/web-app/react-webpack/shared/types/utils.ts +0 -2
- package/template/web-app/react-webpack/tsconfig.node.json +0 -9
- package/template/web-app/react-webpack/webpack.config.mjs +0 -161
- package/template/web-app/react-webpack/webpack_config/constant.mjs +0 -5
- package/template/web-app/react-webpack/webpack_config/index.mjs +0 -2
- package/template/web-app/react-webpack/webpack_config/styles.mjs +0 -22
- /package/template/web-app/{react-webpack → vue-rsbuild}/.editorconfig +0 -0
- /package/template/web-app/{react-webpack → vue-rsbuild}/.husky/commit-msg +0 -0
- /package/template/web-app/{react-webpack → vue-rsbuild}/.husky/pre-commit +0 -0
- /package/template/web-app/{react-webpack → vue-rsbuild}/.prettierignore +0 -0
- /package/template/web-app/{react-webpack → vue-rsbuild}/.prettierrc +0 -0
- /package/template/web-app/{react-webpack → vue-rsbuild}/.stylelintignore +0 -0
- /package/template/web-app/{react-webpack/domain/router/home/ids.ts → vue-rsbuild/router/home/names.ts} +0 -0
- /package/template/web-app/{react-webpack/shared/constant → vue-rsbuild/shared/components}/index.ts +0 -0
- /package/template/web-app/{react-webpack/shared/tools → vue-rsbuild/shared/constant}/index.ts +0 -0
- /package/template/web-app/{react-webpack/index.css → vue-rsbuild/style.css} +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef,
|
|
3
|
-
ForwardRefExoticComponent,
|
|
4
|
-
FunctionComponent,
|
|
5
|
-
PropsWithChildren,
|
|
6
|
-
PropsWithoutRef,
|
|
7
|
-
RefAttributes,
|
|
8
|
-
useImperativeHandle,
|
|
9
|
-
useRef,
|
|
10
|
-
useState
|
|
11
|
-
} from 'react'
|
|
12
|
-
import { createRoot } from 'react-dom/client'
|
|
13
|
-
|
|
14
|
-
const instanceMap: Record<string, { pending: Promise<any>; instance: any }> = {}
|
|
15
|
-
|
|
16
|
-
export interface refsType<P> {
|
|
17
|
-
$setProps: (newProps: P) => void
|
|
18
|
-
$updateProps: (newProps: Partial<P>) => void
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function create(Context?: FunctionComponent<PropsWithChildren<any>>) {
|
|
22
|
-
return async function <P extends Record<string, any>, Refs extends Record<string, any>>(
|
|
23
|
-
key: string,
|
|
24
|
-
Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
|
|
25
|
-
props?: P
|
|
26
|
-
) {
|
|
27
|
-
let current = instanceMap[key]
|
|
28
|
-
if (!current) {
|
|
29
|
-
const div = document.createElement('div')
|
|
30
|
-
document.body.appendChild(div)
|
|
31
|
-
const ApiComponent = forwardRef<Refs & refsType<P>>((__, refs) => {
|
|
32
|
-
const ref = useRef<Refs>(null)
|
|
33
|
-
const [state, setState] = useState<Partial<P>>(props || {})
|
|
34
|
-
|
|
35
|
-
useImperativeHandle(refs, () => {
|
|
36
|
-
return {
|
|
37
|
-
$setProps: newProps => {
|
|
38
|
-
setState(() => newProps)
|
|
39
|
-
},
|
|
40
|
-
$updateProps: newProps => {
|
|
41
|
-
if (newProps) {
|
|
42
|
-
setState(state => ({ ...state, ...newProps }))
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
...ref.current
|
|
46
|
-
} as Refs & refsType<P>
|
|
47
|
-
})
|
|
48
|
-
if (Context) {
|
|
49
|
-
return (
|
|
50
|
-
<Context>
|
|
51
|
-
<Component ref={ref} {...(state as any)} />
|
|
52
|
-
</Context>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
return <Component ref={ref} {...(state as any)} />
|
|
56
|
-
})
|
|
57
|
-
current = instanceMap[key] = {
|
|
58
|
-
instance: void 0,
|
|
59
|
-
pending: new Promise<void>(resolve => {
|
|
60
|
-
createRoot(div).render(
|
|
61
|
-
<ApiComponent
|
|
62
|
-
ref={instance => {
|
|
63
|
-
current.instance = instanceMap[key].instance = instance!
|
|
64
|
-
resolve()
|
|
65
|
-
}}
|
|
66
|
-
/>
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
await current.pending
|
|
72
|
-
current.instance.$setProps(props)
|
|
73
|
-
// Delay return to avoid sync issue
|
|
74
|
-
// ------------------------------------------------------------------------
|
|
75
|
-
await new Promise(resolve => setTimeout(resolve))
|
|
76
|
-
return current.instance as Refs & refsType<P>
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as componentInstance from './componentInstance'
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent, ReactNode } from 'react'
|
|
2
|
-
import { RouteObject } from 'react-router-dom'
|
|
3
|
-
|
|
4
|
-
export type routeType = Omit<RouteObject, 'children' | 'id'> & {
|
|
5
|
-
id: string
|
|
6
|
-
meta?: {
|
|
7
|
-
title?: string
|
|
8
|
-
/** 只在当前路由才显示的小提示 */
|
|
9
|
-
tip?: string
|
|
10
|
-
}
|
|
11
|
-
/** 静态配置,便于回退 */
|
|
12
|
-
unauthorizedOrigin?: boolean
|
|
13
|
-
/** 动态使用,用于程序校验 */
|
|
14
|
-
unauthorized?: boolean
|
|
15
|
-
query?: () => Record<string, any>
|
|
16
|
-
menu?: {
|
|
17
|
-
hidden?: boolean
|
|
18
|
-
icon?: FunctionComponent
|
|
19
|
-
label?: ReactNode
|
|
20
|
-
}
|
|
21
|
-
children?: routeType[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type editableRouteType = Omit<routeType, 'element' | 'errorElement' | 'children'>
|
|
25
|
-
|
|
26
|
-
export interface routerFactoryArgType {
|
|
27
|
-
basename: string
|
|
28
|
-
routes: routeType[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type routeByIdType = Omit<routeType, 'children'> & {
|
|
32
|
-
pos: string
|
|
33
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { DependencyList, useEffect, useMemo } from 'react'
|
|
2
|
-
import { useMatches, useSearchParams, NavigateOptions, createBrowserRouter } from 'react-router-dom'
|
|
3
|
-
import { assign, isArray, reduce, get, map, split, omit, cloneDeep, last, forEach } from 'lodash-es'
|
|
4
|
-
import { stringify, parse } from 'qs'
|
|
5
|
-
import { defineStore } from 'define-zustand'
|
|
6
|
-
import { routeByIdType, routeType, editableRouteType } from './defineRouter.types'
|
|
7
|
-
|
|
8
|
-
export default function defineRouter(router: ReturnType<typeof createBrowserRouter>) {
|
|
9
|
-
const useRouter = defineStore({
|
|
10
|
-
state: () => ({
|
|
11
|
-
routes: cloneDeep(router.routes) as routeType[]
|
|
12
|
-
}),
|
|
13
|
-
getter: {
|
|
14
|
-
routesById: state => {
|
|
15
|
-
return (function flat(routes: routeType[], parentRoute?: routeByIdType) {
|
|
16
|
-
return reduce(
|
|
17
|
-
routes,
|
|
18
|
-
(result, { children, ...route }, i) => {
|
|
19
|
-
const $route: routeByIdType = {
|
|
20
|
-
...route,
|
|
21
|
-
pos: parentRoute?.pos ? `${parentRoute?.pos}-${i}` : `${i}`
|
|
22
|
-
}
|
|
23
|
-
if (parentRoute) {
|
|
24
|
-
$route.path = `${
|
|
25
|
-
parentRoute.path === '/' ? '' : parentRoute.path
|
|
26
|
-
}/${$route.path}`
|
|
27
|
-
}
|
|
28
|
-
result[$route.id] = $route
|
|
29
|
-
if (isArray(children)) {
|
|
30
|
-
assign(result, flat(children, $route))
|
|
31
|
-
}
|
|
32
|
-
return result
|
|
33
|
-
},
|
|
34
|
-
{} as Record<string, routeByIdType>
|
|
35
|
-
)
|
|
36
|
-
})(state.routes)
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
actions: (getState, action) => {
|
|
40
|
-
function posToLodashPath(pos: string) {
|
|
41
|
-
if (pos) {
|
|
42
|
-
return `[${split(pos, '-').join('].children[')}]`
|
|
43
|
-
}
|
|
44
|
-
return ''
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function updateRoute(id: routeType['id'], updator: (route: editableRouteType) => void) {
|
|
48
|
-
const { routesById, routes } = getState()
|
|
49
|
-
const newRoutes = cloneDeep(routes)
|
|
50
|
-
const path = posToLodashPath(routesById[id].pos)
|
|
51
|
-
const route: routeType = get(newRoutes, path)
|
|
52
|
-
const newRoute = cloneDeep(omit(route, ['element', 'errorElement', 'children']))
|
|
53
|
-
updator(newRoute)
|
|
54
|
-
assign(route, newRoute)
|
|
55
|
-
action.setState({ routes: newRoutes })
|
|
56
|
-
}
|
|
57
|
-
function getRoute(id: routeType['id'], path?: string | string[]) {
|
|
58
|
-
const { routesById } = getState()
|
|
59
|
-
const route = routesById[id]
|
|
60
|
-
if (path) {
|
|
61
|
-
return get(route, path)
|
|
62
|
-
}
|
|
63
|
-
return route
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function genRouteUrl(id: routeType['id'], query?: Record<string, any>) {
|
|
67
|
-
const path = getRoute(id, 'path')
|
|
68
|
-
if (path) {
|
|
69
|
-
const { origin } = window.location
|
|
70
|
-
let url = origin + router.basename + path
|
|
71
|
-
url += query ? `?${stringify(query)}` : ''
|
|
72
|
-
return url
|
|
73
|
-
}
|
|
74
|
-
return void 0
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function openRoute(id: routeType['id'], query?: Record<string, any>) {
|
|
78
|
-
const url = genRouteUrl(id, query)
|
|
79
|
-
if (url) {
|
|
80
|
-
window.open(url)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function reloadRoute(id: routeType['id'], query?: Record<string, any>) {
|
|
85
|
-
const url = genRouteUrl(id, query)
|
|
86
|
-
if (url) {
|
|
87
|
-
window.location.replace(url)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function navigate(
|
|
92
|
-
to: { id: routeType['id']; query?: Record<string, any> },
|
|
93
|
-
opts?: NavigateOptions
|
|
94
|
-
) {
|
|
95
|
-
return router.navigate(
|
|
96
|
-
{
|
|
97
|
-
pathname: getRoute(to.id, 'path'),
|
|
98
|
-
search: to.query ? stringify(to.query) : ''
|
|
99
|
-
},
|
|
100
|
-
opts
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
navigate,
|
|
106
|
-
getRoute,
|
|
107
|
-
genRouteUrl,
|
|
108
|
-
openRoute,
|
|
109
|
-
reloadRoute,
|
|
110
|
-
updateRoute
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
function useQuery<Q>() {
|
|
115
|
-
const [params] = useSearchParams()
|
|
116
|
-
const query = parse(params.toString())
|
|
117
|
-
|
|
118
|
-
return query as Q
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function useMatchRoutes(): routeType[] {
|
|
122
|
-
const matches = useMatches()
|
|
123
|
-
const getRoute = useRouter(state => state.getRoute)
|
|
124
|
-
return useMemo(() => map(matches, o => getRoute(o.id)), [matches])
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @description 验证器返回false则无权限
|
|
129
|
-
*/
|
|
130
|
-
function useRoutePermission(
|
|
131
|
-
config: {
|
|
132
|
-
redirectRouteId: string
|
|
133
|
-
validator: (currentRoute?: routeType) => boolean
|
|
134
|
-
},
|
|
135
|
-
deps: DependencyList
|
|
136
|
-
) {
|
|
137
|
-
const matchRoutes = useMatchRoutes()
|
|
138
|
-
const currentRoute = last(matchRoutes)
|
|
139
|
-
const updateRoute = useRouter(state => state.updateRoute)
|
|
140
|
-
const navigate = useRouter(state => state.navigate)
|
|
141
|
-
const routesById = useRouter(state => state.routesById)
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
forEach(routesById, route => {
|
|
145
|
-
updateRoute(route.id, route => {
|
|
146
|
-
route.unauthorized = !config.validator(route)
|
|
147
|
-
})
|
|
148
|
-
})
|
|
149
|
-
}, deps)
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
const result = config.validator(currentRoute)
|
|
153
|
-
if (!result && config.redirectRouteId) {
|
|
154
|
-
navigate({ id: config.redirectRouteId }, { replace: true })
|
|
155
|
-
}
|
|
156
|
-
}, [currentRoute?.id, ...deps])
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return { useRouter, useQuery, useMatchRoutes, useRoutePermission }
|
|
160
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { default as useLoadingAction } from './useLoadingAction'
|
|
2
|
-
export { default as useInterval } from './useInterval'
|
|
3
|
-
export { default as useVisible } from './useVisible'
|
|
4
|
-
export { default as useLowPriorityState } from './useLowPriorityState'
|
|
5
|
-
export * from './useSyncState'
|
|
6
|
-
export * from './defineRouter'
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { useInterval as useRUInterval } from 'react-use'
|
|
3
|
-
|
|
4
|
-
interface actionsType {
|
|
5
|
-
start: () => void
|
|
6
|
-
stop: () => void
|
|
7
|
-
}
|
|
8
|
-
export default function useInterval(
|
|
9
|
-
cb: (actions: actionsType) => Promise<void> | void,
|
|
10
|
-
delay: number
|
|
11
|
-
): actionsType {
|
|
12
|
-
const [startInterval, setStartInterval] = useState(false)
|
|
13
|
-
const start: actionsType['start'] = () => {
|
|
14
|
-
setStartInterval(true)
|
|
15
|
-
}
|
|
16
|
-
const stop: actionsType['stop'] = () => {
|
|
17
|
-
setStartInterval(false)
|
|
18
|
-
}
|
|
19
|
-
useRUInterval(
|
|
20
|
-
async () => {
|
|
21
|
-
cb({ start, stop })
|
|
22
|
-
},
|
|
23
|
-
startInterval ? delay : null
|
|
24
|
-
)
|
|
25
|
-
return { start, stop }
|
|
26
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState, DependencyList, useRef } from 'react'
|
|
2
|
-
|
|
3
|
-
export default function useLoadingAction<C extends (...arg: any) => Promise<any> | any>(
|
|
4
|
-
callback: C,
|
|
5
|
-
deps: DependencyList,
|
|
6
|
-
debounce = true
|
|
7
|
-
) {
|
|
8
|
-
const [loading, setLoading] = useState(false)
|
|
9
|
-
const loadingSync = useRef(loading)
|
|
10
|
-
function $setLoading(loading: boolean) {
|
|
11
|
-
setLoading(loading)
|
|
12
|
-
loadingSync.current = loading
|
|
13
|
-
}
|
|
14
|
-
const action = useCallback(async (...arg: any) => {
|
|
15
|
-
if (debounce && loadingSync.current) {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
$setLoading(true)
|
|
20
|
-
return await callback(...arg)
|
|
21
|
-
} finally {
|
|
22
|
-
$setLoading(false)
|
|
23
|
-
}
|
|
24
|
-
}, deps) as C
|
|
25
|
-
|
|
26
|
-
return [loading, action] as const
|
|
27
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useTransition, DependencyList } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param callback
|
|
6
|
-
* @param watches If set, it is autorun callback
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export default function useLowPriorityState<V>(callback: () => V, watches?: DependencyList) {
|
|
10
|
-
const [value, setValue] = useState<V>(callback)
|
|
11
|
-
const [loading, startTransition] = useTransition()
|
|
12
|
-
|
|
13
|
-
function startLoad() {
|
|
14
|
-
startTransition(() => {
|
|
15
|
-
setValue(callback())
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (watches) {
|
|
21
|
-
startLoad()
|
|
22
|
-
}
|
|
23
|
-
}, watches)
|
|
24
|
-
|
|
25
|
-
return [value, { loading, startLoad }] as const
|
|
26
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useRef, useState, Dispatch, SetStateAction } from 'react'
|
|
2
|
-
import { isFunction } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export function useSyncState<S>(initialState: S | (() => S)) {
|
|
5
|
-
const [state, setState] = useState(initialState)
|
|
6
|
-
const syncState = useRef<S>(state)
|
|
7
|
-
|
|
8
|
-
const $setState: Dispatch<SetStateAction<S>> = newState => {
|
|
9
|
-
const $newState = isFunction(newState) ? newState(state) : newState
|
|
10
|
-
setState($newState)
|
|
11
|
-
syncState.current = $newState
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return [syncState, state, $setState] as const
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './theme.styled'
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
|
|
3
|
-
import { isString } from 'lodash-es'
|
|
4
|
-
|
|
5
|
-
export const theme = {
|
|
6
|
-
tools: {
|
|
7
|
-
ellipsis: () => ({
|
|
8
|
-
overflow: 'hidden',
|
|
9
|
-
textOverflow: 'ellipsis',
|
|
10
|
-
whiteSpace: 'nowrap'
|
|
11
|
-
}),
|
|
12
|
-
lineClamp: (n: number) => ({
|
|
13
|
-
'-webkit-line-clamp': `${n}`,
|
|
14
|
-
'-webkit-box-orient': 'vertical',
|
|
15
|
-
overflow: 'hidden',
|
|
16
|
-
display: '-webkit-box'
|
|
17
|
-
}),
|
|
18
|
-
size: (s: string) => ({ width: s, height: s }),
|
|
19
|
-
py: (s: string) => ({ paddingTop: s, paddingBottom: s }),
|
|
20
|
-
px: (s: string) => ({ paddingLeft: s, paddingRight: s }),
|
|
21
|
-
my: (s: string) => ({ marginTop: s, marginBottom: s }),
|
|
22
|
-
mx: (s: string) => ({ marginLeft: s, marginRight: s }),
|
|
23
|
-
flex: (
|
|
24
|
-
align: CSSProperties['alignItems'],
|
|
25
|
-
justify: CSSProperties['justifyContent'],
|
|
26
|
-
vertical?: boolean
|
|
27
|
-
) => {
|
|
28
|
-
return {
|
|
29
|
-
display: 'flex',
|
|
30
|
-
alignItems: align,
|
|
31
|
-
justifyContent: justify,
|
|
32
|
-
flexDirection: vertical ? 'column' : 'row'
|
|
33
|
-
} satisfies CSSProperties
|
|
34
|
-
},
|
|
35
|
-
/** 数字为元素数量,字符串为对应css的值 */
|
|
36
|
-
grid: {
|
|
37
|
-
grid: (rows: number | string, cols: number | string, gap?: number) => ({
|
|
38
|
-
display: 'grid',
|
|
39
|
-
gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
|
|
40
|
-
gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
|
|
41
|
-
gap: gap ? `${gap}px` : void 0
|
|
42
|
-
}),
|
|
43
|
-
rows: (rows: number | string, gap?: number) => ({
|
|
44
|
-
display: 'grid',
|
|
45
|
-
gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
|
|
46
|
-
rowGap: gap ? `${gap}px` : void 0
|
|
47
|
-
}),
|
|
48
|
-
cols: (cols: number | string, gap?: number) => ({
|
|
49
|
-
display: 'grid',
|
|
50
|
-
gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
|
|
51
|
-
columnGap: gap ? `${gap}px` : void 0
|
|
52
|
-
})
|
|
53
|
-
} satisfies Record<string, (...args: any) => CSSProperties>
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export type themeType = typeof theme
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './utils'
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import webpack from 'webpack'
|
|
3
|
-
import WebpackBar from 'webpackbar'
|
|
4
|
-
import { EsbuildPlugin } from 'esbuild-loader'
|
|
5
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
6
|
-
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
7
|
-
import EslintWebpackPlugin from 'eslint-webpack-plugin'
|
|
8
|
-
import StylelintWebpackPlugin from 'stylelint-webpack-plugin'
|
|
9
|
-
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
|
|
10
|
-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
11
|
-
import * as dotenv from 'dotenv'
|
|
12
|
-
import { ROOT, OUTPUT, createCssLoader, createStyleLoader } from './webpack_config/index.mjs'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {String} mode
|
|
17
|
-
* @param {boolean} isProd
|
|
18
|
-
* @returns {object}
|
|
19
|
-
*/
|
|
20
|
-
function getEnvConfig(mode, isProd) {
|
|
21
|
-
const envConfig = dotenv.config({
|
|
22
|
-
path: isProd ? '.env' : `.env.${mode}`
|
|
23
|
-
}).parsed
|
|
24
|
-
Object.keys(envConfig).forEach(k => {
|
|
25
|
-
envConfig[k] = JSON.stringify(envConfig[k])
|
|
26
|
-
})
|
|
27
|
-
return envConfig
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default function (env) {
|
|
31
|
-
const isProd = ['prod', 'analyse'].includes(env.mode)
|
|
32
|
-
const envConfig = getEnvConfig(env.mode, isProd)
|
|
33
|
-
const publicPath = JSON.parse(envConfig.ENV_BASE_URL)
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
entry: {
|
|
37
|
-
index: [path.join(ROOT, 'main.tsx')]
|
|
38
|
-
},
|
|
39
|
-
output: {
|
|
40
|
-
filename: isProd ? 'js/[name].[chunkhash].js' : 'js/[name].js',
|
|
41
|
-
chunkFilename: isProd ? 'js/[name].[chunkhash].js' : 'js/[name].js',
|
|
42
|
-
path: OUTPUT,
|
|
43
|
-
publicPath,
|
|
44
|
-
clean: true
|
|
45
|
-
},
|
|
46
|
-
mode: isProd ? 'production' : 'development',
|
|
47
|
-
stats: isProd ? 'normal' : 'errors-only',
|
|
48
|
-
performance: {
|
|
49
|
-
hints: false
|
|
50
|
-
},
|
|
51
|
-
devServer: {
|
|
52
|
-
host: '0.0.0.0',
|
|
53
|
-
hot: true,
|
|
54
|
-
open: publicPath,
|
|
55
|
-
static: {
|
|
56
|
-
publicPath
|
|
57
|
-
},
|
|
58
|
-
historyApiFallback: {
|
|
59
|
-
disableDotRule: true,
|
|
60
|
-
index: publicPath
|
|
61
|
-
},
|
|
62
|
-
devMiddleware: {
|
|
63
|
-
publicPath
|
|
64
|
-
},
|
|
65
|
-
proxy: [
|
|
66
|
-
{
|
|
67
|
-
'/api': {
|
|
68
|
-
target: 'http://127.0.0.1:3000',
|
|
69
|
-
changeOrigin: true,
|
|
70
|
-
secure: false,
|
|
71
|
-
pathRewrite: {
|
|
72
|
-
'^/api': ''
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
},
|
|
78
|
-
module: {
|
|
79
|
-
rules: [
|
|
80
|
-
{
|
|
81
|
-
test: /\.[jt]sx?$/,
|
|
82
|
-
loader: 'esbuild-loader',
|
|
83
|
-
options: {
|
|
84
|
-
target: 'chrome82',
|
|
85
|
-
drop: isProd ? ['console', 'debugger'] : []
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
test: /\.(png|jpg|jpeg|gif)$/i,
|
|
90
|
-
type: 'asset/resource'
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
test: /\.svg$/i,
|
|
94
|
-
type: 'asset/resource',
|
|
95
|
-
resourceQuery: /url/ // *.svg?url
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
test: /\.svg$/i,
|
|
99
|
-
issuer: /\.[jt]sx?$/,
|
|
100
|
-
resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url
|
|
101
|
-
use: ['@svgr/webpack']
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
105
|
-
type: 'asset/resource'
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
test: /\.css$/,
|
|
109
|
-
exclude: /\.module\.css$/,
|
|
110
|
-
use: [createStyleLoader(isProd), createCssLoader(), 'postcss-loader']
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
test: /\.module\.css$/,
|
|
114
|
-
use: [createStyleLoader(isProd), createCssLoader(true), 'postcss-loader']
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
},
|
|
118
|
-
plugins: [
|
|
119
|
-
new WebpackBar(),
|
|
120
|
-
new HtmlWebpackPlugin({
|
|
121
|
-
filename: 'index.html',
|
|
122
|
-
template: path.resolve(ROOT, 'index.html')
|
|
123
|
-
}),
|
|
124
|
-
new EslintWebpackPlugin(),
|
|
125
|
-
new StylelintWebpackPlugin(),
|
|
126
|
-
new ForkTsCheckerWebpackPlugin(),
|
|
127
|
-
new webpack.DefinePlugin(envConfig),
|
|
128
|
-
new MiniCssExtractPlugin({
|
|
129
|
-
filename: isProd ? 'css/[name].[contenthash].css' : 'css/[name].css',
|
|
130
|
-
chunkFilename: isProd ? 'css/[name].[contenthash].css' : 'css/[name].css'
|
|
131
|
-
}),
|
|
132
|
-
env.mode === 'analyzer' && new BundleAnalyzerPlugin()
|
|
133
|
-
],
|
|
134
|
-
optimization: {
|
|
135
|
-
minimizer: [new EsbuildPlugin()],
|
|
136
|
-
splitChunks: {
|
|
137
|
-
minChunks: 1,
|
|
138
|
-
cacheGroups: {
|
|
139
|
-
react: {
|
|
140
|
-
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
|
|
141
|
-
chunks: 'all',
|
|
142
|
-
name: 'react'
|
|
143
|
-
},
|
|
144
|
-
vendors: {
|
|
145
|
-
test: /[\\/]node_modules[\\/]/,
|
|
146
|
-
chunks: 'all',
|
|
147
|
-
name: 'vendors',
|
|
148
|
-
priority: -1
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
resolve: {
|
|
154
|
-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
|
|
155
|
-
alias: {
|
|
156
|
-
'@': ROOT
|
|
157
|
-
},
|
|
158
|
-
modules: ['node_modules']
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
2
|
-
import { SCOPE_CLASS_NAME } from './constant.mjs'
|
|
3
|
-
|
|
4
|
-
export function createStyleLoader(build) {
|
|
5
|
-
return build ? MiniCssExtractPlugin.loader : 'style-loader'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createCssLoader(module) {
|
|
9
|
-
if (module) {
|
|
10
|
-
return {
|
|
11
|
-
loader: 'css-loader',
|
|
12
|
-
options: {
|
|
13
|
-
importLoaders: 1,
|
|
14
|
-
modules: {
|
|
15
|
-
mode: 'local',
|
|
16
|
-
localIdentName: SCOPE_CLASS_NAME
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return 'css-loader'
|
|
22
|
-
}
|
|
File without changes
|