@internetarchive/collection-browser 3.4.1-alpha-webdev7761.2 → 3.4.1-alpha-webdev7761.4

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 (208) hide show
  1. package/dist/src/app-root.js +19 -28
  2. package/dist/src/app-root.js.map +1 -1
  3. package/dist/src/collection-browser.d.ts +14 -10
  4. package/dist/src/collection-browser.js +870 -886
  5. package/dist/src/collection-browser.js.map +1 -1
  6. package/dist/src/collection-facets/facet-row.js +3 -4
  7. package/dist/src/collection-facets/facet-row.js.map +1 -1
  8. package/dist/src/collection-facets/models.js.map +1 -1
  9. package/dist/src/collection-facets/more-facets-content.js +145 -156
  10. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  11. package/dist/src/collection-facets/more-facets-pagination.js +6 -10
  12. package/dist/src/collection-facets/more-facets-pagination.js.map +1 -1
  13. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js +16 -21
  14. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map +1 -1
  15. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +7 -10
  16. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
  17. package/dist/src/collection-facets/smart-facets/smart-facet-button.js +3 -2
  18. package/dist/src/collection-facets/smart-facets/smart-facet-button.js.map +1 -1
  19. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +9 -11
  20. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -1
  21. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js +7 -7
  22. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js.map +1 -1
  23. package/dist/src/collection-facets/toggle-switch.js +4 -6
  24. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  25. package/dist/src/collection-facets.js +34 -50
  26. package/dist/src/collection-facets.js.map +1 -1
  27. package/dist/src/combo-box/caret-closed.js +5 -11
  28. package/dist/src/combo-box/caret-closed.js.map +1 -1
  29. package/dist/src/combo-box/caret-open.js +5 -11
  30. package/dist/src/combo-box/caret-open.js.map +1 -1
  31. package/dist/src/combo-box/clear.d.ts +2 -0
  32. package/dist/src/combo-box/clear.js +11 -0
  33. package/dist/src/combo-box/clear.js.map +1 -0
  34. package/dist/src/combo-box/ia-combo-box.d.ts +40 -9
  35. package/dist/src/combo-box/ia-combo-box.js +363 -272
  36. package/dist/src/combo-box/ia-combo-box.js.map +1 -1
  37. package/dist/src/combo-box/models.d.ts +14 -0
  38. package/dist/src/combo-box/models.js +32 -1
  39. package/dist/src/combo-box/models.js.map +1 -1
  40. package/dist/src/data-source/collection-browser-data-source.js +35 -47
  41. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  42. package/dist/src/empty-placeholder.js +19 -18
  43. package/dist/src/empty-placeholder.js.map +1 -1
  44. package/dist/src/expanded-date-picker.js +6 -10
  45. package/dist/src/expanded-date-picker.js.map +1 -1
  46. package/dist/src/language-code-handler/language-code-handler.js +2 -2
  47. package/dist/src/language-code-handler/language-code-handler.js.map +1 -1
  48. package/dist/src/manage/manage-bar.js +86 -92
  49. package/dist/src/manage/manage-bar.js.map +1 -1
  50. package/dist/src/manage/remove-items-modal-content.js +2 -2
  51. package/dist/src/manage/remove-items-modal-content.js.map +1 -1
  52. package/dist/src/models.js +36 -40
  53. package/dist/src/models.js.map +1 -1
  54. package/dist/src/restoration-state-handler.js +9 -10
  55. package/dist/src/restoration-state-handler.js.map +1 -1
  56. package/dist/src/sort-filter-bar/alpha-bar.js +9 -14
  57. package/dist/src/sort-filter-bar/alpha-bar.js.map +1 -1
  58. package/dist/src/sort-filter-bar/sort-filter-bar.js +14 -24
  59. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  60. package/dist/src/tiles/base-tile-component.js +1 -2
  61. package/dist/src/tiles/base-tile-component.js.map +1 -1
  62. package/dist/src/tiles/grid/account-tile.js +36 -38
  63. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  64. package/dist/src/tiles/grid/collection-tile.js +79 -82
  65. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  66. package/dist/src/tiles/grid/item-tile.js +154 -164
  67. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  68. package/dist/src/tiles/grid/search-tile.js +42 -43
  69. package/dist/src/tiles/grid/search-tile.js.map +1 -1
  70. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +119 -119
  71. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  72. package/dist/src/tiles/grid/tile-stats.js +2 -3
  73. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  74. package/dist/src/tiles/hover/hover-pane-controller.js +42 -49
  75. package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
  76. package/dist/src/tiles/hover/tile-hover-pane.js +113 -114
  77. package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
  78. package/dist/src/tiles/image-block.js +5 -8
  79. package/dist/src/tiles/image-block.js.map +1 -1
  80. package/dist/src/tiles/item-image.js +12 -19
  81. package/dist/src/tiles/item-image.js.map +1 -1
  82. package/dist/src/tiles/list/tile-list-compact.js +114 -122
  83. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  84. package/dist/src/tiles/list/tile-list.js +326 -347
  85. package/dist/src/tiles/list/tile-list.js.map +1 -1
  86. package/dist/src/tiles/overlay/icon-overlay.js +1 -2
  87. package/dist/src/tiles/overlay/icon-overlay.js.map +1 -1
  88. package/dist/src/tiles/overlay/text-overlay.js +2 -4
  89. package/dist/src/tiles/overlay/text-overlay.js.map +1 -1
  90. package/dist/src/tiles/text-snippet-block.js +2 -4
  91. package/dist/src/tiles/text-snippet-block.js.map +1 -1
  92. package/dist/src/tiles/tile-dispatcher.js +233 -241
  93. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  94. package/dist/src/tiles/tile-display-value-provider.js +5 -9
  95. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  96. package/dist/src/tiles/tile-mediatype-icon.js +12 -19
  97. package/dist/src/tiles/tile-mediatype-icon.js.map +1 -1
  98. package/dist/src/utils/collapse-repeated-quotes.js +1 -1
  99. package/dist/src/utils/collapse-repeated-quotes.js.map +1 -1
  100. package/dist/src/utils/facet-utils.js +3 -5
  101. package/dist/src/utils/facet-utils.js.map +1 -1
  102. package/dist/src/utils/format-count.js +10 -10
  103. package/dist/src/utils/format-count.js.map +1 -1
  104. package/dist/src/utils/format-date.js.map +1 -1
  105. package/dist/src/utils/resolve-mediatype.js +2 -3
  106. package/dist/src/utils/resolve-mediatype.js.map +1 -1
  107. package/dist/test/collection-browser.test.js +131 -185
  108. package/dist/test/collection-browser.test.js.map +1 -1
  109. package/dist/test/collection-facets/facet-row.test.js +60 -75
  110. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  111. package/dist/test/collection-facets/facets-template.test.js +17 -23
  112. package/dist/test/collection-facets/facets-template.test.js.map +1 -1
  113. package/dist/test/collection-facets/more-facets-content.test.js +22 -32
  114. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  115. package/dist/test/collection-facets/more-facets-pagination.test.js +16 -22
  116. package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -1
  117. package/dist/test/collection-facets/toggle-switch.test.js +22 -19
  118. package/dist/test/collection-facets/toggle-switch.test.js.map +1 -1
  119. package/dist/test/collection-facets.test.js +80 -97
  120. package/dist/test/collection-facets.test.js.map +1 -1
  121. package/dist/test/empty-placeholder.test.js +11 -17
  122. package/dist/test/empty-placeholder.test.js.map +1 -1
  123. package/dist/test/expanded-date-picker.test.js +8 -14
  124. package/dist/test/expanded-date-picker.test.js.map +1 -1
  125. package/dist/test/icon-overlay.test.js +7 -6
  126. package/dist/test/icon-overlay.test.js.map +1 -1
  127. package/dist/test/image-block.test.js +16 -26
  128. package/dist/test/image-block.test.js.map +1 -1
  129. package/dist/test/item-image.test.js +23 -32
  130. package/dist/test/item-image.test.js.map +1 -1
  131. package/dist/test/manage/manage-bar.test.js +21 -33
  132. package/dist/test/manage/manage-bar.test.js.map +1 -1
  133. package/dist/test/manage/remove-items-modal-content.test.js +10 -15
  134. package/dist/test/manage/remove-items-modal-content.test.js.map +1 -1
  135. package/dist/test/mocks/mock-search-service.js +2 -3
  136. package/dist/test/mocks/mock-search-service.js.map +1 -1
  137. package/dist/test/restoration-state-handler.test.js +13 -21
  138. package/dist/test/restoration-state-handler.test.js.map +1 -1
  139. package/dist/test/review-block.test.js +16 -18
  140. package/dist/test/review-block.test.js.map +1 -1
  141. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +2 -3
  142. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js.map +1 -1
  143. package/dist/test/sort-filter-bar/alpha-bar.test.js +18 -24
  144. package/dist/test/sort-filter-bar/alpha-bar.test.js.map +1 -1
  145. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +178 -180
  146. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  147. package/dist/test/text-overlay.test.js +16 -15
  148. package/dist/test/text-overlay.test.js.map +1 -1
  149. package/dist/test/text-snippet-block.test.js +14 -19
  150. package/dist/test/text-snippet-block.test.js.map +1 -1
  151. package/dist/test/tile-stats.test.js +73 -34
  152. package/dist/test/tile-stats.test.js.map +1 -1
  153. package/dist/test/tiles/grid/account-tile.test.js +25 -25
  154. package/dist/test/tiles/grid/account-tile.test.js.map +1 -1
  155. package/dist/test/tiles/grid/collection-tile.test.js +13 -19
  156. package/dist/test/tiles/grid/collection-tile.test.js.map +1 -1
  157. package/dist/test/tiles/grid/item-tile.test.js +141 -168
  158. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  159. package/dist/test/tiles/grid/search-tile.test.js +9 -13
  160. package/dist/test/tiles/grid/search-tile.test.js.map +1 -1
  161. package/dist/test/tiles/hover/hover-pane-controller.test.js +50 -62
  162. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
  163. package/dist/test/tiles/hover/tile-hover-pane.test.js +12 -16
  164. package/dist/test/tiles/hover/tile-hover-pane.test.js.map +1 -1
  165. package/dist/test/tiles/list/tile-list-compact.test.js +104 -118
  166. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
  167. package/dist/test/tiles/list/tile-list.test.js +202 -231
  168. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  169. package/dist/test/tiles/tile-dispatcher.test.js +97 -110
  170. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  171. package/dist/test/tiles/tile-mediatype-icon.test.js +12 -24
  172. package/dist/test/tiles/tile-mediatype-icon.test.js.map +1 -1
  173. package/dist/test/utils/format-date.test.js.map +1 -1
  174. package/index.html +1 -1
  175. package/package.json +5 -3
  176. package/src/collection-browser.ts +3060 -3030
  177. package/src/collection-facets/models.ts +10 -10
  178. package/src/collection-facets/more-facets-content.ts +639 -639
  179. package/src/collection-facets.ts +1 -1
  180. package/src/combo-box/caret-closed.ts +5 -11
  181. package/src/combo-box/caret-open.ts +5 -11
  182. package/src/combo-box/clear.ts +11 -0
  183. package/src/combo-box/ia-combo-box.ts +1288 -1180
  184. package/src/combo-box/models.ts +31 -1
  185. package/src/manage/manage-bar.ts +247 -247
  186. package/src/restoration-state-handler.ts +5 -1
  187. package/src/tiles/base-tile-component.ts +65 -65
  188. package/src/tiles/grid/account-tile.ts +113 -113
  189. package/src/tiles/grid/collection-tile.ts +163 -163
  190. package/src/tiles/grid/item-tile.ts +340 -340
  191. package/src/tiles/grid/search-tile.ts +90 -90
  192. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +130 -130
  193. package/src/tiles/hover/hover-pane-controller.ts +613 -613
  194. package/src/tiles/hover/tile-hover-pane.ts +184 -184
  195. package/src/tiles/list/tile-list-compact.ts +239 -239
  196. package/src/tiles/list/tile-list.ts +700 -700
  197. package/src/tiles/tile-dispatcher.ts +517 -517
  198. package/src/utils/format-date.ts +62 -62
  199. package/test/collection-facets/facet-row.test.ts +375 -375
  200. package/test/collection-facets.test.ts +928 -928
  201. package/test/tiles/grid/item-tile.test.ts +520 -520
  202. package/test/tiles/hover/hover-pane-controller.test.ts +418 -418
  203. package/test/tiles/list/tile-list-compact.test.ts +282 -282
  204. package/test/tiles/list/tile-list.test.ts +552 -552
  205. package/test/tiles/tile-dispatcher.test.ts +283 -283
  206. package/test/utils/format-date.test.ts +89 -89
  207. package/tsconfig.json +8 -3
  208. package/vite.config.ts +29 -22
