/** * ds-storybook-live-compare.js * Side-by-side Storybook and Live Application comparison * UI Team Tool #2 */ import { createComparisonView, setupComparisonHandlers } from '../../utils/tool-templates.js'; import { ComponentHelpers } from '../../utils/component-helpers.js'; import contextStore from '../../stores/context-store.js'; import apiClient from '../../services/api-client.js'; class DSStorybookLiveCompare extends HTMLElement { constructor() { super(); this.storybookUrl = ''; this.liveUrl = ''; } async connectedCallback() { await this.loadProjectConfig(); this.render(); this.setupEventListeners(); } async loadProjectConfig() { try { const context = contextStore.getMCPContext(); if (!context.project_id) { throw new Error('No project selected'); } const project = await apiClient.getProject(context.project_id); this.storybookUrl = project.storybook_url || ''; this.liveUrl = project.live_url || window.location.origin; } catch (error) { console.error('[DSStorybookLiveCompare] Failed to load project config:', error); } } setupEventListeners() { const storybookInput = this.querySelector('#storybook-url-input'); const liveInput = this.querySelector('#live-url-input'); const loadBtn = this.querySelector('#load-comparison-btn'); if (storybookInput) { storybookInput.value = this.storybookUrl; } if (liveInput) { liveInput.value = this.liveUrl; } if (loadBtn) { loadBtn.addEventListener('click', () => this.loadComparison()); } const comparisonContainer = this.querySelector('#comparison-container'); if (comparisonContainer) { setupComparisonHandlers(comparisonContainer, {}); } } loadComparison() { const storybookInput = this.querySelector('#storybook-url-input'); const liveInput = this.querySelector('#live-url-input'); this.storybookUrl = storybookInput?.value || ''; this.liveUrl = liveInput?.value || ''; if (!this.storybookUrl || !this.liveUrl) { ComponentHelpers.showToast?.('Please enter both Storybook and Live application URLs', 'error'); return; } try { new URL(this.storybookUrl); new URL(this.liveUrl); } catch (error) { ComponentHelpers.showToast?.('Invalid URL format', 'error'); return; } const comparisonContainer = this.querySelector('#comparison-container'); if (comparisonContainer) { comparisonContainer.innerHTML = createComparisonView({ leftTitle: 'Storybook (Design System)', rightTitle: 'Live Application', leftSrc: this.storybookUrl, rightSrc: this.liveUrl }); setupComparisonHandlers(comparisonContainer, {}); ComponentHelpers.showToast?.('Comparison loaded', 'success'); } } render() { this.innerHTML = `
Enter Storybook and Live application URLs to compare design system vs implementation