From 0a72cd9b58005b1628ea001a71cb5250f5b5f795 Mon Sep 17 00:00:00 2001 From: "dong.nguyen" Date: Fri, 23 Oct 2026 09:36:59 +0700 Subject: [PATCH] =?UTF-8?q?feat(edit):=20inline=20editing=20controls=20on?= =?UTF-8?q?=20every=20record=20surface=20(spec-v4-inline-editing=20=C2=A75?= =?UTF-8?q?=20steps=201-7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EditableText: wrapper zone + pencil trigger (E6), inline validation errors, provenance tooltip + copy-chip (E7) - TagListEditor: per-chip edit/delete/move + ghost add over all six tag arrays, tagline emphasis toggle - RecordControls + AddGhost on About, AboutPage, Expertise, Experience, ExperiencePage, Projects, ProjectsListPage, ProjectDetailPage (incl. sections), PhilosophyPage; RecordSettings popover (featured, section list with type picker, variant, location, logo) - id-slug rename on committed record titles (E3); per-field conflict UI in EditBar; chrome CSS in App.css; labels in both ui.json - JsonPanel kept until the inline surface is verified in a real browser (spec progress row 8); acceptance §6 partial — build, validate:content, lint, smoke-draft pass 2026-10-23 --- .../design/specs/v4/spec-v4-inline-editing.md | 6 +- src/App.css | 253 ++++++++++++++++ src/components/layout/EditBar.tsx | 67 +++-- src/components/layout/EditModeShell.tsx | 116 ++++++-- src/components/sections/About.tsx | 48 ++- src/components/sections/Experience.tsx | 56 +++- src/components/sections/Expertise.tsx | 35 ++- src/components/sections/Hero.tsx | 81 +++++- src/components/sections/Projects.tsx | 136 ++++++--- src/components/ui/EditableText.tsx | 274 +++++++++++++++--- src/components/ui/RecordControls.tsx | 102 +++++++ src/components/ui/RecordSettings.tsx | 189 ++++++++++++ src/components/ui/TagListEditor.tsx | 132 +++++++++ src/components/ui/icons.tsx | 55 ++++ src/hooks/useEdit.ts | 50 +++- src/i18n/locales/en/ui.json | 53 +++- src/i18n/locales/vi/ui.json | 53 +++- src/pages/AboutPage.tsx | 80 +++-- src/pages/ExperiencePage.tsx | 56 +++- src/pages/PhilosophyPage.tsx | 60 +++- src/pages/ProjectDetailPage.tsx | 77 +++-- src/pages/ProjectsListPage.tsx | 110 +++++-- 22 files changed, 1812 insertions(+), 277 deletions(-) create mode 100644 src/components/ui/RecordControls.tsx create mode 100644 src/components/ui/RecordSettings.tsx create mode 100644 src/components/ui/TagListEditor.tsx diff --git a/docs/design/specs/v4/spec-v4-inline-editing.md b/docs/design/specs/v4/spec-v4-inline-editing.md index b3e28d8..f2feb5b 100644 --- a/docs/design/specs/v4/spec-v4-inline-editing.md +++ b/docs/design/specs/v4/spec-v4-inline-editing.md @@ -112,5 +112,7 @@ Page manifests (`spec-v4-data-organization.md` §5) are **read-only in the app** | # | Task | Status | |---|---|---| | 0 | Design agreed (E1–E7) | ✅ Done 2026-10-23 | -| 1–9 | Implementation §5 | ⬜ TODO | -| — | Acceptance §6 | ⬜ TODO | +| 1–7 | Implementation §5 | ✅ Done 2026-10-23 — EditableText zone/pencil/provenance, TagListEditor over all tag arrays, tagline emphasis, `RecordControls` + `AddGhost` on every record surface (About, AboutPage, Expertise, Experience, ExperiencePage, Projects, ProjectsListPage, ProjectDetailPage incl. sections, PhilosophyPage), `RecordSettings` (featured, section list + type picker, variant, location, logo), id-slug rename on title commit, per-field conflict UI in EditBar; chrome CSS in `App.css`, labels in both `ui.json` | +| 8 | Remove `JsonPanel` + panel labels | ⬜ TODO — kept until the inline surface is verified in a real browser | +| 9 | Docs superseded notes | ⬜ TODO | +| — | Acceptance §6 | 🟡 Partial — `pnpm build`, `pnpm validate:content`, `pnpm lint` (no new warnings), `pnpm tsx scripts/smoke-draft.ts` pass 2026-10-23; browser verification of the edit surfaces pending (user verifies in a real browser) | diff --git a/src/App.css b/src/App.css index 6382b6e..15f3d4e 100644 --- a/src/App.css +++ b/src/App.css @@ -2428,6 +2428,259 @@ background: var(--accent-tint); } +/* Field and record chrome (spec-v4-inline-editing E2/E4/E5): the controls are + edit-mode-only islands inside the site's own elements — one bordered icon + language (44px targets stay on the bar, 24px here), hover/focus in the + accent, delete in the error colour. */ +.edit-field-controls { + display: inline-flex; + align-items: center; + gap: 4px; + margin-left: 8px; + vertical-align: middle; +} + +.edit-pencil, +.edit-item-control, +.edit-record-btn { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 3px; + border: 1px solid var(--border); + border-radius: 4px; + background: var(--bg-surface); + color: var(--text-muted); + cursor: pointer; +} + +.edit-pencil:hover, +.edit-item-control:hover, +.edit-record-btn:hover:not(:disabled) { + color: var(--accent); + border-color: var(--accent); +} + +.edit-pencil:focus-visible, +.edit-item-control:focus-visible, +.edit-record-btn:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} + +.edit-item-control:disabled, +.edit-record-btn:disabled { + opacity: 0.35; + cursor: default; +} + +.edit-item-remove:hover, +.edit-record-btn.edit-record-remove:hover { + color: var(--error); + border-color: var(--error); +} + +.edit-provenance { + max-width: 220px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 12px; + color: var(--text-muted); + border: 1px dashed var(--border); + border-radius: 4px; + background: none; + padding: 2px 6px; + cursor: pointer; +} + +.edit-provenance:hover { + color: var(--accent); + border-color: var(--accent); +} + +.edit-field-error { + display: block; + font-size: 12px; + color: var(--error); + margin-top: 2px; +} + +.edit-add-inline, +.edit-add-ghost { + display: inline-flex; + align-items: center; + gap: 5px; + border: 1px dashed var(--border-strong); + border-radius: 6px; + background: transparent; + color: var(--text-muted); + padding: 6px 10px; + cursor: pointer; +} + +.edit-add-inline:hover, +.edit-add-ghost:hover { + color: var(--accent); + border-color: var(--accent); + border-style: solid; +} + +.edit-add-ghost-card { + justify-content: center; + width: 100%; + min-height: 160px; + border-radius: 12px; +} + +/* A record whose box hosts the controls (cards, timeline entries, sections) + and a grid card whose body is a link (wrapped in a shell) both float the + controls at the top-right corner of the record. Elsewhere — the project + detail header — they stay in flow. */ +.edit-record-host, +.edit-record-shell { + position: relative; +} + +.edit-record-controls { + display: inline-flex; + gap: 4px; +} + +.edit-record-host > .edit-record-controls, +.edit-record-shell > .edit-record-controls { + position: absolute; + top: 8px; + right: 8px; + z-index: 30; +} + +/* Record settings dialog (E2): the structure fields of one record — + featured, section list, timeline variant, logo. */ +.record-settings { + position: fixed; + top: 80px; + left: 50%; + transform: translateX(-50%); + z-index: 960; + width: min(560px, calc(100vw - 32px)); + max-height: min(70vh, 640px); + overflow-y: auto; + background: var(--bg-elevated); + border: 1px solid var(--border-strong); + border-radius: 10px; + padding: 14px 16px; + box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35); +} + +.record-settings-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 12px; +} + +.record-settings-title { + font-weight: 600; +} + +.record-settings-close { + border: 1px solid var(--border); + border-radius: 4px; + background: none; + color: var(--text-muted); + font-size: 16px; + line-height: 1; + padding: 2px 8px; + cursor: pointer; +} + +.record-settings-close:hover { + color: var(--error); + border-color: var(--error); +} + +.record-settings-group-title { + font-size: 12px; + text-transform: uppercase; + letter-spacing: 0.08em; + color: var(--text-muted); + margin: 12px 0 6px; +} + +.record-settings-field { + display: flex; + align-items: center; + gap: 8px; + margin: 8px 0; +} + +.record-settings-field input { + background: var(--bg-surface); + color: inherit; + border: 1px solid var(--border); + border-radius: 4px; + padding: 4px 8px; + min-width: 220px; +} + +.record-settings-list { + list-style: none; + display: grid; + gap: 6px; + margin: 0; + padding: 0; +} + +.record-settings-row { + display: flex; + align-items: center; + gap: 8px; + border: 1px solid var(--border); + border-radius: 6px; + padding: 6px 8px; +} + +.record-settings-row select { + background: var(--bg-surface); + color: inherit; + border: 1px solid var(--border); + border-radius: 4px; + padding: 3px 6px; +} + +.record-settings-id { + font-size: 12px; + color: var(--text-muted); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + max-width: 220px; +} + +/* Field-by-field conflict view (E8). */ +.edit-bar-conflict-fields { + list-style: none; + margin: 8px 0 0; + padding: 0; + display: grid; + gap: 6px; +} + +.edit-bar-conflict-fields li { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 8px; +} + +.edit-bar-conflict-side { + font-size: 12px; + text-transform: uppercase; + letter-spacing: 0.06em; + color: var(--text-muted); +} + @media (max-width: 768px) { .json-panel { width: 100%; diff --git a/src/components/layout/EditBar.tsx b/src/components/layout/EditBar.tsx index 084c4b5..2186d58 100644 --- a/src/components/layout/EditBar.tsx +++ b/src/components/layout/EditBar.tsx @@ -1,13 +1,15 @@ -// EditBar (spec-v4 §5.5): the fixed status bar of edit mode. It lists every -// changed path grouped by document with before → after and a per-path revert, -// reports save progress (written / conflict / failed), partial-save resume, -// conflict resolution (rebase / take-theirs / hand-merge), validation issues, -// and guards Exit with a confirm when changes are unsaved. +// EditBar (spec-v4 §5.5, spec-v4-inline-editing E8): the fixed status bar of +// edit mode. It lists every changed path grouped by document with before → +// after and a per-path revert, reports save progress (written / conflict / +// failed), partial-save resume, validation issues, and guards Exit with a +// confirm when changes are unsaved. Conflicts are resolved field by field: +// keep mine / keep theirs per clashing path, with rebase and take-theirs as +// the whole-document operations. import { useState } from 'react'; import { useI18n } from '@/i18n/provider'; import { DRAFT_DOCS } from '@/i18n/draft'; import { DEFAULT_BRANCH } from '@/i18n/edit-mode'; -import type { DocSaveResult, DraftDocId } from '@/i18n/draft'; +import type { ConflictField, DocSaveResult, DraftDocId } from '@/i18n/draft'; import type { ContentIssue } from '@/i18n/validate'; type ChangedDoc = { id: DraftDocId; paths: { path: string; before: unknown; after: unknown }[] }; @@ -24,12 +26,12 @@ type EditBarProps = { unionNote: 'ok' | 'failed' | null; draftRestored: boolean; branch: string; - onOpenPanel: () => void; + getConflictFields: (id: DraftDocId) => ConflictField[]; onSave: () => void; onExit: () => void; onRebase: (id: DraftDocId) => void; onTakeTheirs: (id: DraftDocId) => void; - onHandMerge: (id: DraftDocId) => void; + onResolveField: (id: DraftDocId, path: string, side: 'mine' | 'theirs') => void; onDiscardDoc: (id: DraftDocId) => void; onRevertPath: (path: string) => void; }; @@ -38,7 +40,7 @@ function fileOf(id: DraftDocId): string { return DRAFT_DOCS.find((d) => d.id === id)!.file; } -// Diff values are shown truncated; the full value lives in the JSON panel. +// Diff values are shown truncated; the full value stays in the document. function truncate(value: unknown): string { const text = typeof value === 'string' ? value : JSON.stringify(value) ?? ''; return text.length > 80 ? `${text.slice(0, 80)}…` : text; @@ -56,18 +58,19 @@ export function EditBar({ unionNote, draftRestored, branch, - onOpenPanel, + getConflictFields, onSave, onExit, onRebase, onTakeTheirs, - onHandMerge, + onResolveField, onDiscardDoc, onRevertPath, }: EditBarProps) { const { ui } = useI18n(); const s = ui.edit; const [showDiff, setShowDiff] = useState(false); + const [openFields, setOpenFields] = useState>(new Set()); const allWritten = saveResults.length > 0 && !saveStopped && saveResults.every((r) => r.status === 'written'); @@ -99,9 +102,6 @@ export function EditBar({ > {s.changesTitle} - - - + {openFields.has(id) && ( + + )} + ))} )} diff --git a/src/components/layout/EditModeShell.tsx b/src/components/layout/EditModeShell.tsx index 2b2e74d..19552c3 100644 --- a/src/components/layout/EditModeShell.tsx +++ b/src/components/layout/EditModeShell.tsx @@ -19,6 +19,7 @@ import { fetchTextFile, saveDraft, saveIdUnions, + recordForTitlePath, } from '@/i18n/draft'; import type { DocBase, DocSaveResult, DraftDocId } from '@/i18n/draft'; import { @@ -35,7 +36,6 @@ import { EditContext } from '@/hooks/useEdit'; import type { EditApi } from '@/hooks/useEdit'; import type { ContentIssue } from '@/i18n/validate'; import { EditBar } from './EditBar'; -import { JsonPanel, type PanelTab } from './JsonPanel'; type Phase = 'authenticating' | 'loading' | 'ready' | 'offline'; @@ -61,8 +61,6 @@ export default function EditModeShell({ children }: { children: ReactNode }) { const [saving, setSaving] = useState(false); const [saveStopped, setSaveStopped] = useState(false); const [unionNote, setUnionNote] = useState<'ok' | 'failed' | null>(null); - const [panelOpen, setPanelOpen] = useState(false); - const [panelTab, setPanelTab] = useState('profile'); const stripEditQuery = useCallback(() => { const params = new URLSearchParams(location.search); @@ -167,15 +165,23 @@ export default function EditModeShell({ children }: { children: ReactNode }) { return () => window.removeEventListener('beforeunload', warn); }, [dirty]); + // The EditApi v2 surface (spec-v4-inline-editing E4): text writes keep the + // v1 helpers; everything else — structure fields, tags, records, order, + // provenance — goes through the generic draft methods. A committed record + // title re-sluges its draft-only id (E3); a saved record's id never moves. const editApi = useMemo( () => store && (phase === 'ready' || phase === 'offline') ? { + textDoc: lang === 'en' ? 'content.en' : 'content.vi', commit: (path, value) => { const rejected = store.setValue(lang, path, value); setIssues(rejected ?? []); - if (!rejected) refresh(store); - return rejected; + if (rejected) return rejected; + const record = recordForTitlePath(path); + if (record) store.renameRecord(record.kind, record.ids, value); + refresh(store); + return null; }, revert: (path) => { const rejected = store.revertPath(path); @@ -184,6 +190,59 @@ export default function EditModeShell({ children }: { children: ReactNode }) { return rejected; }, isPathDirty: (path) => store.isPathDirty(path), + describe: (doc, path) => store.describeField(doc, path), + apply: (doc, next) => { + const rejected = store.apply(doc, next); + setIssues(rejected ?? []); + if (!rejected) refresh(store); + return rejected; + }, + dataOf: (doc) => store.dataOf(doc), + setStructured: (doc, path, value) => { + const rejected = store.setStructured(doc, path, value); + setIssues(rejected ?? []); + if (!rejected) refresh(store); + return rejected; + }, + deleteStructured: (doc, path) => { + const rejected = store.deleteStructured(doc, path); + setIssues(rejected ?? []); + if (!rejected) refresh(store); + return rejected; + }, + isPathDirtyIn: (doc, path) => store.changedPaths(doc).includes(path), + moveItem: (doc, path, from, to) => { + const rejected = store.moveItem(doc, path, from, to); + if (rejected) setIssues(rejected); + else refresh(store); + return rejected; + }, + addRecord: (kind, options) => { + const rejected = store.addRecord(kind, options); + setIssues(rejected ?? []); + if (!rejected) refresh(store); + return rejected; + }, + deleteRecord: (kind, ids) => { + const rejected = store.deleteRecord(kind, ids); + setIssues(rejected ?? []); + if (!rejected) refresh(store); + return rejected; + }, + isCreated: (kind, ids) => store.isCreated(kind, ids), + renameRecord: (kind, ids, rawId) => { + const rejected = store.renameRecord(kind, ids, rawId); + if (!rejected) refresh(store); + return rejected; + }, + conflictFields: (doc) => store.conflictFields(doc), + resolveConflictField: (doc, path, side) => { + const rejected = store.resolveConflictField(doc, path, side); + setIssues(rejected ?? []); + if (!rejected) setConflicts((prev) => prev.filter((x) => x !== doc)); + refresh(store); + return rejected; + }, } : null, [store, phase, lang, refresh], @@ -252,10 +311,27 @@ export default function EditModeShell({ children }: { children: ReactNode }) { [store, refresh], ); - const openHandMerge = useCallback((id: DraftDocId) => { - setPanelTab(id); - setPanelOpen(true); - }, []); + // One field, one side (E8): refresh that document's base first so the + // branch values shown are current, then keep 'mine' or 'theirs' at that + // path and retry the rebase. The document leaves the conflict list only + // when the rebase completes with no remaining clash. + const resolveConflictField = useCallback( + async (id: DraftDocId, path: string, side: 'mine' | 'theirs') => { + if (!store) return; + const meta = DRAFT_DOCS.find((d) => d.id === id)!; + try { + store.resetBase(id, await fetchDoc(meta.file, branch)); + } catch { + // unreachable proxy — the field UI stays, take-theirs still works + } + const rejected = store.resolveConflictField(id, path, side); + setIssues(rejected ?? []); + if (!rejected) setConflicts((prev) => prev.filter((x) => x !== id)); + refresh(store); + }, + [store, refresh, branch], + ); + const discardDoc = useCallback( (id: DraftDocId) => { @@ -282,9 +358,6 @@ export default function EditModeShell({ children }: { children: ReactNode }) { stripEditQuery(); }, [stripEditQuery]); - const openPanel = useCallback(() => { - setPanelOpen(true); - }, []); // `revision` is the draft's invalidation counter — the store mutates in // place, so it is the only signal that a recomputation is due. @@ -311,30 +384,15 @@ export default function EditModeShell({ children }: { children: ReactNode }) { unionNote={unionNote} draftRestored={draftRestored} branch={branch} - onOpenPanel={openPanel} + getConflictFields={(id) => store.conflictFields(id)} onSave={() => void runSave()} onExit={exit} onRebase={(id) => void resolveRebase(id)} onTakeTheirs={resolveTakeTheirs} - onHandMerge={openHandMerge} + onResolveField={(id, path, side) => void resolveConflictField(id, path, side)} onDiscardDoc={discardDoc} onRevertPath={revertPath} /> - {panelOpen && ( - setPanelOpen(false)} - onTab={setPanelTab} - onChanged={() => { - setIssues(store.validate()); - refresh(store); - }} - onConflictResolved={(id) => setConflicts((prev) => prev.filter((x) => x !== id))} - /> - )} )} diff --git a/src/components/sections/About.tsx b/src/components/sections/About.tsx index c95d3c7..e88eccf 100644 --- a/src/components/sections/About.tsx +++ b/src/components/sections/About.tsx @@ -3,9 +3,13 @@ import { motion } from 'motion/react' import { InView } from '@/components/ui/InView' import { Tag } from '@/components/ui/Tag' import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' export function About() { const { ui: s, content: c } = useI18n() + const edit = useEdit() return ( ( + {edit && ( + 0} + canDown={i < c.profile.philosophy.length - 1} + onUp={() => edit.moveItem('profile', 'philosophy', i, i - 1)} + onDown={() => edit.moveItem('profile', 'philosophy', i, i + 1)} + onDelete={() => edit.deleteRecord('philosophy', { id: point.id })} + /> + )} {point.title} {point.description} -
- {point.keywords.map((kw) => ( - {kw} - ))} -
+
))} + {edit && edit.addRecord('philosophy')} />}

