@arcblock/ux 2.12.6 → 2.12.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.
@@ -1,6 +1,7 @@
|
|
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';
|
4
5
|
const BlockletContext = /*#__PURE__*/createContext(null);
|
5
6
|
const {
|
6
7
|
Provider,
|
@@ -12,19 +13,16 @@ function BlockletProvider({
|
|
12
13
|
loading = null
|
13
14
|
}) {
|
14
15
|
const [blockletData, setBlockletData] = useState(null);
|
15
|
-
const
|
16
|
+
const getBlockleDataWithCache = useMemoizedFn(async () => {
|
16
17
|
if (!baseUrl || window.location.href.startsWith(baseUrl)) {
|
17
18
|
throw new Error('no blocklet data');
|
18
19
|
}
|
19
|
-
const
|
20
|
-
url.searchParams.set('type', 'json');
|
21
|
-
const res = await fetch(url.href);
|
22
|
-
const jsonData = await res.json();
|
20
|
+
const jsonData = await getBlockletData(baseUrl);
|
23
21
|
return jsonData;
|
24
22
|
});
|
25
23
|
useAsyncEffect(async () => {
|
26
24
|
try {
|
27
|
-
const data = await
|
25
|
+
const data = await getBlockleDataWithCache();
|
28
26
|
setBlockletData(data);
|
29
27
|
} catch {
|
30
28
|
// NOTICE: 如果获取指定 blockletData 失败,则使用 window.blocklet
|
package/lib/Util/federated.d.ts
CHANGED
@@ -61,4 +61,4 @@ export declare function getApps(blocklet: Blocklet): ({
|
|
61
61
|
appPid?: undefined;
|
62
62
|
version?: undefined;
|
63
63
|
})[];
|
64
|
-
export declare function getBlockletData(appUrl: string): Promise<
|
64
|
+
export declare function getBlockletData(appUrl: string, force?: boolean): Promise<Blocklet | null>;
|
package/lib/Util/federated.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import isEmpty from 'lodash/isEmpty';
|
2
|
+
const cacheBlockletData = {};
|
2
3
|
export function getMaster(blocklet = window.blocklet) {
|
3
4
|
const federated = blocklet?.settings?.federated || {};
|
4
5
|
return federated.master;
|
@@ -83,12 +84,16 @@ export function getApps(blocklet) {
|
|
83
84
|
// NOTICE: masterApp 应该排在前面
|
84
85
|
return appList.reverse();
|
85
86
|
}
|
86
|
-
export async function getBlockletData(appUrl) {
|
87
|
+
export async function getBlockletData(appUrl, force = false) {
|
88
|
+
if (!force && cacheBlockletData[appUrl]) {
|
89
|
+
return cacheBlockletData[appUrl];
|
90
|
+
}
|
87
91
|
try {
|
88
92
|
const url = new URL('__blocklet__.js', appUrl);
|
89
93
|
url.searchParams.set('type', 'json');
|
90
94
|
const res = await fetch(url.href);
|
91
95
|
const jsonData = await res.json();
|
96
|
+
cacheBlockletData[appUrl] = jsonData;
|
92
97
|
return jsonData;
|
93
98
|
} catch (err) {
|
94
99
|
console.error(`Failed to get blocklet data: ${appUrl}`, err);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.12.
|
3
|
+
"version": "2.12.8",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -68,12 +68,12 @@
|
|
68
68
|
"react": ">=18.2.0",
|
69
69
|
"react-router-dom": ">=6.22.3"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "4cfeed31d56495f1368b96adfae11f938e68ef46",
|
72
72
|
"dependencies": {
|
73
73
|
"@arcblock/did-motif": "^1.1.13",
|
74
|
-
"@arcblock/icons": "^2.12.
|
75
|
-
"@arcblock/nft-display": "^2.12.
|
76
|
-
"@arcblock/react-hooks": "^2.12.
|
74
|
+
"@arcblock/icons": "^2.12.8",
|
75
|
+
"@arcblock/nft-display": "^2.12.8",
|
76
|
+
"@arcblock/react-hooks": "^2.12.8",
|
77
77
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
78
78
|
"@fontsource/inter": "^5.0.16",
|
79
79
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -1,6 +1,7 @@
|
|
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
5
|
|
5
6
|
const BlockletContext = createContext<Blocklet | null>(null);
|
6
7
|
|
@@ -19,21 +20,17 @@ function BlockletProvider({
|
|
19
20
|
loading?: React.ReactNode;
|
20
21
|
}) {
|
21
22
|
const [blockletData, setBlockletData] = useState<Blocklet | null>(null);
|
22
|
-
const
|
23
|
+
const getBlockleDataWithCache = useMemoizedFn(async () => {
|
23
24
|
if (!baseUrl || window.location.href.startsWith(baseUrl)) {
|
24
25
|
throw new Error('no blocklet data');
|
25
26
|
}
|
26
|
-
|
27
|
-
|
28
|
-
url.searchParams.set('type', 'json');
|
29
|
-
const res = await fetch(url.href);
|
30
|
-
const jsonData = await res.json();
|
31
|
-
return jsonData as Blocklet;
|
27
|
+
const jsonData = await getBlockletData(baseUrl);
|
28
|
+
return jsonData;
|
32
29
|
});
|
33
30
|
|
34
31
|
useAsyncEffect(async () => {
|
35
32
|
try {
|
36
|
-
const data = await
|
33
|
+
const data = await getBlockleDataWithCache();
|
37
34
|
setBlockletData(data);
|
38
35
|
} catch {
|
39
36
|
// NOTICE: 如果获取指定 blockletData 失败,则使用 window.blocklet
|
package/src/Util/federated.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import isEmpty from 'lodash/isEmpty';
|
2
2
|
|
3
|
+
const cacheBlockletData: Record<string, any> = {};
|
4
|
+
|
3
5
|
export function getMaster(blocklet = window.blocklet) {
|
4
6
|
const federated = blocklet?.settings?.federated || {};
|
5
7
|
return federated.master;
|
@@ -95,12 +97,16 @@ export function getApps(blocklet: Blocklet) {
|
|
95
97
|
return appList.reverse();
|
96
98
|
}
|
97
99
|
|
98
|
-
export async function getBlockletData(appUrl: string) {
|
100
|
+
export async function getBlockletData(appUrl: string, force = false): Promise<Blocklet | null> {
|
101
|
+
if (!force && cacheBlockletData[appUrl]) {
|
102
|
+
return cacheBlockletData[appUrl];
|
103
|
+
}
|
99
104
|
try {
|
100
105
|
const url = new URL('__blocklet__.js', appUrl);
|
101
106
|
url.searchParams.set('type', 'json');
|
102
107
|
const res = await fetch(url.href);
|
103
108
|
const jsonData = await res.json();
|
109
|
+
cacheBlockletData[appUrl] = jsonData;
|
104
110
|
return jsonData;
|
105
111
|
} catch (err) {
|
106
112
|
console.error(`Failed to get blocklet data: ${appUrl}`, err);
|