Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SModelExtension interface #389

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions packages/sprotty/src/base/model/smodel-extension.ts

This file was deleted.

14 changes: 10 additions & 4 deletions packages/sprotty/src/features/bounds/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/decoration/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends SModelElementImpl>(e: T): e is T & Decoration {
Expand Down
8 changes: 5 additions & 3 deletions packages/sprotty/src/features/edge-layout/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -33,7 +35,7 @@ export function isEdgeLayoutable<T extends SModelElementImpl>(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;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/edit/create-on-drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/edit/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends SModelElementImpl>(element: T): element is T & Deletable & SChildElementImpl {
Expand Down
12 changes: 9 additions & 3 deletions packages/sprotty/src/features/edit/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -40,7 +43,10 @@ export function isEditableLabel<T extends SModelElementImpl>(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;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/expand/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/fade/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/hover/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions packages/sprotty/src/features/move/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions packages/sprotty/src/features/nameable/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
********************************************************************************/

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
}

export function isNameable(element: SModelElementImpl): element is SModelElementImpl & Nameable {
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 {
Expand Down
3 changes: 1 addition & 2 deletions packages/sprotty/src/features/projection/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
}
Expand Down
14 changes: 8 additions & 6 deletions packages/sprotty/src/features/routing/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand All @@ -74,7 +76,7 @@ export function getAbsoluteRouteBounds(model: Readonly<SRoutableElementImpl>, 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;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions packages/sprotty/src/features/select/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion packages/sprotty/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down