android-midscene-automation 1.1.7 → 1.1.9

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/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
  # 更新记录
2
+ ## v1.1.9
3
+ - [Appium]修复横向流程中展开节点及内部折叠选项时连接点偏移的问题。
4
+ - [Appium]优化节点展开编辑性能,复用未变化节点的配置,仅测量发生变化的节点,减少重复渲染和整图重排。
5
+ - [Appium]配置页新增“基础配置”和“模型配置”分组,归并流程外观、回放及 AI 相关设置。
6
+
7
+ ## v1.1.8
8
+ - [Appium]流程布局新增横向显示,默认为纵向。
9
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
10
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
11
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
12
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
13
+
2
14
  ## v1.1.7
3
15
  - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
4
16
  - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
package/README.md CHANGED
@@ -1502,6 +1502,18 @@ Linux: ~/.local/share/android-midscene-automation
1502
1502
 
1503
1503
  # 项目更新记录
1504
1504
 
1505
+ ## v1.1.9
1506
+ - [Appium]修复横向流程中展开节点及内部折叠选项时连接点偏移的问题。
1507
+ - [Appium]优化节点展开编辑性能,复用未变化节点的配置,仅测量发生变化的节点,减少重复渲染和整图重排。
1508
+ - [Appium]配置页新增“基础配置”和“模型配置”分组,归并流程外观、回放及 AI 相关设置。
1509
+
1510
+ ## v1.1.8
1511
+ - [Appium]流程布局新增横向显示,默认为纵向。
1512
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
1513
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
1514
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
1515
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
1516
+
1505
1517
  ## v1.1.7
1506
1518
  - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
1507
1519
  - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "android-midscene-automation",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oooooooko/android-midscene-automation.git"
@@ -63,5 +63,17 @@ test('loads quietly, serializes rapid edits, validates colors and surfaces save
63
63
  await delay(400);
64
64
  assert.equal(auto.status.value, '已自动保存');
65
65
  assert.equal(submissions.at(-1)?.screenshotReport, true);
66
+ const savedCount = submissions.length;
67
+ form.appium.flowNodeColor = '#';
68
+ await delay(400);
69
+ assert.equal(submissions.length, savedCount, 'incomplete node colors must not be saved');
70
+ Object.assign(form.appium, { flowBackgroundColor: '#eaf2fb', flowNodeColor: '#f6faff', flowNodeBorderColor: '#a8c1df', flowLineColor: '#6385b0' });
71
+ await delay(400);
72
+ assert.equal(submissions.length, savedCount + 1, 'theme colors are saved together');
73
+ assert.equal(submissions.at(-1)?.flowNodeColor, '#f6faff');
74
+ assert.equal(submissions.at(-1)?.flowNodeBorderColor, '#a8c1df');
75
+ form.appium.flowNodeBorderColor = '#';
76
+ await delay(400);
77
+ assert.equal(submissions.length, savedCount + 1);
66
78
  } finally { scope.stop(); }
67
79
  });
@@ -42,12 +42,18 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
42
42
  const base = `http://127.0.0.1:${address.port}`;
43
43
  const post = (path: string, body: unknown) => fetch(base + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
44
44
  const initial = await (await fetch(base + '/api/config')).json() as AppConfig;
45
+ assert.equal(initial.appium.flowNodeColor, '#ffffff');
46
+ assert.equal(initial.appium.flowNodeBorderColor, '#dfe8f3');
45
47
  assert.equal(initial.appium.flowLineStyle, 'curved');
46
- const appium = { ...initial.appium, flowLineStyle: 'curved', flowLineColor: '#AbC', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
48
+ assert.equal(initial.appium.flowLayoutDirection, 'vertical');
49
+ const appium = { ...initial.appium, flowLineStyle: 'curved', flowLayoutDirection: 'horizontal', flowLineColor: '#AbC', flowNodeColor: '#dEf', flowNodeBorderColor: '#123', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
47
50
  assert.equal((await post('/api/config/appium', { appium, runtime: { androidSdkPath: 'invalid-draft' }, midscene: { model: { name: 'unsaved' } } })).status, 200);
48
51
  let stored = await (await fetch(base + '/api/config')).json() as AppConfig;
49
52
  assert.equal(stored.appium.flowLineColor, '#aabbcc');
53
+ assert.equal(stored.appium.flowNodeColor, '#ddeeff');
54
+ assert.equal(stored.appium.flowNodeBorderColor, '#112233');
50
55
  assert.equal(stored.appium.flowLineStyle, 'curved');
56
+ assert.equal(stored.appium.flowLayoutDirection, 'horizontal');
51
57
  assert.deepEqual(stored.runtime, initial.runtime);
52
58
  assert.deepEqual(stored.midscene, initial.midscene);
53
59
  const { appium: _appium, ...manual } = structuredClone(initial);
@@ -58,10 +64,17 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
58
64
  assert.equal(stored.midscene.model.name, initial.midscene.model.name, 'runtime save must not persist an untested model');
59
65
  assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineColor: 'invalid' } })).status, 400);
