create-packer 1.28.0 → 1.30.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/next/package.json +0 -1
- package/template/web-app/next/postcss.config.js +0 -1
- package/template/web-app/react/.eslintrc +35 -8
- package/template/web-app/react/domain/app/components/app.tsx +4 -1
- package/template/web-app/react/package.json +5 -5
- package/template/web-app/react/pages/home/home.tsx +8 -2
- package/template/web-app/react/postcss.config.cjs +0 -2
- package/template/web-app/react/shared/hooks/defineRouter/defineRouter.types.ts +3 -0
- package/template/web-app/react/shared/hooks/defineRouter/deineRouter.tsx +160 -160
- package/template/web-app/react/shared/theme/index.ts +2 -0
- package/template/web-app/react/shared/theme/theme.components.tsx +7 -0
- package/template/web-app/react/shared/theme/theme.d.ts +8 -0
- package/template/web-app/react/shared/theme/theme.styles.ts +7 -0
- package/template/web-app/react/tsconfig.json +22 -6
- package/template/web-app/react-webpack/domain/app/components/app.tsx +4 -1
- package/template/web-app/react-webpack/package.json +6 -6
- package/template/web-app/react-webpack/pages/home/home.tsx +8 -3
- package/template/web-app/react-webpack/postcss.config.js +0 -2
- package/template/web-app/react-webpack/shared/hooks/defineRouter/defineRouter.types.ts +3 -0
- package/template/web-app/react-webpack/shared/hooks/defineRouter/deineRouter.tsx +160 -160
- package/template/web-app/react-webpack/shared/theme/index.ts +2 -0
- package/template/web-app/react-webpack/shared/theme/theme.components.tsx +7 -0
- package/template/web-app/react-webpack/shared/theme/theme.d.ts +8 -0
- package/template/web-app/react-webpack/shared/theme/theme.styles.ts +7 -0
- package/template/web-extension/content_script/content.tsx +0 -2
- package/template/web-extension/content_script/index.tsx +4 -1
- package/template/web-extension/domain/app/components/app-context.tsx +6 -0
- package/template/web-extension/domain/app/components/index.ts +1 -0
- package/template/web-extension/domain/app/index.ts +1 -0
- package/template/web-extension/package.json +7 -7
- package/template/web-extension/popup/index.tsx +4 -1
- package/template/web-extension/popup/popup.container.tsx +0 -2
- package/template/web-extension/postcss.config.cjs +0 -2
- package/template/web-extension/shared/service/tools/base.ts +15 -5
- package/template/web-extension/shared/service/tools/createRequestActions.ts +4 -4
- package/template/web-extension/shared/service/tools/createService.ts +10 -5
- package/template/web-extension/shared/service/tools/hooks.ts +73 -67
- package/template/web-extension/shared/service/types.ts +0 -4
- package/template/web-extension/shared/theme/index.ts +2 -0
- package/template/web-extension/shared/theme/theme.components.tsx +7 -0
- package/template/web-extension/shared/theme/theme.d.ts +8 -0
- package/template/web-extension/shared/theme/theme.styles.ts +7 -0
- package/template/web-app/next/tailwind.config.js +0 -20
- package/template/web-app/react/pages/home/home.css +0 -1
- package/template/web-app/react/tailwind.config.cjs +0 -17
- package/template/web-app/react-webpack/pages/home/home.module.css +0 -3
- package/template/web-app/react-webpack/tailwind.config.js +0 -17
- package/template/web-extension/content_script/content.css +0 -3
- package/template/web-extension/popup/popup.css +0 -3
- package/template/web-extension/tailwind.config.cjs +0 -13
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"root": true,
|
|
3
3
|
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"plugins": [
|
|
4
|
+
"plugins": [
|
|
5
|
+
"prettier"
|
|
6
|
+
],
|
|
5
7
|
"extends": [
|
|
6
8
|
"eslint:recommended",
|
|
7
9
|
"plugin:@typescript-eslint/recommended",
|
|
@@ -51,12 +53,32 @@
|
|
|
51
53
|
"type"
|
|
52
54
|
],
|
|
53
55
|
"pathGroups": [
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
{
|
|
57
|
+
"pattern": "react",
|
|
58
|
+
"group": "external",
|
|
59
|
+
"position": "before"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"pattern": "react-dom/*",
|
|
63
|
+
"group": "external",
|
|
64
|
+
"position": "before"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"pattern": "react-router",
|
|
68
|
+
"group": "external",
|
|
69
|
+
"position": "before"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"pattern": "react-router-dom",
|
|
73
|
+
"group": "external",
|
|
74
|
+
"position": "before"
|
|
75
|
+
}
|
|
58
76
|
],
|
|
59
|
-
"pathGroupsExcludedImportTypes": [
|
|
77
|
+
"pathGroupsExcludedImportTypes": [
|
|
78
|
+
"react",
|
|
79
|
+
"react-router",
|
|
80
|
+
"react-router-dom"
|
|
81
|
+
]
|
|
60
82
|
}
|
|
61
83
|
],
|
|
62
84
|
"no-case-declarations": "off",
|
|
@@ -70,7 +92,12 @@
|
|
|
70
92
|
"ignoreParameters": true
|
|
71
93
|
}
|
|
72
94
|
],
|
|
73
|
-
"@typescript-eslint/no-unused-vars": [
|
|
95
|
+
"@typescript-eslint/no-unused-vars": [
|
|
96
|
+
"warn",
|
|
97
|
+
{
|
|
98
|
+
"argsIgnorePattern": "^_"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
74
101
|
"@typescript-eslint/member-delimiter-style": 0,
|
|
75
102
|
"@typescript-eslint/class-name-casing": 0,
|
|
76
103
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
@@ -89,4 +116,4 @@
|
|
|
89
116
|
],
|
|
90
117
|
"no-constant-condition": "off"
|
|
91
118
|
}
|
|
92
|
-
}
|
|
119
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StrictMode, useLayoutEffect } from 'react'
|
|
2
2
|
import { RouterProvider } from 'react-router-dom'
|
|
3
|
+
import { ThemeProvider } from '@/shared/theme'
|
|
3
4
|
import { request } from '@/shared/service'
|
|
4
5
|
import { routerInstance } from '@/domain/router'
|
|
5
6
|
|
|
@@ -15,7 +16,9 @@ const App = () => {
|
|
|
15
16
|
|
|
16
17
|
return (
|
|
17
18
|
<StrictMode>
|
|
18
|
-
<
|
|
19
|
+
<ThemeProvider>
|
|
20
|
+
<RouterProvider router={routerInstance} />
|
|
21
|
+
</ThemeProvider>
|
|
19
22
|
</StrictMode>
|
|
20
23
|
)
|
|
21
24
|
}
|
|
@@ -18,16 +18,17 @@
|
|
|
18
18
|
"commit": "git add . && npm run cz"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"1k-types": "1.
|
|
21
|
+
"1k-types": "1.2.0",
|
|
22
22
|
"axios": "1.3.6",
|
|
23
|
-
"define-zustand": "3.1.
|
|
23
|
+
"define-zustand": "3.1.1",
|
|
24
24
|
"immer": "10.0.1",
|
|
25
25
|
"lodash-es": "4.17.21",
|
|
26
26
|
"qs": "6.11.2",
|
|
27
|
-
"react": "18.
|
|
28
|
-
"react-dom": "18.
|
|
27
|
+
"react": "18.3.1",
|
|
28
|
+
"react-dom": "18.3.1",
|
|
29
29
|
"react-router-dom": "6.14.0",
|
|
30
30
|
"react-use": "17.5.0",
|
|
31
|
+
"styled-components": "6.1.11",
|
|
31
32
|
"zustand": "4.4.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
@@ -63,7 +64,6 @@
|
|
|
63
64
|
"rollup-plugin-visualizer": "5.9.2",
|
|
64
65
|
"stylelint": "16.2.1",
|
|
65
66
|
"stylelint-config-standard-scss": "13.0.0",
|
|
66
|
-
"tailwindcss": "3.3.1",
|
|
67
67
|
"typescript": "5.3.3",
|
|
68
68
|
"vite": "4.5.2",
|
|
69
69
|
"vite-plugin-mock-dev-server": "1.4.7",
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import './home.css'
|
|
2
1
|
import { useEffect } from 'react'
|
|
2
|
+
import { styled } from 'styled-components'
|
|
3
3
|
import { request, API } from '@/shared/service'
|
|
4
4
|
|
|
5
|
+
const Wrapper = styled.div`
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
align-items: center;
|
|
9
|
+
`
|
|
10
|
+
|
|
5
11
|
export default function Home() {
|
|
6
12
|
useEffect(() => {
|
|
7
13
|
request.post(API.HOME_DATA).then(({ data }) => {
|
|
@@ -9,5 +15,5 @@ export default function Home() {
|
|
|
9
15
|
})
|
|
10
16
|
}, [])
|
|
11
17
|
|
|
12
|
-
return <
|
|
18
|
+
return <Wrapper className={'flex justify-center items-center'}>sdfs</Wrapper>
|
|
13
19
|
}
|
|
@@ -1,160 +1,160 @@
|
|
|
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
|
+
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FunctionComponent, ReactNode } from 'react'
|
|
2
|
+
import { ThemeProvider as ThemeProviderComponent } from 'styled-components'
|
|
3
|
+
import { theme } from './theme.styles'
|
|
4
|
+
|
|
5
|
+
export const ThemeProvider: FunctionComponent<{ children: ReactNode }> = props => {
|
|
6
|
+
return <ThemeProviderComponent theme={theme}>{props.children}</ThemeProviderComponent>
|
|
7
|
+
}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"baseUrl": ".",
|
|
4
4
|
"target": "ESNext",
|
|
5
5
|
"useDefineForClassFields": true,
|
|
6
|
-
"lib": [
|
|
6
|
+
"lib": [
|
|
7
|
+
"DOM",
|
|
8
|
+
"DOM.Iterable",
|
|
9
|
+
"ESNext"
|
|
10
|
+
],
|
|
7
11
|
"allowJs": false,
|
|
8
12
|
"skipLibCheck": true,
|
|
9
13
|
"esModuleInterop": false,
|
|
@@ -19,10 +23,22 @@
|
|
|
19
23
|
"noEmit": true,
|
|
20
24
|
"jsx": "react-jsx",
|
|
21
25
|
"paths": {
|
|
22
|
-
"@/*": [
|
|
26
|
+
"@/*": [
|
|
27
|
+
"./*"
|
|
28
|
+
]
|
|
23
29
|
}
|
|
24
30
|
},
|
|
25
|
-
"include": [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
"include": [
|
|
32
|
+
"**/*.ts",
|
|
33
|
+
"**/*.tsx"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"scripts",
|
|
37
|
+
"vite.config.ts"
|
|
38
|
+
],
|
|
39
|
+
"references": [
|
|
40
|
+
{
|
|
41
|
+
"path": "./tsconfig.node.json"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StrictMode, useLayoutEffect } from 'react'
|
|
2
2
|
import { RouterProvider } from 'react-router-dom'
|
|
3
|
+
import { ThemeProvider } from '@/shared/theme'
|
|
3
4
|
import { request } from '@/shared/service'
|
|
4
5
|
import { routerInstance } from '@/domain/router'
|
|
5
6
|
|
|
@@ -15,7 +16,9 @@ const App = () => {
|
|
|
15
16
|
|
|
16
17
|
return (
|
|
17
18
|
<StrictMode>
|
|
18
|
-
<
|
|
19
|
+
<ThemeProvider>
|
|
20
|
+
<RouterProvider router={routerInstance} />
|
|
21
|
+
</ThemeProvider>
|
|
19
22
|
</StrictMode>
|
|
20
23
|
)
|
|
21
24
|
}
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"commit": "git add . && npm run cz"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"1k-types": "1.
|
|
22
|
+
"1k-types": "1.2.0",
|
|
23
23
|
"axios": "1.6.7",
|
|
24
|
-
"define-zustand": "3.1.
|
|
24
|
+
"define-zustand": "3.1.1",
|
|
25
25
|
"immer": "10.0.3",
|
|
26
26
|
"lodash-es": "4.17.21",
|
|
27
27
|
"qs": "6.11.2",
|
|
28
|
-
"react": "18.
|
|
29
|
-
"react-dom": "18.
|
|
28
|
+
"react": "18.3.1",
|
|
29
|
+
"react-dom": "18.3.1",
|
|
30
30
|
"react-router-dom": "6.14.0",
|
|
31
31
|
"react-use": "17.5.0",
|
|
32
|
-
"
|
|
33
|
-
"zustand": "4.
|
|
32
|
+
"styled-components": "6.1.11",
|
|
33
|
+
"zustand": "4.4.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@commitlint/cli": "18.6.1",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { styled } from 'styled-components'
|
|
2
|
+
|
|
3
|
+
const Wrapper = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
align-items: center;
|
|
7
|
+
`
|
|
2
8
|
|
|
3
9
|
export default function Home() {
|
|
4
|
-
|
|
5
|
-
return <div className={styles.root}>sdsddds</div>
|
|
10
|
+
return <Wrapper>sdfs</Wrapper>
|
|
6
11
|
}
|