shelving 1.202.0 → 1.203.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 (55) hide show
  1. package/extract/DirectoryExtractor.d.ts +29 -0
  2. package/extract/DirectoryExtractor.js +48 -0
  3. package/extract/Extractor.d.ts +11 -0
  4. package/extract/Extractor.js +6 -0
  5. package/extract/FileExtractor.d.ts +17 -0
  6. package/extract/FileExtractor.js +25 -0
  7. package/extract/MarkdownExtractor.d.ts +13 -0
  8. package/extract/MarkdownExtractor.js +32 -0
  9. package/extract/TypescriptExtractor.d.ts +11 -0
  10. package/extract/TypescriptExtractor.js +244 -0
  11. package/extract/index.d.ts +5 -0
  12. package/extract/index.js +5 -0
  13. package/package.json +6 -6
  14. package/ui/form/ButtonInput.d.ts +1 -1
  15. package/ui/form/CheckboxInput.d.ts +1 -1
  16. package/ui/form/DateInput.d.ts +1 -1
  17. package/ui/form/FileInput.d.ts +1 -1
  18. package/ui/form/Input.d.ts +1 -1
  19. package/ui/form/NumberInput.d.ts +1 -1
  20. package/ui/form/Popover.d.ts +1 -1
  21. package/ui/form/RadioInput.d.ts +1 -1
  22. package/ui/form/TextInput.d.ts +1 -1
  23. package/ui/index.d.ts +1 -0
  24. package/ui/index.js +1 -0
  25. package/ui/index.ts +1 -0
  26. package/ui/misc/Mapper.d.ts +32 -0
  27. package/ui/misc/Mapper.js +46 -0
  28. package/ui/misc/Mapper.tsx +71 -0
  29. package/ui/misc/index.d.ts +1 -0
  30. package/ui/misc/index.js +1 -0
  31. package/ui/misc/index.tsx +1 -0
  32. package/ui/tree/TreeApp.d.ts +24 -0
  33. package/ui/tree/TreeApp.js +22 -0
  34. package/ui/tree/TreeApp.tsx +64 -0
  35. package/ui/tree/TreeCards.d.ts +9 -0
  36. package/ui/tree/TreeCards.js +8 -0
  37. package/ui/tree/TreeCards.module.css +31 -0
  38. package/ui/tree/TreeCards.tsx +20 -0
  39. package/ui/tree/TreeMenu.d.ts +9 -0
  40. package/ui/tree/TreeMenu.js +8 -0
  41. package/ui/tree/TreeMenu.module.css +29 -0
  42. package/ui/tree/TreeMenu.tsx +22 -0
  43. package/ui/tree/TreePage.d.ts +15 -0
  44. package/ui/tree/TreePage.js +17 -0
  45. package/ui/tree/TreePage.tsx +24 -0
  46. package/ui/tree/index.d.ts +4 -0
  47. package/ui/tree/index.js +4 -0
  48. package/ui/tree/index.ts +4 -0
  49. package/util/data.d.ts +11 -1
  50. package/util/data.js +9 -2
  51. package/util/element.d.ts +190 -4
  52. package/util/element.js +107 -12
  53. package/util/file.d.ts +10 -0
  54. package/util/file.js +15 -0
  55. package/util/iterate.d.ts +1 -1
