Skip to content
Snippets Groups Projects
spec.ts 1.78 KiB
Newer Older
David Sehnal's avatar
David Sehnal committed
/**
 * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
David Sehnal's avatar
David Sehnal committed
 *
 * @author David Sehnal <david.sehnal@gmail.com>
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
David Sehnal's avatar
David Sehnal committed
 */

import { StateTransformer, StateAction } from '../mol-state';
import { StateTransformParameters } from './ui/state/common';
David Sehnal's avatar
David Sehnal committed
import { PluginLayoutStateProps } from './layout';
David Sehnal's avatar
David Sehnal committed
import { PluginStateAnimation } from './state/animation/model';

export { PluginSpec }
David Sehnal's avatar
David Sehnal committed

interface PluginSpec {
    actions: PluginSpec.Action[],
David Sehnal's avatar
David Sehnal committed
    behaviors: PluginSpec.Behavior[],
David Sehnal's avatar
David Sehnal committed
    animations?: PluginStateAnimation[],
David Sehnal's avatar
David Sehnal committed
    customParamEditors?: [StateAction | StateTransformer, StateTransformParameters.Class][],
    layout?: {
        initial?: Partial<PluginLayoutStateProps>,
        controls?: PluginSpec.LayoutControls
David Sehnal's avatar
David Sehnal committed
}

namespace PluginSpec {
    export interface Action {
David Sehnal's avatar
David Sehnal committed
        action: StateAction | StateTransformer,
        customControl?: StateTransformParameters.Class,
        autoUpdate?: boolean
    }

David Sehnal's avatar
David Sehnal committed
    export function Action(action: StateAction | StateTransformer, params?: { customControl?: StateTransformParameters.Class, autoUpdate?: boolean }): Action {
        return { action, customControl: params && params.customControl, autoUpdate: params && params.autoUpdate };
    }

    export interface Behavior {
David Sehnal's avatar
David Sehnal committed
        transformer: StateTransformer,
        defaultParams?: any
    }

David Sehnal's avatar
David Sehnal committed
    export function Behavior<T extends StateTransformer>(transformer: T, defaultParams?: StateTransformer.Params<T>): Behavior {
        return { transformer, defaultParams };
    }

    export interface LayoutControls {
        top?: React.ComponentClass | 'none',
        left?: React.ComponentClass | 'none',
        right?: React.ComponentClass | 'none',
        bottom?: React.ComponentClass | 'none'
    }