mind-elixir
Version:
Mind elixir is a free open source mind map core.
222 lines (221 loc) • 8.71 kB
TypeScript
import './index.css';
import './markdown.css';
import { LEFT, RIGHT, SIDE, DOWN, DARK_THEME, THEME } from './const';
import { generateUUID } from './utils/index';
import { createBus } from './utils/pubsub';
import { findEle } from './utils/dom';
import type { MindElixirData, Options, Theme, ThemeCssVar, NodeObj, NodeObjExport, Alignment, KeypressOptions, Before } from './types/index';
import type { Topic, ArrowSvg, SummarySvg, Wrapper, Parent, Children } from './types/dom';
import type { Arrow, ArrowOptions } from './arrow';
import type { Summary, SummaryOptions } from './summary';
import type { ContextMenuOption } from './plugin/contextMenu';
import type { MainLineParams, SubLineParams } from './utils/generateBranch';
import type { LinkPanHelperInstance } from './utils/LinkPanHelper';
import type { EventMap, Operation } from './utils/pubsub';
import type SelectionArea from './viselect/src';
import { createPanHelper } from './utils/panHelper';
type ResolvedTheme<M> = Omit<Theme<M>, 'cssVar'> & {
cssVar: ThemeCssVar;
};
declare class MindElixir<M = any> {
static readonly LEFT = 0;
static readonly RIGHT = 1;
static readonly SIDE = 2;
static readonly DOWN = 3;
static readonly THEME: Theme & {
cssVar: ThemeCssVar;
};
static readonly DARK_THEME: Theme & {
cssVar: ThemeCssVar;
};
/**
* @memberof MindElixir
* @static
*/
static version: string;
/**
* @function
* @memberof MindElixir
* @static
* @name E
* @param {string} id Node id.
* @return {TargetElement} Target element.
* @example
* E('bd4313fbac40284b')
*/
static E: typeof findEle;
/**
* @function new
* @memberof MindElixir
* @static
* @param {String} topic root topic
*/
static new: <M_1 = unknown>(topic: string) => MindElixirData<M_1>;
el: HTMLElement;
theme: ResolvedTheme<M>;
markdown?: (markdown: string, obj: NodeObj<M> | Arrow<M> | Summary) => string;
imageProxy?: (url: string) => string;
disposable: Array<() => void>;
dragged: Topic<M>[] | null;
spacePressed: boolean;
isFocusMode: boolean;
nodeDataBackup: NodeObj<M>;
nodeData: NodeObj<M>;
arrows: Arrow<M>[];
summaries: Summary[];
currentNodes: Topic<M>[];
currentSummary: SummarySvg | null;
currentArrow: ArrowSvg | null;
scaleVal: number;
tempDirection: 0 | 1 | 2 | 3 | null;
meta?: Record<string, any>;
container: HTMLElement;
map: HTMLElement;
root: HTMLElement;
nodes: HTMLElement;
lines: SVGElement;
summarySvg: SVGElement;
linkController: SVGElement;
labelContainer: HTMLElement;
P2: HTMLElement;
P3: HTMLElement;
line1: SVGElement;
line2: SVGElement;
arrowSvg: SVGElement;
/**
* @internal
*/
helper1?: LinkPanHelperInstance;
/**
* @internal
*/
helper2?: LinkPanHelperInstance;
/**
* @internal
*/
pluginsInitialized: boolean;
bus: ReturnType<typeof createBus<EventMap>>;
history: Operation[];
undo: () => void;
redo: () => void;
/**
* Reset the undo/redo stack and update the internal baseline snapshot to the
* current diagram state. Call this after loading new data into an existing
* instance (e.g. after `refresh()`) to prevent users from undoing back into
* a previously loaded diagram.
*
* Only available when `allowUndo` is `true` (the default).
*/
clearHistory?: () => void;
selection: SelectionArea;
panHelper: ReturnType<typeof createPanHelper>;
ptState?: number;
direction: 0 | 1 | 2 | 3;
editable: boolean;
contextMenu: boolean | ContextMenuOption;
toolBar: boolean;
keypress: boolean | KeypressOptions;
mouseSelectionButton: 0 | 2;
before: Before;
newTopicName: string;
allowUndo: boolean;
overflowHidden: boolean;
compact: boolean;
generateMainBranch: (this: MindElixir<M>, params: MainLineParams) => string;
generateSubBranch: (this: MindElixir<M>, params: SubLineParams) => string;
selectionContainer: string | HTMLElement;
alignment: Alignment;
scaleSensitivity: number;
scaleMin: number;
scaleMax: number;
handleWheel: true | ((e: WheelEvent) => void);
pasteHandler: (e: ClipboardEvent) => void;
mobileMultiSelect: boolean;
init: (data: MindElixirData<M>) => Promise<Error | undefined>;
destroy: () => void;
enableMobileMultiSelect: (enable: boolean) => void;
createSummary: (options?: SummaryOptions) => void;
createSummaryFrom: (summary: Omit<Summary, 'id'>) => void;
removeSummary: (id: string) => void;
selectSummary: (el: SummarySvg) => void;
unselectSummary: () => void;
renderSummary: () => void;
editSummary: (el: SummarySvg) => void;
renderArrow: () => void;
editArrowLabel: (el: ArrowSvg) => void;
tidyArrow: () => void;
createArrow: (from: Topic<M>, to: Topic<M>, options?: ArrowOptions) => void;
createArrowFrom: (arrow: Omit<Arrow<M>, 'id'>) => void;
removeArrow: (linkSvg?: ArrowSvg) => void;
selectArrow: (link: ArrowSvg) => void;
unselectArrow: () => void;
reshapeArrow: (arrow: Arrow<M>, patchData: Partial<Arrow<M>>) => void;
rmSubline: (tpc: Topic<M>) => Promise<void>;
reshapeNode: (tpc: Topic<M>, patchData: Partial<NodeObj<M>>) => Promise<void>;
insertSibling: (type: 'before' | 'after', el?: Topic<M> | undefined, node?: NodeObj<M> | undefined) => Promise<void>;
insertParent: (el?: Topic<M> | undefined, node?: NodeObj<M> | undefined) => Promise<void>;
addChild: (el?: Topic<M> | undefined, node?: NodeObj<M> | undefined) => Promise<void>;
copyNodes: (tpcs: Topic<M>[], to: Topic<M>) => Promise<void>;
moveUpNode: (el?: Topic<M> | undefined) => Promise<void>;
moveDownNode: (el?: Topic<M> | undefined) => Promise<void>;
removeNodes: (tpcs: Topic<M>[]) => Promise<void>;
moveNodesIn: (from: Topic<M>[], to: Topic<M>) => Promise<void>;
moveNodesBefore: (from: Topic<M>[], to: Topic<M>) => Promise<void>;
moveNodesAfter: (from: Topic<M>[], to: Topic<M>) => Promise<void>;
beginEdit: (el?: Topic<M> | undefined) => Promise<void>;
setNodeTopic: (el: Topic<M>, topic: string) => Promise<void>;
scrollIntoView: (el: HTMLElement, forceCenter?: boolean) => void;
selectNode: (tpc: Topic<M>, isNewNode?: boolean, e?: MouseEvent) => void;
selectNodes: (tpcs: Topic<M>[]) => void;
unselectNodes: (tpcs: Topic<M>[]) => void;
clearSelection: () => void;
stringifyData: (data: object) => string;
getDataString: () => string;
getData: () => MindElixirData<M>;
enableEdit: () => void;
disableEdit: () => void;
scale: (scaleVal: number, offset?: {
x: number;
y: number;
}) => void;
scaleFit: () => void;
move: (dx: number, dy: number, smooth?: boolean) => boolean;
toCenter: () => void;
install: (plugin: (instance: MindElixir<M>) => void) => void;
focusNode: (el: Topic<M>) => void;
cancelFocus: () => void;
initLeft: () => void;
initRight: () => void;
initSide: () => void;
initDown: () => void;
expandNode: (el: Topic<M>, isExpand?: boolean) => void;
expandNodeAll: (el: Topic<M>, isExpand?: boolean) => void;
refresh: (data?: MindElixirData<M>) => void;
getObjById: (id: string, data: NodeObj<M>) => NodeObj<M> | null;
generateNewObj: () => NodeObjExport<M>;
layout: () => void;
linkDiv: (mainNode?: Wrapper) => void;
editTopic: (el: Topic<M>) => void;
createWrapper: (nodeObj: NodeObj<M>, omitChildren?: boolean) => {
grp: Wrapper;
top: Parent;
tpc: Topic<M>;
};
createParent: (nodeObj: NodeObj<M>) => {
p: Parent;
tpc: Topic<M>;
};
createChildren: (wrappers: Wrapper[]) => Children;
createTopic: (nodeObj: NodeObj<M>) => Topic<M>;
findEle: (id: string, el?: HTMLElement) => Topic<M>;
changeTheme: (theme: Theme<M>, shouldRefresh?: boolean) => void;
changeCompact: (compact: boolean) => void;
get currentNode(): Topic<M> | null;
constructor({ el, direction, editable, contextMenu, toolBar, keypress, mouseSelectionButton, selectionContainer, before, newTopicName, allowUndo, generateMainBranch, generateSubBranch, overflowHidden, compact, theme, alignment, scaleSensitivity, scaleMax, scaleMin, handleWheel, markdown, imageProxy, pasteHandler, mobileMultiSelect, }: Options<M>);
}
export default MindElixir;
export { LEFT, RIGHT, SIDE, DOWN, THEME, DARK_THEME };
export { generateUUID };
export type * from './utils/pubsub';
export type * from './types/index';
export type * from './types/dom';