@@ -79,5 +79,35 @@ export type IAComboBoxFilterOption =
79
79
  * @param keys The list of keys to check
80
80
  */
81
81
  export function hasAnyOf<T>(map: Map<T, unknown>, keys: T[]): boolean {
82
- return keys.some((prop) => map.has(prop));
82
+ return keys.some(prop => map.has(prop));
83
+ }
84
+
85
+ /**
86
+ * Tests whether the given `haystack` string has the given `needle` as a subsequence.
87
+ * Returns `true` if the characters of `needle` appear in order within `haystack`,
88
+ * regardless of whether they are contiguous. Returns `false` otherwise.
89
+ *
90
+ * E.g., `ace` is a subsequence of `archive` (but not a contiguous substring).
91
+ *
92
+ * Note: The empty string is a subsequence of any string, including itself.
93
+ *
94
+ * @param needle The potential subsequence to check for inside `haystack`.
95
+ * @param haystack The string to be tested for containing the `needle` subsequence.
96
+ * @returns Whether `haystack` has `needle` as a subsequence.
97
+ */
98
+ export function isSubsequence(needle: string, haystack: string): boolean {
99
+ const needleChars = [...needle]; // Split out the full code points
100
+ const haystackChars = [...haystack];
101
+ const needleLen = needleChars.length;
102
+ const haystackLen = haystackChars.length;
103
+ if (needleLen === 0) return true;
104
+
105
+ let needleIdx = 0;
106
+ let haystackIdx = 0;
107
+ while (haystackIdx < haystackLen) {
108
+ if (haystackChars[haystackIdx] === needleChars[needleIdx]) needleIdx += 1;
109
+ if (needleIdx >= needleLen) return true;
110
+ haystackIdx += 1;
111
+ }
112
+ return false;
83
113
  }
