@zat-design/sisyphus-react 4.1.2-beta.6 → 4.1.2-beta.7

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.
@@ -699,7 +699,38 @@ var RenderField = _ref => {
699
699
 
700
700
  // 使用useMemo优化最终的formItemProps - 修复Hooks使用规则
701
701
  var finalFormItemProps = useMemo(() => {
702
- return Object.assign(_formItemProps, _objectSpread(_objectSpread(_objectSpread({}, defaultTransform()), namesTransform()), isTrim(type, trim, proConfig)));
702
+ var _namesTransformProps$, _namesTransformProps$2;
703
+ var defaultTransformProps = defaultTransform();
704
+ var namesTransformProps = namesTransform();
705
+ var trimProps = isTrim(type, trim, proConfig); // 使用顶层调用的proConfig
706
+
707
+ var transformNormalize = (_namesTransformProps$ = namesTransformProps === null || namesTransformProps === void 0 ? void 0 : namesTransformProps.normalize) !== null && _namesTransformProps$ !== void 0 ? _namesTransformProps$ : defaultTransformProps === null || defaultTransformProps === void 0 ? void 0 : defaultTransformProps.normalize;
708
+ var userNormalize = _formItemProps === null || _formItemProps === void 0 ? void 0 : _formItemProps.normalize;
709
+ var transformGetValueProps = (_namesTransformProps$2 = namesTransformProps === null || namesTransformProps === void 0 ? void 0 : namesTransformProps.getValueProps) !== null && _namesTransformProps$2 !== void 0 ? _namesTransformProps$2 : defaultTransformProps === null || defaultTransformProps === void 0 ? void 0 : defaultTransformProps.getValueProps;
710
+ var userGetValueProps = _formItemProps === null || _formItemProps === void 0 ? void 0 : _formItemProps.getValueProps;
711
+ var finalNormalize = transformNormalize && userNormalize ? (value, prevValue, allValues, isDiffMode) => {
712
+ // 用户 normalize 需要拿到组件原始值(如 DatePicker 的 dayjs)
713
+ var userValue = userNormalize(value, prevValue, allValues, isDiffMode);
714
+ // 保持用户优先:用户有明确返回值时直接使用,不再强制走内置转换
715
+ if (userValue !== undefined) {
716
+ return userValue;
717
+ }
718
+ // 仅在用户未返回时,回退到内置 transform 逻辑
719
+ return transformNormalize(value, prevValue, allValues, isDiffMode);
720
+ } : userNormalize || transformNormalize;
721
+ var finalGetValueProps = transformGetValueProps && userGetValueProps ? function (value) {
722
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
723
+ args[_key3 - 1] = arguments[_key3];
724
+ }
725
+ var transformValueProps = transformGetValueProps(value, ...args) || {};
726
+ var nextValue = Object.prototype.hasOwnProperty.call(transformValueProps, 'value') ? transformValueProps.value : value;
727
+ var userValueProps = userGetValueProps(nextValue, ...args) || {};
728
+ return _objectSpread(_objectSpread({}, transformValueProps), userValueProps);
729
+ } : userGetValueProps || transformGetValueProps;
730
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _formItemProps), defaultTransformProps), namesTransformProps), trimProps), {}, {
731
+ normalize: finalNormalize,
732
+ getValueProps: finalGetValueProps
733
+ });
703
734
  }, [_formItemProps, defaultTransform, namesTransform, type, trim, proConfig]);
704
735
 
705
736
  // 编辑&保存模式,在查看状态下移除表单的rules不做校验
@@ -950,6 +981,13 @@ export default /*#__PURE__*/memo(RenderField, (prevProps, nextProps) => {
950
981
  }
951
982
  // reactiveParams 中的 form、index、namePath 已经在外层比较过了,无需重复比较
952
983
  }
984
+ // fieldProps 为对象时,必须比较配置变化(如 dataSource 异步更新)
985
+ if (!isFunction(prevColumn === null || prevColumn === void 0 ? void 0 : prevColumn.fieldProps) && !isFunction(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.fieldProps)) {
986
+ var isFieldPropsEqual = isEqualWith(prevColumn === null || prevColumn === void 0 ? void 0 : prevColumn.fieldProps, nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.fieldProps, customEqualForFunction);
987
+ if (!isFieldPropsEqual) {
988
+ return false;
989
+ }
990
+ }
953
991
 
954
992
  // 通用函数比较方法
955
993
  // 优化:不直接调用函数,而是比较输入参数
@@ -22,10 +22,11 @@ import { filterInternalFields } from "../../ProForm/utils";
22
22
  import ProTooltip from "../../ProTooltip";
23
23
  import { RenderField, ActionButton } from "../components";
24
24
  import locale from "../../locale";
25
-
26
- // 渲染操作栏
27
25
  import { jsx as _jsx } from "react/jsx-runtime";
28
26
  import { jsxs as _jsxs } from "react/jsx-runtime";
