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/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__) return 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 o = vm.$options || {};
21
- let n = o.name || o._componentTag;
22
- if (!n && o.__file)
23
- n = String(o.__file)
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
- if (!n && vm.$root === vm) n = 'Root';
28
- return n || 'Anonymous';
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) return;
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) return clear();
63
- const r = el.getBoundingClientRect();
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: `${r.top}px`,
67
- left: `${r.left}px`,
68
- width: `${r.width}px`,
69
- height: `${r.height}px`
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, r.top - 20)}px`;
74
- label.style.left = `${r.left}px`;
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) box.style.display = 'none';
79
- if (label) label.style.display = 'none';
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 = e => {
83
- const vm = nearestVm(e.target);
95
+ const onMove = event => {
96
+ const vm = nearestVm(event.target);
84
97
  hovered = vm;
85
- if (vm) paint(vm);
86
- else clear();
98
+ if (vm) {
99
+ paint(vm);
100
+ } else {
101
+ clear();
102
+ }
87
103
  };
88
104
 
89
- const onClick = e => {
90
- e.preventDefault();
91
- e.stopPropagation();
92
- const vm = hovered || nearestVm(e.target);
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) cb(vm);
111
+ if (vm && cb) {
112
+ cb(vm);
113
+ }
96
114
  };
97
115
 
98
- const onKey = e => {
99
- if (e.key === 'Escape') stopPicking();
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) return;
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) return;
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(l => l());
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 (e) {
25
+ } catch (err) {
26
26
  return state;
27
27
  }
28
28
  };
29
29
 
30
- hook.on('vuex:init', s => {
31
- store = s;
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(s.state),
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) return;
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) return;
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) return;
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) name = 'Root';
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) roots.add(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 t = typeof value;
74
- if (value === null) return 'null';
75
- if (value === undefined) return 'undefined';
76
- if (t === 'string') return JSON.stringify(value);
77
- if (t === 'number' || t === 'boolean') return String(value);
78
- if (t === 'function') return `ƒ ${value.name || 'anonymous'}()`;
79
- if (t === 'symbol') return value.toString();
80
- if (value instanceof Node) return `<${value.nodeName.toLowerCase()}>`;
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) return `Array(${value.length})`;
83
- const items = value.slice(0, 5).map(v => formatValue(v, depth + 1));
84
- if (value.length > 5) items.push(`… +${value.length - 5}`);
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 (t === 'object') {
88
- if (depth > 1) return 'Object';
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(k => `${k}: ${formatValue(value[k], depth + 1)}`);
91
- if (keys.length > 5) preview.push('…');
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) return { props: [], data: [], computed: [] };
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-devtools-vue2",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "vite-plugin-vue-devtools for vue@2.x",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",