From f31f9ed5ebdbd82045a0d8317b270aba28d4e8b5 Mon Sep 17 00:00:00 2001 From: "JLDiaz (m)" Date: Wed, 13 May 2026 21:38:18 +0200 Subject: [PATCH] Fix validator errors and bump to 1.1.1 --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 30 +++++++++--------------------- styles.css | 24 ++++++++++++++++++++++++ versions.json | 1 + 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/manifest.json b/manifest.json index 683a050..f3fb62b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "copy-text-protocol", "name": "Copy Text Protocol", - "version": "1.1.0", + "version": "1.1.1", "minAppVersion": "0.15.0", "description": "Adds support for copying text to the clipboard using a custom protocol.", "author": "jldiaz", diff --git a/package.json b/package.json index 528e1b8..b487f0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "copy-text-protocol", - "version": "1.1.0", + "version": "1.1.1", "description": "A plugin that adds support for copying text via a custom protocol.", "main": "main.js", "type": "module", diff --git a/src/main.ts b/src/main.ts index 2a25ccd..ca543ab 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,25 +9,16 @@ import { } from '@codemirror/view'; import { RangeSetBuilder } from '@codemirror/state'; import { syntaxTree } from '@codemirror/language'; +import { SyntaxNodeRef } from '@lezer/common'; class CopyIconWidget extends WidgetType { constructor(private textToCopy: string) { super(); } toDOM(): HTMLElement { - const span = document.createElement('span'); + const span = activeDocument.createElement('span'); span.className = 'copy-protocol-icon'; - span.style.cursor = 'copy'; - span.style.display = 'inline-flex'; - span.style.marginLeft = '5px'; - span.style.verticalAlign = 'middle'; - span.style.opacity = '0.8'; setIcon(span, 'copy'); - const svg = span.querySelector('svg'); - if (svg) { - svg.style.width = '0.85em'; - svg.style.height = '0.85em'; - } span.onclick = async (e) => { e.preventDefault(); @@ -35,16 +26,13 @@ class CopyIconWidget extends WidgetType { try { await navigator.clipboard.writeText(this.textToCopy); new Notice('Copied to clipboard!'); - span.style.transform = 'scale(1.2)'; - setTimeout(() => span.style.transform = 'scale(1)', 200); - } catch (err) { + span.addClass('is-clicked'); + window.setTimeout(() => span.removeClass('is-clicked'), 200); + } catch { new Notice('Failed to copy.'); } }; - span.onmouseenter = () => span.style.opacity = '1'; - span.onmouseleave = () => span.style.opacity = '0.8'; - return span; } @@ -73,7 +61,7 @@ const copyLinkPlugin = ViewPlugin.fromClass( tree.iterate({ from, to, - enter(node: any) { + enter(node: SyntaxNodeRef) { if (!node.name.includes('string_url')) return; const urlText = view.state.doc.sliceString(node.from, node.to); if (!urlText.includes('obsidian://copy')) return; @@ -90,11 +78,11 @@ const copyLinkPlugin = ViewPlugin.fromClass( if (!textToCopy) return; - let labelNode = null; + let labelNode: SyntaxNodeRef | null = null; let curr = node.node.prevSibling; for (let i = 0; i < 6 && curr; i++) { if (curr.name.includes('link') && !curr.name.includes('formatting')) { - labelNode = curr; + labelNode = curr as unknown as SyntaxNodeRef; break; } curr = curr.prevSibling; @@ -111,7 +99,7 @@ const copyLinkPlugin = ViewPlugin.fromClass( if (!isEditing) { builder.add(labelNode.to, labelNode.to, Decoration.widget({ - widget: new CopyIconWidget(textToCopy as any), + widget: new CopyIconWidget(textToCopy), side: 1 })); } diff --git a/styles.css b/styles.css index 6fe7df7..7b9050b 100644 --- a/styles.css +++ b/styles.css @@ -48,3 +48,27 @@ a[href^="obsidian://copy"]:hover::after { a[href^="obsidian://copy"]:hover { cursor: copy !important; } + +/* ── Widget Styles (Live Preview) ── */ + +.copy-protocol-icon { + cursor: copy; + display: inline-flex; + margin-left: 5px; + vertical-align: middle; + opacity: 0.8; + transition: transform 0.1s ease-out, opacity 0.1s ease-out; +} + +.copy-protocol-icon:hover { + opacity: 1; +} + +.copy-protocol-icon svg { + width: 0.85em; + height: 0.85em; +} + +.copy-protocol-icon.is-clicked { + transform: scale(1.2); +} diff --git a/versions.json b/versions.json index e789ec5..197d03a 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "1.1.1": "0.15.0", "1.1.0": "0.15.0", "1.0.1": "0.15.0", "1.0.0": "0.15.0"