@logicflow/extension 2.1.6 → 2.2.0-alpha.1
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +22 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/components/dnd-panel/index.js +6 -2
- package/es/components/mini-map/index.js +6 -6
- package/es/components/selection-select/index.js +18 -9
- package/es/insert-node-in-polyline/index.js +11 -35
- package/es/tools/label/Label.d.ts +2 -2
- package/es/tools/label/Label.js +1 -1
- package/es/tools/label/LabelOverlay.js +3 -3
- package/es/tools/label/mediumEditor.d.ts +1 -1
- package/es/tools/label/mediumEditor.js +89 -52
- package/es/tools/snapshot/index.js +26 -13
- package/lib/components/dnd-panel/index.js +6 -2
- package/lib/components/mini-map/index.js +6 -6
- package/lib/components/selection-select/index.js +18 -9
- package/lib/insert-node-in-polyline/index.js +10 -34
- package/lib/tools/label/Label.d.ts +2 -2
- package/lib/tools/label/Label.js +1 -1
- package/lib/tools/label/LabelOverlay.js +2 -2
- package/lib/tools/label/mediumEditor.d.ts +1 -1
- package/lib/tools/label/mediumEditor.js +91 -53
- package/lib/tools/snapshot/index.js +26 -13
- package/package.json +5 -5
- package/src/components/dnd-panel/index.ts +10 -2
- package/src/components/menu/index.ts +0 -1
- package/src/components/mini-map/index.ts +8 -8
- package/src/components/selection-select/index.ts +22 -14
- package/src/insert-node-in-polyline/index.ts +17 -11
- package/src/tools/label/Label.tsx +4 -4
- package/src/tools/label/LabelOverlay.tsx +7 -3
- package/src/tools/label/mediumEditor.ts +78 -51
- package/src/tools/snapshot/index.ts +12 -0
- package/stats.html +1 -1
|
@@ -17,6 +17,9 @@ var DndPanel = /** @class */ (function () {
|
|
|
17
17
|
}
|
|
18
18
|
this.panelEl = document.createElement('div');
|
|
19
19
|
this.panelEl.className = 'lf-dndpanel';
|
|
20
|
+
this.panelEl.addEventListener('touchmove', function (e) {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
}, { passive: false });
|
|
20
23
|
this.shapeList.forEach(function (shapeItem) {
|
|
21
24
|
var _a;
|
|
22
25
|
(_a = _this.panelEl) === null || _a === void 0 ? void 0 : _a.appendChild(_this.createDndItem(shapeItem));
|
|
@@ -63,14 +66,14 @@ var DndPanel = /** @class */ (function () {
|
|
|
63
66
|
if (shapeItem.disabled) {
|
|
64
67
|
el.classList.add('disabled');
|
|
65
68
|
// 保留callback的执行,可用于界面提示当前shapeItem的禁用状态
|
|
66
|
-
el.
|
|
69
|
+
el.onpointerdown = function () {
|
|
67
70
|
if (shapeItem.callback) {
|
|
68
71
|
shapeItem.callback(_this.lf, _this.domContainer);
|
|
69
72
|
}
|
|
70
73
|
};
|
|
71
74
|
return el;
|
|
72
75
|
}
|
|
73
|
-
el.
|
|
76
|
+
el.onpointerdown = function (e) {
|
|
74
77
|
if (shapeItem.type) {
|
|
75
78
|
_this.lf.dnd.startDrag({
|
|
76
79
|
type: shapeItem.type,
|
|
@@ -81,6 +84,7 @@ var DndPanel = /** @class */ (function () {
|
|
|
81
84
|
if (shapeItem.callback) {
|
|
82
85
|
shapeItem.callback(_this.lf, _this.domContainer);
|
|
83
86
|
}
|
|
87
|
+
e.preventDefault();
|
|
84
88
|
};
|
|
85
89
|
el.ondblclick = function (e) {
|
|
86
90
|
_this.lf.graphModel.eventCenter.emit('dnd:panel-dbclick', {
|
|
@@ -179,8 +179,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
this.startDrag = function (e) {
|
|
182
|
-
document.addEventListener('
|
|
183
|
-
document.addEventListener('
|
|
182
|
+
document.addEventListener('pointermove', _this.drag);
|
|
183
|
+
document.addEventListener('pointerup', _this.drop);
|
|
184
184
|
var x = e.x, y = e.y;
|
|
185
185
|
_this.startPosition = { x: x, y: y };
|
|
186
186
|
};
|
|
@@ -206,8 +206,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
206
206
|
* 拖拽预览视窗结束,移除拖拽事件
|
|
207
207
|
*/
|
|
208
208
|
this.drop = function () {
|
|
209
|
-
document.removeEventListener('
|
|
210
|
-
document.removeEventListener('
|
|
209
|
+
document.removeEventListener('pointermove', _this.drag);
|
|
210
|
+
document.removeEventListener('pointerup', _this.drop);
|
|
211
211
|
};
|
|
212
212
|
/**
|
|
213
213
|
* 点击小地图中非预览视窗的区域时,移动主画布视口聚焦于点击位置
|
|
@@ -513,8 +513,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
513
513
|
MiniMap.prototype.createViewPort = function () {
|
|
514
514
|
var div = document.createElement('div');
|
|
515
515
|
div.className = 'lf-minimap-viewport';
|
|
516
|
-
|
|
517
|
-
div.addEventListener('
|
|
516
|
+
div.style.touchAction = 'none';
|
|
517
|
+
div.addEventListener('pointerdown', this.startDrag);
|
|
518
518
|
// 禁止预览视窗的点击事件冒泡
|
|
519
519
|
div.addEventListener('click', function (e) {
|
|
520
520
|
e.stopPropagation();
|
|
@@ -46,6 +46,12 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
46
46
|
_this.handleMouseDown(e);
|
|
47
47
|
};
|
|
48
48
|
this.draw = function (ev) {
|
|
49
|
+
if (_this.lf.graphModel.editConfigModel.isPinching) {
|
|
50
|
+
_this.lf.updateEditConfig({ stopMoveGraph: _this.originalStopMoveGraph });
|
|
51
|
+
_this.originStatusSaved = false;
|
|
52
|
+
_this.cleanupSelectionState();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
49
55
|
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
|
50
56
|
_this.endPoint = {
|
|
51
57
|
x: x1,
|
|
@@ -94,9 +100,9 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
94
100
|
}
|
|
95
101
|
var curStartPoint = cloneDeep(_this.startPoint);
|
|
96
102
|
var curEndPoint = cloneDeep(_this.endPoint);
|
|
97
|
-
document.removeEventListener('
|
|
103
|
+
document.removeEventListener('pointermove', _this.draw);
|
|
98
104
|
if (!_this.exclusiveMode) {
|
|
99
|
-
document.removeEventListener('
|
|
105
|
+
document.removeEventListener('pointerup', _this.drawOff);
|
|
100
106
|
}
|
|
101
107
|
if (curStartPoint && curEndPoint) {
|
|
102
108
|
var x = curStartPoint.x, y = curStartPoint.y;
|
|
@@ -210,8 +216,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
210
216
|
this.endPoint = undefined;
|
|
211
217
|
this.mouseDownInfo = null;
|
|
212
218
|
// 移除事件监听
|
|
213
|
-
document.removeEventListener('
|
|
214
|
-
document.removeEventListener('
|
|
219
|
+
document.removeEventListener('pointermove', this.draw);
|
|
220
|
+
document.removeEventListener('pointerup', this.drawOff);
|
|
215
221
|
};
|
|
216
222
|
/**
|
|
217
223
|
* 切换框选模式
|
|
@@ -235,7 +241,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
235
241
|
if (this.exclusiveMode) {
|
|
236
242
|
// 独占模式:监听 container 的 mousedown 事件
|
|
237
243
|
this.container.style.pointerEvents = 'auto';
|
|
238
|
-
this.container.
|
|
244
|
+
this.container.style.touchAction = 'none';
|
|
245
|
+
this.container.addEventListener('pointerdown', this.handleMouseDown);
|
|
239
246
|
}
|
|
240
247
|
else {
|
|
241
248
|
// 非独占模式:监听画布的 blank:mousedown 事件
|
|
@@ -247,7 +254,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
247
254
|
SelectionSelect.prototype.removeEventListeners = function () {
|
|
248
255
|
if (this.container) {
|
|
249
256
|
this.container.style.pointerEvents = 'none';
|
|
250
|
-
this.container.removeEventListener('
|
|
257
|
+
this.container.removeEventListener('pointerdown', this.handleMouseDown);
|
|
251
258
|
}
|
|
252
259
|
// 移除 blank:mousedown 事件监听
|
|
253
260
|
this.lf.off('blank:mousedown', this.handleBlankMouseDown);
|
|
@@ -259,6 +266,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
259
266
|
var _a;
|
|
260
267
|
if (!this.container || this.disabled)
|
|
261
268
|
return;
|
|
269
|
+
if (this.lf.graphModel.editConfigModel.isPinching)
|
|
270
|
+
return;
|
|
262
271
|
// 禁用右键框选
|
|
263
272
|
var isRightClick = e.button === 2;
|
|
264
273
|
if (isRightClick)
|
|
@@ -292,8 +301,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
292
301
|
wrapper.style.left = "".concat(this.startPoint.x, "px");
|
|
293
302
|
(_a = this.container) === null || _a === void 0 ? void 0 : _a.appendChild(wrapper);
|
|
294
303
|
this.wrapper = wrapper;
|
|
295
|
-
document.addEventListener('
|
|
296
|
-
document.addEventListener('
|
|
304
|
+
document.addEventListener('pointermove', this.draw);
|
|
305
|
+
document.addEventListener('pointerup', this.drawOff);
|
|
297
306
|
};
|
|
298
307
|
/**
|
|
299
308
|
* 设置选中的灵敏度
|
|
@@ -331,7 +340,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
331
340
|
if (this.wrapper && this.startPoint && this.endPoint) {
|
|
332
341
|
// 记录上一次的结束点,用于触发 mouseup 事件
|
|
333
342
|
var lastEndPoint = cloneDeep(this.endPoint);
|
|
334
|
-
var lastEvent = new
|
|
343
|
+
var lastEvent = new PointerEvent('pointerup', {
|
|
335
344
|
clientX: lastEndPoint.x,
|
|
336
345
|
clientY: lastEndPoint.y,
|
|
337
346
|
});
|
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
-
if (ar || !(i in from)) {
|
|
20
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
};
|
|
26
|
-
import { EventType, formatAnchorConnectValidateData, } from '@logicflow/core';
|
|
1
|
+
import { EventType, formatAnchorConnectValidateData, getClosestAnchor, } from '@logicflow/core';
|
|
27
2
|
import { cloneDeep } from 'lodash-es';
|
|
28
3
|
import { isNodeInSegment } from './edge';
|
|
29
4
|
var InsertNodeInPolyline = /** @class */ (function () {
|
|
@@ -113,28 +88,29 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
113
88
|
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList, sourceAnchorId = _b.sourceAnchorId, targetAnchorId = _b.targetAnchorId;
|
|
114
89
|
// fix https://github.com/didi/LogicFlow/issues/996
|
|
115
90
|
var startPoint = cloneDeep(pointsList[0]);
|
|
116
|
-
var endPoint = cloneDeep(crossPoints.startCrossPoint);
|
|
117
91
|
this._lf.deleteEdge(id);
|
|
118
92
|
var checkResult = this.checkRuleBeforeInsetNode(sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData);
|
|
93
|
+
// 基于插入节点的进入交点计算出最近的“进入锚点”,用于重连原边的前半段
|
|
94
|
+
var entryAnchorInfo = getClosestAnchor(crossPoints.startCrossPoint, nodeModel);
|
|
95
|
+
var entryAnchor = entryAnchorInfo.anchor;
|
|
96
|
+
// 构造第一条边:原 source → 插入节点(终点为进入锚点)
|
|
119
97
|
this._lf.addEdge({
|
|
120
98
|
type: type,
|
|
121
99
|
sourceNodeId: sourceNodeId,
|
|
122
100
|
targetNodeId: nodeData.id,
|
|
123
101
|
startPoint: startPoint,
|
|
124
|
-
endPoint:
|
|
125
|
-
pointsList: __spreadArray(__spreadArray([], __read(pointsList.slice(0, crossIndex)), false), [
|
|
126
|
-
crossPoints.startCrossPoint,
|
|
127
|
-
], false),
|
|
102
|
+
endPoint: entryAnchor,
|
|
128
103
|
});
|
|
104
|
+
// 基于插入节点的离开交点计算出最近的“离开锚点”,用于重连原边的后半段
|
|
105
|
+
var exitAnchorInfo = getClosestAnchor(crossPoints.endCrossPoint, nodeModel);
|
|
106
|
+
var exitAnchor = exitAnchorInfo.anchor;
|
|
107
|
+
// 构造第二条边:插入节点 → 原 target(起点为离开锚点)
|
|
129
108
|
this._lf.addEdge({
|
|
130
109
|
type: type,
|
|
131
110
|
sourceNodeId: nodeData.id,
|
|
132
111
|
targetNodeId: targetNodeId,
|
|
133
|
-
startPoint: cloneDeep(
|
|
112
|
+
startPoint: cloneDeep(exitAnchor),
|
|
134
113
|
endPoint: cloneDeep(pointsList[pointsList.length - 1]),
|
|
135
|
-
pointsList: __spreadArray([
|
|
136
|
-
crossPoints.endCrossPoint
|
|
137
|
-
], __read(pointsList.slice(crossIndex)), false),
|
|
138
114
|
});
|
|
139
115
|
if (!checkResult.isPass) {
|
|
140
116
|
this._lf.graphModel.eventCenter.emit(EventType.CONNECTION_NOT_ALLOWED, {
|
|
@@ -17,8 +17,8 @@ export declare class Label extends Component<ILabelProps, ILabelState> {
|
|
|
17
17
|
constructor(props: ILabelProps);
|
|
18
18
|
setHoverOn: () => void;
|
|
19
19
|
setHoverOff: () => void;
|
|
20
|
-
handleMouseDown: (e:
|
|
21
|
-
handleMouseUp: (e:
|
|
20
|
+
handleMouseDown: (e: PointerEvent) => void;
|
|
21
|
+
handleMouseUp: (e: PointerEvent) => void;
|
|
22
22
|
handleDragging: ({ deltaX, deltaY }: IDragParams) => void;
|
|
23
23
|
handleDragEnd: () => void;
|
|
24
24
|
handleClick: (e: MouseEvent) => void;
|
package/es/tools/label/Label.js
CHANGED
|
@@ -274,7 +274,7 @@ var Label = /** @class */ (function (_super) {
|
|
|
274
274
|
? "".concat(transform, " rotate(").concat(rotate, "deg)")
|
|
275
275
|
: "".concat(transform, " rotate(").concat(vertical ? -0.25 : 0, "turn)"),
|
|
276
276
|
};
|
|
277
|
-
return (_jsx("div", { id: "element-container-".concat(id), className: classNames('lf-label-editor-container'), style: containerStyle,
|
|
277
|
+
return (_jsx("div", { id: "element-container-".concat(id), className: classNames('lf-label-editor-container'), style: containerStyle, onPointerDown: this.handleMouseDown, onPointerUp: this.handleMouseUp, onClick: this.handleClick, onDblClick: this.handleDbClick, onBlur: this.handleBlur, onMouseEnter: this.setHoverOn, onMouseOver: this.setHoverOn, onMouseLeave: this.setHoverOff, children: _jsx("div", { ref: this.textRef, id: "editor-container-".concat(id), className: classNames('lf-label-editor', (_a = {
|
|
278
278
|
'lf-label-editor-dragging': isDragging,
|
|
279
279
|
'lf-label-editor-editing': isEditing,
|
|
280
280
|
'lf-label-editor-hover': !isEditing && (isHovered || isSelected)
|
|
@@ -49,7 +49,7 @@ import { Component, observer } from '@logicflow/core';
|
|
|
49
49
|
import { forEach, merge } from 'lodash-es';
|
|
50
50
|
import Label from './Label';
|
|
51
51
|
import LabelModel from './LabelModel';
|
|
52
|
-
import { MediumEditor, defaultOptions,
|
|
52
|
+
import { MediumEditor, defaultOptions, createColorPickerButtonClass, } from './mediumEditor';
|
|
53
53
|
// const { createUuid } = LogicFlowUtil
|
|
54
54
|
// DONE: 解决问题,如果 LabelOverlay 设置为 Observer,拖拽 Label 时会导致 LabelOverlay 组件重新渲染,不知道为何
|
|
55
55
|
// 目前解决了。流程是 拖动 -> 更新 label 的数据信息到 element model -> 重新渲染 LabelOverlay
|
|
@@ -74,7 +74,7 @@ var LabelOverlay = /** @class */ (function (_super) {
|
|
|
74
74
|
this.editor = new MediumEditor('.lf-label-editor', merge(defaultOptions, {
|
|
75
75
|
autoLink: true,
|
|
76
76
|
extensions: {
|
|
77
|
-
colorPicker: new
|
|
77
|
+
colorPicker: new (createColorPickerButtonClass(MediumEditor))(),
|
|
78
78
|
},
|
|
79
79
|
}));
|
|
80
80
|
// TODO: 2. 在此处监听一些事件,当 node、edge 数据变化时,主动触发重新渲染,保证同步更新
|
|
@@ -99,7 +99,7 @@ var LabelOverlay = /** @class */ (function (_super) {
|
|
|
99
99
|
this.editor = new MediumEditor('.lf-label-editor', merge(defaultOptions, {
|
|
100
100
|
autoLink: true,
|
|
101
101
|
extensions: {
|
|
102
|
-
colorPicker: new
|
|
102
|
+
colorPicker: new (createColorPickerButtonClass(MediumEditor))(),
|
|
103
103
|
},
|
|
104
104
|
}));
|
|
105
105
|
}
|
|
@@ -36,56 +36,93 @@ export var defaultOptions = {
|
|
|
36
36
|
},
|
|
37
37
|
disableEditing: true,
|
|
38
38
|
};
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
39
|
+
export function createColorPickerButtonClass(MediumEditor) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
var ButtonBase = ((_a = MediumEditor === null || MediumEditor === void 0 ? void 0 : MediumEditor.extensions) === null || _a === void 0 ? void 0 : _a.button) || ((_b = MediumEditor === null || MediumEditor === void 0 ? void 0 : MediumEditor.extensions) === null || _b === void 0 ? void 0 : _b.button);
|
|
42
|
+
var ExtensionBase = (MediumEditor === null || MediumEditor === void 0 ? void 0 : MediumEditor.Extension) || (MediumEditor === null || MediumEditor === void 0 ? void 0 : MediumEditor.Extension);
|
|
43
|
+
// 当 Button 扩展基类不可用时,回退到 Extension 基类,避免在模块加载阶段抛错
|
|
44
|
+
var Base = ButtonBase || ExtensionBase;
|
|
45
|
+
if (!Base) {
|
|
46
|
+
console.warn('MediumEditor button/extension base not available; using noop extension');
|
|
47
|
+
return /** @class */ (function () {
|
|
48
|
+
function class_1() {
|
|
49
|
+
}
|
|
50
|
+
return class_1;
|
|
51
|
+
}());
|
|
52
|
+
}
|
|
53
|
+
return Base.extend({
|
|
54
|
+
name: 'colorpicker',
|
|
55
|
+
tagNames: ['mark'],
|
|
56
|
+
contentDefault: '<b>Color</b>',
|
|
57
|
+
aria: 'Color Picker',
|
|
58
|
+
action: 'colorPicker',
|
|
59
|
+
init: function () {
|
|
60
|
+
var _this = this;
|
|
61
|
+
var _a, _b;
|
|
62
|
+
try {
|
|
63
|
+
rangy.init();
|
|
64
|
+
}
|
|
65
|
+
catch (_c) {
|
|
66
|
+
console.error('rangy.init failed');
|
|
67
|
+
}
|
|
68
|
+
// 初始化按钮(ButtonBase 才有 prototype.init)
|
|
69
|
+
try {
|
|
70
|
+
;
|
|
71
|
+
(_b = (_a = ButtonBase === null || ButtonBase === void 0 ? void 0 : ButtonBase.prototype) === null || _a === void 0 ? void 0 : _a.init) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
72
|
+
}
|
|
73
|
+
catch (_d) {
|
|
74
|
+
console.error('ButtonBase.init failed');
|
|
75
|
+
}
|
|
76
|
+
this.colorPicker = new Picker({
|
|
77
|
+
parent: this.button || undefined,
|
|
78
|
+
color: '#000',
|
|
79
|
+
onDone: function (res) {
|
|
80
|
+
var _a, _b, _c, _d, _e;
|
|
81
|
+
try {
|
|
82
|
+
if (_this.coloredText && ((_b = (_a = _this.coloredText).isAppliedToSelection) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
83
|
+
_this.coloredText.undoToSelection();
|
|
84
|
+
}
|
|
85
|
+
_this.coloredText = rangy.createClassApplier('colored', {
|
|
86
|
+
elementTagName: 'span',
|
|
87
|
+
elementProperties: { style: { color: res.hex } },
|
|
88
|
+
normalize: true,
|
|
89
|
+
});
|
|
90
|
+
_this.coloredText.toggleSelection();
|
|
91
|
+
(_d = (_c = _this.base) === null || _c === void 0 ? void 0 : _c.checkContentChanged) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
92
|
+
(_e = _this.setInactive) === null || _e === void 0 ? void 0 : _e.call(_this);
|
|
93
|
+
}
|
|
94
|
+
catch (_f) {
|
|
95
|
+
console.error('Picker.onDone failed');
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
getButton: function () {
|
|
101
|
+
return this.button;
|
|
102
|
+
},
|
|
103
|
+
handleClick: function () {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
(_a = this.setActive) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
106
|
+
(_c = (_b = this.colorPicker) === null || _b === void 0 ? void 0 : _b.show) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
107
|
+
},
|
|
108
|
+
isAlreadyApplied: function (node) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
return ((_b = (_a = node === null || node === void 0 ? void 0 : node.nodeName) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a)) === 'mark';
|
|
111
|
+
},
|
|
112
|
+
isActive: function () {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
return (_b = (_a = this.button) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.contains('medium-editor-button-active');
|
|
115
|
+
},
|
|
116
|
+
setInactive: function () {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
;
|
|
119
|
+
(_b = (_a = this.button) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.remove('medium-editor-button-active');
|
|
120
|
+
},
|
|
121
|
+
setActive: function () {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
;
|
|
124
|
+
(_b = (_a = this.button) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add('medium-editor-button-active');
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
91
128
|
export { MediumEditor };
|
|
@@ -666,7 +666,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
666
666
|
// 内部方法处理blob转换
|
|
667
667
|
Snapshot.prototype.snapshotBlob = function (toImageOptions, baseFileType, backgroundColor) {
|
|
668
668
|
return __awaiter(this, void 0, void 0, function () {
|
|
669
|
-
var _a, fileType, svg;
|
|
669
|
+
var _a, fileType, svg, copy, svgString, blob;
|
|
670
670
|
var _this = this;
|
|
671
671
|
return __generator(this, function (_b) {
|
|
672
672
|
switch (_b.label) {
|
|
@@ -676,18 +676,31 @@ var Snapshot = /** @class */ (function () {
|
|
|
676
676
|
return [4 /*yield*/, updateImageSource(svg)];
|
|
677
677
|
case 1:
|
|
678
678
|
_b.sent();
|
|
679
|
-
return [
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
679
|
+
if (!(fileType === 'svg')) return [3 /*break*/, 3];
|
|
680
|
+
return [4 /*yield*/, this.cloneSvg(svg)];
|
|
681
|
+
case 2:
|
|
682
|
+
copy = _b.sent();
|
|
683
|
+
svgString = new XMLSerializer().serializeToString(copy);
|
|
684
|
+
blob = new Blob([svgString], {
|
|
685
|
+
type: 'image/svg+xml;charset=utf-8',
|
|
686
|
+
});
|
|
687
|
+
return [2 /*return*/, {
|
|
688
|
+
data: blob,
|
|
689
|
+
width: 0,
|
|
690
|
+
height: 0,
|
|
691
|
+
}];
|
|
692
|
+
case 3: return [2 /*return*/, new Promise(function (resolve) {
|
|
693
|
+
_this.getCanvasData(svg, __assign({ backgroundColor: backgroundColor }, (toImageOptions !== null && toImageOptions !== void 0 ? toImageOptions : {}))).then(function (canvas) {
|
|
694
|
+
canvas.toBlob(function (blob) {
|
|
695
|
+
// 输出图片数据以及图片宽高
|
|
696
|
+
resolve({
|
|
697
|
+
data: blob,
|
|
698
|
+
width: canvas.width,
|
|
699
|
+
height: canvas.height,
|
|
700
|
+
});
|
|
701
|
+
}, "image/".concat(fileType !== null && fileType !== void 0 ? fileType : 'png'));
|
|
702
|
+
});
|
|
703
|
+
})];
|
|
691
704
|
}
|
|
692
705
|
});
|
|
693
706
|
});
|
|
@@ -20,6 +20,9 @@ var DndPanel = /** @class */ (function () {
|
|
|
20
20
|
}
|
|
21
21
|
this.panelEl = document.createElement('div');
|
|
22
22
|
this.panelEl.className = 'lf-dndpanel';
|
|
23
|
+
this.panelEl.addEventListener('touchmove', function (e) {
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
}, { passive: false });
|
|
23
26
|
this.shapeList.forEach(function (shapeItem) {
|
|
24
27
|
var _a;
|
|
25
28
|
(_a = _this.panelEl) === null || _a === void 0 ? void 0 : _a.appendChild(_this.createDndItem(shapeItem));
|
|
@@ -66,14 +69,14 @@ var DndPanel = /** @class */ (function () {
|
|
|
66
69
|
if (shapeItem.disabled) {
|
|
67
70
|
el.classList.add('disabled');
|
|
68
71
|
// 保留callback的执行,可用于界面提示当前shapeItem的禁用状态
|
|
69
|
-
el.
|
|
72
|
+
el.onpointerdown = function () {
|
|
70
73
|
if (shapeItem.callback) {
|
|
71
74
|
shapeItem.callback(_this.lf, _this.domContainer);
|
|
72
75
|
}
|
|
73
76
|
};
|
|
74
77
|
return el;
|
|
75
78
|
}
|
|
76
|
-
el.
|
|
79
|
+
el.onpointerdown = function (e) {
|
|
77
80
|
if (shapeItem.type) {
|
|
78
81
|
_this.lf.dnd.startDrag({
|
|
79
82
|
type: shapeItem.type,
|
|
@@ -84,6 +87,7 @@ var DndPanel = /** @class */ (function () {
|
|
|
84
87
|
if (shapeItem.callback) {
|
|
85
88
|
shapeItem.callback(_this.lf, _this.domContainer);
|
|
86
89
|
}
|
|
90
|
+
e.preventDefault();
|
|
87
91
|
};
|
|
88
92
|
el.ondblclick = function (e) {
|
|
89
93
|
_this.lf.graphModel.eventCenter.emit('dnd:panel-dbclick', {
|
|
@@ -182,8 +182,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
this.startDrag = function (e) {
|
|
185
|
-
document.addEventListener('
|
|
186
|
-
document.addEventListener('
|
|
185
|
+
document.addEventListener('pointermove', _this.drag);
|
|
186
|
+
document.addEventListener('pointerup', _this.drop);
|
|
187
187
|
var x = e.x, y = e.y;
|
|
188
188
|
_this.startPosition = { x: x, y: y };
|
|
189
189
|
};
|
|
@@ -209,8 +209,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
209
209
|
* 拖拽预览视窗结束,移除拖拽事件
|
|
210
210
|
*/
|
|
211
211
|
this.drop = function () {
|
|
212
|
-
document.removeEventListener('
|
|
213
|
-
document.removeEventListener('
|
|
212
|
+
document.removeEventListener('pointermove', _this.drag);
|
|
213
|
+
document.removeEventListener('pointerup', _this.drop);
|
|
214
214
|
};
|
|
215
215
|
/**
|
|
216
216
|
* 点击小地图中非预览视窗的区域时,移动主画布视口聚焦于点击位置
|
|
@@ -516,8 +516,8 @@ var MiniMap = /** @class */ (function () {
|
|
|
516
516
|
MiniMap.prototype.createViewPort = function () {
|
|
517
517
|
var div = document.createElement('div');
|
|
518
518
|
div.className = 'lf-minimap-viewport';
|
|
519
|
-
|
|
520
|
-
div.addEventListener('
|
|
519
|
+
div.style.touchAction = 'none';
|
|
520
|
+
div.addEventListener('pointerdown', this.startDrag);
|
|
521
521
|
// 禁止预览视窗的点击事件冒泡
|
|
522
522
|
div.addEventListener('click', function (e) {
|
|
523
523
|
e.stopPropagation();
|
|
@@ -49,6 +49,12 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
49
49
|
_this.handleMouseDown(e);
|
|
50
50
|
};
|
|
51
51
|
this.draw = function (ev) {
|
|
52
|
+
if (_this.lf.graphModel.editConfigModel.isPinching) {
|
|
53
|
+
_this.lf.updateEditConfig({ stopMoveGraph: _this.originalStopMoveGraph });
|
|
54
|
+
_this.originStatusSaved = false;
|
|
55
|
+
_this.cleanupSelectionState();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
52
58
|
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
|
53
59
|
_this.endPoint = {
|
|
54
60
|
x: x1,
|
|
@@ -97,9 +103,9 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
97
103
|
}
|
|
98
104
|
var curStartPoint = (0, lodash_es_1.cloneDeep)(_this.startPoint);
|
|
99
105
|
var curEndPoint = (0, lodash_es_1.cloneDeep)(_this.endPoint);
|
|
100
|
-
document.removeEventListener('
|
|
106
|
+
document.removeEventListener('pointermove', _this.draw);
|
|
101
107
|
if (!_this.exclusiveMode) {
|
|
102
|
-
document.removeEventListener('
|
|
108
|
+
document.removeEventListener('pointerup', _this.drawOff);
|
|
103
109
|
}
|
|
104
110
|
if (curStartPoint && curEndPoint) {
|
|
105
111
|
var x = curStartPoint.x, y = curStartPoint.y;
|
|
@@ -213,8 +219,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
213
219
|
this.endPoint = undefined;
|
|
214
220
|
this.mouseDownInfo = null;
|
|
215
221
|
// 移除事件监听
|
|
216
|
-
document.removeEventListener('
|
|
217
|
-
document.removeEventListener('
|
|
222
|
+
document.removeEventListener('pointermove', this.draw);
|
|
223
|
+
document.removeEventListener('pointerup', this.drawOff);
|
|
218
224
|
};
|
|
219
225
|
/**
|
|
220
226
|
* 切换框选模式
|
|
@@ -238,7 +244,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
238
244
|
if (this.exclusiveMode) {
|
|
239
245
|
// 独占模式:监听 container 的 mousedown 事件
|
|
240
246
|
this.container.style.pointerEvents = 'auto';
|
|
241
|
-
this.container.
|
|
247
|
+
this.container.style.touchAction = 'none';
|
|
248
|
+
this.container.addEventListener('pointerdown', this.handleMouseDown);
|
|
242
249
|
}
|
|
243
250
|
else {
|
|
244
251
|
// 非独占模式:监听画布的 blank:mousedown 事件
|
|
@@ -250,7 +257,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
250
257
|
SelectionSelect.prototype.removeEventListeners = function () {
|
|
251
258
|
if (this.container) {
|
|
252
259
|
this.container.style.pointerEvents = 'none';
|
|
253
|
-
this.container.removeEventListener('
|
|
260
|
+
this.container.removeEventListener('pointerdown', this.handleMouseDown);
|
|
254
261
|
}
|
|
255
262
|
// 移除 blank:mousedown 事件监听
|
|
256
263
|
this.lf.off('blank:mousedown', this.handleBlankMouseDown);
|
|
@@ -262,6 +269,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
262
269
|
var _a;
|
|
263
270
|
if (!this.container || this.disabled)
|
|
264
271
|
return;
|
|
272
|
+
if (this.lf.graphModel.editConfigModel.isPinching)
|
|
273
|
+
return;
|
|
265
274
|
// 禁用右键框选
|
|
266
275
|
var isRightClick = e.button === 2;
|
|
267
276
|
if (isRightClick)
|
|
@@ -295,8 +304,8 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
295
304
|
wrapper.style.left = "".concat(this.startPoint.x, "px");
|
|
296
305
|
(_a = this.container) === null || _a === void 0 ? void 0 : _a.appendChild(wrapper);
|
|
297
306
|
this.wrapper = wrapper;
|
|
298
|
-
document.addEventListener('
|
|
299
|
-
document.addEventListener('
|
|
307
|
+
document.addEventListener('pointermove', this.draw);
|
|
308
|
+
document.addEventListener('pointerup', this.drawOff);
|
|
300
309
|
};
|
|
301
310
|
/**
|
|
302
311
|
* 设置选中的灵敏度
|
|
@@ -334,7 +343,7 @@ var SelectionSelect = /** @class */ (function () {
|
|
|
334
343
|
if (this.wrapper && this.startPoint && this.endPoint) {
|
|
335
344
|
// 记录上一次的结束点,用于触发 mouseup 事件
|
|
336
345
|
var lastEndPoint = (0, lodash_es_1.cloneDeep)(this.endPoint);
|
|
337
|
-
var lastEvent = new
|
|
346
|
+
var lastEvent = new PointerEvent('pointerup', {
|
|
338
347
|
clientX: lastEndPoint.x,
|
|
339
348
|
clientY: lastEndPoint.y,
|
|
340
349
|
});
|