@flowgram.ai/minimap-plugin 0.1.0-alpha.3 → 0.1.0-alpha.30
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/dist/esm/index.js +192 -159
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +40 -14
- package/dist/index.d.ts +40 -14
- package/dist/index.js +187 -163
- package/dist/index.js.map +1 -1
- package/package.json +15 -18
package/dist/esm/index.js
CHANGED
|
@@ -11,132 +11,21 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
|
|
12
12
|
// src/component.tsx
|
|
13
13
|
import React, { useEffect, useRef, useState } from "react";
|
|
14
|
-
|
|
15
|
-
// src/constant.ts
|
|
16
|
-
var MinimapDefaultCanvasStyle = {
|
|
17
|
-
canvasWidth: 250,
|
|
18
|
-
canvasHeight: 250,
|
|
19
|
-
canvasPadding: 50,
|
|
20
|
-
canvasBackground: "rgba(242, 243, 245, 1)",
|
|
21
|
-
canvasBorderRadius: 10,
|
|
22
|
-
viewportBackground: "rgba(255, 255, 255, 1)",
|
|
23
|
-
viewportBorderRadius: 4,
|
|
24
|
-
viewportBorderColor: "rgba(6, 7, 9, 0.10)",
|
|
25
|
-
viewportBorderWidth: 1,
|
|
26
|
-
viewportBorderDashLength: void 0,
|
|
27
|
-
nodeColor: "rgba(0, 0, 0, 0.10)",
|
|
28
|
-
nodeBorderRadius: 2,
|
|
29
|
-
nodeBorderWidth: 0.145,
|
|
30
|
-
nodeBorderColor: "rgba(6, 7, 9, 0.10)",
|
|
31
|
-
overlayColor: "rgba(255, 255, 255, 0.55)"
|
|
32
|
-
};
|
|
33
|
-
var MinimapDefaultInactiveStyle = {
|
|
34
|
-
scale: 0.7,
|
|
35
|
-
opacity: 1,
|
|
36
|
-
translateX: 15,
|
|
37
|
-
translateY: 15
|
|
38
|
-
};
|
|
39
|
-
var MinimapDefaultOptions = {
|
|
40
|
-
canvasStyle: MinimapDefaultCanvasStyle,
|
|
41
|
-
canvasClassName: "gedit-minimap-canvas",
|
|
42
|
-
enableActiveDebounce: false,
|
|
43
|
-
enableInactiveDebounce: true,
|
|
44
|
-
enableDisplayAllNodes: false,
|
|
45
|
-
activeDebounceTime: 0,
|
|
46
|
-
inactiveDebounceTime: 5
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/component.tsx
|
|
50
|
-
var MinimapRender = (props) => {
|
|
51
|
-
const {
|
|
52
|
-
service,
|
|
53
|
-
panelStyles = {},
|
|
54
|
-
containerStyles = {},
|
|
55
|
-
inactiveStyle: customInactiveStyle = {}
|
|
56
|
-
} = props;
|
|
57
|
-
const inactiveStyle = {
|
|
58
|
-
...MinimapDefaultInactiveStyle,
|
|
59
|
-
...customInactiveStyle
|
|
60
|
-
};
|
|
61
|
-
const panelRef = useRef(null);
|
|
62
|
-
const [activated, setActivated] = useState(false);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
const canvasContainer = panelRef.current;
|
|
65
|
-
if (canvasContainer && service.canvas) {
|
|
66
|
-
canvasContainer.appendChild(service.canvas);
|
|
67
|
-
}
|
|
68
|
-
const disposer = service.onActive((activate) => {
|
|
69
|
-
setActivated(activate);
|
|
70
|
-
});
|
|
71
|
-
return () => {
|
|
72
|
-
disposer.dispose();
|
|
73
|
-
};
|
|
74
|
-
}, []);
|
|
75
|
-
const scale = activated ? 1 : inactiveStyle.scale;
|
|
76
|
-
const opacity = activated ? 1 : inactiveStyle.opacity;
|
|
77
|
-
const translateX = activated ? 0 : inactiveStyle.translateX;
|
|
78
|
-
const translateY = activated ? 0 : inactiveStyle.translateY;
|
|
79
|
-
return /* @__PURE__ */ React.createElement(
|
|
80
|
-
"div",
|
|
81
|
-
{
|
|
82
|
-
className: "minimap-container",
|
|
83
|
-
style: {
|
|
84
|
-
position: "fixed",
|
|
85
|
-
right: 30,
|
|
86
|
-
bottom: 70,
|
|
87
|
-
transition: "all 0.3s ease",
|
|
88
|
-
// 添加过渡效果
|
|
89
|
-
transform: `scale(${scale}) translate(${translateX}px, ${translateY}px)`,
|
|
90
|
-
opacity,
|
|
91
|
-
transformOrigin: "bottom right",
|
|
92
|
-
// 设置变换的原点
|
|
93
|
-
...containerStyles
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
/* @__PURE__ */ React.createElement(
|
|
97
|
-
"div",
|
|
98
|
-
{
|
|
99
|
-
className: "minimap-panel",
|
|
100
|
-
style: {
|
|
101
|
-
display: "flex",
|
|
102
|
-
width: "100%",
|
|
103
|
-
height: "100%",
|
|
104
|
-
borderRadius: "10px",
|
|
105
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
106
|
-
border: "0.572px solid rgba(6, 7, 9, 0.10)",
|
|
107
|
-
overflow: "hidden",
|
|
108
|
-
boxShadow: "0px 2.289px 6.867px 0px rgba(0, 0, 0, 0.08), 0px 4.578px 13.733px 0px rgba(0, 0, 0, 0.04)",
|
|
109
|
-
padding: 8,
|
|
110
|
-
...panelStyles
|
|
111
|
-
},
|
|
112
|
-
"data-flow-editor-selectable": "false",
|
|
113
|
-
ref: panelRef,
|
|
114
|
-
onMouseEnter: () => {
|
|
115
|
-
service.setActivate(true);
|
|
116
|
-
},
|
|
117
|
-
onMouseLeave: () => {
|
|
118
|
-
service.setActivate(false);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// src/create-plugin.ts
|
|
126
|
-
import { definePluginCreator } from "@flowgram.ai/core";
|
|
14
|
+
import { usePlaygroundContainer } from "@flowgram.ai/core";
|
|
127
15
|
|
|
128
16
|
// src/service.ts
|
|
129
|
-
import {
|
|
17
|
+
import { throttle } from "lodash-es";
|
|
130
18
|
import { inject, injectable } from "inversify";
|
|
131
19
|
import { DisposableCollection, Rectangle } from "@flowgram.ai/utils";
|
|
132
20
|
import { FlowNodeTransformData } from "@flowgram.ai/document";
|
|
133
21
|
import { FlowNodeBaseType } from "@flowgram.ai/document";
|
|
134
22
|
import { FlowDocument } from "@flowgram.ai/document";
|
|
135
|
-
import {
|
|
23
|
+
import { MouseTouchEvent, PlaygroundConfigEntity } from "@flowgram.ai/core";
|
|
136
24
|
|
|
137
25
|
// src/draw.ts
|
|
138
26
|
var MinimapDraw;
|
|
139
27
|
((MinimapDraw2) => {
|
|
28
|
+
const isRectValid = (rect) => rect.width > 0 && rect.height > 0;
|
|
140
29
|
MinimapDraw2.clear = (params) => {
|
|
141
30
|
const { canvas, context } = params;
|
|
142
31
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
@@ -148,12 +37,18 @@ var MinimapDraw;
|
|
|
148
37
|
};
|
|
149
38
|
MinimapDraw2.rectangle = (params) => {
|
|
150
39
|
const { context, rect, color } = params;
|
|
40
|
+
if (!isRectValid(rect)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
151
43
|
context.fillStyle = color;
|
|
152
44
|
context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
153
45
|
};
|
|
154
46
|
MinimapDraw2.roundRectangle = (params) => {
|
|
155
47
|
const { context, rect, color, radius, borderColor, borderDashLength, borderWidth = 0 } = params;
|
|
156
48
|
const { x, y, width, height } = rect;
|
|
49
|
+
if (!isRectValid(rect)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
157
52
|
context.beginPath();
|
|
158
53
|
const drawRoundedRectPath = () => {
|
|
159
54
|
context.moveTo(x + radius, y);
|
|
@@ -184,6 +79,9 @@ var MinimapDraw;
|
|
|
184
79
|
};
|
|
185
80
|
MinimapDraw2.overlay = (params) => {
|
|
186
81
|
const { canvas, context, offset, scale, rect, color } = params;
|
|
82
|
+
if (!isRectValid(rect)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
187
85
|
context.fillStyle = color;
|
|
188
86
|
context.fillRect(0, 0, canvas.width, (rect.y + offset.y) * scale);
|
|
189
87
|
context.fillRect(
|
|
@@ -207,9 +105,42 @@ var MinimapDraw;
|
|
|
207
105
|
};
|
|
208
106
|
})(MinimapDraw || (MinimapDraw = {}));
|
|
209
107
|
|
|
108
|
+
// src/constant.ts
|
|
109
|
+
var MinimapDefaultCanvasStyle = {
|
|
110
|
+
canvasWidth: 250,
|
|
111
|
+
canvasHeight: 250,
|
|
112
|
+
canvasPadding: 50,
|
|
113
|
+
canvasBackground: "rgba(242, 243, 245, 1)",
|
|
114
|
+
canvasBorderRadius: 10,
|
|
115
|
+
viewportBackground: "rgba(255, 255, 255, 1)",
|
|
116
|
+
viewportBorderRadius: 4,
|
|
117
|
+
viewportBorderColor: "rgba(6, 7, 9, 0.10)",
|
|
118
|
+
viewportBorderWidth: 1,
|
|
119
|
+
viewportBorderDashLength: void 0,
|
|
120
|
+
nodeColor: "rgba(0, 0, 0, 0.10)",
|
|
121
|
+
nodeBorderRadius: 2,
|
|
122
|
+
nodeBorderWidth: 0.145,
|
|
123
|
+
nodeBorderColor: "rgba(6, 7, 9, 0.10)",
|
|
124
|
+
overlayColor: "rgba(255, 255, 255, 0.55)"
|
|
125
|
+
};
|
|
126
|
+
var MinimapDefaultInactiveStyle = {
|
|
127
|
+
scale: 0.7,
|
|
128
|
+
opacity: 1,
|
|
129
|
+
translateX: 15,
|
|
130
|
+
translateY: 15
|
|
131
|
+
};
|
|
132
|
+
var MinimapDefaultOptions = {
|
|
133
|
+
canvasStyle: MinimapDefaultCanvasStyle,
|
|
134
|
+
canvasClassName: "gedit-minimap-canvas",
|
|
135
|
+
enableDisplayAllNodes: false,
|
|
136
|
+
activeThrottleTime: 0,
|
|
137
|
+
inactiveThrottleTime: 24
|
|
138
|
+
};
|
|
139
|
+
|
|
210
140
|
// src/service.ts
|
|
211
141
|
var FlowMinimapService = class {
|
|
212
142
|
constructor() {
|
|
143
|
+
this.visible = false;
|
|
213
144
|
this.onActive = (callback) => {
|
|
214
145
|
this.onActiveCallbacks.add(callback);
|
|
215
146
|
return {
|
|
@@ -225,14 +156,15 @@ var FlowMinimapService = class {
|
|
|
225
156
|
this.handleWheel = (event) => {
|
|
226
157
|
};
|
|
227
158
|
this.handleStartDrag = (event) => {
|
|
228
|
-
|
|
159
|
+
MouseTouchEvent.preventDefault(event);
|
|
229
160
|
event.stopPropagation();
|
|
230
161
|
const renderContext = this.createRenderContext();
|
|
231
162
|
const { viewRect, scale, offset } = renderContext;
|
|
232
163
|
const canvasRect = this.canvas.getBoundingClientRect();
|
|
164
|
+
const { clientX, clientY } = MouseTouchEvent.getEventCoord(event);
|
|
233
165
|
const mousePoint = {
|
|
234
|
-
x:
|
|
235
|
-
y:
|
|
166
|
+
x: clientX - canvasRect.left,
|
|
167
|
+
y: clientY - canvasRect.top
|
|
236
168
|
};
|
|
237
169
|
const viewRectOnCanvas = this.rectOnCanvas({
|
|
238
170
|
rect: viewRect,
|
|
@@ -246,16 +178,20 @@ var FlowMinimapService = class {
|
|
|
246
178
|
this.dragStart = mousePoint;
|
|
247
179
|
document.addEventListener("mousemove", this.handleDragging);
|
|
248
180
|
document.addEventListener("mouseup", this.handleEndDrag);
|
|
181
|
+
document.addEventListener("touchmove", this.handleDragging, { passive: false });
|
|
182
|
+
document.addEventListener("touchend", this.handleEndDrag);
|
|
183
|
+
document.addEventListener("touchcancel", this.handleEndDrag);
|
|
249
184
|
};
|
|
250
185
|
this.handleDragging = (event) => {
|
|
251
186
|
if (!this.isDragging || !this.dragStart) return;
|
|
252
|
-
|
|
187
|
+
MouseTouchEvent.preventDefault(event);
|
|
253
188
|
event.stopPropagation();
|
|
254
189
|
const renderContext = this.createRenderContext();
|
|
255
190
|
const { scale } = renderContext;
|
|
256
191
|
const canvasRect = this.canvas.getBoundingClientRect();
|
|
257
|
-
const
|
|
258
|
-
const
|
|
192
|
+
const { clientX, clientY } = MouseTouchEvent.getEventCoord(event);
|
|
193
|
+
const mouseX = clientX - canvasRect.left;
|
|
194
|
+
const mouseY = clientY - canvasRect.top;
|
|
259
195
|
const deltaX = (mouseX - this.dragStart.x) / scale;
|
|
260
196
|
const deltaY = (mouseY - this.dragStart.y) / scale;
|
|
261
197
|
this.updateScrollPosition(deltaX, deltaY);
|
|
@@ -263,10 +199,13 @@ var FlowMinimapService = class {
|
|
|
263
199
|
this.render();
|
|
264
200
|
};
|
|
265
201
|
this.handleEndDrag = (event) => {
|
|
266
|
-
|
|
202
|
+
MouseTouchEvent.preventDefault(event);
|
|
267
203
|
event.stopPropagation();
|
|
268
204
|
document.removeEventListener("mousemove", this.handleDragging);
|
|
269
205
|
document.removeEventListener("mouseup", this.handleEndDrag);
|
|
206
|
+
document.removeEventListener("touchmove", this.handleDragging);
|
|
207
|
+
document.removeEventListener("touchend", this.handleEndDrag);
|
|
208
|
+
document.removeEventListener("touchcancel", this.handleEndDrag);
|
|
270
209
|
this.isDragging = false;
|
|
271
210
|
this.dragStart = void 0;
|
|
272
211
|
this.setActivate(this.isMouseInCanvas(event));
|
|
@@ -303,12 +242,8 @@ var FlowMinimapService = class {
|
|
|
303
242
|
init(options) {
|
|
304
243
|
this.options = MinimapDefaultOptions;
|
|
305
244
|
Object.assign(this.options, options);
|
|
306
|
-
this.
|
|
307
|
-
enableDebounce: this.options.enableInactiveDebounce,
|
|
308
|
-
debounceTime: this.options.inactiveDebounceTime
|
|
309
|
-
});
|
|
245
|
+
this.setThrottle(this.options.inactiveThrottleTime);
|
|
310
246
|
this.initStyle();
|
|
311
|
-
this.mountListener();
|
|
312
247
|
}
|
|
313
248
|
dispose() {
|
|
314
249
|
this.toDispose.dispose();
|
|
@@ -316,6 +251,9 @@ var FlowMinimapService = class {
|
|
|
316
251
|
this.activated = false;
|
|
317
252
|
this.removeEventListeners();
|
|
318
253
|
}
|
|
254
|
+
setVisible(visible) {
|
|
255
|
+
this.visible = visible;
|
|
256
|
+
}
|
|
319
257
|
setActivate(activate) {
|
|
320
258
|
if (activate === this.activated) {
|
|
321
259
|
return;
|
|
@@ -325,16 +263,10 @@ var FlowMinimapService = class {
|
|
|
325
263
|
}
|
|
326
264
|
this.activated = activate;
|
|
327
265
|
if (activate) {
|
|
328
|
-
this.
|
|
329
|
-
enableDebounce: this.options.enableActiveDebounce,
|
|
330
|
-
debounceTime: this.options.activeDebounceTime
|
|
331
|
-
});
|
|
266
|
+
this.setThrottle(this.options.activeThrottleTime);
|
|
332
267
|
this.addEventListeners();
|
|
333
268
|
} else {
|
|
334
|
-
this.
|
|
335
|
-
enableDebounce: this.options.enableInactiveDebounce,
|
|
336
|
-
debounceTime: this.options.inactiveDebounceTime
|
|
337
|
-
});
|
|
269
|
+
this.setThrottle(this.options.inactiveThrottleTime);
|
|
338
270
|
this.removeEventListeners();
|
|
339
271
|
}
|
|
340
272
|
this.render();
|
|
@@ -354,24 +286,19 @@ var FlowMinimapService = class {
|
|
|
354
286
|
this.canvas.height = this.style.canvasHeight;
|
|
355
287
|
this.canvas.style.borderRadius = this.style.canvasBorderRadius ? `${this.style.canvasBorderRadius}px` : "unset";
|
|
356
288
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (enableDebounce) {
|
|
360
|
-
this.render = debounce(this._render, debounceTime);
|
|
361
|
-
} else {
|
|
362
|
-
this.render = this._render;
|
|
363
|
-
}
|
|
289
|
+
setThrottle(throttleTime) {
|
|
290
|
+
this.render = throttle(this._render, throttleTime);
|
|
364
291
|
}
|
|
365
292
|
_render() {
|
|
366
|
-
if (!this.initialized) {
|
|
293
|
+
if (!this.initialized || !this.visible) {
|
|
367
294
|
return;
|
|
368
295
|
}
|
|
369
296
|
const renderContext = this.createRenderContext();
|
|
370
297
|
this.renderCanvas(renderContext);
|
|
371
298
|
}
|
|
372
299
|
createRenderContext() {
|
|
373
|
-
const { canvas, context2D
|
|
374
|
-
const nodeTransforms = this.
|
|
300
|
+
const { canvas, context2D } = this;
|
|
301
|
+
const nodeTransforms = this.transformVisibles;
|
|
375
302
|
const nodeRects = nodeTransforms.map((transform) => transform.bounds);
|
|
376
303
|
const viewRect = this.viewRect();
|
|
377
304
|
const renderRect = this.renderRect(nodeRects).withPadding({
|
|
@@ -451,8 +378,13 @@ var FlowMinimapService = class {
|
|
|
451
378
|
};
|
|
452
379
|
return { scale, offset };
|
|
453
380
|
}
|
|
454
|
-
get
|
|
455
|
-
|
|
381
|
+
get transformVisibles() {
|
|
382
|
+
const transformVisible = this.document.getRenderDatas(
|
|
383
|
+
FlowNodeTransformData,
|
|
384
|
+
false
|
|
385
|
+
);
|
|
386
|
+
return transformVisible.filter((transform) => {
|
|
387
|
+
const node = transform.entity;
|
|
456
388
|
if (node.hidden) return false;
|
|
457
389
|
if (node.flowNodeType === FlowNodeBaseType.ROOT) return;
|
|
458
390
|
if (!this.options.enableDisplayAllNodes && node.parent && node.parent.flowNodeType !== FlowNodeBaseType.ROOT)
|
|
@@ -460,9 +392,6 @@ var FlowMinimapService = class {
|
|
|
460
392
|
return true;
|
|
461
393
|
});
|
|
462
394
|
}
|
|
463
|
-
nodeTransforms(nodes) {
|
|
464
|
-
return nodes.map((node) => node.getData(FlowNodeTransformData)).filter(Boolean);
|
|
465
|
-
}
|
|
466
395
|
renderRect(rects) {
|
|
467
396
|
return Rectangle.enlarge(rects);
|
|
468
397
|
}
|
|
@@ -470,10 +399,6 @@ var FlowMinimapService = class {
|
|
|
470
399
|
const { width, height, scrollX, scrollY, zoom } = this.playgroundConfig.config;
|
|
471
400
|
return new Rectangle(scrollX / zoom, scrollY / zoom, width / zoom, height / zoom);
|
|
472
401
|
}
|
|
473
|
-
mountListener() {
|
|
474
|
-
const entityManagerDisposer = this.entityManager.onEntityChange(() => this.render());
|
|
475
|
-
this.toDispose.push(entityManagerDisposer);
|
|
476
|
-
}
|
|
477
402
|
/** 计算画布坐标系下的矩形 */
|
|
478
403
|
rectOnCanvas(params) {
|
|
479
404
|
const { rect, scale, offset } = params;
|
|
@@ -491,16 +416,19 @@ var FlowMinimapService = class {
|
|
|
491
416
|
addEventListeners() {
|
|
492
417
|
this.canvas.addEventListener("wheel", this.handleWheel);
|
|
493
418
|
this.canvas.addEventListener("mousedown", this.handleStartDrag);
|
|
419
|
+
this.canvas.addEventListener("touchstart", this.handleStartDrag, { passive: false });
|
|
494
420
|
this.canvas.addEventListener("mousemove", this.handleCursor);
|
|
495
421
|
}
|
|
496
422
|
removeEventListeners() {
|
|
497
423
|
this.canvas.removeEventListener("wheel", this.handleWheel);
|
|
498
424
|
this.canvas.removeEventListener("mousedown", this.handleStartDrag);
|
|
425
|
+
this.canvas.removeEventListener("touchstart", this.handleStartDrag);
|
|
499
426
|
this.canvas.removeEventListener("mousemove", this.handleCursor);
|
|
500
427
|
}
|
|
501
428
|
isMouseInCanvas(event) {
|
|
502
429
|
const canvasRect = this.canvas.getBoundingClientRect();
|
|
503
|
-
|
|
430
|
+
const { clientX, clientY } = MouseTouchEvent.getEventCoord(event);
|
|
431
|
+
return clientX >= canvasRect.left && clientX <= canvasRect.right && clientY >= canvasRect.top && clientY <= canvasRect.bottom;
|
|
504
432
|
}
|
|
505
433
|
updateScrollPosition(deltaX, deltaY) {
|
|
506
434
|
const { scrollX, scrollY, zoom } = this.playgroundConfig.config;
|
|
@@ -513,9 +441,6 @@ var FlowMinimapService = class {
|
|
|
513
441
|
__decorateClass([
|
|
514
442
|
inject(FlowDocument)
|
|
515
443
|
], FlowMinimapService.prototype, "document", 2);
|
|
516
|
-
__decorateClass([
|
|
517
|
-
inject(EntityManager)
|
|
518
|
-
], FlowMinimapService.prototype, "entityManager", 2);
|
|
519
444
|
__decorateClass([
|
|
520
445
|
inject(PlaygroundConfigEntity)
|
|
521
446
|
], FlowMinimapService.prototype, "playgroundConfig", 2);
|
|
@@ -523,11 +448,107 @@ FlowMinimapService = __decorateClass([
|
|
|
523
448
|
injectable()
|
|
524
449
|
], FlowMinimapService);
|
|
525
450
|
|
|
451
|
+
// src/component.tsx
|
|
452
|
+
var MinimapRender = (props) => {
|
|
453
|
+
const { panelStyles = {}, containerStyles = {}, inactiveStyle: customInactiveStyle = {} } = props;
|
|
454
|
+
const inactiveStyle = {
|
|
455
|
+
...MinimapDefaultInactiveStyle,
|
|
456
|
+
...customInactiveStyle
|
|
457
|
+
};
|
|
458
|
+
const playgroundContainer = usePlaygroundContainer();
|
|
459
|
+
const service = props.service || playgroundContainer?.get(FlowMinimapService);
|
|
460
|
+
const panelRef = useRef(null);
|
|
461
|
+
const [activated, setActivated] = useState(false);
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
const canvasContainer = panelRef.current;
|
|
464
|
+
if (canvasContainer && service.canvas) {
|
|
465
|
+
canvasContainer.appendChild(service.canvas);
|
|
466
|
+
}
|
|
467
|
+
const disposer = service.onActive((activate) => {
|
|
468
|
+
setActivated(activate);
|
|
469
|
+
});
|
|
470
|
+
service.setVisible(true);
|
|
471
|
+
service.render();
|
|
472
|
+
return () => {
|
|
473
|
+
disposer.dispose();
|
|
474
|
+
service.setVisible(false);
|
|
475
|
+
};
|
|
476
|
+
}, [service]);
|
|
477
|
+
const scale = activated ? 1 : inactiveStyle.scale;
|
|
478
|
+
const opacity = activated ? 1 : inactiveStyle.opacity;
|
|
479
|
+
const translateX = activated ? 0 : inactiveStyle.translateX;
|
|
480
|
+
const translateY = activated ? 0 : inactiveStyle.translateY;
|
|
481
|
+
return /* @__PURE__ */ React.createElement(
|
|
482
|
+
"div",
|
|
483
|
+
{
|
|
484
|
+
className: "minimap-container",
|
|
485
|
+
style: {
|
|
486
|
+
position: "fixed",
|
|
487
|
+
right: 30,
|
|
488
|
+
bottom: 70,
|
|
489
|
+
transition: "all 0.3s ease",
|
|
490
|
+
// 添加过渡效果
|
|
491
|
+
transform: `scale(${scale}) translate(${translateX}px, ${translateY}px)`,
|
|
492
|
+
opacity,
|
|
493
|
+
transformOrigin: "bottom right",
|
|
494
|
+
// 设置变换的原点
|
|
495
|
+
...containerStyles
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
/* @__PURE__ */ React.createElement(
|
|
499
|
+
"div",
|
|
500
|
+
{
|
|
501
|
+
className: "minimap-panel",
|
|
502
|
+
style: {
|
|
503
|
+
display: "flex",
|
|
504
|
+
width: "100%",
|
|
505
|
+
height: "100%",
|
|
506
|
+
borderRadius: "10px",
|
|
507
|
+
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
508
|
+
border: "0.572px solid rgba(6, 7, 9, 0.10)",
|
|
509
|
+
overflow: "hidden",
|
|
510
|
+
boxShadow: "0px 2.289px 6.867px 0px rgba(0, 0, 0, 0.08), 0px 4.578px 13.733px 0px rgba(0, 0, 0, 0.04)",
|
|
511
|
+
boxSizing: "border-box",
|
|
512
|
+
padding: 8,
|
|
513
|
+
...panelStyles
|
|
514
|
+
},
|
|
515
|
+
"data-flow-editor-selectable": "false",
|
|
516
|
+
ref: panelRef,
|
|
517
|
+
onMouseEnter: () => {
|
|
518
|
+
service.setActivate(true);
|
|
519
|
+
},
|
|
520
|
+
onMouseLeave: () => {
|
|
521
|
+
service.setActivate(false);
|
|
522
|
+
},
|
|
523
|
+
onTouchStartCapture: () => {
|
|
524
|
+
service.setActivate(true);
|
|
525
|
+
},
|
|
526
|
+
onTouchEndCapture: () => {
|
|
527
|
+
service.setActivate(false);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/create-plugin.ts
|
|
535
|
+
import { definePluginCreator } from "@flowgram.ai/core";
|
|
536
|
+
|
|
526
537
|
// src/layer.tsx
|
|
527
538
|
import React2 from "react";
|
|
528
539
|
import { inject as inject2, injectable as injectable2 } from "inversify";
|
|
529
|
-
import { Layer } from "@flowgram.ai/core";
|
|
530
540
|
import { domUtils } from "@flowgram.ai/utils";
|
|
541
|
+
import {
|
|
542
|
+
FlowNodeEntity,
|
|
543
|
+
FlowNodeTransformData as FlowNodeTransformData2,
|
|
544
|
+
FlowDocumentTransformerEntity
|
|
545
|
+
} from "@flowgram.ai/document";
|
|
546
|
+
import {
|
|
547
|
+
Layer,
|
|
548
|
+
observeEntityDatas,
|
|
549
|
+
observeEntity,
|
|
550
|
+
PlaygroundConfigEntity as PlaygroundConfigEntity2
|
|
551
|
+
} from "@flowgram.ai/core";
|
|
531
552
|
var FlowMinimapLayer = class extends Layer {
|
|
532
553
|
constructor() {
|
|
533
554
|
super();
|
|
@@ -536,6 +557,9 @@ var FlowMinimapLayer = class extends Layer {
|
|
|
536
557
|
this.node.style.zIndex = "9999";
|
|
537
558
|
}
|
|
538
559
|
render() {
|
|
560
|
+
if (this.documentTransformer.loading) return /* @__PURE__ */ React2.createElement(React2.Fragment, null);
|
|
561
|
+
this.documentTransformer.refresh();
|
|
562
|
+
this.service.render();
|
|
539
563
|
if (this.options.disableLayer) {
|
|
540
564
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null);
|
|
541
565
|
}
|
|
@@ -554,6 +578,15 @@ FlowMinimapLayer.type = "FlowMinimapLayer";
|
|
|
554
578
|
__decorateClass([
|
|
555
579
|
inject2(FlowMinimapService)
|
|
556
580
|
], FlowMinimapLayer.prototype, "service", 2);
|
|
581
|
+
__decorateClass([
|
|
582
|
+
observeEntityDatas(FlowNodeEntity, FlowNodeTransformData2)
|
|
583
|
+
], FlowMinimapLayer.prototype, "transformDatas", 2);
|
|
584
|
+
__decorateClass([
|
|
585
|
+
observeEntity(PlaygroundConfigEntity2)
|
|
586
|
+
], FlowMinimapLayer.prototype, "configEntity", 2);
|
|
587
|
+
__decorateClass([
|
|
588
|
+
observeEntity(FlowDocumentTransformerEntity)
|
|
589
|
+
], FlowMinimapLayer.prototype, "documentTransformer", 2);
|
|
557
590
|
FlowMinimapLayer = __decorateClass([
|
|
558
591
|
injectable2()
|
|
559
592
|
], FlowMinimapLayer);
|