@flowgram.ai/free-layout-core 0.5.1 → 0.5.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/dist/esm/{chunk-O4WKIIW2.js → chunk-3UW6BHP2.js} +1 -1
- package/dist/esm/chunk-3UW6BHP2.js.map +1 -0
- package/dist/esm/index.js +111 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/typings/index.js +1 -1
- package/dist/esm/typings/workflow-operation.js +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +110 -30
- package/dist/index.js.map +1 -1
- package/dist/typings/index.d.mts +1 -1
- package/dist/typings/index.d.ts +1 -1
- package/dist/typings/index.js.map +1 -1
- package/dist/typings/workflow-drag.d.mts +1 -1
- package/dist/typings/workflow-drag.d.ts +1 -1
- package/dist/typings/workflow-json.d.mts +1 -1
- package/dist/typings/workflow-json.d.ts +1 -1
- package/dist/typings/workflow-line.d.mts +1 -1
- package/dist/typings/workflow-line.d.ts +1 -1
- package/dist/typings/workflow-node.d.mts +1 -1
- package/dist/typings/workflow-node.d.ts +1 -1
- package/dist/typings/workflow-operation.d.mts +9 -0
- package/dist/typings/workflow-operation.d.ts +9 -0
- package/dist/typings/workflow-operation.js.map +1 -1
- package/dist/typings/workflow-registry.d.mts +1 -1
- package/dist/typings/workflow-registry.d.ts +1 -1
- package/dist/typings/workflow-sub-canvas.d.mts +1 -1
- package/dist/typings/workflow-sub-canvas.d.ts +1 -1
- package/dist/{workflow-node-entity-lKu00Aj4.d.mts → workflow-node-entity-DgQT-wl9.d.mts} +16 -3
- package/dist/{workflow-node-entity-Cnte2phX.d.ts → workflow-node-entity-kGsp2Roz.d.ts} +16 -3
- package/package.json +9 -9
- package/dist/esm/chunk-O4WKIIW2.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/typings/workflow-operation.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { IPoint, Event } from '@flowgram.ai/utils';\nimport {\n FlowNodeEntity,\n FlowNodeEntityOrId,\n FlowOperationBaseService,\n} from '@flowgram.ai/document';\n\nimport { WorkflowJSON } from './workflow-json';\n\nexport interface NodePostionUpdateEvent {\n node: FlowNodeEntity;\n oldPosition: IPoint;\n newPosition: IPoint;\n}\n\nexport interface WorkflowOperationBaseService extends FlowOperationBaseService {\n /**\n * 节点位置更新事件\n */\n readonly onNodePostionUpdate: Event<NodePostionUpdateEvent>;\n /**\n * 更新节点位置\n * @param nodeOrId\n * @param position\n * @returns\n */\n updateNodePosition(nodeOrId: FlowNodeEntityOrId, position: IPoint): void;\n\n /**\n * 更新节点与线条\n */\n fromJSON(json: WorkflowJSON): void;\n}\n\nexport const WorkflowOperationBaseService = Symbol('WorkflowOperationBaseService');\n"],"mappings":";AAuCO,IAAM,+BAA+B,OAAO,8BAA8B;","names":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import "./chunk-DDJTYHXN.js";
|
|
16
16
|
import {
|
|
17
17
|
WorkflowOperationBaseService
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-3UW6BHP2.js";
|
|
19
19
|
import {
|
|
20
20
|
__decorateClass
|
|
21
21
|
} from "./chunk-EUXUH3YW.js";
|
|
@@ -2057,6 +2057,9 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2057
2057
|
this._loading = false;
|
|
2058
2058
|
this.onLoadedEmitter.fire();
|
|
2059
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* @deprecated use `ctx.operation.fromJSON` instead
|
|
2062
|
+
*/
|
|
2060
2063
|
async reload(json, delayTime = 0) {
|
|
2061
2064
|
if (this.disposed) return;
|
|
2062
2065
|
this._loading = true;
|
|
@@ -2077,7 +2080,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2077
2080
|
edges: json.edges ?? []
|
|
2078
2081
|
};
|
|
2079
2082
|
this.entityManager.changeEntityLocked = true;
|
|
2080
|
-
this.
|
|
2083
|
+
this.batchAddFromJSON(workflowJSON);
|
|
2081
2084
|
this.entityManager.changeEntityLocked = false;
|
|
2082
2085
|
this.transformer.loading = false;
|
|
2083
2086
|
if (fireRender) {
|
|
@@ -2097,9 +2100,17 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2097
2100
|
* 创建流程节点
|
|
2098
2101
|
* @param json
|
|
2099
2102
|
*/
|
|
2100
|
-
createWorkflowNode(json, isClone = false,
|
|
2103
|
+
createWorkflowNode(json, isClone = false, parentID) {
|
|
2104
|
+
return this._createWorkflowNode(json, { parentID });
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* 创建流程节点
|
|
2108
|
+
* @param json
|
|
2109
|
+
*/
|
|
2110
|
+
_createWorkflowNode(json, options) {
|
|
2111
|
+
const { parentID, onNodeCreated, onEdgeCreated } = options ?? {};
|
|
2101
2112
|
const isExistedNode = this.getNode(json.id);
|
|
2102
|
-
const parent = this.getNode(
|
|
2113
|
+
const parent = this.getNode(parentID ?? this.root.id) ?? this.root;
|
|
2103
2114
|
const node = this.addNode(
|
|
2104
2115
|
{
|
|
2105
2116
|
...json,
|
|
@@ -2126,15 +2137,19 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2126
2137
|
node.getData(TransformData7).update({
|
|
2127
2138
|
position
|
|
2128
2139
|
});
|
|
2129
|
-
if (formMeta && formData
|
|
2130
|
-
formData.
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2140
|
+
if (formMeta && formData) {
|
|
2141
|
+
if (!formData.formModel.initialized) {
|
|
2142
|
+
formData.createForm(formMeta, json.data);
|
|
2143
|
+
formData.onDataChange(() => {
|
|
2144
|
+
this.fireContentChange({
|
|
2145
|
+
type: "NODE_DATA_CHANGE" /* NODE_DATA_CHANGE */,
|
|
2146
|
+
toJSON: () => formData.toJSON(),
|
|
2147
|
+
entity: node
|
|
2148
|
+
});
|
|
2136
2149
|
});
|
|
2137
|
-
}
|
|
2150
|
+
} else {
|
|
2151
|
+
formData.updateFormValues(json.data);
|
|
2152
|
+
}
|
|
2138
2153
|
}
|
|
2139
2154
|
const positionData = node.getData(PositionData);
|
|
2140
2155
|
if (!isExistedNode) {
|
|
@@ -2173,11 +2188,12 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2173
2188
|
});
|
|
2174
2189
|
}
|
|
2175
2190
|
if (json.blocks) {
|
|
2176
|
-
this.
|
|
2191
|
+
this.batchAddFromJSON(
|
|
2177
2192
|
{ nodes: json.blocks, edges: json.edges ?? [] },
|
|
2178
2193
|
{
|
|
2179
2194
|
parent: node,
|
|
2180
|
-
|
|
2195
|
+
onNodeCreated,
|
|
2196
|
+
onEdgeCreated
|
|
2181
2197
|
}
|
|
2182
2198
|
);
|
|
2183
2199
|
}
|
|
@@ -2309,7 +2325,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2309
2325
|
throw new Error(`[WorkflowDocument.createWorkflowNodeByType] Node Id "${id}" duplicated.`);
|
|
2310
2326
|
}
|
|
2311
2327
|
}
|
|
2312
|
-
return this.
|
|
2328
|
+
return this._createWorkflowNode(
|
|
2313
2329
|
{
|
|
2314
2330
|
...json,
|
|
2315
2331
|
id,
|
|
@@ -2320,13 +2336,15 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2320
2336
|
blocks: json?.blocks,
|
|
2321
2337
|
edges: json?.edges
|
|
2322
2338
|
},
|
|
2323
|
-
|
|
2324
|
-
parentID
|
|
2339
|
+
{ parentID }
|
|
2325
2340
|
);
|
|
2326
2341
|
}
|
|
2327
2342
|
getAllNodes() {
|
|
2328
2343
|
return this.entityManager.getEntities(WorkflowNodeEntity).filter((n) => n.id !== FlowNodeBaseType2.ROOT);
|
|
2329
2344
|
}
|
|
2345
|
+
getAllEdges() {
|
|
2346
|
+
return this.entityManager.getEntities(WorkflowLineEntity);
|
|
2347
|
+
}
|
|
2330
2348
|
getAllPorts() {
|
|
2331
2349
|
return this.entityManager.getEntities(WorkflowPortEntity).filter((p) => p.node.id !== FlowNodeBaseType2.ROOT);
|
|
2332
2350
|
}
|
|
@@ -2427,7 +2445,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2427
2445
|
x: json.meta.position.x + 30,
|
|
2428
2446
|
y: json.meta.position.y + 30
|
|
2429
2447
|
};
|
|
2430
|
-
return this.
|
|
2448
|
+
return this._createWorkflowNode(
|
|
2431
2449
|
{
|
|
2432
2450
|
id: newNodeId || `1${nanoid2()}`,
|
|
2433
2451
|
type: node.flowNodeType,
|
|
@@ -2439,16 +2457,17 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2439
2457
|
blocks: json.blocks,
|
|
2440
2458
|
edges: json.edges
|
|
2441
2459
|
},
|
|
2442
|
-
|
|
2443
|
-
|
|
2460
|
+
{
|
|
2461
|
+
parentID: node.parent?.id
|
|
2462
|
+
}
|
|
2444
2463
|
);
|
|
2445
2464
|
}
|
|
2446
|
-
copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position,
|
|
2465
|
+
copyNodeFromJSON(flowNodeType, nodeJSON, newNodeId, position, parentID) {
|
|
2447
2466
|
position = position || {
|
|
2448
2467
|
x: nodeJSON.meta.position.x + 30,
|
|
2449
2468
|
y: nodeJSON.meta.position.y + 30
|
|
2450
2469
|
};
|
|
2451
|
-
return this.
|
|
2470
|
+
return this._createWorkflowNode(
|
|
2452
2471
|
{
|
|
2453
2472
|
id: newNodeId || `1${nanoid2()}`,
|
|
2454
2473
|
type: flowNodeType,
|
|
@@ -2460,8 +2479,9 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2460
2479
|
blocks: nodeJSON.blocks,
|
|
2461
2480
|
edges: nodeJSON.edges
|
|
2462
2481
|
},
|
|
2463
|
-
|
|
2464
|
-
|
|
2482
|
+
{
|
|
2483
|
+
parentID
|
|
2484
|
+
}
|
|
2465
2485
|
);
|
|
2466
2486
|
}
|
|
2467
2487
|
canRemove(node, silent) {
|
|
@@ -2516,13 +2536,19 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2516
2536
|
* 批量添加节点
|
|
2517
2537
|
*/
|
|
2518
2538
|
batchAddFromJSON(json, options) {
|
|
2519
|
-
const { parent = this.root,
|
|
2520
|
-
const
|
|
2539
|
+
const { parent = this.root, onNodeCreated, onEdgeCreated } = options ?? {};
|
|
2540
|
+
const parentID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
|
|
2521
2541
|
const processedJSON = buildGroupJSON(json);
|
|
2522
2542
|
const nodes = processedJSON.nodes.map(
|
|
2523
|
-
(nodeJSON) => this.
|
|
2543
|
+
(nodeJSON) => this._createWorkflowNode(nodeJSON, {
|
|
2544
|
+
parentID,
|
|
2545
|
+
onNodeCreated,
|
|
2546
|
+
onEdgeCreated
|
|
2547
|
+
})
|
|
2524
2548
|
);
|
|
2525
|
-
const edges = processedJSON.edges.map((edge) => this.createWorkflowLine(edge,
|
|
2549
|
+
const edges = processedJSON.edges.map((edge) => this.createWorkflowLine(edge, parentID)).filter(Boolean);
|
|
2550
|
+
nodes.forEach((node) => options?.onNodeCreated?.(node));
|
|
2551
|
+
edges.forEach((edge) => options?.onEdgeCreated?.(edge));
|
|
2526
2552
|
return { nodes, edges };
|
|
2527
2553
|
}
|
|
2528
2554
|
getNodeSubCanvas(node) {
|
|
@@ -2571,7 +2597,7 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2571
2597
|
}
|
|
2572
2598
|
return lineJSON;
|
|
2573
2599
|
}
|
|
2574
|
-
createWorkflowLine(json,
|
|
2600
|
+
createWorkflowLine(json, parentID) {
|
|
2575
2601
|
const fromNode = this.getNode(json.sourceNodeID);
|
|
2576
2602
|
const toNode = this.getNode(json.targetNodeID);
|
|
2577
2603
|
if (!fromNode || !toNode) {
|
|
@@ -2584,10 +2610,10 @@ var WorkflowDocument = class extends FlowDocument {
|
|
|
2584
2610
|
toPort: json.targetPortID,
|
|
2585
2611
|
data: json.data
|
|
2586
2612
|
};
|
|
2587
|
-
if (!
|
|
2613
|
+
if (!parentID) {
|
|
2588
2614
|
return this.linesManager.createLine(lineInfo);
|
|
2589
2615
|
}
|
|
2590
|
-
const canvasNode = this.getNode(
|
|
2616
|
+
const canvasNode = this.getNode(parentID);
|
|
2591
2617
|
if (!canvasNode) {
|
|
2592
2618
|
return this.linesManager.createLine(lineInfo);
|
|
2593
2619
|
}
|
|
@@ -3532,10 +3558,64 @@ var WorkflowOperationBaseServiceImpl = class extends FlowOperationBaseServiceImp
|
|
|
3532
3558
|
newPosition: position
|
|
3533
3559
|
});
|
|
3534
3560
|
}
|
|
3561
|
+
fromJSON(json) {
|
|
3562
|
+
if (this.document.disposed) return;
|
|
3563
|
+
const workflowJSON = {
|
|
3564
|
+
nodes: json.nodes ?? [],
|
|
3565
|
+
edges: json.edges ?? []
|
|
3566
|
+
};
|
|
3567
|
+
const oldNodes = this.document.getAllNodes();
|
|
3568
|
+
const oldEdges = this.linesManager.getAllLines();
|
|
3569
|
+
const oldPositionMap = new Map(
|
|
3570
|
+
oldNodes.map((node) => [
|
|
3571
|
+
node.id,
|
|
3572
|
+
{
|
|
3573
|
+
x: node.transform.transform.position.x,
|
|
3574
|
+
y: node.transform.transform.position.y
|
|
3575
|
+
}
|
|
3576
|
+
])
|
|
3577
|
+
);
|
|
3578
|
+
const newNodes = [];
|
|
3579
|
+
const newEdges = [];
|
|
3580
|
+
this.document.batchAddFromJSON(workflowJSON, {
|
|
3581
|
+
onNodeCreated: (node) => newNodes.push(node),
|
|
3582
|
+
onEdgeCreated: (edge) => newEdges.push(edge)
|
|
3583
|
+
});
|
|
3584
|
+
const newEdgeIDSet = new Set(newEdges.map((edge) => edge.id));
|
|
3585
|
+
oldEdges.forEach((edge) => {
|
|
3586
|
+
if (!newEdgeIDSet.has(edge.id)) {
|
|
3587
|
+
edge.dispose();
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
});
|
|
3591
|
+
const newNodeIDSet = new Set(newNodes.map((node) => node.id));
|
|
3592
|
+
oldNodes.forEach((node) => {
|
|
3593
|
+
if (!newNodeIDSet.has(node.id)) {
|
|
3594
|
+
node.dispose();
|
|
3595
|
+
return;
|
|
3596
|
+
}
|
|
3597
|
+
const oldPosition = oldPositionMap.get(node.id);
|
|
3598
|
+
const newPosition = {
|
|
3599
|
+
x: node.transform.transform.position.x,
|
|
3600
|
+
y: node.transform.transform.position.y
|
|
3601
|
+
};
|
|
3602
|
+
if (oldPosition && (oldPosition.x !== newPosition.x || oldPosition.y !== newPosition.y)) {
|
|
3603
|
+
this.onNodePostionUpdateEmitter.fire({
|
|
3604
|
+
node,
|
|
3605
|
+
oldPosition,
|
|
3606
|
+
newPosition
|
|
3607
|
+
});
|
|
3608
|
+
}
|
|
3609
|
+
});
|
|
3610
|
+
this.document.fireRender();
|
|
3611
|
+
}
|
|
3535
3612
|
};
|
|
3536
3613
|
__decorateClass([
|
|
3537
3614
|
inject8(WorkflowDocument)
|
|
3538
3615
|
], WorkflowOperationBaseServiceImpl.prototype, "document", 2);
|
|
3616
|
+
__decorateClass([
|
|
3617
|
+
inject8(WorkflowLinesManager)
|
|
3618
|
+
], WorkflowOperationBaseServiceImpl.prototype, "linesManager", 2);
|
|
3539
3619
|
|
|
3540
3620
|
// src/hooks/use-playground-readonly-state.ts
|
|
3541
3621
|
import { useEffect } from "react";
|