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