schema-components 1.9.1 → 1.10.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/dist/themes/radix.d.mts +21 -0
- package/dist/themes/radix.mjs +162 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { b as ComponentResolver } from "../types-BJzEgJdX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/themes/radix.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Register real Radix Themes components for the resolver to use.
|
|
6
|
+
* Call once at app startup before rendering.
|
|
7
|
+
*/
|
|
8
|
+
declare function registerRadixComponents(components: {
|
|
9
|
+
Box: React.ElementType;
|
|
10
|
+
Checkbox: React.ElementType;
|
|
11
|
+
Flex: React.ElementType;
|
|
12
|
+
SelectRoot: React.ElementType;
|
|
13
|
+
SelectTrigger: React.ElementType;
|
|
14
|
+
SelectContent: React.ElementType;
|
|
15
|
+
SelectItem: React.ElementType;
|
|
16
|
+
Text: React.ElementType;
|
|
17
|
+
TextField: React.ElementType;
|
|
18
|
+
}): void;
|
|
19
|
+
declare const radixResolver: ComponentResolver;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { radixResolver, registerRadixComponents };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { isObject } from "../core/guards.mjs";
|
|
2
|
+
import { headlessResolver, toReactNode } from "../react/headless.mjs";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/themes/radix.tsx
|
|
5
|
+
function getLabel(props) {
|
|
6
|
+
if (typeof props.meta.description === "string") return props.meta.description;
|
|
7
|
+
}
|
|
8
|
+
function stripChildren(props) {
|
|
9
|
+
const rest = { ...props };
|
|
10
|
+
if ("children" in rest) delete rest.children;
|
|
11
|
+
return rest;
|
|
12
|
+
}
|
|
13
|
+
let RadixBox = (props) => /* @__PURE__ */ jsx("div", { ...props });
|
|
14
|
+
let RadixCheckbox = (props) => /* @__PURE__ */ jsx("input", {
|
|
15
|
+
type: "checkbox",
|
|
16
|
+
...stripChildren(props)
|
|
17
|
+
});
|
|
18
|
+
let RadixFlex = (props) => /* @__PURE__ */ jsx("div", { ...props });
|
|
19
|
+
let RadixSelectRoot = (props) => /* @__PURE__ */ jsx("select", { ...props });
|
|
20
|
+
let RadixSelectTrigger = (props) => /* @__PURE__ */ jsx("span", { ...props });
|
|
21
|
+
let RadixSelectContent = (props) => /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
22
|
+
let RadixSelectItem = (props) => /* @__PURE__ */ jsx("option", { ...props });
|
|
23
|
+
let RadixText = (props) => /* @__PURE__ */ jsx("span", { ...props });
|
|
24
|
+
let RadixTextField = (props) => /* @__PURE__ */ jsx("input", { ...stripChildren(props) });
|
|
25
|
+
/**
|
|
26
|
+
* Register real Radix Themes components for the resolver to use.
|
|
27
|
+
* Call once at app startup before rendering.
|
|
28
|
+
*/
|
|
29
|
+
function registerRadixComponents(components) {
|
|
30
|
+
RadixBox = components.Box;
|
|
31
|
+
RadixCheckbox = components.Checkbox;
|
|
32
|
+
RadixFlex = components.Flex;
|
|
33
|
+
RadixSelectRoot = components.SelectRoot;
|
|
34
|
+
RadixSelectTrigger = components.SelectTrigger;
|
|
35
|
+
RadixSelectContent = components.SelectContent;
|
|
36
|
+
RadixSelectItem = components.SelectItem;
|
|
37
|
+
RadixText = components.Text;
|
|
38
|
+
RadixTextField = components.TextField;
|
|
39
|
+
}
|
|
40
|
+
function renderStringInput(props) {
|
|
41
|
+
const strValue = typeof props.value === "string" ? props.value : "";
|
|
42
|
+
const label = getLabel(props);
|
|
43
|
+
if (props.readOnly) return /* @__PURE__ */ jsx(RadixText, { children: strValue || "—" });
|
|
44
|
+
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
45
|
+
as: "label",
|
|
46
|
+
size: "2",
|
|
47
|
+
weight: "medium",
|
|
48
|
+
children: label
|
|
49
|
+
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
50
|
+
type: props.constraints.format === "email" ? "email" : props.constraints.format === "uri" ? "url" : "text",
|
|
51
|
+
value: props.writeOnly ? "" : strValue,
|
|
52
|
+
onChange: (e) => {
|
|
53
|
+
props.onChange(e.target.value);
|
|
54
|
+
},
|
|
55
|
+
mt: "1"
|
|
56
|
+
})] });
|
|
57
|
+
}
|
|
58
|
+
function renderNumberInput(props) {
|
|
59
|
+
const label = getLabel(props);
|
|
60
|
+
if (props.readOnly) {
|
|
61
|
+
if (typeof props.value !== "number") return /* @__PURE__ */ jsx(RadixText, { children: "—" });
|
|
62
|
+
return /* @__PURE__ */ jsx(RadixText, { children: props.value.toLocaleString() });
|
|
63
|
+
}
|
|
64
|
+
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
65
|
+
as: "label",
|
|
66
|
+
size: "2",
|
|
67
|
+
weight: "medium",
|
|
68
|
+
children: label
|
|
69
|
+
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
70
|
+
type: "number",
|
|
71
|
+
value: props.writeOnly ? "" : typeof props.value === "number" ? props.value : "",
|
|
72
|
+
onChange: (e) => {
|
|
73
|
+
props.onChange(Number(e.target.value));
|
|
74
|
+
},
|
|
75
|
+
mt: "1"
|
|
76
|
+
})] });
|
|
77
|
+
}
|
|
78
|
+
function renderBooleanInput(props) {
|
|
79
|
+
const label = getLabel(props);
|
|
80
|
+
if (props.readOnly) {
|
|
81
|
+
if (typeof props.value !== "boolean") return /* @__PURE__ */ jsx(RadixText, { children: "—" });
|
|
82
|
+
return /* @__PURE__ */ jsx(RadixText, { children: props.value ? "Yes" : "No" });
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ jsxs(RadixFlex, {
|
|
85
|
+
align: "center",
|
|
86
|
+
gap: "2",
|
|
87
|
+
children: [/* @__PURE__ */ jsx(RadixCheckbox, {
|
|
88
|
+
checked: props.writeOnly ? false : props.value === true,
|
|
89
|
+
onCheckedChange: (checked) => {
|
|
90
|
+
if (typeof checked === "boolean") props.onChange(checked);
|
|
91
|
+
}
|
|
92
|
+
}), label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
93
|
+
as: "label",
|
|
94
|
+
children: label
|
|
95
|
+
})]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function renderEnumInput(props) {
|
|
99
|
+
const enumValue = typeof props.value === "string" ? props.value : "";
|
|
100
|
+
const label = getLabel(props);
|
|
101
|
+
if (props.readOnly) return /* @__PURE__ */ jsx(RadixText, { children: enumValue || "—" });
|
|
102
|
+
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
103
|
+
as: "label",
|
|
104
|
+
size: "2",
|
|
105
|
+
weight: "medium",
|
|
106
|
+
children: label
|
|
107
|
+
}), /* @__PURE__ */ jsxs(RadixSelectRoot, {
|
|
108
|
+
value: props.writeOnly ? "" : enumValue,
|
|
109
|
+
onValueChange: (value) => {
|
|
110
|
+
props.onChange(value);
|
|
111
|
+
},
|
|
112
|
+
children: [/* @__PURE__ */ jsx(RadixSelectTrigger, { mt: "1" }), /* @__PURE__ */ jsx(RadixSelectContent, { children: (props.enumValues ?? []).map((value) => /* @__PURE__ */ jsx(RadixSelectItem, {
|
|
113
|
+
value,
|
|
114
|
+
children: value
|
|
115
|
+
}, value)) })]
|
|
116
|
+
})] });
|
|
117
|
+
}
|
|
118
|
+
function renderObjectContainer(props) {
|
|
119
|
+
const fields = props.fields;
|
|
120
|
+
if (fields === void 0) return null;
|
|
121
|
+
const obj = isObject(props.value) ? props.value : {};
|
|
122
|
+
return /* @__PURE__ */ jsxs(RadixBox, { children: [typeof props.meta.description === "string" && /* @__PURE__ */ jsx(RadixText, {
|
|
123
|
+
as: "div",
|
|
124
|
+
size: "4",
|
|
125
|
+
weight: "bold",
|
|
126
|
+
mb: "3",
|
|
127
|
+
children: props.meta.description
|
|
128
|
+
}), /* @__PURE__ */ jsx(RadixFlex, {
|
|
129
|
+
direction: "column",
|
|
130
|
+
gap: "3",
|
|
131
|
+
children: Object.entries(fields).filter(([, field]) => field.meta.visible !== false).map(([key, field]) => {
|
|
132
|
+
const childValue = obj[key];
|
|
133
|
+
const childOnChange = (v) => {
|
|
134
|
+
const updated = {};
|
|
135
|
+
for (const [k, val] of Object.entries(obj)) updated[k] = val;
|
|
136
|
+
updated[key] = v;
|
|
137
|
+
props.onChange(updated);
|
|
138
|
+
};
|
|
139
|
+
return /* @__PURE__ */ jsx(RadixBox, { children: toReactNode(props.renderChild(field, childValue, childOnChange)) }, key);
|
|
140
|
+
})
|
|
141
|
+
})] });
|
|
142
|
+
}
|
|
143
|
+
function buildResolver() {
|
|
144
|
+
const resolver = {
|
|
145
|
+
string: renderStringInput,
|
|
146
|
+
number: renderNumberInput,
|
|
147
|
+
boolean: renderBooleanInput,
|
|
148
|
+
enum: renderEnumInput,
|
|
149
|
+
object: renderObjectContainer
|
|
150
|
+
};
|
|
151
|
+
if (headlessResolver.literal !== void 0) resolver.literal = headlessResolver.literal;
|
|
152
|
+
if (headlessResolver.union !== void 0) resolver.union = headlessResolver.union;
|
|
153
|
+
if (headlessResolver.discriminatedUnion !== void 0) resolver.discriminatedUnion = headlessResolver.discriminatedUnion;
|
|
154
|
+
if (headlessResolver.array !== void 0) resolver.array = headlessResolver.array;
|
|
155
|
+
if (headlessResolver.record !== void 0) resolver.record = headlessResolver.record;
|
|
156
|
+
if (headlessResolver.file !== void 0) resolver.file = headlessResolver.file;
|
|
157
|
+
if (headlessResolver.unknown !== void 0) resolver.unknown = headlessResolver.unknown;
|
|
158
|
+
return resolver;
|
|
159
|
+
}
|
|
160
|
+
const radixResolver = buildResolver();
|
|
161
|
+
//#endregion
|
|
162
|
+
export { radixResolver, registerRadixComponents };
|