Skip to content

Commit

Permalink
fix: It can listen doubleClickElement when the element is invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshenhai committed Sep 14, 2021
1 parent 27e26e5 commit 151fe71
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/__tests__/lib/core-is.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Core from './../../src';

describe("@idraw/core static is", () => {
describe("@idraw/core:static is", () => {

test('Core.is.number', () => {
expect(Core.is.number(0)).toStrictEqual(true);
Expand Down
1 change: 1 addition & 0 deletions packages/core/examples/features/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ html, body {
line-height: 30px;
color: #666;
font-size: 14px;
user-select: none;
}

.elem-item:last-child {
Expand Down
16 changes: 15 additions & 1 deletion packages/core/examples/features/lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ function listenElements(core) {
renderElemens(core);
} else if (el.hasAttribute('data-elem-btn-lock')) {
const uuid = el.getAttribute('data-elem-btn-lock');
core.moveDownElement(uuid);
const elem = core.getElement(uuid);
if (!elem.operation) {
elem.operation = {};
}
elem.operation.lock = !elem.operation.lock;
core.updateElement(elem);
renderElemens(core);
} else if (el.hasAttribute('data-elem-btn-invisible')) {
const uuid = el.getAttribute('data-elem-btn-invisible');
const elem = core.getElement(uuid);
if (!elem.operation) {
elem.operation = {};
}
elem.operation.invisible = !elem.operation.invisible;
core.updateElement(elem);
renderElemens(core);
}
}, true);
Expand Down
9 changes: 7 additions & 2 deletions packages/core/examples/features/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const core = new Core(mount, {
});


initEvent();
// initEvent();

core.setData(data);

Expand Down Expand Up @@ -85,4 +85,9 @@ function initEvent() {
console.log('screenDoubleClickElement ===', p)
})

}
}

// TODO
core.on('screenDoubleClickElement', (p) => {
console.log('screenDoubleClickElement ===', p)
})
12 changes: 7 additions & 5 deletions packages/core/src/mixins/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ function handleDoubleClick(core: Core) {
return function ( point: TypePoint) {
const [index, uuid] = core[_element].isPointInElement(point, core[_data]);
if (index >= 0 && uuid) {
core[_coreEvent].trigger(
'screenDoubleClickElement',
{ index, uuid, element: deepClone(core[_data].elements?.[index])}
);
const elem = deepClone(core[_data].elements?.[index]);
if (elem?.operation?.invisible !== true) {
core[_coreEvent].trigger(
'screenDoubleClickElement',
{ index, uuid, element: deepClone(core[_data].elements?.[index])}
);
}
}
core[_draw]();
}
Expand Down Expand Up @@ -90,7 +93,6 @@ function handlePoint(core: Core) {

function handleClick(core: Core) {
return function(point: TypePoint): void {
console.log('handleClick: point =', point)
const [index, uuid] = core[_element].isPointInElement(point, core[_data]);
if (index >= 0 && uuid) {
core[_coreEvent].trigger(
Expand Down

0 comments on commit 151fe71

Please sign in to comment.