@vtex/ads-stories 0.5.0 → 0.8.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +29 -297
  3. package/dist/cdn/vtex-ads-stories.js +438 -113
  4. package/dist/cdn/vtex-ads-stories.js.map +1 -1
  5. package/dist/cjs/index.cjs +932 -189
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +42 -196
  8. package/dist/cjs/react.cjs.map +1 -1
  9. package/dist/cjs/react.d.cts +13 -3
  10. package/dist/cjs/story-Ba9J0rbL.d.cts +276 -0
  11. package/dist/esm/index.d.ts +42 -196
  12. package/dist/esm/index.js +956 -212
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/react.d.ts +13 -3
  15. package/dist/esm/story-Ba9J0rbL.d.ts +276 -0
  16. package/package.json +1 -1
  17. package/src/commerce-events.ts +93 -0
  18. package/src/components/card/card.ts +16 -3
  19. package/src/components/carousel/carousel-skeleton.ts +113 -0
  20. package/src/components/carousel/carousel.ts +53 -8
  21. package/src/components/carousel/index.ts +7 -0
  22. package/src/components/events/events-controller.ts +23 -13
  23. package/src/components/icons/assets/minus.svg +1 -0
  24. package/src/components/icons/assets/plus.svg +1 -0
  25. package/src/components/icons/assets/trash.svg +1 -0
  26. package/src/components/icons/assets/warning-circle-fill.svg +1 -0
  27. package/src/components/icons/index.ts +8 -0
  28. package/src/components/media/index.ts +7 -1
  29. package/src/components/media/media.styles.ts +113 -0
  30. package/src/components/media/media.ts +108 -11
  31. package/src/components/media/video-controller.ts +80 -6
  32. package/src/components/player/player.ts +42 -17
  33. package/src/components/product/cta.ts +3 -3
  34. package/src/components/product/index.ts +2 -0
  35. package/src/components/product/product.styles.ts +63 -6
  36. package/src/components/product/product.ts +130 -29
  37. package/src/index.ts +8 -0
  38. package/src/locales/en.ts +13 -3
  39. package/src/locales/es.ts +13 -3
  40. package/src/locales/index.ts +6 -0
  41. package/src/locales/pt.ts +13 -3
  42. package/src/locales/types.ts +22 -2
  43. package/src/react.ts +12 -2
  44. package/src/story/story.ts +218 -20
  45. package/src/utils/hydrate-products.ts +30 -6
  46. package/src/utils/media-ready.ts +58 -0
  47. package/src/utils/safe-url.ts +36 -0
  48. package/src/utils/send-event.ts +1 -1
  49. package/src/utils/http-url.ts +0 -12
@@ -1,206 +1,52 @@
1
- import * as lit from 'lit';
2
- import { LitElement, PropertyValues, nothing } from 'lit';
3
- import { ProductFetcher, Offer, ProductPrice, Channel } from '@vtex/ads-core';
1
+ export { S as StoryHydration, a as StoryProductDetails, T as TAG_NAME, V as VtexAdsStoryCarouselElement, d as defineVtexAdsStoryCarousel } from './story-Ba9J0rbL.js';
2
+ import 'lit';
3
+ import '@vtex/ads-core';
4
4
 
5
5
  /**
6
- * Where the element gets its products' details: a fetcher and a matcher, as
7
- * in `@vtex/ads-core`, and a reader for the price of a fetched product.
6
+ * The commerce events the element hands to the store: it has no cart of its
7
+ * own. They bubble and cross shadow roots, so the store can listen on the
8
+ * element, the document or any ancestor.
8
9
  */
