← All packages

@searsuite/sear-domain-editor

Editor and layout

DocLayoutEngine computes document geometry for a viewport. The viewport and page contracts describe which part of that layout a host should paint.

classDocLayoutCache

Immutable snapshot of block-level document layout used by viewport and SceneGraph projection.

constructorDocLayoutCache(snapshot: LayoutSnapshot, blocksOrIndex: IndexedSnapshot<LayoutSnapshot, DocBlockLayout, DocNodeId> | readonly DocBlockLayout[]): DocLayoutCache

Creates a layout cache from already computed block records.

snapshot

Layout snapshot used to derive this cache.

blocksOrIndex

Top-level block layout records ordered by document position, or a custom indexed store.

memberblocks
blocks: unknown
membersnapshot
snapshot: unknown
methodgetBlockById(id: DocNodeId): DocBlockLayout | null

Returns the cached layout record for a document block id.

methodgetBlockByIndex(index: number): DocBlockLayout | null

Returns the cached layout record for a top-level block index.

methodgetBlockIdsByIndexes(indexes: readonly number[]): readonly DocNodeId[]

Returns block ids for the supplied top-level block indexes.

methodgetBlocksInVerticalRange(top: number, bottom: number): readonly DocBlockLayout[]

Returns all cached block records intersecting the supplied vertical range.

methodgetContentLayoutReusableBlockIndexes(previous: DocLayoutCache): readonly number[]

Returns block indexes whose internal content layout can be reused from a previous cache.

A downstream flow shift changes absolute rect.y, so the whole block record cannot be reused. The renderer can still reuse the block's measured content shape when line count, visual size and flow height are unchanged.

methodhasBlockFlowLayoutChanged(previous: DocLayoutCache, blockId: DocNodeId): boolean

Returns whether one block's height-sensitive flow layout changed.

methodhasFlowHeightChanged(previous: DocLayoutCache, blockId: DocNodeId): boolean

Returns whether one block's flow height changed compared with another cache.

methodfromSnapshot(document: readonly RichDocNode[], snapshot: LayoutSnapshot, previousCache?: DocLayoutCache | null): DocLayoutCachestatic

Builds a block layout cache from a rich document and its layout snapshot.

classDocLayoutEngine

Converts between DocCursorPos (path + char offset) and pixel coordinates (relative to the editor box top-left corner), using rich-text block measurements.

Mirrors the Y-positioning formula used by the document render layout so that cursor positions align with rendered glyphs.

constructorDocLayoutEngine(blockFlowRegistry: RichTextBlockFlowRegistry): DocLayoutEngine
propertyreadonly symbol: symbolstatic

DI token for resolving DocLayoutEngine.

methodbuildSnapshot(doc: RichDocNode[], blockManager: RichTextBlockLayoutProvider, editorWidth: number, editorHeight: number, cellPadding?: number, verticalAlign?: DocVerticalAlign): LayoutSnapshot

Build a LayoutSnapshot from the current blockManager state.

Prerequisites: callers must add all document paragraphs to blockManager before building the snapshot.

doc

The current RichDocNode[] being edited.

blockManager

Layout provider that already holds the paragraph blocks.

editorWidth

Total pixel width of the editor box (including padding).

editorHeight

Total pixel height of the editor box (including padding).

cellPadding

Padding on each side (default 4).

verticalAlign

Vertical positioning strategy (default center for embedded cell editors).

methodbuildSnapshotForBlocks(doc: RichDocNode[], blockManager: RichTextBlockLayoutProvider, blockIndexes: readonly number[], blockTops: readonly number[], editorWidth: number, cellPadding?: number): BlockLayoutSnapshot

Builds a snapshot for selected top-level document blocks.

The returned lines keep their full-document text paths, but only the requested blocks are materialized. Callers supply each block's document Y-position from a block-height index.

methodcursorToPoint(pos: DocCursorPos, snapshot: LayoutSnapshot): { height: number; x: number; y: number }

Convert a DocCursorPos to pixel coordinates relative to the editor box top-left corner.

Returns the position of the cursor bar's horizontal anchor (i.e. the x at which to draw the vertical cursor line, and the y passed to drawCursor), plus the line height needed to size the cursor bar.

methodfindLineIndex(pos: DocCursorPos, snapshot: LayoutSnapshot): number

Returns the index into snapshot.lines for the line containing pos. Returns 0 if not found.

methodgetSelectionRects(sel: DocSelection, snapshot: LayoutSnapshot, originX: number, originY: number): { height: number; width: number; x: number; y: number }[]

Compute canvas-space rectangles for a non-collapsed DocSelection.

ReturnsArray of {x,y,width,height} rectangles in canvas coordinates.

sel

The current DocSelection (anchor + head).

snapshot

Layout snapshot from buildSnapshot.

