@internetarchive/ia-item-navigator 0.0.0-a10 → 0.0.0-a12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/demo/app-root.ts +6 -4
  2. package/dist/demo/app-root.d.ts +0 -1
  3. package/dist/demo/app-root.js +1 -3
  4. package/dist/demo/app-root.js.map +1 -1
  5. package/dist/src/interfaces/nav-controller-interface.d.ts +9 -0
  6. package/dist/src/interfaces/nav-controller-interface.js.map +1 -1
  7. package/dist/src/item-inspector/item-inspector.d.ts +0 -47
  8. package/dist/src/item-inspector/item-inspector.js +253 -271
  9. package/dist/src/item-inspector/item-inspector.js.map +1 -1
  10. package/dist/src/item-navigator.d.ts +14 -7
  11. package/dist/src/item-navigator.js +60 -30
  12. package/dist/src/item-navigator.js.map +1 -1
  13. package/dist/src/no-theater-available.d.ts +9 -0
  14. package/dist/src/no-theater-available.js +79 -0
  15. package/dist/src/no-theater-available.js.map +1 -0
  16. package/dist/test/book-nav-stub.d.ts +17 -0
  17. package/dist/test/book-nav-stub.js +42 -0
  18. package/dist/test/book-nav-stub.js.map +1 -0
  19. package/dist/test/ia-item-navigator.test.d.ts +1 -0
  20. package/dist/test/ia-item-navigator.test.js +146 -114
  21. package/dist/test/ia-item-navigator.test.js.map +1 -1
  22. package/dist/test/ia-stub.d.ts +22 -0
  23. package/dist/test/ia-stub.js +34 -3
  24. package/dist/test/ia-stub.js.map +1 -1
  25. package/dist/test/no-theater-available.test.d.ts +1 -0
  26. package/dist/test/no-theater-available.test.js +27 -0
  27. package/dist/test/no-theater-available.test.js.map +1 -0
  28. package/package.json +3 -2
  29. package/src/interfaces/nav-controller-interface.ts +13 -0
  30. package/src/item-navigator.ts +69 -36
  31. package/src/no-theater-available.ts +87 -0
  32. package/test/book-nav-stub.ts +35 -0
  33. package/test/ia-item-navigator.test.ts +191 -143
  34. package/test/ia-stub.ts +78 -2
  35. package/test/no-theater-available.test.ts +32 -0
  36. package/src/item-inspector/item-inspector.ts +0 -296
