@contractspec/lib.contracts-runtime-client-react 3.8.4 → 3.8.6

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.
@@ -1,15 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/drivers/rn-reusables.ts
10
- function rnReusablesDriver(slots) {
11
- return slots;
12
- }
13
- export {
14
- rnReusablesDriver
15
- };
1
+ var o=((r)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function i(r){return r}export{i as rnReusablesDriver};
@@ -1,15 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/drivers/shadcn.ts
10
- function shadcnDriver(slots) {
11
- return slots;
12
- }
13
- export {
14
- shadcnDriver
15
- };
1
+ var o=((r)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});function n(r){return r}export{n as shadcnDriver};
@@ -1,108 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/transform-engine.ts
10
- import {
11
- createDefaultTransformEngine,
12
- htmlToMarkdown,
13
- registerBasicValidation
14
- } from "@contractspec/lib.presentation-runtime-core/transform-engine";
15
- import React from "react";
16
-
17
- export * from "@contractspec/lib.presentation-runtime-core/transform-engine";
18
- function registerDefaultReactRenderer(engine) {
19
- engine.register({
20
- target: "react",
21
- async render(desc) {
22
- if (desc.source.type === "component") {
23
- const props = desc.source.props ? desc.source.props.getZod().safeParse({}).success ? {} : undefined : undefined;
24
- return {
25
- kind: "react_component",
26
- componentKey: desc.source.componentKey,
27
- props
28
- };
29
- }
30
- return {
31
- kind: "blocknotejs",
32
- docJson: desc.source.docJson,
33
- blockConfig: desc.source.blockConfig
34
- };
35
- }
36
- });
37
- return engine;
38
- }
39
- function registerReactToMarkdownRenderer(engine, componentMap) {
40
- engine.prependRegister({
41
- target: "markdown",
42
- async render(desc) {
43
- if (desc.source.type !== "component") {
44
- throw new Error("React-to-markdown renderer only handles component presentations");
45
- }
46
- const Component = componentMap[desc.source.componentKey];
47
- if (!Component) {
48
- throw new Error(`Component ${desc.source.componentKey} not found in componentMap`);
49
- }
50
- const { renderToStaticMarkup } = await import("react-dom/server");
51
- const element = React.createElement(Component, desc.source.props ? {} : undefined);
52
- const markdown = htmlToMarkdown(renderToStaticMarkup(element));
53
- return {
54
- mimeType: "text/markdown",
55
- body: desc.policy?.pii?.length ? markdown.replace(/\[REDACTED\]/g, "[REDACTED]") : markdown
56
- };
57
- }
58
- });
59
- return engine;
60
- }
61
-
62
- // src/feature-render.ts
63
- import React2 from "react";
64
- function createEngineWithDefaults() {
65
- return registerBasicValidation(registerDefaultReactRenderer(createDefaultTransformEngine()));
66
- }
67
- async function renderFeaturePresentation(engine, target, desc, options) {
68
- if (target === "react") {
69
- const rd = await engine.render("react", desc);
70
- if (rd.kind === "react_component") {
71
- const map = options?.componentMap ?? {};
72
- const C = map[rd.componentKey];
73
- if (!C)
74
- return null;
75
- const merged = {
76
- ...rd.props ?? {},
77
- ...options?.reactProps ?? {}
78
- };
79
- return React2.createElement(C, merged);
80
- }
81
- if (rd.kind === "blocknotejs") {
82
- if (options?.renderBlockNote)
83
- return options.renderBlockNote(rd.docJson, rd.blockConfig);
84
- return React2.createElement("div", {}, "[BlockNote renderer not configured]");
85
- }
86
- return null;
87
- }
88
- if (target === "markdown")
89
- return engine.render(target, desc);
90
- if (target === "application/json")
91
- return engine.render(target, desc);
92
- if (target === "application/xml")
93
- return engine.render(target, desc);
94
- return null;
95
- }
96
- function createFeatureModule(meta, refs) {
97
- return { meta, ...refs };
98
- }
99
- function registerFeature(registry, feature) {
100
- registry.register(feature);
101
- return registry;
102
- }
103
- export {
104
- renderFeaturePresentation,
105
- registerFeature,
106
- createFeatureModule,
107
- createEngineWithDefaults
108
- };
1
+ var N=((q)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(q,{get:(j,x)=>(typeof require<"u"?require:j)[x]}):q)(function(q){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+q+'" is not supported')});import{createDefaultTransformEngine as H,htmlToMarkdown as O,registerBasicValidation as I}from"@contractspec/lib.presentation-runtime-core/transform-engine";import P from"react";export*from"@contractspec/lib.presentation-runtime-core/transform-engine";function J(q){return q.register({target:"react",async render(j){if(j.source.type==="component"){let x=j.source.props?j.source.props.getZod().safeParse({}).success?{}:void 0:void 0;return{kind:"react_component",componentKey:j.source.componentKey,props:x}}return{kind:"blocknotejs",docJson:j.source.docJson,blockConfig:j.source.blockConfig}}}),q}function X(q,j){return q.prependRegister({target:"markdown",async render(x){if(x.source.type!=="component")throw Error("React-to-markdown renderer only handles component presentations");let A=j[x.source.componentKey];if(!A)throw Error(`Component ${x.source.componentKey} not found in componentMap`);let{renderToStaticMarkup:z}=await import("react-dom/server"),G=P.createElement(A,x.source.props?{}:void 0),F=O(z(G));return{mimeType:"text/markdown",body:x.policy?.pii?.length?F.replace(/\[REDACTED\]/g,"[REDACTED]"):F}}}),q}import K from"react";function v(){return I(J(H()))}async function S(q,j,x,A){if(j==="react"){let z=await q.render("react",x);if(z.kind==="react_component"){let F=(A?.componentMap??{})[z.componentKey];if(!F)return null;let L={...z.props??{},...A?.reactProps??{}};return K.createElement(F,L)}if(z.kind==="blocknotejs"){if(A?.renderBlockNote)return A.renderBlockNote(z.docJson,z.blockConfig);return K.createElement("div",{},"[BlockNote renderer not configured]")}return null}if(j==="markdown")return q.render(j,x);if(j==="application/json")return q.render(j,x);if(j==="application/xml")return q.render(j,x);return null}function b(q,j){return{meta:q,...j}}function B(q,j){return q.register(j),q}export{S as renderFeaturePresentation,B as registerFeature,b as createFeatureModule,v as createEngineWithDefaults};
@@ -1,367 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/form-render.impl.tsx
10
- import {
11
- buildZodWithRelations,
12
- evalPredicate
13
- } from "@contractspec/lib.contracts-spec/forms";
14
- import { zodResolver } from "@hookform/resolvers/zod";
15
- import React, { useEffect, useMemo, useState } from "react";
16
- import {
17
- Controller,
18
- useFieldArray,
19
- useForm
20
- } from "react-hook-form";
21
- import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
22
- "use client";
23
- function toOptionsArray(src) {
24
- if (!src)
25
- return;
26
- if (Array.isArray(src))
27
- return { kind: "static", options: src };
28
- return src;
29
- }
30
- function getAtPath(values, path) {
31
- if (!path)
32
- return;
33
- const segs = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
34
- let cur = values;
35
- for (const s of segs) {
36
- if (cur == null)
37
- return;
38
- cur = cur[s];
39
- }
40
- return cur;
41
- }
42
- function makeDepsKey(values, deps) {
43
- if (!deps || deps.length === 0)
44
- return "[]";
45
- try {
46
- return JSON.stringify(deps.map((d) => getAtPath(values, d)));
47
- } catch {
48
- return "[]";
49
- }
50
- }
51
- function useResolvedOptions(values, source, resolvers) {
52
- const [opts, setOpts] = useState([]);
53
- const depKey = useMemo(() => {
54
- if (!source)
55
- return "nil";
56
- if (source.kind === "static")
57
- return JSON.stringify(source.options ?? []);
58
- return makeDepsKey(values, source.deps);
59
- }, [source, values]);
60
- useEffect(() => {
61
- let mounted = true;
62
- const run = async () => {
63
- if (!source)
64
- return setOpts([]);
65
- if (source.kind === "static")
66
- return setOpts([...source.options ?? []]);
67
- const fn = resolvers?.[source.resolverKey];
68
- if (!fn)
69
- return setOpts([]);
70
- const res = await fn(values, source.args);
71
- if (mounted)
72
- setOpts([...res ?? []]);
73
- };
74
- run();
75
- return () => {
76
- mounted = false;
77
- };
78
- }, [
79
- depKey,
80
- source && source.kind === "resolver" ? source.resolverKey : undefined
81
- ]);
82
- return opts;
83
- }
84
- function fieldPath(parent, name, arrayIndex) {
85
- if (!name)
86
- return parent ?? "";
87
- const child = typeof arrayIndex === "number" ? `${name.replace(/^\$index$/, String(arrayIndex))}` : name;
88
- return parent ? `${parent}${typeof arrayIndex === "number" ? `.${arrayIndex}` : ""}.${child}`.replace(/\.+/g, ".") : child;
89
- }
90
- function createFormRenderer(base) {
91
- const conf = base;
92
- const { driver } = conf;
93
- function InternalForm(props) {
94
- const { spec, options, merged } = props;
95
- const baseZod = useMemo(() => buildZodWithRelations(spec), [spec]);
96
- const form = useForm({
97
- ...merged.formOptions,
98
- resolver: zodResolver(baseZod),
99
- defaultValues: options?.defaultValues
100
- });
101
- const values = form.watch();
102
- const renderOne = (f, parent, arrayIndex) => {
103
- const DriverField = driver.Field;
104
- const DriverLabel = driver.FieldLabel;
105
- const DriverDesc = driver.FieldDescription;
106
- const DriverError = driver.FieldError;
107
- const name = fieldPath(parent, f.name, arrayIndex);
108
- const visible = evalPredicate(values, f.visibleWhen);
109
- const enabled = evalPredicate(values, f.enabledWhen);
110
- const invalid = Boolean(form.getFieldState(name)?.invalid);
111
- if (!visible)
112
- return null;
113
- const id = name?.replace(/\./g, "-");
114
- const commonWrapProps = {
115
- "data-invalid": invalid,
116
- hidden: !visible,
117
- disabled: !enabled
118
- };
119
- const labelNode = f.labelI18n ? /* @__PURE__ */ jsxDEV(DriverLabel, {
120
- htmlFor: id,
121
- children: f.labelI18n
122
- }, undefined, false, undefined, this) : null;
123
- const descNode = f.descriptionI18n ? /* @__PURE__ */ jsxDEV(DriverDesc, {
124
- children: f.descriptionI18n
125
- }, undefined, false, undefined, this) : null;
126
- if (f.kind === "group") {
127
- const children = f.fields.map((c, i) => /* @__PURE__ */ jsxDEV(React.Fragment, {
128
- children: renderOne(c, name, arrayIndex)
129
- }, `${name}-${i}`, false, undefined, this));
130
- return /* @__PURE__ */ jsxDEV(DriverField, {
131
- ...commonWrapProps,
132
- children: [
133
- labelNode,
134
- children,
135
- descNode
136
- ]
137
- }, undefined, true, undefined, this);
138
- }
139
- if (f.kind === "array") {
140
- return renderArray(f, parent);
141
- }
142
- return /* @__PURE__ */ jsxDEV(Controller, {
143
- name,
144
- control: form.control,
145
- render: ({ field, fieldState }) => {
146
- const err = fieldState.error ? [fieldState.error] : [];
147
- const ariaInvalid = fieldState.invalid || undefined;
148
- if (f.kind === "text") {
149
- const textField = f;
150
- const Input = driver.Input;
151
- return /* @__PURE__ */ jsxDEV(DriverField, {
152
- ...commonWrapProps,
153
- children: [
154
- labelNode,
155
- /* @__PURE__ */ jsxDEV(Input, {
156
- id,
157
- "aria-invalid": ariaInvalid,
158
- placeholder: f.placeholderI18n,
159
- autoComplete: textField.autoComplete,
160
- inputMode: textField.inputMode,
161
- maxLength: textField.maxLength,
162
- minLength: textField.minLength,
163
- disabled: !enabled,
164
- ...field,
165
- ...f.uiProps
166
- }, undefined, false, undefined, this),
167
- descNode,
168
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
169
- errors: err
170
- }, undefined, false, undefined, this) : null
171
- ]
172
- }, undefined, true, undefined, this);
173
- }
174
- if (f.kind === "textarea") {
175
- const textareaField = f;
176
- const Textarea = driver.Textarea;
177
- return /* @__PURE__ */ jsxDEV(DriverField, {
178
- ...commonWrapProps,
179
- children: [
180
- labelNode,
181
- /* @__PURE__ */ jsxDEV(Textarea, {
182
- id,
183
- "aria-invalid": ariaInvalid,
184
- placeholder: f.placeholderI18n,
185
- rows: textareaField.rows,
186
- maxLength: textareaField.maxLength,
187
- disabled: !enabled,
188
- ...field,
189
- ...f.uiProps
190
- }, undefined, false, undefined, this),
191
- descNode,
192
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
193
- errors: err
194
- }, undefined, false, undefined, this) : null
195
- ]
196
- }, undefined, true, undefined, this);
197
- }
198
- if (f.kind === "select") {
199
- const selectField = f;
200
- const Select = driver.Select;
201
- const src = toOptionsArray(selectField.options);
202
- const opts = useResolvedOptions(values, src, merged.resolvers);
203
- return /* @__PURE__ */ jsxDEV(DriverField, {
204
- ...commonWrapProps,
205
- children: [
206
- labelNode,
207
- /* @__PURE__ */ jsxDEV(Select, {
208
- id,
209
- name,
210
- "aria-invalid": ariaInvalid,
211
- disabled: !enabled,
212
- value: field.value,
213
- onChange: (v) => field.onChange(v),
214
- options: opts,
215
- ...f.uiProps
216
- }, undefined, false, undefined, this),
217
- descNode,
218
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
219
- errors: err
220
- }, undefined, false, undefined, this) : null
221
- ]
222
- }, undefined, true, undefined, this);
223
- }
224
- if (f.kind === "checkbox") {
225
- const Checkbox = driver.Checkbox;
226
- return /* @__PURE__ */ jsxDEV(DriverField, {
227
- ...commonWrapProps,
228
- children: [
229
- labelNode,
230
- /* @__PURE__ */ jsxDEV(Checkbox, {
231
- id,
232
- name,
233
- disabled: !enabled,
234
- checked: !!field.value,
235
- onCheckedChange: (v) => field.onChange(v),
236
- ...f.uiProps
237
- }, undefined, false, undefined, this),
238
- descNode,
239
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
240
- errors: err
241
- }, undefined, false, undefined, this) : null
242
- ]
243
- }, undefined, true, undefined, this);
244
- }
245
- if (f.kind === "radio") {
246
- const radioField = f;
247
- const RadioGroup = driver.RadioGroup;
248
- const src = toOptionsArray(radioField.options);
249
- const opts = useResolvedOptions(values, src, merged.resolvers);
250
- return /* @__PURE__ */ jsxDEV(DriverField, {
251
- ...commonWrapProps,
252
- children: [
253
- labelNode,
254
- /* @__PURE__ */ jsxDEV(RadioGroup, {
255
- id,
256
- name,
257
- disabled: !enabled,
258
- value: field.value,
259
- onValueChange: (v) => field.onChange(v),
260
- options: opts,
261
- ...f.uiProps
262
- }, undefined, false, undefined, this),
263
- descNode,
264
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
265
- errors: err
266
- }, undefined, false, undefined, this) : null
267
- ]
268
- }, undefined, true, undefined, this);
269
- }
270
- if (f.kind === "switch") {
271
- const Switch = driver.Switch;
272
- return /* @__PURE__ */ jsxDEV(DriverField, {
273
- ...commonWrapProps,
274
- children: [
275
- labelNode,
276
- /* @__PURE__ */ jsxDEV(Switch, {
277
- id,
278
- name,
279
- disabled: !enabled,
280
- checked: !!field.value,
281
- onCheckedChange: (v) => field.onChange(v),
282
- ...f.uiProps
283
- }, undefined, false, undefined, this),
284
- descNode,
285
- fieldState.invalid ? /* @__PURE__ */ jsxDEV(DriverError, {
286
- errors: err
287
- }, undefined, false, undefined, this) : null
288
- ]
289
- }, undefined, true, undefined, this);
290
- }
291
- return /* @__PURE__ */ jsxDEV(Fragment, {}, undefined, false, undefined, this);
292
- }
293
- }, name, false, undefined, this);
294
- };
295
- const renderArray = (f, parent) => {
296
- const name = fieldPath(parent, f.name);
297
- const { fields, append, remove } = useFieldArray({
298
- control: form.control,
299
- name
300
- });
301
- const canAdd = f.max == null || fields.length < f.max;
302
- const canRemove = (idx) => (f.min == null ? fields.length > 0 : fields.length > f.min) && idx >= 0;
303
- const Button2 = driver.Button;
304
- const Label = driver.FieldLabel;
305
- return /* @__PURE__ */ jsxDEV("div", {
306
- children: [
307
- f.labelI18n ? /* @__PURE__ */ jsxDEV(Label, {
308
- children: f.labelI18n
309
- }, undefined, false, undefined, this) : null,
310
- fields.map((row, idx) => /* @__PURE__ */ jsxDEV("div", {
311
- children: [
312
- renderOne(f.of, name, idx),
313
- canRemove(idx) ? /* @__PURE__ */ jsxDEV(Button2, {
314
- type: "button",
315
- variant: "ghost",
316
- size: "sm",
317
- onClick: () => remove(idx),
318
- children: "Remove"
319
- }, undefined, false, undefined, this) : null
320
- ]
321
- }, row.id ?? idx, true, undefined, this)),
322
- canAdd ? /* @__PURE__ */ jsxDEV(Button2, {
323
- type: "button",
324
- variant: "outline",
325
- size: "sm",
326
- onClick: () => append({}),
327
- children: "Add"
328
- }, undefined, false, undefined, this) : null
329
- ]
330
- }, name, true, undefined, this);
331
- };
332
- const onSubmit = async (data) => {
333
- const actionKey = spec.actions?.[0]?.key ?? "submit";
334
- if (merged.onSubmitOverride) {
335
- return merged.onSubmitOverride(data, actionKey);
336
- }
337
- };
338
- const Button = driver.Button;
339
- return /* @__PURE__ */ jsxDEV("form", {
340
- onSubmit: form.handleSubmit(onSubmit),
341
- children: [
342
- (spec.fields || []).map((f, i) => /* @__PURE__ */ jsxDEV(React.Fragment, {
343
- children: renderOne(f)
344
- }, i, false, undefined, this)),
345
- spec.actions && spec.actions.length ? /* @__PURE__ */ jsxDEV("div", {
346
- children: spec.actions.map((a) => /* @__PURE__ */ jsxDEV(Button, {
347
- type: "submit",
348
- children: a.labelI18n
349
- }, a.key, false, undefined, this))
350
- }, undefined, false, undefined, this) : null
351
- ]
352
- }, undefined, true, undefined, this);
353
- }
354
- return {
355
- render: (spec, options) => /* @__PURE__ */ jsxDEV(InternalForm, {
356
- spec,
357
- options,
358
- merged: {
359
- ...conf,
360
- ...options?.overrides ?? {}
361
- }
362
- }, undefined, false, undefined, this)
363
- };
364
- }
365
- export {
366
- createFormRenderer
367
- };
1
+ var Qq=((U)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(U,{get:(H,J)=>(typeof require<"u"?require:H)[J]}):U)(function(U){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+U+'" is not supported')});import{buildZodWithRelations as o,evalPredicate as u}from"@contractspec/lib.contracts-spec/forms";import{zodResolver as i}from"@hookform/resolvers/zod";import x,{useEffect as a,useMemo as n,useState as d}from"react";import{Controller as s,useFieldArray as r,useForm as e}from"react-hook-form";import{jsx as Q,jsxs as M,Fragment as Jq}from"react/jsx-runtime";function v(U){if(!U)return;if(Array.isArray(U))return{kind:"static",options:U};return U}function qq(U,H){if(!H)return;let J=H.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean),T=U;for(let L of J){if(T==null)return;T=T[L]}return T}function Hq(U,H){if(!H||H.length===0)return"[]";try{return JSON.stringify(H.map((J)=>qq(U,J)))}catch{return"[]"}}function p(U,H,J){let[T,L]=d([]),X=n(()=>{if(!H)return"nil";if(H.kind==="static")return JSON.stringify(H.options??[]);return Hq(U,H.deps)},[H,U]);return a(()=>{let N=!0;return(async()=>{if(!H)return L([]);if(H.kind==="static")return L([...H.options??[]]);let h=J?.[H.resolverKey];if(!h)return L([]);let k=await h(U,H.args);if(N)L([...k??[]])})(),()=>{N=!1}},[X,H&&H.kind==="resolver"?H.resolverKey:void 0]),T}function c(U,H,J){if(!H)return U??"";let T=typeof J==="number"?`${H.replace(/^\$index$/,String(J))}`:H;return U?`${U}${typeof J==="number"?`.${J}`:""}.${T}`.replace(/\.+/g,"."):T}function $q(U){let H=U,{driver:J}=H;function T(L){let{spec:X,options:N,merged:R}=L,h=n(()=>o(X),[X]),k=e({...R.formOptions,resolver:i(h),defaultValues:N?.defaultValues}),D=k.watch(),I=(q,w,W)=>{let{Field:Y,FieldLabel:y,FieldDescription:F,FieldError:B}=J,_=c(w,q.name,W),O=u(D,q.visibleWhen),Z=u(D,q.enabledWhen),P=Boolean(k.getFieldState(_)?.invalid);if(!O)return null;let $=_?.replace(/\./g,"-"),A={"data-invalid":P,hidden:!O,disabled:!Z},E=q.labelI18n?Q(y,{htmlFor:$,children:q.labelI18n}):null,g=q.descriptionI18n?Q(F,{children:q.descriptionI18n}):null;if(q.kind==="group"){let G=q.fields.map((z,K)=>Q(x.Fragment,{children:I(z,_,W)},`${_}-${K}`));return M(Y,{...A,children:[E,G,g]})}if(q.kind==="array")return l(q,w);return Q(s,{name:_,control:k.control,render:({field:G,fieldState:z})=>{let K=z.error?[z.error]:[],S=z.invalid||void 0;if(q.kind==="text"){let V=q,C=J.Input;return M(Y,{...A,children:[E,Q(C,{id:$,"aria-invalid":S,placeholder:q.placeholderI18n,autoComplete:V.autoComplete,inputMode:V.inputMode,maxLength:V.maxLength,minLength:V.minLength,disabled:!Z,...G,...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}if(q.kind==="textarea"){let V=q,C=J.Textarea;return M(Y,{...A,children:[E,Q(C,{id:$,"aria-invalid":S,placeholder:q.placeholderI18n,rows:V.rows,maxLength:V.maxLength,disabled:!Z,...G,...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}if(q.kind==="select"){let V=q,C=J.Select,b=v(V.options),j=p(D,b,R.resolvers);return M(Y,{...A,children:[E,Q(C,{id:$,name:_,"aria-invalid":S,disabled:!Z,value:G.value,onChange:(m)=>G.onChange(m),options:j,...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}if(q.kind==="checkbox"){let V=J.Checkbox;return M(Y,{...A,children:[E,Q(V,{id:$,name:_,disabled:!Z,checked:!!G.value,onCheckedChange:(C)=>G.onChange(C),...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}if(q.kind==="radio"){let V=q,C=J.RadioGroup,b=v(V.options),j=p(D,b,R.resolvers);return M(Y,{...A,children:[E,Q(C,{id:$,name:_,disabled:!Z,value:G.value,onValueChange:(m)=>G.onChange(m),options:j,...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}if(q.kind==="switch"){let V=J.Switch;return M(Y,{...A,children:[E,Q(V,{id:$,name:_,disabled:!Z,checked:!!G.value,onCheckedChange:(C)=>G.onChange(C),...q.uiProps}),g,z.invalid?Q(B,{errors:K}):null]})}return Q(Jq,{})}},_)},l=(q,w)=>{let W=c(w,q.name),{fields:Y,append:y,remove:F}=r({control:k.control,name:W}),B=q.max==null||Y.length<q.max,_=(P)=>(q.min==null?Y.length>0:Y.length>q.min)&&P>=0,O=J.Button,Z=J.FieldLabel;return M("div",{children:[q.labelI18n?Q(Z,{children:q.labelI18n}):null,Y.map((P,$)=>M("div",{children:[I(q.of,W,$),_($)?Q(O,{type:"button",variant:"ghost",size:"sm",onClick:()=>F($),children:"Remove"}):null]},P.id??$)),B?Q(O,{type:"button",variant:"outline",size:"sm",onClick:()=>y({}),children:"Add"}):null]},W)},t=async(q)=>{let w=X.actions?.[0]?.key??"submit";if(R.onSubmitOverride)return R.onSubmitOverride(q,w)},f=J.Button;return M("form",{onSubmit:k.handleSubmit(t),children:[(X.fields||[]).map((q,w)=>Q(x.Fragment,{children:I(q)},w)),X.actions&&X.actions.length?Q("div",{children:X.actions.map((q)=>Q(f,{type:"submit",children:q.labelI18n},q.key))}):null]})}return{render:(L,X)=>Q(T,{spec:L,options:X,merged:{...H,...X?.overrides??{}}})}}export{$q as createFormRenderer};