@voltro/ui 0.85.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.
- package/CHANGELOG.md +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- package/dist/agentChat.js +117 -0
- package/dist/appAgent.js +30 -0
- package/dist/asyncSelect.js +63 -0
- package/dist/autoForm.js +91 -0
- package/dist/commentsThread.js +163 -0
- package/dist/connectAccount.js +99 -0
- package/dist/dataCopilot.js +77 -0
- package/dist/dataTable.js +60 -0
- package/dist/filters.js +105 -0
- package/dist/index.js +17 -1408
- package/dist/presence.js +43 -0
- package/dist/recordView.js +52 -0
- package/dist/richText.js +81 -0
- package/dist/skeleton.js +52 -0
- package/dist/strings.js +136 -0
- package/dist/widgets.js +247 -0
- package/dist/workflow.js +92 -0
- package/package.json +3 -3
package/dist/presence.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defaultUiStrings as e, useUiStrings as t } from "./strings.js";
|
|
2
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
3
|
+
//#region src/presence.tsx
|
|
4
|
+
var i = (e, t) => {
|
|
5
|
+
let n = e.meta?.[t];
|
|
6
|
+
return typeof n == "string" ? n : void 0;
|
|
7
|
+
}, a = (e) => i(e, "name") ?? i(e, "displayName") ?? e.key, o = (e) => {
|
|
8
|
+
let t = e.trim().split(/\s+/).filter(Boolean);
|
|
9
|
+
return t.length === 0 ? "?" : t.length === 1 ? t[0].slice(0, 2).toUpperCase() : (t[0][0] + t[t.length - 1][0]).toUpperCase();
|
|
10
|
+
};
|
|
11
|
+
function s(e) {
|
|
12
|
+
let { members: i, max: s = 5, nameOf: c = a, renderAvatar: l } = e, u = t().presence, d = i.slice(0, s), f = i.length - d.length;
|
|
13
|
+
return /* @__PURE__ */ r("div", {
|
|
14
|
+
"data-voltro-presence-avatars": !0,
|
|
15
|
+
role: "group",
|
|
16
|
+
"aria-label": u.onlineCount(i.length),
|
|
17
|
+
children: [d.map((e) => {
|
|
18
|
+
let t = c(e);
|
|
19
|
+
return l ? /* @__PURE__ */ n("span", { children: l(e, t) }, e.key) : /* @__PURE__ */ n("span", {
|
|
20
|
+
"data-avatar": !0,
|
|
21
|
+
title: t,
|
|
22
|
+
"aria-label": t,
|
|
23
|
+
children: o(t)
|
|
24
|
+
}, e.key);
|
|
25
|
+
}), f > 0 ? /* @__PURE__ */ r("span", {
|
|
26
|
+
"data-avatar-overflow": !0,
|
|
27
|
+
"aria-label": u.moreOverflow(f),
|
|
28
|
+
children: ["+", f]
|
|
29
|
+
}) : null]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var c = (t, n, r = e.presence) => t.length === 0 ? "" : t.length === 1 ? r.editingOne(t[0], n) : t.length === 2 ? r.editingTwo(t[0], t[1], n) : r.editingMany(t[0], t.length - 1, n);
|
|
33
|
+
function l(e) {
|
|
34
|
+
let { members: r, selfKey: o, field: s, verb: l = "editing", nameOf: u = a } = e, d = t().presence, f = r.filter((e) => !(o !== void 0 && e.key === o || s !== void 0 && i(e, "field") !== s));
|
|
35
|
+
return f.length === 0 ? null : /* @__PURE__ */ n("span", {
|
|
36
|
+
"data-voltro-editing-indicator": !0,
|
|
37
|
+
"data-field": s,
|
|
38
|
+
role: "status",
|
|
39
|
+
children: c(f.map(u), l, d)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { l as EditingIndicator, s as PresenceAvatars, o as initials, c as summarizeEditors };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useUiStrings as e } from "./strings.js";
|
|
2
|
+
import { useRecord as t } from "@voltro/client";
|
|
3
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
+
//#region src/recordView.tsx
|
|
5
|
+
var i = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), a = (e) => Array.isArray(e) && e.every((e) => typeof e == "object" && !!e), o = (e) => e == null ? "—" : typeof e == "boolean" ? e ? "✓" : "✗" : String(e);
|
|
6
|
+
function s({ name: t, items: a }) {
|
|
7
|
+
let s = e().recordView;
|
|
8
|
+
if (a.length === 0) return /* @__PURE__ */ n("p", {
|
|
9
|
+
"data-relation": t,
|
|
10
|
+
"data-empty": !0,
|
|
11
|
+
children: s.emptyRelation(i(t).toLowerCase())
|
|
12
|
+
});
|
|
13
|
+
let c = Object.keys(a[0]);
|
|
14
|
+
return /* @__PURE__ */ r("table", {
|
|
15
|
+
"data-relation": t,
|
|
16
|
+
children: [/* @__PURE__ */ n("thead", { children: /* @__PURE__ */ n("tr", { children: c.map((e) => /* @__PURE__ */ n("th", {
|
|
17
|
+
scope: "col",
|
|
18
|
+
children: i(e)
|
|
19
|
+
}, e)) }) }), /* @__PURE__ */ n("tbody", { children: a.map((e, t) => /* @__PURE__ */ n("tr", { children: c.map((t) => /* @__PURE__ */ n("td", { children: o(e[t]) }, t)) }, String(e.id ?? t))) })]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function c(e) {
|
|
23
|
+
let { api: c, query: l, input: u, fields: d, renderField: f, renderRelation: p, loadingText: m, emptyText: h } = e, { record: g, loading: _ } = t(c, l, u ?? {});
|
|
24
|
+
if (_) return /* @__PURE__ */ n("p", {
|
|
25
|
+
"data-voltro-record-loading": !0,
|
|
26
|
+
"aria-busy": "true",
|
|
27
|
+
children: m ?? "Loading…"
|
|
28
|
+
});
|
|
29
|
+
if (g == null) return /* @__PURE__ */ n("p", {
|
|
30
|
+
"data-voltro-record-empty": !0,
|
|
31
|
+
children: h ?? "Not found."
|
|
32
|
+
});
|
|
33
|
+
let v = Object.entries(g), y = v.filter(([e, t]) => !a(t) && (d === void 0 || d.includes(e))), b = v.filter(([, e]) => a(e)), x = d === void 0 ? y : d.map((e) => [e, g[e]]).filter(([, e]) => !a(e));
|
|
34
|
+
return /* @__PURE__ */ r("div", {
|
|
35
|
+
"data-voltro-record-view": l,
|
|
36
|
+
children: [/* @__PURE__ */ n("dl", {
|
|
37
|
+
"data-record-fields": !0,
|
|
38
|
+
children: x.map(([e, t]) => /* @__PURE__ */ r("div", {
|
|
39
|
+
"data-field": e,
|
|
40
|
+
children: [/* @__PURE__ */ n("dt", { children: i(e) }), /* @__PURE__ */ n("dd", { children: f ? f(e, t, g) : o(t) })]
|
|
41
|
+
}, e))
|
|
42
|
+
}), b.map(([e, t]) => /* @__PURE__ */ r("section", {
|
|
43
|
+
"data-record-relation": e,
|
|
44
|
+
children: [/* @__PURE__ */ n("h3", { children: i(e) }), p ? p(e, t, g) : /* @__PURE__ */ n(s, {
|
|
45
|
+
name: e,
|
|
46
|
+
items: t
|
|
47
|
+
})]
|
|
48
|
+
}, e))]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { c as RecordView };
|
package/dist/richText.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Fragment as e, useEffect as t, useId as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import { isRichTextDocument as a, isSafeHref as o, parseRichText as s, serializeRichText as c } from "@voltro/client";
|
|
3
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
4
|
+
//#region src/richText.tsx
|
|
5
|
+
var f = (t, n) => {
|
|
6
|
+
let r = t.marks ?? [], i = t.text;
|
|
7
|
+
return r.includes("code") && (i = /* @__PURE__ */ u("code", { children: i }, n)), r.includes("italic") && (i = /* @__PURE__ */ u("em", { children: i }, n)), r.includes("strike") && (i = /* @__PURE__ */ u("s", { children: i }, n)), r.includes("bold") && (i = /* @__PURE__ */ u("strong", { children: i }, n)), /* @__PURE__ */ u(e, { children: i }, n);
|
|
8
|
+
}, p = (t) => t.map((t, n) => {
|
|
9
|
+
if (t.type === "link") {
|
|
10
|
+
let r = t.content.map((e) => e.text).join("");
|
|
11
|
+
return o(t.href) ? /* @__PURE__ */ u("a", {
|
|
12
|
+
href: t.href,
|
|
13
|
+
rel: "noopener noreferrer nofollow",
|
|
14
|
+
children: r
|
|
15
|
+
}, n) : /* @__PURE__ */ u(e, { children: r }, n);
|
|
16
|
+
}
|
|
17
|
+
return f(t, n);
|
|
18
|
+
}), m = (e, t) => {
|
|
19
|
+
switch (e.type) {
|
|
20
|
+
case "heading": {
|
|
21
|
+
let n = [
|
|
22
|
+
"h1",
|
|
23
|
+
"h2",
|
|
24
|
+
"h3"
|
|
25
|
+
][e.level - 1] ?? "h3";
|
|
26
|
+
return /* @__PURE__ */ u(n, { children: p(e.content) }, t);
|
|
27
|
+
}
|
|
28
|
+
case "blockquote": return /* @__PURE__ */ u("blockquote", { children: p(e.content) }, t);
|
|
29
|
+
case "bulletList": return /* @__PURE__ */ u("ul", { children: e.content.map((e, t) => /* @__PURE__ */ u("li", { children: p(e.content) }, t)) }, t);
|
|
30
|
+
case "orderedList": return /* @__PURE__ */ u("ol", { children: e.content.map((e, t) => /* @__PURE__ */ u("li", { children: p(e.content) }, t)) }, t);
|
|
31
|
+
case "codeBlock": return /* @__PURE__ */ u("pre", { children: /* @__PURE__ */ u("code", { children: e.text }) }, t);
|
|
32
|
+
default: return /* @__PURE__ */ u("p", { children: p(e.content) }, t);
|
|
33
|
+
}
|
|
34
|
+
}, h = (e) => a(e.doc) ? /* @__PURE__ */ u(l, { children: e.doc.content.map((e, t) => m(e, t)) }) : null, g = (e) => {
|
|
35
|
+
let a = n(), [o, l] = i(() => c(e.value)), f = r(e.value);
|
|
36
|
+
t(() => {
|
|
37
|
+
e.value !== f.current && JSON.stringify(e.value) !== JSON.stringify(f.current) && (f.current = e.value, l(c(e.value)));
|
|
38
|
+
}, [e.value]);
|
|
39
|
+
let p = [e.description === void 0 ? "" : `${a}-desc`, e.error === void 0 ? "" : `${a}-error`].filter(Boolean).join(" ");
|
|
40
|
+
return /* @__PURE__ */ d("div", {
|
|
41
|
+
"data-voltro-field": !0,
|
|
42
|
+
"data-voltro-rich-text": !0,
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ d("label", {
|
|
45
|
+
htmlFor: a,
|
|
46
|
+
children: [e.label, e.required ? /* @__PURE__ */ u("span", {
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
children: " *"
|
|
49
|
+
}) : null]
|
|
50
|
+
}),
|
|
51
|
+
e.description === void 0 ? null : /* @__PURE__ */ u("p", {
|
|
52
|
+
id: `${a}-desc`,
|
|
53
|
+
"data-voltro-field-hint": !0,
|
|
54
|
+
children: e.description
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ u("textarea", {
|
|
57
|
+
id: a,
|
|
58
|
+
name: e.name,
|
|
59
|
+
value: o,
|
|
60
|
+
onChange: (t) => {
|
|
61
|
+
l(t.target.value);
|
|
62
|
+
let n = s(t.target.value);
|
|
63
|
+
f.current = n, e.onChange(n);
|
|
64
|
+
},
|
|
65
|
+
onBlur: e.onBlur,
|
|
66
|
+
disabled: e.disabled,
|
|
67
|
+
required: e.required,
|
|
68
|
+
"aria-required": e.required ? !0 : void 0,
|
|
69
|
+
"aria-invalid": e.error !== void 0,
|
|
70
|
+
"aria-describedby": p === "" ? void 0 : p
|
|
71
|
+
}),
|
|
72
|
+
e.error === void 0 ? null : /* @__PURE__ */ u("p", {
|
|
73
|
+
id: `${a}-error`,
|
|
74
|
+
role: "alert",
|
|
75
|
+
children: e.error
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { h as RichTextView, g as RichTextWidget };
|
package/dist/skeleton.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { formSections as e, useFormSkeleton as t, useTableSkeleton as n } from "@voltro/client";
|
|
2
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
3
|
+
//#region src/skeleton.tsx
|
|
4
|
+
var a = ({ w: e }) => /* @__PURE__ */ r("span", {
|
|
5
|
+
"data-skeleton-bar": !0,
|
|
6
|
+
style: {
|
|
7
|
+
display: "inline-block",
|
|
8
|
+
width: e ?? "100%",
|
|
9
|
+
height: "1em",
|
|
10
|
+
borderRadius: 4
|
|
11
|
+
},
|
|
12
|
+
"aria-hidden": "true"
|
|
13
|
+
});
|
|
14
|
+
function o(n) {
|
|
15
|
+
let o = t(n.api, n.mutation), s = o.length > 0 ? o.length : n.fallbackFields ?? 3, c = o.length > 0 ? e(o) : [{
|
|
16
|
+
name: void 0,
|
|
17
|
+
label: void 0,
|
|
18
|
+
fields: Array.from({ length: s }, (e, t) => ({ name: `f${t}` }))
|
|
19
|
+
}];
|
|
20
|
+
return /* @__PURE__ */ r("div", {
|
|
21
|
+
"data-voltro-form-skeleton": n.mutation,
|
|
22
|
+
"aria-busy": "true",
|
|
23
|
+
"aria-hidden": "true",
|
|
24
|
+
children: c.map((e, t) => /* @__PURE__ */ i("div", {
|
|
25
|
+
...e.name === void 0 ? {} : { "data-skeleton-section": e.name },
|
|
26
|
+
children: [e.name !== void 0 && /* @__PURE__ */ r("div", {
|
|
27
|
+
"data-skeleton-section-title": !0,
|
|
28
|
+
children: /* @__PURE__ */ r(a, { w: "40%" })
|
|
29
|
+
}), e.fields.map((e) => /* @__PURE__ */ i("div", {
|
|
30
|
+
"data-skeleton-field": !0,
|
|
31
|
+
children: [/* @__PURE__ */ r(a, { w: "30%" }), /* @__PURE__ */ r(a, {})]
|
|
32
|
+
}, e.name))]
|
|
33
|
+
}, e.name ?? `_${t}`))
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function s(e) {
|
|
37
|
+
let t = n(e.api, e.query), o = t.length > 0 ? t.length : e.fallbackColumns ?? 4, s = t.length > 0 ? t.map((e) => e.name) : Array.from({ length: o }, (e, t) => `c${t}`), c = e.rows ?? 5;
|
|
38
|
+
return /* @__PURE__ */ i("table", {
|
|
39
|
+
"data-voltro-table-skeleton": e.query,
|
|
40
|
+
"aria-busy": "true",
|
|
41
|
+
"aria-hidden": "true",
|
|
42
|
+
children: [/* @__PURE__ */ r("thead", { children: /* @__PURE__ */ r("tr", { children: s.map((e) => /* @__PURE__ */ r("th", {
|
|
43
|
+
scope: "col",
|
|
44
|
+
children: /* @__PURE__ */ r(a, { w: "60%" })
|
|
45
|
+
}, e)) }) }), /* @__PURE__ */ r("tbody", { children: Array.from({ length: c }, (e, t) => /* @__PURE__ */ r("tr", {
|
|
46
|
+
"data-skeleton-row": !0,
|
|
47
|
+
children: s.map((e) => /* @__PURE__ */ r("td", { children: /* @__PURE__ */ r(a, {}) }, e))
|
|
48
|
+
}, t)) })]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { o as FormSkeleton, s as TableSkeleton };
|
package/dist/strings.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createContext as e, useContext as t, useMemo as n } from "react";
|
|
2
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
3
|
+
//#region src/strings.tsx
|
|
4
|
+
var i = {
|
|
5
|
+
filters: {
|
|
6
|
+
clear: "Clear",
|
|
7
|
+
filtersLabel: "Filters",
|
|
8
|
+
anyOption: (e) => `Any ${e}`,
|
|
9
|
+
resultCount: (e) => `${e} results`
|
|
10
|
+
},
|
|
11
|
+
asyncSelect: {
|
|
12
|
+
searchPlaceholder: "Search…",
|
|
13
|
+
searchLabel: (e) => `Search ${e}`,
|
|
14
|
+
loading: "Loading…",
|
|
15
|
+
empty: "—"
|
|
16
|
+
},
|
|
17
|
+
dataTable: { actions: "Actions" },
|
|
18
|
+
workflow: {
|
|
19
|
+
status: {
|
|
20
|
+
running: "Running",
|
|
21
|
+
succeeded: "Succeeded",
|
|
22
|
+
failed: "Failed",
|
|
23
|
+
cancelled: "Cancelled",
|
|
24
|
+
suspended: "Waiting"
|
|
25
|
+
},
|
|
26
|
+
attempt: (e) => `attempt ${e}`,
|
|
27
|
+
loading: "Loading…",
|
|
28
|
+
empty: "No steps yet."
|
|
29
|
+
},
|
|
30
|
+
agentChat: {
|
|
31
|
+
reasoning: "Reasoning",
|
|
32
|
+
messagePlaceholder: "Message…",
|
|
33
|
+
messageLabel: "Message",
|
|
34
|
+
send: "Send"
|
|
35
|
+
},
|
|
36
|
+
comments: {
|
|
37
|
+
comment: "Comment",
|
|
38
|
+
reply: "Reply",
|
|
39
|
+
replyPlaceholder: "Reply… (@name to mention)",
|
|
40
|
+
replyLabel: "Reply",
|
|
41
|
+
newPlaceholder: "Start a discussion… (@name to mention)",
|
|
42
|
+
newLabel: "New comment",
|
|
43
|
+
resolve: "Resolve",
|
|
44
|
+
reopen: "Reopen",
|
|
45
|
+
markRead: "Mark read",
|
|
46
|
+
edit: "Edit",
|
|
47
|
+
edited: "edited",
|
|
48
|
+
editLabel: "Edit comment",
|
|
49
|
+
save: "Save",
|
|
50
|
+
remove: "Delete",
|
|
51
|
+
react: "React"
|
|
52
|
+
},
|
|
53
|
+
appAgent: {
|
|
54
|
+
toolsSummary: (e) => `${e} tools · acts as you`,
|
|
55
|
+
needsConfirm: "needs confirm"
|
|
56
|
+
},
|
|
57
|
+
presence: {
|
|
58
|
+
moreOverflow: (e) => `${e} more`,
|
|
59
|
+
onlineCount: (e) => `${e} online`,
|
|
60
|
+
editingOne: (e, t) => `${e} is ${t}`,
|
|
61
|
+
editingTwo: (e, t, n) => `${e} and ${t} are ${n}`,
|
|
62
|
+
editingMany: (e, t, n) => `${e} and ${t} others are ${n}`
|
|
63
|
+
},
|
|
64
|
+
recordView: { emptyRelation: (e) => `No ${e}.` },
|
|
65
|
+
connectAccount: {
|
|
66
|
+
connect: (e) => `Connect ${e}`,
|
|
67
|
+
disconnect: "Disconnect",
|
|
68
|
+
reconnect: "Reconnect",
|
|
69
|
+
connectedAs: (e) => `Connected as ${e}`,
|
|
70
|
+
connected: "Connected",
|
|
71
|
+
notConnected: "Not connected",
|
|
72
|
+
expired: "Expired — reconnect to continue",
|
|
73
|
+
revoked: "Access was revoked — reconnect to continue",
|
|
74
|
+
errored: "Could not refresh — retrying",
|
|
75
|
+
tokenLabel: (e) => `${e} personal access token`,
|
|
76
|
+
tokenPlaceholder: "Paste your token…",
|
|
77
|
+
save: "Save",
|
|
78
|
+
howToGetToken: "How do I get a token?",
|
|
79
|
+
loading: "Loading…"
|
|
80
|
+
}
|
|
81
|
+
}, a = e(i), o = (e, t) => ({
|
|
82
|
+
filters: {
|
|
83
|
+
...e.filters,
|
|
84
|
+
...t.filters
|
|
85
|
+
},
|
|
86
|
+
asyncSelect: {
|
|
87
|
+
...e.asyncSelect,
|
|
88
|
+
...t.asyncSelect
|
|
89
|
+
},
|
|
90
|
+
dataTable: {
|
|
91
|
+
...e.dataTable,
|
|
92
|
+
...t.dataTable
|
|
93
|
+
},
|
|
94
|
+
workflow: {
|
|
95
|
+
...e.workflow,
|
|
96
|
+
...t.workflow,
|
|
97
|
+
status: {
|
|
98
|
+
...e.workflow.status,
|
|
99
|
+
...t.workflow?.status
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
agentChat: {
|
|
103
|
+
...e.agentChat,
|
|
104
|
+
...t.agentChat
|
|
105
|
+
},
|
|
106
|
+
comments: {
|
|
107
|
+
...e.comments,
|
|
108
|
+
...t.comments
|
|
109
|
+
},
|
|
110
|
+
appAgent: {
|
|
111
|
+
...e.appAgent,
|
|
112
|
+
...t.appAgent
|
|
113
|
+
},
|
|
114
|
+
presence: {
|
|
115
|
+
...e.presence,
|
|
116
|
+
...t.presence
|
|
117
|
+
},
|
|
118
|
+
recordView: {
|
|
119
|
+
...e.recordView,
|
|
120
|
+
...t.recordView
|
|
121
|
+
},
|
|
122
|
+
connectAccount: {
|
|
123
|
+
...e.connectAccount,
|
|
124
|
+
...t.connectAccount
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
function s(e) {
|
|
128
|
+
let i = t(a), s = n(() => o(i, e.strings), [i, e.strings]);
|
|
129
|
+
return /* @__PURE__ */ r(a.Provider, {
|
|
130
|
+
value: s,
|
|
131
|
+
children: e.children
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
var c = () => t(a);
|
|
135
|
+
//#endregion
|
|
136
|
+
export { s as UiStringsProvider, i as defaultUiStrings, c as useUiStrings };
|
package/dist/widgets.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { RichTextWidget as e } from "./richText.js";
|
|
2
|
+
import { createContext as t, useContext as n, useId as r, useMemo as i } from "react";
|
|
3
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
4
|
+
//#region src/widgets.tsx
|
|
5
|
+
var s = (e) => e == null ? "" : String(e), c = ({ required: e }) => e ? /* @__PURE__ */ a("span", {
|
|
6
|
+
"aria-hidden": "true",
|
|
7
|
+
children: " *"
|
|
8
|
+
}) : null, l = (e) => /* @__PURE__ */ o("div", {
|
|
9
|
+
"data-voltro-field": !0,
|
|
10
|
+
children: [
|
|
11
|
+
/* @__PURE__ */ o("label", {
|
|
12
|
+
htmlFor: e.id,
|
|
13
|
+
children: [e.label, /* @__PURE__ */ a(c, { required: e.required })]
|
|
14
|
+
}),
|
|
15
|
+
e.description === void 0 ? null : /* @__PURE__ */ a("p", {
|
|
16
|
+
id: `${e.id}-desc`,
|
|
17
|
+
"data-voltro-field-hint": !0,
|
|
18
|
+
children: e.description
|
|
19
|
+
}),
|
|
20
|
+
e.children,
|
|
21
|
+
e.error === void 0 ? null : /* @__PURE__ */ a("p", {
|
|
22
|
+
id: `${e.id}-error`,
|
|
23
|
+
role: "alert",
|
|
24
|
+
children: e.error
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
}), u = (e, t, n) => {
|
|
28
|
+
let r = [t === void 0 ? "" : `${e}-desc`, n === void 0 ? "" : `${e}-error`].filter(Boolean);
|
|
29
|
+
return r.length > 0 ? r.join(" ") : void 0;
|
|
30
|
+
}, d = (e) => e ? !0 : void 0, f = (e, t) => (n) => {
|
|
31
|
+
let i = r();
|
|
32
|
+
return /* @__PURE__ */ a(l, {
|
|
33
|
+
id: i,
|
|
34
|
+
label: n.label,
|
|
35
|
+
required: n.required,
|
|
36
|
+
description: n.description,
|
|
37
|
+
error: n.error,
|
|
38
|
+
children: /* @__PURE__ */ a("input", {
|
|
39
|
+
id: i,
|
|
40
|
+
type: e,
|
|
41
|
+
name: n.name,
|
|
42
|
+
value: s(n.value),
|
|
43
|
+
onChange: (e) => n.onChange(t(e.target.value)),
|
|
44
|
+
onBlur: n.onBlur,
|
|
45
|
+
disabled: n.disabled,
|
|
46
|
+
required: n.required,
|
|
47
|
+
"aria-required": d(n.required),
|
|
48
|
+
"aria-invalid": n.error !== void 0,
|
|
49
|
+
"aria-describedby": u(i, n.description, n.error)
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}, p = (e) => {
|
|
53
|
+
let t = r();
|
|
54
|
+
return /* @__PURE__ */ a(l, {
|
|
55
|
+
id: t,
|
|
56
|
+
label: e.label,
|
|
57
|
+
required: e.required,
|
|
58
|
+
description: e.description,
|
|
59
|
+
error: e.error,
|
|
60
|
+
children: /* @__PURE__ */ a("textarea", {
|
|
61
|
+
id: t,
|
|
62
|
+
name: e.name,
|
|
63
|
+
value: s(e.value),
|
|
64
|
+
onChange: (t) => e.onChange(t.target.value),
|
|
65
|
+
disabled: e.disabled,
|
|
66
|
+
onBlur: e.onBlur,
|
|
67
|
+
required: e.required,
|
|
68
|
+
"aria-required": d(e.required),
|
|
69
|
+
"aria-invalid": e.error !== void 0,
|
|
70
|
+
"aria-describedby": u(t, e.description, e.error)
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}, m = (e) => {
|
|
74
|
+
let t = r();
|
|
75
|
+
return /* @__PURE__ */ a(l, {
|
|
76
|
+
id: t,
|
|
77
|
+
label: e.label,
|
|
78
|
+
required: e.required,
|
|
79
|
+
description: e.description,
|
|
80
|
+
error: e.error,
|
|
81
|
+
children: /* @__PURE__ */ a("input", {
|
|
82
|
+
id: t,
|
|
83
|
+
type: "checkbox",
|
|
84
|
+
name: e.name,
|
|
85
|
+
checked: e.value === !0,
|
|
86
|
+
onChange: (t) => e.onChange(t.target.checked),
|
|
87
|
+
disabled: e.disabled,
|
|
88
|
+
onBlur: e.onBlur,
|
|
89
|
+
"aria-required": d(e.required),
|
|
90
|
+
"aria-invalid": e.error !== void 0,
|
|
91
|
+
"aria-describedby": u(t, e.description, e.error)
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
}, h = (e) => {
|
|
95
|
+
let t = r();
|
|
96
|
+
return /* @__PURE__ */ a(l, {
|
|
97
|
+
id: t,
|
|
98
|
+
label: e.label,
|
|
99
|
+
required: e.required,
|
|
100
|
+
description: e.description,
|
|
101
|
+
error: e.error,
|
|
102
|
+
children: /* @__PURE__ */ o("select", {
|
|
103
|
+
id: t,
|
|
104
|
+
name: e.name,
|
|
105
|
+
value: s(e.value),
|
|
106
|
+
onChange: (t) => e.onChange(t.target.value),
|
|
107
|
+
disabled: e.disabled,
|
|
108
|
+
onBlur: e.onBlur,
|
|
109
|
+
required: e.required,
|
|
110
|
+
"aria-required": d(e.required),
|
|
111
|
+
"aria-invalid": e.error !== void 0,
|
|
112
|
+
"aria-describedby": u(t, e.description, e.error),
|
|
113
|
+
children: [/* @__PURE__ */ a("option", {
|
|
114
|
+
value: "",
|
|
115
|
+
children: "—"
|
|
116
|
+
}), (e.options ?? []).map((e) => /* @__PURE__ */ a("option", {
|
|
117
|
+
value: e.value,
|
|
118
|
+
children: e.label
|
|
119
|
+
}, e.value))]
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
}, g = (e) => {
|
|
123
|
+
let t = r();
|
|
124
|
+
return /* @__PURE__ */ o("fieldset", {
|
|
125
|
+
"data-voltro-field": !0,
|
|
126
|
+
"aria-invalid": e.error !== void 0,
|
|
127
|
+
"aria-required": d(e.required),
|
|
128
|
+
"aria-describedby": u(t, e.description, e.error),
|
|
129
|
+
children: [
|
|
130
|
+
/* @__PURE__ */ o("legend", { children: [e.label, /* @__PURE__ */ a(c, { required: e.required })] }),
|
|
131
|
+
e.description === void 0 ? null : /* @__PURE__ */ a("p", {
|
|
132
|
+
id: `${t}-desc`,
|
|
133
|
+
"data-voltro-field-hint": !0,
|
|
134
|
+
children: e.description
|
|
135
|
+
}),
|
|
136
|
+
(e.options ?? []).map((n) => {
|
|
137
|
+
let r = `${t}-${n.value}`;
|
|
138
|
+
return /* @__PURE__ */ o("span", { children: [/* @__PURE__ */ a("input", {
|
|
139
|
+
id: r,
|
|
140
|
+
type: "radio",
|
|
141
|
+
name: e.name,
|
|
142
|
+
value: n.value,
|
|
143
|
+
checked: s(e.value) === n.value,
|
|
144
|
+
onChange: () => e.onChange(n.value),
|
|
145
|
+
disabled: e.disabled,
|
|
146
|
+
onBlur: e.onBlur
|
|
147
|
+
}), /* @__PURE__ */ a("label", {
|
|
148
|
+
htmlFor: r,
|
|
149
|
+
children: n.label
|
|
150
|
+
})] }, n.value);
|
|
151
|
+
}),
|
|
152
|
+
e.error === void 0 ? null : /* @__PURE__ */ a("p", {
|
|
153
|
+
id: `${t}-error`,
|
|
154
|
+
role: "alert",
|
|
155
|
+
children: e.error
|
|
156
|
+
})
|
|
157
|
+
]
|
|
158
|
+
});
|
|
159
|
+
}, _ = (e) => {
|
|
160
|
+
let t = r(), n = Array.isArray(e.value) ? e.value.map(String) : [];
|
|
161
|
+
return /* @__PURE__ */ a(l, {
|
|
162
|
+
id: t,
|
|
163
|
+
label: e.label,
|
|
164
|
+
required: e.required,
|
|
165
|
+
description: e.description,
|
|
166
|
+
error: e.error,
|
|
167
|
+
children: /* @__PURE__ */ a("select", {
|
|
168
|
+
id: t,
|
|
169
|
+
name: e.name,
|
|
170
|
+
multiple: !0,
|
|
171
|
+
value: n,
|
|
172
|
+
onChange: (t) => e.onChange(Array.from(t.target.selectedOptions, (e) => e.value)),
|
|
173
|
+
disabled: e.disabled,
|
|
174
|
+
onBlur: e.onBlur,
|
|
175
|
+
"aria-required": d(e.required),
|
|
176
|
+
"aria-invalid": e.error !== void 0,
|
|
177
|
+
"aria-describedby": u(t, e.description, e.error),
|
|
178
|
+
children: (e.options ?? []).map((e) => /* @__PURE__ */ a("option", {
|
|
179
|
+
value: e.value,
|
|
180
|
+
children: e.label
|
|
181
|
+
}, e.value))
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
}, v = (e) => /* @__PURE__ */ a("input", {
|
|
185
|
+
type: "hidden",
|
|
186
|
+
name: e.name,
|
|
187
|
+
value: s(e.value),
|
|
188
|
+
readOnly: !0
|
|
189
|
+
}), y = (e) => {
|
|
190
|
+
let t = r();
|
|
191
|
+
return /* @__PURE__ */ a(l, {
|
|
192
|
+
id: t,
|
|
193
|
+
label: e.label,
|
|
194
|
+
required: e.required,
|
|
195
|
+
description: e.description,
|
|
196
|
+
error: e.error,
|
|
197
|
+
children: /* @__PURE__ */ a("input", {
|
|
198
|
+
id: t,
|
|
199
|
+
type: "file",
|
|
200
|
+
name: e.name,
|
|
201
|
+
onChange: (t) => e.onChange(t.target.files?.[0] ?? null),
|
|
202
|
+
disabled: e.disabled,
|
|
203
|
+
onBlur: e.onBlur,
|
|
204
|
+
required: e.required,
|
|
205
|
+
"aria-required": d(e.required),
|
|
206
|
+
"aria-invalid": e.error !== void 0,
|
|
207
|
+
"aria-describedby": u(t, e.description, e.error)
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
}, b = (e) => /* @__PURE__ */ o("div", {
|
|
211
|
+
"data-voltro-field": !0,
|
|
212
|
+
"data-voltro-custom": !0,
|
|
213
|
+
children: [/* @__PURE__ */ o("label", { children: [e.label, /* @__PURE__ */ a(c, { required: e.required })] }), /* @__PURE__ */ a("p", {
|
|
214
|
+
role: "note",
|
|
215
|
+
children: `No default widget for "${e.name}" — provide a render-prop via <Field>.`
|
|
216
|
+
})]
|
|
217
|
+
}), x = {
|
|
218
|
+
text: f("text", (e) => e),
|
|
219
|
+
number: f("number", (e) => e === "" ? void 0 : Number(e)),
|
|
220
|
+
date: f("date", (e) => e),
|
|
221
|
+
datetime: f("datetime-local", (e) => e),
|
|
222
|
+
daterange: f("text", (e) => e),
|
|
223
|
+
file: y,
|
|
224
|
+
"async-select": f("text", (e) => e),
|
|
225
|
+
textarea: p,
|
|
226
|
+
"rich-text": e,
|
|
227
|
+
checkbox: m,
|
|
228
|
+
switch: m,
|
|
229
|
+
select: h,
|
|
230
|
+
radio: g,
|
|
231
|
+
"multi-select": _,
|
|
232
|
+
hidden: v,
|
|
233
|
+
array: b,
|
|
234
|
+
reference: b,
|
|
235
|
+
custom: b
|
|
236
|
+
}, S = t({}), C = (e) => {
|
|
237
|
+
let t = n(S), r = i(() => ({
|
|
238
|
+
...t,
|
|
239
|
+
...e.widgets
|
|
240
|
+
}), [t, e.widgets]);
|
|
241
|
+
return /* @__PURE__ */ a(S.Provider, {
|
|
242
|
+
value: r,
|
|
243
|
+
children: e.children
|
|
244
|
+
});
|
|
245
|
+
}, w = (e) => n(S)[e] ?? x[e] ?? x.custom;
|
|
246
|
+
//#endregion
|
|
247
|
+
export { C as WidgetRegistryProvider, x as defaultWidgets, w as useWidget };
|