legacy.css 0.1.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/LICENSE +21 -0
- package/README.md +242 -0
- package/dist/legacy.css +1045 -0
- package/dist/legacy.js +1466 -0
- package/dist/legacy.min.css +1 -0
- package/dist/legacy.min.js +1 -0
- package/mcp/server.js +524 -0
- package/package.json +52 -0
- package/src/alerts.css +21 -0
- package/src/badges.css +39 -0
- package/src/base.css +43 -0
- package/src/buttons.css +40 -0
- package/src/dragdrop.css +49 -0
- package/src/features/dragdrop.ts +273 -0
- package/src/features/modal.ts +265 -0
- package/src/features/multiselect.ts +390 -0
- package/src/features/pagination.ts +483 -0
- package/src/features/popover.ts +322 -0
- package/src/features/tabs.ts +199 -0
- package/src/features/theme.ts +59 -0
- package/src/features/toast.ts +216 -0
- package/src/forms.css +57 -0
- package/src/internal.ts +210 -0
- package/src/jquery.ts +141 -0
- package/src/legacy.css +22 -0
- package/src/legacy.ts +31 -0
- package/src/lists.css +21 -0
- package/src/modal.css +46 -0
- package/src/multiselect.css +118 -0
- package/src/navigation.css +18 -0
- package/src/pagination.css +53 -0
- package/src/panels.css +22 -0
- package/src/popover.css +36 -0
- package/src/progress.css +117 -0
- package/src/sidebar.css +62 -0
- package/src/tables.css +31 -0
- package/src/tabs.css +43 -0
- package/src/toast.css +78 -0
- package/src/toolbars.css +33 -0
- package/src/typography.css +48 -0
- package/src/utilities.css +23 -0
- package/src/variables.css +83 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { currentTargetElement, eventTargetElement, isElement, isLegacyCollection, isSelectElement, listen } from "../internal";
|
|
2
|
+
import type { LegacyPageToken, LegacyPaginationAction, LegacyPaginationOptions, LegacyPaginationPayload, LegacyPaginationResult, LegacyPaginationSetupOptions, LegacyPaginationState, LegacyRequiredApi, LegacyTarget } from "../internal";
|
|
3
|
+
const wiredPaginations = new WeakSet<Element>();
|
|
4
|
+
const paginationOptions = new WeakMap<Element, LegacyPaginationOptions>();
|
|
5
|
+
const paginationState = new WeakMap<Element, LegacyPaginationState>();
|
|
6
|
+
const paginationSelector = "[data-pagination], .pagination";
|
|
7
|
+
|
|
8
|
+
export function installPagination(legacy: LegacyRequiredApi): void {
|
|
9
|
+
function resolvePagination(target: LegacyTarget): Element | null {
|
|
10
|
+
if (!target) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (isLegacyCollection(target)) {
|
|
15
|
+
return resolvePagination(target[0]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof target === "string") {
|
|
19
|
+
return document.querySelector(target);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (isElement(target)) {
|
|
23
|
+
if (target.matches(paginationSelector)) {
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return target.closest(paginationSelector);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getPaginationNumber(value: unknown, fallback: number): number {
|
|
34
|
+
const number = Number(value);
|
|
35
|
+
|
|
36
|
+
return Number.isFinite(number) && number > 0 ? number : fallback;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getPaginationPageSizes(rootElement: Element, options: LegacyPaginationSetupOptions): number[] {
|
|
40
|
+
const configured =
|
|
41
|
+
options.pageSizes ||
|
|
42
|
+
rootElement.getAttribute("data-page-sizes") ||
|
|
43
|
+
rootElement.getAttribute("data-page-size-options");
|
|
44
|
+
const values = Array.isArray(configured)
|
|
45
|
+
? configured
|
|
46
|
+
: String(configured || "10,25,50").split(",");
|
|
47
|
+
const sizes = values
|
|
48
|
+
.map((value) => getPaginationNumber(value, 0))
|
|
49
|
+
.filter((value, index, list) => value > 0 && list.indexOf(value) === index);
|
|
50
|
+
|
|
51
|
+
return sizes.length > 0 ? sizes : [10, 25, 50];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getPaginationTarget(rootElement: Element, options: LegacyPaginationSetupOptions): Element | null {
|
|
55
|
+
if (options.target) {
|
|
56
|
+
/* v8 ignore next 5 -- target normalization accepts selector, element, or fallback */
|
|
57
|
+
return typeof options.target === "string"
|
|
58
|
+
? document.querySelector(options.target)
|
|
59
|
+
: options.target instanceof Element
|
|
60
|
+
? options.target
|
|
61
|
+
: null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const selector = rootElement.getAttribute("data-target");
|
|
65
|
+
|
|
66
|
+
return selector ? document.querySelector(selector) : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createPaginationResult(
|
|
70
|
+
rootElement: Element,
|
|
71
|
+
options: LegacyPaginationOptions,
|
|
72
|
+
state: LegacyPaginationState
|
|
73
|
+
): Promise<unknown> | unknown {
|
|
74
|
+
if (typeof options.load === "function") {
|
|
75
|
+
return options.load.call(rootElement, {
|
|
76
|
+
page: state.page,
|
|
77
|
+
pageSize: state.pageSize,
|
|
78
|
+
offset: (state.page - 1) * state.pageSize,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const data = Array.isArray(options.data) ? options.data : [];
|
|
83
|
+
const start = (state.page - 1) * state.pageSize;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
items: data.slice(start, start + state.pageSize),
|
|
87
|
+
total: data.length,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function normalizePaginationResult(result: unknown, state: LegacyPaginationState): LegacyPaginationResult {
|
|
92
|
+
/* v8 ignore next 6 -- pagination load normalization accepts arrays, objects, and fallbacks */
|
|
93
|
+
const payload: LegacyPaginationPayload = Array.isArray(result)
|
|
94
|
+
? { items: result, total: result.length }
|
|
95
|
+
: result && typeof result === "object"
|
|
96
|
+
? result
|
|
97
|
+
: {};
|
|
98
|
+
/* v8 ignore next -- malformed payload fallback is defensive normalization */
|
|
99
|
+
const items = Array.isArray(payload.items) ? payload.items : [];
|
|
100
|
+
const total = getPaginationNumber(payload.total, items.length);
|
|
101
|
+
const pageCount = Math.max(1, Math.ceil(total / state.pageSize));
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
items,
|
|
105
|
+
page: getPaginationNumber(payload.page, state.page),
|
|
106
|
+
pageCount,
|
|
107
|
+
pageSize: getPaginationNumber(payload.pageSize, state.pageSize),
|
|
108
|
+
total,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function renderPaginationItem(
|
|
113
|
+
item: unknown,
|
|
114
|
+
index: number,
|
|
115
|
+
options: LegacyPaginationOptions,
|
|
116
|
+
state: LegacyPaginationResult
|
|
117
|
+
): Element | DocumentFragment | string | null | undefined {
|
|
118
|
+
if (typeof options.renderItem === "function") {
|
|
119
|
+
return options.renderItem(item, index, state);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const row = document.createElement("tr");
|
|
123
|
+
const values = item && typeof item === "object" ? Object.values(item) : [item];
|
|
124
|
+
|
|
125
|
+
values.forEach((value) => {
|
|
126
|
+
const cell = document.createElement("td");
|
|
127
|
+
|
|
128
|
+
cell.textContent = value == null ? "" : String(value);
|
|
129
|
+
row.append(cell);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function renderPaginationItems(rootElement: Element, result: LegacyPaginationResult): void {
|
|
136
|
+
/* v8 ignore next -- pagination rendering is called after setup stores options */
|
|
137
|
+
const options = paginationOptions.get(rootElement) || {};
|
|
138
|
+
const target = options.target;
|
|
139
|
+
|
|
140
|
+
if (!target) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
target.replaceChildren();
|
|
145
|
+
result.items.forEach((item, index) => {
|
|
146
|
+
const rendered = renderPaginationItem(item, index, options, result);
|
|
147
|
+
|
|
148
|
+
if (typeof rendered === "string") {
|
|
149
|
+
target.insertAdjacentHTML("beforeend", rendered);
|
|
150
|
+
} else if (rendered) {
|
|
151
|
+
target.append(rendered);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getPaginationPages(currentPage: number, pageCount: number, maxPages: number): LegacyPageToken[] {
|
|
157
|
+
const pages: LegacyPageToken[] = [];
|
|
158
|
+
|
|
159
|
+
if (pageCount <= maxPages) {
|
|
160
|
+
for (let page = 1; page <= pageCount; page += 1) {
|
|
161
|
+
pages.push(page);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return pages;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
pages.push(1);
|
|
168
|
+
|
|
169
|
+
const sideCount = Math.max(1, Math.floor((maxPages - 3) / 2));
|
|
170
|
+
const start = Math.max(2, currentPage - sideCount);
|
|
171
|
+
const end = Math.min(pageCount - 1, currentPage + sideCount);
|
|
172
|
+
|
|
173
|
+
/* v8 ignore next -- pagination window shape depends on current page */
|
|
174
|
+
if (start > 2) {
|
|
175
|
+
pages.push("ellipsis-start");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (let page = start; page <= end; page += 1) {
|
|
179
|
+
pages.push(page);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (end < pageCount - 1) {
|
|
183
|
+
pages.push("ellipsis-end");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
pages.push(pageCount);
|
|
187
|
+
|
|
188
|
+
return pages;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function createPaginationButton(label: string, action: LegacyPaginationAction, disabled: boolean): HTMLButtonElement {
|
|
192
|
+
const button = document.createElement("button");
|
|
193
|
+
|
|
194
|
+
button.type = "button";
|
|
195
|
+
button.setAttribute("data-pagination-action", action);
|
|
196
|
+
button.textContent = label;
|
|
197
|
+
button.disabled = disabled;
|
|
198
|
+
|
|
199
|
+
return button;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function renderPaginationControls(rootElement: Element, result: LegacyPaginationResult): void {
|
|
203
|
+
/* v8 ignore next -- pagination controls render after setup stores options */
|
|
204
|
+
const options = paginationOptions.get(rootElement) || {};
|
|
205
|
+
const pageCount = result.pageCount;
|
|
206
|
+
const page = Math.min(result.page, pageCount);
|
|
207
|
+
const maxPages = getPaginationNumber(options.maxPages, 7);
|
|
208
|
+
const summary = document.createElement("span");
|
|
209
|
+
const pages = document.createElement("span");
|
|
210
|
+
const size = document.createElement("span");
|
|
211
|
+
const label = document.createElement("label");
|
|
212
|
+
const select = document.createElement("select");
|
|
213
|
+
|
|
214
|
+
summary.className = "pagination-summary";
|
|
215
|
+
summary.textContent = "Page " + page + " of " + pageCount + " (" + result.total + " items)";
|
|
216
|
+
pages.className = "pagination-pages";
|
|
217
|
+
pages.setAttribute("role", "group");
|
|
218
|
+
pages.setAttribute("aria-label", "Pages");
|
|
219
|
+
pages.append(createPaginationButton("Previous", "previous", page <= 1));
|
|
220
|
+
|
|
221
|
+
getPaginationPages(page, pageCount, maxPages).forEach((pageNumber) => {
|
|
222
|
+
if (typeof pageNumber !== "number") {
|
|
223
|
+
const ellipsis = document.createElement("span");
|
|
224
|
+
|
|
225
|
+
ellipsis.className = "pagination-ellipsis";
|
|
226
|
+
ellipsis.setAttribute("aria-hidden", "true");
|
|
227
|
+
ellipsis.textContent = "...";
|
|
228
|
+
pages.append(ellipsis);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const button = createPaginationButton(String(pageNumber), "page", false);
|
|
233
|
+
|
|
234
|
+
button.className = "pagination-page";
|
|
235
|
+
button.setAttribute("data-pagination-page", String(pageNumber));
|
|
236
|
+
button.setAttribute("aria-label", "Page " + pageNumber);
|
|
237
|
+
|
|
238
|
+
if (pageNumber === page) {
|
|
239
|
+
button.setAttribute("aria-current", "page");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
pages.append(button);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
pages.append(createPaginationButton("Next", "next", page >= pageCount));
|
|
246
|
+
size.className = "pagination-size";
|
|
247
|
+
label.textContent = "Page size";
|
|
248
|
+
|
|
249
|
+
/* v8 ignore next -- setup normalizes page size options */
|
|
250
|
+
const pageSizes = options.pageSizes || [result.pageSize];
|
|
251
|
+
|
|
252
|
+
pageSizes.forEach((pageSize) => {
|
|
253
|
+
const option = document.createElement("option");
|
|
254
|
+
|
|
255
|
+
option.value = String(pageSize);
|
|
256
|
+
option.textContent = String(pageSize);
|
|
257
|
+
option.selected = pageSize === result.pageSize;
|
|
258
|
+
select.append(option);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
select.setAttribute("data-pagination-size", "");
|
|
262
|
+
label.append(select);
|
|
263
|
+
size.append(label);
|
|
264
|
+
rootElement.replaceChildren(summary, pages, size);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function setPaginationLoading(rootElement: Element, loading: boolean): void {
|
|
268
|
+
rootElement.setAttribute("aria-busy", loading ? "true" : "false");
|
|
269
|
+
rootElement.querySelectorAll<HTMLButtonElement | HTMLSelectElement>("button, select").forEach((control) => {
|
|
270
|
+
control.disabled = loading;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function handlePaginationError(
|
|
275
|
+
rootElement: Element,
|
|
276
|
+
state: LegacyPaginationState,
|
|
277
|
+
request: number,
|
|
278
|
+
error: unknown
|
|
279
|
+
): void {
|
|
280
|
+
if (request !== state.request) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (state.result) {
|
|
285
|
+
renderPaginationControls(rootElement, state.result);
|
|
286
|
+
} else {
|
|
287
|
+
setPaginationLoading(rootElement, false);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
rootElement.dispatchEvent(
|
|
291
|
+
new CustomEvent("pagination:error", {
|
|
292
|
+
bubbles: true,
|
|
293
|
+
detail: { error },
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function updatePagination(rootElement: Element | null): Element | null {
|
|
299
|
+
const options = rootElement ? paginationOptions.get(rootElement) : null;
|
|
300
|
+
const state = rootElement ? paginationState.get(rootElement) : null;
|
|
301
|
+
|
|
302
|
+
if (!rootElement || !options || !state) {
|
|
303
|
+
return rootElement;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
state.request += 1;
|
|
307
|
+
const request = state.request;
|
|
308
|
+
|
|
309
|
+
setPaginationLoading(rootElement, true);
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
Promise.resolve(createPaginationResult(rootElement, options, state))
|
|
313
|
+
.then((rawResult) => {
|
|
314
|
+
if (request !== state.request) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const result = normalizePaginationResult(rawResult, state);
|
|
319
|
+
|
|
320
|
+
state.page = Math.min(result.page, result.pageCount);
|
|
321
|
+
state.pageSize = result.pageSize;
|
|
322
|
+
state.result = result;
|
|
323
|
+
renderPaginationItems(rootElement, result);
|
|
324
|
+
renderPaginationControls(rootElement, result);
|
|
325
|
+
rootElement.dispatchEvent(
|
|
326
|
+
new CustomEvent("pagination:change", {
|
|
327
|
+
bubbles: true,
|
|
328
|
+
detail: result,
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
})
|
|
332
|
+
.catch((error) => {
|
|
333
|
+
handlePaginationError(rootElement, state, request, error);
|
|
334
|
+
});
|
|
335
|
+
} catch (error) {
|
|
336
|
+
handlePaginationError(rootElement, state, request, error);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return rootElement;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function setPaginationPage(rootElement: Element | null, page: number | string | null): Element | null {
|
|
343
|
+
const state = rootElement ? paginationState.get(rootElement) : null;
|
|
344
|
+
|
|
345
|
+
if (!state) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
state.page = getPaginationNumber(page, state.page);
|
|
350
|
+
|
|
351
|
+
return updatePagination(rootElement);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function setPaginationPageSize(rootElement: Element | null, pageSize: number | string): Element | null {
|
|
355
|
+
const state = rootElement ? paginationState.get(rootElement) : null;
|
|
356
|
+
|
|
357
|
+
if (!state) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
state.page = 1;
|
|
362
|
+
state.pageSize = getPaginationNumber(pageSize, state.pageSize);
|
|
363
|
+
|
|
364
|
+
return updatePagination(rootElement);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function handlePaginationClick(event: MouseEvent): void {
|
|
368
|
+
const rootElement = resolvePagination(currentTargetElement(event));
|
|
369
|
+
const target = eventTargetElement(event);
|
|
370
|
+
/* v8 ignore next -- browser click events provide element targets */
|
|
371
|
+
const button = target ? target.closest<HTMLButtonElement>("[data-pagination-action]") : null;
|
|
372
|
+
/* v8 ignore next -- delegated pagination events are wired after state exists */
|
|
373
|
+
const state = rootElement ? paginationState.get(rootElement) : null;
|
|
374
|
+
|
|
375
|
+
if (!button || !state || button.disabled) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const action = button.getAttribute("data-pagination-action");
|
|
380
|
+
|
|
381
|
+
/* v8 ignore next 7 -- pagination action dispatch ignores unknown delegated actions */
|
|
382
|
+
if (action === "previous") {
|
|
383
|
+
setPaginationPage(rootElement, state.page - 1);
|
|
384
|
+
} else if (action === "next") {
|
|
385
|
+
setPaginationPage(rootElement, state.page + 1);
|
|
386
|
+
} else if (action === "page") {
|
|
387
|
+
setPaginationPage(rootElement, button.getAttribute("data-pagination-page"));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function handlePaginationChange(event: Event): void {
|
|
392
|
+
const target = eventTargetElement(event);
|
|
393
|
+
const rootElement = resolvePagination(currentTargetElement(event));
|
|
394
|
+
|
|
395
|
+
/* v8 ignore next -- delegated change handler ignores non-page-size controls */
|
|
396
|
+
if (isSelectElement(target) && rootElement && target.matches("[data-pagination-size]")) {
|
|
397
|
+
setPaginationPageSize(rootElement, target.value);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function setupPagination(target: LegacyTarget, options: LegacyPaginationSetupOptions = {}): Element | null {
|
|
402
|
+
const rootElement = resolvePagination(target);
|
|
403
|
+
|
|
404
|
+
if (!rootElement) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/* v8 ignore next -- setup accepts fresh options, merged options, and nullish fallbacks */
|
|
409
|
+
const nextOptions: LegacyPaginationSetupOptions = Object.assign({}, paginationOptions.get(rootElement), options || {});
|
|
410
|
+
|
|
411
|
+
nextOptions.target = getPaginationTarget(rootElement, nextOptions);
|
|
412
|
+
nextOptions.pageSizes = getPaginationPageSizes(rootElement, nextOptions);
|
|
413
|
+
nextOptions.pageSize = getPaginationNumber(
|
|
414
|
+
nextOptions.pageSize || rootElement.getAttribute("data-page-size"),
|
|
415
|
+
nextOptions.pageSizes[0]
|
|
416
|
+
);
|
|
417
|
+
nextOptions.maxPages = getPaginationNumber(
|
|
418
|
+
nextOptions.maxPages || rootElement.getAttribute("data-max-pages"),
|
|
419
|
+
7
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
const normalizedOptions: LegacyPaginationOptions = {
|
|
423
|
+
data: nextOptions.data,
|
|
424
|
+
load: nextOptions.load,
|
|
425
|
+
maxPages: nextOptions.maxPages,
|
|
426
|
+
pageSize: nextOptions.pageSize,
|
|
427
|
+
pageSizes: nextOptions.pageSizes,
|
|
428
|
+
renderItem: nextOptions.renderItem,
|
|
429
|
+
target: isElement(nextOptions.target) ? nextOptions.target : null,
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
paginationOptions.set(rootElement, normalizedOptions);
|
|
433
|
+
|
|
434
|
+
if (paginationState.has(rootElement)) {
|
|
435
|
+
const state = paginationState.get(rootElement);
|
|
436
|
+
|
|
437
|
+
/* v8 ignore next -- repeated setup may update page size or preserve existing state */
|
|
438
|
+
if (state && options.pageSize) {
|
|
439
|
+
state.page = 1;
|
|
440
|
+
state.pageSize = nextOptions.pageSize;
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
paginationState.set(rootElement, {
|
|
444
|
+
page: getPaginationNumber(rootElement.getAttribute("data-page"), 1),
|
|
445
|
+
pageSize: nextOptions.pageSize,
|
|
446
|
+
request: 0,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (!wiredPaginations.has(rootElement)) {
|
|
451
|
+
wiredPaginations.add(rootElement);
|
|
452
|
+
listen(rootElement, "click", handlePaginationClick as EventListener);
|
|
453
|
+
listen(rootElement, "change", handlePaginationChange);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
updatePagination(rootElement);
|
|
457
|
+
|
|
458
|
+
return rootElement;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
legacy.pagination = {
|
|
462
|
+
setup(target, options) {
|
|
463
|
+
return setupPagination(target, options);
|
|
464
|
+
},
|
|
465
|
+
goTo(target, page) {
|
|
466
|
+
return setPaginationPage(resolvePagination(target), page);
|
|
467
|
+
},
|
|
468
|
+
pageSize(target, pageSize) {
|
|
469
|
+
return setPaginationPageSize(resolvePagination(target), pageSize);
|
|
470
|
+
},
|
|
471
|
+
refresh(target) {
|
|
472
|
+
return updatePagination(resolvePagination(target));
|
|
473
|
+
},
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
477
|
+
document.querySelectorAll("[data-pagination]").forEach((rootElement) => {
|
|
478
|
+
setupPagination(rootElement);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
}
|