// How an ask is spoken of in the chrome: its verb and its place, as a line // ("Outline the piece", "Write §3"), and as what is going on ("writing §3"). // The place is named by the document, so the section numbers are the page's. import type { Node as PMNode } from '@tiptap/pm/model'; import type { Ask, AskScope, AskVerb } from './draft.ts'; import { findBlock } from './doc.ts'; /** An assistant's name without what follows in brackets: "the house assistant", "hm-write". */ export const shortWho = (name: string): string => name.replace(/\s*\(.*\)\s*$/, ''); export const VERB_NAMES: Record = { write: 'Write', finer: 'Finer', tighten: 'Tighten', review: 'Review', proofread: 'Proofread', outline: 'Outline', structure: 'Review the structure of', anything: 'About' }; const DOING: Record = { write: 'writing', finer: 'going finer in', tighten: 'tightening', review: 'reviewing', proofread: 'proofreading', outline: 'outlining', structure: 'reviewing the structure of', anything: 'on' }; /** The place an ask is made about, as a word or a section number. */ export function scopeName(scope: AskScope, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { switch (scope.kind) { case 'piece': return opts.chapter ? 'this chapter' : 'the piece'; case 'book': return 'the book'; case 'selection': return 'the selection'; case 'note': return 'a note'; case 'section': { const b = doc ? findBlock(doc, scope.id) : undefined; return b?.number ? `§${b.number}` : 'a section'; } } } /** "Outline the piece", "Write §3", "Finer in §2.1". */ export function describeAsk(a: Pick, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { const place = scopeName(a.scope, doc, opts); if (a.verb === 'finer') return `Finer in ${place}`; return `${VERB_NAMES[a.verb]} ${place}`; } /** "writing §3", for a chip while it goes on. */ export function doingAsk(a: Pick, doc: PMNode | null, opts: { chapter?: boolean } = {}): string { return `${DOING[a.verb]} ${scopeName(a.scope, doc, opts)}`; }