@zat-design/sisyphus-react 4.1.2-beta.3 → 4.1.2-beta.4

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.
@@ -93,9 +93,7 @@ var RenderField = _ref => {
93
93
  var _valueType = valueType;
94
94
  var _disabled = false;
95
95
  var _desensitization = desensitization || [];
96
-
97
- // editRender弃用使用component同ProForm
98
- var _editRender = component || editRender;
96
+ var _component = component || editRender;
99
97
  var isCell = mode === 'cell';
100
98
  var isSingleMode = mode === 'single';
101
99
  if (isCell) {
@@ -184,6 +182,15 @@ var RenderField = _ref => {
184
182
  isEditable = (_dynamicProps$isEdita = dynamicProps.isEditable) !== null && _dynamicProps$isEdita !== void 0 ? _dynamicProps$isEdita : isEditable(rowData, reactiveParams);
185
183
  }
186
184
 
185
+ // component 处理 - 优先使用 hook 返回的值
186
+ if (isFunction(_component)) {
187
+ var _dynamicProps$compone;
188
+ _component = (_dynamicProps$compone = dynamicProps.component) !== null && _dynamicProps$compone !== void 0 ? _dynamicProps$compone : _component(rowData, reactiveParams);
189
+ }
190
+
191
+ // 更新 _editRender 为处理后的 _component
192
+ var _editRender = _component;
193
+
187
194
  // 是否只读文本
188
195
  var isView = !isEditable || (record === null || record === void 0 ? void 0 : record['is-view']) || config.isView || virtualKey && !_isEditing || getDisabled({
189
196
  globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
@@ -232,8 +239,10 @@ var RenderField = _ref => {
232
239
  validateTrigger
233
240
  }), [defaultProps, resetProps, internalRule, validateTrigger]);
234
241
 
235
- // 只在 single 模式下,当这些函数类型存在时,自动添加 shouldUpdate
242
+ // 当这些函数类型存在时,自动添加 shouldUpdate
236
243
  // 因为这些函数依赖行数据,当行数据变化时需要重新计算
244
+ // 扩展到所有模式(single/multiple/cell),统一行为
245
+ // 注意:需要检查原始的 component/editRender,而不是处理后的 _component
237
246
  var hasFunctionDependency = isFunction(column === null || column === void 0 ? void 0 : column.disabled) ||
238
247
  // disabled 是函数
239
248
  isFunction(fieldProps) ||
@@ -244,11 +253,15 @@ var RenderField = _ref => {
244
253
  // rules 是函数
245
254
  isFunction(isEditable) ||
246
255
  // isEditable 是函数
247
- isFunction(_editRender) ||
248
- // component/editRender 是函数
256
+ isFunction(component) ||
257
+ // component 是函数
258
+ isFunction(editRender) ||
259
+ // editRender 是函数
249
260
  isFunction(viewRender); // viewRender 是函数
250
261
 
251
- if (isSingleMode && hasFunctionDependency && !(column !== null && column !== void 0 && column.dependencies)) {
262
+ // 移除 isSingleMode 限制,让所有模式都支持响应式更新
263
+ // 性能优化已通过 useShouldUpdateForTable hook 的缓存和防抖机制实现
264
+ if (hasFunctionDependency && !(column !== null && column !== void 0 && column.dependencies)) {
252
265
  // 使用 shouldUpdate 监听同一行的数据变化
253
266
  _formItemProps.shouldUpdate = (prevValues, currentValues) => {
254
267
  var prevRow = get(prevValues, [...namePath, index]);
@@ -327,11 +340,14 @@ var RenderField = _ref => {
327
340
  TargetComponent = (_componentMap$type = componentMap[type]) !== null && _componentMap$type !== void 0 ? _componentMap$type : /*#__PURE__*/_jsx(_Fragment, {});
328
341
  }
329
342
  if (isEditable && _isEditing) {
330
- if (typeof _editRender === 'function') {
331
- TargetComponent = _editRender(...rowParams);
332
- }
343
+ // _editRender 已经是处理后的值(通过 dynamicProps.component 或直接计算)
344
+ // 如果原本是函数,此时 _editRender 已经是执行后的 ReactNode
345
+ // 如果原本是 ReactElement,_editRender 就是 ReactElement
333
346
  if ( /*#__PURE__*/React.isValidElement(_editRender)) {
334
347
  TargetComponent = _editRender;
348
+ } else if (_editRender) {
349
+ // 其他情况(可能是字符串或其他类型的 ReactNode)
350
+ TargetComponent = _editRender;
335
351
  }
336
352
  }
337
353
 
@@ -707,6 +723,7 @@ var RenderField = _ref => {
707
723
  // 如果处于 shouldUpdate 模式,需要重新获取最新的行数据并重新计算依赖值
708
724
  var finalComponentProps = componentProps;
709
725
  if (shouldUpdateMode) {
726
+ var _column$isEditable2;
710
727
  // 重新获取最新的行数据
711
728
  var latestRowData = form.getFieldValue([...namePath, index]) || record || {};
712
729
  var latestReactiveParams = {
@@ -740,6 +757,18 @@ var RenderField = _ref => {
740
757
  latestDesensitization = desensitization(latestRowData, latestReactiveParams);
741
758
  }
742
759
 
760
+ // 重新计算 component
761
+ var latestComponent = component || editRender;
762
+ if (isFunction(latestComponent)) {
763
+ latestComponent = latestComponent(latestRowData, latestReactiveParams);
764
+ }
765
+
766
+ // 重新计算 isEditable(使用原始的 column.isEditable,而不是处理后的 isEditable)
767
+ var latestIsEditable = (_column$isEditable2 = column.isEditable) !== null && _column$isEditable2 !== void 0 ? _column$isEditable2 : true;
768
+ if (isFunction(column.isEditable)) {
769
+ latestIsEditable = column.isEditable(latestRowData, latestReactiveParams);
770
+ }
771
+
743
772
  // 重新计算 disabled
744
773
  var latestDisabled = getDisabled({
745
774
  globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
@@ -756,6 +785,52 @@ var RenderField = _ref => {
756
785
  }, latestFieldProps), {}, {
757
786
  desensitization: latestDesensitization
758
787
  });
788
+
789
+ // ⭐ 关键修改:在 shouldUpdate 模式下,需要重新设置 TargetComponent
790
+ // 因为 component 函数可能返回不同的结果
791
+ var latestTargetComponent = TargetComponent;
792
+
793
+ // 首先检查是否有内置type
794
+ if (!latestComponent && typeof type === 'string') {
795
+ var _componentMap$type2;
796
+ latestTargetComponent = (_componentMap$type2 = componentMap[type]) !== null && _componentMap$type2 !== void 0 ? _componentMap$type2 : /*#__PURE__*/_jsx(_Fragment, {});
797
+ }
798
+
799
+ // 然后处理自定义 component
800
+ var latestIsView = !latestIsEditable || (record === null || record === void 0 ? void 0 : record['is-view']) || config.isView || virtualKey && !_isEditing || getDisabled({
801
+ globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
802
+ formDisabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.formDisabled,
803
+ column,
804
+ tabledDisabled: config === null || config === void 0 ? void 0 : config.disabled,
805
+ columnFieldProps: latestFieldProps,
806
+ params: latestRowParams,
807
+ rowDisabled: rowDisabled || 'empty'
808
+ });
809
+ if (latestIsEditable && _isEditing) {
810
+ if ( /*#__PURE__*/React.isValidElement(latestComponent)) {
811
+ latestTargetComponent = latestComponent;
812
+ } else if (latestComponent) {
813
+ latestTargetComponent = latestComponent;
814
+ }
815
+ }
816
+
817
+ // 查看模式
818
+ if (latestIsView) {
819
+ if (typeof viewRender === 'function') {
820
+ var latestCurrentValue = dataIndex ? latestRowData === null || latestRowData === void 0 ? void 0 : latestRowData[dataIndex] : null;
821
+ var _View = viewRender(latestCurrentValue, latestRowData || {}, options);
822
+ latestTargetComponent = /*#__PURE__*/_jsx(Container, {
823
+ viewEmpty: viewEmpty,
824
+ children: _View
825
+ });
826
+ }
827
+ if ( /*#__PURE__*/React.isValidElement(viewRender)) {
828
+ latestTargetComponent = viewRender;
829
+ }
830
+ }
831
+
832
+ // 使用重新计算的 TargetComponent
833
+ TargetComponent = latestTargetComponent;
759
834
  }
760
835
  var FormItem = null;
761
836
  // 当 viewRender 存在时,需要排除 finalComponentProps 中的 children,避免覆盖 Container 的 children
@@ -765,7 +840,15 @@ var RenderField = _ref => {
765
840
  if (isTargetDomElement) {
766
841
  propsForTarget = omit(propsForTarget, ['disabled', ...OMIT_FORM_ITEM_AND_DOM_KEYS]);
767
842
  }
768
- var FieldComponent = /*#__PURE__*/React.isValidElement(TargetComponent) ? ( /*#__PURE__*/React.cloneElement(TargetComponent, propsForTarget)) : /*#__PURE__*/_jsx(TargetComponent, _objectSpread({}, propsForTarget));
843
+ // TargetComponent 未定义时,使用空的占位组件避免渲染错误
844
+ var FieldComponent = null;
845
+ if ( /*#__PURE__*/React.isValidElement(TargetComponent)) {
846
+ FieldComponent = /*#__PURE__*/React.cloneElement(TargetComponent, propsForTarget);
847
+ } else if (TargetComponent) {
848
+ FieldComponent = /*#__PURE__*/_jsx(TargetComponent, _objectSpread({}, propsForTarget));
849
+ } else {
850
+ FieldComponent = /*#__PURE__*/_jsx(_Fragment, {});
851
+ }
769
852
  if (originalValues && !getIsNew(record)) {
770
853
  FieldComponent = /*#__PURE__*/_jsx(ListChangedWrapper, {
771
854
  name: cellName,
@@ -796,7 +879,7 @@ var RenderField = _ref => {
796
879
  }
797
880
  FormItem = TargetComponent ? /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread({
798
881
  validateFirst: true
799
- }, omit(finalFormItemProps, ['render', 'key', 'width', 'hiddenNames', 'name', 'onCell', _formItemProps.shouldUpdate ? 'shouldUpdate' : null])), {}, {
882
+ }, omit(finalFormItemProps, ['render', 'key', 'width', 'hiddenNames', 'name', 'onCell', 'disabled', _formItemProps.shouldUpdate ? 'shouldUpdate' : null])), {}, {
800
883
  // 移除非必要字段,但保留 dependencies
801
884
  className: _className,
802
885
  name: formNamePath ? cellName.slice((formNamePath === null || formNamePath === void 0 ? void 0 : formNamePath.length) - 1) : cellName,
@@ -130,6 +130,11 @@ export type RequiredFn<T = any> = ReactiveFunction<T, boolean | boolean[]>;
130
130
  * @template T 记录类型
131
131
  */
132
132
  export type viewRenderFn<T = any> = (text?: any, record?: T, options?: OptionsProps) => string | number | ReactNode | void;
133
+ /**
134
+ * 组件渲染函数类型(与 ReactiveFunction 保持一致)
135
+ * @template T 记录类型
136
+ */
137
+ export type ComponentRenderFn<T = any> = ReactiveFunction<T, string | number | ReactNode | void>;
133
138
  /**
134
139
  * 表格列属性接口
135
140
  * @template Values 值类型
@@ -153,7 +158,7 @@ export interface ProColumnsProps<Values = any, T = any> extends Omit<FormItemPro
153
158
  icon?: string | ReactNode;
154
159
  } & TooltipProps);
155
160
  /** 组件 */
156
- component?: string | number | ReactNode | viewRenderFn<T>;
161
+ component?: string | number | ReactNode | ComponentRenderFn<T>;
157
162
  /** 视图渲染 */
158
163
  viewRender?: string | number | ReactNode | viewRenderFn<T>;
159
164
  /** 隐藏的字段名 */
@@ -10,6 +10,7 @@ interface Result {
10
10
  fieldProps: any;
11
11
  desensitization: any;
12
12
  valueType: any;
13
+ component: any;
13
14
  }
14
15
  declare const useShouldUpdateForTable: (props: UseShouldUpdateForTableProps) => Result;
15
16
  export default useShouldUpdateForTable;
@@ -8,7 +8,7 @@ import { useRef, useState, useEffect } from 'react';
8
8
  import { isFunction, isEqualWith, debounce } from 'lodash';
9
9
  import { customEqualForFunction } from "../../utils";
10
10
  var useShouldUpdateForTable = props => {
11
- var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current;
11
+ var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current, _componentRef$current;
12
12
  var rowParams = props.rowParams,
13
13
  column = props.column,
14
14
  shouldUpdateDebounce = props.shouldUpdateDebounce;
@@ -20,6 +20,7 @@ var useShouldUpdateForTable = props => {
20
20
  var fieldPropsRef = useRef();
21
21
  var desensitizationRef = useRef();
22
22
  var valueTypeRef = useRef();
23
+ var componentRef = useRef();
23
24
  var _useState = useState({}),
24
25
  _useState2 = _slicedToArray(_useState, 2),
25
26
  reRender = _useState2[1];
@@ -100,6 +101,19 @@ var useShouldUpdateForTable = props => {
100
101
  } else {
101
102
  valueTypeRef.current = column.valueType;
102
103
  }
104
+
105
+ // component 处理(注意:component 是 editRender 的别名)
106
+ var componentOrEditRender = column.component || column.editRender;
107
+ if (isFunction(componentOrEditRender)) {
108
+ var newComponent = componentOrEditRender(values, reactiveParams);
109
+ // 对于 ReactNode 类型的返回值,使用深度比较
110
+ if (!isEqualWith(componentRef.current, newComponent, customEqualForFunction)) {
111
+ componentRef.current = newComponent;
112
+ hasChange = true;
113
+ }
114
+ } else {
115
+ componentRef.current = componentOrEditRender;
116
+ }
103
117
  if (hasChange) {
104
118
  reRender({});
105
119
  }
@@ -107,7 +121,8 @@ var useShouldUpdateForTable = props => {
107
121
 
108
122
  // 创建防抖函数(统一处理所有动态属性)
109
123
  useEffect(() => {
110
- if (shouldUpdateDebounce > 0 && (isFunction(column.isEditable) || isFunction(column.required) || isFunction(column.rules) || isFunction(column.fieldProps) || isFunction(column.desensitization) || isFunction(column.valueType))) {
124
+ var componentOrEditRender = column.component || column.editRender;
125
+ if (shouldUpdateDebounce > 0 && (isFunction(column.isEditable) || isFunction(column.required) || isFunction(column.rules) || isFunction(column.fieldProps) || isFunction(column.desensitization) || isFunction(column.valueType) || isFunction(componentOrEditRender))) {
111
126
  debouncedUpdateRef.current = debounce(() => {
112
127
  if (pendingParamsRef.current) {
113
128
  processUpdate(pendingParamsRef.current);
@@ -146,7 +161,8 @@ var useShouldUpdateForTable = props => {
146
161
  rules: (_rulesRef$current = rulesRef.current) !== null && _rulesRef$current !== void 0 ? _rulesRef$current : column.rules,
147
162
  fieldProps: (_fieldPropsRef$curren = fieldPropsRef.current) !== null && _fieldPropsRef$curren !== void 0 ? _fieldPropsRef$curren : column.fieldProps,
148
163
  desensitization: (_desensitizationRef$c = desensitizationRef.current) !== null && _desensitizationRef$c !== void 0 ? _desensitizationRef$c : column.desensitization,
149
- valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType
164
+ valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType,
165
+ component: (_componentRef$current = componentRef.current) !== null && _componentRef$current !== void 0 ? _componentRef$current : column.component || column.editRender
150
166
  };
151
167
  };
152
168
  export default useShouldUpdateForTable;
@@ -75,13 +75,20 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
75
75
  confirm?: boolean | import("antd").ModalFuncProps | import("../../../render/propsType").FunctionArgs<any, boolean | import("antd").ModalFuncProps>;
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
78
+ status?: "" | "success" | "warning" | "error" | "validating";
79
+ className?: string;
80
+ hidden?: boolean;
81
+ id?: string;
82
+ style?: React.CSSProperties;
83
+ children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
84
+ onReset?: () => void;
85
+ prefixCls?: string;
86
+ rootClassName?: string;
79
87
  colon?: boolean;
80
88
  htmlFor?: string;
81
89
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
82
90
  labelCol?: import("antd").ColProps;
83
91
  vertical?: boolean;
84
- children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
85
92
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
86
93
  normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
87
94
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
@@ -89,44 +96,37 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
89
96
  validateTrigger?: string | false | string[];
90
97
  validateDebounce?: number;
91
98
  valuePropName?: string;
99
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
92
100
  messageVariables?: Record<string, string>;
93
101
  initialValue?: any;
94
- onReset?: () => void;
95
102
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
96
103
  preserve?: boolean;
97
104
  isListField?: boolean;
98
105
  isList?: boolean;
99
- prefixCls?: string;
100
106
  noStyle?: boolean;
101
- style?: React.CSSProperties;
102
- className?: string;
103
- rootClassName?: string;
104
- id?: string;
105
107
  hasFeedback?: boolean | {
106
108
  icons: import("antd/es/form/FormItem").FeedbackIcons;
107
109
  };
108
110
  validateStatus?: "" | "success" | "warning" | "error" | "validating";
109
- hidden?: boolean;
110
111
  layout?: import("antd/es/form/Form").FormItemLayout;
111
112
  wrapperCol?: import("antd").ColProps;
112
- status?: "" | "success" | "warning" | "error" | "validating";
113
113
  help?: React.ReactNode;
114
114
  fieldId?: string;
115
- toISOString?: boolean;
116
- toCSTString?: boolean;
117
- switchValue?: [any, any];
118
- clearNotShow?: boolean;
119
115
  valueType?: import("../../../render/propsType").ProFormValueType;
120
116
  viewRender?: (value: any, record: any, { form, index, namePath, }: {
121
117
  [key: string]: any;
122
118
  form: FormInstance<any>;
123
119
  index?: number;
124
120
  }) => string | React.ReactElement<any, any>;
125
- trim?: boolean;
126
121
  desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
127
122
  isView?: boolean;
128
- upperCase?: boolean;
123
+ switchValue?: [any, any];
129
124
  viewType?: import("../../../render/propsType").ViewType;
125
+ trim?: boolean;
126
+ upperCase?: boolean;
127
+ toISOString?: boolean;
128
+ toCSTString?: boolean;
129
+ clearNotShow?: boolean;
130
130
  name: any;
131
131
  dependencies: any[];
132
132
  tooltip: string | {
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
141
141
  * 创建组件属性
142
142
  */
143
143
  export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
144
- componentProps: import("lodash").Omit<any, "format" | "toISOString" | "toCSTString" | "switchValue" | "precision" | "clearNotShow" | "dependNames" | "valueType">;
144
+ componentProps: import("lodash").Omit<any, "valueType" | "precision" | "format" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -100,9 +100,7 @@ var RenderField = _ref => {
100
100
  var _valueType = valueType;
101
101
  var _disabled = false;
102
102
  var _desensitization = desensitization || [];
103
-
104
- // editRender弃用使用component同ProForm
105
- var _editRender = component || editRender;
103
+ var _component = component || editRender;
106
104
  var isCell = mode === 'cell';
107
105
  var isSingleMode = mode === 'single';
108
106
  if (isCell) {
@@ -191,6 +189,15 @@ var RenderField = _ref => {
191
189
  isEditable = (_dynamicProps$isEdita = dynamicProps.isEditable) !== null && _dynamicProps$isEdita !== void 0 ? _dynamicProps$isEdita : isEditable(rowData, reactiveParams);
192
190
  }
193
191
 
192
+ // component 处理 - 优先使用 hook 返回的值
193
+ if ((0, _lodash.isFunction)(_component)) {
194
+ var _dynamicProps$compone;
195
+ _component = (_dynamicProps$compone = dynamicProps.component) !== null && _dynamicProps$compone !== void 0 ? _dynamicProps$compone : _component(rowData, reactiveParams);
196
+ }
197
+
198
+ // 更新 _editRender 为处理后的 _component
199
+ var _editRender = _component;
200
+
194
201
  // 是否只读文本
195
202
  var isView = !isEditable || (record === null || record === void 0 ? void 0 : record['is-view']) || config.isView || virtualKey && !_isEditing || (0, _tools.getDisabled)({
196
203
  globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
@@ -239,8 +246,10 @@ var RenderField = _ref => {
239
246
  validateTrigger
240
247
  }), [defaultProps, resetProps, internalRule, validateTrigger]);
241
248
 
242
- // 只在 single 模式下,当这些函数类型存在时,自动添加 shouldUpdate
249
+ // 当这些函数类型存在时,自动添加 shouldUpdate
243
250
  // 因为这些函数依赖行数据,当行数据变化时需要重新计算
251
+ // 扩展到所有模式(single/multiple/cell),统一行为
252
+ // 注意:需要检查原始的 component/editRender,而不是处理后的 _component
244
253
  var hasFunctionDependency = (0, _lodash.isFunction)(column === null || column === void 0 ? void 0 : column.disabled) ||
245
254
  // disabled 是函数
246
255
  (0, _lodash.isFunction)(fieldProps) ||
@@ -251,11 +260,15 @@ var RenderField = _ref => {
251
260
  // rules 是函数
252
261
  (0, _lodash.isFunction)(isEditable) ||
253
262
  // isEditable 是函数
254
- (0, _lodash.isFunction)(_editRender) ||
255
- // component/editRender 是函数
263
+ (0, _lodash.isFunction)(component) ||
264
+ // component 是函数
265
+ (0, _lodash.isFunction)(editRender) ||
266
+ // editRender 是函数
256
267
  (0, _lodash.isFunction)(viewRender); // viewRender 是函数
257
268
 
258
- if (isSingleMode && hasFunctionDependency && !(column !== null && column !== void 0 && column.dependencies)) {
269
+ // 移除 isSingleMode 限制,让所有模式都支持响应式更新
270
+ // 性能优化已通过 useShouldUpdateForTable hook 的缓存和防抖机制实现
271
+ if (hasFunctionDependency && !(column !== null && column !== void 0 && column.dependencies)) {
259
272
  // 使用 shouldUpdate 监听同一行的数据变化
260
273
  _formItemProps.shouldUpdate = (prevValues, currentValues) => {
261
274
  var prevRow = (0, _lodash.get)(prevValues, [...namePath, index]);
@@ -334,11 +347,14 @@ var RenderField = _ref => {
334
347
  TargetComponent = (_componentMap$type = componentMap[type]) !== null && _componentMap$type !== void 0 ? _componentMap$type : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
335
348
  }
336
349
  if (isEditable && _isEditing) {
337
- if (typeof _editRender === 'function') {
338
- TargetComponent = _editRender(...rowParams);
339
- }
350
+ // _editRender 已经是处理后的值(通过 dynamicProps.component 或直接计算)
351
+ // 如果原本是函数,此时 _editRender 已经是执行后的 ReactNode
352
+ // 如果原本是 ReactElement,_editRender 就是 ReactElement
340
353
  if ( /*#__PURE__*/_react.default.isValidElement(_editRender)) {
341
354
  TargetComponent = _editRender;
355
+ } else if (_editRender) {
356
+ // 其他情况(可能是字符串或其他类型的 ReactNode)
357
+ TargetComponent = _editRender;
342
358
  }
343
359
  }
344
360
 
@@ -714,6 +730,7 @@ var RenderField = _ref => {
714
730
  // 如果处于 shouldUpdate 模式,需要重新获取最新的行数据并重新计算依赖值
715
731
  var finalComponentProps = componentProps;
716
732
  if (shouldUpdateMode) {
733
+ var _column$isEditable2;
717
734
  // 重新获取最新的行数据
718
735
  var latestRowData = form.getFieldValue([...namePath, index]) || record || {};
719
736
  var latestReactiveParams = {
@@ -747,6 +764,18 @@ var RenderField = _ref => {
747
764
  latestDesensitization = desensitization(latestRowData, latestReactiveParams);
748
765
  }
749
766
 
767
+ // 重新计算 component
768
+ var latestComponent = component || editRender;
769
+ if ((0, _lodash.isFunction)(latestComponent)) {
770
+ latestComponent = latestComponent(latestRowData, latestReactiveParams);
771
+ }
772
+
773
+ // 重新计算 isEditable(使用原始的 column.isEditable,而不是处理后的 isEditable)
774
+ var latestIsEditable = (_column$isEditable2 = column.isEditable) !== null && _column$isEditable2 !== void 0 ? _column$isEditable2 : true;
775
+ if ((0, _lodash.isFunction)(column.isEditable)) {
776
+ latestIsEditable = column.isEditable(latestRowData, latestReactiveParams);
777
+ }
778
+
750
779
  // 重新计算 disabled
751
780
  var latestDisabled = (0, _tools.getDisabled)({
752
781
  globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
@@ -763,6 +792,52 @@ var RenderField = _ref => {
763
792
  }, latestFieldProps), {}, {
764
793
  desensitization: latestDesensitization
765
794
  });
795
+
796
+ // ⭐ 关键修改:在 shouldUpdate 模式下,需要重新设置 TargetComponent
797
+ // 因为 component 函数可能返回不同的结果
798
+ var latestTargetComponent = TargetComponent;
799
+
800
+ // 首先检查是否有内置type
801
+ if (!latestComponent && typeof type === 'string') {
802
+ var _componentMap$type2;
803
+ latestTargetComponent = (_componentMap$type2 = componentMap[type]) !== null && _componentMap$type2 !== void 0 ? _componentMap$type2 : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
804
+ }
805
+
806
+ // 然后处理自定义 component
807
+ var latestIsView = !latestIsEditable || (record === null || record === void 0 ? void 0 : record['is-view']) || config.isView || virtualKey && !_isEditing || (0, _tools.getDisabled)({
808
+ globalControl: otherProps === null || otherProps === void 0 ? void 0 : otherProps.globalControl,
809
+ formDisabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.formDisabled,
810
+ column,
811
+ tabledDisabled: config === null || config === void 0 ? void 0 : config.disabled,
812
+ columnFieldProps: latestFieldProps,
813
+ params: latestRowParams,
814
+ rowDisabled: rowDisabled || 'empty'
815
+ });
816
+ if (latestIsEditable && _isEditing) {
817
+ if ( /*#__PURE__*/_react.default.isValidElement(latestComponent)) {
818
+ latestTargetComponent = latestComponent;
819
+ } else if (latestComponent) {
820
+ latestTargetComponent = latestComponent;
821
+ }
822
+ }
823
+
824
+ // 查看模式
825
+ if (latestIsView) {
826
+ if (typeof viewRender === 'function') {
827
+ var latestCurrentValue = dataIndex ? latestRowData === null || latestRowData === void 0 ? void 0 : latestRowData[dataIndex] : null;
828
+ var _View = viewRender(latestCurrentValue, latestRowData || {}, options);
829
+ latestTargetComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Container.default, {
830
+ viewEmpty: viewEmpty,
831
+ children: _View
832
+ });
833
+ }
834
+ if ( /*#__PURE__*/_react.default.isValidElement(viewRender)) {
835
+ latestTargetComponent = viewRender;
836
+ }
837
+ }
838
+
839
+ // 使用重新计算的 TargetComponent
840
+ TargetComponent = latestTargetComponent;
766
841
  }
767
842
  var FormItem = null;
768
843
  // 当 viewRender 存在时,需要排除 finalComponentProps 中的 children,避免覆盖 Container 的 children
@@ -772,7 +847,15 @@ var RenderField = _ref => {
772
847
  if (isTargetDomElement) {
773
848
  propsForTarget = (0, _lodash.omit)(propsForTarget, ['disabled', ...OMIT_FORM_ITEM_AND_DOM_KEYS]);
774
849
  }
775
- var FieldComponent = /*#__PURE__*/_react.default.isValidElement(TargetComponent) ? ( /*#__PURE__*/_react.default.cloneElement(TargetComponent, propsForTarget)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(TargetComponent, _objectSpread({}, propsForTarget));
850
+ // TargetComponent 未定义时,使用空的占位组件避免渲染错误
851
+ var FieldComponent = null;
852
+ if ( /*#__PURE__*/_react.default.isValidElement(TargetComponent)) {
853
+ FieldComponent = /*#__PURE__*/_react.default.cloneElement(TargetComponent, propsForTarget);
854
+ } else if (TargetComponent) {
855
+ FieldComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(TargetComponent, _objectSpread({}, propsForTarget));
856
+ } else {
857
+ FieldComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
858
+ }
776
859
  if (originalValues && !getIsNew(record)) {
777
860
  FieldComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListChangedWrapper.default, {
778
861
  name: cellName,
@@ -803,7 +886,7 @@ var RenderField = _ref => {
803
886
  }
804
887
  FormItem = TargetComponent ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Form.Item, _objectSpread(_objectSpread({
805
888
  validateFirst: true
806
- }, (0, _lodash.omit)(finalFormItemProps, ['render', 'key', 'width', 'hiddenNames', 'name', 'onCell', _formItemProps.shouldUpdate ? 'shouldUpdate' : null])), {}, {
889
+ }, (0, _lodash.omit)(finalFormItemProps, ['render', 'key', 'width', 'hiddenNames', 'name', 'onCell', 'disabled', _formItemProps.shouldUpdate ? 'shouldUpdate' : null])), {}, {
807
890
  // 移除非必要字段,但保留 dependencies
808
891
  className: _className,
809
892
  name: formNamePath ? cellName.slice((formNamePath === null || formNamePath === void 0 ? void 0 : formNamePath.length) - 1) : cellName,
@@ -130,6 +130,11 @@ export type RequiredFn<T = any> = ReactiveFunction<T, boolean | boolean[]>;
130
130
  * @template T 记录类型
131
131
  */
132
132
  export type viewRenderFn<T = any> = (text?: any, record?: T, options?: OptionsProps) => string | number | ReactNode | void;
133
+ /**
134
+ * 组件渲染函数类型(与 ReactiveFunction 保持一致)
135
+ * @template T 记录类型
136
+ */
137
+ export type ComponentRenderFn<T = any> = ReactiveFunction<T, string | number | ReactNode | void>;
133
138
  /**
134
139
  * 表格列属性接口
135
140
  * @template Values 值类型
@@ -153,7 +158,7 @@ export interface ProColumnsProps<Values = any, T = any> extends Omit<FormItemPro
153
158
  icon?: string | ReactNode;
154
159
  } & TooltipProps);
155
160
  /** 组件 */
156
- component?: string | number | ReactNode | viewRenderFn<T>;
161
+ component?: string | number | ReactNode | ComponentRenderFn<T>;
157
162
  /** 视图渲染 */
158
163
  viewRender?: string | number | ReactNode | viewRenderFn<T>;
159
164
  /** 隐藏的字段名 */
@@ -10,6 +10,7 @@ interface Result {
10
10
  fieldProps: any;
11
11
  desensitization: any;
12
12
  valueType: any;
13
+ component: any;
13
14
  }
14
15
  declare const useShouldUpdateForTable: (props: UseShouldUpdateForTableProps) => Result;
15
16
  export default useShouldUpdateForTable;
@@ -14,7 +14,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
14
14
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  var useShouldUpdateForTable = props => {
17
- var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current;
17
+ var _isEditableRef$curren, _requiredRef$current, _rulesRef$current, _fieldPropsRef$curren, _desensitizationRef$c, _valueTypeRef$current, _componentRef$current;
18
18
  var rowParams = props.rowParams,
19
19
  column = props.column,
20
20
  shouldUpdateDebounce = props.shouldUpdateDebounce;
@@ -26,6 +26,7 @@ var useShouldUpdateForTable = props => {
26
26
  var fieldPropsRef = (0, _react.useRef)();
27
27
  var desensitizationRef = (0, _react.useRef)();
28
28
  var valueTypeRef = (0, _react.useRef)();
29
+ var componentRef = (0, _react.useRef)();
29
30
  var _useState = (0, _react.useState)({}),
30
31
  _useState2 = _slicedToArray(_useState, 2),
31
32
  reRender = _useState2[1];
@@ -106,6 +107,19 @@ var useShouldUpdateForTable = props => {
106
107
  } else {
107
108
  valueTypeRef.current = column.valueType;
108
109
  }
110
+
111
+ // component 处理(注意:component 是 editRender 的别名)
112
+ var componentOrEditRender = column.component || column.editRender;
113
+ if ((0, _lodash.isFunction)(componentOrEditRender)) {
114
+ var newComponent = componentOrEditRender(values, reactiveParams);
115
+ // 对于 ReactNode 类型的返回值,使用深度比较
116
+ if (!(0, _lodash.isEqualWith)(componentRef.current, newComponent, _utils.customEqualForFunction)) {
117
+ componentRef.current = newComponent;
118
+ hasChange = true;
119
+ }
120
+ } else {
121
+ componentRef.current = componentOrEditRender;
122
+ }
109
123
  if (hasChange) {
110
124
  reRender({});
111
125
  }
@@ -113,7 +127,8 @@ var useShouldUpdateForTable = props => {
113
127
 
114
128
  // 创建防抖函数(统一处理所有动态属性)
115
129
  (0, _react.useEffect)(() => {
116
- if (shouldUpdateDebounce > 0 && ((0, _lodash.isFunction)(column.isEditable) || (0, _lodash.isFunction)(column.required) || (0, _lodash.isFunction)(column.rules) || (0, _lodash.isFunction)(column.fieldProps) || (0, _lodash.isFunction)(column.desensitization) || (0, _lodash.isFunction)(column.valueType))) {
130
+ var componentOrEditRender = column.component || column.editRender;
131
+ if (shouldUpdateDebounce > 0 && ((0, _lodash.isFunction)(column.isEditable) || (0, _lodash.isFunction)(column.required) || (0, _lodash.isFunction)(column.rules) || (0, _lodash.isFunction)(column.fieldProps) || (0, _lodash.isFunction)(column.desensitization) || (0, _lodash.isFunction)(column.valueType) || (0, _lodash.isFunction)(componentOrEditRender))) {
117
132
  debouncedUpdateRef.current = (0, _lodash.debounce)(() => {
118
133
  if (pendingParamsRef.current) {
119
134
  processUpdate(pendingParamsRef.current);
@@ -152,7 +167,8 @@ var useShouldUpdateForTable = props => {
152
167
  rules: (_rulesRef$current = rulesRef.current) !== null && _rulesRef$current !== void 0 ? _rulesRef$current : column.rules,
153
168
  fieldProps: (_fieldPropsRef$curren = fieldPropsRef.current) !== null && _fieldPropsRef$curren !== void 0 ? _fieldPropsRef$curren : column.fieldProps,
154
169
  desensitization: (_desensitizationRef$c = desensitizationRef.current) !== null && _desensitizationRef$c !== void 0 ? _desensitizationRef$c : column.desensitization,
155
- valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType
170
+ valueType: (_valueTypeRef$current = valueTypeRef.current) !== null && _valueTypeRef$current !== void 0 ? _valueTypeRef$current : column.valueType,
171
+ component: (_componentRef$current = componentRef.current) !== null && _componentRef$current !== void 0 ? _componentRef$current : column.component || column.editRender
156
172
  };
157
173
  };
158
174
  var _default = exports.default = useShouldUpdateForTable;
@@ -75,13 +75,20 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
75
75
  confirm?: boolean | import("antd").ModalFuncProps | import("../../../render/propsType").FunctionArgs<any, boolean | import("antd").ModalFuncProps>;
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
78
+ status?: "" | "success" | "warning" | "error" | "validating";
79
+ className?: string;
80
+ hidden?: boolean;
81
+ id?: string;
82
+ style?: React.CSSProperties;
83
+ children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
84
+ onReset?: () => void;
85
+ prefixCls?: string;
86
+ rootClassName?: string;
79
87
  colon?: boolean;
80
88
  htmlFor?: string;
81
89
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
82
90
  labelCol?: import("antd").ColProps;
83
91
  vertical?: boolean;
84
- children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
85
92
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
86
93
  normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
87
94
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
@@ -89,44 +96,37 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
89
96
  validateTrigger?: string | false | string[];
90
97
  validateDebounce?: number;
91
98
  valuePropName?: string;
99
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
92
100
  messageVariables?: Record<string, string>;
93
101
  initialValue?: any;
94
- onReset?: () => void;
95
102
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
96
103
  preserve?: boolean;
97
104
  isListField?: boolean;
98
105
  isList?: boolean;
99
- prefixCls?: string;
100
106
  noStyle?: boolean;
101
- style?: React.CSSProperties;
102
- className?: string;
103
- rootClassName?: string;
104
- id?: string;
105
107
  hasFeedback?: boolean | {
106
108
  icons: import("antd/es/form/FormItem").FeedbackIcons;
107
109
  };
108
110
  validateStatus?: "" | "success" | "warning" | "error" | "validating";
109
- hidden?: boolean;
110
111
  layout?: import("antd/es/form/Form").FormItemLayout;
111
112
  wrapperCol?: import("antd").ColProps;
112
- status?: "" | "success" | "warning" | "error" | "validating";
113
113
  help?: React.ReactNode;
114
114
  fieldId?: string;
115
- toISOString?: boolean;
116
- toCSTString?: boolean;
117
- switchValue?: [any, any];
118
- clearNotShow?: boolean;
119
115
  valueType?: import("../../../render/propsType").ProFormValueType;
120
116
  viewRender?: (value: any, record: any, { form, index, namePath, }: {
121
117
  [key: string]: any;
122
118
  form: FormInstance<any>;
123
119
  index?: number;
124
120
  }) => string | React.ReactElement<any, any>;
125
- trim?: boolean;
126
121
  desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
127
122
  isView?: boolean;
128
- upperCase?: boolean;
123
+ switchValue?: [any, any];
129
124
  viewType?: import("../../../render/propsType").ViewType;
125
+ trim?: boolean;
126
+ upperCase?: boolean;
127
+ toISOString?: boolean;
128
+ toCSTString?: boolean;
129
+ clearNotShow?: boolean;
130
130
  name: any;
131
131
  dependencies: any[];
132
132
  tooltip: string | {
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
141
141
  * 创建组件属性
142
142
  */
143
143
  export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
144
- componentProps: import("lodash").Omit<any, "format" | "toISOString" | "toCSTString" | "switchValue" | "precision" | "clearNotShow" | "dependNames" | "valueType">;
144
+ componentProps: import("lodash").Omit<any, "valueType" | "precision" | "format" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.1.2-beta.3",
3
+ "version": "4.1.2-beta.4",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -44,6 +44,8 @@
44
44
  "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
45
45
  "lint-staged": "lint-staged",
46
46
  "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx --ignore-pattern '**/__tests__/**' --ignore-pattern '**/*.test.*' --ignore-pattern '**/*.spec.*'",
47
+ "code-standards:check": "node ./scripts/code-standards-check.mjs",
48
+ "git:pull:dev_4": "git pull --tags --no-rebase origin dev_4",
47
49
  "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
48
50
  "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
49
51
  "lint:prettier": "prettier --check \"**/*\" --end-of-line auto",
@@ -62,7 +64,7 @@
62
64
  "husky": {
63
65
  "hooks": {
64
66
  "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
65
- "pre-commit": "npm run lint-staged"
67
+ "pre-commit": "npm run lint-staged && npm run code-standards:check"
66
68
  }
67
69
  },
68
70
  "lint-staged": {