Skip to content

Commit

Permalink
test signal slot
Browse files Browse the repository at this point in the history
  • Loading branch information
xQwexx committed May 1, 2024
1 parent 30cb072 commit 15d1eeb
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 51 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.

199 changes: 151 additions & 48 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ declare class CanvasView extends ModuleView<Canvas> {
cvStyle?: HTMLElement;
clsUnscale: string;
ready: boolean;
updatingScriptTimout: Record<string, ReturnType<typeof setTimeout>>;
frames: FramesView;
frame?: FrameView;
private timerZoom?;
Expand Down Expand Up @@ -2562,6 +2563,20 @@ export declare class Category extends Model<CategoryProperties> {
getId(): string;
getLabel(): string;
}
declare abstract class TraitElement<TraitValueType = any> extends Trait<TraitValueType> {
target: Trait<TraitValueType>;
constructor(target: Trait<TraitValueType>, opts?: any);
abstract get name(): string;
abstract get defaultValue(): TraitValueType;
get component(): Component;
get em(): default;
protected getValue(): TraitValueType;
protected setValue(value: TraitValueType): void;
refreshTrait(forced: boolean): void;
triggerTraitChanged(event: string): void;
get updateEventName(): string;
onUpdateEvent(): void;
}
export interface OnUpdateView<TraitValueType> {
onUpdateEvent(value: TraitValueType, fromTarget: boolean): void;
}
Expand All @@ -2573,13 +2588,14 @@ export interface TraitProperties {
}
declare abstract class Trait<TraitValueType = any, Type extends string = string> {
opts: any;
private view?;
protected view?: OnUpdateView<TraitValueType>;
get name(): string;
get type(): Type;
get templates(): unknown;
get templates(): any[];
private _children;
get children(): Trait[];
set children(children: Trait[]);
get children(): TraitElement[];
set children(children: TraitElement[]);
abstract get component(): Component;
constructor(opts: TraitProperties);
registerForUpdateEvent(view: OnUpdateView<TraitValueType>): void;
protected abstract getValue(): TraitValueType;
Expand All @@ -2589,8 +2605,8 @@ declare abstract class Trait<TraitValueType = any, Type extends string = string>
get value(): TraitValueType;
protected updatingValue: boolean;
set value(value: TraitValueType);
refreshTrait(): void;
setValueFromModel(): void;
refreshTrait(forced: boolean): void;
setValueFromModel(model: Component, opts: any): void;
onUpdateEvent(): void;
updateOpts(opts: any): void;
get viewType(): Type;
Expand All @@ -2602,17 +2618,25 @@ declare abstract class Trait<TraitValueType = any, Type extends string = string>
* @returns {String}
*/
getCategoryLabel(opts?: LocaleOptions): string;
abstract triggerTraitChanged(event?: string): void;
abstract get updateEventName(): string;
setTraitElement(trait: Trait): void;
}
declare class TraitRoot<TModel extends Model & {
em: EditorModel;
}, TraitValueType = any> extends Trait<TraitValueType> {
readonly model: TModel;
private readonly _name;
get name(): string;
traitElement: TraitElement;
get component(): Component;
constructor(name: string, model: TModel, opts: any);
get em(): EditorModel;
protected getValue(): TraitValueType;
protected setValue(value: TraitValueType, opts?: SetOptions): void;
triggerTraitChanged(event: string): void;
get updateEventName(): string;
setTraitElement(trait: TraitElement): void;
}
export interface TraitViewOpts<Type> {
type?: Type;
Expand Down Expand Up @@ -2674,28 +2698,29 @@ export interface TraitSelectViewOpts extends TraitInputViewOpts<"select"> {
}
declare class TraitObjectItem<TraitValueType extends {
[id: string]: any;
} = any> extends Trait<any> {
target: Trait<TraitValueType>;
} = any> extends TraitElement<any> {
onValueChange?: (value: any) => void;
_name: string;
get name(): string;
constructor(name: string, target: Trait<TraitValueType>, opts: any, onValueChange?: (value: any) => void);
get em(): default;
get defaultValue(): any;
protected getValue(): any;
protected setValue(value: any): void;
onUpdateEvent(): void;
}
declare abstract class TraitParent<TraitValueType = any> extends Trait<TraitValueType> {
target: Trait<TraitValueType>;
declare abstract class TraitParent<CT extends TraitElement, TraitValueType = any> extends TraitElement<TraitValueType> {
private updateChildren;
constructor(target: Trait<TraitValueType>);
get name(): string;
protected initChildren(): Trait[];
setValueFromModel(): void;
get em(): default;
protected initChildren(): TraitElement[];
refreshChildren(): void;
protected getValue(): TraitValueType;
protected setValue(value: TraitValueType): void;
refreshTrait(): void;
refreshTrait(forced: boolean): void;
childrenChanged(): void;
protected addChildren(tr: CT): void;
protected removeChildren(key: string): void;
get updateEventName(): string;
}
export interface TraitListViewOpts<T extends string = "object"> extends TraitViewOpts<T> {
traits: any[] | any;
Expand Down Expand Up @@ -3142,6 +3167,61 @@ export interface ToolbarButtonProps {
attributes?: ObjectAny;
events?: ObjectAny;
}
declare class TraitObject<TraitValueType extends {
[id: string]: any;
} = any> extends TraitParent<TraitObjectItem, TraitValueType> {
constructor(target: Trait<TraitValueType>);
protected initChildren(): TraitObjectItem<TraitValueType>[];
get defaultValue(): TraitValueType;
get viewType(): string;
get editable(): boolean;
}
export type VariableType = {
variableType: "global";
data: {
componentId: string;
name: string;
};
} | {
variableType: "parameter";
data: {
default: string;
};
};
export type PropsType = {
name: string;
type: "link";
};
declare class PropComponent {
private model?;
private script;
name: string;
constructor(script: ScriptSubComponent, opts: PropsType);
register(comp: Component): void;
deregister(): void;
private propChange;
static linkToComponent(comp: ScriptSubComponent, name: string): PropComponent;
}
export type ParamType = {
type: "list";
itemType: ParamType;
} | {
type: "object";
params: Record<string, ParamType>;
} | {
type: "string";
};
export type SlotType = {
script: string | ((...params: any[]) => any);
event: {
type: string;
};
params: Record<string, ParamType>;
subscription: {
componentId?: string;
name?: string;
};
};
export interface ScriptData {
main: string | ((...params: any[]) => any);
props: string[];
Expand All @@ -3152,6 +3232,7 @@ export interface ScriptData {
}>;
slots: Record<string, {
script: string | ((...params: any[]) => any);
params: Record<string, ParamType>;
}>;
}
declare class ScriptSubComponent extends Model {
Expand All @@ -3165,17 +3246,16 @@ declare class ScriptSubComponent extends Model {
};
constructor(component: Component, script: ScriptData);
get component(): Component;
get props(): string[];
get props(): PropComponent[];
setProps(props: string[]): void;
get dataId(): string;
initScriptProps(): void;
onChange(): void;
__scriptPropsChange(m?: any, v?: any, opts?: any): void;
__scriptChange(): void;
/**
* Script updated
* @private
*/
scriptUpdated(): void;
private scriptUpdated;
__getScriptProps(): Partial<ComponentProperties>;
register(): void;
deregister(): void;
/**
* Return script in string format, cleans 'function() {..' from scripts
* if it's a function
Expand All @@ -3184,13 +3264,22 @@ declare class ScriptSubComponent extends Model {
* @private
*/
getScriptString(script?: string | Function): string;
static renderComponentSignal(signal: {
componentId: string;
slot: string;
params: Record<string, any>;
}, em: EditorModel): string;
static renderComponentSignals(script: ScriptSubComponent): string;
static renderSlots(scripts: ScriptSubComponent[]): string;
static renderJs(script: ScriptSubComponent | ScriptSubComponent[]): string;
private static mapScripts;
get variables(): any;
get signals(): any;
get slots(): any;
get signals(): Record<string, {
componentId?: string;
slot?: string;
params?: Record<string, VariableType>;
}>;
get slots(): Record<string, SlotType>;
}
export type DragMode = "translate" | "absolute" | "";
export type DraggableDroppableFn = (source: Component, target: Component, index?: number) => boolean | void;
Expand Down Expand Up @@ -3465,6 +3554,17 @@ declare class ComponentWrapper extends Component {
}[];
ajax: {
test: {
url: {
url: string;
variables: {
page: {
variableType: string;
data: {
default: string;
};
};
};
};
urlRaw: string;
dataSrc: string;
dataIds: string[];
Expand All @@ -3477,15 +3577,10 @@ declare class ComponentWrapper extends Component {
changeProp: boolean;
traits: {
type: string;
traits: ({
traits: {
name: string;
type: string;
label?: undefined;
} | {
name: string;
label: string;
type: string;
})[];
}[];
};
} | {
name: string;
Expand Down Expand Up @@ -3884,11 +3979,7 @@ export declare class Component extends StyleableModel<ComponentProperties> {
get traits(): ({
name: string;
} & Trait<any>)[];
get slots(): {
[name: string]: {
script: (el: string, param: any) => void;
};
};
get slots(): Record<string, SlotType>;
get content(): string;
get toolbar(): ToolbarButtonProps[];
get resizable(): boolean | ResizerOptions;
Expand Down Expand Up @@ -9200,27 +9291,17 @@ declare class StorageManager extends Module<StorageManagerConfig & {
canAutoload(): boolean;
destroy(): void;
}
declare class TraitObject<TraitValueType extends {
[id: string]: any;
} = any> extends TraitParent<TraitValueType> {
constructor(target: Trait<TraitValueType>);
protected initChildren(): (Trait<any, string> & {
name: string;
})[];
get viewType(): string;
get editable(): boolean;
}
export interface TraitListUniqueViewOpts<T extends string = "object"> extends TraitViewOpts<T> {
traits: any[] | any;
}
declare abstract class TraitsView<T extends TraitParent> extends TraitView<T> {
declare abstract class TraitsView<T extends TraitParent<TraitElement>> extends TraitView<T> {
protected type: string;
templates: any[];
private _items?;
protected traitOps?: any;
get items(): TraitView<Trait<any, string>>[];
constructor(em: EditorModel, opts: TraitListUniqueViewOpts);
get children(): TraitObjectItem<any>[];
get children(): TraitElement<any>[];
onUpdateEvent(value: any, fromTarget: boolean): void;
onItemRender(e: any): void;
renderItems(traits?: Trait[]): void;
Expand Down Expand Up @@ -9266,6 +9347,27 @@ declare enum TraitsEvents {
*/
all = "trait"
}
declare abstract class TraitFactory {
static build(model: Model & {
em: EditorModel;
}, trait: string | ({
name: string;
} & InputViewProperties) | ({
name: string;
} & Trait<any>)): Trait<any> & {
name: string;
};
static buildNestedTraits(trait: TraitElement & {
name: string;
}): TraitElement & {
name: string;
};
static buildNestedTraits(trait: Trait & {
name: string;
}): Trait & {
name: string;
};
}
export type CustomTrait<T> = T & ThisType<T & TraitView>;
declare class TraitManager extends Module<TraitManagerConfig & {
pStylePrefix?: string;
Expand All @@ -9278,6 +9380,7 @@ declare class TraitManager extends Module<TraitManagerConfig & {
};
__ctn?: HTMLElement;
TraitsView: typeof TraitObjectView;
TraitFactory: typeof TraitFactory;
events: typeof TraitsEvents;
state: Model<TraitModuleStateProps, SetOptions, any>;
/**
Expand Down
Loading

0 comments on commit 15d1eeb

Please sign in to comment.