27
+ var columnDataSourceRefCache = new Map();
28
+
29
+ // 渲染操作栏
29
30
  var getActionColumn = config => {
30
31
  var _cloneDeepWith = cloneDeepWith(config, value => {
31
32
  if ( /*#__PURE__*/React.isValidElement(value)) {
@@ -375,15 +376,33 @@ export var transformColumns = function transformColumns() {
375
376
  // 精准控制单元格更新,减少不必要的渲染
376
377
  if (!item.shouldCellUpdate) {
377
378
  var hasComponent = isFunction(item.component);
379
+ var columnCacheKey = `${Array.isArray(name) ? name.join('.') : String(name)}::${String(columnName)}`;
378
380
  item.shouldCellUpdate = (record, prevRecord) => {
379
- if ((record === null || record === void 0 ? void 0 : record.rowKey) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord.rowKey)) return true;
381
+ var _item$fieldProps;
382
+ var currentDataSourceRef = !isFunction(item === null || item === void 0 ? void 0 : item.fieldProps) ? item === null || item === void 0 || (_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : _item$fieldProps.dataSource : undefined;
383
+ if (currentDataSourceRef !== undefined) {
384
+ var prevDataSourceRef = columnDataSourceRefCache.get(columnCacheKey);
385
+ if (prevDataSourceRef !== currentDataSourceRef) {
386
+ columnDataSourceRefCache.set(columnCacheKey, currentDataSourceRef);
387
+ return true;
388
+ }
389
+ }
390
+ if ((record === null || record === void 0 ? void 0 : record.rowKey) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord.rowKey)) {
391
+ return true;
392
+ }
380
393
  // 单行编辑模式下,需要检测编辑状态变化
381
- if (virtualKey && (record === null || record === void 0 ? void 0 : record._isEditing) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord._isEditing)) return true;
394
+ if (virtualKey && (record === null || record === void 0 ? void 0 : record._isEditing) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord._isEditing)) {
395
+ return true;
396
+ }
382
397
  // 动态 component 可能依赖行内其他字段,需比较整行
383
- if (hasComponent) return !isEqual(record, prevRecord);
398
+ if (hasComponent) {
399
+ var rowChanged = !isEqual(record, prevRecord);
400
+ return rowChanged;
401
+ }
384
402
  var key = item.dataIndex || item.key;
385
403
  if (!key) return true;
386
- return (record === null || record === void 0 ? void 0 : record[key]) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord[key]);
404
+ var keyChanged = (record === null || record === void 0 ? void 0 : record[key]) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord[key]);
405
+ return keyChanged;
387
406
  };
388
407
  }
389
408
  });
@@ -14,7 +14,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
14
14
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
15
  import { useDeepCompareEffect, useRequest as useRequestFunc } from 'ahooks';
16
16
  import { message, Select, Space, Tooltip } from 'antd';
17
- import React, { useImperativeHandle, useState, forwardRef, isValidElement, useCallback, useEffect } from 'react';
17
+ import React, { useImperativeHandle, useState, forwardRef, isValidElement, useCallback, useEffect, useMemo, useRef } from 'react';
18
18
  import { isFunction, isObject, isString, omit, isNumber } from 'lodash';
19
19
  import { useProConfig } from "../ProConfigProvider";
20
20
  import Container from "../ProForm/components/Container";
@@ -22,13 +22,11 @@ import AdaptiveTooltip from "./components/AdaptiveTooltip";
22
22
  import { ProForm } from '..';
23
23
  import locale from "../locale";
24
24
  import { getSelectList } from "./utils";
25
+
26
+ /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
25
27
  import { jsx as _jsx } from "react/jsx-runtime";
26
28
  import { jsxs as _jsxs } from "react/jsx-runtime";
27
29
  import { Fragment as _Fragment } from "react/jsx-runtime";
28
- var Option = Select.Option,
29
- OptGroup = Select.OptGroup;
30
-
31
- /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
32
30
  function flattenOptions(list) {
33
31
  if (!Array.isArray(list) || !list.length) return [];
34
32
  var out = [];
@@ -42,7 +40,7 @@ function flattenOptions(list) {
42
40
  return out;
43
41
  }
44
42
  export var ProSelect = (props, ref) => {
45
- var _selectProps$showCode, _useRequest$options3, _locale$ProSelect;
43
+ var _selectProps$showCode, _ProForm$useFieldProp, _useRequest$options3, _locale$ProSelect;
46
44
  var _ref = useProConfig('ProSelect') || {},
47
45
  _ref$fieldNames = _ref.fieldNames,
48
46
  proSelectFieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
@@ -77,7 +75,7 @@ export var ProSelect = (props, ref) => {
77
75
  selectProps = _objectWithoutProperties(props, _excluded);
78
76
  selectProps.showCodeName = (_selectProps$showCode = selectProps.showCodeName) !== null && _selectProps$showCode !== void 0 ? _selectProps$showCode : showCodeName;
79
77
  var value = getValueProps && props.value ? getValueProps(props.value) : props.value;
80
- var _ref2 = ProForm.useFieldProps() || {},
78
+ var _ref2 = (ProForm === null || ProForm === void 0 || (_ProForm$useFieldProp = ProForm.useFieldProps) === null || _ProForm$useFieldProp === void 0 ? void 0 : _ProForm$useFieldProp.call(ProForm)) || {},
81
79
  isViewCon = _ref2.isView,
82
80
  viewEmpty = _ref2.viewEmpty;
83
81
  var isView = typeof props.isView === 'boolean' ? props.isView : isViewCon; // 组件可直接接收isView参数, 优先级高
@@ -139,6 +137,10 @@ export var ProSelect = (props, ref) => {
139
137
  useRequest === null || useRequest === void 0 || (_useRequest$options = useRequest.options) === null || _useRequest$options === void 0 || (_useRequest$options$o = _useRequest$options.onSuccess) === null || _useRequest$options$o === void 0 || _useRequest$options$o.call(_useRequest$options, data, useRequest === null || useRequest === void 0 || (_useRequest$options2 = useRequest.options) === null || _useRequest$options2 === void 0 ? void 0 : _useRequest$options2.defaultParams);
140
138
  }
141
139
  }));
140
+ var fetchFunctionRef = useRef(fetchFunction);
141
+ useEffect(() => {
142
+ fetchFunctionRef.current = fetchFunction;
143
+ }, [fetchFunction]);
142
144
  var cacheList = useRequest !== null && useRequest !== void 0 && (_useRequest$options3 = useRequest.options) !== null && _useRequest$options3 !== void 0 && _useRequest$options3.cacheKey ? successTransformDataHandle(fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data) : [];
143
145
  var flatOptions = flattenOptions(selectList);
