Skip to content

Commit 6f53c46

Browse files
committed
feat(hub-ui): support transparent standalone viewers
1 parent 2c0c782 commit 6f53c46

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

‎docs/content/1.guide/18.hub-initiate.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface DevframeHubUi {
5959

6060
`@devframes/hub-ui`'s `createUi()` is the reference (viewer + floating dock); its `setup(ctx)` publishes config to `ctx.staticConfig.ui` (`ConnectionMeta.configs.ui`):
6161

62+
- **`viewer`** — set to `false` to disable the standalone viewer, or `{ background: 'transparent' }` when its document should visually inherit an embedding page's surface.
6263
- **`branding`** — rebrand the UI (logo, name, primary color).
6364
- **`dockPreferences`** — dock-bar: `categoryOrder`, floating-dock `maxVisibleItems`, first-run `defaultMode` (`'float'`/`'edge'`) and `defaultPosition`.
6465
- **`embeddedVisibility`** — the floating dock's reveal policy:

‎packages/hub-ui/src/client/standalone/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Devframes</title>
77
<meta name="description" content="Devframes hub" />
8+
<link rel="stylesheet" href="./__hub-ui.css" />
89
<style>
910
html,
1011
body {

‎packages/hub-ui/src/index.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { readFileSync } from 'node:fs'
2+
import { join } from 'node:path'
3+
import { describe, expect, it } from 'vitest'
4+
import { createUi } from './index'
5+
6+
describe('createUi viewer background', () => {
7+
it('loads the runtime viewer stylesheet from the production HTML', () => {
8+
expect.assertions(1)
9+
10+
const html = readFileSync(join(import.meta.dirname, '..', 'dist', 'client', 'standalone', 'index.html'), 'utf8')
11+
12+
expect(html).toContain('<link rel="stylesheet" href="./__hub-ui.css" />')
13+
})
14+
15+
it('preserves the default viewer background', () => {
16+
expect.assertions(1)
17+
18+
const ui = createUi()
19+
20+
expect(ui.assets?.['__hub-ui.css']()).toBe('')
21+
})
22+
23+
it('provides a transparent viewer background when requested', () => {
24+
expect.assertions(1)
25+
26+
const ui = createUi({ viewer: { background: 'transparent' } })
27+
28+
expect(ui.assets?.['__hub-ui.css']()).toBe('html,body{background:transparent!important}')
29+
})
30+
31+
it('does not publish viewer assets when the viewer is disabled', () => {
32+
expect.assertions(2)
33+
34+
const ui = createUi({ viewer: false })
35+
36+
expect(ui.viewer).toBeUndefined()
37+
expect(ui.assets).toBeUndefined()
38+
})
39+
})

‎packages/hub-ui/src/index.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ function clientDir(): string {
3333
}
3434

3535
export interface CreateUiOptions {
36-
/** Serve the standalone viewer SPA at the hub base. Default: `true`. */
37-
viewer?: boolean
36+
/**
37+
* Serve the standalone viewer SPA at the hub base. Pass an object to
38+
* customize the viewer surface. Default: `true`.
39+
*/
40+
viewer?: boolean | {
41+
/** Page background used around transparent renderer content. Default: `'default'`. */
42+
background?: 'default' | 'transparent'
43+
}
3844
/** Serve the floating-dock bootstrap at `<base>embedded.js`. Default: `true`. */
3945
embedded?: boolean
4046
/**
@@ -87,13 +93,23 @@ export interface CreateUiOptions {
8793
*/
8894
export function createUi(options: CreateUiOptions = {}): DevframeHubUi {
8995
const client = clientDir()
96+
const viewerBackground = typeof options.viewer === 'object' ? options.viewer.background : undefined
9097
return {
9198
...(options.viewer !== false
9299
? { viewer: { distDir: join(client, 'standalone') } }
93100
: {}),
94101
...(options.embedded !== false
95102
? { embedded: { entry: join(client, 'embedded.js') } }
96103
: {}),
104+
...(options.viewer !== false
105+
? {
106+
assets: {
107+
'__hub-ui.css': () => viewerBackground === 'transparent'
108+
? 'html,body{background:transparent!important}'
109+
: '',
110+
},
111+
}
112+
: {}),
97113
// Publish the reference UI's config through the generic `ctx.staticConfig`
98114
// — it rides the connection handshake to every mounted frame and the
99115
// standalone viewer as `ConnectionMeta.configs.ui`.

‎tests/__snapshots__/tsnapi/@devframes/hub-ui/index.snapshot.d.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44
// #region Interfaces
55
export interface CreateUiOptions {
6-
viewer?: boolean;
6+
viewer?: boolean | {
7+
background?: 'default' | 'transparent';
8+
};
79
embedded?: boolean;
810
branding?: DevframeBranding;
911
embeddedVisibility?: EmbeddedVisibility;

0 commit comments

Comments
 (0)