@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.
Files changed (86) hide show
  1. package/CHANGELOG.md +35 -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/fidelity.js +2 -4
  27. package/dist/docx/importParagraph.js +6 -9
  28. package/dist/docx/invariants.js +19 -6
  29. package/dist/docx/packageParts.d.ts +2 -0
  30. package/dist/docx/packageParts.js +5 -1
  31. package/dist/docx/partPlan.d.ts +12 -0
  32. package/dist/docx/partPlan.js +19 -1
  33. package/dist/docx/protectionPolicy.d.ts +33 -5
  34. package/dist/docx/protectionPolicy.js +93 -47
  35. package/dist/docx/runProps.d.ts +3 -0
  36. package/dist/docx/runProps.js +9 -0
  37. package/dist/docx/sequenceDiff.d.ts +56 -0
  38. package/dist/docx/sequenceDiff.js +252 -0
  39. package/dist/docx/serializeParagraph.js +29 -3
  40. package/dist/docx/storyProjection.d.ts +2 -0
  41. package/dist/docx/storyProjection.js +10 -9
  42. package/dist/docx/textDiff.d.ts +24 -0
  43. package/dist/docx/textDiff.js +38 -0
  44. package/dist/editor/blockControlEdits.js +4 -4
  45. package/dist/editor/commands/comments/editing.js +59 -22
  46. package/dist/editor/commands/comments/model.d.ts +3 -1
  47. package/dist/editor/createEditor.js +6 -9
  48. package/dist/editor/editorDocument.d.ts +4 -0
  49. package/dist/editor/editorDocument.js +10 -0
  50. package/dist/editor/formatSource.d.ts +17 -0
  51. package/dist/editor/formatSource.js +74 -0
  52. package/dist/editor/plugins/caretFormat.d.ts +10 -0
  53. package/dist/editor/plugins/caretFormat.js +39 -0
  54. package/dist/editor/plugins/commentDecorations.js +6 -2
  55. package/dist/editor/plugins/controlContents.d.ts +5 -0
  56. package/dist/editor/plugins/controlContents.js +120 -13
  57. package/dist/editor/plugins/emptyRunPointer.d.ts +9 -0
  58. package/dist/editor/plugins/emptyRunPointer.js +22 -0
  59. package/dist/editor/plugins/inlinePlugins.d.ts +6 -0
  60. package/dist/editor/plugins/inlinePlugins.js +19 -0
  61. package/dist/editor/stories/storyState.js +4 -8
  62. package/dist/editor/views/runMarkView.d.ts +5 -2
  63. package/dist/editor/views/runMarkView.js +12 -1
  64. package/dist/ooxml/errors.d.ts +1 -1
  65. package/dist/ooxml/names.d.ts +2 -0
  66. package/dist/ooxml/names.js +2 -0
  67. package/dist/ooxml/partSplice.d.ts +13 -3
  68. package/dist/ooxml/partSplice.js +45 -18
  69. package/dist/schema/attrRoles.js +4 -1
  70. package/dist/schema/clipboard.js +3 -0
  71. package/dist/schema/docxSchema.d.ts +1 -1
  72. package/dist/schema/docxSchema.js +52 -4
  73. package/dist/schema/emptyRuns.d.ts +3 -0
  74. package/dist/schema/emptyRuns.js +7 -0
  75. package/dist/schema/locks.d.ts +11 -0
  76. package/dist/schema/locks.js +2 -0
  77. package/dist/schema/protection.js +2 -1
  78. package/dist/styles/classNames.d.ts +4 -0
  79. package/dist/styles/classNames.js +4 -0
  80. package/dist/styles/inlineStyle.d.ts +2 -0
  81. package/dist/styles/inlineStyle.js +10 -4
  82. package/dist/styles.css +15 -0
  83. package/dist/ui/CommentsPanel.js +8 -13
  84. package/dist/ui/comments/commentDate.d.ts +7 -0
  85. package/dist/ui/comments/commentDate.js +17 -0
  86. package/package.json +7 -7