144
146
  var getValueObject = input => {
@@ -316,16 +318,99 @@ export var ProSelect = (props, ref) => {
316
318
  return props.children;
317
319
  };
318
320
  var isReactElement = element => /*#__PURE__*/isValidElement(element);
321
+ var getInnerRecord = option => {
322
+ var _option$data;
323
+ if (!option) return undefined;
324
+ if (option.record) return option.record;
325
+ if ((_option$data = option.data) !== null && _option$data !== void 0 && _option$data.record) return option.data.record;
326
+ return undefined;
327
+ };
328
+ var getOptionText = item => {
329
+ if (OptionRender) {
330
+ var _item$label;
331
+ var rendered = OptionRender(item);
332
+ return isString(rendered) ? rendered : String((_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : '');
333
+ }
334
+ var text = selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label];
335
+ return isString(text) ? text : String(text !== null && text !== void 0 ? text : '');
336
+ };
337
+ var buildOptionItem = (item, index) => {
338
+ var text = getOptionText(item);
339
+ return {
340
+ key: item[code] != null ? `${item[code]}-${index}` : `option-${index}`,
341
+ label: text,
342
+ value: item[code] != null ? item[code] : undefined,
343
+ disabled: !!item.disabled,
344
+ title: text,
345
+ searchText: text,
346
+ record: item
347
+ };
348
+ };
349
+ var selectOptionRender = option => {
350
+ var _option$data2, _ref5, _ref6, _option$data$searchTe, _option$data3, _option$data4;
351
+ var currentRecord = (option === null || option === void 0 || (_option$data2 = option.data) === null || _option$data2 === void 0 ? void 0 : _option$data2.record) || (option === null || option === void 0 ? void 0 : option.record);
352
+ var text = (_ref5 = (_ref6 = (_option$data$searchTe = option === null || option === void 0 || (_option$data3 = option.data) === null || _option$data3 === void 0 ? void 0 : _option$data3.searchText) !== null && _option$data$searchTe !== void 0 ? _option$data$searchTe : option === null || option === void 0 || (_option$data4 = option.data) === null || _option$data4 === void 0 ? void 0 : _option$data4.title) !== null && _ref6 !== void 0 ? _ref6 : option === null || option === void 0 ? void 0 : option.label) !== null && _ref5 !== void 0 ? _ref5 : '';
353
+ if (!currentRecord) {
354
+ return /*#__PURE__*/_jsx(TooltipOption, {
355
+ title: String(text),
356
+ children: String(text)
357
+ });
358
+ }
359
+ return /*#__PURE__*/_jsx(TooltipOption, {
360
+ title: String(text),
361
+ children: OptionRender ? /*#__PURE__*/_jsx("span", {
362
+ children: OptionRender(currentRecord)
363
+ }) : /*#__PURE__*/_jsx("span", {
364
+ children: String(text)
365
+ })
366
+ });
367
+ };
368
+ var defaultFilterOption = useCallback((input, option) => {
369
+ var _ref7, _option$searchText;
370
+ if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
371
+ var optionLabel = (_ref7 = (_option$searchText = option === null || option === void 0 ? void 0 : option.searchText) !== null && _option$searchText !== void 0 ? _option$searchText : option === null || option === void 0 ? void 0 : option.title) !== null && _ref7 !== void 0 ? _ref7 : option === null || option === void 0 ? void 0 : option.label;
372
+ return String(optionLabel !== null && optionLabel !== void 0 ? optionLabel : '').toLowerCase().includes(input.toLowerCase());
373
+ }, []);
374
+ var mergedShowSearch = useMemo(() => {
375
+ var defaultConfig = {
376
+ enabled: true,
377
+ filterOption: isFunction(_onSearch) ? false : defaultFilterOption,
378
+ onSearch: searchValue => {
379
+ _onSearch === null || _onSearch === void 0 || _onSearch(searchValue, _objectSpread({}, fetchFunctionRef.current));
380
+ }
381
+ };
382
+ var customShowSearch = selectProps.showSearch;
383
+ if (customShowSearch === false) {
384
+ return _objectSpread(_objectSpread({}, defaultConfig), {}, {
385
+ enabled: false
386
+ });
387
+ }
388
+ if (customShowSearch === true || customShowSearch == null) {
389
+ return defaultConfig;
390
+ }
391
+ if (isObject(customShowSearch)) {
392
+ var _customShowSearch$fil, _customShowSearch$onS;
393
+ return _objectSpread(_objectSpread(_objectSpread({}, defaultConfig), customShowSearch), {}, {
394
+ enabled: true,
395
+ filterOption: (_customShowSearch$fil = customShowSearch.filterOption) !== null && _customShowSearch$fil !== void 0 ? _customShowSearch$fil : defaultConfig.filterOption,
396
+ onSearch: (_customShowSearch$onS = customShowSearch.onSearch) !== null && _customShowSearch$onS !== void 0 ? _customShowSearch$onS : defaultConfig.onSearch
397
+ });
398
+ }
399
+ return defaultConfig;
400
+ }, [_onSearch, defaultFilterOption, selectProps.showSearch]);
319
401
  var handleChange = (value, _option) => {
320
402
  // option/其第一层子节点是react节点且是labelInValue就拿record
321
403
  var option = _option;
322
404
  if (labelInValue && (isReactElement(_option) || isReactElement(_option === null || _option === void 0 ? void 0 : _option.children))) {
323
- option = _option === null || _option === void 0 ? void 0 : _option.record;
405
+ option = getInnerRecord(_option);
324
406
  }
325
407
  if (selectProps.mode && selectProps.mode === 'multiple') {
326
408
  if (Array.isArray(option)) {
327
409
  option.forEach(item => {
328
- Object.assign(item, item.record);
410
+ var currentRecord = getInnerRecord(item);
411
+ if (currentRecord) {
412
+ Object.assign(item, currentRecord);
413
+ }
329
414
  delete item.record;
330
415
  delete item.children;
331
416
  });
@@ -338,7 +423,7 @@ export var ProSelect = (props, ref) => {
338
423
  } else if (!selectProps.mode && labelInValue) {
339
424
  onChange(getChangeValue ? getChangeValue(getValueObject(value)) : getValueObject(value), option);
340
425
  } else {
341
- onChange === null || onChange === void 0 || onChange(getChangeValue ? getChangeValue(value) : value, _option === null || _option === void 0 ? void 0 : _option.record);
426
+ onChange === null || onChange === void 0 || onChange(getChangeValue ? getChangeValue(value) : value, getInnerRecord(_option));
342
427
  }
343
428
  };
344
429
 
@@ -389,71 +474,41 @@ export var ProSelect = (props, ref) => {
389
474
  mode: selectProps.mode
390
475
  });
391
476
  }
477
+ var selectOptions = Array.isArray(newSelectList) ? newSelectList.map((item, index) => {
478
+ var groupOptions = item.options;
479
+ if (Array.isArray(groupOptions)) {
480
+ var _item$label2;
481
+ return {
482
+ key: (_item$label2 = item[label]) !== null && _item$label2 !== void 0 ? _item$label2 : `group-${index}`,
483
+ label: item[label],
484
+ options: groupOptions.map((opt, optIndex) => buildOptionItem(opt, optIndex))
485
+ };
486
+ }
487
+ return buildOptionItem(item, index);
488
+ }) : [];
489
+ var selectSearchProps = {
490
+ filterOption: mergedShowSearch.filterOption,
491
+ onSearch: mergedShowSearch.onSearch
492
+ };
392
493
  return /*#__PURE__*/_jsx("div", {
393
494
  style: props.style,
394
495
  className: "pro-select",
395
- children: /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread({
496
+ children: /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread(_objectSpread({
396
497
  placeholder: locale === null || locale === void 0 || (_locale$ProSelect = locale.ProSelect) === null || _locale$ProSelect === void 0 ? void 0 : _locale$ProSelect.select,
397
498
  allowClear: true,
398
499
  loading: fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.loading,
399
500
  onChange: handleChange,
400
- showSearch: true,
401
- filterOption: isFunction(_onSearch) ? false : (input, option) => {
402
- var _option$children;
403
- if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
404
- var value = isString(option === null || option === void 0 ? void 0 : option.children) ? option === null || option === void 0 ? void 0 : option.children : option === null || option === void 0 || (_option$children = option.children) === null || _option$children === void 0 || (_option$children = _option$children.props) === null || _option$children === void 0 ? void 0 : _option$children.title;
405
- return value.toLowerCase().includes(input.toLowerCase());
406
- },
407
- onSearch: value => {
408
- _onSearch && _onSearch(value, _objectSpread({}, fetchFunction));
409
- },
501
+ showSearch: mergedShowSearch.enabled
502
+ }, selectSearchProps), {}, {
410
503
  getPopupContainer: trigger => {
411
504
  return scrollFollowParent ? trigger.parentElement : document.body;
412
505
  }
413
- }, omit(_objectSpread({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange', 'getChangeValue', 'viewportReady'])), {}, {
506
+ }, omit(_objectSpread({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange', 'getChangeValue', 'viewportReady', 'showSearch'])), {}, {
414
507
  // 如果是多选模式且用户没有自定义maxTagPlaceholder,使用我们的hover版本
415
508
  maxTagPlaceholder: selectProps.mode === 'multiple' && !selectProps.maxTagPlaceholder ? maxTagPlaceholder : selectProps.maxTagPlaceholder,
509
+ optionRender: selectOptionRender,
416
510
  value: transformValue(),
417
- children: Array.isArray(newSelectList) && newSelectList.map((item, index) => {
418
- var itemValue = item[code];
419
- var itemKey = itemValue != null ? `${itemValue}-${index}` : `option-${index}`;
420
- var optionValue = itemValue != null ? itemValue : undefined;
421
- var groupOpts = item.options;
422
- if (Array.isArray(groupOpts)) {
423
- var _item$label;
424
- return /*#__PURE__*/_jsx(OptGroup, {
425
- label: item[label],
426
- children: groupOpts.map(opt => /*#__PURE__*/_jsx(Option, {
427
- label: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
428
- value: opt[code],
429
- record: opt,
430
- disabled: !!opt.disabled,
431
- children: /*#__PURE__*/_jsx(TooltipOption, {
432
- title: OptionRender ? OptionRender(opt) : selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
433
- children: OptionRender ? /*#__PURE__*/_jsx("span", {
434
- children: OptionRender(opt)
435
- }) : /*#__PURE__*/_jsx("span", {
436
- children: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label]
437
- })
438
- })
439
- }, opt[code]))
440
- }, (_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : `group-${index}`);
441
- }
442
- return /*#__PURE__*/_jsx(Option, {
443
- label: selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label],
444
- value: optionValue,
445
- record: item,
446
- disabled: !!item.disabled,
447
- children: /*#__PURE__*/_jsx(TooltipOption, {
448
- title: OptionRender ? OptionRender(item) : selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label],
449
- children: OptionRender ? /*#__PURE__*/_jsx("span", {
450
- children: OptionRender(item)
451
- }) : /*#__PURE__*/_jsx("span", {
452
- children: selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label]
453
- })
454
- })
455
- }, itemKey);
456
- })
511
+ options: selectOptions
457
512
  }))
458
513
  });
459
514
  };
@@ -706,7 +706,38 @@ var RenderField = _ref => {
706
706
 
707
707
  // 使用useMemo优化最终的formItemProps - 修复Hooks使用规则
708
708
  var finalFormItemProps = (0, _react.useMemo)(() => {
709
- return Object.assign(_formItemProps, _objectSpread(_objectSpread(_objectSpread({}, defaultTransform()), namesTransform()), (0, _utils2.isTrim)(type, trim, proConfig)));
709
+ var _namesTransformProps$, _namesTransformProps$2;
710
+ var defaultTransformProps = defaultTransform();
711
+ var namesTransformProps = namesTransform();
712
+ var trimProps = (0, _utils2.isTrim)(type, trim, proConfig); // 使用顶层调用的proConfig
713
+
714
+ var transformNormalize = (_namesTransformProps$ = namesTransformProps === null || namesTransformProps === void 0 ? void 0 : namesTransformProps.normalize) !== null && _namesTransformProps$ !== void 0 ? _namesTransformProps$ : defaultTransformProps === null || defaultTransformProps === void 0 ? void 0 : defaultTransformProps.normalize;
715
+ var userNormalize = _formItemProps === null || _formItemProps === void 0 ? void 0 : _formItemProps.normalize;
716
+ var transformGetValueProps = (_namesTransformProps$2 = namesTransformProps === null || namesTransformProps === void 0 ? void 0 : namesTransformProps.getValueProps) !== null && _namesTransformProps$2 !== void 0 ? _namesTransformProps$2 : defaultTransformProps === null || defaultTransformProps === void 0 ? void 0 : defaultTransformProps.getValueProps;
717
+ var userGetValueProps = _formItemProps === null || _formItemProps === void 0 ? void 0 : _formItemProps.getValueProps;
718
+ var finalNormalize = transformNormalize && userNormalize ? (value, prevValue, allValues, isDiffMode) => {
719
+ // 用户 normalize 需要拿到组件原始值(如 DatePicker 的 dayjs)
720
+ var userValue = userNormalize(value, prevValue, allValues, isDiffMode);
721
+ // 保持用户优先:用户有明确返回值时直接使用,不再强制走内置转换
722
+ if (userValue !== undefined) {
723
+ return userValue;
724
+ }
725
+ // 仅在用户未返回时,回退到内置 transform 逻辑
726
+ return transformNormalize(value, prevValue, allValues, isDiffMode);
727
+ } : userNormalize || transformNormalize;
728
+ var finalGetValueProps = transformGetValueProps && userGetValueProps ? function (value) {
729
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
730
+ args[_key3 - 1] = arguments[_key3];
731
+ }
732
+ var transformValueProps = transformGetValueProps(value, ...args) || {};
733
+ var nextValue = Object.prototype.hasOwnProperty.call(transformValueProps, 'value') ? transformValueProps.value : value;
734
+ var userValueProps = userGetValueProps(nextValue, ...args) || {};
735
+ return _objectSpread(_objectSpread({}, transformValueProps), userValueProps);
736
+ } : userGetValueProps || transformGetValueProps;
737
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _formItemProps), defaultTransformProps), namesTransformProps), trimProps), {}, {
738
+ normalize: finalNormalize,
739
+ getValueProps: finalGetValueProps
740
+ });
710
741
  }, [_formItemProps, defaultTransform, namesTransform, type, trim, proConfig]);
