import { Ancestor, Editor, Node, Operation, Point, Range, RangeRef, Text, } from 'slate' import { TextDiff } from './diff-text' import { Key } from './key' export type Action = { at?: Point | Range; run: () => void } /** * Two weak maps that allow us rebuild a path given a node. They are populated * at render time such that after a render occurs we can always backtrack. */ export const IS_NODE_MAP_DIRTY: WeakMap = new WeakMap() export const NODE_TO_INDEX: WeakMap = new WeakMap() export const NODE_TO_PARENT: WeakMap = new WeakMap() /** * Weak maps that allow us to go between Slate nodes and DOM nodes. These * are used to resolve DOM event-related logic into Slate actions. */ export const EDITOR_TO_WINDOW: WeakMap = new WeakMap() export const EDITOR_TO_ELEMENT: WeakMap = new WeakMap() export const EDITOR_TO_PLACEHOLDER: WeakMap = new WeakMap() export const EDITOR_TO_PLACEHOLDER_ELEMENT: WeakMap = new WeakMap() export const ELEMENT_TO_NODE: WeakMap = new WeakMap() export const NODE_TO_ELEMENT: WeakMap = new WeakMap() export const NODE_TO_KEY: WeakMap = new WeakMap() export const EDITOR_TO_KEY_TO_ELEMENT: WeakMap< Editor, WeakMap > = new WeakMap() /** * Weak maps for storing editor-related state. */ export const IS_READ_ONLY: WeakMap = new WeakMap() export const IS_FOCUSED: WeakMap = new WeakMap() export const IS_COMPOSING: WeakMap = new WeakMap() export const EDITOR_TO_USER_SELECTION: WeakMap = new WeakMap() /** * Weak map for associating the context `onChange` context with the plugin. */ export const EDITOR_TO_ON_CHANGE = new WeakMap< Editor, (options?: { operation?: Operation }) => void >() /** * Weak maps for saving pending state on composition stage. */ export const EDITOR_TO_SCHEDULE_FLUSH: WeakMap void> = new WeakMap() export const EDITOR_TO_PENDING_INSERTION_MARKS: WeakMap< Editor, Partial | null > = new WeakMap() export const EDITOR_TO_USER_MARKS: WeakMap | null> = new WeakMap() /** * Android input handling specific weak-maps */ export const EDITOR_TO_PENDING_DIFFS: WeakMap = new WeakMap() export const EDITOR_TO_PENDING_ACTION: WeakMap = new WeakMap() export const EDITOR_TO_PENDING_SELECTION: WeakMap = new WeakMap() export const EDITOR_TO_FORCE_RENDER: WeakMap void> = new WeakMap() /** * Symbols. */ export const PLACEHOLDER_SYMBOL = Symbol('placeholder') as unknown as string export const MARK_PLACEHOLDER_SYMBOL = Symbol( 'mark-placeholder' ) as unknown as string