@flanksource/clicky-ui 0.2.8 → 0.2.10

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.
Files changed (139) hide show
  1. package/dist/components/Combobox.cjs +89 -49
  2. package/dist/components/Combobox.cjs.map +1 -1
  3. package/dist/components/Combobox.d.ts +3 -0
  4. package/dist/components/Combobox.d.ts.map +1 -1
  5. package/dist/components/Combobox.js +91 -51
  6. package/dist/components/Combobox.js.map +1 -1
  7. package/dist/components/FilterBar.cjs +42 -44
  8. package/dist/components/FilterBar.cjs.map +1 -1
  9. package/dist/components/FilterBar.d.ts +19 -0
  10. package/dist/components/FilterBar.d.ts.map +1 -1
  11. package/dist/components/FilterBar.js +43 -45
  12. package/dist/components/FilterBar.js.map +1 -1
  13. package/dist/components/JsonSchemaForm.cjs +48 -0
  14. package/dist/components/JsonSchemaForm.cjs.map +1 -0
  15. package/dist/components/JsonSchemaForm.d.ts +3 -0
  16. package/dist/components/JsonSchemaForm.d.ts.map +1 -0
  17. package/dist/components/JsonSchemaForm.js +48 -0
  18. package/dist/components/JsonSchemaForm.js.map +1 -0
  19. package/dist/components/json-schema-form-array.cjs +169 -0
  20. package/dist/components/json-schema-form-array.cjs.map +1 -0
  21. package/dist/components/json-schema-form-array.d.ts +8 -0
  22. package/dist/components/json-schema-form-array.d.ts.map +1 -0
  23. package/dist/components/json-schema-form-array.js +169 -0
  24. package/dist/components/json-schema-form-array.js.map +1 -0
  25. package/dist/components/json-schema-form-fields.cjs +374 -0
  26. package/dist/components/json-schema-form-fields.cjs.map +1 -0
  27. package/dist/components/json-schema-form-fields.d.ts +19 -0
  28. package/dist/components/json-schema-form-fields.d.ts.map +1 -0
  29. package/dist/components/json-schema-form-fields.js +374 -0
  30. package/dist/components/json-schema-form-fields.js.map +1 -0
  31. package/dist/components/json-schema-form-render.cjs +154 -0
  32. package/dist/components/json-schema-form-render.cjs.map +1 -0
  33. package/dist/components/json-schema-form-render.d.ts +40 -0
  34. package/dist/components/json-schema-form-render.d.ts.map +1 -0
  35. package/dist/components/json-schema-form-render.js +154 -0
  36. package/dist/components/json-schema-form-render.js.map +1 -0
  37. package/dist/components/json-schema-form-resolve.cjs +121 -0
  38. package/dist/components/json-schema-form-resolve.cjs.map +1 -0
  39. package/dist/components/json-schema-form-resolve.d.ts +19 -0
  40. package/dist/components/json-schema-form-resolve.d.ts.map +1 -0
  41. package/dist/components/json-schema-form-resolve.js +121 -0
  42. package/dist/components/json-schema-form-resolve.js.map +1 -0
  43. package/dist/components/json-schema-form-types.d.ts +124 -0
  44. package/dist/components/json-schema-form-types.d.ts.map +1 -0
  45. package/dist/components.cjs +7 -0
  46. package/dist/components.cjs.map +1 -1
  47. package/dist/components.d.ts +3 -0
  48. package/dist/components.d.ts.map +1 -1
  49. package/dist/components.js +8 -1
  50. package/dist/components.js.map +1 -1
  51. package/dist/data/Clicky.cjs +1 -1
  52. package/dist/data/Clicky.cjs.map +1 -1
  53. package/dist/data/Clicky.js +1 -1
  54. package/dist/data/Clicky.js.map +1 -1
  55. package/dist/data/DataTable.cjs +16 -15
  56. package/dist/data/DataTable.cjs.map +1 -1
  57. package/dist/data/DataTable.d.ts +2 -1
  58. package/dist/data/DataTable.d.ts.map +1 -1
  59. package/dist/data/DataTable.js +16 -15
  60. package/dist/data/DataTable.js.map +1 -1
  61. package/dist/data/Icon.cjs +11 -0
  62. package/dist/data/Icon.cjs.map +1 -1
  63. package/dist/data/Icon.d.ts +12 -1
  64. package/dist/data/Icon.d.ts.map +1 -1
  65. package/dist/data/Icon.js +12 -1
  66. package/dist/data/Icon.js.map +1 -1
  67. package/dist/data/LogDetails.cjs +277 -0
  68. package/dist/data/LogDetails.cjs.map +1 -0
  69. package/dist/data/LogDetails.d.ts +5 -0
  70. package/dist/data/LogDetails.d.ts.map +1 -0
  71. package/dist/data/LogDetails.js +277 -0
  72. package/dist/data/LogDetails.js.map +1 -0
  73. package/dist/data/LogsTable.cjs +6 -202
  74. package/dist/data/LogsTable.cjs.map +1 -1
  75. package/dist/data/LogsTable.d.ts.map +1 -1
  76. package/dist/data/LogsTable.js +4 -200
  77. package/dist/data/LogsTable.js.map +1 -1
  78. package/dist/data/Properties.cjs +2 -2
  79. package/dist/data/Properties.cjs.map +1 -1
  80. package/dist/data/Properties.js +2 -2
  81. package/dist/data/Properties.js.map +1 -1
  82. package/dist/data/cells/TagList.cjs +19 -3
  83. package/dist/data/cells/TagList.cjs.map +1 -1
  84. package/dist/data/cells/TagList.d.ts +11 -1
  85. package/dist/data/cells/TagList.d.ts.map +1 -1
  86. package/dist/data/cells/TagList.js +19 -3
  87. package/dist/data/cells/TagList.js.map +1 -1
  88. package/dist/data/cells/Timestamp.cjs +17 -2
  89. package/dist/data/cells/Timestamp.cjs.map +1 -1
  90. package/dist/data/cells/Timestamp.d.ts +2 -0
  91. package/dist/data/cells/Timestamp.d.ts.map +1 -1
  92. package/dist/data/cells/Timestamp.js +17 -2
  93. package/dist/data/cells/Timestamp.js.map +1 -1
  94. package/dist/data/log-utils.cjs +7 -0
  95. package/dist/data/log-utils.cjs.map +1 -0
  96. package/dist/data/log-utils.d.ts +2 -0
  97. package/dist/data/log-utils.d.ts.map +1 -0
  98. package/dist/data/log-utils.js +7 -0
  99. package/dist/data/log-utils.js.map +1 -0
  100. package/dist/data.cjs +3 -0
  101. package/dist/data.cjs.map +1 -1
  102. package/dist/data.d.ts +2 -2
  103. package/dist/data.d.ts.map +1 -1
  104. package/dist/data.js +5 -2
  105. package/dist/index.cjs +13 -0
  106. package/dist/index.cjs.map +1 -1
  107. package/dist/index.js +15 -2
  108. package/dist/index.js.map +1 -1
  109. package/dist/rpc/EntityExplorerApp.cjs +3 -2
  110. package/dist/rpc/EntityExplorerApp.cjs.map +1 -1
  111. package/dist/rpc/EntityExplorerApp.js +3 -2
  112. package/dist/rpc/EntityExplorerApp.js.map +1 -1
  113. package/dist/rpc/OperationActionDialog.cjs +1 -1
  114. package/dist/rpc/OperationActionDialog.cjs.map +1 -1
  115. package/dist/rpc/OperationActionDialog.js +1 -1
  116. package/dist/rpc/OperationActionDialog.js.map +1 -1
  117. package/dist/rpc/OperationCommandPage.cjs +21 -14
  118. package/dist/rpc/OperationCommandPage.cjs.map +1 -1
  119. package/dist/rpc/OperationCommandPage.d.ts.map +1 -1
  120. package/dist/rpc/OperationCommandPage.js +21 -14
  121. package/dist/rpc/OperationCommandPage.js.map +1 -1
  122. package/dist/rpc/apiClient.cjs +316 -0
  123. package/dist/rpc/apiClient.cjs.map +1 -0
  124. package/dist/rpc/apiClient.d.ts +44 -0
  125. package/dist/rpc/apiClient.d.ts.map +1 -0
  126. package/dist/rpc/apiClient.js +316 -0
  127. package/dist/rpc/apiClient.js.map +1 -0
  128. package/dist/rpc/useOperations.cjs.map +1 -1
  129. package/dist/rpc/useOperations.d.ts +2 -1
  130. package/dist/rpc/useOperations.d.ts.map +1 -1
  131. package/dist/rpc/useOperations.js.map +1 -1
  132. package/dist/rpc.cjs +3 -0
  133. package/dist/rpc.cjs.map +1 -1
  134. package/dist/rpc.d.ts +1 -0
  135. package/dist/rpc.d.ts.map +1 -1
  136. package/dist/rpc.js +3 -0
  137. package/dist/rpc.js.map +1 -1
  138. package/dist/styles.css +1 -1
  139. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-render.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-render.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AASvC,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACb,MAAM,0BAA0B,CAAC;AAMlC,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAGlB,kBAAkB,EAAE,OAAO,CAAC;IAE5B,MAAM,EAAE,UAAU,CAAC;IAGnB,aAAa,EAAE,OAAO,CAAC;IACvB,GAAG,EAAE,YAAY,EAAE,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,EAAE,CAAC,CAAC,EAAE,CAKf;AAID,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAcjE;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAE1D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAEvD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,EAAE,CAMnE;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CASlE"}
