(req: FieldRequirement)
| 153 | } |
| 154 | |
| 155 | private renderField(req: FieldRequirement) { |
| 156 | const setValue = (id: string, value: string) => { |
| 157 | this.result.set(id, value); |
| 158 | this.updatePreviewDebounced(); |
| 159 | }; |
| 160 | const starting = this.initialValues.get(req.id) ?? req.defaultValue ?? ""; |
| 161 | |
| 162 | switch (req.type) { |
| 163 | case "textarea": { |
| 164 | const setting = new Setting(this.contentEl).setName( |
| 165 | this.decorateLabel(req), |
| 166 | ); |
| 167 | if (req.description) setting.setDesc(req.description); |
| 168 | const input = new TextAreaComponent(setting.controlEl); |
| 169 | input |
| 170 | .setPlaceholder(req.placeholder ?? "") |
| 171 | .setValue(starting) |
| 172 | .onChange((v) => setValue(req.id, v)); |
| 173 | input.inputEl.addClass("qa-onepage-textarea"); |
| 174 | break; |
| 175 | } |
| 176 | case "text": { |
| 177 | const setting = new Setting(this.contentEl).setName( |
| 178 | this.decorateLabel(req), |
| 179 | ); |
| 180 | if (req.description) setting.setDesc(req.description); |
| 181 | const input = new TextComponent(setting.controlEl); |
| 182 | input |
| 183 | .setPlaceholder(req.placeholder ?? "") |
| 184 | .setValue(starting) |
| 185 | .onChange((v) => setValue(req.id, v)); |
| 186 | break; |
| 187 | } |
| 188 | case "number": { |
| 189 | // |type:number — a numeric input so the one-page form rejects |
| 190 | // non-numeric text like the runtime NumberInputPrompt does. |
| 191 | const setting = new Setting(this.contentEl).setName( |
| 192 | this.decorateLabel(req), |
| 193 | ); |
| 194 | if (req.description) setting.setDesc(req.description); |
| 195 | const input = new TextComponent(setting.controlEl); |
| 196 | input.inputEl.type = "number"; |
| 197 | input.inputEl.inputMode = "decimal"; |
| 198 | if (req.numericConfig?.min !== undefined) { |
| 199 | input.inputEl.min = String(req.numericConfig.min); |
| 200 | } |
| 201 | if (req.numericConfig?.max !== undefined) { |
| 202 | input.inputEl.max = String(req.numericConfig.max); |
| 203 | } |
| 204 | input.inputEl.step = |
| 205 | req.numericConfig?.step !== undefined |
| 206 | ? String(req.numericConfig.step) |
| 207 | : "any"; |
| 208 | const normalizedStarting = req.numericConfig |
| 209 | ? normalizeNumericValue(starting, req.numericConfig) |
| 210 | : starting; |
| 211 | input |
| 212 | .setPlaceholder(req.placeholder ?? "") |
no test coverage detected