@logicflow/react-node-registry 1.2.0-alpha.7 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/wrapper.tsx DELETED
@@ -1,76 +0,0 @@
1
- import React, { PureComponent } from 'react'
2
- import { BaseNodeModel, EventType, GraphModel } from '@logicflow/core'
3
- import { reactNodesMap } from './registry'
4
- import Container from './components/Container'
5
-
6
- export interface IWrapperProps {
7
- node: BaseNodeModel
8
- graph: GraphModel
9
- }
10
-
11
- export interface IWrapperState {
12
- tick: number
13
- }
14
-
15
- export class Wrapper extends PureComponent<IWrapperProps, IWrapperState> {
16
- constructor(props: IWrapperProps) {
17
- super(props)
18
- this.state = { tick: 0 }
19
- }
20
-
21
- componentDidMount() {
22
- // TODO: 讨论设计,如果节点有「副作用」属性配置的处理逻辑
23
- const { node, graph } = this.props
24
- graph.eventCenter.on(EventType.NODE_PROPERTIES_CHANGE, (eventData) => {
25
- const keys = eventData.keys as string[]
26
- const content = reactNodesMap[node.type]
27
-
28
- if (content && eventData.id === node.id) {
29
- const { effect } = content
30
-
31
- // 如果没有定义 effect,则默认更新;如果定义了 effect,则只有在 effect 中的属性发生变化时才更新
32
- if (!effect || keys.some((key) => effect.includes(key))) {
33
- this.setState({ tick: this.state.tick + 1 })
34
- }
35
- }
36
- })
37
- }
38
-
39
- clone(elem: React.ReactElement) {
40
- const { node, graph } = this.props
41
-
42
- return typeof elem.type === 'string'
43
- ? React.cloneElement(elem)
44
- : React.cloneElement(elem, { node, graph })
45
- }
46
-
47
- render() {
48
- const { node } = this.props
49
- const content = reactNodesMap[node.type]
50
-
51
- if (!content) return null
52
-
53
- const { _showTitle = false } = node.properties || {}
54
-
55
- const { component } = content
56
- if (React.isValidElement(component)) {
57
- return _showTitle ? (
58
- <Container node={this.props.node} graph={this.props.graph}>
59
- {this.clone(component)}
60
- </Container>
61
- ) : (
62
- this.clone(component)
63
- )
64
- }
65
- const FC = component as React.FC
66
- return _showTitle ? (
67
- <Container node={this.props.node} graph={this.props.graph}>
68
- {this.clone(<FC />)}
69
- </Container>
70
- ) : (
71
- this.clone(<FC />)
72
- )
73
- }
74
- }
75
-
76
- export default Wrapper