feat: add HiCAD editor project shortcuts

This commit is contained in:
134 2026-07-27 23:54:48 +08:00 committed by root
parent 016076015e
commit 8e89bb179e
3 changed files with 166 additions and 1 deletions

View File

@ -315,10 +315,105 @@ function patchOfficialSource() {
" {displayedName !== user.email && (",
" {!isHiCadEmbedded && displayedName !== user.email && ("
);
replaceSource(
"src/components/AppHeader.tsx",
"import { HicadAutosaveStatus } from '@src/components/HicadProjectExperience'\n",
""
);
replaceSource(
"src/components/AppHeader.tsx",
"import { HicadAutosaveStatus, HicadEditorProjectActions } from '@src/components/HicadProjectExperience'\n",
""
);
replaceSource(
"src/components/AppHeader.tsx",
"import ProjectSidebarMenu from '@src/components/ProjectSidebarMenu'\n",
"import { HicadAutosaveStatus } from '@src/components/HicadProjectExperience'\nimport ProjectSidebarMenu from '@src/components/ProjectSidebarMenu'\n"
"import { HicadAutosaveStatus, HicadEditorProjectActions } from '@src/components/HicadProjectExperience'\nimport ProjectSidebarMenu from '@src/components/ProjectSidebarMenu'\n"
);
replaceSource(
"src/components/AppHeader.tsx",
" {project && <HicadEditorProjectActions />}\n",
""
);
replaceSource(
"src/components/AppHeader.tsx",
` {project && (
<HicadEditorProjectActions
onOpenProjectList={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
void navigate(PATHS.HOME)
}}
onCreateBlankProject={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
void navigate(\`\${PATHS.HOME}?create=blank\`)
}}
/>
)}
`,
""
);
replaceSource(
"src/components/AppHeader.tsx",
` {project && (
<HicadEditorProjectActions
onOpenProjectList={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
}}
onCreateBlankProject={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
}}
/>
)}
`,
""
);
replaceSource(
"src/components/AppHeader.tsx",
` </ProjectSidebarMenu>
<div className="flex items-center gap-2 py-1.5 ml-auto">`,
` </ProjectSidebarMenu>
{project && (
<HicadEditorProjectActions
onOpenProjectList={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
}}
onCreateBlankProject={() => {
lsp.onProjectClose(file || null, project.path || null, false)
kclManager.switchedFiles = true
}}
/>
)}
<div className="flex items-center gap-2 py-1.5 ml-auto">`
);
replaceSource(
"src/lib/routeLoaders.ts",
" if (await webHomeRouteEnabled(app)) {\n",
" if (true) {\n"
);
replaceSource(
"src/lib/routeLoaders.ts",
" if (!window.electron && !(await webHomeRouteEnabled(app))) {\n",
" if (false) {\n"
);
replaceSource(
"src/lib/app.ts",
` const enableProjectDirectoryCommands =
typeof window !== 'undefined' &&
(Boolean(window.electron) ||
userFeaturesContextHas(
this.userFeatures.actor.getSnapshot().context,
OPFS_CLOUD_FEATURE_FLAG,
false
))
`,
` const enableProjectDirectoryCommands =
typeof window !== 'undefined'
`
);
replaceSource(
"src/components/AppHeader.tsx",

View File

@ -28,6 +28,19 @@ test.describe('HiCAD project management experience', () => {
expect(experience).toContain('自动保存已开启')
expect(experience).toContain('data-testid="hicad-create-project"')
expect(experience).toContain('data-testid="hicad-create-from-sample"')
expect(experience).toContain('data-testid="hicad-open-project-list"')
expect(experience).toContain('data-testid="hicad-create-blank-project"')
expect(experience).toContain('?create=blank')
expect(experience).toContain('[data-testid="home-new-file"]')
expect(script).toContain('<HicadEditorProjectActions')
expect(script).toContain('lsp.onProjectClose')
expect(script).toContain('kclManager.switchedFiles = true')
expect(script).toContain('" if (await webHomeRouteEnabled(app))')
expect(script).toContain('" if (!window.electron && !(await webHomeRouteEnabled(app)))')
expect(script).toContain('"src/lib/app.ts"')
expect(script).toContain(` const enableProjectDirectoryCommands =
typeof window !== 'undefined'
`)
})
test('keeps new project creation simple and understandable', () => {

View File

@ -1,10 +1,15 @@
import { CustomIcon } from '@src/components/CustomIcon'
import { PATHS } from '@src/lib/paths'
import { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
export function HicadProjectDashboardHeading({
projectCount,
}: {
projectCount: number
}) {
const location = useLocation()
const navigate = useNavigate()
const startCreatingProject = () => {
document
.querySelector<HTMLButtonElement>('[data-testid="home-new-file"]')
@ -18,6 +23,19 @@ export function HicadProjectDashboardHeading({
?.click()
}
useEffect(() => {
const shouldCreateBlankProject =
new URLSearchParams(location.search).get('create') === 'blank'
if (!shouldCreateBlankProject) return
const timer = window.setTimeout(() => {
startCreatingProject()
void navigate(PATHS.HOME, { replace: true })
}, 250)
return () => window.clearTimeout(timer)
}, [location.search, navigate])
return (
<div
className="flex min-w-0 flex-1 flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"
@ -66,3 +84,42 @@ export function HicadAutosaveStatus() {
</span>
)
}
export function HicadEditorProjectActions({
onOpenProjectList,
onCreateBlankProject,
}: {
onOpenProjectList: () => void
onCreateBlankProject: () => void
}) {
const buttonClassName =
'inline-flex h-7 items-center justify-center gap-1.5 rounded-md border border-chalkboard-30 bg-chalkboard-10/80 px-2 text-xs font-medium text-chalkboard-80 transition-colors hover:border-primary/50 hover:bg-primary/5 hover:text-primary focus-visible:outline-appForeground dark:border-chalkboard-70 dark:bg-chalkboard-100/50 dark:text-chalkboard-30 dark:hover:border-primary/50 dark:hover:text-primary'
return (
<div
className="ml-2 flex flex-none items-center gap-1.5"
data-testid="hicad-editor-project-actions"
>
<a
href={`#${PATHS.HOME}`}
className={buttonClassName}
onClick={onOpenProjectList}
data-testid="hicad-open-project-list"
title="查看和打开历史项目"
>
<CustomIcon name="folder" className="h-4 w-4" />
项目列表
</a>
<a
href={`#${PATHS.HOME}?create=blank`}
className={buttonClassName}
onClick={onCreateBlankProject}
data-testid="hicad-create-blank-project"
title="新建空白 CAD 项目"
>
<CustomIcon name="plus" className="h-4 w-4" />
新建空白
</a>
</div>
)
}