@agnos-ui/core 0.4.4 → 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.
Files changed (113) hide show
  1. package/README.md +2 -2
  2. package/{accordion-BnaSamoQ.js → accordion-BGv150k9.js} +10 -13
  3. package/{accordion-DmPT0O0j.cjs → accordion-Lp-LEbZ2.cjs} +10 -13
  4. package/{alert-CEFbEgvG.cjs → alert-Bq101evB.cjs} +1 -1
  5. package/{alert-DdGuK__c.js → alert-DJ2l7bcA.js} +1 -1
  6. package/{common-CO5b5G_J.js → common-Banw3FYN.js} +15 -14
  7. package/{common-nxv_hKNE.cjs → common-DvPjK7SS.cjs} +15 -14
  8. package/components/accordion/accordion.d.ts +35 -8
  9. package/components/accordion/index.cjs +1 -1
  10. package/components/accordion/index.js +1 -1
  11. package/components/alert/alert.d.ts +16 -1
  12. package/components/alert/common.d.ts +19 -1
  13. package/components/alert/index.cjs +1 -1
  14. package/components/alert/index.js +1 -1
  15. package/components/commonProps.d.ts +3 -0
  16. package/components/modal/index.cjs +1 -1
  17. package/components/modal/index.js +1 -1
  18. package/components/modal/modal.d.ts +3 -135
  19. package/components/pagination/index.cjs +1 -1
  20. package/components/pagination/index.js +1 -1
  21. package/components/pagination/pagination.d.ts +30 -217
  22. package/components/progressbar/index.cjs +1 -1
  23. package/components/progressbar/index.js +1 -1
  24. package/components/progressbar/progressbar.d.ts +13 -3
  25. package/components/rating/index.cjs +1 -1
  26. package/components/rating/index.js +1 -1
  27. package/components/rating/rating.d.ts +26 -115
  28. package/components/select/index.cjs +1 -1
  29. package/components/select/index.js +1 -1
  30. package/components/select/select.d.ts +21 -148
  31. package/components/slider/index.cjs +1 -1
  32. package/components/slider/index.js +1 -1
  33. package/components/slider/slider.d.ts +31 -126
  34. package/components/toast/index.cjs +1 -1
  35. package/components/toast/index.js +1 -1
  36. package/components/toast/toast.d.ts +16 -1
  37. package/config.d.ts +17 -1
  38. package/{directive-3-8yr-ZK.js → directive-CKEccryv.js} +11 -5
  39. package/{directive-j-xRk-h3.cjs → directive-DdlwGFtf.cjs} +11 -5
  40. package/index.cjs +13 -13
  41. package/index.js +15 -15
  42. package/{modal-D4d8sy85.cjs → modal-DDHcrykD.cjs} +10 -21
  43. package/{modal-CeTI4jxI.js → modal-DP-4I7vf.js} +11 -22
  44. package/package.json +6 -5
  45. package/{pagination-B9WFv70F.cjs → pagination-CBysiPUs.cjs} +23 -35
  46. package/{pagination-BpPHKQsH.js → pagination-DwDRot6q.js} +23 -35
  47. package/{progressbar-BybOg5FE.js → progressbar-CGmNq0cS.js} +3 -4
  48. package/{progressbar-DXCMeJvL.cjs → progressbar-DghzCJ6_.cjs} +3 -4
  49. package/{rating-D6Tv_4Vx.js → rating-Da38uaZz.js} +61 -54
  50. package/{rating-C2Y95r50.cjs → rating-DlfOuwuX.cjs} +61 -54
  51. package/{select-jUrt_lSn.js → select-CAEPqdz1.js} +92 -72
  52. package/{select-BBiF-m3N.cjs → select-LBVhNdrd.cjs} +92 -72
  53. package/services/extendWidget.d.ts +37 -4
  54. package/services/floatingUI.cjs +3 -2
  55. package/services/floatingUI.d.ts +28 -27
  56. package/services/floatingUI.js +3 -2
  57. package/services/focustrack.cjs +1 -1
  58. package/services/focustrack.d.ts +21 -0
  59. package/services/focustrack.js +1 -1
  60. package/services/hash.d.ts +2 -1
  61. package/services/intersection.cjs +1 -1
  62. package/services/intersection.d.ts +9 -13
  63. package/services/intersection.js +1 -1
  64. package/services/matchMedia.cjs +1 -1
  65. package/services/matchMedia.d.ts +2 -1
  66. package/services/matchMedia.js +1 -1
  67. package/services/navManager.cjs +1 -1
  68. package/services/navManager.d.ts +85 -41
  69. package/services/navManager.js +1 -1
  70. package/services/portal.cjs +1 -1
  71. package/services/portal.d.ts +3 -0
  72. package/services/portal.js +1 -1
  73. package/services/resizeObserver.cjs +2 -2
  74. package/services/resizeObserver.d.ts +2 -6
  75. package/services/resizeObserver.js +2 -2
  76. package/services/siblingsInert.cjs +3 -3
  77. package/services/siblingsInert.d.ts +3 -5
  78. package/services/siblingsInert.js +3 -3
  79. package/services/transitions/baseTransitions.cjs +4 -5
  80. package/services/transitions/baseTransitions.d.ts +21 -4
  81. package/services/transitions/baseTransitions.js +4 -5
  82. package/services/transitions/collapse.cjs +1 -1
  83. package/services/transitions/collapse.d.ts +6 -0
  84. package/services/transitions/collapse.js +1 -1
  85. package/services/transitions/cssTransitions.cjs +1 -1
  86. package/services/transitions/cssTransitions.d.ts +3 -0
  87. package/services/transitions/cssTransitions.js +1 -1
  88. package/services/transitions/simpleClassTransition.cjs +1 -1
  89. package/services/transitions/simpleClassTransition.d.ts +9 -2
  90. package/services/transitions/simpleClassTransition.js +1 -1
  91. package/{slider-ByDkbyr1.js → slider-DYrwS7Mv.js} +118 -116
  92. package/{slider-BdsZpxJr.cjs → slider-DlOAawbZ.cjs} +118 -116
  93. package/{toast-BzxextBQ.js → toast-CpvsibAI.js} +3 -3
  94. package/{toast-Dy3ck2cM.cjs → toast-D_uSrRZL.cjs} +3 -3
  95. package/types.cjs +0 -8
  96. package/types.d.ts +151 -19
  97. package/types.js +1 -9
  98. package/utils/directive.cjs +1 -1
  99. package/utils/directive.d.ts +81 -32
  100. package/utils/directive.js +1 -1
  101. package/utils/internal/checks.d.ts +6 -0
  102. package/utils/internal/dom.d.ts +5 -5
  103. package/utils/internal/promise.d.ts +9 -0
  104. package/utils/internal/sort.d.ts +2 -2
  105. package/utils/internal/ssrHTMLElement.d.ts +4 -0
  106. package/utils/stores.cjs +1 -1
  107. package/utils/stores.d.ts +80 -42
  108. package/utils/stores.js +1 -1
  109. package/utils/writables.cjs +2 -1
  110. package/utils/writables.d.ts +52 -3
  111. package/utils/writables.js +2 -1
  112. package/{writables-D46sFgGK.cjs → writables-BPAJvaL_.cjs} +9 -0
  113. 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 { i as clamp, a as typeNumber, c as typeBoolean, f as typeFunction, e as typeString, j as isNumber } from "./writables-DoU_XYTX.js";
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-3-8yr-ZK.js";
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, pageCount) => `Current page is ${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, pageNavigationHandler) {
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
- if (pageNavigationHandler) {
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
- actions: {
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, event) {
152
- handleNavigation(pageNumber, event);
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(event) {
159
- handleNavigation(1, event);
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(event) {
166
- handleNavigation(page$() - 1, event, (page) => page - 1);
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(event) {
173
- handleNavigation(page$() + 1, event, (page) => page + 1);
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(event) {
180
- handleNavigation(pageCount$(), event);
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) => widget.actions.select(pageLinkContext$().page, 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) => widget.actions.first(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) => widget.actions.previous(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) => widget.actions.next(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) => widget.actions.last(e)
232
+ click: (e) => handleNavigation(pageCount$(), e)
245
233
  },
246
234
  attributes: {
247
235
  "aria-label": ariaLastLabel$,
@@ -1,7 +1,7 @@
1
- import { i as clamp, a as typeNumber, e as typeString, f as typeFunction } from "./writables-DoU_XYTX.js";
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-3-8yr-ZK.js";
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-D46sFgGK.cjs");
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-j-xRk-h3.cjs");
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-3-8yr-ZK.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";
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: (e) => widget.actions.handleKey(e),
132
- mouseleave: () => widget.actions.leave()
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: () => widget.actions.hover(starContext$().index + 1),
155
- click: () => widget.actions.click(starContext$().index + 1)
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-j-xRk-h3.cjs");
5
- const utils_writables = require("./writables-D46sFgGK.cjs");
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: (e) => widget.actions.handleKey(e),
133
- mouseleave: () => widget.actions.leave()
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: () => widget.actions.hover(starContext$().index + 1),
156
- click: () => widget.actions.click(starContext$().index + 1)
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
  }