mx-ui-components
Version:
mobius ui library
150 lines (148 loc) • 4.25 kB
TypeScript
import { Signal } from "./store/signals.js";
import type Store from "./store/store.js";
import "../../app.css";
import "./TailwindCss.js";
import ServiceManager from "../../services/ServiceManager.js";
import type { WebSocketManager } from "../WebsocketService/WebsocketService.js";
import "./CustomKeyEvents.ts";
import type { RouterService } from "./RouterInit.js";
/**
*
* bind = {
* state : {
* stateName : {
* path: 'path',
* initialValue: {}
* },
* stateName2 : {
* path: 'path',
* initialValue: {}
* }
* },
* events : {
* click: {
* stateName : {'actionName': 'path'}
* stateName2 : {'actionName2': 'path'}
* action: {'actionName': 'path'}
* },
* hover: {
* stateName : {'actionName': 'path'}
* stateName2 : {'actionName2': 'path'}
* action: {'actionName': 'path'}
* },
* onload: {
* action: {'actionName': 'path'}
* stateName : {'actionName': 'path'}
* stateName2 : {'actionName2': 'path'}
* },
* onStateChangeActions: {
* stateName : {'actionName': 'path'}
* action: {'actionName': 'path'}
* stateName2 : {'actionName2': 'path'}
* },
* }
*/
interface ConditionalAction {
conditions: string[];
_conditions: string[];
logicalOperator: string;
trueAction: Action;
falseAction: Action;
}
interface Action {
[actionName: string]: string | {
sourcePath: string;
targetPath: string;
conditionalAction: ConditionalAction;
params?: Object;
};
}
interface EventBindings {
onload: {
action: Action;
[stateName: string]: Action;
};
onStateChangeActions: {
action: Action;
[stateName: string]: Action;
};
[eventName: string]: {
action: Action;
[stateName: string]: Action;
};
}
interface StateBindings {
[stateName: string]: {
path: string;
initialValue: any;
action?: Action;
};
}
interface Bindings {
state: StateBindings;
events: EventBindings;
}
export default class BaseComponent extends HTMLElement {
shadowRoot: ShadowRoot | null;
signal: Signal | undefined;
signals: Array<Signal>;
pendingBindings: {
bindings: any;
bindCb: Function;
initialValue?: any;
}[];
store: Store | undefined;
pendingNewBindings: {
bindings: any;
bindCb: Function;
initialValue?: any;
}[];
newSignal: {
[key: string]: Signal | undefined;
};
baseBindings: Bindings | undefined;
serviceManager: ServiceManager | undefined;
meta: Record<string, any>;
websocket: WebSocketManager | undefined;
private __stateListenersMap;
static router: RouterService;
constructor();
onLoad(): Promise<void>;
connectedCallback(): void;
/**
* Sets the store and processes any pending bindings.
*/
setStore(store: Store | undefined): void;
setBindings(bindings: Bindings, bindCb: Function, initialValue?: any): void;
private applyNewBindings;
applyStateBindings(state: StateBindings, cb: Function): void;
private handleDomEvent;
applyEventBindings(evtObject: EventBindings): void;
executeAction(stateName: string, action: Action, e?: any): Promise<any>;
/**
* Binds a state signal to this component.
*/
bindNewState(stateName: string, defaultValue: any, path: string, cb: Function, action: Action | undefined): Signal | undefined;
updateState(value: any): void;
setState(value: any): void;
updateStateByName(value: any, signalName: string): void;
getState(): any;
createElementFromJson(json: any, suspense?: string, element?: HTMLElement | undefined): DocumentFragment;
/**
* Applies the bindings directly.
*/
private applyBindings;
/**
* Binds a state signal to this component.
*/
bindState(stateName: string, defaultValue: any, callback: Function): Signal | undefined;
onSignalChange(value: any): void;
/**
* Binds events to the component.
*/
bindEvents(actionsBindings: any): void;
private setupSocktIoEvents;
private socketEventHandler;
disconnectedCallback(): void;
}
export {};