diff --git a/extensions/paste-as-plain-text/CHANGELOG.md b/extensions/paste-as-plain-text/CHANGELOG.md index 5c2513c062..c5966e041c 100644 --- a/extensions/paste-as-plain-text/CHANGELOG.md +++ b/extensions/paste-as-plain-text/CHANGELOG.md @@ -1,5 +1,10 @@ # Paste as Plain text Changelog +## [Optional No Prompt] - 2024-06-17 + +- Optional No Prompt after pasting +- Update metadata screenshot + ## [Paste as File] - 2024-06-17 - Paste as File, extract file path from the clipboard and paste it as file diff --git a/extensions/paste-as-plain-text/metadata/paste-as-plain-text-1.png b/extensions/paste-as-plain-text/metadata/paste-as-plain-text-1.png index c89492b4be..91d539e1f4 100644 Binary files a/extensions/paste-as-plain-text/metadata/paste-as-plain-text-1.png and b/extensions/paste-as-plain-text/metadata/paste-as-plain-text-1.png differ diff --git a/extensions/paste-as-plain-text/metadata/paste-as-plain-text-2.png b/extensions/paste-as-plain-text/metadata/paste-as-plain-text-2.png index ad231b5487..0b0ee3f62e 100644 Binary files a/extensions/paste-as-plain-text/metadata/paste-as-plain-text-2.png and b/extensions/paste-as-plain-text/metadata/paste-as-plain-text-2.png differ diff --git a/extensions/paste-as-plain-text/package-lock.json b/extensions/paste-as-plain-text/package-lock.json index 9957e405fd..136aa67c09 100644 --- a/extensions/paste-as-plain-text/package-lock.json +++ b/extensions/paste-as-plain-text/package-lock.json @@ -7,8 +7,7 @@ "name": "paste-as-plain-text", "license": "MIT", "dependencies": { - "@jcottam/html-metadata": "^2.0.2", - "@raycast/api": "^1.76.0", + "@raycast/api": "^1.77.1", "axios": "^1.7.2", "cheerio": "^1.0.0-rc.12", "fs-extra": "^11.2.0", @@ -116,14 +115,6 @@ "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, - "node_modules/@jcottam/html-metadata": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@jcottam/html-metadata/-/html-metadata-2.0.2.tgz", - "integrity": "sha512-bDdP73HmlCq4DLsvz/+jn2sh3msgDiMEi+4cyefeXx90iGzNGDRLpJCQygiQlNJkyW1U+EZJ1m0oLpSjnQe8BA==", - "dependencies": { - "cheerio": "^1.0.0-rc.12" - } - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -160,22 +151,22 @@ } }, "node_modules/@raycast/api": { - "version": "1.76.0", - "resolved": "https://registry.npmjs.org/@raycast/api/-/api-1.76.0.tgz", - "integrity": "sha512-MZUajhRw9d9WVKSnXus6z2HzF95/pl7vOtIRUiWaeK7UZLM34aOtuWN838X43Dik6hMMd5sKtFZJbdpWO3+XNQ==", + "version": "1.77.1", + "resolved": "https://registry.npmjs.org/@raycast/api/-/api-1.77.1.tgz", + "integrity": "sha512-voyrH1YFRb8ApMsWe1X72PkP+oUVaQVHbhWG8nQMlS5hyxXmXKcmaQ8sjG91+FL0prlrzOtPlcO2pOJA1g72WQ==", "hasInstallScript": true, "dependencies": { "@types/node": "^20.8.10", - "@types/react": "^18.2.27", - "react": "18.2.0" + "@types/react": "^18.3.3", + "react": "18.3.1" }, "bin": { "ray": "bin/ray" }, "peerDependencies": { "@types/node": "20.8.10", - "@types/react": "18.2.27", - "react-devtools": "4.28.4" + "@types/react": "18.3.3", + "react-devtools": "5.2.0" }, "peerDependenciesMeta": { "@types/node": { @@ -1711,9 +1702,9 @@ ] }, "node_modules/react": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", - "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "dependencies": { "loose-envify": "^1.1.0" }, @@ -2055,14 +2046,6 @@ "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, - "@jcottam/html-metadata": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@jcottam/html-metadata/-/html-metadata-2.0.2.tgz", - "integrity": "sha512-bDdP73HmlCq4DLsvz/+jn2sh3msgDiMEi+4cyefeXx90iGzNGDRLpJCQygiQlNJkyW1U+EZJ1m0oLpSjnQe8BA==", - "requires": { - "cheerio": "^1.0.0-rc.12" - } - }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2090,13 +2073,13 @@ } }, "@raycast/api": { - "version": "1.76.0", - "resolved": "https://registry.npmjs.org/@raycast/api/-/api-1.76.0.tgz", - "integrity": "sha512-MZUajhRw9d9WVKSnXus6z2HzF95/pl7vOtIRUiWaeK7UZLM34aOtuWN838X43Dik6hMMd5sKtFZJbdpWO3+XNQ==", + "version": "1.77.1", + "resolved": "https://registry.npmjs.org/@raycast/api/-/api-1.77.1.tgz", + "integrity": "sha512-voyrH1YFRb8ApMsWe1X72PkP+oUVaQVHbhWG8nQMlS5hyxXmXKcmaQ8sjG91+FL0prlrzOtPlcO2pOJA1g72WQ==", "requires": { "@types/node": "^20.8.10", - "@types/react": "^18.2.27", - "react": "18.2.0" + "@types/react": "^18.3.3", + "react": "18.3.1" } }, "@types/fs-extra": { @@ -3186,9 +3169,9 @@ "dev": true }, "react": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", - "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "requires": { "loose-envify": "^1.1.0" } diff --git a/extensions/paste-as-plain-text/package.json b/extensions/paste-as-plain-text/package.json index 5ed1c2e044..519541668b 100644 --- a/extensions/paste-as-plain-text/package.json +++ b/extensions/paste-as-plain-text/package.json @@ -2,7 +2,7 @@ "$schema": "https://www.raycast.com/schemas/extension.json", "name": "paste-as-plain-text", "title": "Paste as Plain Text", - "description": "Paste text from the clipboard as any format you want.", + "description": "Paste text from the clipboard as any format.", "icon": "paste-icon.png", "author": "koinzhang", "contributors": [ @@ -69,6 +69,14 @@ "description": "Replace clipboard with pasted text after pasting", "required": false, "default": false + }, + { + "name": "showTips", + "label": "Show Tips", + "type": "checkbox", + "description": "Show tips after pasting", + "required": false, + "default": true } ], "commands": [ @@ -76,7 +84,7 @@ "name": "paste-as-plain-text", "title": "Paste as", "subtitle": "Plain Text", - "description": "Paste text from the clipboard as any format you want.", + "description": "Paste text from the clipboard as any format.", "mode": "no-view", "arguments": [ { @@ -117,7 +125,7 @@ } ], "dependencies": { - "@raycast/api": "^1.76.0", + "@raycast/api": "^1.77.1", "axios": "^1.7.2", "cheerio": "^1.0.0-rc.12", "fs-extra": "^11.2.0", diff --git a/extensions/paste-as-plain-text/src/paste-as-plain-text.tsx b/extensions/paste-as-plain-text/src/paste-as-plain-text.tsx index a1e7add58c..45e196c02a 100644 --- a/extensions/paste-as-plain-text/src/paste-as-plain-text.tsx +++ b/extensions/paste-as-plain-text/src/paste-as-plain-text.tsx @@ -1,5 +1,5 @@ -import { captureException, LaunchProps, showHUD } from "@raycast/api"; -import { getArgument, isEmpty } from "./utils/common-utils"; +import { captureException, LaunchProps, Toast } from "@raycast/api"; +import { getArgument, isEmpty, showCustomHUD } from "./utils/common-utils"; import { PasteFormat } from "./types/types"; import { pasteAs } from "./utils/paste-as-utils"; @@ -15,6 +15,6 @@ export default async (props: LaunchProps<{ arguments: PasteAsArguments }>) => { } catch (e) { captureException(e); console.error(e); - await showHUD("🚨 " + e); + await showCustomHUD({ title: String(e), style: Toast.Style.Failure }); } }; diff --git a/extensions/paste-as-plain-text/src/types/types.ts b/extensions/paste-as-plain-text/src/types/types.ts index 869a2776b1..b645cf10fa 100644 --- a/extensions/paste-as-plain-text/src/types/types.ts +++ b/extensions/paste-as-plain-text/src/types/types.ts @@ -6,9 +6,10 @@ interface Preferences { autoFetchTitle: boolean; cleanLineBreaks: boolean; replaceClipboard: boolean; + showTips: boolean; } -export const { trimStart, trimEnd, autoFetchTitle, cleanLineBreaks, replaceClipboard } = +export const { trimStart, trimEnd, autoFetchTitle, cleanLineBreaks, replaceClipboard, showTips } = getPreferenceValues(); export enum PasteFormat { diff --git a/extensions/paste-as-plain-text/src/utils/common-utils.ts b/extensions/paste-as-plain-text/src/utils/common-utils.ts index 4109607fad..feafe65c56 100644 --- a/extensions/paste-as-plain-text/src/utils/common-utils.ts +++ b/extensions/paste-as-plain-text/src/utils/common-utils.ts @@ -1,5 +1,5 @@ -import { cleanLineBreaks, trimEnd, trimStart } from "../types/types"; -import { Cache } from "@raycast/api"; +import { cleanLineBreaks, showTips, trimEnd, trimStart } from "../types/types"; +import { Cache, showHUD, showToast, Toast } from "@raycast/api"; import axios from "axios"; import cheerio from "cheerio"; @@ -87,10 +87,23 @@ export async function fetchTitle(url: string) { const response = await axios.get(url); const html = response.data; const $ = cheerio.load(html); - const title = $("title").text(); - return title; + return $("title").text(); } catch (error) { console.error("Error fetching title:", error); return ""; } } + +export const showCustomHUD = (options: Toast.Options) => { + if (options.style && options.style === Toast.Style.Failure) { + // failure should always show toast + return showToast(options); + } else if (showTips) { + // success or animated should show HUD + if (options.style && options.style === Toast.Style.Animated) { + return showToast(options); + } else { + return showHUD(options.title); + } + } +}; diff --git a/extensions/paste-as-plain-text/src/utils/paste-as-utils.ts b/extensions/paste-as-plain-text/src/utils/paste-as-utils.ts index d76d600b45..ef416a8f2e 100644 --- a/extensions/paste-as-plain-text/src/utils/paste-as-utils.ts +++ b/extensions/paste-as-plain-text/src/utils/paste-as-utils.ts @@ -1,5 +1,5 @@ -import { Clipboard, closeMainWindow, showHUD, updateCommandMetadata } from "@raycast/api"; -import { extractNumber, extractUrl, fetchTitle, isEmpty, transform } from "./common-utils"; +import { Clipboard, closeMainWindow, Toast, updateCommandMetadata } from "@raycast/api"; +import { extractNumber, extractUrl, fetchTitle, isEmpty, showCustomHUD, transform } from "./common-utils"; import { autoFetchTitle, PasteFormat, replaceClipboard } from "../types/types"; import { isJSON, isURL } from "validator"; import fse from "fs-extra"; @@ -7,9 +7,10 @@ import { fileURLToPath } from "node:url"; export async function pasteAs(advancedPasteFormat: string) { await closeMainWindow(); + await showCustomHUD({ title: "Pasting...", style: Toast.Style.Animated }); const clipboardText = await Clipboard.readText(); if (!clipboardText || isEmpty(clipboardText)) { - await showHUD("️🚨 No content in clipboard"); + await showCustomHUD({ title: "No content in clipboard", style: Toast.Style.Failure }); return; } @@ -50,13 +51,10 @@ export async function pasteAs(advancedPasteFormat: string) { } case PasteFormat.File: { const { file } = await Clipboard.read(); - console.log("file " + file); const oldPasteStr = pasteStr; if (file) { pasteStr = file; } - console.log("oldPasteStr " + oldPasteStr); - try { pasteStr = fileURLToPath(pasteStr); } catch (e) { @@ -64,8 +62,7 @@ export async function pasteAs(advancedPasteFormat: string) { } if (fse.pathExistsSync(pasteStr)) { - console.log("pasteStr " + pasteStr); - realPasteFormatIcon = "📃"; + realPasteFormatIcon = "📄"; realPasteFormat = PasteFormat.File; isPasteAsFile = true; } else { @@ -114,7 +111,7 @@ export async function pasteAs(advancedPasteFormat: string) { } } - await showHUD(`${realPasteFormatIcon} Paste as ${realPasteFormat}`); + await showCustomHUD({ title: `${realPasteFormatIcon} Paste as ${realPasteFormat}` }); await updateCommandMetadata({ subtitle: isEmpty(advancedPasteFormat) ? PasteFormat.PLAIN_TEXT : advancedPasteFormat, });