From d4a42d437fff49eff62791d6a0cfe6b5dbf1300d Mon Sep 17 00:00:00 2001 From: JinhyeokLee Date: Sat, 24 Jun 2023 04:18:38 +0900 Subject: [PATCH] refactor(store): Use central element store, add Coder --- manifest.json | 2 +- package.json | 12 +- src/App.tsx | 151 +++--- src/comp/coder2/Files.tsx | 68 +++ src/comp/coder2/Languages.tsx | 149 ++++++ src/comp/coder2/Main.tsx | 141 ++++++ src/comp/coder2/Markdown.tsx | 43 ++ src/comp/coder2/Prepare.tsx | 136 ++++++ src/comp/modals/CoderModal2.tsx | 117 +++++ src/comp/modals/SerializerModal.tsx | 84 +++- src/comp/modals/TokenReaderModal.tsx | 17 +- src/comp/workers/ClickThrougher.tsx | 83 ++-- src/comp/workers/ContinueClicker.tsx | 63 +-- src/comp/workers/ConversationMenu.tsx | 215 +------- src/comp/workers/EditWatcher.tsx | 41 -- src/comp/workers/InputWatcher.tsx | 122 ----- src/comp/workers/MessageSerializer.tsx | 26 +- src/comp/workers/MutationWatcher.tsx | 25 - src/comp/workers/TextAreaAugmenter.tsx | 149 ++++++ src/lib/elementPromises.ts | 1 + src/lib/hooks/useApplyClassName.ts | 13 + src/lib/hooks/useCoder2.ts | 458 ++++++++++++++++++ src/lib/hooks/useDetachment.ts | 58 --- src/lib/hooks/useElements.ts | 25 - src/lib/hooks/useJson.ts | 8 +- src/lib/hooks/useTarget.ts | 102 +++- src/lib/hooks/workers/useContinueClicker.ts | 44 ++ src/lib/hooks/workers/useConversationMenu.tsx | 243 ++++++++++ src/lib/hooks/workers/useElements.ts | 255 ++++++++++ src/lib/hooks/workers/useMessageSerializer.ts | 28 ++ .../hooks/workers/useTextarea.ts} | 172 ++++--- src/lib/install.ts | 9 +- src/lib/messageSerializer.ts | 8 +- src/lib/textExpander.ts | 2 +- src/lib/utils.ts | 7 + vite.config.rollup.js | 3 + yarn.lock | 335 ++++++++++++- 37 files changed, 2615 insertions(+), 800 deletions(-) create mode 100644 src/comp/coder2/Files.tsx create mode 100644 src/comp/coder2/Languages.tsx create mode 100644 src/comp/coder2/Main.tsx create mode 100644 src/comp/coder2/Markdown.tsx create mode 100644 src/comp/coder2/Prepare.tsx create mode 100644 src/comp/modals/CoderModal2.tsx delete mode 100644 src/comp/workers/EditWatcher.tsx delete mode 100644 src/comp/workers/InputWatcher.tsx delete mode 100644 src/comp/workers/MutationWatcher.tsx create mode 100644 src/comp/workers/TextAreaAugmenter.tsx create mode 100644 src/lib/hooks/useApplyClassName.ts create mode 100644 src/lib/hooks/useCoder2.ts delete mode 100644 src/lib/hooks/useDetachment.ts delete mode 100644 src/lib/hooks/useElements.ts create mode 100644 src/lib/hooks/workers/useContinueClicker.ts create mode 100644 src/lib/hooks/workers/useConversationMenu.tsx create mode 100644 src/lib/hooks/workers/useElements.ts create mode 100644 src/lib/hooks/workers/useMessageSerializer.ts rename src/{comp/workers/SelectionWatcher.tsx => lib/hooks/workers/useTextarea.ts} (60%) create mode 100644 src/lib/utils.ts diff --git a/manifest.json b/manifest.json index a6d45e6..d1f782e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "ChatGPT Augment", - "version": "1.7.3", + "version": "1.8.0", "description": "Enhance chat with ChatGPT-Augment: auto-continue, macros, token count, prompts, gradients, JSON format.", "content_scripts": [ { diff --git a/package.json b/package.json index 551706f..835921d 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,20 @@ { "name": "chatgpt-augment", "private": true, - "version": "1.7.3", + "version": "1.8.0", "type": "module", "license": "WTFPL", "scripts": { "build": "node ./scripts/match-versions.mjs && tsc && NODE_ENV=production vite build && NODE_ENV=production node ./scripts/add-banners.mjs", + "build-lex": "node ./scripts/match-versions.mjs && NODE_ENV=production vite build", "dev": "vite dev", + "watch": "nodemon --watch src --ext ts,tsx -x \"concurrently -n 'Build,TSC' -c 'blue.bold,green.bold' 'yarn build-lex' 'tsc'\"", "preview": "vite preview" }, "devDependencies": { "@crxjs/vite-plugin": "beta", "@types/chrome": "^0.0.237", + "@types/jszip": "^3.4.1", "@types/lodash": "^4.14.195", "@types/marked": "^5.0.0", "@types/node-emoji": "^1.8.2", @@ -19,6 +22,8 @@ "@types/react-dom": "^18.2.4", "@vitejs/plugin-react-swc": "^3.3.2", "chokidar-cli": "^3.0.0", + "concurrently": "^8.2.0", + "nodemon": "^2.0.22", "rollup-plugin-visualizer": "^5.9.0", "typescript": "^5.0.2", "vite": "^4.3.9" @@ -29,14 +34,17 @@ "@mantine/hooks": "^6.0.13", "@mantine/notifications": "^6.0.13", "@radix-ui/react-slot": "^1.0.2", - "@tabler/icons-react": "^2.21.0", + "@tabler/icons-react": "^2.22.0", "chrono-node": "^2.6.3", + "json5": "^2.2.3", + "jszip": "^3.10.1", "lodash": "^4.17.21", "marked": "^5.1.0", "node-emoji": "^2.0.2", "node-html-markdown": "^1.3.0", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-wrap-balancer": "^1.0.0", "reactflow": "^11.7.2" }, "packageManager": "yarn@3.6.0" diff --git a/src/App.tsx b/src/App.tsx index 9be0cbe..d00f8ed 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,26 +1,27 @@ -import { MutationWatcher } from "@/comp/workers/MutationWatcher"; import { + Box, ColorSchemeProvider, Group, MantineProvider, - Portal, Text, + Tooltip, Transition, createEmotionCache, } from "@mantine/core"; -import { useToggle, useViewportSize } from "@mantine/hooks"; +import { useViewportSize } from "@mantine/hooks"; import { Notifications } from "@mantine/notifications"; -import { useEffect, useState } from "react"; -import json from "../package.json"; -import { JSONFormatter } from "./comp/modals/JSONFormatter"; +import { useEffect, useMemo, useState } from "react"; +import Balancer from "react-wrap-balancer"; +import { version } from "../package.json"; import { ClickThrougher } from "./comp/workers/ClickThrougher"; +import { ContinueWorker } from "./comp/workers/ContinueClicker"; import { ConversationMenu } from "./comp/workers/ConversationMenu"; -import { InputWatcher } from "./comp/workers/InputWatcher"; -import { SelectionWatcher } from "./comp/workers/SelectionWatcher"; +import { TextAreaAugmenter } from "./comp/workers/TextAreaAugmenter"; import { useCgptColorScheme } from "./lib/hooks/useColorScheme"; -import { useElements } from "./lib/hooks/useElements"; -import { useRootTarget } from "./lib/hooks/useTarget"; +import { useRootAnchor } from "./lib/hooks/useTarget"; +import { useElsUpdater } from "./lib/hooks/workers/useElements"; import { MessageSerializer } from "./comp/workers/MessageSerializer"; +import { CoderModal2 } from "./comp/modals/CoderModal2"; const cache = createEmotionCache({ key: "cgpt-agmt", @@ -29,16 +30,31 @@ const cache = createEmotionCache({ export const App = () => { const [colorScheme, setTheme] = useCgptColorScheme(); - const [target, orgHtml] = useRootTarget("form + div"); + const [mounted, setMounted] = useState(false); - const [visible, toggle] = useToggle([true, false]); - const isWide = useViewportSize().width > 500; - const { textarea, parent } = useElements(); + const isWide = useViewportSize().width > 600; + const [tgt, __html] = useRootAnchor(); + + const { width, height } = useElsUpdater(); // updates els on mutation + const wrapperStyle = useMemo( + () => + ({ + width, + height, + userSelect: "none", + backdropFilter: "blur(3px)", + zIndex: 1, + background: + colorScheme === "dark" + ? "rgb(52, 53, 64 , 0.5)" + : "rgb(255, 255, 255, 0.5)", + } as const), + [colorScheme, width, height] + ); useEffect(() => { - if (!target) setMounted(false); + setMounted(false); setTimeout(() => setMounted(true), 100); - }, [target]); - + }, [tgt]); return ( { } > - {target && ( - - - {(styles) => ( - + + {(styles) => ( + + + } + styles={{ + tooltip: { maxWidth: "90vw", whiteSpace: "pre-wrap" }, + }} + withArrow + withinPortal > - toggle()} - id="chatgpt-augment-app" - > - {isWide && `ChatGPT Augment `}v{json.version} + + {isWide && `ChatGPT Augment `}v{version} - toggle()} - dangerouslySetInnerHTML={{ __html: orgHtml }} - /> - - - {textarea && } - {textarea && } - - - - - )} - - - )} - {mounted && parent && } - - + + + + + + + + {/* BUTTONS / UI HERE */} + + )} + + + ); diff --git a/src/comp/coder2/Files.tsx b/src/comp/coder2/Files.tsx new file mode 100644 index 0000000..a193e0d --- /dev/null +++ b/src/comp/coder2/Files.tsx @@ -0,0 +1,68 @@ +import { useCoder } from "@/lib/hooks/useCoder2"; +import { ClassNames } from "@emotion/react"; +import { Paper, UnstyledButton, rem, useMantineTheme } from "@mantine/core"; +import { IconCircleDashed, IconFile, IconFileCheck } from "@tabler/icons-react"; + +export const Coder2Files = () => { + const [files, currentFile, handleFileSelect] = useCoder((s) => [ + s.files, + s.currentFile, + s.handlers.handleFileSelect, + ]); + const theme = useMantineTheme(); + return ( + + {({ css }) => ( + + {files.map((file) => ( + + {!file.content ? ( + + ) : file.reviewed ? ( + + ) : ( + + )}{" "} + {file.path} + + ))} + + )} + + ); +}; diff --git a/src/comp/coder2/Languages.tsx b/src/comp/coder2/Languages.tsx new file mode 100644 index 0000000..3933fae --- /dev/null +++ b/src/comp/coder2/Languages.tsx @@ -0,0 +1,149 @@ +import { Group, Select, Text } from "@mantine/core"; +import { + IconAbacus, + IconAssembly, + IconBrandCSharp, + IconBrandCpp, + IconBrandCss3, + IconBrandFirefox, + IconBrandGolang, + IconBrandJavascript, + IconBrandKotlin, + IconBrandPhp, + IconBrandPython, + IconBrandRust, + IconBrandSwift, + IconBrandTypescript, + IconBrandVisualStudio, + IconCoffee, + IconHtml, + IconLetterC, + IconLetterR, + IconPoint, + IconSql, +} from "@tabler/icons-react"; +import { ReactNode, forwardRef } from "react"; + +const LANGUAGES = [ + "Python", + "C", + "C++", + "Java", + "C#", + "Visual Basic", + "TypeScript", + "JavaScript", + "HTML", + "CSS3", + "CSS4", + "PHP", + "SQL", + "Go", + "R", + "Swift", + "Rust", + "Assembly language", + "Kotlin", + "MATLAB", + "Delphi", + "Object Pascal", + "Fortran", + "Classic Visual Basic", + "Ruby", + "FoxPro", + "COBOL", + "SAS", + "Objective-C", + "Perl", + "Ada", + "Julia", + "D", + "Transact-SQL", + "Haskell", + "Lua", + "Lisp", + "Dart", + "Scala", + "Prolog", + "PL/SQL", + "Scheme", + "VBScript", + "F#", + "ABAP", + "X++", + "CFML", + "Awk", + "ML", + "Raku", + "Forth", + "Apex", + "Elixir", + "Elm", + "PureScript", + "ReasonML", + "CoffeeScript", + "ClojureScript", + "Haxe", +] as const; + +type Languages = (typeof LANGUAGES)[number]; + +const LANGUAGE_ICONS: Partial> = { + Python: , + C: , + "C++": , + Java: , + "C#": , + "Visual Basic": , + JavaScript: , + PHP: , + Go: , + R: , + Swift: , + Rust: , + Kotlin: , + TypeScript: , + SQL: , + "Assembly language": , + MATLAB: , + HTML: , + CSS3: , + CSS4: , +}; + +const ItemComponent = forwardRef( + ({ value, ...rest }, ref) => { + return ( +
+ + {LANGUAGE_ICONS[value as keyof typeof LANGUAGE_ICONS] || ( + + )} + + + {value} + + +
+ ); + } +); +type Props = { value: string; onSelect(language: string): void }; +export const CoderLanguageSelector = ({ value, onSelect }: Props) => { + return ( +