Skip to content

Commit f5fb5b9

Browse files
authored
Merge pull request #3228 from SwiftPackageIndex/javascript-debug-console
Added a front end debug panel for inspecting useful page metadata
2 parents fd2de95 + b82edbf commit f5fb5b9

File tree

66 files changed

+857
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+857
-53
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ node_modules
1818
.parcel-cache
1919
Public/main.js
2020
Public/main.js.map
21+
Public/shared.js
22+
Public/shared.js.map
2123
Public/main.css
2224
Public/main.css.map
25+
Public/shared.css
26+
Public/shared.css.map
2327
Public/docc.css
2428
Public/docc.css.map
2529
Tests/AppTests/__Snapshots__/WebpageSnapshotTests/*

FrontEnd/docc.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
$mobile-breakpoint: 740px;
2020

21-
@import 'styles/colors';
22-
@import 'styles/images';
23-
2421
header.spi,
2522
footer.spi {
2623
position: sticky;

FrontEnd/esbuild.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { sassPlugin } from 'esbuild-sass-plugin'
1717

1818
try {
1919
const context = await esbuild.context({
20-
entryPoints: ['FrontEnd/main.js', 'FrontEnd/main.scss', 'FrontEnd/docc.scss'],
20+
entryPoints: [
21+
'FrontEnd/main.js',
22+
'FrontEnd/shared.js',
23+
'FrontEnd/main.scss',
24+
'FrontEnd/docc.scss',
25+
'FrontEnd/shared.scss',
26+
],
2127
outdir: 'Public',
2228
bundle: true,
2329
sourcemap: true,

FrontEnd/main.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ $mobile-breakpoint: 740px;
2222
@import 'styles/breadcrumbs';
2323
@import 'styles/build_logs';
2424
@import 'styles/build_monitor';
25-
@import 'styles/colors';
2625
@import 'styles/copyable_input';
2726
@import 'styles/error';
2827
@import 'styles/github_highlighting';
2928
@import 'styles/header_footer';
3029
@import 'styles/home';
31-
@import 'styles/images';
3230
@import 'styles/keywords';
3331
@import 'styles/layout';
3432
@import 'styles/maintainer_info';

FrontEnd/scripts/debug_panel.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
export class SPIDebugPanel extends HTMLElement {
16+
connectedCallback() {
17+
// Debug console is Hidden by default. Make it visble by typing:
18+
// `localStorage.setItem('spiDebug', 'true');`
19+
// into the browser console.
20+
if (localStorage.getItem('spiDebug') === 'true') {
21+
this.classList.remove('hidden')
22+
23+
this.reset()
24+
this.addButtons()
25+
this.addCanonicalUrls()
26+
}
27+
}
28+
29+
disconnectedCallback() {
30+
console.log('SPIDebugPanel disconnectedCallback')
31+
}
32+
33+
reset() {
34+
const buttonsContainer = this.querySelector('.buttons')
35+
if (buttonsContainer) buttonsContainer.remove()
36+
37+
const dynamicRowElements = this.querySelectorAll('tr:not([server-side])')
38+
dynamicRowElements.forEach((row) => row.remove())
39+
}
40+
41+
addButtons() {
42+
const hideButton = document.createElement('button')
43+
hideButton.innerText = 'Hide'
44+
hideButton.title = 'Temporarily hide this panel'
45+
hideButton.addEventListener('click', () => {
46+
this.classList.add('hidden')
47+
})
48+
49+
const disableButton = document.createElement('button')
50+
disableButton.innerText = 'Disable'
51+
disableButton.title = 'Disable the debug panel'
52+
disableButton.addEventListener('click', () => {
53+
localStorage.setItem('spiDebug', 'false')
54+
this.classList.add('hidden')
55+
})
56+
57+
const buttonsContainer = document.createElement('div')
58+
buttonsContainer.classList.add('buttons')
59+
buttonsContainer.appendChild(hideButton)
60+
buttonsContainer.appendChild(disableButton)
61+
this.prepend(buttonsContainer)
62+
}
63+
64+
newTableRow(title, value, valueCssClass) {
65+
const tableElement = this.querySelector('table > tbody')
66+
const rowElement = document.createElement('tr')
67+
68+
const titleCellElement = document.createElement('td')
69+
titleCellElement.innerText = title
70+
71+
const valueSpanElement = document.createElement('span')
72+
valueSpanElement.innerText = value
73+
const valueCellElement = document.createElement('td')
74+
valueCellElement.appendChild(valueSpanElement)
75+
if (valueCssClass) valueCellElement.classList.add(valueCssClass)
76+
77+
rowElement.appendChild(titleCellElement)
78+
rowElement.appendChild(valueCellElement)
79+
tableElement.appendChild(rowElement)
80+
}
81+
82+
addCanonicalUrls() {
83+
const canonicalUrl = document.querySelector('link[rel="canonical"]').href
84+
const windowUrl = window.location.href
85+
const matchingCanonicalUrl = canonicalUrl === windowUrl
86+
87+
this.newTableRow('Canonical URL', canonicalUrl)
88+
this.newTableRow('Window URL', windowUrl)
89+
this.newTableRow('Canonical Match', matchingCanonicalUrl, matchingCanonicalUrl ? 'green' : 'red')
90+
}
91+
}

FrontEnd/shared.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FrontEnd/shared.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// -------------------------------------------------------------------------
16+
// Any styles shared between SPI and the SPI documentation pages.
17+
// -------------------------------------------------------------------------
18+
19+
@import 'styles/colors';
20+
@import 'styles/utility';
21+
@import 'styles/debug_panel';
22+
@import 'styles/images';

FrontEnd/styles/base.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,6 @@ a.big-button {
226226
background-color: var(--announcement-background);
227227
}
228228

229-
.hidden {
230-
display: none;
231-
}
232-
233-
.trimmed {
234-
overflow: hidden;
235-
text-overflow: ellipsis;
236-
}
237-
238229
.count-tag {
239230
padding: 1px 5px;
240231
font-size: 10px;

FrontEnd/styles/colors.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@
187187
--avatar-shadow: 0 2px 2px 3px rgba(0, 0, 0, 5%);
188188

189189
--rss-subscribe-color: var(--orange);
190+
191+
--debug-console-background: var(--light-blue);
192+
--debug-console-border: var(--grey);
193+
--debug-console-button-hover: var(--light-grey);
190194
}
191195

192196
// Dark mode.
@@ -309,5 +313,9 @@
309313
rgba(25, 25, 35, 0%) 50%,
310314
rgba(25, 25, 35, 100%) 100%
311315
);
316+
317+
--debug-console-background: var(--dark-blue);
318+
--debug-console-border: var(--light-grey);
319+
--debug-console-button-hover: var(--dark-grey);
312320
}
313321
}

FrontEnd/styles/debug_panel.scss

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// -------------------------------------------------------------------------
16+
// Debug console panel shared between the site and documentation.
17+
// -------------------------------------------------------------------------
18+
19+
spi-debug-panel {
20+
position: fixed;
21+
bottom: 0;
22+
left: 0;
23+
right: 0;
24+
z-index: 1000;
25+
overflow-y: auto;
26+
max-height: 500px;
27+
min-height: 100px;
28+
padding: 18px;
29+
background-color: var(--debug-console-background);
30+
border-top: 1px solid var(--debug-console-border);
31+
32+
.buttons {
33+
position: absolute;
34+
top: 0;
35+
right: 0;
36+
display: flex;
37+
gap: 10px;
38+
padding: 5px;
39+
40+
button {
41+
cursor: pointer;
42+
padding: 0 6px;
43+
font-size: 10px;
44+
color: var(--page-text);
45+
background: none;
46+
border: none;
47+
border: 1px solid var(--debug-console-border);
48+
border-radius: 50px;
49+
50+
&:hover {
51+
background-color: var(--debug-console-button-hover);
52+
}
53+
}
54+
}
55+
56+
table {
57+
width: 100%;
58+
border-collapse: collapse;
59+
60+
tr {
61+
> td:first-child {
62+
width: 20%;
63+
font-size: 14px;
64+
font-weight: 600;
65+
white-space: nowrap;
66+
}
67+
68+
> td:last-child {
69+
width: 80%;
70+
font-family: monospace;
71+
font-size: 12px;
72+
}
73+
}
74+
75+
td > span {
76+
padding: 3px;
77+
}
78+
79+
td.green > span {
80+
color: var(--very-light-grey);
81+
background-color: var(--mid-green);
82+
}
83+
84+
td.red > span {
85+
color: var(--very-light-grey);
86+
background-color: var(--mid-red);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)