@portone/docx-editor 0.6.3 → 0.6.5
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 +62 -0
- package/dist/DocxEditor.d.ts +11 -0
- package/dist/DocxEditor.js +7 -3
- 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/createEditor.d.ts +4 -1
- package/dist/editor/createEditor.js +14 -2
- package/dist/editor/editRefusal.d.ts +68 -0
- package/dist/editor/editRefusal.js +177 -0
- package/dist/editor/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/plugins/controlContents.d.ts +24 -0
- package/dist/editor/plugins/controlContents.js +260 -0
- package/dist/editor/plugins/controlLifecycle.js +3 -5
- package/dist/editor/plugins/keymap.js +18 -7
- package/dist/editor/stories/storyState.js +2 -0
- package/dist/index.d.ts +2 -0
- 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 +33 -13
- package/dist/schema/controlAttrs.js +18 -6
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +60 -5
- package/dist/schema/guards.d.ts +8 -2
- package/dist/schema/guards.js +14 -8
- package/dist/schema/locks.d.ts +62 -7
- package/dist/schema/locks.js +99 -25
- package/dist/styles/classNames.d.ts +4 -0
- package/dist/styles/classNames.js +4 -0
- package/dist/styles.css +78 -14
- package/dist/ui/MenuNote.d.ts +12 -0
- package/dist/ui/MenuNote.js +14 -0
- package/dist/ui/TableMenu.js +38 -19
- package/dist/ui/TextMenu.js +31 -25
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# @portone/docx-editor
|
|
2
2
|
|
|
3
|
+
## 0.6.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#182](https://github.com/portone-io/docx-editor/pull/182) [`13e5f9f`](https://github.com/portone-io/docx-editor/commit/13e5f9f42d27c047144f3fb22c00b2ac26dae168) Thanks [@Deea222](https://github.com/Deea222)! - Tell the application when an edit is refused, and let it theme locked content.
|
|
8
|
+
|
|
9
|
+
`DocxEditor` takes `onEditRefused`, called when typing, deleting, pasting,
|
|
10
|
+
dropping or formatting in the document body is turned down. It is handed an
|
|
11
|
+
`EditRefusal`: the rule that refused the edit (`lock`, `protection`,
|
|
12
|
+
`controlEdge`, `preserved` or `section`), what the edit would have done, and,
|
|
13
|
+
for a lock, the controls it reached with their `tag`, `alias`, `id`, lock and
|
|
14
|
+
level. Before this a refused keystroke did nothing at all and said nothing.
|
|
15
|
+
|
|
16
|
+
The right-click menus now say "Locked content can't be edited." when the
|
|
17
|
+
selection, or the table under it, holds locked content, which is why their
|
|
18
|
+
editing entries stand disabled.
|
|
19
|
+
|
|
20
|
+
Four custom properties theme how controls are drawn:
|
|
21
|
+
`--docx-editor-locked-background` and `--docx-editor-locked-outline` for locked
|
|
22
|
+
content, which keeps its yellow tint and orange outline by default, and
|
|
23
|
+
`--docx-editor-control-background` and `--docx-editor-control-outline` for a
|
|
24
|
+
content control that stays editable, which is not marked by default.
|
|
25
|
+
|
|
26
|
+
The yellow now shows over a locked table cell or row whose shading the
|
|
27
|
+
document states as `auto`, which used to hide it, and a cell's own shading
|
|
28
|
+
shows through the tint rather than hiding it.
|
|
29
|
+
|
|
30
|
+
- [#183](https://github.com/portone-io/docx-editor/pull/183) [`2423668`](https://github.com/portone-io/docx-editor/commit/242366886c89e96d633d2bc31312f42aaf37e4fd) Thanks [@Deea222](https://github.com/Deea222)! - Keep an inline content control when everything it holds is written over or deleted.
|
|
31
|
+
|
|
32
|
+
Selecting all of the text inside a content control that stands in a paragraph - a bracketed placeholder a template leaves to be filled in, say - and typing over it used to take the control away: the new text landed beside it as ordinary text, and the tag and id a server looks for when it fills the document in were gone. The same happened with a drag carried past the end of the line, a Shift-click, a triple click, a composition, and a paste. The new text now goes into the control, which keeps its tag, its id, and everything else it states, and what is typed next goes on into it.
|
|
33
|
+
|
|
34
|
+
Deleting everything the control holds now leaves the control in the file with nothing inside it, and text typed right after goes back into it. A control locked against deletion alone (`sdtLocked`) takes all of this, since its contents may be edited; before, deleting or retyping everything it held was refused. A selection that also takes in text outside the control still removes the control with that text, and a control locked against deletion still refuses it.
|
|
35
|
+
|
|
36
|
+
## 0.6.4
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [#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.
|
|
41
|
+
|
|
42
|
+
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.
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
- [#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.
|
|
49
|
+
|
|
50
|
+
A file whose main part spells the wordprocessing namespace `ns0:` or leaves
|
|
51
|
+
it as the default namespace - what Python's `xml.etree` writes, and what
|
|
52
|
+
Word and Google Docs both open - used to be refused as content the editor
|
|
53
|
+
cannot write back. Such a package now opens: each part is rewritten to the
|
|
54
|
+
prefixes the editor writes, tag and attribute names only, before anything is
|
|
55
|
+
read, so a comment, a footnote, a header and the body all come through and
|
|
56
|
+
the file goes back out spelled `w:` throughout. A part that had already
|
|
57
|
+
bound `w`, `r` or another prefix the editor writes to a namespace of its own
|
|
58
|
+
is left exactly as it arrived, since respelling it would change what its
|
|
59
|
+
preserved markup means; the checks that applied before still decide such a
|
|
60
|
+
file, so a main part that binds `w` itself to some other namespace - the one
|
|
61
|
+
arrangement no respelling can reach - is refused as it was. A package
|
|
62
|
+
already spelling those prefixes is untouched and still exports byte for
|
|
63
|
+
byte.
|
|
64
|
+
|
|
3
65
|
## 0.6.3
|
|
4
66
|
|
|
5
67
|
### Patch Changes
|
package/dist/DocxEditor.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { type CSSProperties, type ReactNode } from "react";
|
|
|
13
13
|
import { type DocxSource } from "./docx/importDocx";
|
|
14
14
|
import { type ExportProblem } from "./docx/invariants";
|
|
15
15
|
import type { CommentAuthor } from "./editor/commands/commentCommands";
|
|
16
|
+
import type { EditRefusal } from "./editor/editRefusal";
|
|
16
17
|
import { DocxImportError } from "./ooxml/errors";
|
|
17
18
|
import type { EditableComments } from "./schema/protection";
|
|
18
19
|
import type { FontFallbacks } from "./styles/fontStack";
|
|
@@ -145,6 +146,16 @@ export interface DocxEditorProps {
|
|
|
145
146
|
onReady?: (view: EditorView) => void;
|
|
146
147
|
/** Called every time the editor state changes. This covers cursor and selection moves, not just text edits */
|
|
147
148
|
onChange?: () => void;
|
|
149
|
+
/**
|
|
150
|
+
* Called when the editor turns down an edit made in the document body: typing, deleting,
|
|
151
|
+
* pasting or dropping into locked content, or anything the `mode` does not take.
|
|
152
|
+
*
|
|
153
|
+
* The editor itself only leaves the document as it was, so this is where an application says
|
|
154
|
+
* why - a toast, a status line - in its own words. It is called once per refused edit, so a key
|
|
155
|
+
* held down calls it repeatedly. A command reporting `false` dispatches nothing and calls
|
|
156
|
+
* nothing.
|
|
157
|
+
*/
|
|
158
|
+
onEditRefused?: (refusal: EditRefusal) => void;
|
|
148
159
|
}
|
|
149
160
|
/**
|
|
150
161
|
* `forwardRef` rather than a `ref` prop: React 18 hands a function component no `ref`
|
package/dist/DocxEditor.js
CHANGED
|
@@ -178,7 +178,8 @@ function DocxEditorSurface({
|
|
|
178
178
|
className,
|
|
179
179
|
style,
|
|
180
180
|
onReady,
|
|
181
|
-
onChange
|
|
181
|
+
onChange,
|
|
182
|
+
onEditRefused
|
|
182
183
|
}, ref) {
|
|
183
184
|
const { protection, author, editableComments, toolbar, locking } = affordancesOf(mode);
|
|
184
185
|
const bytes = useDocumentBytes(source);
|
|
@@ -209,6 +210,7 @@ function DocxEditorSurface({
|
|
|
209
210
|
);
|
|
210
211
|
const latestOnReady = useLatest(onReady);
|
|
211
212
|
const latestOnChange = useLatest(onChange);
|
|
213
|
+
const latestOnEditRefused = useLatest(onEditRefused);
|
|
212
214
|
const selectedZoom = normalizeZoom(zoom ?? uncontrolledZoom);
|
|
213
215
|
const page = opened?.status === "opened" ? pagePixels(opened.session.geometry) : A4_PAGE_PIXELS;
|
|
214
216
|
const fitWidth = useFitWidthZoom(rootRef, page.pageWidth);
|
|
@@ -237,7 +239,8 @@ function DocxEditorSurface({
|
|
|
237
239
|
keptState.current = { of: opened, state };
|
|
238
240
|
setLive({ view, state });
|
|
239
241
|
latestOnChange.current?.();
|
|
240
|
-
}
|
|
242
|
+
},
|
|
243
|
+
onEditRefused: (refusal) => latestOnEditRefused.current?.(refusal)
|
|
241
244
|
});
|
|
242
245
|
viewRef.current = view;
|
|
243
246
|
keptState.current = { of: opened, state: view.state };
|
|
@@ -254,7 +257,8 @@ function DocxEditorSurface({
|
|
|
254
257
|
mountedFontFallbacks,
|
|
255
258
|
mountedPlugins,
|
|
256
259
|
latestOnReady,
|
|
257
|
-
latestOnChange
|
|
260
|
+
latestOnChange,
|
|
261
|
+
latestOnEditRefused
|
|
258
262
|
]);
|
|
259
263
|
const authorId = author?.id ?? null;
|
|
260
264
|
const mounted = live !== null;
|
|
@@ -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) {
|