@@ -10,7 +10,6 @@ const playgroundButton = document.querySelector<HTMLButtonElement>("#playground"
1010const runnerEndpointInput = document . querySelector < HTMLInputElement > ( "#runner-endpoint" ) ;
1111
1212const defaultRunnerEndpoint = "http://localhost:8882/wp-json/static-site-importer/v1/import-figma" ;
13- const runnerEndpointStorageKey = "figma-to-wordpress-runner-endpoint" ;
1413
1514function log ( message : string , details ?: unknown ) {
1615 if ( typeof details === "undefined" ) {
@@ -54,7 +53,7 @@ function runnerEndpoint(): string {
5453function persistRunnerEndpoint ( ) {
5554 const endpoint = runnerEndpoint ( ) ;
5655
57- localStorage . setItem ( runnerEndpointStorageKey , endpoint ) ;
56+ sendToPlugin ( { type : "set-runner-endpoint" , endpoint } ) ;
5857}
5958
6059async function openPlayground ( ) {
@@ -134,6 +133,13 @@ window.onmessage = (event: MessageEvent<{ pluginMessage?: PluginToUiMessage }>)
134133 return ;
135134 }
136135
136+ if ( message . type === "runner-endpoint" ) {
137+ if ( runnerEndpointInput && message . endpoint ) {
138+ runnerEndpointInput . value = message . endpoint ;
139+ }
140+ return ;
141+ }
142+
137143 if ( message . type === "error" ) {
138144 setStatus ( message . message ) ;
139145 }
@@ -144,8 +150,9 @@ playgroundButton?.addEventListener("click", () => void openPlayground());
144150runnerEndpointInput ?. addEventListener ( "change" , persistRunnerEndpoint ) ;
145151
146152if ( runnerEndpointInput ) {
147- runnerEndpointInput . value = localStorage . getItem ( runnerEndpointStorageKey ) || defaultRunnerEndpoint ;
153+ runnerEndpointInput . value = defaultRunnerEndpoint ;
148154}
149155
150156log ( "UI loaded." , { endpoint : runnerEndpoint ( ) } ) ;
157+ sendToPlugin ( { type : "get-runner-endpoint" } ) ;
151158sendToPlugin ( { type : "refresh-document" } ) ;
0 commit comments