mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
editor: add copy link tool
This commit is contained in:
committed by
Abdullah Atta
parent
c14b09ee1d
commit
ed277a95fb
@@ -34,7 +34,7 @@ function LinkHoverPopup(props: HoverPopupProps) {
|
|||||||
return (
|
return (
|
||||||
<ToolbarGroup
|
<ToolbarGroup
|
||||||
force
|
force
|
||||||
tools={["openLink", "editLink", "removeLink"]}
|
tools={["openLink", "editLink", "removeLink", "copyLink"]}
|
||||||
editor={editor}
|
editor={editor}
|
||||||
selectedNode={selectedNode}
|
selectedNode={selectedNode}
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@@ -18,23 +18,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
mdiApplicationCogOutline,
|
||||||
|
mdiArrowDown,
|
||||||
|
mdiArrowExpandDown,
|
||||||
|
mdiArrowExpandLeft,
|
||||||
|
mdiArrowExpandRight,
|
||||||
|
mdiArrowExpandUp,
|
||||||
|
mdiArrowLeft,
|
||||||
|
mdiArrowUp,
|
||||||
mdiAttachment,
|
mdiAttachment,
|
||||||
mdiBorderHorizontal,
|
mdiBorderHorizontal,
|
||||||
|
mdiCameraOutline,
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
|
mdiCheckboxMarkedOutline,
|
||||||
mdiChevronDown,
|
mdiChevronDown,
|
||||||
|
mdiChevronLeft,
|
||||||
|
mdiChevronRight,
|
||||||
|
mdiChevronUp,
|
||||||
|
mdiCircle,
|
||||||
|
mdiClipboardOutline,
|
||||||
|
mdiClose,
|
||||||
mdiCodeBraces,
|
mdiCodeBraces,
|
||||||
mdiCodeTags,
|
mdiCodeTags,
|
||||||
|
mdiContentSaveOutline,
|
||||||
|
mdiDeleteOutline,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
|
mdiDownloadOutline,
|
||||||
|
mdiDrag,
|
||||||
|
mdiEyeOutline,
|
||||||
|
mdiFileTreeOutline,
|
||||||
mdiFormatAlignCenter,
|
mdiFormatAlignCenter,
|
||||||
mdiFormatAlignJustify,
|
mdiFormatAlignJustify,
|
||||||
mdiFormatAlignLeft,
|
mdiFormatAlignLeft,
|
||||||
mdiFormatAlignRight,
|
mdiFormatAlignRight,
|
||||||
mdiFormatBold,
|
mdiFormatBold,
|
||||||
mdiFormatClear,
|
mdiFormatClear,
|
||||||
|
mdiFormatColorFill,
|
||||||
mdiFormatColorHighlight,
|
mdiFormatColorHighlight,
|
||||||
mdiFormatColorText,
|
mdiFormatColorText,
|
||||||
|
mdiFormatFont,
|
||||||
|
mdiFormatFontSizeIncrease,
|
||||||
|
mdiFormatHeaderPound,
|
||||||
|
mdiFormatIndentDecrease,
|
||||||
|
mdiFormatIndentIncrease,
|
||||||
mdiFormatItalic,
|
mdiFormatItalic,
|
||||||
|
mdiFormatLetterCase,
|
||||||
|
mdiFormatLetterMatches,
|
||||||
mdiFormatListBulleted,
|
mdiFormatListBulleted,
|
||||||
|
mdiFormatListCheckbox,
|
||||||
mdiFormatListNumbered,
|
mdiFormatListNumbered,
|
||||||
mdiFormatQuoteClose,
|
mdiFormatQuoteClose,
|
||||||
mdiFormatStrikethrough,
|
mdiFormatStrikethrough,
|
||||||
@@ -43,78 +74,47 @@ import {
|
|||||||
mdiFormatTextdirectionLToR,
|
mdiFormatTextdirectionLToR,
|
||||||
mdiFormatTextdirectionRToL,
|
mdiFormatTextdirectionRToL,
|
||||||
mdiFormatUnderline,
|
mdiFormatUnderline,
|
||||||
|
mdiFullscreen,
|
||||||
|
mdiFunctionVariant,
|
||||||
|
mdiImageEditOutline,
|
||||||
|
mdiImageOutline,
|
||||||
mdiInvertColorsOff,
|
mdiInvertColorsOff,
|
||||||
|
mdiLink,
|
||||||
|
mdiLinkOff,
|
||||||
mdiLinkPlus,
|
mdiLinkPlus,
|
||||||
mdiLoading,
|
mdiLoading,
|
||||||
|
mdiMathIntegral,
|
||||||
|
mdiMinus,
|
||||||
|
mdiMovieCogOutline,
|
||||||
|
mdiMoviePlusOutline,
|
||||||
|
mdiNewspaper,
|
||||||
|
mdiNotificationClearAll,
|
||||||
|
mdiOpenInNew,
|
||||||
|
mdiPageNextOutline,
|
||||||
|
mdiPaletteOutline,
|
||||||
|
mdiPlus,
|
||||||
|
mdiProgressAlert,
|
||||||
|
mdiProgressDownload,
|
||||||
|
mdiRegex,
|
||||||
|
mdiResizeBottomRight,
|
||||||
|
mdiSortBoolAscendingVariant,
|
||||||
|
mdiSortDescending,
|
||||||
mdiTable,
|
mdiTable,
|
||||||
mdiTableBorder,
|
mdiTableBorder,
|
||||||
mdiTableRowPlusAfter,
|
mdiTableCog,
|
||||||
mdiTableRowPlusBefore,
|
|
||||||
mdiTableRowRemove,
|
|
||||||
mdiTableColumnPlusAfter,
|
mdiTableColumnPlusAfter,
|
||||||
mdiTableColumnPlusBefore,
|
mdiTableColumnPlusBefore,
|
||||||
mdiTableColumnRemove,
|
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,
|
mdiTableColumnWidth,
|
||||||
mdiTableRowHeight,
|
mdiTableMergeCells,
|
||||||
mdiMinus,
|
|
||||||
mdiPaletteOutline,
|
|
||||||
mdiCircle,
|
|
||||||
mdiChevronLeft,
|
|
||||||
mdiTableCog,
|
|
||||||
mdiTableOff,
|
mdiTableOff,
|
||||||
mdiImageEditOutline,
|
mdiTableRowHeight,
|
||||||
mdiArrowLeft,
|
mdiTableRowPlusAfter,
|
||||||
mdiMovieCogOutline,
|
mdiTableRowPlusBefore,
|
||||||
mdiLinkOff,
|
mdiTableRowRemove,
|
||||||
mdiOpenInNew,
|
mdiTableSplitCell,
|
||||||
mdiCameraOutline,
|
mdiUploadOutline,
|
||||||
mdiMathIntegral,
|
mdiWeb
|
||||||
mdiFunctionVariant,
|
|
||||||
mdiFileTreeOutline,
|
|
||||||
mdiFormatFont,
|
|
||||||
mdiFormatFontSizeIncrease,
|
|
||||||
mdiFormatHeaderPound,
|
|
||||||
mdiFormatIndentIncrease,
|
|
||||||
mdiFormatIndentDecrease,
|
|
||||||
mdiResizeBottomRight,
|
|
||||||
mdiImageOutline,
|
|
||||||
mdiProgressDownload,
|
|
||||||
mdiProgressAlert,
|
|
||||||
mdiContentSaveOutline,
|
|
||||||
mdiClipboardOutline,
|
|
||||||
mdiNotificationClearAll,
|
|
||||||
mdiNewspaper,
|
|
||||||
mdiFullscreen,
|
|
||||||
mdiWeb,
|
|
||||||
mdiPageNextOutline,
|
|
||||||
mdiSortBoolAscendingVariant,
|
|
||||||
mdiApplicationCogOutline,
|
|
||||||
mdiEyeOutline
|
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
|
|
||||||
export const Icons = {
|
export const Icons = {
|
||||||
@@ -144,6 +144,7 @@ export const Icons = {
|
|||||||
link: mdiLinkPlus,
|
link: mdiLinkPlus,
|
||||||
linkRemove: mdiLinkOff,
|
linkRemove: mdiLinkOff,
|
||||||
openLink: mdiOpenInNew,
|
openLink: mdiOpenInNew,
|
||||||
|
copyLink: mdiClipboardOutline,
|
||||||
openSource: mdiWeb,
|
openSource: mdiWeb,
|
||||||
webClip: mdiNewspaper,
|
webClip: mdiNewspaper,
|
||||||
simplifyWebClip: mdiPageNextOutline,
|
simplifyWebClip: mdiPageNextOutline,
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ const tools: Record<ToolId, ToolDefinition> = {
|
|||||||
title: "Open link",
|
title: "Open link",
|
||||||
conditional: true
|
conditional: true
|
||||||
},
|
},
|
||||||
|
copyLink: {
|
||||||
|
icon: "copyLink",
|
||||||
|
title: "Copy link",
|
||||||
|
conditional: true
|
||||||
|
},
|
||||||
linkSettings: {
|
linkSettings: {
|
||||||
icon: "linkSettings",
|
icon: "linkSettings",
|
||||||
title: "Link settings",
|
title: "Link settings",
|
||||||
|
|||||||
@@ -81,7 +81,14 @@ import {
|
|||||||
EmbedProperties,
|
EmbedProperties,
|
||||||
EmbedSettings
|
EmbedSettings
|
||||||
} from "./embed";
|
} from "./embed";
|
||||||
import { AddLink, EditLink, RemoveLink, LinkSettings, OpenLink } from "./link";
|
import {
|
||||||
|
AddLink,
|
||||||
|
EditLink,
|
||||||
|
RemoveLink,
|
||||||
|
LinkSettings,
|
||||||
|
OpenLink,
|
||||||
|
CopyLink
|
||||||
|
} from "./link";
|
||||||
import {
|
import {
|
||||||
WebClipFullScreen,
|
WebClipFullScreen,
|
||||||
WebClipSettings,
|
WebClipSettings,
|
||||||
@@ -103,6 +110,7 @@ const tools = {
|
|||||||
addLink: AddLink,
|
addLink: AddLink,
|
||||||
editLink: EditLink,
|
editLink: EditLink,
|
||||||
removeLink: RemoveLink,
|
removeLink: RemoveLink,
|
||||||
|
copyLink: CopyLink,
|
||||||
linkSettings: LinkSettings,
|
linkSettings: LinkSettings,
|
||||||
openLink: OpenLink,
|
openLink: OpenLink,
|
||||||
insertBlock: InsertBlock,
|
insertBlock: InsertBlock,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function LinkSettings(props: ToolProps) {
|
|||||||
autoOpen
|
autoOpen
|
||||||
autoCloseOnUnmount
|
autoCloseOnUnmount
|
||||||
popupId="linkSettings"
|
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 = {
|
export type LinkDefinition = {
|
||||||
href?: string;
|
href?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user