| 144 | |
| 145 | export class QuickAddApi { |
| 146 | public static GetApi( |
| 147 | app: App, |
| 148 | plugin: QuickAdd, |
| 149 | choiceExecutor: IChoiceExecutor, |
| 150 | ) { |
| 151 | return { |
| 152 | /** |
| 153 | * Open a single one-page modal to collect multiple inputs at once from a script. |
| 154 | * Any values already present in variables will be used as defaults and not re-asked. |
| 155 | * |
| 156 | * Example spec items: |
| 157 | * { id: "project", label: "Project", type: "text", defaultValue: "Inbox" } |
| 158 | * { id: "tags", label: "Tags", type: "suggester", options: ["#work", "#personal"], suggesterConfig: { multiSelect: true } } |
| 159 | */ |
| 160 | requestInputs: async ( |
| 161 | inputs: Array<{ |
| 162 | id: string; |
| 163 | label?: string; |
| 164 | type: |
| 165 | | "text" |
| 166 | | "number" |
| 167 | | "textarea" |
| 168 | | "dropdown" |
| 169 | | "date" |
| 170 | | "field-suggest" |
| 171 | | "suggester" |
| 172 | | "slider"; |
| 173 | placeholder?: string; |
| 174 | defaultValue?: string; |
| 175 | numericConfig?: NumericInputConfig; |
| 176 | sliderConfig?: RequestSliderConfig; |
| 177 | options?: string[]; |
| 178 | dateFormat?: string; |
| 179 | description?: string; |
| 180 | optional?: boolean; |
| 181 | suggesterConfig?: { |
| 182 | allowCustomInput?: boolean; |
| 183 | caseSensitive?: boolean; |
| 184 | multiSelect?: boolean; |
| 185 | }; |
| 186 | }>, |
| 187 | ): Promise<Record<string, string>> => { |
| 188 | // If all inputs already have values, return them immediately |
| 189 | const existing: Record<string, string> = {}; |
| 190 | const missing: FieldRequirement[] = []; |
| 191 | for (const spec of inputs) { |
| 192 | const val = choiceExecutor.variables.get(spec.id) as |
| 193 | | string |
| 194 | | undefined; |
| 195 | // Empty string is considered intentional and should not be re-asked |
| 196 | if (val !== undefined && val !== null) { |
| 197 | existing[spec.id] = String(val); |
| 198 | continue; |
| 199 | } |
| 200 | const sliderConfig = sanitizeSliderConfig(spec.sliderConfig); |
| 201 | const numericConfig = |
| 202 | sliderConfig ?? sanitizeNumericConfig(spec.numericConfig); |
| 203 | const type = |