@portone/docx-editor 0.6.5 → 0.6.6

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +4 -4
  3. package/dist/core.d.ts +7 -0
  4. package/dist/core.js +2 -0
  5. package/dist/docx/commentOnlyChange.d.ts +4 -4
  6. package/dist/docx/comments/constants.d.ts +7 -0
  7. package/dist/docx/comments/constants.js +13 -1
  8. package/dist/docx/comments/dates.d.ts +22 -0
  9. package/dist/docx/comments/dates.js +102 -0
  10. package/dist/docx/comments/durable.d.ts +22 -0
  11. package/dist/docx/comments/durable.js +138 -0
  12. package/dist/docx/comments/grammar.d.ts +10 -1
  13. package/dist/docx/comments/grammar.js +49 -2
  14. package/dist/docx/comments/model.d.ts +10 -2
  15. package/dist/docx/comments/model.js +38 -8
  16. package/dist/docx/comments/parts.d.ts +53 -7
  17. package/dist/docx/comments/parts.js +163 -20
  18. package/dist/docx/comments/people.d.ts +1 -1
  19. package/dist/docx/comments/people.js +5 -15
  20. package/dist/docx/comments/reading.d.ts +26 -0
  21. package/dist/docx/comments/reading.js +109 -49
  22. package/dist/docx/comments/writing.d.ts +2 -7
  23. package/dist/docx/comments/writing.js +30 -43
  24. package/dist/docx/compareDocx.d.ts +154 -0
  25. package/dist/docx/compareDocx.js +218 -0
  26. package/dist/docx/importParagraph.js +5 -3
  27. package/dist/docx/invariants.js +19 -6
  28. package/dist/docx/packageParts.d.ts +2 -0
  29. package/dist/docx/packageParts.js +5 -1
  30. package/dist/docx/partPlan.d.ts +12 -0
  31. package/dist/docx/partPlan.js +19 -1
  32. package/dist/docx/protectionPolicy.d.ts +33 -5
  33. package/dist/docx/protectionPolicy.js +93 -47
  34. package/dist/docx/sequenceDiff.d.ts +56 -0
  35. package/dist/docx/sequenceDiff.js +252 -0
  36. package/dist/docx/storyProjection.d.ts +2 -0
  37. package/dist/docx/storyProjection.js +10 -9
  38. package/dist/docx/textDiff.d.ts +24 -0
  39. package/dist/docx/textDiff.js +38 -0
  40. package/dist/editor/commands/comments/editing.js +56 -20
  41. package/dist/editor/commands/comments/model.d.ts +3 -1
  42. package/dist/editor/editorDocument.d.ts +4 -0
  43. package/dist/editor/editorDocument.js +10 -0
  44. package/dist/editor/plugins/commentDecorations.js +6 -2
  45. package/dist/ooxml/errors.d.ts +1 -1
  46. package/dist/ooxml/names.d.ts +2 -0
  47. package/dist/ooxml/names.js +2 -0
  48. package/dist/ooxml/partSplice.d.ts +13 -3
  49. package/dist/ooxml/partSplice.js +45 -18
  50. package/dist/schema/attrRoles.js +3 -1
  51. package/dist/schema/docxSchema.js +10 -3
  52. package/dist/schema/protection.js +2 -1
  53. package/dist/ui/CommentsPanel.js +8 -13
  54. package/dist/ui/comments/commentDate.d.ts +7 -0
  55. package/dist/ui/comments/commentDate.js +17 -0
  56. package/package.json +6 -6
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The elements two sequences share, as the shortest edit between them, and the block-by-block
3
+ * alignment `compareDocx` builds on it.
4
+ *
5
+ * The search is Myers' in linear space (the middle-snake bisection), so a long sequence rewritten
6
+ * throughout costs time rather than a table the size of both sequences multiplied. The time is
7
+ * bounded too: past `COMPARISON_BUDGET` the search gives up and reports everything between the
8
+ * shared head and tail as removed and added, which is a correct edit if not the shortest one.
9
+ */
10
+ export type Match = readonly [original: number, revised: number];
11
+ /**
12
+ * How many element comparisons and diagonal probes one search may spend. It is a count rather
13
+ * than a deadline so that the same two inputs always get the same answer. Five million keeps a
14
+ * search under a tenth of a second, and still finds a thousand edits scattered through a text of
15
+ * forty thousand characters.
16
+ */
17
+ export declare const COMPARISON_BUDGET = 5000000;
18
+ type Same = (original: number, revised: number) => boolean;
19
+ interface Budget {
20
+ left: number;
21
+ }
22
+ /**
23
+ * The index pairs of a longest common subsequence of two sequences under `same`, in order.
24
+ *
25
+ * Where the search runs past its budget, only the shared head and tail are matched. Searches that
26
+ * pass one budget between them share it, so a caller running many bounds them all together.
27
+ */
28
+ export declare function commonSubsequence(originalLength: number, revisedLength: number, same: Same, budget?: Budget): Match[];
29
+ /** One element of a sequence to align: what it would be written as, and what it reads as */
30
+ export interface Alignable {
31
+ identity: string;
32
+ text: string;
33
+ }
34
+ export type Alignment = {
35
+ kind: "kept";
36
+ original: number;
37
+ revised: number;
38
+ } | {
39
+ kind: "changed";
40
+ original: number;
41
+ revised: number;
42
+ change: "text" | "formatting";
43
+ } | {
44
+ kind: "removed";
45
+ original: number;
46
+ } | {
47
+ kind: "added";
48
+ revised: number;
49
+ };
50
+ /**
51
+ * Lines two sequences up: elements written the same are kept, then elements reading the same are
52
+ * changed in formatting, and the elements left between two of those are paired as changed in
53
+ * text (`pairLeftovers`). Elements of different kinds are never paired.
54
+ */
55
+ export declare function alignSequences<T extends Alignable>(original: readonly T[], revised: readonly T[], kindOf?: (item: T) => string): Alignment[];
56
+ export {};
@@ -0,0 +1,252 @@
1
+ // src/docx/sequenceDiff.ts
2
+ var COMPARISON_BUDGET = 5e6;
3
+ function bisect(originalFrom, n, revisedFrom, m, same, budget) {
4
+ const maxD = Math.ceil((n + m) / 2);
5
+ const offset = maxD;
6
+ const length = 2 * maxD + 2;
7
+ const forward = new Int32Array(length).fill(-1);
8
+ const backward = new Int32Array(length).fill(-1);
9
+ forward[offset + 1] = 0;
10
+ backward[offset + 1] = 0;
11
+ const delta = n - m;
12
+ const front = delta % 2 !== 0;
13
+ let forwardStart = 0;
14
+ let forwardEnd = 0;
15
+ let backwardStart = 0;
16
+ let backwardEnd = 0;
17
+ for (let d = 0; d < maxD; d += 1) {
18
+ for (let k = -d + forwardStart; k <= d - forwardEnd; k += 2) {
19
+ budget.left -= 1;
20
+ const at = offset + k;
21
+ let x = k === -d || k !== d && forward[at - 1] < forward[at + 1] ? forward[at + 1] : forward[at - 1] + 1;
22
+ let y = x - k;
23
+ const start = x;
24
+ while (x < n && y < m && same(originalFrom + x, revisedFrom + y)) {
25
+ x += 1;
26
+ y += 1;
27
+ }
28
+ budget.left -= x - start;
29
+ forward[at] = x;
30
+ if (x > n) forwardEnd += 2;
31
+ else if (y > m) forwardStart += 2;
32
+ else if (front) {
33
+ const other = offset + delta - k;
34
+ if (other >= 0 && other < length && backward[other] !== -1) {
35
+ if (x >= n - backward[other]) return [x, y];
36
+ }
37
+ }
38
+ }
39
+ for (let k = -d + backwardStart; k <= d - backwardEnd; k += 2) {
40
+ budget.left -= 1;
41
+ const at = offset + k;
42
+ let x = k === -d || k !== d && backward[at - 1] < backward[at + 1] ? backward[at + 1] : backward[at - 1] + 1;
43
+ let y = x - k;
44
+ const start = x;
45
+ while (x < n && y < m && same(originalFrom + n - x - 1, revisedFrom + m - y - 1)) {
46
+ x += 1;
47
+ y += 1;
48
+ }
49
+ budget.left -= x - start;
50
+ backward[at] = x;
51
+ if (x > n) backwardEnd += 2;
52
+ else if (y > m) backwardStart += 2;
53
+ else if (!front) {
54
+ const other = offset + delta - k;
55
+ if (other >= 0 && other < length && forward[other] !== -1) {
56
+ const meet = forward[other];
57
+ if (meet >= n - x) return [meet, offset + meet - other];
58
+ }
59
+ }
60
+ }
61
+ if (budget.left <= 0) return "exhausted";
62
+ }
63
+ return null;
64
+ }
65
+ function matchesIn(originalFrom, originalTo, revisedFrom, revisedTo, same, budget, found) {
66
+ while (originalFrom < originalTo && revisedFrom < revisedTo && same(originalFrom, revisedFrom)) {
67
+ found.push([originalFrom, revisedFrom]);
68
+ originalFrom += 1;
69
+ revisedFrom += 1;
70
+ }
71
+ const tail = [];
72
+ while (originalFrom < originalTo && revisedFrom < revisedTo && same(originalTo - 1, revisedTo - 1)) {
73
+ originalTo -= 1;
74
+ revisedTo -= 1;
75
+ tail.push([originalTo, revisedTo]);
76
+ }
77
+ if (originalFrom < originalTo && revisedFrom < revisedTo) {
78
+ const split = bisect(
79
+ originalFrom,
80
+ originalTo - originalFrom,
81
+ revisedFrom,
82
+ revisedTo - revisedFrom,
83
+ same,
84
+ budget
85
+ );
86
+ if (split === "exhausted") return false;
87
+ if (split !== null) {
88
+ const [x, y] = split;
89
+ const kept = matchesIn(
90
+ originalFrom,
91
+ originalFrom + x,
92
+ revisedFrom,
93
+ revisedFrom + y,
94
+ same,
95
+ budget,
96
+ found
97
+ ) && matchesIn(
98
+ originalFrom + x,
99
+ originalTo,
100
+ revisedFrom + y,
101
+ revisedTo,
102
+ same,
103
+ budget,
104
+ found
105
+ );
106
+ if (!kept) return false;
107
+ }
108
+ }
109
+ found.push(...tail.reverse());
110
+ return true;
111
+ }
112
+ function commonSubsequence(originalLength, revisedLength, same, budget = { left: COMPARISON_BUDGET }) {
113
+ let head = 0;
114
+ while (head < originalLength && head < revisedLength && same(head, head)) {
115
+ head += 1;
116
+ }
117
+ let tail = 0;
118
+ while (tail < originalLength - head && tail < revisedLength - head && same(originalLength - 1 - tail, revisedLength - 1 - tail)) {
119
+ tail += 1;
120
+ }
121
+ const matched = (from, to, shift) => Array.from({ length: to - from }, (_, at) => [
122
+ from + at,
123
+ from + at + shift
124
+ ]);
125
+ const middle = [];
126
+ const found = matchesIn(
127
+ head,
128
+ originalLength - tail,
129
+ head,
130
+ revisedLength - tail,
131
+ same,
132
+ budget,
133
+ middle
134
+ );
135
+ return [
136
+ ...matched(0, head, 0),
137
+ ...found ? middle : [],
138
+ ...matched(
139
+ originalLength - tail,
140
+ originalLength,
141
+ revisedLength - originalLength
142
+ )
143
+ ];
144
+ }
145
+ function keyed(original, revised) {
146
+ const ids = /* @__PURE__ */ new Map();
147
+ const idOf = (key) => {
148
+ const known = ids.get(key);
149
+ if (known !== void 0) return known;
150
+ ids.set(key, ids.size);
151
+ return ids.size - 1;
152
+ };
153
+ return [Int32Array.from(original, idOf), Int32Array.from(revised, idOf)];
154
+ }
155
+ function matchBetween(anchors, original, revised, key) {
156
+ const [was, now] = keyed(original.map(key), revised.map(key));
157
+ const budget = { left: COMPARISON_BUDGET };
158
+ const found = [];
159
+ let from = 0;
160
+ let to = 0;
161
+ for (const anchor of [
162
+ ...anchors,
163
+ [original.length, revised.length]
164
+ ]) {
165
+ const matches = commonSubsequence(
166
+ anchor[0] - from,
167
+ anchor[1] - to,
168
+ (i, j) => was[from + i] === now[to + j],
169
+ budget
170
+ );
171
+ for (const [i, j] of matches) found.push([from + i, to + j]);
172
+ if (anchor[0] < original.length) found.push(anchor);
173
+ from = anchor[0] + 1;
174
+ to = anchor[1] + 1;
175
+ }
176
+ return found;
177
+ }
178
+ function pairLeftovers(original, revised, kindOf, [originalFrom, originalTo], [revisedFrom, revisedTo]) {
179
+ const steps = [];
180
+ let cursor = originalFrom;
181
+ let added = revisedFrom;
182
+ for (let at = revisedFrom; at < revisedTo; at += 1) {
183
+ const kind = kindOf(revised[at]);
184
+ let partner = cursor;
185
+ while (partner < originalTo && kindOf(original[partner]) !== kind) {
186
+ partner += 1;
187
+ }
188
+ if (partner === originalTo) continue;
189
+ for (; cursor < partner; cursor += 1) {
190
+ steps.push({ kind: "removed", original: cursor });
191
+ }
192
+ for (; added < at; added += 1)
193
+ steps.push({ kind: "added", revised: added });
194
+ steps.push({
195
+ kind: "changed",
196
+ original: partner,
197
+ revised: at,
198
+ change: "text"
199
+ });
200
+ cursor = partner + 1;
201
+ added = at + 1;
202
+ }
203
+ for (; cursor < originalTo; cursor += 1) {
204
+ steps.push({ kind: "removed", original: cursor });
205
+ }
206
+ for (; added < revisedTo; added += 1)
207
+ steps.push({ kind: "added", revised: added });
208
+ return steps;
209
+ }
210
+ function alignSequences(original, revised, kindOf = () => "") {
211
+ const exact = matchBetween(
212
+ [],
213
+ original,
214
+ revised,
215
+ (item) => `${kindOf(item)}\0${item.identity}`
216
+ );
217
+ const matched = matchBetween(
218
+ exact,
219
+ original,
220
+ revised,
221
+ (item) => `${kindOf(item)}\0${item.text}`
222
+ );
223
+ const alignment = [];
224
+ let from = 0;
225
+ let to = 0;
226
+ for (const [was, now] of [
227
+ ...matched,
228
+ [original.length, revised.length]
229
+ ]) {
230
+ alignment.push(
231
+ ...pairLeftovers(original, revised, kindOf, [from, was], [to, now])
232
+ );
233
+ if (was < original.length) {
234
+ alignment.push(
235
+ original[was].identity === revised[now].identity ? { kind: "kept", original: was, revised: now } : {
236
+ kind: "changed",
237
+ original: was,
238
+ revised: now,
239
+ change: "formatting"
240
+ }
241
+ );
242
+ }
243
+ from = was + 1;
244
+ to = now + 1;
245
+ }
246
+ return alignment;
247
+ }
248
+ export {
249
+ COMPARISON_BUDGET,
250
+ alignSequences,
251
+ commonSubsequence
252
+ };
@@ -34,3 +34,5 @@ export declare function isModelledBlock(node: PMNode): boolean;
34
34
  * over: a caller judging two files answers such a story the way it answers a changed one.
