@agnos-ui/core 0.2.0 → 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 +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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { i as clamp, a as typeNumber, e as typeString, f as typeFunction } from "./writables-DoU_XYTX.js";
|
|
2
|
+
import { writablesForProps, stateStores } from "./utils/stores.js";
|
|
3
|
+
import { computed } from "@amadeus-it-group/tansu";
|
|
4
|
+
import { n as createAttributesDirective } from "./directive-DCYlDznf.js";
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
min: 0,
|
|
7
|
+
max: 100,
|
|
8
|
+
value: 0,
|
|
9
|
+
ariaLabel: "Progressbar",
|
|
10
|
+
className: "",
|
|
11
|
+
ariaValueTextFn: () => void 0
|
|
12
|
+
};
|
|
13
|
+
function getProgressbarDefaultConfig() {
|
|
14
|
+
return { ...defaultConfig };
|
|
15
|
+
}
|
|
16
|
+
const configValidator = {
|
|
17
|
+
min: typeNumber,
|
|
18
|
+
max: typeNumber,
|
|
19
|
+
value: typeNumber,
|
|
20
|
+
ariaLabel: typeString,
|
|
21
|
+
className: typeString,
|
|
22
|
+
ariaValueTextFn: typeFunction
|
|
23
|
+
};
|
|
24
|
+
function createProgressbar(config) {
|
|
25
|
+
const [
|
|
26
|
+
{
|
|
27
|
+
// dirty inputs that need adjustment:
|
|
28
|
+
max$: _dirtyMaximum$,
|
|
29
|
+
value$: _dirtyValue$,
|
|
30
|
+
// clean inputs
|
|
31
|
+
min$,
|
|
32
|
+
ariaValueTextFn$,
|
|
33
|
+
ariaLabel$,
|
|
34
|
+
...stateProps
|
|
35
|
+
},
|
|
36
|
+
patch
|
|
37
|
+
] = writablesForProps(defaultConfig, config, configValidator);
|
|
38
|
+
const max$ = computed(() => Math.max(min$(), _dirtyMaximum$()));
|
|
39
|
+
const value$ = computed(() => clamp(_dirtyValue$(), max$(), min$()));
|
|
40
|
+
const percentage$ = computed(() => {
|
|
41
|
+
const max = max$();
|
|
42
|
+
const min = min$();
|
|
43
|
+
if (max > min) {
|
|
44
|
+
return clamp((value$() - min) * 100 / (max - min), 100, 0);
|
|
45
|
+
} else {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const started$ = computed(() => value$() > min$());
|
|
50
|
+
const finished$ = computed(() => value$() === max$());
|
|
51
|
+
const ariaValueText$ = computed(() => ariaValueTextFn$()(value$(), min$(), max$()));
|
|
52
|
+
return {
|
|
53
|
+
...stateStores({
|
|
54
|
+
min$,
|
|
55
|
+
max$,
|
|
56
|
+
value$,
|
|
57
|
+
percentage$,
|
|
58
|
+
started$,
|
|
59
|
+
finished$,
|
|
60
|
+
ariaValueText$,
|
|
61
|
+
ariaLabel$,
|
|
62
|
+
...stateProps
|
|
63
|
+
}),
|
|
64
|
+
patch,
|
|
65
|
+
api: {},
|
|
66
|
+
directives: {
|
|
67
|
+
ariaDirective: createAttributesDirective(() => ({
|
|
68
|
+
attributes: {
|
|
69
|
+
role: "progressbar",
|
|
70
|
+
"aria-label": ariaLabel$,
|
|
71
|
+
"aria-valuenow": value$,
|
|
72
|
+
"aria-valuemin": min$,
|
|
73
|
+
"aria-valuemax": max$,
|
|
74
|
+
"aria-valuetext": ariaValueText$
|
|
75
|
+
}
|
|
76
|
+
}))
|
|
77
|
+
},
|
|
78
|
+
actions: {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
createProgressbar as c,
|
|
83
|
+
getProgressbarDefaultConfig as g
|
|
84
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const func = require("./func-Qd3cD9a3.cjs");
|
|
4
|
+
const promisePending = { status: "pending" };
|
|
5
|
+
const isThenable = (value) => {
|
|
6
|
+
const type = typeof value;
|
|
7
|
+
return type === "object" && value !== null || type === "function" ? typeof value.then === "function" : false;
|
|
8
|
+
};
|
|
9
|
+
const createPromiseStateStore = (promise) => {
|
|
10
|
+
const store = tansu.writable(promisePending);
|
|
11
|
+
Promise.resolve(promise).then(
|
|
12
|
+
(value) => store.set({ status: "fulfilled", value }),
|
|
13
|
+
(reason) => store.set({ status: "rejected", reason })
|
|
14
|
+
);
|
|
15
|
+
return tansu.asReadable(store);
|
|
16
|
+
};
|
|
17
|
+
const promiseWeakMap = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
const promiseStateStore = (value) => {
|
|
19
|
+
if (!isThenable(value)) {
|
|
20
|
+
return tansu.readable({ status: "fulfilled", value });
|
|
21
|
+
}
|
|
22
|
+
let response = promiseWeakMap.get(value);
|
|
23
|
+
if (!response) {
|
|
24
|
+
response = createPromiseStateStore(value);
|
|
25
|
+
promiseWeakMap.set(value, response);
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
};
|
|
29
|
+
const promiseStateStoreEqual = (a, b) => Object.is(a, b) || a.status === b.status && (a.status !== "fulfilled" || tansu.equal(a.value, b.value)) && (a.status !== "rejected" || tansu.equal(a.reason, b.reason));
|
|
30
|
+
const promiseStoreToPromiseStateStore = (promiseStore$) => tansu.computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual });
|
|
31
|
+
const promiseStateStoreToValueStore = (store$, initialValue, equal2) => tansu.derived(
|
|
32
|
+
store$,
|
|
33
|
+
{
|
|
34
|
+
derive: (state, set) => {
|
|
35
|
+
if (state.status === "fulfilled") {
|
|
36
|
+
set(state.value);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
equal: equal2
|
|
40
|
+
},
|
|
41
|
+
initialValue
|
|
42
|
+
);
|
|
43
|
+
const promiseStoreToValueStore = (promiseStore$, initialValue, equal2) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal2);
|
|
44
|
+
const truthyValue = (value) => !!value;
|
|
45
|
+
const promiseFromStore = (store, condition = truthyValue) => {
|
|
46
|
+
let resolve;
|
|
47
|
+
const promise = new Promise((r) => resolve = r);
|
|
48
|
+
let unsubscribe = () => {
|
|
49
|
+
storeUnsubscribe();
|
|
50
|
+
unsubscribe = func.noop;
|
|
51
|
+
};
|
|
52
|
+
let storeUnsubscribe = func.noop;
|
|
53
|
+
storeUnsubscribe = store.subscribe((value) => {
|
|
54
|
+
if (condition(value)) {
|
|
55
|
+
resolve(value);
|
|
56
|
+
unsubscribe();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (unsubscribe === func.noop) {
|
|
60
|
+
storeUnsubscribe();
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
promise,
|
|
64
|
+
unsubscribe() {
|
|
65
|
+
unsubscribe();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const promiseFromEvent = (element, event) => {
|
|
70
|
+
let resolve;
|
|
71
|
+
const promise = new Promise((r) => resolve = r);
|
|
72
|
+
let unsubscribe = () => {
|
|
73
|
+
element.removeEventListener(event, eventListener);
|
|
74
|
+
unsubscribe = func.noop;
|
|
75
|
+
};
|
|
76
|
+
const eventListener = (event2) => {
|
|
77
|
+
if (event2.target === element) {
|
|
78
|
+
resolve(event2);
|
|
79
|
+
unsubscribe();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
element.addEventListener(event, eventListener);
|
|
83
|
+
return {
|
|
84
|
+
promise,
|
|
85
|
+
unsubscribe() {
|
|
86
|
+
unsubscribe();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const promiseFromTimeout = (delay) => {
|
|
91
|
+
let timeout;
|
|
92
|
+
return {
|
|
93
|
+
promise: new Promise((r) => {
|
|
94
|
+
timeout = setTimeout(() => {
|
|
95
|
+
timeout = void 0;
|
|
96
|
+
r();
|
|
97
|
+
}, delay);
|
|
98
|
+
}),
|
|
99
|
+
unsubscribe() {
|
|
100
|
+
if (timeout) {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
timeout = void 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const promiseWithResolve = () => {
|
|
108
|
+
let resolve;
|
|
109
|
+
const promise = new Promise((r) => {
|
|
110
|
+
resolve = r;
|
|
111
|
+
});
|
|
112
|
+
return { promise, resolve };
|
|
113
|
+
};
|
|
114
|
+
exports.promiseFromEvent = promiseFromEvent;
|
|
115
|
+
exports.promiseFromStore = promiseFromStore;
|
|
116
|
+
exports.promiseFromTimeout = promiseFromTimeout;
|
|
117
|
+
exports.promiseStoreToValueStore = promiseStoreToValueStore;
|
|
118
|
+
exports.promiseWithResolve = promiseWithResolve;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { computed, derived, readable, equal, writable, asReadable } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { n as noop } from "./func-DR0n-ShK.js";
|
|
3
|
+
const promisePending = { status: "pending" };
|
|
4
|
+
const isThenable = (value) => {
|
|
5
|
+
const type = typeof value;
|
|
6
|
+
return type === "object" && value !== null || type === "function" ? typeof value.then === "function" : false;
|
|
7
|
+
};
|
|
8
|
+
const createPromiseStateStore = (promise) => {
|
|
9
|
+
const store = writable(promisePending);
|
|
10
|
+
Promise.resolve(promise).then(
|
|
11
|
+
(value) => store.set({ status: "fulfilled", value }),
|
|
12
|
+
(reason) => store.set({ status: "rejected", reason })
|
|
13
|
+
);
|
|
14
|
+
return asReadable(store);
|
|
15
|
+
};
|
|
16
|
+
const promiseWeakMap = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const promiseStateStore = (value) => {
|
|
18
|
+
if (!isThenable(value)) {
|
|
19
|
+
return readable({ status: "fulfilled", value });
|
|
20
|
+
}
|
|
21
|
+
let response = promiseWeakMap.get(value);
|
|
22
|
+
if (!response) {
|
|
23
|
+
response = createPromiseStateStore(value);
|
|
24
|
+
promiseWeakMap.set(value, response);
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
};
|
|
28
|
+
const promiseStateStoreEqual = (a, b) => Object.is(a, b) || a.status === b.status && (a.status !== "fulfilled" || equal(a.value, b.value)) && (a.status !== "rejected" || equal(a.reason, b.reason));
|
|
29
|
+
const promiseStoreToPromiseStateStore = (promiseStore$) => computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual });
|
|
30
|
+
const promiseStateStoreToValueStore = (store$, initialValue, equal2) => derived(
|
|
31
|
+
store$,
|
|
32
|
+
{
|
|
33
|
+
derive: (state, set) => {
|
|
34
|
+
if (state.status === "fulfilled") {
|
|
35
|
+
set(state.value);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
equal: equal2
|
|
39
|
+
},
|
|
40
|
+
initialValue
|
|
41
|
+
);
|
|
42
|
+
const promiseStoreToValueStore = (promiseStore$, initialValue, equal2) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal2);
|
|
43
|
+
const truthyValue = (value) => !!value;
|
|
44
|
+
const promiseFromStore = (store, condition = truthyValue) => {
|
|
45
|
+
let resolve;
|
|
46
|
+
const promise = new Promise((r) => resolve = r);
|
|
47
|
+
let unsubscribe = () => {
|
|
48
|
+
storeUnsubscribe();
|
|
49
|
+
unsubscribe = noop;
|
|
50
|
+
};
|
|
51
|
+
let storeUnsubscribe = noop;
|
|
52
|
+
storeUnsubscribe = store.subscribe((value) => {
|
|
53
|
+
if (condition(value)) {
|
|
54
|
+
resolve(value);
|
|
55
|
+
unsubscribe();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (unsubscribe === noop) {
|
|
59
|
+
storeUnsubscribe();
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
promise,
|
|
63
|
+
unsubscribe() {
|
|
64
|
+
unsubscribe();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const promiseFromEvent = (element, event) => {
|
|
69
|
+
let resolve;
|
|
70
|
+
const promise = new Promise((r) => resolve = r);
|
|
71
|
+
let unsubscribe = () => {
|
|
72
|
+
element.removeEventListener(event, eventListener);
|
|
73
|
+
unsubscribe = noop;
|
|
74
|
+
};
|
|
75
|
+
const eventListener = (event2) => {
|
|
76
|
+
if (event2.target === element) {
|
|
77
|
+
resolve(event2);
|
|
78
|
+
unsubscribe();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
element.addEventListener(event, eventListener);
|
|
82
|
+
return {
|
|
83
|
+
promise,
|
|
84
|
+
unsubscribe() {
|
|
85
|
+
unsubscribe();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const promiseFromTimeout = (delay) => {
|
|
90
|
+
let timeout;
|
|
91
|
+
return {
|
|
92
|
+
promise: new Promise((r) => {
|
|
93
|
+
timeout = setTimeout(() => {
|
|
94
|
+
timeout = void 0;
|
|
95
|
+
r();
|
|
96
|
+
}, delay);
|
|
97
|
+
}),
|
|
98
|
+
unsubscribe() {
|
|
99
|
+
if (timeout) {
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
timeout = void 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const promiseWithResolve = () => {
|
|
107
|
+
let resolve;
|
|
108
|
+
const promise = new Promise((r) => {
|
|
109
|
+
resolve = r;
|
|
110
|
+
});
|
|
111
|
+
return { promise, resolve };
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
promiseFromEvent as a,
|
|
115
|
+
promiseFromTimeout as b,
|
|
116
|
+
promiseWithResolve as c,
|
|
117
|
+
promiseFromStore as d,
|
|
118
|
+
promiseStoreToValueStore as p
|
|
119
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { computed, writable } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { INVALID_VALUE } from "./types.js";
|
|
3
|
+
import { n as createAttributesDirective } from "./directive-DCYlDznf.js";
|
|
4
|
+
import { i as clamp, a as typeNumber, j as isNumber, c as typeBoolean, f as typeFunction, e as typeString } from "./writables-DoU_XYTX.js";
|
|
5
|
+
import { n as noop } from "./func-DR0n-ShK.js";
|
|
6
|
+
import { writablesForProps, bindableProp, stateStores } from "./utils/stores.js";
|
|
7
|
+
const defaultConfig = {
|
|
8
|
+
rating: 0,
|
|
9
|
+
tabindex: 0,
|
|
10
|
+
maxRating: 10,
|
|
11
|
+
disabled: false,
|
|
12
|
+
readonly: false,
|
|
13
|
+
resettable: true,
|
|
14
|
+
ariaValueTextFn: (rating, maxRating) => `${rating} out of ${maxRating}`,
|
|
15
|
+
onHover: noop,
|
|
16
|
+
onLeave: noop,
|
|
17
|
+
onRatingChange: noop,
|
|
18
|
+
className: "",
|
|
19
|
+
ariaLabel: "Rating",
|
|
20
|
+
ariaLabelledBy: ""
|
|
21
|
+
};
|
|
22
|
+
function getRatingDefaultConfig() {
|
|
23
|
+
return { ...defaultConfig };
|
|
24
|
+
}
|
|
25
|
+
const configValidator = {
|
|
26
|
+
rating: typeNumber,
|
|
27
|
+
tabindex: typeNumber,
|
|
28
|
+
maxRating: { normalizeValue: (value) => isNumber(value) ? Math.max(0, value) : INVALID_VALUE },
|
|
29
|
+
disabled: typeBoolean,
|
|
30
|
+
readonly: typeBoolean,
|
|
31
|
+
resettable: typeBoolean,
|
|
32
|
+
ariaValueTextFn: typeFunction,
|
|
33
|
+
onHover: typeFunction,
|
|
34
|
+
onLeave: typeFunction,
|
|
35
|
+
onRatingChange: typeFunction,
|
|
36
|
+
className: typeString,
|
|
37
|
+
ariaLabel: typeString,
|
|
38
|
+
ariaLabelledBy: typeString
|
|
39
|
+
};
|
|
40
|
+
function createRating(config) {
|
|
41
|
+
const [
|
|
42
|
+
{
|
|
43
|
+
// dirty inputs that need adjustment:
|
|
44
|
+
rating$: _dirtyRating$,
|
|
45
|
+
tabindex$: _dirtyTabindex$,
|
|
46
|
+
ariaValueTextFn$,
|
|
47
|
+
onHover$,
|
|
48
|
+
onLeave$,
|
|
49
|
+
onRatingChange$,
|
|
50
|
+
...stateProps
|
|
51
|
+
},
|
|
52
|
+
patch
|
|
53
|
+
] = writablesForProps(defaultConfig, config, configValidator);
|
|
54
|
+
const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
|
|
55
|
+
const tabindex$ = computed(() => disabled$() ? -1 : _dirtyTabindex$());
|
|
56
|
+
const rating$ = bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => clamp(dirtyRating, maxRating$()));
|
|
57
|
+
const _hoveredRating$ = writable(0);
|
|
58
|
+
const interactive$ = computed(() => !disabled$() && !readonly$());
|
|
59
|
+
const visibleRating$ = computed(() => {
|
|
60
|
+
const hoveredRating = _hoveredRating$();
|
|
61
|
+
return hoveredRating !== 0 ? hoveredRating : rating$();
|
|
62
|
+
});
|
|
63
|
+
const ariaValueText$ = computed(() => ariaValueTextFn$()(visibleRating$(), maxRating$()));
|
|
64
|
+
const stars$ = computed(() => {
|
|
65
|
+
const visibleRating = visibleRating$();
|
|
66
|
+
return Array.from({ length: maxRating$() }, (_v, i) => ({
|
|
67
|
+
fill: Math.round(Math.max(Math.min(visibleRating - i, 1), 0) * 100),
|
|
68
|
+
index: i
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
const widget = {
|
|
72
|
+
...stateStores({
|
|
73
|
+
ariaValueText$,
|
|
74
|
+
interactive$,
|
|
75
|
+
rating$,
|
|
76
|
+
stars$,
|
|
77
|
+
tabindex$,
|
|
78
|
+
visibleRating$,
|
|
79
|
+
...stateProps
|
|
80
|
+
}),
|
|
81
|
+
patch,
|
|
82
|
+
actions: {
|
|
83
|
+
click: (index) => {
|
|
84
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
85
|
+
rating$.update((rating) => rating === index && resettable$() ? 0 : index);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
hover: (index) => {
|
|
89
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
90
|
+
_hoveredRating$.set(index);
|
|
91
|
+
onHover$()(index);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
leave: () => {
|
|
95
|
+
if (interactive$()) {
|
|
96
|
+
onLeave$()(_hoveredRating$());
|
|
97
|
+
_hoveredRating$.set(0);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
handleKey(event) {
|
|
101
|
+
if (interactive$()) {
|
|
102
|
+
const { key } = event;
|
|
103
|
+
switch (key) {
|
|
104
|
+
case "ArrowLeft":
|
|
105
|
+
case "ArrowDown":
|
|
106
|
+
rating$.update((rating) => rating - 1);
|
|
107
|
+
break;
|
|
108
|
+
case "ArrowRight":
|
|
109
|
+
case "ArrowUp":
|
|
110
|
+
rating$.update((rating) => rating + 1);
|
|
111
|
+
break;
|
|
112
|
+
case "Home":
|
|
113
|
+
case "PageDown":
|
|
114
|
+
rating$.set(0);
|
|
115
|
+
break;
|
|
116
|
+
case "End":
|
|
117
|
+
case "PageUp":
|
|
118
|
+
rating$.set(maxRating$());
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
directives: {
|
|
129
|
+
containerDirective: createAttributesDirective(() => ({
|
|
130
|
+
events: {
|
|
131
|
+
keydown: (e) => widget.actions.handleKey(e),
|
|
132
|
+
mouseleave: () => widget.actions.leave()
|
|
133
|
+
},
|
|
134
|
+
attributes: {
|
|
135
|
+
role: "slider",
|
|
136
|
+
class: className$,
|
|
137
|
+
"aria-valuemin": 0,
|
|
138
|
+
tabindex: tabindex$,
|
|
139
|
+
"aria-valuemax": maxRating$,
|
|
140
|
+
"aria-valuenow": visibleRating$,
|
|
141
|
+
"aria-valuetext": ariaValueText$,
|
|
142
|
+
"aria-readonly": computed(() => readonly$() ? "true" : void 0),
|
|
143
|
+
"aria-disabled": computed(() => disabled$() ? "true" : void 0),
|
|
144
|
+
"aria-label": ariaLabel$,
|
|
145
|
+
"aria-labelledby": computed(() => ariaLabelledBy$() || void 0)
|
|
146
|
+
},
|
|
147
|
+
classNames: {
|
|
148
|
+
"au-rating": true
|
|
149
|
+
}
|
|
150
|
+
})),
|
|
151
|
+
starDirective: createAttributesDirective((starContext$) => {
|
|
152
|
+
return {
|
|
153
|
+
events: {
|
|
154
|
+
mouseenter: () => widget.actions.hover(starContext$().index + 1),
|
|
155
|
+
click: () => widget.actions.click(starContext$().index + 1)
|
|
156
|
+
},
|
|
157
|
+
styles: {
|
|
158
|
+
cursor: computed(() => interactive$() ? "pointer" : "default")
|
|
159
|
+
},
|
|
160
|
+
classNames: {
|
|
161
|
+
"au-rating-star": true
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
api: {}
|
|
167
|
+
};
|
|
168
|
+
return widget;
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
createRating as c,
|
|
172
|
+
getRatingDefaultConfig as g
|
|
173
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const types = require("./types.cjs");
|
|
4
|
+
const utils_directive = require("./directive-BTSEYLF3.cjs");
|
|
5
|
+
const utils_writables = require("./writables-D46sFgGK.cjs");
|
|
6
|
+
const func = require("./func-Qd3cD9a3.cjs");
|
|
7
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
rating: 0,
|
|
10
|
+
tabindex: 0,
|
|
11
|
+
maxRating: 10,
|
|
12
|
+
disabled: false,
|
|
13
|
+
readonly: false,
|
|
14
|
+
resettable: true,
|
|
15
|
+
ariaValueTextFn: (rating, maxRating) => `${rating} out of ${maxRating}`,
|
|
16
|
+
onHover: func.noop,
|
|
17
|
+
onLeave: func.noop,
|
|
18
|
+
onRatingChange: func.noop,
|
|
19
|
+
className: "",
|
|
20
|
+
ariaLabel: "Rating",
|
|
21
|
+
ariaLabelledBy: ""
|
|
22
|
+
};
|
|
23
|
+
function getRatingDefaultConfig() {
|
|
24
|
+
return { ...defaultConfig };
|
|
25
|
+
}
|
|
26
|
+
const configValidator = {
|
|
27
|
+
rating: utils_writables.typeNumber,
|
|
28
|
+
tabindex: utils_writables.typeNumber,
|
|
29
|
+
maxRating: { normalizeValue: (value) => utils_writables.isNumber(value) ? Math.max(0, value) : types.INVALID_VALUE },
|
|
30
|
+
disabled: utils_writables.typeBoolean,
|
|
31
|
+
readonly: utils_writables.typeBoolean,
|
|
32
|
+
resettable: utils_writables.typeBoolean,
|
|
33
|
+
ariaValueTextFn: utils_writables.typeFunction,
|
|
34
|
+
onHover: utils_writables.typeFunction,
|
|
35
|
+
onLeave: utils_writables.typeFunction,
|
|
36
|
+
onRatingChange: utils_writables.typeFunction,
|
|
37
|
+
className: utils_writables.typeString,
|
|
38
|
+
ariaLabel: utils_writables.typeString,
|
|
39
|
+
ariaLabelledBy: utils_writables.typeString
|
|
40
|
+
};
|
|
41
|
+
function createRating(config) {
|
|
42
|
+
const [
|
|
43
|
+
{
|
|
44
|
+
// dirty inputs that need adjustment:
|
|
45
|
+
rating$: _dirtyRating$,
|
|
46
|
+
tabindex$: _dirtyTabindex$,
|
|
47
|
+
ariaValueTextFn$,
|
|
48
|
+
onHover$,
|
|
49
|
+
onLeave$,
|
|
50
|
+
onRatingChange$,
|
|
51
|
+
...stateProps
|
|
52
|
+
},
|
|
53
|
+
patch
|
|
54
|
+
] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
|
|
55
|
+
const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
|
|
56
|
+
const tabindex$ = tansu.computed(() => disabled$() ? -1 : _dirtyTabindex$());
|
|
57
|
+
const rating$ = utils_stores.bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => utils_writables.clamp(dirtyRating, maxRating$()));
|
|
58
|
+
const _hoveredRating$ = tansu.writable(0);
|
|
59
|
+
const interactive$ = tansu.computed(() => !disabled$() && !readonly$());
|
|
60
|
+
const visibleRating$ = tansu.computed(() => {
|
|
61
|
+
const hoveredRating = _hoveredRating$();
|
|
62
|
+
return hoveredRating !== 0 ? hoveredRating : rating$();
|
|
63
|
+
});
|
|
64
|
+
const ariaValueText$ = tansu.computed(() => ariaValueTextFn$()(visibleRating$(), maxRating$()));
|
|
65
|
+
const stars$ = tansu.computed(() => {
|
|
66
|
+
const visibleRating = visibleRating$();
|
|
67
|
+
return Array.from({ length: maxRating$() }, (_v, i) => ({
|
|
68
|
+
fill: Math.round(Math.max(Math.min(visibleRating - i, 1), 0) * 100),
|
|
69
|
+
index: i
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
const widget = {
|
|
73
|
+
...utils_stores.stateStores({
|
|
74
|
+
ariaValueText$,
|
|
75
|
+
interactive$,
|
|
76
|
+
rating$,
|
|
77
|
+
stars$,
|
|
78
|
+
tabindex$,
|
|
79
|
+
visibleRating$,
|
|
80
|
+
...stateProps
|
|
81
|
+
}),
|
|
82
|
+
patch,
|
|
83
|
+
actions: {
|
|
84
|
+
click: (index) => {
|
|
85
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
86
|
+
rating$.update((rating) => rating === index && resettable$() ? 0 : index);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
hover: (index) => {
|
|
90
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
91
|
+
_hoveredRating$.set(index);
|
|
92
|
+
onHover$()(index);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
leave: () => {
|
|
96
|
+
if (interactive$()) {
|
|
97
|
+
onLeave$()(_hoveredRating$());
|
|
98
|
+
_hoveredRating$.set(0);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
handleKey(event) {
|
|
102
|
+
if (interactive$()) {
|
|
103
|
+
const { key } = event;
|
|
104
|
+
switch (key) {
|
|
105
|
+
case "ArrowLeft":
|
|
106
|
+
case "ArrowDown":
|
|
107
|
+
rating$.update((rating) => rating - 1);
|
|
108
|
+
break;
|
|
109
|
+
case "ArrowRight":
|
|
110
|
+
case "ArrowUp":
|
|
111
|
+
rating$.update((rating) => rating + 1);
|
|
112
|
+
break;
|
|
113
|
+
case "Home":
|
|
114
|
+
case "PageDown":
|
|
115
|
+
rating$.set(0);
|
|
116
|
+
break;
|
|
117
|
+
case "End":
|
|
118
|
+
case "PageUp":
|
|
119
|
+
rating$.set(maxRating$());
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
directives: {
|
|
130
|
+
containerDirective: utils_directive.createAttributesDirective(() => ({
|
|
131
|
+
events: {
|
|
132
|
+
keydown: (e) => widget.actions.handleKey(e),
|
|
133
|
+
mouseleave: () => widget.actions.leave()
|
|
134
|
+
},
|
|
135
|
+
attributes: {
|
|
136
|
+
role: "slider",
|
|
137
|
+
class: className$,
|
|
138
|
+
"aria-valuemin": 0,
|
|
139
|
+
tabindex: tabindex$,
|
|
140
|
+
"aria-valuemax": maxRating$,
|
|
141
|
+
"aria-valuenow": visibleRating$,
|
|
142
|
+
"aria-valuetext": ariaValueText$,
|
|
143
|
+
"aria-readonly": tansu.computed(() => readonly$() ? "true" : void 0),
|
|
144
|
+
"aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0),
|
|
145
|
+
"aria-label": ariaLabel$,
|
|
146
|
+
"aria-labelledby": tansu.computed(() => ariaLabelledBy$() || void 0)
|
|
147
|
+
},
|
|
148
|
+
classNames: {
|
|
149
|
+
"au-rating": true
|
|
150
|
+
}
|
|
151
|
+
})),
|
|
152
|
+
starDirective: utils_directive.createAttributesDirective((starContext$) => {
|
|
153
|
+
return {
|
|
154
|
+
events: {
|
|
155
|
+
mouseenter: () => widget.actions.hover(starContext$().index + 1),
|
|
156
|
+
click: () => widget.actions.click(starContext$().index + 1)
|
|
157
|
+
},
|
|
158
|
+
styles: {
|
|
159
|
+
cursor: tansu.computed(() => interactive$() ? "pointer" : "default")
|
|
160
|
+
},
|
|
161
|
+
classNames: {
|
|
162
|
+
"au-rating-star": true
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
})
|
|
166
|
+
},
|
|
167
|
+
api: {}
|
|
168
|
+
};
|
|
169
|
+
return widget;
|
|
170
|
+
}
|
|
171
|
+
exports.createRating = createRating;
|
|
172
|
+
exports.getRatingDefaultConfig = getRatingDefaultConfig;
|