UNPKG

molstar

Version:

A comprehensive macromolecular library.

55 lines (54 loc) 2.27 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { RuntimeContext } from '../../mol-task'; import { CustomPropertyDescriptor } from '../../mol-model/custom-property'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { ValueBox } from '../../mol-util'; import { AssetManager, Asset } from '../../mol-util/assets'; export { CustomProperty }; declare namespace CustomProperty { interface Context { runtime: RuntimeContext; assetManager: AssetManager; } type Data<V> = { value: V; assets?: Asset.Wrapper[]; }; interface Container<P, V> { readonly props: P; readonly data: ValueBox<V | undefined>; } interface Provider<Data, Params extends PD.Params, Value> { readonly label: string; readonly descriptor: CustomPropertyDescriptor; /** hides property in ui and always attaches */ readonly isHidden?: boolean; readonly getParams: (data: Data) => Params; readonly defaultParams: Params; readonly isApplicable: (data: Data) => boolean; readonly attach: (ctx: Context, data: Data, props?: Partial<PD.Values<Params>>, addRef?: boolean) => Promise<void>; readonly ref: (data: Data, add: boolean) => void; readonly get: (data: Data) => ValueBox<Value | undefined>; readonly set: (data: Data, props: PD.Values<Params>, value?: Value) => void; readonly props: (data: Data) => PD.Values<Params>; } class Registry<Data> { private providers; private defaultAutoAttachValues; /** Get params for all applicable property providers */ getParams(data?: Data): { autoAttach: PD.MultiSelect<string>; properties: PD.Group<PD.Normalize<{ [x: string]: any; }>>; }; setDefaultAutoAttach(name: string, value: boolean): void; get(name: string): Provider<Data, any, any>; register(provider: Provider<Data, any, any>, defaultAutoAttach: boolean): void; unregister(name: string): void; } }