@blocklet/launcher-layout 2.3.19 → 2.3.21

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,38 +1,27 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _Img = _interopRequireDefault(require("@arcblock/ux/lib/Img"));
8
- var _util = require("@blocklet/launcher-util/es/util");
9
- var _styled = _interopRequireDefault(require("@emotion/styled"));
10
- var _Skeleton = _interopRequireDefault(require("@mui/material/Skeleton"));
11
- var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
12
- var _isEmpty = _interopRequireDefault(require("is-empty"));
13
- var _propTypes = _interopRequireDefault(require("prop-types"));
14
- var _react = require("react");
15
- var _urlJoin = _interopRequireDefault(require("url-join"));
16
- var _blockletDefaultLogo = _interopRequireDefault(require("./assets/blocklet-default-logo.png"));
17
- var _locale = require("./locale");
18
- var _jsxRuntime = require("react/jsx-runtime");
19
- var _templateObject, _templateObject2, _templateObject3;
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
22
- function AppHeader(_ref) {
23
- let {
24
- blockletMeta,
25
- subTitle,
26
- logoUrl,
27
- locale,
28
- navLogo,
29
- loading
30
- } = _ref;
31
- const isMobile = (0, _useMediaQuery.default)(theme => theme.breakpoints.down('md'));
1
+ import Img from '@arcblock/ux/lib/Img';
2
+ import { getBlockletDisplayName } from '@blocklet/launcher-util/es/util';
3
+ import styled from '@emotion/styled';
4
+ import { Skeleton, useMediaQuery } from '@mui/material';
5
+ import isEmpty from 'is-empty';
6
+ import PropTypes from 'prop-types';
7
+ import { useEffect, useRef, useState } from 'react';
8
+ import joinUrl from 'url-join';
9
+ import defaultBlockletLogo from './assets/blocklet-default-logo.png';
10
+ import { getLaunchingText } from './locale';
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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'));
32
21
  const blockletSize = isMobile ? 18 : 48;
33
- const appNameRef = (0, _react.useRef)(null);
34
- const [appNameSize, setAppNameSize] = (0, _react.useState)('');
35
- (0, _react.useEffect)(() => {
22
+ const appNameRef = useRef(null);
23
+ const [appNameSize, setAppNameSize] = useState('');
24
+ useEffect(() => {
36
25
  if (appNameRef.current && appNameRef.current.offsetHeight > 34) {
37
26
  if (appNameSize === '') {
38
27
  setAppNameSize('middle');
@@ -41,34 +30,34 @@ function AppHeader(_ref) {
41
30
  }
42
31
  }
43
32
  }, [appNameSize]);
44
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
33
+ return /*#__PURE__*/_jsxs(Container, {
45
34
  className: appNameSize === 'small' ? 'center-mode' : '',
46
- children: [isMobile ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
35
+ children: [isMobile ? /*#__PURE__*/_jsx("div", {
47
36
  className: "app-icon",
48
37
  children: navLogo
49
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
38
+ }) : /*#__PURE__*/_jsxs("div", {
50
39
  className: "app-icon",
51
- children: [loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(AppIconSkeleton, {
40
+ children: [loading && /*#__PURE__*/_jsx(AppIconSkeleton, {
52
41
  blockletSize: blockletSize,
53
42
  isMobile: isMobile
54
- }), !loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(AppIcon, {
43
+ }), !loading && /*#__PURE__*/_jsx(AppIcon, {
55
44
  blockletSize: blockletSize,
56
45
  logoUrl: logoUrl
57
46
  })]
58
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
47
+ }), /*#__PURE__*/_jsxs("div", {
59
48
  className: "header-title",
60
- children: [isMobile && subTitle && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
49
+ children: [isMobile && subTitle && /*#__PURE__*/_jsx("div", {
61
50
  className: "header-title-sub",
62
51
  children: subTitle
63
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
52
+ }), /*#__PURE__*/_jsxs("div", {
64
53
  className: "app-name-content",
65
- children: [!isMobile && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
54
+ children: [!isMobile && /*#__PURE__*/_jsx("div", {
66
55
  className: "launching-context",
67
- children: subTitle || (0, _locale.getLaunchingText)(locale)
68
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
69
- className: "header-title-name ".concat(appNameSize === 'middle' || appNameSize === 'small' ? 'middle-size' : ''),
56
+ children: subTitle || getLaunchingText(locale)
57
+ }), /*#__PURE__*/_jsx("div", {
58
+ className: `header-title-name ${appNameSize === 'middle' || appNameSize === 'small' ? 'middle-size' : ''}`,
70
59
  ref: appNameRef,
71
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AppTitle, {
60
+ children: /*#__PURE__*/_jsx(AppTitle, {
72
61
  logoUrl: logoUrl,
73
62
  isMobile: isMobile,
74
63
  blockletMeta: blockletMeta,
@@ -81,12 +70,12 @@ function AppHeader(_ref) {
81
70
  });
82
71
  }
83
72
  AppHeader.propTypes = {
84
- blockletMeta: _propTypes.default.object,
85
- subTitle: _propTypes.default.any,
86
- logoUrl: _propTypes.default.string,
87
- locale: _propTypes.default.string,
88
- navLogo: _propTypes.default.any,
89
- loading: _propTypes.default.bool
73
+ blockletMeta: PropTypes.object,
74
+ subTitle: PropTypes.any,
75
+ logoUrl: PropTypes.string,
76
+ locale: PropTypes.string,
77
+ navLogo: PropTypes.any,
78
+ loading: PropTypes.bool
90
79
  };
91
80
  AppHeader.defaultProps = {
92
81
  subTitle: '',
@@ -98,13 +87,12 @@ AppHeader.defaultProps = {
98
87
  };
99
88
 
100
89
  // eslint-disable-next-line react/prop-types
101
- function AppIconSkeleton(_ref2) {
102
- let {
103
- blockletSize,
104
- isMobile
105
- } = _ref2;
90
+ function AppIconSkeleton({
91
+ blockletSize,
92
+ isMobile
93
+ }) {
106
94
  if (isMobile) {
107
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
95
+ return /*#__PURE__*/_jsx(Skeleton, {
108
96
  variant: "rectangular",
109
97
  width: 100,
110
98
  height: 16,
@@ -114,7 +102,7 @@ function AppIconSkeleton(_ref2) {
114
102
  }
115
103
  });
116
104
  }
117
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
105
+ return /*#__PURE__*/_jsx(Skeleton, {
118
106
  variant: "rectangular",
119
107
  width: blockletSize,
120
108
  height: blockletSize
@@ -122,36 +110,34 @@ function AppIconSkeleton(_ref2) {
122
110
  }
123
111
 
124
112
  // eslint-disable-next-line react/prop-types
125
- function AppIcon(_ref3) {
126
- let {
127
- logoUrl,
128
- blockletSize
129
- } = _ref3;
130
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Img.default, {
113
+ function AppIcon({
114
+ logoUrl,
115
+ blockletSize
116
+ }) {
117
+ return /*#__PURE__*/_jsx(Img, {
131
118
  // force update
132
119
  width: blockletSize,
133
120
  height: blockletSize,
134
121
  src: logoUrl,
135
122
  alt: "blocklet icon",
136
- fallback: _blockletDefaultLogo.default,
123
+ fallback: defaultBlockletLogo,
137
124
  style: {
138
125
  verticalAlign: 'text-bottom'
139
126
  }
140
- }, "layout-app-icon-".concat(logoUrl));
127
+ }, `layout-app-icon-${logoUrl}`);
141
128
  }
142
129
 
143
130
  // eslint-disable-next-line react/prop-types
144
- function AppTitle(_ref4) {
145
- let {
146
- isMobile,
147
- logoUrl,
148
- blockletMeta,
149
- blockletSize,
150
- loading
151
- } = _ref4;
152
- const name = (0, _util.getBlockletDisplayName)(blockletMeta);
131
+ function AppTitle({
132
+ isMobile,
133
+ logoUrl,
134
+ blockletMeta,
135
+ blockletSize,
136
+ loading
137
+ }) {
138
+ const name = getBlockletDisplayName(blockletMeta);
153
139
  if (loading) {
154
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
140
+ return /*#__PURE__*/_jsx(Skeleton, {
155
141
  variant: "rectangular",
156
142
  width: 100,
157
143
  height: 16,
@@ -161,8 +147,8 @@ function AppTitle(_ref4) {
161
147
  }
162
148
  });
163
149
  }
164
- if ((0, _isEmpty.default)(blockletMeta)) {
165
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
150
+ if (isEmpty(blockletMeta)) {
151
+ return /*#__PURE__*/_jsx(Skeleton, {
166
152
  variant: "rectangular",
167
153
  animation: false,
168
154
  width: 100,
@@ -174,30 +160,177 @@ function AppTitle(_ref4) {
174
160
  });
175
161
  }
176
162
  if (isMobile) {
177
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(MobileTitleStyle, {
178
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(AppIcon, {
163
+ return /*#__PURE__*/_jsxs(MobileTitleStyle, {
164
+ children: [/*#__PURE__*/_jsx(AppIcon, {
179
165
  blockletSize: blockletSize,
180
166
  logoUrl: logoUrl
181
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
167
+ }), /*#__PURE__*/_jsx("span", {
182
168
  className: "ellipsis-title",
183
- children: (0, _util.getBlockletDisplayName)(blockletMeta)
169
+ children: getBlockletDisplayName(blockletMeta)
184
170
  })]
185
171
  });
186
172
  }
187
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(AppLink, {
173
+ return /*#__PURE__*/_jsx(AppLink, {
188
174
  target: "_blank",
189
- href: (0, _urlJoin.default)((blockletMeta === null || blockletMeta === void 0 ? void 0 : blockletMeta.registryUrl) || '', "/blocklets/".concat(blockletMeta === null || blockletMeta === void 0 ? void 0 : blockletMeta.did)),
175
+ href: joinUrl(blockletMeta?.registryUrl || '', `/blocklets/${blockletMeta?.did}`),
190
176
  title: name,
191
177
  children: name
192
178
  });
193
179
  }
194
- const MobileTitleStyle = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .ellipsis-title {\n flex: 1;\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n\n ", " {\n left: 26px;\n width: calc(100% - 26px);\n }\n }\n"])), props => props.theme.breakpoints.down('md'));
180
+ const MobileTitleStyle = styled.div`
181
+ .ellipsis-title {
182
+ flex: 1;
183
+ position: absolute;
184
+ left: 0;
185
+ top: 0;
186
+ width: 100%;
187
+ height: 100%;
188
+ white-space: nowrap;
189
+ overflow: hidden;
190
+ text-overflow: ellipsis;
191
+
192
+ ${props => props.theme.breakpoints.down('md')} {
193
+ left: 26px;
194
+ width: calc(100% - 26px);
195
+ }
196
+ }
197
+ `;
195
198
  AppTitle.propTypes = {
196
- blockletMeta: _propTypes.default.object
199
+ blockletMeta: PropTypes.object
197
200
  };
198
201
  AppTitle.defaultProps = {
199
202
  blockletMeta: {}
200
203
  };
201
- var _default = exports.default = AppHeader;
202
- const AppLink = _styled.default.a(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n text-decoration: none;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n font-family: Lato, Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,\n 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';\n text-decoration: none;\n font-weight: 700;\n -webkit-font-smoothing: antialiased;\n\n ", " {\n display: block;\n max-width: calc(100vw - 150px);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n"])), props => props.theme.palette.common.black, props => props.theme.breakpoints.down('md'));
203
- const Container = _styled.default.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n justify-content: flex-start;\n align-items: flex-start;\n width: 100%;\n ", " {\n min-height: 70px;\n }\n ", " {\n align-items: center;\n }\n .app-name-content {\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n ", " {\n align-items: flex-start;\n flex-direction: column;\n }\n ", " {\n justify-content: flex-start;\n height: 22px;\n }\n }\n .launching-context {\n flex-shrink: 0;\n font-size: 14px;\n font-weight: 600;\n color: ", ";\n ", " {\n margin-bottom: 4px;\n }\n ", " {\n font-size: 14px;\n line-height: 15px;\n &:after {\n display: inline-block;\n margin: 0 4px;\n content: ':';\n }\n }\n }\n\n &.center-mode {\n align-items: flex-start;\n .launching-context {\n ", " {\n margin-bottom: 0;\n }\n }\n }\n\n .app-icon {\n flex-shrink: 0;\n > * {\n display: block;\n vertical-align: middle;\n }\n }\n\n .header-title {\n flex: 1;\n display: flex;\n flex-direction: column;\n justify-content: space-around;\n align-items: flex-start;\n margin-left: 24px;\n ", " {\n margin-left: 16px;\n }\n .header-title-name {\n position: relative;\n display: flex;\n justify-content: center;\n align-items: center;\n flex: 1;\n height: 100%;\n color: ", ";\n font-weight: 700;\n ", " {\n font-size: 18px;\n\n &.middle-size {\n font-size: 16px;\n }\n }\n ", " {\n display: block;\n max-width: calc(100vw - 100px);\n font-size: 16px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n\n .header-title-sub {\n color: ", ";\n font-size: 12px;\n line-height: 16px;\n\n ", " {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n }\n"])), props => props.theme.breakpoints.up('md'), props => props.theme.breakpoints.down('md'), props => props.theme.breakpoints.up('md'), props => props.theme.breakpoints.down('md'), props => props.theme.palette.grey[500], props => props.theme.breakpoints.up('md'), props => props.theme.breakpoints.down('md'), props => props.theme.breakpoints.up('sm'), props => props.theme.breakpoints.down('md'), props => props.theme.palette.common.black, props => props.theme.breakpoints.up('sm'), props => props.theme.breakpoints.down('md'), props => props.theme.palette.grey[700], props => props.theme.breakpoints.down('md'));
204
+ export default AppHeader;
205
+ const AppLink = styled.a`
206
+ color: ${props => props.theme.palette.common.black};
207
+ text-decoration: none;
208
+ overflow: hidden;
209
+ text-overflow: ellipsis;
210
+ display: -webkit-box;
211
+ -webkit-line-clamp: 2;
212
+ -webkit-box-orient: vertical;
213
+ font-family: Lato, Avenir, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,
214
+ 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
215
+ text-decoration: none;
216
+ font-weight: 700;
217
+ -webkit-font-smoothing: antialiased;
218
+
219
+ ${props => props.theme.breakpoints.down('md')} {
220
+ display: block;
221
+ max-width: calc(100vw - 150px);
222
+ white-space: nowrap;
223
+ overflow: hidden;
224
+ text-overflow: ellipsis;
225
+ }
226
+ `;
227
+ const Container = styled.div`
228
+ display: flex;
229
+ justify-content: flex-start;
230
+ align-items: flex-start;
231
+ width: 100%;
232
+ ${props => props.theme.breakpoints.up('md')} {
233
+ min-height: 70px;
234
+ }
235
+ ${props => props.theme.breakpoints.down('md')} {
236
+ align-items: center;
237
+ }
238
+ .app-name-content {
239
+ width: 100%;
240
+ display: flex;
241
+ align-items: center;
242
+ justify-content: center;
243
+ ${props => props.theme.breakpoints.up('md')} {
244
+ align-items: flex-start;
245
+ flex-direction: column;
246
+ }
247
+ ${props => props.theme.breakpoints.down('md')} {
248
+ justify-content: flex-start;
249
+ height: 22px;
250
+ }
251
+ }
252
+ .launching-context {
253
+ flex-shrink: 0;
254
+ font-size: 14px;
255
+ font-weight: 600;
256
+ color: ${props => props.theme.palette.grey[500]};
257
+ ${props => props.theme.breakpoints.up('md')} {
258
+ margin-bottom: 4px;
259
+ }
260
+ ${props => props.theme.breakpoints.down('md')} {
261
+ font-size: 14px;
262
+ line-height: 15px;
263
+ &:after {
264
+ display: inline-block;
265
+ margin: 0 4px;
266
+ content: ':';
267
+ }
268
+ }
269
+ }
270
+
271
+ &.center-mode {
272
+ align-items: flex-start;
273
+ .launching-context {
274
+ ${props => props.theme.breakpoints.up('sm')} {
275
+ margin-bottom: 0;
276
+ }
277
+ }
278
+ }
279
+
280
+ .app-icon {
281
+ flex-shrink: 0;
282
+ > * {
283
+ display: block;
284
+ vertical-align: middle;
285
+ }
286
+ }
287
+
288
+ .header-title {
289
+ flex: 1;
290
+ display: flex;
291
+ flex-direction: column;
292
+ justify-content: space-around;
293
+ align-items: flex-start;
294
+ margin-left: 24px;
295
+ ${props => props.theme.breakpoints.down('md')} {
296
+ margin-left: 16px;
297
+ }
298
+ .header-title-name {
299
+ position: relative;
300
+ display: flex;
301
+ justify-content: center;
302
+ align-items: center;
303
+ flex: 1;
304
+ height: 100%;
305
+ color: ${props => props.theme.palette.common.black};
306
+ font-weight: 700;
307
+ ${props => props.theme.breakpoints.up('sm')} {
308
+ font-size: 18px;
309
+
310
+ &.middle-size {
311
+ font-size: 16px;
312
+ }
313
+ }
314
+ ${props => props.theme.breakpoints.down('md')} {
315
+ display: block;
316
+ max-width: calc(100vw - 100px);
317
+ font-size: 16px;
318
+ white-space: nowrap;
319
+ overflow: hidden;
320
+ text-overflow: ellipsis;
321
+ }
322
+ }
323
+
324
+ .header-title-sub {
325
+ color: ${props => props.theme.palette.grey[700]};
326
+ font-size: 12px;
327
+ line-height: 16px;
328
+
329
+ ${props => props.theme.breakpoints.down('md')} {
330
+ white-space: nowrap;
331
+ overflow: hidden;
332
+ text-overflow: ellipsis;
333
+ }
334
+ }
335
+ }
336
+ `;