@@ -84,6 +84,15 @@ import type {
84
84
import { PluginForm } from ' ../../src'
85
85
import { PLUGIN_METADATA } from ' ../../src/definitions/metadata'
86
86
87
+ function save(type : ' pluginType' | ' schema' , value : unknown ) {
88
+ localStorage .setItem (` plugin-form-playground:${type } ` , JSON .stringify (value ))
89
+ }
90
+
91
+ function load(type : ' pluginType' | ' schema' , defaultValue ? : unknown ) {
92
+ const stored = localStorage .getItem (` plugin-form-playground:${type } ` )
93
+ return stored ? JSON .parse (stored ) : defaultValue
94
+ }
95
+
87
96
const router = useRouter ()
88
97
const controlPlaneId = import .meta .env .VITE_KONNECT_CONTROL_PLANE_ID || ' '
89
98
@@ -95,8 +104,7 @@ const pluginTypes = [
95
104
})),
96
105
].sort ((a , b ) => a .label .localeCompare (b .label ))
97
106
98
- const storedPluginType =
99
- localStorage .getItem (' plugin-form-playground:pluginType' ) || ' '
107
+ const storedPluginType = load (' pluginType' , ' ' )
100
108
const pluginType = ref <string >(
101
109
pluginTypes .find (({ value }) => value === storedPluginType )
102
110
? storedPluginType
@@ -108,8 +116,8 @@ const defaultSchema = {
108
116
}
109
117
const schemaOpen = ref (false )
110
118
111
- const storedSchema = localStorage . getItem ( ' plugin-form-playground: schema' )
112
- const schemaText = ref (storedSchema || JSON . stringify ( defaultSchema , null , 2 ) )
119
+ const storedSchema = load ( ' schema' , JSON . stringify ( defaultSchema , null , 2 ) )
120
+ const schemaText = ref (storedSchema )
113
121
114
122
watch (schemaOpen , async (open ) => {
115
123
if (open ) {
@@ -170,13 +178,13 @@ const onUpdate = (payload: Record<string, any>) => {
170
178
}
171
179
172
180
watch (pluginType , () => {
173
- localStorage . setItem ( ' plugin-form-playground: pluginType' , pluginType .value )
181
+ save ( ' pluginType' , pluginType .value )
174
182
})
175
183
176
184
watch (schemaText , () => {
177
185
renderError .value = ' '
178
186
179
- localStorage . setItem ( ' plugin-form-playground: schema' , schemaText .value )
187
+ save ( ' schema' , schemaText .value )
180
188
})
181
189
182
190
onErrorCaptured ((error ) => {
0 commit comments