{s.about.exploringTitle}

-
- {c.profile.currentInterests.map((interest) => ( - - {interest} - - ))} -
+
) diff --git a/src/components/sections/Experience.tsx b/src/components/sections/Experience.tsx index 7bd0655..4b9fa63 100644 --- a/src/components/sections/Experience.tsx +++ b/src/components/sections/Experience.tsx @@ -2,10 +2,17 @@ import { SectionHeading } from '@/components/ui/SectionHeading' import { motion } from "motion/react" import { InView } from "@/components/ui/InView" import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { RecordSettings, ExperienceSettingsPanel } from '@/components/ui/RecordSettings' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' +import { useState } from 'react' export function Experience() { const { ui: s, content: c } = useI18n() + const edit = useEdit() + const [settingsFor, setSettingsFor] = useState(null) return ( (
+ {edit && ( + 0} + canDown={i < c.experiences.length - 1} + onUp={() => edit.moveItem('experience', '', i, i - 1)} + onDown={() => edit.moveItem('experience', '', i, i + 1)} + onDelete={() => edit.deleteRecord('experience', { id: exp.id })} + onSettings={() => setSettingsFor(exp.id)} + /> + )}
{exp.title} @@ -48,20 +72,18 @@ export function Experience() { )}
-
    - {exp.responsibilities.map((r, ri) => ( - - {r} - - ))} -
