fix(core): update
This commit is contained in:
parent
94127227a6
commit
b60a1bebe0
@ -28,6 +28,7 @@
|
|||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.1.3",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartrouter": "^1.0.6",
|
"@pushrocks/smartrouter": "^1.0.6",
|
||||||
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/smartstate": "^1.0.21",
|
"@pushrocks/smartstate": "^1.0.21",
|
||||||
"@pushrocks/webrequest": "^2.0.13",
|
"@pushrocks/webrequest": "^2.0.13",
|
||||||
"@pushrocks/websetup": "^3.0.11",
|
"@pushrocks/websetup": "^3.0.11",
|
||||||
|
@ -6,7 +6,6 @@ import { TViewport } from './domtools.breakpoints';
|
|||||||
import { Scroller } from './domtools.classes.scroller';
|
import { Scroller } from './domtools.classes.scroller';
|
||||||
import { delayForRandom } from '@pushrocks/smartdelay';
|
import { delayForRandom } from '@pushrocks/smartdelay';
|
||||||
import { WebSetup } from '@pushrocks/websetup';
|
import { WebSetup } from '@pushrocks/websetup';
|
||||||
import { ElementInstrumenter } from './domtools.classes.elementinstrumenter';
|
|
||||||
import { ThemeManager } from './domtools.classes.thememanager';
|
import { ThemeManager } from './domtools.classes.thememanager';
|
||||||
|
|
||||||
export interface IDomToolsState {
|
export interface IDomToolsState {
|
||||||
@ -85,8 +84,6 @@ export class DomTools {
|
|||||||
smartdelay: plugins.smartdelay,
|
smartdelay: plugins.smartdelay,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public elementInstrumenter = new ElementInstrumenter();
|
|
||||||
public deesComms = new plugins.deesComms.DeesComms();
|
public deesComms = new plugins.deesComms.DeesComms();
|
||||||
public scroller = new plugins.SweetScroll({
|
public scroller = new plugins.SweetScroll({
|
||||||
/* some options */
|
/* some options */
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
import * as plugins from './domtools.plugins';
|
|
||||||
import { LitElement } from 'lit-element';
|
|
||||||
|
|
||||||
export class ElementInstrumenter {
|
|
||||||
connectedElements = new plugins.lik.ObjectMap<LitElement>();
|
|
||||||
|
|
||||||
public instrumentElement(elementArg: LitElement) {
|
|
||||||
const addToConnectedElementsFunc = (eventArg: CustomEvent) => {
|
|
||||||
this.connectedElements.add(elementArg);
|
|
||||||
};
|
|
||||||
const removeFromConnectedElementsFunc = eventArg => {
|
|
||||||
this.connectedElements.remove(elementArg);
|
|
||||||
elementArg.removeEventListener('domtools-connected', addToConnectedElementsFunc);
|
|
||||||
elementArg.removeEventListener('domtools-disconnected', removeFromConnectedElementsFunc);
|
|
||||||
};
|
|
||||||
elementArg.addEventListener('domtools-connected', addToConnectedElementsFunc);
|
|
||||||
elementArg.addEventListener('domtools-disconnected', removeFromConnectedElementsFunc);
|
|
||||||
|
|
||||||
if (elementArg.parentElement) {
|
|
||||||
this.connectedElements.add(elementArg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {
|
|
||||||
for (const elementArg of this.connectedElements.getArray()) {
|
|
||||||
await eachFuncArg(elementArg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,34 +8,23 @@ export class ThemeManager {
|
|||||||
public goBrightBoolean = false;
|
public goBrightBoolean = false;
|
||||||
public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)');
|
public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)');
|
||||||
|
|
||||||
|
public themeObservable = new plugins.smartrx.rxjs.ReplaySubject<boolean>(1);
|
||||||
|
|
||||||
constructor(domtoolsRefArg: DomTools) {
|
constructor(domtoolsRefArg: DomTools) {
|
||||||
this.domtoolsRef = domtoolsRefArg;
|
this.domtoolsRef = domtoolsRefArg;
|
||||||
|
|
||||||
// lets take care of elements being added that need to know of the current theme
|
|
||||||
this.domtoolsRef.elementInstrumenter.connectedElements.eventSubject.subscribe(async eventData => {
|
|
||||||
await this.setThemeStatusForElement(eventData.payload, this.goBrightBoolean);
|
|
||||||
});
|
|
||||||
|
|
||||||
// lets care
|
// lets care
|
||||||
this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches;
|
this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches;
|
||||||
this.preferredColorSchemeMediaMatch.addEventListener('change', eventArg => {
|
this.preferredColorSchemeMediaMatch.addEventListener('change', eventArg => {
|
||||||
this.goBrightBoolean = eventArg.matches;
|
this.goBrightBoolean = eventArg.matches;
|
||||||
this.updateAllConnectedElements();
|
this.updateAllConnectedElements();
|
||||||
});
|
});
|
||||||
}
|
this.updateAllConnectedElements();
|
||||||
|
|
||||||
private async setThemeStatusForElement (elementArg: LitElement, goBrightBool: boolean) {
|
|
||||||
const goBright = (elementArg as any).goBright;
|
|
||||||
if (typeof goBright === 'boolean') {
|
|
||||||
(elementArg as any).goBright = goBrightBool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateAllConnectedElements() {
|
private async updateAllConnectedElements() {
|
||||||
document.body.style.background = this.goBrightBoolean ? '#fff' : '#000';
|
document.body.style.background = this.goBrightBoolean ? '#fff' : '#000';
|
||||||
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
|
this.themeObservable.next(this.goBrightBoolean);
|
||||||
await this.setThemeStatusForElement(elementArg, this.goBrightBoolean);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public goBright() {
|
public goBright() {
|
||||||
|
@ -27,7 +27,8 @@ export const setup = async (elementArg?: LitElement): Promise<DomTools> => {
|
|||||||
const domTools = await DomTools.setupDomTools();
|
const domTools = await DomTools.setupDomTools();
|
||||||
|
|
||||||
if (elementArg) {
|
if (elementArg) {
|
||||||
domTools.elementInstrumenter.instrumentElement(elementArg);
|
// lets do something with the element
|
||||||
|
// not used right now
|
||||||
}
|
}
|
||||||
|
|
||||||
domTools.runOnce('elementBasicSetup', async () => {
|
domTools.runOnce('elementBasicSetup', async () => {
|
||||||
|
@ -14,6 +14,7 @@ export { typedrequest };
|
|||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrouter from '@pushrocks/smartrouter';
|
import * as smartrouter from '@pushrocks/smartrouter';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
import * as smartstate from '@pushrocks/smartstate';
|
import * as smartstate from '@pushrocks/smartstate';
|
||||||
import * as webrequest from '@pushrocks/webrequest';
|
import * as webrequest from '@pushrocks/webrequest';
|
||||||
import * as websetup from '@pushrocks/websetup';
|
import * as websetup from '@pushrocks/websetup';
|
||||||
@ -25,7 +26,7 @@ const lik = {
|
|||||||
ObjectMap
|
ObjectMap
|
||||||
};
|
};
|
||||||
|
|
||||||
export { lik, smartdelay, smartpromise, smartrouter, smartstate, webrequest, websetup, webstore };
|
export { lik, smartdelay, smartpromise, smartrouter, smartrx, smartstate, webrequest, websetup, webstore };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import SweetScroll from 'sweet-scroll';
|
import SweetScroll from 'sweet-scroll';
|
||||||
|
Loading…
Reference in New Issue
Block a user