From a51fb24f36f24f75d393f4637ea9b60754f7d596 Mon Sep 17 00:00:00 2001 From: licoy Date: Thu, 27 Jun 2024 15:13:45 +0800 Subject: [PATCH 01/43] fix ts error --- app/components/error.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/components/error.tsx b/app/components/error.tsx index 914740f9686..c90997d1166 100644 --- a/app/components/error.tsx +++ b/app/components/error.tsx @@ -1,3 +1,5 @@ +"use client"; + import React from "react"; import { IconButton } from "./button"; import GithubIcon from "../icons/github.svg"; From fa6ebadc7b78cb023dc15705207ce2d180298edf Mon Sep 17 00:00:00 2001 From: licoy Date: Thu, 27 Jun 2024 15:35:16 +0800 Subject: [PATCH 02/43] feat: add plugin entry selection --- app/components/sidebar.tsx | 25 +++++++++++++++++++++---- app/components/ui-lib.module.scss | 4 ++++ app/components/ui-lib.tsx | 18 ++++++++++++------ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index 69b2e71f871..ea4d70dbb58 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useMemo } from "react"; +import React, { useEffect, useRef, useMemo, useState } from "react"; import styles from "./home.module.scss"; @@ -15,7 +15,7 @@ import DragIcon from "../icons/drag.svg"; import Locale from "../locales"; -import { useAppConfig, useChatStore } from "../store"; +import { ModelType, useAppConfig, useChatStore } from "../store"; import { DEFAULT_SIDEBAR_WIDTH, @@ -29,7 +29,7 @@ import { import { Link, useNavigate } from "react-router-dom"; import { isIOS, useMobileScreen } from "../utils"; import dynamic from "next/dynamic"; -import { showConfirm, showToast } from "./ui-lib"; +import { Selector, showConfirm, showToast } from "./ui-lib"; const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { loading: () => null, @@ -140,6 +140,7 @@ export function SideBar(props: { className?: string }) { () => isIOS() && isMobileScreen, [isMobileScreen], ); + const [showPluginSelector, setShowPluginSelector] = useState(false); useHotKey(); @@ -183,7 +184,7 @@ export function SideBar(props: { className?: string }) { icon={} text={shouldNarrow ? undefined : Locale.Plugin.Name} className={styles["sidebar-bar-button"]} - onClick={() => showToast(Locale.WIP)} + onClick={() => setShowPluginSelector(true)} shadow /> @@ -245,6 +246,22 @@ export function SideBar(props: { className?: string }) { > + {showPluginSelector && ( + setShowPluginSelector(false)} + onSelection={(s) => { + console.log("go to page: ", s); + }} + /> + )} ); } diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 83c02f92a23..ee17746f4ab 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -291,6 +291,10 @@ justify-content: center; z-index: 999; + .selector-item-disabled{ + opacity: 0.6; + } + &-content { .list { max-height: 90vh; diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index da700c0fb7c..26e0f4af1d4 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -13,7 +13,7 @@ import MinIcon from "../icons/min.svg"; import Locale from "../locales"; import { createRoot } from "react-dom/client"; -import React, { HTMLProps, useEffect, useState } from "react"; +import React, { HTMLProps, MouseEvent, useEffect, useState } from "react"; import { IconButton } from "./button"; export function Popover(props: { @@ -47,7 +47,7 @@ export function ListItem(props: { children?: JSX.Element | JSX.Element[]; icon?: JSX.Element; className?: string; - onClick?: () => void; + onClick?: (event: MouseEvent) => void; }) { return (
(props: { title: string; subTitle?: string; value: T; + disable?: boolean; }>; defaultSelectedValue?: T; onSelection?: (selection: T[]) => void; @@ -456,13 +457,18 @@ export function Selector(props: { const selected = props.defaultSelectedValue === item.value; return ( { - props.onSelection?.([item.value]); - props.onClose?.(); + onClick={(event) => { + event.stopPropagation(); + if (!item.disable) { + props.onSelection?.([item.value]); + props.onClose?.(); + } }} > {selected ? ( From d21481173e5c8eeb89024216acb164930ba31175 Mon Sep 17 00:00:00 2001 From: licoy Date: Thu, 27 Jun 2024 16:06:15 +0800 Subject: [PATCH 03/43] feat: add SD page switching --- app/components/home.tsx | 3 +++ app/components/sd-list.module.scss | 0 app/components/sd-list.tsx | 3 +++ app/components/sd.module.scss | 0 app/components/sd.tsx | 3 +++ app/components/sidebar.tsx | 32 +++++++++++++++++++++++++----- app/constant.ts | 3 +++ 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 app/components/sd-list.module.scss create mode 100644 app/components/sd-list.tsx create mode 100644 app/components/sd.module.scss create mode 100644 app/components/sd.tsx diff --git a/app/components/home.tsx b/app/components/home.tsx index ffac64fdac0..99755cc2032 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -1,5 +1,7 @@ "use client"; +import { Sd } from "@/app/components/sd"; + require("../polyfill"); import { useState, useEffect } from "react"; @@ -159,6 +161,7 @@ function Screen() { } /> } /> } /> + } /> } />
diff --git a/app/components/sd-list.module.scss b/app/components/sd-list.module.scss new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/components/sd-list.tsx b/app/components/sd-list.tsx new file mode 100644 index 00000000000..ba42919a54d --- /dev/null +++ b/app/components/sd-list.tsx @@ -0,0 +1,3 @@ +export function SdList() { + return
sd-list
; +} diff --git a/app/components/sd.module.scss b/app/components/sd.module.scss new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/components/sd.tsx b/app/components/sd.tsx new file mode 100644 index 00000000000..5341e5387c9 --- /dev/null +++ b/app/components/sd.tsx @@ -0,0 +1,3 @@ +export function Sd() { + return
sd
; +} diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index ea4d70dbb58..a06262fefb0 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -23,18 +23,24 @@ import { MIN_SIDEBAR_WIDTH, NARROW_SIDEBAR_WIDTH, Path, + PLUGINS, REPO_URL, } from "../constant"; -import { Link, useNavigate } from "react-router-dom"; +import { Link, useLocation, useNavigate } from "react-router-dom"; import { isIOS, useMobileScreen } from "../utils"; import dynamic from "next/dynamic"; import { Selector, showConfirm, showToast } from "./ui-lib"; +import de from "@/app/locales/de"; const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { loading: () => null, }); +const SdList = dynamic(async () => (await import("./sd-list")).SdList, { + loading: () => null, +}); + function useHotKey() { const chatStore = useChatStore(); @@ -141,9 +147,20 @@ export function SideBar(props: { className?: string }) { [isMobileScreen], ); const [showPluginSelector, setShowPluginSelector] = useState(false); + const location = useLocation(); useHotKey(); + let bodyComponent: React.JSX.Element; + let isChat: boolean; + switch (location.pathname) { + case Path.Sd: + bodyComponent = ; + break; + default: + isChat = true; + bodyComponent = ; + } return (
{ - if (e.target === e.currentTarget) { + if (isChat && e.target === e.currentTarget) { navigate(Path.Home); } }} > - + {bodyComponent}
@@ -254,11 +271,16 @@ export function SideBar(props: { className?: string }) { value: "-", disable: true, }, - { title: "Stable Diffusion", value: "sd" }, + ...PLUGINS.map((item) => { + return { + title: item.name, + value: item.path, + }; + }), ]} onClose={() => setShowPluginSelector(false)} onSelection={(s) => { - console.log("go to page: ", s); + navigate(s[0], { state: { fromHome: true } }); }} /> )} diff --git a/app/constant.ts b/app/constant.ts index 411e481508d..c56f77cb9da 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -21,6 +21,7 @@ export enum Path { NewChat = "/new-chat", Masks = "/masks", Auth = "/auth", + Sd = "/sd", } export enum ApiPath { @@ -213,3 +214,5 @@ export const internalAllowedWebDavEndpoints = [ "https://webdav.yandex.com", "https://app.koofr.net/dav/Koofr", ]; + +export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }]; From 34034be0e3ccba51214cb7fac7cd7bae2033ff58 Mon Sep 17 00:00:00 2001 From: licoy Date: Thu, 27 Jun 2024 16:13:51 +0800 Subject: [PATCH 04/43] hide new chat button on sd page --- app/components/sidebar.tsx | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index a06262fefb0..91ddd4c2355 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -152,7 +152,7 @@ export function SideBar(props: { className?: string }) { useHotKey(); let bodyComponent: React.JSX.Element; - let isChat: boolean; + let isChat: boolean = false; switch (location.pathname) { case Path.Sd: bodyComponent = ; @@ -161,6 +161,7 @@ export function SideBar(props: { className?: string }) { isChat = true; bodyComponent = ; } + // @ts-ignore return (
-
- } - text={shouldNarrow ? undefined : Locale.Home.NewChat} - onClick={() => { - if (config.dontShowMaskSplashScreen) { - chatStore.newSession(); - navigate(Path.Chat); - } else { - navigate(Path.NewChat); - } - }} - shadow - /> -
+ {isChat && ( +
+ } + text={shouldNarrow ? undefined : Locale.Home.NewChat} + onClick={() => { + if (config.dontShowMaskSplashScreen) { + chatStore.newSession(); + navigate(Path.Chat); + } else { + navigate(Path.NewChat); + } + }} + shadow + /> +
+ )}
Date: Tue, 2 Jul 2024 10:24:19 +0800 Subject: [PATCH 05/43] Improve the Stability parameter control panel --- app/components/button.tsx | 3 + app/components/sd-list.module.scss | 0 app/components/sd-list.tsx | 3 - app/components/sd-panel.module.scss | 33 +++++ app/components/sd-panel.tsx | 220 ++++++++++++++++++++++++++++ app/components/sidebar.tsx | 4 +- app/components/ui-lib.module.scss | 13 ++ app/components/ui-lib.tsx | 7 +- app/locales/cn.ts | 10 ++ app/locales/en.ts | 11 +- app/styles/globals.scss | 3 +- 11 files changed, 299 insertions(+), 8 deletions(-) delete mode 100644 app/components/sd-list.module.scss delete mode 100644 app/components/sd-list.tsx create mode 100644 app/components/sd-panel.module.scss create mode 100644 app/components/sd-panel.tsx diff --git a/app/components/button.tsx b/app/components/button.tsx index 7a5633924c5..c6039acc292 100644 --- a/app/components/button.tsx +++ b/app/components/button.tsx @@ -1,6 +1,7 @@ import * as React from "react"; import styles from "./button.module.scss"; +import { CSSProperties } from "react"; export type ButtonType = "primary" | "danger" | null; @@ -16,6 +17,7 @@ export function IconButton(props: { disabled?: boolean; tabIndex?: number; autoFocus?: boolean; + style?: CSSProperties; }) { return (