9
- interface StoryHydration<TProduct extends object = object> {
10
- fetcher: ProductFetcher<TProduct>;
11
- matcher(product: TProduct, offer: Offer): boolean;
12
- price(product: TProduct, offer: Offer): ProductPrice | undefined;
13
- /** Whether the product can be bought. Without it, it isn't checked. */
14
- available?(product: TProduct, offer: Offer): boolean | undefined;
15
- }
16
- interface StoryProductDetails {
17
- price?: ProductPrice;
18
- /** Missing when the strategy doesn't say. */
19
- available?: boolean;
20
- }
21
-
22
- declare const TAG_NAME = "vtex-ads-story-carousel";
23
-
24
- declare class VtexAdsStoryCarouselElement extends LitElement {
25
- static readonly properties: {
26
- publisherId: {
27
- attribute: string;
28
- };
29
- sessionId: {
30
- attribute: string;
31
- };
32
- placement: {};
33
- userId: {
34
- attribute: string;
35
- };
36
- accountName: {
37
- attribute: string;
38
- };
39
- channel: {
40
- converter: {
41
- fromAttribute: (value: string | null) => Channel | undefined;
42
- };
43
- };
44
- timeout: {
45
- type: NumberConstructor;
46
- };
47
- quantity: {
48
- type: NumberConstructor;
49
- };
50
- currency: {};
51
- labelAddToCart: {
52
- attribute: string;
53
- };
54
- labelViewProduct: {
55
- attribute: string;
56
- };
57
- hydration: {
58
- converter: {
59
- fromAttribute: (value: string | null) => "none" | undefined;
60
- };
61
- };
62
- hydrationTimeout: {
63
- type: NumberConstructor;
64
- attribute: string;
65
- };
66
- inactiveAutoplay: {
67
- type: BooleanConstructor;
68
- attribute: string;
69
- converter: {
70
- fromAttribute: (value: string | null) => boolean;
71
- };
72
- };
73
- stories: {
74
- state: boolean;
75
- };
76
- products: {
77
- state: boolean;
78
- };
79
- };
80
- /** Required. The publisher the ads are requested for. */
81
- publisherId?: string;
82
- /** Required. The store's session, also used to deduplicate events. */
83
- sessionId?: string;
84
- /** Required. The Story placement configured for the publisher. */
85
- placement?: string;
86
- userId?: string;
87
- accountName?: string;
88
- /** `site` or `app`. Any other attribute value is ignored. */
89
- channel?: Channel;
90
- /**
91
- * Time limit for the ad request, in milliseconds (default 2000). Without a
92
- * Story by then, the element renders nothing. A change applies to the next
93
- * request; it doesn't request again.
94
- */
95
- timeout?: number;
96
- /**
97
- * How many Stories to ask for: the carousel positions (default 8). Missing,
98
- * below 1 or not a number: the default.
99
- */
100
- quantity?: number;
101
- /**
102
- * Currency of the prices, as an ISO 4217 code ("BRL", "ARS"). Missing or
103
- * invalid: BRL.
104
- */
105
- currency?: string;
106
- /**
107
- * The add to cart button's text. Missing or blank: the default in the
108
- * element's language ("Adicionar ao carrinho").
109
- */
110
- labelAddToCart?: string;
111
- /**
112
- * The view product button's text. Missing or blank: the default in the
113
- * element's language ("Ver produto").
114
- */
115
- labelViewProduct?: string;
116
- /**
117
- * Where the products' details (for now, their prices) come from. A
118
- * strategy (fetcher, matcher and price reader) is set as a property; the
119
- * attribute takes only "none", for no product request. Missing:
120
- * Intelligent Search when `account-name` is set, no product request
121
- * otherwise.
122
- */
123
- hydration?: StoryHydration | "none";
124
- /**
125
- * Time limit for the product request, in milliseconds (default 5000).
126
- * Without the prices by then, the cards show the ad server's.
127
- */
128
- hydrationTimeout?: number;
129
- /**
130
- * With more than one Story, whether the cards without the highlight also
131
- * play their video, muted. Off by default: they show only their cover, and
132
- * only the highlighted card plays.
133
- */
134
- inactiveAutoplay: boolean;
135
- /** The Stories shown: none while loading, on error or with none. */
136
- private stories;
137
- /**
138
- * The fetched products, by Story `ad_id`, or `"loading"` while the product
139
- * request runs. Undefined without a product request.
140
- */
141
- private products?;
142
- /**
143
- * Cancels the request in progress. Kept, already aborted, when leaving the
144
- * page cancelled it, so connecting again requests once more.
145
- */
146
- private request?;
147
- static readonly styles: lit.CSSResult[];
148
- /**
149
- * One per rendered card, by its key (see Slide): a Story can show in more
150
- * than one card, each with its own video.
151
- */
152
- private readonly cardVideos;
153
- /** The sound was on when the highlight moved: the new card turns it on. */
154
- private soundPending;
155
- /**
156
- * What to do once the next render is on screen, when the new highlighted
157
- * card's video exists (see leaveHighlight and onLayoutChange). A step
158
- * taken before then replaces it.
159
- */
160
- private afterRender?;
161
- private readonly carousel;
162
- private readonly player;
163
- private readonly events;
164
- constructor();
165
- connectedCallback(): void;
166
- disconnectedCallback(): void;
167
- protected willUpdate(changed: PropertyValues<this>): void;
168
- protected updated(): void;
169
- private get activeHydration();
170
- /**
171
- * Requests the Story and shows it, then hydrates its products. Until the
172
- * Story arrives, and when there is none (see fetchStories), the element
173
- * renders nothing.
174
- */
175
- private loadStory;
176
- private showStories;
10
+ /**
11
+ * Add to cart, or the stepper's plus, was clicked in the player. No default
12
+ * action.
13
+ */
14
+ declare const ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
15
+ /**
16
+ * The stepper's minus, or its trash with one left, was clicked in the
17
+ * player. No default action.
18
+ */
19
+ declare const REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
20
+ interface StoryCartEventDetail {
21
+ /** The Story product's SKU, from the ad API (`product.product_sku`). */
22
+ sku: string;
177
23
  /**
178
- * Where each Story is being watched: the cards on screen (not the hidden
179
- * ones kept for the slide in) and the open player's video, while their
180
- * video plays. A card showing only its cover doesn't count. Behind the
181
- * expanded player, a modal over the page, the cards are covered.
24
+ * The product's seller, from the ad API (`product.seller_id`). Missing
25
+ * when the ad API doesn't send one.
182
26
  */
183
- private viewTargets;
184
- private videoFor;
185
- private get activeVideo();
186
- private leaveHighlight;
187
- private stepInPlayer;
188
- private openPlayer;
189
- private closePlayer;
190
- private formatter?;
191
- private get locale();
192
- private labelSet?;
193
- private get labels();
194
- private get formatPrice();
195
- private productOf;
196
- private readonly renderSlide;
197
- protected render(): typeof nothing | lit.TemplateResult<1>;
27
+ seller?: string;
28
+ /** How many to add (or, removing, to remove). Always 1 for now. */
29
+ quantity: number;
198
30
  }
31
+ /** The detail of the add to cart event: `quantity` is how many to add. */
32
+ type StoryAddToCartDetail = StoryCartEventDetail;
33
+ /** The detail of remove from cart: `quantity` is how many to remove. */
34
+ type StoryRemoveFromCartDetail = StoryCartEventDetail;
35
+ type StoryAddToCartEvent = CustomEvent<StoryAddToCartDetail>;
36
+ type StoryRemoveFromCartEvent = CustomEvent<StoryRemoveFromCartDetail>;
199
37
  declare global {
200
- interface HTMLElementTagNameMap {
201
- [TAG_NAME]: VtexAdsStoryCarouselElement;
38
+ interface HTMLElementEventMap {
39
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
40
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
41
+ }
42
+ interface DocumentEventMap {
43
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
44
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
45
+ }
46
+ interface WindowEventMap {
47
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
48
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
202
49
  }
203
50
  }
204
- declare function defineVtexAdsStoryCarousel(): void;
205
51
 
206
- export { type StoryHydration, type StoryProductDetails, TAG_NAME, VtexAdsStoryCarouselElement, defineVtexAdsStoryCarousel };
52
+ export { ADD_TO_CART_EVENT, REMOVE_FROM_CART_EVENT, type StoryAddToCartDetail, type StoryAddToCartEvent, type StoryRemoveFromCartDetail, type StoryRemoveFromCartEvent };