Skip to content

Commit a732553

Browse files
committed
feat(api): add type to edit custom inspector state
1 parent b140aa7 commit a732553

5 files changed

Lines changed: 9 additions & 6 deletions

File tree

packages/api/src/api/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export type HookPayloads = {
130130
inspectorId: string
131131
nodeId: string
132132
path: string[]
133+
type: string
133134
state: EditStatePayload
134135
set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void
135136
}

packages/app-backend-api/src/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,14 @@ export class DevtoolsApi {
218218
return payload.state
219219
}
220220

221-
async editInspectorState (inspectorId: string, app: App, nodeId: string, dotPath: string, state: EditStatePayload) {
221+
async editInspectorState (inspectorId: string, app: App, nodeId: string, dotPath: string, type: string, state: EditStatePayload) {
222222
const arrayPath = dotPath.split('.')
223223
await this.callHook(Hooks.EDIT_INSPECTOR_STATE, {
224224
inspectorId,
225225
app,
226226
nodeId,
227227
path: arrayPath,
228+
type,
228229
state,
229230
set: (object, path = arrayPath, value = state.value, cb?) => set(object, path, value, cb || createDefaultSetCallback(state))
230231
})

packages/app-backend-core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ async function connect () {
380380
}
381381
})
382382

383-
ctx.bridge.on(BridgeEvents.TO_BACK_CUSTOM_INSPECTOR_EDIT_STATE, async ({ inspectorId, appId, nodeId, path, payload }) => {
383+
ctx.bridge.on(BridgeEvents.TO_BACK_CUSTOM_INSPECTOR_EDIT_STATE, async ({ inspectorId, appId, nodeId, path, type, payload }) => {
384384
const inspector = getInspectorWithAppId(inspectorId, appId, ctx)
385385
if (inspector) {
386-
await editInspectorState(inspector, nodeId, path, payload, ctx)
386+
await editInspectorState(inspector, nodeId, path, type, payload, ctx)
387387
inspector.selectedNodeId = nodeId
388388
await sendInspectorState(inspector, ctx)
389389
} else {

packages/app-backend-core/src/inspector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export async function sendInspectorState (inspector: CustomInspector, ctx: Backe
2929
})
3030
}
3131

32-
export async function editInspectorState (inspector: CustomInspector, nodeId: string, dotPath: string, state: any, ctx: BackendContext) {
33-
await ctx.api.editInspectorState(inspector.id, inspector.app, nodeId, dotPath, {
32+
export async function editInspectorState (inspector: CustomInspector, nodeId: string, dotPath: string, type: string, state: any, ctx: BackendContext) {
33+
await ctx.api.editInspectorState(inspector.id, inspector.app, nodeId, dotPath, type, {
3434
...state,
3535
value: state.value != null ? parse(state.value, true) : state.value
3636
})

packages/app-frontend/src/features/inspector/custom/composable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ export function useCurrentInspector () {
102102
fetchState(currentInspector.value)
103103
}
104104

105-
function editState (path: string, payload: any) {
105+
function editState (path: string, payload: any, type: string) {
106106
bridge.send(BridgeEvents.TO_BACK_CUSTOM_INSPECTOR_EDIT_STATE, {
107107
inspectorId: currentInspector.value.id,
108108
appId: currentInspector.value.appId,
109109
nodeId: currentInspector.value.selectedNodeId,
110110
path,
111+
type,
111112
payload
112113
})
113114
}

0 commit comments

Comments
 (0)