Skip to content

Commit

Permalink
♻️ Turn Composition into a module
Browse files Browse the repository at this point in the history
This change allows consumers to modify the behaviour of the new
`Composition` class by registering an alternative class instead of the
default module.
  • Loading branch information
alecgibson committed Jun 29, 2023
1 parent 28204e6 commit b513f53
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Selection from './core/selection';
import Uploader from './modules/uploader';
import Delta, { Op, OpIterator, AttributeMap } from '@reedsy/quill-delta';
import Input from './modules/input';
import Composition from './core/composition';

export { Delta, Op, OpIterator, AttributeMap };

Expand All @@ -31,6 +32,7 @@ Quill.register({
'blots/text': TextBlot,

'modules/clipboard': Clipboard,
'modules/composition': Composition,
'modules/history': History,
'modules/keyboard': Keyboard,
'modules/selection': Selection,
Expand Down
16 changes: 12 additions & 4 deletions core/composition.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import Embed from '../blots/embed';
import Scroll from '../blots/scroll';
import Emitter from './emitter';
import Module from './module';

class Composition {
class Composition extends Module {
isComposing = false;

constructor(private scroll: Scroll, private emitter: Emitter) {
scroll.domNode.addEventListener('compositionstart', event => {
private scroll: Scroll;
private emitter: Emitter;

constructor(quill, options) {
super(quill, options);
this.scroll = quill.scroll;
this.emitter = quill.emitter;

this.scroll.domNode.addEventListener('compositionstart', event => {
if (!this.isComposing) {
this.handleCompositionStart(event);
}
});

scroll.domNode.addEventListener('compositionend', event => {
this.scroll.domNode.addEventListener('compositionend', event => {
if (this.isComposing) {
this.handleCompositionEnd(event);
}
Expand Down
2 changes: 1 addition & 1 deletion core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class Quill {
emitter: this.emitter,
});
this.editor = new Editor(this.scroll);
this.composition = new Composition(this.scroll, this.emitter);
this.theme = new this.options.theme(this, this.options); // eslint-disable-line new-cap
this.composition = this.theme.addModule('composition');
this.selection = this.theme.addModule('selection');
this.keyboard = this.theme.addModule('keyboard');
this.clipboard = this.theme.addModule('clipboard');
Expand Down
2 changes: 2 additions & 0 deletions core/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import History from '../modules/history';
import Keyboard from '../modules/keyboard';
import Uploader from '../modules/uploader';
import Selection from '../core/selection';
import Composition from './composition';

interface ThemeOptions {
modules: Record<string, unknown>;
Expand Down Expand Up @@ -31,6 +32,7 @@ class Theme {
}

addModule(name: 'clipboard'): Clipboard;
addModule(name: 'composition'): Composition;
addModule(name: 'keyboard'): Keyboard;
addModule(name: 'uploader'): Uploader;
addModule(name: 'history'): History;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reedsy/quill",
"version": "2.0.0-reedsy-3.0.2",
"version": "2.0.0-reedsy-3.1.0",
"description": "Your powerful, rich text editor",
"author": "Jason Chen <jhchen7@gmail.com>",
"homepage": "http://quilljs.com",
Expand Down
2 changes: 2 additions & 0 deletions themes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import History from '../modules/history';
import Keyboard from '../modules/keyboard';
import Uploader from '../modules/uploader';
import Selection from '../core/selection';
import Composition from '../core/composition';

const ALIGNS = [false, 'center', 'right', 'justify'];

Expand Down Expand Up @@ -93,6 +94,7 @@ class BaseTheme extends Theme {
}

addModule(name: 'clipboard'): Clipboard;
addModule(name: 'composition'): Composition;
addModule(name: 'keyboard'): Keyboard;
addModule(name: 'uploader'): Uploader;
addModule(name: 'history'): History;
Expand Down

0 comments on commit b513f53

Please sign in to comment.