Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "@editorjs/table",
"description": "Table for Editor.js",
"version": "2.3.1",
"version": "2.4.0",
"license": "MIT",
"repository": "https://github.com/editor-js/table",
"files": [
"dist"
],
"main": "./dist/table.umd.js",
"module": "./dist/table.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/table.mjs",
"require": "./dist/table.umd.js"
"require": "./dist/table.umd.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
Expand Down Expand Up @@ -41,9 +43,11 @@
"postcss-nested": "^4.1.0",
"postcss-nesting": "^7.0.0",
"vite": "^4.5.0",
"vite-plugin-css-injected-by-js": "^3.3.0"
"vite-plugin-css-injected-by-js": "^3.3.0",
"vite-plugin-dts": "^3.9.1",
"typescript": "^5.5.4"
},
"dependencies": {
"@codexteam/icons": "^0.0.6"
}
}
}
30 changes: 19 additions & 11 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as $ from './utils/dom';
import { IconTable, IconTableWithHeadings, IconTableWithoutHeadings } from '@codexteam/icons';

/**
* @typedef {object} TableConfig - configuration that the user can set for the table
* @typedef {object} TableData - configuration that the user can set for the table
* @property {number} rows - number of rows in the table
* @property {number} cols - number of columns in the table
*/
Expand All @@ -16,10 +16,21 @@ import { IconTable, IconTableWithHeadings, IconTableWithoutHeadings } from '@cod
* @property {void} setTune - set tune state to the table data
*/
/**
* @typedef {object} TableData - object with the data transferred to form a table
* @typedef {object} TableConfig - object with the data transferred to form a table
* @property {boolean} withHeading - setting to use cells of the first row as headings
* @property {string[][]} content - two-dimensional array which contains table content
*/
/**
* @typedef {object} TableConstructor
* @property {TableConfig} data — previously saved data
* @property {TableConfig} config - user config for Tool
* @property {object} api - Editor.js API
* @property {boolean} readOnly - read-only mode flag
*/
/**
* @typedef {import('@editorjs/editorjs').PasteEvent} PasteEvent
*/


/**
* Table block for Editor.js
Expand Down Expand Up @@ -47,10 +58,7 @@ export default class TableBlock {
/**
* Render plugin`s main Element and fill it with saved data
*
* @param {TableData} data — previously saved data
* @param {TableConfig} config - user config for Tool
* @param {object} api - Editor.js API
* @param {boolean} readOnly - read-only mode flag
* @param {TableConstructor} init
*/
constructor({data, config, api, readOnly}) {
this.api = api;
Expand Down Expand Up @@ -152,8 +160,8 @@ export default class TableBlock {

/**
* A helper to get config value.
*
* @param {string} configName - the key to get from the config.
*
* @param {string} configName - the key to get from the config.
* @param {any} defaultValue - default value if config doesn't have passed key
* @param {object} savedData - previously saved data. If passed, the key will be got from there, otherwise from the config
* @returns {any} - config value.
Expand All @@ -168,7 +176,7 @@ export default class TableBlock {
return this.config && this.config[configName] ? this.config[configName] : defaultValue;
}

/**
/**
* Table onPaste configuration
*
* @public
Expand All @@ -190,12 +198,12 @@ export default class TableBlock {

/** Get all rows from the table */
const rows = Array.from(table.querySelectorAll('tr'));

/** Generate a content matrix */
const content = rows.map((row) => {
/** Get cells from row */
const cells = Array.from(row.querySelectorAll('th, td'))

/** Return cells content */
return cells.map((cell) => cell.innerHTML);
});
Expand Down
14 changes: 14 additions & 0 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ const CSS = {
addColumn: 'tc-add-column'
};

/**
* @typedef {object} TableConfig
* @description Tool's config from Editor
* @property {boolean} withHeadings — Uses the first line as headings
* @property {string[][]} withHeadings — two-dimensional array with table contents
*/

/**
* @typedef {object} TableData - object with the data transferred to form a table
* @property {number} rows - number of rows in the table
* @property {number} cols - number of columns in the table
*/


/**
* Generates and manages table contents.
*/
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"include": ["src/**/*"],
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist",
}
}
6 changes: 5 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import * as pkg from "./package.json";
import dts from 'vite-plugin-dts';

const NODE_ENV = process.argv.mode || "development";
const VERSION = pkg.version;
Expand All @@ -19,5 +20,8 @@ export default {
VERSION: JSON.stringify(VERSION),
},

plugins: [cssInjectedByJsPlugin({useStrictCSP: true})],
plugins: [
cssInjectedByJsPlugin({useStrictCSP: true}),
dts({tsconfigPath: './tsconfig.json'})
]
};
Loading