711
742
 
712
743
  // 编辑&保存模式,在查看状态下移除表单的rules不做校验
@@ -957,6 +988,13 @@ var _default = exports.default = /*#__PURE__*/(0, _react.memo)(RenderField, (pre
957
988
  }
958
989
  // reactiveParams 中的 form、index、namePath 已经在外层比较过了,无需重复比较
959
990
  }
991
+ // fieldProps 为对象时,必须比较配置变化(如 dataSource 异步更新)
992
+ if (!(0, _lodash.isFunction)(prevColumn === null || prevColumn === void 0 ? void 0 : prevColumn.fieldProps) && !(0, _lodash.isFunction)(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.fieldProps)) {
993
+ var isFieldPropsEqual = (0, _lodash.isEqualWith)(prevColumn === null || prevColumn === void 0 ? void 0 : prevColumn.fieldProps, nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.fieldProps, _utils.customEqualForFunction);
994
+ if (!isFieldPropsEqual) {
995
+ return false;
996
+ }
997
+ }
960
998
 
961
999
  // 通用函数比较方法
962
1000
  // 优化:不直接调用函数,而是比较输入参数
@@ -18,7 +18,7 @@ var _components = require("../components");
18
18
  var _locale = _interopRequireDefault(require("../../locale"));
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
20
  var _excluded = ["type", "label", "show", "needConfirm", "onHandle", "onClick", "isSelectModal"],
