mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update tag selector
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
"@emotion/react": "^11.11.3",
|
"@emotion/react": "^11.11.3",
|
||||||
"@emotion/styled": "^11.11.0",
|
"@emotion/styled": "^11.11.0",
|
||||||
"@matejmazur/react-katex": "^3.1.3",
|
"@matejmazur/react-katex": "^3.1.3",
|
||||||
|
"@mui/base": "5.0.0-beta.31",
|
||||||
"@mui/joy": "5.0.0-beta.22",
|
"@mui/joy": "5.0.0-beta.22",
|
||||||
"@reduxjs/toolkit": "^1.9.7",
|
"@reduxjs/toolkit": "^1.9.7",
|
||||||
"axios": "^1.6.5",
|
"axios": "^1.6.5",
|
||||||
|
3
web/pnpm-lock.yaml
generated
3
web/pnpm-lock.yaml
generated
@ -17,6 +17,9 @@ dependencies:
|
|||||||
'@matejmazur/react-katex':
|
'@matejmazur/react-katex':
|
||||||
specifier: ^3.1.3
|
specifier: ^3.1.3
|
||||||
version: 3.1.3(katex@0.16.9)(react@18.2.0)
|
version: 3.1.3(katex@0.16.9)(react@18.2.0)
|
||||||
|
'@mui/base':
|
||||||
|
specifier: 5.0.0-beta.31
|
||||||
|
version: 5.0.0-beta.31(@types/react@18.2.47)(react-dom@18.2.0)(react@18.2.0)
|
||||||
'@mui/joy':
|
'@mui/joy':
|
||||||
specifier: 5.0.0-beta.22
|
specifier: 5.0.0-beta.22
|
||||||
version: 5.0.0-beta.22(@emotion/react@11.11.3)(@emotion/styled@11.11.0)(@types/react@18.2.47)(react-dom@18.2.0)(react@18.2.0)
|
version: 5.0.0-beta.22(@emotion/react@11.11.3)(@emotion/styled@11.11.0)(@types/react@18.2.47)(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
@ -67,15 +67,13 @@ const MarkdownMenu = (props: Props) => {
|
|||||||
slots={{ root: IconButton }}
|
slots={{ root: IconButton }}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
root: {
|
root: {
|
||||||
className:
|
|
||||||
"flex flex-row justify-center items-center p-1 w-auto h-auto mr-1 select-none rounded cursor-pointer text-gray-600 dark:!text-gray-400 hover:bg-gray-300 dark:hover:bg-zinc-800 hover:shadow",
|
|
||||||
size: "sm",
|
size: "sm",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon.SquareSlash className="w-5 h-5 mx-auto" />
|
<Icon.SquareSlash className="w-5 h-5 mx-auto" />
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<Menu className="text-sm" size="sm">
|
<Menu className="text-sm" size="sm" placement="bottom-start">
|
||||||
<MenuItem onClick={handleCodeBlockClick}>
|
<MenuItem onClick={handleCodeBlockClick}>
|
||||||
<Icon.Code2 className="w-4 h-auto" />
|
<Icon.Code2 className="w-4 h-auto" />
|
||||||
<span>Code block</span>
|
<span>Code block</span>
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
import { IconButton } from "@mui/joy";
|
import { ClickAwayListener } from "@mui/base/ClickAwayListener";
|
||||||
import { useEffect } from "react";
|
import { Dropdown, IconButton, Menu, MenuButton } from "@mui/joy";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import Icon from "@/components/Icon";
|
import Icon from "@/components/Icon";
|
||||||
import OverflowTip from "@/components/kit/OverflowTip";
|
import OverflowTip from "@/components/kit/OverflowTip";
|
||||||
import { useTagStore } from "@/store/module";
|
import { useTagStore } from "@/store/module";
|
||||||
|
import { EditorRefActions } from "../Editor";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onTagSelectorClick: (tag: string) => void;
|
editorRef: React.RefObject<EditorRefActions>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TagSelector = (props: Props) => {
|
const TagSelector = (props: Props) => {
|
||||||
const { onTagSelectorClick } = props;
|
const { editorRef } = props;
|
||||||
const tagStore = useTagStore();
|
const tagStore = useTagStore();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
const tags = tagStore.state.tags;
|
const tags = tagStore.state.tags;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -23,32 +26,50 @@ const TagSelector = (props: Props) => {
|
|||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleTagClick = (tag: string) => {
|
||||||
|
editorRef.current?.insertText(`#${tag} `);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<Dropdown open={open} onOpenChange={(_, isOpen) => setOpen(isOpen)}>
|
||||||
className="relative group flex flex-row justify-center items-center p-1 w-auto h-auto mr-1 select-none rounded cursor-pointer text-gray-600 dark:!text-gray-400 hover:bg-gray-300 hover:shadow"
|
<MenuButton
|
||||||
size="sm"
|
slots={{ root: IconButton }}
|
||||||
>
|
slotProps={{
|
||||||
<Icon.Hash className="w-5 h-5 mx-auto" />
|
root: {
|
||||||
<div className="hidden flex-row justify-start items-start flex-wrap absolute top-7 left-0 mt-1 p-1 z-1 rounded w-52 h-auto max-h-48 overflow-y-auto font-mono shadow bg-zinc-100 dark:bg-zinc-700 group-hover:flex">
|
size: "sm",
|
||||||
{tags.length > 0 ? (
|
},
|
||||||
tags.map((tag) => {
|
}}
|
||||||
return (
|
>
|
||||||
<div
|
<Icon.Hash className="w-5 h-5 mx-auto" />
|
||||||
className="w-auto max-w-full text-black dark:text-gray-300 cursor-pointer rounded text-sm leading-6 px-2 hover:bg-zinc-200 dark:hover:bg-zinc-800 shrink-0"
|
</MenuButton>
|
||||||
onClick={() => onTagSelectorClick(tag)}
|
<Menu className="relative text-sm" size="sm" placement="bottom-start">
|
||||||
key={tag}
|
<ClickAwayListener
|
||||||
>
|
onClickAway={() => {
|
||||||
<OverflowTip>#{tag}</OverflowTip>
|
setOpen(false);
|
||||||
</div>
|
}}
|
||||||
);
|
>
|
||||||
})
|
{tags.length > 0 ? (
|
||||||
) : (
|
<div className="flex-row justify-start items-start flex-wrap px-1 max-w-[12rem] h-auto max-h-48 overflow-y-auto font-mono">
|
||||||
<p className="italic text-sm ml-2" onClick={(e) => e.stopPropagation()}>
|
{tags.map((tag) => {
|
||||||
No tags found
|
return (
|
||||||
</p>
|
<div
|
||||||
)}
|
className="inline-block w-auto max-w-full cursor-pointer rounded text-sm leading-6 px-2 hover:bg-zinc-100 dark:hover:bg-zinc-800 shrink-0"
|
||||||
</div>
|
onClick={() => handleTagClick(tag)}
|
||||||
</IconButton>
|
key={tag}
|
||||||
|
>
|
||||||
|
<OverflowTip>#{tag}</OverflowTip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="italic mx-1" onClick={(e) => e.stopPropagation()}>
|
||||||
|
No tag found
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</ClickAwayListener>
|
||||||
|
</Menu>
|
||||||
|
</Dropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Select, Option, Button, IconButton, Divider } from "@mui/joy";
|
import { Select, Option, Button, IconButton, Divider } from "@mui/joy";
|
||||||
import { uniqBy } from "lodash-es";
|
import { uniqBy } from "lodash-es";
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useLocalStorage from "react-use/lib/useLocalStorage";
|
import useLocalStorage from "react-use/lib/useLocalStorage";
|
||||||
@ -335,10 +335,6 @@ const MemoEditor = (props: Props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTagSelectorClick = useCallback((tag: string) => {
|
|
||||||
editorRef.current?.insertText(`#${tag} `);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleEditorFocus = () => {
|
const handleEditorFocus = () => {
|
||||||
editorRef.current?.focus();
|
editorRef.current?.focus();
|
||||||
};
|
};
|
||||||
@ -368,20 +364,12 @@ const MemoEditor = (props: Props) => {
|
|||||||
>
|
>
|
||||||
<Editor ref={editorRef} {...editorConfig} />
|
<Editor ref={editorRef} {...editorConfig} />
|
||||||
<div className="relative w-full flex flex-row justify-between items-center pt-2" onFocus={(e) => e.stopPropagation()}>
|
<div className="relative w-full flex flex-row justify-between items-center pt-2" onFocus={(e) => e.stopPropagation()}>
|
||||||
<div className="flex flex-row justify-start items-center">
|
<div className="flex flex-row justify-start items-center opacity-80">
|
||||||
<TagSelector onTagSelectorClick={(tag) => handleTagSelectorClick(tag)} />
|
<TagSelector editorRef={editorRef} />
|
||||||
<IconButton
|
<IconButton size="sm" onClick={handleUploadFileBtnClick}>
|
||||||
className="flex flex-row justify-center items-center p-1 w-auto h-auto mr-1 select-none rounded cursor-pointer text-gray-600 dark:!text-gray-400 hover:bg-gray-300 dark:hover:bg-zinc-800 hover:shadow"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleUploadFileBtnClick}
|
|
||||||
>
|
|
||||||
<Icon.Image className="w-5 h-5 mx-auto" />
|
<Icon.Image className="w-5 h-5 mx-auto" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton size="sm" onClick={handleAddMemoRelationBtnClick}>
|
||||||
className="flex flex-row justify-center items-center p-1 w-auto h-auto mr-1 select-none rounded cursor-pointer text-gray-600 dark:!text-gray-400 hover:bg-gray-300 dark:hover:bg-zinc-800 hover:shadow"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleAddMemoRelationBtnClick}
|
|
||||||
>
|
|
||||||
<Icon.Link className="w-5 h-5 mx-auto" />
|
<Icon.Link className="w-5 h-5 mx-auto" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<MarkdownMenu editorRef={editorRef} />
|
<MarkdownMenu editorRef={editorRef} />
|
||||||
|
Reference in New Issue
Block a user