polen 0.8.0-next.4 → 0.8.0-next.5

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.
Files changed (37) hide show
  1. package/build/api/vite/plugins/core.d.ts.map +1 -1
  2. package/build/api/vite/plugins/core.js +83 -52
  3. package/build/api/vite/plugins/core.js.map +1 -1
  4. package/build/lib/file-router/linter.d.ts.map +1 -1
  5. package/build/lib/file-router/linter.js +3 -3
  6. package/build/lib/file-router/linter.js.map +1 -1
  7. package/build/lib/file-router/route.d.ts +48 -10
  8. package/build/lib/file-router/route.d.ts.map +1 -1
  9. package/build/lib/file-router/route.js +68 -3
  10. package/build/lib/file-router/route.js.map +1 -1
  11. package/build/lib/file-router/scan.d.ts +2 -2
  12. package/build/lib/file-router/scan.d.ts.map +1 -1
  13. package/build/lib/file-router/scan.js +8 -8
  14. package/build/lib/file-router/scan.js.map +1 -1
  15. package/build/lib/kit-temp.d.ts +2 -0
  16. package/build/lib/kit-temp.d.ts.map +1 -0
  17. package/build/lib/kit-temp.js +23 -0
  18. package/build/lib/kit-temp.js.map +1 -0
  19. package/build/project-data.d.ts +10 -1
  20. package/build/project-data.d.ts.map +1 -1
  21. package/build/template/components/Sidebar.d.ts +11 -0
  22. package/build/template/components/Sidebar.d.ts.map +1 -0
  23. package/build/template/components/Sidebar.jsx +47 -0
  24. package/build/template/components/Sidebar.jsx.map +1 -0
  25. package/build/template/routes/root.d.ts.map +1 -1
  26. package/build/template/routes/root.jsx +28 -5
  27. package/build/template/routes/root.jsx.map +1 -1
  28. package/package.json +1 -1
  29. package/src/api/vite/plugins/core.ts +97 -54
  30. package/src/lib/file-router/index.test.ts +5 -5
  31. package/src/lib/file-router/linter.ts +3 -3
  32. package/src/lib/file-router/route.ts +147 -11
  33. package/src/lib/file-router/scan.ts +9 -9
  34. package/src/lib/kit-temp.ts +21 -0
  35. package/src/project-data.ts +12 -1
  36. package/src/template/components/Sidebar.tsx +92 -0
  37. package/src/template/routes/root.tsx +35 -5
@@ -0,0 +1,92 @@
1
+ import { Box, Flex, Text } from '@radix-ui/themes'
2
+ import { Link, useLocation } from 'react-router'
3
+
4
+ export interface SidebarItem {
5
+ title: string
6
+ pathExp: string
7
+ children?: SidebarItem[]
8
+ }
9
+
10
+ interface SidebarProps {
11
+ items: SidebarItem[]
12
+ }
13
+
14
+ export const Sidebar = ({ items }: SidebarProps) => {
15
+ const location = useLocation()
16
+
17
+ return (
18
+ <Box
19
+ style={{
20
+ width: `240px`,
21
+ borderRight: `1px solid var(--gray-3)`,
22
+ height: `100%`,
23
+ paddingRight: `var(--space-4)`,
24
+ }}
25
+ >
26
+ <Flex direction='column' gap='1'>
27
+ {items.map((item) => (
28
+ <SidebarItem
29
+ key={item.pathExp}
30
+ item={item}
31
+ currentPathExp={location.pathname}
32
+ />
33
+ ))}
34
+ </Flex>
35
+ </Box>
36
+ )
37
+ }
38
+
39
+ interface SidebarItemProps {
40
+ item: SidebarItem
41
+ currentPathExp: string
42
+ level?: number
43
+ }
44
+
45
+ const SidebarItem = ({ item, currentPathExp: currentPath, level = 0 }: SidebarItemProps) => {
46
+ const isActive = currentPath === item.pathExp
47
+ const hasChildren = item.children && item.children.length > 0
48
+
49
+ return (
50
+ <>
51
+ <Link
52
+ to={item.pathExp}
53
+ style={{
54
+ textDecoration: `none`,
55
+ color: isActive ? `var(--accent-11)` : `var(--gray-12)`,
56
+ padding: `var(--space-2) var(--space-3)`,
57
+ paddingLeft: `calc(var(--space-3) + ${(level * 16).toString()}px)`,
58
+ borderRadius: `var(--radius-2)`,
59
+ display: `block`,
60
+ backgroundColor: isActive ? `var(--accent-3)` : `transparent`,
61
+ transition: `background-color 0.2s ease, color 0.2s ease`,
62
+ }}
63
+ onMouseEnter={(e) => {
64
+ if (!isActive) {
65
+ e.currentTarget.style.backgroundColor = `var(--gray-2)`
66
+ }
67
+ }}
68
+ onMouseLeave={(e) => {
69
+ if (!isActive) {
70
+ e.currentTarget.style.backgroundColor = `transparent`
71
+ }
72
+ }}
73
+ >
74
+ <Text size='2' weight={isActive ? `medium` : `regular`}>
75
+ {item.title}
76
+ </Text>
77
+ </Link>
78
+ {hasChildren && (
79
+ <Flex direction='column' gap='1'>
80
+ {item.children!.map((child) => (
81
+ <SidebarItem
82
+ key={child.pathExp}
83
+ item={child}
84
+ currentPathExp={currentPath}
85
+ level={level + 1}
86
+ />
87
+ ))}
88
+ </Flex>
89
+ )}
90
+ </>
91
+ )
92
+ }
@@ -5,10 +5,11 @@ import { Box, Button, Heading, Text } from '@radix-ui/themes'
5
5
  import { Flex, Theme } from '@radix-ui/themes'
