@blocklet/ui-react 2.11.37 → 2.11.39

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.
@@ -12,6 +12,7 @@ import InternalFooter from "./internal-footer.js";
12
12
  import { mapRecursive } from "../utils.js";
13
13
  import { formatBlockletInfo, getLocalizedNavigation } from "../blocklets.js";
14
14
  import { BlockletMetaProps } from "../types.js";
15
+ import withHideWhenEmbed from "../libs/with-hide-when-embed.js";
15
16
  function Footer({ meta, theme: themeOverrides, ...rest }) {
16
17
  const { locale } = useLocaleContext() || {};
17
18
  const formattedBlocklet = useMemo(() => {
@@ -77,6 +78,6 @@ const StyledInternalFooter = styled(InternalFooter)`
77
78
  font-family: Inter, Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,
78
79
  'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
79
80
  `;
80
- export default withErrorBoundary(Footer, {
81
+ export default withErrorBoundary(withHideWhenEmbed(Footer), {
81
82
  FallbackComponent: ErrorFallback
82
83
  });
@@ -15,6 +15,7 @@ import { mapRecursive, flatRecursive, matchPaths } from "../utils.js";
15
15
  import { publicPath, formatBlockletInfo, getLocalizedNavigation } from "../blocklets.js";
16
16
  import HeaderAddons from "../common/header-addons.js";
17
17
  import { useWalletHiddenTopbar } from "../common/wallet-hidden-topbar.js";
18
+ import withHideWhenEmbed from "../libs/with-hide-when-embed.js";
18
19
  const parseNavigation = (navigation) => {
19
20
  if (!navigation?.length) {
20
21
  return { navItems: [], activeId: null };
@@ -144,6 +145,6 @@ const StyledUxHeader = styled(ResponsiveHeader)`
144
145
  }
145
146
  }
146
147
  `;
147
- export default withErrorBoundary(Header, {
148
+ export default withErrorBoundary(withHideWhenEmbed(Header), {
148
149
  FallbackComponent: ErrorFallback
149
150
  });
@@ -33,10 +33,11 @@ const settingsLink = joinURL(PROFILE_URL, "/settings");
33
33
  const didSpacesLink = joinURL(PROFILE_URL, "/did-spaces");
34
34
  const Main = styled(Box)(({ theme }) => ({
35
35
  flex: 1,
36
+ boxSizing: "border-box",
37
+ padding: theme.spacing(3),
36
38
  width: "100%",
37
39
  maxWidth: 1200,
38
40
  margin: "0 auto",
39
- p: 3,
40
41
  display: "flex",
41
42
  alignItems: "stretch",
42
43
  gap: 2.5,
@@ -17,7 +17,7 @@ const hasNotification = () => {
17
17
  };
18
18
  export default function HeaderAddons({ formattedBlocklet, addons, sessionManagerProps }) {
19
19
  const sessionCtx = useContext(SessionContext);
20
- const { locale } = useLocaleContext() || {};
20
+ const { locale, languages } = useLocaleContext() || {};
21
21
  const { enableConnect = true, enableLocale = true } = formattedBlocklet;
22
22
  const authenticated = !!sessionCtx?.session?.user;
23
23
  let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.sessionManager, locale) || [];
@@ -30,7 +30,7 @@ export default function HeaderAddons({ formattedBlocklet, addons, sessionManager
30
30
  if (hasNotification()) {
31
31
  addonsArray.push(/* @__PURE__ */ jsx(NotificationAddon, { session: sessionCtx.session }, "notification-addon"));
32
32
  }
33
- if (enableLocale && locale) {
33
+ if (enableLocale && locale && languages.length > 1) {
34
34
  addonsArray.push(/* @__PURE__ */ jsx(LocaleSelector, { showText: false }, "locale-selector"));
35
35
  }
36
36
  if (enableConnect && sessionCtx) {
@@ -0,0 +1 @@
1
+ export declare const EMBED_MODE_KEY = "blocklet-ui-react-embed-mode";
@@ -0,0 +1 @@
1
+ export const EMBED_MODE_KEY = "blocklet-ui-react-embed-mode";
@@ -0,0 +1,4 @@
1
+ export default function withHideWhenEmbed<T extends object>(Component: React.ComponentType<T>): {
2
+ (props: T): import("react").JSX.Element | null;
3
+ displayName: string;
4
+ };
@@ -0,0 +1,19 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useSessionStorageState } from "ahooks";
3
+ import { EMBED_MODE_KEY } from "./constant.js";
4
+ export default function withHideWhenEmbed(Component) {
5
+ const displayName = Component.displayName || Component.name || "Component";
6
+ function WrappedComponent(props) {
7
+ const [embedMode] = useSessionStorageState(EMBED_MODE_KEY, {
8
+ defaultValue: 0,
9
+ listenStorageChange: true
10
+ });
11
+ const isEmbed = embedMode === 1;
12
+ if (isEmbed) {
13
+ return null;
14
+ }
15
+ return /* @__PURE__ */ jsx(Component, { ...props });
16
+ }
17
+ WrappedComponent.displayName = `withHideWhenEmbed(${displayName})`;
18
+ return WrappedComponent;
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.11.37",
3
+ "version": "2.11.39",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@abtnode/constant": "^1.16.38",
36
- "@arcblock/bridge": "^2.11.37",
37
- "@arcblock/react-hooks": "^2.11.37",
36
+ "@arcblock/bridge": "^2.11.39",
37
+ "@arcblock/react-hooks": "^2.11.39",
38
38
  "@arcblock/ws": "^1.19.9",
39
39
  "@blocklet/did-space-react": "^1.0.15",
40
40
  "@iconify-icons/logos": "^1.2.36",
@@ -84,5 +84,5 @@
84
84
  "jest": "^29.7.0",
85
85
  "unbuild": "^2.0.0"
86
86
  },
87
- "gitHead": "5b00e4fe7b54625734ce8e61e9ec41f35cb851ac"
87
+ "gitHead": "25c50d858ec85c90cefcbe43b4e841f039b0800a"
88
88
  }
@@ -12,7 +12,7 @@ import InternalFooter from './internal-footer';
12
12
  import { mapRecursive } from '../utils';
13
13
  import { formatBlockletInfo, getLocalizedNavigation } from '../blocklets';
14
14
  import { BlockletMetaProps } from '../types';
15
-
15
+ import withHideWhenEmbed from '../libs/with-hide-when-embed';
16
16
  /**
17
17
  * 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
18
18
  */
@@ -90,6 +90,6 @@ const StyledInternalFooter = styled(InternalFooter)`
90
90
  'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
91
91
  `;
92
92
 
93
- export default withErrorBoundary(Footer, {
93
+ export default withErrorBoundary(withHideWhenEmbed(Footer), {
94
94
  FallbackComponent: ErrorFallback,
95
95
  });
@@ -17,6 +17,7 @@ import { publicPath, formatBlockletInfo, getLocalizedNavigation } from '../block
17
17
  import HeaderAddons from '../common/header-addons';
18
18
  import { useWalletHiddenTopbar } from '../common/wallet-hidden-topbar';
19
19
  import { BlockletMetaProps, SessionManagerProps } from '../@types';
20
+ import withHideWhenEmbed from '../libs/with-hide-when-embed';
20
21
 
21
22
  // blocklet meta 中的 navigation 数据 => NavMenu 组件的 items
22
23
  const parseNavigation = (navigation: any) => {
@@ -193,6 +194,6 @@ const StyledUxHeader = styled(ResponsiveHeader)<StyledUxHeaderProps>`
193
194
  }
194
195
  `;
195
196
 
196
- export default withErrorBoundary(Header, {
197
+ export default withErrorBoundary(withHideWhenEmbed(Header), {
197
198
  FallbackComponent: ErrorFallback,
198
199
  });
@@ -41,10 +41,11 @@ const didSpacesLink = joinURL(PROFILE_URL, '/did-spaces');
41
41
 
42
42
  const Main = styled(Box)(({ theme }) => ({
43
43
  flex: 1,
44
+ boxSizing: 'border-box',
45
+ padding: theme.spacing(3),
44
46
  width: '100%',
45
47
  maxWidth: 1200,
46
48
  margin: '0 auto',
47
- p: 3,
48
49
  display: 'flex',
49
50
  alignItems: 'stretch',
50
51
  gap: 2.5,
@@ -21,7 +21,7 @@ const hasNotification = () => {
21
21
  // eslint-disable-next-line no-shadow
22
22
  export default function HeaderAddons({ formattedBlocklet, addons, sessionManagerProps }) {
23
23
  const sessionCtx = useContext(SessionContext);
24
- const { locale } = useLocaleContext() || {};
24
+ const { locale, languages } = useLocaleContext() || {};
25
25
  const { enableConnect = true, enableLocale = true } = formattedBlocklet;
26
26
  const authenticated = !!sessionCtx?.session?.user;
27
27
  let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.sessionManager, locale) || [];
@@ -38,8 +38,8 @@ export default function HeaderAddons({ formattedBlocklet, addons, sessionManager
38
38
  if (hasNotification()) {
39
39
  addonsArray.push(<NotificationAddon key="notification-addon" session={sessionCtx.session} />);
40
40
  }
41
- // 启用了多语言并且检测到了 locale context
42
- if (enableLocale && locale) {
41
+ // 启用了多语言,且检测到了 locale context,且有多种语言可以切换
42
+ if (enableLocale && locale && languages.length > 1) {
43
43
  addonsArray.push(<LocaleSelector key="locale-selector" showText={false} />);
44
44
  }
45
45
  // 启用了连接钱包并且检测到了 session context
@@ -0,0 +1 @@
1
+ export const EMBED_MODE_KEY = 'blocklet-ui-react-embed-mode';
@@ -0,0 +1,24 @@
1
+ import { useSessionStorageState } from 'ahooks';
2
+ import { EMBED_MODE_KEY } from './constant';
3
+
4
+ export default function withHideWhenEmbed<T extends object>(Component: React.ComponentType<T>) {
5
+ const displayName = Component.displayName || Component.name || 'Component';
6
+
7
+ function WrappedComponent(props: T) {
8
+ const [embedMode] = useSessionStorageState(EMBED_MODE_KEY, {
9
+ defaultValue: 0,
10
+ listenStorageChange: true,
11
+ });
12
+ const isEmbed = embedMode === 1;
13
+
14
+ if (isEmbed) {
15
+ return null;
16
+ }
17
+
18
+ return <Component {...props} />;
19
+ }
20
+
21
+ WrappedComponent.displayName = `withHideWhenEmbed(${displayName})`;
22
+
23
+ return WrappedComponent;
24
+ }