create-packer 1.44.2 → 1.45.0

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.
Files changed (23) hide show
  1. package/package.json +1 -1
  2. package/template/web-app/react-rsbuild/shared/hooks/defineRouter/deineRouter.tsx +2 -1
  3. package/template/web-app/react-vite/domain/router/components/route-layout.tsx +19 -19
  4. package/template/web-app/react-vite/domain/router/components/sub-route-outlet.tsx +22 -22
  5. package/template/web-app/react-vite/scripts/createChunks.ts +4 -3
  6. package/template/web-app/react-vite/shared/hooks/defineRouter/deineRouter.tsx +2 -1
  7. package/template/web-app/react-vite/shared/hooks/useSyncState.ts +2 -2
  8. package/template/web-app/react-vite/shared/hooks/useVisible.ts +1 -1
  9. package/template/web-app/react-vite/vite.config.ts +79 -80
  10. package/template/web-app/svelte/scripts/createChunks.ts +4 -3
  11. package/template/web-app/svelte/vite.config.ts +1 -5
  12. package/template/web-app/vue/domain/app/createComponentInstance.ts +2 -3
  13. package/template/web-app/vue/scripts/createChunks.ts +4 -3
  14. package/template/web-app/vue/shared/hooks/useList.ts +2 -1
  15. package/template/web-app/vue/shared/hooks/useVisible.ts +1 -1
  16. package/template/web-app/vue/vite.config.ts +68 -69
  17. package/template/web-app/vue-rsbuild/domain/app/createComponentInstance.ts +2 -3
  18. package/template/web-app/vue-rsbuild/shared/hooks/useList.ts +2 -1
  19. package/template/web-app/vue-rsbuild/shared/hooks/useVisible.ts +1 -1
  20. package/template/web-extension/entrypoints/content/domain/app/tools/insertApp.tsx +56 -58
  21. package/template/web-extension/shared/hooks/useSyncState.ts +2 -2
  22. package/template/web-extension/shared/hooks/useVisible.ts +1 -1
  23. package/template/web-extension/shared/styles/theme.styled.ts +47 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.44.2",
3
+ "version": "1.45.0",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -1,6 +1,7 @@
1
1
  import { DependencyList, useEffect, useMemo } from 'react'
2
2
  import { useMatches, useSearchParams, NavigateOptions, createBrowserRouter } from 'react-router'
3
- import { assign, isArray, reduce, get, map, split, omit, cloneDeep, last, forEach } from 'lodash-es'
3
+ import { omit, cloneDeep, last } from 'es-toolkit'
4
+ import { assign, isArray, reduce, get, map, split, forEach } from 'es-toolkit/compat'
4
5
  import { stringify, parse } from 'qs'
5
6
  import { defineStore } from 'define-zustand'
6
7
  import { routeByIdType, routeType, editableRouteType } from './defineRouter.types'