21
- _excluded2 = ["title", "icon"]; // 渲染操作栏
21
+ _excluded2 = ["title", "icon"];
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
24
24
  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; }
@@ -30,6 +30,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
30
30
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
31
31
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
32
32
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
+ var columnDataSourceRefCache = new Map();
34
+
35
+ // 渲染操作栏
33
36
  var getActionColumn = config => {
34
37
  var _cloneDeepWith = (0, _lodash.cloneDeepWith)(config, value => {
35
38
  if ( /*#__PURE__*/_react.default.isValidElement(value)) {
@@ -379,15 +382,33 @@ var transformColumns = exports.transformColumns = function transformColumns() {
379
382
  // 精准控制单元格更新,减少不必要的渲染
380
383
  if (!item.shouldCellUpdate) {
381
384
  var hasComponent = (0, _lodash.isFunction)(item.component);
385
+ var columnCacheKey = `${Array.isArray(name) ? name.join('.') : String(name)}::${String(columnName)}`;
382
386
  item.shouldCellUpdate = (record, prevRecord) => {
383
- if ((record === null || record === void 0 ? void 0 : record.rowKey) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord.rowKey)) return true;
387
+ var _item$fieldProps;
388
+ var currentDataSourceRef = !(0, _lodash.isFunction)(item === null || item === void 0 ? void 0 : item.fieldProps) ? item === null || item === void 0 || (_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : _item$fieldProps.dataSource : undefined;
389
+ if (currentDataSourceRef !== undefined) {
390
+ var prevDataSourceRef = columnDataSourceRefCache.get(columnCacheKey);
391
+ if (prevDataSourceRef !== currentDataSourceRef) {
392
+ columnDataSourceRefCache.set(columnCacheKey, currentDataSourceRef);
393
+ return true;
394
+ }
395
+ }
396
+ if ((record === null || record === void 0 ? void 0 : record.rowKey) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord.rowKey)) {
397
+ return true;
398
+ }
384
399
  // 单行编辑模式下,需要检测编辑状态变化
385
- if (virtualKey && (record === null || record === void 0 ? void 0 : record._isEditing) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord._isEditing)) return true;
400
+ if (virtualKey && (record === null || record === void 0 ? void 0 : record._isEditing) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord._isEditing)) {
401
+ return true;
402
+ }
386
403
  // 动态 component 可能依赖行内其他字段,需比较整行
387
- if (hasComponent) return !(0, _lodash.isEqual)(record, prevRecord);
404
+ if (hasComponent) {
405
+ var rowChanged = !(0, _lodash.isEqual)(record, prevRecord);
406
+ return rowChanged;
407
+ }
388
408
  var key = item.dataIndex || item.key;
389
409
  if (!key) return true;
390
- return (record === null || record === void 0 ? void 0 : record[key]) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord[key]);
410
+ var keyChanged = (record === null || record === void 0 ? void 0 : record[key]) !== (prevRecord === null || prevRecord === void 0 ? void 0 : prevRecord[key]);
411
+ return keyChanged;
391
412
  };
392
413
  }
393
414
  });
