@abtnode/ux 1.16.26-beta-818ea1c5 → 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.
Files changed (81) hide show
  1. package/es/blocklet/{oauth → authentication/federated}/federated-detail-dialog.js +2 -2
  2. package/es/blocklet/{oauth → authentication/federated}/federated-join-dialog.js +2 -2
  3. package/es/blocklet/{oauth → authentication/federated}/federated-site-list.js +3 -3
  4. package/es/blocklet/{oauth/federated.js → authentication/federated/index.js} +1 -1
  5. package/es/blocklet/{oauth → authentication}/index.js +7 -5
  6. package/es/blocklet/authentication/oauth/apple.js +198 -0
  7. package/es/blocklet/{oauth → authentication/oauth}/auth0.js +27 -7
  8. package/es/blocklet/authentication/oauth/drag-item.js +177 -0
  9. package/es/blocklet/authentication/oauth/github.js +145 -0
  10. package/es/blocklet/authentication/oauth/google.js +144 -0
  11. package/es/blocklet/authentication/oauth/index.js +122 -0
  12. package/es/blocklet/preferences/index.js +6 -6
  13. package/es/blocklet/publish/connect-store-list.js +8 -6
  14. package/es/blocklet/publish/create-release.js +16 -7
  15. package/es/blocklet/publish/project-list.js +30 -3
  16. package/es/confirm.js +5 -2
  17. package/es/layout/feedback.js +7 -4
  18. package/es/locales/ar.js +34 -4
  19. package/es/locales/de.js +35 -5
  20. package/es/locales/en.js +34 -4
  21. package/es/locales/es.js +35 -5
  22. package/es/locales/fr.js +35 -5
  23. package/es/locales/hi.js +35 -5
  24. package/es/locales/i18n.db +0 -0
  25. package/es/locales/id.js +35 -5
  26. package/es/locales/ja.js +34 -4
  27. package/es/locales/ko.js +35 -5
  28. package/es/locales/pt.js +35 -5
  29. package/es/locales/ru.js +34 -4
  30. package/es/locales/th.js +34 -4
  31. package/es/locales/vi.js +34 -4
  32. package/es/locales/zh-tw.js +34 -4
  33. package/es/locales/zh.js +35 -5
  34. package/es/store/connect-actions.js +14 -5
  35. package/es/store/delete.js +7 -3
  36. package/es/store/item.js +99 -20
  37. package/es/team/members/index.js +16 -13
  38. package/es/team/members/member.js +2 -7
  39. package/lib/blocklet/{oauth → authentication/federated}/federated-detail-dialog.js +2 -2
  40. package/lib/blocklet/{oauth → authentication/federated}/federated-join-dialog.js +2 -2
  41. package/lib/blocklet/{oauth → authentication/federated}/federated-site-list.js +3 -3
  42. package/lib/blocklet/{oauth/federated.js → authentication/federated/index.js} +1 -1
  43. package/lib/blocklet/{oauth → authentication}/index.js +7 -5
  44. package/lib/blocklet/authentication/oauth/apple.js +226 -0
  45. package/lib/blocklet/authentication/oauth/auth0.js +189 -0
  46. package/lib/blocklet/authentication/oauth/drag-item.js +185 -0
  47. package/lib/blocklet/{oauth/auth0.js → authentication/oauth/github.js} +26 -25
  48. package/lib/blocklet/authentication/oauth/google.js +166 -0
  49. package/lib/blocklet/authentication/oauth/index.js +136 -0
  50. package/lib/blocklet/preferences/index.js +6 -6
  51. package/lib/blocklet/publish/connect-store-list.js +9 -8
  52. package/lib/blocklet/publish/create-release.js +16 -6
  53. package/lib/blocklet/publish/project-list.js +29 -2
  54. package/lib/confirm.js +7 -4
  55. package/lib/layout/feedback.js +6 -3
  56. package/lib/locales/ar.js +34 -4
  57. package/lib/locales/de.js +35 -5
  58. package/lib/locales/en.js +34 -4
  59. package/lib/locales/es.js +35 -5
  60. package/lib/locales/fr.js +35 -5
  61. package/lib/locales/hi.js +35 -5
  62. package/lib/locales/i18n.db +0 -0
  63. package/lib/locales/id.js +35 -5
  64. package/lib/locales/ja.js +34 -4
  65. package/lib/locales/ko.js +35 -5
  66. package/lib/locales/pt.js +35 -5
  67. package/lib/locales/ru.js +34 -4
  68. package/lib/locales/th.js +34 -4
  69. package/lib/locales/vi.js +34 -4
  70. package/lib/locales/zh-tw.js +34 -4
  71. package/lib/locales/zh.js +35 -5
  72. package/lib/store/connect-actions.js +14 -5
  73. package/lib/store/delete.js +7 -3
  74. package/lib/store/item.js +111 -19
  75. package/lib/team/members/index.js +13 -11
  76. package/lib/team/members/member.js +1 -6
  77. package/package.json +30 -20
  78. /package/es/blocklet/{oauth → authentication}/common-settings.js +0 -0
  79. /package/es/blocklet/{oauth → authentication/federated}/federated-invite-dialog.js +0 -0
  80. /package/lib/blocklet/{oauth → authentication}/common-settings.js +0 -0
  81. /package/lib/blocklet/{oauth → authentication/federated}/federated-invite-dialog.js +0 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = DragItem;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _material = require("@mui/material");
