Skip to content

Commit

Permalink
feat: 限制图形拖拽只对鼠标左键生效
Browse files Browse the repository at this point in the history
  • Loading branch information
l-x-f committed Jun 7, 2022
1 parent 70f8288 commit 95bc754
Show file tree
Hide file tree
Showing 10 changed files with 1,456 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
/node_modules
# tests
tests
2 changes: 1 addition & 1 deletion dist/auto-drawing.esm.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dist/auto-drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19101,18 +19101,20 @@
var state = {
startX: 0,
startY: 0,
isDown: false
canTranslate: false
};
zr.on('mousedown', function (e) {
var _e$event = e.event,
startX = _e$event.clientX,
startY = _e$event.clientY;
state.startX = startX;
state.startY = startY;
state.isDown = true;
state.startY = startY; // 判断用户点击的是否是鼠标左键 左键可以平移

state.canTranslate = e.event.button === 0 ? true : false;
});

function move(e) {
if (!state.canTranslate) return;
var _e$event2 = e.event,
clientX = _e$event2.clientX,
clientY = _e$event2.clientY;
Expand All @@ -19138,7 +19140,7 @@

zr.on('mouseup', function (e) {
move(e);
state.isDown = true;
state.canTranslate = false;
});
}
/**
Expand Down
6 changes: 3 additions & 3 deletions dist/auto-drawing.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-drawing",
"version": "0.0.5",
"version": "0.0.6",
"description": "auto-drawing based zrender",
"types": "dist/index.d.ts",
"module": "dist/auto-drawing.esm.js",
Expand Down Expand Up @@ -68,4 +68,4 @@
"npm run lint"
]
}
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const rollupConfig = {

// 使得 rollup 支持 commonjs 规范,识别 commonjs 规范的依赖
commonjs(),
// 配合 commnjs 解析第三方模块
// 配合 commonjs 解析第三方模块
resolve({
// 将自定义选项传递给解析插件
customResolveOptions: {
Expand Down
8 changes: 5 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ export function translateGroup(
group: ZRenderGroup,
options?: { callback?: CallbackType }
): void {
const state = { startX: 0, startY: 0, isDown: false }
const state = { startX: 0, startY: 0, canTranslate: false }
zr.on('mousedown', (e: any) => {
const { clientX: startX, clientY: startY } = e.event
state.startX = startX
state.startY = startY
state.isDown = true
// 判断用户点击的是否是鼠标左键 左键可以平移
state.canTranslate = e.event.button === 0 ? true : false
})
function move(e: any) {
if (!state.canTranslate) return
const { clientX, clientY } = e.event
const stepX = clientX - state.startX
const stepY = clientY - state.startY
Expand All @@ -87,7 +89,7 @@ export function translateGroup(
}
zr.on('mouseup', (e: any) => {
move(e)
state.isDown = true
state.canTranslate = false
})
}

Expand Down

0 comments on commit 95bc754

Please sign in to comment.