From c678ace88b0ad59414597f3561a6db8d848115d6 Mon Sep 17 00:00:00 2001 From: bat Date: Wed, 29 Mar 2023 20:17:13 +0000 Subject: [PATCH] initialize file names and data --- index.html | 60 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 3c700c5..8201026 100644 --- a/index.html +++ b/index.html @@ -51,20 +51,21 @@ class FileGroup extends HTMLElement { addFile({name, data} = {}) { const el = document.createElement('m-file-view') - if (el.name !== undefined) { + if (name !== undefined) { el.name = name } - if (el.name !== undefined) { + if (data !== undefined) { el.data = data } this.contentEl.appendChild(el) + return el } } class FileView extends HTMLElement { icons = { menu: ` - + `, @@ -83,6 +84,14 @@ class FileView extends HTMLElement { this.contentEl.classList.add('content') this.shadowRoot.appendChild(this.headerEl) this.shadowRoot.appendChild(this.contentEl) + this.nameEl = document.createElement('input') + this.nameEl.classList.add('name') + this.headerEl.appendChild(this.nameEl) + this.editEl = document.createElement('m-text-edit') + this.contentEl.appendChild(this.editEl) + this.menuEl = document.createElement('button') + this.menuEl.innerHTML = this.icons.menu + this.headerEl.appendChild(this.menuEl) } connectedCallback() { @@ -121,16 +130,28 @@ class FileView extends HTMLElement { flex-direction: column; align-items: stretch; } + svg { + height: 20px; + width: 20px; + } ` this.shadowRoot.appendChild(style) - this.nameEl = document.createElement('input') - this.nameEl.classList.add('name') - this.headerEl.appendChild(this.nameEl) - this.editEl = document.createElement('m-text-edit') - this.contentEl.appendChild(this.editEl) - this.menuEl = document.createElement('button') - this.menuEl.innerHTML = this.icons.menu - this.headerEl.appendChild(this.menuEl) + } + + set name(name) { + this.nameEl.value = name + } + + get name() { + return this.nameEl.value + } + + set data(data) { + this.editEl.value = data + } + + get data() { + return this.editEl.value } } @@ -182,6 +203,14 @@ class TextEdit extends HTMLElement { ` this.shadowRoot.appendChild(style) } + + set value(value) { + this.textEl.value = value + } + + get value() { + return this.textEl.value + } } customElements.define('m-file-group', FileGroup) @@ -190,6 +219,15 @@ customElements.define('m-text-edit', TextEdit) const fileGroup = document.createElement('m-file-group') +fileGroup.addFile({ + name: 'file-group.js', + data: 'code here' +}) +fileGroup.addFile({ + name: 'file-view.js', + data: 'code here' +}) + document.body.appendChild(fileGroup)