@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
package/package.json
CHANGED
|
@@ -1,64 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnos-ui/core",
|
|
3
3
|
"description": "Framework-agnostic headless widget library.",
|
|
4
|
-
"
|
|
5
|
-
"headless",
|
|
6
|
-
"agnostic",
|
|
7
|
-
"components",
|
|
8
|
-
"widgets",
|
|
9
|
-
"accordion",
|
|
10
|
-
"alert",
|
|
11
|
-
"modal",
|
|
12
|
-
"pagination",
|
|
13
|
-
"rating",
|
|
14
|
-
"slider"
|
|
15
|
-
],
|
|
4
|
+
"version": "0.3.0",
|
|
16
5
|
"type": "module",
|
|
17
|
-
"main": "./index.
|
|
6
|
+
"main": "./index.cjs",
|
|
18
7
|
"module": "./index.js",
|
|
19
8
|
"types": "./index.d.ts",
|
|
20
9
|
"exports": {
|
|
21
10
|
".": {
|
|
22
11
|
"types": "./index.d.ts",
|
|
12
|
+
"require": "./index.cjs",
|
|
23
13
|
"default": "./index.js"
|
|
24
14
|
},
|
|
25
15
|
"./components/*": {
|
|
26
|
-
"types": "./components
|
|
27
|
-
"
|
|
16
|
+
"types": "./components/*/index.d.ts",
|
|
17
|
+
"require": "./components/*/index.cjs",
|
|
18
|
+
"default": "./components/*/index.js"
|
|
28
19
|
},
|
|
29
20
|
"./config": {
|
|
30
21
|
"types": "./config.d.ts",
|
|
22
|
+
"require": "./config.cjs",
|
|
31
23
|
"default": "./config.js"
|
|
32
24
|
},
|
|
33
25
|
"./types": {
|
|
34
26
|
"types": "./types.d.ts",
|
|
27
|
+
"require": "./types.cjs",
|
|
35
28
|
"default": "./types.js"
|
|
36
29
|
},
|
|
37
30
|
"./services/*": {
|
|
38
31
|
"types": "./services/*.d.ts",
|
|
32
|
+
"require": "./services/*.cjs",
|
|
39
33
|
"default": "./services/*.js"
|
|
40
34
|
},
|
|
41
35
|
"./services/transitions/*": {
|
|
42
36
|
"types": "./services/transitions/*.d.ts",
|
|
37
|
+
"require": "./services/transitions/*.cjs",
|
|
43
38
|
"default": "./services/transitions/*.js"
|
|
44
39
|
},
|
|
45
40
|
"./utils/*": {
|
|
46
41
|
"types": "./utils/*.d.ts",
|
|
42
|
+
"require": "./utils/*.cjs",
|
|
47
43
|
"default": "./utils/*.js"
|
|
48
44
|
}
|
|
49
45
|
},
|
|
50
46
|
"peerDependencies": {
|
|
51
47
|
"@amadeus-it-group/tansu": "*",
|
|
52
|
-
"@floating-ui/dom": "*"
|
|
48
|
+
"@floating-ui/dom": "*",
|
|
49
|
+
"esm-env": "*"
|
|
53
50
|
},
|
|
54
51
|
"sideEffects": false,
|
|
55
|
-
"version": "0.2.0",
|
|
56
52
|
"homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/",
|
|
57
53
|
"bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
|
|
58
54
|
"license": "MIT",
|
|
59
55
|
"repository": {
|
|
60
56
|
"type": "git",
|
|
61
|
-
"url": "https://github.com/AmadeusITGroup/AgnosUI.git",
|
|
57
|
+
"url": "git+https://github.com/AmadeusITGroup/AgnosUI.git",
|
|
62
58
|
"directory": "core"
|
|
63
|
-
}
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"headless",
|
|
62
|
+
"AgnosUI",
|
|
63
|
+
"accordion",
|
|
64
|
+
"alert",
|
|
65
|
+
"components",
|
|
66
|
+
"modal",
|
|
67
|
+
"pagination",
|
|
68
|
+
"progressbar",
|
|
69
|
+
"rating",
|
|
70
|
+
"slider",
|
|
71
|
+
"toast",
|
|
72
|
+
"widgets"
|
|
73
|
+
]
|
|
64
74
|
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { computed } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { INVALID_VALUE } from "./types.js";
|
|
3
|
+
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";
|
|
5
|
+
import { n as noop } from "./func-DR0n-ShK.js";
|
|
6
|
+
import { n as createAttributesDirective } from "./directive-DCYlDznf.js";
|
|
7
|
+
const PAGE_LINK_DEFAULT = "#";
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
page: 1,
|
|
10
|
+
collectionSize: 0,
|
|
11
|
+
pageSize: 10,
|
|
12
|
+
disabled: false,
|
|
13
|
+
directionLinks: true,
|
|
14
|
+
boundaryLinks: false,
|
|
15
|
+
size: null,
|
|
16
|
+
onPageChange: 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, pageCount) => `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: typeNumber,
|
|
41
|
+
collectionSize: typeNumber,
|
|
42
|
+
pageSize: typeNumber,
|
|
43
|
+
disabled: typeBoolean,
|
|
44
|
+
directionLinks: typeBoolean,
|
|
45
|
+
boundaryLinks: typeBoolean,
|
|
46
|
+
size: { normalizeValue: (value) => value === "lg" || value === "sm" || value === null ? value : INVALID_VALUE },
|
|
47
|
+
onPageChange: typeFunction,
|
|
48
|
+
pagesFactory: typeFunction,
|
|
49
|
+
ariaLabel: typeString,
|
|
50
|
+
activeLabel: typeString,
|
|
51
|
+
ariaPageLabel: typeFunction,
|
|
52
|
+
ariaFirstLabel: typeString,
|
|
53
|
+
ariaPreviousLabel: typeString,
|
|
54
|
+
ariaNextLabel: typeString,
|
|
55
|
+
ariaLastLabel: typeString,
|
|
56
|
+
ariaLiveLabel: typeFunction,
|
|
57
|
+
className: typeString,
|
|
58
|
+
pageLink: typeFunction
|
|
59
|
+
};
|
|
60
|
+
function createPagination(config) {
|
|
61
|
+
const [
|
|
62
|
+
{
|
|
63
|
+
// dirty inputs that need adjustment:
|
|
64
|
+
page$: _dirtyPage$,
|
|
65
|
+
// clean inputs with value validation:
|
|
66
|
+
collectionSize$,
|
|
67
|
+
pageSize$,
|
|
68
|
+
onPageChange$,
|
|
69
|
+
pagesFactory$,
|
|
70
|
+
ariaPageLabel$,
|
|
71
|
+
ariaLiveLabel$,
|
|
72
|
+
pageLink$,
|
|
73
|
+
disabled$,
|
|
74
|
+
ariaFirstLabel$,
|
|
75
|
+
ariaLastLabel$,
|
|
76
|
+
ariaNextLabel$,
|
|
77
|
+
ariaPreviousLabel$,
|
|
78
|
+
...stateProps
|
|
79
|
+
},
|
|
80
|
+
patch
|
|
81
|
+
] = writablesForProps(defaultConfig, config, configValidator);
|
|
82
|
+
const pageCount$ = computed(() => {
|
|
83
|
+
let pageCount = Math.ceil(collectionSize$() / pageSize$());
|
|
84
|
+
if (!isNumber(pageCount) || pageCount < 1) {
|
|
85
|
+
pageCount = 1;
|
|
86
|
+
}
|
|
87
|
+
return pageCount;
|
|
88
|
+
});
|
|
89
|
+
const page$ = bindableProp(_dirtyPage$, onPageChange$, (dirtyPage) => clamp(dirtyPage, pageCount$(), 1));
|
|
90
|
+
const pages$ = computed(() => pagesFactory$()(page$(), pageCount$()));
|
|
91
|
+
const nextDisabled$ = computed(() => page$() === pageCount$() || disabled$());
|
|
92
|
+
const previousDisabled$ = computed(() => page$() === 1 || disabled$());
|
|
93
|
+
const pagesLabel$ = computed(() => {
|
|
94
|
+
const ariaPageLabel = ariaPageLabel$();
|
|
95
|
+
const pageCount = pageCount$();
|
|
96
|
+
return pages$().map((page) => ariaPageLabel(page, pageCount));
|
|
97
|
+
});
|
|
98
|
+
const pagesHrefs$ = computed(() => {
|
|
99
|
+
const pageLinkFactory = pageLink$();
|
|
100
|
+
const pageCount = pageCount$();
|
|
101
|
+
return Array.from({ length: pageCount }, (_, index) => pageLinkFactory(index + 1));
|
|
102
|
+
});
|
|
103
|
+
const directionsHrefs$ = computed(() => {
|
|
104
|
+
const pagesHrefs = pagesHrefs$();
|
|
105
|
+
const pageIndex = page$() - 1;
|
|
106
|
+
return {
|
|
107
|
+
previous: pagesHrefs.at(pageIndex > 0 ? pageIndex - 1 : 0),
|
|
108
|
+
next: pagesHrefs.at(pageIndex + 1) ?? pagesHrefs.at(-1)
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
const ariaLiveLabelText$ = computed(() => ariaLiveLabel$()(page$(), pageCount$()));
|
|
112
|
+
function handleNavigation(pageNumber, event, pageNavigationHandler) {
|
|
113
|
+
if (pagesHrefs$()[pageNumber - 1] === PAGE_LINK_DEFAULT) {
|
|
114
|
+
event == null ? void 0 : event.preventDefault();
|
|
115
|
+
}
|
|
116
|
+
if (!event || !(event.ctrlKey || event.metaKey)) {
|
|
117
|
+
event == null ? void 0 : event.preventDefault();
|
|
118
|
+
if (pageNavigationHandler) {
|
|
119
|
+
page$.update(pageNavigationHandler);
|
|
120
|
+
} else {
|
|
121
|
+
page$.set(pageNumber);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const widget = {
|
|
126
|
+
...stateStores({
|
|
127
|
+
pageCount$,
|
|
128
|
+
page$,
|
|
129
|
+
pages$,
|
|
130
|
+
nextDisabled$,
|
|
131
|
+
previousDisabled$,
|
|
132
|
+
pagesLabel$,
|
|
133
|
+
pagesHrefs$,
|
|
134
|
+
directionsHrefs$,
|
|
135
|
+
disabled$,
|
|
136
|
+
ariaFirstLabel$,
|
|
137
|
+
ariaLastLabel$,
|
|
138
|
+
ariaNextLabel$,
|
|
139
|
+
ariaPreviousLabel$,
|
|
140
|
+
ariaLiveLabelText$,
|
|
141
|
+
...stateProps
|
|
142
|
+
}),
|
|
143
|
+
patch,
|
|
144
|
+
actions: {
|
|
145
|
+
/**
|
|
146
|
+
* Set the current page pageNumber (starting from 1)
|
|
147
|
+
* @param pageNumber - Current page number to set.
|
|
148
|
+
* Value is normalized between 1 and the number of page
|
|
149
|
+
* @param event UI event that triggered the select
|
|
150
|
+
*/
|
|
151
|
+
select(pageNumber, event) {
|
|
152
|
+
handleNavigation(pageNumber, event);
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Select the first page
|
|
156
|
+
* @param event Event triggering the action
|
|
157
|
+
*/
|
|
158
|
+
first(event) {
|
|
159
|
+
handleNavigation(1, event);
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* Select the previous page
|
|
163
|
+
* @param event Event triggering the action
|
|
164
|
+
*/
|
|
165
|
+
previous(event) {
|
|
166
|
+
handleNavigation(page$() - 1, event, (page) => page - 1);
|
|
167
|
+
},
|
|
168
|
+
/**
|
|
169
|
+
* Select the next page
|
|
170
|
+
* @param event Event triggering the action
|
|
171
|
+
*/
|
|
172
|
+
next(event) {
|
|
173
|
+
handleNavigation(page$() + 1, event, (page) => page + 1);
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Select the last page
|
|
177
|
+
* @param event Event triggering the action
|
|
178
|
+
*/
|
|
179
|
+
last(event) {
|
|
180
|
+
handleNavigation(pageCount$(), event);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
api: {},
|
|
184
|
+
directives: {
|
|
185
|
+
pageLink: createAttributesDirective((pageLinkContext$) => ({
|
|
186
|
+
events: {
|
|
187
|
+
click: (e) => widget.actions.select(pageLinkContext$().page, e)
|
|
188
|
+
},
|
|
189
|
+
attributes: {
|
|
190
|
+
"aria-current": computed(() => page$() === pageLinkContext$().page ? "page" : void 0),
|
|
191
|
+
"aria-label": computed(() => pagesLabel$()[pageLinkContext$().page - 1]),
|
|
192
|
+
href: computed(() => pagesHrefs$()[pageLinkContext$().page - 1]),
|
|
193
|
+
tabindex: computed(() => disabled$() ? "-1" : void 0),
|
|
194
|
+
"aria-disabled": computed(() => disabled$() ? "true" : void 0)
|
|
195
|
+
},
|
|
196
|
+
classNames: {
|
|
197
|
+
"au-page": true
|
|
198
|
+
}
|
|
199
|
+
})),
|
|
200
|
+
pageFirst: createAttributesDirective(() => ({
|
|
201
|
+
events: {
|
|
202
|
+
click: (e) => widget.actions.first(e)
|
|
203
|
+
},
|
|
204
|
+
attributes: {
|
|
205
|
+
"aria-label": ariaFirstLabel$,
|
|
206
|
+
href: computed(() => pagesHrefs$()[0]),
|
|
207
|
+
tabindex: computed(() => previousDisabled$() ? "-1" : void 0),
|
|
208
|
+
"aria-disabled": computed(() => previousDisabled$() ? "true" : void 0)
|
|
209
|
+
},
|
|
210
|
+
classNames: {
|
|
211
|
+
"au-first": true
|
|
212
|
+
}
|
|
213
|
+
})),
|
|
214
|
+
pagePrev: createAttributesDirective(() => ({
|
|
215
|
+
events: {
|
|
216
|
+
click: (e) => widget.actions.previous(e)
|
|
217
|
+
},
|
|
218
|
+
attributes: {
|
|
219
|
+
"aria-label": ariaPreviousLabel$,
|
|
220
|
+
href: computed(() => directionsHrefs$().previous),
|
|
221
|
+
tabindex: computed(() => previousDisabled$() ? "-1" : void 0),
|
|
222
|
+
"aria-disabled": computed(() => previousDisabled$() ? "true" : void 0)
|
|
223
|
+
},
|
|
224
|
+
classNames: {
|
|
225
|
+
"au-previous": true
|
|
226
|
+
}
|
|
227
|
+
})),
|
|
228
|
+
pageNext: createAttributesDirective(() => ({
|
|
229
|
+
events: {
|
|
230
|
+
click: (e) => widget.actions.next(e)
|
|
231
|
+
},
|
|
232
|
+
attributes: {
|
|
233
|
+
"aria-label": ariaNextLabel$,
|
|
234
|
+
href: computed(() => directionsHrefs$().next),
|
|
235
|
+
tabindex: computed(() => nextDisabled$() ? "-1" : void 0),
|
|
236
|
+
"aria-disabled": computed(() => nextDisabled$() ? "true" : void 0)
|
|
237
|
+
},
|
|
238
|
+
classNames: {
|
|
239
|
+
"au-next": true
|
|
240
|
+
}
|
|
241
|
+
})),
|
|
242
|
+
pageLast: createAttributesDirective(() => ({
|
|
243
|
+
events: {
|
|
244
|
+
click: (e) => widget.actions.last(e)
|
|
245
|
+
},
|
|
246
|
+
attributes: {
|
|
247
|
+
"aria-label": ariaLastLabel$,
|
|
248
|
+
href: computed(() => pagesHrefs$().at(-1)),
|
|
249
|
+
tabindex: computed(() => nextDisabled$() ? "-1" : void 0),
|
|
250
|
+
"aria-disabled": computed(() => nextDisabled$() ? "true" : void 0)
|
|
251
|
+
},
|
|
252
|
+
classNames: {
|
|
253
|
+
"au-last": true
|
|
254
|
+
}
|
|
255
|
+
}))
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
return widget;
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
createPagination as c,
|
|
262
|
+
getPaginationDefaultConfig as g
|
|
263
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
3
|
+
const types = require("./types.cjs");
|
|
4
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
5
|
+
const utils_writables = require("./writables-D46sFgGK.cjs");
|
|
6
|
+
const func = require("./func-Qd3cD9a3.cjs");
|
|
7
|
+
const utils_directive = require("./directive-BTSEYLF3.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
|
+
size: null,
|
|
17
|
+
onPageChange: func.noop,
|
|
18
|
+
pagesFactory: (_page, pageCount) => {
|
|
19
|
+
const pages = [];
|
|
20
|
+
for (let i = 1; i <= pageCount; i++) {
|
|
21
|
+
pages.push(i);
|
|
22
|
+
}
|
|
23
|
+
return pages;
|
|
24
|
+
},
|
|
25
|
+
ariaLabel: "Page navigation",
|
|
26
|
+
activeLabel: "(current)",
|
|
27
|
+
ariaPageLabel: (processPage, pageCount) => `Page ${processPage} of ${pageCount}`,
|
|
28
|
+
ariaFirstLabel: "Action link for first page",
|
|
29
|
+
ariaPreviousLabel: "Action link for previous page",
|
|
30
|
+
ariaNextLabel: "Action link for next page",
|
|
31
|
+
ariaLastLabel: "Action link for last page",
|
|
32
|
+
ariaEllipsisLabel: "Ellipsis page element",
|
|
33
|
+
ariaLiveLabel: (currentPage, pageCount) => `Current page is ${currentPage}`,
|
|
34
|
+
className: "",
|
|
35
|
+
pageLink: (_page) => PAGE_LINK_DEFAULT
|
|
36
|
+
};
|
|
37
|
+
function getPaginationDefaultConfig() {
|
|
38
|
+
return { ...defaultConfig };
|
|
39
|
+
}
|
|
40
|
+
const configValidator = {
|
|
41
|
+
page: utils_writables.typeNumber,
|
|
42
|
+
collectionSize: utils_writables.typeNumber,
|
|
43
|
+
pageSize: utils_writables.typeNumber,
|
|
44
|
+
disabled: utils_writables.typeBoolean,
|
|
45
|
+
directionLinks: utils_writables.typeBoolean,
|
|
46
|
+
boundaryLinks: utils_writables.typeBoolean,
|
|
47
|
+
size: { normalizeValue: (value) => value === "lg" || value === "sm" || value === null ? value : types.INVALID_VALUE },
|
|
48
|
+
onPageChange: utils_writables.typeFunction,
|
|
49
|
+
pagesFactory: utils_writables.typeFunction,
|
|
50
|
+
ariaLabel: utils_writables.typeString,
|
|
51
|
+
activeLabel: utils_writables.typeString,
|
|
52
|
+
ariaPageLabel: utils_writables.typeFunction,
|
|
53
|
+
ariaFirstLabel: utils_writables.typeString,
|
|
54
|
+
ariaPreviousLabel: utils_writables.typeString,
|
|
55
|
+
ariaNextLabel: utils_writables.typeString,
|
|
56
|
+
ariaLastLabel: utils_writables.typeString,
|
|
57
|
+
ariaLiveLabel: utils_writables.typeFunction,
|
|
58
|
+
className: utils_writables.typeString,
|
|
59
|
+
pageLink: utils_writables.typeFunction
|
|
60
|
+
};
|
|
61
|
+
function createPagination(config) {
|
|
62
|
+
const [
|
|
63
|
+
{
|
|
64
|
+
// dirty inputs that need adjustment:
|
|
65
|
+
page$: _dirtyPage$,
|
|
66
|
+
// clean inputs with value validation:
|
|
67
|
+
collectionSize$,
|
|
68
|
+
pageSize$,
|
|
69
|
+
onPageChange$,
|
|
70
|
+
pagesFactory$,
|
|
71
|
+
ariaPageLabel$,
|
|
72
|
+
ariaLiveLabel$,
|
|
73
|
+
pageLink$,
|
|
74
|
+
disabled$,
|
|
75
|
+
ariaFirstLabel$,
|
|
76
|
+
ariaLastLabel$,
|
|
77
|
+
ariaNextLabel$,
|
|
78
|
+
ariaPreviousLabel$,
|
|
79
|
+
...stateProps
|
|
80
|
+
},
|
|
81
|
+
patch
|
|
82
|
+
] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
|
|
83
|
+
const pageCount$ = tansu.computed(() => {
|
|
84
|
+
let pageCount = Math.ceil(collectionSize$() / pageSize$());
|
|
85
|
+
if (!utils_writables.isNumber(pageCount) || pageCount < 1) {
|
|
86
|
+
pageCount = 1;
|
|
87
|
+
}
|
|
88
|
+
return pageCount;
|
|
89
|
+
});
|
|
90
|
+
const page$ = utils_stores.bindableProp(_dirtyPage$, onPageChange$, (dirtyPage) => utils_writables.clamp(dirtyPage, pageCount$(), 1));
|
|
91
|
+
const pages$ = tansu.computed(() => pagesFactory$()(page$(), pageCount$()));
|
|
92
|
+
const nextDisabled$ = tansu.computed(() => page$() === pageCount$() || disabled$());
|
|
93
|
+
const previousDisabled$ = tansu.computed(() => page$() === 1 || disabled$());
|
|
94
|
+
const pagesLabel$ = tansu.computed(() => {
|
|
95
|
+
const ariaPageLabel = ariaPageLabel$();
|
|
96
|
+
const pageCount = pageCount$();
|
|
97
|
+
return pages$().map((page) => ariaPageLabel(page, pageCount));
|
|
98
|
+
});
|
|
99
|
+
const pagesHrefs$ = tansu.computed(() => {
|
|
100
|
+
const pageLinkFactory = pageLink$();
|
|
101
|
+
const pageCount = pageCount$();
|
|
102
|
+
return Array.from({ length: pageCount }, (_, index) => pageLinkFactory(index + 1));
|
|
103
|
+
});
|
|
104
|
+
const directionsHrefs$ = tansu.computed(() => {
|
|
105
|
+
const pagesHrefs = pagesHrefs$();
|
|
106
|
+
const pageIndex = page$() - 1;
|
|
107
|
+
return {
|
|
108
|
+
previous: pagesHrefs.at(pageIndex > 0 ? pageIndex - 1 : 0),
|
|
109
|
+
next: pagesHrefs.at(pageIndex + 1) ?? pagesHrefs.at(-1)
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
const ariaLiveLabelText$ = tansu.computed(() => ariaLiveLabel$()(page$(), pageCount$()));
|
|
113
|
+
function handleNavigation(pageNumber, event, pageNavigationHandler) {
|
|
114
|
+
if (pagesHrefs$()[pageNumber - 1] === PAGE_LINK_DEFAULT) {
|
|
115
|
+
event == null ? void 0 : event.preventDefault();
|
|
116
|
+
}
|
|
117
|
+
if (!event || !(event.ctrlKey || event.metaKey)) {
|
|
118
|
+
event == null ? void 0 : event.preventDefault();
|
|
119
|
+
if (pageNavigationHandler) {
|
|
120
|
+
page$.update(pageNavigationHandler);
|
|
121
|
+
} else {
|
|
122
|
+
page$.set(pageNumber);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const widget = {
|
|
127
|
+
...utils_stores.stateStores({
|
|
128
|
+
pageCount$,
|
|
129
|
+
page$,
|
|
130
|
+
pages$,
|
|
131
|
+
nextDisabled$,
|
|
132
|
+
previousDisabled$,
|
|
133
|
+
pagesLabel$,
|
|
134
|
+
pagesHrefs$,
|
|
135
|
+
directionsHrefs$,
|
|
136
|
+
disabled$,
|
|
137
|
+
ariaFirstLabel$,
|
|
138
|
+
ariaLastLabel$,
|
|
139
|
+
ariaNextLabel$,
|
|
140
|
+
ariaPreviousLabel$,
|
|
141
|
+
ariaLiveLabelText$,
|
|
142
|
+
...stateProps
|
|
143
|
+
}),
|
|
144
|
+
patch,
|
|
145
|
+
actions: {
|
|
146
|
+
/**
|
|
147
|
+
* Set the current page pageNumber (starting from 1)
|
|
148
|
+
* @param pageNumber - Current page number to set.
|
|
149
|
+
* Value is normalized between 1 and the number of page
|
|
150
|
+
* @param event UI event that triggered the select
|
|
151
|
+
*/
|
|
152
|
+
select(pageNumber, event) {
|
|
153
|
+
handleNavigation(pageNumber, event);
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Select the first page
|
|
157
|
+
* @param event Event triggering the action
|
|
158
|
+
*/
|
|
159
|
+
first(event) {
|
|
160
|
+
handleNavigation(1, event);
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Select the previous page
|
|
164
|
+
* @param event Event triggering the action
|
|
165
|
+
*/
|
|
166
|
+
previous(event) {
|
|
167
|
+
handleNavigation(page$() - 1, event, (page) => page - 1);
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Select the next page
|
|
171
|
+
* @param event Event triggering the action
|
|
172
|
+
*/
|
|
173
|
+
next(event) {
|
|
174
|
+
handleNavigation(page$() + 1, event, (page) => page + 1);
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Select the last page
|
|
178
|
+
* @param event Event triggering the action
|
|
179
|
+
*/
|
|
180
|
+
last(event) {
|
|
181
|
+
handleNavigation(pageCount$(), event);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
api: {},
|
|
185
|
+
directives: {
|
|
186
|
+
pageLink: utils_directive.createAttributesDirective((pageLinkContext$) => ({
|
|
187
|
+
events: {
|
|
188
|
+
click: (e) => widget.actions.select(pageLinkContext$().page, e)
|
|
189
|
+
},
|
|
190
|
+
attributes: {
|
|
191
|
+
"aria-current": tansu.computed(() => page$() === pageLinkContext$().page ? "page" : void 0),
|
|
192
|
+
"aria-label": tansu.computed(() => pagesLabel$()[pageLinkContext$().page - 1]),
|
|
193
|
+
href: tansu.computed(() => pagesHrefs$()[pageLinkContext$().page - 1]),
|
|
194
|
+
tabindex: tansu.computed(() => disabled$() ? "-1" : void 0),
|
|
195
|
+
"aria-disabled": tansu.computed(() => disabled$() ? "true" : void 0)
|
|
196
|
+
},
|
|
197
|
+
classNames: {
|
|
198
|
+
"au-page": true
|
|
199
|
+
}
|
|
200
|
+
})),
|
|
201
|
+
pageFirst: utils_directive.createAttributesDirective(() => ({
|
|
202
|
+
events: {
|
|
203
|
+
click: (e) => widget.actions.first(e)
|
|
204
|
+
},
|
|
205
|
+
attributes: {
|
|
206
|
+
"aria-label": ariaFirstLabel$,
|
|
207
|
+
href: tansu.computed(() => pagesHrefs$()[0]),
|
|
208
|
+
tabindex: tansu.computed(() => previousDisabled$() ? "-1" : void 0),
|
|
209
|
+
"aria-disabled": tansu.computed(() => previousDisabled$() ? "true" : void 0)
|
|
210
|
+
},
|
|
211
|
+
classNames: {
|
|
212
|
+
"au-first": true
|
|
213
|
+
}
|
|
214
|
+
})),
|
|
215
|
+
pagePrev: utils_directive.createAttributesDirective(() => ({
|
|
216
|
+
events: {
|
|
217
|
+
click: (e) => widget.actions.previous(e)
|
|
218
|
+
},
|
|
219
|
+
attributes: {
|
|
220
|
+
"aria-label": ariaPreviousLabel$,
|
|
221
|
+
href: tansu.computed(() => directionsHrefs$().previous),
|
|
222
|
+
tabindex: tansu.computed(() => previousDisabled$() ? "-1" : void 0),
|
|
223
|
+
"aria-disabled": tansu.computed(() => previousDisabled$() ? "true" : void 0)
|
|
224
|
+
},
|
|
225
|
+
classNames: {
|
|
226
|
+
"au-previous": true
|
|
227
|
+
}
|
|
228
|
+
})),
|
|
229
|
+
pageNext: utils_directive.createAttributesDirective(() => ({
|
|
230
|
+
events: {
|
|
231
|
+
click: (e) => widget.actions.next(e)
|
|
232
|
+
},
|
|
233
|
+
attributes: {
|
|
234
|
+
"aria-label": ariaNextLabel$,
|
|
235
|
+
href: tansu.computed(() => directionsHrefs$().next),
|
|
236
|
+
tabindex: tansu.computed(() => nextDisabled$() ? "-1" : void 0),
|
|
237
|
+
"aria-disabled": tansu.computed(() => nextDisabled$() ? "true" : void 0)
|
|
238
|
+
},
|
|
239
|
+
classNames: {
|
|
240
|
+
"au-next": true
|
|
241
|
+
}
|
|
242
|
+
})),
|
|
243
|
+
pageLast: utils_directive.createAttributesDirective(() => ({
|
|
244
|
+
events: {
|
|
245
|
+
click: (e) => widget.actions.last(e)
|
|
246
|
+
},
|
|
247
|
+
attributes: {
|
|
248
|
+
"aria-label": ariaLastLabel$,
|
|
249
|
+
href: tansu.computed(() => pagesHrefs$().at(-1)),
|
|
250
|
+
tabindex: tansu.computed(() => nextDisabled$() ? "-1" : void 0),
|
|
251
|
+
"aria-disabled": tansu.computed(() => nextDisabled$() ? "true" : void 0)
|
|
252
|
+
},
|
|
253
|
+
classNames: {
|
|
254
|
+
"au-last": true
|
|
255
|
+
}
|
|
256
|
+
}))
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
return widget;
|
|
260
|
+
}
|
|
261
|
+
exports.createPagination = createPagination;
|
|
262
|
+
exports.getPaginationDefaultConfig = getPaginationDefaultConfig;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const utils_writables = require("./writables-D46sFgGK.cjs");
|
|
3
|
+
const utils_stores = require("./utils/stores.cjs");
|
|
4
|
+
const tansu = require("@amadeus-it-group/tansu");
|
|
5
|
+
const utils_directive = require("./directive-BTSEYLF3.cjs");
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
min: 0,
|
|
8
|
+
max: 100,
|
|
9
|
+
value: 0,
|
|
10
|
+
ariaLabel: "Progressbar",
|
|
11
|
+
className: "",
|
|
12
|
+
ariaValueTextFn: () => void 0
|
|
13
|
+
};
|
|
14
|
+
function getProgressbarDefaultConfig() {
|
|
15
|
+
return { ...defaultConfig };
|
|
16
|
+
}
|
|
17
|
+
const configValidator = {
|
|
18
|
+
min: utils_writables.typeNumber,
|
|
19
|
+
max: utils_writables.typeNumber,
|
|
20
|
+
value: utils_writables.typeNumber,
|
|
21
|
+
ariaLabel: utils_writables.typeString,
|
|
22
|
+
className: utils_writables.typeString,
|
|
23
|
+
ariaValueTextFn: utils_writables.typeFunction
|
|
24
|
+
};
|
|
25
|
+
function createProgressbar(config) {
|
|
26
|
+
const [
|
|
27
|
+
{
|
|
28
|
+
// dirty inputs that need adjustment:
|
|
29
|
+
max$: _dirtyMaximum$,
|
|
30
|
+
value$: _dirtyValue$,
|
|
31
|
+
// clean inputs
|
|
32
|
+
min$,
|
|
33
|
+
ariaValueTextFn$,
|
|
34
|
+
ariaLabel$,
|
|
35
|
+
...stateProps
|
|
36
|
+
},
|
|
37
|
+
patch
|
|
38
|
+
] = utils_stores.writablesForProps(defaultConfig, config, configValidator);
|
|
39
|
+
const max$ = tansu.computed(() => Math.max(min$(), _dirtyMaximum$()));
|
|
40
|
+
const value$ = tansu.computed(() => utils_writables.clamp(_dirtyValue$(), max$(), min$()));
|
|
41
|
+
const percentage$ = tansu.computed(() => {
|
|
42
|
+
const max = max$();
|
|
43
|
+
const min = min$();
|
|
44
|
+
if (max > min) {
|
|
45
|
+
return utils_writables.clamp((value$() - min) * 100 / (max - min), 100, 0);
|
|
46
|
+
} else {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const started$ = tansu.computed(() => value$() > min$());
|
|
51
|
+
const finished$ = tansu.computed(() => value$() === max$());
|
|
52
|
+
const ariaValueText$ = tansu.computed(() => ariaValueTextFn$()(value$(), min$(), max$()));
|
|
53
|
+
return {
|
|
54
|
+
...utils_stores.stateStores({
|
|
55
|
+
min$,
|
|
56
|
+
max$,
|
|
57
|
+
value$,
|
|
58
|
+
percentage$,
|
|
59
|
+
started$,
|
|
60
|
+
finished$,
|
|
61
|
+
ariaValueText$,
|
|
62
|
+
ariaLabel$,
|
|
63
|
+
...stateProps
|
|
64
|
+
}),
|
|
65
|
+
patch,
|
|
66
|
+
api: {},
|
|
67
|
+
directives: {
|
|
68
|
+
ariaDirective: utils_directive.createAttributesDirective(() => ({
|
|
69
|
+
attributes: {
|
|
70
|
+
role: "progressbar",
|
|
71
|
+
"aria-label": ariaLabel$,
|
|
72
|
+
"aria-valuenow": value$,
|
|
73
|
+
"aria-valuemin": min$,
|
|
74
|
+
"aria-valuemax": max$,
|
|
75
|
+
"aria-valuetext": ariaValueText$
|
|
76
|
+
}
|
|
77
|
+
}))
|
|
78
|
+
},
|
|
79
|
+
actions: {}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
exports.createProgressbar = createProgressbar;
|
|
83
|
+
exports.getProgressbarDefaultConfig = getProgressbarDefaultConfig;
|