Skip to content

Commit f0d4e24

Browse files
committed
fix: upgrade vue devtools dependency version closes #4863
1 parent e7b2154 commit f0d4e24

File tree

5 files changed

+957
-489
lines changed

5 files changed

+957
-489
lines changed

.changeset/light-rules-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vee-validate': patch
3+
---
4+
5+
fix: upgrade vue devtools dependency version closes #4863

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@rollup/plugin-typescript": "^11.1.6",
3333
"@types/node": "^20.12.8",
3434
"@vitest/coverage-v8": "^1.6.0",
35-
"@vue/devtools-api": "^6.6.1",
35+
"@vue/devtools-api": "^7.5.2",
36+
"@vue/devtools-kit": "^7.5.2",
3637
"chalk": "^5.3.0",
3738
"eslint": "^9.2.0",
3839
"eslint-config-prettier": "^9.1.0",

packages/vee-validate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"vue": "^3.4.26"
3939
},
4040
"dependencies": {
41-
"@vue/devtools-api": "^6.6.1",
41+
"@vue/devtools-api": "^7.5.2",
4242
"type-fest": "^4.8.3"
4343
}
4444
}

packages/vee-validate/src/devtools.ts

Lines changed: 145 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
import { ComponentInternalInstance, getCurrentInstance, nextTick, onUnmounted, unref } from 'vue';
2-
import {
3-
App,
4-
setupDevtoolsPlugin,
5-
DevtoolsPluginApi,
6-
CustomInspectorNode,
7-
CustomInspectorState,
8-
InspectorNodeTag,
9-
} from '@vue/devtools-api';
1+
import { App, ComponentInternalInstance, getCurrentInstance, nextTick, onUnmounted, unref } from 'vue';
2+
import { setupDevtoolsPlugin } from '@vue/devtools-api';
3+
import type { InspectorNodeTag, CustomInspectorState, CustomInspectorNode } from '@vue/devtools-kit';
104
import { PathState, PrivateFieldContext, PrivateFormContext } from './types';
115
import { keysOf, setInPath, throttle } from './utils';
126
import { isObject } from '../../shared';
137

