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

View File

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