create-packer 1.17.15 → 1.17.17
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/react/package.json +6 -4
- package/template/react/src/app.model.ts +2 -2
- package/template/react/src/providers/index.ts +1 -1
- package/template/react/src/providers/modelUtils.ts +52 -0
- package/template/react/src/router/home/index.ts +1 -1
- package/template/react/src/router/home/names.ts +3 -0
- package/template/react/src/router/home/routes.tsx +4 -2
- package/template/react/src/router/index.ts +3 -2
- package/template/react/src/router/{paths.ts → names.ts} +2 -2
- package/template/react/src/router/router.provider.ts +22 -0
- package/template/react/src/router/router.tsx +25 -4
- package/template/react/src/router/router.types.ts +6 -0
- package/template/react/src/types/index.ts +1 -0
- package/template/react/src/types/utils.ts +19 -0
- package/template/react/src/providers/defineModel.ts +0 -42
- package/template/react/src/router/home/paths.ts +0 -1
package/package.json
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"axios": "1.3.6",
|
|
24
24
|
"immer": "10.0.1",
|
|
25
25
|
"lodash-es": "4.17.21",
|
|
26
|
+
"qs": "6.11.2",
|
|
26
27
|
"react": "18.2.0",
|
|
27
28
|
"react-dom": "18.2.0",
|
|
28
29
|
"react-router-dom": "6.10.0",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@commitlint/cli": "17.6.1",
|
|
33
|
-
"@commitlint/config-conventional": "
|
|
34
|
+
"@commitlint/config-conventional": "17.6.1",
|
|
34
35
|
"@commitlint/cz-commitlint": "17.5.0",
|
|
35
36
|
"@testing-library/dom": "9.2.0",
|
|
36
37
|
"@testing-library/jest-dom": "5.16.5",
|
|
@@ -38,7 +39,8 @@
|
|
|
38
39
|
"@testing-library/user-event": "14.4.3",
|
|
39
40
|
"@types/jest": "29.5.1",
|
|
40
41
|
"@types/lodash-es": "4.17.7",
|
|
41
|
-
"@types/node": "
|
|
42
|
+
"@types/node": "18.16.0",
|
|
43
|
+
"@types/qs": "6.9.7",
|
|
42
44
|
"@types/react": "18.0.38",
|
|
43
45
|
"@types/react-dom": "18.0.11",
|
|
44
46
|
"@types/testing-library__jest-dom": "5.14.5",
|
|
@@ -49,8 +51,8 @@
|
|
|
49
51
|
"commitizen": "4.3.0",
|
|
50
52
|
"cssnano": "6.0.0",
|
|
51
53
|
"eslint": "8.39.0",
|
|
52
|
-
"eslint-import-resolver-typescript": "
|
|
53
|
-
"eslint-plugin-import": "
|
|
54
|
+
"eslint-import-resolver-typescript": "3.5.5",
|
|
55
|
+
"eslint-plugin-import": "2.27.5",
|
|
54
56
|
"eslint-plugin-prettier": "4.2.1",
|
|
55
57
|
"eslint-plugin-react": "7.32.2",
|
|
56
58
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { create, StoreApi, UseBoundStore } from 'zustand'
|
|
2
|
+
import { combine } from 'zustand/middleware'
|
|
3
|
+
import { produce } from 'immer'
|
|
4
|
+
import { ExtractModelType } from '@/types'
|
|
5
|
+
|
|
6
|
+
export interface insideActionsType<S> {
|
|
7
|
+
reset: () => void
|
|
8
|
+
setState: (updater: (state: S) => void) => void
|
|
9
|
+
}
|
|
10
|
+
export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
11
|
+
getState: () => S,
|
|
12
|
+
actions: insideActionsType<S> & InsideActions,
|
|
13
|
+
store: StoreApi<S>
|
|
14
|
+
) => OptionAction
|
|
15
|
+
export interface optionsType<S, OptionAction> {
|
|
16
|
+
state: () => S
|
|
17
|
+
actions: actionsType<S, OptionAction>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function define<S extends Record<string, any>, OptionActions extends Record<string, any>>(
|
|
21
|
+
options: optionsType<S, OptionActions>
|
|
22
|
+
) {
|
|
23
|
+
return create(
|
|
24
|
+
combine(options.state(), (set, get, store) => {
|
|
25
|
+
const setState: insideActionsType<S>['setState'] = updater => {
|
|
26
|
+
set(
|
|
27
|
+
produce((store: S) => {
|
|
28
|
+
updater(store)
|
|
29
|
+
}) as any
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
const reset: insideActionsType<S>['reset'] = () => {
|
|
33
|
+
set(() => options.state() as never)
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...options.state(),
|
|
37
|
+
reset,
|
|
38
|
+
setState,
|
|
39
|
+
subscribe: store.subscribe,
|
|
40
|
+
...options.actions(get, { reset, setState }, store)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function defineComputed<
|
|
47
|
+
Model extends UseBoundStore<StoreApi<any>>,
|
|
48
|
+
K extends string,
|
|
49
|
+
R = any
|
|
50
|
+
>(useStore: Model, computed: Record<K, (state: ExtractModelType<Model>) => R>) {
|
|
51
|
+
return (field: K) => useStore(computed[field])
|
|
52
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as routes } from './routes'
|
|
2
|
-
export { default as
|
|
2
|
+
export { default as names } from './names'
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { lazy } from 'react'
|
|
2
|
-
import
|
|
2
|
+
import names from './names'
|
|
3
|
+
import type { routeType } from '../router.types'
|
|
3
4
|
|
|
4
|
-
const routes:
|
|
5
|
+
const routes: routeType[] = [
|
|
5
6
|
{
|
|
6
7
|
index: true,
|
|
8
|
+
name: names.home,
|
|
7
9
|
Component: lazy(() => import('@/pages/home'))
|
|
8
10
|
}
|
|
9
11
|
]
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export
|
|
1
|
+
export { default as routeNames } from './names'
|
|
2
|
+
export * from './router'
|
|
3
|
+
export * from './router.provider'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { find, get } from 'lodash-es'
|
|
2
|
+
import { stringify } from 'qs'
|
|
3
|
+
import { NavigateOptions, redirect as routerRedirect } from 'react-router-dom'
|
|
4
|
+
import { router, routesList } from './router'
|
|
5
|
+
|
|
6
|
+
export function getRoute(name: string, path?: string | string[]) {
|
|
7
|
+
const route = find(routesList, o => o.name === name)
|
|
8
|
+
if (path) {
|
|
9
|
+
return get(route, path)
|
|
10
|
+
}
|
|
11
|
+
return route
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function navigate(
|
|
15
|
+
to: { name: string; query?: Record<string, any> },
|
|
16
|
+
opts?: NavigateOptions
|
|
17
|
+
) {
|
|
18
|
+
return router.navigate(
|
|
19
|
+
{ pathname: getRoute(to.name, 'path'), search: to.query ? stringify(to.query) : '' },
|
|
20
|
+
opts
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
import { lazy } from 'react'
|
|
2
|
+
import { concat, isArray, reduce } from 'lodash-es'
|
|
2
3
|
import { createBrowserRouter } from 'react-router-dom'
|
|
3
4
|
import * as home from './home'
|
|
4
|
-
import
|
|
5
|
+
import names from './names'
|
|
6
|
+
import type { routeType } from './router.types'
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const routes: routeType[] = [
|
|
7
9
|
{
|
|
8
|
-
path:
|
|
10
|
+
path: '/',
|
|
11
|
+
name: names.root,
|
|
9
12
|
Component: lazy(() => import('@/layout')),
|
|
10
13
|
children: [...home.routes]
|
|
11
14
|
},
|
|
12
15
|
{
|
|
13
16
|
path: '*',
|
|
17
|
+
name: '404',
|
|
14
18
|
Component: lazy(() => import('@/pages/notFound'))
|
|
15
19
|
}
|
|
16
|
-
]
|
|
20
|
+
]
|
|
21
|
+
export const routesList = (function flat(routes: routeType[], parentRoute?: routeType) {
|
|
22
|
+
return reduce(
|
|
23
|
+
routes,
|
|
24
|
+
(result, route) => {
|
|
25
|
+
route.path = parentRoute
|
|
26
|
+
? `${parentRoute.path === '/' ? '' : parentRoute.path}/${route.path}`
|
|
27
|
+
: route.path
|
|
28
|
+
result.push(route)
|
|
29
|
+
if (isArray(route.children)) {
|
|
30
|
+
result = concat(result, flat(route.children, route))
|
|
31
|
+
}
|
|
32
|
+
return result
|
|
33
|
+
},
|
|
34
|
+
[] as routeType[]
|
|
35
|
+
)
|
|
36
|
+
})(routes)
|
|
37
|
+
export const router = createBrowserRouter(routes as never)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UseBoundStore, StoreApi } from 'zustand'
|
|
2
|
+
export type ExtractArrayElType<T> = T extends Array<infer E> ? E : unknown
|
|
3
|
+
export type ExtractReadonlyArrayElType<T> = T extends ReadonlyArray<infer E> ? E : unknown
|
|
4
|
+
export type ExtractReadonlyArrayFieldType<T, K extends keyof any> = T extends ReadonlyArray<infer V>
|
|
5
|
+
? V extends { [key in K]: infer V2 }
|
|
6
|
+
? V2
|
|
7
|
+
: any
|
|
8
|
+
: any
|
|
9
|
+
export type ExtractArrayFieldType<T, K extends keyof any> = T extends Array<infer V>
|
|
10
|
+
? V extends { [key in K]: infer V2 }
|
|
11
|
+
? V2
|
|
12
|
+
: any
|
|
13
|
+
: any
|
|
14
|
+
|
|
15
|
+
export type UnReadonly<R extends Record<string, any>> = {
|
|
16
|
+
-readonly [K in keyof R]: R[K]
|
|
17
|
+
}
|
|
18
|
+
export type ValueType<R extends Record<string, any>> = R extends Record<string, infer V> ? V : R
|
|
19
|
+
export type ExtractModelType<T> = T extends UseBoundStore<StoreApi<infer S>> ? S : unknown
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { create } from 'zustand'
|
|
2
|
-
import { produce } from 'immer'
|
|
3
|
-
|
|
4
|
-
export type setStateType<S> = (updater: (state: S) => void) => void
|
|
5
|
-
export interface modelActionsType<S extends Record<string, any>> {
|
|
6
|
-
reset: () => void
|
|
7
|
-
setState: setStateType<S>
|
|
8
|
-
}
|
|
9
|
-
export interface modelOptionsType<S extends Record<string, any>, A extends Record<string, any>> {
|
|
10
|
-
state: () => S
|
|
11
|
-
actions: (getState: () => S, actions: modelActionsType<S>) => A
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function defineModel<S extends Record<string, any>, A extends Record<string, any>>(
|
|
15
|
-
options: modelOptionsType<S, A>
|
|
16
|
-
) {
|
|
17
|
-
return create<{ state: S; actions: modelActionsType<S> & A }>()((setState, getState, store) => {
|
|
18
|
-
const _setState: modelActionsType<S>['setState'] = updater => {
|
|
19
|
-
setState(
|
|
20
|
-
produce((store: { state: S }) => {
|
|
21
|
-
updater(store.state)
|
|
22
|
-
}) as any
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
const _getState = () => getState().state
|
|
26
|
-
const reset: modelActionsType<S>['reset'] = () => {
|
|
27
|
-
setState({ state: options.state() })
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
state: options.state(),
|
|
31
|
-
actions: {
|
|
32
|
-
reset,
|
|
33
|
-
setState: _setState,
|
|
34
|
-
subscribe: store.subscribe,
|
|
35
|
-
...options.actions(_getState, {
|
|
36
|
-
reset,
|
|
37
|
-
setState: _setState
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {}
|