mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 23:44:24 +08:00
670ee64179
* feat: support i18n * feat: wip support i18n * feat: complete space translation * feat: complete page translation * feat: update space translation * feat: update workspace translation * feat: update group translation * feat: update workspace translation * feat: update page translation * feat: update user translation * chore: update pnpm-lock * feat: add query translation * refactor: merge to single file * chore: remove necessary code * feat: save language to BE * fix: only load current language * feat: save language to locale column * fix: cleanups * add language menu to preferences page * new translations * translate editor * Translate editor placeholders * translate space selection component --------- Co-authored-by: Philip Okugbe <phil@docmost.com> Co-authored-by: Philip Okugbe <16838612+Philipinho@users.noreply.github.com>
139 lines
3.7 KiB
TypeScript
139 lines
3.7 KiB
TypeScript
import {
|
|
BubbleMenu as BaseBubbleMenu,
|
|
findParentNode,
|
|
posToDOMRect,
|
|
} from "@tiptap/react";
|
|
import React, { useCallback } from "react";
|
|
import { Node as PMNode } from "prosemirror-model";
|
|
import {
|
|
EditorMenuProps,
|
|
ShouldShowProps,
|
|
} from "@/features/editor/components/table/types/types.ts";
|
|
import { ActionIcon, Tooltip } from "@mantine/core";
|
|
import {
|
|
IconAlertTriangleFilled,
|
|
IconCircleCheckFilled,
|
|
IconCircleXFilled,
|
|
IconInfoCircleFilled,
|
|
} from "@tabler/icons-react";
|
|
import { CalloutType } from "@docmost/editor-ext";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export function CalloutMenu({ editor }: EditorMenuProps) {
|
|
const { t } = useTranslation();
|
|
const shouldShow = useCallback(
|
|
({ state }: ShouldShowProps) => {
|
|
if (!state) {
|
|
return false;
|
|
}
|
|
|
|
return editor.isActive("callout");
|
|
},
|
|
[editor],
|
|
);
|
|
|
|
const getReferenceClientRect = useCallback(() => {
|
|
const { selection } = editor.state;
|
|
const predicate = (node: PMNode) => node.type.name === "callout";
|
|
const parent = findParentNode(predicate)(selection);
|
|
|
|
if (parent) {
|
|
const dom = editor.view.nodeDOM(parent?.pos) as HTMLElement;
|
|
return dom.getBoundingClientRect();
|
|
}
|
|
|
|
return posToDOMRect(editor.view, selection.from, selection.to);
|
|
}, [editor]);
|
|
|
|
const setCalloutType = useCallback(
|
|
(calloutType: CalloutType) => {
|
|
editor
|
|
.chain()
|
|
.focus(undefined, { scrollIntoView: false })
|
|
.updateCalloutType(calloutType)
|
|
.run();
|
|
},
|
|
[editor],
|
|
);
|
|
|
|
return (
|
|
<BaseBubbleMenu
|
|
editor={editor}
|
|
pluginKey={`callout-menu}`}
|
|
updateDelay={0}
|
|
tippyOptions={{
|
|
getReferenceClientRect,
|
|
offset: [0, 10],
|
|
placement: "bottom",
|
|
zIndex: 99,
|
|
popperOptions: {
|
|
modifiers: [{ name: "flip", enabled: false }],
|
|
},
|
|
}}
|
|
shouldShow={shouldShow}
|
|
>
|
|
<ActionIcon.Group className="actionIconGroup">
|
|
<Tooltip position="top" label={t("Info")}>
|
|
<ActionIcon
|
|
onClick={() => setCalloutType("info")}
|
|
size="lg"
|
|
aria-label={t("Info")}
|
|
variant={
|
|
editor.isActive("callout", { type: "info" }) ? "light" : "default"
|
|
}
|
|
>
|
|
<IconInfoCircleFilled size={18} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
|
|
<Tooltip position="top" label={t("Success")}>
|
|
<ActionIcon
|
|
onClick={() => setCalloutType("success")}
|
|
size="lg"
|
|
aria-label={t("Success")}
|
|
variant={
|
|
editor.isActive("callout", { type: "success" })
|
|
? "light"
|
|
: "default"
|
|
}
|
|
>
|
|
<IconCircleCheckFilled size={18} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
|
|
<Tooltip position="top" label={t("Warning")}>
|
|
<ActionIcon
|
|
onClick={() => setCalloutType("warning")}
|
|
size="lg"
|
|
aria-label={t("Warning")}
|
|
variant={
|
|
editor.isActive("callout", { type: "warning" })
|
|
? "light"
|
|
: "default"
|
|
}
|
|
>
|
|
<IconAlertTriangleFilled size={18} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
|
|
<Tooltip position="top" label={t("Danger")}>
|
|
<ActionIcon
|
|
onClick={() => setCalloutType("danger")}
|
|
size="lg"
|
|
aria-label={t("Danger")}
|
|
variant={
|
|
editor.isActive("callout", { type: "danger" })
|
|
? "light"
|
|
: "default"
|
|
}
|
|
>
|
|
<IconCircleXFilled size={18} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
</ActionIcon.Group>
|
|
</BaseBubbleMenu>
|
|
);
|
|
}
|
|
|
|
export default CalloutMenu;
|