Zum Inhalt springen
Docxcelerate

Nodes

Table of contents

Eine Schema-Art ohne Helper — wie Sie eine platzieren und was sie heute tut.

The kind is part of the letter schema and both renderers accept it, but no authoring helper is exported yet. Writing the component by hand works — a node component is a function returning a definition, and the helpers are conveniences over exactly that shape. Noch kein Helper

Helper
Keine — von Hand geschrieben
Node-Art
tableOfContents
Kategorie
Struktur
Wird aufgelöst
By the renderer
Kinder
None. The entries would come from the sections beside it.
Option Typ Was sie bewirkt
id erforderlich string Stable address for the node. Generation endpoints target it and build artifacts diff on it, so treat a rename as a breaking change.
title string Heading for the list. Renderers fall back to their own wording.
derivers DeriverInvocation[] Values computed before the node resolves, written to derived.* and readable from a template token. Built with derive().

Eine ohne Helper schreiben

Die Helper sind Bequemlichkeiten, kein Tor. Eine Node-Komponente ist eine Funktion, die Ihre Daten nimmt und eine Definition zurückgibt — jede Art im Schema ist also erreichbar, indem Sie diese Funktion schreiben:

import type { NodeComponent } from "docxcelerate";

export const Contents: NodeComponent<MemberData> = () => ({
  kind: "tableOfContents",
  id: "contents",
  title: "What is in this document",
});

Sie lässt sich wie jeder andere Node komponieren und löst sich in Vorschau-Builds, Engine-Builds und Tests gleich auf.

Warum jetzt schon eine platzieren

Es kostet eine Zeile, und sie beginnt an dem Tag Einträge zu drucken, an dem die Renderer sie bauen. Die Alternative — eine von Hand gepflegte Liste von Abschnittstiteln in einem Absatz — ist binnen zweier Releases falsch.

Wenn Sie lieber keinen Node ausliefern wollen, der nur eine Überschrift druckt, lassen Sie ihn weg. Ihn später zu ergänzen ist genauso billig.

Varianten

Written by hand

src/nodes/table-of-contents/basic.node.ts

The definition shape the helpers would produce.

import type { NodeComponent } from "docxcelerate";
import type { SampleData } from "../sample-data.ts";

/**
 * No helper ships for this kind yet. A node component is only a function
 * returning a definition, so writing it out reaches the same place.
 *
 * The shipped renderers print the title and stop.
 */
export const Contents: NodeComponent<SampleData> = () => ({
  kind: "tableOfContents",
  id: "contents",
  title: "What is in this letter",
});
table of contents · written by hand Open ↗
Wozu es aufgelöst wird

Der Node, wie er im DocumentModel erscheint: das JSON, das ein Renderer bekommt. Kein Styling, kein Layout.

{
  "id": "contents",
  "kind": "tableOfContents",
  "title": "What is in this letter"
}

Anmerkungen

  • Rechnen Sie irgendwann mit einem tableOfContents-Helper, der dasselbe { id, title } nimmt wie hier. So geschrieben wie oben, ist die Umstellung eine Änderung von einer Zeile.
  • Der Node hat keine Kinder und liest zur Build-Zeit nichts.

Diese Seite auf GitHub bearbeiten ↗