2020-05-11 00:36:58 +00:00
|
|
|
import { LitElement, property, html, customElement, TemplateResult } from 'lit-element';
|
|
|
|
|
2020-05-27 22:13:50 +00:00
|
|
|
import * as deesDomtools from '@designestate/dees-domtools';
|
|
|
|
|
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()
|
|
|
|
public selectedItem: TemplateResult | LitElement = WccDefaultElement as any;
|
|
|
|
|
|
|
|
@property()
|
|
|
|
public selectedInstance;
|
|
|
|
|
|
|
|
@property()
|
2020-05-27 22:13:50 +00:00
|
|
|
public selectedViewport: 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-05-24 19:37:43 +00:00
|
|
|
<wcc-properties .warning="${this.warning}" .selectedItem=${this.selectedItem} .selectedInstance=${this.selectedInstance} @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-05-24 19:37:43 +00:00
|
|
|
this.selectedItem = WccDefaultElement as any;
|
2020-05-11 00:36:58 +00:00
|
|
|
}
|
|
|
|
})()}
|
|
|
|
</wcc-frame>
|
|
|
|
${this.selectedViewport}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:13:50 +00:00
|
|
|
public async updateSlot() {
|
2020-05-11 00:36:58 +00:00
|
|
|
console.log('updateSlot');
|
|
|
|
const oldSelectedItem = this.selectedItem;
|
|
|
|
this.selectedItem = null;
|
2020-05-27 22:13:50 +00:00
|
|
|
const domtools = await deesDomtools.DomTools.setupDomTools();
|
|
|
|
domtools.setVirtualViewport(this.selectedViewport);
|
|
|
|
this.selectedItem = oldSelectedItem;
|
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
|
|
|
}
|