@inappstory/slide-api 0.1.27 → 0.1.28
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/index.cjs +107 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +107 -72
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19107,20 +19107,25 @@ class BottomSheet extends RenderableComponent {
|
|
|
19107
19107
|
return this._isOpened;
|
|
19108
19108
|
}
|
|
19109
19109
|
renderTemplate() {
|
|
19110
|
+
// TODO: calculate border-radius;
|
|
19111
|
+
const borderRadius = 30;
|
|
19110
19112
|
return h("div", { class: `ias-bottom-sheet ${this._isOpened ? "ias-bottom-sheet--open" : ""}` }, h("div", {
|
|
19111
19113
|
class: "ias-bottom-sheet__backdrop",
|
|
19112
19114
|
onClick: this.handleBackdropClick,
|
|
19113
|
-
}), h("div", {
|
|
19115
|
+
}), h("div", {
|
|
19116
|
+
class: "ias-bottom-sheet__container",
|
|
19117
|
+
style: this.props.minHeight != null ? `min-height: ${this.props.minHeight + borderRadius}px` : "",
|
|
19118
|
+
}, h("div", { class: "ias-bottom-sheet__content" },
|
|
19114
19119
|
/* h("div", { class: "ias-bottom-sheet__header" }), */
|
|
19115
19120
|
h("div", { class: "ias-bottom-sheet__body" }, ...(this.props?.children?.map(c => c.render()) ?? [])))));
|
|
19116
19121
|
}
|
|
19117
|
-
|
|
19122
|
+
setMinHeight(height) {
|
|
19118
19123
|
if (!this._root)
|
|
19119
19124
|
return;
|
|
19120
19125
|
const container = this._root.querySelector(".ias-bottom-sheet__container");
|
|
19121
19126
|
if (!container)
|
|
19122
19127
|
return;
|
|
19123
|
-
container.style.
|
|
19128
|
+
container.style.minHeight = `${height}px`;
|
|
19124
19129
|
}
|
|
19125
19130
|
open() {
|
|
19126
19131
|
if (this.isOpened)
|
|
@@ -19178,6 +19183,7 @@ const ADD_TO_CART_TIMEOUT = 60000;
|
|
|
19178
19183
|
|
|
19179
19184
|
class ProductDetailsPurchaseAction extends RenderableComponent {
|
|
19180
19185
|
button;
|
|
19186
|
+
isLoading = false;
|
|
19181
19187
|
constructor(props) {
|
|
19182
19188
|
super(props);
|
|
19183
19189
|
}
|
|
@@ -19190,7 +19196,10 @@ class ProductDetailsPurchaseAction extends RenderableComponent {
|
|
|
19190
19196
|
return this.button;
|
|
19191
19197
|
}
|
|
19192
19198
|
handleClickAddToCart = async () => {
|
|
19199
|
+
if (this.isLoading)
|
|
19200
|
+
return;
|
|
19193
19201
|
try {
|
|
19202
|
+
this.isLoading = true;
|
|
19194
19203
|
this.showLoader();
|
|
19195
19204
|
await this.addToCart();
|
|
19196
19205
|
}
|
|
@@ -19199,6 +19208,7 @@ class ProductDetailsPurchaseAction extends RenderableComponent {
|
|
|
19199
19208
|
}
|
|
19200
19209
|
finally {
|
|
19201
19210
|
this.hideLoader();
|
|
19211
|
+
this.isLoading = false;
|
|
19202
19212
|
}
|
|
19203
19213
|
};
|
|
19204
19214
|
showLoader() {
|
|
@@ -19584,50 +19594,6 @@ class ProductDetails extends RenderableComponent {
|
|
|
19584
19594
|
static get [Symbol.for("___CTOR_ARGS___")]() { return [`ProductDetailsProps`]; }
|
|
19585
19595
|
}
|
|
19586
19596
|
|
|
19587
|
-
class ProductOfferMapper {
|
|
19588
|
-
static fromOfferDtoToProductOffer(offerDto) {
|
|
19589
|
-
return {
|
|
19590
|
-
id: offerDto.id.toString(),
|
|
19591
|
-
offerId: offerDto.offerId,
|
|
19592
|
-
available: offerDto.availability !== 0,
|
|
19593
|
-
availability: offerDto.availability,
|
|
19594
|
-
options: {
|
|
19595
|
-
color: offerDto.color ? { name: "color", value: offerDto.color } : { name: "color", value: "Undefined" },
|
|
19596
|
-
size: offerDto.size ? { name: "size", value: offerDto.size } : { name: "size", value: "Undefined" },
|
|
19597
|
-
},
|
|
19598
|
-
name: offerDto.name,
|
|
19599
|
-
price: offerDto.price,
|
|
19600
|
-
oldPrice: offerDto.oldPrice,
|
|
19601
|
-
currency: offerDto.currency,
|
|
19602
|
-
description: offerDto.description,
|
|
19603
|
-
imageUrls: offerDto.images?.map(image => image.url) ?? [],
|
|
19604
|
-
adult: offerDto.adult,
|
|
19605
|
-
coverUrl: offerDto.coverUrl,
|
|
19606
|
-
groupId: offerDto.groupId,
|
|
19607
|
-
url: offerDto.url,
|
|
19608
|
-
};
|
|
19609
|
-
}
|
|
19610
|
-
static fromOfferDtoToProductCartOffer(offerDto, quantity) {
|
|
19611
|
-
return {
|
|
19612
|
-
offerId: offerDto.offerId,
|
|
19613
|
-
imageUrls: offerDto.images?.map(image => image.url) ?? [],
|
|
19614
|
-
availability: offerDto.availability,
|
|
19615
|
-
quantity,
|
|
19616
|
-
groupId: offerDto.groupId,
|
|
19617
|
-
name: offerDto.name,
|
|
19618
|
-
description: offerDto.description,
|
|
19619
|
-
url: offerDto.url,
|
|
19620
|
-
coverUrl: offerDto.coverUrl,
|
|
19621
|
-
currency: offerDto.currency,
|
|
19622
|
-
price: offerDto.price,
|
|
19623
|
-
oldPrice: offerDto.oldPrice,
|
|
19624
|
-
adult: offerDto.adult,
|
|
19625
|
-
size: offerDto.size,
|
|
19626
|
-
color: offerDto.color,
|
|
19627
|
-
};
|
|
19628
|
-
}
|
|
19629
|
-
}
|
|
19630
|
-
|
|
19631
19597
|
const successSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="none"><path stroke="#212121" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" d="M40 14 18 36 8 26"></path></svg>`;
|
|
19632
19598
|
class ProductCheckout extends RenderableComponent {
|
|
19633
19599
|
constructor(props) {
|
|
@@ -19707,21 +19673,20 @@ class ProductComponentsFactory {
|
|
|
19707
19673
|
this.widgetDeps = widgetDeps;
|
|
19708
19674
|
this.props = props;
|
|
19709
19675
|
}
|
|
19710
|
-
createBottomSheet() {
|
|
19676
|
+
createBottomSheet(props) {
|
|
19711
19677
|
const bs = new BottomSheet({
|
|
19712
19678
|
onClose: () => {
|
|
19713
19679
|
bs.destroy();
|
|
19714
19680
|
},
|
|
19715
19681
|
children: [],
|
|
19682
|
+
minHeight: props.minHeight,
|
|
19716
19683
|
});
|
|
19717
19684
|
return bs;
|
|
19718
19685
|
}
|
|
19719
19686
|
createProductDetails(params) {
|
|
19720
19687
|
return new ProductDetails({
|
|
19721
|
-
product:
|
|
19722
|
-
relatedProducts: params.
|
|
19723
|
-
? params.offer.subOffersApi.map(subOffer => ProductOfferMapper.fromOfferDtoToProductOffer(subOffer))
|
|
19724
|
-
: [],
|
|
19688
|
+
product: params.product,
|
|
19689
|
+
relatedProducts: params.relatedProducts,
|
|
19725
19690
|
onAddToCart: params.onAddToCart,
|
|
19726
19691
|
onAddToCartError: ({ error }) => {
|
|
19727
19692
|
this.widgetDeps.slideApiDeps.showToast(error.message);
|
|
@@ -19729,8 +19694,8 @@ class ProductComponentsFactory {
|
|
|
19729
19694
|
translations: this.props.translations,
|
|
19730
19695
|
isCartSupported: params.isCartSupported,
|
|
19731
19696
|
onOpenUrl: () => {
|
|
19732
|
-
if (params.
|
|
19733
|
-
this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target: params.
|
|
19697
|
+
if (params.product.url)
|
|
19698
|
+
this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target: params.product.url } });
|
|
19734
19699
|
},
|
|
19735
19700
|
});
|
|
19736
19701
|
}
|
|
@@ -19769,6 +19734,50 @@ class ProductComponentsFactory {
|
|
|
19769
19734
|
}`]; }
|
|
19770
19735
|
}
|
|
19771
19736
|
|
|
19737
|
+
class ProductOfferMapper {
|
|
19738
|
+
static fromOfferDtoToProductOffer(offerDto) {
|
|
19739
|
+
return {
|
|
19740
|
+
id: offerDto.id.toString(),
|
|
19741
|
+
offerId: offerDto.offerId,
|
|
19742
|
+
available: offerDto.availability !== 0,
|
|
19743
|
+
availability: offerDto.availability,
|
|
19744
|
+
options: {
|
|
19745
|
+
color: offerDto.color ? { name: "color", value: offerDto.color } : { name: "color", value: "Undefined" },
|
|
19746
|
+
size: offerDto.size ? { name: "size", value: offerDto.size } : { name: "size", value: "Undefined" },
|
|
19747
|
+
},
|
|
19748
|
+
name: offerDto.name,
|
|
19749
|
+
price: offerDto.price,
|
|
19750
|
+
oldPrice: offerDto.oldPrice,
|
|
19751
|
+
currency: offerDto.currency,
|
|
19752
|
+
description: offerDto.description,
|
|
19753
|
+
imageUrls: offerDto.images?.map(image => image.url) ?? [],
|
|
19754
|
+
adult: offerDto.adult,
|
|
19755
|
+
coverUrl: offerDto.coverUrl,
|
|
19756
|
+
groupId: offerDto.groupId,
|
|
19757
|
+
url: offerDto.url,
|
|
19758
|
+
};
|
|
19759
|
+
}
|
|
19760
|
+
static fromOfferDtoToProductCartOffer(offerDto, quantity) {
|
|
19761
|
+
return {
|
|
19762
|
+
offerId: offerDto.offerId,
|
|
19763
|
+
imageUrls: offerDto.images?.map(image => image.url) ?? [],
|
|
19764
|
+
availability: offerDto.availability,
|
|
19765
|
+
quantity,
|
|
19766
|
+
groupId: offerDto.groupId,
|
|
19767
|
+
name: offerDto.name,
|
|
19768
|
+
description: offerDto.description,
|
|
19769
|
+
url: offerDto.url,
|
|
19770
|
+
coverUrl: offerDto.coverUrl,
|
|
19771
|
+
currency: offerDto.currency,
|
|
19772
|
+
price: offerDto.price,
|
|
19773
|
+
oldPrice: offerDto.oldPrice,
|
|
19774
|
+
adult: offerDto.adult,
|
|
19775
|
+
size: offerDto.size,
|
|
19776
|
+
color: offerDto.color,
|
|
19777
|
+
};
|
|
19778
|
+
}
|
|
19779
|
+
}
|
|
19780
|
+
|
|
19772
19781
|
class ProductDetailsBottomSheet extends RenderableComponent {
|
|
19773
19782
|
widgetDeps;
|
|
19774
19783
|
factory;
|
|
@@ -19777,7 +19786,7 @@ class ProductDetailsBottomSheet extends RenderableComponent {
|
|
|
19777
19786
|
super(props);
|
|
19778
19787
|
this.widgetDeps = widgetDeps;
|
|
19779
19788
|
this.factory = new ProductComponentsFactory(this.widgetDeps, this.props);
|
|
19780
|
-
this.bottomSheet = this.factory.createBottomSheet();
|
|
19789
|
+
this.bottomSheet = this.factory.createBottomSheet({ minHeight: props.height });
|
|
19781
19790
|
}
|
|
19782
19791
|
renderTemplate() {
|
|
19783
19792
|
return this.bottomSheet.render();
|
|
@@ -19792,8 +19801,10 @@ class ProductDetailsBottomSheet extends RenderableComponent {
|
|
|
19792
19801
|
this.renderProductDetails({ factory, offer, offerDtos, isCartSupported });
|
|
19793
19802
|
};
|
|
19794
19803
|
renderProductDetails({ factory, offer, offerDtos, isCartSupported, }) {
|
|
19804
|
+
const { product, relatedProducts } = this.getProductAndRelatedProducts(offer);
|
|
19795
19805
|
const productDetails = factory.createProductDetails({
|
|
19796
|
-
|
|
19806
|
+
product,
|
|
19807
|
+
relatedProducts,
|
|
19797
19808
|
onAddToCart: async (payload) => {
|
|
19798
19809
|
await this.productCartUpdate({
|
|
19799
19810
|
offerDtos,
|
|
@@ -19809,7 +19820,6 @@ class ProductDetailsBottomSheet extends RenderableComponent {
|
|
|
19809
19820
|
showProductCheckout({ offerDtos }) {
|
|
19810
19821
|
const productCheckout = this.factory.createProductCheckout(this.bottomSheet, offerDtos);
|
|
19811
19822
|
this.updateBottomSheetContent(productCheckout);
|
|
19812
|
-
this.bottomSheet.setHeight("auto");
|
|
19813
19823
|
}
|
|
19814
19824
|
updateBottomSheetContent(content) {
|
|
19815
19825
|
const cartButton = this.factory.createProductCartButton();
|
|
@@ -19832,6 +19842,16 @@ class ProductDetailsBottomSheet extends RenderableComponent {
|
|
|
19832
19842
|
]);
|
|
19833
19843
|
return productCart.offers;
|
|
19834
19844
|
}
|
|
19845
|
+
getProductAndRelatedProducts(offerDto) {
|
|
19846
|
+
return {
|
|
19847
|
+
product: ProductOfferMapper.fromOfferDtoToProductOffer(offerDto),
|
|
19848
|
+
relatedProducts: offerDto.subOffersApi
|
|
19849
|
+
? offerDto.subOffersApi
|
|
19850
|
+
.filter(subOffer => subOffer.size != null && subOffer.color != null)
|
|
19851
|
+
.map(subOffer => ProductOfferMapper.fromOfferDtoToProductOffer(subOffer))
|
|
19852
|
+
: [],
|
|
19853
|
+
};
|
|
19854
|
+
}
|
|
19835
19855
|
static get [Symbol.for("___CTOR_ARGS___")]() { return [`WidgetDeps`, `ProductDetailsBottomSheetProps`]; }
|
|
19836
19856
|
}
|
|
19837
19857
|
|
|
@@ -19900,6 +19920,7 @@ class WidgetProducts extends WidgetBase {
|
|
|
19900
19920
|
}
|
|
19901
19921
|
onStart() {
|
|
19902
19922
|
super.onStart();
|
|
19923
|
+
this.isLoading = false;
|
|
19903
19924
|
// reinit for case when we returned to slide from other slide and onStop destroyed SwipeGestureDetector
|
|
19904
19925
|
this.initSwipeGestureDetector();
|
|
19905
19926
|
}
|
|
@@ -19984,6 +20005,16 @@ class WidgetProducts extends WidgetBase {
|
|
|
19984
20005
|
console.error(error);
|
|
19985
20006
|
}
|
|
19986
20007
|
}
|
|
20008
|
+
async getOrFetchProducts() {
|
|
20009
|
+
if (this.currentModels.length > 0)
|
|
20010
|
+
return this.currentModels;
|
|
20011
|
+
const result = await this.fetchProducts();
|
|
20012
|
+
if (result.models.length > 0) {
|
|
20013
|
+
this.currentModels = result.models;
|
|
20014
|
+
return result.models;
|
|
20015
|
+
}
|
|
20016
|
+
throw new Error(result.message);
|
|
20017
|
+
}
|
|
19987
20018
|
async fetchProducts() {
|
|
19988
20019
|
const fetchAndCacheMedia = async () => {
|
|
19989
20020
|
if (!this.linkTarget.length) {
|
|
@@ -20098,12 +20129,13 @@ class WidgetProducts extends WidgetBase {
|
|
|
20098
20129
|
}
|
|
20099
20130
|
productsView = null;
|
|
20100
20131
|
isOpen = false;
|
|
20132
|
+
isLoading = false;
|
|
20101
20133
|
get isForcePaused() {
|
|
20102
20134
|
return this.isOpen;
|
|
20103
20135
|
}
|
|
20104
20136
|
currentModels = [];
|
|
20105
20137
|
async openProductsView() {
|
|
20106
|
-
if (this.isOpen) {
|
|
20138
|
+
if (this.isOpen || this.isLoading) {
|
|
20107
20139
|
return;
|
|
20108
20140
|
}
|
|
20109
20141
|
this._statEventWidgetClick();
|
|
@@ -20113,14 +20145,10 @@ class WidgetProducts extends WidgetBase {
|
|
|
20113
20145
|
if (!this.isTransparentElement()) {
|
|
20114
20146
|
this.element.classList.add("loader");
|
|
20115
20147
|
}
|
|
20116
|
-
|
|
20117
|
-
|
|
20118
|
-
|
|
20119
|
-
|
|
20120
|
-
// console.log({result})
|
|
20121
|
-
if (result.models.length > 0) {
|
|
20122
|
-
this.currentModels = result.models;
|
|
20123
|
-
this.productsView = this.createProductsView(this.currentModels, this.closeProductsView.bind(this));
|
|
20148
|
+
try {
|
|
20149
|
+
this.isLoading = true;
|
|
20150
|
+
const models = await this.getOrFetchProducts();
|
|
20151
|
+
this.productsView = this.createProductsView(models, this.closeProductsView.bind(this));
|
|
20124
20152
|
this.productsView.classList.add("ias-products-container-view--visible");
|
|
20125
20153
|
this.slide.appendChild(this.productsView);
|
|
20126
20154
|
this.element.classList.add("hidden");
|
|
@@ -20130,15 +20158,16 @@ class WidgetProducts extends WidgetBase {
|
|
|
20130
20158
|
this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
|
|
20131
20159
|
this.widgetDeps.slideApiDeps.disableVerticalSwipeGesture();
|
|
20132
20160
|
this.widgetDeps.slideApiDeps.disableBackpress();
|
|
20133
|
-
this._statEventWidgetOpen(
|
|
20161
|
+
this._statEventWidgetOpen(models);
|
|
20134
20162
|
this.initSwipeGestureDetector();
|
|
20135
20163
|
}
|
|
20136
|
-
|
|
20137
|
-
|
|
20138
|
-
|
|
20139
|
-
|
|
20164
|
+
catch (error) {
|
|
20165
|
+
this.widgetDeps.slideApiDeps.showToast(error.message);
|
|
20166
|
+
}
|
|
20167
|
+
finally {
|
|
20168
|
+
this.isLoading = false;
|
|
20169
|
+
this.element.classList.remove("loader");
|
|
20140
20170
|
}
|
|
20141
|
-
this.element.classList.remove("loader");
|
|
20142
20171
|
}
|
|
20143
20172
|
closeProductsView() {
|
|
20144
20173
|
if (!this.isOpen) {
|
|
@@ -20223,6 +20252,11 @@ class WidgetProducts extends WidgetBase {
|
|
|
20223
20252
|
showProductDetails = ({ card, offer }) => {
|
|
20224
20253
|
if (!this.productsView)
|
|
20225
20254
|
return;
|
|
20255
|
+
const backgroundView = this.slide.querySelector(".ias-products-container-background-view");
|
|
20256
|
+
const scrollViewGroup = this.slide.querySelector(".ias-products-scroll-view-group");
|
|
20257
|
+
const backgroundViewHeight = backgroundView?.clientHeight ?? 0;
|
|
20258
|
+
let scrollViewGroupHeight = scrollViewGroup?.offsetTop ?? 0;
|
|
20259
|
+
scrollViewGroupHeight = scrollViewGroupHeight > 0 ? 0 : -scrollViewGroupHeight;
|
|
20226
20260
|
const bs = new ProductDetailsBottomSheet(this.widgetDeps, {
|
|
20227
20261
|
translations: {
|
|
20228
20262
|
color: getTagData(this.element, "msgColor") ?? "",
|
|
@@ -20235,6 +20269,7 @@ class WidgetProducts extends WidgetBase {
|
|
|
20235
20269
|
continueBtn: getTagData(this.element, "msgContinue") ?? "",
|
|
20236
20270
|
openUrl: getTagData(this.element, "msgOpenUrl") ?? "",
|
|
20237
20271
|
},
|
|
20272
|
+
height: backgroundViewHeight + scrollViewGroupHeight,
|
|
20238
20273
|
});
|
|
20239
20274
|
const isCartEnabled = getTagData(this.element, "isCartEnabled") === "true";
|
|
20240
20275
|
const isCartSupported = this.widgetDeps.slideApiDeps.isSdkSupportProductCart && isCartEnabled;
|