|
|
|
@ -1,134 +1,13 @@ |
|
|
|
import { isString, isUndefined } from 'underscore'; |
|
|
|
import Category from '../../abstract/ModuleCategory'; |
|
|
|
import { LocaleOptions, Model, SetOptions } from '../../common'; |
|
|
|
import Component from '../../dom_components/model/Component'; |
|
|
|
import Editor from '../../editor'; |
|
|
|
import EditorModel from '../../editor/model/Editor'; |
|
|
|
import TraitView from '../view/TraitView'; |
|
|
|
import { isDef } from '../../utils/mixins'; |
|
|
|
import Category, { CategoryProperties } from '../../abstract/ModuleCategory'; |
|
|
|
import { TraitOption, TraitProperties, TraitSetValueOptions } from '../types'; |
|
|
|
import TraitView from '../view/TraitView'; |
|
|
|
import Traits from './Traits'; |
|
|
|
|
|
|
|
/** @private */ |
|
|
|
export interface TraitProperties { |
|
|
|
/** |
|
|
|
* Trait type, defines how the trait should rendered. |
|
|
|
* Possible values: `text` (default), `number`, `select`, `checkbox`, `color`, `button` |
|
|
|
*/ |
|
|
|
type?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* The name of the trait used as a key for the attribute/property. |
|
|
|
* By default, the name is used as attribute name or property in case `changeProp` in enabled. |
|
|
|
*/ |
|
|
|
name?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Trait id, eg. `my-trait-id`. |
|
|
|
* If not specified, the `name` will be used as id. |
|
|
|
*/ |
|
|
|
id?: string | number; |
|
|
|
|
|
|
|
/** |
|
|
|
* Trait category. |
|
|
|
* @default '' |
|
|
|
*/ |
|
|
|
category?: string | CategoryProperties; |
|
|
|
|
|
|
|
/** |
|
|
|
* The trait label to show for the rendered trait. |
|
|
|
*/ |
|
|
|
label?: string | false; |
|
|
|
|
|
|
|
/** |
|
|
|
* If `true` the trait value is applied on component |
|
|
|
*/ |
|
|
|
changeProp?: boolean; |
|
|
|
|
|
|
|
/** |
|
|
|
* Instead of relying on component props/attributes, define your own |
|
|
|
* logic on how to get the trait value. |
|
|
|
*/ |
|
|
|
getValue?: (props: { editor: Editor; trait: Trait; component: Component }) => any; |
|
|
|
|
|
|
|
/** |
|
|
|
* In conjunction with the `getValue`, define your own logic for updating the trait value. |
|
|
|
*/ |
|
|
|
setValue?: (props: { |
|
|
|
value: any; |
|
|
|
editor: Editor; |
|
|
|
trait: Trait; |
|
|
|
component: Component; |
|
|
|
partial: boolean; |
|
|
|
options: TraitSetValueOptions; |
|
|
|
emitUpdate: () => void; |
|
|
|
}) => void; |
|
|
|
|
|
|
|
/** |
|
|
|
* Custom true value for checkbox type. |
|
|
|
* @default 'true' |
|
|
|
*/ |
|
|
|
valueTrue?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Custom false value for checkbox type. |
|
|
|
* * @default 'false' |
|
|
|
*/ |
|
|
|
valueFalse?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Minimum number value for number type. |
|
|
|
*/ |
|
|
|
min?: number; |
|
|
|
|
|
|
|
/** |
|
|
|
* Maximum number value for number type. |
|
|
|
*/ |
|
|
|
max?: number; |
|
|
|
unit?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Number of steps for number type. |
|
|
|
*/ |
|
|
|
step?: number; |
|
|
|
value?: any; |
|
|
|
target?: Component; |
|
|
|
default?: any; |
|
|
|
|
|
|
|
/** |
|
|
|
* Placeholder to show inside the input. |
|
|
|
*/ |
|
|
|
placeholder?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Array of options for the select type. |
|
|
|
*/ |
|
|
|
options?: Record<string, any>[]; |
|
|
|
|
|
|
|
/** |
|
|
|
* Label text to use for the button type. |
|
|
|
*/ |
|
|
|
text?: string; |
|
|
|
labelButton?: string; |
|
|
|
|
|
|
|
/** |
|
|
|
* Command to use for the button type. |
|
|
|
*/ |
|
|
|
command?: string | ((editor: Editor, trait: Trait) => any); |
|
|
|
|
|
|
|
full?: boolean; |
|
|
|
attributes?: Record<string, any>; |
|
|
|
} |
|
|
|
|
|
|
|
interface TraitSetValueOptions { |
|
|
|
partial?: boolean; |
|
|
|
[key: string]: unknown; |
|
|
|
} |
|
|
|
|
|
|
|
type TraitOption = { |
|
|
|
id: string; |
|
|
|
label?: string; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* @typedef Trait |
|
|
|
* @property {String} id Trait id, eg. `my-trait-id`. |
|
|
|
|