Skip to content

Commit 0ac8081

Browse files
authored
feat(hub): support dock defaults on DevframeDefinition (#94)
1 parent 1223160 commit 0ac8081

5 files changed

Lines changed: 86 additions & 4 deletions

File tree

packages/devframe/src/types/devframe.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@ export interface DevframeCliOptions {
175175
flags?: CliFlagsSchema
176176
}
177177

178+
/**
179+
* Default dock attributes for the iframe entry a hub synthesizes when it
180+
* mounts this devframe. Framework-neutral metadata only — the hub layer
181+
* (`mountDevframe`) merges these beneath its per-mount `dock` overrides,
182+
* which in turn sit beneath the locked, derived `id` / `type` / `url`.
183+
*
184+
* Every field is optional. `title` / `icon` default to the definition's
185+
* `name` / `icon` when omitted here; the rest are unset by default.
186+
* Standalone adapters (`cli` / `spa` / `build`) ignore this entirely.
187+
*/
188+
export interface DevframeDockDefaults {
189+
/** Dock entry title. Defaults to the definition's `name`. */
190+
title?: string
191+
/** Dock entry icon. Defaults to the definition's `icon`. */
192+
icon?: string | { light: string, dark: string }
193+
/**
194+
* Sort weight within the dock; higher sorts earlier.
195+
* @default 0
196+
*/
197+
defaultOrder?: number
198+
/**
199+
* Category the entry groups under in the dock.
200+
* @default 'default'
201+
*/
202+
category?: string
203+
/**
204+
* Conditional-visibility expression (same syntax as command `when`
205+
* clauses). Set to `'false'` to hide the entry unconditionally.
206+
*/
207+
when?: string
208+
/** Badge text rendered on the dock icon (e.g. an unread count). */
209+
badge?: string
210+
/** Id of the dock group this entry collapses under, if any. */
211+
groupId?: string
212+
}
213+
178214
export interface DevframeSpaOptions {
179215
base?: string
180216
/**
@@ -215,6 +251,15 @@ export interface DevframeDefinition {
215251
/** One-line summary of what the tool does. */
216252
description: string
217253
icon?: string | { light: string, dark: string }
254+
/**
255+
* Default dock attributes applied when a hub mounts this devframe as an
256+
* iframe dock entry. Consulted only by hub adapters (`mountDevframe`),
257+
* which merge these beneath the per-mount `dock` overrides; standalone
258+
* adapters (`cli` / `spa` / `build`) ignore it.
259+
*
260+
* @see {@link DevframeDockDefaults}
261+
*/
262+
dock?: DevframeDockDefaults
218263
/**
219264
* Mount path override. Defaults depend on the adapter:
220265
* `/` for standalone (`cli` / `spa` / `build`), `/__<id>/` for hosted

packages/hub/src/node/__tests__/mount-devframe.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ describe('mountDevframe', () => {
5555
expect(setup).toHaveBeenCalledTimes(1)
5656
})
5757

58+
it('applies the definition-level dock defaults to the synthesized entry', async () => {
59+
const ctx = createContext()
60+
await mountDevframe(ctx, makeDevframe({
61+
dock: { category: 'framework', defaultOrder: 5, when: 'clientType == embedded' },
62+
}))
63+
64+
expect(ctx.docks.views.get('demo')).toMatchObject({
65+
id: 'demo',
66+
title: 'Demo',
67+
type: 'iframe',
68+
category: 'framework',
69+
defaultOrder: 5,
70+
when: 'clientType == embedded',
71+
})
72+
})
73+
74+
it('lets per-mount dock overrides win over the definition dock defaults', async () => {
75+
const ctx = createContext()
76+
await mountDevframe(
77+
ctx,
78+
makeDevframe({ dock: { category: 'framework', defaultOrder: 5 } }),
79+
{ dock: { category: 'app' } },
80+
)
81+
82+
expect(ctx.docks.views.get('demo')).toMatchObject({
83+
category: 'app',
84+
defaultOrder: 5,
85+
})
86+
})
87+
5888
it('warns and deduplicates by default, keeping the first registration', async () => {
5989
const ctx = createContext()
6090
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})

packages/hub/src/node/mount-devframe.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export interface MountDevframeOptions {
1111
*/
1212
base?: string
1313
/**
14-
* Overrides for the auto-synthesized iframe dock entry. Use this to
15-
* customize the entry's `category`, override the icon, hide it via
16-
* `when`, etc. Cannot change `id`, `type`, or `url` — those are
17-
* derived from the devframe definition.
14+
* Per-mount overrides for the auto-synthesized iframe dock entry. Use
15+
* this to customize the entry's `category`, override the icon, hide it
16+
* via `when`, etc. Takes precedence over the definition's own
17+
* {@link DevframeDefinition.dock} defaults. Cannot change `id`, `type`,
18+
* or `url` — those are derived from the devframe definition.
1819
*/
1920
dock?: Partial<Omit<DevframeViewIframe, 'id' | 'type' | 'url'>>
2021
}
@@ -85,6 +86,10 @@ export async function mountDevframe(
8586
id,
8687
title: d.name,
8788
icon: d.icon ?? 'ph:plug-duotone',
89+
// Definition-level `dock` defaults sit above the name/icon-derived
90+
// defaults; per-mount `options.dock` overrides them; `type`/`url`
91+
// (and `id`) stay locked, derived from the definition.
92+
...d.dock,
8893
...options.dock,
8994
type: 'iframe',
9095
url: base,

tests/__snapshots__/tsnapi/devframe/index.snapshot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export { DevframeDeploymentKind }
2727
export { DevframeDiagnosticsDefinition }
2828
export { DevframeDiagnosticsHost }
2929
export { DevframeDiagnosticsLogger }
30+
export { DevframeDockDefaults }
3031
export { DevframeDuplicationStrategy }
3132
export { DevframeHost }
3233
export { DevframeNodeContext }

tests/__snapshots__/tsnapi/devframe/types.snapshot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export { DevframeDeploymentKind }
2323
export { DevframeDiagnosticsDefinition }
2424
export { DevframeDiagnosticsHost }
2525
export { DevframeDiagnosticsLogger }
26+
export { DevframeDockDefaults }
2627
export { DevframeDuplicationStrategy }
2728
export { DevframeHost }
2829
export { DevframeNodeContext }

0 commit comments

Comments
 (0)