@@ -75,40 +75,29 @@ 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
- toISOString?: boolean;
79
- toCSTString?: boolean;
80
- switchValue?: [any, any];
81
- clearNotShow?: boolean;
82
- style?: React.CSSProperties;
83
- valueType?: import("../../../render/propsType").ProFormValueType;
84
- viewRender?: (value: any, record: any, { form, index, namePath, }: {
85
- [key: string]: any;
86
- form: FormInstance<any>;
87
- index?: number;
88
- }) => string | React.ReactElement<any, any>;
89
- className?: string;
90
- trim?: boolean;
91
- desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
92
- validateTrigger?: string | false | string[];
93
78
  id?: string;
79
+ className?: string;
94
80
  hidden?: boolean;
81
+ style?: React.CSSProperties;
95
82
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
96
83
  onReset?: () => void;
97
84
  prefixCls?: string;
98
- rootClassName?: string;
99
85
  status?: "" | "warning" | "error" | "success" | "validating";
100
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
101
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
102
- shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
86
+ rootClassName?: string;
87
+ isView?: boolean;
103
88
  colon?: boolean;
104
89
  htmlFor?: string;
105
90
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
106
91
  labelCol?: import("antd").ColProps;
107
92
  vertical?: boolean;
108
93
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
94
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
95
+ shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
109
96
  trigger?: string;
97
+ validateTrigger?: string | false | string[];
110
98
  validateDebounce?: number;
111
99
  valuePropName?: string;
100
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
112
101
  messageVariables?: Record<string, string>;
113
102
  initialValue?: any;
114
103
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
@@ -124,9 +113,20 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
124
113
  wrapperCol?: import("antd").ColProps;
125
114
  help?: React.ReactNode;
126
115
  fieldId?: string;
127
- isView?: boolean;
116
+ valueType?: import("../../../render/propsType").ProFormValueType;
117
+ switchValue?: [any, any];
118
+ viewRender?: (value: any, record: any, { form, index, namePath, }: {
119
+ [key: string]: any;
120
+ form: FormInstance<any>;
121
+ index?: number;
122
+ }) => string | React.ReactElement<any, any>;
128
123
  viewType?: import("../../../render/propsType").ViewType;
124
+ trim?: boolean;
129
125
  upperCase?: boolean;
126
+ toISOString?: boolean;
127
+ toCSTString?: boolean;
128
+ clearNotShow?: boolean;
129
+ desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
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, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow" | "precision">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -16,6 +16,7 @@ var _locale = _interopRequireDefault(require("../locale"));
16
16
  var _utils = require("./utils");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
18
  var _excluded = ["dataSource", "useRequest", "fieldNames", "tooltip", "otherProps", "labelInValue", "filterInList", "scrollFollowParent", "defaultOne", "onSearch", "optionRender", "onChange", "transformResponse", "getValueProps", "getChangeValue", "viewportReady", "isView"];
19
+ /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
19
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -32,10 +33,6 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
32
33
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
34
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
34
35
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
- var Option = _antd.Select.Option,
36
- OptGroup = _antd.Select.OptGroup;
37
-
38
- /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
39
36
  function flattenOptions(list) {
40
37
  if (!Array.isArray(list) || !list.length) return [];
41
38
  var out = [];
@@ -49,7 +46,7 @@ function flattenOptions(list) {
49
46
  return out;
50
47
  }
51
48
  var ProSelect = (props, ref) => {
52
- var _selectProps$showCode, _useRequest$options3, _locale$ProSelect;
49
+ var _selectProps$showCode, _ProForm$useFieldProp, _useRequest$options3, _locale$ProSelect;
53
50
  var _ref = (0, _ProConfigProvider.useProConfig)('ProSelect') || {},
54
51
  _ref$fieldNames = _ref.fieldNames,
55
52
  proSelectFieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
@@ -84,7 +81,7 @@ var ProSelect = (props, ref) => {
84
81
  selectProps = _objectWithoutProperties(props, _excluded);
85
82
  selectProps.showCodeName = (_selectProps$showCode = selectProps.showCodeName) !== null && _selectProps$showCode !== void 0 ? _selectProps$showCode : showCodeName;
86
83
  var value = getValueProps && props.value ? getValueProps(props.value) : props.value;
87
- var _ref2 = _.ProForm.useFieldProps() || {},
84
+ var _ref2 = (_.ProForm === null || _.ProForm === void 0 || (_ProForm$useFieldProp = _.ProForm.useFieldProps) === null || _ProForm$useFieldProp === void 0 ? void 0 : _ProForm$useFieldProp.call(_.ProForm)) || {},
88
85
  isViewCon = _ref2.isView,
89
86
  viewEmpty = _ref2.viewEmpty;
90
87
  var isView = typeof props.isView === 'boolean' ? props.isView : isViewCon; // 组件可直接接收isView参数, 优先级高
@@ -146,6 +143,10 @@ var ProSelect = (props, ref) => {
146
143
  useRequest === null || useRequest === void 0 || (_useRequest$options = useRequest.options) === null || _useRequest$options === void 0 || (_useRequest$options$o = _useRequest$options.onSuccess) === null || _useRequest$options$o === void 0 || _useRequest$options$o.call(_useRequest$options, data, useRequest === null || useRequest === void 0 || (_useRequest$options2 = useRequest.options) === null || _useRequest$options2 === void 0 ? void 0 : _useRequest$options2.defaultParams);
147
144
  }
148
145
  }));
