vite-plugin-devtools-vue2 0.1.3 → 0.1.5

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
@@ -4,6 +4,10 @@
4
4
 
5
5
  面板基于 Shadow DOM + [lit](https://lit.dev/) 渲染,运行在页面同一上下文中,直接读取 Vue 组件实例,无需跨上下文桥接,也不依赖浏览器扩展。
6
6
 
7
+ ## 预览
8
+
9
+ ![插件截图](https://popo-store.cdn.bcebos.com/archive/13276/d3a1b67e0681430cab5df8faaad38027.png)
10
+
7
11
  ## 特性
8
12
 
9
13
  - **组件树**:实时展示组件层级,支持搜索、展开/折叠、方向键导航
package/lib/config.js CHANGED
@@ -20,3 +20,8 @@ export const DragThreshold = 4;
20
20
  // Show a per-section (props/data/computed/attrs…) filter input once a section
21
21
  // has more than this many keys.
22
22
  export const SectionFilterThreshold = 10;
23
+
24
+ // When collapsed, tuck the entry toward the edge after this idle time (ms)…
25
+ export const IdleTuckDelay = 3000;
26
+ // …by shrinking its edge margin to this (negative = peek partly off-screen).
27
+ export const IdleTuckMargin = -12;
package/lib/panel.js CHANGED
@@ -3,12 +3,12 @@
3
3
  // on every Vue scheduler flush.
4
4
 
5
5
  import { LitElement, css, html } from 'lit';
6
- import { DragThreshold, EdgeMargin, PanelEdge, PanelH, PanelW, SectionFilterThreshold, StoreKey } from './config.js';
6
+ import { DragThreshold, EdgeMargin, IdleTuckDelay, IdleTuckMargin, PanelEdge, PanelH, PanelW, SectionFilterThreshold, StoreKey } from './config.js';
7
+ import { clearEvents, subscribe as eventsSubscribe, getEvents } from './events.js';
7
8
  import hook from './hook.js';
8
9
  import { hide, highlight } from './inspector.js';
9
10
  import { isPicking, startPicking, stopPicking } from './picker.js';
10
11
  import { commitAll, getSnapshots, getStore, hasStore, travelTo, subscribe as vuexSubscribe } from './vuex.js';
11
- import { clearEvents, getEvents, subscribe as eventsSubscribe } from './events.js';
12
12
  import { buildTree, formatValue, getInstance } from './walker.js';
13
13
 
14
14
  export class VueDevToolsPanel extends LitElement {
@@ -51,6 +51,9 @@ export class VueDevToolsPanel extends LitElement {
51
51
  // the right; { edge: 'left'|'right'|'top'|'bottom', along: number }.
52
52
  this._pos = ui.pos || { edge: 'bottom', along: Number.POSITIVE_INFINITY };
53
53
  this._drag = null;
54
+ // When collapsed + idle, the entry tucks toward the edge (see IdleTuck*).
55
+ this._idleTucked = false;
56
+ this._idleTimer = 0;
54
57
  this._editingPath = null;
55
58
  this._focusEdit = false;
56
59
  this._flushTimer = null;
@@ -122,12 +125,15 @@ export class VueDevToolsPanel extends LitElement {
122
125
  const alongY = clamp(pos.along, vh - eh - margin);
123
126
 
124
127
  const es = entry.style;
128
+ // When collapsed and idle, tuck the entry toward the edge (smaller /
129
+ // negative margin) so it peeks; hovering/interacting restores it.
130
+ const dockMargin = this.collapsed && this._idleTucked ? IdleTuckMargin : EdgeMargin;
125
131
  es.insetInlineStart = es.insetBlockStart = es.insetInlineEnd = es.insetBlockEnd = 'auto';
126
132
  if (pos.edge === 'right' || pos.edge === 'left') {
127
- es['inset' + (pos.edge === 'right' ? 'InlineEnd' : 'InlineStart')] = margin + 'px';
133
+ es['inset' + (pos.edge === 'right' ? 'InlineEnd' : 'InlineStart')] = dockMargin + 'px';
128
134
  es.insetBlockStart = alongY + 'px';
129
135
  } else {
130
- es['inset' + (pos.edge === 'bottom' ? 'BlockEnd' : 'BlockStart')] = margin + 'px';
136
+ es['inset' + (pos.edge === 'bottom' ? 'BlockEnd' : 'BlockStart')] = dockMargin + 'px';
131
137
  es.insetInlineStart = alongX + 'px';
132
138
  }
133
139
  this.setAttribute('dock', pos.edge);
@@ -164,6 +170,7 @@ export class VueDevToolsPanel extends LitElement {
164
170
  }
165
171
  event.preventDefault();
166
172
  hide(); // clear any hover highlight before dragging
173
+ this._wakeEntry();
167
174
  const entry = this.renderRoot.querySelector('.entry');
168
175
  const rect = entry.getBoundingClientRect();
169
176
  this._drag = {
@@ -222,6 +229,28 @@ export class VueDevToolsPanel extends LitElement {
222
229
  }
223
230
  // Position was already decided live in _dragMove; just remember it.
224
231
  this._persistUiState();
232
+ this._scheduleIdleTuck();
233
+ }
234
+
235
+ // Idle-tuck: when collapsed with no interaction, the entry slides toward the
236
+ // edge; hovering/dragging/opening wakes it back to the normal margin.
237
+ _scheduleIdleTuck() {
238
+ clearTimeout(this._idleTimer);
239
+ if (!this.collapsed) {
240
+ return;
241
+ }
242
+ this._idleTimer = setTimeout(() => {
243
+ this._idleTucked = true;
244
+ this._applyPos();
245
+ }, IdleTuckDelay);
246
+ }
247
+
248
+ _wakeEntry() {
249
+ clearTimeout(this._idleTimer);
250
+ if (this._idleTucked) {
251
+ this._idleTucked = false;
252
+ this._applyPos();
253
+ }
225
254
  }
226
255
 
227
256
  connectedCallback() {
@@ -246,6 +275,7 @@ export class VueDevToolsPanel extends LitElement {
246
275
  hook.off('flush', this._onFlush);
247
276
  window.removeEventListener('keydown', this._onKeydown, true);
248
277
  window.removeEventListener('resize', this._onResize);
278
+ clearTimeout(this._idleTimer);
249
279
  if (this._resizeRaf) {
250
280
  cancelAnimationFrame(this._resizeRaf);
251
281
  this._resizeRaf = 0;
@@ -266,6 +296,7 @@ export class VueDevToolsPanel extends LitElement {
266
296
  firstUpdated() {
267
297
  this._applyPos();
268
298
  this.setAttribute('theme', this.theme);
299
+ this._scheduleIdleTuck();
269
300
  }
270
301
 
271
302
  _toggleTheme() {
@@ -535,6 +566,12 @@ export class VueDevToolsPanel extends LitElement {
535
566
  // Re-clamp the docked position when switching fab <-> panel (sizes differ).
536
567
  if (changed && changed.has('collapsed')) {
537
568
  this._applyPos();
569
+ // Opening wakes the entry; collapsing restarts the idle-tuck timer.
570
+ if (this.collapsed) {
571
+ this._scheduleIdleTuck();
572
+ } else {
573
+ this._wakeEntry();
574
+ }
538
575
  }
539
576
  // Focus a freshly opened inline editor.
540
577
  if (this._focusEdit) {
@@ -1002,7 +1039,12 @@ export class VueDevToolsPanel extends LitElement {
1002
1039
 
1003
1040
  render() {
1004
1041
  return html`
1005
- <div class="entry" @pointerdown=${event => this._onFabPointerDown(event)}>
1042
+ <div
1043
+ class="entry"
1044
+ @pointerdown=${event => this._onFabPointerDown(event)}
1045
+ @pointerenter=${() => this._wakeEntry()}
1046
+ @pointerleave=${() => this._scheduleIdleTuck()}
1047
+ >
1006
1048
  <span class="fab-icon">${this._vueLogo()}</span>
1007
1049
  </div>
1008
1050
  ${this.collapsed ? null : this._renderPanel()}
@@ -1013,7 +1055,6 @@ export class VueDevToolsPanel extends LitElement {
1013
1055
  return html`
1014
1056
  <div class="panel">
1015
1057
  <nav class="sidebar">
1016
- <div class="logo">${this._vueLogo()}</div>
1017
1058
  <button class="side-tab ${this.tab === 'components' ? 'active' : ''}" @click=${() => (this.tab = 'components')}>
1018
1059
  ${this._icon('components')}
1019
1060
  <span class="tip">Components</span>
@@ -1234,8 +1275,7 @@ export class VueDevToolsPanel extends LitElement {
1234
1275
  return html`
1235
1276
  <button class="btn on time-travel" @click=${() => travelTo(entry.index)}>⏱ Time Travel</button>
1236
1277
  ${this._renderKvSection('mutation', { type: snap.type, time: new Date(snap.time).toLocaleTimeString() }, false)}
1237
- ${payloadObj ? this._renderKvSection('payload', payloadObj, false) : null}
1238
- ${this._renderKvSection('state', snap.state || {}, false)}
1278
+ ${payloadObj ? this._renderKvSection('payload', payloadObj, false) : null} ${this._renderKvSection('state', snap.state || {}, false)}
1239
1279
  ${store ? this._renderKvSection('getters (live)', store.getters || {}, false) : null}
1240
1280
  `;
1241
1281
  }
@@ -1246,12 +1286,13 @@ export class VueDevToolsPanel extends LitElement {
1246
1286
  return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}`;
1247
1287
  }
1248
1288
 
1249
- // Plugin logo
1289
+ // Plugin logo (Vite mark).
1250
1290
  _vueLogo() {
1251
1291
  return html`
1252
- <svg fill-rule="evenodd" viewBox="64 64 896 896" fill="var(--logo-fill)" aria-hidden="true">
1292
+ <svg class="vlogo" viewBox="0 0 48 46" fill="none" aria-hidden="true">
1253
1293
  <path
1254
- d="M250.02 547.04c92.37-19.8 79.77-130.07 76.95-154.18-4.56-37.2-48.26-102.16-107.63-97.02-74.7 6.7-85.65 114.58-85.65 114.58-10.04 49.88 24.2 156.43 116.33 136.62m84.7 214.14c10.28 38.7 43.95 40.43 43.95 40.43H427V683.55h-51.74c-23.22 6.96-34.5 25.1-36.98 32.8-2.74 7.8-8.71 27.6-3.57 44.83m169.07-531.1c0-72.42-41.13-131.08-92.2-131.08-50.92 0-92.21 58.66-92.21 131.07 0 72.5 41.3 131.16 92.2 131.16 51.08 0 92.21-58.66 92.21-131.16m248.1 9.1c8.86-54.92-35.08-118.88-83.34-129.82-48.34-11.1-108.7 66.28-114.18 116.74-6.55 61.72 8.79 123.28 76.86 132.06 68.16 8.87 112.03-63.87 120.65-118.97m46.35 433.02s-105.47-81.53-167-169.6c-83.4-129.91-201.98-77.05-241.62-11.02-39.47 66.03-101 107.87-109.7 118.9-8.87 10.93-127.36 74.8-101.07 191.55 26.28 116.65 118.73 114.5 118.73 114.5s68.08 6.7 147.1-10.94C523.7 888.03 591.7 910 591.7 910s184.57 61.72 235.07-57.18c50.41-118.97-28.53-180.61-28.53-180.61M362.42 849.17c-51.83-10.36-72.47-45.65-75.13-51.7-2.57-6.13-17.24-34.55-9.45-82.85 22.39-72.41 86.23-77.63 86.23-77.63h63.85v-78.46l54.4.82.08 289.82zm205.38-.83c-53.56-13.75-56.05-51.78-56.05-51.78V643.95l56.05-.92v137.12c3.4 14.59 21.65 17.32 21.65 17.32h56.88V643.95h59.62v204.39zm323.84-397.72c0-26.35-21.89-105.72-103.15-105.72-81.43 0-92.29 74.9-92.29 127.84 0 50.54 4.31 121.13 105.4 118.8 101.15-2.15 90.04-114.41 90.04-140.92"
1294
+ d="M25.9456 44.9383C25.2821 45.7827 23.925 45.3131 23.925 44.2403V33.9369C23.925 32.6875 22.9126 31.6751 21.6631 31.6751H10.287C9.36714 31.6751 8.83075 30.6346 9.36713 29.8871L16.8464 19.4157C17.917 17.9185 16.8464 15.8376 15.0046 15.8376H1.23731C0.317479 15.8376 -0.218913 14.7972 0.317475 14.0497L10.0134 0.4741C10.2266 0.176825 10.5692 0.000183105 10.9332 0.000183105H39.8271C40.7469 0.000183105 41.2833 1.04065 40.7469 1.78814L33.2676 12.2595C32.197 13.7567 33.2676 15.8376 35.1094 15.8376H46.4856C47.4291 15.8376 47.959 16.9255 47.3753 17.6687L25.9478 44.9404L25.9456 44.9383Z"
1295
+ fill="#863BFF"
1255
1296
  />
1256
1297
  </svg>
1257
1298
  `;
@@ -1422,6 +1463,11 @@ export class VueDevToolsPanel extends LitElement {
1422
1463
  background: var(--bg);
1423
1464
  border: 1px solid var(--border-strong);
1424
1465
  box-shadow: 0 6px 20px rgb(16 24 40 / 0.18);
1466
+ transition:
1467
+ inset-block-start 0.2s ease,
1468
+ inset-block-end 0.2s ease,
1469
+ inset-inline-start 0.2s ease,
1470
+ inset-inline-end 0.2s ease;
1425
1471
  }
1426
1472
  .entry:active {
1427
1473
  cursor: grabbing;
@@ -1436,6 +1482,11 @@ export class VueDevToolsPanel extends LitElement {
1436
1482
  inline-size: 16px;
1437
1483
  block-size: 16px;
1438
1484
  }
1485
+ .fab-icon .vlogo {
1486
+ inline-size: 18px;
1487
+ block-size: 18px;
1488
+ display: block;
1489
+ }
1439
1490
  /* On the left/right edges, stack the entry's icons vertically. */
1440
1491
  :host([dock='left']) .entry,
1441
1492
  :host([dock='right']) .entry {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-devtools-vue2",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "vite-plugin-vue-devtools for vue@2.x",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -18,6 +18,14 @@
18
18
  "inspector"
19
19
  ],
20
20
  "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/shuoshubao/vite-plugin-vue2-devtools.git"
24
+ },
25
+ "author": {
26
+ "name": "shuoshuobao",
27
+ "email": "shuoshuobao@gmail.com"
28
+ },
21
29
  "dependencies": {
22
30
  "lit": "^3.1.4"
23
31
  }