@abtnode/ux 1.16.14-beta-ab7f615e → 1.16.14-beta-cb53c14b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/actions.js +97 -0
- package/es/analytics/card.js +92 -0
- package/es/analytics/chart.js +96 -0
- package/es/analytics/cpu.js +36 -0
- package/es/analytics/disk.js +111 -0
- package/es/analytics/memory.js +72 -0
- package/es/analytics/runtime.js +173 -0
- package/es/analytics/traffic.js +259 -0
- package/es/blocklet/access/config-access.js +307 -0
- package/es/blocklet/access/index.js +216 -0
- package/es/blocklet/actions.js +474 -0
- package/es/blocklet/add-cert.js +177 -0
- package/es/blocklet/agreement-app.js +21 -0
- package/es/blocklet/agreement.js +127 -0
- package/es/blocklet/app-avatar.js +57 -0
- package/es/blocklet/audit-logs.js +259 -0
- package/es/blocklet/blocklet-source.js +48 -0
- package/es/blocklet/bundle-avatar.js +64 -0
- package/es/blocklet/component/add.js +1308 -0
- package/es/blocklet/component/configuration.js +122 -0
- package/es/blocklet/component/delete.js +134 -0
- package/es/blocklet/component/environment.js +370 -0
- package/es/blocklet/component/index.js +975 -0
- package/es/blocklet/component/line.js +20 -0
- package/es/blocklet/component/navigation/locale-tabs.js +225 -0
- package/es/blocklet/component/navigation/navigation-actions.js +112 -0
- package/es/blocklet/component/navigation/navigation-dialog.js +607 -0
- package/es/blocklet/component/navigation/navigation-preview.js +101 -0
- package/es/blocklet/component/navigation/simple-select.js +124 -0
- package/es/blocklet/component/select-store.js +155 -0
- package/es/blocklet/component/setting.js +109 -0
- package/es/blocklet/component/sortable-tree.js +126 -0
- package/es/blocklet/component/space-connector.js +199 -0
- package/es/blocklet/component/space-selector.js +178 -0
- package/es/blocklet/component/start.js +101 -0
- package/es/blocklet/component/store-blocklet-list.js +200 -0
- package/es/blocklet/component/switch-control.js +57 -0
- package/es/blocklet/config-navigation.js +331 -0
- package/es/blocklet/configuration.js +603 -0
- package/es/blocklet/disk-info.js +75 -0
- package/es/blocklet/icons.js +18 -0
- package/es/blocklet/install-from-url.js +337 -0
- package/es/blocklet/log.js +90 -0
- package/es/blocklet/migration.js +149 -0
- package/es/blocklet/mode.js +19 -0
- package/es/blocklet/notification/email.js +257 -0
- package/es/blocklet/notification/index.js +49 -0
- package/es/blocklet/oauth/auth0.js +145 -0
- package/es/blocklet/oauth/common-settings.js +133 -0
- package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
- package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
- package/es/blocklet/oauth/federated-join-dialog.js +111 -0
- package/es/blocklet/oauth/federated-site-list.js +338 -0
- package/es/blocklet/oauth/federated.js +81 -0
- package/es/blocklet/oauth/index.js +69 -0
- package/es/blocklet/overview.js +293 -0
- package/es/blocklet/page-group.js +19 -0
- package/es/blocklet/preferences/app-sk.js +142 -0
- package/es/blocklet/preferences/index.js +305 -0
- package/es/blocklet/purchase/common.js +95 -0
- package/es/blocklet/purchase/component-purchase.js +237 -0
- package/es/blocklet/purchase/index.js +4 -0
- package/es/blocklet/router/action/add-domain-alias.js +167 -0
- package/es/blocklet/router/action/add-rule.js +211 -0
- package/es/blocklet/router/action/config-routing-rule.js +232 -0
- package/es/blocklet/router/action/delete-domain-alias.js +99 -0
- package/es/blocklet/router/action/delete-rule.js +108 -0
- package/es/blocklet/router/action/update-rule.js +209 -0
- package/es/blocklet/router/domain-actions.js +64 -0
- package/es/blocklet/router/domain-status.js +88 -0
- package/es/blocklet/router/rule-actions.js +66 -0
- package/es/blocklet/router/rule-list.js +190 -0
- package/es/blocklet/router/util.js +131 -0
- package/es/blocklet/runtime-info.js +68 -0
- package/es/blocklet/status.js +91 -0
- package/es/blocklet/storage/action.js +134 -0
- package/es/blocklet/storage/backups.js +241 -0
- package/es/blocklet/storage/connect-to.js +373 -0
- package/es/blocklet/storage/connected.js +198 -0
- package/es/blocklet/storage/delete.js +113 -0
- package/es/blocklet/storage/disconnect.js +243 -0
- package/es/blocklet/storage/index.js +19 -0
- package/es/blocklet/storage/item.js +558 -0
- package/es/blocklet/storage/preview-nft.js +286 -0
- package/es/blocklet/transfer-owner.js +198 -0
- package/es/blocklet/types.js +18 -0
- package/es/blocklet/util.js +145 -0
- package/es/blocklet/version.js +141 -0
- package/es/card-selector.js +134 -0
- package/es/certificate.js +105 -0
- package/es/chain.js +13 -0
- package/es/click-to-copy.js +22 -0
- package/es/confirm.js +149 -0
- package/es/contexts/audit-log.js +152 -0
- package/es/contexts/blocklet.js +10 -0
- package/es/contexts/deleting-blocklets.js +70 -0
- package/es/contexts/node.js +17 -0
- package/es/contexts/session.js +8 -0
- package/es/contexts/team.js +10 -0
- package/es/delete-confirm.js +121 -0
- package/es/did-address.js +46 -0
- package/es/dot.js +14 -0
- package/es/exchange-passport.js +102 -0
- package/es/form/form-select-input.js +184 -0
- package/es/form/form-text-input.js +178 -0
- package/es/form/form-wrapper.js +88 -0
- package/es/form/input-triggers.js +98 -0
- package/es/form/required.js +8 -0
- package/es/hooks/blocklet.js +229 -0
- package/es/hooks/confirm.js +90 -0
- package/es/hooks/mobile-width.js +11 -0
- package/es/hooks/url-evaluation.js +155 -0
- package/es/hooks/use-app-logo.js +16 -0
- package/es/hooks/use-backup-progress.js +31 -0
- package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
- package/es/hooks/use-bundle-logo.js +27 -0
- package/es/hooks/use-navigation.js +347 -0
- package/es/hooks/use-passport-id.js +14 -0
- package/es/hooks/use-subscription.js +22 -0
- package/es/icons/empty-space-nft.svg +59 -0
- package/es/icons/empty-spaces-nft.svg +58 -0
- package/es/icons/long-arrow.svg +5 -0
- package/es/icons/space-connected.svg +3 -0
- package/es/icons/space-disconnect.svg +3 -0
- package/es/index.js +3 -0
- package/es/invitation/invitation-app.js +58 -0
- package/es/invitation/invitation-login.js +68 -0
- package/es/invitation/invitation-passport.js +144 -0
- package/es/invitation/invitation-receive.js +138 -0
- package/es/invitation/invitation-success.js +93 -0
- package/es/invitation/invitation-user.js +90 -0
- package/es/invitation/invitation.js +90 -0
- package/es/issue-passport.js +142 -0
- package/es/launch-blocklet/content-layout.js +58 -0
- package/es/launch-blocklet/page-header.js +43 -0
- package/es/layout/addon.js +114 -0
- package/es/layout/feedback.js +55 -0
- package/es/locales/en.js +1534 -0
- package/es/locales/index.js +9 -0
- package/es/locales/zh.js +1537 -0
- package/es/logs/clock.js +11 -0
- package/es/logs/download.js +132 -0
- package/es/logs/log-terminal.js +253 -0
- package/es/lost-passport.js +452 -0
- package/es/nav-logo.js +219 -0
- package/es/passport-tag.js +43 -0
- package/es/permission.js +57 -0
- package/es/relative-time.js +53 -0
- package/es/result-message.js +11 -0
- package/es/schema-form/color-input.js +98 -0
- package/es/schema-form/common-prop-types.js +13 -0
- package/es/schema-form/index.js +215 -0
- package/es/schema-form/passport-input.js +54 -0
- package/es/schema-form/text-input.js +57 -0
- package/es/store/add.js +179 -0
- package/es/store/delete.js +96 -0
- package/es/store/item.js +76 -0
- package/es/subscription.js +144 -0
- package/es/table-icons.js +34 -0
- package/es/table.js +52 -0
- package/es/tag.js +21 -0
- package/es/team/members/actions.js +89 -0
- package/es/team/members/index.js +636 -0
- package/es/team/members/invitations.js +188 -0
- package/es/team/members/invite-member.js +208 -0
- package/es/team/members/issue-passport.js +152 -0
- package/es/team/members/member.js +408 -0
- package/es/team/members/passport-issuances.js +155 -0
- package/es/team/members/passports.js +364 -0
- package/es/team/members/toggle-user-approval.js +122 -0
- package/es/team/members/transfer-node.js +256 -0
- package/es/team/members/util.js +14 -0
- package/es/team/passports/color.js +126 -0
- package/es/team/passports/detail.js +312 -0
- package/es/team/passports/index.js +282 -0
- package/es/team/passports/mutate-role.js +198 -0
- package/es/team/passports/trusted-factories.js +221 -0
- package/es/team/passports/trusted-factory.js +343 -0
- package/es/team/passports/trusted-issuer.js +296 -0
- package/es/team/passports/trusted-issuers.js +226 -0
- package/es/team/search-input.js +46 -0
- package/es/team/styles/dialog.js +72 -0
- package/es/team/styles/list-header.js +31 -0
- package/es/util/api.js +6 -0
- package/es/util/constants.js +2 -0
- package/es/util/index.js +598 -0
- package/es/util/mode.js +4 -0
- package/es/util/space-gateway.js +51 -0
- package/es/util/spaces.js +151 -0
- package/es/who-can-access/config.js +38 -0
- package/es/wrap-locale.js +15 -0
- package/lib/blocklet/component/space-connector.js +1 -1
- package/lib/blocklet/component/space-selector.js +1 -1
- package/lib/blocklet/storage/backups.js +1 -1
- package/lib/blocklet/storage/connect-to.js +1 -1
- package/lib/blocklet/storage/connected.js +1 -1
- package/lib/blocklet/storage/disconnect.js +1 -1
- package/lib/blocklet/storage/index.js +1 -1
- package/lib/blocklet/storage/item.js +1 -1
- package/lib/invitation/invitation-receive.js +1 -1
- package/lib/team/passports/trusted-factory.js +1 -1
- package/package.json +81 -18
package/es/permission.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { useSessionContext } from './contexts/session';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export default function Permission({
|
|
5
|
+
permission,
|
|
6
|
+
role,
|
|
7
|
+
component,
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
10
|
+
const {
|
|
11
|
+
session
|
|
12
|
+
} = useSessionContext();
|
|
13
|
+
let can = true;
|
|
14
|
+
const permissions = [].concat(permission).filter(Boolean);
|
|
15
|
+
const roles = [].concat(role).filter(Boolean);
|
|
16
|
+
if (permissions.length) {
|
|
17
|
+
const userPermissions = session.user && session.user.permissions || [];
|
|
18
|
+
can = permissions.some(p => userPermissions.includes(p));
|
|
19
|
+
}
|
|
20
|
+
if (can && roles.length) {
|
|
21
|
+
can = roles.includes(session.user.role);
|
|
22
|
+
}
|
|
23
|
+
if (typeof component === 'function') {
|
|
24
|
+
return component(can);
|
|
25
|
+
}
|
|
26
|
+
if (typeof children === 'function') {
|
|
27
|
+
return children(can);
|
|
28
|
+
}
|
|
29
|
+
if (can) {
|
|
30
|
+
return component || children || null;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
export function withPermission(Component, permissionName, role) {
|
|
35
|
+
return function WithPermission(props) {
|
|
36
|
+
return /*#__PURE__*/_jsx(Permission, {
|
|
37
|
+
permission: permissionName,
|
|
38
|
+
role: role,
|
|
39
|
+
children: hasPermission => /*#__PURE__*/_jsx(Component, {
|
|
40
|
+
...props,
|
|
41
|
+
hasPermission: hasPermission
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
Permission.propTypes = {
|
|
47
|
+
permission: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
48
|
+
role: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
49
|
+
component: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
|
50
|
+
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node])
|
|
51
|
+
};
|
|
52
|
+
Permission.defaultProps = {
|
|
53
|
+
permission: '',
|
|
54
|
+
role: '',
|
|
55
|
+
component: null,
|
|
56
|
+
children: null
|
|
57
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import prettyMs from 'pretty-ms-i18n';
|
|
3
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
4
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
5
|
+
import { formatPrettyMsLocale, formatToDatetime } from './util';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export default function RelativeTime({
|
|
8
|
+
value
|
|
9
|
+
}) {
|
|
10
|
+
const {
|
|
11
|
+
t,
|
|
12
|
+
locale
|
|
13
|
+
} = useLocaleContext();
|
|
14
|
+
if (!value) {
|
|
15
|
+
return '-';
|
|
16
|
+
}
|
|
17
|
+
const prettyOption = {
|
|
18
|
+
locale: formatPrettyMsLocale(locale),
|
|
19
|
+
compact: true
|
|
20
|
+
};
|
|
21
|
+
const valTime = new Date(value).getTime();
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
if (valTime > now) {
|
|
24
|
+
const time = prettyMs(valTime - now, prettyOption);
|
|
25
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
26
|
+
title: formatToDatetime(value, locale),
|
|
27
|
+
placement: "top-end",
|
|
28
|
+
enterTouchDelay: 0,
|
|
29
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
30
|
+
children: t('common.afterTime', {
|
|
31
|
+
time
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const time = prettyMs(now - valTime, prettyOption);
|
|
37
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
38
|
+
title: formatToDatetime(value, locale),
|
|
39
|
+
placement: "top-end",
|
|
40
|
+
enterTouchDelay: 0,
|
|
41
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
42
|
+
children: t('common.timeAgo', {
|
|
43
|
+
time
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
RelativeTime.propTypes = {
|
|
49
|
+
value: PropTypes.any
|
|
50
|
+
};
|
|
51
|
+
RelativeTime.defaultProps = {
|
|
52
|
+
value: ''
|
|
53
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import styled from '@emotion/styled';
|
|
2
|
+
import ResultMessage from '@blocklet/launcher-layout/lib/launch-result-message';
|
|
3
|
+
const StyledResultMessage = styled(ResultMessage)`
|
|
4
|
+
&& .result-footer {
|
|
5
|
+
height: 120px;
|
|
6
|
+
> div {
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
export default StyledResultMessage;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import Popover from '@mui/material/Popover';
|
|
4
|
+
import { ChromePicker } from 'react-color';
|
|
5
|
+
import commonPropTypes from './common-prop-types';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
export default function ColorInput({
|
|
9
|
+
editing,
|
|
10
|
+
value,
|
|
11
|
+
onChange
|
|
12
|
+
}) {
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
const colorElm = useRef();
|
|
15
|
+
const colorValue = useRef(value);
|
|
16
|
+
|
|
17
|
+
// auto open color picker when editing, should wait the useRef to be ready
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let timer = null;
|
|
20
|
+
if (editing) {
|
|
21
|
+
timer = setTimeout(() => {
|
|
22
|
+
setOpen(true);
|
|
23
|
+
}, 50);
|
|
24
|
+
}
|
|
25
|
+
return () => {
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
};
|
|
28
|
+
}, [editing]);
|
|
29
|
+
const onColorChange = color => {
|
|
30
|
+
colorValue.current = color;
|
|
31
|
+
onChange(color);
|
|
32
|
+
};
|
|
33
|
+
const handleEnterKeyDown = () => {
|
|
34
|
+
setOpen(false);
|
|
35
|
+
onChange(colorValue.current);
|
|
36
|
+
};
|
|
37
|
+
const ReadView = /*#__PURE__*/_jsx(Box, {
|
|
38
|
+
className: "form-item-input slot",
|
|
39
|
+
px: 1,
|
|
40
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
41
|
+
display: "flex",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
children: [value, value !== 'auto' && /*#__PURE__*/_jsx("div", {
|
|
44
|
+
style: {
|
|
45
|
+
marginLeft: 4,
|
|
46
|
+
backgroundColor: value,
|
|
47
|
+
width: '1em',
|
|
48
|
+
height: '1em',
|
|
49
|
+
borderRadius: '0.2em'
|
|
50
|
+
}
|
|
51
|
+
})]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
const EditView = /*#__PURE__*/_jsxs(Box, {
|
|
55
|
+
display: "flex",
|
|
56
|
+
flexGrow: 1,
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
height: "40px",
|
|
59
|
+
onKeyDown: handleEnterKeyDown,
|
|
60
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
61
|
+
display: "flex",
|
|
62
|
+
alignItems: "center",
|
|
63
|
+
onClick: () => setOpen(true),
|
|
64
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
65
|
+
ref: colorElm,
|
|
66
|
+
style: {
|
|
67
|
+
flexShrink: 0,
|
|
68
|
+
marginLeft: '8px',
|
|
69
|
+
backgroundColor: value,
|
|
70
|
+
width: '32px',
|
|
71
|
+
height: '32px',
|
|
72
|
+
boxSizing: 'border-box',
|
|
73
|
+
borderRadius: '8px',
|
|
74
|
+
border: '1px solid #eee',
|
|
75
|
+
cursor: value === 'auto' ? 'default' : 'pointer'
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}), /*#__PURE__*/_jsx(Popover, {
|
|
79
|
+
open: open,
|
|
80
|
+
anchorEl: colorElm.current,
|
|
81
|
+
onClose: () => setOpen(false),
|
|
82
|
+
anchorOrigin: {
|
|
83
|
+
vertical: 'bottom',
|
|
84
|
+
horizontal: 'center'
|
|
85
|
+
},
|
|
86
|
+
transformOrigin: {
|
|
87
|
+
vertical: 'top',
|
|
88
|
+
horizontal: 'center'
|
|
89
|
+
},
|
|
90
|
+
children: /*#__PURE__*/_jsx(ChromePicker, {
|
|
91
|
+
color: value,
|
|
92
|
+
onChange: c => onColorChange(c.hex)
|
|
93
|
+
})
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
return editing ? EditView : ReadView;
|
|
97
|
+
}
|
|
98
|
+
ColorInput.propTypes = commonPropTypes;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
export default {
|
|
3
|
+
description: PropTypes.string,
|
|
4
|
+
editing: PropTypes.bool,
|
|
5
|
+
onChange: PropTypes.func,
|
|
6
|
+
required: PropTypes.bool,
|
|
7
|
+
// eslint-disable-next-line react/no-unused-prop-types
|
|
8
|
+
value: PropTypes.any,
|
|
9
|
+
// eslint-disable-next-line react/no-unused-prop-types
|
|
10
|
+
componentProps: PropTypes.object,
|
|
11
|
+
render: PropTypes.func,
|
|
12
|
+
renderFormItem: PropTypes.func
|
|
13
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { useState, useRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from '@emotion/styled';
|
|
4
|
+
import Box from '@mui/material/Box';
|
|
5
|
+
import EditIcon from '@arcblock/icons/lib/EditIcon';
|
|
6
|
+
import CloseIcon from '@mui/icons-material/Close';
|
|
7
|
+
import DoneIcon from '@mui/icons-material/Done';
|
|
8
|
+
import IconButton from '@mui/material/IconButton';
|
|
9
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
10
|
+
import ColorInput from './color-input';
|
|
11
|
+
import TextInput from './text-input';
|
|
12
|
+
import PassportInput from './passport-input';
|
|
13
|
+
import Required from '../form/required';
|
|
14
|
+
import FormWrapper from '../form/form-wrapper';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
|
+
function getComponent(item, {
|
|
19
|
+
editing = false
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
componentType = 'input',
|
|
23
|
+
render,
|
|
24
|
+
renderFormItem
|
|
25
|
+
} = item;
|
|
26
|
+
// if provided renderItem and editing is true, use it
|
|
27
|
+
if (editing && renderFormItem) {
|
|
28
|
+
return renderFormItem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// if provided render and editing is false, use it
|
|
32
|
+
if (!editing && render) {
|
|
33
|
+
return render;
|
|
34
|
+
}
|
|
35
|
+
const componentMap = {
|
|
36
|
+
input: TextInput,
|
|
37
|
+
color: ColorInput,
|
|
38
|
+
passport: PassportInput
|
|
39
|
+
};
|
|
40
|
+
return componentMap[componentType?.toLowerCase()];
|
|
41
|
+
}
|
|
42
|
+
export default function SchemaForm({
|
|
43
|
+
schema,
|
|
44
|
+
loading,
|
|
45
|
+
value,
|
|
46
|
+
defaultValue,
|
|
47
|
+
onChange,
|
|
48
|
+
style,
|
|
49
|
+
disabled
|
|
50
|
+
}) {
|
|
51
|
+
const isControlled = Object.prototype.toString.call(value) === '[object Object]';
|
|
52
|
+
const [editingItem, setEditingItem] = useState(null);
|
|
53
|
+
const [formValues, setFormValues] = useState(isControlled ? value : defaultValue);
|
|
54
|
+
const editingItemInitialValue = useRef();
|
|
55
|
+
function onFormItemChange(item, changeValue, action) {
|
|
56
|
+
const {
|
|
57
|
+
key,
|
|
58
|
+
secure
|
|
59
|
+
} = item;
|
|
60
|
+
const oldValue = formValues[key];
|
|
61
|
+
const isChanged = oldValue !== changeValue;
|
|
62
|
+
const newValues = {
|
|
63
|
+
...formValues,
|
|
64
|
+
[key]: changeValue
|
|
65
|
+
};
|
|
66
|
+
if (isChanged) {
|
|
67
|
+
setFormValues(newValues);
|
|
68
|
+
}
|
|
69
|
+
onChange({
|
|
70
|
+
[key]: changeValue
|
|
71
|
+
}, {
|
|
72
|
+
allValues: newValues,
|
|
73
|
+
action,
|
|
74
|
+
currentItem: item
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// hide secure text after confirm
|
|
78
|
+
if (action === 'confirm' && secure) {
|
|
79
|
+
setFormValues({
|
|
80
|
+
...formValues,
|
|
81
|
+
[key]: '__encrypted__'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (['confirm', 'cancel'].includes(action)) {
|
|
85
|
+
onItemEditingStatusChange(null);
|
|
86
|
+
} else {
|
|
87
|
+
onItemEditingStatusChange(item);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function onItemEditingStatusChange(item) {
|
|
91
|
+
if (item) {
|
|
92
|
+
editingItemInitialValue.current = formValues[item.key];
|
|
93
|
+
setEditingItem(item);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
editingItemInitialValue.current = null;
|
|
97
|
+
setEditingItem(null);
|
|
98
|
+
}
|
|
99
|
+
function getValue(item, {
|
|
100
|
+
editing = false
|
|
101
|
+
}) {
|
|
102
|
+
const {
|
|
103
|
+
key
|
|
104
|
+
} = item;
|
|
105
|
+
const currentValue = isControlled ? value[key] : formValues[key];
|
|
106
|
+
if (currentValue === '__encrypted__') {
|
|
107
|
+
if (!editing) {
|
|
108
|
+
return '******';
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
return currentValue;
|
|
113
|
+
}
|
|
114
|
+
return /*#__PURE__*/_jsx(StyledFormWrapper, {
|
|
115
|
+
className: "form",
|
|
116
|
+
style: style,
|
|
117
|
+
children: schema?.map(x => {
|
|
118
|
+
const {
|
|
119
|
+
key,
|
|
120
|
+
description,
|
|
121
|
+
required,
|
|
122
|
+
hidden = false,
|
|
123
|
+
componentProps = {}
|
|
124
|
+
} = x;
|
|
125
|
+
if (hidden) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const editing = !!(editingItem && key === editingItem.key);
|
|
129
|
+
const currentValue = getValue(x, {
|
|
130
|
+
editing
|
|
131
|
+
});
|
|
132
|
+
// get component by componentType
|
|
133
|
+
const CurrentComponent = getComponent(x, {
|
|
134
|
+
editing
|
|
135
|
+
});
|
|
136
|
+
const renderComponentProps = {
|
|
137
|
+
inputProps: {
|
|
138
|
+
'data-cy': 'schema-form-item-component'
|
|
139
|
+
},
|
|
140
|
+
key,
|
|
141
|
+
description,
|
|
142
|
+
editing,
|
|
143
|
+
value: currentValue,
|
|
144
|
+
onChange: (changeValue, action = 'change') => onFormItemChange(x, changeValue, action),
|
|
145
|
+
componentProps
|
|
146
|
+
};
|
|
147
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
148
|
+
className: "form-item",
|
|
149
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
150
|
+
className: "form-item-label",
|
|
151
|
+
style: {
|
|
152
|
+
color: required && !currentValue ? '#ff0000' : '#333'
|
|
153
|
+
},
|
|
154
|
+
children: [description, required && /*#__PURE__*/_jsx(Required, {})]
|
|
155
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
|
156
|
+
className: "form-item-body",
|
|
157
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
158
|
+
className: "form-item-input",
|
|
159
|
+
children: /*#__PURE__*/_jsx(CurrentComponent, {
|
|
160
|
+
...renderComponentProps
|
|
161
|
+
})
|
|
162
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
163
|
+
className: "form-item-action",
|
|
164
|
+
children: editing ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
165
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
166
|
+
"data-cy": "schema-form-item-confirm",
|
|
167
|
+
onClick: () => {
|
|
168
|
+
onFormItemChange(x, currentValue, 'confirm');
|
|
169
|
+
},
|
|
170
|
+
disabled: disabled || loading,
|
|
171
|
+
size: "large",
|
|
172
|
+
children: loading ? /*#__PURE__*/_jsx(CircularProgress, {
|
|
173
|
+
size: 24
|
|
174
|
+
}) : /*#__PURE__*/_jsx(DoneIcon, {})
|
|
175
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
176
|
+
"data-cy": "schema-form-item-cancel",
|
|
177
|
+
onClick: () => {
|
|
178
|
+
onFormItemChange(x, editingItemInitialValue.current, 'cancel');
|
|
179
|
+
},
|
|
180
|
+
disabled: disabled || loading,
|
|
181
|
+
size: "large",
|
|
182
|
+
children: /*#__PURE__*/_jsx(CloseIcon, {})
|
|
183
|
+
})]
|
|
184
|
+
}) : /*#__PURE__*/_jsx(IconButton, {
|
|
185
|
+
"data-cy": "schema-form-item-edit",
|
|
186
|
+
onClick: () => {
|
|
187
|
+
onFormItemChange(x, formValues[key], 'edit');
|
|
188
|
+
},
|
|
189
|
+
disabled: disabled || editingItem,
|
|
190
|
+
size: "large",
|
|
191
|
+
children: /*#__PURE__*/_jsx(EditIcon, {})
|
|
192
|
+
})
|
|
193
|
+
})]
|
|
194
|
+
})]
|
|
195
|
+
}, key);
|
|
196
|
+
})
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
SchemaForm.propTypes = {
|
|
200
|
+
schema: PropTypes.array.isRequired,
|
|
201
|
+
loading: PropTypes.bool,
|
|
202
|
+
onChange: PropTypes.func.isRequired,
|
|
203
|
+
value: PropTypes.object,
|
|
204
|
+
defaultValue: PropTypes.object,
|
|
205
|
+
style: PropTypes.object,
|
|
206
|
+
disabled: PropTypes.bool
|
|
207
|
+
};
|
|
208
|
+
SchemaForm.defaultProps = {
|
|
209
|
+
loading: false,
|
|
210
|
+
value: undefined,
|
|
211
|
+
defaultValue: {},
|
|
212
|
+
style: {},
|
|
213
|
+
disabled: false
|
|
214
|
+
};
|
|
215
|
+
const StyledFormWrapper = styled(FormWrapper)``;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import createPassportSvg from '@abtnode/auth/lib/util/create-passport-svg';
|
|
4
|
+
import { getPassportColorFromDid } from '@arcblock/nft-display';
|
|
5
|
+
import { getDisplayName } from '@blocklet/meta/lib/util';
|
|
6
|
+
import ColorInput from './color-input';
|
|
7
|
+
import commonPropTypes from './common-prop-types';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
export default function PassportInput({
|
|
11
|
+
editing,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
componentProps,
|
|
15
|
+
...rest
|
|
16
|
+
}) {
|
|
17
|
+
const {
|
|
18
|
+
blocklet
|
|
19
|
+
} = componentProps;
|
|
20
|
+
const color = value === 'auto' ? getPassportColorFromDid(blocklet.appDid) : value;
|
|
21
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
22
|
+
display: "flex",
|
|
23
|
+
alignItems: "center",
|
|
24
|
+
children: [/*#__PURE__*/_jsx("img", {
|
|
25
|
+
style: {
|
|
26
|
+
width: 96,
|
|
27
|
+
marginRight: 12
|
|
28
|
+
},
|
|
29
|
+
alt: "",
|
|
30
|
+
src: createPassportSvg({
|
|
31
|
+
title: 'Owner',
|
|
32
|
+
issuer: getDisplayName(blocklet),
|
|
33
|
+
issuerDid: blocklet.appDid,
|
|
34
|
+
ownerName: 'Your Name',
|
|
35
|
+
ownerDid: blocklet.appDid,
|
|
36
|
+
isDataUrl: true,
|
|
37
|
+
preferredColor: value || 'auto'
|
|
38
|
+
})
|
|
39
|
+
}), /*#__PURE__*/_jsx(ColorInput, {
|
|
40
|
+
...rest,
|
|
41
|
+
editing: editing,
|
|
42
|
+
value: editing ? color : value,
|
|
43
|
+
onChange: onChange,
|
|
44
|
+
componentProps: componentProps
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
PassportInput.propTypes = {
|
|
49
|
+
...commonPropTypes,
|
|
50
|
+
componentProps: PropTypes.shape({
|
|
51
|
+
blocklet: PropTypes.object.isRequired
|
|
52
|
+
}).isRequired
|
|
53
|
+
};
|
|
54
|
+
PassportInput.defaultProps = {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import TextField from '@mui/material/TextField';
|
|
4
|
+
import commonPropTypes from './common-prop-types';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export default function TextInput({
|
|
7
|
+
editing,
|
|
8
|
+
description,
|
|
9
|
+
value,
|
|
10
|
+
onChange,
|
|
11
|
+
componentProps,
|
|
12
|
+
...rest
|
|
13
|
+
}) {
|
|
14
|
+
const {
|
|
15
|
+
placeholder
|
|
16
|
+
} = componentProps;
|
|
17
|
+
const inputValue = useRef(value);
|
|
18
|
+
|
|
19
|
+
// enter keydown
|
|
20
|
+
const handleKeydown = e => {
|
|
21
|
+
if (e.key === 'Enter') {
|
|
22
|
+
onChange(inputValue.current, 'confirm');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const onInputChange = changeValue => {
|
|
26
|
+
inputValue.current = changeValue;
|
|
27
|
+
onChange(changeValue);
|
|
28
|
+
};
|
|
29
|
+
if (editing) {
|
|
30
|
+
return /*#__PURE__*/_jsx(TextField, {
|
|
31
|
+
style: {
|
|
32
|
+
flex: 1
|
|
33
|
+
},
|
|
34
|
+
fullWidth: true,
|
|
35
|
+
value: value,
|
|
36
|
+
onChange: e => {
|
|
37
|
+
e.persist();
|
|
38
|
+
onInputChange(e.target.value);
|
|
39
|
+
},
|
|
40
|
+
autoFocus: true,
|
|
41
|
+
size: "small",
|
|
42
|
+
variant: "outlined",
|
|
43
|
+
placeholder: description || placeholder,
|
|
44
|
+
onKeyDown: handleKeydown,
|
|
45
|
+
...rest
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
49
|
+
px: 1,
|
|
50
|
+
className: "form-item-input slot",
|
|
51
|
+
children: value
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
TextInput.propTypes = commonPropTypes;
|
|
55
|
+
TextInput.defaultProps = {
|
|
56
|
+
componentProps: {}
|
|
57
|
+
};
|