@abtnode/ux 1.16.26-beta-5251ab18 → 1.16.26-beta-351de484
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/blocklet/{oauth → authentication/federated}/federated-detail-dialog.js +2 -2
- package/es/blocklet/{oauth → authentication/federated}/federated-join-dialog.js +2 -2
- package/es/blocklet/{oauth → authentication/federated}/federated-site-list.js +3 -3
- package/es/blocklet/{oauth/federated.js → authentication/federated/index.js} +1 -1
- package/es/blocklet/{oauth → authentication}/index.js +7 -5
- package/es/blocklet/authentication/oauth/apple.js +198 -0
- package/es/blocklet/{oauth → authentication/oauth}/auth0.js +27 -7
- package/es/blocklet/authentication/oauth/drag-item.js +177 -0
- package/es/blocklet/authentication/oauth/github.js +145 -0
- package/es/blocklet/authentication/oauth/google.js +144 -0
- package/es/blocklet/authentication/oauth/index.js +122 -0
- package/es/blocklet/preferences/index.js +6 -6
- package/es/blocklet/publish/connect-store-list.js +8 -6
- package/es/blocklet/publish/create-release.js +16 -7
- package/es/blocklet/publish/project-list.js +30 -3
- package/es/blocklet/storage/action.js +8 -4
- package/es/blocklet/storage/item.js +2 -1
- package/es/confirm.js +5 -2
- package/es/contexts/blocklet-storage.js +0 -4
- package/es/layout/feedback.js +7 -4
- package/es/locales/ar.js +34 -5
- package/es/locales/de.js +35 -6
- package/es/locales/en.js +34 -5
- package/es/locales/es.js +35 -6
- package/es/locales/fr.js +35 -6
- package/es/locales/hi.js +35 -6
- package/es/locales/i18n.db +0 -0
- package/es/locales/id.js +35 -6
- package/es/locales/ja.js +34 -5
- package/es/locales/ko.js +35 -6
- package/es/locales/pt.js +35 -6
- package/es/locales/ru.js +34 -5
- package/es/locales/th.js +34 -5
- package/es/locales/vi.js +34 -5
- package/es/locales/zh-tw.js +34 -5
- package/es/locales/zh.js +35 -6
- package/es/store/connect-actions.js +14 -5
- package/es/store/delete.js +7 -3
- package/es/store/item.js +99 -20
- package/es/team/members/index.js +16 -13
- package/es/team/members/member.js +2 -7
- package/lib/blocklet/{oauth → authentication/federated}/federated-detail-dialog.js +2 -2
- package/lib/blocklet/{oauth → authentication/federated}/federated-join-dialog.js +2 -2
- package/lib/blocklet/{oauth → authentication/federated}/federated-site-list.js +3 -3
- package/lib/blocklet/{oauth/federated.js → authentication/federated/index.js} +1 -1
- package/lib/blocklet/{oauth → authentication}/index.js +7 -5
- package/lib/blocklet/authentication/oauth/apple.js +226 -0
- package/lib/blocklet/authentication/oauth/auth0.js +189 -0
- package/lib/blocklet/authentication/oauth/drag-item.js +185 -0
- package/lib/blocklet/{oauth/auth0.js → authentication/oauth/github.js} +26 -25
- package/lib/blocklet/authentication/oauth/google.js +166 -0
- package/lib/blocklet/authentication/oauth/index.js +136 -0
- package/lib/blocklet/preferences/index.js +6 -6
- package/lib/blocklet/publish/connect-store-list.js +9 -8
- package/lib/blocklet/publish/create-release.js +16 -6
- package/lib/blocklet/publish/project-list.js +29 -2
- package/lib/blocklet/storage/action.js +10 -6
- package/lib/blocklet/storage/item.js +2 -1
- package/lib/confirm.js +7 -4
- package/lib/contexts/blocklet-storage.js +0 -4
- package/lib/layout/feedback.js +6 -3
- package/lib/locales/ar.js +34 -5
- package/lib/locales/de.js +35 -6
- package/lib/locales/en.js +34 -5
- package/lib/locales/es.js +35 -6
- package/lib/locales/fr.js +35 -6
- package/lib/locales/hi.js +35 -6
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +35 -6
- package/lib/locales/ja.js +34 -5
- package/lib/locales/ko.js +35 -6
- package/lib/locales/pt.js +35 -6
- package/lib/locales/ru.js +34 -5
- package/lib/locales/th.js +34 -5
- package/lib/locales/vi.js +34 -5
- package/lib/locales/zh-tw.js +34 -5
- package/lib/locales/zh.js +35 -6
- package/lib/store/connect-actions.js +14 -5
- package/lib/store/delete.js +7 -3
- package/lib/store/item.js +111 -19
- package/lib/team/members/index.js +13 -11
- package/lib/team/members/member.js +1 -6
- package/package.json +32 -22
- /package/es/blocklet/{oauth → authentication}/common-settings.js +0 -0
- /package/es/blocklet/{oauth → authentication/federated}/federated-invite-dialog.js +0 -0
- /package/lib/blocklet/{oauth → authentication}/common-settings.js +0 -0
- /package/lib/blocklet/{oauth → authentication/federated}/federated-invite-dialog.js +0 -0
|
@@ -12,8 +12,8 @@ import Dialog from '@arcblock/ux/lib/Dialog';
|
|
|
12
12
|
import StarsIcon from '@mui/icons-material/Stars';
|
|
13
13
|
import isUrl from 'is-url';
|
|
14
14
|
import joinUrl from 'url-join';
|
|
15
|
-
import { useBlockletContext } from '
|
|
16
|
-
import { useNodeContext } from '
|
|
15
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
16
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
17
17
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
18
18
|
const FederatedDetailDialog = /*#__PURE__*/forwardRef((props, ref) => {
|
|
19
19
|
const {
|
|
@@ -8,8 +8,8 @@ import { TextField } from '@mui/material';
|
|
|
8
8
|
import { useTheme } from '@arcblock/ux/lib/Theme';
|
|
9
9
|
import noop from 'lodash/noop';
|
|
10
10
|
import isUrl from 'is-url';
|
|
11
|
-
import { useBlockletContext } from '
|
|
12
|
-
import { useNodeContext } from '
|
|
11
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
12
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
const FederatedJoinDialog = /*#__PURE__*/forwardRef((props, ref) => {
|
|
15
15
|
const {
|
|
@@ -11,9 +11,9 @@ import { useCreation, useMemoizedFn } from 'ahooks';
|
|
|
11
11
|
import Button from '@arcblock/ux/lib/Button';
|
|
12
12
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
13
13
|
import { BLOCKLET_CONFIGURABLE_KEY } from '@blocklet/constant';
|
|
14
|
-
import { useBlockletContext } from '
|
|
15
|
-
import { useNodeContext } from '
|
|
16
|
-
import useConfirm from '
|
|
14
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
15
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
16
|
+
import useConfirm from '../../../hooks/confirm';
|
|
17
17
|
import FederatedDetailDialog from './federated-detail-dialog';
|
|
18
18
|
import FederatedInviteDialog from './federated-invite-dialog';
|
|
19
19
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -6,7 +6,7 @@ import { useMemoizedFn } from 'ahooks';
|
|
|
6
6
|
import Button from '@arcblock/ux/lib/Button';
|
|
7
7
|
import { Divider } from '@mui/material';
|
|
8
8
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
9
|
-
import { useBlockletContext } from '
|
|
9
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
10
10
|
import FederatedSiteList from './federated-site-list';
|
|
11
11
|
import FederatedJoinDialog from './federated-join-dialog';
|
|
12
12
|
import FederatedInviteDialog from './federated-invite-dialog';
|
|
@@ -4,7 +4,7 @@ import Tabs from '@arcblock/ux/lib/Tabs';
|
|
|
4
4
|
import { Box } from '@mui/material';
|
|
5
5
|
import { useCreation } from 'ahooks';
|
|
6
6
|
import { useContext, useState } from 'react';
|
|
7
|
-
import
|
|
7
|
+
import OAuthLogin from './oauth';
|
|
8
8
|
import CommonSettings from './common-settings';
|
|
9
9
|
import FederatedLogin from './federated';
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -30,9 +30,9 @@ function OAuth() {
|
|
|
30
30
|
label: /*#__PURE__*/_jsx(Box, {
|
|
31
31
|
textAlign: "center",
|
|
32
32
|
width: "100%",
|
|
33
|
-
children:
|
|
33
|
+
children: t('oauth.oauth')
|
|
34
34
|
}),
|
|
35
|
-
value: '
|
|
35
|
+
value: 'oauth'
|
|
36
36
|
}, {
|
|
37
37
|
label: /*#__PURE__*/_jsx(Box, {
|
|
38
38
|
textAlign: "center",
|
|
@@ -41,9 +41,11 @@ function OAuth() {
|
|
|
41
41
|
}),
|
|
42
42
|
value: 'more'
|
|
43
43
|
}];
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
// tabs[0].value
|
|
46
|
+
const [currentTab, setCurrentTab] = useState('oauth');
|
|
45
47
|
const contents = useCreation(() => ({
|
|
46
|
-
|
|
48
|
+
oauth: /*#__PURE__*/_jsx(OAuthLogin, {}),
|
|
47
49
|
federated: /*#__PURE__*/_jsx(FederatedLogin, {}),
|
|
48
50
|
more: /*#__PURE__*/_jsx(Box, {
|
|
49
51
|
children: /*#__PURE__*/_jsx(Empty, {
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Box, Button, FormControl, FormControlLabel, TextField } from '@mui/material';
|
|
2
|
+
import pick from 'lodash/pick';
|
|
3
|
+
import { useMemoizedFn } from 'ahooks';
|
|
4
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
5
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
7
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
8
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
9
|
+
import SwitchControl from '../../component/switch-control';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
function OAuthApple() {
|
|
12
|
+
const {
|
|
13
|
+
api
|
|
14
|
+
} = useNodeContext();
|
|
15
|
+
const {
|
|
16
|
+
blocklet
|
|
17
|
+
} = useBlockletContext();
|
|
18
|
+
const {
|
|
19
|
+
t
|
|
20
|
+
} = useLocaleContext();
|
|
21
|
+
const did = blocklet?.meta?.did;
|
|
22
|
+
const authData = Object.assign({
|
|
23
|
+
enabled: false,
|
|
24
|
+
teamId: '',
|
|
25
|
+
serviceId: '',
|
|
26
|
+
keyId: '',
|
|
27
|
+
authKey: ''
|
|
28
|
+
}, blocklet?.settings?.oauth?.apple || {});
|
|
29
|
+
const {
|
|
30
|
+
handleSubmit,
|
|
31
|
+
control,
|
|
32
|
+
formState,
|
|
33
|
+
watch,
|
|
34
|
+
reset
|
|
35
|
+
} = useForm({
|
|
36
|
+
defaultValues: pick(authData, ['enabled', 'teamId', 'serviceId', 'keyId', 'authKey'])
|
|
37
|
+
});
|
|
38
|
+
const enabled = watch('enabled');
|
|
39
|
+
const onSubmit = useMemoizedFn(async data => {
|
|
40
|
+
try {
|
|
41
|
+
const {
|
|
42
|
+
blocklet: blockletChanged
|
|
43
|
+
} = await api.configOAuth({
|
|
44
|
+
input: {
|
|
45
|
+
did,
|
|
46
|
+
oauth: JSON.stringify({
|
|
47
|
+
apple: data
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const defaultValues = Object.assign({
|
|
52
|
+
enabled: false,
|
|
53
|
+
teamId: '',
|
|
54
|
+
serviceId: '',
|
|
55
|
+
keyId: '',
|
|
56
|
+
authKey: ''
|
|
57
|
+
}, blockletChanged?.settings?.oauth?.apple || {});
|
|
58
|
+
// 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
|
|
59
|
+
reset(defaultValues);
|
|
60
|
+
Toast.success(t('oauth.saveSuccess'));
|
|
61
|
+
} catch (err) {
|
|
62
|
+
Toast.error(err.message || t('oauth.saveFailed'));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const validateTeamId = useMemoizedFn(val => {
|
|
66
|
+
if (!val?.trim()) {
|
|
67
|
+
return t('oauth.apple.teamIdDescribe');
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
const validateServiceId = useMemoizedFn(val => {
|
|
72
|
+
if (!val?.trim()) {
|
|
73
|
+
return t('oauth.apple.serviceIdDescribe');
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
const validateKeyId = useMemoizedFn(val => {
|
|
78
|
+
if (!val?.trim()) {
|
|
79
|
+
return t('oauth.apple.keyIdDescribe');
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
const validateAuthKey = useMemoizedFn(val => {
|
|
84
|
+
if (!val?.trim()) {
|
|
85
|
+
return t('oauth.apple.authKeyDescribe');
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
});
|
|
89
|
+
const noop = useMemoizedFn(() => true);
|
|
90
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
91
|
+
children: /*#__PURE__*/_jsxs("form", {
|
|
92
|
+
onSubmit: handleSubmit(onSubmit),
|
|
93
|
+
disabled: true,
|
|
94
|
+
children: [/*#__PURE__*/_jsx(Controller, {
|
|
95
|
+
name: "enabled",
|
|
96
|
+
control: control,
|
|
97
|
+
render: ({
|
|
98
|
+
field
|
|
99
|
+
}) => /*#__PURE__*/_jsx(FormControlLabel, {
|
|
100
|
+
control: /*#__PURE__*/_jsx(SwitchControl, {
|
|
101
|
+
checked: field.value,
|
|
102
|
+
style: {
|
|
103
|
+
marginRight: '6px'
|
|
104
|
+
},
|
|
105
|
+
...field
|
|
106
|
+
}),
|
|
107
|
+
label: t('oauth.apple.enable'),
|
|
108
|
+
sx: {
|
|
109
|
+
marginBottom: 2,
|
|
110
|
+
ml: 1
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
114
|
+
name: "teamId",
|
|
115
|
+
control: control,
|
|
116
|
+
rules: {
|
|
117
|
+
validate: enabled ? validateTeamId : noop
|
|
118
|
+
},
|
|
119
|
+
render: ({
|
|
120
|
+
field
|
|
121
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
122
|
+
fullWidth: true,
|
|
123
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
124
|
+
...field,
|
|
125
|
+
error: !!formState.errors[field.name],
|
|
126
|
+
label: t('oauth.apple.teamId'),
|
|
127
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
128
|
+
disabled: !enabled
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
132
|
+
name: "serviceId",
|
|
133
|
+
control: control,
|
|
134
|
+
rules: {
|
|
135
|
+
validate: enabled ? validateServiceId : noop
|
|
136
|
+
},
|
|
137
|
+
render: ({
|
|
138
|
+
field
|
|
139
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
140
|
+
fullWidth: true,
|
|
141
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
142
|
+
...field,
|
|
143
|
+
error: !!formState.errors[field.name],
|
|
144
|
+
label: t('oauth.apple.serviceId'),
|
|
145
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
146
|
+
disabled: !enabled
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
150
|
+
name: "keyId",
|
|
151
|
+
control: control,
|
|
152
|
+
rules: {
|
|
153
|
+
validate: enabled ? validateKeyId : noop
|
|
154
|
+
},
|
|
155
|
+
render: ({
|
|
156
|
+
field
|
|
157
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
158
|
+
fullWidth: true,
|
|
159
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
160
|
+
...field,
|
|
161
|
+
error: !!formState.errors[field.name],
|
|
162
|
+
label: t('oauth.apple.keyId'),
|
|
163
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
164
|
+
disabled: !enabled
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
168
|
+
name: "authKey",
|
|
169
|
+
control: control,
|
|
170
|
+
rules: {
|
|
171
|
+
validate: enabled ? validateAuthKey : noop
|
|
172
|
+
},
|
|
173
|
+
render: ({
|
|
174
|
+
field
|
|
175
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
176
|
+
fullWidth: true,
|
|
177
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
178
|
+
...field,
|
|
179
|
+
type: "password",
|
|
180
|
+
multiline: true,
|
|
181
|
+
rows: 4,
|
|
182
|
+
label: t('oauth.apple.authKey'),
|
|
183
|
+
error: !!formState.errors[field.name],
|
|
184
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
185
|
+
disabled: !enabled
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
189
|
+
type: "submit",
|
|
190
|
+
variant: "contained",
|
|
191
|
+
onSubmit: handleSubmit(onSubmit),
|
|
192
|
+
disabled: !formState.isDirty,
|
|
193
|
+
children: t('oauth.save')
|
|
194
|
+
})]
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
export default OAuthApple;
|
|
@@ -4,9 +4,9 @@ import { useMemoizedFn } from 'ahooks';
|
|
|
4
4
|
import { Controller, useForm } from 'react-hook-form';
|
|
5
5
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
6
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
7
|
-
import { useNodeContext } from '
|
|
8
|
-
import { useBlockletContext } from '
|
|
9
|
-
import SwitchControl from '
|
|
7
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
8
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
9
|
+
import SwitchControl from '../../component/switch-control';
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
function OAuthAuth0() {
|
|
12
12
|
const {
|
|
@@ -18,12 +18,12 @@ function OAuthAuth0() {
|
|
|
18
18
|
const {
|
|
19
19
|
t
|
|
20
20
|
} = useLocaleContext();
|
|
21
|
-
// TODO: @zhanghan 将来需要换成 permanent did
|
|
22
21
|
const did = blocklet?.meta?.did;
|
|
23
22
|
const auth0 = Object.assign({
|
|
24
23
|
enabled: false,
|
|
25
24
|
domain: '',
|
|
26
|
-
clientId: ''
|
|
25
|
+
clientId: '',
|
|
26
|
+
clientSecret: ''
|
|
27
27
|
}, blocklet?.settings?.oauth?.auth0 || {});
|
|
28
28
|
const {
|
|
29
29
|
handleSubmit,
|
|
@@ -32,7 +32,7 @@ function OAuthAuth0() {
|
|
|
32
32
|
watch,
|
|
33
33
|
reset
|
|
34
34
|
} = useForm({
|
|
35
|
-
defaultValues: pick(auth0, ['domain', 'clientId', 'enabled'])
|
|
35
|
+
defaultValues: pick(auth0, ['domain', 'clientId', 'clientSecret', 'enabled'])
|
|
36
36
|
});
|
|
37
37
|
const enabled = watch('enabled');
|
|
38
38
|
const onSubmit = useMemoizedFn(async data => {
|
|
@@ -50,7 +50,8 @@ function OAuthAuth0() {
|
|
|
50
50
|
const defaultValues = Object.assign({
|
|
51
51
|
enabled: false,
|
|
52
52
|
domain: '',
|
|
53
|
-
clientId: ''
|
|
53
|
+
clientId: '',
|
|
54
|
+
clientSecret: ''
|
|
54
55
|
}, blockletChanged?.settings?.oauth?.auth0 || {});
|
|
55
56
|
// 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
|
|
56
57
|
reset(defaultValues);
|
|
@@ -131,6 +132,25 @@ function OAuthAuth0() {
|
|
|
131
132
|
disabled: !enabled
|
|
132
133
|
})
|
|
133
134
|
})
|
|
135
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
136
|
+
name: "clientSecret",
|
|
137
|
+
control: control,
|
|
138
|
+
rules: {
|
|
139
|
+
validate: noop
|
|
140
|
+
},
|
|
141
|
+
render: ({
|
|
142
|
+
field
|
|
143
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
144
|
+
fullWidth: true,
|
|
145
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
146
|
+
...field,
|
|
147
|
+
type: "password",
|
|
148
|
+
error: !!formState.errors[field.name],
|
|
149
|
+
label: t('oauth.auth0.clientSecret'),
|
|
150
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
151
|
+
disabled: !enabled
|
|
152
|
+
})
|
|
153
|
+
})
|
|
134
154
|
}), /*#__PURE__*/_jsx(Button, {
|
|
135
155
|
type: "submit",
|
|
136
156
|
variant: "contained",
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { Box, IconButton, Typography } from '@mui/material';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import { useDrag, useDrop } from 'react-dnd';
|
|
5
|
+
import { temp as colors } from '@arcblock/ux/lib/Colors';
|
|
6
|
+
import { Icon } from '@iconify/react';
|
|
7
|
+
import DragIndicatorIcon from '@iconify-icons/material-symbols/drag-indicator';
|
|
8
|
+
import KeyboardArrowDownRoundedIcon from '@iconify-icons/material-symbols/keyboard-arrow-down-rounded';
|
|
9
|
+
import { useMemoizedFn } from 'ahooks';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line no-unused-vars
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export default function DragItem({
|
|
14
|
+
title,
|
|
15
|
+
id,
|
|
16
|
+
children,
|
|
17
|
+
index,
|
|
18
|
+
onMove,
|
|
19
|
+
defaultExpand,
|
|
20
|
+
onEnd
|
|
21
|
+
}) {
|
|
22
|
+
const [expand, setExpand] = useState(defaultExpand);
|
|
23
|
+
const dropRef = useRef(null);
|
|
24
|
+
const dragRef = useRef(null);
|
|
25
|
+
const [{
|
|
26
|
+
handlerId
|
|
27
|
+
}, drop] = useDrop({
|
|
28
|
+
accept: 'dragItem',
|
|
29
|
+
collect(monitor) {
|
|
30
|
+
return {
|
|
31
|
+
handlerId: monitor.getHandlerId()
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
hover(item, monitor) {
|
|
35
|
+
if (!dropRef.current) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const dragIndex = item.index;
|
|
39
|
+
const hoverIndex = index;
|
|
40
|
+
// Don't replace items with themselves
|
|
41
|
+
if (dragIndex === hoverIndex) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Determine rectangle on screen
|
|
45
|
+
const hoverBoundingRect = dropRef.current?.getBoundingClientRect();
|
|
46
|
+
const dragBoundingRect = dragRef.current?.getBoundingClientRect();
|
|
47
|
+
// 需要拖动多少距离才能触发位置变更
|
|
48
|
+
const dragY = (dragBoundingRect.bottom - dragBoundingRect.top) / 2;
|
|
49
|
+
// Determine mouse position
|
|
50
|
+
const clientOffset = monitor.getClientOffset();
|
|
51
|
+
// Get pixels to the top
|
|
52
|
+
const hoverClientY = clientOffset.y - hoverBoundingRect.top;
|
|
53
|
+
// Only perform the move when the mouse has crossed half of the items height
|
|
54
|
+
// When dragging downwards, only move when the cursor is below 50%
|
|
55
|
+
// When dragging upwards, only move when the cursor is above 50%
|
|
56
|
+
// Dragging downwards
|
|
57
|
+
if (dragIndex < hoverIndex && hoverClientY < dragY) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Dragging upwards
|
|
61
|
+
if (dragIndex > hoverIndex && hoverClientY > dragY) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Time to actually perform the action
|
|
65
|
+
onMove(dragIndex, hoverIndex);
|
|
66
|
+
// Note: we're mutating the monitor item here!
|
|
67
|
+
// Generally it's better to avoid mutations,
|
|
68
|
+
// but it's good here for the sake of performance
|
|
69
|
+
// to avoid expensive index searches.
|
|
70
|
+
item.index = hoverIndex;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const [{
|
|
74
|
+
isDragging
|
|
75
|
+
}, drag] = useDrag({
|
|
76
|
+
item: {
|
|
77
|
+
index,
|
|
78
|
+
type: 'dragItem'
|
|
79
|
+
},
|
|
80
|
+
collect: monitor => ({
|
|
81
|
+
isDragging: monitor.isDragging()
|
|
82
|
+
}),
|
|
83
|
+
end: onEnd
|
|
84
|
+
});
|
|
85
|
+
drag(dragRef);
|
|
86
|
+
drop(dropRef);
|
|
87
|
+
const opacity = isDragging ? 0.5 : 1;
|
|
88
|
+
const toggleExpand = useMemoizedFn(e => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
setExpand(!expand);
|
|
92
|
+
});
|
|
93
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
94
|
+
ref: dropRef,
|
|
95
|
+
sx: {
|
|
96
|
+
borderBottom: `1px solid ${colors.lineBorderStrong}`
|
|
97
|
+
},
|
|
98
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
99
|
+
sx: {
|
|
100
|
+
cursor: 'pointer',
|
|
101
|
+
'&:hover': {
|
|
102
|
+
backgroundColor: colors.backgroundsBgSubtileHover
|
|
103
|
+
},
|
|
104
|
+
borderRadius: 2
|
|
105
|
+
},
|
|
106
|
+
ref: dragRef,
|
|
107
|
+
"data-handler-id": handlerId,
|
|
108
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
109
|
+
sx: {
|
|
110
|
+
py: 1.5,
|
|
111
|
+
px: 1,
|
|
112
|
+
opacity,
|
|
113
|
+
display: 'flex',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
gap: 0.5
|
|
116
|
+
},
|
|
117
|
+
draggable: false,
|
|
118
|
+
onClick: toggleExpand,
|
|
119
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
120
|
+
sx: {
|
|
121
|
+
pointerEvents: 'auto',
|
|
122
|
+
cursor: 'grab',
|
|
123
|
+
'&:active': {
|
|
124
|
+
cursor: 'grabbing'
|
|
125
|
+
},
|
|
126
|
+
fontSize: 0,
|
|
127
|
+
color: colors.textMuted,
|
|
128
|
+
'&:hover': {
|
|
129
|
+
color: colors.textSubtitle
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
133
|
+
fontSize: 20,
|
|
134
|
+
icon: DragIndicatorIcon
|
|
135
|
+
})
|
|
136
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
|
137
|
+
sx: {
|
|
138
|
+
flex: 1
|
|
139
|
+
},
|
|
140
|
+
children: title
|
|
141
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
142
|
+
size: "small",
|
|
143
|
+
sx: {
|
|
144
|
+
pointerEvents: 'auto',
|
|
145
|
+
transform: expand ? '' : 'rotate(180deg)',
|
|
146
|
+
transition: 'transform 0.3s ease'
|
|
147
|
+
},
|
|
148
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
149
|
+
icon: KeyboardArrowDownRoundedIcon,
|
|
150
|
+
style: {
|
|
151
|
+
transform: 'scale(1.5)'
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
})]
|
|
155
|
+
})
|
|
156
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
157
|
+
sx: {
|
|
158
|
+
pl: 4,
|
|
159
|
+
py: 1,
|
|
160
|
+
display: expand ? 'block' : 'none'
|
|
161
|
+
},
|
|
162
|
+
children: children
|
|
163
|
+
})]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
DragItem.propTypes = {
|
|
167
|
+
title: PropTypes.string.isRequired,
|
|
168
|
+
id: PropTypes.string.isRequired,
|
|
169
|
+
children: PropTypes.node.isRequired,
|
|
170
|
+
index: PropTypes.number.isRequired,
|
|
171
|
+
onMove: PropTypes.func.isRequired,
|
|
172
|
+
onEnd: PropTypes.func.isRequired,
|
|
173
|
+
defaultExpand: PropTypes.bool
|
|
174
|
+
};
|
|
175
|
+
DragItem.defaultProps = {
|
|
176
|
+
defaultExpand: true
|
|
177
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Box, Button, FormControl, FormControlLabel, TextField } from '@mui/material';
|
|
2
|
+
import pick from 'lodash/pick';
|
|
3
|
+
import { useMemoizedFn } from 'ahooks';
|
|
4
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
5
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
7
|
+
import { useNodeContext } from '../../../contexts/node';
|
|
8
|
+
import { useBlockletContext } from '../../../contexts/blocklet';
|
|
9
|
+
import SwitchControl from '../../component/switch-control';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
function OAuthGithub() {
|
|
12
|
+
const {
|
|
13
|
+
api
|
|
14
|
+
} = useNodeContext();
|
|
15
|
+
const {
|
|
16
|
+
blocklet
|
|
17
|
+
} = useBlockletContext();
|
|
18
|
+
const {
|
|
19
|
+
t
|
|
20
|
+
} = useLocaleContext();
|
|
21
|
+
// TODO: @zhanghan 将来需要换成 permanent did
|
|
22
|
+
const did = blocklet?.meta?.did;
|
|
23
|
+
const github = Object.assign({
|
|
24
|
+
enabled: false,
|
|
25
|
+
clientId: '',
|
|
26
|
+
clientSecret: ''
|
|
27
|
+
}, blocklet?.settings?.oauth?.github || {});
|
|
28
|
+
const {
|
|
29
|
+
handleSubmit,
|
|
30
|
+
control,
|
|
31
|
+
formState,
|
|
32
|
+
watch,
|
|
33
|
+
reset
|
|
34
|
+
} = useForm({
|
|
35
|
+
defaultValues: pick(github, ['clientSecret', 'clientId', 'enabled'])
|
|
36
|
+
});
|
|
37
|
+
const enabled = watch('enabled');
|
|
38
|
+
const onSubmit = useMemoizedFn(async data => {
|
|
39
|
+
try {
|
|
40
|
+
const {
|
|
41
|
+
blocklet: blockletChanged
|
|
42
|
+
} = await api.configOAuth({
|
|
43
|
+
input: {
|
|
44
|
+
did,
|
|
45
|
+
oauth: JSON.stringify({
|
|
46
|
+
github: data
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const defaultValues = Object.assign({
|
|
51
|
+
enabled: false,
|
|
52
|
+
clientId: '',
|
|
53
|
+
clientSecret: ''
|
|
54
|
+
}, blockletChanged?.settings?.oauth?.github || {});
|
|
55
|
+
// 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
|
|
56
|
+
reset(defaultValues);
|
|
57
|
+
Toast.success(t('oauth.saveSuccess'));
|
|
58
|
+
} catch (err) {
|
|
59
|
+
Toast.error(err.message || t('oauth.saveFailed'));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const validateClientId = useMemoizedFn(val => {
|
|
63
|
+
if (!val?.trim()) {
|
|
64
|
+
return t('oauth.github.clientIdDescribe');
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
68
|
+
const validateClientSecret = useMemoizedFn(val => {
|
|
69
|
+
if (!val?.trim()) {
|
|
70
|
+
return t('oauth.github.clientSecretDescribe');
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
const noop = useMemoizedFn(() => true);
|
|
75
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
76
|
+
children: /*#__PURE__*/_jsxs("form", {
|
|
77
|
+
onSubmit: handleSubmit(onSubmit),
|
|
78
|
+
disabled: true,
|
|
79
|
+
children: [/*#__PURE__*/_jsx(Controller, {
|
|
80
|
+
name: "enabled",
|
|
81
|
+
control: control,
|
|
82
|
+
render: ({
|
|
83
|
+
field
|
|
84
|
+
}) => /*#__PURE__*/_jsx(FormControlLabel, {
|
|
85
|
+
control: /*#__PURE__*/_jsx(SwitchControl, {
|
|
86
|
+
checked: field.value,
|
|
87
|
+
style: {
|
|
88
|
+
marginRight: '6px'
|
|
89
|
+
},
|
|
90
|
+
...field
|
|
91
|
+
}),
|
|
92
|
+
label: t('oauth.github.enable'),
|
|
93
|
+
sx: {
|
|
94
|
+
marginBottom: 2,
|
|
95
|
+
ml: 1
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
99
|
+
name: "clientId",
|
|
100
|
+
control: control,
|
|
101
|
+
rules: {
|
|
102
|
+
validate: enabled ? validateClientId : noop
|
|
103
|
+
},
|
|
104
|
+
render: ({
|
|
105
|
+
field
|
|
106
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
107
|
+
fullWidth: true,
|
|
108
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
109
|
+
...field,
|
|
110
|
+
error: !!formState.errors[field.name],
|
|
111
|
+
label: t('oauth.github.clientId'),
|
|
112
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
113
|
+
disabled: !enabled
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
}), /*#__PURE__*/_jsx(Controller, {
|
|
117
|
+
name: "clientSecret",
|
|
118
|
+
control: control,
|
|
119
|
+
rules: {
|
|
120
|
+
validate: enabled ? validateClientSecret : noop
|
|
121
|
+
},
|
|
122
|
+
render: ({
|
|
123
|
+
field
|
|
124
|
+
}) => /*#__PURE__*/_jsx(FormControl, {
|
|
125
|
+
fullWidth: true,
|
|
126
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
127
|
+
...field,
|
|
128
|
+
type: "password",
|
|
129
|
+
label: t('oauth.github.clientSecret'),
|
|
130
|
+
error: !!formState.errors[field.name],
|
|
131
|
+
helperText: formState.errors[field.name]?.message || ' ',
|
|
132
|
+
disabled: !enabled
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
136
|
+
type: "submit",
|
|
137
|
+
variant: "contained",
|
|
138
|
+
onSubmit: handleSubmit(onSubmit),
|
|
139
|
+
disabled: !formState.isDirty,
|
|
140
|
+
children: t('oauth.save')
|
|
141
|
+
})]
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export default OAuthGithub;
|