@takazudo/zudo-doc 10.0.3 → 12.0.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.
Files changed (129) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/agent-docs/search.js +6 -3
  3. package/dist/asset-index-page/index.js +1 -1
  4. package/dist/asset-page/index.js +1 -1
  5. package/dist/asset-path/index.d.ts +2 -0
  6. package/dist/asset-path/index.js +1 -0
  7. package/dist/catalog.js +1 -1
  8. package/dist/chrome/derive.js +14 -2
  9. package/dist/compiled.css +178 -30
  10. package/dist/config-assertions/index.d.ts +54 -0
  11. package/dist/config-assertions/index.js +205 -0
  12. package/dist/config.d.ts +12 -9
  13. package/dist/config.js +13 -0
  14. package/dist/content/index.d.ts +1 -0
  15. package/dist/content/index.js +2 -0
  16. package/dist/content/wide-section-heading.d.ts +12 -0
  17. package/dist/content/wide-section-heading.js +8 -0
  18. package/dist/content-admonition/index.d.ts +2 -1
  19. package/dist/content-admonition/index.js +2 -1
  20. package/dist/doc-body-end-islands/index.d.ts +0 -7
  21. package/dist/doc-body-end-islands/index.js +0 -6
  22. package/dist/doc-card-nav/index.d.ts +78 -0
  23. package/dist/doc-card-nav/index.js +82 -0
  24. package/dist/doc-card-nav/slug.d.ts +6 -0
  25. package/dist/doc-card-nav/slug.js +6 -0
  26. package/dist/doc-page-renderer/index.d.ts +5 -0
  27. package/dist/doc-page-renderer/index.js +7 -0
  28. package/dist/doc-page-shell/index.d.ts +12 -0
  29. package/dist/doc-page-shell/index.js +6 -1
  30. package/dist/docs-schema/index.d.ts +2 -0
  31. package/dist/docs-schema/index.js +9 -0
  32. package/dist/features.css +201 -0
  33. package/dist/frontmatter-preview-defaults/index.js +3 -1
  34. package/dist/head-with-defaults/index.d.ts +20 -0
  35. package/dist/head-with-defaults/index.js +25 -3
  36. package/dist/home-hero/index.d.ts +36 -0
  37. package/dist/home-hero/index.js +128 -0
  38. package/dist/home-page/index.js +157 -58
  39. package/dist/i18n-defaults/index.js +8 -0
  40. package/dist/mcp/constants.d.ts +11 -0
  41. package/dist/mcp/constants.js +20 -0
  42. package/dist/mcp/discovery.d.ts +45 -0
  43. package/dist/mcp/discovery.js +138 -0
  44. package/dist/mcp/handler.js +5 -9
  45. package/dist/mcp/index.d.ts +3 -0
  46. package/dist/mcp/index.js +37 -1
  47. package/dist/md-utils/index.d.ts +6 -1
  48. package/dist/md-utils/index.js +3 -2
  49. package/dist/mdx-components/index.js +4 -7
  50. package/dist/mdx-components/vocabulary.d.ts +19 -0
  51. package/dist/mdx-components/vocabulary.js +32 -0
  52. package/dist/nav-indexing/doc-card-grid.d.ts +6 -0
  53. package/dist/nav-indexing/doc-card-grid.js +26 -16
  54. package/dist/plugins/internal/agent-export/components.d.ts +27 -0
  55. package/dist/plugins/internal/agent-export/components.js +125 -0
  56. package/dist/plugins/internal/agent-export/index.d.ts +4 -0
  57. package/dist/plugins/internal/agent-export/index.js +29 -8
  58. package/dist/plugins/internal/agent-export/normalize.d.ts +18 -1
  59. package/dist/plugins/internal/agent-export/normalize.js +91 -5
  60. package/dist/plugins/internal/llms-txt/dev-middleware.d.ts +2 -0
  61. package/dist/plugins/internal/llms-txt/dev-middleware.js +6 -1
  62. package/dist/plugins/internal/llms-txt/emit.js +8 -1
  63. package/dist/plugins/internal/llms-txt/generate.d.ts +2 -0
  64. package/dist/plugins/internal/llms-txt/generate.js +3 -0
  65. package/dist/plugins/internal/llms-txt/load.js +2 -2
  66. package/dist/plugins/internal/llms-txt/types.d.ts +4 -0
  67. package/dist/plugins/internal/search-index/collect.js +5 -4
  68. package/dist/plugins/internal/search-index/types.d.ts +2 -0
  69. package/dist/plugins/routes.js +6 -1
  70. package/dist/preset.d.ts +6 -1
  71. package/dist/preset.js +13 -1
  72. package/dist/robots.d.ts +14 -0
  73. package/dist/robots.js +22 -4
  74. package/dist/route-enumerators/index.d.ts +63 -2
  75. package/dist/route-enumerators/index.js +124 -21
  76. package/dist/routes/404.js +1 -1
  77. package/dist/routes/_context.d.ts +1 -1
  78. package/dist/routes/_context.js +6 -0
  79. package/dist/routes/ai-catalog.d.ts +5 -0
  80. package/dist/routes/ai-catalog.js +28 -0
  81. package/dist/routes/mcp-server-card.d.ts +5 -0
  82. package/dist/routes/mcp-server-card.js +24 -0
  83. package/dist/routes/sitemap.xml.js +19 -9
  84. package/dist/settings-defaults.js +1 -1
  85. package/dist/settings.d.ts +102 -6
  86. package/dist/sidebar/client-data.d.ts +1 -1
  87. package/dist/sidebar/client-data.js +2 -0
  88. package/dist/sidebar/types.d.ts +4 -0
  89. package/dist/sidebar-tree/build-tree.js +1 -0
  90. package/dist/sidebar-tree/types.d.ts +4 -0
  91. package/dist/site-schema/nav-tree.js +2 -0
  92. package/dist/site-schema/types.d.ts +3 -0
  93. package/dist/site-tree-nav/index.d.ts +18 -0
  94. package/dist/site-tree-nav/index.js +18 -3
  95. package/dist/site-tree-nav/normalize-island-props.d.ts +6 -0
  96. package/dist/site-tree-nav/normalize-island-props.js +15 -0
  97. package/dist/site-tree-nav-island/count.d.ts +3 -0
  98. package/dist/site-tree-nav-island/count.js +11 -0
  99. package/dist/site-tree-nav-island/index.d.ts +22 -2
  100. package/dist/site-tree-nav-island/index.js +272 -221
  101. package/dist/tag-pages/index.d.ts +1 -0
  102. package/dist/tag-pages/index.js +2 -2
  103. package/dist/theme-packs/bauhaus/meta.json +1 -1
  104. package/dist/theme-packs/bauhaus/pack.css +2 -2
  105. package/dist/theme-packs/beacon/meta.json +1 -1
  106. package/dist/theme-packs/beacon/pack.css +0 -15
  107. package/dist/theme-packs/eink/meta.json +1 -1
  108. package/dist/theme-packs/eink/pack.css +1 -14
  109. package/dist/theme.css +0 -16
  110. package/dist/versions-page/index.d.ts +1 -0
  111. package/dist/versions-page/index.js +1 -1
  112. package/dist/wind.json +4 -6
  113. package/eject/content-admonition/index.tsx +4 -9
  114. package/eject/sidebar/client-data.ts +3 -1
  115. package/eject/sidebar/types.ts +4 -0
  116. package/eject/site-tree-nav-island/count.ts +11 -0
  117. package/eject/site-tree-nav-island/index.tsx +359 -256
  118. package/package.json +19 -7
  119. package/routes-src/404.tsx +1 -1
  120. package/routes-src/_context.ts +3 -0
  121. package/routes-src/ai-catalog.tsx +26 -0
  122. package/routes-src/mcp-server-card.tsx +21 -0
  123. package/routes-src/sitemap.xml.tsx +36 -12
  124. package/dist/find-in-page/find-bar.d.ts +0 -11
  125. package/dist/find-in-page/find-bar.js +0 -103
  126. package/dist/find-in-page/find-in-page.d.ts +0 -17
  127. package/dist/find-in-page/find-in-page.js +0 -131
  128. package/dist/find-in-page/index.d.ts +0 -5
  129. package/dist/find-in-page/index.js +0 -52