+
))} + {edit && edit.addRecord('experience')} />}
+ {edit && settingsFor && ( + setSettingsFor(null)}> + {(() => { + const entry = c.experiences.find((e) => e.id === settingsFor) + return entry ? : null + })()} + + )}
diff --git a/src/components/sections/Expertise.tsx b/src/components/sections/Expertise.tsx index 955d388..4744823 100644 --- a/src/components/sections/Expertise.tsx +++ b/src/components/sections/Expertise.tsx @@ -2,10 +2,14 @@ import { motion } from "motion/react" import { SectionHeading } from "@/components/ui/SectionHeading" import { InView } from '@/components/ui/InView' import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' export function Expertise() { const { ui: s, content: c } = useI18n() + const edit = useEdit() return ( ( + {edit && ( + 0} + canDown={i < c.skillGroups.length - 1} + onUp={() => edit.moveItem('skills', '', i, i - 1)} + onDown={() => edit.moveItem('skills', '', i, i + 1)} + onDelete={() => edit.deleteRecord('skill-group', { id: group.id })} + /> + )} {group.title} -
    - {group.skills.map((skill) => ( -
  • - {skill} -
  • - ))} -
+
))} + {edit && edit.addRecord('skill-group')} />}
diff --git a/src/components/sections/Hero.tsx b/src/components/sections/Hero.tsx index e15ba66..ecdc49a 100644 --- a/src/components/sections/Hero.tsx +++ b/src/components/sections/Hero.tsx @@ -9,11 +9,14 @@ import {Typewriter} from '@/components/ui/Typewriter' import {HeroParticles} from '@/components/sections/HeroParticles' import {EditableText} from '@/components/ui/EditableText' import {SocialLinks} from "@/components/ui/SocialLinks" - +import {useEdit} from '@/hooks/useEdit' +import {deletePath, parsePath, setPath} from '@/i18n/draft' +import {ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon} from '@/components/ui/icons' export function Hero() { const {scrollY} = useScroll() const {ui: s, content: c} = useI18n() + const edit = useEdit() const y = useTransform(scrollY, [0, 300], [0, -80]) return ( @@ -72,15 +75,72 @@ export function Hero() { transition={{duration: 0.45, ease: "easeOut", delay: 0.24}} > {/* Tagline segments (D9): markup is this component's rendering, - never content — the emphasis span keeps its classes. */} - {c.profile.tagline.map((segment, i) => ( - segment.emphasis ? ( + never content — the emphasis span keeps its classes. In edit + mode each segment carries emphasis / move / delete controls + (spec-v4-inline-editing §2.1) and a ghost add follows. */} + {c.profile.tagline.map((segment, i) => { + const controls = edit ? ( + <> + + + + + + ) : undefined + return segment.emphasis ? ( {segment.text} @@ -90,11 +150,22 @@ export function Hero() { key={i} path={`profile.tagline[${i}].text`} label={`${s.edit.fields.tagline} ${i + 1}`} + fieldControls={controls} > {segment.text} ) - ))} + })} + {edit && ( + + )} (null) const featured = c.projects.filter((p) => p.featured).slice(0, 4) return ( @@ -33,51 +40,96 @@ export function Projects() { {s.projects.viewAll} →
- {featured.map((project, i) => ( - -
-
- - {project.title} - - - {s.projects.categories[project.category]} - -
- - {project.summary} - -
- {project.technologies.slice(0, 4).map((tech) => ( - - {tech} - - ))} -
- {project.metrics && project.metrics.length > 0 && ( -
- {project.metrics.map((m) => ( - - {m} - - ))} + {featured.map((project, i) => { + // Structure paths are relative to the document array, so the + // control writes address the record by its real index, not the + // featured-subset index it happens to render at. + const docIndex = c.projects.findIndex((p) => p.id === project.id) + const card = ( + +
+
+ + {project.title} + + + {s.projects.categories[project.category]} +
- )} - {s.projects.viewDetails} → + + {project.summary} + + {edit ? ( + + ) : ( +
+ {project.technologies.slice(0, 4).map((tech) => ( + + {tech} + + ))} +
+ )} + {(edit || (project.metrics?.length ?? 0) > 0) && ( + + )} + {s.projects.viewDetails} → +
+
+ ) + // A card body is a link; its controls sit beside it, in an + // edit-mode shell that keeps the grid layout intact. + return edit ? ( +
+ edit.deleteRecord('project', { id: project.id })} + onSettings={() => setSettingsFor(project.id)} + /> + {card}
- - ))} + ) : ( + card + ) + })}
+ {edit && settingsFor && ( + setSettingsFor(null)}> + {(() => { + const project = c.projects.find((p) => p.id === settingsFor) + return project ? : null + })()} + + )} ) diff --git a/src/components/ui/EditableText.tsx b/src/components/ui/EditableText.tsx index 0548d05..3b38676 100644 --- a/src/components/ui/EditableText.tsx +++ b/src/components/ui/EditableText.tsx @@ -1,30 +1,49 @@ -// EditableText (spec-v4 §5.3): a text node bound to a text-document path. -// Outside edit mode it renders exactly the element the site renders today — -// same tag, same attributes, text as children, zero DOM/CSS/motion difference. -// In edit mode the same element becomes the inline editor. +// EditableText (spec-v4 §5.3, spec-v4-inline-editing E6/E7): a text node +// bound to a document path. Outside edit mode it renders exactly the element +// the site renders today — same tag, same attributes, text as children, zero +// DOM/CSS/motion difference. In edit mode the element stays text: editing is +// entered through the pencil on its corner, never by clicking the text, so a +// reader can still select and copy in edit mode. // // Hard rules implemented here: +// - the pencil starts editing; the element is contentEditable only while +// editing (E6); +// - while editing, the element carries a provenance chip — the file and path +// the value lives in (E7), clickable to copy; the pencil's title names the +// same target for hover; // - commit on blur only, never per keystroke — Vietnamese IME composition is // never truncated because no keystroke ever reaches the draft; // - Esc cancels the current edit and restores the last committed value; // - Enter commits + blurs single-line fields, inserts \n in multi-line ones; // - paste is sanitized to plain text; -// - an empty required value is rejected at commit (validator rule 6) and the -// field keeps focus; +// - an empty required value is rejected at commit (validator rule 6), the +// reason is shown on the field, and the field keeps focus; +// - a structure-document path (doc prop) writes through the same draft store — +// text and structure are one editing surface for the user (E1/E4); // - motion keeps transform ownership: this component edits only the text node // inside already-animated elements. -import { useContext, useRef, useState } from 'react'; +import { useContext, useEffect, useRef, useState } from 'react'; import type { ElementType, ReactNode } from 'react'; import { EditContext } from '@/hooks/useEdit'; +import type { EditApi } from '@/hooks/useEdit'; +import { useI18n } from '@/i18n/provider'; +import { parsePath, setPath } from '@/i18n/draft'; +import type { DraftDocId } from '@/i18n/draft'; +import { PencilIcon } from '@/components/ui/icons'; type EditableTextProps = { // The element this site renders today — tag or motion component. as?: ElementType; - // Text-document path, e.g. `projects.iot-dws-integration.summary`. + // Path inside the target document, e.g. `projects.iot-dws-integration.summary`. path: string; + // Target document; defaults to the text document of the edited language (E1). + doc?: DraftDocId; // Human-readable field name for the accessibility label (§5.3). label: string; multiline?: boolean; + // Extra non-text controls rendered inside the element as chrome islands — + // the per-item buttons a tag list attaches (spec-v4-inline-editing E5). + fieldControls?: ReactNode; children: ReactNode; className?: string; [prop: string]: unknown; @@ -33,17 +52,18 @@ type EditableTextProps = { export function EditableText({ as, path, + doc, label, multiline = false, + fieldControls, children, className, ...rest }: EditableTextProps) { const edit = useContext(EditContext); - const ref = useRef(null); - const [invalid, setInvalid] = useState(false); const Comp = (as ?? 'p') as ElementType; + // Without a provider the element is byte-identical to the plain one. if (!edit) { return ( @@ -52,20 +72,152 @@ export function EditableText({ ); } - const dirty = edit.isPathDirty(path); - const cls = [className, 'editable-text', dirty && 'edit-dirty', invalid && 'edit-invalid'] + return ( + + {children} + + ); +} + +// The chrome islands EditableText renders inside the element — excluded from +// the value and from a cancel-restore, never from the element's own text. +const CHROME_CLASSES = ['edit-pencil', 'edit-provenance', 'edit-field-error', 'edit-field-controls']; +const isChrome = (node: Node): boolean => + node.nodeType === Node.ELEMENT_NODE && + CHROME_CLASSES.some((c) => (node as HTMLElement).classList.contains(c)); + +// Read only the element's own text: chrome subtrees are rejected, and
+// plus block boxes become \n the way innerText would (§5.3 — multi-line text +// is stored as plain text with newlines, rendering unchanged). +function readElementText(el: HTMLElement): string { + const walker = document.createTreeWalker( + el, + NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, + { + acceptNode: (node) => (isChrome(node) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT), + }, + ); + let value = ''; + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + if (node.nodeType === Node.TEXT_NODE) { + value += node.textContent ?? ''; + continue; + } + const tag = (node as HTMLElement).tagName; + if (tag === 'BR') { + value += '\n'; + } else if ((tag === 'DIV' || tag === 'P') && value && !value.endsWith('\n')) { + value += '\n'; + } + } + return value.replace(/\n+$/, ''); +} + +// The editing element — all hooks live here so the provider decision above +// stays a plain branch (react/rules-of-hooks). +function EditableField({ + edit, + Comp, + docId, + path, + label, + multiline, + fieldControls, + className, + rest, + children, +}: { + edit: EditApi; + Comp: ElementType; + docId: DraftDocId; + path: string; + label: string; + multiline: boolean; + fieldControls?: ReactNode; + className?: string; + rest: Record; + children: ReactNode; +}) { + const { ui: s } = useI18n(); + const ref = useRef(null); + const [editing, setEditing] = useState(false); + const [error, setError] = useState(null); + const [copied, setCopied] = useState(false); + + const info = edit.describe(docId, path); + const pointer = `${info.doc} → ${info.pointer}`; + const dirty = edit.isPathDirtyIn(docId, path); + const cls = [className, 'editable-text', dirty && 'edit-dirty', error && 'edit-invalid'] .filter(Boolean) .join(' '); + // Entering edit mode: focus the element and put the caret at the end of + // its text — the browser clamps the caret out of a chrome island. + useEffect(() => { + if (!editing) return; + const el = ref.current; + if (!el) return; + el.focus({ preventScroll: true }); + const range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + const selection = window.getSelection(); + selection?.removeAllRanges(); + selection?.addRange(range); + }, [editing]); + const commit = () => { const el = ref.current; if (!el) return; - // innerText normalizes
/
line boxes into \n — multi-line text - // is stored as plain text with newlines, rendering unchanged (§5.3). - const value = (el.innerText ?? '').replace(/\n+$/, ''); - const issues = edit.commit(path, value); - setInvalid(issues !== null); - if (issues) el.focus(); // empty-required: the field keeps focus + const value = readElementText(el); + if (value.trim() === '') { + setError(s.edit.emptyRequired); + el.focus(); // empty-required: the field keeps focus + return; + } + const issues = + docId === edit.textDoc + ? edit.commit(path, value) + : edit.apply(docId, setPath(edit.dataOf(docId), parsePath(path), value)); + if (issues) { + setError(issues[0]?.message ?? 'invalid'); + el.focus(); + return; + } + setError(null); + setEditing(false); + }; + + // Esc: drop everything the user typed, keep the chrome, restore the last + // committed text. React owns no text-node diff here (the children string is + // unchanged), so the restored node survives the next render. + const cancel = () => { + const el = ref.current; + if (el && typeof children === 'string') { + for (const node of Array.from(el.childNodes)) { + if (!isChrome(node)) el.removeChild(node); + } + const pencil = el.querySelector('.edit-pencil'); + el.insertBefore(document.createTextNode(children), pencil ?? null); + } + setEditing(false); + setError(null); + }; + + const copyPath = () => { + void navigator.clipboard.writeText(`${info.repoPath} → ${info.pointer}`); + setCopied(true); + window.setTimeout(() => setCopied(false), 1500); }; return ( @@ -73,36 +225,78 @@ export function EditableText({ {...rest} ref={ref} className={cls} - contentEditable + contentEditable={editing || undefined} suppressContentEditableWarning - role="textbox" - aria-multiline={multiline || undefined} - aria-label={label} + role={editing ? 'textbox' : undefined} + aria-multiline={editing && multiline ? true : undefined} + aria-label={editing ? label : undefined} data-edit-path={path} - // Editing text must not follow the card link it sits inside. + // Editing text must not follow the card link it sits inside; in idle + // edit mode the click is inert, text stays selectable. onClick={(event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); }} - onBlur={commit} - onKeyDown={(event: React.KeyboardEvent) => { - if (event.key === 'Escape') { - event.preventDefault(); - const el = ref.current; - if (el && typeof children === 'string') el.innerText = children; - el?.blur(); // blurring commits the restored value — a no-op change - setInvalid(false); - } else if (event.key === 'Enter' && !multiline) { - event.preventDefault(); - ref.current?.blur(); // blur performs the commit (§5.3) - } - }} - onPaste={(event: React.ClipboardEvent) => { - event.preventDefault(); - document.execCommand('insertText', false, event.clipboardData.getData('text/plain')); - }} + onBlur={editing ? commit : undefined} + onKeyDown={ + editing + ? (event: React.KeyboardEvent) => { + if (event.key === 'Escape') { + event.preventDefault(); + cancel(); + } else if (event.key === 'Enter' && !multiline) { + event.preventDefault(); + ref.current?.blur(); // blur performs the commit (§5.3) + } + } + : undefined + } + onPaste={ + editing + ? (event: React.ClipboardEvent) => { + event.preventDefault(); + document.execCommand('insertText', false, event.clipboardData.getData('text/plain')); + } + : undefined + } > {children} + {fieldControls && ( + + {fieldControls} + + )} + {/* Editing chrome sits inside the element but outside the editable text + (contentEditable={false}), so it never reaches the value. mousedown + is prevented to keep the caret out of the chrome. */} + + {editing && ( + + )} + {error && ( + + {error} + + )} ); } diff --git a/src/components/ui/RecordControls.tsx b/src/components/ui/RecordControls.tsx new file mode 100644 index 0000000..346158c --- /dev/null +++ b/src/components/ui/RecordControls.tsx @@ -0,0 +1,102 @@ +// Record controls (spec-v4-inline-editing E2): the settings / move / delete +// cluster of one record, plus the ghost affordance that creates a new one. +// Rendered only in edit mode; the caller places them inside the record's own +// element, or beside it for cards whose body is a link. +import { useI18n } from '@/i18n/provider'; +import { ChevronDownIcon, ChevronUpIcon, GearIcon, PlusIcon, TrashIcon } from '@/components/ui/icons'; + +type RecordControlsProps = { + // Human-readable name of the record, carried into every aria-label. + label: string; + canUp?: boolean; + canDown?: boolean; + // The move pair renders only when the caller provides it — a filtered + // subset view (home featured grid) has no document-order move to offer. + onUp?: () => void; + onDown?: () => void; + onDelete: () => void; + onSettings?: () => void; +}; + +export function RecordControls({ + label, + canUp, + canDown, + onUp, + onDown, + onDelete, + onSettings, +}: RecordControlsProps) { + const { ui: s } = useI18n(); + return ( + + {onSettings && ( + + )} + {onUp && onDown && ( + <> + + + + )} + + + ); +} + +type AddGhostProps = { + label: string; + onClick: () => void; + // 'inline' sits at the end of a list; 'card' fills a grid cell like the + // cards beside it, so the new record appears as the next one. + variant?: 'inline' | 'card'; +}; + +export function AddGhost({ label, onClick, variant = 'inline' }: AddGhostProps) { + return ( + + ); +} diff --git a/src/components/ui/RecordSettings.tsx b/src/components/ui/RecordSettings.tsx new file mode 100644 index 0000000..737f0c2 --- /dev/null +++ b/src/components/ui/RecordSettings.tsx @@ -0,0 +1,189 @@ +// RecordSettings (spec-v4-inline-editing E2): the structure-settings dialog of +// one record. Inline editing covers text and tags; the fields that shape a +// record's structure — featured, section list, timeline variant, logo — live +// here, in a small form that writes through the same EditApi. +import { useEffect, useRef } from 'react'; +import type { ReactNode } from 'react'; +import { useEdit } from '@/hooks/useEdit'; +import { useI18n } from '@/i18n/provider'; +import { useClickOutside } from '@/hooks/useClickOutside'; +import type { ProjectStructure, ExperienceStructure } from '@/i18n/dict-types'; +import { ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon } from '@/components/ui/icons'; + +type RecordSettingsProps = { + title: string; + onClose: () => void; + children: ReactNode; +}; + +export function RecordSettings({ title, onClose, children }: RecordSettingsProps) { + const { ui: s } = useI18n(); + const ref = useRef(null); + useClickOutside(ref, onClose); + useEffect(() => { + const onKey = (event: KeyboardEvent) => { + if (event.key === 'Escape') onClose(); + }; + document.addEventListener('keydown', onKey); + return () => document.removeEventListener('keydown', onKey); + }, [onClose]); + return ( +
+
+ {title} + +
+
{children}
+
+ ); +} + +// A project's structure: featured visibility and the section list — order, +// type, delete, add (spec-v4-inline-editing §2.4). +export function ProjectSettingsPanel({ project }: { project: ProjectStructure }) { + const edit = useEdit(); + const { ui: s } = useI18n(); + if (!edit) return null; + const projects = edit.dataOf('projects') as ProjectStructure[]; + const index = projects.findIndex((p) => p.id === project.id); + if (index < 0) return null; + const sections = project.sections; + const typeLabels = s.edit.sectionTypes; + + return ( + <> + + +
{s.edit.sections}
+
    + {sections.map((section, i) => ( +
  • + {section.id} + + + + +
  • + ))} +
