schema-components 1.12.3 → 1.12.5
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/core/walker.mjs +32 -24
- package/dist/react/headless.mjs +4 -1
- package/package.json +1 -1
package/dist/core/walker.mjs
CHANGED
|
@@ -198,7 +198,7 @@ function walk(schema, options = {}) {
|
|
|
198
198
|
isNullable: false,
|
|
199
199
|
isOptional: false,
|
|
200
200
|
defaultValue: void 0,
|
|
201
|
-
|
|
201
|
+
refResults: /* @__PURE__ */ new Map()
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
function walkNode(schema, ctx) {
|
|
@@ -220,31 +220,39 @@ function walkNode(schema, ctx) {
|
|
|
220
220
|
return walkUnion(oneOf, ctx);
|
|
221
221
|
}
|
|
222
222
|
const ref = getString(schema, "$ref");
|
|
223
|
-
if (ref !== void 0
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
223
|
+
if (ref !== void 0) {
|
|
224
|
+
const cached = ctx.refResults.get(ref);
|
|
225
|
+
if (cached !== void 0) return cached;
|
|
226
|
+
const resolved = resolveRef(schema, ctx.rootDocument, /* @__PURE__ */ new Set());
|
|
227
|
+
const placeholder = {
|
|
228
|
+
type: "unknown",
|
|
229
|
+
editability: "editable",
|
|
230
|
+
meta: {},
|
|
231
|
+
constraints: {}
|
|
232
|
+
};
|
|
233
|
+
ctx.refResults.set(ref, placeholder);
|
|
234
|
+
const result = walkNode(resolved, ctx);
|
|
235
|
+
Object.assign(placeholder, result);
|
|
236
|
+
return placeholder;
|
|
237
|
+
}
|
|
238
|
+
const enumValues = getArray(schema, "enum");
|
|
239
|
+
if (enumValues !== void 0) return walkEnum(schema, enumValues, ctx);
|
|
240
|
+
if ("const" in schema) return walkLiteral(schema, ctx);
|
|
241
|
+
const type = getString(schema, "type");
|
|
242
|
+
if (type === void 0) return buildField(schema, "unknown", ctx);
|
|
243
|
+
if (type === "string") return walkString(schema, ctx);
|
|
244
|
+
if (type === "number" || type === "integer") return walkNumber(schema, ctx);
|
|
245
|
+
if (type === "boolean") return walkBoolean(schema, ctx);
|
|
246
|
+
if (type === "null") return buildField(schema, "null", ctx);
|
|
239
247
|
if (type === "object") {
|
|
240
|
-
const properties = getObject(
|
|
241
|
-
if (properties !== void 0) return walkObject(
|
|
242
|
-
const additionalProps = getObject(
|
|
243
|
-
if (additionalProps !== void 0) return walkRecord(
|
|
244
|
-
return buildField(
|
|
248
|
+
const properties = getObject(schema, "properties");
|
|
249
|
+
if (properties !== void 0) return walkObject(schema, properties, ctx);
|
|
250
|
+
const additionalProps = getObject(schema, "additionalProperties");
|
|
251
|
+
if (additionalProps !== void 0) return walkRecord(schema, additionalProps, ctx);
|
|
252
|
+
return buildField(schema, "object", ctx);
|
|
245
253
|
}
|
|
246
|
-
if (type === "array") return walkArray(
|
|
247
|
-
return buildField(
|
|
254
|
+
if (type === "array") return walkArray(schema, ctx);
|
|
255
|
+
return buildField(schema, "unknown", ctx);
|
|
248
256
|
}
|
|
249
257
|
function walkString(schema, ctx) {
|
|
250
258
|
if (getString(schema, "format") === "binary") return buildField(schema, "file", ctx);
|
package/dist/react/headless.mjs
CHANGED
|
@@ -249,6 +249,8 @@ function renderObject(props) {
|
|
|
249
249
|
updated[key] = v;
|
|
250
250
|
props.onChange(updated);
|
|
251
251
|
};
|
|
252
|
+
const child = toReactNode(props.renderChild(field, childValue, childOnChange));
|
|
253
|
+
if (child === null || child === void 0) return null;
|
|
252
254
|
return /* @__PURE__ */ jsxs("div", { children: [typeof field.meta.description === "string" && /* @__PURE__ */ jsxs("label", {
|
|
253
255
|
htmlFor: childId,
|
|
254
256
|
children: [field.meta.description, field.isOptional === false && /* @__PURE__ */ jsxs("span", {
|
|
@@ -256,7 +258,7 @@ function renderObject(props) {
|
|
|
256
258
|
style: { color: "#dc2626" },
|
|
257
259
|
children: [" ", "*"]
|
|
258
260
|
})]
|
|
259
|
-
}),
|
|
261
|
+
}), child] }, key);
|
|
260
262
|
})] });
|
|
261
263
|
}
|
|
262
264
|
function renderRecord(props) {
|
|
@@ -290,6 +292,7 @@ function renderArray(props) {
|
|
|
290
292
|
const arr = Array.isArray(props.value) ? props.value : [];
|
|
291
293
|
const element = props.element;
|
|
292
294
|
if (element === void 0) return null;
|
|
295
|
+
if (props.readOnly && arr.length === 0) return null;
|
|
293
296
|
return /* @__PURE__ */ jsx("div", {
|
|
294
297
|
role: "group",
|
|
295
298
|
"aria-label": props.meta.description ?? void 0,
|