Skip to content

Commit

Permalink
Fix issue editor-js#47 The text alignment is now visible in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchesfree committed Apr 11, 2023
1 parent 5fc5030 commit 0552be1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
margin-bottom: 10px;
}

.cdx-quote__text--left {
text-align: left;
}

.cdx-quote__text--center {
text-align: center;
}

.cdx-quote__text--right {
text-align: right;
}

.cdx-quote__text--justify {
text-align: justify;
}

.cdx-quote__caption {}

.cdx-quote [contentEditable=true][data-placeholder]::before{
Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ export default class Quote {
/**
* Tool`s styles
*
* @returns {{baseClass: string, wrapper: string, quote: string, input: string, caption: string}}
* @returns {{baseClass: string, wrapper: string, text: string, textTune: string, input: string, caption: string}}
*/
get CSS() {
return {
baseClass: this.api.styles.block,
wrapper: 'cdx-quote',
text: 'cdx-quote__text',
textTune: 'cdx-quote__text--' + this.data.alignment,
input: this.api.styles.input,
caption: 'cdx-quote__caption',
};
Expand Down Expand Up @@ -216,7 +217,7 @@ export default class Quote {
*/
render() {
const container = this._make('blockquote', [this.CSS.baseClass, this.CSS.wrapper]);
const quote = this._make('div', [this.CSS.input, this.CSS.text], {
const quote = this._make('div', [this.CSS.input, this.CSS.text, this.CSS.textTune], {
contentEditable: !this.readOnly,
innerHTML: this.data.text,
});
Expand Down Expand Up @@ -292,8 +293,13 @@ export default class Quote {
* @private
*/
_toggleTune(tune) {
const text = this.blockAPI.holder.querySelector(`.${this.CSS.text}`);
text.classList.remove(this.CSS.textTune)

this.data.alignment = tune;

text.classList.add(this.CSS.textTune)

// Tell Editor to know that block was changed
this.blockAPI.dispatchChange()
}
Expand Down

0 comments on commit 0552be1

Please sign in to comment.