@@ -0,0 +1,29 @@
1
+ import type { Element } from "../util/element.js";
2
+ import { Extractor } from "./Extractor.js";
3
+ import type { FileExtractor } from "./FileExtractor.js";
4
+ /** Options for a directory extractor. */
5
+ export interface DirectoryExtractorOptions {
6
+ /** Filenames to treat as the directory's index file (e.g. `["README.md", "INDEX.md"]`). */
7
+ readonly index: readonly string[];
8
+ /** Extractor to use for child files. */
9
+ readonly extractor: FileExtractor;
10
+ }
11
+ /**
12
+ * Extractor that processes a directory's files into a directory element.
13
+ * - Finds an index file and absorbs its content as the directory's own content.
14
+ * - Delegates remaining files to the child file extractor.
15
+ * - Errors if two child elements resolve to the same slug.
16
+ * - Preserves file system ordering.
17
+ */
18
+ export declare class DirectoryExtractor extends Extractor<{
19
+ name: string;
20
+ files: File[];
21
+ }> {
22
+ private readonly _index;
23
+ private readonly _extractor;
24
+ constructor({ index, extractor }: DirectoryExtractorOptions);
25
+ extract({ name, files }: {
26
+ name: string;
27
+ files: File[];
28
+ }): Promise<Element>;
29
+ }
@@ -0,0 +1,48 @@
1
+ import { requireSlug } from "../util/string.js";
2
+ import { Extractor } from "./Extractor.js";
3
+ /**
4
+ * Extractor that processes a directory's files into a directory element.
5
+ * - Finds an index file and absorbs its content as the directory's own content.
6
+ * - Delegates remaining files to the child file extractor.
7
+ * - Errors if two child elements resolve to the same slug.
8
+ * - Preserves file system ordering.
9
+ */
10
+ export class DirectoryExtractor extends Extractor {
11
+ _index;
12
+ _extractor;
13
+ constructor({ index, extractor }) {
14
+ super();
15
+ this._index = index;
16
+ this._extractor = extractor;
17
+ }
18
+ async extract({ name, files }) {
19
+ let indexElement;
20
+ const children = [];
21
+ const keys = new Set();
22
+ for (const file of files) {
23
+ if (!indexElement && this._index.includes(file.name)) {
24
+ indexElement = await this._extractor.extract(file);
25
+ }
26
+ else {
27
+ const element = await this._extractor.extract(file);
28
+ const { key } = element;
29
+ if (key) {
30
+ if (keys.has(key))
31
+ throw new Error(`Duplicate key "${key}" in directory "${name}"`);
32
+ keys.add(key);
33
+ }
34
+ children.push(element);
35
+ }
36
+ }
37
+ return {
38
+ type: "tree-directory",
39
+ key: requireSlug(name),
40
+ props: {
41
+ title: indexElement?.props.title ?? name,
42
+ description: indexElement?.props.description,
43
+ content: indexElement?.props.content,
44
+ children,
45
+ },
46
+ };
47
+ }
48
+ }
@@ -0,0 +1,11 @@
1
+ import type { Element } from "../util/element.js";
2
+ /**
3
+ * Base class for an extractor that converts input into an element.
4
+ * - Extractors are composable: outer extractors delegate to inner extractors.
5
+ */
6
+ export declare abstract class Extractor<I> {
7
+ /** Extract an element from the given input. */
8
+ abstract extract(input: I): Element | Promise<Element>;
9
+ }
10
+ /** Extractor that converts string content into an element. */
11
+ export type ContentExtractor = Extractor<string>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Base class for an extractor that converts input into an element.
3
+ * - Extractors are composable: outer extractors delegate to inner extractors.
4
+ */
5
+ export class Extractor {
6
+ }
@@ -0,0 +1,17 @@
1
+ import type { Element } from "../util/element.js";
2
+ import { type ContentExtractor, Extractor } from "./Extractor.js";
3
+ /** Options for a file extractor. */
4
+ export interface FileExtractorOptions {
5
+ /** Map of file extension (e.g. `".md"`, `".ts"`) to content extractor. */
6
+ readonly extractors: Readonly<Record<string, ContentExtractor>>;
7
+ }
8
+ /**
9
+ * Extractor that dispatches to a content extractor based on file extension.
10
+ * - Reads the file content and passes it to the matched extractor.
11
+ * - Sets the element `key` to the slugified filename (without extension).
12
+ */
13
+ export declare class FileExtractor extends Extractor<File> {
14
+ private readonly _extractors;
15
+ constructor({ extractors }: FileExtractorOptions);
16
+ extract(file: File): Promise<Element>;
17
+ }
@@ -0,0 +1,25 @@
1
+ import { splitFileExtension } from "../util/file.js";
2
+ import { requireSlug } from "../util/string.js";
3
+ import { Extractor } from "./Extractor.js";
4
+ /**
5
+ * Extractor that dispatches to a content extractor based on file extension.
6
+ * - Reads the file content and passes it to the matched extractor.
7
+ * - Sets the element `key` to the slugified filename (without extension).
8
+ */
9
+ export class FileExtractor extends Extractor {
10
+ _extractors;
11
+ constructor({ extractors }) {
12
+ super();
13
+ this._extractors = extractors;
14
+ }
15
+ async extract(file) {
16
+ const [base, ext] = splitFileExtension(file.name);
17
+ const key = requireSlug(base ?? file.name);
18
+ const extractor = ext ? this._extractors[ext] : undefined;
19
+ if (!extractor)
20
+ return { type: "tree-file", key, props: {} };
21
+ const content = await file.text();
22
+ const element = await extractor.extract(content);
23
+ return { ...element, key };
24
+ }
25
+ }
@@ -0,0 +1,13 @@
1
+ import type { MarkupOptions } from "../markup/util/options.js";
2
+ import type { Element } from "../util/element.js";
3
+ import { type ContentExtractor, Extractor } from "./Extractor.js";
4
+ /**
5
+ * Extractor that converts a Markdown string into a file element.
6
+ * - Parses the markdown using the markup module.
7
+ * - Extracts the first `<h1>` heading as the element title.
8
+ */
9
+ export declare class MarkdownExtractor extends Extractor<string> implements ContentExtractor {
10
+ private readonly _options;
11
+ constructor(options?: MarkupOptions);
12
+ extract(content: string): Element;
13
+ }
@@ -0,0 +1,32 @@
1
+ import { renderMarkup } from "../markup/render.js";
2
+ import { MARKUP_RULES } from "../markup/rule/index.js";
3
+ import { getElements, getElementText } from "../util/element.js";
4
+ import { Extractor } from "./Extractor.js";
5
+ /**
6
+ * Extractor that converts a Markdown string into a file element.
7
+ * - Parses the markdown using the markup module.
8
+ * - Extracts the first `<h1>` heading as the element title.
9
+ */
10
+ export class MarkdownExtractor extends Extractor {
11
+ _options;
12
+ constructor(options = { rules: MARKUP_RULES }) {
13
+ super();
14
+ this._options = options;
15
+ }
16
+ extract(content) {
17
+ const elements = renderMarkup(content, this._options);
18
+ const title = _getFirstHeadingText(elements);
19
+ return {
20
+ type: "tree-file",
21
+ key: null,
22
+ props: { title, content: elements },
23
+ };
24
+ }
25
+ }
26
+ /** Find the first `h1` element and extract its text content. */
27
+ function _getFirstHeadingText(elements) {
28
+ for (const el of getElements(elements)) {
29
+ if (el.type === "h1")
30
+ return getElementText(el.props.children) || undefined;
31
+ }
32
+ }
@@ -0,0 +1,11 @@
1
+ import type { Element } from "../util/element.js";
2
+ import { type ContentExtractor, Extractor } from "./Extractor.js";
3
+ /**
4
+ * Extractor that converts a TypeScript source string into a file element.
5
+ * - Uses the TypeScript compiler API to parse the AST.
6
+ * - Extracts exported, public, non-`_`-prefixed declarations with their JSDoc and type signatures.
7
+ * - Top-of-file JSDoc comment becomes the file's description.
8
+ */
9
+ export declare class TypescriptExtractor extends Extractor<string> implements ContentExtractor {
10
+ extract(content: string): Element;
11
+ }
@@ -0,0 +1,244 @@
1
+ import ts from "typescript";
2
+ import { Extractor } from "./Extractor.js";
3
+ /**
4
+ * Extractor that converts a TypeScript source string into a file element.
5
+ * - Uses the TypeScript compiler API to parse the AST.
6
+ * - Extracts exported, public, non-`_`-prefixed declarations with their JSDoc and type signatures.
7
+ * - Top-of-file JSDoc comment becomes the file's description.
8
+ */
9
+ export class TypescriptExtractor extends Extractor {
10
+ extract(content) {
11
+ const source = ts.createSourceFile("source.ts", content, ts.ScriptTarget.Latest, true);
12
+ const children = [];
13
+ const description = _getFileDocComment(source);
14
+ for (const statement of source.statements) {
15
+ const element = _extractStatement(statement, source);
16
+ if (element)
17
+ children.push(element);
18
+ }
19
+ return {
20
+ type: "tree-file",
21
+ key: null,
22
+ props: { description, children },
23
+ };
24
+ }
25
+ }
26
+ /** Get the leading JSDoc comment of the file (before the first statement). */
27
+ function _getFileDocComment(source) {
28
+ const { statements } = source;
29
+ if (!statements.length)
30
+ return;
31
+ const first = statements[0];
32
+ if (!first)
33
+ return;
34
+ const ranges = ts.getLeadingCommentRanges(source.text, first.pos);
35
+ if (!ranges?.length)
36
+ return;
37
+ const range = ranges[0];
38
+ if (!range || range.kind !== ts.SyntaxKind.MultiLineCommentTrivia)
39
+ return;
40
+ const text = source.text.slice(range.pos, range.end);
41
+ return _parseJSDocComment(text);
42
+ }
43
+ /** Extract an element from a top-level statement, or return undefined if it should be skipped. */
44
+ function _extractStatement(statement, source) {
45
+ // Skip non-exported statements.
46
+ if (!_isExported(statement))
47
+ return;
48
+ // Skip statements without a name.
49
+ const name = _getStatementName(statement);
50
+ if (!name)
51
+ return;
52
+ // Skip private/internal names.
53
+ if (name.startsWith("_"))
54
+ return;
55
+ const jsDoc = _getJSDoc(statement, source);
56
+ const kind = _getElementType(statement);
57
+ if (!kind)
58
+ return;
59
+ const signature = _getSignature(statement, source);
60
+ const params = _getParams(statement, source);
61
+ const returns = _getReturnType(statement, source);
62
+ const examples = jsDoc?.examples;
63
+ const children = _getClassMembers(statement, source);
64
+ const props = {
65
+ title: name,
66
+ description: jsDoc?.description,
67
+ signature,
68
+ };
69
+ if (params?.length)
70
+ props.params = params;
71
+ if (returns)
72
+ props.returns = returns;
73
+ if (examples?.length)
74
+ props.examples = examples;
75
+ if (children?.length)
76
+ props.children = children;
77
+ return { type: kind, key: null, props };
78
+ }
79
+ /** Check if a statement has an `export` modifier. */
80
+ function _isExported(statement) {
81
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
82
+ return !!modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword);
83
+ }
84
+ /** Get the declared name of a statement. */
85
+ function _getStatementName(statement) {
86
+ if (ts.isFunctionDeclaration(statement) ||
87
+ ts.isClassDeclaration(statement) ||
88
+ ts.isInterfaceDeclaration(statement) ||
89
+ ts.isTypeAliasDeclaration(statement) ||
90
+ ts.isEnumDeclaration(statement)) {
91
+ return statement.name?.text;
92
+ }
93
+ if (ts.isVariableStatement(statement)) {
94
+ const declaration = statement.declarationList.declarations[0];
95
+ if (declaration && ts.isIdentifier(declaration.name))
96
+ return declaration.name.text;
97
+ }
98
+ }
99
+ /** Map a statement to its tree element type. */
100
+ function _getElementType(statement) {
101
+ if (ts.isFunctionDeclaration(statement))
102
+ return "tree-function";
103
+ if (ts.isClassDeclaration(statement))
104
+ return "tree-class";
105
+ if (ts.isInterfaceDeclaration(statement))
106
+ return "tree-interface";
107
+ if (ts.isTypeAliasDeclaration(statement))
108
+ return "tree-type";
109
+ if (ts.isVariableStatement(statement))
110
+ return "tree-constant";
111
+ }
112
+ /** Get the text signature of a statement. */
113
+ function _getSignature(statement, source) {
114
+ if (ts.isFunctionDeclaration(statement)) {
115
+ const params = statement.parameters.map(p => p.getText(source)).join(", ");
116
+ const ret = statement.type ? statement.type.getText(source) : "void";
117
+ return `(${params}) => ${ret}`;
118
+ }
119
+ if (ts.isTypeAliasDeclaration(statement)) {
120
+ return statement.type.getText(source);
121
+ }
122
+ if (ts.isVariableStatement(statement)) {
123
+ const declaration = statement.declarationList.declarations[0];
124
+ if (declaration?.type)
125
+ return declaration.type.getText(source);
126
+ }
127
+ }
128
+ /** Extract parameters from a function or method declaration. */
129
+ function _getParams(statement, source) {
130
+ if (!ts.isFunctionDeclaration(statement))
131
+ return;
132
+ const jsDocParams = _getJSDoc(statement, source)?.params;
133
+ const params = statement.parameters.map(p => {
134
+ const name = p.name.getText(source);
135
+ const type = p.type?.getText(source);
136
+ const optional = !!p.questionToken || !!p.initializer;
137
+ const description = jsDocParams?.find(d => d.name === name)?.description;
138
+ return { name, type, description, optional };
139
+ });
140
+ return params.length ? params : undefined;
141
+ }
142
+ /** Get the return type of a function declaration. */
143
+ function _getReturnType(statement, source) {
144
+ if (ts.isFunctionDeclaration(statement) && statement.type)
145
+ return statement.type.getText(source);
146
+ }
147
+ /** Extract class or interface members as child elements. */
148
+ function _getClassMembers(statement, source) {
149
+ if (!ts.isClassDeclaration(statement) && !ts.isInterfaceDeclaration(statement))
150
+ return;
151
+ const members = [];
152
+ for (const member of statement.members) {
153
+ // Skip private, protected, and _-prefixed members.
154
+ const name = member.name && ts.isIdentifier(member.name) ? member.name.text : undefined;
155
+ if (!name || name.startsWith("_"))
156
+ continue;
157
+ if (ts.canHaveModifiers(member)) {
158
+ const modifiers = ts.getModifiers(member);
159
+ if (modifiers?.some(m => m.kind === ts.SyntaxKind.PrivateKeyword || m.kind === ts.SyntaxKind.ProtectedKeyword))
160
+ continue;
161
+ }
162
+ const jsDoc = _getJSDoc(member, source);
163
+ const props = {
164
+ title: name,
165
+ description: jsDoc?.description,
166
+ };
167
+ if (ts.isMethodDeclaration(member) || ts.isMethodSignature(member)) {
168
+ const params = member.parameters.map(p => p.getText(source)).join(", ");
169
+ const ret = member.type ? member.type.getText(source) : "void";
170
+ props.signature = `(${params}) => ${ret}`;
171
+ members.push({ type: "tree-method", key: null, props });
172
+ }
173
+ else if (ts.isPropertyDeclaration(member) || ts.isPropertySignature(member)) {
174
+ if (member.type)
175
+ props.signature = member.type.getText(source);
176
+ members.push({ type: "tree-property", key: null, props });
177
+ }
178
+ }
179
+ return members.length ? members : undefined;
180
+ }
181
+ /** Extract JSDoc from a node. */
182
+ function _getJSDoc(node, source) {
183
+ const ranges = ts.getLeadingCommentRanges(source.text, node.pos);
184
+ if (!ranges?.length)
185
+ return;
186
+ // Find the last JSDoc-style comment (/** ... */).
187
+ for (let i = ranges.length - 1; i >= 0; i--) {
188
+ const range = ranges[i];
189
+ if (!range || range.kind !== ts.SyntaxKind.MultiLineCommentTrivia)
190
+ continue;
191
+ const text = source.text.slice(range.pos, range.end);
192
+ if (!text.startsWith("/**"))
193
+ continue;
194
+ const description = _parseJSDocComment(text);
195
+ const params = _parseJSDocParams(text);
196
+ const examples = _parseJSDocExamples(text);
197
+ return {
198
+ description: description || undefined,
199
+ params: params.length ? params : undefined,
200
+ examples: examples.length ? examples : undefined,
201
+ };
202
+ }
203
+ }
204
+ /** Parse a JSDoc comment block into its description text. */
205
+ function _parseJSDocComment(text) {
206
+ const lines = text
207
+ .replace(/^\/\*\*\s*/, "")
208
+ .replace(/\s*\*\/$/, "")
209
+ .split("\n")
210
+ .map(l => l.replace(/^\s*\*\s?/, ""));
211
+ // Collect lines until we hit a @tag.
212
+ const description = [];
213
+ for (const line of lines) {
214
+ if (line.startsWith("@"))
215
+ break;
216
+ description.push(line);
217
+ }
218
+ const result = description.join("\n").trim();
219
+ return result || undefined;
220
+ }
221
+ /** Parse `@param` tags from a JSDoc comment. */
222
+ function _parseJSDocParams(text) {
223
+ const results = [];
224
+ const regexp = /@param\s+(?:\{[^}]*\}\s+)?(\w+)\s+(.*)/g;
225
+ let match;
226
+ while ((match = regexp.exec(text))) {
227
+ const name = match[1];
228
+ const description = match[2];
229
+ if (name && description)
230
+ results.push({ name, description: description.trim() });
231
+ }
232
+ return results;
233
+ }
234
+ /** Parse `@example` tags from a JSDoc comment. */
235
+ function _parseJSDocExamples(text) {
236
+ const results = [];
237
+ const regexp = /@example\s+(.*)/g;
238
+ let match;
239
+ while ((match = regexp.exec(text))) {
240
+ if (match[1])
241
+ results.push(match[1].trim());
242
+ }
243
+ return results;
244
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./DirectoryExtractor.js";
2
+ export * from "./Extractor.js";
3
+ export * from "./FileExtractor.js";
4
+ export * from "./MarkdownExtractor.js";
5
+ export * from "./TypescriptExtractor.js";
@@ -0,0 +1,5 @@
1
+ export * from "./DirectoryExtractor.js";
2
+ export * from "./Extractor.js";
3
+ export * from "./FileExtractor.js";
4
+ export * from "./MarkdownExtractor.js";
5
+ export * from "./TypescriptExtractor.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.202.0",
3
+ "version": "1.203.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,17 +9,17 @@
9
9
  "main": "./index.js",
10
10
  "module": "./index.js",
11
11
  "devDependencies": {
12
- "@biomejs/biome": "^2.4.14",
12
+ "@biomejs/biome": "^2.4.15",
13
13
  "@google-cloud/firestore": "^8.5.0",
14
14
  "@heroicons/react": "^2.2.0",
15
15
  "@types/bun": "^1.3.13",
16
16
  "@types/react": "^19.2.14",
17
17
  "@types/react-dom": "^19.2.3",
18
- "@typescript/native-preview": "^7.0.0-dev.20260502.1",
19
- "firebase": "^12.12.1",
20
- "react": "canary",
18
+ "@typescript/native-preview": "^7.0.0-dev.20260509.2",
19
+ "firebase": "^12.13.0",
20
+ "react": "^19.3.0-canary-d5736f09-20260507",
21
21
  "react-dom": "canary",
22
- "typescript": "^5"
22
+ "typescript": "^5.9.3"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@google-cloud/firestore": ">=7.0.0",
@@ -4,4 +4,4 @@ import { type InputProps } from "./Input.js";
4
4
  export interface ButtonInputProps extends InputProps, ClickableProps {
5
5
  }
6
6
  /** Return either a `<button>` or an `<a href="">` styled as an input, based on whether an `onClick` or `href` prop is provided. */
7
- export declare function ButtonInput({ title, placeholder, disabled, href, onClick, target, download, children }: ButtonInputProps): ReactElement;
7
+ export declare function ButtonInput({ title, placeholder, disabled, href, onClick, target, download, children, }: ButtonInputProps): ReactElement;
@@ -4,4 +4,4 @@ export interface CheckboxProps extends ValueInputProps<boolean> {
4
4
  children?: ReactNode | undefined;
5
5
  }
6
6
  /** Checkbox element. */
7
- export declare function CheckboxInput({ name, title, placeholder, required, disabled, message, value, onValue, children }: CheckboxProps): ReactElement;
7
+ export declare function CheckboxInput({ name, title, placeholder, required, disabled, message, value, onValue, children, }: CheckboxProps): ReactElement;
@@ -9,4 +9,4 @@ export interface DateInputProps extends ValueInputProps<string, PossibleDate> {
9
9
  step?: number | undefined;
10
10
  }
11
11
  export declare function DateInput({ name, title, placeholder, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
12
- required, disabled, message, value, onValue, min, max, input, step }: DateInputProps): ReactElement;
12
+ required, disabled, message, value, onValue, min, max, input, step, }: DateInputProps): ReactElement;
@@ -4,4 +4,4 @@ import { type ValueInputProps } from "./Input.js";
4
4
  export interface FileInputProps extends ValueInputProps<string | File> {
5
5
  types?: FileTypes | undefined;
6
6
  }