@@ -0,0 +1,218 @@
1
+ // src/docx/compareDocx.ts
2
+ import { withXmlParser } from "../ooxml/xml.js";
3
+ import { SDT_BLOCK_NODE, SDT_EMPTY_BLOCK_NODE } from "../schema/controlAttrs.js";
4
+ import { withoutComments } from "../schema/protection.js";
5
+ import { commentReferencesIn } from "./comments/model.js";
6
+ import { commentsPolicy } from "./comments/policy.js";
7
+ import { importDocx } from "./importDocx.js";
8
+ import { sameBytes } from "./packageParts.js";
9
+ import {
10
+ aroundTheBlocks,
11
+ declarationsKept,
12
+ policyPartPaths
13
+ } from "./protectionPolicy.js";
14
+ import { alignSequences } from "./sequenceDiff.js";
15
+ import { storyKey, storyOf, storyText } from "./story.js";
16
+ import { comparableBlock } from "./storyProjection.js";
17
+ import { diffText } from "./textDiff.js";
18
+ var BLOCK_KINDS = {
19
+ paragraph: "paragraph",
20
+ table: "table",
21
+ [SDT_BLOCK_NODE]: "control",
22
+ [SDT_EMPTY_BLOCK_NODE]: "control",
23
+ rawBlock: "preserved"
24
+ };
25
+ function blockKind(node) {
26
+ const kind = BLOCK_KINDS[node.type.name];
27
+ if (kind === void 0) {
28
+ throw new Error(`no block kind for ${node.type.name}`);
29
+ }
30
+ return kind;
31
+ }
32
+ function blocksOf(story, side) {
33
+ const blocks = [];
34
+ story.doc.forEach((node, pos, index) => {
35
+ blocks.push({
36
+ node,
37
+ pos,
38
+ block: blockKind(node),
39
+ text: storyText(node),
40
+ identity: comparableBlock(node, story.session, withoutComments) ?? `\0${side}:${index}`
41
+ });
42
+ });
43
+ return blocks;
44
+ }
45
+ function isDifference(step) {
46
+ return step.kind !== "kept";
47
+ }
48
+ function rowAt({ index, cells }) {
49
+ return { index, cells };
50
+ }
51
+ function rowsOf(table) {
52
+ return table.children.map((row, index) => {
53
+ const cells = row.children.map(storyText);
54
+ const text = JSON.stringify(cells);
55
+ return { index, cells, identity: text, text };
56
+ });
57
+ }
58
+ function rowChanges(original, revised) {
59
+ const was = rowsOf(original);
60
+ const now = rowsOf(revised);
61
+ const rowChange = (step) => {
62
+ switch (step.kind) {
63
+ case "added":
64
+ return { kind: "added", ...rowAt(now[step.revised]) };
65
+ case "removed":
66
+ return { kind: "removed", ...rowAt(was[step.original]) };
67
+ case "changed":
68
+ return {
69
+ kind: "changed",
70
+ original: rowAt(was[step.original]),
71
+ revised: rowAt(now[step.revised])
72
+ };
73
+ }
74
+ };
75
+ return alignSequences(was, now).filter(isDifference).map(rowChange);
76
+ }
77
+ function blockAt({ pos, text }) {
78
+ return { pos, text };
79
+ }
80
+ function changedBlock(from, to, change) {
81
+ const original = blockAt(from);
82
+ const revised = blockAt(to);
83
+ if (to.block === "table") {
84
+ const rows = rowChanges(from.node, to.node);
85
+ return change === "text" ? {
86
+ kind: "changed",
87
+ block: to.block,
88
+ original,
89
+ revised,
90
+ change,
91
+ edits: diffText(from.text, to.text),
92
+ rows
93
+ } : { kind: "changed", block: to.block, original, revised, change, rows };
94
+ }
95
+ return change === "text" ? {
96
+ kind: "changed",
97
+ block: to.block,
98
+ original,
99
+ revised,
100
+ change,
101
+ edits: diffText(from.text, to.text)
102
+ } : { kind: "changed", block: to.block, original, revised, change };
103
+ }
104
+ function blockChanges(original, revised) {
105
+ const was = blocksOf(original, "original");
106
+ const now = blocksOf(revised, "revised");
107
+ const blockChange = (step) => {
108
+ switch (step.kind) {
109
+ case "added": {
110
+ const block = now[step.revised];
111
+ return { kind: "added", block: block.block, ...blockAt(block) };
112
+ }
113
+ case "removed": {
114
+ const block = was[step.original];
115
+ return { kind: "removed", block: block.block, ...blockAt(block) };
116
+ }
117
+ case "changed":
118
+ return changedBlock(was[step.original], now[step.revised], step.change);
119
+ }
120
+ };
121
+ return alignSequences(was, now, (block) => block.block).filter(isDifference).map(blockChange);
122
+ }
123
+ function commentsOf(doc) {
124
+ const read = /* @__PURE__ */ new Map();
125
+ const add = (comment) => {
126
+ if (read.has(comment.id)) return;
127
+ read.set(comment.id, {
128
+ id: comment.id,
129
+ author: comment.author,
130
+ authorId: comment.authorId,
131
+ text: storyText(storyOf(doc, storyKey("comment", comment.id)))
132
+ });
133
+ };
134
+ for (const comment of commentReferencesIn(doc).values()) {
135
+ add(comment);
136
+ comment.replies.forEach(add);
137
+ }
138
+ return read;
139
+ }
140
+ function sameAuthor(original, revised) {
141
+ return original.authorId === null && revised.authorId === null ? original.author === revised.author : original.authorId === revised.authorId;
142
+ }
143
+ function commentChanges(original, revised) {
144
+ const was = commentsOf(original);
145
+ const now = commentsOf(revised);
146
+ const changes = [];
147
+ for (const [id, comment] of was) {
148
+ const current = now.get(id);
149
+ if (current === void 0 || !sameAuthor(comment, current)) {
150
+ changes.push({ kind: "removed", ...comment });
151
+ } else if (current.text !== comment.text) {
152
+ changes.push({
153
+ kind: "changed",
154
+ id,
155
+ author: current.author,
156
+ authorId: current.authorId,
157
+ original: comment.text,
158
+ revised: current.text
159
+ });
160
+ }
161
+ }
162
+ for (const [id, comment] of now) {
163
+ const earlier = was.get(id);
164
+ if (earlier === void 0 || !sameAuthor(earlier, comment)) {
165
+ changes.push({ kind: "added", ...comment });
166
+ }
167
+ }
168
+ return changes;
169
+ }
170
+ function partChanges(original, revised) {
171
+ const was = original.session;
172
+ const now = revised.session;
173
+ const sameMainPart = was.mainPartPath === now.mainPartPath;
174
+ const compared = /* @__PURE__ */ new Set([
175
+ was.mainPartPath,
176
+ now.mainPartPath,
177
+ ...policyPartPaths(commentsPolicy, was),
178
+ ...policyPartPaths(commentsPolicy, now)
179
+ ]);
180
+ const declarations = sameMainPart ? declarationsKept(commentsPolicy, was, now, "gained or dropped") : /* @__PURE__ */ new Map();
181
+ const changes = sameMainPart ? [] : [
182
+ { part: was.mainPartPath, kind: "removed" },
183
+ { part: now.mainPartPath, kind: "added" }
184
+ ];
185
+ for (const part of /* @__PURE__ */ new Set([...was.parts.keys(), ...now.parts.keys()])) {
186
+ if (compared.has(part) || declarations.get(part) === true) continue;
187
+ const arrived = was.parts.get(part);
188
+ const current = now.parts.get(part);
189
+ if (arrived !== void 0 && current !== void 0 && sameBytes(arrived, current)) {
190
+ continue;
191
+ }
192
+ changes.push({
193
+ part,
194
+ kind: arrived === void 0 ? "added" : current === void 0 ? "removed" : "changed"
195
+ });
196
+ }
197
+ if (sameMainPart && aroundTheBlocks(original) !== aroundTheBlocks(revised)) {
198
+ changes.push({ part: was.mainPartPath, kind: "changed" });
199
+ }
200
+ return changes.sort(
201
+ (a, b) => a.part < b.part ? -1 : a.part > b.part ? 1 : 0
202
+ );
203
+ }
204
+ function compareDocx(original, revised, { xmlParser } = {}) {
205
+ return withXmlParser(xmlParser, () => {
206
+ const was = importDocx(original);
207
+ const now = importDocx(revised);
208
+ return {
209
+ blocks: blockChanges(was, now),
210
+ comments: commentChanges(was.doc, now.doc),
211
+ parts: partChanges(was, now)
212
+ };
213
+ });
214
+ }
215
+ export {
216
+ BLOCK_KINDS,
217
+ compareDocx
218
+ };
@@ -33,7 +33,7 @@ function preservedBy(node, element) {
33
33
  code: "preserved-run-content"
34
34
  };
