chore: Editor refactor (#3286)

* cleanup

* add context

* EventEmitter allows removal of toolbar props from extensions

* Move to 'packages' of extensions
Remove EmojiTrigger extension

* types

* iteration

* fix render flashing

* fix: Missing nodes in collection descriptions
This commit is contained in:
Tom Moor
2022-03-30 19:10:34 -07:00
committed by GitHub
parent c5b9a742c0
commit 6f2a4488e8
30 changed files with 517 additions and 581 deletions

29
shared/utils/events.ts Normal file
View File

@@ -0,0 +1,29 @@
/**
* A tiny EventEmitter implementation for the browser.
*/
export default class EventEmitter {
private listeners: { [name: string]: ((data: any) => unknown)[] } = {};
public addListener(name: string, callback: (data: any) => unknown) {
if (!this.listeners[name]) {
this.listeners[name] = [];
}
this.listeners[name].push(callback);
}
public removeListener(name: string, callback: (data: any) => unknown) {
this.listeners[name] = this.listeners[name]?.filter(
(cb) => cb !== callback
);
}
public on = this.addListener;
public off = this.removeListener;
public emit(name: string, data?: any) {
this.listeners[name]?.forEach((callback) => {
callback(data);
});
}
}