7
- export declare function FileInput({ name, title, placeholder, required, disabled, message, onValue, types }: FileInputProps): ReactElement;
7
+ export declare function FileInput({ name, title, placeholder, required, disabled, message, onValue, types, }: FileInputProps): ReactElement;
@@ -38,7 +38,7 @@ export interface ValueInputProps<O, I = never> extends InputProps {
38
38
  onValue(value: O | undefined): void;
39
39
  }
40
40
  /** Return either a `<button>` or an `<a href="">` styled as an input, based on whether an `onClick` or `href` prop is provided. */
41
- export declare function Input({ title, placeholder, disabled, href, onClick, target, download, children }: InputProps & ClickableProps): ReactElement;
41
+ export declare function Input({ title, placeholder, disabled, href, onClick, target, download, children, }: InputProps & ClickableProps): ReactElement;
42
42
  /** Input that is loading. */
43
43
  export declare const LOADING_INPUT: import("react/jsx-runtime").JSX.Element;
44
44
  /** Wraps an input with support for absolutely-positioned `data-slot` icon elements on either side. */
@@ -8,5 +8,5 @@ export interface NumberInputProps extends ValueInputProps<number> {
8
8
  formatter?: NumberFormatter | undefined;
9
9
  }
10
10
  export declare function NumberInput({ name, title, placeholder, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
11
- required, disabled, message, value, onValue, formatter }: NumberInputProps): ReactElement;
11
+ required, disabled, message, value, onValue, formatter, }: NumberInputProps): ReactElement;
12
12
  export {};
