Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function pageUrl(relativePath: string): string {
// `base` itself, and its isActive() comparison ignores .md/.html suffixes and
// /index, so `/api/<stem>/<method>` matches the generated page exactly.
function escapeHtml(text) {
return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return String(text)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}

// opts.indexPrefix — where the collapsible GROUP (API index) links point.
Expand All @@ -65,10 +70,10 @@ function apiSidebar(opts: { indexPrefix?: string; methodPrefix?: string } = {})
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
return manifest.apis.map((api) => {
const children = (api.methods ?? []).map((m) => ({
// v-html surface: default theme renders sidebar text as HTML, so
// every text we emit must be escaped (same as the group label).
text: escapeHtml(m.full),
link: `${methodPrefix}${api.stem}/${m.short}`
// v-html surface: escape both the visible label and tooltip attribute.
text: `<span class="api-method-label" title="${escapeHtml(m.full)}" data-full-name="${escapeHtml(m.full)}"><span aria-hidden="true">${escapeHtml(m.short)}</span><span class="visually-hidden">${escapeHtml(m.full)}</span></span>`,
link: `${methodPrefix}${api.stem}/${m.short}`,
apiMethod: { full: m.full, short: m.short, api: api.displayName }
}))
return {
// Sidebar item text is rendered with v-html by the default theme.
Expand Down
115 changes: 115 additions & 0 deletions docs/.vitepress/theme/ApiSidebarFilter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useData, withBase } from 'vitepress';

type ApiMethod = {
full: string;
short: string;
api: string;
link: string;
};

type SidebarItem = {
link?: string;
items?: SidebarItem[];
apiMethod?: Omit<ApiMethod, 'link'>;
};

const messages: Record<string, { placeholder: string; clear: string; empty: string }> = {
en: { placeholder: 'Filter API methods', clear: 'Clear method filter', empty: 'No matching API methods' },
zh: { placeholder: '筛选 API 方法', clear: '清除方法筛选', empty: '没有匹配的 API 方法' },
ru: { placeholder: 'Фильтр методов API', clear: 'Очистить фильтр методов', empty: 'Методы API не найдены' },
fr: { placeholder: 'Filtrer les méthodes API', clear: 'Effacer le filtre des méthodes', empty: 'Aucune méthode API correspondante' },
de: { placeholder: 'API-Methoden filtern', clear: 'Methodenfilter löschen', empty: 'Keine passenden API-Methoden' },
it: { placeholder: 'Filtra i metodi API', clear: 'Cancella il filtro dei metodi', empty: 'Nessun metodo API corrispondente' },
es: { placeholder: 'Filtrar métodos de API', clear: 'Borrar el filtro de métodos', empty: 'No hay métodos de API coincidentes' },
ko: { placeholder: 'API 메서드 필터링', clear: '메서드 필터 지우기', empty: '일치하는 API 메서드가 없습니다' }
};

const { lang, theme } = useData();
const query = ref('');
const isFiltering = computed(() => query.value.trim().length > 0);
const copy = computed(() => messages[lang.value.split('-')[0]] ?? messages.en);

const methods = computed<ApiMethod[]>(() => {
const found: ApiMethod[] = [];
const seen = new Set<string>();
const visit = (items: SidebarItem[]) => {
for (const item of items) {
if (item.apiMethod && item.link && !seen.has(item.link)) {
seen.add(item.link);
found.push({ ...item.apiMethod, link: item.link });
}
if (item.items) visit(item.items);
}
};
visit(Array.isArray(theme.value.sidebar) ? theme.value.sidebar : []);
return found;
});

const matches = computed(() => {
const needle = query.value.trim().toLocaleLowerCase();
if (!needle) return [];
return methods.value.filter((method) =>
`${method.full} ${method.api}`.toLocaleLowerCase().includes(needle)
);
});

function clear() {
query.value = '';
}
</script>

<template>
<div class="api-sidebar-filter" :data-active="isFiltering ? 'true' : 'false'">
<div class="api-sidebar-filter-control" role="search">
<svg class="api-sidebar-filter-search" viewBox="0 0 20 20" aria-hidden="true">
<path d="M8.5 2a6.5 6.5 0 1 0 3.98 11.65l4.43 4.44 1.42-1.42-4.44-4.43A6.5 6.5 0 0 0 8.5 2Zm0 2a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9Z" />
</svg>
<input
v-model="query"
type="text"
:placeholder="copy.placeholder"
:aria-label="copy.placeholder"
aria-controls="api-sidebar-filter-results"
:aria-expanded="isFiltering"
autocomplete="off"
spellcheck="false"
@keydown.esc="clear"
/>
<button
v-if="isFiltering"
type="button"
class="api-sidebar-filter-clear"
:aria-label="copy.clear"
:title="copy.clear"
@click="clear"
>
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="m5.05 3.64 5 5 5-5 1.41 1.41-5 5 5 5-1.41 1.41-5-5-5 5-1.41-1.41 5-5-5-5 1.41-1.41Z" />
</svg>
</button>
</div>

<div
v-if="isFiltering"
id="api-sidebar-filter-results"
class="api-sidebar-filter-results"
>
<a
v-for="method in matches"
:key="method.full"
class="api-sidebar-filter-result"
:href="withBase(method.link)"
:title="method.full"
@click="clear"
>
<span class="api-sidebar-filter-result-api">{{ method.api }}</span>
<span class="api-sidebar-filter-result-name">{{ method.short }}</span>
</a>
<p v-if="matches.length === 0" class="api-sidebar-filter-empty" role="status">
{{ copy.empty }}
</p>
</div>
</div>
</template>
206 changes: 206 additions & 0 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* 2. Overview card grid (/api/)
* 3. Code cards (Parameters / Response / ops params & examples)
* 4. Table polish (method index tables)
* 5. API sidebar (method labels + filter)
* ------------------------------------------------------------------------- */

/* --- 1. Shared palette (badge chips + code-card accents) ------------------
Expand Down Expand Up @@ -311,3 +312,208 @@ html:not(.dark) .VPNavBarTitle img.logo {
.vp-doc tbody tr:last-child td {
border-bottom: none;
}

/* --- 5. API sidebar (method labels + filter) ------------------------------ */

@media (min-width: 960px) {
:root {
--vp-sidebar-width: 320px;
}
}

.VPSidebarItem .link,
.VPSidebarItem .text {
min-width: 0;
}

.VPSidebarItem .text:has(.api-method-label) {
overflow: hidden;
}

.api-method-label {
position: relative;
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.api-method-label::after {
content: attr(data-full-name);
position: absolute;
top: calc(100% + 4px);
left: 0;
z-index: 20;
width: max-content;
max-width: calc(var(--vp-sidebar-width) - 64px);
padding: 6px 9px;
border: 1px solid var(--vp-c-divider);
border-radius: 6px;
background: var(--vp-c-bg);
box-shadow: var(--vp-shadow-2);
color: var(--vp-c-text-1);
font-family: var(--vp-font-family-mono);
font-size: 12px;
font-weight: 400;
line-height: 1.5;
white-space: normal;
overflow-wrap: anywhere;
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity 120ms ease-out, visibility 120ms ease-out;
}

.VPSidebarItem .link:focus-visible .text:has(.api-method-label),
.VPSidebarItem .link:focus-visible .api-method-label {
overflow: visible;
}

.VPSidebarItem .link:focus-visible .api-method-label::after {
opacity: 1;
visibility: visible;
}

.api-sidebar-filter {
position: relative;
margin-bottom: 16px;
}

.api-sidebar-filter-control {
position: relative;
display: flex;
align-items: center;
}

.api-sidebar-filter-search {
position: absolute;
left: 12px;
width: 16px;
height: 16px;
fill: var(--vp-c-text-3);
pointer-events: none;
}

.api-sidebar-filter input {
width: 100%;
height: 40px;
padding: 0 40px 0 36px;
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
outline: none;
background: var(--vp-c-bg-soft);
color: var(--vp-c-text-1);
font-size: 13px;
transition: border-color 150ms ease-out, background-color 150ms ease-out;
}

.api-sidebar-filter input:hover {
border-color: var(--vp-c-text-3);
}

.api-sidebar-filter input:focus {
border-color: var(--vp-c-brand-1);
background: var(--vp-c-bg);
outline: 2px solid var(--vp-c-brand-1);
outline-offset: 1px;
}

.api-sidebar-filter-clear {
position: absolute;
right: 0;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--vp-c-text-2);
cursor: pointer;
transition: background-color 150ms ease-out, color 150ms ease-out;
}

.api-sidebar-filter-clear:hover {
background: var(--vp-c-default-soft);
color: var(--vp-c-text-1);
}

.api-sidebar-filter-clear:focus-visible {
outline: 2px solid var(--vp-c-brand-1);
outline-offset: -3px;
}

.api-sidebar-filter-clear svg {
width: 14px;
height: 14px;
fill: currentColor;
}

.api-sidebar-filter-results {
padding-top: 6px;
}

.api-sidebar-filter-result {
display: flex;
flex-direction: column;
justify-content: center;
gap: 2px;
min-height: 48px;
margin: 2px 0;
padding: 6px 10px;
border-radius: 6px;
color: var(--vp-c-text-1);
transition: background-color 150ms ease-out, color 150ms ease-out;
}

.api-sidebar-filter-result:hover {
background: var(--vp-c-bg-soft);
color: var(--vp-c-brand-1);
}

.api-sidebar-filter-result:focus-visible {
outline: 2px solid var(--vp-c-brand-1);
outline-offset: 1px;
}

.api-sidebar-filter-result-api,
.api-sidebar-filter-result-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.api-sidebar-filter-result-api {
color: var(--vp-c-text-3);
font-size: 11px;
line-height: 1.4;
}

.api-sidebar-filter-result-name {
font-family: var(--vp-font-family-mono);
font-size: 13px;
font-weight: 500;
line-height: 1.5;
}

.api-sidebar-filter-empty {
margin: 12px 4px;
color: var(--vp-c-text-2);
font-size: 13px;
line-height: 1.6;
}

.VPSidebar > .nav:has(> .api-sidebar-filter[data-active='true']) > .group {
display: none;
}

@media (prefers-reduced-motion: reduce) {
.api-method-label::after,
.api-sidebar-filter input,
.api-sidebar-filter-clear,
.api-sidebar-filter-result {
transition: none;
}
}
12 changes: 8 additions & 4 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Extend the VitePress default theme with site-wide custom styles.
// We deliberately keep the default theme intact (layout, sidebar, search) and
// only layer our own CSS on top — no component rewrites. The one exception is
// DaoTreasuryBalance, a self-contained live-data component used by markdown
// pages (it fetches in the browser only; SSR renders the fallback).
// only layer our own CSS and the sidebar filter slot on top. DaoTreasuryBalance
// is a self-contained live-data component used by markdown pages (it fetches in
// the browser only; SSR renders the fallback).
import DefaultTheme from 'vitepress/theme';
import type { App } from 'vue';
import { h, type App } from 'vue';
import ApiSidebarFilter from './ApiSidebarFilter.vue';
import DaoTreasuryBalance from './DaoTreasuryBalance.vue';
import './custom.css';

export default {
extends: DefaultTheme,
Layout: () => h(DefaultTheme.Layout, null, {
'sidebar-nav-before': () => h(ApiSidebarFilter)
}),
enhanceApp({ app }: { app: App }) {
app.component('DaoTreasuryBalance', DaoTreasuryBalance);
}
Expand Down
Loading