diff --git a/package.json b/package.json index 9a6f9d4..47ed154 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "time-chain", - "version": "1.0.0", + "version": "1.1.0", "description": "timechain", "author": "Jaosn Tudisco", "license": "UNLICENSED", @@ -52,6 +52,7 @@ "nanoid": "^3.2.0", "pubsub-js": "^1.9.4", "riot": "^6.1.2", - "sanitize-html": "^2.6.1" + "sanitize-html": "^2.6.1", + "sweetalert2": "^11.4.8" } } diff --git a/src/lib/toast.js b/src/lib/toast.js new file mode 100644 index 0000000..584b747 --- /dev/null +++ b/src/lib/toast.js @@ -0,0 +1,15 @@ +import Swal from 'sweetalert2' + +const Toast = Swal.mixin({ + toast: true, + position: 'top-end', + showConfirmButton: false, + timer: 3000, + timerProgressBar: true, + didOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } +}); + +module.exports = {Toast}; \ No newline at end of file diff --git a/src/ui/timechain-input.riot b/src/ui/timechain-input.riot index 244a1f3..28918bc 100644 --- a/src/ui/timechain-input.riot +++ b/src/ui/timechain-input.riot @@ -126,8 +126,11 @@ break; }else if(t == 'image/png'){ isFile = true; - this.isIMAGE(e.clipboardData.items[i], 'image/png') + this.isIMAGE(e.clipboardData.items[i], 'image/png'); break; + }else if(t == 'image/gif'){ + isFile = true; + this.isIMAGE(e.clipboardData.items[i], 'image/gif'); } } diff --git a/src/ui/timechain-item-menu.riot b/src/ui/timechain-item-menu.riot new file mode 100644 index 0000000..ab30ce1 --- /dev/null +++ b/src/ui/timechain-item-menu.riot @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/src/ui/timechain-list.riot b/src/ui/timechain-list.riot index 4dc2f97..6778212 100644 --- a/src/ui/timechain-list.riot +++ b/src/ui/timechain-list.riot @@ -9,7 +9,7 @@
-
+
@@ -28,7 +28,7 @@
- +
@@ -49,6 +49,9 @@ import TimechainTag from './timechain-tag.riot' + import {dataURLtoBlob} from '../lib/blobconvert.js' + import {Toast} from '../lib/toast.js' + const { TimeChainDataSqliteRecord @@ -91,6 +94,7 @@ TR.find(search,null,100,0).then(records=>{ console.log("Records", records); + if(records) records.data.forEach(r=>r.iid=this.uid()); this.update({records:records.data,loading:false}); }).then(()=>{ this.processImages(); @@ -125,6 +129,52 @@ this.loadRecords({ tags:search }) + }, + + onContextMenu(e){ + const t = e.target.closest('.timechange-item'); + const id = t.dataset.iid; + const record = this.state.records.find(r=>r.iid==id); + console.log("Right click", id, record); + + if(!record) return; + + + if(record.mime && record.mime.includes('image/')){ + const b = dataURLtoBlob(record.content); + + console.log(b); + + const items = { [b.type]: b }; + const clipboardItem = new ClipboardItem(items); + navigator.clipboard.write([clipboardItem]).then(()=>{ + Toast.fire({ + icon: 'success', + title: 'Copied to clipboard' + }) + }); + + + }else if(record.mime && (record.mime == 'text/html' || record.mime == 'text/plain')){ + const t = record.mime; + const b = new Blob([record.content], {type:t}); + + console.log(t); + console.log(b); + + const data = [new ClipboardItem({ [t]: b })]; + navigator.clipboard.write(data).then(()=>{ + Toast.fire({ + icon: 'success', + title: 'Copied to clipboard' + }) + }); + + }else{ + alert("Can't copy"); + } + + } } diff --git a/start.js b/start.js index fbff7bf..60ddba8 100644 --- a/start.js +++ b/start.js @@ -3,7 +3,16 @@ import './src/css/tagify.scss' import App from './src/ui/app.riot' -import { component } from 'riot' +import { component, install } from 'riot' + +let id = 0 + +install(function(component) { + // all components will pass through here + component.uid = ()=>{ + return ++id; + } +}) window.debugging = true