coralite-plugin-aggregation 0.8.0 → 0.10.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 +328 -661
- package/lib/components/coralite-pagination.html +99 -0
- package/lib/index.js +196 -239
- package/package.json +3 -6
- package/types/index.js +2 -2
- package/lib/templates/coralite-pagination.html +0 -123
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
<template id="coralite-pagination">
|
|
2
|
-
<nav aria-label="{{ ariaLabel }}">
|
|
3
|
-
<ul class="pagination">
|
|
4
|
-
{{ paginationLinks }}
|
|
5
|
-
</ul>
|
|
6
|
-
</nav>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script type="module">
|
|
10
|
-
import { defineComponent } from 'coralite'
|
|
11
|
-
|
|
12
|
-
export default defineComponent({
|
|
13
|
-
tokens: {
|
|
14
|
-
ariaLabel(context) {
|
|
15
|
-
return context['aria-label'] || 'Page navigation'
|
|
16
|
-
},
|
|
17
|
-
/**
|
|
18
|
-
* Generates HTML pagination links based on the provided context.
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} context - The context object containing pagination details.
|
|
21
|
-
* @param {string} context['current-page'] - The current page number (1-based).
|
|
22
|
-
* @param {string} context['total-pages'] - The total number of pages.
|
|
23
|
-
* @param {string} context['base-url'] - The explicit URL for Page 1 (e.g., '/blog.html').
|
|
24
|
-
* @param {string} context['url-prefix'] - The directory prefix for paginated segments (e.g., '/blog').
|
|
25
|
-
* @param {string} [context.segment='page'] - The URL segment for pagination (default: 'page').
|
|
26
|
-
* @param {string} [context.max-visible='5'] - Max number of direct page links to show.
|
|
27
|
-
* @param {string} [context.ellipsis='...'] - Text to display for skipped pages.
|
|
28
|
-
* @returns {string} - A string containing the HTML <li> elements.
|
|
29
|
-
*/
|
|
30
|
-
paginationLinks(context) {
|
|
31
|
-
// Parse inputs with defaults
|
|
32
|
-
const currentPage = parseInt(context['current-page'] || '1', 10)
|
|
33
|
-
const totalPages = parseInt(context['total-pages'] || '1', 10)
|
|
34
|
-
const maxVisible = parseInt(context['max-visible'] || '5', 10)
|
|
35
|
-
|
|
36
|
-
const baseUrl = context['base-url'] || ''
|
|
37
|
-
const urlPrefix = context['url-prefix'] || ''
|
|
38
|
-
const segment = context['segment'] || 'page'
|
|
39
|
-
const ellipsis = context['ellipsis'] || '...'
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Constructs the URL for a specific page.
|
|
43
|
-
* 1. Page 1 links strictly to `base-url` (canonical root).
|
|
44
|
-
* 2. Pages > 1 follow the pattern: `{url-prefix}/{segment}/{page}.html`.
|
|
45
|
-
*/
|
|
46
|
-
const getPageUrl = (page) => {
|
|
47
|
-
if (page === 1) {
|
|
48
|
-
return baseUrl
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Ensure prefix has a trailing slash for concatenation
|
|
52
|
-
const cleanPrefix = urlPrefix.endsWith('/') ? urlPrefix : `${urlPrefix}/`
|
|
53
|
-
return `${cleanPrefix}${segment}/${page}.html`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Helper to generate list items
|
|
57
|
-
const createItem = (page, text, isActive, isDisabled) => {
|
|
58
|
-
let className = 'page-item'
|
|
59
|
-
if (isActive) className += ' active'
|
|
60
|
-
if (isDisabled) className += ' disabled'
|
|
61
|
-
|
|
62
|
-
let attr = ''
|
|
63
|
-
if (isActive) attr += ' aria-current="page"'
|
|
64
|
-
if (isDisabled) attr += ' tabindex="-1" aria-disabled="true"'
|
|
65
|
-
|
|
66
|
-
const href = isDisabled ? '#' : getPageUrl(page)
|
|
67
|
-
|
|
68
|
-
return `<li class="${className}"><a class="page-link" href="${href}"${attr}>${text}</a></li>`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let links = ''
|
|
72
|
-
|
|
73
|
-
// Previous Link
|
|
74
|
-
links += createItem(currentPage - 1, 'Previous', false, currentPage <= 1)
|
|
75
|
-
|
|
76
|
-
// Calculate Window (Start/End)
|
|
77
|
-
const half = Math.floor(maxVisible / 2)
|
|
78
|
-
let start = currentPage - half
|
|
79
|
-
let end = currentPage + half
|
|
80
|
-
|
|
81
|
-
if (start < 1) {
|
|
82
|
-
start = 1
|
|
83
|
-
end = Math.min(totalPages, maxVisible)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (end > totalPages) {
|
|
87
|
-
end = totalPages
|
|
88
|
-
start = Math.max(1, totalPages - maxVisible + 1)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Render Pages with ellipsis
|
|
92
|
-
const showFirst = start > 1
|
|
93
|
-
const showLast = end < totalPages
|
|
94
|
-
|
|
95
|
-
// First page + ellipsis if window doesn't touch start
|
|
96
|
-
if (showFirst) {
|
|
97
|
-
links += createItem(1, '1', false, false)
|
|
98
|
-
if (start > 2) {
|
|
99
|
-
links += `<li class="page-item disabled"><span class="page-link">${ellipsis}</span></li>`
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Main window loop
|
|
104
|
-
for (let i = start; i <= end; i++) {
|
|
105
|
-
links += createItem(i, i, i === currentPage, false)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Last page + ellipsis if window doesn't touch end
|
|
109
|
-
if (showLast) {
|
|
110
|
-
if (end < totalPages - 1) {
|
|
111
|
-
links += `<li class="page-item disabled"><span class="page-link">${ellipsis}</span></li>`
|
|
112
|
-
}
|
|
113
|
-
links += createItem(totalPages, totalPages, false, false)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Next Link
|
|
117
|
-
links += createItem(currentPage + 1, 'Next', false, currentPage >= totalPages)
|
|
118
|
-
|
|
119
|
-
return links
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
</script>
|