@blocklet/launcher-layout 2.13.69 → 3.0.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/lib/header.js CHANGED
@@ -1,184 +1,90 @@
1
- import Img from '@arcblock/ux/lib/Img';
2
- import styled from '@emotion/styled';
3
- import { Skeleton, useMediaQuery } from '@mui/material';
4
- import isEmpty from 'is-empty';
5
- import PropTypes from 'prop-types';
6
- import { useEffect, useRef, useState } from 'react';
7
- import joinUrl from 'url-join';
8
- import defaultBlockletLogo from './assets/blocklet-default-logo.png';
9
- import { getLaunchingText } from './locale';
10
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- const getBlockletDisplayName = blocklet => blocklet?.title || blocklet?.name || '';
12
- function AppHeader({
13
- blockletMeta,
14
- subTitle,
15
- logoUrl,
16
- locale,
17
- navLogo,
18
- loading
19
- }) {
20
- const isMobile = useMediaQuery(theme => theme.breakpoints.down('md'));
21
- const blockletSize = isMobile ? 18 : 48;
22
- const appNameRef = useRef(null);
23
- const [appNameSize, setAppNameSize] = useState('');
24
- useEffect(() => {
25
- if (appNameRef.current && appNameRef.current.offsetHeight > 34) {
26
- if (appNameSize === '') {
27
- setAppNameSize('middle');
28
- } else if (appNameSize === 'middle') {
29
- setAppNameSize('small');
30
- }
31
- }
32
- }, [appNameSize]);
33
- return /*#__PURE__*/_jsxs(Container, {
34
- className: appNameSize === 'small' ? 'center-mode' : '',
35
- children: [isMobile ? /*#__PURE__*/_jsx("div", {
36
- className: "app-icon",
37
- children: navLogo
38
- }) : /*#__PURE__*/_jsxs("div", {
39
- className: "app-icon",
40
- children: [loading && /*#__PURE__*/_jsx(AppIconSkeleton, {
41
- blockletSize: blockletSize,
42
- isMobile: isMobile
43
- }), !loading && /*#__PURE__*/_jsx(AppIcon, {
44
- blockletSize: blockletSize,
45
- logoUrl: logoUrl
46
- })]
47
- }), /*#__PURE__*/_jsxs("div", {
48
- className: "header-title",
49
- children: [isMobile && subTitle && /*#__PURE__*/_jsx("div", {
50
- className: "header-title-sub",
51
- children: subTitle
52
- }), /*#__PURE__*/_jsxs("div", {
53
- className: "app-name-content",
54
- children: [!isMobile && /*#__PURE__*/_jsx("div", {
55
- className: "launching-context",
56
- children: subTitle || getLaunchingText(locale)
57
- }), /*#__PURE__*/_jsx("div", {
58
- className: `header-title-name ${appNameSize === 'middle' || appNameSize === 'small' ? 'middle-size' : ''}`,
59
- ref: appNameRef,
60
- children: /*#__PURE__*/_jsx(AppTitle, {
61
- logoUrl: logoUrl,
62
- isMobile: isMobile,
63
- blockletMeta: blockletMeta,
64
- blockletSize: blockletSize,
65
- loading: loading
66
- })
67
- })]
68
- })]
69
- })]
70
- });
1
+ import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
+ import v from "@arcblock/ux/lib/Img";
3
+ import f from "@emotion/styled";
4
+ import { useMediaQuery as b, Skeleton as p } from "@mui/material";
5
+ import $ from "is-empty";
6
+ import o from "prop-types";
7
+ import { useRef as k, useState as N, useEffect as j } from "react";
8
+ import A from "url-join";
9
+ import S from "./assets/blocklet-default-logo.png";
10
+ import { getLaunchingText as z } from "./locale.js";
11
+ const g = (e) => (e == null ? void 0 : e.title) || (e == null ? void 0 : e.name) || "";
12
+ function T({ blockletMeta: e = {}, subTitle: n = "", logoUrl: i = "", locale: m = "", navLogo: d = "", loading: a = !1 }) {
13
+ const r = b((y) => y.breakpoints.down("md")), c = r ? 18 : 48, h = k(null), [s, x] = N("");
14
+ return j(() => {
15
+ h.current && h.current.offsetHeight > 34 && (s === "" ? x("middle") : s === "middle" && x("small"));
16
+ }, [s]), /* @__PURE__ */ l(R, { className: s === "small" ? "center-mode" : "", children: [
17
+ r ? /* @__PURE__ */ t("div", { className: "app-icon", children: d }) : /* @__PURE__ */ l("div", { className: "app-icon", children: [
18
+ a && /* @__PURE__ */ t(I, { blockletSize: c, isMobile: r }),
19
+ !a && /* @__PURE__ */ t(u, { blockletSize: c, logoUrl: i })
20
+ ] }),
21
+ /* @__PURE__ */ l("div", { className: "header-title", children: [
22
+ r && n && /* @__PURE__ */ t("div", { className: "header-title-sub", children: n }),
23
+ /* @__PURE__ */ l("div", { className: "app-name-content", children: [
24
+ !r && /* @__PURE__ */ t("div", { className: "launching-context", children: n || z(m) }),
25
+ /* @__PURE__ */ t(
26
+ "div",
27
+ {
28
+ className: `header-title-name ${s === "middle" || s === "small" ? "middle-size" : ""}`,
29
+ ref: h,
30
+ children: /* @__PURE__ */ t(
31
+ w,
32
+ {
33
+ logoUrl: i,
34
+ isMobile: r,
35
+ blockletMeta: e,
36
+ blockletSize: c,
37
+ loading: a
38
+ }
39
+ )
40
+ }
41
+ )
42
+ ] })
43
+ ] })
44
+ ] });
71
45
  }
72
- AppHeader.propTypes = {
73
- blockletMeta: PropTypes.object,
74
- subTitle: PropTypes.any,
75
- logoUrl: PropTypes.string,
76
- locale: PropTypes.string,
77
- navLogo: PropTypes.any,
78
- loading: PropTypes.bool
79
- };
80
- AppHeader.defaultProps = {
81
- subTitle: '',
82
- logoUrl: '',
83
- locale: '',
84
- navLogo: '',
85
- loading: false,
86
- blockletMeta: {}
46
+ T.propTypes = {
47
+ blockletMeta: o.object,
48
+ subTitle: o.any,
49
+ logoUrl: o.string,
50
+ locale: o.string,
51
+ navLogo: o.any,
52
+ loading: o.bool
87
53
  };
88
-
89
- // eslint-disable-next-line react/prop-types
90
- function AppIconSkeleton({
91
- blockletSize,
92
- isMobile
93
- }) {
94
- if (isMobile) {
95
- return /*#__PURE__*/_jsx(Skeleton, {
96
- variant: "rectangular",
97
- width: 100,
98
- height: 16,
99
- alt: "icon",
100
- style: {
101
- marginTop: 4
102
- }
103
- });
104
- }
105
- return /*#__PURE__*/_jsx(Skeleton, {
106
- variant: "rectangular",
107
- width: blockletSize,
108
- height: blockletSize
109
- });
54
+ function I({ blockletSize: e, isMobile: n }) {
55
+ return n ? /* @__PURE__ */ t(p, { variant: "rectangular", width: 100, height: 16, alt: "icon", style: { marginTop: 4 } }) : /* @__PURE__ */ t(p, { variant: "rectangular", width: e, height: e });
110
56
  }
111
-
112
- // eslint-disable-next-line react/prop-types
113
- function AppIcon({
114
- logoUrl,
115
- blockletSize
116
- }) {
117
- return /*#__PURE__*/_jsx(Img, {
118
- // force update
119
- width: blockletSize,
120
- height: blockletSize,
121
- src: logoUrl,
122
- alt: "blocklet icon",
123
- fallback: defaultBlockletLogo,
124
- style: {
125
- verticalAlign: 'text-bottom'
126
- }
127
- }, `layout-app-icon-${logoUrl}`);
57
+ function u({ logoUrl: e, blockletSize: n }) {
58
+ return /* @__PURE__ */ t(
59
+ v,
60
+ {
61
+ width: n,
62
+ height: n,
63
+ src: e,
64
+ alt: "blocklet icon",
65
+ fallback: S,
66
+ style: { verticalAlign: "text-bottom" }
67
+ },
68
+ `layout-app-icon-${e}`
69
+ );
128
70
  }
129
-
130
- // eslint-disable-next-line react/prop-types
131
- function AppTitle({
132
- isMobile,
133
- logoUrl,
134
- blockletMeta,
135
- blockletSize,
136
- loading
137
- }) {
138
- const name = getBlockletDisplayName(blockletMeta);
139
- if (loading) {
140
- return /*#__PURE__*/_jsx(Skeleton, {
141
- variant: "rectangular",
142
- width: 100,
143
- height: 16,
144
- alt: "icon",
145
- style: {
146
- marginTop: 4
147
- }
148
- });
149
- }
150
- if (isEmpty(blockletMeta)) {
151
- return /*#__PURE__*/_jsx(Skeleton, {
152
- variant: "rectangular",
153
- animation: false,
154
- width: 100,
155
- height: 16,
156
- alt: "icon",
157
- style: {
158
- marginTop: 4
159
- }
160
- });
161
- }
162
- if (isMobile) {
163
- return /*#__PURE__*/_jsxs(MobileTitleStyle, {
164
- children: [/*#__PURE__*/_jsx(AppIcon, {
165
- blockletSize: blockletSize,
166
- logoUrl: logoUrl
167
- }), /*#__PURE__*/_jsx("span", {
168
- className: "ellipsis-title",
169
- children: getBlockletDisplayName(blockletMeta)
170
- })]
171
- });
172
- }
173
- return /*#__PURE__*/_jsx(AppLink, {
174
- className: "app-link",
175
- target: "_blank",
176
- href: joinUrl(blockletMeta?.registryUrl || '', `/blocklets/${blockletMeta?.did}`),
177
- title: name,
178
- children: name
179
- });
71
+ function w({ isMobile: e, logoUrl: n, blockletMeta: i = {}, blockletSize: m, loading: d }) {
72
+ const a = g(i);
73
+ return d ? /* @__PURE__ */ t(p, { variant: "rectangular", width: 100, height: 16, alt: "icon", style: { marginTop: 4 } }) : $(i) ? /* @__PURE__ */ t(p, { variant: "rectangular", animation: !1, width: 100, height: 16, alt: "icon", style: { marginTop: 4 } }) : e ? /* @__PURE__ */ l(L, { children: [
74
+ /* @__PURE__ */ t(u, { blockletSize: m, logoUrl: n }),
75
+ /* @__PURE__ */ t("span", { className: "ellipsis-title", children: g(i) })
76
+ ] }) : /* @__PURE__ */ t(
77
+ E,
78
+ {
79
+ className: "app-link",
80
+ target: "_blank",
81
+ href: A((i == null ? void 0 : i.registryUrl) || "", `/blocklets/${i == null ? void 0 : i.did}`),
82
+ title: a,
83
+ children: a
84
+ }
85
+ );
180
86
  }
181
- const MobileTitleStyle = styled.div`
87
+ const L = f.div`
182
88
  .ellipsis-title {
183
89
  flex: 1;
184
90
  position: absolute;
@@ -190,21 +96,17 @@ const MobileTitleStyle = styled.div`
190
96
  overflow: hidden;
191
97
  text-overflow: ellipsis;
192
98
 
193
- ${props => props.theme.breakpoints.down('md')} {
99
+ ${(e) => e.theme.breakpoints.down("md")} {
194
100
  left: 26px;
195
101
  width: calc(100% - 26px);
196
102
  }
197
103
  }
198
104
  `;
199
- AppTitle.propTypes = {
200
- blockletMeta: PropTypes.object
105
+ w.propTypes = {
106
+ blockletMeta: o.object
201
107
  };
202
- AppTitle.defaultProps = {
203
- blockletMeta: {}
204
- };
205
- export default AppHeader;
206
- const AppLink = styled.a`
207
- color: ${props => props.theme.palette.text.primary};
108
+ const E = f.a`
109
+ color: ${(e) => e.theme.palette.text.primary};
208
110
  text-decoration: none;
209
111
  overflow: hidden;
210
112
  text-overflow: ellipsis;
@@ -228,23 +130,22 @@ const AppLink = styled.a`
228
130
  font-weight: 700;
229
131
  -webkit-font-smoothing: antialiased;
230
132
 
231
- ${props => props.theme.breakpoints.down('md')} {
133
+ ${(e) => e.theme.breakpoints.down("md")} {
232
134
  display: block;
233
135
  max-width: calc(100vw - 150px);
234
136
  white-space: nowrap;
235
137
  overflow: hidden;
236
138
  text-overflow: ellipsis;
237
139
  }
238
- `;
239
- const Container = styled.div`
140
+ `, R = f.div`
240
141
  display: flex;
241
142
  justify-content: flex-start;
242
143
  align-items: flex-start;
243
144
  width: 100%;
244
- ${props => props.theme.breakpoints.up('md')} {
145
+ ${(e) => e.theme.breakpoints.up("md")} {
245
146
  min-height: 70px;
246
147
  }
247
- ${props => props.theme.breakpoints.down('md')} {
148
+ ${(e) => e.theme.breakpoints.down("md")} {
248
149
  align-items: center;
249
150
  }
250
151
  .app-name-content {
@@ -252,11 +153,11 @@ const Container = styled.div`
252
153
  display: flex;
253
154
  align-items: center;
254
155
  justify-content: center;
255
- ${props => props.theme.breakpoints.up('md')} {
156
+ ${(e) => e.theme.breakpoints.up("md")} {
256
157
  align-items: flex-start;
257
158
  flex-direction: column;
258
159
  }
259
- ${props => props.theme.breakpoints.down('md')} {
160
+ ${(e) => e.theme.breakpoints.down("md")} {
260
161
  justify-content: flex-start;
261
162
  height: 22px;
262
163
  }
@@ -265,11 +166,11 @@ const Container = styled.div`
265
166
  flex-shrink: 0;
266
167
  font-size: 14px;
267
168
  font-weight: 600;
268
- color: ${props => props.theme.palette.text.secondary};
269
- ${props => props.theme.breakpoints.up('md')} {
169
+ color: ${(e) => e.theme.palette.text.secondary};
170
+ ${(e) => e.theme.breakpoints.up("md")} {
270
171
  margin-bottom: 4px;
271
172
  }
272
- ${props => props.theme.breakpoints.down('md')} {
173
+ ${(e) => e.theme.breakpoints.down("md")} {
273
174
  font-size: 14px;
274
175
  line-height: 15px;
275
176
  &:after {
@@ -283,7 +184,7 @@ const Container = styled.div`
283
184
  &.center-mode {
284
185
  align-items: flex-start;
285
186
  .launching-context {
286
- ${props => props.theme.breakpoints.up('sm')} {
187
+ ${(e) => e.theme.breakpoints.up("sm")} {
287
188
  margin-bottom: 0;
288
189
  }
289
190
  }
@@ -304,7 +205,7 @@ const Container = styled.div`
304
205
  justify-content: space-around;
305
206
  align-items: flex-start;
306
207
  margin-left: 24px;
307
- ${props => props.theme.breakpoints.down('md')} {
208
+ ${(e) => e.theme.breakpoints.down("md")} {
308
209
  margin-left: 16px;
309
210
  }
310
211
  .header-title-name {
@@ -314,16 +215,16 @@ const Container = styled.div`
314
215
  align-items: center;
315
216
  flex: 1;
316
217
  height: 100%;
317
- color: ${props => props.theme.palette.text.primary};
218
+ color: ${(e) => e.theme.palette.text.primary};
318
219
  font-weight: 700;
319
- ${props => props.theme.breakpoints.up('sm')} {
220
+ ${(e) => e.theme.breakpoints.up("sm")} {
320
221
  font-size: 18px;
321
222
 
322
223
  &.middle-size {
323
224
  font-size: 16px;
324
225
  }
325
226
  }
326
- ${props => props.theme.breakpoints.down('md')} {
227
+ ${(e) => e.theme.breakpoints.down("md")} {
327
228
  display: block;
328
229
  max-width: calc(100vw - 100px);
329
230
  font-size: 16px;
@@ -334,15 +235,18 @@ const Container = styled.div`
334
235
  }
335
236
 
336
237
  .header-title-sub {
337
- color: ${props => props.theme.palette.grey[700]};
238
+ color: ${(e) => e.theme.palette.grey[700]};
338
239
  font-size: 12px;
339
240
  line-height: 16px;
340
241
 
341
- ${props => props.theme.breakpoints.down('md')} {
242
+ ${(e) => e.theme.breakpoints.down("md")} {
342
243
  white-space: nowrap;
343
244
  overflow: hidden;
344
245
  text-overflow: ellipsis;
345
246
  }
346
247
  }
347
248
  }
348
- `;
249
+ `;
250
+ export {
251
+ T as default
252
+ };