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

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 (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,296 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* eslint-disable import/no-duplicates */
3
- import {
4
- css,
5
- html,
6
- LitElement,
7
- customElement,
8
- property,
9
- state,
10
- } from 'lit-element';
11
- import { MetadataResponse } from '@internetarchive/search-service';
12
-
13
- import {
14
- ModalManagerInterface,
15
- ModalConfig,
16
- } from '@internetarchive/modal-manager';
17
- import { SharedResizeObserverInterface } from '@internetarchive/shared-resize-observer';
18
- import { IntNavController } from '../interfaces/nav-controller-interface';
19
- import {
20
- IntMenuProvider,
21
- IntMenuShortcut,
22
- } from '../interfaces/menu-interfaces';
23
- import { IntManageFullscreenEvent } from '../interfaces/event-interfaces';
24
-
25
- import { ShareProvider } from './share-provider';
26
- import { FilesByTypeProvider } from './files-by-type/files-by-type-provider';
27
- import { VisualModsProvider } from './visual-mod-provider';
28
-
29
- // eslint-disable-next-line no-shadow
30
- enum ItemInspectorEvents {
31
- menuUpdated = 'menuUpdated',
32
- updateSideMenu = 'updateSideMenu',
33
- PostInit = 'PostInit',
34
- ViewportInFullScreen = 'ViewportInFullScreen',
35
- }
36
-
37
- interface menuProvidersInt {
38
- [menuId: string]: IntMenuProvider;
39
- }
40
-
41
- @customElement('ia-item-inspector')
42
- export class IaItemInspector extends LitElement implements IntNavController {
43
- @property({ type: Object }) itemMD: MetadataResponse = {
44
- metadata: {},
45
- } as MetadataResponse;
46
-
47
- @property({ type: String }) baseHost = 'https://archive.org';
48
-
49
- @property({ type: Object }) menuProviders: menuProvidersInt = {};
50
-
51
- @property({ type: Array }) menuShortcuts: IntMenuShortcut[] = [];
52
-
53
- @property({ type: Boolean }) sideMenuOpen = false;
54
-
55
- @property({ type: Boolean }) fullscreenState = false;
56
-
57
- @property({ attribute: false }) modal!: ModalManagerInterface;
58
-
59
- @property({ attribute: false }) sharedRO!: SharedResizeObserverInterface;
60
-
61
- @state() fileCount: number = 0;
62
-
63
- @state() loaded: boolean = false;
64
-
65
- @state() private shortcutOrder = ['visualMods'];
66
-
67
- firstUpdated() {
68
- this.loaded = true;
69
- console.log('modal', this.modal);
70
- }
71
-
72
- updated(changed: any) {
73
- if (changed.has('loaded')) {
74
- setTimeout(() => this.emitLoadingStatusUpdate(this.loaded), 1000);
75
- }
76
-
77
- if (changed.has('itemMD') && this.itemMD) {
78
- this.parseItemInfo();
79
- this.setMenu();
80
- }
81
-
82
- if (changed.has('menuProviders') || changed.has('menuShortcuts')) {
83
- this.updateMenuContents();
84
- }
85
- }
86
-
87
- modalClosedCallback() {
88
- console.log('item-inspector, modal closed');
89
- }
90
-
91
- openModal() {
92
- const config = new ModalConfig();
93
- const customModalContent = html`
94
- Can contain any markup, including web components. Event listeners also
95
- work. Try clicking on the picture.
96
- <div style="text-align: center">
97
- <a href="https://fillmurray.com" style="display: block">Fill Murray</a>
98
- <img src="100x100.jpg" alt="foo" />
99
- </div>
100
- `;
101
-
102
- this.modal.showModal({
103
- config,
104
- customModalContent,
105
- userClosedModalCallback: this.modalClosedCallback,
106
- });
107
- }
108
-
109
- render() {
110
- const { identifier = '' } = this.itemMD?.metadata;
111
- return html`
112
- <section>
113
- <div>
114
- <h2>${identifier}</h2>
115
- </div>
116
- <img src=${this.imageUrl} alt=${`${identifier} thumbnail`} />
117
- <button @click=${() => this.openModal()}>open modal</button>
118
- <p style="font-size: 20px;">
119
- Bacon ipsum dolor amet flank chicken leberkas sausage, meatball pork
120
- belly jowl. Chislic bacon salami frankfurter shankle drumstick
121
- andouille ball tip alcatra. Fatback beef ribs chicken, jerky ground
122
- round hamburger pork chop biltong. Shoulder short loin rump jerky
123
- kielbasa pork porchetta fatback ribeye pork belly sirloin chislic
124
- turducken corned beef tri-tip. Chuck pancetta meatball tail, spare
125
- ribs ham hock capicola pig. Ham hock hamburger chicken tri-tip venison
126
- swine burgdoggen boudin meatloaf pastrami chuck. Tri-tip spare ribs
127
- drumstick, tail rump hamburger burgdoggen swine t-bone tongue
128
- andouille chislic alcatra. Pork loin jowl frankfurter, doner meatball
129
- short loin ham hock filet mignon hamburger rump turkey bresaola
130
- shoulder sirloin flank. Ribeye sausage pig t-bone bacon frankfurter
131
- cupim capicola fatback pastrami ball tip pork belly. Picanha pancetta
132
- andouille flank shankle venison tri-tip tail, kevin turkey turducken
133
- chicken. Bacon picanha swine frankfurter, prosciutto chislic doner
134
- alcatra pork loin corned beef jowl biltong meatball chuck. Bacon
135
- burgdoggen pig fatback cupim t-bone. Cow pork loin bresaola brisket
136
- shoulder filet mignon chicken. Sirloin bresaola porchetta beef
137
- capicola meatloaf brisket shankle jerky turkey pork tri-tip swine
138
- kevin salami. Meatball t-bone doner venison. Pig tri-tip chuck, shank
139
- chicken pork chop landjaeger spare ribs jerky swine ham hock buffalo
140
- sirloin. Leberkas pancetta tenderloin, meatloaf buffalo rump pastrami
141
- chuck. Jerky cupim porchetta, tenderloin chuck andouille venison pork
142
- salami. Chuck strip steak cupim, turducken ham hock kielbasa shoulder
143
- porchetta chislic short loin tri-tip biltong cow corned beef.
144
- </p>
145
- </section>
146
- `;
147
- }
148
-
149
- addMenuShortcut(menuId: keyof menuProvidersInt) {
150
- if (this.menuShortcuts.find(m => m.id === menuId)) {
151
- return;
152
- }
153
-
154
- const shortcut = this.menuProviders[menuId];
155
- this.menuShortcuts.push(shortcut);
156
- this.sortMenuShortcuts();
157
- this.emitMenuShortcutsUpdated();
158
- }
159
-
160
- /**
161
- * Removes a provider object from the menuShortcuts array and emits a
162
- * menuShortcutsUpdated event.
163
- */
164
- removeMenuShortcut(menuId: string) {
165
- this.menuShortcuts = this.menuShortcuts.filter(m => m.id !== menuId);
166
- this.emitMenuShortcutsUpdated();
167
- }
168
-
169
- /**
170
- * Sorts the menuShortcuts property by comparing each provider's id to
171
- * the id in each iteration over the shortcutOrder array.
172
- */
173
- sortMenuShortcuts() {
174
- this.menuShortcuts = this.shortcutOrder.reduce(
175
- (shortcuts: IntMenuShortcut[], id) => {
176
- const menu = this.menuShortcuts.find(m => m.id === id);
177
-
178
- // eslint-disable-next-line no-param-reassign
179
- if (menu) {
180
- const newShortcuts = [...shortcuts, menu];
181
- // eslint-disable-next-line no-param-reassign
182
- shortcuts = newShortcuts;
183
- }
184
- return shortcuts;
185
- },
186
- []
187
- );
188
- }
189
-
190
- emitMenuShortcutsUpdated() {
191
- const event = new CustomEvent('menuShortcutsUpdated', {
192
- detail: this.menuShortcuts,
193
- });
194
- this.dispatchEvent(event);
195
- }
196
-
197
- setMenu() {
198
- const menuProviders = {
199
- share: new ShareProvider({
200
- item: this.itemMD,
201
- baseHost: this.baseHost,
202
- subPrefix: '',
203
- }),
204
- filesByType: new FilesByTypeProvider({
205
- item: this.itemMD,
206
- baseHost: this.baseHost,
207
- subPrefix: '',
208
- }),
209
- visualMods: new VisualModsProvider({
210
- updated: (modType: string) => {
211
- if (modType === 'toggleFullscreen') {
212
- this.updateFullscreenState();
213
- }
214
- },
215
- item: this.itemMD,
216
- baseHost: this.baseHost,
217
- subPrefix: '',
218
- // maybe DOM root for class configs?
219
- }),
220
- };
221
-
222
- this.menuProviders = menuProviders;
223
- this.addMenuShortcut('visualMods');
224
- }
225
-
226
- updateFullscreenState() {
227
- const isFullScreen = !this.fullscreenState;
228
- this.fullscreenState = isFullScreen;
229
-
230
- const event = new CustomEvent('ViewportInFullScreen', {
231
- detail: { isFullScreen },
232
- } as IntManageFullscreenEvent);
233
- this.dispatchEvent(event);
234
- }
235
-
236
- updateMenuContents() {
237
- const { share, filesByType, visualMods } = this.menuProviders;
238
- const availableMenus = [filesByType, share, visualMods].filter(
239
- menu => !!menu
240
- );
241
-
242
- const event = new CustomEvent(ItemInspectorEvents.menuUpdated, {
243
- detail: availableMenus,
244
- });
245
-
246
- this.dispatchEvent(event);
247
- }
248
-
249
- emitLoadingStatusUpdate(loaded: boolean) {
250
- const event = new CustomEvent('loadingStateUpdated', {
251
- detail: { loaded },
252
- });
253
- this.dispatchEvent(event);
254
- }
255
-
256
- parseItemInfo() {
257
- this.fileCount = this.itemMD?.files?.length || 0;
258
- }
259
-
260
- get imageUrl() {
261
- const { metadata = {} } = this.itemMD;
262
- const url = `${this.baseHost}/download/${metadata?.identifier}/__ia_thumb.jpg`;
263
- return url;
264
- }
265
-
266
- static get styles() {
267
- const main = css`
268
- :host {
269
- display: block;
270
- width: 100%;
271
- margin: 0 auto;
272
- position: relative;
273
- overflow: auto;
274
- background-color: black;
275
- color: var(--primaryTextColor, #fff);
276
- }
277
-
278
- :host,
279
- section {
280
- min-height: inherit;
281
- height: inherit;
282
- }
283
-
284
- section {
285
- margin: auto;
286
- width: 100%;
287
- text-align: center;
288
- }
289
-
290
- img {
291
- border: 1px solid var(--primaryTextColor, #fff);
292
- }
293
- `;
294
- return [main];
295
- }
296
- }