35
35
  */
36
36
  export declare function comparableStory(story: Story, strip: (node: PMNode) => PMNode): readonly string[] | null;
37
+ /** One block as the writer puts it out, and null where it cannot be written back at all */
38
+ export declare function comparableBlock(block: PMNode, session: SessionStore, strip: (node: PMNode) => PMNode): string | null;
@@ -7,22 +7,23 @@ function isModelledBlock(node) {
7
7
  }
8
8
  function comparableStory(story, strip) {
9
9
  const blocks = [];
10
+ for (const block of story.doc.children) {
11
+ const xml = comparableBlock(block, story.session, strip);
12
+ if (xml === null) return null;
13
+ blocks.push(xml);
14
+ }
15
+ return blocks;
16
+ }
17
+ function comparableBlock(block, session, strip) {
10
18
  try {
11
- story.doc.forEach((block) => {
12
- blocks.push(
13
- serializeBlock(strip(block), {
14
- ...NO_EXPORT_REFS,
15
- session: story.session
16
- })
17
- );
18
- });
19
+ return serializeBlock(strip(block), { ...NO_EXPORT_REFS, session });
19
20
  } catch (error) {
20
21
  if (error instanceof DocxExportError) return null;
21
22
  throw error;
22
23
  }
23
- return blocks;
24
24
  }
