@flowgram.ai/free-layout-core 0.1.0-alpha.14 → 0.1.0-alpha.16
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/dist/esm/index.js +95 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +48 -184
- package/dist/index.d.ts +48 -184
- package/dist/index.js +97 -24
- package/dist/index.js.map +1 -1
- package/dist/typings/index.d.mts +4 -5
- package/dist/typings/index.d.ts +4 -5
- package/dist/typings/workflow-drag.d.mts +1 -2
- package/dist/typings/workflow-drag.d.ts +1 -2
- package/dist/typings/workflow-json.d.mts +3 -4
- package/dist/typings/workflow-json.d.ts +3 -4
- package/dist/typings/workflow-line.d.mts +3 -4
- package/dist/typings/workflow-line.d.ts +3 -4
- package/dist/typings/workflow-node.d.mts +2 -3
- package/dist/typings/workflow-node.d.ts +2 -3
- package/dist/typings/workflow-registry.d.mts +3 -4
- package/dist/typings/workflow-registry.d.ts +3 -4
- package/dist/typings/workflow-sub-canvas.d.mts +6 -1
- package/dist/typings/workflow-sub-canvas.d.ts +6 -1
- package/dist/{workflow-line-entity-Dn8glLaW.d.mts → workflow-node-entity-DtPEYn6-.d.mts} +380 -213
- package/dist/{workflow-line-entity-BmPrinpL.d.ts → workflow-node-entity-GyY_PHY6.d.ts} +380 -213
- package/package.json +12 -12
- package/dist/workflow-sub-canvas-IQzlYvPD.d.mts +0 -25
- package/dist/workflow-sub-canvas-IQzlYvPD.d.ts +0 -25
package/dist/esm/index.js
CHANGED
|
@@ -43,8 +43,7 @@ import {
|
|
|
43
43
|
useEntities,
|
|
44
44
|
useEntityFromContext as useEntityFromContext3,
|
|
45
45
|
useEntityDataFromContext,
|
|
46
|
-
useRefresh as useRefresh2
|
|
47
|
-
usePlaygroundLatest
|
|
46
|
+
useRefresh as useRefresh2
|
|
48
47
|
} from "@flowgram.ai/core";
|
|
49
48
|
|
|
50
49
|
// src/hooks/use-node-render.tsx
|
|
@@ -455,6 +454,7 @@ var WorkflowNodePortsData = class extends EntityData {
|
|
|
455
454
|
...Array.from(elements).map((element) => ({
|
|
456
455
|
portID: element.getAttribute("data-port-id"),
|
|
457
456
|
type: element.getAttribute("data-port-type"),
|
|
457
|
+
location: element.getAttribute("data-port-location"),
|
|
458
458
|
targetElement: element
|
|
459
459
|
}))
|
|
460
460
|
);
|
|
@@ -776,11 +776,11 @@ var WorkflowLineRenderData = class extends EntityData3 {
|
|
|
776
776
|
* WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
|
|
777
777
|
*/
|
|
778
778
|
updatePosition() {
|
|
779
|
-
this.data.position.from = this.entity.from.
|
|
779
|
+
this.data.position.from = this.entity.from.ports.getOutputPoint(this.entity.info.fromPort);
|
|
780
780
|
if (this.entity.info.drawingTo) {
|
|
781
781
|
this.data.position.to = this.entity.info.drawingTo;
|
|
782
782
|
} else {
|
|
783
|
-
this.data.position.to = this.entity.to?.
|
|
783
|
+
this.data.position.to = this.entity.to?.ports?.getInputPoint(this.entity.info.toPort) ?? {
|
|
784
784
|
x: this.data.position.from.x,
|
|
785
785
|
y: this.data.position.from.y,
|
|
786
786
|
location: this.data.position.from.location === "right" ? "left" : "top"
|
|
@@ -1042,13 +1042,13 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1042
1042
|
return this.getData(WorkflowLineRenderData).calcDistance(pos);
|
|
1043
1043
|
}
|
|
1044
1044
|
get fromPort() {
|
|
1045
|
-
return this.from.
|
|
1045
|
+
return this.from.ports.getPortEntityByKey("output", this.info.fromPort);
|
|
1046
1046
|
}
|
|
1047
1047
|
get toPort() {
|
|
1048
1048
|
if (!this.to) {
|
|
1049
1049
|
return void 0;
|
|
1050
1050
|
}
|
|
1051
|
-
return this.to.
|
|
1051
|
+
return this.to.ports.getPortEntityByKey("input", this.info.toPort);
|
|
1052
1052
|
}
|
|
1053
1053
|
/**
|
|
1054
1054
|
* 获取线条真实的输入输出节点坐标
|
|
@@ -1078,7 +1078,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
|
|
|
1078
1078
|
get disabled() {
|
|
1079
1079
|
return this.linesManager.isDisabledLine(this, this.uiState.disabled);
|
|
1080
1080
|
}
|
|
1081
|
-
/**
|
|
1081
|
+
/**
|
|
1082
|
+
* @deprecated
|
|
1083
|
+
*/
|
|
1082
1084
|
get vertical() {
|
|
1083
1085
|
const fromLocation = this.fromPort.location;
|
|
1084
1086
|
const toLocation = this.toPort?.location;
|
|
@@ -1724,7 +1726,7 @@ var WorkflowLinesManager = class {
|
|
|
1724
1726
|
*/
|
|
1725
1727
|
getPortFromMousePos(pos) {
|
|
1726
1728
|
const allNodes = this.getSortedNodes().reverse();
|
|
1727
|
-
const allPorts = allNodes.map((node) => node.
|
|
1729
|
+
const allPorts = allNodes.map((node) => node.ports.allPorts).flat();
|
|
1728
1730
|
const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
|
|
1729
1731
|
if (targetPort) {
|
|
1730
1732
|
const containNodes = this.getContainNodesFromMousePos(pos);
|
|
@@ -2179,8 +2181,11 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2179
2181
|
originParent,
|
|
2180
2182
|
meta
|
|
2181
2183
|
});
|
|
2184
|
+
this.options.preNodeCreate?.(node);
|
|
2182
2185
|
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
2183
2186
|
node.addInitializeData(datas);
|
|
2187
|
+
node.ports = node.getData(WorkflowNodePortsData);
|
|
2188
|
+
node.lines = node.getData(WorkflowNodeLinesData);
|
|
2184
2189
|
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
2185
2190
|
this.options.fromNodeJSON?.(node, data, true);
|
|
2186
2191
|
isNew = true;
|
|
@@ -2588,6 +2593,18 @@ function checkDragSuccess(time, e, originLine) {
|
|
|
2588
2593
|
}
|
|
2589
2594
|
return false;
|
|
2590
2595
|
}
|
|
2596
|
+
function reverseLocation(sourceLocation) {
|
|
2597
|
+
switch (sourceLocation) {
|
|
2598
|
+
case "bottom":
|
|
2599
|
+
return "top";
|
|
2600
|
+
case "left":
|
|
2601
|
+
return "right";
|
|
2602
|
+
case "top":
|
|
2603
|
+
return "bottom";
|
|
2604
|
+
case "right":
|
|
2605
|
+
return "left";
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2591
2608
|
var WorkflowDragService = class {
|
|
2592
2609
|
constructor() {
|
|
2593
2610
|
this._onDragLineEventEmitter = new Emitter6();
|
|
@@ -2619,10 +2636,6 @@ var WorkflowDragService = class {
|
|
|
2619
2636
|
return Promise.resolve(false);
|
|
2620
2637
|
}
|
|
2621
2638
|
this.isDragging = true;
|
|
2622
|
-
const sameParent = this.childrenOfContainer(selectedNodes);
|
|
2623
|
-
if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType3.ROOT) {
|
|
2624
|
-
selectedNodes = [sameParent];
|
|
2625
|
-
}
|
|
2626
2639
|
let startPosition = this.getNodesPosition(selectedNodes);
|
|
2627
2640
|
let startPositions = selectedNodes.map((node) => {
|
|
2628
2641
|
const transform = node.getData(TransformData8);
|
|
@@ -2684,6 +2697,7 @@ var WorkflowDragService = class {
|
|
|
2684
2697
|
triggerEvent,
|
|
2685
2698
|
dragger
|
|
2686
2699
|
});
|
|
2700
|
+
this.resetContainerInternalPosition(selectedNodes);
|
|
2687
2701
|
}
|
|
2688
2702
|
});
|
|
2689
2703
|
const { clientX, clientY } = MouseTouchEvent.getEventCoord(triggerEvent);
|
|
@@ -2724,7 +2738,7 @@ var WorkflowDragService = class {
|
|
|
2724
2738
|
const targetNode = event.currentTarget;
|
|
2725
2739
|
domNode = cloneNode ? cloneNode(e) : targetNode.cloneNode(true);
|
|
2726
2740
|
const bounds = targetNode.getBoundingClientRect();
|
|
2727
|
-
startPos = { x: bounds.left, y: bounds.top };
|
|
2741
|
+
startPos = { x: bounds.left + window.scrollX, y: bounds.top + window.scrollY };
|
|
2728
2742
|
domUtils2.setStyle(domNode, {
|
|
2729
2743
|
zIndex: 1e3,
|
|
2730
2744
|
position: "absolute",
|
|
@@ -2954,12 +2968,48 @@ var WorkflowDragService = class {
|
|
|
2954
2968
|
};
|
|
2955
2969
|
}
|
|
2956
2970
|
}
|
|
2971
|
+
/**
|
|
2972
|
+
* 容器内子节点总体位置重置为0
|
|
2973
|
+
*/
|
|
2974
|
+
resetContainerInternalPosition(nodes) {
|
|
2975
|
+
const container = this.childrenOfContainer(nodes);
|
|
2976
|
+
if (!container) {
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
const bounds = Rectangle8.enlarge(
|
|
2980
|
+
container.blocks.map((node) => {
|
|
2981
|
+
const x = node.transform.position.x - node.transform.bounds.width / 2;
|
|
2982
|
+
const y = node.transform.position.y;
|
|
2983
|
+
const width = node.transform.bounds.width;
|
|
2984
|
+
const height = node.transform.bounds.height;
|
|
2985
|
+
return new Rectangle8(x, y, width, height);
|
|
2986
|
+
})
|
|
2987
|
+
);
|
|
2988
|
+
const containerTransform = container.getData(TransformData8);
|
|
2989
|
+
containerTransform.update({
|
|
2990
|
+
position: {
|
|
2991
|
+
x: containerTransform.position.x + bounds.x,
|
|
2992
|
+
y: containerTransform.position.y + bounds.y
|
|
2993
|
+
}
|
|
2994
|
+
});
|
|
2995
|
+
this.document.layout.updateAffectedTransform(container);
|
|
2996
|
+
container.blocks.forEach((node) => {
|
|
2997
|
+
const transform = node.getData(TransformData8);
|
|
2998
|
+
transform.update({
|
|
2999
|
+
position: {
|
|
3000
|
+
x: transform.position.x - bounds.x,
|
|
3001
|
+
y: transform.position.y - bounds.y
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
3004
|
+
this.document.layout.updateAffectedTransform(node);
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
2957
3007
|
childrenOfContainer(nodes) {
|
|
2958
3008
|
if (nodes.length === 0) {
|
|
2959
3009
|
return;
|
|
2960
3010
|
}
|
|
2961
3011
|
const sourceContainer = nodes[0]?.parent;
|
|
2962
|
-
if (!sourceContainer
|
|
3012
|
+
if (!sourceContainer) {
|
|
2963
3013
|
return;
|
|
2964
3014
|
}
|
|
2965
3015
|
const valid = nodes.every((node) => node?.parent === sourceContainer);
|
|
@@ -3045,7 +3095,7 @@ var WorkflowDragService = class {
|
|
|
3045
3095
|
line.drawingTo = {
|
|
3046
3096
|
x: dragPos.x,
|
|
3047
3097
|
y: dragPos.y,
|
|
3048
|
-
location: line.fromPort.location
|
|
3098
|
+
location: reverseLocation(line.fromPort.location)
|
|
3049
3099
|
};
|
|
3050
3100
|
}
|
|
3051
3101
|
originLine?.validate();
|
|
@@ -3160,7 +3210,7 @@ var WorkflowDragService = class {
|
|
|
3160
3210
|
}
|
|
3161
3211
|
/** 获取最近的 port */
|
|
3162
3212
|
getNearestPort(node, mousePos) {
|
|
3163
|
-
const portsData = node.
|
|
3213
|
+
const portsData = node.ports;
|
|
3164
3214
|
const distanceSortedPorts = portsData.inputPorts.sort((a, b) => {
|
|
3165
3215
|
const aDistance = Math.abs(mousePos.y - a.point.y);
|
|
3166
3216
|
const bDistance = Math.abs(mousePos.y - b.point.y);
|
|
@@ -3365,7 +3415,7 @@ var isFirefox = navigator?.userAgent?.includes?.("Firefox");
|
|
|
3365
3415
|
function useNodeRender(nodeFromProps) {
|
|
3366
3416
|
const node = nodeFromProps || useContext(PlaygroundEntityContext);
|
|
3367
3417
|
const renderData = node.getData(FlowNodeRenderData3);
|
|
3368
|
-
const portsData = node.
|
|
3418
|
+
const portsData = node.ports;
|
|
3369
3419
|
const readonly = usePlaygroundReadonlyState();
|
|
3370
3420
|
const dragService = useService(WorkflowDragService);
|
|
3371
3421
|
const selectionService = useService(WorkflowSelectService);
|
|
@@ -3593,11 +3643,35 @@ WorkflowDocumentContribution = __decorateClass([
|
|
|
3593
3643
|
|
|
3594
3644
|
// src/utils/get-url-params.ts
|
|
3595
3645
|
function getUrlParams() {
|
|
3596
|
-
|
|
3646
|
+
const paramsMap = /* @__PURE__ */ new Map();
|
|
3647
|
+
location.search.replace(/^\?/, "").split("&").forEach((key) => {
|
|
3648
|
+
if (!key) return;
|
|
3597
3649
|
const [k, v] = key.split("=");
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3650
|
+
if (k) {
|
|
3651
|
+
const decodedKey = decodeURIComponent(k.trim());
|
|
3652
|
+
const decodedValue = v ? decodeURIComponent(v.trim()) : "";
|
|
3653
|
+
const dangerousProps = [
|
|
3654
|
+
"__proto__",
|
|
3655
|
+
"constructor",
|
|
3656
|
+
"prototype",
|
|
3657
|
+
"__defineGetter__",
|
|
3658
|
+
"__defineSetter__",
|
|
3659
|
+
"__lookupGetter__",
|
|
3660
|
+
"__lookupSetter__",
|
|
3661
|
+
"hasOwnProperty",
|
|
3662
|
+
"isPrototypeOf",
|
|
3663
|
+
"propertyIsEnumerable",
|
|
3664
|
+
"toString",
|
|
3665
|
+
"valueOf",
|
|
3666
|
+
"toLocaleString"
|
|
3667
|
+
];
|
|
3668
|
+
if (dangerousProps.includes(decodedKey.toLowerCase())) {
|
|
3669
|
+
return;
|
|
3670
|
+
}
|
|
3671
|
+
paramsMap.set(decodedKey, decodedValue);
|
|
3672
|
+
}
|
|
3673
|
+
});
|
|
3674
|
+
return Object.fromEntries(paramsMap);
|
|
3601
3675
|
}
|
|
3602
3676
|
|
|
3603
3677
|
// src/workflow-document-container-module.ts
|
|
@@ -3672,7 +3746,6 @@ export {
|
|
|
3672
3746
|
usePlayground2 as usePlayground,
|
|
3673
3747
|
usePlaygroundContainer,
|
|
3674
3748
|
usePlaygroundContext,
|
|
3675
|
-
usePlaygroundLatest,
|
|
3676
3749
|
usePlaygroundReadonlyState,
|
|
3677
3750
|
useRefresh2 as useRefresh,
|
|
3678
3751
|
useService3 as useService,
|