schema-components 1.10.0 → 1.10.2
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/react/headless.mjs +28 -0
- package/package.json +1 -1
package/dist/react/headless.mjs
CHANGED
|
@@ -259,6 +259,33 @@ function renderObject(props) {
|
|
|
259
259
|
}), toReactNode(props.renderChild(field, childValue, childOnChange))] }, key);
|
|
260
260
|
})] });
|
|
261
261
|
}
|
|
262
|
+
function renderRecord(props) {
|
|
263
|
+
const obj = isObject(props.value) ? props.value : {};
|
|
264
|
+
const valueType = props.valueType;
|
|
265
|
+
if (valueType === void 0) return null;
|
|
266
|
+
const entries = Object.entries(obj);
|
|
267
|
+
if (entries.length === 0) return /* @__PURE__ */ jsx("span", {
|
|
268
|
+
"aria-readonly": props.readOnly ? "true" : void 0,
|
|
269
|
+
children: "—"
|
|
270
|
+
});
|
|
271
|
+
return /* @__PURE__ */ jsx("div", {
|
|
272
|
+
role: "group",
|
|
273
|
+
"aria-label": props.meta.description ?? "Record",
|
|
274
|
+
children: entries.map(([key, value]) => {
|
|
275
|
+
const childId = inputId(props.path ? `${props.path}.${key}` : key);
|
|
276
|
+
const childOnChange = (nextValue) => {
|
|
277
|
+
const updated = {};
|
|
278
|
+
for (const [k, val] of Object.entries(obj)) updated[k] = val;
|
|
279
|
+
updated[key] = nextValue;
|
|
280
|
+
props.onChange(updated);
|
|
281
|
+
};
|
|
282
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("label", {
|
|
283
|
+
htmlFor: childId,
|
|
284
|
+
children: key
|
|
285
|
+
}), toReactNode(props.renderChild(valueType, value, childOnChange))] }, key);
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
}
|
|
262
289
|
function renderArray(props) {
|
|
263
290
|
const arr = Array.isArray(props.value) ? props.value : [];
|
|
264
291
|
const element = props.element;
|
|
@@ -471,6 +498,7 @@ const headlessResolver = {
|
|
|
471
498
|
boolean: renderBoolean,
|
|
472
499
|
enum: renderEnum,
|
|
473
500
|
object: renderObject,
|
|
501
|
+
record: renderRecord,
|
|
474
502
|
array: renderArray,
|
|
475
503
|
union: renderUnion,
|
|
476
504
|
discriminatedUnion: renderDiscriminatedUnion,
|