@gm-pc/react 1.13.2 → 1.13.3-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/react",
3
- "version": "1.13.2",
3
+ "version": "1.13.3-alpha.0",
4
4
  "description": "观麦前端基础组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@gm-common/hooks": "^2.10.0",
26
26
  "@gm-common/tool": "^2.10.0",
27
- "@gm-pc/locales": "^1.13.2",
27
+ "@gm-pc/locales": "^1.13.3-alpha.0",
28
28
  "big.js": "^6.0.1",
29
29
  "classnames": "^2.2.5",
30
30
  "lodash": "^4.17.19",
@@ -48,5 +48,5 @@
48
48
  "react-router-dom": "^5.2.0",
49
49
  "react-window": "^1.8.5"
50
50
  },
51
- "gitHead": "eed0722555286fb4c48d77c9fe1082db7c6ffb7f"
51
+ "gitHead": "8f4025e778efd916867e985fd61ccdeaa842e441"
52
52
  }
@@ -1,7 +1,7 @@
1
1
  import { createContext } from 'react'
2
2
  import { VBrowserWindow } from '../types'
3
3
 
4
- const BrowserWindowContext = createContext<VBrowserWindow>(undefined as any)
4
+ const BrowserWindowContext = createContext<string>(undefined as any)
5
5
  BrowserWindowContext.displayName = 'VBrowserWindowContext'
6
6
 
7
7
  export default BrowserWindowContext
@@ -12,8 +12,8 @@ type Noop = () => void
12
12
  */
13
13
  export default function useWindowEffect(fn: () => Noop | void, deps: Array<any>) {
14
14
  const browser = useContext(BrowserContext)
15
- /** hook所在窗口 */
16
- const browserWindow = useContext(BrowserWindowContext)
15
+ const path = useContext(BrowserWindowContext)
16
+ const browserWindow = browser.windows.find((w) => w.path === path)!
17
17
  const cb = useRef<Noop | void>()
18
18
 
19
19
  useEffect(() => {
@@ -37,21 +37,15 @@ export default function useWindowEffect(fn: () => Noop | void, deps: Array<any>)
37
37
  const deactivate = pre?.path === browserWindow.path
38
38
  if (activate) {
39
39
  cb.current = fn()
40
- console.log('activate', browserWindow.path)
40
+ // console.log('activate', browserWindow.path)
41
41
  }
42
42
  if (deactivate) {
43
43
  cb.current && cb.current()
44
- console.log('deactivate', browserWindow.path)
44
+ // console.log('deactivate', browserWindow.path)
45
45
  }
46
46
  }
47
- // { fireImmediately: true }
48
47
  )
49
48
  cb.current = fn()
50
- console.log('effect', browserWindow.path, deps)
51
- return () => {
52
- console.log('dispose', browserWindow.path)
53
- dispose()
54
- cb.current && cb.current()
55
- }
49
+ return dispose
56
50
  }, deps)
57
51
  }
