schema-components 1.28.2 → 2.0.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 +38 -16
- package/dist/core/adapter.d.mts +213 -3
- package/dist/core/adapter.mjs +21 -2
- package/dist/core/constraintHint.d.mts +15 -0
- package/dist/core/constraintHint.mjs +24 -0
- package/dist/core/constraints.d.mts +34 -2
- package/dist/core/constraints.mjs +33 -1
- package/dist/core/cssClasses.d.mts +1 -0
- package/dist/core/diagnostics.d.mts +1 -1
- package/dist/core/errors.d.mts +1 -1
- package/dist/core/errors.mjs +22 -12
- package/dist/core/fieldOrder.d.mts +1 -1
- package/dist/core/formats.d.mts +7 -1
- package/dist/core/formats.mjs +6 -0
- package/dist/core/idPath.d.mts +35 -5
- package/dist/core/idPath.mjs +79 -7
- package/dist/core/inferValue.d.mts +2 -0
- package/dist/core/inferValue.mjs +1 -0
- package/dist/core/limits.d.mts +1 -1
- package/dist/core/limits.mjs +6 -0
- package/dist/core/merge.d.mts +22 -1
- package/dist/core/merge.mjs +66 -3
- package/dist/core/normalise.d.mts +17 -2
- package/dist/core/normalise.mjs +1 -1
- package/dist/core/openapi30.mjs +1 -1
- package/dist/core/openapiConstants.d.mts +1 -0
- package/dist/core/ref.d.mts +1 -1
- package/dist/core/refChain.d.mts +3 -4
- package/dist/core/refChain.mjs +2 -3
- package/dist/core/renderer.d.mts +199 -2
- package/dist/core/renderer.mjs +5 -0
- package/dist/core/swagger2.d.mts +1 -1
- package/dist/core/swagger2.mjs +1 -1
- package/dist/core/typeInference.d.mts +3 -3
- package/dist/core/types.d.mts +1 -1
- package/dist/core/types.mjs +17 -0
- package/dist/core/unionMatch.d.mts +1 -1
- package/dist/core/uri.d.mts +12 -4
- package/dist/core/uri.mjs +30 -4
- package/dist/core/version.d.mts +1 -1
- package/dist/core/walkBuilders.d.mts +63 -6
- package/dist/core/walkBuilders.mjs +33 -1
- package/dist/core/walker.d.mts +14 -1
- package/dist/core/walker.mjs +18 -0
- package/dist/{diagnostics-Cbwak-ZX.d.mts → diagnostics-BTrm3O6J.d.mts} +9 -1
- package/dist/{errors-DQSIK4n1.d.mts → errors-Dki7tji4.d.mts} +23 -13
- package/dist/html/a11y.d.mts +3 -7
- package/dist/html/a11y.mjs +1 -16
- package/dist/html/html.d.mts +11 -0
- package/dist/html/html.mjs +11 -0
- package/dist/html/renderToHtml.d.mts +45 -12
- package/dist/html/renderToHtml.mjs +20 -4
- package/dist/html/renderToHtmlStream.d.mts +63 -18
- package/dist/html/renderToHtmlStream.mjs +34 -8
- package/dist/html/renderers.d.mts +6 -31
- package/dist/html/renderers.mjs +45 -91
- package/dist/html/streamRenderers.d.mts +31 -3
- package/dist/html/streamRenderers.mjs +41 -8
- package/dist/inferValue-PPXWJpbN.d.mts +77 -0
- package/dist/{limits-DJhgx5Ay.d.mts → limits-x4OiyJxh.d.mts} +6 -0
- package/dist/{normalise-Db1xaxgx.mjs → normalise-DB-Xtjmn.mjs} +43 -2
- package/dist/openapi/ApiCallbacks.d.mts +13 -1
- package/dist/openapi/ApiCallbacks.mjs +7 -0
- package/dist/openapi/ApiLinks.d.mts +13 -1
- package/dist/openapi/ApiLinks.mjs +7 -0
- package/dist/openapi/ApiResponseHeaders.d.mts +13 -1
- package/dist/openapi/ApiResponseHeaders.mjs +7 -0
- package/dist/openapi/ApiSecurity.d.mts +14 -1
- package/dist/openapi/ApiSecurity.mjs +29 -8
- package/dist/openapi/bundle.d.mts +31 -0
- package/dist/openapi/components.d.mts +135 -20
- package/dist/openapi/components.mjs +90 -15
- package/dist/openapi/parser.d.mts +140 -13
- package/dist/openapi/parser.mjs +84 -12
- package/dist/openapi/resolve.d.mts +42 -47
- package/dist/openapi/resolve.mjs +62 -56
- package/dist/react/SchemaComponent.d.mts +90 -88
- package/dist/react/SchemaComponent.mjs +74 -2
- package/dist/react/SchemaErrorBoundary.d.mts +18 -1
- package/dist/react/SchemaErrorBoundary.mjs +13 -1
- package/dist/react/SchemaView.d.mts +39 -11
- package/dist/react/SchemaView.mjs +23 -6
- package/dist/react/a11y.d.mts +74 -7
- package/dist/react/a11y.mjs +67 -6
- package/dist/react/fieldPath.d.mts +16 -1
- package/dist/react/fieldPath.mjs +25 -1
- package/dist/react/fieldShell.d.mts +49 -0
- package/dist/react/fieldShell.mjs +37 -0
- package/dist/react/headless.d.mts +1 -1
- package/dist/react/headlessRenderers.d.mts +13 -2
- package/dist/react/headlessRenderers.mjs +134 -54
- package/dist/{ref-TdeMfaV_.d.mts → ref-DdsbekXX.d.mts} +33 -1
- package/dist/themes/mantine.d.mts +54 -12
- package/dist/themes/mantine.mjs +195 -140
- package/dist/themes/mui.d.mts +64 -11
- package/dist/themes/mui.mjs +277 -213
- package/dist/themes/radix.d.mts +67 -15
- package/dist/themes/radix.mjs +235 -170
- package/dist/themes/shadcn.d.mts +25 -1
- package/dist/themes/shadcn.mjs +112 -91
- package/dist/{types-BTB73MB8.d.mts → types-BrYbjC7_.d.mts} +30 -0
- package/dist/{version-ZzL5R6cS.d.mts → version-DL8U5RuA.d.mts} +6 -0
- package/package.json +8 -1
- package/dist/adapter-DqlAnZ_w.d.mts +0 -172
- package/dist/renderer-Ul9taFYp.d.mts +0 -169
package/dist/themes/radix.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isObject } from "../core/guards.mjs";
|
|
2
2
|
import { sortFieldsByOrder } from "../core/fieldOrder.mjs";
|
|
3
3
|
import { inputId, toReactNode } from "../react/headlessRenderers.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { FieldShell } from "../react/fieldShell.mjs";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
//#region src/themes/radix.tsx
|
|
7
7
|
function getLabel(props) {
|
|
@@ -12,185 +12,250 @@ function stripChildren(props) {
|
|
|
12
12
|
if ("children" in rest) delete rest.children;
|
|
13
13
|
return rest;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let RadixSelectTrigger = (props) => /* @__PURE__ */ jsx("span", { ...props });
|
|
23
|
-
let RadixSelectContent = (props) => /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
24
|
-
let RadixSelectItem = (props) => /* @__PURE__ */ jsx("option", { ...props });
|
|
25
|
-
let RadixText = (props) => /* @__PURE__ */ jsx("span", { ...props });
|
|
26
|
-
let RadixTextField = (props) => /* @__PURE__ */ jsx("input", { ...stripChildren(props) });
|
|
27
|
-
/**
|
|
28
|
-
* Register real Radix Themes components for the resolver to use.
|
|
29
|
-
* Call once at app startup before rendering.
|
|
30
|
-
*/
|
|
31
|
-
function registerRadixComponents(components) {
|
|
32
|
-
RadixBox = components.Box;
|
|
33
|
-
RadixCheckbox = components.Checkbox;
|
|
34
|
-
RadixFlex = components.Flex;
|
|
35
|
-
RadixSelectRoot = components.SelectRoot;
|
|
36
|
-
RadixSelectTrigger = components.SelectTrigger;
|
|
37
|
-
RadixSelectContent = components.SelectContent;
|
|
38
|
-
RadixSelectItem = components.SelectItem;
|
|
39
|
-
RadixText = components.Text;
|
|
40
|
-
RadixTextField = components.TextField;
|
|
41
|
-
}
|
|
42
|
-
function renderStringInput(props) {
|
|
43
|
-
const strValue = typeof props.value === "string" ? props.value : "";
|
|
44
|
-
const label = getLabel(props);
|
|
45
|
-
const id = inputId(props.path);
|
|
46
|
-
if (props.readOnly) return /* @__PURE__ */ jsx(RadixText, {
|
|
47
|
-
id,
|
|
48
|
-
children: strValue || "—"
|
|
49
|
-
});
|
|
50
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
51
|
-
as: "label",
|
|
52
|
-
size: "2",
|
|
53
|
-
weight: "medium",
|
|
54
|
-
htmlFor: id,
|
|
55
|
-
children: label
|
|
56
|
-
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
57
|
-
id,
|
|
58
|
-
type: props.constraints.format === "email" ? "email" : props.constraints.format === "uri" ? "url" : "text",
|
|
59
|
-
value: props.writeOnly ? "" : strValue,
|
|
60
|
-
onChange: (e) => {
|
|
61
|
-
props.onChange(e.target.value);
|
|
62
|
-
},
|
|
63
|
-
mt: "1"
|
|
64
|
-
})] });
|
|
65
|
-
}
|
|
66
|
-
function renderNumberInput(props) {
|
|
67
|
-
const label = getLabel(props);
|
|
68
|
-
const id = inputId(props.path);
|
|
69
|
-
if (props.readOnly) {
|
|
70
|
-
if (typeof props.value !== "number") return /* @__PURE__ */ jsx(RadixText, {
|
|
15
|
+
function makeRenderStringInput(components) {
|
|
16
|
+
const { Box, Text, TextField } = components;
|
|
17
|
+
return function renderStringInput(props) {
|
|
18
|
+
const strValue = typeof props.value === "string" ? props.value : "";
|
|
19
|
+
const label = getLabel(props);
|
|
20
|
+
const id = inputId(props.path);
|
|
21
|
+
if (props.readOnly) return /* @__PURE__ */ jsx(Text, {
|
|
71
22
|
id,
|
|
72
|
-
children: "—"
|
|
23
|
+
children: strValue || "—"
|
|
73
24
|
});
|
|
74
|
-
return /* @__PURE__ */ jsx(
|
|
75
|
-
|
|
76
|
-
|
|
25
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
26
|
+
props,
|
|
27
|
+
inputId: id,
|
|
28
|
+
hideLabel: true,
|
|
29
|
+
children: (aria) => /* @__PURE__ */ jsxs(Box, { children: [label !== void 0 && /* @__PURE__ */ jsx(Text, {
|
|
30
|
+
as: "label",
|
|
31
|
+
size: "2",
|
|
32
|
+
weight: "medium",
|
|
33
|
+
htmlFor: id,
|
|
34
|
+
children: label
|
|
35
|
+
}), /* @__PURE__ */ jsx(TextField, {
|
|
36
|
+
id,
|
|
37
|
+
type: props.constraints.format === "email" ? "email" : props.constraints.format === "uri" ? "url" : "text",
|
|
38
|
+
value: props.writeOnly ? "" : strValue,
|
|
39
|
+
onChange: (e) => {
|
|
40
|
+
props.onChange(e.target.value);
|
|
41
|
+
},
|
|
42
|
+
mt: "1",
|
|
43
|
+
...aria
|
|
44
|
+
})] })
|
|
77
45
|
});
|
|
78
|
-
}
|
|
79
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
80
|
-
as: "label",
|
|
81
|
-
size: "2",
|
|
82
|
-
weight: "medium",
|
|
83
|
-
htmlFor: id,
|
|
84
|
-
children: label
|
|
85
|
-
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
86
|
-
id,
|
|
87
|
-
type: "number",
|
|
88
|
-
value: props.writeOnly ? "" : typeof props.value === "number" ? props.value : "",
|
|
89
|
-
onChange: (e) => {
|
|
90
|
-
props.onChange(Number(e.target.value));
|
|
91
|
-
},
|
|
92
|
-
mt: "1"
|
|
93
|
-
})] });
|
|
46
|
+
};
|
|
94
47
|
}
|
|
95
|
-
function
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
48
|
+
function makeRenderNumberInput(components) {
|
|
49
|
+
const { Box, Text, TextField } = components;
|
|
50
|
+
return function renderNumberInput(props) {
|
|
51
|
+
const label = getLabel(props);
|
|
52
|
+
const id = inputId(props.path);
|
|
53
|
+
if (props.readOnly) {
|
|
54
|
+
if (typeof props.value !== "number") return /* @__PURE__ */ jsx(Text, {
|
|
55
|
+
id,
|
|
56
|
+
children: "—"
|
|
57
|
+
});
|
|
58
|
+
return /* @__PURE__ */ jsx(Text, {
|
|
59
|
+
id,
|
|
60
|
+
children: props.value.toLocaleString()
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
64
|
+
props,
|
|
65
|
+
inputId: id,
|
|
66
|
+
hideLabel: true,
|
|
67
|
+
children: (aria) => /* @__PURE__ */ jsxs(Box, { children: [label !== void 0 && /* @__PURE__ */ jsx(Text, {
|
|
68
|
+
as: "label",
|
|
69
|
+
size: "2",
|
|
70
|
+
weight: "medium",
|
|
71
|
+
htmlFor: id,
|
|
72
|
+
children: label
|
|
73
|
+
}), /* @__PURE__ */ jsx(TextField, {
|
|
74
|
+
id,
|
|
75
|
+
type: "number",
|
|
76
|
+
value: props.writeOnly ? "" : typeof props.value === "number" ? props.value : "",
|
|
77
|
+
onChange: (e) => {
|
|
78
|
+
props.onChange(Number(e.target.value));
|
|
79
|
+
},
|
|
80
|
+
mt: "1",
|
|
81
|
+
...aria
|
|
82
|
+
})] })
|
|
102
83
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function makeRenderBooleanInput(components) {
|
|
87
|
+
const { Checkbox, Flex, Text } = components;
|
|
88
|
+
return function renderBooleanInput(props) {
|
|
89
|
+
const label = getLabel(props);
|
|
90
|
+
const id = inputId(props.path);
|
|
91
|
+
if (props.readOnly) {
|
|
92
|
+
if (typeof props.value !== "boolean") return /* @__PURE__ */ jsx(Text, {
|
|
93
|
+
id,
|
|
94
|
+
children: "—"
|
|
95
|
+
});
|
|
96
|
+
return /* @__PURE__ */ jsx(Text, {
|
|
97
|
+
id,
|
|
98
|
+
children: props.value ? "Yes" : "No"
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
102
|
+
props,
|
|
103
|
+
inputId: id,
|
|
104
|
+
hideLabel: true,
|
|
105
|
+
children: (aria) => /* @__PURE__ */ jsxs(Flex, {
|
|
106
|
+
align: "center",
|
|
107
|
+
gap: "2",
|
|
108
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
109
|
+
id,
|
|
110
|
+
checked: props.writeOnly ? false : props.value === true,
|
|
111
|
+
onCheckedChange: (checked) => {
|
|
112
|
+
if (typeof checked === "boolean") props.onChange(checked);
|
|
113
|
+
},
|
|
114
|
+
...aria
|
|
115
|
+
}), label !== void 0 && /* @__PURE__ */ jsx(Text, {
|
|
116
|
+
as: "label",
|
|
117
|
+
htmlFor: id,
|
|
118
|
+
children: label
|
|
119
|
+
})]
|
|
120
|
+
})
|
|
106
121
|
});
|
|
107
|
-
}
|
|
108
|
-
return /* @__PURE__ */ jsxs(RadixFlex, {
|
|
109
|
-
align: "center",
|
|
110
|
-
gap: "2",
|
|
111
|
-
children: [/* @__PURE__ */ jsx(RadixCheckbox, {
|
|
112
|
-
id,
|
|
113
|
-
checked: props.writeOnly ? false : props.value === true,
|
|
114
|
-
onCheckedChange: (checked) => {
|
|
115
|
-
if (typeof checked === "boolean") props.onChange(checked);
|
|
116
|
-
}
|
|
117
|
-
}), label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
118
|
-
as: "label",
|
|
119
|
-
htmlFor: id,
|
|
120
|
-
children: label
|
|
121
|
-
})]
|
|
122
|
-
});
|
|
122
|
+
};
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
id
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
133
|
-
as: "label",
|
|
134
|
-
size: "2",
|
|
135
|
-
weight: "medium",
|
|
136
|
-
htmlFor: id,
|
|
137
|
-
children: label
|
|
138
|
-
}), /* @__PURE__ */ jsxs(RadixSelectRoot, {
|
|
139
|
-
value: props.writeOnly ? "" : enumValue,
|
|
140
|
-
onValueChange: (value) => {
|
|
141
|
-
props.onChange(value);
|
|
142
|
-
},
|
|
143
|
-
children: [/* @__PURE__ */ jsx(RadixSelectTrigger, {
|
|
124
|
+
function makeRenderEnumInput(components) {
|
|
125
|
+
const { Box, Text, SelectRoot, SelectTrigger, SelectContent, SelectItem } = components;
|
|
126
|
+
return function renderEnumInput(props) {
|
|
127
|
+
const enumValue = typeof props.value === "string" ? props.value : "";
|
|
128
|
+
const label = getLabel(props);
|
|
129
|
+
const id = inputId(props.path);
|
|
130
|
+
if (props.readOnly) return /* @__PURE__ */ jsx(Text, {
|
|
144
131
|
id,
|
|
145
|
-
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
132
|
+
children: enumValue || "—"
|
|
133
|
+
});
|
|
134
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
135
|
+
props,
|
|
136
|
+
inputId: id,
|
|
137
|
+
hideLabel: true,
|
|
138
|
+
children: (aria) => /* @__PURE__ */ jsxs(Box, { children: [label !== void 0 && /* @__PURE__ */ jsx(Text, {
|
|
139
|
+
as: "label",
|
|
140
|
+
size: "2",
|
|
141
|
+
weight: "medium",
|
|
142
|
+
htmlFor: id,
|
|
143
|
+
children: label
|
|
144
|
+
}), /* @__PURE__ */ jsxs(SelectRoot, {
|
|
145
|
+
value: props.writeOnly ? "" : enumValue,
|
|
146
|
+
onValueChange: (value) => {
|
|
147
|
+
props.onChange(value);
|
|
148
|
+
},
|
|
149
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
150
|
+
id,
|
|
151
|
+
mt: "1",
|
|
152
|
+
...aria
|
|
153
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: (props.tree.type === "enum" ? props.tree.enumValues : []).map((value) => /* @__PURE__ */ jsx(SelectItem, {
|
|
154
|
+
value,
|
|
155
|
+
children: value
|
|
156
|
+
}, value)) })]
|
|
157
|
+
})] })
|
|
158
|
+
});
|
|
159
|
+
};
|
|
151
160
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
function makeRenderObjectContainer(components) {
|
|
162
|
+
const { Box, Flex, Text } = components;
|
|
163
|
+
return function renderObjectContainer(props) {
|
|
164
|
+
if (props.tree.type !== "object") return null;
|
|
165
|
+
const fields = props.tree.fields;
|
|
166
|
+
const obj = isObject(props.value) ? props.value : {};
|
|
167
|
+
return /* @__PURE__ */ jsxs(Box, { children: [typeof props.meta.description === "string" && /* @__PURE__ */ jsx(Text, {
|
|
168
|
+
as: "div",
|
|
169
|
+
size: "4",
|
|
170
|
+
weight: "bold",
|
|
171
|
+
mb: "3",
|
|
172
|
+
children: props.meta.description
|
|
173
|
+
}), /* @__PURE__ */ jsx(Flex, {
|
|
174
|
+
direction: "column",
|
|
175
|
+
gap: "3",
|
|
176
|
+
children: sortFieldsByOrder(fields).filter(([, field]) => field.meta.visible !== false).map(([key, field]) => {
|
|
177
|
+
const childValue = obj[key];
|
|
178
|
+
const childOnChange = (v) => {
|
|
179
|
+
const updated = {};
|
|
180
|
+
for (const [k, val] of Object.entries(obj)) updated[k] = val;
|
|
181
|
+
updated[key] = v;
|
|
182
|
+
props.onChange(updated);
|
|
183
|
+
};
|
|
184
|
+
return /* @__PURE__ */ jsx(Box, { children: toReactNode(props.renderChild(field, childValue, childOnChange, key)) }, key);
|
|
185
|
+
})
|
|
186
|
+
})] });
|
|
187
|
+
};
|
|
176
188
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
const STUB_COMPONENTS = {
|
|
190
|
+
Box: (props) => /* @__PURE__ */ jsx("div", { ...props }),
|
|
191
|
+
Checkbox: (props) => /* @__PURE__ */ jsx("input", {
|
|
192
|
+
type: "checkbox",
|
|
193
|
+
...stripChildren(props)
|
|
194
|
+
}),
|
|
195
|
+
Flex: (props) => /* @__PURE__ */ jsx("div", { ...props }),
|
|
196
|
+
SelectRoot: (props) => /* @__PURE__ */ jsx("select", { ...props }),
|
|
197
|
+
SelectTrigger: (props) => /* @__PURE__ */ jsx("span", { ...props }),
|
|
198
|
+
SelectContent: (props) => /* @__PURE__ */ jsx(Fragment, { children: props.children }),
|
|
199
|
+
SelectItem: (props) => /* @__PURE__ */ jsx("option", { ...props }),
|
|
200
|
+
Text: (props) => /* @__PURE__ */ jsx("span", { ...props }),
|
|
201
|
+
TextField: (props) => /* @__PURE__ */ jsx("input", { ...stripChildren(props) })
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Build a Radix-flavoured {@link ComponentResolver} bound to the
|
|
205
|
+
* supplied element types. Each render function captures the supplied
|
|
206
|
+
* components in a closure so two consumers can build different
|
|
207
|
+
* resolvers from the same package without leaking element types
|
|
208
|
+
* through module-level mutable state.
|
|
209
|
+
*
|
|
210
|
+
* Returns only the keys this theme actually overrides. The runtime
|
|
211
|
+
* `mergeResolvers` call inside `<SchemaComponent>` / `<SchemaView>`
|
|
212
|
+
* fills unset keys from `headlessResolver`, so variants this adapter
|
|
213
|
+
* leaves unset (literal, union, discriminatedUnion, array, record,
|
|
214
|
+
* file, unknown, …) still render via the headless fallback.
|
|
215
|
+
*
|
|
216
|
+
* @group Themes
|
|
217
|
+
*/
|
|
218
|
+
function createRadixResolver(components) {
|
|
219
|
+
return {
|
|
220
|
+
string: makeRenderStringInput(components),
|
|
221
|
+
number: makeRenderNumberInput(components),
|
|
222
|
+
boolean: makeRenderBooleanInput(components),
|
|
223
|
+
enum: makeRenderEnumInput(components),
|
|
224
|
+
object: makeRenderObjectContainer(components)
|
|
184
225
|
};
|
|
185
|
-
if (headlessResolver.literal !== void 0) resolver.literal = headlessResolver.literal;
|
|
186
|
-
if (headlessResolver.union !== void 0) resolver.union = headlessResolver.union;
|
|
187
|
-
if (headlessResolver.discriminatedUnion !== void 0) resolver.discriminatedUnion = headlessResolver.discriminatedUnion;
|
|
188
|
-
if (headlessResolver.array !== void 0) resolver.array = headlessResolver.array;
|
|
189
|
-
if (headlessResolver.record !== void 0) resolver.record = headlessResolver.record;
|
|
190
|
-
if (headlessResolver.file !== void 0) resolver.file = headlessResolver.file;
|
|
191
|
-
if (headlessResolver.unknown !== void 0) resolver.unknown = headlessResolver.unknown;
|
|
192
|
-
return resolver;
|
|
193
226
|
}
|
|
194
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Component resolver mapping schema field types to Radix Themes
|
|
229
|
+
* primitives — `Box`, `Checkbox`, `Flex`, `Select.*`, `Text`,
|
|
230
|
+
* `TextField`.
|
|
231
|
+
*
|
|
232
|
+
* Built against minimal HTML stubs so the resolver is usable without
|
|
233
|
+
* wiring up `@radix-ui/themes` first — production usage should call
|
|
234
|
+
* {@link createRadixResolver} with real Radix element types.
|
|
235
|
+
*
|
|
236
|
+
* @group Themes
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* import * as Radix from "@radix-ui/themes";
|
|
240
|
+
* import { createRadixResolver } from "schema-components/themes/radix";
|
|
241
|
+
*
|
|
242
|
+
* const radixResolver = createRadixResolver({
|
|
243
|
+
* Box: Radix.Box,
|
|
244
|
+
* Checkbox: Radix.Checkbox,
|
|
245
|
+
* Flex: Radix.Flex,
|
|
246
|
+
* SelectRoot: Radix.Select.Root,
|
|
247
|
+
* SelectTrigger: Radix.Select.Trigger,
|
|
248
|
+
* SelectContent: Radix.Select.Content,
|
|
249
|
+
* SelectItem: Radix.Select.Item,
|
|
250
|
+
* Text: Radix.Text,
|
|
251
|
+
* TextField: Radix.TextField.Root,
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* <SchemaProvider resolver={radixResolver}>
|
|
255
|
+
* <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
|
|
256
|
+
* </SchemaProvider>
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
const radixResolver = createRadixResolver(STUB_COMPONENTS);
|
|
195
260
|
//#endregion
|
|
196
|
-
export {
|
|
261
|
+
export { createRadixResolver, radixResolver };
|
package/dist/themes/shadcn.d.mts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentResolver } from "../core/renderer.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/themes/shadcn.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Component resolver mapping schema field types to shadcn/ui components.
|
|
6
|
+
*
|
|
7
|
+
* Pass to `SchemaProvider` to render every `<SchemaComponent>` /
|
|
8
|
+
* `<SchemaView>` in the subtree with shadcn/ui inputs, selects, and
|
|
9
|
+
* cards. Returns only the keys this theme overrides — the runtime
|
|
10
|
+
* `mergeResolvers` call inside `<SchemaComponent>` / `<SchemaView>`
|
|
11
|
+
* fills unset keys from `headlessResolver`, so variants like literal,
|
|
12
|
+
* union, discriminatedUnion, record, file, and unknown still render via
|
|
13
|
+
* the headless fallback.
|
|
14
|
+
*
|
|
15
|
+
* Requires `shadcn/ui` components installed in the consuming project.
|
|
16
|
+
*
|
|
17
|
+
* @group Themes
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { SchemaProvider } from "schema-components/react/SchemaComponent";
|
|
21
|
+
* import { shadcnResolver } from "schema-components/themes/shadcn";
|
|
22
|
+
*
|
|
23
|
+
* <SchemaProvider resolver={shadcnResolver}>
|
|
24
|
+
* <SchemaComponent schema={userSchema} value={user} onChange={setUser} />
|
|
25
|
+
* </SchemaProvider>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
4
28
|
declare const shadcnResolver: ComponentResolver;
|
|
5
29
|
//#endregion
|
|
6
30
|
export { shadcnResolver };
|