8+
const DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }> = {};
9+
const DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }> = {};
10+
11+
const INSPECTOR_ID = 'vee-validate-inspector';
12+
13+
const COLORS = {
14+
error: 0xbd4b4b,
15+
success: 0x06d77b,
16+
unknown: 0x54436b,
17+
white: 0xffffff,
18+
black: 0x000000,
19+
blue: 0x035397,
20+
purple: 0xb980f0,
21+
orange: 0xf5a962,
22+
gray: 0xbbbfca,
23+
};
24+
25+
let SELECTED_NODE:
26+
| { type: 'pathState'; form: PrivateFormContext; state: PathState }
27+
| { type: 'form'; form: PrivateFormContext & { _vm?: ComponentInternalInstance | null } }
28+
| { type: 'field'; field: PrivateFieldContext & { _vm?: ComponentInternalInstance | null } }
29+
| null = null;
30+
31+
/**
32+
* Plugin API
33+
*/
34+
let API: any;
35+
1436
function installDevtoolsPlugin(app: App) {
1537
if (__DEV__) {
1638
setupDevtoolsPlugin(
@@ -22,16 +44,124 @@ function installDevtoolsPlugin(app: App) {
2244
app,
2345
logo: 'https://vee-validate.logaretm.com/v4/logo.png',
2446
},
25-
setupApiHooks,
47+
api => {
48+
console.log('api', api);
49+
API = api;
50+
51+
api.addInspector({
52+
id: INSPECTOR_ID,
53+
icon: 'rule',
54+
label: 'vee-validate',
55+
noSelectionText: 'Select a vee-validate node to inspect',
56+
actions: [
57+
{
58+
icon: 'done_outline',
59+
tooltip: 'Validate selected item',
60+
action: async () => {
61+
if (!SELECTED_NODE) {
62+
console.error('There is not a valid selected vee-validate node or component');
63+
return;
64+
}
65+
66+
if (SELECTED_NODE.type === 'field') {
67+
await SELECTED_NODE.field.validate();
68+
return;
69+
}
70+
71+
if (SELECTED_NODE.type === 'form') {
72+
await SELECTED_NODE.form.validate();
73+
return;
74+
}
75+
76+
if (SELECTED_NODE.type === 'pathState') {
77+
await SELECTED_NODE.form.validateField(SELECTED_NODE.state.path);
78+
}
79+
},
80+
},
81+
{
82+
icon: 'delete_sweep',
83+
tooltip: 'Clear validation state of the selected item',
84+
action: () => {
85+
if (!SELECTED_NODE) {
86+
console.error('There is not a valid selected vee-validate node or component');
87+
return;
88+
}
89+
90+
if (SELECTED_NODE.type === 'field') {
91+
SELECTED_NODE.field.resetField();
92+
return;
93+
}
94+
95+
if (SELECTED_NODE.type === 'form') {
96+
SELECTED_NODE.form.resetForm();
97+
}
98+
99+
if (SELECTED_NODE.type === 'pathState') {
100+
SELECTED_NODE.form.resetField(SELECTED_NODE.state.path);
101+
}
102+
},
103+
},
104+
],
105+
});
106+
107+
api.on.getInspectorTree(payload => {
108+
if (payload.inspectorId !== INSPECTOR_ID) {
109+
return;
110+
}
111+
112+
const forms = Object.values(DEVTOOLS_FORMS);
113+
const fields = Object.values(DEVTOOLS_FIELDS);
114+
115+
payload.rootNodes = [
116+
...forms.map(mapFormForDevtoolsInspector),
117+
...fields.map(field => mapFieldForDevtoolsInspector(field)),
118+
];
119+
});
120+
121+
api.on.getInspectorState(payload => {
122+
if (payload.inspectorId !== INSPECTOR_ID) {
123+
return;
124+
}
125+
126+
const { form, field, state, type } = decodeNodeId(payload.nodeId);
127+
128+
api.unhighlightElement();
129+
130+
if (form && type === 'form') {
131+
payload.state = buildFormState(form);
132+
SELECTED_NODE = { type: 'form', form };
133+
api.highlightElement(form._vm);
134+
return;
135+
}
136+
137+
if (state && type === 'pathState' && form) {
138+
payload.state = buildFieldState(state);
139+
SELECTED_NODE = { type: 'pathState', state, form };
140+
return;
141+
}
142+
143+
if (field && type === 'field') {
144+
payload.state = buildFieldState({
145+
errors: field.errors.value,
146+
dirty: field.meta.dirty,
147+
valid: field.meta.valid,
148+
touched: field.meta.touched,
149+
value: field.value.value,
150+
initialValue: field.meta.initialValue,
151+
});
152+
SELECTED_NODE = { field, type: 'field' };
153+
api.highlightElement(field._vm);
154+
return;
155+
}
156+
157+
SELECTED_NODE = null;
158+
api.unhighlightElement();
159+
});
160+
},
26161
);
27162
}
28163
}
29164

