Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo, keep short ones for security boundaries, upstream quirks and ordering constraints, and record the convention in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+4
-15
@@ -1,15 +1,7 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/cv` — the CV shell: a template picker, a Print button and a link to the
|
||||
* job tracker. Rendered inside CVLayout, which supplies the light print theme.
|
||||
*
|
||||
* The selected template is held in a shallowRef: the value is a component
|
||||
* definition, and a deep `ref` would try to make the whole component object
|
||||
* reactive. Most templates are commented out of `templates` — uncomment a pair of
|
||||
* lines (the import and the entry) to bring one back.
|
||||
*
|
||||
* Printing is just window.print(); the `no-print` class (assets/styles.css) hides
|
||||
* the chrome, and cv-shared.css sizes the pages.
|
||||
* Route `/cv`: template picker and Print. Uncomment an import and its entry
|
||||
* below to bring a template back.
|
||||
*/
|
||||
import { ref, shallowRef } from "vue";
|
||||
// import CVGeneral from "./CVGeneral.vue";
|
||||
@@ -37,9 +29,7 @@ const templates = [
|
||||
];
|
||||
|
||||
const selected = ref(0);
|
||||
// shallowRef, not ref: the value is a component definition. A deep ref would
|
||||
// walk the whole component object making it reactive — wasteful and a known
|
||||
// source of warnings.
|
||||
// shallowRef: a deep ref would make the component definition reactive.
|
||||
const currentComponent = shallowRef(templates[0].component);
|
||||
|
||||
function select(index) {
|
||||
@@ -47,8 +37,7 @@ function select(index) {
|
||||
currentComponent.value = templates[index].component;
|
||||
}
|
||||
|
||||
/** Browser print dialog. The `no-print` class (assets/styles.css) hides the
|
||||
* selector bar; cv-shared.css handles page sizing and breaks. */
|
||||
/** `no-print` hides the chrome; cv-shared.css sizes the pages. */
|
||||
function print() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<script setup>
|
||||
/**
|
||||
* The live CV template — the only one currently listed in CV.vue.
|
||||
*
|
||||
* Both sheets are fixed A4 with overflow hidden (cv-shared.css), so anything
|
||||
* added here has to be checked in print preview: text that doesn't fit is
|
||||
* silently clipped, not pushed onto another page.
|
||||
* The live CV template. Sheets are fixed A4 with overflow hidden: check print
|
||||
* preview, since overflow is clipped silently.
|
||||
*/
|
||||
import Project from "./Project.vue";
|
||||
</script>
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Editable cover letter (contenteditable fields, print to PDF), split into
|
||||
* named sections whose paragraphs can be dragged within and between them.
|
||||
* STATUS: live — CV.vue imports it as the "Cover Letter" tab on /cv.
|
||||
*
|
||||
* Everyone gets the editor; /cv is public and nothing here needs the server
|
||||
* until something is saved. An admin also gets the toolbar (saved letters,
|
||||
* stores/coverLetters.js) and the paragraph bank (CoverSnippetBank.vue,
|
||||
* stores/coverSnippets.js). The letter's data shape and the moves live in
|
||||
* ./coverLetter.js.
|
||||
*
|
||||
* Section titles are editor furniture: they are `no-print`, so the printed
|
||||
* letter is one run of paragraphs, as it was before sections existed.
|
||||
*
|
||||
* Editing: contenteditable elements are filled with v-text and read back on
|
||||
* blur. v-text, not {{ }}, because it replaces the element's whole content —
|
||||
* an interpolated text node would sit alongside the <div>s a browser adds on
|
||||
* Enter and duplicate the text when Vue patched it.
|
||||
*
|
||||
* Dragging is native HTML5 DnD. `drag` holds what is in flight (dataTransfer
|
||||
* can't be read until the drop) and `dropAt` where it would land, which is
|
||||
* what draws the indicator line. Only the ⋮⋮ handle is draggable, so text in
|
||||
* a paragraph stays selectable.
|
||||
* Editable cover letter with draggable paragraphs and sections.
|
||||
* STATUS: live — the "Cover Letter" tab on /cv.
|
||||
* Admins also get saved letters and the paragraph bank. Data shape and moves
|
||||
* are in ./coverLetter.js.
|
||||
* contenteditable fields use v-text, not {{ }}: an interpolated text node would
|
||||
* duplicate text alongside the <div>s browsers add on Enter. Only the ⋮⋮
|
||||
* handle drags, so paragraph text stays selectable.
|
||||
*/
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
@@ -46,8 +31,7 @@ const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
const letter = ref(newLetter());
|
||||
// The open saved letter's id, or null for one never saved (or deleted).
|
||||
const currentId = ref(null);
|
||||
// The body as last saved or loaded; the letter is unsaved when it differs.
|
||||
// Starts as the blank template so an untouched page doesn't nag.
|
||||
// Starts as the blank template so an untouched page isn't "unsaved".
|
||||
const savedBody = ref(serialize(letter.value));
|
||||
const dirty = computed(() => serialize(letter.value) !== savedBody.value);
|
||||
const current = computed(() =>
|
||||
@@ -59,8 +43,7 @@ const error = ref("");
|
||||
|
||||
onMounted(() => auth.ensureLoaded());
|
||||
|
||||
// The stores are admin only, so they are fetched once an admin is known,
|
||||
// which can be after mount on a cold load.
|
||||
// Admin is known only after mount on a cold load.
|
||||
watch(
|
||||
isAdmin,
|
||||
(admin) => {
|
||||
@@ -71,8 +54,7 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// Closing the tab with unsaved changes asks first. Only for an admin, who
|
||||
// can save; a visitor's letter is throwaway by design.
|
||||
// Only admins can save; a visitor's letter is throwaway.
|
||||
function onBeforeUnload(event) {
|
||||
if (isAdmin.value && dirty.value) event.preventDefault();
|
||||
}
|
||||
@@ -102,8 +84,7 @@ function discardOk() {
|
||||
function open(letterRow) {
|
||||
letter.value = parseBody(letterRow.body);
|
||||
currentId.value = letterRow.id;
|
||||
// The normalised form, not the raw body, so an older row doesn't open
|
||||
// already marked unsaved.
|
||||
// Normalised, so an older row doesn't open as unsaved.
|
||||
savedBody.value = serialize(letter.value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
<script setup>
|
||||
/**
|
||||
* The paragraph bank beside the cover letter (admin only, never printed):
|
||||
* reusable paragraphs from stores/coverSnippets.js, grouped by the section
|
||||
* they were written for.
|
||||
*
|
||||
* Dragging works through the parent, which owns the one drag in progress:
|
||||
* dragging a snippet out emits `drag-snippet` so CoverLetters.vue can drop a
|
||||
* copy into the letter, and a letter paragraph dropped here (`accepting` is
|
||||
* true while one is being dragged) emits `drop-paragraph` for the parent to
|
||||
* save. Snippets are edited in place and saved on blur.
|
||||
* The admin's paragraph bank beside the cover letter. CoverLetters.vue owns
|
||||
* the drag in progress; this emits `drag-snippet` and `drop-paragraph`.
|
||||
*/
|
||||
import { computed, ref } from "vue";
|
||||
import { useCoverSnippetsStore } from "@/stores/coverSnippets";
|
||||
@@ -30,8 +23,6 @@ const over = ref(false);
|
||||
const newText = ref("");
|
||||
const newSection = ref("");
|
||||
|
||||
/** [{ section, snippets }] in the store's order (section, then newest),
|
||||
* narrowed by the filter, which matches text or section. */
|
||||
const groups = computed(() => {
|
||||
const q = filter.value.trim().toLowerCase();
|
||||
const out = [];
|
||||
@@ -79,9 +70,8 @@ function onDragStart(snippet, event) {
|
||||
event.dataTransfer.effectAllowed = "copy";
|
||||
// Firefox won't start a drag without some data set.
|
||||
event.dataTransfer.setData("text/plain", snippet.text);
|
||||
// Only the grip is draggable, so text in the textareas stays selectable
|
||||
// (Firefox can't place a caret inside a draggable element); show the
|
||||
// whole card moving rather than the grip.
|
||||
// Only the grip drags (Firefox can't put a caret in a draggable), so show
|
||||
// the whole card as the drag image.
|
||||
event.dataTransfer.setDragImage(event.target.closest(".snippet"), 12, 12);
|
||||
emit("drag-snippet", snippet);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
/**
|
||||
* The cover letter as data, with no Vue in it: the default letter, the JSON
|
||||
* body stored in a CoverLetter row (stores/coverLetters.js), and the moves
|
||||
* the drag and drop in CoverLetters.vue makes.
|
||||
*
|
||||
* Body shape (v: 1):
|
||||
* The cover letter as plain data. Body shape (v: 1):
|
||||
* { v, name, phone, email, role, signoff,
|
||||
* sections: [{ id, title, paragraphs: [{ id, text }] }] }
|
||||
*
|
||||
* Every section and paragraph carries an id because the template keys its
|
||||
* v-for on it. Keying on the index would leave a contenteditable showing the
|
||||
* old text after a reorder, since Vue would reuse the element in place.
|
||||
*
|
||||
* A position is `{ section, index }`: a section's index and a paragraph's
|
||||
* index inside it. `index` may equal the paragraph count, meaning "at the end".
|
||||
* Ids exist because index keys would leave a contenteditable showing stale
|
||||
* text after a reorder. A position is `{ section, index }`; index may equal
|
||||
* the count, meaning the end.
|
||||
*/
|
||||
|
||||
export const BODY_VERSION = 1;
|
||||
|
||||
/** A short id, unique enough within one letter. crypto.randomUUID would do,
|
||||
* but it is missing outside a secure context (the dev stack over a LAN IP). */
|
||||
/** crypto.randomUUID is missing outside a secure context (dev over a LAN IP). */
|
||||
export function newId() {
|
||||
return Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
|
||||
}
|
||||
@@ -50,11 +41,7 @@ export function newLetter() {
|
||||
|
||||
const str = (v, fallback) => (typeof v === "string" ? v : fallback);
|
||||
|
||||
/**
|
||||
* Read a stored body back into a letter. Anything missing or malformed
|
||||
* falls back to the default field by field, so a hand-edited or older row
|
||||
* still opens rather than blanking the page; ids are regenerated if absent.
|
||||
*/
|
||||
/** Malformed or missing fields fall back to defaults one by one. */
|
||||
export function parseBody(json) {
|
||||
const base = newLetter();
|
||||
let raw;
|
||||
@@ -88,8 +75,7 @@ export function parseBody(json) {
|
||||
};
|
||||
}
|
||||
|
||||
/** The JSON stored as a CoverLetter's body. Also what the "unsaved" marker
|
||||
* compares, so the key order here must stay fixed. */
|
||||
/** Also what "unsaved" compares, so key order must stay fixed. */
|
||||
export function serialize(letter) {
|
||||
return JSON.stringify({
|
||||
v: BODY_VERSION,
|
||||
@@ -106,12 +92,7 @@ export function serialize(letter) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the paragraph at `from` to `to`, both positions as they are before the
|
||||
* move. Moving down within one section shifts the target up by one once the
|
||||
* paragraph has been taken out, which is corrected here so a drop lands where
|
||||
* the indicator showed.
|
||||
*/
|
||||
/** Positions are as before the move; a downward move within a section is corrected. */
|
||||
export function moveParagraph(letter, from, to) {
|
||||
const src = letter.sections[from.section];
|
||||
const dst = letter.sections[to.section];
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
/*
|
||||
* Shared styles for the CV templates (src/views/CV/CV*.vue).
|
||||
*
|
||||
* Loaded once, unscoped, by CV.vue. Each template wraps itself in
|
||||
* <main class="cv-template"> and lays out each sheet as <div class="cv-page">.
|
||||
*
|
||||
* Colours are the site tokens from src/assets/styles.css. CVLayout.vue has
|
||||
* already switched them to ink-on-paper; this file only adds the template's
|
||||
* own accents (blue links, red table rules). Sizes are exposed as --cv-*
|
||||
* variables so a template can tune them from its own scoped <style>.
|
||||
*/
|
||||
/* Shared CV template styles, loaded unscoped by CV.vue. --cv-* sizes are tunable per template. */
|
||||
|
||||
.cv-template {
|
||||
--color-primary: black;
|
||||
|
||||
Reference in New Issue
Block a user