From f92e3129d03c42ef2aef3b08bee9431f82605627 Mon Sep 17 00:00:00 2001 From: KickDown Date: Mon, 9 Nov 2026 00:00:09 -0300 Subject: [PATCH 1/7] feat: implements advanced StorageTab, allowing to edit, delete, export and import json --- src/components/DevCompanion.tsx | 26 ++--- src/components/StorageTab.tsx | 178 ++++++++++++++++++++++++++++++++ src/types/storage.ts | 12 +++ src/utils/storage.ts | 51 +++++++++ 4 files changed, 255 insertions(+), 12 deletions(-) create mode 100644 src/components/StorageTab.tsx create mode 100644 src/types/storage.ts create mode 100644 src/utils/storage.ts diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index 8b5fb10..e32a508 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { initFetchInterceptor, NetworkLog } from '../core/fetchInterceptor'; -import { StorageInspector } from './StorageInspector'; +import { StorageTab } from './StorageTab'; export const DevCompanion: React.FC = () => { const [isOpen, setIsOpen] = useState(false); @@ -25,7 +25,7 @@ export const DevCompanion: React.FC = () => { borderRadius: '8px', cursor: 'pointer', fontWeight: 'bold', - boxShadow: '0 4px 12px rgba(0,0,0,0.15)' + boxShadow: '0 4px 12px rgba(0,0,0,0.15)', }} > Dev Companion ({logs.length}) @@ -37,18 +37,18 @@ export const DevCompanion: React.FC = () => { position: 'absolute', bottom: 50, right: 0, - width: 380, - height: 340, + width: 440, + height: 380, background: '#0f172a', color: '#f8fafc', borderRadius: '8px', padding: '12px', boxShadow: '0 8px 24px rgba(0,0,0,0.3)', display: 'flex', - flexDirection: 'column' + flexDirection: 'column', }} > - {/* Main Panel Navigation Header */} + {/* Header de Navegação das Abas Principais */}
- {/* Panel Content */} + {/* Conteúdo dos Painéis */} {activeTab === 'network' ? (
{logs.length === 0 ? ( @@ -96,13 +96,13 @@ export const DevCompanion: React.FC = () => { justifyContent: 'space-between', padding: '6px 0', borderBottom: '1px solid #1e293b', - fontSize: '12px' + fontSize: '12px', }} > [{log.method}] - + {log.url} = 400 ? '#f87171' : '#facc15' }}> @@ -113,7 +113,9 @@ export const DevCompanion: React.FC = () => { )}
) : ( - +
+ +
)} )} diff --git a/src/components/StorageTab.tsx b/src/components/StorageTab.tsx new file mode 100644 index 0000000..907c765 --- /dev/null +++ b/src/components/StorageTab.tsx @@ -0,0 +1,178 @@ +import { useState, useEffect, ChangeEvent } from 'react'; +import { StorageItem, StorageType } from '../types/storage'; +import { getCookies, setCookie, deleteCookie, exportStorageJSON } from '../utils/storage'; + +export const StorageTab = () => { + const [storageType, setStorageType] = useState('localStorage'); + const [items, setItems] = useState([]); + const [editingKey, setEditingKey] = useState(null); + const [editValue, setEditValue] = useState(''); + + const loadItems = () => { + if (typeof window === 'undefined') return; + const list: StorageItem[] = []; + + if (storageType === 'localStorage') { + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i); + if (key) list.push({ key, value: localStorage.getItem(key) || '' }); + } + } else if (storageType === 'sessionStorage') { + for (let i = 0; i < sessionStorage.length; i++) { + const key = sessionStorage.key(i); + if (key) list.push({ key, value: sessionStorage.getItem(key) || '' }); + } + } else if (storageType === 'cookie') { + list.push(...getCookies()); + } + + setItems(list); + }; + + useEffect(() => { + loadItems(); + }, [storageType]); + + const handleSaveEdit = (key: string) => { + if (storageType === 'localStorage') { + localStorage.setItem(key, editValue); + } else if (storageType === 'sessionStorage') { + sessionStorage.setItem(key, editValue); + } else if (storageType === 'cookie') { + setCookie(key, editValue); + } + setEditingKey(null); + loadItems(); + }; + + const handleDelete = (key: string) => { + if (storageType === 'localStorage') { + localStorage.removeItem(key); + } else if (storageType === 'sessionStorage') { + sessionStorage.removeItem(key); + } else if (storageType === 'cookie') { + deleteCookie(key); + } + loadItems(); + }; + + const handleImportJSON = (e: ChangeEvent) => { + const file = e.target.files?.[0]; + if (!file) return; + + const reader = new FileReader(); + reader.onload = (event) => { + try { + const json = JSON.parse(event.target?.result as string); + if (json && json.data) { + Object.entries(json.data).forEach(([k, v]) => { + const strVal = typeof v === 'string' ? v : JSON.stringify(v); + if (storageType === 'localStorage') localStorage.setItem(k, strVal); + if (storageType === 'sessionStorage') sessionStorage.setItem(k, strVal); + if (storageType === 'cookie') setCookie(k, strVal); + }); + loadItems(); + } + } catch (err) { + console.error('[DevCompanion] Falha ao importar JSON:', err); + } + }; + reader.readAsText(file); + }; + + return ( +
+ {/* Sub-abas de seleção de Storage */} +
+
+ {(['localStorage', 'sessionStorage', 'cookie'] as StorageType[]).map((type) => ( + + ))} +
+ + {/* Ações de Import / Export */} +
+ + +
+
+ + {/* Tabela de Itens */} +
+ {items.length === 0 ? ( +

Nenhum item encontrado no {storageType}.

+ ) : ( + + + + + + + + + + {items.map((item) => ( + + + + + + ))} + +
ChaveValorAções
{item.key} + {editingKey === item.key ? ( + setEditValue(e.target.value)} + style={{ width: '100%', background: '#1e1e1e', color: '#fff', border: '1px solid #007acc', padding: '2px 4px' }} + /> + ) : ( + {item.value} + )} + + {editingKey === item.key ? ( + + ) : ( + + )} + +
+ )} +
+
+ ); +}; \ No newline at end of file diff --git a/src/types/storage.ts b/src/types/storage.ts new file mode 100644 index 0000000..0aba0b0 --- /dev/null +++ b/src/types/storage.ts @@ -0,0 +1,12 @@ +export type StorageType = 'localStorage' | 'sessionStorage' | 'cookie'; + +export interface StorageItem { + key: string; + value: string; +} + +export interface StorageExportData { + type: StorageType; + data: Record; + timestamp: string; +} \ No newline at end of file diff --git a/src/utils/storage.ts b/src/utils/storage.ts new file mode 100644 index 0000000..b51ca66 --- /dev/null +++ b/src/utils/storage.ts @@ -0,0 +1,51 @@ +import { StorageItem, StorageType } from '../types/storage'; + +// Lê cookies formatados como key/value +export const getCookies = (): StorageItem[] => { + if (typeof document === 'undefined' || !document.cookie) return []; + return document.cookie.split('; ').map((cookieStr) => { + const [key, ...val] = cookieStr.split('='); + return { key, value: decodeURIComponent(val.join('=')) }; + }); +}; + +// Salva ou remove cookie +export const setCookie = (key: string, value: string, days = 7) => { + if (typeof document === 'undefined') return; + const expires = new Date(Date.now() + days * 864e5).toUTCString(); + document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; expires=${expires}; path=/`; +}; + +export const deleteCookie = (key: string) => { + if (typeof document === 'undefined') return; + document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; +}; + +// Exportar Storage para arquivo JSON +export const exportStorageJSON = (type: StorageType) => { + let data: Record = {}; + + if (type === 'localStorage') { + data = { ...localStorage }; + } else if (type === 'sessionStorage') { + data = { ...sessionStorage }; + } else if (type === 'cookie') { + getCookies().forEach((item) => { + data[item.key] = item.value; + }); + } + + const payload = { + type, + timestamp: new Date().toISOString(), + data, + }; + + const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `dev-companion-${type}-${Date.now()}.json`; + a.click(); + URL.revokeObjectURL(url); +}; \ No newline at end of file From 63d8c777b0f055599fd85a86c20fe0eaab213e22 Mon Sep 17 00:00:00 2001 From: KickDown Date: Mon, 9 Nov 2026 00:05:24 -0300 Subject: [PATCH 2/7] feat: implements advanced Network Tab, adding filters and search --- src/components/DevCompanion.tsx | 30 +------- src/components/Networktab.tsx | 132 ++++++++++++++++++++++++++++++++ src/core/fetchInterceptor.ts | 58 ++++++++++---- 3 files changed, 180 insertions(+), 40 deletions(-) create mode 100644 src/components/Networktab.tsx diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index e32a508..1e66bb8 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react'; import { initFetchInterceptor, NetworkLog } from '../core/fetchInterceptor'; import { StorageTab } from './StorageTab'; +import { NetworkTab } from './Networktab'; export const DevCompanion: React.FC = () => { const [isOpen, setIsOpen] = useState(false); @@ -82,35 +83,10 @@ export const DevCompanion: React.FC = () => { - {/* Conteúdo dos Painéis */} + {/* Panels Content */} {activeTab === 'network' ? (
- {logs.length === 0 ? ( -

No requests captured yet.

- ) : ( - logs.map((log: NetworkLog) => ( -
- - [{log.method}] - - - {log.url} - - = 400 ? '#f87171' : '#facc15' }}> - {log.status || 'PENDING'} - -
- )) - )} +
) : (
diff --git a/src/components/Networktab.tsx b/src/components/Networktab.tsx new file mode 100644 index 0000000..96ac892 --- /dev/null +++ b/src/components/Networktab.tsx @@ -0,0 +1,132 @@ +import { useState } from 'react'; +import { NetworkLog } from '../core/fetchInterceptor'; + +interface NetworkTabProps { + logs: NetworkLog[]; +} + +export const NetworkTab = ({ logs }: NetworkTabProps) => { + const [searchTerm, setSearchTerm] = useState(''); + const [selectedMethod, setSelectedMethod] = useState('ALL'); + + // Filtra os logs por URL e por Método HTTP + const filteredLogs = logs.filter((log) => { + const matchesSearch = log.url.toLowerCase().includes(searchTerm.toLowerCase()); + const matchesMethod = selectedMethod === 'ALL' || log.method === selectedMethod; + return matchesSearch && matchesMethod; + }); + + const handleCopyCurl = (log: NetworkLog) => { + const curl = `curl -X ${log.method} "${log.url}"`; + navigator.clipboard.writeText(curl); + }; + + return ( +
+ {/* Barra de Filtros */} +
+ setSearchTerm(e.target.value)} + style={{ + flex: 1, + background: '#1e293b', + color: '#fff', + border: '1px solid #334155', + borderRadius: '4px', + padding: '4px 8px', + fontSize: '12px', + }} + /> + +
+ + {/* Lista de Requisições Interceptadas */} +
+ {filteredLogs.length === 0 ? ( +

Nenhuma requisição encontrada.

+ ) : ( + filteredLogs.map((log) => { + const isError = !log.status || log.status >= 400; + const statusColor = isError ? '#f87171' : '#4ade80'; + + return ( +
+
+ + [{log.method}] + + + {log.url} + +
+ +
+ {log.duration !== undefined && ( + {log.duration}ms + )} + + {log.status || 'ERR'} + + +
+
+ ); + }) + )} +
+
+ ); +}; \ No newline at end of file diff --git a/src/core/fetchInterceptor.ts b/src/core/fetchInterceptor.ts index d32b789..48d3d15 100644 --- a/src/core/fetchInterceptor.ts +++ b/src/core/fetchInterceptor.ts @@ -3,34 +3,66 @@ export interface NetworkLog { url: string; method: string; status?: number; + duration?: number; timestamp: string; } type LogCallback = (log: NetworkLog) => void; +let isInitialized = false; + export const initFetchInterceptor = (onLog: LogCallback) => { + if (isInitialized || typeof window === 'undefined') return; + isInitialized = true; + const originalFetch = window.fetch; window.fetch = async (...args) => { - const [resource, config] = args; - const url = typeof resource === 'string' ? resource : resource instanceof Request ? resource.url : String(resource); - const method = config?.method || 'GET'; + const startTime = performance.now(); + const id = Math.random().toString(36).substring(2, 9); + + let url = ''; + let method = 'GET'; - const logItem: NetworkLog = { - id: Math.random().toString(36).substring(2, 9), - url, - method: method.toUpperCase(), - timestamp: new Date().toLocaleTimeString() - }; + if (typeof args[0] === 'string') { + url = args[0]; + } else if (args[0] instanceof URL) { + url = args[0].toString(); + } else if (args[0] instanceof Request) { + url = args[0].url; + method = args[0].method || 'GET'; + } + + if (args[1] && args[1].method) { + method = args[1].method.toUpperCase(); + } try { const response = await originalFetch(...args); - logItem.status = response.status; - onLog(logItem); + const endTime = performance.now(); + + onLog({ + id, + url, + method, + status: response.status, + duration: Math.round(endTime - startTime), + timestamp: new Date().toLocaleTimeString(), + }); + return response; } catch (error) { - logItem.status = 0; - onLog(logItem); + const endTime = performance.now(); + + onLog({ + id, + url, + method, + status: 0, // 0 indicates a network error or that the request was blocked + duration: Math.round(endTime - startTime), + timestamp: new Date().toLocaleTimeString(), + }); + throw error; } }; From 247705d00a70ba55be1d7e083294c2555a4167d8 Mon Sep 17 00:00:00 2001 From: KickDown Date: Mon, 9 Nov 2026 00:13:09 -0300 Subject: [PATCH 3/7] feat: adds a keyboard shortcut to open --- src/components/DevCompanion.tsx | 42 ++++++++++++++++++++++++++------ src/hooks/useKeyboardShortcut.ts | 19 +++++++++++++++ tsconfig.json | 3 ++- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 src/hooks/useKeyboardShortcut.ts diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index 1e66bb8..d6bdd20 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -1,23 +1,51 @@ import React, { useEffect, useState } from 'react'; import { initFetchInterceptor, NetworkLog } from '../core/fetchInterceptor'; import { StorageTab } from './StorageTab'; -import { NetworkTab } from './Networktab'; +import { NetworkTab } from './NetworkTab'; +import { useKeyboardShortcut } from '../hooks/useKeyboardShortcut'; -export const DevCompanion: React.FC = () => { +export interface DevCompanionProps { + position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'; +} + +export const DevCompanion: React.FC = ({ position = 'bottom-right' }) => { const [isOpen, setIsOpen] = useState(false); const [activeTab, setActiveTab] = useState<'network' | 'storage'>('network'); const [logs, setLogs] = useState([]); + // Shortcut: Ctrl/CMD + Shift + D to toggle the Dev Companion + useKeyboardShortcut({ key: 'd', ctrlOrCmd: true, shift: true }, () => { + setIsOpen((prev) => !prev); + }); + useEffect(() => { initFetchInterceptor((newLog: NetworkLog) => { setLogs((prev: NetworkLog[]) => [newLog, ...prev]); }); }, []); + // Define position styles based on the provided position prop + const getPositionStyles = () => { + switch (position) { + case 'bottom-left': + return { bottom: 16, left: 16 }; + case 'top-right': + return { top: 16, right: 16 }; + case 'top-left': + return { top: 16, left: 16 }; + case 'bottom-right': + default: + return { bottom: 16, right: 16 }; + } + }; + + const posStyles = getPositionStyles(); + return ( -
+
- {/* Panels Content */} + {/* Content */} {activeTab === 'network' ? (
diff --git a/src/hooks/useKeyboardShortcut.ts b/src/hooks/useKeyboardShortcut.ts new file mode 100644 index 0000000..4a7d2db --- /dev/null +++ b/src/hooks/useKeyboardShortcut.ts @@ -0,0 +1,19 @@ +import { useEffect } from 'react'; + +export const useKeyboardShortcut = (keyCombo: { key: string; ctrlOrCmd?: boolean; shift?: boolean }, callback: () => void) => { + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + const isCmdOrCtrl = keyCombo.ctrlOrCmd ? (event.metaKey || event.ctrlKey) : true; + const isShift = keyCombo.shift ? event.shiftKey : true; + const isKey = event.key.toLowerCase() === keyCombo.key.toLowerCase(); + + if (isCmdOrCtrl && isShift && isKey) { + event.preventDefault(); + callback(); + } + }; + + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, [keyCombo, callback]); +}; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a58b35a..60cb166 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,8 @@ "jsx": "react-jsx", "strict": true, "declaration": true, - "types": ["node"] + "types": ["node"], + "forceConsistentCasingInFileNames": true }, "include": ["src/**/*", "vite.config.ts"] } \ No newline at end of file From 877c4a5828385bdeb4c3033eea55878fcec85d00 Mon Sep 17 00:00:00 2001 From: KickDown Date: Mon, 9 Nov 2026 00:19:11 -0300 Subject: [PATCH 4/7] feat: adds network delay simulation and offline mode --- src/components/DevCompanion.tsx | 4 +-- src/components/Networktab.tsx | 49 +++++++++++++++++++++++++++++++-- src/core/fetchInterceptor.ts | 34 ++++++++++++++++++++--- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index d6bdd20..1228a2f 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -77,7 +77,7 @@ export const DevCompanion: React.FC = ({ position = 'bottom-r flexDirection: 'column', }} > - {/* Header de Navegação */} + {/* Nav header */}
+ {/* Card do Overlay */} {isOpen && (
- {/* Nav header */} -
- - + {/* Header */} +
+
+ + +
+ + + Ctrl+Shift+D +
- {/* Content */} - {activeTab === 'network' ? ( -
- -
- ) : ( -
- -
- )} + {/* Conteúdo */} +
+ {activeTab === 'network' ? : } +
)}
diff --git a/src/components/Networktab.tsx b/src/components/Networktab.tsx index 44150a7..c1a2228 100644 --- a/src/components/Networktab.tsx +++ b/src/components/Networktab.tsx @@ -1,15 +1,21 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { NetworkLog, networkConfig } from '../core/fetchInterceptor'; +import { theme, injectDevCompanionStyles } from './styles'; interface NetworkTabProps { logs: NetworkLog[]; } -export const NetworkTab = ({ logs }: NetworkTabProps) => { +export const NetworkTab = ({ logs = [] }: NetworkTabProps) => { const [searchTerm, setSearchTerm] = useState(''); const [selectedMethod, setSelectedMethod] = useState('ALL'); const [isOffline, setIsOffline] = useState(networkConfig.isOffline); const [delay, setDelay] = useState(networkConfig.delayMs); + const [copiedId, setCopiedId] = useState(null); + + useEffect(() => { + injectDevCompanionStyles(); + }, []); const handleToggleOffline = () => { const nextState = !isOffline; @@ -23,7 +29,8 @@ export const NetworkTab = ({ logs }: NetworkTabProps) => { }; const filteredLogs = logs.filter((log) => { - const matchesSearch = log.url.toLowerCase().includes(searchTerm.toLowerCase()); + if (!log || !log.url) return false; + const matchesSearch = log.url.toLowerCase().includes((searchTerm || '').toLowerCase()); const matchesMethod = selectedMethod === 'ALL' || log.method === selectedMethod; return matchesSearch && matchesMethod; }); @@ -31,68 +38,94 @@ export const NetworkTab = ({ logs }: NetworkTabProps) => { const handleCopyCurl = (log: NetworkLog) => { const curl = `curl -X ${log.method} "${log.url}"`; navigator.clipboard.writeText(curl); + setCopiedId(log.id); + setTimeout(() => setCopiedId(null), 1500); + }; + + const getMethodColor = (method: string) => { + switch (method?.toUpperCase()) { + case 'GET': return theme.methodGet; + case 'POST': return theme.methodPost; + case 'PUT': return theme.methodPut; + case 'DELETE': return theme.methodDelete; + default: return theme.textPrimary; + } }; return ( -
- {/* Controles de Simulação (Offline / Throttling) */} +
+ {/* Sim Controls (Offline / Throttling) */}
-
- {/* Barra de Filtros */} -
+ {/* Filters */} +
setSearchTerm(e.target.value)} style={{ flex: 1, - background: '#1e293b', - color: '#fff', - border: '1px solid #334155', - borderRadius: '4px', - padding: '4px 8px', + background: theme.cardBg, + color: theme.textPrimary, + border: `1px solid ${theme.border}`, + borderRadius: '6px', + padding: '6px 10px', fontSize: '12px', + outline: 'none', }} />
- {/* Lista de Requisições Interceptadas */} -
+ {/* Requests List */} +
{filteredLogs.length === 0 ? ( -

Nenhuma requisição encontrada.

+

+ No requests captured. +

) : ( filteredLogs.map((log) => { const isError = !log.status || log.status >= 400; - const statusColor = isError ? '#f87171' : '#4ade80'; + const statusColor = isError ? theme.danger : theme.success; return (
{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', - padding: '6px 0', - borderBottom: '1px solid #1e293b', + padding: '8px 10px', + background: theme.cardBg, + borderRadius: '6px', + border: `1px solid ${theme.borderSubtle}`, fontSize: '12px', + flexShrink: 0, }} > -
- - [{log.method}] +
+ + {log.method} { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', - maxWidth: '160px', - color: '#e2e8f0', + maxWidth: '170px', + color: theme.textPrimary, + fontFamily: 'monospace', + fontSize: '11px', }} > {log.url} @@ -144,25 +196,38 @@ export const NetworkTab = ({ logs }: NetworkTabProps) => {
{log.duration !== undefined && ( - {log.duration}ms + + {log.duration}ms + )} - + {log.status || 'ERR'}
diff --git a/src/components/StorageTab.tsx b/src/components/StorageTab.tsx index 907c765..e4bdf1f 100644 --- a/src/components/StorageTab.tsx +++ b/src/components/StorageTab.tsx @@ -1,6 +1,7 @@ import { useState, useEffect, ChangeEvent } from 'react'; import { StorageItem, StorageType } from '../types/storage'; import { getCookies, setCookie, deleteCookie, exportStorageJSON } from '../utils/storage'; +import { theme, injectDevCompanionStyles } from './styles'; export const StorageTab = () => { const [storageType, setStorageType] = useState('localStorage'); @@ -8,6 +9,10 @@ export const StorageTab = () => { const [editingKey, setEditingKey] = useState(null); const [editValue, setEditValue] = useState(''); + useEffect(() => { + injectDevCompanionStyles(); + }, []); + const loadItems = () => { if (typeof window === 'undefined') return; const list: StorageItem[] = []; @@ -81,75 +86,112 @@ export const StorageTab = () => { }; return ( -
- {/* Sub-abas de seleção de Storage */} +
+ {/* Sub-abas & Ações */}
-
+
{(['localStorage', 'sessionStorage', 'cookie'] as StorageType[]).map((type) => ( ))}
- {/* Ações de Import / Export */} -
+ {/* Export / Import */} +
-
{/* Tabela de Itens */} -
+
{items.length === 0 ? ( -

Nenhum item encontrado no {storageType}.

+

+ Nenhum item em {storageType}. +

) : ( - +
- - - - + + + + {items.map((item) => ( - - - + + - diff --git a/src/components/styles.ts b/src/components/styles.ts new file mode 100644 index 0000000..6a10d36 --- /dev/null +++ b/src/components/styles.ts @@ -0,0 +1,58 @@ +export const theme = { + bg: '#0f172a', // Slate 900 + cardBg: '#1e293b', // Slate 800 + hoverBg: '#334155', // Slate 700 + border: '#334155', // Slate 700 + borderSubtle: '#1e293b', + textPrimary: '#f8fafc', // Slate 50 + textSecondary: '#94a3b8', // Slate 400 + accent: '#0284c7', // Sky 600 + accentHover: '#0369a1', + success: '#4ade80', // Green 400 + warning: '#facc15', // Yellow 400 + danger: '#f87171', // Red 400 + methodGet: '#38bdf8', // Sky 400 + methodPost: '#4ade80', // Emerald 400 + methodPut: '#facc15', // Amber 400 + methodDelete: '#f87171',// Rose 400 +}; + +// Injeta estilos de scrollbar e animação keyframes no head do documento +export const injectDevCompanionStyles = () => { + if (typeof document === 'undefined') return; + const styleId = 'dev-companion-custom-styles'; + if (document.getElementById(styleId)) return; + + const styleEl = document.createElement('style'); + styleEl.id = styleId; + styleEl.innerHTML = ` + .dev-companion-scroll::-webkit-scrollbar { + width: 5px; + height: 5px; + } + .dev-companion-scroll::-webkit-scrollbar-track { + background: #0f172a; + } + .dev-companion-scroll::-webkit-scrollbar-thumb { + background: #334155; + border-radius: 4px; + } + .dev-companion-scroll::-webkit-scrollbar-thumb:hover { + background: #475569; + } + @keyframes devCompanionSlideUp { + from { + opacity: 0; + transform: translateY(8px) scale(0.98); + } + to { + opacity: 1; + transform: translateY(0) scale(1); + } + } + .dev-companion-panel-animate { + animation: devCompanionSlideUp 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards; + } + `; + document.head.appendChild(styleEl); +}; \ No newline at end of file From 32b12bf08b26d4c2d224b0ec198dfe7da222883e Mon Sep 17 00:00:00 2001 From: KickDown Date: Mon, 9 Nov 2026 00:30:16 -0300 Subject: [PATCH 6/7] feat: adds refresh button to StorageTab and autorefresh for NetworkTab --- src/components/DevCompanion.tsx | 14 +++++++++----- src/components/Networktab.tsx | 30 +++++++++++++++++++++++++----- src/components/StorageTab.tsx | 31 ++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index d6da7ad..f8d4a65 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -46,10 +46,10 @@ export const DevCompanion: React.FC = ({ position = 'bottom-r return (
- {/* Gatilho Flutuante */} + {/* Floating Trigger Button */} - {/* Card do Overlay */} + {/* Overlay Panel Card */} {isOpen && (
= ({ position = 'bottom-r
- {/* Conteúdo */} + {/* Content */}
- {activeTab === 'network' ? : } + {activeTab === 'network' ? ( + setLogs([])} /> + ) : ( + + )}
)} diff --git a/src/components/Networktab.tsx b/src/components/Networktab.tsx index c1a2228..4aa784d 100644 --- a/src/components/Networktab.tsx +++ b/src/components/Networktab.tsx @@ -4,9 +4,10 @@ import { theme, injectDevCompanionStyles } from './styles'; interface NetworkTabProps { logs: NetworkLog[]; + onClear?: () => void; } -export const NetworkTab = ({ logs = [] }: NetworkTabProps) => { +export const NetworkTab = ({ logs = [], onClear }: NetworkTabProps) => { const [searchTerm, setSearchTerm] = useState(''); const [selectedMethod, setSelectedMethod] = useState('ALL'); const [isOffline, setIsOffline] = useState(networkConfig.isOffline); @@ -54,7 +55,7 @@ export const NetworkTab = ({ logs = [] }: NetworkTabProps) => { return (
- {/* Sim Controls (Offline / Throttling) */} + {/* Simulation Controls */}
{
- {/* Filters */} -
+ {/* Filters & Actions */} +
setSearchTerm(e.target.value)} style={{ @@ -134,6 +135,25 @@ export const NetworkTab = ({ logs = [] }: NetworkTabProps) => { + + {onClear && ( + + )}
{/* Requests List */} diff --git a/src/components/StorageTab.tsx b/src/components/StorageTab.tsx index e4bdf1f..9d2fe81 100644 --- a/src/components/StorageTab.tsx +++ b/src/components/StorageTab.tsx @@ -79,7 +79,7 @@ export const StorageTab = () => { loadItems(); } } catch (err) { - console.error('[DevCompanion] Falha ao importar JSON:', err); + console.error('[DevCompanion] Failed to import JSON:', err); } }; reader.readAsText(file); @@ -87,7 +87,7 @@ export const StorageTab = () => { return (
- {/* Sub-abas & Ações */} + {/* Sub-tabs & Actions */}
{(['localStorage', 'sessionStorage', 'cookie'] as StorageType[]).map((type) => ( @@ -111,8 +111,25 @@ export const StorageTab = () => { ))}
- {/* Export / Import */} -
+ {/* Refresh + Export / Import */} +
+ +
- {/* Tabela de Itens */} + {/* Items Table */}
{items.length === 0 ? (

- Nenhum item em {storageType}. + No items found in {storageType}.

) : (
ChaveValorAções
KeyValueActions
{item.key} +
+ {item.key} + {editingKey === item.key ? ( setEditValue(e.target.value)} - style={{ width: '100%', background: '#1e1e1e', color: '#fff', border: '1px solid #007acc', padding: '2px 4px' }} + style={{ + width: '100%', + background: theme.bg, + color: theme.textPrimary, + border: `1px solid ${theme.accent}`, + borderRadius: '4px', + padding: '3px 6px', + fontSize: '11px', + outline: 'none', + }} /> ) : ( - {item.value} + + {item.value} + )} + {editingKey === item.key ? ( - ) : ( @@ -158,12 +200,12 @@ export const StorageTab = () => { setEditingKey(item.key); setEditValue(item.value); }} - style={{ color: '#dcdcaa', background: 'none', border: 'none', cursor: 'pointer', marginRight: '6px' }} + style={{ color: theme.warning, background: 'none', border: 'none', cursor: 'pointer', marginRight: '6px' }} > - Editar + Edit )} -
@@ -192,7 +209,7 @@ export const StorageTab = () => {
{editingKey === item.key ? ( ) : ( + )} + + + {/* Requests List */} +
+ {filteredLogs.length === 0 ? ( +

+ No requests captured. +

+ ) : ( + filteredLogs.map((log) => { + const isError = !log.status || log.status >= 400; + const statusColor = isError ? theme.danger : theme.success; + + return ( +
+
+ + {log.method} + + + {log.url} + +
+ +
+ {log.duration !== undefined && ( + + {log.duration}ms + + )} + + {log.status || 'ERR'} + + +
+
+ ); + }) + )} +
+ + ); +}; \ No newline at end of file