@logicflow/core 1.2.0-alpha.9 → 1.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,7 @@
37
37
  stroke-dashoffset: 100%;
38
38
  animation: dash 5s linear infinite;
39
39
  }
40
- @keyframes dash {
40
+ @keyframes lf-dash {
41
41
  to {
42
42
  stroke-dashoffset: 0;
43
43
  }
@@ -196,3 +196,10 @@
196
196
  .lf-edge-adjust-point {
197
197
  cursor: move;
198
198
  }
199
+ /*
200
+ * svg默认会多5px,强制全部设置为block
201
+ * @see https://stackoverflow.com/questions/41437423/difference-between-display-inline-and-block-on-svg-elements
202
+ */
203
+ .lf-graph svg {
204
+ display: block;
205
+ }
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "1.2.0-alpha.9",
3
+ "version": "1.2.0-next.0",
4
4
  "description": "LogicFlow core, to quickly build flowchart editor",
5
5
  "main": "dist/entry.js",
6
+ "module": "dist/logic-flow.js",
6
7
  "unpkg": "dist/logic-flow.min.js",
8
+ "sideEffects": true,
7
9
  "jsdelivr": "dist/logic-flow.min.js",
8
10
  "license": "Apache-2.0",
9
11
  "homepage": "http://logic-flow.org/",
@@ -17,12 +19,13 @@
17
19
  "dev": "cross-env NODE_ENV=development webpack-dev-server --client-log-level warning --config scripts/webpack.config.dev.js",
18
20
  "clean": "rimraf dist lib esm cjs",
19
21
  "build": "npm run build:umd",
20
- "build:umd": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.build.js && cp -r src/style/ dist/style && cp scripts/entry.js dist",
22
+ "build:umd": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.build.js && npm run copy",
21
23
  "build-analyse": "cross-env analyse=true npm run build",
22
24
  "types": "tsc -d --declarationDir ./tempTypes --outDir temp && rimraf types && mv ./tempTypes/src ./types && rimraf temp && rimraf tempTypes",
23
25
  "lint": "eslint . --ext .ts,.tsx",
24
26
  "publish-lib": "npm run types & npm run clean && npm run build && npm publish",
25
- "publish-next": "npm run types & npm run clean && npm run build && npm publish --tag next"
27
+ "publish-next": "npm run types & npm run clean && npm run build && npm publish --tag next",
28
+ "copy": "node ./scripts/copy.js"
26
29
  },
27
30
  "files": [
28
31
  "dist",
@@ -19,14 +19,6 @@ export default class LogicFlow {
19
19
  * 只读:logicflow实例挂载的容器。
20
20
  */
21
21
  container: HTMLElement;
22
- /**
23
- * 只读:画布宽度
24
- */
25
- width: number;
26
- /**
27
- * 只读:画布高度
28
- */
29
- height: number;
30
22
  /**
31
23
  * 只读:控制整个logicflow画布的model
32
24
  */
@@ -133,8 +125,9 @@ export default class LogicFlow {
133
125
  setTheme(style: Theme): void;
134
126
  /**
135
127
  * 重新设置画布的宽高
128
+ * 不传会自动计算画布宽高
136
129
  */
137
- resize(width: number, height: number): void;
130
+ resize(width?: number, height?: number): void;
138
131
  /**
139
132
  * 设置默认的边类型。
140
133
  * 也就是设置在节点直接有用户手动绘制的连线类型。
@@ -304,6 +297,7 @@ export default class LogicFlow {
304
297
  * @param properties 自定义属性
305
298
  */
306
299
  setProperties(id: string, properties: Object): void;
300
+ deleteProperty(id: string, key: string): void;
307
301
  /**
308
302
  * 获取元素的自定义属性
309
303
  * @param id 元素的id
@@ -337,7 +331,7 @@ export default class LogicFlow {
337
331
  * @param leftTopPoint 区域左上角坐标, dom层坐标
338
332
  * @param rightBottomPoint 区域右下角坐标,dom层坐标
339
333
  */
340
- getAreaElement(leftTopPoint: PointTuple, rightBottomPoint: PointTuple, wholeEdge?: boolean, wholeNode?: boolean): any[];
334
+ getAreaElement(leftTopPoint: PointTuple, rightBottomPoint: PointTuple, wholeEdge?: boolean, wholeNode?: boolean, ignoreHideElement?: boolean): any[];
341
335
  /**
342
336
  * 获取选中的元素数据
343
337
  * @param isIgnoreCheck 是否包括sourceNode和targetNode没有被选中的边,默认包括。
@@ -63,6 +63,7 @@ export declare enum EventType {
63
63
  ANCHOR_DRAGSTART = "anchor:dragstart",
64
64
  ANCHOR_DRAG = "anchor:drag",
65
65
  ANCHOR_DROP = "anchor:drop",
66
+ ANCHOR_DRAGEND = "anchor:dragend",
66
67
  BLANK_MOUSEDOWN = "blank:mousedown",
67
68
  BLANK_DRAGSTART = "blank:dragstart",
68
69
  BLANK_DRAG = "blank:drag",
@@ -53,7 +53,14 @@ interface IBaseModel {
53
53
  * 元素是否被选中
54
54
  */
55
55
  isSelected: boolean;
56
+ /**
57
+ * 节点是否显示
58
+ */
56
59
  visible: boolean;
60
+ /**
61
+ * 节点是否可以通过getGraphData获取
62
+ */
63
+ virtual: boolean;
57
64
  /**
58
65
  * 元素堆叠是层级,默认情况下节点zIndex值为1,边zIndex为0。
59
66
  * todo:写完善
@@ -69,11 +69,11 @@ export interface EditConfigInterface {
69
69
  */
70
70
  multipleSelectKey?: string;
71
71
  /**
72
- * 拖动节点靠近画布边缘时,
72
+ * 拖动节点或者连线靠近画布边缘时,
73
73
  * 是否自动扩张画布.
74
74
  * 默认false。
75
75
  */
76
- autoExpand?: string;
76
+ autoExpand?: boolean;
77
77
  }
78
78
  /**
79
79
  * 页面编辑配置
@@ -53,6 +53,10 @@ declare class GraphModel {
53
53
  * @see todo docs link
54
54
  */
55
55
  idGenerator: (type?: string) => string;
56
+ /**
57
+ * 节点间连线、连线变更时的边的生成规则
58
+ */
59
+ edgeGenerator: Definition['edgeGenerator'];
56
60
  /**
57
61
  * 节点移动规则判断
58
62
  * 在节点移动的时候,会出发此数组中的所有规则判断
@@ -142,8 +146,9 @@ declare class GraphModel {
142
146
  * @param rightBottomPoint 表示区域右下角的点
143
147
  * @param wholeEdge 是否要整个边都在区域内部
144
148
  * @param wholeNode 是否要整个节点都在区域内部
149
+ * @param ignoreHideElement 是否忽略隐藏的节点
145
150
  */
146
- getAreaElement(leftTopPoint: PointTuple, rightBottomPoint: PointTuple, wholeEdge?: boolean, wholeNode?: boolean): any[];
151
+ getAreaElement(leftTopPoint: PointTuple, rightBottomPoint: PointTuple, wholeEdge?: boolean, wholeNode?: boolean, ignoreHideElement?: boolean): any[];
147
152
  /**
148
153
  * 获取指定类型元素对应的Model
149
154
  */
@@ -417,7 +422,7 @@ declare class GraphModel {
417
422
  /**
418
423
  * 重新设置画布的宽高
419
424
  */
420
- resize(width: number, height: number): void;
425
+ resize(width?: number, height?: number): void;
421
426
  /**
422
427
  * 清空画布
423
428
  */
@@ -129,7 +129,9 @@ declare class BaseEdgeModel implements IBaseModel {
129
129
  */
130
130
  getHistoryData(): EdgeData;
131
131
  setProperty(key: any, val: any): void;
132
+ deleteProperty(key: string): void;
132
133
  setProperties(properties: any): void;
134
+ changeEdgeId(id: string): void;
133
135
  setStyle(key: any, val: any): void;
134
136
  setStyles(styles: any): void;
135
137
  updateStyles(styles: any): void;
@@ -43,6 +43,7 @@ export default class BaseNodeModel implements IBaseNodeModel {
43
43
  isHovered: boolean;
44
44
  isDragging: boolean;
45
45
  isHitable: boolean;
46
+ isShowAnchor: boolean;
46
47
  draggable: boolean;
47
48
  visible: boolean;
48
49
  virtual: boolean;
@@ -141,7 +142,7 @@ export default class BaseNodeModel implements IBaseNodeModel {
141
142
  * 获取当前节点锚点拖出连线样式
142
143
  * @returns 自定义锚点拖出样式
143
144
  */
144
- getAnchorLineStyle(): import("../../constant/DefaultTheme").CommonTheme;
145
+ getAnchorLineStyle(anchorInfo: any): import("../../constant/DefaultTheme").CommonTheme;
145
146
  /**
146
147
  * @override 支持重写
147
148
  * 获取outline样式,重写可以定义此类型节点outline样式, 默认使用主题样式
@@ -187,15 +188,18 @@ export default class BaseNodeModel implements IBaseNodeModel {
187
188
  getAnchorInfo(anchorId: string): PointAnchor;
188
189
  addNodeMoveRules(fn: NodeMoveRule): void;
189
190
  move(deltaX: any, deltaY: any, isIgnoreRule?: boolean): boolean;
191
+ getMoveDistance(deltaX: number, deltaY: number, isIgnoreRule?: boolean): [number, number];
190
192
  moveTo(x: any, y: any, isIgnoreRule?: boolean): boolean;
191
193
  moveText(deltaX: any, deltaY: any): void;
192
194
  updateText(value: string): void;
193
195
  setSelected(flag?: boolean): void;
194
196
  setHovered(flag?: boolean): void;
197
+ setIsShowAnchor(flag?: boolean): void;
195
198
  setHitable(flag?: boolean): void;
196
199
  setElementState(state: number, additionStateData?: AdditionData): void;
197
200
  setProperty(key: any, val: any): void;
198
201
  setProperties(properties: any): void;
202
+ deleteProperty(key: string): void;
199
203
  setStyle(key: any, val: any): void;
200
204
  setStyles(styles: any): void;
201
205
  updateStyles(styles: any): void;
@@ -104,6 +104,17 @@ export declare type Definition = {
104
104
  * AnimationConfig: 配置部分动画开启
105
105
  */
106
106
  animation?: boolean | Partial<AnimationConfig>;
107
+ /**
108
+ * 节点间连线、连线变更时的边的生成规则
109
+ * @param sourceNode 起始节点数据
110
+ * @param targetNode 终止节点数据
111
+ * @param currentEdge 当前边的数据, 仅移动已有边的时候有值
112
+ *
113
+ * @return undefined: 使用默认边
114
+ * string: 自定义边类型
115
+ * any: 自定义边及其他数据
116
+ */
117
+ edgeGenerator?: (sourceNode: any, targetNode: any, currentEdge?: any) => string | any | undefined;
107
118
  [key: string]: any;
108
119
  } & EditConfigInterface;
109
120
  export interface GuardsTypes {
@@ -207,6 +218,17 @@ export declare function get(options: Definition): {
207
218
  * AnimationConfig: 配置部分动画开启
208
219
  */
209
220
  animation?: boolean | Partial<AnimationConfig>;
221
+ /**
222
+ * 节点间连线、连线变更时的边的生成规则
223
+ * @param sourceNode 起始节点数据
224
+ * @param targetNode 终止节点数据
225
+ * @param currentEdge 当前边的数据, 仅移动已有边的时候有值
226
+ *
227
+ * @return undefined: 使用默认边
228
+ * string: 自定义边类型
229
+ * any: 自定义边及其他数据
230
+ */
231
+ edgeGenerator?: (sourceNode: any, targetNode: any, currentEdge?: any) => any;
210
232
  } & EditConfigInterface;
211
233
  export declare const defaults: {
212
234
  background: boolean;
@@ -31,6 +31,9 @@ export declare type Point = {
31
31
  y: number;
32
32
  [key: string]: unknown;
33
33
  };
34
+ export declare type Vector2 = [number, number];
35
+ export declare type DirectionVectorNumber = 0 | 1 | -1;
36
+ export declare type DirectionVector2 = [DirectionVectorNumber, DirectionVectorNumber];
34
37
  /**
35
38
  * 锚点坐标
36
39
  * 为了方便计算
@@ -110,4 +110,10 @@ declare type Position = {
110
110
  y: number;
111
111
  };
112
112
  export declare const twoPointDistance: (source: Position, target: Position) => number;
113
+ /**
114
+ * 包装边生成函数
115
+ * @param graphModel graph model
116
+ * @param generator 用户自定义的边生成函数
117
+ */
118
+ export declare function createEdgeGenerator(graphModel: any, generator?: Function): (sourceNode: any, targetNode: any, currentEdge?: any) => any;
113
119
  export {};
@@ -0,0 +1,4 @@
1
+ import { DirectionVector2, Point } from '../type';
2
+ export declare const getDirectionVector: (point1: Point, point2: Point) => DirectionVector2;
3
+ export declare const isSameDirection: (v1: DirectionVector2, v2: DirectionVector2) => boolean;
4
+ export declare const isContraryDirection: (v1: DirectionVector2, v2: DirectionVector2) => boolean;
@@ -5,6 +5,8 @@ export declare type ArrowStyle = {
5
5
  fill?: string;
6
6
  strokeWidth?: number;
7
7
  offset: number;
8
+ refX?: number;
9
+ refY?: number;
8
10
  verticalLength: number;
9
11
  };
10
12
  declare type ArrowAttributesType = {
@@ -12,6 +12,10 @@ export default class BaseEdge extends Component<IProps> {
12
12
  contextMenuTime: number;
13
13
  clickTimer: number;
14
14
  getShape(): void;
15
+ /**
16
+ * 支持重写此方法来实现在连线上定义额外内容。
17
+ */
18
+ getExtraShape(): void;
15
19
  getTextStyle(): void;
16
20
  getText(): "" | h.JSX.Element;
17
21
  getArrowInfo(): ArrowInfo;
@@ -29,7 +33,7 @@ export default class BaseEdge extends Component<IProps> {
29
33
  handleContextMenu: (ev: MouseEvent) => void;
30
34
  handleMouseDown: (e: any) => void;
31
35
  handleMouseUp: (e: MouseEvent) => void;
32
- getIsDraging: () => boolean;
36
+ getIsDragging: () => boolean;
33
37
  toFront(): void;
34
38
  render(): h.JSX.Element;
35
39
  }
@@ -21,7 +21,7 @@ export default class PolylineEdge extends BaseEdge {
21
21
  }) => void;
22
22
  onDragEnd: () => void;
23
23
  beforeDragStart: (e: any, appendInfo: any) => void;
24
- getIsDraging: () => boolean;
24
+ getIsDragging: () => boolean;
25
25
  getEdge(): h.JSX.Element;
26
26
  getShape(): h.JSX.Element;
27
27
  getAnimation(): h.JSX.Element;