Skip to content

Commit 66ce83b

Browse files
committed
feat(devtools): reset form and field paths
1 parent bb7fbbc commit 66ce83b

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.changeset/puny-wasps-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@formwerk/devtools': patch
3+
---
4+
5+
feat(devtools): reset field and path states in devtools

packages/devtools/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
} from './types';
1313
import { toValue } from 'vue';
1414
import { getPluginColors } from './constants';
15-
import { setInPath } from '@core/utils/path';
15+
import { setInPath } from '../../../packages/core/src/utils/path';
1616
import { getField, getForm } from './registry';
1717
import type { FormReturns } from '@core/index';
18-
import { isObject } from 'packages/shared/src/utils';
18+
import { isObject } from '../../../packages/shared/src/utils';
1919

2020
export function buildFieldState(state: FieldState | PathState): CustomInspectorState {
2121
return {

packages/devtools/src/init.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { App, type ComponentInternalInstance, getCurrentInstance, nextTick, onMounted, onUnmounted, watch } from 'vue';
2-
import { throttle } from 'packages/shared/src';
3-
import { FormField, FormReturns } from '@core/index';
4-
import { isSSR } from '@core/utils/common';
5-
import { PathState } from './types';
2+
import { throttle } from '../../../packages/shared/src';
3+
import { isSSR } from '../../../packages/core/src/utils/common';
4+
import type { FormField, FormReturns } from '@core/index';
5+
import { DevtoolsForm, PathState } from './types';
66
import {
77
buildFieldState,
88
buildFormState,
@@ -106,7 +106,19 @@ async function installDevtoolsPlugin(app: App) {
106106
return;
107107
}
108108

109-
console.warn(brandMessage('Resetting a non-field or form path is not yet implemented'));
109+
if (SELECTED_NODE.type === 'field') {
110+
const form = getForm(SELECTED_NODE.field.form?.id) as DevtoolsForm | undefined;
111+
form?.reset(SELECTED_NODE.field.getPath() as any);
112+
return;
113+
}
114+
115+
if (SELECTED_NODE.type === 'path') {
116+
const form = getForm(SELECTED_NODE.state.formId) as DevtoolsForm | undefined;
117+
form?.reset(SELECTED_NODE.state.path as any);
118+
return;
119+
}
120+
121+
console.warn(brandMessage('You can only reset controlled fields and paths'));
110122
},
111123
},
112124
],

0 commit comments

Comments
 (0)