@logicflow/react-node-registry
Version:
LogicFlow React Shape
64 lines • 2.8 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import React, { PureComponent } from 'react';
import { EventType } from '@logicflow/core';
import { reactNodesMap } from './registry';
var Wrapper = /** @class */ (function (_super) {
__extends(Wrapper, _super);
function Wrapper(props) {
var _this = _super.call(this, props) || this;
_this.state = { tick: 0 };
return _this;
}
Wrapper.prototype.componentDidMount = function () {
var _this = this;
// TODO: 讨论设计,如果节点有「副作用」属性配置的处理逻辑
var _a = this.props, node = _a.node, graph = _a.graph;
graph.eventCenter.on(EventType.NODE_PROPERTIES_CHANGE, function (eventData) {
var keys = eventData.keys;
var content = reactNodesMap[node.type];
if (content && eventData.id === node.id) {
var effect_1 = content.effect;
// 如果没有定义 effect,则默认更新;如果定义了 effect,则只有在 effect 中的属性发生变化时才更新
if (!effect_1 || keys.some(function (key) { return effect_1.includes(key); })) {
_this.setState({ tick: _this.state.tick + 1 });
}
}
});
};
Wrapper.prototype.clone = function (elem) {
var _a = this.props, node = _a.node, graph = _a.graph;
return typeof elem.type === 'string'
? React.cloneElement(elem)
: React.cloneElement(elem, { node: node, graph: graph });
};
Wrapper.prototype.render = function () {
var node = this.props.node;
var content = reactNodesMap[node.type];
if (!content)
return null;
var component = content.component;
if (React.isValidElement(component)) {
return this.clone(component);
}
var FC = component;
return this.clone(React.createElement(FC, null));
};
return Wrapper;
}(PureComponent));
export { Wrapper };
export default Wrapper;
//# sourceMappingURL=wrapper.js.map