@orderingstack/front-components-product-configurator 1.6.0-beta.4 → 1.7.0-beta.0
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/dist/components/MenuProduct/MenuProduct.d.ts.map +1 -1
- package/dist/components/MenuProduct/useMenuProduct.d.ts.map +1 -1
- package/dist/components/SimpleCheckbox/SimpleCheckbox.d.ts +1 -0
- package/dist/components/SimpleCheckbox/SimpleCheckbox.d.ts.map +1 -1
- package/dist/index.cjs.js +6 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +112 -19
- package/dist/index.es.js.map +1 -1
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -6295,6 +6295,53 @@ function findGroupInProductItemsBySelCtx(selCtx, parent) {
|
|
|
6295
6295
|
return null;
|
|
6296
6296
|
}
|
|
6297
6297
|
const isAnyGroupOptionKind = (kind) => kind === EProductKind.OPTIONS || kind === EProductKind.CONFIG || kind === EProductKind.GROUP_UPSELL;
|
|
6298
|
+
const isGroupBucketCase = (group) => {
|
|
6299
|
+
var _a, _b, _c, _d, _e2, _f, _g;
|
|
6300
|
+
if (!group) {
|
|
6301
|
+
return false;
|
|
6302
|
+
}
|
|
6303
|
+
if (isAnyGroupOptionKind(group == null ? void 0 : group.kind) && ((_a = group == null ? void 0 : group.attrs) == null ? void 0 : _a.selMin) === "1" && ((_b = group == null ? void 0 : group.attrs) == null ? void 0 : _b.selMax) === "2" && ((_c = group == null ? void 0 : group.attrs) == null ? void 0 : _c.qtyMin) && ((_d = group == null ? void 0 : group.attrs) == null ? void 0 : _d.qtyMin) === ((_e2 = group == null ? void 0 : group.attrs) == null ? void 0 : _e2.qtyMax) && ((_g = (_f = group == null ? void 0 : group.items) == null ? void 0 : _f.filter((x2) => {
|
|
6304
|
+
var _a2;
|
|
6305
|
+
return ((_a2 = x2 == null ? void 0 : x2._) == null ? void 0 : _a2.hidden) !== "true";
|
|
6306
|
+
})) == null ? void 0 : _g.length) === 2) {
|
|
6307
|
+
return true;
|
|
6308
|
+
}
|
|
6309
|
+
return false;
|
|
6310
|
+
};
|
|
6311
|
+
const getGroupBucketSecondChildrenValues = (group, fistProductId, fistProductValue) => {
|
|
6312
|
+
var _a, _b;
|
|
6313
|
+
const otherValue = ((_a = group == null ? void 0 : group.attrs) == null ? void 0 : _a.qtyMax) - fistProductValue;
|
|
6314
|
+
const otherProduct = (_b = group == null ? void 0 : group.items) == null ? void 0 : _b.find((x2) => (x2 == null ? void 0 : x2.id) !== fistProductId);
|
|
6315
|
+
return {
|
|
6316
|
+
product: otherProduct,
|
|
6317
|
+
value: otherValue
|
|
6318
|
+
};
|
|
6319
|
+
};
|
|
6320
|
+
const getGroupBucketSecondChildrenValuesInputChange = (group, clickedProductId, checked, selected) => {
|
|
6321
|
+
var _a, _b, _c, _d;
|
|
6322
|
+
const secondProduct = (_a = group == null ? void 0 : group.items) == null ? void 0 : _a.find((x2) => (x2 == null ? void 0 : x2.id) !== clickedProductId);
|
|
6323
|
+
const qtyMax = (_b = group == null ? void 0 : group.attrs) == null ? void 0 : _b.qtyMax;
|
|
6324
|
+
if (!checked) {
|
|
6325
|
+
return {
|
|
6326
|
+
clickedProductValue: false,
|
|
6327
|
+
secondProductValue: qtyMax,
|
|
6328
|
+
secondProduct
|
|
6329
|
+
};
|
|
6330
|
+
}
|
|
6331
|
+
const isSecondProductInState = !!((_c = selected == null ? void 0 : selected[secondProduct == null ? void 0 : secondProduct.selCtx]) == null ? void 0 : _c[secondProduct == null ? void 0 : secondProduct.id]) && ((_d = selected == null ? void 0 : selected[secondProduct == null ? void 0 : secondProduct.selCtx]) == null ? void 0 : _d[secondProduct == null ? void 0 : secondProduct.id]) !== false;
|
|
6332
|
+
if (isSecondProductInState) {
|
|
6333
|
+
return {
|
|
6334
|
+
clickedProductValue: "1",
|
|
6335
|
+
secondProductValue: `${Number(qtyMax) - 1}`,
|
|
6336
|
+
secondProduct
|
|
6337
|
+
};
|
|
6338
|
+
}
|
|
6339
|
+
return {
|
|
6340
|
+
clickedProductValue: qtyMax,
|
|
6341
|
+
secondProductValue: false,
|
|
6342
|
+
secondProduct
|
|
6343
|
+
};
|
|
6344
|
+
};
|
|
6298
6345
|
function createStore(createState) {
|
|
6299
6346
|
let state;
|
|
6300
6347
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -8519,13 +8566,15 @@ const MenuOptions = (props) => {
|
|
|
8519
8566
|
});
|
|
8520
8567
|
};
|
|
8521
8568
|
const SimpleCheckbox = (props) => {
|
|
8569
|
+
var _a;
|
|
8522
8570
|
const {
|
|
8523
8571
|
product,
|
|
8524
8572
|
inputId,
|
|
8525
8573
|
isDisabled,
|
|
8526
8574
|
registerProps,
|
|
8527
8575
|
size = "lg",
|
|
8528
|
-
children
|
|
8576
|
+
children,
|
|
8577
|
+
parentProduct
|
|
8529
8578
|
} = props;
|
|
8530
8579
|
const {
|
|
8531
8580
|
details: {
|
|
@@ -8538,6 +8587,25 @@ const SimpleCheckbox = (props) => {
|
|
|
8538
8587
|
} = literals || {};
|
|
8539
8588
|
const price = countComplexProductPrice(product);
|
|
8540
8589
|
const imgSrc = getItemImage(product);
|
|
8590
|
+
const {
|
|
8591
|
+
watch
|
|
8592
|
+
} = useFormContext();
|
|
8593
|
+
const selected = watch(`selected`);
|
|
8594
|
+
isGroupBucketCase(parentProduct);
|
|
8595
|
+
const wasGroupEmpty = useRef(!((_a = parentProduct == null ? void 0 : parentProduct.items) == null ? void 0 : _a.some((x2) => {
|
|
8596
|
+
var _a2;
|
|
8597
|
+
return (_a2 = selected == null ? void 0 : selected[x2 == null ? void 0 : x2.selCtx]) == null ? void 0 : _a2[x2.id];
|
|
8598
|
+
})));
|
|
8599
|
+
useEffect(() => {
|
|
8600
|
+
setTimeout(() => {
|
|
8601
|
+
var _a2;
|
|
8602
|
+
const isEmpty2 = !((_a2 = parentProduct == null ? void 0 : parentProduct.items) == null ? void 0 : _a2.some((x2) => {
|
|
8603
|
+
var _a3;
|
|
8604
|
+
return (_a3 = selected == null ? void 0 : selected[x2 == null ? void 0 : x2.selCtx]) == null ? void 0 : _a3[x2.id];
|
|
8605
|
+
}));
|
|
8606
|
+
wasGroupEmpty.current = isEmpty2;
|
|
8607
|
+
}, 10);
|
|
8608
|
+
}, [parentProduct == null ? void 0 : parentProduct.items, selected]);
|
|
8541
8609
|
return /* @__PURE__ */ jsxs("div", {
|
|
8542
8610
|
className: `flex items-center justify-center p-2 pl-3 my-1 rounded-lg bg-white border-2 border-gray-200 ${isDisabled && "opacity-50"}`,
|
|
8543
8611
|
children: [/* @__PURE__ */ jsx("input", {
|
|
@@ -8545,8 +8613,8 @@ const SimpleCheckbox = (props) => {
|
|
|
8545
8613
|
className: `simple-checkbox checkbox-${size} mr-4`,
|
|
8546
8614
|
id: inputId,
|
|
8547
8615
|
disabled: isDisabled,
|
|
8548
|
-
|
|
8549
|
-
|
|
8616
|
+
...registerProps,
|
|
8617
|
+
value: "1"
|
|
8550
8618
|
}), imgSrc && /* @__PURE__ */ jsx("div", {
|
|
8551
8619
|
className: "flex w-20 mr-2 max-h-24",
|
|
8552
8620
|
children: /* @__PURE__ */ jsx("img", {
|
|
@@ -8914,7 +8982,7 @@ const findProductInParentProductBySelCtx = (parent, selCtx) => {
|
|
|
8914
8982
|
return null;
|
|
8915
8983
|
};
|
|
8916
8984
|
function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
8917
|
-
var _a;
|
|
8985
|
+
var _a, _b;
|
|
8918
8986
|
const { id, selCtx, emit = {}, fltCtx } = product;
|
|
8919
8987
|
const {
|
|
8920
8988
|
allowMultiple: parentAllowMultiple,
|
|
@@ -8931,11 +8999,12 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
8931
8999
|
const isRadio = parentSelMin === "1" && parentSelMax === "1";
|
|
8932
9000
|
useEmitFilter(product, isRadio, nestedLvl);
|
|
8933
9001
|
const isCheckbox = !isRadio;
|
|
9002
|
+
const isBucketCase = isGroupBucketCase(parentPriduct);
|
|
8934
9003
|
const isCounter = isApiBooleanTrue(parentAllowMultiple);
|
|
8935
|
-
const isDecrementEnabled = valueNumber > (isRadio ? 1 : 0);
|
|
8936
|
-
const isIncrementEnabled = isInputCounterIncrementEnabled2(product, selected) && (isInputEnabled2(product) || valueNumber);
|
|
8937
|
-
const isChecked = Number(((
|
|
8938
|
-
const isCheckboxEnabled = isInputEnabled2(product) || valueNumber;
|
|
9004
|
+
const isDecrementEnabled = isBucketCase && valueNumber > 0 || valueNumber > (isRadio ? 1 : 0);
|
|
9005
|
+
const isIncrementEnabled = isBucketCase && valueNumber < ((_a = parentPriduct == null ? void 0 : parentPriduct.attrs) == null ? void 0 : _a.qtyMax) || isInputCounterIncrementEnabled2(product, selected) && (isInputEnabled2(product) || valueNumber);
|
|
9006
|
+
const isChecked = Number(((_b = selected == null ? void 0 : selected[selCtx]) == null ? void 0 : _b[id]) || 0) > 0;
|
|
9007
|
+
const isCheckboxEnabled = isBucketCase || isInputEnabled2(product) || valueNumber;
|
|
8939
9008
|
const registerId = `${isRadio ? "radio" : "selected"}.${selCtx}.${id}`;
|
|
8940
9009
|
const registerProps = register(registerId, {
|
|
8941
9010
|
onChange: (e2) => {
|
|
@@ -8943,12 +9012,20 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
8943
9012
|
}
|
|
8944
9013
|
});
|
|
8945
9014
|
const handleCounterIncrementQty = () => {
|
|
8946
|
-
var _a2,
|
|
9015
|
+
var _a2, _b2;
|
|
8947
9016
|
setValue(`selected.${selCtx}.${id}`, `${valueNumber + 1}`);
|
|
8948
|
-
const
|
|
9017
|
+
const isBucketCase2 = isGroupBucketCase(parentPriduct);
|
|
9018
|
+
if (isBucketCase2) {
|
|
9019
|
+
const { product: secondProduct, value: secondProductValue } = getGroupBucketSecondChildrenValues(parentPriduct, id, valueNumber + 1);
|
|
9020
|
+
setValue(`selected.${secondProduct == null ? void 0 : secondProduct.selCtx}.${secondProduct == null ? void 0 : secondProduct.id}`, `${secondProductValue}`);
|
|
9021
|
+
if (secondProductValue === 0) {
|
|
9022
|
+
selectUnselectProduct(setValue, getValues, secondProduct, false, unregister, nestedLvl);
|
|
9023
|
+
}
|
|
9024
|
+
}
|
|
9025
|
+
const importantSubProductsInState = (_b2 = (_a2 = Object.keys(selected)) == null ? void 0 : _a2.map((y2) => {
|
|
8949
9026
|
var _a3;
|
|
8950
9027
|
return { key: y2, subProductId: (_a3 = findProductInParentProductBySelCtx(product, y2)) == null ? void 0 : _a3.id };
|
|
8951
|
-
})) == null ? void 0 :
|
|
9028
|
+
})) == null ? void 0 : _b2.filter((x2) => !!x2.subProductId);
|
|
8952
9029
|
if (valueNumber === 0) {
|
|
8953
9030
|
importantSubProductsInState == null ? void 0 : importantSubProductsInState.forEach((x2) => {
|
|
8954
9031
|
setValue(`selected.${x2.key}.${x2.subProductId}`, `${valueNumber + 1}`);
|
|
@@ -8956,13 +9033,20 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
8956
9033
|
}
|
|
8957
9034
|
};
|
|
8958
9035
|
const handleCounterDecrementQty = () => {
|
|
8959
|
-
var _a2,
|
|
9036
|
+
var _a2, _b2, _c, _d;
|
|
8960
9037
|
const decrementedValue = valueNumber - 1;
|
|
8961
9038
|
setValue(`selected.${selCtx}.${id}`, `${decrementedValue}`);
|
|
8962
|
-
|
|
9039
|
+
if (isBucketCase) {
|
|
9040
|
+
const { product: secondProduct, value: secondProductValue } = getGroupBucketSecondChildrenValues(parentPriduct, id, decrementedValue);
|
|
9041
|
+
setValue(`selected.${secondProduct == null ? void 0 : secondProduct.selCtx}.${secondProduct == null ? void 0 : secondProduct.id}`, `${secondProductValue}`);
|
|
9042
|
+
if (secondProductValue === 1) {
|
|
9043
|
+
selectUnselectProduct(setValue, getValues, secondProduct, true, unregister, nestedLvl);
|
|
9044
|
+
}
|
|
9045
|
+
}
|
|
9046
|
+
const importantSubProductsInState = (_b2 = (_a2 = Object.keys(selected)) == null ? void 0 : _a2.map((y2) => {
|
|
8963
9047
|
var _a3;
|
|
8964
9048
|
return { key: y2, subProductId: (_a3 = findProductInParentProductBySelCtx(product, y2)) == null ? void 0 : _a3.id };
|
|
8965
|
-
})) == null ? void 0 :
|
|
9049
|
+
})) == null ? void 0 : _b2.filter((x2) => !!x2.subProductId);
|
|
8966
9050
|
if (decrementedValue === 0) {
|
|
8967
9051
|
importantSubProductsInState == null ? void 0 : importantSubProductsInState.forEach((x2) => {
|
|
8968
9052
|
setValue(`selected.${x2.key}.${x2.subProductId}`, `${decrementedValue}`);
|
|
@@ -8997,7 +9081,7 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
8997
9081
|
const groupCntPath = `filterWithCnt.${fltCtx}.${selCtx}`;
|
|
8998
9082
|
const fltCtxPath = `filter.${fltCtx}`;
|
|
8999
9083
|
(_d = Object.keys(emit)) == null ? void 0 : _d.forEach((emitKey) => {
|
|
9000
|
-
var _a3,
|
|
9084
|
+
var _a3, _b3, _c2;
|
|
9001
9085
|
const groupValue = getValues(`${groupCntPath}.${emitKey}`) || 0;
|
|
9002
9086
|
if (groupValue) {
|
|
9003
9087
|
if (groupValue > 1) {
|
|
@@ -9016,7 +9100,7 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
9016
9100
|
if (!sameKeyOtherGroup) {
|
|
9017
9101
|
unregister(`${fltCtxPath}.${emitKey}`);
|
|
9018
9102
|
} else {
|
|
9019
|
-
const newValue = (_c2 = (
|
|
9103
|
+
const newValue = (_c2 = (_b3 = groupKeysObj == null ? void 0 : groupKeysObj[`${sameKeyOtherGroup}`]) == null ? void 0 : _b3[`${emitKey}`]) == null ? void 0 : _c2.value;
|
|
9020
9104
|
setValue(`${fltCtxPath}.${emitKey}`, newValue);
|
|
9021
9105
|
}
|
|
9022
9106
|
}
|
|
@@ -9031,9 +9115,17 @@ function useMenuProduct(product, parentAttrs, nestedLvl, parentPriduct) {
|
|
|
9031
9115
|
const {
|
|
9032
9116
|
target: { checked, name: selCtx2, defaultValue: productId }
|
|
9033
9117
|
} = e2;
|
|
9118
|
+
if (isBucketCase) {
|
|
9119
|
+
const { clickedProductValue, secondProductValue, secondProduct } = getGroupBucketSecondChildrenValuesInputChange(parentPriduct, id, checked, selected);
|
|
9120
|
+
console.log("handleOnInputChange clickedProductValue", clickedProductValue, secondProductValue);
|
|
9121
|
+
setValue(`selected.${product == null ? void 0 : product.selCtx}.${product == null ? void 0 : product.id}`, clickedProductValue === false ? false : clickedProductValue);
|
|
9122
|
+
setValue(`selected.${secondProduct == null ? void 0 : secondProduct.selCtx}.${secondProduct == null ? void 0 : secondProduct.id}`, secondProductValue === false ? false : secondProductValue);
|
|
9123
|
+
selectUnselectProduct(setValue, getValues, product, checked, unregister, nestedLvl);
|
|
9124
|
+
selectUnselectProduct(setValue, getValues, secondProduct, secondProductValue !== false, unregister, nestedLvl);
|
|
9125
|
+
return;
|
|
9126
|
+
}
|
|
9034
9127
|
selectUnselectProduct(setValue, getValues, product, checked, unregister, nestedLvl);
|
|
9035
9128
|
if (isRadio) {
|
|
9036
|
-
console.log("handleOnInputChange radio", selCtx2, productId);
|
|
9037
9129
|
const otherGroupItems = (_a2 = parentPriduct == null ? void 0 : parentPriduct.items) == null ? void 0 : _a2.filter((x2) => x2.id !== product.id);
|
|
9038
9130
|
for (const key of Object.keys(selected || {})) {
|
|
9039
9131
|
const isItemToClear = (otherGroupItems == null ? void 0 : otherGroupItems.some((x2) => !!findProductInParentProductBySelCtx(x2, key))) ? key : false;
|
|
@@ -9144,7 +9236,8 @@ const MenuProductDefaultUI = (props) => {
|
|
|
9144
9236
|
counterValue,
|
|
9145
9237
|
handleCounterIncrementQty,
|
|
9146
9238
|
handleCounterDecrementQty,
|
|
9147
|
-
children
|
|
9239
|
+
children,
|
|
9240
|
+
parentProduct
|
|
9148
9241
|
} = props;
|
|
9149
9242
|
const CounterComponent = /* @__PURE__ */ jsx(Counter, {
|
|
9150
9243
|
value: counterValue,
|
|
@@ -9171,6 +9264,7 @@ const MenuProductDefaultUI = (props) => {
|
|
|
9171
9264
|
inputId,
|
|
9172
9265
|
registerProps,
|
|
9173
9266
|
isDisabled: !isCheckboxEnabled,
|
|
9267
|
+
parentProduct,
|
|
9174
9268
|
children: /* @__PURE__ */ jsx(Fragment, {
|
|
9175
9269
|
children: isCounter && CounterComponent
|
|
9176
9270
|
})
|
|
@@ -10794,7 +10888,6 @@ function ProductConfigurator(props) {
|
|
|
10794
10888
|
initFilter,
|
|
10795
10889
|
productQuantity,
|
|
10796
10890
|
setIsOnSubmittedOnTrue,
|
|
10797
|
-
getInvalidSelCtxArray,
|
|
10798
10891
|
increaseProductQuantity,
|
|
10799
10892
|
decreaseProductQuantity,
|
|
10800
10893
|
setCurrency
|