@agnos-ui/core 0.0.1-alpha.3 → 0.0.1-alpha.5

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 (96) hide show
  1. package/{accordion.d.ts → components/accordion/accordion.d.ts} +13 -4
  2. package/{accordion.js → components/accordion/accordion.js} +17 -11
  3. package/components/alert/alert.d.ts +32 -0
  4. package/components/alert/alert.js +23 -0
  5. package/{alert.d.ts → components/alert/common.d.ts} +17 -21
  6. package/{alert.js → components/alert/common.js} +12 -12
  7. package/{modal → components/modal}/modal.d.ts +28 -21
  8. package/{modal → components/modal}/modal.js +39 -13
  9. package/{pagination.d.ts → components/pagination/pagination.d.ts} +3 -3
  10. package/{pagination.js → components/pagination/pagination.js} +6 -4
  11. package/{progressbar.d.ts → components/progressbar/progressbar.d.ts} +2 -3
  12. package/{progressbar.js → components/progressbar/progressbar.js} +6 -6
  13. package/{rating.d.ts → components/rating/rating.d.ts} +2 -3
  14. package/{rating.js → components/rating/rating.js} +6 -9
  15. package/components/select/select.d.ts +337 -0
  16. package/components/select/select.js +266 -0
  17. package/components/slider/slider.d.ts +239 -0
  18. package/components/slider/slider.js +389 -0
  19. package/config.d.ts +13 -8
  20. package/config.js +3 -3
  21. package/index.d.ts +23 -12
  22. package/index.js +29 -12
  23. package/package.json +32 -4
  24. package/services/extendWidget.d.ts +23 -0
  25. package/{extendWidget.js → services/extendWidget.js} +8 -1
  26. package/services/floatingUI.d.ts +48 -0
  27. package/services/floatingUI.js +97 -0
  28. package/services/focustrack.js +1 -1
  29. package/services/intersection.d.ts +1 -1
  30. package/services/intersection.js +2 -2
  31. package/services/navManager.d.ts +83 -1
  32. package/services/navManager.js +153 -37
  33. package/services/portal.js +8 -4
  34. package/services/siblingsInert.d.ts +2 -1
  35. package/services/siblingsInert.js +2 -2
  36. package/{transitions → services/transitions}/baseTransitions.d.ts +1 -2
  37. package/{transitions → services/transitions}/baseTransitions.js +7 -10
  38. package/services/transitions/bootstrap/collapse.d.ts +2 -0
  39. package/services/transitions/bootstrap/fade.d.ts +1 -0
  40. package/services/transitions/bootstrap.d.ts +2 -0
  41. package/services/transitions/bootstrap.js +2 -0
  42. package/{transitions → services/transitions}/collapse.js +1 -1
  43. package/{transitions → services/transitions}/cssTransitions.js +2 -4
  44. package/{transitions → services/transitions}/simpleClassTransition.js +1 -1
  45. package/types.d.ts +37 -4
  46. package/types.js +1 -0
  47. package/{services/directiveUtils.js → utils/directive.js} +1 -1
  48. package/{services → utils/internal}/checks.d.ts +12 -0
  49. package/{services → utils/internal}/checks.js +12 -0
  50. package/utils/internal/dom.d.ts +13 -0
  51. package/utils/internal/dom.js +49 -0
  52. package/utils/internal/isFocusable.d.ts +9 -0
  53. package/utils/internal/isFocusable.js +35 -0
  54. package/utils/internal/math.d.ts +5 -0
  55. package/utils/internal/math.js +13 -0
  56. package/utils/internal/promise.d.ts +31 -0
  57. package/utils/internal/promise.js +113 -0
  58. package/{modal → utils/internal}/scrollbars.js +1 -1
  59. package/utils/internal/textDirection.d.ts +1 -0
  60. package/utils/internal/textDirection.js +1 -0
  61. package/utils/internal/traversal.d.ts +54 -0
  62. package/utils/internal/traversal.js +105 -0
  63. package/{services → utils}/stores.d.ts +11 -35
  64. package/{services → utils}/stores.js +21 -19
  65. package/utils/writables.d.ts +26 -0
  66. package/utils/writables.js +66 -0
  67. package/extendWidget.d.ts +0 -3
  68. package/select.d.ts +0 -196
  69. package/select.js +0 -240
  70. package/services/index.d.ts +0 -8
  71. package/services/index.js +0 -8
  72. package/services/writables.d.ts +0 -8
  73. package/services/writables.js +0 -30
  74. package/transitions/bootstrap/collapse.d.ts +0 -2
  75. package/transitions/bootstrap/fade.d.ts +0 -1
  76. package/transitions/bootstrap/index.d.ts +0 -2
  77. package/transitions/bootstrap/index.js +0 -2
  78. package/transitions/index.d.ts +0 -5
  79. package/transitions/index.js +0 -5
  80. package/transitions/utils.d.ts +0 -20
  81. package/transitions/utils.js +0 -83
  82. /package/{commonProps.d.ts → components/commonProps.d.ts} +0 -0
  83. /package/{commonProps.js → components/commonProps.js} +0 -0
  84. /package/{pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
  85. /package/{pagination.utils.js → components/pagination/bootstrap.js} +0 -0
  86. /package/{transitions → services/transitions}/bootstrap/collapse.js +0 -0
  87. /package/{transitions → services/transitions}/bootstrap/fade.js +0 -0
  88. /package/{transitions → services/transitions}/collapse.d.ts +0 -0
  89. /package/{transitions → services/transitions}/cssTransitions.d.ts +0 -0
  90. /package/{transitions → services/transitions}/simpleClassTransition.d.ts +0 -0
  91. /package/{services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
  92. /package/{utils.d.ts → utils/internal/func.d.ts} +0 -0
  93. /package/{utils.js → utils/internal/func.js} +0 -0
  94. /package/{modal → utils/internal}/scrollbars.d.ts +0 -0
  95. /package/{services/sortUtils.d.ts → utils/internal/sort.d.ts} +0 -0
  96. /package/{services/sortUtils.js → utils/internal/sort.js} +0 -0
@@ -0,0 +1,239 @@
1
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
2
+ import type { Directive, PropsConfig, Widget } from '../../types';
3
+ export interface ProgressDisplayOptions {
4
+ /**
5
+ * Right offset of the progress in %
6
+ */
7
+ left: number | null;
8
+ /**
9
+ * Left offset of the progress in %
10
+ */
11
+ right: number | null;
12
+ /**
13
+ * Top offset of the progress in %
14
+ */
15
+ top: number | null;
16
+ /**
17
+ * Bottom offset of the progress in %
18
+ */
19
+ bottom: number | null;
20
+ /**
21
+ * Width of the progress in %
22
+ */
23
+ width: number;
24
+ /**
25
+ * Height of hte progress in %
26
+ */
27
+ height: number;
28
+ }
29
+ export interface HandleDisplayOptions {
30
+ /**
31
+ * Left offset of the handle in %
32
+ */
33
+ left: number | null;
34
+ /**
35
+ * Top offset of the handle in %
36
+ */
37
+ top: number | null;
38
+ }
39
+ export interface SliderCommonPropsAndState extends WidgetsCommonPropsAndState {
40
+ /**
41
+ * Minimum value that can be assigned to the slider
42
+ */
43
+ min: number;
44
+ /**
45
+ * Maximum value that can be assigned to the slider
46
+ */
47
+ max: number;
48
+ /**
49
+ * Unit value between slider steps
50
+ */
51
+ stepSize: number;
52
+ /**
53
+ * If `true` slider value cannot be changed but the slider is still focusable
54
+ */
55
+ readonly: boolean;
56
+ /**
57
+ * If `true` slider value cannot be changed and the slider cannot be focused
58
+ */
59
+ disabled: boolean;
60
+ /**
61
+ * If `true` is vertically positioned otherwise it is horizontal
62
+ */
63
+ vertical: boolean;
64
+ /**
65
+ * Current slider values
66
+ */
67
+ values: number[];
68
+ /**
69
+ * If `true` the value labels are displayed on the slider
70
+ */
71
+ showValueLabels: boolean;
72
+ /**
73
+ * If `true` the min and max labels are displayed on the slider
74
+ */
75
+ showMinMaxLabels: boolean;
76
+ /**
77
+ * It `true` slider display is inversed
78
+ */
79
+ rtl: boolean;
80
+ }
81
+ export interface SliderState extends SliderCommonPropsAndState {
82
+ /**
83
+ * Sorted slider values
84
+ */
85
+ sortedValues: number[];
86
+ /**
87
+ * Combined label left offset in %
88
+ */
89
+ combinedLabelPositionLeft: number;
90
+ /**
91
+ * Combined label top offset in %
92
+ */
93
+ combinedLabelPositionTop: number;
94
+ /**
95
+ * If true, the minimum label will be visible
96
+ */
97
+ minValueLabelDisplay: boolean;
98
+ /**
99
+ * If true, the maximum label will be visible
100
+ */
101
+ maxValueLabelDisplay: boolean;
102
+ /**
103
+ * If true, the label when the handles are close is visible
104
+ */
105
+ combinedLabelDisplay: boolean;
106
+ /**
107
+ * Array of the sorted handles to display
108
+ */
109
+ sortedHandles: {
110
+ value: number;
111
+ id: number;
112
+ ariaLabel: string;
113
+ }[];
114
+ /**
115
+ * Array of objects representing progress display options
116
+ */
117
+ progressDisplayOptions: ProgressDisplayOptions[];
118
+ /**
119
+ * Array of objects representing handle display options
120
+ */
121
+ handleDisplayOptions: HandleDisplayOptions[];
122
+ }
123
+ export interface SliderProps extends SliderCommonPropsAndState {
124
+ /**
125
+ * Return the value for the 'aria-label' attribute for the handle
126
+ * @param value - value of the handle
127
+ * @param sortedIndex - index of the handle in the sorted list
128
+ * @param index - index of the handle in the original list
129
+ */
130
+ ariaLabelHandle: (value: number, sortedIndex: number, index: number) => string;
131
+ /**
132
+ * An event emitted when slider values are changed
133
+ *
134
+ * Event payload equals to the updated slider values
135
+ */
136
+ onValuesChange: (values: number[]) => void;
137
+ }
138
+ export interface SliderApi {
139
+ }
140
+ export interface SliderDirectives {
141
+ /**
142
+ * Directive to get the slider component elementRef
143
+ */
144
+ sliderDirective: Directive;
145
+ /**
146
+ * Directive to get the minLabel elementRef
147
+ */
148
+ minLabelDirective: Directive;
149
+ /**
150
+ * Directive to get the maxLabel elementRef
151
+ */
152
+ maxLabelDirective: Directive;
153
+ }
154
+ export interface SliderActions {
155
+ /**
156
+ * Method to handle click on the slider
157
+ * @param event - mouse event
158
+ */
159
+ click(event: MouseEvent): void;
160
+ /**
161
+ * Method to process the keyboard event
162
+ * @param event - keyboard event object
163
+ * @param handleNumber - id of the modified handle
164
+ */
165
+ keydown(event: KeyboardEvent, handleNumber: number): void;
166
+ /**
167
+ * Method describing the behavior of the slider handle on mouse down event
168
+ * @param event - mouse event
169
+ * @param handleId - numeric id of the handle
170
+ */
171
+ mouseDown(event: MouseEvent, handleId: number): void;
172
+ }
173
+ export type SliderWidget = Widget<SliderProps, SliderState, SliderApi, SliderActions, SliderDirectives>;
174
+ /**
175
+ * Returns a shallow copy of the default slider config.
176
+ * @returns a copy of the default config
177
+ */
178
+ export declare function getSliderDefaultConfig(): {
179
+ /**
180
+ * Return the value for the 'aria-label' attribute for the handle
181
+ * @param value - value of the handle
182
+ * @param sortedIndex - index of the handle in the sorted list
183
+ * @param index - index of the handle in the original list
184
+ */
185
+ ariaLabelHandle: (value: number, sortedIndex: number, index: number) => string;
186
+ /**
187
+ * An event emitted when slider values are changed
188
+ *
189
+ * Event payload equals to the updated slider values
190
+ */
191
+ onValuesChange: (values: number[]) => void;
192
+ /**
193
+ * Minimum value that can be assigned to the slider
194
+ */
195
+ min: number;
196
+ /**
197
+ * Maximum value that can be assigned to the slider
198
+ */
199
+ max: number;
200
+ /**
201
+ * Unit value between slider steps
202
+ */
203
+ stepSize: number;
204
+ /**
205
+ * If `true` slider value cannot be changed but the slider is still focusable
206
+ */
207
+ readonly: boolean;
208
+ /**
209
+ * If `true` slider value cannot be changed and the slider cannot be focused
210
+ */
211
+ disabled: boolean;
212
+ /**
213
+ * If `true` is vertically positioned otherwise it is horizontal
214
+ */
215
+ vertical: boolean;
216
+ /**
217
+ * Current slider values
218
+ */
219
+ values: number[];
220
+ /**
221
+ * If `true` the value labels are displayed on the slider
222
+ */
223
+ showValueLabels: boolean;
224
+ /**
225
+ * If `true` the min and max labels are displayed on the slider
226
+ */
227
+ showMinMaxLabels: boolean;
228
+ /**
229
+ * It `true` slider display is inversed
230
+ */
231
+ rtl: boolean;
232
+ className: string;
233
+ };
234
+ /**
235
+ * Create a slider widget with given config props
236
+ * @param config - an optional slider config
237
+ * @returns a SliderWidget
238
+ */
239
+ export declare function createSlider(config?: PropsConfig<SliderProps>): SliderWidget;
@@ -0,0 +1,389 @@
1
+ import { computed, derived, writable } from '@amadeus-it-group/tansu';
2
+ import { bindableDerived, writablesForProps } from '../../utils/stores';
3
+ import { createStoreDirective, directiveSubscribe, mergeDirectives } from '../../utils/directive';
4
+ import { stateStores } from '../../utils/stores';
5
+ import { typeArray, typeBoolean, typeFunction, typeNumber, typeNumberInRangeFactory } from '../../utils/writables';
6
+ import { noop } from '../../utils/internal/func';
7
+ import { getDecimalPrecision } from '../../utils/internal/math';
8
+ const defaultSliderConfig = {
9
+ min: 0,
10
+ max: 100,
11
+ stepSize: 1,
12
+ readonly: false,
13
+ disabled: false,
14
+ vertical: false,
15
+ className: '',
16
+ ariaLabelHandle: (value, _index) => '' + value,
17
+ onValuesChange: noop,
18
+ values: [0],
19
+ showValueLabels: true,
20
+ showMinMaxLabels: true,
21
+ rtl: false,
22
+ };
23
+ /**
24
+ * Returns a shallow copy of the default slider config.
25
+ * @returns a copy of the default config
26
+ */
27
+ export function getSliderDefaultConfig() {
28
+ return { ...defaultSliderConfig };
29
+ }
30
+ const configValidator = {
31
+ min: typeNumber,
32
+ max: typeNumber,
33
+ stepSize: typeNumberInRangeFactory(0, +Infinity, { strict: true }),
34
+ readonly: typeBoolean,
35
+ disabled: typeBoolean,
36
+ vertical: typeBoolean,
37
+ ariaLabelHandle: typeFunction,
38
+ onValuesChange: typeFunction,
39
+ values: typeArray,
40
+ showValueLabels: typeBoolean,
41
+ showMinMaxLabels: typeBoolean,
42
+ rtl: typeBoolean,
43
+ };
44
+ /**
45
+ * Computes slider clean value based on the input parameters
46
+ * @param value - dirty value
47
+ * @param min - minimum value
48
+ * @param max - maximum value
49
+ * @param intStepSize - step size converted to integer
50
+ * @param decimalPrecision - maximum decimum precision of slider values
51
+ * @returns adjusted clean value
52
+ */
53
+ const computeCleanValue = (value, min, max, intStepSize, decimalPrecision) => {
54
+ const magnitude = Math.pow(10, decimalPrecision);
55
+ if (value >= max) {
56
+ return max;
57
+ }
58
+ else if (value <= min) {
59
+ return min;
60
+ }
61
+ const indexMin = Math.floor(((value - min) * magnitude) / intStepSize);
62
+ return +(((((value - min) * magnitude) % intStepSize < intStepSize / 2 ? indexMin : indexMin + 1) * intStepSize) / magnitude + min).toFixed(decimalPrecision);
63
+ };
64
+ /**
65
+ * Method to update the dirtyValues for the slider keyboard navigation
66
+ * @param handleIndex - index of the handle to update
67
+ * @param _dirtyValues$ - writable signal that contains dirtyValues
68
+ * @param values - slider values
69
+ * @param stepSize - slider step size
70
+ * @param updateDirection - if equals 1 - value is increased, if equals -1 values is decreased
71
+ */
72
+ const updateDirtyValue = (handleIndex, _dirtyValues$, values, stepSize, updateDirection) => {
73
+ _dirtyValues$.update((value) => {
74
+ value = [...value];
75
+ value[handleIndex] = values[handleIndex] + stepSize * updateDirection;
76
+ return value;
77
+ });
78
+ };
79
+ const getUpdateDirection = (vertical, rtl, keysVertical) => {
80
+ if (vertical && rtl) {
81
+ return keysVertical ? 1 : -1;
82
+ }
83
+ else if (vertical && !rtl) {
84
+ return -1;
85
+ }
86
+ else if (!vertical && rtl) {
87
+ return keysVertical ? -1 : 1;
88
+ }
89
+ else if (!vertical && !rtl) {
90
+ return -1;
91
+ }
92
+ return 1;
93
+ };
94
+ /**
95
+ * Create a slider widget with given config props
96
+ * @param config - an optional slider config
97
+ * @returns a SliderWidget
98
+ */
99
+ export function createSlider(config) {
100
+ const [{
101
+ // dirty inputs that need adjustment:
102
+ min$: _dirtyMinimum$, max$: _dirtyMaximum$, stepSize$, rtl$, values$: _dirtyValues$, ariaLabelHandle$, onValuesChange$, showValueLabels$, showMinMaxLabels$, ...stateProps }, patch,] = writablesForProps(defaultSliderConfig, config, configValidator);
103
+ const { vertical$, disabled$, readonly$ } = stateProps;
104
+ let _prevCoordinate = -1;
105
+ // clean inputs adjustment
106
+ const min$ = computed(() => {
107
+ const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
108
+ if (_dirtyMinimum === _dirtyMaximum) {
109
+ return defaultSliderConfig.min;
110
+ }
111
+ return Math.min(_dirtyMinimum, _dirtyMaximum);
112
+ });
113
+ const max$ = computed(() => {
114
+ const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
115
+ if (_dirtyMinimum === _dirtyMaximum) {
116
+ return defaultSliderConfig.max;
117
+ }
118
+ return Math.max(_dirtyMinimum, _dirtyMaximum);
119
+ });
120
+ const _decimalPrecision$ = computed(() => Math.max(getDecimalPrecision(stepSize$()), getDecimalPrecision(min$()), getDecimalPrecision(max$())));
121
+ const _intStepSize$ = computed(() => stepSize$() * Math.pow(10, _decimalPrecision$()));
122
+ const values$ = bindableDerived(onValuesChange$, [_dirtyValues$, min$, max$, _intStepSize$, _decimalPrecision$], ([dirtyValues, min, max, intStepSize, decimalPrecision]) => dirtyValues.map((dv) => computeCleanValue(dv, min, max, intStepSize, decimalPrecision)), typeArray.equal);
123
+ // computed
124
+ const { directive: sliderDirective, element$: sliderDom$ } = createStoreDirective();
125
+ const { directive: minLabelDirective, element$: minLabelDom$ } = createStoreDirective();
126
+ const { directive: maxLabelDirective, element$: maxLabelDom$ } = createStoreDirective();
127
+ const sliderResized$ = derived(sliderDom$, (sliderDom, set) => {
128
+ if (!sliderDom) {
129
+ set({});
130
+ return;
131
+ }
132
+ const resizeObserver = new ResizeObserver(() => {
133
+ set({});
134
+ });
135
+ resizeObserver.observe(sliderDom);
136
+ return () => resizeObserver.disconnect();
137
+ }, {});
138
+ const updateSliderSize$ = writable({});
139
+ const sliderDomRect$ = computed(() => {
140
+ sliderResized$();
141
+ updateSliderSize$();
142
+ return sliderDom$()?.getBoundingClientRect() ?? {};
143
+ }, {
144
+ equal: Object.is,
145
+ });
146
+ const minLabelDomRect$ = computed(() => {
147
+ sliderResized$();
148
+ updateSliderSize$();
149
+ return minLabelDom$()?.getBoundingClientRect() ?? {};
150
+ }, {
151
+ equal: (a, b) => Object.is(a, b),
152
+ });
153
+ const maxLabelDomRect$ = computed(() => {
154
+ sliderResized$();
155
+ updateSliderSize$();
156
+ return maxLabelDom$()?.getBoundingClientRect() ?? {};
157
+ }, {
158
+ equal: (a, b) => Object.is(a, b),
159
+ });
160
+ const sliderDomRectOffset$ = computed(() => (vertical$() ? sliderDomRect$().top : sliderDomRect$().left));
161
+ const sliderDomRectSize$ = computed(() => (vertical$() ? sliderDomRect$().height : sliderDomRect$().width));
162
+ const sortedValues$ = computed(() => [...values$()].sort((a, b) => a - b));
163
+ const _sortedHandlesValues$ = computed(() => {
164
+ return values$()
165
+ .map((val, index) => {
166
+ return { id: index, value: val };
167
+ })
168
+ .sort((a, b) => a.value - b.value);
169
+ });
170
+ const sortedHandles$ = computed(() => {
171
+ const ariaLabelHandle = ariaLabelHandle$();
172
+ return _sortedHandlesValues$().map((sortedValue, index) => {
173
+ return { ...sortedValue, ariaLabel: ariaLabelHandle(sortedValue.value, index, sortedValue.id) };
174
+ });
175
+ });
176
+ const valuesPercent$ = computed(() => values$().map((val) => percentCompute(val)));
177
+ const sortedValuesPercent$ = computed(() => [...valuesPercent$()].sort((a, b) => a - b));
178
+ const minLabelWidth$ = computed(() => (minLabelDomRect$().width / sliderDomRectSize$()) * 100);
179
+ const maxLabelWidth$ = computed(() => (maxLabelDomRect$().width / sliderDomRectSize$()) * 100);
180
+ const minValueLabelDisplay$ = computed(() => {
181
+ if (!showMinMaxLabels$()) {
182
+ return false;
183
+ }
184
+ else if (!showValueLabels$()) {
185
+ return true;
186
+ }
187
+ const minLabelWidth = minLabelWidth$();
188
+ return rtl$()
189
+ ? !valuesPercent$().some((percent) => 100 - percent > 100 - minLabelWidth - 1)
190
+ : !valuesPercent$().some((percent) => percent < minLabelWidth + 1);
191
+ });
192
+ const maxValueLabelDisplay$ = computed(() => {
193
+ if (!showMinMaxLabels$()) {
194
+ return false;
195
+ }
196
+ else if (!showValueLabels$()) {
197
+ return true;
198
+ }
199
+ const maxLabelWidth = maxLabelWidth$();
200
+ return rtl$()
201
+ ? !valuesPercent$().some((percent) => 100 - percent < maxLabelWidth + 1)
202
+ : !valuesPercent$().some((percent) => percent > 100 - maxLabelWidth - 1);
203
+ });
204
+ // TODO define the intersection value
205
+ const combinedLabelDisplay$ = computed(() => {
206
+ const values = values$();
207
+ return values.length == 2 && Math.abs(values[0] - values[1]) < 10;
208
+ });
209
+ const isInteractable$ = computed(() => !disabled$() && !readonly$());
210
+ const combinedLabelPositionLeft$ = computed(() => {
211
+ const sortedValuesPercent = sortedValuesPercent$();
212
+ const combinedPosition = (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
213
+ return vertical$() || sortedValuesPercent.length != 2 ? 0 : rtl$() ? 100 - combinedPosition : combinedPosition;
214
+ });
215
+ const combinedLabelPositionTop$ = computed(() => {
216
+ const sortedValuesPercent = sortedValuesPercent$();
217
+ const combinedPosition = 100 - (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
218
+ return vertical$() && sortedValuesPercent.length == 2 ? (rtl$() ? 100 - combinedPosition : combinedPosition) : 0;
219
+ });
220
+ const handleDisplayOptions$ = computed(() => {
221
+ const vertical = vertical$(), rtl = rtl$();
222
+ return valuesPercent$().map((vp, index) => {
223
+ return {
224
+ left: rtl ? (vertical ? null : 100 - vp) : vertical ? null : vp,
225
+ top: rtl ? (vertical ? vp : null) : vertical ? 100 - vp : null,
226
+ };
227
+ });
228
+ });
229
+ const progressDisplayOptions$ = computed(() => {
230
+ const vertical = vertical$(), sortedValuesPercent = sortedValuesPercent$(), rtl = rtl$();
231
+ if (sortedValuesPercent.length === 1) {
232
+ return [
233
+ {
234
+ left: vertical ? null : rtl ? null : 0,
235
+ right: vertical ? null : rtl ? 0 : null,
236
+ bottom: vertical ? (rtl ? null : 0) : null,
237
+ top: vertical ? (rtl ? 0 : null) : null,
238
+ width: vertical ? 100 : sortedValuesPercent[0],
239
+ height: vertical ? sortedValuesPercent[0] : 100,
240
+ },
241
+ ];
242
+ }
243
+ else {
244
+ return sortedValuesPercent
245
+ .map((svp, index, array) => {
246
+ return {
247
+ left: vertical ? null : rtl ? null : svp,
248
+ right: vertical ? null : rtl ? array[index] : null,
249
+ bottom: vertical ? (rtl ? null : svp) : null,
250
+ top: vertical ? (rtl ? array[index] : null) : null,
251
+ width: vertical ? 100 : index === array.length - 1 ? svp : array[index + 1] - svp,
252
+ height: vertical ? (index === array.length - 1 ? svp : array[index + 1] - svp) : 100,
253
+ };
254
+ })
255
+ .slice(0, sortedValuesPercent.length - 1);
256
+ }
257
+ });
258
+ // functions
259
+ const percentCompute = (value) => {
260
+ const min = min$();
261
+ return ((value - min) * 100) / (max$() - min);
262
+ };
263
+ const getClosestSliderHandle = (clickedPercent) => {
264
+ const values = values$();
265
+ if (values.length === 1) {
266
+ return 0;
267
+ }
268
+ const sortedValues = sortedValues$();
269
+ const closestBigger = sortedValues.find((sv) => sv > clickedPercent * 100);
270
+ const closestBiggerIndex = closestBigger ? sortedValues.indexOf(closestBigger) : sortedValues.length - 1;
271
+ const midPoint = sortedValues[closestBiggerIndex - 1] + (sortedValues[closestBiggerIndex] - sortedValues[closestBiggerIndex - 1]) / 2;
272
+ const closestValue = sortedValues[clickedPercent * 100 <= midPoint ? closestBiggerIndex - 1 : closestBiggerIndex];
273
+ return values.indexOf(closestValue);
274
+ };
275
+ const adjustCoordinate = (clickedCoordinate, handleNumber) => {
276
+ if (isInteractable$()) {
277
+ const sliderDomRectSize = sliderDomRectSize$(), sliderDomRectOffset = sliderDomRectOffset$();
278
+ let clickedPercent = vertical$()
279
+ ? (sliderDomRectSize - clickedCoordinate + sliderDomRectOffset) / sliderDomRectSize
280
+ : (clickedCoordinate - sliderDomRectOffset) / sliderDomRectSize;
281
+ clickedPercent = rtl$() ? 1 - clickedPercent : clickedPercent;
282
+ const derivedHandleIndex = handleNumber ?? getClosestSliderHandle(clickedPercent);
283
+ const newValue = clickedPercent * (max$() - min$()) + min$();
284
+ _dirtyValues$.update((dh) => {
285
+ dh = [...dh];
286
+ dh[derivedHandleIndex] = newValue;
287
+ return dh;
288
+ });
289
+ }
290
+ };
291
+ return {
292
+ ...stateStores({
293
+ min$,
294
+ max$,
295
+ stepSize$,
296
+ values$,
297
+ sortedValues$,
298
+ sortedHandles$,
299
+ minValueLabelDisplay$,
300
+ maxValueLabelDisplay$,
301
+ combinedLabelDisplay$,
302
+ isInteractable$,
303
+ combinedLabelPositionLeft$,
304
+ combinedLabelPositionTop$,
305
+ progressDisplayOptions$,
306
+ handleDisplayOptions$,
307
+ showValueLabels$,
308
+ showMinMaxLabels$,
309
+ rtl$,
310
+ ...stateProps,
311
+ }),
312
+ patch,
313
+ api: {},
314
+ directives: {
315
+ sliderDirective: mergeDirectives(sliderDirective, directiveSubscribe(sliderResized$)),
316
+ minLabelDirective,
317
+ maxLabelDirective,
318
+ },
319
+ actions: {
320
+ click(event) {
321
+ adjustCoordinate(vertical$() ? event.clientY : event.clientX);
322
+ },
323
+ keydown(event, handleIndex) {
324
+ const { key } = event;
325
+ const rtl = rtl$(), values = values$(), stepSize = stepSize$(), min = min$(), max = max$(), vertical = vertical$();
326
+ if (isInteractable$()) {
327
+ switch (key) {
328
+ case 'ArrowDown':
329
+ updateDirtyValue(handleIndex, _dirtyValues$, values, stepSize, getUpdateDirection(vertical, rtl, true));
330
+ break;
331
+ case 'ArrowLeft':
332
+ updateDirtyValue(handleIndex, _dirtyValues$, values, stepSize, getUpdateDirection(vertical, rtl, false));
333
+ break;
334
+ case 'ArrowUp':
335
+ updateDirtyValue(handleIndex, _dirtyValues$, values, stepSize, -1 * getUpdateDirection(vertical, rtl, true));
336
+ break;
337
+ case 'ArrowRight':
338
+ updateDirtyValue(handleIndex, _dirtyValues$, values, stepSize, -1 * getUpdateDirection(vertical, rtl, false));
339
+ break;
340
+ case 'Home':
341
+ _dirtyValues$.update((value) => {
342
+ value = [...value];
343
+ value[handleIndex] = min;
344
+ return value;
345
+ });
346
+ break;
347
+ case 'End':
348
+ _dirtyValues$.update((value) => {
349
+ value = [...value];
350
+ value[handleIndex] = max;
351
+ return value;
352
+ });
353
+ break;
354
+ case 'PageUp':
355
+ // TODO it is optional in accessibility guidelines, so define the skip value for steps and write unit test
356
+ break;
357
+ case 'PageDown':
358
+ // TODO it is optional in accessibility guidelines, so define the skip value for steps and write unit test
359
+ break;
360
+ default:
361
+ return;
362
+ }
363
+ event.preventDefault();
364
+ event.stopPropagation();
365
+ }
366
+ },
367
+ mouseDown(event, handleId) {
368
+ event.preventDefault();
369
+ const handleDrag = (e) => {
370
+ e.preventDefault();
371
+ const newCoord = vertical$() ? e.clientY : e.clientX;
372
+ event.target.focus();
373
+ if (_prevCoordinate !== newCoord) {
374
+ _prevCoordinate = newCoord;
375
+ adjustCoordinate(newCoord, handleId);
376
+ }
377
+ };
378
+ if (isInteractable$()) {
379
+ event.target.focus();
380
+ document.addEventListener('mousemove', handleDrag);
381
+ // TODO mouse up doesn't work outside the handle area
382
+ document.addEventListener('mouseup', () => {
383
+ document.removeEventListener('mousemove', handleDrag);
384
+ }, { once: true });
385
+ }
386
+ },
387
+ },
388
+ };
389
+ }
package/config.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { ReadableSignal, WritableSignal } from '@amadeus-it-group/tansu';
2
- import type { ModalProps } from './modal/modal';
3
- import type { AlertProps } from './alert';
4
- import type { PaginationProps } from './pagination';
5
- import type { RatingProps } from './rating';
6
- import type { SelectProps } from './select';
7
- import type { AccordionProps } from './accordion';
8
- import type { ProgressbarProps } from './progressbar';
2
+ import type { ModalProps } from './components/modal/modal';
3
+ import type { AlertProps } from './components/alert/alert';
4
+ import type { PaginationProps } from './components/pagination/pagination';
5
+ import type { RatingProps } from './components/rating/rating';
6
+ import type { SelectProps } from './components/select/select';
7
+ import type { AccordionProps } from './components/accordion/accordion';
8
+ import type { ProgressbarProps } from './components/progressbar/progressbar';
9
+ import type { SliderProps } from './components/slider/slider';
9
10
  export type Partial2Levels<T> = Partial<{
10
11
  [Level1 in keyof T]: Partial<T[Level1]>;
11
12
  }>;
@@ -60,7 +61,7 @@ export interface WidgetsConfig {
60
61
  /**
61
62
  * the modal widget config
62
63
  */
63
- modal: ModalProps;
64
+ modal: ModalProps<any>;
64
65
  /**
65
66
  * the alert widget config
66
67
  */
@@ -73,4 +74,8 @@ export interface WidgetsConfig {
73
74
  * the progress bar widget config
74
75
  */
75
76
  progressbar: ProgressbarProps;
77
+ /**
78
+ * slider widget config
79
+ */
80
+ slider: SliderProps;
76
81
  }
package/config.js CHANGED
@@ -1,5 +1,5 @@
1
- import { asReadable, computed, writable } from '@amadeus-it-group/tansu';
2
- import { identity } from './utils';
1
+ import { asWritable, computed, writable } from '@amadeus-it-group/tansu';
2
+ import { identity } from './utils/internal/func';
3
3
  /**
4
4
  * Merges source object into destination object, up to the provided number of levels.
5
5
  * @param destination - destination object
@@ -44,7 +44,7 @@ export const mergeInto = (destination, source, levels = Infinity) => {
44
44
  export const createWidgetsConfig = (parent$, adaptParentConfig = identity) => {
45
45
  const own$ = writable({});
46
46
  const adaptedParent$ = adaptParentConfig === identity ? parent$ : computed(() => adaptParentConfig(mergeInto({}, parent$?.(), 2)));
47
- return asReadable(computed(() => mergeInto(mergeInto({}, adaptedParent$?.(), 2), own$(), 2)), {
47
+ return asWritable(computed(() => mergeInto(mergeInto({}, adaptedParent$?.(), 2), own$(), 2)), {
48
48
  ...own$,
49
49
  own$,
50
50
  adaptedParent$,