aldehyde 0.2.516 → 0.2.518
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/lib/controls/auto-complete/index.d.ts.map +1 -1
- package/lib/controls/auto-complete/index.js +2 -4
- package/lib/controls/auto-complete/index.js.map +1 -1
- package/lib/controls/direct-file-view/index.d.ts.map +1 -1
- package/lib/controls/direct-file-view/index.js +4 -1
- package/lib/controls/direct-file-view/index.js.map +1 -1
- package/lib/controls/entry-control.d.ts.map +1 -1
- package/lib/controls/entry-control.js +4 -0
- package/lib/controls/entry-control.js.map +1 -1
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +99 -99
- package/lib/controls/view-control.d.ts.map +1 -1
- package/lib/controls/view-control.js +1 -0
- package/lib/controls/view-control.js.map +1 -1
- package/lib/detail/view/act-dtmpl-view.d.ts +2 -0
- package/lib/detail/view/act-dtmpl-view.d.ts.map +1 -1
- package/lib/detail/view/act-dtmpl-view.js +3 -2
- package/lib/detail/view/act-dtmpl-view.js.map +1 -1
- package/lib/detail/view/dtmpl-view.d.ts +11 -0
- package/lib/detail/view/dtmpl-view.d.ts.map +1 -1
- package/lib/detail/view/dtmpl-view.js +20 -17
- package/lib/detail/view/dtmpl-view.js.map +1 -1
- package/lib/detail/view/field-view-group.d.ts +9 -0
- package/lib/detail/view/field-view-group.d.ts.map +1 -1
- package/lib/detail/view/field-view-group.js +17 -15
- package/lib/detail/view/field-view-group.js.map +1 -1
- package/lib/detail/view/index.less +6 -0
- package/lib/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/lib/draw-canvas-edit/components/main-header/index.less +23 -23
- package/lib/form/dtmpl-form.d.ts +12 -1
- package/lib/form/dtmpl-form.d.ts.map +1 -1
- package/lib/form/dtmpl-form.js +35 -27
- package/lib/form/dtmpl-form.js.map +1 -1
- package/lib/form/form-Item-group.d.ts +9 -0
- package/lib/form/form-Item-group.d.ts.map +1 -1
- package/lib/form/form-Item-group.js +13 -3
- package/lib/form/form-Item-group.js.map +1 -1
- package/lib/list/card-list/card-list-item.d.ts.map +1 -1
- package/lib/list/card-list/card-list-item.js +28 -6
- package/lib/list/card-list/card-list-item.js.map +1 -1
- package/lib/lowcode-components/base-table/index.less +61 -61
- package/lib/lowcode-components/data-number/index.d.ts +2 -0
- package/lib/lowcode-components/data-number/index.d.ts.map +1 -1
- package/lib/lowcode-components/data-number/index.js +21 -1
- package/lib/lowcode-components/data-number/index.js.map +1 -1
- package/lib/lowcode-components/data-number/index.less +10 -10
- package/lib/lowcode-components/date-time/index.less +4 -4
- package/lib/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/lib/lowcode-components/line-chart/index.js +7 -7
- package/lib/lowcode-components/line-chart/index.js.map +1 -1
- package/lib/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/lib/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/lib/lowcode-components/text-scroller/index.less +28 -28
- package/lib/module/dtmpl-edit-page.d.ts +1 -0
- package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
- package/lib/module/dtmpl-edit-page.js +5 -5
- package/lib/module/dtmpl-edit-page.js.map +1 -1
- package/lib/module/dtmpl-view-card.d.ts +2 -0
- package/lib/module/dtmpl-view-card.d.ts.map +1 -1
- package/lib/module/dtmpl-view-card.js +7 -4
- package/lib/module/dtmpl-view-card.js.map +1 -1
- package/lib/module/dtmpl-view-drawer.d.ts +2 -0
- package/lib/module/dtmpl-view-drawer.d.ts.map +1 -1
- package/lib/module/dtmpl-view-drawer.js +3 -2
- package/lib/module/dtmpl-view-drawer.js.map +1 -1
- package/lib/module/dtmpl-view-modal.d.ts +2 -0
- package/lib/module/dtmpl-view-modal.d.ts.map +1 -1
- package/lib/module/dtmpl-view-modal.js +3 -2
- package/lib/module/dtmpl-view-modal.js.map +1 -1
- package/lib/module/ttmpl-table.d.ts.map +1 -1
- package/lib/module/ttmpl-table.js +1 -1
- package/lib/module/ttmpl-table.js.map +1 -1
- package/lib/routable/index.less +5 -0
- package/lib/routable/ltmpl-route.d.ts +1 -0
- package/lib/routable/ltmpl-route.d.ts.map +1 -1
- package/lib/routable/ltmpl-route.js +37 -7
- package/lib/routable/ltmpl-route.js.map +1 -1
- package/lib/routable/ttmpl-table-route.d.ts.map +1 -1
- package/lib/routable/ttmpl-table-route.js +2 -1
- package/lib/routable/ttmpl-table-route.js.map +1 -1
- package/lib/table/act-table.d.ts +3 -0
- package/lib/table/act-table.d.ts.map +1 -1
- package/lib/table/act-table.js +9 -6
- package/lib/table/act-table.js.map +1 -1
- package/lib/table/column/column-builder.d.ts.map +1 -1
- package/lib/table/column/column-builder.js +22 -10
- package/lib/table/column/column-builder.js.map +1 -1
- package/lib/table/pagination.js +1 -1
- package/lib/table/pagination.js.map +1 -1
- package/lib/table/relation-table.d.ts +5 -0
- package/lib/table/relation-table.d.ts.map +1 -1
- package/lib/table/relation-table.js +54 -10
- package/lib/table/relation-table.js.map +1 -1
- package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
- package/lib/tmpl/control-type-supportor.js +1 -0
- package/lib/tmpl/control-type-supportor.js.map +1 -1
- package/lib/tmpl/hcservice-v3.d.ts +2 -0
- package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
- package/lib/tmpl/hcservice-v3.js +26 -0
- package/lib/tmpl/hcservice-v3.js.map +1 -1
- package/lib/tmpl/interface.d.ts +8 -1
- package/lib/tmpl/interface.d.ts.map +1 -1
- package/lib/tmpl/interface.js.map +1 -1
- package/lib/units/index.d.ts +2 -0
- package/lib/units/index.d.ts.map +1 -1
- package/lib/units/index.js +45 -0
- package/lib/units/index.js.map +1 -1
- package/package.json +1 -1
- package/src/aldehyde/controls/auto-complete/index.tsx +4 -6
- package/src/aldehyde/controls/direct-file-view/index.tsx +4 -1
- package/src/aldehyde/controls/entry-control.tsx +4 -0
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +99 -99
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +156 -156
- package/src/aldehyde/controls/view-control.tsx +1 -0
- package/src/aldehyde/detail/view/act-dtmpl-view.tsx +4 -1
- package/src/aldehyde/detail/view/dtmpl-view.tsx +20 -26
- package/src/aldehyde/detail/view/field-view-group.tsx +20 -22
- package/src/aldehyde/detail/view/index.less +6 -0
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.tsx +110 -110
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.less +23 -23
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.tsx +263 -263
- package/src/aldehyde/draw-canvas-edit/components/render/draws/index.ts +7 -7
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/base-graph.ts +241 -241
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/circle.ts +699 -699
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/curve.ts +500 -500
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/index.ts +5 -5
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/line.ts +493 -493
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/rect.ts +680 -680
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/drag-handlers.ts +68 -68
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/graph-handlers.ts +113 -113
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/index.ts +9 -9
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/key-move-handlers.ts +49 -49
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/link-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/shutcut-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/text-handlers.ts +81 -81
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/zoom-handlers.ts +59 -59
- package/src/aldehyde/draw-canvas-edit/components/render/tools/align-tool.ts +89 -89
- package/src/aldehyde/draw-canvas-edit/components/render/tools/asset-tool.ts +154 -154
- package/src/aldehyde/draw-canvas-edit/components/render/tools/link-tool.ts +222 -222
- package/src/aldehyde/draw-canvas-edit/components/render/tools/z-index-tool.ts +224 -224
- package/src/aldehyde/draw-canvas-edit/components/render/utils/a-star.ts +116 -116
- package/src/aldehyde/draw-canvas-edit/components/render/utils/bezier-scene-func.ts +72 -72
- package/src/aldehyde/draw-canvas-edit/components/setting-form/imag-upload.tsx +119 -119
- package/src/aldehyde/form/dtmpl-form.tsx +59 -55
- package/src/aldehyde/form/form-Item-group.tsx +16 -5
- package/src/aldehyde/layout4/imgs/user.svg +26 -26
- package/src/aldehyde/list/card-list/card-list-item.tsx +26 -7
- package/src/aldehyde/lowcode-components/base-color-block/index.tsx +31 -31
- package/src/aldehyde/lowcode-components/base-table/index.less +61 -61
- package/src/aldehyde/lowcode-components/data-number/index.less +10 -10
- package/src/aldehyde/lowcode-components/data-number/index.tsx +22 -1
- package/src/aldehyde/lowcode-components/date-time/index.less +4 -4
- package/src/aldehyde/lowcode-components/date-time/index.tsx +64 -64
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.tsx +53 -53
- package/src/aldehyde/lowcode-components/line-chart/index.tsx +7 -7
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-controller.ts +64 -64
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-definition.ts +77 -77
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-designer-loader.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +144 -144
- package/src/aldehyde/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/controller.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/definition.ts +53 -53
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/index.tsx +15 -15
- package/src/aldehyde/lowcode-components/lowcode-view/component/layer-builder.tsx +98 -98
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.tsx +121 -121
- package/src/aldehyde/lowcode-components/placeholder-component/index.tsx +81 -81
- package/src/aldehyde/lowcode-components/text-scroller/index.less +28 -28
- package/src/aldehyde/lowcode-components/text-scroller/index.tsx +173 -173
- package/src/aldehyde/module/dtmpl-edit-page.tsx +10 -1
- package/src/aldehyde/module/dtmpl-view-card.tsx +39 -34
- package/src/aldehyde/module/dtmpl-view-drawer.tsx +4 -2
- package/src/aldehyde/module/dtmpl-view-modal.tsx +4 -2
- package/src/aldehyde/module/ttmpl-table.tsx +1 -0
- package/src/aldehyde/routable/index.less +5 -0
- package/src/aldehyde/routable/ltmpl-route.tsx +39 -4
- package/src/aldehyde/routable/ttmpl-table-route.tsx +3 -0
- package/src/aldehyde/table/act-table.tsx +11 -6
- package/src/aldehyde/table/column/column-builder.tsx +14 -3
- package/src/aldehyde/table/pagination.tsx +1 -1
- package/src/aldehyde/table/relation-table.tsx +77 -16
- package/src/aldehyde/tmpl/control-type-supportor.tsx +1 -0
- package/src/aldehyde/tmpl/hcservice-v3.tsx +23 -0
- package/src/aldehyde/tmpl/interface.tsx +9 -2
- package/src/aldehyde/units/index.tsx +44 -0
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
import Konva from 'konva';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
|
-
import { Render } from '../index';
|
|
4
|
-
import { GraphAnchor, LinkDrawPoint, AssetInfoPoint, GraphType, AssetType } from '../types';
|
|
5
|
-
import { GraphDraw } from '../draws';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 图形类
|
|
9
|
-
* 实例主要用于新建图形时,含新建同时的大小拖动。
|
|
10
|
-
* 静态方法主要用于新建之后,通过 调整点 调整的逻辑定义
|
|
11
|
-
*/
|
|
12
|
-
export abstract class BaseGraph {
|
|
13
|
-
/**
|
|
14
|
-
* 更新 图形 的 调整点 的 锚点位置
|
|
15
|
-
* @param width 图形 的 宽度
|
|
16
|
-
* @param height 图形 的 高度
|
|
17
|
-
* @param rotate 图形 的 旋转角度
|
|
18
|
-
* @param anchorShadows 图形 的 调整点 的 锚点
|
|
19
|
-
*/
|
|
20
|
-
static updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[]) {
|
|
21
|
-
console.log('请实现 updateAnchorShadows');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 更新 图形 的 连接点 的 锚点位置
|
|
26
|
-
* @param width 图形 的 宽度
|
|
27
|
-
* @param height 图形 的 高度
|
|
28
|
-
* @param rotate 图形 的 旋转角度
|
|
29
|
-
* @param anchors 图形 的 调整点 的 锚点
|
|
30
|
-
*/
|
|
31
|
-
static updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[]) {
|
|
32
|
-
console.log('请实现 updateLinkAnchorShadows');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 生成 调整点
|
|
37
|
-
* @param render 渲染实例
|
|
38
|
-
* @param graph 图形
|
|
39
|
-
* @param anchorAndShadows 调整点 及其 锚点
|
|
40
|
-
* @param adjustAnchor 正在操作的 调整点
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
static createAnchorShapes(render: Render, graph: Konva.Group, anchorAndShadows: { anchor: GraphAnchor, anchorShadow: Konva.Circle, shape?: Konva.Shape }[], adjustAnchor: GraphAnchor) {
|
|
44
|
-
console.log('请实现 createAnchorShapes');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 调整 图形
|
|
50
|
-
* @param render 渲染实例
|
|
51
|
-
* @param graph 图形
|
|
52
|
-
* @param graphSnap 图形 的 备份
|
|
53
|
-
* @param rect 当前 调整点
|
|
54
|
-
* @param rects 所有 调整点
|
|
55
|
-
* @param startPoint 鼠标按下位置
|
|
56
|
-
* @param endPoint 鼠标拖动位置
|
|
57
|
-
*/
|
|
58
|
-
static adjust(render: Render, graph: Konva.Group, graphSnap: Konva.Group, adjustShape: Konva.Shape, anchorAndShadows: { anchor: GraphAnchor; anchorShadow: Konva.Circle; shape?: Konva.Shape | undefined }[], startPoint: Konva.Vector2d, endPoint: Konva.Vector2d, hoverRect?: Konva.Rect, hoverSize?: { width: number; height: number }, hoverPos?: { x: number; y: number }) {
|
|
59
|
-
hoverRect?.position({
|
|
60
|
-
x: hoverPos?.x ?? 0,
|
|
61
|
-
y: hoverPos?.y ?? 0
|
|
62
|
-
});
|
|
63
|
-
hoverRect?.size({
|
|
64
|
-
width: hoverSize?.width ?? graph.width(),
|
|
65
|
-
height: hoverSize?.height ?? graph.height()
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor): { anchorAndShadows: { anchor: GraphAnchor; anchorShadow: Konva.Circle; shape?: Konva.Shape }[] } {
|
|
70
|
-
// 调整点 信息
|
|
71
|
-
const anchors = (graph.attrs.anchors ?? []) as GraphAnchor[];
|
|
72
|
-
// 调整点 锚点
|
|
73
|
-
const anchorShapes = graph.find(`.anchor`);
|
|
74
|
-
// 调整点 信息&锚点
|
|
75
|
-
const anchorAndShadows = anchors
|
|
76
|
-
.map((anchor) => ({
|
|
77
|
-
anchor,
|
|
78
|
-
anchorShadow: anchorShapes.find(
|
|
79
|
-
(shape) => shape.attrs.adjustType === anchor.adjustType
|
|
80
|
-
) as Konva.Circle
|
|
81
|
-
}))
|
|
82
|
-
.filter((o) => o.anchorShadow !== void 0);
|
|
83
|
-
return { anchorAndShadows };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected render: Render;
|
|
87
|
-
group: Konva.Group;
|
|
88
|
-
// 占用区域,用于识别 hover 态
|
|
89
|
-
hoverRect: Konva.Rect;
|
|
90
|
-
id: string; // 就是 group 的id
|
|
91
|
-
/**
|
|
92
|
-
* 鼠标按下位置
|
|
93
|
-
*/
|
|
94
|
-
protected dropPoint: Konva.Vector2d = { x: 0, y: 0 };
|
|
95
|
-
/**
|
|
96
|
-
* 调整点 定义
|
|
97
|
-
*/
|
|
98
|
-
protected anchors: GraphAnchor[] = [];
|
|
99
|
-
/**
|
|
100
|
-
* 调整点 的 锚点
|
|
101
|
-
*/
|
|
102
|
-
protected anchorShadows: Konva.Circle[] = [];
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 调整点 定义
|
|
106
|
-
*/
|
|
107
|
-
protected linkAnchors: LinkDrawPoint[] = [];
|
|
108
|
-
/**
|
|
109
|
-
* 连接点 的 锚点
|
|
110
|
-
*/
|
|
111
|
-
protected linkAnchorShadows: Konva.Circle[] = [];
|
|
112
|
-
|
|
113
|
-
constructor(
|
|
114
|
-
render: Render,
|
|
115
|
-
dropPoint: Konva.Vector2d,
|
|
116
|
-
config: {
|
|
117
|
-
anchors: GraphAnchor[]
|
|
118
|
-
linkAnchors: AssetInfoPoint[]
|
|
119
|
-
type: GraphType
|
|
120
|
-
}
|
|
121
|
-
) {
|
|
122
|
-
this.render = render;
|
|
123
|
-
this.dropPoint = dropPoint;
|
|
124
|
-
this.id = nanoid();
|
|
125
|
-
this.group = new Konva.Group({
|
|
126
|
-
id: this.id,
|
|
127
|
-
name: 'asset',
|
|
128
|
-
assetType: AssetType.Graph,
|
|
129
|
-
graphType: config.type,
|
|
130
|
-
draggable: true
|
|
131
|
-
});
|
|
132
|
-
this.hoverRect = new Konva.Rect({
|
|
133
|
-
name: 'hoverRect',
|
|
134
|
-
x: 0,
|
|
135
|
-
y: 0,
|
|
136
|
-
hitStrokeWidth: this.render.toStageValue(this.render.bgSize * 2 + 2)
|
|
137
|
-
});
|
|
138
|
-
// 调整点 定义
|
|
139
|
-
this.anchors = config.anchors.map((o) => ({
|
|
140
|
-
...o,
|
|
141
|
-
// 补充信息
|
|
142
|
-
name: 'anchor',
|
|
143
|
-
groupId: this.group.id(),
|
|
144
|
-
type: config.type
|
|
145
|
-
}));
|
|
146
|
-
// 记录在 group 中
|
|
147
|
-
this.group.setAttr('anchors', this.anchors);
|
|
148
|
-
// 新建 调整点 的 锚点
|
|
149
|
-
for (const anchor of this.anchors) {
|
|
150
|
-
const circle = new Konva.Circle({
|
|
151
|
-
adjustType: anchor.adjustType,
|
|
152
|
-
anchorType: anchor.type,
|
|
153
|
-
name: anchor.name,
|
|
154
|
-
radius: 0
|
|
155
|
-
});
|
|
156
|
-
this.anchorShadows.push(circle);
|
|
157
|
-
this.group.add(circle);
|
|
158
|
-
}
|
|
159
|
-
// 连接点 定义
|
|
160
|
-
this.linkAnchors = config.linkAnchors.map(
|
|
161
|
-
(o) =>
|
|
162
|
-
({
|
|
163
|
-
...o,
|
|
164
|
-
id: nanoid(),
|
|
165
|
-
groupId: this.group.id(),
|
|
166
|
-
visible: false,
|
|
167
|
-
pairs: [],
|
|
168
|
-
direction: o.direction,
|
|
169
|
-
alias: o.alias
|
|
170
|
-
}) as LinkDrawPoint
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
// 连接点信息
|
|
174
|
-
this.group.setAttrs({ points: this.linkAnchors });
|
|
175
|
-
// 新建 连接点 的 锚点
|
|
176
|
-
for (const point of this.linkAnchors) {
|
|
177
|
-
const circle = new Konva.Circle({
|
|
178
|
-
name: 'link-anchor',
|
|
179
|
-
id: point.id,
|
|
180
|
-
x: point.x,
|
|
181
|
-
y: point.y,
|
|
182
|
-
radius: this.render.toStageValue(1),
|
|
183
|
-
stroke: 'rgba(0,0,255,1)',
|
|
184
|
-
strokeWidth: this.render.toStageValue(2),
|
|
185
|
-
visible: false,
|
|
186
|
-
direction: point.direction,
|
|
187
|
-
alias: point.alias
|
|
188
|
-
});
|
|
189
|
-
this.linkAnchorShadows.push(circle);
|
|
190
|
-
this.group.add(circle);
|
|
191
|
-
}
|
|
192
|
-
this.render.layer.add(this.group);
|
|
193
|
-
this.render.redraw([GraphDraw.NAME]);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* 调整进行时
|
|
198
|
-
* @param point 鼠标位置 相对位置
|
|
199
|
-
*/
|
|
200
|
-
abstract drawMove(point: Konva.Vector2d): void;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* 调整结束
|
|
204
|
-
*/
|
|
205
|
-
drawEnd(size?: { width: number; height: number }, pos?: { x: number; y: number }): void {
|
|
206
|
-
this.hoverRect?.position({ x: pos?.x ?? 0, y: pos?.y ?? 0 });
|
|
207
|
-
this.hoverRect.size({ width: size?.width ?? this.group.width(), height: size?.height ?? this.group.height() });
|
|
208
|
-
this.hoverRect.on('mouseenter', () => {
|
|
209
|
-
// 防止进入调整点,重复处理
|
|
210
|
-
if (!this.group.attrs.hoverAnchor) {
|
|
211
|
-
this.group.setAttr('hover', true);
|
|
212
|
-
this.render.redraw([GraphDraw.NAME]);
|
|
213
|
-
}
|
|
214
|
-
setTimeout(() => {
|
|
215
|
-
// 调整产生 redraw,导致离开调整点不触发其 mouseleave(进入其他元素区域除外)
|
|
216
|
-
// 在此静态补充“离开调整点”
|
|
217
|
-
// 不影响正常处理(调整点会不停 hoverAnchor = true)
|
|
218
|
-
this.group.setAttr('hoverAnchor', false);
|
|
219
|
-
})
|
|
220
|
-
// 显示 连接点
|
|
221
|
-
this.render.linkTool.pointsVisible(true, this.group);
|
|
222
|
-
})
|
|
223
|
-
this.hoverRect.on('mouseleave', () => {
|
|
224
|
-
// 延迟事件,使调整点的 mouseleave 优先
|
|
225
|
-
setTimeout(() => {
|
|
226
|
-
// 防止进入调整点,重复处理
|
|
227
|
-
// 补充 2,快速调整会漏掉
|
|
228
|
-
if (!this.group.attrs.hoverAnchor) {
|
|
229
|
-
this.group.setAttr('hover', false);
|
|
230
|
-
this.group.setAttr('hoverAnchor', false);
|
|
231
|
-
this.render.redraw([GraphDraw.NAME]);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
// 隐藏 连接点
|
|
235
|
-
this.render.linkTool.pointsVisible(false, this.group);
|
|
236
|
-
// 隐藏 hover 框
|
|
237
|
-
this.group.findOne('#hoverRect')?.visible(false);
|
|
238
|
-
})
|
|
239
|
-
this.group.add(this.hoverRect);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
|
+
import { Render } from '../index';
|
|
4
|
+
import { GraphAnchor, LinkDrawPoint, AssetInfoPoint, GraphType, AssetType } from '../types';
|
|
5
|
+
import { GraphDraw } from '../draws';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 图形类
|
|
9
|
+
* 实例主要用于新建图形时,含新建同时的大小拖动。
|
|
10
|
+
* 静态方法主要用于新建之后,通过 调整点 调整的逻辑定义
|
|
11
|
+
*/
|
|
12
|
+
export abstract class BaseGraph {
|
|
13
|
+
/**
|
|
14
|
+
* 更新 图形 的 调整点 的 锚点位置
|
|
15
|
+
* @param width 图形 的 宽度
|
|
16
|
+
* @param height 图形 的 高度
|
|
17
|
+
* @param rotate 图形 的 旋转角度
|
|
18
|
+
* @param anchorShadows 图形 的 调整点 的 锚点
|
|
19
|
+
*/
|
|
20
|
+
static updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[]) {
|
|
21
|
+
console.log('请实现 updateAnchorShadows');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 更新 图形 的 连接点 的 锚点位置
|
|
26
|
+
* @param width 图形 的 宽度
|
|
27
|
+
* @param height 图形 的 高度
|
|
28
|
+
* @param rotate 图形 的 旋转角度
|
|
29
|
+
* @param anchors 图形 的 调整点 的 锚点
|
|
30
|
+
*/
|
|
31
|
+
static updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[]) {
|
|
32
|
+
console.log('请实现 updateLinkAnchorShadows');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 生成 调整点
|
|
37
|
+
* @param render 渲染实例
|
|
38
|
+
* @param graph 图形
|
|
39
|
+
* @param anchorAndShadows 调整点 及其 锚点
|
|
40
|
+
* @param adjustAnchor 正在操作的 调整点
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
static createAnchorShapes(render: Render, graph: Konva.Group, anchorAndShadows: { anchor: GraphAnchor, anchorShadow: Konva.Circle, shape?: Konva.Shape }[], adjustAnchor: GraphAnchor) {
|
|
44
|
+
console.log('请实现 createAnchorShapes');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 调整 图形
|
|
50
|
+
* @param render 渲染实例
|
|
51
|
+
* @param graph 图形
|
|
52
|
+
* @param graphSnap 图形 的 备份
|
|
53
|
+
* @param rect 当前 调整点
|
|
54
|
+
* @param rects 所有 调整点
|
|
55
|
+
* @param startPoint 鼠标按下位置
|
|
56
|
+
* @param endPoint 鼠标拖动位置
|
|
57
|
+
*/
|
|
58
|
+
static adjust(render: Render, graph: Konva.Group, graphSnap: Konva.Group, adjustShape: Konva.Shape, anchorAndShadows: { anchor: GraphAnchor; anchorShadow: Konva.Circle; shape?: Konva.Shape | undefined }[], startPoint: Konva.Vector2d, endPoint: Konva.Vector2d, hoverRect?: Konva.Rect, hoverSize?: { width: number; height: number }, hoverPos?: { x: number; y: number }) {
|
|
59
|
+
hoverRect?.position({
|
|
60
|
+
x: hoverPos?.x ?? 0,
|
|
61
|
+
y: hoverPos?.y ?? 0
|
|
62
|
+
});
|
|
63
|
+
hoverRect?.size({
|
|
64
|
+
width: hoverSize?.width ?? graph.width(),
|
|
65
|
+
height: hoverSize?.height ?? graph.height()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor): { anchorAndShadows: { anchor: GraphAnchor; anchorShadow: Konva.Circle; shape?: Konva.Shape }[] } {
|
|
70
|
+
// 调整点 信息
|
|
71
|
+
const anchors = (graph.attrs.anchors ?? []) as GraphAnchor[];
|
|
72
|
+
// 调整点 锚点
|
|
73
|
+
const anchorShapes = graph.find(`.anchor`);
|
|
74
|
+
// 调整点 信息&锚点
|
|
75
|
+
const anchorAndShadows = anchors
|
|
76
|
+
.map((anchor) => ({
|
|
77
|
+
anchor,
|
|
78
|
+
anchorShadow: anchorShapes.find(
|
|
79
|
+
(shape) => shape.attrs.adjustType === anchor.adjustType
|
|
80
|
+
) as Konva.Circle
|
|
81
|
+
}))
|
|
82
|
+
.filter((o) => o.anchorShadow !== void 0);
|
|
83
|
+
return { anchorAndShadows };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected render: Render;
|
|
87
|
+
group: Konva.Group;
|
|
88
|
+
// 占用区域,用于识别 hover 态
|
|
89
|
+
hoverRect: Konva.Rect;
|
|
90
|
+
id: string; // 就是 group 的id
|
|
91
|
+
/**
|
|
92
|
+
* 鼠标按下位置
|
|
93
|
+
*/
|
|
94
|
+
protected dropPoint: Konva.Vector2d = { x: 0, y: 0 };
|
|
95
|
+
/**
|
|
96
|
+
* 调整点 定义
|
|
97
|
+
*/
|
|
98
|
+
protected anchors: GraphAnchor[] = [];
|
|
99
|
+
/**
|
|
100
|
+
* 调整点 的 锚点
|
|
101
|
+
*/
|
|
102
|
+
protected anchorShadows: Konva.Circle[] = [];
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 调整点 定义
|
|
106
|
+
*/
|
|
107
|
+
protected linkAnchors: LinkDrawPoint[] = [];
|
|
108
|
+
/**
|
|
109
|
+
* 连接点 的 锚点
|
|
110
|
+
*/
|
|
111
|
+
protected linkAnchorShadows: Konva.Circle[] = [];
|
|
112
|
+
|
|
113
|
+
constructor(
|
|
114
|
+
render: Render,
|
|
115
|
+
dropPoint: Konva.Vector2d,
|
|
116
|
+
config: {
|
|
117
|
+
anchors: GraphAnchor[]
|
|
118
|
+
linkAnchors: AssetInfoPoint[]
|
|
119
|
+
type: GraphType
|
|
120
|
+
}
|
|
121
|
+
) {
|
|
122
|
+
this.render = render;
|
|
123
|
+
this.dropPoint = dropPoint;
|
|
124
|
+
this.id = nanoid();
|
|
125
|
+
this.group = new Konva.Group({
|
|
126
|
+
id: this.id,
|
|
127
|
+
name: 'asset',
|
|
128
|
+
assetType: AssetType.Graph,
|
|
129
|
+
graphType: config.type,
|
|
130
|
+
draggable: true
|
|
131
|
+
});
|
|
132
|
+
this.hoverRect = new Konva.Rect({
|
|
133
|
+
name: 'hoverRect',
|
|
134
|
+
x: 0,
|
|
135
|
+
y: 0,
|
|
136
|
+
hitStrokeWidth: this.render.toStageValue(this.render.bgSize * 2 + 2)
|
|
137
|
+
});
|
|
138
|
+
// 调整点 定义
|
|
139
|
+
this.anchors = config.anchors.map((o) => ({
|
|
140
|
+
...o,
|
|
141
|
+
// 补充信息
|
|
142
|
+
name: 'anchor',
|
|
143
|
+
groupId: this.group.id(),
|
|
144
|
+
type: config.type
|
|
145
|
+
}));
|
|
146
|
+
// 记录在 group 中
|
|
147
|
+
this.group.setAttr('anchors', this.anchors);
|
|
148
|
+
// 新建 调整点 的 锚点
|
|
149
|
+
for (const anchor of this.anchors) {
|
|
150
|
+
const circle = new Konva.Circle({
|
|
151
|
+
adjustType: anchor.adjustType,
|
|
152
|
+
anchorType: anchor.type,
|
|
153
|
+
name: anchor.name,
|
|
154
|
+
radius: 0
|
|
155
|
+
});
|
|
156
|
+
this.anchorShadows.push(circle);
|
|
157
|
+
this.group.add(circle);
|
|
158
|
+
}
|
|
159
|
+
// 连接点 定义
|
|
160
|
+
this.linkAnchors = config.linkAnchors.map(
|
|
161
|
+
(o) =>
|
|
162
|
+
({
|
|
163
|
+
...o,
|
|
164
|
+
id: nanoid(),
|
|
165
|
+
groupId: this.group.id(),
|
|
166
|
+
visible: false,
|
|
167
|
+
pairs: [],
|
|
168
|
+
direction: o.direction,
|
|
169
|
+
alias: o.alias
|
|
170
|
+
}) as LinkDrawPoint
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// 连接点信息
|
|
174
|
+
this.group.setAttrs({ points: this.linkAnchors });
|
|
175
|
+
// 新建 连接点 的 锚点
|
|
176
|
+
for (const point of this.linkAnchors) {
|
|
177
|
+
const circle = new Konva.Circle({
|
|
178
|
+
name: 'link-anchor',
|
|
179
|
+
id: point.id,
|
|
180
|
+
x: point.x,
|
|
181
|
+
y: point.y,
|
|
182
|
+
radius: this.render.toStageValue(1),
|
|
183
|
+
stroke: 'rgba(0,0,255,1)',
|
|
184
|
+
strokeWidth: this.render.toStageValue(2),
|
|
185
|
+
visible: false,
|
|
186
|
+
direction: point.direction,
|
|
187
|
+
alias: point.alias
|
|
188
|
+
});
|
|
189
|
+
this.linkAnchorShadows.push(circle);
|
|
190
|
+
this.group.add(circle);
|
|
191
|
+
}
|
|
192
|
+
this.render.layer.add(this.group);
|
|
193
|
+
this.render.redraw([GraphDraw.NAME]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 调整进行时
|
|
198
|
+
* @param point 鼠标位置 相对位置
|
|
199
|
+
*/
|
|
200
|
+
abstract drawMove(point: Konva.Vector2d): void;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 调整结束
|
|
204
|
+
*/
|
|
205
|
+
drawEnd(size?: { width: number; height: number }, pos?: { x: number; y: number }): void {
|
|
206
|
+
this.hoverRect?.position({ x: pos?.x ?? 0, y: pos?.y ?? 0 });
|
|
207
|
+
this.hoverRect.size({ width: size?.width ?? this.group.width(), height: size?.height ?? this.group.height() });
|
|
208
|
+
this.hoverRect.on('mouseenter', () => {
|
|
209
|
+
// 防止进入调整点,重复处理
|
|
210
|
+
if (!this.group.attrs.hoverAnchor) {
|
|
211
|
+
this.group.setAttr('hover', true);
|
|
212
|
+
this.render.redraw([GraphDraw.NAME]);
|
|
213
|
+
}
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
// 调整产生 redraw,导致离开调整点不触发其 mouseleave(进入其他元素区域除外)
|
|
216
|
+
// 在此静态补充“离开调整点”
|
|
217
|
+
// 不影响正常处理(调整点会不停 hoverAnchor = true)
|
|
218
|
+
this.group.setAttr('hoverAnchor', false);
|
|
219
|
+
})
|
|
220
|
+
// 显示 连接点
|
|
221
|
+
this.render.linkTool.pointsVisible(true, this.group);
|
|
222
|
+
})
|
|
223
|
+
this.hoverRect.on('mouseleave', () => {
|
|
224
|
+
// 延迟事件,使调整点的 mouseleave 优先
|
|
225
|
+
setTimeout(() => {
|
|
226
|
+
// 防止进入调整点,重复处理
|
|
227
|
+
// 补充 2,快速调整会漏掉
|
|
228
|
+
if (!this.group.attrs.hoverAnchor) {
|
|
229
|
+
this.group.setAttr('hover', false);
|
|
230
|
+
this.group.setAttr('hoverAnchor', false);
|
|
231
|
+
this.render.redraw([GraphDraw.NAME]);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
// 隐藏 连接点
|
|
235
|
+
this.render.linkTool.pointsVisible(false, this.group);
|
|
236
|
+
// 隐藏 hover 框
|
|
237
|
+
this.group.findOne('#hoverRect')?.visible(false);
|
|
238
|
+
})
|
|
239
|
+
this.group.add(this.hoverRect);
|
|
240
|
+
}
|
|
241
|
+
}
|