@arcblock/ux 2.8.26 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/es/Address/did-address.js +33 -21
  2. package/es/AnimationWaiter/index.js +2 -1
  3. package/es/Avatar/index.js +1 -1
  4. package/es/BlockletContext/index.js +1 -1
  5. package/es/CardSelector/index.js +2 -1
  6. package/es/Colors/index.js +2 -1
  7. package/es/Colors/themes/temp.js +17 -0
  8. package/es/Datatable/TableSearch.js +2 -1
  9. package/es/Img/index.js +7 -6
  10. package/es/Locale/selector.js +15 -13
  11. package/es/NFTDisplay/index.js +2 -1
  12. package/es/QRCode/index.js +2 -1
  13. package/es/SessionBlocklet/index.js +169 -0
  14. package/es/SessionManager/index.js +2 -381
  15. package/es/SessionPermission/index.js +28 -0
  16. package/es/SessionUser/components/logged-in.js +224 -0
  17. package/es/SessionUser/components/session-user-item.js +148 -0
  18. package/es/SessionUser/components/session-user-switch.js +213 -0
  19. package/es/SessionUser/components/un-login.js +64 -0
  20. package/es/SessionUser/components/user-info.js +163 -0
  21. package/es/SessionUser/index.js +49 -0
  22. package/es/SessionUser/libs/translation.js +19 -0
  23. package/es/SessionUser/libs/utils.js +4 -0
  24. package/es/SplitButton/index.js +2 -1
  25. package/es/Toast/index.js +1 -1
  26. package/es/Util/constant.js +10 -0
  27. package/es/Util/index.js +11 -0
  28. package/lib/Address/did-address.js +36 -22
  29. package/lib/AnimationWaiter/index.js +2 -1
  30. package/lib/Avatar/index.js +1 -1
  31. package/lib/BlockletContext/index.js +1 -1
  32. package/lib/CardSelector/index.js +2 -1
  33. package/lib/Colors/index.js +7 -0
  34. package/lib/Colors/themes/temp.js +24 -0
  35. package/lib/Datatable/TableSearch.js +2 -1
  36. package/lib/Img/index.js +7 -6
  37. package/lib/Locale/selector.js +14 -13
  38. package/lib/NFTDisplay/index.js +2 -1
  39. package/lib/QRCode/index.js +2 -1
  40. package/lib/SessionBlocklet/index.js +187 -0
  41. package/lib/SessionManager/index.js +2 -390
  42. package/lib/SessionPermission/index.js +38 -0
  43. package/lib/SessionUser/components/logged-in.js +243 -0
  44. package/lib/SessionUser/components/session-user-item.js +163 -0
  45. package/lib/SessionUser/components/session-user-switch.js +232 -0
  46. package/lib/SessionUser/components/un-login.js +72 -0
  47. package/lib/SessionUser/components/user-info.js +175 -0
  48. package/lib/SessionUser/index.js +57 -0
  49. package/lib/SessionUser/libs/translation.js +26 -0
  50. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  51. package/lib/SplitButton/index.js +2 -1
  52. package/lib/Toast/index.js +5 -5
  53. package/lib/Util/constant.js +26 -0
  54. package/lib/Util/index.js +16 -3
  55. package/package.json +19 -7
  56. package/src/Address/did-address.jsx +34 -20
  57. package/src/AnimationWaiter/index.js +2 -1
  58. package/src/Avatar/index.jsx +1 -1
  59. package/src/BlockletContext/index.jsx +1 -1
  60. package/src/CardSelector/index.jsx +2 -1
  61. package/src/Colors/index.js +1 -0
  62. package/src/Colors/themes/temp.js +18 -0
  63. package/src/Datatable/TableSearch.js +3 -1
  64. package/src/Img/{index.js → index.jsx} +8 -6
  65. package/src/Locale/selector.jsx +11 -8
  66. package/src/NFTDisplay/index.js +2 -1
  67. package/src/QRCode/index.js +2 -1
  68. package/src/SessionBlocklet/index.jsx +181 -0
  69. package/src/SessionManager/index.jsx +2 -369
  70. package/src/SessionPermission/index.jsx +28 -0
  71. package/src/SessionUser/components/logged-in.jsx +194 -0
  72. package/src/SessionUser/components/session-user-item.jsx +96 -0
  73. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  74. package/src/SessionUser/components/un-login.jsx +55 -0
  75. package/src/SessionUser/components/user-info.jsx +165 -0
  76. package/src/SessionUser/index.jsx +38 -0
  77. package/src/SessionUser/libs/translation.js +19 -0
  78. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  79. package/src/SplitButton/index.js +2 -1
  80. package/src/Toast/index.js +1 -1
  81. package/src/Util/constant.js +12 -0
  82. package/src/Util/index.js +13 -0
  83. package/es/SessionManager/components/account-item.js +0 -212
  84. package/es/SessionManager/components/add-account-item.js +0 -57
  85. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  86. package/es/SessionManager/components/manage-accounts.js +0 -219
  87. package/es/SessionManager/components/manage-blocklet.js +0 -70
  88. package/es/SessionManager/components/menu-accordion.js +0 -103
  89. package/es/SessionManager/components/responsive-popper.js +0 -24
  90. package/es/SessionManager/components/user-drawer.js +0 -68
  91. package/es/SessionManager/components/user-info.js +0 -143
  92. package/es/SessionManager/components/user-popper.js +0 -110
  93. package/es/SessionManager/hooks/use-config.js +0 -34
  94. package/es/SessionManager/libs/translation.js +0 -52
  95. package/es/SessionManager/libs/utils.js +0 -2
  96. package/lib/SessionManager/components/account-item.js +0 -219
  97. package/lib/SessionManager/components/add-account-item.js +0 -66
  98. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  99. package/lib/SessionManager/components/manage-accounts.js +0 -232
  100. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  101. package/lib/SessionManager/components/menu-accordion.js +0 -111
  102. package/lib/SessionManager/components/responsive-popper.js +0 -34
  103. package/lib/SessionManager/components/user-drawer.js +0 -75
  104. package/lib/SessionManager/components/user-info.js +0 -160
  105. package/lib/SessionManager/components/user-popper.js +0 -104
  106. package/lib/SessionManager/hooks/use-config.js +0 -41
  107. package/lib/SessionManager/libs/translation.js +0 -59
  108. package/src/SessionManager/components/account-item.jsx +0 -156
  109. package/src/SessionManager/components/add-account-item.jsx +0 -49
  110. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  111. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  112. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  113. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  114. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  115. package/src/SessionManager/components/user-drawer.jsx +0 -57
  116. package/src/SessionManager/components/user-info.jsx +0 -117
  117. package/src/SessionManager/components/user-popper.jsx +0 -95
  118. package/src/SessionManager/hooks/use-config.js +0 -33
  119. package/src/SessionManager/libs/translation.js +0 -52
