vite-uni-dev-tool 1.1.0 → 1.2.1
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 +21 -1
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +2 -1
- package/dist/const.js +1 -1
- package/dist/core-shared.d.ts +2 -3
- package/dist/core.d.ts +8 -8
- package/dist/core.js +2 -2
- package/dist/i18n/index.d.ts +0 -1
- package/dist/i18n/instance.d.ts +0 -1
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +6 -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 +6 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/modules/devConsole/index.cjs +4 -4
- package/dist/modules/devConsole/index.d.ts +6 -107
- package/dist/modules/devConsole/index.js +4 -4
- package/dist/modules/devEvent/index.cjs +3 -3
- package/dist/modules/devEvent/index.d.ts +2 -3
- package/dist/modules/devEvent/index.js +3 -3
- package/dist/modules/devIntercept/index.cjs +14 -14
- package/dist/modules/devIntercept/index.d.ts +34 -6
- package/dist/modules/devIntercept/index.js +14 -14
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts +48 -40
- package/dist/modules/devStore/index.js +1 -1
- package/dist/modules/devToolInfo/index.cjs +1 -1
- package/dist/modules/devToolInfo/index.d.ts +6 -25
- package/dist/modules/devToolInfo/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformApp.d.ts +0 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -2
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -2
- package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
- package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -2
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -1
- package/dist/plugins/utils/index.d.ts +0 -1
- package/dist/shims-uni.d.ts +26 -22
- package/dist/type.d.ts +47 -43
- package/dist/utils/array.d.ts +0 -1
- package/dist/utils/date.d.ts +0 -1
- package/dist/utils/file.d.ts +0 -1
- package/dist/utils/function.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/ip.d.ts +0 -1
- package/dist/utils/language.d.ts +14 -15
- package/dist/utils/object.cjs +1 -1
- package/dist/utils/object.d.ts +7 -8
- package/dist/utils/object.js +1 -1
- package/dist/utils/openLink.d.ts +0 -1
- package/dist/utils/page.d.ts +0 -1
- package/dist/utils/platform.d.ts +0 -1
- package/dist/utils/string.d.ts +0 -1
- package/dist/utils/utils.d.ts +0 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
- package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
- package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
- package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
- package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
- package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
- package/dist/v3/DevTool/components/DevToolButton/index.vue +42 -6
- package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
- package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
- package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +411 -387
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +644 -629
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
- package/dist/v3/DevTool/components/DevToolWindow/index.vue +27 -64
- package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
- package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
- package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
- package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
- package/dist/v3/DevTool/components/Instance/index.vue +94 -94
- package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
- package/dist/v3/DevTool/components/Instance/transformTree.ts +393 -375
- package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
- package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
- package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
- package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
- package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
- package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
- package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
- package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
- package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
- package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
- package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
- package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
- package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
- package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
- package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
- package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
- package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
- package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
- package/dist/v3/DevTool/components/Performance/index.vue +498 -498
- package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
- package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
- package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
- package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
- package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
- package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
- package/dist/v3/DevTool/components/SettingList/index.vue +226 -218
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +320 -304
- package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
- package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
- package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
- package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
- package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
- package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
- package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
- package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
- package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
- package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
- package/dist/v3/DevTool/index.vue +85 -138
- package/dist/v3/components/AppTransition/index.vue +156 -176
- package/dist/v3/components/AutoSizer/index.vue +192 -192
- package/dist/v3/components/AutoSizer/index1.vue +184 -184
- package/dist/v3/components/AutoSizer/utils.ts +49 -49
- package/dist/v3/components/Barrage/BarrageItem.vue +194 -137
- package/dist/v3/components/Barrage/index.vue +205 -202
- package/dist/v3/components/CircularButton/index.vue +84 -84
- package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
- package/dist/v3/components/CustomSwiper/index.vue +104 -104
- package/dist/v3/components/DevErrorBoundary/index.vue +388 -0
- package/dist/v3/components/DraggableContainer/index.vue +186 -73
- package/dist/v3/components/Empty/index.vue +29 -29
- package/dist/v3/components/FilterSelect/index.vue +179 -179
- package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
- package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
- package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
- package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
- package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
- package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
- package/dist/v3/components/JsonPretty/type.ts +127 -127
- package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
- package/dist/v3/components/MovableContainer/index.vue +10 -4
- package/dist/v3/components/Pick/index.vue +321 -322
- package/dist/v3/components/Tag/index.vue +113 -113
- package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
- package/dist/v3/components/VirtualList/index.vue +416 -416
- package/dist/v3/hooks/useBluetooth/index.ts +561 -561
- package/dist/v3/hooks/useContainerStyle.ts +95 -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 -586
- package/dist/v3/hooks/useRequest/utils.ts +267 -267
- package/dist/v3/hooks/useScanCode/index.ts +206 -206
- package/dist/v3/hooks/useWebsocket/index.ts +253 -253
- package/dist/v3/styles/theme.ts +12 -12
- package/package.json +70 -59
- package/dist/const.d.ts.map +0 -1
- package/dist/core-shared.d.ts.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/i18n/index.d.ts.map +0 -1
- package/dist/i18n/instance.d.ts.map +0 -1
- package/dist/i18n/locales/en.d.ts.map +0 -1
- package/dist/i18n/locales/zh-Hans.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/modules/devConsole/index.d.ts.map +0 -1
- package/dist/modules/devEvent/index.d.ts.map +0 -1
- package/dist/modules/devIntercept/index.d.ts.map +0 -1
- package/dist/modules/devStore/index.d.ts.map +0 -1
- package/dist/modules/devToolInfo/index.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformApp.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +0 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -1
- package/dist/plugins/utils/index.d.ts.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/utils/array.d.ts.map +0 -1
- package/dist/utils/date.d.ts.map +0 -1
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/function.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/ip.d.ts.map +0 -1
- package/dist/utils/language.d.ts.map +0 -1
- package/dist/utils/object.d.ts.map +0 -1
- package/dist/utils/openLink.d.ts.map +0 -1
- package/dist/utils/page.d.ts.map +0 -1
- package/dist/utils/platform.d.ts.map +0 -1
- package/dist/utils/string.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
|
@@ -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 '../../../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>
|
|
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>
|