@pisell/private-materials 6.3.62 → 6.3.63

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.
@@ -6,5 +6,6 @@ import { RenderItemProps } from '../../../../pro/Selector/types';
6
6
  import './index.less';
7
7
  declare const OptionsCard: (props: RenderItemProps & {
8
8
  parentDataSource: any;
9
+ mode: 'single' | 'multiple';
9
10
  }) => React.JSX.Element;
10
11
  export default OptionsCard;
@@ -24,7 +24,7 @@ import OptionsModal from "../OptionsModal";
24
24
  import OptionItemCard from "./OptionItemCard";
25
25
  import "./index.less";
26
26
  var OptionsCard = function OptionsCard(props) {
27
- var _props$dataSource, _props$parentDataSour2, _props$optionItemValu2, _props$dataSource3, _props$optionItemValu4, _props$optionItemValu6, _props$dataSource5;
27
+ var _props$dataSource, _props$parentDataSour2, _props$optionItemValu2, _props$dataSource3, _props$optionItemValu4;
28
28
  var _ref = (props === null || props === void 0 ? void 0 : props.dataSource) || {},
29
29
  uniqueKey = _ref._key,
30
30
  selected = _ref.selected,
@@ -57,33 +57,46 @@ var OptionsCard = function OptionsCard(props) {
57
57
  setModalValue = _useState6[1];
58
58
  // 当前编辑的key
59
59
  var currentEditIndexRef = useRef(-1);
60
+ var _useState7 = useState(-1),
61
+ _useState8 = _slicedToArray(_useState7, 2),
62
+ currentEditIndex = _useState8[0],
63
+ setCurrentEditIndex = _useState8[1];
60
64
  var _indicator = /*#__PURE__*/React.cloneElement(props === null || props === void 0 ? void 0 : props.indicator);
61
65
 
62
66
  // 根据当前Selector已选择了多少选项计算剩余可选数量
63
- // 从props?.values中获取所有的选项的quantity然后相加,再用props?.parentDataSource?.max_quantity减去
64
- var remainingCount = useMemo(function () {
65
- var _props$parentDataSour, _props$values;
66
- var _max = (props === null || props === void 0 || (_props$parentDataSour = props.parentDataSource) === null || _props$parentDataSour === void 0 || (_props$parentDataSour = _props$parentDataSour.ruleConfig) === null || _props$parentDataSour === void 0 ? void 0 : _props$parentDataSour.max) || 0;
67
- if (_max <= 0) return 0;
68
- return _max - ((props === null || props === void 0 || (_props$values = props.values) === null || _props$values === void 0 ? void 0 : _props$values.reduce(function (sum, i) {
67
+ // 全局最大值 - 所有已选项的数量总和
68
+ var selectorRemainingCount = useMemo(function () {
69
+ var _props$parentDataSour;
70
+ var globalMax = (props === null || props === void 0 || (_props$parentDataSour = props.parentDataSource) === null || _props$parentDataSour === void 0 || (_props$parentDataSour = _props$parentDataSour.ruleConfig) === null || _props$parentDataSour === void 0 ? void 0 : _props$parentDataSour.max) || 0;
71
+ if (globalMax <= 0) return Infinity; // 无限制
72
+
73
+ var values = Array.isArray(props === null || props === void 0 ? void 0 : props.values) ? props === null || props === void 0 ? void 0 : props.values : [props === null || props === void 0 ? void 0 : props.values];
74
+ var totalSelected = values.reduce(function (sum, i) {
69
75
  return sum + ((i === null || i === void 0 ? void 0 : i.quantity) || 0);
70
- }, 0)) || 0);
76
+ }, 0) || 0;
77
+ return Math.max(0, globalMax - totalSelected);
71
78
  }, [props === null || props === void 0 || (_props$parentDataSour2 = props.parentDataSource) === null || _props$parentDataSour2 === void 0 || (_props$parentDataSour2 = _props$parentDataSour2.ruleConfig) === null || _props$parentDataSour2 === void 0 ? void 0 : _props$parentDataSour2.max, props === null || props === void 0 ? void 0 : props.values]);
72
79
 
73
- // 当前选项剩余可选数量
74
- var currentOptionRemainingCount = useMemo(function () {
80
+ // 当前选项剩余可选数量 = min(全局剩余, 选项自己的剩余)
81
+ var optionRemainingCount = useMemo(function () {
75
82
  var _props$optionItemValu, _props$dataSource2;
76
- if (remainingCount <= 0) return 0;
77
- var _quantity = (props === null || props === void 0 || (_props$optionItemValu = props.optionItemValue) === null || _props$optionItemValu === void 0 ? void 0 : _props$optionItemValu.quantity) || 0;
78
- if (_quantity >= remainingCount) {
79
- return 0;
80
- }
81
- var _max = (props === null || props === void 0 || (_props$dataSource2 = props.dataSource) === null || _props$dataSource2 === void 0 || (_props$dataSource2 = _props$dataSource2.ruleConfig) === null || _props$dataSource2 === void 0 ? void 0 : _props$dataSource2.max) || 0;
82
- if (_max > 0 && _quantity >= _max) {
83
- return 0;
83
+ var currentQuantity = (props === null || props === void 0 || (_props$optionItemValu = props.optionItemValue) === null || _props$optionItemValu === void 0 ? void 0 : _props$optionItemValu.quantity) || 0;
84
+ var optionMax = (props === null || props === void 0 || (_props$dataSource2 = props.dataSource) === null || _props$dataSource2 === void 0 || (_props$dataSource2 = _props$dataSource2.ruleConfig) === null || _props$dataSource2 === void 0 ? void 0 : _props$dataSource2.max) || 0;
85
+
86
+ // 选项自己的剩余数量(0表示无限制)
87
+ var optionRemaining = optionMax > 0 ? optionMax - currentQuantity : Infinity;
88
+
89
+ // 取Selector剩余和当前选项剩余的最小值
90
+ return Math.max(0, Math.min(selectorRemainingCount, optionRemaining));
91
+ }, [props === null || props === void 0 || (_props$optionItemValu2 = props.optionItemValue) === null || _props$optionItemValu2 === void 0 ? void 0 : _props$optionItemValu2.quantity, selectorRemainingCount, props === null || props === void 0 || (_props$dataSource3 = props.dataSource) === null || _props$dataSource3 === void 0 || (_props$dataSource3 = _props$dataSource3.ruleConfig) === null || _props$dataSource3 === void 0 ? void 0 : _props$dataSource3.max]);
92
+
93
+ // 弹窗剩余可选数量:如果是单选场景下,新增数据时,optionRemainingCount在小于等于0时,设置为1,用于单选能能够切换选择
94
+ var modalRemainingCount = useMemo(function () {
95
+ if ((props === null || props === void 0 ? void 0 : props.mode) === 'single' && currentEditIndex === -1) {
96
+ return optionRemainingCount <= 0 ? 1 : optionRemainingCount;
84
97
  }
85
- return Math.min(remainingCount, _max) - _quantity;
86
- }, [props === null || props === void 0 || (_props$optionItemValu2 = props.optionItemValue) === null || _props$optionItemValu2 === void 0 ? void 0 : _props$optionItemValu2.quantity, remainingCount, props === null || props === void 0 || (_props$dataSource3 = props.dataSource) === null || _props$dataSource3 === void 0 || (_props$dataSource3 = _props$dataSource3.ruleConfig) === null || _props$dataSource3 === void 0 ? void 0 : _props$dataSource3.max]);
98
+ return optionRemainingCount;
99
+ }, [props === null || props === void 0 ? void 0 : props.mode, optionRemainingCount, currentEditIndex]);
87
100
 
88
101
  // 价格文本
89
102
  var priceText = useMemo(function () {
@@ -101,25 +114,23 @@ var OptionsCard = function OptionsCard(props) {
101
114
  setModalDataSource(renderOptionGroup || []);
102
115
  }
103
116
  };
104
-
105
- // 是否禁用
106
- var isDisabled = useMemo(function () {
107
- var _props$optionItemValu5, _props$dataSource4;
117
+ var handleClick = function handleClick() {
108
118
  if (disabled) {
109
- return true;
110
- }
111
- var _quantity = (props === null || props === void 0 || (_props$optionItemValu5 = props.optionItemValue) === null || _props$optionItemValu5 === void 0 ? void 0 : _props$optionItemValu5.quantity) || 0;
112
- if (_quantity >= remainingCount) {
113
- return true;
119
+ console.log('handleClick_disabled>>>>>', disabled);
120
+ return;
114
121
  }
115
- var _max = (props === null || props === void 0 || (_props$dataSource4 = props.dataSource) === null || _props$dataSource4 === void 0 || (_props$dataSource4 = _props$dataSource4.ruleConfig) === null || _props$dataSource4 === void 0 ? void 0 : _props$dataSource4.max) || 0;
116
- if (_max > 0 && _quantity >= _max) {
117
- return true;
122
+ var needShowToast = false;
123
+ // 如果是单选场景下,如果剩余可选量小于等于0,但是点击的不是已选中选项,则不禁止用户点击,用于单选能能够切换选择
124
+ if (optionRemainingCount <= 0) {
125
+ if ((props === null || props === void 0 ? void 0 : props.mode) === 'single' && !selected) {
126
+ needShowToast = false;
127
+ } else {
128
+ needShowToast = true;
129
+ }
130
+ } else {
131
+ needShowToast = false;
118
132
  }
119
- return false;
120
- }, [disabled, props === null || props === void 0 || (_props$optionItemValu6 = props.optionItemValue) === null || _props$optionItemValu6 === void 0 ? void 0 : _props$optionItemValu6.quantity, remainingCount, props === null || props === void 0 || (_props$dataSource5 = props.dataSource) === null || _props$dataSource5 === void 0 || (_props$dataSource5 = _props$dataSource5.ruleConfig) === null || _props$dataSource5 === void 0 ? void 0 : _props$dataSource5.max]);
121
- var handleClick = function handleClick() {
122
- if (isDisabled) {
133
+ if (needShowToast) {
123
134
  PisellToast({
124
135
  content: locales.getText('pisell2.skuOptionsSelection.optionItemCard.overSelected')
125
136
  });
@@ -127,14 +138,16 @@ var OptionsCard = function OptionsCard(props) {
127
138
  }
128
139
  setModalValue({});
129
140
  currentEditIndexRef.current = -1;
141
+ setCurrentEditIndex(-1);
130
142
  setIsOpen(true);
131
143
  transformDataSource();
132
144
  };
133
145
  var handleUpdateClick = function handleUpdateClick(index) {
134
- var _props$optionItemValu7;
146
+ var _props$optionItemValu5;
135
147
  currentEditIndexRef.current = index;
148
+ setCurrentEditIndex(index);
136
149
  setIsOpen(true);
137
- setModalValue((props === null || props === void 0 || (_props$optionItemValu7 = props.optionItemValue) === null || _props$optionItemValu7 === void 0 || (_props$optionItemValu7 = _props$optionItemValu7.data) === null || _props$optionItemValu7 === void 0 || (_props$optionItemValu7 = _props$optionItemValu7._data) === null || _props$optionItemValu7 === void 0 ? void 0 : _props$optionItemValu7[index]) || {});
150
+ setModalValue((props === null || props === void 0 || (_props$optionItemValu5 = props.optionItemValue) === null || _props$optionItemValu5 === void 0 || (_props$optionItemValu5 = _props$optionItemValu5.data) === null || _props$optionItemValu5 === void 0 || (_props$optionItemValu5 = _props$optionItemValu5._data) === null || _props$optionItemValu5 === void 0 ? void 0 : _props$optionItemValu5[index]) || {});
138
151
  transformDataSource();
139
152
  };
140
153
  var handleConfirm = function handleConfirm(v) {
@@ -159,8 +172,8 @@ var OptionsCard = function OptionsCard(props) {
159
172
  setModalValue({});
160
173
  };
161
174
  var handleQuantityChange = function handleQuantityChange(_index, _quantity) {
162
- var _props$optionItemValu8, _props$actions2;
163
- var currentData = (props === null || props === void 0 || (_props$optionItemValu8 = props.optionItemValue) === null || _props$optionItemValu8 === void 0 || (_props$optionItemValu8 = _props$optionItemValu8.data) === null || _props$optionItemValu8 === void 0 || (_props$optionItemValu8 = _props$optionItemValu8._data) === null || _props$optionItemValu8 === void 0 ? void 0 : _props$optionItemValu8[_index]) || {};
175
+ var _props$optionItemValu6, _props$actions2;
176
+ var currentData = (props === null || props === void 0 || (_props$optionItemValu6 = props.optionItemValue) === null || _props$optionItemValu6 === void 0 || (_props$optionItemValu6 = _props$optionItemValu6.data) === null || _props$optionItemValu6 === void 0 || (_props$optionItemValu6 = _props$optionItemValu6._data) === null || _props$optionItemValu6 === void 0 ? void 0 : _props$optionItemValu6[_index]) || {};
164
177
  var _calculateOptionItem3 = calculateOptionItem({
165
178
  editIndex: _index,
166
179
  optionItemValue: props === null || props === void 0 ? void 0 : props.optionItemValue,
@@ -212,7 +225,7 @@ var OptionsCard = function OptionsCard(props) {
212
225
  parentDataSource: props === null || props === void 0 ? void 0 : props.parentDataSource,
213
226
  dataSource: props === null || props === void 0 ? void 0 : props.dataSource,
214
227
  data: selectedOptions,
215
- remainingCount: Math.min(remainingCount, currentOptionRemainingCount),
228
+ remainingCount: optionRemainingCount,
216
229
  onEdit: handleUpdateClick,
217
230
  onQuantityChange: handleQuantityChange
218
231
  }), isOpen && /*#__PURE__*/React.createElement(OptionsModal, {
@@ -222,7 +235,7 @@ var OptionsCard = function OptionsCard(props) {
222
235
  values: props === null || props === void 0 ? void 0 : props.values,
223
236
  optionItemValue: props === null || props === void 0 ? void 0 : props.optionItemValue,
224
237
  modalValue: modalValue,
225
- remainingCount: Math.min(remainingCount, currentOptionRemainingCount),
238
+ remainingCount: modalRemainingCount,
226
239
  open: isOpen,
227
240
  title: title || name || '',
228
241
  onCancel: function onCancel() {
@@ -145,7 +145,8 @@ var OptionsModal = function OptionsModal(props) {
145
145
  display: 'flex',
146
146
  flexDirection: 'column'
147
147
  },
148
- width: (customConfig === null || customConfig === void 0 ? void 0 : customConfig.modalWidth) || '480px'
148
+ width: (customConfig === null || customConfig === void 0 ? void 0 : customConfig.modalWidth) || '480px',
149
+ mobileModalHeight: 'auto'
149
150
  }, /*#__PURE__*/React.createElement(SelectorGroup, {
150
151
  ref: selectorGroupRef,
151
152
  dataSource: props === null || props === void 0 ? void 0 : props.modalDataSource,
@@ -57,7 +57,8 @@ export var transformBundleGroup = function transformBundleGroup(bundleGroup) {
57
57
  ruleConfig: {
58
58
  min: item === null || item === void 0 ? void 0 : item.min_quantity,
59
59
  // 单选时,max为undefined防止选中一个以后把其他的置灰了
60
- max: (item === null || item === void 0 ? void 0 : item.max_quantity) === 1 ? undefined : item === null || item === void 0 ? void 0 : item.max_quantity,
60
+ // max: item?.max_quantity === 1 ? undefined : item?.max_quantity,
61
+ max: item === null || item === void 0 ? void 0 : item.max_quantity,
61
62
  autoValidate: true,
62
63
  required: Number(item === null || item === void 0 ? void 0 : item.min_quantity) > 0 ? true : false
63
64
  },
@@ -77,7 +78,8 @@ export var transformBundleGroup = function transformBundleGroup(bundleGroup) {
77
78
  // console.log('bundle_group_itemProps---', itemProps);
78
79
  if (!!(itemProps !== null && itemProps !== void 0 && (_itemProps$dataSource = itemProps.dataSource) !== null && _itemProps$dataSource !== void 0 && (_itemProps$dataSource = _itemProps$dataSource._original) !== null && _itemProps$dataSource !== void 0 && (_itemProps$dataSource = _itemProps$dataSource.option_group) !== null && _itemProps$dataSource !== void 0 && _itemProps$dataSource.length)) {
79
80
  return /*#__PURE__*/React.createElement(OptionsCard, _extends({}, itemProps || {}, {
80
- parentDataSource: selectorDataSource
81
+ parentDataSource: selectorDataSource,
82
+ mode: selectorDataSource === null || selectorDataSource === void 0 ? void 0 : selectorDataSource.mode
81
83
  }));
82
84
  }
83
85
  return /*#__PURE__*/React.createElement(NormalCard, _extends({}, itemProps || {}, {
@@ -157,7 +157,9 @@ var Selector = /*#__PURE__*/forwardRef(function (props, ref) {
157
157
  var _option$ruleConfig$mi, _option$ruleConfig, _ruleConfig$min, _option$ruleConfig$ma, _option$ruleConfig2;
158
158
  var optionItemValue = Array.isArray(state.values) ? state.values.find(function (item) {
159
159
  return (item === null || item === void 0 ? void 0 : item.value) === option._key;
160
- }) : state.values;
160
+ }) : [state.values].find(function (item) {
161
+ return (item === null || item === void 0 ? void 0 : item.value) === option._key;
162
+ });
161
163
  if ( /*#__PURE__*/React.isValidElement(renderItem)) {
162
164
  return renderItem;
163
165
  }
@@ -163,14 +163,14 @@ export default function useSelectionController(props) {
163
163
  return normalizedOptions.map(function (option) {
164
164
  var state = getOptionState(option._key);
165
165
  // 如果已达到最大值,未选的选项应该被禁用
166
- var disabled = quantityInfo.maxReached && !state.selected;
166
+ var disabled = quantityInfo.maxReached && !(mode === 'single' && (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max) === 1) && !state.selected;
167
167
  return _objectSpread(_objectSpread({}, option), {}, {
168
168
  selected: state.selected,
169
169
  quantity: state.quantity,
170
170
  disabled: option.disabled || disabled
171
171
  });
172
172
  });
173
- }, [normalizedOptions, getOptionState, quantityInfo.maxReached]);
173
+ }, [normalizedOptions, getOptionState, quantityInfo.maxReached, mode, ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max]);
174
174
  var validate = /*#__PURE__*/function () {
175
175
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
176
176
  var errors, _ref3, required, min, max, customValidator, values, currentNormalizedValues, objValue, totalQuantity, selectedValues, selectedKeys, type, message;
@@ -6,5 +6,6 @@ import { RenderItemProps } from '../../../../pro/Selector/types';
6
6
  import './index.less';
7
7
  declare const OptionsCard: (props: RenderItemProps & {
8
8
  parentDataSource: any;
9
+ mode: 'single' | 'multiple';
9
10
  }) => React.JSX.Element;
10
11
  export default OptionsCard;
@@ -42,7 +42,7 @@ var import_OptionsModal = __toESM(require("../OptionsModal"));
42
42
  var import_OptionItemCard = __toESM(require("./OptionItemCard"));
43
43
  var import_index = require("./index.less");
44
44
  var OptionsCard = (props) => {
45
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
45
+ var _a, _b, _c, _d, _e, _f, _g, _h;
46
46
  const { _key: uniqueKey, selected, disabled } = (props == null ? void 0 : props.dataSource) || {};
47
47
  const {
48
48
  cover,
@@ -59,33 +59,33 @@ var OptionsCard = (props) => {
59
59
  const [modalDataSource, setModalDataSource] = (0, import_react.useState)([]);
60
60
  const [modalValue, setModalValue] = (0, import_react.useState)({});
61
61
  const currentEditIndexRef = (0, import_react.useRef)(-1);
62
+ const [currentEditIndex, setCurrentEditIndex] = (0, import_react.useState)(-1);
62
63
  const _indicator = import_react.default.cloneElement(props == null ? void 0 : props.indicator);
63
- const remainingCount = (0, import_react.useMemo)(() => {
64
- var _a2, _b2, _c2;
65
- const _max = ((_b2 = (_a2 = props == null ? void 0 : props.parentDataSource) == null ? void 0 : _a2.ruleConfig) == null ? void 0 : _b2.max) || 0;
66
- if (_max <= 0) return 0;
67
- return _max - (((_c2 = props == null ? void 0 : props.values) == null ? void 0 : _c2.reduce(
68
- (sum, i) => sum + ((i == null ? void 0 : i.quantity) || 0),
69
- 0
70
- )) || 0);
64
+ const selectorRemainingCount = (0, import_react.useMemo)(() => {
65
+ var _a2, _b2;
66
+ const globalMax = ((_b2 = (_a2 = props == null ? void 0 : props.parentDataSource) == null ? void 0 : _a2.ruleConfig) == null ? void 0 : _b2.max) || 0;
67
+ if (globalMax <= 0) return Infinity;
68
+ const values = Array.isArray(props == null ? void 0 : props.values) ? props == null ? void 0 : props.values : [props == null ? void 0 : props.values];
69
+ const totalSelected = values.reduce((sum, i) => sum + ((i == null ? void 0 : i.quantity) || 0), 0) || 0;
70
+ return Math.max(0, globalMax - totalSelected);
71
71
  }, [(_c = (_b = props == null ? void 0 : props.parentDataSource) == null ? void 0 : _b.ruleConfig) == null ? void 0 : _c.max, props == null ? void 0 : props.values]);
72
- const currentOptionRemainingCount = (0, import_react.useMemo)(() => {
72
+ const optionRemainingCount = (0, import_react.useMemo)(() => {
73
73
  var _a2, _b2, _c2;
74
- if (remainingCount <= 0) return 0;
75
- const _quantity = ((_a2 = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _a2.quantity) || 0;
76
- if (_quantity >= remainingCount) {
77
- return 0;
78
- }
79
- const _max = ((_c2 = (_b2 = props == null ? void 0 : props.dataSource) == null ? void 0 : _b2.ruleConfig) == null ? void 0 : _c2.max) || 0;
80
- if (_max > 0 && _quantity >= _max) {
81
- return 0;
82
- }
83
- return Math.min(remainingCount, _max) - _quantity;
74
+ const currentQuantity = ((_a2 = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _a2.quantity) || 0;
75
+ const optionMax = ((_c2 = (_b2 = props == null ? void 0 : props.dataSource) == null ? void 0 : _b2.ruleConfig) == null ? void 0 : _c2.max) || 0;
76
+ const optionRemaining = optionMax > 0 ? optionMax - currentQuantity : Infinity;
77
+ return Math.max(0, Math.min(selectorRemainingCount, optionRemaining));
84
78
  }, [
85
79
  (_d = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _d.quantity,
86
- remainingCount,
80
+ selectorRemainingCount,
87
81
  (_f = (_e = props == null ? void 0 : props.dataSource) == null ? void 0 : _e.ruleConfig) == null ? void 0 : _f.max
88
82
  ]);
83
+ const modalRemainingCount = (0, import_react.useMemo)(() => {
84
+ if ((props == null ? void 0 : props.mode) === "single" && currentEditIndex === -1) {
85
+ return optionRemainingCount <= 0 ? 1 : optionRemainingCount;
86
+ }
87
+ return optionRemainingCount;
88
+ }, [props == null ? void 0 : props.mode, optionRemainingCount, currentEditIndex]);
89
89
  const priceText = (0, import_react.useMemo)(() => {
90
90
  return `${price_type === "markdown" ? "-" : ""}${symbol}${Math.abs(
91
91
  Number(price || 0)
@@ -101,28 +101,22 @@ var OptionsCard = (props) => {
101
101
  setModalDataSource(renderOptionGroup || []);
102
102
  }
103
103
  };
104
- const isDisabled = (0, import_react.useMemo)(() => {
105
- var _a2, _b2, _c2;
104
+ const handleClick = () => {
106
105
  if (disabled) {
107
- return true;
108
- }
109
- const _quantity = ((_a2 = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _a2.quantity) || 0;
110
- if (_quantity >= remainingCount) {
111
- return true;
106
+ console.log("handleClick_disabled>>>>>", disabled);
107
+ return;
112
108
  }
113
- const _max = ((_c2 = (_b2 = props == null ? void 0 : props.dataSource) == null ? void 0 : _b2.ruleConfig) == null ? void 0 : _c2.max) || 0;
114
- if (_max > 0 && _quantity >= _max) {
115
- return true;
109
+ let needShowToast = false;
110
+ if (optionRemainingCount <= 0) {
111
+ if ((props == null ? void 0 : props.mode) === "single" && !selected) {
112
+ needShowToast = false;
113
+ } else {
114
+ needShowToast = true;
115
+ }
116
+ } else {
117
+ needShowToast = false;
116
118
  }
117
- return false;
118
- }, [
119
- disabled,
120
- (_i = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _i.quantity,
121
- remainingCount,
122
- (_k = (_j = props == null ? void 0 : props.dataSource) == null ? void 0 : _j.ruleConfig) == null ? void 0 : _k.max
123
- ]);
124
- const handleClick = () => {
125
- if (isDisabled) {
119
+ if (needShowToast) {
126
120
  (0, import_materials.PisellToast)({
127
121
  content: import_utils.locales.getText(
128
122
  "pisell2.skuOptionsSelection.optionItemCard.overSelected"
@@ -132,12 +126,14 @@ var OptionsCard = (props) => {
132
126
  }
133
127
  setModalValue({});
134
128
  currentEditIndexRef.current = -1;
129
+ setCurrentEditIndex(-1);
135
130
  setIsOpen(true);
136
131
  transformDataSource();
137
132
  };
138
133
  const handleUpdateClick = (index) => {
139
134
  var _a2, _b2, _c2;
140
135
  currentEditIndexRef.current = index;
136
+ setCurrentEditIndex(index);
141
137
  setIsOpen(true);
142
138
  setModalValue(((_c2 = (_b2 = (_a2 = props == null ? void 0 : props.optionItemValue) == null ? void 0 : _a2.data) == null ? void 0 : _b2._data) == null ? void 0 : _c2[index]) || {});
143
139
  transformDataSource();
@@ -209,7 +205,7 @@ var OptionsCard = (props) => {
209
205
  parentDataSource: props == null ? void 0 : props.parentDataSource,
210
206
  dataSource: props == null ? void 0 : props.dataSource,
211
207
  data: selectedOptions,
212
- remainingCount: Math.min(remainingCount, currentOptionRemainingCount),
208
+ remainingCount: optionRemainingCount,
213
209
  onEdit: handleUpdateClick,
214
210
  onQuantityChange: handleQuantityChange
215
211
  }
@@ -222,7 +218,7 @@ var OptionsCard = (props) => {
222
218
  values: props == null ? void 0 : props.values,
223
219
  optionItemValue: props == null ? void 0 : props.optionItemValue,
224
220
  modalValue,
225
- remainingCount: Math.min(remainingCount, currentOptionRemainingCount),
221
+ remainingCount: modalRemainingCount,
226
222
  open: isOpen,
227
223
  title: title || name || "",
228
224
  onCancel: () => setIsOpen(false),
@@ -120,7 +120,8 @@ var OptionsModal = (props) => {
120
120
  display: "flex",
121
121
  flexDirection: "column"
122
122
  },
123
- width: (customConfig == null ? void 0 : customConfig.modalWidth) || "480px"
123
+ width: (customConfig == null ? void 0 : customConfig.modalWidth) || "480px",
124
+ mobileModalHeight: "auto"
124
125
  },
125
126
  /* @__PURE__ */ import_react.default.createElement(
126
127
  SelectorGroup,
@@ -73,7 +73,8 @@ var transformBundleGroup = (bundleGroup) => {
73
73
  ruleConfig: {
74
74
  min: item == null ? void 0 : item.min_quantity,
75
75
  // 单选时,max为undefined防止选中一个以后把其他的置灰了
76
- max: (item == null ? void 0 : item.max_quantity) === 1 ? void 0 : item == null ? void 0 : item.max_quantity,
76
+ // max: item?.max_quantity === 1 ? undefined : item?.max_quantity,
77
+ max: item == null ? void 0 : item.max_quantity,
77
78
  autoValidate: true,
78
79
  required: Number(item == null ? void 0 : item.min_quantity) > 0 ? true : false
79
80
  },
@@ -93,7 +94,8 @@ var transformBundleGroup = (bundleGroup) => {
93
94
  import_OptionsCard.default,
94
95
  {
95
96
  ...itemProps || {},
96
- parentDataSource: selectorDataSource
97
+ parentDataSource: selectorDataSource,
98
+ mode: selectorDataSource == null ? void 0 : selectorDataSource.mode
97
99
  }
98
100
  );
99
101
  }
@@ -159,7 +159,7 @@ var Selector = (0, import_react.forwardRef)((props, ref) => {
159
159
  };
160
160
  const renderOption = (option) => {
161
161
  var _a2, _b2;
162
- const optionItemValue = Array.isArray(state.values) ? state.values.find((item) => (item == null ? void 0 : item.value) === option._key) : state.values;
162
+ const optionItemValue = Array.isArray(state.values) ? state.values.find((item) => (item == null ? void 0 : item.value) === option._key) : [state.values].find((item) => (item == null ? void 0 : item.value) === option._key);
163
163
  if (import_react.default.isValidElement(renderItem)) {
164
164
  return renderItem;
165
165
  }
@@ -131,7 +131,7 @@ function useSelectionController(props) {
131
131
  const options = (0, import_react.useMemo)(() => {
132
132
  return normalizedOptions.map((option) => {
133
133
  const state = getOptionState(option._key);
134
- const disabled = quantityInfo.maxReached && !state.selected;
134
+ const disabled = quantityInfo.maxReached && !(mode === "single" && (ruleConfig == null ? void 0 : ruleConfig.max) === 1) && !state.selected;
135
135
  return {
136
136
  ...option,
137
137
  selected: state.selected,
@@ -139,7 +139,7 @@ function useSelectionController(props) {
139
139
  disabled: option.disabled || disabled
140
140
  };
141
141
  });
142
- }, [normalizedOptions, getOptionState, quantityInfo.maxReached]);
142
+ }, [normalizedOptions, getOptionState, quantityInfo.maxReached, mode, ruleConfig == null ? void 0 : ruleConfig.max]);
143
143
  const validate = async () => {
144
144
  const errors2 = [];
145
145
  const { required, min, max, customValidator } = ruleConfig || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.3.62",
3
+ "version": "6.3.63",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",