deps: bump typescript to 4.8.3, fix Dictionary typings
When running `generate-types` script in core package there is typescript error TS2345 in src/util/Dictionary.ts, added changes to fix it. - Moved types IdentityObject and IdentityFunction to types.ts - Renamed const FIELD_NAME to IDENTITY_FIELD_NAME and moved it to util/Constants.ts - Set Cell and CellOverlay to implement IdentityObjectdevelopment
parent
02ea6f1ceb
commit
b62eb538f7
|
@ -26,15 +26,15 @@
|
|||
"@lerna/filter-options": "^4.0.0",
|
||||
"babel-loader": "^8.2.3",
|
||||
"better-docs": "^2.3.2",
|
||||
"css-loader": "^6.5.1",
|
||||
"cross-env": "~7.0.3",
|
||||
"css-loader": "^6.5.1",
|
||||
"file-loader": "^6.2.0",
|
||||
"jsdoc": "^3.6.7",
|
||||
"lerna": "^4.0.0",
|
||||
"prettier": "^2.5.0",
|
||||
"style-loader": "^3.3.1",
|
||||
"typedoc": "^0.22.10",
|
||||
"typescript": "^4.5.2",
|
||||
"typedoc": "^0.23.15",
|
||||
"typescript": "^4.8.3",
|
||||
"url-loader": "^4.1.1",
|
||||
"webpack": "^5.64.4",
|
||||
"webpack-cli": "^4.9.1",
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { DIRECTION } from './util/Constants';
|
||||
import { DIRECTION, IDENTITY_FIELD_NAME } from './util/Constants';
|
||||
import type Cell from './view/cell/Cell';
|
||||
import type CellState from './view/cell/CellState';
|
||||
import EventSource from './view/event/EventSource';
|
||||
|
@ -316,3 +316,13 @@ export interface PopupMenuItem extends HTMLElement {
|
|||
activeRow: PopupMenuItem | null;
|
||||
eventReceiver: HTMLElement | null;
|
||||
}
|
||||
|
||||
export type IdentityObject = {
|
||||
[IDENTITY_FIELD_NAME]?: string;
|
||||
[k: string]: any;
|
||||
};
|
||||
|
||||
export type IdentityFunction = {
|
||||
(): any;
|
||||
[IDENTITY_FIELD_NAME]?: string;
|
||||
};
|
||||
|
|
|
@ -63,6 +63,12 @@ export const enum DIALECT {
|
|||
STRICTHTML = 'strictHtml',
|
||||
};
|
||||
|
||||
/**
|
||||
* Name of the field to be used to store the object ID. Default is
|
||||
* <code>mxObjectId</code>.
|
||||
*/
|
||||
export const IDENTITY_FIELD_NAME = 'mxObjectId';
|
||||
|
||||
/**
|
||||
* Defines the SVG namespace.
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IdentityFunction, IdentityObject } from 'src/types';
|
||||
import ObjectIdentity from './ObjectIdentity';
|
||||
|
||||
//type Dictionary<T, U> = {
|
||||
|
@ -34,7 +35,7 @@ type Visitor<MapKey, U> = (key: MapKey, value: U) => void;
|
|||
*
|
||||
* Constructs a new dictionary which allows object to be used as keys.
|
||||
*/
|
||||
class Dictionary<T, U> {
|
||||
class Dictionary<T extends IdentityObject | IdentityFunction | null, U> {
|
||||
constructor() {
|
||||
this.clear();
|
||||
}
|
||||
|
|
|
@ -16,19 +16,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IdentityFunction, IdentityObject } from 'src/types';
|
||||
import { IDENTITY_FIELD_NAME } from './Constants';
|
||||
import { getFunctionName } from './StringUtils';
|
||||
|
||||
const FIELD_NAME = 'mxObjectId';
|
||||
|
||||
type IdentityObject = {
|
||||
[FIELD_NAME]?: string;
|
||||
[k: string]: any;
|
||||
};
|
||||
|
||||
type IdentityFunction = {
|
||||
(): any;
|
||||
[FIELD_NAME]?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class
|
||||
|
@ -44,7 +35,7 @@ class ObjectIdentity {
|
|||
* Name of the field to be used to store the object ID. Default is
|
||||
* <code>mxObjectId</code>.
|
||||
*/
|
||||
static FIELD_NAME = FIELD_NAME;
|
||||
static FIELD_NAME = IDENTITY_FIELD_NAME;
|
||||
|
||||
/**
|
||||
* Current counter.
|
||||
|
@ -56,15 +47,15 @@ class ObjectIdentity {
|
|||
*/
|
||||
static get(obj: IdentityObject | IdentityFunction | null) {
|
||||
if (obj) {
|
||||
if (obj[FIELD_NAME] === null || obj[FIELD_NAME] === undefined) {
|
||||
if (obj[IDENTITY_FIELD_NAME] === null || obj[IDENTITY_FIELD_NAME] === undefined) {
|
||||
if (typeof obj === 'object') {
|
||||
const ctor = getFunctionName(obj.constructor);
|
||||
obj[FIELD_NAME] = `${ctor}#${ObjectIdentity.counter++}`;
|
||||
obj[IDENTITY_FIELD_NAME] = `${ctor}#${ObjectIdentity.counter++}`;
|
||||
} else if (typeof obj === 'function') {
|
||||
obj[FIELD_NAME] = `Function#${ObjectIdentity.counter++}`;
|
||||
obj[IDENTITY_FIELD_NAME] = `Function#${ObjectIdentity.counter++}`;
|
||||
}
|
||||
}
|
||||
return obj[FIELD_NAME] as string;
|
||||
return obj[IDENTITY_FIELD_NAME] as string;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -73,7 +64,7 @@ class ObjectIdentity {
|
|||
* Deletes the ID from the given object or function.
|
||||
*/
|
||||
static clear(obj: IdentityObject | IdentityFunction) {
|
||||
delete obj[FIELD_NAME];
|
||||
delete obj[IDENTITY_FIELD_NAME];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import { removeWhitespace } from '../../util/StringUtils';
|
|||
import { importNode } from '../../util/domUtils';
|
||||
import Codec from '../../serialization/Codec';
|
||||
|
||||
import type { CellStyle, FilterFunction } from '../../types';
|
||||
import type { CellStyle, FilterFunction, IdentityObject } from '../../types';
|
||||
|
||||
/**
|
||||
* Cells are the elements of the graph model. They represent the state
|
||||
|
@ -74,7 +74,7 @@ import type { CellStyle, FilterFunction } from '../../types';
|
|||
* ```
|
||||
* @class Cell
|
||||
*/
|
||||
export class Cell {
|
||||
export class Cell implements IdentityObject {
|
||||
constructor(
|
||||
value: any = null,
|
||||
geometry: Geometry | null = null,
|
||||
|
@ -83,7 +83,6 @@ export class Cell {
|
|||
this.value = value;
|
||||
this.setGeometry(geometry);
|
||||
this.setStyle(style);
|
||||
|
||||
if (this.onInit) {
|
||||
this.onInit();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import Rectangle from '../geometry/Rectangle';
|
|||
import EventSource from '../event/EventSource';
|
||||
import ImageBox from '../image/ImageBox';
|
||||
import CellState from './CellState';
|
||||
import ObjectIdentity from 'src/util/ObjectIdentity';
|
||||
|
||||
/**
|
||||
* Extends {@link EventSource} to implement a graph overlay, represented by an icon
|
||||
|
@ -72,7 +73,7 @@ import CellState from './CellState';
|
|||
* values are <ALIGN_TOP>, <ALIGN_MIDDLE> and <ALIGN_BOTTOM>
|
||||
* (default).
|
||||
*/
|
||||
class CellOverlay extends EventSource {
|
||||
class CellOverlay extends EventSource implements ObjectIdentity {
|
||||
constructor(
|
||||
image: ImageBox,
|
||||
tooltip: string | null = null,
|
||||
|
|
Loading…
Reference in New Issue