/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
apps/vscode/editor/src/utils/externalUrlContentHandler.ts
25 строк
1 KB
Mitja Bezenšek
[VSCode] Allow users to drag files from the sidebar. (#5956)
06 май 2025, 14:12
Не верифицирован
06 май 2025, 14:12
996d0ad
Код
Авторство
О чём код?
import { Editor } from 'tldraw' import { rpc } from './rpc' export function registerExternalUrlContentHandler(editor: Editor) { const currentFilesContentHandler = editor.externalContentHandlers['files'] const currentUrlContentHandler = editor.externalContentHandlers['url'] editor.registerExternalContentHandler('url', async (info) => { // This happens when you shift drag a file from the file explorer to the editor if (info.url.startsWith('file://')) { // We cannot fetch the file directly since we are sandboxed, we have to ask the extension manager to get it for us const data = await rpc('vscode:get-file', { url: info.url }) const uint8Array = new Uint8Array(data.file) const blob = new Blob([uint8Array], { type: data.mimeType }) const file = new File([blob], data.fileName, { type: data.mimeType }) currentFilesContentHandler?.({ type: 'files', files: [file], ignoreParent: false, }) } else { // default logic if it's a regular url currentUrlContentHandler?.(info) } }) }