create-packer 1.35.14 → 1.35.16
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 +2 -1
- package/template/cli/biome.json +37 -0
- package/template/cli/package.json +1 -0
- package/template/lib/workspace/.eslintrc +1 -7
- package/template/lib/workspace/biome.json +37 -0
- package/template/lib/workspace/package.json +1 -2
- package/template/lib/workspace/packages/react/.eslintrc +1 -7
- package/template/lib/workspace/packages/react/package.json +0 -2
- package/template/lib/workspace/packages/ts/.eslintrc +1 -7
- package/template/lib/workspace/packages/ts/package.json +0 -1
- package/template/web-app/react-rspack/.eslintrc +1 -10
- package/template/web-app/react-rspack/.vscode/extensions.json +2 -2
- package/template/web-app/react-rspack/biome.json +37 -0
- package/template/web-app/react-rspack/package.json +2 -3
- package/template/web-app/react-vite/.eslintrc +1 -10
- package/template/web-app/react-vite/.vscode/extensions.json +8 -8
- package/template/web-app/react-vite/.vscode/settings.json +4 -18
- package/template/web-app/react-vite/biome.json +37 -0
- package/template/web-app/react-vite/domain/app/app.model.ts +7 -7
- package/template/web-app/react-vite/domain/app/app.styled.ts +3 -3
- package/template/web-app/react-vite/domain/app/components/app-context.tsx +17 -17
- package/template/web-app/react-vite/domain/app/components/app.tsx +24 -24
- package/template/web-app/react-vite/domain/app/components/index.ts +1 -1
- package/template/web-app/react-vite/domain/app/index.ts +2 -2
- package/template/web-app/react-vite/domain/router/home/ids.ts +3 -3
- package/template/web-app/react-vite/domain/router/home/index.ts +2 -2
- package/template/web-app/react-vite/domain/router/home/routes.tsx +13 -13
- package/template/web-app/react-vite/domain/router/ids.ts +6 -6
- package/template/web-app/react-vite/domain/router/index.ts +3 -3
- package/template/web-app/react-vite/domain/router/router.tsx +28 -28
- package/template/web-app/react-vite/domain/router/router.types.ts +3 -3
- package/template/web-app/react-vite/main.tsx +4 -4
- package/template/web-app/react-vite/mockUtils.ts +6 -6
- package/template/web-app/react-vite/package.json +79 -80
- package/template/web-app/react-vite/pages/home/home.mock.ts +19 -19
- package/template/web-app/react-vite/pages/home/home.styled.ts +7 -7
- package/template/web-app/react-vite/pages/home/home.tsx +10 -10
- package/template/web-app/react-vite/pages/home/index.ts +1 -1
- package/template/web-app/react-vite/pages/index.tsx +18 -18
- package/template/web-app/react-vite/pages/not-found.tsx +3 -3
- package/template/web-app/react-vite/scripts/createChunks.ts +26 -26
- package/template/web-app/react-vite/scripts/index.ts +1 -1
- package/template/web-app/react-vite/shared/hooks/defineRouter/defineRouter.types.ts +33 -33
- package/template/web-app/react-vite/shared/hooks/defineRouter/index.ts +2 -2
- package/template/web-app/react-vite/shared/hooks/index.ts +6 -6
- package/template/web-app/react-vite/shared/hooks/useInterval.ts +26 -26
- package/template/web-app/react-vite/shared/hooks/useLoadingAction.ts +27 -27
- package/template/web-app/react-vite/shared/hooks/useLowPriorityState.ts +26 -26
- package/template/web-app/react-vite/shared/hooks/useSyncState.ts +15 -15
- package/template/web-app/react-vite/shared/hooks/useVisible.ts +27 -27
- package/template/web-app/react-vite/shared/service/api.ts +1 -1
- package/template/web-app/react-vite/shared/service/home.ts +10 -10
- package/template/web-app/react-vite/shared/service/index.ts +3 -3
- package/template/web-app/react-vite/shared/service/request.ts +5 -5
- package/template/web-app/react-vite/shared/theme/index.ts +1 -1
- package/template/web-app/react-vite/shared/theme/theme.styled.ts +56 -56
- package/template/web-app/react-vite/shared/tools/componentInstance.tsx +80 -80
- package/template/web-app/react-vite/shared/tools/index.ts +1 -1
- package/template/web-app/react-vite/shared/types/index.ts +1 -1
- package/template/web-app/react-vite/shared/types/utils.ts +2 -2
- package/template/web-app/react-vite/tsconfig.json +32 -44
- package/template/web-app/react-vite/tsconfig.node.json +10 -10
- package/template/web-app/react-vite/vite-env.d.ts +18 -18
- package/template/web-app/react-vite/vite.config.ts +76 -76
- package/template/web-app/react-webpack/.eslintrc +1 -10
- package/template/web-app/react-webpack/.vscode/extensions.json +2 -2
- package/template/web-app/react-webpack/biome.json +37 -0
- package/template/web-app/react-webpack/package.json +2 -3
- package/template/web-app/vue/.eslintrc +0 -7
- package/template/web-app/vue/.vscode/extensions.json +9 -9
- package/template/web-app/vue/biome.json +37 -0
- package/template/web-app/vue/domain/app/app.ts +4 -4
- package/template/web-app/vue/domain/app/components/index.ts +1 -1
- package/template/web-app/vue/domain/app/createComponentInstance.ts +44 -44
- package/template/web-app/vue/domain/app/index.ts +3 -3
- package/template/web-app/vue/main.ts +7 -7
- package/template/web-app/vue/mockUtils.ts +6 -6
- package/template/web-app/vue/package.json +2 -3
- package/template/web-app/vue/pages/home/home.mock.ts +19 -19
- package/template/web-app/vue/pages/home/index.ts +1 -1
- package/template/web-app/vue/pages/index.ts +1 -1
- package/template/web-app/vue/router/home/index.ts +2 -2
- package/template/web-app/vue/router/home/names.ts +3 -3
- package/template/web-app/vue/router/home/routes.ts +8 -8
- package/template/web-app/vue/router/index.ts +26 -26
- package/template/web-app/vue/router/names.ts +5 -5
- package/template/web-app/vue/scripts/createChunks.ts +26 -26
- package/template/web-app/vue/scripts/index.ts +1 -1
- package/template/web-app/vue/shared/hooks/index.ts +2 -2
- package/template/web-app/vue/shared/hooks/useList.ts +104 -104
- package/template/web-app/vue/shared/hooks/useVisible.ts +27 -27
- package/template/web-app/vue/shared/service/api.ts +1 -1
- package/template/web-app/vue/shared/service/home.ts +10 -10
- package/template/web-app/vue/shared/service/index.ts +3 -3
- package/template/web-app/vue/shared/service/request.ts +5 -5
- package/template/web-app/vue/style.css +3 -3
- package/template/web-app/vue/tsconfig.json +24 -24
- package/template/web-app/vue/tsconfig.node.json +10 -10
- package/template/web-app/vue/vite-env.d.ts +18 -18
- package/template/web-app/vue/vite.config.ts +65 -65
- package/template/web-extension/.eslintrc +0 -9
- package/template/web-extension/.vscode/extensions.json +2 -2
- package/template/web-extension/biome.json +37 -0
- package/template/web-extension/package.json +2 -3
- package/template/cli/.prettierignore +0 -6
- package/template/cli/.prettierrc.js +0 -20
- package/template/lib/workspace/.prettierignore +0 -4
- package/template/lib/workspace/.prettierrc +0 -18
- package/template/lib/workspace/packages/react/.prettierignore +0 -4
- package/template/lib/workspace/packages/react/.prettierrc +0 -18
- package/template/lib/workspace/packages/ts/.prettierrc +0 -12
- package/template/web-app/react-rspack/.prettierignore +0 -6
- package/template/web-app/react-rspack/.prettierrc +0 -12
- package/template/web-app/react-vite/.prettierignore +0 -6
- package/template/web-app/react-vite/.prettierrc +0 -12
- package/template/web-app/vue/.prettierignore +0 -6
- package/template/web-app/vue/.prettierrc +0 -12
- package/template/web-extension/.prettierignore +0 -6
- package/template/web-extension/.prettierrc +0 -12
|
@@ -1,15 +1,15 @@
|
|
|
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
|
+
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,27 +1,27 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { isFunction } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export interface useVisibleConfigType {
|
|
5
|
-
defaultVisible?: boolean
|
|
6
|
-
onBeforeShow?: () => Promise<boolean | void>
|
|
7
|
-
onBeforeHide?: () => Promise<boolean | void>
|
|
8
|
-
}
|
|
9
|
-
export default function useVisible(config?: useVisibleConfigType) {
|
|
10
|
-
const [visible, setVisible] = useState(config?.defaultVisible ?? false)
|
|
11
|
-
const onShow = async () => {
|
|
12
|
-
let isShow: boolean | void = true
|
|
13
|
-
if (isFunction(config?.onBeforeShow)) {
|
|
14
|
-
isShow = await config?.onBeforeShow?.()
|
|
15
|
-
}
|
|
16
|
-
setVisible(isShow !== false)
|
|
17
|
-
}
|
|
18
|
-
const onClose = async () => {
|
|
19
|
-
let isHide: boolean | void = true
|
|
20
|
-
if (isFunction(config?.onBeforeHide)) {
|
|
21
|
-
isHide = await config?.onBeforeHide?.()
|
|
22
|
-
}
|
|
23
|
-
setVisible(isHide === false)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return { visible, onShow, onClose }
|
|
27
|
-
}
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { isFunction } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
export interface useVisibleConfigType {
|
|
5
|
+
defaultVisible?: boolean
|
|
6
|
+
onBeforeShow?: () => Promise<boolean | void>
|
|
7
|
+
onBeforeHide?: () => Promise<boolean | void>
|
|
8
|
+
}
|
|
9
|
+
export default function useVisible(config?: useVisibleConfigType) {
|
|
10
|
+
const [visible, setVisible] = useState(config?.defaultVisible ?? false)
|
|
11
|
+
const onShow = async () => {
|
|
12
|
+
let isShow: boolean | void = true
|
|
13
|
+
if (isFunction(config?.onBeforeShow)) {
|
|
14
|
+
isShow = await config?.onBeforeShow?.()
|
|
15
|
+
}
|
|
16
|
+
setVisible(isShow !== false)
|
|
17
|
+
}
|
|
18
|
+
const onClose = async () => {
|
|
19
|
+
let isHide: boolean | void = true
|
|
20
|
+
if (isFunction(config?.onBeforeHide)) {
|
|
21
|
+
isHide = await config?.onBeforeHide?.()
|
|
22
|
+
}
|
|
23
|
+
setVisible(isHide === false)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { visible, onShow, onClose }
|
|
27
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const HOME_DATA = '/homeData'
|
|
1
|
+
export const HOME_DATA = '/homeData'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query'
|
|
2
|
-
import { request } from './request'
|
|
3
|
-
import { HOME_DATA } from './api'
|
|
4
|
-
|
|
5
|
-
export function useHomeQuery() {
|
|
6
|
-
return useQuery({
|
|
7
|
-
queryKey: ['home_data'],
|
|
8
|
-
queryFn: () => request.post(HOME_DATA)
|
|
9
|
-
})
|
|
10
|
-
}
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { request } from './request'
|
|
3
|
+
import { HOME_DATA } from './api'
|
|
4
|
+
|
|
5
|
+
export function useHomeQuery() {
|
|
6
|
+
return useQuery({
|
|
7
|
+
queryKey: ['home_data'],
|
|
8
|
+
queryFn: () => request.post(HOME_DATA)
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './request'
|
|
2
|
-
export * as API from './api'
|
|
3
|
-
export * from './home'
|
|
1
|
+
export * from './request'
|
|
2
|
+
export * as API from './api'
|
|
3
|
+
export * from './home'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
|
|
3
|
-
export const request = axios.create({
|
|
4
|
-
baseURL: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_HOST
|
|
5
|
-
})
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
|
|
3
|
+
export const request = axios.create({
|
|
4
|
+
baseURL: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_HOST
|
|
5
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './theme.styled'
|
|
1
|
+
export * from './theme.styled'
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
import { AnyFunc } from '1k-types'
|
|
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, AnyFunc<CSSProperties>>
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export type themeType = typeof theme
|
|
1
|
+
import { CSSProperties } from 'react'
|
|
2
|
+
import { AnyFunc } from '1k-types'
|
|
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, AnyFunc<CSSProperties>>
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export type themeType = typeof theme
|
|
@@ -1,80 +1,80 @@
|
|
|
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
|
-
(
|
|
62
|
-
<ApiComponent
|
|
63
|
-
ref={instance => {
|
|
64
|
-
current.instance = instanceMap[key].instance = instance!
|
|
65
|
-
resolve()
|
|
66
|
-
}}
|
|
67
|
-
/>
|
|
68
|
-
) as never
|
|
69
|
-
)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
await current.pending
|
|
74
|
-
props && current.instance.$setProps(props)
|
|
75
|
-
// Delay return to avoid sync issue
|
|
76
|
-
// ------------------------------------------------------------------------
|
|
77
|
-
await new Promise(resolve => setTimeout(resolve))
|
|
78
|
-
return current.instance as Refs & refsType<P>
|
|
79
|
-
}
|
|
80
|
-
}
|
|
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
|
+
(
|
|
62
|
+
<ApiComponent
|
|
63
|
+
ref={instance => {
|
|
64
|
+
current.instance = instanceMap[key].instance = instance!
|
|
65
|
+
resolve()
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
) as never
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
await current.pending
|
|
74
|
+
props && current.instance.$setProps(props)
|
|
75
|
+
// Delay return to avoid sync issue
|
|
76
|
+
// ------------------------------------------------------------------------
|
|
77
|
+
await new Promise(resolve => setTimeout(resolve))
|
|
78
|
+
return current.instance as Refs & refsType<P>
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as componentInstance from './componentInstance'
|
|
1
|
+
export * as componentInstance from './componentInstance'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './utils'
|
|
1
|
+
export * from './utils'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { UseBoundStore, StoreApi } from 'zustand'
|
|
2
|
-
export type ExtractModelType<T> = T extends UseBoundStore<StoreApi<infer S>> ? S : unknown
|
|
1
|
+
import type { UseBoundStore, StoreApi } from 'zustand'
|
|
2
|
+
export type ExtractModelType<T> = T extends UseBoundStore<StoreApi<infer S>> ? S : unknown
|
|
@@ -1,44 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"useDefineForClassFields": true,
|
|
6
|
-
"lib": [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"**/*.tsx"
|
|
34
|
-
],
|
|
35
|
-
"exclude": [
|
|
36
|
-
"scripts",
|
|
37
|
-
"vite.config.ts"
|
|
38
|
-
],
|
|
39
|
-
"references": [
|
|
40
|
-
{
|
|
41
|
-
"path": "./tsconfig.node.json"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
7
|
+
"allowJs": false,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"esModuleInterop": false,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"strictPropertyInitialization": false,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"module": "ESNext",
|
|
16
|
+
"moduleResolution": "Node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"jsx": "react-jsx",
|
|
21
|
+
"paths": {
|
|
22
|
+
"@/*": ["./*"]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"include": ["**/*.ts", "**/*.tsx"],
|
|
26
|
+
"exclude": ["scripts", "vite.config.ts"],
|
|
27
|
+
"references": [
|
|
28
|
+
{
|
|
29
|
+
"path": "./tsconfig.node.json"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"composite": true,
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "Node",
|
|
6
|
-
"allowSyntheticDefaultImports": true,
|
|
7
|
-
"resolveJsonModule": true
|
|
8
|
-
},
|
|
9
|
-
"include": ["scripts", "vite.config.ts", "package.json"]
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"composite": true,
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"resolveJsonModule": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["scripts", "vite.config.ts", "package.json"]
|
|
10
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
/// <reference types="vite-plugin-svgr/client" />
|
|
3
|
-
import 'styled-components'
|
|
4
|
-
import { themeType } from './shared/theme'
|
|
5
|
-
|
|
6
|
-
interface ImportMetaEnv {
|
|
7
|
-
readonly VITE_BASE_URL: string
|
|
8
|
-
readonly VITE_API_HOST: string
|
|
9
|
-
// 更多环境变量...
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface ImportMeta {
|
|
13
|
-
readonly env: ImportMetaEnv
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module 'styled-components' {
|
|
17
|
-
export interface DefaultTheme extends themeType {}
|
|
18
|
-
}
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
/// <reference types="vite-plugin-svgr/client" />
|
|
3
|
+
import 'styled-components'
|
|
4
|
+
import { themeType } from './shared/theme'
|
|
5
|
+
|
|
6
|
+
interface ImportMetaEnv {
|
|
7
|
+
readonly VITE_BASE_URL: string
|
|
8
|
+
readonly VITE_API_HOST: string
|
|
9
|
+
// 更多环境变量...
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ImportMeta {
|
|
13
|
+
readonly env: ImportMetaEnv
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module 'styled-components' {
|
|
17
|
+
export interface DefaultTheme extends themeType {}
|
|
18
|
+
}
|