Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/slate-react/components/dom-utils.ts
1698 views
1
/* Some utility functions factored out of editable.tsx */
2
3
import { ReactEditor } from "..";
4
import { Editor, Element } from "slate";
5
6
import { DOMNode, isDOMNode } from "../utils/dom";
7
8
/**
9
* Check if the target is inside void and in the editor.
10
*/
11
12
export const isTargetInsideVoid = (
13
editor: ReactEditor,
14
target: EventTarget | null
15
): boolean => {
16
const slateNode =
17
hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
18
return Element.isElement(slateNode) && Editor.isVoid(editor, slateNode);
19
};
20
21
/**
22
* Check if the target is editable and in the editor.
23
*/
24
25
export const hasEditableTarget = (
26
editor: ReactEditor,
27
target: EventTarget | null
28
): target is DOMNode => {
29
return (
30
isDOMNode(target) &&
31
ReactEditor.hasDOMNode(editor, target, { editable: true })
32
);
33
};
34
35
/**
36
* Check if the target is in the editor.
37
*/
38
39
export const hasTarget = (
40
editor: ReactEditor,
41
target: EventTarget | null
42
): target is DOMNode => {
43
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
44
};
45
46