@internetarchive/collection-browser 1.13.0-alpha2 → 1.14.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 (287) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +26 -26
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/LICENSE +661 -661
  8. package/README.md +83 -83
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +9 -9
  11. package/dist/src/app-root.d.ts +64 -54
  12. package/dist/src/app-root.js +320 -293
  13. package/dist/src/app-root.js.map +1 -1
  14. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  15. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  16. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  17. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  18. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  19. package/dist/src/assets/img/icons/chevron.js +2 -2
  20. package/dist/src/assets/img/icons/contract.d.ts +2 -2
  21. package/dist/src/assets/img/icons/contract.js +2 -2
  22. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  23. package/dist/src/assets/img/icons/empty-query.js +2 -2
  24. package/dist/src/assets/img/icons/expand.d.ts +2 -2
  25. package/dist/src/assets/img/icons/expand.js +2 -2
  26. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  27. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  28. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  29. package/dist/src/assets/img/icons/eye.js +2 -2
  30. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  31. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  32. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  33. package/dist/src/assets/img/icons/login-required.js +2 -2
  34. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  35. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  36. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  37. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  38. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  39. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  40. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  41. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  42. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  43. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  44. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  45. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  46. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  47. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  48. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  49. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  50. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  51. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  52. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  53. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  54. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  55. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  56. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  57. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  58. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  59. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  60. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  61. package/dist/src/assets/img/icons/null-result.js +2 -2
  62. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  63. package/dist/src/assets/img/icons/restricted.js +2 -2
  64. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  65. package/dist/src/assets/img/icons/reviews.js +2 -2
  66. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  67. package/dist/src/assets/img/icons/upload.js +2 -2
  68. package/dist/src/assets/img/icons/views.d.ts +1 -1
  69. package/dist/src/assets/img/icons/views.js +2 -2
  70. package/dist/src/circular-activity-indicator.d.ts +5 -5
  71. package/dist/src/circular-activity-indicator.js +17 -17
  72. package/dist/src/collection-browser.d.ts +522 -473
  73. package/dist/src/collection-browser.js +1846 -1697
  74. package/dist/src/collection-browser.js.map +1 -1
  75. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  76. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  77. package/dist/src/collection-facets/facets-template.d.ts +20 -20
  78. package/dist/src/collection-facets/facets-template.js +152 -152
  79. package/dist/src/collection-facets/more-facets-content.d.ts +77 -77
  80. package/dist/src/collection-facets/more-facets-content.js +359 -359
  81. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  82. package/dist/src/collection-facets/more-facets-pagination.js +196 -196
  83. package/dist/src/collection-facets/toggle-switch.d.ts +41 -41
  84. package/dist/src/collection-facets/toggle-switch.js +94 -94
  85. package/dist/src/collection-facets.d.ts +104 -103
  86. package/dist/src/collection-facets.js +511 -498
  87. package/dist/src/collection-facets.js.map +1 -1
  88. package/dist/src/empty-placeholder.d.ts +23 -23
  89. package/dist/src/empty-placeholder.js +74 -74
  90. package/dist/src/expanded-date-picker.d.ts +43 -43
  91. package/dist/src/expanded-date-picker.js +109 -109
  92. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  93. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  94. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  95. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  96. package/dist/src/manage/manage-bar.d.ts +26 -0
  97. package/dist/src/manage/manage-bar.js +147 -0
  98. package/dist/src/manage/manage-bar.js.map +1 -0
  99. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  100. package/dist/src/mediatype/mediatype-config.js +85 -85
  101. package/dist/src/models.d.ts +164 -163
  102. package/dist/src/models.js +269 -269
  103. package/dist/src/models.js.map +1 -1
  104. package/dist/src/restoration-state-handler.d.ts +70 -70
  105. package/dist/src/restoration-state-handler.js +355 -355
  106. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  107. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  108. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  109. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  110. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  111. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  112. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  113. package/dist/src/sort-filter-bar/img/list.js +2 -2
  114. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  115. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  116. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  117. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  118. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  119. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  120. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  121. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  122. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  123. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  124. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +208 -208
  125. package/dist/src/sort-filter-bar/sort-filter-bar.js +637 -637
  126. package/dist/src/styles/item-image-styles.d.ts +8 -8
  127. package/dist/src/styles/item-image-styles.js +9 -9
  128. package/dist/src/styles/sr-only.d.ts +1 -1
  129. package/dist/src/styles/sr-only.js +2 -2
  130. package/dist/src/tiles/base-tile-component.d.ts +18 -18
  131. package/dist/src/tiles/base-tile-component.js +59 -59
  132. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  133. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  134. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  135. package/dist/src/tiles/grid/account-tile.js +72 -72
  136. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  137. package/dist/src/tiles/grid/collection-tile.js +80 -80
  138. package/dist/src/tiles/grid/item-tile.d.ts +27 -27
  139. package/dist/src/tiles/grid/item-tile.js +134 -134
  140. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  141. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  142. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  143. package/dist/src/tiles/grid/tile-stats.js +48 -48
  144. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  145. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  146. package/dist/src/tiles/hover/tile-hover-pane.d.ts +15 -15
  147. package/dist/src/tiles/hover/tile-hover-pane.js +38 -38
  148. package/dist/src/tiles/image-block.d.ts +17 -17
  149. package/dist/src/tiles/image-block.js +72 -72
  150. package/dist/src/tiles/item-image.d.ts +35 -35
  151. package/dist/src/tiles/item-image.js +117 -117
  152. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  153. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  154. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  155. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  156. package/dist/src/tiles/list/tile-list.d.ts +46 -46
  157. package/dist/src/tiles/list/tile-list.js +298 -298
  158. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  159. package/dist/src/tiles/mediatype-icon.js +47 -47
  160. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  161. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  162. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  163. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  164. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  165. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  166. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  167. package/dist/src/tiles/text-snippet-block.js +73 -73
  168. package/dist/src/tiles/tile-dispatcher.d.ts +63 -50
  169. package/dist/src/tiles/tile-dispatcher.js +255 -187
  170. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  171. package/dist/src/tiles/tile-display-value-provider.d.ts +43 -43
  172. package/dist/src/tiles/tile-display-value-provider.js +80 -80
  173. package/dist/src/utils/analytics-events.d.ts +25 -25
  174. package/dist/src/utils/analytics-events.js +27 -27
  175. package/dist/src/utils/array-equals.d.ts +4 -4
  176. package/dist/src/utils/array-equals.js +10 -10
  177. package/dist/src/utils/format-count.d.ts +7 -7
  178. package/dist/src/utils/format-count.js +76 -76
  179. package/dist/src/utils/format-date.d.ts +2 -2
  180. package/dist/src/utils/format-date.js +25 -25
  181. package/dist/src/utils/format-unit-size.d.ts +2 -2
  182. package/dist/src/utils/format-unit-size.js +33 -33
  183. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  184. package/dist/src/utils/local-date-from-utc.js +15 -15
  185. package/dist/src/utils/sha1.d.ts +2 -2
  186. package/dist/src/utils/sha1.js +8 -8
  187. package/dist/test/collection-browser.test.d.ts +1 -1
  188. package/dist/test/collection-browser.test.js +1122 -979
  189. package/dist/test/collection-browser.test.js.map +1 -1
  190. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  191. package/dist/test/collection-facets/facets-template.test.js +134 -134
  192. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  193. package/dist/test/collection-facets/more-facets-content.test.js +133 -133
  194. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  195. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  196. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -1
  197. package/dist/test/collection-facets/toggle-switch.test.js +73 -73
  198. package/dist/test/collection-facets.test.d.ts +2 -2
  199. package/dist/test/collection-facets.test.js +682 -682
  200. package/dist/test/empty-placeholder.test.d.ts +1 -1
  201. package/dist/test/empty-placeholder.test.js +63 -63
  202. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  203. package/dist/test/expanded-date-picker.test.js +95 -95
  204. package/dist/test/icon-overlay.test.d.ts +1 -1
  205. package/dist/test/icon-overlay.test.js +24 -24
  206. package/dist/test/image-block.test.d.ts +1 -1
  207. package/dist/test/image-block.test.js +48 -48
  208. package/dist/test/item-image.test.d.ts +1 -1
  209. package/dist/test/item-image.test.js +86 -84
  210. package/dist/test/item-image.test.js.map +1 -1
  211. package/dist/test/manage/manage-bar.test.d.ts +1 -0
  212. package/dist/test/manage/manage-bar.test.js +73 -0
  213. package/dist/test/manage/manage-bar.test.js.map +1 -0
  214. package/dist/test/mediatype-config.test.d.ts +1 -1
  215. package/dist/test/mediatype-config.test.js +16 -16
  216. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  217. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  218. package/dist/test/mocks/mock-collection-name-cache.d.ts +9 -9
  219. package/dist/test/mocks/mock-collection-name-cache.js +17 -17
  220. package/dist/test/mocks/mock-search-responses.d.ts +21 -21
  221. package/dist/test/mocks/mock-search-responses.js +709 -707
  222. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  223. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  224. package/dist/test/mocks/mock-search-service.js +50 -50
  225. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  226. package/dist/test/restoration-state-handler.test.js +270 -270
  227. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  228. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  229. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  230. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  231. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  232. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +378 -378
  233. package/dist/test/text-overlay.test.d.ts +1 -1
  234. package/dist/test/text-overlay.test.js +48 -48
  235. package/dist/test/text-snippet-block.test.d.ts +1 -1
  236. package/dist/test/text-snippet-block.test.js +57 -57
  237. package/dist/test/tile-stats.test.d.ts +1 -1
  238. package/dist/test/tile-stats.test.js +33 -33
  239. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  240. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  241. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  242. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  243. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  244. package/dist/test/tiles/grid/item-tile.test.js +254 -254
  245. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  246. package/dist/test/tiles/hover/hover-pane-controller.test.js +258 -257
  247. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
  248. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  249. package/dist/test/tiles/hover/tile-hover-pane.test.js +13 -13
  250. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  251. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  252. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  253. package/dist/test/tiles/list/tile-list.test.js +242 -242
  254. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  255. package/dist/test/tiles/tile-dispatcher.test.js +107 -67
  256. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  257. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  258. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  259. package/dist/test/utils/array-equals.test.d.ts +1 -1
  260. package/dist/test/utils/array-equals.test.js +26 -26
  261. package/dist/test/utils/format-count.test.d.ts +1 -1
  262. package/dist/test/utils/format-count.test.js +23 -23
  263. package/dist/test/utils/format-date.test.d.ts +1 -1
  264. package/dist/test/utils/format-date.test.js +17 -17
  265. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  266. package/dist/test/utils/format-unit-size.test.js +17 -17
  267. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  268. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  269. package/local.archive.org.cert +86 -86
  270. package/local.archive.org.key +27 -27
  271. package/package.json +2 -2
  272. package/renovate.json +6 -6
  273. package/src/app-root.ts +29 -0
  274. package/src/collection-browser.ts +197 -23
  275. package/src/collection-facets.ts +13 -1
  276. package/src/manage/manage-bar.ts +151 -0
  277. package/src/models.ts +1 -0
  278. package/src/tiles/tile-dispatcher.ts +71 -5
  279. package/test/collection-browser.test.ts +198 -1
  280. package/test/item-image.test.ts +2 -0
  281. package/test/manage/manage-bar.test.ts +107 -0
  282. package/test/mocks/mock-search-responses.ts +2 -0
  283. package/test/tiles/hover/hover-pane-controller.test.ts +1 -0
  284. package/test/tiles/tile-dispatcher.test.ts +52 -0
  285. package/tsconfig.json +21 -21
  286. package/web-dev-server.config.mjs +30 -30
  287. package/web-test-runner.config.mjs +41 -41
