|
| 1 | +# Table tool |
| 2 | + |
| 3 | +The Table Block for the [Editor.js](https://editorjs.io). Finally improved. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Get the package |
| 10 | + |
| 11 | +```shell |
| 12 | +yarn add @editorjs/table |
| 13 | +``` |
| 14 | + |
| 15 | +Include module at your application |
| 16 | + |
| 17 | +```javascript |
| 18 | +import Table from '@editorjs/table' |
| 19 | +``` |
| 20 | + |
| 21 | +Optionally, you can load this tool from CDN [JsDelivr CDN](https://cdn.jsdelivr.net/npm/@editorjs/table@latest) |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +Add a new Tool to the `tools` property of the Editor.js initial config. |
| 28 | + |
| 29 | +```javascript |
| 30 | +import Table from '@editorjs/table'; |
| 31 | + |
| 32 | +var editor = EditorJS({ |
| 33 | + tools: { |
| 34 | + table: Table, |
| 35 | + } |
| 36 | +}); |
| 37 | +``` |
| 38 | + |
| 39 | +Or init the Table tool with additional settings |
| 40 | + |
| 41 | +```javascript |
| 42 | +var editor = EditorJS({ |
| 43 | + tools: { |
| 44 | + table: { |
| 45 | + class: Table, |
| 46 | + inlineToolbar: true, |
| 47 | + config: { |
| 48 | + rows: 2, |
| 49 | + cols: 3, |
| 50 | + maxRows: 5, |
| 51 | + maxCols: 5, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | +}); |
| 56 | +``` |
| 57 | + |
| 58 | +## Config Params |
| 59 | + |
| 60 | +| Field | Type | Description | |
| 61 | +| ------------------ | -------- | ---------------------------------------- | |
| 62 | +| `rows` | `number` | initial number of rows. `2` by default | |
| 63 | +| `cols` | `number` | initial number of columns. `2` by default | |
| 64 | +| `maxRows` | `number` | maximum number of rows. `5` by params | |
| 65 | +| `maxCols` | `number` | maximum number of columns. `5` by params | |
| 66 | +| `withHeadings` | `boolean` | toggle table headings. `false` by default | |
| 67 | +| `stretched` | `boolean` | whether the table is stretched to fill the full width of the container | |
| 68 | + |
| 69 | +## Output data |
| 70 | + |
| 71 | +This Tool returns `data` in the following format |
| 72 | + |
| 73 | +| Field | Type | Description | |
| 74 | +| -------------- | ------------ | ----------------------------------------- | |
| 75 | +| `withHeadings` | `boolean` | Uses the first line as headings | |
| 76 | +| `stretched` | `boolean` | whether the table is stretched to fill the full width of the container | |
| 77 | +| `content` | `string[][]` | two-dimensional array with table contents | |
| 78 | + |
| 79 | +```json |
| 80 | +{ |
| 81 | + "type" : "table", |
| 82 | + "data" : { |
| 83 | + "withHeadings": true, |
| 84 | + "stretched": false, |
| 85 | + "content" : [ [ "Kine", "Pigs", "Chicken" ], [ "1 pcs", "3 pcs", "12 pcs" ], [ "100$", "200$", "150$" ] ] |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## CSP support |
| 91 | + |
| 92 | +If you're using Content Security Policy (CSP) pass a `nonce` via [`<meta property="csp-nonce" content={{ nonce }} />`](https://github.com/marco-prontera/vite-plugin-css-injected-by-js#usestrictcsp-boolean) in your document head. |
| 93 | + |
| 94 | +# Support maintenance 🎖 |
| 95 | + |
| 96 | +If you're using this tool and editor.js in your business, please consider supporting their maintenance and evolution. |
| 97 | + |
| 98 | +[http://opencollective.com/editorjs](http://opencollective.com/editorjs) |
| 99 | + |
| 100 | +# About CodeX |
| 101 | + |
| 102 | +<img align="right" width="120" height="120" src="https://codex.so/public/app/img/codex-logo.svg" hspace="50"> |
| 103 | + |
| 104 | +CodeX is a team of digital specialists around the world interested in building high-quality open source products on a global market. We are [open](https://codex.so/join) for young people who want to constantly improve their skills and grow professionally with experiments in leading technologies. |
| 105 | + |
| 106 | +| 🌐 | Join 👋 | Twitter | Instagram | |
| 107 | +| -- | -- | -- | -- | |
| 108 | +| [codex.so](https://codex.so) | [codex.so/join](https://codex.so/join) |[@codex_team](http://twitter.com/codex_team) | [@codex_team](http://instagram.com/codex_team) | |
0 commit comments