create-packer 1.39.0 → 1.39.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.39.0",
3
+ "version": "1.39.1",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -1,58 +1,58 @@
1
- import { CSSProperties, ReactNode } from 'react'
2
- import { createRoot } from 'react-dom/client'
3
- import { forEach, isFunction } from 'lodash-es'
4
- import { AppContext } from '@/shared/components'
5
- import { classNameSpace } from '@/entrypoints/content/constants'
6
-
7
- export enum insertAppStatus {
8
- success,
9
- target_not_exist,
10
- root_existed
11
- }
12
- export interface insertAppResultType {
13
- rootEle: HTMLElement | undefined | null
14
- result: boolean
15
- status: insertAppStatus
16
- }
17
- export function insertApp<T extends HTMLElement>(
18
- target: Nullable<T>,
19
- option: {
20
- insert?: (rootEle: HTMLElement, target: T) => void
21
- reactNode: ReactNode
22
- isReplace?: boolean
23
- rootId: string
24
- rootStyle?: CSSProperties
25
- }
26
- ) {
27
- const result: insertAppResultType = {
28
- result: false,
29
- rootEle: void 0,
30
- status: insertAppStatus.success
31
- }
32
- const rootId = `${import.meta.env.VITE_APP_ID}_${option.rootId}`
33
- if (!target) {
34
- result.status = insertAppStatus.target_not_exist
35
- return result
36
- }
37
- result.rootEle = document.createElement('div')
38
- result.rootEle.className = classNameSpace
39
- result.rootEle.id = rootId
40
- forEach(option.rootStyle, (value, key) => {
41
- result.rootEle!.style[key as any] = value as never
42
- })
43
- const oldRootEle = target.querySelector?.(`#${rootId}`)
44
- if (!option.isReplace && oldRootEle) {
45
- result.status = insertAppStatus.root_existed
46
- return result
47
- }
48
- oldRootEle?.remove()
49
- if (isFunction(option.insert)) {
50
- option.insert(result.rootEle, target)
51
- } else {
52
- target.appendChild(result.rootEle)
53
- }
54
- const root = createRoot(result.rootEle)
55
- root.render(<AppContext>{option.reactNode}</AppContext>)
56
- result.result = true
57
- return result
58
- }
1
+ import { CSSProperties, ReactNode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { forEach, isFunction } from 'lodash-es'
4
+ import { AppContext } from '@/shared/components'
5
+ import { classNameSpace } from '@/entrypoints/content/constants'
6
+
7
+ export enum insertAppStatus {
8
+ success,
9
+ target_not_exist,
10
+ root_existed
11
+ }
12
+ export interface insertAppResultType {
13
+ rootEle: HTMLElement | undefined | null
14
+ result: boolean
15
+ status: insertAppStatus
16
+ }
17
+ export function insertApp<T extends HTMLElement>(
18
+ target: T | null | undefined,
19
+ option: {
20
+ insert?: (rootEle: HTMLElement, target: T) => void
21
+ reactNode: ReactNode
22
+ isReplace?: boolean
23
+ rootId: string
24
+ rootStyle?: CSSProperties
25
+ }
26
+ ) {
27
+ const result: insertAppResultType = {
28
+ result: false,
29
+ rootEle: void 0,
30
+ status: insertAppStatus.success
31
+ }
32
+ const rootId = `${import.meta.env.VITE_APP_ID}_${option.rootId}`
33
+ if (!target) {
34
+ result.status = insertAppStatus.target_not_exist
35
+ return result
36
+ }
37
+ result.rootEle = document.createElement('div')
38
+ result.rootEle.className = classNameSpace
39
+ result.rootEle.id = rootId
40
+ forEach(option.rootStyle, (value, key) => {
41
+ result.rootEle!.style[key as any] = value as never
42
+ })
43
+ const oldRootEle = target.querySelector?.(`#${rootId}`)
44
+ if (!option.isReplace && oldRootEle) {
45
+ result.status = insertAppStatus.root_existed
46
+ return result
47
+ }
48
+ oldRootEle?.remove()
49
+ if (isFunction(option.insert)) {
50
+ option.insert(result.rootEle, target)
51
+ } else {
52
+ target.appendChild(result.rootEle)
53
+ }
54
+ const root = createRoot(result.rootEle)
55
+ root.render(<AppContext>{option.reactNode}</AppContext>)
56
+ result.result = true
57
+ return result
58
+ }