diff --git a/src/mol-plugin/state/transforms/misc.ts b/src/mol-plugin/state/transforms/misc.ts new file mode 100644 index 0000000000000000000000000000000000000000..9c8190dd10f36f5714dfce45901e5400c2f6892a --- /dev/null +++ b/src/mol-plugin/state/transforms/misc.ts @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { StateTransformer } from 'mol-state'; +import { shallowEqual } from 'mol-util'; +import { ParamDefinition as PD } from 'mol-util/param-definition'; +import { PluginStateObject as SO, PluginStateTransform } from '../objects'; + +export { CreateGroup }; +type CreateGroup = typeof CreateGroup +const CreateGroup = PluginStateTransform.BuiltIn({ + name: 'create-group', + display: { name: 'Parse CIF', description: 'Parse CIF from String or Binary data' }, + from: [], + to: SO.Group, + params: { + label: PD.Text('Group'), + description: PD.makeOptional(PD.Text('')) + } +})({ + apply({ params }) { + return new SO.Group({}, params); + }, + update({ oldParams, newParams, b }) { + if (shallowEqual(oldParams, newParams)) return StateTransformer.UpdateResult.Unchanged; + b.label = newParams.label; + b.description = newParams.description; + return StateTransformer.UpdateResult.Updated; + } +}); \ No newline at end of file diff --git a/src/mol-state/state/builder.ts b/src/mol-state/state/builder.ts index 824cf3561eb8af52533f44bab4c222f581d42669..d1e3f9d63e09e87875ede8a542e14ea63171214e 100644 --- a/src/mol-state/state/builder.ts +++ b/src/mol-state/state/builder.ts @@ -70,6 +70,13 @@ namespace StateBuilder { return new To(this.state, t.ref, this.root); } + /** + * A helper to greate a group-like state object and keep the current type. + */ + group<T extends StateTransformer<A, any, any>>(tr: T, params?: StateTransformer.Params<T>, options?: Partial<StateTransform.Options>, initialCellState?: Partial<StateObjectCell.State>): To<A> { + return this.apply(tr, params, options, initialCellState) as To<A>; + } + /** * Inserts a new transform that does not change the object type and move the original children to it. */