|
| 1 | +import * as api from '@/api' |
| 2 | + |
| 3 | +/** |
| 4 | + * Parameter types supported by widget definitions |
| 5 | + */ |
| 6 | +export type ParameterType = (typeof api.ConfigDescriptionParameter)['type'] |
| 7 | + |
| 8 | +/** |
| 9 | + * Visibility function type |
| 10 | + * @param value - The current value of the parameter |
| 11 | + * @param configuration - The full configuration object |
| 12 | + * @param configDescription - The configuration description |
| 13 | + * @param parameters - The parameters object |
| 14 | + * @returns Whether the parameter should be visible |
| 15 | + */ |
| 16 | +export type VisibilityFunction = (value: any, configuration: Record<string, any>, configDescription: any, parameters: any) => boolean |
| 17 | + |
| 18 | +/** |
| 19 | + * Parameter class for building widget configuration parameters |
| 20 | + */ |
| 21 | +export declare class Parameter implements api.ConfigDescriptionParameter { |
| 22 | + type: ParameterType |
| 23 | + name: string |
| 24 | + label: string |
| 25 | + description: string |
| 26 | + advanced?: boolean |
| 27 | + context?: string |
| 28 | + groupName?: string |
| 29 | + multiple?: boolean |
| 30 | + options?: Array<api.ParameterOption> |
| 31 | + limitToOptions?: boolean |
| 32 | + default?: any |
| 33 | + required?: boolean |
| 34 | + visible?: VisibilityFunction |
| 35 | + |
| 36 | + constructor(type: ParameterType, name: string, label: string, description: string) |
| 37 | + |
| 38 | + /** |
| 39 | + * Sets the parameter as advanced |
| 40 | + */ |
| 41 | + a(): this |
| 42 | + |
| 43 | + /** |
| 44 | + * Sets the context of the parameter |
| 45 | + */ |
| 46 | + c(context: string): this |
| 47 | + |
| 48 | + /** |
| 49 | + * Sets the groupName of the parameter |
| 50 | + */ |
| 51 | + g(groupName: string): this |
| 52 | + |
| 53 | + /** |
| 54 | + * Sets the parameter as holding multiple values |
| 55 | + */ |
| 56 | + m(): this |
| 57 | + |
| 58 | + /** |
| 59 | + * Sets the options of the parameter |
| 60 | + * @param opts - The array of options |
| 61 | + * @param limitToOptions - Whether valid values should be restricted to options |
| 62 | + * @param multiple - Whether multiple options may be selected |
| 63 | + */ |
| 64 | + o(opts: api.ParameterOption[], limitToOptions?: boolean, multiple?: boolean): this |
| 65 | + |
| 66 | + /** |
| 67 | + * Sets the default value of the parameter |
| 68 | + * @param value - The default value |
| 69 | + */ |
| 70 | + d(value: any): this |
| 71 | + |
| 72 | + /** |
| 73 | + * Sets the parameter as required |
| 74 | + */ |
| 75 | + r(): this |
| 76 | + |
| 77 | + /** |
| 78 | + * The visibility function |
| 79 | + * @param vfn - The visibility function |
| 80 | + */ |
| 81 | + v(vfn: VisibilityFunction): this |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * Widget definition interface |
| 86 | + */ |
| 87 | +export interface _WidgetDefinition { |
| 88 | + name: string |
| 89 | + label: string |
| 90 | + description: string |
| 91 | + icon?: string |
| 92 | + hidden: boolean |
| 93 | + props: api.ConfigDescription |
| 94 | +} |
| 95 | + |
| 96 | +/** |
| 97 | + * The widget definition class, describing the widget and its props (config parameters) |
| 98 | + */ |
| 99 | +export declare class WidgetDefinition implements _WidgetDefinition { |
| 100 | + name: string |
| 101 | + label: string |
| 102 | + description: string |
| 103 | + icon?: string |
| 104 | + hidden: boolean |
| 105 | + docLink?: string |
| 106 | + props: api.ConfigDescription |
| 107 | + |
| 108 | + constructor(name: string, label: string, description: string, icon?: string, hidden?: boolean) |
| 109 | + |
| 110 | + /** |
| 111 | + * Add a parameter group with optional parameters |
| 112 | + * @param group - The parameter group |
| 113 | + * @param params - Optional array of parameters |
| 114 | + * @param advanced - Whether to mark all parameters as advanced |
| 115 | + */ |
| 116 | + paramGroup(group: api.ConfigDescriptionParameterGroup, params?: Parameter[], advanced?: boolean): this |
| 117 | + |
| 118 | + /** |
| 119 | + * Add parameters to the widget |
| 120 | + * @param p - Array of parameters |
| 121 | + */ |
| 122 | + params(p: Parameter[]): this |
| 123 | +} |
| 124 | + |
| 125 | +// Helper functions |
| 126 | + |
| 127 | +/** |
| 128 | + * Builds a parameter |
| 129 | + * @param type - The type of the parameter |
| 130 | + * @param name - The name of the parameter |
| 131 | + * @param label - The untranslated (English) label of the parameter |
| 132 | + * @param description - The untranslated (English) description of the parameter |
| 133 | + */ |
| 134 | +export declare function p(type: ParameterType, name: string, label: string, description: string): Parameter |
| 135 | + |
| 136 | +/** |
| 137 | + * Builds a boolean parameter |
| 138 | + * @param name - The name of the parameter |
| 139 | + * @param label - The untranslated (English) label of the parameter |
| 140 | + * @param description - The untranslated (English) description of the parameter |
| 141 | + */ |
| 142 | +export declare function pb(name: string, label: string, description: string): Parameter |
| 143 | + |
| 144 | +/** |
| 145 | + * Builds a decimal parameter |
| 146 | + * @param name - The name of the parameter |
| 147 | + * @param label - The untranslated (English) label of the parameter |
| 148 | + * @param description - The untranslated (English) description of the parameter |
| 149 | + */ |
| 150 | +export declare function pd(name: string, label: string, description: string): Parameter |
| 151 | + |
| 152 | +/** |
| 153 | + * Builds a parameter group |
| 154 | + * @param name - The name of the group |
| 155 | + * @param label - The untranslated (English) label of the group |
| 156 | + * @param description - The untranslated (English) description of the group |
| 157 | + */ |
| 158 | +export declare function pg(name: string, label: string, description?: string): api.ConfigDescriptionParameterGroup |
| 159 | + |
| 160 | +/** |
| 161 | + * Builds an item parameter |
| 162 | + * @param name - The name of the parameter |
| 163 | + * @param label - The untranslated (English) label of the parameter |
| 164 | + * @param description - The untranslated (English) description of the parameter |
| 165 | + */ |
| 166 | +export declare function pi(name: string, label: string, description: string): Parameter |
| 167 | + |
| 168 | +/** |
| 169 | + * Builds a text parameter with options |
| 170 | + * @param name - The name of the parameter |
| 171 | + * @param label - The untranslated (English) label of the parameter |
| 172 | + * @param description - The untranslated (English) description of the parameter |
| 173 | + * @param options - An array of options with untranslated (English) labels |
| 174 | + */ |
| 175 | +export declare function po(name: string, label: string, description: string, options: api.ParameterOption[]): Parameter |
| 176 | + |
| 177 | +/** |
| 178 | + * Builds a numerical (integer) parameter |
| 179 | + * @param name - The name of the parameter |
| 180 | + * @param label - The untranslated (English) label of the parameter |
| 181 | + * @param description - The untranslated (English) description of the parameter |
| 182 | + */ |
| 183 | +export declare function pn(name: string, label: string, description: string): Parameter |
| 184 | + |
| 185 | +/** |
| 186 | + * Builds a text parameter |
| 187 | + * @param name - The name of the parameter |
| 188 | + * @param label - The untranslated (English) label of the parameter |
| 189 | + * @param description - The untranslated (English) description of the parameter |
| 190 | + */ |
| 191 | +export declare function pt(name: string, label: string, description: string): Parameter |
0 commit comments