Skip to content

cupertino-files / TableOfContents

Class: TableOfContents

Defined in: src/tswp/toc.ts:94

Constructors

Constructor

new TableOfContents(store, object): TableOfContents

Defined in: src/tswp/toc.ts:98

Parameters

store

ObjectStore

object

IwaObject

Returns

TableOfContents

Properties

object

readonly object: IwaObject

Defined in: src/tswp/toc.ts:96


store

readonly store: ObjectStore

Defined in: src/tswp/toc.ts:95

Accessors

entriesAreStale

Get Signature

get entriesAreStale(): boolean

Defined in: src/tswp/toc.ts:212

True when this session has edited the TOC or its settings.

Only detects changes made through this library since the document was loaded — a TOC that was already stale when Apple saved it looks clean. Use verifyAgainst to compare the cache against actual text.

Returns

boolean


id

Get Signature

get id(): bigint

Defined in: src/tswp/toc.ts:103

Returns

bigint


name

Get Signature

get name(): string | undefined

Defined in: src/tswp/toc.ts:108

The TOC's own name, as shown in the navigator.

Returns

string | undefined

Set Signature

set name(value): void

Defined in: src/tswp/toc.ts:112

Parameters
value

string

Returns

void


scope

Get Signature

get scope(): number | undefined

Defined in: src/tswp/toc.ts:119

Whether the TOC collects from the whole document or just its section.

Returns

number | undefined

Set Signature

set scope(value): void

Defined in: src/tswp/toc.ts:123

Parameters
value

number

Returns

void

Methods

addRule()

addRule(paragraphStyleId, entryStyleId?): void

Defined in: src/tswp/toc.ts:163

Add a collection rule for a paragraph style that has none.

Parameters

paragraphStyleId

bigint

entryStyleId?

bigint

Returns

void


entries()

entries(): TocEntry[]

Defined in: src/tswp/toc.ts:189

The lines the app produced last time it regenerated this TOC.

A cache, not a source of truth: page numbers come from layout. They are accurate for a document nobody has edited since the app last saved it, and stale for one this library has changed.

Returns

TocEntry[]


rules()

rules(): TocRule[]

Defined in: src/tswp/toc.ts:134

Which paragraph styles the TOC collects, and how each is rendered.

Returns

TocRule[]


setIncluded()

setIncluded(paragraphStyleId, included): boolean

Defined in: src/tswp/toc.ts:151

Turn collection of a paragraph style on or off.

Changing which styles are collected is a settings edit, so it survives as an instruction the app acts on at its next repagination — unlike the cached entries, which this library will not invent.

Parameters

paragraphStyleId

bigint

included

boolean

Returns

boolean


shapeStorageId()

shapeStorageId(): bigint | undefined

Defined in: src/tswp/toc.ts:241

The shape that holds the rendered TOC text, when it has one.

Returns

bigint | undefined


verifyAgainst()

verifyAgainst(paragraphs): object[]

Defined in: src/tswp/toc.ts:227

Compare cached headings against the paragraphs they came from.

The only staleness check that survives a reload. Entry instances record a paragraph index but not which storage it indexes, so the caller supplies the one to check — normally the document body. A mismatch means the app has not regenerated the TOC since the text changed.

Page numbers are not checked: they come from layout, and nothing here performs layout, so a page number can only ever be taken on trust.

Parameters

paragraphs

readonly object[]

Returns

object[]

MIT licensed. Independently made — not by Apple in California. Not affiliated with or endorsed by Apple Inc.