fix: It can listen doubleClickElement when the element is invisible

This commit is contained in:
chenshenhai 2021-09-14 11:09:46 +08:00
parent 27e26e5d86
commit 151fe71e95
5 changed files with 31 additions and 9 deletions

View file

@ -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);

View file

@ -61,6 +61,7 @@ html, body {
line-height: 30px;
color: #666;
font-size: 14px;
user-select: none;
}
.elem-item:last-child {

View file

@ -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);

View file

@ -39,7 +39,7 @@ const core = new Core(mount, {
});
initEvent();
// initEvent();
core.setData(data);
@ -85,4 +85,9 @@ function initEvent() {
console.log('screenDoubleClickElement ===', p)
})
}
}
// TODO
core.on('screenDoubleClickElement', (p) => {
console.log('screenDoubleClickElement ===', p)
})

View file

@ -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]();
}
@ -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(