@internetarchive/collection-browser 3.3.1 → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +29 -29
- package/.github/workflows/ci.yml +27 -27
- package/.github/workflows/gh-pages-main.yml +39 -39
- package/.github/workflows/npm-publish.yml +39 -39
- package/.github/workflows/pr-preview.yml +38 -38
- package/.husky/pre-commit +4 -4
- package/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +83 -83
- package/dist/src/collection-browser.js +683 -683
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/more-facets-content.js +118 -118
- package/dist/src/collection-facets/more-facets-content.js.map +1 -1
- package/dist/src/collection-facets.js +265 -266
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
- package/dist/src/data-source/models.js.map +1 -1
- package/dist/src/tiles/base-tile-component.js.map +1 -1
- package/dist/src/tiles/grid/account-tile.js +36 -36
- package/dist/src/tiles/grid/account-tile.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +77 -77
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.js +137 -137
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.d.ts +9 -1
- package/dist/src/tiles/hover/hover-pane-controller.js +105 -37
- package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
- package/dist/src/tiles/hover/tile-hover-pane.d.ts +1 -0
- package/dist/src/tiles/hover/tile-hover-pane.js +115 -112
- package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +99 -99
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +297 -297
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.d.ts +4 -1
- package/dist/src/tiles/tile-dispatcher.js +231 -204
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/utils/format-date.js.map +1 -1
- package/dist/test/collection-browser.test.js +189 -189
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/tiles/grid/item-tile.test.js +77 -77
- package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
- package/dist/test/tiles/hover/hover-pane-controller.test.js +68 -21
- package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list-compact.test.js +70 -70
- package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +126 -126
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/dist/test/tiles/tile-dispatcher.test.js +130 -52
- package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
- package/dist/test/utils/format-date.test.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/index.html +24 -24
- package/local.archive.org.cert +86 -86
- package/local.archive.org.key +27 -27
- package/package.json +118 -117
- package/renovate.json +6 -6
- package/src/collection-browser.ts +2829 -2829
- package/src/collection-facets/more-facets-content.ts +639 -639
- package/src/collection-facets.ts +994 -995
- package/src/data-source/collection-browser-data-source.ts +1401 -1401
- package/src/data-source/collection-browser-query-state.ts +65 -65
- package/src/data-source/models.ts +43 -43
- package/src/tiles/base-tile-component.ts +65 -65
- package/src/tiles/grid/account-tile.ts +113 -113
- package/src/tiles/grid/collection-tile.ts +163 -163
- package/src/tiles/grid/item-tile.ts +340 -340
- package/src/tiles/hover/hover-pane-controller.ts +613 -517
- package/src/tiles/hover/tile-hover-pane.ts +184 -180
- package/src/tiles/list/tile-list-compact.ts +239 -239
- package/src/tiles/list/tile-list.ts +700 -700
- package/src/tiles/tile-dispatcher.ts +517 -490
- package/src/utils/format-date.ts +62 -62
- package/test/collection-browser.test.ts +2403 -2403
- package/test/tiles/grid/item-tile.test.ts +520 -520
- package/test/tiles/hover/hover-pane-controller.test.ts +418 -353
- package/test/tiles/list/tile-list-compact.test.ts +282 -282
- package/test/tiles/list/tile-list.test.ts +552 -552
- package/test/tiles/tile-dispatcher.test.ts +283 -187
- package/test/utils/format-date.test.ts +89 -89
- package/tsconfig.json +20 -20
- package/web-dev-server.config.mjs +30 -30
- package/web-test-runner.config.mjs +41 -41
|
@@ -26,6 +26,10 @@ export interface HoverPaneProviderInterface {
|
|
|
26
26
|
getHoverPane(): HTMLElement | undefined;
|
|
27
27
|
/** Returns properties that should be passed to the hover pane. */
|
|
28
28
|
getHoverPaneProps(): HoverPaneProperties;
|
|
29
|
+
/** When user has keyboard navigated out of more info, we want the host to get focus */
|
|
30
|
+
acquireFocus(): void;
|
|
31
|
+
/** When user has keyboard navigated out of more info, we want the host to lose focus */
|
|
32
|
+
releaseFocus(): void;
|
|
29
33
|
}
|
|
30
34
|
export interface ToggleHoverPaneOptions {
|
|
31
35
|
coords: {
|
|
@@ -155,7 +159,7 @@ export declare class HoverPaneController implements HoverPaneControllerInterface
|
|
|
155
159
|
* correct width and height. If the hover pane is not present, the returned offsets
|
|
156
160
|
* will simply represent the current pointer position.
|
|
157
161
|
*/
|
|
158
|
-
private
|
|
162
|
+
private makePaneDesiredOffsets;
|
|
159
163
|
/**
|
|
160
164
|
* Adds to the host element all the listeners necessary to make the
|
|
161
165
|
* hover pane functional.
|
|
@@ -165,6 +169,10 @@ export declare class HoverPaneController implements HoverPaneControllerInterface
|
|
|
165
169
|
* Removes all the hover pane listeners from the host element.
|
|
166
170
|
*/
|
|
167
171
|
private detachListeners;
|
|
172
|
+
private handleFocus;
|
|
173
|
+
private handleBlur;
|
|
174
|
+
private handleKeyDown;
|
|
175
|
+
private handleKeyUp;
|
|
168
176
|
/**
|
|
169
177
|
* Handler for the mouseenter event on the host element.
|
|
170
178
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { html, nothing, } from 'lit';
|
|
2
|
+
import { msg } from '@lit/localize';
|
|
2
3
|
const clamp = (val, min = -Infinity, max = Infinity) => Math.max(min, Math.min(val, max));
|
|
3
4
|
export class HoverPaneController {
|
|
4
5
|
constructor(
|
|
@@ -56,6 +57,41 @@ export class HoverPaneController {
|
|
|
56
57
|
this.forceTouchBackdrop = false;
|
|
57
58
|
/** A record of the last mouse position on the host element, for positioning the hover pane */
|
|
58
59
|
this.lastPointerClientPos = { x: 0, y: 0 };
|
|
60
|
+
this.handleFocus = () => {
|
|
61
|
+
if (this.hoverPaneState === 'hidden') {
|
|
62
|
+
this.showHoverPane({
|
|
63
|
+
anchor: 'host',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.handleBlur = () => {
|
|
68
|
+
if (this.hoverPaneState !== 'hidden') {
|
|
69
|
+
this.fadeOutHoverPane();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
this.handleKeyDown = (e) => {
|
|
73
|
+
if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') &&
|
|
74
|
+
this.hoverPaneState !== 'hidden') {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.handleKeyUp = (e) => {
|
|
79
|
+
if (this.hoverPaneState === 'hidden' || !this.hoverPane)
|
|
80
|
+
return;
|
|
81
|
+
if (e.key === 'ArrowDown') {
|
|
82
|
+
this.hoverPane.tabIndex = 1;
|
|
83
|
+
this.hoverPane.focus();
|
|
84
|
+
}
|
|
85
|
+
const isArrowUp = e.key === 'ArrowUp';
|
|
86
|
+
const isEscape = e.key === 'Escape' || e.key === 'Esc';
|
|
87
|
+
if (isEscape) {
|
|
88
|
+
this.fadeOutHoverPane();
|
|
89
|
+
}
|
|
90
|
+
if (isArrowUp || isEscape) {
|
|
91
|
+
this.hoverPane.tabIndex = -1;
|
|
92
|
+
this.host.acquireFocus();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
59
95
|
/**
|
|
60
96
|
* Handler for the mouseenter event on the host element.
|
|
61
97
|
*/
|
|
@@ -91,10 +127,10 @@ export class HoverPaneController {
|
|
|
91
127
|
*/
|
|
92
128
|
// NB: Arrow function so 'this' remains bound to the controller
|
|
93
129
|
this.handleMouseLeave = () => {
|
|
130
|
+
this.host.releaseFocus();
|
|
94
131
|
// Abort any timer to show the hover pane, as the mouse has left the tile
|
|
95
132
|
clearTimeout(this.showTimer);
|
|
96
133
|
// Hide the hover pane if it's already been shown
|
|
97
|
-
clearTimeout(this.hideTimer);
|
|
98
134
|
if (this.hoverPaneState !== 'hidden') {
|
|
99
135
|
this.hideTimer = window.setTimeout(() => {
|
|
100
136
|
this.fadeOutHoverPane();
|
|
@@ -171,19 +207,26 @@ export class HoverPaneController {
|
|
|
171
207
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
172
208
|
this.hoverPaneProps = this.host.getHoverPaneProps();
|
|
173
209
|
return this.shouldRenderHoverPane
|
|
174
|
-
? html `
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
.
|
|
181
|
-
.
|
|
182
|
-
.
|
|
183
|
-
.
|
|
184
|
-
.
|
|
185
|
-
.
|
|
186
|
-
|
|
210
|
+
? html `
|
|
211
|
+
${this.touchBackdropTemplate}
|
|
212
|
+
<tile-hover-pane
|
|
213
|
+
popover
|
|
214
|
+
tabindex="-1"
|
|
215
|
+
aria-describedby="tile-hover-pane-aria-description"
|
|
216
|
+
.model=${(_a = this.hoverPaneProps) === null || _a === void 0 ? void 0 : _a.model}
|
|
217
|
+
.baseNavigationUrl=${(_b = this.hoverPaneProps) === null || _b === void 0 ? void 0 : _b.baseNavigationUrl}
|
|
218
|
+
.baseImageUrl=${(_c = this.hoverPaneProps) === null || _c === void 0 ? void 0 : _c.baseImageUrl}
|
|
219
|
+
.loggedIn=${(_d = this.hoverPaneProps) === null || _d === void 0 ? void 0 : _d.loggedIn}
|
|
220
|
+
.suppressBlurring=${(_e = this.hoverPaneProps) === null || _e === void 0 ? void 0 : _e.suppressBlurring}
|
|
221
|
+
.sortParam=${(_f = this.hoverPaneProps) === null || _f === void 0 ? void 0 : _f.sortParam}
|
|
222
|
+
.collectionTitles=${(_g = this.hoverPaneProps) === null || _g === void 0 ? void 0 : _g.collectionTitles}
|
|
223
|
+
.mobileBreakpoint=${this.mobileBreakpoint}
|
|
224
|
+
.currentWidth=${window.innerWidth}
|
|
225
|
+
></tile-hover-pane>
|
|
226
|
+
<div id="tile-hover-pane-aria-description" class="sr-only">
|
|
227
|
+
${msg('Press Up Arrow to exit item detail preview')}
|
|
228
|
+
</div>
|
|
229
|
+
`
|
|
187
230
|
: nothing;
|
|
188
231
|
}
|
|
189
232
|
/** @inheritdoc */
|
|
@@ -208,15 +251,15 @@ export class HoverPaneController {
|
|
|
208
251
|
*/
|
|
209
252
|
get touchBackdropTemplate() {
|
|
210
253
|
return this.showTouchBackdrop
|
|
211
|
-
? html `<div
|
|
212
|
-
id="touch-backdrop"
|
|
213
|
-
@touchstart=${this.handleBackdropInteraction}
|
|
214
|
-
@touchmove=${this.handleBackdropInteraction}
|
|
215
|
-
@touchend=${this.handleBackdropInteraction}
|
|
216
|
-
@touchcancel=${this.handleBackdropInteraction}
|
|
217
|
-
@mouseenter=${(e) => e.stopPropagation()}
|
|
218
|
-
@mousemove=${(e) => e.stopPropagation()}
|
|
219
|
-
@mouseleave=${(e) => e.stopPropagation()}
|
|
254
|
+
? html `<div
|
|
255
|
+
id="touch-backdrop"
|
|
256
|
+
@touchstart=${this.handleBackdropInteraction}
|
|
257
|
+
@touchmove=${this.handleBackdropInteraction}
|
|
258
|
+
@touchend=${this.handleBackdropInteraction}
|
|
259
|
+
@touchcancel=${this.handleBackdropInteraction}
|
|
260
|
+
@mouseenter=${(e) => e.stopPropagation()}
|
|
261
|
+
@mousemove=${(e) => e.stopPropagation()}
|
|
262
|
+
@mouseleave=${(e) => e.stopPropagation()}
|
|
220
263
|
></div>`
|
|
221
264
|
: nothing;
|
|
222
265
|
}
|
|
@@ -248,21 +291,30 @@ export class HoverPaneController {
|
|
|
248
291
|
* correct width and height. If the hover pane is not present, the returned offsets
|
|
249
292
|
* will simply represent the current pointer position.
|
|
250
293
|
*/
|
|
251
|
-
|
|
294
|
+
makePaneDesiredOffsets(anchor) {
|
|
252
295
|
// Try to find offsets for the hover pane that:
|
|
253
296
|
// (a) cause it to lie entirely within the viewport, and
|
|
254
297
|
// (b) to the extent possible, minimize the distance between the
|
|
255
|
-
// nearest corner of the hover pane and the mouse position
|
|
298
|
+
// nearest corner of the hover pane and the mouse/host element position
|
|
256
299
|
// (with some additional offsets applied after the fact).
|
|
257
300
|
var _a;
|
|
258
|
-
let [left, top] = [
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
301
|
+
let [left, top] = [0, 0];
|
|
302
|
+
switch (anchor) {
|
|
303
|
+
case 'host':
|
|
304
|
+
const hostRect = this.host.getBoundingClientRect();
|
|
305
|
+
// slight inset from host top left corner
|
|
306
|
+
left = hostRect.left + 20;
|
|
307
|
+
top = hostRect.top + 30;
|
|
308
|
+
break;
|
|
309
|
+
case 'cursor':
|
|
310
|
+
left = this.lastPointerClientPos.x;
|
|
311
|
+
top = this.lastPointerClientPos.y;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
// Flip the hover pane according to which quadrant of the viewport the coordinates are in.
|
|
263
315
|
// (Similar to how Wikipedia's link hover panes work)
|
|
264
|
-
const flipHorizontal =
|
|
265
|
-
const flipVertical =
|
|
316
|
+
const flipHorizontal = left > window.innerWidth / 2;
|
|
317
|
+
const flipVertical = top > window.innerHeight / 2;
|
|
266
318
|
const hoverPaneRect = (_a = this.hoverPane) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
267
319
|
if (hoverPaneRect) {
|
|
268
320
|
// If we need to flip the hover pane, do so by subtracting its width/height from left/top
|
|
@@ -272,7 +324,7 @@ export class HoverPaneController {
|
|
|
272
324
|
if (flipVertical) {
|
|
273
325
|
top -= hoverPaneRect.height;
|
|
274
326
|
}
|
|
275
|
-
// Apply desired offsets from the
|
|
327
|
+
// Apply desired offsets from the target position
|
|
276
328
|
left += (flipHorizontal ? -1 : 1) * this.offsetX;
|
|
277
329
|
top += (flipVertical ? -1 : 1) * this.offsetY;
|
|
278
330
|
// On mobile view, shunt the hover pane to avoid overflowing the viewport
|
|
@@ -290,6 +342,11 @@ export class HoverPaneController {
|
|
|
290
342
|
* hover pane functional.
|
|
291
343
|
*/
|
|
292
344
|
attachListeners() {
|
|
345
|
+
// keyboard navigation listeners
|
|
346
|
+
this.host.addEventListener('focus', this.handleFocus);
|
|
347
|
+
this.host.addEventListener('blur', this.handleBlur);
|
|
348
|
+
this.host.addEventListener('keyup', this.handleKeyUp);
|
|
349
|
+
this.host.addEventListener('keydown', this.handleKeyDown);
|
|
293
350
|
if (this.isHoverEnabled) {
|
|
294
351
|
this.host.addEventListener('mouseenter', this.handleMouseEnter);
|
|
295
352
|
this.host.addEventListener('mousemove', this.handleMouseMove);
|
|
@@ -315,6 +372,11 @@ export class HoverPaneController {
|
|
|
315
372
|
this.host.removeEventListener('touchend', this.handleLongPressCancel);
|
|
316
373
|
this.host.removeEventListener('touchcancel', this.handleLongPressCancel);
|
|
317
374
|
this.host.removeEventListener('contextmenu', this.handleContextMenu);
|
|
375
|
+
// keyboard navigation listeners
|
|
376
|
+
this.host.removeEventListener('focus', this.handleFocus);
|
|
377
|
+
this.host.removeEventListener('blur', this.handleBlur);
|
|
378
|
+
this.host.removeEventListener('keyup', this.handleKeyUp);
|
|
379
|
+
this.host.removeEventListener('keydown', this.handleKeyDown);
|
|
318
380
|
}
|
|
319
381
|
/**
|
|
320
382
|
* Aborts and restarts the timer for showing the hover pane.
|
|
@@ -322,13 +384,16 @@ export class HoverPaneController {
|
|
|
322
384
|
restartShowHoverPaneTimer() {
|
|
323
385
|
clearTimeout(this.showTimer);
|
|
324
386
|
this.showTimer = window.setTimeout(() => {
|
|
387
|
+
this.host.acquireFocus();
|
|
325
388
|
this.showHoverPane();
|
|
326
389
|
}, this.showDelay);
|
|
327
390
|
}
|
|
328
391
|
/**
|
|
329
392
|
* Causes this tile's hover pane to be rendered, positioned, and made visible.
|
|
330
393
|
*/
|
|
331
|
-
async showHoverPane(
|
|
394
|
+
async showHoverPane(options = {
|
|
395
|
+
anchor: 'cursor',
|
|
396
|
+
}) {
|
|
332
397
|
var _a, _b, _c, _d;
|
|
333
398
|
this.hoverPaneState = 'shown';
|
|
334
399
|
this.host.requestUpdate();
|
|
@@ -344,7 +409,7 @@ export class HoverPaneController {
|
|
|
344
409
|
requestAnimationFrame(resolve);
|
|
345
410
|
});
|
|
346
411
|
// Apply the correct positioning to the hover pane
|
|
347
|
-
this.repositionHoverPane();
|
|
412
|
+
this.repositionHoverPane(options.anchor);
|
|
348
413
|
// The hover pane is initially not visible (to avoid it shifting around
|
|
349
414
|
// while being positioned). Since it now has the correct positioning, we
|
|
350
415
|
// can make it visible and begin its fade-in animation.
|
|
@@ -361,16 +426,19 @@ export class HoverPaneController {
|
|
|
361
426
|
clearTimeout(this.hideTimer);
|
|
362
427
|
this.hideTimer = window.setTimeout(() => {
|
|
363
428
|
this.hoverPaneState = 'hidden';
|
|
429
|
+
if (this.hoverPane) {
|
|
430
|
+
this.hoverPane.tabIndex = -1;
|
|
431
|
+
}
|
|
364
432
|
this.host.requestUpdate();
|
|
365
433
|
}, 100);
|
|
366
434
|
}
|
|
367
435
|
/**
|
|
368
436
|
* Positions the hover pane with the correct offsets.
|
|
369
437
|
*/
|
|
370
|
-
repositionHoverPane() {
|
|
438
|
+
repositionHoverPane(anchor) {
|
|
371
439
|
if (!this.hoverPane)
|
|
372
440
|
return;
|
|
373
|
-
const { top, left } = this.
|
|
441
|
+
const { top, left } = this.makePaneDesiredOffsets(anchor);
|
|
374
442
|
this.hoverPane.style.top = `${top}px`;
|
|
375
443
|
this.hoverPane.style.left = `${left}px`;
|
|
376
444
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover-pane-controller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CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { SortParam } from '@internetarchive/search-service';\nimport {\n html,\n HTMLTemplateResult,\n nothing,\n ReactiveController,\n ReactiveControllerHost,\n} from 'lit';\nimport type { TileModel } from '../../models';\nimport type { CollectionTitles } from '../../data-source/models';\n\ntype HoverPaneState = 'hidden' | 'shown' | 'fading-out';\n\nexport interface HoverPaneProperties {\n model?: TileModel;\n baseNavigationUrl?: string;\n baseImageUrl?: string;\n loggedIn: boolean;\n suppressBlurring: boolean;\n sortParam: SortParam | null;\n collectionTitles?: CollectionTitles;\n}\n\nexport interface HoverPaneControllerOptions {\n offsetX?: number;\n offsetY?: number;\n enableLongPress?: boolean;\n showDelay?: number;\n hideDelay?: number;\n longPressDelay?: number;\n mobileBreakpoint?: number;\n}\n\n/** A common interface for providing a hover pane element. */\nexport interface HoverPaneProviderInterface {\n /** Returns the provider's currently rendered hover pane element. */\n getHoverPane(): HTMLElement | undefined;\n /** Returns properties that should be passed to the hover pane. */\n getHoverPaneProps(): HoverPaneProperties;\n}\n\nexport interface ToggleHoverPaneOptions {\n coords: { x: number; y: number };\n enableTouchBackdrop?: boolean;\n}\n\n/**\n * An interface for interacting with hover pane controllers (e.g.,\n * to retrieve their current hover pane template).\n */\nexport interface HoverPaneControllerInterface extends ReactiveController {\n /**\n * Returns the hover pane template to render based on this controller's\n * current state. The returned template may be `nothing` if the hover\n * pane should not currently be rendered.\n */\n getTemplate(): HTMLTemplateResult | typeof nothing;\n\n /**\n * Requests to manually toggle the state of the hover pane.\n * If the hover pane is already shown, it will begin fading out and then\n * subsequently be hidden and removed. If the hover pane is already fading\n * out or hidden, it will fade back in and be shown.\n */\n toggleHoverPane(options: ToggleHoverPaneOptions): void;\n}\n\nconst clamp = (val: number, min = -Infinity, max = Infinity) =>\n Math.max(min, Math.min(val, max));\n\nexport class HoverPaneController implements HoverPaneControllerInterface {\n /**\n * The hover pane element attached to this controller's host.\n */\n private hoverPane?: HTMLElement;\n\n /**\n * The properties to be passed to the hover pane element\n */\n private hoverPaneProps?: HoverPaneProperties;\n\n /**\n * The breakpoint (in pixels) below which the mobile interface should be used.\n */\n private mobileBreakpoint?: number = 600;\n\n /**\n * The number of horizontal pixels the hover pane should be offset from the\n * pointer position.\n */\n private offsetX: number = -10;\n\n /**\n * The number of vertical pixels the hover pane should be offset from the\n * pointer position.\n */\n private offsetY: number = 15;\n\n /**\n * The delay between the mouse idling within the host element and when the hover\n * pane should begin fading in (in milliseconds).\n */\n private showDelay: number = 300;\n\n /**\n * The delay between when the mouse leaves the host element and when the hover\n * pane should begin fading out (in milliseconds).\n */\n private hideDelay: number = 100;\n\n /**\n * The delay between when a touch event begins on the host element and when the\n * hover pane should begin fading in (in milliseconds).\n */\n private longPressDelay: number = 600;\n\n /**\n * Whether long press interactions should cause the hover pane to appear (when\n * below the mobile breakpoint).\n */\n private enableLongPress: boolean = false;\n\n /**\n * Used to control the current state of this provider's hover pane.\n * - `'hidden'` => The hover pane is not present at all.\n * - `'shown'` => The hover pane is either fading in or fully visible.\n * - `'fading-out'` => The hover pane is fading out and about to be removed.\n */\n private hoverPaneState: HoverPaneState = 'hidden';\n\n /** The timer ID for showing the hover pane */\n private showTimer?: number;\n\n /** The timer ID for hiding the hover pane */\n private hideTimer?: number;\n\n /** The timer ID for recognizing a long press event */\n private longPressTimer?: number;\n\n /**\n * Whether the touch backdrop should currently be rendered irrespective of other touch\n * interactions being enabled.\n */\n private forceTouchBackdrop: boolean = false;\n\n /** A record of the last mouse position on the host element, for positioning the hover pane */\n private lastPointerClientPos = { x: 0, y: 0 };\n\n constructor(\n /** The host element to which this controller should attach listeners */\n private readonly host: ReactiveControllerHost &\n HoverPaneProviderInterface &\n HTMLElement,\n /** Options for adjusting the hover pane behavior (offsets, delays, etc.) */\n options: HoverPaneControllerOptions = {},\n ) {\n this.mobileBreakpoint = options.mobileBreakpoint ?? this.mobileBreakpoint;\n this.offsetX = options.offsetX ?? this.offsetX;\n this.offsetY = options.offsetY ?? this.offsetY;\n this.showDelay = options.showDelay ?? this.showDelay;\n this.hideDelay = options.hideDelay ?? this.hideDelay;\n this.longPressDelay = options.longPressDelay ?? this.longPressDelay;\n this.enableLongPress = options.enableLongPress ?? this.enableLongPress;\n\n this.host.addController(this);\n }\n\n hostConnected(): void {\n this.attachListeners();\n }\n\n hostDisconnected(): void {\n this.detachListeners();\n }\n\n hostUpdated(): void {\n this.hoverPane = this.host.getHoverPane();\n this.hoverPaneProps = this.host.getHoverPaneProps();\n }\n\n /** @inheritdoc */\n getTemplate(): HTMLTemplateResult | typeof nothing {\n this.hoverPaneProps = this.host.getHoverPaneProps();\n\n return this.shouldRenderHoverPane\n ? html` ${this.touchBackdropTemplate}\n <tile-hover-pane\n popover\n .model=${this.hoverPaneProps?.model}\n .baseNavigationUrl=${this.hoverPaneProps?.baseNavigationUrl}\n .baseImageUrl=${this.hoverPaneProps?.baseImageUrl}\n .loggedIn=${this.hoverPaneProps?.loggedIn}\n .suppressBlurring=${this.hoverPaneProps?.suppressBlurring}\n .sortParam=${this.hoverPaneProps?.sortParam}\n .collectionTitles=${this.hoverPaneProps?.collectionTitles}\n .mobileBreakpoint=${this.mobileBreakpoint}\n .currentWidth=${window.innerWidth}\n ></tile-hover-pane>`\n : nothing;\n }\n\n /** @inheritdoc */\n toggleHoverPane(options: ToggleHoverPaneOptions): void {\n if (this.hoverPaneState === 'shown') {\n this.fadeOutHoverPane();\n this.forceTouchBackdrop = false;\n } else {\n this.lastPointerClientPos = options.coords;\n this.forceTouchBackdrop = options.enableTouchBackdrop ?? false;\n this.showHoverPane();\n }\n }\n\n /**\n * Produces a template for the invisible touch capture backdrop that\n * is used to cancel the hover pane on touch devices. We want any\n * touch interaction on the backdrop to remove the hover pane, and\n * we don't want to bubble up mouse events that would otherwise\n * affect the state of the hover pane (e.g., fading it back in).\n */\n private get touchBackdropTemplate(): HTMLTemplateResult | typeof nothing {\n return this.showTouchBackdrop\n ? html`<div\n id=\"touch-backdrop\"\n @touchstart=${this.handleBackdropInteraction}\n @touchmove=${this.handleBackdropInteraction}\n @touchend=${this.handleBackdropInteraction}\n @touchcancel=${this.handleBackdropInteraction}\n @mouseenter=${(e: MouseEvent) => e.stopPropagation()}\n @mousemove=${(e: MouseEvent) => e.stopPropagation()}\n @mouseleave=${(e: MouseEvent) => e.stopPropagation()}\n ></div>`\n : nothing;\n }\n\n private get showTouchBackdrop(): boolean {\n return (\n (this.isTouchEnabled && this.enableLongPress) || this.forceTouchBackdrop\n );\n }\n\n /** Whether to use the mobile layout */\n private get isMobileView(): boolean {\n return !!this.mobileBreakpoint && window.innerWidth < this.mobileBreakpoint;\n }\n\n private get isHoverEnabled(): boolean {\n return window.matchMedia('(hover: hover)').matches;\n }\n\n private get isTouchEnabled(): boolean {\n return (\n 'ontouchstart' in window &&\n window.matchMedia('(any-pointer: coarse)').matches\n );\n }\n\n /** Whether this controller should currently render its hover pane. */\n private get shouldRenderHoverPane(): boolean {\n return this.hoverPaneState !== 'hidden';\n }\n\n /**\n * Returns the desired top/left offsets (in pixels) for this tile's hover pane.\n * The desired offsets balance positioning the hover pane under the primary pointer\n * while preventing it from flowing outside the viewport. The returned offsets are\n * relative to the viewport, intended to position the pane as a popover element.\n *\n * These offsets are only valid if the hover pane is already rendered with its\n * correct width and height. If the hover pane is not present, the returned offsets\n * will simply represent the current pointer position.\n */\n private get hoverPaneDesiredOffsets(): { top: number; left: number } {\n // Try to find offsets for the hover pane that:\n // (a) cause it to lie entirely within the viewport, and\n // (b) to the extent possible, minimize the distance between the\n // nearest corner of the hover pane and the mouse position\n // (with some additional offsets applied after the fact).\n\n let [left, top] = [\n this.lastPointerClientPos.x,\n this.lastPointerClientPos.y,\n ];\n\n // Flip the hover pane according to which quadrant of the viewport the mouse is in.\n // (Similar to how Wikipedia's link hover panes work)\n const flipHorizontal = this.lastPointerClientPos.x > window.innerWidth / 2;\n const flipVertical = this.lastPointerClientPos.y > window.innerHeight / 2;\n\n const hoverPaneRect = this.hoverPane?.getBoundingClientRect();\n if (hoverPaneRect) {\n // If we need to flip the hover pane, do so by subtracting its width/height from left/top\n if (flipHorizontal) {\n left -= hoverPaneRect.width;\n }\n if (flipVertical) {\n top -= hoverPaneRect.height;\n }\n\n // Apply desired offsets from the mouse position\n left += (flipHorizontal ? -1 : 1) * this.offsetX;\n top += (flipVertical ? -1 : 1) * this.offsetY;\n\n // On mobile view, shunt the hover pane to avoid overflowing the viewport\n if (this.isMobileView) {\n left = clamp(left, 20, window.innerWidth - hoverPaneRect.width - 20);\n top = clamp(top, 20, window.innerHeight - hoverPaneRect.height - 20);\n }\n }\n\n left += window.scrollX;\n top += window.scrollY;\n\n return { left, top };\n }\n\n /**\n * Adds to the host element all the listeners necessary to make the\n * hover pane functional.\n */\n private attachListeners(): void {\n if (this.isHoverEnabled) {\n this.host.addEventListener('mouseenter', this.handleMouseEnter);\n this.host.addEventListener('mousemove', this.handleMouseMove);\n this.host.addEventListener('mouseleave', this.handleMouseLeave);\n }\n\n if (this.isTouchEnabled && this.enableLongPress) {\n this.host.addEventListener('touchstart', this.handleTouchStart);\n this.host.addEventListener('touchmove', this.handleLongPressCancel);\n this.host.addEventListener('touchend', this.handleLongPressCancel);\n this.host.addEventListener('touchcancel', this.handleLongPressCancel);\n this.host.addEventListener('contextmenu', this.handleContextMenu);\n }\n }\n\n /**\n * Removes all the hover pane listeners from the host element.\n */\n private detachListeners(): void {\n this.host.removeEventListener('mouseenter', this.handleMouseEnter);\n this.host.removeEventListener('mousemove', this.handleMouseMove);\n this.host.removeEventListener('mouseleave', this.handleMouseLeave);\n this.host.removeEventListener('touchstart', this.handleTouchStart);\n this.host.removeEventListener('touchmove', this.handleLongPressCancel);\n this.host.removeEventListener('touchend', this.handleLongPressCancel);\n this.host.removeEventListener('touchcancel', this.handleLongPressCancel);\n this.host.removeEventListener('contextmenu', this.handleContextMenu);\n }\n\n /**\n * Handler for the mouseenter event on the host element.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleMouseEnter = (e: MouseEvent): void => {\n // Delegate to the mousemove handler, as they are currently processed identically\n this.handleMouseMove(e);\n };\n\n /**\n * Handler for the mousemove event on the host element.\n * Aborts any pending hide/fade-out for the hover pane, and restarts the\n * timer to show it.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleMouseMove = (e: MouseEvent): void => {\n // The mouse is within the tile, so abort any pending removal of the hover pane\n clearTimeout(this.hideTimer);\n\n // If the hover pane is currently fading out, just make it fade back in where it is\n if (this.hoverPaneState === 'fading-out') {\n this.hoverPaneState = 'shown';\n this.hoverPane?.classList.add('fade-in');\n }\n\n // Restart the timer to show the hover pane anytime the mouse moves within the tile\n if (this.hoverPaneState === 'hidden') {\n this.restartShowHoverPaneTimer();\n this.lastPointerClientPos = { x: e.clientX, y: e.clientY };\n }\n };\n\n /**\n * Handler for the mouseleave event on the host element.\n * Hides the hover pane if present, and aborts the timer for showing it.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleMouseLeave = (): void => {\n // Abort any timer to show the hover pane, as the mouse has left the tile\n clearTimeout(this.showTimer);\n\n // Hide the hover pane if it's already been shown\n clearTimeout(this.hideTimer);\n if (this.hoverPaneState !== 'hidden') {\n this.hideTimer = window.setTimeout(() => {\n this.fadeOutHoverPane();\n }, this.hideDelay);\n }\n };\n\n /**\n * Handler for the touchstart event on the host element.\n * Begins the timer for recognizing a long press event.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleTouchStart = (e: TouchEvent): void => {\n clearTimeout(this.longPressTimer);\n\n if (e.touches.length === 1) {\n this.longPressTimer = window.setTimeout(() => {\n if (this.hoverPaneState === 'hidden') {\n this.showHoverPane();\n }\n }, this.longPressDelay);\n\n this.lastPointerClientPos = {\n x: e.touches[0].clientX,\n y: e.touches[0].clientY,\n };\n }\n };\n\n /**\n * Handler for events that should cancel a pending long press event\n * (touchmove, touchend, touchcancel). Aborts the timer for recognizing\n * a long press.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleLongPressCancel = (): void => {\n clearTimeout(this.longPressTimer);\n };\n\n /**\n * Handler for the contextmenu event, which should be suppressed during\n * mobile long-press events on the host element.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleContextMenu = (e: Event): void => {\n e.preventDefault();\n };\n\n /**\n * Immediately causes the hover pane to begin fading out, if it is present.\n */\n // NB: Arrow function so 'this' remains bound to the controller\n private handleBackdropInteraction = (e: Event): void => {\n if (this.hoverPaneState !== 'hidden') {\n this.fadeOutHoverPane();\n }\n e.stopPropagation();\n };\n\n /**\n * Aborts and restarts the timer for showing the hover pane.\n */\n private restartShowHoverPaneTimer(): void {\n clearTimeout(this.showTimer);\n this.showTimer = window.setTimeout(() => {\n this.showHoverPane();\n }, this.showDelay);\n }\n\n /**\n * Causes this tile's hover pane to be rendered, positioned, and made visible.\n */\n private async showHoverPane(): Promise<void> {\n this.hoverPaneState = 'shown';\n this.host.requestUpdate();\n\n // Wait for the state update to render the hover pane\n await this.host.updateComplete;\n\n // Ensure the hover pane element is still in the document before showing,\n // as it might have been removed by the previous update.\n if (!this.hoverPane?.isConnected) return;\n\n this.hoverPane?.showPopover?.();\n await new Promise(resolve => {\n // Pane sizes aren't accurate until next frame\n requestAnimationFrame(resolve);\n });\n\n // Apply the correct positioning to the hover pane\n this.repositionHoverPane();\n\n // The hover pane is initially not visible (to avoid it shifting around\n // while being positioned). Since it now has the correct positioning, we\n // can make it visible and begin its fade-in animation.\n this.hoverPane?.classList.add('visible', 'fade-in');\n }\n\n /**\n * Causes this tile's hover pane to begin fading out and starts\n * the timer for it to be removed.\n */\n private fadeOutHoverPane(): void {\n this.hoverPaneState = 'fading-out';\n this.hoverPane?.classList.remove('fade-in');\n\n clearTimeout(this.hideTimer);\n this.hideTimer = window.setTimeout(() => {\n this.hoverPaneState = 'hidden';\n this.host.requestUpdate();\n }, 100);\n }\n\n /**\n * Positions the hover pane with the correct offsets.\n */\n private repositionHoverPane(): void {\n if (!this.hoverPane) return;\n\n const { top, left } = this.hoverPaneDesiredOffsets;\n this.hoverPane.style.top = `${top}px`;\n this.hoverPane.style.left = `${left}px`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hover-pane-controller.js","sourceRoot":"","sources":["../../../../src/tiles/hover/hover-pane-controller.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EAEJ,OAAO,GAGR,MAAM,KAAK,CAAC;AAGb,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAoEpC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,GAAG,QAAQ,EAAE,EAAE,CAC7D,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEpC,MAAM,OAAO,mBAAmB;IA8E9B;IACE,wEAAwE;IACvD,IAEJ;IACb,4EAA4E;IAC5E,UAAsC,EAAE;;QAJvB,SAAI,GAAJ,IAAI,CAER;QAvEf;;WAEG;QACK,qBAAgB,GAAY,GAAG,CAAC;QAExC;;;WAGG;QACK,YAAO,GAAW,CAAC,EAAE,CAAC;QAE9B;;;WAGG;QACK,YAAO,GAAW,EAAE,CAAC;QAE7B;;;WAGG;QACK,cAAS,GAAW,GAAG,CAAC;QAEhC;;;WAGG;QACK,cAAS,GAAW,GAAG,CAAC;QAEhC;;;WAGG;QACK,mBAAc,GAAW,GAAG,CAAC;QAErC;;;WAGG;QACK,oBAAe,GAAY,KAAK,CAAC;QAEzC;;;;;WAKG;QACK,mBAAc,GAAmB,QAAQ,CAAC;QAWlD;;;WAGG;QACK,uBAAkB,GAAY,KAAK,CAAC;QAE5C,8FAA8F;QACtF,yBAAoB,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QA2OtC,gBAAW,GAAG,GAAS,EAAE;YAC/B,IAAI,IAAI,CAAC,cAAc,KAAK,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,aAAa,CAAC;oBACjB,M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,CAAC;IAED;;OAEG;IACK,mBAAmB,CAAC,MAA+B;QACzD,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAE1D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;QACtC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { SortParam } from '@internetarchive/search-service';\r\nimport {\r\n html,\r\n HTMLTemplateResult,\r\n nothing,\r\n ReactiveController,\r\n ReactiveControllerHost,\r\n} from 'lit';\r\nimport type { TileModel } from '../../models';\r\nimport type { CollectionTitles } from '../../data-source/models';\r\nimport { msg } from '@lit/localize';\r\n\r\ntype HoverPaneState = 'hidden' | 'shown' | 'fading-out';\r\n\r\n// the anchor point of the hover pane\r\n// can be either the mouse cursor or near the host element\r\n// in the case of mouse navigation, we want it to follow the cursor\r\n// in the case of keyboard navigation, we want it to appear near the host element\r\ntype HoverPanePositionAnchor = 'host' | 'cursor';\r\n\r\nexport interface HoverPaneProperties {\r\n model?: TileModel;\r\n baseNavigationUrl?: string;\r\n baseImageUrl?: string;\r\n loggedIn: boolean;\r\n suppressBlurring: boolean;\r\n sortParam: SortParam | null;\r\n collectionTitles?: CollectionTitles;\r\n}\r\n\r\nexport interface HoverPaneControllerOptions {\r\n offsetX?: number;\r\n offsetY?: number;\r\n enableLongPress?: boolean;\r\n showDelay?: number;\r\n hideDelay?: number;\r\n longPressDelay?: number;\r\n mobileBreakpoint?: number;\r\n}\r\n\r\n/** A common interface for providing a hover pane element. */\r\nexport interface HoverPaneProviderInterface {\r\n /** Returns the provider's currently rendered hover pane element. */\r\n getHoverPane(): HTMLElement | undefined;\r\n /** Returns properties that should be passed to the hover pane. */\r\n getHoverPaneProps(): HoverPaneProperties;\r\n /** When user has keyboard navigated out of more info, we want the host to get focus */\r\n acquireFocus(): void;\r\n /** When user has keyboard navigated out of more info, we want the host to lose focus */\r\n releaseFocus(): void;\r\n}\r\n\r\nexport interface ToggleHoverPaneOptions {\r\n coords: { x: number; y: number };\r\n enableTouchBackdrop?: boolean;\r\n}\r\n\r\n/**\r\n * An interface for interacting with hover pane controllers (e.g.,\r\n * to retrieve their current hover pane template).\r\n */\r\nexport interface HoverPaneControllerInterface extends ReactiveController {\r\n /**\r\n * Returns the hover pane template to render based on this controller's\r\n * current state. The returned template may be `nothing` if the hover\r\n * pane should not currently be rendered.\r\n */\r\n getTemplate(): HTMLTemplateResult | typeof nothing;\r\n\r\n /**\r\n * Requests to manually toggle the state of the hover pane.\r\n * If the hover pane is already shown, it will begin fading out and then\r\n * subsequently be hidden and removed. If the hover pane is already fading\r\n * out or hidden, it will fade back in and be shown.\r\n */\r\n toggleHoverPane(options: ToggleHoverPaneOptions): void;\r\n}\r\n\r\nconst clamp = (val: number, min = -Infinity, max = Infinity) =>\r\n Math.max(min, Math.min(val, max));\r\n\r\nexport class HoverPaneController implements HoverPaneControllerInterface {\r\n /**\r\n * The hover pane element attached to this controller's host.\r\n */\r\n private hoverPane?: HTMLElement;\r\n\r\n /**\r\n * The properties to be passed to the hover pane element\r\n */\r\n private hoverPaneProps?: HoverPaneProperties;\r\n\r\n /**\r\n * The breakpoint (in pixels) below which the mobile interface should be used.\r\n */\r\n private mobileBreakpoint?: number = 600;\r\n\r\n /**\r\n * The number of horizontal pixels the hover pane should be offset from the\r\n * pointer position.\r\n */\r\n private offsetX: number = -10;\r\n\r\n /**\r\n * The number of vertical pixels the hover pane should be offset from the\r\n * pointer position.\r\n */\r\n private offsetY: number = 15;\r\n\r\n /**\r\n * The delay between the mouse idling within the host element and when the hover\r\n * pane should begin fading in (in milliseconds).\r\n */\r\n private showDelay: number = 300;\r\n\r\n /**\r\n * The delay between when the mouse leaves the host element and when the hover\r\n * pane should begin fading out (in milliseconds).\r\n */\r\n private hideDelay: number = 100;\r\n\r\n /**\r\n * The delay between when a touch event begins on the host element and when the\r\n * hover pane should begin fading in (in milliseconds).\r\n */\r\n private longPressDelay: number = 600;\r\n\r\n /**\r\n * Whether long press interactions should cause the hover pane to appear (when\r\n * below the mobile breakpoint).\r\n */\r\n private enableLongPress: boolean = false;\r\n\r\n /**\r\n * Used to control the current state of this provider's hover pane.\r\n * - `'hidden'` => The hover pane is not present at all.\r\n * - `'shown'` => The hover pane is either fading in or fully visible.\r\n * - `'fading-out'` => The hover pane is fading out and about to be removed.\r\n */\r\n private hoverPaneState: HoverPaneState = 'hidden';\r\n\r\n /** The timer ID for showing the hover pane */\r\n private showTimer?: number;\r\n\r\n /** The timer ID for hiding the hover pane */\r\n private hideTimer?: number;\r\n\r\n /** The timer ID for recognizing a long press event */\r\n private longPressTimer?: number;\r\n\r\n /**\r\n * Whether the touch backdrop should currently be rendered irrespective of other touch\r\n * interactions being enabled.\r\n */\r\n private forceTouchBackdrop: boolean = false;\r\n\r\n /** A record of the last mouse position on the host element, for positioning the hover pane */\r\n private lastPointerClientPos = { x: 0, y: 0 };\r\n\r\n constructor(\r\n /** The host element to which this controller should attach listeners */\r\n private readonly host: ReactiveControllerHost &\r\n HoverPaneProviderInterface &\r\n HTMLElement,\r\n /** Options for adjusting the hover pane behavior (offsets, delays, etc.) */\r\n options: HoverPaneControllerOptions = {},\r\n ) {\r\n this.mobileBreakpoint = options.mobileBreakpoint ?? this.mobileBreakpoint;\r\n this.offsetX = options.offsetX ?? this.offsetX;\r\n this.offsetY = options.offsetY ?? this.offsetY;\r\n this.showDelay = options.showDelay ?? this.showDelay;\r\n this.hideDelay = options.hideDelay ?? this.hideDelay;\r\n this.longPressDelay = options.longPressDelay ?? this.longPressDelay;\r\n this.enableLongPress = options.enableLongPress ?? this.enableLongPress;\r\n\r\n this.host.addController(this);\r\n }\r\n\r\n hostConnected(): void {\r\n this.attachListeners();\r\n }\r\n\r\n hostDisconnected(): void {\r\n this.detachListeners();\r\n }\r\n\r\n hostUpdated(): void {\r\n this.hoverPane = this.host.getHoverPane();\r\n this.hoverPaneProps = this.host.getHoverPaneProps();\r\n }\r\n\r\n /** @inheritdoc */\r\n getTemplate(): HTMLTemplateResult | typeof nothing {\r\n this.hoverPaneProps = this.host.getHoverPaneProps();\r\n\r\n return this.shouldRenderHoverPane\r\n ? html`\r\n ${this.touchBackdropTemplate}\r\n <tile-hover-pane\r\n popover\r\n tabindex=\"-1\"\r\n aria-describedby=\"tile-hover-pane-aria-description\"\r\n .model=${this.hoverPaneProps?.model}\r\n .baseNavigationUrl=${this.hoverPaneProps?.baseNavigationUrl}\r\n .baseImageUrl=${this.hoverPaneProps?.baseImageUrl}\r\n .loggedIn=${this.hoverPaneProps?.loggedIn}\r\n .suppressBlurring=${this.hoverPaneProps?.suppressBlurring}\r\n .sortParam=${this.hoverPaneProps?.sortParam}\r\n .collectionTitles=${this.hoverPaneProps?.collectionTitles}\r\n .mobileBreakpoint=${this.mobileBreakpoint}\r\n .currentWidth=${window.innerWidth}\r\n ></tile-hover-pane>\r\n <div id=\"tile-hover-pane-aria-description\" class=\"sr-only\">\r\n ${msg('Press Up Arrow to exit item detail preview')}\r\n </div>\r\n `\r\n : nothing;\r\n }\r\n\r\n /** @inheritdoc */\r\n toggleHoverPane(options: ToggleHoverPaneOptions): void {\r\n if (this.hoverPaneState === 'shown') {\r\n this.fadeOutHoverPane();\r\n this.forceTouchBackdrop = false;\r\n } else {\r\n this.lastPointerClientPos = options.coords;\r\n this.forceTouchBackdrop = options.enableTouchBackdrop ?? false;\r\n this.showHoverPane();\r\n }\r\n }\r\n\r\n /**\r\n * Produces a template for the invisible touch capture backdrop that\r\n * is used to cancel the hover pane on touch devices. We want any\r\n * touch interaction on the backdrop to remove the hover pane, and\r\n * we don't want to bubble up mouse events that would otherwise\r\n * affect the state of the hover pane (e.g., fading it back in).\r\n */\r\n private get touchBackdropTemplate(): HTMLTemplateResult | typeof nothing {\r\n return this.showTouchBackdrop\r\n ? html`<div\r\n id=\"touch-backdrop\"\r\n @touchstart=${this.handleBackdropInteraction}\r\n @touchmove=${this.handleBackdropInteraction}\r\n @touchend=${this.handleBackdropInteraction}\r\n @touchcancel=${this.handleBackdropInteraction}\r\n @mouseenter=${(e: MouseEvent) => e.stopPropagation()}\r\n @mousemove=${(e: MouseEvent) => e.stopPropagation()}\r\n @mouseleave=${(e: MouseEvent) => e.stopPropagation()}\r\n ></div>`\r\n : nothing;\r\n }\r\n\r\n private get showTouchBackdrop(): boolean {\r\n return (\r\n (this.isTouchEnabled && this.enableLongPress) || this.forceTouchBackdrop\r\n );\r\n }\r\n\r\n /** Whether to use the mobile layout */\r\n private get isMobileView(): boolean {\r\n return !!this.mobileBreakpoint && window.innerWidth < this.mobileBreakpoint;\r\n }\r\n\r\n private get isHoverEnabled(): boolean {\r\n return window.matchMedia('(hover: hover)').matches;\r\n }\r\n\r\n private get isTouchEnabled(): boolean {\r\n return (\r\n 'ontouchstart' in window &&\r\n window.matchMedia('(any-pointer: coarse)').matches\r\n );\r\n }\r\n\r\n /** Whether this controller should currently render its hover pane. */\r\n private get shouldRenderHoverPane(): boolean {\r\n return this.hoverPaneState !== 'hidden';\r\n }\r\n\r\n /**\r\n * Returns the desired top/left offsets (in pixels) for this tile's hover pane.\r\n * The desired offsets balance positioning the hover pane under the primary pointer\r\n * while preventing it from flowing outside the viewport. The returned offsets are\r\n * relative to the viewport, intended to position the pane as a popover element.\r\n *\r\n * These offsets are only valid if the hover pane is already rendered with its\r\n * correct width and height. If the hover pane is not present, the returned offsets\r\n * will simply represent the current pointer position.\r\n */\r\n private makePaneDesiredOffsets(anchor: HoverPanePositionAnchor): {\r\n top: number;\r\n left: number;\r\n } {\r\n // Try to find offsets for the hover pane that:\r\n // (a) cause it to lie entirely within the viewport, and\r\n // (b) to the extent possible, minimize the distance between the\r\n // nearest corner of the hover pane and the mouse/host element position\r\n // (with some additional offsets applied after the fact).\r\n\r\n let [left, top] = [0, 0];\r\n switch (anchor) {\r\n case 'host':\r\n const hostRect = this.host.getBoundingClientRect();\r\n // slight inset from host top left corner\r\n left = hostRect.left + 20;\r\n top = hostRect.top + 30;\r\n break;\r\n case 'cursor':\r\n left = this.lastPointerClientPos.x;\r\n top = this.lastPointerClientPos.y;\r\n break;\r\n }\r\n\r\n // Flip the hover pane according to which quadrant of the viewport the coordinates are in.\r\n // (Similar to how Wikipedia's link hover panes work)\r\n const flipHorizontal = left > window.innerWidth / 2;\r\n const flipVertical = top > window.innerHeight / 2;\r\n\r\n const hoverPaneRect = this.hoverPane?.getBoundingClientRect();\r\n if (hoverPaneRect) {\r\n // If we need to flip the hover pane, do so by subtracting its width/height from left/top\r\n if (flipHorizontal) {\r\n left -= hoverPaneRect.width;\r\n }\r\n if (flipVertical) {\r\n top -= hoverPaneRect.height;\r\n }\r\n\r\n // Apply desired offsets from the target position\r\n left += (flipHorizontal ? -1 : 1) * this.offsetX;\r\n top += (flipVertical ? -1 : 1) * this.offsetY;\r\n\r\n // On mobile view, shunt the hover pane to avoid overflowing the viewport\r\n if (this.isMobileView) {\r\n left = clamp(left, 20, window.innerWidth - hoverPaneRect.width - 20);\r\n top = clamp(top, 20, window.innerHeight - hoverPaneRect.height - 20);\r\n }\r\n }\r\n\r\n left += window.scrollX;\r\n top += window.scrollY;\r\n\r\n return { left, top };\r\n }\r\n\r\n /**\r\n * Adds to the host element all the listeners necessary to make the\r\n * hover pane functional.\r\n */\r\n private attachListeners(): void {\r\n // keyboard navigation listeners\r\n this.host.addEventListener('focus', this.handleFocus);\r\n this.host.addEventListener('blur', this.handleBlur);\r\n this.host.addEventListener('keyup', this.handleKeyUp);\r\n this.host.addEventListener('keydown', this.handleKeyDown);\r\n\r\n if (this.isHoverEnabled) {\r\n this.host.addEventListener('mouseenter', this.handleMouseEnter);\r\n this.host.addEventListener('mousemove', this.handleMouseMove);\r\n this.host.addEventListener('mouseleave', this.handleMouseLeave);\r\n }\r\n\r\n if (this.isTouchEnabled && this.enableLongPress) {\r\n this.host.addEventListener('touchstart', this.handleTouchStart);\r\n this.host.addEventListener('touchmove', this.handleLongPressCancel);\r\n this.host.addEventListener('touchend', this.handleLongPressCancel);\r\n this.host.addEventListener('touchcancel', this.handleLongPressCancel);\r\n this.host.addEventListener('contextmenu', this.handleContextMenu);\r\n }\r\n }\r\n\r\n /**\r\n * Removes all the hover pane listeners from the host element.\r\n */\r\n private detachListeners(): void {\r\n this.host.removeEventListener('mouseenter', this.handleMouseEnter);\r\n this.host.removeEventListener('mousemove', this.handleMouseMove);\r\n this.host.removeEventListener('mouseleave', this.handleMouseLeave);\r\n this.host.removeEventListener('touchstart', this.handleTouchStart);\r\n this.host.removeEventListener('touchmove', this.handleLongPressCancel);\r\n this.host.removeEventListener('touchend', this.handleLongPressCancel);\r\n this.host.removeEventListener('touchcancel', this.handleLongPressCancel);\r\n this.host.removeEventListener('contextmenu', this.handleContextMenu);\r\n\r\n // keyboard navigation listeners\r\n this.host.removeEventListener('focus', this.handleFocus);\r\n this.host.removeEventListener('blur', this.handleBlur);\r\n this.host.removeEventListener('keyup', this.handleKeyUp);\r\n this.host.removeEventListener('keydown', this.handleKeyDown);\r\n }\r\n\r\n private handleFocus = (): void => {\r\n if (this.hoverPaneState === 'hidden') {\r\n this.showHoverPane({\r\n anchor: 'host',\r\n });\r\n }\r\n };\r\n\r\n private handleBlur = (): void => {\r\n if (this.hoverPaneState !== 'hidden') {\r\n this.fadeOutHoverPane();\r\n }\r\n };\r\n\r\n private handleKeyDown = (e: KeyboardEvent): void => {\r\n if (\r\n (e.key === 'ArrowDown' || e.key === 'ArrowUp') &&\r\n this.hoverPaneState !== 'hidden'\r\n ) {\r\n e.preventDefault();\r\n }\r\n };\r\n\r\n private handleKeyUp = (e: KeyboardEvent): void => {\r\n if (this.hoverPaneState === 'hidden' || !this.hoverPane) return;\r\n if (e.key === 'ArrowDown') {\r\n this.hoverPane.tabIndex = 1;\r\n this.hoverPane.focus();\r\n }\r\n\r\n const isArrowUp = e.key === 'ArrowUp';\r\n const isEscape = e.key === 'Escape' || e.key === 'Esc';\r\n\r\n if (isEscape) {\r\n this.fadeOutHoverPane();\r\n }\r\n if (isArrowUp || isEscape) {\r\n this.hoverPane.tabIndex = -1;\r\n this.host.acquireFocus();\r\n }\r\n };\r\n\r\n /**\r\n * Handler for the mouseenter event on the host element.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleMouseEnter = (e: MouseEvent): void => {\r\n // Delegate to the mousemove handler, as they are currently processed identically\r\n this.handleMouseMove(e);\r\n };\r\n\r\n /**\r\n * Handler for the mousemove event on the host element.\r\n * Aborts any pending hide/fade-out for the hover pane, and restarts the\r\n * timer to show it.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleMouseMove = (e: MouseEvent): void => {\r\n // The mouse is within the tile, so abort any pending removal of the hover pane\r\n clearTimeout(this.hideTimer);\r\n\r\n // If the hover pane is currently fading out, just make it fade back in where it is\r\n if (this.hoverPaneState === 'fading-out') {\r\n this.hoverPaneState = 'shown';\r\n this.hoverPane?.classList.add('fade-in');\r\n }\r\n\r\n // Restart the timer to show the hover pane anytime the mouse moves within the tile\r\n if (this.hoverPaneState === 'hidden') {\r\n this.restartShowHoverPaneTimer();\r\n this.lastPointerClientPos = { x: e.clientX, y: e.clientY };\r\n }\r\n };\r\n\r\n /**\r\n * Handler for the mouseleave event on the host element.\r\n * Hides the hover pane if present, and aborts the timer for showing it.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleMouseLeave = (): void => {\r\n this.host.releaseFocus();\r\n\r\n // Abort any timer to show the hover pane, as the mouse has left the tile\r\n clearTimeout(this.showTimer);\r\n\r\n // Hide the hover pane if it's already been shown\r\n if (this.hoverPaneState !== 'hidden') {\r\n this.hideTimer = window.setTimeout(() => {\r\n this.fadeOutHoverPane();\r\n }, this.hideDelay);\r\n }\r\n };\r\n\r\n /**\r\n * Handler for the touchstart event on the host element.\r\n * Begins the timer for recognizing a long press event.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleTouchStart = (e: TouchEvent): void => {\r\n clearTimeout(this.longPressTimer);\r\n\r\n if (e.touches.length === 1) {\r\n this.longPressTimer = window.setTimeout(() => {\r\n if (this.hoverPaneState === 'hidden') {\r\n this.showHoverPane();\r\n }\r\n }, this.longPressDelay);\r\n\r\n this.lastPointerClientPos = {\r\n x: e.touches[0].clientX,\r\n y: e.touches[0].clientY,\r\n };\r\n }\r\n };\r\n\r\n /**\r\n * Handler for events that should cancel a pending long press event\r\n * (touchmove, touchend, touchcancel). Aborts the timer for recognizing\r\n * a long press.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleLongPressCancel = (): void => {\r\n clearTimeout(this.longPressTimer);\r\n };\r\n\r\n /**\r\n * Handler for the contextmenu event, which should be suppressed during\r\n * mobile long-press events on the host element.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleContextMenu = (e: Event): void => {\r\n e.preventDefault();\r\n };\r\n\r\n /**\r\n * Immediately causes the hover pane to begin fading out, if it is present.\r\n */\r\n // NB: Arrow function so 'this' remains bound to the controller\r\n private handleBackdropInteraction = (e: Event): void => {\r\n if (this.hoverPaneState !== 'hidden') {\r\n this.fadeOutHoverPane();\r\n }\r\n e.stopPropagation();\r\n };\r\n\r\n /**\r\n * Aborts and restarts the timer for showing the hover pane.\r\n */\r\n private restartShowHoverPaneTimer(): void {\r\n clearTimeout(this.showTimer);\r\n this.showTimer = window.setTimeout(() => {\r\n this.host.acquireFocus();\r\n this.showHoverPane();\r\n }, this.showDelay);\r\n }\r\n\r\n /**\r\n * Causes this tile's hover pane to be rendered, positioned, and made visible.\r\n */\r\n private async showHoverPane(\r\n options: {\r\n anchor: HoverPanePositionAnchor;\r\n } = {\r\n anchor: 'cursor',\r\n },\r\n ): Promise<void> {\r\n this.hoverPaneState = 'shown';\r\n this.host.requestUpdate();\r\n\r\n // Wait for the state update to render the hover pane\r\n await this.host.updateComplete;\r\n\r\n // Ensure the hover pane element is still in the document before showing,\r\n // as it might have been removed by the previous update.\r\n if (!this.hoverPane?.isConnected) return;\r\n\r\n this.hoverPane?.showPopover?.();\r\n await new Promise(resolve => {\r\n // Pane sizes aren't accurate until next frame\r\n requestAnimationFrame(resolve);\r\n });\r\n\r\n // Apply the correct positioning to the hover pane\r\n this.repositionHoverPane(options.anchor);\r\n\r\n // The hover pane is initially not visible (to avoid it shifting around\r\n // while being positioned). Since it now has the correct positioning, we\r\n // can make it visible and begin its fade-in animation.\r\n this.hoverPane?.classList.add('visible', 'fade-in');\r\n }\r\n\r\n /**\r\n * Causes this tile's hover pane to begin fading out and starts\r\n * the timer for it to be removed.\r\n */\r\n private fadeOutHoverPane(): void {\r\n this.hoverPaneState = 'fading-out';\r\n this.hoverPane?.classList.remove('fade-in');\r\n\r\n clearTimeout(this.hideTimer);\r\n this.hideTimer = window.setTimeout(() => {\r\n this.hoverPaneState = 'hidden';\r\n if (this.hoverPane) {\r\n this.hoverPane.tabIndex = -1;\r\n }\r\n this.host.requestUpdate();\r\n }, 100);\r\n }\r\n\r\n /**\r\n * Positions the hover pane with the correct offsets.\r\n */\r\n private repositionHoverPane(anchor: HoverPanePositionAnchor): void {\r\n if (!this.hoverPane) return;\r\n\r\n const { top, left } = this.makePaneDesiredOffsets(anchor);\r\n\r\n this.hoverPane.style.top = `${top}px`;\r\n this.hoverPane.style.left = `${left}px`;\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SortParam } from '@internetarchive/search-service';
|
|
2
2
|
import { CSSResultGroup, LitElement, TemplateResult } from 'lit';
|
|
3
|
+
import '@a11y/focus-trap';
|
|
3
4
|
import { type TileModel } from '../../models';
|
|
4
5
|
import type { CollectionTitles } from '../../data-source/models';
|
|
5
6
|
import '../list/tile-list';
|