@principal-ade/panel-layouts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Principal ADE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,466 @@
1
+ # @principal-ade/panel-layouts
2
+
3
+ > Pre-built panel layout components and workspace management for the Panel Framework
4
+
5
+ This package provides ready-to-use panel layout components, workspace presets, and persistence hooks that work with `@principal-ade/panel-framework-core`. Built on top of `@a24z/panels`, it adds workspace management, persistence, and pre-configured layouts from the electron-app.
6
+
7
+ ## 🎯 Purpose
8
+
9
+ While `@principal-ade/panel-framework-core` provides the foundation for how panels *work* (registration, lifecycle, events), this package handles how panels *arrange on screen* (layouts, resizing, workspaces).
10
+
11
+ This package = **@a24z/panels** (layout primitives) + **persistence** + **workspace management** + **preset layouts**
12
+
13
+ ## 📦 What This Package Provides
14
+
15
+ ### Re-exported Components (from @a24z/panels)
16
+
17
+ We re-export the core layout components from `@a24z/panels` for convenience:
18
+
19
+ - **`ConfigurablePanelLayout`** - Main layout component supporting 2 or 3 panel configurations
20
+ - **`TabGroup`** - Tab-based panel grouping
21
+ - **`PanelConfigurator`** - Interactive UI for configuring layouts
22
+ - **`AnimatedResizableLayout`** - Lower-level resizable layout primitive
23
+ - **Types:** `PanelLayout`, `PanelSlot`, `PanelGroup`, `TabsConfig`, `TilesConfig`
24
+
25
+ These components provide:
26
+ - Resizable panels with drag handles (powered by `react-resizable-panels`)
27
+ - Collapsible panels with animations
28
+ - Tab groups and tile arrangements
29
+ - Theme integration with `@a24z/industry-theme`
30
+ - 2-panel and 3-panel layout support
31
+
32
+ ### Our Value-Add: Hooks (Extracted from electron-app)
33
+
34
+ #### `usePanelPersistence`
35
+ **NEW - Extracted from electron-app**
36
+
37
+ Manages saving and loading panel sizes and collapsed states:
38
+ - Saves to user preferences (Electron) or localStorage (web)
39
+ - Supports both 2-panel and 3-panel layouts
40
+ - Debounced saving (500ms) to avoid excessive writes
41
+ - Handles collapse/expand animations
42
+ - Tracks last non-zero sizes for restoring after collapse
43
+
44
+ **Source:** `/Users/griever/Developer/electron-app/src/renderer/hooks/usePanelPersistence.ts`
45
+
46
+ #### `useWorkspace`
47
+ **NEW - Convenience hook**
48
+
49
+ Easy workspace management:
50
+ - Load and apply workspace presets
51
+ - Switch between workspaces
52
+ - Create custom workspaces
53
+ - React hooks API for workspace state
54
+
55
+ ### Our Value-Add: Services (Extracted from electron-app)
56
+
57
+ #### `WorkspaceLayoutService`
58
+ **NEW - Extracted from electron-app**
59
+
60
+ Manages workspace presets and configurations:
61
+ - CRUD operations for custom workspaces
62
+ - Built-in workspace presets (Feed View, Code Review, etc.)
63
+ - Per-repository workspace state tracking
64
+ - Workspace switching and persistence
65
+
66
+ **Source:** `/Users/griever/Developer/electron-app/src/renderer/services/WorkspaceLayoutService.ts`
67
+
68
+ ### Our Value-Add: Pre-built Layouts (Extracted from electron-app)
69
+
70
+ **NEW - Ready-to-use layout configurations**
71
+
72
+ Ready-to-use React components wrapping `ConfigurablePanelLayout` with preset configurations:
73
+
74
+ #### `FeedViewLayout`
75
+ Three-panel layout optimized for repository exploration:
76
+ - **Left Panel (20%):** Projects, Stars, Social, Graphs
77
+ - **Middle Panel (80%):** Commits, README, Signals
78
+ - **Right Panel:** Collapsed by default
79
+
80
+ **Source:** `/Users/griever/Developer/electron-app/src/renderer/principal-window/views/FeedView/FeedView.tsx`
81
+
82
+ #### Other Workspace Presets (to be extracted from electron-app)
83
+ - `ProjectManagementLayout` - Project tracking and planning
84
+ - `CodeReviewLayout` - Git changes and diffs
85
+ - `DocumentationLayout` - README and markdown focus
86
+ - `AgentWorkLayout` - AI agent interaction
87
+ - `QualityCheckLayout` - Code quality metrics
88
+ - `DrawingLayout` - Excalidraw integration
89
+ - `PrincipalOfficeLayout` - Executive dashboard
90
+
91
+ ## 📋 Type Definitions
92
+
93
+ ### Re-exported from @a24z/panels
94
+
95
+ ```typescript
96
+ // Panel Layout Structure (from @a24z/panels)
97
+ interface PanelLayout {
98
+ left?: PanelSlot;
99
+ middle?: PanelSlot;
100
+ right?: PanelSlot;
101
+ }
102
+
103
+ // Panel Slot Configuration
104
+ type PanelSlot = string | null | PanelGroup;
105
+
106
+ interface PanelGroup {
107
+ type: 'tabs' | 'tiles';
108
+ panels: string[];
109
+ config?: TabsConfig | TilesConfig;
110
+ }
111
+
112
+ // Tabs Configuration
113
+ interface TabsConfig {
114
+ defaultActiveTab?: number;
115
+ tabPosition?: 'top' | 'bottom' | 'left' | 'right';
116
+ centered?: boolean;
117
+ activeTabIndex?: number;
118
+ onTabChange?: (index: number) => void;
119
+ }
120
+
121
+ // Tiles Configuration
122
+ interface TilesConfig {
123
+ direction?: 'horizontal' | 'vertical' | 'grid';
124
+ columns?: number;
125
+ rows?: number;
126
+ tileSizes?: number[];
127
+ }
128
+ ```
129
+
130
+ ### Our New Types
131
+
132
+ ```typescript
133
+ // Workspace Preset (NEW)
134
+ interface WorkspacePreset {
135
+ id: string;
136
+ name: string;
137
+ description?: string;
138
+ icon?: string;
139
+ layout: PanelLayout;
140
+ defaultSizes?: {
141
+ left?: number;
142
+ middle?: number;
143
+ right?: number;
144
+ };
145
+ collapsed?: {
146
+ left?: boolean;
147
+ right?: boolean;
148
+ };
149
+ }
150
+
151
+ // Panel Persistence Options (NEW)
152
+ interface PanelPersistenceOptions {
153
+ viewKey: string;
154
+ defaultSizes: PanelSizes | TwoPanelSizes;
155
+ collapsed: PanelCollapsed | { left?: boolean };
156
+ panelType: 'three-panel' | 'two-panel';
157
+ }
158
+ ```
159
+
160
+ ## 🚀 Proposed Usage
161
+
162
+ ```typescript
163
+ import { PanelHarness, globalPanelRegistry } from '@principal-ade/panel-framework-core';
164
+ import {
165
+ FeedViewLayout,
166
+ usePanelPersistence,
167
+ WorkspaceLayoutService
168
+ } from '@principal-ade/panel-layouts';
169
+
170
+ // Register your panels
171
+ globalPanelRegistry.register({
172
+ metadata: { id: 'git-changes', name: 'Git Changes' },
173
+ component: GitChangesPanel,
174
+ });
175
+
176
+ function App() {
177
+ // Use persistence hook for saving layout state
178
+ const { sizes, collapsed, handleResize } = usePanelPersistence('my-app');
179
+
180
+ return (
181
+ <PanelHarness context={context} actions={actions} events={events}>
182
+ <FeedViewLayout
183
+ defaultSizes={sizes}
184
+ collapsed={collapsed}
185
+ onResize={handleResize}
186
+ />
187
+ </PanelHarness>
188
+ );
189
+ }
190
+ ```
191
+
192
+ ### Using ConfigurablePanelLayout Directly
193
+
194
+ ```typescript
195
+ import { ConfigurablePanelLayout } from '@principal-ade/panel-layouts';
196
+
197
+ <ConfigurablePanelLayout
198
+ panels={[
199
+ { id: 'git-changes', content: <GitChangesPanel /> },
200
+ { id: 'readme', content: <ReadmePanel /> },
201
+ { id: 'commits', content: <CommitsPanel /> },
202
+ ]}
203
+ layout={{
204
+ left: {
205
+ type: 'tabs',
206
+ panels: ['git-changes'],
207
+ config: { defaultActiveTab: 0, tabPosition: 'top' }
208
+ },
209
+ middle: {
210
+ type: 'tabs',
211
+ panels: ['readme', 'commits'],
212
+ config: { defaultActiveTab: 0 }
213
+ },
214
+ right: null
215
+ }}
216
+ defaultSizes={{ left: 30, middle: 70, right: 0 }}
217
+ collapsed={{ left: false, right: true }}
218
+ collapsiblePanels={{ left: true, right: false }}
219
+ showCollapseButtons={true}
220
+ onPanelResize={(sizes) => console.log('Resized:', sizes)}
221
+ />
222
+ ```
223
+
224
+ ### Using Workspace Presets
225
+
226
+ ```typescript
227
+ import { WorkspaceLayoutService } from '@principal-ade/panel-layouts';
228
+
229
+ // Get built-in workspaces
230
+ const workspaces = WorkspaceLayoutService.getBuiltInWorkspaces();
231
+
232
+ // Apply a workspace
233
+ WorkspaceLayoutService.applyWorkspace('code-review', repositoryPath);
234
+
235
+ // Create custom workspace
236
+ WorkspaceLayoutService.createCustomWorkspace({
237
+ id: 'my-workflow',
238
+ name: 'My Custom Workflow',
239
+ layout: { /* ... */ },
240
+ defaultSizes: { left: 25, middle: 50, right: 25 }
241
+ });
242
+ ```
243
+
244
+ ## 📁 Package Structure
245
+
246
+ ```
247
+ @principal-ade/panel-layouts/
248
+ ├── src/
249
+ │ ├── index.ts # Main entry - re-exports from @a24z/panels + our code
250
+ │ ├── layouts/
251
+ │ │ ├── FeedViewLayout.tsx # Pre-built feed view
252
+ │ │ ├── ProjectManagementLayout.tsx # Project management preset
253
+ │ │ ├── CodeReviewLayout.tsx # Code review preset
254
+ │ │ ├── DocumentationLayout.tsx # Documentation preset
255
+ │ │ └── index.ts
256
+ │ ├── hooks/
257
+ │ │ ├── usePanelPersistence.ts # Layout state persistence (extracted)
258
+ │ │ ├── useWorkspace.ts # Workspace management hook
259
+ │ │ └── index.ts
260
+ │ ├── services/
261
+ │ │ ├── WorkspaceLayoutService.ts # Workspace CRUD operations (extracted)
262
+ │ │ └── index.ts
263
+ │ └── types/
264
+ │ ├── workspace.types.ts # Workspace types
265
+ │ ├── persistence.types.ts # Persistence types
266
+ │ └── index.ts
267
+ ├── package.json
268
+ ├── tsconfig.json
269
+ ├── vite.config.ts
270
+ ├── README.md
271
+ └── LICENSE
272
+ ```
273
+
274
+ **Note:** We don't duplicate `ConfigurablePanelLayout`, `TabGroup`, etc. - we re-export them from `@a24z/panels`.
275
+
276
+ ## 🔗 Dependencies
277
+
278
+ ```json
279
+ {
280
+ "peerDependencies": {
281
+ "@principal-ade/panel-framework-core": "^0.1.0",
282
+ "react": ">=18.0.0",
283
+ "react-dom": ">=18.0.0"
284
+ },
285
+ "dependencies": {
286
+ "@a24z/panels": "^1.0.26",
287
+ "@a24z/industry-theme": "^0.1.1",
288
+ "react-resizable-panels": "^3.0.0"
289
+ }
290
+ }
291
+ ```
292
+
293
+ **Architecture:**
294
+ - We depend on `@a24z/panels` for layout primitives (ConfigurablePanelLayout, TabGroup, etc.)
295
+ - `@a24z/panels` depends on `react-resizable-panels` for resizing functionality
296
+ - We re-export components from `@a24z/panels` for convenience
297
+ - We add our own persistence, workspace management, and preset layouts on top
298
+
299
+ ## 🎨 Design Principles
300
+
301
+ ### 1. Layered Architecture
302
+ - **@principal-ade/panel-framework-core:** Panel registration, lifecycle, events
303
+ - **@a24z/panels:** Layout primitives, resizing, collapsing, theming
304
+ - **@principal-ade/panel-layouts (this package):** Persistence, workspaces, presets
305
+
306
+ ### 2. Reuse Over Rebuild
307
+ We build on top of proven components (`@a24z/panels`) rather than reinventing the wheel. This allows us to:
308
+ - Focus on high-value features (workspaces, persistence)
309
+ - Get resizing, animations, and theming for free
310
+ - Maintain compatibility with existing electron-app code
311
+
312
+ ### 3. Optional Dependency
313
+ Users can use `@principal-ade/panel-framework-core` + `@a24z/panels` directly if they don't need workspace management.
314
+
315
+ ### 4. Composable
316
+ All components are composable - users can:
317
+ - Use pre-built layouts as-is (`FeedViewLayout`)
318
+ - Use `ConfigurablePanelLayout` with custom configs
319
+ - Use `@a24z/panels` directly for full control
320
+
321
+ ### 5. Persistence-Ready
322
+ Built-in support for saving/loading layout state to:
323
+ - localStorage (web)
324
+ - User preferences (Electron via IPC)
325
+ - Remote storage (optional extension point)
326
+
327
+ ## 📝 Implementation Steps
328
+
329
+ ### Phase 1: Package Setup and Re-exports
330
+ 1. ✅ Set up package structure with TypeScript and Vite
331
+ 2. ✅ Install `@a24z/panels` as a dependency
332
+ 3. ✅ Create re-export index that exposes components from `@a24z/panels`
333
+ 4. ✅ Configure build to output ESM/CJS with CSS
334
+
335
+ **What we're doing:** Setting up the foundation and making `@a24z/panels` components available through our package.
336
+
337
+ ### Phase 2: Extract Persistence Hook (High Priority)
338
+ 1. Extract `usePanelPersistence` from electron-app
339
+ 2. Adapt for both web (localStorage) and Electron (IPC) environments
340
+ 3. Add type definitions
341
+ 4. Write unit tests
342
+
343
+ **Source File:**
344
+ - `/Users/griever/Developer/electron-app/src/renderer/hooks/usePanelPersistence.ts`
345
+
346
+ **What we're doing:** Adding the state persistence layer that `@a24z/panels` doesn't provide.
347
+
348
+ ### Phase 3: Extract Workspace Service
349
+ 1. Extract `WorkspaceLayoutService` from electron-app
350
+ 2. Adapt for both web and Electron environments
351
+ 3. Define built-in workspace presets
352
+ 4. Create `useWorkspace` convenience hook
353
+ 5. Write unit tests
354
+
355
+ **Source File:**
356
+ - `/Users/griever/Developer/electron-app/src/renderer/services/WorkspaceLayoutService.ts`
357
+
358
+ **What we're doing:** Adding workspace management for quick layout switching.
359
+
360
+ ### Phase 4: Create Pre-built Layout Components
361
+ 1. Extract FeedView layout configuration
362
+ 2. Create React component wrappers for each preset
363
+ 3. Make them configurable and extensible
364
+ 4. Document each preset's use case
365
+
366
+ **Source Files:**
367
+ - `/Users/griever/Developer/electron-app/src/renderer/principal-window/views/FeedView/FeedView.tsx`
368
+ - Workspace definitions from WorkspaceLayoutService
369
+
370
+ **What we're doing:** Creating ready-to-use layout components for common use cases.
371
+
372
+ ### Phase 5: Documentation and Publishing
373
+ 1. Write comprehensive usage documentation
374
+ 2. Create example applications (web + Electron)
375
+ 3. Add migration guide from electron-app
376
+ 4. Publish to npm as `@principal-ade/panel-layouts`
377
+
378
+ ## 🔄 Integration with electron-app
379
+
380
+ Once published, the electron-app can replace its current implementation:
381
+
382
+ ```diff
383
+ - import { ConfigurablePanelLayout } from '@a24z/panels';
384
+ - import { usePanelPersistence } from '../hooks/usePanelPersistence';
385
+ + import { ConfigurablePanelLayout, usePanelPersistence } from '@principal-ade/panel-layouts';
386
+ ```
387
+
388
+ Benefits:
389
+ - Shared between web and desktop
390
+ - Community can contribute improvements
391
+ - Consistent across all applications
392
+ - Easier to maintain
393
+
394
+ ## 📚 Related Packages
395
+
396
+ - **@principal-ade/panel-framework-core** - Core panel system (published)
397
+ - **@principal-ade/panel-layouts** - This package (to be implemented)
398
+ - **@a24z/panels** - Current layout implementation in electron-app
399
+ - **@a24z/industry-theme** - Theming system used by layouts
400
+
401
+ ## 🤝 Contributing
402
+
403
+ This package is designed to be the standard layout system for Panel Framework applications. Contributions should focus on:
404
+
405
+ 1. **Performance** - Layouts should be fast and responsive
406
+ 2. **Flexibility** - Support various use cases and customization
407
+ 3. **Accessibility** - Keyboard navigation, screen reader support
408
+ 4. **Documentation** - Clear examples and API docs
409
+
410
+ ## 📄 License
411
+
412
+ MIT
413
+
414
+ ---
415
+
416
+ ## 🚧 Current Status
417
+
418
+ **Status:** 🚧 In Active Development
419
+
420
+ This package is being actively developed with a focus on reusing `@a24z/panels` and adding workspace/persistence features.
421
+
422
+ ### Implementation Progress:
423
+ - ✅ README specification complete
424
+ - ✅ Package setup and build configuration (Vite + TypeScript)
425
+ - ✅ Re-exports from @a24z/panels (25+ components)
426
+ - ✅ `usePanelPersistence` hook extracted and adapted
427
+ - ✅ `LocalStoragePersistenceAdapter` for web apps
428
+ - ✅ Storybook with interactive component stories
429
+ - ✅ ESLint + TypeScript linting configured
430
+ - ✅ Vitest test suite (14 tests passing)
431
+ - ⏳ Extract `WorkspaceLayoutService` (next)
432
+ - ⏳ Create pre-built layout components
433
+ - ⏳ Additional documentation and examples
434
+ - ⏳ Publish to npm
435
+
436
+ ### Architecture Decision:
437
+ We're **reusing** `@a24z/panels@1.0.27` as a dependency rather than rebuilding layout components. This allows us to:
438
+ - Focus on high-value features (persistence, workspaces, presets)
439
+ - Leverage proven, tested layout components
440
+ - Maintain compatibility with existing electron-app code
441
+
442
+ ### What's Working Now:
443
+ ```bash
444
+ # Development
445
+ npm run dev # Start Vite dev server
446
+ npm run storybook # Start Storybook on :6006
447
+
448
+ # Quality Checks
449
+ npm run type-check # TypeScript type checking ✅
450
+ npm run lint # ESLint (2 warnings) ✅
451
+ npm run test # Vitest (14/14 passing) ✅
452
+
453
+ # Build
454
+ npm run build # Build ESM + CJS + types ✅
455
+ ```
456
+
457
+ ### Package Contents:
458
+ - **Re-exported:** All components from @a24z/panels
459
+ - **New:** `usePanelPersistence` hook with localStorage adapter
460
+ - **New:** Comprehensive TypeScript types
461
+ - **New:** Interactive Storybook documentation
462
+
463
+ ### Reference Files (electron-app):
464
+ - Persistence: `/Users/griever/Developer/electron-app/src/renderer/hooks/usePanelPersistence.ts`
465
+ - Workspace Service: `/Users/griever/Developer/electron-app/src/renderer/services/WorkspaceLayoutService.ts`
466
+ - FeedView Layout: `/Users/griever/Developer/electron-app/src/renderer/principal-window/views/FeedView/FeedView.tsx`