diff --git a/src/plugin.js b/src/plugin.js index 60b599f9..0e457f00 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -104,6 +104,18 @@ export default class TableBlock { return this.container; } + /** + * Hook called after the block is fully rendered and mounted + * Set this.block.stretched here as block is not initialized in render(). + * + * @returns {void} + */ + rendered() { + if (this.block) { + this.block.stretched = !!this.data.stretched; + } + } + /** * Returns plugin settings * @@ -119,7 +131,7 @@ export default class TableBlock { toggle: true, onActivate: () => { this.data.withHeadings = true; - this.table.setHeadingsSetting(this.data.withHeadings); + this._updateTunes(); } }, { label: this.api.i18n.t('Without headings'), @@ -129,7 +141,7 @@ export default class TableBlock { toggle: true, onActivate: () => { this.data.withHeadings = false; - this.table.setHeadingsSetting(this.data.withHeadings); + this._updateTunes(); } }, { label: this.data.stretched ? this.api.i18n.t('Collapse') : this.api.i18n.t('Stretch'), @@ -138,11 +150,26 @@ export default class TableBlock { toggle: true, onActivate: () => { this.data.stretched = !this.data.stretched; - this.block.stretched = this.data.stretched; + this._updateTunes(); } } ]; } + + /** + * Handle updating UI for tunes + * + * @returns {void} + */ + _updateTunes() { + this.table.setHeadingsSetting(this.data.withHeadings); + + if (this.block) { + this.block.stretched = !!this.data.stretched; + this.block.dispatchChange(); + } + } + /** * Extract table data from the view * @@ -222,6 +249,7 @@ export default class TableBlock { /** Update Tool's data */ this.data = { withHeadings: firstRowHeading !== null, + stretched: false, content };