diff --git a/frontend/src/assets/prose.css b/frontend/src/assets/prose.css index ede3b289..c987a334 100644 --- a/frontend/src/assets/prose.css +++ b/frontend/src/assets/prose.css @@ -147,6 +147,45 @@ text-decoration: none; } +/* A record reference — `#4286`, `milestone 639`, `rule 34`. Reads as a link in + running text rather than a chip: a work log cites a dozen of them, and a row + of pills would drown the sentence they sit in. */ +.record-ref { + color: var(--fs-wikilink); + text-decoration: underline; + text-decoration-color: color-mix(in srgb, var(--fs-wikilink) 40%, transparent); + text-underline-offset: 0.15em; + font-variant-numeric: tabular-nums; + border-radius: var(--fs-radius-sm); + cursor: pointer; +} + +.record-ref:hover { + text-decoration-color: currentColor; +} + +/* Drawn with its title: the title reads as the link, the number after it is + the citation, quieter and never split across lines. */ +.record-ref__id { + color: var(--fs-text-secondary); + font-size: 0.85em; + white-space: nowrap; +} + +.record-ref:focus-visible { + outline: none; + box-shadow: var(--fs-focus-ring); +} + +/* One the reader cannot open: missing, trashed or not shared. Still legible — + the number is part of the sentence — but plainly not a way through. */ +.record-ref--missing { + color: var(--fs-text-tertiary-fg); + text-decoration-style: dashed; + text-decoration-color: var(--fs-text-tertiary); + cursor: default; +} + /* Task list */ .prose ul[data-type="taskList"] { list-style: none; diff --git a/frontend/src/components/TaskLogSection.vue b/frontend/src/components/TaskLogSection.vue index dc8ed2ef..bdf02dd1 100644 --- a/frontend/src/components/TaskLogSection.vue +++ b/frontend/src/components/TaskLogSection.vue @@ -2,6 +2,7 @@ import { ref, onMounted } from "vue"; import { apiGet, apiPost, apiPatch, apiDelete } from "@/api/client"; import { renderMarkdown } from "@/utils/markdown"; +import { vRecordRefs } from "@/directives/recordRefs"; import type { TaskLog } from "@/types/task"; import { fmtStamp } from "@/utils/dateFormat"; @@ -131,7 +132,7 @@ onMounted(loadLogs); -
+ diff --git a/frontend/src/composables/useAutocomplete.ts b/frontend/src/composables/useAutocomplete.ts index 97245609..d29d806b 100644 --- a/frontend/src/composables/useAutocomplete.ts +++ b/frontend/src/composables/useAutocomplete.ts @@ -51,7 +51,8 @@ export function useAutocomplete( // Must be start of line or preceded by whitespace if (i === 0 || /\s/.test(text[i - 1])) { const query = text.slice(i + 1, cursor); - if (/^[\w/]*$/.test(query)) { + // Digits alone are a record reference being typed (`#4286`), not a tag. + if (/^[\w/]*$/.test(query) && !/^\d+$/.test(query)) { acTriggerStart = i; acType = "tag"; debouncedSearch(query); diff --git a/frontend/src/directives/recordRefs.ts b/frontend/src/directives/recordRefs.ts new file mode 100644 index 00000000..219587bb --- /dev/null +++ b/frontend/src/directives/recordRefs.ts @@ -0,0 +1,199 @@ +import type { ObjectDirective } from "vue"; +import { apiPost } from "@/api/client"; +import router from "@/router"; +import { recordHref } from "@/utils/recordHref"; +import type { RefSpace } from "@/utils/recordRefs"; + +/** v-record-refs — makes the `a.record-ref` links in a v-html body real. + * + * Put it on the element that holds rendered markdown: + * + * + * After each render it asks the server, once for the whole body, what every + * referenced id is. Each link then gets the route its kind opens at (a `#N` + * may be a task, lesson or snippet), the record's title drawn before its + * number — "Fix the cache key #3127" — so a reader knows what is cited + * without hovering, its kind, full title and status as a tooltip, and a + * "leads nowhere" style when the reader cannot open it: missing, trashed and + * not-shared-with-you look the same, on purpose, and keep the bare number. + * The stored text stays `#N`; the title is read at render, so an edited + * title shows everywhere it is cited. + * A plain click navigates in the app; a modified click (new tab) keeps the + * browser's own behaviour. + */ + +interface NoteInfo { id: number; title: string; is_task: boolean; note_type: string; status: string | null; task_kind: string | null } +interface MilestoneInfo { id: number; title: string; project_id: number | null; status: string } +interface RuleInfo { id: number; title: string; kind: string } +type Resolved = { notes: Record