mirror of
https://github.com/codex-team/editor.js
synced 2024-05-07 00:46:45 +02:00
63eeec0f3b
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com> Co-authored-by: tasuku-s <tasuku@freemind.co.jp> Co-authored-by: Athul Anil Kumar <athul7744@outlook.com> Co-authored-by: Taly <vitalik7tv@yandex.ru> Co-authored-by: flaming-cl <51183663+flaming-cl@users.noreply.github.com> Co-authored-by: Nguyen Ngoc Son <sonnn.se@gmail.com> Co-authored-by: Sisir Das K <37764463+sis-dk@users.noreply.github.com> Co-authored-by: Sisir <sisir@hellosivi.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import Module from '../../__module';
|
|
import SelectionUtils from '../../selection';
|
|
import { Selection as SelectionAPIInterface } from '../../../../types/api';
|
|
|
|
/**
|
|
* @class SelectionAPI
|
|
* Provides with methods working with SelectionUtils
|
|
*/
|
|
export default class SelectionAPI extends Module {
|
|
/**
|
|
* Available methods
|
|
*
|
|
* @returns {SelectionAPIInterface}
|
|
*/
|
|
public get methods(): SelectionAPIInterface {
|
|
return {
|
|
findParentTag: (tagName: string, className?: string): HTMLElement | null => this.findParentTag(tagName, className),
|
|
expandToTag: (node: HTMLElement): void => this.expandToTag(node),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Looks ahead from selection and find passed tag with class name
|
|
*
|
|
* @param {string} tagName - tag to find
|
|
* @param {string} className - tag's class name
|
|
*
|
|
* @returns {HTMLElement|null}
|
|
*/
|
|
public findParentTag(tagName: string, className?: string): HTMLElement | null {
|
|
return new SelectionUtils().findParentTag(tagName, className);
|
|
}
|
|
|
|
/**
|
|
* Expand selection to passed tag
|
|
*
|
|
* @param {HTMLElement} node - tag that should contain selection
|
|
*/
|
|
public expandToTag(node: HTMLElement): void {
|
|
new SelectionUtils().expandToTag(node);
|
|
}
|
|
}
|