Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/slate-react/utils/weak-maps.ts
1698 views
1
import { Node, Ancestor, Editor } from "slate";
2
3
import { Key } from "./key";
4
5
/**
6
* Two weak maps that allow us rebuild a path given a node. They are populated
7
* at render time such that after a render occurs we can always backtrack.
8
*/
9
10
export const NODE_TO_INDEX: WeakMap<Node, number> = new WeakMap();
11
export const NODE_TO_PARENT: WeakMap<Node, Ancestor> = new WeakMap();
12
13
/**
14
* Weak maps that allow us to go between Slate nodes and DOM nodes. These
15
* are used to resolve DOM event-related logic into Slate actions.
16
*/
17
18
export const EDITOR_TO_ELEMENT: WeakMap<Editor, HTMLElement> = new WeakMap();
19
export const EDITOR_TO_PLACEHOLDER: WeakMap<Editor, string> = new WeakMap();
20
export const ELEMENT_TO_NODE: WeakMap<HTMLElement, Node> = new WeakMap();
21
export const KEY_TO_ELEMENT: WeakMap<Key, HTMLElement> = new WeakMap();
22
export const NODE_TO_ELEMENT: WeakMap<Node, HTMLElement> = new WeakMap();
23
export const NODE_TO_KEY: WeakMap<Node, Key> = new WeakMap();
24
25
/**
26
* Weak maps for storing editor-related state.
27
*/
28
29
export const IS_READ_ONLY: WeakMap<Editor, boolean> = new WeakMap();
30
export const IS_FOCUSED: WeakMap<Editor, boolean> = new WeakMap();
31
export const IS_DRAGGING: WeakMap<Editor, boolean> = new WeakMap();
32
export const IS_CLICKING: WeakMap<Editor, boolean> = new WeakMap();
33
34
/**
35
* Weak map for associating the context `onChange` context with the plugin.
36
*/
37
38
export const EDITOR_TO_ON_CHANGE = new WeakMap<Editor, () => void>();
39
40
/**
41
* Symbols.
42
*/
43
44
export const PLACEHOLDER_SYMBOL = (Symbol("placeholder") as unknown) as string;
45
46