originX

Absolute canvas X of the editor box top-left.

originY

Absolute canvas Y of the editor box top-left.

methodpointToCursor(px: number, py: number, snapshot: LayoutSnapshot): DocCursorPos

Convert a pixel position (relative to the editor box top-left) to the nearest DocCursorPos.

Used for click-to-position-cursor and drag-selection.

classDocPageMap

Maps document blocks to pages for viewport range queries and virtualization.

constructorDocPageMap(pageHeight: number, pageGap: number, pages: readonly DocPageLayout[]): DocPageMap

Creates a page map from immutable page records.

pageHeight

Page height used by this map.

pageGap

Gap between pages in document coordinates.

pages

Ordered page layout records.

propertyreadonly pageGap: number

Gap between pages in document coordinates.

propertyreadonly pageHeight: number

Page height used by this map.

propertyreadonly pages: readonly DocPageLayout[]

Ordered page layout records.

methodgetPage(index: number): DocPageLayout | null

Returns a page record by index.

methodgetPageIndexesForBlock(blockId: DocNodeId): readonly number[]

Returns page indexes that intersect a block id.

methodgetPagesByIndexes(indexes: readonly number[]): readonly DocPageLayout[]

Returns pages for the supplied page indexes, preserving page order.

methodgetPagesForBlock(block: DocBlockLayout): readonly DocPageLayout[]

Returns all pages intersecting a block layout record.

methodgetPagesInVerticalRange(top: number, bottom: number): readonly DocPageLayout[]

Returns all pages intersecting the supplied vertical document range.

methodfromLayoutCache(cache: DocLayoutCache, pageHeight: number, pageGap?: number): DocPageMapstatic

Builds a page map by intersecting cached block rectangles with fixed-height pages.

classDocViewportWindow

Visible document window used to filter block and page layout ranges.

constructorDocViewportWindow(x: number, y: number, width: number, height: number): DocViewportWindow

Creates a viewport window from document-space rectangle coordinates.

x

Left edge in document coordinates.

y

Top edge in document coordinates.

width

Visible width in document units.

height

Visible height in document units.

propertyreadonly height: number

Visible height in document units.

propertyreadonly width: number

Visible width in document units.

propertyreadonly x: number

Left edge in document coordinates.

propertyreadonly y: number

Top edge in document coordinates.

memberbottom
bottom: unknown
methodintersects(rect: DocLayoutRect): boolean

Returns whether this viewport intersects another document-space rectangle.

methodfromViewport(viewport: { contentRect: DocLayoutRect }, scroll?: { x: number; y: number }): DocViewportWindowstatic

Creates a document-space window from a viewport rectangle and scroll offsets.

classSearEditor

Injectable rich-document editor service placeholder.

The service owns document-editor initialization once a document assembly root is available. It is bound by symbol so consumers do not depend on string DI tokens.

constructorSearEditor(): SearEditor

Constructs the editor service.

propertyreadonly symbol: symbolstatic

DI token for resolving the editor service.

methodinitialize(): void

Initializes document-editor runtime state.

interfaceBlockLayoutSnapshot

Materialized layout for a subset of top-level document blocks.

propertyreadonly blocks: readonly DocBlockLayout[]

Block records for the materialized blocks, using full-document indexes.

propertyreadonly snapshot: LayoutSnapshot

Line snapshot containing only the materialized block ranges.

interfaceDocBlockLayout

Cached layout metadata for one top-level document block.

propertyreadonly flowHeight: number

Flow height from this block top to the next block top, or visual height for the last block.

propertyreadonly id: DocNodeId

Stable block identity used by retained render nodes.

propertyreadonly index: number

Zero-based top-level document block index.

propertyreadonly lineEnd: number

Exclusive index after the last layout line belonging to this block.

propertyreadonly lineStart: number

Inclusive index of the first layout line belonging to this block.

propertyreadonly rect: DocLayoutRect

Document-space rectangle occupied by this block.

interfaceDocBlockLayoutDiffOptions
propertyreadonly reflowBlockIds?: ReadonlySet<DocNodeId>

Reflow blocks whose render output changed even if their measured layout shape did not.

propertyreadonly repaintBlockIds?: ReadonlySet<DocNodeId>

Repaint blocks whose render output changed without invalidating layout cache.

interfaceDocLayoutRect

Rectangle contract used by document layout planning without binding to a render target.

propertyreadonly height: number

Height in document units.

propertyreadonly width: number

Width in document units.

propertyreadonly x: number

Left edge in document coordinates.

propertyreadonly y: number

Top edge in document coordinates.

interfaceDocPageLayout

Layout metadata for one document page.

propertyreadonly blockIds: readonly DocNodeId[]

Block ids that intersect this page.

propertyreadonly index: number

Zero-based page index.

