forked from codex-team/editor.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-selection.ts
More file actions
49 lines (42 loc) · 1.29 KB
/
api-selection.ts
File metadata and controls
49 lines (42 loc) · 1.29 KB
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
46
47
48
49
declare var Module: any;
import {ISelectionAPI} from '../interfaces/api';
import IModuleConfig from '../interfaces/module-config';
import Selection from '../selection';
/**
* @class API
* Provides with methods working with Selection
*/
export default class SelectionAPI extends Module implements ISelectionAPI {
/**
* Save Editor config. API provides passed configuration to the Blocks
*/
constructor({config}: IModuleConfig) {
super({config});
}
/**
* Available methods
* @return {ISelectionAPI}
*/
get methods(): ISelectionAPI {
return {
findParentTag: (tagName: string, className: string) => this.findParentTag(tagName, className),
expandToTag: (node: HTMLElement) => 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
* @return {HTMLElement|null}
*/
public findParentTag(tagName: string, className: string): HTMLElement|null {
return new Selection().findParentTag(tagName, className);
}
/**
* Expand selection to passed tag
* @param {HTMLElement} node - tag that should contain selection
*/
public expandToTag(node: HTMLElement): void {
new Selection().expandToTag(node);
}
}