Naar de inhoud
Docxcelerate

Nodes

Table of contents

Een schemasoort zonder helper — hoe je er een plaatst en wat hij vandaag doet.

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. Nog geen helper

Helpers
Geen — met de hand geschreven
Nodesoort
tableOfContents
Categorie
Structuur
Wordt opgelost
By the renderer
Children
None. The entries would come from the sections beside it.
Optie Type Wat het doet
id verplicht 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().

Er een schrijven zonder helper

De helpers zijn gemakken, geen poort. Een nodecomponent is een functie die jouw data aanneemt en een definitie teruggeeft, dus elke soort in het schema is bereikbaar door die functie te schrijven:

import type { NodeComponent } from "docxcelerate";

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

Hij composeert als elke andere node, en lost in previewbuilds, enginebuilds en tests op dezelfde manier op.

Waarom je er nu al een plaatst

Het kost één regel, en hij begint regels te printen op de dag dat de renderers ze bouwen. Het alternatief — een met de hand bijgehouden lijst met sectietitels in een alinea — is binnen twee releases onjuist.

Als je liever geen node uitlevert die alleen een kop print, laat hem dan weg. Hem later toevoegen is even goedkoop.

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 ↗
Waartoe het wordt opgelost

De node zoals hij in het DocumentModel verschijnt: de JSON die een renderer aangereikt krijgt. Geen opmaak, geen lay-out.

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

Aantekeningen

  • Verwacht uiteindelijk een tableOfContents-helper, die dezelfde { id, title } aanneemt als hier. Geschreven zoals hierboven is overstappen een wijziging van één regel.
  • De node bevat geen kinderen en leest tijdens de build niets.

Deze pagina bewerken op GitHub ↗