乱了, 懒得说是什么
This commit is contained in:
13
client/env.d.ts
vendored
13
client/env.d.ts
vendored
@@ -1,6 +1,19 @@
|
||||
/// <reference types="mdui/jsx.zh-cn.d.ts" />
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
// 貌似没有起效
|
||||
declare global {
|
||||
namespace React {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
'input-element': {
|
||||
'value'?: string
|
||||
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare const __APP_VERSION__: string
|
||||
declare const __GIT_HASH__: string
|
||||
declare const __GIT_HASH_FULL__: string
|
||||
|
||||
24
client/ui/InnerTextContainerElement.ts
Normal file
24
client/ui/InnerTextContainerElement.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export default class InnerTextContainerElement extends HTMLElement {
|
||||
static observedAttributes = ['text']
|
||||
declare textContainer: HTMLDivElement
|
||||
declare slotContainer: HTMLSlotElement
|
||||
declare text?: string
|
||||
constructor() {
|
||||
super()
|
||||
this.attachShadow({ mode: 'open' })
|
||||
}
|
||||
connectedCallback() {
|
||||
this.shadowRoot!.appendChild(document.createElement('slot'))
|
||||
}
|
||||
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
||||
if (this.textContainer == null) {
|
||||
this.textContainer = document.createElement('div')
|
||||
// 注意这里不能加到 shadow
|
||||
this.appendChild(this.textContainer)
|
||||
this.textContainer.style.display = 'none'
|
||||
}
|
||||
this.textContainer.innerText = newValue || ''
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('inner-text-container', InnerTextContainerElement)
|
||||
@@ -7,7 +7,7 @@ type AppState = {
|
||||
openUserInfo: (user: Chat | User | string) => void,
|
||||
openEditMyProfile: () => void,
|
||||
openAddFavouriteChat: () => void,
|
||||
openChat: (chat: string | Chat) => void,
|
||||
openChat: (chat: string | Chat, inDialog?: boolean) => void,
|
||||
closeChat: () => void,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import MainSharedContext, { Shared } from "../MainSharedContext"
|
||||
import ChatFragmentDialog from "./ChatFragmentDialog"
|
||||
import useAsyncEffect from "../../utils/useAsyncEffect"
|
||||
import ClientCache from "../../ClientCache"
|
||||
import isMobileUI from "../../utils/isMobileUI"
|
||||
|
||||
const config = await fetch('/config.json').then((re) => re.json())
|
||||
|
||||
@@ -42,7 +43,6 @@ export default function DialogContextWrapper({ children, useRef }: { children: R
|
||||
MainSharedContext,
|
||||
(context: Shared) => context.state.currentSelectedChatId
|
||||
)
|
||||
const [useChatFragmentDialog, setUseChatFragmentDialog] = React.useState(false)
|
||||
const chatFragmentDialogRef = React.useRef<Dialog>()
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
@@ -70,11 +70,10 @@ export default function DialogContextWrapper({ children, useRef }: { children: R
|
||||
static async openChat(chat: string | Chat, inDialog?: boolean) {
|
||||
if (chat instanceof Chat) chat = chat.getId()
|
||||
|
||||
setUseChatFragmentDialog(inDialog || false)
|
||||
setUserOrChatInfoDialogState([])
|
||||
setCurrentSelectedChatId(chat)
|
||||
|
||||
useChatFragmentDialog && (chatFragmentDialogRef.current!.open = true)
|
||||
inDialog && (chatFragmentDialogRef.current!.open = true)
|
||||
}
|
||||
static closeChat() {
|
||||
if (chatFragmentDialogRef.current!.open) {
|
||||
@@ -85,10 +84,10 @@ export default function DialogContextWrapper({ children, useRef }: { children: R
|
||||
setCurrentSelectedChatId('')
|
||||
}
|
||||
}}>
|
||||
{<ChatFragmentDialog chatId={currentSelectedChatId} useRef={chatFragmentDialogRef} />}
|
||||
<UserOrChatInfoDialog chat={userOrChatInfoDialogState[userOrChatInfoDialogState.length - 1] || lastUserOrChatInfoDialogStateRef.current} useRef={userOrChatInfoDialogRef} />
|
||||
<EditMyProfileDialog useRef={editMyProfileDialogRef} />
|
||||
<AddFavourtieChatDialog useRef={addFavouriteChatDialogRef} />
|
||||
{useChatFragmentDialog && currentSelectedChatId && currentSelectedChatId != '' && <ChatFragmentDialog chatId={currentSelectedChatId} useRef={chatFragmentDialogRef} />}
|
||||
{children}
|
||||
</AppStateContext.Provider>
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Dialog } from "mdui"
|
||||
import * as React from 'react'
|
||||
import LazyChatFragment from "../chat-fragment/LazyChatFragment"
|
||||
import useEventListener from "../../utils/useEventListener"
|
||||
|
||||
export default function ChatFragmentDialog({ chatId, useRef }: { chatId: string, useRef: React.MutableRefObject<Dialog | undefined> }) {
|
||||
React.useEffect(() => {
|
||||
useEventListener(useRef, 'open', () => {
|
||||
const shadow = useRef.current!.shadowRoot as ShadowRoot
|
||||
const panel = shadow.querySelector(".panel") as HTMLElement
|
||||
panel.style.padding = '0'
|
||||
@@ -13,14 +14,14 @@ export default function ChatFragmentDialog({ chatId, useRef }: { chatId: string,
|
||||
const body = shadow.querySelector(".body") as HTMLElement
|
||||
body.style.height = '100%'
|
||||
body.style.display = 'flex'
|
||||
}, [chatId])
|
||||
})
|
||||
|
||||
return <mdui-dialog fullscreen ref={useRef}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
width: '100%',
|
||||
}}>
|
||||
<LazyChatFragment chatId={chatId} openedInDialog={true} />
|
||||
{chatId != null && chatId != '' && <LazyChatFragment chatId={chatId} openedInDialog={true} />}
|
||||
</div>
|
||||
</mdui-dialog>
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export default function UserOrChatInfoDialog({ chat, useRef }: { chat?: Chat, us
|
||||
})}>{favourited ? '取消收藏' : '收藏对话'}</mdui-list-item>
|
||||
}
|
||||
<mdui-list-item icon="chat" rounded onClick={async () => {
|
||||
AppState.openChat(chat!)
|
||||
AppState.openChat(chat!, isMobileUI())
|
||||
}}>打开对话</mdui-list-item>
|
||||
</mdui-list>
|
||||
</mdui-dialog>
|
||||
|
||||
@@ -37,18 +37,14 @@ export default class ChatMentionElement extends HTMLElement {
|
||||
const text = $(this).attr('text')
|
||||
this.link.style.fontStyle = ''
|
||||
if (chatId) {
|
||||
|
||||
this.link.onclick = (e) => {
|
||||
e.stopPropagation()
|
||||
// deno-lint-ignore no-window
|
||||
|
||||
this.openChatInfo?.(chatId)
|
||||
}
|
||||
} else if (userId) {
|
||||
|
||||
this.link.onclick = (e) => {
|
||||
e.stopPropagation()
|
||||
// deno-lint-ignore no-window
|
||||
|
||||
this.openUserInfo?.(userId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ export default function ChatFragment({
|
||||
}} onDrop={(e) => {
|
||||
// 文件拽入
|
||||
}}>
|
||||
<mdui-text-field variant="outlined" placeholder="(。・ω・。)" autosize ref={inputRef} max-rows={6} onChange={() => {
|
||||
<mdui-text-field variant="outlined" placeholder="(。・ω・。)" autosize ref={inputRef} /* max-rows={6} */ onChange={() => {
|
||||
if (inputRef.current?.value.trim() == '') {
|
||||
// 清空缓存的文件
|
||||
}
|
||||
@@ -181,7 +181,12 @@ export default function ChatFragment({
|
||||
marginRight: '10px',
|
||||
marginTop: '3px',
|
||||
marginBottom: '3px',
|
||||
}}></mdui-text-field>
|
||||
}}>
|
||||
{
|
||||
// @ts-ignore
|
||||
<input-element slot="input" />
|
||||
}
|
||||
</mdui-text-field>
|
||||
<mdui-button-icon slot="end-icon" icon="attach_file" style={{
|
||||
marginRight: '6px',
|
||||
}} onClick={() => {
|
||||
|
||||
@@ -77,7 +77,7 @@ export default function RecentChatsList({ ...props }: React.HTMLAttributes<HTMLE
|
||||
).map((v) =>
|
||||
<RecentsListItem
|
||||
active={isMobileUI() ? false : shared.state.currentSelectedChatId == v.getId()}
|
||||
onClick={() => AppState.openChat(v.getId())}
|
||||
onClick={() => AppState.openChat(v.getId(), isMobileUI())}
|
||||
key={v.getId()}
|
||||
recentChat={v} />
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import data from "../data"
|
||||
|
||||
const searchParams = new URL(location.href).searchParams
|
||||
|
||||
export default function isMobileUI() {
|
||||
return data.override_use_mobile_ui || /Mobi|Android|iPhone/i.test(navigator.userAgent)
|
||||
return data.override_use_mobile_ui || searchParams.get('mobile') == 'true' || /Mobi|Android|iPhone/i.test(navigator.userAgent)
|
||||
}
|
||||
Reference in New Issue
Block a user