25
25
  export {
26
+ comparableBlock,
26
27
  comparableStory,
27
28
  isModelledBlock
28
29
  };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The characters two texts share and the ones each has alone, as the shortest edit between them
3
+ * (`./sequenceDiff`).
4
+ *
5
+ * The texts are compared a grapheme cluster at a time, so an edit never splits a character a
6
+ * reader sees as one: a surrogate pair, a flag, an emoji with its skin tone, a letter with its
7
+ * combining accent.
8
+ */
9
+ /** One stretch of the edit: `kept` and `removed` spell the original, `kept` and `added` the revision */
10
+ export type TextEdit = {
11
+ kind: "kept";
12
+ text: string;
13
+ } | {
14
+ kind: "added";
15
+ text: string;
16
+ } | {
17
+ kind: "removed";
18
+ text: string;
19
+ };
20
+ /**
21
+ * The shortest edit from one text to the other. Between two kept stretches the removed text comes
22
+ * first and the added text after it, each as one stretch, and no stretch is empty.
23
+ */
24
+ export declare function diffText(original: string, revised: string): TextEdit[];
@@ -0,0 +1,38 @@
1
+ // src/docx/textDiff.ts
2
+ import { commonSubsequence } from "./sequenceDiff.js";
3
+ var graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
4
+ function charactersOf(text) {
5
+ return Array.from(graphemes.segment(text), ({ segment }) => segment);
6
+ }
7
+ function diffText(original, revised) {
8
+ const was = charactersOf(original);
9
+ const now = charactersOf(revised);
10
+ const edits = [];
11
+ const push = (kind, text) => {
12
+ if (text === "") return;
13
+ const last = edits.at(-1);
14
+ if (last?.kind === kind) {
15
+ edits[edits.length - 1] = { kind, text: last.text + text };
16
+ } else {
17
+ edits.push({ kind, text });
18
+ }
19
+ };
20
+ let from = 0;
21
+ let to = 0;
22
+ const matches = commonSubsequence(
23
+ was.length,
24
+ now.length,
25
+ (i, j) => was[i] === now[j]
26
+ );
27
+ for (const [i, j] of [...matches, [was.length, now.length]]) {
28
+ push("removed", was.slice(from, i).join(""));
29
+ push("added", now.slice(to, j).join(""));
30
+ if (i < was.length) push("kept", was[i]);
31
+ from = i + 1;
32
+ to = j + 1;
33
+ }
34
+ return edits;
35
+ }
36
+ export {
37
+ diffText
38
+ };
@@ -2,7 +2,10 @@
2
2
  import {
3
3
  TextSelection
4
4
  } from "prosemirror-state";
