From bef576a77bc995e8eaf57de212a233081be34727 Mon Sep 17 00:00:00 2001 From: molvqingtai Date: Sun, 27 Oct 2024 09:02:56 +0800 Subject: [PATCH] feat: support @user syntax --- .github/workflows/cd.yml | 2 +- .husky/pre-commit | 2 +- eslint.config.ts | 2 +- package.json | 4 +- pnpm-lock.yaml | 6 + src/app/content/components/MessageInput.tsx | 57 ++-- src/app/content/components/MessageItem.tsx | 20 +- src/app/content/views/AppButton/index.tsx | 20 +- src/app/content/views/AppMain/index.tsx | 4 +- src/app/content/views/Footer/index.tsx | 279 ++++++++++++++++++-- src/app/content/views/Header/index.tsx | 32 ++- src/app/content/views/Setup/index.tsx | 6 +- src/app/options/components/ProfileForm.tsx | 111 +++++--- src/assets/styles/sonner.css | 7 +- src/assets/styles/tailwind.css | 7 - src/components/ui/Popover.tsx | 5 +- src/components/ui/Textarea.tsx | 2 +- src/components/ui/checkbox.tsx | 14 +- src/domain/MessageList.ts | 5 + src/domain/Notification.ts | 15 +- src/domain/Room.ts | 13 +- src/domain/UserInfo.ts | 1 + src/hooks/useClickAway.ts | 51 ---- src/hooks/useCursorPosition.ts | 41 +++ src/hooks/useDarg.ts | 9 +- src/hooks/useResizable.ts | 15 +- src/hooks/useShareRef.ts | 21 ++ src/hooks/useTriggerAway.ts | 52 ++++ src/utils/getCursorPosition.ts | 74 ++++++ src/utils/getTextSimilarity.ts | 45 ++++ src/utils/index.ts | 2 + 31 files changed, 722 insertions(+), 202 deletions(-) delete mode 100644 src/hooks/useClickAway.ts create mode 100644 src/hooks/useCursorPosition.ts create mode 100644 src/hooks/useShareRef.ts create mode 100644 src/hooks/useTriggerAway.ts create mode 100644 src/utils/getCursorPosition.ts create mode 100644 src/utils/getTextSimilarity.ts diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index fe2b121..6b700a5 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -21,7 +21,7 @@ jobs: - run: pnpm install --ignore-scripts - run: pnpm wxt prepare - run: pnpm run lint - - run: pnpm run tsc + - run: pnpm run check release: needs: linter diff --git a/.husky/pre-commit b/.husky/pre-commit index 31eaf1e..d8e461b 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,2 @@ -pnpm lint-staged && pnpm tsc +pnpm lint-staged && pnpm check diff --git a/eslint.config.ts b/eslint.config.ts index e58683f..943cd60 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,4 +1,4 @@ -import type { Linter } from 'eslint' +// import type { Linter } from 'eslint' import globals from 'globals' import pluginJs from '@eslint/js' import tseslint from 'typescript-eslint' diff --git a/package.json b/package.json index 82e9733..273961f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "pack:firefox": "wxt zip -b firefox", "lint": "eslint --fix --flag unstable_ts_config", "clear": "rimraf .output", - "tsc": "tsc --noEmit", + "check": "tsc --noEmit", "prepare": "husky", "postinstall": "wxt prepare" }, @@ -54,6 +54,8 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-popover": "^1.1.2", + "@radix-ui/react-portal": "^1.1.2", + "@radix-ui/react-presence": "^1.1.1", "@radix-ui/react-radio-group": "^1.2.1", "@radix-ui/react-scroll-area": "^1.2.0", "@radix-ui/react-slot": "^1.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9db92b1..f413aaf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,12 @@ importers: '@radix-ui/react-popover': specifier: ^1.1.2 version: 1.1.2(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-portal': + specifier: ^1.1.2 + version: 1.1.2(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-presence': + specifier: ^1.1.1 + version: 1.1.1(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-radio-group': specifier: ^1.2.1 version: 1.2.1(@types/react-dom@18.3.1)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/src/app/content/components/MessageInput.tsx b/src/app/content/components/MessageInput.tsx index 706845a..b523a58 100644 --- a/src/app/content/components/MessageInput.tsx +++ b/src/app/content/components/MessageInput.tsx @@ -1,8 +1,7 @@ import { forwardRef, type ChangeEvent, CompositionEvent, type KeyboardEvent } from 'react' -import { Textarea } from '@/components/ui/Textarea' -import { Markdown } from '@/components/Markdown' import { cn } from '@/utils' +import { Textarea } from '@/components/ui/Textarea' import { ScrollArea } from '@/components/ui/ScrollArea' export interface MessageInputProps { @@ -13,11 +12,16 @@ export interface MessageInputProps { autoFocus?: boolean disabled?: boolean onInput?: (e: ChangeEvent) => void - onEnter?: (e: KeyboardEvent) => void + onKeyDown?: (e: KeyboardEvent) => void onCompositionStart?: (e: CompositionEvent) => void onCompositionEnd?: (e: CompositionEvent) => void } +/** + * Need @ syntax highlighting? Waiting for textarea to support Highlight API + * + * @see https://github.com/w3c/csswg-drafts/issues/4603 + */ const MessageInput = forwardRef( ( { @@ -25,44 +29,33 @@ const MessageInput = forwardRef( className, maxLength = 500, onInput, - onEnter, + onKeyDown, onCompositionStart, onCompositionEnd, - preview, autoFocus, disabled }, ref ) => { - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === 'Enter' && !(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)) { - e.preventDefault() - onEnter?.(e) - } - } - return (
- {preview ? ( - {value} - ) : ( - -