@portone/docx-editor 0.4.0 → 0.5.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 +159 -0
- package/assets/editor.png +0 -0
- package/dist/DocxEditor.d.ts +1 -1
- package/dist/DocxEditor.js +44 -25
- package/dist/docx/cloning.js +4 -9
- package/dist/docx/commentOnlyChange.d.ts +5 -3
- package/dist/docx/comments/grammar.d.ts +27 -10
- package/dist/docx/comments/grammar.js +18 -67
- package/dist/docx/comments/model.d.ts +5 -6
- package/dist/docx/comments/model.js +0 -9
- package/dist/docx/comments/parts.d.ts +16 -10
- package/dist/docx/comments/parts.js +65 -13
- package/dist/docx/comments/people.d.ts +11 -3
- package/dist/docx/comments/people.js +20 -6
- package/dist/docx/comments/policy.js +7 -1
- package/dist/docx/comments/reading.d.ts +4 -2
- package/dist/docx/comments/reading.js +1 -14
- package/dist/docx/comments/writing.js +65 -28
- package/dist/docx/exportDocx.js +10 -14
- package/dist/docx/exportRefs.d.ts +8 -3
- package/dist/docx/exportRefs.js +2 -1
- package/dist/docx/fidelity.js +24 -10
- package/dist/docx/fields.d.ts +42 -0
- package/dist/docx/fields.js +76 -0
- package/dist/docx/headersFooters.d.ts +89 -20
- package/dist/docx/headersFooters.js +163 -172
- package/dist/docx/importDocx.d.ts +1 -1
- package/dist/docx/importDocx.js +100 -48
- package/dist/docx/importParagraph.d.ts +16 -4
- package/dist/docx/importParagraph.js +87 -93
- package/dist/docx/importPolicy.d.ts +70 -0
- package/dist/docx/importPolicy.js +190 -0
- package/dist/docx/importPreserved.d.ts +30 -0
- package/dist/docx/importPreserved.js +54 -0
- package/dist/docx/importTable.js +56 -12
- package/dist/docx/invariants.js +16 -18
- package/dist/docx/notes.d.ts +6 -1
- package/dist/docx/notes.js +6 -16
- package/dist/docx/pageGeometry.d.ts +5 -14
- package/dist/docx/pageGeometry.js +0 -12
- package/dist/docx/protectionPolicy.d.ts +13 -5
- package/dist/docx/protectionPolicy.js +32 -22
- package/dist/docx/scan.d.ts +18 -8
- package/dist/docx/scan.js +17 -11
- package/dist/docx/sections.d.ts +126 -0
- package/dist/docx/sections.js +207 -0
- package/dist/docx/serializeBlock.d.ts +13 -4
- package/dist/docx/serializeBlock.js +16 -18
- package/dist/docx/serializeParagraph.d.ts +4 -0
- package/dist/docx/serializeParagraph.js +1 -0
- package/dist/docx/serializePreserved.d.ts +14 -0
- package/dist/docx/serializePreserved.js +24 -0
- package/dist/docx/serializeStory.d.ts +17 -0
- package/dist/docx/serializeStory.js +17 -0
- package/dist/docx/serializeTable.js +10 -13
- package/dist/docx/session.d.ts +23 -6
- package/dist/docx/session.js +26 -5
- package/dist/docx/story.d.ts +140 -0
- package/dist/docx/story.js +237 -0
- package/dist/docx/storyProjection.js +6 -1
- package/dist/editor/clipboard/htmlReader.d.ts +30 -0
- package/dist/editor/{externalClipboard.js → clipboard/htmlReader.js} +39 -223
- package/dist/editor/clipboard/internalChannel.d.ts +57 -0
- package/dist/editor/clipboard/internalChannel.js +58 -0
- package/dist/editor/clipboard/normalizers.d.ts +99 -0
- package/dist/editor/clipboard/normalizers.js +199 -0
- package/dist/editor/clipboard/parser.d.ts +34 -0
- package/dist/editor/clipboard/parser.js +58 -0
- package/dist/editor/clipboard/plugin.d.ts +21 -0
- package/dist/editor/clipboard/plugin.js +320 -0
- package/dist/editor/clipboard/readContext.d.ts +24 -0
- package/dist/editor/clipboard/readContext.js +19 -0
- package/dist/editor/clipboard/readers.d.ts +33 -0
- package/dist/editor/clipboard/readers.js +37 -0
- package/dist/editor/commands/comments/editing.d.ts +26 -6
- package/dist/editor/commands/comments/editing.js +175 -105
- package/dist/editor/commands/comments/model.d.ts +34 -17
- package/dist/editor/commands/comments/model.js +11 -0
- package/dist/editor/commands/comments/reading.d.ts +5 -3
- package/dist/editor/commands/comments/reading.js +8 -58
- package/dist/editor/commands/index.d.ts +2 -2
- package/dist/editor/commands/index.js +2 -0
- package/dist/editor/commands/listCommands.d.ts +6 -0
- package/dist/editor/commands/listCommands.js +3 -2
- package/dist/editor/commands/noteQueries.d.ts +22 -5
- package/dist/editor/commands/noteQueries.js +34 -6
- package/dist/editor/createEditor.js +13 -3
- package/dist/editor/documentStyles.d.ts +26 -4
- package/dist/editor/documentStyles.js +9 -4
- package/dist/editor/imageFiles.d.ts +2 -2
- package/dist/editor/imageFiles.js +2 -0
- package/dist/editor/insertTable.d.ts +1 -1
- package/dist/editor/insertTable.js +2 -2
- package/dist/editor/plainText.d.ts +12 -0
- package/dist/editor/plainText.js +2 -1
- package/dist/editor/plugins/columnResize.js +6 -3
- package/dist/editor/plugins/commentComposer.d.ts +28 -0
- package/dist/editor/plugins/commentComposer.js +46 -0
- package/dist/editor/plugins/commentDecorations.d.ts +29 -2
- package/dist/editor/plugins/commentDecorations.js +89 -15
- package/dist/editor/plugins/documentProjection.d.ts +31 -0
- package/dist/editor/plugins/documentProjection.js +22 -0
- package/dist/editor/plugins/imagePaste.js +15 -8
- package/dist/editor/plugins/linkPanel.d.ts +7 -3
- package/dist/editor/plugins/linkPanel.js +13 -27
- package/dist/editor/plugins/panelState.d.ts +67 -0
- package/dist/editor/plugins/panelState.js +54 -0
- package/dist/editor/plugins/tableContextMenu.d.ts +1 -1
- package/dist/editor/plugins/tableContextMenu.js +30 -47
- package/dist/editor/plugins/textContextMenu.d.ts +1 -1
- package/dist/editor/plugins/textContextMenu.js +30 -47
- package/dist/ooxml/fragment.d.ts +11 -0
- package/dist/ooxml/fragment.js +14 -4
- package/dist/ooxml/image.d.ts +3 -4
- package/dist/ooxml/image.js +50 -5
- package/dist/ooxml/names.d.ts +6 -0
- package/dist/ooxml/names.js +2 -0
- package/dist/ooxml/props.d.ts +8 -0
- package/dist/ooxml/props.js +14 -4
- package/dist/ooxml/rangeMarkers.d.ts +5 -0
- package/dist/ooxml/rangeMarkers.js +24 -0
- package/dist/page/PageGuides.d.ts +7 -3
- package/dist/page/PageGuides.js +13 -24
- package/dist/page/pageLayout.d.ts +64 -5
- package/dist/page/pageLayout.js +90 -29
- package/dist/page/usePageLayout.d.ts +14 -4
- package/dist/page/usePageLayout.js +19 -20
- package/dist/schema/attrRoles.js +38 -20
- package/dist/schema/docxSchema.d.ts +9 -1
- package/dist/schema/docxSchema.js +191 -139
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +2 -2
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/preservedFragments.d.ts +12 -0
- package/dist/schema/preservedFragments.js +38 -0
- package/dist/schema/preservedGuards.d.ts +9 -7
- package/dist/schema/preservedGuards.js +112 -11
- package/dist/schema/protection.d.ts +34 -5
- package/dist/schema/protection.js +42 -14
- package/dist/schema/rendering.js +3 -1
- package/dist/schema/stories.d.ts +49 -0
- package/dist/schema/stories.js +78 -0
- package/dist/styles/classNames.d.ts +3 -5
- package/dist/styles/classNames.js +3 -5
- package/dist/styles.css +74 -12
- package/dist/table/resize.d.ts +5 -3
- package/dist/ui/CommentsPanel.d.ts +1 -3
- package/dist/ui/CommentsPanel.js +24 -15
- package/dist/ui/NotesPanel.js +2 -2
- package/dist/ui/TextMenu.d.ts +1 -3
- package/dist/ui/TextMenu.js +10 -6
- package/dist/ui/comments/CommentComposer.d.ts +6 -1
- package/dist/ui/comments/CommentComposer.js +26 -3
- package/package.json +1 -1
- package/dist/editor/externalClipboard.d.ts +0 -22
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import {
|
|
3
3
|
useCallback,
|
|
4
4
|
useEffect,
|
|
5
|
-
useMemo,
|
|
6
5
|
useRef,
|
|
7
6
|
useState
|
|
8
7
|
} from "react";
|
|
@@ -10,10 +9,10 @@ import { editorCssVariables } from "../styles/classNames.js";
|
|
|
10
9
|
import { measureSheet } from "./measureBlocks.js";
|
|
11
10
|
import { setPageMarks } from "./pageDecorations.js";
|
|
12
11
|
import {
|
|
13
|
-
|
|
12
|
+
A4_SECTION_PIXELS,
|
|
14
13
|
PAGE_SPLIT_PX,
|
|
15
14
|
pageLayout,
|
|
16
|
-
|
|
15
|
+
sectionPaperAt
|
|
17
16
|
} from "./pageLayout.js";
|
|
18
17
|
function useFrameThrottle(run, hold) {
|
|
19
18
|
const latest = useRef({ run, hold });
|
|
@@ -52,46 +51,46 @@ function usePageLayout({
|
|
|
52
51
|
layer,
|
|
53
52
|
enabled,
|
|
54
53
|
revision,
|
|
55
|
-
|
|
54
|
+
sections
|
|
56
55
|
}) {
|
|
57
56
|
const [overlay, setOverlay] = useState(null);
|
|
58
|
-
const
|
|
59
|
-
() => geometry ? pagePixels(geometry) : A4_PAGE_PIXELS,
|
|
60
|
-
[geometry]
|
|
61
|
-
);
|
|
57
|
+
const papers = sections === void 0 || sections.length === 0 ? A4_SECTION_PIXELS : sections;
|
|
62
58
|
const remeasure = useFrameThrottle(
|
|
63
59
|
() => {
|
|
64
60
|
const box = layer.current;
|
|
65
61
|
if (!view || !box || !enabled) return;
|
|
66
62
|
const measured = measureSheet(view, box);
|
|
67
|
-
const layout = pageLayout({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
pageStep: page.pageStep
|
|
71
|
-
});
|
|
63
|
+
const layout = pageLayout({ blocks: measured.blocks, sections: papers });
|
|
64
|
+
const paperOf = (pos) => sectionPaperAt(papers, pos);
|
|
65
|
+
const sheet = paperOf(0);
|
|
72
66
|
setPageMarks(view, { pushes: layout.pushes, cuts: layout.cuts });
|
|
73
|
-
const sheetHeight = measured.contentTop + layout.bodyHeight + measured.contentBottom;
|
|
67
|
+
const sheetHeight = measured.contentTop + layout.bodyHeight + Math.max(measured.contentBottom, layout.marginBottom);
|
|
74
68
|
box.style.setProperty(editorCssVariables.sheetHeight, `${sheetHeight}px`);
|
|
75
69
|
const next = {
|
|
76
70
|
left: measured.left,
|
|
77
71
|
top: measured.top,
|
|
78
72
|
width: measured.width,
|
|
79
73
|
sheetHeight,
|
|
74
|
+
// A gap opens below the page that ends at this place, so it is that page's own margin
|
|
75
|
+
// the band is drawn under
|
|
80
76
|
marks: layout.splits.map((split) => ({
|
|
81
77
|
page: split.page,
|
|
82
|
-
top: measured.contentTop + split.y + (split.crossed ? 0 : page.marginBottom),
|
|
78
|
+
top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.pos ?? 0).marginBottom),
|
|
83
79
|
height: split.crossed ? 0 : PAGE_SPLIT_PX,
|
|
84
80
|
crossed: split.crossed
|
|
85
81
|
})),
|
|
86
82
|
// A page crossed into has no margin, so the place it was split at is its top corner
|
|
87
83
|
pages: layout.pages.map((start) => {
|
|
88
|
-
const
|
|
84
|
+
const paper = paperOf(start.pos);
|
|
85
|
+
const paperTop = measured.contentTop + start.bodyStart - (start.crossed ? 0 : paper.marginTop);
|
|
89
86
|
return {
|
|
90
87
|
page: start.page,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
pos: start.pos,
|
|
89
|
+
pageInSection: start.pageInSection,
|
|
90
|
+
headerTop: paperTop + paper.marginTop / 2,
|
|
91
|
+
footerTop: paperTop + paper.pageHeight - paper.marginBottom / 2,
|
|
92
|
+
left: sheet.marginLeft,
|
|
93
|
+
width: sheet.bodyWidth,
|
|
95
94
|
crossed: start.crossed
|
|
96
95
|
};
|
|
97
96
|
})
|
package/dist/schema/attrRoles.js
CHANGED
|
@@ -4,7 +4,13 @@ var NODE_ATTR_ROLES = {
|
|
|
4
4
|
doc: {
|
|
5
5
|
// The definitions of the lists started while editing. The export writes numbering.xml from
|
|
6
6
|
// them and nothing derives them again, so they are a source value the document node holds
|
|
7
|
-
newLists: { role: "source", class: "model" }
|
|
7
|
+
newLists: { role: "source", class: "model" },
|
|
8
|
+
// The section that closes the body, as the document wrote it. The export writes it back out
|
|
9
|
+
// between the blocks and the tail, so a change to it is a change to the document
|
|
10
|
+
sectPr: { role: "source", class: "preserved" },
|
|
11
|
+
// What each side story currently says. The comment writer puts a comment's back into the
|
|
12
|
+
// Comments part, so a change to one is a change to the document
|
|
13
|
+
stories: { role: "source", class: "model" }
|
|
8
14
|
},
|
|
9
15
|
paragraph: {
|
|
10
16
|
srcId: { role: "session", class: "identity" },
|
|
@@ -25,13 +31,18 @@ var NODE_ATTR_ROLES = {
|
|
|
25
31
|
styleInside: { role: "display", class: "derived" },
|
|
26
32
|
styleCellMargins: { role: "display", class: "derived" },
|
|
27
33
|
styleConditions: { role: "display", class: "derived" },
|
|
28
|
-
styleBands: { role: "display", class: "derived" }
|
|
34
|
+
styleBands: { role: "display", class: "derived" },
|
|
35
|
+
// The markers a table and a row carry are content the writer puts back exactly where it
|
|
36
|
+
// stood, so a change to one is a change to the table rather than a display refresh
|
|
37
|
+
leadingXml: { role: "source", class: "preserved" }
|
|
29
38
|
},
|
|
30
39
|
tableRow: {
|
|
31
40
|
trAttrs: { role: "source", class: "preserved" },
|
|
32
41
|
tblPrEx: { role: "source", class: "preserved" },
|
|
33
42
|
trPr: { role: "source", class: "preserved" },
|
|
34
|
-
format: { role: "display", class: "derived" }
|
|
43
|
+
format: { role: "display", class: "derived" },
|
|
44
|
+
leadingXml: { role: "source", class: "preserved" },
|
|
45
|
+
trailingXml: { role: "source", class: "preserved" }
|
|
35
46
|
},
|
|
36
47
|
tableCell: {
|
|
37
48
|
colspan: { role: "source", class: "model" },
|
|
@@ -47,19 +58,15 @@ var NODE_ATTR_ROLES = {
|
|
|
47
58
|
// it out of the comparison would let a step that unlocks a cell pass as a re-derivation
|
|
48
59
|
sdtPrefix: { role: "source", class: "preserved" },
|
|
49
60
|
sdtContentsLocked: { role: "source", class: "derived" },
|
|
50
|
-
sdtDeletionLocked: { role: "source", class: "derived" }
|
|
61
|
+
sdtDeletionLocked: { role: "source", class: "derived" },
|
|
62
|
+
trailingXml: { role: "source", class: "preserved" }
|
|
51
63
|
},
|
|
52
64
|
rawBlock: {
|
|
53
65
|
xml: { role: "source", class: "preserved" },
|
|
54
|
-
name: { role: "source", class: "identity" }
|
|
55
|
-
},
|
|
56
|
-
docxRaw: {
|
|
57
66
|
srcId: { role: "session", class: "identity" },
|
|
58
|
-
name: { role: "session", class: "identity" }
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
srcId: { role: "session", class: "identity" },
|
|
62
|
-
name: { role: "session", class: "identity" }
|
|
67
|
+
name: { role: "session", class: "identity" },
|
|
68
|
+
display: { role: "session", class: "derived" },
|
|
69
|
+
guarded: { role: "session", class: "derived" }
|
|
63
70
|
},
|
|
64
71
|
hardBreak: { brAttrs: { role: "source", class: "preserved" } },
|
|
65
72
|
image: {
|
|
@@ -84,14 +91,11 @@ var NODE_ATTR_ROLES = {
|
|
|
84
91
|
authorId: { role: "source", class: "model" },
|
|
85
92
|
initials: { role: "source", class: "model" },
|
|
86
93
|
date: { role: "source", class: "model" },
|
|
87
|
-
text: { role: "source", class: "model" },
|
|
88
|
-
commentXml: { role: "source", class: "preserved" },
|
|
89
94
|
paraId: { role: "source", class: "identity" },
|
|
90
95
|
resolved: { role: "source", class: "model" },
|
|
91
96
|
extensionXml: { role: "source", class: "preserved" },
|
|
92
97
|
replies: { role: "source", class: "model" },
|
|
93
|
-
// Read to decide whether the comment
|
|
94
|
-
imported: { role: "session", class: "derived" },
|
|
98
|
+
// Read to decide whether the extended comment part is rewritten at all; it is never written
|
|
95
99
|
threadImported: { role: "session", class: "derived" }
|
|
96
100
|
},
|
|
97
101
|
noteReference: {
|
|
@@ -99,12 +103,26 @@ var NODE_ATTR_ROLES = {
|
|
|
99
103
|
id: { role: "source", class: "identity" },
|
|
100
104
|
customMarkFollows: { role: "source", class: "model" },
|
|
101
105
|
referenceXml: { role: "source", class: "preserved" },
|
|
102
|
-
//
|
|
106
|
+
// Worked out from the notes part as the document was opened, and the writer puts back the
|
|
103
107
|
// reference alone: a note renumbered around an edit is the same reference it was
|
|
104
|
-
label: { role: "display", class: "derived" }
|
|
105
|
-
text: { role: "display", class: "derived" }
|
|
108
|
+
label: { role: "display", class: "derived" }
|
|
106
109
|
},
|
|
107
|
-
|
|
110
|
+
rawRunContent: {
|
|
111
|
+
xml: { role: "source", class: "preserved" },
|
|
112
|
+
// What the fragment is and how it is drawn are read off the preservation table when the
|
|
113
|
+
// document is opened and never worked out again, so they travel with the fragment itself
|
|
114
|
+
element: { role: "session", class: "identity" },
|
|
115
|
+
display: { role: "session", class: "derived" },
|
|
116
|
+
text: { role: "session", class: "derived" },
|
|
117
|
+
guarded: { role: "session", class: "derived" }
|
|
118
|
+
},
|
|
119
|
+
rawInline: {
|
|
120
|
+
xml: { role: "source", class: "preserved" },
|
|
121
|
+
element: { role: "session", class: "identity" },
|
|
122
|
+
display: { role: "session", class: "derived" },
|
|
123
|
+
text: { role: "session", class: "derived" },
|
|
124
|
+
guarded: { role: "session", class: "derived" }
|
|
125
|
+
}
|
|
108
126
|
};
|
|
109
127
|
var MARK_ATTR_ROLES = {
|
|
110
128
|
run: {
|
|
@@ -15,4 +15,12 @@ import { Schema } from "prosemirror-model";
|
|
|
15
15
|
export { imageNodeSpec, runMarkSpec } from "./rendering";
|
|
16
16
|
/** Whether this is a page-splitting break (`<w:br w:type="page"/>`). Read straight from the original attribute text */
|
|
17
17
|
export declare function isPageBreak(brAttrs: unknown): boolean;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* How a preserved fragment is drawn, baked into the node's attrs when the document is opened
|
|
20
|
+
* (`docx/importPolicy`) so that this layer reads a value rather than a vocabulary.
|
|
21
|
+
*
|
|
22
|
+
* `hidden` puts nothing on screen, `text` draws the character the fragment stands for, `break`
|
|
23
|
+
* ends the line where it stood, and `chip` draws a small box naming the element.
|
|
24
|
+
*/
|
|
25
|
+
export type PreservedDisplay = "hidden" | "text" | "break" | "chip";
|
|
26
|
+
export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
|