Skip to content

Commit

Permalink
chore(deps): Update Deps (Week 38) & fix new lints (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
klarstrup authored Sep 17, 2024
1 parent 52e57e0 commit 3631bc7
Show file tree
Hide file tree
Showing 12 changed files with 2,708 additions and 2,485 deletions.
3 changes: 2 additions & 1 deletion __tests_utils__/webpack-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ export default async function compile(
});

//direct webpack to use memoryfs
// @ts-expect-error - it's not that serious
compiler.inputFileSystem = compiler.outputFileSystem = memFs;

const errors = (
await new Promise<Stats>((y, n) =>
compiler.run((e, r) => (e || !r ? n(e) : y(r)))
compiler.run((e, r) => (e ? n(e) : y(r!)))
)
).compilation.errors;

Expand Down
8 changes: 4 additions & 4 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config extends MicroEvent<{change: [Record<string, any>]}> {

for (let key in config) {
if (key === 'appKey') key = 'apiKey';
if (this.keys.includes(key as typeof this.keys[number])) {
if (this.keys.includes(key as (typeof this.keys)[number])) {
this._attrs[key] = config[key];
changedAttributes[key] = config[key];
}
Expand All @@ -24,17 +24,17 @@ class Config extends MicroEvent<{change: [Record<string, any>]}> {
return this._attrs[option];
}

shadow<T extends Record<string, any> = {}>(
shadow<T extends Record<string, any> = Record<string, any>>(
optionsObject?: T
): T & Record<typeof this.keys[number], string> {
): T & Record<(typeof this.keys)[number], string> {
const optionsWithConfig = {...optionsObject};
this.keys.forEach((key) => {
const get = () => optionsObject?.[key] || this.get(key);
Object.defineProperty(optionsWithConfig, key, {get});
});

return optionsWithConfig as T &
Record<typeof this.keys[number], string>;
Record<(typeof this.keys)[number], string>;
}
}

Expand Down
4 changes: 1 addition & 3 deletions lib/kits/core-ui/offer-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ export default class OfferDetails {
this.position();
}

appendTo(el) {
appendTo(el: Element) {
el.appendChild(this.el);

this.el.offsetWidth;

this.show();

return this;
Expand Down
4 changes: 2 additions & 2 deletions lib/kits/core-ui/page-decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const PageDecorations = () => {
aspectRatio
}: {
pageDecorations: V2PageDecoration[];
aspectRatio: {};
aspectRatio: number;
}) => {
if (pageDecorationsContainer?.innerHTML) {
pageDecorationsContainer.innerHTML = '';
Expand Down Expand Up @@ -108,7 +108,7 @@ const PageDecorations = () => {
}
};

const getPubImageDimension = (aspectRatio, pageCount) => {
const getPubImageDimension = (aspectRatio: number, pageCount: number) => {
const versoPageSpreadEl =
document.querySelector<HTMLElement>('.verso__scroller');
const pageElWidth = (versoPageSpreadEl?.offsetWidth || 0) / pageCount;
Expand Down
51 changes: 32 additions & 19 deletions lib/kits/core-ui/paged-publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const PagedPublication = (
}
) => {
let options;
let sgnData: {details: V2Catalog; pages: V2Page[]} | undefined | {} = {};
let sgnData:
| {details: V2Catalog; pages: V2Page[]}
| undefined
| Record<string, never> = {};
let sgnViewer: Viewer;
let sgnPageDecorations: V2PageDecoration[];
const scriptEls = transformScriptData(scriptEl, mainContainer);
Expand Down Expand Up @@ -229,25 +232,33 @@ const PagedPublication = (
if (mutation.type === 'attributes') {
const element = mutation.target as HTMLButtonElement;
if (element.dataset.direction === 'prev') {
element.classList.contains('sgn-pp--hidden')
? firstControl.classList.add('sgn-pp--hidden')
: firstControl.classList.remove('sgn-pp--hidden');
if (element.classList.contains('sgn-pp--hidden')) {
firstControl.classList.add('sgn-pp--hidden');
} else {
firstControl.classList.remove('sgn-pp--hidden');
}
}
if (element.dataset.direction === 'next') {
element.classList.contains('sgn-pp--hidden')
? lastControl.classList.add('sgn-pp--hidden')
: lastControl.classList.remove('sgn-pp--hidden');
if (element.classList.contains('sgn-pp--hidden')) {
lastControl.classList.add('sgn-pp--hidden');
} else {
lastControl.classList.remove('sgn-pp--hidden');
}
}
}
});
});

prevBtn?.classList.contains('sgn-pp--hidden')
? firstControl.classList.add('sgn-pp--hidden')
: firstControl.classList.remove('sgn-pp--hidden');
nextBtn?.classList.contains('sgn-pp--hidden')
? lastControl.classList.add('sgn-pp--hidden')
: lastControl.classList.remove('sgn-pp--hidden');
if (prevBtn?.classList.contains('sgn-pp--hidden')) {
firstControl.classList.add('sgn-pp--hidden');
} else {
firstControl.classList.remove('sgn-pp--hidden');
}
if (nextBtn?.classList.contains('sgn-pp--hidden')) {
lastControl.classList.add('sgn-pp--hidden');
} else {
lastControl.classList.remove('sgn-pp--hidden');
}

firstControl?.addEventListener('click', () => {
sgnViewer?.first();
Expand Down Expand Up @@ -275,12 +286,14 @@ const PagedPublication = (
?.split(' ')?.[0]
?.split('-')?.[0];

scriptEls.displayUrlParams?.toLowerCase() === 'query'
? pushQueryParam({
[scriptEls.publicationIdParam]: options.id,
[scriptEls.pageIdParam]: pageNum
})
: (location.hash = `${scriptEls.publicationHash}/${options.id}/${pageNum}`);
if (scriptEls.displayUrlParams?.toLowerCase() === 'query') {
pushQueryParam({
[scriptEls.publicationIdParam]: options.id,
[scriptEls.pageIdParam]: pageNum
});
} else {
location.hash = `${scriptEls.publicationHash}/${options.id}/${pageNum}`;
}
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/kits/events/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ interface OfferOpenedEvent {
// View token unique for this event data
vt: string;
}
interface ClientSessionOpenedEvent {}
type ClientSessionOpenedEvent = object;
interface SearchedEvent {
// Search Query
'sea.q': string;
Expand Down Expand Up @@ -241,7 +241,7 @@ export type WolfEvent = WolfEventTypeMap[keyof WolfEventTypeMap];
const locationSources = ['gps', 'geoip', 'manual', 'fallback'] as const;
interface TrackerLocation {
geohash: string | null;
source: typeof locationSources[number] | null;
source: (typeof locationSources)[number] | null;
time: number | null;
country: string | null;
}
Expand Down
20 changes: 15 additions & 5 deletions lib/kits/paged-publication/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ function getColorBrightness(color: string) {
return sum <= 381 ? 'dark' : 'light';
}

interface PagedPublicationCoreInit {}
interface PagedPublicationCoreInit {
id: string;
pageId?: string;
pages?: unknown[];
pageSpreadWidth?: number;
pageSpreadMaxZoomScale?: number;
idleDelay?: number;
resizeDelay?: number;
color?: string;
}

class PagedPublicationCore extends MicroEvent {
defaults = {
pages: [],
Expand All @@ -37,9 +47,9 @@ class PagedPublicationCore extends MicroEvent {
idleTimeout: NodeJS.Timeout | undefined;
pageSpreads: PageSpreads;
resizeListener: () => void;
constructor(el: HTMLElement, options: PagedPublicationCoreInit = {}) {
constructor(el: HTMLElement, options: PagedPublicationCoreInit) {
super();
this.options = this.makeOptions(options, this.defaults);
this.options = this.makeOptions(options ?? {}, this.defaults);
this.pageId = this.getOption('pageId');
this.rootEl = el;
this.pagesEl = el.querySelector('.sgn-pp__pages');
Expand Down Expand Up @@ -113,12 +123,12 @@ class PagedPublicationCore extends MicroEvent {
makeOptions(
options: Partial<PagedPublicationCoreInit>,
defaults: typeof this.defaults
): Partial<PagedPublicationCoreInit> & typeof this.defaults {
) {
const opts = {};

for (const key in options) opts[key] = options[key] ?? defaults[key];

return opts as Partial<PagedPublicationCoreInit> & typeof this.defaults;
return opts as PagedPublicationCoreInit;
}

getOption(key: string) {
Expand Down
2 changes: 1 addition & 1 deletion lib/kits/paged-publication/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface ViewerInit {
color?: string;
eventTracker: Tracker;
keyboard: 'disabled' | 'enabled' | 'global';
hotspotRatio: unknown;
hotspotRatio?: number;
pickHotspot?: typeof defaultPickHotspot;
}
class Viewer extends MicroEvent {
Expand Down
4 changes: 2 additions & 2 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getQueryParam(field, url?: string) {
export function throttle<A extends unknown[]>(
fn: (...args: A) => unknown,
threshold = 250,
scope?: Object
scope?: object
): (...args: A) => void {
let last: number | undefined;
let deferTimer: NodeJS.Timeout;
Expand Down Expand Up @@ -76,7 +76,7 @@ export function throttle<A extends unknown[]>(
export function debounce<A extends unknown[]>(
fn: (...args: A) => unknown,
threshold = 250,
scope?: Object
scope?: object
): (...args: A) => void {
let deferTimer: NodeJS.Timeout;

Expand Down
Loading

0 comments on commit 3631bc7

Please sign in to comment.