From 044bba2532322afd96dfec2cb68586c200eea188 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Fri, 6 Oct 2023 06:11:30 -0700 Subject: [PATCH] Remove SModelExtension interface (#389) Remove the empty `SModelExtension` interface and adapt type doc of feature extension interfaces. Fixes #387 --- .../src/base/model/smodel-extension.ts | 21 ------------------- packages/sprotty/src/features/bounds/model.ts | 14 +++++++++---- .../sprotty/src/features/decoration/model.ts | 6 ++++-- .../sprotty/src/features/edge-layout/model.ts | 8 ++++--- .../src/features/edit/create-on-drag.ts | 6 ++++-- packages/sprotty/src/features/edit/delete.ts | 6 ++++-- packages/sprotty/src/features/edit/model.ts | 12 ++++++++--- packages/sprotty/src/features/expand/model.ts | 5 +++-- packages/sprotty/src/features/fade/model.ts | 6 ++++-- packages/sprotty/src/features/hover/model.ts | 6 ++++-- packages/sprotty/src/features/move/model.ts | 5 +++-- .../sprotty/src/features/nameable/model.ts | 8 ++++--- .../sprotty/src/features/projection/model.ts | 3 +-- .../sprotty/src/features/routing/model.ts | 14 +++++++------ packages/sprotty/src/features/select/model.ts | 6 ++++-- packages/sprotty/src/index.ts | 1 - 16 files changed, 68 insertions(+), 59 deletions(-) delete mode 100644 packages/sprotty/src/base/model/smodel-extension.ts diff --git a/packages/sprotty/src/base/model/smodel-extension.ts b/packages/sprotty/src/base/model/smodel-extension.ts deleted file mode 100644 index 17d83c82..00000000 --- a/packages/sprotty/src/base/model/smodel-extension.ts +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2017-2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -/** - * Interface to mark interefaces that extend the properties of SModelElements, - * usually to store data to support some feature. - */ -export interface SModelExtension {} diff --git a/packages/sprotty/src/features/bounds/model.ts b/packages/sprotty/src/features/bounds/model.ts index f22795d9..3b2b9cde 100644 --- a/packages/sprotty/src/features/bounds/model.ts +++ b/packages/sprotty/src/features/bounds/model.ts @@ -16,7 +16,6 @@ import { Bounds, Dimension, isBounds, Point } from 'sprotty-protocol/lib/utils/geometry'; import { SChildElementImpl, SModelElementImpl, SModelRootImpl, SParentElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; import { findParentByFeature } from '../../base/model/smodel-utils'; import { DOMHelper } from '../../base/views/dom-helper'; import { ViewerOptions } from '../../base/views/viewer-options'; @@ -32,8 +31,10 @@ export const alignFeature = Symbol('alignFeature'); * Model elements that implement this interface have a position and a size. * Note that this definition differs from the one in `sprotty-protocol` because this is * used in the _internal model_, while the other is used in the _external model_. + * + * Feature extension interface for {@link boundsFeature}. */ -export interface BoundsAware extends SModelExtension { +export interface BoundsAware { bounds: Bounds } @@ -46,15 +47,20 @@ export interface LayoutContainer extends LayoutableChild { export type ModelLayoutOptions = { [key: string]: string | number | boolean }; -export interface LayoutableChild extends SModelExtension, BoundsAware { +/** + * Feature extension interface for {@link layoutableChildFeature}. + */ +export interface LayoutableChild extends BoundsAware { layoutOptions?: ModelLayoutOptions } /** * Used to adjust elements whose bounding box is not at the origin, e.g. * labels, or pre-rendered SVG figures. + * + * Feature extension interface for {@link alignFeature}. */ -export interface Alignable extends SModelExtension { +export interface Alignable { alignment: Point } diff --git a/packages/sprotty/src/features/decoration/model.ts b/packages/sprotty/src/features/decoration/model.ts index 709f3224..b10f8223 100644 --- a/packages/sprotty/src/features/decoration/model.ts +++ b/packages/sprotty/src/features/decoration/model.ts @@ -14,14 +14,16 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { SModelExtension } from '../../base/model/smodel-extension'; import { SModelElementImpl } from '../../base/model/smodel'; import { SShapeElementImpl, boundsFeature } from '../bounds/model'; import { hoverFeedbackFeature, popupFeature } from '../hover/model'; export const decorationFeature = Symbol('decorationFeature'); -export interface Decoration extends SModelExtension { +/** + * Feature extension interface for {@link decorationFeature}. + */ +export interface Decoration { } export function isDecoration(e: T): e is T & Decoration { diff --git a/packages/sprotty/src/features/edge-layout/model.ts b/packages/sprotty/src/features/edge-layout/model.ts index 56f4583f..c3ca0458 100644 --- a/packages/sprotty/src/features/edge-layout/model.ts +++ b/packages/sprotty/src/features/edge-layout/model.ts @@ -14,14 +14,16 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { SModelExtension } from '../../base/model/smodel-extension'; import { SModelElementImpl, SChildElementImpl } from '../../base/model/smodel'; import { BoundsAware, isBoundsAware } from '../bounds/model'; import { SRoutableElementImpl } from '../routing/model'; export const edgeLayoutFeature = Symbol('edgeLayout'); -export interface EdgeLayoutable extends SModelExtension { +/** + * Feature extension interface for {@link edgeLayoutFeature}. + */ +export interface EdgeLayoutable { edgePlacement: EdgePlacement } @@ -33,7 +35,7 @@ export function isEdgeLayoutable(element: T): eleme && element.hasFeature(edgeLayoutFeature); } -function checkEdgeLayoutable(element: SChildElementImpl): element is SChildElementImpl & EdgeLayoutable{ +function checkEdgeLayoutable(element: SChildElementImpl): element is SChildElementImpl & EdgeLayoutable { return 'edgePlacement' in element; } diff --git a/packages/sprotty/src/features/edit/create-on-drag.ts b/packages/sprotty/src/features/edit/create-on-drag.ts index d0395998..7085e539 100644 --- a/packages/sprotty/src/features/edit/create-on-drag.ts +++ b/packages/sprotty/src/features/edit/create-on-drag.ts @@ -16,11 +16,13 @@ import { Action } from "sprotty-protocol/lib/actions"; import { SModelElementImpl } from "../../base/model/smodel"; -import { SModelExtension } from "../../base/model/smodel-extension"; export const creatingOnDragFeature = Symbol('creatingOnDragFeature'); -export interface CreatingOnDrag extends SModelExtension { +/** + * Feature extension interface for {@link creatingOnDragFeature}. + */ +export interface CreatingOnDrag { createAction(id: string): Action; } diff --git a/packages/sprotty/src/features/edit/delete.ts b/packages/sprotty/src/features/edit/delete.ts index a1ecf758..609445f7 100644 --- a/packages/sprotty/src/features/edit/delete.ts +++ b/packages/sprotty/src/features/edit/delete.ts @@ -18,12 +18,14 @@ import { inject, injectable } from 'inversify'; import { DeleteElementAction } from 'sprotty-protocol/lib/actions'; import { Command, CommandExecutionContext, CommandReturn } from '../../base/commands/command'; import { SModelElementImpl, SParentElementImpl, SChildElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; import { TYPES } from '../../base/types'; export const deletableFeature = Symbol('deletableFeature'); -export interface Deletable extends SModelExtension { +/** + * Feature extension interface for {@link deletableFeature}. + */ +export interface Deletable { } export function isDeletable(element: T): element is T & Deletable & SChildElementImpl { diff --git a/packages/sprotty/src/features/edit/model.ts b/packages/sprotty/src/features/edit/model.ts index 3c362176..28eddef9 100644 --- a/packages/sprotty/src/features/edit/model.ts +++ b/packages/sprotty/src/features/edit/model.ts @@ -16,7 +16,6 @@ import { Dimension, Point } from 'sprotty-protocol/lib/utils/geometry'; import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; import { SRoutableElementImpl } from '../routing/model'; export const editFeature = Symbol('editFeature'); @@ -25,9 +24,13 @@ export function canEditRouting(element: SModelElementImpl): element is SRoutable return element instanceof SRoutableElementImpl && element.hasFeature(editFeature); } + export const editLabelFeature = Symbol('editLabelFeature'); -export interface EditableLabel extends SModelExtension { +/** + * Feature extension interface for {@link editLabelFeature}. + */ +export interface EditableLabel { text: string; readonly isMultiLine?: boolean; readonly editControlDimension?: Dimension; @@ -40,7 +43,10 @@ export function isEditableLabel(element: T): elemen export const withEditLabelFeature = Symbol('withEditLabelFeature'); -export interface WithEditableLabel extends SModelExtension { +/** + * Feature extension interface for {@link withEditLabelFeature}. + */ +export interface WithEditableLabel { readonly editableLabel?: EditableLabel & SModelElementImpl; } diff --git a/packages/sprotty/src/features/expand/model.ts b/packages/sprotty/src/features/expand/model.ts index 166badec..60b4ee8a 100644 --- a/packages/sprotty/src/features/expand/model.ts +++ b/packages/sprotty/src/features/expand/model.ts @@ -15,14 +15,15 @@ ********************************************************************************/ import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const expandFeature = Symbol('expandFeature'); /** * Model elements that implement this interface can be expanded/collapsed + * + * Feature extension interface for {@link expandFeature}. */ -export interface Expandable extends SModelExtension { +export interface Expandable { expanded: boolean } diff --git a/packages/sprotty/src/features/fade/model.ts b/packages/sprotty/src/features/fade/model.ts index 84bf838e..abe8b585 100644 --- a/packages/sprotty/src/features/fade/model.ts +++ b/packages/sprotty/src/features/fade/model.ts @@ -15,11 +15,13 @@ ********************************************************************************/ import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const fadeFeature = Symbol('fadeFeature'); -export interface Fadeable extends SModelExtension { +/** +* Feature extension interface for {@link fadeFeature}. + */ +export interface Fadeable { opacity: number } diff --git a/packages/sprotty/src/features/hover/model.ts b/packages/sprotty/src/features/hover/model.ts index 093d596b..5feeb2bd 100644 --- a/packages/sprotty/src/features/hover/model.ts +++ b/packages/sprotty/src/features/hover/model.ts @@ -15,11 +15,13 @@ ********************************************************************************/ import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const hoverFeedbackFeature = Symbol('hoverFeedbackFeature'); -export interface Hoverable extends SModelExtension { +/** + * Feature extension interface for {@link hoverFeedbackFeature}. + */ +export interface Hoverable { hoverFeedback: boolean } diff --git a/packages/sprotty/src/features/move/model.ts b/packages/sprotty/src/features/move/model.ts index 44f0e4bf..0afd88bb 100644 --- a/packages/sprotty/src/features/move/model.ts +++ b/packages/sprotty/src/features/move/model.ts @@ -16,15 +16,16 @@ import { Point } from 'sprotty-protocol/lib/utils/geometry'; import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const moveFeature = Symbol('moveFeature'); /** * An element that can be placed at a specific location using its position * property. + * + * Feature extension interface for {@link moveFeature}. */ -export interface Locateable extends SModelExtension { +export interface Locateable { position: Point } diff --git a/packages/sprotty/src/features/nameable/model.ts b/packages/sprotty/src/features/nameable/model.ts index 92731865..f1b94cb5 100644 --- a/packages/sprotty/src/features/nameable/model.ts +++ b/packages/sprotty/src/features/nameable/model.ts @@ -15,11 +15,13 @@ ********************************************************************************/ import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const nameFeature = Symbol('nameableFeature'); -export interface Nameable extends SModelExtension { +/** + * Feature extension interface for {@link nameableFeature}. + */ +export interface Nameable { name: string } @@ -27,7 +29,7 @@ export function isNameable(element: SModelElementImpl): element is SModelElement return element.hasFeature(nameFeature); } -export function name(element: SModelElementImpl): string|undefined { +export function name(element: SModelElementImpl): string | undefined { if (isNameable(element)) { return element.name; } else { diff --git a/packages/sprotty/src/features/projection/model.ts b/packages/sprotty/src/features/projection/model.ts index ac6ad911..37499296 100644 --- a/packages/sprotty/src/features/projection/model.ts +++ b/packages/sprotty/src/features/projection/model.ts @@ -18,7 +18,6 @@ import { Viewport } from 'sprotty-protocol/lib/model'; import { Bounds, Dimension } from 'sprotty-protocol/lib/utils/geometry'; import { hasOwnProperty } from 'sprotty-protocol/lib/utils/object'; import { SChildElementImpl, SModelRootImpl, SParentElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; import { transformToRootBounds } from '../../base/model/smodel-utils'; import { isBoundsAware } from '../bounds/model'; @@ -27,7 +26,7 @@ import { isBoundsAware } from '../bounds/model'; * _Note:_ If set, the projectedBounds property will be prefered over the model element bounds. * Otherwise model elements also have to be `BoundsAware` so their projections can be shown. */ -export interface Projectable extends SModelExtension { +export interface Projectable { projectionCssClasses: string[], projectedBounds?: Bounds, } diff --git a/packages/sprotty/src/features/routing/model.ts b/packages/sprotty/src/features/routing/model.ts index f8c3c682..bb7478b2 100644 --- a/packages/sprotty/src/features/routing/model.ts +++ b/packages/sprotty/src/features/routing/model.ts @@ -16,7 +16,6 @@ import { Bounds, Point } from 'sprotty-protocol/lib/utils/geometry'; import { SChildElementImpl, SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; import { FluentIterable } from '../../utils/iterable'; import { SShapeElementImpl } from '../bounds/model'; import { deletableFeature } from '../edit/delete'; @@ -54,7 +53,10 @@ export abstract class SRoutableElementImpl extends SChildElementImpl { export const connectableFeature = Symbol('connectableFeature'); -export interface Connectable extends SModelExtension { +/** + * Feature extension interface for {@link connectableFeature}. + */ +export interface Connectable { canConnect(routable: SRoutableElementImpl, role: 'source' | 'target'): boolean; } @@ -74,7 +76,7 @@ export function getAbsoluteRouteBounds(model: Readonly, ro } export function getRouteBounds(route: Point[]): Bounds { - const bounds = { x: NaN, y: NaN, width: 0, height: 0}; + const bounds = { x: NaN, y: NaN, width: 0, height: 0 }; for (const point of route) { if (isNaN(bounds.x)) { bounds.x = point.x; @@ -104,9 +106,9 @@ export function getRouteBounds(route: Point[]): Bounds { */ export abstract class SConnectableElementImpl extends SShapeElementImpl implements Connectable { - get anchorKind(): string | undefined{ - return undefined; - } + get anchorKind(): string | undefined { + return undefined; + } strokeWidth: number = 0; diff --git a/packages/sprotty/src/features/select/model.ts b/packages/sprotty/src/features/select/model.ts index bbcd110d..76094f6c 100644 --- a/packages/sprotty/src/features/select/model.ts +++ b/packages/sprotty/src/features/select/model.ts @@ -15,11 +15,13 @@ ********************************************************************************/ import { SModelElementImpl } from '../../base/model/smodel'; -import { SModelExtension } from '../../base/model/smodel-extension'; export const selectFeature = Symbol('selectFeature'); -export interface Selectable extends SModelExtension { +/** + * Feature extension interface for {@link selectFeature}. + */ +export interface Selectable { selected: boolean } diff --git a/packages/sprotty/src/index.ts b/packages/sprotty/src/index.ts index 7cf9577c..e86e164d 100644 --- a/packages/sprotty/src/index.ts +++ b/packages/sprotty/src/index.ts @@ -33,7 +33,6 @@ export * from './base/commands/command-stack'; export * from './base/features/initialize-canvas'; export * from './base/features/set-model'; -export * from './base/model/smodel-extension'; export * from './base/model/smodel-factory'; export * from './base/model/smodel-utils'; export * from './base/model/smodel';