schema-components 1.9.0 → 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/mantine.d.mts +5 -5
- package/dist/themes/mantine.mjs +5 -10
- package/dist/themes/mui.d.mts +9 -6
- package/dist/themes/mui.mjs +6 -11
- package/dist/themes/radix.d.mts +21 -0
- package/dist/themes/radix.mjs +162 -0
- package/package.json +1 -1
|
@@ -6,11 +6,11 @@ import { b as ComponentResolver } from "../types-BJzEgJdX.mjs";
|
|
|
6
6
|
* Call once at app startup before rendering.
|
|
7
7
|
*/
|
|
8
8
|
declare function registerMantineComponents(components: {
|
|
9
|
-
TextInput:
|
|
10
|
-
NumberInput:
|
|
11
|
-
Switch:
|
|
12
|
-
Select:
|
|
13
|
-
Fieldset:
|
|
9
|
+
TextInput: React.ElementType;
|
|
10
|
+
NumberInput: React.ElementType;
|
|
11
|
+
Switch: React.ElementType;
|
|
12
|
+
Select: React.ElementType;
|
|
13
|
+
Fieldset: React.ElementType;
|
|
14
14
|
}): void;
|
|
15
15
|
declare const mantineResolver: ComponentResolver;
|
|
16
16
|
//#endregion
|
package/dist/themes/mantine.mjs
CHANGED
|
@@ -16,21 +16,16 @@ let MantineSwitch = (props) => /* @__PURE__ */ jsx("input", {
|
|
|
16
16
|
});
|
|
17
17
|
let MantineSelect = (props) => /* @__PURE__ */ jsx("select", { ...props });
|
|
18
18
|
let MantineFieldset = (props) => /* @__PURE__ */ jsx("fieldset", { ...props });
|
|
19
|
-
function toComponent(value) {
|
|
20
|
-
if (typeof value === "function") return value;
|
|
21
|
-
if (typeof value === "object" && value !== null && "render" in value) return value;
|
|
22
|
-
throw new Error(`Expected a React component, got ${typeof value}`);
|
|
23
|
-
}
|
|
24
19
|
/**
|
|
25
20
|
* Register real Mantine components for the resolver to use.
|
|
26
21
|
* Call once at app startup before rendering.
|
|
27
22
|
*/
|
|
28
23
|
function registerMantineComponents(components) {
|
|
29
|
-
MantineTextInput =
|
|
30
|
-
MantineNumberInput =
|
|
31
|
-
MantineSwitch =
|
|
32
|
-
MantineSelect =
|
|
33
|
-
MantineFieldset =
|
|
24
|
+
MantineTextInput = components.TextInput;
|
|
25
|
+
MantineNumberInput = components.NumberInput;
|
|
26
|
+
MantineSwitch = components.Switch;
|
|
27
|
+
MantineSelect = components.Select;
|
|
28
|
+
MantineFieldset = components.Fieldset;
|
|
34
29
|
}
|
|
35
30
|
function renderStringInput(props) {
|
|
36
31
|
const strValue = typeof props.value === "string" ? props.value : "";
|
package/dist/themes/mui.d.mts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { b as ComponentResolver } from "../types-BJzEgJdX.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/themes/mui.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Register real MUI components. Call once at app startup.
|
|
6
|
+
*/
|
|
4
7
|
declare function registerMuiComponents(components: {
|
|
5
|
-
TextField:
|
|
6
|
-
Checkbox:
|
|
7
|
-
Typography:
|
|
8
|
-
Box:
|
|
9
|
-
MenuItem:
|
|
10
|
-
FormControlLabel:
|
|
8
|
+
TextField: React.ElementType;
|
|
9
|
+
Checkbox: React.ElementType;
|
|
10
|
+
Typography: React.ElementType;
|
|
11
|
+
Box: React.ElementType;
|
|
12
|
+
MenuItem: React.ElementType;
|
|
13
|
+
FormControlLabel: React.ElementType;
|
|
11
14
|
}): void;
|
|
12
15
|
declare const muiResolver: ComponentResolver;
|
|
13
16
|
//#endregion
|
package/dist/themes/mui.mjs
CHANGED
|
@@ -197,18 +197,13 @@ let MuiFormControlLabel = (props) => {
|
|
|
197
197
|
/**
|
|
198
198
|
* Register real MUI components. Call once at app startup.
|
|
199
199
|
*/
|
|
200
|
-
function toComponent(value) {
|
|
201
|
-
if (typeof value === "function") return value;
|
|
202
|
-
if (typeof value === "object" && value !== null && "render" in value) return value;
|
|
203
|
-
throw new Error(`Expected a React component, got ${typeof value}`);
|
|
204
|
-
}
|
|
205
200
|
function registerMuiComponents(components) {
|
|
206
|
-
MuiTextField =
|
|
207
|
-
MuiCheckbox =
|
|
208
|
-
MuiTypography =
|
|
209
|
-
MuiBox =
|
|
210
|
-
MuiMenuItem =
|
|
211
|
-
MuiFormControlLabel =
|
|
201
|
+
MuiTextField = components.TextField;
|
|
202
|
+
MuiCheckbox = components.Checkbox;
|
|
203
|
+
MuiTypography = components.Typography;
|
|
204
|
+
MuiBox = components.Box;
|
|
205
|
+
MuiMenuItem = components.MenuItem;
|
|
206
|
+
MuiFormControlLabel = components.FormControlLabel;
|
|
212
207
|
}
|
|
213
208
|
function buildResolver() {
|
|
214
209
|
const resolver = {
|
|
@@ -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 };
|