9
+ var _react = require("react");
10
+ var _reactDnd = require("react-dnd");
11
+ var _Colors = require("@arcblock/ux/lib/Colors");
12
+ var _react2 = require("@iconify/react");
13
+ var _dragIndicator = _interopRequireDefault(require("@iconify-icons/material-symbols/drag-indicator"));
14
+ var _keyboardArrowDownRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/keyboard-arrow-down-rounded"));
15
+ var _ahooks = require("ahooks");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ // eslint-disable-next-line no-unused-vars
19
+ function DragItem(_ref) {
20
+ let {
21
+ title,
22
+ id,
23
+ children,
24
+ index,
25
+ onMove,
26
+ defaultExpand,
27
+ onEnd
28
+ } = _ref;
29
+ const [expand, setExpand] = (0, _react.useState)(defaultExpand);
30
+ const dropRef = (0, _react.useRef)(null);
31
+ const dragRef = (0, _react.useRef)(null);
32
+ const [{
33
+ handlerId
34
+ }, drop] = (0, _reactDnd.useDrop)({
35
+ accept: 'dragItem',
36
+ collect(monitor) {
37
+ return {
38
+ handlerId: monitor.getHandlerId()
39
+ };
40
+ },
41
+ hover(item, monitor) {
42
+ var _dropRef$current, _dragRef$current;
43
+ if (!dropRef.current) {
44
+ return;
45
+ }
46
+ const dragIndex = item.index;
47
+ const hoverIndex = index;
48
+ // Don't replace items with themselves
49
+ if (dragIndex === hoverIndex) {
50
+ return;
51
+ }
52
+ // Determine rectangle on screen
53
+ const hoverBoundingRect = (_dropRef$current = dropRef.current) === null || _dropRef$current === void 0 ? void 0 : _dropRef$current.getBoundingClientRect();
54
+ const dragBoundingRect = (_dragRef$current = dragRef.current) === null || _dragRef$current === void 0 ? void 0 : _dragRef$current.getBoundingClientRect();
55
+ // 需要拖动多少距离才能触发位置变更
56
+ const dragY = (dragBoundingRect.bottom - dragBoundingRect.top) / 2;
57
+ // Determine mouse position
58
+ const clientOffset = monitor.getClientOffset();
59
+ // Get pixels to the top
60
+ const hoverClientY = clientOffset.y - hoverBoundingRect.top;
61
+ // Only perform the move when the mouse has crossed half of the items height
62
+ // When dragging downwards, only move when the cursor is below 50%
63
+ // When dragging upwards, only move when the cursor is above 50%
64
+ // Dragging downwards
65
+ if (dragIndex < hoverIndex && hoverClientY < dragY) {
66
+ return;
67
+ }
68
+ // Dragging upwards
69
+ if (dragIndex > hoverIndex && hoverClientY > dragY) {
70
+ return;
71
+ }
72
+ // Time to actually perform the action
73
+ onMove(dragIndex, hoverIndex);
74
+ // Note: we're mutating the monitor item here!
75
+ // Generally it's better to avoid mutations,
76
+ // but it's good here for the sake of performance
77
+ // to avoid expensive index searches.
78
+ item.index = hoverIndex;
79
+ }
80
+ });
81
+ const [{
82
+ isDragging
83
+ }, drag] = (0, _reactDnd.useDrag)({
84
+ item: {
85
+ index,
86
+ type: 'dragItem'
87
+ },
88
+ collect: monitor => ({
89
+ isDragging: monitor.isDragging()
90
+ }),
91
+ end: onEnd
92
+ });
93
+ drag(dragRef);
94
+ drop(dropRef);
95
+ const opacity = isDragging ? 0.5 : 1;
96
+ const toggleExpand = (0, _ahooks.useMemoizedFn)(e => {
97
+ e.preventDefault();
98
+ e.stopPropagation();
99
+ setExpand(!expand);
100
+ });
101
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
102
+ ref: dropRef,
103
+ sx: {
104
+ borderBottom: "1px solid ".concat(_Colors.temp.lineBorderStrong)
105
+ },
106
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
107
+ sx: {
108
+ cursor: 'pointer',
109
+ '&:hover': {
110
+ backgroundColor: _Colors.temp.backgroundsBgSubtileHover
111
+ },
112
+ borderRadius: 2
113
+ },
114
+ ref: dragRef,
115
+ "data-handler-id": handlerId,
116
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
117
+ sx: {
118
+ py: 1.5,
119
+ px: 1,
120
+ opacity,
121
+ display: 'flex',
122
+ alignItems: 'center',
123
+ gap: 0.5
124
+ },
125
+ draggable: false,
126
+ onClick: toggleExpand,
127
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
128
+ sx: {
129
+ pointerEvents: 'auto',
130
+ cursor: 'grab',
131
+ '&:active': {
132
+ cursor: 'grabbing'
133
+ },
134
+ fontSize: 0,
135
+ color: _Colors.temp.textMuted,
136
+ '&:hover': {
137
+ color: _Colors.temp.textSubtitle
138
+ }
139
+ },
140
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
141
+ fontSize: 20,
142
+ icon: _dragIndicator.default
143
+ })
144
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
145
+ sx: {
146
+ flex: 1
147
+ },
148
+ children: title
149
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
150
+ size: "small",
151
+ sx: {
152
+ pointerEvents: 'auto',
153
+ transform: expand ? '' : 'rotate(180deg)',
154
+ transition: 'transform 0.3s ease'
155
+ },
156
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
157
+ icon: _keyboardArrowDownRounded.default,
158
+ style: {
159
+ transform: 'scale(1.5)'
160
+ }
161
+ })
162
+ })]
163
+ })
164
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
165
+ sx: {
166
+ pl: 4,
167
+ py: 1,
168
+ display: expand ? 'block' : 'none'
169
+ },
170
+ children: children
171
+ })]
172
+ });
173
+ }
174
+ DragItem.propTypes = {
175
+ title: _propTypes.default.string.isRequired,
176
+ id: _propTypes.default.string.isRequired,
177
+ children: _propTypes.default.node.isRequired,
178
+ index: _propTypes.default.number.isRequired,
179
+ onMove: _propTypes.default.func.isRequired,
180
+ onEnd: _propTypes.default.func.isRequired,
181
+ defaultExpand: _propTypes.default.bool
182
+ };
183
+ DragItem.defaultProps = {
184
+ defaultExpand: true
185
+ };
@@ -10,9 +10,9 @@ var _ahooks = require("ahooks");
10
10
  var _reactHookForm = require("react-hook-form");
