@logicflow/react-node-registry 1.2.0-alpha.1 → 1.2.0-alpha.3
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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +15 -0
- 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 +3 -3
- package/rollup.config.js +52 -0
- package/src/components/Container.tsx +33 -0
- package/src/components/TitleBar.tsx +149 -0
- package/src/index.less +1 -0
- package/src/model.ts +82 -6
- package/src/style/index.less +140 -0
- package/src/style/raw.ts +129 -0
- package/src/view.ts +102 -9
- package/src/wrapper.tsx +17 -2
package/lib/view.d.ts
CHANGED
|
@@ -2,12 +2,21 @@ import { Root } from 'react-dom/client';
|
|
|
2
2
|
import { HtmlNode } from '@logicflow/core';
|
|
3
3
|
export declare class ReactNodeView extends HtmlNode {
|
|
4
4
|
root?: Root;
|
|
5
|
+
private containerEl?;
|
|
6
|
+
private __resizeObserver?;
|
|
7
|
+
private __resizeRafId?;
|
|
8
|
+
private __lastWidth?;
|
|
9
|
+
private __lastHeight?;
|
|
10
|
+
private __fallbackUnlisten?;
|
|
11
|
+
private __throttledUpdate;
|
|
5
12
|
protected targetId(): string;
|
|
6
13
|
componentWillUnmount(): void;
|
|
7
14
|
setHtml(rootEl: SVGForeignObjectElement): void;
|
|
8
|
-
confirmUpdate(_rootEl: SVGForeignObjectElement): void;
|
|
9
15
|
protected renderReactComponent(container: HTMLElement): void;
|
|
10
16
|
protected unmountReactComponent(): void;
|
|
11
17
|
unmount(): void;
|
|
18
|
+
private measureAndUpdate;
|
|
19
|
+
private startResizeObserver;
|
|
20
|
+
private stopResizeObserver;
|
|
12
21
|
}
|
|
13
22
|
export default ReactNodeView;
|
package/lib/view.js
CHANGED
|
@@ -19,13 +19,70 @@ exports.ReactNodeView = void 0;
|
|
|
19
19
|
var react_1 = require("react");
|
|
20
20
|
var client_1 = require("react-dom/client");
|
|
21
21
|
var core_1 = require("@logicflow/core");
|
|
22
|
+
var lodash_es_1 = require("lodash-es");
|
|
22
23
|
var wrapper_1 = require("./wrapper");
|
|
23
24
|
var portal_1 = require("./portal");
|
|
24
25
|
var react_dom_1 = require("react-dom");
|
|
25
26
|
var ReactNodeView = /** @class */ (function (_super) {
|
|
26
27
|
__extends(ReactNodeView, _super);
|
|
27
28
|
function ReactNodeView() {
|
|
28
|
-
|
|
29
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
+
_this.__throttledUpdate = (0, lodash_es_1.throttle)(function () { return _this.measureAndUpdate(); }, 80);
|
|
31
|
+
_this.measureAndUpdate = function () {
|
|
32
|
+
try {
|
|
33
|
+
var root = _this.containerEl;
|
|
34
|
+
if (!root)
|
|
35
|
+
return;
|
|
36
|
+
var target = root.firstElementChild || root;
|
|
37
|
+
var rect = target.getBoundingClientRect();
|
|
38
|
+
var width = (0, lodash_es_1.round)(rect.width);
|
|
39
|
+
var height = (0, lodash_es_1.round)(rect.height);
|
|
40
|
+
if (width <= 0 || height <= 0)
|
|
41
|
+
return;
|
|
42
|
+
if (width === _this.__lastWidth && height === _this.__lastHeight)
|
|
43
|
+
return;
|
|
44
|
+
_this.__lastWidth = width;
|
|
45
|
+
_this.__lastHeight = height;
|
|
46
|
+
var props = _this.props.model.properties;
|
|
47
|
+
var extra = (0, lodash_es_1.get)(props, '_showTitle')
|
|
48
|
+
? (0, lodash_es_1.isNumber)((0, lodash_es_1.get)(props, '_titleHeight'))
|
|
49
|
+
? (0, lodash_es_1.get)(props, '_titleHeight')
|
|
50
|
+
: 28
|
|
51
|
+
: 0;
|
|
52
|
+
var baseHeight = (0, lodash_es_1.clamp)(height - extra, 1, Number.MAX_SAFE_INTEGER);
|
|
53
|
+
_this.props.model.setProperties({ width: width, height: baseHeight });
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
console.error('measureAndUpdate error', err);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return _this;
|
|
60
|
+
// TODO: 确认是否需要重写 onMouseDown 方法
|
|
61
|
+
// handleMouseDown(ev: MouseEvent, x: number, y: number) {
|
|
62
|
+
// const target = ev.target as Element
|
|
63
|
+
// const tagName = target.tagName.toLowerCase()
|
|
64
|
+
// if (tagName === 'input') {
|
|
65
|
+
// const type = target.getAttribute('type')
|
|
66
|
+
// if (
|
|
67
|
+
// type == null ||
|
|
68
|
+
// [
|
|
69
|
+
// 'text',
|
|
70
|
+
// 'password',
|
|
71
|
+
// 'number',
|
|
72
|
+
// 'email',
|
|
73
|
+
// 'search',
|
|
74
|
+
// 'tel',
|
|
75
|
+
// 'url',
|
|
76
|
+
// ].includes(type)
|
|
77
|
+
// ) {
|
|
78
|
+
// return
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
//
|
|
82
|
+
// console.log('pointer position, x:', x, 'y: ', y)
|
|
83
|
+
// // TODO
|
|
84
|
+
// // super.handleMouseDown(ev)
|
|
85
|
+
// }
|
|
29
86
|
}
|
|
30
87
|
ReactNodeView.prototype.targetId = function () {
|
|
31
88
|
return "".concat(this.props.graphModel.flowId, ":").concat(this.props.model.id);
|
|
@@ -35,15 +92,23 @@ var ReactNodeView = /** @class */ (function (_super) {
|
|
|
35
92
|
this.unmount();
|
|
36
93
|
};
|
|
37
94
|
ReactNodeView.prototype.setHtml = function (rootEl) {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
var existed = rootEl.querySelector('.custom-react-node-content');
|
|
96
|
+
if (existed) {
|
|
97
|
+
this.containerEl = existed;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
var el = document.createElement('div');
|
|
101
|
+
el.className = 'custom-react-node-content';
|
|
102
|
+
this.containerEl = el;
|
|
103
|
+
this.renderReactComponent(el);
|
|
104
|
+
rootEl.appendChild(el);
|
|
105
|
+
}
|
|
106
|
+
this.startResizeObserver();
|
|
46
107
|
};
|
|
108
|
+
// confirmUpdate(_rootEl: SVGForeignObjectElement) {
|
|
109
|
+
// // TODO: 如有需要,可以先通过继承的方式,自定义该节点的更新逻辑;我们后续会根据实际需求,丰富该功能
|
|
110
|
+
// console.log('_rootEl', _rootEl)
|
|
111
|
+
// }
|
|
47
112
|
ReactNodeView.prototype.renderReactComponent = function (container) {
|
|
48
113
|
this.unmountReactComponent();
|
|
49
114
|
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
|
|
@@ -67,6 +132,7 @@ var ReactNodeView = /** @class */ (function (_super) {
|
|
|
67
132
|
};
|
|
68
133
|
ReactNodeView.prototype.unmountReactComponent = function () {
|
|
69
134
|
if (this.rootEl && this.root) {
|
|
135
|
+
this.stopResizeObserver();
|
|
70
136
|
this.root.unmount();
|
|
71
137
|
this.root = undefined;
|
|
72
138
|
this.rootEl.innerHTML = '';
|
|
@@ -76,6 +142,54 @@ var ReactNodeView = /** @class */ (function (_super) {
|
|
|
76
142
|
ReactNodeView.prototype.unmount = function () {
|
|
77
143
|
this.unmountReactComponent();
|
|
78
144
|
};
|
|
145
|
+
ReactNodeView.prototype.startResizeObserver = function () {
|
|
146
|
+
var _this = this;
|
|
147
|
+
var _a;
|
|
148
|
+
var root = this.containerEl;
|
|
149
|
+
if (!root)
|
|
150
|
+
return;
|
|
151
|
+
try {
|
|
152
|
+
if ((0, lodash_es_1.isFunction)(window.ResizeObserver)) {
|
|
153
|
+
this.__resizeObserver = new window.ResizeObserver(function (entries) {
|
|
154
|
+
if (!(0, lodash_es_1.isArray)(entries) || !entries.length)
|
|
155
|
+
return;
|
|
156
|
+
if (_this.__resizeRafId)
|
|
157
|
+
cancelAnimationFrame(_this.__resizeRafId);
|
|
158
|
+
_this.__resizeRafId = requestAnimationFrame(_this.__throttledUpdate);
|
|
159
|
+
});
|
|
160
|
+
var target = root.firstElementChild || root;
|
|
161
|
+
(_a = this.__resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(target);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
window.addEventListener('resize', function () { return _this.__throttledUpdate(); });
|
|
165
|
+
this.__fallbackUnlisten = function () {
|
|
166
|
+
return window.removeEventListener('resize', function () { return _this.__throttledUpdate(); });
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
console.error('startResizeObserver error', err);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
ReactNodeView.prototype.stopResizeObserver = function () {
|
|
175
|
+
try {
|
|
176
|
+
if (this.__resizeObserver) {
|
|
177
|
+
this.__resizeObserver.disconnect();
|
|
178
|
+
this.__resizeObserver = undefined;
|
|
179
|
+
}
|
|
180
|
+
if (this.__resizeRafId) {
|
|
181
|
+
cancelAnimationFrame(this.__resizeRafId);
|
|
182
|
+
this.__resizeRafId = undefined;
|
|
183
|
+
}
|
|
184
|
+
if (this.__fallbackUnlisten) {
|
|
185
|
+
this.__fallbackUnlisten();
|
|
186
|
+
this.__fallbackUnlisten = undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
console.error('stopResizeObserver error', err);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
79
193
|
return ReactNodeView;
|
|
80
194
|
}(core_1.HtmlNode));
|
|
81
195
|
exports.ReactNodeView = ReactNodeView;
|
package/lib/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAkD;AAClD,2CAAmD;AACnD,wCAA0C;AAC1C,qCAAmC;AACnC,mCAAiC;AACjC,uCAAwC;AAExC;IAAmC,iCAAQ;IAA3C;;
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAkD;AAClD,2CAAmD;AACnD,wCAA0C;AAC1C,uCAQkB;AAClB,qCAAmC;AACnC,mCAAiC;AACjC,uCAAwC;AAExC;IAAmC,iCAAQ;IAA3C;;QAQU,uBAAiB,GAAG,IAAA,oBAAQ,EAAC,cAAM,OAAA,KAAI,CAAC,gBAAgB,EAAE,EAAvB,CAAuB,EAAE,EAAE,CAAC,CAAA;QAqE/D,sBAAgB,GAAG;YACzB,IAAI,CAAC;gBACH,IAAM,IAAI,GAAG,KAAI,CAAC,WAA0B,CAAA;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A;YACnC,CAAC;YACD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACvB,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;gBACxC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;YAChC,CAAC;YACD,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC5B,IAAI,CAAC,kBAAkB,EAAE,CAAA;gBACzB,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IA4BH,oBAAC;AAAD,CAAC,AA3KD,CAAmC,eAAQ,GA2K1C;AA3KY,sCAAa;AA6K1B,kBAAe,aAAa,CAAA"}
|
package/lib/wrapper.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare class Wrapper extends PureComponent<IWrapperProps, IWrapperState>
|
|
|
11
11
|
constructor(props: IWrapperProps);
|
|
12
12
|
componentDidMount(): void;
|
|
13
13
|
clone(elem: React.ReactElement): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
14
|
-
render(): React.
|
|
14
|
+
render(): React.JSX.Element | null;
|
|
15
15
|
}
|
|
16
16
|
export default Wrapper;
|
package/lib/wrapper.js
CHANGED
|
@@ -37,11 +37,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
37
|
__setModuleDefault(result, mod);
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
40
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
44
|
exports.Wrapper = void 0;
|
|
42
45
|
var react_1 = __importStar(require("react"));
|
|
43
46
|
var core_1 = require("@logicflow/core");
|
|
44
47
|
var registry_1 = require("./registry");
|
|
48
|
+
var Container_1 = __importDefault(require("./components/Container"));
|
|
45
49
|
var Wrapper = /** @class */ (function (_super) {
|
|
46
50
|
__extends(Wrapper, _super);
|
|
47
51
|
function Wrapper(props) {
|
|
@@ -76,12 +80,13 @@ var Wrapper = /** @class */ (function (_super) {
|
|
|
76
80
|
var content = registry_1.reactNodesMap[node.type];
|
|
77
81
|
if (!content)
|
|
78
82
|
return null;
|
|
83
|
+
var _a = (node.properties || {})._showTitle, _showTitle = _a === void 0 ? false : _a;
|
|
79
84
|
var component = content.component;
|
|
80
85
|
if (react_1.default.isValidElement(component)) {
|
|
81
|
-
return this.clone(component);
|
|
86
|
+
return _showTitle ? (react_1.default.createElement(Container_1.default, { node: this.props.node, graph: this.props.graph }, this.clone(component))) : (this.clone(component));
|
|
82
87
|
}
|
|
83
88
|
var FC = component;
|
|
84
|
-
return this.clone(react_1.default.createElement(FC, null));
|
|
89
|
+
return _showTitle ? (react_1.default.createElement(Container_1.default, { node: this.props.node, graph: this.props.graph }, this.clone(react_1.default.createElement(FC, null)))) : (this.clone(react_1.default.createElement(FC, null)));
|
|
85
90
|
};
|
|
86
91
|
return Wrapper;
|
|
87
92
|
}(react_1.PureComponent));
|
package/lib/wrapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4C;AAC5C,wCAAsE;AACtE,uCAA0C;AAC1C,qEAA8C;AAW9C;IAA6B,2BAA2C;IACtE,iBAAY,KAAoB;QAC9B,YAAA,MAAK,YAAC,KAAK,CAAC,SAAA;QACZ,KAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;;IAC1B,CAAC;IAED,mCAA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I,CAAC,IAAI,CAAC,CAAA;QAExC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAA;QAEjB,IAAA,KAAuB,CAAA,IAAI,CAAC,UAAU,IAAI,EAAE,CAAA,WAA1B,EAAlB,UAAU,mBAAG,KAAK,KAAA,CAA0B;QAE5C,IAAA,SAAS,GAAK,OAAO,UAAZ,CAAY;QAC7B,IAAI,eAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,CAAC,CAAC,CAClB,8BAAC,mBAAS,IAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IACtD,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CACZ,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CACtB,CAAA;QACH,CAAC;QACD,IAAM,EAAE,GAAG,SAAqB,CAAA;QAChC,OAAO,UAAU,CAAC,CAAC,CAAC,CAClB,8BAAC,mBAAS,IAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IACtD,IAAI,CAAC,KAAK,CAAC,8BAAC,EAAE,OAAG,CAAC,CACT,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CAAC,KAAK,CAAC,8BAAC,EAAE,OAAG,CAAC,CACnB,CAAA;IACH,CAAC;IACH,cAAC;AAAD,CAAC,AA3DD,CAA6B,qBAAa,GA2DzC;AA3DY,0BAAO;AA6DpB,kBAAe,OAAO,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logicflow/react-node-registry",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.3",
|
|
4
4
|
"description": "LogicFlow React Shape",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": ">= 18.0.0",
|
|
20
20
|
"react-dom": ">= 18.0.0",
|
|
21
|
-
"@logicflow/core": "2.2.0-alpha.
|
|
21
|
+
"@logicflow/core": "2.2.0-alpha.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@types/react": "^18.0.25",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react": "^18.0.0",
|
|
27
27
|
"react-dom": "^18.0.0",
|
|
28
28
|
"lodash-es": "^4.17.21",
|
|
29
|
-
"@logicflow/core": "2.2.0-alpha.
|
|
29
|
+
"@logicflow/core": "2.2.0-alpha.3"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"clean:turbo": "rss",
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import postcss from 'rollup-plugin-postcss'
|
|
3
|
+
import postcssUrl from 'postcss-url'
|
|
4
|
+
import postcssImport from 'postcss-import'
|
|
5
|
+
import { rollupConfig } from '../../rollup.config'
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
{
|
|
9
|
+
input: 'src/index.less',
|
|
10
|
+
output: [
|
|
11
|
+
{
|
|
12
|
+
file: 'dist/index.css',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
file: 'lib/index.css',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
file: 'lib/style/index.css',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
file: 'es/index.css',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
file: 'es/style/index.css',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
plugins: [
|
|
28
|
+
postcss({
|
|
29
|
+
plugins: [
|
|
30
|
+
postcssImport({
|
|
31
|
+
resolve: (id) => {
|
|
32
|
+
if (id.startsWith('~')) {
|
|
33
|
+
return path.resolve('node_modules', id.slice(1))
|
|
34
|
+
}
|
|
35
|
+
return id
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
postcssUrl({
|
|
39
|
+
url: 'inline', // 选择 'inline' 选项将外部资源内联到最终的 CSS 文件中
|
|
40
|
+
// maxSize: 10, // 以KB为单位的最大文件大小,超过此大小的文件将不会被内联
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
use: [['less', { javascriptEnabled: true }]],
|
|
44
|
+
extract: true,
|
|
45
|
+
// extract: 'index.css', // 提取到一个单独的 CSS 文件
|
|
46
|
+
// extract: path.resolve('dist/index.css'), // 提取到一个单独的 CSS 文件
|
|
47
|
+
minimize: true,
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
rollupConfig(),
|
|
52
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { BaseNodeModel, GraphModel } from '@logicflow/core'
|
|
3
|
+
import TitleBar from './TitleBar'
|
|
4
|
+
|
|
5
|
+
export type ContainerProps = {
|
|
6
|
+
node: BaseNodeModel
|
|
7
|
+
graph: GraphModel
|
|
8
|
+
children?: React.ReactNode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Container: React.FC<ContainerProps> = ({
|
|
12
|
+
node,
|
|
13
|
+
graph,
|
|
14
|
+
children,
|
|
15
|
+
}) => {
|
|
16
|
+
const props: any = node?.properties || {}
|
|
17
|
+
const titleColor = props.style?.titleColor || '#E5EEFC'
|
|
18
|
+
const expanded = props._expanded === true
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
className="lf-vue-node-container"
|
|
23
|
+
style={{
|
|
24
|
+
background: `linear-gradient(180deg, ${titleColor} 0%, #FFFFFF 24px)`,
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
{props._showTitle && <TitleBar node={node} graph={graph} />}
|
|
28
|
+
{expanded && <div className="lf-vue-node-content-wrap">{children}</div>}
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default Container
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { BaseNodeModel, GraphModel } from '@logicflow/core'
|
|
3
|
+
import { isNumber } from 'lodash-es'
|
|
4
|
+
|
|
5
|
+
export type TitleBarProps = {
|
|
6
|
+
node: BaseNodeModel
|
|
7
|
+
graph: GraphModel
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TitleBar: React.FC<TitleBarProps> = ({ node, graph }) => {
|
|
11
|
+
const props: any = node?.properties || {}
|
|
12
|
+
const icon = props._icon
|
|
13
|
+
const title = props._title || ''
|
|
14
|
+
const expanded = !!props._expanded
|
|
15
|
+
const titleHeight = isNumber(props._titleHeight) ? props._titleHeight : 28
|
|
16
|
+
const actProps = props._titleActions || []
|
|
17
|
+
const privActs = (node as any).__actions || []
|
|
18
|
+
const actions =
|
|
19
|
+
Array.isArray(privActs) && privActs.length > 0 ? privActs : actProps
|
|
20
|
+
const showMoreAction = Array.isArray(actions) && actions.length > 0
|
|
21
|
+
const trigger = props.titleTrigger === 'hover' ? 'hover' : 'click'
|
|
22
|
+
const [showTooltip, setShowTooltip] = useState(false)
|
|
23
|
+
const moreBtnRef = useRef<HTMLButtonElement | null>(null)
|
|
24
|
+
const tooltipRef = useRef<HTMLDivElement | null>(null)
|
|
25
|
+
|
|
26
|
+
const toggleExpand = () => {
|
|
27
|
+
const cur = !!node?.properties?._expanded
|
|
28
|
+
node?.setProperty('_expanded', !cur)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const runAction = (act: any) => {
|
|
32
|
+
const fn =
|
|
33
|
+
act?.callback ||
|
|
34
|
+
(privActs || []).find((a: any) => a?.name === act?.name)?.callback
|
|
35
|
+
typeof fn === 'function' && fn(node, graph)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (trigger === 'hover') {
|
|
40
|
+
const mb = moreBtnRef.current
|
|
41
|
+
const tt = tooltipRef.current
|
|
42
|
+
const onEnter = () => setShowTooltip(true)
|
|
43
|
+
const onLeave = () => setShowTooltip(false)
|
|
44
|
+
mb?.addEventListener('mouseenter', onEnter)
|
|
45
|
+
mb?.addEventListener('mouseleave', onLeave)
|
|
46
|
+
tt?.addEventListener('mouseenter', onEnter)
|
|
47
|
+
tt?.addEventListener('mouseleave', onLeave)
|
|
48
|
+
return () => {
|
|
49
|
+
mb?.removeEventListener('mouseenter', onEnter)
|
|
50
|
+
mb?.removeEventListener('mouseleave', onLeave)
|
|
51
|
+
tt?.removeEventListener('mouseenter', onEnter)
|
|
52
|
+
tt?.removeEventListener('mouseleave', onLeave)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const onDoc = (e: MouseEvent) => {
|
|
56
|
+
const mb = moreBtnRef.current
|
|
57
|
+
const tt = tooltipRef.current
|
|
58
|
+
const t = e.target as Node
|
|
59
|
+
if (showTooltip && mb && tt && !mb.contains(t) && !tt.contains(t)) {
|
|
60
|
+
setShowTooltip(false)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
document.addEventListener('click', onDoc)
|
|
64
|
+
return () => document.removeEventListener('click', onDoc)
|
|
65
|
+
}, [trigger, showTooltip])
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
className={
|
|
70
|
+
expanded
|
|
71
|
+
? 'lf-vue-node-title lf-vue-node-title-expanded'
|
|
72
|
+
: 'lf-vue-node-title'
|
|
73
|
+
}
|
|
74
|
+
style={{ height: expanded ? titleHeight : 18 }}
|
|
75
|
+
title={title}
|
|
76
|
+
>
|
|
77
|
+
<div className="lf-vue-node-title-left">
|
|
78
|
+
{icon ? <i className="lf-vue-node-title-icon">{icon}</i> : null}
|
|
79
|
+
<span className="lf-vue-node-title-text">{title}</span>
|
|
80
|
+
</div>
|
|
81
|
+
<div className="lf-vue-node-title-actions">
|
|
82
|
+
<button
|
|
83
|
+
className="lf-vue-node-title-expand"
|
|
84
|
+
onClick={(e) => {
|
|
85
|
+
e.stopPropagation()
|
|
86
|
+
toggleExpand()
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<svg
|
|
90
|
+
width={14}
|
|
91
|
+
height={12}
|
|
92
|
+
viewBox="0 0 14 12"
|
|
93
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
94
|
+
className="lf-vue-node-title-expand-icon"
|
|
95
|
+
style={{ transform: expanded ? 'rotate(180deg)' : 'rotate(0deg)' }}
|
|
96
|
+
>
|
|
97
|
+
<path
|
|
98
|
+
d="M0.5201124,5.47988755C0.23603013,5.7639699,0.24460429,6.2271326,0.53900635,6.5005059L6.3195491,11.8681526C6.7032304,12.2244282,7.2967696,12.2244282,7.6804514,11.8681526L13.460994,6.5005059C13.755396,6.2271326,13.76397,5.7639699,13.479888,5.47988755C13.211547,5.21154633,12.779465,5.20215771,12.499721,5.45858961L7.3378625,10.1902928C7.1467018,10.3655233,6.8532982,10.3655233,6.6621375,10.1902928L1.5002797,5.45858967C1.2205358,5.20215771,0.78845364,5.21154633,0.5201124,5.47988755Z"
|
|
99
|
+
fill="#474747"
|
|
100
|
+
/>
|
|
101
|
+
<path
|
|
102
|
+
d="M0.5201124,0.47988755C0.23603013,0.7639699,0.24460429,1.2271326,0.53900635,1.5005059L6.3195491,6.8681526C6.7032304,7.2244282,7.2967696,7.2244282,7.6804514,6.8681526L13.460994,1.5005059C13.755396,1.2271326,13.76397,0.7639699,13.479888,0.47988755C13.211547,0.21154633,12.779465,0.20215771,12.499721,0.45858961L7.3378625,5.1902928C7.1467018,5.3655233,6.8532982,5.3655233,6.6621375,5.1902928L1.5002797,0.45858967C1.2205358,0.20215771,0.78845364,0.21154633,0.5201124,0.47988755Z"
|
|
103
|
+
fill="#9B9B9B"
|
|
104
|
+
/>
|
|
105
|
+
</svg>
|
|
106
|
+
</button>
|
|
107
|
+
{showMoreAction && (
|
|
108
|
+
<button
|
|
109
|
+
ref={moreBtnRef}
|
|
110
|
+
className="lf-vue-node-title-more"
|
|
111
|
+
onClick={(e) => {
|
|
112
|
+
e.stopPropagation()
|
|
113
|
+
if (trigger === 'click') setShowTooltip(!showTooltip)
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<i className="lf-vue-node-title-more-icon">⋯</i>
|
|
117
|
+
</button>
|
|
118
|
+
)}
|
|
119
|
+
{showMoreAction && (
|
|
120
|
+
<div
|
|
121
|
+
ref={tooltipRef}
|
|
122
|
+
className="lf-vue-node-title-tooltip"
|
|
123
|
+
style={{
|
|
124
|
+
opacity: showTooltip ? 1 : 0,
|
|
125
|
+
pointerEvents: showTooltip ? 'auto' : 'none',
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
<div className="lf-vue-node-title-tooltip-list">
|
|
129
|
+
{actions.map((act: any, idx: number) => (
|
|
130
|
+
<div
|
|
131
|
+
key={idx}
|
|
132
|
+
className="lf-vue-node-title-tooltip-item"
|
|
133
|
+
onClick={(e) => {
|
|
134
|
+
e.stopPropagation()
|
|
135
|
+
runAction(act)
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
{act?.name || ''}
|
|
139
|
+
</div>
|
|
140
|
+
))}
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default TitleBar
|
package/src/index.less
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import url('./style/index.less');
|
package/src/model.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import LogicFlow, {
|
|
2
|
-
|
|
1
|
+
import LogicFlow, {
|
|
2
|
+
HtmlNodeModel,
|
|
3
|
+
IHtmlNodeProperties,
|
|
4
|
+
BaseNodeModel,
|
|
5
|
+
GraphModel,
|
|
6
|
+
} from '@logicflow/core'
|
|
7
|
+
import { cloneDeep, isNil, isArray, isEmpty } from 'lodash-es'
|
|
8
|
+
|
|
9
|
+
import NodeConfig = LogicFlow.NodeConfig
|
|
10
|
+
|
|
11
|
+
export type NodeAction = {
|
|
12
|
+
name: string
|
|
13
|
+
callback?: (node: BaseNodeModel, graph: GraphModel) => void
|
|
14
|
+
}
|
|
3
15
|
|
|
4
16
|
export interface ReactCustomProperties extends IHtmlNodeProperties {
|
|
5
17
|
// 形状属性
|
|
@@ -14,22 +26,81 @@ export interface ReactCustomProperties extends IHtmlNodeProperties {
|
|
|
14
26
|
// 样式属性
|
|
15
27
|
style?: LogicFlow.CommonTheme
|
|
16
28
|
textStyle?: LogicFlow.TextNodeTheme
|
|
29
|
+
// 标题配置
|
|
30
|
+
_showTitle?: boolean
|
|
31
|
+
_title?: string
|
|
32
|
+
_icon?: string
|
|
33
|
+
_titleHeight?: number
|
|
34
|
+
_expanded?: boolean
|
|
17
35
|
}
|
|
18
36
|
|
|
19
37
|
export class ReactNodeModel<
|
|
20
38
|
P extends ReactCustomProperties = ReactCustomProperties,
|
|
21
39
|
> extends HtmlNodeModel<P> {
|
|
40
|
+
private __baseHeight?: number
|
|
41
|
+
public __actions?: {
|
|
42
|
+
name: string
|
|
43
|
+
callback?: (node: BaseNodeModel, graph: GraphModel) => void
|
|
44
|
+
}[]
|
|
45
|
+
constructor(data: NodeConfig<P>, graphModel: GraphModel) {
|
|
46
|
+
super(data, graphModel)
|
|
47
|
+
const { properties } = data
|
|
48
|
+
if (properties) {
|
|
49
|
+
const { _showTitle = false, style = {} } = properties
|
|
50
|
+
if (_showTitle) {
|
|
51
|
+
this.minWidth = 160
|
|
52
|
+
this.minHeight = 80
|
|
53
|
+
this.text.editable = false
|
|
54
|
+
// 判断当前节点宽高是否小于最小宽高,如果是,强制设置为最小宽高
|
|
55
|
+
const newWidth = this.width < this.minWidth ? this.minWidth : this.width
|
|
56
|
+
const newHeight =
|
|
57
|
+
this.height < this.minHeight ? this.minHeight : this.height
|
|
58
|
+
|
|
59
|
+
this.setProperties({
|
|
60
|
+
_expanded: false,
|
|
61
|
+
...properties,
|
|
62
|
+
style: {
|
|
63
|
+
overflow: 'visible',
|
|
64
|
+
...cloneDeep(style),
|
|
65
|
+
},
|
|
66
|
+
width: newWidth,
|
|
67
|
+
height: newHeight,
|
|
68
|
+
})
|
|
69
|
+
this.setNodeActions([
|
|
70
|
+
{
|
|
71
|
+
name: '复制',
|
|
72
|
+
callback: (nodeModel: BaseNodeModel, graphModel: GraphModel) => {
|
|
73
|
+
graphModel.cloneNode(nodeModel.id)
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: '删除',
|
|
78
|
+
callback: (nodeModel: BaseNodeModel, graphModel: GraphModel) => {
|
|
79
|
+
graphModel.deleteNode(nodeModel.id)
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
])
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
22
87
|
setAttributes() {
|
|
23
|
-
const { width, height, radius } = this.properties
|
|
24
|
-
if (width) {
|
|
88
|
+
const { width, height, radius, _showTitle, _titleHeight } = this.properties
|
|
89
|
+
if (!isNil(width)) {
|
|
25
90
|
this.width = width
|
|
26
91
|
}
|
|
27
|
-
if (height) {
|
|
92
|
+
if (!isNil(height)) {
|
|
28
93
|
this.height = height
|
|
29
94
|
}
|
|
30
|
-
if (radius) {
|
|
95
|
+
if (!isNil(radius)) {
|
|
31
96
|
this.radius = radius
|
|
32
97
|
}
|
|
98
|
+
if (this.__baseHeight === undefined) {
|
|
99
|
+
this.__baseHeight = isNil(height) ? this.height : height
|
|
100
|
+
}
|
|
101
|
+
const extra = _showTitle ? (_titleHeight ?? 28) : 0
|
|
102
|
+
const base = isNil(height) ? this.__baseHeight : height
|
|
103
|
+
this.height = base + extra
|
|
33
104
|
}
|
|
34
105
|
|
|
35
106
|
getTextStyle(): LogicFlow.TextNodeTheme {
|
|
@@ -59,6 +130,11 @@ export class ReactNodeModel<
|
|
|
59
130
|
// ry: radius,
|
|
60
131
|
}
|
|
61
132
|
}
|
|
133
|
+
|
|
134
|
+
setNodeActions(actions: NodeAction[]) {
|
|
135
|
+
this.__actions =
|
|
136
|
+
isArray(actions) && !isEmpty(actions) ? cloneDeep(actions) : []
|
|
137
|
+
}
|
|
62
138
|
}
|
|
63
139
|
|
|
64
140
|
export default ReactNodeModel
|