Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions packages/react-devtools/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,25 @@
text-align: center;
margin-top: 1rem;
}

.prompt,
.confirmation {
margin-bottom: 0.25rem;
}

.confirmation {
font-style: italic;
}

.hidden {
display: none;
}
</style>
</head>
<body>
<div id="container" class="container" style="-webkit-user-select: none; -webkit-app-region: drag;">
<div class="waiting-header">Waiting for React to connect…</div>
<div class="boxes">
<div class="boxes" style="-webkit-app-region: none;">
<div class="box">
<div class="box-header">React Native</div>
<div class="box-content">
Expand All @@ -115,7 +128,12 @@
<div class="box">
<div class="box-header">React DOM</div>
<div class="box-content">
Add one of the following:
<div id="box-content-prompt" class="prompt">
Add one of the following (click to copy):
</div>
<div id="box-content-confirmation" class="confirmation hidden">
Copied to clipboard.
</div>
<span class="input" contenteditable="true" id="localhost"></span>
<span class="input" contenteditable="true" id="byip"></span>
to the top of the page you want to debug,
Expand All @@ -127,18 +145,35 @@
</div>
</div>
<script>
const {clipboard} = require("electron");
const port = process.env.PORT || 8097;
const localIp = require("ip").address();
const $ = document.querySelector.bind(document);
const $promptDiv = $("#box-content-prompt");
const $confirmationDiv = $("#box-content-confirmation");
let timeoutID;

function selectAll(event) {
function selectAllAndCopy(event) {
const element = event.target;
if (window.getSelection) {
const selection = window.getSelection();
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
clipboard.writeText(event.target.textContent);

$promptDiv.classList.add('hidden');
$confirmationDiv.classList.remove('hidden');

if (timeoutID) {
clearTimeout(timeoutID);
}

timeoutID = setTimeout(() => {
$promptDiv.classList.remove('hidden');
$confirmationDiv.classList.add('hidden');
}, 1000);
}
}

Expand All @@ -150,13 +185,13 @@

const $localhost = $("#localhost");
$localhost.innerText = `<script src="http://localhost:${port}"></` + 'script>';
$localhost.addEventListener('click', selectAll);
$localhost.addEventListener('focus', selectAll);
$localhost.addEventListener('click', selectAllAndCopy);
$localhost.addEventListener('focus', selectAllAndCopy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I just noticed that this has the unexpected effect of re-focusing (and re-copying) every time you tab away from and back to the process/window. Probably fine though. Overall this seems like a nice improvement.


const $byIp = $("#byip");
$byIp.innerText = `<script src="http://${localIp}:${port}"></` + 'script>';
$byIp.addEventListener('click', selectAll);
$byIp.addEventListener('focus', selectAll);
$byIp.addEventListener('click', selectAllAndCopy);
$byIp.addEventListener('focus', selectAllAndCopy);

let devtools;
try {
Expand Down