File size: 899 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { PluginSettingsItem } from '@vue/devtools-api'
import { SharedData } from './shared-data'

export function getPluginSettings<TSettings extends Record<string, any> = any>(pluginId: string, defaultSettings?: TSettings): TSettings {
  return {
    ...defaultSettings ?? {},
    ...SharedData.pluginSettings[pluginId] ?? {},
  }
}

export function setPluginSettings<TSettings extends Record<string, any> = any>(pluginId: string, settings: TSettings) {
  SharedData.pluginSettings = {
    ...SharedData.pluginSettings,
    [pluginId]: settings,
  }
}

export function getPluginDefaultSettings<TSettings extends Record<string, any> = any>(schema: Record<string, PluginSettingsItem>): TSettings {
  const result: Record<string, any> = {}
  if (schema) {
    for (const id in schema) {
      const item = schema[id]
      result[id] = item.defaultValue
    }
  }
  return result as TSettings
}