30-
const DEVTOOLS_FORMS: Record<string, PrivateFormContext & { _vm?: ComponentInternalInstance | null }> = {};
31-
const DEVTOOLS_FIELDS: Record<string, PrivateFieldContext & { _vm?: ComponentInternalInstance | null }> = {};
32-
33-
let API: DevtoolsPluginApi<Record<string, any>> | undefined;
34-
35165
export const refreshInspector = throttle(() => {
36166
setTimeout(async () => {
37167
await nextTick();
@@ -82,154 +212,6 @@ export function registerSingleFieldWithDevtools(field: PrivateFieldContext) {
82212
refreshInspector();
83213
}
84214

85-
const INSPECTOR_ID = 'vee-validate-inspector';
86-
87-
const COLORS = {
88-
error: 0xbd4b4b,
89-
success: 0x06d77b,
90-
unknown: 0x54436b,
91-
white: 0xffffff,
92-
black: 0x000000,
93-
blue: 0x035397,
94-
purple: 0xb980f0,
95-
orange: 0xf5a962,
96-
gray: 0xbbbfca,
97-
};
98-
99-
let SELECTED_NODE:
100-
| { type: 'pathState'; form: PrivateFormContext; state: PathState }
101-
| { type: 'form'; form: PrivateFormContext & { _vm?: ComponentInternalInstance | null } }
102-
| { type: 'field'; field: PrivateFieldContext & { _vm?: ComponentInternalInstance | null } }
103-
| null = null;
104-
105-
function setupApiHooks(api: DevtoolsPluginApi<Record<string, any>>) {
106-
API = api;
107-
// let highlightTimeout: number | null = null;
108-
function highlightSelected() {
109-
// const vm = SELECTED_NODE?._vm;
110-
// if (!vm) {
111-
// return;
112-
// }
113-
// if (highlightTimeout) {
114-
// window.clearTimeout(highlightTimeout);
115-
// }
116-
// api.unhighlightElement();
117-
// api.highlightElement(vm);
118-
// highlightTimeout = window.setTimeout(() => {
119-
// api.unhighlightElement();
120-
// highlightTimeout = null;
121-
// }, 3000);
122-
}
123-
124-
api.addInspector({
125-
id: INSPECTOR_ID,
126-
icon: 'rule',
127-
label: 'vee-validate',
128-
noSelectionText: 'Select a vee-validate node to inspect',
129-
actions: [
130-
{
131-
icon: 'done_outline',
132-
tooltip: 'Validate selected item',
133-
action: async () => {
134-
if (!SELECTED_NODE) {
135-
console.error('There is not a valid selected vee-validate node or component');
136-
return;
137-
}
138-
139-
if (SELECTED_NODE.type === 'field') {
140-
await SELECTED_NODE.field.validate();
141-
return;
142-
}
143-
144-
if (SELECTED_NODE.type === 'form') {
145-
await SELECTED_NODE.form.validate();
146-
return;
147-
}
148-
149-
if (SELECTED_NODE.type === 'pathState') {
150-
await SELECTED_NODE.form.validateField(SELECTED_NODE.state.path);
151-
}
152-
},
153-
},
154-
{
155-
icon: 'delete_sweep',
156-
tooltip: 'Clear validation state of the selected item',
157-
action: () => {
158-
if (!SELECTED_NODE) {
159-
console.error('There is not a valid selected vee-validate node or component');
160-
return;
161-
}
162-
163-
if (SELECTED_NODE.type === 'field') {
164-
SELECTED_NODE.field.resetField();
165-
return;
166-
}
167-
168-
if (SELECTED_NODE.type === 'form') {
169-
SELECTED_NODE.form.resetForm();
170-
}
171-
172-
if (SELECTED_NODE.type === 'pathState') {
173-
SELECTED_NODE.form.resetField(SELECTED_NODE.state.path);
174-
}
175-
},
176-
},
177-
],
178-
});
179-
180-
api.on.getInspectorTree(payload => {
181-
if (payload.inspectorId !== INSPECTOR_ID) {
182-
return;
183-
}
184-
185-
const forms = Object.values(DEVTOOLS_FORMS);
186-
const fields = Object.values(DEVTOOLS_FIELDS);
187-
188-
payload.rootNodes = [
189-
...forms.map(mapFormForDevtoolsInspector),
190-
...fields.map(field => mapFieldForDevtoolsInspector(field)),
191-
];
192-
});
193-
194-
api.on.getInspectorState((payload, ctx) => {
195-
if (payload.inspectorId !== INSPECTOR_ID || ctx.currentTab !== `custom-inspector:${INSPECTOR_ID}`) {
196-
return;
197-
}
198-
199-
const { form, field, state, type } = decodeNodeId(payload.nodeId);
200-
201-
if (form && type === 'form') {
202-
payload.state = buildFormState(form);
203-
SELECTED_NODE = { type: 'form', form };
204-
highlightSelected();
205-
return;
206-
}
207-
208-
if (state && type === 'pathState' && form) {
209-
payload.state = buildFieldState(state);
210-
SELECTED_NODE = { type: 'pathState', state, form };
211-
highlightSelected();
212-
return;
213-
}
214-
215-
if (field && type === 'field') {
216-
payload.state = buildFieldState({
217-
errors: field.errors.value,
218-
dirty: field.meta.dirty,
219-
valid: field.meta.valid,
220-
touched: field.meta.touched,
221-
value: field.value.value,
222-
initialValue: field.meta.initialValue,
223-
});
224-
SELECTED_NODE = { field, type: 'field' };
225-
highlightSelected();
226-
return;
227-
}
228-
229-
SELECTED_NODE = null;
230-
});
231-
}
232-
233215
function mapFormForDevtoolsInspector(form: PrivateFormContext): CustomInspectorNode {
234216
const { textColor, bgColor } = getValidityColors(form.meta.value.valid);
235217

0 commit comments

Comments
 (0)