vite-plugin-devtools-vue2 0.1.2 → 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 +4 -0
- package/lib/config.js +12 -7
- package/lib/events.js +21 -12
- package/lib/hook.js +12 -6
- package/lib/inspector.js +11 -5
- package/lib/main.js +3 -1
- package/lib/panel.js +476 -226
- package/lib/picker.js +55 -31
- package/lib/vuex.js +14 -8
- package/lib/walker.js +46 -18
- package/package.json +9 -1
package/README.md
CHANGED
package/lib/config.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
// config.js — shared tunables for the devtools panel.
|
|
2
2
|
|
|
3
3
|
// localStorage key for persisted UI state (open/closed, tab, docked position).
|
|
4
|
-
export const
|
|
4
|
+
export const StoreKey = 'vue-devtools:ui';
|
|
5
5
|
|
|
6
6
|
// Panel size (keep in sync with .panel CSS) — used to keep it on-screen.
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
7
|
+
export const PanelW = 620;
|
|
8
|
+
export const PanelH = 420;
|
|
9
9
|
|
|
10
10
|
// Margin between the floating entry and the viewport edge.
|
|
11
|
-
export const
|
|
11
|
+
export const EdgeMargin = 12;
|
|
12
12
|
|
|
13
13
|
// Distance from the viewport edge to the panel when open (leaves room for the
|
|
14
14
|
// floating entry to sit in the gutter, matching the official devtools).
|
|
15
|
-
export const
|
|
15
|
+
export const PanelEdge = EdgeMargin + 30 / 2;
|
|
16
16
|
|
|
17
17
|
// Pointer travel (px) before a press on the entry counts as a drag vs a click.
|
|
18
|
-
export const
|
|
18
|
+
export const DragThreshold = 4;
|
|
19
19
|
|
|
20
20
|
// Show a per-section (props/data/computed/attrs…) filter input once a section
|
|
21
21
|
// has more than this many keys.
|
|
22
|
-
export const
|
|
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/events.js
CHANGED
|
@@ -12,26 +12,31 @@ const listeners = new Set();
|
|
|
12
12
|
let patched = false;
|
|
13
13
|
let seq = 0;
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const MaxEvents = 200;
|
|
16
16
|
|
|
17
17
|
const emit = () => {
|
|
18
|
-
listeners.forEach(
|
|
18
|
+
listeners.forEach(item => item());
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const componentName = vm => {
|
|
22
|
-
const
|
|
23
|
-
let
|
|
24
|
-
if (!
|
|
25
|
-
|
|
22
|
+
const options = (vm && vm.$options) || {};
|
|
23
|
+
let name = options.name || options._componentTag;
|
|
24
|
+
if (!name && options.__file) {
|
|
25
|
+
name = String(options.__file)
|
|
26
26
|
.split(/[\\/]/)
|
|
27
27
|
.pop()
|
|
28
28
|
.replace(/\.vue$/, '');
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
}
|
|
30
|
+
if (!name && vm && vm.$root === vm) {
|
|
31
|
+
name = 'Root';
|
|
32
|
+
}
|
|
33
|
+
return name || 'Anonymous';
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
const record = (vm, name, args) => {
|
|
34
|
-
if (typeof name === 'string' && name.indexOf('hook:') === 0)
|
|
37
|
+
if (typeof name === 'string' && name.indexOf('hook:') === 0) {
|
|
38
|
+
return; // lifecycle noise
|
|
39
|
+
}
|
|
35
40
|
events.push({
|
|
36
41
|
id: ++seq,
|
|
37
42
|
name: String(name),
|
|
@@ -39,19 +44,23 @@ const record = (vm, name, args) => {
|
|
|
39
44
|
component: componentName(vm),
|
|
40
45
|
time: Date.now()
|
|
41
46
|
});
|
|
42
|
-
if (events.length >
|
|
47
|
+
if (events.length > MaxEvents) {
|
|
48
|
+
events.shift();
|
|
49
|
+
}
|
|
43
50
|
emit();
|
|
44
51
|
};
|
|
45
52
|
|
|
46
53
|
hook.on('init', Vue => {
|
|
47
|
-
if (patched || !Vue || !Vue.prototype)
|
|
54
|
+
if (patched || !Vue || !Vue.prototype) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
48
57
|
patched = true;
|
|
49
58
|
const original = Vue.prototype.$emit;
|
|
50
59
|
// Must stay a real function: `this` is the emitting component instance.
|
|
51
60
|
Vue.prototype.$emit = function (name, ...args) {
|
|
52
61
|
try {
|
|
53
62
|
record(this, name, args);
|
|
54
|
-
} catch (
|
|
63
|
+
} catch (err) {
|
|
55
64
|
/* never break the app because of devtools */
|
|
56
65
|
}
|
|
57
66
|
return original.apply(this, arguments);
|
package/lib/hook.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// so we can capture the Vue constructor and subscribe to flushes for live
|
|
8
8
|
// refresh. This module MUST be imported before the app imports Vue.
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const HookKey = '__VUE_DEVTOOLS_GLOBAL_HOOK__';
|
|
11
11
|
|
|
12
12
|
const createHook = () => {
|
|
13
13
|
const listeners = Object.create(null);
|
|
@@ -19,19 +19,25 @@ const createHook = () => {
|
|
|
19
19
|
},
|
|
20
20
|
off(event, fn) {
|
|
21
21
|
const arr = listeners[event];
|
|
22
|
-
if (!arr)
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (!arr) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const index = arr.indexOf(fn);
|
|
26
|
+
if (index > -1) {
|
|
27
|
+
arr.splice(index, 1);
|
|
28
|
+
}
|
|
25
29
|
},
|
|
26
30
|
emit(event, ...args) {
|
|
27
31
|
const arr = listeners[event];
|
|
28
|
-
if (arr)
|
|
32
|
+
if (arr) {
|
|
33
|
+
arr.slice().forEach(item => item(...args));
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
};
|
|
31
37
|
};
|
|
32
38
|
|
|
33
39
|
// Reuse an existing hook if one somehow already exists, otherwise install ours.
|
|
34
|
-
const hook = window[
|
|
40
|
+
const hook = window[HookKey] || (window[HookKey] = createHook());
|
|
35
41
|
|
|
36
42
|
// Capture the Vue constructor as soon as Vue registers itself.
|
|
37
43
|
hook.on('init', Vue => {
|
package/lib/inspector.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
let box = null;
|
|
4
4
|
|
|
5
5
|
const ensureBox = () => {
|
|
6
|
-
if (box)
|
|
6
|
+
if (box) {
|
|
7
|
+
return box;
|
|
8
|
+
}
|
|
7
9
|
box = document.createElement('div');
|
|
8
10
|
Object.assign(box.style, {
|
|
9
11
|
position: 'fixed',
|
|
@@ -21,10 +23,12 @@ const ensureBox = () => {
|
|
|
21
23
|
|
|
22
24
|
export const highlight = vm => {
|
|
23
25
|
const el = vm && vm.$el;
|
|
24
|
-
if (!el || !el.getBoundingClientRect)
|
|
26
|
+
if (!el || !el.getBoundingClientRect) {
|
|
27
|
+
return hide();
|
|
28
|
+
}
|
|
25
29
|
const rect = el.getBoundingClientRect();
|
|
26
|
-
const
|
|
27
|
-
Object.assign(
|
|
30
|
+
const boxEl = ensureBox();
|
|
31
|
+
Object.assign(boxEl.style, {
|
|
28
32
|
display: 'block',
|
|
29
33
|
top: `${rect.top}px`,
|
|
30
34
|
left: `${rect.left}px`,
|
|
@@ -34,5 +38,7 @@ export const highlight = vm => {
|
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
export const hide = () => {
|
|
37
|
-
if (box)
|
|
41
|
+
if (box) {
|
|
42
|
+
box.style.display = 'none';
|
|
43
|
+
}
|
|
38
44
|
};
|
package/lib/main.js
CHANGED
|
@@ -8,7 +8,9 @@ import './vuex.js';
|
|
|
8
8
|
import './events.js';
|
|
9
9
|
|
|
10
10
|
const mount = () => {
|
|
11
|
-
if (document.querySelector('#__vue_devtools__'))
|
|
11
|
+
if (document.querySelector('#__vue_devtools__')) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
12
14
|
const host = document.createElement('div');
|
|
13
15
|
host.id = '__vue_devtools__';
|
|
14
16
|
document.body.appendChild(host);
|