aldehyde 0.2.486 → 0.2.487

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.
Files changed (35) hide show
  1. package/lib/controls/entry-control.d.ts +1 -0
  2. package/lib/controls/entry-control.d.ts.map +1 -1
  3. package/lib/controls/entry-control.js +2 -0
  4. package/lib/controls/entry-control.js.map +1 -1
  5. package/lib/draw-canvas-edit/components/asset-bar/index.d.ts.map +1 -1
  6. package/lib/draw-canvas-edit/components/asset-bar/index.js +26 -7
  7. package/lib/draw-canvas-edit/components/asset-bar/index.js.map +1 -1
  8. package/lib/draw-canvas-edit/components/asset-bar/index.less +1 -1
  9. package/lib/draw-canvas-edit/components/render/handlers/drag-outside-handlers.d.ts.map +1 -1
  10. package/lib/draw-canvas-edit/components/render/handlers/drag-outside-handlers.js +9 -5
  11. package/lib/draw-canvas-edit/components/render/handlers/drag-outside-handlers.js.map +1 -1
  12. package/lib/draw-canvas-edit/components/render/index.d.ts.map +1 -1
  13. package/lib/draw-canvas-edit/components/render/index.js +1 -1
  14. package/lib/draw-canvas-edit/components/render/index.js.map +1 -1
  15. package/lib/module/dtmpl-edit-card.d.ts +1 -1
  16. package/lib/module/dtmpl-edit-card.d.ts.map +1 -1
  17. package/lib/module/dtmpl-edit-card.js +40 -7
  18. package/lib/module/dtmpl-edit-card.js.map +1 -1
  19. package/lib/module/dtmpl-edit-page.d.ts +1 -1
  20. package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
  21. package/lib/module/dtmpl-edit-page.js +40 -7
  22. package/lib/module/dtmpl-edit-page.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/aldehyde/controls/entry-control.tsx +3 -0
  25. package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.less +1 -1
  26. package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.tsx +19 -6
  27. package/src/aldehyde/draw-canvas-edit/components/render/draws/graph-draw.ts +249 -249
  28. package/src/aldehyde/draw-canvas-edit/components/render/draws/link-draw.ts +1414 -1414
  29. package/src/aldehyde/draw-canvas-edit/components/render/draws/preview-draw.ts +273 -273
  30. package/src/aldehyde/draw-canvas-edit/components/render/draws/ref-line-draw.ts +70 -70
  31. package/src/aldehyde/draw-canvas-edit/components/render/draws/ruler-draw.ts +165 -165
  32. package/src/aldehyde/draw-canvas-edit/components/render/handlers/drag-outside-handlers.ts +4 -0
  33. package/src/aldehyde/draw-canvas-edit/components/render/index.ts +0 -1
  34. package/src/aldehyde/module/dtmpl-edit-card.tsx +37 -7
  35. package/src/aldehyde/module/dtmpl-edit-page.tsx +38 -8
