@logicflow/core 1.0.0-alpha.1 → 1.0.0-alpha.5

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.
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "LogicFlow core, to quickly build flowchart editor",
5
5
  "main": "dist/logic-flow.js",
6
6
  "unpkg": "dist/logic-flow.js",
7
7
  "jsdelivr": "dist/logic-flow.js",
8
- "module": "dis/logic-flow.es.js",
9
8
  "license": "Apache-2.0",
10
9
  "homepage": "http://logic-flow.org/",
11
10
  "types": "types/index.d.ts",
@@ -17,9 +16,8 @@
17
16
  "scripts": {
18
17
  "dev": "cross-env NODE_ENV=development webpack-dev-server --client-log-level warning --config scripts/webpack.config.dev.js",
19
18
  "clean": "rimraf dist lib esm cjs",
20
- "build": "npm run build:umd;npm run build:es",
19
+ "build": "npm run build:umd",
21
20
  "build:umd": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.build.js && cp -r src/style/ dist/style",
22
- "build:es": "cp -r scripts/logic-flow.es.js dist/",
23
21
  "build-analyse": "cross-env analyse=true npm run build",
24
22
  "types": "tsc -d --declarationDir ./types --outDir temp && rimraf temp",
25
23
  "lint": "eslint . --ext .ts,.tsx",
@@ -1,73 +1,14 @@
1
1
  import { ElementState } from '../constant/constant';
2
2
  import { TextConfig, AdditionData } from '../type';
3
3
  interface IBaseModel {
4
- /**
5
- * 节点或者连线的id.
6
- * 默认情况下,使用uuidv4生成。
7
- * 如果想要自定义,可以重写createId生成。
8
- */
9
4
  id: string;
10
- /**
11
- * 不可自定义
12
- * model对应的图形外观类型(eg: 圆形、矩形、多边形等)
13
- * 用于logicflow内部计算使用。
14
- */
15
5
  modelType: string;
16
- /**
17
- * 请勿直接修改属性,如果想要将一个节点类型修改为另一个类型。请使用
18
- * `lf.graphModel.changeEdgeType`和`lf.graphModel.changeNodeType`
19
- *
20
- * 流程图元素类型,自定义元素时对应的标识。
21
- * 在logicflow/core中对应着rect、circle、polyline这种。
22
- * 在实际项目中,我们会基于业务类型进行自定义type.
23
- * 例如BPMN应用场景,我们会定义开始节点的类型为bpmn:start-event
24
- *
25
- * 和modelType的区别是,type更多的是业务上的类型,而modelType则是外观上的类型。
26
- * 例如bpmnjs的开始节点和结束节点type分别为'bpmn:start-event'和'bpmn:end-event'。
27
- * 但是他们的modelType都是circle-node, 因为他们外观都是基于圆形自定义而来。
28
- */
29
6
  type: string;
30
- /**
31
- * 元素状态
32
- * 不同的状态对应着元素显示效果。
33
- * 请勿直接修改。
34
- * logicflow内部将元素状态分为5种:
35
- * DEFAULT = 1 默认显示
36
- * TEXT_EDIT = 2 此元素正在进行文本编辑
37
- * SHOW_MENU = 3, 显示菜单,废弃请使用菜单插件
38
- * ALLOW_CONNECT = 4, 此元素允许作为当前连线的目标节点
39
- * NOT_ALLOW_CONNECT = 5, 此元素不允许作为当前连线的目标节点
40
- */
41
7
  state: ElementState;
42
8
  additionStateData: AdditionData;
43
- /**
44
- * 元素上的文本
45
- * logicflow中存在两种文本
46
- * 一种是脱离连线和节点单独存在的文本
47
- * 一种是必须和连线、节点关联的文本。
48
- * 此属性控制的是第二种。
49
- * 节点和连线删除、调整的时候,其关联的文本也会对应删除、调整。
50
- */
51
9
  text: TextConfig;
52
- /**
53
- * 元素是否被选中
54
- */
55
10
  isSelected: boolean;
56
- /**
57
- * 元素堆叠是层级,默认情况下节点zIndex值为1,连线zIndex为0。
58
- * todo:写完善
59
- */
60
11
  zIndex: number;
61
- /**
62
- * 创建节点ID
63
- * 默认情况下,logicflow内部使用uuidv4生成id。
64
- * 在自定义节点的时候,可以重写此方法基于自己的规则生成id。
65
- * 注意,此方法必须是同步的。
66
- * 如果想要异步修改Id,建议删除此节点后再同一位置创建一个新的节点。
67
- * @overridable 可以重写
68
- * @returns string
69
- */
70
- createId(): string;
71
12
  move(deltaX: number, deltaY: number): void;
72
13
  moveText(deltaX: number, deltaY: number): void;
73
14
  updateText(value: string): void;
@@ -90,6 +90,10 @@ declare class GraphModel {
90
90
  nodes: import("../type").NodeData[];
91
91
  edges: import("../type").EdgeData[];
92
92
  };
93
+ modelToHistoryData(): false | {
94
+ nodes: any[];
95
+ edges: any[];
96
+ };
93
97
  getEdgeModel(edgeId: string): BaseEdgeModel;
94
98
  getElement(id: string): IBaseModel | undefined;
95
99
  getNodeEdges(nodeId: any): BaseEdgeModel[];
@@ -168,9 +172,8 @@ declare class GraphModel {
168
172
  * @param fn function
169
173
  */
170
174
  addNodeMoveRules(fn: NodeMoveRule): void;
171
- setDefaultEdgeType(type: string): void;
175
+ changeEdgeType(type: string): void;
172
176
  changeNodeType(id: any, type: string): void;
173
- changeEdgeType(id: any, type: any): void;
174
177
  setTheme(style: Style): void;
175
178
  clearData(): void;
176
179
  }
@@ -37,6 +37,7 @@ declare class BaseEdgeModel implements IBaseModel {
37
37
  zIndex: number;
38
38
  isSelected: boolean;
39
39
  isHovered: boolean;
40
+ isDragging: boolean;
40
41
  isHitable: boolean;
41
42
  hoverStroke: string;
42
43
  selectedStroke: string;
@@ -1,5 +1,5 @@
1
1
  import { ElementState, ModelType, ElementType } from '../../constant/constant';
2
- import { AdditionData, NodeData, NodeAttribute, NodeConfig, NodeMoveRule, Bounds, AnchorConfig, PointAnchor, AnchorsOffsetItem } from '../../type';
2
+ import { AdditionData, NodeData, NodeAttribute, NodeConfig, NodeMoveRule, Bounds, Point, AnchorConfig } from '../../type';
3
3
  import GraphModel from '../GraphModel';
4
4
  import { IBaseModel } from '../BaseModel';
5
5
  export declare type ConnectRule = {
@@ -10,14 +10,8 @@ export declare type ConnectRuleResult = {
10
10
  isAllPass: boolean;
11
11
  msg?: string;
12
12
  };
13
- interface IBaseNodeModel extends IBaseModel {
14
- /**
15
- * model基础类型,固定为node
16
- */
17
- readonly BaseType: ElementType.NODE;
18
- }
19
13
  export { BaseNodeModel };
20
- export default class BaseNodeModel implements IBaseNodeModel {
14
+ export default class BaseNodeModel implements IBaseModel {
21
15
  id: string;
22
16
  readonly BaseType = ElementType.NODE;
23
17
  modelType: ModelType;
@@ -52,9 +46,10 @@ export default class BaseNodeModel implements IBaseNodeModel {
52
46
  hoverOutlineStrokeDashArray: string;
53
47
  isSelected: boolean;
54
48
  isHovered: boolean;
49
+ isDragging: boolean;
55
50
  isHitable: boolean;
56
51
  zIndex: number;
57
- anchorsOffset: AnchorsOffsetItem[];
52
+ anchorsOffset: any[];
58
53
  state: number;
59
54
  text: {
60
55
  value: string;
@@ -65,39 +60,12 @@ export default class BaseNodeModel implements IBaseNodeModel {
65
60
  };
66
61
  draggable: boolean;
67
62
  constructor(data: NodeConfig, graphModel: GraphModel, type: any);
68
- /**
69
- * 初始化节点数据,不建议重写
70
- * 可以重写setAttributes来实现修改初始化功能
71
- * initNodeData和setAttributes的区别在于
72
- * initNodeData需要
73
- */
74
- protected initNodeData(data: any): void;
75
- /**
76
- * @overridable 支持重新
77
- * @returns string
78
- */
79
- createId(): string;
80
- /**
81
- * 初始化文本属性,对
82
- */
83
- private formatText;
84
- /**
85
- * 设置model初始化属性
86
- * 例如设置节点的宽度
87
- * @example
88
- *
89
- * setAttributes () {
90
- * this.width = 300
91
- * this.height = 200
92
- * }
93
- *
94
- * @overridable 支持重写
95
- */
63
+ initNodeData(data: any): void;
64
+ createId(): any;
65
+ formatText(data: any): void;
96
66
  setAttributes(): void;
97
67
  /**
98
- * 获取被保存时返回的数据
99
- * @overridable 支持重写
100
- * @returns NodeData
68
+ * 保存时获取的数据
101
69
  */
102
70
  getData(): NodeData;
103
71
  getProperties(): Record<string, any>;
@@ -118,20 +86,12 @@ export default class BaseNodeModel implements IBaseNodeModel {
118
86
  */
119
87
  isAllowMoveNode(deltaX: any, deltaY: any): boolean;
120
88
  getConnectedTargetRules(): ConnectRule[];
89
+ getAnchorsByOffset(): Point[];
121
90
  /**
122
- * @overridable 子类重写此方法设置锚点
123
- * @returns Point[] 锚点坐标构成的数组
124
- */
125
- getAnchorsByOffset(): PointAnchor[];
126
- /**
127
- * 获取节点默认情况下的锚点
128
- */
129
- getDetaultAnchor(): PointAnchor[];
130
- /**
131
- * 获取节点BBox
91
+ * 获取节点区域
132
92
  */
133
93
  getBounds(): Bounds;
134
- get anchors(): PointAnchor[];
94
+ get anchors(): Point[];
135
95
  addNodeMoveRules(fn: NodeMoveRule): void;
136
96
  move(deltaX: any, deltaY: any, isignoreRule?: boolean): void;
137
97
  moveTo(x: any, y: any, isignoreRule?: boolean): void;
@@ -1,3 +1,4 @@
1
+ import { Point } from '../../type';
1
2
  import BaseNodeModel from './BaseNodeModel';
2
3
  import { ModelType } from '../../constant/constant';
3
4
  import GraphModel from '../GraphModel';
@@ -7,11 +8,7 @@ declare class CircleNodeModel extends BaseNodeModel {
7
8
  constructor(data: any, graphModel: GraphModel);
8
9
  get width(): number;
9
10
  get height(): number;
10
- getDetaultAnchor(): {
11
- x: number;
12
- y: number;
13
- id: string;
14
- }[];
11
+ get anchors(): Point[];
15
12
  }
16
13
  export { CircleNodeModel };
17
14
  export default CircleNodeModel;
@@ -6,11 +6,6 @@ declare class PolygonNodeModel extends BaseNodeModel {
6
6
  modelType: ModelType;
7
7
  points: PointTuple[];
8
8
  constructor(data: any, graphModel: GraphModel);
9
- /**
10
- * 由于大多数情况下,我们初始化拿到的多边形坐标都是基于原点的(例如绘图工具到处的svg)。
11
- * 在logicflow中对多边形进行移动,我们不需要去更新points,
12
- * 而是去更新多边形中心点即可。
13
- */
14
9
  get pointsPosition(): Point[];
15
10
  get width(): number;
16
11
  get height(): number;
@@ -29,27 +29,6 @@ export declare type Point = {
29
29
  y: number;
30
30
  [key: string]: unknown;
31
31
  };
32
- /**
33
- * 锚点坐标
34
- * 为了方便计算
35
- * 锚点的位置都是相对于节点中心点的偏移量。
36
- */
37
- export declare type PointAnchor = {
38
- /**
39
- * 锚点x轴相对于中心点的偏移量
40
- */
41
- x: number;
42
- /**
43
- * 锚点y轴相对于中心点的偏移量
44
- */
45
- y: number;
46
- /**
47
- * 锚点Id
48
- */
49
- id?: string;
50
- [key: string]: unknown;
51
- };
52
- export declare type AnchorsOffsetItem = PointTuple | PointAnchor;
53
32
  export declare type Size = {
54
33
  width: number;
55
34
  height: number;
@@ -9,7 +9,6 @@ declare type IProps = {
9
9
  eventCenter: EventEmitter;
10
10
  };
11
11
  declare type Istate = {
12
- isDraging: boolean;
13
12
  isHovered: boolean;
14
13
  };
15
14
  declare type StyleAttribute = {
@@ -1,74 +0,0 @@
1
-
2
- /**
3
- * 由于logicflow本身基于preact、mobx、mobx-react编写。
4
- * 如果导出es module的形式,会在react项目中mobx-react会错误的使用react渲染。
5
- * 所以logicflow暂时不提供完善导出es module形式。
6
- */
7
- import {
8
- LogicFlow,
9
- LogicFlowUtil,
10
- h,
11
- observer,
12
- BaseNode,
13
- RectNode,
14
- CircleNode,
15
- PolygonNode,
16
- DiamondNode,
17
- EllipseNode,
18
- TextNode,
19
- HtmlNode,
20
- BaseEdge,
21
- LineEdge,
22
- PolylineEdge,
23
- BezierEdge,
24
- BaseEdgeModel,
25
- BezierEdgeModel,
26
- LineEdgeModel,
27
- PolylineEdgeModel,
28
- BaseNodeModel,
29
- CircleNodeModel,
30
- DiamondNodeModel,
31
- EllipseNodeModel,
32
- PolygonNodeModel,
33
- RectNodeModel,
34
- TextNodeModel,
35
- HtmlNodeModel,
36
- GraphModel,
37
- Arrow,
38
- Keyboard,
39
- } from './logic-flow';
40
-
41
- export {
42
- LogicFlow,
43
- LogicFlowUtil,
44
- h,
45
- observer,
46
- BaseNode,
47
- RectNode,
48
- CircleNode,
49
- PolygonNode,
50
- DiamondNode,
51
- EllipseNode,
52
- TextNode,
53
- HtmlNode,
54
- BaseEdge,
55
- LineEdge,
56
- PolylineEdge,
57
- BezierEdge,
58
- BaseEdgeModel,
59
- BezierEdgeModel,
60
- LineEdgeModel,
61
- PolylineEdgeModel,
62
- BaseNodeModel,
63
- CircleNodeModel,
64
- DiamondNodeModel,
65
- EllipseNodeModel,
66
- PolygonNodeModel,
67
- RectNodeModel,
68
- TextNodeModel,
69
- HtmlNodeModel,
70
- GraphModel,
71
- Arrow,
72
- Keyboard,
73
- }
74
- export default LogicFlow;