@design.estate/dees-wcctools 1.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,393 @@
1
+ import { DeesElement, property, html, customElement, type TemplateResult, state } from '@design.estate/dees-element';
2
+ import { WccDashboard } from './wcc-dashboard.js';
3
+
4
+ export type TPropertyType = 'String' | 'Number' | 'Boolean' | 'Object' | 'Enum' | 'Array';
5
+
6
+ export type TEnvironment = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
7
+ export type TTheme = 'bright' | 'dark';
8
+
9
+ let environment: TEnvironment = 'native';
10
+
11
+ export const setEnvironment = (envArg) => {
12
+ environment = envArg;
13
+ };
14
+
15
+ @customElement('wcc-properties')
16
+ export class WccProperties extends DeesElement {
17
+ @property({
18
+ type: WccDashboard
19
+ })
20
+ public dashboardRef: WccDashboard;
21
+
22
+ @property()
23
+ public selectedItem: (() => TemplateResult) | DeesElement;
24
+
25
+ @property()
26
+ public selectedViewport: TEnvironment = 'native';
27
+
28
+ @property()
29
+ public selectedTheme: TTheme = 'dark';
30
+
31
+ @property()
32
+ public warning: string = null;
33
+
34
+ @state()
35
+ propertyContent: TemplateResult[] = [];
36
+
37
+ public render(): TemplateResult {
38
+ return html`
39
+ <style>
40
+ :host {
41
+ font-family: 'Roboto', sans-serif;
42
+ box-sizing: border-box;
43
+ position: absolute;
44
+ left: 200px;
45
+ height: 100px;
46
+ bottom: 0px;
47
+ right: 0px;
48
+ overflow: hidden;
49
+ background: #111;
50
+ color: #fff;
51
+ }
52
+ .grid {
53
+ display: grid;
54
+ grid-template-columns: auto 150px 300px 70px;
55
+ }
56
+ .properties {
57
+ border-right: 1px solid #999;
58
+ height: 100px;
59
+ overflow-y: auto;
60
+ display: grid;
61
+ grid-template-columns: 33% 33% 33%;
62
+ }
63
+
64
+ .material-symbols-outlined {
65
+ font-family: 'Material Symbols Outlined';
66
+ font-weight: normal;
67
+ font-style: normal;
68
+ font-size: 24px; /* Preferred icon size */
69
+ display: inline-block;
70
+ line-height: 1;
71
+ text-transform: none;
72
+ letter-spacing: normal;
73
+ word-wrap: normal;
74
+ white-space: nowrap;
75
+ direction: ltr;
76
+ font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 48;
77
+ }
78
+
79
+ .properties .property {
80
+ padding: 5px;
81
+ background: #444;
82
+ border: 1px solid #000;
83
+ }
84
+
85
+ .properties input,
86
+ .properties select {
87
+ display: block;
88
+ width: 100%;
89
+ background: #333;
90
+ border: none;
91
+ color: #fff;
92
+ }
93
+
94
+ .viewportSelector,
95
+ .themeSelector {
96
+ user-select: none;
97
+ border-right: 1px solid #999;
98
+ }
99
+ .selectorButtons2 {
100
+ display: grid;
101
+ grid-template-columns: 50% 50%;
102
+ }
103
+ .selectorButtons4 {
104
+ display: grid;
105
+ grid-template-columns: 25% 25% 25% 25%;
106
+ }
107
+ .button {
108
+ padding: 10px;
109
+ text-align: center;
110
+ border: 1px solid #000;
111
+ transition: all 0.2s;
112
+ }
113
+ .button:hover {
114
+ cursor: pointer;
115
+ color: #333;
116
+ background: #fff;
117
+ }
118
+
119
+ .button.selected {
120
+ background: #455a64;
121
+ }
122
+
123
+ .button.selected:hover {
124
+ cursor: pointer;
125
+ color: #ffffff;
126
+ background: #455a64;
127
+ }
128
+
129
+ .panelheading {
130
+ padding: 5px;
131
+ font-weight: bold;
132
+ background: #444;
133
+ border: 1px solid #000;
134
+ }
135
+ .docs {
136
+ text-align: center;
137
+ line-height: 100px;
138
+ text-transform: uppercase;
139
+ }
140
+
141
+ .docs:hover {
142
+ cursor: pointer;
143
+ color: #333;
144
+ background: #fff;
145
+ }
146
+
147
+ .warning {
148
+ position: absolute;
149
+ background: #222;
150
+ color: #CCC;
151
+ top: 0px;
152
+ bottom: 0px;
153
+ left: 0px;
154
+ right: 520px;
155
+ text-align: center;
156
+ padding: 35px;
157
+ font-size: 25px;
158
+ }
159
+ </style>
160
+ <div class="grid">
161
+ <div class="properties">
162
+ <div class="panelheading">Properties</div>
163
+ ${this.propertyContent}
164
+ </div>
165
+ <div class="themeSelector">
166
+ <div class="panelheading">Theme</div>
167
+ <div class="selectorButtons2">
168
+ <div
169
+ class="button ${this.selectedTheme === 'dark' ? 'selected' : null}"
170
+ @click=${() => {
171
+ this.selectTheme('dark');
172
+ }}
173
+ >
174
+ Dark<br /><i class="material-symbols-outlined">brightness_3</i>
175
+ </div>
176
+ <div
177
+ class="button ${this.selectedTheme === 'bright' ? 'selected' : null}"
178
+ @click=${() => {
179
+ this.selectTheme('bright');
180
+ }}
181
+ >
182
+ Bright<br /><i class="material-symbols-outlined">flare</i>
183
+ </div>
184
+ </div>
185
+ </div>
186
+ <div class="viewportSelector">
187
+ <div class="panelheading">Viewport</div>
188
+ <div class="selectorButtons4">
189
+ <div
190
+ class="button ${this.selectedViewport === 'phone' ? 'selected' : null}"
191
+ @click=${() => {
192
+ this.selectViewport('phone');
193
+ }}
194
+ >
195
+ Phone<br /><i class="material-symbols-outlined">smartphone</i>
196
+ </div>
197
+ <div
198
+ class="button ${this.selectedViewport === 'phablet' ? 'selected' : null}"
199
+ @click=${() => {
200
+ this.selectViewport('phablet');
201
+ }}
202
+ >
203
+ Phablet<br /><i class="material-symbols-outlined">smartphone</i>
204
+ </div>
205
+ <div
206
+ class="button ${this.selectedViewport === 'tablet' ? 'selected' : null}"
207
+ @click=${() => {
208
+ this.selectViewport('tablet');
209
+ }}
210
+ >
211
+ Tablet<br /><i class="material-symbols-outlined">tablet</i>
212
+ </div>
213
+ <div
214
+ class="button ${this.selectedViewport === 'desktop' ||
215
+ this.selectedViewport === 'native'
216
+ ? 'selected'
217
+ : null}"
218
+ @click=${() => {
219
+ this.selectViewport('native');
220
+ }}
221
+ >
222
+ Desktop<br /><i class="material-symbols-outlined">desktop_windows</i>
223
+ </div>
224
+ </div>
225
+ </div>
226
+ <div class="docs">Docs</div>
227
+ </div>
228
+ ${this.warning ? html`<div class="warning">${this.warning}</div>` : null}
229
+ `;
230
+ }
231
+
232
+ public async createProperties() {
233
+ console.log('creating properties for:');
234
+ console.log(this.selectedItem);
235
+ const isEnumeration = (propertyArg): boolean => {
236
+ const keys = Object.keys(propertyArg.type);
237
+ const values = [];
238
+ for (const key of keys) {
239
+ let value = propertyArg.type[key];
240
+ if (typeof value === 'number') {
241
+ value = value.toString();
242
+ }
243
+ values.push(value);
244
+ }
245
+ for (const key of keys) {
246
+ if (values.indexOf(key) < 0) {
247
+ return false;
248
+ }
249
+ }
250
+ return true;
251
+ };
252
+ const getEnumValues = (propertyArg): any[] => {
253
+ console.log(JSON.stringify(propertyArg));
254
+ const enumValues: any[] = [];
255
+ Object.keys(propertyArg.type).forEach((valueArg: string) => {
256
+ enumValues.push(valueArg);
257
+ });
258
+ return enumValues;
259
+ };
260
+ const determinePropertyType = async (propertyArg: any): Promise<TPropertyType> => {
261
+ const typeName: any | undefined = propertyArg.type.name;
262
+ if (typeName) {
263
+ return typeName;
264
+ } else {
265
+ return Array.isArray(propertyArg)
266
+ ? 'Array'
267
+ : isEnumeration(propertyArg)
268
+ ? 'Enum'
269
+ : 'Object';
270
+ }
271
+ };
272
+ if (this.selectedItem && (this.selectedItem as any).demo) {
273
+ console.log(`Got Dees-Element for property evaluation.`);
274
+ const anonItem: any = this.selectedItem;
275
+ if (!anonItem) {
276
+ this.warning = 'no element selected';
277
+ return;
278
+ }
279
+ console.log(anonItem.elementProperties);
280
+ const wccFrame = await this.dashboardRef.wccFrame;
281
+ let firstFoundInstantiatedElement: HTMLElement;
282
+ for (const element of Array.from((await wccFrame.getViewportElement()).children)) {
283
+ if (element instanceof (this.selectedItem as any)) {
284
+ firstFoundInstantiatedElement = element as HTMLElement;
285
+ break;
286
+ }
287
+ }
288
+ if (!firstFoundInstantiatedElement) {
289
+ this.warning = `no first instantiated element found for >>${anonItem.name}<<`;
290
+ return;
291
+ }
292
+ const classProperties: Map<string, any> = anonItem.elementProperties;
293
+ if (!classProperties) {
294
+ this.warning = `selected element >>${anonItem.name}<< does not expose element properties`;
295
+ return;
296
+ }
297
+ this.warning = null;
298
+ const propertyArray: TemplateResult[] = [];
299
+ for (const key of classProperties.keys()) {
300
+ if (key === 'goBright' || key === 'domtools') {
301
+ continue;
302
+ }
303
+ const property = classProperties.get(key);
304
+ const propertyTypeString = await determinePropertyType(property);
305
+ propertyArray.push(
306
+ html`
307
+ <div class="property">
308
+ ${key} / ${propertyTypeString}<br />
309
+ ${(() => {
310
+ switch (propertyTypeString) {
311
+ case 'Boolean':
312
+ return html`<input
313
+ type="checkbox"
314
+ ?checked=${firstFoundInstantiatedElement[key]}
315
+ @input="${(eventArg: any) => {
316
+ firstFoundInstantiatedElement[key] = eventArg.target.checked;
317
+ }}"
318
+ />`;
319
+ case 'String':
320
+ return html`<input
321
+ type="text"
322
+ value=${firstFoundInstantiatedElement[key]}
323
+ @input="${(eventArg: any) => {
324
+ firstFoundInstantiatedElement[key] = eventArg.target.value;
325
+ }}"
326
+ />`;
327
+ case 'Number':
328
+ return html`<input
329
+ type="number"
330
+ value=${firstFoundInstantiatedElement[key]}
331
+ @input="${(eventArg: any) => {
332
+ firstFoundInstantiatedElement[key] = eventArg.target.value;
333
+ }}"
334
+ />`;
335
+ case 'Enum':
336
+ const enumValues: any[] = getEnumValues(property);
337
+ return html`<select
338
+ @change="${(eventArg: any) => {
339
+ firstFoundInstantiatedElement[key] = eventArg.target.value;
340
+ }}"
341
+ >
342
+ ${enumValues.map((valueArg) => {
343
+ return html`
344
+ <option
345
+ ?selected=${valueArg === firstFoundInstantiatedElement[key] ? true : false}
346
+ name="${valueArg}"
347
+ >
348
+ ${valueArg}
349
+ </option>
350
+ `;
351
+ })}
352
+ </select>`;
353
+ }
354
+ })()}
355
+ </div>
356
+ `
357
+ );
358
+ }
359
+ this.propertyContent = propertyArray;
360
+ } else {
361
+ console.log(`Cannot extract properties of ${(this.selectedItem as any)?.name}`);
362
+ this.warning = `You selected a page.`;
363
+ return null;
364
+ }
365
+ }
366
+
367
+ public selectTheme(themeArg: TTheme) {
368
+ this.selectedTheme = themeArg;
369
+ this.dispatchEvent(
370
+ new CustomEvent('selectedTheme', {
371
+ detail: themeArg,
372
+ })
373
+ );
374
+ console.log(this.dashboardRef.selectedType);
375
+ this.dashboardRef.buildUrl();
376
+ }
377
+
378
+ public async scheduleUpdate() {
379
+ await this.createProperties();
380
+ super.scheduleUpdate();
381
+ }
382
+
383
+ public selectViewport(viewport: TEnvironment) {
384
+ this.selectedViewport = viewport;
385
+ setEnvironment(viewport);
386
+ this.dispatchEvent(
387
+ new CustomEvent('selectedViewport', {
388
+ detail: viewport,
389
+ })
390
+ );
391
+ this.dashboardRef.buildUrl();
392
+ }
393
+ }
@@ -0,0 +1,192 @@
1
+ import * as plugins from '../wcctools.plugins.js';
2
+ import { DeesElement, property, html, customElement, type TemplateResult } from '@design.estate/dees-element';
3
+ import { WccDashboard } from './wcc-dashboard.js';
4
+
5
+ export type TElementType = 'element' | 'page';
6
+
7
+ @customElement('wcc-sidebar')
8
+ export class WccSidebar extends DeesElement {
9
+ @property({type: Array})
10
+ public websites: string[] = [];
11
+
12
+ @property({ attribute: false })
13
+ public selectedItem: DeesElement | (() => TemplateResult);
14
+
15
+ @property({ attribute: false })
16
+ public selectedType: TElementType;
17
+
18
+ @property()
19
+ public dashboardRef: WccDashboard;
20
+
21
+ public render(): TemplateResult {
22
+ return html`
23
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
24
+ <style>
25
+ :host {
26
+ display: block;
27
+ border-right: 1px solid #999;
28
+ font-family: 'Roboto', sans-serif;
29
+ box-sizing: border-box;
30
+ position: absolute;
31
+ left: 0px;
32
+ width: 200px;
33
+ top: 0px;
34
+ bottom: 0px;
35
+ overflow-y: scroll;
36
+ overflow-x: hidden;
37
+ background: #222;
38
+ color: #fff;
39
+ padding: 5px;
40
+ }
41
+
42
+ .material-symbols-outlined {
43
+ font-family: 'Material Symbols Outlined';
44
+ font-weight: normal;
45
+ font-style: normal;
46
+ font-size: 24px; /* Preferred icon size */
47
+ display: inline-block;
48
+ line-height: 1;
49
+ text-transform: none;
50
+ letter-spacing: normal;
51
+ word-wrap: normal;
52
+ white-space: nowrap;
53
+ direction: ltr;
54
+ font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 48;
55
+ }
56
+
57
+ .heading {
58
+ font-size: 24px;
59
+ text-align: center;
60
+ margin: 20px 5px 5px 5px;
61
+ }
62
+
63
+ .heading a {
64
+ text-decoration: none;
65
+ color: #fff;
66
+ }
67
+
68
+ .subheading {
69
+ text-align: center;
70
+ }
71
+ .selectOption {
72
+ position: relative;
73
+ line-height: 24px;
74
+ padding: 5px;
75
+ transition: all 0.2s;
76
+ display: grid;
77
+ grid-template-columns: 28px auto;
78
+ }
79
+ .selectOption:hover {
80
+ cursor: pointer;
81
+ padding: 5px;
82
+ color: #333;
83
+ background: #fff;
84
+ }
85
+
86
+ .selectOption.selected {
87
+ background: #455A64;;
88
+ }
89
+
90
+ .selectOption.selected:hover {
91
+ cursor: pointer;
92
+ color: #ffffff;
93
+ background: #455A64;
94
+ }
95
+
96
+ .selectOption .material-symbols-outlined {
97
+ color: #666;
98
+ display: block;
99
+ transition: all 0.2s;
100
+ }
101
+
102
+ .selectOption.selected .material-symbols-outlined {
103
+ color: #000;
104
+ }
105
+
106
+ .selectOption .text {
107
+ display: block;
108
+ word-wrap: break-word;
109
+ word-break: break-all;
110
+ max-width: 100%;
111
+ }
112
+
113
+
114
+ </style>
115
+ <div class="heading">
116
+ <a href="https://gitlab.com/designestate/dees-wcctools" target="_blank">wcctools</a>
117
+ </div>
118
+ <div class="subheading">
119
+ by Lossless GmbH
120
+ </div>
121
+ <div class="menu">
122
+ <h3>Live Websites</h3>
123
+ ${this.websites.map(website => {
124
+ return html`<div class="selectOption"><i class="material-symbols-outlined">ondemand_video</i><div class="text">${website}</div></div>`;
125
+ })}
126
+ <h3>Pages</h3>
127
+ ${(() => {
128
+ const pages = Object.keys(this.dashboardRef.pages);
129
+ return pages.map(pageName => {
130
+ const item = this.dashboardRef.pages[pageName];
131
+ return html`
132
+ <div
133
+ class="selectOption ${this.selectedItem === item ? 'selected' : null}"
134
+ @click=${async () => {
135
+ const domtools = await plugins.deesDomtools.DomTools.setupDomTools();
136
+ this.selectItem('page', pageName, item);
137
+ }}
138
+ >
139
+ <i class="material-symbols-outlined">insert_drive_file</i>
140
+ <div class="text">${pageName}</div>
141
+ </div>
142
+ `;
143
+ });
144
+ })()}
145
+ <h3>Elements</h3>
146
+ ${(() => {
147
+ const elements = Object.keys(this.dashboardRef.elements);
148
+ return elements.map(elementName => {
149
+ const item = this.dashboardRef.elements[elementName];
150
+ return html`
151
+ <div
152
+ class="selectOption ${this.selectedItem === item ? 'selected' : null}"
153
+ @click=${async () => {
154
+ const domtools = await plugins.deesDomtools.DomTools.setupDomTools();
155
+ this.selectItem('element', elementName, item);
156
+ }}
157
+ >
158
+ <i class="material-symbols-outlined">featured_video</i>
159
+ <div class="text">${elementName}</div>
160
+ </div>
161
+ `;
162
+ });
163
+ })()}
164
+ </menu>
165
+ `;
166
+ }
167
+
168
+ public selectItem(typeArg: TElementType, itemNameArg: string, itemArg: (() => TemplateResult) | DeesElement) {
169
+ console.log('selected item');
170
+ console.log(itemNameArg);
171
+ console.log(itemArg);
172
+ this.selectedItem = itemArg;
173
+ this.selectedType = typeArg;
174
+ this.dispatchEvent(
175
+ new CustomEvent('selectedType', {
176
+ detail: typeArg
177
+ })
178
+ );
179
+ this.dispatchEvent(
180
+ new CustomEvent('selectedItemName', {
181
+ detail: itemNameArg
182
+ })
183
+ );
184
+ this.dispatchEvent(
185
+ new CustomEvent('selectedItem', {
186
+ detail: itemArg
187
+ })
188
+ );
189
+
190
+ this.dashboardRef.buildUrl();
191
+ }
192
+ }
@@ -0,0 +1,19 @@
1
+ import { WccDashboard } from './elements/wcc-dashboard.js';
2
+ import { LitElement, type TemplateResult } from 'lit';
3
+
4
+ const setupWccTools = (elementsArg?: { [key: string]: LitElement }, pagesArg?: { [key: string]: () => TemplateResult }) => {
5
+ let hasRun = false;
6
+ const runWccToolsSetup = async () => {
7
+ if (document.readyState === 'complete' && !hasRun) {
8
+ hasRun = true;
9
+ const wccTools = new WccDashboard(elementsArg as any, pagesArg);
10
+ document.querySelector('body').append(wccTools);
11
+ }
12
+ };
13
+ document.addEventListener('readystatechange', runWccToolsSetup);
14
+ runWccToolsSetup();
15
+ };
16
+
17
+ export {
18
+ setupWccTools
19
+ };
@@ -0,0 +1,11 @@
1
+ import * as smartdelay from '@push.rocks/smartdelay';
2
+
3
+ export {
4
+ smartdelay
5
+ };
6
+
7
+ import * as deesDomtools from '@design.estate/dees-domtools';
8
+
9
+ export {
10
+ deesDomtools
11
+ };