146
+ var fetchFunctionRef = (0, _react.useRef)(fetchFunction);
147
+ (0, _react.useEffect)(() => {
148
+ fetchFunctionRef.current = fetchFunction;
149
+ }, [fetchFunction]);
149
150
  var cacheList = useRequest !== null && useRequest !== void 0 && (_useRequest$options3 = useRequest.options) !== null && _useRequest$options3 !== void 0 && _useRequest$options3.cacheKey ? successTransformDataHandle(fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data) : [];
150
151
  var flatOptions = flattenOptions(selectList);
151
152
  var getValueObject = input => {
@@ -323,16 +324,99 @@ var ProSelect = (props, ref) => {
323
324
  return props.children;
324
325
  };
325
326
  var isReactElement = element => /*#__PURE__*/(0, _react.isValidElement)(element);
327
+ var getInnerRecord = option => {
328
+ var _option$data;
329
+ if (!option) return undefined;
330
+ if (option.record) return option.record;
331
+ if ((_option$data = option.data) !== null && _option$data !== void 0 && _option$data.record) return option.data.record;
332
+ return undefined;
333
+ };
334
+ var getOptionText = item => {
335
+ if (OptionRender) {
336
+ var _item$label;
337
+ var rendered = OptionRender(item);
338
+ return (0, _lodash.isString)(rendered) ? rendered : String((_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : '');
339
+ }
340
+ var text = selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label];
341
+ return (0, _lodash.isString)(text) ? text : String(text !== null && text !== void 0 ? text : '');
342
+ };
343
+ var buildOptionItem = (item, index) => {
344
+ var text = getOptionText(item);
345
+ return {
346
+ key: item[code] != null ? `${item[code]}-${index}` : `option-${index}`,
347
+ label: text,
348
+ value: item[code] != null ? item[code] : undefined,
349
+ disabled: !!item.disabled,
350
+ title: text,
351
+ searchText: text,
352
+ record: item
353
+ };
354
+ };
355
+ var selectOptionRender = option => {
356
+ var _option$data2, _ref5, _ref6, _option$data$searchTe, _option$data3, _option$data4;
357
+ var currentRecord = (option === null || option === void 0 || (_option$data2 = option.data) === null || _option$data2 === void 0 ? void 0 : _option$data2.record) || (option === null || option === void 0 ? void 0 : option.record);
358
+ var text = (_ref5 = (_ref6 = (_option$data$searchTe = option === null || option === void 0 || (_option$data3 = option.data) === null || _option$data3 === void 0 ? void 0 : _option$data3.searchText) !== null && _option$data$searchTe !== void 0 ? _option$data$searchTe : option === null || option === void 0 || (_option$data4 = option.data) === null || _option$data4 === void 0 ? void 0 : _option$data4.title) !== null && _ref6 !== void 0 ? _ref6 : option === null || option === void 0 ? void 0 : option.label) !== null && _ref5 !== void 0 ? _ref5 : '';
359
+ if (!currentRecord) {
360
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(TooltipOption, {
361
+ title: String(text),
362
+ children: String(text)
363
+ });
364
+ }
365
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(TooltipOption, {
366
+ title: String(text),
367
+ children: OptionRender ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
368
+ children: OptionRender(currentRecord)
369
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
370
+ children: String(text)
371
+ })
372
+ });
373
+ };
374
+ var defaultFilterOption = (0, _react.useCallback)((input, option) => {
375
+ var _ref7, _option$searchText;
376
+ if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
377
+ var optionLabel = (_ref7 = (_option$searchText = option === null || option === void 0 ? void 0 : option.searchText) !== null && _option$searchText !== void 0 ? _option$searchText : option === null || option === void 0 ? void 0 : option.title) !== null && _ref7 !== void 0 ? _ref7 : option === null || option === void 0 ? void 0 : option.label;
378
+ return String(optionLabel !== null && optionLabel !== void 0 ? optionLabel : '').toLowerCase().includes(input.toLowerCase());
379
+ }, []);
380
+ var mergedShowSearch = (0, _react.useMemo)(() => {
381
+ var defaultConfig = {
382
+ enabled: true,
383
+ filterOption: (0, _lodash.isFunction)(_onSearch) ? false : defaultFilterOption,
384
+ onSearch: searchValue => {
385
+ _onSearch === null || _onSearch === void 0 || _onSearch(searchValue, _objectSpread({}, fetchFunctionRef.current));
386
+ }
387
+ };
388
+ var customShowSearch = selectProps.showSearch;
389
+ if (customShowSearch === false) {
390
+ return _objectSpread(_objectSpread({}, defaultConfig), {}, {
391
+ enabled: false
392
+ });
393
+ }
394
+ if (customShowSearch === true || customShowSearch == null) {
395
+ return defaultConfig;
396
+ }
397
+ if ((0, _lodash.isObject)(customShowSearch)) {
398
+ var _customShowSearch$fil, _customShowSearch$onS;
399
+ return _objectSpread(_objectSpread(_objectSpread({}, defaultConfig), customShowSearch), {}, {
400
+ enabled: true,
401
+ filterOption: (_customShowSearch$fil = customShowSearch.filterOption) !== null && _customShowSearch$fil !== void 0 ? _customShowSearch$fil : defaultConfig.filterOption,
402
+ onSearch: (_customShowSearch$onS = customShowSearch.onSearch) !== null && _customShowSearch$onS !== void 0 ? _customShowSearch$onS : defaultConfig.onSearch
403
+ });
404
+ }
405
+ return defaultConfig;
406
+ }, [_onSearch, defaultFilterOption, selectProps.showSearch]);
326
407
  var handleChange = (value, _option) => {
327
408
  // option/其第一层子节点是react节点且是labelInValue就拿record
328
409
  var option = _option;
329
410
  if (labelInValue && (isReactElement(_option) || isReactElement(_option === null || _option === void 0 ? void 0 : _option.children))) {
330
- option = _option === null || _option === void 0 ? void 0 : _option.record;
411
+ option = getInnerRecord(_option);
331
412
  }
332
413
  if (selectProps.mode && selectProps.mode === 'multiple') {
333
414
  if (Array.isArray(option)) {
334
415
  option.forEach(item => {
335
- Object.assign(item, item.record);
416
+ var currentRecord = getInnerRecord(item);
417
+ if (currentRecord) {
418
+ Object.assign(item, currentRecord);
419
+ }
336
420
  delete item.record;
337
421
  delete item.children;
338
422
  });
@@ -345,7 +429,7 @@ var ProSelect = (props, ref) => {
345
429
  } else if (!selectProps.mode && labelInValue) {
346
430
  onChange(getChangeValue ? getChangeValue(getValueObject(value)) : getValueObject(value), option);
347
431
  } else {
348
- onChange === null || onChange === void 0 || onChange(getChangeValue ? getChangeValue(value) : value, _option === null || _option === void 0 ? void 0 : _option.record);
432
+ onChange === null || onChange === void 0 || onChange(getChangeValue ? getChangeValue(value) : value, getInnerRecord(_option));
349
433
  }
350
434
  };
351
435
 
@@ -396,71 +480,41 @@ var ProSelect = (props, ref) => {
396
480
  mode: selectProps.mode
397
481
  });
398
482
  }