@@ -1,19 +1,19 @@
1
- import { FunctionComponent } from 'react'
2
- import { Outlet } from 'react-router'
3
- import { last } from 'lodash-es'
4
- import { routeType, useMatchRoutes } from '@/domain/router'
5
-
6
- export interface propsType {
7
- Index: FunctionComponent
8
- rootId: routeType['id']
9
- }
10
-
11
- export const Root: FunctionComponent<propsType> = ({ Index, rootId }) => {
12
- const matchRoutes = useMatchRoutes()
13
-
14
- if (last(matchRoutes)?.id === rootId) {
15
- return <Index />
16
- }
17
-
18
- return <Outlet />
19
- }
1
+ import { FunctionComponent } from 'react'
2
+ import { Outlet } from 'react-router'
3
+ import { last } from 'es-toolkit'
4
+ import { routeType, useMatchRoutes } from '@/domain/router'
5
+
6
+ export interface propsType {
7
+ Index: FunctionComponent
8
+ rootId: routeType['id']
9
+ }
10
+
11
+ export const Root: FunctionComponent<propsType> = ({ Index, rootId }) => {
12
+ const matchRoutes = useMatchRoutes()
13
+
14
+ if (last(matchRoutes)?.id === rootId) {
15
+ return <Index />
16
+ }
17
+
18
+ return <Outlet />
19
+ }
@@ -1,22 +1,22 @@
1
- import { FunctionComponent } from 'react'
2
- import { Outlet } from 'react-router'
3
- import { useMount } from 'react-use'
4
- import { last } from 'lodash-es'
5
- import { useMatchRoutes, useRouter, routeType } from '@/domain/router'
6
-
7
- export interface propsType {
8
- rootId: routeType['id']
9
- homeId: routeType['id']
10
- }
11
- export const Root: FunctionComponent<propsType> = props => {
12
- const matchRoutes = useMatchRoutes()
13
- const navigate = useRouter(state => state.navigate)
14
-
15
- useMount(() => {
16
- if (last(matchRoutes)?.id === props.rootId) {
17
- navigate({ id: props.homeId })
18
- }
19
- })
20
-
21
- return <Outlet />
22
- }
1
+ import { FunctionComponent } from 'react'
2
+ import { Outlet } from 'react-router'
3
+ import { useMount } from 'react-use'
4
+ import { last } from 'es-toolkit'
5
+ import { useMatchRoutes, useRouter, routeType } from '@/domain/router'
6
+
7
+ export interface propsType {
8
+ rootId: routeType['id']
9
+ homeId: routeType['id']
10
+ }
11
+ export const Root: FunctionComponent<propsType> = props => {
12
+ const matchRoutes = useMatchRoutes()
13
+ const navigate = useRouter(state => state.navigate)
14
+
15
+ useMount(() => {
16
+ if (last(matchRoutes)?.id === props.rootId) {
17
+ navigate({ id: props.homeId })
18
+ }
19
+ })
20
+
21
+ return <Outlet />
22
+ }
@@ -1,11 +1,12 @@
1
- import { concat, forEach, isArray, isRegExp, keys, remove, size } from 'lodash-es'
1
+ import { isRegExp, remove } from 'es-toolkit'
2
+ import { concat, forEach, forOwn, isArray, size } from 'es-toolkit/compat'
2
3
  import pkg from '../package.json'
3
4
 
