@agnos-ui/core 0.4.3 → 0.5.0-next.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 +2 -2
- package/{accordion-BnaSamoQ.js → accordion-BGv150k9.js} +10 -13
- package/{accordion-DmPT0O0j.cjs → accordion-Lp-LEbZ2.cjs} +10 -13
- package/{alert-CEFbEgvG.cjs → alert-Bq101evB.cjs} +1 -1
- package/{alert-DdGuK__c.js → alert-DJ2l7bcA.js} +1 -1
- package/{common-CO5b5G_J.js → common-Banw3FYN.js} +15 -14
- package/{common-nxv_hKNE.cjs → common-DvPjK7SS.cjs} +15 -14
- package/components/accordion/accordion.d.ts +35 -8
- package/components/accordion/index.cjs +1 -1
- package/components/accordion/index.js +1 -1
- package/components/alert/alert.d.ts +16 -1
- package/components/alert/common.d.ts +19 -1
- package/components/alert/index.cjs +1 -1
- package/components/alert/index.js +1 -1
- package/components/commonProps.d.ts +3 -0
- package/components/modal/index.cjs +1 -1
- package/components/modal/index.js +1 -1
- package/components/modal/modal.d.ts +3 -135
- package/components/pagination/index.cjs +1 -1
- package/components/pagination/index.js +1 -1
- package/components/pagination/pagination.d.ts +30 -217
- package/components/progressbar/index.cjs +1 -1
- package/components/progressbar/index.js +1 -1
- package/components/progressbar/progressbar.d.ts +13 -3
- package/components/rating/index.cjs +1 -1
- package/components/rating/index.js +1 -1
- package/components/rating/rating.d.ts +26 -115
- package/components/select/index.cjs +1 -1
- package/components/select/index.js +1 -1
- package/components/select/select.d.ts +21 -148
- package/components/slider/index.cjs +1 -1
- package/components/slider/index.js +1 -1
- package/components/slider/slider.d.ts +31 -126
- package/components/toast/index.cjs +1 -1
- package/components/toast/index.js +1 -1
- package/components/toast/toast.d.ts +16 -1
- package/config.d.ts +17 -1
- package/{directive-3-8yr-ZK.js → directive-CKEccryv.js} +11 -5
- package/{directive-j-xRk-h3.cjs → directive-DdlwGFtf.cjs} +11 -5
- package/index.cjs +13 -13
- package/index.js +15 -15
- package/{modal-D4d8sy85.cjs → modal-DDHcrykD.cjs} +10 -21
- package/{modal-CeTI4jxI.js → modal-DP-4I7vf.js} +11 -22
- package/package.json +6 -5
- package/{pagination-B9WFv70F.cjs → pagination-CBysiPUs.cjs} +23 -35
- package/{pagination-BpPHKQsH.js → pagination-DwDRot6q.js} +23 -35
- package/{progressbar-BybOg5FE.js → progressbar-CGmNq0cS.js} +3 -4
- package/{progressbar-DXCMeJvL.cjs → progressbar-DghzCJ6_.cjs} +3 -4
- package/{rating-D6Tv_4Vx.js → rating-Da38uaZz.js} +61 -54
- package/{rating-C2Y95r50.cjs → rating-DlfOuwuX.cjs} +61 -54
- package/{select-jUrt_lSn.js → select-CAEPqdz1.js} +92 -72
- package/{select-BBiF-m3N.cjs → select-LBVhNdrd.cjs} +92 -72
- package/services/extendWidget.d.ts +37 -4
- package/services/floatingUI.cjs +3 -2
- package/services/floatingUI.d.ts +28 -27
- package/services/floatingUI.js +3 -2
- package/services/focustrack.cjs +1 -1
- package/services/focustrack.d.ts +21 -0
- package/services/focustrack.js +1 -1
- package/services/hash.d.ts +2 -1
- package/services/intersection.cjs +1 -1
- package/services/intersection.d.ts +9 -13
- package/services/intersection.js +1 -1
- package/services/matchMedia.cjs +1 -1
- package/services/matchMedia.d.ts +2 -1
- package/services/matchMedia.js +1 -1
- package/services/navManager.cjs +1 -1
- package/services/navManager.d.ts +85 -41
- package/services/navManager.js +1 -1
- package/services/portal.cjs +1 -1
- package/services/portal.d.ts +3 -0
- package/services/portal.js +1 -1
- package/services/resizeObserver.cjs +2 -2
- package/services/resizeObserver.d.ts +2 -6
- package/services/resizeObserver.js +2 -2
- package/services/siblingsInert.cjs +3 -3
- package/services/siblingsInert.d.ts +3 -5
- package/services/siblingsInert.js +3 -3
- package/services/transitions/baseTransitions.cjs +4 -5
- package/services/transitions/baseTransitions.d.ts +21 -4
- package/services/transitions/baseTransitions.js +4 -5
- package/services/transitions/collapse.cjs +1 -1
- package/services/transitions/collapse.d.ts +6 -0
- package/services/transitions/collapse.js +1 -1
- package/services/transitions/cssTransitions.cjs +1 -1
- package/services/transitions/cssTransitions.d.ts +3 -0
- package/services/transitions/cssTransitions.js +1 -1
- package/services/transitions/simpleClassTransition.cjs +1 -1
- package/services/transitions/simpleClassTransition.d.ts +9 -2
- package/services/transitions/simpleClassTransition.js +1 -1
- package/{slider-ByDkbyr1.js → slider-DYrwS7Mv.js} +118 -116
- package/{slider-BdsZpxJr.cjs → slider-DlOAawbZ.cjs} +118 -116
- package/{toast-BzxextBQ.js → toast-CpvsibAI.js} +3 -3
- package/{toast-Dy3ck2cM.cjs → toast-D_uSrRZL.cjs} +3 -3
- package/types.cjs +0 -8
- package/types.d.ts +151 -19
- package/types.js +1 -9
- package/utils/directive.cjs +1 -1
- package/utils/directive.d.ts +81 -32
- package/utils/directive.js +1 -1
- package/utils/internal/checks.d.ts +6 -0
- package/utils/internal/dom.d.ts +5 -5
- package/utils/internal/promise.d.ts +9 -0
- package/utils/internal/sort.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +4 -0
- package/utils/stores.cjs +1 -1
- package/utils/stores.d.ts +80 -42
- package/utils/stores.js +1 -1
- package/utils/writables.cjs +2 -1
- package/utils/writables.d.ts +52 -3
- package/utils/writables.js +2 -1
- package/{writables-D46sFgGK.cjs → writables-BPAJvaL_.cjs} +9 -0
- package/{writables-DoU_XYTX.js → writables-DCiBdIBK.js} +11 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { computed } from "@amadeus-it-group/tansu";
|
|
2
|
-
import { INVALID_VALUE } from "./types.js";
|
|
3
2
|
import { writablesForProps, bindableProp, stateStores } from "./utils/stores.js";
|
|
4
|
-
import {
|
|
3
|
+
import { j as clamp, a as typeNumber, c as typeBoolean, f as typeFunction, e as typeString, k as isNumber } from "./writables-DCiBdIBK.js";
|
|
5
4
|
import { n as noop } from "./func-DR0n-ShK.js";
|
|
6
|
-
import { n as createAttributesDirective } from "./directive-
|
|
5
|
+
import { n as createAttributesDirective } from "./directive-CKEccryv.js";
|
|
7
6
|
const PAGE_LINK_DEFAULT = "#";
|
|
8
7
|
const defaultConfig = {
|
|
9
8
|
page: 1,
|
|
@@ -12,7 +11,6 @@ const defaultConfig = {
|
|
|
12
11
|
disabled: false,
|
|
13
12
|
directionLinks: true,
|
|
14
13
|
boundaryLinks: false,
|
|
15
|
-
size: null,
|
|
16
14
|
onPageChange: noop,
|
|
17
15
|
pagesFactory: (_page, pageCount) => {
|
|
18
16
|
const pages = [];
|
|
@@ -29,7 +27,7 @@ const defaultConfig = {
|
|
|
29
27
|
ariaNextLabel: "Action link for next page",
|
|
30
28
|
ariaLastLabel: "Action link for last page",
|
|
31
29
|
ariaEllipsisLabel: "Ellipsis page element",
|
|
32
|
-
ariaLiveLabel: (currentPage
|
|
30
|
+
ariaLiveLabel: (currentPage) => `Current page is ${currentPage}`,
|
|
33
31
|
className: "",
|
|
34
32
|
pageLink: (_page) => PAGE_LINK_DEFAULT
|
|
35
33
|
};
|
|
@@ -43,7 +41,6 @@ const configValidator = {
|
|
|
43
41
|
disabled: typeBoolean,
|
|
44
42
|
directionLinks: typeBoolean,
|
|
45
43
|
boundaryLinks: typeBoolean,
|
|
46
|
-
size: { normalizeValue: (value) => value === "lg" || value === "sm" || value === null ? value : INVALID_VALUE },
|
|
47
44
|
onPageChange: typeFunction,
|
|
48
45
|
pagesFactory: typeFunction,
|
|
49
46
|
ariaLabel: typeString,
|
|
@@ -55,7 +52,8 @@ const configValidator = {
|
|
|
55
52
|
ariaLastLabel: typeString,
|
|
56
53
|
ariaLiveLabel: typeFunction,
|
|
57
54
|
className: typeString,
|
|
58
|
-
pageLink: typeFunction
|
|
55
|
+
pageLink: typeFunction,
|
|
56
|
+
ariaEllipsisLabel: typeString
|
|
59
57
|
};
|
|
60
58
|
function createPagination(config) {
|
|
61
59
|
const [
|
|
@@ -109,17 +107,13 @@ function createPagination(config) {
|
|
|
109
107
|
};
|
|
110
108
|
});
|
|
111
109
|
const ariaLiveLabelText$ = computed(() => ariaLiveLabel$()(page$(), pageCount$()));
|
|
112
|
-
function handleNavigation(pageNumber, event
|
|
110
|
+
function handleNavigation(pageNumber, event) {
|
|
113
111
|
if (pagesHrefs$()[pageNumber - 1] === PAGE_LINK_DEFAULT) {
|
|
114
112
|
event == null ? void 0 : event.preventDefault();
|
|
115
113
|
}
|
|
116
114
|
if (!event || !(event.ctrlKey || event.metaKey)) {
|
|
117
115
|
event == null ? void 0 : event.preventDefault();
|
|
118
|
-
|
|
119
|
-
page$.update(pageNavigationHandler);
|
|
120
|
-
} else {
|
|
121
|
-
page$.set(pageNumber);
|
|
122
|
-
}
|
|
116
|
+
page$.set(pageNumber);
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
119
|
const widget = {
|
|
@@ -141,50 +135,44 @@ function createPagination(config) {
|
|
|
141
135
|
...stateProps
|
|
142
136
|
}),
|
|
143
137
|
patch,
|
|
144
|
-
|
|
138
|
+
api: {
|
|
145
139
|
/**
|
|
146
140
|
* Set the current page pageNumber (starting from 1)
|
|
147
141
|
* @param pageNumber - Current page number to set.
|
|
148
142
|
* Value is normalized between 1 and the number of page
|
|
149
|
-
* @param event UI event that triggered the select
|
|
150
143
|
*/
|
|
151
|
-
select(pageNumber
|
|
152
|
-
|
|
144
|
+
select(pageNumber) {
|
|
145
|
+
page$.set(pageNumber);
|
|
153
146
|
},
|
|
154
147
|
/**
|
|
155
148
|
* Select the first page
|
|
156
|
-
* @param event Event triggering the action
|
|
157
149
|
*/
|
|
158
|
-
first(
|
|
159
|
-
|
|
150
|
+
first() {
|
|
151
|
+
page$.set(1);
|
|
160
152
|
},
|
|
161
153
|
/**
|
|
162
154
|
* Select the previous page
|
|
163
|
-
* @param event Event triggering the action
|
|
164
155
|
*/
|
|
165
|
-
previous(
|
|
166
|
-
|
|
156
|
+
previous() {
|
|
157
|
+
page$.update((p) => p - 1);
|
|
167
158
|
},
|
|
168
159
|
/**
|
|
169
160
|
* Select the next page
|
|
170
|
-
* @param event Event triggering the action
|
|
171
161
|
*/
|
|
172
|
-
next(
|
|
173
|
-
|
|
162
|
+
next() {
|
|
163
|
+
page$.update((p) => p + 1);
|
|
174
164
|
},
|
|
175
165
|
/**
|
|
176
166
|
* Select the last page
|
|
177
|
-
* @param event Event triggering the action
|
|
178
167
|
*/
|
|
179
|
-
last(
|
|
180
|
-
|
|
168
|
+
last() {
|
|
169
|
+
page$.set(pageCount$());
|
|
181
170
|
}
|
|
182
171
|
},
|
|
183
|
-
api: {},
|
|
184
172
|
directives: {
|
|
185
173
|
pageLink: createAttributesDirective((pageLinkContext$) => ({
|
|
186
174
|
events: {
|
|
187
|
-
click: (e) =>
|
|
175
|
+
click: (e) => handleNavigation(pageLinkContext$().page, e)
|
|
188
176
|
},
|
|
189
177
|
attributes: {
|
|
190
178
|
"aria-current": computed(() => page$() === pageLinkContext$().page ? "page" : void 0),
|
|
@@ -199,7 +187,7 @@ function createPagination(config) {
|
|
|
199
187
|
})),
|
|
200
188
|
pageFirst: createAttributesDirective(() => ({
|
|
201
189
|
events: {
|
|
202
|
-
click: (e) =>
|
|
190
|
+
click: (e) => handleNavigation(1, e)
|
|
203
191
|
},
|
|
204
192
|
attributes: {
|
|
205
193
|
"aria-label": ariaFirstLabel$,
|
|
@@ -213,7 +201,7 @@ function createPagination(config) {
|
|
|
213
201
|
})),
|
|
214
202
|
pagePrev: createAttributesDirective(() => ({
|
|
215
203
|
events: {
|
|
216
|
-
click: (e) =>
|
|
204
|
+
click: (e) => handleNavigation(page$() - 1, e)
|
|
217
205
|
},
|
|
218
206
|
attributes: {
|
|
219
207
|
"aria-label": ariaPreviousLabel$,
|
|
@@ -227,7 +215,7 @@ function createPagination(config) {
|
|
|
227
215
|
})),
|
|
228
216
|
pageNext: createAttributesDirective(() => ({
|
|
229
217
|
events: {
|
|
230
|
-
click: (e) =>
|
|
218
|
+
click: (e) => handleNavigation(page$() + 1, e)
|
|
231
219
|
},
|
|
232
220
|
attributes: {
|
|
233
221
|
"aria-label": ariaNextLabel$,
|
|
@@ -241,7 +229,7 @@ function createPagination(config) {
|
|
|
241
229
|
})),
|
|
242
230
|
pageLast: createAttributesDirective(() => ({
|
|
243
231
|
events: {
|
|
244
|
-
click: (e) =>
|
|
232
|
+
click: (e) => handleNavigation(pageCount$(), e)
|
|
245
233
|
},
|
|
246
234
|
attributes: {
|
|
247
235
|
"aria-label": ariaLastLabel$,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as clamp, a as typeNumber, e as typeString, f as typeFunction } from "./writables-DCiBdIBK.js";
|
|
2
2
|
import { writablesForProps, stateStores } from "./utils/stores.js";
|
|
3
3
|
import { computed } from "@amadeus-it-group/tansu";
|
|
4
|
-
import { n as createAttributesDirective } from "./directive-
|
|
4
|
+
import { n as createAttributesDirective } from "./directive-CKEccryv.js";
|
|
5
5
|
const defaultConfig = {
|
|
6
6
|
min: 0,
|
|
7
7
|
max: 100,
|
|
@@ -74,8 +74,7 @@ function createProgressbar(config) {
|
|
|
74
74
|
"aria-valuetext": ariaValueText$
|
|
75
75
|
}
|
|
76
76
|
}))
|
|
77
|
-
}
|
|
78
|
-
actions: {}
|
|
77
|
+
}
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
80
|
export {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const utils_writables = require("./writables-
|
|
2
|
+
const utils_writables = require("./writables-BPAJvaL_.cjs");
|
|
3
3
|
const utils_stores = require("./utils/stores.cjs");
|
|
4
4
|
const tansu = require("@amadeus-it-group/tansu");
|
|
5
|
-
const utils_directive = require("./directive-
|
|
5
|
+
const utils_directive = require("./directive-DdlwGFtf.cjs");
|
|
6
6
|
const defaultConfig = {
|
|
7
7
|
min: 0,
|
|
8
8
|
max: 100,
|
|
@@ -75,8 +75,7 @@ function createProgressbar(config) {
|
|
|
75
75
|
"aria-valuetext": ariaValueText$
|
|
76
76
|
}
|
|
77
77
|
}))
|
|
78
|
-
}
|
|
79
|
-
actions: {}
|
|
78
|
+
}
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
exports.createProgressbar = createProgressbar;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed, writable } from "@amadeus-it-group/tansu";
|
|
2
2
|
import { INVALID_VALUE } from "./types.js";
|
|
3
|
-
import { n as createAttributesDirective } from "./directive-
|
|
4
|
-
import {
|
|
3
|
+
import { n as createAttributesDirective } from "./directive-CKEccryv.js";
|
|
4
|
+
import { j as clamp, a as typeNumber, k as isNumber, c as typeBoolean, f as typeFunction, e as typeString } from "./writables-DCiBdIBK.js";
|
|
5
5
|
import { n as noop } from "./func-DR0n-ShK.js";
|
|
6
6
|
import { writablesForProps, bindableProp, stateStores } from "./utils/stores.js";
|
|
7
7
|
const defaultConfig = {
|
|
@@ -53,7 +53,7 @@ function createRating(config) {
|
|
|
53
53
|
] = writablesForProps(defaultConfig, config, configValidator);
|
|
54
54
|
const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
|
|
55
55
|
const tabindex$ = computed(() => disabled$() ? -1 : _dirtyTabindex$());
|
|
56
|
-
const rating$ = bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => clamp(dirtyRating, maxRating$()));
|
|
56
|
+
const rating$ = bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => clamp(dirtyRating, maxRating$(), 0));
|
|
57
57
|
const _hoveredRating$ = writable(0);
|
|
58
58
|
const interactive$ = computed(() => !disabled$() && !readonly$());
|
|
59
59
|
const visibleRating$ = computed(() => {
|
|
@@ -79,57 +79,41 @@ function createRating(config) {
|
|
|
79
79
|
...stateProps
|
|
80
80
|
}),
|
|
81
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
82
|
directives: {
|
|
129
83
|
containerDirective: createAttributesDirective(() => ({
|
|
130
84
|
events: {
|
|
131
|
-
keydown: (
|
|
132
|
-
|
|
85
|
+
keydown: (event) => {
|
|
86
|
+
if (interactive$()) {
|
|
87
|
+
const { key } = event;
|
|
88
|
+
switch (key) {
|
|
89
|
+
case "ArrowLeft":
|
|
90
|
+
case "ArrowDown":
|
|
91
|
+
rating$.update((rating) => rating - 1);
|
|
92
|
+
break;
|
|
93
|
+
case "ArrowRight":
|
|
94
|
+
case "ArrowUp":
|
|
95
|
+
rating$.update((rating) => rating + 1);
|
|
96
|
+
break;
|
|
97
|
+
case "Home":
|
|
98
|
+
case "PageDown":
|
|
99
|
+
rating$.set(0);
|
|
100
|
+
break;
|
|
101
|
+
case "End":
|
|
102
|
+
case "PageUp":
|
|
103
|
+
rating$.set(maxRating$());
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
mouseleave: () => {
|
|
113
|
+
if (interactive$()) {
|
|
114
|
+
widget.api.leave();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
133
117
|
},
|
|
134
118
|
attributes: {
|
|
135
119
|
role: "slider",
|
|
@@ -151,8 +135,19 @@ function createRating(config) {
|
|
|
151
135
|
starDirective: createAttributesDirective((starContext$) => {
|
|
152
136
|
return {
|
|
153
137
|
events: {
|
|
154
|
-
mouseenter: () =>
|
|
155
|
-
|
|
138
|
+
mouseenter: () => {
|
|
139
|
+
const index = starContext$().index + 1;
|
|
140
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
141
|
+
_hoveredRating$.set(index);
|
|
142
|
+
onHover$()(index);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
click: () => {
|
|
146
|
+
const index = starContext$().index + 1;
|
|
147
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
148
|
+
rating$.update((rating) => rating === index && resettable$() ? 0 : index);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
156
151
|
},
|
|
157
152
|
styles: {
|
|
158
153
|
cursor: computed(() => interactive$() ? "pointer" : "default")
|
|
@@ -163,7 +158,19 @@ function createRating(config) {
|
|
|
163
158
|
};
|
|
164
159
|
})
|
|
165
160
|
},
|
|
166
|
-
api: {
|
|
161
|
+
api: {
|
|
162
|
+
setRating(index) {
|
|
163
|
+
rating$.set(index);
|
|
164
|
+
},
|
|
165
|
+
setHoveredRating(index) {
|
|
166
|
+
onHover$()(index);
|
|
167
|
+
_hoveredRating$.set(index);
|
|
168
|
+
},
|
|
169
|
+
leave() {
|
|
170
|
+
onLeave$()(visibleRating$());
|
|
171
|
+
_hoveredRating$.set(0);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
167
174
|
};
|
|
168
175
|
return widget;
|
|
169
176
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const tansu = require("@amadeus-it-group/tansu");
|
|
3
3
|
const types = require("./types.cjs");
|
|
4
|
-
const utils_directive = require("./directive-
|
|
5
|
-
const utils_writables = require("./writables-
|
|
4
|
+
const utils_directive = require("./directive-DdlwGFtf.cjs");
|
|
5
|
+
const utils_writables = require("./writables-BPAJvaL_.cjs");
|
|
6
6
|
const func = require("./func-Qd3cD9a3.cjs");
|
|
7
7
|
const utils_stores = require("./utils/stores.cjs");
|
|
8
8
|
const defaultConfig = {
|
|
@@ -54,7 +54,7 @@ function createRating(config) {
|
|
|
54
54
|
] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
|
|
55
55
|
const { ariaLabel$, ariaLabelledBy$, className$, disabled$, maxRating$, readonly$, resettable$ } = stateProps;
|
|
56
56
|
const tabindex$ = tansu.computed(() => disabled$() ? -1 : _dirtyTabindex$());
|
|
57
|
-
const rating$ = utils_stores.bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => utils_writables.clamp(dirtyRating, maxRating$()));
|
|
57
|
+
const rating$ = utils_stores.bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => utils_writables.clamp(dirtyRating, maxRating$(), 0));
|
|
58
58
|
const _hoveredRating$ = tansu.writable(0);
|
|
59
59
|
const interactive$ = tansu.computed(() => !disabled$() && !readonly$());
|
|
60
60
|
const visibleRating$ = tansu.computed(() => {
|
|
@@ -80,57 +80,41 @@ function createRating(config) {
|
|
|
80
80
|
...stateProps
|
|
81
81
|
}),
|
|
82
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
83
|
directives: {
|
|
130
84
|
containerDirective: utils_directive.createAttributesDirective(() => ({
|
|
131
85
|
events: {
|
|
132
|
-
keydown: (
|
|
133
|
-
|
|
86
|
+
keydown: (event) => {
|
|
87
|
+
if (interactive$()) {
|
|
88
|
+
const { key } = event;
|
|
89
|
+
switch (key) {
|
|
90
|
+
case "ArrowLeft":
|
|
91
|
+
case "ArrowDown":
|
|
92
|
+
rating$.update((rating) => rating - 1);
|
|
93
|
+
break;
|
|
94
|
+
case "ArrowRight":
|
|
95
|
+
case "ArrowUp":
|
|
96
|
+
rating$.update((rating) => rating + 1);
|
|
97
|
+
break;
|
|
98
|
+
case "Home":
|
|
99
|
+
case "PageDown":
|
|
100
|
+
rating$.set(0);
|
|
101
|
+
break;
|
|
102
|
+
case "End":
|
|
103
|
+
case "PageUp":
|
|
104
|
+
rating$.set(maxRating$());
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
event.stopPropagation();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
mouseleave: () => {
|
|
114
|
+
if (interactive$()) {
|
|
115
|
+
widget.api.leave();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
134
118
|
},
|
|
135
119
|
attributes: {
|
|
136
120
|
role: "slider",
|
|
@@ -152,8 +136,19 @@ function createRating(config) {
|
|
|
152
136
|
starDirective: utils_directive.createAttributesDirective((starContext$) => {
|
|
153
137
|
return {
|
|
154
138
|
events: {
|
|
155
|
-
mouseenter: () =>
|
|
156
|
-
|
|
139
|
+
mouseenter: () => {
|
|
140
|
+
const index = starContext$().index + 1;
|
|
141
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
142
|
+
_hoveredRating$.set(index);
|
|
143
|
+
onHover$()(index);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
click: () => {
|
|
147
|
+
const index = starContext$().index + 1;
|
|
148
|
+
if (interactive$() && index > 0 && index <= maxRating$()) {
|
|
149
|
+
rating$.update((rating) => rating === index && resettable$() ? 0 : index);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
157
152
|
},
|
|
158
153
|
styles: {
|
|
159
154
|
cursor: tansu.computed(() => interactive$() ? "pointer" : "default")
|
|
@@ -164,7 +159,19 @@ function createRating(config) {
|
|
|
164
159
|
};
|
|
165
160
|
})
|
|
166
161
|
},
|
|
167
|
-
api: {
|
|
162
|
+
api: {
|
|
163
|
+
setRating(index) {
|
|
164
|
+
rating$.set(index);
|
|
165
|
+
},
|
|
166
|
+
setHoveredRating(index) {
|
|
167
|
+
onHover$()(index);
|
|
168
|
+
_hoveredRating$.set(index);
|
|
169
|
+
},
|
|
170
|
+
leave() {
|
|
171
|
+
onLeave$()(visibleRating$());
|
|
172
|
+
_hoveredRating$.set(0);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
168
175
|
};
|
|
169
176
|
return widget;
|
|
170
177
|
}
|