@portone/docx-editor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +174 -0
- package/CONTRIBUTING.md +9 -1
- package/dist/DocxEditor.d.ts +6 -0
- package/dist/DocxEditor.js +12 -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 +14 -7
- package/dist/docx/commentOnlyChange.js +9 -139
- package/dist/docx/comments/constants.d.ts +3 -4
- package/dist/docx/comments/constants.js +4 -5
- package/dist/docx/comments/grammar.d.ts +86 -0
- package/dist/docx/comments/grammar.js +223 -0
- package/dist/docx/comments/parts.d.ts +52 -0
- package/dist/docx/comments/parts.js +279 -0
- package/dist/docx/comments/people.d.ts +11 -2
- package/dist/docx/comments/people.js +28 -106
- package/dist/docx/comments/policy.d.ts +7 -0
- package/dist/docx/comments/policy.js +43 -0
- package/dist/docx/comments/reading.d.ts +5 -3
- package/dist/docx/comments/reading.js +30 -29
- package/dist/docx/comments/writing.d.ts +19 -7
- package/dist/docx/comments/writing.js +105 -137
- 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 +71 -72
- 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 +27 -0
- package/dist/docx/formatting/attrs.js +31 -0
- package/dist/docx/formatting/context.d.ts +31 -0
- package/dist/docx/formatting/context.js +42 -0
- package/dist/docx/formatting/direct.d.ts +6 -5
- package/dist/docx/formatting/direct.js +52 -81
- package/dist/docx/formatting/resolve.d.ts +45 -0
- package/dist/docx/formatting/resolve.js +140 -0
- package/dist/docx/formatting/runProperties.d.ts +93 -0
- package/dist/docx/formatting/runProperties.js +316 -0
- package/dist/docx/formatting/styles.js +3 -3
- 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 +13 -22
- 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 +72 -79
- package/dist/docx/importParagraph.d.ts +1 -1
- package/dist/docx/importParagraph.js +4 -3
- package/dist/docx/importTable.d.ts +1 -1
- package/dist/docx/importTable.js +17 -1
- package/dist/docx/invariants.d.ts +33 -0
- package/dist/docx/invariants.js +256 -0
- package/dist/docx/media.d.ts +6 -4
- package/dist/docx/media.js +6 -37
- package/dist/docx/newLists.d.ts +20 -0
- package/dist/docx/newLists.js +36 -0
- package/dist/docx/notes.js +6 -12
- package/dist/docx/numberingPlanner.d.ts +8 -0
- package/dist/docx/numberingPlanner.js +19 -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 +75 -99
- 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 +15 -15
- 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 +14 -37
- 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 +9 -7
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +25 -14
- package/dist/docx/serializeTable.js +63 -32
- package/dist/docx/session.d.ts +42 -14
- package/dist/docx/session.js +43 -17
- package/dist/docx/storyProjection.d.ts +36 -0
- package/dist/docx/storyProjection.js +23 -0
- package/dist/docx/tableFormatting/editing.js +130 -185
- package/dist/docx/tableFormatting/reading.d.ts +16 -6
- package/dist/docx/tableFormatting/reading.js +40 -20
- package/dist/docx/tableTemplate.js +37 -5
- package/dist/docx/theme.d.ts +0 -6
- package/dist/docx/theme.js +0 -8
- package/dist/download.d.ts +8 -5
- package/dist/download.js +2 -0
- package/dist/editor/clipboard/images.js +17 -3
- package/dist/editor/clipboard/inlineFormatting.d.ts +7 -0
- package/dist/editor/clipboard/inlineFormatting.js +20 -30
- package/dist/editor/commands/breakCommands.js +4 -3
- package/dist/editor/commands/canRunCommand.d.ts +2 -2
- package/dist/editor/commands/canRunCommand.js +1 -1
- package/dist/editor/commands/comments/editing.d.ts +6 -2
- package/dist/editor/commands/comments/editing.js +21 -36
- 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 +103 -0
- package/dist/editor/commands/formatting/shared.d.ts +3 -3
- package/dist/editor/commands/formatting/shared.js +5 -2
- package/dist/editor/commands/historyCommands.js +2 -1
- 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.js +8 -10
- package/dist/editor/commands/lockCommands.d.ts +7 -1
- package/dist/editor/commands/lockCommands.js +35 -37
- package/dist/editor/commands/paragraphCommands.js +28 -31
- package/dist/editor/commands/spacingCommands.js +1 -1
- package/dist/editor/commands/tabCommands.js +4 -3
- package/dist/editor/createEditor.d.ts +17 -29
- package/dist/editor/createEditor.js +61 -67
- package/dist/editor/documentStyles.d.ts +11 -35
- package/dist/editor/documentStyles.js +9 -52
- package/dist/editor/editorDocument.d.ts +56 -0
- package/dist/editor/editorDocument.js +74 -0
- package/dist/editor/externalClipboard.js +166 -33
- package/dist/editor/insertImage.js +4 -3
- package/dist/editor/insertTable.js +4 -3
- package/dist/editor/paragraphEdits.d.ts +11 -18
- package/dist/editor/paragraphEdits.js +7 -16
- package/dist/editor/plugins/displayDerivation.d.ts +47 -0
- package/dist/editor/plugins/displayDerivation.js +78 -0
- package/dist/editor/plugins/documentProtection.d.ts +3 -3
- package/dist/editor/plugins/imagePaste.js +4 -3
- package/dist/editor/plugins/keymap.js +18 -3
- package/dist/editor/plugins/lockedContent.d.ts +4 -4
- package/dist/editor/plugins/lockedContent.js +1 -1
- package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
- package/dist/editor/plugins/numberingDecorations.js +7 -17
- package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
- package/dist/editor/plugins/paragraphDisplay.js +51 -0
- package/dist/editor/plugins/tabLayout.js +1 -1
- package/dist/editor/plugins/tableDisplay.d.ts +6 -0
- package/dist/editor/plugins/tableDisplay.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/model/format.d.ts +30 -8
- package/dist/model/format.js +35 -22
- package/dist/model/tabStops.d.ts +9 -0
- package/dist/model/tabStops.js +18 -0
- package/dist/numbering/listTemplate.js +49 -10
- package/dist/numbering/parseNumbering.d.ts +14 -1
- package/dist/numbering/parseNumbering.js +35 -22
- package/dist/numbering/writeNumbering.d.ts +3 -4
- package/dist/numbering/writeNumbering.js +14 -25
- package/dist/ooxml/childOrder.d.ts +34 -0
- package/dist/ooxml/childOrder.js +496 -0
- package/dist/ooxml/element.d.ts +65 -0
- package/dist/ooxml/element.js +68 -0
- package/dist/ooxml/errors.d.ts +3 -2
- package/dist/ooxml/fragment.d.ts +53 -0
- package/dist/ooxml/fragment.js +76 -0
- package/dist/ooxml/image.d.ts +4 -0
- package/dist/ooxml/image.js +3 -5
- package/dist/ooxml/names.d.ts +27 -0
- package/dist/ooxml/names.js +29 -0
- package/dist/ooxml/partSplice.d.ts +67 -0
- package/dist/ooxml/partSplice.js +169 -0
- package/dist/ooxml/precedence.d.ts +31 -0
- package/dist/ooxml/precedence.js +51 -0
- package/dist/ooxml/props.d.ts +112 -0
- package/dist/ooxml/props.js +214 -0
- 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 +52 -0
- package/dist/ooxml/xml.js +64 -5
- package/dist/page/blockKinds.d.ts +103 -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 -1
- package/dist/page/measureBlocks.js +24 -25
- package/dist/page/pageDecorations.d.ts +27 -28
- package/dist/page/pageDecorations.js +70 -151
- package/dist/page/pageLayout.d.ts +10 -62
- package/dist/page/pageLayout.js +60 -53
- package/dist/page/usePageLayout.d.ts +2 -2
- package/dist/page/usePageLayout.js +3 -11
- package/dist/schema/attrRoles.d.ts +42 -0
- package/dist/schema/attrRoles.js +141 -0
- package/dist/schema/displayDerivation.d.ts +82 -0
- package/dist/schema/displayDerivation.js +130 -0
- package/dist/schema/docxSchema.d.ts +9 -0
- package/dist/schema/docxSchema.js +237 -114
- package/dist/schema/editGuard.d.ts +99 -0
- package/dist/schema/editGuard.js +43 -0
- package/dist/schema/guards.d.ts +91 -0
- package/dist/schema/guards.js +108 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/locks.d.ts +17 -77
- package/dist/schema/locks.js +26 -70
- package/dist/schema/preservedGuards.d.ts +50 -0
- package/dist/schema/preservedGuards.js +80 -0
- package/dist/schema/protection.d.ts +17 -4
- package/dist/schema/protection.js +4 -2
- package/dist/schema/sourceEquality.d.ts +19 -0
- package/dist/schema/sourceEquality.js +39 -0
- package/dist/styles/inlineStyle.js +15 -6
- package/dist/table/cellFormatting.d.ts +8 -1
- package/dist/table/cellFormatting.js +10 -17
- package/dist/table/commands.d.ts +2 -2
- 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 +14 -16
- package/dist/table/gridBorders.js +3 -41
- package/dist/table/index.d.ts +2 -2
- package/dist/table/merge.d.ts +4 -8
- package/dist/table/merge.js +5 -5
- package/package.json +10 -3
- package/dist/docx/comments/contentTypes.d.ts +0 -7
- package/dist/docx/comments/contentTypes.js +0 -38
- package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
- package/dist/docx/formatting/effectiveParagraph.js +0 -81
- package/dist/docx/propsXml.d.ts +0 -49
- package/dist/docx/propsXml.js +0 -302
- package/dist/docx/uniqueControls.d.ts +0 -14
- package/dist/docx/uniqueControls.js +0 -62
- package/dist/editor/plugins/bookmarkProtection.d.ts +0 -3
- package/dist/editor/plugins/bookmarkProtection.js +0 -28
- package/dist/editor/plugins/commentReservations.d.ts +0 -5
- package/dist/editor/plugins/commentReservations.js +0 -26
- package/dist/editor/plugins/noteProtection.d.ts +0 -3
- package/dist/editor/plugins/noteProtection.js +0 -25
- package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
- package/dist/editor/plugins/styledParagraphs.js +0 -65
- package/dist/page/tableMeasurements.d.ts +0 -10
- package/dist/page/tableMeasurements.js +0 -115
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
// src/docx/tableFormatting/reading.ts
|
|
2
|
+
import { parsePropsXml } from "../../ooxml/props.js";
|
|
3
|
+
import {
|
|
4
|
+
ST_MeasurementOrPercent,
|
|
5
|
+
ST_SignedTwipsMeasure,
|
|
6
|
+
ST_TwipsMeasure
|
|
7
|
+
} from "../../ooxml/simpleTypes.js";
|
|
2
8
|
import {
|
|
3
9
|
ALIGN_BY_JC,
|
|
10
|
+
borderLineCss,
|
|
11
|
+
borderLineOfCss,
|
|
4
12
|
borderSide,
|
|
5
13
|
childValue,
|
|
6
14
|
isOn,
|
|
7
15
|
shadingOf,
|
|
8
|
-
toNumber,
|
|
9
16
|
twipsToPt,
|
|
10
17
|
wAttr
|
|
11
18
|
} from "../../ooxml/units.js";
|
|
12
19
|
import { childByLocalName } from "../../ooxml/xml.js";
|
|
13
|
-
|
|
20
|
+
var FIFTIETHS_PER_PERCENT = 50;
|
|
14
21
|
function readTableWidth(parent, name) {
|
|
15
22
|
const el = parent ? childByLocalName(parent, name) : null;
|
|
16
23
|
if (!el) return null;
|
|
17
24
|
const type = wAttr(el, "type") ?? "dxa";
|
|
25
|
+
const width = ST_MeasurementOrPercent.parse(wAttr(el, "w"));
|
|
26
|
+
if (width?.kind === "percent") {
|
|
27
|
+
const fiftieths = Math.round(width.value * FIFTIETHS_PER_PERCENT);
|
|
28
|
+
return Number.isFinite(fiftieths) ? { type: "pct", fiftieths } : null;
|
|
29
|
+
}
|
|
18
30
|
if (type === "auto") return { type: "auto" };
|
|
19
31
|
if (type === "nil") return { type: "nil" };
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
if (width === null) return null;
|
|
33
|
+
if (type === "dxa") {
|
|
34
|
+
return { type: "dxa", twips: width.value };
|
|
35
|
+
}
|
|
24
36
|
if (type === "pct") {
|
|
25
|
-
|
|
37
|
+
if (width.kind === "twips") return null;
|
|
26
38
|
return {
|
|
27
39
|
type: "pct",
|
|
28
|
-
fiftieths:
|
|
40
|
+
fiftieths: width.value
|
|
29
41
|
};
|
|
30
42
|
}
|
|
31
43
|
return null;
|
|
@@ -35,7 +47,7 @@ function readGridCols(tblGrid) {
|
|
|
35
47
|
const cols = [];
|
|
36
48
|
for (const child of Array.from(tblGrid.children)) {
|
|
37
49
|
if (child.localName !== "gridCol") continue;
|
|
38
|
-
const w =
|
|
50
|
+
const w = ST_TwipsMeasure.parse(wAttr(child, "w"));
|
|
39
51
|
if (w !== null) cols.push(w);
|
|
40
52
|
}
|
|
41
53
|
return cols;
|
|
@@ -69,7 +81,7 @@ function marginSide(margins, names) {
|
|
|
69
81
|
if (!el) continue;
|
|
70
82
|
const type = wAttr(el, "type") ?? "dxa";
|
|
71
83
|
if (type === "nil") return 0;
|
|
72
|
-
return type === "dxa" ? twipsToPt(wAttr(el, "w")) : null;
|
|
84
|
+
return type === "dxa" ? twipsToPt(ST_TwipsMeasure.parse(wAttr(el, "w"))) : null;
|
|
73
85
|
}
|
|
74
86
|
return null;
|
|
75
87
|
}
|
|
@@ -107,10 +119,18 @@ function gridEdgesOf(rect, grid) {
|
|
|
107
119
|
}
|
|
108
120
|
function cellBorderDefaults(edges, outer, inside) {
|
|
109
121
|
return {
|
|
110
|
-
top:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
top: borderLineOfCss(
|
|
123
|
+
edges.top ? outer?.borderTop ?? null : inside.horizontal
|
|
124
|
+
),
|
|
125
|
+
bottom: borderLineOfCss(
|
|
126
|
+
edges.bottom ? outer?.borderBottom ?? null : inside.horizontal
|
|
127
|
+
),
|
|
128
|
+
left: borderLineOfCss(
|
|
129
|
+
edges.left ? outer?.borderLeft ?? null : inside.vertical
|
|
130
|
+
),
|
|
131
|
+
right: borderLineOfCss(
|
|
132
|
+
edges.right ? outer?.borderRight ?? null : inside.vertical
|
|
133
|
+
)
|
|
114
134
|
};
|
|
115
135
|
}
|
|
116
136
|
function tblStyleIdOf(tblPr) {
|
|
@@ -133,12 +153,12 @@ function readTableFormat(tblPr) {
|
|
|
133
153
|
const align = ALIGN_BY_JC[childValue(tblPr, "jc") ?? ""];
|
|
134
154
|
if (align) format.align = align;
|
|
135
155
|
const tblInd = childByLocalName(tblPr, "tblInd");
|
|
136
|
-
const indentLeftPt = tblInd ? twipsToPt(wAttr(tblInd, "w")) : null;
|
|
156
|
+
const indentLeftPt = tblInd ? twipsToPt(ST_SignedTwipsMeasure.parse(wAttr(tblInd, "w"))) : null;
|
|
137
157
|
if (indentLeftPt !== null) format.indentLeftPt = indentLeftPt;
|
|
138
158
|
return format;
|
|
139
159
|
}
|
|
140
160
|
function readRowHeight(trHeight) {
|
|
141
|
-
const pt = twipsToPt(wAttr(trHeight, "val"));
|
|
161
|
+
const pt = twipsToPt(ST_TwipsMeasure.parse(wAttr(trHeight, "val")));
|
|
142
162
|
if (pt === null || pt <= 0) return null;
|
|
143
163
|
const rule = wAttr(trHeight, "hRule") === "exact" ? "exact" : "atLeast";
|
|
144
164
|
return { rule, pt };
|
|
@@ -170,13 +190,13 @@ function readCellPadding(tcPr, margins) {
|
|
|
170
190
|
function readCellFormat(tcPr, defaults, margins = NO_CELL_MARGINS) {
|
|
171
191
|
const borders = tcPr ? childByLocalName(tcPr, "tcBorders") : null;
|
|
172
192
|
const format = {};
|
|
173
|
-
const top = borderSide(borders, "top") ?? defaults.top;
|
|
193
|
+
const top = borderSide(borders, "top") ?? borderLineCss(defaults.top);
|
|
174
194
|
if (top) format.borderTop = top;
|
|
175
|
-
const bottom = borderSide(borders, "bottom") ?? defaults.bottom;
|
|
195
|
+
const bottom = borderSide(borders, "bottom") ?? borderLineCss(defaults.bottom);
|
|
176
196
|
if (bottom) format.borderBottom = bottom;
|
|
177
|
-
const left = borderSide(borders, "left") ?? borderSide(borders, "start") ?? defaults.left;
|
|
197
|
+
const left = borderSide(borders, "left") ?? borderSide(borders, "start") ?? borderLineCss(defaults.left);
|
|
178
198
|
if (left) format.borderLeft = left;
|
|
179
|
-
const right = borderSide(borders, "right") ?? borderSide(borders, "end") ?? defaults.right;
|
|
199
|
+
const right = borderSide(borders, "right") ?? borderSide(borders, "end") ?? borderLineCss(defaults.right);
|
|
180
200
|
if (right) format.borderRight = right;
|
|
181
201
|
if (tcPr) {
|
|
182
202
|
const background = shadingOf(tcPr);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/docx/tableTemplate.ts
|
|
2
|
+
import { elementXml } from "../ooxml/element.js";
|
|
3
|
+
import { wName } from "../ooxml/names.js";
|
|
4
|
+
import { orderedElement, parsePropsXml } from "../ooxml/props.js";
|
|
2
5
|
import { docxSchema } from "../schema/index.js";
|
|
3
6
|
import { A4_PORTRAIT, bodyWidth } from "./pageGeometry.js";
|
|
4
|
-
import { parsePropsXml } from "./propsXml.js";
|
|
5
7
|
import {
|
|
6
8
|
cellBorderDefaults,
|
|
7
9
|
gridEdgesOf,
|
|
@@ -25,14 +27,44 @@ var BORDER_SIDES = [
|
|
|
25
27
|
"insideV"
|
|
26
28
|
];
|
|
27
29
|
function borderXml(side) {
|
|
28
|
-
return
|
|
30
|
+
return elementXml(wName(side), [
|
|
31
|
+
[wName("val"), "single"],
|
|
32
|
+
[wName("sz"), `${BORDER_EIGHTHS}`],
|
|
33
|
+
[wName("space"), "0"],
|
|
34
|
+
[wName("color"), "000000"]
|
|
35
|
+
]);
|
|
29
36
|
}
|
|
30
37
|
function tablePropsXml(width) {
|
|
31
|
-
const borders =
|
|
32
|
-
|
|
38
|
+
const borders = orderedElement(
|
|
39
|
+
wName("tblBorders"),
|
|
40
|
+
[],
|
|
41
|
+
BORDER_SIDES.map((side) => ({ name: side, xml: borderXml(side) }))
|
|
42
|
+
);
|
|
43
|
+
return orderedElement(
|
|
44
|
+
wName("tblPr"),
|
|
45
|
+
[],
|
|
46
|
+
[
|
|
47
|
+
{ name: "tblW", xml: widthXml("tblW", width) },
|
|
48
|
+
{ name: "tblBorders", xml: borders },
|
|
49
|
+
{
|
|
50
|
+
name: "tblLayout",
|
|
51
|
+
xml: elementXml(wName("tblLayout"), [[wName("type"), "fixed"]])
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function widthXml(name, width) {
|
|
57
|
+
return elementXml(wName(name), [
|
|
58
|
+
[wName("w"), `${width}`],
|
|
59
|
+
[wName("type"), "dxa"]
|
|
60
|
+
]);
|
|
33
61
|
}
|
|
34
62
|
function cellPropsXml(width) {
|
|
35
|
-
return
|
|
63
|
+
return orderedElement(
|
|
64
|
+
wName("tcPr"),
|
|
65
|
+
[],
|
|
66
|
+
[{ name: "tcW", xml: widthXml("tcW", width) }]
|
|
67
|
+
);
|
|
36
68
|
}
|
|
37
69
|
function evenGridCols(cols, total) {
|
|
38
70
|
const base = Math.floor(total / cols);
|
package/dist/docx/theme.d.ts
CHANGED
|
@@ -21,12 +21,6 @@ export interface ThemeFonts {
|
|
|
21
21
|
}
|
|
22
22
|
/** What applies to a document with no theme part, or one whose theme names no font */
|
|
23
23
|
export declare const NO_THEME_FONTS: ThemeFonts;
|
|
24
|
-
/**
|
|
25
|
-
* The theme attribute paired with each font slot.
|
|
26
|
-
* A theme reference and a name in the same slot cannot both apply, so the name wins,
|
|
27
|
-
* the way Word reads them.
|
|
28
|
-
*/
|
|
29
|
-
export declare const THEME_ATTRS: Record<string, readonly string[]>;
|
|
30
24
|
/** The font one theme reference stands for. null for a reference we cannot resolve */
|
|
31
25
|
export declare function themeFontName(fonts: ThemeFonts, value: string | null): string | null;
|
|
32
26
|
/**
|
package/dist/docx/theme.js
CHANGED
|
@@ -9,13 +9,6 @@ var NO_THEME_FONTS = {
|
|
|
9
9
|
major: NO_FONT_SCHEME,
|
|
10
10
|
minor: NO_FONT_SCHEME
|
|
11
11
|
};
|
|
12
|
-
var THEME_ATTRS = {
|
|
13
|
-
ascii: ["asciiTheme"],
|
|
14
|
-
hAnsi: ["hAnsiTheme"],
|
|
15
|
-
eastAsia: ["eastAsiaTheme"],
|
|
16
|
-
// This is the slot whose capitalization varies from document to document
|
|
17
|
-
cs: ["cstheme", "csTheme"]
|
|
18
|
-
};
|
|
19
12
|
var THEME_SLOTS = {
|
|
20
13
|
majorascii: { scheme: "major", script: "latin" },
|
|
21
14
|
majorhansi: { scheme: "major", script: "latin" },
|
|
@@ -55,7 +48,6 @@ function readThemeFonts(theme) {
|
|
|
55
48
|
}
|
|
56
49
|
export {
|
|
57
50
|
NO_THEME_FONTS,
|
|
58
|
-
THEME_ATTRS,
|
|
59
51
|
readThemeFonts,
|
|
60
52
|
themeFontName
|
|
61
53
|
};
|
package/dist/download.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Node as PMNode } from "prosemirror-model";
|
|
8
8
|
import type { DocxEditorHandle } from "./DocxEditor";
|
|
9
|
+
import type { ExportProblem } from "./docx/invariants";
|
|
9
10
|
export declare const DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
10
11
|
export interface DownloadDocxOptions {
|
|
11
12
|
/** The name to save under. The `.docx` suffix may be there or not */
|
|
@@ -19,6 +20,9 @@ export type DownloadDocxResult = {
|
|
|
19
20
|
status: "unavailable";
|
|
20
21
|
} | {
|
|
21
22
|
status: "empty";
|
|
23
|
+
} | {
|
|
24
|
+
status: "blocked";
|
|
25
|
+
problems: readonly ExportProblem[];
|
|
22
26
|
};
|
|
23
27
|
/** Settles the end of the name on exactly one `.docx` */
|
|
24
28
|
export declare function withDocxExtension(fileName: string): string;
|
|
@@ -48,10 +52,9 @@ export declare function hasExportableContent(doc: PMNode): boolean;
|
|
|
48
52
|
* Downloads the edited document as a docx file.
|
|
49
53
|
*
|
|
50
54
|
* `unavailable` when the editor is not mounted yet or the document could not be
|
|
51
|
-
* opened, `empty` when there is nothing to export,
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* is rethrown as is.
|
|
55
|
+
* opened, `empty` when there is nothing to export, `blocked` with every reason
|
|
56
|
+
* when the document cannot be written back (a new list in a document without
|
|
57
|
+
* numbering.xml, and the like), and `exported` once a file has gone out.
|
|
58
|
+
* A refusal the check did not foresee is still thrown as `DocxExportError`.
|
|
56
59
|
*/
|
|
57
60
|
export declare function downloadDocx(editor: DocxEditorHandle | null | undefined, options: DownloadDocxOptions): DownloadDocxResult;
|
package/dist/download.js
CHANGED
|
@@ -29,6 +29,8 @@ function hasExportableContent(doc) {
|
|
|
29
29
|
function downloadDocx(editor, options) {
|
|
30
30
|
if (!editor) return { status: "unavailable" };
|
|
31
31
|
if (!hasExportableContent(editor.view.state.doc)) return { status: "empty" };
|
|
32
|
+
const problems = editor.exportProblems();
|
|
33
|
+
if (problems.length > 0) return { status: "blocked", problems };
|
|
32
34
|
const bytes = editor.exportBytes();
|
|
33
35
|
const fileName = withDocxExtension(options.fileName);
|
|
34
36
|
downloadBlob(createDocxBlob(bytes), fileName);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// src/editor/clipboard/images.ts
|
|
2
2
|
import { MAX_IMAGE_BYTES } from "../../docx/media.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isImageMime,
|
|
5
|
+
pxToEmu,
|
|
6
|
+
toImageExtent,
|
|
7
|
+
toImageSrc
|
|
8
|
+
} from "../../ooxml/image.js";
|
|
4
9
|
import { editorClassNames } from "../../styles/classNames.js";
|
|
5
10
|
import {
|
|
6
11
|
boundedImageSrc,
|
|
@@ -9,8 +14,7 @@ import {
|
|
|
9
14
|
readImageSource
|
|
10
15
|
} from "../imageFiles.js";
|
|
11
16
|
var PASTED_IMAGE_ATTRIBUTE = "data-docx-pasted-image";
|
|
12
|
-
function
|
|
13
|
-
if (!element.classList.contains(editorClassNames.image)) return null;
|
|
17
|
+
function declaredExtent(element) {
|
|
14
18
|
try {
|
|
15
19
|
return toImageExtent(
|
|
16
20
|
JSON.parse(element.getAttribute("data-extent") ?? "null")
|
|
@@ -19,6 +23,16 @@ function extentAttribute(element) {
|
|
|
19
23
|
return null;
|
|
20
24
|
}
|
|
21
25
|
}
|
|
26
|
+
function renderedExtent(element) {
|
|
27
|
+
const width = Number.parseInt(element.getAttribute("width") ?? "", 10);
|
|
28
|
+
const height = Number.parseInt(element.getAttribute("height") ?? "", 10);
|
|
29
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
|
|
30
|
+
return toImageExtent({ cx: pxToEmu(width), cy: pxToEmu(height) });
|
|
31
|
+
}
|
|
32
|
+
function extentAttribute(element) {
|
|
33
|
+
if (!element.classList.contains(editorClassNames.image)) return null;
|
|
34
|
+
return declaredExtent(element) ?? renderedExtent(element);
|
|
35
|
+
}
|
|
22
36
|
function fetchableUrl(source) {
|
|
23
37
|
try {
|
|
24
38
|
const url = new URL(source);
|
|
@@ -15,6 +15,13 @@ export interface InlineContext {
|
|
|
15
15
|
preserveWhitespace: boolean;
|
|
16
16
|
}
|
|
17
17
|
export type InlineElementReader = (target: PMNode[], element: HTMLElement, context: InlineContext) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The address a link may carry, whichever way it travels.
|
|
20
|
+
*
|
|
21
|
+
* A copy writes one out and a paste reads one in, and an address this rule turns down is one
|
|
22
|
+
* neither end should act on, so both ask here.
|
|
23
|
+
*/
|
|
24
|
+
export declare function safeHref(value: string | null): string | null;
|
|
18
25
|
export declare function contextFor(parent: InlineContext, element: HTMLElement, readElementStyle?: boolean): InlineContext;
|
|
19
26
|
export declare function withInlineStyle(context: InlineContext, style: InlineStyle): InlineContext;
|
|
20
27
|
export declare function marksFor(context: InlineContext): Mark[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/editor/clipboard/inlineFormatting.ts
|
|
2
|
-
import {
|
|
2
|
+
import { rPrOf } from "../../docx/formatting.js";
|
|
3
|
+
import { readRunProps } from "../../docx/runProps.js";
|
|
4
|
+
import { HALF_POINTS_PER_PT, ST_HpsMeasure } from "../../ooxml/simpleTypes.js";
|
|
3
5
|
import { docxSchema } from "../../schema/index.js";
|
|
4
6
|
import { editorClassNames } from "../../styles/classNames.js";
|
|
5
7
|
var IGNORED_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -76,8 +78,8 @@ function fontSizePt(value) {
|
|
|
76
78
|
const amount = Number.parseFloat(match[1] ?? "");
|
|
77
79
|
if (!Number.isFinite(amount) || amount <= 0) return null;
|
|
78
80
|
const points = match[2]?.toLowerCase() === "px" ? amount * 0.75 : amount;
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
+
const half = Math.round(points * HALF_POINTS_PER_PT);
|
|
82
|
+
return ST_HpsMeasure.format(half) === null ? null : half / HALF_POINTS_PER_PT;
|
|
81
83
|
}
|
|
82
84
|
function legacyFontSize(value) {
|
|
83
85
|
const sizes = [8, 10, 12, 14, 18, 24, 36];
|
|
@@ -150,34 +152,21 @@ function contextFor(parent, element, readElementStyle = true) {
|
|
|
150
152
|
function withInlineStyle(context, style) {
|
|
151
153
|
return { ...context, style: { ...context.style, ...style } };
|
|
152
154
|
}
|
|
155
|
+
function settingsOf(style) {
|
|
156
|
+
const settings = {};
|
|
157
|
+
if (style.bold) settings.bold = true;
|
|
158
|
+
if (style.italic) settings.italic = true;
|
|
159
|
+
if (style.underline) settings.underline = "single";
|
|
160
|
+
if (style.strike) settings.strike = true;
|
|
161
|
+
if (style.fontSizePt !== void 0) settings.fontSizePt = style.fontSizePt;
|
|
162
|
+
if (style.fontFamily !== void 0) settings.fontFamily = style.fontFamily;
|
|
163
|
+
if (style.color !== void 0) settings.color = style.color;
|
|
164
|
+
if (style.background !== void 0) settings.background = style.background;
|
|
165
|
+
return settings;
|
|
166
|
+
}
|
|
153
167
|
function runMark(style) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
if (style.italic) edits.push({ kind: "toggle", toggle: "italic", on: true });
|
|
157
|
-
if (style.underline) {
|
|
158
|
-
edits.push({ kind: "toggle", toggle: "underline", on: true });
|
|
159
|
-
}
|
|
160
|
-
if (style.strike) edits.push({ kind: "toggle", toggle: "strike", on: true });
|
|
161
|
-
if (style.fontSizePt !== void 0) {
|
|
162
|
-
edits.push({ kind: "fontSize", pt: style.fontSizePt });
|
|
163
|
-
}
|
|
164
|
-
if (style.fontFamily !== void 0) {
|
|
165
|
-
edits.push({ kind: "fontFamily", name: style.fontFamily });
|
|
166
|
-
}
|
|
167
|
-
if (style.color !== void 0)
|
|
168
|
-
edits.push({ kind: "color", hex: style.color });
|
|
169
|
-
if (style.background !== void 0) {
|
|
170
|
-
edits.push({ kind: "background", hex: style.background });
|
|
171
|
-
}
|
|
172
|
-
let props = {
|
|
173
|
-
rPr: null,
|
|
174
|
-
format: null
|
|
175
|
-
};
|
|
176
|
-
for (const edit of edits) {
|
|
177
|
-
const next = editRunProps(props, null, edit);
|
|
178
|
-
if (next) props = next;
|
|
179
|
-
}
|
|
180
|
-
return props.rPr === null ? null : docxSchema.marks.run.create({ rPr: props.rPr, format: props.format });
|
|
168
|
+
const rPr = rPrOf(settingsOf(style));
|
|
169
|
+
return rPr === null ? null : docxSchema.marks.run.create({ rPr, format: readRunProps(rPr) });
|
|
181
170
|
}
|
|
182
171
|
function marksFor(context) {
|
|
183
172
|
const marks = [];
|
|
@@ -228,5 +217,6 @@ export {
|
|
|
228
217
|
appendInline,
|
|
229
218
|
contextFor,
|
|
230
219
|
marksFor,
|
|
220
|
+
safeHref,
|
|
231
221
|
withInlineStyle
|
|
232
222
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/editor/commands/breakCommands.ts
|
|
2
2
|
import { docxSchema } from "../../schema/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { editsShut } from "../../schema/protectionState.js";
|
|
3
|
+
import { editShut, selectionIntents } from "../../schema/guards.js";
|
|
5
4
|
function insertBreak(brAttrs) {
|
|
6
5
|
return (state, dispatch) => {
|
|
7
|
-
if (
|
|
6
|
+
if (selectionIntents(state.selection, "replace").some(
|
|
7
|
+
(intent) => editShut(state, intent)
|
|
8
|
+
)) {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
10
11
|
if (dispatch) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dry-runs external commands and checks every produced transaction against
|
|
3
|
-
*
|
|
2
|
+
* Dry-runs external commands and checks every produced transaction against every guard
|
|
3
|
+
* (`schema/guards`) without dispatching them or triggering the locked-content plugin's side
|
|
4
4
|
* effects.
|
|
5
5
|
*/
|
|
6
6
|
import type { Command, EditorState } from "prosemirror-state";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/editor/commands/canRunCommand.ts
|
|
2
|
-
import { transactionAllowed } from "../../schema/
|
|
2
|
+
import { transactionAllowed } from "../../schema/guards.js";
|
|
3
3
|
function canRunCommand(command, state) {
|
|
4
4
|
const built = [];
|
|
5
5
|
if (!command(state, (tr) => built.push(tr))) return false;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** Edits Word comments through their range markers and reference nodes. */
|
|
2
2
|
import { type Command, type EditorState } from "prosemirror-state";
|
|
3
3
|
import type { NewComment } from "./model";
|
|
4
|
-
/** Whether a non-empty selection in one paragraph can receive a comment. */
|
|
5
|
-
export declare function canAddComment(state: EditorState): boolean;
|
|
6
4
|
/** Adds a plain-text comment to the current text selection. */
|
|
7
5
|
export declare function addComment(comment: NewComment): Command;
|
|
6
|
+
/**
|
|
7
|
+
* Whether a non-empty selection in one paragraph can receive a comment.
|
|
8
|
+
* This is the command itself asked without a dispatch, over a comment standing in for the one the
|
|
9
|
+
* user would write, so the button and the click cannot answer differently.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canAddComment(state: EditorState): boolean;
|
|
8
12
|
/** Replaces the plain-text body of one comment, retaining its author and anchor. */
|
|
9
13
|
export declare function updateComment(id: string, text: string): Command;
|
|
10
14
|
/** Marks a comment thread resolved or open without deleting it. */
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
} from "prosemirror-state";
|
|
5
5
|
import { commentParaId } from "../../../docx/comments.js";
|
|
6
6
|
import { docxSchema } from "../../../schema/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { guardedCommand } from "../../../schema/guards.js";
|
|
8
8
|
import {
|
|
9
9
|
reservedCommentIds,
|
|
10
10
|
reservedCommentParaIds
|
|
11
|
-
} from "../../
|
|
11
|
+
} from "../../editorDocument.js";
|
|
12
12
|
import { documentComments, repliesAttr, stringAttr } from "./reading.js";
|
|
13
13
|
function validCommentSelection(state) {
|
|
14
14
|
const { selection } = state;
|
|
@@ -113,27 +113,21 @@ function addCommentTransaction(state, comment) {
|
|
|
113
113
|
null,
|
|
114
114
|
startMarks
|
|
115
115
|
);
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
return state.tr.insert(to, end).insert(to + 1, reference).insert(from, start);
|
|
117
|
+
}
|
|
118
|
+
function addComment(comment) {
|
|
119
|
+
return guardedCommand((state) => addCommentTransaction(state, comment));
|
|
118
120
|
}
|
|
119
121
|
function canAddComment(state) {
|
|
120
|
-
return
|
|
122
|
+
return addComment({
|
|
121
123
|
text: "comment",
|
|
122
124
|
author: "Author",
|
|
123
125
|
date: "1970-01-01T00:00:00.000Z"
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
function addComment(comment) {
|
|
127
|
-
return (state, dispatch) => {
|
|
128
|
-
const transaction = addCommentTransaction(state, comment);
|
|
129
|
-
if (!transaction) return false;
|
|
130
|
-
dispatch?.(transaction);
|
|
131
|
-
return true;
|
|
132
|
-
};
|
|
126
|
+
})(state);
|
|
133
127
|
}
|
|
134
128
|
function updateComment(id, text) {
|
|
135
|
-
return (state
|
|
136
|
-
if (text.trim().length === 0) return
|
|
129
|
+
return guardedCommand((state) => {
|
|
130
|
+
if (text.trim().length === 0) return null;
|
|
137
131
|
let transaction = state.tr;
|
|
138
132
|
let changed = false;
|
|
139
133
|
state.doc.descendants((node, pos) => {
|
|
@@ -148,13 +142,11 @@ function updateComment(id, text) {
|
|
|
148
142
|
}
|
|
149
143
|
return true;
|
|
150
144
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return true;
|
|
154
|
-
};
|
|
145
|
+
return changed ? transaction : null;
|
|
146
|
+
});
|
|
155
147
|
}
|
|
156
148
|
function updateReference(id, change) {
|
|
157
|
-
return (state
|
|
149
|
+
return guardedCommand((state) => {
|
|
158
150
|
let transaction = state.tr;
|
|
159
151
|
let changed = false;
|
|
160
152
|
state.doc.descendants((node, pos) => {
|
|
@@ -168,21 +160,17 @@ function updateReference(id, change) {
|
|
|
168
160
|
}
|
|
169
161
|
return false;
|
|
170
162
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return true;
|
|
174
|
-
};
|
|
163
|
+
return changed ? transaction : null;
|
|
164
|
+
});
|
|
175
165
|
}
|
|
176
166
|
function setCommentResolved(id, resolved) {
|
|
177
167
|
return (state, dispatch) => updateReference(id, (node) => {
|
|
178
168
|
if (node.attrs.resolved === resolved) return null;
|
|
179
169
|
return {
|
|
180
170
|
...node.attrs,
|
|
181
|
-
paraId: node.attrs.threadImported === true && node.attrs.extensionXml === null ? nextCommentParaId(state, `comment-${id}`) : node.attrs.paraId,
|
|
182
171
|
resolved,
|
|
183
172
|
extensionXml: null,
|
|
184
|
-
threadImported: false
|
|
185
|
-
imported: node.attrs.commentXml !== null && node.attrs.extensionXml === null ? false : node.attrs.imported
|
|
173
|
+
threadImported: false
|
|
186
174
|
};
|
|
187
175
|
})(state, dispatch);
|
|
188
176
|
}
|
|
@@ -192,7 +180,7 @@ function addCommentReply(id, reply) {
|
|
|
192
180
|
const replyId = nextCommentId(state);
|
|
193
181
|
const date = reply.date ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
194
182
|
return updateReference(id, (node) => {
|
|
195
|
-
const parentParaId =
|
|
183
|
+
const parentParaId = stringAttr(node.attrs.paraId) ?? nextCommentParaId(state, `comment-${id}`);
|
|
196
184
|
const paraId = nextCommentParaId(state, `comment-${replyId}-${date}`, [
|
|
197
185
|
parentParaId
|
|
198
186
|
]);
|
|
@@ -202,7 +190,6 @@ function addCommentReply(id, reply) {
|
|
|
202
190
|
resolved: false,
|
|
203
191
|
extensionXml: null,
|
|
204
192
|
threadImported: false,
|
|
205
|
-
imported: node.attrs.commentXml !== null && node.attrs.extensionXml === null ? false : node.attrs.imported,
|
|
206
193
|
replies: [
|
|
207
194
|
...repliesAttr(node.attrs.replies),
|
|
208
195
|
{
|
|
@@ -264,7 +251,7 @@ function removeCommentReply(commentId, replyId) {
|
|
|
264
251
|
});
|
|
265
252
|
}
|
|
266
253
|
function removeComment(id) {
|
|
267
|
-
return (state
|
|
254
|
+
return guardedCommand((state) => {
|
|
268
255
|
const positions = [];
|
|
269
256
|
state.doc.descendants((node, pos) => {
|
|
270
257
|
if ((node.type.name === "commentStart" || node.type.name === "commentEnd" || node.type.name === "commentReference") && stringAttr(node.attrs.id) === id) {
|
|
@@ -272,15 +259,13 @@ function removeComment(id) {
|
|
|
272
259
|
}
|
|
273
260
|
return true;
|
|
274
261
|
});
|
|
275
|
-
if (positions.length === 0) return
|
|
262
|
+
if (positions.length === 0) return null;
|
|
276
263
|
const transaction = state.tr;
|
|
277
264
|
for (const marker of positions.sort((a, b) => b.pos - a.pos)) {
|
|
278
265
|
transaction.delete(marker.pos, marker.pos + marker.size);
|
|
279
266
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
return true;
|
|
283
|
-
};
|
|
267
|
+
return transaction;
|
|
268
|
+
});
|
|
284
269
|
}
|
|
285
270
|
function selectComment(id) {
|
|
286
271
|
return (state, dispatch) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Document-level readers for whether the document as it stands can be written back. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import { type ExportProblem } from "../../docx/invariants";
|
|
4
|
+
export type { ExportProblem } from "../../docx/invariants";
|
|
5
|
+
/**
|
|
6
|
+
* Every reason writing the document back would be refused, in the order `exportDocx` would raise
|
|
7
|
+
* them, each with the code and message the refusal would carry and the position in the document
|
|
8
|
+
* where there is one. Empty when the file would be written.
|
|
9
|
+
*
|
|
10
|
+
* A state built without an opened document has no file to write back into, so nothing about it
|
|
11
|
+
* can be refused and it reports no problem.
|
|
12
|
+
*/
|
|
13
|
+
export declare function documentExportProblems(state: EditorState): readonly ExportProblem[];
|
|
14
|
+
/** Whether the document as it stands can be written back, which is what an export control is drawn from */
|
|
15
|
+
export declare function canExport(state: EditorState): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/editor/commands/exportQueries.ts
|
|
2
|
+
import { exportProblems } from "../../docx/invariants.js";
|
|
3
|
+
import { documentOf } from "../editorDocument.js";
|
|
4
|
+
function documentExportProblems(state) {
|
|
5
|
+
const { session } = documentOf(state);
|
|
6
|
+
return session === null ? [] : exportProblems(state.doc, session);
|
|
7
|
+
}
|
|
8
|
+
function canExport(state) {
|
|
9
|
+
return documentExportProblems(state).length === 0;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
canExport,
|
|
13
|
+
documentExportProblems
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Document-level reader for what the open document holds that the editor cannot model. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import { type FidelityNote } from "../../docx/fidelity";
|
|
4
|
+
export type { FidelityCode, FidelityNote, FidelitySeverity, } from "../../docx/fidelity";
|
|
5
|
+
/**
|
|
6
|
+
* What the document standing in the editor hides, stands a placeholder in front of, or approximates.
|
|
7
|
+
*
|
|
8
|
+
* The notes are read off the document as it is now, so a note goes away as soon as an edit removes
|
|
9
|
+
* what it was about. `part` is null: an editor state carries the document and not the file it came
|
|
10
|
+
* from, and `importDocx` is where a note can name the part it belongs to.
|
|
11
|
+
*/
|
|
12
|
+
export declare function documentFidelity(state: EditorState): readonly FidelityNote[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The character formatting commands the package exports, each built from the property it edits. */
|
|
2
2
|
import type { Command, EditorState } from "prosemirror-state";
|
|
3
|
-
export type { RunToggle } from "../../../docx/runProps";
|
|
4
3
|
/**
|
|
5
4
|
* Whether character formatting reaches anything where the selection stands, which is what a
|
|
6
5
|
* control offering it is drawn from.
|
|
@@ -13,6 +12,7 @@ export type { RunToggle } from "../../../docx/runProps";
|
|
|
13
12
|
export declare function canFormatText(state: EditorState): boolean;
|
|
14
13
|
export declare const toggleBold: Command;
|
|
15
14
|
export declare const toggleItalic: Command;
|
|
15
|
+
/** Switching the underline on writes a single one; a run already underlined keeps the kind it has */
|
|
16
16
|
export declare const toggleUnderline: Command;
|
|
17
17
|
export declare const toggleStrike: Command;
|
|
18
18
|
/** Sets the font size in points. Null withdraws the setting and falls back to the document default */
|