vite-uni-dev-tool 0.0.18 → 0.0.20

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.
@@ -134,13 +134,13 @@ export declare class DevStore {
134
134
  clearWsList(): void;
135
135
  updateWsList(item: DevTool.WS): DevTool.WS[] | undefined;
136
136
  clearWsMessage(url: string): void;
137
- clearStorageList(): DevTool.StorageItem[];
137
+ clearStorageList(local?: boolean): DevTool.StorageItem[];
138
138
  setStorageList(items: DevTool.StorageItem[]): DevTool.StorageItem[] | undefined;
139
- removeStorage(key: string): DevTool.StorageItem[];
139
+ removeStorage(key: string, local?: boolean): DevTool.StorageItem[];
140
140
  addStorage(data: {
141
141
  key: string;
142
142
  value: any;
143
- }): DevTool.StorageItem[] | undefined;
143
+ }, local?: boolean): DevTool.StorageItem[] | undefined;
144
144
  refreshStore(): DevTool.StorageItem[];
145
145
  updateStoreList(addItems: DevTool.StorageItem[]): DevTool.StorageItem[] | undefined;
146
146
  setRouteList(pages: DevTool.Page[], currentPath?: string): DevTool.Page[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../dev/devStore/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAgBvC,cAAc;AACd,qBAAa,QAAQ;IACnB,WAAW;IACX,OAAO,CAAC,KAAK,CAsBX;IAEF,WAAW;IACX,OAAO,CAAC,cAAc,CAAqC;IAC3D,YAAY;IACZ,OAAO,CAAC,aAAa,CAAQ;IAC7B,YAAY;IACZ,OAAO,CAAC,cAAc,CAAQ;IAC9B,YAAY;IACZ,OAAO,CAAC,cAAc,CAAQ;IAC9B,cAAc;IACd,OAAO,CAAC,aAAa,CAAQ;IAC7B,cAAc;IACd,OAAO,CAAC,gBAAgB,CAAQ;IAChC,YAAY;IACZ,OAAO,CAAC,oBAAoB,CAAQ;IAEpC,YAAY;IACZ,YAAY,SAAwB;IAE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AC,EAAE,MAAM;IAqBjE,gBAAgB;IAIhB,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE;IAW3C,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM;IAiBjE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM;IAmB/D,eAAe;IAIf,iBAAiB,CAAC,OAAO,EAAE,OAAO;IAQlC,iBAAiB;IAMjB,kBAAkB;IASlB;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS;IAOrC;;;;;OAKG;IACH,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa;IAY/C,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,EAAE;IAYhD,aAAa;IAUb,uBAAuB,CAAC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE;IActE,sBAAsB;CAGvB"}
@@ -219,25 +219,25 @@ class V {
219
219
  const e = ((o = (s = this.state) == null ? void 0 : s.wsList) == null ? void 0 : o.findIndex((a) => a.url === t)) ?? -1;
220
220
  e !== -1 && (i = this.state.wsList) != null && i[e] && (this.state.wsList[e].message = []);
221
221
  }
222
- clearStorageList() {
223
- return this.state.storageList = [], uni.clearStorage(), this.state.storageList;
222
+ clearStorageList(t) {
223
+ return this.state.storageList = [], t && uni.clearStorage(), this.state.storageList;
224
224
  }
225
225
  setStorageList(t) {
226
226
  if (this.getDevToolVisible())
227
227
  return this.state.storageList = t, this.state.storageList;
228
228
  }
229
- removeStorage(t) {
230
- var e;
231
- return this.state.storageList = ((e = this.state.storageList) == null ? void 0 : e.filter((s) => s.key !== t)) ?? [], uni.removeStorageSync(t), this.state.storageList;
229
+ removeStorage(t, e) {
230
+ var s;
231
+ return this.state.storageList = ((s = this.state.storageList) == null ? void 0 : s.filter((o) => o.key !== t)) ?? [], e && uni.removeStorageSync(t), this.state.storageList;
232
232
  }
233
- addStorage(t) {
234
- var o;
235
- const { key: e, value: s } = t;
236
- return (o = this.state.storageList) == null || o.unshift({
237
- key: e,
238
- _oldKey: e,
239
- value: s
240
- }), uni.setStorageSync(e, s), this.state.storageList;
233
+ addStorage(t, e) {
234
+ var i;
235
+ const { key: s, value: o } = t;
236
+ return (i = this.state.storageList) == null || i.unshift({
237
+ key: s,
238
+ _oldKey: s,
239
+ value: o
240
+ }), e && uni.setStorageSync(s, o), this.state.storageList;
241
241
  }
242
242
  refreshStore() {
243
243
  const { keys: t } = uni.getStorageInfoSync();
@@ -140,14 +140,14 @@ export default {
140
140
 
141
141
  // 向上滚动时加载前面的数据
142
142
  if (
143
- this.current > 1 &&
143
+ this.current > 0 &&
144
144
  this.currentHeight > 0 &&
145
145
  scrollTop - this.preLodeHeight < this.currentHeight
146
146
  ) {
147
147
  this.start = this.current * this.pageSize;
148
148
  this.current--;
149
149
 
150
- this.updateVisitableData('up');
150
+ this.updateVisitableData();
151
151
  this.updateCurrentHeight();
152
152
  }
153
153
  },
@@ -159,53 +159,36 @@ export default {
159
159
 
160
160
  this.updateCurrentHeight();
161
161
  this.$nextTick(() => {
162
- this.updateVisitableData('down');
162
+ this.updateVisitableData();
163
163
  });
164
164
  }
165
165
  },
166
166
  // 更新可视区域数据
167
- updateVisitableData(direction) {
168
- let tempList = [...this.visitableData];
167
+ updateVisitableData() {
168
+ const tempList = [...this.visitableData];
169
169
  const pageSize = this.pageSize;
170
170
  const current = this.current;
171
171
 
172
- if (direction === 'down') {
173
- // 向下滚动:移除最前面的一页,添加新的一页
174
- tempList.splice(0, pageSize);
175
- const start = pageSize * current;
176
- let end = pageSize * (current + 1);
177
- end = end > this.dataSource.length ? this.dataSource.length : end;
178
- const newData = this.dataSource.slice(start, end);
179
- tempList.push(...newData);
180
- } else {
181
- // 向上滚动:移除最后面的多余数据,添加前面的一页
182
- // 将最末尾的部分进行隐藏
183
- const delCount =
184
- tempList.length - pageSize > 0
185
- ? pageSize
186
- : tempList.length - pageSize;
187
-
188
- tempList.splice(pageSize, delCount);
189
-
190
- // 处理上一页内容
191
- let start = pageSize * (current - 1);
192
-
193
- start = start < 0 ? 0 : start;
172
+ // 计算新的起始和结束索引
194
173
 
195
- const end = pageSize * current;
174
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
175
+ const currentAdd1 = current + 1;
196
176
 
197
- if (end < 0) return;
177
+ const startIndex = currentSub1 * pageSize;
178
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
198
179
 
199
- const newData = this.dataSource.slice(start, end);
200
- tempList.unshift(...newData);
201
- }
180
+ // 更新可见数据
202
181
 
203
- this.visitableData = tempList;
182
+ this.visitableData = tempList.slice(startIndex, endIndex);
204
183
  },
205
184
  // 更新总高度(累加已加载项的高度)
206
185
  updateCurrentHeight() {
186
+ const pageSize = this.pageSize;
187
+ const current = this.current;
188
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
189
+
207
190
  const total = this.itemsHeight
208
- .slice(0, (this.current - 1) * this.pageSize)
191
+ .slice(0, currentSub1 * pageSize)
209
192
  .reduce((acc, height) => acc + (height || 0), 0);
210
193
  this.currentHeight = total;
211
194
  },
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <view class="setting-content">
3
3
  <view class="setting-item">
4
- <DevToolTitle>DevTool(v0.0.18-vue3)</DevToolTitle>
4
+ <DevToolTitle>DevTool(v0.0.20-vue3)</DevToolTitle>
5
5
  <view class="setting-item-content">
6
6
  <view class="setting-row">
7
7
  <view>显示调试按钮:</view>
@@ -9,36 +9,49 @@
9
9
  <CircularButton style="margin-left: auto" text="×" @click="onClose" />
10
10
  </view>
11
11
  <view class="dev-tool-code-title">{{ fileName }}</view>
12
- <scroll-view
13
- scroll-y="true"
14
- scroll-x="true"
15
- class="dev-tool-code-list"
16
- scroll-with-animation="true"
17
- :scroll-top="scrollTop"
18
- :scroll-into-view="scrollIntoView"
12
+
13
+ <VirtualListPro
14
+ v-if="codes.length > 0"
15
+ scrollX
16
+ :pageSize="pageSize"
17
+ :height="height"
18
+ :data="codes"
19
+ :scrollWithAnimation="true"
20
+ :defaultCurrent="defaultCurrent"
21
+ :scrollIntoView="scrollIntoView"
19
22
  >
20
- <view
21
- v-for="(code, index) in codes"
22
- :id="`dev-tool-code-item-${index}`"
23
- :key="index"
24
- :class="`dev-tool-code-item ${index === activeRowCol.activeRow ? 'dev-tool-code-item-active' : ''}`"
25
- >
26
- <view class="dev-tool-code-item-index">
27
- {{ start + index + 1 }}
28
- </view>
29
-
30
- <view class="dev-tool-code-item-content" v-html="code"></view>
31
- </view>
32
- <Empty v-if="!codes || codes.length === 0" />
33
- </scroll-view>
23
+ <template #default="{ list, current, start }">
24
+ <AutoSize
25
+ v-for="(code, index) in list"
26
+ :key="start + index"
27
+ :index="start + index"
28
+ >
29
+ <view
30
+ :id="`dev-code-${start + index}`"
31
+ :class="`dev-tool-code-item ${start + index === activeRowCol.row ? 'dev-tool-code-item-active' : ''}`"
32
+ >
33
+ <view class="dev-tool-code-item-index">
34
+ {{ start + index + 1 }}
35
+ </view>
36
+
37
+ <view class="dev-tool-code-item-content">
38
+ {{ code }}
39
+ </view>
40
+ </view>
41
+ </AutoSize>
42
+ </template>
43
+ </VirtualListPro>
44
+ <Empty v-if="!codes || codes.length === 0" />
34
45
  </view>
35
46
  </template>
36
47
  <script lang="ts" setup>
37
- import { computed, ref, nextTick, onMounted } from 'vue';
48
+ import { computed, ref, onMounted } from 'vue';
38
49
  import FilterInput from '../FilterInput/index.vue';
39
50
  import CircularButton from '../CircularButton/index.vue';
51
+ import VirtualListPro from '../VirtualListPro/index.vue';
40
52
  import Empty from '../Empty/index.vue';
41
- import { escapeHTML, hightLight, isAndroid, parseStock } from '../../utils';
53
+ import AutoSize from '../VirtualListPro/AutoSize.vue';
54
+ import { hightLight, isAndroid, parseStock } from '../../utils';
42
55
 
43
56
  const props = defineProps<{
44
57
  url: string;
@@ -50,7 +63,7 @@ const props = defineProps<{
50
63
  const emit = defineEmits<{ (e: 'close'): void }>();
51
64
 
52
65
  const modelValue = ref('');
53
- const scrollTop = ref(0);
66
+ const height = ref(0);
54
67
  const fileName = computed(() => {
55
68
  const name =
56
69
  props?.url?.split('/')?.pop()?.replace(/\)|\(/, '') ?? '文件名称未知';
@@ -58,16 +71,13 @@ const fileName = computed(() => {
58
71
  });
59
72
 
60
73
  const activeRowCol = ref({ row: -1, col: -1, activeRow: -1 });
74
+ const scrollIntoView = ref('');
61
75
 
62
76
  let backupCodes: string[] = [];
63
77
 
64
78
  const codes = ref<string[]>([]);
65
-
66
- const scrollIntoView = ref('');
67
-
68
- const start = computed(() => {
69
- return activeRowCol.value.row - 20 > 0 ? activeRowCol.value.row - 20 : 0;
70
- });
79
+ const defaultCurrent = ref(1);
80
+ const pageSize = 25;
71
81
 
72
82
  function onClose() {
73
83
  emit('close');
@@ -79,6 +89,35 @@ function onSearch(value: string) {
79
89
  });
80
90
  }
81
91
 
92
+ let timer: number;
93
+ function startCounter({
94
+ start,
95
+ target,
96
+ duration,
97
+ onExecute,
98
+ onSuccess,
99
+ }: {
100
+ start: number;
101
+ target: number;
102
+ duration: number;
103
+ onExecute: (current: number) => void;
104
+ onSuccess: () => void;
105
+ }) {
106
+ if (timer) return;
107
+
108
+ let s = start;
109
+ timer = setInterval(() => {
110
+ if (s >= target) {
111
+ clearInterval(timer);
112
+ console.log('停止');
113
+ onSuccess();
114
+ return;
115
+ }
116
+ s++;
117
+ onExecute(s);
118
+ }, duration);
119
+ }
120
+
82
121
  let index = 0;
83
122
  function getCode(url: string, i: number = 0) {
84
123
  let allUrl = url;
@@ -100,34 +139,23 @@ function getCode(url: string, i: number = 0) {
100
139
  url: allUrl,
101
140
  success: (res) => {
102
141
  if (typeof res.data === 'string') {
103
- // 为什么要注释掉?
104
- // 在 Android 识别到标签后会进行重启,导致代码无法显示
105
- // TODO: 还有其它原因导致重启
106
- const str = res.data
107
- ?.replace(/<jscript/, '// [DevTool] 注释 <javascript')
108
- ?.replace(/<\/script>/, '// [DevTool] 注释 </javascript>')
109
- ?.replace(/<style/, '// [DevTool] 注释 <style')
110
- ?.replace(/<\/style>/, '// [DevTool] 注释 </style>');
111
- backupCodes = escapeHTML(str ?? '')
112
- .toString()
113
- .split('\n');
114
-
115
- const start =
116
- activeRowCol.value.row - 20 > 0 ? activeRowCol.value.row - 20 : 0;
117
-
118
- const end =
119
- activeRowCol.value.row + 20 > backupCodes.length
120
- ? backupCodes.length
121
- : activeRowCol.value.row + 20;
122
-
123
- // backupCodes.slice(start, end);
124
-
125
- codes.value = backupCodes.slice(start, end);
126
-
127
- activeRowCol.value.activeRow = activeRowCol.value.row - start;
128
-
129
- nextTick(() => {
130
- scrollIntoView.value = `dev-tool-code-item-${activeRowCol.value.activeRow}`;
142
+ codes.value = res.data?.split('\n') ?? [];
143
+
144
+ // 缓慢显示
145
+ const row = activeRowCol.value.row;
146
+ // defaultCurrent.value = Math.ceil(activeRowCol.value.row / pageSize);
147
+ const targetCurrent = Math.ceil(row / pageSize);
148
+
149
+ startCounter({
150
+ start: 1,
151
+ target: targetCurrent,
152
+ duration: 500,
153
+ onExecute(current) {
154
+ scrollIntoView.value = `dev-code-${current * pageSize - 1}`;
155
+ },
156
+ onSuccess() {
157
+ // scrollIntoView.value = `dev-code-${row}`;
158
+ },
131
159
  });
132
160
  }
133
161
  },
@@ -155,6 +183,10 @@ function getSourceCodeDev(url: string) {
155
183
  }
156
184
 
157
185
  onMounted(() => {
186
+ const { windowHeight } = uni.getWindowInfo();
187
+
188
+ height.value = windowHeight - 32 - 32 - 32;
189
+
158
190
  let url = props?.url;
159
191
 
160
192
  const { path, col, row } = parseStock(props?.url ?? '');
@@ -6,6 +6,7 @@
6
6
  :style="style"
7
7
  :scroll-into-view="innerScrollIntoView"
8
8
  scroll-y
9
+ :scrollX="scrollX"
9
10
  @scroll="onScroll"
10
11
  @scrolltolower="onScrollToLower"
11
12
  >
@@ -34,7 +35,7 @@
34
35
  </template>
35
36
  <script lang="ts" setup>
36
37
  import { nextTick } from 'vue';
37
- import { uniqueId } from '../../utils';
38
+ import { debounce, uniqueId } from '../../utils';
38
39
  import { reactive, watch, onBeforeMount, provide, computed, ref } from 'vue';
39
40
 
40
41
  const props = withDefaults(
@@ -59,11 +60,15 @@ const props = withDefaults(
59
60
  scrollWithAnimation?: boolean;
60
61
  /** 返回顶部 */
61
62
  showBackTop?: boolean;
63
+ /** 默认当前页 */
64
+ defaultCurrent?: number;
65
+ scrollX?: boolean;
62
66
  }>(),
63
67
  {
64
68
  height: 400,
65
69
  pageSize: 10,
66
70
  preLodeHeight: 50,
71
+ defaultCurrent: 1,
67
72
  },
68
73
  );
69
74
 
@@ -106,69 +111,75 @@ const innerScrollIntoView = computed(() => {
106
111
 
107
112
  onBeforeMount(() => {
108
113
  // 初始渲染数据
109
- state.visitableData = props.data.slice(0, props.pageSize * 2);
114
+ state.visitableData = props.data.slice(
115
+ (props.defaultCurrent - 1) * props.pageSize,
116
+ props.pageSize * 2,
117
+ );
118
+
119
+ state.currentHeight = itemsHeight
120
+ .slice(0, (props.defaultCurrent - 1) * props.pageSize)
121
+ ?.reduce((acc, cur) => acc + cur, 0);
110
122
  });
111
123
 
112
124
  // 数据更新时重置
113
125
  watch(
114
- () => [props.data, props.pageSize],
126
+ () => [props.data, props.pageSize, props.defaultCurrent],
115
127
  () => {
116
- state.visitableData = props.data.slice(0, props.pageSize * 2);
117
- },
118
- );
128
+ // state.visitableData = props.data.slice(
129
+ // (props.defaultCurrent - 1) * props.pageSize,
130
+ // props.pageSize * 2,
131
+ // );
119
132
 
120
- /** 向上滚动和向下滚动 */
121
- function updateVisitableData(direction: 'up' | 'down') {
122
- let tempList = [...state.visitableData];
133
+ // console.log(' state.visitableData: ', state.visitableData);
123
134
 
124
- if (direction === 'down') {
125
- // 将最前面的内容进行隐藏
126
- tempList.splice(0, props.pageSize);
135
+ // state.currentHeight = itemsHeight
136
+ // .slice(0, (props.defaultCurrent - 1) * props.pageSize)
137
+ // ?.reduce((acc, cur) => acc + cur, 0);
127
138
 
128
- // 处理下一页内容
129
- const start = props.pageSize * state.current;
130
- let end = props.pageSize * (state.current + 1);
139
+ const { pageSize, data, defaultCurrent } = props;
131
140
 
132
- if (start >= props.data.length) {
133
- return;
134
- }
141
+ // 计算新的起始和结束索引
135
142
 
136
- if (end > props.data.length) {
137
- end = props.data.length;
138
- }
143
+ const currentSub1 = defaultCurrent - 1 < 0 ? 0 : defaultCurrent - 1;
144
+ const currentAdd1 = defaultCurrent + 1;
139
145
 
140
- const newData = props.data.slice(start, end);
146
+ const startIndex = currentSub1 * pageSize;
147
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
141
148
 
142
- tempList.push(...newData);
143
- } else {
144
- // 将最末尾的部分进行隐藏
145
- const delCount =
146
- tempList.length - props.pageSize > 0
147
- ? props.pageSize
148
- : tempList.length - props.pageSize;
149
+ // 更新可见数据
150
+ state.visitableData = data.slice(startIndex, endIndex);
149
151
 
150
- tempList.splice(props.pageSize, delCount);
152
+ state.currentHeight = itemsHeight
153
+ .slice(0, currentSub1 * pageSize)
154
+ ?.reduce((acc, cur) => acc + cur, 0);
155
+ },
156
+ );
151
157
 
152
- // 处理上一页内容
153
- let start = props.pageSize * (state.current - 1);
158
+ /** 向上滚动和向下滚动 */
159
+ function updateVisitableData() {
160
+ const { pageSize, data } = props;
161
+ const { current } = state;
154
162
 
155
- const end = props.pageSize * state.current;
163
+ // 计算新的起始和结束索引
156
164
 
157
- if (end < 0) return;
165
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
166
+ const currentAdd1 = current + 1;
158
167
 
159
- if (start < 0) {
160
- start = 0;
161
- }
162
- const newData = props.data.slice(start, end);
163
- tempList.unshift(...newData);
164
- }
165
- state.visitableData = tempList;
168
+ const startIndex = currentSub1 * pageSize;
169
+ const endIndex = Math.min(currentAdd1 * pageSize, data.length);
170
+
171
+ // 更新可见数据
172
+ state.visitableData = data.slice(startIndex, endIndex);
166
173
  }
167
174
 
168
175
  /** 计算合并的高度 */
169
176
  function updateCurrentHeight() {
177
+ const { pageSize } = props;
178
+ const { current } = state;
179
+ const currentSub1 = current - 1 < 0 ? 0 : current - 1;
180
+
170
181
  const total = itemsHeight
171
- .slice(0, state.current * props.pageSize)
182
+ .slice(0, currentSub1 * pageSize)
172
183
  ?.reduce((acc, cur) => acc + cur, 0);
173
184
 
174
185
  state.currentHeight = total;
@@ -179,7 +190,7 @@ function onScrollToLower() {
179
190
  if ((state.current + 1) * props.pageSize < props.data.length) {
180
191
  state.current++;
181
192
 
182
- updateVisitableData('down');
193
+ updateVisitableData();
183
194
 
184
195
  updateCurrentHeight();
185
196
  }
@@ -194,7 +205,7 @@ function onScroll(e: { detail: { scrollTop: number } }) {
194
205
  ) {
195
206
  state.current--;
196
207
 
197
- updateVisitableData('up');
208
+ updateVisitableData();
198
209
 
199
210
  updateCurrentHeight();
200
211
  }
@@ -213,7 +224,7 @@ function onBackTop() {
213
224
  nextTick(() => {
214
225
  state.current = 1;
215
226
  state.currentHeight = 0;
216
- updateVisitableData('up');
227
+ updateVisitableData();
217
228
 
218
229
  toView.value = '';
219
230
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-uni-dev-tool",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
5
5
  "keywords": [
6
6
  "vite",