From 84d4836daae224085069747e47d654a82185f6e5 Mon Sep 17 00:00:00 2001 From: bat Date: Fri, 26 May 2023 06:59:21 +0000 Subject: [PATCH 1/3] Index templates --- components/page-actions.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/components/page-actions.js b/components/page-actions.js index 76d31d2..4df7c09 100644 --- a/components/page-actions.js +++ b/components/page-actions.js @@ -268,6 +268,7 @@ export class PageActions extends HTMLElement { settingsData, dir, otherDir ) } + this.applyTemplateSettings() dialog.close() this.dispatchEvent(new CustomEvent( 'settings-change', {bubbles: true, composed: true} @@ -336,6 +337,31 @@ export class PageActions extends HTMLElement { } } + applyTemplateSettings() { + const templates = {} + for (const key of this.storage.keys()) { + try { + if (key.startsWith('settings/page:')) { + const data = JSON.parse( + this.storage.getItem(key) + ) + if (data.template) { + const name = key.slice( + 'settings/page:'.length + ) + settings[name] = {name} + } + } + } catch (err) { + // do nothing + } + } + this.storage.setItem( + 'settings:templates', + JSON.stringify({templates}), + ) + } + get language() { return this._language } From a333dcd9f101ec162e52e2d2b0a177d135b6a5ca Mon Sep 17 00:00:00 2001 From: bat Date: Sun, 28 May 2023 06:58:53 +0000 Subject: [PATCH 2/3] Create from template --- components/header.js | 36 +++++++++++++++++++++++++++++++----- components/page-actions.js | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/header.js b/components/header.js index 9a2d77c..e405b96 100644 --- a/components/header.js +++ b/components/header.js @@ -254,6 +254,22 @@ export class Header extends HTMLElement { return this.editing ? this.icons.check : this.icons.edit } + getTemplates() { + const text = this.storage.getItem( + 'settings:templates' + ) + if (text ?? undefined !== undefined) { + const data = JSON.parse(text) + return Object.entries( + data.templates + ).map(([id, data]) => ( + {...data, id} + )) + } else { + return [] + } + } + addPage() { const dialog = document.createElement('m-dialog') this.dialogWrap.replaceChildren(dialog) @@ -269,6 +285,13 @@ export class Header extends HTMLElement { el.innerText = this.text[value] return el })) + const templates = this.getTemplates() + select.append(...templates.map(t => { + const el = document.createElement('option') + el.value = t.id + el.innerText = t.name + return el + })) select.value = 'htmlCss' input.addEventListener('input', e => { const ext = e.target.value.match(/\.\w+$/) @@ -295,10 +318,9 @@ export class Header extends HTMLElement { } return } - const value = ( - select.value === 'singleFile' ? - '' : - JSON.stringify({ + let value + if (select.value === 'htmlCss') { + value = JSON.stringify({ type: 'm-file-group', files: [ { @@ -311,7 +333,11 @@ export class Header extends HTMLElement { }, ], }) - ) + } else { + value = this.storage.getItem( + select.value + ) ?? '' + } this.storage.setItem(newPath, value) this.storage.setItem( 'settings/page:' + newPath, '{}' diff --git a/components/page-actions.js b/components/page-actions.js index 4df7c09..451b0e2 100644 --- a/components/page-actions.js +++ b/components/page-actions.js @@ -349,7 +349,7 @@ export class PageActions extends HTMLElement { const name = key.slice( 'settings/page:'.length ) - settings[name] = {name} + templates[name] = {name} } } } catch (err) { From b212e91413f47696cec311a05db8451b8726091b Mon Sep 17 00:00:00 2001 From: bat Date: Mon, 29 May 2023 06:24:07 +0000 Subject: [PATCH 3/3] bump --- sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw.js b/sw.js index ba86bb4..178ee22 100644 --- a/sw.js +++ b/sw.js @@ -25,7 +25,7 @@ async function initCache() { '/settings/connections.js', '/settings/connection-edit.js', '/editor-lib-codemirror/codemirror-bundle.js', - '/storage/storage.js', //1 + '/storage/storage.js', //2 ]) }