Skip to content

Commit 02e48eb

Browse files
husky-dothusky-dot
andauthored
feat(core): add flowing field to LineColor interface (bytedance#370)
Co-authored-by: husky-dot <xiaozhi@xiaozhideMacBook-Pro.local>
1 parent f048f63 commit 02e48eb

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Add `flowing` field to `LineColor` interface for configuring flowing line colors
8+
- Added `flowing: string` field to `LineColor` interface
9+
- Added `LineColors.FLOWING` enum value with default color
10+
- Updated `WorkflowLinesManager.getLineColor()` to support flowing state
11+
- Updated demo configurations to include flowing color examples
12+
- Added comprehensive test coverage for flowing line functionality
13+
14+
### Features
15+
16+
- Lines can now be colored differently when in flowing state (e.g., during workflow execution)
17+
- Priority order: hidden > error > highlight > drawing > hovered > selected > flowing > default
18+
- Backward compatible with existing line color configurations
19+
20+
### Demo Updates
21+
22+
- Updated `apps/demo-free-layout` to include flowing color configuration
23+
- Added CSS variable support: `var(--g-workflow-line-color-flowing,#4d53e8)`
24+
25+
### Tests
26+
27+
- Added test cases for flowing line color functionality
28+
- Verified priority ordering with other line states
29+
- Ensured backward compatibility

apps/demo-free-layout/src/hooks/use-editor-props.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function useEditorProps(
8383
hovered: 'var(--g-workflow-line-color-hover,#37d0ff)',
8484
selected: 'var(--g-workflow-line-color-selected,#37d0ff)',
8585
error: 'var(--g-workflow-line-color-error,red)',
86+
flowing: 'var(--g-workflow-line-color-flowing,#4d53e8)',
8687
},
8788
/*
8889
* Check whether the line can be added

apps/docs/src/en/guide/advanced/free-layout/line.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function App() {
170170
hovered: '#37d0ff',
171171
selected: '#37d0ff',
172172
error: 'red',
173+
flowing: '#ff6b35', // Color for flowing lines (e.g., during workflow execution)
173174
},
174175
// ...others
175176
}
@@ -180,7 +181,6 @@ function App() {
180181
)
181182
}
182183
```
183-
184184
### 2. Limit Single Output Port to One Line
185185

186186
<img loading="lazy" style={{ width: 500, margin: '0 auto' }} className="invert-img" src="/free-layout/line-limit.gif"/>
@@ -318,3 +318,4 @@ function SomeReact() {
318318
}
319319
```
320320

321+

packages/canvas-engine/free-layout-core/__tests__/workflow-lines-manager.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
WorkflowDocumentOptions,
88
WorkflowLineRenderData,
99
WorkflowSimpleLineContribution,
10+
LineColors,
1011
} from '../src';
1112
import { createWorkflowContainer } from './mocks';
1213
describe('workflow-lines-manager', () => {
@@ -171,4 +172,68 @@ describe('workflow-lines-manager', () => {
171172
expect((e as Error).message).toBe('[setToPort] only support drawing line.');
172173
}
173174
});
175+
176+
describe('flowing line support', () => {
177+
it('should return flowing color when line is flowing', () => {
178+
const documentOptions: WorkflowDocumentOptions = {
179+
lineColor: {
180+
flowing: '#ff0000', // 自定义流动颜色
181+
},
182+
isFlowingLine: () => true,
183+
};
184+
185+
Object.assign(linesManager, { options: documentOptions });
186+
187+
const line = linesManager.createLine({
188+
from: 'start_0',
189+
to: 'end_0',
190+
});
191+
192+
expect(line).toBeDefined();
193+
expect(linesManager.isFlowingLine(line!)).toBe(true);
194+
expect(linesManager.getLineColor(line!)).toBe('#ff0000');
195+
});
196+
197+
it('should use default flowing color when no custom color provided', () => {
198+
const documentOptions: WorkflowDocumentOptions = {
199+
isFlowingLine: () => true,
200+
};
201+
202+
Object.assign(linesManager, { options: documentOptions });
203+
204+
const line = linesManager.createLine({
205+
from: 'start_0',
206+
to: 'end_0',
207+
});
208+
209+
expect(line).toBeDefined();
210+
expect(linesManager.isFlowingLine(line!)).toBe(true);
211+
expect(linesManager.getLineColor(line!)).toBe(LineColors.FLOWING);
212+
});
213+
214+
it('should prioritize selected/hovered over flowing', () => {
215+
const documentOptions: WorkflowDocumentOptions = {
216+
lineColor: {
217+
flowing: '#ff0000',
218+
selected: '#00ff00',
219+
},
220+
isFlowingLine: () => true,
221+
};
222+
223+
Object.assign(linesManager, { options: documentOptions });
224+
225+
const line = linesManager.createLine({
226+
from: 'start_0',
227+
to: 'end_0',
228+
});
229+
230+
// 模拟选中状态
231+
linesManager.selectService.select(line!);
232+
233+
expect(line).toBeDefined();
234+
expect(linesManager.isFlowingLine(line!)).toBe(true);
235+
// 选中状态应该优先于流动状态
236+
expect(linesManager.getLineColor(line!)).toBe('#00ff00');
237+
});
238+
});
174239
});

packages/canvas-engine/free-layout-core/src/typings/workflow-line.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface LineColor {
2121
hovered: string;
2222
selected: string;
2323
error: string;
24+
flowing: string;
2425
}
2526

2627
export enum LineColors {
@@ -30,6 +31,7 @@ export enum LineColors {
3031
HOVER = 'var(--g-workflow-line-color-hover,#37d0ff)',
3132
SELECTED = 'var(--g-workflow-line-color-selected,#37d0ff)',
3233
ERROR = 'var(--g-workflow-line-color-error,red)',
34+
FLOWING = 'var(--g-workflow-line-color-flowing,#4d53e8)', // 流动线条,默认使用主题色
3335
}
3436

3537
export interface WorkflowLineRenderContribution {

packages/canvas-engine/free-layout-core/src/workflow-lines-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class WorkflowLinesManager {
8686
drawing: LineColors.DRAWING,
8787
hovered: LineColors.HOVER,
8888
selected: LineColors.SELECTED,
89+
flowing: LineColors.FLOWING,
8990
};
9091
if (this.options.lineColor) {
9192
Object.assign(color, this.options.lineColor);
@@ -336,6 +337,10 @@ export class WorkflowLinesManager {
336337
if (this.selectService.isSelected(line.id)) {
337338
return this.lineColor.selected;
338339
}
340+
// 检查是否为流动线条
341+
if (this.isFlowingLine(line)) {
342+
return this.lineColor.flowing;
343+
}
339344
return this.lineColor.default;
340345
}
341346

0 commit comments

Comments
 (0)