UNPKG

docxml

Version:

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

57 lines (56 loc) 1.78 kB
import { Component } from '../classes/Component.js'; import { registerComponent } from '../utilities/components.js'; import { create } from '../utilities/dom.js'; import { QNS } from '../utilities/namespaces.js'; import { evaluateXPathToBoolean, evaluateXPathToMap } from '../utilities/xquery.js'; /** * The start of a range associated with a complex field. */ export class FieldRangeStart extends Component { /** * Creates an XML DOM node for this component instance. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars toNode(_ancestry) { return create(` element ${QNS.w}fldChar { attribute ${QNS.w}fldCharType { "begin" }, if ($isDirty) then attribute ${QNS.w}dirty { "1" } else (), if ($isLocked) then attribute ${QNS.w}fldLock { "1" } else () } `, { isDirty: !!this.props.isDirty, isLocked: !!this.props.isLocked, }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return evaluateXPathToBoolean('self::w:fldChar and @w:fldCharType = "begin"', node); } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node) { return new FieldRangeStart(evaluateXPathToMap(` map { "isDirty": docxml:st-on-off(@${QNS.w}dirty), "isLocked": docxml:st-on-off(@${QNS.w}fldLock) } `, node)); } } Object.defineProperty(FieldRangeStart, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(FieldRangeStart, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); registerComponent(FieldRangeStart);