dees-wcctools/ts_web/elements/wcc-dashboard.ts

111 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-05-11 00:36:58 +00:00
import { LitElement, property, html, customElement, TemplateResult } from 'lit-element';
2020-06-01 15:07:13 +00:00
import * as plugins from '../wcctools.plugins';
2020-05-27 22:13:50 +00:00
2020-05-11 00:36:58 +00:00
import { WccDefaultElement } from './wcc-defaultelement';
// wcc tools
import './wcc-frame';
import './wcc-sidebar';
import './wcc-properties';
@customElement('wcc-dashboard')
export class WccDashboard extends LitElement {
@property()
2020-06-01 13:18:51 +00:00
public selectedItem: TemplateResult | LitElement;
2020-05-11 00:36:58 +00:00
@property()
2020-06-01 15:07:13 +00:00
public selectedViewport: plugins.deesDomtools.breakpoints.TViewport = 'desktop';
2020-05-11 00:36:58 +00:00
@property()
2020-05-23 14:00:49 +00:00
public pages: { [key: string]: TemplateResult } = {};
2020-05-11 00:36:58 +00:00
@property()
2020-05-23 14:00:49 +00:00
public elements: { [key: string]: LitElement } = {};
2020-05-11 00:36:58 +00:00
2020-05-24 19:37:43 +00:00
@property()
public warning: string = null;
2020-05-23 14:00:49 +00:00
constructor(elementsArg?: { [key: string]: LitElement }, pagesArg?: { [key: string]: TemplateResult }) {
2020-05-11 00:36:58 +00:00
super();
2020-05-23 14:00:49 +00:00
if (elementsArg) {
this.elements = elementsArg;
}
if (pagesArg) {
this.pages = pagesArg;
}
2020-05-11 00:36:58 +00:00
}
public render(): TemplateResult {
return html`
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
:host {
font-family: 'Roboto', sans-serif;
background: #fcfcfc;
display: block;
box-sizing: border-box;
}
:host([hidden]) {
display: none;
}
</style>
<wcc-sidebar .pages=${this.pages} .elements=${this.elements} @selectedItem=${eventArg => {
this.selectedItem = eventArg.detail;
}}></wcc-sidebar>
2020-06-01 13:18:51 +00:00
<wcc-properties .warning="${this.warning}" .selectedItem=${this.selectedItem} @selectedViewport=${eventArg => {this.selectedViewport = eventArg.detail; this.updateSlot();}}></wcc-properties>
2020-05-11 00:36:58 +00:00
<wcc-frame id="wccFrame" viewport=${this.selectedViewport}>
${(() => {
if (this.selectedItem instanceof TemplateResult) {
return this.selectedItem;
} else if (this.selectedItem) {
console.log(this.selectedItem);
const anonItem: any = this.selectedItem;
2020-05-24 19:37:43 +00:00
if (!anonItem.demo) {
this.setWarning(`component ${anonItem.name} does not expose a demo property.`);
return;
2020-05-11 00:36:58 +00:00
}
2020-05-24 19:37:43 +00:00
if (!(typeof anonItem.demo === 'function')) {
this.setWarning(`component ${anonItem.name} has demo property, but it is not of type function`);
return;
}
this.setWarning(null);
return html`${anonItem.demo()}`;
2020-05-11 00:36:58 +00:00
} else {
2020-06-01 13:18:51 +00:00
this.updateSlot();
2020-05-11 00:36:58 +00:00
}
})()}
</wcc-frame>
`;
}
2020-06-01 15:56:32 +00:00
private currentlyUpdating: boolean = false;
2020-05-27 22:13:50 +00:00
public async updateSlot() {
2020-06-01 15:56:32 +00:00
if (this.currentlyUpdating) {
return;
}
this.currentlyUpdating = true;
!this.selectedItem ? this.selectedItem = WccDefaultElement as any : null;
const localSelectedItem = this.selectedItem;
this.selectedItem = null;
2020-05-11 00:36:58 +00:00
console.log('updateSlot');
2020-06-01 15:07:13 +00:00
const domtools = await plugins.deesDomtools.DomTools.setupDomTools();
2020-05-27 22:13:50 +00:00
domtools.setVirtualViewport(this.selectedViewport);
2020-06-01 15:56:32 +00:00
await super.performUpdate();
this.selectedItem = localSelectedItem;
await super.performUpdate();
this.currentlyUpdating = false;
2020-05-11 00:36:58 +00:00
}
2020-05-24 19:37:43 +00:00
public setWarning(warningTextArg: string) {
if (this.warning !== warningTextArg) {
console.log(warningTextArg);
this.warning = warningTextArg;
setTimeout(() => {
super.performUpdate();
}, 0);
}
}
2020-05-11 00:36:58 +00:00
}