@agnos-ui/core 0.2.0 → 0.3.1
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/README.md +3 -3
- package/accordion-BaWN0_n-.js +330 -0
- package/accordion-BuIgxZ0S.cjs +329 -0
- package/alert-C4jCg9Pl.cjs +8 -0
- package/alert-Dlf-BV98.js +9 -0
- package/common-DRdsw5m8.js +76 -0
- package/common-nJRMXbwj.cjs +75 -0
- package/components/accordion/accordion.d.ts +38 -49
- package/components/accordion/index.cjs +7 -0
- package/components/accordion/index.js +7 -1
- package/components/alert/alert.d.ts +3 -12
- package/components/alert/common.d.ts +4 -13
- package/components/alert/index.cjs +10 -0
- package/components/alert/index.js +10 -2
- package/components/modal/index.cjs +7 -0
- package/components/modal/index.js +7 -1
- package/components/modal/modal.d.ts +7 -49
- package/components/pagination/index.cjs +5 -0
- package/components/pagination/index.d.ts +0 -1
- package/components/pagination/index.js +5 -2
- package/components/pagination/pagination.d.ts +68 -139
- package/components/progressbar/index.cjs +5 -0
- package/components/progressbar/index.js +5 -1
- package/components/progressbar/progressbar.d.ts +6 -22
- package/components/rating/index.cjs +5 -0
- package/components/rating/index.js +5 -1
- package/components/rating/rating.d.ts +16 -11
- package/components/select/index.cjs +6 -0
- package/components/select/index.js +6 -1
- package/components/select/select.d.ts +15 -33
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.js +5 -1
- package/components/slider/slider.d.ts +29 -35
- package/components/toast/index.cjs +5 -0
- package/components/toast/index.js +5 -1
- package/components/toast/toast.d.ts +11 -8
- package/config.cjs +38 -0
- package/config.d.ts +1 -1
- package/config.js +35 -50
- package/directive-BTSEYLF3.cjs +404 -0
- package/directive-DCYlDznf.js +405 -0
- package/func-DR0n-ShK.js +7 -0
- package/func-Qd3cD9a3.cjs +6 -0
- package/index.cjs +119 -0
- package/index.d.ts +1 -1
- package/index.js +119 -33
- package/modal-BI2qUu1M.js +251 -0
- package/modal-rzMpATf5.cjs +250 -0
- package/package.json +29 -19
- package/pagination--GkwduJn.js +263 -0
- package/pagination-EWSWQT1I.cjs +262 -0
- package/progressbar-DH7DHYMp.cjs +83 -0
- package/progressbar-DuRX7_my.js +84 -0
- package/promise-BMJ8qhA8.cjs +118 -0
- package/promise-CY2U8bTP.js +119 -0
- package/rating-BR5wD7y2.js +173 -0
- package/rating-CmuYUSxy.cjs +172 -0
- package/select-BCs6HQWn.js +358 -0
- package/select-CCIKn8WR.cjs +357 -0
- package/services/extendWidget.cjs +32 -0
- package/services/extendWidget.d.ts +2 -1
- package/services/extendWidget.js +31 -34
- package/services/floatingUI.cjs +131 -0
- package/services/floatingUI.d.ts +30 -14
- package/services/floatingUI.js +128 -102
- package/services/focustrack.cjs +47 -0
- package/services/focustrack.js +45 -44
- package/services/hash.cjs +15 -0
- package/services/hash.js +14 -12
- package/services/intersection.cjs +53 -0
- package/services/intersection.js +48 -50
- package/services/matchMedia.cjs +13 -0
- package/services/matchMedia.d.ts +7 -0
- package/services/matchMedia.js +13 -0
- package/services/navManager.cjs +196 -0
- package/services/navManager.d.ts +9 -9
- package/services/navManager.js +186 -168
- package/services/portal.cjs +43 -0
- package/services/portal.js +41 -42
- package/services/resizeObserver.cjs +32 -0
- package/services/resizeObserver.d.ts +1 -1
- package/services/resizeObserver.js +31 -28
- package/services/siblingsInert.cjs +40 -0
- package/services/siblingsInert.js +31 -31
- package/services/transitions/baseTransitions.cjs +171 -0
- package/services/transitions/baseTransitions.d.ts +16 -16
- package/services/transitions/baseTransitions.js +159 -170
- package/services/transitions/collapse.cjs +44 -0
- package/services/transitions/collapse.js +41 -49
- package/services/transitions/cssTransitions.cjs +32 -0
- package/services/transitions/cssTransitions.d.ts +2 -1
- package/services/transitions/cssTransitions.js +29 -39
- package/services/transitions/simpleClassTransition.cjs +31 -0
- package/services/transitions/simpleClassTransition.js +30 -41
- package/slider-CA_fszn7.js +536 -0
- package/slider-DsLvT87U.cjs +535 -0
- package/toast-8tWp6x89.js +63 -0
- package/toast-Aw8o0Iwe.cjs +62 -0
- package/types.cjs +12 -0
- package/types.d.ts +21 -1
- package/types.js +11 -13
- package/utils/directive.cjs +26 -0
- package/utils/directive.d.ts +148 -5
- package/utils/directive.js +25 -205
- package/utils/internal/dom.d.ts +43 -4
- package/utils/internal/promise.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +7 -0
- package/utils/stores.cjs +163 -0
- package/utils/stores.d.ts +9 -17
- package/utils/stores.js +149 -284
- package/utils/writables.cjs +13 -0
- package/utils/writables.js +12 -71
- package/writables-D46sFgGK.cjs +85 -0
- package/writables-DoU_XYTX.js +86 -0
- package/components/accordion/accordion.js +0 -264
- package/components/alert/alert.js +0 -22
- package/components/alert/common.js +0 -69
- package/components/commonProps.js +0 -1
- package/components/modal/modal.js +0 -186
- package/components/pagination/bootstrap.d.ts +0 -8
- package/components/pagination/bootstrap.js +0 -110
- package/components/pagination/pagination.js +0 -195
- package/components/progressbar/progressbar.js +0 -78
- package/components/rating/rating.js +0 -137
- package/components/select/select.js +0 -297
- package/components/slider/slider.js +0 -420
- package/components/toast/toast.js +0 -43
- package/services/transitions/bootstrap/collapse.d.ts +0 -2
- package/services/transitions/bootstrap/collapse.js +0 -15
- package/services/transitions/bootstrap/fade.d.ts +0 -1
- package/services/transitions/bootstrap/fade.js +0 -7
- package/services/transitions/bootstrap.d.ts +0 -2
- package/services/transitions/bootstrap.js +0 -2
- package/utils/internal/checks.js +0 -60
- package/utils/internal/dom.js +0 -82
- package/utils/internal/func.js +0 -11
- package/utils/internal/isFocusable.js +0 -37
- package/utils/internal/math.js +0 -13
- package/utils/internal/promise.js +0 -169
- package/utils/internal/scrollbars.js +0 -33
- package/utils/internal/sort.js +0 -28
- package/utils/internal/textDirection.js +0 -7
- package/utils/internal/traversal.js +0 -105
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
import { computed, writable } from '@amadeus-it-group/tansu';
|
|
2
|
-
import { createStoreDirective, mergeDirectives } from '../../utils/directive';
|
|
3
|
-
import { noop } from '../../utils/internal/func';
|
|
4
|
-
import { getDecimalPrecision } from '../../utils/internal/math';
|
|
5
|
-
import { bindableProp, stateStores, writablesForProps } from '../../utils/stores';
|
|
6
|
-
import { typeArray, typeBoolean, typeFunction, typeNumber, typeNumberInRangeFactory } from '../../utils/writables';
|
|
7
|
-
import { createResizeObserver } from '../../services/resizeObserver';
|
|
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) => '' + value,
|
|
17
|
-
ariaValueText: (value) => '' + value,
|
|
18
|
-
onValuesChange: noop,
|
|
19
|
-
values: [0],
|
|
20
|
-
showValueLabels: true,
|
|
21
|
-
showMinMaxLabels: true,
|
|
22
|
-
rtl: false,
|
|
23
|
-
slotStructure: undefined,
|
|
24
|
-
slotLabel: ({ value }) => '' + value,
|
|
25
|
-
slotHandle: undefined,
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Returns a shallow copy of the default slider config.
|
|
29
|
-
* @returns a copy of the default config
|
|
30
|
-
*/
|
|
31
|
-
export function getSliderDefaultConfig() {
|
|
32
|
-
return { ...defaultSliderConfig };
|
|
33
|
-
}
|
|
34
|
-
const configValidator = {
|
|
35
|
-
min: typeNumber,
|
|
36
|
-
max: typeNumber,
|
|
37
|
-
stepSize: typeNumberInRangeFactory(0, +Infinity, { strict: true }),
|
|
38
|
-
readonly: typeBoolean,
|
|
39
|
-
disabled: typeBoolean,
|
|
40
|
-
vertical: typeBoolean,
|
|
41
|
-
ariaLabelHandle: typeFunction,
|
|
42
|
-
ariaValueText: typeFunction,
|
|
43
|
-
onValuesChange: typeFunction,
|
|
44
|
-
values: typeArray,
|
|
45
|
-
showValueLabels: typeBoolean,
|
|
46
|
-
showMinMaxLabels: typeBoolean,
|
|
47
|
-
rtl: typeBoolean,
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Computes slider clean value based on the input parameters
|
|
51
|
-
* @param value - dirty value
|
|
52
|
-
* @param min - minimum value
|
|
53
|
-
* @param max - maximum value
|
|
54
|
-
* @param intStepSize - step size converted to integer
|
|
55
|
-
* @param decimalPrecision - maximum decimum precision of slider values
|
|
56
|
-
* @returns adjusted clean value
|
|
57
|
-
*/
|
|
58
|
-
const computeCleanValue = (value, min, max, intStepSize, decimalPrecision) => {
|
|
59
|
-
const magnitude = Math.pow(10, decimalPrecision);
|
|
60
|
-
if (value >= max) {
|
|
61
|
-
return max;
|
|
62
|
-
}
|
|
63
|
-
else if (value <= min) {
|
|
64
|
-
return min;
|
|
65
|
-
}
|
|
66
|
-
const indexMin = Math.floor(((value - min) * magnitude) / intStepSize);
|
|
67
|
-
return +(((((value - min) * magnitude) % intStepSize < intStepSize / 2 ? indexMin : indexMin + 1) * intStepSize) / magnitude + min).toFixed(decimalPrecision);
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Method to update the values for the slider keyboard navigation
|
|
71
|
-
* @param handleIndex - index of the handle to update
|
|
72
|
-
* @param values$ - writable signal that contains values
|
|
73
|
-
* @param stepSize - slider step size
|
|
74
|
-
* @param updateDirection - if equals 1 value is increased, if equals -1 value is decreased
|
|
75
|
-
*/
|
|
76
|
-
const updateValue = (handleIndex, values$, stepSize, updateDirection) => {
|
|
77
|
-
values$.update((value) => {
|
|
78
|
-
value = [...value];
|
|
79
|
-
value[handleIndex] = value[handleIndex] + stepSize * updateDirection;
|
|
80
|
-
return value;
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
const getUpdateDirection = (vertical, rtl, keysVertical) => {
|
|
84
|
-
if (vertical && rtl) {
|
|
85
|
-
return keysVertical ? 1 : -1;
|
|
86
|
-
}
|
|
87
|
-
else if (vertical && !rtl) {
|
|
88
|
-
return -1;
|
|
89
|
-
}
|
|
90
|
-
else if (!vertical && rtl) {
|
|
91
|
-
return keysVertical ? -1 : 1;
|
|
92
|
-
}
|
|
93
|
-
else if (!vertical && !rtl) {
|
|
94
|
-
return -1;
|
|
95
|
-
}
|
|
96
|
-
return 1;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Create a slider widget with given config props
|
|
100
|
-
* @param config - an optional slider config
|
|
101
|
-
* @returns a SliderWidget
|
|
102
|
-
*/
|
|
103
|
-
export function createSlider(config) {
|
|
104
|
-
const [{
|
|
105
|
-
// dirty inputs that need adjustment:
|
|
106
|
-
min$: _dirtyMinimum$, max$: _dirtyMaximum$, stepSize$, rtl$, values$: _dirtyValues$, ariaLabelHandle$, ariaValueText$, onValuesChange$, showValueLabels$, showMinMaxLabels$, ...stateProps }, patch,] = writablesForProps(defaultSliderConfig, config, configValidator);
|
|
107
|
-
const { vertical$, disabled$, readonly$ } = stateProps;
|
|
108
|
-
let _prevCoordinate = -1;
|
|
109
|
-
// clean inputs adjustment
|
|
110
|
-
const min$ = computed(() => {
|
|
111
|
-
const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
|
|
112
|
-
if (_dirtyMinimum === _dirtyMaximum) {
|
|
113
|
-
return defaultSliderConfig.min;
|
|
114
|
-
}
|
|
115
|
-
return Math.min(_dirtyMinimum, _dirtyMaximum);
|
|
116
|
-
});
|
|
117
|
-
const max$ = computed(() => {
|
|
118
|
-
const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
|
|
119
|
-
if (_dirtyMinimum === _dirtyMaximum) {
|
|
120
|
-
return defaultSliderConfig.max;
|
|
121
|
-
}
|
|
122
|
-
return Math.max(_dirtyMinimum, _dirtyMaximum);
|
|
123
|
-
});
|
|
124
|
-
const _decimalPrecision$ = computed(() => Math.max(getDecimalPrecision(stepSize$()), getDecimalPrecision(min$()), getDecimalPrecision(max$())));
|
|
125
|
-
const _intStepSize$ = computed(() => stepSize$() * Math.pow(10, _decimalPrecision$()));
|
|
126
|
-
const values$ = bindableProp(_dirtyValues$, onValuesChange$, (dirtyValues) => {
|
|
127
|
-
const min = min$();
|
|
128
|
-
const max = max$();
|
|
129
|
-
const intStepSize = _intStepSize$();
|
|
130
|
-
const decimalPrecision = _decimalPrecision$();
|
|
131
|
-
return dirtyValues.map((dv) => computeCleanValue(dv, min, max, intStepSize, decimalPrecision));
|
|
132
|
-
}, typeArray.equal);
|
|
133
|
-
// computed
|
|
134
|
-
const { directive: sliderDirective, element$: sliderDom$ } = createStoreDirective();
|
|
135
|
-
const { directive: minLabelDirective, element$: minLabelDom$ } = createStoreDirective();
|
|
136
|
-
const { directive: maxLabelDirective, element$: maxLabelDom$ } = createStoreDirective();
|
|
137
|
-
const { directive: resizeDirective, dimensions$ } = createResizeObserver();
|
|
138
|
-
const updateSliderSize$ = writable({});
|
|
139
|
-
const sliderDomRect$ = computed(() => {
|
|
140
|
-
dimensions$();
|
|
141
|
-
updateSliderSize$();
|
|
142
|
-
return sliderDom$()?.getBoundingClientRect() ?? {};
|
|
143
|
-
}, {
|
|
144
|
-
equal: Object.is,
|
|
145
|
-
});
|
|
146
|
-
const minLabelDomRect$ = computed(() => {
|
|
147
|
-
dimensions$();
|
|
148
|
-
updateSliderSize$();
|
|
149
|
-
return minLabelDom$()?.getBoundingClientRect() ?? {};
|
|
150
|
-
}, {
|
|
151
|
-
equal: (a, b) => Object.is(a, b),
|
|
152
|
-
});
|
|
153
|
-
const maxLabelDomRect$ = computed(() => {
|
|
154
|
-
dimensions$();
|
|
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$(), ariaValueText = ariaValueText$();
|
|
172
|
-
return _sortedHandlesValues$().map((sortedValue, index) => {
|
|
173
|
-
return {
|
|
174
|
-
...sortedValue,
|
|
175
|
-
ariaLabel: ariaLabelHandle(sortedValue.value, index, sortedValue.id),
|
|
176
|
-
ariaValueText: ariaValueText(sortedValue.value, index, sortedValue.id),
|
|
177
|
-
};
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
const valuesPercent$ = computed(() => values$().map((val) => percentCompute(val)));
|
|
181
|
-
const sortedValuesPercent$ = computed(() => [...valuesPercent$()].sort((a, b) => a - b));
|
|
182
|
-
const minLabelWidth$ = computed(() => (minLabelDomRect$().width / sliderDomRectSize$()) * 100);
|
|
183
|
-
const maxLabelWidth$ = computed(() => (maxLabelDomRect$().width / sliderDomRectSize$()) * 100);
|
|
184
|
-
const minValueLabelDisplay$ = computed(() => {
|
|
185
|
-
if (!showMinMaxLabels$()) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
else if (!showValueLabels$()) {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
const minLabelWidth = minLabelWidth$();
|
|
192
|
-
return rtl$()
|
|
193
|
-
? !valuesPercent$().some((percent) => 100 - percent > 100 - minLabelWidth - 1)
|
|
194
|
-
: !valuesPercent$().some((percent) => percent < minLabelWidth + 1);
|
|
195
|
-
});
|
|
196
|
-
const maxValueLabelDisplay$ = computed(() => {
|
|
197
|
-
if (!showMinMaxLabels$()) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
else if (!showValueLabels$()) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
const maxLabelWidth = maxLabelWidth$();
|
|
204
|
-
return rtl$()
|
|
205
|
-
? !valuesPercent$().some((percent) => 100 - percent < maxLabelWidth + 1)
|
|
206
|
-
: !valuesPercent$().some((percent) => percent > 100 - maxLabelWidth - 1);
|
|
207
|
-
});
|
|
208
|
-
// TODO define the intersection value
|
|
209
|
-
const combinedLabelDisplay$ = computed(() => {
|
|
210
|
-
const values = values$();
|
|
211
|
-
return values.length == 2 && Math.abs(values[0] - values[1]) < 10;
|
|
212
|
-
});
|
|
213
|
-
const isInteractable$ = computed(() => !disabled$() && !readonly$());
|
|
214
|
-
const combinedLabelPositionLeft$ = computed(() => {
|
|
215
|
-
const sortedValuesPercent = sortedValuesPercent$();
|
|
216
|
-
const combinedPosition = (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
|
|
217
|
-
return vertical$() || sortedValuesPercent.length != 2 ? 0 : rtl$() ? 100 - combinedPosition : combinedPosition;
|
|
218
|
-
});
|
|
219
|
-
const combinedLabelPositionTop$ = computed(() => {
|
|
220
|
-
const sortedValuesPercent = sortedValuesPercent$();
|
|
221
|
-
const combinedPosition = 100 - (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
|
|
222
|
-
return vertical$() && sortedValuesPercent.length == 2 ? (rtl$() ? 100 - combinedPosition : combinedPosition) : 0;
|
|
223
|
-
});
|
|
224
|
-
const handleDisplayOptions$ = computed(() => {
|
|
225
|
-
const vertical = vertical$(), rtl = rtl$();
|
|
226
|
-
return valuesPercent$().map((vp, index) => {
|
|
227
|
-
return {
|
|
228
|
-
left: rtl ? (vertical ? null : 100 - vp) : vertical ? null : vp,
|
|
229
|
-
top: rtl ? (vertical ? vp : null) : vertical ? 100 - vp : null,
|
|
230
|
-
};
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
const progressDisplayOptions$ = computed(() => {
|
|
234
|
-
const vertical = vertical$(), sortedValuesPercent = sortedValuesPercent$(), rtl = rtl$();
|
|
235
|
-
if (sortedValuesPercent.length === 1) {
|
|
236
|
-
return [
|
|
237
|
-
{
|
|
238
|
-
left: vertical ? null : rtl ? null : 0,
|
|
239
|
-
right: vertical ? null : rtl ? 0 : null,
|
|
240
|
-
bottom: vertical ? (rtl ? null : 0) : null,
|
|
241
|
-
top: vertical ? (rtl ? 0 : null) : null,
|
|
242
|
-
width: vertical ? 100 : sortedValuesPercent[0],
|
|
243
|
-
height: vertical ? sortedValuesPercent[0] : 100,
|
|
244
|
-
},
|
|
245
|
-
];
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
return sortedValuesPercent
|
|
249
|
-
.map((svp, index, array) => {
|
|
250
|
-
return {
|
|
251
|
-
left: vertical ? null : rtl ? null : svp,
|
|
252
|
-
right: vertical ? null : rtl ? array[index] : null,
|
|
253
|
-
bottom: vertical ? (rtl ? null : svp) : null,
|
|
254
|
-
top: vertical ? (rtl ? array[index] : null) : null,
|
|
255
|
-
width: vertical ? 100 : index === array.length - 1 ? svp : array[index + 1] - svp,
|
|
256
|
-
height: vertical ? (index === array.length - 1 ? svp : array[index + 1] - svp) : 100,
|
|
257
|
-
};
|
|
258
|
-
})
|
|
259
|
-
.slice(0, sortedValuesPercent.length - 1);
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
// functions
|
|
263
|
-
const percentCompute = (value) => {
|
|
264
|
-
const min = min$();
|
|
265
|
-
return ((value - min) * 100) / (max$() - min);
|
|
266
|
-
};
|
|
267
|
-
const getClosestSliderHandle = (clickedPercent) => {
|
|
268
|
-
const values = values$();
|
|
269
|
-
if (values.length === 1) {
|
|
270
|
-
return 0;
|
|
271
|
-
}
|
|
272
|
-
const sortedValues = sortedValues$();
|
|
273
|
-
const closestBigger = sortedValues.find((sv) => sv > clickedPercent * 100);
|
|
274
|
-
const closestBiggerIndex = closestBigger ? sortedValues.indexOf(closestBigger) : sortedValues.length - 1;
|
|
275
|
-
const midPoint = sortedValues[closestBiggerIndex - 1] + (sortedValues[closestBiggerIndex] - sortedValues[closestBiggerIndex - 1]) / 2;
|
|
276
|
-
const closestValue = sortedValues[clickedPercent * 100 <= midPoint ? closestBiggerIndex - 1 : closestBiggerIndex];
|
|
277
|
-
return values.indexOf(closestValue);
|
|
278
|
-
};
|
|
279
|
-
const adjustCoordinate = (clickedCoordinate, handleNumber) => {
|
|
280
|
-
if (isInteractable$()) {
|
|
281
|
-
const sliderDomRectSize = sliderDomRectSize$(), sliderDomRectOffset = sliderDomRectOffset$();
|
|
282
|
-
let clickedPercent = vertical$()
|
|
283
|
-
? (sliderDomRectSize - clickedCoordinate + sliderDomRectOffset) / sliderDomRectSize
|
|
284
|
-
: (clickedCoordinate - sliderDomRectOffset) / sliderDomRectSize;
|
|
285
|
-
clickedPercent = rtl$() ? 1 - clickedPercent : clickedPercent;
|
|
286
|
-
const derivedHandleIndex = handleNumber ?? getClosestSliderHandle(clickedPercent);
|
|
287
|
-
const newValue = clickedPercent * (max$() - min$()) + min$();
|
|
288
|
-
values$.update((dh) => {
|
|
289
|
-
dh = [...dh];
|
|
290
|
-
dh[derivedHandleIndex] = newValue;
|
|
291
|
-
return dh;
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
return {
|
|
296
|
-
...stateStores({
|
|
297
|
-
min$,
|
|
298
|
-
max$,
|
|
299
|
-
stepSize$,
|
|
300
|
-
values$,
|
|
301
|
-
sortedValues$,
|
|
302
|
-
sortedHandles$,
|
|
303
|
-
minValueLabelDisplay$,
|
|
304
|
-
maxValueLabelDisplay$,
|
|
305
|
-
combinedLabelDisplay$,
|
|
306
|
-
isInteractable$,
|
|
307
|
-
combinedLabelPositionLeft$,
|
|
308
|
-
combinedLabelPositionTop$,
|
|
309
|
-
progressDisplayOptions$,
|
|
310
|
-
handleDisplayOptions$,
|
|
311
|
-
showValueLabels$,
|
|
312
|
-
showMinMaxLabels$,
|
|
313
|
-
rtl$,
|
|
314
|
-
...stateProps,
|
|
315
|
-
}),
|
|
316
|
-
patch,
|
|
317
|
-
api: {},
|
|
318
|
-
directives: {
|
|
319
|
-
sliderDirective: mergeDirectives(sliderDirective, resizeDirective),
|
|
320
|
-
minLabelDirective,
|
|
321
|
-
maxLabelDirective,
|
|
322
|
-
},
|
|
323
|
-
actions: {
|
|
324
|
-
click(event) {
|
|
325
|
-
adjustCoordinate(vertical$() ? event.clientY : event.clientX);
|
|
326
|
-
},
|
|
327
|
-
keydown(event, handleIndex) {
|
|
328
|
-
const { key } = event;
|
|
329
|
-
const rtl = rtl$(), stepSize = stepSize$(), min = min$(), max = max$(), vertical = vertical$();
|
|
330
|
-
if (isInteractable$()) {
|
|
331
|
-
switch (key) {
|
|
332
|
-
case 'ArrowDown':
|
|
333
|
-
updateValue(handleIndex, values$, stepSize, getUpdateDirection(vertical, rtl, true));
|
|
334
|
-
break;
|
|
335
|
-
case 'ArrowLeft':
|
|
336
|
-
updateValue(handleIndex, values$, stepSize, getUpdateDirection(vertical, rtl, false));
|
|
337
|
-
break;
|
|
338
|
-
case 'ArrowUp':
|
|
339
|
-
updateValue(handleIndex, values$, stepSize, -1 * getUpdateDirection(vertical, rtl, true));
|
|
340
|
-
break;
|
|
341
|
-
case 'ArrowRight':
|
|
342
|
-
updateValue(handleIndex, values$, stepSize, -1 * getUpdateDirection(vertical, rtl, false));
|
|
343
|
-
break;
|
|
344
|
-
case 'Home':
|
|
345
|
-
values$.update((value) => {
|
|
346
|
-
value = [...value];
|
|
347
|
-
value[handleIndex] = min;
|
|
348
|
-
return value;
|
|
349
|
-
});
|
|
350
|
-
break;
|
|
351
|
-
case 'End':
|
|
352
|
-
values$.update((value) => {
|
|
353
|
-
value = [...value];
|
|
354
|
-
value[handleIndex] = max;
|
|
355
|
-
return value;
|
|
356
|
-
});
|
|
357
|
-
break;
|
|
358
|
-
case 'PageUp':
|
|
359
|
-
// TODO it is optional in accessibility guidelines, so define the skip value for steps and write unit test
|
|
360
|
-
break;
|
|
361
|
-
case 'PageDown':
|
|
362
|
-
// TODO it is optional in accessibility guidelines, so define the skip value for steps and write unit test
|
|
363
|
-
break;
|
|
364
|
-
default:
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
event.preventDefault();
|
|
368
|
-
event.stopPropagation();
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
mouseDown(event, handleId) {
|
|
372
|
-
event.preventDefault();
|
|
373
|
-
const currentTarget = event.target;
|
|
374
|
-
const handleDrag = (e) => {
|
|
375
|
-
e.preventDefault();
|
|
376
|
-
const newCoord = vertical$() ? e.clientY : e.clientX;
|
|
377
|
-
currentTarget.focus();
|
|
378
|
-
if (_prevCoordinate !== newCoord) {
|
|
379
|
-
_prevCoordinate = newCoord;
|
|
380
|
-
adjustCoordinate(newCoord, handleId);
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
if (isInteractable$()) {
|
|
384
|
-
updateSliderSize$.set({});
|
|
385
|
-
currentTarget.focus();
|
|
386
|
-
document.addEventListener('mousemove', handleDrag);
|
|
387
|
-
// TODO mouse up doesn't work outside the handle area
|
|
388
|
-
document.addEventListener('mouseup', () => {
|
|
389
|
-
document.removeEventListener('mousemove', handleDrag);
|
|
390
|
-
}, { once: true });
|
|
391
|
-
}
|
|
392
|
-
},
|
|
393
|
-
touchStart(event, handleId) {
|
|
394
|
-
event.preventDefault();
|
|
395
|
-
const handleDrag = (e) => {
|
|
396
|
-
e.preventDefault();
|
|
397
|
-
const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX;
|
|
398
|
-
event.target.focus();
|
|
399
|
-
if (_prevCoordinate !== newCoord) {
|
|
400
|
-
_prevCoordinate = newCoord;
|
|
401
|
-
adjustCoordinate(newCoord, handleId);
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
if (isInteractable$()) {
|
|
405
|
-
updateSliderSize$.set({});
|
|
406
|
-
event.target.focus();
|
|
407
|
-
document.addEventListener('touchmove', handleDrag);
|
|
408
|
-
document.addEventListener('touchend', () => {
|
|
409
|
-
document.removeEventListener('touchmove', handleDrag);
|
|
410
|
-
document.removeEventListener('touchcancel', handleDrag);
|
|
411
|
-
}, { once: true });
|
|
412
|
-
document.addEventListener('touchcancel', () => {
|
|
413
|
-
document.removeEventListener('touchmove', handleDrag);
|
|
414
|
-
document.removeEventListener('touchend', handleDrag);
|
|
415
|
-
}, { once: true });
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
};
|
|
420
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { computed } from '@amadeus-it-group/tansu';
|
|
2
|
-
import { extendWidgetProps } from '../../services/extendWidget';
|
|
3
|
-
import { directiveSubscribe } from '../../utils/directive';
|
|
4
|
-
import { typeBoolean, typeNumberInRangeFactory } from '../../utils/writables';
|
|
5
|
-
import { createCommonAlert, getCommonAlertDefaultConfig } from '../alert/common';
|
|
6
|
-
const toastDefaultConfig = {
|
|
7
|
-
autohide: true,
|
|
8
|
-
delay: 5000,
|
|
9
|
-
slotHeader: undefined,
|
|
10
|
-
};
|
|
11
|
-
const toastConfigValidator = {
|
|
12
|
-
autohide: typeBoolean,
|
|
13
|
-
delay: typeNumberInRangeFactory(0, +Infinity, { strict: true }),
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Retrieve a shallow copy of the default toast config
|
|
17
|
-
* @returns the default toast config
|
|
18
|
-
*/
|
|
19
|
-
export function getToastDefaultConfig() {
|
|
20
|
-
return { ...getCommonAlertDefaultConfig(), ...toastDefaultConfig };
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a ToastWidget with given config props
|
|
24
|
-
* @param config - an optional toast config
|
|
25
|
-
* @returns a ToastWidget
|
|
26
|
-
*/
|
|
27
|
-
export function createToast(config) {
|
|
28
|
-
let _timeout;
|
|
29
|
-
const extendedAlert = extendWidgetProps(createCommonAlert, toastDefaultConfig, toastConfigValidator)(config);
|
|
30
|
-
const time$ = computed(() => {
|
|
31
|
-
clearTimeout(_timeout);
|
|
32
|
-
if (extendedAlert.stores.autohide$()) {
|
|
33
|
-
_timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
...extendedAlert,
|
|
38
|
-
directives: {
|
|
39
|
-
...extendedAlert.directives,
|
|
40
|
-
autohideDirective: directiveSubscribe(time$),
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { createCollapseTransition } from '../collapse';
|
|
2
|
-
const verticalConfig = {
|
|
3
|
-
dimension: 'height',
|
|
4
|
-
hideClasses: ['collapse'],
|
|
5
|
-
showClasses: ['collapse', 'show'],
|
|
6
|
-
animationPendingClasses: ['collapsing'],
|
|
7
|
-
};
|
|
8
|
-
const horizontalConfig = {
|
|
9
|
-
dimension: 'width',
|
|
10
|
-
hideClasses: ['collapse', 'collapse-horizontal'],
|
|
11
|
-
showClasses: ['collapse', 'collapse-horizontal', 'show'],
|
|
12
|
-
animationPendingClasses: ['collapsing', 'collapse-horizontal'],
|
|
13
|
-
};
|
|
14
|
-
export const collapseVerticalTransition = createCollapseTransition(verticalConfig);
|
|
15
|
-
export const collapseHorizontalTransition = createCollapseTransition(horizontalConfig);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const fadeTransition: import("../baseTransitions").TransitionFn;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createSimpleClassTransition } from '../simpleClassTransition';
|
|
2
|
-
export const fadeTransition = createSimpleClassTransition({
|
|
3
|
-
animationPendingClasses: ['fade'],
|
|
4
|
-
animationPendingShowClasses: ['show'],
|
|
5
|
-
showClasses: ['show', 'fade'],
|
|
6
|
-
hideClasses: ['d-none', 'fade'],
|
|
7
|
-
});
|
package/utils/internal/checks.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* a number type guard
|
|
3
|
-
* @param value - the value to check
|
|
4
|
-
* @returns true if the value is a number
|
|
5
|
-
*/
|
|
6
|
-
export function isNumber(value) {
|
|
7
|
-
return typeof value === 'number' && !isNaN(value) && Number.isFinite(value);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* a boolean type guard
|
|
11
|
-
* @param value - the value to check
|
|
12
|
-
* @returns true if the value is a boolean
|
|
13
|
-
*/
|
|
14
|
-
export function isBoolean(value) {
|
|
15
|
-
return value === true || value === false;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* a function type guard
|
|
19
|
-
* @param value - the value to check
|
|
20
|
-
* @returns true if the value is a function
|
|
21
|
-
*/
|
|
22
|
-
export function isFunction(value) {
|
|
23
|
-
return typeof value === 'function';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* a string type guard
|
|
27
|
-
* @param value - the value to check
|
|
28
|
-
* @returns true if the value is a string
|
|
29
|
-
*/
|
|
30
|
-
export function isString(value) {
|
|
31
|
-
return typeof value === 'string';
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* an array type guard
|
|
35
|
-
* @returns true if the value is an array
|
|
36
|
-
*/
|
|
37
|
-
export const isArray = Array.isArray;
|
|
38
|
-
// TODO should we check that max > min?
|
|
39
|
-
/**
|
|
40
|
-
* Clamp the value based on a maximum and optional minimum
|
|
41
|
-
* @param value - the value to check
|
|
42
|
-
* @param max - the max to clamp to
|
|
43
|
-
* @param [min] - the min to clamp to
|
|
44
|
-
* @returns the clamped value
|
|
45
|
-
*/
|
|
46
|
-
export function clamp(value, max, min = 0) {
|
|
47
|
-
return Math.max(Math.min(value, max), min);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* an html element type guard
|
|
51
|
-
* @param value - the value to check
|
|
52
|
-
* @returns true if the value is an instance of HTMLElement
|
|
53
|
-
*/
|
|
54
|
-
export const isHTMLElement = (value) => value instanceof HTMLElement;
|
|
55
|
-
/**
|
|
56
|
-
* Returns a new type guard that is based on the provided type guard and also returns true for null values.
|
|
57
|
-
* @param isType - base type guard
|
|
58
|
-
* @returns A type guard function that returns true for null values and calls the provided type guard for other values.
|
|
59
|
-
*/
|
|
60
|
-
export const allowNull = (isType) => (value) => value === null || isType(value);
|
package/utils/internal/dom.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the common ancestor of the provided DOM elements.
|
|
3
|
-
* @param elements - array of DOM elements
|
|
4
|
-
* @returns the common ancestor, or null if the array is empty or if there is no common ancestor (e.g.: if elements are detached)
|
|
5
|
-
*/
|
|
6
|
-
export const computeCommonAncestor = (elements) => {
|
|
7
|
-
const length = elements.length;
|
|
8
|
-
if (length === 0)
|
|
9
|
-
return null;
|
|
10
|
-
let ancestor = elements[0];
|
|
11
|
-
for (let i = 1; i < length && ancestor; i++) {
|
|
12
|
-
const element = elements[i];
|
|
13
|
-
while (ancestor) {
|
|
14
|
-
if (ancestor === element) {
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
const comparison = ancestor.compareDocumentPosition(element);
|
|
18
|
-
if (comparison & Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
else if (comparison & Node.DOCUMENT_POSITION_CONTAINS) {
|
|
22
|
-
ancestor = element;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
else if (comparison & Node.DOCUMENT_POSITION_DISCONNECTED) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
ancestor = ancestor.parentElement;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return ancestor;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Launch a reflow using a call to the provided html element getBoudingClientRect
|
|
35
|
-
* @param element - the html element
|
|
36
|
-
*/
|
|
37
|
-
export function reflow(element = document.body) {
|
|
38
|
-
element.getBoundingClientRect();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Attach the given css classes to the element
|
|
42
|
-
*
|
|
43
|
-
* @param element - the HTML element
|
|
44
|
-
* @param classes - the css lcasses
|
|
45
|
-
*/
|
|
46
|
-
export const addClasses = (element, classes) => {
|
|
47
|
-
if (classes && classes.length > 0) {
|
|
48
|
-
element.classList.add(...classes);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Remove the given css classes to the element
|
|
53
|
-
*
|
|
54
|
-
* @param element - the HTML element
|
|
55
|
-
* @param classes - the css classes
|
|
56
|
-
*/
|
|
57
|
-
export const removeClasses = (element, classes) => {
|
|
58
|
-
if (classes && classes.length > 0) {
|
|
59
|
-
element.classList.remove(...classes);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Adds an event listener to the specified element.
|
|
64
|
-
*
|
|
65
|
-
* @param element - The HTML element to which the event listener will be added.
|
|
66
|
-
* @param type - A string representing the event type to listen for.
|
|
67
|
-
* @param fn - The event listener function or object.
|
|
68
|
-
* @returns A function that removes the event listener from the element.
|
|
69
|
-
*/
|
|
70
|
-
export function addEvent(element, type, fn) {
|
|
71
|
-
element.addEventListener(type, fn);
|
|
72
|
-
return function () {
|
|
73
|
-
element.removeEventListener(type, fn);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
let idCount = 0;
|
|
77
|
-
/**
|
|
78
|
-
* Generates a unique ID with the format 'auId-[counter]'.
|
|
79
|
-
*
|
|
80
|
-
* @returns The generated ID.
|
|
81
|
-
*/
|
|
82
|
-
export const generateId = () => `auId-${idCount++}`;
|