88 */
99
1010import type { LingoDevState , WidgetPosition } from "./types" ;
11+ import { logger } from "../utils/logger" ;
1112
1213/**
1314 * Lingo.dev Dev Widget Custom Element
@@ -40,17 +41,14 @@ class LingoDevWidget extends HTMLElement {
4041 this . render ( ) ;
4142 }
4243
43- // Connect to WebSocket for real-time server updates
4444 this . connectWebSocket ( ) ;
4545 }
4646
4747 disconnectedCallback ( ) {
48- // Cleanup
4948 if ( window . __LINGO_DEV_UPDATE__ ) {
5049 delete window . __LINGO_DEV_UPDATE__ ;
5150 }
5251
53- // Close WebSocket connection
5452 if ( this . ws ) {
5553 this . ws . close ( ) ;
5654 this . ws = null ;
@@ -60,42 +58,36 @@ class LingoDevWidget extends HTMLElement {
6058 private connectWebSocket ( ) {
6159 const wsUrl = window . __LINGO_DEV_WS_URL__ ;
6260 if ( ! wsUrl ) {
63- console . warn (
64- "[Lingo.dev] WebSocket URL not available, real-time updates disabled" ,
65- ) ;
61+ logger . warn ( "WebSocket URL not available, real-time updates disabled" ) ;
6662 return ;
6763 }
6864
6965 try {
70- // Convert HTTP URL to WS URL
7166 const url = new URL ( wsUrl ) ;
7267 url . protocol = url . protocol === "https:" ? "wss:" : "ws:" ;
7368
7469 this . ws = new WebSocket ( url . toString ( ) ) ;
7570
7671 this . ws . onopen = ( ) => {
77- console . log ( "[Lingo.dev] WebSocket connected") ;
78- this . reconnectAttempts = 0 ; // Reset on successful connection
72+ logger . info ( " WebSocket connected") ;
73+ this . reconnectAttempts = 0 ;
7974 } ;
8075
8176 this . ws . onmessage = ( event ) => {
8277 try {
8378 const data = JSON . parse ( event . data ) ;
8479 this . handleServerEvent ( data ) ;
8580 } catch ( error ) {
86- console . error (
87- "[Lingo.dev] Failed to parse WebSocket message:" ,
88- error ,
89- ) ;
81+ logger . error ( "Failed to parse WebSocket message:" , error ) ;
9082 }
9183 } ;
9284
9385 this . ws . onerror = ( error ) => {
94- console . error ( "[Lingo.dev] WebSocket error:" , error ) ;
86+ logger . error ( "WebSocket error:" , error ) ;
9587 } ;
9688
9789 this . ws . onclose = ( ) => {
98- console . log ( "[Lingo.dev] WebSocket disconnected") ;
90+ logger . info ( " WebSocket disconnected") ;
9991 this . ws = null ;
10092
10193 // Attempt to reconnect with exponential backoff
@@ -105,26 +97,21 @@ class LingoDevWidget extends HTMLElement {
10597 10000 ,
10698 ) ;
10799 this . reconnectAttempts ++ ;
108- console . log (
109- `[Lingo.dev] Reconnecting in ${ delay } ms (attempt ${ this . reconnectAttempts } /${ this . maxReconnectAttempts } )` ,
100+ logger . info (
101+ `Reconnecting in ${ delay } ms (attempt ${ this . reconnectAttempts } /${ this . maxReconnectAttempts } )` ,
110102 ) ;
111103 setTimeout ( ( ) => this . connectWebSocket ( ) , delay ) ;
112104 }
113105 } ;
114106 } catch ( error ) {
115- console . error (
116- "[Lingo.dev] Failed to create WebSocket connection:" ,
117- error ,
118- ) ;
107+ logger . error ( "Failed to create WebSocket connection:" , error ) ;
119108 }
120109 }
121110
122111 private handleServerEvent ( event : any ) {
123112 switch ( event . type ) {
124113 case "connected" :
125- console . log (
126- `[Lingo.dev] Connected to translation server: ${ event . serverUrl } ` ,
127- ) ;
114+ logger . info ( `Connected to translation server: ${ event . serverUrl } ` ) ;
128115 break ;
129116
130117 case "batch:start" :
@@ -183,8 +170,7 @@ class LingoDevWidget extends HTMLElement {
183170 this . state ;
184171
185172 // Show loader if either client or server translations are in progress
186- const showLoader =
187- isLoading || ( serverProgress && serverProgress . status === "in-progress" ) ;
173+ const showLoader = isLoading || serverProgress ?. status === "in-progress" ;
188174
189175 this . shadow . innerHTML = `
190176 <style>
@@ -242,41 +228,6 @@ class LingoDevWidget extends HTMLElement {
242228 height: 26px;
243229 flex-shrink: 0;
244230 }
245-
246- .status {
247- display: flex;
248- align-items: center;
249- gap: 8px;
250- }
251-
252- .spinner {
253- display: inline-block;
254- font-size: 16px;
255- animation: lingo-spin 1s linear infinite;
256- }
257-
258- @keyframes lingo-spin {
259- 0% { transform: rotate(0deg); }
260- 100% { transform: rotate(360deg); }
261- }
262-
263- .content {
264- display: flex;
265- flex-direction: column;
266- gap: 2px;
267- }
268-
269- .title {
270- font-weight: 500;
271- font-size: 12px;
272- line-height: 16px;
273- }
274-
275- .subtitle {
276- font-size: 11px;
277- opacity: 0.8;
278- line-height: 14px;
279- }
280231 ` ;
281232 }
282233
@@ -313,7 +264,7 @@ class LingoDevWidget extends HTMLElement {
313264 }
314265}
315266
316- console . debug ( "Loading Lingo Dev Widget..." , window ) ;
267+ logger . debug ( "Loading Lingo Dev Widget..." ) ;
317268if ( typeof window !== "undefined" ) {
318269 customElements . define ( "lingo-dev-widget" , LingoDevWidget ) ;
319270 const widget = document . createElement ( "lingo-dev-widget" ) ;
0 commit comments