UBERF-7829 Fix embedded image preview (#6279)

This commit is contained in:
Alexander Onnikov 2024-08-07 20:21:40 +07:00 committed by GitHub
parent 36cbccfeb2
commit 3c424b8c31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 31 deletions

View File

@ -21,7 +21,7 @@
import presentation from '../plugin'
import { BlobMetadata } from '../types'
import { getClient, getFileUrl } from '../utils'
import { getFileUrl } from '../utils'
import ActionContext from './ActionContext.svelte'
import FilePreview from './FilePreview.svelte'
@ -36,7 +36,6 @@
export let fullSize = false
export let showIcon = true
const client = getClient()
const dispatch = createEventDispatcher()
let download: HTMLAnchorElement

View File

@ -71,18 +71,6 @@ export const FileNode = Node.create<FileOptions>({
return [
{
tag: `div[data-type="${this.name}"]`
},
{
tag: 'div[data-file-name]'
},
{
tag: 'div[data-file-size]'
},
{
tag: 'div[data-file-type]'
},
{
tag: 'div[data-file-href]'
}
]
},

View File

@ -73,7 +73,10 @@ export const ImageNode = Node.create<ImageOptions>({
title: {
default: null
},
align: getDataAttribute('align')
align: getDataAttribute('align'),
'data-file-type': {
default: null
}
}
},
@ -120,8 +123,10 @@ export const ImageNode = Node.create<ImageOptions>({
}
for (const [k, v] of Object.entries(divAttributes)) {
if (v !== null) {
container.setAttribute(k, v)
}
}
const imgAttributes = mergeAttributes(
{

View File

@ -28,9 +28,8 @@ export function getDataAttribute (
default: null,
parseHTML: (element) => element.getAttribute(dataName),
renderHTML: (attributes) => {
// eslint-disable-next-line
if (!attributes[name]) {
return {}
if (attributes[name] == null) {
return null
}
return {

View File

@ -53,15 +53,6 @@ export const FileExtension = FileNode.extend<FileOptions>({
return [
{
tag: `div[data-type="${this.name}"]`
},
{
tag: 'div[data-file-name]'
},
{
tag: 'div[data-file-size]'
},
{
tag: 'div[data-file-type]'
}
]
},

View File

@ -151,7 +151,7 @@ export const ImageExtension = ImageNode.extend<ImageOptions>({
const fileId = node.attrs['file-id'] ?? node.attrs.src
const fileName = node.attrs.alt ?? ''
const fileType = node.attrs['data-file-type'] ?? ''
const fileType = node.attrs['data-file-type'] ?? 'image/*'
showPopup(
FilePreviewPopup,
@ -211,7 +211,7 @@ export async function openImage (editor: Editor): Promise<void> {
const attributes = editor.getAttributes('image')
const fileId = attributes['file-id'] ?? attributes.src
const fileName = attributes.alt ?? ''
const fileType = attributes['data-file-type'] ?? ''
const fileType = attributes['data-file-type'] ?? 'image/*'
await new Promise<void>((resolve) => {
showPopup(
FilePreviewPopup,

View File

@ -153,7 +153,10 @@ async function handleImageUpload (
const size = await getImageSize(file)
const node = view.state.schema.nodes.image.create({
'file-id': attached.file,
'data-file-type': file.type,
src: url,
alt: file.name,
title: file.name,
width: Math.round(size.width / size.pixelRatio)
})

View File

@ -755,7 +755,8 @@ A list of closed updated issues`
align: null,
height: null,
title: null,
'file-id': null
'file-id': null,
'data-file-type': null
}
}
]