vite-uni-dev-tool 0.0.10 → 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 CHANGED
@@ -151,6 +151,16 @@ uni.__dev__console.log('hello vite-uni-dev-tool');
151
151
 
152
152
  ## 更新日志
153
153
 
154
+ ### 0.0.11
155
+
156
+ - 新增 console run 简易提示
157
+ - 新增 appInfo
158
+ - 新增 captureScreen(h5端不支持)
159
+ - 新增滑动切换
160
+ - 修复 console 滚动到指定位置
161
+ - 修复调用栈起始行
162
+ - 修复 json pretty 折叠icon
163
+
154
164
  ### 0.0.10
155
165
 
156
166
  - 修复 console 过滤异常
@@ -0,0 +1,36 @@
1
+ <template>
2
+ <view class="app-info-content">
3
+ <JsonPretty v-if="showJson" :data="appInfo" />
4
+ <Empty v-else />
5
+ </view>
6
+ </template>
7
+ <script lang="ts" setup>
8
+ import { computed } from 'vue';
9
+ import JsonPretty from '../JsonPretty/index.vue';
10
+
11
+ import Empty from '../Empty/index.vue';
12
+ const props = defineProps<{
13
+ appInfo: Record<string, any>;
14
+ }>();
15
+
16
+ const showJson = computed(() => {
17
+ try {
18
+ const str = JSON.stringify(props.appInfo);
19
+ if (typeof props.appInfo === 'object' && (str === '' || str === '{}')) {
20
+ return false;
21
+ }
22
+ return true;
23
+ } catch (error) {
24
+ return false;
25
+ }
26
+ });
27
+ </script>
28
+ <style scoped>
29
+ .app-info-content {
30
+ padding: 16px;
31
+ font-size: var(--dev-tool-base-font-size);
32
+
33
+ height: calc(100% - 32px);
34
+ overflow: auto;
35
+ }
36
+ </style>
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <view class="capture-screen-content">
3
+ <view class="capture-screen-control">
4
+ <Tag style="margin-left: auto" mode="clear" @click="emit('clear')">
5
+ 清空
6
+ </Tag>
7
+ </view>
8
+
9
+ <view class="capture-screen-list">
10
+ <view class="capture-screen-item" v-for="item in captureScreenList">
11
+ <view class="info-row">时间:{{ item.timer }} </view>
12
+ <view class="info-row">页面:{{ item.position }}</view>
13
+ </view>
14
+
15
+ <Empty v-if="!captureScreenList || captureScreenList.length === 0" />
16
+ </view>
17
+ </view>
18
+ </template>
19
+ <script lang="ts" setup>
20
+ import type { DevTool } from '../../type';
21
+ import Empty from '../Empty/index.vue';
22
+ import Tag from '../Tag/index.vue';
23
+
24
+ defineProps<{
25
+ captureScreenList: DevTool.CaptureScreenItem[];
26
+ }>();
27
+
28
+ const emit = defineEmits<{
29
+ (e: 'clear'): void;
30
+ }>();
31
+ </script>
32
+ <style scoped>
33
+ .capture-screen-content {
34
+ height: 100%;
35
+ font-size: var(--dev-tool-base-font-size);
36
+ }
37
+
38
+ .capture-screen-list {
39
+ height: calc(100% - 32px);
40
+ overflow: auto;
41
+ }
42
+
43
+ .capture-screen-control {
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: space-between;
47
+ gap: 8px;
48
+ padding: 0 16px;
49
+ height: 32px;
50
+ border-bottom: 1px solid var(--dev-tool-border-color);
51
+ box-sizing: border-box;
52
+ }
53
+
54
+ .capture-screen-item {
55
+ padding: 16px;
56
+ border-bottom: 1px solid var(--dev-tool-border-color);
57
+ }
58
+ .info-row {
59
+ height: 28px;
60
+ line-height: 28px;
61
+ }
62
+ </style>
@@ -23,7 +23,9 @@
23
23
  :key="index"
24
24
  :class="`dev-tool-code-item ${index === activeRowCol.activeRow ? 'dev-tool-code-item-active' : ''}`"
25
25
  >
26
- <view class="dev-tool-code-item-index"> {{ index + 1 }}</view>
26
+ <view class="dev-tool-code-item-index">
27
+ {{ start + index + 1 }}
28
+ </view>
27
29
 
28
30
  <view class="dev-tool-code-item-content" v-html="code"></view>
29
31
  </view>
@@ -62,6 +64,10 @@ const codes = ref<string[]>([]);
62
64
 
63
65
  const scrollIntoView = ref('');
64
66
 
67
+ const start = computed(() => {
68
+ return activeRowCol.value.row - 20 > 0 ? activeRowCol.value.row - 20 : 0;
69
+ });
70
+
65
71
  function onClose() {
66
72
  emit('close');
67
73
  }
@@ -172,9 +178,6 @@ onMounted(() => {
172
178
  top: 0;
173
179
  left: 0;
174
180
  padding: 0 16px;
175
- /* #ifdef H5 */
176
- padding: 50px 16px;
177
- /* #endif */
178
181
 
179
182
  background-color: rgba(255, 255, 255, 0.95);
180
183
  box-sizing: border-box;
@@ -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>
@@ -17,7 +17,13 @@
17
17
  </Tag>
18
18
  </view>
19
19
 
20
- <VirtualListPro :data="consoleList" :pageSize="10" className="console-list">
20
+ <VirtualListPro
21
+ :data="consoleList"
22
+ :pageSize="10"
23
+ :scrollIntoView="scrollIntoView"
24
+ :scrollWithAnimation="true"
25
+ className="console-list"
26
+ >
21
27
  <template v-slot="{ list, start }">
22
28
  <AutoSize
23
29
  v-for="(item, index) in list"