diff --git a/components/header.js b/components/header.js index 04ff05e..1028520 100644 --- a/components/header.js +++ b/components/header.js @@ -21,6 +21,7 @@ export class Header extends HTMLElement { textEn = { download: 'Download', rename: 'Move/Rename', + duplicate: 'Duplicate', delete: 'Delete', confirmDelete: f => ( `Are you sure you want to delete ${f}?` @@ -36,6 +37,7 @@ export class Header extends HTMLElement { textEs = { download: 'Descargar', rename: 'Mover/Renombrar', + duplicate: 'Duplicar', delete: 'Borrar', confirmDelete: f => ( `¿Desea borrar ${f}?` @@ -253,6 +255,45 @@ export class Header extends HTMLElement { dialog.footerEl.appendChild(bGroup) dialog.open() }) + this.pageMenu.add(this.text.duplicate, () => { + const dialog = document.createElement( + 'm-dialog' + ) + this.dialogWrap.replaceChildren(dialog) + const input = document.createElement('input') + input.value = this.path + input.style.minWidth = '300px' + dialog.bodyEl.appendChild(input) + let errorEl + const bGroup = document.createElement( + 'm-forms-button-group' + ) + bGroup.addPrimary(this.text.duplicate, () => { + const newPath = input.value + const v = localStorage.getItem(newPath) + if (v !== null || newPath === this.path) { + if (!errorEl) { + errorEl = document.createElement('p') + errorEl.style.color = 'red' + const errText = this.text.alreadyExists + errorEl.innerText = errText + dialog.bodyEl.appendChild(errorEl) + } + return + } + localStorage.setItem( + newPath, + localStorage.getItem(this.path) + ) + dialog.close() + location.hash = newPath + }) + bGroup.addCancel(this.text.cancel, () => { + dialog.close() + }) + dialog.footerEl.appendChild(bGroup) + dialog.open() + }) this.pageMenu.add(this.text.delete, () => { const dialog = document.createElement( 'm-dialog' diff --git a/sw.js b/sw.js index 15ff0a6..e3804c0 100644 --- a/sw.js +++ b/sw.js @@ -17,7 +17,7 @@ async function initCache() { '/loader/builder.js', '/loader/editor-build.js', '/menu/dropdown.js', - ]) //2 + ]) //3 } self.addEventListener("install", event => {