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