Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/docxml/src/classes/Component.ts>Component

TypeScript (component) library for building and parsing a DOCX file
Latest
class Component
Abstract
import { Component } from "https://deno.land/x/docxml@5.15.3/src/classes/Component.ts";

Constructors

new
Component(props: PropsGeneric, ...children: ChildGeneric[])

Type Parameters

optional
PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }
optional
ChildGeneric extends AnyComponent | string = never

Properties

readonly
children: ChildGeneric[]

The children given to this component instance.

readonly
props: PropsGeneric

The props given to this component instance.

Methods

protected
childrenToNode(ancestry: Array<ComponentAncestor>): Promise<ComponentNode[]>

An event hook with which this component can ensure that the correct relationship type is recorded to the relationship XML.

For example;

  • Create a relationship to a Hyperlink external target
  • Create a relationship from the Image component to its image file binary.

You'll want to use RelationshipsXml to create a relationship and store its identifier somewhere, before using it in Component.toNode.

this.#relationshipId = relationships.add(RelationshipType.hyperlink, this.props.url);

Create a DOM node for this XML component, one that can be stringified to schema-valid OOXML.

By default, an XML component would serialize to its children and string contents -- like a fragment. Most components have an override to use specific OOXML elememnts, such as <w:p>.

Static Properties

readonly
children: string[]

Informs the JSX pragma which child components are allowed in this component. The JSX pragma can use this to attempt repairs at invalidly nested children.

readonly
mixed: boolean

Informs the JSX pragma on wether or not this component can contain text (string) children. The JSX pragma can use this to attempt repairs at invalidly nested children.

[IS_COMPONENT]: true

Static Methods

fromNode(_node: Node, _context: ComponentContext): null | AnyComponent
matchesNode(_node: Node): boolean