@empathyco/x-components 6.0.0-alpha.203 → 6.0.0-alpha.205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/docs/API-reference/api/x-components.addquerytohistory.md +15 -1
  3. package/docs/API-reference/api/x-components.addquerytohistoryaction.addquerytohistory.md +15 -1
  4. package/docs/API-reference/api/x-components.addquerytohistoryaction.md +1 -1
  5. package/docs/API-reference/api/x-components.basedropdown.md +1 -1
  6. package/docs/API-reference/api/x-components.baseidmodal.md +1 -1
  7. package/docs/API-reference/api/x-components.baseresultimage.md +1 -1
  8. package/docs/API-reference/api/x-components.collapseheight.md +3 -3
  9. package/docs/API-reference/api/x-components.collapsewidth.md +3 -3
  10. package/docs/API-reference/api/x-components.createfetchandsaveactions.md +15 -1
  11. package/docs/API-reference/api/x-components.createrelatedtagsquerygetter.md +15 -1
  12. package/docs/API-reference/api/x-components.debouncefunction.md +17 -1
  13. package/docs/API-reference/api/x-components.defaultfacetsservice.clearfilterswithmetadata.md +17 -1
  14. package/docs/API-reference/api/x-components.defaultfacetsservice.md +1 -1
  15. package/docs/API-reference/api/x-components.historyqueriesgetter.historyqueries.md +15 -1
  16. package/docs/API-reference/api/x-components.historyqueriesgetter.md +1 -1
  17. package/docs/API-reference/api/x-components.isinrange.md +15 -1
  18. package/docs/API-reference/api/x-components.md +10 -10
  19. package/docs/API-reference/api/x-components.querysuggestionsgetter.md +1 -1
  20. package/docs/API-reference/api/x-components.querysuggestionsgetter.querysuggestions.md +15 -1
  21. package/docs/API-reference/api/x-components.usecollapseanimation.md +4 -4
  22. package/docs/API-reference/api/x-components.useemitdisplayevent.md +15 -1
  23. package/docs/API-reference/api/x-components.useondisplay.md +15 -1
  24. package/docs/API-reference/api/x-components.usescroll.md +15 -1
  25. package/docs/API-reference/api/x-types.suggestion.key.md +1 -1
  26. package/docs/API-reference/api/x-types.suggestion.md +4 -4
  27. package/js/components/animations/animate-scale/animate-scale.style.css.js +1 -1
  28. package/js/components/animations/use-collapse-animation.js +9 -0
  29. package/js/components/animations/use-collapse-animation.js.map +1 -1
  30. package/js/components/base-dropdown.vue.js +3 -3
  31. package/js/components/base-dropdown.vue.js.map +1 -1
  32. package/js/components/base-dropdown.vue2.js +6 -4
  33. package/js/components/base-dropdown.vue2.js.map +1 -1
  34. package/js/components/base-grid.vue.js.map +1 -1
  35. package/js/components/base-grid.vue2.js.map +1 -1
  36. package/js/components/base-rating.vue3.js +1 -1
  37. package/js/components/column-picker/base-column-picker-list.vue.js.map +1 -1
  38. package/js/components/column-picker/base-column-picker-list.vue2.js.map +1 -1
  39. package/js/components/modals/base-id-modal.vue.js +1 -1
  40. package/js/components/modals/base-id-modal.vue.js.map +1 -1
  41. package/js/components/modals/base-id-modal.vue2.js +3 -3
  42. package/js/components/modals/base-id-modal.vue2.js.map +1 -1
  43. package/js/components/panels/base-tabs-panel.vue.js +1 -1
  44. package/js/components/panels/base-tabs-panel.vue.js.map +1 -1
  45. package/js/components/panels/base-tabs-panel.vue2.js.map +1 -1
  46. package/js/components/result/base-result-current-price.vue.js +4 -3
  47. package/js/components/result/base-result-current-price.vue.js.map +1 -1
  48. package/js/components/result/base-result-current-price.vue2.js.map +1 -1
  49. package/js/components/result/base-result-image.vue.js.map +1 -1
  50. package/js/components/result/base-result-image.vue2.js +2 -1
  51. package/js/components/result/base-result-image.vue2.js.map +1 -1
  52. package/js/components/result/base-result-previous-price.vue.js +1 -1
  53. package/js/components/result/base-result-previous-price.vue.js.map +1 -1
  54. package/js/components/result/base-result-previous-price.vue2.js.map +1 -1
  55. package/js/components/sliding-panel.vue3.js +1 -1
  56. package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
  57. package/js/x-modules/facets/components/facets/facets.vue2.js.map +1 -1
  58. package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js +2 -2
  59. package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js.map +1 -1
  60. package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js.map +1 -1
  61. package/js/x-modules/facets/components/lists/filters-search.vue.js +1 -1
  62. package/js/x-modules/facets/components/lists/filters-search.vue.js.map +1 -1
  63. package/js/x-modules/facets/components/lists/filters-search.vue2.js.map +1 -1
  64. package/js/x-modules/facets/components/lists/filters-search.vue3.js +1 -1
  65. package/js/x-modules/facets/components/lists/selected-filters-list.vue.js.map +1 -1
  66. package/js/x-modules/facets/components/lists/selected-filters-list.vue2.js.map +1 -1
  67. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue.js.map +1 -1
  68. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js.map +1 -1
  69. package/js/x-modules/search/components/sort-picker-list.vue.js.map +1 -1
  70. package/js/x-modules/search/components/sort-picker-list.vue2.js.map +1 -1
  71. package/package.json +18 -18
  72. package/report/tsdoc-metadata.json +1 -1
  73. package/report/x-adapter-platform.api.json +1 -1
  74. package/report/x-components.api.json +161 -67
  75. package/report/x-components.api.md +46 -45
  76. package/report/x-types.api.json +4 -4
  77. package/types/components/animations/collapse-height.vue.d.ts +3 -3
  78. package/types/components/animations/collapse-width.vue.d.ts +3 -3
  79. package/types/components/animations/use-collapse-animation.d.ts +3 -3
  80. package/types/components/animations/use-collapse-animation.d.ts.map +1 -1
  81. package/types/components/base-dropdown.vue.d.ts +1 -1
  82. package/types/components/base-dropdown.vue.d.ts.map +1 -1
  83. package/types/components/base-grid.types.d.ts +11 -0
  84. package/types/components/base-grid.types.d.ts.map +1 -0
  85. package/types/components/base-grid.vue.d.ts +2 -10
  86. package/types/components/base-grid.vue.d.ts.map +1 -1
  87. package/types/components/column-picker/base-column-picker-list.types.d.ts +9 -0
  88. package/types/components/column-picker/base-column-picker-list.types.d.ts.map +1 -0
  89. package/types/components/column-picker/base-column-picker-list.vue.d.ts +1 -8
  90. package/types/components/column-picker/base-column-picker-list.vue.d.ts.map +1 -1
  91. package/types/components/modals/base-id-modal.vue.d.ts +1 -1
  92. package/types/components/result/base-result-image.vue.d.ts +1 -1
  93. package/types/components/result/base-result-image.vue.d.ts.map +1 -1
  94. package/types/x-modules/facets/components/facets/facets.types.d.ts +12 -0
  95. package/types/x-modules/facets/components/facets/facets.types.d.ts.map +1 -0
  96. package/types/x-modules/facets/components/facets/facets.vue.d.ts +1 -10
  97. package/types/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
  98. package/types/x-modules/facets/components/lists/selected-filters-list.types.d.ts +11 -0
  99. package/types/x-modules/facets/components/lists/selected-filters-list.types.d.ts.map +1 -0
  100. package/types/x-modules/facets/components/lists/selected-filters-list.vue.d.ts +1 -9
  101. package/types/x-modules/facets/components/lists/selected-filters-list.vue.d.ts.map +1 -1
  102. package/types/x-modules/search/components/sort-picker-list.types.d.ts +12 -0
  103. package/types/x-modules/search/components/sort-picker-list.types.d.ts.map +1 -0
  104. package/types/x-modules/search/components/sort-picker-list.vue.d.ts +1 -10
  105. package/types/x-modules/search/components/sort-picker-list.vue.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"base-result-previous-price.vue2.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\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport { defineComponent } from 'vue'\nimport BaseCurrency from '../currency/base-currency.vue'\n\n/**\n * Component that renders the {@link @empathyco/x-types#Result} previous price.\n *\n * @public\n */\nexport default defineComponent({\n components: { BaseCurrency },\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#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 an optional\n`format` prop 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 setup>\nimport { BaseResultPreviousPrice } from '@empathyco/x-components'\nconst result = {\n price: { originalValue: 199.99, hasDiscount: true },\n // ...other result properties\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 setup>\nimport { BaseResultPreviousPrice } from '@empathyco/x-components'\nconst result = {\n price: { originalValue: 199.99, hasDiscount: true },\n // ...other result properties\n}\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAsBA;;;;AAIE;AACF,gBAAe,eAAe,CAAC;IAC7B,UAAU,EAAE,EAAE,YAAW,EAAG;AAC5B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAA0B;AAChC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;;;;;;;;;;;;AAeE;AACF,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACF,KAAA;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"base-result-previous-price.vue2.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\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport { defineComponent } from 'vue'\nimport BaseCurrency from '../currency/base-currency.vue'\n\n/**\n * Component that renders the {@link @empathyco/x-types#Result} previous price.\n *\n * @public\n */\nexport default defineComponent({\n components: { BaseCurrency },\n props: {\n /**\n * (Required) The {@link @empathyco/x-types#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 an optional\n`format` prop 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 setup>\nimport { BaseResultPreviousPrice } from '@empathyco/x-components'\nconst result = {\n price: { originalValue: 199.99, hasDiscount: true },\n // ...other result properties\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 setup>\nimport { BaseResultPreviousPrice } from '@empathyco/x-components'\nconst result = {\n price: { originalValue: 199.99, hasDiscount: true },\n // ...other result properties\n}\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAsBA;;;;AAIE;AACF,gBAAe,eAAe,CAAC;IAC7B,UAAU,EAAE,EAAE,YAAW,EAAG;AAC5B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAA0B;AAChC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;;;;;;;;;;;;AAeE;AACF,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACF,KAAA;AACF,CAAA,CAAA;;;;"}
@@ -1,6 +1,6 @@
1
1
  import injectCss from '../../tools/inject-css.js';
2
2
 
3
- var css = ".x-sliding-panel[data-v-9402d5ce]{align-items:center;display:flex;flex-flow:row nowrap;position:relative}.x-sliding-panel__button[data-v-9402d5ce]{opacity:0;pointer-events:none;position:absolute;transition:all .2s ease-out;z-index:2}.x-sliding-panel-button-left[data-v-9402d5ce]{left:var(--x-sliding-panel-buttons-distance,0)}.x-sliding-panel-button-right[data-v-9402d5ce]{right:var(--x-sliding-panel-buttons-distance,0)}.x-sliding-panel__scroll[data-v-9402d5ce]{-ms-overflow-style:none;display:flex;flex:100%;flex-flow:row nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none}.x-sliding-panel__scroll[data-v-9402d5ce]::-webkit-scrollbar{display:none}.x-sliding-panel__scroll[data-v-9402d5ce]>*{flex:0 0 auto}.x-sliding-panel:not(.x-sliding-panel-show-buttons-on-hover):not(.x-sliding-panel-at-end) .x-sliding-panel-button-right[data-v-9402d5ce],.x-sliding-panel:not(.x-sliding-panel-show-buttons-on-hover):not(.x-sliding-panel-at-start) .x-sliding-panel-button-left[data-v-9402d5ce]{opacity:1;pointer-events:all}";
3
+ var css = ".x-sliding-panel[data-v-9402d5ce]{align-items:center;display:flex;flex-flow:row nowrap;position:relative}.x-sliding-panel__button[data-v-9402d5ce]{opacity:0;pointer-events:none;position:absolute;transition:all .2s ease-out;z-index:2}.x-sliding-panel-button-left[data-v-9402d5ce]{left:var(--x-sliding-panel-buttons-distance,0)}.x-sliding-panel-button-right[data-v-9402d5ce]{right:var(--x-sliding-panel-buttons-distance,0)}.x-sliding-panel__scroll[data-v-9402d5ce]{-ms-overflow-style:none;display:flex;flex:100%;flex-flow:row nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none}.x-sliding-panel__scroll[data-v-9402d5ce]::-webkit-scrollbar{display:none}.x-sliding-panel__scroll[data-v-9402d5ce]>*{flex:0 0 auto}.x-sliding-panel:not(.x-sliding-panel-show-buttons-on-hover):not(.x-sliding-panel-at-start) .x-sliding-panel-button-left[data-v-9402d5ce]{opacity:1;pointer-events:all}.x-sliding-panel:not(.x-sliding-panel-show-buttons-on-hover):not(.x-sliding-panel-at-end) .x-sliding-panel-button-right[data-v-9402d5ce]{opacity:1;pointer-events:all}";
4
4
  injectCss(css);
5
5
 
6
6
  export { css };
@@ -1 +1 @@
1
- {"version":3,"file":"facets.vue.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Custom interface to provide a slot name to a Facet.\n *\n * @internal\n */\ninterface RenderFacet {\n slotNameById: string\n slotNameByModelName: string\n facet: Facet\n}\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_renderSlot","_mergeProps","_createTextVNode","_toDisplayString"],"mappings":";;;;;;SACmC,IAAA,CAAA,SAAA,IAAAA,SAAA,EAAA,EAAjCC,WAAA,CAmDYC,wBAnDI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;IAAmB,KAAA,EAAM,eAAA;AAAA,IAAgB,WAAA,EAAU,QAAA;AAAA,IAAS,GAAA,EAAI;AAAA,GAAA,EAAA;qBAErF,MAA+E;AAAA,OAAAF,SAAA,CAAA,IAAA,CAAA,EADjFG,kBAAA;AAAA,QAiDKC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAhD+D,mBAAY,CAAA,EAApE,KAAA,EAAO,YAAA,EAAc,mBAAA,IAAuB,OAAA,KAAO;8BAD/DF,kBAAA,CAiDK,IAAA,EAAA;AAAA,YA/CF,GAAA,EAAK,OAAA;AAAA,YACN,KAAA,EAAM,qBAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,EAAA;AASF,YAAA,IAAA,CAAA,OAAA,CAAQ,YAAY,CAAA,GAD5BG,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,cANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAazE,aAAQ,mBAAmB,CAAA,GADxCD,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,qBANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAYtFD,UAAA,CAQO,wBARPC,UAAA,CAQO;AAAA,cAAA,GAAA,EAAA,CAAA;;;AANe,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAFtF,MAQO;AAAA,cAAAC,eAAA;gBAFN,eAAA,GACaC,eAAA,CAAG,KAAA,CAAM,KAAK,CAAA,GAAG,2DAAA;AAAA,gBAC/B;AAAA;AAAA;AAAA,aAAA,EAAA,IAAA;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"facets.vue.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_renderSlot","_mergeProps","_createTextVNode","_toDisplayString"],"mappings":";;;;;;SACmC,IAAA,CAAA,SAAA,IAAAA,SAAA,EAAA,EAAjCC,WAAA,CAmDYC,wBAnDI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;IAAmB,KAAA,EAAM,eAAA;AAAA,IAAgB,WAAA,EAAU,QAAA;AAAA,IAAS,GAAA,EAAI;AAAA,GAAA,EAAA;qBAErF,MAA+E;AAAA,OAAAF,SAAA,CAAA,IAAA,CAAA,EADjFG,kBAAA;AAAA,QAiDKC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAhD+D,mBAAY,CAAA,EAApE,KAAA,EAAO,YAAA,EAAc,mBAAA,IAAuB,OAAA,KAAO;8BAD/DF,kBAAA,CAiDK,IAAA,EAAA;AAAA,YA/CF,GAAA,EAAK,OAAA;AAAA,YACN,KAAA,EAAM,qBAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,EAAA;AASF,YAAA,IAAA,CAAA,OAAA,CAAQ,YAAY,CAAA,GAD5BG,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,cANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAazE,aAAQ,mBAAmB,CAAA,GADxCD,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,qBANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAYtFD,UAAA,CAQO,wBARPC,UAAA,CAQO;AAAA,cAAA,GAAA,EAAA,CAAA;;;AANe,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAFtF,MAQO;AAAA,cAAAC,eAAA;gBAFN,eAAA,GACaC,eAAA,CAAG,KAAA,CAAM,KAAK,CAAA,GAAG,2DAAA;AAAA,gBAC/B;AAAA;AAAA;AAAA,aAAA,EAAA,IAAA;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"facets.vue2.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Custom interface to provide a slot name to a Facet.\n *\n * @internal\n */\ninterface RenderFacet {\n slotNameById: string\n slotNameByModelName: string\n facet: Facet\n}\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;AA8EA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,aAAa,CAAC,IAAI;AAC3B,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE,KAAqC;;AAEhD,QAAA,aAAa,EAAE,OAAO;;AAEtB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;;;;;;;;;;;;;;;AAkBE;AACF,QAAA,gBAAgB,EAAE,MAAM;AACzB,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,KAAI,EAAG,EAAA;QACpB,MAAM,EAAE,sBAAqB,KAAM,SAAS,CAAC,KAAK,CAAA;QAClD,MAAM,EAAE,MAAK,EAAE,GAAI,SAAS,CAAC,QAAQ,CAAA;AAErC;;;;;AAKE;AACF,QAAA,MAAM,cAAa,GAAI,QAAQ,CAAoB,MAAI;AACrD,YAAA,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;gBAC3B,OAAO,MAAM,CAAC,KAAI;YACpB;iBAAO;gBACL,MAAM,cAAa,GAAI,IAAG;gBAC1B,MAAM,QAAQ,GAAa,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAM,IAAK,OAAO,CAAC,IAAI,EAAE,CAAA;gBAC1F,MAAM,QAAQ,GAAa,EAAC;gBAC5B,MAAM,QAAQ,GAAa,EAAC;AAC5B,gBAAA,QAAQ,CAAC,OAAO,CAAC,OAAM,IAAG;AACxB,oBAAA,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;AAChC,wBAAA,Q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,EAAA;AAC3B,YAAA,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAA;QACrB;QAEA,OAAO;YACL,sBAAsB;YACtB,SAAS;YACT,YAAY;YACZ,OAAO;SACT;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"facets.vue2.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;AAoEA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,aAAa,CAAC,IAAI;AAC3B,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE,KAAqC;;AAEhD,QAAA,aAAa,EAAE,OAAO;;AAEtB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;;;;;;;;;;;;;;;AAkBE;AACF,QAAA,gBAAgB,EAAE,MAAM;AACzB,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,KAAI,EAAG,EAAA;QACpB,MAAM,EAAE,sBAAqB,KAAM,SAAS,CAAC,KAAK,CAAA;QAClD,MAAM,EAAE,MAAK,EAAE,GAAI,SAAS,CAAC,QAAQ,CAAA;AAErC;;;;;AAKE;AACF,QAAA,MAAM,cAAa,GAAI,QAAQ,CAAoB,MAAI;AACrD,YAAA,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;gBAC3B,O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Q,CAAC,SAAS,CAAA;YAC9C,OAAO,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,QAAO,IAAG;gBAC1C,MAAM,UAAS,GAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;gBACrD,MAAM,UAAS,GAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AAErD,gBAAA,OAAO,mBAAkB,GAAI,UAAS,IAAK,CAAC,UAAS,GAAI,CAAC,UAAS;AACrE,YAAA,CAAC,CAAA;QACH;AAEA;;;;;;AAME;QACF,SAAS,OAAO,CAAC,IAAY,EAAA;AAC3B,YAAA,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAA;QACrB;QAEA,OAAO;YACL,sBAAsB;YACtB,SAAS;YACT,YAAY;YACZ,OAAO;SACT;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
@@ -31,7 +31,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
31
31
  value: !_ctx.isAnyRange ? _ctx.min : null,
32
32
  "data-test": "range-min",
33
33
  "aria-label": _ctx.rangeFilterMin,
34
- onChange: _cache[0] || (_cache[0] = ($event) => _ctx.setMin($event.target.valueAsNumber))
34
+ onChange: _cache[0] || (_cache[0] = ($event) => _ctx.setMin($event?.target?.valueAsNumber))
35
35
  }, null, 42, _hoisted_1),