@@ -4,395 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = require("react");
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _material = require("@mui/material");
10
- var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
11
- var _noop = _interopRequireDefault(require("lodash/noop"));
12
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
13
- var _ahooks = require("ahooks");
14
- var _Avatar = _interopRequireDefault(require("../Avatar"));
15
- var _Util = require("../Util");
16
- var _federatedLoginDetecter = _interopRequireDefault(require("./components/federated-login-detecter"));
17
- var _userInfo = _interopRequireDefault(require("./components/user-info"));
18
- var _responsivePopper = _interopRequireDefault(require("./components/responsive-popper"));
19
- var _util = require("../Locale/util");
20
- var _manageAccounts = _interopRequireDefault(require("./components/manage-accounts"));
21
- var _manageBlocklet = _interopRequireDefault(require("./components/manage-blocklet"));
22
- var _translation = require("./libs/translation");
23
- var _utils = require("./libs/utils");
24
- var _useConfig = _interopRequireDefault(require("./hooks/use-config"));
25
- var _federated = require("../Util/federated");
26
- var _jsxRuntime = require("react/jsx-runtime");
27
- const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size", "showManageBlocklet"];
28
- /* eslint-disable react/prop-types */
29
- /* eslint-disable react/jsx-no-bind */
7
+ var _SessionUser = _interopRequireDefault(require("../SessionUser"));
30
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
32
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
34
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
35
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
36
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
37
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
38
- function SessionManager(_ref) {
39
- var _session$user, _session$user$avatar;
40
- let {
41
- session,
42
- locale,
43
- showText,
44
- showRole,
45
- switchDid,
46
- switchProfile,
47
- switchPassport,
48
- disableLogout,
49
- onLogin,
50
- onLogout,
51
- onSwitchDid,
52
- onSwitchProfile,
53
- onSwitchPassport,
54
- onBindWallet,
55
- menu,
56
- menuRender,
57
- dark,
58
- size,
59
- showManageBlocklet
60
- } = _ref,
61
- rest = _objectWithoutProperties(_ref, _excluded);
62
- const latestSession = (0, _ahooks.useLatest)(session);
63
- const {
64
- connectAccount,
65
- config,
66
- setConfig,
67
- deleteAccount
68
- } = (0, _useConfig.default)();
69
- const t = (0, _ahooks.useMemoizedFn)(function (key) {
70
- let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
71
- return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
72
- });
73
- const userAnchorRef = (0, _react.useRef)(null);
74
- const {
75
- logoutOAuth,
76
- switchOAuthPassport
77
- } = session.useOAuth();
78
- const [userOpen, setUserOpen] = (0, _react.useState)(false);
79
-
80
- // base64 img maybe have some blank char, need encodeURIComponent to transform it
81
- const avatar = (0, _Util.getUserAvatar)((_session$user = session.user) === null || _session$user === void 0 ? void 0 : (_session$user$avatar = _session$user.avatar) === null || _session$user$avatar === void 0 ? void 0 : _session$user$avatar.replace(/\s/g, encodeURIComponent(' ')));
82
- const isRawWalletAccount = (0, _utils.getSourceProvider)(session.user) === 'wallet';
83
- const connectedAccounts = (0, _utils.getConnectedAccounts)(session.user);
84
- const isFirstLoading = (0, _react.useMemo)(() => {
85
- return (session === null || session === void 0 ? void 0 : session.initialized) === false && (session === null || session === void 0 ? void 0 : session.loading) === true;
86
- }, [session === null || session === void 0 ? void 0 : session.initialized, session === null || session === void 0 ? void 0 : session.loading]);
87
- let hasBindWallet = false;
88
- let hasBindAccount = false;
89
- if (isRawWalletAccount) {
90
- if (connectedAccounts.some(item => item.provider !== 'wallet')) {
91
- hasBindAccount = true;
92
- }
93
- hasBindWallet = true;
94
- } else if (connectedAccounts.some(item => item.provider === 'wallet')) {
95
- hasBindAccount = true;
96
- hasBindWallet = true;
97
- }
98
- const _connectAccount = (0, _ahooks.useMemoizedFn)(async () => {
99
- var _latestSession$curren, _window;
100
- // HACK: 强制等待组件渲染一轮,以拿到最新的 session 值
101
- await (0, _Util.sleep)();
102
- if (!((_latestSession$curren = latestSession.current) !== null && _latestSession$curren !== void 0 && _latestSession$curren.user)) {
103
- return;
104
- }
105
- if (typeof window === 'undefined') {
106
- return;
107
- }
108
- const blocklet = (_window = window) === null || _window === void 0 ? void 0 : _window.blocklet;
109
- const currentApp = (0, _federated.getCurrentApp)(blocklet);
110
- const masterApp = (0, _federated.getFederatedApp)(blocklet);
111
- const targetApp = latestSession.current.user.sourceAppPid ? masterApp : currentApp;
112
- if (targetApp) {
113
- const loginAccount = _objectSpread(_objectSpread({}, targetApp), {}, {
114
- did: latestSession.current.user.did,
115
- avatar: latestSession.current.user.avatar,
116
- provider: latestSession.current.provider || targetApp.provider,
117
- walletOS: latestSession.current.walletOS
118
- });
119
- connectAccount(loginAccount);
120
- }
121
- });
122
-
123
- // HACK: 用于处理 统一登录 的自动登录情况,添加一个已连接的账号
124
- // 同时可用于以前的站点,会自动生成一个已连接的账号
125
- (0, _react.useEffect)(() => {
126
- if (session.user) {
127
- _connectAccount();
128
- }
129
- // eslint-disable-next-line react-hooks/exhaustive-deps
130
- }, [session.user]);
131
- if (!session.user) {
132
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
133
- children: [showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Button, _objectSpread(_objectSpread({
134
- ref: userAnchorRef,
135
- sx: [{
136
- borderRadius: '100vw'
137
- }, dark && {
138
- color: '#fff',
139
- borderColor: '#fff'
140
- }],
141
- variant: "outlined",
142
- onClick: _onLogin,
143
- role: "button",
144
- "aria-label": "Login button"
145
- }, rest), {}, {
146
- "data-cy": "sessionManager-login",
147
- children: [isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
148
- style: {
149
- lineHeight: '25px'
150
- },
151
- children: t('connect')
152
- })]
153
- })) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
154
- ref: userAnchorRef
155
- }, rest), {}, {
156
- onClick: _onLogin,
157
- "data-cy": "sessionManager-login",
158
- size: "medium",
159
- role: "button",
160
- "aria-label": "Login button",
161
- children: isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
162
- width: size,
163
- height: size,
164
- display: "flex",
165
- justifyContent: "center",
166
- alignItems: "center",
167
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {
168
- style: {
169
- width: size - 4,
170
- height: size - 4,
171
- color: dark ? '#fff' : ''
172
- }
173
- })
174
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {
175
- style: {
176
- width: size,
177
- height: size,
178
- color: dark ? '#fff' : ''
179
- }
180
- })
181
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_federatedLoginDetecter.default, {
182
- locale: locale,
183
- dark: dark,
184
- session: session,
185
- anchorEl: userAnchorRef.current
186
- })]
187
- });
188
- }
189
- function onToggleUser() {
190
- setUserOpen(prevOpen => !prevOpen);
191
- }
192
- function close() {
193
- setUserOpen(false);
194
- }
195
- function onCloseUser(e) {
196
- if (userAnchorRef.current && userAnchorRef.current.contains(e.target)) {
197
- return;
198
- }
199
- close();
200
- }
201
- function _onLogin() {
202
- if (!isFirstLoading) {
203
- session.login(function () {
204
- _connectAccount();
205
- onLogin(...arguments);
206
- });
207
- }
208
- }
209
- function _onLogout() {
210
- return new Promise((resolve, reject) => {
211
- logoutOAuth({
212
- session,
213
- hack: true
214
- }).catch(err => {
215
- console.error(err);
216
- reject(err);
217
- }).finally(() => {
218
- session.logout(function () {
219
- onLogout(...arguments);
220
- resolve();
221
- close();
222
- });
223
- });
224
- });
225
- }
226
- /**
227
- * @name 切换账户
228
- * @description 该功能仅在登录后才能使用,目前仅用于切换普通登录和统一登录的账户,所以会增加一些与统一登录相关的逻辑
229
- */
230
-
231
- function _onSwitchProfile() {
232
- session.switchProfile(function () {
233
- close();
234
- onSwitchProfile(...arguments);
235
- });
236
- }
237
- function _onSwitchPassport() {
238
- const {
239
- user,
240
- provider
241
- } = session;
242
- if (['auth0'].includes(provider)) {
243
- switchOAuthPassport(user);
244
- } else {
245
- close();
246
- session.switchPassport(function () {
247
- close();
248
- onSwitchPassport(...arguments);
249
- });
250
- }
251
- }
252
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
253
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
254
- ref: userAnchorRef,
255
- onClick: onToggleUser
256
- }, rest), {}, {
257
- "data-cy": "sessionManager-logout-popup",
258
- size: "medium",
259
- role: "button",
260
- "aria-label": "User info button",
261
- style: {
262
- lineHeight: 1
263
- },
264
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
265
- variant: "circle",
266
- did: session.user.did,
267
- src: avatar,
268
- size: size,
269
- shape: "circle"
270
- })
271
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_responsivePopper.default, {
272
- open: userOpen,
273
- onClose: onCloseUser,
274
- anchorEl: userAnchorRef.current,
275
- dark: dark,
276
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuList, {
277
- sx: {
278
- p: 0
279
- },
280
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_userInfo.default, {
281
- session: session,
282
- size: size,
283
- locale: locale,
284
- onSwitchProfile: () => {
285
- close();
286
- _onSwitchProfile();
287
- },
288
- onSwitchPassport: () => {
289
- close();
290
- _onSwitchPassport();
291
- },
292
- close: close,
293
- switchProfile: switchProfile,
294
- hasBindWallet: hasBindWallet
295
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageAccounts.default, {
296
- session: session,
297
- locale: locale,
298
- onBindWallet: onBindWallet,
299
- onSwitchDid: onSwitchDid,
300
- connectAccount: _connectAccount,
301
- close: close,
302
- hasBindAccount: hasBindAccount,
303
- onLogout: _onLogout,
304
- expanded: config.expandAccount,
305
- onExpand: value => {
306
- const cloneConfig = (0, _cloneDeep.default)(config);
307
- cloneConfig.expandAccount = value;
308
- setConfig(cloneConfig);
309
- },
310
- deleteAccount: deleteAccount,
311
- accounts: config.accounts
312
- }), showManageBlocklet ? [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}, "divider"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageBlocklet.default, {
313
- menu: menu,
314
- menuRender: menuRender,
315
- locale: locale,
316
- expanded: config.expandBlocklet,
317
- onExpand: value => {
318
- const cloneConfig = (0, _cloneDeep.default)(config);
319
- cloneConfig.expandBlocklet = value;
320
- setConfig(cloneConfig);
321
- }
322
- }, "manageBlocklet")] : null]
323
- })
324
- })]
325
- });
326
- }
327
- SessionManager.propTypes = {
328
- session: _propTypes.default.shape({
329
- federatedMaster: _propTypes.default.object,
330
- provider: _propTypes.default.oneOf(['wallet', 'auth0', '']),
331
- user: _propTypes.default.shape({
332
- did: _propTypes.default.string.isRequired,
333
- role: _propTypes.default.string.isRequired,
334
- fullName: _propTypes.default.string,
335
- email: _propTypes.default.string,
336
- avatar: _propTypes.default.string,
337
- sourceProvider: _propTypes.default.string,
338
- connectedAccounts: _propTypes.default.arrayOf(_propTypes.default.shape({
339
- provider: _propTypes.default.string.isRequired,
340
- did: _propTypes.default.string.isRequired,
341
- id: _propTypes.default.string
342
- })),
343
- passports: _propTypes.default.arrayOf(_propTypes.default.shape({
344
- name: _propTypes.default.string.isRequired,
345
- title: _propTypes.default.string.isRequired
346
- })),
347
- // Deprecated
348
- extraConfigs: _propTypes.default.object
349
- }),
350
- login: _propTypes.default.func.isRequired,
351
- logout: _propTypes.default.func.isRequired,
352
- switchDid: _propTypes.default.func.isRequired,
353
- switchProfile: _propTypes.default.func.isRequired,
354
- switchPassport: _propTypes.default.func.isRequired,
355
- bindWallet: _propTypes.default.func.isRequired,
356
- refresh: _propTypes.default.func.isRequired
357
- }).isRequired,
358
- locale: _propTypes.default.string,
359
- showText: _propTypes.default.bool,
360
- showRole: _propTypes.default.bool,
361
- switchDid: _propTypes.default.bool,
362
- switchProfile: _propTypes.default.bool,
363
- switchPassport: _propTypes.default.bool,
364
- disableLogout: _propTypes.default.bool,
365
- onLogin: _propTypes.default.func,
366
- onLogout: _propTypes.default.func,
367
- onSwitchDid: _propTypes.default.func,
368
- onSwitchProfile: _propTypes.default.func,
369
- onSwitchPassport: _propTypes.default.func,
370
- onBindWallet: _propTypes.default.func,
371
- menu: _propTypes.default.array,
372
- menuRender: _propTypes.default.func,
373
- dark: _propTypes.default.bool,
374
- size: _propTypes.default.number,
375
- showManageBlocklet: _propTypes.default.bool
376
- };
377
- SessionManager.defaultProps = {
378
- locale: 'en',
379
- showText: false,
380
- showRole: false,
381
- switchDid: true,
382
- switchProfile: true,
383
- switchPassport: true,
384
- disableLogout: false,
385
- menu: [],
386
- menuRender: _noop.default,
387
- onLogin: _noop.default,
388
- onLogout: _noop.default,
389
- onSwitchDid: _noop.default,
390
- onSwitchProfile: _noop.default,
391
- onSwitchPassport: _noop.default,
392
- onBindWallet: _noop.default,
393
- dark: false,
394
- size: 24,
395
- showManageBlocklet: true
396
- };
397
- var _default = SessionManager;
9
+ var _default = _SessionUser.default;
398
10
  exports.default = _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SessionPermission;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _ahooks = require("ahooks");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const roleList = ['owner', 'admin', 'member', 'guest'];
