@internetarchive/collection-browser 4.7.1-alpha-webdev9189.0 → 4.8.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.
Files changed (87) hide show
  1. package/dist/src/app-root.js +0 -2
  2. package/dist/src/app-root.js.map +1 -1
  3. package/dist/src/assets/img/icons/check.d.ts +2 -0
  4. package/dist/src/assets/img/icons/check.js +5 -0
  5. package/dist/src/assets/img/icons/check.js.map +1 -0
  6. package/dist/src/collection-browser.js +2 -24
  7. package/dist/src/collection-browser.js.map +1 -1
  8. package/dist/src/collection-facets/facet-row-template.d.ts +38 -0
  9. package/dist/src/collection-facets/facet-row-template.js +200 -0
  10. package/dist/src/collection-facets/facet-row-template.js.map +1 -0
  11. package/dist/src/collection-facets/facet-row.js +11 -186
  12. package/dist/src/collection-facets/facet-row.js.map +1 -1
  13. package/dist/src/collection-facets/models.d.ts +7 -2
  14. package/dist/src/collection-facets/models.js +7 -2
  15. package/dist/src/collection-facets/models.js.map +1 -1
  16. package/dist/src/collection-facets/more-facets-content.d.ts +87 -21
  17. package/dist/src/collection-facets/more-facets-content.js +477 -200
  18. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  19. package/dist/src/collection-facets/more-facets-scroller.d.ts +85 -0
  20. package/dist/src/collection-facets/more-facets-scroller.js +428 -0
  21. package/dist/src/collection-facets/more-facets-scroller.js.map +1 -0
  22. package/dist/src/collection-facets/page-window.d.ts +73 -0
  23. package/dist/src/collection-facets/page-window.js +202 -0
  24. package/dist/src/collection-facets/page-window.js.map +1 -0
  25. package/dist/src/collection-facets/toggle-switch.js +1 -0
  26. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  27. package/dist/src/models.d.ts +4 -0
  28. package/dist/src/models.js +16 -0
  29. package/dist/src/models.js.map +1 -1
  30. package/dist/src/sort-filter-bar/sort-filter-bar.js +0 -1
  31. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  32. package/dist/src/utils/log.d.ts +1 -4
  33. package/dist/src/utils/normalize-filter-text.d.ts +28 -0
  34. package/dist/src/utils/normalize-filter-text.js +35 -0
  35. package/dist/src/utils/normalize-filter-text.js.map +1 -0
  36. package/dist/test/collection-browser.test.js +0 -34
  37. package/dist/test/collection-browser.test.js.map +1 -1
  38. package/dist/test/collection-facets/more-facets-content.test.js +367 -17
  39. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  40. package/dist/test/collection-facets/more-facets-scroller.test.d.ts +1 -0
  41. package/dist/test/collection-facets/more-facets-scroller.test.js +288 -0
  42. package/dist/test/collection-facets/more-facets-scroller.test.js.map +1 -0
  43. package/dist/test/collection-facets/page-window.test.d.ts +1 -0
  44. package/dist/test/collection-facets/page-window.test.js +175 -0
  45. package/dist/test/collection-facets/page-window.test.js.map +1 -0
  46. package/dist/test/mocks/mock-search-responses.d.ts +6 -0
  47. package/dist/test/mocks/mock-search-responses.js +52 -0
  48. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  49. package/dist/test/mocks/mock-search-service.js +2 -1
  50. package/dist/test/mocks/mock-search-service.js.map +1 -1
  51. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +0 -22
  52. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  53. package/dist/test/utils/normalize-filter-text.test.d.ts +1 -0
  54. package/dist/test/utils/normalize-filter-text.test.js +69 -0
  55. package/dist/test/utils/normalize-filter-text.test.js.map +1 -0
  56. package/docs/design/column-virtualization.md +214 -0
  57. package/package.json +3 -1
  58. package/src/app-root.ts +0 -2
  59. package/src/assets/img/icons/check.ts +5 -0
  60. package/src/collection-browser.ts +4 -26
  61. package/src/collection-facets/facet-row-template.ts +242 -0
  62. package/src/collection-facets/facet-row.ts +15 -202
  63. package/src/collection-facets/models.ts +8 -2
  64. package/src/collection-facets/more-facets-content.ts +528 -221
  65. package/src/collection-facets/more-facets-scroller.ts +485 -0
  66. package/src/collection-facets/page-window.ts +247 -0
  67. package/src/collection-facets/toggle-switch.ts +1 -0
  68. package/src/models.ts +17 -0
  69. package/src/sort-filter-bar/sort-filter-bar.ts +0 -1
  70. package/src/utils/normalize-filter-text.ts +54 -0
  71. package/test/collection-browser.test.ts +0 -55
  72. package/test/collection-facets/more-facets-content.test.ts +509 -24
  73. package/test/collection-facets/more-facets-scroller.test.ts +401 -0
  74. package/test/collection-facets/page-window.test.ts +208 -0
  75. package/test/mocks/mock-search-responses.ts +56 -0
  76. package/test/mocks/mock-search-service.ts +2 -0
  77. package/test/sort-filter-bar/sort-filter-bar.test.ts +0 -29
  78. package/test/utils/normalize-filter-text.test.ts +87 -0
  79. package/web-test-runner.config.mjs +7 -2
  80. package/dist/src/collection-facets/more-facets-pagination.d.ts +0 -36
  81. package/dist/src/collection-facets/more-facets-pagination.js +0 -260
  82. package/dist/src/collection-facets/more-facets-pagination.js.map +0 -1
  83. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +0 -1
  84. package/dist/test/collection-facets/more-facets-pagination.test.js +0 -126
  85. package/dist/test/collection-facets/more-facets-pagination.test.js.map +0 -1
  86. package/src/collection-facets/more-facets-pagination.ts +0 -294
  87. package/test/collection-facets/more-facets-pagination.test.ts +0 -201
