@portone/docx-editor 0.6.0 → 0.6.2
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 +40 -0
- package/dist/DocxEditor.js +84 -26
- package/dist/core.d.ts +4 -3
- package/dist/docx/exportDocx.d.ts +3 -2
- package/dist/docx/exportDocx.js +6 -10
- package/dist/docx/headersFooters.js +35 -23
- package/dist/docx/identities.d.ts +30 -0
- package/dist/docx/identities.js +43 -10
- package/dist/docx/importDocx.js +25 -26
- package/dist/docx/importParagraph.d.ts +1 -4
- package/dist/docx/importParagraph.js +4 -18
- package/dist/docx/invariants.d.ts +13 -10
- package/dist/docx/invariants.js +300 -116
- package/dist/docx/newLists.js +12 -3
- package/dist/docx/notes/newNote.d.ts +39 -0
- package/dist/docx/notes/newNote.js +122 -0
- package/dist/docx/notes/numbering.d.ts +27 -0
- package/dist/docx/notes/numbering.js +113 -0
- package/dist/docx/notes/reading.d.ts +58 -0
- package/dist/docx/notes/reading.js +98 -0
- package/dist/docx/notes/references.d.ts +33 -0
- package/dist/docx/notes/references.js +37 -0
- package/dist/docx/notes/writing.d.ts +19 -0
- package/dist/docx/notes/writing.js +95 -0
- package/dist/docx/partPlan.d.ts +3 -0
- package/dist/docx/partPlanners.d.ts +13 -0
- package/dist/docx/partPlanners.js +48 -0
- package/dist/docx/sections.d.ts +5 -0
- package/dist/docx/sections.js +7 -2
- package/dist/docx/serializeParagraph.js +7 -2
- package/dist/docx/serializePreserved.d.ts +5 -1
- package/dist/docx/serializePreserved.js +24 -7
- package/dist/docx/session.d.ts +5 -0
- package/dist/docx/session.js +6 -0
- package/dist/docx/storyParts.d.ts +133 -0
- package/dist/docx/storyParts.js +314 -0
- package/dist/editor/clipboard/htmlReader.d.ts +24 -4
- package/dist/editor/clipboard/htmlReader.js +39 -4
- package/dist/editor/clipboard/internalChannel.d.ts +30 -3
- package/dist/editor/clipboard/internalChannel.js +43 -3
- package/dist/editor/clipboard/normalizers.d.ts +35 -8
- package/dist/editor/clipboard/normalizers.js +60 -11
- package/dist/editor/clipboard/plugin.js +42 -22
- package/dist/editor/commands/exportQueries.d.ts +4 -3
- package/dist/editor/commands/index.d.ts +2 -1
- package/dist/editor/commands/index.js +18 -0
- package/dist/editor/commands/noteCommands.d.ts +47 -0
- package/dist/editor/commands/noteCommands.js +95 -0
- package/dist/editor/commands/noteQueries.d.ts +22 -3
- package/dist/editor/commands/noteQueries.js +21 -13
- package/dist/editor/createEditor.js +21 -3
- package/dist/editor/documentStyles.d.ts +3 -0
- package/dist/editor/documentStyles.js +2 -1
- package/dist/editor/editorDocument.d.ts +24 -0
- package/dist/editor/editorDocument.js +34 -4
- package/dist/editor/notes/noteSurface.d.ts +53 -0
- package/dist/editor/notes/noteSurface.js +246 -0
- package/dist/editor/plugins/compositionSelection.d.ts +20 -0
- package/dist/editor/plugins/compositionSelection.js +19 -0
- package/dist/editor/plugins/keymap.d.ts +14 -0
- package/dist/editor/plugins/keymap.js +13 -1
- package/dist/editor/plugins/noteLifecycle.d.ts +18 -0
- package/dist/editor/plugins/noteLifecycle.js +117 -0
- package/dist/editor/plugins/noteNavigation.d.ts +45 -0
- package/dist/editor/plugins/noteNavigation.js +86 -0
- package/dist/editor/plugins/noteNumbering.d.ts +13 -0
- package/dist/editor/plugins/noteNumbering.js +58 -0
- package/dist/editor/plugins/rowResize.js +2 -7
- package/dist/editor/plugins/tabLayout.js +2 -7
- package/dist/editor/stories/storyMarkup.d.ts +24 -0
- package/dist/editor/stories/storyMarkup.js +35 -0
- package/dist/editor/stories/storyState.d.ts +34 -0
- package/dist/editor/stories/storyState.js +74 -0
- package/dist/editor/stories/storyView.d.ts +115 -0
- package/dist/editor/stories/storyView.js +144 -0
- package/dist/index.d.ts +2 -2
- package/dist/numbering/spellers.d.ts +1 -1
- package/dist/numbering/spellers.js +6 -1
- package/dist/ooxml/errors.d.ts +135 -2
- package/dist/ooxml/errors.js +6 -0
- package/dist/page/blockKinds.d.ts +23 -4
- package/dist/page/demands/footnoteDemands.d.ts +18 -0
- package/dist/page/demands/footnoteDemands.js +51 -0
- package/dist/page/demands/index.d.ts +43 -0
- package/dist/page/demands/index.js +8 -0
- package/dist/page/kinds/paragraphKind.js +7 -1
- package/dist/page/kinds/tableKind.js +9 -1
- package/dist/page/measureBlocks.d.ts +2 -0
- package/dist/page/measureBlocks.js +31 -10
- package/dist/page/pageDecorations.d.ts +9 -2
- package/dist/page/pageDecorations.js +18 -5
- package/dist/page/pageLayout.d.ts +77 -1
- package/dist/page/pageLayout.js +186 -9
- package/dist/page/usePageLayout.d.ts +57 -2
- package/dist/page/usePageLayout.js +50 -5
- package/dist/schema/attrRoles.js +3 -2
- package/dist/schema/docxSchema.js +5 -2
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +1 -2
- package/dist/schema/preservedGuards.d.ts +4 -6
- package/dist/schema/preservedGuards.js +0 -9
- package/dist/schema/stories.d.ts +42 -2
- package/dist/schema/stories.js +28 -5
- package/dist/styles/classNames.d.ts +21 -6
- package/dist/styles/classNames.js +21 -6
- package/dist/styles/inlineStyle.d.ts +7 -0
- package/dist/styles/inlineStyle.js +11 -5
- package/dist/styles/visualScale.d.ts +19 -0
- package/dist/styles/visualScale.js +26 -0
- package/dist/styles.css +89 -32
- package/dist/ui/InsertImageButton.d.ts +3 -1
- package/dist/ui/InsertImageButton.js +3 -2
- package/dist/ui/TableMenu.d.ts +5 -2
- package/dist/ui/TableMenu.js +18 -1
- package/dist/ui/TextMenu.d.ts +5 -2
- package/dist/ui/TextMenu.js +21 -6
- package/dist/ui/Toolbar.d.ts +17 -2
- package/dist/ui/Toolbar.js +23 -10
- package/dist/ui/comments/useCommentRailLayout.js +2 -4
- package/dist/ui/noteItems.d.ts +21 -0
- package/dist/ui/noteItems.js +30 -0
- package/dist/ui/notes/NoteAreas.d.ts +73 -0
- package/dist/ui/notes/NoteAreas.js +131 -0
- package/dist/ui/notes/NoteList.d.ts +25 -0
- package/dist/ui/notes/NoteList.js +58 -0
- package/dist/ui/notes/StoryRow.d.ts +75 -0
- package/dist/ui/notes/StoryRow.js +122 -0
- package/dist/ui/notes/noteBands.d.ts +100 -0
- package/dist/ui/notes/noteBands.js +142 -0
- package/dist/ui/notes/noteHeights.d.ts +10 -0
- package/dist/ui/notes/noteHeights.js +24 -0
- package/dist/ui/notes/noteSeparator.d.ts +12 -0
- package/dist/ui/notes/noteSeparator.js +9 -0
- package/dist/ui/notes/useStorySurface.d.ts +68 -0
- package/dist/ui/notes/useStorySurface.js +95 -0
- package/dist/ui/runCommand.d.ts +8 -1
- package/dist/ui/runCommand.js +2 -2
- package/dist/ui/shortcutLabels.d.ts +16 -0
- package/dist/ui/shortcutLabels.js +9 -0
- package/dist/ui/usePageRoom.d.ts +13 -0
- package/dist/ui/usePageRoom.js +31 -0
- package/package.json +1 -1
- package/dist/docx/notes.d.ts +0 -27
- package/dist/docx/notes.js +0 -55
- package/dist/ui/NotesPanel.d.ts +0 -6
- package/dist/ui/NotesPanel.js +0 -33
package/dist/docx/importDocx.js
CHANGED
|
@@ -37,7 +37,12 @@ import { readLinkTargets } from "./hyperlink.js";
|
|
|
37
37
|
import { NO_IMPORT_SOURCES } from "./importParagraph.js";
|
|
38
38
|
import { readImageSources } from "./media.js";
|
|
39
39
|
import { NUMBERING_REL_TYPE } from "./newLists.js";
|
|
40
|
-
import {
|
|
40
|
+
import { withNoteLabels } from "./notes/numbering.js";
|
|
41
|
+
import {
|
|
42
|
+
readNoteNumbering,
|
|
43
|
+
readNotes,
|
|
44
|
+
specialNotesOf
|
|
45
|
+
} from "./notes/reading.js";
|
|
41
46
|
import { readPart, relatedPartPath } from "./packageParts.js";
|
|
42
47
|
import { A4_PORTRAIT } from "./pageGeometry.js";
|
|
43
48
|
import { readRelationships } from "./relationships.js";
|
|
@@ -215,25 +220,13 @@ function readDocx(input) {
|
|
|
215
220
|
);
|
|
216
221
|
const comments = readComments(parts, mainPartPath);
|
|
217
222
|
const notes = readNotes(parts, mainPartPath);
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
endnote: /* @__PURE__ */ new Map()
|
|
221
|
-
};
|
|
222
|
-
const noteLabel = (kind, id) => {
|
|
223
|
-
const labels = noteLabels[kind];
|
|
224
|
-
const existing = labels.get(id);
|
|
225
|
-
if (existing) return existing;
|
|
226
|
-
const label = `${labels.size + 1}`;
|
|
227
|
-
labels.set(id, label);
|
|
228
|
-
return label;
|
|
229
|
-
};
|
|
223
|
+
const noteNumbering = readNoteNumbering(settingsDom);
|
|
224
|
+
const specialNotes = specialNotesOf(notes);
|
|
230
225
|
const sources = {
|
|
231
226
|
images: readImageSources(parts, mainPartPath),
|
|
232
227
|
themeFonts,
|
|
233
228
|
links: readLinkTargets(parts, mainPartPath),
|
|
234
|
-
comments
|
|
235
|
-
notes,
|
|
236
|
-
noteLabel
|
|
229
|
+
comments
|
|
237
230
|
};
|
|
238
231
|
const sessionId = newSessionId();
|
|
239
232
|
const headerFooters = readHeaderFooterStories(
|
|
@@ -275,14 +268,18 @@ function readDocx(input) {
|
|
|
275
268
|
)
|
|
276
269
|
);
|
|
277
270
|
}
|
|
278
|
-
const doc =
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
271
|
+
const doc = withNoteLabels(
|
|
272
|
+
docxSchema.nodes.doc.create(
|
|
273
|
+
{
|
|
274
|
+
sectPr: scan.sectPr,
|
|
275
|
+
stories: Object.fromEntries(
|
|
276
|
+
Array.from(stories, ([key, story]) => [key, story.doc.toJSON()])
|
|
277
|
+
)
|
|
278
|
+
},
|
|
279
|
+
blockNodes
|
|
280
|
+
),
|
|
281
|
+
noteNumbering,
|
|
282
|
+
specialNotes
|
|
286
283
|
);
|
|
287
284
|
return {
|
|
288
285
|
doc,
|
|
@@ -294,7 +291,7 @@ function readDocx(input) {
|
|
|
294
291
|
documentPrefix: scan.prefix,
|
|
295
292
|
documentSuffix: scan.suffix,
|
|
296
293
|
documentHadBom: hadBom,
|
|
297
|
-
blocks:
|
|
294
|
+
blocks: doc.children.map((node, i) => ({
|
|
298
295
|
xml: scan.blocks[i]?.xml ?? "",
|
|
299
296
|
node
|
|
300
297
|
})),
|
|
@@ -308,7 +305,9 @@ function readDocx(input) {
|
|
|
308
305
|
comments,
|
|
309
306
|
commentReferenceIds: new Set(commentReferencesIn(doc).keys()),
|
|
310
307
|
headerFooterStories: headerFooters.refs,
|
|
311
|
-
stories
|
|
308
|
+
stories,
|
|
309
|
+
noteNumbering,
|
|
310
|
+
specialNotes
|
|
312
311
|
})
|
|
313
312
|
};
|
|
314
313
|
}
|
|
@@ -19,11 +19,10 @@ import type { Node as PMNode } from "prosemirror-model";
|
|
|
19
19
|
import { type ImportedComments } from "./comments/reading";
|
|
20
20
|
import { type LinkTargets } from "./hyperlink";
|
|
21
21
|
import type { ImageSources } from "./media";
|
|
22
|
-
import { type ImportedNotes, type NoteKind } from "./notes";
|
|
23
22
|
import { type ThemeFonts } from "./theme";
|
|
24
23
|
/**
|
|
25
24
|
* What the body is read with: the images its drawings can point at, the fonts a theme reference
|
|
26
|
-
* resolves to, the addresses its links can point at, and the
|
|
25
|
+
* resolves to, the addresses its links can point at, and the comments its references name.
|
|
27
26
|
* They travel together from `docx/importDocx` down through the tables to here.
|
|
28
27
|
*/
|
|
29
28
|
export interface ImportSources {
|
|
@@ -31,8 +30,6 @@ export interface ImportSources {
|
|
|
31
30
|
themeFonts: ThemeFonts;
|
|
32
31
|
links: LinkTargets;
|
|
33
32
|
comments: ImportedComments;
|
|
34
|
-
notes: ImportedNotes;
|
|
35
|
-
noteLabel: (kind: NoteKind, id: string) => string;
|
|
36
33
|
}
|
|
37
34
|
export declare const NO_IMPORT_SOURCES: ImportSources;
|
|
38
35
|
/**
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
preservationOf
|
|
21
21
|
} from "./importPreserved.js";
|
|
22
22
|
import { NO_IMAGES } from "./media.js";
|
|
23
|
-
import { NO_NOTES, noteById } from "./notes.js";
|
|
24
23
|
import { NO_THEME_FONTS } from "./theme.js";
|
|
25
24
|
import { wrapperFits, wrapperKindFor } from "./wrappers.js";
|
|
26
25
|
function runMark(run, themeFonts) {
|
|
@@ -47,7 +46,7 @@ function buildImage(el, marks, images) {
|
|
|
47
46
|
marks
|
|
48
47
|
);
|
|
49
48
|
}
|
|
50
|
-
function buildModelledRunChild(el, marks, images, comments
|
|
49
|
+
function buildModelledRunChild(el, marks, images, comments) {
|
|
51
50
|
switch (el.localName) {
|
|
52
51
|
case "t": {
|
|
53
52
|
const text = el.textContent ?? "";
|
|
@@ -102,7 +101,6 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
|
|
|
102
101
|
const id = annotationId(el);
|
|
103
102
|
if (id === null) return null;
|
|
104
103
|
const kind = el.localName === "footnoteReference" ? "footnote" : "endnote";
|
|
105
|
-
const note = noteById(notes, kind, id);
|
|
106
104
|
const written = attributeByLocalName(el, "customMarkFollows");
|
|
107
105
|
const customMarkFollows = written !== null && (ST_OnOff.parse(written) ?? true);
|
|
108
106
|
return [
|
|
@@ -110,7 +108,6 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
|
|
|
110
108
|
{
|
|
111
109
|
kind,
|
|
112
110
|
id,
|
|
113
|
-
label: note ? noteLabel(kind, id) : "?",
|
|
114
111
|
customMarkFollows,
|
|
115
112
|
referenceXml: serializeXml(el)
|
|
116
113
|
},
|
|
@@ -123,7 +120,7 @@ function buildModelledRunChild(el, marks, images, comments, notes, noteLabel) {
|
|
|
123
120
|
return null;
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
|
-
function buildRunNodes(run, images, themeFonts, comments,
|
|
123
|
+
function buildRunNodes(run, images, themeFonts, comments, wrappers = []) {
|
|
127
124
|
const mark = runMark(run, themeFonts);
|
|
128
125
|
const marks = wrappers.reduce(
|
|
129
126
|
(set, wrapper) => wrapper.addToSet(set),
|
|
@@ -134,14 +131,7 @@ function buildRunNodes(run, images, themeFonts, comments, notes, noteLabel, wrap
|
|
|
134
131
|
const policy = policyFor(child, "r");
|
|
135
132
|
if (policy.tier === "model") {
|
|
136
133
|
if (child.localName === "rPr") continue;
|
|
137
|
-
const built = buildModelledRunChild(
|
|
138
|
-
child,
|
|
139
|
-
marks,
|
|
140
|
-
images,
|
|
141
|
-
comments,
|
|
142
|
-
notes,
|
|
143
|
-
noteLabel
|
|
144
|
-
);
|
|
134
|
+
const built = buildModelledRunChild(child, marks, images, comments);
|
|
145
135
|
if (built !== null) {
|
|
146
136
|
nodes.push(...built);
|
|
147
137
|
continue;
|
|
@@ -176,9 +166,7 @@ var NO_IMPORT_SOURCES = {
|
|
|
176
166
|
images: NO_IMAGES,
|
|
177
167
|
themeFonts: NO_THEME_FONTS,
|
|
178
168
|
links: NO_LINK_TARGETS,
|
|
179
|
-
comments: NO_COMMENTS
|
|
180
|
-
notes: NO_NOTES,
|
|
181
|
-
noteLabel: () => "?"
|
|
169
|
+
comments: NO_COMMENTS
|
|
182
170
|
};
|
|
183
171
|
function buildModelledInline(child, sources, depth, wrappers) {
|
|
184
172
|
if (child.localName === "r") {
|
|
@@ -187,8 +175,6 @@ function buildModelledInline(child, sources, depth, wrappers) {
|
|
|
187
175
|
sources.images,
|
|
188
176
|
sources.themeFonts,
|
|
189
177
|
sources.comments,
|
|
190
|
-
sources.notes,
|
|
191
|
-
sources.noteLabel,
|
|
192
178
|
wrappers
|
|
193
179
|
);
|
|
194
180
|
}
|
|
@@ -5,27 +5,30 @@
|
|
|
5
5
|
* would throw, so a screen can ask at edit time what `exportDocx` would say. The list is walked in
|
|
6
6
|
* order and `exportDocx` throws its first entry, which is what keeps the two from disagreeing.
|
|
7
7
|
*
|
|
8
|
+
* A code covers several situations, so each entry also carries the `ExportProblemReason`
|
|
9
|
+
* (`ooxml/errors`) naming the one that was met and the content it is about. Every place a problem
|
|
10
|
+
* is built names its own, rather than a reader telling them apart by the message.
|
|
11
|
+
*
|
|
12
|
+
* What the writer puts out block by block is the body and every side story a part writer rewrites
|
|
13
|
+
* (`exportScopes`), so the invariants over content are asked of each of those in turn: markup
|
|
14
|
+
* refused in the body is refused just the same out of a footnote or a header.
|
|
15
|
+
*
|
|
8
16
|
* The checks inspect model attrs and preserved XML without running the writers. Bookmark
|
|
9
17
|
* fragments and list definitions use the export parser. `assertBookmarkPairs` in `./exportDocx`
|
|
10
18
|
* and `assertPartsParse` in `./partPlan` remain the final checks over the parts as actually written.
|
|
11
19
|
*/
|
|
12
20
|
import type { Node as PMNode } from "prosemirror-model";
|
|
13
|
-
import type {
|
|
21
|
+
import type { ExportProblem } from "../ooxml/errors";
|
|
14
22
|
import type { ExportOptions } from "./exportDocx";
|
|
15
23
|
import { type DocxSession, type SessionStore } from "./session";
|
|
16
|
-
|
|
17
|
-
export interface ExportProblem {
|
|
18
|
-
readonly code: DocxExportErrorCode;
|
|
19
|
-
readonly message: string;
|
|
20
|
-
/** Where the problem stands in the document. Absent for a problem of the package or of the session */
|
|
21
|
-
readonly pos?: number;
|
|
22
|
-
}
|
|
24
|
+
export type { ExportPartName, ExportProblem, ExportProblemReason, ExportProblemStory, ExportStoryKind, } from "../ooxml/errors";
|
|
23
25
|
/** The problems as the writer sees them, for a caller already inside the writer's parser scope */
|
|
24
26
|
export declare function problemsOf(doc: PMNode, session: SessionStore): readonly ExportProblem[];
|
|
25
27
|
/**
|
|
26
28
|
* Known reasons writing this document back would be refused, in the order `exportDocx` would
|
|
27
|
-
* raise them. An empty list does not rule out failures while writing. Each entry carries the code
|
|
28
|
-
* `DocxExportError` would carry,
|
|
29
|
+
* raise them. An empty list does not rule out failures while writing. Each entry carries the code
|
|
30
|
+
* and message the `DocxExportError` would carry, the `reason` naming what the refusal is about,
|
|
31
|
+
* and the position in the document where there is one.
|
|
29
32
|
*
|
|
30
33
|
* The list definitions are read to tell a new list from one the document already had, so this
|
|
31
34
|
* needs an XML parser the way `exportDocx` does and takes the same option.
|