David Sehnal 6 роки тому
батько
коміт
fd6aac51e7

+ 33 - 0
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;
+    }
+});

+ 7 - 0
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.
          */