36
36
  createElementVNode("input", {
37
37
  name: "max",
@@ -40,7 +40,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
40
40
  value: _ctx.max,
41
41
  "data-test": "range-max",
42
42
  "aria-label": _ctx.rangeFilterMax,
43
- onChange: _cache[1] || (_cache[1] = ($event) => _ctx.setMax($event.target.valueAsNumber))
43
+ onChange: _cache[1] || (_cache[1] = ($event) => _ctx.setMax($event?.target?.valueAsNumber))
44
44
  }, null, 42, _hoisted_2),
45
45
  !_ctx.isInstant ? (openBlock(), createElementBlock("button", {
46
46
  key: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"editable-number-range-filter.vue.js","sources":["../../../../../../src/x-modules/facets/components/filters/editable-number-range-filter.vue"],"sourcesContent":["<template>\n <div\n class=\"x-editable-number-range-filter\"\n :class=\"cssClasses\"\n data-test=\"editable-number-range-filter\"\n >\n <!--\n @slot Empty slot used to customize the whole component.\n @binding {min} number - Component min value.\n @binding {max} number - Component max value.\n @binding {setMin} function - Component min setter.\n @binding {setMax} function - Component max setter.\n @binding {emitUserModifiedFilter} function - It emits the\n `UserModifiedEditableNumberRangeFilter` X event.\n @binding {clearValues} function - It sets component min and max values to null.\n @binding {hasError} boolean - Returns true when there is an error with component values.\n -->\n <slot\n v-bind=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <!-- eslint-disable max-len -->\n <input\n name=\"min\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--min x-input\"\n :class=\"inputsClass\"\n :value=\"!isAnyRange ? min : null\"\n data-test=\"range-min\"\n :aria-label=\"rangeFilterMin\"\n @change=\"setMin($event.target.valueAsNumber)\"\n />\n\n <input\n name=\"max\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--max x-input\"\n :class=\"inputsClass\"\n :value=\"max\"\n data-test=\"range-max\"\n :aria-label=\"rangeFilterMax\"\n @change=\"setMax($event.target.valueAsNumber)\"\n />\n <!-- eslint-enable max-len -->\n\n <button\n v-if=\"!isInstant\"\n class=\"x-editable-number-range-filter__apply x-button\"\n :class=\"buttonsClass\"\n :disabled=\"hasError\"\n data-test=\"range-apply\"\n @click=\"emitUserModifiedFilter\"\n >\n <!--\n @slot Slot used to customize the apply button content.\n -->\n <slot name=\"apply-content\">✓</slot>\n </button>\n\n <button\n v-if=\"renderClearButton\"\n class=\"x-editable-number-range-filter__clear x-button\"\n :class=\"buttonsClass\"\n data-test=\"range-clear\"\n @click=\"clearValues\"\n >\n <!--\n @slot Slot used to customize the clear button content.\n -->\n <slot name=\"clear-content\">𐄂</slot>\n </button>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type {\n EditableNumberRangeFilter as EditableNumberRangeFilterModel,\n RangeValue,\n} from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { use$x } from '../../../../composables'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders an editable number range filter. It has two input fields to handle min and max values,\n * emitting the needed events when clicked.\n *\n * It provides a default slot, with some utils bind, to customize the whole component; and two\n * named slots `apply-content` and `clear-content` to override each button content.\n *\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\nexport default defineComponent({\n name: 'EditableNumberRangeFilter',\n xModule: facetsXModule.name,\n props: {\n /**\n * The filter data to render and edit.\n *\n * @public\n */\n filter: {\n type: Object as PropType<EditableNumberRangeFilterModel>,\n required: true,\n },\n /**\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * @public\n */\n isInstant: Boolean,\n /**\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\n hasClearButton: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n inputsClass: String,\n /** Class inherited by content element. */\n buttonsClass: String,\n },\n setup(props) {\n const $x = use$x()\n\n const rangeFilterMin = 'minimum amount'\n const rangeFilterMax = 'maximum amount'\n /**\n * Component min value.\n *\n * @internal\n */\n const min: Ref<RangeValue['min']> = ref(null)\n /**\n * Component max value.\n *\n * @internal\n */\n const max: Ref<RangeValue['max']> = ref(null)\n\n /**\n * Returns {@link @empathyco/x-types#RangeValue} with component min and max\n * values.\n *\n * @returns Range value object with component values.\n *\n * @internal\n */\n const range = computed((): RangeValue => {\n return { min: min.value, max: max.value }\n })\n\n /**\n * It checks if component min and max values are valid.\n *\n * @returns True if there is any error in the component min and max values.\n *\n * @internal\n */\n const hasError = computed(\n () => min.value !== null && max.value !== null && min.value > max.value,\n )\n\n /**\n * It checks if component min and max values are different from the ones within the filter\n * provided as property.\n *\n * @returns True if they are different.\n *\n * @internal\n */\n const areValuesDifferent = computed(\n () => min.value !== props.filter.range.min || max.value !== props.filter.range.max,\n )\n\n /**\n * Dynamic CSS classes.\n *\n * @returns Object which contains dynamic CSS classes.\n *\n * @internal\n */\n const cssClasses = computed(() => {\n return { 'x-editable-number-range-filter--error': hasError.value }\n })\n\n /**\n * Checks if the range of the filter allows any value, which happens when the min is\n * null or 0 and the max is null.\n *\n * @returns True if the range of the filter allows any value.\n *\n * @internal\n */\n const isAnyRange = computed(() => !min.value && max.value === null)\n\n /**\n * It returns true if the property `hasClearButton` is true and there are values to clear.\n *\n * @returns True if the clear button has to be rendered.\n *\n * @internal\n */\n const renderClearButton = computed(() => props.hasClearButton && !isAnyRange.value)\n\n /**\n * It emits {@link FacetsXEvents.UserModifiedEditableNumberRangeFilter} event if there are no\n * errors and component `min` and `max` values are different than `filter.range` ones.\n *\n * @internal\n */\n const emitUserModifiedFilter = () => {\n if (!hasError.value && areValuesDifferent.value) {\n $x.emit('UserModifiedEditableNumberRangeFilter', {\n ...props.filter,\n range: range.value,\n })\n }\n }\n\n /**\n * It returns the number if possible or null otherwise.\n *\n * @param value - Value.\n * @returns The element value as a number if possible or null.\n *\n * @internal\n */\n const parseRangeValue = (value: number) => (Number.isNaN(value) ? null : value)\n\n /**\n * `min` setter.\n *\n * @param value - The component `min` value to be set.\n *\n * @internal\n */\n const setMin = (value: number) => {\n min.value = parseRangeValue(value)\n }\n\n /**\n * `max` setter.\n *\n * @param value - The component `max` value to be set.\n *\n * @internal\n */\n const setMax = (value: number) => {\n max.value = parseRangeValue(value)\n }\n\n /**\n * It sets component `min` and `max` values to null , and it emits the change if component is\n * working in instant mode.\n *\n * @internal\n */\n const clearValues = () => {\n min.value = null\n max.value = null\n }\n\n /**\n * It resets the min/max range values to null if the\n * {@link FacetsXEvents.UserClickedClearAllFilters} event is fired.\n *\n * @public\n */\n $x.on('UserClickedClearAllFilters', false).subscribe(clearValues)\n\n /**\n * It watches the filter range values passed as property and updates component range values if\n * they change.\n *\n * @param newRange - New range value.\n *\n * @internal\n */\n watch(\n () => props.filter.range,\n (newRange: RangeValue) => {\n min.value = newRange.min\n max.value = newRange.max\n },\n { immediate: true, deep: true },\n )\n\n /**\n * It watches range values in order to emit the event with the change if `isInstant`\n * property is true.\n *\n * @internal\n */\n watch(\n range,\n () => {\n if (props.isInstant) {\n emitUserModifiedFilter()\n }\n },\n { deep: true },\n )\n\n return {\n rangeFilterMin,\n rangeFilterMax,\n cssClasses,\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n renderClearButton,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-editable-number-range-filter--error .x-editable-number-range-filter__input {\n border-color: red;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`UserModifiedEditableNumberRangeFilter`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n this event is emitted instantly after typing the value or clicking the submit button. The event\n payload in both cases is an object containing the filter and the new value for the range.\n\n## Example\n\nRenders an editable number range filter. It has two input fields to handle min and max values,\nemitting the needed events when clicked.\n\nIt provides a default slot, with some utils bind, to customize the whole component; and two named\nslots `apply-content` and `clear-content` to override each button content.\n\nIf `instant` prop is true, the needed events are emitted immediately; else, apply button is rendered\nto confirm to do it. False by default.\n\nIf `clear` prop is true, clear button, which sets to null component min and max values, is rendered.\nTrue by default.\n\n### Basic usage\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Properties\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" :isInstant=\"true\" :hasClearButton=\"false\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing content slots\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\">\n <template #apply-content>Apply</template>\n <template #clear-content>Clear</template>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing default slot\n\n```vue\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n #default=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <button @click=\"emitUserModifiedFilter\">✅ Apply!</button>\n <button @click=\"clearValues\">🗑 Clear!</button>\n <input :value=\"!isAnyRange ? min : null\" @change=\"setMin($event.target.valueAsNumber)\" />\n <input :value=\"max\" @change=\"setMax($event.target.valueAsNumber)\" />\n <div class=\"has-error\" v-if=\"hasError\">⚠️ Invalid range values</div>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing the items with classes\n\nThe `buttonsClass` and `inputsClass` props can be used to add classes to the inputs and buttons of\nthe component.\n\n```\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n :inputsClass=\"'my-inputs-class'\"\n :buttonsClass=\"'my-buttons-class'\"\n />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_renderSlot","_normalizeProps","_guardReactiveProps","_createElementVNode","_createTextVNode"],"mappings":";;;;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA+EM,KAAA;AAAA,IAAA;AAAA,MA9EJ,KAAA,EAAKC,cAAA,CAAA,CAAC,gCAAA,EACE,IAAA,CAAA,UAAU,CAAA,CAAA;AAAA,MAClB,WAAA,EAAU;AAAA,KAAA;;MAaVC,UAAA,CA8DO,IAAA,CAAA,MAAA,EAAA,SAAA,EAAAC,cAAA,CAAAC,kBAAA,CAAA;AAAA,QAAA,GAAA,EA7Da,IAAA,CAAA,GAAA;AAAA,QAAA,GAAA,EAAa,IAAA,CAAA,GAAA;AAAA,QAAA,MAAA,EAAa,IAAA,CAAA,MAAA;AAAA,QAAA,MAAA,EAAgB,IAAA,CAAA,MAAA;AAAA,QAAA,sBAAA,EAAgB,IAAA,CAAA,sBAAA;AAAA,QAAA,WAAA,EAAgC,IAAA,CAAA,WAAA;AAAA,QAAA,QAAA,EAAqB,IAAA,CAAA,QAAA;AAAA,QAAA,UAAA,EAAkB,IAAA,CAAA;AAAA,OAAA,CAAA,CAAA,EADrJ,MA8DO;AAAA,QAjDLC,kBAAA,CASE,OAAA,EAAA;AAAA,UARA,IAAA,EAAK,KAAA;AAAA,UAC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AAAA,UACT,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,sBAAA,IAAA,IAAA,CAAA,sBAAA,CAAA,GAAA,IAAA,CAAA;AAAA,SAAA,EAAA;AAKR,UAAAC,UAAA,CAAmC,kCAAnC,MAAmC;AAAA,YAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAI,eAAA;AAAR,cAAA,GAAA;AAAA,cAAC;AAAA;AAAA,aAAA;AAAA,WAAA,EAAA,IAAA;;QAItB,IAAA,CAAA,iBAAA,IAAAP,SAAA,EAAA,EADRC,kBAAA;AAAA,UAWS,QAAA;AAAA,UAAA;AAAA,YAAA,GAAA,EAAA,CAAA;YATP,KAAA,EAAKC,cAAA,CAAA,CAAC,kDACE,IAAA,CAAA,YAAY,CAAA,CAAA;AAAA,YACpB,WAAA,EAAU,aAAA;AAAA,YACT,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,WAAA,IAAA,IAAA,CAAA,WAAA,CAAA,GAAA,IAAA,CAAA;AAAA,WAAA;;AAKR,YAAAC,UAAA,CAAoC,kCAApC,MAAoC;AAAA,cAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAI,eAAA;AAAT,gBAAA,IAAA;AAAA,gBAAE;AAAA;AAAA,eAAA;AAAA,aAAA,EAAA,IAAA;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"editable-number-range-filter.vue.js","sources":["../../../../../../src/x-modules/facets/components/filters/editable-number-range-filter.vue"],"sourcesContent":["<template>\n <div\n class=\"x-editable-number-range-filter\"\n :class=\"cssClasses\"\n data-test=\"editable-number-range-filter\"\n >\n <!--\n @slot Empty slot used to customize the whole component.\n @binding {min} number - Component min value.\n @binding {max} number - Component max value.\n @binding {setMin} function - Component min setter.\n @binding {setMax} function - Component max setter.\n @binding {emitUserModifiedFilter} function - It emits the\n `UserModifiedEditableNumberRangeFilter` X event.\n @binding {clearValues} function - It sets component min and max values to null.\n @binding {hasError} boolean - Returns true when there is an error with component values.\n -->\n <slot\n v-bind=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <!-- eslint-disable max-len -->\n <input\n name=\"min\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--min x-input\"\n :class=\"inputsClass\"\n :value=\"!isAnyRange ? min : null\"\n data-test=\"range-min\"\n :aria-label=\"rangeFilterMin\"\n @change=\"setMin(($event?.target as HTMLInputElement)?.valueAsNumber)\"\n />\n\n <input\n name=\"max\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--max x-input\"\n :class=\"inputsClass\"\n :value=\"max\"\n data-test=\"range-max\"\n :aria-label=\"rangeFilterMax\"\n @change=\"setMax(($event?.target as HTMLInputElement)?.valueAsNumber)\"\n />\n <!-- eslint-enable max-len -->\n\n <button\n v-if=\"!isInstant\"\n class=\"x-editable-number-range-filter__apply x-button\"\n :class=\"buttonsClass\"\n :disabled=\"hasError\"\n data-test=\"range-apply\"\n @click=\"emitUserModifiedFilter\"\n >\n <!--\n @slot Slot used to customize the apply button content.\n -->\n <slot name=\"apply-content\">✓</slot>\n </button>\n\n <button\n v-if=\"renderClearButton\"\n class=\"x-editable-number-range-filter__clear x-button\"\n :class=\"buttonsClass\"\n data-test=\"range-clear\"\n @click=\"clearValues\"\n >\n <!--\n @slot Slot used to customize the clear button content.\n -->\n <slot name=\"clear-content\">𐄂</slot>\n </button>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type {\n EditableNumberRangeFilter as EditableNumberRangeFilterModel,\n RangeValue,\n} from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { use$x } from '../../../../composables'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders an editable number range filter. It has two input fields to handle min and max values,\n * emitting the needed events when clicked.\n *\n * It provides a default slot, with some utils bind, to customize the whole component; and two\n * named slots `apply-content` and `clear-content` to override each button content.\n *\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\nexport default defineComponent({\n name: 'EditableNumberRangeFilter',\n xModule: facetsXModule.name,\n props: {\n /**\n * The filter data to render and edit.\n *\n * @public\n */\n filter: {\n type: Object as PropType<EditableNumberRangeFilterModel>,\n required: true,\n },\n /**\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * @public\n */\n isInstant: Boolean,\n /**\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\n hasClearButton: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n inputsClass: String,\n /** Class inherited by content element. */\n buttonsClass: String,\n },\n setup(props) {\n const $x = use$x()\n\n const rangeFilterMin = 'minimum amount'\n const rangeFilterMax = 'maximum amount'\n /**\n * Component min value.\n *\n * @internal\n */\n const min: Ref<RangeValue['min']> = ref(null)\n /**\n * Component max value.\n *\n * @internal\n */\n const max: Ref<RangeValue['max']> = ref(null)\n\n /**\n * Returns {@link @empathyco/x-types#RangeValue} with component min and max\n * values.\n *\n * @returns Range value object with component values.\n *\n * @internal\n */\n const range = computed((): RangeValue => {\n return { min: min.value, max: max.value }\n })\n\n /**\n * It checks if component min and max values are valid.\n *\n * @returns True if there is any error in the component min and max values.\n *\n * @internal\n */\n const hasError = computed(\n () => min.value !== null && max.value !== null && min.value > max.value,\n )\n\n /**\n * It checks if component min and max values are different from the ones within the filter\n * provided as property.\n *\n * @returns True if they are different.\n *\n * @internal\n */\n const areValuesDifferent = computed(\n () => min.value !== props.filter.range.min || max.value !== props.filter.range.max,\n )\n\n /**\n * Dynamic CSS classes.\n *\n * @returns Object which contains dynamic CSS classes.\n *\n * @internal\n */\n const cssClasses = computed(() => {\n return { 'x-editable-number-range-filter--error': hasError.value }\n })\n\n /**\n * Checks if the range of the filter allows any value, which happens when the min is\n * null or 0 and the max is null.\n *\n * @returns True if the range of the filter allows any value.\n *\n * @internal\n */\n const isAnyRange = computed(() => !min.value && max.value === null)\n\n /**\n * It returns true if the property `hasClearButton` is true and there are values to clear.\n *\n * @returns True if the clear button has to be rendered.\n *\n * @internal\n */\n const renderClearButton = computed(() => props.hasClearButton && !isAnyRange.value)\n\n /**\n * It emits {@link FacetsXEvents.UserModifiedEditableNumberRangeFilter} event if there are no\n * errors and component `min` and `max` values are different than `filter.range` ones.\n *\n * @internal\n */\n const emitUserModifiedFilter = () => {\n if (!hasError.value && areValuesDifferent.value) {\n $x.emit('UserModifiedEditableNumberRangeFilter', {\n ...props.filter,\n range: range.value,\n })\n }\n }\n\n /**\n * It returns the number if possible or null otherwise.\n *\n * @param value - Value.\n * @returns The element value as a number if possible or null.\n *\n * @internal\n */\n const parseRangeValue = (value: number) => (Number.isNaN(value) ? null : value)\n\n /**\n * `min` setter.\n *\n * @param value - The component `min` value to be set.\n *\n * @internal\n */\n const setMin = (value: number) => {\n min.value = parseRangeValue(value)\n }\n\n /**\n * `max` setter.\n *\n * @param value - The component `max` value to be set.\n *\n * @internal\n */\n const setMax = (value: number) => {\n max.value = parseRangeValue(value)\n }\n\n /**\n * It sets component `min` and `max` values to null , and it emits the change if component is\n * working in instant mode.\n *\n * @internal\n */\n const clearValues = () => {\n min.value = null\n max.value = null\n }\n\n /**\n * It resets the min/max range values to null if the\n * {@link FacetsXEvents.UserClickedClearAllFilters} event is fired.\n *\n * @public\n */\n $x.on('UserClickedClearAllFilters', false).subscribe(clearValues)\n\n /**\n * It watches the filter range values passed as property and updates component range values if\n * they change.\n *\n * @param newRange - New range value.\n *\n * @internal\n */\n watch(\n () => props.filter.range,\n (newRange: RangeValue) => {\n min.value = newRange.min\n max.value = newRange.max\n },\n { immediate: true, deep: true },\n )\n\n /**\n * It watches range values in order to emit the event with the change if `isInstant`\n * property is true.\n *\n * @internal\n */\n watch(\n range,\n () => {\n if (props.isInstant) {\n emitUserModifiedFilter()\n }\n },\n { deep: true },\n )\n\n return {\n rangeFilterMin,\n rangeFilterMax,\n cssClasses,\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n renderClearButton,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-editable-number-range-filter--error .x-editable-number-range-filter__input {\n border-color: red;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`UserModifiedEditableNumberRangeFilter`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n this event is emitted instantly after typing the value or clicking the submit button. The event\n payload in both cases is an object containing the filter and the new value for the range.\n\n## Example\n\nRenders an editable number range filter. It has two input fields to handle min and max values,\nemitting the needed events when clicked.\n\nIt provides a default slot, with some utils bind, to customize the whole component; and two named\nslots `apply-content` and `clear-content` to override each button content.\n\nIf `instant` prop is true, the needed events are emitted immediately; else, apply button is rendered\nto confirm to do it. False by default.\n\nIf `clear` prop is true, clear button, which sets to null component min and max values, is rendered.\nTrue by default.\n\n### Basic usage\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Properties\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" :isInstant=\"true\" :hasClearButton=\"false\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing content slots\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\">\n <template #apply-content>Apply</template>\n <template #clear-content>Clear</template>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing default slot\n\n```vue\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n #default=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <button @click=\"emitUserModifiedFilter\">✅ Apply!</button>\n <button @click=\"clearValues\">🗑 Clear!</button>\n <input :value=\"!isAnyRange ? min : null\" @change=\"setMin($event.target.valueAsNumber)\" />\n <input :value=\"max\" @change=\"setMax($event.target.valueAsNumber)\" />\n <div class=\"has-error\" v-if=\"hasError\">⚠️ Invalid range values</div>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing the items with classes\n\nThe `buttonsClass` and `inputsClass` props can be used to add classes to the inputs and buttons of\nthe component.\n\n```\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n :inputsClass=\"'my-inputs-class'\"\n :buttonsClass=\"'my-buttons-class'\"\n />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_renderSlot","_normalizeProps","_guardReactiveProps","_createElementVNode","_createTextVNode"],"mappings":";;;;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA+EM,KAAA;AAAA,IAAA;AAAA,MA9EJ,KAAA,EAAKC,cAAA,CAAA,CAAC,gCAAA,EACE,IAAA,CAAA,UAAU,CAAA,CAAA;AAAA,MAClB,WAAA,EAAU;AAAA,KAAA;;MAaVC,UAAA,CA8DO,IAAA,CAAA,MAAA,EAAA,SAAA,EAAAC,cAAA,CAAAC,kBAAA,CAAA;AAAA,QAAA,GAAA,EA7Da,IAAA,CAAA,GAAA;AAAA,QAAA,GAAA,EAAa,IAAA,CAAA,GAAA;AAAA,QAAA,MAAA,EAAa,IAAA,CAAA,MAAA;AAAA,QAAA,MAAA,EAAgB,IAAA,CAAA,MAAA;AAAA,QAAA,sBAAA,EAAgB,IAAA,CAAA,sBAAA;AAAA,QAAA,WAAA,EAAgC,IAAA,CAAA,WAAA;AAAA,QAAA,QAAA,EAAqB,IAAA,CAAA,QAAA;AAAA,QAAA,UAAA,EAAkB,IAAA,CAAA;AAAA,OAAA,CAAA,CAAA,EADrJ,MA8DO;AAAA,QAjDLC,kBAAA,CASE,OAAA,EAAA;AAAA,UARA,IAAA,EAAK,KAAA;AAAA,UACL,IAAA,EAAK,QAAA;AAAA,UACL,KAAA,EAAKJ,cAAA,CAAA,CAAC,0FAAA,EACE,IAAA,CAAA,WAAW,CAAA,CAAA;AAAA,UAClB,KAAA,EAAK,CAAG,IAAA,CAAA,UAAA,GAAa,IAAA,CAAA,GAAA,GAAG,IAAA;AAAA,UACzB,WA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AC,UAAA,CAAmC,kCAAnC,MAAmC;AAAA,YAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAI,eAAA;AAAR,cAAA,GAAA;AAAA,cAAC;AAAA;AAAA,aAAA;AAAA,WAAA,EAAA,IAAA;;QAItB,IAAA,CAAA,iBAAA,IAAAP,SAAA,EAAA,EADRC,kBAAA;AAAA,UAWS,QAAA;AAAA,UAAA;AAAA,YAAA,GAAA,EAAA,CAAA;YATP,KAAA,EAAKC,cAAA,CAAA,CAAC,kDACE,IAAA,CAAA,YAAY,CAAA,CAAA;AAAA,YACpB,WAAA,EAAU,aAAA;AAAA,YACT,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,WAAA,IAAA,IAAA,CAAA,WAAA,CAAA,GAAA,IAAA,CAAA;AAAA,WAAA;;AAKR,YAAAC,UAAA,CAAoC,kCAApC,MAAoC;AAAA,cAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAI,eAAA;AAAT,gBAAA,IAAA;AAAA,gBAAE;AAAA;AAAA,eAAA;AAAA,aAAA,EAAA,IAAA;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"editable-number-range-filter.vue2.js","sources":["../../../../../../src/x-modules/facets/components/filters/editable-number-range-filter.vue"],"sourcesContent":["<template>\n <div\n class=\"x-editable-number-range-filter\"\n :class=\"cssClasses\"\n data-test=\"editable-number-range-filter\"\n >\n <!--\n @slot Empty slot used to customize the whole component.\n @binding {min} number - Component min value.\n @binding {max} number - Component max value.\n @binding {setMin} function - Component min setter.\n @binding {setMax} function - Component max setter.\n @binding {emitUserModifiedFilter} function - It emits the\n `UserModifiedEditableNumberRangeFilter` X event.\n @binding {clearValues} function - It sets component min and max values to null.\n @binding {hasError} boolean - Returns true when there is an error with component values.\n -->\n <slot\n v-bind=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <!-- eslint-disable max-len -->\n <input\n name=\"min\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--min x-input\"\n :class=\"inputsClass\"\n :value=\"!isAnyRange ? min : null\"\n data-test=\"range-min\"\n :aria-label=\"rangeFilterMin\"\n @change=\"setMin($event.target.valueAsNumber)\"\n />\n\n <input\n name=\"max\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--max x-input\"\n :class=\"inputsClass\"\n :value=\"max\"\n data-test=\"range-max\"\n :aria-label=\"rangeFilterMax\"\n @change=\"setMax($event.target.valueAsNumber)\"\n />\n <!-- eslint-enable max-len -->\n\n <button\n v-if=\"!isInstant\"\n class=\"x-editable-number-range-filter__apply x-button\"\n :class=\"buttonsClass\"\n :disabled=\"hasError\"\n data-test=\"range-apply\"\n @click=\"emitUserModifiedFilter\"\n >\n <!--\n @slot Slot used to customize the apply button content.\n -->\n <slot name=\"apply-content\">✓</slot>\n </button>\n\n <button\n v-if=\"renderClearButton\"\n class=\"x-editable-number-range-filter__clear x-button\"\n :class=\"buttonsClass\"\n data-test=\"range-clear\"\n @click=\"clearValues\"\n >\n <!--\n @slot Slot used to customize the clear button content.\n -->\n <slot name=\"clear-content\">𐄂</slot>\n </button>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type {\n EditableNumberRangeFilter as EditableNumberRangeFilterModel,\n RangeValue,\n} from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { use$x } from '../../../../composables'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders an editable number range filter. It has two input fields to handle min and max values,\n * emitting the needed events when clicked.\n *\n * It provides a default slot, with some utils bind, to customize the whole component; and two\n * named slots `apply-content` and `clear-content` to override each button content.\n *\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\nexport default defineComponent({\n name: 'EditableNumberRangeFilter',\n xModule: facetsXModule.name,\n props: {\n /**\n * The filter data to render and edit.\n *\n * @public\n */\n filter: {\n type: Object as PropType<EditableNumberRangeFilterModel>,\n required: true,\n },\n /**\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * @public\n */\n isInstant: Boolean,\n /**\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\n hasClearButton: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n inputsClass: String,\n /** Class inherited by content element. */\n buttonsClass: String,\n },\n setup(props) {\n const $x = use$x()\n\n const rangeFilterMin = 'minimum amount'\n const rangeFilterMax = 'maximum amount'\n /**\n * Component min value.\n *\n * @internal\n */\n const min: Ref<RangeValue['min']> = ref(null)\n /**\n * Component max value.\n *\n * @internal\n */\n const max: Ref<RangeValue['max']> = ref(null)\n\n /**\n * Returns {@link @empathyco/x-types#RangeValue} with component min and max\n * values.\n *\n * @returns Range value object with component values.\n *\n * @internal\n */\n const range = computed((): RangeValue => {\n return { min: min.value, max: max.value }\n })\n\n /**\n * It checks if component min and max values are valid.\n *\n * @returns True if there is any error in the component min and max values.\n *\n * @internal\n */\n const hasError = computed(\n () => min.value !== null && max.value !== null && min.value > max.value,\n )\n\n /**\n * It checks if component min and max values are different from the ones within the filter\n * provided as property.\n *\n * @returns True if they are different.\n *\n * @internal\n */\n const areValuesDifferent = computed(\n () => min.value !== props.filter.range.min || max.value !== props.filter.range.max,\n )\n\n /**\n * Dynamic CSS classes.\n *\n * @returns Object which contains dynamic CSS classes.\n *\n * @internal\n */\n const cssClasses = computed(() => {\n return { 'x-editable-number-range-filter--error': hasError.value }\n })\n\n /**\n * Checks if the range of the filter allows any value, which happens when the min is\n * null or 0 and the max is null.\n *\n * @returns True if the range of the filter allows any value.\n *\n * @internal\n */\n const isAnyRange = computed(() => !min.value && max.value === null)\n\n /**\n * It returns true if the property `hasClearButton` is true and there are values to clear.\n *\n * @returns True if the clear button has to be rendered.\n *\n * @internal\n */\n const renderClearButton = computed(() => props.hasClearButton && !isAnyRange.value)\n\n /**\n * It emits {@link FacetsXEvents.UserModifiedEditableNumberRangeFilter} event if there are no\n * errors and component `min` and `max` values are different than `filter.range` ones.\n *\n * @internal\n */\n const emitUserModifiedFilter = () => {\n if (!hasError.value && areValuesDifferent.value) {\n $x.emit('UserModifiedEditableNumberRangeFilter', {\n ...props.filter,\n range: range.value,\n })\n }\n }\n\n /**\n * It returns the number if possible or null otherwise.\n *\n * @param value - Value.\n * @returns The element value as a number if possible or null.\n *\n * @internal\n */\n const parseRangeValue = (value: number) => (Number.isNaN(value) ? null : value)\n\n /**\n * `min` setter.\n *\n * @param value - The component `min` value to be set.\n *\n * @internal\n */\n const setMin = (value: number) => {\n min.value = parseRangeValue(value)\n }\n\n /**\n * `max` setter.\n *\n * @param value - The component `max` value to be set.\n *\n * @internal\n */\n const setMax = (value: number) => {\n max.value = parseRangeValue(value)\n }\n\n /**\n * It sets component `min` and `max` values to null , and it emits the change if component is\n * working in instant mode.\n *\n * @internal\n */\n const clearValues = () => {\n min.value = null\n max.value = null\n }\n\n /**\n * It resets the min/max range values to null if the\n * {@link FacetsXEvents.UserClickedClearAllFilters} event is fired.\n *\n * @public\n */\n $x.on('UserClickedClearAllFilters', false).subscribe(clearValues)\n\n /**\n * It watches the filter range values passed as property and updates component range values if\n * they change.\n *\n * @param newRange - New range value.\n *\n * @internal\n */\n watch(\n () => props.filter.range,\n (newRange: RangeValue) => {\n min.value = newRange.min\n max.value = newRange.max\n },\n { immediate: true, deep: true },\n )\n\n /**\n * It watches range values in order to emit the event with the change if `isInstant`\n * property is true.\n *\n * @internal\n */\n watch(\n range,\n () => {\n if (props.isInstant) {\n emitUserModifiedFilter()\n }\n },\n { deep: true },\n )\n\n return {\n rangeFilterMin,\n rangeFilterMax,\n cssClasses,\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n renderClearButton,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-editable-number-range-filter--error .x-editable-number-range-filter__input {\n border-color: red;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`UserModifiedEditableNumberRangeFilter`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n this event is emitted instantly after typing the value or clicking the submit button. The event\n payload in both cases is an object containing the filter and the new value for the range.\n\n## Example\n\nRenders an editable number range filter. It has two input fields to handle min and max values,\nemitting the needed events when clicked.\n\nIt provides a default slot, with some utils bind, to customize the whole component; and two named\nslots `apply-content` and `clear-content` to override each button content.\n\nIf `instant` prop is true, the needed events are emitted immediately; else, apply button is rendered\nto confirm to do it. False by default.\n\nIf `clear` prop is true, clear button, which sets to null component min and max values, is rendered.\nTrue by default.\n\n### Basic usage\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Properties\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" :isInstant=\"true\" :hasClearButton=\"false\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing content slots\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\">\n <template #apply-content>Apply</template>\n <template #clear-content>Clear</template>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing default slot\n\n```vue\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n #default=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <button @click=\"emitUserModifiedFilter\">✅ Apply!</button>\n <button @click=\"clearValues\">🗑 Clear!</button>\n <input :value=\"!isAnyRange ? min : null\" @change=\"setMin($event.target.valueAsNumber)\" />\n <input :value=\"max\" @change=\"setMax($event.target.valueAsNumber)\" />\n <div class=\"has-error\" v-if=\"hasError\">⚠️ Invalid range values</div>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing the items with classes\n\nThe `buttonsClass` and `inputsClass` props can be used to add classes to the inputs and buttons of\nthe component.\n\n```\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n :inputsClass=\"'my-inputs-class'\"\n :buttonsClass=\"'my-buttons-class'\"\n />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;;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E;QACF,MAAM,WAAU,GAAI,MAAI;AACtB,YAAA,GAAG,CAAC,KAAI,GAAI,IAAG;AACf,YAAA,GAAG,CAAC,KAAI,GAAI,IAAG;AACjB,QAAA,CAAA;AAEA;;;;;AAKE;AACF,QAAA,EAAE,CAAC,EAAE,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,WAAW,CAAA;AAEhE;;;;;;;AAOE;AACF,QAAA,KAAK,CACH,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EACxB,CAAC,QAAoB,KAAG;AACtB,YAAA,GAAG,CAAC,KAAI,GAAI,QAAQ,CAAC,GAAE;AACvB,YAAA,GAAG,CAAC,KAAI,GAAI,QAAQ,CAAC,GAAE;QACzB,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAG,EAAG,CACjC;AAEA;;;;;AAKE;AACF,QAAA,KAAK,CACH,KAAK,EACL,MAAI;AACF,YAAA,IAAI,KAAK,CAAC,SAAS,EAAE;AACnB,gBAAA,sBAAsB,EAAC;YACzB;AACF,QAAA,CAAC,EACD,EAAE,IAAI,EAAE,IAAG,EAAG,CAChB;QAEA,OAAO;YACL,cAAc;YACd,cAAc;YACd,UAAU;YACV,GAAG;YACH,GAAG;YACH,MAAM;YACN,MAAM;YACN,sBAAsB;YACtB,WAAW;YACX,QAAQ;YACR,UAAU;YACV,iBAAiB;SACnB;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"editable-number-range-filter.vue2.js","sources":["../../../../../../src/x-modules/facets/components/filters/editable-number-range-filter.vue"],"sourcesContent":["<template>\n <div\n class=\"x-editable-number-range-filter\"\n :class=\"cssClasses\"\n data-test=\"editable-number-range-filter\"\n >\n <!--\n @slot Empty slot used to customize the whole component.\n @binding {min} number - Component min value.\n @binding {max} number - Component max value.\n @binding {setMin} function - Component min setter.\n @binding {setMax} function - Component max setter.\n @binding {emitUserModifiedFilter} function - It emits the\n `UserModifiedEditableNumberRangeFilter` X event.\n @binding {clearValues} function - It sets component min and max values to null.\n @binding {hasError} boolean - Returns true when there is an error with component values.\n -->\n <slot\n v-bind=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <!-- eslint-disable max-len -->\n <input\n name=\"min\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--min x-input\"\n :class=\"inputsClass\"\n :value=\"!isAnyRange ? min : null\"\n data-test=\"range-min\"\n :aria-label=\"rangeFilterMin\"\n @change=\"setMin(($event?.target as HTMLInputElement)?.valueAsNumber)\"\n />\n\n <input\n name=\"max\"\n type=\"number\"\n class=\"x-editable-number-range-filter__input x-editable-number-range-filter__input--max x-input\"\n :class=\"inputsClass\"\n :value=\"max\"\n data-test=\"range-max\"\n :aria-label=\"rangeFilterMax\"\n @change=\"setMax(($event?.target as HTMLInputElement)?.valueAsNumber)\"\n />\n <!-- eslint-enable max-len -->\n\n <button\n v-if=\"!isInstant\"\n class=\"x-editable-number-range-filter__apply x-button\"\n :class=\"buttonsClass\"\n :disabled=\"hasError\"\n data-test=\"range-apply\"\n @click=\"emitUserModifiedFilter\"\n >\n <!--\n @slot Slot used to customize the apply button content.\n -->\n <slot name=\"apply-content\">✓</slot>\n </button>\n\n <button\n v-if=\"renderClearButton\"\n class=\"x-editable-number-range-filter__clear x-button\"\n :class=\"buttonsClass\"\n data-test=\"range-clear\"\n @click=\"clearValues\"\n >\n <!--\n @slot Slot used to customize the clear button content.\n -->\n <slot name=\"clear-content\">𐄂</slot>\n </button>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type {\n EditableNumberRangeFilter as EditableNumberRangeFilterModel,\n RangeValue,\n} from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { use$x } from '../../../../composables'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders an editable number range filter. It has two input fields to handle min and max values,\n * emitting the needed events when clicked.\n *\n * It provides a default slot, with some utils bind, to customize the whole component; and two\n * named slots `apply-content` and `clear-content` to override each button content.\n *\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\nexport default defineComponent({\n name: 'EditableNumberRangeFilter',\n xModule: facetsXModule.name,\n props: {\n /**\n * The filter data to render and edit.\n *\n * @public\n */\n filter: {\n type: Object as PropType<EditableNumberRangeFilterModel>,\n required: true,\n },\n /**\n * If `instant` prop is true, the needed events are emitted immediately; else, apply button is\n * rendered to confirm to do it. False by default.\n *\n * @public\n */\n isInstant: Boolean,\n /**\n * If `clear` prop is true, clear button, which sets to null component min and max values, is\n * rendered. True by default.\n *\n * @public\n */\n hasClearButton: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n inputsClass: String,\n /** Class inherited by content element. */\n buttonsClass: String,\n },\n setup(props) {\n const $x = use$x()\n\n const rangeFilterMin = 'minimum amount'\n const rangeFilterMax = 'maximum amount'\n /**\n * Component min value.\n *\n * @internal\n */\n const min: Ref<RangeValue['min']> = ref(null)\n /**\n * Component max value.\n *\n * @internal\n */\n const max: Ref<RangeValue['max']> = ref(null)\n\n /**\n * Returns {@link @empathyco/x-types#RangeValue} with component min and max\n * values.\n *\n * @returns Range value object with component values.\n *\n * @internal\n */\n const range = computed((): RangeValue => {\n return { min: min.value, max: max.value }\n })\n\n /**\n * It checks if component min and max values are valid.\n *\n * @returns True if there is any error in the component min and max values.\n *\n * @internal\n */\n const hasError = computed(\n () => min.value !== null && max.value !== null && min.value > max.value,\n )\n\n /**\n * It checks if component min and max values are different from the ones within the filter\n * provided as property.\n *\n * @returns True if they are different.\n *\n * @internal\n */\n const areValuesDifferent = computed(\n () => min.value !== props.filter.range.min || max.value !== props.filter.range.max,\n )\n\n /**\n * Dynamic CSS classes.\n *\n * @returns Object which contains dynamic CSS classes.\n *\n * @internal\n */\n const cssClasses = computed(() => {\n return { 'x-editable-number-range-filter--error': hasError.value }\n })\n\n /**\n * Checks if the range of the filter allows any value, which happens when the min is\n * null or 0 and the max is null.\n *\n * @returns True if the range of the filter allows any value.\n *\n * @internal\n */\n const isAnyRange = computed(() => !min.value && max.value === null)\n\n /**\n * It returns true if the property `hasClearButton` is true and there are values to clear.\n *\n * @returns True if the clear button has to be rendered.\n *\n * @internal\n */\n const renderClearButton = computed(() => props.hasClearButton && !isAnyRange.value)\n\n /**\n * It emits {@link FacetsXEvents.UserModifiedEditableNumberRangeFilter} event if there are no\n * errors and component `min` and `max` values are different than `filter.range` ones.\n *\n * @internal\n */\n const emitUserModifiedFilter = () => {\n if (!hasError.value && areValuesDifferent.value) {\n $x.emit('UserModifiedEditableNumberRangeFilter', {\n ...props.filter,\n range: range.value,\n })\n }\n }\n\n /**\n * It returns the number if possible or null otherwise.\n *\n * @param value - Value.\n * @returns The element value as a number if possible or null.\n *\n * @internal\n */\n const parseRangeValue = (value: number) => (Number.isNaN(value) ? null : value)\n\n /**\n * `min` setter.\n *\n * @param value - The component `min` value to be set.\n *\n * @internal\n */\n const setMin = (value: number) => {\n min.value = parseRangeValue(value)\n }\n\n /**\n * `max` setter.\n *\n * @param value - The component `max` value to be set.\n *\n * @internal\n */\n const setMax = (value: number) => {\n max.value = parseRangeValue(value)\n }\n\n /**\n * It sets component `min` and `max` values to null , and it emits the change if component is\n * working in instant mode.\n *\n * @internal\n */\n const clearValues = () => {\n min.value = null\n max.value = null\n }\n\n /**\n * It resets the min/max range values to null if the\n * {@link FacetsXEvents.UserClickedClearAllFilters} event is fired.\n *\n * @public\n */\n $x.on('UserClickedClearAllFilters', false).subscribe(clearValues)\n\n /**\n * It watches the filter range values passed as property and updates component range values if\n * they change.\n *\n * @param newRange - New range value.\n *\n * @internal\n */\n watch(\n () => props.filter.range,\n (newRange: RangeValue) => {\n min.value = newRange.min\n max.value = newRange.max\n },\n { immediate: true, deep: true },\n )\n\n /**\n * It watches range values in order to emit the event with the change if `isInstant`\n * property is true.\n *\n * @internal\n */\n watch(\n range,\n () => {\n if (props.isInstant) {\n emitUserModifiedFilter()\n }\n },\n { deep: true },\n )\n\n return {\n rangeFilterMin,\n rangeFilterMax,\n cssClasses,\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n renderClearButton,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-editable-number-range-filter--error .x-editable-number-range-filter__input {\n border-color: red;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`UserModifiedEditableNumberRangeFilter`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n this event is emitted instantly after typing the value or clicking the submit button. The event\n payload in both cases is an object containing the filter and the new value for the range.\n\n## Example\n\nRenders an editable number range filter. It has two input fields to handle min and max values,\nemitting the needed events when clicked.\n\nIt provides a default slot, with some utils bind, to customize the whole component; and two named\nslots `apply-content` and `clear-content` to override each button content.\n\nIf `instant` prop is true, the needed events are emitted immediately; else, apply button is rendered\nto confirm to do it. False by default.\n\nIf `clear` prop is true, clear button, which sets to null component min and max values, is rendered.\nTrue by default.\n\n### Basic usage\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Properties\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\" :isInstant=\"true\" :hasClearButton=\"false\" />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing content slots\n\n```vue\n<template>\n <EditableNumberRangeFilter :filter=\"editableFilter\">\n <template #apply-content>Apply</template>\n <template #clear-content>Clear</template>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing default slot\n\n```vue\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n #default=\"{\n min,\n max,\n setMin,\n setMax,\n emitUserModifiedFilter,\n clearValues,\n hasError,\n isAnyRange,\n }\"\n >\n <button @click=\"emitUserModifiedFilter\">✅ Apply!</button>\n <button @click=\"clearValues\">🗑 Clear!</button>\n <input :value=\"!isAnyRange ? min : null\" @change=\"setMin($event.target.valueAsNumber)\" />\n <input :value=\"max\" @change=\"setMax($event.target.valueAsNumber)\" />\n <div class=\"has-error\" v-if=\"hasError\">⚠️ Invalid range values</div>\n </EditableNumberRangeFilter>\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n\n### Customizing the items with classes\n\nThe `buttonsClass` and `inputsClass` props can be used to add classes to the inputs and buttons of\nthe component.\n\n```\n<template>\n <EditableNumberRangeFilter\n :filter=\"editableFilter\"\n :inputsClass=\"'my-inputs-class'\"\n :buttonsClass=\"'my-buttons-class'\"\n />\n</template>\n\n<script setup>\nimport { EditableNumberRangeFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst editableFilter = ref({\n facetId: 'age',\n id: 'age:primary',\n label: 'primary',\n modelName: 'EditableNumberRangeFilter',\n range: {\n min: null,\n max: null,\n },\n})\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA6FA;;;;;;;;;;;;;;AAcE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,2BAA2B;IACjC,OAAO,EAAE,aAAa,CAAC,IAAI;AAC3B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAAkD;AACxD,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;;AAKE;AACF,QAAA,SAAS,EAAE,OAAO;AAClB;;;;;AAKE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,WAAW,EAAE,MAAM;;AAEnB,QAAA,YAAY,EAAE,MAAM;AACrB,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,MAAM,EAAC,GAAI,KAAK,EAAC;QAEjB,MAAM,cAAa,GAAI,gBAAe;QACtC,MAAM,cAAa,GAAI,gBAAe;AACtC;;;;AAIE;AACF,QAAA,MAAM,GAAG,GAA2B,GAAG,CAAC,IAAI,CAAA;AAC5C;;;;AAIE;AACF,QAAA,MAAM,GAAG,GAA2B,GAAG,CAAC,IAAI,CAAA;AAE5C;;;;;;;AAOE;AACF,QAAA,MAAM,KAAI,GAAI,QAAQ,CAAC,MAAgB;AACrC,YAAA,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,KAAI,EAAE;AAC1C,QAAA,CAAC,CAAA;AAED;;;;;;AAME;QACF,MAAM,QAAO,GAAI,QAAQ,CACvB,MAAM,GAAG,CAAC,KAAI,KAAM,IAAG,IAAK,GAAG,CAAC,KAAI,KAAM,IAAG,IAAK,GAAG,CAAC,KA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M,MAAK,GAAI,CAAC,KAAa,KAAG;AAC9B,YAAA,GAAG,CAAC,KAAI,GAAI,eAAe,CAAC,KAAK,CAAA;AACnC,QAAA,CAAA;AAEA;;;;;AAKE;QACF,MAAM,WAAU,GAAI,MAAI;AACtB,YAAA,GAAG,CAAC,KAAI,GAAI,IAAG;AACf,YAAA,GAAG,CAAC,KAAI,GAAI,IAAG;AACjB,QAAA,CAAA;AAEA;;;;;AAKE;AACF,QAAA,EAAE,CAAC,EAAE,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,WAAW,CAAA;AAEhE;;;;;;;AAOE;AACF,QAAA,KAAK,CACH,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EACxB,CAAC,QAAoB,KAAG;AACtB,YAAA,GAAG,CAAC,KAAI,GAAI,QAAQ,CAAC,GAAE;AACvB,YAAA,GAAG,CAAC,KAAI,GAAI,QAAQ,CAAC,GAAE;QACzB,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAG,EAAG,CACjC;AAEA;;;;;AAKE;AACF,QAAA,KAAK,CACH,KAAK,EACL,MAAI;AACF,YAAA,IAAI,KAAK,CAAC,SAAS,EAAE;AACnB,gBAAA,sBAAsB,EAAC;YACzB;AACF,QAAA,CAAC,EACD,EAAE,IAAI,EAAE,IAAG,EAAG,CAChB;QAEA,OAAO;YACL,cAAc;YACd,cAAc;YACd,UAAU;YACV,GAAG;YACH,GAAG;YACH,MAAM;YACN,MAAM;YACN,sBAAsB;YACtB,WAAW;YACX,QAAQ;YACR,UAAU;YACV,iBAAiB;SACnB;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
@@ -19,7 +19,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
19
19
  class: "x-filters-search__input x-input",
20
20
  "data-test": "filters-search-input",
21
21
  "aria-label": "search into the filter values",
22
- onInput: _cache[0] || (_cache[0] = ($event) => _ctx.setQuery($event.target.value))
22
+ onInput: _cache[0] || (_cache[0] = ($event) => _ctx.setQuery($event?.target?.value))
23
23
  }, null, 40, _hoisted_1)