@@ -28,4 +28,4 @@ export interface PopoverProps {
28
28
  * @todo DH: Would love to use new HTML `popover="auto"` functionality for this but the anchor positioning it needs is not supported everywhere yet.
29
29
  */
30
30
  export declare function Popover({ children: [trigger, ...popover], //
31
- onClose, open }: PopoverProps): ReactElement;
31
+ onClose, open, }: PopoverProps): ReactElement;
@@ -4,4 +4,4 @@ export interface RadioInputProps extends ValueInputProps<boolean> {
4
4
  children?: ReactNode | undefined;
5
5
  }
6
6
  /** A single `<input type="radio">` in a `<label>` wrapper styled as an `<Input>` */
7
- export declare function RadioInput({ name, title, placeholder, required, disabled, message, value, onValue, children }: RadioInputProps): ReactElement;
7
+ export declare function RadioInput({ name, title, placeholder, required, disabled, message, value, onValue, children, }: RadioInputProps): ReactElement;
@@ -12,5 +12,5 @@ export interface TextInputProps extends ValueInputProps<string> {
12
12
  formatter?: TextFormatter | undefined;
13
13
  }
14
14
  export declare function TextInput({ name, title, placeholder, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
15
- required, disabled, message, value, onValue, input, min, max, rows, formatter }: TextInputProps): ReactElement;
15
+ required, disabled, message, value, onValue, input, min, max, rows, formatter, }: TextInputProps): ReactElement;
16
16
  export {};