@@ -1,4 +1,3 @@
1
- /* eslint-disable import/no-duplicates */
2
1
  import {
3
2
  css,
4
3
  html,
@@ -8,12 +7,12 @@ import {
8
7
  state,
9
8
  query,
10
9
  PropertyValues,
10
+ CSSResult,
11
11
  } from 'lit-element';
12
12
  import { nothing, TemplateResult } from 'lit-html';
13
13
  import { MetadataResponse } from '@internetarchive/search-service';
14
14
  import {
15
15
  SharedResizeObserver,
16
- SharedResizeObserverInterface,
17
16
  SharedResizeObserverResizeHandlerInterface,
18
17
  } from '@internetarchive/shared-resize-observer';
19
18
  // @ts-ignore
@@ -34,7 +33,7 @@ import {
34
33
  } from './interfaces/event-interfaces';
35
34
 
36
35
  import { IntMenuProvider, IntMenuShortcut } from './interfaces/menu-interfaces';
37
-
36
+ import './no-theater-available';
38
37
  @customElement('ia-item-navigator')
39
38
  export class ItemNavigator
40
39
  extends LitElement
@@ -78,7 +77,9 @@ export class ItemNavigator
78
77
 
79
78
  @property({ type: Array }) menuShortcuts: IntMenuShortcut[] = [];
80
79
 
81
- @property({ type: Boolean, reflect: true }) viewportInFullscreen = false;
80
+ @property({ type: Boolean, reflect: true }) viewportInFullscreen:
81
+ | boolean
82
+ | null = null;
82
83
 
83
84
  @property({ type: Boolean }) menuOpened = false;
84
85
 
@@ -87,14 +88,16 @@ export class ItemNavigator
87
88
  @property({ attribute: false }) modal?: ModalManagerInterface;
88
89
 
89
90
  @property({ attribute: false })
90
- sharedObserver?: SharedResizeObserverInterface;
91
+ sharedObserver?: SharedResizeObserver;
91
92
 
92
- @property({ type: Boolean, reflect: true }) loaded: boolean = false;
93
+ @property({ reflect: true, attribute: true }) loaded: boolean | null = null;
93
94
 
94
95
  @state() openMenuState: 'overlay' | 'shift' = 'shift';
95
96
 
96
97
  @query('#frame') private frame!: HTMLDivElement;
97
98
 
99
+ @query('slot[name="theater-header"]') private headerSlot!: HTMLDivElement;
100
+
98
101
  disconnectedCallback() {
99
102
  this.sharedObserver?.removeObserver({
100
103
  handler: this,
@@ -102,8 +105,7 @@ export class ItemNavigator
102
105
  });
103
106
  }
104
107
 
105
- firstUpdated(pp: any): void {
106
- console.log('first updated item-nav', this.modal, pp);
108
+ firstUpdated(): void {
107
109
  if (!this.modal) {
108
110
  this.createModal();
109
111
  }
@@ -147,30 +149,61 @@ export class ItemNavigator
147
149
  return this.viewportInFullscreen ? 'Internet Archive' : '';
148
150
  }
149
151
 
152
+ get readerHeightStyle(): string {
153
+ const calcFSHeight = `calc(100vh - ${this.headerSlot?.offsetHeight}px)`;
154
+ return this.viewportInFullscreen ? `height: ${calcFSHeight}` : '';
155
+ }
156
+
157
+ handleHeaderSlotChange(e: Event) {
158
+ console.log('~~~~ handleHeaderSlotChange', e);
159
+ }
160
+
161
+ get loadingArea() {
162
+ return html`
163
+ <div class="loading-area">
164
+ <div class="loading-view">
165
+ <ia-itemnav-loader .title=${this.loaderTitle}></ia-itemnav-loader>
166
+ </div>
167
+ </div>
168
+ `;
169
+ }
170
+
150
171
  render(): TemplateResult {
151
172
  const displayReaderClass = this.loaded ? '' : 'hide';
152
173
  return html`
153
174
  <div id="frame" class=${`${this.menuClass}`}>
154
- <slot name="theater-header"></slot>
155
175
  <div class="menu-and-reader">
156
176
  ${this.shouldRenderMenu ? this.renderSideMenu : nothing}
157
- <div id="reader" class=${displayReaderClass}>
177
+ <slot
178
+ name="theater-header"
179
+ @slotchange=${this.handleHeaderSlotChange}
180
+ ></slot>
181
+ <div
182
+ id="reader"
183
+ class=${displayReaderClass}
184
+ style=${this.readerHeightStyle}
185
+ >
158
186
  ${this.renderViewport}
159
187
  </div>
160
- ${!this.loaded
161
- ? html` <div class="loading-area">
162
- <div class="loading-view">
163
- <ia-itemnav-loader
164
- .title=${this.loaderTitle}
165
- ></ia-itemnav-loader>
166
- </div>
167
- </div>`
168
- : nothing}
188
+ ${!this.loaded ? this.loadingArea : nothing}
169
189
  </div>
170
190
  </div>
171
191
  `;
172
192
  }
173
193
 
194
+ get noTheaterView() {
195
+ return html`<ia-no-theater-available
196
+ .identifier=${this.item?.metadata?.identifier}
197
+ @loadingStateUpdated=${this.loadingStateUpdated}
198
+ ></ia-no-theater-available>`;
199
+ }
200
+
201
+ get theaterSlot() {
202
+ return html`
203
+ <slot name="theater-main" style=${this.readerHeightStyle}></slot>
204
+ `;
205
+ }
206
+
174
207
  get BooksViewer(): TemplateResult {
175
208
  const slotVisibility = !this.loaded ? 'opacity: 0;' : 'opacity: 1;';
176
209
 
@@ -189,7 +222,7 @@ export class ItemNavigator
189
222
  @menuShortcutsUpdated=${this.setMenuShortcuts}
190
223
  >
191
224
  <div slot="theater-main" style=${slotVisibility}>
192
- <slot name="theater-main"></slot>
225
+ ${this.theaterSlot}
193
226
  </div>
194
227
  </book-navigator>
195
228
  `;
@@ -202,13 +235,12 @@ export class ItemNavigator
202
235
  if (this.itemType === 'bookreader') {
203
236
  return this.BooksViewer;
204
237
  }
205
- return nothing;
238
+ return this.noTheaterView;
206
239
  }
207
240
 
208
241
  loadingStateUpdated(e: IntLoadingStateUpdatedEvent): void {
209
242
  const { loaded } = e.detail;
210
243
  this.loaded = !!loaded;
211
- console.log('******loadingStateUpdated', e.detail);
212
244
  }
213
245
 
214
246
  /** Creates modal DOM & attaches to `<body>` */
@@ -222,12 +254,14 @@ export class ItemNavigator
222
254
 
223
255
  /** Fullscreen Management */
224
256
  manageViewportFullscreen(e: IntManageFullscreenEvent): void {
225
- this.viewportInFullscreen = !!e.detail.isFullScreen;
226
- this.dispatchEvent(
227
- new CustomEvent('ViewportInFullScreen', {
228
- detail: e.detail,
229
- }) as IntManageFullscreenEvent
230
- );
257
+ const fullscreenStatus = !!e.detail.isFullScreen;
258
+ this.viewportInFullscreen = !fullscreenStatus ? null : fullscreenStatus;
259
+
260
+ const event = new CustomEvent('fullscreenToggled', {
261
+ detail: e.detail,
262
+ }) as IntManageFullscreenEvent;
263
+
264
+ this.dispatchEvent(event);
231
265
  }
232
266
  /** End Fullscreen Management */
233
267
 
@@ -274,7 +308,6 @@ export class ItemNavigator
274
308
  }
275
309
 
276
310
  get menuToggleButton() {
277
- // <ia-icon icon="ellipses" style="width: var(--iconWidth); height: var(--iconHeight);"></ia-icon>
278
311
  return html`
279
312
  <button
280
313
  class="toggle-menu"
@@ -340,7 +373,7 @@ export class ItemNavigator
340
373
  return `${drawerState} ${fullscreenState} ${this.openMenuState}`;
341
374
  }
342
375
 
343
- static get styles() {
376
+ static get styles(): CSSResult {
344
377
  const subnavWidth = css`var(--menuWidth, 320px)`;
345
378
  const transitionTiming = css`var(--animationTiming, 200ms)`;
346
379
  const transitionEffect = css`transform ${transitionTiming} ease-out`;
@@ -350,7 +383,6 @@ export class ItemNavigator
350
383
  return css`
351
384
  :host,
352
385
  #frame,
353
- #reader,
354
386
  .menu-and-reader {
355
387
  min-height: inherit;
356
388
  height: inherit;
@@ -359,6 +391,11 @@ export class ItemNavigator
359
391
  display: block;
360
392
  }
361
393
 
394
+ slot {
395
+ display: block;
396
+ overflow: hidden;
397
+ }
398
+
362
399
  #frame {
363
400
  background-color: ${theaterBg};
364
401
  color-scheme: dark;
@@ -373,11 +410,6 @@ export class ItemNavigator
373
410
  z-index: 9;
374
411
  }
375
412
 
376
- #frame.fullscreen,
377
- #frame.fullscreen #reader {
378
- height: 100vh;
379
- }
380
-
381
413
  .loading-area {
382
414
  position: absolute;
383
415
  top: 0;
@@ -494,6 +526,7 @@ export class ItemNavigator
494
526
  transition: ${transitionEffect};
495
527
  }
496
528
 
529
+ .open.shift slot[name='theater-header'],
497
530
  .open.shift #reader {
498
531
  width: calc(100% - var(--menuWidth));
499
532
  float: right;
@@ -0,0 +1,87 @@
1
+ import {
2
+ LitElement,
3
+ customElement,
4
+ property,
5
+ html,
6
+ TemplateResult,
7
+ PropertyValues,
8
+ CSSResult,
9
+ css,
10
+ } from 'lit-element';
11
+
12
+ import { IntLoadingStateUpdatedEvent } from './interfaces/event-interfaces';
13
+
14
+ @customElement('ia-no-theater-available')
15
+ export class IANoTheaterAvailable extends LitElement {
16
+ @property({ type: String }) identifier?: string = '';
17
+
18
+ emitLoaded(): void {
19
+ this.dispatchEvent(
20
+ new CustomEvent('loadingStateUpdated', {
21
+ detail: { loaded: true },
22
+ }) as IntLoadingStateUpdatedEvent
23
+ );
24
+ }
25
+
26
+ updated(changed: PropertyValues): void {
27
+ if (changed.has('identifier')) {
28
+ this.emitLoaded();
29
+ }
30
+ }
31
+
32
+ get downloadUrl(): string {
33
+ return `/download/${this.identifier}`;
34
+ }
35
+
36
+ render(): TemplateResult {
37
+ return html`
38
+ <section>
39
+ <h2>THERE IS NO PREVIEW AVAILABLE FOR THIS ITEM</h2>
40
+ <p>
41
+ This item does not appear to have any files that can be experienced on
42
+ Archive.org. <br />
43
+ Please download files in this item to interact with them on your
44
+ computer.
45
+ </p>
46
+ <a href=${this.downloadUrl}>Show all files</a>
47
+ </section>
48
+ `;
49
+ }
50
+
51
+ static get styles(): CSSResult {
52
+ return css`
53
+ :host {
54
+ color: var(--primaryTextColor, #fff);
55
+ text-align: center;
56
+ }
57
+ section {
58
+ margin: 10% auto 0;
59
+ padding: 0 5%;
60
+ }
61
+ p {
62
+ font-size: 1.4rem;
63
+ }
64
+ a {
65
+ color: var(--primaryTextColor, #fff);
66
+ background-color: rgb(25, 72, 128);
67
+ min-height: 35px;
68
+ outline: none;
69
+ cursor: pointer;
70
+ line-height: normal;
71
+ border-radius: 0.4rem;
72
+ text-align: center;
73
+ vertical-align: middle;
74
+ font-size: 1.4rem;
75
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
76
+ display: inline-block;
77
+ padding: 0.85rem 1.2rem;
78
+ border: 1px solid rgb(197, 209, 223);
79
+ white-space: nowrap;
80
+ appearance: auto;
81
+ box-sizing: border-box;
82
+ user-select: none;
83
+ text-decoration: none;
84
+ }
85
+ `;
86
+ }
87
+ }
@@ -0,0 +1,35 @@
1
+ import { ModalManagerInterface } from '@internetarchive/modal-manager';
2
+ import { MetadataResponse } from '@internetarchive/search-service';
3
+ import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
4
+ import { html, customElement, LitElement, property } from 'lit-element';
5
+
6
+ @customElement('book-navigator')
7
+ export class BookNavigator extends LitElement {
8
+ @property({ attribute: false }) modal?: ModalManagerInterface;
9
+
10
+ @property({ type: String }) baseHost?: string;
11
+
12
+ @property({ type: Object }) book?: MetadataResponse;
13
+
14
+ @property({ type: Boolean, reflect: true }) signedIn?: boolean | null = null;
15
+
16
+ @property({ type: Boolean }) sideMenuOpen?: boolean;
17
+
18
+ @property({ attribute: false }) sharedObserver?: SharedResizeObserver;
19
+
20
+ addMenuShortcut(menuId: string) {
21
+ return menuId;
22
+ }
23
+
24
+ removeMenuShortcut(menuId: string) {
25
+ return menuId;
26
+ }
27
+
28
+ sortMenuShortcuts() {}
29
+
30
+ emitMenuShortcutsUpdated() {}
31
+
32
+ render() {
33
+ return html` <p>foo</p> `;
34
+ }
35
+ }