Fix issue #95: Make documentation a resizable window
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -417,4 +417,89 @@ span.artifact {
|
||||
|
||||
.fold.is-collapsed > .fold-body {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* El markdown renderitzat de la documentació: tot dins de .docs-markdown, que ve de v-html.
|
||||
Va aquí perquè la pàgina de /docs (views/DocsView.vue) i la finestra de documentació
|
||||
(windows/DocumentationWindow.vue) se'l serveixen plegades. */
|
||||
.docs-markdown h1 {
|
||||
margin: 0 0 14px 0;
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 2rem;
|
||||
font-weight: normal;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.docs-markdown h2 {
|
||||
margin: 30px 0 10px 0;
|
||||
padding-bottom: 4px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 1.35rem;
|
||||
font-weight: normal;
|
||||
scroll-margin-top: 20px;
|
||||
}
|
||||
|
||||
.docs-markdown h3 {
|
||||
margin: 22px 0 8px 0;
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 1.1rem;
|
||||
font-weight: normal;
|
||||
scroll-margin-top: 20px;
|
||||
}
|
||||
|
||||
.docs-markdown p,
|
||||
.docs-markdown li {
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.docs-markdown ul,
|
||||
.docs-markdown ol {
|
||||
margin: 10px 0;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
.docs-markdown a {
|
||||
color: var(--color-link);
|
||||
}
|
||||
|
||||
.docs-markdown code {
|
||||
padding: 1px 5px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--color-background-light);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.docs-markdown pre {
|
||||
margin: 14px 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
background-color: var(--color-background-light);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.docs-markdown pre code {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.docs-markdown table {
|
||||
margin: 14px 0;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.docs-markdown th,
|
||||
.docs-markdown td {
|
||||
padding: 7px 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.docs-markdown th {
|
||||
background-color: var(--color-background-light);
|
||||
}
|
||||
@@ -13,6 +13,13 @@ function OpenCampaignSettings() {
|
||||
CreateWindow('campaign_settings', { campaign: Campaign.value });
|
||||
}
|
||||
|
||||
function OpenDocumentation() {
|
||||
// La documentació és una finestra que va davant de l'espai de treball, així que les notes
|
||||
// obertes no es perden. CreateWindow deixa sola una finestra que ja és oberta: tornar a
|
||||
// prémer el botó no la torna a la primera pàgina.
|
||||
CreateWindow('documentation');
|
||||
}
|
||||
|
||||
function ExitCampaign() {
|
||||
// Torn al menú principal: neteja la campanya (i el localStorage), amaga
|
||||
// l'espai de treball i reobre el menú
|
||||
@@ -35,11 +42,11 @@ function ExitCampaign() {
|
||||
<TopSearchBar></TopSearchBar>
|
||||
</div>
|
||||
<div class="right">
|
||||
<!-- La documentació és una pàgina a part (/docs), i una pestanya nova deixa la
|
||||
campanya tal com era: les notes obertes no es perden. -->
|
||||
<a class="btn-primary docs-button sound-click" href="/docs" target="_blank" rel="noopener noreferrer">
|
||||
<!-- La documentació s'obre en una finestra seva, davant de la campanya: les notes
|
||||
obertes no es perden i no cal obrir una pestanya nova. -->
|
||||
<button class="btn-primary settings-button docs-button sound-click" type="button" @click="OpenDocumentation">
|
||||
{{ $t('main-menu.documentation') }}
|
||||
</a>
|
||||
</button>
|
||||
<button class="btn-primary settings-button sound-click" type="button" @click="OpenCampaignSettings">
|
||||
{{ $t('main-menu.settings') }}
|
||||
</button>
|
||||
@@ -90,29 +97,6 @@ function ExitCampaign() {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
/* L'enllaç a la documentació és un `<a>` i els botons estan estilats per element, així
|
||||
que li toca portar el mateix look que els dos que té al costat. */
|
||||
.docs-button {
|
||||
padding: 5px 10px;
|
||||
margin: 5px 0;
|
||||
font-size: 15px;
|
||||
border-radius: 6px;
|
||||
border: solid 1px var(--color-border);
|
||||
background-color: var(--color-button-background);
|
||||
color: var(--color-text);
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
transition: 300ms background-color;
|
||||
}
|
||||
|
||||
.docs-button:hover {
|
||||
background-color: var(--color-button-hover);
|
||||
}
|
||||
|
||||
.docs-button:active {
|
||||
background-color: var(--color-button-active);
|
||||
}
|
||||
|
||||
.top-bar-title {
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
|
||||
@@ -301,88 +301,8 @@ useHead({
|
||||
color: var(--color-link);
|
||||
}
|
||||
|
||||
/* El markdown renderitzat: tot dins de .docs-markdown, perquè ve de v-html. */
|
||||
.docs-markdown :deep(h1) {
|
||||
margin: 0 0 14px 0;
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 2rem;
|
||||
font-weight: normal;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(h2) {
|
||||
margin: 30px 0 10px 0;
|
||||
padding-bottom: 4px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 1.35rem;
|
||||
font-weight: normal;
|
||||
scroll-margin-top: 20px;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(h3) {
|
||||
margin: 22px 0 8px 0;
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 1.1rem;
|
||||
font-weight: normal;
|
||||
scroll-margin-top: 20px;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(p),
|
||||
.docs-markdown :deep(li) {
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(ul),
|
||||
.docs-markdown :deep(ol) {
|
||||
margin: 10px 0;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(a) {
|
||||
color: var(--color-link);
|
||||
}
|
||||
|
||||
.docs-markdown :deep(code) {
|
||||
padding: 1px 5px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--color-background-light);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(pre) {
|
||||
margin: 14px 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
background-color: var(--color-background-light);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(pre code) {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(table) {
|
||||
margin: 14px 0;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(th),
|
||||
.docs-markdown :deep(td) {
|
||||
padding: 7px 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.docs-markdown :deep(th) {
|
||||
background-color: var(--color-background-light);
|
||||
}
|
||||
/* El markdown renderitzat ve estilat a assets/css/main.scss, sota .docs-markdown, perquè la
|
||||
finestra de documentació (windows/DocumentationWindow.vue) se'l serveix igualment. */
|
||||
|
||||
/* Finestra molt ampla: tot el conjunt va al mig, així els apartats queden a prop del
|
||||
text en lloc d'estirats cap al cantó dret de la pantalla. */
|
||||
|
||||
261
frontend/app/components/windows/DocumentationWindow.vue
Normal file
261
frontend/app/components/windows/DocumentationWindow.vue
Normal file
@@ -0,0 +1,261 @@
|
||||
<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>
|
||||
@@ -120,6 +120,12 @@ const defWindows = {
|
||||
component: () => import('~/components/windows/PinnedNoteWindow.vue'),
|
||||
close: () => ClearWindow({type: 'pinned_note'}),
|
||||
movable: true
|
||||
},
|
||||
documentation: {
|
||||
title: 'windows.documentation',
|
||||
component: () => import('~/components/windows/DocumentationWindow.vue'),
|
||||
close: () => ClearWindow({type: 'documentation'}),
|
||||
movable: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"create-map": "Crear mapa",
|
||||
"map-viewer": "Mapa",
|
||||
"pinned-note": "Nota fixada",
|
||||
"documentation": "Documentació",
|
||||
"item-sheet": "Objecte",
|
||||
"icon-source": "Tria una icona",
|
||||
"foundry-icons": "Icones del Foundry"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"create-map": "Create Map",
|
||||
"map-viewer": "Map",
|
||||
"pinned-note": "Pinned note",
|
||||
"documentation": "Documentation",
|
||||
"item-sheet": "Item",
|
||||
"icon-source": "Choose an icon",
|
||||
"foundry-icons": "Foundry icons"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"create-map": "Crear mapa",
|
||||
"map-viewer": "Mapa",
|
||||
"pinned-note": "Nota fijada",
|
||||
"documentation": "Documentación",
|
||||
"item-sheet": "Objeto",
|
||||
"icon-source": "Elegir icono",
|
||||
"foundry-icons": "Iconos de Foundry"
|
||||
|
||||
Reference in New Issue
Block a user