@portone/docx-editor 0.3.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 +205 -0
- package/assets/editor.png +0 -0
- package/dist/DocxEditor.d.ts +1 -1
- package/dist/DocxEditor.js +45 -25
- package/dist/core.d.ts +1 -1
- 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 +78 -35
- package/dist/docx/exportDocx.js +30 -18
- 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/formatting/attrs.d.ts +20 -2
- package/dist/docx/formatting/attrs.js +57 -2
- package/dist/docx/formatting/context.d.ts +10 -2
- package/dist/docx/formatting/context.js +23 -5
- package/dist/docx/formatting/resolve.d.ts +10 -4
- package/dist/docx/formatting/resolve.js +31 -11
- package/dist/docx/formatting/styles.d.ts +25 -2
- package/dist/docx/formatting/styles.js +84 -3
- package/dist/docx/headersFooters.d.ts +89 -20
- package/dist/docx/headersFooters.js +163 -172
- package/dist/docx/hyperlink.d.ts +14 -4
- package/dist/docx/hyperlink.js +4 -1
- package/dist/docx/importDocx.d.ts +1 -1
- package/dist/docx/importDocx.js +135 -74
- 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.d.ts +2 -2
- package/dist/docx/importTable.js +107 -66
- package/dist/docx/invariants.js +42 -31
- package/dist/docx/newLists.d.ts +30 -0
- package/dist/docx/newLists.js +24 -1
- package/dist/docx/notes.d.ts +6 -1
- package/dist/docx/notes.js +6 -16
- package/dist/docx/numberingPlanner.d.ts +6 -3
- package/dist/docx/numberingPlanner.js +38 -7
- 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 +24 -7
- package/dist/docx/session.js +37 -6
- package/dist/docx/story.d.ts +140 -0
- package/dist/docx/story.js +237 -0
- package/dist/docx/storyProjection.js +6 -1
- package/dist/docx/tableFormatting/conditions.d.ts +76 -0
- package/dist/docx/tableFormatting/conditions.js +196 -0
- package/dist/docx/tableFormatting/editing.d.ts +7 -3
- package/dist/docx/tableFormatting/editing.js +4 -5
- package/dist/docx/tableFormatting/reading.d.ts +49 -19
- package/dist/docx/tableFormatting/reading.js +109 -35
- package/dist/docx/tableFormatting.d.ts +1 -0
- package/dist/docx/tableFormatting.js +1 -0
- package/dist/docx/tableTemplate.js +12 -12
- package/dist/editor/clipboard/htmlReader.d.ts +30 -0
- package/dist/editor/clipboard/htmlReader.js +302 -0
- 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/formatting/propertyCommands.js +6 -1
- package/dist/editor/commands/index.d.ts +2 -2
- package/dist/editor/commands/index.js +2 -0
- package/dist/editor/commands/listCommands.d.ts +12 -3
- package/dist/editor/commands/listCommands.js +76 -30
- package/dist/editor/commands/noteQueries.d.ts +22 -5
- package/dist/editor/commands/noteQueries.js +34 -6
- package/dist/editor/commands/paragraphCommands.js +6 -1
- package/dist/editor/createEditor.js +14 -4
- package/dist/editor/documentStyles.d.ts +26 -4
- package/dist/editor/documentStyles.js +9 -4
- package/dist/editor/editorDocument.d.ts +7 -6
- package/dist/editor/editorDocument.js +18 -6
- 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/paragraphEdits.d.ts +16 -1
- package/dist/editor/paragraphEdits.js +13 -5
- package/dist/editor/paragraphPlacement.d.ts +11 -0
- package/dist/editor/paragraphPlacement.js +18 -0
- 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 +20 -10
- package/dist/editor/plugins/linkPanel.d.ts +7 -3
- package/dist/editor/plugins/linkPanel.js +13 -27
- package/dist/editor/plugins/numberingDecorations.d.ts +10 -4
- package/dist/editor/plugins/numberingDecorations.js +43 -2
- package/dist/editor/plugins/panelState.d.ts +67 -0
- package/dist/editor/plugins/panelState.js +54 -0
- package/dist/editor/plugins/paragraphDisplay.js +9 -3
- package/dist/editor/plugins/tableContextMenu.d.ts +1 -1
- package/dist/editor/plugins/tableContextMenu.js +30 -47
- package/dist/editor/plugins/tableDisplay.js +19 -5
- package/dist/editor/plugins/textContextMenu.d.ts +1 -1
- package/dist/editor/plugins/textContextMenu.js +30 -47
- package/dist/model/format.d.ts +50 -0
- package/dist/model/format.js +65 -0
- package/dist/numbering/listRegistry.d.ts +37 -0
- package/dist/numbering/listRegistry.js +112 -0
- package/dist/numbering/listTemplate.d.ts +26 -17
- package/dist/numbering/listTemplate.js +66 -20
- package/dist/numbering/markers.d.ts +15 -6
- package/dist/numbering/markers.js +26 -59
- package/dist/numbering/parseNumbering.d.ts +70 -5
- package/dist/numbering/parseNumbering.js +100 -26
- package/dist/numbering/spellers.d.ts +15 -0
- package/dist/numbering/spellers.js +96 -0
- package/dist/numbering/writeNumbering.d.ts +5 -3
- package/dist/numbering/writeNumbering.js +15 -15
- package/dist/ooxml/conformance.d.ts +28 -0
- package/dist/ooxml/conformance.js +20 -0
- package/dist/ooxml/errors.d.ts +5 -5
- 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 +15 -0
- package/dist/ooxml/names.js +10 -1
- package/dist/ooxml/partSplice.d.ts +1 -1
- package/dist/ooxml/partSplice.js +10 -3
- 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/ooxml/xml.d.ts +8 -9
- package/dist/ooxml/xml.js +6 -6
- package/dist/page/PageGuides.d.ts +8 -4
- package/dist/page/PageGuides.js +13 -37
- package/dist/page/pageLayout.d.ts +62 -13
- package/dist/page/pageLayout.js +91 -37
- package/dist/page/usePageLayout.d.ts +14 -11
- package/dist/page/usePageLayout.js +21 -29
- package/dist/schema/attrRoles.js +44 -19
- package/dist/schema/docxSchema.d.ts +9 -1
- package/dist/schema/docxSchema.js +220 -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 +16 -7
- package/dist/styles/classNames.js +16 -7
- package/dist/styles.css +90 -30
- package/dist/table/cellFormatting.js +1 -2
- package/dist/table/gridBorders.d.ts +11 -15
- package/dist/table/gridBorders.js +32 -18
- 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 -11
- package/dist/editor/externalClipboard.js +0 -456
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
// src/editor/externalClipboard.ts
|
|
2
|
-
import {
|
|
3
|
-
DOMSerializer,
|
|
4
|
-
Fragment,
|
|
5
|
-
Slice
|
|
6
|
-
} from "prosemirror-model";
|
|
7
|
-
import { Plugin } from "prosemirror-state";
|
|
8
|
-
import { paragraphAttrsFor, styleIdOf } from "../docx/formatting.js";
|
|
9
|
-
import {
|
|
10
|
-
withListNumbering,
|
|
11
|
-
withParagraphStyle
|
|
12
|
-
} from "../docx/paraProps.js";
|
|
13
|
-
import { MAX_ILVL, nextNumId } from "../numbering/listTemplate.js";
|
|
14
|
-
import { docxSchema, isPageBreak } from "../schema/index.js";
|
|
15
|
-
import { editorClassNames } from "../styles/classNames.js";
|
|
16
|
-
import { PASTED_IMAGE_ATTRIBUTE } from "./clipboard/images.js";
|
|
17
|
-
import {
|
|
18
|
-
appendInline,
|
|
19
|
-
contextFor,
|
|
20
|
-
marksFor,
|
|
21
|
-
safeHref,
|
|
22
|
-
withInlineStyle
|
|
23
|
-
} from "./clipboard/inlineFormatting.js";
|
|
24
|
-
import { listRefOf } from "./commands/listCommands.js";
|
|
25
|
-
import { documentFormatting, documentParagraphStyles } from "./documentStyles.js";
|
|
26
|
-
import { insertPlainText } from "./plainText.js";
|
|
27
|
-
import { moveCaretToDrop } from "./plugins/dropCaret.js";
|
|
28
|
-
import {
|
|
29
|
-
canStartNewList,
|
|
30
|
-
documentNumbering
|
|
31
|
-
} from "./plugins/numberingDecorations.js";
|
|
32
|
-
var BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
33
|
-
"ADDRESS",
|
|
34
|
-
"ARTICLE",
|
|
35
|
-
"ASIDE",
|
|
36
|
-
"BLOCKQUOTE",
|
|
37
|
-
"DIV",
|
|
38
|
-
"H1",
|
|
39
|
-
"H2",
|
|
40
|
-
"H3",
|
|
41
|
-
"H4",
|
|
42
|
-
"H5",
|
|
43
|
-
"H6",
|
|
44
|
-
"LI",
|
|
45
|
-
"P",
|
|
46
|
-
"PRE",
|
|
47
|
-
"SECTION"
|
|
48
|
-
]);
|
|
49
|
-
var HEADING_LEVELS = {
|
|
50
|
-
H1: 1,
|
|
51
|
-
H2: 2,
|
|
52
|
-
H3: 3,
|
|
53
|
-
H4: 4,
|
|
54
|
-
H5: 5,
|
|
55
|
-
H6: 6
|
|
56
|
-
};
|
|
57
|
-
var HEADING_FALLBACKS = {
|
|
58
|
-
1: { bold: true, fontSizePt: 24 },
|
|
59
|
-
2: { bold: true, fontSizePt: 18 },
|
|
60
|
-
3: { bold: true, fontSizePt: 14 },
|
|
61
|
-
4: { bold: true, fontSizePt: 12 },
|
|
62
|
-
5: { bold: true, fontSizePt: 10 },
|
|
63
|
-
6: { bold: true, fontSizePt: 8 }
|
|
64
|
-
};
|
|
65
|
-
var PUBLIC_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
66
|
-
"alt",
|
|
67
|
-
"aria-label",
|
|
68
|
-
"class",
|
|
69
|
-
"colspan",
|
|
70
|
-
"height",
|
|
71
|
-
"href",
|
|
72
|
-
"lang",
|
|
73
|
-
"rowspan",
|
|
74
|
-
"src",
|
|
75
|
-
"style",
|
|
76
|
-
"width"
|
|
77
|
-
]);
|
|
78
|
-
var COPIED_STYLE_ATTRIBUTE = "data-style";
|
|
79
|
-
function isAttributes(value) {
|
|
80
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Node);
|
|
81
|
-
}
|
|
82
|
-
function publicAttributes(attrs) {
|
|
83
|
-
return Object.fromEntries(
|
|
84
|
-
Object.entries(attrs).filter(([name]) => PUBLIC_ATTRIBUTES.has(name))
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
function isSpecArray(value) {
|
|
88
|
-
return Array.isArray(value) && typeof value[0] === "string";
|
|
89
|
-
}
|
|
90
|
-
function stripPrivateAttributes(spec) {
|
|
91
|
-
if (!isSpecArray(spec)) return spec;
|
|
92
|
-
const [tag, ...rest] = spec;
|
|
93
|
-
const attrs = isAttributes(rest[0]) ? publicAttributes(rest[0]) : null;
|
|
94
|
-
const children = (attrs === null ? rest : rest.slice(1)).map(
|
|
95
|
-
(child) => isSpecArray(child) ? stripPrivateAttributes(child) : child
|
|
96
|
-
);
|
|
97
|
-
return attrs === null ? [tag, ...children] : [tag, attrs, ...children];
|
|
98
|
-
}
|
|
99
|
-
function withDomAttribute(spec, name, value) {
|
|
100
|
-
if (!isSpecArray(spec)) return spec;
|
|
101
|
-
const [tag, ...rest] = spec;
|
|
102
|
-
return isAttributes(rest[0]) ? [tag, { ...rest[0], [name]: value }, ...rest.slice(1)] : [tag, { [name]: value }, ...rest];
|
|
103
|
-
}
|
|
104
|
-
function asTag(spec, tag) {
|
|
105
|
-
return isSpecArray(spec) ? [tag, ...spec.slice(1)] : spec;
|
|
106
|
-
}
|
|
107
|
-
function copiedMarkSpec(mark, spec) {
|
|
108
|
-
const stripped = stripPrivateAttributes(spec);
|
|
109
|
-
if (mark.type !== docxSchema.marks.link) return stripped;
|
|
110
|
-
const href = safeHref(
|
|
111
|
-
typeof mark.attrs.href === "string" ? mark.attrs.href : null
|
|
112
|
-
);
|
|
113
|
-
return href === null ? stripped : asTag(withDomAttribute(stripped, "href", href), "a");
|
|
114
|
-
}
|
|
115
|
-
function copiedNodeSpec(node, spec) {
|
|
116
|
-
const stripped = stripPrivateAttributes(spec);
|
|
117
|
-
if (node.type !== docxSchema.nodes.paragraph) return stripped;
|
|
118
|
-
const styleId = styleIdOf(node.attrs.pPr);
|
|
119
|
-
return styleId === null ? stripped : withDomAttribute(stripped, COPIED_STYLE_ATTRIBUTE, styleId);
|
|
120
|
-
}
|
|
121
|
-
function clipboardSerializer() {
|
|
122
|
-
const drawn = DOMSerializer.fromSchema(docxSchema);
|
|
123
|
-
const nodes = Object.fromEntries(
|
|
124
|
-
Object.entries(drawn.nodes).map(([name, toDOM]) => [
|
|
125
|
-
name,
|
|
126
|
-
(node) => copiedNodeSpec(node, toDOM(node))
|
|
127
|
-
])
|
|
128
|
-
);
|
|
129
|
-
const marks = Object.fromEntries(
|
|
130
|
-
Object.entries(drawn.marks).map(([name, toDOM]) => [
|
|
131
|
-
name,
|
|
132
|
-
(mark, inline) => copiedMarkSpec(mark, toDOM(mark, inline))
|
|
133
|
-
])
|
|
134
|
-
);
|
|
135
|
-
return new DOMSerializer(nodes, marks);
|
|
136
|
-
}
|
|
137
|
-
var UNREADABLE_BLOCKS = /* @__PURE__ */ new Set([
|
|
138
|
-
"bookmarkBlock",
|
|
139
|
-
"docxRaw",
|
|
140
|
-
"rawBlock"
|
|
141
|
-
]);
|
|
142
|
-
function stringAttr(value) {
|
|
143
|
-
return typeof value === "string" ? value : "";
|
|
144
|
-
}
|
|
145
|
-
function inlineText(node) {
|
|
146
|
-
if (node.isText) return node.text ?? "";
|
|
147
|
-
if (node.type === docxSchema.nodes.hardBreak) {
|
|
148
|
-
return isPageBreak(node.attrs.brAttrs) ? "\f" : "\n";
|
|
149
|
-
}
|
|
150
|
-
if (node.type === docxSchema.nodes.image) return stringAttr(node.attrs.alt);
|
|
151
|
-
if (node.type === docxSchema.nodes.noteReference) {
|
|
152
|
-
return node.attrs.customMarkFollows === true ? "" : stringAttr(node.attrs.label);
|
|
153
|
-
}
|
|
154
|
-
return "";
|
|
155
|
-
}
|
|
156
|
-
function rowsText(table) {
|
|
157
|
-
const rows = [];
|
|
158
|
-
table.forEach((row) => {
|
|
159
|
-
const cells = [];
|
|
160
|
-
row.forEach((cell) => {
|
|
161
|
-
cells.push(fragmentText(cell.content));
|
|
162
|
-
});
|
|
163
|
-
rows.push(cells.join(" "));
|
|
164
|
-
});
|
|
165
|
-
return rows.join("\n");
|
|
166
|
-
}
|
|
167
|
-
function blockText(node) {
|
|
168
|
-
if (node.type === docxSchema.nodes.table) return rowsText(node);
|
|
169
|
-
if (UNREADABLE_BLOCKS.has(node.type.name)) return "";
|
|
170
|
-
return fragmentText(node.content);
|
|
171
|
-
}
|
|
172
|
-
function fragmentText(fragment) {
|
|
173
|
-
const pieces = [];
|
|
174
|
-
fragment.forEach((child) => {
|
|
175
|
-
pieces.push(child.isInline ? inlineText(child) : blockText(child));
|
|
176
|
-
});
|
|
177
|
-
return pieces.join(fragment.firstChild?.isInline === true ? "" : "\n");
|
|
178
|
-
}
|
|
179
|
-
function bareWrappers(content, openStart, openEnd) {
|
|
180
|
-
const wrapper = content.firstChild;
|
|
181
|
-
if (openStart <= 1 || openEnd <= 1 || content.childCount !== 1)
|
|
182
|
-
return content;
|
|
183
|
-
if (wrapper === null || wrapper.childCount !== 1) return content;
|
|
184
|
-
return Fragment.from(
|
|
185
|
-
wrapper.type.create(
|
|
186
|
-
null,
|
|
187
|
-
bareWrappers(wrapper.content, openStart - 1, openEnd - 1),
|
|
188
|
-
wrapper.marks
|
|
189
|
-
)
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
function copiedSlice(slice) {
|
|
193
|
-
return new Slice(
|
|
194
|
-
bareWrappers(slice.content, slice.openStart, slice.openEnd),
|
|
195
|
-
slice.openStart,
|
|
196
|
-
slice.openEnd
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
function clipboardText(slice) {
|
|
200
|
-
return fragmentText(slice.content);
|
|
201
|
-
}
|
|
202
|
-
function normalizedStyleName(value) {
|
|
203
|
-
return value.toLowerCase().replace(/[\s_-]+/g, "");
|
|
204
|
-
}
|
|
205
|
-
function copiedStyleId(element) {
|
|
206
|
-
if (!element.classList.contains(editorClassNames.paragraph)) return null;
|
|
207
|
-
return element.getAttribute(COPIED_STYLE_ATTRIBUTE) ?? styleIdOf(element.getAttribute("data-ppr"));
|
|
208
|
-
}
|
|
209
|
-
function headingLevel(element, sourceStyleId) {
|
|
210
|
-
const direct = HEADING_LEVELS[element.tagName];
|
|
211
|
-
if (direct !== void 0) return direct;
|
|
212
|
-
const match = /^heading([1-6])$/.exec(
|
|
213
|
-
normalizedStyleName(sourceStyleId ?? "")
|
|
214
|
-
);
|
|
215
|
-
return match ? Number.parseInt(match[1] ?? "", 10) : null;
|
|
216
|
-
}
|
|
217
|
-
function destinationStyleId(state, sourceStyleId, level) {
|
|
218
|
-
const styles = documentParagraphStyles(state);
|
|
219
|
-
if (sourceStyleId && styles.some((style) => style.id === sourceStyleId)) {
|
|
220
|
-
return sourceStyleId;
|
|
221
|
-
}
|
|
222
|
-
if (level === null) return null;
|
|
223
|
-
const wanted = `heading${level}`;
|
|
224
|
-
return styles.find(
|
|
225
|
-
(style) => normalizedStyleName(style.id) === wanted || normalizedStyleName(style.name) === wanted
|
|
226
|
-
)?.id ?? null;
|
|
227
|
-
}
|
|
228
|
-
function blockContext(state, parent, element, preserveParagraphStyle) {
|
|
229
|
-
const editorParagraph = element.classList.contains(
|
|
230
|
-
editorClassNames.paragraph
|
|
231
|
-
);
|
|
232
|
-
const sourceStyleId = copiedStyleId(element);
|
|
233
|
-
const level = headingLevel(element, sourceStyleId);
|
|
234
|
-
if (!preserveParagraphStyle && editorParagraph) {
|
|
235
|
-
return {
|
|
236
|
-
inline: contextFor(parent, element),
|
|
237
|
-
paragraph: null
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
const styleId = destinationStyleId(state, sourceStyleId, level);
|
|
241
|
-
const paragraph = styleId === null ? null : withParagraphStyle(null, styleId);
|
|
242
|
-
const usesDestinationStyle = editorParagraph && (sourceStyleId === null || paragraph !== null);
|
|
243
|
-
let inline = parent;
|
|
244
|
-
if (paragraph === null && level !== null) {
|
|
245
|
-
inline = withInlineStyle(inline, HEADING_FALLBACKS[level] ?? {});
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
inline: contextFor(inline, element, !usesDestinationStyle),
|
|
249
|
-
paragraph
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function listParagraphProps(list) {
|
|
253
|
-
if (!list || list.numId === null) return null;
|
|
254
|
-
return withListNumbering(null, {
|
|
255
|
-
numbering: { numId: list.numId, ilvl: Math.min(MAX_ILVL, list.level) },
|
|
256
|
-
indent: { kind: "keep" }
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
function paragraphAttrs(state, list, paragraph) {
|
|
260
|
-
const props = listParagraphProps(list) ?? paragraph;
|
|
261
|
-
return props ? {
|
|
262
|
-
pPr: props.pPr,
|
|
263
|
-
...paragraphAttrsFor(props.pPr, documentFormatting(state))
|
|
264
|
-
} : null;
|
|
265
|
-
}
|
|
266
|
-
function usedNumIds(state) {
|
|
267
|
-
const used = new Set(documentNumbering(state).lists.keys());
|
|
268
|
-
state.doc.descendants((node) => {
|
|
269
|
-
if (node.type !== docxSchema.nodes.paragraph) return true;
|
|
270
|
-
const ref = listRefOf(node);
|
|
271
|
-
if (ref) used.add(ref.numId);
|
|
272
|
-
return false;
|
|
273
|
-
});
|
|
274
|
-
return used;
|
|
275
|
-
}
|
|
276
|
-
var HtmlReader = class {
|
|
277
|
-
constructor(state, preserveParagraphStyles, images) {
|
|
278
|
-
this.state = state;
|
|
279
|
-
this.preserveParagraphStyles = preserveParagraphStyles;
|
|
280
|
-
this.images = images;
|
|
281
|
-
this.used = usedNumIds(state);
|
|
282
|
-
this.canCreateLists = canStartNewList(state);
|
|
283
|
-
}
|
|
284
|
-
state;
|
|
285
|
-
preserveParagraphStyles;
|
|
286
|
-
images;
|
|
287
|
-
blocks = [];
|
|
288
|
-
used;
|
|
289
|
-
canCreateLists;
|
|
290
|
-
read(root) {
|
|
291
|
-
this.readFlow(root, { style: {}, href: null, preserveWhitespace: false });
|
|
292
|
-
return this.blocks;
|
|
293
|
-
}
|
|
294
|
-
appendInline(target, node, context) {
|
|
295
|
-
appendInline(target, node, context, (content, element, inline) => {
|
|
296
|
-
if (element.tagName !== "IMG") return false;
|
|
297
|
-
const token = element.getAttribute(PASTED_IMAGE_ATTRIBUTE);
|
|
298
|
-
const image = token === null ? void 0 : this.images.get(token);
|
|
299
|
-
if (!image) return true;
|
|
300
|
-
content.push(
|
|
301
|
-
docxSchema.nodes.image.create(
|
|
302
|
-
{
|
|
303
|
-
...image,
|
|
304
|
-
// The source drawing may point at a relationship in another package.
|
|
305
|
-
xml: null
|
|
306
|
-
},
|
|
307
|
-
null,
|
|
308
|
-
marksFor(inline)
|
|
309
|
-
)
|
|
310
|
-
);
|
|
311
|
-
return true;
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
addParagraph(content, list = null, paragraph = null) {
|
|
315
|
-
if (list && list.numId === null) {
|
|
316
|
-
const marker = list.kind === "bullet" ? "\u2022 " : "1. ";
|
|
317
|
-
content.unshift(docxSchema.text(marker));
|
|
318
|
-
}
|
|
319
|
-
this.blocks.push(
|
|
320
|
-
docxSchema.nodes.paragraph.create(
|
|
321
|
-
paragraphAttrs(this.state, list, paragraph),
|
|
322
|
-
content
|
|
323
|
-
)
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
readFlow(parent, context, paragraph = null) {
|
|
327
|
-
let inline = [];
|
|
328
|
-
const flush = () => {
|
|
329
|
-
if (inline.length === 0) return;
|
|
330
|
-
this.addParagraph(inline, null, paragraph);
|
|
331
|
-
inline = [];
|
|
332
|
-
};
|
|
333
|
-
for (const child of parent.childNodes) {
|
|
334
|
-
const element = child.nodeType === child.ELEMENT_NODE ? child : null;
|
|
335
|
-
if (element?.tagName === "UL" || element?.tagName === "OL") {
|
|
336
|
-
flush();
|
|
337
|
-
this.readList(element, context, 0, null);
|
|
338
|
-
} else if (element && BLOCK_TAGS.has(element.tagName)) {
|
|
339
|
-
flush();
|
|
340
|
-
const before = this.blocks.length;
|
|
341
|
-
const block = blockContext(
|
|
342
|
-
this.state,
|
|
343
|
-
context,
|
|
344
|
-
element,
|
|
345
|
-
this.preserveParagraphStyles
|
|
346
|
-
);
|
|
347
|
-
this.readFlow(element, block.inline, block.paragraph);
|
|
348
|
-
if (this.blocks.length === before) {
|
|
349
|
-
this.addParagraph([], null, block.paragraph);
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
this.appendInline(inline, child, context);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
flush();
|
|
356
|
-
}
|
|
357
|
-
takeNumId(kind) {
|
|
358
|
-
if (!this.canCreateLists) return null;
|
|
359
|
-
const id = nextNumId(this.used, kind);
|
|
360
|
-
this.used.add(id);
|
|
361
|
-
return id;
|
|
362
|
-
}
|
|
363
|
-
readList(list, context, level, inherited) {
|
|
364
|
-
const kind = list.tagName === "UL" ? "bullet" : "numbered";
|
|
365
|
-
const listContext = {
|
|
366
|
-
kind,
|
|
367
|
-
numId: inherited?.kind === kind ? inherited.numId : this.takeNumId(kind),
|
|
368
|
-
level
|
|
369
|
-
};
|
|
370
|
-
const items = Array.from(list.children).filter(
|
|
371
|
-
(child) => child.tagName === "LI"
|
|
372
|
-
);
|
|
373
|
-
for (const item of items) {
|
|
374
|
-
const itemContext = contextFor(context, item);
|
|
375
|
-
const content = [];
|
|
376
|
-
for (const child of item.childNodes) {
|
|
377
|
-
const nested = child.nodeType === child.ELEMENT_NODE ? child : null;
|
|
378
|
-
if (nested?.tagName === "UL" || nested?.tagName === "OL") continue;
|
|
379
|
-
this.appendInline(content, child, itemContext);
|
|
380
|
-
}
|
|
381
|
-
this.addParagraph(content, listContext);
|
|
382
|
-
for (const nested of Array.from(item.children)) {
|
|
383
|
-
if (nested.tagName === "UL" || nested.tagName === "OL") {
|
|
384
|
-
this.readList(
|
|
385
|
-
nested,
|
|
386
|
-
itemContext,
|
|
387
|
-
level + 1,
|
|
388
|
-
listContext
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
function sliceDepth(root) {
|
|
396
|
-
const marker = root.querySelector("[data-pm-slice]");
|
|
397
|
-
const openStart = Number.parseInt(
|
|
398
|
-
marker?.getAttribute("data-pm-slice")?.split(/\s+/, 1)[0] ?? "",
|
|
399
|
-
10
|
|
400
|
-
);
|
|
401
|
-
if (Number.isFinite(openStart)) return openStart === 0 ? 0 : 1;
|
|
402
|
-
const blocks = [...BLOCK_TAGS, "OL", "UL"].map((tag) => tag.toLowerCase());
|
|
403
|
-
return root.querySelector(blocks.join(",")) ? 0 : 1;
|
|
404
|
-
}
|
|
405
|
-
function richHtmlSlice(state, document, source, images = /* @__PURE__ */ new Map()) {
|
|
406
|
-
if (source.trim() === "") return null;
|
|
407
|
-
const template = document.createElement("template");
|
|
408
|
-
template.innerHTML = source;
|
|
409
|
-
const open = sliceDepth(template.content);
|
|
410
|
-
const blocks = new HtmlReader(state, open === 0, images).read(
|
|
411
|
-
template.content
|
|
412
|
-
);
|
|
413
|
-
return blocks.length === 0 ? null : new Slice(Fragment.fromArray([...blocks]), open, open);
|
|
414
|
-
}
|
|
415
|
-
function insertRichHtml(view, source) {
|
|
416
|
-
const slice = richHtmlSlice(view.state, view.dom.ownerDocument, source);
|
|
417
|
-
if (slice === null) return false;
|
|
418
|
-
view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
function insertClipboardData(view, data) {
|
|
422
|
-
if (insertRichHtml(view, data.html ?? "")) return;
|
|
423
|
-
insertPlainText(view, data.text ?? "");
|
|
424
|
-
}
|
|
425
|
-
function externalClipboard() {
|
|
426
|
-
const serializer = clipboardSerializer();
|
|
427
|
-
return new Plugin({
|
|
428
|
-
props: {
|
|
429
|
-
clipboardSerializer: serializer,
|
|
430
|
-
clipboardTextSerializer: clipboardText,
|
|
431
|
-
transformCopied: copiedSlice,
|
|
432
|
-
handlePaste(view, event) {
|
|
433
|
-
insertClipboardData(view, {
|
|
434
|
-
html: event.clipboardData?.getData("text/html"),
|
|
435
|
-
text: event.clipboardData?.getData("text/plain")
|
|
436
|
-
});
|
|
437
|
-
return true;
|
|
438
|
-
},
|
|
439
|
-
handleDrop(view, event) {
|
|
440
|
-
if (view.dragging) return false;
|
|
441
|
-
const text = event.dataTransfer?.getData("text/plain") ?? "";
|
|
442
|
-
if (text) {
|
|
443
|
-
moveCaretToDrop(view, event);
|
|
444
|
-
insertPlainText(view, text);
|
|
445
|
-
}
|
|
446
|
-
return true;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
export {
|
|
452
|
-
externalClipboard,
|
|
453
|
-
insertClipboardData,
|
|
454
|
-
insertRichHtml,
|
|
455
|
-
richHtmlSlice
|
|
456
|
-
};
|