propertyreadonly rect: DocLayoutRect

Page rectangle in document coordinates.

interfaceDocViewportRange

Inclusive visible block/page range within the current document viewport.

propertyreadonly endBlock: number

Last top-level document block index included in the buffered viewport.

propertyreadonly endPage: number

Last page index included in the buffered viewport.

propertyreadonly startBlock: number

First top-level document block index included in the buffered viewport.

propertyreadonly startPage: number

First page index included in the buffered viewport.

interfaceDocViewportScrollSource

Minimal scroll/viewport contract needed to compute a document viewport range.

methodgetShape(): readonly [number, number]

Returns the viewport width/height.

methodgetState(): { x: number; y: number }

Returns the current scroll offset in document coordinates.

interfaceLayoutLine

A single wrapped line inside the editor, with full path metadata for bidirectional cursor ↔ pixel coordinate mapping.

propertychars: RichTextChar[]

Per-character measurements for this line.

propertycharStartOffset: number

Char offset (within the text node) of the FIRST character on this line. e.g. if a text node wraps at char 20, the second line has charStartOffset=20.

propertycursorXOffsets?: number[]

Cursor boundary x offsets relative to this line's x, one entry per char boundary.

propertyfontAscent: number

Font ascent: distance from baseline to top of tallest glyph on this line.

propertyheight: number

Line height in CSS/canvas pixels.

propertytextNodePath: number[]

Full path to the text node this line belongs to.

For a flat document (paragraph → single text node): textNodePath = [paraIndex, 0]

The path mirrors DocCursorPos.path semantics: a cursor at { path: textNodePath, offset } lives on this line when charStartOffset &lt;= offset &lt;= charStartOffset + chars.length.

propertyx: number

Left edge of text, relative to editor box top-left (includes cellPadding).

propertyy: number

Y coordinate used for fillText/cursor drawing, relative to editor box top-left. This is the baseline consumed by document render nodes so cursor pixel coordinates align with rendered text.

typeDocBlockLayoutDiffStatus
type DocBlockLayoutDiffStatus = "unchanged" | "shifted" | "changed" | "added" | "removed"
typeDocVerticalAlign
type DocVerticalAlign = "top" | "center"

Vertical positioning strategy for a laid-out document frame.

functioncomputeViewportRange
computeViewportRange(scrollSource: DocViewportScrollSource, layoutCache: DocLayoutCache, pageMap: DocPageMap, offset?: { x: number; y: number }): DocViewportRange

Computes the visible document block/page range from scroll state and cached layout.

This mirrors Sheet's viewport-range helper at the responsibility level: convert viewport bounds to inclusive start/end indexes and include a one-item buffer on each side. Consumers decide how to query blocks/pages or render.

Snapshots and rendering

Layout snapshots and block diffs identify the areas that changed so rendering can reuse unaffected work.

classArrayIndexedSnapshot
class ArrayIndexedSnapshot<TSnapshot, TItem, TKey> extends IndexedSnapshot<TSnapshot, TItem, TKey>

Array and Map backed implementation of IndexedSnapshot.

constructorArrayIndexedSnapshot<TSnapshot, TItem, TKey>(snapshot: TSnapshot, items: readonly TItem[], getKey: (item: TItem): TKey, getIndex: (item: TItem): number): ArrayIndexedSnapshot<TSnapshot, TItem, TKey>

Creates an indexed snapshot from ordered items and selector functions.

methodgetByIndex(index: number): TItem | null

Returns one item by its numeric index.

methodgetByKey(key: TKey): TItem | null

Returns one item by its stable key.

methodgetKeysByIndexes(indexes: readonly number[]): readonly TKey[]

Returns keys for the supplied numeric indexes, preserving input order.

Inherited members 2

Inherited from IndexedSnapshot.

classIndexedSnapshot
class IndexedSnapshot<TSnapshot, TItem, TKey>

Generic immutable snapshot plus ordered, multi-key indexed item access.

propertyreadonly items: readonly TItem[]

Items in their canonical order.

propertyreadonly snapshot: TSnapshot
methodgetByIndex(index: number): TItem | null

Returns one item by its numeric index.

methodgetByKey(key: TKey): TItem | null

Returns one item by its stable key.

methodgetKeysByIndexes(indexes: readonly number[]): readonly TKey[]

Returns keys for the supplied numeric indexes, preserving input order.

interfaceLayoutSnapshot

Pre-computed layout for the entire editing session.

typeDocBlockRenderFrameMode
type DocBlockRenderFrameMode = "rebuild" | "full" | "scroll" | "block-copy" | "skipped"
functionlockLayoutSnapshot
lockLayoutSnapshot(snapshot: LayoutSnapshot): LayoutSnapshot

Locks a completed layout so readers cannot change cursor or render geometry.