chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动

演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-18 13:59:25 +08:00
1 parent 60158935f4
commit 6519682885
15831 files changed
+3063428

No files matched your search

@@ -0,0 +1,55 @@
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useState } from 'react'
import FloatRightContainer from '../index'
it('opens mobile content in a named drawer and closes it through the supplied action', async () => {
const user = userEvent.setup()
const onClose = vi.fn()
function Harness() {
const [open, setOpen] = useState(false)
return (
<>
<button type="button" onClick={() => setOpen(true)}>
Open panel
</button>
<FloatRightContainer
isMobile
isOpen={open}
title="Mobile panel"
showClose
onClose={() => {
setOpen(false)
onClose()
}}
>
Mobile content
</FloatRightContainer>
</>
)
}
render(<Harness />)
await user.click(screen.getByRole('button', { name: 'Open panel' }))
expect(await screen.findByRole('dialog', { name: 'Mobile panel' })).toBeInTheDocument()
expect(screen.getByText('Mobile content')).toBeVisible()
await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
expect(onClose).toHaveBeenCalledOnce()
})
it('shows desktop content inline only while open', () => {
const { rerender } = render(
<FloatRightContainer isMobile={false} isOpen onClose={vi.fn()} title="Drawer title">
Desktop content
</FloatRightContainer>,
)
expect(screen.getByText('Desktop content')).toBeVisible()
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
expect(screen.queryByText('Drawer title')).not.toBeInTheDocument()
rerender(
<FloatRightContainer isMobile={false} isOpen={false} onClose={vi.fn()}>
Desktop content
</FloatRightContainer>,
)
expect(screen.queryByText('Desktop content')).not.toBeInTheDocument()
})
@@ -0,0 +1,75 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
import { useState } from 'react'
import { fn } from 'storybook/test'
import FloatRightContainer from '.'
const meta = {
title: 'Base/Feedback/FloatRightContainer',
component: FloatRightContainer,
parameters: {
layout: 'fullscreen',
docs: {
description: {
component:
'Wrapper that renders content in a drawer on mobile and inline on desktop. Useful for responsive settings panels.',
},
},
},
tags: ['autodocs'],
} satisfies Meta<typeof FloatRightContainer>
export default meta
type Story = StoryObj<typeof meta>
const ContainerDemo = () => {
const [open, setOpen] = useState(false)
const [isMobile, setIsMobile] = useState(false)
return (
<div className="flex h-90 flex-col gap-4 bg-background-default-subtle p-6">
<div className="flex items-center gap-3">
<button
type="button"
className="rounded-md bg-primary-600 px-3 py-1.5 text-sm font-medium text-white shadow-sm hover:bg-primary-700"
onClick={() => setOpen(true)}
>
Open panel
</button>
<label className="flex items-center gap-1 text-xs text-text-secondary">
<input
type="checkbox"
checked={isMobile}
onChange={(e) => setIsMobile(e.target.checked)}
/>
Simulate mobile
</label>
</div>
<FloatRightContainer
isMobile={isMobile}
isOpen={open}
onClose={() => setOpen(false)}
title="Responsive panel"
mask
>
<div className="rounded-xl border border-divider-subtle bg-components-panel-bg p-4 text-xs text-text-secondary">
<p className="mb-2 text-sm text-text-primary">Panel Content</p>
<p>
On desktop, this block renders inline when `isOpen` is true. On mobile it appears inside
the drawer wrapper.
</p>
</div>
</FloatRightContainer>
</div>
)
}
export const Playground: Story = {
render: () => <ContainerDemo />,
args: {
isMobile: false,
isOpen: false,
onClose: fn(),
children: null,
},
}
@@ -0,0 +1,96 @@
'use client'
import type { DrawerPopupProps } from '@langgenius/dify-ui/drawer'
import { cn } from '@langgenius/dify-ui/cn'
import {
Drawer,
DrawerBackdrop,
DrawerClose,
DrawerContent,
DrawerPopup,
DrawerPortal,
DrawerTitle,
DrawerViewport,
} from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { useTranslation } from 'react-i18next'
type IFloatRightContainerProps = Pick<DrawerPopupProps, 'finalFocus'> & {
isMobile: boolean
isOpen: boolean
onClose: () => void
children?: React.ReactNode
showClose?: boolean
panelClassName?: string
title?: string
mask?: boolean
}
const FloatRightContainer = ({
isMobile,
children,
isOpen,
onClose,
showClose = false,
panelClassName,
title,
mask = true,
finalFocus,
}: IFloatRightContainerProps) => {
const { t } = useTranslation(['common'])
return (
<>
{isMobile && (
<Drawer
open={isOpen}
modal
swipeDirection="right"
onOpenChange={(open) => {
if (!open) onClose()
}}
>
<DrawerPortal>
<DrawerBackdrop className={cn(!mask && 'bg-transparent')} />
<DrawerViewport>
<DrawerPopup
finalFocus={finalFocus}
className={cn(
'data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-sm',
panelClassName,
)}
>
<DrawerContent className="flex min-h-0 flex-1 flex-col">
{(title || showClose) && (
<div className="mb-4 flex shrink-0 items-center justify-between">
{title && (
<DrawerTitle className="text-lg/6 font-medium text-text-primary">
{title}
</DrawerTitle>
)}
{showClose && (
<DrawerClose
render={
<IconButton
aria-label={t(($) => $['operation.close'], { ns: 'common' })}
size="md"
>
<span aria-hidden="true" className="i-ri-close-line size-4" />
</IconButton>
}
/>
)}
</div>
)}
{children}
</DrawerContent>
</DrawerPopup>
</DrawerViewport>
</DrawerPortal>
</Drawer>
)}
{!isMobile && isOpen && <>{children}</>}
</>
)
}
export default FloatRightContainer