@portone/docx-editor 0.4.0 → 0.5.1
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 +201 -0
- package/CONTRIBUTING.md +2 -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/formatting/styles.d.ts +0 -2
- package/dist/docx/formatting/styles.js +2 -15
- package/dist/docx/headersFooters.d.ts +89 -20
- package/dist/docx/headersFooters.js +163 -172
- package/dist/docx/identities.js +17 -26
- package/dist/docx/importDocx.d.ts +1 -1
- package/dist/docx/importDocx.js +100 -48
- package/dist/docx/importParagraph.d.ts +18 -5
- package/dist/docx/importParagraph.js +75 -128
- package/dist/docx/importPolicy.d.ts +70 -0
- package/dist/docx/importPolicy.js +195 -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 +9 -4
- package/dist/docx/serializeParagraph.js +23 -58
- 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/docx/tableTemplate.d.ts +25 -0
- package/dist/docx/tableTemplate.js +30 -16
- package/dist/docx/wrappers.d.ts +67 -0
- package/dist/docx/wrappers.js +117 -0
- package/dist/editor/clipboard/blockReaders.d.ts +74 -0
- package/dist/editor/clipboard/blockReaders.js +193 -0
- package/dist/editor/clipboard/htmlReader.d.ts +26 -0
- package/dist/editor/clipboard/htmlReader.js +376 -0
- package/dist/editor/clipboard/inlineFormatting.d.ts +0 -7
- package/dist/editor/clipboard/inlineFormatting.js +1 -7
- 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 +188 -0
- package/dist/editor/clipboard/readContext.d.ts +34 -0
- package/dist/editor/clipboard/readContext.js +25 -0
- package/dist/editor/clipboard/readers.d.ts +33 -0
- package/dist/editor/clipboard/readers.js +37 -0
- package/dist/editor/clipboard/source.d.ts +12 -0
- package/dist/editor/clipboard/source.js +21 -0
- package/dist/editor/commands/comments/editing.d.ts +26 -6
- package/dist/editor/commands/comments/editing.js +177 -106
- 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/linkCommands.js +20 -5
- package/dist/editor/commands/listCommands.d.ts +6 -0
- package/dist/editor/commands/listCommands.js +3 -2
- package/dist/editor/commands/lockCommands.js +59 -16
- package/dist/editor/commands/noteQueries.d.ts +22 -5
- package/dist/editor/commands/noteQueries.js +34 -6
- package/dist/editor/commands/paragraphCommands.js +2 -2
- 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 +10 -0
- package/dist/ooxml/props.js +28 -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 +46 -23
- package/dist/schema/clipboard.d.ts +72 -0
- package/dist/schema/clipboard.js +288 -0
- package/dist/schema/docxSchema.d.ts +9 -1
- package/dist/schema/docxSchema.js +217 -165
- 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/locks.d.ts +3 -0
- package/dist/schema/locks.js +29 -12
- 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.d.ts +14 -0
- package/dist/schema/rendering.js +27 -12
- package/dist/schema/stories.d.ts +49 -0
- package/dist/schema/stories.js +78 -0
- package/dist/schema/wrappers.d.ts +58 -0
- package/dist/schema/wrappers.js +77 -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 +5 -4
- package/dist/editor/externalClipboard.d.ts +0 -22
- package/dist/editor/externalClipboard.js +0 -486
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// src/schema/clipboard.ts
|
|
2
|
+
import {
|
|
3
|
+
DOMSerializer,
|
|
4
|
+
Fragment
|
|
5
|
+
} from "prosemirror-model";
|
|
6
|
+
import {
|
|
7
|
+
spanCount,
|
|
8
|
+
toCellFormat,
|
|
9
|
+
toGridCols,
|
|
10
|
+
toParagraphFormat,
|
|
11
|
+
toRowFormat,
|
|
12
|
+
toRunFormat,
|
|
13
|
+
toTableFormat,
|
|
14
|
+
toTableWidth
|
|
15
|
+
} from "../model/format.js";
|
|
16
|
+
import { styleIdOf } from "../ooxml/props.js";
|
|
17
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
18
|
+
import { DEFAULT_FONT_FALLBACKS } from "../styles/fontStack.js";
|
|
19
|
+
import {
|
|
20
|
+
cellStyle,
|
|
21
|
+
columnWidthPx,
|
|
22
|
+
paragraphStyle,
|
|
23
|
+
rowStyle,
|
|
24
|
+
tableStyle
|
|
25
|
+
} from "../styles/inlineStyle.js";
|
|
26
|
+
import { isPageBreak } from "./docxSchema.js";
|
|
27
|
+
import { imageAttrs, runAttrs } from "./rendering.js";
|
|
28
|
+
var COPIED_STYLE_ATTRIBUTE = "data-style";
|
|
29
|
+
function safeHref(value) {
|
|
30
|
+
const href = value?.trim() ?? "";
|
|
31
|
+
if (href === "") return null;
|
|
32
|
+
if (/^(?:https?|mailto|tel):/i.test(href)) return href;
|
|
33
|
+
return /^(?:[./]|#)/.test(href) ? href : null;
|
|
34
|
+
}
|
|
35
|
+
function textAttr(value) {
|
|
36
|
+
return typeof value === "string" ? value : void 0;
|
|
37
|
+
}
|
|
38
|
+
function noteLabel(node) {
|
|
39
|
+
return node.attrs.customMarkFollows === true ? "" : textAttr(node.attrs.label) ?? "";
|
|
40
|
+
}
|
|
41
|
+
function oneLine(text) {
|
|
42
|
+
return text.replace(/[\n\f]+/g, " ");
|
|
43
|
+
}
|
|
44
|
+
function spanAttribute(count) {
|
|
45
|
+
const span = spanCount(count);
|
|
46
|
+
return span > 1 ? `${span}` : void 0;
|
|
47
|
+
}
|
|
48
|
+
function preservedText(node) {
|
|
49
|
+
const display = node.attrs.display;
|
|
50
|
+
if (display === "break") return "\n";
|
|
51
|
+
if (display !== "text" && display !== "chip") return null;
|
|
52
|
+
const drawn = textAttr(node.attrs.text);
|
|
53
|
+
return drawn === void 0 || drawn === "" ? null : drawn;
|
|
54
|
+
}
|
|
55
|
+
var PRESERVED_SPEC = {
|
|
56
|
+
toClipboardDOM: (node) => {
|
|
57
|
+
const said = preservedText(node);
|
|
58
|
+
if (said === null) return null;
|
|
59
|
+
return said === "\n" ? ["br"] : ["span", said];
|
|
60
|
+
},
|
|
61
|
+
toClipboardText: preservedText
|
|
62
|
+
};
|
|
63
|
+
var WRITES_NOTHING = {
|
|
64
|
+
toClipboardDOM: null,
|
|
65
|
+
toClipboardText: null
|
|
66
|
+
};
|
|
67
|
+
var CLIPBOARD_NODES = {
|
|
68
|
+
// A slice carries blocks, never the document itself, so neither answer is ever asked for
|
|
69
|
+
doc: WRITES_NOTHING,
|
|
70
|
+
paragraph: {
|
|
71
|
+
toClipboardDOM: (node) => [
|
|
72
|
+
"p",
|
|
73
|
+
{
|
|
74
|
+
class: editorClassNames.paragraph,
|
|
75
|
+
style: paragraphStyle(
|
|
76
|
+
toParagraphFormat(node.attrs.format),
|
|
77
|
+
toRunFormat(node.attrs.styleRun)
|
|
78
|
+
),
|
|
79
|
+
[COPIED_STYLE_ATTRIBUTE]: styleIdOf(node.attrs.pPr) ?? void 0
|
|
80
|
+
},
|
|
81
|
+
0
|
|
82
|
+
],
|
|
83
|
+
toClipboardText: (_node, children) => children.join("")
|
|
84
|
+
},
|
|
85
|
+
table: {
|
|
86
|
+
toClipboardDOM: (node) => {
|
|
87
|
+
const attrs = {
|
|
88
|
+
class: editorClassNames.table,
|
|
89
|
+
style: tableStyle(
|
|
90
|
+
toTableFormat(node.attrs.format),
|
|
91
|
+
toTableWidth(node.attrs.tblW)
|
|
92
|
+
)
|
|
93
|
+
};
|
|
94
|
+
const body = ["tbody", 0];
|
|
95
|
+
const columns = toGridCols(node.attrs.gridCols).map((dxa) => [
|
|
96
|
+
"col",
|
|
97
|
+
{ style: `width:${columnWidthPx(dxa)}px` }
|
|
98
|
+
]);
|
|
99
|
+
if (columns.length === 0) return ["table", attrs, body];
|
|
100
|
+
return ["table", attrs, ["colgroup", ...columns], body];
|
|
101
|
+
},
|
|
102
|
+
toClipboardText: (_node, children) => children.join("\n")
|
|
103
|
+
},
|
|
104
|
+
tableRow: {
|
|
105
|
+
toClipboardDOM: (node) => [
|
|
106
|
+
"tr",
|
|
107
|
+
{
|
|
108
|
+
class: editorClassNames.tableRow,
|
|
109
|
+
style: rowStyle(toRowFormat(node.attrs.format))
|
|
110
|
+
},
|
|
111
|
+
0
|
|
112
|
+
],
|
|
113
|
+
toClipboardText: (_node, children) => children.join(" ")
|
|
114
|
+
},
|
|
115
|
+
tableCell: {
|
|
116
|
+
toClipboardDOM: (node) => [
|
|
117
|
+
"td",
|
|
118
|
+
{
|
|
119
|
+
class: editorClassNames.tableCell,
|
|
120
|
+
style: cellStyle(toCellFormat(node.attrs.format)),
|
|
121
|
+
colspan: spanAttribute(node.attrs.colspan),
|
|
122
|
+
rowspan: spanAttribute(node.attrs.rowspan)
|
|
123
|
+
},
|
|
124
|
+
0
|
|
125
|
+
],
|
|
126
|
+
// A tab stands between two cells and a line between two rows wherever a table is pasted as
|
|
127
|
+
// text, so nothing inside a cell may write a line: several paragraphs, a line break of their
|
|
128
|
+
// own and a nested table all say what they hold on the one line this cell stands on
|
|
129
|
+
toClipboardText: (_node, children) => oneLine(children.join(" "))
|
|
130
|
+
},
|
|
131
|
+
rawBlock: WRITES_NOTHING,
|
|
132
|
+
hardBreak: {
|
|
133
|
+
toClipboardDOM: () => ["br"],
|
|
134
|
+
// A page break ends more than a line, and the form feed is what says so in plain text
|
|
135
|
+
toClipboardText: (node) => isPageBreak(node.attrs.brAttrs) ? "\f" : "\n"
|
|
136
|
+
},
|
|
137
|
+
image: {
|
|
138
|
+
// The measure the document keeps stays behind. The pixels it was drawn at are what another
|
|
139
|
+
// application reads a size from, and what a paste back into this editor reads one from
|
|
140
|
+
toClipboardDOM: (node) => ["img", imageAttrs(node.attrs)],
|
|
141
|
+
// A picture is not text. But a copy may be read where no picture can follow, and there the
|
|
142
|
+
// words the document gave it for that very case are better than a gap
|
|
143
|
+
toClipboardText: (node) => textAttr(node.attrs.alt) ?? ""
|
|
144
|
+
},
|
|
145
|
+
commentStart: WRITES_NOTHING,
|
|
146
|
+
commentEnd: WRITES_NOTHING,
|
|
147
|
+
commentReference: WRITES_NOTHING,
|
|
148
|
+
noteReference: {
|
|
149
|
+
// A note whose own mark follows draws no number, and an empty superscript would stand for
|
|
150
|
+
// nothing wherever the copy lands
|
|
151
|
+
toClipboardDOM: (node) => {
|
|
152
|
+
const label = noteLabel(node);
|
|
153
|
+
if (label === "") return null;
|
|
154
|
+
const kind = node.attrs.kind === "endnote" ? "Endnote" : "Footnote";
|
|
155
|
+
return ["sup", { "aria-label": `${kind} ${label}` }, label];
|
|
156
|
+
},
|
|
157
|
+
toClipboardText: noteLabel
|
|
158
|
+
},
|
|
159
|
+
rawRunContent: PRESERVED_SPEC,
|
|
160
|
+
rawInline: PRESERVED_SPEC,
|
|
161
|
+
text: {
|
|
162
|
+
// `DOMSerializer` writes a text node itself and never asks a spec for one, so there is no
|
|
163
|
+
// drawing to declare. The characters travel as they stand
|
|
164
|
+
toClipboardDOM: null,
|
|
165
|
+
toClipboardText: (node) => node.text ?? ""
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var CLIPBOARD_MARKS = {
|
|
169
|
+
// A content control is a wrapper the file keeps and nothing outside this editor reads back, so
|
|
170
|
+
// the text it held leaves on its own rather than inside a span standing for nothing
|
|
171
|
+
sdt: { toClipboardDOM: null },
|
|
172
|
+
link: {
|
|
173
|
+
// The editor draws the address as data so that a click inside the text places the caret.
|
|
174
|
+
// Anywhere else an anchor is what a link is: it follows in mail or a document, and it comes
|
|
175
|
+
// back as a link when it is pasted here again
|
|
176
|
+
toClipboardDOM: (mark) => {
|
|
177
|
+
const href = safeHref(textAttr(mark.attrs.href) ?? null);
|
|
178
|
+
const attrs = { class: editorClassNames.link, href: href ?? void 0 };
|
|
179
|
+
return href === null ? ["span", attrs, 0] : ["a", attrs, 0];
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
run: {
|
|
183
|
+
// The built-in fallbacks rather than the ones this editor was given: a copy is read where the
|
|
184
|
+
// host's font list means nothing, and the schema cannot see which editor it is drawing for
|
|
185
|
+
toClipboardDOM: (mark) => [
|
|
186
|
+
"span",
|
|
187
|
+
runAttrs(mark.attrs, DEFAULT_FONT_FALLBACKS),
|
|
188
|
+
0
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
tab: { toClipboardDOM: () => ["span", { class: editorClassNames.tab }, 0] }
|
|
192
|
+
};
|
|
193
|
+
var clipboardSpecs = { nodes: CLIPBOARD_NODES, marks: CLIPBOARD_MARKS };
|
|
194
|
+
var NODES_BY_NAME = CLIPBOARD_NODES;
|
|
195
|
+
function nodeSpec(node) {
|
|
196
|
+
return NODES_BY_NAME[node.type.name];
|
|
197
|
+
}
|
|
198
|
+
function clipboardDOMOf(node) {
|
|
199
|
+
const spec = nodeSpec(node);
|
|
200
|
+
if (spec === void 0 || spec.toClipboardDOM === null) return null;
|
|
201
|
+
return spec.toClipboardDOM(node);
|
|
202
|
+
}
|
|
203
|
+
function written(fragment) {
|
|
204
|
+
const kept = [];
|
|
205
|
+
fragment.forEach((child) => {
|
|
206
|
+
if (child.isText || clipboardDOMOf(child) !== null) kept.push(child);
|
|
207
|
+
});
|
|
208
|
+
return kept.length === fragment.childCount ? fragment : Fragment.from(kept);
|
|
209
|
+
}
|
|
210
|
+
var ClipboardSerializer = class extends DOMSerializer {
|
|
211
|
+
constructor(stampCopy) {
|
|
212
|
+
super(clipboardNodes(), clipboardMarks());
|
|
213
|
+
this.stampCopy = stampCopy;
|
|
214
|
+
}
|
|
215
|
+
stampCopy;
|
|
216
|
+
serializeFragment(fragment, options, target) {
|
|
217
|
+
const dom = super.serializeFragment(written(fragment), options, target);
|
|
218
|
+
if (target !== void 0) return dom;
|
|
219
|
+
if (dom.firstChild === null && fragment.childCount > 0) {
|
|
220
|
+
carrier(dom, options?.document);
|
|
221
|
+
}
|
|
222
|
+
this.stampCopy?.(dom);
|
|
223
|
+
return dom;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function carrier(copy, document) {
|
|
227
|
+
const owner = document ?? copy.ownerDocument;
|
|
228
|
+
if (owner !== null) copy.appendChild(owner.createElement("span"));
|
|
229
|
+
}
|
|
230
|
+
function clipboardNodes() {
|
|
231
|
+
return Object.fromEntries(
|
|
232
|
+
Object.entries(CLIPBOARD_NODES).flatMap(([name, spec]) => {
|
|
233
|
+
const draw = spec.toClipboardDOM;
|
|
234
|
+
return draw === null ? [] : [
|
|
235
|
+
[
|
|
236
|
+
name,
|
|
237
|
+
(node) => {
|
|
238
|
+
const drawn = draw(node);
|
|
239
|
+
if (drawn === null) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
`${name} was serialized after drawing nothing`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return drawn;
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
];
|
|
248
|
+
})
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
function clipboardMarks() {
|
|
252
|
+
return Object.fromEntries(
|
|
253
|
+
Object.entries(CLIPBOARD_MARKS).flatMap(
|
|
254
|
+
([name, spec]) => (
|
|
255
|
+
// A mark with no drawing of its own is left out, and `DOMSerializer` writes the content it
|
|
256
|
+
// covered without a wrapper
|
|
257
|
+
spec.toClipboardDOM === null ? [] : [[name, spec.toClipboardDOM]]
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
function clipboardSerializer(stampCopy) {
|
|
263
|
+
return new ClipboardSerializer(stampCopy);
|
|
264
|
+
}
|
|
265
|
+
function textPieces(fragment) {
|
|
266
|
+
const pieces = [];
|
|
267
|
+
fragment.forEach((child) => {
|
|
268
|
+
const piece = clipboardTextOf(child);
|
|
269
|
+
if (piece !== null) pieces.push(piece);
|
|
270
|
+
});
|
|
271
|
+
return pieces;
|
|
272
|
+
}
|
|
273
|
+
function clipboardTextOf(node) {
|
|
274
|
+
const spec = nodeSpec(node);
|
|
275
|
+
if (spec === void 0 || spec.toClipboardText === null) return null;
|
|
276
|
+
return spec.toClipboardText(node, textPieces(node.content));
|
|
277
|
+
}
|
|
278
|
+
function clipboardText(slice) {
|
|
279
|
+
const pieces = textPieces(slice.content);
|
|
280
|
+
return pieces.join(slice.content.firstChild?.isInline === true ? "" : "\n");
|
|
281
|
+
}
|
|
282
|
+
export {
|
|
283
|
+
COPIED_STYLE_ATTRIBUTE,
|
|
284
|
+
clipboardSerializer,
|
|
285
|
+
clipboardSpecs,
|
|
286
|
+
clipboardText,
|
|
287
|
+
safeHref
|
|
288
|
+
};
|
|
@@ -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">;
|