Skip to content
Draft
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
90 changes: 90 additions & 0 deletions .vitepress/theme/components/MavCmdFilter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<script setup>
// Sticky filter for the MAV_CMD sections generated into en/messages/*.md.
// Progressive enhancement: the generated page is complete without this component.
// Commands are wrapped by the generator in <div class="mav-cmd" data-mission data-command ...>;
// filtering just sets data-mav-cmd-filter on <html> and CSS (style.css) hides non-matching wrappers.
import { ref, onMounted, onBeforeUnmount, nextTick } from "vue";
import { useRoute } from "vitepress";

const FILTERS = [
{ key: "all", label: "All" },
{ key: "mission", label: "Mission" },
{ key: "command", label: "Command" },
{ key: "fence", label: "Fence" },
{ key: "rally", label: "Rally" },
];

const mounted = ref(false); // render nothing until JS is running: no dead control
const active = ref("all");
const shown = ref(0);
const total = ref(0);
const route = useRoute();

const cmds = () => Array.from(document.querySelectorAll(".mav-cmd"));

function updateOutline() {
// Outline is built by the theme from all headings; hide entries for hidden commands.
document.querySelectorAll(".VPDocAsideOutline .outline-link").forEach((a) => {
const id = decodeURIComponent((a.getAttribute("href") || "").slice(1));
const target = id && document.getElementById(id);
const wrapper = target && target.closest(".mav-cmd");
const hide = wrapper && wrapper.hasAttribute("data-hidden");
a.parentElement.style.display = hide ? "none" : "";
});
}

function apply(key) {
active.value = key;
const root = document.documentElement;
if (key === "all") root.removeAttribute("data-mav-cmd-filter");
else root.setAttribute("data-mav-cmd-filter", key);
const all = cmds();
let n = 0;
all.forEach((el) => {
const hidden = key !== "all" && !el.hasAttribute("data-" + key);
el.toggleAttribute("data-hidden", hidden);
if (!hidden) n++;
});
total.value = all.length;
shown.value = n;
updateOutline();
}

// A link to a command hidden by the filter would land on nothing: reset to "all".
function revealHashTarget() {
const id = decodeURIComponent(location.hash.slice(1));
const target = id && document.getElementById(id);
const wrapper = target && target.closest(".mav-cmd");
if (wrapper && wrapper.hasAttribute("data-hidden")) {
apply("all");
nextTick(() => target.scrollIntoView());
}
}

onMounted(() => {
mounted.value = true;
apply("all");
window.addEventListener("hashchange", revealHashTarget);
});
onBeforeUnmount(() => {
window.removeEventListener("hashchange", revealHashTarget);
document.documentElement.removeAttribute("data-mav-cmd-filter");
});
</script>

