schema-components 1.8.1 → 1.9.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/dist/themes/mantine.d.mts +17 -0
- package/dist/themes/mantine.mjs +126 -0
- package/dist/themes/mui.d.mts +6 -6
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { b as ComponentResolver } from "../types-BJzEgJdX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/themes/mantine.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Register real Mantine components for the resolver to use.
|
|
6
|
+
* Call once at app startup before rendering.
|
|
7
|
+
*/
|
|
8
|
+
declare function registerMantineComponents(components: {
|
|
9
|
+
TextInput: React.ElementType;
|
|
10
|
+
NumberInput: React.ElementType;
|
|
11
|
+
Switch: React.ElementType;
|
|
12
|
+
Select: React.ElementType;
|
|
13
|
+
Fieldset: React.ElementType;
|
|
14
|
+
}): void;
|
|
15
|
+
declare const mantineResolver: ComponentResolver;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { mantineResolver, registerMantineComponents };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { isObject } from "../core/guards.mjs";
|
|
2
|
+
import { headlessResolver, toReactNode } from "../react/headless.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/themes/mantine.tsx
|
|
5
|
+
function getLabel(props) {
|
|
6
|
+
if (typeof props.meta.description === "string") return props.meta.description;
|
|
7
|
+
}
|
|
8
|
+
let MantineTextInput = (props) => /* @__PURE__ */ jsx("input", { ...props });
|
|
9
|
+
let MantineNumberInput = (props) => /* @__PURE__ */ jsx("input", {
|
|
10
|
+
type: "number",
|
|
11
|
+
...props
|
|
12
|
+
});
|
|
13
|
+
let MantineSwitch = (props) => /* @__PURE__ */ jsx("input", {
|
|
14
|
+
type: "checkbox",
|
|
15
|
+
...props
|
|
16
|
+
});
|
|
17
|
+
let MantineSelect = (props) => /* @__PURE__ */ jsx("select", { ...props });
|
|
18
|
+
let MantineFieldset = (props) => /* @__PURE__ */ jsx("fieldset", { ...props });
|
|
19
|
+
/**
|
|
20
|
+
* Register real Mantine components for the resolver to use.
|
|
21
|
+
* Call once at app startup before rendering.
|
|
22
|
+
*/
|
|
23
|
+
function registerMantineComponents(components) {
|
|
24
|
+
MantineTextInput = components.TextInput;
|
|
25
|
+
MantineNumberInput = components.NumberInput;
|
|
26
|
+
MantineSwitch = components.Switch;
|
|
27
|
+
MantineSelect = components.Select;
|
|
28
|
+
MantineFieldset = components.Fieldset;
|
|
29
|
+
}
|
|
30
|
+
function renderStringInput(props) {
|
|
31
|
+
const strValue = typeof props.value === "string" ? props.value : "";
|
|
32
|
+
const label = getLabel(props);
|
|
33
|
+
if (props.readOnly) return /* @__PURE__ */ jsx("span", { children: strValue || "—" });
|
|
34
|
+
return /* @__PURE__ */ jsx(MantineTextInput, {
|
|
35
|
+
label,
|
|
36
|
+
value: props.writeOnly ? "" : strValue,
|
|
37
|
+
onChange: (e) => {
|
|
38
|
+
props.onChange(e.target.value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function renderNumberInput(props) {
|
|
43
|
+
const label = getLabel(props);
|
|
44
|
+
if (props.readOnly) {
|
|
45
|
+
if (typeof props.value !== "number") return /* @__PURE__ */ jsx("span", { children: "—" });
|
|
46
|
+
return /* @__PURE__ */ jsx("span", { children: props.value.toLocaleString() });
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ jsx(MantineNumberInput, {
|
|
49
|
+
label,
|
|
50
|
+
value: props.writeOnly ? void 0 : typeof props.value === "number" ? props.value : void 0,
|
|
51
|
+
onChange: (v) => {
|
|
52
|
+
if (typeof v === "number") props.onChange(v);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function renderBooleanInput(props) {
|
|
57
|
+
const label = getLabel(props);
|
|
58
|
+
if (props.readOnly) {
|
|
59
|
+
if (typeof props.value !== "boolean") return /* @__PURE__ */ jsx("span", { children: "—" });
|
|
60
|
+
return /* @__PURE__ */ jsx("span", { children: props.value ? "Yes" : "No" });
|
|
61
|
+
}
|
|
62
|
+
return /* @__PURE__ */ jsx(MantineSwitch, {
|
|
63
|
+
label,
|
|
64
|
+
checked: props.writeOnly ? false : props.value === true,
|
|
65
|
+
onChange: (e) => {
|
|
66
|
+
props.onChange(e.target.checked);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function renderEnumInput(props) {
|
|
71
|
+
const enumValue = typeof props.value === "string" ? props.value : "";
|
|
72
|
+
const label = getLabel(props);
|
|
73
|
+
if (props.readOnly) return /* @__PURE__ */ jsx("span", { children: enumValue || "—" });
|
|
74
|
+
return /* @__PURE__ */ jsx(MantineSelect, {
|
|
75
|
+
label,
|
|
76
|
+
value: props.writeOnly ? null : enumValue || null,
|
|
77
|
+
onChange: (v) => {
|
|
78
|
+
if (typeof v === "string") props.onChange(v);
|
|
79
|
+
},
|
|
80
|
+
data: (props.enumValues ?? []).map((v) => ({
|
|
81
|
+
value: v,
|
|
82
|
+
label: v
|
|
83
|
+
}))
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function renderObjectContainer(props) {
|
|
87
|
+
const fields = props.fields;
|
|
88
|
+
if (fields === void 0) return null;
|
|
89
|
+
const obj = isObject(props.value) ? props.value : {};
|
|
90
|
+
return /* @__PURE__ */ jsx(MantineFieldset, {
|
|
91
|
+
legend: getLabel(props),
|
|
92
|
+
children: Object.entries(fields).filter(([, field]) => field.meta.visible !== false).map(([key, field]) => {
|
|
93
|
+
const childValue = obj[key];
|
|
94
|
+
const childOnChange = (v) => {
|
|
95
|
+
const updated = {};
|
|
96
|
+
for (const [k, val] of Object.entries(obj)) updated[k] = val;
|
|
97
|
+
updated[key] = v;
|
|
98
|
+
props.onChange(updated);
|
|
99
|
+
};
|
|
100
|
+
return /* @__PURE__ */ jsx("div", {
|
|
101
|
+
style: { marginBottom: "0.5rem" },
|
|
102
|
+
children: toReactNode(props.renderChild(field, childValue, childOnChange))
|
|
103
|
+
}, key);
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function buildResolver() {
|
|
108
|
+
const resolver = {
|
|
109
|
+
string: renderStringInput,
|
|
110
|
+
number: renderNumberInput,
|
|
111
|
+
boolean: renderBooleanInput,
|
|
112
|
+
enum: renderEnumInput,
|
|
113
|
+
object: renderObjectContainer
|
|
114
|
+
};
|
|
115
|
+
if (headlessResolver.literal !== void 0) resolver.literal = headlessResolver.literal;
|
|
116
|
+
if (headlessResolver.union !== void 0) resolver.union = headlessResolver.union;
|
|
117
|
+
if (headlessResolver.discriminatedUnion !== void 0) resolver.discriminatedUnion = headlessResolver.discriminatedUnion;
|
|
118
|
+
if (headlessResolver.array !== void 0) resolver.array = headlessResolver.array;
|
|
119
|
+
if (headlessResolver.record !== void 0) resolver.record = headlessResolver.record;
|
|
120
|
+
if (headlessResolver.file !== void 0) resolver.file = headlessResolver.file;
|
|
121
|
+
if (headlessResolver.unknown !== void 0) resolver.unknown = headlessResolver.unknown;
|
|
122
|
+
return resolver;
|
|
123
|
+
}
|
|
124
|
+
const mantineResolver = buildResolver();
|
|
125
|
+
//#endregion
|
|
126
|
+
export { mantineResolver, registerMantineComponents };
|
package/dist/themes/mui.d.mts
CHANGED
|
@@ -5,12 +5,12 @@ import { b as ComponentResolver } from "../types-BJzEgJdX.mjs";
|
|
|
5
5
|
* Register real MUI components. Call once at app startup.
|
|
6
6
|
*/
|
|
7
7
|
declare function registerMuiComponents(components: {
|
|
8
|
-
TextField: React.
|
|
9
|
-
Checkbox: React.
|
|
10
|
-
Typography: React.
|
|
11
|
-
Box: React.
|
|
12
|
-
MenuItem: React.
|
|
13
|
-
FormControlLabel: React.
|
|
8
|
+
TextField: React.ElementType;
|
|
9
|
+
Checkbox: React.ElementType;
|
|
10
|
+
Typography: React.ElementType;
|
|
11
|
+
Box: React.ElementType;
|
|
12
|
+
MenuItem: React.ElementType;
|
|
13
|
+
FormControlLabel: React.ElementType;
|
|
14
14
|
}): void;
|
|
15
15
|
declare const muiResolver: ComponentResolver;
|
|
16
16
|
//#endregion
|