6
6
  import radixStylesUrl from '@radix-ui/themes/styles.css?url'
7
7
  import { Link as LinkReactRouter } from 'react-router'
8
- import { Outlet, ScrollRestoration } from 'react-router'
8
+ import { Outlet, ScrollRestoration, useLocation } from 'react-router'
9
9
  import { PROJECT_DATA } from 'virtual:polen/project/data'
10
10
  import { templateVariables } from 'virtual:polen/template/variables'
11
11
  import { Link } from '../components/Link.jsx'
12
+ import { Sidebar } from '../components/Sidebar.jsx'
12
13
  import entryClientUrl from '../entry.client.jsx?url'
13
14
  import { changelog } from './changelog.jsx'
14
15
  import { index } from './index.jsx'
@@ -55,6 +56,23 @@ export const Component = () => {
55
56
  }
56
57
 
57
58
  const Layout = () => {
59
+ const location = useLocation()
60
+
61
+ // Determine if we should show sidebar based on current path
62
+ const getCurrentNavPathExp = (): string | null => {
63
+ // todo: general path manipulation lib because we are duplicating logic here found in FileRouter
64
+ // todo: kit: try a Str.split that returns [] | string[] so that our predicates can refine on it?
65
+ const segments = location.pathname.split(`/`).filter(Boolean)
66
+ if (Arr.isntEmpty(segments)) {
67
+ return `/${segments[0]}`
68
+ }
69
+ return null
70
+ }
71
+
72
+ const currentNavPathExp = getCurrentNavPathExp()
73
+ const sidebarItems = currentNavPathExp && PROJECT_DATA.sidebar[currentNavPathExp]
74
+ const showSidebar = sidebarItems && sidebarItems.length > 0
75
+
58
76
  return (
59
77
  <Theme asChild>
60
78
  <Box m='8'>
@@ -80,15 +98,26 @@ const Layout = () => {
80
98
  </LinkReactRouter>
81
99
  <Flex direction='row' gap='4'>
82
100
  {PROJECT_DATA.siteNavigationItems.map((item, key) => (
83
- <Link key={key} color='gray' to={item.path}>
101
+ <Link key={key} color='gray' to={item.pathExp}>
84
102
  {item.title}
85
103
  </Link>
86
104
  ))}
87
105
  </Flex>
88
106
  </Flex>
89
- <Box>
90
- <Outlet />
91
- </Box>
107
+ {showSidebar
108
+ ? (
109
+ <Flex gap='8'>
110
+ <Sidebar items={sidebarItems} />
111
+ <Box style={{ flex: 1 }}>
112
+ <Outlet />
113
+ </Box>
114
+ </Flex>
115
+ )
116
+ : (
117
+ <Box>
118
+ <Outlet />
119
+ </Box>
120
+ )}
92
121
  </Box>
93
122
  </Theme>
94
123
  )
@@ -165,6 +194,7 @@ children.push(notFoundRoute)
165
194
  //
166
195
  //
167
196
 
197
+ import { Arr } from '@wollybeard/kit'
168
198
  import { pages } from 'virtual:polen/project/pages.jsx'
169
199
 
170
200
  export const root = createRoute({