/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import { Task } from '../mol-task'; import { UUID } from '../mol-util'; import { ParamDefinition as PD } from '../mol-util/param-definition'; import { StateObject, StateObjectCell } from './object'; import { State } from './state'; import { StateTransformer } from './transformer'; import { StateTransform } from './transform'; export { StateAction }; interface StateAction { create(params: P): StateAction.Instance; readonly id: UUID; readonly definition: StateAction.Definition; /** create a fresh copy of the params which can be edited in place */ createDefaultParams(a: A, globalCtx: unknown): P; } declare namespace StateAction { type Id = string & { '@type': 'transformer-id'; }; type Params> = T extends StateAction ? P : unknown; type ReType> = T extends StateAction ? T : unknown; type ControlsFor = { [P in keyof Props]?: PD.Any; }; interface Instance { action: StateAction; params: any; } interface ApplyParams { ref: string; cell: StateObjectCell; a: A; state: State; params: P; } interface DefinitionBase { /** * Apply an action that modifies the State specified in Params. */ run(params: ApplyParams, globalCtx: unknown): T | Task; /** Test if the transform can be applied to a given node */ isApplicable?(a: A, aTransform: StateTransform>, globalCtx: unknown): boolean; } interface Definition extends DefinitionBase { readonly from: StateObject.Ctor[]; readonly display: { readonly name: string; readonly description?: string; }; params?(a: A, globalCtx: unknown): { [K in keyof P]: PD.Any; }; } function create(definition: Definition): StateAction; function fromTransformer(transformer: T): StateAction, void, StateTransformer.Params>; namespace Builder { interface Type { from?: A | A[]; params?: PD.For

| ((a: StateObject.From, globalCtx: any) => PD.For

); display?: string | { name: string; description?: string; }; isApplicable?: DefinitionBase, any, P>['isApplicable']; } interface Root { (info: Type): Define, PD.Normalize

>; } interface Define { (def: DefinitionBase | DefinitionBase['run']): StateAction; } const build: Root; } const build: Builder.Root; }