@orderingstack/front-components-product-configurator 1.3.5 → 1.4.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/useMenuProduct.d.ts.map +1 -1
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +62 -4
- package/dist/index.es.js.map +1 -1
- package/dist/utils/formatValues.d.ts.map +1 -1
- package/dist/utils/setSelected.d.ts +2 -0
- package/dist/utils/setSelected.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -6022,14 +6022,12 @@ function isEqual(value, other) {
|
|
|
6022
6022
|
const propertyToEncode = ["id", "selCtx", "fltCtx"];
|
|
6023
6023
|
const CHAR_TO_REPLACE = ".";
|
|
6024
6024
|
const REPLACEMENT_CHAR = "#dot";
|
|
6025
|
-
const DASH_CHAR_TO_REPLACE = "-";
|
|
6026
|
-
const DASH_REPLACEMENT_CHAR = "#dash";
|
|
6027
6025
|
const FIX_NUMBER_PREFIX = "#FIX_NUMBER";
|
|
6028
6026
|
const encodeProduct = (product) => {
|
|
6029
6027
|
return iterateOverObject(cloneDeep(product), encodeValue);
|
|
6030
6028
|
};
|
|
6031
6029
|
const replaceIn = (value) => {
|
|
6032
|
-
const replaced = value.replaceAll(CHAR_TO_REPLACE, REPLACEMENT_CHAR)
|
|
6030
|
+
const replaced = value.replaceAll(CHAR_TO_REPLACE, REPLACEMENT_CHAR);
|
|
6033
6031
|
if (/^\d+$/.test(replaced)) {
|
|
6034
6032
|
return `${FIX_NUMBER_PREFIX}${replaced}`;
|
|
6035
6033
|
} else {
|
|
@@ -6037,7 +6035,7 @@ const replaceIn = (value) => {
|
|
|
6037
6035
|
}
|
|
6038
6036
|
};
|
|
6039
6037
|
const replaceOut = (value) => {
|
|
6040
|
-
return value.replaceAll(REPLACEMENT_CHAR, CHAR_TO_REPLACE).replaceAll(
|
|
6038
|
+
return value.replaceAll(REPLACEMENT_CHAR, CHAR_TO_REPLACE).replaceAll(FIX_NUMBER_PREFIX, "");
|
|
6041
6039
|
};
|
|
6042
6040
|
const encodeValue = (key, value) => {
|
|
6043
6041
|
return codeValue(key, value, replaceIn);
|
|
@@ -8685,6 +8683,60 @@ function useValidate() {
|
|
|
8685
8683
|
isInputCounterIncrementEnabled: isInputCounterIncrementEnabled2
|
|
8686
8684
|
};
|
|
8687
8685
|
}
|
|
8686
|
+
const addProductToState = (selected, setValue) => {
|
|
8687
|
+
Object.keys(selected).forEach((selCtx) => {
|
|
8688
|
+
setValue(`selected.${selCtx}`, selected[selCtx]);
|
|
8689
|
+
});
|
|
8690
|
+
};
|
|
8691
|
+
const removeProductFromState = (selCtx, getValues, setValue) => {
|
|
8692
|
+
const changedSelCtx = getValues(`selected.${selCtx}`);
|
|
8693
|
+
setValue(
|
|
8694
|
+
`selected.${selCtx}`,
|
|
8695
|
+
Object.keys(changedSelCtx).reduce((acc, key) => {
|
|
8696
|
+
acc[key] = false;
|
|
8697
|
+
return acc;
|
|
8698
|
+
}, {})
|
|
8699
|
+
);
|
|
8700
|
+
};
|
|
8701
|
+
const selectUnselectProduct = (setValue, getValues, items, isChecked, state) => {
|
|
8702
|
+
const { selected = {} } = state || {};
|
|
8703
|
+
if (isChecked) {
|
|
8704
|
+
addProductToState(selected, setValue);
|
|
8705
|
+
const checkSubProducts = (items2) => {
|
|
8706
|
+
if (!Array.isArray(items2))
|
|
8707
|
+
return;
|
|
8708
|
+
items2.map((product) => {
|
|
8709
|
+
if (product.state && "selected" in product.state) {
|
|
8710
|
+
const {
|
|
8711
|
+
state: { selected: selected2 }
|
|
8712
|
+
} = product;
|
|
8713
|
+
addProductToState(selected2, setValue);
|
|
8714
|
+
}
|
|
8715
|
+
if (Array.isArray(product.items)) {
|
|
8716
|
+
checkSubProducts(product.items);
|
|
8717
|
+
}
|
|
8718
|
+
});
|
|
8719
|
+
};
|
|
8720
|
+
checkSubProducts(items);
|
|
8721
|
+
} else {
|
|
8722
|
+
Object.keys(selected).forEach((selCtx) => {
|
|
8723
|
+
removeProductFromState(selCtx, getValues, setValue);
|
|
8724
|
+
});
|
|
8725
|
+
const checkSubProducts = (items2) => {
|
|
8726
|
+
if (!Array.isArray(items2))
|
|
8727
|
+
return;
|
|
8728
|
+
items2.map((product) => {
|
|
8729
|
+
const { selCtx } = product;
|
|
8730
|
+
const changedSelCtx = getValues(`selected.${selCtx}`);
|
|
8731
|
+
if (changedSelCtx) {
|
|
8732
|
+
removeProductFromState(selCtx, getValues, setValue);
|
|
8733
|
+
}
|
|
8734
|
+
checkSubProducts(product.items);
|
|
8735
|
+
});
|
|
8736
|
+
};
|
|
8737
|
+
checkSubProducts(items);
|
|
8738
|
+
}
|
|
8739
|
+
};
|
|
8688
8740
|
function useMenuProduct(product, parentAttrs) {
|
|
8689
8741
|
var _a;
|
|
8690
8742
|
const { id, selCtx } = product;
|
|
@@ -8728,6 +8780,12 @@ function useMenuProduct(product, parentAttrs) {
|
|
|
8728
8780
|
const {
|
|
8729
8781
|
target: { checked, name: selCtx2, defaultValue: productId }
|
|
8730
8782
|
} = e2;
|
|
8783
|
+
for (const key of Object.keys(selected || {})) {
|
|
8784
|
+
if (key !== (product == null ? void 0 : product.selCtx) && (key == null ? void 0 : key.includes(product.selCtx)) && isRadio) {
|
|
8785
|
+
setValue(`selected.${key}`, false);
|
|
8786
|
+
}
|
|
8787
|
+
}
|
|
8788
|
+
selectUnselectProduct(setValue, getValues, product.items, checked, product.state);
|
|
8731
8789
|
if (isRadio) {
|
|
8732
8790
|
console.log("handleOnInputChange radio", selCtx2, productId);
|
|
8733
8791
|
const selectedContextName = "selected." + selCtx2.replace("radio.", "").split(".")[0];
|