@@ -259,35 +259,6 @@ describe('Sort dropdown behavior', () => {
259
259
  expect(slotEl?.shadowRoot?.querySelector('#sort-selector-container')).to.not
260
260
  .exist;
261
261
  });
262
-
263
- it('renders the sort-bar-end slot after the display mode buttons', async () => {
264
- const el = await fixture<SortFilterBar>(html`
265
- <sort-filter-bar>
266
- <button slot="sort-bar-end" id="end-button">End</button>
267
- </sort-filter-bar>
268
- `);
269
-
270
- const sortBar = el.shadowRoot?.querySelector('#sort-bar');
271
- const displayModes = sortBar?.querySelector('#display-style-selector');
272
- const endSlot = sortBar?.querySelector(
273
- 'slot[name="sort-bar-end"]',
274
- ) as HTMLSlotElement;
275
-
276
- expect(endSlot).to.exist;
277
- expect(sortBar?.lastElementChild).to.equal(endSlot);
278
- expect(displayModes?.nextElementSibling).to.equal(endSlot);
279
- expect(endSlot.assignedElements()[0]?.id).to.equal('end-button');
280
- });
281
-
282
- it('keeps the sort-bar-end slot when display modes are suppressed', async () => {
283
- const el = await fixture<SortFilterBar>(html`
284
- <sort-filter-bar suppressDisplayModes></sort-filter-bar>
285
- `);
286
-
287
- const sortBar = el.shadowRoot?.querySelector('#sort-bar');
288
- expect(sortBar?.querySelector('#display-style-selector')).to.not.exist;
289
- expect(sortBar?.querySelector('slot[name="sort-bar-end"]')).to.exist;
290
- });
291
262
  });
292
263
 
