cell.d.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. import { KeyValue, Size, Basecoat } from '@antv/x6-common';
  2. import { Rectangle, Point } from '@antv/x6-geometry';
  3. import { NonUndefined } from 'utility-types';
  4. import { Attr } from '../registry';
  5. import { Model } from './model';
  6. import { PortManager } from './port';
  7. import { Store } from './store';
  8. import { Edge } from './edge';
  9. import { Animation } from './animation';
  10. import { CellView, Markup } from '../view';
  11. import { Node } from './node';
  12. import { Graph } from '../graph';
  13. export declare class Cell<Properties extends Cell.Properties = Cell.Properties> extends Basecoat<Cell.EventArgs> {
  14. protected static markup: Markup;
  15. protected static defaults: Cell.Defaults;
  16. protected static attrHooks: Attr.Definitions;
  17. protected static propHooks: Cell.PropHook[];
  18. static config<C extends Cell.Config = Cell.Config>(presets: C): void;
  19. static getMarkup(): Markup;
  20. static getDefaults<T extends Cell.Defaults = Cell.Defaults>(raw?: boolean): T;
  21. static getAttrHooks(): Attr.Definitions;
  22. static applyPropHooks(cell: Cell, metadata: Cell.Metadata): Cell.Metadata;
  23. protected get [Symbol.toStringTag](): string;
  24. readonly id: string;
  25. protected readonly store: Store<Cell.Properties>;
  26. protected readonly animation: Animation;
  27. protected _model: Model | null;
  28. protected _parent: Cell | null;
  29. protected _children: Cell[] | null;
  30. constructor(metadata?: Cell.Metadata);
  31. init(): void;
  32. get model(): Model | null;
  33. set model(model: Model | null);
  34. protected preprocess(metadata: Cell.Metadata, ignoreIdCheck?: boolean): Properties;
  35. protected postprocess(metadata: Cell.Metadata): void;
  36. protected setup(): void;
  37. notify<Key extends keyof Cell.EventArgs>(name: Key, args: Cell.EventArgs[Key]): this;
  38. notify(name: Exclude<string, keyof Cell.EventArgs>, args: any): this;
  39. isNode(): this is Node;
  40. isEdge(): this is Edge;
  41. isSameStore(cell: Cell): boolean;
  42. get view(): string | undefined;
  43. get shape(): string;
  44. getProp(): Properties;
  45. getProp<K extends keyof Properties>(key: K): Properties[K];
  46. getProp<K extends keyof Properties>(key: K, defaultValue: Properties[K]): NonUndefined<Properties[K]>;
  47. getProp<T>(key: string): T;
  48. getProp<T>(key: string, defaultValue: T): T;
  49. setProp<K extends keyof Properties>(key: K, value: Properties[K] | null | undefined | void, options?: Cell.SetOptions): this;
  50. setProp(key: string, value: any, options?: Cell.SetOptions): this;
  51. setProp(props: Partial<Properties>, options?: Cell.SetOptions): this;
  52. removeProp<K extends keyof Properties>(key: K | K[], options?: Cell.SetOptions): this;
  53. removeProp(key: string | string[], options?: Cell.SetOptions): this;
  54. removeProp(options?: Cell.SetOptions): this;
  55. hasChanged(): boolean;
  56. hasChanged<K extends keyof Properties>(key: K | null): boolean;
  57. hasChanged(key: string | null): boolean;
  58. getPropByPath<T>(path: string | string[]): T;
  59. setPropByPath(path: string | string[], value: any, options?: Cell.SetByPathOptions): this;
  60. removePropByPath(path: string | string[], options?: Cell.SetOptions): this;
  61. prop(): Properties;
  62. prop<K extends keyof Properties>(key: K): Properties[K];
  63. prop<T>(key: string): T;
  64. prop<T>(path: string[]): T;
  65. prop<K extends keyof Properties>(key: K, value: Properties[K] | null | undefined | void, options?: Cell.SetOptions): this;
  66. prop(key: string, value: any, options?: Cell.SetOptions): this;
  67. prop(path: string[], value: any, options?: Cell.SetOptions): this;
  68. prop(props: Partial<Properties>, options?: Cell.SetOptions): this;
  69. previous<K extends keyof Properties>(name: K): Properties[K] | undefined;
  70. previous<T>(name: string): T | undefined;
  71. get zIndex(): number | undefined | null;
  72. set zIndex(z: number | undefined | null);
  73. getZIndex(): number | undefined;
  74. setZIndex(z: number, options?: Cell.SetOptions): this;
  75. removeZIndex(options?: Cell.SetOptions): this;
  76. toFront(options?: Cell.ToFrontOptions): this;
  77. toBack(options?: Cell.ToBackOptions): this;
  78. get markup(): Markup | undefined | null;
  79. set markup(value: Markup | undefined | null);
  80. getMarkup(): Markup;
  81. setMarkup(markup: Markup, options?: Cell.SetOptions): this;
  82. removeMarkup(options?: Cell.SetOptions): this;
  83. get attrs(): Attr.CellAttrs | null | undefined;
  84. set attrs(value: Attr.CellAttrs | null | undefined);
  85. getAttrs(): {
  86. [x: string]: Attr.ComplexAttrs;
  87. };
  88. setAttrs(attrs: Attr.CellAttrs | null | undefined, options?: Cell.SetAttrOptions): this;
  89. replaceAttrs(attrs: Attr.CellAttrs, options?: Cell.SetOptions): this;
  90. updateAttrs(attrs: Attr.CellAttrs, options?: Cell.SetOptions): this;
  91. removeAttrs(options?: Cell.SetOptions): this;
  92. getAttrDefinition(attrName: string): string | Attr.Qualify | null;
  93. getAttrByPath(): Attr.CellAttrs;
  94. getAttrByPath<T>(path: string | string[]): T;
  95. setAttrByPath(path: string | string[], value: Attr.ComplexAttrValue, options?: Cell.SetOptions): this;
  96. removeAttrByPath(path: string | string[], options?: Cell.SetOptions): this;
  97. protected prefixAttrPath(path: string | string[]): string | string[];
  98. attr(): Attr.CellAttrs;
  99. attr<T>(path: string | string[]): T;
  100. attr(path: string | string[], value: Attr.ComplexAttrValue | null, options?: Cell.SetOptions): this;
  101. attr(attrs: Attr.CellAttrs, options?: Cell.SetAttrOptions): this;
  102. get visible(): boolean;
  103. set visible(value: boolean);
  104. setVisible(visible: boolean, options?: Cell.SetOptions): this;
  105. isVisible(): boolean;
  106. show(options?: Cell.SetOptions): this;
  107. hide(options?: Cell.SetOptions): this;
  108. toggleVisible(visible: boolean, options?: Cell.SetOptions): this;
  109. toggleVisible(options?: Cell.SetOptions): this;
  110. get data(): Properties['data'];
  111. set data(val: Properties['data']);
  112. getData<T = Properties['data']>(): T;
  113. setData<T = Properties['data']>(data: T, options?: Cell.SetDataOptions): this;
  114. replaceData<T = Properties['data']>(data: T, options?: Cell.SetOptions): this;
  115. updateData<T = Properties['data']>(data: T, options?: Cell.SetOptions): this;
  116. removeData(options?: Cell.SetOptions): this;
  117. get parent(): Cell | null;
  118. get children(): Cell<Cell.Properties>[] | null;
  119. getParentId(): string | undefined;
  120. getParent<T extends Cell = Cell>(): T | null;
  121. getChildren(): Cell<Cell.Properties>[] | null;
  122. hasParent(): boolean;
  123. isParentOf(child: Cell | null): boolean;
  124. isChildOf(parent: Cell | null): boolean;
  125. eachChild(iterator: (child: Cell, index: number, children: Cell[]) => void, context?: any): this;
  126. filterChild(filter: (cell: Cell, index: number, arr: Cell[]) => boolean, context?: any): Cell[];
  127. getChildCount(): number;
  128. getChildIndex(child: Cell): number;
  129. getChildAt(index: number): Cell<Cell.Properties> | null;
  130. getAncestors(options?: {
  131. deep?: boolean;
  132. }): Cell[];
  133. getDescendants(options?: Cell.GetDescendantsOptions): Cell[];
  134. isDescendantOf(ancestor: Cell | null, options?: {
  135. deep?: boolean;
  136. }): boolean;
  137. isAncestorOf(descendant: Cell | null, options?: {
  138. deep?: boolean;
  139. }): boolean;
  140. contains(cell: Cell | null): boolean;
  141. getCommonAncestor(...cells: (Cell | null | undefined)[]): Cell | null;
  142. setParent(parent: Cell | null, options?: Cell.SetOptions): this;
  143. setChildren(children: Cell[] | null, options?: Cell.SetOptions): this;
  144. unembed(child: Cell, options?: Cell.SetOptions): this;
  145. embed(child: Cell, options?: Cell.SetOptions): this;
  146. addTo(model: Model, options?: Cell.SetOptions): this;
  147. addTo(graph: Graph, options?: Cell.SetOptions): this;
  148. addTo(parent: Cell, options?: Cell.SetOptions): this;
  149. insertTo(parent: Cell, index?: number, options?: Cell.SetOptions): this;
  150. addChild(child: Cell | null, options?: Cell.SetOptions): this;
  151. insertChild(child: Cell | null, index?: number, options?: Cell.SetOptions): this;
  152. removeFromParent(options?: Cell.RemoveOptions): this;
  153. removeChild(child: Cell, options?: Cell.RemoveOptions): Cell<Cell.Properties> | null;
  154. removeChildAt(index: number, options?: Cell.RemoveOptions): Cell<Cell.Properties> | null;
  155. remove(options?: Cell.RemoveOptions): this;
  156. transition<K extends keyof Properties>(path: K, target: Properties[K], options?: Animation.StartOptions<Properties[K]>, delim?: string): () => void;
  157. transition<T extends Animation.TargetValue>(path: string | string[], target: T, options?: Animation.StartOptions<T>, delim?: string): () => void;
  158. stopTransition<T extends Animation.TargetValue>(path: string | string[], options?: Animation.StopOptions<T>, delim?: string): this;
  159. getTransitions(): string[];
  160. translate(tx: number, ty: number, options?: Cell.TranslateOptions): this;
  161. scale(sx: number, // eslint-disable-line
  162. sy: number, // eslint-disable-line
  163. origin?: Point | Point.PointLike, // eslint-disable-line
  164. options?: Node.SetOptions): this;
  165. addTools(items: Cell.ToolItem | Cell.ToolItem[], options?: Cell.AddToolOptions): void;
  166. addTools(items: Cell.ToolItem | Cell.ToolItem[], name: string, options?: Cell.AddToolOptions): void;
  167. setTools(tools?: Cell.ToolsLoose | null, options?: Cell.SetOptions): this;
  168. getTools(): Cell.Tools | null;
  169. removeTools(options?: Cell.SetOptions): this;
  170. hasTools(name?: string): boolean;
  171. hasTool(name: string): boolean;
  172. removeTool(name: string, options?: Cell.SetOptions): this;
  173. removeTool(index: number, options?: Cell.SetOptions): this;
  174. getBBox(options?: {
  175. deep?: boolean;
  176. }): Rectangle;
  177. getConnectionPoint(edge: Edge, type: Edge.TerminalType): Point;
  178. toJSON(options?: Cell.ToJSONOptions): this extends Node ? Node.Properties : this extends Edge ? Edge.Properties : Properties;
  179. clone(options?: Cell.CloneOptions): this extends Node ? Node : this extends Edge ? Edge : Cell;
  180. findView(graph: Graph): CellView | null;
  181. startBatch(name: Model.BatchName, data?: KeyValue, model?: Model | null): this;
  182. stopBatch(name: Model.BatchName, data?: KeyValue, model?: Model | null): this;
  183. batchUpdate<T>(name: Model.BatchName, execute: () => T, data?: KeyValue): T;
  184. dispose(): void;
  185. }
  186. export declare namespace Cell {
  187. interface Common {
  188. view?: string;
  189. shape?: string;
  190. markup?: Markup;
  191. attrs?: Attr.CellAttrs;
  192. zIndex?: number;
  193. visible?: boolean;
  194. data?: any;
  195. }
  196. interface Defaults extends Common {
  197. }
  198. interface Metadata extends Common, KeyValue {
  199. id?: string;
  200. tools?: ToolsLoose;
  201. }
  202. interface Properties extends Defaults, Metadata {
  203. parent?: string;
  204. children?: string[];
  205. tools?: Tools;
  206. }
  207. }
  208. export declare namespace Cell {
  209. type ToolItem = string | {
  210. name: string;
  211. args?: any;
  212. };
  213. interface Tools {
  214. name?: string | null;
  215. local?: boolean;
  216. items: ToolItem[];
  217. }
  218. type ToolsLoose = ToolItem | ToolItem[] | Tools;
  219. function normalizeTools(raw: ToolsLoose): Tools;
  220. }
  221. export declare namespace Cell {
  222. interface SetOptions extends Store.SetOptions {
  223. }
  224. interface MutateOptions extends Store.MutateOptions {
  225. }
  226. interface RemoveOptions extends SetOptions {
  227. deep?: boolean;
  228. }
  229. interface SetAttrOptions extends SetOptions {
  230. deep?: boolean;
  231. overwrite?: boolean;
  232. }
  233. interface SetDataOptions extends SetOptions {
  234. deep?: boolean;
  235. overwrite?: boolean;
  236. }
  237. interface SetByPathOptions extends Store.SetByPathOptions {
  238. }
  239. interface ToFrontOptions extends SetOptions {
  240. deep?: boolean;
  241. }
  242. interface ToBackOptions extends ToFrontOptions {
  243. }
  244. interface TranslateOptions extends SetOptions {
  245. tx?: number;
  246. ty?: number;
  247. translateBy?: string | number;
  248. }
  249. interface AddToolOptions extends SetOptions {
  250. reset?: boolean;
  251. local?: boolean;
  252. }
  253. interface GetDescendantsOptions {
  254. deep?: boolean;
  255. breadthFirst?: boolean;
  256. }
  257. interface ToJSONOptions {
  258. diff?: boolean;
  259. }
  260. interface CloneOptions {
  261. deep?: boolean;
  262. keepId?: boolean;
  263. }
  264. }
  265. export declare namespace Cell {
  266. export interface EventArgs {
  267. 'transition:start': Animation.CallbackArgs<Animation.TargetValue>;
  268. 'transition:progress': Animation.ProgressArgs<Animation.TargetValue>;
  269. 'transition:complete': Animation.CallbackArgs<Animation.TargetValue>;
  270. 'transition:stop': Animation.StopArgs<Animation.TargetValue>;
  271. 'transition:finish': Animation.CallbackArgs<Animation.TargetValue>;
  272. 'change:*': ChangeAnyKeyArgs;
  273. 'change:attrs': ChangeArgs<Attr.CellAttrs>;
  274. 'change:zIndex': ChangeArgs<number>;
  275. 'change:markup': ChangeArgs<Markup>;
  276. 'change:visible': ChangeArgs<boolean>;
  277. 'change:parent': ChangeArgs<string>;
  278. 'change:children': ChangeArgs<string[]>;
  279. 'change:tools': ChangeArgs<Tools>;
  280. 'change:view': ChangeArgs<string>;
  281. 'change:data': ChangeArgs<any>;
  282. 'change:size': NodeChangeArgs<Size>;
  283. 'change:angle': NodeChangeArgs<number>;
  284. 'change:position': NodeChangeArgs<Point.PointLike>;
  285. 'change:ports': NodeChangeArgs<PortManager.Port[]>;
  286. 'change:portMarkup': NodeChangeArgs<Markup>;
  287. 'change:portLabelMarkup': NodeChangeArgs<Markup>;
  288. 'change:portContainerMarkup': NodeChangeArgs<Markup>;
  289. 'ports:removed': {
  290. cell: Cell;
  291. node: Node;
  292. removed: PortManager.Port[];
  293. };
  294. 'ports:added': {
  295. cell: Cell;
  296. node: Node;
  297. added: PortManager.Port[];
  298. };
  299. 'change:source': EdgeChangeArgs<Edge.TerminalData>;
  300. 'change:target': EdgeChangeArgs<Edge.TerminalData>;
  301. 'change:terminal': EdgeChangeArgs<Edge.TerminalData> & {
  302. type: Edge.TerminalType;
  303. };
  304. 'change:router': EdgeChangeArgs<Edge.RouterData>;
  305. 'change:connector': EdgeChangeArgs<Edge.ConnectorData>;
  306. 'change:vertices': EdgeChangeArgs<Point.PointLike[]>;
  307. 'change:labels': EdgeChangeArgs<Edge.Label[]>;
  308. 'change:defaultLabel': EdgeChangeArgs<Edge.Label>;
  309. 'vertexs:added': {
  310. cell: Cell;
  311. edge: Edge;
  312. added: Point.PointLike[];
  313. };
  314. 'vertexs:removed': {
  315. cell: Cell;
  316. edge: Edge;
  317. removed: Point.PointLike[];
  318. };
  319. 'labels:added': {
  320. cell: Cell;
  321. edge: Edge;
  322. added: Edge.Label[];
  323. };
  324. 'labels:removed': {
  325. cell: Cell;
  326. edge: Edge;
  327. removed: Edge.Label[];
  328. };
  329. 'batch:start': {
  330. name: Model.BatchName;
  331. data: KeyValue;
  332. cell: Cell;
  333. };
  334. 'batch:stop': {
  335. name: Model.BatchName;
  336. data: KeyValue;
  337. cell: Cell;
  338. };
  339. changed: {
  340. cell: Cell;
  341. options: MutateOptions;
  342. };
  343. added: {
  344. cell: Cell;
  345. index: number;
  346. options: Cell.SetOptions;
  347. };
  348. removed: {
  349. cell: Cell;
  350. index: number;
  351. options: Cell.RemoveOptions;
  352. };
  353. }
  354. interface ChangeAnyKeyArgs<T extends keyof Properties = keyof Properties> {
  355. key: T;
  356. current: Properties[T];
  357. previous: Properties[T];
  358. options: MutateOptions;
  359. cell: Cell;
  360. }
  361. export interface ChangeArgs<T> {
  362. cell: Cell;
  363. current?: T;
  364. previous?: T;
  365. options: MutateOptions;
  366. }
  367. interface NodeChangeArgs<T> extends ChangeArgs<T> {
  368. node: Node;
  369. }
  370. interface EdgeChangeArgs<T> extends ChangeArgs<T> {
  371. edge: Edge;
  372. }
  373. export {};
  374. }
  375. export declare namespace Cell {
  376. const toStringTag: string;
  377. function isCell(instance: any): instance is Cell;
  378. }
  379. export declare namespace Cell {
  380. function getCommonAncestor(...cells: (Cell | null | undefined)[]): Cell | null;
  381. interface GetCellsBBoxOptions {
  382. deep?: boolean;
  383. }
  384. function getCellsBBox(cells: Cell[], options?: GetCellsBBoxOptions): Rectangle | null;
  385. function deepClone(cell: Cell): KeyValue<Cell<Properties>>;
  386. function cloneCells(cells: Cell[]): KeyValue<Cell<Properties>>;
  387. }
  388. export declare namespace Cell {
  389. type Definition = typeof Cell;
  390. type PropHook<M extends Metadata = Metadata, C extends Cell = Cell> = (this: C, metadata: M) => M;
  391. type PropHooks<M extends Metadata = Metadata, C extends Cell = Cell> = KeyValue<PropHook<M, C>> | PropHook<M, C> | PropHook<M, C>[];
  392. interface Config<M extends Metadata = Metadata, C extends Cell = Cell> extends Defaults, KeyValue {
  393. constructorName?: string;
  394. overwrite?: boolean;
  395. propHooks?: PropHooks<M, C>;
  396. attrHooks?: Attr.Definitions;
  397. }
  398. }
  399. export declare namespace Cell {
  400. }