Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

feat(vault): enable universal drag-and-drop for text, links, web images, and files

Deepender25e7ba6c122cd0
diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts
index 48c9508..e9c96b7 100644
--- a/electron/main/ipc.ts
+++ b/electron/main/ipc.ts
@@ -5,7 +5,7 @@
* renderer calls them through the typed preload bridge, so a signature mismatch
* is a compile-time error rather than a runtime one.
*/
-import { app, ipcMain, clipboard, nativeImage, shell } from 'electron'
+import { app, ipcMain, clipboard, nativeImage, shell, net } from 'electron'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { execFile } from 'node:child_process'
@@ -21,6 +21,7 @@ import { startDragOut, resolveDragData } from './drag'
import { clipboardSignature } from '../clipboard/formats'
import type { ItemData, MergeResult } from '../../shared/types'
import { quitAndInstallUpdate, checkForUpdatesManual, startUpdateDownload, syncAutoUpdaterState } from './updater'
+import { createId } from '../store/ids'
/**
* Returns true if the current system clipboard content matches the given item data.
@@ -441,6 +442,48 @@ export function registerIpc(): void {
return getStore().toDto()
})
+ handle('item:add-data', async (data) => {
+ if (!data) return getStore().toDto()
+
+ if (data.kind === 'files' && data.paths && data.paths.length > 0) {
+ const result = addFiles(data.paths)
+ if (result.stacksCreated > 1) {
+ toast(`Split into ${result.stacksCreated} stacks (max 10 each)`, 'info')
+ }
+ return getStore().toDto()
+ }
+
+ if (data.kind === 'image' && (data as any).imageUrl) {
+ const imageUrl = (data as any).imageUrl
+ try {
+ let img = nativeImage.createFromDataURL(imageUrl)
+ if (img.isEmpty() && /^https?:\/\//i.test(imageUrl)) {
+ const res = await net.fetch(imageUrl)
+ if (res.ok) {
+ const arrayBuf = await res.arrayBuffer()
+ img = nativeImage.createFromBuffer(Buffer.from(arrayBuf))
+ }
+ }
+ if (!img.isEmpty()) {
+ const png = img.toPNG()
+ const size = img.getSize()
+ data.imageId = createId()
+ data.bytes = png.length
+ data.width = size.width
+ data.height = size.height
+ data.ext = 'png'
+ getStore().stageImageBytes(data.imageId, png)
+ }
+ } catch (err) {
+ console.error('[IPC] Failed to process dropped web image URL:', err)
+ }
+ }
+
+ getStore().add(data, loadSettings().historyLimit)
+ pushState.items()
+ return getStore().toDto()
+ })
+
handle('item:remove-subitem', (req) => {
const success = getStore().removeSubitem(req)
if (success) pushState.items()
diff --git a/electron/preload/index.ts b/electron/preload/index.ts
index 7a8ba2c..6430a8b 100644
--- a/electron/preload/index.ts
+++ b/electron/preload/index.ts
@@ -68,24 +68,71 @@ win.addEventListener('drop', (e: any) => {
return
}
- const files = e.dataTransfer?.files
- if (!files || !files.length) return
-
- const paths: string[] = []
- for (let i = 0; i < files.length; i++) {
- try {
- const p = webUtils.getPathForFile(files[i])
- if (p) paths.push(p)
- } catch {
- /* ignore unreadable entries */
+ const dt = e.dataTransfer
+ if (!dt) return
+
+ // 1. Local Files
+ const files = dt.files
+ if (files && files.length > 0) {
+ const paths: string[] = []
+ for (let i = 0; i < files.length; i++) {
+ try {
+ const p = webUtils.getPathForFile(files[i])
+ if (p) paths.push(p)
+ } catch {
+ /* ignore unreadable entries */
+ }
+ }
+ if (paths.length > 0) {
+ e.preventDefault()
+ invoke('item:add-files', paths).catch(console.error)
+ return
+ }
+ }
+
+ // 2. URLs / Web Links / Web Images
+ const uriList = dt.getData('text/uri-list') || dt.getData('URL')
+ const plainText = dt.getData('text/plain')?.trim()
+ const htmlText = dt.getData('text/html')?.trim()
+
+ if (uriList) {
+ const urls = uriList.split(/\r?\n/).map((u: string) => u.trim()).filter((u: string) => u && !u.startsWith('#'))
+ if (urls.length > 0) {
+ const url = urls[0]
+ const isImg = /\.(png|jpe?g|gif|webp|svg)(\?.*)?$/i.test(url) || /^data:image\//i.test(url)
+ e.preventDefault()
+ if (isImg) {
+ invoke('item:add-data', {
+ kind: 'image',
+ imageId: '',
+ width: 0,
+ height: 0,
+ bytes: 0,
+ imageUrl: url
+ } as any).catch(console.error)
+ } else {
+ invoke('item:add-data', {
+ kind: 'text',
+ text: url,
+ isUrl: true
+ }).catch(console.error)
+ }
+ return
}
}
- if (paths.length > 0) {
- // Fire and forget to the main process.
- // The main process will broadcast the new state back to React.
+ // 3. Plain Text / HTML
+ if (plainText) {
e.preventDefault()
- invoke('item:add-files', paths).catch(console.error)
+ const isUrl = /^(https?:\/\/|www\.)[^\s]+$/i.test(plainText)
+ const isColor = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(plainText)
+ invoke('item:add-data', {
+ kind: 'text',
+ text: plainText,
+ html: htmlText && htmlText !== plainText ? htmlText : undefined,
+ isUrl,
+ isColor
+ }).catch(console.error)
}
}, true)
@@ -105,6 +152,7 @@ const api = {
quitApp: () => invoke('app:quit'),
startDrag: (req: DragRequest) => send('item:start-drag', req),
addFiles: (paths: string[]) => invoke('item:add-files', paths),
+ addItemData: (data: import('../../shared/types').ItemData) => invoke('item:add-data', data),
removeSubitem: (req: import('../../shared/types').DragRequest) => invoke('item:remove-subitem', req),
mergeItems: (sourceId: string, targetId: string) => invoke('item:merge', sourceId, targetId),
splitItem: (req: import('../../shared/types').DragRequest) => invoke('item:split', req),
diff --git a/shared/bridge.ts b/shared/bridge.ts
index 316c1c0..dceb279 100644
--- a/shared/bridge.ts
+++ b/shared/bridge.ts
@@ -29,6 +29,7 @@ export interface EdgeApi {
*/
startDrag: (req: DragRequest) => void
addFiles: (paths: string[]) => Promise<import('./types').ClipboardItemDto[]>
+ addItemData: (data: import('./types').ItemData) => Promise<import('./types').ClipboardItemDto[]>
mergeItems: (sourceId: string, targetId: string) => Promise<import('./types').MergeResult>
splitItem: (req: import('./types').DragRequest) => Promise<boolean>
updateSettings: (patch: Partial<Settings>) => Promise<Settings>
diff --git a/shared/ipc.ts b/shared/ipc.ts
index 00d0c38..161bd41 100644
--- a/shared/ipc.ts
+++ b/shared/ipc.ts
@@ -47,6 +47,9 @@ export interface InvokeMap {
/** Add local file paths dragged into the shelf. */
'item:add-files': { args: [paths: string[]]; result: ClipboardItemDto[] }
+ /** Add arbitrary dropped item data (text, URL, web image, files) into the shelf. */
+ 'item:add-data': { args: [data: import('./types').ItemData]; result: ClipboardItemDto[] }
+
/** Merge an item into another. Returns why it failed (full / incompatible). */
'item:merge': { args: [sourceId: string, targetId: string]; result: MergeResult }
diff --git a/src/components/CopyIndicatorCurve.tsx b/src/components/CopyIndicatorCurve.tsx
index 9ec1d08..1c80978 100644
--- a/src/components/CopyIndicatorCurve.tsx
+++ b/src/components/CopyIndicatorCurve.tsx
@@ -28,7 +28,7 @@ export function TickIndicatorIcon({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
- filter: `drop-shadow(0 0 10px ${glowColor})`
+ filter: `drop-shadow(0 0 12px ${glowColor}) drop-shadow(0 0 4px ${glowColor})`
}}
>
{/* Floating & Breathing Motion Wrapper */}
@@ -55,24 +55,14 @@ export function TickIndicatorIcon({
style={{ display: 'block', overflow: 'visible' }}
>
<motion.path
- d="M9 22H15C20 22 22 20 22 15V9C22 4 20 2 15 2H9C4 2 2 4 2 9V15C2 20 4 22 9 22Z"
- stroke={fillColor}
- strokeWidth="2.5"
- strokeLinecap="round"
- strokeLinejoin="round"
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.25 }}
- />
- <motion.path
- d="M7.0 12.0L10.5 15.5L17.8 8.0"
+ d="M 5.0 12.5 L 9.5 17.0 L 22.8 2.8"
stroke={fillColor}
- strokeWidth="3.15"
+ strokeWidth="3.2"
strokeLinecap="round"
strokeLinejoin="round"
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.25, delay: 0.05 }}
+ initial={{ pathLength: 0, opacity: 0 }}
+ animate={{ pathLength: 1, opacity: 1 }}
+ transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}
/>
</svg>
</motion.div>
diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx
index 63a72c3..9a5d10b 100644
--- a/src/components/Panel.tsx
+++ b/src/components/Panel.tsx
@@ -162,17 +162,28 @@ export function Panel() {
}
}, [internalDragReq, setInternalDragReq, setDragActive])
- const hasFiles = (e: React.DragEvent) => e.dataTransfer.types.includes('Files')
+ const hasDragContent = (e: React.DragEvent) => {
+ const types = Array.from(e.dataTransfer?.types || [])
+ return (
+ types.includes('Files') ||
+ types.includes('text/uri-list') ||
+ types.includes('text/plain') ||
+ types.includes('text/html') ||
+ types.includes('URL')
+ )
+ }
const onDragEnter = (e: React.DragEvent) => {
- if (hasFiles(e)) {
+ if (hasDragContent(e)) {
e.preventDefault()
setDragActive(true)
}
}
const onDragOver = (e: React.DragEvent) => {
- if (hasFiles(e)) e.preventDefault()
+ if (hasDragContent(e)) {
+ e.preventDefault()
+ }
}
const onDragLeave = (e: React.DragEvent) => {
@@ -186,19 +197,11 @@ export function Panel() {
e.stopPropagation()
console.log('[Panel] onDrop internalDragReq=', internalDragReq)
if (internalDragReq) {
- e.preventDefault()
- // If it reaches here, it means it was dropped on the general panel background
- // (not on another item, which would have called stopPropagation).
- // Check if it's a subitem that should be split out:
if (internalDragReq.imageId || (internalDragReq.paths && internalDragReq.paths.length > 0)) {
console.log('[Panel] calling splitItem')
window.edge.splitItem(internalDragReq)
- } else {
- console.log('[Panel] internalDragReq has no subitem, not splitting')
}
setInternalDragReq(null)
- } else if (hasFiles(e)) {
- e.preventDefault()
}
setDragActive(false)
}