@logicflow/vue-node-registry 0.0.1-beta.0
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 +37 -0
- package/LICENSE +203 -0
- package/README.md +35 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +5 -0
- package/es/index.js.map +1 -0
- package/es/model.d.ts +16 -0
- package/es/model.js +63 -0
- package/es/model.js.map +1 -0
- package/es/registry.d.ts +12 -0
- package/es/registry.js +19 -0
- package/es/registry.js.map +1 -0
- package/es/teleport.d.ts +5 -0
- package/es/teleport.js +40 -0
- package/es/teleport.js.map +1 -0
- package/es/view.d.ts +14 -0
- package/es/view.js +116 -0
- package/es/view.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/model.d.ts +16 -0
- package/lib/model.js +66 -0
- package/lib/model.js.map +1 -0
- package/lib/registry.d.ts +12 -0
- package/lib/registry.js +23 -0
- package/lib/registry.js.map +1 -0
- package/lib/teleport.d.ts +5 -0
- package/lib/teleport.js +47 -0
- package/lib/teleport.js.map +1 -0
- package/lib/view.d.ts +14 -0
- package/lib/view.js +119 -0
- package/lib/view.js.map +1 -0
- package/package.json +54 -0
- package/src/index.ts +4 -0
- package/src/model.ts +67 -0
- package/src/registry.ts +43 -0
- package/src/teleport.ts +64 -0
- package/src/view.ts +105 -0
- package/tsconfig.json +20 -0
package/lib/model.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import LogicFlow, { HtmlNodeModel } from '@logicflow/core';
|
|
2
|
+
export type CustomProperties = {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
radius?: number;
|
|
6
|
+
refX?: number;
|
|
7
|
+
refY?: number;
|
|
8
|
+
style?: LogicFlow.CommonTheme;
|
|
9
|
+
textStyle?: LogicFlow.TextNodeTheme;
|
|
10
|
+
};
|
|
11
|
+
export declare class VueNodeModel extends HtmlNodeModel {
|
|
12
|
+
setAttributes(): void;
|
|
13
|
+
getTextStyle(): LogicFlow.TextNodeTheme;
|
|
14
|
+
getNodeStyle(): LogicFlow.CommonTheme;
|
|
15
|
+
}
|
|
16
|
+
export default VueNodeModel;
|
package/lib/model.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.VueNodeModel = void 0;
|
|
30
|
+
var core_1 = require("@logicflow/core");
|
|
31
|
+
var lodash_es_1 = require("lodash-es");
|
|
32
|
+
var VueNodeModel = /** @class */ (function (_super) {
|
|
33
|
+
__extends(VueNodeModel, _super);
|
|
34
|
+
function VueNodeModel() {
|
|
35
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
36
|
+
}
|
|
37
|
+
VueNodeModel.prototype.setAttributes = function () {
|
|
38
|
+
console.log('this.properties', this.properties);
|
|
39
|
+
var _a = this.properties, width = _a.width, height = _a.height, radius = _a.radius;
|
|
40
|
+
if (width) {
|
|
41
|
+
this.width = width;
|
|
42
|
+
}
|
|
43
|
+
if (height) {
|
|
44
|
+
this.height = height;
|
|
45
|
+
}
|
|
46
|
+
if (radius) {
|
|
47
|
+
this.radius = radius;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
VueNodeModel.prototype.getTextStyle = function () {
|
|
51
|
+
// const { x, y, width, height } = this
|
|
52
|
+
var _a = this.properties, _b = _a.refX, refX = _b === void 0 ? 0 : _b, _c = _a.refY, refY = _c === void 0 ? 0 : _c, textStyle = _a.textStyle;
|
|
53
|
+
var style = _super.prototype.getTextStyle.call(this);
|
|
54
|
+
// 通过 transform 重新设置 text 的位置
|
|
55
|
+
return __assign(__assign(__assign({}, style), ((0, lodash_es_1.cloneDeep)(textStyle) || {})), { transform: "matrix(1 0 0 1 ".concat(refX, " ").concat(refY, ")") });
|
|
56
|
+
};
|
|
57
|
+
VueNodeModel.prototype.getNodeStyle = function () {
|
|
58
|
+
var style = _super.prototype.getNodeStyle.call(this);
|
|
59
|
+
var customNodeStyle = this.properties.style;
|
|
60
|
+
return __assign(__assign({}, style), ((0, lodash_es_1.cloneDeep)(customNodeStyle) || {}));
|
|
61
|
+
};
|
|
62
|
+
return VueNodeModel;
|
|
63
|
+
}(core_1.HtmlNodeModel));
|
|
64
|
+
exports.VueNodeModel = VueNodeModel;
|
|
65
|
+
exports.default = VueNodeModel;
|
|
66
|
+
//# sourceMappingURL=model.js.map
|
package/lib/model.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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H,CAAC;IACH,mBAAC;AAAD,CAAC,AA9CD,CAAkC,oBAAa,GA8C9C;AA9CY,oCAAY;AAgDzB,kBAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import LogicFlow from '@logicflow/core';
|
|
2
|
+
import RegisterConfig = LogicFlow.RegisterConfig;
|
|
3
|
+
export type VueNodeConfig = {
|
|
4
|
+
type: string;
|
|
5
|
+
component: any;
|
|
6
|
+
effect?: (keyof LogicFlow.PropertiesType)[];
|
|
7
|
+
} & Partial<RegisterConfig>;
|
|
8
|
+
export declare const vueNodesMap: Record<string, {
|
|
9
|
+
component: any;
|
|
10
|
+
effect?: (keyof LogicFlow.PropertiesType)[];
|
|
11
|
+
}>;
|
|
12
|
+
export declare function register(config: VueNodeConfig, lf: LogicFlow): void;
|
package/lib/registry.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = exports.vueNodesMap = void 0;
|
|
4
|
+
var view_1 = require("./view");
|
|
5
|
+
var model_1 = require("./model");
|
|
6
|
+
exports.vueNodesMap = {};
|
|
7
|
+
function register(config, lf) {
|
|
8
|
+
var type = config.type, component = config.component, effect = config.effect, CustomNodeView = config.view, CustomNodeModel = config.model;
|
|
9
|
+
if (!type) {
|
|
10
|
+
throw new Error('You should specify type in config');
|
|
11
|
+
}
|
|
12
|
+
exports.vueNodesMap[type] = {
|
|
13
|
+
component: component,
|
|
14
|
+
effect: effect,
|
|
15
|
+
};
|
|
16
|
+
lf.register({
|
|
17
|
+
type: type,
|
|
18
|
+
view: CustomNodeView || view_1.VueNodeView,
|
|
19
|
+
model: CustomNodeModel || model_1.VueNodeModel,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.register = register;
|
|
23
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AACpC,iCAAsC;AAUzB,QAAA,WAAW,GAMpB,EAAE,CAAA;AAEN,SAAgB,QAAQ,CAAC,MAAqB,EAAE,EAAa;IAEzD,IAAA,IAAI,GAKF,MAAM,KALJ,EACJ,SAAS,GAIP,MAAM,UAJC,EACT,MAAM,GAGJ,MAAM,OAHF,EACA,cAAc,GAElB,MAAM,KAFY,EACb,eAAe,GACpB,MAAM,MADc,CACd;IAEV,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;IACD,mBAAW,CAAC,IAAI,CAAC,GAAG;QAClB,SAAS,WAAA;QACT,MAAM,QAAA;KACP,CAAA;IAED,EAAE,CAAC,QAAQ,CAAC;QACV,IAAI,MAAA;QACJ,IAAI,EAAE,cAAc,IAAI,kBAAW;QACnC,KAAK,EAAE,eAAe,IAAI,oBAAY;KACvC,CAAC,CAAA;AACJ,CAAC;AAtBD,4BAsBC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BaseNodeModel, GraphModel } from '@logicflow/core';
|
|
2
|
+
export declare function connect(id: string, component: any, container: HTMLDivElement, node: BaseNodeModel, graph: GraphModel): void;
|
|
3
|
+
export declare function disconnect(id: string): void;
|
|
4
|
+
export declare function isActive(): boolean;
|
|
5
|
+
export declare function getTeleport(): any;
|
package/lib/teleport.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTeleport = exports.isActive = exports.disconnect = exports.connect = void 0;
|
|
4
|
+
var vue_demi_1 = require("vue-demi");
|
|
5
|
+
var active = false;
|
|
6
|
+
var items = (0, vue_demi_1.reactive)({});
|
|
7
|
+
function connect(id, component, container, node, graph) {
|
|
8
|
+
if (active) {
|
|
9
|
+
items[id] = (0, vue_demi_1.markRaw)((0, vue_demi_1.defineComponent)({
|
|
10
|
+
render: function () {
|
|
11
|
+
return (0, vue_demi_1.h)(vue_demi_1.Teleport, { to: container }, [
|
|
12
|
+
(0, vue_demi_1.h)(component, { node: node, graph: graph }),
|
|
13
|
+
]);
|
|
14
|
+
},
|
|
15
|
+
provide: function () { return ({
|
|
16
|
+
getNode: function () { return node; },
|
|
17
|
+
getGraph: function () { return graph; },
|
|
18
|
+
}); },
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.connect = connect;
|
|
23
|
+
function disconnect(id) {
|
|
24
|
+
if (active) {
|
|
25
|
+
delete items[id];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.disconnect = disconnect;
|
|
29
|
+
function isActive() {
|
|
30
|
+
return active;
|
|
31
|
+
}
|
|
32
|
+
exports.isActive = isActive;
|
|
33
|
+
function getTeleport() {
|
|
34
|
+
if (!vue_demi_1.isVue3) {
|
|
35
|
+
throw new Error('teleport is only available in Vue3');
|
|
36
|
+
}
|
|
37
|
+
active = true;
|
|
38
|
+
return (0, vue_demi_1.defineComponent)({
|
|
39
|
+
setup: function () {
|
|
40
|
+
return function () {
|
|
41
|
+
return (0, vue_demi_1.h)(vue_demi_1.Fragment, {}, Object.keys(items).map(function (id) { return (0, vue_demi_1.h)(items[id]); }));
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.getTeleport = getTeleport;
|
|
47
|
+
//# sourceMappingURL=teleport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teleport.js","sourceRoot":"","sources":["../src/teleport.ts"],"names":[],"mappings":";;;AACA,qCAQiB;AAEjB,IAAI,MAAM,GAAG,KAAK,CAAA;AAClB,IAAM,KAAK,GAAG,IAAA,mBAAQ,EAAyB,EAAE,CAAC,CAAA;AAElD,SAAgB,OAAO,CACrB,EAAU,EACV,SAAc,EACd,SAAyB,EACzB,IA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C"}
|
package/lib/view.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HtmlNode } from '@logicflow/core';
|
|
2
|
+
export declare class VueNodeView extends HtmlNode {
|
|
3
|
+
root?: any;
|
|
4
|
+
private vm;
|
|
5
|
+
getComponentContainer(): any;
|
|
6
|
+
protected targetId(): string;
|
|
7
|
+
componentWillUnmount(): void;
|
|
8
|
+
setHtml(rootEl: SVGForeignObjectElement): void;
|
|
9
|
+
confirmUpdate(_rootEl: SVGForeignObjectElement): void;
|
|
10
|
+
protected renderVueComponent(): void;
|
|
11
|
+
protected unmountVueComponent(): any;
|
|
12
|
+
unmount(): void;
|
|
13
|
+
}
|
|
14
|
+
export default VueNodeView;
|
package/lib/view.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.VueNodeView = void 0;
|
|
19
|
+
var vue_demi_1 = require("vue-demi");
|
|
20
|
+
var core_1 = require("@logicflow/core");
|
|
21
|
+
var registry_1 = require("./registry");
|
|
22
|
+
var teleport_1 = require("./teleport");
|
|
23
|
+
var VueNodeView = /** @class */ (function (_super) {
|
|
24
|
+
__extends(VueNodeView, _super);
|
|
25
|
+
function VueNodeView() {
|
|
26
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
}
|
|
28
|
+
VueNodeView.prototype.getComponentContainer = function () {
|
|
29
|
+
return this.root;
|
|
30
|
+
};
|
|
31
|
+
VueNodeView.prototype.targetId = function () {
|
|
32
|
+
return "".concat(this.props.graphModel.flowId, ":").concat(this.props.model.id);
|
|
33
|
+
};
|
|
34
|
+
VueNodeView.prototype.componentWillUnmount = function () {
|
|
35
|
+
_super.prototype.componentWillUnmount.call(this);
|
|
36
|
+
this.unmount();
|
|
37
|
+
};
|
|
38
|
+
VueNodeView.prototype.setHtml = function (rootEl) {
|
|
39
|
+
var el = document.createElement('div');
|
|
40
|
+
el.className = 'custom-react-node-content';
|
|
41
|
+
this.root = el;
|
|
42
|
+
this.renderVueComponent();
|
|
43
|
+
rootEl.appendChild(el);
|
|
44
|
+
};
|
|
45
|
+
VueNodeView.prototype.confirmUpdate = function (_rootEl) {
|
|
46
|
+
// TODO: 如有需要,可以先通过继承的方式,自定义该节点的更新逻辑;我们后续会根据实际需求,丰富该功能
|
|
47
|
+
console.log('_rootEl', _rootEl);
|
|
48
|
+
};
|
|
49
|
+
VueNodeView.prototype.renderVueComponent = function () {
|
|
50
|
+
var _a;
|
|
51
|
+
this.unmountVueComponent();
|
|
52
|
+
var root = this.getComponentContainer();
|
|
53
|
+
var _b = this.props, model = _b.model, graphModel = _b.graphModel;
|
|
54
|
+
if (root) {
|
|
55
|
+
var component_1 = registry_1.vueNodesMap[model.type].component;
|
|
56
|
+
if (component_1) {
|
|
57
|
+
if (vue_demi_1.isVue2) {
|
|
58
|
+
var Vue = vue_demi_1.Vue2;
|
|
59
|
+
this.vm = new Vue({
|
|
60
|
+
el: root,
|
|
61
|
+
render: function (h) {
|
|
62
|
+
return h(component_1, {
|
|
63
|
+
node: model,
|
|
64
|
+
graph: graphModel,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
provide: function () {
|
|
68
|
+
return {
|
|
69
|
+
getNode: function () { return model; },
|
|
70
|
+
getGraph: function () { return graphModel; },
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else if (vue_demi_1.isVue3) {
|
|
76
|
+
if ((0, teleport_1.isActive)()) {
|
|
77
|
+
(0, teleport_1.connect)(this.targetId(), component_1, root, model, graphModel);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.vm = (0, vue_demi_1.createApp)({
|
|
81
|
+
render: function () {
|
|
82
|
+
return (0, vue_demi_1.h)(component_1, {
|
|
83
|
+
node: model,
|
|
84
|
+
graph: graphModel,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
provide: function () {
|
|
88
|
+
return {
|
|
89
|
+
getNode: function () { return model; },
|
|
90
|
+
getGraph: function () { return graphModel; },
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
(_a = this.vm) === null || _a === void 0 ? void 0 : _a.mount(root);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
VueNodeView.prototype.unmountVueComponent = function () {
|
|
101
|
+
var root = this.getComponentContainer();
|
|
102
|
+
if (this.vm) {
|
|
103
|
+
vue_demi_1.isVue2 && this.vm.$destroy();
|
|
104
|
+
vue_demi_1.isVue3 && this.vm.$destroy();
|
|
105
|
+
this.vm = null;
|
|
106
|
+
}
|
|
107
|
+
if (root) {
|
|
108
|
+
root.innerHTML = '';
|
|
109
|
+
}
|
|
110
|
+
return root;
|
|
111
|
+
};
|
|
112
|
+
VueNodeView.prototype.unmount = function () {
|
|
113
|
+
this.unmountVueComponent();
|
|
114
|
+
};
|
|
115
|
+
return VueNodeView;
|
|
116
|
+
}(core_1.HtmlNode));
|
|
117
|
+
exports.VueNodeView = VueNodeView;
|
|
118
|
+
exports.default = VueNodeView;
|
|
119
|
+
//# sourceMappingURL=view.js.map
|
package/lib/view.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,qCAA6D;AAC7D,wCAA0C;AAC1C,uCAAwC;AACxC,uCAA8C;AAE9C;IAAiC,+BAAQ;IAAzC;;IAiGA,CAAC;IA7FC,2CAAqB,GAArB;QACE,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAES,8BAAQ,GAAlB;QACE,OAAO,UAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,cAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAE,CAAA;IACjE,CAAC;IAED,0CAAoB,GAApB;QACE,gBAAK,CAAC,oBAAoB,WAAE,CAAA;QAC5B,IAAI,CAAC,OAAO,EAAE,CAAA;IAChB,CAAC;IAED,6BAAO,GAAP,UAAQ,MAA+B;QACrC,IAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QACxC,EAAE,CAAC,SAAS,GAAG,2BAA2B,CAAA;QAC1C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QAEd,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC;IAED,mCAAa,GAAb,UAAc,OAAgC;QAC5C,sDAAsD;QACtD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC;IAES,wCAAkB,GAA5B;;QACE,IAAI,CAAC,mBAAmB,EAAE,CAAA;QAC1B,IAAM,IAAI,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAA;QACnC,IAAA,KAAwB,IAAI,CAAC,KAAK,EAAhC,KAAK,WAAA,EAAE,UAAU,gBAAe,CAAA;QAExC,IAA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ACtB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAES,yCAAmB,GAA7B;QACE,IAAM,IAAI,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAA;QACzC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,iBAAM,IAAI,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAA;YAC5B,iBAAM,IAAI,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAA;YAC5B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAA;QAChB,CAAC;QACD,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QACrB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,6BAAO,GAAP;QACE,IAAI,CAAC,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IACH,kBAAC;AAAD,CAAC,AAjGD,CAAiC,eAAQ,GAiGxC;AAjGY,kCAAW;AAmGxB,kBAAe,WAAW,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@logicflow/vue-node-registry",
|
|
3
|
+
"version": "0.0.1-beta.0",
|
|
4
|
+
"description": "LogicFlow Vue Component Node Registry",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
|
+
"unpkg": "dist/index.js",
|
|
8
|
+
"jsdeliver": "dist/index.js",
|
|
9
|
+
"types": "lib/index.d.ts",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"@logicflow/vue-node-registry",
|
|
12
|
+
"LogicFlow",
|
|
13
|
+
"Vue",
|
|
14
|
+
"Node"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"vue-demi": "latest"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@vue/composition-api": "^1.0.0-rc.1",
|
|
21
|
+
"vue": "^2.0.0 || >=3.0.0",
|
|
22
|
+
"@logicflow/core": "2.0.0-beta.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependenciesMeta": {
|
|
25
|
+
"@vue/composition-api": {
|
|
26
|
+
"optional": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"vue": "^3.0.0",
|
|
31
|
+
"@logicflow/core": "2.0.0-beta.0"
|
|
32
|
+
},
|
|
33
|
+
"author": {
|
|
34
|
+
"name": "boyongjiong",
|
|
35
|
+
"email": "boyongjiong@gmail.com"
|
|
36
|
+
},
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean:turbo": "rss",
|
|
40
|
+
"clean:build": "rss",
|
|
41
|
+
"clean": "rss",
|
|
42
|
+
"build:less": "rss",
|
|
43
|
+
"build:esm": "tsc --module esnext --target es5 --outDir ./es",
|
|
44
|
+
"build:cjs": "tsc --module commonjs --target es5 --outDir ./lib",
|
|
45
|
+
"build:umd": "rss",
|
|
46
|
+
"build:dev": "rss",
|
|
47
|
+
"build:watch": "rss",
|
|
48
|
+
"build:watch:esm": "rss",
|
|
49
|
+
"build:watch:cjs": "rss",
|
|
50
|
+
"build": "rss",
|
|
51
|
+
"prebuild": "rss",
|
|
52
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.ts
ADDED
package/src/model.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import LogicFlow, { HtmlNodeModel } from '@logicflow/core'
|
|
2
|
+
import { cloneDeep } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
export type CustomProperties = {
|
|
5
|
+
// 形状属性
|
|
6
|
+
width?: number
|
|
7
|
+
height?: number
|
|
8
|
+
radius?: number
|
|
9
|
+
|
|
10
|
+
// 文字位置属性
|
|
11
|
+
refX?: number
|
|
12
|
+
refY?: number
|
|
13
|
+
|
|
14
|
+
// 样式属性
|
|
15
|
+
style?: LogicFlow.CommonTheme
|
|
16
|
+
textStyle?: LogicFlow.TextNodeTheme
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class VueNodeModel extends HtmlNodeModel {
|
|
20
|
+
setAttributes() {
|
|
21
|
+
console.log('this.properties', this.properties)
|
|
22
|
+
const { width, height, radius } = this.properties as CustomProperties
|
|
23
|
+
if (width) {
|
|
24
|
+
this.width = width
|
|
25
|
+
}
|
|
26
|
+
if (height) {
|
|
27
|
+
this.height = height
|
|
28
|
+
}
|
|
29
|
+
if (radius) {
|
|
30
|
+
this.radius = radius
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getTextStyle(): LogicFlow.TextNodeTheme {
|
|
35
|
+
// const { x, y, width, height } = this
|
|
36
|
+
const {
|
|
37
|
+
refX = 0,
|
|
38
|
+
refY = 0,
|
|
39
|
+
textStyle,
|
|
40
|
+
} = this.properties as CustomProperties
|
|
41
|
+
const style = super.getTextStyle()
|
|
42
|
+
|
|
43
|
+
// 通过 transform 重新设置 text 的位置
|
|
44
|
+
return {
|
|
45
|
+
...style,
|
|
46
|
+
...(cloneDeep(textStyle) || {}),
|
|
47
|
+
transform: `matrix(1 0 0 1 ${refX} ${refY})`,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getNodeStyle(): LogicFlow.CommonTheme {
|
|
52
|
+
const style = super.getNodeStyle()
|
|
53
|
+
const {
|
|
54
|
+
style: customNodeStyle,
|
|
55
|
+
// radius = 0, // 第二种方式,设置圆角
|
|
56
|
+
} = this.properties as CustomProperties
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...style,
|
|
60
|
+
...(cloneDeep(customNodeStyle) || {}),
|
|
61
|
+
// rx: radius,
|
|
62
|
+
// ry: radius,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default VueNodeModel
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import LogicFlow from '@logicflow/core'
|
|
2
|
+
import { VueNodeView } from './view'
|
|
3
|
+
import { VueNodeModel } from './model'
|
|
4
|
+
|
|
5
|
+
import RegisterConfig = LogicFlow.RegisterConfig
|
|
6
|
+
|
|
7
|
+
export type VueNodeConfig = {
|
|
8
|
+
type: string
|
|
9
|
+
component: any
|
|
10
|
+
effect?: (keyof LogicFlow.PropertiesType)[]
|
|
11
|
+
} & Partial<RegisterConfig>
|
|
12
|
+
|
|
13
|
+
export const vueNodesMap: Record<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
component: any
|
|
17
|
+
effect?: (keyof LogicFlow.PropertiesType)[]
|
|
18
|
+
}
|
|
19
|
+
> = {}
|
|
20
|
+
|
|
21
|
+
export function register(config: VueNodeConfig, lf: LogicFlow) {
|
|
22
|
+
const {
|
|
23
|
+
type,
|
|
24
|
+
component,
|
|
25
|
+
effect,
|
|
26
|
+
view: CustomNodeView,
|
|
27
|
+
model: CustomNodeModel,
|
|
28
|
+
} = config
|
|
29
|
+
|
|
30
|
+
if (!type) {
|
|
31
|
+
throw new Error('You should specify type in config')
|
|
32
|
+
}
|
|
33
|
+
vueNodesMap[type] = {
|
|
34
|
+
component,
|
|
35
|
+
effect,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
lf.register({
|
|
39
|
+
type,
|
|
40
|
+
view: CustomNodeView || VueNodeView,
|
|
41
|
+
model: CustomNodeModel || VueNodeModel,
|
|
42
|
+
})
|
|
43
|
+
}
|
package/src/teleport.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BaseNodeModel, GraphModel } from '@logicflow/core'
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
reactive,
|
|
6
|
+
isVue3,
|
|
7
|
+
Teleport,
|
|
8
|
+
markRaw,
|
|
9
|
+
Fragment,
|
|
10
|
+
} from 'vue-demi'
|
|
11
|
+
|
|
12
|
+
let active = false
|
|
13
|
+
const items = reactive<{ [key: string]: any }>({})
|
|
14
|
+
|
|
15
|
+
export function connect(
|
|
16
|
+
id: string,
|
|
17
|
+
component: any,
|
|
18
|
+
container: HTMLDivElement,
|
|
19
|
+
node: BaseNodeModel,
|
|
20
|
+
graph: GraphModel,
|
|
21
|
+
) {
|
|
22
|
+
if (active) {
|
|
23
|
+
items[id] = markRaw(
|
|
24
|
+
defineComponent({
|
|
25
|
+
render: () =>
|
|
26
|
+
h(Teleport, { to: container } as any, [
|
|
27
|
+
h(component, { node, graph }),
|
|
28
|
+
]),
|
|
29
|
+
provide: () => ({
|
|
30
|
+
getNode: () => node,
|
|
31
|
+
getGraph: () => graph,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function disconnect(id: string) {
|
|
39
|
+
if (active) {
|
|
40
|
+
delete items[id]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isActive() {
|
|
45
|
+
return active
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getTeleport(): any {
|
|
49
|
+
if (!isVue3) {
|
|
50
|
+
throw new Error('teleport is only available in Vue3')
|
|
51
|
+
}
|
|
52
|
+
active = true
|
|
53
|
+
|
|
54
|
+
return defineComponent({
|
|
55
|
+
setup() {
|
|
56
|
+
return () =>
|
|
57
|
+
h(
|
|
58
|
+
Fragment,
|
|
59
|
+
{},
|
|
60
|
+
Object.keys(items).map((id) => h(items[id])),
|
|
61
|
+
)
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
}
|
package/src/view.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isVue2, isVue3, createApp, h, Vue2 } from 'vue-demi'
|
|
2
|
+
import { HtmlNode } from '@logicflow/core'
|
|
3
|
+
import { vueNodesMap } from './registry'
|
|
4
|
+
import { isActive, connect } from './teleport'
|
|
5
|
+
|
|
6
|
+
export class VueNodeView extends HtmlNode {
|
|
7
|
+
root?: any
|
|
8
|
+
private vm: any
|
|
9
|
+
|
|
10
|
+
getComponentContainer() {
|
|
11
|
+
return this.root
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected targetId() {
|
|
15
|
+
return `${this.props.graphModel.flowId}:${this.props.model.id}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
componentWillUnmount() {
|
|
19
|
+
super.componentWillUnmount()
|
|
20
|
+
this.unmount()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setHtml(rootEl: SVGForeignObjectElement) {
|
|
24
|
+
const el = document.createElement('div')
|
|
25
|
+
el.className = 'custom-react-node-content'
|
|
26
|
+
this.root = el
|
|
27
|
+
|
|
28
|
+
this.renderVueComponent()
|
|
29
|
+
rootEl.appendChild(el)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
confirmUpdate(_rootEl: SVGForeignObjectElement) {
|
|
33
|
+
// TODO: 如有需要,可以先通过继承的方式,自定义该节点的更新逻辑;我们后续会根据实际需求,丰富该功能
|
|
34
|
+
console.log('_rootEl', _rootEl)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected renderVueComponent() {
|
|
38
|
+
this.unmountVueComponent()
|
|
39
|
+
const root = this.getComponentContainer()
|
|
40
|
+
const { model, graphModel } = this.props
|
|
41
|
+
|
|
42
|
+
if (root) {
|
|
43
|
+
const { component } = vueNodesMap[model.type]
|
|
44
|
+
if (component) {
|
|
45
|
+
if (isVue2) {
|
|
46
|
+
const Vue = Vue2 as any
|
|
47
|
+
this.vm = new Vue({
|
|
48
|
+
el: root,
|
|
49
|
+
render(h: any) {
|
|
50
|
+
return h(component, {
|
|
51
|
+
node: model,
|
|
52
|
+
graph: graphModel,
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
provide() {
|
|
56
|
+
return {
|
|
57
|
+
getNode: () => model,
|
|
58
|
+
getGraph: () => graphModel,
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
} else if (isVue3) {
|
|
63
|
+
if (isActive()) {
|
|
64
|
+
connect(this.targetId(), component, root, model, graphModel)
|
|
65
|
+
} else {
|
|
66
|
+
this.vm = createApp({
|
|
67
|
+
render() {
|
|
68
|
+
return h(component, {
|
|
69
|
+
node: model,
|
|
70
|
+
graph: graphModel,
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
provide() {
|
|
74
|
+
return {
|
|
75
|
+
getNode: () => model,
|
|
76
|
+
getGraph: () => graphModel,
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
this.vm?.mount(root)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected unmountVueComponent() {
|
|
88
|
+
const root = this.getComponentContainer()
|
|
89
|
+
if (this.vm) {
|
|
90
|
+
isVue2 && this.vm.$destroy()
|
|
91
|
+
isVue3 && this.vm.$destroy()
|
|
92
|
+
this.vm = null
|
|
93
|
+
}
|
|
94
|
+
if (root) {
|
|
95
|
+
root.innerHTML = ''
|
|
96
|
+
}
|
|
97
|
+
return root
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
unmount() {
|
|
101
|
+
this.unmountVueComponent()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default VueNodeView
|