plugin.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import * as React from 'react';
  7. import { PluginContext } from '../context';
  8. import { StateTree } from './state-tree';
  9. import { Viewport } from './viewport';
  10. import { Controls, _test_CreateTransform } from './controls';
  11. import { Transformer } from 'mol-state';
  12. // TODO: base object with subscribe helpers
  13. export class Plugin extends React.Component<{ plugin: PluginContext }, { }> {
  14. render() {
  15. return <div style={{ position: 'absolute', width: '100%', height: '100%', fontFamily: 'monospace' }}>
  16. <div style={{ position: 'absolute', width: '350px', height: '100%', overflowY: 'scroll' }}>
  17. <StateTree plugin={this.props.plugin} />
  18. <hr />
  19. <_test_CurrentObject plugin={this.props.plugin} />
  20. </div>
  21. <div style={{ position: 'absolute', left: '350px', right: '250px', height: '100%' }}>
  22. <Viewport plugin={this.props.plugin} />
  23. </div>
  24. <div style={{ position: 'absolute', width: '250px', right: '0', height: '100%' }}>
  25. <Controls plugin={this.props.plugin} />
  26. </div>
  27. </div>;
  28. }
  29. }
  30. export class _test_CurrentObject extends React.Component<{ plugin: PluginContext }, { }> {
  31. componentDidMount() {
  32. // TODO: move to constructor?
  33. this.props.plugin.behaviors.state.data.currentObject.subscribe(() => this.forceUpdate());
  34. }
  35. render() {
  36. const ref = this.props.plugin.behaviors.state.data.currentObject.value.ref;
  37. // const n = this.props.plugin.state.data.tree.nodes.get(ref)!;
  38. const obj = this.props.plugin.state.data.objects.get(ref)!;
  39. const type = obj && obj.obj ? obj.obj.type : void 0;
  40. const transforms = type
  41. ? Transformer.fromType(type)
  42. : []
  43. return <div>
  44. Current Ref: {this.props.plugin.behaviors.state.data.currentObject.value.ref}
  45. <hr />
  46. {
  47. transforms.map((t, i) => <_test_CreateTransform key={`${t.id} ${ref} ${i}`} plugin={this.props.plugin} transformer={t} nodeRef={ref} />)
  48. }
  49. </div>;
  50. }
  51. }