@empathyco/x-components 3.0.0-alpha.365 → 3.0.0-alpha.366
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/CHANGELOG.md +12 -0
- package/docs/API-reference/api/x-components.baseaddtocart.md +14 -11
- package/docs/API-reference/api/x-components.baseresultcurrentprice.md +20 -11
- package/docs/API-reference/api/x-components.baseresultimage.md +50 -13
- package/docs/API-reference/api/x-components.baseresultlink.md +15 -10
- package/docs/API-reference/api/x-components.baseresultpreviousprice.md +18 -11
- package/docs/API-reference/api/x-components.baseresultrating.md +20 -11
- package/docs/API-reference/api/x-components.md +6 -6
- package/js/components/result/base-result-add-to-cart.vue.js.map +1 -1
- package/js/components/result/base-result-add-to-cart.vue_rollup-plugin-vue_script.vue.js +29 -23
- package/js/components/result/base-result-add-to-cart.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-current-price.vue.js.map +1 -1
- package/js/components/result/base-result-current-price.vue_rollup-plugin-vue_script.vue.js +47 -26
- package/js/components/result/base-result-current-price.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-image.vue.js +1 -1
- package/js/components/result/base-result-image.vue.js.map +1 -1
- package/js/components/result/base-result-image.vue_rollup-plugin-vue_script.vue.js +125 -96
- package/js/components/result/base-result-image.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-image.vue_rollup-plugin-vue_styles.0.vue.js +1 -1
- package/js/components/result/base-result-link.vue.js +2 -1
- package/js/components/result/base-result-link.vue.js.map +1 -1
- package/js/components/result/base-result-link.vue_rollup-plugin-vue_script.vue.js +46 -27
- package/js/components/result/base-result-link.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-link.vue_rollup-plugin-vue_styles.0.vue.js +1 -1
- package/js/components/result/base-result-previous-price.vue.js.map +1 -1
- package/js/components/result/base-result-previous-price.vue_rollup-plugin-vue_script.vue.js +34 -17
- package/js/components/result/base-result-previous-price.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-rating.vue.js +2 -1
- package/js/components/result/base-result-rating.vue.js.map +1 -1
- package/js/components/result/base-result-rating.vue_rollup-plugin-vue_script.vue.js +44 -27
- package/js/components/result/base-result-rating.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/result/base-result-rating.vue_rollup-plugin-vue_styles.0.vue.js +1 -1
- package/js/utils/options-api.js +4 -0
- package/js/utils/options-api.js.map +1 -0
- package/package.json +2 -2
- package/report/x-components.api.json +1556 -526
- package/report/x-components.api.md +130 -57
- package/types/components/result/base-result-add-to-cart.vue.d.ts +16 -8
- package/types/components/result/base-result-add-to-cart.vue.d.ts.map +1 -1
- package/types/components/result/base-result-current-price.vue.d.ts +40 -10
- package/types/components/result/base-result-current-price.vue.d.ts.map +1 -1
- package/types/components/result/base-result-image.vue.d.ts +60 -70
- package/types/components/result/base-result-image.vue.d.ts.map +1 -1
- package/types/components/result/base-result-link.vue.d.ts +18 -23
- package/types/components/result/base-result-link.vue.d.ts.map +1 -1
- package/types/components/result/base-result-previous-price.vue.d.ts +40 -5
- package/types/components/result/base-result-previous-price.vue.d.ts.map +1 -1
- package/types/components/result/base-result-rating.vue.d.ts +28 -9
- package/types/components/result/base-result-rating.vue.d.ts.map +1 -1
- package/types/utils/options-api.d.ts +3 -0
- package/types/utils/options-api.d.ts.map +1 -0
- package/docs/API-reference/api/x-components.baseaddtocart.events.md +0 -13
- package/docs/API-reference/api/x-components.baseaddtocart.result.md +0 -13
- package/docs/API-reference/api/x-components.baseresultcurrentprice.format.md +0 -18
- package/docs/API-reference/api/x-components.baseresultcurrentprice.result.md +0 -13
- package/docs/API-reference/api/x-components.baseresultimage.hoveranimation.md +0 -13
- package/docs/API-reference/api/x-components.baseresultimage.loadanimation.md +0 -13
- package/docs/API-reference/api/x-components.baseresultimage.result.md +0 -13
- package/docs/API-reference/api/x-components.baseresultimage.shownextimageonhover.md +0 -13
- package/docs/API-reference/api/x-components.baseresultlink.result.md +0 -13
- package/docs/API-reference/api/x-components.baseresultpreviousprice.format.md +0 -18
- package/docs/API-reference/api/x-components.baseresultpreviousprice.result.md +0 -13
- package/docs/API-reference/api/x-components.baseresultrating.link.md +0 -13
- package/docs/API-reference/api/x-components.baseresultrating.result.md +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-result-image.vue.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n class=\"x-result-picture x-picture\"\n data-test=\"result-picture\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n loading=\"lazy\"\n :src=\"pendingImages[0]\"\n :style=\"loaderStyles\"\n class=\"x-picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n />\n <component :is=\"animation\" class=\"x-picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import
|
|
1
|
+
{"version":3,"file":"base-result-image.vue.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n class=\"x-result-picture x-picture\"\n data-test=\"result-picture\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n loading=\"lazy\"\n :src=\"pendingImages[0]\"\n :style=\"loaderStyles\"\n class=\"x-picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n />\n <component :is=\"animation\" class=\"x-picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import {\n computed,\n DefineComponent,\n defineComponent,\n PropType,\n Ref,\n ref,\n toRef,\n watch\n } from 'vue';\n import { NoElement } from '../no-element';\n import { animationProp } from '../../utils/options-api';\n\n /**\n * Component to be reused that renders an `<img>`.\n *\n * @public\n */\n export default defineComponent({\n components: {\n NoElement\n },\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#Result | result} information.\n *\n * @public\n */\n result: {\n type: Object as PropType<Result>,\n required: true\n },\n\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n *\n * @public\n */\n loadAnimation: {\n type: animationProp,\n default: () => NoElement\n },\n\n /**\n * Animation to use when switching between the loaded image and the hover image.\n *\n * @public\n */\n hoverAnimation: {\n type: animationProp\n },\n\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false\n }\n },\n\n setup(props) {\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<string[]> = ref([]);\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<string[]> = ref([]);\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false);\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false);\n\n /**.\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: Partial<CSSStyleDeclaration> = {\n position: 'absolute !important',\n top: '0 !important',\n left: '0 !important',\n width: '100% !important',\n height: '100% !important',\n pointerEvents: 'none !important',\n visibility: 'hidden !important'\n };\n\n const resultImages = toRef(props.result, 'images');\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n resultImages,\n () => {\n pendingImages.value = [...(props.result.images ?? [])];\n loadedImages.value = pendingImages.value.filter(image =>\n loadedImages.value.includes(image)\n );\n },\n { immediate: true }\n );\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed<DefineComponent | string>(() => {\n return userHasHoveredImage\n ? props.hoverAnimation ?? props.loadAnimation\n : props.loadAnimation;\n });\n\n /**\n * Gets the src from the result image.\n *\n * @returns The result image src.\n *\n * @internal\n */\n const imageSrc = computed<string>(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering ? 0 : loadedImages.value.length - 1\n ];\n });\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed<boolean>(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage ? 2 : 1;\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad;\n });\n\n /**\n * Sets an image as failed.\n *\n * @internal\n */\n const flagImageAsFailed = (): void => {\n pendingImages.value.shift();\n };\n\n /**\n * Sets an image as loaded.\n *\n * @internal\n */\n const flagImageLoaded = (): void => {\n const image = pendingImages.value.shift();\n if (image) {\n loadedImages.value.push(image);\n }\n };\n\n return {\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded\n };\n }\n });\n</script>\n\n<style lang=\"scss\" scoped>\n .x-result-picture {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n\n &-image {\n max-width: 100%;\n max-height: 100%;\n }\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component is for the result image. It may be part of the search result page, recommendations or\nother section which needs to include results.\n\nThe result prop is required. It will render a `<img/>` with the result image:\n\n```vue\n<BaseResultImage :result=\"result\" />\n```\n\n### Showing the next image on hover\n\nIf a result has multiple images, it can show the next one on hover.\n\n```vue\n<BaseResultImage :result=\"result\" showNextImageOnHover />\n```\n\n### Customizing slots content\n\nFallback and placeholder contents can be customized.\n\nThe fallback slot allows you to replace the content of the fallback image.\n\nThe other slot is called `placeholder`, and allows you to set the image that its going to be\ndisplayed while the real one is loaded.\n\n```vue\n<BaseResultImage :result=\"result\">\n <template #placeholder>\n <img alt=\"Placeholder image\" src=\"./placeholder-image.svg\"/>\n </template>\n <template #fallback>\n <img alt=\"Fallback image\" src=\"./fallback-image.svg\"/>\n </template>\n</BaseResultImage>\n```\n\n### Customizing the animations\n\nTwo animations can be used this component.\n\nThe `loadAnimation` is used to transition between the placeholder, the fallback and the image.\n\nThe `hoverAnimation` is used to transition between the image and the hover image, if the\n`showNextImageOnHover` prop is `true`.\n\n`hoverAnimation` will default to `loadAnimation` if it is not provided.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n :loadAnimation=\"loadAnimation\"\n :hoverAnimation=\"hoverAnimation\"\n showNextImageOnHover\n />\n</template>\n\n<script>\n import { BaseResultImage } from '@empathyco/x-components';\n import { CrossFade, CollapseHeight } from '@empathyco/x-components/animations';\n\n export default {\n name: 'BaseResultImageAnimations',\n components: {\n BaseResultImage\n },\n data() {\n return {\n loadAnimation: CrossFade,\n hoverAnimation: CollapseHeight,\n result: {\n name: 'jacket',\n images: ['https://some-image', 'https://some-image-2']\n }\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;AAEA,MAAc,cAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Vue from 'vue';
|
|
3
|
-
import { Prop, Watch, Component } from 'vue-property-decorator';
|
|
1
|
+
import { defineComponent, ref, toRef, watch, computed } from 'vue';
|
|
4
2
|
import { NoElement } from '../no-element.js';
|
|
3
|
+
import { animationProp } from '../../utils/options-api.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Component to be reused that renders an `<img>`.
|
|
8
7
|
*
|
|
9
8
|
* @public
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
var script = defineComponent({
|
|
11
|
+
components: {
|
|
12
|
+
NoElement
|
|
13
|
+
},
|
|
14
|
+
props: {
|
|
15
|
+
/**
|
|
16
|
+
* (Required) The {@link @empathyco/x-types#Result | result} information.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
result: {
|
|
21
|
+
type: Object,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Animation to use when switching between the placeholder, the loaded image, or the failed
|
|
26
|
+
* image fallback.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
loadAnimation: {
|
|
31
|
+
type: animationProp,
|
|
32
|
+
default: () => NoElement
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Animation to use when switching between the loaded image and the hover image.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
hoverAnimation: {
|
|
40
|
+
type: animationProp
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Indicates if the next valid image should be displayed on hover.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
showNextImageOnHover: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
setup(props) {
|
|
14
53
|
/**
|
|
15
54
|
* Copy of the images of the result.
|
|
16
55
|
*
|
|
@@ -19,31 +58,31 @@ let BaseResultImage = class BaseResultImage extends Vue {
|
|
|
19
58
|
*
|
|
20
59
|
* @internal
|
|
21
60
|
*/
|
|
22
|
-
|
|
61
|
+
const pendingImages = ref([]);
|
|
23
62
|
/**
|
|
24
63
|
* Contains the images that have been loaded successfully.
|
|
25
64
|
*
|
|
26
65
|
* @internal
|
|
27
66
|
*/
|
|
28
|
-
|
|
67
|
+
const loadedImages = ref([]);
|
|
29
68
|
/**
|
|
30
69
|
* Indicates if the user is hovering the image.
|
|
31
70
|
*
|
|
32
71
|
* @internal
|
|
33
72
|
*/
|
|
34
|
-
|
|
73
|
+
const isHovering = ref(false);
|
|
35
74
|
/**
|
|
36
75
|
* Indicates if the user has hovered the image.
|
|
37
76
|
*
|
|
38
77
|
* @internal
|
|
39
78
|
*/
|
|
40
|
-
|
|
79
|
+
const userHasHoveredImage = ref(false);
|
|
41
80
|
/**.
|
|
42
81
|
* Styles to use inline in the image loader, to prevent override from CSS
|
|
43
82
|
*
|
|
44
83
|
* @internal
|
|
45
84
|
*/
|
|
46
|
-
|
|
85
|
+
const loaderStyles = {
|
|
47
86
|
position: 'absolute !important',
|
|
48
87
|
top: '0 !important',
|
|
49
88
|
left: '0 !important',
|
|
@@ -52,92 +91,82 @@ let BaseResultImage = class BaseResultImage extends Vue {
|
|
|
52
91
|
pointerEvents: 'none !important',
|
|
53
92
|
visibility: 'hidden !important'
|
|
54
93
|
};
|
|
94
|
+
const resultImages = toRef(props.result, 'images');
|
|
95
|
+
/**
|
|
96
|
+
* Initializes images state and resets when the result's images change.
|
|
97
|
+
*
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
watch(resultImages, () => {
|
|
101
|
+
pendingImages.value = [...(props.result.images ?? [])];
|
|
102
|
+
loadedImages.value = pendingImages.value.filter(image => loadedImages.value.includes(image));
|
|
103
|
+
}, { immediate: true });
|
|
104
|
+
/**
|
|
105
|
+
* Animation to be used.
|
|
106
|
+
*
|
|
107
|
+
* @returns The animation to be used, taking into account if the user has hovered the image.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
const animation = computed(() => {
|
|
112
|
+
return userHasHoveredImage
|
|
113
|
+
? props.hoverAnimation ?? props.loadAnimation
|
|
114
|
+
: props.loadAnimation;
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* Gets the src from the result image.
|
|
118
|
+
*
|
|
119
|
+
* @returns The result image src.
|
|
120
|
+
*
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
const imageSrc = computed(() => {
|
|
124
|
+
return loadedImages.value[!props.showNextImageOnHover || !isHovering ? 0 : loadedImages.value.length - 1];
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Indicates if the loader should try to load the next image.
|
|
128
|
+
*
|
|
129
|
+
* @returns True if it should try to load the next image.
|
|
130
|
+
*
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
const shouldLoadNextImage = computed(() => {
|
|
134
|
+
const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage ? 2 : 1;
|
|
135
|
+
return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad;
|
|
136
|
+
});
|
|
137
|
+
/**
|
|
138
|
+
* Sets an image as failed.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
const flagImageAsFailed = () => {
|
|
143
|
+
pendingImages.value.shift();
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Sets an image as loaded.
|
|
147
|
+
*
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
const flagImageLoaded = () => {
|
|
151
|
+
const image = pendingImages.value.shift();
|
|
152
|
+
if (image) {
|
|
153
|
+
loadedImages.value.push(image);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
pendingImages,
|
|
158
|
+
loadedImages,
|
|
159
|
+
isHovering,
|
|
160
|
+
userHasHoveredImage,
|
|
161
|
+
loaderStyles,
|
|
162
|
+
animation,
|
|
163
|
+
imageSrc,
|
|
164
|
+
shouldLoadNextImage,
|
|
165
|
+
flagImageAsFailed,
|
|
166
|
+
flagImageLoaded
|
|
167
|
+
};
|
|
55
168
|
}
|
|
56
|
-
|
|
57
|
-
* Initializes images state and resets when the result's images change.
|
|
58
|
-
*
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
resetImagesState() {
|
|
62
|
-
this.pendingImages = [...(this.result.images ?? [])];
|
|
63
|
-
this.loadedImages = this.pendingImages.filter(image => this.loadedImages.includes(image));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Animation to be used.
|
|
67
|
-
*
|
|
68
|
-
* @returns The animation to be used, taking into account if the user has hovered the image.
|
|
69
|
-
*
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
get animation() {
|
|
73
|
-
return this.userHasHoveredImage
|
|
74
|
-
? this.hoverAnimation ?? this.loadAnimation
|
|
75
|
-
: this.loadAnimation;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets the src from the result image.
|
|
79
|
-
*
|
|
80
|
-
* @returns The result image src.
|
|
81
|
-
*
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
get imageSrc() {
|
|
85
|
-
return this.loadedImages[!this.showNextImageOnHover || !this.isHovering ? 0 : this.loadedImages.length - 1];
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Indicates if the loader should try to load the next image.
|
|
89
|
-
*
|
|
90
|
-
* @returns True if it should try to load the next image.
|
|
91
|
-
*
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
get shouldLoadNextImage() {
|
|
95
|
-
const numImagesToLoad = this.showNextImageOnHover && this.userHasHoveredImage ? 2 : 1;
|
|
96
|
-
return !!this.pendingImages.length && this.loadedImages.length < numImagesToLoad;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Sets an image as failed.
|
|
100
|
-
*
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
flagImageAsFailed() {
|
|
104
|
-
this.pendingImages.shift();
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Sets an image as loaded.
|
|
108
|
-
*
|
|
109
|
-
* @internal
|
|
110
|
-
*/
|
|
111
|
-
flagImageLoaded() {
|
|
112
|
-
const image = this.pendingImages.shift();
|
|
113
|
-
if (image) {
|
|
114
|
-
this.loadedImages.push(image);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
__decorate([
|
|
119
|
-
Prop({ required: true })
|
|
120
|
-
], BaseResultImage.prototype, "result", void 0);
|
|
121
|
-
__decorate([
|
|
122
|
-
Prop({ default: () => NoElement })
|
|
123
|
-
], BaseResultImage.prototype, "loadAnimation", void 0);
|
|
124
|
-
__decorate([
|
|
125
|
-
Prop()
|
|
126
|
-
], BaseResultImage.prototype, "hoverAnimation", void 0);
|
|
127
|
-
__decorate([
|
|
128
|
-
Prop({ type: Boolean, default: false })
|
|
129
|
-
], BaseResultImage.prototype, "showNextImageOnHover", void 0);
|
|
130
|
-
__decorate([
|
|
131
|
-
Watch('result.images', { immediate: true })
|
|
132
|
-
], BaseResultImage.prototype, "resetImagesState", null);
|
|
133
|
-
BaseResultImage = __decorate([
|
|
134
|
-
Component({
|
|
135
|
-
components: {
|
|
136
|
-
NoElement
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
], BaseResultImage);
|
|
140
|
-
var script = BaseResultImage;
|
|
169
|
+
});
|
|
141
170
|
|
|
142
171
|
export { script as default };
|
|
143
172
|
//# sourceMappingURL=base-result-image.vue_rollup-plugin-vue_script.vue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-result-image.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/result/base-result-image.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n import { Result } from '@empathyco/x-types';\n import
|
|
1
|
+
{"version":3,"file":"base-result-image.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/result/base-result-image.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n import { Result } from '@empathyco/x-types';\n import {\n computed,\n DefineComponent,\n defineComponent,\n PropType,\n Ref,\n ref,\n toRef,\n watch\n } from 'vue';\n import { NoElement } from '../no-element';\n import { animationProp } from '../../utils/options-api';\n\n /**\n * Component to be reused that renders an `<img>`.\n *\n * @public\n */\n export default defineComponent({\n components: {\n NoElement\n },\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#Result | result} information.\n *\n * @public\n */\n result: {\n type: Object as PropType<Result>,\n required: true\n },\n\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n *\n * @public\n */\n loadAnimation: {\n type: animationProp,\n default: () => NoElement\n },\n\n /**\n * Animation to use when switching between the loaded image and the hover image.\n *\n * @public\n */\n hoverAnimation: {\n type: animationProp\n },\n\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false\n }\n },\n\n setup(props) {\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<string[]> = ref([]);\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<string[]> = ref([]);\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false);\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false);\n\n /**.\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: Partial<CSSStyleDeclaration> = {\n position: 'absolute !important',\n top: '0 !important',\n left: '0 !important',\n width: '100% !important',\n height: '100% !important',\n pointerEvents: 'none !important',\n visibility: 'hidden !important'\n };\n\n const resultImages = toRef(props.result, 'images');\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n resultImages,\n () => {\n pendingImages.value = [...(props.result.images ?? [])];\n loadedImages.value = pendingImages.value.filter(image =>\n loadedImages.value.includes(image)\n );\n },\n { immediate: true }\n );\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed<DefineComponent | string>(() => {\n return userHasHoveredImage\n ? props.hoverAnimation ?? props.loadAnimation\n : props.loadAnimation;\n });\n\n /**\n * Gets the src from the result image.\n *\n * @returns The result image src.\n *\n * @internal\n */\n const imageSrc = computed<string>(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering ? 0 : loadedImages.value.length - 1\n ];\n });\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed<boolean>(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage ? 2 : 1;\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad;\n });\n\n /**\n * Sets an image as failed.\n *\n * @internal\n */\n const flagImageAsFailed = (): void => {\n pendingImages.value.shift();\n };\n\n /**\n * Sets an image as loaded.\n *\n * @internal\n */\n const flagImageLoaded = (): void => {\n const image = pendingImages.value.shift();\n if (image) {\n loadedImages.value.push(image);\n }\n };\n\n return {\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded\n };\n }\n });\n"],"names":[],"mappings":";;;;AAwDE;;;;AAIG;AACH,aAAe,eAAe,CAAC;AAC7B,IAAA,UAAU,EAAE;QACV,SAAS;AACV,KAAA;AACD,IAAA,KAAK,EAAE;AACL;;;;AAIG;AACH,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAA0B;AAChC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AAED;;;;;AAKG;AACH,QAAA,aAAa,EAAE;AACb,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,SAAS;AACzB,SAAA;AAED;;;;AAIG;AACH,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,aAAa;AACpB,SAAA;AAED;;;;AAIG;AACH,QAAA,oBAAoB,EAAE;AACpB,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACF,KAAA;AAED,IAAA,KAAK,CAAC,KAAK,EAAA;AACT;;;;;;;AAOG;AACH,QAAA,MAAM,aAAa,GAAkB,GAAG,CAAC,EAAE,CAAC,CAAC;AAE7C;;;;AAIG;AACH,QAAA,MAAM,YAAY,GAAkB,GAAG,CAAC,EAAE,CAAC,CAAC;AAE5C;;;;AAIG;AACH,QAAA,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;AAE9B;;;;AAIG;AACH,QAAA,MAAM,mBAAmB,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;AAEvC;;;;AAIG;AACH,QAAA,MAAM,YAAY,GAAiC;AACjD,YAAA,QAAQ,EAAE,qBAAqB;AAC/B,YAAA,GAAG,EAAE,cAAc;AACnB,YAAA,IAAI,EAAE,cAAc;AACpB,YAAA,KAAK,EAAE,iBAAiB;AACxB,YAAA,MAAM,EAAE,iBAAiB;AACzB,YAAA,aAAa,EAAE,iBAAiB;AAChC,YAAA,UAAU,EAAE,mBAAmB;SAChC,CAAC;QAEF,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEnD;;;;AAIG;AACH,QAAA,KAAK,CACH,YAAY,EACZ,MAAK;AACH,YAAA,aAAa,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;YACvD,YAAY,CAAC,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IACnD,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CACnC,CAAC;AACJ,SAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;AAEF;;;;;;AAMG;AACH,QAAA,MAAM,SAAS,GAAG,QAAQ,CAA2B,MAAK;AACxD,YAAA,OAAO,mBAAmB;AACxB,kBAAE,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,aAAa;AAC7C,kBAAE,KAAK,CAAC,aAAa,CAAC;AAC1B,SAAC,CAAC,CAAC;AAEH;;;;;;AAMG;AACH,QAAA,MAAM,QAAQ,GAAG,QAAQ,CAAS,MAAK;YACrC,OAAO,YAAY,CAAC,KAAK,CACvB,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAC/E,CAAC;AACJ,SAAC,CAAC,CAAC;AAEH;;;;;;AAMG;AACH,QAAA,MAAM,mBAAmB,GAAG,QAAQ,CAAU,MAAK;AACjD,YAAA,MAAM,eAAe,GAAG,KAAK,CAAC,oBAAoB,IAAI,mBAAmB,GAAG,CAAC,GAAG,CAAC,CAAC;AAClF,YAAA,OAAO,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC;AACrF,SAAC,CAAC,CAAC;AAEH;;;;AAIG;QACH,MAAM,iBAAiB,GAAG,MAAW;AACnC,YAAA,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;AAC9B,SAAC,CAAC;AAEF;;;;AAIG;QACH,MAAM,eAAe,GAAG,MAAW;YACjC,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;AAC1C,YAAA,IAAI,KAAK,EAAE;AACT,gBAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,aAAA;AACH,SAAC,CAAC;QAEF,OAAO;YACL,aAAa;YACb,YAAY;YACZ,UAAU;YACV,mBAAmB;YACnB,YAAY;YACZ,SAAS;YACT,QAAQ;YACR,mBAAmB;YACnB,iBAAiB;YACjB,eAAe;SAChB,CAAC;KACH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createInjector, createInjectorSSR } from 'vue-runtime-helpers';
|
|
2
2
|
|
|
3
|
-
var css = ".x-result-picture[data-v-
|
|
3
|
+
var css = ".x-result-picture[data-v-1ae01006] {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n}\n.x-result-picture-image[data-v-1ae01006] {\n max-width: 100%;\n max-height: 100%;\n}";
|
|
4
4
|
const isBrowser = /*#__PURE__*/ (function () {
|
|
5
5
|
return (
|
|
6
6
|
Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) !==
|
|
@@ -12,6 +12,7 @@ var __vue_render__ = function () {
|
|
|
12
12
|
return _c(
|
|
13
13
|
"a",
|
|
14
14
|
{
|
|
15
|
+
ref: "el",
|
|
15
16
|
staticClass: "x-result-link",
|
|
16
17
|
attrs: { href: _vm.result.url, "data-test": "result-link" },
|
|
17
18
|
on: {
|
|
@@ -37,7 +38,7 @@ __vue_render__._withStripped = true;
|
|
|
37
38
|
/* style */
|
|
38
39
|
const __vue_inject_styles__ = undefined;
|
|
39
40
|
/* scoped */
|
|
40
|
-
const __vue_scope_id__ = "data-v-
|
|
41
|
+
const __vue_scope_id__ = "data-v-5c0bb921";
|
|
41
42
|
/* module identifier */
|
|
42
43
|
const __vue_module_identifier__ = undefined;
|
|
43
44
|
/* functional template */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-result-link.vue.js","sources":["../../../../src/components/result/base-result-link.vue"],"sourcesContent":["<template>\n <a\n @click=\"emitUserClickedAResult\"\n @click.right=\"emitUserClickedAResult\"\n @click.middle=\"emitUserClickedAResult\"\n :href=\"result.url\"\n class=\"x-result-link\"\n data-test=\"result-link\"\n >\n <!--\n @slot (Required) Link content with a text, an image, another component or both\n @binding {Result} result - Result data\n -->\n <slot :result=\"result\" />\n </a>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import
|
|
1
|
+
{"version":3,"file":"base-result-link.vue.js","sources":["../../../../src/components/result/base-result-link.vue"],"sourcesContent":["<template>\n <a\n ref=\"el\"\n @click=\"emitUserClickedAResult\"\n @click.right=\"emitUserClickedAResult\"\n @click.middle=\"emitUserClickedAResult\"\n :href=\"result.url\"\n class=\"x-result-link\"\n data-test=\"result-link\"\n >\n <!--\n @slot (Required) Link content with a text, an image, another component or both\n @binding {Result} result - Result data\n -->\n <slot :result=\"result\" />\n </a>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import { defineComponent, inject, PropType, ref } from 'vue';\n import { PropsWithType } from '../../utils/types';\n import { XEventsTypes } from '../../wiring/events.types';\n import { use$x } from '../../composables/index';\n\n /**\n * Component to be reused that renders an `<a>` wrapping the result contents.\n *\n * @remarks\n * It has the logic to emit {@link XEventsTypes.UserClickedAResult} to the bus on click mouse\n * events. Additionally, this component may be injected other events to be emitted on click\n * event, so, depending on where it's used its father component may provide this events.\n *\n * @public\n */\n export default defineComponent({\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#Result | result} information.\n *\n * @public\n */\n result: {\n type: Object as PropType<Result>,\n required: true\n }\n },\n setup(props) {\n const $x = use$x();\n\n /**\n * The rendered DOM element.\n *\n * @internal\n */\n const el = ref<HTMLElement | null>();\n\n /**\n * The list of additional events to be emitted by the component when user clicks the link.\n *\n * @internal\n */\n const resultClickExtraEvents = inject<PropsWithType<XEventsTypes, Result>[]>(\n 'resultClickExtraEvents',\n []\n );\n\n /**\n * Emits the {@link XEventsTypes.UserClickedAResult} when user clicks on the result, and also\n * additional events if have been injected in the component.\n *\n * @internal\n */\n const emitUserClickedAResult = (): void => {\n $x.emit('UserClickedAResult', props.result, { target: el.value! });\n resultClickExtraEvents.forEach(event => {\n $x.emit(event, props.result, { target: el.value! });\n });\n };\n\n return {\n emitUserClickedAResult\n };\n }\n });\n</script>\n\n<style lang=\"scss\" scoped>\n .x-result-link {\n text-decoration: none;\n }\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the following event:\n\n- [`UserClickedAResult`](x-components.xeventstypes.userclickedaresult.md)\n\nThe component can emit more events on click using the `resultClickExtraEvents` prop.\n\n## See it in action\n\nThis component is a wrapper for the result contents (images, name, price...) It may be part of the\nsearch result page, recommendations or other section which needs to include results.\n\nAdditionally, this component may be injected other events to be emitted on click event, so,\ndepending where it's used its father component may provide this events.\n\nThe result prop is required. It will render a `<a></a>` with the href to the result URL:\n\n```vue\n<BaseResultLink :result=\"result\">\n <template #default=\"{ result }\">\n <img :src=\"result.images[0]\"/>\n <span>{{ result.name }}</span>\n </template>\n</BaseResultLink>\n```\n</docs>\n"],"names":[],"mappings":";;;;;AAEA,MAAc,cAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { defineComponent, ref, inject } from 'vue';
|
|
2
|
+
import '../../composables/create-use-device.composable.js';
|
|
3
|
+
import { use$x } from '../../composables/use-_x.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Component to be reused that renders an `<a>` wrapping the result contents.
|
|
@@ -8,34 +8,53 @@ import { Inject, Prop, Component } from 'vue-property-decorator';
|
|
|
8
8
|
* @remarks
|
|
9
9
|
* It has the logic to emit {@link XEventsTypes.UserClickedAResult} to the bus on click mouse
|
|
10
10
|
* events. Additionally, this component may be injected other events to be emitted on click
|
|
11
|
-
* event, so, depending where it's used its father component may provide this events.
|
|
11
|
+
* event, so, depending on where it's used its father component may provide this events.
|
|
12
12
|
*
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
var script = defineComponent({
|
|
16
|
+
props: {
|
|
17
|
+
/**
|
|
18
|
+
* (Required) The {@link @empathyco/x-types#Result | result} information.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
result: {
|
|
23
|
+
type: Object,
|
|
24
|
+
required: true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
setup(props) {
|
|
28
|
+
const $x = use$x();
|
|
29
|
+
/**
|
|
30
|
+
* The rendered DOM element.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
const el = ref();
|
|
35
|
+
/**
|
|
36
|
+
* The list of additional events to be emitted by the component when user clicks the link.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
const resultClickExtraEvents = inject('resultClickExtraEvents', []);
|
|
41
|
+
/**
|
|
42
|
+
* Emits the {@link XEventsTypes.UserClickedAResult} when user clicks on the result, and also
|
|
43
|
+
* additional events if have been injected in the component.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
const emitUserClickedAResult = () => {
|
|
48
|
+
$x.emit('UserClickedAResult', props.result, { target: el.value });
|
|
49
|
+
resultClickExtraEvents.forEach(event => {
|
|
50
|
+
$x.emit(event, props.result, { target: el.value });
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
emitUserClickedAResult
|
|
55
|
+
};
|
|
27
56
|
}
|
|
28
|
-
};
|
|
29
|
-
__decorate([
|
|
30
|
-
Inject({ from: 'resultClickExtraEvents', default: [] })
|
|
31
|
-
], BaseResultLink.prototype, "resultClickExtraEvents", void 0);
|
|
32
|
-
__decorate([
|
|
33
|
-
Prop({ required: true })
|
|
34
|
-
], BaseResultLink.prototype, "result", void 0);
|
|
35
|
-
BaseResultLink = __decorate([
|
|
36
|
-
Component
|
|
37
|
-
], BaseResultLink);
|
|
38
|
-
var script = BaseResultLink;
|
|
57
|
+
});
|
|
39
58
|
|
|
40
59
|
export { script as default };
|
|
41
60
|
//# sourceMappingURL=base-result-link.vue_rollup-plugin-vue_script.vue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-result-link.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/result/base-result-link.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n import { Result } from '@empathyco/x-types';\n import
|
|
1
|
+
{"version":3,"file":"base-result-link.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/result/base-result-link.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n import { Result } from '@empathyco/x-types';\n import { defineComponent, inject, PropType, ref } from 'vue';\n import { PropsWithType } from '../../utils/types';\n import { XEventsTypes } from '../../wiring/events.types';\n import { use$x } from '../../composables/index';\n\n /**\n * Component to be reused that renders an `<a>` wrapping the result contents.\n *\n * @remarks\n * It has the logic to emit {@link XEventsTypes.UserClickedAResult} to the bus on click mouse\n * events. Additionally, this component may be injected other events to be emitted on click\n * event, so, depending on where it's used its father component may provide this events.\n *\n * @public\n */\n export default defineComponent({\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#Result | result} information.\n *\n * @public\n */\n result: {\n type: Object as PropType<Result>,\n required: true\n }\n },\n setup(props) {\n const $x = use$x();\n\n /**\n * The rendered DOM element.\n *\n * @internal\n */\n const el = ref<HTMLElement | null>();\n\n /**\n * The list of additional events to be emitted by the component when user clicks the link.\n *\n * @internal\n */\n const resultClickExtraEvents = inject<PropsWithType<XEventsTypes, Result>[]>(\n 'resultClickExtraEvents',\n []\n );\n\n /**\n * Emits the {@link XEventsTypes.UserClickedAResult} when user clicks on the result, and also\n * additional events if have been injected in the component.\n *\n * @internal\n */\n const emitUserClickedAResult = (): void => {\n $x.emit('UserClickedAResult', props.result, { target: el.value! });\n resultClickExtraEvents.forEach(event => {\n $x.emit(event, props.result, { target: el.value! });\n });\n };\n\n return {\n emitUserClickedAResult\n };\n }\n });\n"],"names":[],"mappings":";;;;AAyBE;;;;;;;;;AASG;AACH,aAAe,eAAe,CAAC;AAC7B,IAAA,KAAK,EAAE;AACL;;;;AAIG;AACH,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAA0B;AAChC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;AAEnB;;;;AAIG;AACH,QAAA,MAAM,EAAE,GAAG,GAAG,EAAsB,CAAC;AAErC;;;;AAIG;QACH,MAAM,sBAAsB,GAAG,MAAM,CACnC,wBAAwB,EACxB,EAAE,CACH,CAAC;AAEF;;;;;AAKG;QACH,MAAM,sBAAsB,GAAG,MAAW;AACxC,YAAA,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,KAAM,EAAE,CAAC,CAAC;AACnE,YAAA,sBAAsB,CAAC,OAAO,CAAC,KAAK,IAAG;AACrC,gBAAA,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,KAAM,EAAE,CAAC,CAAC;AACtD,aAAC,CAAC,CAAC;AACL,SAAC,CAAC;QAEF,OAAO;YACL,sBAAsB;SACvB,CAAC;KACH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createInjector, createInjectorSSR } from 'vue-runtime-helpers';
|
|
2
2
|
|
|
3
|
-
var css = ".x-result-link[data-v-
|
|
3
|
+
var css = ".x-result-link[data-v-5c0bb921] {\n text-decoration: none;\n}";
|
|
4
4
|
const isBrowser = /*#__PURE__*/ (function () {
|
|
5
5
|
return (
|
|
6
6
|
Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) !==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-result-previous-price.vue.js","sources":["../../../../src/components/result/base-result-previous-price.vue"],"sourcesContent":["<template>\n <div\n v-if=\"result.price.hasDiscount\"\n class=\"x-result-previous-price\"\n data-test=\"result-previous-price\"\n >\n <!--\n @slot Base currency item\n @binding {result} result - Result data\n -->\n <slot :result=\"result\">\n <BaseCurrency :value=\"result.price.originalValue\" :format=\"format\" />\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import {
|
|
1
|
+
{"version":3,"file":"base-result-previous-price.vue.js","sources":["../../../../src/components/result/base-result-previous-price.vue"],"sourcesContent":["<template>\n <div\n v-if=\"result.price.hasDiscount\"\n class=\"x-result-previous-price\"\n data-test=\"result-previous-price\"\n >\n <!--\n @slot Base currency item\n @binding {result} result - Result data\n -->\n <slot :result=\"result\">\n <BaseCurrency :value=\"result.price.originalValue\" :format=\"format\" />\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Result } from '@empathyco/x-types';\n import { defineComponent, PropType } from 'vue';\n import BaseCurrency from '../currency/base-currency.vue';\n\n /**\n * Component that renders the {@link @empathyco/x-types#Result | result} previous price.\n *\n * @public\n */\n export default defineComponent({\n components: { BaseCurrency },\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#Result | result} information.\n *\n * @public\n */\n result: {\n type: Object as PropType<Result>,\n required: true\n },\n /**\n * Format or mask to be defined as string.\n * - Use 'i' to define integer numbers.\n * - Use 'd' to define decimal numbers. You can define the length of the decimal part. If the\n * doesn't include decimals, it is filled with zeros until reach the length defined with 'd's.\n * - Integer separator must be defined between the 3rd and the 4th integer 'i' of a group.\n * - Decimal separator must be defined between the last 'i' and the first 'd'. It can be more\n * than one character.\n * - Set whatever you need around the integers and decimals marks.\n *\n * @remarks The number of 'd', which is the maximum decimal length, MUST match with the length\n * of decimals provided from the adapter. Otherwise, when the component truncate the decimal\n * part, delete significant digits.\n *\n * @public\n */\n format: {\n type: String\n }\n }\n });\n</script>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component shows the previous price formatted if it has discount. The component has two optional\nprops. `format` to select the currency format to be applied.\n\n```vue\n<template>\n <BaseResultPreviousPrice :result=\"result\" :format=\"'i.iii,ddd €'\" />\n</template>\n\n<script>\n import { BaseResultPreviousPrice } from '@empathyco/x-components';\n\n export default {\n name: 'BaseResultPreviousPriceDemo',\n components: {\n BaseResultPreviousPrice\n }\n };\n</script>\n```\n\n### Overriding default slot\n\n```vue\n<template>\n <BaseResultPreviousPrice :result=\"result\">\n <span class=\"custom-base-result-previous-price\">{{ result.price.originalValue }}</span>\n </BaseResultPreviousPrice>\n</template>\n\n<script>\n import { BaseResultPreviousPrice } from '@empathyco/x-components';\n\n export default {\n name: 'BaseResultPreviousPriceDemo',\n components: {\n BaseResultPreviousPrice\n }\n };\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;AAEA,MAAc,cAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Prop, Component } from 'vue-property-decorator';
|
|
3
|
-
import Vue from 'vue';
|
|
1
|
+
import { defineComponent } from 'vue';
|
|
4
2
|
import __vue_component__ from '../currency/base-currency.vue.js';
|
|
5
3
|
|
|
6
4
|
/**
|
|
@@ -8,20 +6,39 @@ import __vue_component__ from '../currency/base-currency.vue.js';
|
|
|
8
6
|
*
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
var script = defineComponent({
|
|
10
|
+
components: { BaseCurrency: __vue_component__ },
|
|
11
|
+
props: {
|
|
12
|
+
/**
|
|
13
|
+
* (Required) The {@link @empathyco/x-types#Result | result} information.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
result: {
|
|
18
|
+
type: Object,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Format or mask to be defined as string.
|
|
23
|
+
* - Use 'i' to define integer numbers.
|
|
24
|
+
* - Use 'd' to define decimal numbers. You can define the length of the decimal part. If the
|
|
25
|
+
* doesn't include decimals, it is filled with zeros until reach the length defined with 'd's.
|
|
26
|
+
* - Integer separator must be defined between the 3rd and the 4th integer 'i' of a group.
|
|
27
|
+
* - Decimal separator must be defined between the last 'i' and the first 'd'. It can be more
|
|
28
|
+
* than one character.
|
|
29
|
+
* - Set whatever you need around the integers and decimals marks.
|
|
30
|
+
*
|
|
31
|
+
* @remarks The number of 'd', which is the maximum decimal length, MUST match with the length
|
|
32
|
+
* of decimals provided from the adapter. Otherwise, when the component truncate the decimal
|
|
33
|
+
* part, delete significant digits.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
format: {
|
|
38
|
+
type: String
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
25
42
|
|
|
26
43
|
export { script as default };
|
|
27
44
|
//# sourceMappingURL=base-result-previous-price.vue_rollup-plugin-vue_script.vue.js.map
|