android-midscene-automation 1.1.6 → 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.
@@ -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; }
@@ -1,64 +1,49 @@
1
1
  <script setup lang="ts">
2
- import { computed } from 'vue';
2
+ import { computed, inject } from 'vue';
3
3
  import { BaseEdge, type EdgeProps } from '@vue-flow/core';
4
+ import { flowLineStyleKey, normalizeFlowLineStyle, flowLayoutDirectionKey, normalizeFlowLayoutDirection } from '../flow-appearance';
4
5
  import type { FlowGraphNodeData } from '../flow-graph';
5
6
 
6
7
  const props = defineProps<EdgeProps>();
8
+ const lineStyle = inject(flowLineStyleKey, computed(() => normalizeFlowLineStyle(undefined)));
9
+ const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(undefined)));
7
10
 
8
- const targetData = computed(() => props.targetNode.data as FlowGraphNodeData | undefined);
9
-
10
- type Point = {
11
- x: number;
12
- y: number;
13
- };
14
-
15
- function linePath(points: Point[]) {
16
- if (points.length < 2) return '';
17
- const [start, ...rest] = points;
18
- return [
19
- `M ${start.x} ${start.y}`,
20
- ...rest.map((point) => `L ${point.x} ${point.y}`),
21
- ].join(' ');
22
- }
11
+ type Point = { x: number; y: number };
23
12
 
