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.
@@ -198,7 +198,7 @@ function walk(schema, options = {}) {
198
198
  isNullable: false,
199
199
  isOptional: false,
200
200
  defaultValue: void 0,
201
- visitedRefs: /* @__PURE__ */ new Set()
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 && ctx.visitedRefs.has(ref)) return buildField(schema, "unknown", ctx);
224
- const resolved = ref !== void 0 ? resolveRef(schema, ctx.rootDocument, /* @__PURE__ */ new Set()) : schema;
225
- const childVisited = ref !== void 0 ? new Set([...ctx.visitedRefs, ref]) : ctx.visitedRefs;
226
- const ctxWithRef = {
227
- ...ctx,
228
- visitedRefs: childVisited
229
- };
230
- const enumValues = getArray(resolved, "enum");
231
- if (enumValues !== void 0) return walkEnum(resolved, enumValues, ctxWithRef);
232
- if ("const" in resolved) return walkLiteral(resolved, ctxWithRef);
233
- const type = getString(resolved, "type");
234
- if (type === void 0) return buildField(resolved, "unknown", ctxWithRef);
235
- if (type === "string") return walkString(resolved, ctxWithRef);
236
- if (type === "number" || type === "integer") return walkNumber(resolved, ctxWithRef);
237
- if (type === "boolean") return walkBoolean(resolved, ctxWithRef);
238
- if (type === "null") return buildField(resolved, "null", ctxWithRef);
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(resolved, "properties");
241
- if (properties !== void 0) return walkObject(resolved, properties, ctxWithRef);
242
- const additionalProps = getObject(resolved, "additionalProperties");
243
- if (additionalProps !== void 0) return walkRecord(resolved, additionalProps, ctxWithRef);
244
- return buildField(resolved, "object", ctxWithRef);
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(resolved, ctxWithRef);
247
- return buildField(resolved, "unknown", ctxWithRef);
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);
@@ -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
- }), toReactNode(props.renderChild(field, childValue, childOnChange))] }, key);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-components",
3
- "version": "1.12.3",
3
+ "version": "1.12.5",
4
4
  "description": "React components that render UI from Zod schemas, JSON Schema, and OpenAPI documents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",