Skip to content

Commit 7dd3941

Browse files
authored
Merge pull request #161 from parmisan/master
added the ability to stretch the table
2 parents dee45c8 + ef1e39e commit 7dd3941

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var editor = EditorJS({
6464
| `maxRows` | `number` | maximum number of rows. `5` by params |
6565
| `maxCols` | `number` | maximum number of columns. `5` by params |
6666
| `withHeadings` | `boolean` | toggle table headings. `false` by default |
67+
| `stretched` | `boolean` | whether the table is stretched to fill the full width of the container |
6768

6869
## Output data
6970

@@ -72,13 +73,15 @@ This Tool returns `data` in the following format
7273
| Field | Type | Description |
7374
| -------------- | ------------ | ----------------------------------------- |
7475
| `withHeadings` | `boolean` | Uses the first line as headings |
76+
| `stretched` | `boolean` | whether the table is stretched to fill the full width of the container |
7577
| `content` | `string[][]` | two-dimensional array with table contents |
7678

7779
```json
7880
{
7981
"type" : "table",
8082
"data" : {
8183
"withHeadings": true,
84+
"stretched": false,
8285
"content" : [ [ "Kine", "Pigs", "Chicken" ], [ "1 pcs", "3 pcs", "12 pcs" ], [ "100$", "200$", "150$" ] ]
8386
}
8487
}

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@
4040
<pre class="output"></pre>
4141

4242
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
43-
<script src="./dist/table.umd.js"></script>
44-
45-
<script>
4643

44+
<script type="module">
45+
import Table from './src/index'
4746
const editor = new EditorJS({
4847
autofocus: true,
4948
tools: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@editorjs/table",
33
"description": "Table for Editor.js",
4-
"version": "2.4.1",
4+
"version": "2.4.2",
55
"license": "MIT",
66
"repository": "https://github.com/editor-js/table",
77
"files": [

src/plugin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Table from './table';
22
import * as $ from './utils/dom';
33

4-
import { IconTable, IconTableWithHeadings, IconTableWithoutHeadings } from '@codexteam/icons';
5-
4+
import { IconTable, IconTableWithHeadings, IconTableWithoutHeadings, IconStretch, IconCollapse } from '@codexteam/icons';
65
/**
76
* @typedef {object} TableData - configuration that the user can set for the table
87
* @property {number} rows - number of rows in the table
@@ -60,15 +59,17 @@ export default class TableBlock {
6059
*
6160
* @param {TableConstructor} init
6261
*/
63-
constructor({data, config, api, readOnly}) {
62+
constructor({data, config, api, readOnly, block}) {
6463
this.api = api;
6564
this.readOnly = readOnly;
6665
this.config = config;
6766
this.data = {
6867
withHeadings: this.getConfig('withHeadings', false, data),
68+
stretched: this.getConfig('stretched', false, data),
6969
content: data && data.content ? data.content : []
7070
};
7171
this.table = null;
72+
this.block = block;
7273
}
7374

7475
/**
@@ -130,6 +131,15 @@ export default class TableBlock {
130131
this.data.withHeadings = false;
131132
this.table.setHeadingsSetting(this.data.withHeadings);
132133
}
134+
}, {
135+
label: this.data.stretched ? this.api.i18n.t('Collapse') : this.api.i18n.t('Stretch'),
136+
icon: this.data.stretched ? IconCollapse : IconStretch,
137+
closeOnActivate: true,
138+
toggle: true,
139+
onActivate: () => {
140+
this.data.stretched = !this.data.stretched;
141+
this.block.stretched = this.data.stretched;
142+
}
133143
}
134144
];
135145
}
@@ -143,6 +153,7 @@ export default class TableBlock {
143153

144154
const result = {
145155
withHeadings: this.data.withHeadings,
156+
stretched: this.data.stretched,
146157
content: tableContent
147158
};
148159

0 commit comments

Comments
 (0)