@abtnode/ux 1.15.17 → 1.16.0-beta-b16cb035

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.
Files changed (154) hide show
  1. package/lib/actions.js +111 -0
  2. package/lib/blocklet/access/config-access.js +303 -0
  3. package/lib/blocklet/access/index.js +221 -0
  4. package/lib/blocklet/actions.js +438 -0
  5. package/lib/blocklet/add-cert.js +191 -0
  6. package/lib/blocklet/agreement-app.js +30 -0
  7. package/lib/blocklet/agreement.js +72 -0
  8. package/lib/blocklet/app-avatar.js +74 -0
  9. package/lib/blocklet/audit-logs.js +197 -0
  10. package/lib/blocklet/blocklet-source.js +56 -0
  11. package/lib/blocklet/bundle-avatar.js +80 -0
  12. package/lib/blocklet/component/add.js +1063 -0
  13. package/lib/blocklet/component/configuration.js +124 -0
  14. package/lib/blocklet/component/delete.js +117 -0
  15. package/lib/blocklet/component/environment.js +289 -0
  16. package/lib/blocklet/component/expiration.js +53 -0
  17. package/lib/blocklet/component/index.js +804 -0
  18. package/lib/blocklet/component/line.js +28 -0
  19. package/lib/blocklet/component/navigation/locale-tabs.js +218 -0
  20. package/lib/blocklet/component/navigation/navigation-actions.js +120 -0
  21. package/lib/blocklet/component/navigation/navigation-dialog.js +620 -0
  22. package/lib/blocklet/component/navigation/navigation-preview.js +102 -0
  23. package/lib/blocklet/component/navigation/simple-select.js +131 -0
  24. package/lib/blocklet/component/select-store.js +153 -0
  25. package/lib/blocklet/component/setting.js +151 -0
  26. package/lib/blocklet/component/sortable-tree.js +138 -0
  27. package/lib/blocklet/component/space-gateway-selector.js +174 -0
  28. package/lib/blocklet/component/store-blocklet-list.js +205 -0
  29. package/lib/blocklet/config-navigation.js +344 -0
  30. package/lib/blocklet/configuration.js +574 -0
  31. package/lib/blocklet/disk-info.js +91 -0
  32. package/lib/blocklet/icons.js +26 -0
  33. package/lib/blocklet/install-from-url.js +347 -0
  34. package/lib/blocklet/log.js +62 -0
  35. package/lib/blocklet/migration.js +153 -0
  36. package/lib/blocklet/mode.js +35 -0
  37. package/lib/blocklet/monitor.js +186 -0
  38. package/lib/blocklet/overview.js +236 -0
  39. package/lib/blocklet/preferences/app-sk.js +131 -0
  40. package/lib/blocklet/preferences/index.js +238 -0
  41. package/lib/blocklet/preferences/wallet-type.js +107 -0
  42. package/lib/blocklet/purchase/common.js +103 -0
  43. package/lib/blocklet/purchase/component-purchase.js +253 -0
  44. package/lib/blocklet/purchase/index.js +13 -0
  45. package/lib/blocklet/router/action/add-domain-alias.js +173 -0
  46. package/lib/blocklet/router/action/add-rule.js +204 -0
  47. package/lib/blocklet/router/action/config-routing-rule.js +129 -0
  48. package/lib/blocklet/router/action/delete-domain-alias.js +107 -0
  49. package/lib/blocklet/router/action/delete-rule.js +114 -0
  50. package/lib/blocklet/router/action/update-rule.js +203 -0
  51. package/lib/blocklet/router/domain-actions.js +71 -0
  52. package/lib/blocklet/router/domain-status.js +96 -0
  53. package/lib/blocklet/router/rule-actions.js +77 -0
  54. package/lib/blocklet/router/rule-list.js +181 -0
  55. package/lib/blocklet/router/util.js +146 -0
  56. package/lib/blocklet/runtime-info.js +87 -0
  57. package/lib/blocklet/status.js +105 -0
  58. package/lib/blocklet/storage.js +322 -0
  59. package/lib/blocklet/types.js +25 -0
  60. package/lib/blocklet/util.js +213 -0
  61. package/lib/blocklet/version.js +156 -0
  62. package/lib/card-selector.js +109 -0
  63. package/lib/certificate.js +110 -0
  64. package/lib/click-to-copy.js +38 -0
  65. package/lib/confirm.js +149 -0
  66. package/lib/contexts/audit-log.js +141 -0
  67. package/lib/contexts/blocklet.js +19 -0
  68. package/lib/contexts/deleting-blocklets.js +78 -0
  69. package/lib/contexts/node.js +30 -0
  70. package/lib/contexts/session.js +20 -0
  71. package/lib/contexts/team.js +19 -0
  72. package/lib/delete-confirm.js +127 -0
  73. package/lib/did-address.js +77 -0
  74. package/lib/dot.js +18 -0
  75. package/lib/form/form-text-input.js +266 -0
  76. package/lib/form/form-wrapper.js +13 -0
  77. package/lib/form/required.js +13 -0
  78. package/lib/hooks/blocklet.js +231 -0
  79. package/lib/hooks/mobile-width.js +19 -0
  80. package/lib/hooks/url-evaluation.js +168 -0
  81. package/lib/hooks/use-app-logo.js +25 -0
  82. package/lib/hooks/use-bundle-logo.js +36 -0
  83. package/lib/hooks/use-navigation.js +355 -0
  84. package/lib/hooks/use-passport-id.js +21 -0
  85. package/lib/hooks/use-subscription.js +28 -0
  86. package/lib/icons/long-arrow.svg +5 -0
  87. package/lib/index.js +0 -3
  88. package/lib/invitation/invitation-app.js +51 -0
  89. package/lib/invitation/invitation-login.js +47 -0
  90. package/lib/invitation/invitation-passport.js +130 -0
  91. package/lib/invitation/invitation-receive.js +108 -0
  92. package/lib/invitation/invitation-success.js +82 -0
  93. package/lib/invitation/invitation-user.js +79 -0
  94. package/lib/invitation/invitation.js +80 -0
  95. package/lib/issue-passport.js +84 -84
  96. package/lib/launch-blocklet/content-layout.js +33 -0
  97. package/lib/launch-blocklet/page-header.js +38 -0
  98. package/lib/layout/addon.js +100 -0
  99. package/lib/layout/feedback.js +55 -0
  100. package/lib/locales/en.js +1221 -10
  101. package/lib/locales/index.js +3 -4
  102. package/lib/locales/zh.js +1232 -15
  103. package/lib/logs/clock.js +19 -0
  104. package/lib/logs/download.js +139 -0
  105. package/lib/logs/log-terminal.js +183 -0
  106. package/lib/lost-passport.js +191 -195
  107. package/lib/monitor/card.js +73 -0
  108. package/lib/monitor/cpu.js +109 -0
  109. package/lib/monitor/disk.js +122 -0
  110. package/lib/monitor/memory.js +144 -0
  111. package/lib/nav-logo.js +120 -0
  112. package/lib/passport-tag.js +43 -0
  113. package/lib/permission.js +70 -0
  114. package/lib/relative-time.js +61 -0
  115. package/lib/schema-form/color-input.js +105 -0
  116. package/lib/schema-form/common-prop-types.js +21 -0
  117. package/lib/schema-form/index.js +229 -0
  118. package/lib/schema-form/passport-input.js +66 -0
  119. package/lib/schema-form/text-input.js +72 -0
  120. package/lib/store/add.js +185 -0
  121. package/lib/store/delete.js +102 -0
  122. package/lib/store/item.js +84 -0
  123. package/lib/table-icons.js +42 -0
  124. package/lib/table.js +13 -0
  125. package/lib/tag.js +37 -0
  126. package/lib/team/members/actions.js +99 -0
  127. package/lib/team/members/index.js +503 -0
  128. package/lib/team/members/invitations.js +196 -0
  129. package/lib/team/members/invite-member.js +212 -0
  130. package/lib/team/members/issue-passport.js +155 -0
  131. package/lib/team/members/member.js +300 -0
  132. package/lib/team/members/passport-issuances.js +154 -0
  133. package/lib/team/members/passports.js +336 -0
  134. package/lib/team/members/toggle-user-approval.js +128 -0
  135. package/lib/team/members/transfer-node.js +262 -0
  136. package/lib/team/members/util.js +20 -0
  137. package/lib/team/passports/color.js +132 -0
  138. package/lib/team/passports/detail.js +271 -0
  139. package/lib/team/passports/index.js +233 -0
  140. package/lib/team/passports/mutate-role.js +204 -0
  141. package/lib/team/passports/trusted-issuer.js +297 -0
  142. package/lib/team/passports/trusted-issuers.js +240 -0
  143. package/lib/team/search-input.js +38 -0
  144. package/lib/team/styles/dialog.js +13 -0
  145. package/lib/team/styles/list-header.js +13 -0
  146. package/lib/toast.js +86 -0
  147. package/lib/util/api.js +21 -0
  148. package/lib/util/constants.js +10 -0
  149. package/lib/util/index.js +703 -0
  150. package/lib/util/locales.js +28 -0
  151. package/lib/util/mode.js +11 -0
  152. package/lib/who-can-access/config.js +46 -0
  153. package/lib/wrap-locale.js +12 -13
  154. package/package.json +69 -17
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBlockletUrlEvaluation = useBlockletUrlEvaluation;
7
+ exports.useDomainsAccessibility = useDomainsAccessibility;
8
+ exports.useUrlEvaluation = useUrlEvaluation;
9
+ var _react = require("react");
10
+ var _urlJoin = _interopRequireDefault(require("url-join"));
11
+ var _memoize = _interopRequireDefault(require("lodash/memoize"));
12
+ var _constant = require("@abtnode/constant");
13
+ var _urlEvaluation = require("@abtnode/util/lib/url-evaluation");
14
+ var _checkAccessibleBrowser = _interopRequireDefault(require("@abtnode/util/lib/url-evaluation/check-accessible-browser"));
15
+ var _context = require("@arcblock/ux/lib/Locale/context");
16
+ var _util = require("../util");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ 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; }
19
+ 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; }
20
+ 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; }
21
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
22
+ 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); }
23
+ // 如果同一个页面中存在多个部分同时对同一个 url 检测 url 可访问性, 避免造成重复请求
24
+ const ping = (0, _memoize.default)(url => {
25
+ const {
26
+ origin,
27
+ hostname
28
+ } = new URL(url);
29
+ if (hostname === window.location.hostname) {
30
+ return true;
31
+ }
32
+ return (0, _checkAccessibleBrowser.default)((0, _urlJoin.default)(origin, _constant.WELLKNOWN_PING_PREFIX));
33
+ });
34
+
35
+ // url <-> evaluation cache
36
+ const CACHE = {};
37
+ function useUrlEvaluation(_ref) {
38
+ let {
39
+ urls,
40
+ checkAccessible = _checkAccessibleBrowser.default,
41
+ disableCache = false
42
+ } = _ref;
43
+ // 基于 CACHE 初始化该 hook 的状态
44
+ // FIXME: 最好解决源头的 material-table 渲染 BlockletInterface 时的 re-mount 问题 (#4897)
45
+ const initialCachedRef = (0, _react.useRef)(urls.filter(url => CACHE[url]).map(url => CACHE[url]));
46
+ const allCached = initialCachedRef.current.length === urls.length;
47
+ const [urlsState, setUrlsState] = (0, _react.useState)(allCached ? initialCachedRef.current : []);
48
+ const [loading, setLoading] = (0, _react.useState)(!allCached);
49
+ const recommendedUrlState = (0, _react.useMemo)(() => {
50
+ if (!loading && urlsState.length) {
51
+ return urlsState[0];
52
+ }
53
+ return null;
54
+ }, [urlsState, loading]);
55
+ (0, _react.useEffect)(() => {
56
+ if ((urls === null || urls === void 0 ? void 0 : urls.length) > 0 && !allCached) {
57
+ const evaluate = async () => {
58
+ let results;
59
+ setLoading(true);
60
+ if (disableCache) {
61
+ results = await (0, _urlEvaluation.evaluateURLs)(urls, {
62
+ checkAccessible
63
+ });
64
+ results.forEach(item => {
65
+ CACHE[item.url] = item;
66
+ });
67
+ } else {
68
+ const misses = await (0, _urlEvaluation.evaluateURLs)(urls.filter(url => !CACHE[url]), {
69
+ checkAccessible
70
+ });
71
+ misses.forEach(item => {
72
+ CACHE[item.url] = item;
73
+ });
74
+ results = urls.map(url => CACHE[url]).sort((a, b) => b.score - a.score);
75
+ }
76
+ setUrlsState(results);
77
+ setLoading(false);
78
+ };
79
+ evaluate();
80
+ }
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [urls, disableCache, allCached]);
83
+ return {
84
+ urlsState,
85
+ loading,
86
+ recommendedUrlState,
87
+ recommendedUrl: recommendedUrlState === null || recommendedUrlState === void 0 ? void 0 : recommendedUrlState.url
88
+ };
89
+ }
90
+
91
+ /**
92
+ * 主要对 blocklet 访问 urls 进行评估
93
+ * @param {object} blocklet
94
+ */
95
+ function useBlockletUrlEvaluation(blocklet) {
96
+ const {
97
+ locale
98
+ } = (0, _react.useContext)(_context.LocaleContext);
99
+ const urls = (0, _react.useMemo)(() => {
100
+ if (!blocklet) {
101
+ return [];
102
+ }
103
+ // getBlockletUrlParams 的调用是必须的, 会根据 blocklet 状态决定是否添加 "__start__" 参数, 以保证 blocklet 启动按钮可以正确的跳转到启动页面
104
+ return (0, _util.getBlockletUrls)({
105
+ blocklet,
106
+ params: (0, _util.getBlockletUrlParams)(blocklet, locale)
107
+ });
108
+ }, [blocklet, locale]);
109
+ const {
110
+ loading,
111
+ recommendedUrlState,
112
+ recommendedUrl
113
+ } = useUrlEvaluation({
114
+ urls,
115
+ checkAccessible: ping
116
+ });
117
+ return {
118
+ urls,
119
+ loading,
120
+ recommendedUrlState,
121
+ recommendedUrl
122
+ };
123
+ }
124
+
125
+ /**
126
+ * 主要对 blocklet domains 对应的 urls 进行评估, 配合 DomainStatusProvider 使用
127
+ * @param {string[]} domains
128
+ */
129
+ function useDomainsAccessibility(domains) {
130
+ // 获取 blocklet domain 对应的访问 url
131
+ const urls = (0, _react.useMemo)(() => domains.map(item => (0, _util.getAccessUrl)(item)), [domains]);
132
+ const {
133
+ urlsState,
134
+ loading,
135
+ recommendedUrl
136
+ } = useUrlEvaluation({
137
+ urls,
138
+ checkAccessible: ping
139
+ });
140
+ let result;
141
+ if (loading) {
142
+ result = {
143
+ domainsAccessibility: domains.reduce((acc, cur) => _objectSpread(_objectSpread({}, acc), {}, {
144
+ [cur]: {
145
+ loading: true
146
+ }
147
+ }), {}),
148
+ recommendedDomain: null
149
+ };
150
+ } else {
151
+ var _urlsState$find;
152
+ const domainsAccessibility = urlsState.reduce((acc, cur) => {
153
+ // 检测对象是 domain, 但检测可访问性用的是 domain 对应的 ping url, 所以需要取 hostname 作为结果
154
+ const domain = new URL(cur.url).hostname;
155
+ acc[domain] = _objectSpread(_objectSpread({}, cur), {}, {
156
+ domain
157
+ });
158
+ return acc;
159
+ }, {});
160
+ // 从排好优先级的 urls 中选择第一个可访问的 url 作为 recommendedDomain (对于自定义域名, 可能存在评分最高但不可访问的情况) (#5195)
161
+ const accessibleUrl = ((_urlsState$find = urlsState.find(item => item.accessible)) === null || _urlsState$find === void 0 ? void 0 : _urlsState$find.url) || recommendedUrl;
162
+ result = {
163
+ domainsAccessibility,
164
+ recommendedDomain: accessibleUrl ? new URL(accessibleUrl).hostname : null
165
+ };
166
+ }
167
+ return result;
168
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useAppLogo;
7
+ var _urlJoin = _interopRequireDefault(require("url-join"));
8
+ var _node = require("../contexts/node");
9
+ var _util = require("../util");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function useAppLogo(_ref) {
12
+ var _window$env, _blocklet$meta;
13
+ let {
14
+ blocklet
15
+ } = _ref;
16
+ const {
17
+ inService
18
+ } = (0, _node.useNodeContext)();
19
+ const prefix = ((_window$env = window.env) === null || _window$env === void 0 ? void 0 : _window$env.apiPrefix) || '/';
20
+ const search = "?v=".concat(blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.version).concat((0, _util.isInstalling)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.status) ? '~' : '');
21
+ const logoUrl = (0, _urlJoin.default)(prefix, "/blocklet/logo/".concat(inService ? '' : blocklet.meta.did), search);
22
+ return {
23
+ logoUrl
24
+ };
25
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useAvatar;
7
+ var _urlJoin = _interopRequireDefault(require("url-join"));
8
+ var _constant = require("@abtnode/constant");
9
+ var _node = require("../contexts/node");
10
+ var _util = require("../util");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function useAvatar(_ref) {
13
+ var _blocklet$meta;
14
+ let {
15
+ blocklet,
16
+ ancestors = []
17
+ } = _ref;
18
+ const node = (0, _node.useNodeContext)();
19
+ const {
20
+ inService
21
+ } = node;
22
+ const search = "?v=".concat(blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.version).concat((0, _util.isDownloading)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.status) ? '~' : '');
23
+ let logoUrl = inService ? (0, _urlJoin.default)(_util.APP_PREFIX, _constant.WELLKNOWN_SERVICE_PATH_PREFIX, '/blocklet/logo-bundle', search) : (0, _urlJoin.default)(node.imgPrefix, 'blocklet.png');
24
+ if (blocklet.source === 'registry' && blocklet.deployedFrom && blocklet.meta.logo) {
25
+ logoUrl = (0, _urlJoin.default)(blocklet.deployedFrom, (0, _util.formatRegistryLogoPath)(blocklet.meta.bundleDid, blocklet.meta.logo), search);
26
+ } else {
27
+ const prefix = window.env.apiPrefix || '/';
28
+ const components = ancestors.concat(blocklet);
29
+ const list = inService ? components.slice(1) : components;
30
+ logoUrl = (0, _urlJoin.default)(prefix, "/blocklet/logo-bundle".concat(list.map(x => "/".concat(x.meta.did)).join('')), search);
31
+ }
32
+ return {
33
+ logoUrl,
34
+ inService
35
+ };
36
+ }
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useNavigation;
7
+ var _ahooks = require("ahooks");
8
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
9
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
10
+ var _omit = _interopRequireDefault(require("lodash/omit"));
11
+ var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
12
+ var _react = require("react");
13
+ var _nanoid = require("nanoid");
14
+ var _material = require("@mui/material");
15
+ var _parseNavigationFromBlocklet = require("@blocklet/meta/lib/parse-navigation-from-blocklet");
16
+ var _constant = require("@abtnode/constant");
17
+ var _blocklet = require("../contexts/blocklet");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ 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; }
21
+ 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; }
22
+ 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; }
23
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
24
+ 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); }
25
+ const BASE_LINK = '/';
26
+ const DEFAULT_SECTION = 'header';
27
+ // 默认注入的数据
28
+ // 需要指定一些内置的 id
29
+ const injectNavigationData = {
30
+ sessionManager: [{
31
+ id: '/sessionManager',
32
+ title: {
33
+ en: 'Manage',
34
+ zh: '管理'
35
+ },
36
+ section: ['sessionManager'],
37
+ icon: 'ion:settings-outline',
38
+ link: "".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/admin"),
39
+ role: ['owner', 'admin'],
40
+ from: 'tmpl'
41
+ }],
42
+ dashboard: [{
43
+ id: '/access',
44
+ title: {
45
+ en: 'Access',
46
+ zh: '访问控制'
47
+ },
48
+ role: ['owner', 'admin', 'member'],
49
+ section: ['dashboard'],
50
+ link: '',
51
+ from: 'tmpl',
52
+ items: [{
53
+ id: 'member',
54
+ title: {
55
+ en: 'Members',
56
+ zh: '成员'
57
+ },
58
+ icon: 'ant-design:user-outlined',
59
+ link: "".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/admin/members"),
60
+ from: 'tmpl'
61
+ }, {
62
+ id: 'passport',
63
+ title: {
64
+ en: 'Passport',
65
+ zh: '通行证'
66
+ },
67
+ icon: 'icon-park-outline:passport',
68
+ link: "".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/admin/passports"),
69
+ from: 'tmpl'
70
+ }]
71
+ }, {
72
+ id: '/dashboard',
73
+ title: 'Blocklet',
74
+ role: ['owner', 'admin'],
75
+ section: ['dashboard'],
76
+ link: '',
77
+ from: 'tmpl',
78
+ items: [{
79
+ id: 'dashboard',
80
+ title: {
81
+ en: 'Dashboard',
82
+ zh: '仪表盘'
83
+ },
84
+ icon: 'ant-design:dashboard-outlined',
85
+ link: "".concat(_constant.WELLKNOWN_SERVICE_PATH_PREFIX, "/admin"),
86
+ from: 'tmpl'
87
+ }]
88
+ }]
89
+ };
90
+ function isSameNavigation(a, b) {
91
+ if (a.section && b.section) {
92
+ return a.section === b.section && a.id === b.id;
93
+ }
94
+ return a.id === b.id;
95
+ }
96
+ function useNavigation() {
97
+ const {
98
+ blocklet,
99
+ actions
100
+ } = (0, _blocklet.useBlockletContext)();
101
+ const {
102
+ navigationList,
103
+ components,
104
+ builtinList
105
+ } = (0, _parseNavigationFromBlocklet.parseNavigation)(blocklet, {
106
+ beforeProcess(rawList) {
107
+ const copyList = (0, _cloneDeep.default)(rawList);
108
+ // 注入默认的 dashboard 菜单
109
+ injectNavigationData.dashboard.forEach(item => {
110
+ if (!copyList.some(x => x.id === item.id)) {
111
+ copyList.push(item);
112
+ }
113
+ });
114
+ // 注入默认的 sessionManager 菜单
115
+ if (!copyList.some(x => x.id && (x.section || []).includes('sessionManager'))) {
116
+ copyList.push(...injectNavigationData.sessionManager);
117
+ }
118
+ return copyList;
119
+ }
120
+ });
121
+ const state = (0, _ahooks.useReactive)({
122
+ rawNavigation: (0, _cloneDeep.default)(navigationList),
123
+ activeSection: DEFAULT_SECTION,
124
+ components
125
+ });
126
+ const navigation = (0, _react.useMemo)(() => {
127
+ return (0, _parseNavigationFromBlocklet.nestNavigationList)(state.rawNavigation);
128
+ }, [state.rawNavigation]);
129
+ const treeNavigation = (0, _react.useMemo)(() => {
130
+ const rawData = (0, _parseNavigationFromBlocklet.filterNavigation)(state.rawNavigation, components);
131
+ const navigationWithLink = (0, _parseNavigationFromBlocklet.joinLink)(rawData, components);
132
+ return (0, _parseNavigationFromBlocklet.cleanOrphanNavigation)(navigationWithLink);
133
+ }, [components, state.rawNavigation]);
134
+ function getNavigationFullLink(navigationItem) {
135
+ if (!navigationItem.id) return '';
136
+ const fullList = (0, _parseNavigationFromBlocklet.flatternNavigation)((0, _parseNavigationFromBlocklet.joinLink)(navigation, components));
137
+ const findItem = fullList.find(item => item.id === navigationItem.id);
138
+ // eslint-disable-next-line react/prop-types
139
+ function Uninstalled(_ref) {
140
+ let {
141
+ name
142
+ } = _ref;
143
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
144
+ label: "Uninstalled: ".concat(name),
145
+ color: "error",
146
+ size: "small",
147
+ variant: "outlined",
148
+ sx: {
149
+ fontSize: 10,
150
+ height: 20
151
+ }
152
+ });
153
+ }
154
+ if (findItem !== null && findItem !== void 0 && findItem.component) {
155
+ if (!components.some(x => x.name === findItem.component)) {
156
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Uninstalled, {
157
+ name: findItem.component
158
+ });
159
+ }
160
+ } else if (findItem.parent) {
161
+ const parent = fullList.find(x => x.id === findItem.parent);
162
+ if (parent !== null && parent !== void 0 && parent.component) {
163
+ if (!components.some(x => x.name === parent.component)) {
164
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Uninstalled, {
165
+ name: parent.component
166
+ });
167
+ }
168
+ }
169
+ }
170
+ return findItem === null || findItem === void 0 ? void 0 : findItem.link;
171
+ }
172
+ function updateActiveSection(activeSection) {
173
+ state.activeSection = activeSection;
174
+ }
175
+ function updateNavigationTree(tree) {
176
+ const list = [];
177
+ (0, _parseNavigationFromBlocklet.deepWalk)(tree, (treeItem, parent) => {
178
+ const tmpData = _objectSpread(_objectSpread({}, (0, _omit.default)(treeItem, ['children', 'expand'])), {}, {
179
+ parent: parent === null || parent === void 0 ? void 0 : parent.id
180
+ });
181
+ list.push(tmpData);
182
+ });
183
+ const unchangedNavigation = state.rawNavigation.filter(item => {
184
+ if (!state.activeSection) {
185
+ return false;
186
+ }
187
+ const findItem = list.find(v => isSameNavigation(v, item));
188
+ if (findItem) {
189
+ return !(0, _parseNavigationFromBlocklet.isMatchSection)(findItem.section, state.activeSection);
190
+ }
191
+ return true;
192
+ });
193
+ state.rawNavigation = [...unchangedNavigation, ...list];
194
+ }
195
+ /**
196
+ * 更新导航的一个节点
197
+ * @param {object} itemData 更新的数据
198
+ */
199
+ function updateNavigationItem(itemData) {
200
+ _saveNavigationChange([itemData]);
201
+ }
202
+ function _saveNavigationChange() {
203
+ let changed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
204
+ const updatedNavigation = state.rawNavigation.map(item => {
205
+ const findChanged = changed.find(changeItem => isSameNavigation(_objectSpread(_objectSpread({}, changeItem), {}, {
206
+ section: state.activeSection
207
+ }), item));
208
+ if (findChanged) {
209
+ return _objectSpread(_objectSpread({}, item), findChanged);
210
+ }
211
+ return item;
212
+ });
213
+ state.rawNavigation = updatedNavigation;
214
+ }
215
+ /**
216
+ * 删除一个导航节点
217
+ * @param {string} id 导航的 ID
218
+ */
219
+ function delNavigationItem(id) {
220
+ const relatedNavigationId = state.rawNavigation.filter(item => item.id === id || item.parent === id).map(item => item.id);
221
+ state.rawNavigation = state.rawNavigation.filter(item => !relatedNavigationId.includes(item.id));
222
+ }
223
+ /**
224
+ * 增加一个导航节点
225
+ * @param {object} params 导航数据
226
+ */
227
+ function addNavigationItem() {
228
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
229
+ const data = _objectSpread(_objectSpread({}, params), {}, {
230
+ // 新增的数据使用随机生成的 nanoid (A-Za-z0-9_-)
231
+ id: (0, _nanoid.nanoid)(),
232
+ section: state.activeSection,
233
+ visible: true
234
+ });
235
+ state.rawNavigation = [...state.rawNavigation, data];
236
+ }
237
+
238
+ /**
239
+ * 将树状结构转换为数据库存储的导航结构
240
+ * @param {array} tree 树状结构
241
+ * @returns array
242
+ */
243
+ // eslint-disable-next-line no-unused-vars
244
+ function tree2navigation(tree) {
245
+ const list = tree.map(item => {
246
+ const items = item.children || [];
247
+ return {
248
+ title: item.title,
249
+ icon: item.icon,
250
+ link: item.link,
251
+ items: tree2navigation(items),
252
+ section: item.section,
253
+ visible: item.visible,
254
+ parent: item.parent,
255
+ component: item.component,
256
+ role: item.role,
257
+ from: item.from,
258
+ id: item.id
259
+ };
260
+ });
261
+ return list;
262
+ }
263
+ /**
264
+ * 将数据库中的导航数据转换为树状结构
265
+ * @param {array} list 数据库中导航的结构
266
+ * @param {string} baseLink 当前 tree 的 base
267
+ * @returns 树状结构
268
+ */
269
+ function navigation2tree(list) {
270
+ let baseLink = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : BASE_LINK;
271
+ const tree = list.map(item => {
272
+ const findComponent = components.find(componentItem => componentItem.name === item.component);
273
+ const base = (findComponent === null || findComponent === void 0 ? void 0 : findComponent.link) || baseLink;
274
+ const children = item.items || [];
275
+ const {
276
+ link
277
+ } = item;
278
+ return {
279
+ title: item.title,
280
+ subtitle: getNavigationFullLink(item),
281
+ link,
282
+ icon: item.icon,
283
+ children: navigation2tree(children, link || BASE_LINK),
284
+ section: item.section,
285
+ visible: item.visible,
286
+ parent: item.parent,
287
+ component: item.component,
288
+ id: item.id,
289
+ role: item.role,
290
+ from: item.from,
291
+ __base: base
292
+ };
293
+ });
294
+ return tree;
295
+ }
296
+
297
+ /**
298
+ * 获取指定区块的导航数据
299
+ * @param {string} section 导航所属区块
300
+ * @returns 在指定导航区块内的导航数据
301
+ */
302
+ function getNavigation(section) {
303
+ const copyNavigation = (0, _cloneDeep.default)(navigation);
304
+ const filteredSectionNavigation = copyNavigation.filter(item => {
305
+ return (0, _parseNavigationFromBlocklet.isMatchSection)(item.section, section);
306
+ });
307
+ return navigation2tree(filteredSectionNavigation);
308
+ }
309
+
310
+ /**
311
+ * 将导航数据保存到后端
312
+ * @param {array} list 需要保存的导航数据
313
+ */
314
+ async function saveNavigationList(list) {
315
+ const data = list.map(item => {
316
+ return (0, _omitBy.default)(item, _isNil.default);
317
+ });
318
+ const formartedData = data.map(item => {
319
+ const tempData = _objectSpread({}, item);
320
+ if (tempData.role && Array.isArray(tempData.role)) {
321
+ tempData.role = JSON.stringify(tempData.role);
322
+ }
323
+ if (tempData.section && Array.isArray(tempData.section)) {
324
+ tempData.section = JSON.stringify(tempData.section);
325
+ }
326
+ if (tempData.title && tempData.title instanceof Object) {
327
+ tempData.title = JSON.stringify(tempData.title);
328
+ }
329
+ if (tempData.link && tempData.link instanceof Object) {
330
+ tempData.link = JSON.stringify(tempData.link);
331
+ }
332
+ return tempData;
333
+ });
334
+ // .filter((item) => item.from !== ' tmpl');
335
+ await actions.configNavigations(formartedData);
336
+ }
337
+ async function resetNavigation() {
338
+ await saveNavigationList([]);
339
+ state.rawNavigation = (0, _cloneDeep.default)(builtinList);
340
+ }
341
+ return {
342
+ state,
343
+ navigation: treeNavigation,
344
+ components,
345
+ getNavigationFullLink,
346
+ updateActiveSection,
347
+ updateNavigationItem,
348
+ delNavigationItem,
349
+ addNavigationItem,
350
+ updateNavigationTree,
351
+ getNavigation,
352
+ saveNavigationList,
353
+ resetNavigation
354
+ };
355
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = usePassportId;
7
+ var _useLocalStorage = _interopRequireDefault(require("react-use/lib/useLocalStorage"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function usePassportId() {
10
+ const [passportId, setPassportId, clearPassportId] = (0, _useLocalStorage.default)('passportId', '');
11
+ const getPassportId = () => {
12
+ setTimeout(() => {
13
+ clearPassportId();
14
+ }, 0);
15
+ return passportId || '';
16
+ };
17
+ return {
18
+ getPassportId,
19
+ setPassportId
20
+ };
21
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSubscription = useSubscription;
7
+ var _react = require("react");
8
+ // eslint-disable-next-line import/prefer-default-export
9
+ function useSubscription(_ref) {
10
+ let {
11
+ wsClient,
12
+ event,
13
+ cb = () => {},
14
+ deps = []
15
+ } = _ref;
16
+ (0, _react.useEffect)(() => {
17
+ // if deps has false value, do not sub
18
+ const shouldSub = wsClient && (!deps.length || deps.every(Boolean));
19
+ if (shouldSub) {
20
+ wsClient.on(event, cb);
21
+ }
22
+ return () => {
23
+ if (shouldSub) {
24
+ wsClient.off(event, cb);
25
+ }
26
+ };
27
+ }, deps); // eslint-disable-line
28
+ }
@@ -0,0 +1,5 @@
1
+ <svg width="65" height="16" viewBox="0 0 65 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path
3
+ d="M64.7071 8.70711C65.0976 8.31658 65.0976 7.68342 64.7071 7.29289L58.3431 0.928932C57.9526 0.538408 57.3195 0.538408 56.9289 0.928932C56.5384 1.31946 56.5384 1.95262 56.9289 2.34315L62.5858 8L56.9289 13.6569C56.5384 14.0474 56.5384 14.6805 56.9289 15.0711C57.3195 15.4616 57.9526 15.4616 58.3431 15.0711L64.7071 8.70711ZM0 9H64V7H0V9Z"
4
+ fill="#666666" />
5
+ </svg>
package/lib/index.js CHANGED
@@ -15,9 +15,6 @@ Object.defineProperty(exports, "LostPassport", {
15
15
  return _lostPassport.default;
16
16
  }
17
17
  });
18
-
19
18
  var _issuePassport = _interopRequireDefault(require("./issue-passport"));
20
-
21
19
  var _lostPassport = _interopRequireDefault(require("./lost-passport"));
22
-
23
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }