@takazudo/zudo-doc 12.0.0 → 13.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ The format is based on Keep a Changelog, and release notes are generated from th
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [13.0.0] - 2026-11-16
10
+
11
+ ### Breaking Changes
12
+
13
+ - Require the ZFB 7.0.0 family (`^7.0.0`). ZFB 7 suspends the Linux arm64 npm CLI and CSS distribution, so a Linux arm64 npm install no longer receives `@takazudo/zfb-linux-arm64-gnu`. Linux x64, macOS and Windows npm installs are unchanged. Rust builds, GitHub Release archives and the standalone CLI still support Linux arm64. Removed bundler selectors must stay unset.
14
+ - A design-token panel needs `@takazudo/zdtp` 0.9.8 or newer. 0.9.7 and earlier do not accept the ZFB 7 peer.
15
+ - The `@takazudo/zudo-doc-history-server` peer floor moves from `^12.0.0` to `^13.0.0`. Projects that enable document history need history-server 13.x.
16
+
17
+ ### Features
18
+
19
+ - New `` component and repeatable `category-list` entry for `home.sections` list the first `limit` documents of one category, such as a blog, a numbered note tray or an ordinary category, as cards (up to three columns) or a two-column list, with an optional "See all" link to the full category. Items follow the category's own order and public navigation visibility; note trays keep their sidebar numbers and dates. Both layouts render on the server without client JavaScript. The `@takazudo/zudo-doc/category-list` subpath exports the resolver and view, and the agent export renders the component as a link list. (#4802)
20
+
21
+ ## [12.0.1] - 2026-11-14
22
+
23
+ - No package-specific changes.
24
+
9
25
  ## [12.0.0] - 2026-11-13
10
26
 
11
27
  ### Breaking Changes
@@ -0,0 +1,68 @@
1
+ /** @jsxRuntime automatic */
2
+ import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
3
+ import type { DateFormatSetting } from "../settings.js";
4
+ import { type CategoryListNode, type CategoryListOptions, type CategoryListResolution } from "./model.js";
5
+ import { type CategoryListLabels } from "./view.js";
6
+ export * from "./model.js";
7
+ export { CategoryListView, resolveCategoryListDisplay, type CategoryListDisplay, type CategoryListLabels, type CategoryListViewProps, } from "./view.js";
8
+ /** Minimal doc shape read for tags and category-index detection. */
9
+ export interface CategoryListSourceDoc {
10
+ slug: string;
11
+ data: {
12
+ slug?: string;
13
+ tags?: string[];
14
+ };
15
+ }
16
+ export interface CategoryListSource {
17
+ /** Every merged doc, including unlisted/standalone ones hidden from navigation. */
18
+ docs?: unknown[];
19
+ navDocs: unknown[];
20
+ categoryMeta: Map<string, unknown>;
21
+ }
22
+ /** Injected dependencies (all available on a `ChromeContext`). */
23
+ export interface CategoryListDeps {
24
+ defaultLocale: string;
25
+ /** `settings.docTags`: tags are only listed when the site uses tags. */
26
+ docTags?: boolean;
27
+ resolveNavSource: (lang: string, currentVersion: string | undefined, options?: {
28
+ applyDefaultLocaleOnlyFilter?: boolean;
29
+ keepUnlisted?: boolean;
30
+ }) => CategoryListSource;
31
+ buildNavTree: (docs: unknown[], locale: string, categoryMeta: Map<string, unknown>) => CategoryListNode[];
32
+ toRouteSlug: (entrySlug: string) => string;
33
+ resolveTag?: (raw: string) => string;
34
+ t: (key: string, locale: string) => string;
35
+ versionedDocsUrl?: (slug: string, versionSlug: string, lang: string) => string;
36
+ dateFormat?: DateFormatSetting;
37
+ }
38
+ /** Per-render context. */
39
+ export interface CategoryListRenderContext {
40
+ lang: string;
41
+ currentVersion?: string;
42
+ /** Where the options came from, for diagnostics (e.g. `home.sections[2]`). */
43
+ where: string;
44
+ }
45
+ export interface CategoryListRenderer {
46
+ /** Resolve without rendering (used to decide whether a home section renders at all). */
47
+ resolve(options: CategoryListOptions, context: CategoryListRenderContext): CategoryListResolution;
48
+ /** Resolve + render. `null` when the category is valid but has nothing to list. */
49
+ render(options: CategoryListOptions, context: CategoryListRenderContext, resolution?: CategoryListResolution, titleLevel?: 3 | 4): JSX.Element | null;
50
+ }
51
+ /** Localized labels; `archiveLabel` overrides the archive text when non-blank. */
52
+ export declare function resolveCategoryListLabels(t: (key: string, locale: string) => string, locale: string, archiveLabel?: string): CategoryListLabels;
53
+ export declare function createCategoryListRenderer(deps: CategoryListDeps): CategoryListRenderer;
54
+ /** `<CategoryList>` props: the shared options plus the per-page bindings the MDX map injects. */
55
+ export interface CategoryListProps extends CategoryListOptions {
56
+ /** Active locale. Injected per page by the MDX component map. */
57
+ lang?: string;
58
+ /** Active version slug. Injected per page by the MDX component map. */
59
+ currentVersion?: string;
60
+ /** Item heading level. Use 4 when the list sits under an H3. @default 3 */
61
+ titleLevel?: 3 | 4;
62
+ }
63
+ /**
64
+ * Create the `<CategoryList>` server component bound to a nav source. Place it
65
+ * under an authored `##` heading; it renders no heading of its own and
66
+ * nothing at all when the category has no visible documents.
67
+ */
68
+ export declare function createCategoryListWrapper(deps: CategoryListDeps): (props: CategoryListProps) => JSX.Element | null;
@@ -0,0 +1,130 @@
1
+ import { jsx } from "@takazudo/zfb/zudo-react/jsx-runtime";
2
+ import { remapVersionedHrefs } from "../nav-data-prep/index.js";
3
+ import { resolveDateFormats } from "../date-format-resolve/index.js";
4
+ import {
5
+ assertValidCategoryListOptions,
6
+ resolveCategoryList
7
+ } from "./model.js";
8
+ import {
9
+ CategoryListView,
10
+ resolveCategoryListDisplay
11
+ } from "./view.js";
12
+ export * from "./model.js";
13
+ import {
14
+ CategoryListView as CategoryListView2,
15
+ resolveCategoryListDisplay as resolveCategoryListDisplay2
16
+ } from "./view.js";
17
+ function resolveCategoryListLabels(t, locale, archiveLabel) {
18
+ return {
19
+ archive: archiveLabel?.trim() ? archiveLabel : t("categoryList.archive", locale),
20
+ count: t("categoryList.count", locale),
21
+ updated: t("doc.updated", locale),
22
+ tags: t("doc.tags", locale),
23
+ path: t("categoryList.path", locale)
24
+ };
25
+ }
26
+ const warned = /* @__PURE__ */ new Set();
27
+ function warnOnce(message) {
28
+ if (warned.has(message)) return;
29
+ warned.add(message);
30
+ console.warn(message);
31
+ }
32
+ function createCategoryListRenderer(deps) {
33
+ function resolve(options, { lang, currentVersion, where }) {
34
+ assertValidCategoryListOptions(options, where);
35
+ const source = deps.resolveNavSource(lang, currentVersion, {
36
+ applyDefaultLocaleOnlyFilter: true,
37
+ keepUnlisted: true
38
+ });
39
+ const navDocs = source.navDocs;
40
+ const rawTree = deps.buildNavTree(navDocs, lang, source.categoryMeta);
41
+ const tree = currentVersion && deps.versionedDocsUrl ? remapVersionedHrefs(rawTree, currentVersion, lang, deps.versionedDocsUrl) : rawTree;
42
+ const bySlug = /* @__PURE__ */ new Map();
43
+ for (const doc of navDocs) {
44
+ const routeSlug = doc.data.slug ?? deps.toRouteSlug(doc.slug);
45
+ if (!bySlug.has(routeSlug)) bySlug.set(routeSlug, doc);
46
+ }
47
+ const resolveTag = deps.resolveTag ?? ((raw) => raw);
48
+ const resolution = resolveCategoryList(tree, options.category, {
49
+ ...options.scope !== void 0 ? { scope: options.scope } : {},
50
+ limit: options.limit,
51
+ tagsFor: (slug) => deps.docTags === false ? [] : (bySlug.get(slug)?.data.tags ?? []).map(resolveTag),
52
+ isCategoryIndex: (slug) => {
53
+ const doc = bySlug.get(slug);
54
+ return doc === void 0 || doc.slug === "index" || doc.slug.endsWith("/index");
55
+ }
56
+ });
57
+ if (resolution.status === "not-category") {
58
+ throw new Error(
59
+ `[zudo-doc] ${where}: category ${JSON.stringify(options.category)} is a document, not a category. Point it at a category (a folder with an index page or _category_.json).`
60
+ );
61
+ }
62
+ const knownCategory = resolution.status === "not-found" && (source.categoryMeta.has(options.category) || (source.docs ?? []).some((doc) => {
63
+ const routeSlug = doc.data.slug ?? deps.toRouteSlug(doc.slug);
64
+ return routeSlug === options.category || routeSlug.startsWith(`${options.category}/`);
65
+ }));
66
+ if (knownCategory) {
67
+ return {
68
+ status: "ok",
69
+ category: { slug: options.category, label: options.category, kind: "tree", dated: false },
70
+ items: [],
71
+ total: 0
72
+ };
73
+ }
74
+ if (resolution.status === "not-found") {
75
+ if (lang === deps.defaultLocale && !currentVersion) {
76
+ throw new Error(
77
+ `[zudo-doc] ${where}: unknown category ${JSON.stringify(options.category)}. Use the category's canonical slug as it appears in the sidebar URL (e.g. "blog" or "guides/layout-demos").`
78
+ );
79
+ }
80
+ warnOnce(
81
+ `[zudo-doc] ${where}: category ${JSON.stringify(options.category)} is not available for locale "${lang}"${currentVersion ? ` / version "${currentVersion}"` : ""} \u2014 nothing rendered.`
82
+ );
83
+ return resolution;
84
+ }
85
+ if ((options.showArchive ?? true) && resolution.category.href === void 0) {
86
+ warnOnce(
87
+ `[zudo-doc] ${where}: category ${JSON.stringify(options.category)} has no archive page (category_no_page) \u2014 the "see all" link is omitted. Set showArchive: false to silence this.`
88
+ );
89
+ }
90
+ return resolution;
91
+ }
92
+ function render(options, context, resolution = resolve(options, context), titleLevel = 3) {
93
+ if (resolution.status !== "ok" || resolution.items.length === 0) return null;
94
+ return /* @__PURE__ */ jsx(
95
+ CategoryListView,
96
+ {
97
+ resolved: resolution,
98
+ display: resolveCategoryListDisplay(options),
99
+ labels: resolveCategoryListLabels(deps.t, context.lang, options.archiveLabel),
100
+ locale: context.lang,
101
+ dateFormats: resolveDateFormats(deps.dateFormat, context.lang),
102
+ titleLevel
103
+ }
104
+ );
105
+ }
106
+ return { resolve, render };
107
+ }
108
+ function createCategoryListWrapper(deps) {
109
+ const renderer = createCategoryListRenderer(deps);
110
+ return function CategoryList(props) {
111
+ const { lang = deps.defaultLocale, currentVersion, titleLevel = 3, ...options } = props;
112
+ if (titleLevel !== 3 && titleLevel !== 4) {
113
+ throw new TypeError(`Invalid <CategoryList> titleLevel ${JSON.stringify(titleLevel)}: must be 3 or 4.`);
114
+ }
115
+ const { children: _children, key: _key, ...rest } = options;
116
+ const context = {
117
+ lang,
118
+ ...currentVersion !== void 0 ? { currentVersion } : {},
119
+ where: "<CategoryList>"
120
+ };
121
+ return renderer.render(rest, context, void 0, titleLevel);
122
+ };
123
+ }
124
+ export {
125
+ CategoryListView2 as CategoryListView,
126
+ createCategoryListRenderer,
127
+ createCategoryListWrapper,
128
+ resolveCategoryListDisplay2 as resolveCategoryListDisplay,
129
+ resolveCategoryListLabels
130
+ };
@@ -0,0 +1,142 @@
1
+ export type CategoryListLayout = "cards" | "list";
2
+ export type CategoryListScope = "descendants" | "direct";
3
+ /** What sits in the leading slot before the title. */
4
+ export type CategoryListLead = "auto" | "none" | "rank" | "date";
5
+ export declare const CATEGORY_LIST_LAYOUTS: readonly CategoryListLayout[];
6
+ export declare const CATEGORY_LIST_SCOPES: readonly CategoryListScope[];
7
+ export declare const CATEGORY_LIST_LEADS: readonly CategoryListLead[];
8
+ /**
9
+ * Author options shared by the `category-list` home section and the
10
+ * `<CategoryList>` component. Only `category` and `limit` are required.
11
+ */
12
+ export interface CategoryListOptions {
13
+ /** Canonical category slug as it appears in the nav tree, e.g. `"blog"` or `"guides/layout-demos"`. */
14
+ category: string;
15
+ /** Presentation. Switching it never changes the items. @default "cards" */
16
+ layout?: CategoryListLayout;
17
+ /** Maximum number of items shown (positive integer). Required. */
18
+ limit: number;
19
+ /**
20
+ * Ordinary categories: every document page below the category
21
+ * (`"descendants"`) or only its direct children (`"direct"`). Note trays
22
+ * always use their own flat membership and ignore this. @default "descendants"
23
+ */
24
+ scope?: CategoryListScope;
25
+ /**
26
+ * Leading detail. `"auto"` = publication date for a dated note tray, the
27
+ * category rank for an undated tray, nothing for an ordinary category.
28
+ * `"rank"` on an ordinary category shows nothing (ranks are never invented).
29
+ * @default "auto"
30
+ */
31
+ lead?: CategoryListLead;
32
+ /** Show the frontmatter description. @default true */
33
+ showDescription?: boolean;
34
+ /** Show the publication date in the metadata row (skipped when it is already the lead). @default false */
35
+ showDate?: boolean;
36
+ /** Show the updated date with a label (skipped when equal to the publication date). @default false */
37
+ showUpdated?: boolean;
38
+ /** Show the document's tags as plain text. @default false */
39
+ showTags?: boolean;
40
+ /** Show the subcategory path between the listed category and the item. @default false */
41
+ showPath?: boolean;
42
+ /** Show "N of total" in the footer. @default false */
43
+ showCount?: boolean;
44
+ /** Show the footer link to the full category. @default true */
45
+ showArchive?: boolean;
46
+ /** Archive link text. Blank uses the translated default ("See all"). */
47
+ archiveLabel?: string;
48
+ }
49
+ /** Keys accepted by {@link assertValidCategoryListOptions}. */
50
+ export declare const CATEGORY_LIST_OPTION_KEYS: readonly (keyof CategoryListOptions)[];
51
+ /** A canonical category slug: non-empty segments, no leading/trailing slash, no URL or whitespace. */
52
+ export declare function isCanonicalCategorySlug(value: unknown): value is string;
53
+ /**
54
+ * Validate the option fields of one listing. `at` names the entry in error
55
+ * messages (e.g. `home.sections[2]` or `<CategoryList>`). `extraKeys` lists
56
+ * additional keys the caller owns (a home section's `type`/`heading`/…).
57
+ * Throws a `TypeError` describing the first problem.
58
+ */
59
+ export declare function assertValidCategoryListOptions(value: Record<string, unknown>, at: string, extraKeys?: readonly string[]): void;
60
+ /** Structural nav-tree node the resolver reads (a `DocNavNode` satisfies it). */
61
+ export interface CategoryListNode {
62
+ slug: string;
63
+ label: string;
64
+ description?: string;
65
+ href?: string;
66
+ hasPage: boolean;
67
+ children: CategoryListNode[];
68
+ shape?: "note-tray";
69
+ noteTrayDated?: boolean;
70
+ date?: string;
71
+ updated?: string;
72
+ rank?: number;
73
+ }
74
+ /** One listed document. */
75
+ export interface CategoryListItem {
76
+ slug: string;
77
+ title: string;
78
+ href: string;
79
+ description?: string;
80
+ /** Category position from the shared note-tray model; trays only. */
81
+ rank?: number;
82
+ date?: string;
83
+ updated?: string;
84
+ /** Labels of the subcategories between the listed category and the item. */
85
+ path: string[];
86
+ /** Canonical tags (already resolved and deduplicated). */
87
+ tags: string[];
88
+ }
89
+ export type CategoryListKind = "note-tray" | "tree";
90
+ export interface CategoryListResolved {
91
+ status: "ok";
92
+ category: {
93
+ slug: string;
94
+ label: string;
95
+ /** Canonical archive URL, absent when the category has no addressable page. */
96
+ href?: string;
97
+ kind: CategoryListKind;
98
+ dated: boolean;
99
+ };
100
+ /** Items after visibility filtering and the limit, in canonical order. */
101
+ items: CategoryListItem[];
102
+ /** Eligible item count before the limit. */
103
+ total: number;
104
+ /** Rank label width for the whole tray (`rankWidth`), trays only. */
105
+ rankWidth?: number;
106
+ }
107
+ export type CategoryListResolution = CategoryListResolved | {
108
+ status: "not-found";
109
+ category: string;
110
+ } | {
111
+ status: "not-category";
112
+ category: string;
113
+ };
114
+ export interface ResolveCategoryListOptions {
115
+ scope?: CategoryListScope;
116
+ limit: number;
117
+ /** Canonical tags for a route slug. Omitted → no tags. */
118
+ tagsFor?: (slug: string) => readonly string[];
119
+ /**
120
+ * True when the route slug is a category landing page (an `index` file).
121
+ * Distinguishes a category whose documents are all hidden (valid, empty)
122
+ * from a plain document targeted by mistake (an authoring error).
123
+ */
124
+ isCategoryIndex?: (slug: string) => boolean;
125
+ }
126
+ /**
127
+ * Resolve one category against a visibility-filtered nav tree for the render
128
+ * locale/version (drafts, unlisted and standalone already removed, translation
129
+ * fallbacks already deduplicated, hrefs already locale/base/version aware).
130
+ *
131
+ * - The category is found by its exact nav-tree slug, never a prefix match.
132
+ * - A note tray lists its shared flat membership (`getNoteTrayItems`) with
133
+ * ranks and rank width taken from the whole tray; `scope` is ignored.
134
+ * - An ordinary category lists real document pages (`hasPage` + `href`) in
135
+ * tree order, either direct children or all descendants. Grouping-only and
136
+ * auto-index nodes are traversed but never listed; the category's own
137
+ * landing page is never listed.
138
+ * - `total` is counted after filtering and before `limit`.
139
+ */
140
+ export declare function resolveCategoryList(tree: readonly CategoryListNode[], category: string, options: ResolveCategoryListOptions): CategoryListResolution;
141
+ /** The concrete leading detail for a resolved category. */
142
+ export declare function resolveCategoryListLead(lead: CategoryListLead | undefined, category: CategoryListResolved["category"]): "none" | "rank" | "date";
@@ -0,0 +1,174 @@
1
+ import { getNoteTrayItems, rankWidth } from "../note-tray-model/index.js";
2
+ const CATEGORY_LIST_LAYOUTS = ["cards", "list"];
3
+ const CATEGORY_LIST_SCOPES = ["descendants", "direct"];
4
+ const CATEGORY_LIST_LEADS = ["auto", "none", "rank", "date"];
5
+ const CATEGORY_LIST_OPTION_KEYS = [
6
+ "category",
7
+ "layout",
8
+ "limit",
9
+ "scope",
10
+ "lead",
11
+ "showDescription",
12
+ "showDate",
13
+ "showUpdated",
14
+ "showTags",
15
+ "showPath",
16
+ "showCount",
17
+ "showArchive",
18
+ "archiveLabel"
19
+ ];
20
+ const BOOLEAN_KEYS = [
21
+ "showDescription",
22
+ "showDate",
23
+ "showUpdated",
24
+ "showTags",
25
+ "showPath",
26
+ "showCount",
27
+ "showArchive"
28
+ ];
29
+ function describe(value) {
30
+ if (value === void 0) return "undefined";
31
+ if (Array.isArray(value)) return "(array)";
32
+ try {
33
+ return JSON.stringify(value) ?? String(value);
34
+ } catch {
35
+ return String(value);
36
+ }
37
+ }
38
+ function isCanonicalCategorySlug(value) {
39
+ return typeof value === "string" && value.length > 0 && !/\s/.test(value) && !value.includes("://") && !value.startsWith("/") && !value.endsWith("/") && !value.split("/").some((part) => part === "" || part === "." || part === "..");
40
+ }
41
+ function assertValidCategoryListOptions(value, at, extraKeys = []) {
42
+ const allowed = /* @__PURE__ */ new Set([...CATEGORY_LIST_OPTION_KEYS, ...extraKeys]);
43
+ for (const key of Object.keys(value)) {
44
+ if (!allowed.has(key)) {
45
+ throw new TypeError(
46
+ `Invalid ${at}: unknown key "${key}" for a category list. Allowed keys: ${[...allowed].join(", ")}.`
47
+ );
48
+ }
49
+ }
50
+ if (!isCanonicalCategorySlug(value.category)) {
51
+ throw new TypeError(
52
+ `Invalid ${at}.category ${describe(value.category)}: must be a canonical category slug such as "blog" or "guides/layout-demos" (no leading or trailing "/", no URL).`
53
+ );
54
+ }
55
+ const limit = value.limit;
56
+ if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1) {
57
+ throw new TypeError(
58
+ `Invalid ${at}.limit ${describe(limit)}: a positive integer is required (the number of items to show, e.g. 6).`
59
+ );
60
+ }
61
+ const enumChecks = [
62
+ ["layout", CATEGORY_LIST_LAYOUTS],
63
+ ["scope", CATEGORY_LIST_SCOPES],
64
+ ["lead", CATEGORY_LIST_LEADS]
65
+ ];
66
+ for (const [key, allowedValues] of enumChecks) {
67
+ const v = value[key];
68
+ if (v !== void 0 && !allowedValues.includes(v)) {
69
+ throw new TypeError(
70
+ `Invalid ${at}.${key} ${describe(v)}: must be ${allowedValues.map((a) => `"${a}"`).join(" or ")}.`
71
+ );
72
+ }
73
+ }
74
+ for (const key of BOOLEAN_KEYS) {
75
+ const v = value[key];
76
+ if (v !== void 0 && typeof v !== "boolean") {
77
+ throw new TypeError(`Invalid ${at}.${key} ${describe(v)}: must be true or false.`);
78
+ }
79
+ }
80
+ if (value.archiveLabel !== void 0 && typeof value.archiveLabel !== "string") {
81
+ throw new TypeError(`Invalid ${at}.archiveLabel ${describe(value.archiveLabel)}: must be a string.`);
82
+ }
83
+ }
84
+ function findBySlug(nodes, slug) {
85
+ for (const node of nodes) {
86
+ if (node.slug === slug) return node;
87
+ const found = findBySlug(node.children, slug);
88
+ if (found) return found;
89
+ }
90
+ return void 0;
91
+ }
92
+ function isDocumentPage(node) {
93
+ return node.hasPage === true && typeof node.href === "string" && node.href.length > 0;
94
+ }
95
+ function toItem(node, path, tagsFor, withRank) {
96
+ const description = node.description?.trim();
97
+ const tags = tagsFor ? [...new Set(tagsFor(node.slug))] : [];
98
+ return {
99
+ slug: node.slug,
100
+ title: node.label,
101
+ href: node.href,
102
+ ...description ? { description } : {},
103
+ ...withRank && node.rank !== void 0 ? { rank: node.rank } : {},
104
+ ...node.date ? { date: node.date } : {},
105
+ ...node.updated ? { updated: node.updated } : {},
106
+ path,
107
+ tags
108
+ };
109
+ }
110
+ function resolveCategoryList(tree, category, options) {
111
+ const node = findBySlug(tree, category);
112
+ if (!node) return { status: "not-found", category };
113
+ const isTray = node.shape === "note-tray";
114
+ if (!isTray && node.children.length === 0) {
115
+ const isIndex = options.isCategoryIndex?.(node.slug) ?? node.hasPage !== true;
116
+ if (!isIndex) return { status: "not-category", category };
117
+ }
118
+ const seen = /* @__PURE__ */ new Set();
119
+ const eligible = [];
120
+ const push = (child, path, withRank) => {
121
+ if (!isDocumentPage(child) || seen.has(child.slug)) return;
122
+ seen.add(child.slug);
123
+ eligible.push(toItem(child, path, options.tagsFor, withRank));
124
+ };
125
+ if (isTray) {
126
+ for (const item of getNoteTrayItems(node)) push(item, [], true);
127
+ } else if ((options.scope ?? "descendants") === "direct") {
128
+ for (const child of node.children) push(child, [], false);
129
+ } else {
130
+ const walk = (nodes, path) => {
131
+ for (const child of nodes) {
132
+ push(child, path, false);
133
+ if (child.children.length > 0) walk(child.children, [...path, child.label]);
134
+ }
135
+ };
136
+ walk(node.children, []);
137
+ }
138
+ return {
139
+ status: "ok",
140
+ category: {
141
+ slug: node.slug,
142
+ label: node.label,
143
+ ...node.href ? { href: node.href } : {},
144
+ kind: isTray ? "note-tray" : "tree",
145
+ dated: isTray && node.noteTrayDated === true
146
+ },
147
+ items: eligible.slice(0, options.limit),
148
+ total: eligible.length,
149
+ ...isTray ? { rankWidth: rankWidth(getNoteTrayItems(node)) } : {}
150
+ };
151
+ }
152
+ function resolveCategoryListLead(lead, category) {
153
+ switch (lead ?? "auto") {
154
+ case "none":
155
+ return "none";
156
+ case "date":
157
+ return "date";
158
+ case "rank":
159
+ return category.kind === "note-tray" ? "rank" : "none";
160
+ default:
161
+ if (category.kind !== "note-tray") return "none";
162
+ return category.dated ? "date" : "rank";
163
+ }
164
+ }
165
+ export {
166
+ CATEGORY_LIST_LAYOUTS,
167
+ CATEGORY_LIST_LEADS,
168
+ CATEGORY_LIST_OPTION_KEYS,
169
+ CATEGORY_LIST_SCOPES,
170
+ assertValidCategoryListOptions,
171
+ isCanonicalCategorySlug,
172
+ resolveCategoryList,
173
+ resolveCategoryListLead
174
+ };
@@ -0,0 +1,56 @@
1
+ /** @jsxRuntime automatic */
2
+ import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
3
+ import type { ResolvedDateFormats } from "../settings.js";
4
+ import { type CategoryListLayout, type CategoryListLead, type CategoryListResolved } from "./model.js";
5
+ /** Localized strings the view needs. */
6
+ export interface CategoryListLabels {
7
+ /** Archive link text, e.g. "See all". */
8
+ archive: string;
9
+ /** Footer count template with `{shown}` and `{total}`, e.g. "Showing {shown} of {total}". */
10
+ count: string;
11
+ /** Prefix for the updated date, e.g. "Updated". */
12
+ updated: string;
13
+ /** Screen-reader label for the tag list, e.g. "Tags". */
14
+ tags: string;
15
+ /** Screen-reader label for the subcategory path, e.g. "In". */
16
+ path: string;
17
+ }
18
+ /** Metadata toggles after defaults are applied. */
19
+ export interface CategoryListDisplay {
20
+ layout: CategoryListLayout;
21
+ lead: CategoryListLead;
22
+ showDescription: boolean;
23
+ showDate: boolean;
24
+ showUpdated: boolean;
25
+ showTags: boolean;
26
+ showPath: boolean;
27
+ showCount: boolean;
28
+ showArchive: boolean;
29
+ }
30
+ export interface CategoryListViewProps {
31
+ resolved: CategoryListResolved;
32
+ display: CategoryListDisplay;
33
+ labels: CategoryListLabels;
34
+ locale: string;
35
+ dateFormats?: ResolvedDateFormats;
36
+ /** Heading level of item titles. @default 3 (beneath a section H2) */
37
+ titleLevel?: 3 | 4;
38
+ }
39
+ /** Defaults for omitted toggles — kept in one place for the docs and tests. */
40
+ export declare function resolveCategoryListDisplay(options: {
41
+ layout?: CategoryListLayout;
42
+ lead?: CategoryListLead;
43
+ showDescription?: boolean;
44
+ showDate?: boolean;
45
+ showUpdated?: boolean;
46
+ showTags?: boolean;
47
+ showPath?: boolean;
48
+ showCount?: boolean;
49
+ showArchive?: boolean;
50
+ }): CategoryListDisplay;
51
+ /**
52
+ * Render a resolved category listing as `cards` (B) or `list` (C) with an
53
+ * optional footer (count + archive link). Renders nothing for an empty list —
54
+ * the caller owns any surrounding heading and must suppress it as well.
55
+ */
56
+ export declare function CategoryListView({ resolved, display, labels, locale, dateFormats, titleLevel, }: CategoryListViewProps): JSX.Element | null;