5
- import { commentParaId } from "../../../docx/comments.js";
5
+ import { seededHexId } from "../../../docx/comments.js";
6
+ import { writtenCommentDates } from "../../../docx/comments/dates.js";
7
+ import { HIGHEST_DURABLE_ID } from "../../../docx/comments/grammar.js";
8
+ import { durableIdKey } from "../../../docx/comments/reading.js";
6
9
  import {
7
10
  sameStory,
8
11
  setStory,
@@ -16,6 +19,7 @@ import { docxSchema } from "../../../schema/index.js";
16
19
  import { guardedCommand } from "../../../schema/guards.js";
17
20
  import { isWrapperType } from "../../../schema/wrappers.js";
18
21
  import {
22
+ reservedCommentDurableIds,
19
23
  reservedCommentIds,
20
24
  reservedCommentParaIds
21
25
  } from "../../editorDocument.js";
@@ -70,25 +74,48 @@ function nextCommentId(state) {
70
74
  }
71
75
  return (max + 1n).toString();
72
76
  }
73
- function nextCommentParaId(state, seed, additional = []) {
74
- const taken = new Set(
75
- Array.from(reservedCommentParaIds(state), (id) => id.toUpperCase())
76
- );
77
+ var hexId = (value) => value.toString(16).toUpperCase().padStart(8, "0");
78
+ function nextHexId(taken, seed, highest) {
79
+ const hashed = Number.parseInt(seededHexId(seed), 16);
80
+ let candidate = hashed > highest ? 1 : hashed;
81
+ while (taken.has(hexId(candidate))) {
82
+ candidate = candidate === highest ? 1 : candidate + 1;
83
+ }
84
+ return hexId(candidate);
85
+ }
86
+ function idsInDocument(state, key) {
87
+ const ids = [];
88
+ const take = (value) => {
89
+ const id = stringAttr(value);
90
+ if (id !== null) ids.push(id);
91
+ };
77
92
  state.doc.descendants((node) => {
78
93
  if (node.type.name !== "commentReference") return true;
79
- const paraId = stringAttr(node.attrs.paraId);
80
- if (paraId !== null) taken.add(paraId.toUpperCase());
81
- for (const reply of repliesAttr(node.attrs.replies)) {
82
- taken.add(reply.paraId.toUpperCase());
83
- }
94
+ take(node.attrs[key]);
95
+ for (const reply of repliesAttr(node.attrs.replies)) take(reply[key]);
84
96
  return true;
85
97
  });
86
- for (const paraId of additional) taken.add(paraId.toUpperCase());
87
- let candidate = Number.parseInt(commentParaId(seed), 16);
88
- while (taken.has(candidate.toString(16).toUpperCase().padStart(8, "0"))) {
89
- candidate = candidate === 2147483647 ? 1 : candidate + 1;
90
- }
91
- return candidate.toString(16).toUpperCase().padStart(8, "0");
98
+ return ids;
99
+ }
100
+ function nextCommentParaId(state, seed, additional = []) {
101
+ const taken = new Set(
102
+ [
103
+ ...reservedCommentParaIds(state),
104
+ ...idsInDocument(state, "paraId"),
105
+ ...additional
106
+ ].map((id) => id.toUpperCase())
107
+ );
108
+ return nextHexId(taken, seed, 2147483647);
109
+ }
110
+ function nextCommentDurableId(state, seed, dateUtc) {
111
+ if (dateUtc === null) return null;
112
+ const taken = new Set(
113
+ [
114
+ ...reservedCommentDurableIds(state),
115
+ ...idsInDocument(state, "durableId")
116
+ ].map(durableIdKey)
117
+ );
118
+ return nextHexId(taken, `${seed}-${dateUtc}`, HIGHEST_DURABLE_ID);
92
119
  }
93
120
  function wrapperMarksAt(state, pos, side) {
94
121
  const resolved = state.doc.resolve(pos);
@@ -101,7 +128,7 @@ function addCommentTransaction(state, comment, at) {
101
128
  const range = commentedRange(state, at);
102
129
  if (range === null || comment.text.trim().length === 0) return null;
103
130
  const id = nextCommentId(state);
104
- const date = comment.date ?? (/* @__PURE__ */ new Date()).toISOString();
131
+ const { date, dateUtc } = writtenCommentDates(comment.date);
105
132
  const paraId = nextCommentParaId(state, `comment-${id}-${date}`);
106
133
  const { from, to } = range;
107
134
  const startMarks = wrapperMarksAt(state, from, "after");
@@ -123,7 +150,9 @@ function addCommentTransaction(state, comment, at) {
123
150
  resolved: false,
124
151
  extensionXml: null,
125
152
  threadImported: true,
126
- replies: []
153
+ replies: [],
154
+ durableId: nextCommentDurableId(state, `durable-${id}`, dateUtc),
155
+ dateUtc
127
156
  },
128
157
  null,
129
158
  endMarks
@@ -222,7 +251,12 @@ function addCommentReply(id, reply) {
222
251
  return (state, dispatch) => {
223
252
  if (reply.text.trim().length === 0) return false;
224
253
  const replyId = nextCommentId(state);
225
- const date = reply.date ?? (/* @__PURE__ */ new Date()).toISOString();
254
+ const { date, dateUtc } = writtenCommentDates(reply.date);
255
+ const durableId = nextCommentDurableId(
256
+ state,
257
+ `durable-${replyId}`,
258
+ dateUtc
259
+ );
226
260
  return updateReference(
227
261
  id,
228
262
  (node) => {
@@ -246,7 +280,9 @@ function addCommentReply(id, reply) {
246
280
  date,
247
281
  paraId,
248
282
  parentParaId,
249
- extensionXml: null
283
+ extensionXml: null,
284
+ durableId,
285
+ dateUtc
250
286
  }
251
287
  ]
252
288
  };
@@ -24,7 +24,7 @@ export interface NewComment {
24
24
  /** The identity behind `author`. A comment written without one belongs to nobody in particular */
25
25
  authorId?: string;
26
26
  initials?: string;
27
- /** ISO 8601 timestamp. The current time is used when omitted. */
27
+ /** ISO 8601 instant, kept to the second. The current time is used when omitted. */
28
28
  date?: string;
29
29
  }
30
30
  /**
@@ -36,6 +36,7 @@ export interface DocumentComment {
36
36
  readonly author: string | null;
37
37
  readonly authorId: string | null;
38
38
  readonly initials: string | null;
39
+ /** ISO 8601 instant in UTC. A value that is not a readable date is returned as written. */
39
40
  readonly date: string | null;
40
41
  /** What it says, as plain text. The formatting behind it is `setCommentBody`'s to write */
41
42
  readonly text: string;
@@ -57,6 +58,7 @@ export interface DocumentCommentReply {
57
58
  readonly author: string | null;
58
59
  readonly authorId: string | null;
59
60
  readonly initials: string | null;
61
+ /** Read the way `DocumentComment.date` is */
60
62
  readonly date: string | null;
61
63
  readonly text: string;
62
64
  }
@@ -43,6 +43,8 @@ export interface EditorDocument {
43
43
  readonly reservedCommentIds: ReadonlySet<string>;
44
44
  /** Every paragraph id present in the opened comment parts, including orphan extension entries */
45
45
  readonly reservedCommentParaIds: ReadonlySet<string>;
46
+ /** Every durable id the opened comment parts name, including orphan entries */
47
+ readonly reservedCommentDurableIds: ReadonlySet<string>;
46
48
  /** How the document counts its footnotes and endnotes, which the note labels are spelled in */
47
49
  readonly noteNumbering: NoteNumbering;
48
50
  /** The note entries that lay out the page rather than number a note: separators and the continuation notice */
@@ -79,3 +81,5 @@ export declare function storyDocument(document: EditorDocument, geometry: PageGe
79
81
  export declare function reservedCommentIds(state: EditorState): ReadonlySet<string>;
80
82
  /** The paragraph ids the opened comment parts already spent */
81
83
  export declare function reservedCommentParaIds(state: EditorState): ReadonlySet<string>;
84
+ /** The durable ids the opened comment parts already spent */
85
+ export declare function reservedCommentDurableIds(state: EditorState): ReadonlySet<string>;
@@ -1,5 +1,6 @@
1
1
  // src/editor/editorDocument.ts
2
2
  import { Plugin, PluginKey } from "prosemirror-state";
3
+ import { spentDurableIds } from "../docx/comments/reading.js";
3
4
  import { DEFAULT_TAB_STOP_PT } from "../docx/documentSettings.js";
4
5
  import {
5
6
  NO_DOCUMENT_DEFAULTS,
@@ -29,6 +30,7 @@ var NO_DOCUMENT = {
29
30
  defaultTabStopPt: DEFAULT_TAB_STOP_PT,
30
31
  reservedCommentIds: NO_IDS,
31
32
  reservedCommentParaIds: NO_IDS,
33
+ reservedCommentDurableIds: NO_IDS,
32
34
  noteNumbering: DEFAULT_NOTE_NUMBERING,
33
35
  specialNotes: NO_NOTE_KEYS,
34
36
  reservedNoteKeys: NO_NOTE_KEYS
@@ -41,6 +43,9 @@ function reservedParaIds(session) {
41
43
  for (const extension of session.comments.extendedOrdered) {
42
44
  paraIds.add(extension.paraId);
43
45
  }
46
+ for (const entry of session.comments.ids.ordered) {
47
+ paraIds.add(entry.paraId);
48
+ }
44
49
  return paraIds;
45
50
  }
46
51
  function formattingWithNewLists(formatting, doc) {
@@ -62,6 +67,7 @@ function editorDocumentOf(session, doc) {
62
67
  defaultTabStopPt: session.defaultTabStopPt,
63
68
  reservedCommentIds: new Set(session.comments.byId.keys()),
64
69
  reservedCommentParaIds: reservedParaIds(session),
70
+ reservedCommentDurableIds: spentDurableIds(session.comments),
65
71
  noteNumbering: session.noteNumbering,
66
72
  specialNotes: session.specialNotes,
67
73
  reservedNoteKeys: new Set(
@@ -105,11 +111,15 @@ function reservedCommentIds(state) {
105
111
  function reservedCommentParaIds(state) {
106
112
  return documentOf(state).reservedCommentParaIds;
107
113
  }
114
+ function reservedCommentDurableIds(state) {
115
+ return documentOf(state).reservedCommentDurableIds;
116
+ }
108
117
  export {
109
118
  NO_DOCUMENT,
110
119
  documentOf,
111
120
  editorDocument,
112
121
  editorDocumentOf,
122
+ reservedCommentDurableIds,
113
123
  reservedCommentIds,
114
124
  reservedCommentParaIds,
115
125
  storyDocument
@@ -1,5 +1,6 @@
1
1
  // src/editor/plugins/commentDecorations.ts
2
2
  import { Decoration, DecorationSet } from "prosemirror-view";
3
+ import { commentInstant } from "../../docx/comments/dates.js";
3
4
  import { storyKey, storyOf, storyText } from "../../docx/story.js";
4
5
  import { editorClassNames } from "../../styles/classNames.js";
5
6
  import {
@@ -41,7 +42,10 @@ function commentsIn(doc) {
41
42
  author: stringAttr(node.attrs.author),
42
43
  authorId: stringAttr(node.attrs.authorId),
43
44
  initials: stringAttr(node.attrs.initials),
44
- date: stringAttr(node.attrs.date),
45
+ date: commentInstant(
46
+ stringAttr(node.attrs.date),
47
+ stringAttr(node.attrs.dateUtc)
48
+ ),
45
49
  text: bodyText(doc, id),
46
50
  from: anchored ? start + 1 : point,
47
51
  to: anchored ? end : point,
@@ -53,7 +57,7 @@ function commentsIn(doc) {
53
57
  author: reply.author,
54
58
  authorId: reply.authorId,
55
59
  initials: reply.initials,
56
- date: reply.date,
60
+ date: commentInstant(stringAttr(reply.date), stringAttr(reply.dateUtc)),
57
61
  text: bodyText(doc, reply.id)
58
62
  }))
59
63
  };
@@ -52,7 +52,7 @@ export interface ExportProblemStory {
52
52
  readonly id: string;
53
53
  }
54
54
  /** A part the export writes beside the body, named after what it holds */
55
- export type ExportPartName = "media" | "numbering" | "comments" | "commentsExtended" | "people" | "footnotes" | "endnotes";
55
+ export type ExportPartName = "media" | "numbering" | "comments" | "commentsExtended" | "people" | "commentsIds" | "commentsExtensible" | "footnotes" | "endnotes";
56
56
  /**
57
57
  * What a refusal is actually about.
58
58
  *
@@ -26,6 +26,8 @@ export declare const NAMESPACES: {
26
26
  readonly r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
27
27
  readonly w14: "http://schemas.microsoft.com/office/word/2010/wordml";
28
28
  readonly w15: "http://schemas.microsoft.com/office/word/2012/wordml";
29
+ readonly w16cid: "http://schemas.microsoft.com/office/word/2016/wordml/cid";
30
+ readonly w16cex: "http://schemas.microsoft.com/office/word/2018/wordml/cex";
29
31
  readonly mc: "http://schemas.openxmlformats.org/markup-compatibility/2006";
30
32
  readonly wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
31
33
  readonly a: "http://schemas.openxmlformats.org/drawingml/2006/main";