package/ui/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export * from "./notice/index.js";
9
9
  export * from "./page/index.js";
10
10
  export * from "./router/index.js";
11
11
  export * from "./transition/index.js";
12
+ export * from "./tree/index.js";
12
13
  export * from "./util/index.js";
package/ui/index.js CHANGED
@@ -9,4 +9,5 @@ export * from "./notice/index.js";
9
9
  export * from "./page/index.js";
10
10
  export * from "./router/index.js";
11
11
  export * from "./transition/index.js";
12
+ export * from "./tree/index.js";
12
13
  export * from "./util/index.js";
package/ui/index.ts CHANGED
@@ -9,4 +9,5 @@ export * from "./notice/index.js";
9
9
  export * from "./page/index.js";
10
10
  export * from "./router/index.js";
11
11
  export * from "./transition/index.js";
12
+ export * from "./tree/index.js";
12
13
  export * from "./util/index.js";
@@ -0,0 +1,32 @@
1
+ import { type ComponentType, type JSX, type ReactNode } from "react";
2
+ /**
3
+ * Element mapping — maps intrinsic element type strings to React components.
4
+ * - Keys are element type names from `JSX.IntrinsicElements` (e.g. `"tree-file"`, `"tree-directory"`).
5
+ * - Each component must accept the props declared in `JSX.IntrinsicElements` for that element type.
6
+ */
7
+ export type Mapping = {
8
+ [K in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[K]>;
9
+ };
10
+ /** Props for the `Mapping` component returned by `createElementMapper()`. */
11
+ export interface MappingProps {
12
+ /** Mapping entries that override the defaults (and any parent `Mapping` entries). */
13
+ mapping: Mapping;
14
+ children: ReactNode;
15
+ }
16
+ /** Props for the `Mapper` component returned by `createElementMapper()`. */
17
+ export interface MapperProps {
18
+ children?: ReactNode;
19
+ }
20
+ /**
21
+ * Create an element mapper — a `[Mapping, Mapper]` pair of React components.
22
+ *
23
+ * - `Mapping` — wraps a subtree to override or extend the element mapping for this mapper.
24
+ * - `Mapper` — maps children, replacing element types with registered components.
25
+ *
26
+ * Each mapper has its own React context, so different mappers (e.g. `TreeMenu`, `TreePage`)
27
+ * can have independent mappings without interfering with each other.
28
+ *
29
+ * @param defaults Default mapping entries (lowest priority — overridden by any `Mapping` wrapper).
30
+ * @returns A `[Mapping, Mapper]` tuple of React components.
31
+ */
32
+ export declare function createMapper(defaults?: Mapping): [Mapping: React.FunctionComponent<MappingProps>, Mapper: React.FunctionComponent<MapperProps>];