35
35
  case "rawInline":
36
- return preservedInline(node, element);
36
+ return preservedInline(node);
37
37
  default:
38
38
  return null;
39
39
  }
@@ -44,9 +44,7 @@ function preservedBlockNote(node, element) {
44
44
  }
45
45
  return node.attrs.guarded === true ? { severity: "hidden", code: "range-marker" } : { severity: "hidden", code: "preserved-block" };
46
46
  }
47
- function preservedInline(node, element) {
48
- const name = stringAttr(node.attrs.element) ?? localNameOf(element);
49
- if (name === "r") return null;
47
+ function preservedInline(node) {
50
48
  const severity = severityOf(node.attrs.display);
51
49
  return severity === "hidden" && node.attrs.guarded === true ? { severity, code: "range-marker" } : { severity, code: "preserved-inline" };
52
50
  }
@@ -9,7 +9,7 @@ import {
9
9
  serializeXml
10
10
  } from "../ooxml/xml.js";
11
11
  import { docxSchema } from "../schema/index.js";
12
- import { commentParaId, importedCommentReplies } from "./comments/model.js";
12
+ import { importedCommentReplies, seededHexId } from "./comments/model.js";
13
13
  import { NO_COMMENTS } from "./comments/reading.js";
14
14
  import { readParagraphFormat, readRunFormat } from "./formatting.js";
15
15
  import { NO_LINK_TARGETS } from "./hyperlink.js";
@@ -75,7 +75,7 @@ function buildModelledRunChild(el, marks, images, comments) {
75
75
  const id = annotationId(el);
76
76
  if (id === null) return null;
77
77
  const comment = comments.byId.get(id);
78
- const paraId = comment?.paraId ?? commentParaId(`comment-${id}`);
78
+ const paraId = comment?.paraId ?? seededHexId(`comment-${id}`);
79
79
  return [
80
80
  docxSchema.nodes.commentReference.create(
81
81
  {
@@ -89,7 +89,9 @@ function buildModelledRunChild(el, marks, images, comments) {
89
89
  resolved: comment?.resolved ?? false,
90
90
  extensionXml: comment?.extensionXml ?? null,
91
91
  threadImported: true,
92
- replies: importedCommentReplies(comments, id)
92
+ replies: importedCommentReplies(comments, id),
93
+ durableId: comment?.durableId ?? null,
94
+ dateUtc: comment?.dateUtc ?? null
93
95
  },
94
96
  null,
95
97
  marks
@@ -143,12 +145,7 @@ function buildRunNodes(run, images, themeFonts, comments, wrappers = []) {
143
145
  }
144
146
  if (nodes.length === 0) {
145
147
  return [
146
- docxSchema.nodes.rawInline.create(
147
- { xml: serializeXml(run), element: run.localName },
148
- null,
149
- // The wrappers have to close again around this XML on export, so their marks ride along here too
150
- wrappers
151
- )
148
+ docxSchema.nodes.emptyRun.create({ xml: serializeXml(run) }, null, marks)
152
149
  ];
153
150
  }
154
151
  return nodes;
@@ -24,17 +24,15 @@ import {
24
24
  extensionsChanged,
25
25
  extensionsRootProblem
26
26
  } from "./comments.js";
27
+ import { rewrittenDurableParts } from "./comments/durable.js";
28
+ import { currentCommentBodies } from "./comments/model.js";
27
29
  import {
28
30
  commentsExtendedPart,
29
31
  commentsPart,
30
32
  peoplePart
31
33
  } from "./comments/parts.js";
32
34
  import { unrecordedAuthors } from "./comments/people.js";
33
- import {
34
- COMMENT_MARKUP,
35
- currentCommentBodies,
36
- EXTENSIONS_MARKUP
37
- } from "./comments/writing.js";
35
+ import { commentsMarkup, EXTENSIONS_MARKUP } from "./comments/writing.js";
38
36
  import { HEADER_MARKUP } from "./headersFooters.js";
39
37
  import { identityProblems, identityProblemsInStories } from "./identities.js";
40
38
  import { insertedImageSrcs } from "./media.js";
@@ -379,6 +377,16 @@ var commentPartRoots = {
379
377
  });
380
378
  }
381
379
  }
380
+ if (commentsChanged(doc, session)) {
381
+ for (const part of rewrittenDurableParts(doc, session)) {
382
+ if (part.rootProblem === null) continue;
383
+ problems.push({
384
+ code: "malformed-xml",
385
+ message: part.rootProblem,
386
+ reason: { kind: "unwritable-part-root", part: part.name }
387
+ });
388
+ }
389
+ }
382
390
  return problems;
383
391
  }
384
392
  };
