vite-uni-dev-tool 0.0.9 → 0.0.11
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 +18 -0
- package/dev/components/AppInfo/index.vue +36 -0
- package/dev/components/AutoSizer/index.vue +193 -0
- package/dev/components/AutoSizer/index1.vue +186 -0
- package/dev/components/AutoSizer/utils.ts +49 -0
- package/dev/components/CaptureScreen/index.vue +62 -0
- package/dev/components/Code/index.vue +7 -4
- package/dev/components/ConsoleList/RunJSInput.vue +177 -1
- package/dev/components/ConsoleList/index.vue +29 -19
- package/dev/components/ConsoleList/staticTips.ts +1145 -0
- package/dev/components/DevToolWindow/index.vue +225 -101
- package/dev/components/JsonPretty/components/Carets/index.vue +10 -14
- package/dev/components/JsonPretty/index.vue +50 -41
- package/dev/components/NetworkList/index.vue +16 -9
- package/dev/components/RouteList/index.vue +31 -19
- package/dev/components/Tabs/index.vue +23 -10
- package/dev/components/UploadList/index.vue +15 -5
- package/dev/components/VirtualListPro/AutoSize.vue +43 -0
- package/dev/components/VirtualListPro/index.vue +175 -0
- package/dev/components/VirtualListPro/readme.md +40 -0
- package/dev/components/WebSocket/index.vue +16 -4
- package/dev/const.ts +2 -4
- package/dev/devEvent/index.ts +29 -2
- package/dev/devIntercept/index.ts +18 -0
- package/dev/devStore/index.ts +33 -0
- package/dev/plugins/uniDevTool/uniDevTool.js +36 -36
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.js +7 -7
- package/dev/type.ts +7 -0
- package/dev/utils/array.ts +15 -0
- package/dev/utils/index.ts +3 -0
- package/dev/utils/string.ts +12 -0
- package/package.json +1 -1
|
@@ -6,11 +6,28 @@
|
|
|
6
6
|
class="run-js-input"
|
|
7
7
|
placeholder="run..."
|
|
8
8
|
@confirm="onConfirm"
|
|
9
|
+
@input="onChange"
|
|
9
10
|
/>
|
|
11
|
+
<view class="run-js-tips">
|
|
12
|
+
<view
|
|
13
|
+
class="run-js-tips-item"
|
|
14
|
+
v-for="(item, index) in tips"
|
|
15
|
+
@click="onChoose(item.name)"
|
|
16
|
+
>
|
|
17
|
+
{{ item.name }}{{ item.description ? ': ' : ' ' }}{{ item.description }}
|
|
18
|
+
</view>
|
|
19
|
+
</view>
|
|
10
20
|
</view>
|
|
11
21
|
</template>
|
|
12
22
|
<script lang="ts" setup>
|
|
13
23
|
import { ref } from 'vue';
|
|
24
|
+
import {
|
|
25
|
+
staticTips,
|
|
26
|
+
singleTips,
|
|
27
|
+
flatStaticTips,
|
|
28
|
+
baseSymbols,
|
|
29
|
+
type Tip,
|
|
30
|
+
} from './staticTips';
|
|
14
31
|
|
|
15
32
|
const emit = defineEmits<{
|
|
16
33
|
(e: 'run', value: string): void;
|
|
@@ -18,7 +35,10 @@ const emit = defineEmits<{
|
|
|
18
35
|
|
|
19
36
|
const code = ref('');
|
|
20
37
|
|
|
38
|
+
const tips = ref<Tip[]>([]);
|
|
39
|
+
|
|
21
40
|
function onConfirm() {
|
|
41
|
+
tips.value = [];
|
|
22
42
|
const value = code.value;
|
|
23
43
|
if (!value) return;
|
|
24
44
|
code.value = '';
|
|
@@ -26,6 +46,135 @@ function onConfirm() {
|
|
|
26
46
|
emit('run', value);
|
|
27
47
|
}, 100);
|
|
28
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 1.对象,方法,变量 在 ; ( , =,==,=== , + , - , * , / , && , || ?? 之后 开始提示
|
|
52
|
+
*
|
|
53
|
+
* Math
|
|
54
|
+
* console
|
|
55
|
+
*
|
|
56
|
+
* 2.在 . 之后 提示
|
|
57
|
+
*
|
|
58
|
+
* Math.a
|
|
59
|
+
* console.a
|
|
60
|
+
*
|
|
61
|
+
*
|
|
62
|
+
* 3.对方法,属性返回值进行提示
|
|
63
|
+
*
|
|
64
|
+
* Math.abc().
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
* any, void 不进行提示
|
|
68
|
+
*
|
|
69
|
+
* 4. [] 数组提示
|
|
70
|
+
*
|
|
71
|
+
* [1,2].concat([2,3].map(parseInt))
|
|
72
|
+
*
|
|
73
|
+
* 5. (值) 推断提示
|
|
74
|
+
* ({}).valueOf()
|
|
75
|
+
*
|
|
76
|
+
*
|
|
77
|
+
* @param e 输入框内容
|
|
78
|
+
*/
|
|
79
|
+
function onChange(e: any) {
|
|
80
|
+
const { value, cursor } = e.detail as { value: string; cursor: number };
|
|
81
|
+
// 光标之前的内容
|
|
82
|
+
const content = value.slice(0, cursor);
|
|
83
|
+
|
|
84
|
+
// 获取符号之后的内容
|
|
85
|
+
const lastIndex = getBaseSymbolLastIndex(content);
|
|
86
|
+
|
|
87
|
+
const con = lastIndex > -1 ? value.substring(lastIndex + 1) : value;
|
|
88
|
+
|
|
89
|
+
if (!con) {
|
|
90
|
+
// 不存在内容
|
|
91
|
+
tips.value = [];
|
|
92
|
+
} else {
|
|
93
|
+
// 存在内容
|
|
94
|
+
|
|
95
|
+
// 一级点之后的内容
|
|
96
|
+
const [main, sub] = con.split('.');
|
|
97
|
+
|
|
98
|
+
if (singleTips.includes(main) && con.includes('.')) {
|
|
99
|
+
const list = [
|
|
100
|
+
...(staticTips[main]?.attr ?? []),
|
|
101
|
+
...(staticTips[main]?.fun ?? []),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
if (sub) {
|
|
105
|
+
tips.value = list.filter((item) => item.name.startsWith(sub));
|
|
106
|
+
} else {
|
|
107
|
+
tips.value = list;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (main.includes(')') && con.includes('.')) {
|
|
111
|
+
// 方法调用之后的提示
|
|
112
|
+
|
|
113
|
+
// 获取方法名称 倒数第二个 . 到最后一个 ( 之间为方法名称
|
|
114
|
+
const s = getSecondLastDotPosition(content);
|
|
115
|
+
const e = content.lastIndexOf('(');
|
|
116
|
+
const methodName = content.substring(s + 1, e);
|
|
117
|
+
|
|
118
|
+
const fn = findFunction(methodName);
|
|
119
|
+
// 获取方法返回值
|
|
120
|
+
const result = fn?.[0]?.result?.[0];
|
|
121
|
+
if (result && result !== 'any' && result !== 'void') {
|
|
122
|
+
tips.value = Object.values(staticTips?.[result] ?? {}).flat(2);
|
|
123
|
+
} else {
|
|
124
|
+
tips.value = [];
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
// 基础提示
|
|
128
|
+
tips.value = singleTips
|
|
129
|
+
.filter((item) => item.startsWith(con))
|
|
130
|
+
.map((item) => ({
|
|
131
|
+
name: item,
|
|
132
|
+
description: '',
|
|
133
|
+
result: ['any'],
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function onChoose(name: string) {
|
|
140
|
+
// TODO 选择提示
|
|
141
|
+
// const lastIndex = code.value.lastIndexOf(';');
|
|
142
|
+
// const con =
|
|
143
|
+
// lastIndex > -1 ? code.value?.substring(lastIndex + 1) : code.value;
|
|
144
|
+
// const lastCon = con.lastIndexOf('.');
|
|
145
|
+
// if (lastCon > -1) {
|
|
146
|
+
// code.value = con.substring(0, lastCon + 1) + name;
|
|
147
|
+
// } else {
|
|
148
|
+
// code.value = name;
|
|
149
|
+
// }
|
|
150
|
+
// tips.value = [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function getBaseSymbolLastIndex(code: string) {
|
|
154
|
+
for (let i = code.length - 1; i >= 0; i--) {
|
|
155
|
+
if (baseSymbols.includes(code[i])) {
|
|
156
|
+
return i; // 找到最后一个符号的位置
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return -1; // 未找到任何符号
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function getSecondLastDotPosition(str: string) {
|
|
163
|
+
let dotCount = 0;
|
|
164
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
165
|
+
if (str[i] === '.') {
|
|
166
|
+
dotCount++;
|
|
167
|
+
if (dotCount === 2) {
|
|
168
|
+
return i;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return -1; // 未找到足够的点号
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function findFunction(fn: string) {
|
|
176
|
+
return flatStaticTips.filter((item) => item.name.startsWith(fn));
|
|
177
|
+
}
|
|
29
178
|
</script>
|
|
30
179
|
<style scoped>
|
|
31
180
|
.run-js-input-wrapper {
|
|
@@ -35,7 +184,6 @@ function onConfirm() {
|
|
|
35
184
|
min-height: 28px;
|
|
36
185
|
border-top: 1px solid var(--dev-tool-border-color);
|
|
37
186
|
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
38
|
-
overflow: hidden;
|
|
39
187
|
}
|
|
40
188
|
|
|
41
189
|
.run-js-input-icon {
|
|
@@ -56,4 +204,32 @@ function onConfirm() {
|
|
|
56
204
|
border: 1px solid transparent;
|
|
57
205
|
font-size: var(--dev-tool-base-font-size);
|
|
58
206
|
}
|
|
207
|
+
|
|
208
|
+
.run-js-tips {
|
|
209
|
+
position: absolute;
|
|
210
|
+
bottom: 31px;
|
|
211
|
+
left: 0;
|
|
212
|
+
background-color: #fff;
|
|
213
|
+
width: 100%;
|
|
214
|
+
max-height: 200px;
|
|
215
|
+
padding: 0 16px 0 36px;
|
|
216
|
+
box-sizing: border-box;
|
|
217
|
+
overflow-y: auto;
|
|
218
|
+
overflow-x: hidden;
|
|
219
|
+
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.1);
|
|
220
|
+
}
|
|
221
|
+
.run-js-tips-item {
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
height: 28px;
|
|
225
|
+
width: 100%;
|
|
226
|
+
white-space: nowrap;
|
|
227
|
+
border: 1px solid transparent;
|
|
228
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
229
|
+
overflow: hidden;
|
|
230
|
+
text-overflow: ellipsis;
|
|
231
|
+
}
|
|
232
|
+
.run-js-tips-item-active {
|
|
233
|
+
border: 1px solid var(--dev-tool-main-color);
|
|
234
|
+
}
|
|
59
235
|
</style>
|
|
@@ -12,26 +12,35 @@
|
|
|
12
12
|
:key="item.value"
|
|
13
13
|
:active="currentConsoleType === item.value"
|
|
14
14
|
@click="emit('choose', item.value)"
|
|
15
|
-
>{{ item.label }}</Tag
|
|
16
15
|
>
|
|
16
|
+
{{ item.label }}
|
|
17
|
+
</Tag>
|
|
17
18
|
</view>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
:
|
|
19
|
+
|
|
20
|
+
<VirtualListPro
|
|
21
|
+
:data="consoleList"
|
|
22
|
+
:pageSize="10"
|
|
23
|
+
:scrollIntoView="scrollIntoView"
|
|
24
|
+
:scrollWithAnimation="true"
|
|
25
|
+
className="console-list"
|
|
23
26
|
>
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
<template v-slot="{ list, start }">
|
|
28
|
+
<AutoSize
|
|
29
|
+
v-for="(item, index) in list"
|
|
30
|
+
:index="start + index"
|
|
31
|
+
:key="start + index"
|
|
32
|
+
>
|
|
33
|
+
<ConsoleItem
|
|
34
|
+
:consoleItem="item"
|
|
35
|
+
:sourceFileServers="sourceFileServers"
|
|
36
|
+
:mode="mode"
|
|
37
|
+
:useDevSource="useDevSource"
|
|
38
|
+
:id="`dev-console-${index}`"
|
|
39
|
+
/>
|
|
40
|
+
</AutoSize>
|
|
41
|
+
<Empty v-if="!consoleList || consoleList.length === 0" />
|
|
42
|
+
</template>
|
|
43
|
+
</VirtualListPro>
|
|
35
44
|
<RunJSInput @run="emit('run', $event)" />
|
|
36
45
|
</view>
|
|
37
46
|
</template>
|
|
@@ -44,6 +53,9 @@ import RunJSInput from './RunJSInput.vue';
|
|
|
44
53
|
import type { DevTool } from '../../type';
|
|
45
54
|
import { ref, watch } from 'vue';
|
|
46
55
|
import { debounce } from '../../utils';
|
|
56
|
+
import VirtualListPro from '../VirtualListPro/index.vue';
|
|
57
|
+
import AutoSize from '../VirtualListPro/AutoSize.vue';
|
|
58
|
+
|
|
47
59
|
type ConsoleType = 'all' | 'log' | 'info' | 'warn' | 'error' | 'clear';
|
|
48
60
|
const props = defineProps<{
|
|
49
61
|
consoleList: DevTool.ConsoleItem[];
|
|
@@ -93,7 +105,6 @@ const scrollIntoView = ref('');
|
|
|
93
105
|
|
|
94
106
|
const debounceWatch = debounce(() => {
|
|
95
107
|
scrollIntoView.value = `dev-console-${props.consoleList.length - 1}`;
|
|
96
|
-
console.log('props.consoleList: ', props.consoleList);
|
|
97
108
|
}, 200);
|
|
98
109
|
|
|
99
110
|
watch(() => props.consoleList, debounceWatch);
|
|
@@ -105,7 +116,6 @@ watch(() => props.consoleList, debounceWatch);
|
|
|
105
116
|
}
|
|
106
117
|
.console-list {
|
|
107
118
|
height: calc(100% - 32px - 32px);
|
|
108
|
-
overflow: auto;
|
|
109
119
|
}
|
|
110
120
|
.console-control {
|
|
111
121
|
display: flex;
|