feat: editor heading levels, outline, link rel, generic-anchor warning and image naming

- the blogeditor and mlblogeditor types serve headingLevels and
  genericAnchors through RequestOptions, per schema request
- J1: H2 to H4 with a pasted or loaded H1 parsed as H2 while the H1
  setting is on, H1 to H4 while it is off; H5 and H6 still parse
- J2: the outline bar and panel (skipped, empty, link-only, H1 in Source,
  generic link texts), 300 ms after a change, collapsed, read-only
- J3: nofollow/sponsored/ugc checkboxes for absolute http(s) links only,
  and a non-blocking warning for a generic link text
- J4: one form per picked file with the slugged file name, alt required
  unless decorative (alt=""); Insert uploads the renamed file and the
  image is inserted on the upload result
- assets/dist rebuilt
This commit is contained in:
Jakub Zych
2026-11-04 10:35:19 +01:00
parent 391435b4bf
commit 4b09bd9312
16 changed files with 1482 additions and 170 deletions

View File

@@ -4,7 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { EMBED_PROVIDERS, isEmbedProvider, parseEmbedUrl } from '../../assets/src/blogeditor/embed'
import { isPolicyUrl } from '../../assets/src/blogeditor/extensions'
import { format, labelsFor } from '../../assets/src/blogeditor/labels'
import { button, click, fill, form, mount, status } from './helpers'
import { button, chooseImage, click, fill, form, mount, status } from './helpers'
afterEach(() => {
vi.useRealTimers()
@@ -179,33 +179,36 @@ describe('upload flow', () => {
}
it('ignores an answer with an id it did not send', () => {
const { el, uploads, changes } = mount('<p>a</p>')
const { el, uploads } = mount('<p>a</p>')
pick(el, [png()])
expect(uploads).toHaveLength(0)
chooseImage(el, { alt: 'Grzyb' })
answer(el, { id: 'not-ours', url: '/x.png' })
answer(el, { id: 'not-ours', error: 'nope' })
expect(form(el, 'image')).toBeNull()
expect(status(el)).toBe('Uploading grzyb.png…')
expect(el.value).toBe('<p>a</p>')
answer(el, { id: uploads[0]!.id, url: '/ours.png' })
expect(form(el, 'image')).not.toBeNull()
expect(changes).toEqual([])
expect(el.value).toContain('<img src="/ours.png" alt="Grzyb">')
})
it('times out after 60 seconds and ignores the late answer', () => {
vi.useFakeTimers()
const { el, uploads } = mount('')
pick(el, [png()])
chooseImage(el, { alt: 'Grzyb' })
vi.advanceTimersByTime(59_999)
expect(status(el)).toBe('Uploading grzyb.png…')
vi.advanceTimersByTime(1)
expect(status(el)).toBe('The upload of grzyb.png took too long.')
answer(el, { id: uploads[0]!.id, url: '/late.png' })
expect(form(el, 'image')).toBeNull()
expect(el.value).toBe('')
})
it('answers each of several uploads by its own id', () => {
const { el, uploads } = mount('')
pick(el, [png(), new File([new Uint8Array([255, 216, 255])], 'b.jpg', { type: 'image/jpeg' })])
chooseImage(el, { alt: 'A' })
chooseImage(el, { alt: 'B' })
expect(uploads).toHaveLength(2)
expect(uploads[0]!.id).not.toBe(uploads[1]!.id)
answer(el, { id: uploads[1]!.id, error: 'Too big' })
@@ -215,6 +218,7 @@ describe('upload flow', () => {
it('refuses an uploaded URL outside the policy', () => {
const { el, uploads } = mount('')
pick(el, [png()])
chooseImage(el, { alt: 'Grzyb' })
answer(el, { id: uploads[0]!.id, url: 'javascript:alert(1)' })
expect(form(el, 'image')).toBeNull()
expect(status(el)).toMatch(/^Upload failed/)