483
+ var selectOptions = Array.isArray(newSelectList) ? newSelectList.map((item, index) => {
484
+ var groupOptions = item.options;
485
+ if (Array.isArray(groupOptions)) {
486
+ var _item$label2;
487
+ return {
488
+ key: (_item$label2 = item[label]) !== null && _item$label2 !== void 0 ? _item$label2 : `group-${index}`,
489
+ label: item[label],
490
+ options: groupOptions.map((opt, optIndex) => buildOptionItem(opt, optIndex))
491
+ };
492
+ }
493
+ return buildOptionItem(item, index);
494
+ }) : [];
495
+ var selectSearchProps = {
496
+ filterOption: mergedShowSearch.filterOption,
497
+ onSearch: mergedShowSearch.onSearch
498
+ };
399
499
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
400
500
  style: props.style,
401
501
  className: "pro-select",
402
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Select, _objectSpread(_objectSpread({
502
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Select, _objectSpread(_objectSpread(_objectSpread({
403
503
  placeholder: _locale.default === null || _locale.default === void 0 || (_locale$ProSelect = _locale.default.ProSelect) === null || _locale$ProSelect === void 0 ? void 0 : _locale$ProSelect.select,
404
504
  allowClear: true,
405
505
  loading: fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.loading,
406
506
  onChange: handleChange,
407
- showSearch: true,
408
- filterOption: (0, _lodash.isFunction)(_onSearch) ? false : (input, option) => {
409
- var _option$children;
410
- if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
411
- var value = (0, _lodash.isString)(option === null || option === void 0 ? void 0 : option.children) ? option === null || option === void 0 ? void 0 : option.children : option === null || option === void 0 || (_option$children = option.children) === null || _option$children === void 0 || (_option$children = _option$children.props) === null || _option$children === void 0 ? void 0 : _option$children.title;
412
- return value.toLowerCase().includes(input.toLowerCase());
413
- },
414
- onSearch: value => {
415
- _onSearch && _onSearch(value, _objectSpread({}, fetchFunction));
416
- },
507
+ showSearch: mergedShowSearch.enabled
508
+ }, selectSearchProps), {}, {
417
509
  getPopupContainer: trigger => {
418
510
  return scrollFollowParent ? trigger.parentElement : document.body;
419
511
  }
420
- }, (0, _lodash.omit)(_objectSpread({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange', 'getChangeValue', 'viewportReady'])), {}, {
512
+ }, (0, _lodash.omit)(_objectSpread({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange', 'getChangeValue', 'viewportReady', 'showSearch'])), {}, {
421
513
  // 如果是多选模式且用户没有自定义maxTagPlaceholder,使用我们的hover版本
422
514
  maxTagPlaceholder: selectProps.mode === 'multiple' && !selectProps.maxTagPlaceholder ? maxTagPlaceholder : selectProps.maxTagPlaceholder,
515
+ optionRender: selectOptionRender,
423
516
  value: transformValue(),
424
- children: Array.isArray(newSelectList) && newSelectList.map((item, index) => {
425
- var itemValue = item[code];
426
- var itemKey = itemValue != null ? `${itemValue}-${index}` : `option-${index}`;
427
- var optionValue = itemValue != null ? itemValue : undefined;
428
- var groupOpts = item.options;
429
- if (Array.isArray(groupOpts)) {
430
- var _item$label;
431
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(OptGroup, {
432
- label: item[label],
433
- children: groupOpts.map(opt => /*#__PURE__*/(0, _jsxRuntime.jsx)(Option, {
434
- label: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
435
- value: opt[code],
436
- record: opt,
437
- disabled: !!opt.disabled,
438
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TooltipOption, {
439
- title: OptionRender ? OptionRender(opt) : selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
440
- children: OptionRender ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
441
- children: OptionRender(opt)
442
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
443
- children: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label]
444
- })
445
- })
446
- }, opt[code]))
447
- }, (_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : `group-${index}`);
448
- }
449
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(Option, {
450
- label: selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label],
451
- value: optionValue,
452
- record: item,
453
- disabled: !!item.disabled,
454
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TooltipOption, {
455
- title: OptionRender ? OptionRender(item) : selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label],
456
- children: OptionRender ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
457
- children: OptionRender(item)
458
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
459
- children: selectProps.showCodeName ? `${item[code]}-${item[label]}` : item[label]
460
- })
461
- })
462
- }, itemKey);
463
- })
517
+ options: selectOptions
464
518
  }))
465
519
  });
466
520
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.1.2-beta.6",
3
+ "version": "4.1.2-beta.7",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",