@@ -408,11 +416,16 @@ function rewrittenParts(doc, session) {
408
416
  }
409
417
  const { xml, extendedXml, extendedPartPath } = session.comments;
410
418
  if (commentsChanged(doc, session)) {
411
- add(commentsPart.pathIn(session), xml, COMMENT_MARKUP);
419
+ add(commentsPart.pathIn(session), xml, commentsMarkup(doc, session));
412
420
  }
413
421
  if (extensionsChanged(doc, session) && (commentReferencesIn(doc).size > 0 || extendedPartPath !== null)) {
414
422
  add(commentsExtendedPart.pathIn(session), extendedXml, EXTENSIONS_MARKUP);
415
423
  }
424
+ if (commentsChanged(doc, session)) {
425
+ for (const part of rewrittenDurableParts(doc, session)) {
426
+ add(part.path, part.xml, part.declarations);
427
+ }
428
+ }
416
429
  if (startedLists(doc, session).defined.size > 0) {
417
430
  const path = session.numberingPartPath;
418
431
  add(path, readPart(session.parts, path), NUMBERING_MARKUP);
@@ -8,6 +8,8 @@
8
8
  * related part lived in five places.
9
9
  */
10
10
  export declare const CONTENT_TYPES_PATH = "[Content_Types].xml";
11
+ /** Whether two parts hold the same bytes, which is the only sameness a part nothing reads has */
12
+ export declare function sameBytes(before: Uint8Array, after: Uint8Array): boolean;
11
13
  /**
12
14
  * Where the part the main part relates under this type sits. null for no such relationship, and
13
15
  * for one that points outside the package, which no part of it can stand behind.
@@ -15,6 +15,9 @@ import {
15
15
  resolveTarget
16
16
  } from "./relationships.js";
17
17
  var CONTENT_TYPES_PATH = "[Content_Types].xml";
18
+ function sameBytes(before, after) {
19
+ return before.length === after.length && before.every((byte, index) => byte === after[index]);
20
+ }
18
21
  function relatedPartPath(parts, mainPartPath, type) {
19
22
  const relationship = readRelationships(parts, relsPathOf(mainPartPath)).find(
20
23
  (entry) => entry.type === type && !entry.external
@@ -147,5 +150,6 @@ export {
147
150
  declaredXmlParts,
148
151
  markupParts,
149
152
  readPart,
150
- relatedPartPath
153
+ relatedPartPath,
154
+ sameBytes
151
155
  };
@@ -17,6 +17,18 @@ export interface PartPlanContext {
17
17
  /** Where a story writer records an approximation it had to make, beside the body writer's */
18
18
  readonly notes: FidelityCollector;
19
19
  }
