mirror of https://github.com/artf/grapesjs.git
Browse Source
* Refactor Traits Collection * Fix css prefix * Fix trait undo and add test for it --------- Co-authored-by: Artur Arseniev <artur.catch@hotmail.it>pull/5196/head
committed by
GitHub
9 changed files with 125 additions and 77 deletions
@ -1,35 +1,35 @@ |
|||||
import { TraitManagerConfig } from '../config/config'; |
import { TraitManagerConfig } from '../config/config'; |
||||
import { TraitProperties } from './Trait'; |
import { isString } from 'underscore'; |
||||
|
import Trait, { TraitProperties } from './Trait'; |
||||
|
import EditorModel from '../../editor/model/Editor'; |
||||
|
|
||||
|
export default class TraitFactory { |
||||
|
config: Partial<TraitManagerConfig>; |
||||
|
|
||||
|
constructor(config: Partial<TraitManagerConfig> = {}) { |
||||
|
this.config = config; |
||||
|
} |
||||
|
|
||||
export default (config: Partial<TraitManagerConfig> = {}) => ({ |
|
||||
/** |
/** |
||||
* Build props object by their name |
* Build props object by their name |
||||
* @param {Array<string>|string} props Array of properties name |
|
||||
* @return {Array<Object>} |
|
||||
*/ |
*/ |
||||
build(props: string | string[]) { |
build(prop: string | TraitProperties, em: EditorModel): Trait { |
||||
const objs = []; |
return isString(prop) ? this.buildFromString(prop, em) : new Trait(prop, em); |
||||
|
} |
||||
if (typeof props === 'string') props = [props]; |
|
||||
|
|
||||
for (let i = 0; i < props.length; i++) { |
private buildFromString(name: string, em: EditorModel): Trait { |
||||
const prop = props[i]; |
const obj: TraitProperties = { |
||||
const obj: TraitProperties = { |
name: name, |
||||
name: prop, |
type: 'text', |
||||
type: 'text', |
}; |
||||
}; |
|
||||
|
|
||||
switch (prop) { |
switch (name) { |
||||
case 'target': |
case 'target': |
||||
obj.type = 'select'; |
obj.type = 'select'; |
||||
obj.default = false; |
obj.default = false; |
||||
obj.options = config.optionsTarget; |
obj.options = this.config.optionsTarget; |
||||
break; |
break; |
||||
} |
|
||||
|
|
||||
objs.push(obj); |
|
||||
} |
} |
||||
|
return new Trait(obj, em); |
||||
return objs; |
} |
||||
}, |
} |
||||
}); |
|
||||
|
|||||
Loading…
Reference in new issue