Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 30x 30x 30x 30x 30x 1x 1x 30x 13x 13x 30x 30x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 29x 29x 29x 29x 29x 29x 29x 29x 1x 1x 29x 29x 1x 1x 29x 29x 29x 7x 7x 7x 7x 18x 18x 7x 7x 7x 7x 2x 5x 7x 7x 29x 29x 17x 17x 17x 29x 29x 29x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { esc } from "./markdown-to-html.js" import { deliveryFormFields, formatDependsOn, parseDependsOn, type DeliveryFormPayload, selectOptionsForField, } from "./delivery-form-schema.js" import type { DeliveryFolder } from "./delivery-path.js" export type DeliveryFormViewModel = { relativePath: string entityLabel: string folder: DeliveryFolder form: DeliveryFormPayload saveError?: string saveOk?: boolean showAdvanced?: boolean rawMarkdown?: string } function fieldValue( model: DeliveryFormViewModel, field: ReturnType<typeof deliveryFormFields>[number], ): string { if (field.scope === "preamble") { return model.form.preamble } if (field.scope === "frontmatter") { return model.form.frontmatter[field.key] ?? "" } return model.form.sections[field.key] ?? "" } function catalogLabel( model: DeliveryFormViewModel, field: ReturnType<typeof deliveryFormFields>[number], id: string, ): string { if (!field.catalogKey || !model.form.catalog) { return id } const entry = model.form.catalog[field.catalogKey]?.find((item) => item.id === id) if (!entry) return id const status = entry.status ? ` · ${entry.status}` : "" if (field.catalogKey === "sprints" && entry.version) { return `${entry.id} — ${entry.version}${status}` } return `${entry.id} — ${entry.title}${status}` } function renderMultiselect( model: DeliveryFormViewModel, field: ReturnType<typeof deliveryFormFields>[number], ): string { const selected = new Set(parseDependsOn(fieldValue(model, field))) const options = selectOptionsForField(model.folder, field, model.form.catalog) ?? [] const id = `field-${field.scope}-${field.key}` if (!options.length) { return `<div class="field"><label>${esc(field.label)}</label><p class="hint">No stories in database yet.</p><input type="hidden" id="${id}" data-scope="${field.scope}" data-key="${esc(field.key)}" data-multiselect="true" value="${esc(fieldValue(model, field))}" /></div>` } const items = options .map((opt) => { const checked = selected.has(opt) ? " checked" : "" return `<label class="check-item"><input type="checkbox" data-multiselect-parent="${id}" value="${esc(opt)}"${checked} /><span>${esc(catalogLabel(model, field, opt))}</span></label>` }) .join("") return `<div class="field multiselect"><label>${esc(field.label)}</label><div class="check-list" id="${id}" data-scope="${field.scope}" data-key="${esc(field.key)}" data-multiselect="true">${items}</div><p class="hint">Select prerequisite user stories (PK). /implement-us blocks until each is ✅.</p></div>` } function renderField( model: DeliveryFormViewModel, field: ReturnType<typeof deliveryFormFields>[number], ): string { const value = fieldValue(model, field) const id = `field-${field.scope}-${field.key}` if (field.kind === "readonly") { return `<div class="field readonly"><label>${esc(field.label)}</label><div class="readonly-value">${esc(value)}</div></div>` } if (field.kind === "multiselect") { return renderMultiselect(model, field) } const options = selectOptionsForField(model.folder, field, model.form.catalog) if (options) { let list = options if (model.folder === "us" && field.key === "sprint" && model.form.catalog?.sprints?.length) { const version = model.form.frontmatter.version if (version) { const allowed = new Set( model.form.catalog.sprints .filter((s) => !s.version || s.version === version) .map((s) => s.id), ) list = options.filter((opt) => allowed.has(opt)) } } const opts = list .map((opt) => { const label = field.catalogKey ? catalogLabel(model, field, opt) : opt return `<option value="${esc(opt)}"${opt === value ? " selected" : ""}>${esc(label)}</option>` }) .join("") const empty = field.catalogKey && !value ? `<option value="" selected>— select —</option>` : "" return `<div class="field"><label for="${id}">${esc(field.label)}</label><select id="${id}" data-scope="${field.scope}" data-key="${esc(field.key)}">${empty}${opts}</select></div>` } if (field.kind === "textarea") { const rows = field.rows ?? 4 return `<div class="field"><label for="${id}">${esc(field.label)}</label><textarea id="${id}" data-scope="${field.scope}" data-key="${esc(field.key)}" rows="${rows}" spellcheck="false">${esc(value)}</textarea></div>` } return `<div class="field"><label for="${id}">${esc(field.label)}</label><input id="${id}" type="text" data-scope="${field.scope}" data-key="${esc(field.key)}" value="${esc(value)}" /></div>` } export function buildDeliveryFormHtml(model: DeliveryFormViewModel): string { const fields = deliveryFormFields(model.folder) const groups = [...new Set(fields.map((f) => f.group))] const groupHtml = groups .map((group) => { const groupFields = fields.filter((f) => f.group === group) const inner = groupFields.map((f) => renderField(model, f)).join("") return `<section class="form-group"><h2 class="form-group-title">${esc(group)}</h2>${inner}</section>` }) .join("") const statusMsg = model.saveError ? `<p class="banner error">${esc(model.saveError)}</p>` : model.saveOk ? `<p class="banner ok">Saved to SQLite.</p>` : "" const advancedBlock = model.showAdvanced ? `<section class="form-group advanced"><h2 class="form-group-title">Advanced markdown</h2> <p class="edit-hint">Raw markdown bypasses the form. Prefer Save form unless you know the template.</p> <textarea id="rawEditor" class="editor" spellcheck="false">${esc(model.rawMarkdown ?? "")}</textarea> <div class="toolbar-actions inner"><button type="button" class="btn primary" id="saveRawBtn">Save raw</button></div> </section>` : "" const title = model.form.frontmatter.title || model.form.frontmatter.id || model.relativePath return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline';" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> * { box-sizing: border-box; } body { margin: 0; font-family: var(--vscode-font-family); font-size: calc(var(--vscode-font-size) * 1.02); color: var(--vscode-foreground); background: var(--vscode-editor-background); min-height: 100vh; display: flex; flex-direction: column; } .toolbar { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--vscode-panel-border); background: var(--vscode-sideBar-background); } .toolbar-title { flex: 1 1 180px; min-width: 0; font-weight: 600; font-size: 0.95em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .toolbar-actions { display: flex; flex-wrap: wrap; gap: 6px; } .toolbar-actions.inner { margin-top: 10px; } .btn { font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 4px; border: 1px solid var(--vscode-button-border, transparent); background: var(--vscode-button-secondaryBackground); color: var(--vscode-button-secondaryForeground); cursor: pointer; } .btn:hover { background: var(--vscode-button-secondaryHoverBackground); } .btn.primary { background: var(--vscode-button-background); color: var(--vscode-button-foreground); } .btn.primary:hover { background: var(--vscode-button-hoverBackground); } .main { flex: 1; padding: 16px 18px 28px; max-width: 920px; width: 100%; margin: 0 auto; } .entity-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--vscode-descriptionForeground); margin-bottom: 12px; } .source { font-size: 11px; color: var(--vscode-descriptionForeground); margin-bottom: 16px; word-break: break-all; } .form-group { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--vscode-panel-border); } .form-group-title { margin: 0 0 12px; font-size: 1em; font-weight: 600; } .field { margin-bottom: 12px; } .field label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--vscode-descriptionForeground); margin-bottom: 4px; } .field input, .field select, .field textarea { width: 100%; font: inherit; font-size: 0.95em; color: var(--vscode-input-foreground); background: var(--vscode-input-background); border: 1px solid var(--vscode-input-border, var(--vscode-panel-border)); border-radius: 6px; padding: 8px 10px; } .field textarea { min-height: 72px; resize: vertical; font-family: var(--vscode-editor-font-family, monospace); line-height: 1.45; } .readonly-value { padding: 8px 10px; border-radius: 6px; background: var(--vscode-input-background); border: 1px solid var(--vscode-panel-border); font-family: var(--vscode-editor-font-family, monospace); } .check-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--vscode-input-border, var(--vscode-panel-border)); background: var(--vscode-input-background); } .check-item { display: flex; align-items: flex-start; gap: 8px; font-size: 0.92em; line-height: 1.35; cursor: pointer; } .check-item input { width: auto; margin-top: 3px; flex-shrink: 0; } .hint, .edit-hint { margin: 4px 0 0; font-size: 11px; color: var(--vscode-descriptionForeground); } .banner { margin: 0 0 12px; padding: 8px 10px; border-radius: 6px; font-size: 12px; } .banner.error { background: color-mix(in srgb, var(--vscode-errorForeground) 12%, transparent); color: var(--vscode-errorForeground); border: 1px solid color-mix(in srgb, var(--vscode-errorForeground) 35%, transparent); } .banner.ok { border: 1px solid var(--vscode-panel-border); } .editor { width: 100%; min-height: 50vh; resize: vertical; font-family: var(--vscode-editor-font-family, monospace); font-size: calc(var(--vscode-editor-font-size, 13px) * 0.95); line-height: 1.45; color: var(--vscode-editor-foreground); background: var(--vscode-editor-background); border: 1px solid var(--vscode-panel-border); border-radius: 8px; padding: 12px 14px; } </style> </head> <body> <header class="toolbar"> <div class="toolbar-title">${esc(title)}</div> <div class="toolbar-actions"> <button type="button" class="btn" id="viewBtn">View</button> <button type="button" class="btn primary" id="saveFormBtn">Save</button> <button type="button" class="btn" id="advancedBtn">${model.showAdvanced ? "Hide advanced" : "Advanced"}</button> </div> </header> <main class="main"> <div class="entity-label">${esc(model.entityLabel)} · structured form</div> <div class="source">SQLite · ${esc(model.relativePath)}</div> ${statusMsg} <form id="deliveryForm" autocomplete="off">${groupHtml}</form> ${advancedBlock} </main> <script> const vscode = acquireVsCodeApi(); function formatDependsOn(ids) { if (!ids.length) return "[]"; return "[" + ids.join(", ") + "]"; } function readFieldValue(el) { if (el.dataset.multiselect === "true") { const parentId = el.id; const boxes = document.querySelectorAll('[data-multiselect-parent="' + parentId + '"]'); const ids = []; boxes.forEach((box) => { if (box.checked) ids.push(box.value); }); return formatDependsOn(ids); } return el.value ?? ""; } document.getElementById("viewBtn").onclick = () => vscode.postMessage({ type: "view" }); document.getElementById("saveFormBtn").onclick = () => { const payload = { frontmatter: {}, preamble: "", sections: {} }; document.querySelectorAll("[data-scope][data-key]").forEach((el) => { const scope = el.getAttribute("data-scope"); const key = el.getAttribute("data-key"); const value = readFieldValue(el); if (scope === "frontmatter") payload.frontmatter[key] = value; else if (scope === "sections") payload.sections[key] = value; else if (scope === "preamble") payload.preamble = value; }); vscode.postMessage({ type: "saveForm", payload }); }; const advancedBtn = document.getElementById("advancedBtn"); if (advancedBtn) { advancedBtn.onclick = () => vscode.postMessage({ type: "toggleAdvanced" }); } const saveRawBtn = document.getElementById("saveRawBtn"); const rawEditor = document.getElementById("rawEditor"); if (saveRawBtn && rawEditor) { saveRawBtn.onclick = () => vscode.postMessage({ type: "saveRaw", markdown: rawEditor.value }); } </script> </body> </html>` } // Re-export for tests export { formatDependsOn, parseDependsOn } |