fix(core): update

This commit is contained in:
2020-05-27 21:15:38 +00:00
parent fb36c641a9
commit 0ed59e850e
10 changed files with 73 additions and 51 deletions

View File

@ -1,24 +1,29 @@
import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240;
export const tablet = 700;
export const phablet = 500;
export const phone = 340;
export type TEnvironment = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
let environment: TEnvironment = 'native';
export const setEnvironment = envArg => {
environment = envArg;
export const getEnvironment = async (): Promise<TViewport> => {
const domToolsInstance = await DomTools.setupDomTools();
return domToolsInstance.domToolsStatePart.getState().virtualViewport;
};
export const cssForTablet = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
export const cssForTablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
} else if (environment === 'tablet' || environment === 'phablet' || environment === 'phone') {
} else if (
(await getEnvironment()) === 'tablet' ||
(await getEnvironment()) === 'phablet' ||
(await getEnvironment()) === 'phone'
) {
return `
@media (min-width: 0px) {
${contentArg}
@ -27,14 +32,14 @@ export const cssForTablet = (contentArg) => {
}
};
export const cssForPhablet = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
export const cssForPhablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
} else if (environment === 'phablet' || environment === 'phone') {
} else if ((await getEnvironment()) === 'phablet' || (await getEnvironment()) === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
@ -43,14 +48,14 @@ export const cssForPhablet = (contentArg) => {
}
};
export const cssForPhone = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
export const cssForPhone = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
} else if (environment === 'phone') {
} else if ((await getEnvironment()) === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}

View File

@ -1,6 +1,11 @@
import * as plugins from './domtools.plugins';
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
import { TViewport } from './domtools.breakpoints';
export interface IDomToolsState {
virtualViewport: TViewport;
}
export class DomTools {
public static async setupDomTools() {
@ -26,6 +31,7 @@ export class DomTools {
}
public smartstate = new plugins.smartstate.Smartstate();
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools');
public domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer();
@ -37,9 +43,11 @@ export class DomTools {
bodyElement: HTMLElement;
} = {
headElement: null,
bodyElement: null,
bodyElement: null
};
constructor() {}
public async setGlobalStyles(stylesText: string) {
await this.domReady.promise;
const styleElement = document.createElement('style');
@ -57,18 +65,22 @@ export class DomTools {
*/
public async runOnce<T>(identifierArg: string, funcArg: () => Promise<T>) {
const runningId = `${identifierArg}+runningCheck`;
if(!this.runOnceTrackerStringMap.checkString(identifierArg)) {
if (!this.runOnceTrackerStringMap.checkString(identifierArg)) {
this.runOnceTrackerStringMap.addString(identifierArg);
this.runOnceTrackerStringMap.addString(runningId);
const result = await funcArg();
this.runOnceResultMap.addToMap(identifierArg, result);
this.runOnceTrackerStringMap.removeString(runningId);
}
return await this.runOnceTrackerStringMap.registerUntilTrue(stringMap => {
return !stringMap.includes(runningId);
}, () => {
return this.runOnceResultMap.getByKey(identifierArg);
});
return await this.runOnceTrackerStringMap.registerUntilTrue(
stringMap => {
return !stringMap.includes(runningId);
},
() => {
return this.runOnceResultMap.getByKey(identifierArg);
}
);
}
}
setVirtualViewport() {}
}

View File

@ -1 +1 @@
import * as plugins from './domtools.plugins';
import * as plugins from './domtools.plugins';

View File

@ -3,4 +3,4 @@ export interface IDeesColorSet {
secondaryAccent: string;
primaryBackground: string;
secondaryBackground: string;
}
}

View File

@ -1,7 +1,8 @@
export const cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number) => {
let returnString = ``;
for (let i = 0; i < amountOfColumnsArg; i++) {
returnString += ` calc((100%/${amountOfColumnsArg}) - (${gapSizeArg * (amountOfColumnsArg - 1)}px/${amountOfColumnsArg}))`;
returnString += ` calc((100%/${amountOfColumnsArg}) - (${gapSizeArg *
(amountOfColumnsArg - 1)}px/${amountOfColumnsArg}))`;
}
return returnString;
};

View File

@ -1,7 +1,6 @@
import * as plugins from './domtools.plugins';
import { DomTools } from './domtools.classes.domtools';
import { html } from 'lit-element';
export const styles = html`
<style>
@ -12,7 +11,6 @@ export const styles = html`
</style>
`;
/**
* a basic setup for elements
* makes sure everything is in check

View File

@ -2,7 +2,4 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartstate from '@pushrocks/smartstate';
export {
smartpromise,
smartstate
};
export { smartpromise, smartstate };

View File

@ -4,8 +4,4 @@ import * as elementBasic from './domtools.elementbasic';
import * as breakpoints from './domtools.breakpoints';
import * as css from './domtools.css';
export {
css,
breakpoints,
elementBasic
};
export { css, breakpoints, elementBasic };