|
3 | 3 | (function () {
|
4 | 4 |
|
5 | 5 | class BreinifyDevConsole extends HTMLElement {
|
| 6 | + $shadowRoot = null; |
| 7 | + $toggleButton = null; |
| 8 | + $panel = null; |
| 9 | + $closeBtn = null; |
| 10 | + $tabs = null; |
| 11 | + |
| 12 | + $logContainer = null; |
| 13 | + $infoContainer = null; |
| 14 | + |
6 | 15 | constructor() {
|
7 | 16 | super();
|
8 | 17 |
|
|
13 | 22 |
|
14 | 23 | this.render();
|
15 | 24 | this.hookConsole();
|
| 25 | + this.toggleDevStudio(); |
16 | 26 | }
|
17 | 27 |
|
18 | 28 | render() {
|
|
28 | 38 | header button.tab { background: transparent; border: none; color: #ccc; cursor: pointer; padding: 4px 8px; font-size: 12px; border-bottom: 2px solid transparent; transition: border-color 0.15s ease; }
|
29 | 39 | header button.tab.active { border-bottom-color: #fff; color: white; }
|
30 | 40 | header button.tab:hover:not(.active) { color: #fff; }
|
31 |
| - #log-container { flex-grow: 1; background: #1e1e1e; padding: 10px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; color: white; } |
| 41 | + div.container { display: none; flex-grow: 1; background: #1e1e1e; padding: 10px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; color: white; } |
| 42 | + div.container.active { display: block; } |
32 | 43 | #toggle-button { position: fixed; bottom: 10px; right: 10px; width: 32px; height: 32px; background: #333; border-radius: 50%; align-items: center; justify-content: center; cursor: pointer; z-index: 1000000; box-shadow: 0 0 5px rgba(0,0,0,0.3); transition: opacity 0.2s ease-out; display: none; }
|
33 | 44 | #toggle-button:hover svg path { fill: #ccc; }
|
34 | 45 | ::-webkit-scrollbar { width: 6px; }
|
|
46 | 57 | <button class="tab" data-tab="info">Info</button>
|
47 | 58 | </div>
|
48 | 59 | </header>
|
49 |
| - <div id="log-container"></div> |
| 60 | + <div id="log-container" class="container active"></div> |
| 61 | + <div id="info-container" class="container"></div> |
50 | 62 | </div>
|
51 | 63 | <div id="toggle-button" title="Show Breinify DevStudio" role="button" tabindex="0"><svg xmlns="http://www.w3.org/2000/svg" fill="white" width="16" height="16" viewBox="0 0 24 24"><path d="M12 2C8.1 2 6 4.4 6 7v5c0 .5-.2.9-.5 1.3-.3.4-.5.9-.5 1.4v.3c.1.6.5 1.1 1 1.5.5.4.8 1 .8 1.6 0 .6.2 1.1.5 1.5s.7.7 1.2.9V21c0 .6.4 1 1 1s1-.4 1-1v-1h2v1c0 .6.4 1 1 1s1-.4 1-1v-1.5c.5-.2.9-.5 1.2-.9s.5-.9.5-1.5c0-.6.3-1.2.8-1.6.5-.4.9-.9 1-1.5v-.3c0-.5-.2-1-.5-1.4-.3-.4-.5-.9-.5-1.3V7c0-2.6-2.1-5-6-5z"/></svg></div>`;
|
52 | 64 |
|
53 |
| - this.logContainer = this.shadowRoot.querySelector('#log-container'); |
54 |
| - this.toggleButton = this.shadowRoot.querySelector('#toggle-button'); |
55 |
| - this.panel = this.shadowRoot.querySelector('#panel'); |
56 |
| - this.closeBtn = this.shadowRoot.querySelector('button.close-btn'); |
57 |
| - this.tabs = this.shadowRoot.querySelectorAll('button.tab'); |
| 65 | + this.$shadowRoot = $(this.shadowRoot); |
| 66 | + this.$toggleButton = this.$shadowRoot.find('#toggle-button'); |
| 67 | + this.$panel = this.$shadowRoot.find('#panel'); |
| 68 | + this.$closeBtn = this.$shadowRoot.find('button.close-btn'); |
| 69 | + this.$tabs = this.$shadowRoot.find('button.tab'); |
58 | 70 |
|
59 |
| - this.closeBtn.addEventListener('click', () => this.toggleConsole()); |
60 |
| - this.toggleButton.addEventListener('click', () => this.toggleConsole()); |
| 71 | + this.$logContainer = this.$shadowRoot.find('#log-container'); |
| 72 | + this.$infoContainer = this.$shadowRoot.find('#info-container'); |
61 | 73 |
|
62 |
| - this.tabs.forEach(tab => tab.addEventListener('click', e => this.switchTab(e))); |
| 74 | + this.$closeBtn.click(() => this.toggleDevStudio()); |
| 75 | + this.$toggleButton.click(() => this.toggleDevStudio()); |
| 76 | + |
| 77 | + this.$tabs.click(e => this.switchTab(e)); |
63 | 78 | }
|
64 | 79 |
|
65 |
| - toggleConsole() { |
| 80 | + toggleDevStudio() { |
66 | 81 | this.isVisible = !this.isVisible;
|
67 | 82 |
|
68 | 83 | if (this.isVisible) {
|
69 |
| - this.panel.style.transform = 'translateY(0)'; |
70 |
| - this.panel.style.opacity = '1'; |
71 |
| - this.toggleButton.style.display = 'none'; |
| 84 | + this.$panel.css('transform', 'translateY(0)'); |
| 85 | + this.$panel.css('opacity', '1'); |
| 86 | + this.$toggleButton.css('display', 'none'); |
72 | 87 | } else {
|
73 |
| - this.panel.style.transform = 'translateY(100%)'; |
74 |
| - this.panel.style.opacity = '0'; |
75 |
| - this.toggleButton.style.display = 'flex'; |
| 88 | + this.$panel.css('transform', 'translateY(100%)'); |
| 89 | + this.$panel.css('opacity', '0'); |
| 90 | + this.$toggleButton.css('display', 'flex'); |
76 | 91 | }
|
77 | 92 | }
|
78 | 93 |
|
79 | 94 | switchTab(event) {
|
80 | 95 | const selectedTab = event.target.dataset.tab;
|
81 |
| - this.tabs.forEach(tab => { |
82 |
| - tab.classList.toggle('active', tab.dataset.tab === selectedTab); |
| 96 | + this.$tabs.each(function () { |
| 97 | + this.classList.toggle('active', this.dataset.tab === selectedTab); |
83 | 98 | });
|
84 | 99 |
|
85 | 100 | // For now, just clear or keep logs on console tab, and show placeholder on info tab
|
86 | 101 | if (selectedTab === 'console') {
|
87 |
| - this.logContainer.style.display = 'block'; |
88 |
| - if (this.infoDiv) this.infoDiv.style.display = 'none'; |
| 102 | + this.$logContainer.addClass('active'); |
| 103 | + this.$infoContainer.removeClass('active'); |
89 | 104 | } else if (selectedTab === 'info') {
|
90 |
| - |
91 |
| - // Lazy create info div |
92 |
| - if (!this.infoDiv) { |
93 |
| - this.infoDiv = document.createElement('div'); |
94 |
| - this.infoDiv.textContent = 'Information tab content goes here.'; |
95 |
| - this.infoDiv.style.padding = '10px'; |
96 |
| - this.infoDiv.style.color = '#ddd'; |
97 |
| - this.infoDiv.style.height = '100%'; |
98 |
| - this.infoDiv.style.overflowY = 'auto'; |
99 |
| - this.logContainer.after(this.infoDiv); |
100 |
| - } |
101 |
| - |
102 |
| - this.logContainer.style.display = 'none'; |
103 |
| - this.infoDiv.style.display = 'block'; |
| 105 | + this.$logContainer.removeClass('active'); |
| 106 | + this.$infoContainer.addClass('active'); |
104 | 107 | }
|
105 | 108 | }
|
106 | 109 |
|
|
128 | 131 | info: 'lightblue'
|
129 | 132 | }[method];
|
130 | 133 |
|
131 |
| - if (this.logContainer) { |
132 |
| - this.logContainer.appendChild(entry); |
133 |
| - this.logContainer.scrollTop = this.logContainer.scrollHeight; |
134 |
| - } |
| 134 | + this.$logContainer.append(entry); |
| 135 | + this.$logContainer.get(0).scrollTop = this.$logContainer.get(0).scrollHeight; |
135 | 136 |
|
136 | 137 | original.apply(console, args);
|
137 | 138 | };
|
|
0 commit comments