@@ -1,249 +1,249 @@
1
- import Konva from 'konva';
2
- import { GraphAnchor, BaseDraw, Draw, Render, AssetType } from '../types';
3
- import { Circle, Rect, Line, Bezier, Curve } from '../graphs';
4
- import { GraphDraw as DrawGraph, LinkDraw, PreviewDraw } from '../draws';
5
-
6
- // 矩形、圆、曲线等基础图形绘制
7
-
8
- export interface GraphDrawState {
9
- adjusting: boolean; // 调整中
10
- adjustGroupId: string; // 调整组ID
11
- adjustAnchor?: GraphAnchor; // 调整点
12
- startPointCurrent: Konva.Vector2d; // 鼠标按下调整点位置
13
- graphCurrent?: Konva.Group; // 图形 group
14
- graphCurrentSnap?: Konva.Group; // 图形 group 镜像,用于计算位置、大小的偏移
15
- }
16
-
17
- export interface GraphDrawOption { }
18
-
19
- export class GraphDraw extends BaseDraw implements Draw {
20
-
21
- option: {}
22
- on = {}
23
-
24
- state: GraphDrawState = {
25
- adjusting: false,
26
- adjustGroupId: '',
27
- startPointCurrent: { x: 0, y: 0 }
28
- }
29
-
30
- constructor(render: Render, layer: Konva.Layer, option: GraphDrawOption) {
31
- super(render, layer);
32
- this.option = option;
33
- this.group.name(this.constructor.name);
34
- }
35
-
36
- /**
37
- * 获取鼠标位置,并处理为 相对大小
38
- * @param attract 含磁贴计算
39
- * @returns
40
- */
41
- getStagePoint(attract = false) {
42
- const pos = this.render.stage.getPointerPosition();
43
- if (pos) {
44
- const stageState = this.render.getStageState();
45
- if (attract) {
46
- // 磁贴
47
- const { pos: transformerPos } = this.render.attractTool.attractPoint(pos);
48
- return {
49
- x: this.render.toStageValue(transformerPos.x - stageState.x),
50
- y: this.render.toStageValue(transformerPos.y - stageState.y)
51
- }
52
- } else {
53
- return {
54
- x: this.render.toStageValue(pos.x - stageState.x),
55
- y: this.render.toStageValue(pos.y - stageState.y)
56
- }
57
- }
58
- }
59
- return null;
60
- }
61
-
62
- override draw() {
63
- this.clear();
64
- // 所有图形
65
- const graphs = this.render.layer.find('.asset').filter((o) => o.attrs.assetType === AssetType.Graph) as Konva.Group[];
66
- for (const graph of graphs) {
67
- // 非选中状态才显示 调整点
68
- if (!graph.attrs.selected) {
69
- let anchorAndShadows: {
70
- anchor: GraphAnchor
71
- anchorShadow: Konva.Circle
72
- shape?: Konva.Shape | undefined
73
- }[] = [];
74
-
75
- switch (graph.attrs.graphType) { // 判断绘制的图形
76
- case "Circle":
77
- anchorAndShadows = Circle.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
78
- break;
79
- case "Rect":
80
- anchorAndShadows = Rect.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
81
- break;
82
- case "Line":
83
- anchorAndShadows = Line.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
84
- break;
85
- case "Curve":
86
- anchorAndShadows = Curve.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
87
- break;
88
- case "Bezier":
89
- anchorAndShadows = Bezier.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
90
- break;
91
- }
92
-
93
- for (const anchorAndShadow of anchorAndShadows) {
94
- const { shape } = anchorAndShadow;
95
- if (shape) {
96
- // 鼠标按下
97
- shape.on('mousedown', () => {
98
- const pos = this.getStagePoint(); // 获取鼠标坐标点
99
- if (pos) {
100
- this.state.adjusting = true;
101
- this.state.adjustAnchor = shape.attrs.anchor;
102
- this.state.adjustGroupId = graph.id();
103
- this.state.startPointCurrent = pos;
104
- this.state.graphCurrent = graph;
105
- this.state.graphCurrentSnap = graph.clone();
106
- graph.setAttr('adjusting', true);
107
- shape.setAttr('adjusting', true);
108
- if (this.state.adjustAnchor) {
109
- switch (shape.attrs.anchor?.type) {
110
- case "Line":
111
- // 使用 直线、折线 静态处理方法
112
- Line.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
113
- break;
114
- case "Curve":
115
- // 使用 直线、折线 静态处理方法
116
- Curve.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
117
- break;
118
- case "Bezier":
119
- // 使用 直线、折线 静态处理方法
120
- Bezier.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
121
- break;
122
- }
123
- }
124
- }
125
- })
126
-
127
- // 调整中
128
- this.render.stage.on('mousemove', () => {
129
- if (this.state.adjusting && this.state.graphCurrent && this.state.graphCurrentSnap) {
130
- if (shape.attrs.adjusting) {
131
- // 调整 圆/椭圆 图形
132
- const pos = this.getStagePoint(true);
133
- if (pos) {
134
- switch (shape.attrs.anchor?.type) {
135
- case "Circle":
136
- // 使用 圆/椭圆 静态处理方法
137
- Circle.adjust(
138
- this.render,
139
- graph,
140
- this.state.graphCurrentSnap,
141
- shape,
142
- anchorAndShadows,
143
- this.state.startPointCurrent,
144
- pos,
145
- graph.findOne('.hoverRect')
146
- );
147
- break;
148
- case "Rect":
149
- // 使用 圆/椭圆 静态处理方法
150
- Rect.adjust(
151
- this.render,
152
- graph,
153
- this.state.graphCurrentSnap,
154
- shape,
155
- anchorAndShadows,
156
- this.state.startPointCurrent,
157
- pos,
158
- graph.findOne('.hoverRect')
159
- );
160
- break;
161
- case "Line":
162
- // 使用 直线、折线 静态处理方法
163
- Line.adjust(
164
- this.render,
165
- graph,
166
- this.state.graphCurrentSnap,
167
- shape,
168
- anchorAndShadows,
169
- this.state.startPointCurrent,
170
- pos,
171
- graph.findOne('.hoverRect')
172
- );
173
- break;
174
- case "Curve":
175
- // 使用 直线、折线 静态处理方法
176
- Curve.adjust(
177
- this.render,
178
- graph,
179
- this.state.graphCurrentSnap,
180
- shape,
181
- anchorAndShadows,
182
- this.state.startPointCurrent,
183
- pos,
184
- graph.findOne('.hoverRect')
185
- );
186
- break;
187
- case "Bezier":
188
- // 使用 直线、折线 静态处理方法
189
- Bezier.adjust(
190
- this.render,
191
- graph,
192
- this.state.graphCurrentSnap,
193
- shape,
194
- anchorAndShadows,
195
- this.state.startPointCurrent,
196
- pos,
197
- graph.findOne('.hoverRect')
198
- );
199
- break;
200
- }
201
- // 重绘
202
- this.render.redraw([
203
- DrawGraph.name,
204
- LinkDraw.name,
205
- PreviewDraw.name
206
- ]);
207
- }
208
- }
209
- }
210
- });
211
-
212
- // 调整结束
213
- this.render.stage.on('mouseup', () => {
214
- graph.setAttr('adjusting', false);
215
- // 防止二次 hover 失效
216
- graph.setAttr('hover', false);
217
- graph.setAttr('hoverAnchor', false);
218
- if (this.state.adjusting) {
219
- // 更新历史
220
- this.render.updateHistory();
221
- // 重绘
222
- this.render.redraw([
223
- DrawGraph.name,
224
- LinkDraw.name,
225
- PreviewDraw.name
226
- ]);
227
- }
228
- this.state.adjusting = false;
229
- this.state.adjustAnchor = undefined;
230
- this.state.adjustGroupId = '';
231
- // 恢复显示所有 调整点
232
- for (const { shape } of anchorAndShadows) {
233
- if (shape) {
234
- shape.setAttr('adjusting', false);
235
- }
236
- }
237
- document.body.style.cursor = 'default';
238
- // 销毁 镜像
239
- this.state.graphCurrentSnap?.destroy();
240
- // 对齐线清除
241
- this.render.attractTool.alignLinesClear();
242
- })
243
- this.group.add(shape);
244
- }
245
- }
246
- }
247
- }
248
- }
249
- }
1
+ import Konva from 'konva';
2
+ import { GraphAnchor, BaseDraw, Draw, Render, AssetType } from '../types';
3
+ import { Circle, Rect, Line, Bezier, Curve } from '../graphs';
4
+ import { GraphDraw as DrawGraph, LinkDraw, PreviewDraw } from '../draws';
5
+
6
+ // 矩形、圆、曲线等基础图形绘制
7
+
8
+ export interface GraphDrawState {
9
+ adjusting: boolean; // 调整中
10
+ adjustGroupId: string; // 调整组ID
11
+ adjustAnchor?: GraphAnchor; // 调整点
12
+ startPointCurrent: Konva.Vector2d; // 鼠标按下调整点位置
13
+ graphCurrent?: Konva.Group; // 图形 group
14
+ graphCurrentSnap?: Konva.Group; // 图形 group 镜像,用于计算位置、大小的偏移
15
+ }
16
+
17
+ export interface GraphDrawOption { }
18
+
19
+ export class GraphDraw extends BaseDraw implements Draw {
20
+
21
+ option: {}
22
+ on = {}
23
+
24
+ state: GraphDrawState = {
25
+ adjusting: false,
26
+ adjustGroupId: '',
27
+ startPointCurrent: { x: 0, y: 0 }
28
+ }
29
+
30
+ constructor(render: Render, layer: Konva.Layer, option: GraphDrawOption) {
31
+ super(render, layer);
32
+ this.option = option;
33
+ this.group.name(this.constructor.name);
34
+ }
35
+
36
+ /**
37
+ * 获取鼠标位置,并处理为 相对大小
38
+ * @param attract 含磁贴计算
39
+ * @returns
40
+ */
41
+ getStagePoint(attract = false) {
42
+ const pos = this.render.stage.getPointerPosition();
43
+ if (pos) {
44
+ const stageState = this.render.getStageState();
45
+ if (attract) {
46
+ // 磁贴
47
+ const { pos: transformerPos } = this.render.attractTool.attractPoint(pos);
48
+ return {
49
+ x: this.render.toStageValue(transformerPos.x - stageState.x),
50
+ y: this.render.toStageValue(transformerPos.y - stageState.y)
51
+ }
52
+ } else {
53
+ return {
54
+ x: this.render.toStageValue(pos.x - stageState.x),
55
+ y: this.render.toStageValue(pos.y - stageState.y)
56
+ }
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+
62
+ override draw() {
63
+ this.clear();
64
+ // 所有图形
65
+ const graphs = this.render.layer.find('.asset').filter((o) => o.attrs.assetType === AssetType.Graph) as Konva.Group[];
66
+ for (const graph of graphs) {
67
+ // 非选中状态才显示 调整点
68
+ if (!graph.attrs.selected) {
69
+ let anchorAndShadows: {
70
+ anchor: GraphAnchor
71
+ anchorShadow: Konva.Circle
72
+ shape?: Konva.Shape | undefined
73
+ }[] = [];
74
+
75
+ switch (graph.attrs.graphType) { // 判断绘制的图形
76
+ case "Circle":
77
+ anchorAndShadows = Circle.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
78
+ break;
79
+ case "Rect":
80
+ anchorAndShadows = Rect.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
81
+ break;
82
+ case "Line":
83
+ anchorAndShadows = Line.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
84
+ break;
85
+ case "Curve":
86
+ anchorAndShadows = Curve.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
87
+ break;
88
+ case "Bezier":
89
+ anchorAndShadows = Bezier.draw(graph, this.render, this.state.adjustAnchor).anchorAndShadows;
90
+ break;
91
+ }
92
+
93
+ for (const anchorAndShadow of anchorAndShadows) {
94
+ const { shape } = anchorAndShadow;
95
+ if (shape) {
96
+ // 鼠标按下
97
+ shape.on('mousedown', () => {
98
+ const pos = this.getStagePoint(); // 获取鼠标坐标点
99
+ if (pos) {
100
+ this.state.adjusting = true;
101
+ this.state.adjustAnchor = shape.attrs.anchor;
102
+ this.state.adjustGroupId = graph.id();
103
+ this.state.startPointCurrent = pos;
104
+ this.state.graphCurrent = graph;
105
+ this.state.graphCurrentSnap = graph.clone();
106
+ graph.setAttr('adjusting', true);
107
+ shape.setAttr('adjusting', true);
108
+ if (this.state.adjustAnchor) {
109
+ switch (shape.attrs.anchor?.type) {
110
+ case "Line":
111
+ // 使用 直线、折线 静态处理方法
112
+ Line.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
113
+ break;
114
+ case "Curve":
115
+ // 使用 直线、折线 静态处理方法
116
+ Curve.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
117
+ break;
118
+ case "Bezier":
119
+ // 使用 直线、折线 静态处理方法
120
+ Bezier.adjustStart(this.render, graph, this.state.adjustAnchor, pos);
121
+ break;
122
+ }
123
+ }
124
+ }
125
+ })
126
+
127
+ // 调整中
128
+ this.render.stage.on('mousemove', () => {
129
+ if (this.state.adjusting && this.state.graphCurrent && this.state.graphCurrentSnap) {
130
+ if (shape.attrs.adjusting) {
131
+ // 调整 圆/椭圆 图形
132
+ const pos = this.getStagePoint(true);
133
+ if (pos) {
134
+ switch (shape.attrs.anchor?.type) {
135
+ case "Circle":
136
+ // 使用 圆/椭圆 静态处理方法
137
+ Circle.adjust(
138
+ this.render,
139
+ graph,
140
+ this.state.graphCurrentSnap,
141
+ shape,
142
+ anchorAndShadows,
143
+ this.state.startPointCurrent,
144
+ pos,
145
+ graph.findOne('.hoverRect')
146
+ );
147
+ break;
148
+ case "Rect":
149
+ // 使用 圆/椭圆 静态处理方法
150
+ Rect.adjust(
151
+ this.render,
152
+ graph,
153
+ this.state.graphCurrentSnap,
154
+ shape,
155
+ anchorAndShadows,
156
+ this.state.startPointCurrent,
157
+ pos,
158
+ graph.findOne('.hoverRect')
159
+ );
160
+ break;
161
+ case "Line":
162
+ // 使用 直线、折线 静态处理方法
163
+ Line.adjust(
164
+ this.render,
165
+ graph,
166
+ this.state.graphCurrentSnap,
167
+ shape,
168
+ anchorAndShadows,
169
+ this.state.startPointCurrent,
170
+ pos,
171
+ graph.findOne('.hoverRect')
172
+ );
173
+ break;
174
+ case "Curve":
175
+ // 使用 直线、折线 静态处理方法
176
+ Curve.adjust(
177
+ this.render,
178
+ graph,
179
+ this.state.graphCurrentSnap,
180
+ shape,
181
+ anchorAndShadows,
182
+ this.state.startPointCurrent,
183
+ pos,
184
+ graph.findOne('.hoverRect')
185
+ );
186
+ break;
187
+ case "Bezier":
188
+ // 使用 直线、折线 静态处理方法
189
+ Bezier.adjust(
190
+ this.render,
191
+ graph,
192
+ this.state.graphCurrentSnap,
193
+ shape,
194
+ anchorAndShadows,
195
+ this.state.startPointCurrent,
196
+ pos,
197
+ graph.findOne('.hoverRect')
198
+ );
199
+ break;
200
+ }
201
+ // 重绘
202
+ this.render.redraw([
203
+ DrawGraph.name,
204
+ LinkDraw.name,
205
+ PreviewDraw.name
206
+ ]);
207
+ }
208
+ }
209
+ }
210
+ });
211
+
212
+ // 调整结束
213
+ this.render.stage.on('mouseup', () => {
214
+ graph.setAttr('adjusting', false);
215
+ // 防止二次 hover 失效
216
+ graph.setAttr('hover', false);
217
+ graph.setAttr('hoverAnchor', false);
218
+ if (this.state.adjusting) {
219
+ // 更新历史
220
+ this.render.updateHistory();
221
+ // 重绘
222
+ this.render.redraw([
223
+ DrawGraph.name,
224
+ LinkDraw.name,
225
+ PreviewDraw.name
226
+ ]);
227
+ }
228
+ this.state.adjusting = false;
229
+ this.state.adjustAnchor = undefined;
230
+ this.state.adjustGroupId = '';
231
+ // 恢复显示所有 调整点
232
+ for (const { shape } of anchorAndShadows) {
233
+ if (shape) {
234
+ shape.setAttr('adjusting', false);
235
+ }
236
+ }
237
+ document.body.style.cursor = 'default';
238
+ // 销毁 镜像
239
+ this.state.graphCurrentSnap?.destroy();
240
+ // 对齐线清除
241
+ this.render.attractTool.alignLinesClear();
242
+ })
243
+ this.group.add(shape);
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }