UNPKG

react-vtk-js

Version:

React based declarative vtk.js visualization pipeline

2 lines (1 loc) 3.31 kB
import t from"../node_modules/@babel/runtime/helpers/esm/defineProperty.js";import e from"../node_modules/@babel/runtime/helpers/esm/classCallCheck.js";import r from"../node_modules/@babel/runtime/helpers/esm/createClass.js";import o from"../node_modules/@babel/runtime/helpers/esm/inherits.js";import n from"../node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js";import s from"../node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js";import a,{Component as i}from"react";import l from"prop-types";import{RepresentationContext as u,DownstreamContext as p}from"./View.js";import c from"../node_modules/@kitware/vtk.js/vtk.js";function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function m(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?f(Object(o),!0).forEach((function(r){t(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):f(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function d(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,o=s(t);if(e){var a=s(this).constructor;r=Reflect.construct(o,arguments,a)}else r=o.apply(this,arguments);return n(this,r)}}var h=function(t){o(s,i);var n=d(s);function s(t){var r;return e(this,s),(r=n.call(this,t)).algo=null,r}return r(s,[{key:"render",value:function(){var t=this;return a.createElement(u.Consumer,null,(function(e){return a.createElement(p.Consumer,null,(function(r){if(t.representation=e,!t.algo){var o=t.props,n=o.vtkClass,s=o.state;t.algo=c(m({vtkClass:n},s))}return t.downstream||(r.setInputConnection(t.algo.getOutputPort(),t.props.port),t.downstream=r),a.createElement(p.Provider,{value:t.algo},a.createElement("div",{key:t.props.id,id:t.props.id},t.props.children))}))}))}},{key:"componentDidMount",value:function(){this.update(this.props)}},{key:"componentDidUpdate",value:function(t,e,r){this.update(this.props,t)}},{key:"componentWillUnmount",value:function(){this.algo.delete(),this.algo=null}},{key:"update",value:function(t,e){var r=t.vtkClass,o=t.state;if(r&&(!e||r!==e.vtkClass)){if(this.algo){if(this.algo.getClassName()!==r){var n=this.algo;this.algo=c(m({vtkClass:r},o));for(var s=n.getNumberOfInputPorts(),a=0;a<s;a++){var i=n.getInputConnection(a);i?this.algo.setInputConnection(i,a):this.algo.setInputData(n.getInputData(a),a)}}}else this.algo=c(m({vtkClass:r},o));this.downstream.setInputConnection(this.algo.getOutputPort(),this.props.port)}!o||e&&o===e.state||(this.algo.set(o),this.representation&&this.representation.dataChanged()),0===this.algo.getNumberOfInputPorts()&&this.representation&&this.representation.dataAvailable()}}]),s}();h.defaultProps={port:0,vtkClass:"vtkConeSource",state:{}},h.propTypes={id:l.string,port:l.number,vtkClass:l.string,state:l.object,children:l.oneOfType([l.arrayOf(l.node),l.node])};export{h as default};