json-joy
Version:
Collection of libraries for building collaborative editing apps.
40 lines • 1.38 kB
JavaScript
export class CompositionController {
dom;
composing = false;
data = '';
constructor(dom) {
this.dom = dom;
}
/** -------------------------------------------------- {@link UiLifeCycles} */
start() {
const onStart = (event) => {
this.composing = true;
this.data = event.data;
};
const onUpdate = (event) => {
this.composing = true;
this.data = event.data;
};
const onEnd = (event) => {
this.composing = false;
this.data = '';
const text = event.data;
if (text)
this.dom.et.insert(text);
};
const el = this.dom.el;
el.addEventListener('compositionstart', onStart);
el.addEventListener('compositionupdate', onUpdate);
el.addEventListener('compositionend', onEnd);
return () => {
el.removeEventListener('compositionstart', onStart);
el.removeEventListener('compositionupdate', onUpdate);
el.removeEventListener('compositionend', onEnd);
};
}
/** ----------------------------------------------------- {@link Printable} */
toString(tab) {
return `composition { composing: ${this.composing}, data: ${JSON.stringify(this.data)} }`;
}
}
//# sourceMappingURL=CompositionController.js.map