60
66
  assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineStyle: 'invalid' } })).status, 400);
67
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLayoutDirection: 'diagonal' } })).status, 400);
68
+ for (const key of ['flowNodeColor', 'flowNodeBorderColor']) {
69
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, [key]: 'invalid' } })).status, 400);
70
+ }
61
71
  assert.equal((await post('/api/config/appium', { appium: null })).status, 400);
62
72
  const { loadModelConfigFromDb } = await import('./config-store');
63
73
  assert.equal(loadModelConfigFromDb()?.appium?.flowLineColor, '#aabbcc');
74
+ assert.equal(loadModelConfigFromDb()?.appium?.flowNodeColor, '#ddeeff');
75
+ assert.equal(loadModelConfigFromDb()?.appium?.flowNodeBorderColor, '#112233');
64
76
  assert.equal(loadModelConfigFromDb()?.appium?.flowLineStyle, 'curved');
77
+ assert.equal(loadModelConfigFromDb()?.appium?.flowLayoutDirection, 'horizontal');
65
78
 
66
79
  for (const key of ['midscene', 'scriptOptimizer', 'appium'] as const) {
67
80
  const before = await (await fetch(base + '/api/config')).json() as AppConfig;
@@ -0,0 +1,52 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { buildFlowGraph } from '../../src/appium-recorder/flow-graph';
4
+ import { labelFlowStep } from '../../src/appium-recorder/flow-labels';
5
+ import type { AppiumRecordedStep } from '../../src/appium-recorder/types';
6
+
7
+ const steps: AppiumRecordedStep[] = [
8
+ { id: 'outer', type: 'assertExists', label: '外层判断', flow: { nodeKind: 'condition' } },
9
+ { id: 'inner', type: 'assertExists', label: '内层判断', flow: { nodeKind: 'condition', parentConditionId: 'outer', parentBranch: 'yes' } },
10
+ { id: 'left', type: 'delay', label: '等待', flow: { parentConditionId: 'inner', parentBranch: 'yes' } },
11
+ { id: 'right', type: 'delay', label: '等待', flow: { parentConditionId: 'inner', parentBranch: 'no' } },
12
+ { id: 'outer-no', type: 'delay', label: '等待', flow: { parentConditionId: 'outer', parentBranch: 'no' } },
13
+ { id: 'finish', type: 'log', label: '公共节点' },
14
+ ];
15
+ const options = { expandedStepIndex: null, selectedCopyIndexes: [], copyMode: false, canOpenInsertMenu: true,
16
+ isStartActionDisabled: () => false, isInsertActionDisabled: () => false, isAppExecutionDisabled: () => false,
17
+ startActionGroups: [], mainActionGroups: [], labelStep: labelFlowStep, isCopySelected: () => false };
18
+
19
+ test('both layout directions preserve flow links, center merges and avoid expanded cards', () => {
20
+ const original = structuredClone(steps);
21
+ const baseline = buildFlowGraph(steps, options);
22
+ for (const layoutDirection of ['vertical', 'horizontal'] as const) {
23
+ const horizontal = layoutDirection === 'horizontal';
24
+ const graph = buildFlowGraph(steps, { ...options, layoutDirection, expandedStepIndex: 2, measuredNodeHeights: { 'step:left': 920 } });
25
+ assert.deepEqual(graph.edges, baseline.edges, 'display direction must not change the flow');
26
+ const byId = new Map(graph.nodes.map(node => [node.id, node]));
27
+ const crossCenter = (id: string) => {
28
+ const node = byId.get(id)!;
29
+ return horizontal ? node.position.y + Number(node.height) / 2 : node.position.x + Number(node.width) / 2;
30
+ };
31
+ for (const [index, a] of graph.nodes.entries()) {
32
+ assert.equal(a.sourcePosition, horizontal ? 'right' : 'bottom');
33
+ if (a.data.kind === 'step') assert.equal(a.width, 340);
34
+ for (const b of graph.nodes.slice(index + 1)) {
35
+ const overlapX = Math.min(a.position.x + Number(a.width), b.position.x + Number(b.width)) - Math.max(a.position.x, b.position.x);
36
+ const overlapY = Math.min(a.position.y + Number(a.height), b.position.y + Number(b.height)) - Math.max(a.position.y, b.position.y);
37
+ assert.ok(overlapX <= 1 || overlapY <= 1, `${layoutDirection}: ${a.id} overlaps ${b.id}`);
38
+ }
39
+ }
40
+ for (const edge of graph.edges) {
41
+ const source = byId.get(edge.source)!;
42
+ const target = byId.get(edge.target)!;
43
+ assert.ok(horizontal ? target.position.x >= source.position.x + Number(source.width) + 23
44
+ : target.position.y >= source.position.y + Number(source.height) + 23);
45
+ if ((edge.data as { merge?: boolean })?.merge) {
46
+ const incoming = graph.edges.filter(item => item.target === edge.target).map(item => crossCenter(item.source));
47
+ assert.ok(Math.abs(crossCenter(edge.target) - (Math.min(...incoming) + Math.max(...incoming)) / 2) <= 1);
48
+ }
49
+ }
50
+ }
51
+ assert.deepEqual(steps, original);
52
+ });
package/server/config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { resolveReportSummary, type ReportSummaryConfig } from '../src/appium-recorder/report-summary';
2
2
  import type { AiPromptPreset } from '../src/appium-recorder/ai-prompt-presets';
3
3
  import fs from 'node:fs';
4
- import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor, normalizeFlowLineStyle } from '../src/appium-recorder/flow-appearance';
4
+ import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor, normalizeFlowLineStyle, normalizeFlowLayoutDirection, normalizeFlowNodeColor, normalizeFlowNodeBorderColor } from '../src/appium-recorder/flow-appearance';
5
5
  import os from 'node:os';
