editor: add copy link tool

This commit is contained in:
ammarahm-ed
2023-07-21 10:31:29 +05:00
committed by Abdullah Atta
parent c14b09ee1d
commit ed277a95fb
5 changed files with 100 additions and 65 deletions

View File

@@ -34,7 +34,7 @@ function LinkHoverPopup(props: HoverPopupProps) {
return (
<ToolbarGroup
force
tools={["openLink", "editLink", "removeLink"]}
tools={["openLink", "editLink", "removeLink", "copyLink"]}
editor={editor}
selectedNode={selectedNode}
sx={{

View File

@@ -18,23 +18,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {
mdiApplicationCogOutline,
mdiArrowDown,
mdiArrowExpandDown,
mdiArrowExpandLeft,
mdiArrowExpandRight,
mdiArrowExpandUp,
mdiArrowLeft,
mdiArrowUp,
mdiAttachment,
mdiBorderHorizontal,
mdiCameraOutline,
mdiCheck,
mdiCheckboxMarkedOutline,
mdiChevronDown,
mdiChevronLeft,
mdiChevronRight,
mdiChevronUp,
mdiCircle,
mdiClipboardOutline,
mdiClose,
mdiCodeBraces,
mdiCodeTags,
mdiContentSaveOutline,
mdiDeleteOutline,
mdiDotsVertical,
mdiDownloadOutline,
mdiDrag,
mdiEyeOutline,
mdiFileTreeOutline,
mdiFormatAlignCenter,
mdiFormatAlignJustify,
mdiFormatAlignLeft,
mdiFormatAlignRight,
mdiFormatBold,
mdiFormatClear,
mdiFormatColorFill,
mdiFormatColorHighlight,
mdiFormatColorText,
mdiFormatFont,
mdiFormatFontSizeIncrease,
mdiFormatHeaderPound,
mdiFormatIndentDecrease,
mdiFormatIndentIncrease,
mdiFormatItalic,
mdiFormatLetterCase,
mdiFormatLetterMatches,
mdiFormatListBulleted,
mdiFormatListCheckbox,
mdiFormatListNumbered,
mdiFormatQuoteClose,
mdiFormatStrikethrough,
@@ -43,78 +74,47 @@ import {
mdiFormatTextdirectionLToR,
mdiFormatTextdirectionRToL,
mdiFormatUnderline,
mdiFullscreen,
mdiFunctionVariant,
mdiImageEditOutline,
mdiImageOutline,
mdiInvertColorsOff,
mdiLink,
mdiLinkOff,
mdiLinkPlus,
mdiLoading,
mdiMathIntegral,
mdiMinus,
mdiMovieCogOutline,
mdiMoviePlusOutline,
mdiNewspaper,
mdiNotificationClearAll,
mdiOpenInNew,
mdiPageNextOutline,
mdiPaletteOutline,
mdiPlus,
mdiProgressAlert,
mdiProgressDownload,
mdiRegex,
mdiResizeBottomRight,
mdiSortBoolAscendingVariant,
mdiSortDescending,
mdiTable,
mdiTableBorder,
mdiTableRowPlusAfter,
mdiTableRowPlusBefore,
mdiTableRowRemove,
mdiTableCog,
mdiTableColumnPlusAfter,
mdiTableColumnPlusBefore,
mdiTableColumnRemove,
mdiUploadOutline,
mdiPlus,
mdiFormatColorFill,
mdiClose,
mdiSortDescending,
mdiArrowExpandRight,
mdiArrowExpandLeft,
mdiArrowExpandDown,
mdiArrowExpandUp,
mdiTableMergeCells,
mdiTableSplitCell,
mdiDeleteOutline,
mdiDownloadOutline,
mdiFormatListCheckbox,
mdiDrag,
mdiCheckboxMarkedOutline,
mdiChevronUp,
mdiArrowUp,
mdiArrowDown,
mdiRegex,
mdiFormatLetterCase,
mdiFormatLetterMatches,
mdiMoviePlusOutline,
mdiLink,
mdiChevronRight,
mdiTableColumnWidth,
mdiTableRowHeight,
mdiMinus,
mdiPaletteOutline,
mdiCircle,
mdiChevronLeft,
mdiTableCog,
mdiTableMergeCells,
mdiTableOff,
mdiImageEditOutline,
mdiArrowLeft,
mdiMovieCogOutline,
mdiLinkOff,
mdiOpenInNew,
mdiCameraOutline,
mdiMathIntegral,
mdiFunctionVariant,
mdiFileTreeOutline,
mdiFormatFont,
mdiFormatFontSizeIncrease,
mdiFormatHeaderPound,
mdiFormatIndentIncrease,
mdiFormatIndentDecrease,
mdiResizeBottomRight,
mdiImageOutline,
mdiProgressDownload,
mdiProgressAlert,
mdiContentSaveOutline,
mdiClipboardOutline,
mdiNotificationClearAll,
mdiNewspaper,
mdiFullscreen,
mdiWeb,
mdiPageNextOutline,
mdiSortBoolAscendingVariant,
mdiApplicationCogOutline,
mdiEyeOutline
mdiTableRowHeight,
mdiTableRowPlusAfter,
mdiTableRowPlusBefore,
mdiTableRowRemove,
mdiTableSplitCell,
mdiUploadOutline,
mdiWeb
} from "@mdi/js";
export const Icons = {
@@ -144,6 +144,7 @@ export const Icons = {
link: mdiLinkPlus,
linkRemove: mdiLinkOff,
openLink: mdiOpenInNew,
copyLink: mdiClipboardOutline,
openSource: mdiWeb,
webClip: mdiNewspaper,
simplifyWebClip: mdiPageNextOutline,

View File

@@ -60,6 +60,11 @@ const tools: Record<ToolId, ToolDefinition> = {
title: "Open link",
conditional: true
},
copyLink: {
icon: "copyLink",
title: "Copy link",
conditional: true
},
linkSettings: {
icon: "linkSettings",
title: "Link settings",

View File

@@ -81,7 +81,14 @@ import {
EmbedProperties,
EmbedSettings
} from "./embed";
import { AddLink, EditLink, RemoveLink, LinkSettings, OpenLink } from "./link";
import {
AddLink,
EditLink,
RemoveLink,
LinkSettings,
OpenLink,
CopyLink
} from "./link";
import {
WebClipFullScreen,
WebClipSettings,
@@ -103,6 +110,7 @@ const tools = {
addLink: AddLink,
editLink: EditLink,
removeLink: RemoveLink,
copyLink: CopyLink,
linkSettings: LinkSettings,
openLink: OpenLink,
insertBlock: InsertBlock,

View File

@@ -41,7 +41,7 @@ export function LinkSettings(props: ToolProps) {
autoOpen
autoCloseOnUnmount
popupId="linkSettings"
tools={["openLink", "editLink", "removeLink"]}
tools={["openLink", "editLink", "removeLink", "copyLink"]}
/>
);
}
@@ -247,6 +247,27 @@ export function OpenLink(props: ToolProps) {
);
}
export function CopyLink(props: ToolProps) {
const { editor, selectedNode: _selectedNode } = props;
const selectedNode = useRefValue(
_selectedNode || selectionToOffset(editor.state)
);
const { node } = selectedNode.current || {};
const link = node ? findMark(node, "link") : null;
if (!link) return null;
const href = link?.attrs.href;
return (
<ToolButton
{...props}
toggled={false}
onClick={() => {
editor.commands.copyToClipboard(href);
}}
/>
);
}
export type LinkDefinition = {
href?: string;
text?: string;