|
| 1 | +import type { DevframeViewAction, DevframeViewGroup } from '@devframes/hub' |
| 2 | +import type { DevframeHubContext } from '@devframes/hub/node' |
| 3 | +import type { DevframeDockEntryBase } from '@devframes/hub/types' |
| 4 | +import { PLAYGROUND_GROUP_ID } from './constants' |
| 5 | + |
| 6 | +/** |
| 7 | + * A dock type no renderer covers — registering it exercises the viewer's |
| 8 | + * fallback view (`No renderer for "playground-unrendered" in the current |
| 9 | + * environment`) instead of leaving the dock bar empty. Mirrors |
| 10 | + * `examples/hub-vite/src/unrendered-dock.ts`. |
| 11 | + */ |
| 12 | +interface PlaygroundUnrenderedDockEntry extends DevframeDockEntryBase { |
| 13 | + type: 'playground-unrendered' |
| 14 | +} |
| 15 | + |
| 16 | +declare module '@devframes/hub/types' { |
| 17 | + interface DevframeDockEntryRegistry { |
| 18 | + 'playground-unrendered': PlaygroundUnrenderedDockEntry |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +const unrenderedDockEntry: PlaygroundUnrenderedDockEntry = { |
| 23 | + type: 'playground-unrendered', |
| 24 | + id: 'playground:unrendered', |
| 25 | + title: 'No Renderer', |
| 26 | + icon: 'ph:puzzle-piece-duotone', |
| 27 | + category: 'app', |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * The dock-bar button collapsing the Git devframe (grouped by |
| 32 | + * `hub-plugin.ts`'s `devframes` entry) and the "Ping" action below — |
| 33 | + * exercises the grouped-dock UI (`DockGroupButton`/`DockGroupPopover`) the |
| 34 | + * playground otherwise never touches. |
| 35 | + */ |
| 36 | +const playgroundGroup: DevframeViewGroup = { |
| 37 | + type: 'group', |
| 38 | + id: PLAYGROUND_GROUP_ID, |
| 39 | + title: 'Playground Tools', |
| 40 | + icon: 'ph:flask-duotone', |
| 41 | + category: 'app', |
| 42 | + // No `defaultChildId` — clicking reveals the member popover instead of |
| 43 | + // jumping straight to one, exercising that UI too (`DockGroupPopover`). |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * A one-shot action dock — no panel of its own, just a client script |
| 48 | + * (`client-scripts/ping-action.ts`) the viewer imports and runs on click. |
| 49 | + * Grouped alongside the Git devframe above. |
| 50 | + */ |
| 51 | +const pingAction: DevframeViewAction = { |
| 52 | + type: 'action', |
| 53 | + id: 'playground:ping', |
| 54 | + title: 'Ping', |
| 55 | + icon: 'ph:hand-waving-duotone', |
| 56 | + category: 'app', |
| 57 | + groupId: PLAYGROUND_GROUP_ID, |
| 58 | + action: { importFrom: '/client-scripts/ping-action.ts' }, |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * Seeds the playground's hub context with just enough content to exercise |
| 63 | + * hub-ui's own surfaces — the dock bar, message center, and command palette — |
| 64 | + * without needing a real mounted devframe SPA. Called from `hub-plugin.ts`'s |
| 65 | + * `configure` hook once the context exists. |
| 66 | + */ |
| 67 | +export async function seedPlayground(ctx: DevframeHubContext): Promise<void> { |
| 68 | + ctx.docks.register(unrenderedDockEntry) |
| 69 | + ctx.docks.register(playgroundGroup) |
| 70 | + ctx.docks.register(pingAction) |
| 71 | + |
| 72 | + ctx.commands.register({ |
| 73 | + id: 'playground:say-hello', |
| 74 | + title: 'Playground · Say Hello', |
| 75 | + icon: 'ph:hand-waving-duotone', |
| 76 | + category: 'playground', |
| 77 | + handler: () => 'Hello from the hub-ui playground!', |
| 78 | + }) |
| 79 | + ctx.commands.register({ |
| 80 | + id: 'playground:throw', |
| 81 | + title: 'Playground · Throw an Error', |
| 82 | + icon: 'ph:bomb-duotone', |
| 83 | + category: 'playground', |
| 84 | + handler: () => { |
| 85 | + throw new Error('Deliberate playground error — exercises the command palette\'s failure toast.') |
| 86 | + }, |
| 87 | + }) |
| 88 | + |
| 89 | + await ctx.messages.add({ |
| 90 | + level: 'info', |
| 91 | + message: 'Hub UI playground started', |
| 92 | + description: 'Editing anything under packages/hub-ui/src/client hot-reloads this page.', |
| 93 | + }) |
| 94 | + await ctx.messages.add({ |
| 95 | + level: 'success', |
| 96 | + message: 'Sample success message', |
| 97 | + }) |
| 98 | + await ctx.messages.add({ |
| 99 | + level: 'warn', |
| 100 | + message: 'Sample warning message', |
| 101 | + description: 'Messages support an optional description line like this one.', |
| 102 | + }) |
| 103 | + await ctx.messages.add({ |
| 104 | + level: 'error', |
| 105 | + message: 'Sample error message', |
| 106 | + }) |
| 107 | +} |
0 commit comments