24
13
  const path = computed(() => {
25
- const source = { x: props.sourceX, y: props.sourceY };
26
- const target = { x: props.targetX, y: props.targetY };
14
+ // 逻辑 y 轴始终沿流程前进,输出时再换成画布坐标。
15
+ const horizontal = layoutDirection.value === 'horizontal';
16
+ const source = horizontal ? { x: props.sourceY, y: props.sourceX } : { x: props.sourceX, y: props.sourceY };
17
+ const target = horizontal ? { x: props.targetY, y: props.targetX } : { x: props.targetX, y: props.targetY };
18
+ const point = ({ x, y }: Point) => horizontal ? `${y} ${x}` : `${x} ${y}`;
19
+ const linePath = (points: Point[]) => points.map((p, i) => `${i ? 'L' : 'M'} ${point(p)}`).join(' ');
27
20
  const deltaX = target.x - source.x;
28
21
  const deltaY = target.y - source.y;
22
+ const merge = props.data?.merge && deltaY > 0;
23
+
24
+ if (lineStyle.value === 'curved') {
25
+ // 长汇入线先沿分支前进,留足弯曲空间后再汇合,避开中间卡片。
26
+ const bend = { x: source.x, y: merge ? Math.max(source.y, target.y - 160) : source.y };
27
+ const gap = target.y - bend.y;
28
+ const reach = gap > 0 ? Math.min(gap * 0.8, Math.max(gap * 0.5, Math.abs(deltaX) * 0.25)) : Math.max(40, Math.abs(gap) * 0.5);
29
+ return [
30
+ `M ${point(source)}`,
31
+ ...(bend.y !== source.y ? [`L ${point(bend)}`] : []),
32
+ `C ${point({ x: bend.x, y: bend.y + reach })} ${point({ x: target.x, y: target.y - reach })} ${point(target)}`,
33
+ ].join(' ');
34
+ }
29
35
 
30
- if (props.data?.merge && deltaY > 0) {
31
- // 同一公共节点的入边共用横线高度,不能随各分支的长度变化。
36
+ if (merge) {
32
37
  const joinY = target.y - 24;
33
38
  return linePath([source, { x: source.x, y: joinY }, { x: target.x, y: joinY }, target]);
34
39
  }
35
-
36
- if (targetData.value?.kind === 'branch') {
37
- const direction = deltaY >= 0 ? 1 : -1;
38
- const branchY = source.y + direction * Math.min(Math.max(Math.abs(deltaY) * 0.45, 18), 34);
39
- return linePath([
40
- source,
41
- { x: source.x, y: branchY },
42
- { x: target.x, y: branchY },
43
- target,
44
- ]);
45
- }
46
-
47
- if (Math.abs(deltaX) < 2) {
48
- return `M ${source.x} ${source.y} L ${target.x} ${target.y}`;
40
+ if ((props.targetNode.data as FlowGraphNodeData | undefined)?.kind === 'branch') {
41
+ const branchY = source.y + (deltaY >= 0 ? 1 : -1) * Math.min(Math.max(Math.abs(deltaY) * 0.45, 18), 34);
42
+ return linePath([source, { x: source.x, y: branchY }, { x: target.x, y: branchY }, target]);
49
43
  }
50
-
51
- const verticalGap = Math.min(Math.max(Math.abs(deltaY) * 0.38, 28), 56);
52
- const splitY = deltaY >= 0
53
- ? source.y + verticalGap
54
- : source.y - verticalGap;
55
-
56
- return linePath([
57
- source,
58
- { x: source.x, y: splitY },
59
- { x: target.x, y: splitY },
60
- target,
61
- ]);
44
+ if (Math.abs(deltaX) < 2) return linePath([source, target]);
45
+ const splitY = source.y + (deltaY >= 0 ? 1 : -1) * Math.min(Math.max(Math.abs(deltaY) * 0.38, 28), 56);
46
+ return linePath([source, { x: source.x, y: splitY }, { x: target.x, y: splitY }, target]);
62
47
  });
63
48
  </script>
64
49
 
@@ -163,7 +163,7 @@ function patchSelector(patch: Partial<AppiumSelector>) {
163
163
 
164
164
  <template>
165
165
  <div class="appium-flow-editor">
166
- <el-form label-position="top" size="small">
166
+ <el-form class="appium-flow-editor__form" label-position="left" label-width="104px" size="small">
167
167
  <LongPressSettings v-if="step.type === 'longPress'" :step="step" :disabled="disabled" @update="patchStep" />
168
168
  <el-form-item v-if="['waitActivity', 'launchApp', 'stopApp', 'clearAppData'].includes(step.type)" :label="step.type === 'waitActivity' ? '目标 Activity' : '目标 APP 包名'">
169
169
  <el-input :model-value="step.value || ''" :disabled="disabled" @update:model-value="patchStep({ value: String($event) })" />
@@ -458,19 +458,55 @@ function patchSelector(patch: Partial<AppiumSelector>) {
458
458
  </template>
459
459
 
460
460
  <style scoped>
461
+ .appium-flow-editor { --node-editor-gap: 12px; padding: 12px; }
462
+ .appium-flow-editor__form { display: grid; gap: var(--node-editor-gap); }
463
+ /* 高度动画会逐帧触发整张流程重排,子选项直接展开以保持编辑响应。 */
464
+ .appium-flow-editor :deep(.el-collapse-item__wrap) { transition: none; }
465
+ .appium-flow-editor :deep(.appium-flow-editor__section) { display: grid; gap: var(--node-editor-gap); }
466
+ .appium-flow-editor :deep(.el-collapse .el-collapse-item__content) {
467
+ display: grid;
468
+ gap: var(--node-editor-gap);
469
+ padding: 12px;
470
+ }
461
471
  .appium-flow-editor__fallback {
462
472
  display: grid;
463
- gap: 10px;
464
- margin-top: 8px;
473
+ gap: var(--node-editor-gap);
465
474
  padding-top: 12px;
466
475
  border-top: 1px solid var(--el-border-color-lighter);
467
476
  }
468
477
 
469
- .appium-flow-editor :deep(.el-form-item) { margin-bottom: 10px; }
470
-
471
- .appium-flow-editor__fallback :deep(.el-form-item) {
472
- margin-bottom: 0;
478
+ .appium-flow-editor :deep(.el-form-item),
479
+ .appium-flow-editor :deep(.ai-recognition-settings .el-form-item) { min-width: 0; margin: 0; }
480
+ .appium-flow-editor :deep(.el-form-item.is-error) { margin-bottom: 8px; }
481
+ .appium-flow-editor :deep(.el-form-item:has(> .el-form-item__label)) {
482
+ display: grid;
483
+ grid-template-columns: 100px minmax(0, 1fr);
484
+ align-items: start;
485
+ column-gap: 8px;
486
+ }
487
+ .appium-flow-editor :deep(.el-form-item > .el-form-item__label) {
488
+ justify-content: flex-start;
489
+ width: auto !important;
490
+ height: auto;
491
+ min-height: 28px;
492
+ margin: 0;
493
+ padding: 5px 0;
494
+ color: var(--ui-text-secondary);
495
+ font-size: 12px;
496
+ line-height: 18px;
497
+ overflow-wrap: anywhere;
473
498
  }
499
+ .appium-flow-editor :deep(.el-form-item > .el-form-item__content) { min-width: 0; margin-left: 0 !important; }
500
+ .appium-flow-editor :deep(.el-input-number),
501
+ .appium-flow-editor :deep(.el-select) { width: 100%; }
502
+ .appium-flow-editor :deep(.appium-flow-editor__grid),
503
+ .appium-flow-editor :deep(.ai-recognition-settings__grid) { grid-template-columns: minmax(0, 1fr); gap: var(--node-editor-gap); }
504
+ .appium-flow-editor :deep(.el-input__wrapper),
505
+ .appium-flow-editor :deep(.el-select__wrapper),
506
+ .appium-flow-editor :deep(.el-textarea__inner) { background: var(--ui-bg-soft); box-shadow: inset 0 0 0 1px var(--ui-border); }
507
+ .appium-flow-editor :deep(.el-form-item:has(.el-textarea)) { display: block; }
508
+ .appium-flow-editor :deep(.el-radio-group) { width: 100%; }
509
+ .appium-flow-editor :deep(.el-radio-button__inner) { padding: 5px 8px; font-size: 12px; }
474
510
 
475
511
  .appium-flow-editor__fallback-alert {
476
512
  padding: 8px 12px;
@@ -483,10 +519,10 @@ function patchSelector(patch: Partial<AppiumSelector>) {
483
519
 
484
520
  .appium-flow-editor__groups {
485
521
  overflow: hidden;
486
- margin-top: 8px;
522
+ margin: 0;
487
523
  border: 1px solid var(--el-border-color-lighter);
488
524
  border-radius: 10px;
489
- background: #fff;
525
+ background: var(--ui-surface);
490
526
  }
491
527
 
492
528
  .appium-flow-editor__groups :deep(.el-collapse-item__header) {
@@ -497,7 +533,6 @@ function patchSelector(patch: Partial<AppiumSelector>) {
497
533
  }
498
534
 
499
535
  .appium-flow-editor__groups :deep(.el-collapse-item__wrap) { border-bottom: 0; }
500
- .appium-flow-editor__groups :deep(.el-collapse-item__content) { padding: 8px 10px 2px; }
501
536
  .appium-flow-editor__group-title { display: flex; align-items: center; justify-content: space-between; min-width: 0; width: 100%; padding-right: 8px; gap: 8px; }
502
537
  .appium-flow-editor__group-title strong { flex: none; color: var(--ui-text); font-size: 12px; }
503
538
  .appium-flow-editor__group-title small { min-width: 0; overflow: hidden; color: var(--ui-text-muted); font-size: 11px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
@@ -23,7 +23,7 @@ function changeCoordinate(key: 'centerX' | 'centerY', value: number | undefined)
23
23
  </script>
24
24
 
25
25
  <template>
26
- <div>
26
+ <div class="appium-flow-editor__section">
27
27
  <el-form-item label="长按方式">
28
28
  <el-radio-group :model-value="mode" :disabled="disabled" @update:model-value="changeMode($event as AppiumRecordedStep['longPressMode'])">
29
29
  <el-radio-button value="element">长按元素</el-radio-button>
@@ -241,12 +241,20 @@ async function deleteSelectedNodes() {
241
241
  finally { deleting.value = false; }
242
242
  }
243
243
 
244
- watch(() => props.steps, () => { if (copyMode.value) cancelCopyMode(); });
244
+ watch(() => props.steps, (steps, previous) => {
245
+ if (copyMode.value) cancelCopyMode();
246
+ if (expandedStepIndex.value === null) return;
247
+ const id = previous[expandedStepIndex.value]?.id;
248
+ const index = steps.findIndex(step => step.id === id);
249
+ expandedStepIndex.value = index < 0 ? null : index;
250
+ });
245
251
 
246
252
  function resetMainFlowPosition() {
247
253
  mainResetViewToken.value += 1;
248
254
  }
249
255
 
256
+ defineExpose({ resetMainFlowPosition });
257
+
250
258
  function resetDialogFlowPosition() {
251
259
  dialogResetViewToken.value += 1;
252
260
  }
@@ -1,7 +1,7 @@
1
1
  import type { InjectionKey, Ref } from 'vue';
2
2
 
3
- export const DEFAULT_FLOW_BACKGROUND = '#f8fafc';
4
- export const FLOW_BACKGROUND_PRESETS = ['#f8fafc', '#d4e8dd', '#d5e6f5', '#e4dcf2', '#f2dedc', '#d5eae9', '#e8e4cc'];
3
+ export const DEFAULT_FLOW_BACKGROUND = '#f1f5f9';
4
+ export const FLOW_BACKGROUND_PRESETS = [DEFAULT_FLOW_BACKGROUND, '#d4e8dd', '#d5e6f5', '#e4dcf2', '#f2dedc', '#d5eae9', '#e8e4cc'];
5
5
  export const flowBackgroundKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowBackground');
6
6
  export const DEFAULT_FLOW_LINE_COLOR = '#94a3b8';
7
7
  export const FLOW_LINE_COLOR_PRESETS = ['#94a3b8', '#719985', '#4b83c4', '#8b6bb1', '#c78a46', '#7b8794', '#374151'];
@@ -24,3 +24,47 @@ function normalizeFlowColor(value: unknown, fallback: string) {
24
24
  const color = value.trim().toLowerCase();
25
25
  return color.length === 4 ? '#' + [...color.slice(1)].map((char) => char + char).join('') : color;
26
26
  }
27
+
28
+ export type FlowLineStyle = 'straight' | 'curved';
29
+ export const flowLineStyleKey: InjectionKey<Readonly<Ref<FlowLineStyle>>> = Symbol('flowLineStyle');
30
+
31
+ export function normalizeFlowLineStyle(value: unknown): FlowLineStyle {
32
+ return value === 'straight' ? 'straight' : 'curved';
33
+ }
34
+
35
+ export type FlowLayoutDirection = 'vertical' | 'horizontal';
36
+ export const flowLayoutDirectionKey: InjectionKey<Readonly<Ref<FlowLayoutDirection>>> = Symbol('flowLayoutDirection');
37
+
38
+ export function normalizeFlowLayoutDirection(value: unknown): FlowLayoutDirection {
39
+ return value === 'horizontal' ? 'horizontal' : 'vertical';
40
+ }
41
+
42
+ export const DEFAULT_FLOW_NODE_COLOR = '#ffffff';
43
+ export const DEFAULT_FLOW_NODE_BORDER_COLOR = '#dfe8f3';
44
+ export const flowNodeColorKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowNodeColor');
45
+ export const flowNodeBorderColorKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowNodeBorderColor');
46
+
47
+ export function normalizeFlowNodeColor(value: unknown) {
48
+ return normalizeFlowColor(value, DEFAULT_FLOW_NODE_COLOR);
49
+ }
50
+ export function normalizeFlowNodeBorderColor(value: unknown) {
51
+ return normalizeFlowColor(value, DEFAULT_FLOW_NODE_BORDER_COLOR);
52
+ }
53
+
54
+ export const FLOW_APPEARANCE_THEMES = [
55
+ { id: 'default', name: '默认浅灰', colors: { flowBackgroundColor: DEFAULT_FLOW_BACKGROUND, flowNodeColor: DEFAULT_FLOW_NODE_COLOR, flowNodeBorderColor: DEFAULT_FLOW_NODE_BORDER_COLOR, flowLineColor: DEFAULT_FLOW_LINE_COLOR } },
56
+ { id: 'blue', name: '雾蓝', colors: { flowBackgroundColor: '#eaf2fb', flowNodeColor: '#f6faff', flowNodeBorderColor: '#a8c1df', flowLineColor: '#6385b0' } },
57
+ { id: 'mint', name: '薄荷', colors: { flowBackgroundColor: '#e9f3ee', flowNodeColor: '#f5fcf8', flowNodeBorderColor: '#a2c5b2', flowLineColor: '#5d8d74' } },
58
+ { id: 'apricot', name: '暖杏', colors: { flowBackgroundColor: '#f8f0e6', flowNodeColor: '#fffaf3', flowNodeBorderColor: '#dcc3a2', flowLineColor: '#ac8256' } },
59
+ { id: 'violet', name: '浅紫', colors: { flowBackgroundColor: '#f0ecf8', flowNodeColor: '#faf8ff', flowNodeBorderColor: '#c4b4df', flowLineColor: '#9175b3' } },
60
+ { id: 'graphite', name: '石墨', colors: { flowBackgroundColor: '#191c22', flowNodeColor: '#292e38', flowNodeBorderColor: '#535e70', flowLineColor: '#a9a0d8' } },
61
+ ];
62
+ export type FlowAppearanceTheme = typeof FLOW_APPEARANCE_THEMES[number];
63
+
64
+ export function flowNodeTextColors(value: unknown) {
65
+ const color = normalizeFlowNodeColor(value);
66
+ const rgb = [1, 3, 5].map(index => parseInt(color.slice(index, index + 2), 16) / 255)
67
+ .map(channel => channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4);
68
+ const dark = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722 < 0.179;
69
+ return { dark, text: dark ? '#f1f5f9' : '#0f172a', muted: dark ? '#b7c1d1' : '#64748b' };
70
+ }