@mechane-ai/elements 0.40.0 → 0.42.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 +41 -10
- package/bin/catalog.d.mts +17 -0
- package/bin/mechane-elements-catalog.mjs +60 -0
- package/dist/agent.js +1 -1
- package/dist/ai.js +23 -23
- package/dist/catalog.json +1896 -0
- package/dist/{categorical-values-DnGR_pQx.js → categorical-values-B6lGI7BH.js} +3 -3
- package/dist/{chart-frame-BsyI1Zc8.js → chart-frame-D0enjyj9.js} +1 -1
- package/dist/{chart-input-r4S3-QCT.js → chart-input-D4_Awave.js} +2 -2
- package/dist/{chart-navigation-D7OkLdSx.js → chart-navigation-D4-pdgpj.js} +12 -1
- package/dist/charts/cartesian.js +263 -243
- package/dist/charts/distribution.js +4 -4
- package/dist/charts/graph.js +4 -4
- package/dist/charts/hierarchy.js +4 -4
- package/dist/charts/matrix.js +4 -4
- package/dist/charts/timeline.js +3 -3
- package/dist/charts.js +2 -2
- package/dist/{code-block-C4K1sM9O.js → code-block-Cpfr7B6a.js} +1 -1
- package/dist/collections.js +475 -354
- package/dist/content/code.js +1 -1
- package/dist/content/diff.js +3 -3
- package/dist/content/link.js +1 -1
- package/dist/content/markdown.js +2 -2
- package/dist/content/tree.js +2 -2
- package/dist/{content-link-CBDqSvgP.js → content-link-CGeFFb9F.js} +1 -1
- package/dist/content.js +1 -1
- package/dist/feedback.js +1 -1
- package/dist/forms/dates.js +89 -12
- package/dist/{forms-I-WMHTkr.js → forms-DeU0Tiv3.js} +6 -2
- package/dist/forms.js +3 -3
- package/dist/index.js +1 -1
- package/dist/layout.js +275 -249
- package/dist/mechane-elements-catalog.mjs +4 -0
- package/dist/navigation.js +2 -2
- package/dist/packages/charts/src/chart-inspection.d.ts +1 -0
- package/dist/packages/charts/src/chart-navigation.d.ts +2 -0
- package/dist/packages/charts/src/chart-surface.d.ts +2 -0
- package/dist/packages/collections/src/collection-controls.d.ts +2 -1
- package/dist/packages/collections/src/data-table.d.ts +12 -8
- package/dist/packages/collections/src/index.d.ts +1 -0
- package/dist/packages/collections/src/table-results.d.ts +26 -0
- package/dist/packages/core/src/actions.d.ts +6 -0
- package/dist/packages/core/src/index.d.ts +1 -1
- package/dist/packages/forms/src/dates/event-month.d.ts +17 -0
- package/dist/packages/forms/src/dates/index.d.ts +2 -0
- package/dist/packages/forms/src/form-status.d.ts +7 -0
- package/dist/packages/forms/src/forms.d.ts +3 -1
- package/dist/packages/forms/src/index.d.ts +2 -0
- package/dist/packages/foundations/src/agent/index.d.ts +2 -2
- package/dist/packages/layout/src/page-context.d.ts +4 -0
- package/dist/packages/navigation/src/index.d.ts +1 -0
- package/dist/packages/navigation/src/route-link.d.ts +2 -0
- package/dist/{pierre-diff-DJ3oOfPX.js → pierre-diff-B3tD3-6z.js} +1 -1
- package/dist/{src-D2OHco8V.js → src-Bk7M67zy.js} +3 -3
- package/dist/{src-DfOAlAd2.js → src-BpvnBWrF.js} +1 -1
- package/dist/{src-CQQvXi7a.js → src-DBNncL7_.js} +70 -50
- package/dist/{src-s3tWwnN4.js → src-DcW_gMX8.js} +178 -168
- package/dist/{src-CNV1ewzb.js → src-gqEebHEa.js} +319 -285
- package/dist/styles2.css +18 -0
- package/package.json +9 -2
- package/recipes/consequential-form.tsx +132 -0
- package/recipes/searchable-collection.tsx +106 -0
- package/recipes/sectioned-report.tsx +58 -0
- package/recipes/tabbed-workspace.tsx +84 -0
- package/skills/extend-elements/SKILL.md +28 -0
- package/skills/use-elements/SKILL.md +36 -0
- package/skills/{elements-presentation/SKILL.md → use-elements/references/reports.md} +0 -6
- package/skills/{elements-workspace/SKILL.md → use-elements/references/workspace.md} +3 -6
package/README.md
CHANGED
|
@@ -9,18 +9,49 @@ Applications import the Elements family that owns the interaction. When adding a
|
|
|
9
9
|
and its Storybook example. Keep focus, value changes, and dismissal with one primitive. Native links retain browser
|
|
10
10
|
navigation and modifier-key behavior.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
does not grant an external agent access. Keep credentials out of observable values and retain human approval for
|
|
14
|
-
privileged actions.
|
|
12
|
+
## Build with an agent
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
Use the [use-elements skill](skills/use-elements/SKILL.md) when building an app and the
|
|
15
|
+
[extend-elements skill](skills/extend-elements/SKILL.md) when changing the library. Both ship with the package.
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
toolbar geometry.
|
|
20
|
-
- [Loading and chart interaction](skills/elements-presentation/SKILL.md) covers coordinated route transitions, delayed
|
|
21
|
-
skeletons and pointer and keyboard inspection.
|
|
17
|
+
Find a recipe by task from a project with Elements installed:
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
```sh
|
|
20
|
+
pnpm exec mechane-elements-catalog "searchable table with filters"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The catalog connects a task to the example's TSX, public imports, and rendered Storybook story. Read the same index
|
|
24
|
+
programmatically at `@mechane-ai/elements/catalog.json`. When running the local Elements Storybook, connect an MCP
|
|
25
|
+
client to `http://localhost:6006/mcp` to explore the examples while developing.
|
|
26
|
+
|
|
27
|
+
## Enable an agent in an app
|
|
28
|
+
|
|
29
|
+
Create the bridge at browser startup. A host integrating its own model can use the tool definitions in `agentTools`. To
|
|
30
|
+
expose tools to the browser through WebMCP, call `registerTools` explicitly and keep its cleanup function:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createAgent, registerTools } from '@mechane-ai/elements/agent';
|
|
34
|
+
import type { AgentAction } from '@mechane-ai/elements/agent';
|
|
35
|
+
|
|
36
|
+
const allow = (step: AgentAction) =>
|
|
37
|
+
step.confirm === undefined && step.component === 'collection-query' && step.action === 'setQuery';
|
|
38
|
+
|
|
39
|
+
const agent = createAgent({ allow });
|
|
40
|
+
const unregister = registerTools(agent, { allow });
|
|
41
|
+
// Call unregister() when the host ends this integration.
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This example permits changing a collection search. A host can query or snapshot mounted components to discover their
|
|
45
|
+
available actions. After requesting a change, read the resulting state, including pending or error feedback from the
|
|
46
|
+
data owner. Keep credentials and private values out of observable labels, descriptions, and results. The application
|
|
47
|
+
authorizes data reads and mutations on the server.
|
|
48
|
+
|
|
49
|
+
| What the agent needs | What to look for in the mounted UI |
|
|
50
|
+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
51
|
+
| Find and open a record | Use the named `collection-query`, then re-read `collection-results` until its `status` is `ready`. A pending or failed read can retain the previous rows. Match the chosen item to a mounted `collection-record` by `collection` and `recordId`, then use its advertised action. |
|
|
52
|
+
| Know where the user is | Read the `page-title`, current `navigation-link` or tab, and the `page-section` at the reading position. Scrolling updates the section an agent can query. |
|
|
53
|
+
| Inspect a chart or file | Query chart or tree items for the visible label and identifier. Read the chart's formatted `readout` after inspection. After selection, query the inspector's labeled `detail-field` entries. |
|
|
54
|
+
| Complete a form | Use visible field validation and `form-status` for pending, error, or success. Use `Field.Root isSensitive` to hide sensitive labels, values, and validation from the bridge. Put `ConfirmButton` on the action that performs a consequential mutation. |
|
|
24
55
|
|
|
25
56
|
## Install
|
|
26
57
|
|
|
@@ -69,7 +100,7 @@ Every path below belongs to `@mechane-ai/elements`. There is one package, versio
|
|
|
69
100
|
| ---------------------- | ----------------------------------------------------------------------------------- |
|
|
70
101
|
| Root | Buttons, text, surfaces, disclosure, avatars, and CopyValue. |
|
|
71
102
|
| `/forms` | Fields, inputs, selection, appearance picking, file picking, and settings sections. |
|
|
72
|
-
| `/forms/dates` | Civil-date
|
|
103
|
+
| `/forms/dates` | Civil-date pickers, range selection, and a controlled event month. |
|
|
73
104
|
| `/overlays` | Dialog, Drawer, Menu, Popover, Preview, Tooltip, and AlertDialog. |
|
|
74
105
|
| `/feedback` | Async regions, skeletons, progress, meters, notices, empty states, and toasts. |
|
|
75
106
|
| `/navigation` | Tabs, page navigation, breadcrumbs, skip links, and shortcut labels. |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Recipe = {
|
|
2
|
+
readonly slug: string;
|
|
3
|
+
readonly title: string;
|
|
4
|
+
readonly description: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly story: string;
|
|
7
|
+
readonly imports: ReadonlyArray<string>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type PublicExport = { readonly kind: 'type' | 'value'; readonly declaration: string };
|
|
11
|
+
|
|
12
|
+
export type Catalog = {
|
|
13
|
+
readonly package: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly recipes: ReadonlyArray<Recipe>;
|
|
16
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, PublicExport>>>>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
|
|
4
|
+
const ignored = new Set(['a', 'an', 'and', 'are', 'build', 'for', 'in', 'of', 'on', 'page', 'the', 'to', 'with']);
|
|
5
|
+
|
|
6
|
+
/** @import {Catalog} from './catalog.d.mts' */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {Catalog} catalog The catalog built from the public package.
|
|
10
|
+
* @param {string} query Normalized task or public export name.
|
|
11
|
+
*/
|
|
12
|
+
function lookup(catalog, query) {
|
|
13
|
+
const version = { package: catalog.package, version: catalog.version };
|
|
14
|
+
|
|
15
|
+
if (query.length === 0) {
|
|
16
|
+
return { ...version, recipes: catalog.recipes };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const words = new Set(query.match(/[a-z0-9]+/g));
|
|
20
|
+
const terms = [...words].filter((word) => !ignored.has(word));
|
|
21
|
+
const matches = catalog.recipes
|
|
22
|
+
.map((recipe) => {
|
|
23
|
+
const title = `${recipe.title} ${recipe.slug}`.toLowerCase();
|
|
24
|
+
const details = `${recipe.description} ${recipe.imports.join(' ')}`.toLowerCase();
|
|
25
|
+
const score = terms.reduce((sum, term) => sum + (title.includes(term) ? 3 : Number(details.includes(term))), 0);
|
|
26
|
+
|
|
27
|
+
return { recipe, score };
|
|
28
|
+
})
|
|
29
|
+
.filter(({ score }) => score > 0)
|
|
30
|
+
.toSorted((first, second) => second.score - first.score);
|
|
31
|
+
|
|
32
|
+
const exports = Object.entries(catalog.entries).flatMap(([specifier, members]) =>
|
|
33
|
+
Object.entries(members)
|
|
34
|
+
.filter(([name]) => name.toLowerCase().includes(query) || specifier.toLowerCase() === query)
|
|
35
|
+
.map(([name, member]) => ({ name, specifier, ...member })),
|
|
36
|
+
);
|
|
37
|
+
const best = matches[0]?.recipe;
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...version,
|
|
41
|
+
recipes: matches.map(({ recipe }) => recipe),
|
|
42
|
+
exports,
|
|
43
|
+
...(best !== undefined && { example: readFileSync(new URL(`../${best.path}`, import.meta.url), 'utf8') }),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {Catalog} catalog The catalog built from the public package. */
|
|
48
|
+
export function runCatalog(catalog) {
|
|
49
|
+
const { positionals, values } = parseArgs({
|
|
50
|
+
allowPositionals: true,
|
|
51
|
+
options: { help: { type: 'boolean', short: 'h', default: false } },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (values.help) {
|
|
55
|
+
process.stdout.write('Usage: mechane-elements-catalog [task or public export name]\n');
|
|
56
|
+
} else {
|
|
57
|
+
const result = lookup(catalog, positionals.join(' ').trim().toLowerCase());
|
|
58
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/agent.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createAgent } from "@ui-sdk/react/agent";
|
|
1
|
+
export { agentTools, createAgent, registerTools } from "@ui-sdk/react/agent";
|
package/dist/ai.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { D as e, E as t,
|
|
2
|
-
import { t as l } from "./code-block-
|
|
3
|
-
import { a as u } from "./src-
|
|
4
|
-
import { t as d } from "./content-link-
|
|
1
|
+
import { D as e, E as t, O as n, _ as r, i, m as a, p as o, t as s, w as c } from "./src-DcW_gMX8.js";
|
|
2
|
+
import { t as l } from "./code-block-Cpfr7B6a.js";
|
|
3
|
+
import { a as u } from "./src-Bk7M67zy.js";
|
|
4
|
+
import { t as d } from "./content-link-CGeFFb9F.js";
|
|
5
5
|
import { r as f, t as p } from "./src-na2DdkKI.js";
|
|
6
|
-
import { f as m, l as h } from "./src-
|
|
7
|
-
import { i as g, t as _ } from "./forms-
|
|
6
|
+
import { f as m, l as h } from "./src-BpvnBWrF.js";
|
|
7
|
+
import { i as g, t as _ } from "./forms-DeU0Tiv3.js";
|
|
8
8
|
import { t as ee } from "./accessibility-P89UG9-r.js";
|
|
9
9
|
import { r as v } from "./control-styles-D3q_Qyxi.js";
|
|
10
10
|
import { t as y } from "./visible-motion-1GcUaEi4.js";
|
|
@@ -330,16 +330,16 @@ function oe({ name: e, description: t, href: n, actions: r }) {
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
// packages/ai/src/message-action.tsx
|
|
333
|
-
function se(
|
|
334
|
-
if (
|
|
335
|
-
let { kind:
|
|
336
|
-
return /* @__PURE__ */ O(
|
|
333
|
+
function se(n) {
|
|
334
|
+
if (n.kind === "link") {
|
|
335
|
+
let { kind: t, label: r, ...i } = n;
|
|
336
|
+
return /* @__PURE__ */ O(e, {
|
|
337
337
|
...i,
|
|
338
338
|
"aria-label": r
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
|
-
let { kind: r, label: i, ...a } =
|
|
342
|
-
return /* @__PURE__ */ O(
|
|
341
|
+
let { kind: r, label: i, ...a } = n;
|
|
342
|
+
return /* @__PURE__ */ O(t, {
|
|
343
343
|
...a,
|
|
344
344
|
variant: "ghost",
|
|
345
345
|
"aria-label": i
|
|
@@ -406,7 +406,7 @@ function ue({ isCompact: e = !1 }) {
|
|
|
406
406
|
})
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
|
-
function de({ label: e, value:
|
|
409
|
+
function de({ label: e, value: n, onValueChange: r, onSubmit: i, name: a = "prompt", placeholder: o, maxLength: s, required: c = !0, isPending: l = !1, disabled: u = !1, isSubmitDisabled: d = !1, submitLabel: f = "Send message", pendingLabel: m = "Sending…", enterBehavior: h = "newline", isCompact: v = !1, description: y, error: x, controls: S, attachments: C, onStop: T, isStopPending: E = !1, stopLabel: D = "Stop response" }) {
|
|
410
410
|
let A = w(), M = u, N = v && C === void 0 && S === void 0, P = !M && !l && !d, F = f;
|
|
411
411
|
T === void 0 ? l ? F = m : h === "submit" && (F = `${f} · Enter`) : F = E ? "Stopping…" : D;
|
|
412
412
|
function I(e) {
|
|
@@ -443,7 +443,7 @@ function de({ label: e, value: t, onValueChange: r, onSubmit: i, name: a = "prom
|
|
|
443
443
|
shouldGrow: N,
|
|
444
444
|
xstyle: N ? $.inlineInput : void 0,
|
|
445
445
|
name: a,
|
|
446
|
-
value:
|
|
446
|
+
value: n,
|
|
447
447
|
onValueChange: r,
|
|
448
448
|
onKeyDown: I,
|
|
449
449
|
placeholder: o ?? e,
|
|
@@ -461,7 +461,7 @@ function de({ label: e, value: t, onValueChange: r, onSubmit: i, name: a = "prom
|
|
|
461
461
|
children: [S !== void 0 && /* @__PURE__ */ O("div", {
|
|
462
462
|
className: "x78zum5 x1a02dak x6s0dn4 x1hnptsi xeuugli x12lumcd",
|
|
463
463
|
children: S
|
|
464
|
-
}), /* @__PURE__ */ k(p.Root, { children: [/* @__PURE__ */ O(p.Trigger, { render: T === void 0 ? /* @__PURE__ */ O(
|
|
464
|
+
}), /* @__PURE__ */ k(p.Root, { children: [/* @__PURE__ */ O(p.Trigger, { render: T === void 0 ? /* @__PURE__ */ O(t, {
|
|
465
465
|
xstyle: $.action,
|
|
466
466
|
type: "submit",
|
|
467
467
|
"data-agent-confirm": f,
|
|
@@ -473,7 +473,7 @@ function de({ label: e, value: t, onValueChange: r, onSubmit: i, name: a = "prom
|
|
|
473
473
|
size: 16,
|
|
474
474
|
"aria-hidden": !0
|
|
475
475
|
})
|
|
476
|
-
}) : /* @__PURE__ */ O(
|
|
476
|
+
}) : /* @__PURE__ */ O(t, {
|
|
477
477
|
xstyle: $.action,
|
|
478
478
|
type: "button",
|
|
479
479
|
"data-agent-confirm": D,
|
|
@@ -553,22 +553,22 @@ function pe({ sources: e, label: t = "Sources" }) {
|
|
|
553
553
|
]
|
|
554
554
|
});
|
|
555
555
|
}
|
|
556
|
-
function me({ source:
|
|
556
|
+
function me({ source: e, label: t }) {
|
|
557
557
|
return /* @__PURE__ */ O("span", {
|
|
558
558
|
className: "xt0psk2 x11njtxf xss6m8b",
|
|
559
559
|
children: /* @__PURE__ */ k(f.Root, { children: [/* @__PURE__ */ O(f.Trigger, {
|
|
560
|
-
render: /* @__PURE__ */ O(
|
|
561
|
-
"aria-label": `Source ${
|
|
562
|
-
children:
|
|
560
|
+
render: /* @__PURE__ */ O(n, {}),
|
|
561
|
+
"aria-label": `Source ${t}: ${e.title}`,
|
|
562
|
+
children: t
|
|
563
563
|
}), /* @__PURE__ */ O(f.Popup, {
|
|
564
564
|
side: "top",
|
|
565
565
|
children: /* @__PURE__ */ k(a, {
|
|
566
566
|
isCompact: !0,
|
|
567
567
|
children: [
|
|
568
|
-
/* @__PURE__ */ O(f.Title, { children:
|
|
569
|
-
|
|
568
|
+
/* @__PURE__ */ O(f.Title, { children: e.title }),
|
|
569
|
+
e.description !== void 0 && /* @__PURE__ */ O(f.Description, { children: e.description }),
|
|
570
570
|
/* @__PURE__ */ O(d, {
|
|
571
|
-
href:
|
|
571
|
+
href: e.href,
|
|
572
572
|
children: "Open source"
|
|
573
573
|
})
|
|
574
574
|
]
|