4
5
  export function createChunks(chunks: { [key: string]: Array<string | RegExp> }) {
5
- const vendor = keys(pkg.dependencies)
6
+ const vendor = Object.keys(pkg.dependencies)
6
7
  const result: { [key: string]: string[] } = {}
7
8
 
8
- forEach(chunks, (values, key) => {
9
+ forOwn(chunks, (values, key) => {
9
10
  if (!isArray(result[key])) {
10
11
  result[key] = []
11
12
  }
@@ -1,6 +1,7 @@
1
1
  import { DependencyList, useEffect, useMemo } from 'react'
2
2
  import { useMatches, useSearchParams, NavigateOptions, createBrowserRouter } from 'react-router'
3
- import { assign, isArray, reduce, get, map, split, omit, cloneDeep, last, forEach } from 'lodash-es'
3
+ import { omit, cloneDeep, last } from 'es-toolkit'
4
+ import { assign, isArray, reduce, get, map, split, forEach } from 'es-toolkit/compat'
4
5
  import { stringify, parse } from 'qs'
5
6
  import { defineStore } from 'define-zustand'
6
7
  import { routeByIdType, routeType, editableRouteType } from './defineRouter.types'
@@ -1,12 +1,12 @@
1
1
  import { useRef, useState, Dispatch, SetStateAction } from 'react'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export function useSyncState<S>(initialState: S | (() => S)) {
5
5
  const [state, setState] = useState(initialState)
6
6
  const syncState = useRef<S>(state)
7
7
 
8
8
  const $setState: Dispatch<SetStateAction<S>> = newState => {
9
- const $newState = isFunction(newState) ? newState(state) : newState
9
+ const $newState = (isFunction(newState) ? newState(state) : newState) as S
10
10
  setState($newState)
11
11
  syncState.current = $newState
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export interface useVisibleConfigType {
5
5
  defaultVisible?: boolean
@@ -1,80 +1,79 @@
1
- import { defineConfig, loadEnv } from 'vite'
2
- import react from '@vitejs/plugin-react'
3
- import svgr from 'vite-plugin-svgr'
4
- import mockDevServer from 'vite-plugin-mock-dev-server'
5
- import checker from 'vite-plugin-checker'
6
- import { visualizer } from 'rollup-plugin-visualizer'
7
- import { includes } from 'lodash-es'
8
- import tailwindcss from '@tailwindcss/vite'
9
- import { createChunks } from './scripts'
10
-
11
- // https://vitejs.dev/config/
12
- export default defineConfig(({ mode }) => {
13
- const env = loadEnv(mode, process.cwd(), '')
14
- const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
15
- const plugins: any[] = [
16
- tailwindcss(),
17
- svgr(),
18
- mockDevServer({
19
- include: ['**/*.mock.{ts,js}']
20
- }),
21
- checker({
22
- enableBuild: false,
23
- typescript: true,
24
- eslint: { useFlatConfig: true, lintCommand: 'eslint', dev: { logLevel: ['error'] } }
25
- }),
26
- react({
27
- babel: {
28
- plugins: [
29
- [
30
- 'babel-plugin-styled-components',
31
- {
32
- ssr: false,
33
- displayName: false,
34
- fileName: false,
35
- transpileTemplateLiterals: false
36
- }
37
- ]
38
- ]
39
- }
40
- })
41
- ]
42
-
43
- if (mode === 'analyse') {
44
- plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
45
- }
46
-
47
- return {
48
- base: env.VITE_BASE_URL,
49
- plugins,
50
- resolve: {
51
- alias: {
52
- '@': __dirname
53
- }
54
- },
55
- esbuild: {
56
- drop: includes(['production', 'analyse'], mode) ? ['console', 'debugger'] : []
57
- },
58
- build: {
59
- sourcemap: mode === 'analyse',
60
- reportCompressedSize: mode === 'analyse',
61
- rollupOptions: {
62
- output: {
63
- manualChunks: createChunks({
64
- react: ['react', 'react-dom']
65
- })
66
- }
67
- }
68
- },
69
- server: {
70
- host: '0.0.0.0',
71
- proxy: {
72
- [proxyBaseUrl]: {
73
- target: 'http://127.0.0.1',
74
- changeOrigin: true,
75
- rewrite: path => path.replace(proxyBaseUrl, '')
76
- }
77
- }
78
- }
79
- }
80
- })
1
+ import { defineConfig, loadEnv } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+ import svgr from 'vite-plugin-svgr'
4
+ import mockDevServer from 'vite-plugin-mock-dev-server'
5
+ import checker from 'vite-plugin-checker'
6
+ import { visualizer } from 'rollup-plugin-visualizer'
7
+ import tailwindcss from '@tailwindcss/vite'
8
+ import { createChunks } from './scripts'
9
+
10
+ // https://vitejs.dev/config/
11
+ export default defineConfig(({ mode }) => {
12
+ const env = loadEnv(mode, process.cwd(), '')
13
+ const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
14
+ const plugins: any[] = [
15
+ tailwindcss(),
16
+ svgr(),
17
+ mockDevServer({
18
+ include: ['**/*.mock.{ts,js}']
19
+ }),
20
+ checker({
21
+ enableBuild: false,
22
+ typescript: true,
23
+ eslint: { useFlatConfig: true, lintCommand: 'eslint', dev: { logLevel: ['error'] } }
24
+ }),
25
+ react({
26
+ babel: {
27
+ plugins: [
28
+ [
29
+ 'babel-plugin-styled-components',
30
+ {
31
+ ssr: false,
32
+ displayName: false,
33
+ fileName: false,
34
+ transpileTemplateLiterals: false
35
+ }
36
+ ]
37
+ ]
38
+ }
39
+ })
40
+ ]
41
+
42
+ if (mode === 'analyse') {
43
+ plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
44
+ }
45
+
46
+ return {
47
+ base: env.VITE_BASE_URL,
48
+ plugins,
49
+ resolve: {
50
+ alias: {
51
+ '@': __dirname
52
+ }
53
+ },
54
+ esbuild: {
55
+ drop: ['production', 'analyse'].includes(mode) ? ['console', 'debugger'] : []
56
+ },
57
+ build: {
58
+ sourcemap: mode === 'analyse',
59
+ reportCompressedSize: mode === 'analyse',
60
+ rollupOptions: {
61
+ output: {
62
+ manualChunks: createChunks({
63
+ react: ['react', 'react-dom']
64
+ })
65
+ }
66
+ }
67
+ },
68
+ server: {
69
+ host: '0.0.0.0',
70
+ proxy: {
71
+ [proxyBaseUrl]: {
72
+ target: 'http://127.0.0.1',
73
+ changeOrigin: true,
74
+ rewrite: path => path.replace(proxyBaseUrl, '')
75
+ }
76
+ }
77
+ }
78
+ }
79
+ })
@@ -1,11 +1,12 @@
1
- import { concat, forEach, isArray, isRegExp, keys, remove, size } from 'lodash-es'
1
+ import { isRegExp, remove } from 'es-toolkit'
2
+ import { concat, forEach, forOwn, isArray, size } from 'es-toolkit/compat'
2
3
  import pkg from '../package.json'
3
4
 
4
5
  export function createChunks(chunks: { [key: string]: Array<string | RegExp> }) {
5
- const vendor = keys(pkg.dependencies)
6
+ const vendor = Object.keys(pkg.dependencies)
6
7
  const result: { [key: string]: string[] } = {}
7
8
 
8
- forEach(chunks, (values, key) => {
9
+ forOwn(chunks, (values, key) => {
9
10
  if (!isArray(result[key])) {
10
11
  result[key] = []
11
12
  }
@@ -1,16 +1,12 @@
1
- import path from 'path'
2
1
  import { defineConfig, loadEnv } from 'vite'
3
2
  import { sveltekit } from '@sveltejs/kit/vite'
4
- import stylelint from 'vite-plugin-stylelint'
5
3
  import checker from 'vite-plugin-checker'
6
4
  import { visualizer } from 'rollup-plugin-visualizer'
7
- import { includes } from 'lodash-es'
8
5
  import { createChunks } from './scripts'
9
6
 
10
7
  export default defineConfig(({ mode }) => {
11
8
  const env = loadEnv(mode, process.cwd(), '')
12
9
  const plugins: any[] = [
13
- stylelint({ cache: false, include: ['**/*.{css,scss,sass,less,styl,ts,tsx}'] }),
14
10
  checker({
15
11
  enableBuild: false,
16
12
  typescript: true,
@@ -26,7 +22,7 @@ export default defineConfig(({ mode }) => {
26
22
  return {
27
23
  plugins,
28
24
  esbuild: {
29
- drop: includes(['production', 'analyse'], mode) ? ['console', 'debugger'] : []
25
+ drop: ['production', 'analyse'].includes(mode) ? ['console', 'debugger'] : []
30
26
  },
31
27
  build: {
32
28
  sourcemap: mode === 'analyse',
@@ -1,14 +1,13 @@
1
1
  import { createVNode, render, VNodeChild } from 'vue'
2
- import { assign, keys } from 'lodash-es'
3
2
  import app from './app'
4
3
 
5
4
  const store = new Map()
6
5
 
7
6
  function reset(oldObj: Record<string, any>, newObj: Record<string, any>) {
8
- keys(oldObj).forEach(k => {
7
+ Object.keys(oldObj).forEach(k => {
9
8
  oldObj[k] = void 0
10
9
  })
11
- assign(oldObj, newObj)
10
+ Object.assign(oldObj, newObj)
12
11
  }
13
12
 
14
13
  export function createComponentInstance<
@@ -1,11 +1,12 @@
1
- import { concat, forEach, includes, isArray, isRegExp, keys, remove, size } from 'lodash-es'
1
+ import { isRegExp, remove } from 'es-toolkit'
2
+ import { concat, forEach, forOwn, isArray, size } from 'es-toolkit/compat'
2
3
  import pkg from '../package.json'
3
4
 
4
5
  export function createChunks(chunks: { [key: string]: Array<string | RegExp> }) {
5
- const vendor = keys(pkg.dependencies)
6
+ const vendor = Object.keys(pkg.dependencies)
6
7
  const result: { [key: string]: string[] } = {}
7
8
 
8
- forEach(chunks, (values, key) => {
9
+ forOwn(chunks, (values, key) => {
9
10
  if (!isArray(result[key])) {
10
11
  result[key] = []
11
12
  }
@@ -1,5 +1,6 @@
1
1
  import { ref, reactive, computed, unref } from 'vue'
2
- import { cloneDeep, assign, pick, isNil, size, max } from 'lodash-es'
2
+ import { cloneDeep, pick, isNil } from 'es-toolkit'
3
+ import { assign, size, max } from 'es-toolkit/compat'
3
4
 
4
5
  export interface configType<ListItem, P> {
5
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { ref } from 'vue'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export interface useVisibleConfigType {
5
5
  defaultVisible?: boolean
@@ -1,69 +1,68 @@
1
- import { defineConfig, loadEnv } from 'vite'
2
- import vue from '@vitejs/plugin-vue'
3
- import vueJsx from '@vitejs/plugin-vue-jsx'
4
- import svgLoader from 'vite-svg-loader'
5
- import mockDevServer from 'vite-plugin-mock-dev-server'
6
- import checker from 'vite-plugin-checker'
7
- import tailwindcss from '@tailwindcss/vite'
8
- import { visualizer } from 'rollup-plugin-visualizer'
9
- import { includes } from 'lodash-es'
10
- import { createChunks } from './scripts'
11
-
12
- // https://vitejs.dev/config/
13
- export default defineConfig(({ mode }) => {
14
- const env = loadEnv(mode, process.cwd(), '')
15
- const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
16
- const plugins: any[] = [
17
- tailwindcss(),
18
- mockDevServer({
19
- include: ['**/*.mock.{ts,js}']
20
- }),
21
- vueJsx({
22
- enableObjectSlots: false
23
- }),
24
- vue(),
25
- checker({
26
- enableBuild: false,
27
- typescript: true,
28
- eslint: { useFlatConfig: true, lintCommand: 'eslint', dev: { logLevel: ['error'] } }
29
- }),
30
- svgLoader()
31
- ]
32
-
33
- if (mode === 'analyse') {
34
- plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
35
- }
36
- return {
37
- base: env.VITE_BASE_URL,
38
- plugins,
39
- resolve: {
40
- alias: {
41
- '@': __dirname
42
- }
43
- },
44
- esbuild: {
45
- drop: includes(['production', 'analyse'], mode) ? ['console', 'debugger'] : []
46
- },
47
- build: {
48
- sourcemap: mode === 'analyse',
49
- reportCompressedSize: mode === 'analyse',
50
- rollupOptions: {
51
- output: {
52
- manualChunks: createChunks({
53
- vue: ['vue', 'vue-router']
54
- })
55
- }
56
- }
57
- },
58
- server: {
59
- host: '0.0.0.0',
60
- proxy: {
61
- [proxyBaseUrl]: {
62
- target: 'http://127.0.0.1',
63
- changeOrigin: true,
64
- rewrite: path => path.replace(proxyBaseUrl, '')
65
- }
66
- }
67
- }
68
- }
69
- })
1
+ import { defineConfig, loadEnv } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+ import vueJsx from '@vitejs/plugin-vue-jsx'
4
+ import svgLoader from 'vite-svg-loader'
5
+ import mockDevServer from 'vite-plugin-mock-dev-server'
6
+ import checker from 'vite-plugin-checker'
7
+ import tailwindcss from '@tailwindcss/vite'
8
+ import { visualizer } from 'rollup-plugin-visualizer'
9
+ import { createChunks } from './scripts'
10
+
11
+ // https://vitejs.dev/config/
12
+ export default defineConfig(({ mode }) => {
13
+ const env = loadEnv(mode, process.cwd(), '')
14
+ const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
15
+ const plugins: any[] = [
16
+ tailwindcss(),
17
+ mockDevServer({
18
+ include: ['**/*.mock.{ts,js}']
19
+ }),
20
+ vueJsx({
21
+ enableObjectSlots: false
22
+ }),
23
+ vue(),
24
+ checker({
25
+ enableBuild: false,
26
+ typescript: true,
27
+ eslint: { useFlatConfig: true, lintCommand: 'eslint', dev: { logLevel: ['error'] } }
28
+ }),
29
+ svgLoader()
30
+ ]
31
+
32
+ if (mode === 'analyse') {
33
+ plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
34
+ }
35
+ return {
36
+ base: env.VITE_BASE_URL,
37
+ plugins,
38
+ resolve: {
39
+ alias: {
40
+ '@': __dirname
41
+ }
42
+ },
43
+ esbuild: {
44
+ drop: ['production', 'analyse'].includes(mode) ? ['console', 'debugger'] : []
45
+ },
46
+ build: {
47
+ sourcemap: mode === 'analyse',
48
+ reportCompressedSize: mode === 'analyse',
49
+ rollupOptions: {
50
+ output: {
51
+ manualChunks: createChunks({
52
+ vue: ['vue', 'vue-router']
53
+ })
54
+ }
55
+ }
56
+ },
57
+ server: {
58
+ host: '0.0.0.0',
59
+ proxy: {
60
+ [proxyBaseUrl]: {
61
+ target: 'http://127.0.0.1',
62
+ changeOrigin: true,
63
+ rewrite: path => path.replace(proxyBaseUrl, '')
64
+ }
65
+ }
66
+ }
67
+ }
68
+ })
@@ -1,14 +1,13 @@
1
1
  import { createVNode, render, VNodeChild } from 'vue'
2
- import { assign, keys } from 'lodash-es'
3
2
  import app from './app'
4
3
 
5
4
  const store = new Map()
6
5
 
7
6
  function reset(oldObj: Record<string, any>, newObj: Record<string, any>) {
8
- keys(oldObj).forEach(k => {
7
+ Object.keys(oldObj).forEach(k => {
9
8
  oldObj[k] = void 0
10
9
  })
11
- assign(oldObj, newObj)
10
+ Object.assign(oldObj, newObj)
12
11
  }
13
12
 
14
13
  export function createComponentInstance<
@@ -1,5 +1,6 @@
1
1
  import { ref, reactive, computed, unref } from 'vue'
2
- import { cloneDeep, assign, pick, isNil, size, max } from 'lodash-es'
2
+ import { cloneDeep, pick, isNil } from 'es-toolkit'
3
+ import { assign, size, max } from 'es-toolkit/compat'
3
4
 
4
5
  export interface configType<ListItem, P> {
5
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { ref } from 'vue'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export interface useVisibleConfigType {
5
5
  defaultVisible?: boolean
@@ -1,58 +1,56 @@
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.Root>{option.reactNode}</AppContext.Root>)
56
- result.result = true
57
- return result
58
- }
1
+ import { CSSProperties, ReactNode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import { isFunction } from 'es-toolkit'
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
+ Object.assign(result.rootEle!.style, option.rootStyle)
41
+ const oldRootEle = target.querySelector?.(`#${rootId}`)
42
+ if (!option.isReplace && oldRootEle) {
43
+ result.status = insertAppStatus.root_existed
44
+ return result
45
+ }
46
+ oldRootEle?.remove()
47
+ if (isFunction(option.insert)) {
48
+ option.insert(result.rootEle, target)
49
+ } else {
50
+ target.appendChild(result.rootEle)
51
+ }
52
+ const root = createRoot(result.rootEle)
53
+ root.render(<AppContext.Root>{option.reactNode}</AppContext.Root>)
54
+ result.result = true
55
+ return result
56
+ }
@@ -1,12 +1,12 @@
1
1
  import { useRef, useState, Dispatch, SetStateAction } from 'react'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export function useSyncState<S>(initialState: S | (() => S)) {
5
5
  const [state, setState] = useState(initialState)
6
6
  const syncState = useRef<S>(state)
7
7
 
8
8
  const $setState: Dispatch<SetStateAction<S>> = newState => {
9
- const $newState = isFunction(newState) ? newState(state) : newState
9
+ const $newState = (isFunction(newState) ? newState(state) : newState) as S
10
10
  setState($newState)
11
11
  syncState.current = $newState
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react'
2
- import { isFunction } from 'lodash-es'
2
+ import { isFunction } from 'es-toolkit'
3
3
 
4
4
  export interface useVisibleConfigType {
5
5
  defaultVisible?: boolean
@@ -1,47 +1,47 @@
1
- import { CSSProperties } from 'react'
2
- import { isString } from 'lodash-es'
3
-
4
- export const theme = {
5
- tools: {
6
- ellipsis: () => ({
7
- overflow: 'hidden',
8
- textOverflow: 'ellipsis',
9
- whiteSpace: 'nowrap'
10
- }),
11
- lineClamp: (n: number) => {
12
- return {
13
- WebkitLineClamp: `${n}`,
14
- WebkitBoxOrient: 'vertical',
15
- overflow: 'hidden',
16
- display: '-webkit-box'
17
- } satisfies CSSProperties
18
- },
19
- size: (s: string) => ({ width: s, height: s }),
20
- py: (s: string) => ({ paddingTop: s, paddingBottom: s }),
21
- px: (s: string) => ({ paddingLeft: s, paddingRight: s }),
22
- my: (s: string) => ({ marginTop: s, marginBottom: s }),
23
- mx: (s: string) => ({ marginLeft: s, marginRight: s }),
24
- flex: (
25
- align: CSSProperties['alignItems'],
26
- justify: CSSProperties['justifyContent'],
27
- vertical?: boolean
28
- ) => {
29
- return {
30
- display: 'flex',
31
- alignItems: align,
32
- justifyContent: justify,
33
- flexDirection: vertical ? 'column' : 'row'
34
- } satisfies CSSProperties
35
- },
36
- /** 数字为元素数量,字符串为对应css的值 */
37
- grid: (rows: number | string, cols: number | string, gap?: number) => {
38
- return {
39
- display: 'grid',
40
- gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
41
- gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
42
- gap: gap ? `${gap}px` : void 0
43
- } satisfies CSSProperties
44
- }
45
- }
46
- }
47
- export type themeType = typeof theme
1
+ import { CSSProperties } from 'react'
2
+ import { isString } from 'es-toolkit'
3
+
4
+ export const theme = {
5
+ tools: {
6
+ ellipsis: () => ({
7
+ overflow: 'hidden',
8
+ textOverflow: 'ellipsis',
9
+ whiteSpace: 'nowrap'
10
+ }),
11
+ lineClamp: (n: number) => {
12
+ return {
13
+ WebkitLineClamp: `${n}`,
14
+ WebkitBoxOrient: 'vertical',
15
+ overflow: 'hidden',
16
+ display: '-webkit-box'
17
+ } satisfies CSSProperties
18
+ },
19
+ size: (s: string) => ({ width: s, height: s }),
20
+ py: (s: string) => ({ paddingTop: s, paddingBottom: s }),
21
+ px: (s: string) => ({ paddingLeft: s, paddingRight: s }),
22
+ my: (s: string) => ({ marginTop: s, marginBottom: s }),
23
+ mx: (s: string) => ({ marginLeft: s, marginRight: s }),
24
+ flex: (
25
+ align: CSSProperties['alignItems'],
26
+ justify: CSSProperties['justifyContent'],
27
+ vertical?: boolean
28
+ ) => {
29
+ return {
30
+ display: 'flex',
31
+ alignItems: align,
32
+ justifyContent: justify,
33
+ flexDirection: vertical ? 'column' : 'row'
34
+ } satisfies CSSProperties
35
+ },
36
+ /** 数字为元素数量,字符串为对应css的值 */
37
+ grid: (rows: number | string, cols: number | string, gap?: number) => {
38
+ return {
39
+ display: 'grid',
40
+ gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
41
+ gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
42
+ gap: gap ? `${gap}px` : void 0
43
+ } satisfies CSSProperties
44
+ }
45
+ }
46
+ }
47
+ export type themeType = typeof theme