mirror of https://github.com/artf/grapesjs.git
12 changed files with 11061 additions and 9659 deletions
@ -1,6 +1,33 @@ |
|||
import Backbone from 'backbone'; |
|||
import Backbone, { AddOptions } from 'backbone'; |
|||
import { isArray, isObject } from 'underscore'; |
|||
import Model from './Model'; |
|||
|
|||
export default class Collection< |
|||
TModel extends Model = Model |
|||
> extends Backbone.Collection<TModel> {} |
|||
type Module<TModel extends Model> = TModel extends Model<infer M> ? M : unknown; |
|||
type ModelConstructor<TModel extends Model> = { new (mod: Module<TModel>, attr: any): TModel }; |
|||
|
|||
export default class Collection<TModel extends Model = Model> extends Backbone.Collection<TModel> { |
|||
module!: Module<TModel>; |
|||
private newModel!: { new (mod: Module<TModel>, attr: any): TModel }; |
|||
|
|||
//modelConstructor = {new (mod: Module<TModel>, attr: any): TModel}
|
|||
add(model: Array<Record<string, any>> | TModel, options?: AddOptions): TModel; |
|||
add(models: Array<Array<Record<string, any>> | TModel>, options?: AddOptions): TModel[]; |
|||
add(model: unknown, options?: AddOptions): any { |
|||
var models = isArray(model) ? model : [model]; |
|||
models = models.map(m => (m instanceof this.newModel ? m : new this.newModel(this.module, m))); |
|||
return super.add(isArray(model) ? models : models[0], options); |
|||
} |
|||
|
|||
constructor( |
|||
module: Module<TModel>, |
|||
models: TModel[] | Array<Record<string, any>>, |
|||
modelConstructor: ModelConstructor<TModel> |
|||
) { |
|||
super(models, { module, modelConstructor }); |
|||
} |
|||
|
|||
preinitialize(models?: TModel[] | Array<Record<string, any>>, options?: any) { |
|||
this.newModel = options.modelConstructor; |
|||
this.module = options.module; |
|||
} |
|||
} |
|||
|
|||
@ -1,6 +1,11 @@ |
|||
import { Collection } from '../../common'; |
|||
import PanelManager from '..'; |
|||
import { Collection } from '../../abstract'; |
|||
import Panel from './Panel'; |
|||
|
|||
export default class Panels extends Collection<Panel> {} |
|||
export default class Panels extends Collection<Panel> { |
|||
constructor(module: PanelManager, models: Panel[] | Array<Record<string, any>>) { |
|||
super(module, models, Panel); |
|||
} |
|||
} |
|||
|
|||
Panels.prototype.model = Panel; |
|||
|
|||
File diff suppressed because it is too large
Loading…
Reference in new issue