UNPKG

docxml

Version:

TypeScript (component) library for building and parsing a DOCX file

60 lines (59 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FieldRangeInstruction = void 0; const Component_js_1 = require("../classes/Component.js"); const components_js_1 = require("../utilities/components.js"); const dom_js_1 = require("../utilities/dom.js"); const namespaces_js_1 = require("../utilities/namespaces.js"); const xquery_js_1 = require("../utilities/xquery.js"); /** * An instruction in a complex field. */ class FieldRangeInstruction extends Component_js_1.Component { /** * Creates an XML DOM node for this component instance. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars async toNode(ancestry) { return (0, dom_js_1.create)(` element ${namespaces_js_1.QNS.w}instrText { $children } `, { children: await this.childrenToNode(ancestry), }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return (0, xquery_js_1.evaluateXPathToBoolean)('self::w:instrText', node); } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node, context) { const { children } = (0, xquery_js_1.evaluateXPathToMap)(` map { "children": array{ ./text() } } `, node); return new FieldRangeInstruction({}, ...(0, components_js_1.createChildComponentsFromNodes)(this.children, children, context)); } } exports.FieldRangeInstruction = FieldRangeInstruction; Object.defineProperty(FieldRangeInstruction, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(FieldRangeInstruction, "mixed", { enumerable: true, configurable: true, writable: true, value: true }); (0, components_js_1.registerComponent)(FieldRangeInstruction);