11
+ function SessionPermission(_ref) {
12
+ var _session$user2;
13
+ let {
14
+ session,
15
+ roles,
16
+ children
17
+ } = _ref;
18
+ const hasPermission = (0, _ahooks.useCreation)(() => {
19
+ var _session$user;
20
+ return roles.includes((session === null || session === void 0 ? void 0 : (_session$user = session.user) === null || _session$user === void 0 ? void 0 : _session$user.role) || 'guest');
21
+ }, [session === null || session === void 0 ? void 0 : (_session$user2 = session.user) === null || _session$user2 === void 0 ? void 0 : _session$user2.role, roles]);
22
+ if (typeof children === 'function') {
23
+ return children({
24
+ hasPermission
25
+ });
26
+ }
27
+ if (hasPermission) {
28
+ return children;
29
+ }
30
+ }
31
+ SessionPermission.propTypes = {
32
+ children: _propTypes.default.any.isRequired,
33
+ session: _propTypes.default.object.isRequired,
34
+ roles: _propTypes.default.arrayOf(_propTypes.default.oneOf(roleList))
35
+ };
36
+ SessionPermission.defaultProps = {
37
+ roles: ['owner', 'admin']
38
+ };
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = LoggedIn;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = require("react");
9
+ var _ahooks = require("ahooks");
10
+ var _material = require("@mui/material");
11
+ var _react2 = require("@iconify/react");
12
+ var _personOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/person-outline-rounded"));
13
+ var _filterVintageOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/filter-vintage-outline-rounded"));
14
+ var _accountCircleOffOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/account-circle-off-outline-rounded"));
15
+ var _noop = _interopRequireDefault(require("lodash/noop"));
16
+ var _Avatar = _interopRequireDefault(require("../../Avatar"));
17
+ var _Util = require("../../Util");
18
+ var _userInfo = _interopRequireDefault(require("./user-info"));
19
+ var _Colors = require("../../Colors");
20
+ var _constant = require("../../Util/constant");
21
+ var _SessionPermission = _interopRequireDefault(require("../../SessionPermission"));
22
+ var _translation = require("../libs/translation");
23
+ var _util = require("../../Locale/util");
24
+ var _jsxRuntime = require("react/jsx-runtime");
25
+ const _excluded = ["icon", "title"];
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
28
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
29
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
30
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
32
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
33
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
34
+ function LoggedIn(_ref) {
35
+ var _session$user, _session$user$avatar;
36
+ let {
37
+ session,
38
+ dark,
39
+ onBindWallet,
40
+ isBlocklet,
41
+ locale,
42
+ size
43
+ } = _ref;
44
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
45
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
47
+ });
48
+ const popperAnchorRef = (0, _react.useRef)(null);
49
+ const currentState = (0, _ahooks.useReactive)({
50
+ open: false
51
+ });
52
+ const onTogglePopper = (0, _ahooks.useMemoizedFn)(function () {
53
+ let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !currentState.open;
54
+ currentState.open = value;
55
+ });
56
+ // base64 img maybe have some blank char, need encodeURIComponent to transform it
57
+ const avatar = (0, _Util.getUserAvatar)((_session$user = session.user) === null || _session$user === void 0 ? void 0 : (_session$user$avatar = _session$user.avatar) === null || _session$user$avatar === void 0 ? void 0 : _session$user$avatar.replace(/\s/g, encodeURIComponent(' ')));
58
+ const handleSwitchPassport = (0, _ahooks.useMemoizedFn)(() => {
59
+ onTogglePopper(false);
60
+ session.switchPassport();
61
+ });
62
+ const handleSwitchAccount = (0, _ahooks.useMemoizedFn)(function () {
63
+ let {
64
+ userSession
65
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
66
+ return new Promise(resolve => {
67
+ const options = {};
68
+ if (!userSession) {
69
+ onTogglePopper(false);
70
+ options.showQuickConnect = false;
71
+ } else {
72
+ options.userSession = userSession;
73
+ }
74
+ session.switchDid(() => {
75
+ onTogglePopper(false);
76
+ resolve();
77
+ }, {}, options);
78
+ });
79
+ });
80
+ const handleSwitchProfile = (0, _ahooks.useMemoizedFn)(() => {
81
+ onTogglePopper(false);
82
+ session.switchProfile();
83
+ });
84
+ const onLogout = (0, _ahooks.useMemoizedFn)(() => {
85
+ onTogglePopper(false);
86
+ session.logout();
87
+ });
88
+ const handleBindWallet = (0, _ahooks.useMemoizedFn)(() => {
89
+ onTogglePopper(false);
90
+ session.bindWallet(onBindWallet);
91
+ });
92
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
93
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
94
+ ref: popperAnchorRef,
95
+ onClick: () => onTogglePopper(),
96
+ size: "medium",
97
+ "data-cy": "sessionManager-logout-popup",
98
+ "aria-label": "User info button",
99
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
100
+ variant: "circle",
101
+ did: session.user.did,
102
+ src: avatar,
103
+ size: size,
104
+ shape: "circle"
105
+ })
106
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Popper, {
107
+ open: currentState.open,
108
+ onClose: () => onTogglePopper(false),
109
+ anchorEl: popperAnchorRef.current,
110
+ dark: dark,
111
+ transition: true,
112
+ placement: "bottom-end",
113
+ sx: {
114
+ zIndex: 1600
115
+ },
116
+ children: _ref2 => {
117
+ let {
118
+ TransitionProps
119
+ } = _ref2;
120
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
121
+ onClickAway: e => {
122
+ e.preventDefault();
123
+ e.stopPropagation();
124
+ onTogglePopper(false);
125
+ },
126
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Fade, _objectSpread(_objectSpread({}, TransitionProps), {}, {
127
+ timeout: 350,
128
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Paper, {
129
+ variant: "outlined",
130
+ sx: {
131
+ borderRadius: 3,
132
+ width: 350,
133
+ maxWidth: '90vw',
134
+ borderColor: _Colors.temp.lineStep,
135
+ border: '0 !important',
136
+ boxShadow: "0px 8px 16px 0px ".concat(_Colors.temp.gray6, ", 0px 0px 0px 1px ").concat(_Colors.temp.gray6)
137
+ },
138
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_userInfo.default, {
139
+ locale: locale,
140
+ isBlocklet: isBlocklet,
141
+ session: session,
142
+ onSwitchPassport: handleSwitchPassport,
143
+ onSwitchAccount: handleSwitchAccount,
144
+ onSwitchProfile: handleSwitchProfile,
145
+ onBindWallet: handleBindWallet
146
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuList, {
147
+ sx: {
148
+ p: 0
149
+ },
150
+ children: [isBlocklet ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
151
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SessionPermission.default, {
152
+ session: session,
153
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(SessionMenuItem, {
154
+ icon: _filterVintageOutlineRounded.default,
155
+ title: t('dashboard'),
156
+ component: "a",
157
+ href: _constant.DASHBOARD_URL,
158
+ sx: {
159
+ display: 'block',
160
+ textDecoration: 'none',
161
+ color: 'inherit'
162
+ }
163
+ })
164
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(SessionMenuItem, {
165
+ icon: _personOutlineRounded.default,
166
+ title: t('profile'),
167
+ component: "a",
168
+ href: _constant.PROFILE_URL,
169
+ sx: {
170
+ display: 'block',
171
+ textDecoration: 'none',
172
+ color: 'inherit'
173
+ }
174
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
175
+ sx: {
176
+ m: '0!important',
177
+ borderColor: _Colors.temp.lineStep
178
+ }
179
+ })]
180
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(SessionMenuItem, {
181
+ icon: _accountCircleOffOutlineRounded.default,
182
+ title: t('logout'),
183
+ sx: {
184
+ color: 'error.main'
185
+ },
186
+ onClick: onLogout,
187
+ "data-cy": "sessionManager-logout-trigger"
188
+ })]
189
+ })]
190
+ })
191
+ }))
192
+ });
193
+ }
194
+ })]
195
+ });
196
+ }
197
+ LoggedIn.propTypes = {
198
+ session: _propTypes.default.object.isRequired,
199
+ onBindWallet: _propTypes.default.func,
200
+ dark: _propTypes.default.bool,
201
+ isBlocklet: _propTypes.default.bool,
202
+ locale: _propTypes.default.string,
203
+ size: _propTypes.default.number
204
+ };
205
+ LoggedIn.defaultProps = {
206
+ dark: false,
207
+ isBlocklet: true,
208
+ onBindWallet: _noop.default,
209
+ locale: 'en',
210
+ size: 24
211
+ };
212
+ function SessionMenuItem(_ref3) {
213
+ let {
214
+ icon,
215
+ title
216
+ } = _ref3,
217
+ rest = _objectWithoutProperties(_ref3, _excluded);
218
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, _objectSpread(_objectSpread({}, rest), {}, {
219
+ sx: _objectSpread({
220
+ p: 0.5
221
+ }, rest === null || rest === void 0 ? void 0 : rest.sx),
222
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
223
+ sx: {
224
+ display: 'flex',
225
+ gap: 1,
226
+ alignItems: 'center',
227
+ borderRadius: 2,
228
+ '&:hover': {
229
+ backgroundColor: "".concat(_Colors.temp.surfacePrimarySubtitle, " !important")
230
+ },
231
+ py: 1
232
+ },
233
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
234
+ icon: icon,
235
+ fontSize: 24
236
+ }), title]
237
+ })
238
+ }));
239
+ }
240
+ SessionMenuItem.propTypes = {
241
+ icon: _propTypes.default.string.isRequired,
242
+ title: _propTypes.default.string.isRequired
243
+ };