Compare commits

...

8 Commits

Author SHA1 Message Date
284d2be0e3 1.0.23 2020-05-27 22:30:04 +00:00
dfb9175613 fix(core): update 2020-05-27 22:30:03 +00:00
16a213f536 1.0.22 2020-05-27 22:28:52 +00:00
9869b0c6aa fix(core): update 2020-05-27 22:28:52 +00:00
e63cb9669b 1.0.21 2020-05-27 22:06:06 +00:00
06766c6895 fix(core): update 2020-05-27 22:06:05 +00:00
48f1b02f0b 1.0.20 2020-05-27 21:59:28 +00:00
f41550fa22 fix(core): update 2020-05-27 21:59:28 +00:00
5 changed files with 35 additions and 19 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@designestate/dees-domtools", "name": "@designestate/dees-domtools",
"version": "1.0.19", "version": "1.0.23",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@designestate/dees-domtools", "name": "@designestate/dees-domtools",
"version": "1.0.19", "version": "1.0.23",
"private": false, "private": false,
"description": "tools to simplify complex css structures", "description": "tools to simplify complex css structures",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -7,22 +7,25 @@ export const phone = 340;
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone'; export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export const getEnvironment = async (): Promise<TViewport> => { export const getEnvironment = (): TViewport => {
const domToolsInstance = await DomTools.setupDomTools(); if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
return domToolsInstance.domToolsStatePart.getState().virtualViewport; return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
}; };
export const cssForTablet = async contentArg => { export const cssForTablet = async (contentArg) => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${tablet}px) { @media (max-width: ${tablet}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if ( } else if (
(await getEnvironment()) === 'tablet' || getEnvironment() === 'tablet' ||
(await getEnvironment()) === 'phablet' || getEnvironment() === 'phablet' ||
(await getEnvironment()) === 'phone' getEnvironment() === 'phone'
) { ) {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
@ -32,14 +35,14 @@ export const cssForTablet = async contentArg => {
} }
}; };
export const cssForPhablet = async contentArg => { export const cssForPhablet = async (contentArg) => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${phablet}px) { @media (max-width: ${phablet}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if ((await getEnvironment()) === 'phablet' || (await getEnvironment()) === 'phone') { } else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
${contentArg} ${contentArg}
@ -48,14 +51,14 @@ export const cssForPhablet = async contentArg => {
} }
}; };
export const cssForPhone = async contentArg => { export const cssForPhone = async (contentArg) => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${phone}px) { @media (max-width: ${phone}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if ((await getEnvironment()) === 'phone') { } else if (getEnvironment() === 'phone') {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
${contentArg} ${contentArg}

View File

@ -31,7 +31,15 @@ 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'
});
public actionSetVirtualViewport = this.domToolsStatePart.createAction<TViewport>(async (statePart, payload) => {
const currentState = statePart.getState();
currentState.virtualViewport = payload;
return currentState;
});
public domToolsReady = plugins.smartpromise.defer(); public domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer(); public domReady = plugins.smartpromise.defer();
@ -46,7 +54,9 @@ export class DomTools {
bodyElement: null bodyElement: null
}; };
constructor() {} constructor() {
}
public async setGlobalStyles(stylesText: string) { public async setGlobalStyles(stylesText: string) {
await this.domReady.promise; await this.domReady.promise;
@ -82,5 +92,7 @@ export class DomTools {
); );
} }
setVirtualViewport() {} setVirtualViewport(environmentArg: TViewport) {
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
}
} }

View File

@ -5,3 +5,4 @@ import * as breakpoints from './domtools.breakpoints';
import * as css from './domtools.css'; import * as css from './domtools.css';
export { css, breakpoints, elementBasic }; export { css, breakpoints, elementBasic };
export { DomTools } from './domtools.classes.domtools';