@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
193 lines (192 loc) • 7.88 kB
TypeScript
import { MarkType, Node, NodeType, Schema, Slice, MediaAttributes } from '../';
import { NodeSpec, MarkSpec } from '../prosemirror';
/**
* Represents a ProseMirror "position" in a document.
*/
export declare type position = number;
/**
* A useful feature of the builder is being able to declaratively mark positions
* in content using the curly braces e.g. `{<>}`.
*
* These positions are called "refs" (inspired by React), and are tracked on
* every node in the tree that has a ref on any of its descendants.
*/
export declare type Refs = {
[name: string]: position;
};
/**
* Content that contains refs information.
*/
export declare type RefsContentItem = RefsNode | RefsTracker;
/**
* Content node or mark builders can consume, e.g.
*
* const builder = nodeFactory('p');
* builder('string');
* builder(aNode);
* builder(aRefsNode);
* builder(aRefsTracker);
* builder([aNode, aRefsNode, aRefsTracker]);
*/
export declare type BuilderContent = string | Node | RefsContentItem | (Node | RefsContentItem)[];
/**
* ProseMirror doesn't support empty text nodes, which can be quite
* inconvenient when you want to capture a position ref without introducing
* text.
*
* Take a couple of examples:
*
* p('{<>}')
* p('Hello ', '{<>}', 'world!')
*
* After the ref syntax is stripped you're left with:
*
* p('')
* p('Hello ', '', 'world!')
*
* This violates the rule of text nodes being non-empty. This class solves the
* problem by providing an alternative data structure that *only* stores refs,
* and can be used in scenarios where an empty text would be forbidden.
*
* This is done under the hood when using `text()` factory, and instead of
* always returning a text node, it'll instead return one of two things:
*
* - a text node -- when given a non-empty string
* - a refs tracker -- when given a string that *only* contains refs.
*/
export declare class RefsTracker {
refs: Refs;
}
/**
* A standard ProseMirror Node that also tracks refs.
*/
export interface RefsNode extends Node {
refs: Refs;
}
/**
* Create a text node.
*
* Special markers called "refs" can be put in the text. Refs provide a way to
* declaratively describe a position within some text, and then access the
* position in the resulting node.
*/
export declare function text(value: string, schema: Schema<NodeSpec, MarkSpec>): RefsContentItem;
/**
* Offset ref position values by some amount.
*/
export declare function offsetRefs(refs: Refs, offset: number): Refs;
/**
* Given a collection of nodes, sequence them in an array and return the result
* along with the updated refs.
*/
export declare function sequence(...content: RefsContentItem[]): {
nodes: RefsNode[];
refs: Refs;
};
/**
* Given a jagged array, flatten it down to a single level.
*/
export declare function flatten<T>(deep: (T | T[])[]): T[];
/**
* Coerce builder content into ref nodes.
*/
export declare function coerce(content: BuilderContent[], schema: Schema<NodeSpec, MarkSpec>): {
nodes: RefsNode[];
refs: Refs;
};
/**
* Create a factory for nodes.
*/
export declare function nodeFactory(type: NodeType, attrs?: {}): (...content: BuilderContent[]) => RefsNode;
/**
* Create a factory for marks.
*/
export declare function markFactory(type: MarkType, attrs?: {}): (...content: BuilderContent[]) => RefsNode[];
export declare const createCell: (colspan: any, rowspan: any) => RefsNode;
export declare const createHeaderCell: (colspan: any, rowspan: any) => RefsNode;
export declare const doc: (...content: BuilderContent[]) => RefsNode;
export declare const p: (...content: BuilderContent[]) => RefsNode;
export declare const blockquote: (...content: BuilderContent[]) => RefsNode;
export declare const h1: (...content: BuilderContent[]) => RefsNode;
export declare const h2: (...content: BuilderContent[]) => RefsNode;
export declare const h3: (...content: BuilderContent[]) => RefsNode;
export declare const h4: (...content: BuilderContent[]) => RefsNode;
export declare const h5: (...content: BuilderContent[]) => RefsNode;
export declare const h6: (...content: BuilderContent[]) => RefsNode;
export declare const li: (...content: BuilderContent[]) => RefsNode;
export declare const ul: (...content: BuilderContent[]) => RefsNode;
export declare const ol: (...content: BuilderContent[]) => RefsNode;
export declare const br: any;
export declare const panel: (...content: BuilderContent[]) => RefsNode;
export declare const panelNote: (...content: BuilderContent[]) => RefsNode;
export declare const plain: (...content: BuilderContent[]) => RefsNode;
export declare const hardBreak: (...content: BuilderContent[]) => RefsNode;
export declare const code_block: (attrs?: {}) => (...content: BuilderContent[]) => RefsNode;
export declare const img: (attrs: {
src: string;
alt?: string | undefined;
title?: string | undefined;
}) => any;
export declare const emoji: (attrs: {
shortName: string;
id?: string | undefined;
fallback?: string | undefined;
}) => any;
export declare const mention: (attrs: {
id: string;
text?: string | undefined;
}) => any;
export declare const hr: any;
export declare const em: (...content: BuilderContent[]) => RefsNode[];
export declare const subsup: (attrs: {
type: string;
}) => (...content: BuilderContent[]) => RefsNode[];
export declare const underline: (...content: BuilderContent[]) => RefsNode[];
export declare const strong: (...content: BuilderContent[]) => RefsNode[];
export declare const code: (...content: BuilderContent[]) => RefsNode[];
export declare const strike: (...content: BuilderContent[]) => RefsNode[];
export declare const mentionQuery: (attrs?: {
active: boolean;
}) => (...content: BuilderContent[]) => RefsNode[];
export declare const a: (attrs: {
href: string;
title?: string | undefined;
}) => (...content: BuilderContent[]) => RefsNode[];
export declare const fragment: (...content: BuilderContent[]) => BuilderContent[];
export declare const slice: (...content: BuilderContent[]) => Slice;
export declare const emojiQuery: (...content: BuilderContent[]) => RefsNode[];
export declare const singleImage: (attrs?: {}) => (...content: BuilderContent[]) => RefsNode;
export declare const mediaGroup: (...content: BuilderContent[]) => RefsNode;
export declare const media: (attrs: MediaAttributes) => any;
export declare const textColor: (attrs: {
color: string;
}) => (...content: BuilderContent[]) => RefsNode[];
export declare const table: (...content: BuilderContent[]) => RefsNode;
export declare const tr: (...content: BuilderContent[]) => RefsNode;
export declare const td: (attrs: {
colspan?: number | undefined;
rowspan?: number | undefined;
}) => (...content: BuilderContent[]) => RefsNode;
export declare const th: (attrs: {
colspan?: number | undefined;
rowspan?: number | undefined;
}) => (...content: BuilderContent[]) => RefsNode;
export declare const tdEmpty: RefsNode;
export declare const thEmpty: RefsNode;
export declare const tdCursor: RefsNode;
export declare const thCursor: RefsNode;
export declare const td11: RefsNode;
export declare const th11: RefsNode;
export declare const decisionList: (...content: BuilderContent[]) => RefsNode;
export declare const decisionItem: (...content: BuilderContent[]) => RefsNode;
export declare const taskList: (...content: BuilderContent[]) => RefsNode;
export declare const taskItem: (...content: BuilderContent[]) => RefsNode;
export declare const confluenceUnsupportedBlock: (cxhtml: string) => RefsNode;
export declare const confluenceUnsupportedInline: (cxhtml: string) => RefsNode;
export declare const confluenceJiraIssue: (attrs: {
issueKey?: string | undefined;
macroId?: string | undefined;
schemaVersion?: string | undefined;
server?: string | undefined;
serverId?: string | undefined;
}) => any;