ain-ui 0.1.0 → 0.1.1
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 +8 -0
- package/dist/react.d.ts +9 -1
- package/dist/react.js +8 -3
- package/dist/styles.css +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,3 +105,11 @@ npm pack --dry-run
|
|
|
105
105
|
|
|
106
106
|
Source extracted from aindrive's existing AINUI implementation. aindrive and
|
|
107
107
|
ainmem consume this package; protocol and component changes belong here.
|
|
108
|
+
|
|
109
|
+
### Host file previews
|
|
110
|
+
|
|
111
|
+
`AinuiSurface` accepts `renderFile({ src, download, name, mime, size })` to
|
|
112
|
+
render a `FileView` with the host's document, spreadsheet or other rich preview.
|
|
113
|
+
The URLs have already passed the renderer's URL checks and asset resolver.
|
|
114
|
+
Keep authentication and file permissions in the host's byte-serving routes.
|
|
115
|
+
Omit this callback to use the built-in media preview and download view.
|
package/dist/react.d.ts
CHANGED
|
@@ -5,9 +5,17 @@ import type { A2uiAction, A2uiMessage } from "./basic.js";
|
|
|
5
5
|
export type AssetResolver = (asset: AssetRef["$asset"], options?: {
|
|
6
6
|
download?: boolean;
|
|
7
7
|
}) => string;
|
|
8
|
+
export type FileViewRenderer = (file: {
|
|
9
|
+
src: string;
|
|
10
|
+
download: string;
|
|
11
|
+
name: string;
|
|
12
|
+
mime: string;
|
|
13
|
+
size?: number;
|
|
14
|
+
}) => React.ReactNode;
|
|
8
15
|
export declare const ainuiCatalog: Catalog<import("@a2ui/react/v0_9").ReactComponentImplementation, import("@a2ui/web_core/v0_9").FunctionImplementation>;
|
|
9
|
-
export declare function AinuiSurface({ messages, onAction, resolveAsset }: {
|
|
16
|
+
export declare function AinuiSurface({ messages, onAction, resolveAsset, renderFile }: {
|
|
10
17
|
messages: A2uiMessage[];
|
|
11
18
|
onAction: (action: A2uiAction) => void | Promise<void>;
|
|
12
19
|
resolveAsset?: AssetResolver;
|
|
20
|
+
renderFile?: FileViewRenderer;
|
|
13
21
|
}): React.JSX.Element;
|
package/dist/react.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { A2uiSurface, MarkdownContext, basicCatalog, createBinderlessComponentImplementation, useSignalValue } from "@a2ui/react/v0_9";
|
|
5
5
|
import { Catalog, CommonSchemas, MessageProcessor } from "@a2ui/web_core/v0_9";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { renderMarkdown } from "@a2ui/markdown-it";
|
|
8
8
|
import { AINUI_CATALOG, AINUI_UPLOAD_MAX_BYTES } from "./ainui.js";
|
|
9
|
+
const FileRenderer = createContext(undefined);
|
|
9
10
|
const Assets = createContext(() => "");
|
|
10
11
|
const box = { display: "flex", flexDirection: "column", gap: 8, minWidth: 0 };
|
|
11
12
|
const button = { padding: "8px 12px", border: "1px solid #8885", borderRadius: 8, color: "inherit", background: "transparent" };
|
|
@@ -63,6 +64,10 @@ const FileView = createBinderlessComponentImplementation(api("FileView", { src:
|
|
|
63
64
|
const mime = useValue(context, p.mime) || "";
|
|
64
65
|
const resolver = useContext(Assets);
|
|
65
66
|
const src = urlOf(asset, resolver);
|
|
67
|
+
const render = useContext(FileRenderer);
|
|
68
|
+
const size = useValue(context, p.size);
|
|
69
|
+
if (render && src)
|
|
70
|
+
return _jsx(_Fragment, { children: render({ src, download: urlOf(asset, resolver, true), name, mime, size }) });
|
|
66
71
|
return _jsxs("div", { style: box, children: [src && (mime.startsWith("image/") ? _jsx("img", { src: src, alt: name, style: { maxHeight: "70vh", objectFit: "contain" } }) :
|
|
67
72
|
mime.startsWith("video/") ? _jsx("video", { controls: true, src: src }) : mime.startsWith("audio/") ? _jsx("audio", { controls: true, src: src }) :
|
|
68
73
|
mime === "application/pdf" ? _jsx("iframe", { title: name, src: src, style: { height: "70vh", border: 0 } }) : null), _jsx("strong", { children: name }), _jsx("a", { href: urlOf(asset, resolver, true), download: name, children: "Download" })] });
|
|
@@ -146,7 +151,7 @@ const Button = createBinderlessComponentImplementation(api("Button", { child: Co
|
|
|
146
151
|
void fire(context); }, children: buildChild(String(p.child)) });
|
|
147
152
|
});
|
|
148
153
|
export const ainuiCatalog = new Catalog(AINUI_CATALOG, [...basicCatalog.components.values()].filter((c) => c.name !== "Button").concat([Button, Grid, Tile, FileView, Breadcrumbs, Segmented, FileUpload, X402Payment]), [...basicCatalog.functions.values()]);
|
|
149
|
-
export function AinuiSurface({ messages, onAction, resolveAsset }) {
|
|
154
|
+
export function AinuiSurface({ messages, onAction, resolveAsset, renderFile }) {
|
|
150
155
|
const handler = useRef(onAction);
|
|
151
156
|
handler.current = onAction;
|
|
152
157
|
const [processor, setProcessor] = useState(null);
|
|
@@ -169,5 +174,5 @@ export function AinuiSurface({ messages, onAction, resolveAsset }) {
|
|
|
169
174
|
return _jsx("div", { className: "ain-ui", role: "alert", children: error });
|
|
170
175
|
if (!processor)
|
|
171
176
|
return _jsx("div", { className: "ain-ui", "aria-busy": "true" });
|
|
172
|
-
return _jsx(MarkdownContext.Provider, { value: renderMarkdown, children: _jsx(Assets.Provider, { value: resolveAsset ?? (() => ""), children: _jsx("div", { className: "ain-ui", children: Array.from(processor.model.surfacesMap.values()).map((surface) => _jsx(A2uiSurface, { surface: surface }, surface.id)) }) }) });
|
|
177
|
+
return _jsx(MarkdownContext.Provider, { value: renderMarkdown, children: _jsx(Assets.Provider, { value: resolveAsset ?? (() => ""), children: _jsx(FileRenderer.Provider, { value: renderFile, children: _jsx("div", { className: "ain-ui", children: Array.from(processor.model.surfacesMap.values()).map((surface) => _jsx(A2uiSurface, { surface: surface }, surface.id)) }) }) }) });
|
|
173
178
|
}
|
package/dist/styles.css
CHANGED
|
@@ -4,3 +4,10 @@
|
|
|
4
4
|
.ain-ui button:disabled { cursor:default; opacity:.5; }
|
|
5
5
|
.ain-ui img, .ain-ui video { max-width:100%; }
|
|
6
6
|
.ain-ui fieldset { border:0; padding:0; margin:0; min-width:0; }
|
|
7
|
+
.ain-ui label { display:block; margin-block:6px; }
|
|
8
|
+
.ain-ui label input[type=checkbox], .ain-ui label input[type=radio] { margin-inline-end:8px; }
|
|
9
|
+
.ain-ui input[type=text], .ain-ui input[type=number], .ain-ui input[type=password], .ain-ui textarea {
|
|
10
|
+
width:100%; box-sizing:border-box; padding:8px 10px; border:1px solid #8886; border-radius:6px; color:inherit; background:transparent;
|
|
11
|
+
}
|
|
12
|
+
.ain-ui button:focus-visible, .ain-ui input:focus-visible, .ain-ui textarea:focus-visible { outline:2px solid currentColor; outline-offset:2px; }
|
|
13
|
+
.ain-ui p { margin-block:6px; }
|