@portone/docx-editor 0.6.3 → 0.6.4
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 +29 -0
- package/dist/docx/comments/writing.d.ts +8 -0
- package/dist/docx/comments/writing.js +9 -2
- package/dist/docx/headersFooters.d.ts +7 -0
- package/dist/docx/headersFooters.js +4 -1
- package/dist/docx/identities.d.ts +4 -3
- package/dist/docx/identities.js +14 -1
- package/dist/docx/importDocx.js +2 -0
- package/dist/docx/importParagraph.d.ts +4 -0
- package/dist/docx/importParagraph.js +2 -0
- package/dist/docx/importSdtBlock.d.ts +2 -3
- package/dist/docx/importSdtBlock.js +7 -16
- package/dist/docx/invariants.js +60 -3
- package/dist/docx/numberingPlanner.d.ts +3 -0
- package/dist/docx/numberingPlanner.js +8 -2
- package/dist/docx/packageParts.d.ts +9 -0
- package/dist/docx/packageParts.js +16 -0
- package/dist/docx/packagePrefixes.d.ts +12 -0
- package/dist/docx/packagePrefixes.js +18 -0
- package/dist/docx/partPlan.js +3 -5
- package/dist/docx/sdt.d.ts +27 -0
- package/dist/docx/sdt.js +14 -1
- package/dist/docx/serializeBlock.js +4 -3
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +6 -1
- package/dist/docx/serializeSdtBlock.d.ts +0 -8
- package/dist/docx/serializeSdtBlock.js +1 -5
- package/dist/docx/storyParts.d.ts +3 -0
- package/dist/docx/storyParts.js +4 -1
- package/dist/docx/wrappers.d.ts +23 -8
- package/dist/docx/wrappers.js +33 -2
- package/dist/editor/blockControlEdits.d.ts +2 -2
- package/dist/editor/blockControlEdits.js +6 -6
- package/dist/editor/commands/lockCommands.js +25 -5
- package/dist/editor/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/plugins/keymap.js +18 -7
- package/dist/ooxml/element.js +3 -2
- package/dist/ooxml/errors.d.ts +11 -0
- package/dist/ooxml/fragment.js +3 -2
- package/dist/ooxml/names.d.ts +4 -0
- package/dist/ooxml/names.js +8 -2
- package/dist/ooxml/partPrefixes.d.ts +21 -0
- package/dist/ooxml/partPrefixes.js +164 -0
- package/dist/ooxml/partSplice.d.ts +6 -1
- package/dist/ooxml/partSplice.js +30 -10
- package/dist/ooxml/tagScan.d.ts +24 -2
- package/dist/ooxml/tagScan.js +26 -7
- package/dist/ooxml/xml.d.ts +8 -0
- package/dist/ooxml/xml.js +27 -5
- package/dist/schema/attrRoles.js +11 -0
- package/dist/schema/clipboard.js +2 -0
- package/dist/schema/controlAttrs.d.ts +27 -13
- package/dist/schema/controlAttrs.js +14 -6
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +60 -5
- package/dist/schema/locks.d.ts +37 -5
- package/dist/schema/locks.js +33 -15
- package/dist/styles/classNames.d.ts +2 -0
- package/dist/styles/classNames.js +2 -0
- package/dist/styles.css +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @portone/docx-editor
|
|
2
2
|
|
|
3
|
+
## 0.6.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#171](https://github.com/portone-io/docx-editor/pull/171) [`2a610ee`](https://github.com/portone-io/docx-editor/commit/2a610ee732cd2e024e0ce735efa5c91b1ddc9428) Thanks [@Deea222](https://github.com/Deea222)! - Draw nothing for a content control a paragraph holds with nothing inside it.
|
|
8
|
+
|
|
9
|
+
A `w:sdt` standing between the words of a paragraph whose `w:sdtContent` was empty, or which wrote no content element at all, used to open as a dotted box saying the content was preserved. A server that answers a failed condition by leaving a tagged phrase empty - a clause that does not apply, a signing date to be filled in later - therefore drew a box in the middle of a sentence, in every draft, and the reader could neither open it nor take it away. Such a control now opens as a node of its own that holds nothing and takes no width, so the sentence reads on as the file says it should.
|
|
10
|
+
|
|
11
|
+
Everything the control states about itself is kept: its tag, its id, its lock and its data binding all ride back out untouched, a control nobody edited goes out as the bytes it arrived as, and a control standing inside another control or inside a hyperlink still has that wrapper closed around it. Backspace and Delete beside it pass over it and take the character on the far side, as if it were not there, so the control goes only with a selection that covers it, and then only if its lock does not say otherwise; a control holding nothing that carries a lock also keeps a selection covering it from being replaced or deleted. Copying a sentence it stands in leaves the control behind, since it holds nothing to carry, and a document holding one no longer reports it as content that was preserved rather than read, since nothing of it was lost.
|
|
12
|
+
|
|
13
|
+
The control a file writes with nothing inside it between paragraphs, which 0.6.3 released as one that goes only when it is selected whole, now follows the same rule: it can no longer be selected on its own, and a selection covering it is what removes it.
|
|
14
|
+
|
|
15
|
+
- [#172](https://github.com/portone-io/docx-editor/pull/172) [`d882a25`](https://github.com/portone-io/docx-editor/commit/d882a25aac4d0434e4a9d95a79447dcaee4f3b00) Thanks [@Deea222](https://github.com/Deea222)! - Open a document whose WordprocessingML is written under another prefix.
|
|
16
|
+
|
|
17
|
+
A file whose main part spells the wordprocessing namespace `ns0:` or leaves
|
|
18
|
+
it as the default namespace - what Python's `xml.etree` writes, and what
|
|
19
|
+
Word and Google Docs both open - used to be refused as content the editor
|
|
20
|
+
cannot write back. Such a package now opens: each part is rewritten to the
|
|
21
|
+
prefixes the editor writes, tag and attribute names only, before anything is
|
|
22
|
+
read, so a comment, a footnote, a header and the body all come through and
|
|
23
|
+
the file goes back out spelled `w:` throughout. A part that had already
|
|
24
|
+
bound `w`, `r` or another prefix the editor writes to a namespace of its own
|
|
25
|
+
is left exactly as it arrived, since respelling it would change what its
|
|
26
|
+
preserved markup means; the checks that applied before still decide such a
|
|
27
|
+
file, so a main part that binds `w` itself to some other namespace - the one
|
|
28
|
+
arrangement no respelling can reach - is refused as it was. A package
|
|
29
|
+
already spelling those prefixes is untouched and still exports byte for
|
|
30
|
+
byte.
|
|
31
|
+
|
|
3
32
|
## 0.6.3
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Plans changed comment package parts while preserving untouched XML.
|
|
3
3
|
*/
|
|
4
4
|
import type { Node as PMNode } from "prosemirror-model";
|
|
5
|
+
import { type RootDeclarations } from "../../ooxml/partSplice";
|
|
5
6
|
import type { PartPlanner } from "../partPlan";
|
|
6
7
|
import type { SessionStore } from "../session";
|
|
7
8
|
import { type CommentReferenceData, type CommentReplyData } from "./model";
|
|
@@ -22,5 +23,12 @@ export declare function commentsRootProblem(xml: string): string | null;
|
|
|
22
23
|
export declare function extensionsRootProblem(xml: string): string | null;
|
|
23
24
|
/** Whether the extended part has to be rewritten: thread state arrived, changed, or went with a deleted comment */
|
|
24
25
|
export declare function extensionsChanged(doc: PMNode, session: SessionStore): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* What a part carrying comments this editor wrote has to declare. Every entry it writes is spelled
|
|
28
|
+
* under `w`, so the root binds it rather than each entry declaring it again.
|
|
29
|
+
*/
|
|
30
|
+
export declare const COMMENT_MARKUP: RootDeclarations;
|
|
31
|
+
/** What a part carrying the thread an entry belongs to has to declare, its keys being `w15` ones */
|
|
32
|
+
export declare const EXTENSIONS_MARKUP: RootDeclarations;
|
|
25
33
|
export declare function currentCommentBodies(references: ReadonlyMap<string, CommentReferenceData>): ReadonlyMap<string, CommentReferenceData | CommentReplyData>;
|
|
26
34
|
export declare const commentsPlanner: PartPlanner;
|
|
@@ -102,7 +102,7 @@ function extensionsXml(references, comments, originallyReferenced) {
|
|
|
102
102
|
root: EXTENSIONS_ROOT,
|
|
103
103
|
replaceChildren: pieces.join("")
|
|
104
104
|
}),
|
|
105
|
-
|
|
105
|
+
EXTENSIONS_MARKUP
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
var COMMENTS_ROOT = "comments";
|
|
@@ -163,11 +163,16 @@ function renderedComment(comment, arrivedKeyed, arrived, doc, session) {
|
|
|
163
163
|
session
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
var COMMENT_MARKUP = {
|
|
166
|
+
var COMMENT_MARKUP = {
|
|
167
|
+
namespaces: { w: NAMESPACES.w }
|
|
168
|
+
};
|
|
167
169
|
var THREAD_MARKUP = {
|
|
168
170
|
namespaces: { w: NAMESPACES.w, w14: NAMESPACES.w14, mc: NAMESPACES.mc },
|
|
169
171
|
ignorable: ["w14"]
|
|
170
172
|
};
|
|
173
|
+
var EXTENSIONS_MARKUP = {
|
|
174
|
+
namespaces: { w15: NAMESPACES.w15 }
|
|
175
|
+
};
|
|
171
176
|
function currentCommentBodies(references) {
|
|
172
177
|
const comments = /* @__PURE__ */ new Map();
|
|
173
178
|
for (const [id, comment] of references) {
|
|
@@ -309,6 +314,8 @@ var commentsPlanner = {
|
|
|
309
314
|
plan: planCommentParts
|
|
310
315
|
};
|
|
311
316
|
export {
|
|
317
|
+
COMMENT_MARKUP,
|
|
318
|
+
EXTENSIONS_MARKUP,
|
|
312
319
|
commentsChanged,
|
|
313
320
|
commentsPlanner,
|
|
314
321
|
commentsRootProblem,
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { Node as PMNode } from "prosemirror-model";
|
|
14
14
|
import { type ParagraphAlign } from "../model/format";
|
|
15
|
+
import { type RootDeclarations } from "../ooxml/partSplice";
|
|
15
16
|
import { type StoryKey } from "../schema/stories";
|
|
16
17
|
import type { PartPlanner } from "./partPlan";
|
|
17
18
|
import { type DocumentSection } from "./sections";
|
|
@@ -96,6 +97,12 @@ export declare function headerFooterOn(variants: HeaderFooterVariants, headersFo
|
|
|
96
97
|
* `PAGE` field prints (§17.16.5.45).
|
|
97
98
|
*/
|
|
98
99
|
export declare function headerFooterText(story: PMNode, page: number, totalPages: number): string;
|
|
100
|
+
/**
|
|
101
|
+
* What a header this editor rewrote has to declare: every block it writes is spelled under `w`, so
|
|
102
|
+
* the part's root binds it rather than each block declaring it again. A part that already binds it
|
|
103
|
+
* - which every one Word writes does - is left exactly as it stands.
|
|
104
|
+
*/
|
|
105
|
+
export declare const HEADER_MARKUP: RootDeclarations;
|
|
99
106
|
/**
|
|
100
107
|
* Writes back the header and footer parts an edit changed, and no others.
|
|
101
108
|
*
|
|
@@ -162,7 +162,9 @@ function paragraphText(paragraph, page, totalPages) {
|
|
|
162
162
|
function headerFooterText(story, page, totalPages) {
|
|
163
163
|
return storyParagraphs(story).map((paragraph) => paragraphText(paragraph, page, totalPages)).join("\n");
|
|
164
164
|
}
|
|
165
|
-
var HEADER_MARKUP = {
|
|
165
|
+
var HEADER_MARKUP = {
|
|
166
|
+
namespaces: { w: NAMESPACES.w }
|
|
167
|
+
};
|
|
166
168
|
function writtenPart(imported, current, session, notes) {
|
|
167
169
|
const written = withUniqueStoryIdentities([{ story: current, frozen: false }]).map(
|
|
168
170
|
(story) => serializeStory(story, imported, imported, {
|
|
@@ -193,6 +195,7 @@ var headerFooterPlanner = {
|
|
|
193
195
|
plan: (doc, session, context) => rewrittenParts(doc, session, context.notes)
|
|
194
196
|
};
|
|
195
197
|
export {
|
|
198
|
+
HEADER_MARKUP,
|
|
196
199
|
displayPageNumber,
|
|
197
200
|
headerFooterOn,
|
|
198
201
|
headerFooterPlanner,
|
|
@@ -53,9 +53,10 @@ export declare const paragraphIdRule: IdentityRule;
|
|
|
53
53
|
* inside another. Each piece after the first opens as a copy with a `w:id` of its own (see
|
|
54
54
|
* `docx/sdt` for what a copy must not carry along).
|
|
55
55
|
*
|
|
56
|
-
* Every carrier `schema/controlAttrs` knows is settled here, the block container
|
|
57
|
-
*
|
|
58
|
-
* one's `w:id` is not a shape §17.5.2.18
|
|
56
|
+
* Every carrier `schema/controlAttrs` knows is settled here, the block container, a wrapped cell
|
|
57
|
+
* or row and either node a control holding nothing stands as alike, each read under its own
|
|
58
|
+
* attribute names: a second control claiming the first one's `w:id` is not a shape §17.5.2.18
|
|
59
|
+
* allows, whichever of them carries it.
|
|
59
60
|
*/
|
|
60
61
|
export declare const controlRule: IdentityRule;
|
|
61
62
|
/**
|
package/dist/docx/identities.js
CHANGED
|
@@ -94,7 +94,20 @@ function rewriteParagraph(paragraph, written) {
|
|
|
94
94
|
renamed = true;
|
|
95
95
|
marks = control.copy.addToSet(control.mark.removeFromSet(marks));
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
const names = controlAttrsOf(child);
|
|
98
|
+
const own = names === null ? null : claimedPrefix(child.attrs, names, written);
|
|
99
|
+
if (names === null || own === null) {
|
|
100
|
+
inline.push(marks === child.marks ? child : child.mark(marks));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
renamed = true;
|
|
104
|
+
inline.push(
|
|
105
|
+
child.type.create(
|
|
106
|
+
{ ...child.attrs, [names.prefix]: own },
|
|
107
|
+
child.content,
|
|
108
|
+
marks
|
|
109
|
+
)
|
|
110
|
+
);
|
|
98
111
|
});
|
|
99
112
|
return renamed ? paragraph.copy(Fragment.fromArray(inline)) : paragraph;
|
|
100
113
|
}
|
package/dist/docx/importDocx.js
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
specialNotesOf
|
|
45
45
|
} from "./notes/reading.js";
|
|
46
46
|
import { readPart, relatedPartPath } from "./packageParts.js";
|
|
47
|
+
import { normalizePackagePrefixes } from "./packagePrefixes.js";
|
|
47
48
|
import { A4_PORTRAIT } from "./pageGeometry.js";
|
|
48
49
|
import { readRelationships } from "./relationships.js";
|
|
49
50
|
import { scanBody } from "./scan.js";
|
|
@@ -170,6 +171,7 @@ function importDocx(input, options) {
|
|
|
170
171
|
function readDocx(input) {
|
|
171
172
|
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
172
173
|
const parts = openParts(bytes);
|
|
174
|
+
normalizePackagePrefixes(parts);
|
|
173
175
|
const mainPartPath = findMainPartPath(parts);
|
|
174
176
|
const mainPart = parts.get(mainPartPath);
|
|
175
177
|
if (!mainPart) {
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* is read as the file wrote it and recorded on the marks (`docx/wrappers`). A link inside a link is
|
|
10
10
|
* the one arrangement no mark can record, and the inner one stays whole as it always has.
|
|
11
11
|
*
|
|
12
|
+
* A wrapper the file wrote with nothing inside it holds no text for a mark to ride on, so the
|
|
13
|
+
* registry says what it opens as instead: a content control becomes a node of its own, wearing the
|
|
14
|
+
* wrappers around it (`docx/wrappers`).
|
|
15
|
+
*
|
|
12
16
|
* Nothing here demotes a paragraph. What the editor has no model for - a field character, a
|
|
13
17
|
* tracked insertion, a symbol, a drawing nobody could read - is kept where it stood, inside its
|
|
14
18
|
* run or beside it, by the rule `docx/importPolicy` gives it for the level it stands at. The
|
|
@@ -181,6 +181,8 @@ function buildModelledInline(child, sources, depth, wrappers) {
|
|
|
181
181
|
const kind = wrapperKindFor(child);
|
|
182
182
|
if (kind) {
|
|
183
183
|
if (!wrapperFits(kind, wrappers)) return null;
|
|
184
|
+
const empty = kind.readEmpty(child, wrappers);
|
|
185
|
+
if (empty) return [empty];
|
|
184
186
|
const reading = kind.read(child, depth, sources);
|
|
185
187
|
if (!reading) return null;
|
|
186
188
|
return buildContent(reading.content, sources, depth + 1, [
|
|
@@ -17,8 +17,7 @@ export type BlockReader = (el: Element) => PMNode;
|
|
|
17
17
|
* `srcId` names the fragment of the session the control was sliced as; a control inside a cell or
|
|
18
18
|
* inside another control was never a fragment of its own and is handed null, as a nested table is.
|
|
19
19
|
*
|
|
20
|
-
* A control holding nothing is read as the atom that draws nothing
|
|
21
|
-
*
|
|
22
|
-
* element a cache of what stood inside rather than the statement itself.
|
|
20
|
+
* A control holding nothing is read as the atom that draws nothing, in either of the two shapes
|
|
21
|
+
* that state it (`./sdt`).
|
|
23
22
|
*/
|
|
24
23
|
export declare function buildSdtBlock(el: Element, srcId: string | null, readBlock: BlockReader): PMNode | null;
|
|
@@ -5,12 +5,7 @@ import {
|
|
|
5
5
|
controlAttrs,
|
|
6
6
|
OWN_CONTROL_ATTRS
|
|
7
7
|
} from "../schema/controlAttrs.js";
|
|
8
|
-
import {
|
|
9
|
-
controlFactsFrom,
|
|
10
|
-
modelsBlockContent,
|
|
11
|
-
readEmptySdt,
|
|
12
|
-
readSdtWrapper
|
|
13
|
-
} from "./sdt.js";
|
|
8
|
+
import { controlFactsFrom, modelsBlockContent, readSdtContents } from "./sdt.js";
|
|
14
9
|
import { nextKey } from "./wrappers.js";
|
|
15
10
|
function controlNodeAttrs(el, srcId, facts) {
|
|
16
11
|
return {
|
|
@@ -21,20 +16,16 @@ function controlNodeAttrs(el, srcId, facts) {
|
|
|
21
16
|
}
|
|
22
17
|
function buildSdtBlock(el, srcId, readBlock) {
|
|
23
18
|
if (!modelsBlockContent(el)) return null;
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
return facts === null ? null : docxSchema.nodes.sdtEmpty.create(controlNodeAttrs(el, srcId, facts));
|
|
28
|
-
}
|
|
29
|
-
const children = elementChildren(wrapper.content);
|
|
30
|
-
if (children.length === 0) {
|
|
19
|
+
const read = readSdtContents(el);
|
|
20
|
+
if (read === null) return null;
|
|
21
|
+
if (read.kind === "nothing") {
|
|
31
22
|
return docxSchema.nodes.sdtEmpty.create(
|
|
32
|
-
controlNodeAttrs(el, srcId,
|
|
23
|
+
controlNodeAttrs(el, srcId, read.facts)
|
|
33
24
|
);
|
|
34
25
|
}
|
|
35
26
|
return docxSchema.nodes.sdtBlock.create(
|
|
36
|
-
controlNodeAttrs(el, srcId, controlFactsFrom(wrapper)),
|
|
37
|
-
|
|
27
|
+
controlNodeAttrs(el, srcId, controlFactsFrom(read.wrapper)),
|
|
28
|
+
elementChildren(read.wrapper.content).map(readBlock)
|
|
38
29
|
);
|
|
39
30
|
}
|
|
40
31
|
export {
|
package/dist/docx/invariants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/docx/invariants.ts
|
|
2
2
|
import { spanCount, toParagraphFormat } from "../model/format.js";
|
|
3
|
+
import {
|
|
4
|
+
rootBindingConflict
|
|
5
|
+
} from "../ooxml/partSplice.js";
|
|
3
6
|
import {
|
|
4
7
|
attributeByLocalName,
|
|
5
8
|
parseXml,
|
|
@@ -27,12 +30,18 @@ import {
|
|
|
27
30
|
peoplePart
|
|
28
31
|
} from "./comments/parts.js";
|
|
29
32
|
import { unrecordedAuthors } from "./comments/people.js";
|
|
30
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
COMMENT_MARKUP,
|
|
35
|
+
currentCommentBodies,
|
|
36
|
+
EXTENSIONS_MARKUP
|
|
37
|
+
} from "./comments/writing.js";
|
|
38
|
+
import { HEADER_MARKUP } from "./headersFooters.js";
|
|
31
39
|
import { identityProblems, identityProblemsInStories } from "./identities.js";
|
|
32
40
|
import { insertedImageSrcs } from "./media.js";
|
|
33
41
|
import { canDefineNewList, newNumIds, startedLists } from "./newLists.js";
|
|
34
42
|
import { firstNoteReferences } from "./notes/references.js";
|
|
35
|
-
import {
|
|
43
|
+
import { NUMBERING_MARKUP } from "./numberingPlanner.js";
|
|
44
|
+
import { CONTENT_TYPES_PATH, readPart, relatedPartPath } from "./packageParts.js";
|
|
36
45
|
import { STORY_ENTRIES_PARTS, STORY_WRITINGS } from "./partPlanners.js";
|
|
37
46
|
import { lostOriginal } from "./serializePreserved.js";
|
|
38
47
|
import {
|
|
@@ -40,6 +49,7 @@ import {
|
|
|
40
49
|
sessionOf
|
|
41
50
|
} from "./session.js";
|
|
42
51
|
import {
|
|
52
|
+
ENTRY_MARKUP,
|
|
43
53
|
rewrittenStories,
|
|
44
54
|
storyChangesOf,
|
|
45
55
|
storyEntriesOf,
|
|
@@ -378,6 +388,52 @@ var notePartRoots = {
|
|
|
378
388
|
(part) => storyEntriesProblems(part, doc, session)
|
|
379
389
|
)
|
|
380
390
|
};
|
|
391
|
+
function rewrittenParts(doc, session) {
|
|
392
|
+
const parts = [];
|
|
393
|
+
const add = (path, xml2, declarations) => {
|
|
394
|
+
if (path !== null && xml2 !== null) parts.push({ path, xml: xml2, declarations });
|
|
395
|
+
};
|
|
396
|
+
for (const { key } of rewrittenStories(STORY_WRITINGS, doc, session)) {
|
|
397
|
+
const { kind, id } = splitStoryKey(key);
|
|
398
|
+
if (kind === "header" || kind === "footer") {
|
|
399
|
+
add(id, readPart(session.parts, id), HEADER_MARKUP);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
for (const part of STORY_ENTRIES_PARTS) {
|
|
403
|
+
const changed = storyChangesOf(doc, session, part.kind).some(
|
|
404
|
+
({ change }) => change !== "kept"
|
|
405
|
+
);
|
|
406
|
+
const path = changed ? relatedPartPath(session.parts, session.mainPartPath, part.relType) : null;
|
|
407
|
+
add(path, readPart(session.parts, path), ENTRY_MARKUP);
|
|
408
|
+
}
|
|
409
|
+
const { xml, extendedXml, extendedPartPath } = session.comments;
|
|
410
|
+
if (commentsChanged(doc, session)) {
|
|
411
|
+
add(commentsPart.pathIn(session), xml, COMMENT_MARKUP);
|
|
412
|
+
}
|
|
413
|
+
if (extensionsChanged(doc, session) && (commentReferencesIn(doc).size > 0 || extendedPartPath !== null)) {
|
|
414
|
+
add(commentsExtendedPart.pathIn(session), extendedXml, EXTENSIONS_MARKUP);
|
|
415
|
+
}
|
|
416
|
+
if (startedLists(doc, session).defined.size > 0) {
|
|
417
|
+
const path = session.numberingPartPath;
|
|
418
|
+
add(path, readPart(session.parts, path), NUMBERING_MARKUP);
|
|
419
|
+
}
|
|
420
|
+
return parts;
|
|
421
|
+
}
|
|
422
|
+
var partRootBindings = {
|
|
423
|
+
name: "partRootBindings",
|
|
424
|
+
check: ({ doc, session }) => rewrittenParts(doc, session).flatMap(
|
|
425
|
+
({ path, xml, declarations }) => {
|
|
426
|
+
const prefix = rootBindingConflict(xml, declarations);
|
|
427
|
+
return prefix === null ? [] : [
|
|
428
|
+
{
|
|
429
|
+
code: "unsupported-content",
|
|
430
|
+
message: `${path} binds ${prefix} to a namespace the writer cannot use`,
|
|
431
|
+
reason: { kind: "conflicting-part-prefix", path, prefix }
|
|
432
|
+
}
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
)
|
|
436
|
+
};
|
|
381
437
|
function noteKeyIn(reason) {
|
|
382
438
|
const story = "story" in reason ? reason.story : null;
|
|
383
439
|
if (story === null) return null;
|
|
@@ -412,7 +468,8 @@ var EXPORT_INVARIANTS = [
|
|
|
412
468
|
storiesHaveWriters,
|
|
413
469
|
mediaContentTypes,
|
|
414
470
|
commentPartRoots,
|
|
415
|
-
notePartRoots
|
|
471
|
+
notePartRoots,
|
|
472
|
+
partRootBindings
|
|
416
473
|
];
|
|
417
474
|
function exportScopes(doc, session) {
|
|
418
475
|
return [
|
|
@@ -7,5 +7,8 @@
|
|
|
7
7
|
* declaration of what it holds asked of the context, so the first list a document takes costs it
|
|
8
8
|
* nothing outside this planner. Nothing is written when no list was started.
|
|
9
9
|
*/
|
|
10
|
+
import { type RootDeclarations } from "../ooxml/partSplice";
|
|
10
11
|
import type { PartPlanner } from "./partPlan";
|
|
12
|
+
/** What a numbering part takes a definition: every list this writer splices in is spelled under `w` */
|
|
13
|
+
export declare const NUMBERING_MARKUP: RootDeclarations;
|
|
11
14
|
export declare const numberingPlanner: PartPlanner;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { addListDefinitions } from "../numbering/writeNumbering.js";
|
|
3
3
|
import { elementXml, xmlnsAttr } from "../ooxml/element.js";
|
|
4
4
|
import { NAMESPACES, wName } from "../ooxml/names.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ensureRootDeclarations
|
|
7
|
+
} from "../ooxml/partSplice.js";
|
|
6
8
|
import { decodeUtf8, encodeUtf8 } from "../ooxml/xml.js";
|
|
7
9
|
import {
|
|
8
10
|
NUMBERING_CONTENT_TYPE,
|
|
@@ -12,6 +14,9 @@ import {
|
|
|
12
14
|
} from "./newLists.js";
|
|
13
15
|
import { availablePartPath } from "./packageParts.js";
|
|
14
16
|
import { directoryOf } from "./relationships.js";
|
|
17
|
+
var NUMBERING_MARKUP = {
|
|
18
|
+
namespaces: { w: NAMESPACES.w }
|
|
19
|
+
};
|
|
15
20
|
function emptyNumberingPart() {
|
|
16
21
|
return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + elementXml(wName("numbering"), [xmlnsAttr("w")]);
|
|
17
22
|
}
|
|
@@ -40,11 +45,12 @@ var numberingPlanner = {
|
|
|
40
45
|
const { text, hadBom } = decodeUtf8(original.bytes);
|
|
41
46
|
const rewritten = ensureRootDeclarations(
|
|
42
47
|
addListDefinitions(text, defined),
|
|
43
|
-
|
|
48
|
+
NUMBERING_MARKUP
|
|
44
49
|
);
|
|
45
50
|
return /* @__PURE__ */ new Map([[original.path, encodeUtf8(rewritten, hadBom)]]);
|
|
46
51
|
}
|
|
47
52
|
};
|
|
48
53
|
export {
|
|
54
|
+
NUMBERING_MARKUP,
|
|
49
55
|
numberingPlanner
|
|
50
56
|
};
|
|
@@ -39,4 +39,13 @@ export interface ContentTypeWriter {
|
|
|
39
39
|
}
|
|
40
40
|
/** XML parts named by OPC content types, even when their URI has no .xml suffix. */
|
|
41
41
|
export declare function declaredXmlParts(types: Uint8Array, paths: Iterable<string>): ReadonlySet<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Which of these parts hold markup: the ones named as XML or as relationships, and the ones the
|
|
44
|
+
* content types declare as XML under a name of their own. Media bytes are neither.
|
|
45
|
+
*
|
|
46
|
+
* The open respells the namespaces of these parts and the export reads back the ones it wrote, so
|
|
47
|
+
* a part one of them took for markup and the other did not would be spelled one way and checked
|
|
48
|
+
* another.
|
|
49
|
+
*/
|
|
50
|
+
export declare function markupParts(paths: Iterable<string>, contentTypes?: Uint8Array): ReadonlySet<string>;
|
|
42
51
|
export declare function contentTypeWriter(parts: ReadonlyMap<string, Uint8Array>): ContentTypeWriter;
|
|
@@ -75,6 +75,21 @@ function declaredXmlParts(types, paths) {
|
|
|
75
75
|
})
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
|
+
var MARKUP_NAME = /\.(?:xml|rels)$/i;
|
|
79
|
+
function markupParts(paths, contentTypes) {
|
|
80
|
+
const named = /* @__PURE__ */ new Set();
|
|
81
|
+
const rest = [];
|
|
82
|
+
for (const path of paths) {
|
|
83
|
+
if (MARKUP_NAME.test(path)) named.add(path);
|
|
84
|
+
else rest.push(path);
|
|
85
|
+
}
|
|
86
|
+
if (contentTypes === void 0 || rest.length === 0) return named;
|
|
87
|
+
try {
|
|
88
|
+
for (const path of declaredXmlParts(contentTypes, rest)) named.add(path);
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
return named;
|
|
92
|
+
}
|
|
78
93
|
function contentTypeWriter(parts) {
|
|
79
94
|
const overrides = /* @__PURE__ */ new Map();
|
|
80
95
|
const defaults = /* @__PURE__ */ new Map();
|
|
@@ -130,6 +145,7 @@ export {
|
|
|
130
145
|
availablePartPath,
|
|
131
146
|
contentTypeWriter,
|
|
132
147
|
declaredXmlParts,
|
|
148
|
+
markupParts,
|
|
133
149
|
readPart,
|
|
134
150
|
relatedPartPath
|
|
135
151
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spelling a whole package under the prefixes this editor writes, as it is opened.
|
|
3
|
+
* `spec/notes/conformance.md` holds the decision and what it rests on.
|
|
4
|
+
*
|
|
5
|
+
* Every reader and every writer re-reads its part out of the one map the session holds, so the
|
|
6
|
+
* rewrite belongs to that map rather than to any one of them: the main part, the comments, the
|
|
7
|
+
* notes, each header and footer and the numbering then all arrive spelled alike.
|
|
8
|
+
*
|
|
9
|
+
* Which parts hold markup is `docx/packageParts`' answer, the one the export reads the parts it
|
|
10
|
+
* wrote back by. A part that comes back unrewritten is never re-encoded.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizePackagePrefixes(parts: Map<string, Uint8Array>): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/docx/packagePrefixes.ts
|
|
2
|
+
import { withEditorPrefixes } from "../ooxml/partPrefixes.js";
|
|
3
|
+
import { decodeUtf8Strictly, encodeUtf8 } from "../ooxml/xml.js";
|
|
4
|
+
import { CONTENT_TYPES_PATH, markupParts } from "./packageParts.js";
|
|
5
|
+
function normalizePackagePrefixes(parts) {
|
|
6
|
+
const markup = markupParts(parts.keys(), parts.get(CONTENT_TYPES_PATH));
|
|
7
|
+
for (const [path, bytes] of parts) {
|
|
8
|
+
if (!markup.has(path)) continue;
|
|
9
|
+
const decoded = decodeUtf8Strictly(bytes);
|
|
10
|
+
if (decoded === null) continue;
|
|
11
|
+
const rewritten = withEditorPrefixes(decoded.text);
|
|
12
|
+
if (rewritten !== decoded.text)
|
|
13
|
+
parts.set(path, encodeUtf8(rewritten, decoded.hadBom));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
normalizePackagePrefixes
|
|
18
|
+
};
|
package/dist/docx/partPlan.js
CHANGED
|
@@ -3,7 +3,7 @@ import { DocxExportError } from "../ooxml/errors.js";
|
|
|
3
3
|
import { decodeUtf8, parseXml } from "../ooxml/xml.js";
|
|
4
4
|
import {
|
|
5
5
|
CONTENT_TYPES_PATH,
|
|
6
|
-
|
|
6
|
+
markupParts
|
|
7
7
|
} from "./packageParts.js";
|
|
8
8
|
import { relsPathOf } from "./relationships.js";
|
|
9
9
|
function runPartPlanners(planners, doc, session, context, prior = /* @__PURE__ */ new Map()) {
|
|
@@ -36,12 +36,10 @@ function runPartPlanners(planners, doc, session, context, prior = /* @__PURE__ *
|
|
|
36
36
|
}
|
|
37
37
|
return parts;
|
|
38
38
|
}
|
|
39
|
-
var XML_PART = /\.(?:xml|rels)$/i;
|
|
40
39
|
function assertPartsParse(replacements, contentTypes) {
|
|
41
|
-
const
|
|
42
|
-
const declared = contentTypes && paths.some((path) => !XML_PART.test(path)) ? declaredXmlParts(contentTypes, paths) : /* @__PURE__ */ new Set();
|
|
40
|
+
const markup = markupParts(replacements.keys(), contentTypes);
|
|
43
41
|
for (const [path, bytes] of replacements) {
|
|
44
|
-
if (!
|
|
42
|
+
if (!markup.has(path)) continue;
|
|
45
43
|
try {
|
|
46
44
|
parseXml(decodeUtf8(bytes).text);
|
|
47
45
|
} catch (cause) {
|
package/dist/docx/sdt.d.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* runs inside a paragraph (`docx/importParagraph`) each read the content their own way, and the
|
|
13
13
|
* wrapper they put back on export is the same string in all of them.
|
|
14
14
|
*/
|
|
15
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
15
16
|
import type { ControlFacts, ControlFlags } from "../schema/controlAttrs";
|
|
16
17
|
/**
|
|
17
18
|
* What a control's `w:sdtPr` states, which is all the editor reads off a control besides the XML
|
|
@@ -46,6 +47,24 @@ export declare function readEmptySdt(el: Element): ControlFacts | null;
|
|
|
46
47
|
* wrapped row cannot come to disagree about what one and the same `w:sdtPr` says.
|
|
47
48
|
*/
|
|
48
49
|
export declare function controlFactsFrom(wrapper: SdtWrapper): ControlFacts;
|
|
50
|
+
/**
|
|
51
|
+
* What one `w:sdt` holds, which is the question the block reader and the inline reader must
|
|
52
|
+
* answer the same way.
|
|
53
|
+
*
|
|
54
|
+
* A control holding nothing takes two shapes - an empty `w:sdtContent`, and no content element at
|
|
55
|
+
* all, which §17.5.2.34 admits because that element is a cache of what stood inside rather than
|
|
56
|
+
* the statement itself - and the two state the same thing. They are told apart here rather than in
|
|
57
|
+
* each reader, so neither level can come to read one of them as content and the other as nothing.
|
|
58
|
+
*/
|
|
59
|
+
export type SdtContents = {
|
|
60
|
+
kind: "nothing";
|
|
61
|
+
facts: ControlFacts;
|
|
62
|
+
} | {
|
|
63
|
+
kind: "content";
|
|
64
|
+
wrapper: SdtWrapper;
|
|
65
|
+
};
|
|
66
|
+
/** What this control holds, and null for a shape this editor does not write back */
|
|
67
|
+
export declare function readSdtContents(el: Element): SdtContents | null;
|
|
49
68
|
/**
|
|
50
69
|
* Whether this control's content may be read as a container of blocks, which is read off the
|
|
51
70
|
* `w:sdtPr` alone so that a control kept whole never has its prefix serialized.
|
|
@@ -66,6 +85,14 @@ export declare const SDT_CLOSING_XML = "</w:sdtContent></w:sdt>";
|
|
|
66
85
|
export declare function sdtOpeningXml(prefix: unknown): string;
|
|
67
86
|
/** One whole control: the opening it arrived with, around content this writer owns */
|
|
68
87
|
export declare function sdtXml(prefix: unknown, content: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* A control holding nothing, wherever it stood: the opening it arrived with around a content tag
|
|
90
|
+
* with nothing in it.
|
|
91
|
+
*
|
|
92
|
+
* A control that arrived writing no content element at all gains one here: §17.5.2.34 makes that
|
|
93
|
+
* element a cache of what stood inside, so the two shapes state the same thing.
|
|
94
|
+
*/
|
|
95
|
+
export declare function serializeEmptyControl(node: PMNode): string;
|
|
69
96
|
/**
|
|
70
97
|
* The number Word writes on every control. Nothing reads it back and it only has to differ
|
|
71
98
|
* from the other controls in the document, so a draw out of the whole 32 bit range is enough.
|
package/dist/docx/sdt.js
CHANGED
|
@@ -79,6 +79,14 @@ function controlFactsFrom(wrapper) {
|
|
|
79
79
|
showingPlaceholder: wrapper.showingPlaceholder
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
+
function readSdtContents(el) {
|
|
83
|
+
const wrapper = readSdtWrapper(el);
|
|
84
|
+
if (!wrapper) {
|
|
85
|
+
const facts = readEmptySdt(el);
|
|
86
|
+
return facts === null ? null : { kind: "nothing", facts };
|
|
87
|
+
}
|
|
88
|
+
return elementChildren(wrapper.content).length === 0 ? { kind: "nothing", facts: controlFactsFrom(wrapper) } : { kind: "content", wrapper };
|
|
89
|
+
}
|
|
82
90
|
var RESTRAINED_TYPES = [
|
|
83
91
|
`{${W_NS}}text`,
|
|
84
92
|
`{${W_NS}}picture`,
|
|
@@ -109,6 +117,9 @@ function sdtOpeningXml(prefix) {
|
|
|
109
117
|
function sdtXml(prefix, content) {
|
|
110
118
|
return sdtOpeningXml(prefix) + content + SDT_CLOSING_XML;
|
|
111
119
|
}
|
|
120
|
+
function serializeEmptyControl(node) {
|
|
121
|
+
return sdtXml(node.attrs.sdtPrefix, "");
|
|
122
|
+
}
|
|
112
123
|
function newControlId() {
|
|
113
124
|
return Math.floor(Math.random() * 2147483647);
|
|
114
125
|
}
|
|
@@ -157,7 +168,9 @@ export {
|
|
|
157
168
|
namesNothing,
|
|
158
169
|
newControlId,
|
|
159
170
|
readEmptySdt,
|
|
171
|
+
readSdtContents,
|
|
160
172
|
readSdtWrapper,
|
|
161
173
|
sdtOpeningXml,
|
|
162
|
-
sdtXml
|
|
174
|
+
sdtXml,
|
|
175
|
+
serializeEmptyControl
|
|
163
176
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// src/docx/serializeBlock.ts
|
|
2
2
|
import { DocxExportError } from "../ooxml/errors.js";
|
|
3
|
-
import { isBlockControl,
|
|
3
|
+
import { isBlockControl, isEmptyBlockControl } from "../schema/controlAttrs.js";
|
|
4
4
|
import { sameSource } from "../schema/sourceEquality.js";
|
|
5
5
|
import { NO_EXPORT_REFS } from "./exportRefs.js";
|
|
6
|
+
import { serializeEmptyControl } from "./sdt.js";
|
|
6
7
|
import { serializeParagraph } from "./serializeParagraph.js";
|
|
7
8
|
import { serializePreservedBlock } from "./serializePreserved.js";
|
|
8
|
-
import { serializeSdtBlock
|
|
9
|
+
import { serializeSdtBlock } from "./serializeSdtBlock.js";
|
|
9
10
|
import { serializeTable } from "./serializeTable.js";
|
|
10
11
|
import { originalBlock } from "./session.js";
|
|
11
12
|
function serializeBlock(node, refs = NO_EXPORT_REFS) {
|
|
@@ -16,7 +17,7 @@ function serializeBlock(node, refs = NO_EXPORT_REFS) {
|
|
|
16
17
|
if (isBlockControl(node)) {
|
|
17
18
|
return serializeSdtBlock(node, refs, serializeBlock);
|
|
18
19
|
}
|
|
19
|
-
if (
|
|
20
|
+
if (isEmptyBlockControl(node)) return serializeEmptyControl(node);
|
|
20
21
|
if (node.type.isInGroup("preserved")) {
|
|
21
22
|
return serializePreservedBlock(node, refs);
|
|
22
23
|
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A fragment the reader kept whole goes back where it stood: one kept inside a run is written as
|
|
7
7
|
* a piece of that run, and one kept beside the runs is written between them, which is what the
|
|
8
|
-
* two content models admit.
|
|
8
|
+
* two content models admit. A content control holding nothing is written between them for the
|
|
9
|
+
* same reason.
|
|
9
10
|
*
|
|
10
11
|
* The inlines are grouped from the outside in: neighbours sharing the outermost wrapper each stands
|
|
11
12
|
* inside go back into it, that grouping is made again one wrapper deeper, and at the bottom the
|
|
@@ -15,7 +15,7 @@ import { wName } from "../ooxml/names.js";
|
|
|
15
15
|
import { escapeXml } from "../ooxml/xml.js";
|
|
16
16
|
import { wrapperMarks } from "../schema/wrappers.js";
|
|
17
17
|
import { NO_EXPORT_REFS } from "./exportRefs.js";
|
|
18
|
-
import { wrapperKindOf } from "./wrappers.js";
|
|
18
|
+
import { emptyWrapperXml, wrapperKindOf } from "./wrappers.js";
|
|
19
19
|
function sameMark(a, b) {
|
|
20
20
|
if (a === null || b === null) return a === b;
|
|
21
21
|
return a.eq(b);
|
|
@@ -118,6 +118,11 @@ function addInline(parts, child, images) {
|
|
|
118
118
|
parts.push({ kind: "raw", xml: preservedXml(child) });
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
+
const empty = emptyWrapperXml(child);
|
|
122
|
+
if (empty !== null) {
|
|
123
|
+
parts.push({ kind: "raw", xml: empty });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
121
126
|
if (child.type.name === "commentStart" || child.type.name === "commentEnd") {
|
|
122
127
|
const original = child.attrs.xml;
|
|
123
128
|
if (typeof original === "string") {
|