@pisell/private-materials 6.12.160 → 6.12.161
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.
- package/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/preview.js +1 -1
- package/build/lowcode/render/default/view.js +18 -18
- package/build/lowcode/view.js +18 -18
- package/es/components/bigSale/components/BookingFloatingPanel/useBookingPanelController.js +1 -0
- package/es/components/bigSale/components/TimeBar/index.js +1 -0
- package/es/components/bigSale/dialog.js +1 -0
- package/es/components/bigSale/hooks/useBigSaleContext.js +1 -0
- package/es/components/bigSale/hooks/useSelectFloorMapResourceForBigSale.js +1 -0
- package/es/components/bigSale/index.js +3 -2
- package/es/components/bigSale/templates/Kiosk/index.js +1 -0
- package/es/components/sharedSecondaryBigSale/SharedSecondaryBigSaleReceiver.js +1 -0
- package/es/index.js +2 -0
- package/es/plus/pisellReservation/data/bookingToReservationTables.js +1 -1
- package/es/plus/pisellReservation/floorMap/floorPlanApi.js +1 -1
- package/es/plus/pisellReservation/floorMap/reservationMock.js +1 -1
- package/es/plus/pisellReservation/index.js +17 -0
- package/es/plus/saleDetail/Base.js +1 -0
- package/es/plus/saleDetail/components/CartItems/Editable/index.js +1 -0
- package/es/plus/saleDetail/components/Client/hooks/useClientSelectorProps.js +1 -0
- package/es/plus/saleDetail/components/DetailActions/index.js +1 -0
- package/es/plus/saleDetail/components/SummaryFinancialSections/index.js +1 -0
- package/es/plus/saleDetail/index.js +1 -0
- package/es/plus/saleDetail/tmpl/B/components/Dish/index.js +1 -0
- package/es/plus/saleDetail/tmpl/B/index.js +1 -0
- package/es/plus/salesSdk/context/SalesSdkCartContext.js +25 -12
- package/es/plus/salesSdk/context/SalesSdkProvider.js +9 -5
- package/es/plus/salesSdk/hosts/BookingEditHostRenderer.js +12 -7
- package/es/plus/salesSdk/index.js +51 -0
- package/es/plus/salesSdk/utils/addProductWithFlowDebounced.js +1 -1
- package/es/plus/salesSdk/utils/bookingDate.js +1 -1
- package/es/plus/salesSdk/utils/customerAuthGate.js +1 -1
- package/es/plus/salesSdk/utils/enrichCartLineHolderDisplay.js +1 -1
- package/es/plus/salesSdk/utils/resolvePreviousService.js +28 -0
- package/es/plus/skuOptionsSelection/components/NormalCard/index.js +18 -12
- package/es/plus/skuOptionsSelection/docs/skuOptionsSelection.$tab-dev.md +66 -2
- package/es/plus/skuOptionsSelection/types.d.ts +50 -1
- package/es/plus/skuOptionsSelection/utils/normalizers.js +17 -0
- package/es/plus/skuOptionsSelection/utils/transformOptionGroup.js +17 -7
- package/es/plus/skuOptionsSelection/utils/transformSelectorValueToValue.js +89 -15
- package/es/plus/skuOptionsSelection/utils/transformValueToSelectorValue.js +31 -19
- package/es/pro/Login2.0/AuthModal.d.ts +1 -1
- package/es/pro/Login2.0/index.d.ts +2 -1
- package/es/pro/Login2.0/shared/types.d.ts +1 -1
- package/es/pro/Selector/Selector.js +11 -6
- package/es/pro/Selector/hooks/useSelectionController.js +54 -61
- package/es/pro/Selector/locales.js +10 -0
- package/es/pro/Selector/types.d.ts +5 -0
- package/es/pro/skuDetailModal/types.d.ts +1 -0
- package/lib/components/bigSale/index.js +2 -2
- package/lib/plus/saleDetail/components/CartItems/Editable/index.js +1 -0
- package/lib/plus/salesSdk/context/SalesSdkCartContext.js +25 -12
- package/lib/plus/salesSdk/context/SalesSdkProvider.js +9 -5
- package/lib/plus/salesSdk/hosts/BookingEditHostRenderer.js +12 -7
- package/lib/plus/salesSdk/utils/resolvePreviousService.js +30 -0
- package/lib/plus/skuOptionsSelection/components/NormalCard/index.js +18 -12
- package/lib/plus/skuOptionsSelection/docs/skuOptionsSelection.$tab-dev.md +66 -2
- package/lib/plus/skuOptionsSelection/types.d.ts +50 -1
- package/lib/plus/skuOptionsSelection/utils/normalizers.js +19 -0
- package/lib/plus/skuOptionsSelection/utils/transformOptionGroup.js +17 -7
- package/lib/plus/skuOptionsSelection/utils/transformSelectorValueToValue.js +89 -15
- package/lib/plus/skuOptionsSelection/utils/transformValueToSelectorValue.js +31 -19
- package/lib/pro/Selector/Selector.js +11 -6
- package/lib/pro/Selector/hooks/useSelectionController.js +54 -61
- package/lib/pro/Selector/locales.js +10 -0
- package/lib/pro/Selector/types.d.ts +5 -0
- package/lib/pro/skuDetailModal/types.d.ts +1 -0
- package/package.json +4 -4
- package/es/private-materials/lowcode/authmodal/meta.d.ts +0 -1
|
@@ -2,10 +2,46 @@ const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
|
|
|
2
2
|
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
|
|
3
3
|
const require_objectWithoutProperties = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
|
|
4
4
|
const require_store = require("../store/store.js");
|
|
5
|
+
const require_normalizers = require("./normalizers.js");
|
|
5
6
|
let decimal_js = require("decimal.js");
|
|
6
7
|
decimal_js = require_runtime.__toESM(decimal_js);
|
|
7
8
|
//#region src/plus/skuOptionsSelection/utils/transformSelectorValueToValue.ts
|
|
8
9
|
const _excluded = ["_data"];
|
|
10
|
+
const isSameNodeId = (left, right) => left !== null && left !== void 0 && right !== null && right !== void 0 && String(left) === String(right);
|
|
11
|
+
const getOptionItemId = (value) => {
|
|
12
|
+
var _value$id;
|
|
13
|
+
return (_value$id = value === null || value === void 0 ? void 0 : value.id) !== null && _value$id !== void 0 ? _value$id : value === null || value === void 0 ? void 0 : value.product_option_item_id;
|
|
14
|
+
};
|
|
15
|
+
const getBundleItemId = (value) => {
|
|
16
|
+
var _value$id2;
|
|
17
|
+
return (_value$id2 = value === null || value === void 0 ? void 0 : value.id) !== null && _value$id2 !== void 0 ? _value$id2 : value === null || value === void 0 ? void 0 : value.bundle_id;
|
|
18
|
+
};
|
|
19
|
+
const getBundleGroupId = (value) => {
|
|
20
|
+
var _value$group_id;
|
|
21
|
+
return (_value$group_id = value === null || value === void 0 ? void 0 : value.group_id) !== null && _value$group_id !== void 0 ? _value$group_id : value === null || value === void 0 ? void 0 : value.bundle_group_id;
|
|
22
|
+
};
|
|
23
|
+
const createOutputOption = (params) => {
|
|
24
|
+
var _ref, _ref2, _selectorItem$quantit, _selectorItem$value, _currentGroup$id, _currentGroup$option_, _currentOptionItem$id;
|
|
25
|
+
const { selectorItem, optionGroupId, currentOptionGroups = [], snapshotOptions = [] } = params;
|
|
26
|
+
const itemData = (selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.data) || {};
|
|
27
|
+
const quantity = Number((_ref = (_ref2 = (_selectorItem$quantit = selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.quantity) !== null && _selectorItem$quantit !== void 0 ? _selectorItem$quantit : itemData === null || itemData === void 0 ? void 0 : itemData.quantity) !== null && _ref2 !== void 0 ? _ref2 : itemData === null || itemData === void 0 ? void 0 : itemData.num) !== null && _ref !== void 0 ? _ref : 0);
|
|
28
|
+
if (!(quantity > 0)) return null;
|
|
29
|
+
const optionItemId = (_selectorItem$value = selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.value) !== null && _selectorItem$value !== void 0 ? _selectorItem$value : getOptionItemId(itemData);
|
|
30
|
+
const requestedGroupId = optionGroupId !== null && optionGroupId !== void 0 ? optionGroupId : itemData === null || itemData === void 0 ? void 0 : itemData.option_group_id;
|
|
31
|
+
const currentGroup = currentOptionGroups.find((group) => isSameNodeId(group === null || group === void 0 ? void 0 : group.id, requestedGroupId));
|
|
32
|
+
const resolvedGroupId = (_currentGroup$id = currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.id) !== null && _currentGroup$id !== void 0 ? _currentGroup$id : requestedGroupId;
|
|
33
|
+
const currentOptionItem = currentGroup === null || currentGroup === void 0 || (_currentGroup$option_ = currentGroup.option_item) === null || _currentGroup$option_ === void 0 ? void 0 : _currentGroup$option_.find((item) => isSameNodeId(item === null || item === void 0 ? void 0 : item.id, optionItemId));
|
|
34
|
+
const resolvedOptionItemId = (_currentOptionItem$id = currentOptionItem === null || currentOptionItem === void 0 ? void 0 : currentOptionItem.id) !== null && _currentOptionItem$id !== void 0 ? _currentOptionItem$id : optionItemId;
|
|
35
|
+
const snapshotOption = snapshotOptions.find((item) => isSameNodeId(getOptionItemId(item), optionItemId) && ((item === null || item === void 0 ? void 0 : item.option_group_id) === null || (item === null || item === void 0 ? void 0 : item.option_group_id) === void 0 || isSameNodeId(item === null || item === void 0 ? void 0 : item.option_group_id, resolvedGroupId)));
|
|
36
|
+
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, itemData), {}, {
|
|
37
|
+
id: resolvedOptionItemId,
|
|
38
|
+
product_option_item_id: resolvedOptionItemId,
|
|
39
|
+
option_group_id: resolvedGroupId,
|
|
40
|
+
production_code: currentOptionItem ? require_normalizers.resolveProductionCode(snapshotOption, currentOptionItem) : "",
|
|
41
|
+
quantity,
|
|
42
|
+
num: quantity
|
|
43
|
+
});
|
|
44
|
+
};
|
|
9
45
|
/**
|
|
10
46
|
* 将SelectorValue转换为Value
|
|
11
47
|
*/
|
|
@@ -13,6 +49,8 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
13
49
|
var _dataSource$bundle_gr, _dataSource$option_gr, _dataSource$variant_g;
|
|
14
50
|
if (!selectorValue) return {};
|
|
15
51
|
const dataSource = require_store.default.getState().dataSource;
|
|
52
|
+
const originalValue = require_store.default.getState().value;
|
|
53
|
+
let selectedVariant = null;
|
|
16
54
|
const transformValue = {
|
|
17
55
|
bundle: [],
|
|
18
56
|
option: [],
|
|
@@ -27,37 +65,65 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
27
65
|
const groupItemValue = selectorValue === null || selectorValue === void 0 ? void 0 : selectorValue[groupId];
|
|
28
66
|
if (!groupId || !groupItemValue) return;
|
|
29
67
|
(Array.isArray(groupItemValue) ? groupItemValue : [groupItemValue]).forEach((item) => {
|
|
30
|
-
|
|
68
|
+
var _item$value, _bundleGroupItem$bund;
|
|
69
|
+
const bundleItemId = (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : getBundleItemId(item === null || item === void 0 ? void 0 : item.data);
|
|
70
|
+
const currentBundleItem = bundleGroupItem === null || bundleGroupItem === void 0 || (_bundleGroupItem$bund = bundleGroupItem.bundle_item) === null || _bundleGroupItem$bund === void 0 ? void 0 : _bundleGroupItem$bund.find((bundleItem) => isSameNodeId(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.id, bundleItemId));
|
|
71
|
+
const bundleSnapshots = ((originalValue === null || originalValue === void 0 ? void 0 : originalValue.bundle) || []).filter((bundleItem) => isSameNodeId(getBundleItemId(bundleItem), bundleItemId) && (getBundleGroupId(bundleItem) === null || getBundleGroupId(bundleItem) === void 0 || isSameNodeId(getBundleGroupId(bundleItem), groupId)));
|
|
72
|
+
const bundleSnapshot = bundleSnapshots.find((bundleItem) => require_normalizers.hasOwnProductionCode(bundleItem));
|
|
73
|
+
const _ref3 = (item === null || item === void 0 ? void 0 : item.data) || {}, { _data } = _ref3, rest = require_objectWithoutProperties._objectWithoutProperties(_ref3, _excluded);
|
|
31
74
|
if (_data) _data === null || _data === void 0 || _data.forEach((_item) => {
|
|
32
75
|
if (_item === null || _item === void 0 ? void 0 : _item.data) {
|
|
33
|
-
|
|
76
|
+
const bundleQuantity = Number((_item === null || _item === void 0 ? void 0 : _item.quantity) || 0);
|
|
77
|
+
if (!(bundleQuantity > 0)) return;
|
|
78
|
+
let _newData = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, rest), {}, {
|
|
79
|
+
option: [],
|
|
80
|
+
production_code: currentBundleItem ? require_normalizers.resolveProductionCode(bundleSnapshot, currentBundleItem) : ""
|
|
81
|
+
});
|
|
34
82
|
let totalPrice = new decimal_js.default(0);
|
|
35
83
|
Object.keys(_item === null || _item === void 0 ? void 0 : _item.data).forEach((key) => {
|
|
36
84
|
var _item$data;
|
|
37
85
|
const _itemDataItem = _item === null || _item === void 0 || (_item$data = _item.data) === null || _item$data === void 0 ? void 0 : _item$data[key];
|
|
38
86
|
if (Array.isArray(_itemDataItem)) _itemDataItem.forEach((_itemDataItem_item) => {
|
|
39
|
-
|
|
87
|
+
const outputOption = createOutputOption({
|
|
88
|
+
selectorItem: _itemDataItem_item,
|
|
89
|
+
optionGroupId: key,
|
|
90
|
+
currentOptionGroups: (currentBundleItem === null || currentBundleItem === void 0 ? void 0 : currentBundleItem.option_group) || [],
|
|
91
|
+
snapshotOptions: bundleSnapshots.flatMap((bundleItem) => (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option) || [])
|
|
92
|
+
});
|
|
93
|
+
if (!outputOption) return;
|
|
40
94
|
totalPrice = totalPrice.plus(new decimal_js.default((_itemDataItem_item === null || _itemDataItem_item === void 0 ? void 0 : _itemDataItem_item.totalPrice) || 0));
|
|
41
|
-
_newData.option.push(
|
|
95
|
+
_newData.option.push(outputOption);
|
|
42
96
|
});
|
|
43
97
|
else {
|
|
44
|
-
|
|
98
|
+
const outputOption = createOutputOption({
|
|
99
|
+
selectorItem: _itemDataItem,
|
|
100
|
+
optionGroupId: key,
|
|
101
|
+
currentOptionGroups: (currentBundleItem === null || currentBundleItem === void 0 ? void 0 : currentBundleItem.option_group) || [],
|
|
102
|
+
snapshotOptions: bundleSnapshots.flatMap((bundleItem) => (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option) || [])
|
|
103
|
+
});
|
|
104
|
+
if (!outputOption) return;
|
|
45
105
|
totalPrice = totalPrice.plus(new decimal_js.default((_itemDataItem === null || _itemDataItem === void 0 ? void 0 : _itemDataItem.totalPrice) || 0));
|
|
46
|
-
_newData.option.push(
|
|
106
|
+
_newData.option.push(outputOption);
|
|
47
107
|
}
|
|
48
108
|
});
|
|
49
109
|
const _restPricePrefix = (rest === null || rest === void 0 ? void 0 : rest.price_type) === "markdown" ? -1 : 1;
|
|
50
110
|
_newData.price = totalPrice.plus(new decimal_js.default((rest === null || rest === void 0 ? void 0 : rest.price) || 0).times(_restPricePrefix)).toString();
|
|
51
111
|
_newData.original_price = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
52
112
|
_newData.original_total = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
53
|
-
_newData.quantity =
|
|
54
|
-
_newData.num =
|
|
113
|
+
_newData.quantity = bundleQuantity;
|
|
114
|
+
_newData.num = bundleQuantity;
|
|
55
115
|
_newData._bundle_product_id = _newData === null || _newData === void 0 ? void 0 : _newData.bundle_product_id;
|
|
56
116
|
transformValue.bundle.push(_newData);
|
|
57
117
|
}
|
|
58
118
|
});
|
|
59
119
|
else {
|
|
120
|
+
var _ref4, _ref5, _item$quantity;
|
|
60
121
|
const _newData = require_objectSpread2._objectSpread2({}, (item === null || item === void 0 ? void 0 : item.data) || {});
|
|
122
|
+
const bundleQuantity = Number((_ref4 = (_ref5 = (_item$quantity = item === null || item === void 0 ? void 0 : item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : _newData === null || _newData === void 0 ? void 0 : _newData.quantity) !== null && _ref5 !== void 0 ? _ref5 : _newData === null || _newData === void 0 ? void 0 : _newData.num) !== null && _ref4 !== void 0 ? _ref4 : 0);
|
|
123
|
+
if (!(bundleQuantity > 0)) return;
|
|
124
|
+
_newData.production_code = currentBundleItem ? require_normalizers.resolveProductionCode(bundleSnapshot, currentBundleItem) : "";
|
|
125
|
+
_newData.quantity = bundleQuantity;
|
|
126
|
+
_newData.num = bundleQuantity;
|
|
61
127
|
const _pricePrefix = (_newData === null || _newData === void 0 ? void 0 : _newData.price_type) === "markdown" ? -1 : 1;
|
|
62
128
|
_newData.price = new decimal_js.default((_newData === null || _newData === void 0 ? void 0 : _newData.price) || 0).times(_pricePrefix).toString();
|
|
63
129
|
_newData.original_price = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
@@ -79,8 +145,13 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
79
145
|
else _groupItemValue = [groupItemValue];
|
|
80
146
|
_groupItemValue === null || _groupItemValue === void 0 || _groupItemValue.forEach((item) => {
|
|
81
147
|
if (item === null || item === void 0 ? void 0 : item.data) {
|
|
82
|
-
|
|
83
|
-
|
|
148
|
+
const outputOption = createOutputOption({
|
|
149
|
+
selectorItem: item,
|
|
150
|
+
optionGroupId: groupId,
|
|
151
|
+
currentOptionGroups: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.option_group) || [],
|
|
152
|
+
snapshotOptions: (originalValue === null || originalValue === void 0 ? void 0 : originalValue.option) || []
|
|
153
|
+
});
|
|
154
|
+
if (outputOption) transformValue.option.push(outputOption);
|
|
84
155
|
}
|
|
85
156
|
});
|
|
86
157
|
});
|
|
@@ -98,9 +169,9 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
98
169
|
else _groupItemValue = [groupItemValue];
|
|
99
170
|
_groupItemValue === null || _groupItemValue === void 0 || _groupItemValue.forEach((item) => {
|
|
100
171
|
if (item === null || item === void 0 ? void 0 : item.data) {
|
|
101
|
-
var _item$
|
|
102
|
-
selectedVariantIds.push(`${item === null || item === void 0 || (_item$
|
|
103
|
-
selectedVariantOptionString.push(`${variantGroupItem === null || variantGroupItem === void 0 ? void 0 : variantGroupItem.name}:${item === null || item === void 0 || (_item$
|
|
172
|
+
var _item$data2, _item$data3, _item$data4;
|
|
173
|
+
selectedVariantIds.push(`${item === null || item === void 0 || (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.variant_group_id}:${item === null || item === void 0 || (_item$data3 = item.data) === null || _item$data3 === void 0 ? void 0 : _item$data3.id}`);
|
|
174
|
+
selectedVariantOptionString.push(`${variantGroupItem === null || variantGroupItem === void 0 ? void 0 : variantGroupItem.name}:${item === null || item === void 0 || (_item$data4 = item.data) === null || _item$data4 === void 0 ? void 0 : _item$data4.name}`);
|
|
104
175
|
}
|
|
105
176
|
});
|
|
106
177
|
});
|
|
@@ -112,12 +183,15 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
112
183
|
return selectedVariantIds.every((idItem) => ids.includes(idItem));
|
|
113
184
|
});
|
|
114
185
|
if (filteredVariant === null || filteredVariant === void 0 ? void 0 : filteredVariant.length) {
|
|
115
|
-
|
|
116
|
-
transformValue.product_variant_id =
|
|
186
|
+
selectedVariant = filteredVariant[0];
|
|
187
|
+
transformValue.product_variant_id = selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.id;
|
|
117
188
|
transformValue.product_option_string = selectedVariantOptionString.join(", ");
|
|
118
189
|
}
|
|
119
190
|
}
|
|
120
191
|
}
|
|
192
|
+
if (selectedVariant) transformValue.production_code = require_normalizers.resolveProductionCode(isSameNodeId(originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id, selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.id) ? originalValue : void 0, selectedVariant);
|
|
193
|
+
else transformValue.production_code = require_normalizers.resolveProductionCode((originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === null || (originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === void 0 || Number(originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === 0 ? originalValue : void 0, dataSource);
|
|
194
|
+
console.log("transformSelectorValueToValue>>>>>", transformValue);
|
|
121
195
|
return transformValue;
|
|
122
196
|
};
|
|
123
197
|
//#endregion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
|
|
3
|
+
const require_normalizers = require("./normalizers.js");
|
|
3
4
|
let decimal_js = require("decimal.js");
|
|
4
5
|
decimal_js = require_runtime.__toESM(decimal_js);
|
|
5
6
|
//#region src/plus/skuOptionsSelection/utils/transformValueToSelectorValue.ts
|
|
@@ -15,16 +16,17 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
15
16
|
if (value === null || value === void 0 ? void 0 : value.bundle) {
|
|
16
17
|
var _value$bundle, _newBundle$forEach;
|
|
17
18
|
const newBundle = value === null || value === void 0 || (_value$bundle = value.bundle) === null || _value$bundle === void 0 ? void 0 : _value$bundle.reduce((acc, v) => {
|
|
18
|
-
|
|
19
|
+
var _v$id;
|
|
20
|
+
const _bundleItemId = (_v$id = v === null || v === void 0 ? void 0 : v.id) !== null && _v$id !== void 0 ? _v$id : v === null || v === void 0 ? void 0 : v.bundle_id;
|
|
19
21
|
const idx = acc === null || acc === void 0 ? void 0 : acc.findIndex((v1) => (v1 === null || v1 === void 0 ? void 0 : v1.id) === _bundleItemId);
|
|
20
22
|
if (idx !== -1) {
|
|
21
23
|
var _acc$idx, _acc$idx$push;
|
|
22
24
|
(_acc$idx = acc[idx]) === null || _acc$idx === void 0 || (_acc$idx = _acc$idx.bundleOptions) === null || _acc$idx === void 0 || (_acc$idx$push = _acc$idx.push) === null || _acc$idx$push === void 0 || _acc$idx$push.call(_acc$idx, v);
|
|
23
25
|
} else {
|
|
24
|
-
var _acc$push;
|
|
26
|
+
var _acc$push, _v$group_id;
|
|
25
27
|
acc === null || acc === void 0 || (_acc$push = acc.push) === null || _acc$push === void 0 || _acc$push.call(acc, {
|
|
26
28
|
id: _bundleItemId,
|
|
27
|
-
groupId: v === null || v === void 0 ? void 0 : v.group_id,
|
|
29
|
+
groupId: (_v$group_id = v === null || v === void 0 ? void 0 : v.group_id) !== null && _v$group_id !== void 0 ? _v$group_id : v === null || v === void 0 ? void 0 : v.bundle_group_id,
|
|
28
30
|
bundleOptions: [v]
|
|
29
31
|
});
|
|
30
32
|
}
|
|
@@ -33,6 +35,7 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
33
35
|
newBundle === null || newBundle === void 0 || (_newBundle$forEach = newBundle.forEach) === null || _newBundle$forEach === void 0 || _newBundle$forEach.call(newBundle, (v1) => {
|
|
34
36
|
const _bundleGroupId = v1 === null || v1 === void 0 ? void 0 : v1.groupId;
|
|
35
37
|
const _bundleValue = createBundleValue(v1, dataSource);
|
|
38
|
+
if (!_bundleValue) return;
|
|
36
39
|
if (transformValue[_bundleGroupId]) transformValue[_bundleGroupId] = [...transformValue[_bundleGroupId] || [], _bundleValue];
|
|
37
40
|
else transformValue[_bundleGroupId] = [_bundleValue];
|
|
38
41
|
});
|
|
@@ -79,7 +82,7 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
79
82
|
* 创建套餐商品数据
|
|
80
83
|
*/
|
|
81
84
|
const createBundleValue = (v, dataSource) => {
|
|
82
|
-
var _dataSource$bundle_gr, _v$
|
|
85
|
+
var _dataSource$bundle_gr, _v$bundleOptions2, _v$bundleOptions2$for;
|
|
83
86
|
let _createdValue = null;
|
|
84
87
|
const bundleGroupItem = dataSource === null || dataSource === void 0 || (_dataSource$bundle_gr = dataSource.bundle_group) === null || _dataSource$bundle_gr === void 0 ? void 0 : _dataSource$bundle_gr.find((v1) => {
|
|
85
88
|
return isSameId(v1 === null || v1 === void 0 ? void 0 : v1.id, v === null || v === void 0 ? void 0 : v.groupId);
|
|
@@ -90,29 +93,34 @@ const createBundleValue = (v, dataSource) => {
|
|
|
90
93
|
findedBundleItem = bundleGroupItem === null || bundleGroupItem === void 0 || (_bundleGroupItem$bund = bundleGroupItem.bundle_item) === null || _bundleGroupItem$bund === void 0 ? void 0 : _bundleGroupItem$bund.find((v1) => {
|
|
91
94
|
return isSameId(v1 === null || v1 === void 0 ? void 0 : v1.id, v === null || v === void 0 ? void 0 : v.id);
|
|
92
95
|
});
|
|
93
|
-
if (!!findedBundleItem)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
if (!!findedBundleItem) {
|
|
97
|
+
var _v$bundleOptions;
|
|
98
|
+
const bundleSnapshot = v === null || v === void 0 || (_v$bundleOptions = v.bundleOptions) === null || _v$bundleOptions === void 0 ? void 0 : _v$bundleOptions.find((item) => require_normalizers.hasOwnProductionCode(item));
|
|
99
|
+
_createdValue = {
|
|
100
|
+
value: findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.id,
|
|
101
|
+
data: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, findedBundleItem || {}), {}, { production_code: require_normalizers.resolveProductionCode(bundleSnapshot, findedBundleItem) })
|
|
102
|
+
};
|
|
103
|
+
}
|
|
97
104
|
}
|
|
98
105
|
if (!_createdValue) return null;
|
|
99
106
|
let totalQuantity = 0;
|
|
100
|
-
v === null || v === void 0 || (_v$
|
|
101
|
-
var _v1$option;
|
|
107
|
+
v === null || v === void 0 || (_v$bundleOptions2 = v.bundleOptions) === null || _v$bundleOptions2 === void 0 || (_v$bundleOptions2$for = _v$bundleOptions2.forEach) === null || _v$bundleOptions2$for === void 0 || _v$bundleOptions2$for.call(_v$bundleOptions2, (v1) => {
|
|
108
|
+
var _v1$option, _v1$quantity2;
|
|
102
109
|
if (v1 === null || v1 === void 0 || (_v1$option = v1.option) === null || _v1$option === void 0 ? void 0 : _v1$option.length) {
|
|
103
|
-
var _createdValue$data;
|
|
110
|
+
var _createdValue$data, _v1$quantity;
|
|
104
111
|
const _data = (_createdValue === null || _createdValue === void 0 || (_createdValue$data = _createdValue.data) === null || _createdValue$data === void 0 ? void 0 : _createdValue$data._data) || [];
|
|
105
112
|
const _createdValueData = createOptionValue({}, v1, findedBundleItem);
|
|
106
113
|
_data.push({
|
|
107
|
-
value:
|
|
114
|
+
value: findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.id,
|
|
108
115
|
data: _createdValueData,
|
|
109
|
-
quantity: (v1 === null || v1 === void 0 ? void 0 : v1.quantity) || 1
|
|
116
|
+
quantity: require_normalizers.normalizeNonNegativeInteger((_v1$quantity = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity !== void 0 ? _v1$quantity : v1 === null || v1 === void 0 ? void 0 : v1.num, 1)
|
|
110
117
|
});
|
|
111
118
|
_createdValue.data._data = _data;
|
|
112
119
|
}
|
|
113
|
-
|
|
120
|
+
const itemQuantity = require_normalizers.normalizeNonNegativeInteger((_v1$quantity2 = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity2 !== void 0 ? _v1$quantity2 : v1 === null || v1 === void 0 ? void 0 : v1.num, 1);
|
|
121
|
+
totalQuantity = totalQuantity + itemQuantity;
|
|
114
122
|
const _price = (v1 === null || v1 === void 0 ? void 0 : v1.price) || (findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.price) || 0;
|
|
115
|
-
_createdValue.totalPrice = new decimal_js.default(_createdValue.totalPrice || 0).plus(new decimal_js.default(_price).times(
|
|
123
|
+
_createdValue.totalPrice = new decimal_js.default(_createdValue.totalPrice || 0).plus(new decimal_js.default(_price).times(itemQuantity)).toNumber();
|
|
116
124
|
});
|
|
117
125
|
_createdValue.quantity = totalQuantity;
|
|
118
126
|
_createdValue.data.quantity = totalQuantity;
|
|
@@ -126,21 +134,25 @@ const createOptionValue = (initValue, value, dataSource) => {
|
|
|
126
134
|
var _value$option, _value$option$forEach;
|
|
127
135
|
let _createdValue = initValue || {};
|
|
128
136
|
value === null || value === void 0 || (_value$option = value.option) === null || _value$option === void 0 || (_value$option$forEach = _value$option.forEach) === null || _value$option$forEach === void 0 || _value$option$forEach.call(_value$option, (v1) => {
|
|
129
|
-
var _dataSource$option_gr, _matchedGroup$option_;
|
|
137
|
+
var _v1$id, _dataSource$option_gr, _matchedGroup$option_, _v1$quantity3;
|
|
130
138
|
const _optionGroupId = v1 === null || v1 === void 0 ? void 0 : v1.option_group_id;
|
|
139
|
+
const optionItemId = (_v1$id = v1 === null || v1 === void 0 ? void 0 : v1.id) !== null && _v1$id !== void 0 ? _v1$id : v1 === null || v1 === void 0 ? void 0 : v1.product_option_item_id;
|
|
131
140
|
const matchedGroup = dataSource === null || dataSource === void 0 || (_dataSource$option_gr = dataSource.option_group) === null || _dataSource$option_gr === void 0 ? void 0 : _dataSource$option_gr.find((v2) => isSameId(v2 === null || v2 === void 0 ? void 0 : v2.id, _optionGroupId));
|
|
132
|
-
const matchedOptionItem = matchedGroup === null || matchedGroup === void 0 || (_matchedGroup$option_ = matchedGroup.option_item) === null || _matchedGroup$option_ === void 0 ? void 0 : _matchedGroup$option_.find((v3) => isSameId(v3 === null || v3 === void 0 ? void 0 : v3.id,
|
|
133
|
-
const _num = (v1 === null || v1 === void 0 ? void 0 : v1.quantity)
|
|
141
|
+
const matchedOptionItem = matchedGroup === null || matchedGroup === void 0 || (_matchedGroup$option_ = matchedGroup.option_item) === null || _matchedGroup$option_ === void 0 ? void 0 : _matchedGroup$option_.find((v3) => isSameId(v3 === null || v3 === void 0 ? void 0 : v3.id, optionItemId));
|
|
142
|
+
const _num = require_normalizers.normalizeNonNegativeInteger((_v1$quantity3 = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity3 !== void 0 ? _v1$quantity3 : v1 === null || v1 === void 0 ? void 0 : v1.num, 1);
|
|
134
143
|
const _price = (matchedOptionItem === null || matchedOptionItem === void 0 ? void 0 : matchedOptionItem.add_price) || 0;
|
|
135
144
|
const _tempOptionValue = {
|
|
136
145
|
data: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, matchedOptionItem || {}), v1 || {}), {}, {
|
|
146
|
+
id: optionItemId,
|
|
147
|
+
product_option_item_id: optionItemId,
|
|
148
|
+
production_code: matchedOptionItem ? require_normalizers.resolveProductionCode(v1, matchedOptionItem) : "",
|
|
137
149
|
num: _num,
|
|
138
150
|
price: _price,
|
|
139
151
|
original_price: _price,
|
|
140
152
|
original_total: _price
|
|
141
153
|
}),
|
|
142
154
|
quantity: _num,
|
|
143
|
-
value:
|
|
155
|
+
value: optionItemId,
|
|
144
156
|
totalPrice: new decimal_js.default((matchedOptionItem === null || matchedOptionItem === void 0 ? void 0 : matchedOptionItem.add_price) || 0).times(_num).toNumber()
|
|
145
157
|
};
|
|
146
158
|
if (_createdValue[_optionGroupId]) _createdValue[_optionGroupId] = [..._createdValue[_optionGroupId] || [], _tempOptionValue];
|
|
@@ -94,23 +94,28 @@ const Selector = (0, react.forwardRef)((props, ref) => {
|
|
|
94
94
|
if (props.showStepper === false) return null;
|
|
95
95
|
if ((props.showStepper === "auto" || props.showStepper === void 0) && !showQuantity) return null;
|
|
96
96
|
return /* @__PURE__ */ react.default.createElement(require_index$2.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props.stepperProps || {}), {}, {
|
|
97
|
-
min:
|
|
97
|
+
min: 0,
|
|
98
98
|
max: option.effectiveMax,
|
|
99
99
|
value: option.quantity,
|
|
100
100
|
disabled: disabled || option.disabled,
|
|
101
|
-
onChange: (value) => {
|
|
102
|
-
|
|
101
|
+
onChange: (value, meta) => {
|
|
102
|
+
const initialQuantity = Math.max(1, Number((option === null || option === void 0 ? void 0 : option.effectiveMin) || 0));
|
|
103
|
+
let nextQuantity = value;
|
|
104
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.action) === "increase" && option.quantity <= 0) nextQuantity = initialQuantity;
|
|
105
|
+
else if ((meta === null || meta === void 0 ? void 0 : meta.action) === "decrease" && initialQuantity > 1 && option.quantity === initialQuantity && value < initialQuantity) nextQuantity = 0;
|
|
106
|
+
actions.update(option._key, { quantity: nextQuantity });
|
|
103
107
|
}
|
|
104
108
|
}));
|
|
105
109
|
};
|
|
106
110
|
const renderOption = (option) => {
|
|
107
|
-
var _option$ruleConfig$mi, _option$ruleConfig, _ruleConfig$min, _option$
|
|
111
|
+
var _option$ruleConfig$mi, _option$ruleConfig, _ruleConfig$min, _option$ruleConfig2;
|
|
108
112
|
const optionItemValue = Array.isArray(state.values) ? state.values.find((item) => (item === null || item === void 0 ? void 0 : item.value) === option._key) : [state.values].find((item) => (item === null || item === void 0 ? void 0 : item.value) === option._key);
|
|
109
113
|
if (react.default.isValidElement(renderItem)) return renderItem;
|
|
110
114
|
const configMin = (_option$ruleConfig$mi = option === null || option === void 0 || (_option$ruleConfig = option.ruleConfig) === null || _option$ruleConfig === void 0 ? void 0 : _option$ruleConfig.min) !== null && _option$ruleConfig$mi !== void 0 ? _option$ruleConfig$mi : 0;
|
|
111
115
|
const groupMin = (_ruleConfig$min = ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.min) !== null && _ruleConfig$min !== void 0 ? _ruleConfig$min : 0;
|
|
112
116
|
const effectiveMin = options.length < 2 && groupMin > 0 ? groupMin : configMin;
|
|
113
|
-
const
|
|
117
|
+
const configuredMax = option === null || option === void 0 || (_option$ruleConfig2 = option.ruleConfig) === null || _option$ruleConfig2 === void 0 ? void 0 : _option$ruleConfig2.max;
|
|
118
|
+
const configMax = typeof configuredMax === "number" && configuredMax > 0 ? configuredMax : Number.MAX_SAFE_INTEGER;
|
|
114
119
|
const effectiveMax = remainingCount !== void 0 ? Math.min(remainingCount + (option.quantity || 0), configMax) : configMax;
|
|
115
120
|
option.effectiveMin = effectiveMin;
|
|
116
121
|
option.effectiveMax = effectiveMax;
|
|
@@ -162,7 +167,7 @@ const Selector = (0, react.forwardRef)((props, ref) => {
|
|
|
162
167
|
const { required = false } = ruleConfig || {};
|
|
163
168
|
if (!required) return null;
|
|
164
169
|
const style = { borderRadius: 16 };
|
|
165
|
-
if (errors.find((item) => item.type === "required" || item.type === "min")) return /* @__PURE__ */ react.default.createElement(ATag, {
|
|
170
|
+
if (errors.find((item) => item.type === "required" || item.type === "min" || item.type === "minTypes")) return /* @__PURE__ */ react.default.createElement(ATag, {
|
|
166
171
|
className: "pisell-pro-selector_required-tag",
|
|
167
172
|
icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.ExclamationCircleOutlined, null),
|
|
168
173
|
color: "error",
|
|
@@ -5,6 +5,24 @@ let react = require("react");
|
|
|
5
5
|
let _pisell_utils = require("@pisell/utils");
|
|
6
6
|
let ahooks = require("ahooks");
|
|
7
7
|
//#region src/pro/Selector/hooks/useSelectionController.ts
|
|
8
|
+
const normalizeSelectionQuantity = (quantity) => {
|
|
9
|
+
if (quantity === null || quantity === void 0) return 1;
|
|
10
|
+
const normalizedQuantity = Number(quantity);
|
|
11
|
+
return Number.isFinite(normalizedQuantity) ? normalizedQuantity : 1;
|
|
12
|
+
};
|
|
13
|
+
const normalizeSelectionValues = (values) => {
|
|
14
|
+
if (values === null || values === void 0) return [];
|
|
15
|
+
return (Array.isArray(values) ? values : [values]).map((item) => {
|
|
16
|
+
if (typeof item === "object" && item !== null) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
|
|
17
|
+
value: item.value,
|
|
18
|
+
quantity: normalizeSelectionQuantity(item.quantity)
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
value: item,
|
|
22
|
+
quantity: 1
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
};
|
|
8
26
|
function useSelectionController(props) {
|
|
9
27
|
const { dataSource = [], ruleConfig, fieldNames, mode = "single", valueType = "primitive" } = props || {};
|
|
10
28
|
const [values, setValues] = (0, ahooks.useControllableValue)(props);
|
|
@@ -39,48 +57,34 @@ function useSelectionController(props) {
|
|
|
39
57
|
return map;
|
|
40
58
|
}, [mutexGroups]);
|
|
41
59
|
const normalizedValues = (0, react.useMemo)(() => {
|
|
42
|
-
|
|
43
|
-
if (Array.isArray(values)) return values.map((item) => {
|
|
44
|
-
if (typeof item === "object" && item !== null) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
|
|
45
|
-
value: item.value,
|
|
46
|
-
quantity: item.quantity || 1
|
|
47
|
-
});
|
|
48
|
-
return {
|
|
49
|
-
value: item,
|
|
50
|
-
quantity: 1
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
if (typeof values === "object" && values !== null) {
|
|
54
|
-
const objValue = values;
|
|
55
|
-
return [require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, objValue), {}, {
|
|
56
|
-
value: objValue.value,
|
|
57
|
-
quantity: objValue.quantity || 1
|
|
58
|
-
})];
|
|
59
|
-
}
|
|
60
|
-
return [{
|
|
61
|
-
value: values,
|
|
62
|
-
quantity: 1
|
|
63
|
-
}];
|
|
60
|
+
return normalizeSelectionValues(values);
|
|
64
61
|
}, [values]);
|
|
65
62
|
const quantityInfo = (0, react.useMemo)(() => {
|
|
66
|
-
const
|
|
63
|
+
const positiveValues = normalizedValues.filter((item) => Number(item.quantity) > 0);
|
|
64
|
+
const selectedCount = positiveValues.reduce((sum, item) => sum + Number(item.quantity), 0);
|
|
65
|
+
const selectedTypeCount = new Set(positiveValues.map((item) => item.value)).size;
|
|
67
66
|
const showQuantity = (Array.isArray(dataSource) ? dataSource : dataSource || []).some((opt) => {
|
|
68
67
|
var _opt$ruleConfig, _opt$ruleConfig2;
|
|
69
|
-
return typeof (opt === null || opt === void 0 || (_opt$ruleConfig = opt.ruleConfig) === null || _opt$ruleConfig === void 0 ? void 0 : _opt$ruleConfig.max) === "number" && opt.ruleConfig.max > 1 || typeof (opt === null || opt === void 0 || (_opt$ruleConfig2 = opt.ruleConfig) === null || _opt$ruleConfig2 === void 0 ? void 0 : _opt$ruleConfig2.min) === "number" && opt.ruleConfig.min > 1;
|
|
68
|
+
return typeof (opt === null || opt === void 0 || (_opt$ruleConfig = opt.ruleConfig) === null || _opt$ruleConfig === void 0 ? void 0 : _opt$ruleConfig.max) === "number" && (opt.ruleConfig.max === 0 || opt.ruleConfig.max > 1) || typeof (opt === null || opt === void 0 || (_opt$ruleConfig2 = opt.ruleConfig) === null || _opt$ruleConfig2 === void 0 ? void 0 : _opt$ruleConfig2.min) === "number" && opt.ruleConfig.min > 1;
|
|
70
69
|
});
|
|
71
70
|
return {
|
|
72
71
|
maxReached: typeof (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max) === "number" && ruleConfig.max > 0 && selectedCount >= ruleConfig.max,
|
|
73
72
|
showQuantity,
|
|
74
73
|
remainingCount: typeof (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max) === "number" && ruleConfig.max > 0 ? Math.max(0, ruleConfig.max - selectedCount) : Infinity,
|
|
75
|
-
selectedCount
|
|
74
|
+
selectedCount,
|
|
75
|
+
selectedTypeCount,
|
|
76
|
+
typeMaxReached: mode === "multiple" && typeof (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.maxTypes) === "number" && ruleConfig.maxTypes > 0 && selectedTypeCount >= ruleConfig.maxTypes,
|
|
77
|
+
remainingTypeCount: typeof (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.maxTypes) === "number" && ruleConfig.maxTypes > 0 ? Math.max(0, ruleConfig.maxTypes - selectedTypeCount) : Infinity
|
|
76
78
|
};
|
|
77
79
|
}, [
|
|
78
80
|
normalizedValues,
|
|
79
81
|
dataSource,
|
|
80
|
-
|
|
82
|
+
mode,
|
|
83
|
+
ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max,
|
|
84
|
+
ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.maxTypes
|
|
81
85
|
]);
|
|
82
86
|
const getOptionState = (0, react.useCallback)((optionKey) => {
|
|
83
|
-
const found = normalizedValues.find((item) => item.value === optionKey);
|
|
87
|
+
const found = normalizedValues.find((item) => item.value === optionKey && Number(item.quantity) > 0);
|
|
84
88
|
return {
|
|
85
89
|
selected: !!found,
|
|
86
90
|
quantity: (found === null || found === void 0 ? void 0 : found.quantity) || 0
|
|
@@ -89,59 +93,51 @@ function useSelectionController(props) {
|
|
|
89
93
|
const options = (0, react.useMemo)(() => {
|
|
90
94
|
return normalizedOptions.map((option) => {
|
|
91
95
|
const state = getOptionState(option._key);
|
|
92
|
-
const
|
|
96
|
+
const disabledByTotalLimit = quantityInfo.maxReached && !(mode === "single" && (ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max) === 1) && !state.selected;
|
|
97
|
+
const disabledByTypeLimit = mode === "multiple" && quantityInfo.typeMaxReached && !state.selected;
|
|
93
98
|
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, option), {}, {
|
|
94
99
|
selected: state.selected,
|
|
95
100
|
quantity: state.quantity,
|
|
96
|
-
disabled: option.disabled ||
|
|
101
|
+
disabled: option.disabled || disabledByTotalLimit || disabledByTypeLimit
|
|
97
102
|
});
|
|
98
103
|
});
|
|
99
104
|
}, [
|
|
100
105
|
normalizedOptions,
|
|
101
106
|
getOptionState,
|
|
102
107
|
quantityInfo.maxReached,
|
|
108
|
+
quantityInfo.typeMaxReached,
|
|
103
109
|
mode,
|
|
104
110
|
ruleConfig === null || ruleConfig === void 0 ? void 0 : ruleConfig.max
|
|
105
111
|
]);
|
|
106
112
|
const validate = function() {
|
|
107
113
|
var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
|
|
108
114
|
const errors = [];
|
|
109
|
-
const { required, min, max, customValidator } = ruleConfig || {};
|
|
115
|
+
const { required, min, max, minTypes, maxTypes, customValidator } = ruleConfig || {};
|
|
110
116
|
const values = valuesRef.current;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
quantity: item.quantity || 1
|
|
116
|
-
});
|
|
117
|
-
return {
|
|
118
|
-
value: item,
|
|
119
|
-
quantity: 1
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
else if (typeof values === "object" && values !== null) {
|
|
123
|
-
const objValue = values;
|
|
124
|
-
currentNormalizedValues = [require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, objValue), {}, {
|
|
125
|
-
value: objValue.value,
|
|
126
|
-
quantity: objValue.quantity || 1
|
|
127
|
-
})];
|
|
128
|
-
} else currentNormalizedValues = [{
|
|
129
|
-
value: values,
|
|
130
|
-
quantity: 1
|
|
131
|
-
}];
|
|
132
|
-
const totalQuantity = currentNormalizedValues.reduce((sum, item) => sum + (item.quantity || 0), 0);
|
|
117
|
+
const currentNormalizedValues = normalizeSelectionValues(values);
|
|
118
|
+
const positiveValues = currentNormalizedValues.filter((item) => Number(item.quantity) > 0);
|
|
119
|
+
const totalQuantity = positiveValues.reduce((sum, item) => sum + Number(item.quantity), 0);
|
|
120
|
+
const selectedTypeCount = new Set(positiveValues.map((item) => item.value)).size;
|
|
133
121
|
if (required && totalQuantity < 1) errors.push({
|
|
134
122
|
type: "required",
|
|
135
123
|
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.required-msg")
|
|
136
124
|
});
|
|
137
|
-
if (typeof min === "number" && totalQuantity < min) errors.push({
|
|
125
|
+
if (typeof min === "number" && min > 0 && totalQuantity < min) errors.push({
|
|
138
126
|
type: "min",
|
|
139
127
|
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.min-selection")(min)
|
|
140
128
|
});
|
|
141
|
-
if (typeof max === "number" && totalQuantity > max) errors.push({
|
|
129
|
+
if (typeof max === "number" && max > 0 && totalQuantity > max) errors.push({
|
|
142
130
|
type: "max",
|
|
143
131
|
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.max-selection")(max)
|
|
144
132
|
});
|
|
133
|
+
if (typeof minTypes === "number" && minTypes > 0 && selectedTypeCount < minTypes) errors.push({
|
|
134
|
+
type: "minTypes",
|
|
135
|
+
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.min-types")(minTypes)
|
|
136
|
+
});
|
|
137
|
+
if (typeof maxTypes === "number" && maxTypes > 0 && selectedTypeCount > maxTypes) errors.push({
|
|
138
|
+
type: "maxTypes",
|
|
139
|
+
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.max-types")(maxTypes)
|
|
140
|
+
});
|
|
145
141
|
options.forEach((option) => {
|
|
146
142
|
var _option$ruleConfig, _option$ruleConfig2;
|
|
147
143
|
const _optionVal = currentNormalizedValues.find((item) => item.value === option._key);
|
|
@@ -149,19 +145,19 @@ function useSelectionController(props) {
|
|
|
149
145
|
const { _label } = option;
|
|
150
146
|
const _min = option === null || option === void 0 || (_option$ruleConfig = option.ruleConfig) === null || _option$ruleConfig === void 0 ? void 0 : _option$ruleConfig.min;
|
|
151
147
|
const _max = option === null || option === void 0 || (_option$ruleConfig2 = option.ruleConfig) === null || _option$ruleConfig2 === void 0 ? void 0 : _option$ruleConfig2.max;
|
|
152
|
-
if (typeof _min === "number" && quantity < _min) errors.push({
|
|
148
|
+
if (quantity > 0 && typeof _min === "number" && _min > 0 && quantity < _min) errors.push({
|
|
153
149
|
type: "optionMin",
|
|
154
150
|
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.min-selection")(_min, _label),
|
|
155
151
|
_key: option._key
|
|
156
152
|
});
|
|
157
|
-
if (typeof _max === "number" && quantity > _max) errors.push({
|
|
153
|
+
if (typeof _max === "number" && _max > 0 && quantity > _max) errors.push({
|
|
158
154
|
type: "optionMax",
|
|
159
155
|
message: _pisell_utils.locales.getText("pisell2.pro.selector.validate.max-selection")(_max, _label),
|
|
160
156
|
_key: option._key
|
|
161
157
|
});
|
|
162
158
|
});
|
|
163
159
|
if (mutexGroups.length > 0) {
|
|
164
|
-
const selectedKeys =
|
|
160
|
+
const selectedKeys = positiveValues.map((item) => item.value);
|
|
165
161
|
mutexGroups.forEach((group) => {
|
|
166
162
|
if (selectedKeys.filter((k) => group.includes(k)).length > 1) errors.push({
|
|
167
163
|
type: "mutex",
|
|
@@ -211,10 +207,7 @@ function useSelectionController(props) {
|
|
|
211
207
|
} else {
|
|
212
208
|
if (existingIndex >= 0) newNormalizedValues[existingIndex] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, newNormalizedValues[existingIndex]), data);
|
|
213
209
|
else {
|
|
214
|
-
const newItem = require_objectSpread2._objectSpread2({
|
|
215
|
-
value: optionKey,
|
|
216
|
-
quantity: data.quantity || 1
|
|
217
|
-
}, data);
|
|
210
|
+
const newItem = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ value: optionKey }, data), {}, { quantity: normalizeSelectionQuantity(data === null || data === void 0 ? void 0 : data.quantity) });
|
|
218
211
|
if (mode === "single") newNormalizedValues = [newItem];
|
|
219
212
|
else newNormalizedValues.push(newItem);
|
|
220
213
|
}
|
|
@@ -8,6 +8,8 @@ var locales_default = {
|
|
|
8
8
|
"pisell2.pro.selector.required-tag": "Required",
|
|
9
9
|
"pisell2.pro.selector.validate.min-selection": (min, label) => `Select at least ${min}${label ? " " + label : ""}`,
|
|
10
10
|
"pisell2.pro.selector.validate.max-selection": (max, label) => `Select at most ${max}${label ? " " + label : ""}`,
|
|
11
|
+
"pisell2.pro.selector.validate.min-types": (min) => `Select at least ${min} option types`,
|
|
12
|
+
"pisell2.pro.selector.validate.max-types": (max) => `Select at most ${max} option types`,
|
|
11
13
|
"pisell2.pro.selector.tip.require-one-option": "Choose 1",
|
|
12
14
|
"pisell2.pro.selector.tip.min-max-selection": (min, max) => {
|
|
13
15
|
if (min === max && min > 0) return `Choose ${min}`;
|
|
@@ -25,6 +27,8 @@ var locales_default = {
|
|
|
25
27
|
"pisell2.pro.selector.required-tag": "必选",
|
|
26
28
|
"pisell2.pro.selector.validate.min-selection": (min, label) => `至少选 ${min} 个${label ? " " + label : ""}`,
|
|
27
29
|
"pisell2.pro.selector.validate.max-selection": (max, label) => `最多选 ${max} 个${label ? " " + label : ""}`,
|
|
30
|
+
"pisell2.pro.selector.validate.min-types": (min) => `至少选择 ${min} 种选项`,
|
|
31
|
+
"pisell2.pro.selector.validate.max-types": (max) => `最多选择 ${max} 种选项`,
|
|
28
32
|
"pisell2.pro.selector.tip.require-one-option": "需选 1 项",
|
|
29
33
|
"pisell2.pro.selector.tip.min-max-selection": (min, max) => {
|
|
30
34
|
if (min === max && min > 0) return `需选 ${min} 个`;
|
|
@@ -42,6 +46,8 @@ var locales_default = {
|
|
|
42
46
|
"pisell2.pro.selector.required-tag": "必選",
|
|
43
47
|
"pisell2.pro.selector.validate.min-selection": (min, label) => `至少選 ${min} 個${label ? " " + label : ""}`,
|
|
44
48
|
"pisell2.pro.selector.validate.max-selection": (max, label) => `最多選 ${max} 個${label ? " " + label : ""}`,
|
|
49
|
+
"pisell2.pro.selector.validate.min-types": (min) => `至少選擇 ${min} 種選項`,
|
|
50
|
+
"pisell2.pro.selector.validate.max-types": (max) => `最多選擇 ${max} 種選項`,
|
|
45
51
|
"pisell2.pro.selector.tip.require-one-option": "需選 1 項",
|
|
46
52
|
"pisell2.pro.selector.tip.min-max-selection": (min, max) => {
|
|
47
53
|
if (min === max && min > 0) return `需選 ${min} 個`;
|
|
@@ -59,6 +65,8 @@ var locales_default = {
|
|
|
59
65
|
"pisell2.pro.selector.required-tag": "必須",
|
|
60
66
|
"pisell2.pro.selector.validate.min-selection": (min, label) => `少なくとも${min}${label ? " " + label : ""}を選択`,
|
|
61
67
|
"pisell2.pro.selector.validate.max-selection": (max, label) => `最大${max}${label ? " " + label : ""}を選択`,
|
|
68
|
+
"pisell2.pro.selector.validate.min-types": (min) => `少なくとも${min}種類のオプションを選択してください`,
|
|
69
|
+
"pisell2.pro.selector.validate.max-types": (max) => `選択できるオプションは最大${max}種類です`,
|
|
62
70
|
"pisell2.pro.selector.tip.require-one-option": "1つ選択",
|
|
63
71
|
"pisell2.pro.selector.tip.min-max-selection": (min, max) => {
|
|
64
72
|
if (min === max && min > 0) return `${min}つ選択`;
|
|
@@ -76,6 +84,8 @@ var locales_default = {
|
|
|
76
84
|
"pisell2.pro.selector.required-tag": "Obrigatório",
|
|
77
85
|
"pisell2.pro.selector.validate.min-selection": (min, label) => `Selecione pelo menos ${min}${label ? " " + label : ""}`,
|
|
78
86
|
"pisell2.pro.selector.validate.max-selection": (max, label) => `Selecione no máximo ${max}${label ? " " + label : ""}`,
|
|
87
|
+
"pisell2.pro.selector.validate.min-types": (min) => `Selecione pelo menos ${min} tipos de opção`,
|
|
88
|
+
"pisell2.pro.selector.validate.max-types": (max) => `Selecione no máximo ${max} tipos de opção`,
|
|
79
89
|
"pisell2.pro.selector.tip.require-one-option": "Escolha 1",
|
|
80
90
|
"pisell2.pro.selector.tip.min-max-selection": (min, max) => {
|
|
81
91
|
if (min === max && min > 0) return `Escolha ${min}`;
|
|
@@ -8,6 +8,8 @@ interface RuleConfig {
|
|
|
8
8
|
required?: 0 | 1;
|
|
9
9
|
min?: number;
|
|
10
10
|
max?: number;
|
|
11
|
+
minTypes?: number;
|
|
12
|
+
maxTypes?: number;
|
|
11
13
|
mutex?: Array<Array<OptionKey>>;
|
|
12
14
|
customValidator?: (value: SelectionValue) => Promise<void>;
|
|
13
15
|
}
|
|
@@ -63,6 +65,9 @@ type RenderItemProps = {
|
|
|
63
65
|
maxReached: boolean;
|
|
64
66
|
remainingCount: number;
|
|
65
67
|
selectedCount: number;
|
|
68
|
+
selectedTypeCount: number;
|
|
69
|
+
typeMaxReached: boolean;
|
|
70
|
+
remainingTypeCount: number;
|
|
66
71
|
};
|
|
67
72
|
};
|
|
68
73
|
type ItemProps = {
|