Skip to content

Commit

Permalink
feat: added tracy vite extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lubomirblazekcz committed Jan 6, 2022
1 parent afb9bb4 commit 24a3f59
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/Presenters/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Presenters;

use Nette;
use Nette\Http\Request;


/**
Expand All @@ -14,6 +15,10 @@ abstract class BasePresenter extends Nette\Application\UI\Presenter
{
public function renderDefault(): void
{
$httpRequest = $this->getHttpRequest();

$this->template->netteViteCookie = $httpRequest->getCookie('netteVite');

if (\Tracy\Debugger::$productionMode && file_exists(__DIR__ . '/../../www/manifest.json')) {
$this->template->manifest = Nette\Utils\Json::decode(file_get_contents(__DIR__ . '/../../www/manifest.json'),1);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>

{if !\Tracy\Debugger::$productionMode}
{if !\Tracy\Debugger::$productionMode && $netteViteCookie == 'true'}
<script type="module" src="http://localhost:3000/@vite/client"></script>
<script type="module" src="http://localhost:3000/src/scripts/main.js"></script>
{else}
{elseif isset($manifest)}
{foreach $manifest['src/main.js']['css'] as $file}
<link rel="stylesheet" href="/assets/{$file}" />
{/foreach}
Expand Down
49 changes: 49 additions & 0 deletions app/Tracy/Vite/Vite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<span title="Toggle Vite" data-action="netteVite">
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
<defs>
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
<stop stop-color="#41D1FF"/>
<stop offset="1" stop-color="#BD34FE"/>
</linearGradient>
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
<stop stop-color="#FFEA83"/>
<stop offset="0.0833333" stop-color="#FFDD35"/>
<stop offset="1" stop-color="#FFA800"/>
</linearGradient>
</defs>
</svg>
</span>
<style>
#tracy-debug [data-action="netteVite"] {
cursor: pointer;
padding: 0 .4em;
margin: 0 -.4em;
display: block;
}

#tracy-debug [data-action="netteVite"]:hover {
background: #c3c1b8;
}
</style>
<script>
function getCookie(n, a = `; ${document.cookie}`.match(`;\\s*${n}=([^;]+)`)) {
return a ? JSON.parse(a[1]) : false;
}

const element = document.querySelector('#tracy-debug [data-action="netteVite"]')

console.log(getCookie('netteVite'))

if (!getCookie('netteVite')) {
element.style.opacity = '40%'
}

element.addEventListener('click', () => {
document.cookie = getCookie('netteVite') ? 'netteVite=false; path=/;' : 'netteVite=true; path=/;'

getCookie('netteVite') ? (element.style.opacity = '') : (element.style.opacity = '40%')
document.location.reload()
})
</script>
14 changes: 14 additions & 0 deletions app/Tracy/Vite/Vite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class VitePanel implements Tracy\IBarPanel
{
public function getTab()
{
return file_get_contents(__DIR__ . '/Vite.html');
}

public function getPanel()
{
return '';
}
}
4 changes: 4 additions & 0 deletions config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ di:
export:
parameters: no
tags: no

tracy:
bar:
- VitePanel

0 comments on commit 24a3f59

Please sign in to comment.