@docx4j/core-ts 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,10 @@ import * as w15Factory from '@docx4j/generated-objects-ts/factory/org_docx4j_w15
3
3
  import * as w16cidFactory from '@docx4j/generated-objects-ts/factory/org_docx4j_w16cid';
4
4
  import { linkParents } from '@docx4j/generated-objects-ts/builders/wml';
5
5
  import { Docx4JException } from '../../opc/exceptions.mjs';
6
+ import { parseXml } from '../../xml/dom.mjs';
6
7
  import { MainDocumentPart, CommentsPart, CommentsExtendedPart, CommentsIdsPart, PeoplePart } from './index.mjs';
7
8
  import { COMMENT_REFERENCE_STYLE, COMMENT_TEXT_STYLE, setCommentPartsAccess, dateToCalendar, } from '../../model/content/comments.mjs';
9
+ import { dateOf } from '../../model/content/tracking.mjs';
8
10
  // Loaded for its side effect: the Comment views register themselves with the content API.
9
11
  import '../../model/content/Comment.mjs';
10
12
  /** The comment parts of one document. */
@@ -14,6 +16,7 @@ class DocumentCommentParts {
14
16
  this.commentsPart = commentsPart;
15
17
  this.comments = comments;
16
18
  this.author = author;
19
+ this.datesUtc = new Map();
17
20
  this.loadedAll = false;
18
21
  }
19
22
  ensureCommentsEx() {
@@ -66,8 +69,52 @@ async function partsFor(main, commentsPart, author) {
66
69
  parts.commentsEx = await main.commentsExtendedPart.getContents();
67
70
  if (main.peoplePart)
68
71
  parts.people = await main.peoplePart.getContents();
72
+ await readDatesUtc(main, parts.datesUtc);
69
73
  return parts;
70
74
  }
75
+ const W16CID_NS = 'http://schemas.microsoft.com/office/word/2016/wordml/cid';
76
+ const W16CEX_NS = 'http://schemas.microsoft.com/office/word/2018/wordml/cex';
77
+ /**
78
+ * Each comment's `w16cex:dateUtc`, by the paragraph id `w16cid:commentId` pairs its durable id with.
79
+ * From the parts' contents when they are unmarshalled, else from their XML, which leaves them
80
+ * untouched: no view needs them otherwise, and an unmarshalled part is re-marshalled on save.
81
+ */
82
+ async function readDatesUtc(main, into) {
83
+ var _a, _b, _c;
84
+ const idsPart = main.commentsIdsPart;
85
+ const extensiblePart = main.commentsExtensiblePart;
86
+ if (!idsPart || !extensiblePart)
87
+ return;
88
+ const paraIdOf = new Map();
89
+ if (idsPart.isUnmarshalled) {
90
+ for (const e of (_a = idsPart.contents.commentId) !== null && _a !== void 0 ? _a : [])
91
+ if (e.durableId && e.paraId)
92
+ paraIdOf.set(e.durableId.toUpperCase(), e.paraId.toUpperCase());
93
+ }
94
+ else {
95
+ for (const e of Array.from(parseXml(await idsPart.getXml()).getElementsByTagNameNS(W16CID_NS, 'commentId'))) {
96
+ const durableId = e.getAttributeNS(W16CID_NS, 'durableId');
97
+ const paraId = e.getAttributeNS(W16CID_NS, 'paraId');
98
+ if (durableId && paraId)
99
+ paraIdOf.set(durableId.toUpperCase(), paraId.toUpperCase());
100
+ }
101
+ }
102
+ const add = (durableId, date) => {
103
+ const paraId = durableId ? paraIdOf.get(durableId.toUpperCase()) : undefined;
104
+ if (paraId && date && !Number.isNaN(date.getTime()))
105
+ into.set(paraId, date);
106
+ };
107
+ if (extensiblePart.isUnmarshalled) {
108
+ for (const e of (_b = extensiblePart.contents.commentExtensible) !== null && _b !== void 0 ? _b : [])
109
+ add(e.durableId, dateOf(e.dateUtc));
110
+ }
111
+ else {
112
+ for (const e of Array.from(parseXml(await extensiblePart.getXml()).getElementsByTagNameNS(W16CEX_NS, 'commentExtensible'))) {
113
+ const value = e.getAttributeNS(W16CEX_NS, 'dateUtc');
114
+ add((_c = e.getAttributeNS(W16CEX_NS, 'durableId')) !== null && _c !== void 0 ? _c : undefined, value ? new Date(value) : undefined);
115
+ }
116
+ }
117
+ }
71
118
  async function ensurePeople(main) {
72
119
  if (main.peoplePart)
73
120
  return main.peoplePart.getContents();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docx4j/core-ts",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "docx4j-core for TypeScript: Open Packaging (docx/pptx/xlsx zip and flat OPC), typed parts and relationships, style, numbering and font resolution over @docx4j/generated-objects-ts. Node, browsers, Word add-ins.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",