@portone/docx-editor 0.6.5 → 0.6.7
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.
- package/CHANGELOG.md +35 -0
- package/CONTRIBUTING.md +4 -4
- package/dist/core.d.ts +7 -0
- package/dist/core.js +2 -0
- package/dist/docx/commentOnlyChange.d.ts +4 -4
- package/dist/docx/comments/constants.d.ts +7 -0
- package/dist/docx/comments/constants.js +13 -1
- package/dist/docx/comments/dates.d.ts +22 -0
- package/dist/docx/comments/dates.js +102 -0
- package/dist/docx/comments/durable.d.ts +22 -0
- package/dist/docx/comments/durable.js +138 -0
- package/dist/docx/comments/grammar.d.ts +10 -1
- package/dist/docx/comments/grammar.js +49 -2
- package/dist/docx/comments/model.d.ts +10 -2
- package/dist/docx/comments/model.js +38 -8
- package/dist/docx/comments/parts.d.ts +53 -7
- package/dist/docx/comments/parts.js +163 -20
- package/dist/docx/comments/people.d.ts +1 -1
- package/dist/docx/comments/people.js +5 -15
- package/dist/docx/comments/reading.d.ts +26 -0
- package/dist/docx/comments/reading.js +109 -49
- package/dist/docx/comments/writing.d.ts +2 -7
- package/dist/docx/comments/writing.js +30 -43
- package/dist/docx/compareDocx.d.ts +154 -0
- package/dist/docx/compareDocx.js +218 -0
- package/dist/docx/fidelity.js +2 -4
- package/dist/docx/importParagraph.js +6 -9
- package/dist/docx/invariants.js +19 -6
- package/dist/docx/packageParts.d.ts +2 -0
- package/dist/docx/packageParts.js +5 -1
- package/dist/docx/partPlan.d.ts +12 -0
- package/dist/docx/partPlan.js +19 -1
- package/dist/docx/protectionPolicy.d.ts +33 -5
- package/dist/docx/protectionPolicy.js +93 -47
- package/dist/docx/runProps.d.ts +3 -0
- package/dist/docx/runProps.js +9 -0
- package/dist/docx/sequenceDiff.d.ts +56 -0
- package/dist/docx/sequenceDiff.js +252 -0
- package/dist/docx/serializeParagraph.js +29 -3
- package/dist/docx/storyProjection.d.ts +2 -0
- package/dist/docx/storyProjection.js +10 -9
- package/dist/docx/textDiff.d.ts +24 -0
- package/dist/docx/textDiff.js +38 -0
- package/dist/editor/blockControlEdits.js +4 -4
- package/dist/editor/commands/comments/editing.js +59 -22
- package/dist/editor/commands/comments/model.d.ts +3 -1
- package/dist/editor/createEditor.js +6 -9
- package/dist/editor/editorDocument.d.ts +4 -0
- package/dist/editor/editorDocument.js +10 -0
- package/dist/editor/formatSource.d.ts +17 -0
- package/dist/editor/formatSource.js +74 -0
- package/dist/editor/plugins/caretFormat.d.ts +10 -0
- package/dist/editor/plugins/caretFormat.js +39 -0
- package/dist/editor/plugins/commentDecorations.js +6 -2
- package/dist/editor/plugins/controlContents.d.ts +5 -0
- package/dist/editor/plugins/controlContents.js +120 -13
- package/dist/editor/plugins/emptyRunPointer.d.ts +9 -0
- package/dist/editor/plugins/emptyRunPointer.js +22 -0
- package/dist/editor/plugins/inlinePlugins.d.ts +6 -0
- package/dist/editor/plugins/inlinePlugins.js +19 -0
- package/dist/editor/stories/storyState.js +4 -8
- package/dist/editor/views/runMarkView.d.ts +5 -2
- package/dist/editor/views/runMarkView.js +12 -1
- package/dist/ooxml/errors.d.ts +1 -1
- package/dist/ooxml/names.d.ts +2 -0
- package/dist/ooxml/names.js +2 -0
- package/dist/ooxml/partSplice.d.ts +13 -3
- package/dist/ooxml/partSplice.js +45 -18
- package/dist/schema/attrRoles.js +4 -1
- package/dist/schema/clipboard.js +3 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +52 -4
- package/dist/schema/emptyRuns.d.ts +3 -0
- package/dist/schema/emptyRuns.js +7 -0
- package/dist/schema/locks.d.ts +11 -0
- package/dist/schema/locks.js +2 -0
- package/dist/schema/protection.js +2 -1
- package/dist/styles/classNames.d.ts +4 -0
- package/dist/styles/classNames.js +4 -0
- package/dist/styles/inlineStyle.d.ts +2 -0
- package/dist/styles/inlineStyle.js +10 -4
- package/dist/styles.css +15 -0
- package/dist/ui/CommentsPanel.js +8 -13
- package/dist/ui/comments/commentDate.d.ts +7 -0
- package/dist/ui/comments/commentDate.js +17 -0
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/docx/comments/model.ts
|
|
2
|
-
function
|
|
2
|
+
function seededHexId(seed) {
|
|
3
3
|
let hash = 2166136261;
|
|
4
4
|
for (const char of seed) {
|
|
5
5
|
hash ^= char.charCodeAt(0);
|
|
@@ -18,8 +18,8 @@ function importedCommentReplies(comments, rootId) {
|
|
|
18
18
|
const { parentId, reply } = item;
|
|
19
19
|
visited.add(reply.id);
|
|
20
20
|
const parent = comments.byId.get(parentId);
|
|
21
|
-
const paraId = reply.paraId ??
|
|
22
|
-
const parentParaId = reply.parentParaId ?? parent?.paraId ??
|
|
21
|
+
const paraId = reply.paraId ?? seededHexId(`comment-${reply.id}`);
|
|
22
|
+
const parentParaId = reply.parentParaId ?? parent?.paraId ?? seededHexId(`comment-${parentId}`);
|
|
23
23
|
replies.push({
|
|
24
24
|
id: reply.id,
|
|
25
25
|
author: reply.author,
|
|
@@ -28,7 +28,9 @@ function importedCommentReplies(comments, rootId) {
|
|
|
28
28
|
date: reply.date,
|
|
29
29
|
paraId,
|
|
30
30
|
parentParaId,
|
|
31
|
-
extensionXml: reply.extensionXml
|
|
31
|
+
extensionXml: reply.extensionXml,
|
|
32
|
+
durableId: reply.durableId,
|
|
33
|
+
dateUtc: reply.dateUtc
|
|
32
34
|
});
|
|
33
35
|
const children = comments.repliesByParentId.get(reply.id) ?? [];
|
|
34
36
|
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
@@ -37,6 +39,28 @@ function importedCommentReplies(comments, rootId) {
|
|
|
37
39
|
}
|
|
38
40
|
return replies;
|
|
39
41
|
}
|
|
42
|
+
function currentCommentBodies(references) {
|
|
43
|
+
const comments = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const [id, comment] of references) {
|
|
45
|
+
comments.set(id, comment);
|
|
46
|
+
for (const reply of comment.replies) comments.set(reply.id, reply);
|
|
47
|
+
}
|
|
48
|
+
return comments;
|
|
49
|
+
}
|
|
50
|
+
function originalThreadIds(comments, rootIds) {
|
|
51
|
+
const ids = new Set(rootIds);
|
|
52
|
+
const pending = Array.from(rootIds);
|
|
53
|
+
while (pending.length > 0) {
|
|
54
|
+
const parent = pending.shift();
|
|
55
|
+
if (parent === void 0) break;
|
|
56
|
+
for (const reply of comments.repliesByParentId.get(parent) ?? []) {
|
|
57
|
+
if (ids.has(reply.id)) continue;
|
|
58
|
+
ids.add(reply.id);
|
|
59
|
+
pending.push(reply.id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return ids;
|
|
63
|
+
}
|
|
40
64
|
function nullableString(value) {
|
|
41
65
|
return typeof value === "string" ? value : null;
|
|
42
66
|
}
|
|
@@ -58,7 +82,9 @@ function replyData(value) {
|
|
|
58
82
|
date: nullableString(entry.date),
|
|
59
83
|
paraId,
|
|
60
84
|
parentParaId,
|
|
61
|
-
extensionXml: nullableString(entry.extensionXml)
|
|
85
|
+
extensionXml: nullableString(entry.extensionXml),
|
|
86
|
+
durableId: nullableString(entry.durableId),
|
|
87
|
+
dateUtc: nullableString(entry.dateUtc)
|
|
62
88
|
}
|
|
63
89
|
];
|
|
64
90
|
});
|
|
@@ -77,7 +103,9 @@ function referenceData(node) {
|
|
|
77
103
|
resolved: node.attrs.resolved === true,
|
|
78
104
|
extensionXml: nullableString(node.attrs.extensionXml),
|
|
79
105
|
threadImported: node.attrs.threadImported === true,
|
|
80
|
-
replies: replyData(node.attrs.replies)
|
|
106
|
+
replies: replyData(node.attrs.replies),
|
|
107
|
+
durableId: nullableString(node.attrs.durableId),
|
|
108
|
+
dateUtc: nullableString(node.attrs.dateUtc)
|
|
81
109
|
};
|
|
82
110
|
}
|
|
83
111
|
function commentReferencesIn(doc) {
|
|
@@ -92,7 +120,9 @@ function commentReferencesIn(doc) {
|
|
|
92
120
|
return references;
|
|
93
121
|
}
|
|
94
122
|
export {
|
|
95
|
-
commentParaId,
|
|
96
123
|
commentReferencesIn,
|
|
97
|
-
|
|
124
|
+
currentCommentBodies,
|
|
125
|
+
importedCommentReplies,
|
|
126
|
+
originalThreadIds,
|
|
127
|
+
seededHexId
|
|
98
128
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The parts a comment is written across, each declared once: where it sits, what it is
|
|
3
3
|
* declared as in the package, what an entry in it looks like, and who may have written one.
|
|
4
4
|
*
|
|
5
5
|
* The writer named the relationship and the content type where it added a part and the verifier
|
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
* comment under `editableComments: "all"`, which is a thing the editor lets them do.
|
|
13
13
|
*/
|
|
14
14
|
import { type EditableComments } from "../../schema/protection";
|
|
15
|
-
import type { StoryPartKind } from "../protectionPolicy";
|
|
15
|
+
import type { JudgedPackages, PolicyOptions, StoryPartKind } from "../protectionPolicy";
|
|
16
|
+
import type { SessionStore } from "../session";
|
|
17
|
+
import { type Story } from "../storyProjection";
|
|
16
18
|
import { type ImportedPeople } from "./people";
|
|
19
|
+
import { type ImportedCommentPart } from "./reading";
|
|
17
20
|
/**
|
|
18
21
|
* Whether this editor's writer could have put the entry out, whoever it belongs to.
|
|
19
22
|
*
|
|
@@ -47,12 +50,55 @@ export declare function threadKeyAlone(entry: Element, original: Element): boole
|
|
|
47
50
|
* against; `people` is the submission's, since it says who the submission names.
|
|
48
51
|
*/
|
|
49
52
|
export declare function entryAllowed(entry: Element, original: Element | null, authorId: string, editableComments: EditableComments, people: ImportedPeople, unattributed: ReadonlySet<string>): boolean;
|
|
53
|
+
/** What an entry is judged by beside the entry itself and the one that arrived under its key */
|
|
54
|
+
interface EntryJudgement {
|
|
55
|
+
authorId: string;
|
|
56
|
+
options: PolicyOptions;
|
|
57
|
+
packages: JudgedPackages;
|
|
58
|
+
unattributed: ReadonlySet<string>;
|
|
59
|
+
}
|
|
60
|
+
/** What one comment part holds, beyond what every story part declares */
|
|
61
|
+
interface CommentPartShape {
|
|
62
|
+
relType: string;
|
|
63
|
+
contentType: string;
|
|
64
|
+
/** The name a new part takes, ahead of the number that tells it from one the package has */
|
|
65
|
+
baseName: string;
|
|
66
|
+
namespace: string;
|
|
67
|
+
/** The element the entries stand in, which shares their namespace */
|
|
68
|
+
rootName: string;
|
|
69
|
+
/** Whether rebuilding the entries drops the content between them, as the two comment writers do */
|
|
70
|
+
rewritesContents: boolean;
|
|
71
|
+
localName: string;
|
|
72
|
+
idAttr: string;
|
|
73
|
+
/** The one other child the part's type takes, after every entry, which a submission keeps as it arrived */
|
|
74
|
+
closingChild?: string;
|
|
75
|
+
xmlIn(session: SessionStore): string | null;
|
|
76
|
+
pathIn(session: SessionStore): string | null;
|
|
77
|
+
referents(story: Story): ReadonlySet<string>;
|
|
78
|
+
/** Grammar alone, as `StoryPartKind.wellFormed` asks it */
|
|
79
|
+
wellFormed(entry: Element, original: Element | null): boolean;
|
|
80
|
+
/** Permission alone, as `StoryPartKind.allowed` asks it */
|
|
81
|
+
allowed(entry: Element, original: Element | null, judgement: EntryJudgement): boolean;
|
|
82
|
+
}
|
|
50
83
|
export declare const commentsPart: StoryPartKind;
|
|
51
84
|
export declare const commentsExtendedPart: StoryPartKind;
|
|
52
85
|
export declare const peoplePart: StoryPartKind;
|
|
86
|
+
/** A part a comment's time is recorded across, which the writer splices entries into (`./durable`) */
|
|
87
|
+
export interface DurablePartShape extends CommentPartShape {
|
|
88
|
+
/** As an export refusal names it (`ExportPartName`) */
|
|
89
|
+
name: "commentsIds" | "commentsExtensible";
|
|
90
|
+
/** What a part written from nothing binds `namespace` to */
|
|
91
|
+
prefix: "w16cid" | "w16cex";
|
|
92
|
+
imported(session: SessionStore): ImportedCommentPart<unknown>;
|
|
93
|
+
}
|
|
94
|
+
/** A durable part as the verifier reads it, carrying the shape the writer writes it by */
|
|
95
|
+
export interface DurablePart extends StoryPartKind {
|
|
96
|
+
shape: DurablePartShape;
|
|
97
|
+
}
|
|
98
|
+
/** Gives a comment's thread key the durable id its UTC date is recorded under */
|
|
99
|
+
export declare const commentsIdsPart: DurablePart;
|
|
100
|
+
/** Records under a durable id when the comment was written, in UTC */
|
|
101
|
+
export declare const commentsExtensiblePart: DurablePart;
|
|
53
102
|
/** The parts a comment protection lets an edit rewrite, in the order an export writes them */
|
|
54
|
-
export declare const COMMENT_STORY_PARTS: readonly [
|
|
55
|
-
|
|
56
|
-
StoryPartKind,
|
|
57
|
-
StoryPartKind
|
|
58
|
-
];
|
|
103
|
+
export declare const COMMENT_STORY_PARTS: readonly StoryPartKind[];
|
|
104
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { NAMESPACES } from "../../ooxml/names.js";
|
|
3
3
|
import {
|
|
4
4
|
attributeByLocalName,
|
|
5
|
+
elementChildren,
|
|
5
6
|
isElement,
|
|
6
7
|
parseXml,
|
|
7
8
|
serializeXml,
|
|
@@ -21,12 +22,19 @@ import {
|
|
|
21
22
|
COMMENTS_CONTENT_TYPE,
|
|
22
23
|
COMMENTS_EXTENDED_CONTENT_TYPE,
|
|
23
24
|
COMMENTS_EXTENDED_REL_TYPE,
|
|
25
|
+
COMMENTS_EXTENSIBLE_CONTENT_TYPE,
|
|
26
|
+
COMMENTS_EXTENSIBLE_REL_TYPE,
|
|
27
|
+
COMMENTS_IDS_CONTENT_TYPE,
|
|
28
|
+
COMMENTS_IDS_REL_TYPE,
|
|
24
29
|
COMMENTS_REL_TYPE,
|
|
25
30
|
PEOPLE_CONTENT_TYPE,
|
|
26
31
|
PEOPLE_REL_TYPE,
|
|
27
32
|
W14_NS,
|
|
28
|
-
W15_NS
|
|
33
|
+
W15_NS,
|
|
34
|
+
W16CEX_NS,
|
|
35
|
+
W16CID_NS
|
|
29
36
|
} from "./constants.js";
|
|
37
|
+
import { dateWritten, oneInstant } from "./dates.js";
|
|
30
38
|
import {
|
|
31
39
|
attributesWithin,
|
|
32
40
|
COMMENT_ATTRIBUTES,
|
|
@@ -36,12 +44,18 @@ import {
|
|
|
36
44
|
isLayoutText,
|
|
37
45
|
lastBodyParagraph,
|
|
38
46
|
recordedIdentity,
|
|
47
|
+
wellFormedCommentDate,
|
|
39
48
|
wellFormedCommentExtension,
|
|
49
|
+
wellFormedCommentId,
|
|
40
50
|
wellFormedPerson
|
|
41
51
|
} from "./grammar.js";
|
|
42
52
|
import { commentReferencesIn } from "./model.js";
|
|
43
53
|
import { commentAuthorId } from "./people.js";
|
|
44
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
durableIdKey,
|
|
56
|
+
lastParagraphId,
|
|
57
|
+
spentDurableIds
|
|
58
|
+
} from "./reading.js";
|
|
45
59
|
var COMMENT_IDENTITY = [
|
|
46
60
|
"id",
|
|
47
61
|
"author",
|
|
@@ -142,6 +156,47 @@ function entryAllowed(entry, original, authorId, editableComments, people, unatt
|
|
|
142
156
|
}
|
|
143
157
|
return false;
|
|
144
158
|
}
|
|
159
|
+
function newCommentUnder(durableId, { arrived, submitted }) {
|
|
160
|
+
const key = durableIdKey(durableId);
|
|
161
|
+
const named = submitted.comments.ids.ordered.filter(
|
|
162
|
+
(entry) => durableIdKey(entry.durableId) === key
|
|
163
|
+
);
|
|
164
|
+
if (named.length !== 1 || spentDurableIds(arrived.comments).has(key)) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const [{ paraId }] = named;
|
|
168
|
+
const comment = submitted.comments.ordered.find(
|
|
169
|
+
(entry) => entry.paraId === paraId
|
|
170
|
+
);
|
|
171
|
+
return comment === void 0 || arrived.comments.byId.has(comment.id) ? null : comment;
|
|
172
|
+
}
|
|
173
|
+
function newCommentOf(entry, original, packages) {
|
|
174
|
+
const durableId = attributeByLocalName(entry, "durableId");
|
|
175
|
+
return original !== null || durableId === null ? null : newCommentUnder(durableId, packages);
|
|
176
|
+
}
|
|
177
|
+
function commentDateAllowed(entry, original, packages) {
|
|
178
|
+
const comment = newCommentOf(entry, original, packages);
|
|
179
|
+
const durableId = attributeByLocalName(entry, "durableId");
|
|
180
|
+
const dateUtc = attributeByLocalName(entry, "dateUtc");
|
|
181
|
+
if (comment?.date == null || durableId === null || dateUtc === null) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const key = durableIdKey(durableId);
|
|
185
|
+
const dated = packages.submitted.comments.extensible.ordered.filter(
|
|
186
|
+
(other) => durableIdKey(other.durableId) === key
|
|
187
|
+
);
|
|
188
|
+
return dated.length === 1 && dateWritten(comment.date) && oneInstant(comment.date, dateUtc);
|
|
189
|
+
}
|
|
190
|
+
function commentEntryAllowed(entry, original, { authorId, options, packages, unattributed }) {
|
|
191
|
+
return entryAllowed(
|
|
192
|
+
entry,
|
|
193
|
+
original,
|
|
194
|
+
authorId,
|
|
195
|
+
options.editableComments,
|
|
196
|
+
packages.submitted.comments.people,
|
|
197
|
+
unattributed
|
|
198
|
+
);
|
|
199
|
+
}
|
|
145
200
|
var COMPATIBILITY = /* @__PURE__ */ new Map([
|
|
146
201
|
["xmlns:w14", NAMESPACES.w14],
|
|
147
202
|
["xmlns:mc", NAMESPACES.mc]
|
|
@@ -193,12 +248,23 @@ function rootKeptAgainst(now, was, shape) {
|
|
|
193
248
|
});
|
|
194
249
|
return kept && Array.from(had.keys()).every((name) => now.hasAttribute(name));
|
|
195
250
|
}
|
|
251
|
+
function closingChildOf(root, shape) {
|
|
252
|
+
const last = elementChildren(root).at(-1);
|
|
253
|
+
return shape.closingChild !== void 0 && last !== void 0 && last.namespaceURI === shape.namespace && last.localName === shape.closingChild ? last : null;
|
|
254
|
+
}
|
|
255
|
+
function closingChildKept(now, was, shape) {
|
|
256
|
+
const kept = closingChildOf(now, shape);
|
|
257
|
+
const arrived = was === null ? null : closingChildOf(was, shape);
|
|
258
|
+
return kept === null || arrived === null ? kept === arrived : serializeXml(kept) === serializeXml(arrived);
|
|
259
|
+
}
|
|
196
260
|
function entriesOf(shape, xml, reading) {
|
|
197
261
|
const entries = /* @__PURE__ */ new Map();
|
|
198
262
|
if (xml === null) return entries;
|
|
199
263
|
const strict = reading === "submitted";
|
|
200
|
-
|
|
201
|
-
|
|
264
|
+
const root = parseXml(xml).documentElement;
|
|
265
|
+
const closing = closingChildOf(root, shape);
|
|
266
|
+
for (const node of Array.from(root.childNodes)) {
|
|
267
|
+
if (!isElement(node) || node === closing) continue;
|
|
202
268
|
const el = node;
|
|
203
269
|
const named = strict ? el.namespaceURI === shape.namespace && el.localName === shape.localName : el.localName === shape.localName;
|
|
204
270
|
if (!named) {
|
|
@@ -238,19 +304,21 @@ function storyPart(shape) {
|
|
|
238
304
|
now.documentElement,
|
|
239
305
|
was?.documentElement ?? null,
|
|
240
306
|
shape.rewritesContents
|
|
307
|
+
) && closingChildKept(
|
|
308
|
+
now.documentElement,
|
|
309
|
+
was?.documentElement ?? null,
|
|
310
|
+
shape
|
|
241
311
|
);
|
|
242
312
|
},
|
|
243
313
|
referents: shape.referents,
|
|
244
|
-
wellFormed:
|
|
314
|
+
wellFormed: shape.wellFormed,
|
|
245
315
|
anyonesChange: threadKeyAlone,
|
|
246
|
-
allowed: (entry, original, authorId, options,
|
|
247
|
-
entry,
|
|
248
|
-
original,
|
|
316
|
+
allowed: (entry, original, authorId, options, packages, unattributed) => shape.allowed(entry, original, {
|
|
249
317
|
authorId,
|
|
250
|
-
options
|
|
251
|
-
|
|
318
|
+
options,
|
|
319
|
+
packages,
|
|
252
320
|
unattributed
|
|
253
|
-
)
|
|
321
|
+
})
|
|
254
322
|
};
|
|
255
323
|
}
|
|
256
324
|
function referencedCommentIds(doc) {
|
|
@@ -272,7 +340,9 @@ var commentsShape = {
|
|
|
272
340
|
idAttr: "id",
|
|
273
341
|
xmlIn: (session) => session.comments.xml,
|
|
274
342
|
pathIn: (session) => session.comments.partPath,
|
|
275
|
-
referents: (story) => referencedCommentIds(story.doc)
|
|
343
|
+
referents: (story) => referencedCommentIds(story.doc),
|
|
344
|
+
wellFormed: wellFormedEntry,
|
|
345
|
+
allowed: commentEntryAllowed
|
|
276
346
|
};
|
|
277
347
|
function commentEntries(story) {
|
|
278
348
|
return Array.from(
|
|
@@ -280,6 +350,14 @@ function commentEntries(story) {
|
|
|
280
350
|
(entry) => entry.el
|
|
281
351
|
);
|
|
282
352
|
}
|
|
353
|
+
function threadKeys(story) {
|
|
354
|
+
return new Set(
|
|
355
|
+
commentEntries(story).flatMap((el) => {
|
|
356
|
+
const key = lastParagraphId(el);
|
|
357
|
+
return key === null ? [] : [key];
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
}
|
|
283
361
|
var commentsPart = storyPart(commentsShape);
|
|
284
362
|
var commentsExtendedPart = storyPart({
|
|
285
363
|
relType: COMMENTS_EXTENDED_REL_TYPE,
|
|
@@ -293,12 +371,9 @@ var commentsExtendedPart = storyPart({
|
|
|
293
371
|
xmlIn: (session) => session.comments.extendedXml,
|
|
294
372
|
pathIn: (session) => session.comments.extendedPartPath,
|
|
295
373
|
// Thread state stands for a comment, and it is keyed by the comment's own thread key
|
|
296
|
-
referents:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return key === null ? [] : [key];
|
|
300
|
-
})
|
|
301
|
-
)
|
|
374
|
+
referents: threadKeys,
|
|
375
|
+
wellFormed: wellFormedEntry,
|
|
376
|
+
allowed: commentEntryAllowed
|
|
302
377
|
});
|
|
303
378
|
var peoplePart = storyPart({
|
|
304
379
|
relType: PEOPLE_REL_TYPE,
|
|
@@ -317,12 +392,80 @@ var peoplePart = storyPart({
|
|
|
317
392
|
const author = attributeByLocalName(el, "author");
|
|
318
393
|
return author === null ? [] : [author];
|
|
319
394
|
})
|
|
320
|
-
)
|
|
395
|
+
),
|
|
396
|
+
wellFormed: wellFormedEntry,
|
|
397
|
+
allowed: commentEntryAllowed
|
|
321
398
|
});
|
|
322
|
-
|
|
399
|
+
function durableShape(shape) {
|
|
400
|
+
return {
|
|
401
|
+
...shape,
|
|
402
|
+
xmlIn: (session) => shape.imported(session).xml,
|
|
403
|
+
pathIn: (session) => shape.imported(session).partPath
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function durablePart(shape) {
|
|
407
|
+
return { ...storyPart(shape), shape };
|
|
408
|
+
}
|
|
409
|
+
var commentsIdsShape = durableShape({
|
|
410
|
+
name: "commentsIds",
|
|
411
|
+
prefix: "w16cid",
|
|
412
|
+
relType: COMMENTS_IDS_REL_TYPE,
|
|
413
|
+
contentType: COMMENTS_IDS_CONTENT_TYPE,
|
|
414
|
+
baseName: "commentsIds",
|
|
415
|
+
namespace: W16CID_NS,
|
|
416
|
+
rootName: "commentsIds",
|
|
417
|
+
rewritesContents: false,
|
|
418
|
+
localName: "commentId",
|
|
419
|
+
idAttr: "paraId",
|
|
420
|
+
imported: (session) => session.comments.ids,
|
|
421
|
+
referents: threadKeys,
|
|
422
|
+
wellFormed: wellFormedCommentId,
|
|
423
|
+
allowed: (entry, original, { packages }) => newCommentOf(entry, original, packages) !== null
|
|
424
|
+
});
|
|
425
|
+
var commentsIdsPart = durablePart(commentsIdsShape);
|
|
426
|
+
var commentsExtensiblePart = durablePart(
|
|
427
|
+
durableShape({
|
|
428
|
+
name: "commentsExtensible",
|
|
429
|
+
prefix: "w16cex",
|
|
430
|
+
relType: COMMENTS_EXTENSIBLE_REL_TYPE,
|
|
431
|
+
contentType: COMMENTS_EXTENSIBLE_CONTENT_TYPE,
|
|
432
|
+
baseName: "commentsExtensible",
|
|
433
|
+
namespace: W16CEX_NS,
|
|
434
|
+
rootName: "commentsExtensible",
|
|
435
|
+
rewritesContents: false,
|
|
436
|
+
localName: "commentExtensible",
|
|
437
|
+
idAttr: "durableId",
|
|
438
|
+
// `CT_CommentsExtensible` closes on an optional extension list ([MS-DOCX] §2.10.3.2)
|
|
439
|
+
closingChild: "extLst",
|
|
440
|
+
imported: (session) => session.comments.extensible,
|
|
441
|
+
referents: (story) => {
|
|
442
|
+
const keys = threadKeys(story);
|
|
443
|
+
return new Set(
|
|
444
|
+
Array.from(arrivedIn(commentsIdsShape, story.session).values()).flatMap(
|
|
445
|
+
({ el }) => {
|
|
446
|
+
const paraId = attributeByLocalName(el, "paraId");
|
|
447
|
+
const durableId = attributeByLocalName(el, "durableId");
|
|
448
|
+
return paraId !== null && durableId !== null && keys.has(paraId) ? [durableId] : [];
|
|
449
|
+
}
|
|
450
|
+
)
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
wellFormed: wellFormedCommentDate,
|
|
454
|
+
allowed: (entry, original, { packages }) => commentDateAllowed(entry, original, packages)
|
|
455
|
+
})
|
|
456
|
+
);
|
|
457
|
+
var COMMENT_STORY_PARTS = [
|
|
458
|
+
commentsPart,
|
|
459
|
+
commentsExtendedPart,
|
|
460
|
+
peoplePart,
|
|
461
|
+
commentsIdsPart,
|
|
462
|
+
commentsExtensiblePart
|
|
463
|
+
];
|
|
323
464
|
export {
|
|
324
465
|
COMMENT_STORY_PARTS,
|
|
325
466
|
commentsExtendedPart,
|
|
467
|
+
commentsExtensiblePart,
|
|
468
|
+
commentsIdsPart,
|
|
326
469
|
commentsPart,
|
|
327
470
|
entryAllowed,
|
|
328
471
|
peoplePart,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* A name the file's comments already write under carries the same weight, recorded or not: a
|
|
12
12
|
* person appended for it would claim those comments too.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { type PartPlanContext } from "../partPlan";
|
|
15
15
|
import type { StoryPartKind } from "../protectionPolicy";
|
|
16
16
|
import type { SessionStore } from "../session";
|
|
17
17
|
import type { CommentReferenceData, CommentReplyData } from "./model";
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../../ooxml/xml.js";
|
|
13
13
|
import { unattributedCommentAuthors } from "../../schema/protection.js";
|
|
14
14
|
import { relatedPartPath } from "../packageParts.js";
|
|
15
|
-
import {
|
|
15
|
+
import { declarePart } from "../partPlan.js";
|
|
16
16
|
import { COMMENT_AUTHOR_PROVIDER, PEOPLE_REL_TYPE, W15_NS } from "./constants.js";
|
|
17
17
|
import { renderPerson } from "./grammar.js";
|
|
18
18
|
var NO_PEOPLE = {
|
|
@@ -110,20 +110,10 @@ function planPeoplePart(part, bodies, session, context) {
|
|
|
110
110
|
unattributedCommentAuthors(session.comments.ordered)
|
|
111
111
|
);
|
|
112
112
|
if (added.size === 0) return null;
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
context.relationships.add({
|
|
118
|
-
type: part.relType,
|
|
119
|
-
target: partPath.slice(directoryOf(session.mainPartPath).length)
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
parts.set(partPath, encodeUtf8(peopleXml(people, added), people.hadBom));
|
|
123
|
-
if (addingPart || people.xml === null) {
|
|
124
|
-
context.contentTypes.addOverride(partPath, part.contentType);
|
|
125
|
-
}
|
|
126
|
-
return parts;
|
|
113
|
+
const partPath = declarePart(part, session, context, people.xml);
|
|
114
|
+
return /* @__PURE__ */ new Map([
|
|
115
|
+
[partPath, encodeUtf8(peopleXml(people, added), people.hadBom)]
|
|
116
|
+
]);
|
|
127
117
|
}
|
|
128
118
|
export {
|
|
129
119
|
NO_PEOPLE,
|
|
@@ -16,11 +16,31 @@ export interface ImportedComment {
|
|
|
16
16
|
*/
|
|
17
17
|
authorId: string | null;
|
|
18
18
|
initials: string | null;
|
|
19
|
+
/** As written: the author's wall clock (`./dates`) */
|
|
19
20
|
date: string | null;
|
|
20
21
|
paraId: string | null;
|
|
21
22
|
parentParaId: string | null;
|
|
22
23
|
resolved: boolean;
|
|
23
24
|
extensionXml: string | null;
|
|
25
|
+
durableId: string | null;
|
|
26
|
+
/** As written, where the durable id reaches one */
|
|
27
|
+
dateUtc: string | null;
|
|
28
|
+
}
|
|
29
|
+
/** A `w16cid:commentId`, keyed by the thread key of the comment it stands for */
|
|
30
|
+
export interface ImportedCommentId {
|
|
31
|
+
paraId: string;
|
|
32
|
+
durableId: string;
|
|
33
|
+
}
|
|
34
|
+
/** A `w16cex:commentExtensible` */
|
|
35
|
+
export interface ImportedCommentDate {
|
|
36
|
+
durableId: string;
|
|
37
|
+
dateUtc: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface ImportedCommentPart<Entry> {
|
|
40
|
+
partPath: string | null;
|
|
41
|
+
xml: string | null;
|
|
42
|
+
hadBom: boolean;
|
|
43
|
+
ordered: readonly Entry[];
|
|
24
44
|
}
|
|
25
45
|
export interface ImportedComments {
|
|
26
46
|
partPath: string | null;
|
|
@@ -35,6 +55,8 @@ export interface ImportedComments {
|
|
|
35
55
|
extendedOrdered: readonly ImportedCommentExtension[];
|
|
36
56
|
/** The people part as opened, which is where an author's identity is looked up */
|
|
37
57
|
people: ImportedPeople;
|
|
58
|
+
ids: ImportedCommentPart<ImportedCommentId>;
|
|
59
|
+
extensible: ImportedCommentPart<ImportedCommentDate>;
|
|
38
60
|
}
|
|
39
61
|
export declare const NO_COMMENTS: ImportedComments;
|
|
40
62
|
export interface ImportedCommentExtension {
|
|
@@ -45,6 +67,10 @@ export interface ImportedCommentExtension {
|
|
|
45
67
|
}
|
|
46
68
|
/** The thread key of a comment, which the writer puts on the last paragraph of its body */
|
|
47
69
|
export declare function lastParagraphId(comment: Element): string | null;
|
|
70
|
+
/** A durable id is hexadecimal (`ST_LongHexNumber`), so two spellings in different case are one id */
|
|
71
|
+
export declare function durableIdKey(durableId: string): string;
|
|
72
|
+
/** Every durable id the ids and extensible parts name, orphans included: a date left under one would become a new comment's */
|
|
73
|
+
export declare function spentDurableIds(comments: ImportedComments): ReadonlySet<string>;
|
|
48
74
|
/**
|
|
49
75
|
* Reads the Comments part related from the main document story.
|
|
50
76
|
*
|