feat: 沙箱预览住进 playground 侧栏——右缘双贴签(紫色沙箱签+珊瑚编辑器签),侧栏展开灰色蒙版罩页,点运行自动切沙箱页签
No files matched your search
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'
|
||||
|
||||
async function openEditor(page: import('@playwright/test').Page) {
|
||||
await page.locator('[data-comp="editor-dock-tab"]').click()
|
||||
await expect(page.locator('#editor-dock-panel')).toBeVisible()
|
||||
await expect(page.locator('#playground-dock-panel')).toBeVisible()
|
||||
}
|
||||
|
||||
async function addFile(page: import('@playwright/test').Page, name: string) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'
|
||||
|
||||
async function openEditor(page: import('@playwright/test').Page) {
|
||||
await page.locator('[data-comp="editor-dock-tab"]').click()
|
||||
await expect(page.locator('#editor-dock-panel')).toBeVisible()
|
||||
await expect(page.locator('#playground-dock-panel')).toBeVisible()
|
||||
}
|
||||
|
||||
test('html 身体注入:运行后预览框渲染 #app 文本', async ({ page }) => {
|
||||
|
||||
@@ -4,18 +4,6 @@ const SIDEBAR = '#site-sidebar-drawer'
|
||||
const OPENER = 'label[for="site-sidebar-toggle"][aria-label="打开侧栏导航"]'
|
||||
const OVERLAY = 'label[for="site-sidebar-toggle"][aria-hidden="true"]'
|
||||
|
||||
async function clickAnchorAndAssertScroll(
|
||||
page: import('@playwright/test').Page,
|
||||
click: () => Promise<void>,
|
||||
maxY: number,
|
||||
) {
|
||||
const before = await page.evaluate(() => window.scrollY)
|
||||
await click()
|
||||
await expect.poll(async () => page.evaluate(() => window.scrollY)).toBeGreaterThan(before + 100)
|
||||
const box = await page.locator('#practice-sandbox').boundingBox()
|
||||
expect(box?.y ?? Number.POSITIVE_INFINITY).toBeLessThan(maxY)
|
||||
}
|
||||
|
||||
test.describe('练习场 · sidebar 导航(唯一导航形态)', () => {
|
||||
test('桌面:顶部 navbar 退场,侧栏常驻在场', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
@@ -24,7 +12,7 @@ test.describe('练习场 · sidebar 导航(唯一导航形态)', () => {
|
||||
const sidebar = page.locator(SIDEBAR)
|
||||
await expect(sidebar).toBeVisible()
|
||||
await expect(sidebar.locator('a').first()).toContainText('idealjs stack')
|
||||
for (const label of ['全栈教程', '博客', '设计系统', '在线练习', '本页']) {
|
||||
for (const label of ['全栈教程', '博客', '设计系统', '在线练习']) {
|
||||
await expect(sidebar.getByText(label, { exact: true })).toBeVisible()
|
||||
}
|
||||
})
|
||||
@@ -44,14 +32,11 @@ test.describe('练习场 · sidebar 导航(唯一导航形态)', () => {
|
||||
expect(rowShadow).toContain('inset')
|
||||
})
|
||||
|
||||
test('桌面:主区一屏放下,本页锚点目标保持在视口内', async ({ page }) => {
|
||||
test('桌面:主区一屏放下,沙箱已撤出主区住进右缘侧栏', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await page.goto('/practice.html', { timeout: 20_000 })
|
||||
await page.locator(SIDEBAR).getByText('代码沙箱', { exact: true }).click()
|
||||
const box = await page.locator('#practice-sandbox').boundingBox()
|
||||
expect(box, '锚点目标应在场').not.toBeNull()
|
||||
expect(box!.y, '锚点目标顶部应落在视口内').toBeGreaterThanOrEqual(0)
|
||||
expect(box!.y, '锚点目标顶部应落在视口内').toBeLessThan(900)
|
||||
await expect(page.getByRole('heading', { name: '在线练习' })).toBeVisible()
|
||||
await expect(page.locator('#practice-sandbox')).toHaveCount(0)
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
||||
)
|
||||
@@ -78,17 +63,4 @@ test.describe('练习场 · sidebar 导航(唯一导航形态)', () => {
|
||||
await sidebar.getByLabel('收起侧栏导航', { exact: true }).click()
|
||||
await expect(sidebar).toBeHidden()
|
||||
})
|
||||
|
||||
test('移动:抽屉打开后可点本页锚点滚动到位', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 390, height: 844 })
|
||||
await page.goto('/practice.html', { timeout: 20_000 })
|
||||
await page.locator(OPENER).click()
|
||||
const sidebar = page.locator(SIDEBAR)
|
||||
await expect(sidebar).toBeVisible()
|
||||
await clickAnchorAndAssertScroll(
|
||||
page,
|
||||
() => sidebar.getByText('代码沙箱', { exact: true }).click(),
|
||||
844,
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -7,7 +7,9 @@ const LIST_PANEL = '#checklist-dock-panel'
|
||||
const CHECKLIST = '[data-comp="clipboard-checklist"]'
|
||||
const FLOW = '[data-comp="data-flow-board"]'
|
||||
const EDITOR_TAB = '[data-comp="editor-dock-tab"]'
|
||||
const EDITOR_PANEL = '#editor-dock-panel'
|
||||
const SANDBOX_TAB = '[data-comp="sandbox-dock-tab"]'
|
||||
const DOCK_MASK = '[data-comp="playground-dock-mask"]'
|
||||
const DOCK_PANEL = '#playground-dock-panel'
|
||||
const TIPS = '[data-comp="tips-dock-trigger"]'
|
||||
const TIPS_PANEL = '#tips-dock-panel'
|
||||
|
||||
@@ -161,7 +163,6 @@ test.describe('练习场 · tips 喂给陪练(右上角)', () => {
|
||||
})
|
||||
|
||||
test('流水线板收进面板:主区不再有板,三步同源提示词,第一步为虚线起点', async ({ page }) => {
|
||||
await expect(page.locator('#practice-sandbox').locator(FLOW)).toHaveCount(0)
|
||||
await expect(page.locator('main > #practice-flow')).toHaveCount(0)
|
||||
|
||||
await page.locator(TIPS).click()
|
||||
@@ -208,77 +209,98 @@ test.describe('练习场 · tips 喂给陪练(右上角)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('练习场 · 主区布局', () => {
|
||||
test.describe('练习场 · playground 侧栏(沙箱 + 编辑器)', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/practice.html')
|
||||
})
|
||||
|
||||
test('沙箱独占主区,大屏下沙箱栏独立滚动', async ({ page }) => {
|
||||
test('沙箱撤出主区,整体住进右缘侧栏;编辑器与沙箱两个独特贴签停靠右缘', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
const runner = page.locator('section[aria-label="web runner 沙箱预览"]')
|
||||
await expect(page.locator('#practice-sandbox')).toHaveCount(0)
|
||||
const panel = page.locator(DOCK_PANEL)
|
||||
await expect(panel).toBeHidden()
|
||||
await expect(page.locator('[data-testid="sandbox-frame"]')).not.toBeVisible()
|
||||
await expect(panel.locator('section[aria-label="web runner 沙箱预览"]')).toHaveCount(1)
|
||||
|
||||
const editorTab = page.locator(EDITOR_TAB)
|
||||
const sandboxTab = page.locator(SANDBOX_TAB)
|
||||
await expect(editorTab).toContainText('playground · 编辑器')
|
||||
await expect(sandboxTab).toContainText('web runner · 沙箱预览')
|
||||
for (const tab of [editorTab, sandboxTab]) {
|
||||
const box = await tab.boundingBox()
|
||||
expect(box).not.toBeNull()
|
||||
expect(1280 - (box!.x + box!.width), '贴签应停靠右缘').toBeLessThanOrEqual(2)
|
||||
await expect(tab).toHaveAttribute('aria-expanded', 'false')
|
||||
await expect(tab).toHaveAttribute('aria-controls', 'playground-dock-panel')
|
||||
}
|
||||
await expect(page.locator(DOCK_PANEL)).toBeHidden()
|
||||
})
|
||||
|
||||
test('点「沙箱预览」签拉开侧栏:状态线、沙箱帧、输出在场;运行前帧不显示、占位说明在场', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await page.locator(SANDBOX_TAB).click()
|
||||
const panel = page.locator(DOCK_PANEL)
|
||||
await expect(panel).toBeVisible()
|
||||
await expect(page.locator(SANDBOX_TAB)).toHaveAttribute('aria-expanded', 'true')
|
||||
const runner = panel.locator('section[aria-label="web runner 沙箱预览"]')
|
||||
await expect(runner).toBeVisible()
|
||||
await expect(runner).toContainText('web runner · 沙箱预览')
|
||||
await expect(runner.locator('[data-testid="runtime-status"]')).toBeVisible()
|
||||
await expect(runner.locator('[data-testid="sandbox-frame"]')).toHaveCount(1)
|
||||
await expect(runner.getByRole('region', { name: '输出' })).toBeVisible()
|
||||
|
||||
const sandboxOverflow = await page
|
||||
.locator('#practice-sandbox')
|
||||
.evaluate((el) => getComputedStyle(el).overflowY)
|
||||
expect(sandboxOverflow, '沙箱栏应是独立滚动容器').toBe('auto')
|
||||
})
|
||||
|
||||
test('运行前预览区展示占位说明,iframe 未运行时不显示,编辑器收成固定贴签不占排版', async ({
|
||||
page,
|
||||
}) => {
|
||||
const runner = page.locator('section[aria-label="web runner 沙箱预览"]')
|
||||
await expect(runner).toContainText('点右缘「编辑器」')
|
||||
await expect(runner).toContainText('构建产物送进隔离 iframe 真跑')
|
||||
await expect(runner.locator('[data-testid="sandbox-frame"]')).not.toBeVisible()
|
||||
const editor = page.locator('section[aria-label="playground 编辑器"]')
|
||||
await expect(editor).toBeHidden()
|
||||
await expect(editor).toHaveCSS('position', 'fixed')
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('练习场 · 编辑器侧栏(右缘)', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/practice.html')
|
||||
})
|
||||
|
||||
test('大屏与窄屏默认都收起;点击展开成大区域,Esc 与 ✕ 收起', async ({ page }) => {
|
||||
for (const width of [1280, 390]) {
|
||||
await page.setViewportSize({ width, height: 900 })
|
||||
const tab = page.locator(EDITOR_TAB)
|
||||
const panel = page.locator(EDITOR_PANEL)
|
||||
await expect(tab).toBeVisible()
|
||||
await expect(tab).toContainText('playground · 编辑器')
|
||||
await expect(tab).toHaveAttribute('aria-expanded', 'false')
|
||||
await expect(tab).toHaveAttribute('aria-controls', 'editor-dock-panel')
|
||||
await expect(panel).toBeHidden()
|
||||
test('侧栏展开时页面罩上灰色蒙版:蒙版在场且半透明,点蒙版收回侧栏', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
const mask = page.locator(DOCK_MASK)
|
||||
await expect(mask).toHaveCSS('opacity', '0')
|
||||
|
||||
await tab.click()
|
||||
await expect(tab).toHaveAttribute('aria-expanded', 'true')
|
||||
await expect(panel).toBeVisible()
|
||||
await expect(panel).toContainText('playground · 编辑器')
|
||||
await expect(panel.getByLabel('项目文件')).toBeVisible()
|
||||
await expect(panel.getByLabel('模块代码')).toBeVisible()
|
||||
await expect(panel.getByRole('button', { name: '运行 ▶' })).toBeVisible()
|
||||
await page.locator(EDITOR_TAB).click()
|
||||
await expect(page.locator(DOCK_PANEL)).toBeVisible()
|
||||
await expect(mask).toBeVisible()
|
||||
const opacity = await mask.evaluate((el) => getComputedStyle(el).backgroundColor)
|
||||
expect(opacity, '蒙版应是半透明灰').not.toBe('rgba(0, 0, 0, 0)')
|
||||
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(panel).toBeHidden()
|
||||
await expect(tab).toHaveAttribute('aria-expanded', 'false')
|
||||
|
||||
await tab.click()
|
||||
await expect(panel).toBeVisible()
|
||||
await panel.getByRole('button', { name: '收起编辑器' }).click()
|
||||
await expect(panel).toBeHidden()
|
||||
}
|
||||
await page.mouse.click(200, 450)
|
||||
await expect(page.locator(DOCK_PANEL)).toBeHidden()
|
||||
await expect(mask).toHaveCSS('opacity', '0')
|
||||
})
|
||||
|
||||
test('展开区域比原卡片区更大:大屏面板 ≥520px 宽,内部独立滚动', async ({ page }) => {
|
||||
test('页签切换:编辑器与沙箱预览互斥展示,Esc 与 ✕ 收起侧栏', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await page.locator(EDITOR_TAB).click()
|
||||
const panel = page.locator(EDITOR_PANEL)
|
||||
const panel = page.locator(DOCK_PANEL)
|
||||
await expect(panel).toBeVisible()
|
||||
|
||||
const editorPaneTab = panel.locator('[data-comp="editor-dock-pane-tab"]')
|
||||
const sandboxPaneTab = panel.locator('[data-comp="sandbox-dock-pane-tab"]')
|
||||
const runner = panel.locator('section[aria-label="web runner 沙箱预览"]')
|
||||
await expect(editorPaneTab).toHaveAttribute('aria-pressed', 'true')
|
||||
await expect(panel.getByLabel('项目文件')).toBeVisible()
|
||||
await expect(runner).not.toBeVisible()
|
||||
|
||||
await sandboxPaneTab.click()
|
||||
await expect(sandboxPaneTab).toHaveAttribute('aria-pressed', 'true')
|
||||
await expect(editorPaneTab).toHaveAttribute('aria-pressed', 'false')
|
||||
await expect(runner).toBeVisible()
|
||||
await expect(panel.getByLabel('项目文件')).not.toBeVisible()
|
||||
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(panel).toBeHidden()
|
||||
|
||||
await page.locator(EDITOR_TAB).click()
|
||||
await expect(panel).toBeVisible()
|
||||
await panel.getByRole('button', { name: '收起侧栏' }).click()
|
||||
await expect(panel).toBeHidden()
|
||||
})
|
||||
|
||||
test('展开区域是大面板:大屏面板 ≥520px 宽,内部独立滚动', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await page.locator(EDITOR_TAB).click()
|
||||
const panel = page.locator(DOCK_PANEL)
|
||||
await expect(panel).toBeVisible()
|
||||
const panelBox = await panel.boundingBox()
|
||||
expect(panelBox?.width ?? 0).toBeGreaterThanOrEqual(520)
|
||||
@@ -289,6 +311,26 @@ test.describe('练习场 · 编辑器侧栏(右缘)', () => {
|
||||
.evaluate((el) => getComputedStyle(el).overflowY)
|
||||
expect(bodyOverflow).toBe('auto')
|
||||
})
|
||||
|
||||
test('大屏与窄屏默认都收起;编辑器签拉开后写码三件套在场', async ({ page }) => {
|
||||
for (const width of [1280, 390]) {
|
||||
await page.setViewportSize({ width, height: 900 })
|
||||
const tab = page.locator(EDITOR_TAB)
|
||||
const panel = page.locator(DOCK_PANEL)
|
||||
await expect(tab).toBeVisible()
|
||||
await expect(panel).toBeHidden()
|
||||
|
||||
await tab.click()
|
||||
await expect(panel).toBeVisible()
|
||||
await expect(panel.getByLabel('项目文件')).toBeVisible()
|
||||
await expect(panel.getByLabel('模块代码')).toBeVisible()
|
||||
await expect(panel.getByRole('button', { name: '运行 ▶' })).toBeVisible()
|
||||
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(panel).toBeHidden()
|
||||
await expect(tab).toHaveAttribute('aria-expanded', 'false')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('练习场 · 布局自查', () => {
|
||||
@@ -344,15 +386,21 @@ test.describe('练习场 · 布局自查', () => {
|
||||
width - (editorBox!.x + editorBox!.width),
|
||||
`宽度 ${width} 编辑器签距右缘过大`,
|
||||
).toBeLessThanOrEqual(2)
|
||||
const sandboxBox = await page.locator(SANDBOX_TAB).boundingBox()
|
||||
expect(sandboxBox).not.toBeNull()
|
||||
expect(
|
||||
width - (sandboxBox!.x + sandboxBox!.width),
|
||||
`宽度 ${width} 沙箱签距右缘过大`,
|
||||
).toBeLessThanOrEqual(2)
|
||||
|
||||
await page.locator(EDITOR_TAB).click()
|
||||
await expect(page.locator(EDITOR_PANEL)).toBeVisible()
|
||||
await expect(page.locator(DOCK_PANEL)).toBeVisible()
|
||||
const panelOverflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
||||
)
|
||||
expect(panelOverflow, `宽度 ${width} 编辑器展开后出现横向溢出`).toBe(0)
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(page.locator(EDITOR_PANEL)).toBeHidden()
|
||||
await expect(page.locator(DOCK_PANEL)).toBeHidden()
|
||||
|
||||
await page.locator(TIPS).click()
|
||||
await expect(page.locator(TIPS_PANEL)).toBeVisible()
|
||||
|
||||
@@ -1,30 +1,22 @@
|
||||
import type { NavRowGroup } from '../../design-system'
|
||||
import { SiteSidebar } from '../../design-system'
|
||||
import { SiteFooter } from '../../lib/site'
|
||||
import { SITE_NAV } from '../../lib/ui'
|
||||
import { PracticeWorkspace } from './components/PracticeWorkspace'
|
||||
|
||||
const PAGE_ROWS: NavRowGroup[] = [
|
||||
...SITE_NAV.rows,
|
||||
{
|
||||
sectionKey: 'practice-page',
|
||||
label: '本页',
|
||||
items: [{ key: 'practice-sandbox', label: '代码沙箱', href: '#practice-sandbox' }],
|
||||
},
|
||||
]
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<div className="flex min-h-dvh text-content text-body">
|
||||
<SiteSidebar brand={SITE_NAV.brand} rows={PAGE_ROWS} active="practice" />
|
||||
<main className="mx-auto w-full max-w-[1200px] min-w-0 flex-1 px-3 py-4 max-lg:pt-16">
|
||||
<SiteSidebar brand={SITE_NAV.brand} rows={SITE_NAV.rows} active="practice" />
|
||||
<main className="mx-auto w-full max-w-[1200px] min-w-0 flex-1 px-3 py-4 max-lg:pr-12 max-lg:pt-16">
|
||||
<div className="mb-4">
|
||||
<h1 className="m-0 text-t1 font-extrabold text-ink">在线练习</h1>
|
||||
<p className="m-0 mt-1.5 text-content text-mute">
|
||||
沙箱写真跑:web runner 沙箱预览接构建输出,点「运行 ▶」产物送进隔离 iframe
|
||||
执行;右上角「💡 tips」拉出操作流水线,点任意一步,提示词自动填进陪练 agent
|
||||
输入框,回车即发;playground
|
||||
编辑器收在右缘侧栏,点「编辑器」签拉开写码;验收清单夹在页面右上角,点夹具拉出来逐条打勾。
|
||||
沙箱写真跑:web runner 沙箱预览与 playground
|
||||
编辑器同住右缘侧栏——点紫色的「沙箱预览」签直接看沙箱,点「编辑器」签写码;点「运行
|
||||
▶」构建产物送进隔离 iframe
|
||||
执行,并自动切到沙箱页签;侧栏展开时页面罩上灰色蒙版,点蒙版或按 Esc 收回。右上角「💡
|
||||
tips」拉出操作流水线,点任意一步,提示词自动填进陪练 agent
|
||||
输入框,回车即发;验收清单夹在页面右上角,点夹具拉出来逐条打勾。
|
||||
</p>
|
||||
</div>
|
||||
<PracticeWorkspace />
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export function EditorDock({
|
||||
panelId,
|
||||
open,
|
||||
onToggle,
|
||||
children,
|
||||
}: {
|
||||
panelId: string
|
||||
open: boolean
|
||||
onToggle: () => void
|
||||
children: ReactNode
|
||||
}) {
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') onToggle()
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [open, onToggle])
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
data-comp="editor-dock-tab"
|
||||
aria-expanded={open}
|
||||
aria-controls={panelId}
|
||||
onClick={onToggle}
|
||||
className={`fixed top-1/2 right-0 z-40 flex -translate-y-1/2 cursor-pointer flex-col items-center gap-1.5 rounded-l-lg border-2 border-r-0 border-ink bg-clash1a py-3 pl-1.5 pr-2 text-[12.5px] font-extrabold text-ink shadow-[-3px_3px_0_var(--color-ink)] transition-[translate] duration-150 motion-reduce:transition-none ${
|
||||
open ? 'translate-x-full pointer-events-none opacity-0' : 'hover:-translate-x-0.5'
|
||||
}`}
|
||||
>
|
||||
<span aria-hidden className="text-[10px] leading-none">
|
||||
◀
|
||||
</span>
|
||||
<span className="[writing-mode:vertical-rl]">playground · 编辑器</span>
|
||||
</button>
|
||||
|
||||
<section
|
||||
id={panelId}
|
||||
aria-label="playground 编辑器"
|
||||
className={`fixed top-0 right-0 z-50 flex h-dvh w-[min(600px,calc(100vw-24px))] flex-col rounded-l-xl border-2 border-r-0 border-ink bg-paper shadow-ink transition-[transform,opacity,visibility] duration-200 ease-out motion-reduce:transition-none ${
|
||||
open
|
||||
? 'visible translate-x-0 opacity-100'
|
||||
: 'invisible pointer-events-none translate-x-full opacity-0'
|
||||
}`}
|
||||
>
|
||||
<div className="flex shrink-0 items-baseline justify-between gap-x-2 border-b-2 border-ink px-4 py-2.5">
|
||||
<span className="t-small-strong shrink-0">playground · 编辑器</span>
|
||||
<span className="t-small-mute min-w-0 flex-1 truncate">
|
||||
宿主 stack 构建,产物送左侧沙箱
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
aria-label="收起编辑器"
|
||||
title="收起编辑器"
|
||||
className="shrink-0 cursor-pointer rounded-md border-2 border-ink bg-white px-1.5 py-0.5 text-[12px] font-bold text-ink hover:bg-paper-deep"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto p-4">{children}</div>
|
||||
</section>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { usePlayground } from '../../../playground'
|
||||
|
||||
type DockPaneKind = 'editor' | 'sandbox'
|
||||
|
||||
const PANE_META: Record<DockPaneKind, string> = {
|
||||
editor: '宿主 stack 构建,产物送「沙箱预览」真跑',
|
||||
sandbox: '隔离 iframe,postMessage 单通道',
|
||||
}
|
||||
|
||||
function EdgeTab({
|
||||
comp,
|
||||
label,
|
||||
accentClass,
|
||||
positionClass,
|
||||
panelId,
|
||||
open,
|
||||
onOpen,
|
||||
}: {
|
||||
comp: string
|
||||
label: string
|
||||
accentClass: string
|
||||
positionClass: string
|
||||
panelId: string
|
||||
open: boolean
|
||||
onOpen: () => void
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
data-comp={comp}
|
||||
aria-expanded={open}
|
||||
aria-controls={panelId}
|
||||
onClick={onOpen}
|
||||
className={`fixed right-0 z-40 flex -translate-y-1/2 cursor-pointer flex-col items-center gap-1.5 rounded-l-lg border-2 border-r-0 border-ink py-3 pr-2 pl-1.5 text-[12.5px] font-extrabold text-ink shadow-[-3px_3px_0_var(--color-ink)] transition-[translate,opacity] duration-150 motion-reduce:transition-none ${accentClass} ${positionClass} ${
|
||||
open ? 'pointer-events-none translate-x-full opacity-0' : 'hover:-translate-x-0.5'
|
||||
}`}
|
||||
>
|
||||
<span aria-hidden className="text-[10px] leading-none">
|
||||
◀
|
||||
</span>
|
||||
<span className="[writing-mode:vertical-rl]">{label}</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export function PlaygroundDock({
|
||||
panelId,
|
||||
open,
|
||||
onToggle,
|
||||
editor,
|
||||
sandbox,
|
||||
}: {
|
||||
panelId: string
|
||||
open: boolean
|
||||
onToggle: () => void
|
||||
editor: ReactNode
|
||||
sandbox: ReactNode
|
||||
}) {
|
||||
const { runSeq } = usePlayground()
|
||||
const [pane, setPane] = useState<DockPaneKind>('editor')
|
||||
|
||||
useEffect(() => {
|
||||
if (runSeq === 0) return
|
||||
setPane('sandbox')
|
||||
}, [runSeq])
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') onToggle()
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [open, onToggle])
|
||||
|
||||
const openPane = (next: DockPaneKind) => {
|
||||
setPane(next)
|
||||
if (!open) onToggle()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
data-comp="playground-dock-mask"
|
||||
aria-hidden
|
||||
onClick={onToggle}
|
||||
className={`fixed inset-0 z-[45] bg-ink/45 transition-opacity duration-200 motion-reduce:transition-none ${
|
||||
open ? 'opacity-100' : 'pointer-events-none opacity-0'
|
||||
}`}
|
||||
/>
|
||||
|
||||
<EdgeTab
|
||||
comp="editor-dock-tab"
|
||||
label="playground · 编辑器"
|
||||
accentClass="bg-clash1a"
|
||||
positionClass="top-[calc(50%-7.5rem)]"
|
||||
panelId={panelId}
|
||||
open={open}
|
||||
onOpen={() => openPane('editor')}
|
||||
/>
|
||||
<EdgeTab
|
||||
comp="sandbox-dock-tab"
|
||||
label="web runner · 沙箱预览"
|
||||
accentClass="bg-clash2b"
|
||||
positionClass="top-[calc(50%+7.5rem)]"
|
||||
panelId={panelId}
|
||||
open={open}
|
||||
onOpen={() => openPane('sandbox')}
|
||||
/>
|
||||
|
||||
<section
|
||||
id={panelId}
|
||||
aria-label="playground 侧栏"
|
||||
className={`fixed top-0 right-0 z-50 flex h-dvh w-[min(600px,calc(100vw-24px))] flex-col rounded-l-xl border-2 border-r-0 border-ink bg-paper shadow-ink transition-[transform,opacity,visibility] duration-200 ease-out motion-reduce:transition-none ${
|
||||
open
|
||||
? 'visible translate-x-0 opacity-100'
|
||||
: 'invisible pointer-events-none translate-x-full opacity-0'
|
||||
}`}
|
||||
>
|
||||
<div className="flex shrink-0 items-center gap-x-2 border-b-2 border-ink px-4 py-2.5">
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
data-comp="editor-dock-pane-tab"
|
||||
aria-pressed={pane === 'editor'}
|
||||
onClick={() => setPane('editor')}
|
||||
className={`cursor-pointer rounded-md border-2 border-ink px-2.5 py-1 text-[12.5px] font-extrabold text-ink transition-colors duration-150 motion-reduce:transition-none ${
|
||||
pane === 'editor' ? 'bg-ink text-paper' : 'bg-white hover:bg-paper-deep'
|
||||
}`}
|
||||
>
|
||||
编辑器
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-comp="sandbox-dock-pane-tab"
|
||||
aria-pressed={pane === 'sandbox'}
|
||||
onClick={() => setPane('sandbox')}
|
||||
className={`flex cursor-pointer items-center gap-1 rounded-md border-2 border-ink px-2.5 py-1 text-[12.5px] font-extrabold text-ink transition-colors duration-150 motion-reduce:transition-none ${
|
||||
pane === 'sandbox' ? 'bg-clash2b' : 'bg-white hover:bg-paper-deep'
|
||||
}`}
|
||||
>
|
||||
<span aria-hidden className="text-[10px] leading-none">
|
||||
▶
|
||||
</span>
|
||||
沙箱预览
|
||||
</button>
|
||||
</div>
|
||||
<span className="t-small-mute hidden min-w-0 flex-1 truncate sm:block">
|
||||
{PANE_META[pane]}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
aria-label="收起侧栏"
|
||||
title="收起侧栏"
|
||||
className="shrink-0 cursor-pointer rounded-md border-2 border-ink bg-white px-1.5 py-0.5 text-[12px] font-bold text-ink hover:bg-paper-deep"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
data-comp="playground-dock-body"
|
||||
className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto p-4"
|
||||
>
|
||||
<div className={pane === 'editor' ? 'contents' : 'hidden'}>{editor}</div>
|
||||
<div className={pane === 'sandbox' ? 'contents' : 'hidden'}>{sandbox}</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import type { ChatItem } from './ChatPanel'
|
||||
import { ChatPanel } from './ChatPanel'
|
||||
import { ChecklistDock } from './ChecklistDock'
|
||||
import { DockSticky } from './DockSticky'
|
||||
import { EditorDock } from './EditorDock'
|
||||
import { KeyModal } from './KeyModal'
|
||||
import { PlaygroundDock } from './PlaygroundDock'
|
||||
import { TipsDock } from './TipsDock'
|
||||
|
||||
const FLOW_TONES = ['coral', 'teal', 'blue'] as const
|
||||
@@ -38,20 +38,24 @@ function appendAssistant(items: ChatItem[], delta: string): ChatItem[] {
|
||||
return next
|
||||
}
|
||||
|
||||
function RunnerStage() {
|
||||
function SandboxPane() {
|
||||
const { preview } = usePlayground()
|
||||
return (
|
||||
<div className="relative h-[280px] overflow-hidden rounded-lg border-2 border-ink bg-white">
|
||||
<SandboxFrame fill />
|
||||
{!preview && (
|
||||
<div className="pointer-events-none absolute inset-0 grid place-content-center gap-1 p-4 text-center">
|
||||
<p className="t-small-strong m-0">沙箱预览</p>
|
||||
<p className="t-small-mute m-0">
|
||||
点右缘「编辑器」签写代码,点「运行 ▶」,构建产物会送进这里真跑。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<section aria-label="web runner 沙箱预览" className="flex min-h-0 flex-1 flex-col gap-2.5">
|
||||
<StatusLine />
|
||||
<div className="relative h-[320px] shrink-0 overflow-hidden rounded-lg border-2 border-ink bg-white">
|
||||
<SandboxFrame fill />
|
||||
{!preview && (
|
||||
<div className="pointer-events-none absolute inset-0 grid place-content-center gap-1 p-4 text-center">
|
||||
<p className="t-small-strong m-0">沙箱预览</p>
|
||||
<p className="t-small-mute m-0">
|
||||
切到「编辑器」页签写代码,点「运行 ▶」回到这里,构建产物送进隔离 iframe 真跑。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<OutputView />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,12 +71,12 @@ export function PracticeWorkspace() {
|
||||
const [draft, setDraft] = useState('')
|
||||
const [focusSignal, setFocusSignal] = useState(0)
|
||||
const [openDock, setOpenDock] = useState<DockPane>(null)
|
||||
const [editorOpen, setEditorOpen] = useState(false)
|
||||
const [dockOpen, setDockOpen] = useState(false)
|
||||
const [checkedIds, setCheckedIds] = useState<readonly string[]>([])
|
||||
const [chat, setChat] = useState<ChatItem[]>(() => [
|
||||
{
|
||||
kind: 'assistant',
|
||||
text: `我是这个练习场的陪练 agent,收在右下角贴签里。当前任务「${task.title}」——点右上角「tips」拉出操作流水线,点任意一步,提示词会自动填进输入框,回车就能发给我;也可以直接聊思路、要代码、贴报错。代码写进右缘「编辑器」侧栏(点右缘小签拉开),点「运行 ▶」在沙箱里真跑;验收清单夹在页面右上角,做完拉出来逐条打勾。`,
|
||||
text: `我是这个练习场的陪练 agent,收在右下角贴签里。当前任务「${task.title}」——点右上角「tips」拉出操作流水线,点任意一步,提示词会自动填进输入框,回车就能发给我;也可以直接聊思路、要代码、贴报错。代码写进右缘侧栏(点「编辑器」签拉开),点「运行 ▶」自动切到「沙箱预览」页签真跑;验收清单夹在页面右上角,做完拉出来逐条打勾。`,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -139,24 +143,6 @@ export function PracticeWorkspace() {
|
||||
return (
|
||||
<div className="pb-24" suppressHydrationWarning>
|
||||
<PlaygroundProvider initialFiles={TEMPLATE_FILES}>
|
||||
<div
|
||||
id="practice-sandbox"
|
||||
className="grid scroll-mt-3 content-start gap-3 lg:sticky lg:top-3 lg:max-h-[calc(100dvh-1.5rem)] lg:overflow-y-auto lg:pr-1"
|
||||
>
|
||||
<section
|
||||
aria-label="web runner 沙箱预览"
|
||||
className="rounded-xl border-2 border-ink bg-paper-deep p-2.5 shadow-ink"
|
||||
>
|
||||
<div className="mb-1.5 flex flex-wrap items-baseline justify-between gap-x-2">
|
||||
<span className="t-small-strong">web runner · 沙箱预览</span>
|
||||
<span className="t-small-mute">隔离 iframe,postMessage 单通道</span>
|
||||
</div>
|
||||
<StatusLine />
|
||||
<RunnerStage />
|
||||
<OutputView />
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<TipsDock
|
||||
panelId="tips-dock-panel"
|
||||
open={openDock === 'tips'}
|
||||
@@ -172,15 +158,19 @@ export function PracticeWorkspace() {
|
||||
</section>
|
||||
</TipsDock>
|
||||
|
||||
<EditorDock
|
||||
panelId="editor-dock-panel"
|
||||
open={editorOpen}
|
||||
onToggle={() => setEditorOpen((v) => !v)}
|
||||
>
|
||||
<FileTabs />
|
||||
<CodeEditor className="min-h-[360px] flex-1" />
|
||||
<RunRow />
|
||||
</EditorDock>
|
||||
<PlaygroundDock
|
||||
panelId="playground-dock-panel"
|
||||
open={dockOpen}
|
||||
onToggle={() => setDockOpen((v) => !v)}
|
||||
editor={
|
||||
<>
|
||||
<FileTabs />
|
||||
<CodeEditor className="min-h-[360px] flex-1" />
|
||||
<RunRow />
|
||||
</>
|
||||
}
|
||||
sandbox={<SandboxPane />}
|
||||
/>
|
||||
</PlaygroundProvider>
|
||||
|
||||
<ChecklistDock
|
||||
|
||||
@@ -50,6 +50,7 @@ export interface PlaygroundApi {
|
||||
sameOriginAlert: boolean
|
||||
done: boolean
|
||||
building: boolean
|
||||
runSeq: number
|
||||
engineReady: boolean
|
||||
preview: boolean
|
||||
iframeRef: RefObject<HTMLIFrameElement>
|
||||
@@ -88,6 +89,7 @@ export function PlaygroundProvider({
|
||||
const [sameOriginAlert, setSameOriginAlert] = useState(false)
|
||||
const [done, setDone] = useState(false)
|
||||
const [building, setBuilding] = useState(false)
|
||||
const [runSeq, setRunSeq] = useState(0)
|
||||
const [preview, setPreview] = useState(false)
|
||||
const [engineReady, setEngineReady] = useState(false)
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null)
|
||||
@@ -178,6 +180,7 @@ export function PlaygroundProvider({
|
||||
|
||||
const run = async () => {
|
||||
if (building) return
|
||||
setRunSeq((s) => s + 1)
|
||||
setLines([])
|
||||
setDone(false)
|
||||
setSameOriginAlert(false)
|
||||
@@ -216,6 +219,7 @@ export function PlaygroundProvider({
|
||||
sameOriginAlert,
|
||||
done,
|
||||
building,
|
||||
runSeq,
|
||||
engineReady,
|
||||
preview,
|
||||
iframeRef,
|
||||
|
||||
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 85 KiB |