Skip to content

Commit bd694fa

Browse files
committed
feat(toolbar): add demo path indicator and use JSDoc comments
1 parent a3d62a2 commit bd694fa

File tree

2 files changed

+22
-20
lines changed
  • examples
    • next/toolbar-demo/example-app/lib
    • vanilla/toolbar-demo/example-app/src

2 files changed

+22
-20
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Toolbar } from '@wpengine/hwp-toolbar';
22

3-
// Singleton toolbar instance
4-
// This ensures the same toolbar state is shared across the app
3+
/**
4+
* Singleton toolbar instance
5+
* This ensures the same toolbar state is shared across the app
6+
*/
57
export const toolbar = new Toolbar({
68
onPreviewChange: (enabled) => {
79
console.log('Preview mode:', enabled);
@@ -10,7 +12,11 @@ export const toolbar = new Toolbar({
1012
},
1113
});
1214

13-
// Register custom nodes
15+
/**
16+
* Register custom nodes
17+
*/
1418
toolbar.register('home', 'Home', () => {
1519
window.location.href = '/';
1620
});
21+
22+
toolbar.register('demo-path', 'examples/next/toolbar-demo');

examples/vanilla/toolbar-demo/example-app/src/main.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,37 @@ import './style.css';
44

55
const WP_URL = import.meta.env.VITE_WP_URL;
66

7-
// ============================================================================
8-
// Initialize Toolbar
9-
// ============================================================================
10-
7+
/**
8+
* Initialize Toolbar
9+
*/
1110
const toolbar = new Toolbar({
1211
onPreviewChange: (enabled) => {
1312
console.log('Preview mode:', enabled);
1413
alert(`Preview mode: ${enabled ? 'ON' : 'OFF'}\n\nIn production, this would trigger Next.js/framework preview mode`);
1514
}
1615
});
1716

18-
// Render toolbar to DOM
1917
const renderer = new VanillaRenderer(toolbar, 'toolbar');
2018

21-
// ============================================================================
22-
// Register Custom Nodes
23-
// ============================================================================
24-
19+
/**
20+
* Register Custom Nodes
21+
*/
2522
toolbar.register('home', 'Home', () => {
2623
window.location.href = '/';
2724
});
2825

29-
// ============================================================================
30-
// State Management
31-
// ============================================================================
26+
toolbar.register('demo-path', 'examples/vanilla/toolbar-demo');
3227

33-
// Subscribe to state changes for debugging display
28+
/**
29+
* State Management
30+
*/
3431
toolbar.subscribe((nodes, state) => {
3532
document.getElementById('state').textContent = JSON.stringify(state, null, 2);
3633
});
3734

38-
// ============================================================================
39-
// Demo Actions
40-
// ============================================================================
41-
35+
/**
36+
* Demo Actions
37+
*/
4238
window.login = async () => {
4339
try {
4440
const response = await fetch(`${WP_URL}/?rest_route=/wp/v2/users/1`);

0 commit comments

Comments
 (0)