@zat-design/sisyphus-react 3.14.5 → 3.14.6

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.
@@ -63,6 +63,11 @@ var ProEditLabel = _ref => {
63
63
  _Form$useForm4 = _slicedToArray(_Form$useForm3, 1),
64
64
  viewForm = _Form$useForm4[0];
65
65
  var inputRef = useRef(null);
66
+
67
+ // 类型断言:antd FormInstance 确实有这些方法(setFieldsValue, validateFields等)
68
+ // 使用类型断言解决 TypeScript 类型检查问题
69
+ var formInstance = form;
70
+ var viewFormInstance = viewForm;
66
71
  var onPress = e => {
67
72
  var element = e.target;
68
73
  if (e.key === 'Enter') {
@@ -78,9 +83,16 @@ var ProEditLabel = _ref => {
78
83
  if (mode === 'popup') {
79
84
  // 兼容老写法
80
85
  if (!popupProps.columns) {
81
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
86
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
87
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
88
+ return;
89
+ }
90
+ formInstance.setFieldsValue({
91
+ [popupProps.type]: confirmValue
92
+ });
82
93
  } else {
83
- form.setFieldsValue(confirmValue || {});
94
+ var matchedValue = matchFormValue(confirmValue, popupProps.columns);
95
+ formInstance.setFieldsValue(matchedValue || {});
84
96
  }
85
97
  // 弹窗同步最新value数据,解决Popconfirm空白处关闭数据不同步问题
86
98
  setState({
@@ -108,13 +120,21 @@ var ProEditLabel = _ref => {
108
120
  if (mode === 'popup' && props.value) {
109
121
  // 兼容老写法
110
122
  if (!popupProps.columns) {
111
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
123
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
124
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
125
+ return;
126
+ }
127
+ formInstance.setFieldsValue({
128
+ [popupProps.type]: props.value
129
+ });
112
130
  // 文本模式初始化赋值
113
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
131
+ viewFormInstance.setFieldsValue({
132
+ [popupProps.type]: props.value
133
+ });
114
134
  } else {
115
- form.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
135
+ formInstance.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
116
136
  // 文本模式初始化赋值
117
- viewForm.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
137
+ viewFormInstance.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
118
138
  }
119
139
  }
120
140
  }, [props.value, mode]);
@@ -125,9 +145,15 @@ var ProEditLabel = _ref => {
125
145
  if (mode === 'popup' && confirmValue !== props.value) {
126
146
  // 兼容老写法
127
147
  if (!popupProps.columns) {
128
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
148
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
149
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
150
+ return;
151
+ }
152
+ viewFormInstance.setFieldsValue({
153
+ [popupProps.type]: confirmValue
154
+ });
129
155
  } else {
130
- viewForm.setFieldsValue(matchFormValue(confirmValue, popupProps.columns) || {});
156
+ viewFormInstance.setFieldsValue(matchFormValue(confirmValue, popupProps.columns) || {});
131
157
  }
132
158
  }
133
159
  }, [confirmValue, mode]);
@@ -146,53 +172,71 @@ var ProEditLabel = _ref => {
146
172
  */
147
173
  var onConfirmHandle = /*#__PURE__*/function () {
148
174
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
149
- var res, value;
175
+ var res, value, fieldName;
150
176
  return _regeneratorRuntime().wrap(function _callee$(_context) {
151
177
  while (1) switch (_context.prev = _context.next) {
152
178
  case 0:
153
179
  _context.next = 2;
154
- return form.validateFields();
180
+ return formInstance.validateFields();
155
181
  case 2:
156
182
  res = _context.sent;
157
- // 兼容老写法
158
- if (!popupProps.columns) {
159
- value = res[(popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input'];
183
+ if (popupProps.columns) {
184
+ _context.next = 10;
185
+ break;
186
+ }
187
+ if (popupProps !== null && popupProps !== void 0 && popupProps.type) {
188
+ _context.next = 7;
189
+ break;
160
190
  }
161
- value = res;
162
- _context.prev = 5;
191
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
192
+ return _context.abrupt("return", Promise.reject(new Error('popupProps.type is required')));
193
+ case 7:
194
+ value = res[popupProps.type];
195
+ _context.next = 11;
196
+ break;
197
+ case 10:
198
+ // 新写法:如果只有一个字段,提取单个值;否则使用整个对象
199
+ if (popupProps.columns.length === 1) {
200
+ fieldName = popupProps.columns[0].name || popupProps.columns[0].type;
201
+ value = res[fieldName];
202
+ } else {
203
+ value = res;
204
+ }
205
+ case 11:
206
+ _context.prev = 11;
163
207
  _context.t0 = onFinish;
164
208
  if (!_context.t0) {
165
- _context.next = 10;
209
+ _context.next = 16;
166
210
  break;
167
211
  }
168
- _context.next = 10;
212
+ _context.next = 16;
169
213
  return onFinish(value);
170
- case 10:
214
+ case 16:
171
215
  _context.t1 = onConfirm;
172
216
  if (!_context.t1) {
173
- _context.next = 14;
217
+ _context.next = 20;
174
218
  break;
175
219
  }
176
- _context.next = 14;
220
+ _context.next = 20;
177
221
  return onConfirm(value);
178
- case 14:
179
- _context.next = 16;
222
+ case 20:
223
+ _context.next = 22;
180
224
  return setState({
181
225
  confirmValue: value,
182
226
  popValue: value
183
227
  });
184
- case 16:
185
- _context.next = 21;
228
+ case 22:
229
+ _context.next = 27;
186
230
  break;
187
- case 18:
188
- _context.prev = 18;
189
- _context.t2 = _context["catch"](5);
231
+ case 24:
232
+ _context.prev = 24;
233
+ _context.t2 = _context["catch"](11);
190
234
  return _context.abrupt("return", Promise.reject());
191
- case 21:
235
+ case 27:
192
236
  case "end":
193
237
  return _context.stop();
194
238
  }
195
- }, _callee, null, [[5, 18]]);
239
+ }, _callee, null, [[11, 24]]);
196
240
  }));
197
241
  return function onConfirmHandle() {
198
242
  return _ref2.apply(this, arguments);
@@ -205,9 +249,15 @@ var ProEditLabel = _ref => {
205
249
  var onCancelHandle = () => {
206
250
  // 兼容老写法
207
251
  if (!popupProps.columns) {
208
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
252
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
253
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
254
+ return;
255
+ }
256
+ formInstance.setFieldsValue({
257
+ [popupProps.type]: props.value
258
+ });
209
259
  } else {
210
- form.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
260
+ formInstance.setFieldsValue(matchFormValue(props.value, popupProps.columns) || {});
211
261
  }
212
262
  setState({
213
263
  popValue: props.value
@@ -2,7 +2,7 @@ import { InputProps } from 'antd/es/input';
2
2
  import { PopconfirmProps } from 'antd/es/popconfirm';
3
3
  import { FormInstance } from 'antd/es/form';
4
4
  import React from 'react';
5
- import type { ProFormColumnType } from '../index';
5
+ import type { ProFormColumnType } from '../ProForm/propsType';
6
6
  export interface ContainerType {
7
7
  /**
8
8
  * @description 触发方式
@@ -77,13 +77,13 @@ export interface PopupType {
77
77
  * @description 列配置
78
78
  * @default -
79
79
  */
80
- columns?: ProFormColumnType;
80
+ columns?: ProFormColumnType[];
81
81
  /**
82
82
  * @description 允许扩展字段
83
83
  */
84
84
  [key: string]: any;
85
85
  }
86
- export interface LabelType extends InputProps {
86
+ export interface LabelType extends Omit<InputProps, 'onChange'> {
87
87
  /**
88
88
  * @description 是否可见
89
89
  * @default false
@@ -103,7 +103,7 @@ export interface LabelType extends InputProps {
103
103
  * @description 值变化回调
104
104
  * @default -
105
105
  */
106
- onChange?: (value: React.ChangeEvent<HTMLInputElement>) => void;
106
+ onChange?: (value: any) => void;
107
107
  /**
108
108
  * @description 是否可编辑
109
109
  * @default false
@@ -69,6 +69,11 @@ var ProEditLabel = _ref => {
69
69
  _Form$useForm4 = (0, _slicedToArray2.default)(_Form$useForm3, 1),
70
70
  viewForm = _Form$useForm4[0];
71
71
  var inputRef = (0, _react.useRef)(null);
72
+
73
+ // 类型断言:antd FormInstance 确实有这些方法(setFieldsValue, validateFields等)
74
+ // 使用类型断言解决 TypeScript 类型检查问题
75
+ var formInstance = form;
76
+ var viewFormInstance = viewForm;
72
77
  var onPress = e => {
73
78
  var element = e.target;
74
79
  if (e.key === 'Enter') {
@@ -84,9 +89,16 @@ var ProEditLabel = _ref => {
84
89
  if (mode === 'popup') {
85
90
  // 兼容老写法
86
91
  if (!popupProps.columns) {
87
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
92
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
93
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
94
+ return;
95
+ }
96
+ formInstance.setFieldsValue({
97
+ [popupProps.type]: confirmValue
98
+ });
88
99
  } else {
89
- form.setFieldsValue(confirmValue || {});
100
+ var matchedValue = (0, _utils.matchFormValue)(confirmValue, popupProps.columns);
101
+ formInstance.setFieldsValue(matchedValue || {});
90
102
  }
91
103
  // 弹窗同步最新value数据,解决Popconfirm空白处关闭数据不同步问题
92
104
  setState({
@@ -114,13 +126,21 @@ var ProEditLabel = _ref => {
114
126
  if (mode === 'popup' && props.value) {
115
127
  // 兼容老写法
116
128
  if (!popupProps.columns) {
117
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
129
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
130
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
131
+ return;
132
+ }
133
+ formInstance.setFieldsValue({
134
+ [popupProps.type]: props.value
135
+ });
118
136
  // 文本模式初始化赋值
119
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
137
+ viewFormInstance.setFieldsValue({
138
+ [popupProps.type]: props.value
139
+ });
120
140
  } else {
121
- form.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
141
+ formInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
122
142
  // 文本模式初始化赋值
123
- viewForm.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
143
+ viewFormInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
124
144
  }
125
145
  }
126
146
  }, [props.value, mode]);
@@ -131,9 +151,15 @@ var ProEditLabel = _ref => {
131
151
  if (mode === 'popup' && confirmValue !== props.value) {
132
152
  // 兼容老写法
133
153
  if (!popupProps.columns) {
134
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
154
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
155
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
156
+ return;
157
+ }
158
+ viewFormInstance.setFieldsValue({
159
+ [popupProps.type]: confirmValue
160
+ });
135
161
  } else {
136
- viewForm.setFieldsValue((0, _utils.matchFormValue)(confirmValue, popupProps.columns) || {});
162
+ viewFormInstance.setFieldsValue((0, _utils.matchFormValue)(confirmValue, popupProps.columns) || {});
137
163
  }
138
164
  }
139
165
  }, [confirmValue, mode]);
@@ -152,53 +178,71 @@ var ProEditLabel = _ref => {
152
178
  */
153
179
  var onConfirmHandle = /*#__PURE__*/function () {
154
180
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee() {
155
- var res, value;
181
+ var res, value, fieldName;
156
182
  return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
157
183
  while (1) switch (_context.prev = _context.next) {
158
184
  case 0:
159
185
  _context.next = 2;
160
- return form.validateFields();
186
+ return formInstance.validateFields();
161
187
  case 2:
162
188
  res = _context.sent;
163
- // 兼容老写法
164
- if (!popupProps.columns) {
165
- value = res[(popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input'];
189
+ if (popupProps.columns) {
190
+ _context.next = 10;
191
+ break;
192
+ }
193
+ if (popupProps !== null && popupProps !== void 0 && popupProps.type) {
194
+ _context.next = 7;
195
+ break;
166
196
  }
167
- value = res;
168
- _context.prev = 5;
197
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
198
+ return _context.abrupt("return", Promise.reject(new Error('popupProps.type is required')));
199
+ case 7:
200
+ value = res[popupProps.type];
201
+ _context.next = 11;
202
+ break;
203
+ case 10:
204
+ // 新写法:如果只有一个字段,提取单个值;否则使用整个对象
205
+ if (popupProps.columns.length === 1) {
206
+ fieldName = popupProps.columns[0].name || popupProps.columns[0].type;
207
+ value = res[fieldName];
208
+ } else {
209
+ value = res;
210
+ }
211
+ case 11:
212
+ _context.prev = 11;
169
213
  _context.t0 = onFinish;
170
214
  if (!_context.t0) {
171
- _context.next = 10;
215
+ _context.next = 16;
172
216
  break;
173
217
  }
174
- _context.next = 10;
218
+ _context.next = 16;
175
219
  return onFinish(value);
176
- case 10:
220
+ case 16:
177
221
  _context.t1 = onConfirm;
178
222
  if (!_context.t1) {
179
- _context.next = 14;
223
+ _context.next = 20;
180
224
  break;
181
225
  }
182
- _context.next = 14;
226
+ _context.next = 20;
183
227
  return onConfirm(value);
184
- case 14:
185
- _context.next = 16;
228
+ case 20:
229
+ _context.next = 22;
186
230
  return setState({
187
231
  confirmValue: value,
188
232
  popValue: value
189
233
  });
190
- case 16:
191
- _context.next = 21;
234
+ case 22:
235
+ _context.next = 27;
192
236
  break;
193
- case 18:
194
- _context.prev = 18;
195
- _context.t2 = _context["catch"](5);
237
+ case 24:
238
+ _context.prev = 24;
239
+ _context.t2 = _context["catch"](11);
196
240
  return _context.abrupt("return", Promise.reject());
197
- case 21:
241
+ case 27:
198
242
  case "end":
199
243
  return _context.stop();
200
244
  }
201
- }, _callee, null, [[5, 18]]);
245
+ }, _callee, null, [[11, 24]]);
202
246
  }));
203
247
  return function onConfirmHandle() {
204
248
  return _ref2.apply(this, arguments);
@@ -211,9 +255,15 @@ var ProEditLabel = _ref => {
211
255
  var onCancelHandle = () => {
212
256
  // 兼容老写法
213
257
  if (!popupProps.columns) {
214
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
258
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
259
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
260
+ return;
261
+ }
262
+ formInstance.setFieldsValue({
263
+ [popupProps.type]: props.value
264
+ });
215
265
  } else {
216
- form.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
266
+ formInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
217
267
  }
218
268
  setState({
219
269
  popValue: props.value
@@ -2,7 +2,7 @@ import { InputProps } from 'antd/es/input';
2
2
  import { PopconfirmProps } from 'antd/es/popconfirm';
3
3
  import { FormInstance } from 'antd/es/form';
4
4
  import React from 'react';
5
- import type { ProFormColumnType } from '../index';
5
+ import type { ProFormColumnType } from '../ProForm/propsType';
6
6
  export interface ContainerType {
7
7
  /**
8
8
  * @description 触发方式
@@ -77,13 +77,13 @@ export interface PopupType {
77
77
  * @description 列配置
78
78
  * @default -
79
79
  */
80
- columns?: ProFormColumnType;
80
+ columns?: ProFormColumnType[];
81
81
  /**
82
82
  * @description 允许扩展字段
83
83
  */
84
84
  [key: string]: any;
85
85
  }
86
- export interface LabelType extends InputProps {
86
+ export interface LabelType extends Omit<InputProps, 'onChange'> {
87
87
  /**
88
88
  * @description 是否可见
89
89
  * @default false
@@ -103,7 +103,7 @@ export interface LabelType extends InputProps {
103
103
  * @description 值变化回调
104
104
  * @default -
105
105
  */
106
- onChange?: (value: React.ChangeEvent<HTMLInputElement>) => void;
106
+ onChange?: (value: any) => void;
107
107
  /**
108
108
  * @description 是否可编辑
109
109
  * @default false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.14.5",
3
+ "version": "3.14.6",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">=18.19.0"