mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-07 08:21:08 +00:00
UBERF-7829 Fix embedded image preview (#6279)
This commit is contained in:
parent
36cbccfeb2
commit
3c424b8c31
@ -21,7 +21,7 @@
|
|||||||
import presentation from '../plugin'
|
import presentation from '../plugin'
|
||||||
|
|
||||||
import { BlobMetadata } from '../types'
|
import { BlobMetadata } from '../types'
|
||||||
import { getClient, getFileUrl } from '../utils'
|
import { getFileUrl } from '../utils'
|
||||||
|
|
||||||
import ActionContext from './ActionContext.svelte'
|
import ActionContext from './ActionContext.svelte'
|
||||||
import FilePreview from './FilePreview.svelte'
|
import FilePreview from './FilePreview.svelte'
|
||||||
@ -36,7 +36,6 @@
|
|||||||
export let fullSize = false
|
export let fullSize = false
|
||||||
export let showIcon = true
|
export let showIcon = true
|
||||||
|
|
||||||
const client = getClient()
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let download: HTMLAnchorElement
|
let download: HTMLAnchorElement
|
||||||
|
@ -71,18 +71,6 @@ export const FileNode = Node.create<FileOptions>({
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tag: `div[data-type="${this.name}"]`
|
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]'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,10 @@ export const ImageNode = Node.create<ImageOptions>({
|
|||||||
title: {
|
title: {
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
align: getDataAttribute('align')
|
align: getDataAttribute('align'),
|
||||||
|
'data-file-type': {
|
||||||
|
default: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -120,7 +123,9 @@ export const ImageNode = Node.create<ImageOptions>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(divAttributes)) {
|
for (const [k, v] of Object.entries(divAttributes)) {
|
||||||
container.setAttribute(k, v)
|
if (v !== null) {
|
||||||
|
container.setAttribute(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const imgAttributes = mergeAttributes(
|
const imgAttributes = mergeAttributes(
|
||||||
|
@ -28,9 +28,8 @@ export function getDataAttribute (
|
|||||||
default: null,
|
default: null,
|
||||||
parseHTML: (element) => element.getAttribute(dataName),
|
parseHTML: (element) => element.getAttribute(dataName),
|
||||||
renderHTML: (attributes) => {
|
renderHTML: (attributes) => {
|
||||||
// eslint-disable-next-line
|
if (attributes[name] == null) {
|
||||||
if (!attributes[name]) {
|
return null
|
||||||
return {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -53,15 +53,6 @@ export const FileExtension = FileNode.extend<FileOptions>({
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tag: `div[data-type="${this.name}"]`
|
tag: `div[data-type="${this.name}"]`
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'div[data-file-name]'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'div[data-file-size]'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'div[data-file-type]'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -151,7 +151,7 @@ export const ImageExtension = ImageNode.extend<ImageOptions>({
|
|||||||
|
|
||||||
const fileId = node.attrs['file-id'] ?? node.attrs.src
|
const fileId = node.attrs['file-id'] ?? node.attrs.src
|
||||||
const fileName = node.attrs.alt ?? ''
|
const fileName = node.attrs.alt ?? ''
|
||||||
const fileType = node.attrs['data-file-type'] ?? ''
|
const fileType = node.attrs['data-file-type'] ?? 'image/*'
|
||||||
|
|
||||||
showPopup(
|
showPopup(
|
||||||
FilePreviewPopup,
|
FilePreviewPopup,
|
||||||
@ -211,7 +211,7 @@ export async function openImage (editor: Editor): Promise<void> {
|
|||||||
const attributes = editor.getAttributes('image')
|
const attributes = editor.getAttributes('image')
|
||||||
const fileId = attributes['file-id'] ?? attributes.src
|
const fileId = attributes['file-id'] ?? attributes.src
|
||||||
const fileName = attributes.alt ?? ''
|
const fileName = attributes.alt ?? ''
|
||||||
const fileType = attributes['data-file-type'] ?? ''
|
const fileType = attributes['data-file-type'] ?? 'image/*'
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
showPopup(
|
showPopup(
|
||||||
FilePreviewPopup,
|
FilePreviewPopup,
|
||||||
|
@ -153,7 +153,10 @@ async function handleImageUpload (
|
|||||||
const size = await getImageSize(file)
|
const size = await getImageSize(file)
|
||||||
const node = view.state.schema.nodes.image.create({
|
const node = view.state.schema.nodes.image.create({
|
||||||
'file-id': attached.file,
|
'file-id': attached.file,
|
||||||
|
'data-file-type': file.type,
|
||||||
src: url,
|
src: url,
|
||||||
|
alt: file.name,
|
||||||
|
title: file.name,
|
||||||
width: Math.round(size.width / size.pixelRatio)
|
width: Math.round(size.width / size.pixelRatio)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -755,7 +755,8 @@ A list of closed updated issues`
|
|||||||
align: null,
|
align: null,
|
||||||
height: null,
|
height: null,
|
||||||
title: null,
|
title: null,
|
||||||
'file-id': null
|
'file-id': null,
|
||||||
|
'data-file-type': null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user