vite-plugin-devtools-vue2 0.1.1 → 0.1.3
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/lib/config.js +22 -0
- package/lib/events.js +80 -0
- package/lib/hook.js +12 -6
- package/lib/inspector.js +11 -5
- package/lib/main.js +4 -1
- package/lib/panel.js +562 -201
- package/lib/picker.js +55 -31
- package/lib/vuex.js +16 -9
- package/lib/walker.js +46 -18
- package/package.json +1 -1
package/lib/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// config.js — shared tunables for the devtools panel.
|
|
2
|
+
|
|
3
|
+
// localStorage key for persisted UI state (open/closed, tab, docked position).
|
|
4
|
+
export const StoreKey = 'vue-devtools:ui';
|
|
5
|
+
|
|
6
|
+
// Panel size (keep in sync with .panel CSS) — used to keep it on-screen.
|
|
7
|
+
export const PanelW = 620;
|
|
8
|
+
export const PanelH = 420;
|
|
9
|
+
|
|
10
|
+
// Margin between the floating entry and the viewport edge.
|
|
11
|
+
export const EdgeMargin = 12;
|
|
12
|
+
|
|
13
|
+
// Distance from the viewport edge to the panel when open (leaves room for the
|
|
14
|
+
// floating entry to sit in the gutter, matching the official devtools).
|
|
15
|
+
export const PanelEdge = EdgeMargin + 30 / 2;
|
|
16
|
+
|
|
17
|
+
// Pointer travel (px) before a press on the entry counts as a drag vs a click.
|
|
18
|
+
export const DragThreshold = 4;
|
|
19
|
+
|
|
20
|
+
// Show a per-section (props/data/computed/attrs…) filter input once a section
|
|
21
|
+
// has more than this many keys.
|
|
22
|
+
export const SectionFilterThreshold = 10;
|
package/lib/events.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// events.js — records component events by patching Vue 2's `$emit`.
|
|
2
|
+
//
|
|
3
|
+
// We capture the Vue constructor from the global hook's `init` event (fired
|
|
4
|
+
// before the app mounts, since this module is imported early), then wrap
|
|
5
|
+
// `Vue.prototype.$emit` to log every custom event with its payload + source
|
|
6
|
+
// component. Lifecycle `hook:*` events are filtered out as noise.
|
|
7
|
+
|
|
8
|
+
import hook from './hook.js';
|
|
9
|
+
|
|
10
|
+
const events = [];
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
let patched = false;
|
|
13
|
+
let seq = 0;
|
|
14
|
+
|
|
15
|
+
const MaxEvents = 200;
|
|
16
|
+
|
|
17
|
+
const emit = () => {
|
|
18
|
+
listeners.forEach(item => item());
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const componentName = vm => {
|
|
22
|
+
const options = (vm && vm.$options) || {};
|
|
23
|
+
let name = options.name || options._componentTag;
|
|
24
|
+
if (!name && options.__file) {
|
|
25
|
+
name = String(options.__file)
|
|
26
|
+
.split(/[\\/]/)
|
|
27
|
+
.pop()
|
|
28
|
+
.replace(/\.vue$/, '');
|
|
29
|
+
}
|
|
30
|
+
if (!name && vm && vm.$root === vm) {
|
|
31
|
+
name = 'Root';
|
|
32
|
+
}
|
|
33
|
+
return name || 'Anonymous';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const record = (vm, name, args) => {
|
|
37
|
+
if (typeof name === 'string' && name.indexOf('hook:') === 0) {
|
|
38
|
+
return; // lifecycle noise
|
|
39
|
+
}
|
|
40
|
+
events.push({
|
|
41
|
+
id: ++seq,
|
|
42
|
+
name: String(name),
|
|
43
|
+
args,
|
|
44
|
+
component: componentName(vm),
|
|
45
|
+
time: Date.now()
|
|
46
|
+
});
|
|
47
|
+
if (events.length > MaxEvents) {
|
|
48
|
+
events.shift();
|
|
49
|
+
}
|
|
50
|
+
emit();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
hook.on('init', Vue => {
|
|
54
|
+
if (patched || !Vue || !Vue.prototype) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
patched = true;
|
|
58
|
+
const original = Vue.prototype.$emit;
|
|
59
|
+
// Must stay a real function: `this` is the emitting component instance.
|
|
60
|
+
Vue.prototype.$emit = function (name, ...args) {
|
|
61
|
+
try {
|
|
62
|
+
record(this, name, args);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
/* never break the app because of devtools */
|
|
65
|
+
}
|
|
66
|
+
return original.apply(this, arguments);
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const getEvents = () => events;
|
|
71
|
+
|
|
72
|
+
export const subscribe = cb => {
|
|
73
|
+
listeners.add(cb);
|
|
74
|
+
return () => listeners.delete(cb);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const clearEvents = () => {
|
|
78
|
+
events.length = 0;
|
|
79
|
+
emit();
|
|
80
|
+
};
|
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
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
import './hook.js';
|
|
6
6
|
import './panel.js';
|
|
7
7
|
import './vuex.js';
|
|
8
|
+
import './events.js';
|
|
8
9
|
|
|
9
10
|
const mount = () => {
|
|
10
|
-
if (document.querySelector('#__vue_devtools__'))
|
|
11
|
+
if (document.querySelector('#__vue_devtools__')) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
11
14
|
const host = document.createElement('div');
|
|
12
15
|
host.id = '__vue_devtools__';
|
|
13
16
|
document.body.appendChild(host);
|