vite-plugin-devtools-vue2 0.1.2 → 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 +7 -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 +420 -221
- package/lib/picker.js +55 -31
- package/lib/vuex.js +14 -8
- package/lib/walker.js +46 -18
- package/package.json +1 -1
package/lib/picker.js
CHANGED
|
@@ -10,26 +10,33 @@ let hovered = null;
|
|
|
10
10
|
|
|
11
11
|
const nearestVm = el => {
|
|
12
12
|
while (el) {
|
|
13
|
-
if (el.__vue__)
|
|
13
|
+
if (el.__vue__) {
|
|
14
|
+
return el.__vue__;
|
|
15
|
+
}
|
|
14
16
|
el = el.parentElement;
|
|
15
17
|
}
|
|
16
18
|
return null;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
const vmName = vm => {
|
|
20
|
-
const
|
|
21
|
-
let
|
|
22
|
-
if (!
|
|
23
|
-
|
|
22
|
+
const options = vm.$options || {};
|
|
23
|
+
let name = options.name || options._componentTag;
|
|
24
|
+
if (!name && options.__file) {
|
|
25
|
+
name = String(options.__file)
|
|
24
26
|
.split(/[\\/]/)
|
|
25
27
|
.pop()
|
|
26
28
|
.replace(/\.vue$/, '');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
}
|
|
30
|
+
if (!name && vm.$root === vm) {
|
|
31
|
+
name = 'Root';
|
|
32
|
+
}
|
|
33
|
+
return name || 'Anonymous';
|
|
29
34
|
};
|
|
30
35
|
|
|
31
36
|
const ensureEls = () => {
|
|
32
|
-
if (box)
|
|
37
|
+
if (box) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
33
40
|
box = document.createElement('div');
|
|
34
41
|
Object.assign(box.style, {
|
|
35
42
|
position: 'fixed',
|
|
@@ -59,48 +66,63 @@ const ensureEls = () => {
|
|
|
59
66
|
|
|
60
67
|
const paint = vm => {
|
|
61
68
|
const el = vm && vm.$el;
|
|
62
|
-
if (!el || !el.getBoundingClientRect)
|
|
63
|
-
|
|
69
|
+
if (!el || !el.getBoundingClientRect) {
|
|
70
|
+
return clear();
|
|
71
|
+
}
|
|
72
|
+
const rect = el.getBoundingClientRect();
|
|
64
73
|
Object.assign(box.style, {
|
|
65
74
|
display: 'block',
|
|
66
|
-
top: `${
|
|
67
|
-
left: `${
|
|
68
|
-
width: `${
|
|
69
|
-
height: `${
|
|
75
|
+
top: `${rect.top}px`,
|
|
76
|
+
left: `${rect.left}px`,
|
|
77
|
+
width: `${rect.width}px`,
|
|
78
|
+
height: `${rect.height}px`
|
|
70
79
|
});
|
|
71
80
|
label.textContent = `<${vmName(vm)}>`;
|
|
72
81
|
label.style.display = 'block';
|
|
73
|
-
label.style.top = `${Math.max(0,
|
|
74
|
-
label.style.left = `${
|
|
82
|
+
label.style.top = `${Math.max(0, rect.top - 20)}px`;
|
|
83
|
+
label.style.left = `${rect.left}px`;
|
|
75
84
|
};
|
|
76
85
|
|
|
77
86
|
const clear = () => {
|
|
78
|
-
if (box)
|
|
79
|
-
|
|
87
|
+
if (box) {
|
|
88
|
+
box.style.display = 'none';
|
|
89
|
+
}
|
|
90
|
+
if (label) {
|
|
91
|
+
label.style.display = 'none';
|
|
92
|
+
}
|
|
80
93
|
};
|
|
81
94
|
|
|
82
|
-
const onMove =
|
|
83
|
-
const vm = nearestVm(
|
|
95
|
+
const onMove = event => {
|
|
96
|
+
const vm = nearestVm(event.target);
|
|
84
97
|
hovered = vm;
|
|
85
|
-
if (vm)
|
|
86
|
-
|
|
98
|
+
if (vm) {
|
|
99
|
+
paint(vm);
|
|
100
|
+
} else {
|
|
101
|
+
clear();
|
|
102
|
+
}
|
|
87
103
|
};
|
|
88
104
|
|
|
89
|
-
const onClick =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const vm = hovered || nearestVm(
|
|
105
|
+
const onClick = event => {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
event.stopPropagation();
|
|
108
|
+
const vm = hovered || nearestVm(event.target);
|
|
93
109
|
const cb = onPick;
|
|
94
110
|
stopPicking();
|
|
95
|
-
if (vm && cb)
|
|
111
|
+
if (vm && cb) {
|
|
112
|
+
cb(vm);
|
|
113
|
+
}
|
|
96
114
|
};
|
|
97
115
|
|
|
98
|
-
const onKey =
|
|
99
|
-
if (
|
|
116
|
+
const onKey = event => {
|
|
117
|
+
if (event.key === 'Escape') {
|
|
118
|
+
stopPicking();
|
|
119
|
+
}
|
|
100
120
|
};
|
|
101
121
|
|
|
102
122
|
export const startPicking = cb => {
|
|
103
|
-
if (active)
|
|
123
|
+
if (active) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
104
126
|
ensureEls();
|
|
105
127
|
active = true;
|
|
106
128
|
onPick = cb;
|
|
@@ -112,7 +134,9 @@ export const startPicking = cb => {
|
|
|
112
134
|
};
|
|
113
135
|
|
|
114
136
|
export const stopPicking = () => {
|
|
115
|
-
if (!active)
|
|
137
|
+
if (!active) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
116
140
|
active = false;
|
|
117
141
|
onPick = null;
|
|
118
142
|
hovered = null;
|
package/lib/vuex.js
CHANGED
|
@@ -14,7 +14,7 @@ const listeners = new Set();
|
|
|
14
14
|
let store = null;
|
|
15
15
|
|
|
16
16
|
const emit = () => {
|
|
17
|
-
listeners.forEach(
|
|
17
|
+
listeners.forEach(item => item());
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// Deep clone so a snapshot isn't mutated by later state changes. Vuex state is
|
|
@@ -22,25 +22,27 @@ const emit = () => {
|
|
|
22
22
|
const clone = state => {
|
|
23
23
|
try {
|
|
24
24
|
return JSON.parse(JSON.stringify(state));
|
|
25
|
-
} catch (
|
|
25
|
+
} catch (err) {
|
|
26
26
|
return state;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
hook.on('vuex:init',
|
|
31
|
-
store =
|
|
30
|
+
hook.on('vuex:init', storeInstance => {
|
|
31
|
+
store = storeInstance;
|
|
32
32
|
snapshots.length = 0;
|
|
33
33
|
snapshots.push({
|
|
34
34
|
type: 'Base State',
|
|
35
35
|
payload: undefined,
|
|
36
|
-
state: clone(
|
|
36
|
+
state: clone(storeInstance.state),
|
|
37
37
|
base: true
|
|
38
38
|
});
|
|
39
39
|
emit();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
hook.on('vuex:mutation', (mutation, state) => {
|
|
43
|
-
if (!store)
|
|
43
|
+
if (!store) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
44
46
|
snapshots.push({
|
|
45
47
|
type: mutation.type,
|
|
46
48
|
payload: mutation.payload,
|
|
@@ -71,13 +73,17 @@ export const subscribe = cb => {
|
|
|
71
73
|
// replaceState in response to this event).
|
|
72
74
|
export const travelTo = index => {
|
|
73
75
|
const snap = snapshots[index];
|
|
74
|
-
if (!snap || !store)
|
|
76
|
+
if (!snap || !store) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
75
79
|
hook.emit('vuex:travel-to-state', snap.state);
|
|
76
80
|
};
|
|
77
81
|
|
|
78
82
|
// Drop history and treat the current live state as the new base.
|
|
79
83
|
export const commitAll = () => {
|
|
80
|
-
if (!store)
|
|
84
|
+
if (!store) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
81
87
|
snapshots.length = 0;
|
|
82
88
|
snapshots.push({
|
|
83
89
|
type: 'Base State',
|
package/lib/walker.js
CHANGED
|
@@ -30,7 +30,9 @@ const displayName = vm => {
|
|
|
30
30
|
.pop()
|
|
31
31
|
.replace(/\.vue$/, '');
|
|
32
32
|
}
|
|
33
|
-
if (!name && vm.$root === vm)
|
|
33
|
+
if (!name && vm.$root === vm) {
|
|
34
|
+
name = 'Root';
|
|
35
|
+
}
|
|
34
36
|
return name || 'Anonymous';
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -41,7 +43,9 @@ export const findRoots = () => {
|
|
|
41
43
|
const els = document.querySelectorAll('*');
|
|
42
44
|
for (const el of els) {
|
|
43
45
|
const vm = el.__vue__;
|
|
44
|
-
if (vm && vm.$root)
|
|
46
|
+
if (vm && vm.$root) {
|
|
47
|
+
roots.add(vm.$root);
|
|
48
|
+
}
|
|
45
49
|
}
|
|
46
50
|
return [...roots];
|
|
47
51
|
};
|
|
@@ -70,25 +74,47 @@ const walk = vm => {
|
|
|
70
74
|
// Render an arbitrary value into a short, safe display string. Same-realm, so
|
|
71
75
|
// we can inspect types directly; we just avoid dumping huge/circular objects.
|
|
72
76
|
export const formatValue = (value, depth = 0) => {
|
|
73
|
-
const
|
|
74
|
-
if (value === null)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
77
|
+
const type = typeof value;
|
|
78
|
+
if (value === null) {
|
|
79
|
+
return 'null';
|
|
80
|
+
}
|
|
81
|
+
if (value === undefined) {
|
|
82
|
+
return 'undefined';
|
|
83
|
+
}
|
|
84
|
+
if (type === 'string') {
|
|
85
|
+
return JSON.stringify(value);
|
|
86
|
+
}
|
|
87
|
+
if (type === 'number' || type === 'boolean') {
|
|
88
|
+
return String(value);
|
|
89
|
+
}
|
|
90
|
+
if (type === 'function') {
|
|
91
|
+
return `ƒ ${value.name || 'anonymous'}()`;
|
|
92
|
+
}
|
|
93
|
+
if (type === 'symbol') {
|
|
94
|
+
return value.toString();
|
|
95
|
+
}
|
|
96
|
+
if (value instanceof Node) {
|
|
97
|
+
return `<${value.nodeName.toLowerCase()}>`;
|
|
98
|
+
}
|
|
81
99
|
if (Array.isArray(value)) {
|
|
82
|
-
if (depth > 1)
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
if (depth > 1) {
|
|
101
|
+
return `Array(${value.length})`;
|
|
102
|
+
}
|
|
103
|
+
const items = value.slice(0, 5).map(item => formatValue(item, depth + 1));
|
|
104
|
+
if (value.length > 5) {
|
|
105
|
+
items.push(`… +${value.length - 5}`);
|
|
106
|
+
}
|
|
85
107
|
return `[${items.join(', ')}]`;
|
|
86
108
|
}
|
|
87
|
-
if (
|
|
88
|
-
if (depth > 1)
|
|
109
|
+
if (type === 'object') {
|
|
110
|
+
if (depth > 1) {
|
|
111
|
+
return 'Object';
|
|
112
|
+
}
|
|
89
113
|
const keys = Object.keys(value);
|
|
90
|
-
const preview = keys.slice(0, 5).map(
|
|
91
|
-
if (keys.length > 5)
|
|
114
|
+
const preview = keys.slice(0, 5).map(item => `${item}: ${formatValue(value[item], depth + 1)}`);
|
|
115
|
+
if (keys.length > 5) {
|
|
116
|
+
preview.push('…');
|
|
117
|
+
}
|
|
92
118
|
return `{ ${preview.join(', ')} }`;
|
|
93
119
|
}
|
|
94
120
|
return String(value);
|
|
@@ -97,7 +123,9 @@ export const formatValue = (value, depth = 0) => {
|
|
|
97
123
|
// Extract props / data / computed for the detail pane. Values are returned raw
|
|
98
124
|
// (not stringified) so the panel can render an expandable value tree.
|
|
99
125
|
export const inspect = vm => {
|
|
100
|
-
if (!vm)
|
|
126
|
+
if (!vm) {
|
|
127
|
+
return { props: [], data: [], computed: [] };
|
|
128
|
+
}
|
|
101
129
|
|
|
102
130
|
const props = [];
|
|
103
131
|
const propDefs = (vm.$options && vm.$options.props) || null;
|