@agnos-ui/core 0.0.1-alpha.4 → 0.0.1-alpha.6
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/{accordion.d.ts → components/accordion/accordion.d.ts} +3 -4
- package/{accordion.js → components/accordion/accordion.js} +10 -9
- package/components/alert/alert.d.ts +32 -0
- package/components/alert/alert.js +23 -0
- package/{alert.d.ts → components/alert/common.d.ts} +17 -21
- package/{alert.js → components/alert/common.js} +12 -12
- package/{modal → components/modal}/modal.d.ts +28 -21
- package/{modal → components/modal}/modal.js +39 -13
- package/{pagination.d.ts → components/pagination/pagination.d.ts} +3 -3
- package/{pagination.js → components/pagination/pagination.js} +6 -4
- package/{progressbar.d.ts → components/progressbar/progressbar.d.ts} +2 -3
- package/{progressbar.js → components/progressbar/progressbar.js} +6 -6
- package/{rating.d.ts → components/rating/rating.d.ts} +2 -3
- package/{rating.js → components/rating/rating.js} +6 -9
- package/components/select/select.d.ts +337 -0
- package/components/select/select.js +266 -0
- package/{slider.d.ts → components/slider/slider.d.ts} +60 -14
- package/components/slider/slider.js +389 -0
- package/config.d.ts +9 -9
- package/config.js +3 -3
- package/index.d.ts +23 -13
- package/index.js +29 -13
- package/package.json +30 -3
- package/services/extendWidget.d.ts +23 -0
- package/{extendWidget.js → services/extendWidget.js} +8 -1
- package/services/floatingUI.d.ts +48 -0
- package/services/floatingUI.js +97 -0
- package/services/focustrack.js +1 -1
- package/services/intersection.d.ts +1 -1
- package/services/intersection.js +2 -2
- package/services/navManager.d.ts +83 -1
- package/services/navManager.js +153 -37
- package/services/portal.js +8 -4
- package/services/siblingsInert.d.ts +2 -1
- package/services/siblingsInert.js +2 -2
- package/{transitions → services/transitions}/baseTransitions.d.ts +1 -2
- package/{transitions → services/transitions}/baseTransitions.js +7 -10
- package/services/transitions/bootstrap/collapse.d.ts +2 -0
- package/services/transitions/bootstrap/fade.d.ts +1 -0
- package/services/transitions/bootstrap.d.ts +2 -0
- package/services/transitions/bootstrap.js +2 -0
- package/{transitions → services/transitions}/collapse.js +1 -1
- package/{transitions → services/transitions}/cssTransitions.js +2 -4
- package/{transitions → services/transitions}/simpleClassTransition.js +1 -1
- package/types.d.ts +37 -4
- package/types.js +1 -0
- package/{services/directiveUtils.js → utils/directive.js} +1 -1
- package/{services → utils/internal}/checks.d.ts +12 -0
- package/{services → utils/internal}/checks.js +12 -0
- package/utils/internal/dom.d.ts +13 -0
- package/utils/internal/dom.js +49 -0
- package/utils/internal/math.d.ts +5 -0
- package/utils/internal/math.js +13 -0
- package/utils/internal/promise.d.ts +31 -0
- package/utils/internal/promise.js +113 -0
- package/{modal → utils/internal}/scrollbars.js +1 -1
- package/utils/internal/textDirection.d.ts +1 -0
- package/utils/internal/textDirection.js +1 -0
- package/utils/internal/traversal.d.ts +54 -0
- package/utils/internal/traversal.js +105 -0
- package/{services → utils}/stores.d.ts +11 -35
- package/{services → utils}/stores.js +21 -19
- package/utils/writables.d.ts +26 -0
- package/utils/writables.js +66 -0
- package/extendWidget.d.ts +0 -3
- package/select.d.ts +0 -196
- package/select.js +0 -240
- package/services/index.d.ts +0 -9
- package/services/index.js +0 -9
- package/services/writables.d.ts +0 -8
- package/services/writables.js +0 -30
- package/slider.js +0 -289
- package/transitions/bootstrap/collapse.d.ts +0 -2
- package/transitions/bootstrap/fade.d.ts +0 -1
- package/transitions/bootstrap/index.d.ts +0 -2
- package/transitions/bootstrap/index.js +0 -2
- package/transitions/index.d.ts +0 -5
- package/transitions/index.js +0 -5
- package/transitions/utils.d.ts +0 -20
- package/transitions/utils.js +0 -83
- /package/{commonProps.d.ts → components/commonProps.d.ts} +0 -0
- /package/{commonProps.js → components/commonProps.js} +0 -0
- /package/{pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
- /package/{pagination.utils.js → components/pagination/bootstrap.js} +0 -0
- /package/{transitions → services/transitions}/bootstrap/collapse.js +0 -0
- /package/{transitions → services/transitions}/bootstrap/fade.js +0 -0
- /package/{transitions → services/transitions}/collapse.d.ts +0 -0
- /package/{transitions → services/transitions}/cssTransitions.d.ts +0 -0
- /package/{transitions → services/transitions}/simpleClassTransition.d.ts +0 -0
- /package/{services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
- /package/{utils.d.ts → utils/internal/func.d.ts} +0 -0
- /package/{utils.js → utils/internal/func.js} +0 -0
- /package/{services → utils/internal}/isFocusable.d.ts +0 -0
- /package/{services → utils/internal}/isFocusable.js +0 -0
- /package/{modal → utils/internal}/scrollbars.d.ts +0 -0
- /package/{services/sortUtils.d.ts → utils/internal/sort.d.ts} +0 -0
- /package/{services/sortUtils.js → utils/internal/sort.js} +0 -0
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import type { WidgetsCommonPropsAndState } from '
|
|
2
|
-
import type { PropsConfig } from '
|
|
3
|
-
import type { Directive, Widget } from './types';
|
|
1
|
+
import type { WidgetsCommonPropsAndState } from '../commonProps';
|
|
2
|
+
import type { Directive, PropsConfig, Widget } from '../../types';
|
|
4
3
|
export interface ProgressDisplayOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Right offset of the progress in %
|
|
6
|
+
*/
|
|
7
|
+
left: number | null;
|
|
5
8
|
/**
|
|
6
9
|
* Left offset of the progress in %
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
right: number | null;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Top offset of the progress in %
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
top: number | null;
|
|
16
|
+
/**
|
|
17
|
+
* Bottom offset of the progress in %
|
|
18
|
+
*/
|
|
19
|
+
bottom: number | null;
|
|
13
20
|
/**
|
|
14
21
|
* Width of the progress in %
|
|
15
22
|
*/
|
|
@@ -23,11 +30,11 @@ export interface HandleDisplayOptions {
|
|
|
23
30
|
/**
|
|
24
31
|
* Left offset of the handle in %
|
|
25
32
|
*/
|
|
26
|
-
left: number;
|
|
33
|
+
left: number | null;
|
|
27
34
|
/**
|
|
28
35
|
* Top offset of the handle in %
|
|
29
36
|
*/
|
|
30
|
-
top: number;
|
|
37
|
+
top: number | null;
|
|
31
38
|
}
|
|
32
39
|
export interface SliderCommonPropsAndState extends WidgetsCommonPropsAndState {
|
|
33
40
|
/**
|
|
@@ -58,6 +65,18 @@ export interface SliderCommonPropsAndState extends WidgetsCommonPropsAndState {
|
|
|
58
65
|
* Current slider values
|
|
59
66
|
*/
|
|
60
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;
|
|
61
80
|
}
|
|
62
81
|
export interface SliderState extends SliderCommonPropsAndState {
|
|
63
82
|
/**
|
|
@@ -73,23 +92,24 @@ export interface SliderState extends SliderCommonPropsAndState {
|
|
|
73
92
|
*/
|
|
74
93
|
combinedLabelPositionTop: number;
|
|
75
94
|
/**
|
|
76
|
-
* If
|
|
95
|
+
* If true, the minimum label will be visible
|
|
77
96
|
*/
|
|
78
|
-
minValueLabelDisplay:
|
|
97
|
+
minValueLabelDisplay: boolean;
|
|
79
98
|
/**
|
|
80
|
-
* If
|
|
99
|
+
* If true, the maximum label will be visible
|
|
81
100
|
*/
|
|
82
|
-
maxValueLabelDisplay:
|
|
101
|
+
maxValueLabelDisplay: boolean;
|
|
83
102
|
/**
|
|
84
|
-
* If
|
|
103
|
+
* If true, the label when the handles are close is visible
|
|
85
104
|
*/
|
|
86
|
-
combinedLabelDisplay:
|
|
105
|
+
combinedLabelDisplay: boolean;
|
|
87
106
|
/**
|
|
88
107
|
* Array of the sorted handles to display
|
|
89
108
|
*/
|
|
90
109
|
sortedHandles: {
|
|
91
110
|
value: number;
|
|
92
111
|
id: number;
|
|
112
|
+
ariaLabel: string;
|
|
93
113
|
}[];
|
|
94
114
|
/**
|
|
95
115
|
* Array of objects representing progress display options
|
|
@@ -101,6 +121,13 @@ export interface SliderState extends SliderCommonPropsAndState {
|
|
|
101
121
|
handleDisplayOptions: HandleDisplayOptions[];
|
|
102
122
|
}
|
|
103
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;
|
|
104
131
|
/**
|
|
105
132
|
* An event emitted when slider values are changed
|
|
106
133
|
*
|
|
@@ -149,6 +176,13 @@ export type SliderWidget = Widget<SliderProps, SliderState, SliderApi, SliderAct
|
|
|
149
176
|
* @returns a copy of the default config
|
|
150
177
|
*/
|
|
151
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;
|
|
152
186
|
/**
|
|
153
187
|
* An event emitted when slider values are changed
|
|
154
188
|
*
|
|
@@ -183,6 +217,18 @@ export declare function getSliderDefaultConfig(): {
|
|
|
183
217
|
* Current slider values
|
|
184
218
|
*/
|
|
185
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;
|
|
186
232
|
className: string;
|
|
187
233
|
};
|
|
188
234
|
/**
|
|
@@ -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,12 +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';
|
|
9
|
-
import type { SliderProps } from './slider';
|
|
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';
|
|
10
10
|
export type Partial2Levels<T> = Partial<{
|
|
11
11
|
[Level1 in keyof T]: Partial<T[Level1]>;
|
|
12
12
|
}>;
|
|
@@ -61,7 +61,7 @@ export interface WidgetsConfig {
|
|
|
61
61
|
/**
|
|
62
62
|
* the modal widget config
|
|
63
63
|
*/
|
|
64
|
-
modal: ModalProps
|
|
64
|
+
modal: ModalProps<any>;
|
|
65
65
|
/**
|
|
66
66
|
* the alert widget config
|
|
67
67
|
*/
|
package/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
|
47
|
+
return asWritable(computed(() => mergeInto(mergeInto({}, adaptedParent$?.(), 2), own$(), 2)), {
|
|
48
48
|
...own$,
|
|
49
49
|
own$,
|
|
50
50
|
adaptedParent$,
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
export * from './components/commonProps';
|
|
1
2
|
export * from './types';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
3
|
+
export * from './components/accordion/accordion';
|
|
4
|
+
export * from './components/alert/alert';
|
|
5
|
+
export * from './components/modal/modal';
|
|
6
|
+
export * from './components/pagination/pagination';
|
|
7
|
+
export * from './components/progressbar/progressbar';
|
|
8
|
+
export * from './components/rating/rating';
|
|
9
|
+
export * from './components/select/select';
|
|
10
|
+
export * from './components/slider/slider';
|
|
8
11
|
export * from './config';
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
12
|
+
export * from './services/extendWidget';
|
|
13
|
+
export * from './services/floatingUI';
|
|
14
|
+
export * from './services/focustrack';
|
|
15
|
+
export * from './services/intersection';
|
|
16
|
+
export * from './services/navManager';
|
|
17
|
+
export * from './services/portal';
|
|
18
|
+
export * from './services/siblingsInert';
|
|
19
|
+
export * from './services/transitions/baseTransitions';
|
|
20
|
+
export * from './services/transitions/cssTransitions';
|
|
21
|
+
export * from './services/transitions/simpleClassTransition';
|
|
22
|
+
export * from './services/transitions/bootstrap';
|
|
23
|
+
export * from './utils/directive';
|
|
24
|
+
export * from './utils/stores';
|
|
25
|
+
export * from './utils/writables';
|
package/index.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
// types
|
|
2
|
+
export * from './components/commonProps';
|
|
1
3
|
export * from './types';
|
|
2
|
-
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './pagination';
|
|
7
|
-
export * from './
|
|
4
|
+
// components
|
|
5
|
+
export * from './components/accordion/accordion';
|
|
6
|
+
export * from './components/alert/alert';
|
|
7
|
+
export * from './components/modal/modal';
|
|
8
|
+
export * from './components/pagination/pagination';
|
|
9
|
+
export * from './components/progressbar/progressbar';
|
|
10
|
+
export * from './components/rating/rating';
|
|
11
|
+
export * from './components/select/select';
|
|
12
|
+
export * from './components/slider/slider';
|
|
13
|
+
// config
|
|
8
14
|
export * from './config';
|
|
9
|
-
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
15
|
+
// services
|
|
16
|
+
export * from './services/extendWidget';
|
|
17
|
+
export * from './services/floatingUI';
|
|
18
|
+
export * from './services/focustrack';
|
|
19
|
+
export * from './services/intersection';
|
|
20
|
+
export * from './services/navManager';
|
|
21
|
+
export * from './services/portal';
|
|
22
|
+
export * from './services/siblingsInert';
|
|
23
|
+
// services transitions
|
|
24
|
+
export * from './services/transitions/baseTransitions';
|
|
25
|
+
export * from './services/transitions/cssTransitions';
|
|
26
|
+
export * from './services/transitions/simpleClassTransition';
|
|
27
|
+
export * from './services/transitions/bootstrap';
|
|
28
|
+
// public utils
|
|
29
|
+
export * from './utils/directive';
|
|
30
|
+
export * from './utils/stores';
|
|
31
|
+
export * from './utils/writables';
|