open-agreements
Version:
Open-source legal template filling CLI and library
88 lines • 5.14 kB
TypeScript
/**
* In-Place AST Modifier
*
* Modifies the revised document's AST in-place to add track changes markup.
* This replaces the reconstruction-based approach with direct tree manipulation.
*/
import type { ComparisonUnitAtom } from '../../core-types.js';
import { type RevisionIdState } from './inPlaceModifier-shared.js';
import { type BookmarkSurvivalContext } from './inPlaceModifier-bookmarks.js';
export declare function getInsertableAtomContentElements(atom: ComparisonUnitAtom, filterRun?: Element): Element[];
/**
* Clone a source run and replace its non-rPr children with atom content.
*
* This keeps run-level formatting while allowing atom-level fragment insertion.
*
* @param filterRun - When provided, only include content elements belonging
* to this source run (for multi-run collapsed field replay).
*/
export declare function cloneRunWithAtomContent(sourceRun: Element, atom: ComparisonUnitAtom, filterRun?: Element): Element;
/**
* Clone a deleted run from the original document and insert it into the revised document.
*
* For a single-content atom this wraps one cloned run in `<w:del>` and returns
* the `<w:del>` element. For a collapsed-field atom (issue #217), control
* routes to `insertFragmentedDeletedField` which emits multiple sibling
* elements — `w:fldChar` runs at sibling level (unwrapped) and individual
* `<w:del>` wrappers around each payload run — and returns the LAST inserted
* sibling (which may be a `<w:r>` carrying the end fldChar, not a `<w:del>`).
* Callers use the return value purely as the next insertion anchor.
*
* @param deletedAtom - Atom with the deleted content
* @param insertAfterRun - The run to insert after (null to insert at beginning of paragraph)
* @param targetParagraph - The paragraph to insert into
* @param author - Author name
* @param dateStr - Formatted date
* @param state - Revision ID state
* @returns The last inserted sibling element (a `<w:del>` for non-collapsed-field
* atoms; possibly a `<w:r>` for fragmented collapsed-field atoms), or null
* if insertion failed.
*/
export declare function insertDeletedRun(deletedAtom: ComparisonUnitAtom, insertAfterRun: Element | null, targetParagraph: Element, author: string, dateStr: string, state: RevisionIdState, context?: BookmarkSurvivalContext): Element | null;
/**
* Emit a fragmented deletion of a collapsed-field atom: walks the constituent
* source runs in document order, cloning each into the target paragraph as
* either a sibling-level unwrapped run (for `w:fldChar`) or a `<w:del>`-wrapped
* run (for payload runs whose text is renamed to `w:delText` / `w:delInstrText`).
*
* Returns the last sibling element inserted, which the caller uses as the
* next insertion anchor (preserving the contract of `insertDeletedRun`).
*
* @conformance ECMA-376 edition 5, Part 4 § 17.16.5
*
* Rule: `w:delInstrText` MUST appear inside `<w:del>`;
* by extension and by issue #217's deep-research conclusion, `w:fldChar` runs
* stay at sibling level.
*/
export declare function insertFragmentedDeletedField(deletedAtom: ComparisonUnitAtom, sourceRun: Element, insertAfterRun: Element | null, targetParagraph: Element, author: string, dateStr: string, state: RevisionIdState, context?: BookmarkSurvivalContext): Element | null;
/**
* Clone a moved-from run from the original document and insert it into the revised document.
*
* MovedSource atoms have their sourceRunElement in the ORIGINAL tree, but we need to
* insert the content into the REVISED tree. This function clones the run, wraps it with
* <w:moveFrom> and range markers, and inserts at the correct position.
*
* @param atom - Atom with the moved-from content
* @param moveName - Name for linking source and destination
* @param insertAfterRun - The run to insert after (null to insert at beginning of paragraph)
* @param targetParagraph - The paragraph to insert into
* @param author - Author name
* @param dateStr - Formatted date
* @param state - Revision ID state
* @returns The inserted moveFrom element, or null if insertion failed
*/
export declare function insertMoveFromRun(atom: ComparisonUnitAtom, moveName: string, insertAfterRun: Element | null, targetParagraph: Element, author: string, dateStr: string, state: RevisionIdState, context?: BookmarkSurvivalContext): Element | null;
/**
* Clone a deleted paragraph from the original document and insert it.
*
* @param deletedAtom - Atom representing the deleted paragraph
* @param insertAfterParagraph - Paragraph to insert after (null to insert at body start)
* @param targetBody - The body element to insert into
* @param author - Author name
* @param dateStr - Formatted date
* @param state - Revision ID state
* @returns The inserted paragraph, or null if insertion failed
*/
export declare function insertDeletedParagraph(deletedAtom: ComparisonUnitAtom, insertAfterParagraph: Element | null, targetContainer: Element, author: string, dateStr: string, state: RevisionIdState): Element | null;
export declare const FIELD_CHAR_TAG_NAMES: ReadonlySet<string>;
//# sourceMappingURL=inPlaceModifier-deletion.d.ts.map