2020-10-12 23:03:00 +02:00
|
|
|
import Module from '../../__module';
|
2018-11-23 17:11:50 +01:00
|
|
|
import SelectionUtils from '../../selection';
|
2020-06-03 10:17:29 +02:00
|
|
|
import { Selection as SelectionAPIInterface } from '../../../../types/api';
|
2018-11-23 17:11:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class SelectionAPI
|
|
|
|
* Provides with methods working with SelectionUtils
|
|
|
|
*/
|
|
|
|
export default class SelectionAPI extends Module {
|
|
|
|
/**
|
|
|
|
* Available methods
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
|
|
|
* @returns {SelectionAPIInterface}
|
2018-11-23 17:11:50 +01:00
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public get methods(): SelectionAPIInterface {
|
2018-11-23 17:11:50 +01:00
|
|
|
return {
|
2020-06-03 10:17:29 +02:00
|
|
|
findParentTag: (tagName: string, className?: string): HTMLElement | null => this.findParentTag(tagName, className),
|
|
|
|
expandToTag: (node: HTMLElement): void => this.expandToTag(node),
|
2018-11-23 17:11:50 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks ahead from selection and find passed tag with class name
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2018-11-23 17:11:50 +01:00
|
|
|
* @param {string} tagName - tag to find
|
|
|
|
* @param {string} className - tag's class name
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
|
|
|
* @returns {HTMLElement|null}
|
2018-11-23 17:11:50 +01:00
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public findParentTag(tagName: string, className?: string): HTMLElement | null {
|
2018-11-23 17:11:50 +01:00
|
|
|
return new SelectionUtils().findParentTag(tagName, className);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expand selection to passed tag
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2018-11-23 17:11:50 +01:00
|
|
|
* @param {HTMLElement} node - tag that should contain selection
|
|
|
|
*/
|
|
|
|
public expandToTag(node: HTMLElement): void {
|
|
|
|
new SelectionUtils().expandToTag(node);
|
|
|
|
}
|
|
|
|
}
|