@arcblock/ux 2.7.12 → 2.7.14

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.
@@ -60,6 +60,21 @@ export default function CardSelector({
60
60
  transform: `translate(${-translateX}px, 0)`
61
61
  },
62
62
  children: list.map((e, i) => {
63
+ if (e instanceof Function) {
64
+ return /*#__PURE__*/_jsx("div", {
65
+ className: `card-item ${i === selectedId ? 'selected' : ''}`,
66
+ style: {
67
+ width,
68
+ height,
69
+ margin: cardSpace / 2
70
+ }
71
+ // eslint-disable-next-line react/no-array-index-key
72
+ ,
73
+
74
+ onClick: () => selectedItem(i),
75
+ children: e(i)
76
+ }, i);
77
+ }
63
78
  return /*#__PURE__*/_jsx("div", {
64
79
  className: `card-item ${i === selectedId ? 'selected' : ''}`,
65
80
  style: {
@@ -96,7 +111,8 @@ const Contianer = styled.div`
96
111
  align-items: center;
97
112
  flex-shrink: 0;
98
113
  cursor: pointer;
99
- img {
114
+ img,
115
+ svg {
100
116
  max-width: 100%;
101
117
  max-height: 100%;
102
118
  width: auto;
@@ -107,7 +123,8 @@ const Contianer = styled.div`
107
123
  }
108
124
  &.selected {
109
125
  cursor: default;
110
- img {
126
+ img,
127
+ svg {
111
128
  outline: #526ded solid 5px;
112
129
  }
113
130
  }
@@ -1,4 +1,8 @@
1
1
  import PropTypes from 'prop-types';
2
+ import { useContext, forwardRef, useRef, useImperativeHandle } from 'react';
3
+ import { useMemoizedFn, useReactive } from 'ahooks';
4
+ import noop from 'lodash/noop';
5
+ import { LocaleContext } from '../Locale/context';
2
6
  import Button from '../Button';
3
7
  import Dialog from './dialog';
4
8
 
@@ -12,7 +16,7 @@ import Dialog from './dialog';
12
16
  @property {boolean} [showCancelButton=true]
13
17
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [confirmButton={text: 'Confirm'}]
14
18
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [cancelButton={text: 'Cancel'}]
15
- @property {import('@mui/material').PaperProps} [PaperProps={}]
19
+ @property {import('@mui/material').PaperProps} [PaperProps={}]
16
20
  */
17
21
 
18
22
  // 注意排在 {...rest} 之后的 props 优先级更高
@@ -87,4 +91,96 @@ Confirm.defaultProps = {
87
91
  text: 'Cancel'
88
92
  },
89
93
  PaperProps: {}
90
- };
94
+ };
95
+ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
96
+ const {
97
+ t
98
+ } = useContext(LocaleContext);
99
+ const state = useReactive({
100
+ show: false,
101
+ title: '',
102
+ content: '',
103
+ onConfirm: noop,
104
+ onCancel: noop,
105
+ loading: false
106
+ });
107
+ const open = useMemoizedFn((params = {}) => {
108
+ state.show = true;
109
+ state.title = params.title;
110
+ state.content = params.content;
111
+ state.onConfirm = params.onConfirm || noop;
112
+ state.onCancel = params.onCancel || noop;
113
+ state.loading = false;
114
+ });
115
+ const reset = useMemoizedFn(() => {
116
+ state.title = '';
117
+ state.content = '';
118
+ state.onConfirm = noop;
119
+ state.onCancel = noop;
120
+ });
121
+ const close = useMemoizedFn(() => {
122
+ state.show = false;
123
+ setTimeout(() => {
124
+ reset();
125
+ }, 300);
126
+ });
127
+ const onCancel = useMemoizedFn(() => {
128
+ close();
129
+ state?.onCancel();
130
+ }, []);
131
+ const onConfirm = useMemoizedFn(async () => {
132
+ state.loading = true;
133
+ try {
134
+ await state?.onConfirm(close);
135
+ } finally {
136
+ state.loading = false;
137
+ }
138
+ }, []);
139
+ useImperativeHandle(ref, () => {
140
+ return {
141
+ open,
142
+ close
143
+ };
144
+ }, [open, close]);
145
+ return /*#__PURE__*/_jsx(Confirm, {
146
+ open: state.show,
147
+ title: state.title,
148
+ onConfirm: onConfirm,
149
+ onCancel: onCancel,
150
+ confirmButton: {
151
+ text: t('common.confirm'),
152
+ props: {
153
+ variant: 'contained',
154
+ color: 'primary',
155
+ loading: state.loading
156
+ }
157
+ },
158
+ cancelButton: {
159
+ text: t('common.cancel'),
160
+ props: {
161
+ variant: 'outlined',
162
+ color: 'primary'
163
+ }
164
+ },
165
+ children: state.content
166
+ });
167
+ });
168
+ export function useConfirm() {
169
+ const confirmRef = useRef(null);
170
+ const open = useMemoizedFn((...args) => {
171
+ confirmRef.current?.open(...args);
172
+ });
173
+ const close = useMemoizedFn((...args) => {
174
+ confirmRef.current?.close(...args);
175
+ });
176
+ const confirmApi = {
177
+ open,
178
+ close
179
+ };
180
+ return {
181
+ confirmHolder: /*#__PURE__*/_jsx(ConfirmHolder, {
182
+ ref: confirmRef
183
+ }),
184
+ confirmApi
185
+ };
186
+ }
@@ -1,3 +1,4 @@
1
1
  // eslint-disable-next-line no-restricted-exports
2
2
  export { default } from './dialog';
3
- export { default as Confirm } from './confirm';
3
+ export { default as Confirm } from './confirm';
4
+ export { useConfirm } from './confirm';
@@ -195,7 +195,8 @@ function SessionManager({
195
195
  function _onLogout() {
196
196
  session.logout((...args) => {
197
197
  logoutOAuth({
198
- session
198
+ session,
199
+ hack: true
199
200
  }, ...args).then(() => {
200
201
  onLogout(...args);
201
202
  }).catch(err => {
@@ -70,6 +70,21 @@ function CardSelector(_ref) {
70
70
  transform: "translate(".concat(-translateX, "px, 0)")
71
71
  },
72
72
  children: list.map((e, i) => {
73
+ if (e instanceof Function) {
74
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
75
+ className: "card-item ".concat(i === selectedId ? 'selected' : ''),
76
+ style: {
77
+ width,
78
+ height,
79
+ margin: cardSpace / 2
80
+ }
81
+ // eslint-disable-next-line react/no-array-index-key
82
+ ,
83
+
84
+ onClick: () => selectedItem(i),
85
+ children: e(i)
86
+ }, i);
87
+ }
73
88
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
74
89
  className: "card-item ".concat(i === selectedId ? 'selected' : ''),
75
90
  style: {
@@ -90,7 +105,7 @@ function CardSelector(_ref) {
90
105
  })
91
106
  });
92
107
  }
93
- const Contianer = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n mask-image: linear-gradient(to left, transparent, black 3%, black 97%, transparent);\n overflow: hidden;\n .card-container {\n display: flex;\n white-space: nowrap;\n width: max-content;\n transition: all ease 0.3s;\n }\n .card-item {\n display: inline-flex;\n justify-content: center;\n align-items: center;\n flex-shrink: 0;\n cursor: pointer;\n img {\n max-width: 100%;\n max-height: 100%;\n width: auto;\n height: auto;\n outline: #526ded solid 0;\n transition: all ease 0.2s;\n box-shadow: rgba(0, 0, 0, 0.2) 0 0 10px;\n }\n &.selected {\n cursor: default;\n img {\n outline: #526ded solid 5px;\n }\n }\n }\n"])));
108
+ const Contianer = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n mask-image: linear-gradient(to left, transparent, black 3%, black 97%, transparent);\n overflow: hidden;\n .card-container {\n display: flex;\n white-space: nowrap;\n width: max-content;\n transition: all ease 0.3s;\n }\n .card-item {\n display: inline-flex;\n justify-content: center;\n align-items: center;\n flex-shrink: 0;\n cursor: pointer;\n img,\n svg {\n max-width: 100%;\n max-height: 100%;\n width: auto;\n height: auto;\n outline: #526ded solid 0;\n transition: all ease 0.2s;\n box-shadow: rgba(0, 0, 0, 0.2) 0 0 10px;\n }\n &.selected {\n cursor: default;\n img,\n svg {\n outline: #526ded solid 5px;\n }\n }\n }\n"])));
94
109
  CardSelector.propTypes = {
95
110
  list: _propTypes.default.array,
96
111
  width: _propTypes.default.number,
@@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = Confirm;
7
+ exports.useConfirm = useConfirm;
7
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _react = require("react");
10
+ var _ahooks = require("ahooks");
11
+ var _noop = _interopRequireDefault(require("lodash/noop"));
12
+ var _context = require("../Locale/context");
8
13
  var _Button = _interopRequireDefault(require("../Button"));
9
14
  var _dialog = _interopRequireDefault(require("./dialog"));
10
15
  var _jsxRuntime = require("react/jsx-runtime");
@@ -19,7 +24,7 @@ const _excluded = ["title", "children", "onConfirm", "onCancel", "showCancelButt
19
24
  @property {boolean} [showCancelButton=true]
20
25
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [confirmButton={text: 'Confirm'}]
21
26
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [cancelButton={text: 'Cancel'}]
22
- @property {import('@mui/material').PaperProps} [PaperProps={}]
27
+ @property {import('@mui/material').PaperProps} [PaperProps={}]
23
28
  */
24
29
  // 注意排在 {...rest} 之后的 props 优先级更高
25
30
  /**
@@ -99,4 +104,105 @@ Confirm.defaultProps = {
99
104
  text: 'Cancel'
100
105
  },
101
106
  PaperProps: {}
102
- };
107
+ };
108
+ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
109
+ const {
110
+ t
111
+ } = (0, _react.useContext)(_context.LocaleContext);
112
+ const state = (0, _ahooks.useReactive)({
113
+ show: false,
114
+ title: '',
115
+ content: '',
116
+ onConfirm: _noop.default,
117
+ onCancel: _noop.default,
118
+ loading: false
119
+ });
120
+ const open = (0, _ahooks.useMemoizedFn)(function () {
121
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
122
+ state.show = true;
123
+ state.title = params.title;
124
+ state.content = params.content;
125
+ state.onConfirm = params.onConfirm || _noop.default;
126
+ state.onCancel = params.onCancel || _noop.default;
127
+ state.loading = false;
128
+ });
129
+ const reset = (0, _ahooks.useMemoizedFn)(() => {
130
+ state.title = '';
131
+ state.content = '';
132
+ state.onConfirm = _noop.default;
133
+ state.onCancel = _noop.default;
134
+ });
135
+ const close = (0, _ahooks.useMemoizedFn)(() => {
136
+ state.show = false;
137
+ setTimeout(() => {
138
+ reset();
139
+ }, 300);
140
+ });
141
+ const onCancel = (0, _ahooks.useMemoizedFn)(() => {
142
+ close();
143
+ state === null || state === void 0 ? void 0 : state.onCancel();
144
+ }, []);
145
+ const onConfirm = (0, _ahooks.useMemoizedFn)(async () => {
146
+ state.loading = true;
147
+ try {
148
+ await (state === null || state === void 0 ? void 0 : state.onConfirm(close));
149
+ } finally {
150
+ state.loading = false;
151
+ }
152
+ }, []);
153
+ (0, _react.useImperativeHandle)(ref, () => {
154
+ return {
155
+ open,
156
+ close
157
+ };
158
+ }, [open, close]);
159
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Confirm, {
160
+ open: state.show,
161
+ title: state.title,
162
+ onConfirm: onConfirm,
163
+ onCancel: onCancel,
164
+ confirmButton: {
165
+ text: t('common.confirm'),
166
+ props: {
167
+ variant: 'contained',
168
+ color: 'primary',
169
+ loading: state.loading
170
+ }
171
+ },
172
+ cancelButton: {
173
+ text: t('common.cancel'),
174
+ props: {
175
+ variant: 'outlined',
176
+ color: 'primary'
177
+ }
178
+ },
179
+ children: state.content
180
+ });
181
+ });
182
+ function useConfirm() {
183
+ const confirmRef = (0, _react.useRef)(null);
184
+ const open = (0, _ahooks.useMemoizedFn)(function () {
185
+ var _confirmRef$current;
186
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
187
+ args[_key] = arguments[_key];
188
+ }
189
+ (_confirmRef$current = confirmRef.current) === null || _confirmRef$current === void 0 ? void 0 : _confirmRef$current.open(...args);
190
+ });
191
+ const close = (0, _ahooks.useMemoizedFn)(function () {
192
+ var _confirmRef$current2;
193
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
194
+ args[_key2] = arguments[_key2];
195
+ }
196
+ (_confirmRef$current2 = confirmRef.current) === null || _confirmRef$current2 === void 0 ? void 0 : _confirmRef$current2.close(...args);
197
+ });
198
+ const confirmApi = {
199
+ open,
200
+ close
201
+ };
202
+ return {
203
+ confirmHolder: /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfirmHolder, {
204
+ ref: confirmRef
205
+ }),
206
+ confirmApi
207
+ };
208
+ }
@@ -15,6 +15,14 @@ Object.defineProperty(exports, "default", {
15
15
  return _dialog.default;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "useConfirm", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _confirm.useConfirm;
22
+ }
23
+ });
18
24
  var _dialog = _interopRequireDefault(require("./dialog"));
19
- var _confirm = _interopRequireDefault(require("./confirm"));
25
+ var _confirm = _interopRequireWildcard(require("./confirm"));
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -223,7 +223,8 @@ function SessionManager(_ref) {
223
223
  args[_key] = arguments[_key];
224
224
  }
225
225
  logoutOAuth({
226
- session
226
+ session,
227
+ hack: true
227
228
  }, ...args).then(() => {
228
229
  onLogout(...args);
229
230
  }).catch(err => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.7.12",
3
+ "version": "2.7.14",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -318,11 +318,11 @@
318
318
  "peerDependencies": {
319
319
  "react": ">=18.1.0"
320
320
  },
321
- "gitHead": "d092d3768f75f169c051e49f438e67a60842f357",
321
+ "gitHead": "bdb3657628085f18d46bca6769f62074d06f54d3",
322
322
  "dependencies": {
323
323
  "@arcblock/did-motif": "^1.1.13",
324
- "@arcblock/icons": "^2.7.12",
325
- "@arcblock/react-hooks": "^2.7.12",
324
+ "@arcblock/icons": "^2.7.14",
325
+ "@arcblock/react-hooks": "^2.7.14",
326
326
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
327
327
  "@emotion/react": "^11.10.4",
328
328
  "@emotion/styled": "^11.10.4",
@@ -54,6 +54,18 @@ export default function CardSelector({ list, width, height, cardSpace, onSelect,
54
54
  <Contianer ref={outterCon} onTouchStart={touchstart} onTouchEnd={touchend}>
55
55
  <div className="card-container" style={{ transform: `translate(${-translateX}px, 0)` }}>
56
56
  {list.map((e, i) => {
57
+ if (e instanceof Function) {
58
+ return (
59
+ <div
60
+ className={`card-item ${i === selectedId ? 'selected' : ''}`}
61
+ style={{ width, height, margin: cardSpace / 2 }}
62
+ // eslint-disable-next-line react/no-array-index-key
63
+ key={i}
64
+ onClick={() => selectedItem(i)}>
65
+ {e(i)}
66
+ </div>
67
+ );
68
+ }
57
69
  return (
58
70
  <div
59
71
  className={`card-item ${i === selectedId ? 'selected' : ''}`}
@@ -86,7 +98,8 @@ const Contianer = styled.div`
86
98
  align-items: center;
87
99
  flex-shrink: 0;
88
100
  cursor: pointer;
89
- img {
101
+ img,
102
+ svg {
90
103
  max-width: 100%;
91
104
  max-height: 100%;
92
105
  width: auto;
@@ -97,7 +110,8 @@ const Contianer = styled.div`
97
110
  }
98
111
  &.selected {
99
112
  cursor: default;
100
- img {
113
+ img,
114
+ svg {
101
115
  outline: #526ded solid 5px;
102
116
  }
103
117
  }
@@ -1,4 +1,9 @@
1
1
  import PropTypes from 'prop-types';
2
+ import { useContext, forwardRef, useRef, useImperativeHandle } from 'react';
3
+ import { useMemoizedFn, useReactive } from 'ahooks';
4
+ import noop from 'lodash/noop';
5
+
6
+ import { LocaleContext } from '../Locale/context';
2
7
  import Button from '../Button';
3
8
  import Dialog from './dialog';
4
9
 
@@ -12,7 +17,7 @@ import Dialog from './dialog';
12
17
  @property {boolean} [showCancelButton=true]
13
18
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [confirmButton={text: 'Confirm'}]
14
19
  @property {{text: string, props?: import('../Button/wrap').ButtonProps}} [cancelButton={text: 'Cancel'}]
15
- @property {import('@mui/material').PaperProps} [PaperProps={}]
20
+ @property {import('@mui/material').PaperProps} [PaperProps={}]
16
21
  */
17
22
 
18
23
  // 注意排在 {...rest} 之后的 props 优先级更高
@@ -91,3 +96,103 @@ Confirm.defaultProps = {
91
96
  },
92
97
  PaperProps: {},
93
98
  };
99
+
100
+ const ConfirmHolder = forwardRef((props, ref) => {
101
+ const { t } = useContext(LocaleContext);
102
+
103
+ const state = useReactive({
104
+ show: false,
105
+ title: '',
106
+ content: '',
107
+ onConfirm: noop,
108
+ onCancel: noop,
109
+ loading: false,
110
+ });
111
+ const open = useMemoizedFn((params = {}) => {
112
+ state.show = true;
113
+ state.title = params.title;
114
+ state.content = params.content;
115
+ state.onConfirm = params.onConfirm || noop;
116
+ state.onCancel = params.onCancel || noop;
117
+ state.loading = false;
118
+ });
119
+ const reset = useMemoizedFn(() => {
120
+ state.title = '';
121
+ state.content = '';
122
+ state.onConfirm = noop;
123
+ state.onCancel = noop;
124
+ });
125
+ const close = useMemoizedFn(() => {
126
+ state.show = false;
127
+ setTimeout(() => {
128
+ reset();
129
+ }, 300);
130
+ });
131
+ const onCancel = useMemoizedFn(() => {
132
+ close();
133
+ state?.onCancel();
134
+ }, []);
135
+ const onConfirm = useMemoizedFn(async () => {
136
+ state.loading = true;
137
+ try {
138
+ await state?.onConfirm(close);
139
+ } finally {
140
+ state.loading = false;
141
+ }
142
+ }, []);
143
+ useImperativeHandle(
144
+ ref,
145
+ () => {
146
+ return {
147
+ open,
148
+ close,
149
+ };
150
+ },
151
+ [open, close]
152
+ );
153
+
154
+ return (
155
+ <Confirm
156
+ open={state.show}
157
+ title={state.title}
158
+ onConfirm={onConfirm}
159
+ onCancel={onCancel}
160
+ confirmButton={{
161
+ text: t('common.confirm'),
162
+ props: {
163
+ variant: 'contained',
164
+ color: 'primary',
165
+ loading: state.loading,
166
+ },
167
+ }}
168
+ cancelButton={{
169
+ text: t('common.cancel'),
170
+ props: {
171
+ variant: 'outlined',
172
+ color: 'primary',
173
+ },
174
+ }}>
175
+ {state.content}
176
+ </Confirm>
177
+ );
178
+ });
179
+
180
+ export function useConfirm() {
181
+ const confirmRef = useRef(null);
182
+
183
+ const open = useMemoizedFn((...args) => {
184
+ confirmRef.current?.open(...args);
185
+ });
186
+ const close = useMemoizedFn((...args) => {
187
+ confirmRef.current?.close(...args);
188
+ });
189
+ const confirmApi = {
190
+ open,
191
+ close,
192
+ };
193
+
194
+ return {
195
+ confirmHolder: <ConfirmHolder ref={confirmRef} />,
196
+ confirmApi,
197
+ };
198
+ }
@@ -1,3 +1,4 @@
1
1
  // eslint-disable-next-line no-restricted-exports
2
2
  export { default } from './dialog';
3
3
  export { default as Confirm } from './confirm';
4
+ export { useConfirm } from './confirm';
@@ -177,7 +177,7 @@ function SessionManager({
177
177
  }
178
178
  function _onLogout() {
179
179
  session.logout((...args) => {
180
- logoutOAuth({ session }, ...args)
180
+ logoutOAuth({ session, hack: true }, ...args)
181
181
  .then(() => {
182
182
  onLogout(...args);
183
183
  })