@@ -1,356 +1,356 @@
1
- import { SearchType } from '@internetarchive/search-service';
2
- import { getCookie, setCookie } from 'typescript-cookie';
3
- import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, } from './models';
4
- import { arrayEquals } from './utils/array-equals';
5
- export class RestorationStateHandler {
6
- constructor(options) {
7
- this.cookieDomain = '.archive.org';
8
- this.cookieExpiration = 30;
9
- this.cookiePath = '/';
10
- this.context = options.context;
11
- }
12
- persistState(state) {
13
- if (state.displayMode)
14
- this.persistViewStateToCookies(state.displayMode);
15
- this.persistQueryStateToUrl(state);
16
- }
17
- getRestorationState() {
18
- const restorationState = this.loadQueryStateFromUrl();
19
- const displayMode = this.loadTileViewStateFromCookies();
20
- restorationState.displayMode = displayMode;
21
- return restorationState;
22
- }
23
- persistViewStateToCookies(displayMode) {
24
- const gridState = displayMode === 'grid' ? 'tiles' : 'lists';
25
- setCookie(`view-${this.context}`, gridState, {
26
- domain: this.cookieDomain,
27
- expires: this.cookieExpiration,
28
- path: this.cookiePath,
29
- });
30
- const detailsState = displayMode === 'list-detail' ? 'showdetails' : '';
31
- setCookie(`showdetails-${this.context}`, detailsState, {
32
- domain: this.cookieDomain,
33
- expires: this.cookieExpiration,
34
- path: this.cookiePath,
35
- });
36
- }
37
- loadTileViewStateFromCookies() {
38
- const viewState = getCookie(`view-${this.context}`);
39
- const detailsState = getCookie(`showdetails-${this.context}`);
40
- if (viewState === 'tiles' || viewState === undefined)
41
- return 'grid';
42
- if (detailsState === 'showdetails')
43
- return 'list-detail';
44
- return 'list-compact';
45
- }
46
- persistQueryStateToUrl(state) {
47
- var _a, _b, _c;
48
- const url = new URL(window.location.href);
49
- const oldParams = new URLSearchParams(url.searchParams);
50
- const newParams = this.removeRecognizedParams(url.searchParams);
51
- let replaceEmptySin = false;
52
- if (state.baseQuery) {
53
- newParams.set('query', state.baseQuery);
54
- }
55
- if (state.searchType === SearchType.FULLTEXT) {
56
- newParams.set('sin', 'TXT');
57
- }
58
- if (oldParams.get('sin') === '') {
59
- // Treat empty sin the same as no sin at all
60
- oldParams.delete('sin');
61
- replaceEmptySin = true;
62
- }
63
- if (state.currentPage) {
64
- if (state.currentPage > 1) {
65
- newParams.set('page', state.currentPage.toString());
66
- }
67
- else {
68
- newParams.delete('page');
69
- }
70
- }
71
- if (state.selectedSort) {
72
- const sortOption = SORT_OPTIONS[state.selectedSort];
73
- let prefix = this.sortDirectionPrefix(state.sortDirection);
74
- if (sortOption.field === SortField.unrecognized) {
75
- // For unrecognized sorts, use the existing param, possibly updating its direction
76
- const oldSortParam = (_a = oldParams.get('sort')) !== null && _a !== void 0 ? _a : '';
77
- const { field, direction } = this.getSortFieldAndDirection(oldSortParam);
78
- // Use the state-specified direction if available, or extract one from the param if not
79
- if (!state.sortDirection)
80
- prefix = this.sortDirectionPrefix(direction);
81
- if (field) {
82
- newParams.set('sort', `${prefix}${field}`);
83
- }
84
- else {
85
- newParams.set('sort', oldSortParam);
86
- }
87
- }
88
- else if (sortOption.shownInURL) {
89
- // Otherwise, use the canonical API form of the sort option
90
- const canonicalApiSort = sortOption.urlNames[0];
91
- newParams.set('sort', `${prefix}${canonicalApiSort}`);
92
- }
93
- }
94
- if (state.selectedFacets) {
95
- for (const [facetName, facetValues] of Object.entries(state.selectedFacets)) {
96
- const facetEntries = Object.entries(facetValues);
97
- // eslint-disable-next-line no-continue
98
- if (facetEntries.length === 0)
99
- continue;
100
- for (const [key, data] of facetEntries) {
101
- const notValue = data.state === 'hidden';
102
- const paramValue = `${facetName}:"${key}"`;
103
- if (notValue) {
104
- newParams.append('not[]', paramValue);
105
- }
106
- else {
107
- newParams.append('and[]', paramValue);
108
- }
109
- }
110
- }
111
- }
112
- if (state.minSelectedDate && state.maxSelectedDate) {
113
- newParams.append('and[]', `year:[${state.minSelectedDate} TO ${state.maxSelectedDate}]`);
114
- }
115
- if (state.titleQuery) {
116
- newParams.append('and[]', state.titleQuery);
117
- }
118
- if (state.creatorQuery) {
119
- newParams.append('and[]', state.creatorQuery);
120
- }
121
- // Ensure we aren't pushing consecutive identical states to the history stack.
122
- // - If the state has changed, we push a new history entry.
123
- // - If only the page number has changed, we replace the current history entry.
124
- // - If the state hasn't changed, then do nothing.
125
- let historyMethod = 'pushState';
126
- const nonQueryParamsMatch = this.paramsMatch(oldParams, newParams, [
127
- 'sin',
128
- 'sort',
129
- 'and[]',
130
- 'not[]',
131
- ]);
132
- if (nonQueryParamsMatch &&
133
- this.paramsMatch(oldParams, newParams, ['query'])) {
134
- if (replaceEmptySin) {
135
- // Get rid of any empty sin param
136
- newParams.delete('sin');
137
- }
138
- else if (this.paramsMatch(oldParams, newParams, ['page'])) {
139
- // For page number, we want to replace the page state when it changes,
140
- // not push a new history entry. If it hasn't changed, then we're done.
141
- return;
142
- }
143
- historyMethod = 'replaceState';
144
- }
145
- else if (nonQueryParamsMatch && this.hasLegacyParam(oldParams)) {
146
- // Similarly, if the only non-matching param was a legacy query param, then
147
- // we just want to overwrite it.
148
- historyMethod = 'replaceState';
149
- }
150
- (_c = (_b = window.history)[historyMethod]) === null || _c === void 0 ? void 0 : _c.call(_b, {
151
- query: state.baseQuery,
152
- searchType: state.searchType,
153
- page: state.currentPage,
154
- sort: { field: state.selectedSort, direction: state.sortDirection },
155
- minDate: state.minSelectedDate,
156
- maxDate: state.maxSelectedDate,
157
- facets: state.selectedFacets,
158
- }, '', url);
159
- }
160
- loadQueryStateFromUrl() {
161
- var _a;
162
- const url = new URL(window.location.href);
163
- const searchInside = url.searchParams.get('sin');
164
- const pageNumber = url.searchParams.get('page');
165
- const searchQuery = url.searchParams.get('query');
166
- const sortQuery = url.searchParams.get('sort');
167
- const facetAnds = url.searchParams.getAll('and[]');
168
- const facetNots = url.searchParams.getAll('not[]');
169
- // We also need to check for the presence of params like 'and[0]', 'not[1]', etc.
170
- // since Facebook automatically converts URLs with [] into those forms.
171
- for (const [key, val] of url.searchParams.entries()) {
172
- if (/and\[\d+\]/.test(key)) {
173
- facetAnds.push(val);
174
- }
175
- else if (/not\[\d+\]/.test(key)) {
176
- facetNots.push(val);
177
- }
178
- }
179
- // Legacy search allowed `q` and `search` params for the query, so in the interest
180
- // of backwards-compatibility with old bookmarks, we recognize those here too.
181
- // (However, they still get upgraded to a `query` param when we persist our state
182
- // to the URL).
183
- const legacySearchQuery = (_a = url.searchParams.get('q')) !== null && _a !== void 0 ? _a : url.searchParams.get('search');
184
- const restorationState = {
185
- selectedFacets: getDefaultSelectedFacets(),
186
- };
187
- if (searchQuery) {
188
- restorationState.baseQuery = searchQuery;
189
- }
190
- else if (legacySearchQuery) {
191
- restorationState.baseQuery = legacySearchQuery;
192
- }
193
- switch (searchInside) {
194
- // Eventually there will be TV/Radio search types here too.
195
- case 'TXT':
196
- restorationState.searchType = SearchType.FULLTEXT;
197
- break;
198
- default:
199
- restorationState.searchType = SearchType.METADATA;
200
- break;
201
- }
202
- if (pageNumber) {
203
- const parsed = parseInt(pageNumber, 10);
204
- restorationState.currentPage = parsed;
205
- }
206
- else {
207
- restorationState.currentPage = 1;
208
- }
209
- if (sortQuery) {
210
- const { field, direction } = this.getSortFieldAndDirection(sortQuery);
211
- const sortOption = sortOptionFromAPIString(field);
212
- restorationState.selectedSort = sortOption.field;
213
- if (['asc', 'desc'].includes(direction)) {
214
- restorationState.sortDirection = direction;
215
- }
216
- }
217
- if (facetAnds) {
218
- facetAnds.forEach(and => {
219
- // eslint-disable-next-line prefer-const
220
- let [field, value] = and.split(':');
221
- // Legacy search allowed and[] fields like 'creatorSorter', 'languageSorter', etc.
222
- // which we want to normalize to 'creator', 'language', etc. if redirected here.
223
- field = field.replace(/Sorter$/, '');
224
- // Legacy search also allowed a form of negative faceting like `and[]=-collection:foo`
225
- // which we want to normalize to a not[] param instead
226
- if (field.startsWith('-')) {
227
- facetNots.push(and.slice(1));
228
- return;
229
- }
230
- switch (field) {
231
- case 'year': {
232
- const [minDate, maxDate] = value.split(' TO ');
233
- // we have two potential ways of filtering by date:
234
- // the range with "date TO date" or the single date with "date"
235
- // this is checking for the range case and if we don't have those, fall
236
- // back to the single date case
237
- if (minDate && maxDate) {
238
- restorationState.minSelectedDate = minDate.substring(1, minDate.length);
239
- restorationState.maxSelectedDate = maxDate.substring(0, maxDate.length - 1);
240
- }
241
- else {
242
- this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'selected');
243
- }
244
- break;
245
- }
246
- case 'firstTitle':
247
- restorationState.selectedTitleFilter = value;
248
- break;
249
- case 'firstCreator':
250
- restorationState.selectedCreatorFilter = value;
251
- break;
252
- default:
253
- this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'selected');
254
- }
255
- });
256
- }
257
- if (facetNots) {
258
- facetNots.forEach(not => {
259
- const [field, value] = not.split(':');
260
- this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'hidden');
261
- });
262
- }
263
- return restorationState;
264
- }
265
- /**
266
- * Converts a URL sort param into a field/direction pair, if possible.
267
- * Either or both may be undefined if the param is not in a recognized format.
268
- */
269
- getSortFieldAndDirection(sortParam) {
270
- // check for two different sort formats: `date desc` and `-date`
271
- const hasSpace = sortParam.indexOf(' ') > -1;
272
- let field;
273
- let direction;
274
- if (hasSpace) {
275
- [field, direction] = sortParam.split(' ');
276
- }
277
- else {
278
- field = sortParam.startsWith('-') ? sortParam.slice(1) : sortParam;
279
- direction = sortParam.startsWith('-') ? 'desc' : 'asc';
280
- }
281
- return { field, direction };
282
- }
283
- /** Returns the `-` prefix for `desc` sort, or the empty string otherwise. */
284
- sortDirectionPrefix(sortDirection) {
285
- return sortDirection === 'desc' ? '-' : '';
286
- }
287
- /** Remove optional opening and closing quotes from a string */
288
- stripQuotes(value) {
289
- if (value.startsWith('"') && value.endsWith('"')) {
290
- return value.substring(1, value.length - 1);
291
- }
292
- return value;
293
- }
294
- /**
295
- * Returns whether the two given URLSearchParams objects have
296
- * identical values for all of the given param keys. If either
297
- * object contains more than one value for a given key, then
298
- * all of the values for that key must match (disregarding order).
299
- */
300
- paramsMatch(searchParams1, searchParams2, keys) {
301
- return keys.every(key => arrayEquals(searchParams1.getAll(key).sort(), searchParams2.getAll(key).sort()));
302
- }
303
- /**
304
- * Deletes any params from the given URLSearchParams object that are recognized
305
- * when loading state from the URL.
306
- */
307
- removeRecognizedParams(searchParams) {
308
- // Remove all of our standard params
309
- searchParams.delete('query');
310
- searchParams.delete('sin');
311
- searchParams.delete('page');
312
- searchParams.delete('sort');
313
- searchParams.delete('and[]');
314
- searchParams.delete('not[]');
315
- // Remove any and/not facet params that contain numbers in their square brackets
316
- for (const key of searchParams.keys()) {
317
- if (/(and|not)\[\d+\]/.test(key)) {
318
- searchParams.delete(key);
319
- }
320
- }
321
- // Also remove some legacy params that should have been upgraded to the ones above
322
- searchParams.delete('q');
323
- searchParams.delete('search');
324
- return searchParams;
325
- }
326
- /**
327
- * Returns whether the given URLSearchParams object contains a param that is
328
- * only recognized as a holdover from legacy search, and should not be
329
- * persisted to the URL.
330
- */
331
- hasLegacyParam(searchParams) {
332
- return searchParams.has('q') || searchParams.has('search');
333
- }
334
- /**
335
- * Sets the facet state for the given field & value to the given state,
336
- * creating any previously-undefined buckets as needed.
337
- */
338
- setSelectedFacetState(selectedFacets, field, value, state) {
339
- var _a;
340
- const facet = selectedFacets[field];
341
- if (!facet)
342
- return; // Unrecognized facet group, ignore it.
343
- const unQuotedValue = this.stripQuotes(value);
344
- (_a = facet[unQuotedValue]) !== null && _a !== void 0 ? _a : (facet[unQuotedValue] = this.getDefaultBucket(value));
345
- facet[unQuotedValue].state = state;
346
- }
347
- /** Returns a default bucket with the given key, count of 0, and state 'none'. */
348
- getDefaultBucket(key) {
349
- return {
350
- key,
351
- count: 0,
352
- state: 'none',
353
- };
354
- }
355
- }
1
+ import { SearchType } from '@internetarchive/search-service';
2
+ import { getCookie, setCookie } from 'typescript-cookie';
3
+ import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, } from './models';
4
+ import { arrayEquals } from './utils/array-equals';
5
+ export class RestorationStateHandler {
6
+ constructor(options) {
7
+ this.cookieDomain = '.archive.org';
8
+ this.cookieExpiration = 30;
9
+ this.cookiePath = '/';
10
+ this.context = options.context;
11
+ }
12
+ persistState(state) {
13
+ if (state.displayMode)
14
+ this.persistViewStateToCookies(state.displayMode);
15
+ this.persistQueryStateToUrl(state);
16
+ }
17
+ getRestorationState() {
18
+ const restorationState = this.loadQueryStateFromUrl();
19
+ const displayMode = this.loadTileViewStateFromCookies();
20
+ restorationState.displayMode = displayMode;
21
+ return restorationState;
22
+ }
23
+ persistViewStateToCookies(displayMode) {
24
+ const gridState = displayMode === 'grid' ? 'tiles' : 'lists';
25
+ setCookie(`view-${this.context}`, gridState, {
26
+ domain: this.cookieDomain,
27
+ expires: this.cookieExpiration,
28
+ path: this.cookiePath,
29
+ });
30
+ const detailsState = displayMode === 'list-detail' ? 'showdetails' : '';
31
+ setCookie(`showdetails-${this.context}`, detailsState, {
32
+ domain: this.cookieDomain,
33
+ expires: this.cookieExpiration,
34
+ path: this.cookiePath,
35
+ });
36
+ }
37
+ loadTileViewStateFromCookies() {
38
+ const viewState = getCookie(`view-${this.context}`);
39
+ const detailsState = getCookie(`showdetails-${this.context}`);
40
+ if (viewState === 'tiles' || viewState === undefined)
41
+ return 'grid';
42
+ if (detailsState === 'showdetails')
43
+ return 'list-detail';
44
+ return 'list-compact';
45
+ }
46
+ persistQueryStateToUrl(state) {
47
+ var _a, _b, _c;
48
+ const url = new URL(window.location.href);
49
+ const oldParams = new URLSearchParams(url.searchParams);
50
+ const newParams = this.removeRecognizedParams(url.searchParams);
51
+ let replaceEmptySin = false;
52
+ if (state.baseQuery) {
53
+ newParams.set('query', state.baseQuery);
54
+ }
55
+ if (state.searchType === SearchType.FULLTEXT) {
56
+ newParams.set('sin', 'TXT');
57
+ }
58
+ if (oldParams.get('sin') === '') {
59
+ // Treat empty sin the same as no sin at all
60
+ oldParams.delete('sin');
61
+ replaceEmptySin = true;
62
+ }
63
+ if (state.currentPage) {
64
+ if (state.currentPage > 1) {
65
+ newParams.set('page', state.currentPage.toString());
66
+ }
67
+ else {
68
+ newParams.delete('page');
69
+ }
70
+ }
71
+ if (state.selectedSort) {
72
+ const sortOption = SORT_OPTIONS[state.selectedSort];
73
+ let prefix = this.sortDirectionPrefix(state.sortDirection);
74
+ if (sortOption.field === SortField.unrecognized) {
75
+ // For unrecognized sorts, use the existing param, possibly updating its direction
76
+ const oldSortParam = (_a = oldParams.get('sort')) !== null && _a !== void 0 ? _a : '';
77
+ const { field, direction } = this.getSortFieldAndDirection(oldSortParam);
78
+ // Use the state-specified direction if available, or extract one from the param if not
79
+ if (!state.sortDirection)
80
+ prefix = this.sortDirectionPrefix(direction);
81
+ if (field) {
82
+ newParams.set('sort', `${prefix}${field}`);
83
+ }
84
+ else {
85
+ newParams.set('sort', oldSortParam);
86
+ }
87
+ }
88
+ else if (sortOption.shownInURL) {
89
+ // Otherwise, use the canonical API form of the sort option
90
+ const canonicalApiSort = sortOption.urlNames[0];
91
+ newParams.set('sort', `${prefix}${canonicalApiSort}`);
92
+ }
93
+ }
94
+ if (state.selectedFacets) {
95
+ for (const [facetName, facetValues] of Object.entries(state.selectedFacets)) {
96
+ const facetEntries = Object.entries(facetValues);
97
+ // eslint-disable-next-line no-continue
98
+ if (facetEntries.length === 0)
99
+ continue;
100
+ for (const [key, data] of facetEntries) {
101
+ const notValue = data.state === 'hidden';
102
+ const paramValue = `${facetName}:"${key}"`;
103
+ if (notValue) {
104
+ newParams.append('not[]', paramValue);
105
+ }
106
+ else {
107
+ newParams.append('and[]', paramValue);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ if (state.minSelectedDate && state.maxSelectedDate) {
113
+ newParams.append('and[]', `year:[${state.minSelectedDate} TO ${state.maxSelectedDate}]`);
114
+ }
115
+ if (state.titleQuery) {
116
+ newParams.append('and[]', state.titleQuery);
117
+ }
118
+ if (state.creatorQuery) {
119
+ newParams.append('and[]', state.creatorQuery);
120
+ }
121
+ // Ensure we aren't pushing consecutive identical states to the history stack.
122
+ // - If the state has changed, we push a new history entry.
123
+ // - If only the page number has changed, we replace the current history entry.
124
+ // - If the state hasn't changed, then do nothing.
125
+ let historyMethod = 'pushState';
126
+ const nonQueryParamsMatch = this.paramsMatch(oldParams, newParams, [
127
+ 'sin',
128
+ 'sort',
129
+ 'and[]',
130
+ 'not[]',
131
+ ]);
132
+ if (nonQueryParamsMatch &&
133
+ this.paramsMatch(oldParams, newParams, ['query'])) {
134
+ if (replaceEmptySin) {
135
+ // Get rid of any empty sin param
136
+ newParams.delete('sin');
137
+ }
138
+ else if (this.paramsMatch(oldParams, newParams, ['page'])) {
139
+ // For page number, we want to replace the page state when it changes,
140
+ // not push a new history entry. If it hasn't changed, then we're done.
141
+ return;
142
+ }
143
+ historyMethod = 'replaceState';
144
+ }
145
+ else if (nonQueryParamsMatch && this.hasLegacyParam(oldParams)) {
146
+ // Similarly, if the only non-matching param was a legacy query param, then
147
+ // we just want to overwrite it.
148
+ historyMethod = 'replaceState';
149
+ }
150
+ (_c = (_b = window.history)[historyMethod]) === null || _c === void 0 ? void 0 : _c.call(_b, {
151
+ query: state.baseQuery,
152
+ searchType: state.searchType,
153
+ page: state.currentPage,
154
+ sort: { field: state.selectedSort, direction: state.sortDirection },
155
+ minDate: state.minSelectedDate,
156
+ maxDate: state.maxSelectedDate,
157
+ facets: state.selectedFacets,
158
+ }, '', url);
159
+ }
160
+ loadQueryStateFromUrl() {
161
+ var _a;
162
+ const url = new URL(window.location.href);
163
+ const searchInside = url.searchParams.get('sin');
164
+ const pageNumber = url.searchParams.get('page');
165
+ const searchQuery = url.searchParams.get('query');
166
+ const sortQuery = url.searchParams.get('sort');
167
+ const facetAnds = url.searchParams.getAll('and[]');
168
+ const facetNots = url.searchParams.getAll('not[]');
169
+ // We also need to check for the presence of params like 'and[0]', 'not[1]', etc.
170
+ // since Facebook automatically converts URLs with [] into those forms.
171
+ for (const [key, val] of url.searchParams.entries()) {
172
+ if (/and\[\d+\]/.test(key)) {
173
+ facetAnds.push(val);
174
+ }
175
+ else if (/not\[\d+\]/.test(key)) {
176
+ facetNots.push(val);
177
+ }
178
+ }
179
+ // Legacy search allowed `q` and `search` params for the query, so in the interest
180
+ // of backwards-compatibility with old bookmarks, we recognize those here too.
181
+ // (However, they still get upgraded to a `query` param when we persist our state
182
+ // to the URL).
183
+ const legacySearchQuery = (_a = url.searchParams.get('q')) !== null && _a !== void 0 ? _a : url.searchParams.get('search');
184
+ const restorationState = {
185
+ selectedFacets: getDefaultSelectedFacets(),
186
+ };
187
+ if (searchQuery) {
188
+ restorationState.baseQuery = searchQuery;
189
+ }
190
+ else if (legacySearchQuery) {
191
+ restorationState.baseQuery = legacySearchQuery;
192
+ }
193
+ switch (searchInside) {
194
+ // Eventually there will be TV/Radio search types here too.
195
+ case 'TXT':
196
+ restorationState.searchType = SearchType.FULLTEXT;
197
+ break;
198
+ default:
199
+ restorationState.searchType = SearchType.METADATA;
200
+ break;
201
+ }
202
+ if (pageNumber) {
203
+ const parsed = parseInt(pageNumber, 10);
204
+ restorationState.currentPage = parsed;
205
+ }
206
+ else {
207
+ restorationState.currentPage = 1;
208
+ }
209
+ if (sortQuery) {
210
+ const { field, direction } = this.getSortFieldAndDirection(sortQuery);
211
+ const sortOption = sortOptionFromAPIString(field);
212
+ restorationState.selectedSort = sortOption.field;
213
+ if (['asc', 'desc'].includes(direction)) {
214
+ restorationState.sortDirection = direction;
215
+ }
216
+ }
217
+ if (facetAnds) {
218
+ facetAnds.forEach(and => {
219
+ // eslint-disable-next-line prefer-const
220
+ let [field, value] = and.split(':');
221
+ // Legacy search allowed and[] fields like 'creatorSorter', 'languageSorter', etc.
222
+ // which we want to normalize to 'creator', 'language', etc. if redirected here.
223
+ field = field.replace(/Sorter$/, '');
224
+ // Legacy search also allowed a form of negative faceting like `and[]=-collection:foo`
225
+ // which we want to normalize to a not[] param instead
226
+ if (field.startsWith('-')) {
227
+ facetNots.push(and.slice(1));
228
+ return;
229
+ }
230
+ switch (field) {
231
+ case 'year': {
232
+ const [minDate, maxDate] = value.split(' TO ');
233
+ // we have two potential ways of filtering by date:
234
+ // the range with "date TO date" or the single date with "date"
235
+ // this is checking for the range case and if we don't have those, fall
236
+ // back to the single date case
237
+ if (minDate && maxDate) {
238
+ restorationState.minSelectedDate = minDate.substring(1, minDate.length);
239
+ restorationState.maxSelectedDate = maxDate.substring(0, maxDate.length - 1);
240
+ }
241
+ else {
242
+ this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'selected');
243
+ }
244
+ break;
245
+ }
246
+ case 'firstTitle':
247
+ restorationState.selectedTitleFilter = value;
248
+ break;
249
+ case 'firstCreator':
250
+ restorationState.selectedCreatorFilter = value;
251
+ break;
252
+ default:
253
+ this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'selected');
254
+ }
255
+ });
256
+ }
257
+ if (facetNots) {
258
+ facetNots.forEach(not => {
259
+ const [field, value] = not.split(':');
260
+ this.setSelectedFacetState(restorationState.selectedFacets, field, value, 'hidden');
261
+ });
262
+ }
263
+ return restorationState;
264
+ }
265
+ /**
266
+ * Converts a URL sort param into a field/direction pair, if possible.
267
+ * Either or both may be undefined if the param is not in a recognized format.
268
+ */
269
+ getSortFieldAndDirection(sortParam) {
270
+ // check for two different sort formats: `date desc` and `-date`
271
+ const hasSpace = sortParam.indexOf(' ') > -1;
272
+ let field;
273
+ let direction;
274
+ if (hasSpace) {
275
+ [field, direction] = sortParam.split(' ');
276
+ }
277
+ else {
278
+ field = sortParam.startsWith('-') ? sortParam.slice(1) : sortParam;
279
+ direction = sortParam.startsWith('-') ? 'desc' : 'asc';
280
+ }
281
+ return { field, direction };
282
+ }
283
+ /** Returns the `-` prefix for `desc` sort, or the empty string otherwise. */
284
+ sortDirectionPrefix(sortDirection) {
285
+ return sortDirection === 'desc' ? '-' : '';
286
+ }
287
+ /** Remove optional opening and closing quotes from a string */
288
+ stripQuotes(value) {
289
+ if (value.startsWith('"') && value.endsWith('"')) {
290
+ return value.substring(1, value.length - 1);
291
+ }
292
+ return value;
293
+ }
294
+ /**
295
+ * Returns whether the two given URLSearchParams objects have
296
+ * identical values for all of the given param keys. If either
297
+ * object contains more than one value for a given key, then
298
+ * all of the values for that key must match (disregarding order).
299
+ */
300
+ paramsMatch(searchParams1, searchParams2, keys) {
301
+ return keys.every(key => arrayEquals(searchParams1.getAll(key).sort(), searchParams2.getAll(key).sort()));
302
+ }
303
+ /**
304
+ * Deletes any params from the given URLSearchParams object that are recognized
305
+ * when loading state from the URL.
306
+ */
307
+ removeRecognizedParams(searchParams) {
308
+ // Remove all of our standard params
309
+ searchParams.delete('query');
310
+ searchParams.delete('sin');
311
+ searchParams.delete('page');
312
+ searchParams.delete('sort');
313
+ searchParams.delete('and[]');
314
+ searchParams.delete('not[]');
315
+ // Remove any and/not facet params that contain numbers in their square brackets
316
+ for (const key of searchParams.keys()) {
317
+ if (/(and|not)\[\d+\]/.test(key)) {
318
+ searchParams.delete(key);
319
+ }
320
+ }
321
+ // Also remove some legacy params that should have been upgraded to the ones above
322
+ searchParams.delete('q');
323
+ searchParams.delete('search');
324
+ return searchParams;
325
+ }
326
+ /**
327
+ * Returns whether the given URLSearchParams object contains a param that is
328
+ * only recognized as a holdover from legacy search, and should not be
329
+ * persisted to the URL.
330
+ */
331
+ hasLegacyParam(searchParams) {
332
+ return searchParams.has('q') || searchParams.has('search');
333
+ }
334
+ /**
335
+ * Sets the facet state for the given field & value to the given state,
336
+ * creating any previously-undefined buckets as needed.
337
+ */
338
+ setSelectedFacetState(selectedFacets, field, value, state) {
339
+ var _a;
340
+ const facet = selectedFacets[field];
341
+ if (!facet)
342
+ return; // Unrecognized facet group, ignore it.
343
+ const unQuotedValue = this.stripQuotes(value);
344
+ (_a = facet[unQuotedValue]) !== null && _a !== void 0 ? _a : (facet[unQuotedValue] = this.getDefaultBucket(value));
345
+ facet[unQuotedValue].state = state;
346
+ }
347
+ /** Returns a default bucket with the given key, count of 0, and state 'none'. */
348
+ getDefaultBucket(key) {
349
+ return {
350
+ key,
351
+ count: 0,
352
+ state: 'none',
353
+ };
354
+ }
355
+ }
356
356
  //# sourceMappingURL=restoration-state-handler.js.map