Skip to content

Commit

Permalink
update(eslint): remove some rules from eslint configuration, and fix …
Browse files Browse the repository at this point in the history
…them
  • Loading branch information
dependentmadani committed Jul 22, 2024
1 parent 24aef36 commit 067c736
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 78 deletions.
3 changes: 0 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export default [
rules: {
'n/no-missing-import': ['off'],
'n/no-unsupported-features/node-builtins': ['off'],
'jsdoc/no-types': ['off'],
'jsdoc/require-returns-description': ['off'],
'jsdoc/check-tag-names': ['off'],
'jsdoc/require-jsdoc': ['off'],
"@typescript-eslint/naming-convention": [
"error",
{
Expand Down
60 changes: 21 additions & 39 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Ui from './ui';
import Uploader from './uploader';

import { IconAddBorder, IconStretch, IconAddBackground, IconPicture } from '@codexteam/icons';
import type { ActionConfig, UploadResponseFormat, ImageToolData, ImageConfig, HTMLPasteEventDetailExtended } from './types/types';
import type { ActionConfig, UploadResponseFormat, ImageToolData, ImageConfig, HTMLPasteEventDetailExtended, ImageSetterParam } from './types/types';

type ImageToolConstructorOptions = BlockToolConstructorOptions<ImageToolData, ImageConfig>;

Expand Down Expand Up @@ -150,7 +150,7 @@ export default class ImageTool implements BlockTool {

/**
* Notify core that read-only mode is supported
* @returns { boolean }
* @returns
*/
public static get isReadOnlySupported(): boolean {
return true;
Expand All @@ -160,7 +160,7 @@ export default class ImageTool implements BlockTool {
* Get Tool toolbox settings
* icon - Tool icon's SVG
* title - title to show in toolbox
* @returns {{icon: string, title: string}}
* @returns
*/
public static get toolbox(): ToolboxConfig {
return {
Expand All @@ -171,7 +171,7 @@ export default class ImageTool implements BlockTool {

/**
* Available image tools
* @returns {Array}
* @returns
*/
public static get tunes(): Array<ActionConfig> {
return [
Expand All @@ -198,27 +198,24 @@ export default class ImageTool implements BlockTool {

/**
* Renders Block content
* @public
* @returns {HTMLDivElement}
* @returns
*/
public render(): HTMLDivElement {
return this.ui.render(this.data) as HTMLDivElement;
}

/**
* Validate data: check if Image exists
* @param {ImageToolData} savedData — data received after saving
* @returns {boolean} false if saved data is not correct, otherwise true
* @public
* @param savedData — data received after saving
* @returns false if saved data is not correct, otherwise true
*/
public validate(savedData: ImageToolData): boolean {
return !!savedData.file.url;
}

/**
* Return Block data
* @public
* @returns {ImageToolData}
* @returns
*/
public save(): ImageToolData {
const caption = this.ui.nodes.caption;
Expand All @@ -230,7 +227,6 @@ export default class ImageTool implements BlockTool {

/**
* Returns configuration for block tunes: add background, add border, stretch image
* @public
* @returns TunesMenuConfig
*/
public renderSettings(): TunesMenuConfig {
Expand Down Expand Up @@ -259,7 +255,6 @@ export default class ImageTool implements BlockTool {
/**
* Fires after clicks on the Toolbox Image Icon
* Initiates click on the Select File button
* @public
*/
public appendCallback(): void {
this.ui.nodes.fileButton.click();
Expand All @@ -268,7 +263,7 @@ export default class ImageTool implements BlockTool {
/**
* Specify paste substitutes
* @see {@link https://github.com/codex-team/editor.js/blob/master/docs/tools.md#paste-handling}
* @returns { PasteConfig }
* @returns
*/
public static get pasteConfig(): PasteConfig {
return {
Expand Down Expand Up @@ -298,11 +293,10 @@ export default class ImageTool implements BlockTool {

/**
* Specify paste handlers
* @public
* @see {@link https://github.com/codex-team/editor.js/blob/master/docs/tools.md#paste-handling}
* @param event - editor.js custom paste event
* {@link https://github.com/codex-team/editor.js/blob/master/types/tools/paste-events.d.ts}
* @returns {void}
* @returns
*/
public async onPaste(event: PasteEvent): Promise<void> {
switch (event.type) {
Expand Down Expand Up @@ -344,8 +338,7 @@ export default class ImageTool implements BlockTool {

/**
* Stores all Tool's data
* @private
* @param {ImageToolData} data - data in Image Tool format
* @param data - data in Image Tool format
*/
private set data(data: ImageToolData) {
this.image = data.file;
Expand All @@ -362,19 +355,17 @@ export default class ImageTool implements BlockTool {

/**
* Return Tool data
* @private
* @returns {ImageToolData}
* @returns
*/
private get data(): ImageToolData {
return this._data;
}

/**
* Set new image file
* @private
* @param {object} file - uploaded file data
* @param file - uploaded file data
*/
private set image(file: { url: string } | undefined) {
private set image(file: ImageSetterParam | undefined) {
this._data.file = file || { url: '' };

if (file && file.url) {
Expand All @@ -384,9 +375,7 @@ export default class ImageTool implements BlockTool {

/**
* File uploading callback
* @private
* @param {UploadResponseFormat} response - uploading server response
* @returns {void}
* @param response - uploading server response
*/
private onUpload(response: UploadResponseFormat): void {
if (response.success && response.file.url) {
Expand All @@ -398,9 +387,7 @@ export default class ImageTool implements BlockTool {

/**
* Handle uploader errors
* @private
* @param {string} errorText - uploading error info
* @returns {void}
* @param errorText - uploading error info
*/
private uploadingFailed(errorText: string): void {
console.log('Image Tool: uploading failed because of', errorText);
Expand All @@ -414,9 +401,7 @@ export default class ImageTool implements BlockTool {

/**
* Callback fired when Block Tune is activated
* @private
* @param {string} tuneName - tune that has been clicked
* @returns {void}
* @param tuneName - tune that has been clicked
*/
private tuneToggled(tuneName: keyof ImageToolData): void {
// inverse tune state
Expand All @@ -425,9 +410,8 @@ export default class ImageTool implements BlockTool {

/**
* Set one tune
* @param {string} tuneName - {@link Tunes.tunes}
* @param {boolean} value - tune state
* @returns {void}
* @param tuneName - {@link Tunes.tunes}
* @param value - tune state
*/
private setTune(tuneName: keyof ImageToolData, value: boolean): void {
(this._data[tuneName] as boolean) = value;
Expand All @@ -448,8 +432,7 @@ export default class ImageTool implements BlockTool {

/**
* Show preloader and upload image file
* @param {File} file - file that is currently uploading (from paste)
* @returns {void}
* @param file - file that is currently uploading (from paste)
*/
private uploadFile(file: Blob): void {
this.uploader.uploadByFile(file, {
Expand All @@ -461,8 +444,7 @@ export default class ImageTool implements BlockTool {

/**
* Show preloader and upload image by target url
* @param {string} url - url pasted
* @returns {void}
* @param url - url pasted
*/
private uploadUrl(url: string): void {
this.ui.showPreloader(url);
Expand Down
66 changes: 65 additions & 1 deletion src/types/codexteam__ajax.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,89 @@
/**
* Module declaration for '@codexteam/ajax'.
*/
declare module '@codexteam/ajax' {
/**
* Options for configuring an Ajax request.
*/
export interface AjaxOptions {
/**
* The URL to which the request is sent.
*/
url?: string;
/**
* The data to send with the request.
*/
data?: object;
/**
* The MIME type of the request.
*/
accept?: string;
/**
* The headers to send with the request.
*/
headers?: object;
/**
* A function to call before the request is sent, with the files to be sent.
*/
beforeSend?: (files: File[]) => void;
/**
* The name of the field in the form data to which the file should be assigned.
*/
fieldName?: string;
/**
* The type of the request (e.g., 'POST', 'GET').
*/
type?: string;
}

/**
* Parameter type of selectFiles function in AjaxOptions interface
*/
export type AjaxFileOptionsParam = {
/**
* the accepted file types.
*/
accept: string;
};

/**
* Represents the response from an Ajax request.
* @template T - The type of the response body.
*/
export interface AjaxResponse<T = object> {
/** The body of the response. */
body: T;
}

export function selectFiles(options: { accept: string }): Promise<File[]>;
/**
* Prompts the user to select files and returns a promise that resolves with the selected files.
* @param options - Options for file selection.
* @param options.accept - The accepted file types.
* @returns A promise that resolves with the selected files.
*/
export function selectFiles(options: AjaxFileOptionsParam): Promise<File[]>;

/**
* Sends an Ajax request with the specified options.
* @param options - Options for the Ajax request.
* @returns A promise that resolves with the Ajax response.
*/
export function transport(options: AjaxOptions): Promise<AjaxResponse>;

/**
* Sends a POST request with the specified options.
* @param options - Options for the POST request.
* @returns A promise that resolves with the Ajax response.
*/
export function post(options: AjaxOptions): Promise<AjaxResponse>;

/**
* Represents common content types.
*/
export const contentType: {
/**
* The MIME type for JSON content.
*/
JSON: string;
};
}
17 changes: 16 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import type { HTMLPasteEventDetail } from '@editorjs/editorjs';
* Represents options for uploading, including a function to handle previewing.
*/
export interface UploadOptions {
/**
* Callback function to be called when the preview is ready.
* @param src - The source of the preview as a string.
* @returns void
*/
onPreview: (src: string) => void;
};
}

/**
* User configuration of Image block tunes. Allows to add custom tunes through the config
Expand Down Expand Up @@ -183,3 +188,13 @@ export interface HTMLPasteEventDetailExtended extends HTMLPasteEventDetail {
src: string;
} & HTMLElement;
}

/**
* Parameter type of Image setter function in ImageTool
*/
export type ImageSetterParam = {
/**
* url path of the image
*/
url: string;
};
Loading

0 comments on commit 067c736

Please sign in to comment.