@@ -14,7 +14,7 @@ export interface VBrowserWindow {
14
14
  export interface VBrowserProps {
15
15
  /** 窗口数量限制 */
16
16
  maxLength?: number
17
- /** 准备就绪 */
17
+ /** 准备就绪 (读取Storage) */
18
18
  onReady?: Function
19
19
  /** 重新打开vBrowser时恢复已打开窗口, 默认为true */
20
20
  restore?: boolean
@@ -64,7 +64,7 @@ const VBrowserContainer: FC<{ className?: string }> = observer(
64
64
  createPortal(
65
65
  pages.map((page, i) => {
66
66
  return (
67
- <BrowserWindowContext.Provider key={i} value={page}>
67
+ <BrowserWindowContext.Provider key={i} value={page.path}>
68
68
  <WindowWrapper key={i} path={page.path} />
69
69
  </BrowserWindowContext.Provider>
70
70
  )
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable dot-notation */
2
2
  import { get } from 'lodash'
3
3
  import { observer } from 'mobx-react'
4
- import React, { createRef, FC, useContext, useEffect } from 'react'
4
+ import React, { createRef, FC, lazy, Suspense, useContext, useEffect } from 'react'
5
+ import { Loading } from '../../loading'
5
6
  import { NProgress } from '../../n_progress'
6
7
  import BrowserContext from '../context/browser'
8
+ import BrowserWindowContext from '../context/browserWindow'
7
9
  import { CacheItem } from '../types'
8
10
  import { pages } from '../v_browser'
9
11
 
@@ -34,27 +36,27 @@ const WindowWrapper: FC<WindowWrapperProps> = ({ path }) => {
34
36
  const page = pages.find((p) => p.path === path)
35
37
  if (!page) throw new Error('[VBrowser] page not found: ' + path)
36
38
 
37
- NProgress.start()
38
- page
39
- .loader()
40
- .then((module) => {
41
- const Component = module.default
42
- const vNode = (
43
- <div
44
- className='v-browser-window-content'
45
- data-vbrowser-window={path}
46
- ref={createRef()}
47
- >
48
- <Component />
49
- </div>
50
- ) as CacheItem['vNode']
51
- browser['_setCache'](path, { vNode })
52
- browser['_fire']('show', w!)
53
- return null
54
- })
55
- .finally(() => {
56
- NProgress.done()
57
- })
39
+ const loading = (
40
+ <div className='tw-w-full tw-h-full tw-flex tw-items-center tw-justify-center'>
41
+ <Loading size='24' />
42
+ </div>
43
+ )
44
+ const Component = lazy(page.loader)
45
+ const vNode = (
46
+ <div
47
+ className='v-browser-window-content'
48
+ data-vbrowser-window={path}
49
+ ref={createRef()}
50
+ >
51
+ {/* <BrowserWindowContext.Provider value={page.path}> */}
52
+ <Suspense fallback={loading}>
53
+ <Component />
54
+ </Suspense>
55
+ {/* </BrowserWindowContext.Provider> */}
56
+ </div>
57
+ ) as CacheItem['vNode']
58
+ browser['_setCache'](path, { vNode })
59
+ browser['_fire']('show', w!)
58
60
  return
59
61
  }
60
62
 
@@ -15,7 +15,7 @@ export const pages = req.keys().map((key) => {
15
15
  }
16
16
  })
17
17
 
18
- const STORAGE_KEY = 'vbrowser-cache'
18
+ export const VBROWSER_STORAGE_KEY = 'gm_vbrowser-cache'
19
19
 
20
20
  type EventName = 'error' | 'change' | 'close' | 'show'
21
21
 
@@ -151,16 +151,18 @@ class VBrowser implements VBrowser {
151
151
  // #region 打开新浏览器窗口
152
152
  if (target === '_blank') {
153
153
  // 避免继承
154
- const currentCache = JSON.parse(sessionStorage.getItem(STORAGE_KEY) || '{}')
154
+ const currentCache = JSON.parse(
155
+ sessionStorage.getItem(VBROWSER_STORAGE_KEY) || '{}'
156
+ )
155
157
  const newCache = { windows: [] as VBrowserWindow[], activeIndex: 0 }
156
158
  newCache.windows.push(...this.windows.filter((w) => !w.closeable))
157
159
  newCache.windows.push(w)
158
160
  newCache.activeIndex = newCache.windows.findIndex(
159
161
  (item) => item.path === (w as VBrowserWindow).path
160
162
  )
161
- sessionStorage.setItem(STORAGE_KEY, JSON.stringify(newCache))
163
+ sessionStorage.setItem(VBROWSER_STORAGE_KEY, JSON.stringify(newCache))
162
164
  window.open(`#${w.path}?${stringify(w.query || {})}`, '_blank')
163
- sessionStorage.setItem(STORAGE_KEY, JSON.stringify(currentCache))
165
+ sessionStorage.setItem(VBROWSER_STORAGE_KEY, JSON.stringify(currentCache))
164
166
  }
165
167
  // #endregion
166
168
  }
@@ -219,14 +221,14 @@ class VBrowser implements VBrowser {
219
221
  windows,
220
222
  activeIndex: this.activeIndex,
221
223
  })
222
- sessionStorage.setItem(STORAGE_KEY, string)
224
+ sessionStorage.setItem(VBROWSER_STORAGE_KEY, string)
223
225
  }
224
226
 
225
227
  // 恢复已开窗口
226
228
  private async _loadStash() {
227
229
  await new Promise((resolve) => setTimeout(resolve, 100))
228
230
  const { windows = [], activeIndex = 0 } = JSON.parse(
229
- sessionStorage.getItem(STORAGE_KEY) || '{}'
231
+ sessionStorage.getItem(VBROWSER_STORAGE_KEY) || '{}'
230
232
  )
231
233
  if (windows.length === 0) return
232
234
  this.windows = windows