Skip to content

Commit

Permalink
config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Nov 16, 2023
1 parent 27ffda3 commit 051b865
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 66 deletions.
7 changes: 5 additions & 2 deletions src/IUVData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { YouTubeData } from "./content-handlers/youtube/YouTubeData";
import { ILocale } from "./content-handlers/iiif/modules/uv-shared-module/ILocale";
import { BaseConfig } from "./content-handlers/iiif/BaseConfig";

export interface IUVData extends IIIFData, EPubData, YouTubeData {
config?: BaseConfig; // do not pass this on initialisation, internal use only
export interface IUVData<T extends BaseConfig>
extends IIIFData,
EPubData,
YouTubeData {
config?: T; // do not pass this on initialisation, internal use only
debug?: boolean;
embedded?: boolean;
isReload?: boolean;
Expand Down
10 changes: 5 additions & 5 deletions src/UniversalViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BaseContentHandler, { EventListener } from "./BaseContentHandler";

export interface IUVOptions {
target: HTMLElement;
data: IUVData;
data: IUVData<any>;
}

enum ContentType {
Expand All @@ -29,9 +29,9 @@ const ContentHandler: IContentHandlerRegistry = {
),
};

export class UniversalViewer extends BaseContentHandler<IUVData> {
export class UniversalViewer extends BaseContentHandler<IUVData<any>> {
private _contentType: ContentType = ContentType.UNKNOWN;
private _assignedContentHandler: IContentHandler<IUVData>;
private _assignedContentHandler: IContentHandler<IUVData<any>>;
private _externalEventListeners: EventListener[] = [];

constructor(public options: IUVOptions) {
Expand All @@ -51,7 +51,7 @@ export class UniversalViewer extends BaseContentHandler<IUVData> {
});
}

private async _assignContentHandler(data: IUVData): Promise<boolean> {
private async _assignContentHandler(data: IUVData<any>): Promise<boolean> {
let contentType: ContentType;

if (data[ContentType.IIIFLEGACY]) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class UniversalViewer extends BaseContentHandler<IUVData> {
return handlerChanged;
}

public set(data: IUVData, initial?: boolean): void {
public set(data: IUVData<any>, initial?: boolean): void {
// content type may have changed
this._assignContentHandler(data).then((handlerChanged: boolean) => {
if (handlerChanged) {
Expand Down
8 changes: 4 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const debounce = (callback: (args: any) => void, wait: number) => {
};

export const propertiesChanged = (
newData: IUVData,
currentData: IUVData,
newData: IUVData<any>,
currentData: IUVData<any>,
properties: string[]
): boolean => {
let propChanged: boolean = false;
Expand All @@ -53,8 +53,8 @@ export const propertiesChanged = (
};

export const propertyChanged = (
newData: IUVData,
currentData: IUVData,
newData: IUVData<any>,
currentData: IUVData<any>,
propertyName: string
): boolean => {
return currentData[propertyName] !== newData[propertyName];
Expand Down
3 changes: 0 additions & 3 deletions src/content-handlers/iiif/BaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ export type Options = {
/** Determines if arrow keys can be used to navigate */
useArrowKeysToNavigate?: boolean;

/** Determines if PDF.js should be used for PDF rendering */
usePdfJs?: boolean;

/** Determines if zoom to search result is enabled */
zoomToSearchResultEnabled?: boolean;

Expand Down
55 changes: 31 additions & 24 deletions src/content-handlers/iiif/IIIFContentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,64 +36,64 @@ const Extension: IExtensionRegistry = {
name: "uv-av-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-av-extension/Extension"
),
"./extensions/uv-av-extension/Extension"
),
},
ALEPH: {
name: "uv-aleph-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-aleph-extension/Extension"
),
"./extensions/uv-aleph-extension/Extension"
),
},
DEFAULT: {
name: "uv-default-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-default-extension/Extension"
),
"./extensions/uv-default-extension/Extension"
),
},
EBOOK: {
name: "uv-ebook-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-ebook-extension/Extension"
),
"./extensions/uv-ebook-extension/Extension"
),
},
MEDIAELEMENT: {
name: "uv-mediaelement-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-mediaelement-extension/Extension"
),
"./extensions/uv-mediaelement-extension/Extension"
),
},
MODELVIEWER: {
name: "uv-model-viewer-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-model-viewer-extension/Extension"
),
"./extensions/uv-model-viewer-extension/Extension"
),
},
OSD: {
name: "uv-openseadragon-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-openseadragon-extension/Extension"
),
"./extensions/uv-openseadragon-extension/Extension"
),
},
PDF: {
name: "uv-pdf-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-pdf-extension/Extension"
),
"./extensions/uv-pdf-extension/Extension"
),
},
SLIDEATLAS: {
name: "uv-openseadragon-extension",
loader: () =>
/* webpackMode: "lazy" */ import(
"./extensions/uv-openseadragon-extension/Extension"
),
"./extensions/uv-openseadragon-extension/Extension"
),
},
};

Expand Down Expand Up @@ -196,7 +196,7 @@ export default class IIIFContentHandler extends BaseContentHandler<IIIFData>
return this._getExtensionByType(this._extensionRegistry[format], format);
}

