Ir al contenido
Docxcelerate

Nodos

Table of contents

Una clase del esquema que aún no tiene helper — cómo colocar una y qué hace hoy.

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. Aún sin helper

Helpers
Ninguno — se escribe a mano
Clase de nodo
tableOfContents
Categoría
Estructura
Se resuelve
By the renderer
Hijos
None. The entries would come from the sections beside it.
Opción Tipo Qué hace
id obligatorio 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().

Escribir una sin helper

Los helpers son comodidades, no una barrera. Un componente de nodo es una función que toma tus datos y devuelve una definición, así que cualquier clase del esquema está a tu alcance sin más que escribir esa función:

import type { NodeComponent } from "docxcelerate";

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

Se compone como cualquier otro nodo, y se resuelve igual en compilaciones de vista previa, en compilaciones del motor y en pruebas.

Por qué colocar una ya

Cuesta una línea, y empieza a imprimir entradas el día en que los renderizadores las construyan. La alternativa — una lista de títulos de sección mantenida a mano dentro de un párrafo — estará equivocada en dos versiones.

Si prefieres no publicar un nodo que solo imprime un encabezado, déjalo fuera. Añadirlo más adelante es igual de barato.

Variantes

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 ↗
En qué se resuelve

El nodo tal como aparece en el DocumentModel: el JSON que recibe un renderizador. Sin estilos, sin maquetación.

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

Notas

  • Cuenta con que acabe habiendo un helper tableOfContents, que tomará el mismo { id, title } que toma aquí. Escrito como arriba, adoptarlo es un cambio de una línea.
  • El nodo no contiene hijos y no lee nada en tiempo de compilación.

Editar esta página en GitHub ↗