vite-uni-dev-tool 1.0.0 → 1.1.0
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/README.md +46 -0
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +12 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +1 -1
- package/dist/core-shared.d.ts +1 -1
- package/dist/core-shared.d.ts.map +1 -1
- package/dist/core-shared.js +1 -1
- package/dist/core.d.ts +10 -3
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -2
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +81 -0
- package/dist/i18n/locales/en.d.ts.map +1 -1
- package/dist/i18n/locales/en.js +1 -1
- package/dist/i18n/locales/zh-Hans.cjs +1 -1
- package/dist/i18n/locales/zh-Hans.d.ts +82 -1
- package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/modules/devConsole/index.cjs +1 -1
- package/dist/modules/devConsole/index.js +3 -3
- package/dist/modules/devEvent/index.cjs +3 -3
- package/dist/modules/devEvent/index.d.ts +1 -0
- package/dist/modules/devEvent/index.d.ts.map +1 -1
- package/dist/modules/devEvent/index.js +3 -3
- package/dist/modules/devIntercept/index.cjs +14 -13
- package/dist/modules/devIntercept/index.d.ts +19 -0
- package/dist/modules/devIntercept/index.d.ts.map +1 -1
- package/dist/modules/devIntercept/index.js +14 -13
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts +21 -0
- package/dist/modules/devStore/index.d.ts.map +1 -1
- package/dist/modules/devStore/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.js +1 -1
- package/dist/type.d.ts +47 -2
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/language.cjs +1 -1
- package/dist/utils/language.d.ts.map +1 -1
- package/dist/utils/language.js +1 -1
- package/dist/utils/object.cjs +1 -1
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/object.js +1 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
- package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +109 -109
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +225 -224
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +247 -249
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +171 -160
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +1145 -1145
- package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
- package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +24 -24
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +197 -182
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +48 -48
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +387 -338
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +629 -549
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +197 -184
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
- package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +105 -105
- package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +106 -109
- package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +265 -265
- package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +226 -226
- package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +94 -94
- package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +49 -49
- package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +375 -375
- package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +268 -268
- package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +43 -43
- package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +485 -485
- package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +70 -70
- package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +112 -113
- package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +454 -478
- package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +56 -56
- package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +94 -98
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +624 -608
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +140 -140
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +287 -296
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +88 -93
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +163 -167
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +589 -556
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +4 -4
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +86 -86
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +160 -160
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +101 -101
- package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +498 -495
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +153 -153
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +460 -460
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +258 -258
- package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +93 -94
- package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
- package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +148 -148
- package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +97 -98
- package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +100 -104
- package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +45 -45
- package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +218 -150
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +212 -208
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +157 -119
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +74 -74
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +230 -230
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
- package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +2 -2
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +127 -116
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +609 -701
- package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +174 -174
- package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +268 -268
- package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
- package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
- package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
- package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
- package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +84 -84
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
- package/dist/v3/DevTool/index.vue +179 -5
- package/dist/v3/{AppTransition → components/AppTransition}/index.vue +176 -170
- package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +192 -192
- package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +184 -184
- package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +49 -49
- package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
- package/dist/v3/components/Barrage/index.vue +202 -0
- package/dist/v3/{CircularButton → components/CircularButton}/index.vue +84 -84
- package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +49 -49
- package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +104 -104
- package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
- package/dist/v3/{Empty → components/Empty}/index.vue +29 -29
- package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
- package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +179 -179
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +27 -27
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +59 -59
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +136 -136
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +387 -381
- package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +21 -21
- package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +21 -21
- package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
- package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +127 -126
- package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +169 -169
- package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +1 -1
- package/dist/v3/{Pick → components/Pick}/index.vue +322 -322
- package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
- package/dist/v3/{Tag → components/Tag}/index.vue +113 -113
- package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +40 -40
- package/dist/v3/{VirtualList → components/VirtualList}/index.vue +416 -412
- package/dist/v3/hooks/useBluetooth/index.ts +561 -0
- package/dist/v3/hooks/useContainerStyle.ts +153 -153
- package/dist/v3/hooks/useNFC/index.ts +107 -107
- package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
- package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
- package/dist/v3/hooks/useNFC/utils.ts +754 -754
- package/dist/v3/hooks/useRequest/index.ts +586 -573
- package/dist/v3/hooks/useRequest/utils.ts +267 -267
- package/dist/v3/hooks/useScanCode/index.ts +206 -206
- package/dist/v3/hooks/useWebsocket/README.md +79 -0
- package/dist/v3/hooks/useWebsocket/index.ts +253 -0
- package/dist/v3/styles/theme.css +17 -10
- package/dist/v3/styles/theme.ts +12 -12
- package/package.json +59 -64
- package/dist/plugins/uniParseStock/index.d.ts +0 -10
- package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
- /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
- /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
- /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
- /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将树结构扁平化并添加层级及闭合层级信息(包含闭合节点)
|
|
3
|
-
* 这个函数会为每个节点添加开始和结束标记,形成类似括号匹配的结构
|
|
4
|
-
* @param tree - 生成的树结构
|
|
5
|
-
* @param collapsedIds - 收起的节点UID集合
|
|
6
|
-
* @param result - 结果数组 (递归使用)
|
|
7
|
-
* @param level - 当前层级,默认为0
|
|
8
|
-
* @param parentUid - 父节点UID,默认为undefined
|
|
9
|
-
* @returns 扁平化的节点数组(包含闭合节点)
|
|
10
|
-
*/
|
|
11
|
-
// 栈中的项结构,用于模拟递归帧
|
|
12
|
-
type StackItem = {
|
|
13
|
-
node: InstanceTree.TreeNode;
|
|
14
|
-
level: number;
|
|
15
|
-
parentUid?: string | number;
|
|
16
|
-
processed: boolean; // false: 处理开始标记和入栈子节点; true: 处理结束标记
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function flattenTreeWithEndMarkers(
|
|
20
|
-
tree: InstanceTree.TreeNode | null,
|
|
21
|
-
expandedIds: Set<string | number>,
|
|
22
|
-
result: InstanceTree.FlattenedNodeWithEnd[] = [],
|
|
23
|
-
level: number = 0,
|
|
24
|
-
parentUid?: string | number,
|
|
25
|
-
): InstanceTree.FlattenedNodeWithEnd[] {
|
|
26
|
-
if (!tree) {
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 使用栈代替递归
|
|
31
|
-
const stack: StackItem[] = [
|
|
32
|
-
{ node: tree, level, parentUid, processed: false },
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
while (stack.length > 0) {
|
|
36
|
-
const frame = stack[stack.length - 1]; // 查看栈顶,不直接 pop
|
|
37
|
-
const { node, level, parentUid, processed } = frame;
|
|
38
|
-
|
|
39
|
-
if (processed) {
|
|
40
|
-
// 阶段2:后序处理(处理结束标记)
|
|
41
|
-
stack.pop(); // 真正移除
|
|
42
|
-
|
|
43
|
-
// 重新计算一些基本状态用于判断是否需要结束标记
|
|
44
|
-
// 注意:这些状态必须与开始标记阶段一致
|
|
45
|
-
const hasChildren =
|
|
46
|
-
(node.hasChildren ||
|
|
47
|
-
(node.children && node.children.length > 0) ||
|
|
48
|
-
(node.content !== undefined &&
|
|
49
|
-
node.content !== null &&
|
|
50
|
-
node.content !== '')) ??
|
|
51
|
-
false;
|
|
52
|
-
|
|
53
|
-
const isExpanded =
|
|
54
|
-
node.uid !== undefined ? expandedIds.has(node.uid) : false;
|
|
55
|
-
const isCollapsed = !isExpanded;
|
|
56
|
-
const isEmptyTag = !hasChildren && !isCollapsed;
|
|
57
|
-
|
|
58
|
-
// 判断内联状态 (必须完全复刻开始阶段的逻辑)
|
|
59
|
-
let isInline = false;
|
|
60
|
-
if (!isCollapsed) {
|
|
61
|
-
if (node.type === 'v-cmt') {
|
|
62
|
-
const content = node.content || '';
|
|
63
|
-
if (!content.includes('\n')) {
|
|
64
|
-
isInline = true;
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
const hasChildrenNodes = node.children && node.children.length > 0;
|
|
68
|
-
const hasContentValue =
|
|
69
|
-
node.content !== undefined &&
|
|
70
|
-
node.content !== null &&
|
|
71
|
-
node.content !== '';
|
|
72
|
-
if (hasChildrenNodes && node.children) {
|
|
73
|
-
const allText = node.children.every((c) => c.type === 'text');
|
|
74
|
-
if (allText) {
|
|
75
|
-
isInline = true;
|
|
76
|
-
}
|
|
77
|
-
} else if (hasContentValue) {
|
|
78
|
-
isInline = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 如果收起了,或是空标签,或是内联展示,就不生成结束标记
|
|
84
|
-
if (isCollapsed || isEmptyTag || isInline) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 添加结束标记
|
|
89
|
-
const endNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
90
|
-
type: node.type,
|
|
91
|
-
level: level,
|
|
92
|
-
...(node.uid !== undefined && { uid: node.uid }),
|
|
93
|
-
...(node.content !== undefined && { content: '' }),
|
|
94
|
-
...(parentUid !== undefined && { parentUid: parentUid }),
|
|
95
|
-
isEndNode: true,
|
|
96
|
-
hasChildren,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
if (endNode.type || endNode.content) {
|
|
100
|
-
result.push(endNode);
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
// 阶段1:前序处理(生成开始标记,处理内容,将子节点入栈)
|
|
104
|
-
frame.processed = true; // 标记为已处理过开始阶段,下次循环处理结束阶段
|
|
105
|
-
|
|
106
|
-
const hasChildren =
|
|
107
|
-
(node.hasChildren ||
|
|
108
|
-
(node.children && node.children.length > 0) ||
|
|
109
|
-
(node.content !== undefined &&
|
|
110
|
-
node.content !== null &&
|
|
111
|
-
node.content !== '')) ??
|
|
112
|
-
false;
|
|
113
|
-
|
|
114
|
-
const isExpanded =
|
|
115
|
-
node.uid !== undefined ? expandedIds.has(node.uid) : false;
|
|
116
|
-
const isCollapsed = !isExpanded;
|
|
117
|
-
const isEmptyTag = !hasChildren && !isCollapsed;
|
|
118
|
-
|
|
119
|
-
let isInline = false;
|
|
120
|
-
let inlineContent = '';
|
|
121
|
-
if (!isCollapsed) {
|
|
122
|
-
if (node.type === 'v-cmt') {
|
|
123
|
-
const content = node.content || '';
|
|
124
|
-
if (!content.includes('\n')) {
|
|
125
|
-
isInline = true;
|
|
126
|
-
inlineContent = content;
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
const hasChildrenNodes = node.children && node.children.length > 0;
|
|
130
|
-
const hasContentValue =
|
|
131
|
-
node.content !== undefined &&
|
|
132
|
-
node.content !== null &&
|
|
133
|
-
node.content !== '';
|
|
134
|
-
|
|
135
|
-
if (hasChildrenNodes && node.children) {
|
|
136
|
-
const allText = node.children.every((c) => c.type === 'text');
|
|
137
|
-
if (allText) {
|
|
138
|
-
isInline = true;
|
|
139
|
-
inlineContent = node.children
|
|
140
|
-
.map((c) => c.content || '')
|
|
141
|
-
.join('');
|
|
142
|
-
}
|
|
143
|
-
} else if (hasContentValue) {
|
|
144
|
-
isInline = true;
|
|
145
|
-
inlineContent = node.content!;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 生成开始标记
|
|
151
|
-
const startNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
152
|
-
type: node.type,
|
|
153
|
-
level: level,
|
|
154
|
-
...(node.uid !== undefined && { uid: node.uid }),
|
|
155
|
-
...(node.content !== undefined && { content: '' }),
|
|
156
|
-
...(parentUid !== undefined && { parentUid: parentUid }),
|
|
157
|
-
isStartNode: true,
|
|
158
|
-
hasChildren: node.type === 'v-cmt' || isInline ? false : hasChildren,
|
|
159
|
-
isCollapsed,
|
|
160
|
-
isEmptyTag,
|
|
161
|
-
isInline,
|
|
162
|
-
inlineContent,
|
|
163
|
-
props: node.props,
|
|
164
|
-
styles: node.styles,
|
|
165
|
-
other: node.other,
|
|
166
|
-
provides: node.provides,
|
|
167
|
-
data: node.data,
|
|
168
|
-
functions: node.functions,
|
|
169
|
-
emits: node.emits,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
if (startNode.type || startNode.content) {
|
|
173
|
-
result.push(startNode);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (isCollapsed || isEmptyTag || isInline) {
|
|
177
|
-
// 不需要处理子节点,直接移除栈顶项(其实就是刚才的 frame),因为不需要后序处理结束标记了
|
|
178
|
-
// 注意:这里需要把刚刚标记为 true 的 frame 彻底 pop 掉
|
|
179
|
-
// 但为了简单,可以在这里直接 continue,并且因为 frame.processed 已经是 true,
|
|
180
|
-
// 下次循环会进入上面的 if(processed) 分支。
|
|
181
|
-
// 为了不在那里重复计算 isInline 等逻辑,我们在那里也加了检查。
|
|
182
|
-
// 不过更高效的做法是如果这里决定不再深入,直接 pop。
|
|
183
|
-
stack.pop();
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 处理多行内容节点
|
|
188
|
-
if (
|
|
189
|
-
node.content !== undefined &&
|
|
190
|
-
node.content !== null &&
|
|
191
|
-
node.content !== ''
|
|
192
|
-
) {
|
|
193
|
-
const content = node.content || '';
|
|
194
|
-
const lines = content.split('\n');
|
|
195
|
-
// 是否有 startNode 决定了 level 偏移
|
|
196
|
-
const hasStart = !!(startNode.type || startNode.content);
|
|
197
|
-
|
|
198
|
-
lines.forEach((line) => {
|
|
199
|
-
const contentNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
200
|
-
type: node.type,
|
|
201
|
-
level: level + (hasStart ? 1 : 0),
|
|
202
|
-
content: line,
|
|
203
|
-
parentUid: node.uid,
|
|
204
|
-
isContentNode: true,
|
|
205
|
-
};
|
|
206
|
-
result.push(contentNode);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// 将子节点入栈 (注意:栈是后进先出,所以要逆序入栈,从而保证正序处理)
|
|
211
|
-
if (node.children && node.children.length > 0) {
|
|
212
|
-
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
213
|
-
const child = node.children[i];
|
|
214
|
-
stack.push({
|
|
215
|
-
node: child,
|
|
216
|
-
level: level + 1,
|
|
217
|
-
parentUid: node.uid,
|
|
218
|
-
processed: false,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 将树结构扁平化并添加层级及闭合层级信息(包含闭合节点)
|
|
3
|
+
* 这个函数会为每个节点添加开始和结束标记,形成类似括号匹配的结构
|
|
4
|
+
* @param tree - 生成的树结构
|
|
5
|
+
* @param collapsedIds - 收起的节点UID集合
|
|
6
|
+
* @param result - 结果数组 (递归使用)
|
|
7
|
+
* @param level - 当前层级,默认为0
|
|
8
|
+
* @param parentUid - 父节点UID,默认为undefined
|
|
9
|
+
* @returns 扁平化的节点数组(包含闭合节点)
|
|
10
|
+
*/
|
|
11
|
+
// 栈中的项结构,用于模拟递归帧
|
|
12
|
+
type StackItem = {
|
|
13
|
+
node: InstanceTree.TreeNode;
|
|
14
|
+
level: number;
|
|
15
|
+
parentUid?: string | number;
|
|
16
|
+
processed: boolean; // false: 处理开始标记和入栈子节点; true: 处理结束标记
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function flattenTreeWithEndMarkers(
|
|
20
|
+
tree: InstanceTree.TreeNode | null,
|
|
21
|
+
expandedIds: Set<string | number>,
|
|
22
|
+
result: InstanceTree.FlattenedNodeWithEnd[] = [],
|
|
23
|
+
level: number = 0,
|
|
24
|
+
parentUid?: string | number,
|
|
25
|
+
): InstanceTree.FlattenedNodeWithEnd[] {
|
|
26
|
+
if (!tree) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 使用栈代替递归
|
|
31
|
+
const stack: StackItem[] = [
|
|
32
|
+
{ node: tree, level, parentUid, processed: false },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const frame = stack[stack.length - 1]; // 查看栈顶,不直接 pop
|
|
37
|
+
const { node, level, parentUid, processed } = frame;
|
|
38
|
+
|
|
39
|
+
if (processed) {
|
|
40
|
+
// 阶段2:后序处理(处理结束标记)
|
|
41
|
+
stack.pop(); // 真正移除
|
|
42
|
+
|
|
43
|
+
// 重新计算一些基本状态用于判断是否需要结束标记
|
|
44
|
+
// 注意:这些状态必须与开始标记阶段一致
|
|
45
|
+
const hasChildren =
|
|
46
|
+
(node.hasChildren ||
|
|
47
|
+
(node.children && node.children.length > 0) ||
|
|
48
|
+
(node.content !== undefined &&
|
|
49
|
+
node.content !== null &&
|
|
50
|
+
node.content !== '')) ??
|
|
51
|
+
false;
|
|
52
|
+
|
|
53
|
+
const isExpanded =
|
|
54
|
+
node.uid !== undefined ? expandedIds.has(node.uid) : false;
|
|
55
|
+
const isCollapsed = !isExpanded;
|
|
56
|
+
const isEmptyTag = !hasChildren && !isCollapsed;
|
|
57
|
+
|
|
58
|
+
// 判断内联状态 (必须完全复刻开始阶段的逻辑)
|
|
59
|
+
let isInline = false;
|
|
60
|
+
if (!isCollapsed) {
|
|
61
|
+
if (node.type === 'v-cmt') {
|
|
62
|
+
const content = node.content || '';
|
|
63
|
+
if (!content.includes('\n')) {
|
|
64
|
+
isInline = true;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const hasChildrenNodes = node.children && node.children.length > 0;
|
|
68
|
+
const hasContentValue =
|
|
69
|
+
node.content !== undefined &&
|
|
70
|
+
node.content !== null &&
|
|
71
|
+
node.content !== '';
|
|
72
|
+
if (hasChildrenNodes && node.children) {
|
|
73
|
+
const allText = node.children.every((c) => c.type === 'text');
|
|
74
|
+
if (allText) {
|
|
75
|
+
isInline = true;
|
|
76
|
+
}
|
|
77
|
+
} else if (hasContentValue) {
|
|
78
|
+
isInline = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 如果收起了,或是空标签,或是内联展示,就不生成结束标记
|
|
84
|
+
if (isCollapsed || isEmptyTag || isInline) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 添加结束标记
|
|
89
|
+
const endNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
90
|
+
type: node.type,
|
|
91
|
+
level: level,
|
|
92
|
+
...(node.uid !== undefined && { uid: node.uid }),
|
|
93
|
+
...(node.content !== undefined && { content: '' }),
|
|
94
|
+
...(parentUid !== undefined && { parentUid: parentUid }),
|
|
95
|
+
isEndNode: true,
|
|
96
|
+
hasChildren,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (endNode.type || endNode.content) {
|
|
100
|
+
result.push(endNode);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
// 阶段1:前序处理(生成开始标记,处理内容,将子节点入栈)
|
|
104
|
+
frame.processed = true; // 标记为已处理过开始阶段,下次循环处理结束阶段
|
|
105
|
+
|
|
106
|
+
const hasChildren =
|
|
107
|
+
(node.hasChildren ||
|
|
108
|
+
(node.children && node.children.length > 0) ||
|
|
109
|
+
(node.content !== undefined &&
|
|
110
|
+
node.content !== null &&
|
|
111
|
+
node.content !== '')) ??
|
|
112
|
+
false;
|
|
113
|
+
|
|
114
|
+
const isExpanded =
|
|
115
|
+
node.uid !== undefined ? expandedIds.has(node.uid) : false;
|
|
116
|
+
const isCollapsed = !isExpanded;
|
|
117
|
+
const isEmptyTag = !hasChildren && !isCollapsed;
|
|
118
|
+
|
|
119
|
+
let isInline = false;
|
|
120
|
+
let inlineContent = '';
|
|
121
|
+
if (!isCollapsed) {
|
|
122
|
+
if (node.type === 'v-cmt') {
|
|
123
|
+
const content = node.content || '';
|
|
124
|
+
if (!content.includes('\n')) {
|
|
125
|
+
isInline = true;
|
|
126
|
+
inlineContent = content;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
const hasChildrenNodes = node.children && node.children.length > 0;
|
|
130
|
+
const hasContentValue =
|
|
131
|
+
node.content !== undefined &&
|
|
132
|
+
node.content !== null &&
|
|
133
|
+
node.content !== '';
|
|
134
|
+
|
|
135
|
+
if (hasChildrenNodes && node.children) {
|
|
136
|
+
const allText = node.children.every((c) => c.type === 'text');
|
|
137
|
+
if (allText) {
|
|
138
|
+
isInline = true;
|
|
139
|
+
inlineContent = node.children
|
|
140
|
+
.map((c) => c.content || '')
|
|
141
|
+
.join('');
|
|
142
|
+
}
|
|
143
|
+
} else if (hasContentValue) {
|
|
144
|
+
isInline = true;
|
|
145
|
+
inlineContent = node.content!;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 生成开始标记
|
|
151
|
+
const startNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
152
|
+
type: node.type,
|
|
153
|
+
level: level,
|
|
154
|
+
...(node.uid !== undefined && { uid: node.uid }),
|
|
155
|
+
...(node.content !== undefined && { content: '' }),
|
|
156
|
+
...(parentUid !== undefined && { parentUid: parentUid }),
|
|
157
|
+
isStartNode: true,
|
|
158
|
+
hasChildren: node.type === 'v-cmt' || isInline ? false : hasChildren,
|
|
159
|
+
isCollapsed,
|
|
160
|
+
isEmptyTag,
|
|
161
|
+
isInline,
|
|
162
|
+
inlineContent,
|
|
163
|
+
props: node.props,
|
|
164
|
+
styles: node.styles,
|
|
165
|
+
other: node.other,
|
|
166
|
+
provides: node.provides,
|
|
167
|
+
data: node.data,
|
|
168
|
+
functions: node.functions,
|
|
169
|
+
emits: node.emits,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (startNode.type || startNode.content) {
|
|
173
|
+
result.push(startNode);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (isCollapsed || isEmptyTag || isInline) {
|
|
177
|
+
// 不需要处理子节点,直接移除栈顶项(其实就是刚才的 frame),因为不需要后序处理结束标记了
|
|
178
|
+
// 注意:这里需要把刚刚标记为 true 的 frame 彻底 pop 掉
|
|
179
|
+
// 但为了简单,可以在这里直接 continue,并且因为 frame.processed 已经是 true,
|
|
180
|
+
// 下次循环会进入上面的 if(processed) 分支。
|
|
181
|
+
// 为了不在那里重复计算 isInline 等逻辑,我们在那里也加了检查。
|
|
182
|
+
// 不过更高效的做法是如果这里决定不再深入,直接 pop。
|
|
183
|
+
stack.pop();
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 处理多行内容节点
|
|
188
|
+
if (
|
|
189
|
+
node.content !== undefined &&
|
|
190
|
+
node.content !== null &&
|
|
191
|
+
node.content !== ''
|
|
192
|
+
) {
|
|
193
|
+
const content = node.content || '';
|
|
194
|
+
const lines = content.split('\n');
|
|
195
|
+
// 是否有 startNode 决定了 level 偏移
|
|
196
|
+
const hasStart = !!(startNode.type || startNode.content);
|
|
197
|
+
|
|
198
|
+
lines.forEach((line) => {
|
|
199
|
+
const contentNode: InstanceTree.FlattenedNodeWithEnd = {
|
|
200
|
+
type: node.type,
|
|
201
|
+
level: level + (hasStart ? 1 : 0),
|
|
202
|
+
content: line,
|
|
203
|
+
parentUid: node.uid,
|
|
204
|
+
isContentNode: true,
|
|
205
|
+
};
|
|
206
|
+
result.push(contentNode);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 将子节点入栈 (注意:栈是后进先出,所以要逆序入栈,从而保证正序处理)
|
|
211
|
+
if (node.children && node.children.length > 0) {
|
|
212
|
+
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
213
|
+
const child = node.children[i];
|
|
214
|
+
stack.push({
|
|
215
|
+
node: child,
|
|
216
|
+
level: level + 1,
|
|
217
|
+
parentUid: node.uid,
|
|
218
|
+
processed: false,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<VirtualList
|
|
3
|
-
:data="flatData"
|
|
4
|
-
:pageSize="pageSize"
|
|
5
|
-
:height="height"
|
|
6
|
-
:itemHeight="itemHeight"
|
|
7
|
-
scroll-with-animation
|
|
8
|
-
showBackTop
|
|
9
|
-
:dataChangeScrollToTop="false"
|
|
10
|
-
scrollX>
|
|
11
|
-
<template v-slot="{ list, start }">
|
|
12
|
-
<InstanceTreeNode
|
|
13
|
-
v-for="(item, index) in list"
|
|
14
|
-
:key="start + index"
|
|
15
|
-
:style="{ height: '20px' }"
|
|
16
|
-
:showLine="showLine"
|
|
17
|
-
:node="item"
|
|
18
|
-
:isActive="selectedUid === item.uid"
|
|
19
|
-
@toggle="onToggle"
|
|
20
|
-
@select="handleSelect" />
|
|
21
|
-
</template>
|
|
22
|
-
</VirtualList>
|
|
23
|
-
</template>
|
|
24
|
-
<script lang="ts" setup>
|
|
25
|
-
import VirtualList from '
|
|
26
|
-
import InstanceTreeNode from './components/InstanceTreeNode.vue';
|
|
27
|
-
import { computed, ref, markRaw, shallowRef, watch } from 'vue';
|
|
28
|
-
import { simpleTreeCtx, resetUidCount } from './transformTreeCtx';
|
|
29
|
-
import { flattenTreeWithEndMarkers } from './flatten';
|
|
30
|
-
|
|
31
|
-
const props = withDefaults(
|
|
32
|
-
defineProps<{
|
|
33
|
-
data: any;
|
|
34
|
-
pageSize?: number;
|
|
35
|
-
height?: number | string;
|
|
36
|
-
showLine?: boolean;
|
|
37
|
-
itemHeight?: number;
|
|
38
|
-
}>(),
|
|
39
|
-
{
|
|
40
|
-
pageSize: 30,
|
|
41
|
-
height: 400,
|
|
42
|
-
showLine: false,
|
|
43
|
-
itemHeight: 20,
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const emit = defineEmits<{
|
|
48
|
-
(e: 'select', node: any): void;
|
|
49
|
-
}>();
|
|
50
|
-
|
|
51
|
-
const expandedIds = ref<Set<string | number>>(new Set());
|
|
52
|
-
const selectedUid = ref<string | number | undefined>(undefined);
|
|
53
|
-
|
|
54
|
-
const handleSelect = (node: any) => {
|
|
55
|
-
selectedUid.value = node.uid;
|
|
56
|
-
emit('select', node);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const onToggle = (uid: string | number) => {
|
|
60
|
-
if (expandedIds.value.has(uid)) {
|
|
61
|
-
expandedIds.value.delete(uid);
|
|
62
|
-
} else {
|
|
63
|
-
expandedIds.value.add(uid);
|
|
64
|
-
}
|
|
65
|
-
expandedIds.value = new Set(expandedIds.value); // 触发响应式更新
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const treeData = shallowRef<InstanceTree.TreeNode | null>(null);
|
|
69
|
-
|
|
70
|
-
watch(
|
|
71
|
-
() => props.data,
|
|
72
|
-
(val) => {
|
|
73
|
-
resetUidCount();
|
|
74
|
-
const tree = simpleTreeCtx(val) as any;
|
|
75
|
-
|
|
76
|
-
// 默认展开第一层
|
|
77
|
-
if (tree && tree.uid && expandedIds.value.size === 0) {
|
|
78
|
-
expandedIds.value.add(tree.uid);
|
|
79
|
-
expandedIds.value = new Set(expandedIds.value);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
treeData.value = tree ? markRaw(tree) : null;
|
|
83
|
-
},
|
|
84
|
-
{ immediate: true },
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const flatData = computed(() => {
|
|
88
|
-
if (!treeData.value) return [];
|
|
89
|
-
const result: InstanceTree.FlattenedNodeWithEnd[] = [];
|
|
90
|
-
flattenTreeWithEndMarkers(treeData.value, expandedIds.value, result);
|
|
91
|
-
return markRaw(result);
|
|
92
|
-
});
|
|
93
|
-
</script>
|
|
94
|
-
<style scoped></style>
|
|
1
|
+
<template>
|
|
2
|
+
<VirtualList
|
|
3
|
+
:data="flatData"
|
|
4
|
+
:pageSize="pageSize"
|
|
5
|
+
:height="height"
|
|
6
|
+
:itemHeight="itemHeight"
|
|
7
|
+
scroll-with-animation
|
|
8
|
+
showBackTop
|
|
9
|
+
:dataChangeScrollToTop="false"
|
|
10
|
+
scrollX>
|
|
11
|
+
<template v-slot="{ list, start }">
|
|
12
|
+
<InstanceTreeNode
|
|
13
|
+
v-for="(item, index) in list"
|
|
14
|
+
:key="start + index"
|
|
15
|
+
:style="{ height: '20px' }"
|
|
16
|
+
:showLine="showLine"
|
|
17
|
+
:node="item"
|
|
18
|
+
:isActive="selectedUid === item.uid"
|
|
19
|
+
@toggle="onToggle"
|
|
20
|
+
@select="handleSelect" />
|
|
21
|
+
</template>
|
|
22
|
+
</VirtualList>
|
|
23
|
+
</template>
|
|
24
|
+
<script lang="ts" setup>
|
|
25
|
+
import VirtualList from '../../../components/VirtualList/index.vue';
|
|
26
|
+
import InstanceTreeNode from './components/InstanceTreeNode.vue';
|
|
27
|
+
import { computed, ref, markRaw, shallowRef, watch } from 'vue';
|
|
28
|
+
import { simpleTreeCtx, resetUidCount } from './transformTreeCtx';
|
|
29
|
+
import { flattenTreeWithEndMarkers } from './flatten';
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
data: any;
|
|
34
|
+
pageSize?: number;
|
|
35
|
+
height?: number | string;
|
|
36
|
+
showLine?: boolean;
|
|
37
|
+
itemHeight?: number;
|
|
38
|
+
}>(),
|
|
39
|
+
{
|
|
40
|
+
pageSize: 30,
|
|
41
|
+
height: 400,
|
|
42
|
+
showLine: false,
|
|
43
|
+
itemHeight: 20,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits<{
|
|
48
|
+
(e: 'select', node: any): void;
|
|
49
|
+
}>();
|
|
50
|
+
|
|
51
|
+
const expandedIds = ref<Set<string | number>>(new Set());
|
|
52
|
+
const selectedUid = ref<string | number | undefined>(undefined);
|
|
53
|
+
|
|
54
|
+
const handleSelect = (node: any) => {
|
|
55
|
+
selectedUid.value = node.uid;
|
|
56
|
+
emit('select', node);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const onToggle = (uid: string | number) => {
|
|
60
|
+
if (expandedIds.value.has(uid)) {
|
|
61
|
+
expandedIds.value.delete(uid);
|
|
62
|
+
} else {
|
|
63
|
+
expandedIds.value.add(uid);
|
|
64
|
+
}
|
|
65
|
+
expandedIds.value = new Set(expandedIds.value); // 触发响应式更新
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const treeData = shallowRef<InstanceTree.TreeNode | null>(null);
|
|
69
|
+
|
|
70
|
+
watch(
|
|
71
|
+
() => props.data,
|
|
72
|
+
(val) => {
|
|
73
|
+
resetUidCount();
|
|
74
|
+
const tree = simpleTreeCtx(val) as any;
|
|
75
|
+
|
|
76
|
+
// 默认展开第一层
|
|
77
|
+
if (tree && tree.uid && expandedIds.value.size === 0) {
|
|
78
|
+
expandedIds.value.add(tree.uid);
|
|
79
|
+
expandedIds.value = new Set(expandedIds.value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
treeData.value = tree ? markRaw(tree) : null;
|
|
83
|
+
},
|
|
84
|
+
{ immediate: true },
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const flatData = computed(() => {
|
|
88
|
+
if (!treeData.value) return [];
|
|
89
|
+
const result: InstanceTree.FlattenedNodeWithEnd[] = [];
|
|
90
|
+
flattenTreeWithEndMarkers(treeData.value, expandedIds.value, result);
|
|
91
|
+
return markRaw(result);
|
|
92
|
+
});
|
|
93
|
+
</script>
|
|
94
|
+
<style scoped></style>
|