<template>
<div v-if="mounted" class="mav-cmd-filter" role="group" aria-label="Filter commands by where they can be used">
<span class="mav-cmd-filter-label">Show:</span>
<button
v-for="f in FILTERS"
:key="f.key"
type="button"
:class="{ active: active === f.key }"
:aria-pressed="active === f.key"
@click="apply(f.key)"
>
{{ f.label }}
</button>
<span class="mav-cmd-filter-count" aria-live="polite">{{ shown }} of {{ total }}</span>
</div>
</template>
4 changes: 4 additions & 0 deletions .vitepress/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (inBrowser) {
// Support redirect plugin
import Redirect from "./components/Redirect.vue";

// Filter for MAV_CMD sections in generated messages docs
import MavCmdFilter from "./components/MavCmdFilter.vue";

// Tabs: https://github.com/Red-Asuka/vitepress-plugin-tabs
import { Tab, Tabs } from "vue3-tabs-component";
import "@red-asuka/vitepress-plugin-tabs/dist/style.css";
Expand All @@ -34,6 +37,7 @@ export default {
},
enhanceApp({ app, router, siteData }) {
app.component("Redirect", Redirect); //Redirect plugin
app.component("MavCmdFilter", MavCmdFilter);
//Tabs: https://github.com/Red-Asuka/vitepress-plugin-tabs
app.component("Tab", Tab);
app.component("Tabs", Tabs);
Expand Down
40 changes: 39 additions & 1 deletion .vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,42 @@ html {
min-width: 940px !important;
}
}
*/
*/
/* MAV_CMD usage filter (see components/MavCmdFilter.vue) */
.mav-cmd-filter {
position: sticky;
top: var(--vp-nav-height);
z-index: 5;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin: 16px 0;
padding: 8px 12px;
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
background: var(--vp-c-bg-soft);
}
.mav-cmd-filter button {
padding: 2px 12px;
border: 1px solid var(--vp-c-divider);
border-radius: 12px;
background: var(--vp-c-bg);
font-size: 13px;
}
.mav-cmd-filter button.active {
border-color: var(--vp-c-brand-1);
background: var(--vp-c-brand-soft);
color: var(--vp-c-brand-1);
}
.mav-cmd-filter-count {
margin-left: auto;
font-size: 13px;
color: var(--vp-c-text-2);
}
html[data-mav-cmd-filter="mission"] .mav-cmd:not([data-mission]),
html[data-mav-cmd-filter="command"] .mav-cmd:not([data-command]),
html[data-mav-cmd-filter="fence"] .mav-cmd:not([data-fence]),
html[data-mav-cmd-filter="rally"] .mav-cmd:not([data-rally]) {
display: none;
}
12 changes: 10 additions & 2 deletions en/messages/ASLUAV.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ Value | Name | Description

## Commands (MAV_CMD) {#mav_commands}

<MavCmdFilter />

<div class="mav-cmd">

### MAV_CMD_RESET_MPPT (40001) {#MAV_CMD_RESET_MPPT}

Mission command to reset Maximum Power Point Tracker (MPPT)
Expand All @@ -394,8 +398,11 @@ Param (Label) | Description
4 | Empty
5 | Empty
6 | Empty
7 | Empty
7 | Empty

</div>

<div class="mav-cmd">

### MAV_CMD_PAYLOAD_CONTROL (40002) {#MAV_CMD_PAYLOAD_CONTROL}

Expand All @@ -409,6 +416,7 @@ Param (Label) | Description
4 | Empty
5 | Empty
6 | Empty
7 | Empty
7 | Empty

</div>

37 changes: 30 additions & 7 deletions en/messages/AVSSUAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ Value | Name | Description

## Commands (MAV_CMD) {#mav_commands}

<MavCmdFilter />

<div class="mav-cmd">

### MAV_CMD_PRS_SET_ARM (60050) {#MAV_CMD_PRS_SET_ARM}

AVSS defined command. Set PRS arm statuses.
Expand All @@ -156,8 +160,11 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_GET_ARM (60051) {#MAV_CMD_PRS_GET_ARM}

Expand All @@ -171,8 +178,11 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_GET_BATTERY (60052) {#MAV_CMD_PRS_GET_BATTERY}

Expand All @@ -186,8 +196,11 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_GET_ERR (60053) {#MAV_CMD_PRS_GET_ERR}

Expand All @@ -201,8 +214,11 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_SET_ARM_ALTI (60070) {#MAV_CMD_PRS_SET_ARM_ALTI}

Expand All @@ -216,8 +232,11 @@ Param (Label) | Description | Units
4 | User defined |
5 | User defined |
6 | User defined |
7 | User defined |
7 | User defined |

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_GET_ARM_ALTI (60071) {#MAV_CMD_PRS_GET_ARM_ALTI}

Expand All @@ -231,8 +250,11 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

<div class="mav-cmd">

### MAV_CMD_PRS_SHUTDOWN (60072) {#MAV_CMD_PRS_SHUTDOWN}

Expand All @@ -246,6 +268,7 @@ Param (Label) | Description
4 | User defined
5 | User defined
6 | User defined
7 | User defined
7 | User defined

</div>

5 changes: 5 additions & 0 deletions en/messages/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ The following sections list all entities in the dialect (both included and defin

## Commands (MAV_CMD) {#mav_commands}

<MavCmdFilter />

<div class="mav-cmd">

### MAV_CMD_DUMMY_ALL (393) — [WIP] {#MAV_CMD_DUMMY_ALL}

<span class="warning">**WORK IN PROGRESS**: Do not use in stable production environments (it may change).</span>
Expand All @@ -83,4 +87,5 @@ It not be used, and will be removed when the toolchain is fixed.
Param (Label) | Description
--- | ---

</div>

Loading
Loading