@re-venue/ui-core-react 0.2.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@re-venue/ui-core-react",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/ui-core-react.umd.cjs",
6
6
  "module": "./dist/ui-core-react.js",
@@ -1,7 +1,6 @@
1
1
  import { useMemo, useState, useEffect } from 'react'
2
2
  import type { ReactNode } from 'react'
3
3
  import { ConfirmModal } from './ConfirmModal'
4
- import { VenueSwitcher } from './VenueSwitcher'
5
4
  import { useTheme } from '../hooks/useTheme'
6
5
  import type { AuthUser, SidebarNavItem, Venue } from '../types'
7
6
  import '../styles/shell.css'
@@ -14,9 +13,11 @@ interface Props {
14
13
  navItems: SidebarNavItem[]
15
14
  cookieDomain?: string
16
15
  onSwitchVenue?: (venueId: string) => void
16
+ onSwitchWorkspace?: (workspaceId: string) => void
17
17
  onLogout: () => void
18
18
  accountSettingsUrl?: string
19
19
  headerSlot?: ReactNode
20
+ headerActions?: ReactNode
20
21
  sidebarPanel?: ReactNode
21
22
  scrollable?: boolean
22
23
  children: ReactNode
@@ -55,6 +56,8 @@ function writeSidebarCookie(value: boolean, cookieDomain?: string): void {
55
56
  document.cookie = `${SIDEBAR_COOKIE}=${value}; Path=/; Max-Age=${SIDEBAR_COOKIE_MAX_AGE}; SameSite=Lax${domainPart}`
56
57
  }
57
58
 
59
+ const placementOf = (item: SidebarNavItem) => item.placement ?? 'header'
60
+
58
61
  export function AppShell({
59
62
  user,
60
63
  isAdmin,
@@ -63,9 +66,11 @@ export function AppShell({
63
66
  navItems,
64
67
  cookieDomain,
65
68
  onSwitchVenue,
69
+ onSwitchWorkspace,
66
70
  onLogout,
67
71
  accountSettingsUrl,
68
72
  headerSlot,
73
+ headerActions,
69
74
  sidebarPanel,
70
75
  scrollable = true,
71
76
  children,
@@ -74,6 +79,7 @@ export function AppShell({
74
79
  const [collapsed, setCollapsed] = useState(() => readSidebarCookie())
75
80
  const [showLogoutConfirm, setShowLogoutConfirm] = useState(false)
76
81
  const [currentHref, setCurrentHref] = useState(() => window.location.href)
82
+ const [expanded, setExpanded] = useState<Set<string>>(() => new Set())
77
83
 
78
84
  useEffect(() => {
79
85
  ensureHistoryPatched()
@@ -93,7 +99,14 @@ export function AppShell({
93
99
  }
94
100
 
95
101
  const activeVenue = useMemo(() => venues.find((v) => v.id === activeVenueId), [venues, activeVenueId])
96
- const workspaceName = activeVenue?.workspace?.name ?? ''
102
+ const activeWorkspaceId = activeVenue?.workspace?.id ?? ''
103
+
104
+ // Keep the active workspace expanded by default.
105
+ useEffect(() => {
106
+ if (activeWorkspaceId) {
107
+ setExpanded((prev) => (prev.has(activeWorkspaceId) ? prev : new Set(prev).add(activeWorkspaceId)))
108
+ }
109
+ }, [activeWorkspaceId])
97
110
 
98
111
  const userInitials = useMemo(() => {
99
112
  if (!user?.email) return '?'
@@ -101,20 +114,38 @@ export function AppShell({
101
114
  }, [user?.email])
102
115
 
103
116
  const visibleNavItems = useMemo(() => {
104
- const activeWorkspaceId = activeVenue?.workspace?.id
117
+ const wsId = activeVenue?.workspace?.id
105
118
  return navItems.filter((item) => {
106
119
  if (item.hidden) return false
107
120
  if (!item.permission) return true
108
121
  if (isAdmin) return true
109
122
  if (user?.globalPermissions.includes(item.permission)) return true
110
- if (activeWorkspaceId && user?.workspacePermissions?.[activeWorkspaceId]?.includes(item.permission)) return true
123
+ if (wsId && user?.workspacePermissions?.[wsId]?.includes(item.permission)) return true
111
124
  if (activeVenueId && user?.venuePermissions?.[activeVenueId]?.includes(item.permission)) return true
112
125
  return false
113
126
  })
114
127
  }, [navItems, isAdmin, user, activeVenue, activeVenueId])
115
128
 
116
- const mainNavItems = useMemo(() => visibleNavItems.filter((item) => !item.pinned), [visibleNavItems])
117
- const pinnedNavItems = useMemo(() => visibleNavItems.filter((item) => item.pinned), [visibleNavItems])
129
+ const sidebarNavItems = useMemo(() => visibleNavItems.filter((i) => placementOf(i) === 'sidebar'), [visibleNavItems])
130
+ const headerNavItems = useMemo(() => visibleNavItems.filter((i) => placementOf(i) === 'header'), [visibleNavItems])
131
+ const settingsNavItems = useMemo(() => visibleNavItems.filter((i) => placementOf(i) === 'settings'), [visibleNavItems])
132
+ const workspaceNavItem = useMemo(() => visibleNavItems.find((i) => placementOf(i) === 'workspace'), [visibleNavItems])
133
+ const firstHeaderItem = headerNavItems[0]
134
+
135
+ const tree = useMemo(() => {
136
+ const groups: { id: string; name: string; venues: Venue[] }[] = []
137
+ for (const venue of venues) {
138
+ const ws = venue.workspace
139
+ if (!ws?.id) continue
140
+ let group = groups.find((g) => g.id === ws.id)
141
+ if (!group) {
142
+ group = { id: ws.id, name: ws.name, venues: [] }
143
+ groups.push(group)
144
+ }
145
+ group.venues.push(venue)
146
+ }
147
+ return groups
148
+ }, [venues])
118
149
 
119
150
  const activeNavUrl = useMemo(() => {
120
151
  const matches = navItems
@@ -123,7 +154,32 @@ export function AppShell({
123
154
  return matches[0]?.url ?? null
124
155
  }, [navItems, currentHref])
125
156
 
126
- const showHeader = venues.length > 0 || headerSlot !== undefined
157
+ function toggleWorkspace(id: string) {
158
+ setExpanded((prev) => {
159
+ const next = new Set(prev)
160
+ next.has(id) ? next.delete(id) : next.add(id)
161
+ return next
162
+ })
163
+ }
164
+
165
+ function onWorkspaceTitleClick(workspaceId: string) {
166
+ onSwitchWorkspace?.(workspaceId)
167
+ const url = workspaceNavItem?.url
168
+ if (url) {
169
+ window.location.assign(url)
170
+ } else if (!expanded.has(workspaceId)) {
171
+ toggleWorkspace(workspaceId)
172
+ }
173
+ }
174
+
175
+ function onVenueClick(venueId: string) {
176
+ if (venueId === activeVenueId) return
177
+ onSwitchVenue?.(venueId)
178
+ const url = firstHeaderItem?.url
179
+ if (url) window.location.assign(url)
180
+ }
181
+
182
+ const showHeader = headerNavItems.length > 0 || settingsNavItems.length > 0 || headerActions !== undefined || headerSlot !== undefined
127
183
 
128
184
  return (
129
185
  <div className="rv-app-shell">
@@ -154,7 +210,6 @@ export function AppShell({
154
210
  </clipPath>
155
211
  </defs>
156
212
  </svg>
157
- {workspaceName && <span className="rv-sidebar-workspace">{workspaceName}</span>}
158
213
  </div>
159
214
  )}
160
215
  <button
@@ -178,23 +233,9 @@ export function AppShell({
178
233
 
179
234
  {sidebarPanel && <div className="rv-sidebar-panel">{sidebarPanel}</div>}
180
235
 
181
- <nav className="rv-sidebar-nav">
182
- {mainNavItems.map((item) => (
183
- <a
184
- key={item.url}
185
- href={item.url}
186
- className={`rv-nav-item${item.url === activeNavUrl ? ' rv-active' : ''}`}
187
- title={collapsed ? item.label : undefined}
188
- >
189
- <span className="rv-nav-icon" dangerouslySetInnerHTML={{ __html: item.icon }} />
190
- {!collapsed && <span className="rv-nav-label">{item.label}</span>}
191
- </a>
192
- ))}
193
- </nav>
194
-
195
- {pinnedNavItems.length > 0 && (
196
- <nav className="rv-sidebar-pinned">
197
- {pinnedNavItems.map((item) => (
236
+ {sidebarNavItems.length > 0 && (
237
+ <nav className="rv-sidebar-top-nav">
238
+ {sidebarNavItems.map((item) => (
198
239
  <a
199
240
  key={item.url}
200
241
  href={item.url}
@@ -208,6 +249,49 @@ export function AppShell({
208
249
  </nav>
209
250
  )}
210
251
 
252
+ <div className="rv-sidebar-tree">
253
+ {!collapsed && tree.length > 0 && <div className="rv-tree-section-label">Workspaces &amp; venues</div>}
254
+ {tree.map((ws) => (
255
+ <div key={ws.id} className="rv-tree-group">
256
+ <div className="rv-tree-ws" title={collapsed ? ws.name : undefined}>
257
+ {!collapsed && (
258
+ <button
259
+ className={`rv-tree-disclosure${expanded.has(ws.id) ? ' rv-open' : ''}`}
260
+ aria-label={expanded.has(ws.id) ? 'Collapse workspace' : 'Expand workspace'}
261
+ onClick={(e) => { e.stopPropagation(); toggleWorkspace(ws.id) }}
262
+ >
263
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
264
+ <polyline points="6 9 12 15 18 9" />
265
+ </svg>
266
+ </button>
267
+ )}
268
+ <button className="rv-tree-ws-title" onClick={() => onWorkspaceTitleClick(ws.id)}>
269
+ <svg className="rv-tree-ws-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
270
+ <path d="M3 21h18" /><path d="M5 21V7l7-4 7 4v14" /><path d="M9 9h.01M15 9h.01M9 13h.01M15 13h.01M9 17h.01M15 17h.01" />
271
+ </svg>
272
+ {!collapsed && <span className="rv-tree-ws-name">{ws.name}</span>}
273
+ </button>
274
+ </div>
275
+ {!collapsed && expanded.has(ws.id) && (
276
+ <div className="rv-tree-venues">
277
+ {ws.venues.map((venue) => (
278
+ <button
279
+ key={venue.id}
280
+ className={`rv-tree-venue${venue.id === activeVenueId ? ' rv-active' : ''}`}
281
+ onClick={() => onVenueClick(venue.id)}
282
+ >
283
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
284
+ <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" /><circle cx="12" cy="10" r="3" />
285
+ </svg>
286
+ <span className="rv-tree-venue-name">{venue.name}</span>
287
+ </button>
288
+ ))}
289
+ </div>
290
+ )}
291
+ </div>
292
+ ))}
293
+ </div>
294
+
211
295
  <div className="rv-sidebar-user">
212
296
  <div className="rv-user-avatar">{userInitials}</div>
213
297
  {!collapsed && (
@@ -251,12 +335,39 @@ export function AppShell({
251
335
  <div className="rv-shell-body">
252
336
  {showHeader && (
253
337
  <header className="rv-shell-header">
254
- {headerSlot !== undefined ? headerSlot : (
255
- <VenueSwitcher
256
- value={activeVenueId ?? ''}
257
- venues={venues}
258
- onChange={onSwitchVenue ?? (() => undefined)}
259
- />
338
+ {headerNavItems.length > 0 && (
339
+ <nav className="rv-header-nav">
340
+ {headerNavItems.map((item) => (
341
+ <a
342
+ key={item.url}
343
+ href={item.url}
344
+ className={`rv-header-nav-item${item.url === activeNavUrl ? ' rv-active' : ''}`}
345
+ >
346
+ <span className="rv-nav-icon" dangerouslySetInnerHTML={{ __html: item.icon }} />
347
+ <span className="rv-nav-label">{item.label}</span>
348
+ </a>
349
+ ))}
350
+ </nav>
351
+ )}
352
+ {headerSlot}
353
+ {(headerActions || settingsNavItems.length > 0) && (
354
+ <div className="rv-header-right">
355
+ {headerActions}
356
+ {settingsNavItems.length > 0 && (
357
+ <div className="rv-header-settings">
358
+ {settingsNavItems.map((item) => (
359
+ <a
360
+ key={item.url}
361
+ href={item.url}
362
+ className={`rv-header-action${item.url === activeNavUrl ? ' rv-active' : ''}`}
363
+ >
364
+ <span className="rv-header-action-icon" dangerouslySetInnerHTML={{ __html: item.icon }} />
365
+ <span className="rv-header-action-label">{item.label}</span>
366
+ </a>
367
+ ))}
368
+ </div>
369
+ )}
370
+ </div>
260
371
  )}
261
372
  </header>
262
373
  )}
@@ -278,6 +278,273 @@
278
278
  flex-direction: column;
279
279
  }
280
280
 
281
+ /* Sidebar top nav (e.g. Portfolio, above the tree) */
282
+ .rv-sidebar-top-nav {
283
+ display: flex;
284
+ flex-direction: column;
285
+ gap: 2px;
286
+ padding: 0.625rem 0.5rem 0.25rem;
287
+ flex-shrink: 0;
288
+ }
289
+
290
+ .rv-sidebar.rv-collapsed .rv-sidebar-top-nav {
291
+ padding: 0.5rem 0;
292
+ align-items: center;
293
+ }
294
+
295
+ /* Workspace → venue tree */
296
+ .rv-sidebar-tree {
297
+ flex: 1;
298
+ display: flex;
299
+ flex-direction: column;
300
+ gap: 1px;
301
+ padding: 0.25rem 0.5rem 0.5rem;
302
+ overflow-y: auto;
303
+ }
304
+
305
+ .rv-sidebar.rv-collapsed .rv-sidebar-tree {
306
+ padding: 0.5rem 0;
307
+ align-items: center;
308
+ }
309
+
310
+ .rv-tree-section-label {
311
+ font-size: 0.65rem;
312
+ font-weight: 700;
313
+ letter-spacing: 0.07em;
314
+ text-transform: uppercase;
315
+ color: var(--color-text-muted, #777777);
316
+ padding: 0.375rem 0.625rem 0.25rem;
317
+ }
318
+
319
+ .rv-tree-group {
320
+ display: flex;
321
+ flex-direction: column;
322
+ gap: 1px;
323
+ }
324
+
325
+ .rv-tree-ws {
326
+ display: flex;
327
+ align-items: center;
328
+ gap: 0.25rem;
329
+ }
330
+
331
+ .rv-sidebar.rv-collapsed .rv-tree-ws {
332
+ justify-content: center;
333
+ }
334
+
335
+ .rv-tree-disclosure {
336
+ flex-shrink: 0;
337
+ display: flex;
338
+ align-items: center;
339
+ justify-content: center;
340
+ width: 22px;
341
+ height: 22px;
342
+ border: none;
343
+ background: none;
344
+ cursor: pointer;
345
+ color: var(--color-text-muted, #777777);
346
+ border-radius: var(--radius-sm, 4px);
347
+ }
348
+
349
+ .rv-tree-disclosure svg {
350
+ transition: transform var(--transition-fast, 0.1s ease);
351
+ transform: rotate(-90deg);
352
+ }
353
+
354
+ .rv-tree-disclosure.rv-open svg {
355
+ transform: rotate(0deg);
356
+ }
357
+
358
+ .rv-tree-disclosure:hover {
359
+ background: var(--color-bg-surface, #f0f0f0);
360
+ color: var(--color-text-secondary, #444444);
361
+ }
362
+
363
+ .rv-tree-ws-title {
364
+ flex: 1;
365
+ min-width: 0;
366
+ display: flex;
367
+ align-items: center;
368
+ gap: 0.5rem;
369
+ padding: 0.5rem 0.5rem;
370
+ border: none;
371
+ background: none;
372
+ cursor: pointer;
373
+ border-radius: var(--radius-md, 8px);
374
+ font-family: inherit;
375
+ font-size: 0.875rem;
376
+ font-weight: 600;
377
+ color: var(--color-text-primary, #111111);
378
+ text-align: left;
379
+ }
380
+
381
+ .rv-tree-ws-title:hover {
382
+ background: var(--color-bg-surface, #f0f0f0);
383
+ }
384
+
385
+ .rv-sidebar.rv-collapsed .rv-tree-ws-title {
386
+ justify-content: center;
387
+ width: 100%;
388
+ padding: 0.5rem 0;
389
+ }
390
+
391
+ .rv-tree-ws-icon {
392
+ flex-shrink: 0;
393
+ color: var(--color-text-muted, #777777);
394
+ }
395
+
396
+ .rv-tree-ws-name {
397
+ overflow: hidden;
398
+ text-overflow: ellipsis;
399
+ white-space: nowrap;
400
+ }
401
+
402
+ .rv-tree-venues {
403
+ display: flex;
404
+ flex-direction: column;
405
+ gap: 1px;
406
+ margin: 1px 0 0.25rem 0.9375rem;
407
+ padding-left: 0.875rem;
408
+ border-left: 1px solid var(--color-border-subtle, #d1d5db);
409
+ }
410
+
411
+ .rv-tree-venue {
412
+ display: flex;
413
+ align-items: center;
414
+ gap: 0.5rem;
415
+ padding: 0.4375rem 0.5625rem;
416
+ border: none;
417
+ background: none;
418
+ cursor: pointer;
419
+ border-radius: var(--radius-md, 8px);
420
+ font-family: inherit;
421
+ font-size: 0.8125rem;
422
+ color: var(--color-text-secondary, #444444);
423
+ text-align: left;
424
+ width: 100%;
425
+ }
426
+
427
+ .rv-tree-venue svg {
428
+ flex-shrink: 0;
429
+ color: var(--color-text-muted, #777777);
430
+ }
431
+
432
+ .rv-tree-venue:hover:not(.rv-active) {
433
+ background: var(--color-bg-surface, #f0f0f0);
434
+ color: var(--color-text-primary, #111111);
435
+ }
436
+
437
+ .rv-tree-venue.rv-active {
438
+ background: var(--color-primary-focus, rgba(22, 163, 74, 0.1));
439
+ color: var(--color-primary, #16a34a);
440
+ font-weight: 600;
441
+ }
442
+
443
+ .rv-tree-venue.rv-active svg {
444
+ color: var(--color-primary, #16a34a);
445
+ }
446
+
447
+ .rv-tree-venue-name {
448
+ overflow: hidden;
449
+ text-overflow: ellipsis;
450
+ white-space: nowrap;
451
+ }
452
+
453
+ /* Header nav (top-bar tool buttons) */
454
+ .rv-header-nav {
455
+ display: flex;
456
+ align-items: center;
457
+ gap: 0.25rem;
458
+ }
459
+
460
+ .rv-header-nav-item {
461
+ display: flex;
462
+ align-items: center;
463
+ gap: 0.5rem;
464
+ padding: 0.5rem 0.8125rem;
465
+ border-radius: var(--radius-md, 8px);
466
+ color: var(--color-text-secondary, #444444);
467
+ text-decoration: none;
468
+ font-size: 0.875rem;
469
+ transition: background var(--transition-fast, 0.1s ease), color var(--transition-fast, 0.1s ease);
470
+ white-space: nowrap;
471
+ }
472
+
473
+ .rv-header-nav-item .rv-nav-icon,
474
+ .rv-header-nav-item .rv-nav-icon svg {
475
+ width: 16px;
476
+ height: 16px;
477
+ }
478
+
479
+ .rv-header-nav-item:hover {
480
+ background: var(--color-bg-surface, #f0f0f0);
481
+ color: var(--color-text-primary, #111111);
482
+ }
483
+
484
+ .rv-header-nav-item.rv-active {
485
+ background: var(--color-primary-focus, rgba(22, 163, 74, 0.1));
486
+ color: var(--color-primary, #16a34a);
487
+ font-weight: 600;
488
+ }
489
+
490
+ /* Header right cluster (top-right): app actions + settings */
491
+ .rv-header-right {
492
+ margin-left: auto;
493
+ display: flex;
494
+ align-items: center;
495
+ gap: 0.75rem;
496
+ }
497
+
498
+ .rv-header-settings {
499
+ display: flex;
500
+ align-items: center;
501
+ gap: 0.5rem;
502
+ }
503
+
504
+ .rv-header-action {
505
+ display: inline-flex;
506
+ align-items: center;
507
+ gap: 0.4375rem;
508
+ padding: 0.4375rem 0.75rem;
509
+ border: 1px solid var(--color-border-subtle, #d1d5db);
510
+ border-radius: var(--radius-md, 8px);
511
+ background: var(--color-bg-panel, #ffffff);
512
+ font-family: inherit;
513
+ font-size: 0.8125rem;
514
+ color: var(--color-text-secondary, #444444);
515
+ text-decoration: none;
516
+ white-space: nowrap;
517
+ transition: background var(--transition-fast, 0.1s ease), color var(--transition-fast, 0.1s ease);
518
+ }
519
+
520
+ .rv-header-action:hover {
521
+ background: var(--color-bg-surface, #f0f0f0);
522
+ color: var(--color-text-primary, #111111);
523
+ }
524
+
525
+ .rv-header-action.rv-active {
526
+ background: var(--color-primary-focus, rgba(22, 163, 74, 0.1));
527
+ border-color: var(--color-primary-focus, rgba(22, 163, 74, 0.1));
528
+ color: var(--color-primary, #16a34a);
529
+ font-weight: 600;
530
+ }
531
+
532
+ .rv-header-action.rv-active .rv-header-action-icon {
533
+ color: var(--color-primary, #16a34a);
534
+ }
535
+
536
+ .rv-header-action-icon {
537
+ display: flex;
538
+ align-items: center;
539
+ justify-content: center;
540
+ color: var(--color-text-muted, #777777);
541
+ }
542
+
543
+ .rv-header-action-icon svg {
544
+ width: 15px;
545
+ height: 15px;
546
+ }
547
+
281
548
  /* VenueSwitcher */
282
549
  .rv-venue-switcher {
283
550
  position: relative;
package/src/types.ts CHANGED
@@ -16,12 +16,23 @@ export interface Venue {
16
16
  }
17
17
  }
18
18
 
19
+ /**
20
+ * Where a nav item is surfaced in the AppShell chrome:
21
+ * - 'sidebar' → rendered above the workspace/venue tree (e.g. Portfolio)
22
+ * - 'header' → a top-bar tool button (default); the first one is the venue-click target
23
+ * - 'workspace' → not rendered; its url is the target when a workspace title is clicked (e.g. Dashboard)
24
+ * - 'settings' → top-right settings cluster (e.g. Venue/Workspace Settings)
25
+ */
26
+ export type NavPlacement = 'sidebar' | 'header' | 'workspace' | 'settings'
27
+
19
28
  export interface SidebarNavItem {
20
29
  label: string
21
30
  url: string
22
31
  icon: string
23
32
  permission?: string
33
+ placement?: NavPlacement
24
34
  active?: boolean
35
+ /** @deprecated superseded by `placement: 'settings'`; ignored by the new layout */
25
36
  pinned?: boolean
26
37
  hidden?: boolean
27
38
  }