UNPKG

@xraph/smartform-react

Version:

React library for rendering and validating SmartForms with shadcn components

1,844 lines (1,843 loc) 96.5 kB
var v = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.Auth = "auth", r))(v || {}), B = /* @__PURE__ */ ((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))(B || {}), o = /* @__PURE__ */ ((r) => (r.Simple = "simple", r.And = "and", r.Or = "or", r.Not = "not", r.Exists = "exists", r.Expression = "expression", r))(o || {}), c = /* @__PURE__ */ ((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 || {}), h = /* @__PURE__ */ ((r) => (r.Static = "static", r.Dynamic = "dynamic", r.Dependent = "dependent", r))(h || {}), F = /* @__PURE__ */ ((r) => (r.OAuth2 = "oauth2", r.Basic = "basic", r.APIKey = "apikey", r.JWT = "jwt", r.SAML = "saml", r.Custom = "custom", r))(F || {}); class D { /** * Creates a new options builder */ constructor() { this.config = { type: h.Static }; } /** * Creates a static options configuration */ static() { return this.config.type = h.Static, this.config.static = [], new N(this); } /** * Creates a dynamic options configuration */ dynamic() { return this.config.type = h.Dynamic, this.config.dynamicSource = {}, new C(this); } /** * Creates a dependent options configuration * @param field Field that options depend on */ dependent(e) { return this.config.type = h.Dependent, this.config.dependency = { field: e, valueMap: {} }, new V(this); } /** * Extracts the dynamic source from the options config */ getDynamicSource() { if (this.config.type === h.Dynamic) return this.config.dynamicSource; } /** * Finalizes and returns the options configuration */ build() { return this.config; } } class N { /** * Creates a new static options builder * @param optionsBuilder Parent options builder */ constructor(e) { this.optionsBuilder = e; } /** * Adds an option to the static options list * @param value Option value * @param label Option label */ 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; } /** * Adds an option with an icon to the static options list * @param value Option value * @param label Option label * @param icon Option icon */ 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; } /** * Adds multiple options to the static options list * @param options Options to add */ addOptions(...e) { return this.optionsBuilder.config.static || (this.optionsBuilder.config.static = []), this.optionsBuilder.config.static.push(...e), this; } /** * Finalizes and returns the options configuration */ build() { return this.optionsBuilder.build(); } } class C { /** * Creates a new dynamic options builder * @param optionsBuilder Parent options builder */ constructor(e) { this.optionsBuilder = e; } /** * Configures options to be fetched from an API endpoint * @param endpoint API endpoint URL * @param method HTTP method */ 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; } /** * Configures options to be fetched from an API endpoint with paths * @param endpoint API endpoint URL * @param method HTTP method * @param valuePath JSON path to value in response * @param labelPath JSON path to label in response */ 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; } /** * Adds an HTTP header to the API request * @param key Header key * @param value Header value */ 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; } /** * Adds a parameter to the API request * @param key Parameter key * @param value Parameter value */ 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; } /** * Sets the JSON path to the value in the response * @param path JSON path */ withValuePath(e) { return this.optionsBuilder.config.dynamicSource && (this.optionsBuilder.config.dynamicSource.valuePath = e), this; } /** * Sets the JSON path to the label in the response * @param path JSON path */ withLabelPath(e) { return this.optionsBuilder.config.dynamicSource && (this.optionsBuilder.config.dynamicSource.labelPath = e), this; } /** * Sets fields that trigger options refresh * @param fieldIDs Field IDs */ refreshOn(...e) { return this.optionsBuilder.config.dynamicSource && (this.optionsBuilder.config.dynamicSource.refreshOn = e), this; } /** * Configures options to be generated by a custom function * @param functionName Function name */ fromFunction(e) { return this.optionsBuilder.config.dynamicSource && (this.optionsBuilder.config.dynamicSource.type = "function", this.optionsBuilder.config.dynamicSource.functionName = e), this; } /** * Configures options to come from a dynamic function * @param functionNameOrFn Function name or implementation */ 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 L(this.optionsBuilder); } withSource(e) { return this.optionsBuilder.config.dynamicSource && (this.optionsBuilder.config.dynamicSource = e), this; } /** * Finalizes and returns the options configuration */ build() { return this.optionsBuilder.build(); } } class V { /** * Creates a new dependent options builder * @param optionsBuilder Parent options builder */ constructor(e) { this.optionsBuilder = e; } /** * Adds options for a specific value of the dependent field * @param value Dependent field value */ whenEquals(e) { return new j(this, e); } /** * Sets a custom expression for option filtering * @param expression Custom expression */ withExpression(e) { return this.optionsBuilder.config.dependency && (this.optionsBuilder.config.dependency.expression = e), this; } /** * Finalizes and returns the options configuration */ build() { return this.optionsBuilder.build(); } } class j { /** * Creates a new dependent value options builder * @param dependentOptionsBuilder Parent dependent options builder * @param value Dependent field value */ constructor(e, t) { this.dependentOptionsBuilder = e, this.value = t; } /** * Adds an option for the current value * @param value Option value * @param label Option label */ 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; } /** * Adds an option with an icon for the current value * @param value Option value * @param label Option label * @param icon Option icon */ 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; } /** * Adds multiple options for the current value * @param options Options to add */ 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; } /** * Returns to the parent dependent options builder */ end() { return this.dependentOptionsBuilder; } } function Q(r, e) { return { value: r, label: e }; } function X(r, e, t) { return { value: r, label: e, icon: t }; } let L = class { /** * Creates a new dynamic options function builder * @param optionsBuilder Parent options builder */ constructor(e) { this.optionsBuilder = e; } /** * Adds an argument to the dynamic function * @param name Argument name * @param value Argument value */ withArgument(e, t) { var i; return (i = this.optionsBuilder.config.dynamicSource) != null && i.parameters && (this.optionsBuilder.config.dynamicSource.parameters[e] = t), this; } /** * Adds multiple arguments to the dynamic function * @param args Arguments to add */ 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; } /** * Adds a field reference as an argument * @param argName Argument name * @param fieldId Field ID to reference */ withFieldReference(e, t) { var i; return (i = this.optionsBuilder.config.dynamicSource) != null && i.parameters && (this.optionsBuilder.config.dynamicSource.parameters[e] = `\${${t}}`), this; } /** * Finalizes and returns the options configuration */ build() { return this.optionsBuilder.build(); } }; class d { /** * Creates a new field builder * @param id Field identifier * @param fieldType Field type * @param label Field display label */ constructor(e, t, i) { this.field = { id: e, type: t, label: i, required: !1, properties: {}, order: 0 }; } /** * Marks the field as required * @param required Whether the field is required */ required(e = !0) { return this.field.required = e, this; } /** * Sets the field placeholder text * @param placeholder Placeholder text */ placeholder(e) { return this.field.placeholder = e, this; } /** * Sets the field help text * @param helpText Help text to display */ helpText(e) { return this.field.helpText = e, this; } /** * Sets the field default value * @param value Default value */ defaultValue(e) { return this.field.defaultValue = e, this; } /** * Sets the field order * @param order Display order */ order(e) { return this.field.order = e, this; } /** * Sets a custom property on the field * @param key Property key * @param value Property value */ property(e, t) { return this.field.properties[e] = t, this; } /** * Sets a conditional requirement for the field * @param condition Condition for requirement */ requiredIf(e) { return this.field.requiredIf = e, this; } /** * Makes the field required when another field equals a value * @param fieldId ID of the field to check * @param value Value to compare with */ requiredWhenEquals(e, t) { return this.field.requiredIf = { type: o.Simple, field: e, operator: "eq", value: t }, this; } /** * Makes the field required when another field doesn't equal a value * @param fieldId ID of the field to check * @param value Value to compare with */ requiredWhenNotEquals(e, t) { return this.field.requiredIf = { type: o.Simple, field: e, operator: "neq", value: t }, this; } /** * Makes the field required when another field is greater than a value * @param fieldId ID of the field to check * @param value Value to compare with */ requiredWhenGreaterThan(e, t) { return this.field.requiredIf = { type: o.Simple, field: e, operator: "gt", value: t }, this; } /** * Makes the field required when another field is less than a value * @param fieldId ID of the field to check * @param value Value to compare with */ requiredWhenLessThan(e, t) { return this.field.requiredIf = { type: o.Simple, field: e, operator: "lt", value: t }, this; } /** * Makes the field required when another field exists and is not empty * @param fieldId ID of the field to check */ requiredWhenExists(e) { return this.field.requiredIf = { type: o.Exists, field: e }, this; } /** * Makes the field required when all specified conditions match * @param conditions Conditions to check */ requiredWhenAllMatch(...e) { return this.field.requiredIf = { type: o.And, conditions: e }, this; } /** * Makes the field required when any of the specified conditions match * @param conditions Conditions to check */ requiredWhenAnyMatch(...e) { return this.field.requiredIf = { type: o.Or, conditions: e }, this; } /** * Makes the field required based on a custom expression * @param expression Custom expression to evaluate */ requiredWithExpression(e) { return this.field.requiredIf = { type: o.Expression, expression: e }, this; } /** * Sets visibility condition for the field * @param condition Condition determining visibility */ visibleWhen(e) { return this.field.visible = e, this; } /** * Makes the field visible when another field equals a value * @param fieldId ID of the field to check * @param value Value to compare with */ visibleWhenEquals(e, t) { return this.field.visible = { type: o.Simple, field: e, operator: "eq", value: t }, this; } /** * Makes the field visible when another field doesn't equal a value * @param fieldId ID of the field to check * @param value Value to compare with */ visibleWhenNotEquals(e, t) { return this.field.visible = { type: o.Simple, field: e, operator: "neq", value: t }, this; } /** * Makes the field visible when another field is greater than a value * @param fieldId ID of the field to check * @param value Value to compare with */ visibleWhenGreaterThan(e, t) { return this.field.visible = { type: o.Simple, field: e, operator: "gt", value: t }, this; } /** * Makes the field visible when another field is less than a value * @param fieldId ID of the field to check * @param value Value to compare with */ visibleWhenLessThan(e, t) { return this.field.visible = { type: o.Simple, field: e, operator: "lt", value: t }, this; } /** * Makes the field visible when another field exists and is not empty * @param fieldId ID of the field to check */ visibleWhenExists(e) { return this.field.visible = { type: o.Exists, field: e }, this; } /** * Makes the field visible when all specified conditions match * @param conditions Conditions to check */ visibleWhenAllMatch(...e) { return this.field.visible = { type: o.And, conditions: e }, this; } /** * Makes the field visible when any of the specified conditions match * @param conditions Conditions to check */ visibleWhenAnyMatch(...e) { return this.field.visible = { type: o.Or, conditions: e }, this; } /** * Makes the field visible based on a custom expression * @param expression Custom expression to evaluate */ visibleWithExpression(e) { return this.field.visible = { type: o.Expression, expression: e }, this; } /** * Sets enablement condition for the field * @param condition Condition determining enablement */ enabledWhen(e) { return this.field.enabled = e, this; } /** * Makes the field enabled when another field equals a value * @param fieldId ID of the field to check * @param value Value to compare with */ enabledWhenEquals(e, t) { return this.field.enabled = { type: o.Simple, field: e, operator: "eq", value: t }, this; } /** * Makes the field enabled when another field doesn't equal a value * @param fieldId ID of the field to check * @param value Value to compare with */ enabledWhenNotEquals(e, t) { return this.field.enabled = { type: o.Simple, field: e, operator: "neq", value: t }, this; } /** * Makes the field enabled when another field exists and is not empty * @param fieldId ID of the field to check */ enabledWhenExists(e) { return this.field.enabled = { type: o.Exists, field: e }, this; } /** * Adds a validation rule to the field * @param rule Validation rule to add */ addValidation(e) { return this.field.validationRules || (this.field.validationRules = []), this.field.validationRules.push(e), this; } /** * Adds a required validation rule * @param message Validation error message */ validateRequired(e) { return this.addValidation({ type: c.Required, message: e }); } /** * Adds a minimum length validation rule * @param min Minimum length * @param message Validation error message */ validateMinLength(e, t) { return this.addValidation({ type: c.MinLength, message: t, parameters: e }); } /** * Adds a maximum length validation rule * @param max Maximum length * @param message Validation error message */ validateMaxLength(e, t) { return this.addValidation({ type: c.MaxLength, message: t, parameters: e }); } /** * Adds a pattern validation rule * @param pattern Regular expression pattern * @param message Validation error message */ validatePattern(e, t) { return this.addValidation({ type: c.Pattern, message: t, parameters: e }); } /** * Adds a minimum value validation rule * @param min Minimum value * @param message Validation error message */ validateMin(e, t) { return this.addValidation({ type: c.Min, message: t, parameters: e }); } /** * Adds a maximum value validation rule * @param max Maximum value * @param message Validation error message */ validateMax(e, t) { return this.addValidation({ type: c.Max, message: t, parameters: e }); } /** * Adds an email validation rule * @param message Validation error message */ validateEmail(e) { return this.addValidation({ type: c.Email, message: e }); } /** * Adds a URL validation rule * @param message Validation error message */ validateURL(e) { return this.addValidation({ type: c.URL, message: e }); } /** * Adds a file type validation rule * @param allowedTypes Allowed file types * @param message Validation error message */ validateFileType(e, t) { return this.addValidation({ type: c.FileType, message: t, parameters: e }); } /** * Adds a file size validation rule * @param maxSize Maximum file size * @param message Validation error message */ validateFileSize(e, t) { return this.addValidation({ type: c.FileType, message: t, parameters: e }); } /** * Adds an image dimensions validation rule * @param dimensions Image dimension constraints * @param message Validation error message */ validateImageDimensions(e, t) { return this.addValidation({ type: c.ImageDimensions, message: t, parameters: e }); } /** * Adds a field dependency validation rule * @param dependency Dependency configuration * @param message Validation error message */ validateDependency(e, t) { return this.addValidation({ type: c.Dependency, message: t, parameters: e }); } /** * Adds a uniqueness validation rule * @param message Validation error message */ validateUnique(e) { return this.addValidation({ type: c.Unique, message: e }); } /** * Adds a custom validation rule * @param params Rule parameters * @param message Validation error message */ validateCustom(e, t) { return this.addValidation({ type: c.Custom, message: t, parameters: e }); } /** * Adds static options to the field * @param options Options to add */ withStaticOptions(e) { return this.field.options = { type: h.Static, static: e }, this; } /** * Adds dynamic options that come directly from a function * @param functionNameOrFn Function name or implementation */ 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 D().dynamic(); i.withSource(t), this.field.options = i.build(); const s = { functionName: t.functionName, arguments: {} }; return new k(i, s); } /** * Adds dynamic options to the field * @param source Dynamic options source */ withDynamicOptions(e) { return this.field.options = { type: h.Dynamic, dynamicSource: e }, this; } /** * Adds a dynamic function to the field * @param functionName Function name */ withDynamicFunction(e) { const t = { functionName: e, arguments: {} }; return this.field.properties.dynamicFunction = t, new y(this, t); } /** * Checks if the field has a dynamic function */ hasDynamicFunction() { return this.field.properties.dynamicFunction !== void 0; } /** * Gets the dynamic function config for the field */ getDynamicFunctionConfig() { return this.field.properties.dynamicFunction; } /** * Adds dependent options to the field * @param dependentField Field that options depend on * @param valueMap Mapping from dependent field values to options */ withDependentOptions(e, t) { return this.field.options = { type: h.Dependent, dependency: { field: e, valueMap: t } }, this; } /** * Adds a single option to the field * @param value Option value * @param label Option label */ addOption(e, t) { const i = { value: e, label: t }; return this.field.options ? this.field.options.type === h.Static ? (this.field.options.static || (this.field.options.static = []), this.field.options.static.push(i)) : this.field.options = { type: h.Static, static: [i] } : this.field.options = { type: h.Static, static: [i] }, this; } /** * Adds multiple options to the field * @param options Options to add */ addOptions(...e) { return this.field.options ? this.field.options.type === h.Static ? (this.field.options.static || (this.field.options.static = []), this.field.options.static.push(...e)) : this.field.options = { type: h.Static, static: e } : this.field.options = { type: h.Static, static: e }, this; } /** * Adds dynamic options from an API endpoint * @param endpoint API endpoint URL * @param method HTTP method * @param valuePath JSON path to value in response * @param labelPath JSON path to label in response */ withOptionsFromAPI(e, t, i, s) { const n = { type: "api", endpoint: e, method: t, valuePath: i, labelPath: s }; return this.withDynamicOptions(n); } /** * Adds refresh triggers to dynamic options * @param fieldIDs Fields that trigger refresh */ withOptionsRefreshingOn(...e) { var t; return (t = this.field.options) != null && t.dynamicSource && (this.field.options.dynamicSource.refreshOn = e), this; } /** * Adds dynamic options from a config * @param config Options configuration */ withDynamicOptionsConfig(e) { return e.type === h.Dynamic && e.dynamicSource ? this.field.options = { type: h.Dynamic, dynamicSource: e.dynamicSource } : this.field.options = e, this; } /** * Adds a dynamic value calculation to the field * @param functionName Function name */ dynamicValue(e) { return this.field.properties.dynamicValue = !0, this.withDynamicFunction(e); } /** * Adds a dynamic validation rule to the field * @param functionName Function name * @param message Validation error message */ dynamicValidation(e, t) { const i = { functionName: e, arguments: {} }; return this.addValidation({ type: c.Custom, message: t, parameters: { dynamicFunction: i } }), new y(this, i); } /** * Adds autocomplete functionality to text fields * @param functionName Function name */ autocompleteField(e) { if (this.field.type !== B.Text && this.field.type !== B.Email && this.field.type !== B.Password) return null; this.field.properties.autocomplete = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.autocompleteFunction = t, new y(this, t); } /** * Adds live search capability to a field * @param functionName Function name */ liveSearch(e) { this.field.properties.liveSearch = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.searchFunction = t, new y(this, t); } /** * Sets a dynamic data source for the field * @param functionName Function name */ dataSource(e) { this.field.properties.dataSource = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.dataSourceFunction = t, new y(this, t); } /** * Adds a dynamic formatter to the field * @param functionName Function name */ formatter(e) { this.field.properties.formatter = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.formatterFunction = t, new y(this, t); } /** * Adds a dynamic parser to the field * @param functionName Function name */ parser(e) { this.field.properties.parser = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.parserFunction = t, new y(this, t); } /** * Adds a conditional default value to the field * @param condition Condition to check * @param value Default value to apply if condition is true */ defaultWhen(e, t) { return this.field.defaultWhen || (this.field.defaultWhen = []), this.field.defaultWhen.push({ condition: e, value: t }), this; } /** * Adds a conditional default value based on field equality * @param fieldId Field to check * @param equals Value to compare with * @param value Default value to apply */ defaultWhenEquals(e, t, i) { const s = { type: o.Simple, field: e, operator: "eq", value: t }; return this.defaultWhen(s, i); } /** * Adds a conditional default value based on field inequality * @param fieldId Field to check * @param notEquals Value to compare with * @param value Default value to apply */ defaultWhenNotEquals(e, t, i) { const s = { type: o.Simple, field: e, operator: "neq", value: t }; return this.defaultWhen(s, i); } /** * Adds a conditional default value based on field comparison * @param fieldId Field to check * @param greaterThan Value to compare with * @param value Default value to apply */ defaultWhenGreaterThan(e, t, i) { const s = { type: o.Simple, field: e, operator: "gt", value: t }; return this.defaultWhen(s, i); } /** * Adds a conditional default value based on field comparison * @param fieldId Field to check * @param lessThan Value to compare with * @param value Default value to apply */ defaultWhenLessThan(e, t, i) { const s = { type: o.Simple, field: e, operator: "lt", value: t }; return this.defaultWhen(s, i); } /** * Adds a conditional default value based on field existence * @param fieldId Field to check * @param value Default value to apply */ defaultWhenExists(e, t) { const i = { type: o.Exists, field: e }; return this.defaultWhen(i, t); } /** * Adds a conditional default value based on a custom expression * @param expression Expression to evaluate * @param value Default value to apply */ defaultWhenExpression(e, t) { const i = { type: o.Expression, expression: e }; return this.defaultWhen(i, t); } /** * Finalizes and returns the field * @returns The completed field */ build() { return this.field; } } class y { /** * Creates a new dynamic function builder * @param fieldBuilder Parent field builder * @param config Dynamic function configuration */ constructor(e, t) { this.fieldBuilder = e, this.config = t; } /** * Adds an argument to the dynamic function * @param name Argument name * @param value Argument value */ withArgument(e, t) { return this.config.arguments[e] = t, this; } /** * Adds multiple arguments to the dynamic function * @param args Arguments to add */ withArguments(e) { for (const [t, i] of Object.entries(e)) this.config.arguments[t] = i; return this; } /** * Adds a field reference as an argument * @param argName Argument name * @param fieldId Field ID to reference */ withFieldReference(e, t) { return this.config.arguments[e] = `\${${t}}`, this; } /** * Adds a data transformer to the dynamic function * @param transformerName Transformer name */ withTransformer(e) { return this.config.transformerName = e, this.config.transformerParams = {}, this; } /** * Adds a parameter to the transformer * @param name Parameter name * @param value Parameter value */ withTransformerParam(e, t) { return this.config.transformerParams || (this.config.transformerParams = {}), this.config.transformerParams[e] = t, this; } /** * Returns to the field builder * @returns The parent field builder */ end() { return this.fieldBuilder; } } class k { /** * Creates a new dynamic options function builder * @param dynamicOptionsBuilder Parent options builder * @param config Dynamic function configuration */ constructor(e, t) { this.dynamicOptionsBuilder = e, this.config = t; } /** * Adds an argument to the dynamic function * @param name Argument name * @param value Argument value */ 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; } /** * Adds multiple arguments to the dynamic function * @param args Arguments to add */ withArguments(e) { for (const [t, i] of Object.entries(e)) this.withArgument(t, i); return this; } /** * Adds a field reference as an argument * @param argName Argument name * @param fieldId Field ID to reference */ withFieldReference(e, t) { const i = `\${${t}}`; return this.withArgument(e, i); } /** * Adds a data transformer to the dynamic function * @param transformerName Transformer name */ 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; } /** * Adds a parameter to the transformer * @param name Parameter name * @param value Parameter value */ 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; } /** * Enables search and filtering for the options */ withSearchSupport() { return this.config.transformerParams || (this.config.transformerParams = {}), this.config.transformerParams.enableSearch = !0, this; } /** * Specifies which fields can be filtered * @param fields Fields that can be filtered */ withFilterableFields(...e) { return this.config.transformerParams || (this.config.transformerParams = {}), this.config.transformerParams.filterableFields = e, this; } /** * Specifies which fields can be sorted * @param fields Fields that can be sorted */ withSortableFields(...e) { return this.config.transformerParams || (this.config.transformerParams = {}), this.config.transformerParams.sortableFields = e, this; } /** * Enables pagination for the options * @param defaultLimit Default page size */ withPagination(e) { return this.config.transformerParams || (this.config.transformerParams = {}), this.config.transformerParams.enablePagination = !0, this.config.transformerParams.defaultLimit = e, this; } /** * Returns to the dynamic options builder * @returns The parent dynamic options builder */ end() { return this.dynamicOptionsBuilder; } } class g extends d { /** * Creates a new group field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "group", t), this.field.nested = []; } /** * Adds a nested field to the group * @param field Field to add */ addField(e) { return this.field.nested || (this.field.nested = []), this.field.nested.push(e), this; } /** * Adds a text field to the group * @param id Field identifier * @param label Field display label */ textField(e, t) { const i = new d(e, "text", t); return this.addField(i.build()), i; } /** * Adds a textarea field to the group * @param id Field identifier * @param label Field display label */ textareaField(e, t) { const i = new d(e, "textarea", t); return this.addField(i.build()), i; } /** * Adds a number field to the group * @param id Field identifier * @param label Field display label */ numberField(e, t) { const i = new d(e, "number", t); return this.addField(i.build()), i; } /** * Adds an email field to the group * @param id Field identifier * @param label Field display label */ emailField(e, t) { const i = new d(e, "email", t); return this.addField(i.build()), i; } /** * Adds a select field to the group * @param id Field identifier * @param label Field display label */ selectField(e, t) { const i = new d(e, "select", t); return this.addField(i.build()), i; } /** * Adds a checkbox field to the group * @param id Field identifier * @param label Field display label */ checkboxField(e, t) { const i = new d(e, "checkbox", t); return this.addField(i.build()), i; } /** * Adds a radio button field to the group * @param id Field identifier * @param label Field display label */ radioField(e, t) { const i = new d(e, "radio", t); return this.addField(i.build()), i; } /** * Adds a multi-select field to the group * @param id Field identifier * @param label Field display label */ multiSelectField(e, t) { const i = new d(e, "multiselect", t); return this.addField(i.build()), i; } /** * Adds a password field to the group * @param id Field identifier * @param label Field display label */ passwordField(e, t) { const i = new d(e, "password", t); return this.addField(i.build()), i; } /** * Adds a file upload field to the group * @param id Field identifier * @param label Field display label */ fileField(e, t) { const i = new d(e, "file", t); return this.addField(i.build()), i; } /** * Adds an object field to the group * @param id Field identifier * @param label Field display label */ objectField(e, t) { const i = new g(e, t); return this.addField(i.build()), i; } /** * Adds an object template to the group * @param id Field identifier * @param label Field display label */ objectTemplate(e, t) { const i = new g(e, t); return this.addField(i.build()), i; } /** * Adds an array field to the group * @param id Field identifier * @param label Field display label */ arrayField(e, t) { const i = new W(e, t); return this.addField(i.build()), i; } /** * Adds a oneOf field to the group * @param id Field identifier * @param label Field display label */ oneOfField(e, t) { const i = new x(e, t); return this.addField(i.build()), i; } /** * Adds an anyOf field to the group * @param id Field identifier * @param label Field display label */ anyOfField(e, t) { const i = new O(e, t); return this.addField(i.build()), i; } /** * Adds an API integration field to the group * @param id Field identifier * @param label Field display label */ apiField(e, t) { const i = new q(e, t); return this.addField(i.build()), i; } /** * Adds an authentication field to the group * @param id Field identifier * @param label Field display label */ authField(e, t) { const i = new E(e, t); return this.addField(i.build()), i; } /** * Adds a workflow branch field to the group * @param id Field identifier * @param label Field display label */ branchField(e, t) { const i = new I(e, t); return this.addField(i.build()), i; } /** * Adds a custom field to the group * @param id Field identifier * @param label Field display label */ customField(e, t) { const i = new P(e, t); return this.addField(i.build()), i; } /** * Adds a hidden field to the group * @param id Field identifier * @param label Field display label */ hiddenField(e, t) { const i = new d(e, "hidden", t); return this.addField(i.build()), i; } /** * Adds a date field to the group * @param id Field identifier * @param label Field display label */ dateField(e, t) { const i = new d(e, "date", t); return this.addField(i.build()), i; } } class W extends d { /** * Creates a new array field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "array", t), this.field.nested = []; } /** * Sets the template for array items * @param field Template field */ itemTemplate(e) { return this.field.nested || (this.field.nested = []), this.field.nested.push(e), this; } /** * Adds a text field template to the array * @param id Field identifier * @param label Field display label */ textField(e, t) { const i = new d(e, "text", t); return this.itemTemplate(i.build()), i; } /** * Adds an object field template to the array * @param id Field identifier * @param label Field display label */ objectTemplate(e, t) { const i = new g(e, t); return this.itemTemplate(i.build()), i; } /** * Creates a GroupFieldBuilder with the given fields, sets it as an item template * @param id Field identifier * @param label Field display label * @param fields Fields to add to the group */ objectTemplateWithFields(e, t, i) { const s = new g(e, t); for (const n of i) s.addField(n); return this.itemTemplate(s.build()), s; } /** * Adds a date field to the array * @param id Field identifier * @param label Field display label */ dateField(e, t) { const i = new d(e, "date", t); return this.itemTemplate(i.build()), i; } /** * Adds a number field to the array * @param id Field identifier * @param label Field display label */ numberField(e, t) { const i = new d(e, "number", t); return this.itemTemplate(i.build()), i; } /** * Adds an email field to the array * @param id Field identifier * @param label Field display label */ emailField(e, t) { const i = new d(e, "email", t); return this.itemTemplate(i.build()), i; } /** * Adds a select field to the array * @param id Field identifier * @param label Field display label */ selectField(e, t) { const i = new d(e, "select", t); return this.itemTemplate(i.build()), i; } /** * Adds a checkbox field to the array * @param id Field identifier * @param label Field display label */ checkboxField(e, t) { const i = new d(e, "checkbox", t); return this.itemTemplate(i.build()), i; } /** * Adds a radio field to the array * @param id Field identifier * @param label Field display label */ radioField(e, t) { const i = new d(e, "radio", t); return this.itemTemplate(i.build()), i; } /** * Adds a multi-select field to the array * @param id Field identifier * @param label Field display label */ multiSelectField(e, t) { const i = new d(e, "multiselect", t); return this.itemTemplate(i.build()), i; } /** * Adds a password field to the array * @param id Field identifier * @param label Field display label */ passwordField(e, t) { const i = new d(e, "password", t); return this.itemTemplate(i.build()), i; } /** * Adds a file field to the array * @param id Field identifier * @param label Field display label */ fileField(e, t) { const i = new d(e, "file", t); return this.itemTemplate(i.build()), i; } /** * Adds a object field to the array * @param id Field identifier * @param label Field display label */ objectField(e, t) { const i = new g(e, t); return this.itemTemplate(i.build()), i; } /** * Adds a oneOf field to the array * @param id Field identifier * @param label Field display label */ oneOfField(e, t) { const i = new x(e, t); return this.itemTemplate(i.build()), i; } /** * Adds an anyOf field to the array * @param id Field identifier * @param label Field display label */ anyOfField(e, t) { const i = new O(e, t); return this.itemTemplate(i.build()), i; } /** * Adds an API field to the array * @param id Field identifier * @param label Field display label */ apiField(e, t) { const i = new q(e, t); return this.itemTemplate(i.build()), i; } /** * Adds an authentication field to the array * @param id Field identifier * @param label Field display label */ authField(e, t) { const i = new E(e, t); return this.itemTemplate(i.build()), i; } /** * Adds a branch field to the array * @param id Field identifier * @param label Field display label */ branchField(e, t) { const i = new I(e, t); return this.itemTemplate(i.build()), i; } /** * Adds a custom field to the array * @param id Field identifier * @param label Field display label */ customField(e, t) { const i = new P(e, t); return this.itemTemplate(i.build()), i; } /** * Adds a hidden field to the array * @param id Field identifier * @param label Field display label */ hiddenField(e, t) { const i = new d(e, "hidden", t); return this.itemTemplate(i.build()), i; } /** * Sets the minimum number of items in the array * @param min Minimum items */ minItems(e) { return this.property("minItems", e), this; } /** * Sets the maximum number of items in the array * @param max Maximum items */ maxItems(e) { return this.property("maxItems", e), this; } } class x extends d { /** * Creates a new oneOf field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "oneOf", t), this.field.nested = []; } /** * Adds an option to the oneOf field * @param field Option field */ addOption(e) { return this.field.nested || (this.field.nested = []), this.field.nested.push(e), this; } /** * Adds a group option to the oneOf field * @param id Field identifier * @param label Field display label */ groupOption(e, t) { const i = new g(e, t); return this.addOption(i.build()), i; } } class O extends d { /** * Creates a new anyOf field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "anyOf", t), this.field.nested = []; } /** * Adds an option to the anyOf field * @param field Option field */ addOption(e) { return this.field.nested || (this.field.nested = []), this.field.nested.push(e), this; } /** * Adds a group option to the anyOf field * @param id Field identifier * @param label Field display label */ groupOption(e, t) { const i = new g(e, t); return this.addOption(i.build()), i; } } class q extends d { /** * Creates a new API field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "api", t); } /** * Sets the API endpoint * @param endpoint API endpoint URL */ endpoint(e) { return this.property("endpoint", e), this; } /** * Sets the HTTP method * @param method HTTP method */ method(e) { return this.property("method", e), this; } /** * Adds an HTTP header * @param key Header key * @param value Header value */ 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; } /** * Adds a request parameter * @param key Parameter key * @param value Parameter value */ 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; } /** * Sets a mapping from API response to form fields * @param mapping Response mapping */ responseMapping(e) { return this.property("responseMapping", e), this; } /** * Adds dynamic request generation to the API field * @param functionName Function name */ withDynamicRequest(e) { this.field.properties.dynamicRequest = !0; const t = { functionName: e, arguments: {} }; return this.field.properties.requestFunction = t, new y(this, t); } /** * Adds dynamic response handling to the API field * @param functionName Function name */ 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 { /** * Creates a new authentication field builder * @param id Field identifier * @param label Field display label */ constructor(e, t) { super(e, "auth", t); } /** * Sets the authentication type * @param authType Authentication type */ authType(e) { return this.property("authType", e), this; } /** * Sets the service ID for authentication * @param serviceId Service ID */