camelmind 0.2.7 → 0.2.8

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": "camelmind",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Create and manage CamelMind documentation sites",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -97,7 +97,8 @@ export default async function DocPage({ params }: Props) {
97
97
 
98
98
  const activeGroup = getGroupForSlugFromConfig(nav, fullSlug) as NavGroup | null
99
99
  const sectionEntry = getSectionForSlugFromConfig(nav, fullSlug) as NavEntry | null
100
- const { frontmatter, source, toc, lastUpdated, lastUpdatedAuthor } = loadMdxFile(navEntry.file)
100
+ const { frontmatter, source: rawSource, toc, lastUpdated, lastUpdatedAuthor } = loadMdxFile(navEntry.file)
101
+ const source = rawSource.replace(/\n+([ \t]*<\/Tab>)/g, "\n\n{' '}\n\n$1")
101
102
  const isSectionRoot = sectionEntry?.slug === fullSlug
102
103
 
103
104
  return (
@@ -60,7 +60,7 @@ export function TopNav({ nav, userRoles, userName, authEnabled = false, versions
60
60
  <div className="hidden md:flex items-center gap-6 flex-1">
61
61
  {nav.map((item) => {
62
62
  if (isNavGroup(item)) {
63
- const visibleItems = (item.items ?? []).filter((i) => canSee(i.roles))
63
+ const visibleItems = (item.items ?? []).filter((i) => canSee(i.roles) && !i.hidden_from_nav)
64
64
  const directHref = item.slug ?? visibleItems[0]?.slug
65
65
 
66
66
  if ((item.noDropdown || !item.items) && directHref) {
@@ -16,59 +16,83 @@ function canSee(roles: string[], userRoles: string[], authEnabled: boolean) {
16
16
  return roles.length === 0 || roles.some((r) => userRoles.includes(r))
17
17
  }
18
18
 
19
+ // Recursively check if any descendant matches the slug
20
+ function subtreeContains(items: NavChild[], slug: string): boolean {
21
+ return items.some(
22
+ (c) => c.slug === slug || (c.children ? subtreeContains(c.children, slug) : false)
23
+ )
24
+ }
25
+
19
26
  // Doc page link (leaf node inside a section)
20
- function DocLink({ item, currentSlug }: { item: NavChild; currentSlug: string }) {
27
+ function DocLink({ item, currentSlug, depth = 0 }: { item: NavChild; currentSlug: string; depth?: number }) {
21
28
  const isActive = currentSlug === item.slug
29
+ const isNested = depth > 0
30
+ const wrapperIndent = isNested ? `${depth * 7}px` : undefined
31
+
22
32
  return (
23
- <li>
33
+ <div style={wrapperIndent ? { paddingLeft: wrapperIndent } : {}}>
24
34
  <Link
25
35
  href={item.slug}
26
36
  style={isActive ? { borderColor: "var(--cm-active-border)", color: "var(--cm-active)" } : {}}
27
- className={`block py-1.5 pl-4 pr-3 text-sm border-l-2 transition-colors ${
37
+ className={`block py-1.5 pr-3 text-sm transition-colors ${
38
+ isNested
39
+ ? "pl-4 border-l-2"
40
+ : "pl-2"
41
+ } ${
28
42
  isActive
29
43
  ? "font-medium bg-black/5 dark:bg-white/10"
30
- : "border-transparent text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 hover:border-gray-300 dark:hover:border-gray-600"
44
+ : isNested
45
+ ? "border-transparent text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 hover:border-gray-300 dark:hover:border-gray-600"
46
+ : "text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100"
31
47
  }`}
32
48
  >
33
49
  {item.label}
34
50
  </Link>
35
- </li>
51
+ </div>
36
52
  )
37
53
  }
38
54
 
39
- // Collapsible section row (e.g. "DoW Deployment") collapsed by default
55
+ // Collapsible section row renders children as DocLink or nested SectionRow
40
56
  function SectionRow({
41
57
  section,
42
58
  currentSlug,
43
59
  userRoles,
44
60
  authEnabled = false,
61
+ depth = 0,
45
62
  }: {
46
63
  section: NavChild
47
64
  currentSlug: string
48
65
  userRoles: string[]
49
66
  authEnabled?: boolean
67
+ depth?: number
50
68
  }) {
51
69
  const docs = (section.children ?? []).filter((c) => canSee(c.roles, userRoles, authEnabled))
52
70
  const hasChildren = docs.length > 0
53
71
 
54
- // Open only if the current page lives inside this section
72
+ // Open if the current page is anywhere in the subtree
55
73
  const containsCurrent =
56
- currentSlug === section.slug ||
57
- docs.some((d) => currentSlug === d.slug)
74
+ currentSlug === section.slug || subtreeContains(docs, currentSlug)
58
75
 
59
76
  const [open, setOpen] = useState(containsCurrent)
60
77
 
78
+ const isNested = depth > 0
79
+ const wrapperIndent = isNested ? `${depth * 7}px` : undefined
80
+
61
81
  // No children — render as a plain link, no arrow
62
82
  if (!hasChildren) {
63
83
  return (
64
- <div className="mb-0.5">
84
+ <div className="mb-0.5" style={wrapperIndent ? { paddingLeft: wrapperIndent } : {}}>
65
85
  <Link
66
86
  href={section.slug}
67
87
  style={currentSlug === section.slug ? { borderColor: "var(--cm-active-border)", color: "var(--cm-active)" } : {}}
68
- className={`block py-1.5 pl-4 pr-2 text-sm border-l-2 transition-colors ${
88
+ className={`block py-1.5 pr-2 text-sm transition-colors ${
89
+ isNested ? "pl-4 border-l-2" : "pl-2"
90
+ } ${
69
91
  currentSlug === section.slug
70
92
  ? "font-medium bg-black/5 dark:bg-white/10"
71
- : "border-transparent text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:border-gray-300 dark:hover:border-gray-600"
93
+ : isNested
94
+ ? "border-transparent text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 hover:border-gray-300 dark:hover:border-gray-600"
95
+ : "text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"
72
96
  }`}
73
97
  >
74
98
  {section.label}
@@ -78,30 +102,61 @@ function SectionRow({
78
102
  }
79
103
 
80
104
  return (
81
- <div className="mb-0.5">
82
- {/* Section header — full-width click area toggles collapse */}
83
- <button
84
- onClick={() => setOpen((o) => !o)}
85
- className="w-full flex items-center justify-between py-1.5 px-2 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 transition-colors rounded"
105
+ <div className="mb-0.5" style={wrapperIndent ? { paddingLeft: wrapperIndent } : {}}>
106
+ {/* Section header — link navigates, chevron toggles collapse */}
107
+ <div
108
+ style={isNested && currentSlug === section.slug ? { borderColor: "var(--cm-active-border)" } : {}}
109
+ className={`flex items-start rounded hover:bg-black/5 dark:hover:bg-white/5 transition-colors ${
110
+ isNested ? `border-l-2 ${currentSlug === section.slug ? "" : "border-transparent"}` : ""
111
+ }`}
86
112
  >
87
- <span>{section.label}</span>
88
- <svg
89
- className={`w-3.5 h-3.5 shrink-0 text-gray-400 transition-transform ${open ? "rotate-0" : "rotate-180"}`}
90
- fill="none"
91
- viewBox="0 0 24 24"
92
- stroke="currentColor"
93
- strokeWidth={2.5}
113
+ <Link
114
+ href={section.slug}
115
+ style={currentSlug === section.slug ? { color: "var(--cm-active)" } : {}}
116
+ className={`flex-1 min-w-0 py-1.5 text-sm leading-snug transition-colors ${
117
+ isNested ? "pl-4" : "pl-2"
118
+ } ${
119
+ currentSlug === section.slug
120
+ ? "font-medium"
121
+ : "text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"
122
+ }`}
94
123
  >
95
- <path strokeLinecap="round" strokeLinejoin="round" d="M5 15l7-7 7 7" />
96
- </svg>
97
- </button>
124
+ {section.label}
125
+ </Link>
126
+ <button
127
+ onClick={() => setOpen((o) => !o)}
128
+ className="shrink-0 p-1.5 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
129
+ aria-label={open ? "Collapse" : "Expand"}
130
+ >
131
+ <svg
132
+ className={`w-3.5 h-3.5 transition-transform ${open ? "rotate-0" : "rotate-180"}`}
133
+ fill="none"
134
+ viewBox="0 0 24 24"
135
+ stroke="currentColor"
136
+ strokeWidth={2.5}
137
+ >
138
+ <path strokeLinecap="round" strokeLinejoin="round" d="M5 15l7-7 7 7" />
139
+ </svg>
140
+ </button>
141
+ </div>
98
142
 
99
143
  {open && (
100
- <ul className="mt-0.5 mb-1">
101
- {docs.map((doc) => (
102
- <DocLink key={doc.slug} item={doc} currentSlug={currentSlug} />
103
- ))}
104
- </ul>
144
+ <div className="mt-0.5 mb-1">
145
+ {docs.map((doc) =>
146
+ (doc.children ?? []).filter((c) => canSee(c.roles, userRoles, authEnabled)).length > 0 ? (
147
+ <SectionRow
148
+ key={doc.slug}
149
+ section={doc}
150
+ currentSlug={currentSlug}
151
+ userRoles={userRoles}
152
+ authEnabled={authEnabled}
153
+ depth={depth + 1}
154
+ />
155
+ ) : (
156
+ <DocLink key={doc.slug} item={doc} currentSlug={currentSlug} depth={depth + 1} />
157
+ )
158
+ )}
159
+ </div>
105
160
  )}
106
161
  </div>
107
162
  )
@@ -1,6 +1,6 @@
1
1
  "use client"
2
2
 
3
- import { useState, Children, isValidElement } from "react"
3
+ import { useState, useEffect, useId, Children, isValidElement } from "react"
4
4
 
5
5
  type TabProps = {
6
6
  label: string
@@ -19,20 +19,43 @@ export function Tabs({ children }: { children: React.ReactNode }) {
19
19
  )
20
20
  ) as React.ReactElement<TabProps>[]
21
21
 
22
+ // Stable per-instance group id — SSR-safe, unique across multiple Tabs on the same page
23
+ const uid = useId().replace(/[^a-z0-9]/g, "")
24
+
25
+ const getIndexFromHash = () => {
26
+ if (typeof window === "undefined") return 0
27
+ const match = window.location.hash.match(new RegExp(`^#__tabbed_${uid}_(\\d+)$`))
28
+ if (!match) return 0
29
+ const idx = parseInt(match[1], 10) - 1 // hash is 1-based
30
+ return idx >= 0 && idx < tabs.length ? idx : 0
31
+ }
32
+
22
33
  const [active, setActive] = useState(0)
23
34
 
35
+ useEffect(() => {
36
+ setActive(getIndexFromHash())
37
+ const onHashChange = () => setActive(getIndexFromHash())
38
+ window.addEventListener("hashchange", onHashChange)
39
+ return () => window.removeEventListener("hashchange", onHashChange)
40
+ }, [])
41
+
42
+ const handleClick = (i: number) => {
43
+ setActive(i)
44
+ history.replaceState(null, "", `#__tabbed_${uid}_${i + 1}`)
45
+ }
46
+
24
47
  if (tabs.length === 0) return null
25
48
 
26
49
  return (
27
- <div className="my-4 not-prose">
50
+ <div className="my-4">
28
51
  {/* Screen: tabbed UI — hidden in PDF via data-print="hide" */}
29
52
  <div data-print="hide" className="rounded-lg border border-gray-200 overflow-hidden">
30
- {/* Tab bar */}
31
- <div className="flex border-b border-gray-200 bg-gray-50">
53
+ {/* Tab bar — not-prose scoped here so prose styles don't bleed into buttons */}
54
+ <div className="not-prose flex border-b border-gray-200 bg-gray-50">
32
55
  {tabs.map((tab, i) => (
33
56
  <button
34
57
  key={i}
35
- onClick={() => setActive(i)}
58
+ onClick={() => handleClick(i)}
36
59
  className={`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${
37
60
  i === active
38
61
  ? "border-gray-900 text-gray-900 bg-white"
@@ -11,6 +11,7 @@ export type NavEntry = {
11
11
  slug: string
12
12
  file: string
13
13
  roles: string[]
14
+ hidden_from_nav?: boolean // accessible by URL but excluded from dropdown and sidebar
14
15
  section?: NavChild[] // renders as ALL CAPS category block with children below
15
16
  children?: NavChild[] // renders as a plain collapsible row (no category label)
16
17
  }