public set(data: IUVData, initial?: boolean): void {
public set(data: IUVData<any>, initial?: boolean): void {
if (initial) {
this.extra.initial = true;
}
Expand All @@ -210,7 +210,11 @@ export default class IIIFContentHandler extends BaseContentHandler<IIIFData>
this._reload(data);
} else {
// changing any of these data properties forces the UV to reload.
const newData: IUVData = Object.assign({}, this.extension.data, data);
const newData: IUVData<any> = Object.assign(
{},
this.extension.data,
data
);
if (
newData.isReload ||
newData.iiifManifestId !== this.extension.data.iiifManifestId ||
Expand Down Expand Up @@ -269,12 +273,12 @@ export default class IIIFContentHandler extends BaseContentHandler<IIIFData>
// $elem.attr("class", "");
}

private async _reload(data: IUVData): Promise<void> {
private async _reload(data: IUVData<any>): Promise<void> {
this._pubsub.dispose(); // remove any existing event listeners

data.target = ""; // clear target

this.subscribe(Events.RELOAD, (data?: IUVData) => {
this.subscribe(Events.RELOAD, (data?: IUVData<any>) => {
this.fire(Events.RELOAD, data);
});

Expand Down Expand Up @@ -384,7 +388,10 @@ export default class IIIFContentHandler extends BaseContentHandler<IIIFData>
}

// import the config file
let config = await (extension as any).loadConfig(data.locales[0].name, extension?.type.name);
let config = await (extension as any).loadConfig(
data.locales[0].name,
extension?.type.name
);

data.config = await that.configure(config);

Expand All @@ -401,7 +408,7 @@ export default class IIIFContentHandler extends BaseContentHandler<IIIFData>

private _createExtension(
extension: any,
data: IUVData,
data: IUVData<any>,
helper: Helper
): void {
this.extension = extension;
Expand Down
4 changes: 2 additions & 2 deletions src/content-handlers/iiif/URLAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class URLAdapter extends UVAdapter {
}
}

public getInitialData(overrides?: IUVData): IUVData {
public getInitialData(overrides?: IUVData<any>): IUVData<any> {
const formattedLocales: Array<{ label?: string; name: string }> = [];
const locales = this.get<string>("locales", "");
if (locales) {
Expand Down Expand Up @@ -189,7 +189,7 @@ export class URLAdapter extends UVAdapter {
uv.on(
IIIFEvents.RANGE_CHANGE,
(range) => {
const rangeId = !range || typeof range === 'string' ? range : range.id;
const rangeId = !range || typeof range === "string" ? range : range.id;
this.set("rid", rangeId);
},
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "./theme/theme.less";
import defaultConfig from "./config/config.json";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension
export default class Extension extends BaseExtension<Config>
implements IAlephExtension {
$downloadDialogue: JQuery;
$multiSelectDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IUVData } from "../../../../IUVData";
import { Config } from "./config/Config";

export interface IAlephExtensionData extends IUVData {}
export interface IAlephExtensionData extends IUVData<Config> {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import "./theme/theme.less";
import defaultConfig from "./config/config.json";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension implements IAVExtension {
export default class Extension extends BaseExtension<Config>
implements IAVExtension {
$downloadDialogue: JQuery;
$multiSelectDialogue: JQuery;
$settingsDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IUVData } from "../../../../IUVData";
import { Config } from "./config/Config";

export interface IAVExtensionData extends IUVData {}
export interface IAVExtensionData extends IUVData<Config> {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import "./theme/theme.less";
import defaultConfig from "./config/config.json";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension
export default class Extension extends BaseExtension<Config>
implements IDefaultExtension {
$downloadDialogue: JQuery;
$shareDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "./theme/theme.less";
import defaultConfig from "./config/config.json";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension
export default class Extension extends BaseExtension<Config>
implements IEbookExtension {
$downloadDialogue: JQuery;
$moreInfoDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IUVData } from "../../../../IUVData";
import { Config } from "./config/Config";

export interface IEbookExtensionData extends IUVData {
export interface IEbookExtensionData extends IUVData<Config> {
cfi: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import defaultConfig from "./config/config.json";
import { Events } from "../../../../Events";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension
export default class Extension extends BaseExtension<Config>
implements IMediaElementExtension {
$downloadDialogue: JQuery;
$shareDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { AnnotationGroup } from "@iiif/manifold";
import { AnnotationResults } from "../../modules/uv-shared-module/AnnotationResults";
import { Config } from "./config/Config";

export default class ModelViewerExtension extends BaseExtension {
export default class ModelViewerExtension extends BaseExtension<Config> {
$downloadDialogue: JQuery;
$shareDialogue: JQuery;
$helpDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { merge } from "../../../../Utils";
import defaultConfig from "./config/config.json";
import { Config } from "./config/Config";

export default class OpenSeadragonExtension extends BaseExtension {
export default class OpenSeadragonExtension extends BaseExtension<Config> {
$downloadDialogue: JQuery;
$externalContentDialogue: JQuery;
$helpDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import defaultConfig from "./config/config.json";
import { Events } from "../../../../Events";
import { Config } from "./config/Config";

export default class Extension extends BaseExtension implements IPDFExtension {
export default class Extension extends BaseExtension<Config>
implements IPDFExtension {
$downloadDialogue: JQuery;
$shareDialogue: JQuery;
$helpDialogue: JQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IUVData } from "../../../../IUVData";
import { Config } from "./config/Config";

export interface IPDFExtensionData extends IUVData {
export interface IPDFExtensionData extends IUVData<Config> {
anchor: string | null;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { BaseConfig } from "@/content-handlers/iiif/BaseConfig";
import { BaseConfig, Options } from "@/content-handlers/iiif/BaseConfig";

type Modules = {};

type PDFOptions = Options & {
/** Determines if PDF.js should be used for PDF rendering */
usePdfJs?: boolean;
};

export type Config = BaseConfig & {
options: PDFOptions;
modules: Modules;
};
Loading

0 comments on commit 051b865

Please sign in to comment.