Skip to content

Commit

Permalink
Up OpenTraitManager for custom traits
Browse files Browse the repository at this point in the history
  • Loading branch information
artf authored and pety-dc committed Aug 14, 2023
1 parent ab1d2fe commit 94e2029
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dist/grapes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/grapes.min.js.map

Large diffs are not rendered by default.

50 changes: 47 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ export interface TraitProperties {
partial: boolean;
}) => void;
}
export type TraitOption = {
id: string;
label?: string;
};
/**
* @typedef Trait
* @property {String} id Trait id, eg. `my-trait-id`.
Expand Down Expand Up @@ -897,6 +901,36 @@ export declare class Trait extends Model<TraitProperties> {
setValue(value: any, opts?: {
partial?: boolean;
}): void;
/**
* Get default value.
*/
getDefault(): any;
/**
* Get trait options.
*/
getOptions(): TraitOption[];
/**
* Get current selected option or by id.
* @param {String} [id] Option id.
* @returns {Object | null}
*/
getOption(id?: string): TraitOption | undefined;
/**
* Get the option id from the option object.
* @param {Object} option Option object
* @returns {String} Option id
*/
getOptionId(option: TraitOption): any;
/**
* Get option label.
* @param {String|Object} id Option id or the option object
* @param {Object} [opts={}] Options
* @param {Boolean} [opts.locale=true] Use the locale string from i18n module
* @returns {String} Option label
*/
getOptionLabel(id: string | TraitOption, opts?: {
locale?: boolean;
}): string;
props(): Partial<TraitProperties>;
targetUpdated(): void;
getTargetValue(): any;
Expand All @@ -916,6 +950,11 @@ export interface TraitManagerConfig {
* @default ''
*/
appendTo?: string | HTMLElement;
/**
* Avoid rendering the default Trait Manager UI.
* @default false
*/
custom?: boolean;
optionsTarget?: Record<string, any>[];
}
declare class TraitFactory {
Expand Down Expand Up @@ -2445,6 +2484,7 @@ declare class FrameView extends ModuleView<Frame, HTMLIFrameElement> {
allowfullscreen: string;
};
dragging: boolean;
loaded: boolean;
droppable?: Droppable;
rect?: DOMRect;
lastClientY?: number;
Expand Down Expand Up @@ -8278,6 +8318,7 @@ declare class SelectorManager extends ItemManagerModule<SelectorManagerConfig &
all: Selectors;
storageKey: string;
__update: Debounced;
__ctn?: HTMLElement;
/**
* Get configuration object
* @name getConfig
Expand All @@ -8292,7 +8333,7 @@ declare class SelectorManager extends ItemManagerModule<SelectorManagerConfig &
__customData(opts?: any): {
states: State[];
selected: Selector[];
container: any;
container: HTMLElement | undefined;
};
postRender(): void;
select(value: StyleModuleParam<"select", 0>, opts?: StyleModuleParam<"select", 1>): this;
Expand Down Expand Up @@ -8798,8 +8839,11 @@ declare class TraitManager extends Module<TraitManagerConfig & {
__upSel(): void;
__onUp(): void;
select(component?: Component): void;
getSelected(): any;
getCurrent(): any;
getSelected(): Component | undefined;
/**
* Get traits from the currently selected component.
*/
getCurrent(): Trait[];
__trgCustom(opts?: any): void;
postRender(): void;
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Free and Open Source Web Builder Framework",
"version": "0.21.2",
"version": "0.21.3",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",
Expand Down
10 changes: 8 additions & 2 deletions src/commands/view/OpenTraitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export default {
this.$cn.append(this.$cn2);
this.$header = $('<div>').append(`<div class="${confTm.stylePrefix}header">${em.t('traitManager.empty')}</div>`);
this.$cn.append(this.$header);
this.$cn2.append(`<div class="${pfx}traits-label">${em.t('traitManager.label')}</div>`);
this.$cn2.append(tm.render());

if (confTm.custom) {
tm.__trgCustom({ container: this.$cn2.get(0) });
} else {
this.$cn2.append(`<div class="${pfx}traits-label">${em.t('traitManager.label')}</div>`);
this.$cn2.append(tm.render());
}

var panels = editor.Panels;

if (!panels.getPanel('views-container')) {
Expand Down

0 comments on commit 94e2029

Please sign in to comment.