From 052dc03ff55dc71fc2a4665c02cb7ec020a8239f Mon Sep 17 00:00:00 2001 From: "you@example.com" Date: Mon, 22 Jul 2024 08:13:40 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=94=E3=83=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tray.js | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Tray.js b/src/Tray.js index 5582339..7bef861 100644 --- a/src/Tray.js +++ b/src/Tray.js @@ -1121,12 +1121,9 @@ formatCreatedTime() { copyTray() { - const copiedTray = new Tray(Date.now().toString(), this.name + ' (Copy)', [...this.labels]); - if (this.parent) { - this.parent.addChild(copiedTray); - const index = this.parent.children.indexOf(this); - this.parent.element.querySelector('.tray-content').insertBefore(copiedTray.element, this.element.nextSibling); - } + const serialized = serializeDOM(this) + serialized.id = generateUUID() + navigator.clipboard.writeText(JSON.stringify(serialized)) } renameTray() { @@ -1137,27 +1134,22 @@ formatCreatedTime() { } cutTray() { - if (this.id === '0') { - alert('Cannot cut root tray'); - return; - } - sessionStorage.setItem('cutTray', JSON.stringify(this.serialize())); - if (this.parent) { - this.parent.removeChild(this); - this.element.remove(); - } + const serialized = serializeDOM(this) + navigator.clipboard.writeText(JSON.stringify(serialized)) } pasteTray() { - const cutTrayData = sessionStorage.getItem('cutTray'); - if (cutTrayData) { - const trayData = JSON.parse(cutTrayData); - const newTray = Tray.deserialize(trayData); + const serialized = navigator.clipboard.readText().then(str => + {try{ + let newTray = deserializeDOM(JSON.parse(str)) this.addChild(newTray); - this.element.querySelector('.tray-content').appendChild(newTray.element); - sessionStorage.removeItem('cutTray'); + }catch{ + const texts = str.split('\n').filter(line => line.trim() !== ''); + const trays = texts.map(text => new Tray(this.id,generateUUID(),text)); + trays.map(t => this.addChild(t)) } - } + }) +}