@slickgrid-universal/pagination-component 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./slick-pagination.component"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./slick-pagination.component"), exports);
18
18
  //# sourceMappingURL=index.js.map
@@ -1,295 +1,295 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlickPaginationComponent = void 0;
4
- const common_1 = require("@slickgrid-universal/common");
5
- const binding_1 = require("@slickgrid-universal/binding");
6
- class SlickPaginationComponent {
7
- constructor(paginationService, pubSubService, sharedService, translaterService) {
8
- var _a, _b, _c, _d, _e;
9
- this.paginationService = paginationService;
10
- this.pubSubService = pubSubService;
11
- this.sharedService = sharedService;
12
- this.translaterService = translaterService;
13
- this._enableTranslate = false;
14
- this._subscriptions = [];
15
- this.firstButtonClasses = '';
16
- this.lastButtonClasses = '';
17
- this.prevButtonClasses = '';
18
- this.nextButtonClasses = '';
19
- // text translations (handled by i18n or by custom locale)
20
- this.textItemsPerPage = 'items per page';
21
- this.textItems = 'items';
22
- this.textOf = 'of';
23
- this.textPage = 'Page';
24
- this._bindingHelper = new binding_1.BindingHelper();
25
- this._bindingHelper.querySelectorPrefix = `.${this.gridUid} `;
26
- this.currentPagination = this.paginationService.getFullPagination();
27
- this._enableTranslate = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.enableTranslate) !== null && _b !== void 0 ? _b : false;
28
- if (this._enableTranslate && (!this.translaterService || !this.translaterService.translate)) {
29
- throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.');
30
- }
31
- this.translatePaginationTexts();
32
- if (this._enableTranslate && ((_c = this.pubSubService) === null || _c === void 0 ? void 0 : _c.subscribe)) {
33
- const translateEventName = (_e = (_d = this.translaterService) === null || _d === void 0 ? void 0 : _d.eventName) !== null && _e !== void 0 ? _e : 'onLanguageChange';
34
- this._subscriptions.push(this.pubSubService.subscribe(translateEventName, () => this.translatePaginationTexts()));
35
- }
36
- // Anytime the pagination is initialized or has changes,
37
- // we'll copy the data into a local object so that we can add binding to this local object
38
- this._subscriptions.push(this.pubSubService.subscribe('onPaginationRefreshed', paginationChanges => {
39
- for (const key of Object.keys(paginationChanges)) {
40
- this.currentPagination[key] = paginationChanges[key];
41
- }
42
- this.updatePageButtonsUsability();
43
- const pageFromToElm = document.querySelector(`.${this.gridUid} span.page-info-from-to`);
44
- if (pageFromToElm === null || pageFromToElm === void 0 ? void 0 : pageFromToElm.style) {
45
- pageFromToElm.style.display = (this.currentPagination.totalItems === 0) ? 'none' : '';
46
- }
47
- }));
48
- }
49
- get availablePageSizes() {
50
- return this.paginationService.availablePageSizes || [];
51
- }
52
- get dataFrom() {
53
- return this.paginationService.dataFrom;
54
- }
55
- get dataTo() {
56
- return this.paginationService.dataTo;
57
- }
58
- get itemsPerPage() {
59
- return this.paginationService.itemsPerPage;
60
- }
61
- set itemsPerPage(count) {
62
- this.paginationService.changeItemPerPage(count);
63
- }
64
- get pageCount() {
65
- return this.paginationService.pageCount;
66
- }
67
- get pageNumber() {
68
- return this.paginationService.pageNumber;
69
- }
70
- set pageNumber(_page) {
71
- // the setter has to be declared but we won't use it, instead we will use the "changeToCurrentPage()" to only update the value after ENTER keydown event
72
- }
73
- get grid() {
74
- return this.sharedService.slickGrid;
75
- }
76
- get gridOptions() {
77
- return this.sharedService.gridOptions;
78
- }
79
- get gridUid() {
80
- var _a, _b;
81
- return (_b = (_a = this.grid) === null || _a === void 0 ? void 0 : _a.getUID()) !== null && _b !== void 0 ? _b : '';
82
- }
83
- get locales() {
84
- var _a, _b;
85
- // get locales provided by user in main file or else use default English locales via the Constants
86
- return (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.locales) !== null && _b !== void 0 ? _b : common_1.Constants.locales;
87
- }
88
- get totalItems() {
89
- return this.paginationService.totalItems;
90
- }
91
- get isLeftPaginationDisabled() {
92
- return this.pageNumber === 1 || this.totalItems === 0;
93
- }
94
- get isRightPaginationDisabled() {
95
- return this.pageNumber === this.pageCount || this.totalItems === 0;
96
- }
97
- dispose() {
98
- // also dispose of all Subscriptions
99
- this.pubSubService.unsubscribeAll(this._subscriptions);
100
- this._bindingHelper.dispose();
101
- this._paginationElement.remove();
102
- }
103
- renderPagination(gridParentContainerElm) {
104
- const paginationElm = this.createPaginationContainer();
105
- const divNavContainerElm = (0, common_1.createDomElement)('div', { className: 'slick-pagination-nav' });
106
- const leftNavigationElm = this.createPageNavigation('Page navigation', [
107
- { liClass: 'page-item seek-first', aClass: 'page-link icon-seek-first', ariaLabel: 'First Page' },
108
- { liClass: 'page-item seek-prev', aClass: 'page-link icon-seek-prev', ariaLabel: 'Previous Page' },
109
- ]);
110
- const pageNumberSectionElm = this.createPageNumberSection();
111
- const rightNavigationElm = this.createPageNavigation('Page navigation', [
112
- { liClass: 'page-item seek-next', aClass: 'page-link icon-seek-next', ariaLabel: 'Next Page' },
113
- { liClass: 'page-item seek-end', aClass: 'page-link icon-seek-end', ariaLabel: 'Last Page' },
114
- ]);
115
- paginationElm.appendChild(divNavContainerElm);
116
- divNavContainerElm.appendChild(leftNavigationElm);
117
- divNavContainerElm.appendChild(pageNumberSectionElm);
118
- divNavContainerElm.appendChild(rightNavigationElm);
119
- const paginationSettingsElm = this.createPaginationSettingsSection();
120
- paginationElm.appendChild(divNavContainerElm);
121
- paginationElm.appendChild(paginationSettingsElm);
122
- this._paginationElement.appendChild(paginationElm);
123
- if ((gridParentContainerElm === null || gridParentContainerElm === void 0 ? void 0 : gridParentContainerElm.appendChild) && this._paginationElement) {
124
- gridParentContainerElm.appendChild(this._paginationElement);
125
- }
126
- this.renderPageSizes();
127
- this.addBindings();
128
- this.addEventListeners();
129
- this.updatePageButtonsUsability();
130
- }
131
- /** Render and fill the Page Sizes <select> element */
132
- renderPageSizes() {
133
- const selectElm = document.querySelector(`.${this.gridUid} .items-per-page`);
134
- if (selectElm && Array.isArray(this.availablePageSizes)) {
135
- for (const option of this.availablePageSizes) {
136
- selectElm.appendChild((0, common_1.createDomElement)('option', { value: `${option}`, text: `${option}` }));
137
- }
138
- }
139
- }
140
- /** Add some DOM Element bindings */
141
- addBindings() {
142
- this._bindingHelper.addElementBinding(this, 'firstButtonClasses', 'li.page-item.seek-first', 'className');
143
- this._bindingHelper.addElementBinding(this, 'prevButtonClasses', 'li.page-item.seek-prev', 'className');
144
- this._bindingHelper.addElementBinding(this, 'lastButtonClasses', 'li.page-item.seek-end', 'className');
145
- this._bindingHelper.addElementBinding(this, 'nextButtonClasses', 'li.page-item.seek-next', 'className');
146
- this._bindingHelper.addElementBinding(this.currentPagination, 'dataFrom', 'span.item-from', 'textContent');
147
- this._bindingHelper.addElementBinding(this.currentPagination, 'dataTo', 'span.item-to', 'textContent');
148
- this._bindingHelper.addElementBinding(this.currentPagination, 'totalItems', 'span.total-items', 'textContent');
149
- this._bindingHelper.addElementBinding(this.currentPagination, 'pageCount', 'span.page-count', 'textContent');
150
- this._bindingHelper.addElementBinding(this.currentPagination, 'pageNumber', 'input.page-number', 'value', 'change', this.changeToCurrentPage.bind(this));
151
- this._bindingHelper.addElementBinding(this.currentPagination, 'pageSize', 'select.items-per-page', 'value');
152
- // locale text changes
153
- this._bindingHelper.addElementBinding(this, 'textItems', 'span.text-items', 'textContent');
154
- this._bindingHelper.addElementBinding(this, 'textItemsPerPage', 'span.text-item-per-page', 'textContent');
155
- this._bindingHelper.addElementBinding(this, 'textOf', 'span.text-of', 'textContent');
156
- this._bindingHelper.addElementBinding(this, 'textPage', 'span.text-page', 'textContent');
157
- }
158
- /** Add some DOM Element event listeners */
159
- addEventListeners() {
160
- this._bindingHelper.bindEventHandler('.icon-seek-first', 'click', this.changeToFirstPage.bind(this));
161
- this._bindingHelper.bindEventHandler('.icon-seek-end', 'click', this.changeToLastPage.bind(this));
162
- this._bindingHelper.bindEventHandler('.icon-seek-next', 'click', this.changeToNextPage.bind(this));
163
- this._bindingHelper.bindEventHandler('.icon-seek-prev', 'click', this.changeToPreviousPage.bind(this));
164
- this._bindingHelper.bindEventHandler('select.items-per-page', 'change', (event) => { var _a, _b; return this.itemsPerPage = +((_b = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); });
165
- }
166
- changeToFirstPage(event) {
167
- if (!this.isLeftPaginationDisabled) {
168
- this.paginationService.goToFirstPage(event);
169
- }
170
- }
171
- changeToLastPage(event) {
172
- if (!this.isRightPaginationDisabled) {
173
- this.paginationService.goToLastPage(event);
174
- }
175
- }
176
- changeToNextPage(event) {
177
- if (!this.isRightPaginationDisabled) {
178
- this.paginationService.goToNextPage(event);
179
- }
180
- }
181
- changeToPreviousPage(event) {
182
- if (!this.isLeftPaginationDisabled) {
183
- this.paginationService.goToPreviousPage(event);
184
- }
185
- }
186
- changeToCurrentPage(pageNumber) {
187
- this.paginationService.goToPageNumber(+pageNumber);
188
- }
189
- /** Translate all the texts shown in the UI, use ngx-translate service when available or custom locales when service is null */
190
- translatePaginationTexts() {
191
- var _a;
192
- if (this._enableTranslate && ((_a = this.translaterService) === null || _a === void 0 ? void 0 : _a.translate)) {
193
- const translationPrefix = (0, common_1.getTranslationPrefix)(this.gridOptions);
194
- this.textItemsPerPage = this.translaterService.translate(`${translationPrefix}ITEMS_PER_PAGE`);
195
- this.textItems = this.translaterService.translate(`${translationPrefix}ITEMS`);
196
- this.textOf = this.translaterService.translate(`${translationPrefix}OF`);
197
- this.textPage = this.translaterService.translate(`${translationPrefix}PAGE`);
198
- }
199
- else if (this.locales) {
200
- this.textItemsPerPage = this.locales.TEXT_ITEMS_PER_PAGE || 'TEXT_ITEMS_PER_PAGE';
201
- this.textItems = this.locales.TEXT_ITEMS || 'TEXT_ITEMS';
202
- this.textOf = this.locales.TEXT_OF || 'TEXT_OF';
203
- this.textPage = this.locales.TEXT_PAGE || 'TEXT_PAGE';
204
- }
205
- }
206
- // --
207
- // protected functions
208
- // --------------------
209
- /** Create the Pagination Container */
210
- createPaginationContainer() {
211
- const paginationContainerElm = (0, common_1.createDomElement)('div', {
212
- id: 'pager', className: `slick-pagination-container ${this.gridUid} pager`,
213
- style: { width: '100%' },
214
- });
215
- const paginationElm = (0, common_1.createDomElement)('div', { className: 'slick-pagination' });
216
- paginationContainerElm.appendChild(paginationElm);
217
- this._paginationElement = paginationContainerElm; // keep internal ref
218
- return paginationElm;
219
- }
220
- createPageNavigation(navAriaLabel, liElements) {
221
- const navElm = (0, common_1.createDomElement)('nav', { ariaLabel: navAriaLabel });
222
- const ulElm = (0, common_1.createDomElement)('ul', { className: 'pagination' });
223
- for (const li of liElements) {
224
- const liElm = (0, common_1.createDomElement)('li', { className: li.liClass });
225
- const aElm = (0, common_1.createDomElement)('a', { className: li.aClass });
226
- aElm.setAttribute('aria-label', li.ariaLabel);
227
- liElm.appendChild(aElm);
228
- ulElm.appendChild(liElm);
229
- }
230
- navElm.appendChild(ulElm);
231
- return navElm;
232
- }
233
- createPageNumberSection() {
234
- const divElm = (0, common_1.createDomElement)('div', { className: 'slick-page-number' });
235
- const spanTextPageElm = (0, common_1.createDomElement)('span', { className: 'text-page', textContent: 'Page' });
236
- const input = (0, common_1.createDomElement)('input', {
237
- type: 'text', className: 'form-control page-number',
238
- value: '1', size: 1,
239
- dataset: { test: 'page-number-input' },
240
- });
241
- input.setAttribute('aria-label', 'Page Number');
242
- const spanTextOfElm = (0, common_1.createDomElement)('span', { className: 'text-of', textContent: 'of' });
243
- const spanPageCountElm = (0, common_1.createDomElement)('span', { className: 'page-count', dataset: { test: 'page-count' } });
244
- divElm.appendChild(spanTextPageElm);
245
- divElm.appendChild(document.createTextNode(' '));
246
- divElm.appendChild(input);
247
- divElm.appendChild(document.createTextNode(' '));
248
- divElm.appendChild(spanTextOfElm);
249
- divElm.appendChild(document.createTextNode(' '));
250
- divElm.appendChild(spanPageCountElm);
251
- return divElm;
252
- }
253
- createPaginationSettingsSection() {
254
- const spanContainerElm = (0, common_1.createDomElement)('span', { className: 'slick-pagination-settings' });
255
- const selectElm = (0, common_1.createDomElement)('select', { id: 'items-per-page-label', className: 'items-per-page' });
256
- selectElm.setAttribute('aria-label', 'Items per Page Select');
257
- const spanItemPerPageElm = (0, common_1.createDomElement)('span', { className: 'text-item-per-page', textContent: 'items per page' });
258
- const spanPaginationCount = (0, common_1.createDomElement)('span', { className: 'slick-pagination-count' });
259
- const spanInfoFromToElm = (0, common_1.createDomElement)('span', { className: 'page-info-from-to' });
260
- const spanItemFromElm = (0, common_1.createDomElement)('span', { className: 'item-from', dataset: { test: 'item-from' } });
261
- spanItemFromElm.setAttribute('aria-label', 'Page Item From');
262
- const spanItemToElm = (0, common_1.createDomElement)('span', { className: 'item-to', dataset: { test: 'item-to' } });
263
- spanItemToElm.setAttribute('aria-label', 'Page Item To');
264
- const spanOfElm = (0, common_1.createDomElement)('span', { className: 'text-of', textContent: 'of' });
265
- const spanInfoTotalElm = (0, common_1.createDomElement)('span', { className: 'page-info-total-items' });
266
- const spanTotalItem = (0, common_1.createDomElement)('span', { className: 'total-items', dataset: { test: 'total-items' } });
267
- const spanTextItemsElm = (0, common_1.createDomElement)('span', { className: 'text-items', textContent: 'items' });
268
- spanContainerElm.appendChild(selectElm);
269
- spanContainerElm.appendChild(document.createTextNode(' '));
270
- spanContainerElm.appendChild(spanItemPerPageElm);
271
- spanContainerElm.appendChild(document.createTextNode(', '));
272
- spanInfoFromToElm.appendChild(spanItemFromElm);
273
- spanInfoFromToElm.appendChild(document.createTextNode('-'));
274
- spanInfoFromToElm.appendChild(spanItemToElm);
275
- spanInfoFromToElm.appendChild(document.createTextNode(' '));
276
- spanInfoFromToElm.appendChild(spanOfElm);
277
- spanInfoFromToElm.appendChild(document.createTextNode(' '));
278
- spanPaginationCount.appendChild(spanInfoFromToElm);
279
- spanContainerElm.appendChild(spanPaginationCount);
280
- spanInfoTotalElm.appendChild(spanTotalItem);
281
- spanInfoTotalElm.appendChild(document.createTextNode(' '));
282
- spanInfoTotalElm.appendChild(spanTextItemsElm);
283
- spanInfoTotalElm.appendChild(document.createTextNode(' '));
284
- spanPaginationCount.appendChild(spanInfoTotalElm);
285
- return spanContainerElm;
286
- }
287
- updatePageButtonsUsability() {
288
- this.firstButtonClasses = this.isLeftPaginationDisabled ? 'page-item seek-first disabled' : 'page-item seek-first';
289
- this.prevButtonClasses = this.isLeftPaginationDisabled ? 'page-item seek-prev disabled' : 'page-item seek-prev';
290
- this.lastButtonClasses = this.isRightPaginationDisabled ? 'page-item seek-end disabled' : 'page-item seek-end';
291
- this.nextButtonClasses = this.isRightPaginationDisabled ? 'page-item seek-next disabled' : 'page-item seek-next';
292
- }
293
- }
294
- exports.SlickPaginationComponent = SlickPaginationComponent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SlickPaginationComponent = void 0;
4
+ const common_1 = require("@slickgrid-universal/common");
5
+ const binding_1 = require("@slickgrid-universal/binding");
6
+ class SlickPaginationComponent {
7
+ constructor(paginationService, pubSubService, sharedService, translaterService) {
8
+ var _a, _b, _c, _d, _e;
9
+ this.paginationService = paginationService;
10
+ this.pubSubService = pubSubService;
11
+ this.sharedService = sharedService;
12
+ this.translaterService = translaterService;
13
+ this._enableTranslate = false;
14
+ this._subscriptions = [];
15
+ this.firstButtonClasses = '';
16
+ this.lastButtonClasses = '';
17
+ this.prevButtonClasses = '';
18
+ this.nextButtonClasses = '';
19
+ // text translations (handled by i18n or by custom locale)
20
+ this.textItemsPerPage = 'items per page';
21
+ this.textItems = 'items';
22
+ this.textOf = 'of';
23
+ this.textPage = 'Page';
24
+ this._bindingHelper = new binding_1.BindingHelper();
25
+ this._bindingHelper.querySelectorPrefix = `.${this.gridUid} `;
26
+ this.currentPagination = this.paginationService.getFullPagination();
27
+ this._enableTranslate = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.enableTranslate) !== null && _b !== void 0 ? _b : false;
28
+ if (this._enableTranslate && (!this.translaterService || !this.translaterService.translate)) {
29
+ throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.');
30
+ }
31
+ this.translatePaginationTexts();
32
+ if (this._enableTranslate && ((_c = this.pubSubService) === null || _c === void 0 ? void 0 : _c.subscribe)) {
33
+ const translateEventName = (_e = (_d = this.translaterService) === null || _d === void 0 ? void 0 : _d.eventName) !== null && _e !== void 0 ? _e : 'onLanguageChange';
34
+ this._subscriptions.push(this.pubSubService.subscribe(translateEventName, () => this.translatePaginationTexts()));
35
+ }
36
+ // Anytime the pagination is initialized or has changes,
37
+ // we'll copy the data into a local object so that we can add binding to this local object
38
+ this._subscriptions.push(this.pubSubService.subscribe('onPaginationRefreshed', paginationChanges => {
39
+ for (const key of Object.keys(paginationChanges)) {
40
+ this.currentPagination[key] = paginationChanges[key];
41
+ }
42
+ this.updatePageButtonsUsability();
43
+ const pageFromToElm = document.querySelector(`.${this.gridUid} span.page-info-from-to`);
44
+ if (pageFromToElm === null || pageFromToElm === void 0 ? void 0 : pageFromToElm.style) {
45
+ pageFromToElm.style.display = (this.currentPagination.totalItems === 0) ? 'none' : '';
46
+ }
47
+ }));
48
+ }
49
+ get availablePageSizes() {
50
+ return this.paginationService.availablePageSizes || [];
51
+ }
52
+ get dataFrom() {
53
+ return this.paginationService.dataFrom;
54
+ }
55
+ get dataTo() {
56
+ return this.paginationService.dataTo;
57
+ }
58
+ get itemsPerPage() {
59
+ return this.paginationService.itemsPerPage;
60
+ }
61
+ set itemsPerPage(count) {
62
+ this.paginationService.changeItemPerPage(count);
63
+ }
64
+ get pageCount() {
65
+ return this.paginationService.pageCount;
66
+ }
67
+ get pageNumber() {
68
+ return this.paginationService.pageNumber;
69
+ }
70
+ set pageNumber(_page) {
71
+ // the setter has to be declared but we won't use it, instead we will use the "changeToCurrentPage()" to only update the value after ENTER keydown event
72
+ }
73
+ get grid() {
74
+ return this.sharedService.slickGrid;
75
+ }
76
+ get gridOptions() {
77
+ return this.sharedService.gridOptions;
78
+ }
79
+ get gridUid() {
80
+ var _a, _b;
81
+ return (_b = (_a = this.grid) === null || _a === void 0 ? void 0 : _a.getUID()) !== null && _b !== void 0 ? _b : '';
82
+ }
83
+ get locales() {
84
+ var _a, _b;
85
+ // get locales provided by user in main file or else use default English locales via the Constants
86
+ return (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.locales) !== null && _b !== void 0 ? _b : common_1.Constants.locales;
87
+ }
88
+ get totalItems() {
89
+ return this.paginationService.totalItems;
90
+ }
91
+ get isLeftPaginationDisabled() {
92
+ return this.pageNumber === 1 || this.totalItems === 0;
93
+ }
94
+ get isRightPaginationDisabled() {
95
+ return this.pageNumber === this.pageCount || this.totalItems === 0;
96
+ }
97
+ dispose() {
98
+ // also dispose of all Subscriptions
99
+ this.pubSubService.unsubscribeAll(this._subscriptions);
100
+ this._bindingHelper.dispose();
101
+ this._paginationElement.remove();
102
+ }
103
+ renderPagination(gridParentContainerElm) {
104
+ const paginationElm = this.createPaginationContainer();
105
+ const divNavContainerElm = (0, common_1.createDomElement)('div', { className: 'slick-pagination-nav' });
106
+ const leftNavigationElm = this.createPageNavigation('Page navigation', [
107
+ { liClass: 'page-item seek-first', aClass: 'page-link icon-seek-first', ariaLabel: 'First Page' },
108
+ { liClass: 'page-item seek-prev', aClass: 'page-link icon-seek-prev', ariaLabel: 'Previous Page' },
109
+ ]);
110
+ const pageNumberSectionElm = this.createPageNumberSection();
111
+ const rightNavigationElm = this.createPageNavigation('Page navigation', [
112
+ { liClass: 'page-item seek-next', aClass: 'page-link icon-seek-next', ariaLabel: 'Next Page' },
113
+ { liClass: 'page-item seek-end', aClass: 'page-link icon-seek-end', ariaLabel: 'Last Page' },
114
+ ]);
115
+ paginationElm.appendChild(divNavContainerElm);
116
+ divNavContainerElm.appendChild(leftNavigationElm);
117
+ divNavContainerElm.appendChild(pageNumberSectionElm);
118
+ divNavContainerElm.appendChild(rightNavigationElm);
119
+ const paginationSettingsElm = this.createPaginationSettingsSection();
120
+ paginationElm.appendChild(divNavContainerElm);
121
+ paginationElm.appendChild(paginationSettingsElm);
122
+ this._paginationElement.appendChild(paginationElm);
123
+ if ((gridParentContainerElm === null || gridParentContainerElm === void 0 ? void 0 : gridParentContainerElm.appendChild) && this._paginationElement) {
124
+ gridParentContainerElm.appendChild(this._paginationElement);
125
+ }
126
+ this.renderPageSizes();
127
+ this.addBindings();
128
+ this.addEventListeners();
129
+ this.updatePageButtonsUsability();
130
+ }
131
+ /** Render and fill the Page Sizes <select> element */
132
+ renderPageSizes() {
133
+ const selectElm = document.querySelector(`.${this.gridUid} .items-per-page`);
134
+ if (selectElm && Array.isArray(this.availablePageSizes)) {
135
+ for (const option of this.availablePageSizes) {
136
+ selectElm.appendChild((0, common_1.createDomElement)('option', { value: `${option}`, text: `${option}` }));
137
+ }
138
+ }
139
+ }
140
+ /** Add some DOM Element bindings */
141
+ addBindings() {
142
+ this._bindingHelper.addElementBinding(this, 'firstButtonClasses', 'li.page-item.seek-first', 'className');
143
+ this._bindingHelper.addElementBinding(this, 'prevButtonClasses', 'li.page-item.seek-prev', 'className');
144
+ this._bindingHelper.addElementBinding(this, 'lastButtonClasses', 'li.page-item.seek-end', 'className');
145
+ this._bindingHelper.addElementBinding(this, 'nextButtonClasses', 'li.page-item.seek-next', 'className');
146
+ this._bindingHelper.addElementBinding(this.currentPagination, 'dataFrom', 'span.item-from', 'textContent');
147
+ this._bindingHelper.addElementBinding(this.currentPagination, 'dataTo', 'span.item-to', 'textContent');
148
+ this._bindingHelper.addElementBinding(this.currentPagination, 'totalItems', 'span.total-items', 'textContent');
149
+ this._bindingHelper.addElementBinding(this.currentPagination, 'pageCount', 'span.page-count', 'textContent');
150
+ this._bindingHelper.addElementBinding(this.currentPagination, 'pageNumber', 'input.page-number', 'value', 'change', this.changeToCurrentPage.bind(this));
151
+ this._bindingHelper.addElementBinding(this.currentPagination, 'pageSize', 'select.items-per-page', 'value');
152
+ // locale text changes
153
+ this._bindingHelper.addElementBinding(this, 'textItems', 'span.text-items', 'textContent');
154
+ this._bindingHelper.addElementBinding(this, 'textItemsPerPage', 'span.text-item-per-page', 'textContent');
155
+ this._bindingHelper.addElementBinding(this, 'textOf', 'span.text-of', 'textContent');
156
+ this._bindingHelper.addElementBinding(this, 'textPage', 'span.text-page', 'textContent');
157
+ }
158
+ /** Add some DOM Element event listeners */
159
+ addEventListeners() {
160
+ this._bindingHelper.bindEventHandler('.icon-seek-first', 'click', this.changeToFirstPage.bind(this));
161
+ this._bindingHelper.bindEventHandler('.icon-seek-end', 'click', this.changeToLastPage.bind(this));
162
+ this._bindingHelper.bindEventHandler('.icon-seek-next', 'click', this.changeToNextPage.bind(this));
163
+ this._bindingHelper.bindEventHandler('.icon-seek-prev', 'click', this.changeToPreviousPage.bind(this));
164
+ this._bindingHelper.bindEventHandler('select.items-per-page', 'change', (event) => { var _a, _b; return this.itemsPerPage = +((_b = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); });
165
+ }
166
+ changeToFirstPage(event) {
167
+ if (!this.isLeftPaginationDisabled) {
168
+ this.paginationService.goToFirstPage(event);
169
+ }
170
+ }
171
+ changeToLastPage(event) {
172
+ if (!this.isRightPaginationDisabled) {
173
+ this.paginationService.goToLastPage(event);
174
+ }
175
+ }
176
+ changeToNextPage(event) {
177
+ if (!this.isRightPaginationDisabled) {
178
+ this.paginationService.goToNextPage(event);
179
+ }
180
+ }
181
+ changeToPreviousPage(event) {
182
+ if (!this.isLeftPaginationDisabled) {
183
+ this.paginationService.goToPreviousPage(event);
184
+ }
185
+ }
186
+ changeToCurrentPage(pageNumber) {
187
+ this.paginationService.goToPageNumber(+pageNumber);
188
+ }
189
+ /** Translate all the texts shown in the UI, use ngx-translate service when available or custom locales when service is null */
190
+ translatePaginationTexts() {
191
+ var _a;
192
+ if (this._enableTranslate && ((_a = this.translaterService) === null || _a === void 0 ? void 0 : _a.translate)) {
193
+ const translationPrefix = (0, common_1.getTranslationPrefix)(this.gridOptions);
194
+ this.textItemsPerPage = this.translaterService.translate(`${translationPrefix}ITEMS_PER_PAGE`);
195
+ this.textItems = this.translaterService.translate(`${translationPrefix}ITEMS`);
196
+ this.textOf = this.translaterService.translate(`${translationPrefix}OF`);
197
+ this.textPage = this.translaterService.translate(`${translationPrefix}PAGE`);
198
+ }
199
+ else if (this.locales) {
200
+ this.textItemsPerPage = this.locales.TEXT_ITEMS_PER_PAGE || 'TEXT_ITEMS_PER_PAGE';
201
+ this.textItems = this.locales.TEXT_ITEMS || 'TEXT_ITEMS';
202
+ this.textOf = this.locales.TEXT_OF || 'TEXT_OF';
203
+ this.textPage = this.locales.TEXT_PAGE || 'TEXT_PAGE';
204
+ }
205
+ }
206
+ // --
207
+ // protected functions
208
+ // --------------------
209
+ /** Create the Pagination Container */
210
+ createPaginationContainer() {
211
+ const paginationContainerElm = (0, common_1.createDomElement)('div', {
212
+ id: 'pager', className: `slick-pagination-container ${this.gridUid} pager`,
213
+ style: { width: '100%' },
214
+ });
215
+ const paginationElm = (0, common_1.createDomElement)('div', { className: 'slick-pagination' });
216
+ paginationContainerElm.appendChild(paginationElm);
217
+ this._paginationElement = paginationContainerElm; // keep internal ref
218
+ return paginationElm;
219
+ }
220
+ createPageNavigation(navAriaLabel, liElements) {
221
+ const navElm = (0, common_1.createDomElement)('nav', { ariaLabel: navAriaLabel });
222
+ const ulElm = (0, common_1.createDomElement)('ul', { className: 'pagination' });
223
+ for (const li of liElements) {
224
+ const liElm = (0, common_1.createDomElement)('li', { className: li.liClass });
225
+ const aElm = (0, common_1.createDomElement)('a', { className: li.aClass });
226
+ aElm.setAttribute('aria-label', li.ariaLabel);
227
+ liElm.appendChild(aElm);
228
+ ulElm.appendChild(liElm);
229
+ }
230
+ navElm.appendChild(ulElm);
231
+ return navElm;
232
+ }
233
+ createPageNumberSection() {
234
+ const divElm = (0, common_1.createDomElement)('div', { className: 'slick-page-number' });
235
+ const spanTextPageElm = (0, common_1.createDomElement)('span', { className: 'text-page', textContent: 'Page' });
236
+ const input = (0, common_1.createDomElement)('input', {
237
+ type: 'text', className: 'form-control page-number',
238
+ value: '1', size: 1,
239
+ dataset: { test: 'page-number-input' },
240
+ });
241
+ input.setAttribute('aria-label', 'Page Number');
242
+ const spanTextOfElm = (0, common_1.createDomElement)('span', { className: 'text-of', textContent: 'of' });
243
+ const spanPageCountElm = (0, common_1.createDomElement)('span', { className: 'page-count', dataset: { test: 'page-count' } });
244
+ divElm.appendChild(spanTextPageElm);
245
+ divElm.appendChild(document.createTextNode(' '));
246
+ divElm.appendChild(input);
247
+ divElm.appendChild(document.createTextNode(' '));
248
+ divElm.appendChild(spanTextOfElm);
249
+ divElm.appendChild(document.createTextNode(' '));
250
+ divElm.appendChild(spanPageCountElm);
251
+ return divElm;
252
+ }
253
+ createPaginationSettingsSection() {
254
+ const spanContainerElm = (0, common_1.createDomElement)('span', { className: 'slick-pagination-settings' });
255
+ const selectElm = (0, common_1.createDomElement)('select', { id: 'items-per-page-label', className: 'items-per-page' });
256
+ selectElm.setAttribute('aria-label', 'Items per Page Select');
257
+ const spanItemPerPageElm = (0, common_1.createDomElement)('span', { className: 'text-item-per-page', textContent: 'items per page' });
258
+ const spanPaginationCount = (0, common_1.createDomElement)('span', { className: 'slick-pagination-count' });
259
+ const spanInfoFromToElm = (0, common_1.createDomElement)('span', { className: 'page-info-from-to' });
260
+ const spanItemFromElm = (0, common_1.createDomElement)('span', { className: 'item-from', dataset: { test: 'item-from' } });
261
+ spanItemFromElm.setAttribute('aria-label', 'Page Item From');
262
+ const spanItemToElm = (0, common_1.createDomElement)('span', { className: 'item-to', dataset: { test: 'item-to' } });
263
+ spanItemToElm.setAttribute('aria-label', 'Page Item To');
264
+ const spanOfElm = (0, common_1.createDomElement)('span', { className: 'text-of', textContent: 'of' });
265
+ const spanInfoTotalElm = (0, common_1.createDomElement)('span', { className: 'page-info-total-items' });
266
+ const spanTotalItem = (0, common_1.createDomElement)('span', { className: 'total-items', dataset: { test: 'total-items' } });
267
+ const spanTextItemsElm = (0, common_1.createDomElement)('span', { className: 'text-items', textContent: 'items' });
268
+ spanContainerElm.appendChild(selectElm);
269
+ spanContainerElm.appendChild(document.createTextNode(' '));
270
+ spanContainerElm.appendChild(spanItemPerPageElm);
271
+ spanContainerElm.appendChild(document.createTextNode(', '));
272
+ spanInfoFromToElm.appendChild(spanItemFromElm);
273
+ spanInfoFromToElm.appendChild(document.createTextNode('-'));
274
+ spanInfoFromToElm.appendChild(spanItemToElm);
275
+ spanInfoFromToElm.appendChild(document.createTextNode(' '));
276
+ spanInfoFromToElm.appendChild(spanOfElm);
277
+ spanInfoFromToElm.appendChild(document.createTextNode(' '));
278
+ spanPaginationCount.appendChild(spanInfoFromToElm);
279
+ spanContainerElm.appendChild(spanPaginationCount);
280
+ spanInfoTotalElm.appendChild(spanTotalItem);
281
+ spanInfoTotalElm.appendChild(document.createTextNode(' '));
282
+ spanInfoTotalElm.appendChild(spanTextItemsElm);
283
+ spanInfoTotalElm.appendChild(document.createTextNode(' '));
284
+ spanPaginationCount.appendChild(spanInfoTotalElm);
285
+ return spanContainerElm;
286
+ }
287
+ updatePageButtonsUsability() {
288
+ this.firstButtonClasses = this.isLeftPaginationDisabled ? 'page-item seek-first disabled' : 'page-item seek-first';
289
+ this.prevButtonClasses = this.isLeftPaginationDisabled ? 'page-item seek-prev disabled' : 'page-item seek-prev';
290
+ this.lastButtonClasses = this.isRightPaginationDisabled ? 'page-item seek-end disabled' : 'page-item seek-end';
291
+ this.nextButtonClasses = this.isRightPaginationDisabled ? 'page-item seek-next disabled' : 'page-item seek-next';
292
+ }
293
+ }
294
+ exports.SlickPaginationComponent = SlickPaginationComponent;
295
295
  //# sourceMappingURL=slick-pagination.component.js.map