You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
12 months ago
|
import { getContextMenuLabel } from "../components/hyperlink/Hyperlink";
|
||
|
import { LinkIcon } from "../components/icons";
|
||
|
import { ToolButton } from "../components/ToolButton";
|
||
|
import { isEmbeddableElement } from "../element/typeChecks";
|
||
|
import { t } from "../i18n";
|
||
|
import { KEYS } from "../keys";
|
||
|
import { getSelectedElements } from "../scene";
|
||
|
import { getShortcutKey } from "../utils";
|
||
|
import { register } from "./register";
|
||
|
|
||
|
export const actionLink = register({
|
||
|
name: "hyperlink",
|
||
|
perform: (elements, appState) => {
|
||
|
if (appState.showHyperlinkPopup === "editor") {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
elements,
|
||
|
appState: {
|
||
|
...appState,
|
||
|
showHyperlinkPopup: "editor",
|
||
|
openMenu: null,
|
||
|
},
|
||
|
commitToHistory: true,
|
||
|
};
|
||
|
},
|
||
|
trackEvent: { category: "hyperlink", action: "click" },
|
||
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.K,
|
||
|
contextItemLabel: (elements, appState) =>
|
||
|
getContextMenuLabel(elements, appState),
|
||
|
predicate: (elements, appState) => {
|
||
|
const selectedElements = getSelectedElements(elements, appState);
|
||
|
return selectedElements.length === 1;
|
||
|
},
|
||
|
PanelComponent: ({ elements, appState, updateData }) => {
|
||
|
const selectedElements = getSelectedElements(elements, appState);
|
||
|
|
||
|
return (
|
||
|
<ToolButton
|
||
|
type="button"
|
||
|
icon={LinkIcon}
|
||
|
aria-label={t(getContextMenuLabel(elements, appState))}
|
||
|
title={`${
|
||
|
isEmbeddableElement(elements[0])
|
||
|
? t("labels.link.labelEmbed")
|
||
|
: t("labels.link.label")
|
||
|
} - ${getShortcutKey("CtrlOrCmd+K")}`}
|
||
|
onClick={() => updateData(null)}
|
||
|
selected={selectedElements.length === 1 && !!selectedElements[0].link}
|
||
|
/>
|
||
|
);
|
||
|
},
|
||
|
});
|