feat(media): unify uploads onto modules/album, add batched srcset enrichment and Media Library picker

This commit is contained in:
Jakub Zych
2026-11-27 13:26:59 +01:00
parent f61c90a326
commit ccd8dc85aa
14 changed files with 781 additions and 79 deletions

View File

@@ -222,7 +222,7 @@ declare module '@tiptap/core' {
}
figure: {
/** Inserts an image with a caption as figure, img and figcaption. */
setFigure: (attributes: { src: string; alt: string; caption: string }) => ReturnType
setFigure: (attributes: { src: string; alt: string; caption: string; width?: number | string | null; height?: number | string | null }) => ReturnType
}
}
}
@@ -452,9 +452,12 @@ export const Figure = Node.create({
addCommands() {
return {
setFigure:
({ src, alt, caption }) =>
({ src, alt, caption, width, height }) =>
({ commands }) => {
const content: Record<string, unknown>[] = [{ type: 'figureImage', attrs: { src, alt } }]
const imgAttrs: Record<string, unknown> = { src, alt }
if (width != null && width !== '') imgAttrs.width = String(width)
if (height != null && height !== '') imgAttrs.height = String(height)
const content: Record<string, unknown>[] = [{ type: 'figureImage', attrs: imgAttrs }]
if (caption) content.push({ type: 'figcaption', content: [{ type: 'text', text: caption }] })
return commands.insertContent({ type: this.name, content })
},
@@ -572,6 +575,17 @@ export const HeadingOneAsTwo = Node.create({
* the preservation nodes and marks. headingLevels are the offered heading
* levels (J1): without 1, an h1 is parsed as a level 2 heading.
*/
/** Inline image with optional width/height attributes preserved for Media Library picks. */
const SizedImage = Image.extend({
addAttributes() {
return {
...this.parent?.(),
width: { default: null },
height: { default: null },
}
},
})
export function preservationExtensions(labels: Labels = labelsFor('en'), headingLevels: readonly number[] = DEFAULT_HEADING_LEVELS): AnyExtension[] {
const levels = schemaHeadingLevels(headingLevels)
return [
@@ -585,7 +599,7 @@ export function preservationExtensions(labels: Labels = labelsFor('en'), heading
},
}),
...(levels.includes(1) ? [] : [HeadingOneAsTwo]),
Image.configure({ inline: true, allowBase64: false }),
SizedImage.configure({ inline: true, allowBase64: false }),
PlainTable,
TableRow,
PlainTableHeader,