Skip to content

Commit

Permalink
update(eslint): eslint now is working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Jul 21, 2024
1 parent 83606cf commit 1d03215
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 72 deletions.
18 changes: 18 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,32 @@ export default [
'jsdoc/no-types': ['off'],
'jsdoc/require-returns-description': ['off'],
'jsdoc/check-tag-names': ['off'],
'jsdoc/require-jsdoc': ['off'],
'@typescript-eslint/no-unsafe-assignment': ['off'],
'@typescript-eslint/no-unsafe-member-access': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "variable",
"format": ["camelCase"],
"leadingUnderscore": "allow"
},
],
"@typescript-eslint/ban-types": ["error",
{
"types": {
"String": true,
"Boolean": true,
"Number": true,
"Symbol": true,
"{}": false,
"Object": true,
"object": false,
"Function": false,
},
"extendDefaults": true
}
]
}
},
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default class ImageTool implements BlockTool {
public async onPaste(event: CustomEvent): Promise<void> {
switch (event.type) {
case 'tag': {
const image: { src: string } = event.detail.data;
const image = event.detail.data as { src: string };

/** Images from PDF */
if (/^blob:/.test(image.src)) {
Expand All @@ -323,13 +323,13 @@ export default class ImageTool implements BlockTool {
break;
}
case 'pattern': {
const url: string = event.detail.data;
const url = event.detail.data as string;

this.uploadUrl(url);
break;
}
case 'file': {
const file: Blob = event.detail.file;
const file = event.detail.file as Blob;

this.uploadFile(file);
break;
Expand Down Expand Up @@ -389,7 +389,7 @@ export default class ImageTool implements BlockTool {
* @returns {void}
*/
private onUpload(response: UploadResponseFormat): void {
if (response.success && response.file) {
if (response.success && response.file.url) {
this.image = response.file;
} else {
this.uploadingFailed('incorrect response: ' + JSON.stringify(response));
Expand All @@ -399,7 +399,7 @@ export default class ImageTool implements BlockTool {
/**
* Handle uploader errors
* @private
* @param {string} errorText - uploading error text
* @param {string} errorText - uploading error info
* @returns {void}
*/
private uploadingFailed(errorText: string): void {
Expand All @@ -420,7 +420,7 @@ export default class ImageTool implements BlockTool {
*/
private tuneToggled(tuneName: keyof ImageToolData): void {
// inverse tune state
this.setTune(tuneName, !this._data[tuneName]);
this.setTune(tuneName, this._data[tuneName] != undefined ? false : true);
}

/**
Expand Down
87 changes: 46 additions & 41 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ interface ConstructorParams {
* - apply tune view
*/
export default class Ui {
/**
* API instance for Editor.js.
*/
/**
* Nodes representing various elements in the UI.
*/
public nodes: Nodes;

/**
* API instance for Editor.js.
*/
private api: API;

/**
Expand All @@ -108,15 +113,11 @@ export default class Ui {
private readOnly: boolean;

/**
* Nodes representing various elements in the UI.
*/
public nodes: Nodes;
/**
* @param ui - image tool Ui module
* @param ui.api - Editor.js API
* @param ui.config - user config
* @param ui.onSelectFile - callback for clicks on Select file button
* @param ui.readOnly - read-only mode flag
* @param {object} ui - image tool Ui module
* @param {object} ui.api - Editor.js API
* @param {ImageConfig} ui.config - user config
* @param {Function} ui.onSelectFile - callback for clicks on Select file button
* @param {boolean} ui.readOnly - read-only mode flag
*/
constructor({ api, config, onSelectFile, readOnly }: ConstructorParams) {
this.api = api;
Expand Down Expand Up @@ -153,9 +154,9 @@ export default class Ui {

/**
* CSS classes
* @returns
* @returns {object}
*/
get CSS(): Record<string, string> {
public get CSS(): Record<string, string> {
return {
baseClass: this.api.styles.block,
loading: this.api.styles.loader,
Expand All @@ -175,11 +176,11 @@ export default class Ui {

/**
* Renders tool UI
* @param toolData - saved tool data
* @returns
* @param {ImageToolData} toolData - saved tool data
* @returns {Element}
*/
render(toolData: ImageToolData): HTMLElement {
if (!toolData.file || Object.keys(toolData.file).length === 0) {
public render(toolData: ImageToolData): HTMLElement {
if (toolData.file == undefined || Object.keys(toolData.file).length === 0) {
this.toggleStatus(UiState.Empty);
} else {
this.toggleStatus(UiState.Uploading);
Expand All @@ -190,12 +191,12 @@ export default class Ui {

/**
* Creates upload-file button
* @returns
* @returns {Element}
*/
createFileButton(): HTMLElement {
public createFileButton(): HTMLElement {
const button = make('div', [this.CSS.button]);

button.innerHTML = this.config.buttonContent || `${IconPicture} ${this.api.i18n.t('Select an Image')}`;
button.innerHTML = this.config.buttonContent != undefined ? this.config.buttonContent : `${IconPicture} ${this.api.i18n.t('Select an Image')}`;

button.addEventListener('click', () => {
this.onSelectFile();
Expand All @@ -206,30 +207,30 @@ export default class Ui {

/**
* Shows uploading preloader
* @param src - preview source
* @returns
* @param {string} src - preview source
* @returns {void}
*/
showPreloader(src: string): void {
public showPreloader(src: string): void {
this.nodes.imagePreloader.style.backgroundImage = `url(${src})`;

this.toggleStatus(UiState.Uploading);
}

/**
* Hide uploading preloader
* @returns
* @returns {void}
*/
hidePreloader(): void {
public hidePreloader(): void {
this.nodes.imagePreloader.style.backgroundImage = '';
this.toggleStatus(UiState.Empty);
}

/**
* Shows an image
* @param url - image source
* @returns
* @param {string} url - image source
* @returns {void}
*/
fillImage(url: string): void {
public fillImage(url: string): void {
/**
* Check for a source extension to compose element correctly: video tag for mp4, img — for others
*/
Expand All @@ -243,6 +244,7 @@ export default class Ui {
* We use eventName variable because IMG and VIDEO tags have different event to be called on source load
* - IMG: load
* - VIDEO: loadeddata
* @type {string}
*/
let eventName = 'load';

Expand All @@ -252,6 +254,7 @@ export default class Ui {
if (tag === 'VIDEO') {
/**
* Add attributes for playing muted mp4 as a gif
* @type {boolean}
*/
attributes.autoplay = true;
attributes.loop = true;
Expand All @@ -260,12 +263,14 @@ export default class Ui {

/**
* Change event to be listened
* @type {string}
*/
eventName = 'loadeddata';
}

/**
* Compose tag with defined attributes
* @type {Element}
*/
this.nodes.imageEl = make(tag, this.CSS.imageEl, attributes);

Expand All @@ -278,7 +283,7 @@ export default class Ui {
/**
* Preloader does not exists on first rendering with presaved data
*/
if (this.nodes.imagePreloader) {
if (this.nodes.imagePreloader != undefined) {
this.nodes.imagePreloader.style.backgroundImage = '';
}
});
Expand All @@ -288,21 +293,21 @@ export default class Ui {

/**
* Shows caption input
* @param text - caption text
* @returns
* @param {string} text - caption content text
* @returns {void}
*/
fillCaption(text: string): void {
if (this.nodes.caption) {
public fillCaption(text: string): void {
if (this.nodes.caption != undefined) {
this.nodes.caption.innerHTML = text;
}
}

/**
* Changes UI status
* @param status - see {@link Ui.status} constants
* @returns
* @param {string} status - see {@link Ui.status} constants
* @returns {void}
*/
toggleStatus(status: UiState): void {
public toggleStatus(status: UiState): void {
for (const statusType in UiState) {
if (Object.prototype.hasOwnProperty.call(UiState, statusType)) {
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${UiState[statusType as keyof typeof UiState]}`, status === UiState[statusType as keyof typeof UiState]);
Expand All @@ -312,11 +317,11 @@ export default class Ui {

/**
* Apply visual representation of activated tune
* @param tuneName - one of available tunes {@link Tunes.tunes}
* @param status - true for enable, false for disable
* @returns
* @param {string} tuneName - one of available tunes {@link Tunes.tunes}
* @param {boolean} status - true for enable, false for disable
* @returns {void}
*/
applyTune(tuneName: string, status: boolean): void {
public applyTune(tuneName: string, status: boolean): void {
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${tuneName}`, status);
}
}
Loading

0 comments on commit 1d03215

Please sign in to comment.