UNPKG

docxml

Version:

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

78 lines (77 loc) 2.99 kB
"use strict"; /** * @file * Note this file is 99% the same as RowDeletion. Please maintain both accordingly. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RowDeletion = void 0; const Component_js_1 = require("../classes/Component.js"); const changes_js_1 = require("../utilities/changes.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"); const Row_js_1 = require("./Row.js"); /** * A component that represents a change-tracked table row that was deleted. Works the same way as * a normal row, but requires some props describing the change. */ class RowDeletion extends Component_js_1.Component { /** * Creates an XML DOM node for this component instance. */ async toNode(ancestry) { const node = await (0, Row_js_1.createNodeFromRow)(this, ancestry); let trPr = (0, xquery_js_1.evaluateXPathToFirstNode)(`./${namespaces_js_1.QNS.w}trPr`, node); if (!trPr) { trPr = (0, dom_js_1.create)(`element ${namespaces_js_1.QNS.w}trPr {}`); node.insertBefore(trPr, node.firstChild); } trPr.insertBefore((0, dom_js_1.create)(` element ${namespaces_js_1.QNS.w}del { attribute ${namespaces_js_1.QNS.w}id { $id }, attribute ${namespaces_js_1.QNS.w}author { $author }, attribute ${namespaces_js_1.QNS.w}date { $date } } `, { ...this.props, date: this.props.date.toISOString(), }), null); return node; } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return (0, xquery_js_1.evaluateXPathToBoolean)(` self::${namespaces_js_1.QNS.w}tr and ./${namespaces_js_1.QNS.w}trPr/${namespaces_js_1.QNS.w}del and not(./${namespaces_js_1.QNS.w}trPr/${namespaces_js_1.QNS.w}ins) `, node); } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node, context) { const { children, ...rowProps } = (0, Row_js_1.parsePropsAndChildNodes)(node); const changeProps = (0, changes_js_1.getChangeInformation)((0, xquery_js_1.evaluateXPathToFirstNode)(`./${namespaces_js_1.QNS.w}trPr`, node)); return new RowDeletion({ ...rowProps, ...changeProps, }, ...(0, components_js_1.createChildComponentsFromNodes)(this.children, children, context)); } } exports.RowDeletion = RowDeletion; Object.defineProperty(RowDeletion, "children", { enumerable: true, configurable: true, writable: true, value: Row_js_1.Row.children }); Object.defineProperty(RowDeletion, "mixed", { enumerable: true, configurable: true, writable: true, value: Row_js_1.Row.mixed }); (0, components_js_1.registerComponent)(RowDeletion);