Skip to content

Commit 76aa3e8

Browse files
committed
chore: save generation result before manual editing for easier port after experimentation
1 parent 7215be1 commit 76aa3e8

File tree

62 files changed

+11319
-0
lines changed

Some content is hidden

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

62 files changed

+11319
-0
lines changed

rework-prototype/content/fsdocs-default.css

Lines changed: 1397 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const expandDetails = !!JSON.parse(localStorage.getItem('details-expanded'));
2+
3+
addEventListener('load', _ => {
4+
if (expandDetails) {
5+
for (const details of document.getElementsByTagName('details')) {
6+
details.setAttribute('open', 'true');
7+
}
8+
}
9+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
2+
3+
const detailsExpanded = !!JSON.parse(localStorage.getItem('details-expanded'));
4+
5+
export class DetailsToggle extends LitElement {
6+
static properties = {
7+
_detailsExpanded: { state: true, type: Boolean },
8+
};
9+
10+
constructor() {
11+
super();
12+
this._detailsExpanded = detailsExpanded;
13+
document.addEventListener('detailstoggled', e => this._detailsExpanded = !!e?.detail?.expanding);
14+
}
15+
16+
static styles = css`
17+
:host {
18+
cursor: pointer;
19+
}
20+
`;
21+
22+
toggleDetails() {
23+
this._detailsExpanded = !this._detailsExpanded;
24+
localStorage.setItem('details-expanded', JSON.stringify(this._detailsExpanded));
25+
if (this._detailsExpanded) {
26+
for (const details of document.getElementsByTagName('details')) {
27+
details.setAttribute('open', 'true');
28+
}
29+
} else {
30+
for (const details of document.getElementsByTagName('details')) {
31+
details.removeAttribute('open');
32+
}
33+
}
34+
document.dispatchEvent(new CustomEvent('detailstoggled', { detail: { expanding: this._detailsExpanded } }));
35+
}
36+
37+
render() {
38+
const icon = this._detailsExpanded ? 'carbon:collapse-categories' : 'carbon:expand-categories';
39+
const title = this._detailsExpanded ? 'Collapse details' : 'Expand details';
40+
return html`
41+
<iconify-icon width="24" height="24" icon="${icon}" title="${title}" style="color:var(--header-link-color)" @click=${this.toggleDetails}></iconify-icon>
42+
`;
43+
}
44+
}
45+
46+
customElements.define('fsdocs-details-toggle', DetailsToggle);
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import Fuse from "https://esm.sh/[email protected]";
2+
3+
const searchBtn = document.querySelector("#search-btn");
4+
5+
function hideSearchBtn() {
6+
// Hide search icon if we can't search in the first place.
7+
searchBtn.style.display = 'none';
8+
}
9+
10+
function debounce(mainFunction, delay) {
11+
// Declare a variable called 'timer' to store the timer ID
12+
let timer;
13+
14+
// Return an anonymous function that takes in any number of arguments
15+
return function (...args) {
16+
// Clear the previous timer to prevent the execution of 'mainFunction'
17+
clearTimeout(timer);
18+
19+
// Set a new timer that will execute 'mainFunction' after the specified delay
20+
timer = setTimeout(() => {
21+
mainFunction(...args);
22+
}, delay);
23+
};
24+
}
25+
26+
const root = document.documentElement.getAttribute("data-root");
27+
if (root && searchBtn) {
28+
let fuse = null;
29+
const searchIndexUrl = `${root}/index.json`;
30+
fetch(searchIndexUrl, {})
31+
.then(response => response.json())
32+
.then(index => {
33+
fuse = new Fuse(index, {
34+
includeScore: true,
35+
keys: ['uri', 'title', 'content', 'headings'],
36+
includeMatches: true,
37+
limit: 20,
38+
ignoreLocation: true,
39+
threshold: 0.6,
40+
minMatchCharLength: 2,
41+
ignoreFieldNorm: true,
42+
shouldSort: true
43+
});
44+
})
45+
.catch(() => {
46+
hideSearchBtn();
47+
})
48+
49+
const searchDialog = document.querySelector("dialog");
50+
const empty = document.querySelector("dialog .empty");
51+
const resultsElement = document.querySelector("dialog ul");
52+
const searchBox = document.querySelector("dialog input[type=search]");
53+
54+
searchBtn.addEventListener("click", () => {
55+
searchDialog.showModal();
56+
})
57+
58+
searchDialog.addEventListener("click", ev => {
59+
if (ev.target.tagName === "DIALOG") {
60+
searchBox.value = '';
61+
searchDialog.close()
62+
}
63+
})
64+
65+
function searchAux(searchTerm) {
66+
if (!fuse) return;
67+
68+
const results = fuse.search(searchTerm);
69+
if (results.length === 0) {
70+
clearResults();
71+
empty.textContent = "No results were found";
72+
} else {
73+
if (location.hostname === 'localhost'){
74+
console.table(results);
75+
}
76+
77+
empty.style.display = 'none';
78+
const newResultNodes =
79+
results
80+
.map(result => {
81+
const item = result.item;
82+
const li = document.createElement("li");
83+
const a = document.createElement("a");
84+
a.setAttribute("href", item.uri);
85+
const icon = document.createElement("iconify-icon");
86+
icon.setAttribute("width", "24");
87+
icon.setAttribute("height", "24");
88+
icon.setAttribute("icon", item.type === "content" ? "iconoir:page" : "bxs:file-doc")
89+
a.append(icon, item.title);
90+
li.appendChild(a);
91+
return li;
92+
});
93+
resultsElement.replaceChildren(...newResultNodes);
94+
}
95+
}
96+
97+
const search = debounce(searchAux, 250);
98+
99+
function clearResults() {
100+
empty.style.display = 'block';
101+
resultsElement.replaceChildren();
102+
}
103+
104+
searchBox.addEventListener('keyup', ev => {
105+
ev.stopPropagation();
106+
const searchTerm = ev.target.value;
107+
if (!searchTerm) {
108+
empty.textContent = "Type something to start searching.";
109+
clearResults();
110+
} else {
111+
search(searchTerm);
112+
}
113+
});
114+
115+
window.addEventListener('keyup', ev => {
116+
if (ev.key === 'Escape' && searchDialog.open) {
117+
searchDialog.close();
118+
}
119+
120+
if (ev.key === '/' && !searchDialog.open) {
121+
searchDialog.showModal();
122+
}
123+
})
124+
} else {
125+
hideSearchBtn();
126+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const prefersDark = window.matchMedia("@media (prefers-color-scheme: dark)").matches;
2+
let currentTheme = localStorage.getItem('theme') ?? (prefersDark ? 'dark' : 'light');
3+
if (currentTheme === 'dark') {
4+
window.document.documentElement.setAttribute("data-theme", 'dark');
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {LitElement, html, css} from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
2+
3+
const prefersDark = window.matchMedia("@media (prefers-color-scheme: dark)").matches;
4+
let currentTheme = localStorage.getItem('theme') ?? (prefersDark ? 'dark' : 'light');
5+
6+
export class ThemeToggle extends LitElement {
7+
static properties = {
8+
_theme: {state: true, type: String},
9+
};
10+
11+
constructor() {
12+
super();
13+
this._theme = currentTheme;
14+
}
15+
16+
static styles = css`
17+
:host {
18+
cursor: pointer;
19+
box-sizing: border-box;
20+
transform: translateY(3px);
21+
}
22+
`;
23+
24+
changeTheme() {
25+
this._theme = this._theme === 'light' ? 'dark' : 'light';
26+
localStorage.setItem('theme', this._theme);
27+
window.document.documentElement.setAttribute("data-theme", this._theme);
28+
}
29+
30+
render() {
31+
const icon = this._theme === 'light' ? 'basil:moon-solid' : 'basil:sun-solid';
32+
return html`
33+
<iconify-icon width="30" height="30" icon="${icon}" style="color:var(--header-link-color)" @click=${this.changeTheme}></iconify-icon>
34+
`;
35+
}
36+
}
37+
38+
customElements.define('fsdocs-theme-toggle', ThemeToggle);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Override any variables here */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Automatically scroll to the active aside menu item.
2+
const mainMenu = document.getElementById('fsdocs-main-menu');
3+
function scrollToActiveItem(activeItem) {
4+
const halfMainMenuHeight = mainMenu.offsetHeight / 2
5+
if(activeItem.offsetTop > halfMainMenuHeight){
6+
mainMenu.scrollTop = (activeItem.offsetTop - halfMainMenuHeight) - (activeItem.offsetHeight / 2);
7+
}
8+
}
9+
10+
const activeItem = document.querySelector("aside .nav-item.active");
11+
if (activeItem && mainMenu) {
12+
scrollToActiveItem(activeItem);
13+
}
14+
15+
function scrollToAndExpandSelectedMember() {
16+
if (location.hash) {
17+
const details = document.querySelector(`tr > td.fsdocs-member-usage:has(a[href='${location.hash}']) ~ td.fsdocs-member-xmldoc > details`);
18+
details?.setAttribute('open', 'true');
19+
const header = document.querySelector(`a[href='${location.hash}']`);
20+
header?.scrollIntoView({ behavior: 'instant'});
21+
}
22+
}
23+
24+
scrollToAndExpandSelectedMember();
25+
addEventListener('hashchange', scrollToAndExpandSelectedMember);
26+
27+
if(location.pathname.startsWith('/reference/')) {
28+
// Scroll to API Reference header
29+
const navHeaders = document.querySelectorAll(".nav-header");
30+
for (const navHeader of navHeaders) {
31+
if (navHeader.textContent && navHeader.textContent.trim() === 'API Reference') {
32+
scrollToActiveItem(navHeader);
33+
}
34+
}
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
let currentTip = null;
2+
let currentTipElement = null;
3+
4+
function hideTip(evt, name, unique) {
5+
const el = document.getElementById(name);
6+
el.style.display = "none";
7+
currentTip = null;
8+
}
9+
10+
function hideUsingEsc(e) {
11+
hideTip(e, currentTipElement, currentTip);
12+
}
13+
14+
function showTip(evt, name, unique, owner) {
15+
document.onkeydown = hideUsingEsc;
16+
if (currentTip === unique) return;
17+
currentTip = unique;
18+
currentTipElement = name;
19+
20+
const offset = 20;
21+
let x = evt.clientX;
22+
let y = evt.clientY + offset;
23+
24+
const el = document.getElementById(name);
25+
el.style.position = "absolute";
26+
el.style.display = "block";
27+
el.style.left = `${x}px`;
28+
el.style.top = `${y}px`;
29+
const maxWidth = document.documentElement.clientWidth - x - 16;
30+
el.style.maxWidth = `${maxWidth}px`;
31+
32+
const rect = el.getBoundingClientRect();
33+
// Move tooltip if it is out of sight
34+
if(rect.bottom > window.innerHeight) {
35+
y = y - el.clientHeight - offset;
36+
el.style.top = `${y}px`;
37+
}
38+
39+
if (rect.right > window.innerWidth) {
40+
x = y - el.clientWidth - offset;
41+
el.style.left = `${x}px`;
42+
const maxWidth = document.documentElement.clientWidth - x - 16;
43+
el.style.maxWidth = `${maxWidth}px`;
44+
}
45+
}
46+
47+
function Clipboard_CopyTo(value) {
48+
const tempInput = document.createElement("input");
49+
tempInput.value = value;
50+
document.body.appendChild(tempInput);
51+
tempInput.select();
52+
document.execCommand("copy");
53+
document.body.removeChild(tempInput);
54+
}
55+
56+
window.showTip = showTip;
57+
window.hideTip = hideTip;
58+
// Used by API documentation
59+
window.Clipboard_CopyTo = Clipboard_CopyTo;
Loading

0 commit comments

Comments
 (0)