From 999f6e13c7863894ff9ad2291278dfabbb76154c Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 6 Jul 2024 07:33:58 +0200 Subject: [PATCH] fix(TS): Type fixes and improved JSDOCS. (#9978) --- CHANGELOG.md | 6 ++++++ package-lock.json | 2 +- package.json | 2 +- src/Observable.ts | 8 ++++++++ src/shapes/Object/Object.ts | 16 +++++++++------- src/shapes/Text/Text.ts | 4 ++-- src/util/misc/objectEnlive.ts | 1 + 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 608fbaef7d5..570027361d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [next] +## [6.0.2] + +- fix(TS): Type fixes and improved JSDOCS. [#9978](https://github.com/fabricjs/fabric.js/pull/9978) + +## [6.0.1] + - chore(): export InteractiveFabricObject to tweak default values [#9963](https://github.com/fabricjs/fabric.js/pull/9963) - chore(): use deconstruction and constants in place of strings to save some bytes of code [#9593](https://github.com/fabricjs/fabric.js/pull/9593) - tests(): Start moving visual tests to playwrigth [#9481](https://github.com/fabricjs/fabric.js/pull/9481) diff --git a/package-lock.json b/package-lock.json index a61ccf61850..e5535afa2b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "fabric", - "version": "6.0.1", + "version": "6.0.2", "license": "MIT", "devDependencies": { "@babel/cli": "^7.22.9", diff --git a/package.json b/package.json index a084bb78bd5..d90921dfe84 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "fabric", "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", "homepage": "http://fabricjs.com/", - "version": "6.0.1", + "version": "6.0.2", "author": "Juriy Zaytsev ", "contributors": [ { diff --git a/src/Observable.ts b/src/Observable.ts index 1a9387c52ae..5e98140df00 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -112,6 +112,14 @@ export class Observable { } } + /** + * Unsubscribe all event listeners for eventname. + * Do not use this pattern. You could kill internal fabricJS events. + * We know we should have protected events for internal flows, but we don't have yet + * @deprecated + * @param {string} eventName event name (eg. 'after:render') + */ + off(eventName: K): void; /** * unsubscribe an event listener * @param {string} eventName event name (eg. 'after:render') diff --git a/src/shapes/Object/Object.ts b/src/shapes/Object/Object.ts index 93e72cc2f7f..3d761492f47 100644 --- a/src/shapes/Object/Object.ts +++ b/src/shapes/Object/Object.ts @@ -285,19 +285,21 @@ export class FabricObject< } /** - * The class type. Used to identify which class this is. - * This is used for serialization purposes and internally it can be used - * to identify classes. As a developer you could use `instance of Class` - * but to avoid importing all the code and blocking tree shaking we try - * to avoid doing that. + * The class type. + * This is used for serialization and deserialization purposes and internally it can be used + * to identify classes. + * When we transform a class in a plain JS object we need a way to recognize which class it was, + * and the type is the way we do that. It has no other purposes and you should not give one. + * Hard to reach on instances and please do not use to drive instance's logic (this.constructor.type). + * To idenfity a class use instanceof class ( instanceof Rect ). + * We do not do that in fabricJS code because we want to try to have code splitting possible. */ static type = 'FabricObject'; /** * Legacy identifier of the class. Prefer using utils like isType or instanceOf * Will be removed in fabric 7 or 8. - * The setter exists because is very hard to catch all the ways in which a type value - * could be set in the instance + * The setter exists to avoid type errors in old code and possibly current deserialization code. * @TODO add sustainable warning message * @type string * @deprecated diff --git a/src/shapes/Text/Text.ts b/src/shapes/Text/Text.ts index 7d526a64944..446854c9a93 100644 --- a/src/shapes/Text/Text.ts +++ b/src/shapes/Text/Text.ts @@ -94,7 +94,7 @@ interface UniqueTextProps { charSpacing: number; lineHeight: number; fontSize: number; - fontWeight: string; + fontWeight: string | number; fontFamily: string; fontStyle: string; pathSide: TPathSide; @@ -176,7 +176,7 @@ export class FabricText< * @type {(Number|String)} * @default */ - declare fontWeight: string; + declare fontWeight: string | number; /** * Font family diff --git a/src/util/misc/objectEnlive.ts b/src/util/misc/objectEnlive.ts index 3acf82bb1ab..79dbca0a86a 100644 --- a/src/util/misc/objectEnlive.ts +++ b/src/util/misc/objectEnlive.ts @@ -81,6 +81,7 @@ export type EnlivenObjectOptions = Abortable & { }; /** + * @TODO type this correctly. * Creates corresponding fabric instances from their object representations * @param {Object[]} objects Objects to enliven * @param {EnlivenObjectOptions} [options]