@@ -9,6 +9,7 @@ type Props = {
|
|||||||
href: string;
|
href: string;
|
||||||
isSelected: boolean;
|
isSelected: boolean;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
onMouseDown?: React.MouseEventHandler<HTMLAnchorElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Widget(props: Props & ThemeProps<DefaultTheme>) {
|
export default function Widget(props: Props & ThemeProps<DefaultTheme>) {
|
||||||
@@ -19,6 +20,7 @@ export default function Widget(props: Props & ThemeProps<DefaultTheme>) {
|
|||||||
}
|
}
|
||||||
href={props.href}
|
href={props.href}
|
||||||
rel="noreferrer nofollow"
|
rel="noreferrer nofollow"
|
||||||
|
onMouseDown={props.onMouseDown}
|
||||||
>
|
>
|
||||||
{props.icon}
|
{props.icon}
|
||||||
<Preview>
|
<Preview>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Token from "markdown-it/lib/token";
|
import Token from "markdown-it/lib/token";
|
||||||
import { DownloadIcon } from "outline-icons";
|
import { DownloadIcon } from "outline-icons";
|
||||||
import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model";
|
import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model";
|
||||||
|
import { NodeSelection } from "prosemirror-state";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
import { bytesToHumanReadable } from "../../utils/files";
|
import { bytesToHumanReadable } from "../../utils/files";
|
||||||
@@ -66,12 +67,23 @@ export default class Attachment extends Node {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
component({ isSelected, theme, node }: ComponentProps) {
|
handleSelect =
|
||||||
|
({ getPos }: { getPos: () => number }) =>
|
||||||
|
() => {
|
||||||
|
const { view } = this.editor;
|
||||||
|
const $pos = view.state.doc.resolve(getPos());
|
||||||
|
const transaction = view.state.tr.setSelection(new NodeSelection($pos));
|
||||||
|
view.dispatch(transaction);
|
||||||
|
};
|
||||||
|
|
||||||
|
component = (props: ComponentProps) => {
|
||||||
|
const { isSelected, theme, node } = props;
|
||||||
return (
|
return (
|
||||||
<Widget
|
<Widget
|
||||||
icon={<FileExtension title={node.attrs.title} />}
|
icon={<FileExtension title={node.attrs.title} />}
|
||||||
href={node.attrs.href}
|
href={node.attrs.href}
|
||||||
title={node.attrs.title}
|
title={node.attrs.title}
|
||||||
|
onMouseDown={this.handleSelect(props)}
|
||||||
context={
|
context={
|
||||||
node.attrs.href ? (
|
node.attrs.href ? (
|
||||||
bytesToHumanReadable(node.attrs.size)
|
bytesToHumanReadable(node.attrs.size)
|
||||||
@@ -87,7 +99,7 @@ export default class Attachment extends Node {
|
|||||||
{node.attrs.href && <DownloadIcon size={20} />}
|
{node.attrs.href && <DownloadIcon size={20} />}
|
||||||
</Widget>
|
</Widget>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
commands({ type }: { type: NodeType }) {
|
commands({ type }: { type: NodeType }) {
|
||||||
return (attrs: Record<string, any>) => toggleWrap(type, attrs);
|
return (attrs: Record<string, any>) => toggleWrap(type, attrs);
|
||||||
|
|||||||
Reference in New Issue
Block a user