@@ -9,13 +9,7 @@ import {
9
9
  } from "@takazudo/zfb/zudo-react";
10
10
  import type { SidebarNavNode } from "../sidebar/types.js";
11
11
  import type { ResolvedDateFormats } from "../settings.js";
12
- import {
13
- INDENT,
14
- connectorLeft,
15
- connectorLabelStart,
16
- ConnectorLines,
17
- CategoryLinkIcon,
18
- } from "../tree-nav-shared/index.js";
12
+ import { CategoryLinkIcon } from "../tree-nav-shared/index.js";
19
13
  import { ChevronRight } from "../icons/index.js";
20
14
  import {
21
15
  formatDate,
@@ -27,21 +21,31 @@ import {
27
21
  } from "../note-tray-model/index.js";
28
22
  import { formatMonthDay } from "../format-date/index.js";
29
23
  import { initialCategoryOpenState, toggleCategoryOpenState } from "./state.js";
24
+ import { countCategoryDocuments } from "./count.js";
30
25
 
31
- // site-tree-nav uses wider padding than the narrow sidebar
32
- const SITE_BASE_PAD = "clamp(0.5rem, 0.8vw, 1rem)";
26
+ // Tree geometry (slot, rail axis, indent, first-line midpoint, lead-in/crop
27
+ // switch) is authored once as `.zd-site-tree*` rules in `features.css`; this
28
+ // file only emits the hook classes and data attributes those rules read.
33
29
 
34
- // The homepage draws its connectors at twice the sidebar width, so on wide
35
- // viewports the branch endpoint passes the fixed label indent. The label starts
36
- // at whichever is further right: that indent, or the endpoint plus a gap.
37
- const CONNECTOR_WIDTH_SCALE = 2;
38
- const CONNECTOR_LABEL_GAP = "var(--spacing-hsp-xs)";
30
+ /** Standard keeps the established 18rem grid; described cards need ~22rem. */
31
+ const GRID_COLUMNS = {
32
+ default: "repeat(auto-fill, minmax(min(18rem, 100%), 1fr))",
33
+ described: "repeat(auto-fit, minmax(min(22rem, 100%), 1fr))",
34
+ } as const;
39
35
 
40
- function padLeft(depth: number): string {
41
- if (depth === 0) return SITE_BASE_PAD;
42
- return `max(calc(${depth} * ${INDENT} + 1.25rem + 5px), ${connectorLabelStart(depth, CONNECTOR_WIDTH_SCALE, CONNECTOR_LABEL_GAP)})`;
36
+ /** Pluralized "N documents" templates for the described variant; `{count}` is replaced. */
37
+ export interface SiteTreeNavCountLabels {
38
+ one: string;
39
+ other: string;
43
40
  }
44
41
 
42
+ const DEFAULT_COUNT_LABELS: SiteTreeNavCountLabels = {
43
+ one: "{count} document",
44
+ other: "{count} documents",
45
+ };
46
+
47
+ export type SiteTreeNavVariant = "default" | "described";
48
+
45
49
  function reorderTree(tree: SidebarNavNode[], order: string[]): SidebarNavNode[] {
46
50
  const map = new Map(tree.map((node) => [node.slug, node]));
47
51
  const ordered: SidebarNavNode[] = [];
@@ -59,6 +63,23 @@ function reorderTree(tree: SidebarNavNode[], order: string[]): SidebarNavNode[]
59
63
  return ordered;
60
64
  }
61
65
 
66
+ /** DOM-id-safe, deterministic encoding of a nav slug. */
67
+ function slugToId(slug: string): string {
68
+ if (slug === "") return "root";
69
+ return slug.replace(/[^A-Za-z0-9_-]/g, (c) => `_${c.codePointAt(0)!.toString(16)}`);
70
+ }
71
+
72
+ function formatCount(count: number, locale: string, labels: SiteTreeNavCountLabels): string {
73
+ let category = "other";
74
+ try {
75
+ category = new Intl.PluralRules(locale).select(count);
76
+ } catch {
77
+ category = count === 1 ? "one" : "other";
78
+ }
79
+ const template = category === "one" ? labels.one : labels.other;
80
+ return template.replaceAll("{count}", String(count));
81
+ }
82
+
62
83
  export interface SiteTreeNavProps {
63
84
  tree: SidebarNavNode[];
64
85
  ariaLabel?: string;
@@ -66,7 +87,7 @@ export interface SiteTreeNavProps {
66
87
  categoryIgnore?: string[];
67
88
  /** Exact full category slugs at any depth that should start collapsed. */
68
89
  initiallyCollapsedCategorySlugs?: string[];
69
- /** Locale used by dated note-tray rows. */
90
+ /** Locale used by dated note-tray rows and the described document count. */
70
91
  locale?: string;
71
92
  /**
72
93
  * Per-role date patterns already resolved for the page's locale, serialized
@@ -77,6 +98,29 @@ export interface SiteTreeNavProps {
77
98
  dateFormats?: ResolvedDateFormats;
78
99
  /** @deprecated — no longer rendered (created date only). */
79
100
  updatedLabel?: string;
101
+ /**
102
+ * `"described"` shows available category/document descriptions and each
103
+ * category's document count in a ~22rem-column grid; a lone category splits
104
+ * into summary + tree columns when its own box is wide enough. Omitted (or
105
+ * `"default"`) keeps the standard compact grid.
106
+ */
107
+ variant?: SiteTreeNavVariant;
108
+ /** Described-variant count templates (`{count}` placeholder). English when omitted. */
109
+ countLabels?: SiteTreeNavCountLabels;
110
+ /**
111
+ * Prefix for the disclosure-target ids. Give distinct values when several
112
+ * site trees share one page. @default "zd-site-tree"
113
+ */
114
+ idPrefix?: string;
115
+ }
116
+
117
+ interface TreeContext {
118
+ initiallyCollapsed: ReadonlySet<string>;
119
+ idPrefix: string;
120
+ described: boolean;
121
+ locale: string;
122
+ dateFormats?: ResolvedDateFormats;
123
+ updatedLabel: string;
80
124
  }
81
125
 
82
126
  export function SiteTreeNav({
@@ -88,6 +132,9 @@ export function SiteTreeNav({
88
132
  locale = "en",
89
133
  dateFormats,
90
134
  updatedLabel = "Updated",
135
+ variant = "default",
136
+ countLabels = DEFAULT_COUNT_LABELS,
137
+ idPrefix = "zd-site-tree",
91
138
  }: SiteTreeNavProps) {
92
139
  let processedTree = tree;
93
140
  if (categoryIgnore) {
@@ -98,227 +145,349 @@ export function SiteTreeNav({
98
145
  processedTree = reorderTree(processedTree, categoryOrder);
99
146
  }
100
147
 
148
+ const described = variant === "described";
101
149
  // Every value used to seed the tree is part of the JSON-serializable island
102
150
  // props. There is no browser storage or location read during setup.
103
151
  const roots = signal(processedTree);
104
- const initiallyCollapsed = new Set(initiallyCollapsedCategorySlugs);
152
+ const visibleRootCount = processedTree.filter(
153
+ (node) => node.shape !== "note-tray" || getNoteTrayItems(node).length > 0,
154
+ ).length;
155
+ const context: TreeContext = {
156
+ initiallyCollapsed: new Set(initiallyCollapsedCategorySlugs),
157
+ idPrefix,
158
+ described,
159
+ locale,
160
+ dateFormats,
161
+ updatedLabel,
162
+ };
105
163
 
106
164
  return (
107
165
  <nav
108
166
  aria-label={ariaLabel}
109
167
  data-site-nav
110
- class="grid gap-vsp-md"
111
- style={{
112
- "grid-template-columns": "repeat(auto-fill, minmax(min(18rem, 100%), 1fr))",
113
- }}
168
+ data-variant={described ? "described" : "default"}
169
+ class="zd-site-tree grid gap-vsp-md"
170
+ style={{ "grid-template-columns": GRID_COLUMNS[described ? "described" : "default"] }}
114
171
  >
115
172
  <For each={roots} by={(node) => node.slug}>
116
- {(node, index) => {
117
- const isLast = computed(() => index.value === roots.value.length - 1);
118
- return (
173
+ {(node) => (
174
+ <Show
175
+ when={computed(
176
+ () =>
177
+ node.value.shape !== "note-tray" ||
178
+ getNoteTrayItems(node.value).length > 0,
179
+ )}
180
+ >
181
+ {() => (
182
+ <RootCard
183
+ node={node}
184
+ context={context}
185
+ single={visibleRootCount === 1}
186
+ countLabels={countLabels}
187
+ />
188
+ )}
189
+ </Show>
190
+ )}
191
+ </For>
192
+ </nav>
193
+ );
194
+ }
195
+ SiteTreeNav.displayName = "SiteTreeNav";
196
+
197
+ function DisclosureButton({
198
+ open,
199
+ label,
200
+ controls,
201
+ onToggle,
202
+ }: {
203
+ open: ReadonlySignal<boolean>;
204
+ label: ReadonlySignal<string>;
205
+ controls: string;
206
+ onToggle: () => void;
207
+ }) {
208
+ return (
209
+ <button
210
+ type="button"
211
+ on:click={onToggle}
212
+ class="zd-site-tree-toggle flex shrink-0 items-center justify-center border border-muted text-muted hover:text-accent hover:underline focus:underline focus-visible:text-accent"
213
+ aria-expanded={computed(() => (open.value ? "true" : "false"))}
214
+ aria-label={computed(() => `${open.value ? "Collapse" : "Expand"} ${label.value}`)}
215
+ aria-controls={controls}
216
+ >
217
+ <span
218
+ class="inline-flex transition-transform duration-150"
219
+ aria-hidden="true"
220
+ style={computed(() => `transform:rotate(${open.value ? "90deg" : "0deg"})`)}
221
+ >
222
+ <ChevronRight class="h-icon-xs w-icon-xs" />
223
+ </span>
224
+ </button>
225
+ );
226
+ }
227
+
228
+ function RootCard({
229
+ node,
230
+ context,
231
+ single,
232
+ countLabels,
233
+ }: {
234
+ node: ReadonlySignal<SidebarNavNode>;
235
+ context: TreeContext;
236
+ single: boolean;
237
+ countLabels: SiteTreeNavCountLabels;
238
+ }) {
239
+ const { described } = context;
240
+ const hasChildren = node.value.children.length > 0;
241
+ const open = signal(
242
+ initialCategoryOpenState(context.initiallyCollapsed.has(node.value.slug)),
243
+ );
244
+ const toggle = () => {
245
+ open.value = toggleCategoryOpenState(open.value);
246
+ };
247
+ const label = computed(() => node.value.label);
248
+ const href = computed(() => node.value.href);
249
+ const description = computed(() => node.value.description ?? "");
250
+ const controls = `${context.idPrefix}-${slugToId(node.value.slug)}`;
251
+ const isNoteTray = node.value.shape === "note-tray";
252
+ const splitCandidate = described && single && hasChildren;
253
+ const labelClass =
254
+ "zd-site-tree-label flex min-w-0 flex-1 items-start text-left font-semibold text-fg break-words hover:text-accent hover:underline focus:underline focus-visible:text-accent";
255
+ const labelContent = (
256
+ <>
257
+ <span class="zd-site-tree-marker flex shrink-0 items-center justify-center" aria-hidden="true">
258
+ <CategoryLinkIcon class="w-[18px]" />
259
+ </span>
260
+ <span class="min-w-0">{label}</span>
261
+ </>
262
+ );
263
+
264
+ return (
265
+ <div
266
+ class="zd-site-tree-card min-w-0 border border-muted bg-bg"
267
+ data-site-tree-root={node.value.slug}
268
+ {...(described ? { "data-described": "" } : {})}
269
+ >
270
+ {node.value.coverHref ? (
271
+ <img
272
+ src={node.value.coverHref}
273
+ alt=""
274
+ width="1200"
275
+ height="630"
276
+ loading="lazy"
277
+ decoding="async"
278
+ class="zd-site-nav-cover"
279
+ />
280
+ ) : null}
281
+ <div
282
+ class="zd-site-tree-body"
283
+ {...(splitCandidate
284
+ ? { "data-split": computed(() => (open.value ? "true" : "false")) }
285
+ : {})}
286
+ >
287
+ <div class="min-w-0">
288
+ <div class="zd-site-tree-head flex items-start justify-between gap-hsp-xs text-small">
119
289
  <Show
120
- when={computed(
121
- () =>
122
- node.value.shape !== "note-tray" ||
123
- getNoteTrayItems(node.value).length > 0,
124
- )}
290
+ when={computed(() => Boolean(href.value))}
291
+ fallback={() =>
292
+ hasChildren ? (
293
+ <button
294
+ type="button"
295
+ on:click={toggle}
296
+ class={labelClass}
297
+ aria-expanded={computed(() => (open.value ? "true" : "false"))}
298
+ aria-controls={controls}
299
+ >
300
+ {labelContent}
301
+ </button>
302
+ ) : (
303
+ <span class={labelClass}>{labelContent}</span>
304
+ )
305
+ }
125
306
  >
126
307
  {() => (
127
- <div class="min-w-0 border border-muted pl-hsp-sm py-vsp-2xs">
128
- <Show
129
- when={computed(() => node.value.children.length > 0)}
130
- fallback={() => (
131
- <LeafNode node={node} depth={0} isLast={isLast} />
132
- )}
133
- >
134
- {() => (
135
- <CategoryNode
136
- node={node}
137
- depth={0}
138
- isLast={isLast}
139
- initiallyCollapsedCategorySlugs={initiallyCollapsed}
140
- locale={locale}
141
- dateFormats={dateFormats}
142
- updatedLabel={updatedLabel}
143
- />
144
- )}
145
- </Show>
146
- </div>
308
+ <a href={computed(() => href.value ?? "")} class={labelClass}>
309
+ {labelContent}
310
+ </a>
147
311
  )}
148
312
  </Show>
149
- );
150
- }}
151
- </For>
152
- </nav>
313
+ {hasChildren && (
314
+ <DisclosureButton open={open} label={label} controls={controls} onToggle={toggle} />
315
+ )}
316
+ </div>
317
+ {described && (
318
+ <>
319
+ <Show when={computed(() => description.value.length > 0)}>
320
+ {() => (
321
+ <p class="mt-vsp-xs text-small text-muted break-words" data-site-tree-description>
322
+ {description}
323
+ </p>
324
+ )}
325
+ </Show>
326
+ <p class="mt-vsp-2xs text-caption text-muted" data-site-tree-count>
327
+ {computed(() =>
328
+ formatCount(countCategoryDocuments(node.value), context.locale, countLabels),
329
+ )}
330
+ </p>
331
+ </>
332
+ )}
333
+ </div>
334
+ {hasChildren && (
335
+ <div
336
+ id={controls}
337
+ class="min-w-0"
338
+ hidden={computed(() => !open.value)}
339
+ >
340
+ <Show when={open}>
341
+ {() =>
342
+ isNoteTray ? (
343
+ <NoteTrayNodeList
344
+ node={node}
345
+ locale={context.locale}
346
+ dateFormats={context.dateFormats}
347
+ updatedLabel={context.updatedLabel}
348
+ />
349
+ ) : (
350
+ <NodeList
351
+ nodes={computed(() => node.value.children)}
352
+ context={context}
353
+ root={true}
354
+ />
355
+ )
356
+ }
357
+ </Show>
358
+ </div>
359
+ )}
360
+ </div>
361
+ </div>
153
362
  );
154
363
  }
155
- SiteTreeNav.displayName = "SiteTreeNav";
156
364
 
157
365
  function NodeList({
158
366
  nodes,
159
- depth,
160
- initiallyCollapsedCategorySlugs,
367
+ context,
368
+ root,
161
369
  }: {
162
370
  nodes: ReadonlySignal<readonly SidebarNavNode[]>;
163
- depth: number;
164
- initiallyCollapsedCategorySlugs: ReadonlySet<string>;
371
+ context: TreeContext;
372
+ root: boolean;
165
373
  }) {
374
+ // Rows without a link or children render nothing, so first/last (which crop
375
+ // the rails) are taken from the rows that are actually drawn.
376
+ const visible = computed(() =>
377
+ nodes.value.filter((node) => node.children.length > 0 || Boolean(node.href)),
378
+ );
166
379
  return (
167
- <For each={nodes} by={(node) => node.slug}>
168
- {(node, index) => {
169
- const isLast = computed(() => index.value === nodes.value.length - 1);
170
- return (
171
- <Show
172
- when={computed(() => node.value.children.length > 0)}
173
- fallback={() => (
174
- <LeafNode node={node} depth={depth} isLast={isLast} />
175
- )}
176
- >
177
- {() => (
178
- <CategoryNode node={node} depth={depth} isLast={isLast} initiallyCollapsedCategorySlugs={initiallyCollapsedCategorySlugs} />
179
- )}
180
- </Show>
181
- );
182
- }}
183
- </For>
380
+ <ul class="zd-site-tree-list" role="list">
381
+ <For each={visible} by={(node) => node.slug}>
382
+ {(node, index) => {
383
+ const isLast = computed(() => index.value === visible.value.length - 1);
384
+ const isFirst = computed(() => index.value === 0);
385
+ return <TreeRow node={node} isFirst={isFirst} isLast={isLast} root={root} context={context} />;
386
+ }}
387
+ </For>
388
+ </ul>
184
389
  );
185
390
  }
186
391
 
187
- function CategoryNode({
392
+ function TreeRow({
188
393
  node,
189
- depth,
394
+ isFirst,
190
395
  isLast,
191
- initiallyCollapsedCategorySlugs,
192
- locale = "en",
193
- dateFormats,
194
- updatedLabel = "Updated",
396
+ root,
397
+ context,
195
398
  }: {
196
399
  node: ReadonlySignal<SidebarNavNode>;
197
- depth: number;
400
+ isFirst: ReadonlySignal<boolean>;
198
401
  isLast: ReadonlySignal<boolean>;
199
- initiallyCollapsedCategorySlugs: ReadonlySet<string>;
200
- locale?: string;
201
- dateFormats?: ResolvedDateFormats;
202
- updatedLabel?: string;
402
+ root: boolean;
403
+ context: TreeContext;
203
404
  }) {
204
- const open = signal(initialCategoryOpenState(initiallyCollapsedCategorySlugs.has(node.value.slug)));
405
+ const group = node.value.children.length > 0;
406
+ const open = signal(
407
+ initialCategoryOpenState(context.initiallyCollapsed.has(node.value.slug)),
408
+ );
205
409
  const toggle = () => {
206
410
  open.value = toggleCategoryOpenState(open.value);
207
411
  };
208
412
  const label = computed(() => node.value.label);
209
413
  const href = computed(() => node.value.href);
210
- const children = computed(() => node.value.children);
211
- const paddingLeft = padLeft(depth);
212
-
213
- return (
214
- <div class={computed(() => (depth >= 1 && !isLast.value ? "relative" : ""))}>
215
- <Show when={computed(() => depth >= 1 && !isLast.value && open.value)}>
414
+ const description = computed(() =>
415
+ context.described ? (node.value.description ?? "") : "",
416
+ );
417
+ const controls = `${context.idPrefix}-${slugToId(node.value.slug)}`;
418
+ const labelClass = `zd-site-tree-label block min-w-0 flex-1 text-left text-fg break-words hover:text-accent hover:underline focus:underline focus-visible:text-accent${group ? " font-semibold" : ""}`;
419
+ const labelContent = (
420
+ <>
421
+ <span class="block">{label}</span>
422
+ <Show when={computed(() => description.value.length > 0)}>
216
423
  {() => (
217
- <div
218
- class="absolute border-l border-dashed border-muted z-local-1"
219
- style={{
220
- left: connectorLeft(depth),
221
- top: "0px",
222
- bottom: "0px",
223
- }}
224
- />
424
+ <span class="mt-vsp-3xs block text-caption text-muted" data-site-tree-description>
425
+ {description}
426
+ </span>
225
427
  )}
226
428
  </Show>
227
- <div class="relative">
228
- <Show when={isLast}>
229
- {() => (
230
- <ConnectorLines
231
- depth={depth}
232
- isLast={true}
233
- widthScale={CONNECTOR_WIDTH_SCALE}
234
- topPad="calc(0.15rem + var(--spacing-vsp-xs))"
235
- />
429
+ </>
430
+ );
431
+
432
+ return (
433
+ <li
434
+ class="zd-site-tree-row"
435
+ data-node={node.value.slug}
436
+ {...(group ? { "data-group": "" } : {})}
437
+ >
438
+ <span
439
+ aria-hidden="true"
440
+ class="zd-site-tree-rail"
441
+ data-tree-rail
442
+ {...(root ? { "data-root": "" } : {})}
443
+ data-first={computed(() => (isFirst.value ? "true" : "false"))}
444
+ data-last={computed(() => (isLast.value ? "true" : "false"))}
445
+ />
446
+ <span aria-hidden="true" class="zd-site-tree-branch" data-tree-branch />
447
+ <div class="zd-site-tree-line relative flex min-w-0 items-start gap-hsp-xs">
448
+ {group && (
449
+ <DisclosureButton open={open} label={label} controls={controls} onToggle={toggle} />
450
+ )}
451
+ <Show
452
+ when={computed(() => Boolean(href.value))}
453
+ fallback={() => (
454
+ <button
455
+ type="button"
456
+ on:click={toggle}
457
+ class={labelClass}
458
+ aria-expanded={computed(() => (open.value ? "true" : "false"))}
459
+ aria-controls={controls}
460
+ >
461
+ {labelContent}
462
+ </button>
236
463
  )}
237
- </Show>
238
- <Show when={computed(() => !isLast.value)}>
464
+ >
239
465
  {() => (
240
- <ConnectorLines
241
- depth={depth}
242
- isLast={false}
243
- widthScale={CONNECTOR_WIDTH_SCALE}
244
- topPad="calc(0.15rem + var(--spacing-vsp-xs))"
245
- />
466
+ <a href={computed(() => href.value ?? "")} class={labelClass}>
467
+ {labelContent}
468
+ </a>
246
469
  )}
247
470
  </Show>
248
- <div
249
- class="flex w-full items-center justify-between text-small font-semibold pt-[0.15rem] text-fg"
250
- style={{ "padding-left": paddingLeft }}
251
- >
252
- <Show
253
- when={computed(() => Boolean(href.value))}
254
- fallback={() => (
255
- <button
256
- type="button"
257
- on:click={toggle}
258
- class="flex-1 min-w-0 break-words py-vsp-xs text-left hover:text-accent hover:underline focus:underline"
259
- >
260
- {label}
261
- </button>
262
- )}
263
- >
471
+ {group && (
472
+ <Show when={open}>
473
+ {() => <span aria-hidden="true" class="zd-site-tree-stem" data-tree-stem />}
474
+ </Show>
475
+ )}
476
+ </div>
477
+ {group && (
478
+ <div id={controls} hidden={computed(() => !open.value)}>
479
+ <Show when={open}>
264
480
  {() => (
265
- <a
266
- href={computed(() => href.value ?? "")}
267
- class="flex-1 flex items-start gap-hsp-xs py-vsp-xs text-fg hover:text-accent hover:underline focus:underline focus-visible:text-accent"
268
- >
269
- {depth === 0 && (
270
- <span class="flex h-[1lh] items-center">
271
- <CategoryLinkIcon class="w-[18px]" />
272
- </span>
273
- )}
274
- {label}
275
- </a>
481
+ <NodeList
482
+ nodes={computed(() => node.value.children)}
483
+ context={context}
484
+ root={false}
485
+ />
276
486
  )}
277
487
  </Show>
278
- <button
279
- type="button"
280
- on:click={toggle}
281
- class="aspect-square flex items-center justify-center w-[1.75rem] border-y border-l border-muted hover:underline focus:underline"
282
- aria-expanded={computed(() => (open.value ? "true" : "false"))}
283
- aria-label={computed(
284
- () => `${open.value ? "Collapse" : "Expand"} ${label.value}`,
285
- )}
286
- >
287
- <span
288
- class="inline-flex transition-transform duration-150"
289
- style={computed(
290
- () => `transform:rotate(${open.value ? "90deg" : "0deg"})`,
291
- )}
292
- >
293
- <ChevronRight class="h-icon-xs w-icon-xs text-muted" />
294
- </span>
295
- </button>
296
488
  </div>
297
- </div>
298
- <Show when={open}>
299
- {() => (
300
- <div>
301
- <Show
302
- when={computed(
303
- () => node.value.shape === "note-tray" && depth === 0,
304
- )}
305
- fallback={() => (
306
- <NodeList nodes={children} depth={depth + 1} initiallyCollapsedCategorySlugs={initiallyCollapsedCategorySlugs} />
307
- )}
308
- >
309
- {() => (
310
- <NoteTrayNodeList
311
- node={node}
312
- locale={locale}
313
- dateFormats={dateFormats}
314
- updatedLabel={updatedLabel}
315
- />
316
- )}
317
- </Show>
318
- </div>
319
- )}
320
- </Show>
321
- </div>
489
+ )}
490
+ </li>
322
491
  );
323
492
  }
324
493
 
@@ -473,69 +642,3 @@ function NoteTrayRow({
473
642
  </Show>
474
643
  );
475
644
  }
476
-
477
- function LeafNode({
478
- node,
479
- depth,
480
- isLast,
481
- }: {
482
- node: ReadonlySignal<SidebarNavNode>;
483
- depth: number;
484
- isLast: ReadonlySignal<boolean>;
485
- }) {
486
- const href = computed(() => node.value.href);
487
- const label = computed(() => node.value.label);
488
- const isRoot = depth === 0;
489
- const paddingLeft = padLeft(depth);
490
-
491
- const topPad = isRoot
492
- ? "calc(var(--spacing-vsp-xs) + 0.15rem)"
493
- : "var(--spacing-vsp-2xs)";
494
-
495
- return (
496
- <Show when={computed(() => Boolean(href.value))}>
497
- {() => (
498
- <div>
499
- <div class="relative">
500
- <Show when={isLast}>
501
- {() => (
502
- <ConnectorLines
503
- depth={depth}
504
- isLast={true}
505
- widthScale={CONNECTOR_WIDTH_SCALE}
506
- topPad={topPad}
507
- />
508
- )}
509
- </Show>
510
- <Show when={computed(() => !isLast.value)}>
511
- {() => (
512
- <ConnectorLines
513
- depth={depth}
514
- isLast={false}
515
- widthScale={CONNECTOR_WIDTH_SCALE}
516
- topPad={topPad}
517
- />
518
- )}
519
- </Show>
520
- <a
521
- href={computed(() => href.value ?? "")}
522
- class={computed(() =>
523
- isRoot
524
- ? "flex items-start gap-hsp-xs py-[calc(var(--spacing-vsp-xs)_+_0.15rem)] pr-hsp-sm text-small font-semibold text-fg break-words hover:text-accent hover:underline focus:underline focus-visible:text-accent"
525
- : `block py-vsp-2xs pr-hsp-sm ${isLast.value ? "pb-vsp-xs" : ""} text-small text-fg break-words hover:text-accent hover:underline focus:underline focus-visible:text-accent`,
526
- )}
527
- style={{ "padding-left": paddingLeft }}
528
- >
529
- {isRoot && (
530
- <span class="flex h-[1lh] items-center">
531
- <CategoryLinkIcon class="w-[18px]" />
532
- </span>
533
- )}
534
- {isRoot ? <span class="min-w-0">{label}</span> : label}
535
- </a>
536
- </div>
537
- </div>
538
- )}
539
- </Show>
540
- );
541
- }