20
+ /** A part a planner may add, as the package relates and declares it */
21
+ export interface DeclaredPart {
22
+ readonly relType: string;
23
+ readonly contentType: string;
24
+ pathIn(session: SessionStore): string | null;
25
+ writePathIn(session: SessionStore): string;
26
+ }
27
+ /**
28
+ * Where the part is written: related from the main part where the package relates none, and
29
+ * declared in `[Content_Types].xml` where its bytes did not arrive.
30
+ */
31
+ export declare function declarePart(part: DeclaredPart, session: SessionStore, context: PartPlanContext, arrivedXml: string | null): string;
20
32
  export interface PartPlanner {
21
33
  readonly name: string;
22
34
  /** The parts to write, keyed by path, and null when the document gives this planner nothing to write */
@@ -5,7 +5,24 @@ import {
5
5
  CONTENT_TYPES_PATH,
6
6
  markupParts
7
7
  } from "./packageParts.js";
8
- import { relsPathOf } from "./relationships.js";
8
+ import {
9
+ directoryOf,
10
+ relsPathOf
11
+ } from "./relationships.js";
12
+ function declarePart(part, session, context, arrivedXml) {
13
+ const adding = part.pathIn(session) === null;
14
+ const path = part.writePathIn(session);
15
+ if (adding) {
16
+ context.relationships.add({
17
+ type: part.relType,
18
+ target: path.slice(directoryOf(session.mainPartPath).length)
19
+ });
20
+ }
21
+ if (adding || arrivedXml === null) {
22
+ context.contentTypes.addOverride(path, part.contentType);
23
+ }
24
+ return path;
25
+ }
9
26
  function runPartPlanners(planners, doc, session, context, prior = /* @__PURE__ */ new Map()) {
10
27
  const owned = new Set(
11
28
  [
@@ -53,5 +70,6 @@ function assertPartsParse(replacements, contentTypes) {
53
70
  }
54
71
  export {
55
72
  assertPartsParse,
73
+ declarePart,
56
74
  runPartPlanners
57
75
  };
@@ -36,6 +36,10 @@ export interface PolicyOptions {
36
36
  export interface VerifyOptions extends PolicyOptions {
37
37
  xmlParser?: XmlParser;
38
38
  }
39
+ export interface JudgedPackages {
40
+ arrived: SessionStore;
41
+ submitted: SessionStore;
42
+ }
39
43
  /** One package part a protection lets an editor rewrite, and how a rewritten entry is judged */
40
44
  export interface StoryPartKind {
41
45
  relType: string;
@@ -75,12 +79,11 @@ export interface StoryPartKind {
75
79
  anyonesChange(entry: Element, original: Element): boolean;
76
80
  /**
77
81
  * Permission alone: whether `authorId` may have written (`original === null`) or rewritten this
78
- * entry under `options`. `session` is the submission's, so a kind can look across at a sibling
79
- * part, the way a comment's author resolves through the people part. `unattributed` is the
80
- * display names the file that arrived writes comments under while recording nobody for them,
81
- * which is what an entry claiming no identity is held against.
82
+ * entry under `options`. `packages` lets a kind look across at a sibling part or back at what
83
+ * arrived. `unattributed` is the display names the file that arrived writes comments under while
84
+ * recording nobody for them, which is what an entry claiming no identity is held against.
82
85
  */
83
- allowed(entry: Element, original: Element | null, authorId: string, options: PolicyOptions, session: SessionStore, unattributed: ReadonlySet<string>): boolean;
86
+ allowed(entry: Element, original: Element | null, authorId: string, options: PolicyOptions, packages: JudgedPackages, unattributed: ReadonlySet<string>): boolean;
84
87
  }
85
88
  /** The two reasons the package comparison answers with, whatever the policy */
86
89
  export type PackageReason = "part-changed" | "relationship-changed";
@@ -113,6 +116,31 @@ export declare function registerProtectionPolicy<S extends string, P extends str
113
116
  * `readOnly` among them.
114
117
  */
115
118
  export declare function protectionPolicyFor(level: EditingProtection): ProtectionPolicy<string, string> | undefined;
119
+ /** The paths of the policy's parts this package holds, which is what a comparison of its bytes leaves to the policy */
120
+ export declare function policyPartPaths(policy: ProtectionPolicy<string, string>, session: SessionStore): string[];
121
+ /**
122
+ * The main document part with every block of the body taken out of it: the namespaces the story
123
+ * is written under, the text around the body, and the section properties that set the paper and
124
+ * its margins. A comment is written inside a paragraph, so nothing a comment edit writes reaches
125
+ * this text.
126
+ *
127
+ * The section closing the body is read off the document node rather than out of the tail
128
+ * (`docx/sections`), and it belongs here for the same reason the rest does: a submission is free
129
+ * to rewrite the paper it is written on, and a comparison of the blocks would not see it.
130
+ */
131
+ export declare function aroundTheBlocks(story: Story): string;
132
+ /**
133
+ * Which of the policy's declarations two packages differ by: `gained` lets the revised package add
134
+ * them, the way a submission writing its first comment does, and `gained or dropped` also lets it
135
+ * give them up, the way a file that lost its last comment may.
136
+ */
137
+ export type DeclarationChange = "gained" | "gained or dropped";
138
+ /**
139
+ * Whether each of the package's two declaration parts, the main part's relationships and
140
+ * `[Content_Types].xml`, differs between the two packages in nothing but what the policy's parts
141
+ * need, keyed by the part's path.
142
+ */
143
+ export declare function declarationsKept(policy: ProtectionPolicy<string, string>, before: SessionStore, after: SessionStore, allowed: DeclarationChange): ReadonlyMap<string, boolean>;
116
144
  /**
117
145
  * Whether the parts this protection lets an edit rewrite came back holding only entries this
118
146
  * editor writes, each of them one this author was in a position to write.