diff --git a/package.json b/package.json index 5e3fea1f0..66ba375ec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 4e3a4dfa3..f5ff261ff 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -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; +}; diff --git a/packages/core/src/util/Constants.ts b/packages/core/src/util/Constants.ts index 0b76dce7d..073e369ba 100644 --- a/packages/core/src/util/Constants.ts +++ b/packages/core/src/util/Constants.ts @@ -63,6 +63,12 @@ export const enum DIALECT { STRICTHTML = 'strictHtml', }; +/** + * Name of the field to be used to store the object ID. Default is + * mxObjectId. + */ +export const IDENTITY_FIELD_NAME = 'mxObjectId'; + /** * Defines the SVG namespace. */ diff --git a/packages/core/src/util/Dictionary.ts b/packages/core/src/util/Dictionary.ts index bd13b0823..eb44313b1 100644 --- a/packages/core/src/util/Dictionary.ts +++ b/packages/core/src/util/Dictionary.ts @@ -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 = { @@ -34,7 +35,7 @@ type Visitor = (key: MapKey, value: U) => void; * * Constructs a new dictionary which allows object to be used as keys. */ -class Dictionary { +class Dictionary { constructor() { this.clear(); } diff --git a/packages/core/src/util/ObjectIdentity.ts b/packages/core/src/util/ObjectIdentity.ts index 27fdb86cb..b2439a02a 100644 --- a/packages/core/src/util/ObjectIdentity.ts +++ b/packages/core/src/util/ObjectIdentity.ts @@ -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 * mxObjectId. */ - 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]; } } diff --git a/packages/core/src/view/cell/Cell.ts b/packages/core/src/view/cell/Cell.ts index fa2e64f86..23689ded2 100644 --- a/packages/core/src/view/cell/Cell.ts +++ b/packages/core/src/view/cell/Cell.ts @@ -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(); } diff --git a/packages/core/src/view/cell/CellOverlay.ts b/packages/core/src/view/cell/CellOverlay.ts index 57a309b82..f9eb3180c 100644 --- a/packages/core/src/view/cell/CellOverlay.ts +++ b/packages/core/src/view/cell/CellOverlay.ts @@ -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 , and * (default). */ -class CellOverlay extends EventSource { +class CellOverlay extends EventSource implements ObjectIdentity { constructor( image: ImageBox, tooltip: string | null = null,