From 1e4ec0d542c4d07bc78dff44e27141c159611db0 Mon Sep 17 00:00:00 2001 From: Alex Ritter Date: Sun, 17 Apr 2022 12:45:43 +0200 Subject: [PATCH] Convert Selected to ts --- src/editor/model/{Selected.js => Selected.ts} | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) rename src/editor/model/{Selected.js => Selected.ts} (66%) diff --git a/src/editor/model/Selected.js b/src/editor/model/Selected.ts similarity index 66% rename from src/editor/model/Selected.js rename to src/editor/model/Selected.ts index b229df14b..e05e4ef77 100644 --- a/src/editor/model/Selected.js +++ b/src/editor/model/Selected.ts @@ -1,25 +1,26 @@ import { isArray } from 'underscore'; import { Collection, Model } from '../../common'; +import { Component } from '../../dom_components/model/Component'; export class Selectable extends Model {} -export default class Selected extends Collection { - getByComponent(component) { +export default class Selected extends Collection { + getByComponent(component: Component) { return this.filter(s => this.getComponent(s) === component)[0]; } - addComponent(component, opts) { + addComponent(component: Component, opts: any) { const toAdd = (isArray(component) ? component : [component]) .filter(c => !this.hasComponent(c)) - .map(component => ({ component })); + .map(component => new Selectable({ component }))[0]; return this.push(toAdd, opts); } - getComponent(model) { + getComponent(model: Selectable) { return model.get('component'); } - hasComponent(component) { + hasComponent(component: Component) { const model = this.getByComponent(component); return model && this.contains(model); } @@ -33,10 +34,8 @@ export default class Selected extends Collection { return this.map(s => this.getComponent(s)).filter(i => i); } - removeComponent(component, opts) { + removeComponent(component: Component, opts: any) { const toRemove = (isArray(component) ? component : [component]).map(c => this.getByComponent(c)); return this.remove(toRemove, opts); } } - -Selected.prototype.model = Selectable;