feat: CustomTool链式调用

This commit is contained in:
unanmed 2023-12-18 17:15:39 +08:00
parent 72d74ec7a6
commit 334c25fb7a

View File

@ -102,6 +102,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
} as ToolbarItemMap[K]; } as ToolbarItemMap[K];
this.items.push(data); this.items.push(data);
this.emit('add', data); this.emit('add', data);
return this;
} }
/** /**
@ -114,6 +115,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
const item = this.items[index]; const item = this.items[index];
this.items.splice(index, 1); this.items.splice(index, 1);
this.emit('delete', item); this.emit('delete', item);
return this;
} }
/** /**
@ -129,6 +131,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
if (!toSet) return; if (!toSet) return;
Object.assign(toSet, item); Object.assign(toSet, item);
this.emit('set', id, item); this.emit('set', id, item);
return this;
} }
/** /**
@ -172,7 +175,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
nextTick(() => { nextTick(() => {
this.items.push(...items); this.items.push(...items);
}); });
// this.items.push(...this.items.splice(0)); return this;
} }
setPos(x?: number, y?: number) { setPos(x?: number, y?: number) {
@ -196,20 +199,21 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
hook.once('reset', () => { hook.once('reset', () => {
const toolbar = new CustomToolbar('test'); const toolbar = new CustomToolbar('test');
toolbar.add<'hotkey'>({ toolbar
id: 'test1', .add<'hotkey'>({
type: 'hotkey', id: 'test1',
assist: 0, type: 'hotkey',
key: KeyCode.KeyX assist: 0,
}); key: KeyCode.KeyX
toolbar.add<'assistKey'>({ })
id: 'test2', .add<'assistKey'>({
type: 'assistKey', id: 'test2',
assist: KeyCode.Ctrl type: 'assistKey',
}); assist: KeyCode.Ctrl
toolbar.add<'item'>({ })
id: 'test3', .add<'item'>({
type: 'item', id: 'test3',
item: 'book' type: 'item',
}); item: 'book'
});
}); });