From 9e13e339b8d55363b4c6831720f306f874abf010 Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Sun, 20 Sep 2026 01:40:49 +0000 Subject: [PATCH 01/29] feat(ui): add reusable breadcrumbs and migrate Web navigation (#42534) --- lint.config.ts | 9 + packages/dify-ui/README.md | 2 +- packages/dify-ui/docs/authoring.md | 8 + packages/dify-ui/package.json | 4 + packages/dify-ui/src/alert-dialog/index.tsx | 2 +- packages/dify-ui/src/autocomplete/index.tsx | 2 +- .../src/breadcrumb/__tests__/types.tsx | 42 + .../dify-ui/src/breadcrumb/index.stories.tsx | 300 +++++ packages/dify-ui/src/breadcrumb/index.tsx | 97 ++ .../src/button/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/checkbox/index.tsx | 2 +- .../dify-ui/src/collapsible/index.stories.tsx | 4 +- packages/dify-ui/src/combobox/index.tsx | 2 +- .../src/context-menu/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/context-menu/index.tsx | 2 +- packages/dify-ui/src/dialog/index.tsx | 2 +- packages/dify-ui/src/drawer/index.tsx | 2 +- .../dropdown-menu/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/dropdown-menu/index.tsx | 2 +- packages/dify-ui/src/icon-button/index.tsx | 2 +- packages/dify-ui/src/input-group/index.tsx | 2 +- packages/dify-ui/src/kbd/index.tsx | 2 +- packages/dify-ui/src/number-field/index.tsx | 2 +- packages/dify-ui/src/popover/index.tsx | 2 +- .../src/preview-card/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/preview-card/index.tsx | 2 +- packages/dify-ui/src/radio-group/index.tsx | 2 +- .../src/scroll-area/__tests__/index.spec.tsx | 2 +- .../dify-ui/src/scroll-area/index.stories.tsx | 2 +- .../__tests__/index.spec.tsx | 2 +- .../dify-ui/src/segmented-control/index.tsx | 2 +- packages/dify-ui/src/select/index.tsx | 2 +- packages/dify-ui/src/spinner/index.tsx | 4 +- packages/dify-ui/src/status-dot/index.tsx | 2 +- packages/dify-ui/src/switch/index.tsx | 2 +- .../src/textarea/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/textarea/index.tsx | 2 +- packages/dify-ui/src/toast/index.tsx | 2 +- .../src/tooltip/__tests__/index.spec.tsx | 2 +- packages/dify-ui/src/tooltip/index.tsx | 2 +- packages/dify-ui/tsconfig.json | 1 + .../components/app-sidebar/app-detail-top.tsx | 53 +- .../app-sidebar/dataset-detail-top.tsx | 53 +- .../add-member-or-group-pop.spec.tsx | 10 +- .../group-picker-layout.browser.spec.tsx | 62 + .../add-member-or-group-pop/breadcrumb.tsx | 98 +- .../add-member-or-group-pop/index.tsx | 10 +- .../breadcrumbs/__tests__/bucket.spec.tsx | 46 - .../breadcrumbs/__tests__/drive.spec.tsx | 63 - .../breadcrumbs/__tests__/index.spec.tsx | 1157 +++-------------- .../breadcrumbs/__tests__/item.spec.tsx | 48 - .../file-list/header/breadcrumbs/bucket.tsx | 78 +- .../file-list/header/breadcrumbs/drive.tsx | 28 +- .../dropdown/__tests__/index.spec.tsx | 819 ------------ .../dropdown/__tests__/item.spec.tsx | 54 - .../dropdown/__tests__/menu.spec.tsx | 89 -- .../header/breadcrumbs/dropdown/index.tsx | 65 +- .../header/breadcrumbs/dropdown/item.tsx | 21 - .../header/breadcrumbs/dropdown/menu.tsx | 27 - .../file-list/header/breadcrumbs/index.tsx | 116 +- .../file-list/header/breadcrumbs/item.tsx | 65 +- .../marketplace/creator-profile/view.tsx | 45 +- .../snippet-list/__tests__/index.spec.tsx | 4 + web/app/components/snippet-list/index.tsx | 37 +- .../__tests__/snippet-detail-top.spec.tsx | 38 + .../components/snippet-detail-top.tsx | 63 +- .../single-run-form.browser.spec.tsx | 41 + .../components/single-run-form.tsx | 43 +- .../__tests__/agent-log-nav.browser.spec.tsx | 39 + .../workflow/run/agent-log/agent-log-nav.tsx | 112 +- .../working-directory-breadcrumb.spec.tsx | 16 +- .../preview/working-directory-breadcrumb.tsx | 134 +- .../agent-v2/agent-detail/navigation.tsx | 50 +- .../new-rag/knowledge-space-shell.tsx | 46 +- web/features/skills/detail/file-tree.tsx | 47 +- 75 files changed, 1489 insertions(+), 2721 deletions(-) create mode 100644 packages/dify-ui/src/breadcrumb/__tests__/types.tsx create mode 100644 packages/dify-ui/src/breadcrumb/index.stories.tsx create mode 100644 packages/dify-ui/src/breadcrumb/index.tsx create mode 100644 web/app/components/app/app-access-control/__tests__/group-picker-layout.browser.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/__tests__/bucket.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/__tests__/drive.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/__tests__/item.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/dropdown/__tests__/index.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/dropdown/__tests__/item.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/dropdown/__tests__/menu.spec.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/dropdown/item.tsx delete mode 100644 web/app/components/datasets/documents/create-from-pipeline/data-source/online-drive/file-list/header/breadcrumbs/dropdown/menu.tsx create mode 100644 web/app/components/snippets/components/__tests__/snippet-detail-top.spec.tsx create mode 100644 web/app/components/workflow/nodes/human-input/components/__tests__/single-run-form.browser.spec.tsx create mode 100644 web/app/components/workflow/run/agent-log/__tests__/agent-log-nav.browser.spec.tsx diff --git a/lint.config.ts b/lint.config.ts index bf84dec886b..e543a0a153f 100644 --- a/lint.config.ts +++ b/lint.config.ts @@ -1153,6 +1153,15 @@ export const lintConfig = { { files: ['packages/dify-ui/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'], rules: { + 'unicorn/import-style': [ + 'error', + { + extendDefaultStyles: false, + styles: { + react: { namespace: true }, + }, + }, + ], 'react/exhaustive-deps': [ 'error', { diff --git a/packages/dify-ui/README.md b/packages/dify-ui/README.md index d124e42c99f..e27216366bc 100644 --- a/packages/dify-ui/README.md +++ b/packages/dify-ui/README.md @@ -43,7 +43,7 @@ Import `styles.css` once from the consumer's root stylesheet or entrypoint. | Form | `./form`, `./field`, `./fieldset`, `./input`, `./input-group`, `./textarea`, `./checkbox`, `./checkbox-group`, `./radio-group`, `./number-field`, `./select`, `./slider`, `./switch` | | Layout | `./scroll-area` | | Media | `./avatar` | -| Navigation | `./file-tree`, `./pagination`, `./tabs` | +| Navigation | `./breadcrumb`, `./file-tree`, `./pagination`, `./tabs` | | Overlay and menu | `./alert-dialog`, `./context-menu`, `./dialog`, `./drawer`, `./dropdown-menu`, `./popover`, `./preview-card`, `./tooltip` | | Search and pick | `./autocomplete`, `./combobox`, `./select` | diff --git a/packages/dify-ui/docs/authoring.md b/packages/dify-ui/docs/authoring.md index 536b744c872..20bcce9d05f 100644 --- a/packages/dify-ui/docs/authoring.md +++ b/packages/dify-ui/docs/authoring.md @@ -5,6 +5,14 @@ module-local and publish the complete surface through separate `export { ... }` `export type { ... }` manifests at the bottom of the file. Do not mix scattered inline exports with the manifest or use wildcard exports. +## React imports + +Use React namespace imports throughout this package, including stories and tests. Use +`import * as React from 'react'` when calling React runtime APIs, and +`import type * as React from 'react'` when referencing only React types. A runtime namespace +import also covers React types; do not add separate named type imports. JSX alone does not +require an explicit React import. + ## Subpaths and names Every public primitive needs a matching `package.json#exports` subpath. Import relatively between diff --git a/packages/dify-ui/package.json b/packages/dify-ui/package.json index 8084254b75f..9d60deb5639 100644 --- a/packages/dify-ui/package.json +++ b/packages/dify-ui/package.json @@ -21,6 +21,10 @@ "types": "./src/avatar/index.tsx", "import": "./src/avatar/index.tsx" }, + "./breadcrumb": { + "types": "./src/breadcrumb/index.tsx", + "import": "./src/breadcrumb/index.tsx" + }, "./button": { "types": "./src/button/index.tsx", "import": "./src/button/index.tsx" diff --git a/packages/dify-ui/src/alert-dialog/index.tsx b/packages/dify-ui/src/alert-dialog/index.tsx index 9789d2f6740..0e5f8ce2e73 100644 --- a/packages/dify-ui/src/alert-dialog/index.tsx +++ b/packages/dify-ui/src/alert-dialog/index.tsx @@ -1,8 +1,8 @@ 'use client' +import type * as React from 'react' import type { ButtonProps } from '../button' import { AlertDialog as BaseAlertDialog } from '@base-ui/react/alert-dialog' -import * as React from 'react' import { Button } from '../button' import { cn } from '../cn' import { modalBackdropClassName, modalPopupAnimationClassName } from '../overlay-shared' diff --git a/packages/dify-ui/src/autocomplete/index.tsx b/packages/dify-ui/src/autocomplete/index.tsx index 3d1fc3f4c29..6dd17fadd9f 100644 --- a/packages/dify-ui/src/autocomplete/index.tsx +++ b/packages/dify-ui/src/autocomplete/index.tsx @@ -1,10 +1,10 @@ 'use client' import type { VariantProps } from 'class-variance-authority' +import type * as React from 'react' import type { Placement } from '../placement' import { Autocomplete as BaseAutocomplete } from '@base-ui/react/autocomplete' import { cva } from 'class-variance-authority' -import * as React from 'react' import { cn } from '../cn' import { textControlCompoundInputFocusClassName } from '../form-control-shared' import { diff --git a/packages/dify-ui/src/breadcrumb/__tests__/types.tsx b/packages/dify-ui/src/breadcrumb/__tests__/types.tsx new file mode 100644 index 00000000000..69cfc7a45fe --- /dev/null +++ b/packages/dify-ui/src/breadcrumb/__tests__/types.tsx @@ -0,0 +1,42 @@ +import { + Breadcrumb, + BreadcrumbItem, + BreadcrumbLink, + BreadcrumbList, + BreadcrumbPage, + BreadcrumbSeparator, +} from '@langgenius/dify-ui/breadcrumb' + +export function breadcrumbTypeContracts() { + const labelled = + const referenced = + const link = } aria-current="page" /> + + // @ts-expect-error A navigation name must be supplied by the consumer. + const unnamed = + // @ts-expect-error Choose one accessible naming mechanism. + const duplicateName = + // @ts-expect-error Structural parts do not expose render. + const rootRender = } /> + // @ts-expect-error List semantics are fixed. + const listRender = } /> + // @ts-expect-error Item semantics are fixed. + const itemRender = } /> + // @ts-expect-error Use BreadcrumbLink for an interactive current page. + const pageRender = } /> + // @ts-expect-error Customize decorative content through children. + const separatorRender = } /> + + return { + labelled, + referenced, + link, + unnamed, + duplicateName, + rootRender, + listRender, + itemRender, + pageRender, + separatorRender, + } +} diff --git a/packages/dify-ui/src/breadcrumb/index.stories.tsx b/packages/dify-ui/src/breadcrumb/index.stories.tsx new file mode 100644 index 00000000000..13b2483cc98 --- /dev/null +++ b/packages/dify-ui/src/breadcrumb/index.stories.tsx @@ -0,0 +1,300 @@ +import type { Meta, StoryObj } from '@storybook/react-vite' +import * as React from 'react' +import { expect, waitFor, within } from 'storybook/test' +import { + Breadcrumb, + BreadcrumbItem, + BreadcrumbLink, + BreadcrumbList, + BreadcrumbPage, + BreadcrumbSeparator, +} from '.' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '../dropdown-menu' +import { IconButton } from '../icon-button' + +const meta = { + title: 'Base/UI/Breadcrumb', + component: Breadcrumb, + parameters: { + layout: 'centered', + a11y: { config: { rules: [{ id: 'color-contrast', enabled: true }] } }, + docs: { + description: { + component: + 'Explicit navigation anatomy with a required localized aria-label or aria-labelledby. ' + + 'Separators are decorative list siblings. Only BreadcrumbLink supports render, for components that forward props and refs to an anchor. ' + + 'Current links remain interactive; BreadcrumbPage is static text. No route inference, automatic separators, truncation, or collapsing. ' + + 'The default layout is a single row with consistent typography and tertiary ancestor links / primary current text. ' + + 'Consumers own typography overrides, available width, and overflow handling.', + }, + }, + }, + args: { 'aria-label': 'Breadcrumb' }, + decorators: [ + (Story) => ( +
+ +
+ ), + ], +} satisfies Meta + +export default meta +type Story = StoryObj + +export const Default: Story = { + render: (args) => ( + + + + Home + + + + Knowledge + + + + Product documents + + + + ), + play: async ({ canvas, userEvent }) => { + const navigation = within(canvas.getByRole('navigation', { name: 'Breadcrumb' })) + await expect(navigation.getAllByRole('listitem')).toHaveLength(3) + const home = navigation.getByRole('link', { name: 'Home' }) + home.focus() + await userEvent.tab() + await expect(navigation.getByRole('link', { name: 'Knowledge' })).toHaveFocus() + await expect(navigation.getByText('Product documents')).toHaveAttribute('aria-current', 'page') + }, +} + +export const CurrentPageLink: Story = { + render: (args) => ( + + + + Home + + + + + Documents + + + + + ), + play: async ({ canvas, userEvent }) => { + canvas.getByRole('link', { name: 'Home' }).focus() + await userEvent.tab() + const current = canvas.getByRole('link', { name: 'Documents', current: 'page' }) + await expect(current).toHaveFocus() + await expect(current).toHaveAttribute('href', '#documents') + await expect(current).not.toHaveAttribute('aria-disabled') + }, +} + +function StoryLink({ children, ...props }: React.ComponentProps<'a'>) { + return {children} +} + +function RenderLinkExample() { + const ref = React.useRef(null) + return ( +
+ + + + }> + Projects + + + + + Design system + + + + +
+ ) +} + +export const RenderLink: Story = { + render: () => , + play: async ({ canvas, userEvent }) => { + await userEvent.click(canvas.getByRole('button', { name: 'Focus project link' })) + await expect(canvas.getByRole('link', { name: 'Projects' })).toHaveFocus() + await expect(canvas.getByRole('link', { name: 'Projects' })).toHaveAttribute( + 'href', + '#projects', + ) + }, +} + +export const LabelledBy: Story = { + render: () => ( +
+

+ Project location +

+ + + + Projects + + + + Design system + + + +
+ ), +} + +export const RightToLeft: Story = { + render: () => ( + + + + الرئيسية + + + + + + المعرفة + + + + + + المستندات + + + + ), +} + +export const TruncatedLabel: Story = { + parameters: { + docs: { + description: { + story: + 'The consumer constrains one item and truncates its text, leaving the anchor focus outline and its full accessible name intact.', + }, + }, + }, + render: (args) => ( + + + + Home + + + + + Research and development documentation + + + + + Overview + + + + ), +} + +export const CollapsedAncestors: Story = { + parameters: { + docs: { + description: { + story: + 'Collapsing is an explicit DropdownMenu composition. Its trigger owns the accessible name; hidden ancestors remain links. Escape restores focus to the trigger.', + }, + }, + }, + render: (args) => ( + + + + Home + + + + + + + + } + /> + + }>Projects + }>Knowledge + + + + + + Documents + + + + ), + play: async ({ canvas, canvasElement, userEvent }) => { + const trigger = canvas.getByRole('button', { name: 'Show ancestor pages' }) + trigger.focus() + await userEvent.keyboard('{Enter}') + const body = within(canvasElement.ownerDocument.body) + await expect(await body.findByRole('menuitem', { name: 'Projects' })).toBeVisible() + await userEvent.keyboard('{Escape}') + await waitFor(() => expect(trigger).toHaveFocus()) + }, +} + +export const Dark: Story = { + ...Default, + globals: { theme: 'dark' }, +} + +export const Typography: Story = { + parameters: { + docs: { + description: { + story: + 'Set typography on the list to change the size and weight of every item together. Links and current text inherit these styles.', + }, + }, + }, + render: () => ( + + + + Documentation + + + + Getting started + + + + ), +} diff --git a/packages/dify-ui/src/breadcrumb/index.tsx b/packages/dify-ui/src/breadcrumb/index.tsx new file mode 100644 index 00000000000..91fdf4bc092 --- /dev/null +++ b/packages/dify-ui/src/breadcrumb/index.tsx @@ -0,0 +1,97 @@ +'use client' + +import type * as React from 'react' +import { mergeProps } from '@base-ui/react/merge-props' +import { useRender } from '@base-ui/react/use-render' +import { cn } from '../cn' + +type BreadcrumbName = + | { 'aria-label': string; 'aria-labelledby'?: never } + | { 'aria-label'?: never; 'aria-labelledby': string } + +type BreadcrumbProps = Omit, 'aria-label' | 'aria-labelledby'> & + BreadcrumbName +type BreadcrumbListProps = React.ComponentProps<'ol'> +type BreadcrumbItemProps = React.ComponentProps<'li'> +type BreadcrumbLinkProps = useRender.ComponentProps<'a'> +type BreadcrumbPageProps = React.ComponentProps<'span'> +type BreadcrumbSeparatorProps = React.ComponentProps<'li'> + +function Breadcrumb({ className, ...props }: BreadcrumbProps) { + return