feat(admin): colour picker, mail image field and the image picker with insert

- insertImage escapes markdown/html/css/text snippets per UI-SPEC C4
- MailImagePicker with canUpload-gated upload, radiogroup tiles, insert/choose modes
- ColorPickerField, MailImageField, markdown/codeeditor Insert image wiring

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:34:54 +01:00
parent 48e87b7543
commit 68e1d36fd5
8 changed files with 734 additions and 35 deletions

View File

@@ -1,7 +1,34 @@
// Stub for TDD RED (35-03 Task 5): real escaping lands in GREEN.
// Pure snippet builder for mail image insertion (UI-SPEC C4, D-19/D-20).
// The SPA never builds image URLs; callers pass the absolute URL the server returned.
export type InsertImageLanguage = 'markdown' | 'html' | 'css' | 'text'
/** Builds the snippet inserted into a mail body or code editor. */
export function insertImage(_language: InsertImageLanguage, _url: string, _alt: string): string {
return ''
function escapeMarkdownAlt(alt: string): string {
return alt.replace(/\\/g, '\\\\').replace(/\[/g, '\\[').replace(/\]/g, '\\]')
}
/** Percent-encode spaces and parentheses in Markdown URLs (research Pitfall 4). */
function encodeMarkdownUrl(url: string): string {
return url.replace(/[ ()]/g, (ch) => encodeURIComponent(ch))
}
function escapeHtmlAttr(value: string): string {
return value
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
}
/** Builds the snippet inserted into a mail body or code editor. */
export function insertImage(language: InsertImageLanguage, url: string, alt: string): string {
switch (language) {
case 'markdown':
return `![${escapeMarkdownAlt(alt)}](${encodeMarkdownUrl(url)})`
case 'html':
return `<img src="${escapeHtmlAttr(url)}" alt="${escapeHtmlAttr(alt)}">`
case 'css':
return `url("${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}")`
case 'text':
return url
}
}