Path: blob/master/src/packages/frontend/editors/slate/slate-react/utils/weak-maps.ts
1698 views
import { Node, Ancestor, Editor } from "slate";12import { Key } from "./key";34/**5* Two weak maps that allow us rebuild a path given a node. They are populated6* at render time such that after a render occurs we can always backtrack.7*/89export const NODE_TO_INDEX: WeakMap<Node, number> = new WeakMap();10export const NODE_TO_PARENT: WeakMap<Node, Ancestor> = new WeakMap();1112/**13* Weak maps that allow us to go between Slate nodes and DOM nodes. These14* are used to resolve DOM event-related logic into Slate actions.15*/1617export const EDITOR_TO_ELEMENT: WeakMap<Editor, HTMLElement> = new WeakMap();18export const EDITOR_TO_PLACEHOLDER: WeakMap<Editor, string> = new WeakMap();19export const ELEMENT_TO_NODE: WeakMap<HTMLElement, Node> = new WeakMap();20export const KEY_TO_ELEMENT: WeakMap<Key, HTMLElement> = new WeakMap();21export const NODE_TO_ELEMENT: WeakMap<Node, HTMLElement> = new WeakMap();22export const NODE_TO_KEY: WeakMap<Node, Key> = new WeakMap();2324/**25* Weak maps for storing editor-related state.26*/2728export const IS_READ_ONLY: WeakMap<Editor, boolean> = new WeakMap();29export const IS_FOCUSED: WeakMap<Editor, boolean> = new WeakMap();30export const IS_DRAGGING: WeakMap<Editor, boolean> = new WeakMap();31export const IS_CLICKING: WeakMap<Editor, boolean> = new WeakMap();3233/**34* Weak map for associating the context `onChange` context with the plugin.35*/3637export const EDITOR_TO_ON_CHANGE = new WeakMap<Editor, () => void>();3839/**40* Symbols.41*/4243export const PLACEHOLDER_SYMBOL = (Symbol("placeholder") as unknown) as string;444546