diff --git a/app/actions/sections.ts b/app/actions/sections.ts index b434143c29..e56996cb0f 100644 --- a/app/actions/sections.ts +++ b/app/actions/sections.ts @@ -13,6 +13,8 @@ export const DeveloperSection = ({ t }: ActionContext) => t("Debug"); export const DocumentSection = ({ t }: ActionContext) => t("Document"); +export const DocumentsSection = ({ t }: ActionContext) => t("Documents"); + export const ActiveDocumentSection = ({ t, stores }: ActionContext) => { const activeDocument = stores.documents.active; return `${t("Document")} · ${activeDocument?.titleWithDefault}`; diff --git a/app/editor/components/LinkToolbar.tsx b/app/editor/components/LinkToolbar.tsx deleted file mode 100644 index 92707544b4..0000000000 --- a/app/editor/components/LinkToolbar.tsx +++ /dev/null @@ -1,146 +0,0 @@ -import { EditorView } from "prosemirror-view"; -import * as React from "react"; -import createAndInsertLink from "@shared/editor/commands/createAndInsertLink"; -import { creatingUrlPrefix } from "@shared/utils/urls"; -import useDictionary from "~/hooks/useDictionary"; -import useEventListener from "~/hooks/useEventListener"; -import { useEditor } from "./EditorContext"; -import FloatingToolbar from "./FloatingToolbar"; -import LinkEditor, { SearchResult } from "./LinkEditor"; - -type Props = { - isActive: boolean; - onCreateLink?: (title: string) => Promise; - onSearchLink?: (term: string) => Promise; - onClickLink: ( - href: string, - event: React.MouseEvent - ) => void; - onClose: () => void; -}; - -function isActive(view: EditorView, active: boolean): boolean { - try { - const { selection } = view.state; - const paragraph = view.domAtPos(selection.from); - return active && !!paragraph.node; - } catch (err) { - return false; - } -} - -export default function LinkToolbar({ - onCreateLink, - onSearchLink, - onClickLink, - onClose, - ...rest -}: Props) { - const dictionary = useDictionary(); - const { view } = useEditor(); - const menuRef = React.useRef(null); - - useEventListener("mousedown", (event: Event) => { - if ( - event.target instanceof HTMLElement && - menuRef.current && - menuRef.current.contains(event.target) - ) { - return; - } - onClose(); - }); - - const handleOnCreateLink = React.useCallback( - async (title: string, nested?: boolean) => { - onClose(); - view.focus(); - - if (!onCreateLink) { - return; - } - - const { dispatch, state } = view; - const { from, to } = state.selection; - if (from !== to) { - // selection must be collapsed - return; - } - - const href = `${creatingUrlPrefix}#${title}…`; - - // Insert a placeholder link - dispatch( - view.state.tr - .insertText(title, from, to) - .addMark( - from, - to + title.length, - state.schema.marks.link.create({ href }) - ) - ); - - return createAndInsertLink(view, title, href, { - nested, - onCreateLink, - dictionary, - }); - }, - [onCreateLink, onClose, view, dictionary] - ); - - const handleOnSelectLink = React.useCallback( - ({ - href, - title, - }: { - href: string; - title: string; - from: number; - to: number; - }) => { - onClose(); - view.focus(); - - const { dispatch, state } = view; - const { from, to } = state.selection; - if (from !== to) { - // selection must be collapsed - return; - } - - dispatch( - view.state.tr - .insertText(title, from, to) - .addMark( - from, - to + title.length, - state.schema.marks.link.create({ href }) - ) - ); - }, - [onClose, view] - ); - - const { selection } = view.state; - const active = isActive(view, rest.isActive); - - return ( - - {active && ( - - )} - - ); -} diff --git a/app/editor/components/MentionMenu.tsx b/app/editor/components/MentionMenu.tsx index 80e3551c56..6c0ee97bc8 100644 --- a/app/editor/components/MentionMenu.tsx +++ b/app/editor/components/MentionMenu.tsx @@ -1,5 +1,5 @@ import { observer } from "mobx-react"; -import { DocumentIcon } from "outline-icons"; +import { DocumentIcon, PlusIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; @@ -13,7 +13,7 @@ import Document from "~/models/Document"; import User from "~/models/User"; import { Avatar, AvatarSize } from "~/components/Avatar"; import Flex from "~/components/Flex"; -import { DocumentSection, UserSection } from "~/actions/sections"; +import { DocumentsSection, UserSection } from "~/actions/sections"; import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import { client } from "~/utils/ApiClient"; @@ -105,7 +105,7 @@ function MentionMenu({ search, isActive, ...rest }: Props) { ), title: doc.title, subtitle: doc.collection?.name, - section: DocumentSection, + section: DocumentsSection, appendSpace: true, attrs: { id: v4(), @@ -115,7 +115,25 @@ function MentionMenu({ search, isActive, ...rest }: Props) { label: doc.title, }, })) - ); + ) + .concat([ + { + name: "mention", + icon: , + title: search?.trim(), + section: DocumentsSection, + subtitle: t("Create a new doc"), + visible: !!search, + appendSpace: true, + attrs: { + id: v4(), + type: MentionType.Document, + modelId: v4(), + actorId: auth.currentUserId ?? undefined, + label: search, + }, + }, + ]); setItems(items); setLoaded(true); diff --git a/app/editor/index.tsx b/app/editor/index.tsx index f3474a6e35..8358cd0141 100644 --- a/app/editor/index.tsx +++ b/app/editor/index.tsx @@ -37,7 +37,7 @@ import Mark from "@shared/editor/marks/Mark"; import { basicExtensions as extensions } from "@shared/editor/nodes"; import Node from "@shared/editor/nodes/Node"; import ReactNode from "@shared/editor/nodes/ReactNode"; -import { ComponentProps, EventType } from "@shared/editor/types"; +import { ComponentProps } from "@shared/editor/types"; import { ProsemirrorData, UserPreferences } from "@shared/types"; import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; import EventEmitter from "@shared/utils/events"; @@ -48,7 +48,6 @@ import Logger from "~/utils/Logger"; import ComponentView from "./components/ComponentView"; import EditorContext from "./components/EditorContext"; import { SearchResult } from "./components/LinkEditor"; -import LinkToolbar from "./components/LinkToolbar"; import { NodeViewRenderer } from "./components/NodeViewRenderer"; import SelectionToolbar from "./components/SelectionToolbar"; import WithTheme from "./components/WithTheme"; @@ -145,8 +144,6 @@ type State = { isEditorFocused: boolean; /** If the toolbar for a text selection is visible */ selectionToolbarOpen: boolean; - /** If the insert link toolbar is visible */ - linkToolbarOpen: boolean; }; /** @@ -176,7 +173,6 @@ export class Editor extends React.PureComponent< isRTL: false, isEditorFocused: false, selectionToolbarOpen: false, - linkToolbarOpen: false, }; isInitialized = false; @@ -205,11 +201,6 @@ export class Editor extends React.PureComponent< events = new EventEmitter(); mutationObserver?: MutationObserver; - public constructor(props: Props & ThemeProps) { - super(props); - this.events.on(EventType.LinkToolbarOpen, this.handleOpenLinkToolbar); - } - /** * We use componentDidMount instead of constructor as the init method requires * that the dom is already mounted. @@ -274,9 +265,7 @@ export class Editor extends React.PureComponent< if ( this.isBlurred && - (this.state.isEditorFocused || - this.state.linkToolbarOpen || - this.state.selectionToolbarOpen) + (this.state.isEditorFocused || this.state.selectionToolbarOpen) ) { this.isBlurred = false; this.props.onFocus?.(); @@ -779,23 +768,6 @@ export class Editor extends React.PureComponent< })); }; - private handleOpenLinkToolbar = () => { - if (this.state.selectionToolbarOpen) { - return; - } - this.setState((state) => ({ - ...state, - linkToolbarOpen: true, - })); - }; - - private handleCloseLinkToolbar = () => { - this.setState((state) => ({ - ...state, - linkToolbarOpen: false, - })); - }; - public render() { const { dir, readOnly, canUpdate, grow, style, className, onKeyDown } = this.props; @@ -839,15 +811,6 @@ export class Editor extends React.PureComponent< onCreateLink={this.props.onCreateLink} /> )} - {!readOnly && this.view && this.marks.link && ( - - )} {this.widgets && Object.values(this.widgets).map((Widget, index) => ( diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index a815fcea4d..49d967350b 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -14,7 +14,6 @@ import { toast } from "sonner"; import { sanitizeUrl } from "../../utils/urls"; import { getMarkRange } from "../queries/getMarkRange"; import { isMarkActive } from "../queries/isMarkActive"; -import { EventType } from "../types"; import Mark from "./Mark"; const LINK_INPUT_REGEX = /\[([^[]+)]\((\S+)\)$/; @@ -109,8 +108,7 @@ export default class Link extends Mark { return { "Mod-k": (state, dispatch) => { if (state.selection.empty) { - this.editor.events.emit(EventType.LinkToolbarOpen); - return true; + return false; } return toggleMark(type, { href: "" })(state, dispatch); diff --git a/shared/editor/types/index.ts b/shared/editor/types/index.ts index 07ea6fec73..7504fe088e 100644 --- a/shared/editor/types/index.ts +++ b/shared/editor/types/index.ts @@ -8,10 +8,6 @@ import { Primitive } from "utility-types"; export type PlainTextSerializer = (node: ProsemirrorNode) => string; -export enum EventType { - LinkToolbarOpen = "linkMenuOpen", -} - export enum TableLayout { fullWidth = "full-width", } diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 015c3d1f02..cee2e422ff 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -138,6 +138,7 @@ "Collection": "Collection", "Debug": "Debug", "Document": "Document", + "Documents": "Documents", "Recently viewed": "Recently viewed", "Revision": "Revision", "Navigation": "Navigation", @@ -302,7 +303,6 @@ "Unknown": "Unknown", "Mark all as read": "Mark all as read", "You're all caught up": "You're all caught up", - "Documents": "Documents", "{{ username }} reacted with {{ emoji }}": "{{ username }} reacted with {{ emoji }}", "{{ firstUsername }} and {{ secondUsername }} reacted with {{ emoji }}": "{{ firstUsername }} and {{ secondUsername }} reacted with {{ emoji }}", "{{ firstUsername }} and {{ count }} others reacted with {{ emoji }}": "{{ firstUsername }} and {{ count }} other reacted with {{ emoji }}", @@ -417,6 +417,7 @@ "Replace": "Replace", "Replace all": "Replace all", "Profile picture": "Profile picture", + "Create a new doc": "Create a new doc", "{{ userName }} won't be notified, as they do not have access to this document": "{{ userName }} won't be notified, as they do not have access to this document", "Add column after": "Add column after", "Add column before": "Add column before", @@ -435,7 +436,6 @@ "Comment": "Comment", "Create link": "Create link", "Sorry, an error occurred creating the link": "Sorry, an error occurred creating the link", - "Create a new doc": "Create a new doc", "Create a new child doc": "Create a new child doc", "Delete table": "Delete table", "Delete file": "Delete file",