@redvars/peacock 3.15.0 → 3.17.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/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.js +19 -19
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/card-content.js +8 -7
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +142 -98
- package/dist/card.js.map +1 -1
- package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
- package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
- package/dist/chart-area.js +78 -0
- package/dist/chart-area.js.map +1 -0
- package/dist/chart-bar.js +283 -213
- package/dist/chart-bar.js.map +1 -1
- package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
- package/dist/chart-base-C2qRMF48.js.map +1 -0
- package/dist/chart-doughnut.js +55 -287
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +626 -0
- package/dist/chart-line.js.map +1 -0
- package/dist/chart-pie.js +637 -195
- package/dist/chart-pie.js.map +1 -1
- package/dist/code-editor.js +704 -131
- package/dist/code-editor.js.map +1 -1
- package/dist/code-group.js +188 -0
- package/dist/code-group.js.map +1 -0
- package/dist/code-highlighter.js +895 -257
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +2278 -677
- package/dist/custom-elements.json +13962 -3690
- package/dist/image.js +5 -1
- package/dist/image.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/loader-full.js +1 -1
- package/dist/loader.js +9 -3
- package/dist/loader.js.map +1 -1
- package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
- package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
- package/dist/pagination.js +408 -110
- package/dist/pagination.js.map +1 -1
- package/dist/path-CJ0Arqcy.js +166 -0
- package/dist/path-CJ0Arqcy.js.map +1 -0
- package/dist/snackbar.js +89 -34
- package/dist/snackbar.js.map +1 -1
- package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
- package/dist/src/__internal/chart/chart-base.d.ts +113 -0
- package/dist/src/__internal/chart/paths.d.ts +5 -0
- package/dist/src/__internal/chart/types.d.ts +42 -0
- package/dist/src/card/card-content.d.ts +2 -3
- package/dist/src/card/card.d.ts +31 -17
- package/dist/src/chart-area/chart-area.d.ts +54 -0
- package/dist/src/chart-area/index.d.ts +1 -0
- package/dist/src/chart-bar/chart-bar.d.ts +44 -33
- package/dist/src/chart-bar/index.d.ts +0 -1
- package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
- package/dist/src/chart-line/chart-line.d.ts +69 -0
- package/dist/src/chart-line/index.d.ts +1 -0
- package/dist/src/chart-pie/chart-pie.d.ts +63 -28
- package/dist/src/code-editor/code-editor.d.ts +52 -13
- package/dist/src/code-editor/editor-theme.d.ts +60 -0
- package/dist/src/code-highlighter/code-group.d.ts +52 -0
- package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
- package/dist/src/code-highlighter/index.d.ts +1 -0
- package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
- package/dist/src/code-highlighter/local.d.ts +4 -1
- package/dist/src/code-highlighter/token-colors.d.ts +8 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/pagination/page-items.d.ts +14 -0
- package/dist/src/pagination/pagination.d.ts +46 -7
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/table/table.d.ts +125 -27
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +1007 -338
- package/dist/table.js.map +1 -1
- package/dist/test/chart.test.d.ts +1 -0
- package/dist/test/code-highlighter.test.d.ts +1 -0
- package/dist/test/pagination.test.d.ts +1 -0
- package/dist/test/table.test.d.ts +1 -0
- package/dist/token-colors-0TFHWbcq.js +81 -0
- package/dist/token-colors-0TFHWbcq.js.map +1 -0
- package/dist/toolbar.js +195 -184
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/readme.md +7 -6
- package/scss/_code-block.scss +139 -0
- package/scss/tokens.css +24 -0
- package/src/__internal/chart/cartesian-chart.ts +404 -0
- package/src/__internal/chart/chart-base.scss +252 -0
- package/src/__internal/chart/chart-base.ts +474 -0
- package/src/__internal/chart/paths.ts +28 -0
- package/src/__internal/chart/types.ts +49 -0
- package/src/card/card-content.ts +12 -9
- package/src/card/card.scss +66 -54
- package/src/card/card.ts +109 -73
- package/src/chart-area/chart-area.ts +82 -0
- package/src/chart-area/index.ts +1 -0
- package/src/chart-bar/chart-bar.ts +336 -250
- package/src/chart-bar/index.ts +0 -1
- package/src/chart-doughnut/chart-doughnut.ts +62 -262
- package/src/chart-doughnut/demo/index.html +14 -22
- package/src/chart-line/chart-line.scss +25 -0
- package/src/chart-line/chart-line.ts +346 -0
- package/src/chart-line/index.ts +1 -0
- package/src/chart-pie/chart-pie.scss +35 -16
- package/src/chart-pie/chart-pie.ts +282 -188
- package/src/chart-pie/demo/index.html +13 -21
- package/src/code-editor/code-editor.scss +132 -36
- package/src/code-editor/code-editor.ts +308 -88
- package/src/code-editor/demo/index.html +39 -12
- package/src/code-editor/editor-theme.ts +213 -0
- package/src/code-highlighter/code-group.scss +34 -0
- package/src/code-highlighter/code-group.ts +173 -0
- package/src/code-highlighter/code-highlighter.scss +226 -111
- package/src/code-highlighter/code-highlighter.ts +554 -199
- package/src/code-highlighter/demo/index.html +68 -4
- package/src/code-highlighter/index.ts +1 -0
- package/src/code-highlighter/line-ranges.ts +81 -0
- package/src/code-highlighter/local.ts +9 -3
- package/src/code-highlighter/token-colors.ts +42 -0
- package/src/index.ts +4 -2
- package/src/loader.ts +8 -2
- package/src/pagination/page-items.ts +50 -0
- package/src/pagination/pagination.scss +159 -44
- package/src/pagination/pagination.ts +275 -74
- package/src/snackbar/demo/index.html +39 -4
- package/src/snackbar/snackbar.scss +27 -10
- package/src/snackbar/snackbar.ts +80 -37
- package/src/table/table.scss +337 -109
- package/src/table/table.ts +812 -272
- package/src/toolbar/toolbar-colors.scss +6 -7
- package/src/toolbar/toolbar.scss +35 -106
- package/src/toolbar/toolbar.ts +180 -80
- package/dist/array-D5vjT2Xm.js +0 -14
- package/dist/array-D5vjT2Xm.js.map +0 -1
- package/dist/chart-bar-D5dGFJfK.js.map +0 -1
- package/dist/chart-stacked-bar.js +0 -403
- package/dist/chart-stacked-bar.js.map +0 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
- package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
- package/dist/pie-Dz0IDiPt.js +0 -537
- package/dist/pie-Dz0IDiPt.js.map +0 -1
- package/dist/pierre-dark-DFWl0m-C.js +0 -4
- package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
- package/dist/pierre-light-BEkAPImt.js +0 -4
- package/dist/pierre-light-BEkAPImt.js.map +0 -1
- package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
- package/dist/src/code-highlighter/constants.d.ts +0 -1
- package/dist/transform-DSwFSqzD.js.map +0 -1
- package/src/chart-bar/chart-bar.scss +0 -58
- package/src/chart-bar/chart-stacked-bar.ts +0 -398
- package/src/chart-doughnut/chart-donut.scss +0 -37
- package/src/code-highlighter/constants.ts +0 -117
- /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
package/dist/pagination.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { i, _ as __decorate, I as IndividualComponent, a as i$1, b } from './IndividualComponent-Bdwyrvd6.js';
|
|
1
|
+
import { i, _ as __decorate, I as IndividualComponent, a as i$1, b, A } from './IndividualComponent-Bdwyrvd6.js';
|
|
2
2
|
import { n } from './property-B49QQ8pS.js';
|
|
3
|
+
import { e } from './class-map-DG7CA1et.js';
|
|
4
|
+
import './directive-ZPhl09Yt.js';
|
|
3
5
|
|
|
4
6
|
var css_248z = i`* {
|
|
5
7
|
box-sizing: border-box;
|
|
@@ -17,96 +19,251 @@ var css_248z = i`* {
|
|
|
17
19
|
:host {
|
|
18
20
|
display: block;
|
|
19
21
|
container-type: inline-size;
|
|
22
|
+
--pagination-background: var(--color-surface, #fff);
|
|
23
|
+
--_pagination-target-size: 2.5rem;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
.pagination {
|
|
23
27
|
display: flex;
|
|
24
|
-
align-items: center;
|
|
25
|
-
justify-content: space-between;
|
|
26
28
|
flex-wrap: wrap;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: var(--spacing-100, 0.5rem) var(--spacing-300, 1.5rem);
|
|
31
|
+
padding: var(--spacing-100, 0.5rem) var(--spacing-200, 1rem);
|
|
32
|
+
background: var(--pagination-background);
|
|
33
|
+
color: var(--color-on-surface-variant);
|
|
34
|
+
font-family: var(--typography-body-medium-font-family);
|
|
35
|
+
font-size: var(--typography-body-medium-font-size);
|
|
36
|
+
font-weight: var(--typography-body-medium-font-weight);
|
|
37
|
+
line-height: var(--typography-body-medium-line-height);
|
|
38
|
+
letter-spacing: var(--typography-body-medium-letter-spacing);
|
|
31
39
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
40
|
+
|
|
41
|
+
.range {
|
|
42
|
+
flex: 1 1 auto;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
font-variant-numeric: tabular-nums;
|
|
38
45
|
}
|
|
39
|
-
|
|
46
|
+
|
|
47
|
+
.page-size {
|
|
40
48
|
display: inline-flex;
|
|
41
49
|
align-items: center;
|
|
42
50
|
gap: var(--spacing-100, 0.5rem);
|
|
43
|
-
min-inline-size: max-content;
|
|
44
51
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
font-size: var(--typography-body-small-font-size);
|
|
48
|
-
font-weight: var(--typography-body-small-font-weight);
|
|
49
|
-
line-height: var(--typography-body-small-line-height);
|
|
50
|
-
letter-spacing: var(--typography-body-small-letter-spacing);
|
|
51
|
-
color: var(--color-on-surface-variant);
|
|
52
|
+
|
|
53
|
+
.page-size-label {
|
|
52
54
|
white-space: nowrap;
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
|
|
57
|
+
.page-size-select {
|
|
55
58
|
inline-size: 5.5rem;
|
|
56
|
-
|
|
57
|
-
--field-
|
|
59
|
+
--field-height: var(--_pagination-target-size);
|
|
60
|
+
--field-padding-block: 0;
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
.controls {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
gap: var(--spacing-050, 0.25rem);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.nav-button {
|
|
70
|
+
--button-container-shape: var(--shape-corner-full);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.page-list {
|
|
63
74
|
display: flex;
|
|
64
75
|
align-items: center;
|
|
76
|
+
gap: var(--spacing-025, 0.125rem);
|
|
77
|
+
margin: 0;
|
|
78
|
+
padding: 0;
|
|
79
|
+
list-style: none;
|
|
65
80
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
|
|
82
|
+
.page-button {
|
|
83
|
+
background: transparent;
|
|
84
|
+
border: none;
|
|
85
|
+
appearance: none;
|
|
86
|
+
margin: 0;
|
|
87
|
+
outline: none;
|
|
88
|
+
padding: 0;
|
|
89
|
+
font-family: var(--typography-label-large-font-family);
|
|
90
|
+
font-size: var(--typography-label-large-font-size);
|
|
91
|
+
font-weight: var(--typography-label-large-font-weight);
|
|
92
|
+
line-height: var(--typography-label-large-line-height);
|
|
93
|
+
letter-spacing: var(--typography-label-large-letter-spacing);
|
|
94
|
+
display: inline-flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
min-inline-size: var(--_pagination-target-size);
|
|
98
|
+
block-size: var(--_pagination-target-size);
|
|
99
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
100
|
+
border-radius: var(--shape-corner-full);
|
|
101
|
+
color: var(--color-on-surface-variant);
|
|
102
|
+
font-variant-numeric: tabular-nums;
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
transition: background-color var(--duration-short2, 100ms) ease;
|
|
72
105
|
}
|
|
73
|
-
.
|
|
106
|
+
.page-button:hover {
|
|
107
|
+
background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
108
|
+
}
|
|
109
|
+
.page-button:active {
|
|
110
|
+
background: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
|
|
111
|
+
}
|
|
112
|
+
.page-button:focus-visible {
|
|
113
|
+
outline: 2px solid var(--color-primary);
|
|
114
|
+
outline-offset: 2px;
|
|
115
|
+
}
|
|
116
|
+
.page-button.current {
|
|
117
|
+
background: var(--color-secondary-container);
|
|
118
|
+
color: var(--color-on-secondary-container);
|
|
119
|
+
cursor: default;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.page-ellipsis {
|
|
123
|
+
display: inline-flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
justify-content: center;
|
|
126
|
+
min-inline-size: var(--_pagination-target-size);
|
|
127
|
+
block-size: var(--_pagination-target-size);
|
|
128
|
+
user-select: none;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.page-jump {
|
|
132
|
+
display: inline-flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
gap: var(--spacing-100, 0.5rem);
|
|
135
|
+
padding-inline: var(--spacing-050, 0.25rem);
|
|
136
|
+
white-space: nowrap;
|
|
137
|
+
font-variant-numeric: tabular-nums;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.page-input {
|
|
74
141
|
font-family: var(--typography-body-medium-font-family);
|
|
75
142
|
font-size: var(--typography-body-medium-font-size);
|
|
76
143
|
font-weight: var(--typography-body-medium-font-weight);
|
|
77
144
|
line-height: var(--typography-body-medium-line-height);
|
|
78
145
|
letter-spacing: var(--typography-body-medium-letter-spacing);
|
|
79
|
-
|
|
146
|
+
inline-size: 3.5rem;
|
|
147
|
+
block-size: 2rem;
|
|
148
|
+
padding: 0 var(--spacing-100, 0.5rem);
|
|
149
|
+
border: 1px solid var(--color-outline-variant);
|
|
150
|
+
border-radius: var(--shape-corner-small);
|
|
151
|
+
background: var(--color-surface);
|
|
152
|
+
color: var(--color-on-surface);
|
|
153
|
+
text-align: center;
|
|
154
|
+
font-variant-numeric: tabular-nums;
|
|
155
|
+
appearance: textfield;
|
|
80
156
|
}
|
|
81
|
-
.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
gap: var(--spacing-025, 0.125rem);
|
|
157
|
+
.page-input::-webkit-inner-spin-button, .page-input::-webkit-outer-spin-button {
|
|
158
|
+
appearance: none;
|
|
159
|
+
margin: 0;
|
|
85
160
|
}
|
|
86
|
-
.
|
|
87
|
-
|
|
161
|
+
.page-input:hover {
|
|
162
|
+
border-color: var(--color-outline);
|
|
163
|
+
}
|
|
164
|
+
.page-input:focus-visible {
|
|
165
|
+
outline: 2px solid var(--color-primary);
|
|
166
|
+
outline-offset: -1px;
|
|
167
|
+
border-color: transparent;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.variant-full .page-jump {
|
|
171
|
+
display: none;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@container (max-width: 40rem) {
|
|
175
|
+
.variant-full .page-list {
|
|
176
|
+
display: none;
|
|
177
|
+
}
|
|
178
|
+
.variant-full .page-jump {
|
|
179
|
+
display: inline-flex;
|
|
180
|
+
}
|
|
181
|
+
.page-size-label {
|
|
182
|
+
display: none;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
@container (max-width: 26rem) {
|
|
186
|
+
.controls {
|
|
187
|
+
flex-basis: 100%;
|
|
188
|
+
justify-content: space-between;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
.visually-hidden {
|
|
192
|
+
position: absolute;
|
|
193
|
+
inline-size: 1px;
|
|
194
|
+
block-size: 1px;
|
|
195
|
+
margin: -1px;
|
|
196
|
+
padding: 0;
|
|
197
|
+
overflow: hidden;
|
|
198
|
+
clip-path: inset(50%);
|
|
199
|
+
white-space: nowrap;
|
|
200
|
+
border: 0;
|
|
88
201
|
}`;
|
|
89
202
|
|
|
203
|
+
function range(from, to) {
|
|
204
|
+
return Array.from({ length: to - from + 1 }, (_, index) => from + index);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Builds the page list shown by the `full` pagination variant.
|
|
208
|
+
*
|
|
209
|
+
* The list always keeps the first and last page, the current page and `siblings` pages on each
|
|
210
|
+
* side of it, and fills the rest with an ellipsis. It never holds more than
|
|
211
|
+
* `2 * siblings + 5` slots, so the control keeps its width while the user moves through pages.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* getPageItems(5, 24); // [1, 'ellipsis', 4, 5, 6, 'ellipsis', 24]
|
|
215
|
+
* getPageItems(2, 24); // [1, 2, 3, 4, 5, 'ellipsis', 24]
|
|
216
|
+
*/
|
|
217
|
+
function getPageItems(current, total, siblings = 1) {
|
|
218
|
+
const totalPages = Math.max(1, Math.trunc(total));
|
|
219
|
+
const page = Math.min(Math.max(1, Math.trunc(current)), totalPages);
|
|
220
|
+
const maxSlots = 2 * siblings + 5;
|
|
221
|
+
if (totalPages <= maxSlots) {
|
|
222
|
+
return range(1, totalPages);
|
|
223
|
+
}
|
|
224
|
+
const start = Math.max(page - siblings, 1);
|
|
225
|
+
const end = Math.min(page + siblings, totalPages);
|
|
226
|
+
// A gap of one page is shown as that page; only a gap of two or more becomes an ellipsis.
|
|
227
|
+
const showStartGap = start > 3;
|
|
228
|
+
const showEndGap = end < totalPages - 2;
|
|
229
|
+
// Pages shown on the side without a gap: the window, the edge page and the slot the
|
|
230
|
+
// ellipsis would have taken.
|
|
231
|
+
const edgeCount = 2 * siblings + 3;
|
|
232
|
+
if (!showStartGap && showEndGap) {
|
|
233
|
+
return [...range(1, edgeCount), 'ellipsis', totalPages];
|
|
234
|
+
}
|
|
235
|
+
if (showStartGap && !showEndGap) {
|
|
236
|
+
return [1, 'ellipsis', ...range(totalPages - edgeCount + 1, totalPages)];
|
|
237
|
+
}
|
|
238
|
+
return [1, 'ellipsis', ...range(start, end), 'ellipsis', totalPages];
|
|
239
|
+
}
|
|
240
|
+
|
|
90
241
|
const DEFAULT_PAGE_SIZES = [10, 25, 50, 100];
|
|
91
242
|
/**
|
|
92
243
|
* @label Pagination
|
|
93
244
|
* @tag wc-pagination
|
|
94
245
|
* @rawTag pagination
|
|
95
|
-
* @summary A pagination control with page
|
|
246
|
+
* @summary A pagination control with page numbers, a rows-per-page selector and the current item range.
|
|
96
247
|
* @overview
|
|
97
|
-
* <p>The pagination component
|
|
248
|
+
* <p>The pagination component moves through paged data. It shows the current item range, the pages and a rows-per-page selector.</p>
|
|
249
|
+
* <p>Three variants cover different data sets: <code>full</code> lists page numbers with ellipses, <code>compact</code> shows "Page [n] of N" with a field to jump to a page, and <code>simple</code> shows previous and next only. When <code>total-items</code> is not set, the total is unknown (cursor-based APIs): the control shows previous and next, and <code>has-next</code> says whether another page exists.</p>
|
|
250
|
+
* <p>On a narrow container the <code>full</code> variant collapses to <code>compact</code>.</p>
|
|
98
251
|
*
|
|
99
252
|
* @fires {CustomEvent} page - Dispatched when the page or page size changes. Detail: `{ page, pageSize }`.
|
|
100
253
|
*
|
|
254
|
+
* @cssprop --pagination-background - Background of the control. Defaults to the surface color.
|
|
255
|
+
*
|
|
101
256
|
* @example
|
|
102
257
|
* ```html
|
|
103
|
-
* <wc-pagination style="width: 100%;" page="1" page-size="10" total-items="
|
|
258
|
+
* <wc-pagination style="width: 100%;" page="1" page-size="10" total-items="240"></wc-pagination>
|
|
104
259
|
* ```
|
|
105
260
|
* @tags navigation, data
|
|
106
261
|
*/
|
|
107
262
|
let Pagination = class Pagination extends i$1 {
|
|
108
263
|
constructor() {
|
|
264
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
109
265
|
super(...arguments);
|
|
266
|
+
// ── Properties ───────────────────────────────────────────────────────────
|
|
110
267
|
/**
|
|
111
268
|
* The current page number (1-based). Defaults to `1`.
|
|
112
269
|
*/
|
|
@@ -115,27 +272,55 @@ let Pagination = class Pagination extends i$1 {
|
|
|
115
272
|
* The number of rows per page. Defaults to `10`.
|
|
116
273
|
*/
|
|
117
274
|
this.pageSize = 10;
|
|
118
|
-
/**
|
|
119
|
-
* Total number of items.
|
|
120
|
-
*/
|
|
121
|
-
this.totalItems = 0;
|
|
122
275
|
/**
|
|
123
276
|
* Supported page size options.
|
|
124
277
|
*/
|
|
125
278
|
this.pageSizes = DEFAULT_PAGE_SIZES;
|
|
126
|
-
|
|
127
|
-
|
|
279
|
+
/**
|
|
280
|
+
* How the pages are shown: `full` (page numbers), `compact` ("Page [n] of N") or `simple`
|
|
281
|
+
* (previous and next only). Defaults to `full`.
|
|
282
|
+
*/
|
|
283
|
+
this.variant = 'full';
|
|
284
|
+
/**
|
|
285
|
+
* Whether another page exists after this one. Used only when `total-items` is unset.
|
|
286
|
+
*/
|
|
287
|
+
this.hasNext = false;
|
|
288
|
+
/**
|
|
289
|
+
* Shows buttons that jump to the first and the last page.
|
|
290
|
+
*/
|
|
291
|
+
this.showFirstLast = false;
|
|
292
|
+
/**
|
|
293
|
+
* Hides the rows-per-page selector.
|
|
294
|
+
*/
|
|
295
|
+
this.hidePageSize = false;
|
|
296
|
+
/**
|
|
297
|
+
* Accessible name of the navigation landmark. Defaults to `"Pagination"`.
|
|
298
|
+
*/
|
|
299
|
+
this.label = 'Pagination';
|
|
300
|
+
this.handlePageInput = (event) => {
|
|
301
|
+
const input = event.target;
|
|
302
|
+
const value = Number.parseInt(input.value, 10);
|
|
303
|
+
if (Number.isFinite(value)) {
|
|
304
|
+
this.setPage(value);
|
|
305
|
+
}
|
|
306
|
+
// Show the page actually used, for example after clamping 99 to the last page.
|
|
307
|
+
input.value = String(this.page);
|
|
128
308
|
};
|
|
129
|
-
this.
|
|
130
|
-
|
|
309
|
+
this.handlePageInputKeydown = (event) => {
|
|
310
|
+
if (event.key === 'Enter') {
|
|
311
|
+
this.handlePageInput(event);
|
|
312
|
+
}
|
|
131
313
|
};
|
|
132
314
|
}
|
|
315
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
133
316
|
willUpdate(changedProperties) {
|
|
134
317
|
// Normalize page-size options so the select always has valid numeric values.
|
|
135
|
-
const normalizedPageSizes = [
|
|
318
|
+
const normalizedPageSizes = [
|
|
319
|
+
...new Set(this.pageSizes
|
|
136
320
|
.map(size => Number(size))
|
|
137
321
|
.filter(size => Number.isFinite(size) && size > 0)
|
|
138
|
-
.map(size => Math.trunc(size)))
|
|
322
|
+
.map(size => Math.trunc(size))),
|
|
323
|
+
];
|
|
139
324
|
if (!normalizedPageSizes.length) {
|
|
140
325
|
normalizedPageSizes.push(...DEFAULT_PAGE_SIZES);
|
|
141
326
|
}
|
|
@@ -147,25 +332,59 @@ let Pagination = class Pagination extends i$1 {
|
|
|
147
332
|
if (!this.pageSizes.includes(this.pageSize)) {
|
|
148
333
|
this.pageSize = this.pageSizes[0] ?? DEFAULT_PAGE_SIZES[0];
|
|
149
334
|
}
|
|
150
|
-
if (
|
|
335
|
+
if (this.totalItems !== undefined &&
|
|
336
|
+
this.totalItems !== null &&
|
|
337
|
+
(!Number.isFinite(this.totalItems) || this.totalItems < 0)) {
|
|
151
338
|
this.totalItems = 0;
|
|
152
339
|
}
|
|
153
340
|
if (!Number.isFinite(this.page) || this.page < 1) {
|
|
154
341
|
this.page = 1;
|
|
155
342
|
}
|
|
156
|
-
const
|
|
157
|
-
if (this.page >
|
|
158
|
-
this.page =
|
|
343
|
+
const totalPages = this.getTotalPages();
|
|
344
|
+
if (totalPages !== undefined && this.page > totalPages) {
|
|
345
|
+
this.page = totalPages;
|
|
159
346
|
}
|
|
160
347
|
}
|
|
348
|
+
// ── Private methods ──────────────────────────────────────────────────────
|
|
349
|
+
/** True when the total is known. */
|
|
350
|
+
get hasTotal() {
|
|
351
|
+
return this.totalItems !== undefined && this.totalItems !== null;
|
|
352
|
+
}
|
|
353
|
+
/** The number of pages, or `undefined` when the total is unknown. */
|
|
161
354
|
getTotalPages() {
|
|
162
|
-
if (this.
|
|
355
|
+
if (!this.hasTotal)
|
|
356
|
+
return undefined;
|
|
357
|
+
const total = this.totalItems ?? 0;
|
|
358
|
+
if (total <= 0)
|
|
163
359
|
return 1;
|
|
164
|
-
return Math.max(1, Math.ceil(
|
|
360
|
+
return Math.max(1, Math.ceil(total / this.pageSize));
|
|
361
|
+
}
|
|
362
|
+
get isFirstPage() {
|
|
363
|
+
return this.page <= 1;
|
|
364
|
+
}
|
|
365
|
+
get isLastPage() {
|
|
366
|
+
const totalPages = this.getTotalPages();
|
|
367
|
+
return totalPages === undefined ? !this.hasNext : this.page >= totalPages;
|
|
368
|
+
}
|
|
369
|
+
/** The variant actually rendered: an unknown total can only go previous and next. */
|
|
370
|
+
get effectiveVariant() {
|
|
371
|
+
return this.hasTotal ? this.variant : 'simple';
|
|
372
|
+
}
|
|
373
|
+
getRangeText() {
|
|
374
|
+
const total = this.totalItems ?? 0;
|
|
375
|
+
if (this.hasTotal && total === 0)
|
|
376
|
+
return '0 of 0';
|
|
377
|
+
const start = this.pageSize * (this.page - 1) + 1;
|
|
378
|
+
if (!this.hasTotal)
|
|
379
|
+
return `${start}–${this.pageSize * this.page}`;
|
|
380
|
+
const end = Math.min(this.pageSize * this.page, total);
|
|
381
|
+
return `${start}–${end} of ${total}`;
|
|
165
382
|
}
|
|
166
383
|
setPage(nextPage) {
|
|
167
|
-
const
|
|
168
|
-
|
|
384
|
+
const totalPages = this.getTotalPages() ?? Number.MAX_SAFE_INTEGER;
|
|
385
|
+
const lastAllowed = this.hasTotal || this.hasNext ? totalPages : Math.max(1, this.page);
|
|
386
|
+
const clampedPage = Math.min(Math.max(1, Math.trunc(nextPage)), lastAllowed);
|
|
387
|
+
if (!Number.isFinite(clampedPage) || clampedPage === this.page)
|
|
169
388
|
return;
|
|
170
389
|
this.page = clampedPage;
|
|
171
390
|
this.dispatchPageEvent();
|
|
@@ -176,8 +395,12 @@ let Pagination = class Pagination extends i$1 {
|
|
|
176
395
|
if (!Number.isFinite(parsedPageSize) || parsedPageSize <= 0) {
|
|
177
396
|
return;
|
|
178
397
|
}
|
|
398
|
+
if (parsedPageSize === this.pageSize)
|
|
399
|
+
return;
|
|
400
|
+
// Keep the first visible item on screen instead of jumping back to page 1.
|
|
401
|
+
const firstItemIndex = this.pageSize * (this.page - 1);
|
|
179
402
|
this.pageSize = parsedPageSize;
|
|
180
|
-
this.page = 1;
|
|
403
|
+
this.page = Math.floor(firstItemIndex / parsedPageSize) + 1;
|
|
181
404
|
this.dispatchPageEvent();
|
|
182
405
|
}
|
|
183
406
|
dispatchPageEvent() {
|
|
@@ -187,56 +410,116 @@ let Pagination = class Pagination extends i$1 {
|
|
|
187
410
|
composed: true,
|
|
188
411
|
}));
|
|
189
412
|
}
|
|
413
|
+
// ── Render helpers ───────────────────────────────────────────────────────
|
|
414
|
+
renderNavButton(icon, label, disabled, target, className) {
|
|
415
|
+
return b `
|
|
416
|
+
<wc-icon-button
|
|
417
|
+
class="nav-button ${className}"
|
|
418
|
+
color="secondary"
|
|
419
|
+
variant="text"
|
|
420
|
+
size="sm"
|
|
421
|
+
aria-label=${label}
|
|
422
|
+
title=${label}
|
|
423
|
+
?disabled=${disabled}
|
|
424
|
+
@click=${() => this.setPage(target())}
|
|
425
|
+
>
|
|
426
|
+
<wc-icon name=${icon}></wc-icon>
|
|
427
|
+
</wc-icon-button>
|
|
428
|
+
`;
|
|
429
|
+
}
|
|
430
|
+
renderPageList(totalPages) {
|
|
431
|
+
return b `
|
|
432
|
+
<ol class="page-list">
|
|
433
|
+
${getPageItems(this.page, totalPages).map(item => item === 'ellipsis'
|
|
434
|
+
? b `<li class="page-ellipsis" aria-hidden="true">…</li>`
|
|
435
|
+
: b `
|
|
436
|
+
<li>
|
|
437
|
+
<button
|
|
438
|
+
type="button"
|
|
439
|
+
class=${e({
|
|
440
|
+
'page-button': true,
|
|
441
|
+
current: item === this.page,
|
|
442
|
+
})}
|
|
443
|
+
aria-label="Page ${item}"
|
|
444
|
+
aria-current=${item === this.page ? 'page' : A}
|
|
445
|
+
@click=${() => this.setPage(item)}
|
|
446
|
+
>
|
|
447
|
+
${item}
|
|
448
|
+
</button>
|
|
449
|
+
</li>
|
|
450
|
+
`)}
|
|
451
|
+
</ol>
|
|
452
|
+
`;
|
|
453
|
+
}
|
|
454
|
+
renderPageJump(totalPages) {
|
|
455
|
+
return b `
|
|
456
|
+
<div class="page-jump">
|
|
457
|
+
<span>Page</span>
|
|
458
|
+
<input
|
|
459
|
+
class="page-input"
|
|
460
|
+
type="number"
|
|
461
|
+
inputmode="numeric"
|
|
462
|
+
min="1"
|
|
463
|
+
max=${totalPages}
|
|
464
|
+
.value=${String(this.page)}
|
|
465
|
+
aria-label="Page number, ${totalPages} pages"
|
|
466
|
+
@change=${this.handlePageInput}
|
|
467
|
+
@keydown=${this.handlePageInputKeydown}
|
|
468
|
+
/>
|
|
469
|
+
<span>of ${totalPages}</span>
|
|
470
|
+
</div>
|
|
471
|
+
`;
|
|
472
|
+
}
|
|
473
|
+
renderPageSize() {
|
|
474
|
+
if (this.hidePageSize)
|
|
475
|
+
return A;
|
|
476
|
+
return b `
|
|
477
|
+
<div class="page-size">
|
|
478
|
+
<span class="page-size-label" aria-hidden="true">Rows per page</span>
|
|
479
|
+
<wc-select
|
|
480
|
+
class="page-size-select"
|
|
481
|
+
.value=${String(this.pageSize)}
|
|
482
|
+
aria-label="Rows per page"
|
|
483
|
+
@change=${this.handlePageSizeChange}
|
|
484
|
+
>
|
|
485
|
+
${this.pageSizes.map(size => b `<wc-option value=${String(size)}>${size}</wc-option>`)}
|
|
486
|
+
</wc-select>
|
|
487
|
+
</div>
|
|
488
|
+
`;
|
|
489
|
+
}
|
|
490
|
+
// ── Render ───────────────────────────────────────────────────────────────
|
|
190
491
|
render() {
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
492
|
+
const variant = this.effectiveVariant;
|
|
493
|
+
const totalPages = this.getTotalPages() ?? 1;
|
|
494
|
+
const rangeText = this.getRangeText();
|
|
495
|
+
const showFirstLast = this.showFirstLast && this.hasTotal;
|
|
195
496
|
return b `
|
|
196
|
-
<
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
>
|
|
205
|
-
${this.pageSizes.map(size => b `<wc-option value=${String(size)}>${size}</wc-option>`)}
|
|
206
|
-
</wc-select>
|
|
207
|
-
</div>
|
|
497
|
+
<nav
|
|
498
|
+
class=${e({ pagination: true, [`variant-${variant}`]: true })}
|
|
499
|
+
aria-label=${this.label}
|
|
500
|
+
>
|
|
501
|
+
<div class="range" aria-hidden="true">${rangeText}</div>
|
|
502
|
+
<span class="visually-hidden" aria-live="polite">
|
|
503
|
+
Showing ${rangeText}
|
|
504
|
+
</span>
|
|
208
505
|
|
|
209
|
-
|
|
210
|
-
<span class="pagination-text">
|
|
211
|
-
${startItem} - ${endItem} of ${this.totalItems}
|
|
212
|
-
</span>
|
|
213
|
-
</div>
|
|
506
|
+
${this.renderPageSize()}
|
|
214
507
|
|
|
215
|
-
<div class="
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
?
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
class="nav-button"
|
|
229
|
-
color="secondary"
|
|
230
|
-
variant="text"
|
|
231
|
-
size="sm"
|
|
232
|
-
title="Next page"
|
|
233
|
-
?disabled=${isLastPage}
|
|
234
|
-
@click=${this.handleNextPage}
|
|
235
|
-
>
|
|
236
|
-
<wc-icon name="keyboard_arrow_right"></wc-icon>
|
|
237
|
-
</wc-icon-button>
|
|
508
|
+
<div class="controls">
|
|
509
|
+
${showFirstLast
|
|
510
|
+
? this.renderNavButton('first_page', 'First page', this.isFirstPage, () => 1, 'first')
|
|
511
|
+
: A}
|
|
512
|
+
${this.renderNavButton('chevron_left', 'Previous page', this.isFirstPage, () => this.page - 1, 'previous')}
|
|
513
|
+
${variant === 'full' ? this.renderPageList(totalPages) : A}
|
|
514
|
+
${variant === 'full' || variant === 'compact'
|
|
515
|
+
? this.renderPageJump(totalPages)
|
|
516
|
+
: A}
|
|
517
|
+
${this.renderNavButton('chevron_right', 'Next page', this.isLastPage, () => this.page + 1, 'next')}
|
|
518
|
+
${showFirstLast
|
|
519
|
+
? this.renderNavButton('last_page', 'Last page', this.isLastPage, () => totalPages, 'last')
|
|
520
|
+
: A}
|
|
238
521
|
</div>
|
|
239
|
-
</
|
|
522
|
+
</nav>
|
|
240
523
|
`;
|
|
241
524
|
}
|
|
242
525
|
};
|
|
@@ -253,6 +536,21 @@ __decorate([
|
|
|
253
536
|
__decorate([
|
|
254
537
|
n({ type: Array, attribute: 'page-sizes' })
|
|
255
538
|
], Pagination.prototype, "pageSizes", void 0);
|
|
539
|
+
__decorate([
|
|
540
|
+
n({ type: String, reflect: true })
|
|
541
|
+
], Pagination.prototype, "variant", void 0);
|
|
542
|
+
__decorate([
|
|
543
|
+
n({ type: Boolean, attribute: 'has-next' })
|
|
544
|
+
], Pagination.prototype, "hasNext", void 0);
|
|
545
|
+
__decorate([
|
|
546
|
+
n({ type: Boolean, attribute: 'show-first-last' })
|
|
547
|
+
], Pagination.prototype, "showFirstLast", void 0);
|
|
548
|
+
__decorate([
|
|
549
|
+
n({ type: Boolean, attribute: 'hide-page-size' })
|
|
550
|
+
], Pagination.prototype, "hidePageSize", void 0);
|
|
551
|
+
__decorate([
|
|
552
|
+
n({ type: String })
|
|
553
|
+
], Pagination.prototype, "label", void 0);
|
|
256
554
|
Pagination = __decorate([
|
|
257
555
|
IndividualComponent
|
|
258
556
|
], Pagination);
|