@arcblock/ux 2.12.53 → 2.12.54

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.
@@ -1,6 +1,12 @@
1
1
  import type { Blocklet } from '../type';
2
- declare const BlockletContext: import("react").Context<Blocklet | null>;
3
- declare const Consumer: import("react").Consumer<Blocklet | null>;
2
+ declare const BlockletContext: import("react").Context<{
3
+ blocklet: Blocklet | null;
4
+ masterBlocklet: Blocklet | null;
5
+ }>;
6
+ declare const Consumer: import("react").Consumer<{
7
+ blocklet: Blocklet | null;
8
+ masterBlocklet: Blocklet | null;
9
+ }>;
4
10
  declare function BlockletProvider({ children, baseUrl, loading, }: {
5
11
  children?: React.ReactNode;
6
12
  /**
@@ -11,5 +17,6 @@ declare function BlockletProvider({ children, baseUrl, loading, }: {
11
17
  }): import("react/jsx-runtime").JSX.Element;
12
18
  declare function useBlockletContext(): {
13
19
  blocklet: Blocklet | null;
20
+ masterBlocklet: Blocklet | null;
14
21
  };
15
22
  export { BlockletContext, BlockletProvider, Consumer as BlockletConsumer, useBlockletContext };
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useMemoizedFn, useAsyncEffect } from 'ahooks';
3
3
  import { createContext, useContext, useState } from 'react';
4
- import { getBlockletData } from '../Util/federated';
5
- const BlockletContext = /*#__PURE__*/createContext(null);
4
+ import { getBlockletData, getFederatedEnabled, getMaster } from '../Util/federated';
5
+ const BlockletContext = /*#__PURE__*/createContext({
6
+ blocklet: null,
7
+ masterBlocklet: null
8
+ });
6
9
  const {
7
10
  Provider,
8
11
  Consumer
@@ -13,6 +16,7 @@ function BlockletProvider({
13
16
  loading = null
14
17
  }) {
15
18
  const [blockletData, setBlockletData] = useState(null);
19
+ const [masterBlockletData, setMasterBlockletData] = useState(null);
16
20
  const getBlockleDataWithCache = useMemoizedFn(async () => {
17
21
  if (!baseUrl || window.location.href.startsWith(baseUrl)) {
18
22
  throw new Error('no blocklet data');
@@ -21,25 +25,43 @@ function BlockletProvider({
21
25
  return jsonData;
22
26
  });
23
27
  useAsyncEffect(async () => {
28
+ let result = null;
29
+ let resultMaster = null;
24
30
  try {
25
- const data = await getBlockleDataWithCache();
26
- setBlockletData(data);
31
+ result = await getBlockleDataWithCache();
27
32
  } catch {
28
33
  // NOTICE: 如果获取指定 blockletData 失败,则使用 window.blocklet
29
34
  const data = globalThis.blocklet || globalThis.env;
30
- setBlockletData(data);
35
+ result = data;
31
36
  }
37
+ if (result) {
38
+ if (getFederatedEnabled(result)) {
39
+ const masterSite = getMaster(result);
40
+ if (masterSite) {
41
+ resultMaster = await getBlockletData(masterSite.appUrl);
42
+ }
43
+ }
44
+ }
45
+ setBlockletData(result);
46
+ setMasterBlockletData(resultMaster);
32
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
48
  }, [baseUrl]);
34
49
  return /*#__PURE__*/_jsx(Provider, {
35
- value: blockletData,
50
+ value: {
51
+ blocklet: blockletData,
52
+ masterBlocklet: masterBlockletData
53
+ },
36
54
  children: blockletData ? children : loading || null
37
55
  });
38
56
  }
39
57
  function useBlockletContext() {
40
- const blocklet = useContext(BlockletContext);
58
+ const {
59
+ blocklet,
60
+ masterBlocklet
61
+ } = useContext(BlockletContext);
41
62
  return {
42
- blocklet
63
+ blocklet,
64
+ masterBlocklet
43
65
  };
44
66
  }
45
67
  export { BlockletContext, BlockletProvider, Consumer as BlockletConsumer, useBlockletContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.12.53",
3
+ "version": "2.12.54",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -69,12 +69,12 @@
69
69
  "react": ">=18.2.0",
70
70
  "react-router-dom": ">=6.22.3"
71
71
  },
72
- "gitHead": "454c63f6d9b58724fa0176ac74de2f306b53207c",
72
+ "gitHead": "fa8ee46123aa7dc5b6a79a9c75d08cb43857ad2c",
73
73
  "dependencies": {
74
74
  "@arcblock/did-motif": "^1.1.13",
75
- "@arcblock/icons": "^2.12.53",
76
- "@arcblock/nft-display": "^2.12.53",
77
- "@arcblock/react-hooks": "^2.12.53",
75
+ "@arcblock/icons": "^2.12.54",
76
+ "@arcblock/nft-display": "^2.12.54",
77
+ "@arcblock/react-hooks": "^2.12.54",
78
78
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
79
79
  "@fontsource/inter": "^5.0.16",
80
80
  "@fontsource/ubuntu-mono": "^5.0.18",
@@ -1,9 +1,15 @@
1
1
  import { useMemoizedFn, useAsyncEffect } from 'ahooks';
2
2
  import { createContext, useContext, useState } from 'react';
3
3
  import type { Blocklet } from '../type';
4
- import { getBlockletData } from '../Util/federated';
4
+ import { getBlockletData, getFederatedEnabled, getMaster } from '../Util/federated';
5
5
 
6
- const BlockletContext = createContext<Blocklet | null>(null);
6
+ const BlockletContext = createContext<{
7
+ blocklet: Blocklet | null;
8
+ masterBlocklet: Blocklet | null;
9
+ }>({
10
+ blocklet: null,
11
+ masterBlocklet: null,
12
+ });
7
13
 
8
14
  const { Provider, Consumer } = BlockletContext;
9
15
 
@@ -20,6 +26,7 @@ function BlockletProvider({
20
26
  loading?: React.ReactNode;
21
27
  }) {
22
28
  const [blockletData, setBlockletData] = useState<Blocklet | null>(null);
29
+ const [masterBlockletData, setMasterBlockletData] = useState<Blocklet | null>(null);
23
30
  const getBlockleDataWithCache = useMemoizedFn(async () => {
24
31
  if (!baseUrl || window.location.href.startsWith(baseUrl)) {
25
32
  throw new Error('no blocklet data');
@@ -29,22 +36,37 @@ function BlockletProvider({
29
36
  });
30
37
 
31
38
  useAsyncEffect(async () => {
39
+ let result = null;
40
+ let resultMaster = null;
32
41
  try {
33
- const data = await getBlockleDataWithCache();
34
- setBlockletData(data);
42
+ result = await getBlockleDataWithCache();
35
43
  } catch {
36
44
  // NOTICE: 如果获取指定 blockletData 失败,则使用 window.blocklet
37
45
  const data = globalThis.blocklet || globalThis.env;
38
- setBlockletData(data);
46
+ result = data;
39
47
  }
48
+ if (result) {
49
+ if (getFederatedEnabled(result)) {
50
+ const masterSite = getMaster(result);
51
+ if (masterSite) {
52
+ resultMaster = await getBlockletData(masterSite.appUrl);
53
+ }
54
+ }
55
+ }
56
+ setBlockletData(result);
57
+ setMasterBlockletData(resultMaster);
40
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
41
59
  }, [baseUrl]);
42
- return <Provider value={blockletData}>{blockletData ? children : loading || null}</Provider>;
60
+ return (
61
+ <Provider value={{ blocklet: blockletData, masterBlocklet: masterBlockletData }}>
62
+ {blockletData ? children : loading || null}
63
+ </Provider>
64
+ );
43
65
  }
44
66
 
45
67
  function useBlockletContext() {
46
- const blocklet = useContext(BlockletContext);
47
- return { blocklet };
68
+ const { blocklet, masterBlocklet } = useContext(BlockletContext);
69
+ return { blocklet, masterBlocklet };
48
70
  }
49
71
 
50
72
  export { BlockletContext, BlockletProvider, Consumer as BlockletConsumer, useBlockletContext };