UBERF-8477 Allow to download image from text editor (#6929)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-10-15 15:36:27 +07:00 committed by GitHub
parent 49836dd0cf
commit a337bb128c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 42 additions and 1 deletions

View File

@ -331,6 +331,15 @@ export function createModel (builder: Builder): void {
index: 10
})
builder.createDoc(textEditor.class.TextEditorAction, core.space.Model, {
kind: 'image',
action: textEditor.function.DownloadImage,
icon: textEditor.icon.Download,
label: textEditor.string.Download,
category: 90,
index: 15
})
builder.createDoc(textEditor.class.TextEditorAction, core.space.Model, {
kind: 'image',
action: textEditor.function.MoreImageActions,

View File

@ -29,6 +29,7 @@ export default mergeIds(textEditorId, textEditor, {
ExpandImage: '' as Resource<TextActionFunction>,
MoreImageActions: '' as Resource<TextActionFunction>,
ConfigureNote: '' as Resource<TextActionFunction>,
DownloadImage: '' as Resource<TextActionFunction>,
IsEditableTableActive: '' as Resource<TextActionVisibleFunction>,
IsEditableNote: '' as Resource<TextActionVisibleFunction>,

View File

@ -183,6 +183,14 @@
d="M18.2927 19.7071C17.9022 19.3166 17.9022 18.6834 18.2927 18.2929C18.6833 17.9024 19.3164 17.9024 19.707 18.2929L26 24.586V20H28V28H20V26H24.586L18.2927 19.7071Z"
/>
</symbol>
<symbol id="download" viewBox="0 0 24 24">
<path
d="M18.7,9.6C18.5,6,15.6,3.2,12,3.2C8.4,3.2,5.5,6,5.3,9.5c-2.3,0.7-4,2.9-4,5.5c0,3.2,2.6,5.8,5.8,5.8 c0.5,0,1.1-0.1,1.6-0.2C9,20.4,9.2,20,9.1,19.6S8.6,19,8.2,19.1c-0.4,0.1-0.8,0.2-1.2,0.2c-2.3,0-4.2-1.9-4.2-4.2 c0-2,1.4-3.7,3.3-4.1c0.2,0,0.3-0.1,0.4-0.2c0.2-0.1,0.4-0.4,0.4-0.6c0-2.9,2.4-5.2,5.2-5.2s5.2,2.4,5.2,5.2c0,0.1,0,0.1,0,0.2 c0,0.3,0.2,0.6,0.6,0.7c1.9,0.4,3.3,2.1,3.3,4.1c0,2.3-1.9,4.2-4.2,4.2c-0.4,0-0.8-0.1-1.2-0.2c-0.4-0.1-0.8,0.1-0.9,0.5 c-0.1,0.4,0.1,0.8,0.5,0.9c0.5,0.1,1,0.2,1.6,0.2c3.2,0,5.8-2.6,5.8-5.8C22.6,12.5,21,10.4,18.7,9.6z"
/>
<path
d="M16.1,14.5c-0.3-0.3-0.8-0.3-1.1,0l-2.3,2.3V10c0-0.4-0.3-0.8-0.8-0.8s-0.8,0.3-0.8,0.8v6.7l-2.2-2.2 c-0.3-0.3-0.8-0.3-1.1,0c-0.3,0.3-0.3,0.8,0,1.1l3.5,3.5c0.3,0.3,0.8,0.3,1.1,0l3.6-3.5C16.4,15.2,16.4,14.8,16.1,14.5z"
/>
</symbol>
<symbol id="note" viewBox="0 0 256 256">
<rect width="256" height="256" fill="none"></rect><line x1="96" x2="160" y1="96" y2="96" fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="8"></line><line x1="96" x2="160" y1="128" y2="128" fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="8"></line><line x1="96" x2="128" y1="160" y2="160" fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="8"></line><path fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="8" d="M156.68629,216H48a8,8,0,0,1-8-8V48a8,8,0,0,1,8-8H208a8,8,0,0,1,8,8V156.68629a8,8,0,0,1-2.34315,5.65686l-51.3137,51.3137A8,8,0,0,1,156.68629,216Z"></path><polyline fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="8" points="215.277 159.992 160 159.992 160 215.272"></polyline>
</symbol>

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -32,6 +32,7 @@
"AlignCenter": "Align center",
"AlignLeft": "Align left",
"AlignRight": "Align right",
"Download": "Download",
"ViewImage": "View image",
"ViewOriginal": "View original",
"MoreActions": "More actions",

View File

@ -32,6 +32,7 @@
"AlignCenter": "Alinear centro",
"AlignLeft": "Alinear izquierda",
"AlignRight": "Alinear derecha",
"Download": "Descargar",
"ViewImage": "Ver imagen",
"ViewOriginal": "Ver original",
"MoreActions": "Más acciones",

View File

@ -32,6 +32,7 @@
"AlignCenter": "Aligner au centre",
"AlignLeft": "Aligner à gauche",
"AlignRight": "Aligner à droite",
"Download": "Télécharger",
"ViewImage": "Voir l'image",
"ViewOriginal": "Voir l'original",
"MoreActions": "Plus d'actions",

View File

@ -32,6 +32,7 @@
"AlignCenter": "Alinhar centro",
"AlignLeft": "Alinhar esquerda",
"AlignRight": "Alinhar direita",
"Download": "Transferir",
"ViewImage": "Ver imagem",
"ViewOriginal": "Ver original",
"MoreActions": "Mais ações",

View File

@ -32,6 +32,7 @@
"AlignCenter": "По центру",
"AlignLeft": "По левому краю",
"AlignRight": "По правому краю",
"Download": "Скачать",
"ViewImage": "Открыть изображение",
"ViewOriginal": "Открыть оригинал",
"MoreActions": "Дополнительные действия",

View File

@ -32,6 +32,7 @@
"AlignCenter": "居中对齐",
"AlignLeft": "左对齐",
"AlignRight": "右对齐",
"Download": "下载",
"ViewImage": "查看图片",
"ViewOriginal": "查看原图",
"MoreActions": "更多操作",

View File

@ -38,5 +38,6 @@ loadMetadata(textEditor.icon, {
MoreH: `${icons}#moreH`,
Expand: `${icons}#expand`,
ScaleOut: `${icons}#scaleOut`,
Download: `${icons}#download`,
Note: `${icons}#note`
})

View File

@ -233,6 +233,19 @@ export async function openImage (editor: Editor): Promise<void> {
})
}
export async function downloadImage (editor: Editor): Promise<void> {
const attributes = editor.getAttributes('image')
const fileId = attributes['file-id'] ?? attributes.src
const href = getFileUrl(fileId)
const link = document.createElement('a')
link.style.display = 'none'
link.target = '_blank'
link.href = href
link.download = attributes.title ?? attributes.alt ?? ''
link.click()
}
export async function expandImage (editor: Editor): Promise<void> {
const attributes = editor.getAttributes('image')
const fileId = attributes['file-id'] ?? attributes.src

View File

@ -18,7 +18,7 @@ import { type Resources } from '@hcengineering/platform'
import { formatLink } from './kits/default-kit'
import { isEditable, isHeadingVisible } from './kits/editor-kit'
import { openTableOptions, isEditableTableActive } from './components/extension/table/table'
import { openImage, expandImage, moreImageActions } from './components/extension/imageExt'
import { openImage, downloadImage, expandImage, moreImageActions } from './components/extension/imageExt'
import { configureNote, isEditableNote } from './components/extension/note'
export * from '@hcengineering/presentation/src/types'
@ -82,6 +82,7 @@ export default async (): Promise<Resources> => ({
OpenTableOptions: openTableOptions,
OpenImage: openImage,
ExpandImage: expandImage,
DownloadImage: downloadImage,
MoreImageActions: moreImageActions,
ConfigureNote: configureNote,
IsEditableTableActive: isEditableTableActive,

View File

@ -72,6 +72,7 @@ export default plugin(textEditorId, {
AlignRight: '' as IntlString,
ViewImage: '' as IntlString,
ViewOriginal: '' as IntlString,
Download: '' as IntlString,
MoreActions: '' as IntlString,
InsertTable: '' as IntlString,
@ -115,6 +116,7 @@ export default plugin(textEditorId, {
MoreH: '' as Asset,
Expand: '' as Asset,
ScaleOut: '' as Asset,
Download: '' as Asset,
Note: '' as Asset
}
})