@streamscloud/embeddable 10.0.0 → 10.1.1
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/core/actions/horizontal-wheel-scroll.d.ts +1 -0
- package/dist/core/actions/horizontal-wheel-scroll.js +9 -8
- package/dist/streams/layout/cmp.slot-content.svelte +18 -13
- package/dist/streams/layout/element-views/cmp.button-stream-element.svelte +26 -0
- package/dist/streams/layout/element-views/cmp.button-stream-element.svelte.d.ts +10 -0
- package/dist/streams/layout/element-views/cmp.products-slider-stream-element.svelte +43 -0
- package/dist/streams/layout/element-views/cmp.products-slider-stream-element.svelte.d.ts +13 -0
- package/dist/streams/layout/element-views/cmp.stream-element.svelte +8 -6
- package/dist/streams/layout/element-views/index.d.ts +2 -0
- package/dist/streams/layout/element-views/index.js +2 -0
- package/dist/streams/layout/element-views/price-element-view.svelte +3 -0
- package/dist/streams/layout/elements.d.ts +20 -2
- package/dist/streams/layout/enums.d.ts +4 -1
- package/dist/streams/layout/enums.js +3 -0
- package/dist/streams/layout/index.d.ts +1 -0
- package/dist/streams/layout/index.js +15 -0
- package/dist/streams/layout/serializer.svelte.js +30 -5
- package/dist/streams/layout/slot-data-input.d.ts +5 -1
- package/dist/streams/layout/slot-data-ref.d.ts +2 -2
- package/dist/streams/layout/slot-data.d.ts +6 -1
- package/dist/streams/layout/styles-transformer.d.ts +3 -1
- package/dist/streams/layout/styles-transformer.js +47 -0
- package/dist/streams/layout/styles.d.ts +25 -0
- package/dist/streams/layout/type-guards.d.ts +11 -4
- package/dist/streams/layout/type-guards.js +17 -3
- package/dist/ui/player/providers/chunks-player-buffer/player-chunks-manager.svelte.d.ts +6 -6
- package/dist/ui/player/providers/chunks-player-buffer/player-chunks-manager.svelte.js +24 -16
- package/package.json +1 -1
- package/dist/streams/layout/element-views/stream-element-localization.d.ts +0 -7
- package/dist/streams/layout/element-views/stream-element-localization.js +0 -11
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
export const horizontalWheelScroll = (node, param = { isolateScroll: true }) => {
|
|
1
|
+
export const horizontalWheelScroll = (node, param = { isolateScroll: true, speed: 1 }) => {
|
|
2
2
|
const onWheel = (event) => {
|
|
3
3
|
const canScrollX = node.scrollWidth > node.clientWidth;
|
|
4
4
|
if (!canScrollX) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const delta = event.deltaY * (param.speed ?? 1);
|
|
11
|
+
node.scrollBy({ left: delta, behavior: 'auto' });
|
|
12
|
+
if (param.isolateScroll) {
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
event.stopPropagation();
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
node.addEventListener('wheel', onWheel, { passive: false });
|
|
@@ -3,30 +3,35 @@ import { enrichProductLinkWithTracking } from '../../marketing-tracking';
|
|
|
3
3
|
import { StreamElementView } from './element-views';
|
|
4
4
|
import { StreamComponentDataType } from './enums';
|
|
5
5
|
let { model, locale, trackingParams, on } = $props();
|
|
6
|
+
const slotData = $derived.by(() => {
|
|
7
|
+
return model.data;
|
|
8
|
+
});
|
|
6
9
|
const component = $derived.by(() => {
|
|
7
|
-
return model.components.find((c) => (
|
|
10
|
+
return model.components.find((c) => (slotData ? c.dataType === slotData.type : c.dataType === StreamComponentDataType.NoData));
|
|
8
11
|
});
|
|
9
12
|
const dataIsFilled = $derived.by(() => {
|
|
10
|
-
if (!
|
|
13
|
+
if (!slotData) {
|
|
11
14
|
return false;
|
|
12
15
|
}
|
|
13
|
-
switch (
|
|
14
|
-
case StreamComponentDataType.
|
|
15
|
-
return !!
|
|
16
|
+
switch (slotData.type) {
|
|
17
|
+
case StreamComponentDataType.Images: {
|
|
18
|
+
return !!slotData.items.length;
|
|
16
19
|
}
|
|
17
20
|
case StreamComponentDataType.Product: {
|
|
18
|
-
return !!
|
|
21
|
+
return !!slotData.product;
|
|
19
22
|
}
|
|
20
|
-
case StreamComponentDataType.
|
|
21
|
-
return !!
|
|
23
|
+
case StreamComponentDataType.Products: {
|
|
24
|
+
return !!slotData.products.length;
|
|
25
|
+
}
|
|
26
|
+
case StreamComponentDataType.ShortVideo: {
|
|
27
|
+
return !!slotData.shortVideo;
|
|
22
28
|
}
|
|
23
29
|
default:
|
|
24
|
-
Utils.assertUnreachable(
|
|
30
|
+
Utils.assertUnreachable(slotData);
|
|
25
31
|
}
|
|
26
32
|
});
|
|
27
33
|
const productModel = $derived.by(() => {
|
|
28
|
-
|
|
29
|
-
return ((_a = model.data) === null || _a === void 0 ? void 0 : _a.type) === StreamComponentDataType.Product ? model.data.product : undefined;
|
|
34
|
+
return (slotData === null || slotData === void 0 ? void 0 : slotData.type) === StreamComponentDataType.Product ? slotData.product : undefined;
|
|
30
35
|
});
|
|
31
36
|
const enrichedLink = $derived((productModel === null || productModel === void 0 ? void 0 : productModel.link)
|
|
32
37
|
? enrichProductLinkWithTracking({
|
|
@@ -71,9 +76,9 @@ const productLinkMounted = (node, productModel) => {
|
|
|
71
76
|
</script>
|
|
72
77
|
|
|
73
78
|
{#snippet slotContent()}
|
|
74
|
-
{#if component && (!
|
|
79
|
+
{#if component && (!slotData || dataIsFilled)}
|
|
75
80
|
{#each component.elements as element (element)}
|
|
76
|
-
<StreamElementView model={element} data={
|
|
81
|
+
<StreamElementView model={element} data={slotData} trackingParams={trackingParams} locale={locale} on={on} />
|
|
77
82
|
{/each}
|
|
78
83
|
{/if}
|
|
79
84
|
{/snippet}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">import { generateButtonStyles } from '../styles-transformer';
|
|
2
|
+
let { model, placeholder, inert = false } = $props();
|
|
3
|
+
const handleClick = () => {
|
|
4
|
+
if (model.url) {
|
|
5
|
+
window.open(model.url, '_blank', 'noopener noreferrer');
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<button type="button" class="button-stream-element" style={generateButtonStyles(model.styles)} onclick={handleClick} inert={inert}>
|
|
11
|
+
<span class="button-stream-element__text">
|
|
12
|
+
{#if model.text}
|
|
13
|
+
{model.text}
|
|
14
|
+
{:else if placeholder}
|
|
15
|
+
{@render placeholder()}
|
|
16
|
+
{/if}
|
|
17
|
+
</span>
|
|
18
|
+
</button>
|
|
19
|
+
|
|
20
|
+
<style>.button-stream-element__text {
|
|
21
|
+
min-width: 0;
|
|
22
|
+
max-width: 100%;
|
|
23
|
+
white-space: nowrap;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
text-overflow: ellipsis;
|
|
26
|
+
}</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ButtonStreamElementModel } from '../elements';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = {
|
|
4
|
+
model: ButtonStreamElementModel;
|
|
5
|
+
inert?: boolean;
|
|
6
|
+
placeholder?: Snippet;
|
|
7
|
+
};
|
|
8
|
+
declare const Cmp: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type Cmp = ReturnType<typeof Cmp>;
|
|
10
|
+
export default Cmp;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script lang="ts">import { horizontalWheelScroll } from '../../../core/actions';
|
|
2
|
+
import { StreamComponentDataType, StreamElementStyleDirection } from '../enums';
|
|
3
|
+
import { generateProductsSliderStyles } from '../styles-transformer';
|
|
4
|
+
import { default as StreamElement } from './cmp.stream-element.svelte';
|
|
5
|
+
let { model, data, trackingParams, locale } = $props();
|
|
6
|
+
const getProductDataByIndex = (index) => {
|
|
7
|
+
const products = (data === null || data === void 0 ? void 0 : data.type) === StreamComponentDataType.Products ? data.products : [];
|
|
8
|
+
const product = products[index];
|
|
9
|
+
if (!product) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
type: StreamComponentDataType.Product,
|
|
14
|
+
id: product.id,
|
|
15
|
+
product: product
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<div class="products-slider-stream-element" style={generateProductsSliderStyles(model.styles)} use:horizontalWheelScroll>
|
|
21
|
+
{#each model.items as item, index (item)}
|
|
22
|
+
<div class="products-slider-stream-element__item">
|
|
23
|
+
{#each item.elements as element (element)}
|
|
24
|
+
{@const productData = getProductDataByIndex(index)}
|
|
25
|
+
<StreamElement
|
|
26
|
+
model={element}
|
|
27
|
+
data={productData}
|
|
28
|
+
trackingParams={trackingParams}
|
|
29
|
+
constainerDirection={StreamElementStyleDirection.Vertical}
|
|
30
|
+
locale={locale} />
|
|
31
|
+
{/each}
|
|
32
|
+
</div>
|
|
33
|
+
{/each}
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<style>.products-slider-stream-element {
|
|
37
|
+
overscroll-behavior-x: contain;
|
|
38
|
+
scroll-snap-type: x proximity;
|
|
39
|
+
}
|
|
40
|
+
.products-slider-stream-element__item {
|
|
41
|
+
scroll-snap-align: start;
|
|
42
|
+
flex-shrink: 0;
|
|
43
|
+
}</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Locale } from '../../../core/locale';
|
|
2
|
+
import type { StreamTrackingParams } from '..';
|
|
3
|
+
import type { ProductsSliderStreamElementModel } from '../elements';
|
|
4
|
+
import type { StreamSlotData } from '../slot-data';
|
|
5
|
+
type Props = {
|
|
6
|
+
model: ProductsSliderStreamElementModel;
|
|
7
|
+
data: StreamSlotData | null;
|
|
8
|
+
trackingParams: StreamTrackingParams;
|
|
9
|
+
locale: Locale;
|
|
10
|
+
};
|
|
11
|
+
declare const Cmp: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type Cmp = ReturnType<typeof Cmp>;
|
|
13
|
+
export default Cmp;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
<script lang="ts">import { AnnotationStreamElementView, ContainerStreamElementView, ImageRefStreamElementView, ImagesStreamElementView, PriceStreamElementView, ShortVideoStreamElementView, SpacerStreamElementView, StockStreamElementView, TextRefStreamElementView, TextStreamElementView, WebViewStreamElementView } from '.';
|
|
2
|
-
import { StreamElementLocalization } from './stream-element-localization';
|
|
1
|
+
<script lang="ts">import { AnnotationStreamElementView, ButtonStreamElementView, ContainerStreamElementView, ImageRefStreamElementView, ImagesStreamElementView, PriceStreamElementView, ProductsSliderStreamElementView, ShortVideoStreamElementView, SpacerStreamElementView, StockStreamElementView, TextRefStreamElementView, TextStreamElementView, WebViewStreamElementView } from '.';
|
|
3
2
|
import { StreamComponentDataType, StreamElementStyleDirection, StreamElementType } from '../enums';
|
|
4
3
|
let { model, data, trackingParams, constainerDirection = StreamElementStyleDirection.Vertical, locale, on } = $props();
|
|
5
|
-
const localization = $derived(new StreamElementLocalization(locale));
|
|
6
4
|
const shortVideoModel = $derived.by(() => {
|
|
7
5
|
if (!data) {
|
|
8
6
|
return null;
|
|
@@ -43,6 +41,8 @@ const productModel = $derived.by(() => {
|
|
|
43
41
|
|
|
44
42
|
{#if model.type === StreamElementType.Annotation}
|
|
45
43
|
<AnnotationStreamElementView model={model} />
|
|
44
|
+
{:else if model.type === StreamElementType.Button}
|
|
45
|
+
<ButtonStreamElementView model={model} />
|
|
46
46
|
{:else if model.type === StreamElementType.Container}
|
|
47
47
|
<ContainerStreamElementView model={model} data={data} trackingParams={trackingParams} locale={locale} />
|
|
48
48
|
{:else if model.type === StreamElementType.ImageRef && data}
|
|
@@ -50,12 +50,14 @@ const productModel = $derived.by(() => {
|
|
|
50
50
|
{:else if model.type === StreamElementType.Images && imagesModel?.length}
|
|
51
51
|
<ImagesStreamElementView model={model} data={imagesModel} />
|
|
52
52
|
{:else if model.type === StreamElementType.Price && productModel}
|
|
53
|
-
<PriceStreamElementView model={model} data={productModel.price} locale={
|
|
53
|
+
<PriceStreamElementView model={model} data={productModel.price} locale={locale} />
|
|
54
|
+
{:else if model.type === StreamElementType.ProductsSlider}
|
|
55
|
+
<ProductsSliderStreamElementView model={model} data={data} trackingParams={trackingParams} locale={locale} />
|
|
54
56
|
{:else if model.type === StreamElementType.ShortVideo && shortVideoModel}
|
|
55
57
|
<ShortVideoStreamElementView
|
|
56
58
|
data={shortVideoModel}
|
|
57
59
|
trackingParams={trackingParams}
|
|
58
|
-
locale={
|
|
60
|
+
locale={locale}
|
|
59
61
|
on={on
|
|
60
62
|
? {
|
|
61
63
|
progress: (progress: Number) => {
|
|
@@ -66,7 +68,7 @@ const productModel = $derived.by(() => {
|
|
|
66
68
|
{:else if model.type === StreamElementType.Spacer}
|
|
67
69
|
<SpacerStreamElementView model={model} parentContainerDirection={constainerDirection} />
|
|
68
70
|
{:else if model.type === StreamElementType.Stock}
|
|
69
|
-
<StockStreamElementView model={model} locale={
|
|
71
|
+
<StockStreamElementView model={model} locale={locale} />
|
|
70
72
|
{:else if model.type === StreamElementType.Text}
|
|
71
73
|
<TextStreamElementView model={model} />
|
|
72
74
|
{:else if model.type === StreamElementType.TextRef && data}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { default as StreamElementView } from './cmp.stream-element.svelte';
|
|
2
2
|
export { default as AnnotationStreamElementView } from './cmp.annotation-stream-element.svelte';
|
|
3
|
+
export { default as ButtonStreamElementView } from './cmp.button-stream-element.svelte';
|
|
3
4
|
export { default as ContainerStreamElementView } from './cmp.container-stream-element.svelte';
|
|
4
5
|
export { default as ImageRefStreamElementView } from './cmp.image-ref-stream-element.svelte';
|
|
5
6
|
export { default as ImagesStreamElementView } from './cmp.images-stream-element.svelte';
|
|
6
7
|
export { default as PriceStreamElementView } from './cmp.price-stream-element.svelte';
|
|
8
|
+
export { default as ProductsSliderStreamElementView } from './cmp.products-slider-stream-element.svelte';
|
|
7
9
|
export { default as ShortVideoStreamElementView } from './cmp.short-video-stream-element.svelte';
|
|
8
10
|
export { default as SpacerStreamElementView } from './cmp.spacer-stream-element.svelte';
|
|
9
11
|
export { default as StockStreamElementView } from './cmp.stock-stream-element.svelte';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { default as StreamElementView } from './cmp.stream-element.svelte';
|
|
2
2
|
export { default as AnnotationStreamElementView } from './cmp.annotation-stream-element.svelte';
|
|
3
|
+
export { default as ButtonStreamElementView } from './cmp.button-stream-element.svelte';
|
|
3
4
|
export { default as ContainerStreamElementView } from './cmp.container-stream-element.svelte';
|
|
4
5
|
export { default as ImageRefStreamElementView } from './cmp.image-ref-stream-element.svelte';
|
|
5
6
|
export { default as ImagesStreamElementView } from './cmp.images-stream-element.svelte';
|
|
6
7
|
export { default as PriceStreamElementView } from './cmp.price-stream-element.svelte';
|
|
8
|
+
export { default as ProductsSliderStreamElementView } from './cmp.products-slider-stream-element.svelte';
|
|
7
9
|
export { default as ShortVideoStreamElementView } from './cmp.short-video-stream-element.svelte';
|
|
8
10
|
export { default as SpacerStreamElementView } from './cmp.spacer-stream-element.svelte';
|
|
9
11
|
export { default as StockStreamElementView } from './cmp.stock-stream-element.svelte';
|
|
@@ -102,6 +102,9 @@ const adjustHeightToFit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
102
102
|
while (currentHeight > minElementHeight) {
|
|
103
103
|
adjustedHeight = currentHeight;
|
|
104
104
|
yield new Promise((resolve) => requestAnimationFrame(resolve));
|
|
105
|
+
if (!priceContainerRef || !priceElementRef || !adjustableHeight) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
105
108
|
let hasOverflow = priceElementRef.clientWidth < priceContainerRef.clientWidth;
|
|
106
109
|
if (!hasOverflow) {
|
|
107
110
|
break;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StreamElementType, ImagesStreamElementMode, AnnotationStreamElementPlacement, StockStreamElementLevel } from './enums';
|
|
2
|
-
import type { ImageStreamElementStyles, TextStreamElementStyles, ContainerStreamElementStyles, PriceStreamElementStyles, AnnotationStreamElementStyles, StockStreamElementStyles } from './styles';
|
|
3
|
-
export type StreamElementModel = AnnotationStreamElementModel | ContainerStreamElementModel | ImageRefStreamElementModel | ImagesStreamElementModel | PriceStreamElementModel | ShortVideoStreamElementModel | SpacerStreamElementModel | StockStreamElementModel | TextStreamElementModel | TextRefStreamElementModel | WebViewStreamElementModel;
|
|
2
|
+
import type { ImageStreamElementStyles, TextStreamElementStyles, ContainerStreamElementStyles, PriceStreamElementStyles, AnnotationStreamElementStyles, StockStreamElementStyles, ProductsSliderStreamElementStyles, ButtonStreamElementStyles } from './styles';
|
|
3
|
+
export type StreamElementModel = AnnotationStreamElementModel | ButtonStreamElementModel | ContainerStreamElementModel | ImageRefStreamElementModel | ImagesStreamElementModel | PriceStreamElementModel | ProductsSliderStreamElementModel | ShortVideoStreamElementModel | SpacerStreamElementModel | StockStreamElementModel | TextStreamElementModel | TextRefStreamElementModel | WebViewStreamElementModel;
|
|
4
4
|
export type AnnotationStreamElementModel = {
|
|
5
5
|
type: StreamElementType.Annotation;
|
|
6
6
|
$id: string;
|
|
@@ -10,6 +10,14 @@ export type AnnotationStreamElementModel = {
|
|
|
10
10
|
placement: AnnotationStreamElementPlacement;
|
|
11
11
|
styles: AnnotationStreamElementStyles;
|
|
12
12
|
};
|
|
13
|
+
export type ButtonStreamElementModel = {
|
|
14
|
+
type: StreamElementType.Button;
|
|
15
|
+
$id: string;
|
|
16
|
+
name?: string | null;
|
|
17
|
+
text: string | null;
|
|
18
|
+
url: string | null;
|
|
19
|
+
styles: ButtonStreamElementStyles | null;
|
|
20
|
+
};
|
|
13
21
|
export type ContainerStreamElementModel = {
|
|
14
22
|
type: StreamElementType.Container;
|
|
15
23
|
$id: string;
|
|
@@ -42,6 +50,16 @@ export type PriceStreamElementModel = {
|
|
|
42
50
|
stock?: StockStreamElementModel | null;
|
|
43
51
|
styles: PriceStreamElementStyles | null;
|
|
44
52
|
};
|
|
53
|
+
export type ProductsSliderStreamElementModel = {
|
|
54
|
+
type: StreamElementType.ProductsSlider;
|
|
55
|
+
$id: string;
|
|
56
|
+
name?: string | null;
|
|
57
|
+
template: StreamElementModel[];
|
|
58
|
+
items: {
|
|
59
|
+
elements: StreamElementModel[];
|
|
60
|
+
}[];
|
|
61
|
+
styles: ProductsSliderStreamElementStyles | null;
|
|
62
|
+
};
|
|
45
63
|
export type ShortVideoStreamElementModel = {
|
|
46
64
|
type: StreamElementType.ShortVideo;
|
|
47
65
|
$id: string;
|
|
@@ -2,14 +2,17 @@ export declare enum StreamComponentDataType {
|
|
|
2
2
|
Images = "IMAGES",
|
|
3
3
|
NoData = "NO_DATA",
|
|
4
4
|
ShortVideo = "SHORT_VIDEO",
|
|
5
|
-
Product = "PRODUCT"
|
|
5
|
+
Product = "PRODUCT",
|
|
6
|
+
Products = "PRODUCTS"
|
|
6
7
|
}
|
|
7
8
|
export declare enum StreamElementType {
|
|
8
9
|
Annotation = "ANNOTATION",
|
|
10
|
+
Button = "BUTTON",
|
|
9
11
|
Container = "CONTAINER",
|
|
10
12
|
ImageRef = "IMAGE_REF",
|
|
11
13
|
Images = "IMAGES",
|
|
12
14
|
Price = "PRICE",
|
|
15
|
+
ProductsSlider = "PRODUCTS_SLIDER",
|
|
13
16
|
ShortVideo = "SHORT_VIDEO",
|
|
14
17
|
Spacer = "SPACER",
|
|
15
18
|
Stock = "STOCK",
|
|
@@ -4,14 +4,17 @@ export var StreamComponentDataType;
|
|
|
4
4
|
StreamComponentDataType["NoData"] = "NO_DATA";
|
|
5
5
|
StreamComponentDataType["ShortVideo"] = "SHORT_VIDEO";
|
|
6
6
|
StreamComponentDataType["Product"] = "PRODUCT";
|
|
7
|
+
StreamComponentDataType["Products"] = "PRODUCTS";
|
|
7
8
|
})(StreamComponentDataType || (StreamComponentDataType = {}));
|
|
8
9
|
export var StreamElementType;
|
|
9
10
|
(function (StreamElementType) {
|
|
10
11
|
StreamElementType["Annotation"] = "ANNOTATION";
|
|
12
|
+
StreamElementType["Button"] = "BUTTON";
|
|
11
13
|
StreamElementType["Container"] = "CONTAINER";
|
|
12
14
|
StreamElementType["ImageRef"] = "IMAGE_REF";
|
|
13
15
|
StreamElementType["Images"] = "IMAGES";
|
|
14
16
|
StreamElementType["Price"] = "PRICE";
|
|
17
|
+
StreamElementType["ProductsSlider"] = "PRODUCTS_SLIDER";
|
|
15
18
|
StreamElementType["ShortVideo"] = "SHORT_VIDEO";
|
|
16
19
|
StreamElementType["Spacer"] = "SPACER";
|
|
17
20
|
StreamElementType["Stock"] = "STOCK";
|
|
@@ -10,4 +10,5 @@ export * from './svg-attributes';
|
|
|
10
10
|
export type { StreamTrackingParams } from './types';
|
|
11
11
|
export { parseToStreamLayout, parseToStreamLayoutTemplate, stringifyToStreamLayoutInput, IdPopulator } from './serializer.svelte';
|
|
12
12
|
export declare const getAllowedDataTypesForSlot: (slot: StreamSlot) => StreamComponentDataType[];
|
|
13
|
+
export declare const slotAcceptsDataOfType: (slot: StreamSlot, dataType: StreamComponentDataType) => boolean;
|
|
13
14
|
export declare const getSingleShortVideoFromLayout: (layout: StreamLayout) => StreamLayoutShortVideoModel | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Utils } from '../../core/utils';
|
|
1
2
|
import { StreamComponentDataType } from './enums';
|
|
2
3
|
export { default as StreamPageLayout } from './cmp.layout.svelte';
|
|
3
4
|
export { default as StreamLayoutSlot } from './cmp.slot.svelte';
|
|
@@ -8,6 +9,20 @@ export { parseToStreamLayout, parseToStreamLayoutTemplate, stringifyToStreamLayo
|
|
|
8
9
|
export const getAllowedDataTypesForSlot = (slot) => {
|
|
9
10
|
return slot.components.flatMap((c) => c.dataType);
|
|
10
11
|
};
|
|
12
|
+
export const slotAcceptsDataOfType = (slot, dataType) => {
|
|
13
|
+
const allowedDataTypesForSlot = getAllowedDataTypesForSlot(slot);
|
|
14
|
+
switch (dataType) {
|
|
15
|
+
case StreamComponentDataType.Images:
|
|
16
|
+
case StreamComponentDataType.NoData:
|
|
17
|
+
case StreamComponentDataType.Products:
|
|
18
|
+
case StreamComponentDataType.ShortVideo:
|
|
19
|
+
return allowedDataTypesForSlot.includes(dataType);
|
|
20
|
+
case StreamComponentDataType.Product:
|
|
21
|
+
return allowedDataTypesForSlot.includes(StreamComponentDataType.Product) || allowedDataTypesForSlot.includes(StreamComponentDataType.Products);
|
|
22
|
+
default:
|
|
23
|
+
Utils.assertUnreachable(dataType);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
11
26
|
export const getSingleShortVideoFromLayout = (layout) => {
|
|
12
27
|
if (layout.slots.length === 1 && layout.slots[0].data?.type === StreamComponentDataType.ShortVideo && layout.slots[0].data.shortVideo) {
|
|
13
28
|
return layout.slots[0].data.shortVideo;
|
|
@@ -31,28 +31,47 @@ export const stringifyToStreamLayoutInput = (layout) => {
|
|
|
31
31
|
// @ts-expect-error - clearing local data before sending to the server
|
|
32
32
|
delete data.items;
|
|
33
33
|
break;
|
|
34
|
-
case StreamComponentDataType.ShortVideo:
|
|
35
|
-
// @ts-expect-error - clearing local data before sending to the server
|
|
36
|
-
delete data.shortVideo;
|
|
37
|
-
break;
|
|
38
34
|
case StreamComponentDataType.Product:
|
|
39
35
|
// @ts-expect-error - clearing local data before sending to the server
|
|
40
36
|
delete data.product;
|
|
41
37
|
break;
|
|
38
|
+
case StreamComponentDataType.Products:
|
|
39
|
+
// @ts-expect-error - clearing local data before sending to the server
|
|
40
|
+
delete data.products;
|
|
41
|
+
break;
|
|
42
|
+
case StreamComponentDataType.ShortVideo:
|
|
43
|
+
// @ts-expect-error - clearing local data before sending to the server
|
|
44
|
+
delete data.shortVideo;
|
|
45
|
+
break;
|
|
42
46
|
default:
|
|
43
47
|
Utils.assertUnreachable(data);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
|
-
return JSON.stringify(clone);
|
|
52
|
+
return JSON.stringify(clone, removeNullishReplacer);
|
|
49
53
|
};
|
|
54
|
+
function removeNullishReplacer(key, value) {
|
|
55
|
+
if (key === '') {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
if (value === null || value === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
50
63
|
const removeElementIdRecursive = (element) => {
|
|
51
64
|
// @ts-expect-error - clearing local data before sending to the server
|
|
52
65
|
delete element.$id;
|
|
53
66
|
if (element.type === StreamElementType.Container && Array.isArray(element.elements)) {
|
|
54
67
|
element.elements.forEach(removeElementIdRecursive);
|
|
55
68
|
}
|
|
69
|
+
if (element.type === StreamElementType.ProductsSlider) {
|
|
70
|
+
element.template.forEach(removeElementIdRecursive);
|
|
71
|
+
if (Array.isArray(element.items)) {
|
|
72
|
+
element.items.flatMap((i) => i.elements).forEach(removeElementIdRecursive);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
56
75
|
if (element.type === StreamElementType.ImageRef && Array.isArray(element.annotations)) {
|
|
57
76
|
element.annotations.forEach((annotation) => {
|
|
58
77
|
// @ts-expect-error - clearing local data before sending to the server
|
|
@@ -82,6 +101,12 @@ export class IdPopulator {
|
|
|
82
101
|
if (element.type === StreamElementType.Container && element.elements) {
|
|
83
102
|
element.elements.forEach((element) => IdPopulator.populateElementId(element));
|
|
84
103
|
}
|
|
104
|
+
if (element.type === StreamElementType.ProductsSlider) {
|
|
105
|
+
element.template.forEach((element) => IdPopulator.populateElementId(element));
|
|
106
|
+
if (element.items) {
|
|
107
|
+
element.items.flatMap((i) => i.elements).forEach((element) => IdPopulator.populateElementId(element));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
85
110
|
if (element.type === StreamElementType.ImageRef && element.annotations) {
|
|
86
111
|
element.annotations.forEach((element) => IdPopulator.populateElementId(element));
|
|
87
112
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StreamComponentDataType } from './enums';
|
|
2
|
-
export type StreamSlotDataInput = ImagesStreamSlotDataInput | ProductStreamSlotDataInput | ShortVideoStreamSlotDataInput;
|
|
2
|
+
export type StreamSlotDataInput = ImagesStreamSlotDataInput | ProductStreamSlotDataInput | ProductsStreamSlotDataInput | ShortVideoStreamSlotDataInput;
|
|
3
3
|
export interface ImagesStreamSlotDataInput {
|
|
4
4
|
type: StreamComponentDataType.Images;
|
|
5
5
|
ids: string[];
|
|
@@ -8,6 +8,10 @@ export interface ProductStreamSlotDataInput {
|
|
|
8
8
|
type: StreamComponentDataType.Product;
|
|
9
9
|
id: string;
|
|
10
10
|
}
|
|
11
|
+
export interface ProductsStreamSlotDataInput {
|
|
12
|
+
type: StreamComponentDataType.Products;
|
|
13
|
+
ids: string[];
|
|
14
|
+
}
|
|
11
15
|
export interface ShortVideoStreamSlotDataInput {
|
|
12
16
|
type: StreamComponentDataType.ShortVideo;
|
|
13
17
|
id: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ImagesStreamSlotData, ProductStreamSlotData, ShortVideoStreamSlotData } from './slot-data';
|
|
2
|
-
export type StreamSlotDataRef = Partial<Pick<ImagesStreamSlotData, 'items'>> & Partial<Pick<ProductStreamSlotData, 'product'>> & Partial<Pick<ShortVideoStreamSlotData, 'shortVideo'>>;
|
|
1
|
+
import type { ImagesStreamSlotData, ProductsStreamSlotData, ProductStreamSlotData, ShortVideoStreamSlotData } from './slot-data';
|
|
2
|
+
export type StreamSlotDataRef = Partial<Pick<ImagesStreamSlotData, 'items'>> & Partial<Pick<ProductStreamSlotData, 'product'>> & Partial<Pick<ProductsStreamSlotData, 'products'>> & Partial<Pick<ShortVideoStreamSlotData, 'shortVideo'>>;
|
|
3
3
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
|
|
4
4
|
type Join<K, P> = K extends string | number ? (P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never) : never;
|
|
5
5
|
type IsPrimitive<T> = T extends string | number | boolean | null | undefined ? true : false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StreamComponentDataType } from './enums';
|
|
2
2
|
import type { StreamLayoutBlobModel, StreamLayoutProductModel, StreamLayoutShortVideoModel } from './models';
|
|
3
|
-
export type StreamSlotData = ImagesStreamSlotData | ProductStreamSlotData | ShortVideoStreamSlotData;
|
|
3
|
+
export type StreamSlotData = ImagesStreamSlotData | ProductStreamSlotData | ProductsStreamSlotData | ShortVideoStreamSlotData;
|
|
4
4
|
export type ImagesStreamSlotData = {
|
|
5
5
|
type: StreamComponentDataType.Images;
|
|
6
6
|
ids: string[];
|
|
@@ -11,6 +11,11 @@ export type ProductStreamSlotData = {
|
|
|
11
11
|
id: string;
|
|
12
12
|
product: StreamLayoutProductModel | null;
|
|
13
13
|
};
|
|
14
|
+
export type ProductsStreamSlotData = {
|
|
15
|
+
type: StreamComponentDataType.Products;
|
|
16
|
+
ids: string[];
|
|
17
|
+
products: StreamLayoutProductModel[];
|
|
18
|
+
};
|
|
14
19
|
export type ShortVideoStreamSlotData = {
|
|
15
20
|
type: StreamComponentDataType.ShortVideo;
|
|
16
21
|
id: string;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { StreamElementStyleFontFamily, StreamElementStyleFontWeight, StreamElementStyleHorizontalAlign, AnnotationStreamElementPlacement } from './enums';
|
|
2
|
-
import type { AnnotationStreamElementStyles, ContainerStreamElementStyles, ImageStreamElementStyles, StreamLayoutStyles, TextStreamElementStyles } from './styles';
|
|
2
|
+
import type { AnnotationStreamElementStyles, ButtonStreamElementStyles, ContainerStreamElementStyles, ImageStreamElementStyles, ProductsSliderStreamElementStyles, StreamLayoutStyles, TextStreamElementStyles } from './styles';
|
|
3
3
|
export declare const generateStreamLayoutStyles: (styles: StreamLayoutStyles | null) => string;
|
|
4
4
|
export declare const generateContainerStyles: (styles: Partial<ContainerStreamElementStyles> | null) => string;
|
|
5
|
+
export declare const generateButtonStyles: (styles: Partial<ButtonStreamElementStyles> | null) => string;
|
|
5
6
|
export declare const generateAnnotationStyles: (styles: AnnotationStreamElementStyles, placement: AnnotationStreamElementPlacement) => string;
|
|
7
|
+
export declare const generateProductsSliderStyles: (styles: Partial<ProductsSliderStreamElementStyles> | null) => string;
|
|
6
8
|
export declare const generateTextStyles: (styles: Partial<TextStreamElementStyles> | null) => string;
|
|
7
9
|
export declare const generateImageStyles: (styles: Partial<ImageStreamElementStyles> | null) => string;
|
|
8
10
|
export declare const mapFontFamily: (value: StreamElementStyleFontFamily | null | undefined) => string;
|
|
@@ -32,6 +32,32 @@ export const generateContainerStyles = (styles) => {
|
|
|
32
32
|
}
|
|
33
33
|
return values.join(';');
|
|
34
34
|
};
|
|
35
|
+
export const generateButtonStyles = (styles) => {
|
|
36
|
+
styles = styles || {};
|
|
37
|
+
const values = [
|
|
38
|
+
'display: flex',
|
|
39
|
+
`justify-content: ${mapFlexJustifyContent(styles.textAlign)}`,
|
|
40
|
+
`text-align: ${mapTextAlign(styles.textAlign)}`,
|
|
41
|
+
`align-items: center`,
|
|
42
|
+
`min-width: ${transformNumericValue(styles.minWidth, '0')}`,
|
|
43
|
+
`max-width: ${transformNumericValue(styles.maxWidth, '100%')}`,
|
|
44
|
+
`height: ${transformNumericValue(styles.height, 'fit-content')}`,
|
|
45
|
+
`font-family: ${mapFontFamily(styles.fontFamily)}`,
|
|
46
|
+
`font-size: ${transformFontSizeValue(styles.fontSize)}`,
|
|
47
|
+
`font-weight: ${mapFontWeight(styles.fontWeight)}`,
|
|
48
|
+
`padding-top: ${transformNumericValue(styles.paddingTop)}`,
|
|
49
|
+
`padding-right: ${transformNumericValue(styles.paddingRight)}`,
|
|
50
|
+
`padding-bottom: ${transformNumericValue(styles.paddingBottom)}`,
|
|
51
|
+
`padding-left: ${transformNumericValue(styles.paddingLeft)}`,
|
|
52
|
+
`color: ${transformColorValue(styles.textColor)}`,
|
|
53
|
+
`background-color: ${transformColorValue(styles.backgroundColor)}`,
|
|
54
|
+
`border-width: ${styles.borderColor ? '1px' : '0'}`,
|
|
55
|
+
`border-radius: ${transformNumericValue(styles.borderRadius)}`,
|
|
56
|
+
`border-color: ${transformColorValue(styles.borderColor)}`,
|
|
57
|
+
`overflow: hidden`
|
|
58
|
+
];
|
|
59
|
+
return values.join(';');
|
|
60
|
+
};
|
|
35
61
|
export const generateAnnotationStyles = (styles, placement) => {
|
|
36
62
|
const values = [`height: ${transformNumericValue(styles.height)}`, `aspect-ratio: ${styles.aspectRatio}`, 'position: absolute'];
|
|
37
63
|
switch (placement) {
|
|
@@ -56,6 +82,27 @@ export const generateAnnotationStyles = (styles, placement) => {
|
|
|
56
82
|
}
|
|
57
83
|
return values.join(';');
|
|
58
84
|
};
|
|
85
|
+
export const generateProductsSliderStyles = (styles) => {
|
|
86
|
+
styles = styles || {};
|
|
87
|
+
const values = [
|
|
88
|
+
'display: flex',
|
|
89
|
+
'flex-direction: row',
|
|
90
|
+
`width: 100%`,
|
|
91
|
+
`height: 100%`,
|
|
92
|
+
`gap: ${transformNumericValue(styles.gap)}`,
|
|
93
|
+
`padding-top: ${transformNumericValue(styles.paddingTop)}`,
|
|
94
|
+
`padding-right: ${transformNumericValue(styles.paddingRight)}`,
|
|
95
|
+
`padding-bottom: ${transformNumericValue(styles.paddingBottom)}`,
|
|
96
|
+
`padding-left: ${transformNumericValue(styles.paddingLeft)}`,
|
|
97
|
+
`background-color: ${transformColorValue(styles.backgroundColor)}`,
|
|
98
|
+
`overflow-x: auto`,
|
|
99
|
+
`overflow-y: hidden`,
|
|
100
|
+
`scrollbar-width: none`,
|
|
101
|
+
`scroll-padding-left: ${transformNumericValue(styles.paddingLeft)}`,
|
|
102
|
+
`scroll-padding-right: ${transformNumericValue(styles.paddingRight)}`
|
|
103
|
+
];
|
|
104
|
+
return values.join(';');
|
|
105
|
+
};
|
|
59
106
|
export const generateTextStyles = (styles) => {
|
|
60
107
|
styles = styles || {};
|
|
61
108
|
const values = [
|
|
@@ -10,6 +10,23 @@ export type AnnotationStreamElementStyles = {
|
|
|
10
10
|
offsetX: number;
|
|
11
11
|
offsetY: number;
|
|
12
12
|
};
|
|
13
|
+
export type ButtonStreamElementStyles = {
|
|
14
|
+
minWidth?: number | null;
|
|
15
|
+
maxWidth?: number | null;
|
|
16
|
+
height?: number | null;
|
|
17
|
+
fontSize?: number | null;
|
|
18
|
+
fontWeight?: StreamElementStyleFontWeight | null;
|
|
19
|
+
fontFamily?: StreamElementStyleFontFamily | null;
|
|
20
|
+
textAlign?: StreamElementStyleHorizontalAlign | null;
|
|
21
|
+
paddingTop?: number | null;
|
|
22
|
+
paddingRight?: number | null;
|
|
23
|
+
paddingBottom?: number | null;
|
|
24
|
+
paddingLeft?: number | null;
|
|
25
|
+
textColor?: string | null;
|
|
26
|
+
backgroundColor?: string | null;
|
|
27
|
+
borderRadius?: number | null;
|
|
28
|
+
borderColor?: string | null;
|
|
29
|
+
};
|
|
13
30
|
export type ContainerStreamElementStyles = {
|
|
14
31
|
width?: StreamCssValue | null;
|
|
15
32
|
height?: StreamCssValue | null;
|
|
@@ -38,6 +55,14 @@ export type PriceStreamElementStyles = {
|
|
|
38
55
|
beforeValueColor?: string | null;
|
|
39
56
|
horizontalAlign?: StreamElementStyleHorizontalAlign | null;
|
|
40
57
|
};
|
|
58
|
+
export type ProductsSliderStreamElementStyles = {
|
|
59
|
+
gap?: number;
|
|
60
|
+
paddingTop?: number | null;
|
|
61
|
+
paddingBottom?: number | null;
|
|
62
|
+
paddingLeft?: number | null;
|
|
63
|
+
paddingRight?: number | null;
|
|
64
|
+
backgroundColor?: string | null;
|
|
65
|
+
};
|
|
41
66
|
export type StockStreamElementStyles = {
|
|
42
67
|
height?: number | null;
|
|
43
68
|
horizontalAlign?: StreamElementStyleHorizontalAlign | null;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import type { AnnotationStreamElementModel, ContainerStreamElementModel, ImageRefStreamElementModel, ImagesStreamElementModel, PriceStreamElementModel, ShortVideoStreamElementModel, SpacerStreamElementModel, StockStreamElementModel, TextRefStreamElementModel, TextStreamElementModel, WebViewStreamElementModel } from './elements';
|
|
1
|
+
import type { AnnotationStreamElementModel, ButtonStreamElementModel, ContainerStreamElementModel, ImageRefStreamElementModel, ImagesStreamElementModel, PriceStreamElementModel, ProductsSliderStreamElementModel, ShortVideoStreamElementModel, SpacerStreamElementModel, StockStreamElementModel, TextRefStreamElementModel, TextStreamElementModel, WebViewStreamElementModel } from './elements';
|
|
2
2
|
import { StreamElementType } from './enums';
|
|
3
|
-
import type { ImagesStreamSlotData, ProductStreamSlotData, ShortVideoStreamSlotData, StreamSlotData } from './slot-data';
|
|
4
|
-
import type { ImagesStreamSlotDataInput, ProductStreamSlotDataInput, ShortVideoStreamSlotDataInput, StreamSlotDataInput } from './slot-data-input';
|
|
5
|
-
import type { AnnotationStreamElementStyles, ContainerStreamElementStyles, ImageStreamElementStyles, PriceStreamElementStyles, StockStreamElementStyles, TextStreamElementStyles } from './styles';
|
|
3
|
+
import type { ImagesStreamSlotData, ProductsStreamSlotData, ProductStreamSlotData, ShortVideoStreamSlotData, StreamSlotData } from './slot-data';
|
|
4
|
+
import type { ImagesStreamSlotDataInput, ProductsStreamSlotDataInput, ProductStreamSlotDataInput, ShortVideoStreamSlotDataInput, StreamSlotDataInput } from './slot-data-input';
|
|
5
|
+
import type { AnnotationStreamElementStyles, ButtonStreamElementStyles, ContainerStreamElementStyles, ImageStreamElementStyles, PriceStreamElementStyles, ProductsSliderStreamElementStyles, StockStreamElementStyles, TextStreamElementStyles } from './styles';
|
|
6
6
|
export declare function isImagesSlotDataInput(data: StreamSlotDataInput | null): data is ImagesStreamSlotDataInput;
|
|
7
7
|
export declare function isProductSlotDataInput(data: StreamSlotDataInput | null): data is ProductStreamSlotDataInput;
|
|
8
|
+
export declare function isProductsSlotDataInput(data: StreamSlotDataInput | null): data is ProductsStreamSlotDataInput;
|
|
8
9
|
export declare function isShortVideoSlotDataInput(data: StreamSlotDataInput | null): data is ShortVideoStreamSlotDataInput;
|
|
9
10
|
export declare function isImagesSlotData(data: StreamSlotData | null): data is ImagesStreamSlotData;
|
|
10
11
|
export declare function isProductSlotData(data: StreamSlotData | null): data is ProductStreamSlotData;
|
|
12
|
+
export declare function isProductsSlotData(data: StreamSlotData | null): data is ProductsStreamSlotData;
|
|
11
13
|
export declare function isShortVideoSlotData(data: StreamSlotData | null): data is ShortVideoStreamSlotData;
|
|
12
14
|
export type ElementTypeToStylesMap = {
|
|
13
15
|
[StreamElementType.Annotation]: AnnotationStreamElementStyles;
|
|
16
|
+
[StreamElementType.Button]: ButtonStreamElementStyles;
|
|
14
17
|
[StreamElementType.Container]: ContainerStreamElementStyles;
|
|
15
18
|
[StreamElementType.Price]: PriceStreamElementStyles;
|
|
19
|
+
[StreamElementType.ProductsSlider]: ProductsSliderStreamElementStyles;
|
|
16
20
|
[StreamElementType.ImageRef]: ImageStreamElementStyles;
|
|
17
21
|
[StreamElementType.Stock]: StockStreamElementStyles;
|
|
18
22
|
[StreamElementType.Text]: TextStreamElementStyles;
|
|
@@ -20,10 +24,12 @@ export type ElementTypeToStylesMap = {
|
|
|
20
24
|
};
|
|
21
25
|
export type ElementTypeToModelMap = {
|
|
22
26
|
[StreamElementType.Annotation]: AnnotationStreamElementModel;
|
|
27
|
+
[StreamElementType.Button]: ButtonStreamElementModel;
|
|
23
28
|
[StreamElementType.Container]: ContainerStreamElementModel;
|
|
24
29
|
[StreamElementType.ImageRef]: ImageRefStreamElementModel;
|
|
25
30
|
[StreamElementType.Images]: ImagesStreamElementModel;
|
|
26
31
|
[StreamElementType.Price]: PriceStreamElementModel;
|
|
32
|
+
[StreamElementType.ProductsSlider]: ProductsSliderStreamElementModel;
|
|
27
33
|
[StreamElementType.ShortVideo]: ShortVideoStreamElementModel;
|
|
28
34
|
[StreamElementType.Spacer]: SpacerStreamElementModel;
|
|
29
35
|
[StreamElementType.Stock]: StockStreamElementModel;
|
|
@@ -34,6 +40,7 @@ export type ElementTypeToModelMap = {
|
|
|
34
40
|
export declare const NotAllowedElementTypesForComponent: {
|
|
35
41
|
IMAGES: StreamElementType[];
|
|
36
42
|
PRODUCT: StreamElementType[];
|
|
43
|
+
PRODUCTS: StreamElementType[];
|
|
37
44
|
SHORT_VIDEO: StreamElementType[];
|
|
38
45
|
NO_DATA: StreamElementType[];
|
|
39
46
|
};
|
|
@@ -6,6 +6,9 @@ export function isImagesSlotDataInput(data) {
|
|
|
6
6
|
export function isProductSlotDataInput(data) {
|
|
7
7
|
return data?.type === StreamComponentDataType.Product;
|
|
8
8
|
}
|
|
9
|
+
export function isProductsSlotDataInput(data) {
|
|
10
|
+
return data?.type === StreamComponentDataType.Products;
|
|
11
|
+
}
|
|
9
12
|
export function isShortVideoSlotDataInput(data) {
|
|
10
13
|
return data?.type === StreamComponentDataType.ShortVideo;
|
|
11
14
|
}
|
|
@@ -16,17 +19,28 @@ export function isImagesSlotData(data) {
|
|
|
16
19
|
export function isProductSlotData(data) {
|
|
17
20
|
return data?.type === StreamComponentDataType.Product;
|
|
18
21
|
}
|
|
22
|
+
export function isProductsSlotData(data) {
|
|
23
|
+
return data?.type === StreamComponentDataType.Products;
|
|
24
|
+
}
|
|
19
25
|
export function isShortVideoSlotData(data) {
|
|
20
26
|
return data?.type === StreamComponentDataType.ShortVideo;
|
|
21
27
|
}
|
|
22
28
|
export const NotAllowedElementTypesForComponent = {
|
|
23
|
-
[StreamComponentDataType.Images]: [
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
[StreamComponentDataType.Images]: [
|
|
30
|
+
StreamElementType.ImageRef,
|
|
31
|
+
StreamElementType.Price,
|
|
32
|
+
StreamElementType.ProductsSlider,
|
|
33
|
+
StreamElementType.ShortVideo,
|
|
34
|
+
StreamElementType.TextRef
|
|
35
|
+
],
|
|
36
|
+
[StreamComponentDataType.Product]: [StreamElementType.Images, StreamElementType.ProductsSlider, StreamElementType.ShortVideo],
|
|
37
|
+
[StreamComponentDataType.Products]: [StreamElementType.Images, StreamElementType.ShortVideo],
|
|
38
|
+
[StreamComponentDataType.ShortVideo]: [StreamElementType.ImageRef, StreamElementType.Price, StreamElementType.ProductsSlider, StreamElementType.TextRef],
|
|
26
39
|
[StreamComponentDataType.NoData]: [
|
|
27
40
|
StreamElementType.ImageRef,
|
|
28
41
|
StreamElementType.Images,
|
|
29
42
|
StreamElementType.Price,
|
|
43
|
+
StreamElementType.ProductsSlider,
|
|
30
44
|
StreamElementType.ShortVideo,
|
|
31
45
|
StreamElementType.TextRef
|
|
32
46
|
]
|
|
@@ -2,18 +2,18 @@ import { PlayerChunk } from './player-chunk.svelte';
|
|
|
2
2
|
import type { IChunksPlayerDataProvider, WithId } from '../types';
|
|
3
3
|
export declare class PlayerChunksManager<TItem extends WithId, TChunk extends WithId> {
|
|
4
4
|
private provider;
|
|
5
|
-
private
|
|
6
|
-
readonly activeChunk: PlayerChunk<TItem, TChunk>;
|
|
7
|
-
readonly loadedChunks: PlayerChunk<TItem, TChunk>[];
|
|
8
|
-
readonly flattenedChunkItems: TItem[];
|
|
9
|
-
readonly flattenedActiveChunkItemIndex: number;
|
|
5
|
+
private callbacks;
|
|
10
6
|
private _activeChunkIndex;
|
|
11
7
|
private _loadedChunks;
|
|
12
8
|
private _isLoading;
|
|
13
|
-
constructor(provider: IChunksPlayerDataProvider<TItem, TChunk>,
|
|
9
|
+
constructor(provider: IChunksPlayerDataProvider<TItem, TChunk>, callbacks: {
|
|
14
10
|
onInitializationFinished: () => void;
|
|
15
11
|
onEndReached: () => void;
|
|
16
12
|
});
|
|
13
|
+
get activeChunk(): PlayerChunk<TItem, TChunk>;
|
|
14
|
+
get loadedChunks(): PlayerChunk<TItem, TChunk>[];
|
|
15
|
+
get flattenedChunkItems(): TItem[];
|
|
16
|
+
get flattenedActiveChunkItemIndex(): number;
|
|
17
17
|
initialize: () => Promise<void>;
|
|
18
18
|
setActiveChunkIndex: (index: number) => Promise<void>;
|
|
19
19
|
activateItemAtFlattenedIndex: (index: number) => Promise<void>;
|
|
@@ -3,14 +3,27 @@ const CHUNKS_BUFFER_SIZE = 5;
|
|
|
3
3
|
const FIXED_START_INDEX = 0;
|
|
4
4
|
export class PlayerChunksManager {
|
|
5
5
|
provider;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
callbacks;
|
|
7
|
+
_activeChunkIndex = $state(-1);
|
|
8
|
+
_loadedChunks = $state.raw([]);
|
|
9
|
+
_isLoading = $state(false);
|
|
10
|
+
constructor(provider, callbacks) {
|
|
11
|
+
this.provider = provider;
|
|
12
|
+
this.callbacks = callbacks;
|
|
13
|
+
}
|
|
14
|
+
get activeChunk() {
|
|
15
|
+
return this._loadedChunks[this._activeChunkIndex] ?? null;
|
|
16
|
+
}
|
|
17
|
+
get loadedChunks() {
|
|
18
|
+
return this._loadedChunks;
|
|
19
|
+
}
|
|
20
|
+
get flattenedChunkItems() {
|
|
21
|
+
return this._loadedChunks.reduce((acc, chunk) => {
|
|
22
|
+
acc.push(...chunk.items);
|
|
23
|
+
return acc;
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
26
|
+
get flattenedActiveChunkItemIndex() {
|
|
14
27
|
if (!this.activeChunk || !this.activeChunk.activeChunkItem) {
|
|
15
28
|
return -1;
|
|
16
29
|
}
|
|
@@ -19,16 +32,9 @@ export class PlayerChunksManager {
|
|
|
19
32
|
itemsBeforeActiveChunk += this._loadedChunks[i].items.length;
|
|
20
33
|
}
|
|
21
34
|
return itemsBeforeActiveChunk + this.activeChunk.activeChunkItem.indexWithinChunk;
|
|
22
|
-
});
|
|
23
|
-
_activeChunkIndex = $state(-1);
|
|
24
|
-
_loadedChunks = $state.raw([]);
|
|
25
|
-
_isLoading = $state(false);
|
|
26
|
-
constructor(provider, callabacks) {
|
|
27
|
-
this.provider = provider;
|
|
28
|
-
this.callabacks = callabacks;
|
|
29
35
|
}
|
|
30
36
|
initialize = async () => {
|
|
31
|
-
const { onInitializationFinished, onEndReached } = this.
|
|
37
|
+
const { onInitializationFinished, onEndReached } = this.callbacks;
|
|
32
38
|
const handleInitialized = async () => {
|
|
33
39
|
const startIndex = Math.min(FIXED_START_INDEX, this._loadedChunks.length - 1);
|
|
34
40
|
const populateChunkResult = await this.populateChunkAtIndex(startIndex, (currentIndex) => currentIndex + 1);
|
|
@@ -58,6 +64,8 @@ export class PlayerChunksManager {
|
|
|
58
64
|
this._activeChunkIndex = index;
|
|
59
65
|
this._loadedChunks.forEach((c) => c.setActiveItemIndex(0, false));
|
|
60
66
|
await this.populateChunkAtIndex(this._activeChunkIndex + 1, (currentIndex) => currentIndex + 1);
|
|
67
|
+
// Don't wait for warm up to be finished, it runs in the background
|
|
68
|
+
this.warmUp();
|
|
61
69
|
};
|
|
62
70
|
activateItemAtFlattenedIndex = async (index) => {
|
|
63
71
|
const activeChunkId = this.activeChunk?.model.id;
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {} from '../../../core/locale';
|
|
2
|
-
export class StreamElementLocalization {
|
|
3
|
-
priceElementLocalization;
|
|
4
|
-
stockElementLocalization;
|
|
5
|
-
shortVideoElementLocalization;
|
|
6
|
-
constructor(locale) {
|
|
7
|
-
this.priceElementLocalization = locale;
|
|
8
|
-
this.stockElementLocalization = locale;
|
|
9
|
-
this.shortVideoElementLocalization = locale;
|
|
10
|
-
}
|
|
11
|
-
}
|