/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import * as React from 'react'; import { PluginContext } from '../context'; import { PluginStateObject } from 'mol-plugin/state/objects'; import { State } from 'mol-state' import { PluginCommands } from 'mol-plugin/command'; export class StateTree extends React.Component<{ plugin: PluginContext, state: State }, { }> { componentDidMount() { // TODO: move to constructor? this.props.state.events.changed.subscribe(() => this.forceUpdate()); } render() { // const n = this.props.plugin.state.data.tree.nodes.get(this.props.plugin.state.data.tree.rootRef)!; const n = this.props.state.tree.root.ref; return
{ /* n.children.map(c => ) */}
; } } export class StateTreeNode extends React.Component<{ plugin: PluginContext, nodeRef: string, state: State }, { }> { render() { const n = this.props.state.tree.nodes.get(this.props.nodeRef)!; const cell = this.props.state.cells.get(this.props.nodeRef)!; const remove = <>[ { e.preventDefault(); PluginCommands.State.RemoveObject.dispatch(this.props.plugin, { state: this.props.state, ref: this.props.nodeRef }); }}>X] let label: any; if (cell.status !== 'ok' || !cell.obj) { const name = (n.transformer.definition.display && n.transformer.definition.display.name) || n.transformer.definition.name; label = <>{cell.status} { e.preventDefault(); PluginCommands.State.SetCurrentObject.dispatch(this.props.plugin, { state: this.props.state, ref: this.props.nodeRef }); }}>{name}: {cell.errorText}; } else { const obj = cell.obj as PluginStateObject.Any; label = <> { e.preventDefault(); PluginCommands.State.SetCurrentObject.dispatch(this.props.plugin, { state: this.props.state, ref: this.props.nodeRef }); }}>{obj.label} {obj.description ? {obj.description} : void 0}; } const children = this.props.state.tree.children.get(this.props.nodeRef); return
{remove} {label} {children.size === 0 ? void 0 :
{children.map(c => )}
}
; } }