11
11
  var _context = require("@arcblock/ux/lib/Locale/context");
12
12
  var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
13
- var _node = require("../../contexts/node");
14
- var _blocklet = require("../../contexts/blocklet");
15
- var _switchControl = _interopRequireDefault(require("../component/switch-control"));
13
+ var _node = require("../../../contexts/node");
14
+ var _blocklet = require("../../../contexts/blocklet");
15
+ var _switchControl = _interopRequireDefault(require("../../component/switch-control"));
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -20,7 +20,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
20
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
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
22
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
- function OAuthAuth0() {
23
+ function OAuthGithub() {
24
24
  var _blocklet$meta, _blocklet$settings;
25
25
  const {
26
26
  api
@@ -33,11 +33,11 @@ function OAuthAuth0() {
33
33
  } = (0, _context.useLocaleContext)();
34
34
  // TODO: @zhanghan 将来需要换成 permanent did
35
35
  const did = blocklet === null || blocklet === void 0 || (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did;
36
- const auth0 = Object.assign({
36
+ const github = Object.assign({
37
37
  enabled: false,
38
- domain: '',
39
- clientId: ''
40
- }, (blocklet === null || blocklet === void 0 || (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 || (_blocklet$settings = _blocklet$settings.oauth) === null || _blocklet$settings === void 0 ? void 0 : _blocklet$settings.auth0) || {});
38
+ clientId: '',
39
+ clientSecret: ''
40
+ }, (blocklet === null || blocklet === void 0 || (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 || (_blocklet$settings = _blocklet$settings.oauth) === null || _blocklet$settings === void 0 ? void 0 : _blocklet$settings.github) || {});
41
41
  const {
42
42
  handleSubmit,
43
43
  control,
@@ -45,7 +45,7 @@ function OAuthAuth0() {
45
45
  watch,
46
46
  reset
47
47
  } = (0, _reactHookForm.useForm)({
48
- defaultValues: (0, _pick.default)(auth0, ['domain', 'clientId', 'enabled'])
48
+ defaultValues: (0, _pick.default)(github, ['clientSecret', 'clientId', 'enabled'])
49
49
  });
50
50
  const enabled = watch('enabled');
51
51
  const onSubmit = (0, _ahooks.useMemoizedFn)(async data => {
@@ -57,15 +57,15 @@ function OAuthAuth0() {
57
57
  input: {
58
58
  did,
59
59
  oauth: JSON.stringify({
60
- auth0: data
60
+ github: data
61
61
  })
62
62
  }
63
63
  });
64
64
  const defaultValues = Object.assign({
65
65
  enabled: false,
66
- domain: '',
67
- clientId: ''
68
- }, (blockletChanged === null || blockletChanged === void 0 || (_blockletChanged$sett = blockletChanged.settings) === null || _blockletChanged$sett === void 0 || (_blockletChanged$sett = _blockletChanged$sett.oauth) === null || _blockletChanged$sett === void 0 ? void 0 : _blockletChanged$sett.auth0) || {});
66
+ clientId: '',
67
+ clientSecret: ''
68
+ }, (blockletChanged === null || blockletChanged === void 0 || (_blockletChanged$sett = blockletChanged.settings) === null || _blockletChanged$sett === void 0 || (_blockletChanged$sett = _blockletChanged$sett.oauth) === null || _blockletChanged$sett === void 0 ? void 0 : _blockletChanged$sett.github) || {});
69
69
  // 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
70
70
  reset(defaultValues);
71
71
  _Toast.default.success(t('oauth.saveSuccess'));
@@ -73,15 +73,15 @@ function OAuthAuth0() {
73
73
  _Toast.default.error(err.message || t('oauth.saveFailed'));
74
74
  }
75
75
  });
76
- const validateDomain = (0, _ahooks.useMemoizedFn)(val => {
76
+ const validateClientId = (0, _ahooks.useMemoizedFn)(val => {
77
77
  if (!(val !== null && val !== void 0 && val.trim())) {
78
- return t('oauth.auth0.domainDescribe');
78
+ return t('oauth.github.clientIdDescribe');
79
79
  }
80
80
  return true;
81
81
  });
82
- const validateClientId = (0, _ahooks.useMemoizedFn)(val => {
82
+ const validateClientSecret = (0, _ahooks.useMemoizedFn)(val => {
83
83
  if (!(val !== null && val !== void 0 && val.trim())) {
84
- return t('oauth.auth0.clientIdDescribe');
84
+ return t('oauth.github.clientSecretDescribe');
85
85
  }
86
86
  return true;
87
87
  });
@@ -104,7 +104,7 @@ function OAuthAuth0() {
104
104
  marginRight: '6px'
105
105
  }
106
106
  }, field)),
107
- label: t('oauth.auth0.enable'),
107
+ label: t('oauth.github.enable'),
108
108
  sx: {
109
109
  marginBottom: 2,
110
110
  ml: 1
@@ -112,10 +112,10 @@ function OAuthAuth0() {
112
112
  });
113
113
  }
114
114
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
115
- name: "domain",
115
+ name: "clientId",
116
116
  control: control,
117
117
  rules: {
118
- validate: enabled ? validateDomain : noop
118
+ validate: enabled ? validateClientId : noop
119
119
  },
120
120
  render: _ref2 => {
121
121
  var _formState$errors$fie;
@@ -125,18 +125,18 @@ function OAuthAuth0() {
125
125
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, {
126
126
  fullWidth: true,
127
127
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({}, field), {}, {
128
- label: t('oauth.auth0.domain'),
129
128
  error: !!formState.errors[field.name],
129
+ label: t('oauth.github.clientId'),
130
130
  helperText: ((_formState$errors$fie = formState.errors[field.name]) === null || _formState$errors$fie === void 0 ? void 0 : _formState$errors$fie.message) || ' ',
131
131
  disabled: !enabled
132
132
  }))
133
133
  });
134
134
  }
135
135
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
136
- name: "clientId",
136
+ name: "clientSecret",
137
137
  control: control,
138
138
  rules: {
139
- validate: enabled ? validateClientId : noop
139
+ validate: enabled ? validateClientSecret : noop
140
140
  },
141
141
  render: _ref3 => {
142
142
  var _formState$errors$fie2;
@@ -146,8 +146,9 @@ function OAuthAuth0() {
146
146
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, {
147
147
  fullWidth: true,
148
148
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({}, field), {}, {
149
+ type: "password",
150
+ label: t('oauth.github.clientSecret'),
149
151
  error: !!formState.errors[field.name],
150
- label: t('oauth.auth0.clientId'),
151
152
  helperText: ((_formState$errors$fie2 = formState.errors[field.name]) === null || _formState$errors$fie2 === void 0 ? void 0 : _formState$errors$fie2.message) || ' ',
152
153
  disabled: !enabled
153
154
  }))
@@ -163,4 +164,4 @@ function OAuthAuth0() {
163
164
  })
164
165
  });
