@portone/docx-editor 0.2.1 → 0.4.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.
- package/CHANGELOG.md +155 -0
- package/CONTRIBUTING.md +5 -1
- package/dist/DocxEditor.d.ts +6 -0
- package/dist/DocxEditor.js +13 -29
- package/dist/core.d.ts +23 -8
- package/dist/core.js +9 -4
- package/dist/docx/cloning.d.ts +38 -0
- package/dist/docx/cloning.js +74 -0
- package/dist/docx/commentOnlyChange.d.ts +12 -7
- package/dist/docx/commentOnlyChange.js +9 -156
- package/dist/docx/comments/constants.d.ts +0 -1
- package/dist/docx/comments/constants.js +0 -2
- package/dist/docx/comments/grammar.d.ts +10 -4
- package/dist/docx/comments/grammar.js +12 -2
- package/dist/docx/comments/{verifying.d.ts → parts.d.ts} +26 -18
- package/dist/docx/comments/parts.js +279 -0
- package/dist/docx/comments/people.d.ts +11 -2
- package/dist/docx/comments/people.js +16 -92
- package/dist/docx/comments/policy.d.ts +7 -0
- package/dist/docx/comments/policy.js +43 -0
- package/dist/docx/comments/reading.js +8 -10
- package/dist/docx/comments/writing.d.ts +19 -7
- package/dist/docx/comments/writing.js +59 -112
- package/dist/docx/documentSettings.d.ts +7 -0
- package/dist/docx/documentSettings.js +10 -2
- package/dist/docx/exportDocx.d.ts +40 -5
- package/dist/docx/exportDocx.js +88 -74
- package/dist/docx/exportRefs.d.ts +5 -2
- package/dist/docx/exportRefs.js +3 -1
- package/dist/docx/fidelity.d.ts +43 -0
- package/dist/docx/fidelity.js +64 -0
- package/dist/docx/formatting/attrs.d.ts +45 -0
- package/dist/docx/formatting/attrs.js +86 -0
- package/dist/docx/formatting/context.d.ts +39 -0
- package/dist/docx/formatting/context.js +60 -0
- package/dist/docx/formatting/direct.d.ts +6 -5
- package/dist/docx/formatting/direct.js +52 -78
- package/dist/docx/formatting/resolve.d.ts +51 -0
- package/dist/docx/formatting/resolve.js +160 -0
- package/dist/docx/formatting/runProperties.d.ts +93 -0
- package/dist/docx/formatting/runProperties.js +316 -0
- package/dist/docx/formatting/styles.d.ts +25 -2
- package/dist/docx/formatting/styles.js +87 -6
- package/dist/docx/formatting/tabStops.js +7 -22
- package/dist/docx/formatting.d.ts +4 -1
- package/dist/docx/formatting.js +4 -1
- package/dist/docx/headersFooters.js +6 -13
- package/dist/docx/hyperlink.d.ts +14 -4
- package/dist/docx/hyperlink.js +4 -1
- package/dist/docx/identities.d.ts +67 -0
- package/dist/docx/identities.js +174 -0
- package/dist/docx/importDocx.d.ts +12 -1
- package/dist/docx/importDocx.js +90 -88
- package/dist/docx/importParagraph.d.ts +1 -1
- package/dist/docx/importParagraph.js +4 -3
- package/dist/docx/importTable.d.ts +2 -2
- package/dist/docx/importTable.js +69 -56
- package/dist/docx/invariants.d.ts +33 -0
- package/dist/docx/invariants.js +269 -0
- package/dist/docx/media.d.ts +6 -4
- package/dist/docx/media.js +6 -37
- package/dist/docx/newLists.d.ts +50 -0
- package/dist/docx/newLists.js +59 -0
- package/dist/docx/notes.js +3 -7
- package/dist/docx/numberingPlanner.d.ts +11 -0
- package/dist/docx/numberingPlanner.js +50 -0
- package/dist/docx/packageParts.d.ts +42 -0
- package/dist/docx/packageParts.js +135 -0
- package/dist/docx/pageGeometry.d.ts +2 -0
- package/dist/docx/pageGeometry.js +18 -9
- package/dist/docx/paraProps.d.ts +10 -22
- package/dist/docx/paraProps.js +47 -76
- package/dist/docx/partPlan.d.ts +36 -0
- package/dist/docx/partPlan.js +59 -0
- package/dist/docx/protectionPolicy.d.ts +127 -0
- package/dist/docx/protectionPolicy.js +169 -0
- package/dist/docx/relationships.d.ts +1 -1
- package/dist/docx/relationships.js +8 -13
- package/dist/docx/runProps.d.ts +9 -22
- package/dist/docx/runProps.js +15 -168
- package/dist/docx/scan.js +20 -52
- package/dist/docx/sdt.js +9 -34
- package/dist/docx/sdtProps.d.ts +8 -1
- package/dist/docx/sdtProps.js +10 -0
- package/dist/docx/serializeBlock.d.ts +2 -0
- package/dist/docx/serializeBlock.js +8 -5
- package/dist/docx/serializeTable.js +32 -15
- package/dist/docx/session.d.ts +42 -14
- package/dist/docx/session.js +53 -17
- package/dist/docx/tableFormatting/conditions.d.ts +76 -0
- package/dist/docx/tableFormatting/conditions.js +196 -0
- package/dist/docx/tableFormatting/editing.d.ts +7 -3
- package/dist/docx/tableFormatting/editing.js +111 -143
- package/dist/docx/tableFormatting/reading.d.ts +63 -23
- package/dist/docx/tableFormatting/reading.js +132 -38
- package/dist/docx/tableFormatting.d.ts +1 -0
- package/dist/docx/tableFormatting.js +1 -0
- package/dist/docx/tableTemplate.js +30 -19
- package/dist/download.d.ts +8 -5
- package/dist/download.js +2 -0
- package/dist/editor/clipboard/inlineFormatting.js +19 -30
- package/dist/editor/commands/comments/editing.d.ts +6 -2
- package/dist/editor/commands/comments/editing.js +19 -31
- package/dist/editor/commands/exportQueries.d.ts +15 -0
- package/dist/editor/commands/exportQueries.js +14 -0
- package/dist/editor/commands/fidelityQueries.d.ts +12 -0
- package/dist/editor/commands/fidelityQueries.js +8 -0
- package/dist/editor/commands/formatting/editing.d.ts +2 -2
- package/dist/editor/commands/formatting/editing.js +26 -108
- package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
- package/dist/editor/commands/formatting/propertyCommands.js +108 -0
- package/dist/editor/commands/formatting/shared.d.ts +3 -3
- package/dist/editor/commands/formatting/shared.js +5 -2
- package/dist/editor/commands/indentCommands.js +5 -4
- package/dist/editor/commands/index.d.ts +11 -0
- package/dist/editor/commands/index.js +5 -0
- package/dist/editor/commands/linkCommands.js +5 -6
- package/dist/editor/commands/listCommands.d.ts +6 -3
- package/dist/editor/commands/listCommands.js +73 -30
- package/dist/editor/commands/lockCommands.d.ts +7 -1
- package/dist/editor/commands/lockCommands.js +35 -46
- package/dist/editor/commands/paragraphCommands.js +33 -31
- package/dist/editor/commands/spacingCommands.js +1 -1
- package/dist/editor/createEditor.d.ts +17 -29
- package/dist/editor/createEditor.js +58 -58
- package/dist/editor/documentStyles.d.ts +11 -35
- package/dist/editor/documentStyles.js +9 -52
- package/dist/editor/editorDocument.d.ts +57 -0
- package/dist/editor/editorDocument.js +86 -0
- package/dist/editor/externalClipboard.d.ts +13 -2
- package/dist/editor/externalClipboard.js +76 -75
- package/dist/editor/insertTable.js +4 -3
- package/dist/editor/paragraphEdits.d.ts +27 -19
- package/dist/editor/paragraphEdits.js +18 -19
- package/dist/editor/paragraphPlacement.d.ts +11 -0
- package/dist/editor/paragraphPlacement.js +18 -0
- package/dist/editor/plugins/displayDerivation.d.ts +47 -0
- package/dist/editor/plugins/displayDerivation.js +78 -0
- package/dist/editor/plugins/imagePaste.js +11 -7
- package/dist/editor/plugins/keymap.js +18 -3
- package/dist/editor/plugins/numberingDecorations.d.ts +14 -14
- package/dist/editor/plugins/numberingDecorations.js +50 -19
- package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
- package/dist/editor/plugins/paragraphDisplay.js +57 -0
- package/dist/editor/plugins/tabLayout.js +1 -1
- package/dist/editor/plugins/tableDisplay.d.ts +6 -0
- package/dist/editor/plugins/tableDisplay.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/model/format.d.ts +80 -8
- package/dist/model/format.js +100 -22
- package/dist/model/tabStops.d.ts +9 -0
- package/dist/model/tabStops.js +18 -0
- package/dist/numbering/listRegistry.d.ts +37 -0
- package/dist/numbering/listRegistry.js +112 -0
- package/dist/numbering/listTemplate.d.ts +26 -17
- package/dist/numbering/listTemplate.js +88 -25
- package/dist/numbering/markers.d.ts +15 -6
- package/dist/numbering/markers.js +26 -59
- package/dist/numbering/parseNumbering.d.ts +84 -6
- package/dist/numbering/parseNumbering.js +131 -44
- package/dist/numbering/spellers.d.ts +15 -0
- package/dist/numbering/spellers.js +96 -0
- package/dist/numbering/writeNumbering.d.ts +8 -7
- package/dist/numbering/writeNumbering.js +28 -39
- package/dist/ooxml/childOrder.d.ts +34 -0
- package/dist/ooxml/childOrder.js +496 -0
- package/dist/ooxml/conformance.d.ts +28 -0
- package/dist/ooxml/conformance.js +20 -0
- package/dist/ooxml/element.d.ts +24 -11
- package/dist/ooxml/element.js +31 -12
- package/dist/ooxml/errors.d.ts +6 -5
- package/dist/ooxml/image.d.ts +4 -0
- package/dist/ooxml/image.js +2 -5
- package/dist/ooxml/names.d.ts +9 -0
- package/dist/ooxml/names.js +8 -1
- package/dist/ooxml/partSplice.d.ts +67 -0
- package/dist/ooxml/partSplice.js +176 -0
- package/dist/ooxml/props.d.ts +112 -0
- package/dist/{docx/propsXml.js → ooxml/props.js} +72 -200
- package/dist/ooxml/simpleTypes.d.ts +103 -0
- package/dist/ooxml/simpleTypes.js +182 -0
- package/dist/ooxml/tabStops.js +8 -27
- package/dist/ooxml/tagScan.d.ts +34 -0
- package/dist/ooxml/tagScan.js +108 -0
- package/dist/ooxml/units.d.ts +25 -13
- package/dist/ooxml/units.js +65 -31
- package/dist/ooxml/xml.d.ts +35 -15
- package/dist/ooxml/xml.js +43 -11
- package/dist/page/PageGuides.d.ts +1 -1
- package/dist/page/PageGuides.js +0 -13
- package/dist/page/blockKinds.d.ts +61 -0
- package/dist/page/blockKinds.js +11 -0
- package/dist/page/kinds/index.d.ts +6 -0
- package/dist/page/kinds/index.js +10 -0
- package/dist/page/kinds/paragraphKind.d.ts +10 -0
- package/dist/page/kinds/paragraphKind.js +71 -0
- package/dist/page/kinds/tableKind.d.ts +10 -0
- package/dist/page/kinds/tableKind.js +178 -0
- package/dist/page/measureBlocks.d.ts +3 -14
- package/dist/page/measureBlocks.js +24 -45
- package/dist/page/pageDecorations.d.ts +27 -44
- package/dist/page/pageDecorations.js +70 -152
- package/dist/page/pageLayout.d.ts +2 -29
- package/dist/page/pageLayout.js +39 -16
- package/dist/page/usePageLayout.d.ts +2 -24
- package/dist/page/usePageLayout.js +5 -48
- package/dist/schema/attrRoles.d.ts +25 -18
- package/dist/schema/attrRoles.js +110 -68
- package/dist/schema/displayDerivation.d.ts +82 -0
- package/dist/schema/displayDerivation.js +130 -0
- package/dist/schema/docxSchema.d.ts +3 -0
- package/dist/schema/docxSchema.js +58 -17
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.d.ts +37 -14
- package/dist/schema/guards.js +29 -3
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/locks.d.ts +11 -44
- package/dist/schema/locks.js +0 -9
- package/dist/schema/preservedGuards.d.ts +26 -6
- package/dist/schema/preservedGuards.js +31 -1
- package/dist/schema/protection.d.ts +7 -1
- package/dist/schema/protection.js +2 -1
- package/dist/schema/sourceEquality.d.ts +1 -9
- package/dist/schema/sourceEquality.js +1 -27
- package/dist/styles/classNames.d.ts +13 -2
- package/dist/styles/classNames.js +13 -2
- package/dist/styles/inlineStyle.js +15 -6
- package/dist/styles.css +16 -18
- package/dist/table/cellFormatting.d.ts +8 -1
- package/dist/table/cellFormatting.js +11 -20
- package/dist/table/commands.js +20 -18
- package/dist/table/format.d.ts +3 -0
- package/dist/table/format.js +3 -9
- package/dist/table/gridBorders.d.ts +24 -30
- package/dist/table/gridBorders.js +35 -59
- package/dist/table/merge.d.ts +2 -6
- package/dist/table/merge.js +5 -5
- package/package.json +7 -3
- package/dist/docx/comments/contentTypes.d.ts +0 -7
- package/dist/docx/comments/contentTypes.js +0 -38
- package/dist/docx/comments/verifying.js +0 -206
- package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
- package/dist/docx/formatting/effectiveParagraph.js +0 -81
- package/dist/docx/propsXml.d.ts +0 -67
- package/dist/docx/uniqueControls.d.ts +0 -14
- package/dist/docx/uniqueControls.js +0 -62
- package/dist/editor/plugins/commentReservations.d.ts +0 -5
- package/dist/editor/plugins/commentReservations.js +0 -26
- package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
- package/dist/editor/plugins/styledParagraphs.js +0 -65
- package/dist/page/tableMeasurements.d.ts +0 -18
- package/dist/page/tableMeasurements.js +0 -119
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// src/docx/comments/verifying.ts
|
|
2
|
-
import {
|
|
3
|
-
attributeByLocalName,
|
|
4
|
-
elementChildren,
|
|
5
|
-
isElement,
|
|
6
|
-
parseXml,
|
|
7
|
-
serializeXml,
|
|
8
|
-
W_NS
|
|
9
|
-
} from "../../ooxml/xml.js";
|
|
10
|
-
import { W14_NS, W15_NS } from "./constants.js";
|
|
11
|
-
import {
|
|
12
|
-
attributesWithin,
|
|
13
|
-
COMMENT_ATTRIBUTES,
|
|
14
|
-
lastBodyParagraph,
|
|
15
|
-
readStrictCommentBody,
|
|
16
|
-
recordedIdentity,
|
|
17
|
-
wellFormedCommentExtension,
|
|
18
|
-
wellFormedPerson
|
|
19
|
-
} from "./grammar.js";
|
|
20
|
-
import { commentReferencesIn } from "./model.js";
|
|
21
|
-
import { commentAuthorId } from "./people.js";
|
|
22
|
-
import { lastParagraphId } from "./reading.js";
|
|
23
|
-
var COMMENT_IDENTITY = [
|
|
24
|
-
"id",
|
|
25
|
-
"author",
|
|
26
|
-
"date",
|
|
27
|
-
"initials"
|
|
28
|
-
];
|
|
29
|
-
function sameAttributes(entry, original, names) {
|
|
30
|
-
return names.every(
|
|
31
|
-
(name) => attributeByLocalName(entry, name) === attributeByLocalName(original, name)
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
function arrivedEntries(xml, localName, idAttr) {
|
|
35
|
-
const entries = /* @__PURE__ */ new Map();
|
|
36
|
-
if (xml === null) return entries;
|
|
37
|
-
for (const el of elementChildren(parseXml(xml).documentElement)) {
|
|
38
|
-
if (el.localName !== localName) continue;
|
|
39
|
-
const id = attributeByLocalName(el, idAttr);
|
|
40
|
-
if (id === null || entries.has(id)) continue;
|
|
41
|
-
entries.set(id, { el, xml: serializeXml(el) });
|
|
42
|
-
}
|
|
43
|
-
return entries;
|
|
44
|
-
}
|
|
45
|
-
function submittedEntries(xml, namespace, localName, idAttr) {
|
|
46
|
-
if (xml === null) return [];
|
|
47
|
-
const entries = [];
|
|
48
|
-
const seen = /* @__PURE__ */ new Set();
|
|
49
|
-
for (const el of elementChildren(parseXml(xml).documentElement)) {
|
|
50
|
-
if (el.namespaceURI !== namespace || el.localName !== localName)
|
|
51
|
-
return null;
|
|
52
|
-
const id = attributeByLocalName(el, idAttr);
|
|
53
|
-
if (id === null || seen.has(id)) return null;
|
|
54
|
-
seen.add(id);
|
|
55
|
-
entries.push({ id, el, xml: serializeXml(el) });
|
|
56
|
-
}
|
|
57
|
-
return entries;
|
|
58
|
-
}
|
|
59
|
-
function referencedCommentIds(doc) {
|
|
60
|
-
const ids = /* @__PURE__ */ new Set();
|
|
61
|
-
for (const [id, comment] of commentReferencesIn(doc)) {
|
|
62
|
-
ids.add(id);
|
|
63
|
-
for (const reply of comment.replies) ids.add(reply.id);
|
|
64
|
-
}
|
|
65
|
-
return ids;
|
|
66
|
-
}
|
|
67
|
-
function wellFormedEntry(entry) {
|
|
68
|
-
if (entry.namespaceURI === W_NS && entry.localName === "comment") {
|
|
69
|
-
return attributesWithin(entry, COMMENT_ATTRIBUTES) && readStrictCommentBody(entry) !== null;
|
|
70
|
-
}
|
|
71
|
-
if (entry.namespaceURI === W15_NS && entry.localName === "commentEx") {
|
|
72
|
-
return wellFormedCommentExtension(entry);
|
|
73
|
-
}
|
|
74
|
-
if (entry.namespaceURI === W15_NS && entry.localName === "person") {
|
|
75
|
-
return wellFormedPerson(entry);
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
function withoutThreadKey(entry) {
|
|
80
|
-
const copy = entry.cloneNode(true);
|
|
81
|
-
if (!isElement(copy)) return serializeXml(entry);
|
|
82
|
-
const last = lastBodyParagraph(copy);
|
|
83
|
-
last?.removeAttributeNS(W14_NS, "paraId");
|
|
84
|
-
return serializeXml(copy);
|
|
85
|
-
}
|
|
86
|
-
function threadKeyAlone(entry, original) {
|
|
87
|
-
const before = lastParagraphId(original);
|
|
88
|
-
const after = lastParagraphId(entry);
|
|
89
|
-
const kept = before === null || after === before;
|
|
90
|
-
return kept && withoutThreadKey(entry) === withoutThreadKey(original);
|
|
91
|
-
}
|
|
92
|
-
function entryAllowed(entry, original, authorId, editableComments, people) {
|
|
93
|
-
if (entry.namespaceURI === W_NS && entry.localName === "comment") {
|
|
94
|
-
const author = attributeByLocalName(entry, "author");
|
|
95
|
-
const recorded = author === null ? null : commentAuthorId(people, author);
|
|
96
|
-
if (original === null) return recorded === authorId;
|
|
97
|
-
const paraId = lastParagraphId(original);
|
|
98
|
-
if (!sameAttributes(entry, original, COMMENT_IDENTITY) || paraId !== null && lastParagraphId(entry) !== paraId) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return editableComments === "all" || recorded === null || recorded === authorId;
|
|
102
|
-
}
|
|
103
|
-
if (entry.namespaceURI === W15_NS && entry.localName === "commentEx") {
|
|
104
|
-
if (original === null) return true;
|
|
105
|
-
return sameAttributes(entry, original, ["paraId", "paraIdParent"]);
|
|
106
|
-
}
|
|
107
|
-
if (entry.namespaceURI === W15_NS && entry.localName === "person") {
|
|
108
|
-
return original === null && recordedIdentity(entry) === authorId;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
function commentEntries(story) {
|
|
113
|
-
return Array.from(
|
|
114
|
-
arrivedEntries(story.session.comments.xml, "comment", "id").values(),
|
|
115
|
-
(entry) => entry.el
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
var COMMENT_PARTS = [
|
|
119
|
-
{
|
|
120
|
-
namespace: W_NS,
|
|
121
|
-
localName: "comment",
|
|
122
|
-
idAttr: "id",
|
|
123
|
-
xmlOf: (story) => story.session.comments.xml,
|
|
124
|
-
pathOf: (story) => story.session.comments.partPath,
|
|
125
|
-
referents: (story) => referencedCommentIds(story.doc)
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
namespace: W15_NS,
|
|
129
|
-
localName: "commentEx",
|
|
130
|
-
idAttr: "paraId",
|
|
131
|
-
xmlOf: (story) => story.session.comments.extendedXml,
|
|
132
|
-
pathOf: (story) => story.session.comments.extendedPartPath,
|
|
133
|
-
// Thread state stands for a comment, and it is keyed by the comment's own thread key
|
|
134
|
-
referents: (story) => new Set(
|
|
135
|
-
commentEntries(story).flatMap((el) => {
|
|
136
|
-
const key = lastParagraphId(el);
|
|
137
|
-
return key === null ? [] : [key];
|
|
138
|
-
})
|
|
139
|
-
)
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
namespace: W15_NS,
|
|
143
|
-
localName: "person",
|
|
144
|
-
idAttr: "author",
|
|
145
|
-
xmlOf: (story) => story.session.comments.people.xml,
|
|
146
|
-
pathOf: (story) => story.session.comments.people.partPath,
|
|
147
|
-
// An identity stands for a name somebody writes comments under
|
|
148
|
-
referents: (story) => new Set(
|
|
149
|
-
commentEntries(story).flatMap((el) => {
|
|
150
|
-
const author = attributeByLocalName(el, "author");
|
|
151
|
-
return author === null ? [] : [author];
|
|
152
|
-
})
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
];
|
|
156
|
-
function partKept(kind, before, after, authorId, editableComments) {
|
|
157
|
-
const arrived = arrivedEntries(
|
|
158
|
-
kind.xmlOf(before),
|
|
159
|
-
kind.localName,
|
|
160
|
-
kind.idAttr
|
|
161
|
-
);
|
|
162
|
-
const submitted = submittedEntries(
|
|
163
|
-
kind.xmlOf(after),
|
|
164
|
-
kind.namespace,
|
|
165
|
-
kind.localName,
|
|
166
|
-
kind.idAttr
|
|
167
|
-
);
|
|
168
|
-
if (submitted === null) return false;
|
|
169
|
-
const stoodBehindNow = kind.referents(after);
|
|
170
|
-
const people = after.session.comments.people;
|
|
171
|
-
for (const entry of submitted) {
|
|
172
|
-
const original = arrived.get(entry.id);
|
|
173
|
-
if (original && original.xml === entry.xml) continue;
|
|
174
|
-
if (!stoodBehindNow.has(entry.id)) return false;
|
|
175
|
-
if (original && threadKeyAlone(entry.el, original.el)) continue;
|
|
176
|
-
if (!wellFormedEntry(entry.el) || !entryAllowed(
|
|
177
|
-
entry.el,
|
|
178
|
-
original?.el ?? null,
|
|
179
|
-
authorId,
|
|
180
|
-
editableComments,
|
|
181
|
-
people
|
|
182
|
-
)) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const held = new Set(submitted.map((entry) => entry.id));
|
|
187
|
-
const stoodBehindBefore = kind.referents(before);
|
|
188
|
-
return Array.from(arrived.keys()).every(
|
|
189
|
-
(id) => stoodBehindBefore.has(id) || held.has(id)
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
function commentPartsKept(before, after, authorId, editableComments) {
|
|
193
|
-
for (const kind of COMMENT_PARTS) {
|
|
194
|
-
const path = kind.pathOf(after) ?? kind.pathOf(before);
|
|
195
|
-
if (path === null) continue;
|
|
196
|
-
if (!partKept(kind, before, after, authorId, editableComments)) {
|
|
197
|
-
return { ok: false, reason: "part-changed", part: path };
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return { ok: true };
|
|
201
|
-
}
|
|
202
|
-
export {
|
|
203
|
-
commentPartsKept,
|
|
204
|
-
entryAllowed,
|
|
205
|
-
wellFormedEntry
|
|
206
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ParagraphFormat } from "../../model/format";
|
|
2
|
-
import { type Numbering } from "../../numbering/parseNumbering";
|
|
3
|
-
import { type StyleFormat, type StyleTable } from "./styles";
|
|
4
|
-
import { type ParagraphFormatLayer } from "./tabStops";
|
|
5
|
-
export interface ParagraphFormattingContext {
|
|
6
|
-
styles: StyleTable;
|
|
7
|
-
defaultStyleId: string | null;
|
|
8
|
-
defaults: ParagraphFormatLayer;
|
|
9
|
-
numbering: Numbering;
|
|
10
|
-
}
|
|
11
|
-
export declare const NO_PARAGRAPH_FORMATTING: ParagraphFormattingContext;
|
|
12
|
-
/** Resolves the effective OOXML paragraph-property hierarchy for display. */
|
|
13
|
-
export declare function effectiveParagraphFormat(pPr: unknown, context: ParagraphFormattingContext): ParagraphFormat | null;
|
|
14
|
-
/** Resolves the run properties supplied by the paragraph style. */
|
|
15
|
-
export declare function effectiveParagraphStyle(pPr: unknown, context: ParagraphFormattingContext): StyleFormat | undefined;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// src/docx/formatting/effectiveParagraph.ts
|
|
2
|
-
import { toParagraphFormat } from "../../model/format.js";
|
|
3
|
-
import { mergeTabStops } from "../../model/tabStops.js";
|
|
4
|
-
import {
|
|
5
|
-
EMPTY_NUMBERING,
|
|
6
|
-
levelIndentPt
|
|
7
|
-
} from "../../numbering/parseNumbering.js";
|
|
8
|
-
import { parsePropsXml } from "../propsXml.js";
|
|
9
|
-
import { readParagraphFormat } from "./direct.js";
|
|
10
|
-
import {
|
|
11
|
-
paragraphStyleFormat
|
|
12
|
-
} from "./styles.js";
|
|
13
|
-
import { layerParagraphValues } from "./tabStops.js";
|
|
14
|
-
var NO_PARAGRAPH_FORMATTING = {
|
|
15
|
-
styles: /* @__PURE__ */ new Map(),
|
|
16
|
-
defaultStyleId: null,
|
|
17
|
-
defaults: {},
|
|
18
|
-
numbering: EMPTY_NUMBERING
|
|
19
|
-
};
|
|
20
|
-
function numberingRef(defaults, style, direct) {
|
|
21
|
-
let value = defaults.numbering;
|
|
22
|
-
if (style.numbering !== void 0) value = style.numbering;
|
|
23
|
-
if (direct.numbering !== void 0) value = direct.numbering;
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
function numberingLayer(ref, numbering) {
|
|
27
|
-
if (!ref) return {};
|
|
28
|
-
const level = numbering.lists.get(ref.numId)?.levels.get(ref.ilvl);
|
|
29
|
-
if (!level) return {};
|
|
30
|
-
const indent = levelIndentPt(level.indent);
|
|
31
|
-
const leadingIndentPt = indent.startPt;
|
|
32
|
-
const implicitHangingStop = leadingIndentPt !== null && indent.textIndentPt !== null && indent.textIndentPt < 0 ? [{ positionPt: leadingIndentPt, align: "start" }] : [];
|
|
33
|
-
return {
|
|
34
|
-
tabStops: [...implicitHangingStop, ...level.tabStops ?? []]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function withImplicitHangingStop(format) {
|
|
38
|
-
const leadingIndentPt = format?.indentStartPt ?? format?.indentLeftPt;
|
|
39
|
-
if (format?.textIndentPt === void 0 || format.textIndentPt >= 0 || leadingIndentPt === void 0) {
|
|
40
|
-
return format;
|
|
41
|
-
}
|
|
42
|
-
const implicit = {
|
|
43
|
-
positionPt: leadingIndentPt,
|
|
44
|
-
align: "start"
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
...format,
|
|
48
|
-
tabStops: mergeTabStops([implicit], format.tabStops ?? [])
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function directLayer(pPr) {
|
|
52
|
-
if (typeof pPr !== "string") return {};
|
|
53
|
-
return readParagraphFormat(parsePropsXml(pPr)) ?? {};
|
|
54
|
-
}
|
|
55
|
-
function styleFor(pPr, context) {
|
|
56
|
-
return paragraphStyleFormat(pPr, context.styles, context.defaultStyleId);
|
|
57
|
-
}
|
|
58
|
-
function effectiveParagraphFormat(pPr, context) {
|
|
59
|
-
const direct = directLayer(pPr);
|
|
60
|
-
const style = styleFor(pPr, context)?.paragraph ?? {};
|
|
61
|
-
const level = numberingLayer(
|
|
62
|
-
numberingRef(context.defaults, style, direct),
|
|
63
|
-
context.numbering
|
|
64
|
-
);
|
|
65
|
-
const layered = [level, style, direct].reduce(
|
|
66
|
-
layerParagraphValues,
|
|
67
|
-
context.defaults
|
|
68
|
-
);
|
|
69
|
-
const format = toParagraphFormat(layered);
|
|
70
|
-
return withImplicitHangingStop(
|
|
71
|
-
format !== null && Object.keys(format).length === 0 ? null : format
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
function effectiveParagraphStyle(pPr, context) {
|
|
75
|
-
return styleFor(pPr, context);
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
NO_PARAGRAPH_FORMATTING,
|
|
79
|
-
effectiveParagraphFormat,
|
|
80
|
-
effectiveParagraphStyle
|
|
81
|
-
};
|
package/dist/docx/propsXml.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handles the XML fragments that carry formatting, such as `<w:rPr>`, `<w:pPr>`, and `<w:tcPr>`.
|
|
3
|
-
*
|
|
4
|
-
* A fragment is never rebuilt: only the one child a job names is sliced out and swapped, so the
|
|
5
|
-
* rest (borders, shading, margins) stays as the original text wrote it. OOXML lays down the order
|
|
6
|
-
* of the children, so the spot to insert a child that was not there is found by that same order.
|
|
7
|
-
*/
|
|
8
|
-
export interface PropsChild {
|
|
9
|
-
/** The name with its namespace prefix stripped off (e.g. `gridSpan`) */
|
|
10
|
-
name: string;
|
|
11
|
-
/** This child's original XML fragment exactly as it was */
|
|
12
|
-
xml: string;
|
|
13
|
-
/**
|
|
14
|
-
* Whatever stood between the child before this one and this one: line breaks a producer laid
|
|
15
|
-
* out, comments, anything that is not an element. Carried so that rewriting one child does not
|
|
16
|
-
* quietly drop the rest of what the fragment said. Absent rather than empty when nothing did.
|
|
17
|
-
*/
|
|
18
|
-
before?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface Props {
|
|
21
|
-
/** The opening tag name exactly as written (e.g. `w:tcPr`) */
|
|
22
|
-
tag: string;
|
|
23
|
-
attrs: string | null;
|
|
24
|
-
children: PropsChild[];
|
|
25
|
-
/** The same, for what stood between the last child and the closing tag */
|
|
26
|
-
tail?: string;
|
|
27
|
-
}
|
|
28
|
-
/** The order the children are laid out in under `w:rPr` (CT_RPr) */
|
|
29
|
-
export declare const RUN_PR_ORDER: readonly string[];
|
|
30
|
-
/** The order the children are laid out in under `w:pPr` (CT_PPr) */
|
|
31
|
-
export declare const P_PR_ORDER: readonly string[];
|
|
32
|
-
/** The order the children are laid out in under `w:tcPr` (CT_TcPr) */
|
|
33
|
-
export declare const TC_PR_ORDER: readonly string[];
|
|
34
|
-
/** The conventional order of children under `w:trPr` (CT_TrPr). */
|
|
35
|
-
export declare const TR_PR_ORDER: readonly string[];
|
|
36
|
-
/** The order the children are laid out in under `w:tblPr` (CT_TblPr) */
|
|
37
|
-
export declare const TBL_PR_ORDER: readonly string[];
|
|
38
|
-
/**
|
|
39
|
-
* What stood inside a single element, and "" for one that stood empty or cannot be made out.
|
|
40
|
-
*
|
|
41
|
-
* The opening tag is read rather than scanned for, so a `>` inside an attribute value does not
|
|
42
|
-
* pass for the end of it.
|
|
43
|
-
*/
|
|
44
|
-
export declare function innerXml(xml: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* Splits a formatting fragment into its opening tag and its list of children.
|
|
47
|
-
* null if its shape cannot be made out (in which case leaving the original untouched is the safe move).
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseProps(xml: string): Props | null;
|
|
50
|
-
/**
|
|
51
|
-
* With nothing to say, the formatting fragment itself is not written. A fragment holding only
|
|
52
|
-
* whitespace says nothing; one holding a comment does, so it is written back.
|
|
53
|
-
*/
|
|
54
|
-
export declare function renderProps(props: Props): string;
|
|
55
|
-
/**
|
|
56
|
-
* Replaces a single child with new XML.
|
|
57
|
-
* A null `xml` removes that child. A child that was not there goes into the spot the order calls for.
|
|
58
|
-
*/
|
|
59
|
-
export declare function setPropsChild(props: Props, name: string, xml: string | null, order: readonly string[]): Props;
|
|
60
|
-
export declare function propsChild(children: PropsChild[], name: string): PropsChild | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* Reads a single formatting fragment into an element.
|
|
63
|
-
*
|
|
64
|
-
* A fragment carries no namespace declarations, so they are put back on as it is wrapped.
|
|
65
|
-
* null if its shape cannot be made out, in which case the caller leaves the display values alone.
|
|
66
|
-
*/
|
|
67
|
-
export declare function parsePropsXml(xml: string): Element | null;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Keeping one content control from going out twice under the same name.
|
|
3
|
-
*
|
|
4
|
-
* A control cannot cross a paragraph, so splitting a paragraph in the middle of one leaves that
|
|
5
|
-
* same control standing in two, and dropping unmarked text into the middle of one breaks it in
|
|
6
|
-
* two within the paragraph. Each piece then writes a `w:sdt` of its own (see `docx/sdt` for what
|
|
7
|
-
* a copy must not carry along).
|
|
8
|
-
*
|
|
9
|
-
* A document nobody broke apart comes back node for node as it was, which is what keeps an
|
|
10
|
-
* unedited block going out as its original XML.
|
|
11
|
-
*/
|
|
12
|
-
import { type Node as PMNode } from "prosemirror-model";
|
|
13
|
-
/** The document with every copy of a control opening under a name of its own */
|
|
14
|
-
export declare function withUniqueControls(doc: PMNode): PMNode;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/docx/uniqueControls.ts
|
|
2
|
-
import { Fragment } from "prosemirror-model";
|
|
3
|
-
import { docxSchema } from "../schema/index.js";
|
|
4
|
-
import { copiedControlPrefix, newControlId } from "./sdt.js";
|
|
5
|
-
function sdtMarkOf(node) {
|
|
6
|
-
return node.marks.find((mark) => mark.type === docxSchema.marks.sdt) ?? null;
|
|
7
|
-
}
|
|
8
|
-
function controlName(mark) {
|
|
9
|
-
const key = mark.attrs.sdtKey;
|
|
10
|
-
const prefix = mark.attrs.sdtPrefix;
|
|
11
|
-
return `${typeof key === "number" ? key : 0} ${typeof prefix === "string" ? prefix : ""}`;
|
|
12
|
-
}
|
|
13
|
-
function copiedMark(mark) {
|
|
14
|
-
const prefix = mark.attrs.sdtPrefix;
|
|
15
|
-
if (typeof prefix !== "string") return mark;
|
|
16
|
-
return mark.type.create({
|
|
17
|
-
...mark.attrs,
|
|
18
|
-
sdtPrefix: copiedControlPrefix(prefix, newControlId())
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function claim(mark, written) {
|
|
22
|
-
const name = controlName(mark);
|
|
23
|
-
const copy = written.has(name) ? copiedMark(mark) : null;
|
|
24
|
-
written.add(name);
|
|
25
|
-
return { mark, copy };
|
|
26
|
-
}
|
|
27
|
-
function rewriteParagraph(paragraph, written) {
|
|
28
|
-
const inline = [];
|
|
29
|
-
let running = null;
|
|
30
|
-
let renamed = false;
|
|
31
|
-
paragraph.forEach((child) => {
|
|
32
|
-
const mark = sdtMarkOf(child);
|
|
33
|
-
if (!mark) {
|
|
34
|
-
running = null;
|
|
35
|
-
inline.push(child);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const control = running?.mark.eq(mark) ? running : claim(mark, written);
|
|
39
|
-
running = control;
|
|
40
|
-
if (!control.copy) {
|
|
41
|
-
inline.push(child);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
renamed = true;
|
|
45
|
-
inline.push(
|
|
46
|
-
child.mark(control.copy.addToSet(mark.removeFromSet(child.marks)))
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
return renamed ? paragraph.copy(Fragment.fromArray(inline)) : paragraph;
|
|
50
|
-
}
|
|
51
|
-
function rewriteBlock(node, written) {
|
|
52
|
-
if (node.type.name === "paragraph") return rewriteParagraph(node, written);
|
|
53
|
-
if (node.childCount === 0) return node;
|
|
54
|
-
const children = node.children.map((child) => rewriteBlock(child, written));
|
|
55
|
-
return children.every((child, index) => child === node.child(index)) ? node : node.copy(Fragment.fromArray(children));
|
|
56
|
-
}
|
|
57
|
-
function withUniqueControls(doc) {
|
|
58
|
-
return rewriteBlock(doc, /* @__PURE__ */ new Set());
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
61
|
-
withUniqueControls
|
|
62
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** Keeps identifiers from the opened Comments parts reserved for the lifetime of the editor state. */
|
|
2
|
-
import { type EditorState, Plugin } from "prosemirror-state";
|
|
3
|
-
export declare function commentReservations(ids: Iterable<string>, paraIds: Iterable<string>): Plugin;
|
|
4
|
-
export declare function reservedCommentIds(state: EditorState): ReadonlySet<string>;
|
|
5
|
-
export declare function reservedCommentParaIds(state: EditorState): ReadonlySet<string>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/editor/plugins/commentReservations.ts
|
|
2
|
-
import { Plugin, PluginKey } from "prosemirror-state";
|
|
3
|
-
var commentReservationsKey = new PluginKey(
|
|
4
|
-
"docxCommentReservations"
|
|
5
|
-
);
|
|
6
|
-
function commentReservations(ids, paraIds) {
|
|
7
|
-
const reserved = { ids: new Set(ids), paraIds: new Set(paraIds) };
|
|
8
|
-
return new Plugin({
|
|
9
|
-
key: commentReservationsKey,
|
|
10
|
-
state: {
|
|
11
|
-
init: () => reserved,
|
|
12
|
-
apply: (_transaction, value) => value
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function reservedCommentIds(state) {
|
|
17
|
-
return commentReservationsKey.getState(state)?.ids ?? /* @__PURE__ */ new Set();
|
|
18
|
-
}
|
|
19
|
-
function reservedCommentParaIds(state) {
|
|
20
|
-
return commentReservationsKey.getState(state)?.paraIds ?? /* @__PURE__ */ new Set();
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
commentReservations,
|
|
24
|
-
reservedCommentIds,
|
|
25
|
-
reservedCommentParaIds
|
|
26
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies inherited style display values to paragraphs created in the editor. The paragraph under
|
|
3
|
-
* active IME composition is deferred to avoid redrawing and canceling the composition.
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin } from "prosemirror-state";
|
|
6
|
-
/**
|
|
7
|
-
* Reads the document's styles into the paragraphs an edit built.
|
|
8
|
-
*
|
|
9
|
-
* No transaction of its own goes to the history: ProseMirror hands an appended transaction to the
|
|
10
|
-
* history as part of the same event, so a single undo takes the edit and these values back together.
|
|
11
|
-
*
|
|
12
|
-
* An appended transaction is handed nothing but states, so the view an open composition is read
|
|
13
|
-
* from is the one the plugin is given when it mounts.
|
|
14
|
-
*/
|
|
15
|
-
export declare function styledParagraphs(): Plugin;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/editor/plugins/styledParagraphs.ts
|
|
2
|
-
import { Plugin } from "prosemirror-state";
|
|
3
|
-
import {
|
|
4
|
-
effectiveParagraphFormat,
|
|
5
|
-
effectiveParagraphStyle,
|
|
6
|
-
layerRunFormat
|
|
7
|
-
} from "../../docx/formatting.js";
|
|
8
|
-
import { docxSchema } from "../../schema/index.js";
|
|
9
|
-
import { documentParagraphFormatting } from "../documentStyles.js";
|
|
10
|
-
function needsFormatting(node) {
|
|
11
|
-
return node.attrs.format === null && node.attrs.styleRun === null;
|
|
12
|
-
}
|
|
13
|
-
function paragraphSpots(doc) {
|
|
14
|
-
const found = [];
|
|
15
|
-
doc.descendants((node, pos) => {
|
|
16
|
-
if (node.type !== docxSchema.nodes.paragraph) return true;
|
|
17
|
-
if (needsFormatting(node)) found.push({ pos, node });
|
|
18
|
-
return false;
|
|
19
|
-
});
|
|
20
|
-
return found;
|
|
21
|
-
}
|
|
22
|
-
function styledAttrs(node, state) {
|
|
23
|
-
const context = documentParagraphFormatting(state);
|
|
24
|
-
const style = effectiveParagraphStyle(node.attrs.pPr, context);
|
|
25
|
-
const format = effectiveParagraphFormat(node.attrs.pPr, context);
|
|
26
|
-
const styleRun = style ? layerRunFormat(style.run, null) : null;
|
|
27
|
-
return { ...node.attrs, format, styleRun };
|
|
28
|
-
}
|
|
29
|
-
function composingAt(view, state) {
|
|
30
|
-
return view?.composing === true ? state.selection.from : null;
|
|
31
|
-
}
|
|
32
|
-
function holdsComposition(paragraph, composing) {
|
|
33
|
-
return composing !== null && composing >= paragraph.pos && composing <= paragraph.pos + paragraph.node.nodeSize;
|
|
34
|
-
}
|
|
35
|
-
function styledParagraphs() {
|
|
36
|
-
let live = null;
|
|
37
|
-
return new Plugin({
|
|
38
|
-
view(view) {
|
|
39
|
-
live = view;
|
|
40
|
-
return {
|
|
41
|
-
destroy() {
|
|
42
|
-
live = null;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
appendTransaction(transactions, _oldState, newState) {
|
|
47
|
-
if (!transactions.some((transaction) => transaction.docChanged)) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
const composing = composingAt(live, newState);
|
|
51
|
-
const tr = newState.tr;
|
|
52
|
-
for (const paragraph of paragraphSpots(newState.doc)) {
|
|
53
|
-
if (holdsComposition(paragraph, composing)) continue;
|
|
54
|
-
const attrs = styledAttrs(paragraph.node, newState);
|
|
55
|
-
if (!paragraph.node.hasMarkup(paragraph.node.type, attrs)) {
|
|
56
|
-
tr.setNodeMarkup(paragraph.pos, null, attrs);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return tr.docChanged ? tr : null;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
styledParagraphs
|
|
65
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Measures safe row boundaries without treating pagination decorations as document content. */
|
|
2
|
-
import type { Node as PMNode } from "prosemirror-model";
|
|
3
|
-
import type { EditorView } from "prosemirror-view";
|
|
4
|
-
import type { BreakCandidate } from "./blockKinds";
|
|
5
|
-
export interface TableMeasure {
|
|
6
|
-
/** Every row that may start the continued part of the table */
|
|
7
|
-
candidates: readonly BreakCandidate[];
|
|
8
|
-
/** The smallest useful first piece: headers followed by one body row group */
|
|
9
|
-
minFirstPiece: number;
|
|
10
|
-
/** Height already added by the previous pagination pass */
|
|
11
|
-
appliedHeight: number;
|
|
12
|
-
/** Document positions of the contiguous header rows at the start of the table */
|
|
13
|
-
headerRows: readonly number[];
|
|
14
|
-
/** Changes when any projected header content or formatting changes */
|
|
15
|
-
headerSignature: string;
|
|
16
|
-
columns: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function measureTable(view: EditorView, tableNode: PMNode, tablePos: number, tableDom: HTMLElement, scale?: number): TableMeasure | null;
|