fix(core): update

This commit is contained in:
Philipp Kunz 2022-04-21 22:53:58 +02:00
parent 4ec8707596
commit b83d3e1aed
2 changed files with 15 additions and 10 deletions

View File

@ -6,13 +6,17 @@ import { TViewport } from './domtools.css.breakpoints.js';
import { Scroller } from './domtools.classes.scroller.js'; import { Scroller } from './domtools.classes.scroller.js';
import { WebSetup } from '@pushrocks/websetup'; import { WebSetup } from '@pushrocks/websetup';
import { ThemeManager } from './domtools.classes.thememanager.js'; import { ThemeManager } from './domtools.classes.thememanager.js';
import { Keyboard, Key } from './domtools.classes.keyboard.js'; import { Keyboard } from './domtools.classes.keyboard.js';
export interface IDomToolsState { export interface IDomToolsState {
virtualViewport: TViewport; virtualViewport: TViewport;
jwt: string; jwt: string;
} }
export interface IDomToolsContructorOptions {
ignoreGlobal?: boolean;
}
export class DomTools { export class DomTools {
// ====== // ======
// STATIC // STATIC
@ -20,10 +24,10 @@ export class DomTools {
/** /**
* setups domtools * setups domtools
*/ */
public static async setupDomTools() { public static async setupDomTools(optionsArg: IDomToolsContructorOptions = {}) {
let domToolsInstance: DomTools; let domToolsInstance: DomTools;
if (!globalThis.deesDomTools) { if (!globalThis.deesDomTools && !optionsArg.ignoreGlobal) {
globalThis.deesDomTools = new DomTools(); globalThis.deesDomTools = new DomTools(optionsArg);
domToolsInstance = globalThis.deesDomTools; domToolsInstance = globalThis.deesDomTools;
// lets make sure the dom is ready // lets make sure the dom is ready
@ -36,6 +40,8 @@ export class DomTools {
}; };
document.addEventListener('readystatechange', readyStateChangedFunc); document.addEventListener('readystatechange', readyStateChangedFunc);
domToolsInstance.domToolsReady.resolve(); domToolsInstance.domToolsReady.resolve();
} else if (optionsArg.ignoreGlobal) {
domToolsInstance = new DomTools(optionsArg);
} else { } else {
domToolsInstance = globalThis.deesDomTools; domToolsInstance = globalThis.deesDomTools;
} }
@ -75,7 +81,7 @@ export class DomTools {
public smartstate = new plugins.smartstate.Smartstate(); public smartstate = new plugins.smartstate.Smartstate();
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', { public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', {
virtualViewport: 'native', virtualViewport: 'native',
jwt: null jwt: null,
}); });
public router = new plugins.smartrouter.SmartRouter({ public router = new plugins.smartrouter.SmartRouter({
@ -93,13 +99,12 @@ export class DomTools {
}); // TODO: switch to scroller class }); // TODO: switch to scroller class
public themeManager = new ThemeManager(this); public themeManager = new ThemeManager(this);
public keyboard = new Keyboard(document.body); public keyboard = new Keyboard(document.body);
public domToolsReady = plugins.smartpromise.defer(); public domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer(); public domReady = plugins.smartpromise.defer();
public globalStylesReady = plugins.smartpromise.defer(); public globalStylesReady = plugins.smartpromise.defer();
constructor() {} constructor(optionsArg: IDomToolsContructorOptions) {}
private runOnceTrackerStringMap = new Stringmap(); private runOnceTrackerStringMap = new Stringmap();
private runOnceResultMap = new FastMap(); private runOnceResultMap = new FastMap();

View File

@ -1,5 +1,5 @@
import * as plugins from './domtools.plugins.js'; import * as plugins from './domtools.plugins.js';
import { DomTools } from './domtools.classes.domtools.js'; import { DomTools, IDomToolsContructorOptions } from './domtools.classes.domtools.js';
import { scrollBarStyles, globalBaseStyles } from './domtools.css.basestyles.js'; import { scrollBarStyles, globalBaseStyles } from './domtools.css.basestyles.js';
import { html, LitElement, css, unsafeCSS } from 'lit'; import { html, LitElement, css, unsafeCSS } from 'lit';
@ -40,8 +40,8 @@ export const styles = html`
* a basic setup for elements * a basic setup for elements
* makes sure everything is in check * makes sure everything is in check
*/ */
export const setup = async (elementArg?: LitElement): Promise<DomTools> => { export const setup = async (elementArg?: LitElement, optionsArg: IDomToolsContructorOptions = {}): Promise<DomTools> => {
const domTools = await DomTools.setupDomTools(); const domTools = await DomTools.setupDomTools(optionsArg);
if (elementArg) { if (elementArg) {
// lets do something with the element // lets do something with the element