create-packer 1.21.6 → 1.21.8
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/package.json +1 -1
- package/template/react/react-app/src/controllers/index.ts +0 -1
- package/template/react/react-app/src/providers/componentInstance.tsx +19 -16
- package/template/react/react-app/src/controllers/useComponentInstance.ts +0 -31
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"preview": "vite preview",
|
|
11
11
|
"up:vite": "pnpm up vite @vitejs/* -L",
|
|
12
12
|
"format": "prettier --write \"src/**/*.{ts,js,tsx,jsx,css,scss,less}\" \"./package.json\"",
|
|
13
|
-
"lint": "eslint ./src/**/*.{tsx,ts} && stylelint ./src/**/*.{css,scss,less}",
|
|
13
|
+
"lint": "tsc --noEmit && eslint ./src/**/*.{tsx,ts} && stylelint ./src/**/*.{css,scss,less}",
|
|
14
14
|
"lint:fix": "eslint ./src/**/*.{tsx,ts} --fix && stylelint ./src/**/*.{css,scss,less} --fix",
|
|
15
15
|
"test:watchs": "jest --watch",
|
|
16
16
|
"test": "jest",
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from 'react'
|
|
10
10
|
import { createRoot } from 'react-dom/client'
|
|
11
11
|
|
|
12
|
-
const instanceMap: Record<string, any> = {}
|
|
12
|
+
const instanceMap: Record<string, { pending: Promise<any>; instance: any }> = {}
|
|
13
13
|
|
|
14
14
|
export interface refsType<P> {
|
|
15
15
|
$setProps: (newProps: P) => void
|
|
@@ -21,9 +21,8 @@ export async function create<P extends Record<string, any>, Refs extends Record<
|
|
|
21
21
|
Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
|
|
22
22
|
props?: P
|
|
23
23
|
) {
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
if (!$instance) {
|
|
24
|
+
let current = instanceMap[key]
|
|
25
|
+
if (!current) {
|
|
27
26
|
const div = document.createElement('div')
|
|
28
27
|
document.body.appendChild(div)
|
|
29
28
|
const ApiComponent = forwardRef<Refs & refsType<P>>((__, refs) => {
|
|
@@ -45,17 +44,21 @@ export async function create<P extends Record<string, any>, Refs extends Record<
|
|
|
45
44
|
})
|
|
46
45
|
return <Component ref={ref} {...(state as any)} />
|
|
47
46
|
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
current = instanceMap[key] = {
|
|
48
|
+
instance: void 0,
|
|
49
|
+
pending: new Promise<void>(resolve => {
|
|
50
|
+
createRoot(div).render(
|
|
51
|
+
<ApiComponent
|
|
52
|
+
ref={instance => {
|
|
53
|
+
current.instance = instanceMap[key].instance = instance!
|
|
54
|
+
resolve()
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
await current.pending
|
|
62
|
+
props && current.instance.$setProps(props)
|
|
63
|
+
return current.instance as Refs & refsType<P>
|
|
61
64
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, useEffect, useRef } from 'react'
|
|
2
|
-
import { componentInstance } from '@/providers'
|
|
3
|
-
|
|
4
|
-
export default function useComponentInstance<
|
|
5
|
-
P extends Record<string, any>,
|
|
6
|
-
Refs extends Record<string, any>
|
|
7
|
-
>(
|
|
8
|
-
key: string,
|
|
9
|
-
Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
|
|
10
|
-
props?: P
|
|
11
|
-
) {
|
|
12
|
-
const $instance = useRef<(Refs & componentInstance.refsType<P>) | null>(null)
|
|
13
|
-
const pending = useRef(false)
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if ($instance.current === null) {
|
|
17
|
-
if (pending.current === false) {
|
|
18
|
-
pending.current = true
|
|
19
|
-
componentInstance.create(key, Component, props).then(instance => {
|
|
20
|
-
$instance.current = instance
|
|
21
|
-
props && $instance.current.$updateProps(props)
|
|
22
|
-
pending.current = false
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
props && $instance.current?.$updateProps(props)
|
|
27
|
-
}
|
|
28
|
-
}, [props])
|
|
29
|
-
|
|
30
|
-
return $instance
|
|
31
|
-
}
|