|
@@ -5,29 +5,29 @@
|
|
|
*/
|
|
|
|
|
|
import * as React from 'react';
|
|
|
-import { PluginContext } from '../context';
|
|
|
import { Transform, State } from 'mol-state';
|
|
|
import { ParametersComponent } from 'mol-app/component/parameters';
|
|
|
import { StateAction } from 'mol-state/action';
|
|
|
import { PluginCommands } from 'mol-plugin/command';
|
|
|
import { UpdateTrajectory } from 'mol-plugin/state/actions/basic';
|
|
|
+import { PluginComponent } from './base';
|
|
|
|
|
|
-export class Controls extends React.Component<{ plugin: PluginContext }, { id: string }> {
|
|
|
+export class Controls extends PluginComponent<{ }, { }> {
|
|
|
state = { id: '1grm' };
|
|
|
|
|
|
private _snap: any = void 0;
|
|
|
private getSnapshot = () => {
|
|
|
- this._snap = this.props.plugin.state.getSnapshot();
|
|
|
+ this._snap = this.context.state.getSnapshot();
|
|
|
console.log(btoa(JSON.stringify(this._snap)));
|
|
|
}
|
|
|
private setSnapshot = () => {
|
|
|
if (!this._snap) return;
|
|
|
- this.props.plugin.state.setSnapshot(this._snap);
|
|
|
+ this.context.state.setSnapshot(this._snap);
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
return <div>
|
|
|
- <button onClick={() => this.props.plugin._test_centerView()}>Center View</button><br />
|
|
|
+ <button onClick={() => this.context._test_centerView()}>Center View</button><br />
|
|
|
<hr />
|
|
|
<button onClick={this.getSnapshot}>Get Snapshot</button>
|
|
|
<button onClick={this.setSnapshot}>Set Snapshot</button>
|
|
@@ -36,27 +36,27 @@ export class Controls extends React.Component<{ plugin: PluginContext }, { id: s
|
|
|
}
|
|
|
|
|
|
|
|
|
-export class _test_TrajectoryControls extends React.Component<{ plugin: PluginContext }> {
|
|
|
+export class _test_TrajectoryControls extends PluginComponent {
|
|
|
render() {
|
|
|
return <div>
|
|
|
<b>Trajectory: </b>
|
|
|
- <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.props.plugin, {
|
|
|
- state: this.props.plugin.state.data,
|
|
|
+ <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.context, {
|
|
|
+ state: this.context.state.data,
|
|
|
action: UpdateTrajectory.create({ action: 'advance', by: -1 })
|
|
|
})}><<</button>
|
|
|
- <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.props.plugin, {
|
|
|
- state: this.props.plugin.state.data,
|
|
|
+ <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.context, {
|
|
|
+ state: this.context.state.data,
|
|
|
action: UpdateTrajectory.create({ action: 'reset' })
|
|
|
})}>Reset</button>
|
|
|
- <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.props.plugin, {
|
|
|
- state: this.props.plugin.state.data,
|
|
|
+ <button onClick={() => PluginCommands.State.ApplyAction.dispatch(this.context, {
|
|
|
+ state: this.context.state.data,
|
|
|
action: UpdateTrajectory.create({ action: 'advance', by: +1 })
|
|
|
})}>>></button><br />
|
|
|
</div>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export class _test_ApplyAction extends React.Component<{ plugin: PluginContext, nodeRef: Transform.Ref, state: State, action: StateAction }, { params: any }> {
|
|
|
+export class _test_ApplyAction extends PluginComponent<{ nodeRef: Transform.Ref, state: State, action: StateAction }, { params: any }> {
|
|
|
private getObj() {
|
|
|
const obj = this.props.state.cells.get(this.props.nodeRef)!;
|
|
|
return obj;
|
|
@@ -67,7 +67,7 @@ export class _test_ApplyAction extends React.Component<{ plugin: PluginContext,
|
|
|
if (!p || !p.default) return {};
|
|
|
const obj = this.getObj();
|
|
|
if (!obj.obj) return {};
|
|
|
- return p.default(obj.obj, this.props.plugin);
|
|
|
+ return p.default(obj.obj, this.context);
|
|
|
}
|
|
|
|
|
|
private getParamDef() {
|
|
@@ -75,17 +75,17 @@ export class _test_ApplyAction extends React.Component<{ plugin: PluginContext,
|
|
|
if (!p || !p.controls) return {};
|
|
|
const obj = this.getObj();
|
|
|
if (!obj.obj) return {};
|
|
|
- return p.controls(obj.obj, this.props.plugin);
|
|
|
+ return p.controls(obj.obj, this.context);
|
|
|
}
|
|
|
|
|
|
private create() {
|
|
|
console.log('Apply Action', this.state.params);
|
|
|
- PluginCommands.State.ApplyAction.dispatch(this.props.plugin, {
|
|
|
+ PluginCommands.State.ApplyAction.dispatch(this.context, {
|
|
|
state: this.props.state,
|
|
|
action: this.props.action.create(this.state.params),
|
|
|
ref: this.props.nodeRef
|
|
|
});
|
|
|
- // this.props.plugin.applyTransform(this.props.state, this.props.nodeRef, this.props.transformer, this.state.params);
|
|
|
+ // this.context.applyTransform(this.props.state, this.props.nodeRef, this.props.transformer, this.state.params);
|
|
|
}
|
|
|
|
|
|
state = { params: this.getDefaultParams() }
|
|
@@ -111,7 +111,7 @@ export class _test_ApplyAction extends React.Component<{ plugin: PluginContext,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export class _test_UpdateTransform extends React.Component<{ plugin: PluginContext, state: State, nodeRef: Transform.Ref }, { params: any }> {
|
|
|
+export class _test_UpdateTransform extends PluginComponent<{ state: State, nodeRef: Transform.Ref }, { params: any }> {
|
|
|
private getCell(ref?: string) {
|
|
|
return this.props.state.cells.get(ref || this.props.nodeRef)!;
|
|
|
}
|
|
@@ -130,16 +130,16 @@ export class _test_UpdateTransform extends React.Component<{ plugin: PluginConte
|
|
|
const src = this.getCell(cell.sourceRef);
|
|
|
if (!src || !src.obj) return void 0;
|
|
|
|
|
|
- return def.params.controls(src.obj, this.props.plugin);
|
|
|
+ return def.params.controls(src.obj, this.context);
|
|
|
}
|
|
|
|
|
|
private update() {
|
|
|
console.log(this.props.nodeRef, this.state.params);
|
|
|
- this.props.plugin.updateTransform(this.props.state, this.props.nodeRef, this.state.params);
|
|
|
+ this.context.updateTransform(this.props.state, this.props.nodeRef, this.state.params);
|
|
|
}
|
|
|
|
|
|
// componentDidMount() {
|
|
|
- // const t = this.props.plugin.state.data.tree.nodes.get(this.props.nodeRef)!;
|
|
|
+ // const t = this.context.state.data.tree.nodes.get(this.props.nodeRef)!;
|
|
|
// if (t) this.setState({ params: t.value.params });
|
|
|
// }
|
|
|
|