mirror of
https://github.com/ziglang/zig.git
synced 2025-12-21 05:33:15 +00:00
Merge pull request #12347 from r00ster91/nicedocs
autodoc: various improvements
This commit is contained in:
commit
1db99b08e2
@ -25,6 +25,7 @@
|
||||
--search-bg-color-focus: #ffffff;
|
||||
--search-sh-color: rgba(0, 0, 0, 0.18);
|
||||
--help-sh-color: rgba(0, 0, 0, 0.75);
|
||||
--help-bg-color: #aaa;
|
||||
}
|
||||
|
||||
html, body { margin: 0; padding: 0; height: 100%; }
|
||||
@ -190,11 +191,11 @@
|
||||
box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);
|
||||
}
|
||||
|
||||
.docs .search::placeholder {
|
||||
font-size: 1rem;
|
||||
font-family: var(--ui);
|
||||
color: var(--tx-color);
|
||||
opacity: 0.5;
|
||||
#searchPlaceholder {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
top: 5px;
|
||||
left: 5px;
|
||||
}
|
||||
|
||||
.docs a {
|
||||
@ -294,7 +295,7 @@
|
||||
padding: 1px 1em;
|
||||
}
|
||||
|
||||
/* help dialog */
|
||||
/* help modal */
|
||||
.help-modal {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
@ -308,13 +309,13 @@
|
||||
backdrop-filter: blur(0.3em);
|
||||
}
|
||||
|
||||
.help-modal > .dialog {
|
||||
.help-modal > .modal {
|
||||
max-width: 97vw;
|
||||
max-height: 97vh;
|
||||
overflow: auto;
|
||||
font-size: 1rem;
|
||||
color: #fff;
|
||||
background-color: #333;
|
||||
background-color: var(--help-bg-color);
|
||||
border: 0.125rem solid #000;
|
||||
box-shadow: 0 0.5rem 2.5rem 0.3rem var(--help-sh-color);
|
||||
}
|
||||
@ -335,7 +336,7 @@
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.help-modal kbd {
|
||||
kbd {
|
||||
display: inline-block;
|
||||
padding: 0.3em 0.2em;
|
||||
font-size: 1.2em;
|
||||
@ -348,7 +349,7 @@
|
||||
border-bottom-color: #c6cbd1;
|
||||
border: solid 0.0625em;
|
||||
border-radius: 0.1875em;
|
||||
box-shadow: inset 0 -0.0625em 0 #c6cbd1;
|
||||
box-shadow: inset 0 -0.2em 0 #c6cbd1;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
@ -391,7 +392,6 @@
|
||||
|
||||
/* dark mode */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
|
||||
:root {
|
||||
--tx-color: #bbb;
|
||||
--bg-color: #111;
|
||||
@ -408,6 +408,7 @@
|
||||
--search-bg-color-focus: #000;
|
||||
--search-sh-color: rgba(255, 255, 255, 0.28);
|
||||
--help-sh-color: rgba(142, 142, 142, 0.5);
|
||||
--help-bg-color: #333;
|
||||
}
|
||||
|
||||
.docs pre {
|
||||
@ -457,7 +458,6 @@
|
||||
.tok-type {
|
||||
color: #68f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 750px) {
|
||||
@ -615,7 +615,10 @@
|
||||
<div class="flex-right">
|
||||
<div class="wrap">
|
||||
<section class="docs">
|
||||
<input type="search" class="search" id="search" autocomplete="off" spellcheck="false" placeholder="`s` to search, `?` to see more options">
|
||||
<div style="position: relative">
|
||||
<span id="searchPlaceholder"><kbd>S</kbd> to search, <kbd>?</kbd> for more options</span>
|
||||
<input type="search" class="search" id="search" autocomplete="off" spellcheck="false" disabled>
|
||||
</div>
|
||||
<p id="status">Loading...</p>
|
||||
<div id="sectNav" class="hidden"><ul id="listNav"></ul></div>
|
||||
<div id="fnProto" class="hidden">
|
||||
@ -708,12 +711,12 @@
|
||||
<div class="flex-filler"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="helpDialog" class="hidden">
|
||||
<div id="helpModal" class="hidden">
|
||||
<div class="help-modal">
|
||||
<div class="dialog">
|
||||
<div class="modal">
|
||||
<h1>Keyboard Shortcuts</h1>
|
||||
<dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd></dl>
|
||||
<dl><dt><kbd>Esc</kbd></dt><dd>Clear focus; close this dialog</dd></dl>
|
||||
<dl><dt><kbd>?</kbd></dt><dd>Show this help modal</dd></dl>
|
||||
<dl><dt><kbd>Esc</kbd></dt><dd>Clear focus; close this modal</dd></dl>
|
||||
<dl><dt><kbd>s</kbd></dt><dd>Focus the search field</dd></dl>
|
||||
<dl><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd></dl>
|
||||
<dl><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd></dl>
|
||||
|
||||
122
lib/docs/main.js
122
lib/docs/main.js
@ -3,53 +3,54 @@
|
||||
var zigAnalysis;
|
||||
|
||||
(function () {
|
||||
let domStatus = document.getElementById("status");
|
||||
let domSectNav = document.getElementById("sectNav");
|
||||
let domListNav = document.getElementById("listNav");
|
||||
let domSectMainPkg = document.getElementById("sectMainPkg");
|
||||
let domSectPkgs = document.getElementById("sectPkgs");
|
||||
let domListPkgs = document.getElementById("listPkgs");
|
||||
let domSectTypes = document.getElementById("sectTypes");
|
||||
let domListTypes = document.getElementById("listTypes");
|
||||
let domSectTests = document.getElementById("sectTests");
|
||||
let domListTests = document.getElementById("listTests");
|
||||
let domSectNamespaces = document.getElementById("sectNamespaces");
|
||||
let domListNamespaces = document.getElementById("listNamespaces");
|
||||
let domSectErrSets = document.getElementById("sectErrSets");
|
||||
let domListErrSets = document.getElementById("listErrSets");
|
||||
let domSectFns = document.getElementById("sectFns");
|
||||
let domListFns = document.getElementById("listFns");
|
||||
let domSectFields = document.getElementById("sectFields");
|
||||
let domListFields = document.getElementById("listFields");
|
||||
let domSectGlobalVars = document.getElementById("sectGlobalVars");
|
||||
let domListGlobalVars = document.getElementById("listGlobalVars");
|
||||
let domSectValues = document.getElementById("sectValues");
|
||||
let domListValues = document.getElementById("listValues");
|
||||
let domFnProto = document.getElementById("fnProto");
|
||||
let domFnProtoCode = document.getElementById("fnProtoCode");
|
||||
let domSectParams = document.getElementById("sectParams");
|
||||
let domListParams = document.getElementById("listParams");
|
||||
let domTldDocs = document.getElementById("tldDocs");
|
||||
let domSectFnErrors = document.getElementById("sectFnErrors");
|
||||
let domListFnErrors = document.getElementById("listFnErrors");
|
||||
let domTableFnErrors = document.getElementById("tableFnErrors");
|
||||
let domFnErrorsAnyError = document.getElementById("fnErrorsAnyError");
|
||||
let domFnExamples = document.getElementById("fnExamples");
|
||||
// let domListFnExamples = (document.getElementById("listFnExamples"));
|
||||
let domFnNoExamples = document.getElementById("fnNoExamples");
|
||||
let domDeclNoRef = document.getElementById("declNoRef");
|
||||
let domSearch = document.getElementById("search");
|
||||
let domSectSearchResults = document.getElementById("sectSearchResults");
|
||||
let domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
|
||||
const domStatus = document.getElementById("status");
|
||||
const domSectNav = document.getElementById("sectNav");
|
||||
const domListNav = document.getElementById("listNav");
|
||||
const domSectMainPkg = document.getElementById("sectMainPkg");
|
||||
const domSectPkgs = document.getElementById("sectPkgs");
|
||||
const domListPkgs = document.getElementById("listPkgs");
|
||||
const domSectTypes = document.getElementById("sectTypes");
|
||||
const domListTypes = document.getElementById("listTypes");
|
||||
const domSectTests = document.getElementById("sectTests");
|
||||
const domListTests = document.getElementById("listTests");
|
||||
const domSectNamespaces = document.getElementById("sectNamespaces");
|
||||
const domListNamespaces = document.getElementById("listNamespaces");
|
||||
const domSectErrSets = document.getElementById("sectErrSets");
|
||||
const domListErrSets = document.getElementById("listErrSets");
|
||||
const domSectFns = document.getElementById("sectFns");
|
||||
const domListFns = document.getElementById("listFns");
|
||||
const domSectFields = document.getElementById("sectFields");
|
||||
const domListFields = document.getElementById("listFields");
|
||||
const domSectGlobalVars = document.getElementById("sectGlobalVars");
|
||||
const domListGlobalVars = document.getElementById("listGlobalVars");
|
||||
const domSectValues = document.getElementById("sectValues");
|
||||
const domListValues = document.getElementById("listValues");
|
||||
const domFnProto = document.getElementById("fnProto");
|
||||
const domFnProtoCode = document.getElementById("fnProtoCode");
|
||||
const domSectParams = document.getElementById("sectParams");
|
||||
const domListParams = document.getElementById("listParams");
|
||||
const domTldDocs = document.getElementById("tldDocs");
|
||||
const domSectFnErrors = document.getElementById("sectFnErrors");
|
||||
const domListFnErrors = document.getElementById("listFnErrors");
|
||||
const domTableFnErrors = document.getElementById("tableFnErrors");
|
||||
const domFnErrorsAnyError = document.getElementById("fnErrorsAnyError");
|
||||
const domFnExamples = document.getElementById("fnExamples");
|
||||
// const domListFnExamples = (document.getElementById("listFnExamples"));
|
||||
const domFnNoExamples = document.getElementById("fnNoExamples");
|
||||
const domDeclNoRef = document.getElementById("declNoRef");
|
||||
const domSearch = document.getElementById("search");
|
||||
const domSectSearchResults = document.getElementById("sectSearchResults");
|
||||
const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
|
||||
|
||||
let domListSearchResults = document.getElementById("listSearchResults");
|
||||
let domSectSearchNoResults = document.getElementById("sectSearchNoResults");
|
||||
let domSectInfo = document.getElementById("sectInfo");
|
||||
// let domTdTarget = (document.getElementById("tdTarget"));
|
||||
let domPrivDeclsBox = document.getElementById("privDeclsBox");
|
||||
let domTdZigVer = document.getElementById("tdZigVer");
|
||||
let domHdrName = document.getElementById("hdrName");
|
||||
let domHelpModal = document.getElementById("helpDialog");
|
||||
const domListSearchResults = document.getElementById("listSearchResults");
|
||||
const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
|
||||
const domSectInfo = document.getElementById("sectInfo");
|
||||
// const domTdTarget = (document.getElementById("tdTarget"));
|
||||
const domPrivDeclsBox = document.getElementById("privDeclsBox");
|
||||
const domTdZigVer = document.getElementById("tdZigVer");
|
||||
const domHdrName = document.getElementById("hdrName");
|
||||
const domHelpModal = document.getElementById("helpModal");
|
||||
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
|
||||
|
||||
let searchTimer = null;
|
||||
let searchTrimResults = true;
|
||||
@ -104,7 +105,15 @@ var zigAnalysis;
|
||||
// map of decl index to list of comptime fn calls
|
||||
// let nodesToCallsMap = indexNodesToCalls();
|
||||
|
||||
domSearch.disabled = false;
|
||||
domSearch.addEventListener("keydown", onSearchKeyDown, false);
|
||||
domSearch.addEventListener("focus", ev => {
|
||||
domSearchPlaceholder.classList.add("hidden");
|
||||
});
|
||||
domSearch.addEventListener("blur", ev => {
|
||||
if (domSearch.value.length == 0)
|
||||
domSearchPlaceholder.classList.remove("hidden");
|
||||
});
|
||||
domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
|
||||
function onClickSearchShowAllResults(ev) {
|
||||
ev.preventDefault();
|
||||
@ -142,6 +151,12 @@ var zigAnalysis;
|
||||
location.hash = "#root";
|
||||
}
|
||||
|
||||
// make the modal disappear if you click outside it
|
||||
domHelpModal.addEventListener("click", ev => {
|
||||
if (ev.target.className == "help-modal")
|
||||
domHelpModal.classList.add("hidden");
|
||||
});
|
||||
|
||||
window.addEventListener("hashchange", onHashChange, false);
|
||||
window.addEventListener("keydown", onWindowKeyDown, false);
|
||||
onHashChange();
|
||||
@ -2628,6 +2643,10 @@ var zigAnalysis;
|
||||
updateCurNav();
|
||||
if (domSearch.value !== curNavSearch) {
|
||||
domSearch.value = curNavSearch;
|
||||
if (domSearch.value.length == 0)
|
||||
domSearchPlaceholder.classList.remove("hidden");
|
||||
else
|
||||
domSearchPlaceholder.classList.add("hidden");
|
||||
}
|
||||
render();
|
||||
if (imFeelingLucky) {
|
||||
@ -2749,7 +2768,7 @@ var zigAnalysis;
|
||||
});
|
||||
}
|
||||
|
||||
// Generic fun/ction
|
||||
// Generic function
|
||||
if (value.kind == typeKinds.Fn && value.generic_ret != null) {
|
||||
let resolvedVal = resolveValue({ expr: value.generic_ret });
|
||||
if ("type" in resolvedVal.expr) {
|
||||
@ -3343,12 +3362,11 @@ var zigAnalysis;
|
||||
return operatorCompare(a.decl.name, b.decl.name);
|
||||
});
|
||||
|
||||
|
||||
var searchTrimmed = false
|
||||
var searchTrimResultsMaxItems = 200
|
||||
let searchTrimmed = false;
|
||||
const searchTrimResultsMaxItems = 200;
|
||||
if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) {
|
||||
matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems)
|
||||
searchTrimmed = true
|
||||
matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems);
|
||||
searchTrimmed = true;
|
||||
}
|
||||
|
||||
// Build up the list of search results
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user