diff --git a/package.json b/package.json index 7a51058..b956398 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "class-variance-authority": "^0.5.2", "clsx": "^1.2.1", "cmdk": "^0.2.0", - "copy-to-clipboard": "^3.3.3", "dayjs": "^1.11.7", "jotai": "^2.1.0", "lodash": "^4.17.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index beb6f21..c341436 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,9 +43,6 @@ dependencies: cmdk: specifier: ^0.2.0 version: 0.2.0(@types/react@18.0.38)(react-dom@18.2.0)(react@18.2.0) - copy-to-clipboard: - specifier: ^3.3.3 - version: 3.3.3 dayjs: specifier: ^1.11.7 version: 1.11.7 diff --git a/src/components/DrawingCard.tsx b/src/components/DrawingCard.tsx index 92a618d..ed2cea1 100644 --- a/src/components/DrawingCard.tsx +++ b/src/components/DrawingCard.tsx @@ -1,16 +1,18 @@ -import React, { useState } from "react"; +import type { BlockEntity, PageEntity } from '@logseq/libs/dist/LSPlugin' +import { Trash2, Edit3, Tag, Image } from 'lucide-react' +import React, { useState } from 'react' + +import SVGComponent from '@/components/SVGComponent' import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, -} from "@/components/ui/context-menu"; -import { BlockEntity, type PageEntity } from "@logseq/libs/dist/LSPlugin"; -import { Trash2, Edit3, Tag, Image } from "lucide-react"; -import SVGComponent from "@/components/SVGComponent"; -import copy from "copy-to-clipboard"; -import { useToast } from "./ui/use-toast"; +} from '@/components/ui/context-menu' +import { copyToClipboard } from '@/lib/utils' + +import EditDrawingInfoModal, { EditTypeEnum } from './EditDrawingInfoModal' import { AlertDialog, AlertDialogAction, @@ -21,57 +23,57 @@ import { AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, -} from "./ui/alert-dialog"; -import EditDrawingInfoModal, { EditTypeEnum } from "./EditDrawingInfoModal"; +} from './ui/alert-dialog' +import { useToast } from './ui/use-toast' export const PREVIEW_WINDOW = { width: 280, height: 180, -}; -const TITLE_HEIGHT = 50; +} +const TITLE_HEIGHT = 50 export type IPageWithDrawing = PageEntity & { - drawSvg: SVGSVGElement; - drawAlias?: string; - drawTag?: string; - drawRawBlocks: BlockEntity[]; -}; + drawSvg: SVGSVGElement + drawAlias?: string + drawTag?: string + drawRawBlocks: BlockEntity[] +} const DrawingCard: React.FC<{ - page: IPageWithDrawing; - onClickDrawing: (page: IPageWithDrawing) => void; - onDelete: (page: IPageWithDrawing) => void; - onChange?: () => void; + page: IPageWithDrawing + onClickDrawing: (page: IPageWithDrawing) => void + onDelete: (page: IPageWithDrawing) => void + onChange?: () => void }> = ({ page, onClickDrawing, onDelete, onChange }) => { const [editModalData, setEditModalData] = useState<{ - type?: EditTypeEnum; - open: boolean; - }>(); - const { toast } = useToast(); + type?: EditTypeEnum + open: boolean + }>() + const { toast } = useToast() const openEditDialog = (type: EditTypeEnum) => { setEditModalData({ type, open: true, - }); - }; + }) + } const onClickCopyRendererText = () => { - copy(`{{renderer excalidraw-menu, ${page.originalName}}}`, { - onCopy: () => { - toast({ - title: "Copied", - description: "Renderer text copied to clipboard successfully", - }); - }, - }); - }; + // The reason for delay in execution is that the copying action can only be performed after shadcn's layer disappears. + setTimeout(() => { + copyToClipboard(`{{renderer excalidraw, ${page.originalName}}}`) + toast({ + title: 'Copied', + description: 'Renderer text copied to clipboard successfully', + }) + }, 1000) + } const deleteDrawing = async () => { - await logseq.Editor.deletePage(page.originalName); + await logseq.Editor.deletePage(page.originalName) toast({ - title: "Deleted", - description: "Page deleted successfully", - }); - onDelete(page); - }; + title: 'Deleted', + description: 'Page deleted successfully', + }) + onDelete(page) + } return ( <>