@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
53 lines (52 loc) • 2.86 kB
TypeScript
import type { JSONDocNode, JSONNode } from '@atlaskit/editor-json-transformer';
import type { Fragment, MarkType, NodeType, Mark as PMMark, Node as PMNode, ResolvedPos, Schema } from '@atlaskit/editor-prosemirror/model';
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
import type { CardAppearance } from '@atlaskit/smart-card';
/**
* Finds all top level nodes affected by the transaction
* Uses from/to positions in transaction's steps to work out which nodes will
* be changed by the transaction
*/
export declare const findChangedNodesFromTransaction: (tr: Transaction) => PMNode[];
export declare const validNode: (node: PMNode) => boolean;
/** Validates prosemirror nodes, and returns true only if all nodes are valid */
export declare const validateNodes: (nodes: PMNode[]) => boolean;
type PMEntities = PMNode | PMMark | null | undefined;
export declare const isType: (node: PMEntities, type: NodeType | MarkType | undefined) => boolean | null | undefined;
export declare const isParagraph: (node: PMEntities, schema: Schema) => boolean | null | undefined;
export declare const isText: (node: PMEntities, schema: Schema) => boolean | null | undefined;
export declare const isLinkMark: (node: PMEntities, schema: Schema) => boolean | null | undefined;
export declare enum SelectedState {
selectedInRange = 0,
selectedInside = 1
}
/**
* Returns if the current selection from achor-head is selecting the node.
* If the node is not selected then null is returned.
* If the node is selected then an enum is returned that describes weather the node
* is fully selected by a range or if the "inside" of the node has been selected or clicked.
*/
export declare const isNodeSelectedOrInRange: (anchorPosition: number, headPosition: number, nodePosition: number | undefined, nodeSize: number) => SelectedState | null;
/**
* Checks if a particular node fragment is supported in the parent
* @param state EditorState
* @param fragment The fragment to be checked for
*/
export declare const isSupportedInParent: (state: EditorState, fragment: Fragment, currentAppearance?: CardAppearance) => boolean;
/**
* Checks if the passed in node is a media node
* Includes media, mediaInline, mediaGroup, mediaSingle
* @param node The PM node to be checked
*/
export declare const isMediaNode: (node: PMNode) => boolean;
/**
* Checks if the node before selection is a media node
* If there is no node before, checks the node before the parent node
* Includes media, mediaInline, mediaGroup, mediaSingle
* @param $pos The position of the selection
* @param state The editor state
*/
export declare const isNodeBeforeMediaNode: ($pos: ResolvedPos, state: EditorState) => boolean;
export declare function toJSON(node: PMNode): JSONDocNode;
export declare function nodeToJSON(node: PMNode): JSONNode;
export {};