docxml
Version:
TypeScript (component) library for building and parsing a DOCX file
68 lines (67 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextDeletion = 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 deleted.
*/
class TextDeletion 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}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 },
$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:del';
}
/**
* 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 TextDeletion(props, ...(0, components_js_1.createChildComponentsFromNodes)(this.children, (0, xquery_js_1.evaluateXPathToNodes)(`./${namespaces_js_1.QNS.w}r`, node), context));
}
}
exports.TextDeletion = TextDeletion;
Object.defineProperty(TextDeletion, "children", {
enumerable: true,
configurable: true,
writable: true,
value: [
'Text',
'TextAddition',
// Sometimes deletions nested into themselves work well? At other times, they don't.
// For safety, keep it disabled now (or put it behind a flag possibly)
// 'TextDeletion',
]
});
Object.defineProperty(TextDeletion, "mixed", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
(0, components_js_1.registerComponent)(TextDeletion);