@xraph/smartform-react
Version:
React library for rendering and validating SmartForms with shadcn components
2 lines (1 loc) • 42.5 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=(r=>(r.Regular="regular",r.Auth="auth",r))(v||{}),S=(r=>(r.Text="text",r.Textarea="textarea",r.Number="number",r.Select="select",r.MultiSelect="multiselect",r.Checkbox="checkbox",r.Radio="radio",r.Date="date",r.Time="time",r.DateTime="datetime",r.Email="email",r.Password="password",r.File="file",r.Image="image",r.Group="group",r.Array="array",r.OneOf="oneOf",r.AnyOf="anyOf",r.Switch="switch",r.Slider="slider",r.Rating="rating",r.Object="object",r.RichText="richtext",r.Color="color",r.Hidden="hidden",r.Section="section",r.Custom="custom",r.API="api",r.Auth="auth",r.Branch="branch",r))(S||{}),o=(r=>(r.Simple="simple",r.And="and",r.Or="or",r.Not="not",r.Exists="exists",r.Expression="expression",r))(o||{}),c=(r=>(r.Required="required",r.RequiredIf="requiredIf",r.MinLength="minLength",r.MaxLength="maxLength",r.Pattern="pattern",r.Min="min",r.Max="max",r.Email="email",r.URL="url",r.Custom="custom",r.Unique="unique",r.FileType="fileType",r.FileSize="fileSize",r.ImageDimensions="imageDimensions",r.Dependency="dependency",r))(c||{}),l=(r=>(r.Static="static",r.Dynamic="dynamic",r.Dependent="dependent",r))(l||{}),F=(r=>(r.OAuth2="oauth2",r.Basic="basic",r.APIKey="apikey",r.JWT="jwt",r.SAML="saml",r.Custom="custom",r))(F||{});class T{constructor(){this.config={type:l.Static}}static(){return this.config.type=l.Static,this.config.static=[],new D(this)}dynamic(){return this.config.type=l.Dynamic,this.config.dynamicSource={},new R(this)}dependent(e){return this.config.type=l.Dependent,this.config.dependency={field:e,valueMap:{}},new N(this)}getDynamicSource(){if(this.config.type===l.Dynamic)return this.config.dynamicSource}build(){return this.config}}class D{constructor(e){this.optionsBuilder=e}addOption(e,t){const i={value:e,label:t};return this.optionsBuilder.config.static||(this.optionsBuilder.config.static=[]),this.optionsBuilder.config.static.push(i),this}addOptionWithIcon(e,t,i){const s={value:e,label:t,icon:i};return this.optionsBuilder.config.static||(this.optionsBuilder.config.static=[]),this.optionsBuilder.config.static.push(s),this}addOptions(...e){return this.optionsBuilder.config.static||(this.optionsBuilder.config.static=[]),this.optionsBuilder.config.static.push(...e),this}build(){return this.optionsBuilder.build()}}class R{constructor(e){this.optionsBuilder=e}fromAPI(e,t){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.type="api",this.optionsBuilder.config.dynamicSource.endpoint=e,this.optionsBuilder.config.dynamicSource.method=t),this}fromAPIWithPath(e,t,i,s){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.type="api",this.optionsBuilder.config.dynamicSource.endpoint=e,this.optionsBuilder.config.dynamicSource.method=t,this.optionsBuilder.config.dynamicSource.valuePath=i,this.optionsBuilder.config.dynamicSource.labelPath=s),this}withHeader(e,t){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.headers||(this.optionsBuilder.config.dynamicSource.headers={}),this.optionsBuilder.config.dynamicSource.headers[e]=t),this}withParameter(e,t){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.parameters||(this.optionsBuilder.config.dynamicSource.parameters={}),this.optionsBuilder.config.dynamicSource.parameters[e]=t),this}withValuePath(e){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.valuePath=e),this}withLabelPath(e){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.labelPath=e),this}refreshOn(...e){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.refreshOn=e),this}fromFunction(e){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource.type="function",this.optionsBuilder.config.dynamicSource.functionName=e),this}withFunctionOptions(e){if(this.optionsBuilder.config.dynamicSource){if(this.optionsBuilder.config.dynamicSource.type="function",typeof e=="string")this.optionsBuilder.config.dynamicSource.functionName=e;else{const t=`direct_func_${Date.now()}`;this.optionsBuilder.config.dynamicSource.functionName=t,this.optionsBuilder.config.dynamicSource.directFunction=e}this.optionsBuilder.config.dynamicSource.parameters||(this.optionsBuilder.config.dynamicSource.parameters={})}return new V(this.optionsBuilder)}withSource(e){return this.optionsBuilder.config.dynamicSource&&(this.optionsBuilder.config.dynamicSource=e),this}build(){return this.optionsBuilder.build()}}class N{constructor(e){this.optionsBuilder=e}whenEquals(e){return new C(this,e)}withExpression(e){return this.optionsBuilder.config.dependency&&(this.optionsBuilder.config.dependency.expression=e),this}build(){return this.optionsBuilder.build()}}class C{constructor(e,t){this.dependentOptionsBuilder=e,this.value=t}addOption(e,t){var n;const i={value:e,label:t},s=this.dependentOptionsBuilder.optionsBuilder.config;return(n=s.dependency)!=null&&n.valueMap&&(s.dependency.valueMap[this.value]||(s.dependency.valueMap[this.value]=[]),s.dependency.valueMap[this.value].push(i)),this}addOptionWithIcon(e,t,i){var a;const s={value:e,label:t,icon:i},n=this.dependentOptionsBuilder.optionsBuilder.config;return(a=n.dependency)!=null&&a.valueMap&&(n.dependency.valueMap[this.value]||(n.dependency.valueMap[this.value]=[]),n.dependency.valueMap[this.value].push(s)),this}addOptions(...e){var i;const t=this.dependentOptionsBuilder.optionsBuilder.config;return(i=t.dependency)!=null&&i.valueMap&&(t.dependency.valueMap[this.value]||(t.dependency.valueMap[this.value]=[]),t.dependency.valueMap[this.value].push(...e)),this}end(){return this.dependentOptionsBuilder}}function G(r,e){return{value:r,label:e}}function Q(r,e,t){return{value:r,label:e,icon:t}}let V=class{constructor(e){this.optionsBuilder=e}withArgument(e,t){var i;return(i=this.optionsBuilder.config.dynamicSource)!=null&&i.parameters&&(this.optionsBuilder.config.dynamicSource.parameters[e]=t),this}withArguments(e){var t;if((t=this.optionsBuilder.config.dynamicSource)!=null&&t.parameters)for(const[i,s]of Object.entries(e))this.optionsBuilder.config.dynamicSource.parameters[i]=s;return this}withFieldReference(e,t){var i;return(i=this.optionsBuilder.config.dynamicSource)!=null&&i.parameters&&(this.optionsBuilder.config.dynamicSource.parameters[e]=`\${${t}}`),this}build(){return this.optionsBuilder.build()}};class d{constructor(e,t,i){this.field={id:e,type:t,label:i,required:!1,properties:{},order:0}}required(e=!0){return this.field.required=e,this}placeholder(e){return this.field.placeholder=e,this}helpText(e){return this.field.helpText=e,this}defaultValue(e){return this.field.defaultValue=e,this}order(e){return this.field.order=e,this}property(e,t){return this.field.properties[e]=t,this}requiredIf(e){return this.field.requiredIf=e,this}requiredWhenEquals(e,t){return this.field.requiredIf={type:o.Simple,field:e,operator:"eq",value:t},this}requiredWhenNotEquals(e,t){return this.field.requiredIf={type:o.Simple,field:e,operator:"neq",value:t},this}requiredWhenGreaterThan(e,t){return this.field.requiredIf={type:o.Simple,field:e,operator:"gt",value:t},this}requiredWhenLessThan(e,t){return this.field.requiredIf={type:o.Simple,field:e,operator:"lt",value:t},this}requiredWhenExists(e){return this.field.requiredIf={type:o.Exists,field:e},this}requiredWhenAllMatch(...e){return this.field.requiredIf={type:o.And,conditions:e},this}requiredWhenAnyMatch(...e){return this.field.requiredIf={type:o.Or,conditions:e},this}requiredWithExpression(e){return this.field.requiredIf={type:o.Expression,expression:e},this}visibleWhen(e){return this.field.visible=e,this}visibleWhenEquals(e,t){return this.field.visible={type:o.Simple,field:e,operator:"eq",value:t},this}visibleWhenNotEquals(e,t){return this.field.visible={type:o.Simple,field:e,operator:"neq",value:t},this}visibleWhenGreaterThan(e,t){return this.field.visible={type:o.Simple,field:e,operator:"gt",value:t},this}visibleWhenLessThan(e,t){return this.field.visible={type:o.Simple,field:e,operator:"lt",value:t},this}visibleWhenExists(e){return this.field.visible={type:o.Exists,field:e},this}visibleWhenAllMatch(...e){return this.field.visible={type:o.And,conditions:e},this}visibleWhenAnyMatch(...e){return this.field.visible={type:o.Or,conditions:e},this}visibleWithExpression(e){return this.field.visible={type:o.Expression,expression:e},this}enabledWhen(e){return this.field.enabled=e,this}enabledWhenEquals(e,t){return this.field.enabled={type:o.Simple,field:e,operator:"eq",value:t},this}enabledWhenNotEquals(e,t){return this.field.enabled={type:o.Simple,field:e,operator:"neq",value:t},this}enabledWhenExists(e){return this.field.enabled={type:o.Exists,field:e},this}addValidation(e){return this.field.validationRules||(this.field.validationRules=[]),this.field.validationRules.push(e),this}validateRequired(e){return this.addValidation({type:c.Required,message:e})}validateMinLength(e,t){return this.addValidation({type:c.MinLength,message:t,parameters:e})}validateMaxLength(e,t){return this.addValidation({type:c.MaxLength,message:t,parameters:e})}validatePattern(e,t){return this.addValidation({type:c.Pattern,message:t,parameters:e})}validateMin(e,t){return this.addValidation({type:c.Min,message:t,parameters:e})}validateMax(e,t){return this.addValidation({type:c.Max,message:t,parameters:e})}validateEmail(e){return this.addValidation({type:c.Email,message:e})}validateURL(e){return this.addValidation({type:c.URL,message:e})}validateFileType(e,t){return this.addValidation({type:c.FileType,message:t,parameters:e})}validateFileSize(e,t){return this.addValidation({type:c.FileType,message:t,parameters:e})}validateImageDimensions(e,t){return this.addValidation({type:c.ImageDimensions,message:t,parameters:e})}validateDependency(e,t){return this.addValidation({type:c.Dependency,message:t,parameters:e})}validateUnique(e){return this.addValidation({type:c.Unique,message:e})}validateCustom(e,t){return this.addValidation({type:c.Custom,message:t,parameters:e})}withStaticOptions(e){return this.field.options={type:l.Static,static:e},this}withDynamicFunctionOptions(e){const t={type:"function",parameters:{}};if(typeof e=="string")t.functionName=e;else{const n=`direct_func_${Date.now()}`;t.functionName=n,t.directFunction=e}const i=new T().dynamic();i.withSource(t),this.field.options=i.build();const s={functionName:t.functionName,arguments:{}};return new j(i,s)}withDynamicOptions(e){return this.field.options={type:l.Dynamic,dynamicSource:e},this}withDynamicFunction(e){const t={functionName:e,arguments:{}};return this.field.properties.dynamicFunction=t,new y(this,t)}hasDynamicFunction(){return this.field.properties.dynamicFunction!==void 0}getDynamicFunctionConfig(){return this.field.properties.dynamicFunction}withDependentOptions(e,t){return this.field.options={type:l.Dependent,dependency:{field:e,valueMap:t}},this}addOption(e,t){const i={value:e,label:t};return this.field.options?this.field.options.type===l.Static?(this.field.options.static||(this.field.options.static=[]),this.field.options.static.push(i)):this.field.options={type:l.Static,static:[i]}:this.field.options={type:l.Static,static:[i]},this}addOptions(...e){return this.field.options?this.field.options.type===l.Static?(this.field.options.static||(this.field.options.static=[]),this.field.options.static.push(...e)):this.field.options={type:l.Static,static:e}:this.field.options={type:l.Static,static:e},this}withOptionsFromAPI(e,t,i,s){const n={type:"api",endpoint:e,method:t,valuePath:i,labelPath:s};return this.withDynamicOptions(n)}withOptionsRefreshingOn(...e){var t;return(t=this.field.options)!=null&&t.dynamicSource&&(this.field.options.dynamicSource.refreshOn=e),this}withDynamicOptionsConfig(e){return e.type===l.Dynamic&&e.dynamicSource?this.field.options={type:l.Dynamic,dynamicSource:e.dynamicSource}:this.field.options=e,this}dynamicValue(e){return this.field.properties.dynamicValue=!0,this.withDynamicFunction(e)}dynamicValidation(e,t){const i={functionName:e,arguments:{}};return this.addValidation({type:c.Custom,message:t,parameters:{dynamicFunction:i}}),new y(this,i)}autocompleteField(e){if(this.field.type!==S.Text&&this.field.type!==S.Email&&this.field.type!==S.Password)return null;this.field.properties.autocomplete=!0;const t={functionName:e,arguments:{}};return this.field.properties.autocompleteFunction=t,new y(this,t)}liveSearch(e){this.field.properties.liveSearch=!0;const t={functionName:e,arguments:{}};return this.field.properties.searchFunction=t,new y(this,t)}dataSource(e){this.field.properties.dataSource=!0;const t={functionName:e,arguments:{}};return this.field.properties.dataSourceFunction=t,new y(this,t)}formatter(e){this.field.properties.formatter=!0;const t={functionName:e,arguments:{}};return this.field.properties.formatterFunction=t,new y(this,t)}parser(e){this.field.properties.parser=!0;const t={functionName:e,arguments:{}};return this.field.properties.parserFunction=t,new y(this,t)}defaultWhen(e,t){return this.field.defaultWhen||(this.field.defaultWhen=[]),this.field.defaultWhen.push({condition:e,value:t}),this}defaultWhenEquals(e,t,i){const s={type:o.Simple,field:e,operator:"eq",value:t};return this.defaultWhen(s,i)}defaultWhenNotEquals(e,t,i){const s={type:o.Simple,field:e,operator:"neq",value:t};return this.defaultWhen(s,i)}defaultWhenGreaterThan(e,t,i){const s={type:o.Simple,field:e,operator:"gt",value:t};return this.defaultWhen(s,i)}defaultWhenLessThan(e,t,i){const s={type:o.Simple,field:e,operator:"lt",value:t};return this.defaultWhen(s,i)}defaultWhenExists(e,t){const i={type:o.Exists,field:e};return this.defaultWhen(i,t)}defaultWhenExpression(e,t){const i={type:o.Expression,expression:e};return this.defaultWhen(i,t)}build(){return this.field}}class y{constructor(e,t){this.fieldBuilder=e,this.config=t}withArgument(e,t){return this.config.arguments[e]=t,this}withArguments(e){for(const[t,i]of Object.entries(e))this.config.arguments[t]=i;return this}withFieldReference(e,t){return this.config.arguments[e]=`\${${t}}`,this}withTransformer(e){return this.config.transformerName=e,this.config.transformerParams={},this}withTransformerParam(e,t){return this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams[e]=t,this}end(){return this.fieldBuilder}}class j{constructor(e,t){this.dynamicOptionsBuilder=e,this.config=t}withArgument(e,t){var i;return this.config.arguments[e]=t,(i=this.dynamicOptionsBuilder.config.dynamicSource)!=null&&i.parameters&&(this.dynamicOptionsBuilder.config.dynamicSource.parameters[e]=t),this}withArguments(e){for(const[t,i]of Object.entries(e))this.withArgument(t,i);return this}withFieldReference(e,t){const i=`\${${t}}`;return this.withArgument(e,i)}withTransformer(e){var t;return this.config.transformerName=e,this.config.transformerParams={},(t=this.dynamicOptionsBuilder.config.dynamicSource)!=null&&t.parameters&&(this.dynamicOptionsBuilder.config.dynamicSource.parameters.transformer=e,this.dynamicOptionsBuilder.config.dynamicSource.parameters.transformerParams={}),this}withTransformerParam(e,t){var i;if(this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams[e]=t,(i=this.dynamicOptionsBuilder.config.dynamicSource)!=null&&i.parameters){const s=this.dynamicOptionsBuilder.config.dynamicSource.parameters.transformerParams||{};s[e]=t,this.dynamicOptionsBuilder.config.dynamicSource.parameters.transformerParams=s}return this}withSearchSupport(){return this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams.enableSearch=!0,this}withFilterableFields(...e){return this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams.filterableFields=e,this}withSortableFields(...e){return this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams.sortableFields=e,this}withPagination(e){return this.config.transformerParams||(this.config.transformerParams={}),this.config.transformerParams.enablePagination=!0,this.config.transformerParams.defaultLimit=e,this}end(){return this.dynamicOptionsBuilder}}class g extends d{constructor(e,t){super(e,"group",t),this.field.nested=[]}addField(e){return this.field.nested||(this.field.nested=[]),this.field.nested.push(e),this}textField(e,t){const i=new d(e,"text",t);return this.addField(i.build()),i}textareaField(e,t){const i=new d(e,"textarea",t);return this.addField(i.build()),i}numberField(e,t){const i=new d(e,"number",t);return this.addField(i.build()),i}emailField(e,t){const i=new d(e,"email",t);return this.addField(i.build()),i}selectField(e,t){const i=new d(e,"select",t);return this.addField(i.build()),i}checkboxField(e,t){const i=new d(e,"checkbox",t);return this.addField(i.build()),i}radioField(e,t){const i=new d(e,"radio",t);return this.addField(i.build()),i}multiSelectField(e,t){const i=new d(e,"multiselect",t);return this.addField(i.build()),i}passwordField(e,t){const i=new d(e,"password",t);return this.addField(i.build()),i}fileField(e,t){const i=new d(e,"file",t);return this.addField(i.build()),i}objectField(e,t){const i=new g(e,t);return this.addField(i.build()),i}objectTemplate(e,t){const i=new g(e,t);return this.addField(i.build()),i}arrayField(e,t){const i=new A(e,t);return this.addField(i.build()),i}oneOfField(e,t){const i=new O(e,t);return this.addField(i.build()),i}anyOfField(e,t){const i=new x(e,t);return this.addField(i.build()),i}apiField(e,t){const i=new q(e,t);return this.addField(i.build()),i}authField(e,t){const i=new E(e,t);return this.addField(i.build()),i}branchField(e,t){const i=new I(e,t);return this.addField(i.build()),i}customField(e,t){const i=new P(e,t);return this.addField(i.build()),i}hiddenField(e,t){const i=new d(e,"hidden",t);return this.addField(i.build()),i}dateField(e,t){const i=new d(e,"date",t);return this.addField(i.build()),i}}class A extends d{constructor(e,t){super(e,"array",t),this.field.nested=[]}itemTemplate(e){return this.field.nested||(this.field.nested=[]),this.field.nested.push(e),this}textField(e,t){const i=new d(e,"text",t);return this.itemTemplate(i.build()),i}objectTemplate(e,t){const i=new g(e,t);return this.itemTemplate(i.build()),i}objectTemplateWithFields(e,t,i){const s=new g(e,t);for(const n of i)s.addField(n);return this.itemTemplate(s.build()),s}dateField(e,t){const i=new d(e,"date",t);return this.itemTemplate(i.build()),i}numberField(e,t){const i=new d(e,"number",t);return this.itemTemplate(i.build()),i}emailField(e,t){const i=new d(e,"email",t);return this.itemTemplate(i.build()),i}selectField(e,t){const i=new d(e,"select",t);return this.itemTemplate(i.build()),i}checkboxField(e,t){const i=new d(e,"checkbox",t);return this.itemTemplate(i.build()),i}radioField(e,t){const i=new d(e,"radio",t);return this.itemTemplate(i.build()),i}multiSelectField(e,t){const i=new d(e,"multiselect",t);return this.itemTemplate(i.build()),i}passwordField(e,t){const i=new d(e,"password",t);return this.itemTemplate(i.build()),i}fileField(e,t){const i=new d(e,"file",t);return this.itemTemplate(i.build()),i}objectField(e,t){const i=new g(e,t);return this.itemTemplate(i.build()),i}oneOfField(e,t){const i=new O(e,t);return this.itemTemplate(i.build()),i}anyOfField(e,t){const i=new x(e,t);return this.itemTemplate(i.build()),i}apiField(e,t){const i=new q(e,t);return this.itemTemplate(i.build()),i}authField(e,t){const i=new E(e,t);return this.itemTemplate(i.build()),i}branchField(e,t){const i=new I(e,t);return this.itemTemplate(i.build()),i}customField(e,t){const i=new P(e,t);return this.itemTemplate(i.build()),i}hiddenField(e,t){const i=new d(e,"hidden",t);return this.itemTemplate(i.build()),i}minItems(e){return this.property("minItems",e),this}maxItems(e){return this.property("maxItems",e),this}}class O extends d{constructor(e,t){super(e,"oneOf",t),this.field.nested=[]}addOption(e){return this.field.nested||(this.field.nested=[]),this.field.nested.push(e),this}groupOption(e,t){const i=new g(e,t);return this.addOption(i.build()),i}}class x extends d{constructor(e,t){super(e,"anyOf",t),this.field.nested=[]}addOption(e){return this.field.nested||(this.field.nested=[]),this.field.nested.push(e),this}groupOption(e,t){const i=new g(e,t);return this.addOption(i.build()),i}}class q extends d{constructor(e,t){super(e,"api",t)}endpoint(e){return this.property("endpoint",e),this}method(e){return this.property("method",e),this}header(e,t){var s;const i=((s=this.field.properties)==null?void 0:s.headers)||{};return i[e]=t,this.property("headers",i),this}parameter(e,t){var s;const i=((s=this.field.properties)==null?void 0:s.parameters)||{};return i[e]=t,this.property("parameters",i),this}responseMapping(e){return this.property("responseMapping",e),this}withDynamicRequest(e){this.field.properties.dynamicRequest=!0;const t={functionName:e,arguments:{}};return this.field.properties.requestFunction=t,new y(this,t)}withDynamicResponse(e){this.field.properties.dynamicResponse=!0;const t={functionName:e,arguments:{}};return this.field.properties.responseFunction=t,new y(this,t)}}class E extends d{constructor(e,t){super(e,"auth",t)}authType(e){return this.property("authType",e),this}serviceId(e){return this.property("serviceId",e),this}}class I extends d{constructor(e,t){super(e,"branch",t)}condition(e){return this.property("condition",e),this}trueBranch(e){return this.property("trueBranch",e),this}falseBranch(e){return this.property("falseBranch",e),this}}class P extends d{constructor(e,t){super(e,"custom",t)}componentName(e){return this.property("componentName",e),this}componentProps(e){return this.property("componentProps",e),this}}class L{constructor(e,t){this.authField=new d(e,"auth",t),this.authField.property("authType",F.OAuth2)}clientId(e){return this.authField.property("clientId",e),this}clientSecret(e){return this.authField.property("clientSecret",e),this}authorizationUrl(e){return this.authField.property("authorizationUrl",e),this}tokenUrl(e){return this.authField.property("tokenUrl",e),this}scopes(e){return this.authField.property("scopes",e),this}redirectUri(e){return this.authField.property("redirectUri",e),this}responseType(e){return this.authField.property("responseType",e),this}state(e){return this.authField.property("useState",e),this}pkce(e){return this.authField.property("usePKCE",e),this}autoRefresh(e){return this.authField.property("autoRefresh",e),this}required(e=!0){return this.authField.required(e),this}helpText(e){return this.authField.helpText(e),this}serviceId(e){return this.authField.property("serviceId",e),this}build(){return this.authField.build()}}class k{constructor(e,t){this.authField=new d(e,"auth",t),this.authField.property("authType",F.Basic)}usernameField(e,t){return this.authField.property("usernameField",{label:e,placeholder:t}),this}passwordField(e,t){return this.authField.property("passwordField",{label:e,placeholder:t}),this}rememberMe(e,t){return this.authField.property("rememberMe",{label:e,defaultValue:t}),this}required(e=!0){return this.authField.required(e),this}helpText(e){return this.authField.helpText(e),this}serviceId(e){return this.authField.property("serviceId",e),this}build(){return this.authField.build()}}class J{constructor(e,t){this.authField=new d(e,"auth",t),this.authField.property("authType",F.APIKey)}keyName(e){return this.authField.property("keyName",e),this}keyLocation(e){return this.authField.property("keyLocation",e),this}placeholder(e){return this.authField.property("placeholder",e),this}required(e=!0){return this.authField.required(e),this}helpText(e){return this.authField.helpText(e),this}serviceId(e){return this.authField.property("serviceId",e),this}build(){return this.authField.build()}}class ${constructor(e,t){this.authField=new d(e,"auth",t),this.authField.property("authType",F.JWT)}secretKey(e){return this.authField.property("secretKey",e),this}algorithm(e){return this.authField.property("algorithm",e),this}issuer(e){return this.authField.property("issuer",e),this}audience(e){return this.authField.property("audience",e),this}tokenExpiry(e){return this.authField.property("expirySeconds",e),this}required(e=!0){return this.authField.required(e),this}helpText(e){return this.authField.helpText(e),this}serviceId(e){return this.authField.property("serviceId",e),this}build(){return this.authField.build()}}class U{constructor(e,t){this.authField=new d(e,"auth",t),this.authField.property("authType",F.SAML)}idPMetadataURL(e){return this.authField.property("idpMetadataUrl",e),this}idPMetadata(e){return this.authField.property("idpMetadata",e),this}assertionConsumerServiceURL(e){return this.authField.property("assertionConsumerServiceUrl",e),this}spEntityId(e){return this.authField.property("spEntityId",e),this}attributeMapping(e){return this.authField.property("attributeMapping",e),this}signRequests(e){return this.authField.property("signRequests",e),this}required(e=!0){return this.authField.required(e),this}helpText(e){return this.authField.helpText(e),this}serviceId(e){return this.authField.property("serviceId",e),this}build(){return this.authField.build()}}class b{constructor(e){this.condition=e}static when(e){return new b({type:o.Simple,field:e})}equals(e){return this.condition.operator="eq",this.condition.value=e,this}notEquals(e){return this.condition.operator="neq",this.condition.value=e,this}greaterThan(e){return this.condition.operator="gt",this.condition.value=e,this}greaterThanOrEquals(e){return this.condition.operator="gte",this.condition.value=e,this}lessThan(e){return this.condition.operator="lt",this.condition.value=e,this}lessThanOrEquals(e){return this.condition.operator="lte",this.condition.value=e,this}contains(e){return this.condition.operator="contains",this.condition.value=e,this}startsWith(e){return this.condition.operator="startsWith",this.condition.value=e,this}endsWith(e){return this.condition.operator="endsWith",this.condition.value=e,this}static exists(e){return new b({type:o.Exists,field:e})}static and(...e){return new b({type:o.And,conditions:e})}static or(...e){return new b({type:o.Or,conditions:e})}static not(e){return new b({type:o.Not,conditions:[e]})}static withExpression(e){return new b({type:o.Expression,expression:e})}addCondition(e){return(this.condition.type===o.And||this.condition.type===o.Or)&&(this.condition.conditions||(this.condition.conditions=[]),this.condition.conditions.push(e)),this}build(){return this.condition}}class W{constructor(e){this.schema=e}validateForm(e){var i;const t={valid:!0,errors:[]};for(const s of this.schema.fields)this.validateField(s,e,"",t);return t.valid=((i=t.errors)==null?void 0:i.length)===0,t}validateField(e,t,i,s){var u,h,B;const n=i?`${i}.${e.id}`:e.id;if(e.visible&&!this.evaluateCondition(e.visible,t))return;const a=this.getValueByPath(t,n);if(e.required&&this.isEmpty(a)&&((u=s.errors)==null||u.push({fieldId:n,message:`${e.label} is required`,ruleType:"required"})),e.requiredIf&&this.evaluateCondition(e.requiredIf,t)&&this.isEmpty(a)&&((h=s.errors)==null||h.push({fieldId:n,message:`${e.label} is required based on other field values`,ruleType:"requiredIf"})),!this.isEmpty(a)){if(e.validationRules)for(const f of e.validationRules){const[p,m]=this.applyValidationRule(f,a,e,t);p||(B=s.errors)==null||B.push({fieldId:n,message:m,ruleType:f.type})}if((e.type==="group"||e.type==="object")&&e.nested&&e.nested.length>0){const f=a||{};for(const p of e.nested)this.validateField(p,f,n,s)}if(e.type==="array"&&Array.isArray(a)){for(let f=0;f<a.length;f++)if(e.nested&&e.nested.length>0){const p=a[f];if(typeof p=="object")for(const m of e.nested)this.validateField(m,p,`${n}[${f}]`,s)}}e.type==="oneOf"&&e.nested&&e.nested.length>0,e.type==="anyOf"&&e.nested&&e.nested.length>0}}applyValidationRule(e,t,i,s){switch(e.type){case"required":return[!this.isEmpty(t),e.message];case"requiredIf":{if(e.parameters&&typeof e.parameters=="object"&&"type"in e.parameters){const n=e.parameters;if(this.evaluateCondition(n,s))return[!this.isEmpty(t),e.message]}return[!0,""]}case"minLength":{if(typeof t=="string"){const n=e.parameters;return[t.length>=n,e.message]}return[!1,e.message]}case"maxLength":{if(typeof t=="string"){const n=e.parameters;return[t.length<=n,e.message]}return[!1,e.message]}case"pattern":{if(typeof t=="string"){const n=e.parameters;try{return[new RegExp(n).test(t),e.message]}catch{return[!1,"Invalid pattern"]}}return[!1,e.message]}case"min":{if(typeof t=="number"){const n=e.parameters;return[t>=n,e.message]}return[!1,e.message]}case"max":{if(typeof t=="number"){const n=e.parameters;return[t<=n,e.message]}return[!1,e.message]}case"email":return typeof t=="string"?[/^[^@]+@[^@]+\.[^@]+$/.test(t),e.message]:[!1,e.message];case"url":return typeof t=="string"?[/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(t),e.message]:[!1,e.message];case"fileType":return[!0,e.message];case"fileSize":return[!0,e.message];case"imageDimensions":return[!0,e.message];case"dependency":return[this.validateDependency(e,i,s),e.message];case"unique":return[!0,e.message];case"custom":return[!0,e.message];default:return[!0,""]}}validateDependency(e,t,i){if(e.parameters&&typeof e.parameters=="object"){const s=e.parameters,n=s.field,a=s.operator,u=s.value,h=this.getValueByPath(i,n);switch(a){case"eq":return this.deepEqual(h,u);case"neq":return!this.deepEqual(h,u);case"gt":return typeof h=="number"&&typeof u=="number"&&h>u;case"lt":return typeof h=="number"&&typeof u=="number"&&h<u;default:return!1}}return!1}evaluateCondition(e,t){switch(e.type){case o.Simple:{if(e.field){const i=this.getValueByPath(t,e.field);switch(e.operator){case"eq":return this.deepEqual(i,e.value);case"neq":return!this.deepEqual(i,e.value);case"contains":return typeof i=="string"&&typeof e.value=="string"?i.includes(e.value):!1;case"startsWith":return typeof i=="string"&&typeof e.value=="string"?i.startsWith(e.value):!1;case"endsWith":return typeof i=="string"&&typeof e.value=="string"?i.endsWith(e.value):!1;case"gt":return typeof i=="number"&&typeof e.value=="number"?i>e.value:!1;case"gte":return typeof i=="number"&&typeof e.value=="number"?i>=e.value:!1;case"lt":return typeof i=="number"&&typeof e.value=="number"?i<e.value:!1;case"lte":return typeof i=="number"&&typeof e.value=="number"?i<=e.value:!1;default:return!1}}return!1}case o.And:{if(e.conditions){for(const i of e.conditions)if(!this.evaluateCondition(i,t))return!1;return!0}return!1}case o.Or:{if(e.conditions){for(const i of e.conditions)if(this.evaluateCondition(i,t))return!0;return!1}return!1}case o.Not:return e.conditions&&e.conditions.length>0?!this.evaluateCondition(e.conditions[0],t):!1;case o.Exists:{if(e.field){const i=this.getValueByPath(t,e.field);return!this.isEmpty(i)}return!1}case o.Expression:return e.expression?this.evaluateExpression(e.expression,t):!1;default:return!1}}evaluateExpression(e,t){return!0}isEmpty(e){if(e==null)return!0;switch(typeof e){case"string":return e.trim()==="";case"object":return Array.isArray(e)?e.length===0:Object.keys(e).length===0;case"boolean":return!e;case"number":return e===0;default:return!1}}deepEqual(e,t){if(e===t)return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(const n of i)if(!s.includes(n)||!this.deepEqual(e[n],t[n]))return!1;return!0}getValueByPath(e,t){const i=t.split("."),s=/(.*)\[(\d+)\]$/;let n=e;for(let a=0;a<i.length;a++){const u=i[a],h=u.match(s);if(h){const B=h[1],f=h[2],p=n[B];if(!p||!Array.isArray(p))return;const m=Number.parseInt(f,10);if(m<0||m>=p.length)return;if(a===i.length-1)return p[m];if(typeof p[m]=="object"&&p[m]!==null)n=p[m];else return}else{if(a===i.length-1)return n[u];if(n[u]&&typeof n[u]=="object")n=n[u];else return}}}}class w{constructor(e,t){this.fields=[],this.properties={},this.functions=new Map,this.id=e,this.title=t,this.type=v.Regular,this.validator=new W(this)}static createAuthForm(e,t,i){const s=new w(e,t);return s.type=v.Auth,s.authType=i,s}addField(e){return this.fields.push(e),this}addFields(...e){return this.fields.push(...e),this}findFieldById(e){for(const t of this.fields){if(t.id===e)return t;if(t.nested){const i=this.findNestedFieldById(t.nested,e);if(i)return i}}}findNestedFieldById(e,t){for(const i of e){if(i.id===t)return i;if(i.nested){const s=this.findNestedFieldById(i.nested,t);if(s)return s}}}validate(e){return this.validator.validateForm(e)}sortFields(){this.ensureFieldsHaveOrder(),this.fields.sort((e,t)=>e.order-t.order);for(const e of this.fields)e.nested&&e.nested.length>0&&this.sortNestedFields(e.nested)}ensureFieldsHaveOrder(){let e=0;for(const s of this.fields)s.order>0&&e++;if(e===0){this.fields.forEach((s,n)=>{s.order=n+1});return}let t=0;for(const s of this.fields)s.order>t&&(t=s.order);let i=t+1;for(const s of this.fields)s.order===0&&(s.order=i,i++);for(const s of this.fields)s.nested&&s.nested.length>0&&this.ensureNestedFieldsHaveOrder(s.nested)}ensureNestedFieldsHaveOrder(e){let t=0;for(const i of e)i.order>0&&t++;if(t===0)e.forEach((i,s)=>{i.order=s+1});else{let i=0;for(const n of e)n.order>i&&(i=n.order);let s=i+1;for(const n of e)n.order===0&&(n.order=s,s++)}for(const i of e)i.nested&&i.nested.length>0&&this.ensureNestedFieldsHaveOrder(i.nested)}sortNestedFields(e){e.sort((t,i)=>t.order-i.order);for(const t of e)t.nested&&t.nested.length>0&&this.sortNestedFields(t.nested)}registerFunction(e,t){this.functions.set(e,t)}async executeDynamicFunction(e,t,i){const s=this.functions.get(e);if(s)return await s(t,i);throw new Error(`Function ${e} not registered with schema`)}toJSON(){return JSON.stringify(this)}static fromJSON(e){const t=JSON.parse(e),i=new w(t.id,t.title);return t.description&&(i.description=t.description),t.type&&(i.type=t.type),t.authType&&(i.authType=t.authType),t.fields&&(i.fields=t.fields),t.properties&&(i.properties=t.properties),i}}class M{constructor(e,t){this.schema=new w(e,t)}static createAuthForm(e,t,i){const s=new M(e,t);return s.schema.type=v.Auth,s.schema.authType=i,s}description(e){return this.schema.description=e,this}formType(e){return this.schema.type=e,this}authType(e){return this.schema.type===v.Auth&&(this.schema.authType=e),this}property(e,t){return this.schema.properties[e]=t,this}addField(e){return this.schema.addField(e),this}addFields(...e){return this.schema.addFields(...e),this}textField(e,t){const i=new d(e,"text",t);return this.addField(i.build()),i}textareaField(e,t){const i=new d(e,"textarea",t);return this.addField(i.build()),i}numberField(e,t){const i=new d(e,"number",t);return this.addField(i.build()),i}emailField(e,t){const i=new d(e,"email",t);return this.addField(i.build()),i}passwordField(e,t){const i=new d(e,"password",t);return this.addField(i.build()),i}selectField(e,t){const i=new d(e,"select",t);return this.addField(i.build()),i}multiSelectField(e,t){const i=new d(e,"multiselect",t);return this.addField(i.build()),i}checkboxField(e,t){const i=new d(e,"checkbox",t);return this.addField(i.build()),i}radioField(e,t){const i=new d(e,"radio",t);return this.addField(i.build()),i}dateField(e,t){const i=new d(e,"date",t);return this.addField(i.build()),i}timeField(e,t){const i=new d(e,"time",t);return this.addField(i.build()),i}dateTimeField(e,t){const i=new d(e,"datetime",t);return this.addField(i.build()),i}fileField(e,t){const i=new d(e,"file",t);return this.addField(i.build()),i}imageField(e,t){const i=new d(e,"image",t);return this.addField(i.build()),i}switchField(e,t){const i=new d(e,"switch",t);return this.addField(i.build()),i}sliderField(e,t){const i=new d(e,"slider",t);return this.addField(i.build()),i}ratingField(e,t){const i=new d(e,"rating",t);return this.addField(i.build()),i}colorField(e,t){const i=new d(e,"color",t);return this.addField(i.build()),i}hiddenField(e,t){const i=new d(e,"hidden","");return i.defaultValue(t),this.addField(i.build()),i}richTextField(e,t){const i=new d(e,"richtext",t);return this.addField(i.build()),i}sectionField(e,t){const i=new d(e,"section",t);return this.addField(i.build()),i}groupField(e,t){const i=new g(e,t);return this.addField(i.build()),i}arrayField(e,t){const i=new A(e,t);return this.addField(i.build()),i}oneOfField(e,t){const i=new O(e,t);return this.addField(i.build()),i}anyOfField(e,t){const i=new x(e,t);return this.addField(i.build()),i}apiField(e,t){const i=new q(e,t);return this.addField(i.build()),i}authField(e,t){const i=new E(e,t);return this.addField(i.build()),i}oAuthField(e,t){const i=new L(e,t);return this.addField(i.build()),i}basicAuthField(e,t){const i=new k(e,t);return this.addField(i.build()),i}apiKeyField(e,t){const i=new J(e,t);return this.addField(i.build()),i}jwtField(e,t){const i=new $(e,t);return this.addField(i.build()),i}samlField(e,t){const i=new U(e,t);return this.addField(i.build()),i}branchField(e,t){const i=new I(e,t);return this.addField(i.build()),i}customField(e,t){const i=new P(e,t);return this.addField(i.build()),i}build(){return this.schema.sortFields(),this.schema}}class X{constructor(e){this.schema=e,this.validator=new W(e)}renderJson(){return JSON.stringify(this.schema,null,2)}renderJsonWithContext(e){const t=this.copySchemaWithContext(e);return JSON.stringify(t,null,2)}copyFieldWithContext(e,t){var s;const i={id:e.id,type:e.type,label:e.label,required:e.required,defaultValue:e.defaultValue,placeholder:e.placeholder,helpText:e.helpText,order:e.order,properties:{...e.properties},nested:[]};if(e.requiredIf&&(i.requiredIf=this.copyCondition(e.requiredIf)),e.validationRules&&(i.validationRules=e.validationRules.map(n=>({type:n.type,message:n.message,parameters:n.parameters}))),e.visible&&(i.visible=this.copyCondition(e.visible)),e.enabled&&(i.enabled=this.copyCondition(e.enabled),this.validator.evaluateCondition(e.enabled,t)||(i.properties.disabled=!0)),e.options&&(i.options=this.copyOptionsWithContext(e.options,t)),e.nested&&e.nested.length>0)for(const n of e.nested){if(n.visible&&!this.validator.evaluateCondition(n.visible,t))continue;const a=this.copyFieldWithContext(n,t);(s=i.nested)==null||s.push(a)}return i}copySchemaWithContext(e){const t={id:this.schema.id,title:this.schema.title,description:this.schema.description,type:this.schema.type,authType:this.schema.authType,fields:[],properties:{...this.schema.properties}};for(const i of this.schema.fields){if(i.visible&&!this.validator.evaluateCondition(i.visible,e))continue;const s=this.copyFieldWithContext(i,e);t.fields.push(s)}return t.fields.sort((i,s)=>i.order-s.order),t}copyCondition(e){const t={type:e.type,field:e.field,value:e.value,operator:e.operator,expression:e.expression};return e.conditions&&e.conditions.length>0&&(t.conditions=e.conditions.map(i=>this.copyCondition(i))),t}copyOptionsWithContext(e,t){if(!e)return null;const i={type:e.type};if(e.static&&(i.static=e.static.map(s=>({value:s.value,label:s.label,icon:s.icon}))),e.dynamicSource&&(i.dynamicSource={type:e.dynamicSource.type,endpoint:e.dynamicSource.endpoint,method:e.dynamicSource.method,valuePath:e.dynamicSource.valuePath,labelPath:e.dynamicSource.labelPath,refreshOn:e.dynamicSource.refreshOn?[...e.dynamicSource.refreshOn]:[]},e.dynamicSource.headers&&(i.dynamicSource.headers={...e.dynamicSource.headers}),e.dynamicSource.parameters&&(i.dynamicSource.parameters={...e.dynamicSource.parameters})),e.dependency){const s=e.dependency.field,n=this.getValueFromContext(t,s);if(i.dependency={field:s},e.dependency.valueMap){i.dependency.valueMap={};for(const[a,u]of Object.entries(e.dependency.valueMap))i.dependency.valueMap[a]=u.map(h=>({value:h.value,label:h.label,icon:h.icon}));if(n!=null){const a=String(n);e.dependency.valueMap[a]&&(i.static=e.dependency.valueMap[a].map(u=>({value:u.value,label:u.label,icon:u.icon})))}}}return i}getValueFromContext(e,t){return this.validator.getValueByPath(e,t)}}function Y(r){return _(r)}function Z(r){return H(r)}const K={importJSON:r=>{let e;try{e=JSON.parse(r)}catch(t){throw new Error(`Failed to parse JSON: ${t==null?void 0:t.message}`)}return H(e)}};function H(r){const e=r.id;if(!e)throw new Error("Missing required 'id' field");const t=r.title;if(!t)throw new Error("Missing required 'title' field");const i=new w(e,t);if(r.description&&(i.description=r.description),r.type&&(i.type=r.type),r.authType&&(i.authType=r.authType),r.properties&&typeof r.properties=="object"&&(i.properties={...r.properties}),r.fields&&Array.isArray(r.fields))for(const s of r.fields)try{const n=z(s);i.addField(n)}catch{}return i.sortFields(),i}function z(r){const e=r.id;if(!e)throw new Error("Missing required 'id' field in field definition");const t=r.type;if(!t)throw new Error("Missing required 'type' field in field definition");const i=r.label||"",s={id:e,type:t,label:i,required:!1,order:0,properties:{}};if(r.required!==void 0&&(s.required=!!r.required),r.placeholder&&(s.placeholder=r.placeholder),r.helpText&&(s.helpText=r.helpText),r.order!==void 0&&(s.order=Number(r.order)),"defaultValue"in r&&(s.defaultValue=r.defaultValue),r.properties&&typeof r.properties=="object"&&(s.properties={...r.properties}),r.visible&&(s.visible=r.visible),r.enabled&&(s.enabled=r.enabled),r.requiredIf&&(s.requiredIf=r.requiredIf),r.validationRules&&Array.isArray(r.validationRules)&&(s.validationRules=r.validationRules),r.options&&(s.options=r.options),r.nested&&Array.isArray(r.nested)){s.nested=[];for(const n of r.nested)try{const a=z(n);s.nested.push(a)}catch{}}return s}function _(r){return K.importJSON(r)}exports.APIFieldBuilder=q;exports.APIKeyBuilder=J;exports.AnyOfFieldBuilder=x;exports.ArrayFieldBuilder=A;exports.AuthFieldBuilder=E;exports.AuthStrategy=F;exports.BasicAuthBuilder=k;exports.BranchFieldBuilder=I;exports.ConditionBuilder=b;exports.ConditionType=o;exports.CustomFieldBuilder=P;exports.DependentOptionsBuilder=N;exports.DependentValueOptionsBuilder=C;exports.DynamicFunctionBuilder=y;exports.DynamicOptionsBuilder=R;exports.DynamicOptionsFunction=V;exports.DynamicOptionsFunctionBuilder=j;exports.FieldBuilder=d;exports.FieldType=S;exports.FormBuilder=M;exports.FormRenderer=X;exports.FormSchemaImpl=w;exports.FormType=v;exports.GroupFieldBuilder=g;exports.JSONImporter=K;exports.JWTBuilder=$;exports.OAuth2Builder=L;exports.OneOfFieldBuilder=O;exports.OptionsBuilder=T;exports.OptionsType=l;exports.SAMLBuilder=U;exports.StaticOptionsBuilder=D;exports.ValidationType=c;exports.Validator=W;exports.formSchemaFromJSON=Y;exports.formSchemaFromObject=Z;exports.newOption=G;exports.newOptionWithIcon=Q;