262 lines
7.9 KiB
Vue
262 lines
7.9 KiB
Vue
<script setup>
|
|
import { computed, nextTick, onMounted, ref } from 'vue';
|
|
import { SetupHandle, SetSize, ResetPosition, Top, SetResizable, SetMinSize } from '@/services/Windows';
|
|
|
|
import WindowHandle from './partials/WindowHandle.vue';
|
|
import { GetDocsFirstSlug, GetDocsNav, GetDocsPage } from '~/services/Docs';
|
|
|
|
// La documentació dins d'una finestra: el sumari a l'esquerra i la pàgina al centre, amb el
|
|
// mateix contingut de app/content/docs que la pàgina pública de /docs (mira ~/services/Docs.js).
|
|
// El sumari no porta enlloc amb rutes sinó amb estat propi, així obrir la documentació dins
|
|
// d'una campanya no deixa les notes obertes enrere.
|
|
const props = defineProps(['data']);
|
|
const id = props.data.id;
|
|
|
|
const handle = ref(null);
|
|
const wrapper = ref(null);
|
|
const reading = ref(null);
|
|
|
|
const nav = GetDocsNav();
|
|
const slug = ref(GetDocsFirstSlug());
|
|
const page = computed(() => GetDocsPage(slug.value));
|
|
|
|
function GoTo(target) {
|
|
if (!GetDocsPage(target)) return;
|
|
slug.value = target;
|
|
// Cada pàgina es comença a dalt, com faria el navegador.
|
|
nextTick(() => { if (reading.value) reading.value.scrollTop = 0; });
|
|
}
|
|
|
|
// Els enllaços que el markdown porta a dins (`[Foundry](/docs/foundry)`) i els seus apartats
|
|
// s'han de seguir dins la finestra: sortir-ne per via d'una ruta deixaria la campanya enrere.
|
|
function OnContentClick(event) {
|
|
const link = event.target?.closest?.('a');
|
|
if (!link) return;
|
|
|
|
const href = link.getAttribute('href') || '';
|
|
|
|
// Un apartat de la pàgina: el que fila és la columna de lectura, no la pantalla.
|
|
if (href.startsWith('#')) {
|
|
if (href.length < 2) return;
|
|
const heading = reading.value?.querySelector('#' + CSS.escape(href.slice(1)));
|
|
if (!heading) return;
|
|
event.preventDefault();
|
|
heading.scrollIntoView({ block: 'start' });
|
|
return;
|
|
}
|
|
|
|
const inside = /^\/docs\/?([a-z0-9-]*)$/.exec(href);
|
|
if (inside) {
|
|
event.preventDefault();
|
|
GoTo(inside[1] || GetDocsFirstSlug());
|
|
return;
|
|
}
|
|
|
|
// Fora de la documentació: una pestanya nova, que la campanya no es mou d'aquí.
|
|
if (href && !href.startsWith('/')) {
|
|
event.preventDefault();
|
|
window.open(href, '_blank', 'noopener');
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
Top(wrapper);
|
|
SetupHandle(id, handle);
|
|
SetSize(id, {
|
|
width: Math.max(620, Math.min(1000, window.innerWidth - 24)),
|
|
height: Math.max(420, Math.min(780, window.innerHeight - 32))
|
|
});
|
|
ResetPosition(id, 'center');
|
|
SetResizable(id, true);
|
|
SetMinSize(id, { width: 620, height: 420 });
|
|
});
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
|
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
|
|
|
<!-- Body -->
|
|
<div class="docs-body">
|
|
<aside class="docs-contents" :aria-label="$t('docs.contents')">
|
|
<section v-for="group in nav" :key="group.key" class="docs-group">
|
|
<h2 class="docs-group-title">{{ $t(`docs.groups.${group.key}`) }}</h2>
|
|
<ul>
|
|
<li v-for="entry in group.pages" :key="entry.slug">
|
|
<button
|
|
type="button"
|
|
class="docs-nav-link sound-click"
|
|
:class="{ active: entry.slug === slug }"
|
|
v-on:click="GoTo(entry.slug)"
|
|
>{{ entry.title }}</button>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</aside>
|
|
|
|
<div class="docs-reading" ref="reading">
|
|
<template v-if="page">
|
|
<article class="docs-article" v-on:click="OnContentClick">
|
|
<p class="docs-kicker">{{ $t(`docs.groups.${page.group}`) }}</p>
|
|
<!-- El contingut és markdown nostre, de app/content/docs -->
|
|
<div class="docs-markdown" v-html="page.html"></div>
|
|
</article>
|
|
|
|
<nav class="docs-pager">
|
|
<button
|
|
v-if="page.previous"
|
|
type="button"
|
|
class="docs-pager-link sound-click"
|
|
v-on:click="GoTo(page.previous.slug)"
|
|
>
|
|
<span class="docs-pager-label">{{ $t('docs.previous') }}</span>
|
|
<strong>{{ page.previous.title }}</strong>
|
|
</button>
|
|
<button
|
|
v-if="page.next"
|
|
type="button"
|
|
class="docs-pager-link next sound-click"
|
|
v-on:click="GoTo(page.next.slug)"
|
|
>
|
|
<span class="docs-pager-label">{{ $t('docs.next') }}</span>
|
|
<strong>{{ page.next.title }}</strong>
|
|
</button>
|
|
</nav>
|
|
</template>
|
|
|
|
<article v-else class="docs-article">
|
|
<h1>{{ $t('docs.title') }}</h1>
|
|
<p>{{ $t('docs.not-found', { page: slug }) }}</p>
|
|
</article>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
/* El sumari i la lectura són les dues columnes d'una finestra: cada una fila per la seva,
|
|
res d'una pantalla d'alçada ni de sticky, que la finestra ja és el que es mou. */
|
|
.docs-body {
|
|
display: flex;
|
|
flex: 1;
|
|
width: 100%;
|
|
min-height: 0;
|
|
}
|
|
|
|
.docs-contents {
|
|
flex: 0 0 212px;
|
|
min-width: 0;
|
|
box-sizing: border-box;
|
|
padding: 14px 10px;
|
|
border-right: 1px solid var(--color-border);
|
|
overflow-y: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 16px;
|
|
}
|
|
|
|
.docs-group-title {
|
|
margin: 0 0 6px 0;
|
|
font-family: 'MrEavesRemake', serif;
|
|
font-size: 0.78rem;
|
|
font-weight: normal;
|
|
letter-spacing: 0.08em;
|
|
text-transform: uppercase;
|
|
color: var(--color-gray);
|
|
}
|
|
|
|
.docs-contents ul {
|
|
margin: 0;
|
|
padding: 0;
|
|
list-style: none;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 2px;
|
|
}
|
|
|
|
/* Les pàgines del sumari són botons: una finestra no té rutes a seguir. */
|
|
.docs-nav-link {
|
|
width: 100%;
|
|
margin: 0;
|
|
padding: 6px 9px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
box-shadow: none;
|
|
background-color: transparent;
|
|
font-size: 0.95rem;
|
|
line-height: 1.35;
|
|
text-align: left;
|
|
color: var(--color-text);
|
|
}
|
|
|
|
.docs-nav-link:hover {
|
|
background-color: var(--color-hover);
|
|
}
|
|
|
|
.docs-nav-link.active {
|
|
background-color: var(--color-background-soft);
|
|
color: var(--color-link);
|
|
}
|
|
|
|
.docs-reading {
|
|
flex: 1;
|
|
min-width: 0;
|
|
box-sizing: border-box;
|
|
padding: 20px 26px 40px 26px;
|
|
overflow-y: auto;
|
|
/* El que es llegeix es pot seleccionar, encara que una finestra no ho permeti per defecte. */
|
|
user-select: text;
|
|
}
|
|
|
|
/* La columna de lectura, centrada dins l'espai que deixa el sumari. */
|
|
.docs-article,
|
|
.docs-pager {
|
|
width: 100%;
|
|
max-width: 720px;
|
|
margin-inline: auto;
|
|
}
|
|
|
|
.docs-kicker {
|
|
margin: 0 0 4px 0;
|
|
font-size: 0.8rem;
|
|
letter-spacing: 0.08em;
|
|
text-transform: uppercase;
|
|
color: var(--color-gray);
|
|
}
|
|
|
|
.docs-pager {
|
|
margin-top: 30px;
|
|
padding-top: 16px;
|
|
border-top: 1px solid var(--color-border);
|
|
display: flex;
|
|
gap: 14px;
|
|
}
|
|
|
|
/* Són els botons d'abans i després, no botons d'un formulari: van plans, com a /docs. */
|
|
.docs-pager-link {
|
|
flex: 1 1 0;
|
|
min-width: 0;
|
|
margin: 0;
|
|
padding: 10px 12px;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 8px;
|
|
box-shadow: none;
|
|
text-align: left;
|
|
color: var(--color-text);
|
|
}
|
|
|
|
.docs-pager-link.next {
|
|
text-align: right;
|
|
}
|
|
|
|
.docs-pager-label {
|
|
display: block;
|
|
font-size: 0.78rem;
|
|
letter-spacing: 0.06em;
|
|
text-transform: uppercase;
|
|
color: var(--color-gray);
|
|
}
|
|
</style>
|