mirror of https://github.com/artf/grapesjs.git
67 changed files with 281 additions and 290 deletions
@ -0,0 +1,46 @@ |
|||
import Backbone from 'backbone'; |
|||
import ModuleCollection from './ModuleCollection'; |
|||
import ModuleModel from './ModuleModel'; |
|||
import { IBaseModule } from './Module'; |
|||
|
|||
type ModuleFromModel<TModel extends ModuleModel> = TModel extends ModuleModel<infer M> ? M : unknown; |
|||
type ModuleModelExt<TItem extends ModuleModel | ModuleCollection> = TItem extends ModuleCollection<infer M> |
|||
? ModuleFromModel<M> |
|||
: TItem extends ModuleModel<infer M> |
|||
? M |
|||
: unknown; |
|||
|
|||
// type TCollection<TItem extends ModuleModel | ModuleCollection> = TItem extends ModuleCollection ? TItem : unknown;
|
|||
|
|||
export default class ModuleView< |
|||
TModel extends ModuleModel | ModuleCollection = ModuleModel, |
|||
TElement extends Element = HTMLElement |
|||
> extends Backbone.View<TModel extends ModuleModel ? TModel : undefined, TElement> { |
|||
protected get pfx() { |
|||
return this.ppfx + (this.config as any).stylePrefix || ''; |
|||
} |
|||
|
|||
protected get ppfx() { |
|||
return this.em.config.stylePrefix || ''; |
|||
} |
|||
|
|||
collection!: TModel extends ModuleModel ? ModuleCollection<ModuleModel> : TModel; |
|||
|
|||
protected get module(): ModuleModelExt<TModel> { |
|||
return (this.model as any)?.module ?? this.collection.module; |
|||
} |
|||
|
|||
protected get em() { |
|||
return this.module.em; |
|||
} |
|||
|
|||
protected get config(): ModuleModelExt<TModel> extends IBaseModule<infer C> ? C : unknown { |
|||
return this.module.config as any; |
|||
} |
|||
|
|||
public className!: string; |
|||
|
|||
preinitialize(options?: any) { |
|||
this.className = ''; |
|||
} |
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
import Backbone from 'backbone'; |
|||
import Collection from './Collection'; |
|||
import Model from './Model'; |
|||
import { IBaseModule } from './Module'; |
|||
|
|||
type ModuleFromModel<TModel extends Model> = TModel extends Model<infer M> ? M : unknown; |
|||
type Module<TItem extends Model | Collection> = TItem extends Collection<infer M> |
|||
? ModuleFromModel<M> |
|||
: TItem extends Model<infer M> |
|||
? M |
|||
: unknown; |
|||
|
|||
type TCollection<TItem extends Model | Collection> = TItem extends Collection ? TItem : unknown; |
|||
|
|||
export default class View< |
|||
TModel extends Model | Collection = Model, |
|||
TElement extends Element = HTMLElement |
|||
> extends Backbone.View<TModel extends Model ? TModel : undefined, TElement> { |
|||
protected get pfx() { |
|||
return this.ppfx + (this.config as any).stylePrefix || ''; |
|||
} |
|||
|
|||
protected get ppfx() { |
|||
return this.em.config.stylePrefix || ''; |
|||
} |
|||
|
|||
collection!: TModel extends Model ? Collection<Model> : TModel; |
|||
|
|||
protected get module(): Module<TModel> { |
|||
return (this.model as any)?.module ?? this.collection.module; |
|||
} |
|||
|
|||
protected get em() { |
|||
return this.module.em; |
|||
} |
|||
|
|||
protected get config(): Module<TModel> extends IBaseModule<infer C> ? C : unknown { |
|||
return this.module.config as any; |
|||
} |
|||
|
|||
public className!: string; |
|||
|
|||
preinitialize(options?: any) { |
|||
this.className = ''; |
|||
} |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
export { default as Model } from './Model'; |
|||
export { default as Collection } from './Collection'; |
|||
export { default as View } from './View'; |
|||
export { default as ModuleModel } from './ModuleModel'; |
|||
export { default as ModuleCollection } from './ModuleCollection'; |
|||
export { default as ModuleView } from './ModuleView'; |
|||
export { default as Module } from './Module'; |
|||
|
|||
Loading…
Reference in new issue