@@ -1,247 +1,247 @@
1
- import { msg } from '@lit/localize';
2
- import { LitElement, html, css, TemplateResult, CSSResultGroup } from 'lit';
3
- import { customElement, property } from 'lit/decorators.js';
4
- import { when } from 'lit/directives/when.js';
5
- import {
6
- ModalConfig,
7
- type ModalManagerInterface,
8
- } from '@internetarchive/modal-manager';
9
- import type { ManageableItem } from '../models';
10
- import iaButtonStyle from '../styles/ia-button';
11
- import './remove-items-modal-content';
12
-
13
- @customElement('manage-bar')
14
- export class ManageBar extends LitElement {
15
- /**
16
- * The label displayed in front of the management buttons
17
- */
18
- @property({ type: String }) label = msg('Select items to remove');
19
-
20
- /**
21
- * The shared modal manager component for displaying modal dialogs on this page
22
- */
23
- @property({ type: Object }) modalManager?: ModalManagerInterface;
24
-
25
- /**
26
- * Array of items that have been selected for management
27
- */
28
- @property({ type: Object }) selectedItems: Array<ManageableItem> = [];
29
-
30
- /**
31
- * Message shows as note in the modal when removing items
32
- */
33
- @property({ type: String }) manageViewModalMsg?: string;
34
-
35
- /**
36
- * Whether to show the "Select All" button (default false)
37
- */
38
- @property({ type: Boolean }) showSelectAll = false;
39
-
40
- /**
41
- * Whether to show the "Unselect All" button (default false)
42
- */
43
- @property({ type: Boolean }) showUnselectAll = false;
44
-
45
- /**
46
- * Whether to show "Item Manager the items" button (default false)
47
- */
48
- @property({ type: Boolean }) showItemManageButton = false;
49
-
50
- /**
51
- * Whether to active delete button for selectable items
52
- */
53
- @property({ type: Boolean }) removeAllowed = false;
54
-
55
- render(): TemplateResult {
56
- return html`
57
- <div class="manage-container">
58
- <span class="manage-label">${this.label}</span>
59
- <div class="manage-buttons">
60
- <button class="ia-button dark" @click=${this.cancelClicked}>
61
- ${msg('Cancel')}
62
- </button>
63
- <button
64
- class="ia-button danger"
65
- ?disabled=${!this.removeAllowed}
66
- @click=${this.showRemoveItemsModal}
67
- >
68
- ${msg('Remove selected items')} (${this.selectedItems.length})...
69
- </button>
70
- ${when(
71
- this.showItemManageButton,
72
- () =>
73
- html` <button
74
- class="ia-button warning"
75
- ?disabled=${!this.removeAllowed}
76
- @click=${this.manageItemsClicked}
77
- >
78
- ${msg('Item Manager the items')} (${this.selectedItems.length})
79
- </button>`,
80
- )}
81
- <div class="selection-buttons">
82
- ${when(
83
- this.showSelectAll,
84
- () =>
85
- html` <button
86
- class="ia-button link select-all-btn"
87
- @click=${this.selectAllClicked}
88
- >
89
- ${msg('Select all')}
90
- </button>`,
91
- )}
92
- ${when(
93
- this.showUnselectAll,
94
- () =>
95
- html` <button
96
- class="ia-button link unselect-all-btn"
97
- @click=${this.unselectAllClicked}
98
- >
99
- ${msg('Unselect all')}
100
- </button>`,
101
- )}
102
- </div>
103
- </div>
104
- </div>
105
- `;
106
- }
107
-
108
- private cancelClicked(): void {
109
- this.dispatchEvent(new CustomEvent('cancel'));
110
- }
111
-
112
- private removeItemsClicked(): void {
113
- this.dispatchEvent(new CustomEvent('removeItems'));
114
- }
115
-
116
- private manageItemsClicked(): void {
117
- this.dispatchEvent(new CustomEvent('manageItems'));
118
- }
119
-
120
- private selectAllClicked(): void {
121
- this.dispatchEvent(new CustomEvent('selectAll'));
122
- }
123
-
124
- private unselectAllClicked(): void {
125
- this.dispatchEvent(new CustomEvent('unselectAll'));
126
- }
127
-
128
- /**
129
- * Shows a modal dialog confirming the list of items to be removed
130
- * @param items Which items to list in the modal
131
- */
132
- private showRemoveItemsModal(): void {
133
- const customModalContent = html`
134
- <remove-items-modal-content
135
- .items=${this.selectedItems}
136
- .message=${this.manageViewModalMsg}
137
- @confirm=${() => this.removeItemsClicked()}
138
- ></remove-items-modal-content>
139
- `;
140
-
141
- const config = new ModalConfig({
142
- showProcessingIndicator: false,
143
- processingImageMode: 'processing',
144
- bodyColor: '#fff',
145
- headerColor: '#194880',
146
- showHeaderLogo: false,
147
- closeOnBackdropClick: true,
148
- title: html`${msg('Are you sure you want to remove these items?')}`,
149
- });
150
-
151
- this.modalManager?.classList.add('remove-items');
152
- this.modalManager?.showModal({
153
- config,
154
- customModalContent,
155
- userClosedModalCallback: () => {
156
- this.modalManager?.classList.remove('remove-items');
157
- },
158
- });
159
- }
160
-
161
- /**
162
- * Shows a modal dialog indicating that item removal is being processed
163
- */
164
- showRemoveItemsProcessingModal(): void {
165
- const config = new ModalConfig({
166
- showProcessingIndicator: true,
167
- processingImageMode: 'processing',
168
- bodyColor: '#fff',
169
- headerColor: '#194880',
170
- showHeaderLogo: false,
171
- closeOnBackdropClick: true,
172
- title: html`${msg('Removing selected items...')}`,
173
- });
174
-
175
- this.modalManager?.classList.add('remove-items');
176
- this.modalManager?.showModal({
177
- config,
178
- userClosedModalCallback: () => {
179
- this.modalManager?.classList.remove('remove-items');
180
- },
181
- });
182
- }
183
-
184
- /**
185
- * Shows a modal dialog indicating that an error occurred while removing items
186
- */
187
- showRemoveItemsErrorModal(): void {
188
- const config = new ModalConfig({
189
- showProcessingIndicator: false,
190
- processingImageMode: 'processing',
191
- bodyColor: '#fff',
192
- headerColor: '#691916',
193
- showHeaderLogo: false,
194
- closeOnBackdropClick: true,
195
- title: html`${msg('Error: unable to remove items')}`,
196
- message: html`${msg(
197
- 'An error occurred while removing items. Please try again in a few minutes.',
198
- )}`,
199
- });
200
-
201
- this.modalManager?.classList.add('remove-items');
202
- this.modalManager?.showModal({
203
- config,
204
- userClosedModalCallback: () => {
205
- this.modalManager?.classList.remove('remove-items');
206
- },
207
- });
208
- }
209
-
210
- static get styles(): CSSResultGroup {
211
- return css`
212
- ${iaButtonStyle}
213
- .manage-container {
214
- display: flex;
215
- align-items: center;
216
- column-gap: 5px;
217
- padding: 20px 0 20px;
218
- flex-wrap: wrap;
219
- }
220
-
221
- .manage-label {
222
- display: inline-block;
223
- font-weight: bold;
224
- font-size: 1.8rem;
225
- padding-right: 10px;
226
- }
227
-
228
- .manage-buttons {
229
- display: flex;
230
- flex-wrap: wrap;
231
- align-items: center;
232
- column-gap: 5px;
233
- }
234
-
235
- .selection-buttons {
236
- display: inherit;
237
- }
238
-
239
- .ia-button,
240
- button {
241
- padding: 6px 12px;
242
- font-size: 1.4rem;
243
- margin: 3px 0;
244
- }
245
- `;
246
- }
247
- }
1
+ import { msg } from '@lit/localize';
2
+ import { LitElement, html, css, TemplateResult, CSSResultGroup } from 'lit';
3
+ import { customElement, property } from 'lit/decorators.js';
4
+ import { when } from 'lit/directives/when.js';
5
+ import {
6
+ ModalConfig,
7
+ type ModalManagerInterface,
8
+ } from '@internetarchive/modal-manager';
9
+ import type { ManageableItem } from '../models';
10
+ import iaButtonStyle from '../styles/ia-button';
11
+ import './remove-items-modal-content';
12
+
13
+ @customElement('manage-bar')
14
+ export class ManageBar extends LitElement {
15
+ /**
16
+ * The label displayed in front of the management buttons
17
+ */
18
+ @property({ type: String }) label = msg('Select items to remove');
19
+
20
+ /**
21
+ * The shared modal manager component for displaying modal dialogs on this page
22
+ */
23
+ @property({ type: Object }) modalManager?: ModalManagerInterface;
24
+
25
+ /**
26
+ * Array of items that have been selected for management
27
+ */
28
+ @property({ type: Object }) selectedItems: Array<ManageableItem> = [];
29
+
30
+ /**
31
+ * Message shows as note in the modal when removing items
32
+ */
33
+ @property({ type: String }) manageViewModalMsg?: string;
34
+
35
+ /**
36
+ * Whether to show the "Select All" button (default false)
37
+ */
38
+ @property({ type: Boolean }) showSelectAll = false;
39
+
40
+ /**
41
+ * Whether to show the "Unselect All" button (default false)
42
+ */
43
+ @property({ type: Boolean }) showUnselectAll = false;
44
+
45
+ /**
46
+ * Whether to show "Item Manager the items" button (default false)
47
+ */
48
+ @property({ type: Boolean }) showItemManageButton = false;
49
+
50
+ /**
51
+ * Whether to active delete button for selectable items
52
+ */
53
+ @property({ type: Boolean }) removeAllowed = false;
54
+
55
+ render(): TemplateResult {
56
+ return html`
57
+ <div class="manage-container">
58
+ <span class="manage-label">${this.label}</span>
59
+ <div class="manage-buttons">
60
+ <button class="ia-button dark" @click=${this.cancelClicked}>
61
+ ${msg('Cancel')}
62
+ </button>
63
+ <button
64
+ class="ia-button danger"
65
+ ?disabled=${!this.removeAllowed}
66
+ @click=${this.showRemoveItemsModal}
67
+ >
68
+ ${msg('Remove selected items')} (${this.selectedItems.length})...
69
+ </button>
70
+ ${when(
71
+ this.showItemManageButton,
72
+ () =>
73
+ html` <button
74
+ class="ia-button warning"
75
+ ?disabled=${!this.removeAllowed}
76
+ @click=${this.manageItemsClicked}
77
+ >
78
+ ${msg('Item Manager the items')} (${this.selectedItems.length})
79
+ </button>`,
80
+ )}
81
+ <div class="selection-buttons">
82
+ ${when(
83
+ this.showSelectAll,
84
+ () =>
85
+ html` <button
86
+ class="ia-button link select-all-btn"
87
+ @click=${this.selectAllClicked}
88
+ >
89
+ ${msg('Select all')}
90
+ </button>`,
91
+ )}
92
+ ${when(
93
+ this.showUnselectAll,
94
+ () =>
95
+ html` <button
96
+ class="ia-button link unselect-all-btn"
97
+ @click=${this.unselectAllClicked}
98
+ >
99
+ ${msg('Unselect all')}
100
+ </button>`,
101
+ )}
102
+ </div>
103
+ </div>
104
+ </div>
105
+ `;
106
+ }
107
+
108
+ private cancelClicked(): void {
109
+ this.dispatchEvent(new CustomEvent('cancel'));
110
+ }
111
+
112
+ private removeItemsClicked(): void {
113
+ this.dispatchEvent(new CustomEvent('removeItems'));
114
+ }
115
+
116
+ private manageItemsClicked(): void {
117
+ this.dispatchEvent(new CustomEvent('manageItems'));
118
+ }
119
+
120
+ private selectAllClicked(): void {
121
+ this.dispatchEvent(new CustomEvent('selectAll'));
122
+ }
123
+
124
+ private unselectAllClicked(): void {
125
+ this.dispatchEvent(new CustomEvent('unselectAll'));
126
+ }
127
+
128
+ /**
129
+ * Shows a modal dialog confirming the list of items to be removed
130
+ * @param items Which items to list in the modal
131
+ */
132
+ private showRemoveItemsModal(): void {
133
+ const customModalContent = html`
134
+ <remove-items-modal-content
135
+ .items=${this.selectedItems}
136
+ .message=${this.manageViewModalMsg}
137
+ @confirm=${() => this.removeItemsClicked()}
138
+ ></remove-items-modal-content>
139
+ `;
140
+
141
+ const config = new ModalConfig({
142
+ showProcessingIndicator: false,
143
+ processingImageMode: 'processing',
144
+ bodyColor: '#fff',
145
+ headerColor: '#194880',
146
+ showHeaderLogo: false,
147
+ closeOnBackdropClick: true,
148
+ title: html`${msg('Are you sure you want to remove these items?')}`,
149
+ });
150
+
151
+ this.modalManager?.classList.add('remove-items');
152
+ this.modalManager?.showModal({
153
+ config,
154
+ customModalContent,
155
+ userClosedModalCallback: () => {
156
+ this.modalManager?.classList.remove('remove-items');
157
+ },
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Shows a modal dialog indicating that item removal is being processed
163
+ */
164
+ showRemoveItemsProcessingModal(): void {
165
+ const config = new ModalConfig({
166
+ showProcessingIndicator: true,
167
+ processingImageMode: 'processing',
168
+ bodyColor: '#fff',
169
+ headerColor: '#194880',
170
+ showHeaderLogo: false,
171
+ closeOnBackdropClick: true,
172
+ title: html`${msg('Removing selected items...')}`,
173
+ });
174
+
175
+ this.modalManager?.classList.add('remove-items');
176
+ this.modalManager?.showModal({
177
+ config,
178
+ userClosedModalCallback: () => {
179
+ this.modalManager?.classList.remove('remove-items');
180
+ },
181
+ });
182
+ }
183
+
184
+ /**
185
+ * Shows a modal dialog indicating that an error occurred while removing items
186
+ */
187
+ showRemoveItemsErrorModal(): void {
188
+ const config = new ModalConfig({
189
+ showProcessingIndicator: false,
190
+ processingImageMode: 'processing',
191
+ bodyColor: '#fff',
192
+ headerColor: '#691916',
193
+ showHeaderLogo: false,
194
+ closeOnBackdropClick: true,
195
+ title: html`${msg('Error: unable to remove items')}`,
196
+ message: html`${msg(
197
+ 'An error occurred while removing items. Please try again in a few minutes.',
198
+ )}`,
199
+ });
200
+
201
+ this.modalManager?.classList.add('remove-items');
202
+ this.modalManager?.showModal({
203
+ config,
204
+ userClosedModalCallback: () => {
205
+ this.modalManager?.classList.remove('remove-items');
206
+ },
207
+ });
208
+ }
209
+
210
+ static get styles(): CSSResultGroup {
211
+ return css`
212
+ ${iaButtonStyle}
213
+ .manage-container {
214
+ display: flex;
215
+ align-items: center;
216
+ column-gap: 5px;
217
+ padding: 20px 0 20px;
218
+ flex-wrap: wrap;
219
+ }
220
+
221
+ .manage-label {
222
+ display: inline-block;
223
+ font-weight: bold;
224
+ font-size: 1.8rem;
225
+ padding-right: 10px;
226
+ }
227
+
228
+ .manage-buttons {
229
+ display: flex;
230
+ flex-wrap: wrap;
231
+ align-items: center;
232
+ column-gap: 5px;
233
+ }
234
+
235
+ .selection-buttons {
236
+ display: inherit;
237
+ }
238
+
239
+ .ia-button,
240
+ button {
241
+ padding: 6px 12px;
242
+ font-size: 1.4rem;
243
+ margin: 3px 0;
244
+ }
245
+ `;
246
+ }
247
+ }
@@ -147,6 +147,10 @@ export class RestorationStateHandler
147
147
  const sortOption = SORT_OPTIONS[state.selectedSort];
148
148
  let prefix = this.sortDirectionPrefix(state.sortDirection);
149
149
 
150
+ const isTVRelevanceSort =
151
+ state.searchType === SearchType.TV &&
152
+ state.selectedSort === SortField.relevance;
153
+
150
154
  if (sortOption.field === SortField.unrecognized) {
151
155
  // For unrecognized sorts, use the existing param, possibly updating its direction
152
156
  const oldSortParam = oldParams.get('sort') ?? '';
@@ -161,7 +165,7 @@ export class RestorationStateHandler
161
165
  } else {
162
166
  newParams.set('sort', oldSortParam);
163
167
  }
164
- } else if (sortOption.shownInURL) {
168
+ } else if (sortOption.shownInURL || isTVRelevanceSort) {
165
169
  // Otherwise, use the canonical API form of the sort option
166
170
  const canonicalApiSort = sortOption.urlNames[0];
167
171
  newParams.set('sort', `${prefix}${canonicalApiSort}`);