@pritzlaff/nano-elements 0.1.0 → 0.4.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/README.md CHANGED
@@ -1,16 +1,64 @@
1
1
  # @pritzlaff/nano-elements
2
2
 
3
- Lit elements over `@pritzlaff/nano-core` components.
4
-
5
- - **`ModelElement`:** shows and drives one model. Give it a `registry` and a `model` (an instance id), and
6
- optionally a `watch` list of more instances whose sources it reads. It joins the registry as a hidden
7
- subscriber of each, re-renders when they publish, and calls the model's actions through its own handle:
8
- `this.read(op)` gives the latest value, and `this.act(op, arg)` calls an action, keeping a refusal in
9
- `this.problem`.
10
- - **`PlacedElement`:** a ModelElement that brings its own component (`static component`).
11
- - **On the page,** it shows the instance named by its `name` attribute, in the registry provided for the
12
- document. If no instance has that name, it creates one and removes it when the element goes.
13
- - **Moving it** (as a dock does) keeps the instance.
14
- - **Without a `name`,** it gets a generated one.
15
- - **`provide(document, registry)`:** sets the registry that placed elements use.
16
- - **`base`:** the shared styles (the puzzle prototype's palette).
3
+ Lit elements: the nano kit (command, select, calendar, menu, data table, tree, agent parts, ...), `base` (the shared
4
+ styles) and the `--nano-*` theme contract.
5
+
6
+ ## Theming: the `--nano-*` contract
7
+
8
+ Every element reads its colours, fonts and radius from these CSS custom properties, which reach inside shadow roots.
9
+ A host sets them (or maps its own variables onto them, once); unset, each falls back to the default dark look
10
+ (`NANO_TOKENS`). Elements never know which host or theme they're in.
11
+
12
+ | Group | Tokens |
13
+ | --- | --- |
14
+ | surfaces | `bg` `surface` `surface-2` `border` `border-strong` |
15
+ | text | `fg` `fg-2` `muted` `on-accent` |
16
+ | intent | `accent` `accent-soft` `focus` `good` `good-bg` `bad` `bad-bg` `warn` `warn-bg` |
17
+ | type, shape | `font` `font-display` `font-mono` `radius` `radius-s` |
18
+ | series | `s1` … `s8` |
19
+
20
+ A host with its own vocabulary maps it, e.g. a newspaper page:
21
+
22
+ ```css
23
+ :root { --nano-bg: var(--paper); --nano-surface: var(--paper); --nano-fg: var(--ink); --nano-border: var(--rule);
24
+ --nano-accent: var(--accent); --nano-font: var(--body-font); --nano-font-display: var(--display-font); --nano-radius: 0; }
25
+ ```
26
+
27
+ In an element: `static styles = [base, css\`…${t('accent')}…\`]`, or `tv('accent')` in an inline style.
28
+
29
+ ## The component library (`base`)
30
+
31
+ Bare `button`, `input`, `select` and `textarea` are styled; and the classes: `.btn` (`.primary` `.danger` `.dashed`
32
+ `.small`), `.icon-btn`, `.badge` (`.good` `.bad` `.warn` `.accent`), `.chip`, `.pill`, `.card`, `.alert` (`.good`
33
+ `.bad`), `.problem`, `.field`, `.input`, `.meter` (a `span` inside, width = value), `.table`, `.tabs`
34
+ (`button[aria-selected]`), `.list-row`, `.kicker`, `.display-s/m/l`, `.muted`, `.mono`, `.row`, `.col`, `.grid-auto`.
35
+
36
+ Where the browser allows it (`appearance: base-select`), a bare `select`'s open list takes the theme too. Set
37
+ `color-scheme` (light or dark) on the page, so the browser's own pickers and scrollbars match.
38
+
39
+ ## The kit (`kit`), in shadcn's look
40
+
41
+ CSS only (`static styles = [base, kit]`, or a page's `document.adoptedStyleSheets`): `.avatar` (`.small` `.large`)
42
+ and `.avatar-stack`, `.bubble` (`.mine`), `.kbd`, `.code`, `.input-group` (with `.addon`s and buttons), `.toggle`
43
+ (`aria-pressed`) and `.toggle-group`, `input[type=checkbox].switch`, `dialog.dialog` and `dialog.drawer` (`.bottom`)
44
+ for native `<dialog>`s (`showModal()`; a `<form method="dialog">` closes one), `.pop` (a `[popover]` surface),
45
+ `.menu-item`, `.menu-sep`, `.menu-label`, `.shortcut`, `.toast`.
46
+
47
+ Elements, defined on import:
48
+
49
+ | Element | Takes | Emits |
50
+ | --- | --- | --- |
51
+ | `<nano-select>` (`multiple`, `placeholder`, `label`) | `options` (strings or `{ value, label?, group?, disabled? }`), `value` (string, or array when multiple) | `change` |
52
+ | `<nano-command>` | `items` (`{ value, label?, group?, shortcut? }`), `selected` | `pick` (the item) |
53
+ | `<nano-calendar>`, `<nano-date-picker>` | `value` (ISO `YYYY-MM-DD`) | `change` |
54
+ | `<nano-menu>` (wraps content; right-click opens it) | `items` (`{ label, shortcut?, danger?, disabled? }`, `{ separator: true }`, `{ heading }`) | `pick` (the item) |
55
+ | `<nano-hover-card>` (`open-delay`, `close-delay`) | content, and a `card` slot | |
56
+ | `<nano-data-table>` (`filter`, `selectable`, `page-size`) | `columns` (`{ key, label, sortable?, align?, width?, minWidth?, render? }`; each resizes by its header's edge, drag or ←/→), `rows` | `selection` (the rows) |
57
+ | `<nano-code-block>` (`language`) | `code` | |
58
+ | `<nano-tree>` (`open-depth`); `reveal(id, { focus? })` | `nodes` (`{ id, label, kind?, count?, badge?, terms?, end?, body?, children? }`), `query`, `selected` | `select` (`{ id }`; cancel it to keep `selected` yours) |
59
+ | `toast(title, { description?, variant?, duration? })` | shows in one `<nano-toaster>`, made on first use | |
60
+
61
+ Agent pieces, display only, on the AI SDK's data shapes: `<nano-tool>` (`.tool`: a tool part — `type`, `state`,
62
+ `input`, `output`, `errorText`), `<nano-task>` (`.task`), `<nano-subagent>` (`.agent`: name, status, its tool
63
+ parts), `<nano-cli>` (`.runs`: command, output, exit code), `<nano-trace>` (`.spans`: OpenTelemetry-style `spanId`,
64
+ `parentSpanId`, `startTime`, `endTime`, `status`) and `<nano-test-results>` (`.results`: summary and suites).
@@ -0,0 +1,79 @@
1
+ import { LitElement, nothing } from 'lit';
2
+ /** A tool part: `type` is `tool-<name>`, or `dynamic-tool` with `toolName`. */
3
+ export interface ToolPart {
4
+ type: string;
5
+ toolName?: string;
6
+ toolCallId?: string;
7
+ state: 'input-streaming' | 'input-available' | 'output-available' | 'output-error';
8
+ input?: unknown;
9
+ output?: unknown;
10
+ errorText?: string;
11
+ }
12
+ export interface TaskItem {
13
+ text: string;
14
+ status?: 'pending' | 'in_progress' | 'completed';
15
+ file?: {
16
+ name: string;
17
+ };
18
+ }
19
+ export interface Task {
20
+ title: string;
21
+ items: TaskItem[];
22
+ }
23
+ export interface Subagent {
24
+ name: string;
25
+ description?: string;
26
+ status: 'running' | 'completed' | 'error';
27
+ parts: ToolPart[];
28
+ result?: string;
29
+ }
30
+ export interface Run {
31
+ command: string;
32
+ output?: string;
33
+ exitCode?: number;
34
+ running?: boolean;
35
+ cwd?: string;
36
+ }
37
+ /** What the agent pieces share: a card that opens, with a header row. */
38
+ export declare const agentStyles: import("lit").CSSResult;
39
+ export declare class NanoTool extends LitElement {
40
+ static properties: {
41
+ tool: {
42
+ attribute: boolean;
43
+ };
44
+ };
45
+ static styles: import("lit").CSSResult[];
46
+ tool: ToolPart | undefined;
47
+ render(): typeof nothing | import("lit").TemplateResult<1>;
48
+ }
49
+ export declare class NanoTask extends LitElement {
50
+ static properties: {
51
+ task: {
52
+ attribute: boolean;
53
+ };
54
+ };
55
+ static styles: import("lit").CSSResult[];
56
+ task: Task | undefined;
57
+ render(): typeof nothing | import("lit").TemplateResult<1>;
58
+ }
59
+ export declare class NanoSubagent extends LitElement {
60
+ static properties: {
61
+ agent: {
62
+ attribute: boolean;
63
+ };
64
+ };
65
+ static styles: import("lit").CSSResult[];
66
+ agent: Subagent | undefined;
67
+ render(): typeof nothing | import("lit").TemplateResult<1>;
68
+ }
69
+ export declare class NanoCli extends LitElement {
70
+ static properties: {
71
+ runs: {
72
+ attribute: boolean;
73
+ };
74
+ };
75
+ static styles: import("lit").CSSResult[];
76
+ runs: Run[];
77
+ constructor();
78
+ render(): import("lit").TemplateResult<1>;
79
+ }
@@ -0,0 +1,52 @@
1
+ import { LitElement, nothing } from 'lit';
2
+ export interface Span {
3
+ spanId: string;
4
+ parentSpanId?: string;
5
+ name: string;
6
+ startTime: number;
7
+ endTime: number;
8
+ status?: 'ok' | 'error' | 'unset';
9
+ }
10
+ export interface TestCase {
11
+ name: string;
12
+ status: 'passed' | 'failed' | 'skipped';
13
+ duration?: number;
14
+ error?: {
15
+ message: string;
16
+ stack?: string;
17
+ };
18
+ }
19
+ export interface TestResults {
20
+ summary: {
21
+ passed: number;
22
+ failed: number;
23
+ skipped: number;
24
+ total: number;
25
+ duration?: number;
26
+ };
27
+ suites: {
28
+ name: string;
29
+ tests: TestCase[];
30
+ }[];
31
+ }
32
+ export declare class NanoTrace extends LitElement {
33
+ static properties: {
34
+ spans: {
35
+ attribute: boolean;
36
+ };
37
+ };
38
+ static styles: import("lit").CSSResult[];
39
+ spans: Span[];
40
+ constructor();
41
+ render(): typeof nothing | import("lit").TemplateResult<1>;
42
+ }
43
+ export declare class NanoTestResults extends LitElement {
44
+ static properties: {
45
+ results: {
46
+ attribute: boolean;
47
+ };
48
+ };
49
+ static styles: import("lit").CSSResult[];
50
+ results: TestResults | undefined;
51
+ render(): typeof nothing | import("lit").TemplateResult<1>;
52
+ }
package/attrs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function setAttrs(el: Element | undefined, all?: Record<string, string | undefined>): void;
package/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export { ModelElement } from './model-element.js';
2
- export { PlacedElement, provide, providedRegistry } from './placed-element.js';
3
1
  export { base } from './styles.js';
4
- export type { Catalog, CatalogEntry } from './catalog.js';
2
+ export { kit } from './kit.js';
3
+ export { NANO_TOKENS, t, tv, type NanoToken } from './tokens.js';
4
+ export { NanoCommand, NanoSelect, type Item } from './kit/select.js';
5
+ export { NanoCalendar, NanoDatePicker } from './kit/calendar.js';
6
+ export { NanoMenu, NanoHoverCard, NanoToaster, NanoCodeBlock, toast, type MenuItem, type Toast } from './kit/overlays.js';
7
+ export { NanoDataTable, type Column } from './kit/data-table.js';
8
+ export { NanoTool, NanoTask, NanoSubagent, NanoCli, type ToolPart, type Task, type TaskItem, type Subagent, type Run } from './agent/parts.js';
9
+ export { NanoTrace, NanoTestResults, type Span, type TestCase, type TestResults } from './agent/timeline.js';
10
+ export { NanoTree, type TreeNode } from './kit/tree.js';