Skip to content

Commit

Permalink
build: update typings to support Node v18 (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaerusKaru authored Oct 11, 2022
1 parent 77a9b62 commit 97c24af
Show file tree
Hide file tree
Showing 5 changed files with 1,117 additions and 862 deletions.
2 changes: 1 addition & 1 deletion projects/apps/demo-app/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* You can add global styles to this file, and also import other style files */
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
@import '@angular/material/prebuilt-themes/indigo-pink.css';

body {
margin: 50px;
Expand Down
30 changes: 14 additions & 16 deletions projects/libs/flex-layout/core/match-media/match-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,21 @@ function buildQueryCss(mediaQueries: string[], _document: Document) {
}
}

function buildMockMql(query: string) {
const et: any = new EventTarget();
et.matches = query === 'all' || query === '';
et.media = query;
et.addListener = () => {};
et.removeListener = () => {};
et.addEventListener = () => {};
et.dispatchEvent = () => false;
et.onchange = null;

return et as MediaQueryList;
}

function constructMql(query: string, isBrowser: boolean): MediaQueryList {
const canListen = isBrowser && !!(<Window>window).matchMedia('all').addListener;

return canListen ? (<Window>window).matchMedia(query) : {
matches: query === 'all' || query === '',
media: query,
addListener: () => {
},
removeListener: () => {
},
onchange: null,
addEventListener() {
},
removeEventListener() {
},
dispatchEvent() {
return false;
}
} as MediaQueryList;
return canListen ? (<Window>window).matchMedia(query) : buildMockMql(query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class MockMatchMedia extends MatchMedia {
* - supports manual activation to simulate mediaQuery matching
* - manages listeners
*/
export class MockMediaQueryList implements MediaQueryList {
export class MockMediaQueryList extends EventTarget implements MediaQueryList {
private _isActive = false;
private _listeners: MediaQueryListListener[] = [];

Expand All @@ -178,6 +178,7 @@ export class MockMediaQueryList implements MediaQueryList {
}

constructor(private _mediaQuery: string) {
super();
}

/**
Expand Down Expand Up @@ -228,31 +229,7 @@ export class MockMediaQueryList implements MediaQueryList {
removeListener(_: MediaQueryListListener | null) {
}

addEventListener<K extends keyof MediaQueryListEventMap>(
_: K,
__: (this: MediaQueryList,
ev: MediaQueryListEventMap[K]) => any,
___?: boolean | AddEventListenerOptions): void;

addEventListener(
_: string,
__: EventListenerOrEventListenerObject,
___?: boolean | AddEventListenerOptions) {
}

removeEventListener<K extends keyof MediaQueryListEventMap>(
_: K,
__: (this: MediaQueryList,
ev: MediaQueryListEventMap[K]) => any,
___?: boolean | EventListenerOptions): void;

removeEventListener(
_: string,
__: EventListenerOrEventListenerObject,
___?: boolean | EventListenerOptions) {
}

dispatchEvent(_: Event): boolean {
override dispatchEvent(_: Event): boolean {
return false;
}

Expand Down
12 changes: 7 additions & 5 deletions projects/libs/flex-layout/server/server-match-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
* - supports manual activation to simulate mediaQuery matching
* - manages listeners
*/
export class ServerMediaQueryList implements MediaQueryList {
export class ServerMediaQueryList extends EventTarget implements MediaQueryList {
private _listeners: MediaQueryListListener[] = [];

get matches(): boolean {
Expand All @@ -31,7 +31,9 @@ export class ServerMediaQueryList implements MediaQueryList {
return this._mediaQuery;
}

constructor(private _mediaQuery: string, private _isActive = false) {}
constructor(private _mediaQuery: string, private _isActive = false) {
super();
}

/**
* Destroy the current list by deactivating the
Expand Down Expand Up @@ -81,13 +83,13 @@ export class ServerMediaQueryList implements MediaQueryList {
removeListener() {
}

addEventListener() {
override addEventListener() {
}

removeEventListener() {
override removeEventListener() {
}

dispatchEvent(_: Event): boolean {
override dispatchEvent(_: Event): boolean {
return false;
}

Expand Down
Loading

0 comments on commit 97c24af

Please sign in to comment.