165
166
  }
166
- var _default = exports.default = OAuthAuth0;
167
+ var _default = exports.default = OAuthGithub;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _material = require("@mui/material");
8
+ var _pick = _interopRequireDefault(require("lodash/pick"));
9
+ var _ahooks = require("ahooks");
10
+ var _reactHookForm = require("react-hook-form");
11
+ var _context = require("@arcblock/ux/lib/Locale/context");
12
+ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
13
+ var _node = require("../../../contexts/node");
14
+ var _blocklet = require("../../../contexts/blocklet");
15
+ var _switchControl = _interopRequireDefault(require("../../component/switch-control"));
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ function OAuthGoogle() {
24
+ var _blocklet$meta, _blocklet$settings;
25
+ const {
26
+ api
27
+ } = (0, _node.useNodeContext)();
28
+ const {
29
+ blocklet
30
+ } = (0, _blocklet.useBlockletContext)();
31
+ const {
32
+ t
33
+ } = (0, _context.useLocaleContext)();
34
+ const did = blocklet === null || blocklet === void 0 || (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did;
35
+ const authData = Object.assign({
36
+ enabled: false,
37
+ clientId: '',
38
+ clientSecret: ''
39
+ }, (blocklet === null || blocklet === void 0 || (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 || (_blocklet$settings = _blocklet$settings.oauth) === null || _blocklet$settings === void 0 ? void 0 : _blocklet$settings.google) || {});
40
+ const {
41
+ handleSubmit,
42
+ control,
43
+ formState,
44
+ watch,
45
+ reset
46
+ } = (0, _reactHookForm.useForm)({
47
+ defaultValues: (0, _pick.default)(authData, ['clientSecret', 'clientId', 'enabled'])
48
+ });
49
+ const enabled = watch('enabled');
50
+ const onSubmit = (0, _ahooks.useMemoizedFn)(async data => {
51
+ try {
52
+ var _blockletChanged$sett;
53
+ const {
54
+ blocklet: blockletChanged
55
+ } = await api.configOAuth({
56
+ input: {
57
+ did,
58
+ oauth: JSON.stringify({
59
+ google: data
60
+ })
61
+ }
62
+ });
63
+ const defaultValues = Object.assign({
64
+ enabled: false,
65
+ clientId: '',
66
+ clientSecret: ''
67
+ }, (blockletChanged === null || blockletChanged === void 0 || (_blockletChanged$sett = blockletChanged.settings) === null || _blockletChanged$sett === void 0 || (_blockletChanged$sett = _blockletChanged$sett.oauth) === null || _blockletChanged$sett === void 0 ? void 0 : _blockletChanged$sett.google) || {});
68
+ // 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
69
+ reset(defaultValues);
70
+ _Toast.default.success(t('oauth.saveSuccess'));
71
+ } catch (err) {
72
+ _Toast.default.error(err.message || t('oauth.saveFailed'));
73
+ }
74
+ });
75
+ const validateClientId = (0, _ahooks.useMemoizedFn)(val => {
76
+ if (!(val !== null && val !== void 0 && val.trim())) {
77
+ return t('oauth.google.clientIdDescribe');
78
+ }
79
+ return true;
80
+ });
81
+ const validateClientSecret = (0, _ahooks.useMemoizedFn)(val => {
82
+ if (!(val !== null && val !== void 0 && val.trim())) {
83
+ return t('oauth.google.clientSecretDescribe');
84
+ }
85
+ return true;
86
+ });
87
+ const noop = (0, _ahooks.useMemoizedFn)(() => true);
88
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
89
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
90
+ onSubmit: handleSubmit(onSubmit),
91
+ disabled: true,
92
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
93
+ name: "enabled",
94
+ control: control,
95
+ render: _ref => {
96
+ let {
97
+ field
98
+ } = _ref;
99
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControlLabel, {
100
+ control: /*#__PURE__*/(0, _jsxRuntime.jsx)(_switchControl.default, _objectSpread({
101
+ checked: field.value,
102
+ style: {
103
+ marginRight: '6px'
104
+ }
105
+ }, field)),
106
+ label: t('oauth.google.enable'),
107
+ sx: {
108
+ marginBottom: 2,
109
+ ml: 1
110
+ }
111
+ });
112
+ }
113
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
114
+ name: "clientId",
115
+ control: control,
116
+ rules: {
117
+ validate: enabled ? validateClientId : noop
118
+ },
119
+ render: _ref2 => {
120
+ var _formState$errors$fie;
121
+ let {
122
+ field
123
+ } = _ref2;
124
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, {
125
+ fullWidth: true,
126
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({}, field), {}, {
127
+ error: !!formState.errors[field.name],
128
+ label: t('oauth.google.clientId'),
129
+ helperText: ((_formState$errors$fie = formState.errors[field.name]) === null || _formState$errors$fie === void 0 ? void 0 : _formState$errors$fie.message) || ' ',
130
+ disabled: !enabled
131
+ }))
132
+ });
133
+ }
134
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
135
+ name: "clientSecret",
136
+ control: control,
137
+ rules: {
138
+ validate: enabled ? validateClientSecret : noop
139
+ },
140
+ render: _ref3 => {
141
+ var _formState$errors$fie2;
142
+ let {
143
+ field
144
+ } = _ref3;
145
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, {
146
+ fullWidth: true,
147
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, _objectSpread(_objectSpread({}, field), {}, {
148
+ type: "password",
149
+ label: t('oauth.google.clientSecret'),
150
+ error: !!formState.errors[field.name],
151
+ helperText: ((_formState$errors$fie2 = formState.errors[field.name]) === null || _formState$errors$fie2 === void 0 ? void 0 : _formState$errors$fie2.message) || ' ',
152
+ disabled: !enabled
153
+ }))
154
+ });
155
+ }
156
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
157
+ type: "submit",
158
+ variant: "contained",
159
+ onSubmit: handleSubmit(onSubmit),
160
+ disabled: !formState.isDirty,
161
+ children: t('oauth.save')
162
+ })]
163
+ })
164
+ });
165
+ }
166
+ var _default = exports.default = OAuthGoogle;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = OAuthLogin;
7
+ var _material = require("@mui/material");
8
+ var _ahooks = require("ahooks");
9
+ var _reactDnd = require("react-dnd");
10
+ var _reactDndHtml5Backend = require("react-dnd-html5-backend");
11
+ var _react = require("@iconify/react");
12
+ var _apple = _interopRequireDefault(require("@iconify-icons/logos/apple"));
13
+ var _githubIcon = _interopRequireDefault(require("@iconify-icons/logos/github-icon"));
14
+ var _googleIcon = _interopRequireDefault(require("@iconify-icons/logos/google-icon"));
15
+ var _auth0Icon = _interopRequireDefault(require("@iconify-icons/logos/auth0-icon"));
16
+ var _auth = _interopRequireDefault(require("./auth0"));
17
+ var _github = _interopRequireDefault(require("./github"));
18
+ var _google = _interopRequireDefault(require("./google"));
19
+ var _apple2 = _interopRequireDefault(require("./apple"));
20
+ var _dragItem = _interopRequireDefault(require("./drag-item"));
21
+ var _node = require("../../../contexts/node");
22
+ var _blocklet = require("../../../contexts/blocklet");
23
+ var _jsxRuntime = require("react/jsx-runtime");
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
26
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
27
+ 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; }
28
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
29
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
30
+ const avaliableAuthentication = [{
31
+ name: 'github',
32
+ title: 'GitHub',
33
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
34
+ icon: _githubIcon.default
35
+ }),
36
+ component: /*#__PURE__*/(0, _jsxRuntime.jsx)(_github.default, {})
37
+ }, {
38
+ name: 'google',
39
+ title: 'Google',
40
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
41
+ icon: _googleIcon.default
42
+ }),
43
+ component: /*#__PURE__*/(0, _jsxRuntime.jsx)(_google.default, {})
44
+ }, {
45
+ name: 'apple',
46
+ title: 'Apple',
47
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
48
+ icon: _apple.default
49
+ }),
50
+ component: /*#__PURE__*/(0, _jsxRuntime.jsx)(_apple2.default, {})
51
+ }, {
52
+ name: 'auth0',
53
+ title: 'Auth0',
54
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
55
+ icon: _auth0Icon.default
56
+ }),
57
+ component: /*#__PURE__*/(0, _jsxRuntime.jsx)(_auth.default, {})
58
+ }];
59
+ const DEFAULT_OAUTH_LIST = ['github', 'google', 'apple', 'auth0'];
60
+ function OAuthLogin() {
61
+ var _blocklet$meta, _blocklet$settings;
62
+ const {
63
+ api
64
+ } = (0, _node.useNodeContext)();
65
+ const {
66
+ blocklet
67
+ } = (0, _blocklet.useBlockletContext)();
68
+ const did = blocklet === null || blocklet === void 0 || (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did;
69
+ const oauthConfig = (blocklet === null || blocklet === void 0 || (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 ? void 0 : _blocklet$settings.oauth) || {};
70
+ const oauthSort = Object.keys(oauthConfig).sort((a, b) => {
71
+ var _oauthConfig$a, _oauthConfig$b, _oauthConfig$a2;
72
+ if (((_oauthConfig$a = oauthConfig[a]) === null || _oauthConfig$a === void 0 ? void 0 : _oauthConfig$a.order) !== undefined && ((_oauthConfig$b = oauthConfig[b]) === null || _oauthConfig$b === void 0 ? void 0 : _oauthConfig$b.order) !== undefined) {
73
+ return oauthConfig[a].order - oauthConfig[b].order;
74
+ }
75
+ if (((_oauthConfig$a2 = oauthConfig[a]) === null || _oauthConfig$a2 === void 0 ? void 0 : _oauthConfig$a2.order) !== undefined) {
76
+ return -1;
77
+ }
78
+ return 1;
79
+ });
80
+ for (const OAUTH_ITEM of DEFAULT_OAUTH_LIST) {
81
+ if (!oauthSort.includes(OAUTH_ITEM)) {
82
+ oauthSort.push(OAUTH_ITEM);
83
+ }
84
+ }
85
+ const sortMaps = (0, _ahooks.useReactive)(oauthSort.reduce((total, value, index) => Object.assign(total, {
86
+ [value]: index
87
+ }), {}));
88
+ const sortedAuthentication = (0, _ahooks.useCreation)(() => {
89
+ const list = [...avaliableAuthentication];
90
+ list.sort((a, b) => sortMaps[a.name] - sortMaps[b.name]);
91
+ return list;
92
+ }, [sortMaps.auth0, sortMaps.github, sortMaps.google]);
93
+ const dndProps = {};
94
+ if (typeof window !== 'undefined') {
95
+ dndProps.context = window;
96
+ }
97
+ const saveOrder = (0, _ahooks.useMemoizedFn)(async rawOrderData => {
98
+ const orderData = {};
99
+ Object.keys(rawOrderData).forEach(oauthName => {
100
+ orderData[oauthName] = {
101
+ order: rawOrderData[oauthName]
102
+ };
103
+ });
104
+ await api.configOAuth({
105
+ input: {
106
+ did,
107
+ oauth: JSON.stringify(orderData)
108
+ }
109
+ });
110
+ });
111
+ const handleMoveItem = (0, _ahooks.useMemoizedFn)((dragIndex, hoverIndex) => {
112
+ const dragItem = sortedAuthentication[dragIndex];
113
+ const hoverItem = sortedAuthentication[hoverIndex];
114
+ sortMaps[dragItem.name] = hoverIndex;
115
+ sortMaps[hoverItem.name] = dragIndex;
116
+ });
117
+ const handleSaveOrder = (0, _ahooks.useMemoizedFn)(async () => {
118
+ await saveOrder(sortMaps);
119
+ });
120
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
121
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactDnd.DndProvider, _objectSpread(_objectSpread({
122
+ backend: _reactDndHtml5Backend.HTML5Backend
123
+ }, dndProps), {}, {
124
+ children: sortedAuthentication.map((x, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_dragItem.default, {
125
+ index: index,
126
+ id: x.name,
127
+ title: x.title,
128
+ icon: x.icon,
129
+ onMove: handleMoveItem,
130
+ onEnd: handleSaveOrder,
131
+ defaultExpand: x.enabled,
132
+ children: x.component
133
+ }, x.name))
134
+ }))
135
+ });
136
+ }
@@ -28,7 +28,7 @@ var _configuration = _interopRequireDefault(require("../configuration"));
28
28
  var _notification = _interopRequireDefault(require("../notification"));
