-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
getselectedimageeditornodes.ts
45 lines (37 loc) · 1.2 KB
/
getselectedimageeditornodes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module image/imageresize/utils/getselectedimageeditornodes
*/
import type { ViewElement, Element } from 'ckeditor5/src/engine.js';
import type { Editor } from 'ckeditor5/src/core.js';
/**
* Finds model, view and DOM element for selected image element. Returns `null` if there is no image selected.
*
* @param editor Editor instance.
*/
export function getSelectedImageEditorNodes( editor: Editor ): ImageEditorNodes | null {
const { editing } = editor;
const imageUtils = editor.plugins.get( 'ImageUtils' );
const imageModelElement = imageUtils.getClosestSelectedImageElement( editor.model.document.selection );
if ( !imageModelElement ) {
return null;
}
const imageViewElement = editing.mapper.toViewElement( imageModelElement )!;
const imageDOMElement = editing.view.domConverter.mapViewToDom( imageViewElement )!;
return {
model: imageModelElement,
view: imageViewElement,
dom: imageDOMElement
};
}
/**
* @internal;
*/
type ImageEditorNodes = {
model: Element;
view: ViewElement;
dom: HTMLElement;
};