24
24
  ], true),
25
25
  renderSlot(_ctx.$slots, "default", { siftedFilters: _ctx.siftedFilters }, void 0, true)
@@ -1 +1 @@
1
- {"version":3,"file":"filters-search.vue.js","sources":["../../../../../../src/x-modules/facets/components/lists/filters-search.vue"],"sourcesContent":["<template>\n <div class=\"x-filters-search\" :class=\"cssClasses\" data-test=\"filters-search\">\n <!--\n @slot Search content. It is the content which triggers the filters sifting.\n @binding {string} query - The query to search in filters.\n @binding {Function} setQuery - The function to set the query. The query is passed as\n parameter.\n @binding {Function} clearQuery - The function to clear the query.\n -->\n <slot name=\"search\" v-bind=\"{ query, setQuery, clearQuery }\">\n <input\n :value=\"query\"\n type=\"search\"\n class=\"x-filters-search__input x-input\"\n data-test=\"filters-search-input\"\n aria-label=\"search into the filter values\"\n @input=\"setQuery($event.target.value)\"\n />\n </slot>\n <!--\n @slot (Required) Sifted filters content.\n @binding {Filter[]} siftedFilters - Sifted filters data.\n -->\n <slot :sifted-filters=\"siftedFilters\"></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { DebouncedFunction, VueCSSClasses } from '../../../../utils/types'\nimport { isBooleanFilter } from '@empathyco/x-types'\nimport { computed, defineComponent, provide, ref, watch } from 'vue'\nimport { debounce } from '../../../../utils/debounce'\nimport { normalizeString } from '../../../../utils/normalize'\nimport { useFiltersInjection } from '../../composables/use-filters-injection'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders the filters sifted with the input query.\n *\n * @public\n */\nexport default defineComponent({\n name: 'FiltersSearch',\n xModule: facetsXModule.name,\n props: {\n /**\n * The list of filters to be rendered as slots.\n *\n * @public\n */\n filters: Array as PropType<Filter[]>,\n\n /**\n * This prop is used in the `HierarchicalFilter` component and only in that case. It is necessary\n * to make the `renderedFilters` to return only the filters of each level of the hierarchy.\n *\n * @public\n */\n parentId: {\n type: String as PropType<Filter['id']>,\n required: false,\n },\n\n /** The debounce time for applying the filter sifting. */\n debounceInMs: {\n type: Number,\n default: 200,\n },\n },\n setup(props) {\n const renderedFilters = useFiltersInjection(props)\n\n const query = ref('')\n let setQueryDebounced: DebouncedFunction<[string]>\n\n const debounceInMs = computed(() => props.debounceInMs)\n\n /**\n * Set the debounce function for setting the query debounced.\n *\n * @internal\n */\n const updateSetQueryDebounced = () => {\n setQueryDebounced = debounce(queryDebounced => {\n query.value = queryDebounced\n }, props.debounceInMs)\n }\n watch(debounceInMs, updateSetQueryDebounced, { immediate: true })\n\n /**\n * Sift the array of filters which matches with the query.\n *\n * @returns Array of sifted filters.\n * @internal\n */\n const siftedFilters = computed((): Filter[] => {\n const normalizedQuery = normalizeString(query.value)\n return renderedFilters.value.filter(\n filter =>\n isBooleanFilter(filter) && normalizeString(filter.label).includes(normalizedQuery),\n )\n })\n provide('filters', siftedFilters)\n\n /**\n * Adds the dynamic css classes to the component.\n *\n * @returns The class to be added to the component.\n * @internal\n */\n const cssClasses = computed((): VueCSSClasses => {\n return { 'x-filters-search--is-sifted': !!query.value }\n })\n\n /**\n * Set the query through the debounced function.\n *\n * @param query - The query to sift filters.\n * @internal\n */\n const setQuery = (query: string): void => {\n setQueryDebounced(query)\n }\n\n /**\n * Clear the query.\n *\n * @internal\n */\n const clearQuery = (): void => {\n query.value = ''\n }\n\n return {\n clearQuery,\n setQuery,\n cssClasses,\n siftedFilters,\n query,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-filters-search {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-filters-search__input::-ms-clear {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-ms-reveal {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-webkit-search-decoration,\n.x-filters-search__input::-webkit-search-cancel-button,\n.x-filters-search__input::-webkit-search-results-button,\n.x-filters-search__input::-webkit-search-results-decoration {\n display: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nIt renders an input and a list of filters passed as prop or being injected. The list of filters can\nbe sifted with the query typed in the input. This component has also a debounce prop to set the time\nin milliseconds to apply the filters search. Moreover, it has two scoped slots. The first one for\ncustomize the search triggering with three slot props; the query, a function to set the query by\nsifting and a third one for cleaning the query. The second scoped slot is required and it is for\ndisplaying the list of filters sifted. It has a slot prop with these filters sifted.\n\n### Important\n\nThe component has two ways of receive the filters list, it can be injected by another component or\nbe send it as a prop. If the component doesnt have a parent component that receive and exposed a\nfilters list to their children, it is mandatory to send it as prop.\n\n### Basic usage\n\nUsing default and required slot:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nSetting debounce time:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" :debounceInMs=\"500\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nReplacing search triggering:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\">\n <template #search=\"{ query, setQuery, clearQuery }\">\n <input\n @input=\"setQuery($event.target.value)\"\n :value=\"query\"\n class=\"x-input x-filters-search__input\"\n :aria-label=\"filtersSearchInputMessage\"\n />\n <button @click=\"clearQuery\">X</button>\n </template>\n <template #default=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </template>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\n> **Using injection**: It can receive the filters list by injection. It only works if it has a\n> parent component that receives and exposes the filters list. Using the injection, It is not\n> necessary to send the prop to the child components, it has to be send it in the parent component,\n> the rest of components will inject this list.\n\n```vue\n<template>\n <Facets v-slot=\"{ facet }\">\n <SlicedFilters :filters=\"facet.filters\" :max=\"8\">\n <FiltersSearch>\n <Filters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" data-test=\"brand-filter\" />\n </Filters>\n </FiltersSearch>\n </SlicedFilters>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\nimport { SlicedFilters, FiltersSearch, Filters, SimpleFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst facet = ref({\n filters: [\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n ],\n})\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_renderSlot","_createElementVNode"],"mappings":";;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAuBM,KAAA;AAAA,IAAA;AAAA,MAvBD,KAAA,EAAKC,cAAA,CAAA,CAAC,kBAAA,EAA2B,IAAA,CAAA,UAAU,CAAA,CAAA;AAAA,MAAE,WAAA,EAAU;AAAA,KAAA;;AAQ1D,MAAAC,UAAA,CASO,kEATuB,IAAA,CAAA,KAAA,EAAK,QAAA,EAAE,eAAQ,UAAA,EAAE,IAAA,CAAA,UAAA,MAA/C,MASO;AAAA,QARLC,kBAAA,CAOE,OAAA,EAAA;AAAA,UANC,KAAA,EAAO,IAAA,CAAA,KAAA;AAAA,UACR,IAAA,EAAK,QAAA;AAAA,UACL,KAAA,EAAM,iCAAA;AAAA,UACN,WAAA,EAAU,sBAAA;AAAA,UACV,YAAA,EAAW,+BAAA;AAAA,UACV,OAAA,EAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KAAE,IAAA,CAAA,QAAA,CAAS,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,SAAA,EAAA,IAAA,EAAA,EAAA,EAAA,UAAA;;MAOxCD,UAAA,CAA6C,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA,EAAtC,eAAgB,IAAA,CAAA,aAAA,EAAa,EAAA,MAAA,EAAA,IAAA;AAAA,KAAA;;;;;;;;;"}
1
+ {"version":3,"file":"filters-search.vue.js","sources":["../../../../../../src/x-modules/facets/components/lists/filters-search.vue"],"sourcesContent":["<template>\n <div class=\"x-filters-search\" :class=\"cssClasses\" data-test=\"filters-search\">\n <!--\n @slot Search content. It is the content which triggers the filters sifting.\n @binding {string} query - The query to search in filters.\n @binding {Function} setQuery - The function to set the query. The query is passed as\n parameter.\n @binding {Function} clearQuery - The function to clear the query.\n -->\n <slot name=\"search\" v-bind=\"{ query, setQuery, clearQuery }\">\n <input\n :value=\"query\"\n type=\"search\"\n class=\"x-filters-search__input x-input\"\n data-test=\"filters-search-input\"\n aria-label=\"search into the filter values\"\n @input=\"setQuery(($event?.target as HTMLInputElement)?.value)\"\n />\n </slot>\n <!--\n @slot (Required) Sifted filters content.\n @binding {Filter[]} siftedFilters - Sifted filters data.\n -->\n <slot :sifted-filters=\"siftedFilters\"></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { DebouncedFunction, VueCSSClasses } from '../../../../utils/types'\nimport { isBooleanFilter } from '@empathyco/x-types'\nimport { computed, defineComponent, provide, ref, watch } from 'vue'\nimport { debounce } from '../../../../utils/debounce'\nimport { normalizeString } from '../../../../utils/normalize'\nimport { useFiltersInjection } from '../../composables/use-filters-injection'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders the filters sifted with the input query.\n *\n * @public\n */\nexport default defineComponent({\n name: 'FiltersSearch',\n xModule: facetsXModule.name,\n props: {\n /**\n * The list of filters to be rendered as slots.\n *\n * @public\n */\n filters: Array as PropType<Filter[]>,\n\n /**\n * This prop is used in the `HierarchicalFilter` component and only in that case. It is necessary\n * to make the `renderedFilters` to return only the filters of each level of the hierarchy.\n *\n * @public\n */\n parentId: {\n type: String as PropType<Filter['id']>,\n required: false,\n },\n\n /** The debounce time for applying the filter sifting. */\n debounceInMs: {\n type: Number,\n default: 200,\n },\n },\n setup(props) {\n const renderedFilters = useFiltersInjection(props)\n\n const query = ref('')\n let setQueryDebounced: DebouncedFunction<[string]>\n\n const debounceInMs = computed(() => props.debounceInMs)\n\n /**\n * Set the debounce function for setting the query debounced.\n *\n * @internal\n */\n const updateSetQueryDebounced = () => {\n setQueryDebounced = debounce(queryDebounced => {\n query.value = queryDebounced\n }, props.debounceInMs)\n }\n watch(debounceInMs, updateSetQueryDebounced, { immediate: true })\n\n /**\n * Sift the array of filters which matches with the query.\n *\n * @returns Array of sifted filters.\n * @internal\n */\n const siftedFilters = computed((): Filter[] => {\n const normalizedQuery = normalizeString(query.value)\n return renderedFilters.value.filter(\n filter =>\n isBooleanFilter(filter) && normalizeString(filter.label).includes(normalizedQuery),\n )\n })\n provide('filters', siftedFilters)\n\n /**\n * Adds the dynamic css classes to the component.\n *\n * @returns The class to be added to the component.\n * @internal\n */\n const cssClasses = computed((): VueCSSClasses => {\n return { 'x-filters-search--is-sifted': !!query.value }\n })\n\n /**\n * Set the query through the debounced function.\n *\n * @param query - The query to sift filters.\n * @internal\n */\n const setQuery = (query: string): void => {\n setQueryDebounced(query)\n }\n\n /**\n * Clear the query.\n *\n * @internal\n */\n const clearQuery = (): void => {\n query.value = ''\n }\n\n return {\n clearQuery,\n setQuery,\n cssClasses,\n siftedFilters,\n query,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-filters-search {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-filters-search__input::-ms-clear {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-ms-reveal {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-webkit-search-decoration,\n.x-filters-search__input::-webkit-search-cancel-button,\n.x-filters-search__input::-webkit-search-results-button,\n.x-filters-search__input::-webkit-search-results-decoration {\n display: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nIt renders an input and a list of filters passed as prop or being injected. The list of filters can\nbe sifted with the query typed in the input. This component has also a debounce prop to set the time\nin milliseconds to apply the filters search. Moreover, it has two scoped slots. The first one for\ncustomize the search triggering with three slot props; the query, a function to set the query by\nsifting and a third one for cleaning the query. The second scoped slot is required and it is for\ndisplaying the list of filters sifted. It has a slot prop with these filters sifted.\n\n### Important\n\nThe component has two ways of receive the filters list, it can be injected by another component or\nbe send it as a prop. If the component doesnt have a parent component that receive and exposed a\nfilters list to their children, it is mandatory to send it as prop.\n\n### Basic usage\n\nUsing default and required slot:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nSetting debounce time:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" :debounceInMs=\"500\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nReplacing search triggering:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\">\n <template #search=\"{ query, setQuery, clearQuery }\">\n <input\n @input=\"setQuery($event.target.value)\"\n :value=\"query\"\n class=\"x-input x-filters-search__input\"\n :aria-label=\"filtersSearchInputMessage\"\n />\n <button @click=\"clearQuery\">X</button>\n </template>\n <template #default=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </template>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\n> **Using injection**: It can receive the filters list by injection. It only works if it has a\n> parent component that receives and exposes the filters list. Using the injection, It is not\n> necessary to send the prop to the child components, it has to be send it in the parent component,\n> the rest of components will inject this list.\n\n```vue\n<template>\n <Facets v-slot=\"{ facet }\">\n <SlicedFilters :filters=\"facet.filters\" :max=\"8\">\n <FiltersSearch>\n <Filters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" data-test=\"brand-filter\" />\n </Filters>\n </FiltersSearch>\n </SlicedFilters>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\nimport { SlicedFilters, FiltersSearch, Filters, SimpleFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst facet = ref({\n filters: [\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n ],\n})\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_renderSlot","_createElementVNode"],"mappings":";;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAuBM,KAAA;AAAA,IAAA;AAAA,MAvBD,KAAA,EAAKC,cAAA,CAAA,CAAC,kBAAA,EAA2B,IAAA,CAAA,UAAU,CAAA,CAAA;AAAA,MAAE,WAAA,EAAU;AAAA,KAAA;;AAQ1D,MAAAC,UAAA,CASO,kEATuB,IAAA,CAAA,KAAA,EAAK,QAAA,EAAE,eAAQ,UAAA,EAAE,IAAA,CAAA,UAAA,MAA/C,MASO;AAAA,QARLC,kBAAA,CAOE,OAAA,EAAA;AAAA,UANC,KAAA,EAAO,IAAA,CAAA,KAAA;AAAA,UACR,IAAA,EAAK,QAAA;AAAA,UACL,KAAA,EAAM,iCAAA;AAAA,UACN,WAAA,EAAU,sBAAA;AAAA,UACV,YAAA,EAAW,+BAAA;AAAA,UACV,OAAA,EAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KAAE,IAAA,CAAA,QAAA,CAAU,MAAA,EAAQ,QAA6B,KAAK,CAAA;AAAA,SAAA,EAAA,IAAA,EAAA,EAAA,EAAA,UAAA;;MAOhED,UAAA,CAA6C,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA,EAAtC,eAAgB,IAAA,CAAA,aAAA,EAAa,EAAA,MAAA,EAAA,IAAA;AAAA,KAAA;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"filters-search.vue2.js","sources":["../../../../../../src/x-modules/facets/components/lists/filters-search.vue"],"sourcesContent":["<template>\n <div class=\"x-filters-search\" :class=\"cssClasses\" data-test=\"filters-search\">\n <!--\n @slot Search content. It is the content which triggers the filters sifting.\n @binding {string} query - The query to search in filters.\n @binding {Function} setQuery - The function to set the query. The query is passed as\n parameter.\n @binding {Function} clearQuery - The function to clear the query.\n -->\n <slot name=\"search\" v-bind=\"{ query, setQuery, clearQuery }\">\n <input\n :value=\"query\"\n type=\"search\"\n class=\"x-filters-search__input x-input\"\n data-test=\"filters-search-input\"\n aria-label=\"search into the filter values\"\n @input=\"setQuery($event.target.value)\"\n />\n </slot>\n <!--\n @slot (Required) Sifted filters content.\n @binding {Filter[]} siftedFilters - Sifted filters data.\n -->\n <slot :sifted-filters=\"siftedFilters\"></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { DebouncedFunction, VueCSSClasses } from '../../../../utils/types'\nimport { isBooleanFilter } from '@empathyco/x-types'\nimport { computed, defineComponent, provide, ref, watch } from 'vue'\nimport { debounce } from '../../../../utils/debounce'\nimport { normalizeString } from '../../../../utils/normalize'\nimport { useFiltersInjection } from '../../composables/use-filters-injection'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders the filters sifted with the input query.\n *\n * @public\n */\nexport default defineComponent({\n name: 'FiltersSearch',\n xModule: facetsXModule.name,\n props: {\n /**\n * The list of filters to be rendered as slots.\n *\n * @public\n */\n filters: Array as PropType<Filter[]>,\n\n /**\n * This prop is used in the `HierarchicalFilter` component and only in that case. It is necessary\n * to make the `renderedFilters` to return only the filters of each level of the hierarchy.\n *\n * @public\n */\n parentId: {\n type: String as PropType<Filter['id']>,\n required: false,\n },\n\n /** The debounce time for applying the filter sifting. */\n debounceInMs: {\n type: Number,\n default: 200,\n },\n },\n setup(props) {\n const renderedFilters = useFiltersInjection(props)\n\n const query = ref('')\n let setQueryDebounced: DebouncedFunction<[string]>\n\n const debounceInMs = computed(() => props.debounceInMs)\n\n /**\n * Set the debounce function for setting the query debounced.\n *\n * @internal\n */\n const updateSetQueryDebounced = () => {\n setQueryDebounced = debounce(queryDebounced => {\n query.value = queryDebounced\n }, props.debounceInMs)\n }\n watch(debounceInMs, updateSetQueryDebounced, { immediate: true })\n\n /**\n * Sift the array of filters which matches with the query.\n *\n * @returns Array of sifted filters.\n * @internal\n */\n const siftedFilters = computed((): Filter[] => {\n const normalizedQuery = normalizeString(query.value)\n return renderedFilters.value.filter(\n filter =>\n isBooleanFilter(filter) && normalizeString(filter.label).includes(normalizedQuery),\n )\n })\n provide('filters', siftedFilters)\n\n /**\n * Adds the dynamic css classes to the component.\n *\n * @returns The class to be added to the component.\n * @internal\n */\n const cssClasses = computed((): VueCSSClasses => {\n return { 'x-filters-search--is-sifted': !!query.value }\n })\n\n /**\n * Set the query through the debounced function.\n *\n * @param query - The query to sift filters.\n * @internal\n */\n const setQuery = (query: string): void => {\n setQueryDebounced(query)\n }\n\n /**\n * Clear the query.\n *\n * @internal\n */\n const clearQuery = (): void => {\n query.value = ''\n }\n\n return {\n clearQuery,\n setQuery,\n cssClasses,\n siftedFilters,\n query,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-filters-search {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-filters-search__input::-ms-clear {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-ms-reveal {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-webkit-search-decoration,\n.x-filters-search__input::-webkit-search-cancel-button,\n.x-filters-search__input::-webkit-search-results-button,\n.x-filters-search__input::-webkit-search-results-decoration {\n display: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nIt renders an input and a list of filters passed as prop or being injected. The list of filters can\nbe sifted with the query typed in the input. This component has also a debounce prop to set the time\nin milliseconds to apply the filters search. Moreover, it has two scoped slots. The first one for\ncustomize the search triggering with three slot props; the query, a function to set the query by\nsifting and a third one for cleaning the query. The second scoped slot is required and it is for\ndisplaying the list of filters sifted. It has a slot prop with these filters sifted.\n\n### Important\n\nThe component has two ways of receive the filters list, it can be injected by another component or\nbe send it as a prop. If the component doesnt have a parent component that receive and exposed a\nfilters list to their children, it is mandatory to send it as prop.\n\n### Basic usage\n\nUsing default and required slot:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nSetting debounce time:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" :debounceInMs=\"500\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nReplacing search triggering:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\">\n <template #search=\"{ query, setQuery, clearQuery }\">\n <input\n @input=\"setQuery($event.target.value)\"\n :value=\"query\"\n class=\"x-input x-filters-search__input\"\n :aria-label=\"filtersSearchInputMessage\"\n />\n <button @click=\"clearQuery\">X</button>\n </template>\n <template #default=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </template>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\n> **Using injection**: It can receive the filters list by injection. It only works if it has a\n> parent component that receives and exposes the filters list. Using the injection, It is not\n> necessary to send the prop to the child components, it has to be send it in the parent component,\n> the rest of components will inject this list.\n\n```vue\n<template>\n <Facets v-slot=\"{ facet }\">\n <SlicedFilters :filters=\"facet.filters\" :max=\"8\">\n <FiltersSearch>\n <Filters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" data-test=\"brand-filter\" />\n </Filters>\n </FiltersSearch>\n </SlicedFilters>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\nimport { SlicedFilters, FiltersSearch, Filters, SimpleFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst facet = ref({\n filters: [\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n ],\n})\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;AAsCA;;;;AAIE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,aAAa,CAAC,IAAI;AAC3B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,OAAO,EAAE,KAA2B;AAEpC;;;;;AAKE;AACF,QAAA,QAAQ,EAAE;AACR,YAAA,IAAI,EAAE,MAAgC;AACtC,YAAA,QAAQ,EAAE,KAAK;AAChB,SAAA;;AAGD,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,GAAG;AACb,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,MAAM,eAAc,GAAI,mBAAmB,CAAC,KAAK,CAAA;AAEjD,QAAA,MAAM,KAAI,GAAI,GAAG,CAAC,EAAE,CAAA;AACpB,QAAA,IAAI,i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js","sources":["../../../../../../src/x-modules/facets/components/lists/filters-search.vue"],"sourcesContent":["<template>\n <div class=\"x-filters-search\" :class=\"cssClasses\" data-test=\"filters-search\">\n <!--\n @slot Search content. It is the content which triggers the filters sifting.\n @binding {string} query - The query to search in filters.\n @binding {Function} setQuery - The function to set the query. The query is passed as\n parameter.\n @binding {Function} clearQuery - The function to clear the query.\n -->\n <slot name=\"search\" v-bind=\"{ query, setQuery, clearQuery }\">\n <input\n :value=\"query\"\n type=\"search\"\n class=\"x-filters-search__input x-input\"\n data-test=\"filters-search-input\"\n aria-label=\"search into the filter values\"\n @input=\"setQuery(($event?.target as HTMLInputElement)?.value)\"\n />\n </slot>\n <!--\n @slot (Required) Sifted filters content.\n @binding {Filter[]} siftedFilters - Sifted filters data.\n -->\n <slot :sifted-filters=\"siftedFilters\"></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { DebouncedFunction, VueCSSClasses } from '../../../../utils/types'\nimport { isBooleanFilter } from '@empathyco/x-types'\nimport { computed, defineComponent, provide, ref, watch } from 'vue'\nimport { debounce } from '../../../../utils/debounce'\nimport { normalizeString } from '../../../../utils/normalize'\nimport { useFiltersInjection } from '../../composables/use-filters-injection'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * Renders the filters sifted with the input query.\n *\n * @public\n */\nexport default defineComponent({\n name: 'FiltersSearch',\n xModule: facetsXModule.name,\n props: {\n /**\n * The list of filters to be rendered as slots.\n *\n * @public\n */\n filters: Array as PropType<Filter[]>,\n\n /**\n * This prop is used in the `HierarchicalFilter` component and only in that case. It is necessary\n * to make the `renderedFilters` to return only the filters of each level of the hierarchy.\n *\n * @public\n */\n parentId: {\n type: String as PropType<Filter['id']>,\n required: false,\n },\n\n /** The debounce time for applying the filter sifting. */\n debounceInMs: {\n type: Number,\n default: 200,\n },\n },\n setup(props) {\n const renderedFilters = useFiltersInjection(props)\n\n const query = ref('')\n let setQueryDebounced: DebouncedFunction<[string]>\n\n const debounceInMs = computed(() => props.debounceInMs)\n\n /**\n * Set the debounce function for setting the query debounced.\n *\n * @internal\n */\n const updateSetQueryDebounced = () => {\n setQueryDebounced = debounce(queryDebounced => {\n query.value = queryDebounced\n }, props.debounceInMs)\n }\n watch(debounceInMs, updateSetQueryDebounced, { immediate: true })\n\n /**\n * Sift the array of filters which matches with the query.\n *\n * @returns Array of sifted filters.\n * @internal\n */\n const siftedFilters = computed((): Filter[] => {\n const normalizedQuery = normalizeString(query.value)\n return renderedFilters.value.filter(\n filter =>\n isBooleanFilter(filter) && normalizeString(filter.label).includes(normalizedQuery),\n )\n })\n provide('filters', siftedFilters)\n\n /**\n * Adds the dynamic css classes to the component.\n *\n * @returns The class to be added to the component.\n * @internal\n */\n const cssClasses = computed((): VueCSSClasses => {\n return { 'x-filters-search--is-sifted': !!query.value }\n })\n\n /**\n * Set the query through the debounced function.\n *\n * @param query - The query to sift filters.\n * @internal\n */\n const setQuery = (query: string): void => {\n setQueryDebounced(query)\n }\n\n /**\n * Clear the query.\n *\n * @internal\n */\n const clearQuery = (): void => {\n query.value = ''\n }\n\n return {\n clearQuery,\n setQuery,\n cssClasses,\n siftedFilters,\n query,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-filters-search {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-filters-search__input::-ms-clear {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-ms-reveal {\n display: none;\n width: 0;\n height: 0;\n}\n\n.x-filters-search__input::-webkit-search-decoration,\n.x-filters-search__input::-webkit-search-cancel-button,\n.x-filters-search__input::-webkit-search-results-button,\n.x-filters-search__input::-webkit-search-results-decoration {\n display: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nIt renders an input and a list of filters passed as prop or being injected. The list of filters can\nbe sifted with the query typed in the input. This component has also a debounce prop to set the time\nin milliseconds to apply the filters search. Moreover, it has two scoped slots. The first one for\ncustomize the search triggering with three slot props; the query, a function to set the query by\nsifting and a third one for cleaning the query. The second scoped slot is required and it is for\ndisplaying the list of filters sifted. It has a slot prop with these filters sifted.\n\n### Important\n\nThe component has two ways of receive the filters list, it can be injected by another component or\nbe send it as a prop. If the component doesnt have a parent component that receive and exposed a\nfilters list to their children, it is mandatory to send it as prop.\n\n### Basic usage\n\nUsing default and required slot:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nSetting debounce time:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\" :debounceInMs=\"500\" v-slot=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\nReplacing search triggering:\n\n```vue\n<template>\n <FiltersSearch :filters=\"filters\">\n <template #search=\"{ query, setQuery, clearQuery }\">\n <input\n @input=\"setQuery($event.target.value)\"\n :value=\"query\"\n class=\"x-input x-filters-search__input\"\n :aria-label=\"filtersSearchInputMessage\"\n />\n <button @click=\"clearQuery\">X</button>\n </template>\n <template #default=\"{ siftedFilters }\">\n <ul v-for=\"filter in siftedFilters\">\n <li :key=\"filter.id\">{{ filter.label }}</li>\n </ul>\n </template>\n </FiltersSearch>\n</template>\n\n<script setup>\nimport { FiltersSearch } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst filters = ref([\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n])\n</script>\n```\n\n> **Using injection**: It can receive the filters list by injection. It only works if it has a\n> parent component that receives and exposes the filters list. Using the injection, It is not\n> necessary to send the prop to the child components, it has to be send it in the parent component,\n> the rest of components will inject this list.\n\n```vue\n<template>\n <Facets v-slot=\"{ facet }\">\n <SlicedFilters :filters=\"facet.filters\" :max=\"8\">\n <FiltersSearch>\n <Filters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" data-test=\"brand-filter\" />\n </Filters>\n </FiltersSearch>\n </SlicedFilters>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\nimport { SlicedFilters, FiltersSearch, Filters, SimpleFilter } from '@empathyco/x-components/facets'\nimport { ref } from 'vue'\n\nconst facet = ref({\n filters: [\n { id: '1', label: 'Filter 1', modelName: 'SimpleFilter', selected: false },\n { id: '2', label: 'Filter 2', modelName: 'SimpleFilter', selected: false },\n ],\n})\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;AAsCA;;;;AAIE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,aAAa,CAAC,IAAI;AAC3B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,OAAO,EAAE,KAA2B;AAEpC;;;;;AAKE;AACF,QAAA,QAAQ,EAAE;AACR,YAAA,IAAI,EAAE,MAAgC;AACtC,YAAA,QAAQ,EAAE,KAAK;AAChB,SAAA;;AAGD,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,GAAG;AACb,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,MAAM,eAAc,G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AAQ;YACR,UAAU;YACV,aAAa;YACb,KAAK;SACP;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
@@ -1,6 +1,6 @@
1
1
  import injectCss from '../../../../../tools/inject-css.js';
2
2
 
3
- var css = ".x-filters-search[data-v-4979a051]{display:flex;flex-flow:column nowrap}.x-filters-search__input[data-v-4979a051]::-ms-clear,.x-filters-search__input[data-v-4979a051]::-ms-reveal{display:none;height:0;width:0}.x-filters-search__input[data-v-4979a051]::-webkit-search-cancel-button,.x-filters-search__input[data-v-4979a051]::-webkit-search-decoration,.x-filters-search__input[data-v-4979a051]::-webkit-search-results-button,.x-filters-search__input[data-v-4979a051]::-webkit-search-results-decoration{display:none}";
3
+ var css = ".x-filters-search[data-v-4979a051]{display:flex;flex-flow:column nowrap}.x-filters-search__input[data-v-4979a051]::-ms-clear{display:none;height:0;width:0}.x-filters-search__input[data-v-4979a051]::-ms-reveal{display:none;height:0;width:0}.x-filters-search__input[data-v-4979a051]::-webkit-search-cancel-button,.x-filters-search__input[data-v-4979a051]::-webkit-search-decoration,.x-filters-search__input[data-v-4979a051]::-webkit-search-results-button,.x-filters-search__input[data-v-4979a051]::-webkit-search-results-decoration{display:none}";
4
4
  injectCss(css);
5
5
 
6
6
  export { css };