schema-components 1.29.0 → 2.0.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 +38 -16
- package/dist/core/adapter.d.mts +213 -3
- package/dist/core/adapter.mjs +1 -1
- package/dist/core/constraintHint.d.mts +15 -0
- package/dist/core/constraintHint.mjs +24 -0
- package/dist/core/constraints.d.mts +2 -2
- package/dist/core/constraints.mjs +1 -1
- package/dist/core/diagnostics.d.mts +1 -1
- package/dist/core/errors.d.mts +1 -1
- package/dist/core/fieldOrder.d.mts +1 -1
- package/dist/core/formats.d.mts +1 -1
- 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 +5 -0
- package/dist/core/merge.d.mts +12 -1
- package/dist/core/merge.mjs +66 -3
- package/dist/core/normalise.d.mts +1 -1
- package/dist/core/normalise.mjs +1 -1
- package/dist/core/openapi30.mjs +1 -1
- 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/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/unionMatch.d.mts +1 -1
- package/dist/core/uri.d.mts +12 -4
- package/dist/core/uri.mjs +30 -4
- package/dist/core/walkBuilders.d.mts +18 -6
- package/dist/core/walkBuilders.mjs +3 -1
- package/dist/core/walker.d.mts +1 -1
- package/dist/core/walker.mjs +5 -0
- package/dist/{diagnostics-ByEzkjrA.d.mts → diagnostics-BTrm3O6J.d.mts} +1 -1
- package/dist/{errors-D8JndRwI.d.mts → errors-Dki7tji4.d.mts} +1 -1
- package/dist/html/a11y.d.mts +3 -7
- package/dist/html/a11y.mjs +1 -16
- package/dist/html/renderToHtml.d.mts +22 -9
- package/dist/html/renderToHtml.mjs +2 -1
- package/dist/html/renderToHtmlStream.d.mts +24 -11
- package/dist/html/renderToHtmlStream.mjs +2 -1
- package/dist/html/renderers.d.mts +2 -33
- package/dist/html/renderers.mjs +39 -91
- package/dist/html/streamRenderers.d.mts +3 -3
- package/dist/html/streamRenderers.mjs +13 -8
- package/dist/inferValue-PPXWJpbN.d.mts +77 -0
- package/dist/{limits-DswmqWuy.d.mts → limits-x4OiyJxh.d.mts} +5 -0
- package/dist/{normalise-Db1xaxgx.mjs → normalise-DB-Xtjmn.mjs} +43 -2
- package/dist/openapi/ApiCallbacks.d.mts +1 -1
- package/dist/openapi/ApiLinks.d.mts +1 -1
- package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
- package/dist/openapi/ApiSecurity.d.mts +1 -1
- package/dist/openapi/ApiSecurity.mjs +21 -8
- package/dist/openapi/bundle.d.mts +31 -0
- package/dist/openapi/components.d.mts +41 -10
- package/dist/openapi/components.mjs +19 -13
- package/dist/openapi/parser.d.mts +13 -13
- package/dist/openapi/parser.mjs +12 -12
- package/dist/openapi/resolve.d.mts +38 -49
- package/dist/openapi/resolve.mjs +62 -56
- package/dist/react/SchemaComponent.d.mts +19 -95
- package/dist/react/SchemaComponent.mjs +12 -1
- package/dist/react/SchemaView.d.mts +11 -7
- package/dist/react/SchemaView.mjs +3 -1
- 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 +2 -2
- package/dist/react/headlessRenderers.mjs +123 -54
- package/dist/{ref-CPh8rKQ3.d.mts → ref-DdsbekXX.d.mts} +33 -1
- package/dist/themes/mantine.d.mts +36 -20
- package/dist/themes/mantine.mjs +179 -150
- package/dist/themes/mui.d.mts +47 -21
- package/dist/themes/mui.mjs +259 -222
- package/dist/themes/radix.d.mts +38 -23
- package/dist/themes/radix.mjs +208 -180
- package/dist/themes/shadcn.d.mts +6 -3
- package/dist/themes/shadcn.mjs +93 -93
- package/dist/{types-C2Ay1FEh.d.mts → types-BrYbjC7_.d.mts} +7 -0
- package/package.json +5 -1
- package/dist/adapter-DcWi4XXn.d.mts +0 -223
- package/dist/renderer-OaOz-n6-.d.mts +0 -185
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,206 +12,234 @@ 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
|
-
* Inject real Radix Themes element types into the resolver. Call once
|
|
29
|
-
* at application startup before rendering any schema-driven component
|
|
30
|
-
* so that {@link radixResolver}'s renderers delegate to the supplied
|
|
31
|
-
* Radix primitives.
|
|
32
|
-
*
|
|
33
|
-
* @group Themes
|
|
34
|
-
*/
|
|
35
|
-
function registerRadixComponents(components) {
|
|
36
|
-
RadixBox = components.Box;
|
|
37
|
-
RadixCheckbox = components.Checkbox;
|
|
38
|
-
RadixFlex = components.Flex;
|
|
39
|
-
RadixSelectRoot = components.SelectRoot;
|
|
40
|
-
RadixSelectTrigger = components.SelectTrigger;
|
|
41
|
-
RadixSelectContent = components.SelectContent;
|
|
42
|
-
RadixSelectItem = components.SelectItem;
|
|
43
|
-
RadixText = components.Text;
|
|
44
|
-
RadixTextField = components.TextField;
|
|
45
|
-
}
|
|
46
|
-
function renderStringInput(props) {
|
|
47
|
-
const strValue = typeof props.value === "string" ? props.value : "";
|
|
48
|
-
const label = getLabel(props);
|
|
49
|
-
const id = inputId(props.path);
|
|
50
|
-
if (props.readOnly) return /* @__PURE__ */ jsx(RadixText, {
|
|
51
|
-
id,
|
|
52
|
-
children: strValue || "—"
|
|
53
|
-
});
|
|
54
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
55
|
-
as: "label",
|
|
56
|
-
size: "2",
|
|
57
|
-
weight: "medium",
|
|
58
|
-
htmlFor: id,
|
|
59
|
-
children: label
|
|
60
|
-
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
61
|
-
id,
|
|
62
|
-
type: props.constraints.format === "email" ? "email" : props.constraints.format === "uri" ? "url" : "text",
|
|
63
|
-
value: props.writeOnly ? "" : strValue,
|
|
64
|
-
onChange: (e) => {
|
|
65
|
-
props.onChange(e.target.value);
|
|
66
|
-
},
|
|
67
|
-
mt: "1"
|
|
68
|
-
})] });
|
|
69
|
-
}
|
|
70
|
-
function renderNumberInput(props) {
|
|
71
|
-
const label = getLabel(props);
|
|
72
|
-
const id = inputId(props.path);
|
|
73
|
-
if (props.readOnly) {
|
|
74
|
-
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, {
|
|
75
22
|
id,
|
|
76
|
-
children: "—"
|
|
23
|
+
children: strValue || "—"
|
|
77
24
|
});
|
|
78
|
-
return /* @__PURE__ */ jsx(
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
})] })
|
|
81
45
|
});
|
|
82
|
-
}
|
|
83
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
84
|
-
as: "label",
|
|
85
|
-
size: "2",
|
|
86
|
-
weight: "medium",
|
|
87
|
-
htmlFor: id,
|
|
88
|
-
children: label
|
|
89
|
-
}), /* @__PURE__ */ jsx(RadixTextField, {
|
|
90
|
-
id,
|
|
91
|
-
type: "number",
|
|
92
|
-
value: props.writeOnly ? "" : typeof props.value === "number" ? props.value : "",
|
|
93
|
-
onChange: (e) => {
|
|
94
|
-
props.onChange(Number(e.target.value));
|
|
95
|
-
},
|
|
96
|
-
mt: "1"
|
|
97
|
-
})] });
|
|
46
|
+
};
|
|
98
47
|
}
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
})] })
|
|
106
83
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
})
|
|
110
121
|
});
|
|
111
|
-
}
|
|
112
|
-
return /* @__PURE__ */ jsxs(RadixFlex, {
|
|
113
|
-
align: "center",
|
|
114
|
-
gap: "2",
|
|
115
|
-
children: [/* @__PURE__ */ jsx(RadixCheckbox, {
|
|
116
|
-
id,
|
|
117
|
-
checked: props.writeOnly ? false : props.value === true,
|
|
118
|
-
onCheckedChange: (checked) => {
|
|
119
|
-
if (typeof checked === "boolean") props.onChange(checked);
|
|
120
|
-
}
|
|
121
|
-
}), label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
122
|
-
as: "label",
|
|
123
|
-
htmlFor: id,
|
|
124
|
-
children: label
|
|
125
|
-
})]
|
|
126
|
-
});
|
|
122
|
+
};
|
|
127
123
|
}
|
|
128
|
-
function
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
id
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
return /* @__PURE__ */ jsxs(RadixBox, { children: [label !== void 0 && /* @__PURE__ */ jsx(RadixText, {
|
|
137
|
-
as: "label",
|
|
138
|
-
size: "2",
|
|
139
|
-
weight: "medium",
|
|
140
|
-
htmlFor: id,
|
|
141
|
-
children: label
|
|
142
|
-
}), /* @__PURE__ */ jsxs(RadixSelectRoot, {
|
|
143
|
-
value: props.writeOnly ? "" : enumValue,
|
|
144
|
-
onValueChange: (value) => {
|
|
145
|
-
props.onChange(value);
|
|
146
|
-
},
|
|
147
|
-
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, {
|
|
148
131
|
id,
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
};
|
|
155
160
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
+
};
|
|
180
188
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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)
|
|
188
225
|
};
|
|
189
|
-
if (headlessResolver.literal !== void 0) resolver.literal = headlessResolver.literal;
|
|
190
|
-
if (headlessResolver.union !== void 0) resolver.union = headlessResolver.union;
|
|
191
|
-
if (headlessResolver.discriminatedUnion !== void 0) resolver.discriminatedUnion = headlessResolver.discriminatedUnion;
|
|
192
|
-
if (headlessResolver.array !== void 0) resolver.array = headlessResolver.array;
|
|
193
|
-
if (headlessResolver.record !== void 0) resolver.record = headlessResolver.record;
|
|
194
|
-
if (headlessResolver.file !== void 0) resolver.file = headlessResolver.file;
|
|
195
|
-
if (headlessResolver.unknown !== void 0) resolver.unknown = headlessResolver.unknown;
|
|
196
|
-
return resolver;
|
|
197
226
|
}
|
|
198
227
|
/**
|
|
199
228
|
* Component resolver mapping schema field types to Radix Themes
|
|
200
229
|
* primitives — `Box`, `Checkbox`, `Flex`, `Select.*`, `Text`,
|
|
201
230
|
* `TextField`.
|
|
202
231
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* inject the actual Radix element types.
|
|
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.
|
|
207
235
|
*
|
|
208
236
|
* @group Themes
|
|
209
237
|
* @example
|
|
210
238
|
* ```tsx
|
|
211
239
|
* import * as Radix from "@radix-ui/themes";
|
|
212
|
-
* import {
|
|
240
|
+
* import { createRadixResolver } from "schema-components/themes/radix";
|
|
213
241
|
*
|
|
214
|
-
*
|
|
242
|
+
* const radixResolver = createRadixResolver({
|
|
215
243
|
* Box: Radix.Box,
|
|
216
244
|
* Checkbox: Radix.Checkbox,
|
|
217
245
|
* Flex: Radix.Flex,
|
|
@@ -228,6 +256,6 @@ function buildResolver() {
|
|
|
228
256
|
* </SchemaProvider>
|
|
229
257
|
* ```
|
|
230
258
|
*/
|
|
231
|
-
const radixResolver =
|
|
259
|
+
const radixResolver = createRadixResolver(STUB_COMPONENTS);
|
|
232
260
|
//#endregion
|
|
233
|
-
export {
|
|
261
|
+
export { createRadixResolver, radixResolver };
|
package/dist/themes/shadcn.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentResolver } from "../core/renderer.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/themes/shadcn.d.ts
|
|
4
4
|
/**
|
|
@@ -6,8 +6,11 @@ import { r as ComponentResolver } from "../renderer-OaOz-n6-.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* Pass to `SchemaProvider` to render every `<SchemaComponent>` /
|
|
8
8
|
* `<SchemaView>` in the subtree with shadcn/ui inputs, selects, and
|
|
9
|
-
* cards.
|
|
10
|
-
*
|
|
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.
|
|
11
14
|
*
|
|
12
15
|
* Requires `shadcn/ui` components installed in the consuming project.
|
|
13
16
|
*
|