Add sub-tabs to records sections (Refs #18)
Records sections can be split into user-named sub-tabs with a General catch-all. Records and visual sequences move between tabs via a Sub-tab drop-down; up/down, collapse all and print work per tab. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
26
src/model.js
26
src/model.js
@@ -15,6 +15,12 @@ import { isImageDataUrl, MAX_IMAGE_DATA_CHARS } from './images.js';
|
||||
// 'steps' -> { items: [Item] } ordered instructions (wind-down)
|
||||
// 'checklist' -> { items: [Item] } things still to add/do
|
||||
// Every section has { id, title, kind } and may have { intro: string }.
|
||||
// A 'records' section may also have sub-tabs:
|
||||
// subsections?: [{ id, title }] user-defined tabs, in display order
|
||||
// generalTitle?: string name of the catch-all first tab (default 'General')
|
||||
// Each record or sequence in its list may carry `subsection: <a subsections id>`.
|
||||
// No `subsection` (or one that matches no tab) means the General tab. With no
|
||||
// subsections the section shows no tabs at all.
|
||||
//
|
||||
// Record: { id, title, status: 'ok'|'tbd', updated: 'YYYY-MM-DD',
|
||||
// fields: [Field], notes?: string }
|
||||
@@ -38,6 +44,7 @@ import { isImageDataUrl, MAX_IMAGE_DATA_CHARS } from './images.js';
|
||||
// in the UI and optionally in print output.
|
||||
|
||||
export const SCHEMA_VERSION = 1;
|
||||
export const GENERAL_TITLE = 'General';
|
||||
export const SECTION_KINDS = ['text', 'records', 'steps', 'checklist'];
|
||||
export const RECORD_STATUSES = ['ok', 'tbd'];
|
||||
export const ITEM_STATUSES = ['open', 'done', 'tbd'];
|
||||
@@ -117,6 +124,7 @@ export function validate(doc) {
|
||||
if (!isStr(s.title) || !s.title) errs.push(`${where}: missing title`);
|
||||
if (s.intro !== undefined && !isStr(s.intro)) errs.push(`${where}: intro must be a string`);
|
||||
if (!SECTION_KINDS.includes(s.kind)) return errs.push(`${where}: unknown kind "${s.kind}"`);
|
||||
if (s.kind !== 'records' && (s.subsections !== undefined || s.generalTitle !== undefined)) errs.push(`${where}: only records sections can have sub-tabs`);
|
||||
|
||||
if (s.kind === 'text') {
|
||||
if (!isStr(s.body)) errs.push(`${where}: text section needs a body string`);
|
||||
@@ -126,7 +134,23 @@ export function validate(doc) {
|
||||
}
|
||||
} else if (s.kind === 'records') {
|
||||
if (!Array.isArray(s.records)) return errs.push(`${where}: records must be an array`);
|
||||
s.records.forEach((r, j) => (isSequence(r) ? checkSequence : checkRecord)(r, `${where}.records[${j}]`));
|
||||
const tabIds = new Set();
|
||||
if (s.generalTitle !== undefined && (!isStr(s.generalTitle) || !s.generalTitle.trim())) errs.push(`${where}: generalTitle must be a non-empty string`);
|
||||
if (s.subsections !== undefined) {
|
||||
if (!Array.isArray(s.subsections)) errs.push(`${where}: subsections must be an array`);
|
||||
else s.subsections.forEach((t, j) => {
|
||||
const tw = `${where}.subsections[${j}]`;
|
||||
if (!isObj(t)) return errs.push(`${tw}: must be an object`);
|
||||
checkId(t.id, tw);
|
||||
if (isStr(t.id)) tabIds.add(t.id);
|
||||
if (!isStr(t.title) || !t.title.trim()) errs.push(`${tw}: missing title`);
|
||||
});
|
||||
}
|
||||
s.records.forEach((r, j) => {
|
||||
const rw = `${where}.records[${j}]`;
|
||||
(isSequence(r) ? checkSequence : checkRecord)(r, rw);
|
||||
if (isObj(r) && r.subsection !== undefined && !tabIds.has(r.subsection)) errs.push(`${rw}: subsection "${r.subsection}" is not one of this section's sub-tabs`);
|
||||
});
|
||||
} else {
|
||||
if (!Array.isArray(s.items)) return errs.push(`${where}: items must be an array`);
|
||||
s.items.forEach((it, j) => (isSequence(it) ? checkSequence : checkItem)(it, `${where}.items[${j}]`));
|
||||
|
||||
Reference in New Issue
Block a user