From fbc7c77f32f9f22d211667db918c0fb8b3566e43 Mon Sep 17 00:00:00 2001 From: Alex Matveev Date: Tue, 12 Mar 2024 02:21:25 +0300 Subject: [PATCH] ESLint --- packages/drawing/package-lock.json | 4 +- packages/drawing/package.json | 3 +- packages/drawing/src/drawing.jsx | 77 ++++++++++----------- packages/drawing/src/util/fabric-presets.js | 4 +- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/drawing/package-lock.json b/packages/drawing/package-lock.json index 52a6c371..792ee9ca 100644 --- a/packages/drawing/package-lock.json +++ b/packages/drawing/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ulms/ui-drawing", - "version": "3.3.19", + "version": "3.3.19-dev.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ulms/ui-drawing", - "version": "3.3.19", + "version": "3.3.19-dev.0", "license": "MIT", "dependencies": { "abortcontroller-polyfill": "^1.7.5", diff --git a/packages/drawing/package.json b/packages/drawing/package.json index 1ad7a1ad..7ae5bc7f 100644 --- a/packages/drawing/package.json +++ b/packages/drawing/package.json @@ -1,6 +1,6 @@ { "name": "@ulms/ui-drawing", - "version": "3.3.19", + "version": "3.3.19-dev.0", "description": "Whiteboard for uLMS", "keywords": [ "lerna" @@ -22,6 +22,7 @@ "src" ], "scripts": { + "lint": "eslint --fix --ext js,jsx ./src", "build": "rm -rf ./es/* && BABEL_ENV=es rollup --config ./rollup.config.js index.js" }, "dependencies": { diff --git a/packages/drawing/src/drawing.jsx b/packages/drawing/src/drawing.jsx index 1b85a106..4759d1ee 100644 --- a/packages/drawing/src/drawing.jsx +++ b/packages/drawing/src/drawing.jsx @@ -1,4 +1,4 @@ -/* eslint-disable react/prop-types, max-classes-per-file */ +/* eslint-disable react/prop-types, max-classes-per-file, promise/catch-or-return */ import React from 'react' import { fabric } from 'fabric/dist/fabric.min' import Hammer from 'hammerjs' @@ -62,7 +62,7 @@ function clearExternalSelection () { } let abortController = null -let signal = null; +let signal = null export class Drawing extends React.Component { constructor (props) { @@ -1085,51 +1085,53 @@ export class Drawing extends React.Component { } } - _abortableCreateObjectsPromise = (pageObjects) => { - return new Promise((resolve, reject) => { - let shouldAbort = false - signal.addEventListener('abort', () => { - shouldAbort = true + _abortableCreateObjectsPromise = pageObjects => new Promise((resolve) => { + let shouldAbort = false + + signal.addEventListener('abort', () => { + shouldAbort = true + resolve() + }) + + const normalizedObjects = pageObjects.map(_ => normalizeFields({ ..._, remote: true })).filter(_ => !_._removed) + + if (shouldAbort) return + fabric.util.enlivenObjects(normalizedObjects, (enlivenedObjects) => { + // Есть ситуации, когда во время выполнения enlivenObjects this.canvas уже нет + if (shouldAbort) return + + if (!this.canvas) { resolve() - }); - const normalizedObjects = pageObjects.map(_ => normalizeFields({..._, remote: true})).filter(_ => !_._removed) + return + } - if(shouldAbort) return - fabric.util.enlivenObjects(normalizedObjects, (enlivenedObjects) => { + enlivenedObjects.forEach((object) => { // Есть ситуации, когда во время выполнения enlivenObjects this.canvas уже нет - if(shouldAbort) return - if (!this.canvas) { resolve() + return } - enlivenedObjects.forEach((object) => { - // Есть ситуации, когда во время выполнения enlivenObjects this.canvas уже нет - if (!this.canvas) { - resolve() - return - } + this._fixObjectInteractivity(object) - this._fixObjectInteractivity(object) + this.canvas._objectsMap.set(object._id, object) + }) + if (shouldAbort) return + this.canvas.renderOnAddRemove = false + this.canvas.add(...enlivenedObjects) + this.canvas.renderOnAddRemove = true - this.canvas._objectsMap.set(object._id, object) - }) - if(shouldAbort) return - this.canvas.renderOnAddRemove = false - this.canvas.add(...enlivenedObjects) - this.canvas.renderOnAddRemove = true + if (shouldAbort) { // Если дошли до этого места и прервали загрузку объектов - надо удалить добавленные объекты + this.canvas.remove(...enlivenedObjects) - if(shouldAbort) { // Если дошли до этого места и прервали загрузку объектов - надо удалить добавленные объекты - this.canvas.remove(...enlivenedObjects) - return - } + return + } - resolve() - }) + resolve() }) - } + }) createCanvasObjects = (pageObjects) => { if (abortController) { @@ -1138,16 +1140,13 @@ export class Drawing extends React.Component { abortController = null } - abortController = new window.AbortController(); - signal = abortController.signal; + abortController = new window.AbortController() + signal = abortController.signal this.clearCanvasObjects() if (pageObjects.length) { this._abortableCreateObjectsPromise(pageObjects) - .then(() => { - this.canvas.requestRenderAll() - } - ) + .then(() => this.canvas.requestRenderAll()) .finally(() => { signal = null abortController = null diff --git a/packages/drawing/src/util/fabric-presets.js b/packages/drawing/src/util/fabric-presets.js index d5551308..0e76a0eb 100644 --- a/packages/drawing/src/util/fabric-presets.js +++ b/packages/drawing/src/util/fabric-presets.js @@ -80,7 +80,7 @@ fabric.Line.prototype.calcLineEndpointCoords = function calcLineEndpointCoords ( const textBoxOnInput = fabric.Textbox.prototype.onInput const textBoxFromObject = fabric.Textbox.fromObject -fabric.Textbox.prototype.onInput = function (e) { +fabric.Textbox.prototype.onInput = function onInput (e) { textBoxOnInput.call(this, e) if (this.canvas) { @@ -93,7 +93,7 @@ fabric.Textbox.prototype.onInput = function (e) { } } -fabric.Textbox.fromObject = function (object, callback) { +fabric.Textbox.fromObject = function fromObject (object, callback) { if (object.fontFamily.includes('BlinkMacSystemFont')) { // eslint-disable-next-line no-param-reassign object.fontFamily = object.fontFamily.split(', ').filter(item => item !== 'BlinkMacSystemFont').join(', ')