@empathyco/x-components 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/core/index.js.map +1 -1
- package/docs/API-reference/api/x-adapter-platform.facetschema.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformfacet.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.platformfacet.values.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.platformfacettype.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.max.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.md +90 -0
- package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.min.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformsliderfilter.unit.md +11 -0
- package/docs/API-reference/api/x-components.baseslider.md +2 -8
- package/docs/API-reference/api/x-components.facetsxevents.md +19 -0
- package/docs/API-reference/api/x-components.facetsxevents.usermodifiedsliderfilter.md +13 -0
- package/docs/API-reference/api/x-components.hierarchicalfilter.md +1 -0
- package/docs/API-reference/api/x-components.simplefilter.md +1 -0
- package/docs/API-reference/api/x-components.snippetcallbacks.md +1 -0
- package/docs/API-reference/api/x-types.facetmodelname.md +1 -1
- package/docs/API-reference/api/x-types.filtermodelname.md +1 -1
- package/docs/API-reference/api/x-types.issliderfacet.md +56 -0
- package/docs/API-reference/api/x-types.issliderfilter.md +56 -0
- package/docs/API-reference/api/x-types.md +44 -0
- package/docs/API-reference/api/x-types.sliderfacet.filters.md +13 -0
- package/docs/API-reference/api/x-types.sliderfacet.md +78 -0
- package/docs/API-reference/api/x-types.sliderfacet.modelname.md +13 -0
- package/docs/API-reference/api/x-types.sliderfilter.md +116 -0
- package/docs/API-reference/api/x-types.sliderfilter.modelname.md +13 -0
- package/docs/API-reference/api/x-types.sliderfilter.range.md +16 -0
- package/docs/API-reference/api/x-types.sliderfilter.selectedrange.md +13 -0
- package/docs/API-reference/api/x-types.sliderfilter.unit.md +13 -0
- package/docs/API-reference/components/common/x-components.base-slider.md +1 -1
- package/docs/API-reference/components/facets/x-components.filters/slider-filter.md +33 -0
- package/facets/index.js +1 -0
- package/js/components/base-slider.vue.js +12 -3
- package/js/components/base-slider.vue.js.map +1 -1
- package/js/components/base-slider.vue2.js +1 -1
- package/js/components/base-slider.vue2.js.map +1 -1
- package/js/index.js +1 -0
- package/js/index.js.map +1 -1
- package/js/x-modules/facets/entities/filter-entity.factory.js +2 -0
- package/js/x-modules/facets/entities/filter-entity.factory.js.map +1 -1
- package/js/x-modules/facets/entities/slider-filter.entity.js +107 -0
- package/js/x-modules/facets/entities/slider-filter.entity.js.map +1 -0
- package/js/x-modules/facets/wiring.js +3 -0
- package/js/x-modules/facets/wiring.js.map +1 -1
- package/package.json +4 -4
- package/report/x-adapter-platform.api.json +130 -4
- package/report/x-components.api.json +88 -6
- package/report/x-components.api.md +30 -13
- package/report/x-types.api.json +351 -2
- package/types/src/components/base-slider.vue.d.ts +3 -8
- package/types/src/components/base-slider.vue.d.ts.map +1 -1
- package/types/src/components/snippet-callbacks.vue.d.ts +1 -0
- package/types/src/components/snippet-callbacks.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts +1 -0
- package/types/src/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/simple-filter.vue.d.ts +1 -0
- package/types/src/x-modules/facets/components/filters/simple-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/entities/filter-entity.factory.d.ts.map +1 -1
- package/types/src/x-modules/facets/entities/index.d.ts +1 -0
- package/types/src/x-modules/facets/entities/index.d.ts.map +1 -1
- package/types/src/x-modules/facets/entities/slider-filter.entity.d.ts +65 -0
- package/types/src/x-modules/facets/entities/slider-filter.entity.d.ts.map +1 -0
- package/types/src/x-modules/facets/events.types.d.ts +6 -1
- package/types/src/x-modules/facets/events.types.d.ts.map +1 -1
- package/types/src/x-modules/facets/wiring.d.ts +3 -0
- package/types/src/x-modules/facets/wiring.d.ts.map +1 -1
- package/types/src/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts.map +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-types](./x-types.md) > [SliderFilter](./x-types.sliderfilter.md)
|
|
4
|
+
|
|
5
|
+
## SliderFilter interface
|
|
6
|
+
|
|
7
|
+
A type of filter used in [SliderFacet](./x-types.sliderfacet.md) and extends from [FacetFilter](./x-types.facetfilter.md)<!-- -->. This filter has the particularity that its [RangeValue](./x-types.rangevalue.md) is editable by the user. Editable means that the value max and min can be changed by the user instead of having several boolean filters with different values.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export interface SliderFilter extends FacetFilter
|
|
13
|
+
```
|
|
14
|
+
**Extends:** [FacetFilter](./x-types.facetfilter.md)
|
|
15
|
+
|
|
16
|
+
## Properties
|
|
17
|
+
|
|
18
|
+
<table><thead><tr><th>
|
|
19
|
+
|
|
20
|
+
Property
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
</th><th>
|
|
24
|
+
|
|
25
|
+
Modifiers
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</th><th>
|
|
29
|
+
|
|
30
|
+
Type
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
</th><th>
|
|
34
|
+
|
|
35
|
+
Description
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
</th></tr></thead>
|
|
39
|
+
<tbody><tr><td>
|
|
40
|
+
|
|
41
|
+
[modelName](./x-types.sliderfilter.modelname.md)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
</td><td>
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
</td><td>
|
|
48
|
+
|
|
49
|
+
'SliderFilter'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
</td><td>
|
|
53
|
+
|
|
54
|
+
Model name to indicate the filter type.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
</td></tr>
|
|
58
|
+
<tr><td>
|
|
59
|
+
|
|
60
|
+
[range](./x-types.sliderfilter.range.md)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
</td><td>
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
</td><td>
|
|
67
|
+
|
|
68
|
+
{ min: number; max: number; }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
</td><td>
|
|
72
|
+
|
|
73
|
+
boundary range.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
</td></tr>
|
|
77
|
+
<tr><td>
|
|
78
|
+
|
|
79
|
+
[selectedRange](./x-types.sliderfilter.selectedrange.md)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
</td><td>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
</td><td>
|
|
86
|
+
|
|
87
|
+
[RangeValue](./x-types.rangevalue.md)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
</td><td>
|
|
91
|
+
|
|
92
|
+
Filter range to use in the frontend.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
</td></tr>
|
|
96
|
+
<tr><td>
|
|
97
|
+
|
|
98
|
+
[unit](./x-types.sliderfilter.unit.md)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
</td><td>
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
</td><td>
|
|
105
|
+
|
|
106
|
+
Intl.NumberFormatOptions\['style'\]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
</td><td>
|
|
110
|
+
|
|
111
|
+
Units to format the values of the ranges. Currently unused, reserved for future formatting.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
</td></tr>
|
|
115
|
+
</tbody></table>
|
|
116
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-types](./x-types.md) > [SliderFilter](./x-types.sliderfilter.md) > [modelName](./x-types.sliderfilter.modelname.md)
|
|
4
|
+
|
|
5
|
+
## SliderFilter.modelName property
|
|
6
|
+
|
|
7
|
+
Model name to indicate the filter type.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
modelName: 'SliderFilter';
|
|
13
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-types](./x-types.md) > [SliderFilter](./x-types.sliderfilter.md) > [range](./x-types.sliderfilter.range.md)
|
|
4
|
+
|
|
5
|
+
## SliderFilter.range property
|
|
6
|
+
|
|
7
|
+
boundary range.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
range: {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
};
|
|
16
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-types](./x-types.md) > [SliderFilter](./x-types.sliderfilter.md) > [selectedRange](./x-types.sliderfilter.selectedrange.md)
|
|
4
|
+
|
|
5
|
+
## SliderFilter.selectedRange property
|
|
6
|
+
|
|
7
|
+
Filter range to use in the frontend.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
selectedRange: RangeValue;
|
|
13
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-types](./x-types.md) > [SliderFilter](./x-types.sliderfilter.md) > [unit](./x-types.sliderfilter.unit.md)
|
|
4
|
+
|
|
5
|
+
## SliderFilter.unit property
|
|
6
|
+
|
|
7
|
+
Units to format the values of the ranges. Currently unused, reserved for future formatting.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
unit: Intl.NumberFormatOptions['style'];
|
|
13
|
+
```
|
|
@@ -18,7 +18,7 @@ for the slider implementation.
|
|
|
18
18
|
| Name | Description | Type | Default |
|
|
19
19
|
| ------------------------- | ----------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------- |
|
|
20
20
|
| <code>threshold</code> | The threshold prop sets the limits for the slider. | <code>{ min: number; max: number }</code> | <code>() => ({ min: 0, max: Number.MAX_SAFE_INTEGER })</code> |
|
|
21
|
-
| <code>modelValue</code> | The modelValue prop sets the initial values for the slider. | <code>
|
|
21
|
+
| <code>modelValue</code> | The modelValue prop sets the initial values for the slider. | <code>RangeValue</code> | <code></code> |
|
|
22
22
|
| <code>contentClass</code> | Class to be able to customize slider styles. | <code>string</code> | <code>''</code> |
|
|
23
23
|
|
|
24
24
|
## Events
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
title: SliderFilter
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SliderFilter
|
|
8
|
+
|
|
9
|
+
Renders a slider filter with editable minimum and maximum values.
|
|
10
|
+
|
|
11
|
+
Users can select a range using the slider or by entering the minimum and
|
|
12
|
+
maximum values directly.
|
|
13
|
+
|
|
14
|
+
In instant mode, valid changes are emitted automatically. Otherwise, the
|
|
15
|
+
apply button is rendered and changes are emitted when it is clicked.
|
|
16
|
+
|
|
17
|
+
The clear action resets the selected range to the slider boundaries.
|
|
18
|
+
|
|
19
|
+
The default slot exposes the selected range, slider boundaries, validation
|
|
20
|
+
state, and methods to update, apply, or clear the selected values.
|
|
21
|
+
|
|
22
|
+
## Props
|
|
23
|
+
|
|
24
|
+
| Name | Description | Type | Default |
|
|
25
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------- |
|
|
26
|
+
| <code>filter</code> | The slider filter data to render and edit. | <code>SliderFilterModel</code> | <code></code> |
|
|
27
|
+
| <code>isInstant</code> | Whether changes should be emitted immediately.<br /><br />When false, the apply button is rendered and changes are emitted when<br />the user clicks it. | <code>boolean</code> | <code></code> |
|
|
28
|
+
|
|
29
|
+
## Slots
|
|
30
|
+
|
|
31
|
+
| Name | Description | Bindings<br />(name - type - description) |
|
|
32
|
+
| -------------------- | ------------------------------------------- | ----------------------------------------- |
|
|
33
|
+
| <code>default</code> | Slot used to customize the whole component. | <br /><br /><br /><br /><br /><br /> |
|
package/facets/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export { NumberRangeFilterEntity } from '../js/x-modules/facets/entities/number-
|
|
|
24
24
|
export { RawFilterEntity } from '../js/x-modules/facets/entities/raw-filter.entity.js';
|
|
25
25
|
export { SimpleFilterEntity } from '../js/x-modules/facets/entities/simple-filter.entity.js';
|
|
26
26
|
export { SingleSelectModifier } from '../js/x-modules/facets/entities/single-select.modifier.js';
|
|
27
|
+
export { SliderFilterEntity } from '../js/x-modules/facets/entities/slider-filter.entity.js';
|
|
27
28
|
export { StickyModifier } from '../js/x-modules/facets/entities/sticky.modifier.js';
|
|
28
29
|
export { BaseFilterEntityModifier } from '../js/x-modules/facets/entities/types.js';
|
|
29
30
|
export { DefaultFacetsService } from '../js/x-modules/facets/service/facets.service.js';
|
|
@@ -3,10 +3,19 @@ import { openBlock, createElementBlock, createElementVNode, normalizeClass, rend
|
|
|
3
3
|
import './base-slider.vue3.js';
|
|
4
4
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
5
5
|
|
|
6
|
-
const _hoisted_1 = {
|
|
6
|
+
const _hoisted_1 = {
|
|
7
|
+
class: "x-base-slider",
|
|
8
|
+
"data-test": "base-slider"
|
|
9
|
+
};
|
|
7
10
|
const _hoisted_2 = { class: "x-base-slider__selected" };
|
|
8
|
-
const _hoisted_3 = {
|
|
9
|
-
|
|
11
|
+
const _hoisted_3 = {
|
|
12
|
+
class: "x-base-slider__selected-min",
|
|
13
|
+
"data-test": "base-slider-min"
|
|
14
|
+
};
|
|
15
|
+
const _hoisted_4 = {
|
|
16
|
+
class: "x-base-slider__selected-max",
|
|
17
|
+
"data-test": "base-slider-max"
|
|
18
|
+
};
|
|
10
19
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
11
20
|
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
12
21
|
createElementVNode(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-slider.vue.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<{ min: number; max: number }>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch(\n () => props.threshold,\n ({ min, max }) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n },\n )\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min < props.threshold.min ? props.threshold.min : min\n const maxValidated = max > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_toDisplayString"],"mappings":";;;;;AACO,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,eAAA,EAAe;AAEnB,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,yBAAA,EAAyB;AAO7B,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,6BAAA,EAA6B;AAMnC,MA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AAA,YAAA;AAAA;AAAA;AAAA,SAAA;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"base-slider.vue.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\" data-test=\"base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\" data-test=\"base-slider-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\" data-test=\"base-slider-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { RangeValue } from '@empathyco/x-types'\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<RangeValue>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n })\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min! < props.threshold.min ? props.threshold.min : min\n const maxValidated = max! > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_toDisplayString"],"mappings":";;;;;;EACO,KAAA,EAAM,eAAA;AAAA,EAAgB,WAAA,EAAU;;AAE9B,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,yBAAA,EAAyB;;EAO7B,KAAA,EAAM,6BAAA;AAAA,EAA8B,WAAA,EAAU;;;EAM9C,KAAA,EAAM,6BAAA;AAAA,EAA8B,WAAA,EAAU;;;AAfvD,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA,CAuBM,OAvBN,UAAA,EAuBM;AAAA,IAtBJC,kBAAA;AAAA,MAAqF,KAAA;AAAA,MAAA;AAAA,QAAhF,GAAA,EAAI,QAAA;AAAA,QAAU,KAAA,EAAKC,cAAA,CAAA,CAAA,2BAAA,CAAA,CAAgC,MAAA,CAAM,CAAA,EAAI,IAAA,CAAA,YAAY,CAAA,CAAA,CAAA;AAAA,OAAA;;;;;AAC9E,IAAAD,kBAAA,CAoBM,OApBN,UAAA,EAoBM;AAAA,MAdJE,UAAA,CAaO,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA,EAbA,aAAA,EAAgB,IAAA,CAAA,aAAA,IAAvB,MAaO;AAAA,QAZLF,kBAAA,CAKI,KALJ,UAAA,EAKI;AAAA,UAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAJFA,kBAAA;AAAA,YAAsB,MAAA;AAAA,YAAA,IAAA;AAAA,YAAhB,WAAA;AAAA,YAAS;AAAA;AAAA,WAAA,CAAA;AAAA,UACfA,kBAAA;AAAA,YAEO,MAAA;AAAA,YAAA,IAAA;AAAA,YAAAG,eAAA,CADF,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA,CAAA;AAAA,YAAA;AAAA;AAAA;AAAA,SAAA,CAAA;AAGpB,QAAAH,kBAAA,CAKI,KALJ,UAAA,EAKI;AAAA,UAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAJFA,kBAAA;AAAA,YAAsB,MAAA;AAAA,YAAA,IAAA;AAAA,YAAhB,WAAA;AAAA,YAAS;AAAA;AAAA,WAAA,CAAA;AAAA,UACfA,kBAAA;AAAA,YAEO,MAAA;AAAA,YAAA,IAAA;AAAA,YAAAG,eAAA,CADF,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA,CAAA;AAAA,YAAA;AAAA;AAAA;AAAA,SAAA;;;;;;;;;"}
|
|
@@ -71,7 +71,7 @@ var _sfc_main = defineComponent({
|
|
|
71
71
|
/**
|
|
72
72
|
* Watch the threshold prop to update the slider state and emit the selected values.
|
|
73
73
|
*/
|
|
74
|
-
watch(() => props.threshold, (
|
|
74
|
+
watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {
|
|
75
75
|
sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false);
|
|
76
76
|
emit('update:modelValue', { min, max });
|
|
77
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-slider.vue2.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<{ min: number; max: number }>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch(\n () => props.threshold,\n ({ min, max }) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n },\n )\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min < props.threshold.min ? props.threshold.min : min\n const maxValidated = max > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAiCA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,gBAAe,EAAG,CAAC;AAC1D,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA;AACF,KAAA;AACD;;;AAGE;IACF,KAAK,EAAE,CAAC,mBAAmB,CAAC;AAC5B,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,IAAG,EAAG,EAAA;;AAEnB,QAAA,IAAI,cAAkB;;AAEtB,QAAA,MAAM,MAA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A;QAED,OAAO;YACL,MAAM;YACN,aAAa;SACf;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"base-slider.vue2.js","sources":["../../../src/components/base-slider.vue"],"sourcesContent":["<template>\n <div class=\"x-base-slider\" data-test=\"base-slider\">\n <div ref=\"slider\" :class=\"['x-base-slider__nouislider'].concat(`${contentClass}`)\" />\n <div class=\"x-base-slider__selected\">\n <!--\n @slot Default selected range rendering. This slot will be used by default for rendering\n the selected range without an specific slot implementation.\n @binding {number[]} rangeSelected - The selected range values. Min position 0, Max position 1.\n -->\n <slot :range-selected=\"rangeSelected\">\n <p class=\"x-base-slider__selected-min\" data-test=\"base-slider-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\" data-test=\"base-slider-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </slot>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { RangeValue } from '@empathyco/x-types'\nimport type { API } from 'nouislider'\nimport type { PropType } from 'vue'\nimport { create } from 'nouislider'\nimport { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'\n\n/**\n * This component implements a range slider and prints the selected values.\n * It receives a threshold prop to set the limits and uses v-model to get and set\n * the selected values.\n *\n * It makes use of the nouslider library @see https://refreshless.com/nouislider/\n * for the slider implementation.\n *\n */\nexport default defineComponent({\n name: 'BaseSlider',\n props: {\n /** The threshold prop sets the limits for the slider. */\n threshold: {\n type: Object as PropType<{ min: number; max: number }>,\n default: () => ({ min: 0, max: Number.MAX_SAFE_INTEGER }),\n },\n /** The modelValue prop sets the initial values for the slider. */\n modelValue: {\n type: Object as PropType<RangeValue>,\n required: true,\n },\n /** Class to be able to customize slider styles. */\n contentClass: {\n type: String,\n default: '',\n },\n },\n /**\n * The component emits an event with the selected values whenever\n * the user changes the slider.\n */\n emits: ['update:modelValue'],\n setup(props, { emit }) {\n /** The nouislider instance. */\n let sliderInstance: API\n /** The nouislider element reference. */\n const slider = ref<HTMLElement>()\n\n /** The selected min value. */\n const minSelected = ref(props.modelValue?.min ?? props.threshold.min)\n /** The selected max value. */\n const maxSelected = ref(props.modelValue?.max ?? props.threshold.max)\n\n /** The selected range as an array. */\n const rangeSelected = computed(() => [minSelected.value, maxSelected.value])\n /** The range for the nouislider. */\n const slideRange = computed(() => ({ min: props.threshold.min, max: props.threshold.max }))\n\n onMounted(() => {\n // Create the slider instance\n sliderInstance = create(slider.value!, {\n start: rangeSelected.value,\n range: slideRange.value,\n step: 1,\n connect: true,\n margin: 1,\n })\n\n // Update the selected values when the slider update its values\n sliderInstance.on('update', ([min, max]) => {\n minSelected.value = Number(min)\n maxSelected.value = Number(max)\n })\n\n // Emits the selected values when the slider values change\n sliderInstance.on('change', () =>\n emit('update:modelValue', { min: minSelected.value, max: maxSelected.value }),\n )\n })\n\n onUnmounted(() => {\n // Waiting to finish the collapse animation before destroying it\n setTimeout(sliderInstance.destroy.bind(sliderInstance), 600)\n })\n\n /**\n * Watch the threshold prop to update the slider state and emit the selected values.\n */\n watch([() => props.threshold.min, () => props.threshold.max], ([min, max]) => {\n sliderInstance.updateOptions({ range: slideRange.value, start: [min, max] }, false)\n emit('update:modelValue', { min, max })\n })\n\n /**\n * Watch the modelValue prop to update the slider state.\n *\n * @remarks It only update the values if the values are corrects. It means,\n * values within the threshold limits and not equal to the current values.\n *\n * @returns Undefined.\n */\n watch([() => props.modelValue.min, () => props.modelValue.max], ([min, max]) => {\n // Check if the values are the same\n if (min === minSelected.value && max === maxSelected.value) {\n return\n }\n\n // Validate the values\n const minValidated = min! < props.threshold.min ? props.threshold.min : min\n const maxValidated = max! > props.threshold.max ? props.threshold.max : max\n\n // Update the nouislider values\n sliderInstance.set([minValidated, maxValidated])\n\n // Emit the selected values\n if (minValidated !== min || maxValidated !== max) {\n emit('update:modelValue', { min: minValidated, max: maxValidated })\n }\n })\n\n return {\n slider,\n rangeSelected,\n }\n },\n})\n</script>\n<style lang=\"css\">\n@import 'nouislider/dist/nouislider.css';\n/** Customize nouislider styles: https://refreshless.com/nouislider/examples/#section-styling */\n\n.x-base-slider {\n gap: 16px;\n}\n\n.x-base-slider,\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n display: flex;\n flex-flow: column nowrap;\n}\n\n.x-base-slider__selected {\n display: inline-flex;\n}\n\n.x-base-slider__selected-min,\n.x-base-slider__selected-max {\n flex: 50%;\n}\n\n.x-base-slider__nouislider {\n margin: 16px 0;\n padding: 0 16px;\n}\n\n.x-base-slider__nouislider .noUi-handle {\n box-shadow: none;\n}\n\n.x-base-slider__nouislider .noUi-handle:before,\n.x-base-slider__nouislider .noUi-handle:after {\n content: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a slider and the selected values. The component needs the threshold for the\nslider, although is not required (If not passed, fallback is min: 0, max: Number.MAX_SAFE_INTEGER ),\nwhich are passed using the `threshold` prop and the selected range, which is passed in using the\nv-model.\n\n### Default usage\n\nIt is required to send the value prop which holds the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst selectedRange = ref({ min: 0, max: 1000 })\n</script>\n```\n\n#### With threshold\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" />\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\n### Customized usage\n\n#### Overriding the slots\n\nIt is possible to override the default slot to customize the layout for the selected values.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\" v-slot=\"{ rangeSelected }\">\n <p class=\"x-base-slider__selected-min\">\n <span>min value</span>\n <span>\n {{ rangeSelected[0] }}\n </span>\n </p>\n <p class=\"x-base-slider__selected-max\">\n <span>max value</span>\n <span>\n {{ rangeSelected[1] }}\n </span>\n </p>\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n\nIt is also possible to add inputs to complement the slider and allow to change the selected values\nmanually.\n\n```vue live\n<template>\n <BaseSlider v-model=\"selectedRange\" :threshold=\"threshold\">\n <input\n @change=\"selectedRange.min = $event.target?.valueAsNumber || 0\"\n class=\"xds:input\"\n name=\"min\"\n type=\"number\"\n :value=\"selectedRange.min\"\n :aria-label=\"'min'\"\n />\n\n <input\n @change=\"selectedRange.max = $event.target?.valueAsNumber || 1000000\"\n style=\"display: block\"\n class=\"xds:input\"\n name=\"max\"\n type=\"number\"\n :value=\"selectedRange.max\"\n :aria-label=\"'max'\"\n />\n </BaseSlider>\n</template>\n\n<script setup>\nimport { BaseSlider } from '@empathyco/x-components'\nimport { ref } from 'vue'\nconst threshold = { min: 0, max: 1000 }\nconst selectedRange = ref({ ...threshold })\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;AAkCA;;;;;;;;AAQE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,MAAgD;AACtD,YAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,gBAAe,EAAG,CAAC;AAC1D,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,MAA8B;AACpC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA;AACF,KAAA;AACD;;;AAGE;IACF,KAAK,EAAE,CAAC,mBAAmB,CAAC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;YAG/C,IAAI,YAAW,KAAM,GAAE,IAAK,iBAAiB,GAAG,EAAE;AAChD,gBAAA,IAAI,CAAC,mBAAmB,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,YAAW,EAAG,CAAA;YACpE;AACF,QAAA,CAAC,CAAA;QAED,OAAO;YACL,MAAM;YACN,aAAa;SACf;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
package/js/index.js
CHANGED
|
@@ -276,6 +276,7 @@ export { NumberRangeFilterEntity } from './x-modules/facets/entities/number-rang
|
|
|
276
276
|
export { RawFilterEntity } from './x-modules/facets/entities/raw-filter.entity.js';
|
|
277
277
|
export { SimpleFilterEntity } from './x-modules/facets/entities/simple-filter.entity.js';
|
|
278
278
|
export { SingleSelectModifier } from './x-modules/facets/entities/single-select.modifier.js';
|
|
279
|
+
export { SliderFilterEntity } from './x-modules/facets/entities/slider-filter.entity.js';
|
|
279
280
|
export { StickyModifier } from './x-modules/facets/entities/sticky.modifier.js';
|
|
280
281
|
export { BaseFilterEntityModifier } from './x-modules/facets/entities/types.js';
|
|
281
282
|
export { DefaultFacetsService } from './x-modules/facets/service/facets.service.js';
|
package/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -6,6 +6,7 @@ import { HierarchicalFilterEntity } from './hierarchical-filter.entity.js';
|
|
|
6
6
|
import { NumberRangeFilterEntity } from './number-range-filter.entity.js';
|
|
7
7
|
import { RawFilterEntity } from './raw-filter.entity.js';
|
|
8
8
|
import { SimpleFilterEntity } from './simple-filter.entity.js';
|
|
9
|
+
import { SliderFilterEntity } from './slider-filter.entity.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Creates {@link FilterEntity | FilterEntities} based on the provided configs.
|
|
@@ -24,6 +25,7 @@ class FilterEntityFactory {
|
|
|
24
25
|
EditableNumberRangeFilterEntity,
|
|
25
26
|
RawFilterEntity,
|
|
26
27
|
BooleanFilterEntity,
|
|
28
|
+
SliderFilterEntity,
|
|
27
29
|
];
|
|
28
30
|
/**
|
|
29
31
|
* The registered modifiers grouped by the facetId to be applied.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-entity.factory.js","sources":["../../../../../src/x-modules/facets/entities/filter-entity.factory.ts"],"sourcesContent":["import type { Facet, Filter, FilterModelName } from '@empathyco/x-types'\nimport type { Store } from 'vuex'\nimport type { RootXStoreState } from '../../../store/store.types'\nimport type { FilterEntity, FilterEntityConstructor, FilterEntityModifier } from './types'\nimport { isFacetFilter } from '@empathyco/x-types'\nimport { UNKNOWN_FACET_KEY } from '../store/constants'\nimport { BooleanFilterEntity } from './boolean-filter.entity'\nimport { EditableNumberRangeFilterEntity } from './editable-number-range-filter.entity'\nimport { HierarchicalFilterEntity } from './hierarchical-filter.entity'\nimport { NumberRangeFilterEntity } from './number-range-filter.entity'\nimport { RawFilterEntity } from './raw-filter.entity'\nimport { SimpleFilterEntity } from './simple-filter.entity'\n\n/**\n * Creates {@link FilterEntity | FilterEntities} based on the provided configs.\n *\n * @internal\n */\nexport class FilterEntityFactory {\n /**\n * The public global instance of the Singleton.\n *\n * @remarks The constructor is not private, so it's possible to create more instances,\n * to simplify the testing.\n */\n public static instance = new FilterEntityFactory()\n\n /**\n * The registered entities by default to be used by the Factory.\n */\n protected entities = [\n SimpleFilterEntity,\n HierarchicalFilterEntity,\n NumberRangeFilterEntity,\n EditableNumberRangeFilterEntity,\n RawFilterEntity,\n BooleanFilterEntity,\n ] as FilterEntityConstructor[]\n\n /**\n * The registered modifiers grouped by the facetId to be applied.\n */\n protected modifiersByFacetId: Record<Facet['id'], FilterEntityModifier[]> = {}\n\n /**\n * The registered modifiers grouped by the filter `ModelName` to be applied.\n */\n protected modifiersByFilterModelName: Partial<Record<FilterModelName, FilterEntityModifier[]>> =\n {}\n\n /**\n * Contains the instantiated entities for each facet.\n *\n * @internal\n */\n protected cache: Record<Facet['id'] | typeof UNKNOWN_FACET_KEY, FilterEntity> = {}\n\n /**\n * Creates a new FilterEntity from a filter.\n *\n * @param store - The {@link https://vuex.vuejs.org/guide/ | Vuex Store} that the entity will\n * use.\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} necessary to know what\n * {@link FilterEntity} to create.\n * @returns The {@link FilterEntity} created by the factory.\n */\n getFilterEntity(store: Store<RootXStoreState>, filter: Filter): FilterEntity {\n const cacheKey = isFacetFilter(filter) ? filter.facetId : UNKNOWN_FACET_KEY\n return this.cache[cacheKey] ?? (this.cache[cacheKey] = this.createFilterEntity(store, filter))\n }\n\n /**\n * Creates a brand new {@link FilterEntity} for the given\n * {@link @empathyco/x-types#Filter | Filter}.\n *\n * @param store - The store which should be mutated through the entity.\n * @param filter - The filter to create the entity for.\n * @returns A new {@link FilterEntity} for the given {@link @empathyco/x-types#Filter | Filter}.\n * @internal\n */\n protected createFilterEntity(store: Store<RootXStoreState>, filter: Filter): FilterEntity {\n const filterEntityConstructor = this.entities.find(entity => entity.accepts(filter))\n if (!filterEntityConstructor) {\n throw new Error(`Entity configuration for ${filter.modelName} not registered.`)\n }\n // eslint-disable-next-line new-cap\n const entity = new filterEntityConstructor(store)\n const modifiers = isFacetFilter(filter)\n ? (this.modifiersByFacetId[filter.facetId] ??\n this.modifiersByFilterModelName[filter.modelName] ??\n [])\n : []\n return modifiers.reduce(\n // eslint-disable-next-line new-cap\n (modifiedEntity, modifier) => new modifier(store, modifiedEntity),\n entity,\n )\n }\n\n /**\n * Registers a new {@link FilterEntity} to be used by the factory.\n *\n * @param entity - The new {@link FilterEntity} to be registered in the factory.\n */\n registerFilterEntity(entity: FilterEntityConstructor): void {\n if (!this.entities.includes(entity)) {\n this.entities.push(entity)\n }\n }\n\n /**\n * Registers a list of modifiers to be used with the {@link FilterEntity | FilterEntities} of a\n * particular facet.\n *\n * @param facetId - The facet id whose Entities will be modified.\n * @param modifiers - The list of modifiers to be registered.\n */\n registerModifierByFacetId(facetId: Facet['id'], ...modifiers: FilterEntityModifier[]): void {\n this.updateModifiers(this.modifiersByFacetId, facetId, modifiers)\n }\n\n /**\n * Registers a list of modifiers to be used with the {@link FilterEntity | FilterEntities} of a\n * particular facet.\n *\n * @param filterModelName - The facet ModelName whose Entities will be modified.\n * @param modifiers - The list of modifiers to be registered.\n */\n registerModifierByFilterModelName(\n filterModelName: FilterModelName,\n ...modifiers: FilterEntityModifier[]\n ): void {\n this.updateModifiers(this.modifiersByFilterModelName, filterModelName, modifiers)\n }\n\n /**\n * Updates the modifiers for a particular facet.\n *\n * @param modifiersRecord - The map of modifiers to be updated.\n * @param modifierKey - The id whose modifiers will be updated.\n * @param modifiers - The list of new modifiers to be registered.\n */\n protected updateModifiers(\n modifiersRecord: Record<string, FilterEntityModifier[]>,\n modifierKey: string | number,\n modifiers: FilterEntityModifier[],\n ): void {\n if (!modifiersRecord[modifierKey]) {\n modifiersRecord[modifierKey] = []\n }\n const facetModifiers = modifiersRecord[modifierKey]\n const newModifiers = modifiers.filter(modifier => !facetModifiers.includes(modifier))\n facetModifiers.push(...newModifiers)\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter-entity.factory.js","sources":["../../../../../src/x-modules/facets/entities/filter-entity.factory.ts"],"sourcesContent":["import type { Facet, Filter, FilterModelName } from '@empathyco/x-types'\nimport type { Store } from 'vuex'\nimport type { RootXStoreState } from '../../../store/store.types'\nimport type { FilterEntity, FilterEntityConstructor, FilterEntityModifier } from './types'\nimport { isFacetFilter } from '@empathyco/x-types'\nimport { UNKNOWN_FACET_KEY } from '../store/constants'\nimport { BooleanFilterEntity } from './boolean-filter.entity'\nimport { EditableNumberRangeFilterEntity } from './editable-number-range-filter.entity'\nimport { HierarchicalFilterEntity } from './hierarchical-filter.entity'\nimport { NumberRangeFilterEntity } from './number-range-filter.entity'\nimport { RawFilterEntity } from './raw-filter.entity'\nimport { SimpleFilterEntity } from './simple-filter.entity'\nimport { SliderFilterEntity } from './slider-filter.entity'\n\n/**\n * Creates {@link FilterEntity | FilterEntities} based on the provided configs.\n *\n * @internal\n */\nexport class FilterEntityFactory {\n /**\n * The public global instance of the Singleton.\n *\n * @remarks The constructor is not private, so it's possible to create more instances,\n * to simplify the testing.\n */\n public static instance = new FilterEntityFactory()\n\n /**\n * The registered entities by default to be used by the Factory.\n */\n protected entities = [\n SimpleFilterEntity,\n HierarchicalFilterEntity,\n NumberRangeFilterEntity,\n EditableNumberRangeFilterEntity,\n RawFilterEntity,\n BooleanFilterEntity,\n SliderFilterEntity,\n ] as FilterEntityConstructor[]\n\n /**\n * The registered modifiers grouped by the facetId to be applied.\n */\n protected modifiersByFacetId: Record<Facet['id'], FilterEntityModifier[]> = {}\n\n /**\n * The registered modifiers grouped by the filter `ModelName` to be applied.\n */\n protected modifiersByFilterModelName: Partial<Record<FilterModelName, FilterEntityModifier[]>> =\n {}\n\n /**\n * Contains the instantiated entities for each facet.\n *\n * @internal\n */\n protected cache: Record<Facet['id'] | typeof UNKNOWN_FACET_KEY, FilterEntity> = {}\n\n /**\n * Creates a new FilterEntity from a filter.\n *\n * @param store - The {@link https://vuex.vuejs.org/guide/ | Vuex Store} that the entity will\n * use.\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} necessary to know what\n * {@link FilterEntity} to create.\n * @returns The {@link FilterEntity} created by the factory.\n */\n getFilterEntity(store: Store<RootXStoreState>, filter: Filter): FilterEntity {\n const cacheKey = isFacetFilter(filter) ? filter.facetId : UNKNOWN_FACET_KEY\n return this.cache[cacheKey] ?? (this.cache[cacheKey] = this.createFilterEntity(store, filter))\n }\n\n /**\n * Creates a brand new {@link FilterEntity} for the given\n * {@link @empathyco/x-types#Filter | Filter}.\n *\n * @param store - The store which should be mutated through the entity.\n * @param filter - The filter to create the entity for.\n * @returns A new {@link FilterEntity} for the given {@link @empathyco/x-types#Filter | Filter}.\n * @internal\n */\n protected createFilterEntity(store: Store<RootXStoreState>, filter: Filter): FilterEntity {\n const filterEntityConstructor = this.entities.find(entity => entity.accepts(filter))\n if (!filterEntityConstructor) {\n throw new Error(`Entity configuration for ${filter.modelName} not registered.`)\n }\n // eslint-disable-next-line new-cap\n const entity = new filterEntityConstructor(store)\n const modifiers = isFacetFilter(filter)\n ? (this.modifiersByFacetId[filter.facetId] ??\n this.modifiersByFilterModelName[filter.modelName] ??\n [])\n : []\n return modifiers.reduce(\n // eslint-disable-next-line new-cap\n (modifiedEntity, modifier) => new modifier(store, modifiedEntity),\n entity,\n )\n }\n\n /**\n * Registers a new {@link FilterEntity} to be used by the factory.\n *\n * @param entity - The new {@link FilterEntity} to be registered in the factory.\n */\n registerFilterEntity(entity: FilterEntityConstructor): void {\n if (!this.entities.includes(entity)) {\n this.entities.push(entity)\n }\n }\n\n /**\n * Registers a list of modifiers to be used with the {@link FilterEntity | FilterEntities} of a\n * particular facet.\n *\n * @param facetId - The facet id whose Entities will be modified.\n * @param modifiers - The list of modifiers to be registered.\n */\n registerModifierByFacetId(facetId: Facet['id'], ...modifiers: FilterEntityModifier[]): void {\n this.updateModifiers(this.modifiersByFacetId, facetId, modifiers)\n }\n\n /**\n * Registers a list of modifiers to be used with the {@link FilterEntity | FilterEntities} of a\n * particular facet.\n *\n * @param filterModelName - The facet ModelName whose Entities will be modified.\n * @param modifiers - The list of modifiers to be registered.\n */\n registerModifierByFilterModelName(\n filterModelName: FilterModelName,\n ...modifiers: FilterEntityModifier[]\n ): void {\n this.updateModifiers(this.modifiersByFilterModelName, filterModelName, modifiers)\n }\n\n /**\n * Updates the modifiers for a particular facet.\n *\n * @param modifiersRecord - The map of modifiers to be updated.\n * @param modifierKey - The id whose modifiers will be updated.\n * @param modifiers - The list of new modifiers to be registered.\n */\n protected updateModifiers(\n modifiersRecord: Record<string, FilterEntityModifier[]>,\n modifierKey: string | number,\n modifiers: FilterEntityModifier[],\n ): void {\n if (!modifiersRecord[modifierKey]) {\n modifiersRecord[modifierKey] = []\n }\n const facetModifiers = modifiersRecord[modifierKey]\n const newModifiers = modifiers.filter(modifier => !facetModifiers.includes(modifier))\n facetModifiers.push(...newModifiers)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAcA;;;;AAIG;MACU,mBAAmB,CAAA;AAAhC,IAAA,WAAA,GAAA;AASE;;AAEG;AACO,QAAA,IAAA,CAAA,QAAQ,GAAG;YACnB,kBAAkB;YAClB,wBAAwB;YACxB,uBAAuB;YACvB,+BAA+B;YAC/B,eAAe;YACf,mBAAmB;YACnB,kBAAkB;SACU;AAE9B;;AAEG;QACO,IAAA,CAAA,kBAAkB,GAAgD,EAAE;AAE9E;;AAEG;QACO,IAAA,CAAA,0BAA0B,GAClC,EAAE;AAEJ;;;;AAIG;QACO,IAAA,CAAA,KAAK,GAAiE,EAAE;IAmGpF;AAjGE;;;;;;;;AAQG;IACH,eAAe,CAAC,KAA6B,EAAE,MAAc,EAAA;AAC3D,QAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,iBAAi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AE,SAAS,CAAC;IACnE;AAEA;;;;;;AAMG;AACH,IAAA,iCAAiC,CAC/B,eAAgC,EAChC,GAAG,SAAiC,EAAA;QAEpC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,0BAA0B,EAAE,eAAe,EAAE,SAAS,CAAC;IACnF;AAEA;;;;;;AAMG;AACO,IAAA,eAAe,CACvB,eAAuD,EACvD,WAA4B,EAC5B,SAAiC,EAAA;AAEjC,QAAA,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE;AACjC,YAAA,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QACnC;AACA,QAAA,MAAM,cAAc,GAAG,eAAe,CAAC,WAAW,CAAC;AACnD,QAAA,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACrF,QAAA,cAAc,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;IACtC;;AAvIA;;;;;AAKG;AACW,mBAAA,CAAA,QAAQ,GAAG,IAAI,mBAAmB,EAAE;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { isSliderFilter } from '@empathyco/x-types';
|
|
2
|
+
import { addFacetIfNotPresent } from './add-facet-if-not-present.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Allows selecting and deselecting a filter of {@link @empathyco/x-types#SliderFilter
|
|
6
|
+
* | SliderFilter}.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
class SliderFilterEntity {
|
|
11
|
+
constructor(store) {
|
|
12
|
+
this.store = store;
|
|
13
|
+
}
|
|
14
|
+
static accepts(filter) {
|
|
15
|
+
return isSliderFilter(filter);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* It sets {@link @empathyco/x-types#SliderFilter | SliderFilter} to
|
|
19
|
+
* false. Range values are kept to be able to update the {@link FacetsGetters.selectedFilters}
|
|
20
|
+
* getter accordingly (as the id is built using the range).
|
|
21
|
+
*
|
|
22
|
+
* @param filterParam - The filter to deselect.
|
|
23
|
+
*/
|
|
24
|
+
deselect(filterParam) {
|
|
25
|
+
const filter = filterParam;
|
|
26
|
+
const newFilterState = {
|
|
27
|
+
facetId: filter.facetId,
|
|
28
|
+
range: { min: filter.range.min, max: filter.range.max },
|
|
29
|
+
selectedRange: { min: null, max: null },
|
|
30
|
+
selected: false,
|
|
31
|
+
};
|
|
32
|
+
this.removePreviousFilter(filter.facetId);
|
|
33
|
+
this.store.commit('x/facets/mutateFilter', {
|
|
34
|
+
filter,
|
|
35
|
+
newFilterState: Object.assign(newFilterState, { id: this.getNewFilterId(newFilterState) }),
|
|
36
|
+
});
|
|
37
|
+
addFacetIfNotPresent(this.store, filter.facetId, 'SliderFacet');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* It selects the {@link @empathyco/x-types#SliderFilter
|
|
41
|
+
* | SliderFilter}.
|
|
42
|
+
*
|
|
43
|
+
* @param filterParam - The filter to select.
|
|
44
|
+
* @remarks If the filter has no selected range, then filter is deselected when this
|
|
45
|
+
* method is called.
|
|
46
|
+
*/
|
|
47
|
+
select(filterParam) {
|
|
48
|
+
const filter = filterParam;
|
|
49
|
+
this.removePreviousFilter(filter.facetId);
|
|
50
|
+
this.store.commit('x/facets/mutateFilter', {
|
|
51
|
+
filter,
|
|
52
|
+
newFilterState: {
|
|
53
|
+
id: this.getNewFilterId(filter),
|
|
54
|
+
selected: this.isSelected(filter),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
addFacetIfNotPresent(this.store, filter.facetId, 'SliderFacet');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates a new filter id using the range values.
|
|
61
|
+
*
|
|
62
|
+
* @param filter - The filter to generate its new id.
|
|
63
|
+
* @returns The new filter id.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
getNewFilterId({ facetId, selectedRange, range, }) {
|
|
67
|
+
return `${facetId}:${String(selectedRange.min ?? range.min)}-${String(selectedRange.max ?? range.max)}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* It returns if the filter range min or the filter range max is not null.
|
|
71
|
+
*
|
|
72
|
+
* @param filter - The filter to determine if it is selected or not.
|
|
73
|
+
* @returns True if filter selectedRange min or filter selectedRange max is diferrent from filter range
|
|
74
|
+
* min or filter range max respectively.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
isSelected({ selectedRange, range }) {
|
|
78
|
+
return ((selectedRange.min ?? range.min) !== range.min ||
|
|
79
|
+
(selectedRange.max ?? range.max) !== range.max);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Removes the previous filter of this facet from the store, only if it exists.
|
|
83
|
+
*
|
|
84
|
+
* @param facetId - The facet to remove its only filter.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
removePreviousFilter(facetId) {
|
|
88
|
+
const previousFilter = this.getFilterByFacet(facetId);
|
|
89
|
+
if (previousFilter) {
|
|
90
|
+
this.store.commit('x/facets/removeFilter', previousFilter);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves the filter of the given facet id from the store.
|
|
95
|
+
*
|
|
96
|
+
* @param facetId - The facet id to retrieve its filter.
|
|
97
|
+
* @returns The filter of the facet if it exists.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
getFilterByFacet(facetId) {
|
|
101
|
+
// eslint-disable-next-line ts/no-unsafe-member-access,ts/no-unsafe-return
|
|
102
|
+
return this.store.getters['x/facets/facets'][facetId]?.filters?.[0];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { SliderFilterEntity };
|
|
107
|
+
//# sourceMappingURL=slider-filter.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider-filter.entity.js","sources":["../../../../../src/x-modules/facets/entities/slider-filter.entity.ts"],"sourcesContent":["import type { Facet, Filter, SliderFilter } from '@empathyco/x-types'\nimport type { Store } from 'vuex'\nimport type { RootXStoreState } from '../../../store/store.types'\nimport type { FilterEntity } from './types'\nimport { isSliderFilter } from '@empathyco/x-types'\nimport { addFacetIfNotPresent } from './add-facet-if-not-present'\n\n/**\n * Allows selecting and deselecting a filter of {@link @empathyco/x-types#SliderFilter\n * | SliderFilter}.\n *\n * @internal\n */\nexport class SliderFilterEntity implements FilterEntity {\n public constructor(protected store: Store<RootXStoreState>) {}\n\n static accepts(filter: Filter): boolean {\n return isSliderFilter(filter)\n }\n\n /**\n * It sets {@link @empathyco/x-types#SliderFilter | SliderFilter} to\n * false. Range values are kept to be able to update the {@link FacetsGetters.selectedFilters}\n * getter accordingly (as the id is built using the range).\n *\n * @param filterParam - The filter to deselect.\n */\n deselect(filterParam: Filter): void {\n const filter = filterParam as SliderFilter\n const newFilterState: Pick<SliderFilter, 'selectedRange' | 'range' | 'facetId' | 'selected'> = {\n facetId: filter.facetId,\n range: { min: filter.range.min, max: filter.range.max },\n selectedRange: { min: null, max: null },\n selected: false,\n }\n this.removePreviousFilter(filter.facetId)\n this.store.commit('x/facets/mutateFilter', {\n filter,\n newFilterState: Object.assign(newFilterState, { id: this.getNewFilterId(newFilterState) }),\n })\n addFacetIfNotPresent(this.store, filter.facetId, 'SliderFacet')\n }\n\n /**\n * It selects the {@link @empathyco/x-types#SliderFilter\n * | SliderFilter}.\n *\n * @param filterParam - The filter to select.\n * @remarks If the filter has no selected range, then filter is deselected when this\n * method is called.\n */\n select(filterParam: Filter): void {\n const filter = filterParam as SliderFilter\n this.removePreviousFilter(filter.facetId)\n this.store.commit('x/facets/mutateFilter', {\n filter,\n newFilterState: {\n id: this.getNewFilterId(filter),\n selected: this.isSelected(filter),\n },\n })\n addFacetIfNotPresent(this.store, filter.facetId, 'SliderFacet')\n }\n\n /**\n * Generates a new filter id using the range values.\n *\n * @param filter - The filter to generate its new id.\n * @returns The new filter id.\n * @internal\n */\n protected getNewFilterId({\n facetId,\n selectedRange,\n range,\n }: Pick<SliderFilter, 'selectedRange' | 'range' | 'facetId'>): string {\n return `${facetId}:${String(selectedRange.min ?? range.min)}-${String(selectedRange.max ?? range.max)}`\n }\n\n /**\n * It returns if the filter range min or the filter range max is not null.\n *\n * @param filter - The filter to determine if it is selected or not.\n * @returns True if filter selectedRange min or filter selectedRange max is diferrent from filter range\n * min or filter range max respectively.\n * @internal\n */\n protected isSelected({ selectedRange, range }: SliderFilter): boolean {\n return (\n (selectedRange.min ?? range.min) !== range.min ||\n (selectedRange.max ?? range.max) !== range.max\n )\n }\n\n /**\n * Removes the previous filter of this facet from the store, only if it exists.\n *\n * @param facetId - The facet to remove its only filter.\n * @internal\n */\n protected removePreviousFilter(facetId: Facet['id']): void {\n const previousFilter = this.getFilterByFacet(facetId)\n if (previousFilter) {\n this.store.commit('x/facets/removeFilter', previousFilter)\n }\n }\n\n /**\n * Retrieves the filter of the given facet id from the store.\n *\n * @param facetId - The facet id to retrieve its filter.\n * @returns The filter of the facet if it exists.\n * @internal\n */\n protected getFilterByFacet(facetId: Facet['id']): SliderFilter | undefined {\n // eslint-disable-next-line ts/no-unsafe-member-access,ts/no-unsafe-return\n return this.store.getters['x/facets/facets'][facetId]?.filters?.[0]\n }\n}\n"],"names":[],"mappings":";;;AAOA;;;;;AAKG;MACU,kBAAkB,CAAA;AAC7B,IAAA,WAAA,CAA6B,KAA6B,EAAA;QAA7B,IAAA,CAAA,KAAK,GAAL,KAAK;IAA2B;IAE7D,OAAO,OAAO,CAAC,MAAc,EAAA;AAC3B,QAAA,OAAO,cAAc,CAAC,MAAM,CAAC;IAC/B;AAEA;;;;;;AAMG;AACH,IAAA,QAAQ,CAAC,WAAmB,EAAA;QAC1B,MAAM,MAAM,GAAG,WAA2B;AAC1C,QAAA,MAAM,cAAc,GAA2E;YAC7F,OAAO,EAAE,MAAM,CAAC,OAAO;AACvB,YAAA,KAAK,EAAE,EAAE,G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