@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
package/dist/docx/session.d.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { Node as PMNode } from "prosemirror-model";
|
|
11
11
|
import type { DocumentDefaults } from "../model/format";
|
|
12
|
-
import { type Numbering } from "../numbering/parseNumbering";
|
|
12
|
+
import { type Numbering, type NumberingOptions } from "../numbering/parseNumbering";
|
|
13
13
|
import type { ImportedComments } from "./comments";
|
|
14
|
-
import type
|
|
14
|
+
import { type FormattingContext, type ParagraphStyleOption } from "./formatting";
|
|
15
15
|
import type { HeadersFooters } from "./headersFooters";
|
|
16
16
|
import type { PageGeometry } from "./pageGeometry";
|
|
17
17
|
export interface ImportedBlock {
|
|
@@ -28,9 +28,23 @@ export interface ImportedBlock {
|
|
|
28
28
|
export interface DocxSession {
|
|
29
29
|
readonly kind: "docxSession";
|
|
30
30
|
}
|
|
31
|
+
/** What names one open document, which a block key is written against */
|
|
32
|
+
export interface SessionIdentity {
|
|
33
|
+
readonly sessionId: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A name for one open document.
|
|
37
|
+
*
|
|
38
|
+
* Opening the same bytes twice opens two documents, so this is drawn fresh each time rather than
|
|
39
|
+
* worked out from what was opened. It carries no `:`, which is what lets a block key be read back
|
|
40
|
+
* however many colons the story it names holds.
|
|
41
|
+
*/
|
|
42
|
+
export declare function newSessionId(): string;
|
|
31
43
|
/** What the package's own layers read the open document off */
|
|
32
|
-
export declare class SessionStore implements DocxSession {
|
|
44
|
+
export declare class SessionStore implements DocxSession, SessionIdentity {
|
|
33
45
|
readonly kind = "docxSession";
|
|
46
|
+
/** Which open document this is. Every block key of it names it, so a block of another document is not taken for one of this one */
|
|
47
|
+
readonly sessionId: string;
|
|
34
48
|
readonly parts: Map<string, Uint8Array>;
|
|
35
49
|
readonly mainPartPath: string;
|
|
36
50
|
readonly documentPrefix: string;
|
|
@@ -41,19 +55,12 @@ export declare class SessionStore implements DocxSession {
|
|
|
41
55
|
readonly defaults: DocumentDefaults;
|
|
42
56
|
/** The effective automatic tab interval read from settings.xml. Used for display only. */
|
|
43
57
|
readonly defaultTabStopPt: number;
|
|
44
|
-
/** The paragraph properties at the base of the OOXML formatting hierarchy. */
|
|
45
|
-
readonly paragraphDefaults: ParagraphFormatLayer;
|
|
46
58
|
/** The paper this document is written on, read from the first section. Used for display only: the `w:sectPr` itself goes back out in the preserved tail */
|
|
47
59
|
readonly geometry: PageGeometry;
|
|
48
|
-
/**
|
|
49
|
-
readonly
|
|
60
|
+
/** Everything the display values of a paragraph or a run are resolved against: the style chain, the defaults, the list definitions */
|
|
61
|
+
readonly formatting: FormattingContext;
|
|
50
62
|
/** The paragraph styles this document defines, in the order styles.xml lists them. What the style picker offers */
|
|
51
63
|
readonly paragraphStyles: ParagraphStyleOption[];
|
|
52
|
-
/**
|
|
53
|
-
* The paragraph style every paragraph with no `w:pStyle` of its own wears (`w:default="1"`,
|
|
54
|
-
* usually Normal). null when the document marks none
|
|
55
|
-
*/
|
|
56
|
-
readonly defaultParagraphStyleId: string | null;
|
|
57
64
|
/** The raw text of numbering.xml. Kept around so list numbers can be drawn on screen. null if there is none */
|
|
58
65
|
readonly numberingXml: string | null;
|
|
59
66
|
/** Where numbering.xml sits inside the zip. When a new list is exported it is rewritten at that spot. null if there is none */
|
|
@@ -76,6 +83,27 @@ export declare function sessionOf(session: DocxSession): SessionStore;
|
|
|
76
83
|
/** Where the body part sits inside the package, which is the one part an export rewrites */
|
|
77
84
|
export declare function documentPartPath(session: DocxSession): string;
|
|
78
85
|
/** The list definitions the document carries, which is what a paragraph's numbering points into */
|
|
79
|
-
export declare function documentNumbering(session: DocxSession): Numbering;
|
|
80
|
-
/**
|
|
86
|
+
export declare function documentNumbering(session: DocxSession, options?: NumberingOptions): Numbering;
|
|
87
|
+
/** The story a block key names when the block stood in the main document body */
|
|
88
|
+
export declare const BODY_STORY_KEY = "body";
|
|
89
|
+
/** A block key read back: which open document the block came from, which story of it, and where in that story */
|
|
90
|
+
export interface BlockKey {
|
|
91
|
+
sessionId: string;
|
|
92
|
+
storyKey: string;
|
|
93
|
+
index: number;
|
|
94
|
+
}
|
|
95
|
+
/** Where a block stands, as the one string a node carries on its `srcId` */
|
|
96
|
+
export declare function blockKey(session: SessionIdentity, storyKey: string, index: number): string;
|
|
97
|
+
/**
|
|
98
|
+
* The three parts of a block key, or null for a string that is not one.
|
|
99
|
+
*
|
|
100
|
+
* A story key holds colons of its own (`comment:4`), so the key is read from both ends rather
|
|
101
|
+
* than split: the first segment is the document, the last is the place in the story, and
|
|
102
|
+
* everything between them is the story itself.
|
|
103
|
+
*/
|
|
104
|
+
export declare function splitBlockKey(key: string): BlockKey | null;
|
|
105
|
+
/**
|
|
106
|
+
* Finds which original block a node came from. undefined for a node newly created during editing,
|
|
107
|
+
* and for one that came in from another document, whose original is in that file and not this one.
|
|
108
|
+
*/
|
|
81
109
|
export declare function originalBlock(node: PMNode, session: SessionStore): ImportedBlock | undefined;
|
package/dist/docx/session.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
// src/docx/session.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
parseNumbering
|
|
4
|
+
} from "../numbering/parseNumbering.js";
|
|
5
|
+
import {
|
|
6
|
+
numberingOptionsFor
|
|
7
|
+
} from "./formatting.js";
|
|
8
|
+
var sessionsOpened = 0;
|
|
9
|
+
function newSessionId() {
|
|
10
|
+
sessionsOpened += 1;
|
|
11
|
+
return `d${sessionsOpened}-${Math.random().toString(36).slice(2, 10)}`;
|
|
12
|
+
}
|
|
3
13
|
var SessionStore = class {
|
|
4
14
|
kind = "docxSession";
|
|
15
|
+
/** Which open document this is. Every block key of it names it, so a block of another document is not taken for one of this one */
|
|
16
|
+
sessionId;
|
|
5
17
|
parts;
|
|
6
18
|
mainPartPath;
|
|
7
19
|
documentPrefix;
|
|
@@ -12,19 +24,12 @@ var SessionStore = class {
|
|
|
12
24
|
defaults;
|
|
13
25
|
/** The effective automatic tab interval read from settings.xml. Used for display only. */
|
|
14
26
|
defaultTabStopPt;
|
|
15
|
-
/** The paragraph properties at the base of the OOXML formatting hierarchy. */
|
|
16
|
-
paragraphDefaults;
|
|
17
27
|
/** The paper this document is written on, read from the first section. Used for display only: the `w:sectPr` itself goes back out in the preserved tail */
|
|
18
28
|
geometry;
|
|
19
|
-
/**
|
|
20
|
-
|
|
29
|
+
/** Everything the display values of a paragraph or a run are resolved against: the style chain, the defaults, the list definitions */
|
|
30
|
+
formatting;
|
|
21
31
|
/** The paragraph styles this document defines, in the order styles.xml lists them. What the style picker offers */
|
|
22
32
|
paragraphStyles;
|
|
23
|
-
/**
|
|
24
|
-
* The paragraph style every paragraph with no `w:pStyle` of its own wears (`w:default="1"`,
|
|
25
|
-
* usually Normal). null when the document marks none
|
|
26
|
-
*/
|
|
27
|
-
defaultParagraphStyleId;
|
|
28
33
|
/** The raw text of numbering.xml. Kept around so list numbers can be drawn on screen. null if there is none */
|
|
29
34
|
numberingXml;
|
|
30
35
|
/** Where numbering.xml sits inside the zip. When a new list is exported it is rewritten at that spot. null if there is none */
|
|
@@ -36,6 +41,7 @@ var SessionStore = class {
|
|
|
36
41
|
/** First-section header and footer stories projected for the page preview. */
|
|
37
42
|
headersFooters;
|
|
38
43
|
constructor(opened) {
|
|
44
|
+
this.sessionId = opened.sessionId;
|
|
39
45
|
this.parts = opened.parts;
|
|
40
46
|
this.mainPartPath = opened.mainPartPath;
|
|
41
47
|
this.documentPrefix = opened.documentPrefix;
|
|
@@ -44,11 +50,9 @@ var SessionStore = class {
|
|
|
44
50
|
this.blocks = opened.blocks;
|
|
45
51
|
this.defaults = opened.defaults;
|
|
46
52
|
this.defaultTabStopPt = opened.defaultTabStopPt;
|
|
47
|
-
this.paragraphDefaults = opened.paragraphDefaults;
|
|
48
53
|
this.geometry = opened.geometry;
|
|
49
|
-
this.
|
|
54
|
+
this.formatting = opened.formatting;
|
|
50
55
|
this.paragraphStyles = opened.paragraphStyles;
|
|
51
|
-
this.defaultParagraphStyleId = opened.defaultParagraphStyleId;
|
|
52
56
|
this.numberingXml = opened.numberingXml;
|
|
53
57
|
this.numberingPartPath = opened.numberingPartPath;
|
|
54
58
|
this.comments = opened.comments;
|
|
@@ -63,17 +67,49 @@ function sessionOf(session) {
|
|
|
63
67
|
function documentPartPath(session) {
|
|
64
68
|
return sessionOf(session).mainPartPath;
|
|
65
69
|
}
|
|
66
|
-
function documentNumbering(session) {
|
|
67
|
-
|
|
70
|
+
function documentNumbering(session, options) {
|
|
71
|
+
const store = sessionOf(session);
|
|
72
|
+
return parseNumbering(store.numberingXml, {
|
|
73
|
+
...numberingOptionsFor(
|
|
74
|
+
store.formatting.styles,
|
|
75
|
+
store.formatting.themeFonts
|
|
76
|
+
),
|
|
77
|
+
...options
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var BODY_STORY_KEY = "body";
|
|
81
|
+
function blockKey(session, storyKey, index) {
|
|
82
|
+
return `${session.sessionId}:${storyKey}:${index}`;
|
|
83
|
+
}
|
|
84
|
+
function splitBlockKey(key) {
|
|
85
|
+
const first = key.indexOf(":");
|
|
86
|
+
const last = key.lastIndexOf(":");
|
|
87
|
+
if (first < 1 || last <= first + 1) return null;
|
|
88
|
+
const indexText = key.slice(last + 1);
|
|
89
|
+
if (!/^\d+$/.test(indexText)) return null;
|
|
90
|
+
const index = Number(indexText);
|
|
91
|
+
if (!Number.isSafeInteger(index)) return null;
|
|
92
|
+
return {
|
|
93
|
+
sessionId: key.slice(0, first),
|
|
94
|
+
storyKey: key.slice(first + 1, last),
|
|
95
|
+
index
|
|
96
|
+
};
|
|
68
97
|
}
|
|
69
98
|
function originalBlock(node, session) {
|
|
70
99
|
const srcId = node.attrs.srcId;
|
|
71
|
-
|
|
100
|
+
if (typeof srcId !== "string") return void 0;
|
|
101
|
+
const key = splitBlockKey(srcId);
|
|
102
|
+
if (key === null || key.sessionId !== session.sessionId) return void 0;
|
|
103
|
+
return key.storyKey === BODY_STORY_KEY ? session.blocks[key.index] : void 0;
|
|
72
104
|
}
|
|
73
105
|
export {
|
|
106
|
+
BODY_STORY_KEY,
|
|
74
107
|
SessionStore,
|
|
108
|
+
blockKey,
|
|
75
109
|
documentNumbering,
|
|
76
110
|
documentPartPath,
|
|
111
|
+
newSessionId,
|
|
77
112
|
originalBlock,
|
|
78
|
-
sessionOf
|
|
113
|
+
sessionOf,
|
|
114
|
+
splitBlockKey
|
|
79
115
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which parts of a table one cell belongs to, and what its table style dresses those parts with.
|
|
3
|
+
*
|
|
4
|
+
* A table style says one thing for the header row, another for the first column, another for the
|
|
5
|
+
* banded rows (`w:tblStylePr`), and `w:tblLook` says which of those a table takes at all. Every
|
|
6
|
+
* caller that asks what a cell falls back on - the import, a table created fresh, the lines derived
|
|
7
|
+
* again after the grid moved, and a cell formatting edit - asks here, so a cell is dressed the same
|
|
8
|
+
* whichever of them asked.
|
|
9
|
+
*
|
|
10
|
+
* A conditional format writes the lines of the part it dresses rather than of every cell in it:
|
|
11
|
+
* its four sides are drawn where a cell lies on the edge of that part and its inside lines between
|
|
12
|
+
* the cells within it, which is the same rule the table's own lines are drawn by.
|
|
13
|
+
*/
|
|
14
|
+
import type { BandSizes, CellMargins, InsideBorders, TableFormat, TableStyleConditions, TableStyleOverrideType } from "../../model/format";
|
|
15
|
+
import { type CellDefaults, type GridRect, type GridSize } from "./reading";
|
|
16
|
+
/** Which parts of its table style a table takes (`w:tblLook`, §17.4.55) */
|
|
17
|
+
export interface TableLook {
|
|
18
|
+
firstRow: boolean;
|
|
19
|
+
lastRow: boolean;
|
|
20
|
+
firstColumn: boolean;
|
|
21
|
+
lastColumn: boolean;
|
|
22
|
+
noHBand: boolean;
|
|
23
|
+
noVBand: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a table writing no `w:tblLook` at all takes: the banded rows and columns, and neither the
|
|
27
|
+
* header row, the last row, nor the edge columns (§17.4.55). Switching the banding off is
|
|
28
|
+
* something a table has to say, which is why both band settings are worded as `no`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const NO_LOOK: TableLook;
|
|
31
|
+
/**
|
|
32
|
+
* Which parts of its table style this table takes.
|
|
33
|
+
*
|
|
34
|
+
* The six attributes are what a document writes today; where one of them is missing the legacy
|
|
35
|
+
* bitmask answers for it, so a document written either way reads the same.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readTableLook(tblPr: Element | null): TableLook;
|
|
38
|
+
/** One conditional format a cell takes, and the part of the grid it dresses */
|
|
39
|
+
export interface CellCondition {
|
|
40
|
+
type: TableStyleOverrideType;
|
|
41
|
+
/** Its four lines are drawn on the edge of this block, and its inside lines within it */
|
|
42
|
+
region: GridRect;
|
|
43
|
+
}
|
|
44
|
+
/** Where a cell sits, and which parts of the table it therefore belongs to */
|
|
45
|
+
export interface CellPlacement {
|
|
46
|
+
rect: GridRect;
|
|
47
|
+
grid: GridSize;
|
|
48
|
+
/** Lowest first, in the order §17.7.6 lays them over one another */
|
|
49
|
+
conditions: readonly CellCondition[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The parts of the table this cell belongs to, lowest first.
|
|
53
|
+
*
|
|
54
|
+
* A cell sits in a row band by the row it starts in and in a column band by the column it starts
|
|
55
|
+
* in, and it is a corner only where the table takes both the row and the column that meet there.
|
|
56
|
+
*/
|
|
57
|
+
export declare function cellPlacement(rect: GridRect, grid: GridSize, look: TableLook, bands: BandSizes): CellPlacement;
|
|
58
|
+
/** What a table lays down for its cells to draw. What its style laid down is not in the `tblPr`, so it comes along separately */
|
|
59
|
+
export interface TableCellSources {
|
|
60
|
+
outer: TableFormat | null;
|
|
61
|
+
inside: InsideBorders;
|
|
62
|
+
margins: CellMargins;
|
|
63
|
+
/** The parts of its style the table takes */
|
|
64
|
+
look: TableLook;
|
|
65
|
+
bands: BandSizes;
|
|
66
|
+
/** What the style dresses each of those parts with */
|
|
67
|
+
conditions: TableStyleConditions;
|
|
68
|
+
/** The style the paragraphs inside the cells resolve against. null for a table wearing none */
|
|
69
|
+
styleId: string | null;
|
|
70
|
+
}
|
|
71
|
+
export declare const NO_CELL_SOURCES: TableCellSources;
|
|
72
|
+
/**
|
|
73
|
+
* What the cell covering this block of the grid falls back on: the table's own lines and margins,
|
|
74
|
+
* with every conditional format its style dresses a part it belongs to with laid over them.
|
|
75
|
+
*/
|
|
76
|
+
export declare function cellDefaultsFor(rect: GridRect, grid: GridSize, sources: TableCellSources): CellDefaults;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// src/docx/tableFormatting/conditions.ts
|
|
2
|
+
import { ST_OnOff } from "../../ooxml/simpleTypes.js";
|
|
3
|
+
import { borderLineOfCss, wAttr } from "../../ooxml/units.js";
|
|
4
|
+
import { childByLocalName } from "../../ooxml/xml.js";
|
|
5
|
+
import {
|
|
6
|
+
layerCellMargins,
|
|
7
|
+
NO_BAND_SIZES,
|
|
8
|
+
NO_CELL_MARGINS,
|
|
9
|
+
NO_INSIDE_BORDERS,
|
|
10
|
+
NO_TABLE_STYLE_CONDITIONS
|
|
11
|
+
} from "./reading.js";
|
|
12
|
+
var NO_LOOK = {
|
|
13
|
+
firstRow: false,
|
|
14
|
+
lastRow: false,
|
|
15
|
+
firstColumn: false,
|
|
16
|
+
lastColumn: false,
|
|
17
|
+
noHBand: false,
|
|
18
|
+
noVBand: false
|
|
19
|
+
};
|
|
20
|
+
var LEGACY_LOOK_BITS = {
|
|
21
|
+
firstRow: 32,
|
|
22
|
+
lastRow: 64,
|
|
23
|
+
firstColumn: 128,
|
|
24
|
+
lastColumn: 256,
|
|
25
|
+
noHBand: 512,
|
|
26
|
+
noVBand: 1024
|
|
27
|
+
};
|
|
28
|
+
var SHORT_HEX = /^[0-9a-fA-F]{4}$/;
|
|
29
|
+
function legacyLook(value) {
|
|
30
|
+
const bits = value !== null && SHORT_HEX.test(value) ? Number.parseInt(value, 16) : 0;
|
|
31
|
+
return {
|
|
32
|
+
firstRow: (bits & LEGACY_LOOK_BITS.firstRow) !== 0,
|
|
33
|
+
lastRow: (bits & LEGACY_LOOK_BITS.lastRow) !== 0,
|
|
34
|
+
firstColumn: (bits & LEGACY_LOOK_BITS.firstColumn) !== 0,
|
|
35
|
+
lastColumn: (bits & LEGACY_LOOK_BITS.lastColumn) !== 0,
|
|
36
|
+
noHBand: (bits & LEGACY_LOOK_BITS.noHBand) !== 0,
|
|
37
|
+
noVBand: (bits & LEGACY_LOOK_BITS.noVBand) !== 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function readTableLook(tblPr) {
|
|
41
|
+
const el = tblPr ? childByLocalName(tblPr, "tblLook") : null;
|
|
42
|
+
if (!el) return NO_LOOK;
|
|
43
|
+
const legacy = legacyLook(wAttr(el, "val"));
|
|
44
|
+
const written = (name) => ST_OnOff.parse(wAttr(el, name)) ?? legacy[name];
|
|
45
|
+
return {
|
|
46
|
+
firstRow: written("firstRow"),
|
|
47
|
+
lastRow: written("lastRow"),
|
|
48
|
+
firstColumn: written("firstColumn"),
|
|
49
|
+
lastColumn: written("lastColumn"),
|
|
50
|
+
noHBand: written("noHBand"),
|
|
51
|
+
noVBand: written("noVBand")
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function bandWidth(size) {
|
|
55
|
+
return size ?? 1;
|
|
56
|
+
}
|
|
57
|
+
function bandedRows(grid, look) {
|
|
58
|
+
return [look.firstRow ? 1 : 0, look.lastRow ? grid.rows - 1 : grid.rows];
|
|
59
|
+
}
|
|
60
|
+
function bandedColumns(grid, look) {
|
|
61
|
+
return [
|
|
62
|
+
look.firstColumn ? 1 : 0,
|
|
63
|
+
look.lastColumn ? grid.cols - 1 : grid.cols
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
function bandAt(at, [from, to], size) {
|
|
67
|
+
if (at < from || at >= to) return null;
|
|
68
|
+
const index = Math.floor((at - from) / size);
|
|
69
|
+
return {
|
|
70
|
+
first: index % 2 === 0,
|
|
71
|
+
start: from + index * size,
|
|
72
|
+
end: Math.min(from + (index + 1) * size, to)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function rowsOf(grid, top, bottom) {
|
|
76
|
+
return { top, bottom, left: 0, right: grid.cols };
|
|
77
|
+
}
|
|
78
|
+
function columnsOf(grid, left, right) {
|
|
79
|
+
return { top: 0, bottom: grid.rows, left, right };
|
|
80
|
+
}
|
|
81
|
+
function cellPlacement(rect, grid, look, bands) {
|
|
82
|
+
const found = [];
|
|
83
|
+
const add = (type, region) => {
|
|
84
|
+
found.push({ type, region });
|
|
85
|
+
};
|
|
86
|
+
add("wholeTable", rowsOf(grid, 0, grid.rows));
|
|
87
|
+
const column = look.noVBand ? null : bandAt(rect.left, bandedColumns(grid, look), bandWidth(bands.col));
|
|
88
|
+
if (column) {
|
|
89
|
+
add(
|
|
90
|
+
column.first ? "band1Vert" : "band2Vert",
|
|
91
|
+
columnsOf(grid, column.start, column.end)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const row = look.noHBand ? null : bandAt(rect.top, bandedRows(grid, look), bandWidth(bands.row));
|
|
95
|
+
if (row) {
|
|
96
|
+
add(
|
|
97
|
+
row.first ? "band1Horz" : "band2Horz",
|
|
98
|
+
rowsOf(grid, row.start, row.end)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const firstRow = look.firstRow && rect.top === 0;
|
|
102
|
+
const lastRow = look.lastRow && rect.bottom === grid.rows && grid.rows > 1;
|
|
103
|
+
const firstCol = look.firstColumn && rect.left === 0;
|
|
104
|
+
const lastCol = look.lastColumn && rect.right === grid.cols && grid.cols > 1;
|
|
105
|
+
if (firstRow) add("firstRow", rowsOf(grid, 0, 1));
|
|
106
|
+
if (lastRow) add("lastRow", rowsOf(grid, grid.rows - 1, grid.rows));
|
|
107
|
+
if (firstCol) add("firstCol", columnsOf(grid, 0, 1));
|
|
108
|
+
if (lastCol) add("lastCol", columnsOf(grid, grid.cols - 1, grid.cols));
|
|
109
|
+
const corner = (type, top, left) => {
|
|
110
|
+
add(type, { top, bottom: top + 1, left, right: left + 1 });
|
|
111
|
+
};
|
|
112
|
+
if (firstRow && firstCol) corner("nwCell", 0, 0);
|
|
113
|
+
if (firstRow && lastCol) corner("neCell", 0, grid.cols - 1);
|
|
114
|
+
if (lastRow && firstCol) corner("swCell", grid.rows - 1, 0);
|
|
115
|
+
if (lastRow && lastCol) corner("seCell", grid.rows - 1, grid.cols - 1);
|
|
116
|
+
return { rect, grid, conditions: found };
|
|
117
|
+
}
|
|
118
|
+
var NO_CELL_SOURCES = {
|
|
119
|
+
outer: null,
|
|
120
|
+
inside: NO_INSIDE_BORDERS,
|
|
121
|
+
margins: NO_CELL_MARGINS,
|
|
122
|
+
look: NO_LOOK,
|
|
123
|
+
bands: NO_BAND_SIZES,
|
|
124
|
+
conditions: NO_TABLE_STYLE_CONDITIONS,
|
|
125
|
+
styleId: null
|
|
126
|
+
};
|
|
127
|
+
function edgesIn(rect, region) {
|
|
128
|
+
return {
|
|
129
|
+
top: rect.top === region.top,
|
|
130
|
+
bottom: rect.bottom === region.bottom,
|
|
131
|
+
left: rect.left === region.left,
|
|
132
|
+
right: rect.right === region.right
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function tableBorderDefaults(edges, outer, inside) {
|
|
136
|
+
return {
|
|
137
|
+
top: borderLineOfCss(
|
|
138
|
+
edges.top ? outer?.borderTop ?? null : inside.horizontal
|
|
139
|
+
),
|
|
140
|
+
bottom: borderLineOfCss(
|
|
141
|
+
edges.bottom ? outer?.borderBottom ?? null : inside.horizontal
|
|
142
|
+
),
|
|
143
|
+
left: borderLineOfCss(
|
|
144
|
+
edges.left ? outer?.borderLeft ?? null : inside.vertical
|
|
145
|
+
),
|
|
146
|
+
right: borderLineOfCss(
|
|
147
|
+
edges.right ? outer?.borderRight ?? null : inside.vertical
|
|
148
|
+
)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function conditionBorderDefaults(base, format, edges) {
|
|
152
|
+
const line = (onEdge, edge, within) => borderLineOfCss(onEdge ? edge : within);
|
|
153
|
+
return {
|
|
154
|
+
top: line(edges.top, format.borders.top, format.inside.horizontal) ?? base.top,
|
|
155
|
+
bottom: line(edges.bottom, format.borders.bottom, format.inside.horizontal) ?? base.bottom,
|
|
156
|
+
left: line(edges.left, format.borders.left, format.inside.vertical) ?? base.left,
|
|
157
|
+
right: line(edges.right, format.borders.right, format.inside.vertical) ?? base.right
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function cellDefaultsFor(rect, grid, sources) {
|
|
161
|
+
const placement = cellPlacement(rect, grid, sources.look, sources.bands);
|
|
162
|
+
const whole = { top: 0, bottom: grid.rows, left: 0, right: grid.cols };
|
|
163
|
+
let borders = tableBorderDefaults(
|
|
164
|
+
edgesIn(rect, whole),
|
|
165
|
+
sources.outer,
|
|
166
|
+
sources.inside
|
|
167
|
+
);
|
|
168
|
+
let margins = sources.margins;
|
|
169
|
+
let background = null;
|
|
170
|
+
let verticalAlign = null;
|
|
171
|
+
for (const { type, region } of placement.conditions) {
|
|
172
|
+
const format = sources.conditions[type];
|
|
173
|
+
if (!format) continue;
|
|
174
|
+
borders = conditionBorderDefaults(borders, format, edgesIn(rect, region));
|
|
175
|
+
margins = layerCellMargins(margins, format.margins);
|
|
176
|
+
background = format.background ?? background;
|
|
177
|
+
verticalAlign = format.verticalAlign ?? verticalAlign;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
borders,
|
|
181
|
+
margins,
|
|
182
|
+
background,
|
|
183
|
+
verticalAlign,
|
|
184
|
+
placement: {
|
|
185
|
+
tableStyleId: sources.styleId,
|
|
186
|
+
conditions: placement.conditions.map((condition) => condition.type)
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
NO_CELL_SOURCES,
|
|
192
|
+
NO_LOOK,
|
|
193
|
+
cellDefaultsFor,
|
|
194
|
+
cellPlacement,
|
|
195
|
+
readTableLook
|
|
196
|
+
};
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* only the child and attributes named by the edit are changed, and unsupported formatting stays
|
|
4
4
|
* untouched.
|
|
5
5
|
*/
|
|
6
|
-
import type { CellFormat,
|
|
7
|
-
import { type
|
|
6
|
+
import type { CellFormat, CellVerticalAlign, RowFormat } from "../../model/format";
|
|
7
|
+
import { type CellDefaults } from "./reading";
|
|
8
8
|
export interface CellProps {
|
|
9
9
|
/** The whole `<w:tcPr>...</w:tcPr>` XML. null for a cell with no formatting */
|
|
10
10
|
tcPr: string | null;
|
|
@@ -45,11 +45,15 @@ export type CellFormatEdit =
|
|
|
45
45
|
/**
|
|
46
46
|
* The cell formatting XML and display values after one piece of formatting is changed.
|
|
47
47
|
*
|
|
48
|
+
* What the cell falls back on is what an edit measures against: switching a side off writes `none`
|
|
49
|
+
* over whatever line was being drawn there, and recoloring writes only where a line is drawn at
|
|
50
|
+
* all, so the defaults handed in have to be the ones the cell is actually drawn with.
|
|
51
|
+
*
|
|
48
52
|
* null when there is nothing to do: a fragment whose shape could not be made out, a value that
|
|
49
53
|
* cannot be written into the document, or a cell already in the state the job wants. In every one
|
|
50
54
|
* of those cases the cell keeps its original XML.
|
|
51
55
|
*/
|
|
52
|
-
export declare function editCellProps(tcPr: string | null, edit: CellFormatEdit, defaults?:
|
|
56
|
+
export declare function editCellProps(tcPr: string | null, edit: CellFormatEdit, defaults?: CellDefaults): CellProps | null;
|
|
53
57
|
/**
|
|
54
58
|
* Whether the cell's own formatting draws a line on any side.
|
|
55
59
|
* A border color has nothing to act on when it does not, because the lines on screen are then the
|