Skip to content

Commit fd664cc

Browse files
committed
fix : address feedback from PR review
1 parent 5ef0292 commit fd664cc

File tree

4 files changed

+328
-232
lines changed

4 files changed

+328
-232
lines changed

eslint.config.mjs

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,45 @@ import Codex from "eslint-config-codex";
22
import { plugin as TsPlugin, parser as TsParser } from 'typescript-eslint';
33

44
export default [
5-
...Codex,
6-
{
7-
files: ['src/**/*.ts'],
8-
languageOptions: {
9-
parser: TsParser,
10-
parserOptions: {
11-
project: './tsconfig.json',
12-
tsconfigRootDir: './',
13-
sourceType: 'module',
14-
},
5+
...Codex,
6+
{
7+
files: ['src/**/*.ts'],
8+
languageOptions: {
9+
parser: TsParser,
10+
parserOptions: {
11+
project: './tsconfig.json',
12+
tsconfigRootDir: './',
13+
sourceType: 'module',
14+
},
15+
},
16+
rules: {
17+
'n/no-missing-import': ['off'],
18+
'n/no-unsupported-features/node-builtins': ['off'],
19+
'jsdoc/require-returns-description': ['off'],
20+
'@typescript-eslint/naming-convention': [
21+
'error',
22+
{
23+
'selector': 'variable',
24+
'format': ['camelCase'],
25+
'leadingUnderscore': 'allow'
1526
},
16-
rules: {
17-
'n/no-missing-import': ['off'],
18-
'n/no-unsupported-features/node-builtins': ['off'],
19-
'jsdoc/require-returns-description': ['off'],
20-
'jsdoc/require-jsdoc': [
21-
'error',
22-
{
23-
'require': {
24-
'FunctionDeclaration': true,
25-
'MethodDefinition': true,
26-
'ClassDeclaration': true,
27-
'ArrowFunctionExpression': false,
28-
'FunctionExpression': false,
29-
}
30-
}
31-
],
32-
'@typescript-eslint/explicit-member-accessibility': ['off'],
33-
'@typescript-eslint/naming-convention': [
34-
'error',
35-
{
36-
'selector': 'variable',
37-
'format': ['camelCase'],
38-
'leadingUnderscore': 'allow'
39-
},
40-
],
41-
'@typescript-eslint/no-unsafe-member-access': ['off'],
42-
'@typescript-eslint/no-restricted-types': ['error',
43-
{
44-
'types': {
45-
'String': "Use 'string' instead.",
46-
'Boolean': "Use 'boolean' instead.",
47-
'Number': "Use 'number' instead.",
48-
'Symbol': "Use 'symbol' instead.",
49-
'Object': "Use 'object' instead, or define a more specific type.",
50-
'Function': "Use a specific function type instead, like '(arg: type) => returnType'."
51-
}
52-
}
53-
]
27+
],
28+
'@typescript-eslint/no-unsafe-member-access': ['off'],
29+
'@typescript-eslint/no-restricted-types': ['error',
30+
{
31+
'types': {
32+
'String': "Use 'string' instead.",
33+
'Boolean': "Use 'boolean' instead.",
34+
'Number': "Use 'number' instead.",
35+
'Symbol': "Use 'symbol' instead.",
36+
'Object': "Use 'object' instead, or define a more specific type.",
37+
'Function': "Use a specific function type instead, like '(arg: type) => returnType'."
38+
}
5439
}
55-
},
56-
{
57-
ignores: ['dev/**', 'eslint.config.mjs', 'vite.config.js', 'postcss.config.js']
40+
]
5841
}
42+
},
43+
{
44+
ignores: ['dev/**', 'eslint.config.mjs', 'vite.config.js', 'postcss.config.js']
45+
}
5946
];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"eslint-config-codex": "^2.0.2",
4343
"typescript": "^5.5.3",
4444
"typescript-eslint": "^8.4.0",
45-
"vite": "^4.5.0",
45+
"vite": "^5.4.3",
4646
"vite-plugin-css-injected-by-js": "^3.3.0",
4747
"vite-plugin-dts": "^3.9.1"
4848
},

src/index.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './index.css';
22
import { getLineStartPosition } from './utils/string';
33
import { IconBrackets } from '@codexteam/icons';
4-
import type { API, BlockTool, BlockToolConstructorOptions, PasteEvent, SanitizerConfig } from '@editorjs/editorjs';
4+
import type { API, BlockTool, BlockToolConstructorOptions, BlockToolData, PasteConfig, PasteEvent, SanitizerConfig, ToolboxConfig } from '@editorjs/editorjs';
55

66
/**
77
* CodeTool for Editor.js
@@ -12,7 +12,7 @@ import type { API, BlockTool, BlockToolConstructorOptions, PasteEvent, Sanitizer
1212
/**
1313
* Data structure for CodeTool's data
1414
*/
15-
export interface CodeData {
15+
export interface CodeData extends BlockToolData {
1616
/**
1717
* The code content input by the user
1818
*/
@@ -53,6 +53,16 @@ interface CodeToolNodes {
5353
textarea: HTMLTextAreaElement | null;
5454
}
5555

56+
/**
57+
* Options passed to the constructor of a block tool
58+
*/
59+
interface CodeToolConstructorOptions extends BlockToolConstructorOptions {
60+
/**
61+
* Data specific to the CodeTool
62+
*/
63+
data: CodeData;
64+
}
65+
5666
/**
5767
* Code Tool for the Editor.js allows to include code examples in your articles.
5868
*/
@@ -86,7 +96,7 @@ export default class CodeTool implements BlockTool {
8696
* Notify core that read-only mode is supported
8797
* @returns true if read-only mode is supported
8898
*/
89-
static get isReadOnlySupported(): boolean {
99+
public static get isReadOnlySupported(): boolean {
90100
return true;
91101
}
92102

@@ -95,15 +105,10 @@ export default class CodeTool implements BlockTool {
95105
* This enables multi-line input within the code editor.
96106
* @returns true if line breaks are allowed in the textarea
97107
*/
98-
static get enableLineBreaks(): boolean {
108+
public static get enableLineBreaks(): boolean {
99109
return true;
100110
}
101111

102-
/**
103-
* CodeData — plugin saved data
104-
* code - previously saved plugin code
105-
*/
106-
107112
/**
108113
* Render plugin`s main Element and fill it with saved data
109114
* @param options - tool constricting options
@@ -112,7 +117,7 @@ export default class CodeTool implements BlockTool {
112117
* @param options.api - Editor.js API
113118
* @param options.readOnly - read only mode flag
114119
*/
115-
constructor({ data, config, api, readOnly }: BlockToolConstructorOptions) {
120+
constructor({ data, config, api, readOnly }: CodeToolConstructorOptions) {
116121
this.api = api;
117122
this.readOnly = readOnly;
118123

@@ -131,7 +136,7 @@ export default class CodeTool implements BlockTool {
131136
};
132137

133138
this.data = {
134-
code: data.code as string || '',
139+
code: data.code ?? '',
135140
};
136141

137142
this.nodes.holder = this.drawView();
@@ -199,7 +204,7 @@ export default class CodeTool implements BlockTool {
199204
* - icon: SVG representation of the Tool's icon
200205
* - title: Title to show in the toolbox
201206
*/
202-
static get toolbox(): { icon: string; title: string } {
207+
public static get toolbox(): ToolboxConfig {
203208
return {
204209
icon: IconBrackets,
205210
title: 'Code',
@@ -210,7 +215,7 @@ export default class CodeTool implements BlockTool {
210215
* Default placeholder for CodeTool's textarea
211216
* @returns
212217
*/
213-
static get DEFAULT_PLACEHOLDER(): string {
218+
public static get DEFAULT_PLACEHOLDER(): string {
214219
return 'Enter a code';
215220
}
216221

@@ -219,7 +224,7 @@ export default class CodeTool implements BlockTool {
219224
* Provides configuration to handle CODE tag.
220225
* @returns
221226
*/
222-
static get pasteConfig(): { tags: string[] } {
227+
public static get pasteConfig(): PasteConfig {
223228
return {
224229
tags: ['pre'],
225230
};
@@ -229,7 +234,7 @@ export default class CodeTool implements BlockTool {
229234
* Automatic sanitize config
230235
* @returns
231236
*/
232-
static get sanitize(): SanitizerConfig {
237+
public static get sanitize(): SanitizerConfig {
233238
return {
234239
code: true, // Allow HTML tags
235240
};

0 commit comments

Comments
 (0)