File size: 3,646 Bytes
c9ae51a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ca2022
 
 
c9ae51a
 
 
8ca2022
c9ae51a
8ca2022
c9ae51a
 
 
8ca2022
c9ae51a
8ca2022
c9ae51a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class FloatingOverlay extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        :host {
          position: absolute;
          bottom: 1rem;
          right: 1rem;
          z-index: 10;
        }
        
        .overlay-container {
          display: flex;
          gap: 0.5rem;
        }
        
        .action-button {
          width: 3rem;
          height: 3rem;
          border-radius: 50%;
          background: rgba(15, 23, 42, 0.9);
          border: 1px solid rgba(71, 85, 105, 0.5);
          color: #94a3b8;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          transition: all 0.2s ease;
          box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        .action-button:hover {
          background: rgba(34, 197, 94, 0.1);
          color: #22c55e;
          border-color: #22c55e;
        }
        
        .primary-button {
          background: #22c55e;
          color: white;
          border-color: #22c55e;
        }
        
        .primary-button:hover {
          background: #16a34a;
        }
.disabled {
          opacity: 0.5;
          pointer-events: none;
        }
      </style>
      
      <div class="overlay-container">
        <div class="action-button" id="undo-btn" title="Undo (Ctrl+Z)">
          <i data-feather="corner-up-left"></i>
        </div>
        <div class="action-button" id="redo-btn" title="Redo (Ctrl+Y)">
          <i data-feather="corner-up-right"></i>
        </div>
        <div class="action-button" id="ai-btn" title="Generate with AI">
          <i data-feather="sparkles"></i>
        </div>
        <div class="action-button primary-button" id="run-btn" title="Run Workflow">
          <i data-feather="play"></i>
        </div>
      </div>
    `;
    
    this.setupEventListeners();
    this.updateButtonStates();
  }
  
  setupEventListeners() {
    this.shadowRoot.getElementById('undo-btn').addEventListener('click', () => {
      this.dispatchEvent(new CustomEvent('undo'));
    });
    
    this.shadowRoot.getElementById('redo-btn').addEventListener('click', () => {
      this.dispatchEvent(new CustomEvent('redo'));
    });
    
    this.shadowRoot.getElementById('ai-btn').addEventListener('click', () => {
      this.dispatchEvent(new CustomEvent('generate'));
    });
    
    this.shadowRoot.getElementById('run-btn').addEventListener('click', () => {
      this.dispatchEvent(new CustomEvent('run'));
    });
  }
  
  updateButtonStates() {
    const canUndo = this.hasAttribute('can-undo');
    const canRedo = this.hasAttribute('can-redo');
    const isExecuting = this.hasAttribute('is-executing');
    
    const undoBtn = this.shadowRoot.getElementById('undo-btn');
    const redoBtn = this.shadowRoot.getElementById('redo-btn');
    const runBtn = this.shadowRoot.getElementById('run-btn');
    
    undoBtn.classList.toggle('disabled', !canUndo);
    redoBtn.classList.toggle('disabled', !canRedo);
    runBtn.classList.toggle('disabled', isExecuting);
    
    if (isExecuting) {
      runBtn.innerHTML = '<i data-feather="loader" class="animate-spin"></i>';
    } else {
      runBtn.innerHTML = '<i data-feather="play"></i>';
    }
  }
  
  static get observedAttributes() {
    return ['can-undo', 'can-redo', 'is-executing'];
  }
  
  attributeChangedCallback(name, oldValue, newValue) {
    if (name === 'can-undo' || name === 'can-redo' || name === 'is-executing') {
      this.updateButtonStates();
    }
  }
}

customElements.define('floating-overlay', FloatingOverlay);