Skip to content

Commit

Permalink
Merge pull request #105 from MalindaWMD/master
Browse files Browse the repository at this point in the history
Add withHeadings config
  • Loading branch information
neSpecc authored Nov 8, 2022
2 parents 5907135 + 1e2b514 commit a45d732
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var editor = EditorJS({
| ------------------ | -------- | ---------------------------------------- |
| `rows` | `number` | initial number of rows. `2` by default |
| `cols` | `number` | initial number of columns. `2` by default |
| `withHeadings` | `boolean` | toggle table headings. `false` by default |

## Output data

Expand Down
3 changes: 3 additions & 0 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
table: {
class: Table,
inlineToolbar: true,
config: {
withHeadings: true
}
}
},
data: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@editorjs/table",
"description": "Table for Editor.js",
"version": "2.0.4",
"version": "2.1.0",
"license": "MIT",
"main": "./dist/table.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export default class TableBlock {
constructor({ data, config, api, readOnly }) {
this.api = api;
this.readOnly = readOnly;
this.config = config;
this.data = {
withHeadings: data && data.withHeadings ? data.withHeadings : false,
withHeadings: this.getConfig('withHeadings', false),
content: data && data.content ? data.content : []
};
this.config = config;
this.table = null;
}

Expand Down Expand Up @@ -199,4 +199,17 @@ export default class TableBlock {
destroy() {
this.table.destroy();
}

/**
* A helper to get config
*
* @returns {any}
*/
getConfig(configName, defaultValue=null) {
if(this.data){
return this.data[configName] ? this.data[configName] : defaultValue;
}

return this.config && this.config[configName] ? this.config[configName] : defaultValue;
}
}

0 comments on commit a45d732

Please sign in to comment.