Add supported embed detection

This commit is contained in:
Tom Moor committed 2025-01-16 23:18:03 -05:00
1 parent 5eb95f7bd9
commit 28d5d0da5d
8 files changed
+47 -22

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ type Props = {
as?: string | React.ComponentType<any>;
hide?: () => void;
level?: number;
icon?: React.ReactElement;
icon?: React.ReactNode;
children?: React.ReactNode;
ref?: React.LegacyRef<HTMLButtonElement> | undefined;
};
+26 -4
View File
@@ -1,27 +1,48 @@
import { LinkIcon } from "outline-icons";
import React from "react";
import { useTranslation } from "react-i18next";
import { EmbedDescriptor } from "@shared/editor/embeds";
import SuggestionsMenu, {
Props as SuggestionsMenuProps,
} from "./SuggestionsMenu";
import SuggestionsMenuItem from "./SuggestionsMenuItem";
type Props = Omit<SuggestionsMenuProps, "renderMenuItem" | "items" | "embeds">;
type Props = Omit<
SuggestionsMenuProps,
"renderMenuItem" | "items" | "embeds"
> & {
pastedText: string;
embeds: EmbedDescriptor[];
};
const PasteMenu = (props: Props) => {
const PasteMenu = ({ embeds, ...props }: Props) => {
const { t } = useTranslation();
const embed = React.useMemo(() => {
for (const e of embeds) {
const matches = e.matcher(props.pastedText);
if (matches) {
return e;
}
}
return;
}, [embeds, props.pastedText]);
const items = React.useMemo(
() => [
{
name: "link",
title: t("URL"),
title: t("Keep as link"),
icon: <LinkIcon />,
},
{
name: "embed",
title: t("Embed"),
icon: embed?.icon,
keywords: embed?.keywords,
},
],
[t]
[embed, t]
);
return (
@@ -35,6 +56,7 @@ const PasteMenu = (props: Props) => {
}}
selected={options.selected}
title={item.title}
icon={item.icon}
/>
)}
items={items}
@@ -12,7 +12,7 @@ export type Props = {
/** Callback when the item is clicked */
onClick: (event: React.SyntheticEvent) => void;
/** An optional icon for the item */
icon?: React.ReactElement;
icon?: React.ReactNode;
/** The title of the item */
title: React.ReactNode;
/** An optional subtitle for the item */
+8 -6
View File
@@ -65,11 +65,11 @@ export default class PasteHandler extends Extension {
state: {
open: boolean;
query: string;
pasteData: Record<string, any>;
pastedText: string;
} = observable({
open: false,
query: "",
pasteData: {},
pastedText: "",
});
get name() {
@@ -288,14 +288,14 @@ export default class PasteHandler extends Extension {
private showPasteMenu(text: string) {
action(() => {
this.state.pasteData.text = text;
this.state.pastedText = text;
this.state.open = true;
})();
}
private hidePasteMenu() {
action(() => {
this.state.pasteData.text = "";
this.state.pastedText = "";
this.state.open = false;
})();
}
@@ -344,6 +344,8 @@ export default class PasteHandler extends Extension {
<PasteMenu
rtl={rtl}
trigger=""
embeds={this.editor.props.embeds}
pastedText={this.state.pastedText}
isActive={this.state.open}
search={this.state.query}
onClose={() => {
@@ -356,10 +358,10 @@ export default class PasteHandler extends Extension {
break;
case "embed":
this.replaceOldLink(this.state.pasteData.text);
this.replaceOldLink(this.state.pastedText);
this.editor.commands.embed({
href: this.state.pasteData.text,
href: this.state.pastedText,
});
this.hidePasteMenu();
+6 -6
View File
@@ -26,7 +26,7 @@ export type MenuItemButton = {
visible?: boolean;
selected?: boolean;
disabled?: boolean;
icon?: React.ReactElement;
icon?: React.ReactNode;
};
export type MenuItemWithChildren = {
@@ -38,7 +38,7 @@ export type MenuItemWithChildren = {
hover?: boolean;
items: MenuItem[];
icon?: React.ReactElement;
icon?: React.ReactNode;
};
export type MenuSeparator = {
@@ -59,7 +59,7 @@ export type MenuInternalLink = {
visible?: boolean;
selected?: boolean;
disabled?: boolean;
icon?: React.ReactElement;
icon?: React.ReactNode;
};
export type MenuExternalLink = {
@@ -70,7 +70,7 @@ export type MenuExternalLink = {
selected?: boolean;
disabled?: boolean;
level?: number;
icon?: React.ReactElement;
icon?: React.ReactNode;
};
export type MenuItem =
@@ -108,7 +108,7 @@ export type Action = {
/** Higher number is higher in results, default is 0. */
priority?: number;
iconInContextMenu?: boolean;
icon?: React.ReactElement | React.FC;
icon?: React.ReactNode;
placeholder?: ((context: ActionContext) => string) | string;
selected?: (context: ActionContext) => boolean;
visible?: (context: ActionContext) => boolean;
@@ -127,7 +127,7 @@ export type CommandBarAction = {
shortcut: string[];
keywords: string;
placeholder?: string;
icon?: React.ReactElement;
icon?: React.ReactNode;
perform?: () => void;
children?: string[];
parent?: string;
+2 -2
View File
@@ -31,9 +31,9 @@ export type EmbedProps = {
};
const Img = styled(Image)`
border-radius: 2px;
border-radius: 3px;
background: #fff;
box-shadow: 0 0 0 1px #fff;
box-shadow: 0 0 0 1px ${(props) => props.theme.divider};
margin: 3px;
width: 18px;
height: 18px;
+1 -1
View File
@@ -16,7 +16,7 @@ export enum TableLayout {
}
export type MenuItem = {
icon?: React.ReactElement;
icon?: React.ReactNode;
name?: string;
title?: string;
subtitle?: string;
+2 -1
View File
@@ -418,7 +418,7 @@
"Replace all": "Replace all",
"{{ 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",
"Profile picture": "Profile picture",
"URL": "URL",
"Keep as link": "Keep as link",
"Embed": "Embed",
"Add column after": "Add column after",
"Add column before": "Add column before",
@@ -1108,6 +1108,7 @@
"Updating": "Updating",
"Provide a descriptive name for this webhook and the URL we should send a POST request to when matching events are created.": "Provide a descriptive name for this webhook and the URL we should send a POST request to when matching events are created.",
"A memorable identifer": "A memorable identifer",
"URL": "URL",
"Signing secret": "Signing secret",
"Subscribe to all events, groups, or individual events. We recommend only subscribing to the minimum amount of events that your application needs to function.": "Subscribe to all events, groups, or individual events. We recommend only subscribing to the minimum amount of events that your application needs to function.",
"All events": "All events",