@design-factory/core 21.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +3 -0
  2. package/accordion-B0vs8JWM.cjs +314 -0
  3. package/accordion-D9ba0XYq.js +315 -0
  4. package/alert-AhaliJ17.cjs +9 -0
  5. package/alert-Cb9FhbFQ.js +10 -0
  6. package/collapse-Bn8iHKrd.js +95 -0
  7. package/collapse-BnWw4Hnc.cjs +94 -0
  8. package/common-B5jS-Ih_.cjs +73 -0
  9. package/common-DFyZvkII.js +74 -0
  10. package/components/accordion/accordion.d.ts +333 -0
  11. package/components/accordion/index.cjs +7 -0
  12. package/components/accordion/index.d.ts +1 -0
  13. package/components/accordion/index.js +7 -0
  14. package/components/alert/alert.d.ts +37 -0
  15. package/components/alert/common.d.ts +138 -0
  16. package/components/alert/index.cjs +5 -0
  17. package/components/alert/index.d.ts +1 -0
  18. package/components/alert/index.js +5 -0
  19. package/components/carousel/carousel.d.ts +247 -0
  20. package/components/carousel/index.cjs +292 -0
  21. package/components/carousel/index.d.ts +1 -0
  22. package/components/carousel/index.js +292 -0
  23. package/components/collapse/collapse.d.ts +135 -0
  24. package/components/collapse/index.cjs +5 -0
  25. package/components/collapse/index.d.ts +1 -0
  26. package/components/collapse/index.js +5 -0
  27. package/components/commonProps.d.ts +11 -0
  28. package/components/drawer/drawer.d.ts +279 -0
  29. package/components/drawer/index.cjs +5 -0
  30. package/components/drawer/index.d.ts +1 -0
  31. package/components/drawer/index.js +5 -0
  32. package/components/modal/index.cjs +8 -0
  33. package/components/modal/index.d.ts +1 -0
  34. package/components/modal/index.js +8 -0
  35. package/components/modal/modal.d.ts +245 -0
  36. package/components/pagination/index.cjs +5 -0
  37. package/components/pagination/index.d.ts +1 -0
  38. package/components/pagination/index.js +5 -0
  39. package/components/pagination/pagination.d.ts +313 -0
  40. package/components/progressbar/index.cjs +5 -0
  41. package/components/progressbar/index.d.ts +1 -0
  42. package/components/progressbar/index.js +5 -0
  43. package/components/progressbar/progressbar.d.ts +91 -0
  44. package/components/rating/index.cjs +5 -0
  45. package/components/rating/index.d.ts +1 -0
  46. package/components/rating/index.js +5 -0
  47. package/components/rating/rating.d.ts +191 -0
  48. package/components/slider/index.cjs +5 -0
  49. package/components/slider/index.d.ts +1 -0
  50. package/components/slider/index.js +5 -0
  51. package/components/slider/slider-utils.d.ts +25 -0
  52. package/components/slider/slider.d.ts +383 -0
  53. package/components/toast/index.cjs +7 -0
  54. package/components/toast/index.d.ts +2 -0
  55. package/components/toast/index.js +7 -0
  56. package/components/toast/toast.d.ts +66 -0
  57. package/components/toast/toaster.d.ts +128 -0
  58. package/components/tree/index.cjs +5 -0
  59. package/components/tree/index.d.ts +1 -0
  60. package/components/tree/index.js +5 -0
  61. package/components/tree/tree.d.ts +143 -0
  62. package/config.cjs +36 -0
  63. package/config.d.ts +117 -0
  64. package/config.js +36 -0
  65. package/directive-CNNSo5Yn.js +524 -0
  66. package/directive-DyTodNPd.cjs +523 -0
  67. package/drawer-BIIfJa0F.js +329 -0
  68. package/drawer-C8ojtwIn.cjs +328 -0
  69. package/index.cjs +134 -0
  70. package/index.d.ts +29 -0
  71. package/index.js +134 -0
  72. package/isFocusable-Ckwus82R.js +32 -0
  73. package/isFocusable-DfzDLeAN.cjs +31 -0
  74. package/modal-C13G13jV.js +253 -0
  75. package/modal-DWv0VqiG.cjs +252 -0
  76. package/package.json +56 -0
  77. package/pagination-BLVa1UsZ.cjs +254 -0
  78. package/pagination-BQWusWXN.js +255 -0
  79. package/progressbar-RopgvVeA.cjs +86 -0
  80. package/progressbar-S1pNn5rM.js +87 -0
  81. package/promise-CxCD3NYv.cjs +118 -0
  82. package/promise-D-RZVPuv.js +119 -0
  83. package/rating-DWgGgwk3.js +184 -0
  84. package/rating-DZ3OQgtt.cjs +183 -0
  85. package/scrollbars-CT87iv_6.cjs +30 -0
  86. package/scrollbars-CcxSrnCx.js +31 -0
  87. package/services/extendWidget.cjs +41 -0
  88. package/services/extendWidget.d.ts +31 -0
  89. package/services/extendWidget.js +41 -0
  90. package/services/floatingUI.cjs +111 -0
  91. package/services/floatingUI.d.ts +76 -0
  92. package/services/floatingUI.js +111 -0
  93. package/services/focusElement.cjs +46 -0
  94. package/services/focusElement.d.ts +9 -0
  95. package/services/focusElement.js +46 -0
  96. package/services/focustrack.cjs +47 -0
  97. package/services/focustrack.d.ts +40 -0
  98. package/services/focustrack.js +47 -0
  99. package/services/hash.cjs +15 -0
  100. package/services/hash.d.ts +3 -0
  101. package/services/hash.js +15 -0
  102. package/services/intersection.cjs +53 -0
  103. package/services/intersection.d.ts +30 -0
  104. package/services/intersection.js +53 -0
  105. package/services/matchMedia.cjs +14 -0
  106. package/services/matchMedia.d.ts +8 -0
  107. package/services/matchMedia.js +14 -0
  108. package/services/navManager.cjs +166 -0
  109. package/services/navManager.d.ts +144 -0
  110. package/services/navManager.js +166 -0
  111. package/services/pointerdownPosition.cjs +60 -0
  112. package/services/pointerdownPosition.d.ts +42 -0
  113. package/services/pointerdownPosition.js +60 -0
  114. package/services/portal.cjs +42 -0
  115. package/services/portal.d.ts +16 -0
  116. package/services/portal.js +42 -0
  117. package/services/resizeObserver.cjs +54 -0
  118. package/services/resizeObserver.d.ts +18 -0
  119. package/services/resizeObserver.js +54 -0
  120. package/services/siblingsInert.cjs +44 -0
  121. package/services/siblingsInert.d.ts +16 -0
  122. package/services/siblingsInert.js +44 -0
  123. package/services/transitions/baseTransitions.cjs +186 -0
  124. package/services/transitions/baseTransitions.d.ts +166 -0
  125. package/services/transitions/baseTransitions.js +186 -0
  126. package/services/transitions/collapse.cjs +40 -0
  127. package/services/transitions/collapse.d.ts +49 -0
  128. package/services/transitions/collapse.js +40 -0
  129. package/services/transitions/cssTransitions.cjs +32 -0
  130. package/services/transitions/cssTransitions.d.ts +25 -0
  131. package/services/transitions/cssTransitions.js +32 -0
  132. package/services/transitions/simpleClassTransition.cjs +37 -0
  133. package/services/transitions/simpleClassTransition.d.ts +47 -0
  134. package/services/transitions/simpleClassTransition.js +37 -0
  135. package/slider-Br_Qiopx.js +808 -0
  136. package/slider-pgDq1V5r.cjs +807 -0
  137. package/textDirection-cNgt24LJ.js +4 -0
  138. package/textDirection-zqcZ5-eK.cjs +3 -0
  139. package/toaster-BUBzFeJM.js +162 -0
  140. package/toaster-Dlube4Ya.cjs +161 -0
  141. package/tree-Chcy4ulJ.cjs +228 -0
  142. package/tree-vD7ZkV8Z.js +229 -0
  143. package/types.cjs +6 -0
  144. package/types.d.ts +246 -0
  145. package/types.js +6 -0
  146. package/utils/directive.cjs +28 -0
  147. package/utils/directive.d.ts +352 -0
  148. package/utils/directive.js +28 -0
  149. package/utils/func.cjs +7 -0
  150. package/utils/func.d.ts +11 -0
  151. package/utils/func.js +7 -0
  152. package/utils/id.cjs +5 -0
  153. package/utils/id.d.ts +6 -0
  154. package/utils/id.js +5 -0
  155. package/utils/internal/assign.d.ts +10 -0
  156. package/utils/internal/checks.d.ts +57 -0
  157. package/utils/internal/dom.d.ts +75 -0
  158. package/utils/internal/isFocusable.d.ts +9 -0
  159. package/utils/internal/math.d.ts +5 -0
  160. package/utils/internal/promise.d.ts +98 -0
  161. package/utils/internal/scrollbars.d.ts +8 -0
  162. package/utils/internal/sort.d.ts +16 -0
  163. package/utils/internal/ssrHTMLElement.d.ts +17 -0
  164. package/utils/internal/textDirection.d.ts +7 -0
  165. package/utils/internal/traversal.d.ts +54 -0
  166. package/utils/stores.cjs +172 -0
  167. package/utils/stores.d.ts +224 -0
  168. package/utils/stores.js +172 -0
  169. package/utils/widget.cjs +8 -0
  170. package/utils/widget.d.ts +11 -0
  171. package/utils/widget.js +8 -0
  172. package/utils/writables.cjs +16 -0
  173. package/utils/writables.d.ts +95 -0
  174. package/utils/writables.js +16 -0
  175. package/writables-DYGjj5T3.js +103 -0
  176. package/writables-Dt68gADJ.cjs +102 -0
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const utils_writables = require("./writables-Dt68gADJ.cjs");
4
+ const utils_stores = require("./utils/stores.cjs");
5
+ const services_transitions_baseTransitions = require("./services/transitions/baseTransitions.cjs");
6
+ const promise = require("./promise-CxCD3NYv.cjs");
7
+ const utils_func = require("./utils/func.cjs");
8
+ const scrollbars = require("./scrollbars-CT87iv_6.cjs");
9
+ const utils_directive = require("./directive-DyTodNPd.cjs");
10
+ const services_portal = require("./services/portal.cjs");
11
+ const services_siblingsInert = require("./services/siblingsInert.cjs");
12
+ const utils_widget = require("./utils/widget.cjs");
13
+ const services_focusElement = require("./services/focusElement.cjs");
14
+ const modalOutsideClick = /* @__PURE__ */ Symbol();
15
+ const modalCloseButtonClick = /* @__PURE__ */ Symbol();
16
+ const modalCloseEscape = /* @__PURE__ */ Symbol();
17
+ const defaultConfig = {
18
+ animated: true,
19
+ ariaCloseButtonLabel: "Close",
20
+ backdrop: true,
21
+ backdropClass: "",
22
+ backdropTransition: utils_func.noop,
23
+ closeButton: true,
24
+ closeOnOutsideClick: true,
25
+ container: typeof window !== "undefined" ? document.body : null,
26
+ className: "",
27
+ modalTransition: utils_func.noop,
28
+ onBeforeClose: utils_func.noop,
29
+ onVisibleChange: utils_func.noop,
30
+ onHidden: utils_func.noop,
31
+ onShown: utils_func.noop,
32
+ visible: false
33
+ };
34
+ const configValidator = {
35
+ animated: utils_writables.typeBoolean,
36
+ ariaCloseButtonLabel: utils_writables.typeString,
37
+ backdrop: utils_writables.typeBoolean,
38
+ backdropClass: utils_writables.typeString,
39
+ backdropTransition: utils_writables.typeFunction,
40
+ closeButton: utils_writables.typeBoolean,
41
+ closeOnOutsideClick: utils_writables.typeBoolean,
42
+ container: utils_writables.typeHTMLElementOrNull,
43
+ className: utils_writables.typeString,
44
+ modalTransition: utils_writables.typeFunction,
45
+ onBeforeClose: utils_writables.typeFunction,
46
+ onVisibleChange: utils_writables.typeFunction,
47
+ onHidden: utils_writables.typeFunction,
48
+ onShown: utils_writables.typeFunction,
49
+ visible: utils_writables.typeBoolean
50
+ };
51
+ function getModalDefaultConfig() {
52
+ return { ...defaultConfig };
53
+ }
54
+ const modals$ = utils_directive.registrationArray();
55
+ const hasModals$ = tansu.computed(() => modals$().length > 0);
56
+ const scrollbarsAction$ = tansu.computed(() => {
57
+ if (hasModals$()) {
58
+ scrollbars.removeScrollbars();
59
+ } else {
60
+ scrollbars.revertScrollbars();
61
+ }
62
+ });
63
+ const modalsAction$ = tansu.computed(() => {
64
+ scrollbarsAction$();
65
+ });
66
+ const createModal = utils_widget.createWidgetFactory(
67
+ "modal",
68
+ (config$) => {
69
+ const [
70
+ {
71
+ animated$,
72
+ backdrop$,
73
+ backdropTransition$,
74
+ closeOnOutsideClick$,
75
+ container$,
76
+ modalTransition$,
77
+ onBeforeClose$,
78
+ onVisibleChange$,
79
+ onHidden$,
80
+ onShown$,
81
+ ariaCloseButtonLabel$,
82
+ className$,
83
+ backdropClass$,
84
+ visible$: requestedVisible$,
85
+ ...stateProps
86
+ },
87
+ patch
88
+ ] = utils_stores.writablesForProps(defaultConfig, config$, configValidator);
89
+ const modalTransition = services_transitions_baseTransitions.createTransition({
90
+ props: {
91
+ transition: modalTransition$,
92
+ visible: requestedVisible$,
93
+ animated: animated$,
94
+ animatedOnInit: animated$,
95
+ onVisibleChange: onVisibleChange$,
96
+ // TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
97
+ // (especially in case one of the two transitions takes more time than the other)
98
+ onHidden: onHidden$,
99
+ onShown: onShown$
100
+ }
101
+ });
102
+ const visible$ = modalTransition.stores.visible$;
103
+ const backdropTransition = services_transitions_baseTransitions.createTransition({
104
+ props: {
105
+ transition: backdropTransition$,
106
+ visible: requestedVisible$,
107
+ animated: animated$,
108
+ animatedOnInit: animated$
109
+ }
110
+ });
111
+ const transitioning$ = tansu.computed(
112
+ () => modalTransition.stores.transitioning$() || backdrop$() && backdropTransition.stores.transitioning$()
113
+ );
114
+ const hidden$ = tansu.computed(() => !transitioning$() && !visible$());
115
+ const backdropHidden$ = tansu.computed(() => !backdrop$() || hidden$());
116
+ let hideResult;
117
+ const close = (result) => {
118
+ hideResult = result;
119
+ const beforeCloseEvent = {
120
+ get result() {
121
+ return hideResult;
122
+ },
123
+ set result(value) {
124
+ hideResult = value;
125
+ },
126
+ cancel: false
127
+ };
128
+ onBeforeClose$()(beforeCloseEvent);
129
+ if (beforeCloseEvent.cancel) {
130
+ return;
131
+ }
132
+ patch({ visible: false });
133
+ };
134
+ const modalPortalDirective = utils_directive.bindDirective(
135
+ services_portal.portal,
136
+ tansu.computed(() => ({ container: container$() }))
137
+ );
138
+ const backdropPortalDirective = utils_directive.bindDirective(
139
+ services_portal.portal,
140
+ tansu.computed(() => {
141
+ const container = container$();
142
+ const element = container ? modalTransition.stores.element$() : void 0;
143
+ return {
144
+ container,
145
+ insertBefore: element?.parentElement === container ? element : void 0
146
+ };
147
+ })
148
+ );
149
+ const registerModalAction$ = tansu.readable(void 0, () => modals$.register(res));
150
+ const action$ = tansu.computed(() => {
151
+ if (modalTransition.stores.elementPresent$() && !hidden$()) {
152
+ registerModalAction$();
153
+ }
154
+ modalsAction$();
155
+ });
156
+ const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
157
+ attributes: {
158
+ type: tansu.readable("button"),
159
+ "aria-label": ariaCloseButtonLabel$
160
+ },
161
+ events: {
162
+ click: () => close(modalCloseButtonClick)
163
+ }
164
+ }));
165
+ const backdropAttributeDirective = utils_directive.createAttributesDirective(() => ({
166
+ attributes: {
167
+ class: backdropClass$
168
+ }
169
+ }));
170
+ const modalAttributeDirective = utils_directive.createAttributesDirective(() => ({
171
+ attributes: {
172
+ class: className$,
173
+ tabIndex: tansu.readable("-1")
174
+ },
175
+ events: {
176
+ click: (event) => {
177
+ if (event.currentTarget === event.target && closeOnOutsideClick$()) {
178
+ close(modalOutsideClick);
179
+ }
180
+ },
181
+ keydown: (event) => {
182
+ const { key } = event;
183
+ switch (key) {
184
+ case "Escape":
185
+ close(modalCloseEscape);
186
+ event.stopPropagation();
187
+ break;
188
+ }
189
+ }
190
+ }
191
+ }));
192
+ const res = {
193
+ ...utils_stores.stateStores({
194
+ backdropHidden$,
195
+ container$,
196
+ hidden$,
197
+ transitioning$,
198
+ visible$,
199
+ modalElement$: modalTransition.stores.element$,
200
+ ariaCloseButtonLabel$,
201
+ className$,
202
+ backdropClass$,
203
+ ...stateProps
204
+ }),
205
+ directives: {
206
+ modalPortalDirective,
207
+ backdropPortalDirective,
208
+ backdropDirective: utils_directive.mergeDirectives(backdropTransition.directives.directive, backdropAttributeDirective),
209
+ modalDirective: utils_directive.mergeDirectives(
210
+ modalTransition.directives.directive,
211
+ utils_directive.bindDirectiveNoArg(services_siblingsInert.siblingsInert),
212
+ utils_directive.directiveSubscribe(action$),
213
+ modalAttributeDirective,
214
+ services_focusElement.focusElement
215
+ ),
216
+ closeButtonDirective,
217
+ dialogDirective: utils_directive.bindDirective(
218
+ utils_directive.browserDirective((dialog, visible) => {
219
+ const update = (visible2) => {
220
+ if (visible2) {
221
+ dialog.showModal();
222
+ } else {
223
+ dialog.close();
224
+ }
225
+ };
226
+ update(visible);
227
+ return {
228
+ update
229
+ };
230
+ }),
231
+ visible$
232
+ )
233
+ },
234
+ patch,
235
+ api: {
236
+ close,
237
+ async open() {
238
+ patch({ visible: true });
239
+ await promise.promiseFromStore(hidden$).promise;
240
+ return hideResult;
241
+ },
242
+ patch
243
+ }
244
+ };
245
+ return res;
246
+ }
247
+ );
248
+ exports.createModal = createModal;
249
+ exports.getModalDefaultConfig = getModalDefaultConfig;
250
+ exports.modalCloseButtonClick = modalCloseButtonClick;
251
+ exports.modalCloseEscape = modalCloseEscape;
252
+ exports.modalOutsideClick = modalOutsideClick;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@design-factory/core",
3
+ "description": "Internal package used by the Design Factory.",
4
+ "version": "21.1.0-next.1",
5
+ "type": "module",
6
+ "main": "./index.cjs",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "require": "./index.cjs",
13
+ "default": "./index.js"
14
+ },
15
+ "./components/*": {
16
+ "types": "./components/*/index.d.ts",
17
+ "require": "./components/*/index.cjs",
18
+ "default": "./components/*/index.js"
19
+ },
20
+ "./config": {
21
+ "types": "./config.d.ts",
22
+ "require": "./config.cjs",
23
+ "default": "./config.js"
24
+ },
25
+ "./types": {
26
+ "types": "./types.d.ts",
27
+ "require": "./types.cjs",
28
+ "default": "./types.js"
29
+ },
30
+ "./services/*": {
31
+ "types": "./services/*.d.ts",
32
+ "require": "./services/*.cjs",
33
+ "default": "./services/*.js"
34
+ },
35
+ "./services/transitions/*": {
36
+ "types": "./services/transitions/*.d.ts",
37
+ "require": "./services/transitions/*.cjs",
38
+ "default": "./services/transitions/*.js"
39
+ },
40
+ "./utils/*": {
41
+ "types": "./utils/*.d.ts",
42
+ "require": "./utils/*.cjs",
43
+ "default": "./utils/*.js"
44
+ }
45
+ },
46
+ "dependencies": {
47
+ "clsx": "^2.1.1"
48
+ },
49
+ "peerDependencies": {
50
+ "@amadeus-it-group/tansu": "^2.0.0",
51
+ "@floating-ui/dom": "^1.6.12",
52
+ "embla-carousel": "^8.5.2",
53
+ "esm-env": "^1.2.1"
54
+ },
55
+ "sideEffects": false
56
+ }
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ const tansu = require("@amadeus-it-group/tansu");
3
+ const utils_stores = require("./utils/stores.cjs");
4
+ const utils_writables = require("./writables-Dt68gADJ.cjs");
5
+ const utils_func = require("./utils/func.cjs");
6
+ const utils_directive = require("./directive-DyTodNPd.cjs");
7
+ const utils_widget = require("./utils/widget.cjs");
8
+ const PAGE_LINK_DEFAULT = "#";
9
+ const defaultConfig = {
10
+ page: 1,
11
+ collectionSize: 0,
12
+ pageSize: 10,
13
+ disabled: false,
14
+ directionLinks: true,
15
+ boundaryLinks: false,
16
+ onPageChange: utils_func.noop,
17
+ pagesFactory: (_page, pageCount) => {
18
+ const pages = [];
19
+ for (let i = 1; i <= pageCount; i++) {
20
+ pages.push(i);
21
+ }
22
+ return pages;
23
+ },
24
+ ariaLabel: "Page navigation",
25
+ activeLabel: "(current)",
26
+ ariaPageLabel: (processPage, pageCount) => `Page ${processPage} of ${pageCount}`,
27
+ ariaFirstLabel: "Action link for first page",
28
+ ariaPreviousLabel: "Action link for previous page",
29
+ ariaNextLabel: "Action link for next page",
30
+ ariaLastLabel: "Action link for last page",
31
+ ariaEllipsisLabel: "Ellipsis page element",
32
+ ariaLiveLabel: (currentPage) => `Current page is ${currentPage}`,
33
+ className: "",
34
+ pageLink: (_page) => PAGE_LINK_DEFAULT
35
+ };
36
+ function getPaginationDefaultConfig() {
37
+ return { ...defaultConfig };
38
+ }
39
+ const configValidator = {
40
+ page: utils_writables.typeNumber,
41
+ collectionSize: utils_writables.typeNumber,
42
+ pageSize: utils_writables.typeNumber,
43
+ disabled: utils_writables.typeBoolean,
44
+ directionLinks: utils_writables.typeBoolean,
45
+ boundaryLinks: utils_writables.typeBoolean,
46
+ onPageChange: utils_writables.typeFunction,
47
+ pagesFactory: utils_writables.typeFunction,
48
+ ariaLabel: utils_writables.typeString,
49
+ activeLabel: utils_writables.typeString,
50
+ ariaPageLabel: utils_writables.typeFunction,
51
+ ariaFirstLabel: utils_writables.typeString,
52
+ ariaPreviousLabel: utils_writables.typeString,
53
+ ariaNextLabel: utils_writables.typeString,
54
+ ariaLastLabel: utils_writables.typeString,
55
+ ariaLiveLabel: utils_writables.typeFunction,
56
+ className: utils_writables.typeString,
57
+ pageLink: utils_writables.typeFunction,
58
+ ariaEllipsisLabel: utils_writables.typeString
59
+ };
60
+ const createPagination = utils_widget.createWidgetFactory(
61
+ "pagination",
62
+ (config) => {
63
+ const [
64
+ {
65
+ // dirty inputs that need adjustment:
66
+ page$: _dirtyPage$,
67
+ // clean inputs with value validation:
68
+ collectionSize$,
69
+ pageSize$,
70
+ onPageChange$,
71
+ pagesFactory$,
72
+ ariaPageLabel$,
73
+ ariaLiveLabel$,
74
+ pageLink$,
75
+ disabled$,
76
+ ariaFirstLabel$,
77
+ ariaLastLabel$,
78
+ ariaNextLabel$,
79
+ ariaPreviousLabel$,
80
+ ...stateProps
81
+ },
82
+ patch
83
+ ] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
84
+ const pageCount$ = tansu.computed(() => {
85
+ let pageCount = Math.ceil(collectionSize$() / pageSize$());
86
+ if (!utils_writables.isNumber(pageCount) || pageCount < 1) {
87
+ pageCount = 1;
88
+ }
89
+ return pageCount;
90
+ });
91
+ const page$ = utils_stores.bindableProp(_dirtyPage$, onPageChange$, (dirtyPage) => utils_writables.clamp(dirtyPage, pageCount$(), 1));
92
+ const pages$ = tansu.computed(() => pagesFactory$()(page$(), pageCount$()));
93
+ const nextDisabled$ = tansu.computed(() => page$() === pageCount$() || disabled$());
94
+ const previousDisabled$ = tansu.computed(() => page$() === 1 || disabled$());
95
+ const pagesLabel$ = tansu.computed(() => {
96
+ const ariaPageLabel = ariaPageLabel$();
97
+ const pageCount = pageCount$();
98
+ return pages$().map((page) => ariaPageLabel(page, pageCount));
99
+ });
100
+ const pagesHrefs$ = tansu.computed(() => {
101
+ const pageLinkFactory = pageLink$();
102
+ const pageCount = pageCount$();
103
+ return Array.from({ length: pageCount }, (_, index) => pageLinkFactory(index + 1));
104
+ });
105
+ const directionsHrefs$ = tansu.computed(() => {
106
+ const pagesHrefs = pagesHrefs$();
107
+ const pageIndex = page$() - 1;
108
+ return {
109
+ previous: pagesHrefs.at(pageIndex > 0 ? pageIndex - 1 : 0),
110
+ next: pagesHrefs.at(pageIndex + 1) ?? pagesHrefs.at(-1)
111
+ };
112
+ });
113
+ const ariaLiveLabelText$ = tansu.computed(() => ariaLiveLabel$()(page$(), pageCount$()));
114
+ function handleNavigation(pageNumber, event) {
115
+ if (pagesHrefs$()[pageNumber - 1] === PAGE_LINK_DEFAULT) {
116
+ event?.preventDefault();
117
+ }
118
+ if (!event || !(event.ctrlKey || event.metaKey)) {
119
+ event?.preventDefault();
120
+ page$.set(pageNumber);
121
+ }
122
+ }
123
+ const widget = {
124
+ ...utils_stores.stateStores({
125
+ pageCount$,
126
+ page$,
127
+ pages$,
128
+ nextDisabled$,
129
+ previousDisabled$,
130
+ pagesLabel$,
131
+ pagesHrefs$,
132
+ directionsHrefs$,
133
+ disabled$,
134
+ ariaFirstLabel$,
135
+ ariaLastLabel$,
136
+ ariaNextLabel$,
137
+ ariaPreviousLabel$,
138
+ ariaLiveLabelText$,
139
+ ...stateProps
140
+ }),
141
+ patch,
142
+ api: {
143
+ /**
144
+ * Set the current page pageNumber (starting from 1)
145
+ * @param pageNumber - Current page number to set.
146
+ * Value is normalized between 1 and the number of page
147
+ */
148
+ select(pageNumber) {
149
+ page$.set(pageNumber);
150
+ },
151
+ /**
152
+ * Select the first page
153
+ */
154
+ first() {
155
+ page$.set(1);
156
+ },
157
+ /**
158
+ * Select the previous page
159
+ */
160
+ previous() {
161
+ page$.update((p) => p - 1);
162
+ },
163
+ /**
164
+ * Select the next page
165
+ */
166
+ next() {
167
+ page$.update((p) => p + 1);
168
+ },
169
+ /**
170
+ * Select the last page
171
+ */
172
+ last() {
173
+ page$.set(pageCount$());
174
+ }
175
+ },
176
+ directives: {
177
+ pageLink: utils_directive.createAttributesDirective((pageLinkContext$) => ({
178
+ events: {
179
+ click: (e) => handleNavigation(pageLinkContext$().page, e)
180
+ },
181
+ attributes: {
182
+ "aria-current": tansu.computed(() => page$() === pageLinkContext$().page ? "page" : void 0),
183
+ "aria-label": tansu.computed(() => pagesLabel$()[pageLinkContext$().page - 1]),
184
+ href: tansu.computed(() => pagesHrefs$()[pageLinkContext$().page - 1]),
185
+ tabindex: tansu.computed(() => disabled$() ? "-1" : void 0),
186
+ "aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0)
187
+ },
188
+ classNames: {
189
+ "au-page": utils_stores.true$
190
+ }
191
+ })),
192
+ pageFirst: utils_directive.createAttributesDirective(() => ({
193
+ events: {
194
+ click: (e) => handleNavigation(1, e)
195
+ },
196
+ attributes: {
197
+ "aria-label": ariaFirstLabel$,
198
+ href: tansu.computed(() => pagesHrefs$()[0]),
199
+ tabindex: tansu.computed(() => previousDisabled$() ? "-1" : void 0),
200
+ "aria-disabled": tansu.computed(() => previousDisabled$() ? "true" : void 0)
201
+ },
202
+ classNames: {
203
+ "au-first": utils_stores.true$
204
+ }
205
+ })),
206
+ pagePrev: utils_directive.createAttributesDirective(() => ({
207
+ events: {
208
+ click: (e) => handleNavigation(page$() - 1, e)
209
+ },
210
+ attributes: {
211
+ "aria-label": ariaPreviousLabel$,
212
+ href: tansu.computed(() => directionsHrefs$().previous),
213
+ tabindex: tansu.computed(() => previousDisabled$() ? "-1" : void 0),
214
+ "aria-disabled": tansu.computed(() => previousDisabled$() ? "true" : void 0)
215
+ },
216
+ classNames: {
217
+ "au-previous": utils_stores.true$
218
+ }
219
+ })),
220
+ pageNext: utils_directive.createAttributesDirective(() => ({
221
+ events: {
222
+ click: (e) => handleNavigation(page$() + 1, e)
223
+ },
224
+ attributes: {
225
+ "aria-label": ariaNextLabel$,
226
+ href: tansu.computed(() => directionsHrefs$().next),
227
+ tabindex: tansu.computed(() => nextDisabled$() ? "-1" : void 0),
228
+ "aria-disabled": tansu.computed(() => nextDisabled$() ? "true" : void 0)
229
+ },
230
+ classNames: {
231
+ "au-next": utils_stores.true$
232
+ }
233
+ })),
234
+ pageLast: utils_directive.createAttributesDirective(() => ({
235
+ events: {
236
+ click: (e) => handleNavigation(pageCount$(), e)
237
+ },
238
+ attributes: {
239
+ "aria-label": ariaLastLabel$,
240
+ href: tansu.computed(() => pagesHrefs$().at(-1)),
241
+ tabindex: tansu.computed(() => nextDisabled$() ? "-1" : void 0),
242
+ "aria-disabled": tansu.computed(() => nextDisabled$() ? "true" : void 0)
243
+ },
244
+ classNames: {
245
+ "au-last": utils_stores.true$
246
+ }
247
+ }))
248
+ }
249
+ };
250
+ return widget;
251
+ }
252
+ );
253
+ exports.createPagination = createPagination;
254
+ exports.getPaginationDefaultConfig = getPaginationDefaultConfig;