29
29
  var _index = _interopRequireDefault(require("../access/index"));
30
30
  var _node = require("../../contexts/node");
31
- var _oauth = _interopRequireDefault(require("../oauth"));
31
+ var _authentication = _interopRequireDefault(require("../authentication"));
32
32
  var _jsxRuntime = require("react/jsx-runtime");
33
33
  var _templateObject;
34
34
  const _excluded = ["blocklet", "onUpdate"]; // eslint-disable-line
@@ -150,7 +150,7 @@ function BlockletPreferences(_ref2) {
150
150
  label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
151
151
  display: "flex",
152
152
  alignItems: "center",
153
- "data-cy": "configuration-tab-oauth",
153
+ "data-cy": "configuration-tab-authentication",
154
154
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Login.default, {
155
155
  sx: {
156
156
  fontSize: 24
@@ -164,8 +164,8 @@ function BlockletPreferences(_ref2) {
164
164
  children: t('common.login')
165
165
  })
166
166
  })]
167
- }, "oauth"),
168
- value: 'oauth'
167
+ }, "authentication"),
168
+ value: 'authentication'
169
169
  }, {
170
170
  label: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
171
171
  display: "flex",
@@ -246,8 +246,8 @@ function BlockletPreferences(_ref2) {
246
246
  });
247
247
  } else if (current === 'access') {
248
248
  content = /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.default, {});
249
- } else if (current === 'oauth') {
250
- content = /*#__PURE__*/(0, _jsxRuntime.jsx)(_oauth.default, {});
249
+ } else if (current === 'authentication') {
250
+ content = /*#__PURE__*/(0, _jsxRuntime.jsx)(_authentication.default, {});
251
251
  } else if (current === 'notification') {
252
252
  content = /*#__PURE__*/(0, _jsxRuntime.jsx)(_notification.default, {});
253
253
  } else {