Graph calculator improvmentes
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 24s
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 24s
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import type { ToolPage } from '~/utils/routes'
|
||||
|
||||
export interface ArticleTab {
|
||||
/** the article this page is of — its canonical slug, and the page's key */
|
||||
identity: string
|
||||
/** set when the page is one of the wiki's own pages — the link map, the
|
||||
* graphing calculator — laid on the book instead of an article: the page
|
||||
* draws that live surface, at its own address, for as long as it is open */
|
||||
tool?: ToolPage
|
||||
/** the language this page is turned to */
|
||||
lang: string
|
||||
/** the version in view, as the library files it: its stored slug */
|
||||
@@ -13,14 +19,31 @@ export interface ArticleTab {
|
||||
|
||||
const MAX_TABS = 10
|
||||
|
||||
/** The address a page of the book was read from: the version it is turned to. */
|
||||
export function tabHref(tab: Pick<ArticleTab, 'identity' | 'lang'>): string {
|
||||
return versionHref(tab.identity, tab.lang)
|
||||
/** What each of the wiki's own pages is called, as a message key — the label
|
||||
* the book's spine, chips and dock wear for one of these pages. */
|
||||
export const TOOL_LABEL_KEYS: Record<ToolPage, string> = {
|
||||
graph: 'sidebar.graph',
|
||||
calculator: 'sidebar.calculator',
|
||||
}
|
||||
|
||||
/** The key of the book page holding one of the wiki's own pages. No article
|
||||
* slug carries a colon, so this can never read as an article's identity. */
|
||||
export function toolPageIdentity(page: ToolPage): string {
|
||||
return `page:${page}`
|
||||
}
|
||||
|
||||
/** The address a page of the book was read from: the version it is turned to,
|
||||
* or the wiki's own page's address where the page holds one of those. */
|
||||
export function tabHref(tab: Pick<ArticleTab, 'identity' | 'lang' | 'tool'>): string {
|
||||
return tab.tool ? toolHref(tab.tool) : versionHref(tab.identity, tab.lang)
|
||||
}
|
||||
|
||||
/** Which page of the stack an address points at, if any. An address that
|
||||
* names no language points at the article's page however it is turned. */
|
||||
* names no language points at the article's page however it is turned; the
|
||||
* wiki's own pages are found by their own addresses. */
|
||||
export function tabAt(tabs: readonly ArticleTab[], path: string): ArticleTab | null {
|
||||
const page = toolFromPath(path)
|
||||
if (page) return tabs.find((t) => t.tool === page) ?? null
|
||||
const loc = parseReaderPath(path)
|
||||
if (!loc) return null
|
||||
/* one article is one page of the book, in whichever language that page is
|
||||
@@ -99,6 +122,26 @@ export function useArticleTabs() {
|
||||
tabs.value = stack
|
||||
}
|
||||
|
||||
/**
|
||||
* Lay one of the wiki's own pages — the link map, the graphing calculator —
|
||||
* on the book beside the articles. One surface is one page however many
|
||||
* times it is asked for: asking again just finds the page already there.
|
||||
*/
|
||||
function openTool(page: ToolPage) {
|
||||
const identity = toolPageIdentity(page)
|
||||
if (tabs.value.some((t) => t.tool === page)) return
|
||||
const stack = [
|
||||
...tabs.value,
|
||||
{ identity, tool: page, lang: DEFAULT_LANGUAGE, slug: identity, title: page },
|
||||
]
|
||||
if (stack.length > MAX_TABS) {
|
||||
/* don't stack forever — retire the oldest page that isn't this one */
|
||||
const drop = stack.findIndex((t) => t.identity !== identity)
|
||||
if (drop !== -1) stack.splice(drop, 1)
|
||||
}
|
||||
tabs.value = stack
|
||||
}
|
||||
|
||||
/* Close a page. Closing one that isn't in view just takes it out of the
|
||||
stack and the rest settle; closing the page in view turns back to the
|
||||
page before it — or returns to the last page outside the book once the
|
||||
@@ -113,7 +156,7 @@ export function useArticleTabs() {
|
||||
}
|
||||
}
|
||||
|
||||
return { tabs, origin, lastIdentity, openVersion, closeTab }
|
||||
return { tabs, origin, lastIdentity, openVersion, openTool, closeTab }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,9 +175,21 @@ export function useArticleTabsSync() {
|
||||
(to) => {
|
||||
/* filed under the article's identity, so a version turned to another
|
||||
language is still found as the same page of the book */
|
||||
if (isReaderPath(to))
|
||||
if (isReaderPath(to)) {
|
||||
lastIdentity.value = tabAt(tabs.value, to)?.identity ?? wikiSlugFromPath(to) ?? ''
|
||||
else if (!isReadingSurface(to)) origin.value = to
|
||||
return
|
||||
}
|
||||
/* one of the wiki's own pages held by the book belongs to the reading
|
||||
surface too — it's where its page is in view, not a place to return
|
||||
to; asked plain (no page open), it's an ordinary page of the site */
|
||||
if (isToolPath(to)) {
|
||||
const page = tabAt(tabs.value, to)
|
||||
if (page) {
|
||||
lastIdentity.value = page.identity
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!isReadingSurface(to)) origin.value = to
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user