@agnos-ui/core 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +57 -64
- 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 +107 -128
- 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 +45 -57
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.js +5 -1
- package/components/slider/slider.d.ts +63 -5
- package/components/toast/index.cjs +5 -0
- package/components/toast/index.d.ts +1 -0
- package/components/toast/index.js +5 -0
- package/components/toast/toast.d.ts +47 -0
- package/config.cjs +38 -0
- package/config.d.ts +6 -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 +3 -1
- package/index.js +119 -31
- package/modal-BI2qUu1M.js +251 -0
- package/modal-rzMpATf5.cjs +250 -0
- package/package.json +30 -22
- 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 +10 -5
- 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.d.ts +2 -0
- package/services/hash.js +15 -0
- 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 +24 -17
- package/services/navManager.js +186 -162
- package/services/portal.cjs +43 -0
- package/services/portal.js +41 -42
- package/services/resizeObserver.cjs +32 -0
- package/services/resizeObserver.d.ts +14 -0
- package/services/resizeObserver.js +32 -0
- 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 +155 -4
- package/utils/directive.js +25 -189
- package/utils/internal/dom.d.ts +57 -3
- package/utils/internal/promise.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +7 -0
- package/utils/internal/textDirection.d.ts +1 -1
- package/utils/stores.cjs +163 -0
- package/utils/stores.d.ts +23 -20
- package/utils/stores.js +151 -269
- 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 -267
- 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 -149
- package/components/progressbar/progressbar.js +0 -78
- package/components/rating/rating.js +0 -138
- package/components/select/select.js +0 -266
- package/components/slider/slider.js +0 -415
- 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 -61
- package/utils/internal/func.js +0 -11
- package/utils/internal/isFocusable.js +0 -35
- 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
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const utils_directive = require("./directive-BTSEYLF3.cjs");
|
|
4
|
+
const func = require("./func-Qd3cD9a3.cjs");
|
|
5
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
6
|
+
const utils_writables = require("./writables-D46sFgGK.cjs");
|
|
7
|
+
const services_resizeObserver = require("./services/resizeObserver.cjs");
|
|
8
|
+
const decimalRegExp = /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;
|
|
9
|
+
function getDecimalPrecision(number) {
|
|
10
|
+
var _a;
|
|
11
|
+
const matches = ("" + number).match(decimalRegExp);
|
|
12
|
+
return Math.max(
|
|
13
|
+
0,
|
|
14
|
+
// Number of digits right of decimal point.
|
|
15
|
+
(((_a = matches[1]) == null ? void 0 : _a.length) ?? 0) - // Adjust for exponential notation.
|
|
16
|
+
(+matches[2] || 0)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
const defaultSliderConfig = {
|
|
20
|
+
min: 0,
|
|
21
|
+
max: 100,
|
|
22
|
+
stepSize: 1,
|
|
23
|
+
readonly: false,
|
|
24
|
+
disabled: false,
|
|
25
|
+
vertical: false,
|
|
26
|
+
className: "",
|
|
27
|
+
ariaLabelHandle: (value) => "" + value,
|
|
28
|
+
ariaValueText: (value) => "" + value,
|
|
29
|
+
onValuesChange: func.noop,
|
|
30
|
+
values: [0],
|
|
31
|
+
showValueLabels: true,
|
|
32
|
+
showMinMaxLabels: true,
|
|
33
|
+
rtl: false
|
|
34
|
+
};
|
|
35
|
+
function getSliderDefaultConfig() {
|
|
36
|
+
return { ...defaultSliderConfig };
|
|
37
|
+
}
|
|
38
|
+
const configValidator = {
|
|
39
|
+
min: utils_writables.typeNumber,
|
|
40
|
+
max: utils_writables.typeNumber,
|
|
41
|
+
stepSize: utils_writables.typeNumberInRangeFactory(0, Infinity, { strict: true }),
|
|
42
|
+
readonly: utils_writables.typeBoolean,
|
|
43
|
+
disabled: utils_writables.typeBoolean,
|
|
44
|
+
vertical: utils_writables.typeBoolean,
|
|
45
|
+
ariaLabelHandle: utils_writables.typeFunction,
|
|
46
|
+
ariaValueText: utils_writables.typeFunction,
|
|
47
|
+
onValuesChange: utils_writables.typeFunction,
|
|
48
|
+
values: utils_writables.typeArray,
|
|
49
|
+
showValueLabels: utils_writables.typeBoolean,
|
|
50
|
+
showMinMaxLabels: utils_writables.typeBoolean,
|
|
51
|
+
rtl: utils_writables.typeBoolean
|
|
52
|
+
};
|
|
53
|
+
const computeCleanValue = (value, min, max, intStepSize, decimalPrecision) => {
|
|
54
|
+
const magnitude = Math.pow(10, decimalPrecision);
|
|
55
|
+
if (value >= max) {
|
|
56
|
+
return max;
|
|
57
|
+
} else if (value <= min) {
|
|
58
|
+
return min;
|
|
59
|
+
}
|
|
60
|
+
const indexMin = Math.floor((value - min) * magnitude / intStepSize);
|
|
61
|
+
return +(((value - min) * magnitude % intStepSize < intStepSize / 2 ? indexMin : indexMin + 1) * intStepSize / magnitude + min).toFixed(
|
|
62
|
+
decimalPrecision
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
const updateValue = (handleIndex, values$, stepSize, updateDirection) => {
|
|
66
|
+
values$.update((value) => {
|
|
67
|
+
value = [...value];
|
|
68
|
+
value[handleIndex] = value[handleIndex] + stepSize * updateDirection;
|
|
69
|
+
return value;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const getUpdateDirection = (vertical, rtl, keysVertical) => {
|
|
73
|
+
if (vertical && rtl) {
|
|
74
|
+
return keysVertical ? 1 : -1;
|
|
75
|
+
} else if (vertical && !rtl) {
|
|
76
|
+
return -1;
|
|
77
|
+
} else if (!vertical && rtl) {
|
|
78
|
+
return keysVertical ? -1 : 1;
|
|
79
|
+
} else if (!vertical && !rtl) {
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
return 1;
|
|
83
|
+
};
|
|
84
|
+
const percent = (value) => value != null ? `${value}%` : "";
|
|
85
|
+
function createSlider(config) {
|
|
86
|
+
const [
|
|
87
|
+
{
|
|
88
|
+
// dirty inputs that need adjustment:
|
|
89
|
+
min$: _dirtyMinimum$,
|
|
90
|
+
max$: _dirtyMaximum$,
|
|
91
|
+
stepSize$,
|
|
92
|
+
rtl$,
|
|
93
|
+
values$: _dirtyValues$,
|
|
94
|
+
ariaLabelHandle$,
|
|
95
|
+
ariaValueText$,
|
|
96
|
+
onValuesChange$,
|
|
97
|
+
showValueLabels$,
|
|
98
|
+
showMinMaxLabels$,
|
|
99
|
+
...stateProps
|
|
100
|
+
},
|
|
101
|
+
patch
|
|
102
|
+
] = utils_stores.writablesForProps(defaultSliderConfig, config, configValidator);
|
|
103
|
+
const { vertical$, disabled$, readonly$ } = stateProps;
|
|
104
|
+
let _prevCoordinate = -1;
|
|
105
|
+
const min$ = tansu.computed(() => {
|
|
106
|
+
const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
|
|
107
|
+
if (_dirtyMinimum === _dirtyMaximum) {
|
|
108
|
+
return defaultSliderConfig.min;
|
|
109
|
+
}
|
|
110
|
+
return Math.min(_dirtyMinimum, _dirtyMaximum);
|
|
111
|
+
});
|
|
112
|
+
const max$ = tansu.computed(() => {
|
|
113
|
+
const _dirtyMinimum = _dirtyMinimum$(), _dirtyMaximum = _dirtyMaximum$();
|
|
114
|
+
if (_dirtyMinimum === _dirtyMaximum) {
|
|
115
|
+
return defaultSliderConfig.max;
|
|
116
|
+
}
|
|
117
|
+
return Math.max(_dirtyMinimum, _dirtyMaximum);
|
|
118
|
+
});
|
|
119
|
+
const _decimalPrecision$ = tansu.computed(() => Math.max(getDecimalPrecision(stepSize$()), getDecimalPrecision(min$()), getDecimalPrecision(max$())));
|
|
120
|
+
const _intStepSize$ = tansu.computed(() => stepSize$() * Math.pow(10, _decimalPrecision$()));
|
|
121
|
+
const values$ = utils_stores.bindableProp(
|
|
122
|
+
_dirtyValues$,
|
|
123
|
+
onValuesChange$,
|
|
124
|
+
(dirtyValues) => {
|
|
125
|
+
const min = min$();
|
|
126
|
+
const max = max$();
|
|
127
|
+
const intStepSize = _intStepSize$();
|
|
128
|
+
const decimalPrecision = _decimalPrecision$();
|
|
129
|
+
return dirtyValues.map((dv) => computeCleanValue(dv, min, max, intStepSize, decimalPrecision));
|
|
130
|
+
},
|
|
131
|
+
utils_writables.typeArray.equal
|
|
132
|
+
);
|
|
133
|
+
const { directive: sliderDirective, element$: sliderDom$ } = utils_directive.createBrowserStoreDirective();
|
|
134
|
+
const { directive: minLabelDomDirective, element$: minLabelDom$ } = utils_directive.createBrowserStoreDirective();
|
|
135
|
+
const { directive: maxLabelDomDirective, element$: maxLabelDom$ } = utils_directive.createBrowserStoreDirective();
|
|
136
|
+
const { directive: resizeDirective, dimensions$ } = services_resizeObserver.createResizeObserver();
|
|
137
|
+
const updateSliderSize$ = tansu.writable({});
|
|
138
|
+
const sliderDomRect$ = tansu.computed(
|
|
139
|
+
() => {
|
|
140
|
+
var _a;
|
|
141
|
+
dimensions$();
|
|
142
|
+
updateSliderSize$();
|
|
143
|
+
return ((_a = sliderDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
equal: Object.is
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
const minLabelDomRect$ = tansu.computed(
|
|
150
|
+
() => {
|
|
151
|
+
var _a;
|
|
152
|
+
dimensions$();
|
|
153
|
+
updateSliderSize$();
|
|
154
|
+
return ((_a = minLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
equal: (a, b) => Object.is(a, b)
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
const maxLabelDomRect$ = tansu.computed(
|
|
161
|
+
() => {
|
|
162
|
+
var _a;
|
|
163
|
+
dimensions$();
|
|
164
|
+
updateSliderSize$();
|
|
165
|
+
return ((_a = maxLabelDom$()) == null ? void 0 : _a.getBoundingClientRect()) ?? {};
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
equal: (a, b) => Object.is(a, b)
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
const sliderDomRectOffset$ = tansu.computed(() => vertical$() ? sliderDomRect$().top : sliderDomRect$().left);
|
|
172
|
+
const sliderDomRectSize$ = tansu.computed(() => vertical$() ? sliderDomRect$().height : sliderDomRect$().width);
|
|
173
|
+
const sortedValues$ = tansu.computed(() => [...values$()].sort((a, b) => a - b));
|
|
174
|
+
const _sortedHandlesValues$ = tansu.computed(() => {
|
|
175
|
+
return values$().map((val, index) => {
|
|
176
|
+
return { id: index, value: val };
|
|
177
|
+
}).sort((a, b) => a.value - b.value);
|
|
178
|
+
});
|
|
179
|
+
const sortedHandles$ = tansu.computed(() => {
|
|
180
|
+
const ariaLabelHandle = ariaLabelHandle$(), ariaValueText = ariaValueText$();
|
|
181
|
+
return _sortedHandlesValues$().map((sortedValue, index) => {
|
|
182
|
+
return {
|
|
183
|
+
...sortedValue,
|
|
184
|
+
ariaLabel: ariaLabelHandle(sortedValue.value, index, sortedValue.id),
|
|
185
|
+
ariaValueText: ariaValueText(sortedValue.value, index, sortedValue.id)
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
const valuesPercent$ = tansu.computed(() => values$().map((val) => percentCompute(val)));
|
|
190
|
+
const sortedValuesPercent$ = tansu.computed(() => [...valuesPercent$()].sort((a, b) => a - b));
|
|
191
|
+
const minLabelWidth$ = tansu.computed(() => minLabelDomRect$().width / sliderDomRectSize$() * 100);
|
|
192
|
+
const maxLabelWidth$ = tansu.computed(() => maxLabelDomRect$().width / sliderDomRectSize$() * 100);
|
|
193
|
+
const minValueLabelDisplay$ = tansu.computed(() => {
|
|
194
|
+
if (!showMinMaxLabels$()) {
|
|
195
|
+
return false;
|
|
196
|
+
} else if (!showValueLabels$()) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
const minLabelWidth = minLabelWidth$();
|
|
200
|
+
return rtl$() ? !valuesPercent$().some((percent2) => 100 - percent2 > 100 - minLabelWidth - 1) : !valuesPercent$().some((percent2) => percent2 < minLabelWidth + 1);
|
|
201
|
+
});
|
|
202
|
+
const maxValueLabelDisplay$ = tansu.computed(() => {
|
|
203
|
+
if (!showMinMaxLabels$()) {
|
|
204
|
+
return false;
|
|
205
|
+
} else if (!showValueLabels$()) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const maxLabelWidth = maxLabelWidth$();
|
|
209
|
+
return rtl$() ? !valuesPercent$().some((percent2) => 100 - percent2 < maxLabelWidth + 1) : !valuesPercent$().some((percent2) => percent2 > 100 - maxLabelWidth - 1);
|
|
210
|
+
});
|
|
211
|
+
const combinedLabelDisplay$ = tansu.computed(() => {
|
|
212
|
+
const values = values$();
|
|
213
|
+
return values.length == 2 && Math.abs(values[0] - values[1]) < 10;
|
|
214
|
+
});
|
|
215
|
+
const interactive$ = tansu.computed(() => !disabled$() && !readonly$());
|
|
216
|
+
const combinedLabelPositionLeft$ = tansu.computed(() => {
|
|
217
|
+
const sortedValuesPercent = sortedValuesPercent$();
|
|
218
|
+
const combinedPosition = (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
|
|
219
|
+
return vertical$() || sortedValuesPercent.length != 2 ? 0 : rtl$() ? 100 - combinedPosition : combinedPosition;
|
|
220
|
+
});
|
|
221
|
+
const combinedLabelPositionTop$ = tansu.computed(() => {
|
|
222
|
+
const sortedValuesPercent = sortedValuesPercent$();
|
|
223
|
+
const combinedPosition = 100 - (sortedValuesPercent[0] + sortedValuesPercent[1]) / 2;
|
|
224
|
+
return vertical$() && sortedValuesPercent.length == 2 ? rtl$() ? 100 - combinedPosition : combinedPosition : 0;
|
|
225
|
+
});
|
|
226
|
+
const handleDisplayOptions$ = tansu.computed(() => {
|
|
227
|
+
const vertical = vertical$(), rtl = rtl$();
|
|
228
|
+
return valuesPercent$().map((vp, index) => {
|
|
229
|
+
return {
|
|
230
|
+
left: rtl ? vertical ? null : 100 - vp : vertical ? null : vp,
|
|
231
|
+
top: rtl ? vertical ? vp : null : vertical ? 100 - vp : null
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
const progressDisplayOptions$ = tansu.computed(() => {
|
|
236
|
+
const vertical = vertical$(), sortedValuesPercent = sortedValuesPercent$(), rtl = rtl$();
|
|
237
|
+
if (sortedValuesPercent.length === 1) {
|
|
238
|
+
return [
|
|
239
|
+
{
|
|
240
|
+
left: vertical ? null : rtl ? null : 0,
|
|
241
|
+
right: vertical ? null : rtl ? 0 : null,
|
|
242
|
+
bottom: vertical ? rtl ? null : 0 : null,
|
|
243
|
+
top: vertical ? rtl ? 0 : null : null,
|
|
244
|
+
width: vertical ? 100 : sortedValuesPercent[0],
|
|
245
|
+
height: vertical ? sortedValuesPercent[0] : 100
|
|
246
|
+
}
|
|
247
|
+
];
|
|
248
|
+
} else {
|
|
249
|
+
return sortedValuesPercent.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
|
+
}).slice(0, sortedValuesPercent.length - 1);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
const percentCompute = (value) => {
|
|
262
|
+
const min = min$();
|
|
263
|
+
return (value - min) * 100 / (max$() - min);
|
|
264
|
+
};
|
|
265
|
+
const getClosestSliderHandle = (clickedPercent) => {
|
|
266
|
+
const values = values$();
|
|
267
|
+
if (values.length === 1) {
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
const sortedValues = sortedValues$();
|
|
271
|
+
const closestBigger = sortedValues.find((sv) => sv > clickedPercent * 100);
|
|
272
|
+
const closestBiggerIndex = closestBigger ? sortedValues.indexOf(closestBigger) : sortedValues.length - 1;
|
|
273
|
+
const midPoint = sortedValues[closestBiggerIndex - 1] + (sortedValues[closestBiggerIndex] - sortedValues[closestBiggerIndex - 1]) / 2;
|
|
274
|
+
const closestValue = sortedValues[clickedPercent * 100 <= midPoint ? closestBiggerIndex - 1 : closestBiggerIndex];
|
|
275
|
+
return values.indexOf(closestValue);
|
|
276
|
+
};
|
|
277
|
+
const adjustCoordinate = (clickedCoordinate, handleNumber) => {
|
|
278
|
+
if (interactive$()) {
|
|
279
|
+
const sliderDomRectSize = sliderDomRectSize$(), sliderDomRectOffset = sliderDomRectOffset$();
|
|
280
|
+
let clickedPercent = vertical$() ? (sliderDomRectSize - clickedCoordinate + sliderDomRectOffset) / sliderDomRectSize : (clickedCoordinate - sliderDomRectOffset) / sliderDomRectSize;
|
|
281
|
+
clickedPercent = rtl$() ? 1 - clickedPercent : clickedPercent;
|
|
282
|
+
const derivedHandleIndex = handleNumber ?? getClosestSliderHandle(clickedPercent);
|
|
283
|
+
const newValue = clickedPercent * (max$() - min$()) + min$();
|
|
284
|
+
values$.update((dh) => {
|
|
285
|
+
dh = [...dh];
|
|
286
|
+
dh[derivedHandleIndex] = newValue;
|
|
287
|
+
return dh;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const horizontal$ = tansu.computed(() => !vertical$());
|
|
292
|
+
const containerDirective = utils_directive.createAttributesDirective(() => ({
|
|
293
|
+
attributes: {
|
|
294
|
+
"aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0),
|
|
295
|
+
class: stateProps.className$
|
|
296
|
+
},
|
|
297
|
+
classNames: {
|
|
298
|
+
"au-slider": true,
|
|
299
|
+
"au-slider-vertical": vertical$,
|
|
300
|
+
"au-slider-horizontal": horizontal$,
|
|
301
|
+
disabled: disabled$
|
|
302
|
+
}
|
|
303
|
+
}));
|
|
304
|
+
const minLabelDirective = utils_directive.createAttributesDirective(() => ({
|
|
305
|
+
classNames: {
|
|
306
|
+
"au-slider-label-vertical": vertical$,
|
|
307
|
+
"au-slider-label-vertical-min": vertical$,
|
|
308
|
+
"au-slider-label": horizontal$,
|
|
309
|
+
"au-slider-label-min": horizontal$,
|
|
310
|
+
"au-slider-rtl": rtl$,
|
|
311
|
+
invisible: tansu.computed(() => !minValueLabelDisplay$())
|
|
312
|
+
}
|
|
313
|
+
}));
|
|
314
|
+
const maxLabelDirective = utils_directive.createAttributesDirective(() => ({
|
|
315
|
+
classNames: {
|
|
316
|
+
"au-slider-label-vertical": vertical$,
|
|
317
|
+
"au-slider-label-vertical-max": vertical$,
|
|
318
|
+
"au-slider-label": horizontal$,
|
|
319
|
+
"au-slider-label-max": horizontal$,
|
|
320
|
+
"au-slider-rtl": rtl$,
|
|
321
|
+
invisible: tansu.computed(() => !maxValueLabelDisplay$())
|
|
322
|
+
}
|
|
323
|
+
}));
|
|
324
|
+
const widget = {
|
|
325
|
+
...utils_stores.stateStores({
|
|
326
|
+
min$,
|
|
327
|
+
max$,
|
|
328
|
+
stepSize$,
|
|
329
|
+
values$,
|
|
330
|
+
sortedValues$,
|
|
331
|
+
sortedHandles$,
|
|
332
|
+
minValueLabelDisplay$,
|
|
333
|
+
maxValueLabelDisplay$,
|
|
334
|
+
combinedLabelDisplay$,
|
|
335
|
+
interactive$,
|
|
336
|
+
combinedLabelPositionLeft$,
|
|
337
|
+
combinedLabelPositionTop$,
|
|
338
|
+
progressDisplayOptions$,
|
|
339
|
+
handleDisplayOptions$,
|
|
340
|
+
showValueLabels$,
|
|
341
|
+
showMinMaxLabels$,
|
|
342
|
+
rtl$,
|
|
343
|
+
...stateProps
|
|
344
|
+
}),
|
|
345
|
+
patch,
|
|
346
|
+
api: {},
|
|
347
|
+
directives: {
|
|
348
|
+
sliderDirective: utils_directive.mergeDirectives(sliderDirective, resizeDirective, containerDirective),
|
|
349
|
+
progressDisplayDirective: utils_directive.createAttributesDirective((progressContext$) => ({
|
|
350
|
+
styles: {
|
|
351
|
+
left: tansu.computed(() => percent(progressContext$().option.left)),
|
|
352
|
+
right: tansu.computed(() => percent(progressContext$().option.right)),
|
|
353
|
+
top: tansu.computed(() => percent(progressContext$().option.top)),
|
|
354
|
+
bottom: tansu.computed(() => percent(progressContext$().option.bottom)),
|
|
355
|
+
width: tansu.computed(() => percent(progressContext$().option.width)),
|
|
356
|
+
height: tansu.computed(() => percent(progressContext$().option.height))
|
|
357
|
+
},
|
|
358
|
+
classNames: {
|
|
359
|
+
"au-slider-progress": true
|
|
360
|
+
}
|
|
361
|
+
})),
|
|
362
|
+
clickableAreaDirective: utils_directive.createAttributesDirective(() => ({
|
|
363
|
+
events: {
|
|
364
|
+
click: (event) => widget.actions.click(event)
|
|
365
|
+
},
|
|
366
|
+
classNames: {
|
|
367
|
+
"au-slider-clickable-area": horizontal$,
|
|
368
|
+
"au-slider-clickable-area-vertical": vertical$
|
|
369
|
+
}
|
|
370
|
+
})),
|
|
371
|
+
handleDirective: utils_directive.createAttributesDirective((handleContext$) => ({
|
|
372
|
+
events: {
|
|
373
|
+
keydown: (event) => widget.actions.keydown(event, handleContext$().item.id),
|
|
374
|
+
mousedown: (event) => widget.actions.mouseDown(event, handleContext$().item.id),
|
|
375
|
+
touchstart: (event) => widget.actions.touchStart(event, handleContext$().item.id)
|
|
376
|
+
},
|
|
377
|
+
attributes: {
|
|
378
|
+
role: "slider",
|
|
379
|
+
"aria-valuemin": min$,
|
|
380
|
+
"aria-valuemax": max$,
|
|
381
|
+
"aria-valuenow": tansu.computed(() => handleContext$().item.value),
|
|
382
|
+
"aria-valuetext": tansu.computed(() => handleContext$().item.ariaValueText),
|
|
383
|
+
"aria-label": tansu.computed(() => handleContext$().item.ariaLabel),
|
|
384
|
+
"aria-orientation": tansu.computed(() => vertical$() ? "vertical" : void 0),
|
|
385
|
+
"aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0),
|
|
386
|
+
disabled: disabled$,
|
|
387
|
+
"aria-readonly": tansu.computed(() => readonly$() ? "true" : void 0)
|
|
388
|
+
},
|
|
389
|
+
styles: {
|
|
390
|
+
left: tansu.computed(() => percent(handleDisplayOptions$()[handleContext$().item.id].left)),
|
|
391
|
+
top: tansu.computed(() => percent(handleDisplayOptions$()[handleContext$().item.id].top))
|
|
392
|
+
},
|
|
393
|
+
classNames: {
|
|
394
|
+
"au-slider-handle": true,
|
|
395
|
+
"au-slider-handle-vertical": vertical$,
|
|
396
|
+
"au-slider-handle-horizontal": horizontal$
|
|
397
|
+
}
|
|
398
|
+
})),
|
|
399
|
+
minLabelDirective: utils_directive.mergeDirectives(minLabelDomDirective, minLabelDirective),
|
|
400
|
+
maxLabelDirective: utils_directive.mergeDirectives(maxLabelDomDirective, maxLabelDirective),
|
|
401
|
+
combinedHandleLabelDisplayDirective: utils_directive.createAttributesDirective(() => ({
|
|
402
|
+
classNames: {
|
|
403
|
+
"au-slider-label-vertical": vertical$,
|
|
404
|
+
"au-slider-label-vertical-now": vertical$,
|
|
405
|
+
"au-slider-label": horizontal$,
|
|
406
|
+
"au-slider-label-now": horizontal$
|
|
407
|
+
},
|
|
408
|
+
styles: {
|
|
409
|
+
left: tansu.computed(() => percent(combinedLabelPositionLeft$())),
|
|
410
|
+
top: tansu.computed(() => percent(combinedLabelPositionTop$()))
|
|
411
|
+
}
|
|
412
|
+
})),
|
|
413
|
+
handleLabelDisplayDirective: utils_directive.createAttributesDirective((labelDisplayContext$) => ({
|
|
414
|
+
classNames: {
|
|
415
|
+
"au-slider-label-vertical": vertical$,
|
|
416
|
+
"au-slider-label-vertical-now": vertical$,
|
|
417
|
+
"au-slider-label": horizontal$,
|
|
418
|
+
"au-slider-label-now": horizontal$
|
|
419
|
+
},
|
|
420
|
+
styles: {
|
|
421
|
+
left: tansu.computed(() => percent(handleDisplayOptions$()[labelDisplayContext$().index].left)),
|
|
422
|
+
top: tansu.computed(() => percent(handleDisplayOptions$()[labelDisplayContext$().index].top))
|
|
423
|
+
}
|
|
424
|
+
}))
|
|
425
|
+
},
|
|
426
|
+
actions: {
|
|
427
|
+
click(event) {
|
|
428
|
+
adjustCoordinate(vertical$() ? event.clientY : event.clientX);
|
|
429
|
+
},
|
|
430
|
+
keydown(event, handleIndex) {
|
|
431
|
+
const { key } = event;
|
|
432
|
+
const rtl = rtl$(), stepSize = stepSize$(), min = min$(), max = max$(), vertical = vertical$();
|
|
433
|
+
if (interactive$()) {
|
|
434
|
+
switch (key) {
|
|
435
|
+
case "ArrowDown":
|
|
436
|
+
updateValue(handleIndex, values$, stepSize, getUpdateDirection(vertical, rtl, true));
|
|
437
|
+
break;
|
|
438
|
+
case "ArrowLeft":
|
|
439
|
+
updateValue(handleIndex, values$, stepSize, getUpdateDirection(vertical, rtl, false));
|
|
440
|
+
break;
|
|
441
|
+
case "ArrowUp":
|
|
442
|
+
updateValue(handleIndex, values$, stepSize, -1 * getUpdateDirection(vertical, rtl, true));
|
|
443
|
+
break;
|
|
444
|
+
case "ArrowRight":
|
|
445
|
+
updateValue(handleIndex, values$, stepSize, -1 * getUpdateDirection(vertical, rtl, false));
|
|
446
|
+
break;
|
|
447
|
+
case "Home":
|
|
448
|
+
values$.update((value) => {
|
|
449
|
+
value = [...value];
|
|
450
|
+
value[handleIndex] = min;
|
|
451
|
+
return value;
|
|
452
|
+
});
|
|
453
|
+
break;
|
|
454
|
+
case "End":
|
|
455
|
+
values$.update((value) => {
|
|
456
|
+
value = [...value];
|
|
457
|
+
value[handleIndex] = max;
|
|
458
|
+
return value;
|
|
459
|
+
});
|
|
460
|
+
break;
|
|
461
|
+
case "PageUp":
|
|
462
|
+
break;
|
|
463
|
+
case "PageDown":
|
|
464
|
+
break;
|
|
465
|
+
default:
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
event.preventDefault();
|
|
469
|
+
event.stopPropagation();
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
mouseDown(event, handleId) {
|
|
473
|
+
event.preventDefault();
|
|
474
|
+
const currentTarget = event.target;
|
|
475
|
+
const handleDrag = (e) => {
|
|
476
|
+
e.preventDefault();
|
|
477
|
+
const newCoord = vertical$() ? e.clientY : e.clientX;
|
|
478
|
+
currentTarget.focus();
|
|
479
|
+
if (_prevCoordinate !== newCoord) {
|
|
480
|
+
_prevCoordinate = newCoord;
|
|
481
|
+
adjustCoordinate(newCoord, handleId);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
if (interactive$()) {
|
|
485
|
+
updateSliderSize$.set({});
|
|
486
|
+
currentTarget.focus();
|
|
487
|
+
document.addEventListener("mousemove", handleDrag);
|
|
488
|
+
document.addEventListener(
|
|
489
|
+
"mouseup",
|
|
490
|
+
() => {
|
|
491
|
+
document.removeEventListener("mousemove", handleDrag);
|
|
492
|
+
},
|
|
493
|
+
{ once: true }
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
touchStart(event, handleId) {
|
|
498
|
+
event.preventDefault();
|
|
499
|
+
const handleDrag = (e) => {
|
|
500
|
+
e.preventDefault();
|
|
501
|
+
const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX;
|
|
502
|
+
event.target.focus();
|
|
503
|
+
if (_prevCoordinate !== newCoord) {
|
|
504
|
+
_prevCoordinate = newCoord;
|
|
505
|
+
adjustCoordinate(newCoord, handleId);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
if (interactive$()) {
|
|
509
|
+
updateSliderSize$.set({});
|
|
510
|
+
event.target.focus();
|
|
511
|
+
document.addEventListener("touchmove", handleDrag, { passive: false });
|
|
512
|
+
document.addEventListener(
|
|
513
|
+
"touchend",
|
|
514
|
+
() => {
|
|
515
|
+
document.removeEventListener("touchmove", handleDrag);
|
|
516
|
+
document.removeEventListener("touchcancel", handleDrag);
|
|
517
|
+
},
|
|
518
|
+
{ once: true }
|
|
519
|
+
);
|
|
520
|
+
document.addEventListener(
|
|
521
|
+
"touchcancel",
|
|
522
|
+
() => {
|
|
523
|
+
document.removeEventListener("touchmove", handleDrag);
|
|
524
|
+
document.removeEventListener("touchend", handleDrag);
|
|
525
|
+
},
|
|
526
|
+
{ once: true }
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
return widget;
|
|
533
|
+
}
|
|
534
|
+
exports.createSlider = createSlider;
|
|
535
|
+
exports.getSliderDefaultConfig = getSliderDefaultConfig;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { computed } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { extendWidgetProps } from "./services/extendWidget.js";
|
|
3
|
+
import { d as directiveSubscribe, n as createAttributesDirective } from "./directive-DCYlDznf.js";
|
|
4
|
+
import { c as typeBoolean, b as typeNumberInRangeFactory } from "./writables-DoU_XYTX.js";
|
|
5
|
+
import { g as getCommonAlertDefaultConfig, a as createCommonAlert } from "./common-DRdsw5m8.js";
|
|
6
|
+
const toastDefaultConfig = {
|
|
7
|
+
autoHide: true,
|
|
8
|
+
delay: 5e3
|
|
9
|
+
};
|
|
10
|
+
const toastConfigValidator = {
|
|
11
|
+
autoHide: typeBoolean,
|
|
12
|
+
delay: typeNumberInRangeFactory(0, Infinity, { strict: true })
|
|
13
|
+
};
|
|
14
|
+
function getToastDefaultConfig() {
|
|
15
|
+
return { ...getCommonAlertDefaultConfig(), ...toastDefaultConfig };
|
|
16
|
+
}
|
|
17
|
+
function createToast(config) {
|
|
18
|
+
let _timeout;
|
|
19
|
+
const extendedAlert = extendWidgetProps(
|
|
20
|
+
createCommonAlert,
|
|
21
|
+
toastDefaultConfig,
|
|
22
|
+
toastConfigValidator
|
|
23
|
+
)(config);
|
|
24
|
+
const time$ = computed(() => {
|
|
25
|
+
clearTimeout(_timeout);
|
|
26
|
+
if (extendedAlert.stores.autoHide$()) {
|
|
27
|
+
_timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const bodyDirective = createAttributesDirective(() => ({
|
|
31
|
+
attributes: {
|
|
32
|
+
role: "alert",
|
|
33
|
+
"aria-atomic": "true",
|
|
34
|
+
class: computed(() => extendedAlert.stores.className$())
|
|
35
|
+
},
|
|
36
|
+
classNames: {
|
|
37
|
+
"au-toast": true,
|
|
38
|
+
toast: true
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
const closeButtonDirective = createAttributesDirective(() => ({
|
|
42
|
+
attributes: {
|
|
43
|
+
type: "button",
|
|
44
|
+
"aria-label": computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
|
|
45
|
+
},
|
|
46
|
+
events: {
|
|
47
|
+
click: extendedAlert.api.close
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
...extendedAlert,
|
|
52
|
+
directives: {
|
|
53
|
+
...extendedAlert.directives,
|
|
54
|
+
autoHideDirective: directiveSubscribe(time$),
|
|
55
|
+
bodyDirective,
|
|
56
|
+
closeButtonDirective
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
createToast as c,
|
|
62
|
+
getToastDefaultConfig as g
|
|
63
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const services_extendWidget = require("./services/extendWidget.cjs");
|
|
4
|
+
const utils_directive = require("./directive-BTSEYLF3.cjs");
|
|
5
|
+
const utils_writables = require("./writables-D46sFgGK.cjs");
|
|
6
|
+
const common = require("./common-nJRMXbwj.cjs");
|
|
7
|
+
const toastDefaultConfig = {
|
|
8
|
+
autoHide: true,
|
|
9
|
+
delay: 5e3
|
|
10
|
+
};
|
|
11
|
+
const toastConfigValidator = {
|
|
12
|
+
autoHide: utils_writables.typeBoolean,
|
|
13
|
+
delay: utils_writables.typeNumberInRangeFactory(0, Infinity, { strict: true })
|
|
14
|
+
};
|
|
15
|
+
function getToastDefaultConfig() {
|
|
16
|
+
return { ...common.getCommonAlertDefaultConfig(), ...toastDefaultConfig };
|
|
17
|
+
}
|
|
18
|
+
function createToast(config) {
|
|
19
|
+
let _timeout;
|
|
20
|
+
const extendedAlert = services_extendWidget.extendWidgetProps(
|
|
21
|
+
common.createCommonAlert,
|
|
22
|
+
toastDefaultConfig,
|
|
23
|
+
toastConfigValidator
|
|
24
|
+
)(config);
|
|
25
|
+
const time$ = tansu.computed(() => {
|
|
26
|
+
clearTimeout(_timeout);
|
|
27
|
+
if (extendedAlert.stores.autoHide$()) {
|
|
28
|
+
_timeout = setTimeout(() => extendedAlert.api.close(), extendedAlert.stores.delay$());
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const bodyDirective = utils_directive.createAttributesDirective(() => ({
|
|
32
|
+
attributes: {
|
|
33
|
+
role: "alert",
|
|
34
|
+
"aria-atomic": "true",
|
|
35
|
+
class: tansu.computed(() => extendedAlert.stores.className$())
|
|
36
|
+
},
|
|
37
|
+
classNames: {
|
|
38
|
+
"au-toast": true,
|
|
39
|
+
toast: true
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
|
|
43
|
+
attributes: {
|
|
44
|
+
type: "button",
|
|
45
|
+
"aria-label": tansu.computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
|
|
46
|
+
},
|
|
47
|
+
events: {
|
|
48
|
+
click: extendedAlert.api.close
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
return {
|
|
52
|
+
...extendedAlert,
|
|
53
|
+
directives: {
|
|
54
|
+
...extendedAlert.directives,
|
|
55
|
+
autoHideDirective: utils_directive.directiveSubscribe(time$),
|
|
56
|
+
bodyDirective,
|
|
57
|
+
closeButtonDirective
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.createToast = createToast;
|
|
62
|
+
exports.getToastDefaultConfig = getToastDefaultConfig;
|
package/types.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const toSlotContextWidget = (w) => ({
|
|
4
|
+
actions: w.actions,
|
|
5
|
+
api: w.api,
|
|
6
|
+
directives: w.directives,
|
|
7
|
+
state$: w.state$,
|
|
8
|
+
stores: w.stores
|
|
9
|
+
});
|
|
10
|
+
const INVALID_VALUE = Symbol();
|
|
11
|
+
exports.INVALID_VALUE = INVALID_VALUE;
|
|
12
|
+
exports.toSlotContextWidget = toSlotContextWidget;
|