@voltro/ui 0.84.0 → 0.86.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.
@@ -0,0 +1,77 @@
1
+ import { useState as e } from "react";
2
+ import { useDataCopilot as t } from "@voltro/client";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ //#region src/dataCopilot.tsx
5
+ var i = (e) => e == null ? "" : typeof e == "boolean" ? e ? "✓" : "✗" : typeof e == "object" ? JSON.stringify(e) : String(e), a = (e) => {
6
+ let t = /* @__PURE__ */ new Set(), n = [];
7
+ for (let r of e) for (let e of Object.keys(r)) t.has(e) || (t.add(e), n.push(e));
8
+ return n;
9
+ };
10
+ function o(e) {
11
+ let { answer: t, emptyText: o } = e;
12
+ if (t === void 0) return null;
13
+ if (!t.ok) return /* @__PURE__ */ n("p", {
14
+ "data-voltro-data-copilot-refused": !0,
15
+ role: "status",
16
+ children: t.reason
17
+ });
18
+ if (t.rows.length === 0) return /* @__PURE__ */ n("p", {
19
+ "data-voltro-data-copilot-empty": !0,
20
+ children: o ?? "No rows."
21
+ });
22
+ let s = a(t.rows);
23
+ return /* @__PURE__ */ r("table", {
24
+ "data-voltro-data-copilot-results": !0,
25
+ children: [/* @__PURE__ */ n("thead", { children: /* @__PURE__ */ n("tr", { children: s.map((e) => /* @__PURE__ */ n("th", {
26
+ scope: "col",
27
+ children: e
28
+ }, e)) }) }), /* @__PURE__ */ n("tbody", { children: t.rows.map((e, t) => /* @__PURE__ */ n("tr", { children: s.map((t) => /* @__PURE__ */ n("td", {
29
+ "data-column": t,
30
+ children: i(e[t])
31
+ }, t)) }, String(e.id ?? t))) })]
32
+ });
33
+ }
34
+ function s(i) {
35
+ let { api: a, action: s, placeholder: c, askLabel: l, emptyText: u } = i, d = t(a, s), [f, p] = e(""), m = () => {
36
+ let e = f.trim();
37
+ e.length === 0 || d.pending || d.ask(e);
38
+ };
39
+ return /* @__PURE__ */ r("div", {
40
+ "data-voltro-data-copilot": s,
41
+ children: [/* @__PURE__ */ r("form", {
42
+ "data-composer": !0,
43
+ onSubmit: (e) => {
44
+ e.preventDefault(), m();
45
+ },
46
+ children: [/* @__PURE__ */ n("input", {
47
+ value: f,
48
+ onChange: (e) => p(e.target.value),
49
+ placeholder: c ?? "Ask about your data…",
50
+ "aria-label": "Ask about your data",
51
+ disabled: d.pending
52
+ }), /* @__PURE__ */ n("button", {
53
+ type: "submit",
54
+ disabled: d.pending || f.trim().length === 0,
55
+ children: l ?? "Ask"
56
+ })]
57
+ }), /* @__PURE__ */ n("div", {
58
+ "data-answer": !0,
59
+ "aria-live": "polite",
60
+ "aria-busy": d.pending ? "true" : void 0,
61
+ children: d.error === void 0 ? /* @__PURE__ */ n(o, {
62
+ answer: d.answer,
63
+ ...u === void 0 ? {} : { emptyText: u }
64
+ }) : /* @__PURE__ */ n("p", {
65
+ "data-voltro-data-copilot-error": !0,
66
+ role: "alert",
67
+ children: d.error instanceof Error ? d.error.message : String(d.error)
68
+ })
69
+ })]
70
+ });
71
+ }
72
+ function c(e) {
73
+ let n = t(e.api, e.action);
74
+ return e.children(n);
75
+ }
76
+ //#endregion
77
+ export { s as DataCopilot, o as DataCopilotAnswer, c as DataCopilotStream };
@@ -0,0 +1,60 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { memo as t, useMemo as n } from "react";
3
+ import { useDataTable as r } from "@voltro/client";
4
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
5
+ //#region src/dataTable.tsx
6
+ var s = (e) => e == null ? "" : typeof e == "boolean" ? e ? "✓" : "✗" : String(e), c = (e, t) => e ? t === "asc" ? "ascending" : "descending" : "none";
7
+ function l({ row: e, columns: t, renderCell: n, rowActions: r }) {
8
+ return /* @__PURE__ */ o("tr", { children: [t.map((t) => /* @__PURE__ */ a("td", {
9
+ "data-column": t.name,
10
+ children: n ? n(e, t) : s(e[t.name])
11
+ }, t.name)), r ? /* @__PURE__ */ a("td", { children: r(e) }) : null] });
12
+ }
13
+ var u = t(l);
14
+ function d(t) {
15
+ let { api: s, query: l, emptyText: d, loadingText: f, loadMoreText: p, renderCell: m, rowActions: h, rowKey: g, ..._ } = t, v = e().dataTable, y = r(s, l, _), b = n(() => y.loading ? null : y.rows.map((e, t) => /* @__PURE__ */ a(u, {
16
+ row: e,
17
+ columns: y.columns,
18
+ renderCell: m,
19
+ rowActions: h
20
+ }, g ? g(e) : String(e.id ?? t))), [
21
+ y.loading,
22
+ y.rows,
23
+ y.columns,
24
+ m,
25
+ h,
26
+ g
27
+ ]);
28
+ return y.loading ? /* @__PURE__ */ a("p", {
29
+ "data-voltro-datatable-loading": !0,
30
+ "aria-busy": "true",
31
+ children: f ?? "Loading…"
32
+ }) : y.rows.length === 0 ? /* @__PURE__ */ a("p", {
33
+ "data-voltro-datatable-empty": !0,
34
+ children: d ?? "No rows."
35
+ }) : /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ o("table", {
36
+ "data-voltro-datatable": l,
37
+ children: [/* @__PURE__ */ a("thead", { children: /* @__PURE__ */ o("tr", { children: [y.columns.map((e) => {
38
+ let t = y.sort?.column === e.name, n = y.sort?.direction ?? "asc";
39
+ return /* @__PURE__ */ a("th", {
40
+ "aria-sort": c(t, n),
41
+ scope: "col",
42
+ children: /* @__PURE__ */ o("button", {
43
+ type: "button",
44
+ onClick: () => y.toggleSort(e.name),
45
+ children: [e.label, t ? n === "asc" ? " ▲" : " ▼" : ""]
46
+ })
47
+ }, e.name);
48
+ }), h ? /* @__PURE__ */ a("th", {
49
+ scope: "col",
50
+ children: v.actions
51
+ }) : null] }) }), /* @__PURE__ */ a("tbody", { children: b })]
52
+ }), y.hasMore ? /* @__PURE__ */ a("button", {
53
+ type: "button",
54
+ "data-voltro-datatable-more": !0,
55
+ onClick: () => y.loadMore(),
56
+ children: p ?? "Load more"
57
+ }) : null] });
58
+ }
59
+ //#endregion
60
+ export { d as DataTable };
@@ -0,0 +1,105 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { useQueryFilters as t } from "@voltro/client";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ //#region src/filters.tsx
5
+ var i = (e) => e == null ? "" : String(e);
6
+ function a(t) {
7
+ let { filter: a, value: o, onChange: s } = t, c = e().filters, l = {
8
+ "data-filter": a.name,
9
+ "aria-label": a.label
10
+ };
11
+ switch (a.kind) {
12
+ case "select": return /* @__PURE__ */ r("select", {
13
+ ...l,
14
+ value: i(o),
15
+ onChange: (e) => s(e.target.value || void 0),
16
+ children: [/* @__PURE__ */ n("option", {
17
+ value: "",
18
+ children: c.anyOption(a.label)
19
+ }), (a.options ?? []).map((e) => /* @__PURE__ */ n("option", {
20
+ value: e.value,
21
+ children: e.label
22
+ }, e.value))]
23
+ });
24
+ case "multi-select": return /* @__PURE__ */ n("select", {
25
+ ...l,
26
+ multiple: !0,
27
+ value: Array.isArray(o) ? o : [],
28
+ onChange: (e) => s(Array.from(e.target.selectedOptions, (e) => e.value)),
29
+ children: (a.options ?? []).map((e) => /* @__PURE__ */ n("option", {
30
+ value: e.value,
31
+ children: e.label
32
+ }, e.value))
33
+ });
34
+ case "boolean": return /* @__PURE__ */ n("input", {
35
+ ...l,
36
+ type: "checkbox",
37
+ checked: o === !0,
38
+ onChange: (e) => s(e.target.checked ? !0 : void 0)
39
+ });
40
+ case "number-range":
41
+ case "date-range": {
42
+ let e = a.kind === "number-range" ? "number" : "date", t = o ?? {};
43
+ return /* @__PURE__ */ r("span", {
44
+ "data-filter": a.name,
45
+ "data-range": a.kind,
46
+ children: [/* @__PURE__ */ n("input", {
47
+ "aria-label": `${a.label} from`,
48
+ type: e,
49
+ value: i(t.gte),
50
+ onChange: (e) => s({
51
+ ...t,
52
+ gte: e.target.value || void 0
53
+ })
54
+ }), /* @__PURE__ */ n("input", {
55
+ "aria-label": `${a.label} to`,
56
+ type: e,
57
+ value: i(t.lte),
58
+ onChange: (e) => s({
59
+ ...t,
60
+ lte: e.target.value || void 0
61
+ })
62
+ })]
63
+ });
64
+ }
65
+ default: return /* @__PURE__ */ n("input", {
66
+ ...l,
67
+ type: "text",
68
+ value: i(o),
69
+ onChange: (e) => s(e.target.value || void 0)
70
+ });
71
+ }
72
+ }
73
+ function o(i) {
74
+ let o = t(i.api, i.query, i.initial ? { initial: i.initial } : {}), s = e().filters;
75
+ return /* @__PURE__ */ r("div", {
76
+ "data-voltro-query-filters": i.query,
77
+ children: [/* @__PURE__ */ r("div", {
78
+ "data-filter-controls": !0,
79
+ role: "group",
80
+ "aria-label": s.filtersLabel,
81
+ children: [
82
+ o.filters.map((e) => /* @__PURE__ */ r("label", {
83
+ "data-filter-label": !0,
84
+ children: [/* @__PURE__ */ n("span", { children: e.label }), /* @__PURE__ */ n(a, {
85
+ filter: e,
86
+ value: o.values[e.name],
87
+ onChange: (t) => o.setFilter(e.name, t)
88
+ })]
89
+ }, e.name)),
90
+ /* @__PURE__ */ n("button", {
91
+ type: "button",
92
+ "data-filter-clear": !0,
93
+ onClick: () => o.clear(),
94
+ children: s.clear
95
+ }),
96
+ i.showCount ?? !0 ? /* @__PURE__ */ n("span", {
97
+ "data-filter-count": !0,
98
+ children: s.resultCount(o.count ?? "…")
99
+ }) : null
100
+ ]
101
+ }), i.children ? i.children(o) : null]
102
+ });
103
+ }
104
+ //#endregion
105
+ export { o as QueryFilters };
package/dist/index.d.ts CHANGED
@@ -105,7 +105,7 @@ export declare interface AutoFormProps<Input extends Record<string, unknown>, Ou
105
105
  readonly mutation: string;
106
106
  /** The mutation's input `Schema`. Optional — resolved from the mounted
107
107
  * descriptor's capability-map entry (`descriptors[tag].input`) when omitted. */
108
- readonly schema?: Schema.Schema.Any;
108
+ readonly schema?: Schema.Top;
109
109
  readonly defaults?: Partial<Input>;
110
110
  readonly onSuccess?: (output: Output) => void;
111
111
  readonly submitLabel?: string;