@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,620 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
9
+ var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
10
+ var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _material = require("@mui/material");
12
+ var _ahooks = require("ahooks");
13
+ var _omit = _interopRequireDefault(require("lodash/omit"));
14
+ var _pick = _interopRequireDefault(require("lodash/pick"));
15
+ var _values = _interopRequireDefault(require("lodash/values"));
16
+ var _without = _interopRequireDefault(require("lodash/without"));
17
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
18
+ var _isString = _interopRequireDefault(require("lodash/isString"));
19
+ var _isObject = _interopRequireDefault(require("lodash/isObject"));
20
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
21
+ var _react = require("react");
22
+ var _reactHookForm = require("react-hook-form");
23
+ var _react2 = require("@iconify/react");
24
+ var _notistack = require("notistack");
25
+ var _parseNavigationFromBlocklet = require("@blocklet/meta/lib/parse-navigation-from-blocklet");
26
+ var _urlJoin = _interopRequireDefault(require("url-join"));
27
+ var _index = require("ufo/dist/index.mjs");
28
+ var _isAbsoluteUrl = _interopRequireDefault(require("is-absolute-url"));
29
+ var _localeTabs = _interopRequireDefault(require("./locale-tabs"));
30
+ var _simpleSelect = _interopRequireDefault(require("./simple-select"));
31
+ var _team = require("../../../contexts/team");
32
+ var _jsxRuntime = require("react/jsx-runtime");
33
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
+ 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; }
35
+ 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; }
36
+ 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; }
37
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
38
+ 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); }
39
+ const MAX_TITLE_LENGTH = 24;
40
+ const defaultType = 'add';
41
+ const defaultLocale = 'en';
42
+ const initialFormState = {
43
+ title: {
44
+ [defaultLocale]: ''
45
+ },
46
+ link: {
47
+ [defaultLocale]: ''
48
+ }
49
+ };
50
+ function IconSuffix(_ref) {
51
+ let {
52
+ icon
53
+ } = _ref;
54
+ const [loaded, setLoaded] = (0, _react.useState)(false);
55
+ (0, _ahooks.useAsyncEffect)(async () => {
56
+ setLoaded(false);
57
+ await (0, _react2.loadIcon)(icon);
58
+ setLoaded(true);
59
+ }, [icon]);
60
+ if (icon) {
61
+ if (loaded) {
62
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
63
+ icon: icon
64
+ });
65
+ }
66
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
67
+ color: "#f06f6e",
68
+ icon: "ic:baseline-error"
69
+ });
70
+ }
71
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
72
+ icon: "codicon:blank"
73
+ });
74
+ }
75
+ IconSuffix.propTypes = {
76
+ icon: _propTypes.default.string.isRequired
77
+ };
78
+ const NavigationDialog = /*#__PURE__*/(0, _react.forwardRef)(function NavigationDialog(_ref2, ref) {
79
+ let {
80
+ section,
81
+ components,
82
+ rawNavigations
83
+ } = _ref2;
84
+ const {
85
+ roles
86
+ } = (0, _team.useTeamContext)();
87
+ const {
88
+ t,
89
+ locale
90
+ } = (0, _context.useLocaleContext)();
91
+ const saveFn = (0, _react.useRef)(() => {});
92
+ const [show, {
93
+ setFalse,
94
+ setTrue
95
+ }] = (0, _ahooks.useBoolean)(false);
96
+ const {
97
+ enqueueSnackbar
98
+ } = (0, _notistack.useSnackbar)();
99
+ const state = (0, _ahooks.useReactive)({
100
+ isRoot: true,
101
+ type: defaultType,
102
+ linkDisabled: false,
103
+ locale: defaultLocale,
104
+ formState: (0, _cloneDeep.default)(initialFormState),
105
+ get localeList() {
106
+ // eslint-disable-next-line react/no-this-in-sfc
107
+ return (0, _without.default)(Object.keys(this.formState.title), defaultLocale);
108
+ }
109
+ });
110
+ const {
111
+ handleSubmit,
112
+ control,
113
+ watch,
114
+ setValue,
115
+ clearErrors,
116
+ formState: {
117
+ errors
118
+ }
119
+ } = (0, _reactHookForm.useForm)({
120
+ mode: 'onChange',
121
+ defaultValues: {
122
+ id: undefined,
123
+ title: undefined,
124
+ icon: undefined,
125
+ link: undefined,
126
+ component: undefined,
127
+ parent: undefined,
128
+ role: []
129
+ }
130
+ });
131
+ (0, _react.useEffect)(() => {
132
+ setValue('title', state.formState.title[state.locale]);
133
+ setValue('link', state.formState.link[state.locale]);
134
+ // eslint-disable-next-line react-hooks/exhaustive-deps
135
+ }, [setValue, state.locale, show]);
136
+ const watchComponent = watch('component');
137
+ const watchTitle = watch('title');
138
+ const watchLink = watch('link');
139
+ const watchIcon = watch('icon');
140
+ const watchParent = watch('parent');
141
+ (0, _react.useEffect)(() => {
142
+ state.formState.title[state.locale] = watchTitle;
143
+ // eslint-disable-next-line react-hooks/exhaustive-deps
144
+ }, [watchTitle]);
145
+ (0, _react.useEffect)(() => {
146
+ state.formState.link[state.locale] = watchLink;
147
+ // eslint-disable-next-line react-hooks/exhaustive-deps
148
+ }, [watchLink]);
149
+ const selectedOption = (0, _react.useMemo)(() => {
150
+ const parentData = rawNavigations.find(item => {
151
+ if (watchComponent) {
152
+ const findComponent = components.find(x => x.name === watchComponent);
153
+ return findComponent.did === item.id;
154
+ }
155
+ return item.id === watchParent;
156
+ });
157
+ return parentData;
158
+ }, [components, rawNavigations, watchComponent, watchParent]);
159
+ const linkPrefix = (0, _react.useMemo)(() => {
160
+ if (selectedOption !== null && selectedOption !== void 0 && selectedOption.component) {
161
+ const findComponent = components.find(item => item.name === selectedOption.component);
162
+ const {
163
+ link
164
+ } = findComponent || {};
165
+ const stringLink = (0, _isObject.default)(link) ? link[state.locale] : link;
166
+ if (watchComponent) {
167
+ return (0, _index.withoutTrailingSlash)(stringLink);
168
+ }
169
+ const selectedLink = (0, _isObject.default)(selectedOption.link) ? selectedOption.link[state.locale] : selectedOption.link;
170
+ return (0, _index.withoutTrailingSlash)((0, _urlJoin.default)(stringLink, selectedLink || '/'));
171
+ }
172
+ return null;
173
+ }, [components, state.locale, selectedOption, watchComponent]);
174
+ const autocompleteOptions = (0, _react.useMemo)(() => {
175
+ const {
176
+ component
177
+ } = selectedOption || {};
178
+ const componentBlocklet = components.find(item => item.name === component);
179
+ const {
180
+ navigation = []
181
+ } = componentBlocklet || {};
182
+ const flatternedNavigation = (0, _parseNavigationFromBlocklet.flatternNavigation)(navigation, {
183
+ transform(item, parent) {
184
+ if (parent !== null && parent !== void 0 && parent.section) {
185
+ item.section = item.section || parent.section;
186
+ }
187
+ return item;
188
+ }
189
+ });
190
+ return flatternedNavigation.filter(item => item.link)
191
+ // 在指定 section 下只展示能够展示的 navigation
192
+ .filter(item => (0, _parseNavigationFromBlocklet.isMatchSection)(item.section, section)).map(item => {
193
+ return {
194
+ label: item.link,
195
+ title: item.title[locale] || item.title
196
+ };
197
+ });
198
+ }, [selectedOption, components, section, locale]);
199
+ const name = (0, _react.useMemo)(() => {
200
+ const typeMap = {
201
+ add: t('common.create'),
202
+ edit: t('common.edit')
203
+ };
204
+ const typeName = typeMap[state.type];
205
+ if (typeName) {
206
+ return "".concat(typeName, " ").concat(t('navigation.navigation'));
207
+ }
208
+ return '--';
209
+ }, [state.type, t]);
210
+ const reset = (0, _react.useCallback)(() => {
211
+ state.type = defaultType;
212
+ state.linkDisabled = false;
213
+ saveFn.current = () => {};
214
+ setValue('id', undefined);
215
+ setValue('icon', undefined);
216
+ setValue('title', undefined);
217
+ setValue('link', undefined);
218
+ setValue('component', undefined);
219
+ setValue('parent', undefined);
220
+ setValue('role', []);
221
+ state.formState = (0, _cloneDeep.default)(initialFormState);
222
+ clearErrors();
223
+ }, [clearErrors, setValue, state]);
224
+ const patchFormValues = (0, _react.useCallback)(function () {
225
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
226
+ if (state.localeList.length > 0) {
227
+ if (new Set((0, _values.default)(state.formState.title)).size > 1) {
228
+ params.title = state.formState.title;
229
+ }
230
+ if (new Set((0, _values.default)(state.formState.link)).size > 1) {
231
+ params.link = state.formState.link;
232
+ }
233
+ }
234
+ if ((0, _isEmpty.default)(params.role)) {
235
+ params.role = undefined;
236
+ }
237
+ return params;
238
+ }, [state.formState.link, state.formState.title, state.localeList]);
239
+ const close = (0, _react.useCallback)(() => {
240
+ setFalse();
241
+ setTimeout(() => {
242
+ reset();
243
+ });
244
+ }, [reset, setFalse]);
245
+ const add = (0, _react.useCallback)(function () {
246
+ let {
247
+ parent
248
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
249
+ let cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
250
+ state.type = 'add';
251
+ state.isRoot = !parent;
252
+ setValue('parent', parent === null || parent === void 0 ? void 0 : parent.id);
253
+ saveFn.current = params => {
254
+ cb(close, params);
255
+ };
256
+ setTrue();
257
+ }, [close, setTrue, setValue, state]);
258
+ const edit = (0, _react.useCallback)(function () {
259
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
260
+ let cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
261
+ const {
262
+ id,
263
+ title,
264
+ icon,
265
+ link,
266
+ parent,
267
+ component,
268
+ role = []
269
+ } = data;
270
+ setValue('id', id);
271
+ setValue('icon', icon);
272
+ if (data.from === 'tmpl') {
273
+ state.linkDisabled = true;
274
+ }
275
+ if ((0, _isString.default)(title)) {
276
+ state.formState.title = state.localeList.reduce((resData, localeItem) => {
277
+ resData[localeItem] = title;
278
+ return resData;
279
+ }, {
280
+ [defaultLocale]: title
281
+ });
282
+ } else if ((0, _isObject.default)(title)) {
283
+ state.formState.title = (0, _cloneDeep.default)(title);
284
+ } else {
285
+ state.formState.title = {};
286
+ }
287
+ if ((0, _isString.default)(link)) {
288
+ state.formState.link = state.localeList.reduce((resData, localeItem) => {
289
+ resData[localeItem] = link;
290
+ return resData;
291
+ }, {
292
+ [defaultLocale]: link
293
+ });
294
+ } else if ((0, _isObject.default)(link)) {
295
+ state.formState.link = (0, _cloneDeep.default)(link);
296
+ } else {
297
+ state.formState.link = {};
298
+ }
299
+ setValue('component', component);
300
+ setValue('parent', parent);
301
+ setValue('role', role || []);
302
+ setTrue();
303
+ state.type = 'edit';
304
+ state.isRoot = !parent;
305
+ saveFn.current = params => {
306
+ const pickData = (0, _pick.default)(params, ['id', 'title', 'icon', 'link', 'role']);
307
+ cb(close, pickData);
308
+ };
309
+ }, [close, setTrue, setValue, state]);
310
+ (0, _react.useImperativeHandle)(ref, () => {
311
+ return {
312
+ add,
313
+ edit,
314
+ close
315
+ };
316
+ }, [add, close, edit]);
317
+ function validTitle(raw) {
318
+ const value = raw === null || raw === void 0 ? void 0 : raw.trim();
319
+ if (!value) return t('common.requiredErrorText', {
320
+ name: t('navigation.form.title')
321
+ });
322
+ if (value.length > MAX_TITLE_LENGTH) return t('navigation.form.titleTooLong', {
323
+ len: MAX_TITLE_LENGTH
324
+ });
325
+ return true;
326
+ }
327
+ async function validIcon(raw) {
328
+ const value = raw === null || raw === void 0 ? void 0 : raw.trim();
329
+ if (value) {
330
+ try {
331
+ await (0, _react2.loadIcon)(value);
332
+ } catch (_unused) {
333
+ return t('navigation.form.invalidIcon');
334
+ }
335
+ }
336
+ return true;
337
+ }
338
+ function validLink(raw) {
339
+ const value = raw === null || raw === void 0 ? void 0 : raw.trim();
340
+ if (!value) {
341
+ if (!state.isRoot) {
342
+ return t('common.requiredErrorText', {
343
+ name: t('navigation.form.link')
344
+ });
345
+ }
346
+ return true;
347
+ }
348
+ if (!(0, _parseNavigationFromBlocklet.checkLink)(value)) {
349
+ return t('navigation.form.invalidLink');
350
+ }
351
+ return true;
352
+ }
353
+ const handleChangeLocale = (0, _react.useCallback)(currentLocale => {
354
+ state.locale = currentLocale;
355
+ if (!state.formState.title[currentLocale]) {
356
+ state.formState.title[currentLocale] = '';
357
+ }
358
+ if (!state.formState.link[currentLocale]) {
359
+ state.formState.link[currentLocale] = '';
360
+ }
361
+ setTimeout(() => {
362
+ clearErrors();
363
+ });
364
+ }, [clearErrors, state]);
365
+ const checkFormState = (0, _react.useCallback)(() => {
366
+ const {
367
+ title,
368
+ link
369
+ } = state.formState;
370
+ for (const key of Object.keys(title)) {
371
+ const validRes = validTitle(title[key]);
372
+ if (validRes !== true) {
373
+ return validRes;
374
+ }
375
+ }
376
+ for (const key of Object.keys(link)) {
377
+ const validRes = validLink(link[key]);
378
+ if (validRes !== true) {
379
+ return validRes;
380
+ }
381
+ }
382
+ return true;
383
+ // eslint-disable-next-line react-hooks/exhaustive-deps
384
+ }, [state.formState]);
385
+ const handleFormSubmit = (0, _react.useCallback)(params => {
386
+ const checkRes = checkFormState();
387
+ if (checkRes === true) {
388
+ saveFn.current(patchFormValues(params));
389
+ } else {
390
+ enqueueSnackbar(checkRes, {
391
+ variant: 'error'
392
+ });
393
+ }
394
+ }, [checkFormState, enqueueSnackbar, patchFormValues]);
395
+ const handleRemoveLocale = (0, _react.useCallback)(currentLocale => {
396
+ state.formState.title = (0, _omit.default)(state.formState.title, currentLocale);
397
+ state.formState.link = (0, _omit.default)(state.formState.link, currentLocale);
398
+ }, [state.formState]);
399
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dialog.default, {
400
+ open: show,
401
+ title: name,
402
+ onClose: close,
403
+ actions: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
404
+ onClick: handleSubmit(handleFormSubmit),
405
+ color: "primary",
406
+ autoFocus: true,
407
+ variant: "contained",
408
+ children: t('common.confirm')
409
+ }),
410
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_localeTabs.default, {
411
+ sx: {
412
+ mb: 1
413
+ },
414
+ onChange: handleChangeLocale,
415
+ onRemoveLocale: handleRemoveLocale,
416
+ locales: state.localeList
417
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
418
+ noValidate: true,
419
+ autoComplete: "off",
420
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
421
+ name: "title",
422
+ control: control,
423
+ rules: {
424
+ validate: validTitle
425
+ },
426
+ render: _ref3 => {
427
+ var _errors$title, _errors$title2;
428
+ let {
429
+ field
430
+ } = _ref3;
431
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread({
432
+ fullWidth: true,
433
+ variant: "outlined",
434
+ margin: "dense",
435
+ required: true,
436
+ placeholder: t('navigation.form.titlePlaceholder'),
437
+ label: t('navigation.form.title'),
438
+ disabled: state.isEdit,
439
+ error: !!(errors !== null && errors !== void 0 && (_errors$title = errors.title) !== null && _errors$title !== void 0 && _errors$title.message),
440
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$title2 = errors.title) === null || _errors$title2 === void 0 ? void 0 : _errors$title2.message) || ' '
441
+ }, field));
442
+ }
443
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
444
+ name: "icon",
445
+ control: control,
446
+ rules: {
447
+ validate: validIcon
448
+ },
449
+ render: _ref4 => {
450
+ var _errors$icon, _errors$icon2;
451
+ let {
452
+ field
453
+ } = _ref4;
454
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({
455
+ fullWidth: true,
456
+ variant: "outlined",
457
+ margin: "dense",
458
+ placeholder: t('navigation.form.iconPlaceholder'),
459
+ label: t('navigation.form.icon'),
460
+ error: !!(errors !== null && errors !== void 0 && (_errors$icon = errors.icon) !== null && _errors$icon !== void 0 && _errors$icon.message),
461
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$icon2 = errors.icon) === null || _errors$icon2 === void 0 ? void 0 : _errors$icon2.message) || /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
462
+ display: "flex",
463
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
464
+ component: "a",
465
+ href: "https://icones.js.org",
466
+ target: "_blank",
467
+ display: "flex",
468
+ alignItems: "center",
469
+ children: [t('navigation.form.findMoreIcon'), ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
470
+ style: {
471
+ marginLeft: 4
472
+ },
473
+ icon: "radix-icons:external-link"
474
+ })]
475
+ })
476
+ })
477
+ }, field), {}, {
478
+ InputProps: {
479
+ endAdornment: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputAdornment, {
480
+ position: "end",
481
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
482
+ sx: {
483
+ cursor: 'default'
484
+ },
485
+ disableFocusRipple: true,
486
+ disableRipple: true,
487
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconSuffix, {
488
+ icon: watchIcon
489
+ })
490
+ })
491
+ })
492
+ }
493
+ }));
494
+ }
495
+ }), state.isRoot && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
496
+ name: "component",
497
+ control: control,
498
+ render: _ref5 => {
499
+ var _errors$component, _errors$component2;
500
+ let {
501
+ field
502
+ } = _ref5;
503
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_simpleSelect.default, _objectSpread({
504
+ fullWidth: true,
505
+ margin: "dense",
506
+ disabled: state.type === 'edit',
507
+ label: t('navigation.form.component'),
508
+ placeholer: t('navigation.form.componentPlaceholder'),
509
+ options: components.map(item => ({
510
+ title: item.title,
511
+ value: item.name,
512
+ description: item.link
513
+ })),
514
+ error: !!(errors !== null && errors !== void 0 && (_errors$component = errors.component) !== null && _errors$component !== void 0 && _errors$component.message),
515
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$component2 = errors.component) === null || _errors$component2 === void 0 ? void 0 : _errors$component2.message) || ' '
516
+ }, field));
517
+ }
518
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
519
+ name: "link",
520
+ control: control,
521
+ rules: {
522
+ validate: validLink
523
+ },
524
+ render: _ref6 => {
525
+ var _errors$link3, _errors$link4;
526
+ let {
527
+ field
528
+ } = _ref6;
529
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, {
530
+ fullWidth: true,
531
+ margin: "dense",
532
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Autocomplete, _objectSpread(_objectSpread({
533
+ disablePortal: true,
534
+ freeSolo: true,
535
+ blurOnSelect: true,
536
+ autoSelect: true,
537
+ fullWidth: true,
538
+ disabled: state.linkDisabled,
539
+ isOptionEqualToValue: option => option.label,
540
+ options: autocompleteOptions,
541
+ renderInput: params => {
542
+ var _errors$link, _errors$link2;
543
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({}, params), {}, {
544
+ placeholder: t('navigation.form.linkPlaceholder'),
545
+ label: t('navigation.form.link'),
546
+ error: !!(errors !== null && errors !== void 0 && (_errors$link = errors.link) !== null && _errors$link !== void 0 && _errors$link.message),
547
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$link2 = errors.link) === null || _errors$link2 === void 0 ? void 0 : _errors$link2.message) || '/abc/bcd or /abc or https://arcblock.io'
548
+ // FIXME: 添加了 startAdornment 后,autocomplete 选项无法显示,之后换成 antd 的 autocomplete 可以解决这个问题
549
+ ,
550
+ InputProps: {
551
+ startAdornment: linkPrefix ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputAdornment, {
552
+ position: "start",
553
+ sx: {
554
+ textDecoration: (0, _isAbsoluteUrl.default)(watchLink || '') ? 'line-through' : ''
555
+ },
556
+ children: linkPrefix
557
+ }) : null
558
+ }
559
+ }));
560
+ },
561
+ renderOption: (props, option) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, _objectSpread(_objectSpread({
562
+ component: "li"
563
+ }, props), {}, {
564
+ children: [option.label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
565
+ marginLeft: 1,
566
+ component: "span",
567
+ variant: "body2",
568
+ color: "text.secondary",
569
+ children: option.title
570
+ })]
571
+ })),
572
+ error: !!(errors !== null && errors !== void 0 && (_errors$link3 = errors.link) !== null && _errors$link3 !== void 0 && _errors$link3.message),
573
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$link4 = errors.link) === null || _errors$link4 === void 0 ? void 0 : _errors$link4.message) || ' ',
574
+ margin: "dense"
575
+ }, field), {}, {
576
+ onChange: () => {},
577
+ onInputChange: (e, value) => {
578
+ field.onChange(value);
579
+ }
580
+ }))
581
+ });
582
+ }
583
+ }), ['dashboard', 'sessionManager'].includes(section) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
584
+ name: "role",
585
+ control: control,
586
+ render: _ref7 => {
587
+ var _errors$role, _errors$role2;
588
+ let {
589
+ field
590
+ } = _ref7;
591
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_simpleSelect.default, _objectSpread({
592
+ fullWidth: true,
593
+ multiple: true,
594
+ margin: "dense",
595
+ label: t('navigation.form.role'),
596
+ placeholer: t('navigation.form.rolePlaceholder'),
597
+ options: roles.map(role => ({
598
+ title: role.title,
599
+ value: role.name
600
+ })),
601
+ error: !!(errors !== null && errors !== void 0 && (_errors$role = errors.role) !== null && _errors$role !== void 0 && _errors$role.message),
602
+ helperText: (errors === null || errors === void 0 ? void 0 : (_errors$role2 = errors.role) === null || _errors$role2 === void 0 ? void 0 : _errors$role2.message) || ' '
603
+ }, field));
604
+ }
605
+ })]
606
+ })]
607
+ });
608
+ });
609
+ NavigationDialog.propTypes = {
610
+ section: _propTypes.default.string,
611
+ components: _propTypes.default.array,
612
+ rawNavigations: _propTypes.default.array
613
+ };
614
+ NavigationDialog.defaultProps = {
615
+ section: '',
616
+ components: [],
617
+ rawNavigations: []
618
+ };
619
+ var _default = NavigationDialog;
620
+ exports.default = _default;