@logicflow/react-node-registry 1.2.0 → 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/README.md +6 -3
- package/dist/index.css +122 -0
- package/es/components/Container.d.ts +9 -0
- package/es/components/Container.js +16 -0
- package/es/components/Container.js.map +1 -0
- package/es/components/TitleBar.d.ts +8 -0
- package/es/components/TitleBar.js +87 -0
- package/es/components/TitleBar.js.map +1 -0
- package/es/index.css +122 -0
- package/es/index.less +1 -0
- package/es/model.d.ts +18 -1
- package/es/model.js +46 -8
- package/es/model.js.map +1 -1
- package/es/style/index.css +122 -0
- package/es/style/index.less +140 -0
- package/es/style/raw.d.ts +4 -0
- package/es/style/raw.js +6 -0
- package/es/style/raw.js.map +1 -0
- package/es/view.d.ts +10 -1
- package/es/view.js +123 -9
- package/es/view.js.map +1 -1
- package/es/wrapper.d.ts +1 -1
- package/es/wrapper.js +4 -2
- package/es/wrapper.js.map +1 -1
- package/lib/components/Container.d.ts +9 -0
- package/lib/components/Container.js +23 -0
- package/lib/components/Container.js.map +1 -0
- package/lib/components/TitleBar.d.ts +8 -0
- package/lib/components/TitleBar.js +114 -0
- package/lib/components/TitleBar.js.map +1 -0
- package/lib/index.css +122 -0
- package/lib/index.less +1 -0
- package/lib/model.d.ts +18 -1
- package/lib/model.js +44 -6
- package/lib/model.js.map +1 -1
- package/lib/style/index.css +122 -0
- package/lib/style/index.less +140 -0
- package/lib/style/raw.d.ts +4 -0
- package/lib/style/raw.js +9 -0
- package/lib/style/raw.js.map +1 -0
- package/lib/view.d.ts +10 -1
- package/lib/view.js +123 -9
- package/lib/view.js.map +1 -1
- package/lib/wrapper.d.ts +1 -1
- package/lib/wrapper.js +7 -2
- package/lib/wrapper.js.map +1 -1
- package/package.json +13 -6
- package/.turbo/turbo-build.log +0 -34
- package/CHANGELOG.md +0 -201
- package/src/index.ts +0 -5
- package/src/model.ts +0 -64
- package/src/portal.ts +0 -79
- package/src/registry.ts +0 -47
- package/src/view.ts +0 -97
- package/src/wrapper.tsx +0 -61
- package/stats.html +0 -4842
- package/tsconfig.json +0 -21
package/src/registry.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import LogicFlow, { BaseNodeModel, GraphModel } from '@logicflow/core'
|
|
2
|
-
import ReactNodeView from './view'
|
|
3
|
-
import ReactNodeModel from './model'
|
|
4
|
-
import RegisterConfig = LogicFlow.RegisterConfig
|
|
5
|
-
|
|
6
|
-
export type ReactNodeProps = {
|
|
7
|
-
node: BaseNodeModel
|
|
8
|
-
graph: GraphModel
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type ReactNodeConfig = {
|
|
12
|
-
type: string
|
|
13
|
-
component: React.ComponentType<ReactNodeProps>
|
|
14
|
-
effect?: (keyof LogicFlow.PropertiesType)[]
|
|
15
|
-
} & Partial<RegisterConfig>
|
|
16
|
-
|
|
17
|
-
export const reactNodesMap: Record<
|
|
18
|
-
string,
|
|
19
|
-
{
|
|
20
|
-
component: React.ComponentType<ReactNodeProps>
|
|
21
|
-
effect?: (keyof LogicFlow.PropertiesType)[]
|
|
22
|
-
}
|
|
23
|
-
> = {}
|
|
24
|
-
|
|
25
|
-
export function register(config: ReactNodeConfig, lf: LogicFlow) {
|
|
26
|
-
const {
|
|
27
|
-
type,
|
|
28
|
-
component,
|
|
29
|
-
effect,
|
|
30
|
-
view: CustomNodeView,
|
|
31
|
-
model: CustomNodeModel,
|
|
32
|
-
} = config
|
|
33
|
-
|
|
34
|
-
if (!type) {
|
|
35
|
-
throw new Error('You should specify type in config')
|
|
36
|
-
}
|
|
37
|
-
reactNodesMap[type] = {
|
|
38
|
-
component,
|
|
39
|
-
effect,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
lf.register({
|
|
43
|
-
type,
|
|
44
|
-
view: CustomNodeView || ReactNodeView,
|
|
45
|
-
model: CustomNodeModel || ReactNodeModel,
|
|
46
|
-
})
|
|
47
|
-
}
|
package/src/view.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { createElement, ReactPortal } from 'react'
|
|
2
|
-
import { createRoot, Root } from 'react-dom/client'
|
|
3
|
-
import { HtmlNode } from '@logicflow/core'
|
|
4
|
-
import { Wrapper } from './wrapper'
|
|
5
|
-
import { Portal } from './portal'
|
|
6
|
-
import { createPortal } from 'react-dom'
|
|
7
|
-
|
|
8
|
-
export class ReactNodeView extends HtmlNode {
|
|
9
|
-
root?: Root
|
|
10
|
-
|
|
11
|
-
protected targetId() {
|
|
12
|
-
return `${this.props.graphModel.flowId}:${this.props.model.id}`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
componentWillUnmount() {
|
|
16
|
-
super.componentWillUnmount()
|
|
17
|
-
this.unmount()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setHtml(rootEl: SVGForeignObjectElement) {
|
|
21
|
-
const el = document.createElement('div')
|
|
22
|
-
el.className = 'custom-react-node-content'
|
|
23
|
-
|
|
24
|
-
this.renderReactComponent(el)
|
|
25
|
-
rootEl.appendChild(el)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
confirmUpdate(_rootEl: SVGForeignObjectElement) {
|
|
29
|
-
// TODO: 如有需要,可以先通过继承的方式,自定义该节点的更新逻辑;我们后续会根据实际需求,丰富该功能
|
|
30
|
-
console.log('_rootEl', _rootEl)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
protected renderReactComponent(container: HTMLElement) {
|
|
34
|
-
this.unmountReactComponent()
|
|
35
|
-
const { model, graphModel } = this.props
|
|
36
|
-
|
|
37
|
-
if (container) {
|
|
38
|
-
// 基于自定义节点新建 React 元素
|
|
39
|
-
const elem = createElement(Wrapper, {
|
|
40
|
-
node: model,
|
|
41
|
-
graph: graphModel,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
if (Portal.isActive()) {
|
|
45
|
-
// 使用 Portal
|
|
46
|
-
const portal = createPortal(elem, container, model.id) as ReactPortal
|
|
47
|
-
Portal.connect(this.targetId(), portal)
|
|
48
|
-
} else {
|
|
49
|
-
// 创建 Root 元素
|
|
50
|
-
this.root = createRoot(container)
|
|
51
|
-
this.root.render(elem)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected unmountReactComponent() {
|
|
57
|
-
if (this.rootEl && this.root) {
|
|
58
|
-
this.root.unmount()
|
|
59
|
-
this.root = undefined
|
|
60
|
-
this.rootEl.innerHTML = ''
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// DONE: 是否需要 unmount 或 destroy 方法,在销毁后做一些处理
|
|
65
|
-
unmount() {
|
|
66
|
-
this.unmountReactComponent()
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// TODO: 确认是否需要重写 onMouseDown 方法
|
|
70
|
-
// handleMouseDown(ev: MouseEvent, x: number, y: number) {
|
|
71
|
-
// const target = ev.target as Element
|
|
72
|
-
// const tagName = target.tagName.toLowerCase()
|
|
73
|
-
// if (tagName === 'input') {
|
|
74
|
-
// const type = target.getAttribute('type')
|
|
75
|
-
// if (
|
|
76
|
-
// type == null ||
|
|
77
|
-
// [
|
|
78
|
-
// 'text',
|
|
79
|
-
// 'password',
|
|
80
|
-
// 'number',
|
|
81
|
-
// 'email',
|
|
82
|
-
// 'search',
|
|
83
|
-
// 'tel',
|
|
84
|
-
// 'url',
|
|
85
|
-
// ].includes(type)
|
|
86
|
-
// ) {
|
|
87
|
-
// return
|
|
88
|
-
// }
|
|
89
|
-
// }
|
|
90
|
-
//
|
|
91
|
-
// console.log('pointer position, x:', x, 'y: ', y)
|
|
92
|
-
// // TODO
|
|
93
|
-
// // super.handleMouseDown(ev)
|
|
94
|
-
// }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default ReactNodeView
|
package/src/wrapper.tsx
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import React, { PureComponent } from 'react'
|
|
2
|
-
import { BaseNodeModel, EventType, GraphModel } from '@logicflow/core'
|
|
3
|
-
import { reactNodesMap } from './registry'
|
|
4
|
-
|
|
5
|
-
export interface IWrapperProps {
|
|
6
|
-
node: BaseNodeModel
|
|
7
|
-
graph: GraphModel
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface IWrapperState {
|
|
11
|
-
tick: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Wrapper extends PureComponent<IWrapperProps, IWrapperState> {
|
|
15
|
-
constructor(props: IWrapperProps) {
|
|
16
|
-
super(props)
|
|
17
|
-
this.state = { tick: 0 }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
componentDidMount() {
|
|
21
|
-
// TODO: 讨论设计,如果节点有「副作用」属性配置的处理逻辑
|
|
22
|
-
const { node, graph } = this.props
|
|
23
|
-
graph.eventCenter.on(EventType.NODE_PROPERTIES_CHANGE, (eventData) => {
|
|
24
|
-
const keys = eventData.keys as string[]
|
|
25
|
-
const content = reactNodesMap[node.type]
|
|
26
|
-
|
|
27
|
-
if (content && eventData.id === node.id) {
|
|
28
|
-
const { effect } = content
|
|
29
|
-
|
|
30
|
-
// 如果没有定义 effect,则默认更新;如果定义了 effect,则只有在 effect 中的属性发生变化时才更新
|
|
31
|
-
if (!effect || keys.some((key) => effect.includes(key))) {
|
|
32
|
-
this.setState({ tick: this.state.tick + 1 })
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
clone(elem: React.ReactElement) {
|
|
39
|
-
const { node, graph } = this.props
|
|
40
|
-
|
|
41
|
-
return typeof elem.type === 'string'
|
|
42
|
-
? React.cloneElement(elem)
|
|
43
|
-
: React.cloneElement(elem, { node, graph })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
render() {
|
|
47
|
-
const { node } = this.props
|
|
48
|
-
const content = reactNodesMap[node.type]
|
|
49
|
-
|
|
50
|
-
if (!content) return null
|
|
51
|
-
|
|
52
|
-
const { component } = content
|
|
53
|
-
if (React.isValidElement(component)) {
|
|
54
|
-
return this.clone(component)
|
|
55
|
-
}
|
|
56
|
-
const FC = component as React.FC
|
|
57
|
-
return this.clone(<FC />)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default Wrapper
|