create-packer 1.17.12 → 1.17.14
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/chrome-extension/tsconfig.json +1 -0
- package/template/react/src/controllers/useComponentInstance.ts +3 -3
- package/template/react/src/providers/componentInstance.tsx +6 -6
- package/template/react/src/providers/defineModel.ts +13 -10
- package/template/react/tsconfig.json +1 -0
- package/template/solid/tsconfig.json +1 -0
- package/template/vue/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export default function useComponentInstance<
|
|
|
6
6
|
Refs extends Record<string, any>
|
|
7
7
|
>(
|
|
8
8
|
key: string,
|
|
9
|
-
Component: ForwardRefExoticComponent<PropsWithoutRef<
|
|
9
|
+
Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
|
|
10
10
|
props?: P
|
|
11
11
|
) {
|
|
12
12
|
const $instance = useRef<(Refs & componentInstance.refsType<P>) | null>(null)
|
|
@@ -18,12 +18,12 @@ export default function useComponentInstance<
|
|
|
18
18
|
pending.current = true
|
|
19
19
|
componentInstance.create(key, Component, props).then(instance => {
|
|
20
20
|
$instance.current = instance
|
|
21
|
-
$instance.current.$updateProps(props)
|
|
21
|
+
props && $instance.current.$updateProps(props)
|
|
22
22
|
pending.current = false
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
|
-
$instance.current?.$updateProps(props)
|
|
26
|
+
props && $instance.current?.$updateProps(props)
|
|
27
27
|
}
|
|
28
28
|
}, [props])
|
|
29
29
|
|
|
@@ -12,13 +12,13 @@ import { createRoot } from 'react-dom/client'
|
|
|
12
12
|
const instanceMap: Record<string, any> = {}
|
|
13
13
|
|
|
14
14
|
export interface refsType<P> {
|
|
15
|
-
$setProps: (newProps
|
|
16
|
-
$updateProps: (newProps
|
|
15
|
+
$setProps: (newProps: P) => void
|
|
16
|
+
$updateProps: (newProps: Partial<P>) => void
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export async function create<P extends Record<string, any>, Refs extends Record<string, any>>(
|
|
20
20
|
key: string,
|
|
21
|
-
Component: ForwardRefExoticComponent<PropsWithoutRef<
|
|
21
|
+
Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
|
|
22
22
|
props?: P
|
|
23
23
|
) {
|
|
24
24
|
let $instance: Refs & refsType<P> = instanceMap[key]
|
|
@@ -28,7 +28,7 @@ export async function create<P extends Record<string, any>, Refs extends Record<
|
|
|
28
28
|
document.body.appendChild(div)
|
|
29
29
|
const ApiComponent = forwardRef<Refs & refsType<P>>((__, refs) => {
|
|
30
30
|
const ref = useRef<Refs>(null)
|
|
31
|
-
const [state, setState] = useState<P
|
|
31
|
+
const [state, setState] = useState<Partial<P>>(props || {})
|
|
32
32
|
|
|
33
33
|
useImperativeHandle(refs, () => {
|
|
34
34
|
return {
|
|
@@ -43,7 +43,7 @@ export async function create<P extends Record<string, any>, Refs extends Record<
|
|
|
43
43
|
...ref.current
|
|
44
44
|
} as Refs & refsType<P>
|
|
45
45
|
})
|
|
46
|
-
return <Component ref={ref} {...state} />
|
|
46
|
+
return <Component ref={ref} {...(state as any)} />
|
|
47
47
|
})
|
|
48
48
|
await new Promise<void>(resolve => {
|
|
49
49
|
createRoot(div).render(
|
|
@@ -56,6 +56,6 @@ export async function create<P extends Record<string, any>, Refs extends Record<
|
|
|
56
56
|
)
|
|
57
57
|
})
|
|
58
58
|
}
|
|
59
|
-
$instance.$setProps(props)
|
|
59
|
+
props && $instance.$setProps(props)
|
|
60
60
|
return $instance
|
|
61
61
|
}
|
|
@@ -2,20 +2,20 @@ import { create } from 'zustand'
|
|
|
2
2
|
import { produce } from 'immer'
|
|
3
3
|
|
|
4
4
|
export type setStateType<S> = (updater: (state: S) => void) => void
|
|
5
|
-
export interface modelActionsType {
|
|
5
|
+
export interface modelActionsType<S extends Record<string, any>> {
|
|
6
6
|
reset: () => void
|
|
7
|
+
setState: setStateType<S>
|
|
7
8
|
}
|
|
8
9
|
export interface modelOptionsType<S extends Record<string, any>, A extends Record<string, any>> {
|
|
9
10
|
state: () => S
|
|
10
|
-
actions: (
|
|
11
|
+
actions: (getState: () => S, actions: modelActionsType<S>) => A
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export function defineModel<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const _setState: setStateType<S> = updater => {
|
|
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
19
|
setState(
|
|
20
20
|
produce((store: { state: S }) => {
|
|
21
21
|
updater(store.state)
|
|
@@ -23,7 +23,7 @@ export function defineModel<
|
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
25
|
const _getState = () => getState().state
|
|
26
|
-
const reset: modelActionsType['reset'] = () => {
|
|
26
|
+
const reset: modelActionsType<S>['reset'] = () => {
|
|
27
27
|
setState({ state: options.state() })
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
@@ -32,7 +32,10 @@ export function defineModel<
|
|
|
32
32
|
reset,
|
|
33
33
|
setState: _setState,
|
|
34
34
|
subscribe: store.subscribe,
|
|
35
|
-
...options.actions(
|
|
35
|
+
...options.actions(_getState, {
|
|
36
|
+
reset,
|
|
37
|
+
setState: _setState
|
|
38
|
+
})
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
})
|