|
| 1 | +import type { DevframeHubContext } from '@devframes/hub/node' |
| 2 | +import type { DevframeDockEntryBase } from '@devframes/hub/types' |
| 3 | + |
| 4 | +/** |
| 5 | + * A dock type no renderer covers — registering it exercises the viewer's |
| 6 | + * fallback view (`No renderer for "playground-unrendered" in the current |
| 7 | + * environment`) instead of leaving the dock bar empty. Mirrors |
| 8 | + * `examples/hub-vite/src/unrendered-dock.ts`. |
| 9 | + */ |
| 10 | +interface PlaygroundUnrenderedDockEntry extends DevframeDockEntryBase { |
| 11 | + type: 'playground-unrendered' |
| 12 | +} |
| 13 | + |
| 14 | +declare module '@devframes/hub/types' { |
| 15 | + interface DevframeDockEntryRegistry { |
| 16 | + 'playground-unrendered': PlaygroundUnrenderedDockEntry |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +const unrenderedDockEntry: PlaygroundUnrenderedDockEntry = { |
| 21 | + type: 'playground-unrendered', |
| 22 | + id: 'playground:unrendered', |
| 23 | + title: 'No Renderer', |
| 24 | + icon: 'ph:puzzle-piece-duotone', |
| 25 | + category: 'app', |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Seeds the playground's hub context with just enough content to exercise |
| 30 | + * hub-ui's own surfaces — the dock bar, message center, and command palette — |
| 31 | + * without needing a real mounted devframe SPA. Called from `hub-plugin.ts`'s |
| 32 | + * `configure` hook once the context exists. |
| 33 | + */ |
| 34 | +export async function seedPlayground(ctx: DevframeHubContext): Promise<void> { |
| 35 | + ctx.docks.register(unrenderedDockEntry) |
| 36 | + |
| 37 | + ctx.commands.register({ |
| 38 | + id: 'playground:say-hello', |
| 39 | + title: 'Playground · Say Hello', |
| 40 | + icon: 'ph:hand-waving-duotone', |
| 41 | + category: 'playground', |
| 42 | + handler: () => 'Hello from the hub-ui playground!', |
| 43 | + }) |
| 44 | + ctx.commands.register({ |
| 45 | + id: 'playground:throw', |
| 46 | + title: 'Playground · Throw an Error', |
| 47 | + icon: 'ph:bomb-duotone', |
| 48 | + category: 'playground', |
| 49 | + handler: () => { |
| 50 | + throw new Error('Deliberate playground error — exercises the command palette\'s failure toast.') |
| 51 | + }, |
| 52 | + }) |
| 53 | + |
| 54 | + await ctx.messages.add({ |
| 55 | + level: 'info', |
| 56 | + message: 'Hub UI playground started', |
| 57 | + description: 'Editing anything under packages/hub-ui/src/client hot-reloads this page.', |
| 58 | + }) |
| 59 | + await ctx.messages.add({ |
| 60 | + level: 'success', |
| 61 | + message: 'Sample success message', |
| 62 | + }) |
| 63 | + await ctx.messages.add({ |
| 64 | + level: 'warn', |
| 65 | + message: 'Sample warning message', |
| 66 | + description: 'Messages support an optional description line like this one.', |
| 67 | + }) |
| 68 | + await ctx.messages.add({ |
| 69 | + level: 'error', |
| 70 | + message: 'Sample error message', |
| 71 | + }) |
| 72 | +} |
0 commit comments