android-midscene-automation 1.1.7 → 1.1.8

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,11 @@
1
1
  # 更新记录
2
+ ## v1.1.8
3
+ - [Appium]流程布局新增横向显示,默认为纵向。
4
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
5
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
6
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
7
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
8
+
2
9
  ## v1.1.7
3
10
  - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
4
11
  - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
package/README.md CHANGED
@@ -1502,6 +1502,13 @@ Linux: ~/.local/share/android-midscene-automation
1502
1502
 
1503
1503
  # 项目更新记录
1504
1504
 
1505
+ ## v1.1.8
1506
+ - [Appium]流程布局新增横向显示,默认为纵向。
1507
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
1508
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
1509
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
1510
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
1511
+
1505
1512
  ## v1.1.7
1506
1513
  - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
1507
1514
  - [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.8",
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,22 @@ 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
+ let resizeFrame = 0;
96
+ let pendingNodeHeights: Record<string, number> = {};
65
97
  let resetViewFrame = 0;
66
- let pendingResetView = false;
67
98
  let searchFrame = 0;
68
99
  let focusFrame = 0;
69
100
  let focusedNodeId = '';
101
+ let insertionNodeId = '';
102
+ let viewportAnchor: { id: string; x: number; y: number } | null = null;
103
+ let knownStepIds = new Set(props.steps.map(step => step.id));
70
104
  watch(() => [props.searchFocusToken, props.searchTargetId, props.searchActive, paneReady.value], async () => {
71
105
  if (searchFrame) cancelAnimationFrame(searchFrame);
72
106
  if (!props.searchActive || !props.searchTargetId || !paneReady.value) return;
107
+ viewportAnchor = null;
73
108
  await nextTick();
74
109
  searchFrame = requestAnimationFrame(() => {
75
110
  const node = findNode(`step:${props.searchTargetId}`);
@@ -80,6 +115,7 @@ watch(() => [props.searchFocusToken, props.searchTargetId, props.searchActive, p
80
115
  });
81
116
 
82
117
  const graph = computed(() => buildFlowGraph(props.steps, {
118
+ layoutDirection: layoutDirection.value,
83
119
  deleteMode: props.deleteMode,
84
120
  mergeDisabled: props.mergeDisabled,
85
121
  aiRecognitionModelConfigured: props.aiRecognitionModelConfigured,
@@ -103,14 +139,17 @@ const graph = computed(() => buildFlowGraph(props.steps, {
103
139
 
104
140
  function handleNodeResize(payload: { id: string; height: number }) {
105
141
  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());
142
+ const previous = pendingNodeHeights[payload.id] ?? measuredNodeHeights.value[payload.id] ?? 0;
143
+ if (!height || Math.abs(previous - height) < 1) return;
144
+ pendingNodeHeights[payload.id] = height;
145
+ if (resizeFrame) return;
146
+ // 同一帧的尺寸变化只重排一次;展开子选项不重新聚焦画布。
147
+ resizeFrame = window.requestAnimationFrame(() => {
148
+ resizeFrame = 0;
149
+ measuredNodeHeights.value = { ...measuredNodeHeights.value, ...pendingNodeHeights };
150
+ pendingNodeHeights = {};
151
+ if (props.readonly) void nextTick(() => scheduleResetView());
152
+ });
114
153
  }
115
154
 
116
155
  function scheduleNodeFocus(nodeId: string) {
@@ -134,6 +173,8 @@ function scheduleNodeFocus(nodeId: string) {
134
173
  }
135
174
 
136
175
  function handleNodeClick(index: number) {
176
+ viewportAnchor = null;
177
+ insertionNodeId = '';
137
178
  const step = props.steps[index];
138
179
  if (step) focusedNodeId = `step:${step.id}`;
139
180
  emit('nodeClick', index);
@@ -145,21 +186,32 @@ function scheduleNodeInternalsUpdate() {
145
186
  internalsFrame = window.requestAnimationFrame(() => {
146
187
  internalsFrame = 0;
147
188
  updateNodeInternals(graph.value.nodes.map((node) => node.id));
189
+ preserveInsertionPosition();
148
190
  });
149
191
  }
150
192
 
151
- function scheduleResetView(attempt = 0) {
152
- if (!paneReady.value) {
153
- pendingResetView = true;
154
- return;
193
+ function preserveInsertionPosition() {
194
+ if (!viewportAnchor) return;
195
+ const node = findNode(viewportAnchor.id);
196
+ if (!node) { viewportAnchor = null; return; }
197
+ const dx = viewportAnchor.x - node.position.x;
198
+ const dy = viewportAnchor.y - node.position.y;
199
+ if (dx || dy) {
200
+ const { x, y, zoom } = viewport.value;
201
+ void setViewport({ x: x + dx * zoom, y: y + dy * zoom, zoom });
155
202
  }
203
+ viewportAnchor = { id: node.id, x: node.position.x, y: node.position.y };
204
+ }
205
+
206
+ function scheduleResetView(attempt = 0) {
207
+ if (!paneReady.value) return;
156
208
  if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
157
209
  resetViewFrame = window.requestAnimationFrame(async () => {
158
210
  resetViewFrame = 0;
159
211
  updateNodeInternals(graph.value.nodes.map((node) => node.id));
160
212
  const fitted = await fitView({
161
213
  padding: 0.18,
162
- minZoom: 0.35,
214
+ minZoom: layoutDirection.value === 'horizontal' ? (props.readonly ? 0.1 : 0.7) : 0.35,
163
215
  maxZoom: 1.8,
164
216
  duration: attempt ? 0 : 240,
165
217
  });
@@ -169,8 +221,6 @@ function scheduleResetView(attempt = 0) {
169
221
 
170
222
  function handlePaneReady() {
171
223
  paneReady.value = true;
172
- if (!pendingResetView && !props.readonly) return;
173
- pendingResetView = false;
174
224
  void nextTick(() => scheduleResetView());
175
225
  }
176
226
 
@@ -187,7 +237,29 @@ function flowStructureKey() {
187
237
  }
188
238
 
189
239
  watch(flowStructureKey, () => {
190
- measuredNodeHeights.value = {};
240
+ const nextIds = new Set(props.steps.map(step => step.id));
241
+ const added = [...nextIds].some(id => !knownStepIds.has(id));
242
+ const sameScript = !knownStepIds.size || [...nextIds].some(id => knownStepIds.has(id));
243
+ if (added && sameScript) {
244
+ const node = findNode(insertionNodeId) || findNode(focusedNodeId);
245
+ viewportAnchor = node ? { id: node.id, x: node.position.x, y: node.position.y } : null;
246
+ focusedNodeId = '';
247
+ if (focusFrame) window.cancelAnimationFrame(focusFrame);
248
+ focusFrame = 0;
249
+ if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
250
+ resetViewFrame = 0;
251
+ // 中断旧的聚焦动画;新增节点不改变当前缩放。
252
+ if (paneReady.value) void setViewport({ ...viewport.value });
253
+ } else if (!sameScript) {
254
+ viewportAnchor = null;
255
+ }
256
+ insertionNodeId = '';
257
+ knownStepIds = nextIds;
258
+ // 已有尺寸仍然有效,避免重新测量整张图时触发旧选中节点的聚焦。
259
+ const retained = Object.entries(measuredNodeHeights.value).filter(([id]) => nextIds.has(id.replace(/^step:/, '')));
260
+ if (retained.length !== Object.keys(measuredNodeHeights.value).length) {
261
+ measuredNodeHeights.value = Object.fromEntries(retained);
262
+ }
191
263
  void nextTick(scheduleNodeInternalsUpdate);
192
264
  });
193
265
 
@@ -195,11 +267,23 @@ watch(graph, () => {
195
267
  void nextTick(scheduleNodeInternalsUpdate);
196
268
  });
197
269
 
270
+ watch(layoutDirection, () => {
271
+ viewportAnchor = null;
272
+ focusedNodeId = '';
273
+ if (focusFrame) window.cancelAnimationFrame(focusFrame);
274
+ focusFrame = 0;
275
+ void nextTick(() => {
276
+ scheduleNodeInternalsUpdate();
277
+ scheduleResetView();
278
+ });
279
+ });
280
+
198
281
  watch(() => props.expandedStepIndex, () => {
199
282
  if (focusedNodeId) void nextTick(() => scheduleNodeFocus(focusedNodeId));
200
283
  });
201
284
 
202
285
  watch(() => props.resetViewToken, () => {
286
+ viewportAnchor = null;
203
287
  focusedNodeId = '';
204
288
  if (focusFrame) window.cancelAnimationFrame(focusFrame);
205
289
  focusFrame = 0;
@@ -210,8 +294,8 @@ onBeforeUnmount(() => {
210
294
  if (searchFrame) cancelAnimationFrame(searchFrame);
211
295
  if (focusFrame) cancelAnimationFrame(focusFrame);
212
296
  if (internalsFrame) window.cancelAnimationFrame(internalsFrame);
297
+ if (resizeFrame) window.cancelAnimationFrame(resizeFrame);
213
298
  if (resetViewFrame) window.cancelAnimationFrame(resetViewFrame);
214
- pendingResetView = false;
215
299
  });
216
300
 
217
301
  function handleInsert(payload: {
@@ -220,7 +304,8 @@ function handleInsert(payload: {
220
304
  branch?: FlowBranch;
221
305
  conditionIndex?: number;
222
306
  beforeStepId?: string;
223
- }) {
307
+ }, nodeId: string) {
308
+ insertionNodeId = nodeId;
224
309
  if (payload.action === PASTE_COMMAND) {
225
310
  emit('paste', payload.afterIndex, payload.branch, payload.beforeStepId);
226
311
  return;
@@ -234,14 +319,13 @@ function handleInsert(payload: {
234
319
  </script>
235
320
 
236
321
  <template>
237
- <div class="appium-flow-canvas appium-flow-canvas--vue" :style="{ '--flow-background': flowBackground, '--appium-flow-line-color': flowLineColor }">
322
+ <div class="appium-flow-canvas appium-flow-canvas--vue" :class="[`appium-flow-canvas--${layoutDirection}`, { 'appium-flow-canvas--dark-nodes': nodeText.dark }]" :style="canvasStyle">
238
323
  <VueFlow
239
324
  :id="id"
240
325
  class="appium-vue-flow"
241
326
  :nodes="graph.nodes"
242
327
  :edges="graph.edges"
243
- :fit-view-on-init="true"
244
- :min-zoom="0.35"
328
+ :min-zoom="layoutDirection === 'horizontal' ? 0.1 : 0.35"
245
329
  :max-zoom="1.8"
246
330
  :nodes-draggable="false"
247
331
  :nodes-connectable="false"
@@ -268,7 +352,7 @@ function handleInsert(payload: {
268
352
  @remove="emit('remove', $event)"
269
353
  @edit-input="emit('editInput', $event)"
270
354
  @execute="emit('executeStep', $event)"
271
- @insert="handleInsert"
355
+ @insert="(payload) => handleInsert(payload, nodeId)"
272
356
  @update-step="emit('updateStep', $event.index, $event.step)"
273
357
  @merge="emit('merge', $event)"
274
358
  @preview-linked-script="emit('previewLinkedScript', $event)"
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue';
2
+ import { computed, inject, onBeforeUnmount, onMounted, shallowRef } from 'vue';
3
+ import { flowLayoutDirectionKey, normalizeFlowLayoutDirection } from '../flow-appearance';
3
4
  import { Handle, Position } from '@vue-flow/core';
4
5
  import { CopyDocument, Delete, Edit, Plus, VideoPlay, View, WarningFilled, Connection, RefreshLeft } from '@element-plus/icons-vue';
5
6
  import type { AppiumRecordedStep } from '../types';
@@ -33,6 +34,9 @@ const emit = defineEmits<{
33
34
  resize: [payload: { id: string; height: number }];
34
35
  }>();
35
36
 
37
+ const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(undefined)));
38
+ const horizontal = computed(() => layoutDirection.value === 'horizontal');
39
+
36
40
  const rootRef = shallowRef<HTMLElement | null>(null);
37
41
  let resizeObserver: ResizeObserver | null = null;
38
42
 
@@ -64,27 +68,21 @@ function handleStepClick() {
64
68
  emit('nodeClick', props.data.index);
65
69
  }
66
70
 
67
- function reportSize() {
71
+ onMounted(() => {
68
72
  if (!rootRef.value || props.data.kind !== 'step') return;
69
- emit('resize', {
70
- id: props.nodeId,
71
- height: rootRef.value.offsetHeight,
73
+ resizeObserver = new ResizeObserver(([entry]) => {
74
+ if (!entry) return;
75
+ emit('resize', {
76
+ id: props.nodeId,
77
+ height: entry.borderBoxSize[0]?.blockSize ?? rootRef.value!.offsetHeight,
78
+ });
72
79
  });
73
- }
74
-
75
- onMounted(() => {
76
- resizeObserver = new ResizeObserver(reportSize);
77
- if (rootRef.value) resizeObserver.observe(rootRef.value);
78
- void nextTick(reportSize);
80
+ resizeObserver.observe(rootRef.value);
79
81
  });
80
82
 
81
83
  onBeforeUnmount(() => {
82
84
  resizeObserver?.disconnect();
83
85
  });
84
-
85
- watch(() => props.data, () => {
86
- void nextTick(reportSize);
87
- });
88
86
  </script>
89
87
 
90
88
  <template>
@@ -100,8 +98,8 @@ watch(() => props.data, () => {
100
98
  <Handle
101
99
  id="top"
102
100
  type="target"
103
- :position="Position.Top"
104
- class="appium-flow-handle appium-flow-handle--top"
101
+ :position="horizontal ? Position.Left : Position.Top"
102
+ class="appium-flow-handle"
105
103
  />
106
104
 
107
105
  <div v-if="data.kind === 'start'" class="appium-flow-start-card nodrag nopan">
@@ -264,13 +262,35 @@ watch(() => props.data, () => {
264
262
  <Handle
265
263
  id="bottom"
266
264
  type="source"
267
- :position="Position.Bottom"
268
- class="appium-flow-handle appium-flow-handle--bottom"
265
+ :position="horizontal ? Position.Right : Position.Bottom"
266
+ class="appium-flow-handle"
269
267
  />
270
268
  </div>
271
269
  </template>
272
270
 
273
271
  <style scoped>
272
+ .appium-flow-step-shell--expanded {
273
+ overflow: hidden;
274
+ border: 1px solid var(--ui-border);
275
+ border-radius: var(--ui-radius-control);
276
+ background: var(--ui-surface);
277
+ box-shadow: var(--ui-shadow-card);
278
+ }
279
+ .appium-flow-step-shell--expanded.appium-flow-step-shell--selected { border-color: var(--ui-primary); }
280
+ .appium-flow-step-shell--expanded > .appium-flow-step-card {
281
+ width: 100%;
282
+ border: 0;
283
+ border-radius: 0;
284
+ box-shadow: none;
285
+ }
286
+ .appium-flow-step-shell--expanded > .appium-flow-step-editor {
287
+ width: 100%;
288
+ margin-top: 0;
289
+ border: 0;
290
+ border-top: 1px solid var(--ui-border);
291
+ border-radius: 0;
292
+ }
293
+
274
294
  .appium-flow-step-shell--delete-selected .appium-flow-step-card { background: #b83232; border-color: #a52a2a; }
275
295
  .appium-flow-step-shell--delete-selected .appium-flow-step-card__content strong,
276
296
  .appium-flow-step-shell--delete-selected .appium-flow-step-card__content em { color: #fff; }