feat(edit): inline editing controls on every record surface (spec-v4-inline-editing §5 steps 1-7)

- 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
This commit is contained in:
dong.nguyen committed 2026-10-23 09:36:59 +07:00
1 parent 753b28a4e3
commit 0a72cd9b58
22 files changed
+1812 -277

No files matched your search

+49 -18
View File
@@ -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<Set<DraftDocId>>(new Set());
const allWritten =
saveResults.length > 0 && !saveStopped && saveResults.every((r) => r.status === 'written');
@@ -99,9 +102,6 @@ export function EditBar({
>
{s.changesTitle}
</button>
<button type="button" className="edit-btn" onClick={onOpenPanel}>
{s.openPanel}
</button>
<button
type="button"
className="edit-btn edit-btn-primary"
@@ -159,7 +159,7 @@ export function EditBar({
<div className="edit-bar-conflicts">
<strong>{s.conflicts}</strong>
{conflicts.map((id) => (
<span key={id} className="edit-bar-conflict">
<div key={id} className="edit-bar-conflict">
<code>{fileOf(id)}</code> {s.conflictDetail}{' '}
<button type="button" className="edit-btn" onClick={() => onRebase(id)}>
{s.rebase}
@@ -167,10 +167,41 @@ export function EditBar({
<button type="button" className="edit-btn" onClick={() => onTakeTheirs(id)}>
{s.takeTheirs}
</button>
<button type="button" className="edit-btn" onClick={() => onHandMerge(id)}>
{s.handMerge}
<button
type="button"
className="edit-btn"
aria-expanded={openFields.has(id)}
onClick={() =>
setOpenFields((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
})
}
>
{s.conflictFields}
</button>
</span>
{openFields.has(id) && (
<ul className="edit-bar-conflict-fields">
{getConflictFields(id).map((f) => (
<li key={f.path}>
<code className="edit-bar-path">{f.path}</code>
<span className="edit-bar-conflict-side">{s.yours}</span>
<span className="edit-bar-value">{truncate(f.mine)}</span>
<span className="edit-bar-conflict-side">{s.theirs}</span>
<span className="edit-bar-value">{truncate(f.theirs)}</span>
<button type="button" className="edit-btn" onClick={() => onResolveField(id, f.path, 'mine')}>
{s.keepMine}
</button>
<button type="button" className="edit-btn" onClick={() => onResolveField(id, f.path, 'theirs')}>
{s.keepTheirs}
</button>
</li>
))}
</ul>
)}
</div>
))}
</div>
)}
+87 -29
View File
@@ -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<PanelTab>('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<EditApi | null>(
() =>
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 && (
<JsonPanel
store={store}
tab={panelTab}
revision={revision}
conflicts={conflicts}
onClose={() => setPanelOpen(false)}
onTab={setPanelTab}
onChanged={() => {
setIssues(store.validate());
refresh(store);
}}
onConflictResolved={(id) => setConflicts((prev) => prev.filter((x) => x !== id))}
/>
)}
</>
)}
</EditContext.Provider>