Browse Source

Add callback types to StyleManager

type-event-callbacks
Artur Arseniev 1 month ago
parent
commit
cc47a01865
  1. 5
      packages/core/src/editor/types.ts
  2. 4
      packages/core/src/style_manager/index.ts
  3. 42
      packages/core/src/style_manager/types.ts

5
packages/core/src/editor/types.ts

@ -15,7 +15,7 @@ import { ParserEvent, ParserEventCallback } from '../parser/types';
import { RichTextEditorEvent, RichTextEditorEventCallback } from '../rich_text_editor';
import { SelectorEvent, SelectorEventCallback } from '../selector_manager/types';
import { StorageEvent, StorageEventCallback } from '../storage_manager/types';
import { StyleManagerEvent } from '../style_manager';
import { StyleManagerEvent, StyleManagerEventCallback } from '../style_manager/types';
import { EditorConfig } from './config/config';
import EditorModel from './model/Editor';
@ -62,7 +62,8 @@ export interface EditorEventCallbacks
ParserEventCallback,
RichTextEditorEventCallback,
SelectorEventCallback,
StorageEventCallback
StorageEventCallback,
StyleManagerEventCallback
{
[key: string]: any[];
}

4
packages/core/src/style_manager/index.ts

@ -68,9 +68,7 @@ import { PropertyTypes, StyleManagerEvents, StyleTarget } from './types';
import { CustomPropertyView } from './view/PropertyView';
import SectorsView from './view/SectorsView';
export type { PropertyTypes, StyleModuleParam, StyleTarget } from './types';
export type StyleManagerEvent = `${StyleManagerEvents}`;
export type { PropertyTypes, StyleManagerEventCallback, StyleModuleParam, StyleTarget } from './types';
const propDef = (value: any) => value || value === 0;

42
packages/core/src/style_manager/types.ts

@ -1,5 +1,10 @@
import StyleManager from '.';
import { AddOptions, ObjectAny, RemoveOptions } from '../common';
import StyleableModel from '../domain_abstract/model/StyleableModel';
import Property, { PropertyProps } from './model/Property';
import PropertyStack from './model/PropertyStack';
import Sector, { SectorProperties } from './model/Sector';
import Sectors from './model/Sectors';
import { PropertyNumberProps } from './model/PropertyNumber';
import { PropertySelectProps } from './model/PropertySelect';
import { PropertyStackProps } from './model/PropertyStack';
@ -84,5 +89,42 @@ export enum StyleManagerEvents {
}
/**{END_EVENTS}*/
export type StyleManagerEvent = `${StyleManagerEvents}`;
export interface StyleManagerPropertyUpdateEventData {
property: Property;
from: Partial<PropertyProps>;
to: Partial<PropertyProps>;
value: any;
opts: ObjectAny;
}
export interface StyleManagerLayerSelectEventData {
property: PropertyStack;
}
export interface StyleManagerCustomEventData {
container: HTMLElement | undefined;
}
export interface StyleManagerAllEventData {
event: string;
model?: Sector | Sectors;
options: ObjectAny;
}
export interface StyleManagerEventCallback {
[StyleManagerEvents.sectorAdd]: [Sector, AddOptions];
[StyleManagerEvents.sectorRemove]: [Sector, RemoveOptions];
[StyleManagerEvents.sectorUpdate]: [Sector, Partial<SectorProperties>, ObjectAny];
[StyleManagerEvents.propertyAdd]: [Property, AddOptions];
[StyleManagerEvents.propertyRemove]: [Property, RemoveOptions];
[StyleManagerEvents.propertyUpdate]: [StyleManagerPropertyUpdateEventData];
[StyleManagerEvents.target]: [StyleTarget | undefined];
[StyleManagerEvents.layerSelect]: [StyleManagerLayerSelectEventData];
[StyleManagerEvents.custom]: [StyleManagerCustomEventData];
[StyleManagerEvents.all]: [StyleManagerAllEventData];
}
// need this to avoid the TS documentation generator to break
export default StyleManagerEvents;

Loading…
Cancel
Save