mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
26 lines
860 B
TypeScript
26 lines
860 B
TypeScript
import {ImageManager} from "../../components";
|
|
import {$createImageNode} from "../nodes/image";
|
|
import {$createLinkNode, LinkNode} from "@lexical/link";
|
|
|
|
type EditorImageData = {
|
|
url: string;
|
|
thumbs?: {display: string};
|
|
name: string;
|
|
};
|
|
|
|
export function showImageManager(callback: (image: EditorImageData) => any) {
|
|
const imageManager: ImageManager = window.$components.first('image-manager') as ImageManager;
|
|
imageManager.show((image: EditorImageData) => {
|
|
callback(image);
|
|
}, 'gallery');
|
|
}
|
|
|
|
export function $createLinkedImageNodeFromImageData(image: EditorImageData): LinkNode {
|
|
const url = image.thumbs?.display || image.url;
|
|
const linkNode = $createLinkNode(url, {target: '_blank'});
|
|
const imageNode = $createImageNode(url, {
|
|
alt: image.name
|
|
});
|
|
linkNode.append(imageNode);
|
|
return linkNode;
|
|
} |