@@ -0,0 +1,154 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "react";
3
+ import { LabelIcon } from "../data/Icon.js";
4
+ import { FieldWrapper, fieldInputId, renderValueControl, FieldLabel } from "./json-schema-form-fields.js";
5
+ import { effectiveProperties, resolveControl } from "./json-schema-form-resolve.js";
6
+ function buildField(args, ctx) {
7
+ const base = resolveControl(args);
8
+ let field = base;
9
+ for (const ext of ctx.pre) {
10
+ if (!field) break;
11
+ field = ext(field, { key: args.key, prop: args.prop, value: args.value });
12
+ }
13
+ if (!field) return null;
14
+ if (ctx.hideReadOnlyFields && field.readOnly) return null;
15
+ const fieldId = fieldInputId(field.key);
16
+ let label = /* @__PURE__ */ jsx(FieldLabel, { field, fieldId });
17
+ let value = renderValueControl(field, ctx);
18
+ for (const ext of ctx.post) {
19
+ const next = ext(field, { label, value });
20
+ label = next.label;
21
+ value = next.value;
22
+ }
23
+ return { field, label, value };
24
+ }
25
+ function renderFieldNodes(args, ctx) {
26
+ const built = buildField(args, ctx);
27
+ if (!built) return null;
28
+ return { label: built.label, value: built.value };
29
+ }
30
+ function renderFieldRow(args, ctx, opts) {
31
+ const built = buildField(args, ctx);
32
+ if (!built) return null;
33
+ const { field } = built;
34
+ if (field.kind === "object") {
35
+ return /* @__PURE__ */ jsx(
36
+ ObjectSection,
37
+ {
38
+ label: (opts == null ? void 0 : opts.labelOverride) ?? field.label,
39
+ required: field.required,
40
+ ...field.badge ? { badge: field.badge } : {},
41
+ ...field.helper ? { helper: field.helper } : {},
42
+ ...field.labelIcon != null ? { labelIcon: field.labelIcon } : {},
43
+ children: built.value
44
+ }
45
+ );
46
+ }
47
+ const label = (opts == null ? void 0 : opts.labelOverride) ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-sm font-medium", children: [
48
+ /* @__PURE__ */ jsx(LabelIcon, { icon: field.labelIcon, className: "text-[15px] text-muted-foreground" }),
49
+ /* @__PURE__ */ jsx("span", { children: opts.labelOverride }),
50
+ field.required && /* @__PURE__ */ jsx("span", { className: "text-destructive", children: "*" }),
51
+ field.badge && /* @__PURE__ */ jsx("span", { className: "rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground", children: field.badge })
52
+ ] }) : built.label;
53
+ const err = softError(field);
54
+ return /* @__PURE__ */ jsx(
55
+ FieldWrapper,
56
+ {
57
+ layout: ctx.layout,
58
+ label,
59
+ value: built.value,
60
+ ...field.helper ? { helper: field.helper } : {},
61
+ ...err ? { error: err } : {}
62
+ }
63
+ );
64
+ }
65
+ function ObjectSection({
66
+ label,
67
+ required,
68
+ badge,
69
+ helper,
70
+ labelIcon,
71
+ children
72
+ }) {
73
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
74
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b border-border pb-1 text-sm font-semibold", children: [
75
+ /* @__PURE__ */ jsx(LabelIcon, { icon: labelIcon, className: "text-[15px] text-muted-foreground" }),
76
+ /* @__PURE__ */ jsx("span", { children: label }),
77
+ required && /* @__PURE__ */ jsx("span", { className: "text-destructive", children: "*" }),
78
+ badge && /* @__PURE__ */ jsx("span", { className: "rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground", children: badge })
79
+ ] }),
80
+ helper && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: helper }),
81
+ children
82
+ ] });
83
+ }
84
+ function renderObjectFields(schema, value, onChange, ctx, opts) {
85
+ const { properties, required } = effectiveProperties(schema, value);
86
+ const hidden = new Set((opts == null ? void 0 : opts.hiddenKeys) ?? []);
87
+ const entries = ctx.requiredFirst ? orderRequiredFirst(Object.entries(properties), required) : Object.entries(properties);
88
+ return entries.flatMap(([key, prop]) => {
89
+ if (hidden.has(key)) return [];
90
+ const row = renderFieldRow(
91
+ {
92
+ key,
93
+ prop,
94
+ required: required.includes(key),
95
+ value: value[key],
96
+ onChange: (next) => onChange({ ...value, [key]: next })
97
+ },
98
+ ctx
99
+ );
100
+ return row ? [/* @__PURE__ */ jsx("div", { children: row }, key)] : [];
101
+ });
102
+ }
103
+ function orderRequiredFirst(entries, required) {
104
+ const isRequired = new Set(required);
105
+ const head = entries.filter(([key]) => isRequired.has(key));
106
+ const tail = entries.filter(([key]) => !isRequired.has(key));
107
+ return [...head, ...tail];
108
+ }
109
+ function softError(field) {
110
+ const v = field.value;
111
+ const isEmpty = v === void 0 || v === null || v === "";
112
+ if (field.required && isEmpty) return "Required";
113
+ if (field.kind === "number" && typeof field.minimum === "number" && typeof v === "number") {
114
+ if (v < field.minimum) return `Must be ≥ ${field.minimum}`;
115
+ }
116
+ if (field.kind === "enum" && !field.allowCustomValue && !isEmpty) {
117
+ const known = (field.options ?? []).some((o) => o.value === String(v));
118
+ if (!known) return "Unknown value (allowed)";
119
+ }
120
+ return void 0;
121
+ }
122
+ function setIndex(arr, i, v) {
123
+ return arr.map((x, idx) => idx === i ? v : x);
124
+ }
125
+ function removeIndex(arr, i) {
126
+ return arr.filter((_, idx) => idx !== i);
127
+ }
128
+ function moveItem(arr, from, to) {
129
+ if (to < 0 || to >= arr.length) return arr;
130
+ const next = [...arr];
131
+ const [moved] = next.splice(from, 1);
132
+ next.splice(to, 0, moved);
133
+ return next;
134
+ }
135
+ function seedFromSchema(schema) {
136
+ if (schema.default !== void 0) return schema.default;
137
+ const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
138
+ if (type === "array") return [];
139
+ if (type === "object") return {};
140
+ if (type === "boolean") return false;
141
+ return "";
142
+ }
143
+ export {
144
+ moveItem,
145
+ orderRequiredFirst,
146
+ removeIndex,
147
+ renderFieldNodes,
148
+ renderFieldRow,
149
+ renderObjectFields,
150
+ seedFromSchema,
151
+ setIndex,
152
+ softError
153
+ };
154
+ //# sourceMappingURL=json-schema-form-render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-render.js","sources":["../../src/components/json-schema-form-render.tsx"],"sourcesContent":["import { type ReactNode } from \"react\";\nimport { LabelIcon, type LabelIconSpec } from \"../data/Icon\";\nimport {\n FieldLabel,\n FieldWrapper,\n fieldInputId,\n renderValueControl,\n} from \"./json-schema-form-fields\";\nimport { effectiveProperties, resolveControl } from \"./json-schema-form-resolve\";\nimport type {\n FieldControl,\n FormLayout,\n JsonSchemaObject,\n JsonSchemaProperty,\n PostExtension,\n PreExtension,\n} from \"./json-schema-form-types\";\n\n// RenderContext carries everything the recursive renderer needs to descend into\n// array items and object/map values: readOnly/inline layout, the consumer's\n// pre/post extension stacks (so they apply at EVERY depth, not just the top\n// level), and the current depth (for keys/labels).\nexport interface RenderContext {\n readOnly: boolean;\n // Drop fields whose resolved control is read-only (schema `readOnly: true`)\n // instead of rendering them as value displays. Applies at every depth.\n hideReadOnlyFields: boolean;\n // Resolved form layout (mode + inline width caps); see FormLayout.\n layout: FormLayout;\n // requiredFirst stably reorders each object level so required fields render\n // before optional ones (see JsonSchemaFormProps.requiredFirst).\n requiredFirst: boolean;\n pre: PreExtension[];\n post: PostExtension[];\n depth: number;\n}\n\n// runExtensions resolves a control, applies the pre-extensions (any returning\n// null drops the field), renders the value node, then applies the\n// post-extensions to the {label, value} node pair.\nfunction buildField(\n args: { key: string; prop: JsonSchemaProperty; required: boolean; value: unknown; onChange: (next: unknown) => void },\n ctx: RenderContext,\n): { field: FieldControl; label: ReactNode; value: ReactNode } | null {\n const base = resolveControl(args);\n let field: FieldControl | null = base;\n for (const ext of ctx.pre) {\n if (!field) break;\n field = ext(field, { key: args.key, prop: args.prop, value: args.value });\n }\n if (!field) return null;\n // Drop read-only fields entirely when the form opts out of displaying them.\n // Checked after pre-extensions so an extension that sets/clears readOnly wins.\n if (ctx.hideReadOnlyFields && field.readOnly) return null;\n\n const fieldId = fieldInputId(field.key);\n let label: ReactNode = <FieldLabel field={field} fieldId={fieldId} />;\n let value: ReactNode = renderValueControl(field, ctx);\n for (const ext of ctx.post) {\n const next = ext(field, { label, value });\n label = next.label;\n value = next.value;\n }\n return { field, label, value };\n}\n\n// renderFieldNodes runs the full pipeline and returns the raw {label, value}\n// nodes (no FieldWrapper). Used where the caller arranges layout itself — map\n// rows (value only) and scalar array items.\nexport function renderFieldNodes(\n args: { key: string; prop: JsonSchemaProperty; required: boolean; value: unknown; onChange: (next: unknown) => void },\n ctx: RenderContext,\n): { label: ReactNode; value: ReactNode } | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n return { label: built.label, value: built.value };\n}\n\n// renderFieldRow runs the pipeline and wraps it in a FieldWrapper with the soft\n// validation hint. `labelOverride` lets a container relabel a field that has no\n// natural key (e.g. array items → \"Item 1\").\nexport function renderFieldRow(\n args: { key: string; prop: JsonSchemaProperty; required: boolean; value: unknown; onChange: (next: unknown) => void },\n ctx: RenderContext,\n opts?: { labelOverride?: string },\n): ReactNode | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n const { field } = built;\n // Object fields render as a flat section — a header followed by the nested\n // fields at full width — rather than an inline label + bordered sub-form box.\n // This keeps deep schemas (e.g. policy → shape, asfile → params) readable as a\n // single column of labelled sections instead of progressively indented boxes.\n if (field.kind === \"object\") {\n return (\n <ObjectSection\n label={opts?.labelOverride ?? field.label}\n required={field.required}\n {...(field.badge ? { badge: field.badge } : {})}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(field.labelIcon != null ? { labelIcon: field.labelIcon } : {})}\n >\n {built.value}\n </ObjectSection>\n );\n }\n const label = opts?.labelOverride ? (\n <span className=\"flex items-center gap-2 text-sm font-medium\">\n <LabelIcon icon={field.labelIcon} className=\"text-[15px] text-muted-foreground\" />\n <span>{opts.labelOverride}</span>\n {field.required && <span className=\"text-destructive\">*</span>}\n {field.badge && (\n <span className=\"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\">\n {field.badge}\n </span>\n )}\n </span>\n ) : (\n built.label\n );\n const err = softError(field);\n return (\n <FieldWrapper\n layout={ctx.layout}\n label={label}\n value={built.value}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(err ? { error: err } : {})}\n />\n );\n}\n\n// ObjectSection renders a nested object as a labelled section: a header row\n// (the field label + required/badge) above its fields, which fill the full\n// width below. It replaces the inline label + bordered box so nested objects\n// read as flat, headed groups rather than indented sub-forms.\nfunction ObjectSection({\n label,\n required,\n badge,\n helper,\n labelIcon,\n children,\n}: {\n label: string;\n required: boolean;\n badge?: string;\n helper?: string;\n labelIcon?: LabelIconSpec;\n children: ReactNode;\n}) {\n return (\n <div className=\"space-y-1.5\">\n <div className=\"flex items-center gap-2 border-b border-border pb-1 text-sm font-semibold\">\n <LabelIcon icon={labelIcon} className=\"text-[15px] text-muted-foreground\" />\n <span>{label}</span>\n {required && <span className=\"text-destructive\">*</span>}\n {badge && (\n <span className=\"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\">\n {badge}\n </span>\n )}\n </div>\n {helper && <p className=\"text-xs text-muted-foreground\">{helper}</p>}\n {children}\n </div>\n );\n}\n\n// renderObjectFields maps an object subschema's effective properties to field\n// rows. It is the recursive heart, shared by the top-level form and the nested\n// ObjectControl. Edits spread immutably onto the object.\nexport function renderObjectFields(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n onChange: (next: Record<string, unknown>) => void,\n ctx: RenderContext,\n opts?: { hiddenKeys?: string[] },\n): ReactNode[] {\n const { properties, required } = effectiveProperties(schema, value);\n const hidden = new Set(opts?.hiddenKeys ?? []);\n const entries = ctx.requiredFirst\n ? orderRequiredFirst(Object.entries(properties), required)\n : Object.entries(properties);\n return entries.flatMap(([key, prop]) => {\n if (hidden.has(key)) return [];\n const row = renderFieldRow(\n {\n key,\n prop,\n required: required.includes(key),\n value: value[key],\n onChange: (next) => onChange({ ...value, [key]: next }),\n },\n ctx,\n );\n return row ? [<div key={key}>{row}</div>] : [];\n });\n}\n\n// orderRequiredFirst stably partitions property entries so the keys named in\n// `required` come first (in their original order), then the rest (in theirs).\n// A stable two-pass partition, so it never reshuffles within either group.\nexport function orderRequiredFirst<T>(\n entries: [string, T][],\n required: string[],\n): [string, T][] {\n const isRequired = new Set(required);\n const head = entries.filter(([key]) => isRequired.has(key));\n const tail = entries.filter(([key]) => !isRequired.has(key));\n return [...head, ...tail];\n}\n\n// softError computes a display-only validation hint. It never blocks onChange.\n// Consumers suppress the unknown-enum hint by setting allowCustomValue.\nexport function softError(field: FieldControl): string | undefined {\n const v = field.value;\n const isEmpty = v === undefined || v === null || v === \"\";\n if (field.required && isEmpty) return \"Required\";\n\n if (field.kind === \"number\" && typeof field.minimum === \"number\" && typeof v === \"number\") {\n if (v < field.minimum) return `Must be ≥ ${field.minimum}`;\n }\n\n if (field.kind === \"enum\" && !field.allowCustomValue && !isEmpty) {\n const known = (field.options ?? []).some((o) => o.value === String(v));\n if (!known) return \"Unknown value (allowed)\";\n }\n return undefined;\n}\n\n// Immutable array helpers used by the array control.\nexport function setIndex<T>(arr: T[], i: number, v: T): T[] {\n return arr.map((x, idx) => (idx === i ? v : x));\n}\n\nexport function removeIndex<T>(arr: T[], i: number): T[] {\n return arr.filter((_, idx) => idx !== i);\n}\n\nexport function moveItem<T>(arr: T[], from: number, to: number): T[] {\n if (to < 0 || to >= arr.length) return arr;\n const next = [...arr];\n const [moved] = next.splice(from, 1);\n next.splice(to, 0, moved as T);\n return next;\n}\n\n// seedFromSchema produces the initial value for a freshly-added array item or\n// object field, honouring an explicit default.\nexport function seedFromSchema(schema: JsonSchemaProperty): unknown {\n if (schema.default !== undefined) return schema.default;\n const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n if (type === \"array\") return [];\n if (type === \"object\") return {};\n if (type === \"boolean\") return false;\n // Numbers seed as \"\" so the soft Required hint can show without coercion\n // surprises; the number control coerces on first real input.\n return \"\";\n}\n"],"names":[],"mappings":";;;;;AAwCA,SAAS,WACP,MACA,KACoE;AACpE,QAAM,OAAO,eAAe,IAAI;AAChC,MAAI,QAA6B;AACjC,aAAW,OAAO,IAAI,KAAK;AACzB,QAAI,CAAC,MAAO;AACZ,YAAQ,IAAI,OAAO,EAAE,KAAK,KAAK,KAAK,MAAM,KAAK,MAAM,OAAO,KAAK,MAAA,CAAO;AAAA,EAC1E;AACA,MAAI,CAAC,MAAO,QAAO;AAGnB,MAAI,IAAI,sBAAsB,MAAM,SAAU,QAAO;AAErD,QAAM,UAAU,aAAa,MAAM,GAAG;AACtC,MAAI,QAAmB,oBAAC,YAAA,EAAW,OAAc,QAAA,CAAkB;AACnE,MAAI,QAAmB,mBAAmB,OAAO,GAAG;AACpD,aAAW,OAAO,IAAI,MAAM;AAC1B,UAAM,OAAO,IAAI,OAAO,EAAE,OAAO,OAAO;AACxC,YAAQ,KAAK;AACb,YAAQ,KAAK;AAAA,EACf;AACA,SAAO,EAAE,OAAO,OAAO,MAAA;AACzB;AAKO,SAAS,iBACd,MACA,KAC+C;AAC/C,QAAM,QAAQ,WAAW,MAAM,GAAG;AAClC,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,EAAE,OAAO,MAAM,OAAO,OAAO,MAAM,MAAA;AAC5C;AAKO,SAAS,eACd,MACA,KACA,MACkB;AAClB,Q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;AAClE,MAAI,SAAS,QAAS,QAAO,CAAA;AAC7B,MAAI,SAAS,SAAU,QAAO,CAAA;AAC9B,MAAI,SAAS,UAAW,QAAO;AAG/B,SAAO;AACT;"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function isOpenStringMap(prop) {
4
+ return schemaHasType(prop, "object") && typeof prop.additionalProperties === "object" && prop.additionalProperties !== null;
5
+ }
6
+ function schemaHasType(prop, type) {
7
+ if (Array.isArray(prop.type)) return prop.type.includes(type);
8
+ return prop.type === type;
9
+ }
10
+ function enumOptions(prop) {
11
+ return (prop.enum ?? []).map((v) => ({ value: String(v), label: String(v) }));
12
+ }
13
+ function enumBranch(prop) {
14
+ for (const branch of [...prop.anyOf ?? [], ...prop.oneOf ?? []]) {
15
+ if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;
16
+ }
17
+ return void 0;
18
+ }
19
+ function resolveControl(args) {
20
+ const { key, prop, required, value, onChange } = args;
21
+ const labelIcon = prop["x-icon"];
22
+ const base = {
23
+ key,
24
+ kind: "string",
25
+ label: typeof prop.title === "string" && prop.title ? prop.title : key,
26
+ required,
27
+ schema: prop,
28
+ value,
29
+ onChange,
30
+ ...prop.readOnly === true ? { readOnly: true } : {},
31
+ ...typeof prop.description === "string" ? { description: prop.description } : {},
32
+ ...labelIcon != null && labelIcon !== "" ? { labelIcon } : {}
33
+ };
34
+ if (Array.isArray(prop.enum) && prop.enum.length > 0) {
35
+ return { ...base, kind: "enum", options: enumOptions(prop) };
36
+ }
37
+ const branch = enumBranch(prop);
38
+ if (branch) {
39
+ return { ...base, kind: "enum", options: enumOptions(branch) };
40
+ }
41
+ if (prop.format === "date" || prop.format === "date-time") {
42
+ return { ...base, kind: "date", dateFormat: prop.format };
43
+ }
44
+ if (schemaHasType(prop, "boolean")) {
45
+ return { ...base, kind: "boolean" };
46
+ }
47
+ if (schemaHasType(prop, "integer") || schemaHasType(prop, "number")) {
48
+ return {
49
+ ...base,
50
+ kind: "number",
51
+ coerceNumber: true,
52
+ ...typeof prop.minimum === "number" ? { minimum: prop.minimum } : {}
53
+ };
54
+ }
55
+ if (schemaHasType(prop, "array")) {
56
+ return { ...base, kind: "array", ...prop.items ? { itemSchema: prop.items } : {} };
57
+ }
58
+ if (isOpenStringMap(prop)) {
59
+ return {
60
+ ...base,
61
+ kind: "string-map",
62
+ valueSchema: prop.additionalProperties,
63
+ ...prop.properties ? { knownProperties: prop.properties } : {},
64
+ allowExtraKeys: true
65
+ };
66
+ }
67
+ if (schemaHasType(prop, "object") && prop.properties) {
68
+ return {
69
+ ...base,
70
+ kind: "object",
71
+ objectProperties: prop.properties,
72
+ ...prop.required ? { objectRequired: prop.required } : {}
73
+ };
74
+ }
75
+ if (schemaHasType(prop, "object")) {
76
+ return { ...base, kind: "string-map", allowExtraKeys: prop.additionalProperties !== false };
77
+ }
78
+ return base;
79
+ }
80
+ function isScalarStringItems(items) {
81
+ if (!items) return true;
82
+ if (items.type !== void 0 && !schemaHasType(items, "string")) return false;
83
+ return items.enum === void 0 && items.const === void 0 && items.properties === void 0 && items.items === void 0 && items.additionalProperties === void 0 && items.allOf === void 0;
84
+ }
85
+ function matchesIf(ifSchema, value) {
86
+ if (!ifSchema) return false;
87
+ for (const k of ifSchema.required ?? []) {
88
+ if (!(k in value)) return false;
89
+ }
90
+ for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {
91
+ if ("const" in sub && value[k] !== sub.const) return false;
92
+ }
93
+ return true;
94
+ }
95
+ function effectiveProperties(schema, value) {
96
+ const properties = { ...schema.properties ?? {} };
97
+ const required = new Set(schema.required ?? []);
98
+ for (const clause of schema.allOf ?? []) {
99
+ if (clause.if === void 0 && clause.then === void 0) {
100
+ for (const [k, sub] of Object.entries(clause.properties ?? {})) {
101
+ properties[k] = sub;
102
+ }
103
+ for (const k of clause.required ?? []) required.add(k);
104
+ continue;
105
+ }
106
+ if (!matchesIf(clause.if, value)) continue;
107
+ const then = clause.then ?? {};
108
+ for (const [k, sub] of Object.entries(then.properties ?? {})) {
109
+ properties[k] = sub;
110
+ }
111
+ for (const k of then.required ?? []) required.add(k);
112
+ }
113
+ return { properties, required: [...required] };
114
+ }
115
+ exports.effectiveProperties = effectiveProperties;
116
+ exports.enumBranch = enumBranch;
117
+ exports.isOpenStringMap = isOpenStringMap;
118
+ exports.isScalarStringItems = isScalarStringItems;
119
+ exports.matchesIf = matchesIf;
120
+ exports.resolveControl = resolveControl;
121
+ //# sourceMappingURL=json-schema-form-resolve.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-resolve.cjs","sources":["../../src/components/json-schema-form-resolve.ts"],"sourcesContent":["import type {\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map).\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n return (\n schemaHasType(prop, \"object\") &&\n typeof prop.additionalProperties === \"object\" &&\n prop.additionalProperties !== null\n );\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n return (prop.enum ?? []).map((v) => ({ value: String(v), label: String(v) }));\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n return { ...base, kind: \"enum\", options: enumOptions(prop) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return { ...base, kind: \"array\", ...(prop.items ? { itemSchema: prop.items } : {}) };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema. Renders as editable key/value rows (+ any known properties).\n if (isOpenStringMap(prop)) {\n return {\n ...base,\n kind: \"string-map\",\n valueSchema: prop.additionalProperties as JsonSchemaProperty,\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys: true,\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return { ...base, kind: \"string-map\", allowExtraKeys: prop.additionalProperties !== false };\n }\n return base;\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...(schema.properties ?? {}) };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?? []) required.add(k);\n }\n return { properties, required: [...required] };\n}\n"],"names":[],"mappings":";;AASO,SAAS,gBAAgB,MAAmC;AACjE,SACE,cAAc,MAAM,QAAQ,KAC5B,OAAO,KAAK,yBAAyB,YACrC,KAAK,yBAAyB;AAElC;AAEA,SAAS,cAAc,MAA0B,MAAuB;AACtE,MAAI,MAAM,QAAQ,KAAK,IAAI,EAAG,QAAO,KAAK,KAAK,SAAS,IAAa;AACrE,SAAO,KAAK,SAAS;AACvB;AAEA,SAAS,YAAY,MAAyC;AAC5D,UAAQ,KAAK,QAAQ,CAAA,GAAI,IAAI,CAAC,OAAO,EAAE,OAAO,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,IAAI;AAC9E;AAMO,SAAS,WAAW,MAA0D;AACnF,aAAW,UAAU,CAAC,GAAI,KAAK,SAAS,CAAA,GAAK,GAAI,KAAK,SAAS,CAAA,CAAG,GAAG;AACnE,QAAI,MAAM,QAAQ,OAAO,IAAI,KAAK,OAAO,KAAK,SAAS,EAAG,QAAO;AAAA,EACnE;AACA,SAAO;AACT;AAeO,SAAS,eAAe,MAAwC;AACrE,QAAM,EAAE,KAAK,MAAM,UAAU,OAAO,aAAa;AACjD,QAAM,YAAY,KAAK,QAAQ;AAC/B,QAAM,OAAqB;AAAA,IACz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AAI,OAAO,YAAY,CAAA,CAAE;AAC9C,aAAW,UAAU,OAAO,SAAS,CAAA,GAAI;AAEvC,QAAI,OAAO,OAAO,UAAa,OAAO,SAAS,QAAW;AACxD,iBAAW,CAAC,GAAG,GAAG,KAAK,OAAO,QAAQ,OAAO,cAAc,CAAA,CAAE,GAAG;AAC9D,mBAAW,CAAC,IAAI;AAAA,MAClB;AACA,iBAAW,KAAK,OAAO,YAAY,CAAA,EAAI,UAAS,IAAI,CAAC;AACrD;AAAA,IACF;AACA,QAAI,CAAC,UAAU,OAAO,IAAI,KAAK,EAAG;AAClC,UAAM,OAAO,OAAO,QAAQ,CAAA;AAC5B,eAAW,CAAC,GAAG,GAAG,KAAK,OAAO,QAAQ,KAAK,cAAc,CAAA,CAAE,GAAG;AAC5D,iBAAW,CAAC,IAAI;AAAA,IAClB;AACA,eAAW,KAAK,KAAK,YAAY,CAAA,EAAI,UAAS,IAAI,CAAC;AAAA,EACrD;AACA,SAAO,EAAE,YAAY,UAAU,CAAC,GAAG,QAAQ,EAAA;AAC7C;;;;;;;"}
@@ -0,0 +1,19 @@
1
+ import { FieldControl, JsonSchemaObject, JsonSchemaProperty } from './json-schema-form-types';
2
+ export declare function isOpenStringMap(prop: JsonSchemaProperty): boolean;
3
+ export declare function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined;
4
+ export interface ResolveControlArgs {
5
+ key: string;
6
+ prop: JsonSchemaProperty;
7
+ required: boolean;
8
+ value: unknown;
9
+ onChange: (next: unknown) => void;
10
+ }
11
+ export declare function resolveControl(args: ResolveControlArgs): FieldControl;
12
+ export declare function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean;
13
+ export declare function matchesIf(ifSchema: JsonSchemaProperty | undefined, value: Record<string, unknown>): boolean;
14
+ export interface EffectiveProperties {
15
+ properties: Record<string, JsonSchemaProperty>;
16
+ required: string[];
17
+ }
18
+ export declare function effectiveProperties(schema: JsonSchemaObject, value: Record<string, unknown>): EffectiveProperties;
19
+ //# sourceMappingURL=json-schema-form-resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-resolve.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAEZ,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAIlC,wBAAgB,eAAe,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAMjE;AAeD,wBAAgB,UAAU,CAAC,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS,CAKnF;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC;AAOD,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,YAAY,CAuErE;AAMD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,GAAG,OAAO,CAWlF;AAKD,wBAAgB,SAAS,CACvB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,EACxC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAST;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAQD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,mBAAmB,CAoBrB"}
@@ -0,0 +1,121 @@
1
+ function isOpenStringMap(prop) {
2
+ return schemaHasType(prop, "object") && typeof prop.additionalProperties === "object" && prop.additionalProperties !== null;
3
+ }
4
+ function schemaHasType(prop, type) {
5
+ if (Array.isArray(prop.type)) return prop.type.includes(type);
6
+ return prop.type === type;
7
+ }
8
+ function enumOptions(prop) {
9
+ return (prop.enum ?? []).map((v) => ({ value: String(v), label: String(v) }));
10
+ }
11
+ function enumBranch(prop) {
12
+ for (const branch of [...prop.anyOf ?? [], ...prop.oneOf ?? []]) {
13
+ if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;
14
+ }
15
+ return void 0;
16
+ }
17
+ function resolveControl(args) {
18
+ const { key, prop, required, value, onChange } = args;
19
+ const labelIcon = prop["x-icon"];
20
+ const base = {
21
+ key,
22
+ kind: "string",
23
+ label: typeof prop.title === "string" && prop.title ? prop.title : key,
24
+ required,
25
+ schema: prop,
26
+ value,
27
+ onChange,
28
+ ...prop.readOnly === true ? { readOnly: true } : {},
29
+ ...typeof prop.description === "string" ? { description: prop.description } : {},
30
+ ...labelIcon != null && labelIcon !== "" ? { labelIcon } : {}
31
+ };
32
+ if (Array.isArray(prop.enum) && prop.enum.length > 0) {
33
+ return { ...base, kind: "enum", options: enumOptions(prop) };
34
+ }
35
+ const branch = enumBranch(prop);
36
+ if (branch) {
37
+ return { ...base, kind: "enum", options: enumOptions(branch) };
38
+ }
39
+ if (prop.format === "date" || prop.format === "date-time") {
40
+ return { ...base, kind: "date", dateFormat: prop.format };
41
+ }
42
+ if (schemaHasType(prop, "boolean")) {
43
+ return { ...base, kind: "boolean" };
44
+ }
45
+ if (schemaHasType(prop, "integer") || schemaHasType(prop, "number")) {
46
+ return {
47
+ ...base,
48
+ kind: "number",
49
+ coerceNumber: true,
50
+ ...typeof prop.minimum === "number" ? { minimum: prop.minimum } : {}
51
+ };
52
+ }
53
+ if (schemaHasType(prop, "array")) {
54
+ return { ...base, kind: "array", ...prop.items ? { itemSchema: prop.items } : {} };
55
+ }
56
+ if (isOpenStringMap(prop)) {
57
+ return {
58
+ ...base,
59
+ kind: "string-map",
60
+ valueSchema: prop.additionalProperties,
61
+ ...prop.properties ? { knownProperties: prop.properties } : {},
62
+ allowExtraKeys: true
63
+ };
64
+ }
65
+ if (schemaHasType(prop, "object") && prop.properties) {
66
+ return {
67
+ ...base,
68
+ kind: "object",
69
+ objectProperties: prop.properties,
70
+ ...prop.required ? { objectRequired: prop.required } : {}
71
+ };
72
+ }
73
+ if (schemaHasType(prop, "object")) {
74
+ return { ...base, kind: "string-map", allowExtraKeys: prop.additionalProperties !== false };
75
+ }
76
+ return base;
77
+ }
78
+ function isScalarStringItems(items) {
79
+ if (!items) return true;
80
+ if (items.type !== void 0 && !schemaHasType(items, "string")) return false;
81
+ return items.enum === void 0 && items.const === void 0 && items.properties === void 0 && items.items === void 0 && items.additionalProperties === void 0 && items.allOf === void 0;
82
+ }
83
+ function matchesIf(ifSchema, value) {
84
+ if (!ifSchema) return false;
85
+ for (const k of ifSchema.required ?? []) {
86
+ if (!(k in value)) return false;
87
+ }
88
+ for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {
89
+ if ("const" in sub && value[k] !== sub.const) return false;
90
+ }
91
+ return true;
92
+ }
93
+ function effectiveProperties(schema, value) {
94
+ const properties = { ...schema.properties ?? {} };
95
+ const required = new Set(schema.required ?? []);
96
+ for (const clause of schema.allOf ?? []) {
97
+ if (clause.if === void 0 && clause.then === void 0) {
98
+ for (const [k, sub] of Object.entries(clause.properties ?? {})) {
99
+ properties[k] = sub;
100
+ }
101
+ for (const k of clause.required ?? []) required.add(k);
102
+ continue;
103
+ }
104
+ if (!matchesIf(clause.if, value)) continue;
105
+ const then = clause.then ?? {};
106
+ for (const [k, sub] of Object.entries(then.properties ?? {})) {
107
+ properties[k] = sub;
108
+ }
109
+ for (const k of then.required ?? []) required.add(k);
110
+ }
111
+ return { properties, required: [...required] };
112
+ }
113
+ export {
114
+ effectiveProperties,
115
+ enumBranch,
116
+ isOpenStringMap,
117
+ isScalarStringItems,
118
+ matchesIf,
119
+ resolveControl
120
+ };
121
+ //# sourceMappingURL=json-schema-form-resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-resolve.js","sources":["../../src/components/json-schema-form-resolve.ts"],"sourcesContent":["import type {\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map).\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n return (\n schemaHasType(prop, \"object\") &&\n typeof prop.additionalProperties === \"object\" &&\n prop.additionalProperties !== null\n );\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n return (prop.enum ?? []).map((v) => ({ value: String(v), label: String(v) }));\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n return { ...base, kind: \"enum\", options: enumOptions(prop) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return { ...base, kind: \"array\", ...(prop.items ? { itemSchema: prop.items } : {}) };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema. Renders as editable key/value rows (+ any known properties).\n if (isOpenStringMap(prop)) {\n return {\n ...base,\n kind: \"string-map\",\n valueSchema: prop.additionalProperties as JsonSchemaProperty,\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys: true,\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return { ...base, kind: \"string-map\", allowExtraKeys: prop.additionalProperties !== false };\n }\n return base;\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...(schema.properties ?? {}) };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?? []) required.add(k);\n }\n return { properties, required: [...required] };\n}\n"],"names":[],"mappings":"AASO,SAAS,gBAAgB,MAAmC;AACjE,SACE,cAAc,MAAM,QAAQ,KAC5B,OAAO,KAAK,yBAAyB,YACrC,KAAK,yBAAyB;AAElC;AAEA,SAAS,cAAc,MAA0B,MAAuB;AACtE,MAAI,MAAM,QAAQ,KAAK,IAAI,EAAG,QAAO,KAAK,KAAK,SAAS,IAAa;AACrE,SAAO,KAAK,SAAS;AACvB;AAEA,SAAS,YAAY,MAAyC;AAC5D,UAAQ,KAAK,QAAQ,CAAA,GAAI,IAAI,CAAC,OAAO,EAAE,OAAO,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,IAAI;AAC9E;AAMO,SAAS,WAAW,MAA0D;AACnF,aAAW,UAAU,CAAC,GAAI,KAAK,SAAS,CAAA,GAAK,GAAI,KAAK,SAAS,CAAA,CAAG,GAAG;AACnE,QAAI,MAAM,QAAQ,OAAO,IAAI,KAAK,OAAO,KAAK,SAAS,EAAG,QAAO;AAAA,EACnE;AACA,SAAO;AACT;AAeO,SAAS,eAAe,MAAwC;AACrE,QAAM,EAAE,KAAK,MAAM,UAAU,OAAO,aAAa;AACjD,QAAM,YAAY,KAAK,QAAQ;AAC/B,QAAM,OAAqB;AAAA,IACzB;AAAA,IACA,MAAM;AAAA,IACN,OAAO,OAAO,KAAK,UAAU,YAAY,KAAK,QAAQ,KAAK,QAAQ;AAAA,IACnE;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,GAAI,KAAK,aAAa,OAAO,EAAE,UAAU,KAAA,IAAS,CAAA;AAAA,IAClD,GAAI,OAAO,KAAK,gBAAgB,WAAW,EAAE,aAAa,KAAK,YAAA,IAAgB,CAAA;AAAA,IAC/E,GAAI,aAAa,QAAQ,cAAc,KAAK,EAAE,UAAA,IAAsD,C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I,KAAK,EAAG;AAClC,UAAM,OAAO,OAAO,QAAQ,CAAA;AAC5B,eAAW,CAAC,GAAG,GAAG,KAAK,OAAO,QAAQ,KAAK,cAAc,CAAA,CAAE,GAAG;AAC5D,iBAAW,CAAC,IAAI;AAAA,IAClB;AACA,eAAW,KAAK,KAAK,YAAY,CAAA,EAAI,UAAS,IAAI,CAAC;AAAA,EACrD;AACA,SAAO,EAAE,YAAY,UAAU,CAAC,GAAG,QAAQ,EAAA;AAC7C;"}
@@ -0,0 +1,124 @@
1
+ import { ReactNode } from 'react';
2
+ import { LabelIconSpec } from '../data/Icon';
3
+ export interface JsonSchemaProperty {
4
+ type?: JsonSchemaType | JsonSchemaType[];
5
+ description?: string;
6
+ title?: string;
7
+ enum?: unknown[];
8
+ const?: unknown;
9
+ default?: unknown;
10
+ format?: string;
11
+ readOnly?: boolean;
12
+ minimum?: number;
13
+ maximum?: number;
14
+ items?: JsonSchemaProperty;
15
+ properties?: Record<string, JsonSchemaProperty>;
16
+ required?: string[];
17
+ additionalProperties?: boolean | JsonSchemaProperty;
18
+ allOf?: JsonSchemaConditional[];
19
+ anyOf?: JsonSchemaProperty[];
20
+ oneOf?: JsonSchemaProperty[];
21
+ if?: JsonSchemaProperty;
22
+ then?: JsonSchemaProperty;
23
+ else?: JsonSchemaProperty;
24
+ [key: string]: unknown;
25
+ }
26
+ export type JsonSchemaType = "object" | "array" | "string" | "integer" | "number" | "boolean" | "null";
27
+ export interface JsonSchemaConditional {
28
+ if?: JsonSchemaProperty;
29
+ then?: JsonSchemaProperty;
30
+ properties?: Record<string, JsonSchemaProperty>;
31
+ required?: string[];
32
+ }
33
+ export interface JsonSchemaObject extends JsonSchemaProperty {
34
+ type?: "object";
35
+ properties?: Record<string, JsonSchemaProperty>;
36
+ required?: string[];
37
+ additionalProperties?: boolean | JsonSchemaProperty;
38
+ allOf?: JsonSchemaConditional[];
39
+ }
40
+ export type FieldControlKind = "string" | "number" | "boolean" | "enum" | "date" | "string-map" | "array" | "object";
41
+ export type EnumDisplay = "combobox" | "radio";
42
+ export interface FieldControl {
43
+ key: string;
44
+ kind: FieldControlKind;
45
+ label: string;
46
+ description?: string;
47
+ required: boolean;
48
+ schema: JsonSchemaProperty;
49
+ value: unknown;
50
+ onChange: (next: unknown) => void;
51
+ readOnly?: boolean;
52
+ labelIcon?: LabelIconSpec;
53
+ options?: FieldOption[];
54
+ allowCustomValue?: boolean;
55
+ display?: EnumDisplay;
56
+ badge?: string;
57
+ helper?: string;
58
+ minimum?: number;
59
+ coerceNumber?: boolean;
60
+ dateFormat?: "date" | "date-time";
61
+ valueSchema?: JsonSchemaProperty;
62
+ knownProperties?: Record<string, JsonSchemaProperty>;
63
+ allowExtraKeys?: boolean;
64
+ itemSchema?: JsonSchemaProperty;
65
+ objectProperties?: Record<string, JsonSchemaProperty>;
66
+ objectRequired?: string[];
67
+ }
68
+ export interface FieldOption {
69
+ value: string;
70
+ label: string;
71
+ }
72
+ export type PreExtension = (field: FieldControl, ctx: {
73
+ key: string;
74
+ prop: JsonSchemaProperty;
75
+ value: unknown;
76
+ }) => FieldControl | null;
77
+ export type PostExtension = (field: FieldControl, nodes: {
78
+ label: ReactNode;
79
+ value: ReactNode;
80
+ }) => {
81
+ label: ReactNode;
82
+ value: ReactNode;
83
+ };
84
+ export interface FormLayout {
85
+ /** "inline" = 2-column label/value; "stacked" = label above value. */
86
+ mode: "inline" | "stacked";
87
+ /** Inline only: max width of the label column (CSS length). Default "40ch". */
88
+ labelMaxWidth?: string;
89
+ /** Inline only: max width of the value column (CSS length). Default "400px". */
90
+ valueMaxWidth?: string;
91
+ }
92
+ export interface JsonSchemaFormProps {
93
+ schema: JsonSchemaObject;
94
+ value: Record<string, unknown>;
95
+ onChange: (next: Record<string, unknown>) => void;
96
+ readOnly?: boolean;
97
+ /**
98
+ * Shorthand for `layout: { mode: "inline" }` (2-column label/value); stacked
99
+ * when false (default). Ignored when `layout` is provided.
100
+ */
101
+ inline?: boolean;
102
+ /**
103
+ * Form-level layout. Takes precedence over `inline`. Inline mode caps the
104
+ * label column (default 40ch) and value column (default 400px).
105
+ */
106
+ layout?: FormLayout;
107
+ /**
108
+ * Omit fields whose schema declares `readOnly: true` entirely, instead of
109
+ * rendering them as read-only value displays. Applies at every depth.
110
+ */
111
+ hideReadOnlyFields?: boolean;
112
+ /** Property keys to omit from rendering. */
113
+ hiddenKeys?: string[];
114
+ /**
115
+ * Render required fields before optional ones at every object level. The sort
116
+ * is stable: required keys keep their relative order, then optional keys keep
117
+ * theirs. Defaults to false (schema property order is preserved).
118
+ */
119
+ requiredFirst?: boolean;
120
+ title?: string;
121
+ pre?: PreExtension[];
122
+ post?: PostExtension[];
123
+ }
124
+ //# sourceMappingURL=json-schema-form-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-form-types.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,EAAE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