+ + + ); +} + +// A timeline entry's decoration and metadata: the current/gap variant marker, +// location, logo path — all structure fields of the experience document. +export function ExperienceSettingsPanel({ entry }: { entry: ExperienceStructure }) { + const edit = useEdit(); + const { ui: s } = useI18n(); + if (!edit) return null; + const experiences = edit.dataOf('experience') as ExperienceStructure[]; + const index = experiences.findIndex((e) => e.id === entry.id); + if (index < 0) return null; + + const writeOrDrop = (field: string, value: string) => { + const trimmed = value.trim(); + if (trimmed === '') { + edit.deleteStructured('experience', `[${index}].${field}`); + } else { + edit.setStructured('experience', `[${index}].${field}`, trimmed); + } + }; + + return ( + <> + + + + + ); +} diff --git a/src/components/ui/TagListEditor.tsx b/src/components/ui/TagListEditor.tsx new file mode 100644 index 0000000..60a968f --- /dev/null +++ b/src/components/ui/TagListEditor.tsx @@ -0,0 +1,132 @@ +// TagListEditor (spec-v4-inline-editing E5): an array field rendered with the +// site's own container and tag elements. Outside edit mode the markup is +// exactly what the section renders today — same container, same tag elements, +// zero chrome. In edit mode every item carries move/delete controls inside its +// own element (EditableText fieldControls islands) and a ghost add button +// follows the list. Text arrays (interests, keywords, metrics, tagline tags) +// and structure arrays (technologies, skills) are the same component — one +// editing surface (E1). +import type { ElementType } from 'react'; +import { useEdit } from '@/hooks/useEdit'; +import { useI18n } from '@/i18n/provider'; +import { EditableText } from '@/components/ui/EditableText'; +import { parsePath, setPath } from '@/i18n/draft'; +import type { DraftDocId } from '@/i18n/draft'; +import { ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon } from '@/components/ui/icons'; + +type TagListEditorProps = { + // Structure document to edit; defaults to the text document of the edited + // language (E1) — text arrays need no explicit doc. + doc?: DraftDocId; + // Array path inside that document: `profile.currentInterests` for a text + // document, `[2].technologies` for a structure document. + arrayPath: string; + items: string[]; + // The container and item elements the site renders today. + containerAs: ElementType; + containerClassName: string; + as: ElementType; + itemClassName?: string; + // Tag's accent variant, passed through when the site's tag component takes it. + accent?: boolean; + // Human-readable names for the accessibility labels and the add button. + labelPrefix: string; + addLabel: string; +}; + +export function TagListEditor({ + doc, + arrayPath, + items, + containerAs, + containerClassName, + as, + itemClassName, + accent, + labelPrefix, + addLabel, +}: TagListEditorProps) { + const edit = useEdit(); + const { ui: s } = useI18n(); + const Container = containerAs; + const Comp = as; + + if (!edit) { + return ( + + {items.map((item, i) => ( + + {item} + + ))} + + ); + } + const docId = doc ?? edit.textDoc; + + const write = (next: string[]) => + edit.apply(docId, setPath(edit.dataOf(docId), parsePath(arrayPath), next)); + + const controls = (i: number) => ( + <> + + + + + ); + + return ( + + {items.map((item, i) => ( + + {item} + + ))} + + + ); +} diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx index 8a84edf..28431eb 100644 --- a/src/components/ui/icons.tsx +++ b/src/components/ui/icons.tsx @@ -84,3 +84,58 @@ export function MoonIcon({ size = 20 }: IconProps) { ) } + +// Edit-mode chrome glyphs (spec-v4-inline-editing §3): one stroke language as +// the bar icons. The pencil opens an inline editor, the gear opens a record's +// structure settings, the arrows move array items, the trash removes a record. +export function PencilIcon({ size = 16 }: IconProps) { + return ( + + ) +} + +export function PlusIcon({ size = 16 }: IconProps) { + return ( + + ) +} + +export function TrashIcon({ size = 16 }: IconProps) { + return ( + + ) +} + +export function ChevronUpIcon({ size = 16 }: IconProps) { + return ( + + ) +} + +export function ChevronDownIcon({ size = 16 }: IconProps) { + return ( + + ) +} + +export function GearIcon({ size = 16 }: IconProps) { + return ( + + ) +} diff --git a/src/hooks/useEdit.ts b/src/hooks/useEdit.ts index 7caec21..ba8553d 100644 --- a/src/hooks/useEdit.ts +++ b/src/hooks/useEdit.ts @@ -1,17 +1,53 @@ -// The edit-mode context (spec-v4 §5.3): the API EditModeShell hands to -// EditableText consumers. Lives on its own so component files stay pure -// components (react/only-export-components). -import { createContext } from 'react'; +// The edit-mode context (spec-v4 §5.3, spec-v4-inline-editing E4): the API +// EditModeShell hands to every editing consumer. Lives on its own so +// component files stay pure components (react/only-export-components). +import { createContext, useContext } from 'react'; import type { ContentIssue } from '@/i18n/validate'; +import type { + ConflictField, + DraftDocId, + FieldInfo, + RecordIds, + RecordKind, +} from '@/i18n/draft'; -// commit/revert return the validator issues when the candidate draft is -// invalid (the edit was NOT applied), or null when it was accepted. +// commit/apply/revert return the validator issues when the candidate draft is +// invalid (the change was NOT applied), or null when it was accepted. export type EditApi = { + // The text document of the language being edited — the default `doc` for + // every text path (E1). + textDoc: DraftDocId; + // Text-document helpers, unchanged from v1 (paths relative to textDoc). commit: (path: string, value: string) => ContentIssue[] | null; revert: (path: string) => ContentIssue[] | null; isPathDirty: (path: string) => boolean; + // Generic draft surface (E4): read one document, propose the next version, + // ask where a field lives. + describe: (doc: DraftDocId, path: string) => FieldInfo; + apply: (doc: DraftDocId, next: unknown) => ContentIssue[] | null; + dataOf: (doc: DraftDocId) => unknown; + // Structure fields (E4): set or delete one value at a concrete path. + setStructured: (doc: DraftDocId, path: string, value: unknown) => ContentIssue[] | null; + deleteStructured: (doc: DraftDocId, path: string) => ContentIssue[] | null; + isPathDirtyIn: (doc: DraftDocId, path: string) => boolean; + // One primitive for every order question (E5): record order (document root + // array) and tag order (array field) are the same move. + moveItem: (doc: DraftDocId, path: string, from: number, to: number) => ContentIssue[] | null; + // Records (E2/E3): structure record + text entries move as one action. + addRecord: (kind: RecordKind, options?: { projectId?: string }) => ContentIssue[] | null; + deleteRecord: (kind: RecordKind, ids: RecordIds) => ContentIssue[] | null; + // A draft-only record's id follows its title; a saved record's id is fixed. + isCreated: (kind: RecordKind, ids: RecordIds) => boolean; + renameRecord: (kind: RecordKind, ids: RecordIds, rawId: string) => ContentIssue[] | null; + // Conflicts, field by field (E8). + conflictFields: (doc: DraftDocId) => ConflictField[]; + resolveConflictField: (doc: DraftDocId, path: string, side: 'mine' | 'theirs') => ContentIssue[] | null; }; // Without a provider (every visitor request, every page outside edit mode) -// the context is null and EditableText is transparent. +// the context is null and every editing affordance is absent. export const EditContext = createContext(null); + +export function useEdit(): EditApi | null { + return useContext(EditContext); +} diff --git a/src/i18n/locales/en/ui.json b/src/i18n/locales/en/ui.json index f37c0e2..65b7fa1 100644 --- a/src/i18n/locales/en/ui.json +++ b/src/i18n/locales/en/ui.json @@ -114,6 +114,50 @@ "QR_ALT": "QR code" }, "edit": { + "editField": "Edit this field", + "copyPath": "Copy JSON path", + "pathCopied": "Copied", + "emptyRequired": "Required fields cannot be empty", + "settings": "Record settings", + "closeSettings": "Close settings", + "moveUp": "Move up", + "moveDown": "Move down", + "remove": "Remove", + "removeConfirm": "Remove this item?", + "newTag": "new", + "emphasis": "Emphasis", + "featured": "Featured on the home page", + "sections": "Sections", + "sectionType": "Section type", + "sectionTypes": { + "text": "prose", + "diagram": "diagram", + "metrics": "metrics", + "code": "code" + }, + "conflictFields": "Show conflicting fields", + "yours": "mine:", + "theirs": "theirs:", + "keepMine": "Keep mine", + "keepTheirs": "Keep theirs", + "variant": "Timeline variant", + "variantNone": "normal", + "variantCurrent": "current role", + "variantGap": "career break", + "addTaglineSegment": "Add tagline segment", + "addKeyword": "Add keyword", + "addInterest": "Add interest", + "addSkill": "Add skill", + "addTechnology": "Add technology", + "addMetric": "Add metric", + "addResponsibility": "Add responsibility", + "addQuoteDetail": "Add quote paragraph", + "addQuote": "Add quote", + "addProject": "Add project", + "addSection": "Add section", + "addExperience": "Add experience", + "addSkillGroup": "Add skill group", + "addPhilosophy": "Add philosophy point", "title": "Edit mode", "changes": "Unsaved changes", "noChanges": "No unsaved changes", @@ -178,7 +222,14 @@ "quoteDetail": "quote paragraph", "company": "company", "duration": "duration", - "projectRole": "project role" + "projectRole": "project role", + "interests": "interest", + "skill": "skill", + "technology": "technology", + "metric": "metric", + "pointKeywords": "philosophy keyword", + "location": "location", + "logo": "logo" } } } diff --git a/src/i18n/locales/vi/ui.json b/src/i18n/locales/vi/ui.json index 4584d60..13ed022 100644 --- a/src/i18n/locales/vi/ui.json +++ b/src/i18n/locales/vi/ui.json @@ -114,6 +114,50 @@ "QR_ALT": "mã QR" }, "edit": { + "editField": "Sửa trường này", + "copyPath": "Copy đường dẫn JSON", + "pathCopied": "Đã copy", + "emptyRequired": "Trường bắt buộc không được để trống", + "settings": "Cài đặt bản ghi", + "closeSettings": "Đóng cài đặt", + "moveUp": "Chuyển lên", + "moveDown": "Chuyển xuống", + "remove": "Xóa", + "removeConfirm": "Xóa mục này?", + "newTag": "mới", + "emphasis": "Nhấn mạnh", + "featured": "Nổi bật", + "sections": "Các mục", + "sectionType": "Kiểu mục", + "sectionTypes": { + "text": "chữ", + "diagram": "sơ đồ", + "metrics": "chỉ số", + "code": "code" + }, + "conflictFields": "Xem các trường xung đột", + "yours": "bản của tôi:", + "theirs": "bản gốc:", + "keepMine": "Giữ bản của tôi", + "keepTheirs": "Giữ bản gốc", + "variant": "Biến thể timeline", + "variantNone": "bình thường", + "variantCurrent": "đang làm", + "variantGap": "nghỉ giữa hai vai trò", + "addTaglineSegment": "Thêm đoạn tagline", + "addKeyword": "Thêm từ khóa", + "addInterest": "Thêm sở thích", + "addSkill": "Thêm kỹ năng", + "addTechnology": "Thêm công nghệ", + "addMetric": "Thêm chỉ số", + "addResponsibility": "Thêm trách nhiệm", + "addQuoteDetail": "Thêm đoạn trích dẫn", + "addQuote": "Thêm trích dẫn", + "addProject": "Thêm dự án", + "addSection": "Thêm mục", + "addExperience": "Thêm kinh nghiệm", + "addSkillGroup": "Thêm nhóm kỹ năng", + "addPhilosophy": "Thêm nguyên lý", "title": "Chế độ sửa", "changes": "Thay đổi chưa lưu", "noChanges": "Không có thay đổi chưa lưu", @@ -178,7 +222,14 @@ "quoteDetail": "đoạn trích dẫn", "company": "công ty", "duration": "thời gian công tác", - "projectRole": "vai trò dự án" + "projectRole": "vai trò dự án", + "interests": "sở thích", + "skill": "kỹ năng", + "technology": "công nghệ", + "metric": "chỉ số", + "pointKeywords": "từ khóa nguyên lý", + "location": "địa điểm", + "logo": "logo" } } } diff --git a/src/pages/AboutPage.tsx b/src/pages/AboutPage.tsx index 33e67db..f698009 100644 --- a/src/pages/AboutPage.tsx +++ b/src/pages/AboutPage.tsx @@ -3,10 +3,15 @@ import { SectionHeading } from '@/components/ui/SectionHeading' import { Tag } from '@/components/ui/Tag' import { InView } from '@/components/ui/InView' import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' export function AboutPage() { const { ui: s, content: c } = useI18n() + const edit = useEdit() + return ( <> @@ -51,7 +56,7 @@ export function AboutPage() { {c.profile.philosophy.map((point, i) => ( + {edit && ( + 0} + canDown={i < c.profile.philosophy.length - 1} + onUp={() => edit.moveItem('profile', 'philosophy', i, i - 1)} + onDown={() => edit.moveItem('profile', 'philosophy', i, i + 1)} + onDelete={() => edit.deleteRecord('philosophy', { id: point.id })} + /> + )} {point.title} {point.description} -
- {point.keywords.map((kw) => ( - {kw} - ))} -
+
))} + {edit && edit.addRecord('philosophy')} />}