293
264
  describe('Sort direction button behavior', () => {
@@ -0,0 +1,87 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import {
3
+ filterTextIncludes,
4
+ normalizeFilterText,
5
+ } from '../../src/utils/normalize-filter-text';
6
+
7
+ /** Whether filtering for `filter` would find `text` */
8
+ function finds(text: string, filter: string): boolean {
9
+ return filterTextIncludes(
10
+ normalizeFilterText(text),
11
+ normalizeFilterText(filter),
12
+ );
13
+ }
14
+
15
+ describe('normalizeFilterText', () => {
16
+ it('lowercases text', () => {
17
+ expect(normalizeFilterText('Puppies')).to.deep.equal({
18
+ spaced: 'puppies',
19
+ joined: 'puppies',
20
+ });
21
+ });
22
+
23
+ it('removes punctuation other than word joiners', () => {
24
+ expect(normalizeFilterText('A.O.R.').spaced).to.equal('aor');
25
+ expect(normalizeFilterText('Dr. Drew').spaced).to.equal('dr drew');
26
+ expect(normalizeFilterText("Children's books").spaced).to.equal(
27
+ 'childrens books',
28
+ );
29
+ });
30
+
31
+ it('turns word joiners into spaces in one form and removes them in the other', () => {
32
+ expect(normalizeFilterText('WC-TV')).to.deep.equal({
33
+ spaced: 'wc tv',
34
+ joined: 'wctv',
35
+ });
36
+ expect(normalizeFilterText('AC/DC')).to.deep.equal({
37
+ spaced: 'ac dc',
38
+ joined: 'acdc',
39
+ });
40
+ expect(normalizeFilterText('snake_case')).to.deep.equal({
41
+ spaced: 'snake case',
42
+ joined: 'snakecase',
43
+ });
44
+ expect(normalizeFilterText('1950–1960').spaced).to.equal('1950 1960');
45
+ });
46
+
47
+ it('removes accents', () => {
48
+ expect(normalizeFilterText('Café Müller').spaced).to.equal('cafe muller');
49
+ });
50
+
51
+ it('collapses and trims whitespace', () => {
52
+ expect(normalizeFilterText(' Dogs -- Fiction ')).to.deep.equal({
53
+ spaced: 'dogs fiction',
54
+ joined: 'dogs fiction',
55
+ });
56
+ });
57
+
58
+ it('keeps symbols that carry meaning', () => {
59
+ expect(normalizeFilterText('C++').spaced).to.equal('c++');
60
+ });
61
+
62
+ it('reduces text that is only punctuation to nothing', () => {
63
+ expect(normalizeFilterText('...')).to.deep.equal({
64
+ spaced: '',
65
+ joined: '',
66
+ });
67
+ expect(normalizeFilterText(' - ').spaced).to.equal('');
68
+ });
69
+ });
70
+
71
+ describe('filterTextIncludes', () => {
72
+ it('matches hyphenated words typed apart or together', () => {
73
+ expect(finds('WC-TV', 'wc tv')).to.be.true;
74
+ expect(finds('WC-TV', 'wctv')).to.be.true;
75
+ expect(finds('WC-TV', 'wc-tv')).to.be.true;
76
+ expect(finds('Human-animal relationships', 'human animal')).to.be.true;
77
+ });
78
+
79
+ it('matches regardless of other punctuation', () => {
80
+ expect(finds('A.O.R.', 'aor')).to.be.true;
81
+ expect(finds('Dr. Drew', 'dr drew')).to.be.true;
82
+ });
83
+
84
+ it("doesn't match words that are apart in the value but typed together", () => {
85
+ expect(finds('WC TV', 'wctv')).to.be.false;
86
+ });
87
+ });
@@ -38,8 +38,13 @@ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
38
38
  /** Amount of browsers to run concurrently */
39
39
  // concurrentBrowsers: 2,
40
40
 
41
- /** Amount of test files per browser to test concurrently */
42
- // concurrency: 1,
41
+ /**
42
+ * Amount of test files per browser to test concurrently. Files run in
43
+ * browser tabs, and Chrome doesn't render tabs in the background, so they
44
+ * get no animation frames or ResizeObserver callbacks. Running one at a time
45
+ * keeps each in the foreground (and is faster than the throttled default).
46
+ */
47
+ concurrency: 1,
43
48
 
44
49
  /** Browsers to run tests on */
45
50
  // browsers: [
@@ -1,36 +0,0 @@
1
- import { CSSResultGroup, LitElement, TemplateResult } from 'lit';
2
- export declare class MoreFacetsPagination extends LitElement {
3
- /**
4
- * Total number of pages
5
- */
6
- size: number;
7
- /**
8
- * Number of pages can be moved in back/forward
9
- */
10
- step: number;
11
- currentPage: number;
12
- pages?: number[];
13
- firstUpdated(): void;
14
- updated(changed: Map<string, any>): void;
15
- /** creates `this.pages` array that notes which pages to draw
16
- * - `0` is elipses marker
17
- * - rule: selected page is centered between -2/+2 pages
18
- * - outlier: first page selected, show _1_ 2 3 ... N
19
- * - outlier: second page selected, show 1 _2_ 3 4 ... N
20
- * - outlier: last page selected, show 1 ... N-2 N-1 _N_
21
- * - outlier: if page count = 7, & selected is either [2, 3, 4, 5, 6], show all pages
22
- */
23
- observePageCount(): void;
24
- private createFirstNode;
25
- private createMiddelNode;
26
- private createLastNode;
27
- private get getEllipsisTemplate();
28
- emitPageClick(): void;
29
- private onRewind;
30
- private onForward;
31
- private onChange;
32
- private getPageTemplate;
33
- private get getPagesTemplate();
34
- render(): TemplateResult<1>;
35
- static get styles(): CSSResultGroup;
36
- }
@@ -1,260 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { css, html, LitElement, nothing, } from 'lit';
3
- import { customElement, property, state } from 'lit/decorators.js';
4
- import arrowLeftIcon from '../assets/img/icons/arrow-left';
5
- import arrowRightIcon from '../assets/img/icons/arrow-right';
6
- import { srOnlyStyle } from '../styles/sr-only';
7
- let MoreFacetsPagination = class MoreFacetsPagination extends LitElement {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * Number of pages can be moved in back/forward
12
- */
13
- this.step = 2;
14
- this.currentPage = 1;
15
- this.pages = [];
16
- }
17
- firstUpdated() {
18
- this.observePageCount();
19
- }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- updated(changed) {
22
- if (changed.has('size')) {
23
- this.observePageCount();
24
- }
25
- if (changed.has('currentPage')) {
26
- this.observePageCount();
27
- this.emitPageClick();
28
- }
29
- }
30
- /** creates `this.pages` array that notes which pages to draw
31
- * - `0` is elipses marker
32
- * - rule: selected page is centered between -2/+2 pages
33
- * - outlier: first page selected, show _1_ 2 3 ... N
34
- * - outlier: second page selected, show 1 _2_ 3 4 ... N
35
- * - outlier: last page selected, show 1 ... N-2 N-1 _N_
36
- * - outlier: if page count = 7, & selected is either [2, 3, 4, 5, 6], show all pages
37
- */
38
- observePageCount() {
39
- this.pages = []; /* `0` is elipses marker */
40
- const paginatorMaxPagesToShow = 7;
41
- const atMinThreshold = this.size <= paginatorMaxPagesToShow;
42
- /** Display outliers */
43
- if (this.size <= 5) {
44
- // display all pages
45
- this.pages = [...Array(this.size).keys()].map(i => i + 1);
46
- return;
47
- }
48
- if (this.size === paginatorMaxPagesToShow) {
49
- // edge: 7 pages
50
- if (this.currentPage === 2) {
51
- this.pages = [1, 2, 3, 4, 0, this.size];
52
- return;
53
- }
54
- if (this.currentPage === this.size - 1) {
55
- this.pages = [1, 0, 4, 5, this.size - 1, this.size];
56
- return;
57
- }
58
- }
59
- if (this.currentPage === 1) {
60
- // first page
61
- this.pages = [1, 2, 3, 0, this.size];
62
- return;
63
- }
64
- if (this.currentPage === this.size) {
65
- // last page
66
- this.pages = [1, 0, this.size - 2, this.size - 1, this.size];
67
- return;
68
- }
69
- if (this.currentPage === this.size - 1) {
70
- // second last page
71
- this.pages = [
72
- 1,
73
- 0,
74
- this.size - 3,
75
- this.size - 2,
76
- this.size - 1,
77
- this.size,
78
- ];
79
- return;
80
- }
81
- if (atMinThreshold &&
82
- this.currentPage > 1 &&
83
- this.currentPage < paginatorMaxPagesToShow) {
84
- this.pages = [...Array(this.size).keys()].map(i => i + 1);
85
- return;
86
- }
87
- /* The rest here calculates the range to display in "page window" */
88
- let startPage = this.currentPage - this.step;
89
- let endPage = this.currentPage + this.step;
90
- if (startPage <= 0) {
91
- endPage += -startPage + 1;
92
- startPage = 1;
93
- }
94
- if (endPage >= this.size) {
95
- startPage = Math.max(startPage - (endPage - this.size), 1);
96
- endPage = this.size;
97
- }
98
- if (startPage === 2) {
99
- endPage -= 1;
100
- }
101
- if (endPage === this.size - 1) {
102
- startPage += 1;
103
- }
104
- // create first page node
105
- this.createFirstNode(startPage);
106
- // create middle pages node
107
- this.createMiddelNode(startPage, endPage);
108
- // create last page node
109
- this.createLastNode(endPage);
110
- }
111
- createFirstNode(startPage) {
112
- if (startPage > 1) {
113
- this.pages?.push(1);
114
- }
115
- if (startPage > 2) {
116
- this.pages?.push(0); // let's asssume 0 is for ellipsis template
117
- }
118
- }
119
- createMiddelNode(startPage, endPage) {
120
- for (let page = startPage; page <= endPage; page += 1) {
121
- this.pages?.push(page);
122
- }
123
- }
124
- createLastNode(endPage) {
125
- if (endPage < this.size - 1) {
126
- this.pages?.push(0); // let's asssume 0 is for ellipsis template
127
- }
128
- if (endPage < this.size) {
129
- this.pages?.push(this.size);
130
- }
131
- }
132
- get getEllipsisTemplate() {
133
- return html `<i class="ellipses">...</i>`;
134
- }
135
- emitPageClick() {
136
- this.dispatchEvent(new CustomEvent('pageNumberClicked', {
137
- detail: { page: this.currentPage },
138
- bubbles: true,
139
- composed: true,
140
- }));
141
- }
142
- onRewind() {
143
- this.currentPage -= 1;
144
- if (this.currentPage < 1) {
145
- this.currentPage = 1;
146
- }
147
- }
148
- onForward() {
149
- this.currentPage += 1;
150
- if (this.currentPage > this.size) {
151
- this.currentPage = this.size;
152
- }
153
- }
154
- onChange(page) {
155
- this.currentPage = page;
156
- }
157
- getPageTemplate(page) {
158
- return html `
159
- <button
160
- @click=${() => this.onChange(page)}
161
- class=${this.currentPage === page ? 'current' : ''}
162
- data-page=${page}
163
- >
164
- ${page}
165
- </button>
166
- `;
167
- }
168
- get getPagesTemplate() {
169
- if (!this.pages || !this.pages.length) {
170
- return nothing;
171
- }
172
- return html `
173
- ${this.pages?.map(page => html `${page !== 0
174
- ? this.getPageTemplate(page)
175
- : this.getEllipsisTemplate}`)}
176
- `;
177
- }
178
- render() {
179
- return html `
180
- <div class="facets-pagination">
181
- <button class="arrow-icon rewind" @click=${this.onRewind}>
182
- <span class="sr-only">Rewind pagination:</span>
183
- ${arrowLeftIcon}
184
- </button>
185
- <div class="page-numbers">${this.getPagesTemplate}</div>
186
- <button class="arrow-icon forward" @click=${this.onForward}>
187
- <span class="sr-only">Forward pagination:</span>
188
- ${arrowRightIcon}
189
- </button>
190
- </div>
191
- `;
192
- }
193
- static get styles() {
194
- return [
195
- srOnlyStyle,
196
- css `
197
- .facets-pagination {
198
- user-select: none;
199
- margin-top: 10px;
200
- background-color: #eee;
201
- text-align: center;
202
- }
203
- .facets-pagination button {
204
- border: none;
205
- background: none;
206
- }
207
- .facets-pagination .arrow-icon {
208
- width: 2.5rem;
209
- vertical-align: middle;
210
- }
211
- .facets-pagination .arrow-icon svg {
212
- height: 14px;
213
- fill: #2c2c2c;
214
- }
215
- .facets-pagination button,
216
- .facets-pagination i {
217
- background: none;
218
- border: 0;
219
- cursor: pointer;
220
- border-radius: 4px;
221
- margin: 10px 5px;
222
- padding: 5px;
223
- font-size: 1.4rem;
224
- color: inherit;
225
- vertical-align: baseline;
226
- display: inline-block;
227
- min-width: 2.5rem;
228
- }
229
- .facets-pagination i {
230
- cursor: auto;
231
- display: inline;
232
- }
233
- .facets-pagination button.current {
234
- background: #2c2c2c;
235
- color: white;
236
- }
237
- .page-numbers {
238
- display: inline-block;
239
- }
240
- `,
241
- ];
242
- }
243
- };
244
- __decorate([
245
- property({ type: Number })
246
- ], MoreFacetsPagination.prototype, "size", void 0);
247
- __decorate([
248
- property({ type: Number })
249
- ], MoreFacetsPagination.prototype, "step", void 0);
250
- __decorate([
251
- property({ type: Number })
252
- ], MoreFacetsPagination.prototype, "currentPage", void 0);
253
- __decorate([
254
- state()
255
- ], MoreFacetsPagination.prototype, "pages", void 0);
256
- MoreFacetsPagination = __decorate([
257
- customElement('more-facets-pagination')
258
- ], MoreFacetsPagination);
259
- export { MoreFacetsPagination };
260
- //# sourceMappingURL=more-facets-pagination.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"more-facets-pagination.js","sourceRoot":"","sources":["../../../src/collection-facets/more-facets-pagination.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EAEH,IAAI,EACJ,UAAU,EACV,OAAO,GAER,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGzC,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,UAAU;IAA7C;;QAML;;WAEG;QACyB,SAAI,GAAG,CAAC,CAAC;QAET,gBAAW,GAAW,CAAC,CAAC;QAE3C,UAAK,GAAc,EAAE,CAAC;IA0QjC,CAAC;IAxQC,YAAY;QACV,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,8DAA8D;IACrD,OAAO,CAAC,OAAyB;QACxC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,gBAAgB;QACd,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,2BAA2B;QAE5C,MAAM,uBAAuB,GAAG,CAAC,CAAC;QAClC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,IAAI,uBAAuB,CAAC;QAE5D,wBAAwB;QACxB,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;YACnB,oBAAo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ACjC;KACF,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;mDAEoC,IAAI,CAAC,QAAQ;;YAEpD,aAAa;;oCAEW,IAAI,CAAC,gBAAgB;oDACL,IAAI,CAAC,SAAS;;YAEtD,cAAc;;;KAGrB,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,WAAW;YACX,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAnR6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AAKd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAU;AAET;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAAyB;AAE3C;IAAR,KAAK,EAAE;mDAAuB;AAbpB,oBAAoB;IADhC,aAAa,CAAC,wBAAwB,CAAC;GAC3B,oBAAoB,CAuRhC","sourcesContent":["import {\n css,\n CSSResultGroup,\n html,\n LitElement,\n nothing,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport arrowLeftIcon from '../assets/img/icons/arrow-left';\nimport arrowRightIcon from '../assets/img/icons/arrow-right';\nimport { srOnlyStyle } from '../styles/sr-only';\n\n@customElement('more-facets-pagination')\nexport class MoreFacetsPagination extends LitElement {\n /**\n * Total number of pages\n */\n @property({ type: Number }) size!: number;\n\n /**\n * Number of pages can be moved in back/forward\n */\n @property({ type: Number }) step = 2;\n\n @property({ type: Number }) currentPage: number = 1;\n\n @state() pages?: number[] = [];\n\n firstUpdated() {\n this.observePageCount();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n override updated(changed: Map<string, any>) {\n if (changed.has('size')) {\n this.observePageCount();\n }\n if (changed.has('currentPage')) {\n this.observePageCount();\n this.emitPageClick();\n }\n }\n\n /** creates `this.pages` array that notes which pages to draw\n * - `0` is elipses marker\n * - rule: selected page is centered between -2/+2 pages\n * - outlier: first page selected, show _1_ 2 3 ... N\n * - outlier: second page selected, show 1 _2_ 3 4 ... N\n * - outlier: last page selected, show 1 ... N-2 N-1 _N_\n * - outlier: if page count = 7, & selected is either [2, 3, 4, 5, 6], show all pages\n */\n observePageCount() {\n this.pages = []; /* `0` is elipses marker */\n\n const paginatorMaxPagesToShow = 7;\n const atMinThreshold = this.size <= paginatorMaxPagesToShow;\n\n /** Display outliers */\n if (this.size <= 5) {\n // display all pages\n this.pages = [...Array(this.size).keys()].map(i => i + 1);\n return;\n }\n\n if (this.size === paginatorMaxPagesToShow) {\n // edge: 7 pages\n if (this.currentPage === 2) {\n this.pages = [1, 2, 3, 4, 0, this.size];\n return;\n }\n\n if (this.currentPage === this.size - 1) {\n this.pages = [1, 0, 4, 5, this.size - 1, this.size];\n return;\n }\n }\n\n if (this.currentPage === 1) {\n // first page\n this.pages = [1, 2, 3, 0, this.size];\n return;\n }\n\n if (this.currentPage === this.size) {\n // last page\n this.pages = [1, 0, this.size - 2, this.size - 1, this.size];\n return;\n }\n\n if (this.currentPage === this.size - 1) {\n // second last page\n this.pages = [\n 1,\n 0,\n this.size - 3,\n this.size - 2,\n this.size - 1,\n this.size,\n ];\n return;\n }\n\n if (\n atMinThreshold &&\n this.currentPage > 1 &&\n this.currentPage < paginatorMaxPagesToShow\n ) {\n this.pages = [...Array(this.size).keys()].map(i => i + 1);\n return;\n }\n\n /* The rest here calculates the range to display in \"page window\" */\n let startPage = this.currentPage - this.step;\n let endPage = this.currentPage + this.step;\n\n if (startPage <= 0) {\n endPage += -startPage + 1;\n startPage = 1;\n }\n\n if (endPage >= this.size) {\n startPage = Math.max(startPage - (endPage - this.size), 1);\n endPage = this.size;\n }\n\n if (startPage === 2) {\n endPage -= 1;\n }\n\n if (endPage === this.size - 1) {\n startPage += 1;\n }\n\n // create first page node\n this.createFirstNode(startPage);\n\n // create middle pages node\n this.createMiddelNode(startPage, endPage);\n\n // create last page node\n this.createLastNode(endPage);\n }\n\n private createFirstNode(startPage: number) {\n if (startPage > 1) {\n this.pages?.push(1);\n }\n if (startPage > 2) {\n this.pages?.push(0); // let's asssume 0 is for ellipsis template\n }\n }\n\n private createMiddelNode(startPage: number, endPage: number) {\n for (let page = startPage; page <= endPage; page += 1) {\n this.pages?.push(page);\n }\n }\n\n private createLastNode(endPage: number) {\n if (endPage < this.size - 1) {\n this.pages?.push(0); // let's asssume 0 is for ellipsis template\n }\n if (endPage < this.size) {\n this.pages?.push(this.size);\n }\n }\n\n private get getEllipsisTemplate() {\n return html`<i class=\"ellipses\">...</i>`;\n }\n\n emitPageClick() {\n this.dispatchEvent(\n new CustomEvent('pageNumberClicked', {\n detail: { page: this.currentPage },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n private onRewind() {\n this.currentPage -= 1;\n if (this.currentPage < 1) {\n this.currentPage = 1;\n }\n }\n\n private onForward() {\n this.currentPage += 1;\n if (this.currentPage > this.size) {\n this.currentPage = this.size;\n }\n }\n\n private onChange(page: number) {\n this.currentPage = page;\n }\n\n private getPageTemplate(page: number) {\n return html`\n <button\n @click=${() => this.onChange(page)}\n class=${this.currentPage === page ? 'current' : ''}\n data-page=${page}\n >\n ${page}\n </button>\n `;\n }\n\n private get getPagesTemplate(): TemplateResult | typeof nothing {\n if (!this.pages || !this.pages.length) {\n return nothing;\n }\n\n return html`\n ${this.pages?.map(\n page =>\n html`${page !== 0\n ? this.getPageTemplate(page)\n : this.getEllipsisTemplate}`,\n )}\n `;\n }\n\n render() {\n return html`\n <div class=\"facets-pagination\">\n <button class=\"arrow-icon rewind\" @click=${this.onRewind}>\n <span class=\"sr-only\">Rewind pagination:</span>\n ${arrowLeftIcon}\n </button>\n <div class=\"page-numbers\">${this.getPagesTemplate}</div>\n <button class=\"arrow-icon forward\" @click=${this.onForward}>\n <span class=\"sr-only\">Forward pagination:</span>\n ${arrowRightIcon}\n </button>\n </div>\n `;\n }\n\n static get styles(): CSSResultGroup {\n return [\n srOnlyStyle,\n css`\n .facets-pagination {\n user-select: none;\n margin-top: 10px;\n background-color: #eee;\n text-align: center;\n }\n .facets-pagination button {\n border: none;\n background: none;\n }\n .facets-pagination .arrow-icon {\n width: 2.5rem;\n vertical-align: middle;\n }\n .facets-pagination .arrow-icon svg {\n height: 14px;\n fill: #2c2c2c;\n }\n .facets-pagination button,\n .facets-pagination i {\n background: none;\n border: 0;\n cursor: pointer;\n border-radius: 4px;\n margin: 10px 5px;\n padding: 5px;\n font-size: 1.4rem;\n color: inherit;\n vertical-align: baseline;\n display: inline-block;\n min-width: 2.5rem;\n }\n .facets-pagination i {\n cursor: auto;\n display: inline;\n }\n .facets-pagination button.current {\n background: #2c2c2c;\n color: white;\n }\n .page-numbers {\n display: inline-block;\n }\n `,\n ];\n }\n}\n"]}
@@ -1 +0,0 @@
1
- import '../../src/collection-facets/more-facets-pagination';
@@ -1,126 +0,0 @@
1
- import { expect, fixture, oneEvent } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import sinon from 'sinon';
4
- import '../../src/collection-facets/more-facets-pagination';
5
- afterEach(() => {
6
- sinon.restore();
7
- });
8
- describe('More facets pagination', () => {
9
- describe('5 pages or less', () => {
10
- it('shows all pages', async () => {
11
- const el = await fixture(html `<more-facets-pagination .size=${5}></more-facets-pagination>`);
12
- await el.updateComplete;
13
- const pageButtons = el.shadowRoot?.querySelectorAll('button[data-page]');
14
- expect(pageButtons.length).to.greaterThan(0);
15
- pageButtons.forEach((button, index) => {
16
- expect(button.textContent).to.contain(index + 1);
17
- });
18
- });
19
- });
20
- it('should render pagination template', async () => {
21
- const el = await fixture(html `<more-facets-pagination .size=${10}></more-facets-pagination>`);
22
- await el.updateComplete;
23
- expect(el.shadowRoot?.querySelector('.facets-pagination')).to.exist;
24
- expect(el.shadowRoot?.querySelector('.arrow-icon')).to.exist;
25
- });
26
- it('should render page numbers', async () => {
27
- const el = await fixture(html `<more-facets-pagination .size=${3}></more-facets-pagination>`);
28
- await el.updateComplete;
29
- const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');
30
- expect(pageNumberElement).to.exist;
31
- expect(pageNumberElement?.querySelectorAll('button').length).to.equal(3);
32
- });
33
- it('check current page and total pages', async () => {
34
- const el = await fixture(html `<more-facets-pagination
35
- .size=${4}
36
- .currentPage=${2}
37
- ></more-facets-pagination>`);
38
- await el.updateComplete;
39
- const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');
40
- expect(pageNumberElement).to.exist;
41
- expect(pageNumberElement
42
- ?.querySelectorAll('button')[1]
43
- .classList.contains('current')).to.be.true;
44
- expect(el.pages?.length).to.equal(4);
45
- });
46
- it('get page numbers based of size and currentPage', async () => {
47
- const el = await fixture(html `<more-facets-pagination
48
- .size=${4}
49
- .currentPage=${2}
50
- ></more-facets-pagination>`);
51
- await el.updateComplete;
52
- expect(el.pages?.length).to.equal(4);
53
- });
54
- describe('Selecting a page', () => {
55
- it('fires event', async () => {
56
- const el = await fixture(html `<more-facets-pagination></more-facets-pagination>`);
57
- await el.updateComplete;
58
- setTimeout(() => el.dispatchEvent(new CustomEvent('pageNumberClicked', { detail: { page: 15 } })));
59
- const { detail } = await oneEvent(el, 'pageNumberClicked');
60
- expect(detail?.page).to.equal(15);
61
- });
62
- it('sets off side effects with `onChange`', async () => {
63
- const el = await fixture(html `<more-facets-pagination
64
- .size=${'10'}
65
- .currentPage=${2}
66
- ></more-facets-pagination>`);
67
- expect(el.currentPage).to.equal(2); // confirm current page
68
- const fake1 = sinon.fake();
69
- const fake2 = sinon.fake();
70
- el.observePageCount = fake1;
71
- el.emitPageClick = fake2;
72
- // select first page button
73
- const pageButton = el.shadowRoot?.querySelector('.page-numbers > button');
74
- // confirm button isn't selected
75
- expect(pageButton.classList.contains('current')).to.be.false;
76
- pageButton.click();
77
- await el.updateComplete;
78
- expect(fake1.callCount).to.equal(1);
79
- expect(fake2.callCount).to.equal(1);
80
- expect(el.currentPage).to.equal(1); // brings us back to currentPage
81
- // confirm button is selected
82
- expect(pageButton.classList.contains('current')).to.be.true;
83
- });
84
- });
85
- describe('Using Arrows', () => {
86
- it('going backwards', async () => {
87
- const el = await fixture(html `<more-facets-pagination
88
- .size=${'10'}
89
- .currentPage=${2}
90
- ></more-facets-pagination>`);
91
- expect(el.currentPage).to.equal(2); // confirm current page
92
- const fake1 = sinon.fake();
93
- const fake2 = sinon.fake();
94
- el.observePageCount = fake1;
95
- el.emitPageClick = fake2;
96
- // select first page button
97
- const rewindButton = el.shadowRoot?.querySelector('.facets-pagination > button.rewind');
98
- rewindButton.click();
99
- await el.updateComplete;
100
- expect(fake1.callCount).to.equal(1);
101
- expect(fake2.callCount).to.equal(1);
102
- expect(el.currentPage).to.equal(1); // brings us back 1 page
103
- // confirm button is selected
104
- expect((el.shadowRoot?.querySelector('.page-numbers > button[data-page="1"]')).classList.contains('current')).to.be.true;
105
- });
106
- it('going forwards', async () => {
107
- const el = await fixture(html `<more-facets-pagination
108
- .size=${'10'}
109
- .currentPage=${5}
110
- ></more-facets-pagination>`);
111
- expect(el.currentPage).to.equal(5); // confirm current page
112
- const fake1 = sinon.fake();
113
- const fake2 = sinon.fake();
114
- el.observePageCount = fake1;
115
- el.emitPageClick = fake2;
116
- // select first page button
117
- const forwardButton = el.shadowRoot?.querySelector('.facets-pagination > button.forward');
118
- forwardButton.click();
119
- await el.updateComplete;
120
- expect(fake1.callCount).to.equal(1);
121
- expect(fake2.callCount).to.equal(1);
122
- expect(el.currentPage).to.equal(6); // brings us forward 1 page
123
- });
124
- });
125
- });
126
- //# sourceMappingURL=more-facets-pagination.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"more-facets-pagination.test.js","sourceRoot":"","sources":["../../../test/collection-facets/more-facets-pagination.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,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qCAAqC,CACjB,CAAC;YACvB,aAAa,CAAC,KAAK,EAAE,CAAC;YAEtB,MAAM,EAAE,CAAC,cAAc,CAAC;YAExB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B;QACjE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect, fixture, oneEvent } from '@open-wc/testing';\nimport { html } from 'lit';\nimport sinon from 'sinon';\nimport '../../src/collection-facets/more-facets-pagination';\nimport type { MoreFacetsPagination } from '../../src/collection-facets/more-facets-pagination';\n\nafterEach(() => {\n sinon.restore();\n});\n\ndescribe('More facets pagination', () => {\n describe('5 pages or less', () => {\n it('shows all pages', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination .size=${5}></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n const pageButtons = el.shadowRoot?.querySelectorAll(\n 'button[data-page]',\n ) as NodeList;\n expect(pageButtons.length).to.greaterThan(0);\n\n pageButtons.forEach((button, index) => {\n expect(button.textContent).to.contain(index + 1);\n });\n });\n });\n\n it('should render pagination template', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination .size=${10}></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n expect(el.shadowRoot?.querySelector('.facets-pagination')).to.exist;\n expect(el.shadowRoot?.querySelector('.arrow-icon')).to.exist;\n });\n\n it('should render page numbers', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination .size=${3}></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');\n expect(pageNumberElement).to.exist;\n expect(pageNumberElement?.querySelectorAll('button').length).to.equal(3);\n });\n\n it('check current page and total pages', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination\n .size=${4}\n .currentPage=${2}\n ></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');\n expect(pageNumberElement).to.exist;\n expect(\n pageNumberElement\n ?.querySelectorAll('button')[1]\n .classList.contains('current'),\n ).to.be.true;\n expect(el.pages?.length).to.equal(4);\n });\n\n it('get page numbers based of size and currentPage', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination\n .size=${4}\n .currentPage=${2}\n ></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n expect(el.pages?.length).to.equal(4);\n });\n\n describe('Selecting a page', () => {\n it('fires event', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination></more-facets-pagination>`,\n );\n\n await el.updateComplete;\n\n setTimeout(() =>\n el.dispatchEvent(\n new CustomEvent('pageNumberClicked', { detail: { page: 15 } }),\n ),\n );\n const { detail } = await oneEvent(el, 'pageNumberClicked');\n expect(detail?.page).to.equal(15);\n });\n it('sets off side effects with `onChange`', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination\n .size=${'10'}\n .currentPage=${2}\n ></more-facets-pagination>`,\n );\n\n expect(el.currentPage).to.equal(2); // confirm current page\n\n const fake1 = sinon.fake();\n const fake2 = sinon.fake();\n el.observePageCount = fake1;\n el.emitPageClick = fake2;\n\n // select first page button\n const pageButton = el.shadowRoot?.querySelector(\n '.page-numbers > button',\n ) as HTMLButtonElement;\n // confirm button isn't selected\n expect(pageButton.classList.contains('current')).to.be.false;\n pageButton.click();\n\n await el.updateComplete;\n\n expect(fake1.callCount).to.equal(1);\n expect(fake2.callCount).to.equal(1);\n expect(el.currentPage).to.equal(1); // brings us back to currentPage\n // confirm button is selected\n expect(pageButton.classList.contains('current')).to.be.true;\n });\n });\n\n describe('Using Arrows', () => {\n it('going backwards', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination\n .size=${'10'}\n .currentPage=${2}\n ></more-facets-pagination>`,\n );\n\n expect(el.currentPage).to.equal(2); // confirm current page\n\n const fake1 = sinon.fake();\n const fake2 = sinon.fake();\n el.observePageCount = fake1;\n el.emitPageClick = fake2;\n\n // select first page button\n const rewindButton = el.shadowRoot?.querySelector(\n '.facets-pagination > button.rewind',\n ) as HTMLButtonElement;\n rewindButton.click();\n\n await el.updateComplete;\n\n expect(fake1.callCount).to.equal(1);\n expect(fake2.callCount).to.equal(1);\n expect(el.currentPage).to.equal(1); // brings us back 1 page\n // confirm button is selected\n expect(\n (\n el.shadowRoot?.querySelector(\n '.page-numbers > button[data-page=\"1\"]',\n ) as HTMLButtonElement\n ).classList.contains('current'),\n ).to.be.true;\n });\n\n it('going forwards', async () => {\n const el = await fixture<MoreFacetsPagination>(\n html`<more-facets-pagination\n .size=${'10'}\n .currentPage=${5}\n ></more-facets-pagination>`,\n );\n\n expect(el.currentPage).to.equal(5); // confirm current page\n\n const fake1 = sinon.fake();\n const fake2 = sinon.fake();\n el.observePageCount = fake1;\n el.emitPageClick = fake2;\n\n // select first page button\n const forwardButton = el.shadowRoot?.querySelector(\n '.facets-pagination > button.forward',\n ) as HTMLButtonElement;\n forwardButton.click();\n\n await el.updateComplete;\n\n expect(fake1.callCount).to.equal(1);\n expect(fake2.callCount).to.equal(1);\n expect(el.currentPage).to.equal(6); // brings us forward 1 page\n });\n });\n});\n"]}