UNPKG

docxml

Version:

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

64 lines (63 loc) 2.31 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextAddition = void 0; // Import without assignment ensures Deno does not tree-shake this component. To avoid circular // definitions, components register themselves in a side-effect of their module. require("./Text.js"); 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"); /** * A component that represents a change-tracked text that was inserted. */ class TextAddition extends Component_js_1.Component { /** * Creates an XML DOM node for this component instance. */ async toNode(ancestry) { return (0, dom_js_1.create)(` element ${namespaces_js_1.QNS.w}ins { attribute ${namespaces_js_1.QNS.w}id { $id }, attribute ${namespaces_js_1.QNS.w}author { $author }, attribute ${namespaces_js_1.QNS.w}date { $date }, $children } `, { ...this.props, date: this.props.date.toISOString(), children: await this.childrenToNode(ancestry), }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return node.nodeName === 'w:ins'; } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node, context) { const props = (0, changes_js_1.getChangeInformation)(node); return new TextAddition(props, ...(0, components_js_1.createChildComponentsFromNodes)(this.children, (0, xquery_js_1.evaluateXPathToNodes)(`./${namespaces_js_1.QNS.w}r`, node), context)); } } exports.TextAddition = TextAddition; _a = TextAddition; Object.defineProperty(TextAddition, "children", { enumerable: true, configurable: true, writable: true, value: ['Text', _a.name, 'TextDeletion'] }); Object.defineProperty(TextAddition, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); (0, components_js_1.registerComponent)(TextAddition);