6
6
  import path from 'node:path';
7
7
  import YAML from 'yaml';
@@ -13,7 +13,7 @@ import { resolveAiDeduplication, type AiDeduplicationConfig } from '../src/appiu
13
13
  import type { MidsceneModelProvider } from '../src/config/midscene-model-presets';
14
14
 
15
15
  export type AppConfig = {
16
- appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; flowLineStyle?: 'straight' | 'curved'; screenshotReport?: boolean };
16
+ appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowNodeColor?: string; flowNodeBorderColor?: string; flowLineColor?: string; flowLineStyle?: 'straight' | 'curved'; flowLayoutDirection?: 'vertical' | 'horizontal'; screenshotReport?: boolean };
17
17
  runtime: {
18
18
  androidSdkPath: string;
19
19
  reportOutputPath: string;
@@ -99,8 +99,11 @@ function normalizeConfig(config: Partial<AppConfig> | null | undefined): AppConf
99
99
  aiDeduplication: resolveAiDeduplication(config?.appium?.aiDeduplication),
100
100
  screenshotReport: config?.appium?.screenshotReport === true,
101
101
  flowBackgroundColor: normalizeFlowBackground(config?.appium?.flowBackgroundColor),
102
+ flowNodeColor: normalizeFlowNodeColor(config?.appium?.flowNodeColor),
103
+ flowNodeBorderColor: normalizeFlowNodeBorderColor(config?.appium?.flowNodeBorderColor),
102
104
  flowLineColor: normalizeFlowLineColor(config?.appium?.flowLineColor),
103
105
  flowLineStyle: normalizeFlowLineStyle(config?.appium?.flowLineStyle),
106
+ flowLayoutDirection: normalizeFlowLayoutDirection(config?.appium?.flowLayoutDirection),
104
107
  model: Object.fromEntries(['baseUrl', 'apiKey', 'name'].map((key) => {
105
108
  const value = config?.appium?.model?.[key as keyof AiRecognitionModel];
106
109
  return [key, typeof value === 'string' ? value.trim() : ''];
@@ -243,6 +246,14 @@ export function saveConfig(config: AppConfig) {
243
246
  if (config.appium?.flowLineStyle !== undefined && !['straight', 'curved'].includes(config.appium.flowLineStyle)) {
244
247
  throw new ConfigValidationError('连接线条样式必须是直线或曲线');
245
248
  }
249
+ if (config.appium?.flowLayoutDirection !== undefined && !['vertical', 'horizontal'].includes(config.appium.flowLayoutDirection)) {
250
+ throw new ConfigValidationError('流程布局方向必须是纵向或横向');
251
+ }
252
+ for (const key of ['flowNodeColor', 'flowNodeBorderColor'] as const) {
253
+ if (config.appium?.[key] !== undefined && !isHexColor(config.appium[key])) {
254
+ throw new ConfigValidationError('节点颜色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
255
+ }
256
+ }
246
257
  const normalized = normalizeConfig(config);
247
258
  validateRuntimeConfig(normalized);
248
259
  cachedConfig = normalized;
package/src/App.vue CHANGED
@@ -993,8 +993,11 @@ onUnmounted(() => {
993
993
  :ai-prompt-presets="configForm.appium.aiPromptPresets"
994
994
  :report-summary="configForm.appium.reportSummary"
995
995
  :flow-background-color="configForm.appium.flowBackgroundColor"
996
+ :flow-node-color="configForm.appium.flowNodeColor"
997
+ :flow-node-border-color="configForm.appium.flowNodeBorderColor"
996
998
  :flow-line-color="configForm.appium.flowLineColor"
997
999
  :flow-line-style="configForm.appium.flowLineStyle"
1000
+ :flow-layout-direction="configForm.appium.flowLayoutDirection"
998
1001
  :device-actions="deviceActions"
999
1002
  :playground-available="playgroundAvailable"
1000
1003
  :playground-device-id="playgroundDeviceId"
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, h, nextTick, onMounted, onUnmounted, provide, reactive, shallowRef, useTemplateRef, watch } from 'vue';
3
- import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor, flowLineStyleKey, normalizeFlowLineStyle, type FlowLineStyle } from './flow-appearance';
3
+ import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor, flowLineStyleKey, normalizeFlowLineStyle, type FlowLineStyle, flowLayoutDirectionKey, normalizeFlowLayoutDirection, type FlowLayoutDirection, flowNodeColorKey, normalizeFlowNodeColor, flowNodeBorderColorKey, normalizeFlowNodeBorderColor } from './flow-appearance';
4
4
  import { useCoordinatePicker } from './coordinate-preview';
5
5
  import { DEFAULT_NODE_TIMEOUT_MS } from './node-timeout';
6
6
  import { aiPromptPresetsKey, DEFAULT_AI_PROMPT_PRESETS, type AiPromptPreset } from './ai-prompt-presets';
@@ -111,8 +111,11 @@ const props = defineProps<{
111
111
  aiPromptPresets?: AiPromptPreset[];
112
112
  reportSummary?: ReportSummaryConfig;
113
113
  flowBackgroundColor?: string;
114
+ flowNodeColor?: string;
115
+ flowNodeBorderColor?: string;
114
116
  flowLineColor?: string;
115
117
  flowLineStyle?: FlowLineStyle;
118
+ flowLayoutDirection?: FlowLayoutDirection;
116
119
  active: boolean;
117
120
  appPresets: AppPreset[];
118
121
  deviceActions: readonly DeviceAction[];
@@ -138,8 +141,11 @@ const props = defineProps<{
138
141
 
139
142
  // provide/inject 随组件关系传递,放大弹窗 teleport 后也能使用同一颜色。
140
143
  provide(flowBackgroundKey, computed(() => normalizeFlowBackground(props.flowBackgroundColor)));
144
+ provide(flowNodeColorKey, computed(() => normalizeFlowNodeColor(props.flowNodeColor)));
145
+ provide(flowNodeBorderColorKey, computed(() => normalizeFlowNodeBorderColor(props.flowNodeBorderColor)));
141
146
  provide(flowLineColorKey, computed(() => normalizeFlowLineColor(props.flowLineColor)));
142
147
  provide(flowLineStyleKey, computed(() => normalizeFlowLineStyle(props.flowLineStyle)));
148
+ provide(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(props.flowLayoutDirection)));
143
149
  const availableAiPromptPresets = computed(() => props.aiPromptPresets ?? DEFAULT_AI_PROMPT_PRESETS);
144
150
  const availableReportTemplates = computed(() => [
145
151
  ...REPORT_SUMMARY_PROMPT_PRESETS,
@@ -232,7 +232,7 @@ async function save(enabled: boolean, observation?: AiObservationConfig) {
232
232
  .ai-recognition-settings__toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0 12px; }
233
233
  .ai-recognition-settings__toggle-row :deep(.el-checkbox) { margin-right: 0; }
234
234
  .ai-recognition-settings__toggles :deep(.el-form-item__content) { align-items: center; }
235
- .ai-recognition-settings__groups { overflow: hidden; border: 1px solid var(--el-border-color-lighter); border-radius: 10px; background: #fff; }
235
+ .ai-recognition-settings__groups { overflow: hidden; border: 1px solid var(--el-border-color-lighter); border-radius: 10px; background: var(--ui-surface); }
236
236
  .ai-recognition-settings__groups :deep(.el-collapse-item__header) { height: 42px; padding: 0 10px; border-bottom-color: var(--el-border-color-lighter); font-size: 12px; }
237
237
  .ai-recognition-settings__groups :deep(.el-collapse-item__wrap) { border-bottom-color: var(--el-border-color-lighter); }
238
238
  .ai-recognition-settings__groups :deep(.el-collapse-item:last-child .el-collapse-item__header),
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, inject, nextTick, onBeforeUnmount, shallowRef, watch } from 'vue';
3
- import { DEFAULT_FLOW_BACKGROUND, flowBackgroundKey, DEFAULT_FLOW_LINE_COLOR, flowLineColorKey } from '../flow-appearance';
3
+ import { DEFAULT_FLOW_BACKGROUND, flowBackgroundKey, DEFAULT_FLOW_LINE_COLOR, flowLineColorKey, flowLayoutDirectionKey, normalizeFlowLayoutDirection, flowNodeColorKey, flowNodeBorderColorKey, normalizeFlowNodeColor, normalizeFlowNodeBorderColor, flowNodeTextColors } from '../flow-appearance';
4
4
  import { useVueFlow, VueFlow } from '@vue-flow/core';
5
5
  import FlowNodeCard from './FlowNodeCard.vue';
6
6
  import FlowRoundedEdge from './FlowRoundedEdge.vue';
@@ -15,6 +15,36 @@ import type { AppiumRecordedStep } from '../types';
15
15
 
16
16
  const flowBackground = inject(flowBackgroundKey, computed(() => DEFAULT_FLOW_BACKGROUND));
17
17
  const flowLineColor = inject(flowLineColorKey, computed(() => DEFAULT_FLOW_LINE_COLOR));
18
+ const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(undefined)));
19
+ const nodeColor = inject(flowNodeColorKey, computed(() => normalizeFlowNodeColor(undefined)));
20
+ const nodeBorderColor = inject(flowNodeBorderColorKey, computed(() => normalizeFlowNodeBorderColor(undefined)));
21
+ const nodeText = computed(() => flowNodeTextColors(nodeColor.value));
22
+ const canvasStyle = computed(() => {
23
+ const field = `color-mix(in srgb, ${nodeColor.value} 92%, ${nodeText.value.text})`;
24
+ return {
25
+ '--flow-background': flowBackground.value,
26
+ '--appium-flow-line-color': flowLineColor.value,
27
+ '--ui-surface': nodeColor.value,
28
+ '--ui-border': nodeBorderColor.value,
29
+ '--ui-text': nodeText.value.text,
30
+ '--ui-text-secondary': nodeText.value.muted,
31
+ '--ui-text-muted': nodeText.value.muted,
32
+ '--ui-bg-soft': field,
33
+ '--el-bg-color': nodeColor.value,
34
+ '--el-fill-color-blank': nodeColor.value,
35
+ '--el-fill-color-light': field,
36
+ '--el-fill-color-lighter': field,
37
+ '--el-text-color-primary': nodeText.value.text,
38
+ '--el-text-color-regular': nodeText.value.text,
39
+ '--el-text-color-secondary': nodeText.value.muted,
40
+ '--el-text-color-placeholder': nodeText.value.muted,
41
+ '--el-border-color': nodeBorderColor.value,
42
+ '--el-border-color-light': nodeBorderColor.value,
43
+ '--el-border-color-lighter': nodeBorderColor.value,
44
+ '--el-disabled-bg-color': field,
45
+ '--el-disabled-text-color': nodeText.value.muted,
46
+ };
47
+ });
18
48
 
19
49
  const props = defineProps<{
20
50
  aiRecognitionModelConfigured?: boolean;
@@ -59,17 +89,23 @@ const emit = defineEmits<{
59
89
  }>();
60
90
 
61
91
  const measuredNodeHeights = shallowRef<Record<string, number>>({});
62
- const { fitView, updateNodeInternals, findNode, setCenter, viewport } = useVueFlow(props.id);
92
+ const { fitView, updateNodeInternals, findNode, setCenter, setViewport, viewport } = useVueFlow(props.id);
63
93
  const paneReady = shallowRef(false);
64
94
  let internalsFrame = 0;
95
+ const pendingInternals = new Set<string>();
96
+ let resizeFrame = 0;
97
+ let pendingNodeHeights: Record<string, number> = {};
65
98
  let resetViewFrame = 0;
66
- let pendingResetView = false;
67
99
  let searchFrame = 0;
68
100
  let focusFrame = 0;
69
101
  let focusedNodeId = '';
102
+ let insertionNodeId = '';
103
+ let viewportAnchor: { id: string; x: number; y: number } | null = null;
104
+ let knownStepIds = new Set(props.steps.map(step => step.id));
70
105
  watch(() => [props.searchFocusToken, props.searchTargetId, props.searchActive, paneReady.value], async () => {
71
106
  if (searchFrame) cancelAnimationFrame(searchFrame);
72
107
  if (!props.searchActive || !props.searchTargetId || !paneReady.value) return;
108
+ viewportAnchor = null;
73
109
  await nextTick();
74
110
  searchFrame = requestAnimationFrame(() => {
75
111
  const node = findNode(`step:${props.searchTargetId}`);
@@ -79,38 +115,55 @@ watch(() => [props.searchFocusToken, props.searchTargetId, props.searchActive, p
79
115
  });
80
116
  });
81
117
 
82
- const graph = computed(() => buildFlowGraph(props.steps, {
83
- deleteMode: props.deleteMode,
84
- mergeDisabled: props.mergeDisabled,
85
- aiRecognitionModelConfigured: props.aiRecognitionModelConfigured,
86
- expandedStepIndex: props.expandedStepIndex,
87
- selectedCopyIndexes: props.selectedCopyIndexes,
88
- copyMode: props.copyMode,
89
- disabled: props.disabled,
90
- removeDisabled: props.removeDisabled,
91
- launchingStepId: props.launchingStepId,
92
- clipboardCount: props.clipboardCount,
93
- canOpenInsertMenu: props.canOpenInsertMenu,
94
- isStartActionDisabled: props.isStartActionDisabled,
95
- isInsertActionDisabled: props.isInsertActionDisabled,
96
- isAppExecutionDisabled: props.isAppExecutionDisabled,
97
- startActionGroups: props.startActionGroups,
98
- mainActionGroups: props.mainActionGroups,
99
- measuredNodeHeights: measuredNodeHeights.value,
100
- labelStep: props.labelStep,
101
- isCopySelected: props.isCopySelected,
102
- }));
118
+ const graph = computed<ReturnType<typeof buildFlowGraph>>((previous) => {
119
+ const next = buildFlowGraph(props.steps, {
120
+ layoutDirection: layoutDirection.value,
121
+ deleteMode: props.deleteMode,
122
+ mergeDisabled: props.mergeDisabled,
123
+ aiRecognitionModelConfigured: props.aiRecognitionModelConfigured,
124
+ // 展开先更新当前卡片,布局只响应随后测到的实际尺寸。
125
+ expandedStepIndex: null,
126
+ selectedCopyIndexes: props.selectedCopyIndexes,
127
+ copyMode: props.copyMode,
128
+ disabled: props.disabled,
129
+ removeDisabled: props.removeDisabled,
130
+ launchingStepId: props.launchingStepId,
131
+ clipboardCount: props.clipboardCount,
132
+ canOpenInsertMenu: props.canOpenInsertMenu,
133
+ isStartActionDisabled: props.isStartActionDisabled,
134
+ isInsertActionDisabled: props.isInsertActionDisabled,
135
+ isAppExecutionDisabled: props.isAppExecutionDisabled,
136
+ startActionGroups: props.startActionGroups,
137
+ mainActionGroups: props.mainActionGroups,
138
+ measuredNodeHeights: measuredNodeHeights.value,
139
+ labelStep: props.labelStep,
140
+ isCopySelected: props.isCopySelected,
141
+ });
142
+ const previousNodes = new Map(previous?.nodes.map(node => [node.id, node]));
143
+ for (const node of next.nodes) {
144
+ const old = previousNodes.get(node.id)?.data;
145
+ // 保持未修改节点的配置引用,避免一次展开让所有卡片重新渲染。
146
+ if (old && node.data && Object.keys(old).length === Object.keys(node.data).length
147
+ && Object.entries(node.data).every(([key, value]) => Reflect.get(old, key) === value)) {
148
+ node.data = old;
149
+ }
150
+ }
151
+ return next;
152
+ });
103
153
 
104
154
  function handleNodeResize(payload: { id: string; height: number }) {
105
155
  const height = Math.ceil(payload.height) + 6;
106
- if (!height || Math.abs((measuredNodeHeights.value[payload.id] || 0) - height) < 1) return;
107
- measuredNodeHeights.value = {
108
- ...measuredNodeHeights.value,
109
- [payload.id]: height,
110
- };
111
- void nextTick(scheduleNodeInternalsUpdate);
112
- if (payload.id === focusedNodeId) void nextTick(() => scheduleNodeFocus(payload.id));
113
- if (props.readonly) void nextTick(() => scheduleResetView());
156
+ const previous = pendingNodeHeights[payload.id] ?? measuredNodeHeights.value[payload.id] ?? 0;
157
+ if (!height || Math.abs(previous - height) < 1) return;
158
+ pendingNodeHeights[payload.id] = height;
159
+ if (resizeFrame) return;
160
+ // 同一帧的尺寸变化只重排一次;展开子选项不重新聚焦画布。
161
+ resizeFrame = window.requestAnimationFrame(() => {
162
+ resizeFrame = 0;
163
+ measuredNodeHeights.value = { ...measuredNodeHeights.value, ...pendingNodeHeights };
164
+ pendingNodeHeights = {};
165
+ if (props.readonly) void nextTick(() => scheduleResetView());
166
+ });
114
167
  }
115
168
 
116
169
  function scheduleNodeFocus(nodeId: string) {
@@ -134,32 +187,48 @@ function scheduleNodeFocus(nodeId: string) {
134
187
  }
135
188
 
136
189
  function handleNodeClick(index: number) {
190
+ viewportAnchor = null;
191
+ insertionNodeId = '';
137
192
  const step = props.steps[index];
138
193
  if (step) focusedNodeId = `step:${step.id}`;
139
194
  emit('nodeClick', index);
140
195
  if (focusedNodeId) void nextTick(() => scheduleNodeFocus(focusedNodeId));
141
196
  }
142
197
 
143
- function scheduleNodeInternalsUpdate() {
144
- if (internalsFrame) window.cancelAnimationFrame(internalsFrame);
198
+ function scheduleNodeInternalsUpdate(ids = graph.value.nodes.map(node => node.id)) {
199
+ ids.forEach(id => pendingInternals.add(id));
200
+ if (internalsFrame) return;
145
201
  internalsFrame = window.requestAnimationFrame(() => {
146
202
  internalsFrame = 0;
147
- updateNodeInternals(graph.value.nodes.map((node) => node.id));
203
+ const changed = [...pendingInternals];
204
+ pendingInternals.clear();
205
+ if (changed.length) updateNodeInternals(changed);
206
+ preserveInsertionPosition();
148
207
  });
149
208
  }
150
209
 
151
- function scheduleResetView(attempt = 0) {
152
- if (!paneReady.value) {
153
- pendingResetView = true;
154
- return;
210
+ function preserveInsertionPosition() {
211
+ if (!viewportAnchor) return;
212
+ const node = findNode(viewportAnchor.id);
213
+ if (!node) { viewportAnchor = null; return; }
214
+ const dx = viewportAnchor.x - node.position.x;
215
+ const dy = viewportAnchor.y - node.position.y;
216
+ if (dx || dy) {
217
+ const { x, y, zoom } = viewport.value;
218
+ void setViewport({ x: x + dx * zoom, y: y + dy * zoom, zoom });
155
219
  }
220
+ viewportAnchor = { id: node.id, x: node.position.x, y: node.position.y };
221
+ }
222
+
223
+ function scheduleResetView(attempt = 0) {
224
+ if (!paneReady.value) return;
156
225
  if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
157
226
  resetViewFrame = window.requestAnimationFrame(async () => {
158
227
  resetViewFrame = 0;
159
228
  updateNodeInternals(graph.value.nodes.map((node) => node.id));
160
229
  const fitted = await fitView({
161
230
  padding: 0.18,
162
- minZoom: 0.35,
231
+ minZoom: layoutDirection.value === 'horizontal' ? (props.readonly ? 0.1 : 0.7) : 0.35,
163
232
  maxZoom: 1.8,
164
233
  duration: attempt ? 0 : 240,
165
234
  });
@@ -169,8 +238,6 @@ function scheduleResetView(attempt = 0) {
169
238
 
170
239
  function handlePaneReady() {
171
240
  paneReady.value = true;
172
- if (!pendingResetView && !props.readonly) return;
173
- pendingResetView = false;
174
241
  void nextTick(() => scheduleResetView());
175
242
  }
176
243
 
@@ -187,12 +254,51 @@ function flowStructureKey() {
187
254
  }
188
255
 
189
256
  watch(flowStructureKey, () => {
190
- measuredNodeHeights.value = {};
191
- void nextTick(scheduleNodeInternalsUpdate);
257
+ const nextIds = new Set(props.steps.map(step => step.id));
258
+ const added = [...nextIds].some(id => !knownStepIds.has(id));
259
+ const sameScript = !knownStepIds.size || [...nextIds].some(id => knownStepIds.has(id));
260
+ if (added && sameScript) {
261
+ const node = findNode(insertionNodeId) || findNode(focusedNodeId);
262
+ viewportAnchor = node ? { id: node.id, x: node.position.x, y: node.position.y } : null;
263
+ focusedNodeId = '';
264
+ if (focusFrame) window.cancelAnimationFrame(focusFrame);
265
+ focusFrame = 0;
266
+ if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
267
+ resetViewFrame = 0;
268
+ // 中断旧的聚焦动画;新增节点不改变当前缩放。
269
+ if (paneReady.value) void setViewport({ ...viewport.value });
270
+ } else if (!sameScript) {
271
+ viewportAnchor = null;
272
+ }
273
+ insertionNodeId = '';
274
+ knownStepIds = nextIds;
275
+ // 已有尺寸仍然有效,避免重新测量整张图时触发旧选中节点的聚焦。
276
+ const retained = Object.entries(measuredNodeHeights.value).filter(([id]) => nextIds.has(id.replace(/^step:/, '')));
277
+ if (retained.length !== Object.keys(measuredNodeHeights.value).length) {
278
+ measuredNodeHeights.value = Object.fromEntries(retained);
279
+ }
192
280
  });
193
281
 
194
- watch(graph, () => {
195
- void nextTick(scheduleNodeInternalsUpdate);
282
+ watch(graph, (next, previous) => {
283
+ const previousNodes = new Map(previous.nodes.map(node => [node.id, node]));
284
+ const changed = next.nodes.filter(node => {
285
+ const old = previousNodes.get(node.id);
286
+ return !old || old.data !== node.data || old.width !== node.width || old.height !== node.height
287
+ || old.sourcePosition !== node.sourcePosition || old.targetPosition !== node.targetPosition;
288
+ }).map(node => node.id);
289
+ // 平移后的相对连接点不变,只测量新增或尺寸、内容发生变化的节点。
290
+ void nextTick(() => scheduleNodeInternalsUpdate(changed));
291
+ });
292
+
293
+ watch(layoutDirection, () => {
294
+ viewportAnchor = null;
295
+ focusedNodeId = '';
296
+ if (focusFrame) window.cancelAnimationFrame(focusFrame);
297
+ focusFrame = 0;
298
+ void nextTick(() => {
299
+ scheduleNodeInternalsUpdate();
300
+ scheduleResetView();
301
+ });
196
302
  });
197
303
 
198
304
  watch(() => props.expandedStepIndex, () => {
@@ -200,6 +306,7 @@ watch(() => props.expandedStepIndex, () => {
200
306
  });
201
307
 
202
308
  watch(() => props.resetViewToken, () => {
309
+ viewportAnchor = null;
203
310
  focusedNodeId = '';
204
311
  if (focusFrame) window.cancelAnimationFrame(focusFrame);
205
312
  focusFrame = 0;
@@ -210,8 +317,8 @@ onBeforeUnmount(() => {
210
317
  if (searchFrame) cancelAnimationFrame(searchFrame);
211
318
  if (focusFrame) cancelAnimationFrame(focusFrame);
212
319
  if (internalsFrame) window.cancelAnimationFrame(internalsFrame);
320
+ if (resizeFrame) window.cancelAnimationFrame(resizeFrame);
213
321
  if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
214
- pendingResetView = false;
215
322
  });
216
323
 
217
324
  function handleInsert(payload: {
@@ -220,7 +327,8 @@ function handleInsert(payload: {
220
327
  branch?: FlowBranch;
221
328
  conditionIndex?: number;
222
329
  beforeStepId?: string;
223
- }) {
330
+ }, nodeId: string) {
331
+ insertionNodeId = nodeId;
224
332
  if (payload.action === PASTE_COMMAND) {
225
333
  emit('paste', payload.afterIndex, payload.branch, payload.beforeStepId);
226
334
  return;
@@ -234,14 +342,13 @@ function handleInsert(payload: {
234
342
  </script>
235
343
 
236
344
  <template>
237
- <div class="appium-flow-canvas appium-flow-canvas--vue" :style="{ '--flow-background': flowBackground, '--appium-flow-line-color': flowLineColor }">
345
+ <div class="appium-flow-canvas appium-flow-canvas--vue" :class="[`appium-flow-canvas--${layoutDirection}`, { 'appium-flow-canvas--dark-nodes': nodeText.dark }]" :style="canvasStyle">
238
346
  <VueFlow
239
347
  :id="id"
240
348
  class="appium-vue-flow"
241
349
  :nodes="graph.nodes"
242
350
  :edges="graph.edges"
243
- :fit-view-on-init="true"
244
- :min-zoom="0.35"
351
+ :min-zoom="layoutDirection === 'horizontal' ? 0.1 : 0.35"
245
352
  :max-zoom="1.8"
246
353
  :nodes-draggable="false"
247
354
  :nodes-connectable="false"
@@ -261,6 +368,7 @@ function handleInsert(payload: {
261
368
  :steps="steps"
262
369
  :node-id="nodeId"
263
370
  :data="data"
371
+ :expanded="data.kind === 'step' && data.index === expandedStepIndex"
264
372
  :readonly="props.readonly"
265
373
  :search-highlighted="nodeId === `step:${searchTargetId}`"
266
374
  @node-click="handleNodeClick"
@@ -268,7 +376,7 @@ function handleInsert(payload: {
268
376
  @remove="emit('remove', $event)"
269
377
  @edit-input="emit('editInput', $event)"
270
378
  @execute="emit('executeStep', $event)"
271
- @insert="handleInsert"
379
+ @insert="(payload) => handleInsert(payload, nodeId)"
272
380
  @update-step="emit('updateStep', $event.index, $event.step)"
273
381
  @merge="emit('merge', $event)"
274
382
  @preview-linked-script="emit('previewLinkedScript', $event)"