{s.about.exploringTitlePage}

-
- {c.profile.currentInterests.map((interest) => ( - - {interest} - - ))} -
+ @@ -103,7 +126,7 @@ export function AboutPage() { {c.skillGroups.map((group, i) => ( + {edit && ( + 0} + canDown={i < c.skillGroups.length - 1} + onUp={() => edit.moveItem('skills', '', i, i - 1)} + onDown={() => edit.moveItem('skills', '', i, i + 1)} + onDelete={() => edit.deleteRecord('skill-group', { id: group.id })} + /> + )} {group.title} -
    - {group.skills.map((skill: string) => ( -
  • - {skill} -
  • - ))} -
+
))} + {edit && edit.addRecord('skill-group')} />}
diff --git a/src/pages/ExperiencePage.tsx b/src/pages/ExperiencePage.tsx index eb7ba08..866da40 100644 --- a/src/pages/ExperiencePage.tsx +++ b/src/pages/ExperiencePage.tsx @@ -2,10 +2,17 @@ import { motion } from 'motion/react' import { SectionHeading } from '@/components/ui/SectionHeading' import { InView } from '@/components/ui/InView' import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { RecordSettings, ExperienceSettingsPanel } from '@/components/ui/RecordSettings' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' +import { useState } from 'react' export function ExperiencePage() { const { ui: s, content: c } = useI18n() + const edit = useEdit() + const [settingsFor, setSettingsFor] = useState(null) return ( (
+ {edit && ( + 0} + canDown={i < c.experiences.length - 1} + onUp={() => edit.moveItem('experience', '', i, i - 1)} + onDown={() => edit.moveItem('experience', '', i, i + 1)} + onDelete={() => edit.deleteRecord('experience', { id: exp.id })} + onSettings={() => setSettingsFor(exp.id)} + /> + )}
{exp.title} @@ -45,20 +69,18 @@ export function ExperiencePage() { {exp.location && {exp.location}}
-
    - {exp.responsibilities.map((r, ri) => ( - - {r} - - ))} -
+
))} + {edit && edit.addRecord('experience')} />}
+ {edit && settingsFor && ( + setSettingsFor(null)}> + {(() => { + const entry = c.experiences.find((e) => e.id === settingsFor) + return entry ? : null + })()} + + )}
diff --git a/src/pages/PhilosophyPage.tsx b/src/pages/PhilosophyPage.tsx index 5101347..bc7f504 100644 --- a/src/pages/PhilosophyPage.tsx +++ b/src/pages/PhilosophyPage.tsx @@ -2,11 +2,19 @@ import {SectionHeading} from '@/components/ui/SectionHeading' import {EditableText} from '@/components/ui/EditableText' import {motion} from 'motion/react' import {InView} from '@/components/ui/InView' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { useEdit } from '@/hooks/useEdit' +import { useI18n } from '@/i18n/provider' +import { setPath, parsePath } from '@/i18n/draft' -import {useI18n} from '@/i18n/provider' +// philosophyQuotes are text-only records: they live in the language document +// being edited, so add and delete go through the plain document primitives. +const quotesPath = 'profile.philosophyQuotes' export function PhilosophyPage() { const {ui: s, content: c} = useI18n() + const edit = useEdit() return ( ( + {edit && ( + 0} + canDown={i < c.profile.philosophyQuotes.length - 1} + onUp={() => edit.moveItem(edit.textDoc, quotesPath, i, i - 1)} + onDown={() => edit.moveItem(edit.textDoc, quotesPath, i, i + 1)} + onDelete={() => { + const doc = edit.dataOf(edit.textDoc) as Record + const next = setPath(doc, parsePath(quotesPath), + (doc.profile.philosophyQuotes as unknown[]).filter((_, j) => j !== i)) + edit.apply(edit.textDoc, next) + }} + /> + )} {quote.title} -
- {quote.details.map((detail, j) => ( - - {detail} - - ))} -
+
))} + {edit && ( + { + const doc = edit.dataOf(edit.textDoc) as Record + const next = setPath(doc, parsePath(quotesPath), + [...(doc.profile.philosophyQuotes as unknown[]), { title: 'New quote', details: ['Write the quote here.'] }]) + edit.apply(edit.textDoc, next) + }} + /> + )}
diff --git a/src/pages/ProjectDetailPage.tsx b/src/pages/ProjectDetailPage.tsx index f1f8e48..5992bc9 100644 --- a/src/pages/ProjectDetailPage.tsx +++ b/src/pages/ProjectDetailPage.tsx @@ -5,7 +5,11 @@ import { Tag } from '@/components/ui/Tag' import { EditableText } from '@/components/ui/EditableText' import { InView } from '@/components/ui/InView' import { useI18n } from '@/i18n/provider' - +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { RecordSettings, ProjectSettingsPanel } from '@/components/ui/RecordSettings' +import { useEdit } from '@/hooks/useEdit' +import { useState } from 'react' const sectionVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { duration: 0.5 } }, @@ -20,8 +24,9 @@ const itemTransition = (delay: number): Transition => ({ export function ProjectDetailPage() { const { id } = useParams<{ id: string }>() const { ui: s, content: c } = useI18n() + const edit = useEdit() + const [settingsOpen, setSettingsOpen] = useState(false) const project = c.projects.find((p) => p.id === id) - if (!project) { return ( @@ -66,6 +71,13 @@ export function ProjectDetailPage() { {project.title} {s.projects.categories[project.category]} + {edit && ( + edit.deleteRecord('project', { id: project.id })} + onSettings={() => setSettingsOpen(true)} + /> + )}
- {project.metrics && project.metrics.length > 0 && ( + {(edit || (project.metrics?.length ?? 0) > 0) && (

{s.projectDetail.impact}

-
- {project.metrics.map((m) => ( - - {m} - - ))} -
+
)} @@ -120,14 +135,19 @@ export function ProjectDetailPage() { transition={itemTransition(0.32)} >

{s.projectDetail.technologies}

-
- {project.technologies.map((tech) => ( - {tech} - ))} -
+ p.id === project.id)}].technologies`} + items={project.technologies} + containerAs="div" + containerClassName="philosophy-keywords" + as={Tag} + labelPrefix={`${project.title} — ${s.edit.fields.technology}`} + addLabel={s.edit.addTechnology} + /> - {project.sections && project.sections.length > 0 && ( + {(edit || (project.sections?.length ?? 0) > 0) && (
{project.sections.map((section, idx) => ( + {edit && ( + 0} + canDown={idx < (project.sections?.length ?? 0) - 1} + onUp={() => edit.moveItem('projects', `[${c.projects.findIndex((p) => p.id === project.id)}].sections`, idx, idx - 1)} + onDown={() => edit.moveItem('projects', `[${c.projects.findIndex((p) => p.id === project.id)}].sections`, idx, idx + 1)} + onDelete={() => edit.deleteRecord('section', { id: section.id, projectId: project.id })} + /> + )} {section.title} @@ -155,9 +185,20 @@ export function ProjectDetailPage() { {section.type} ))} + {edit && ( + edit.addRecord('section', { projectId: project.id })} + /> + )}
)}
+ {edit && settingsOpen && ( + setSettingsOpen(false)}> + + + )}
) diff --git a/src/pages/ProjectsListPage.tsx b/src/pages/ProjectsListPage.tsx index bb6a4a5..06f2383 100644 --- a/src/pages/ProjectsListPage.tsx +++ b/src/pages/ProjectsListPage.tsx @@ -3,7 +3,12 @@ import { Badge } from '@/components/ui/Badge' import { motion } from 'motion/react' import { InView } from '@/components/ui/InView' import { EditableText } from '@/components/ui/EditableText' +import { TagListEditor } from '@/components/ui/TagListEditor' +import { RecordControls, AddGhost } from '@/components/ui/RecordControls' +import { RecordSettings, ProjectSettingsPanel } from '@/components/ui/RecordSettings' +import { useEdit } from '@/hooks/useEdit' import { useI18n } from '@/i18n/provider' +import { useState } from 'react' import { Link } from 'react-router' @@ -12,6 +17,8 @@ const MotionLink = motion.create(Link) export function ProjectsListPage() { const { ui: s, content: c } = useI18n() + const edit = useEdit() + const [settingsFor, setSettingsFor] = useState(null) return (
- {c.projects.map((project, i) => ( - -
- - {project.title} + {c.projects.map((project, i) => { + const card = ( + +
+ + {project.title} + + + {s.projects.categories[project.category]} + +
+ + {project.summary} - - {s.projects.categories[project.category]} - + {edit ? ( + + ) : ( +
+ {project.technologies.slice(0, 4).map((tech) => ( + + {tech} + + ))} +
+ )} + {s.projects.viewDetails} → +
+ ) + return edit ? ( +
+ 0} + canDown={i < c.projects.length - 1} + onUp={() => edit.moveItem('projects', '', i, i - 1)} + onDown={() => edit.moveItem('projects', '', i, i + 1)} + onDelete={() => edit.deleteRecord('project', { id: project.id })} + onSettings={() => setSettingsFor(project.id)} + /> + {card}
- - {project.summary} - -
- {project.technologies.slice(0, 4).map((tech) => ( - - {tech} - - ))} -
- {s.projects.viewDetails} → - - ))} + ) : ( + card + ) + })} + {edit && edit.addRecord('project')} />}
+ {edit && settingsFor && ( + setSettingsFor(null)}> + {(() => { + const project = c.projects.find((p) => p.id === settingsFor) + return project ? : null + })()} + + )} )