@coco-vexel/coco-office-editor 1.0.10 → 1.0.11
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/dist/index.cjs +1513 -28489
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1512 -28267
- package/dist/{model-DT8Dw2G6.d.cts → model-CgISL5eB.d.cts} +2 -0
- package/dist/{model-DT8Dw2G6.d.ts → model-CgISL5eB.d.ts} +2 -0
- package/dist/{native-C3ZdrIcW.d.ts → native-D9lhNG94.d.ts} +2 -1
- package/dist/{native-wR2uhZvi.d.cts → native-DVRWKaOC.d.cts} +2 -1
- package/dist/ppt-native.cjs +7 -5369
- package/dist/ppt-native.js +7 -5367
- package/dist/ppt.cjs +7 -5462
- package/dist/ppt.js +7 -5445
- package/dist/spreadsheet.cjs +11 -5789
- package/dist/spreadsheet.js +11 -5718
- package/dist/word-editing.cjs +2 -812
- package/dist/word-editing.js +2 -803
- package/dist/word-native.cjs +1541 -13831
- package/dist/word-native.d.cts +2 -2
- package/dist/word-native.d.ts +2 -2
- package/dist/word-native.js +1541 -13723
- package/dist/word-prosemirror.cjs +1 -489
- package/dist/word-prosemirror.js +1 -483
- package/dist/word.cjs +1373 -17298
- package/dist/word.d.cts +5 -5
- package/dist/word.d.ts +5 -5
- package/dist/word.js +1373 -17163
- package/package.json +3 -3
- package/src/styles/editor.css +49 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ppt-native.cjs.map +0 -1
- package/dist/ppt-native.js.map +0 -1
- package/dist/ppt.cjs.map +0 -1
- package/dist/ppt.js.map +0 -1
- package/dist/spreadsheet.cjs.map +0 -1
- package/dist/spreadsheet.js.map +0 -1
- package/dist/word-editing.cjs.map +0 -1
- package/dist/word-editing.js.map +0 -1
- package/dist/word-native.cjs.map +0 -1
- package/dist/word-native.js.map +0 -1
- package/dist/word-prosemirror.cjs.map +0 -1
- package/dist/word-prosemirror.js.map +0 -1
- package/dist/word.cjs.map +0 -1
- package/dist/word.js.map +0 -1
package/dist/word-prosemirror.js
CHANGED
|
@@ -1,483 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { baseKeymap } from 'prosemirror-commands';
|
|
3
|
-
import { keymap } from 'prosemirror-keymap';
|
|
4
|
-
import { PluginKey, EditorState, Plugin } from 'prosemirror-state';
|
|
5
|
-
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defProps = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
27
|
-
var wordEditorSchema = new Schema({
|
|
28
|
-
nodes: {
|
|
29
|
-
doc: { content: "block+" },
|
|
30
|
-
paragraph: {
|
|
31
|
-
group: "block",
|
|
32
|
-
content: "inline*",
|
|
33
|
-
attrs: {
|
|
34
|
-
paraId: { default: "" },
|
|
35
|
-
story: { default: "body" },
|
|
36
|
-
styleId: { default: null },
|
|
37
|
-
format: { default: null }
|
|
38
|
-
},
|
|
39
|
-
parseDOM: [{ tag: "p" }],
|
|
40
|
-
toDOM: /* @__PURE__ */ __name((node) => ["p", paragraphDomAttrs(node.attrs), 0], "toDOM")
|
|
41
|
-
},
|
|
42
|
-
table: {
|
|
43
|
-
group: "block",
|
|
44
|
-
content: "table_row+",
|
|
45
|
-
attrs: {
|
|
46
|
-
tableId: { default: "" },
|
|
47
|
-
columnWidths: { default: null }
|
|
48
|
-
},
|
|
49
|
-
tableRole: "table",
|
|
50
|
-
toDOM: /* @__PURE__ */ __name((node) => [
|
|
51
|
-
"div",
|
|
52
|
-
{ class: "coco-word-table-scroll" },
|
|
53
|
-
["table", tableDomAttrs(node.attrs), ["tbody", 0]]
|
|
54
|
-
], "toDOM")
|
|
55
|
-
},
|
|
56
|
-
table_row: {
|
|
57
|
-
content: "table_cell+",
|
|
58
|
-
tableRole: "row",
|
|
59
|
-
toDOM: /* @__PURE__ */ __name(() => ["tr", 0], "toDOM")
|
|
60
|
-
},
|
|
61
|
-
table_cell: {
|
|
62
|
-
content: "block+",
|
|
63
|
-
attrs: {
|
|
64
|
-
colspan: { default: 1 },
|
|
65
|
-
rowspan: { default: 1 },
|
|
66
|
-
width: { default: null },
|
|
67
|
-
shading: { default: null },
|
|
68
|
-
verticalAlignment: { default: null }
|
|
69
|
-
},
|
|
70
|
-
tableRole: "cell",
|
|
71
|
-
toDOM: /* @__PURE__ */ __name((node) => ["td", tableCellDomAttrs(node.attrs), 0], "toDOM")
|
|
72
|
-
},
|
|
73
|
-
image: {
|
|
74
|
-
inline: true,
|
|
75
|
-
group: "inline",
|
|
76
|
-
atom: true,
|
|
77
|
-
attrs: {
|
|
78
|
-
src: {},
|
|
79
|
-
alt: { default: "" },
|
|
80
|
-
width: { default: null },
|
|
81
|
-
height: { default: null },
|
|
82
|
-
drawingId: { default: null }
|
|
83
|
-
},
|
|
84
|
-
toDOM: /* @__PURE__ */ __name((node) => ["img", imageDomAttrs(node.attrs)], "toDOM")
|
|
85
|
-
},
|
|
86
|
-
text: { group: "inline" }
|
|
87
|
-
},
|
|
88
|
-
marks: {
|
|
89
|
-
strong: {
|
|
90
|
-
parseDOM: [{ tag: "strong" }, { tag: "b" }],
|
|
91
|
-
toDOM: /* @__PURE__ */ __name(() => ["strong", 0], "toDOM")
|
|
92
|
-
},
|
|
93
|
-
em: {
|
|
94
|
-
parseDOM: [{ tag: "em" }, { tag: "i" }],
|
|
95
|
-
toDOM: /* @__PURE__ */ __name(() => ["em", 0], "toDOM")
|
|
96
|
-
},
|
|
97
|
-
underline: {
|
|
98
|
-
parseDOM: [{ tag: "u" }],
|
|
99
|
-
toDOM: /* @__PURE__ */ __name(() => ["u", 0], "toDOM")
|
|
100
|
-
},
|
|
101
|
-
textStyle: {
|
|
102
|
-
attrs: {
|
|
103
|
-
color: { default: null },
|
|
104
|
-
fontSize: { default: null }
|
|
105
|
-
},
|
|
106
|
-
parseDOM: [{ tag: "span" }],
|
|
107
|
-
toDOM: /* @__PURE__ */ __name((mark) => ["span", textStyleDomAttrs(mark.attrs), 0], "toDOM")
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
var wordDecorationsKey = new PluginKey("coco-word-decorations");
|
|
112
|
-
var wordStructureNormalizationKey = new PluginKey("coco-word-structure-normalization");
|
|
113
|
-
function createWordEditorState(view, options = {}) {
|
|
114
|
-
var _a;
|
|
115
|
-
const projection = projectWordViewToProseMirror(view);
|
|
116
|
-
return EditorState.create({
|
|
117
|
-
schema: wordEditorSchema,
|
|
118
|
-
doc: projection.doc,
|
|
119
|
-
plugins: [
|
|
120
|
-
createWordDecorationsPlugin(projection.decorations),
|
|
121
|
-
keymap(baseKeymap),
|
|
122
|
-
createWordStructureNormalizationPlugin(),
|
|
123
|
-
...(_a = options.plugins) != null ? _a : []
|
|
124
|
-
]
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
__name(createWordEditorState, "createWordEditorState");
|
|
128
|
-
function projectWordViewToProseMirror(view) {
|
|
129
|
-
const paragraphContentPos = /* @__PURE__ */ new Map();
|
|
130
|
-
const blocks = view.blocks.map((block) => blockToNode(block));
|
|
131
|
-
const doc = wordEditorSchema.nodes.doc.create(null, blocks);
|
|
132
|
-
doc.descendants((node, pos) => {
|
|
133
|
-
if (node.type === wordEditorSchema.nodes.paragraph && typeof node.attrs.paraId === "string") {
|
|
134
|
-
paragraphContentPos.set(node.attrs.paraId, pos + 1);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
const decorations = [];
|
|
138
|
-
for (const paragraph of view.paragraphs) {
|
|
139
|
-
const base = paragraphContentPos.get(paragraph.paraId);
|
|
140
|
-
for (const span of paragraph.spans) {
|
|
141
|
-
if (span.to <= span.from) {
|
|
142
|
-
if (span.kind === "comment") {
|
|
143
|
-
decorations.push(createCommentWidget(base + span.from, span));
|
|
144
|
-
}
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
const className = span.kind === "comment" ? "coco-word-comment" : span.revisionKind === "delete" ? "coco-word-revision-delete" : "coco-word-revision-insert";
|
|
148
|
-
decorations.push(
|
|
149
|
-
Decoration.inline(
|
|
150
|
-
base + span.from,
|
|
151
|
-
base + span.to,
|
|
152
|
-
__spreadValues({
|
|
153
|
-
class: className
|
|
154
|
-
}, span.kind === "comment" ? commentDomAttrs(span) : {}),
|
|
155
|
-
{
|
|
156
|
-
id: span.id,
|
|
157
|
-
kind: span.kind,
|
|
158
|
-
paraId: paragraph.paraId
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
doc,
|
|
166
|
-
decorations: DecorationSet.create(doc, decorations),
|
|
167
|
-
paragraphContentPos
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
__name(projectWordViewToProseMirror, "projectWordViewToProseMirror");
|
|
171
|
-
function createCommentWidget(pos, span) {
|
|
172
|
-
return Decoration.widget(
|
|
173
|
-
pos,
|
|
174
|
-
() => {
|
|
175
|
-
const marker = document.createElement("span");
|
|
176
|
-
marker.className = "coco-word-comment-widget";
|
|
177
|
-
marker.dataset.commentId = String(span.commentId);
|
|
178
|
-
marker.title = commentTitle(span);
|
|
179
|
-
marker.textContent = "!";
|
|
180
|
-
return marker;
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
id: span.id,
|
|
184
|
-
kind: "comment",
|
|
185
|
-
side: 1
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
__name(createCommentWidget, "createCommentWidget");
|
|
190
|
-
function commentDomAttrs(span) {
|
|
191
|
-
return {
|
|
192
|
-
"data-comment-id": String(span.commentId),
|
|
193
|
-
title: commentTitle(span)
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
__name(commentDomAttrs, "commentDomAttrs");
|
|
197
|
-
function commentTitle(span) {
|
|
198
|
-
const body = span.body.trim();
|
|
199
|
-
return body.length > 0 ? `Comment ${span.commentId}: ${body}` : `Comment ${span.commentId}`;
|
|
200
|
-
}
|
|
201
|
-
__name(commentTitle, "commentTitle");
|
|
202
|
-
function blockToNode(block) {
|
|
203
|
-
return block.type === "table" ? tableToNode(block) : paragraphToNode(block);
|
|
204
|
-
}
|
|
205
|
-
__name(blockToNode, "blockToNode");
|
|
206
|
-
function paragraphToNode(paragraph) {
|
|
207
|
-
var _a, _b;
|
|
208
|
-
return wordEditorSchema.nodes.paragraph.create(
|
|
209
|
-
{
|
|
210
|
-
paraId: paragraph.paraId,
|
|
211
|
-
story: paragraph.story,
|
|
212
|
-
styleId: (_a = paragraph.styleId) != null ? _a : null,
|
|
213
|
-
format: (_b = paragraph.format) != null ? _b : null
|
|
214
|
-
},
|
|
215
|
-
paragraph.segments.length > 0 ? paragraph.segments.flatMap((segment) => {
|
|
216
|
-
var _a2, _b2, _c;
|
|
217
|
-
if (segment.kind === "placeholder") {
|
|
218
|
-
return [wordEditorSchema.text("\uFFFC")];
|
|
219
|
-
}
|
|
220
|
-
if (segment.kind === "drawing") {
|
|
221
|
-
return [wordEditorSchema.text(segment.text && segment.text.length > 0 ? segment.text : "\uFFFC")];
|
|
222
|
-
}
|
|
223
|
-
if (segment.kind === "field") {
|
|
224
|
-
return [wordEditorSchema.text((_a2 = segment.cachedText) != null ? _a2 : "\uFFFC", marksForRunFormat(segment.format))];
|
|
225
|
-
}
|
|
226
|
-
if (segment.kind === "image") {
|
|
227
|
-
return [
|
|
228
|
-
wordEditorSchema.nodes.image.create({
|
|
229
|
-
src: segment.src,
|
|
230
|
-
alt: segment.drawingId,
|
|
231
|
-
width: (_b2 = segment.width) != null ? _b2 : null,
|
|
232
|
-
height: (_c = segment.height) != null ? _c : null,
|
|
233
|
-
drawingId: segment.drawingId
|
|
234
|
-
})
|
|
235
|
-
];
|
|
236
|
-
}
|
|
237
|
-
if (segment.text.length === 0) return [];
|
|
238
|
-
const format = segment.kind === "text" ? segment.format : void 0;
|
|
239
|
-
return [wordEditorSchema.text(segment.text, marksForRunFormat(format))];
|
|
240
|
-
}) : paragraph.text.length > 0 ? wordEditorSchema.text(paragraph.text) : void 0
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
__name(paragraphToNode, "paragraphToNode");
|
|
244
|
-
function tableToNode(table) {
|
|
245
|
-
return wordEditorSchema.nodes.table.create(
|
|
246
|
-
{ tableId: table.tableId, columnWidths: table.columnWidths },
|
|
247
|
-
table.rows.map(
|
|
248
|
-
(row) => wordEditorSchema.nodes.table_row.create(
|
|
249
|
-
null,
|
|
250
|
-
row.cells.filter((cell) => cell.vMerge !== "continue").map((cell) => tableCellToNode(cell))
|
|
251
|
-
)
|
|
252
|
-
)
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
__name(tableToNode, "tableToNode");
|
|
256
|
-
function tableCellToNode(cell) {
|
|
257
|
-
var _a, _b, _c, _d;
|
|
258
|
-
const paragraphs = cell.paragraphs.length > 0 ? cell.paragraphs.map((paragraph) => paragraphToNode(paragraph)) : [wordEditorSchema.nodes.paragraph.create(null)];
|
|
259
|
-
return wordEditorSchema.nodes.table_cell.create(
|
|
260
|
-
{
|
|
261
|
-
colspan: Math.max(1, cell.gridSpan),
|
|
262
|
-
rowspan: Math.max(1, (_a = cell.rowSpan) != null ? _a : 1),
|
|
263
|
-
width: (_b = cell.width) != null ? _b : null,
|
|
264
|
-
shading: (_c = cell.shading) != null ? _c : null,
|
|
265
|
-
verticalAlignment: (_d = cell.verticalAlignment) != null ? _d : null
|
|
266
|
-
},
|
|
267
|
-
paragraphs
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
__name(tableCellToNode, "tableCellToNode");
|
|
271
|
-
function marksForRunFormat(format) {
|
|
272
|
-
var _a, _b;
|
|
273
|
-
if (!format) return void 0;
|
|
274
|
-
const marks = [];
|
|
275
|
-
if (format.bold) marks.push(wordEditorSchema.marks.strong.create());
|
|
276
|
-
if (format.italic) marks.push(wordEditorSchema.marks.em.create());
|
|
277
|
-
if (format.underline) marks.push(wordEditorSchema.marks.underline.create());
|
|
278
|
-
if (format.color || format.fontSize) {
|
|
279
|
-
marks.push(
|
|
280
|
-
wordEditorSchema.marks.textStyle.create({
|
|
281
|
-
color: (_a = format.color) != null ? _a : null,
|
|
282
|
-
fontSize: (_b = format.fontSize) != null ? _b : null
|
|
283
|
-
})
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
return marks.length > 0 ? marks : void 0;
|
|
287
|
-
}
|
|
288
|
-
__name(marksForRunFormat, "marksForRunFormat");
|
|
289
|
-
function paragraphDomAttrs(attrs) {
|
|
290
|
-
const domAttrs = {};
|
|
291
|
-
if (typeof attrs.paraId === "string" && attrs.paraId.length > 0) {
|
|
292
|
-
domAttrs["data-para-id"] = attrs.paraId;
|
|
293
|
-
}
|
|
294
|
-
if (typeof attrs.story === "string" && attrs.story.length > 0) {
|
|
295
|
-
domAttrs["data-story"] = attrs.story;
|
|
296
|
-
}
|
|
297
|
-
if (typeof attrs.styleId === "string" && attrs.styleId.length > 0) {
|
|
298
|
-
domAttrs["data-style-id"] = attrs.styleId;
|
|
299
|
-
}
|
|
300
|
-
const format = isParagraphFormat(attrs.format) ? attrs.format : null;
|
|
301
|
-
if ((format == null ? void 0 : format.outlineLevel) !== void 0) {
|
|
302
|
-
domAttrs["data-outline-level"] = String(format.outlineLevel);
|
|
303
|
-
}
|
|
304
|
-
const style = paragraphStyle(format);
|
|
305
|
-
if (style.length > 0) domAttrs.style = style;
|
|
306
|
-
return domAttrs;
|
|
307
|
-
}
|
|
308
|
-
__name(paragraphDomAttrs, "paragraphDomAttrs");
|
|
309
|
-
function tableDomAttrs(attrs) {
|
|
310
|
-
const domAttrs = {};
|
|
311
|
-
if (typeof attrs.tableId === "string" && attrs.tableId.length > 0) {
|
|
312
|
-
domAttrs["data-table-id"] = attrs.tableId;
|
|
313
|
-
}
|
|
314
|
-
return domAttrs;
|
|
315
|
-
}
|
|
316
|
-
__name(tableDomAttrs, "tableDomAttrs");
|
|
317
|
-
function tableCellDomAttrs(attrs) {
|
|
318
|
-
const domAttrs = {};
|
|
319
|
-
if (typeof attrs.colspan === "number" && attrs.colspan > 1) {
|
|
320
|
-
domAttrs.colspan = String(attrs.colspan);
|
|
321
|
-
}
|
|
322
|
-
if (typeof attrs.rowspan === "number" && attrs.rowspan > 1) {
|
|
323
|
-
domAttrs.rowspan = String(attrs.rowspan);
|
|
324
|
-
}
|
|
325
|
-
const style = [];
|
|
326
|
-
if (typeof attrs.width === "number" && attrs.width > 0) {
|
|
327
|
-
style.push(`width: ${twipsToPt(attrs.width)}`);
|
|
328
|
-
}
|
|
329
|
-
if (isShading(attrs.shading)) {
|
|
330
|
-
const fill = colorToCss(attrs.shading.fill);
|
|
331
|
-
if (fill) style.push(`background-color: ${fill}`);
|
|
332
|
-
}
|
|
333
|
-
if (typeof attrs.verticalAlignment === "string") {
|
|
334
|
-
style.push(`vertical-align: ${attrs.verticalAlignment === "center" ? "middle" : attrs.verticalAlignment}`);
|
|
335
|
-
}
|
|
336
|
-
if (style.length > 0) domAttrs.style = style.join("; ");
|
|
337
|
-
return domAttrs;
|
|
338
|
-
}
|
|
339
|
-
__name(tableCellDomAttrs, "tableCellDomAttrs");
|
|
340
|
-
function imageDomAttrs(attrs) {
|
|
341
|
-
const domAttrs = {
|
|
342
|
-
src: typeof attrs.src === "string" ? attrs.src : "",
|
|
343
|
-
alt: typeof attrs.alt === "string" ? attrs.alt : ""
|
|
344
|
-
};
|
|
345
|
-
if (typeof attrs.drawingId === "string") domAttrs["data-drawing-id"] = attrs.drawingId;
|
|
346
|
-
const style = [];
|
|
347
|
-
if (typeof attrs.width === "number" && attrs.width > 0) {
|
|
348
|
-
style.push(`width: ${attrs.width}px`);
|
|
349
|
-
}
|
|
350
|
-
if (typeof attrs.height === "number" && attrs.height > 0) {
|
|
351
|
-
style.push(`height: ${attrs.height}px`);
|
|
352
|
-
}
|
|
353
|
-
if (style.length > 0) domAttrs.style = style.join("; ");
|
|
354
|
-
return domAttrs;
|
|
355
|
-
}
|
|
356
|
-
__name(imageDomAttrs, "imageDomAttrs");
|
|
357
|
-
function isShading(value) {
|
|
358
|
-
return value !== null && typeof value === "object";
|
|
359
|
-
}
|
|
360
|
-
__name(isShading, "isShading");
|
|
361
|
-
function textStyleDomAttrs(attrs) {
|
|
362
|
-
const style = [];
|
|
363
|
-
const color = typeof attrs.color === "string" ? colorToCss(attrs.color) : null;
|
|
364
|
-
if (color) style.push(`color: ${color}`);
|
|
365
|
-
if (typeof attrs.fontSize === "number") style.push(`font-size: ${attrs.fontSize}pt`);
|
|
366
|
-
return style.length > 0 ? { style: style.join("; ") } : {};
|
|
367
|
-
}
|
|
368
|
-
__name(textStyleDomAttrs, "textStyleDomAttrs");
|
|
369
|
-
function isParagraphFormat(value) {
|
|
370
|
-
return value !== null && typeof value === "object";
|
|
371
|
-
}
|
|
372
|
-
__name(isParagraphFormat, "isParagraphFormat");
|
|
373
|
-
function paragraphStyle(format) {
|
|
374
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
375
|
-
if (!format) return "";
|
|
376
|
-
const declarations = [];
|
|
377
|
-
if (format.alignment) declarations.push(`text-align: ${alignmentToCss(format.alignment)}`);
|
|
378
|
-
if (((_a = format.indent) == null ? void 0 : _a.left) !== void 0) declarations.push(`margin-left: ${twipsToPt(format.indent.left)}`);
|
|
379
|
-
if (((_b = format.indent) == null ? void 0 : _b.right) !== void 0) declarations.push(`margin-right: ${twipsToPt(format.indent.right)}`);
|
|
380
|
-
if (((_c = format.indent) == null ? void 0 : _c.firstLine) !== void 0) {
|
|
381
|
-
declarations.push(`text-indent: ${twipsToPt(format.indent.firstLine)}`);
|
|
382
|
-
}
|
|
383
|
-
if (((_d = format.spacing) == null ? void 0 : _d.before) !== void 0) {
|
|
384
|
-
declarations.push(`margin-top: ${twipsToPt(format.spacing.before)}`);
|
|
385
|
-
}
|
|
386
|
-
if (((_e = format.spacing) == null ? void 0 : _e.after) !== void 0) {
|
|
387
|
-
declarations.push(`margin-bottom: ${twipsToPt(format.spacing.after)}`);
|
|
388
|
-
}
|
|
389
|
-
const lineHeight = lineHeightToCss((_f = format.spacing) == null ? void 0 : _f.line, (_g = format.spacing) == null ? void 0 : _g.lineRule);
|
|
390
|
-
if (lineHeight) declarations.push(`line-height: ${lineHeight}`);
|
|
391
|
-
if (format.fontSize !== void 0) declarations.push(`font-size: ${format.fontSize}pt`);
|
|
392
|
-
if (format.bold !== void 0) declarations.push(`font-weight: ${format.bold ? "700" : "400"}`);
|
|
393
|
-
const borderBottom = borderToCss(format.borderBottom);
|
|
394
|
-
if (borderBottom) {
|
|
395
|
-
declarations.push(`border-bottom: ${borderBottom}`);
|
|
396
|
-
declarations.push(`padding-bottom: ${(_i = (_h = format.borderBottom) == null ? void 0 : _h.space) != null ? _i : 4}pt`);
|
|
397
|
-
}
|
|
398
|
-
return declarations.join("; ");
|
|
399
|
-
}
|
|
400
|
-
__name(paragraphStyle, "paragraphStyle");
|
|
401
|
-
function alignmentToCss(alignment) {
|
|
402
|
-
if (alignment === "both" || alignment === "distribute") return "justify";
|
|
403
|
-
return alignment;
|
|
404
|
-
}
|
|
405
|
-
__name(alignmentToCss, "alignmentToCss");
|
|
406
|
-
function borderToCss(border) {
|
|
407
|
-
var _a;
|
|
408
|
-
if (!border || border.val === "none" || border.val === "nil") return null;
|
|
409
|
-
const color = (_a = colorToCss(border.color)) != null ? _a : "#000000";
|
|
410
|
-
const widthPt = border.size !== void 0 ? Math.max(0.75, border.size / 8) : 0.75;
|
|
411
|
-
const style = border.val === "double" ? "double" : "solid";
|
|
412
|
-
return `${widthPt}pt ${style} ${color}`;
|
|
413
|
-
}
|
|
414
|
-
__name(borderToCss, "borderToCss");
|
|
415
|
-
function lineHeightToCss(line, lineRule) {
|
|
416
|
-
if (line === void 0) return null;
|
|
417
|
-
if (lineRule === "exact" || lineRule === "atLeast") return twipsToPt(line);
|
|
418
|
-
return String(line / 240);
|
|
419
|
-
}
|
|
420
|
-
__name(lineHeightToCss, "lineHeightToCss");
|
|
421
|
-
function twipsToPt(twips) {
|
|
422
|
-
return `${twips / 20}pt`;
|
|
423
|
-
}
|
|
424
|
-
__name(twipsToPt, "twipsToPt");
|
|
425
|
-
function colorToCss(color) {
|
|
426
|
-
if (!color || color === "auto") return null;
|
|
427
|
-
return /^[0-9a-f]{6}$/i.test(color) ? `#${color}` : null;
|
|
428
|
-
}
|
|
429
|
-
__name(colorToCss, "colorToCss");
|
|
430
|
-
function createWordDecorationsPlugin(decorations) {
|
|
431
|
-
return new Plugin({
|
|
432
|
-
key: wordDecorationsKey,
|
|
433
|
-
state: {
|
|
434
|
-
init: /* @__PURE__ */ __name(() => decorations, "init"),
|
|
435
|
-
apply: /* @__PURE__ */ __name((tr, set) => set.map(tr.mapping, tr.doc), "apply")
|
|
436
|
-
},
|
|
437
|
-
props: {
|
|
438
|
-
decorations(state) {
|
|
439
|
-
return wordDecorationsKey.getState(state);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
__name(createWordDecorationsPlugin, "createWordDecorationsPlugin");
|
|
445
|
-
function createWordStructureNormalizationPlugin() {
|
|
446
|
-
return new Plugin({
|
|
447
|
-
key: wordStructureNormalizationKey,
|
|
448
|
-
appendTransaction(transactions, _oldState, newState) {
|
|
449
|
-
if (!transactions.some((tr2) => tr2.docChanged)) return null;
|
|
450
|
-
if (transactions.some((tr2) => tr2.getMeta(wordStructureNormalizationKey))) return null;
|
|
451
|
-
const seen = /* @__PURE__ */ new Set();
|
|
452
|
-
let tr = newState.tr;
|
|
453
|
-
let changed = false;
|
|
454
|
-
newState.doc.descendants((node, pos) => {
|
|
455
|
-
if (node.type !== wordEditorSchema.nodes.paragraph) return true;
|
|
456
|
-
const paraId = typeof node.attrs.paraId === "string" ? node.attrs.paraId : "";
|
|
457
|
-
if (paraId && !seen.has(paraId)) {
|
|
458
|
-
seen.add(paraId);
|
|
459
|
-
return true;
|
|
460
|
-
}
|
|
461
|
-
const nextParaId = nextUniqueParaId(seen);
|
|
462
|
-
seen.add(nextParaId);
|
|
463
|
-
tr = tr.setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, node.attrs), { paraId: nextParaId }));
|
|
464
|
-
changed = true;
|
|
465
|
-
return true;
|
|
466
|
-
});
|
|
467
|
-
return changed ? tr.setMeta(wordStructureNormalizationKey, { normalized: true }) : null;
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
__name(createWordStructureNormalizationPlugin, "createWordStructureNormalizationPlugin");
|
|
472
|
-
function nextUniqueParaId(seen) {
|
|
473
|
-
let paraId = "";
|
|
474
|
-
do {
|
|
475
|
-
paraId = Math.floor(Math.random() * 4294967295).toString(16).toUpperCase().padStart(8, "0");
|
|
476
|
-
} while (!paraId || seen.has(paraId));
|
|
477
|
-
return paraId;
|
|
478
|
-
}
|
|
479
|
-
__name(nextUniqueParaId, "nextUniqueParaId");
|
|
480
|
-
|
|
481
|
-
export { createWordEditorState, projectWordViewToProseMirror, wordDecorationsKey, wordEditorSchema, wordStructureNormalizationKey };
|
|
482
|
-
//# sourceMappingURL=word-prosemirror.js.map
|
|
483
|
-
//# sourceMappingURL=word-prosemirror.js.map
|
|
1
|
+
import {Schema}from'prosemirror-model';import {baseKeymap}from'prosemirror-commands';import {keymap}from'prosemirror-keymap';import {PluginKey,EditorState,Plugin}from'prosemirror-state';import {Decoration,DecorationSet}from'prosemirror-view';var E=Object.defineProperty,C=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var y=(t,n,e)=>n in t?E(t,n,{enumerable:true,configurable:true,writable:true,value:e}):t[n]=e,p=(t,n)=>{for(var e in n||(n={}))v.call(n,e)&&y(t,e,n[e]);if(b)for(var e of b(n))N.call(n,e)&&y(t,e,n[e]);return t},k=(t,n)=>C(t,F(n));var d=new Schema({nodes:{doc:{content:"block+"},paragraph:{group:"block",content:"inline*",attrs:{paraId:{default:""},story:{default:"body"},styleId:{default:null},format:{default:null}},parseDOM:[{tag:"p"}],toDOM:t=>["p",K(t.attrs),0]},table:{group:"block",content:"table_row+",attrs:{tableId:{default:""},columnWidths:{default:null}},tableRole:"table",toDOM:t=>["div",{class:"coco-word-table-scroll"},["table",H(t.attrs),["tbody",0]]]},table_row:{content:"table_cell+",tableRole:"row",toDOM:()=>["tr",0]},table_cell:{content:"block+",attrs:{colspan:{default:1},rowspan:{default:1},width:{default:null},shading:{default:null},verticalAlignment:{default:null}},tableRole:"cell",toDOM:t=>["td",U(t.attrs),0]},image:{inline:true,group:"inline",atom:true,attrs:{src:{},alt:{default:""},width:{default:null},height:{default:null},drawingId:{default:null}},toDOM:t=>["img",q(t.attrs)]},text:{group:"inline"}},marks:{strong:{parseDOM:[{tag:"strong"},{tag:"b"}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"em"},{tag:"i"}],toDOM:()=>["em",0]},underline:{parseDOM:[{tag:"u"}],toDOM:()=>["u",0]},textStyle:{attrs:{color:{default:null},fontSize:{default:null}},parseDOM:[{tag:"span"}],toDOM:t=>["span",J(t.attrs),0]}}}),I=new PluginKey("coco-word-decorations"),g=new PluginKey("coco-word-structure-normalization");function ut(t,n={}){var o;let e=W(t);return EditorState.create({schema:d,doc:e.doc,plugins:[nt(e.decorations),keymap(baseKeymap),et(),...(o=n.plugins)!=null?o:[]]})}function W(t){let n=new Map,e=t.blocks.map(i=>_(i)),o=d.nodes.doc.create(null,e);o.descendants((i,r)=>{i.type===d.nodes.paragraph&&typeof i.attrs.paraId=="string"&&n.set(i.attrs.paraId,r+1);});let l=[];for(let i of t.paragraphs){let r=n.get(i.paraId);for(let a of i.spans){if(a.to<=a.from){a.kind==="comment"&&l.push(j(r+a.from,a));continue}let s=a.kind==="comment"?"coco-word-comment":a.revisionKind==="delete"?"coco-word-revision-delete":"coco-word-revision-insert";l.push(Decoration.inline(r+a.from,r+a.to,p({class:s},a.kind==="comment"?V(a):{}),{id:a.id,kind:a.kind,paraId:i.paraId}));}}return {doc:o,decorations:DecorationSet.create(o,l),paragraphContentPos:n}}function j(t,n){return Decoration.widget(t,()=>{let e=document.createElement("span");return e.className="coco-word-comment-widget",e.dataset.commentId=String(n.commentId),e.title=P(n),e.textContent="!",e},{id:n.id,kind:"comment",side:1})}function V(t){return {"data-comment-id":String(t.commentId),title:P(t)}}function P(t){let n=t.body.trim();return n.length>0?`Comment ${t.commentId}: ${n}`:`Comment ${t.commentId}`}function _(t){return t.type==="table"?B(t):$(t)}function $(t){var n,e;return d.nodes.paragraph.create({paraId:t.paraId,story:t.story,styleId:(n=t.styleId)!=null?n:null,format:(e=t.format)!=null?e:null},t.segments.length>0?t.segments.flatMap(o=>{var i,r,a;if(o.kind==="placeholder")return [d.text("\uFFFC")];if(o.kind==="drawing")return [d.text(o.text&&o.text.length>0?o.text:"\uFFFC")];if(o.kind==="field")return [d.text((i=o.cachedText)!=null?i:"\uFFFC",S(o.format))];if(o.kind==="image")return [d.nodes.image.create({src:o.src,alt:o.drawingId,width:(r=o.width)!=null?r:null,height:(a=o.height)!=null?a:null,drawingId:o.drawingId})];if(o.text.length===0)return [];let l=o.kind==="text"?o.format:void 0;return [d.text(o.text,S(l))]}):t.text.length>0?d.text(t.text):void 0)}function B(t){return d.nodes.table.create({tableId:t.tableId,columnWidths:t.columnWidths},t.rows.map(n=>d.nodes.table_row.create(null,n.cells.filter(e=>e.vMerge!=="continue").map(e=>L(e)))))}function L(t){var e,o,l,i;let n=t.paragraphs.length>0?t.paragraphs.map(r=>$(r)):[d.nodes.paragraph.create(null)];return d.nodes.table_cell.create({colspan:Math.max(1,t.gridSpan),rowspan:Math.max(1,(e=t.rowSpan)!=null?e:1),width:(o=t.width)!=null?o:null,shading:(l=t.shading)!=null?l:null,verticalAlignment:(i=t.verticalAlignment)!=null?i:null},n)}function S(t){var e,o;if(!t)return;let n=[];return t.bold&&n.push(d.marks.strong.create()),t.italic&&n.push(d.marks.em.create()),t.underline&&n.push(d.marks.underline.create()),(t.color||t.fontSize)&&n.push(d.marks.textStyle.create({color:(e=t.color)!=null?e:null,fontSize:(o=t.fontSize)!=null?o:null})),n.length>0?n:void 0}function K(t){let n={};typeof t.paraId=="string"&&t.paraId.length>0&&(n["data-para-id"]=t.paraId),typeof t.story=="string"&&t.story.length>0&&(n["data-story"]=t.story),typeof t.styleId=="string"&&t.styleId.length>0&&(n["data-style-id"]=t.styleId);let e=Q(t.format)?t.format:null;(e==null?void 0:e.outlineLevel)!==void 0&&(n["data-outline-level"]=String(e.outlineLevel));let o=X(e);return o.length>0&&(n.style=o),n}function H(t){let n={};return typeof t.tableId=="string"&&t.tableId.length>0&&(n["data-table-id"]=t.tableId),n}function U(t){let n={};typeof t.colspan=="number"&&t.colspan>1&&(n.colspan=String(t.colspan)),typeof t.rowspan=="number"&&t.rowspan>1&&(n.rowspan=String(t.rowspan));let e=[];if(typeof t.width=="number"&&t.width>0&&e.push(`width: ${u(t.width)}`),G(t.shading)){let o=f(t.shading.fill);o&&e.push(`background-color: ${o}`);}return typeof t.verticalAlignment=="string"&&e.push(`vertical-align: ${t.verticalAlignment==="center"?"middle":t.verticalAlignment}`),e.length>0&&(n.style=e.join("; ")),n}function q(t){let n={src:typeof t.src=="string"?t.src:"",alt:typeof t.alt=="string"?t.alt:""};typeof t.drawingId=="string"&&(n["data-drawing-id"]=t.drawingId);let e=[];return typeof t.width=="number"&&t.width>0&&e.push(`width: ${t.width}px`),typeof t.height=="number"&&t.height>0&&e.push(`height: ${t.height}px`),e.length>0&&(n.style=e.join("; ")),n}function G(t){return t!==null&&typeof t=="object"}function J(t){let n=[],e=typeof t.color=="string"?f(t.color):null;return e&&n.push(`color: ${e}`),typeof t.fontSize=="number"&&n.push(`font-size: ${t.fontSize}pt`),n.length>0?{style:n.join("; ")}:{}}function Q(t){return t!==null&&typeof t=="object"}function X(t){var l,i,r,a,s,c,m,h,w;if(!t)return "";let n=[];t.alignment&&n.push(`text-align: ${Y(t.alignment)}`),((l=t.indent)==null?void 0:l.left)!==void 0&&n.push(`margin-left: ${u(t.indent.left)}`),((i=t.indent)==null?void 0:i.right)!==void 0&&n.push(`margin-right: ${u(t.indent.right)}`),((r=t.indent)==null?void 0:r.firstLine)!==void 0&&n.push(`text-indent: ${u(t.indent.firstLine)}`),((a=t.spacing)==null?void 0:a.before)!==void 0&&n.push(`margin-top: ${u(t.spacing.before)}`),((s=t.spacing)==null?void 0:s.after)!==void 0&&n.push(`margin-bottom: ${u(t.spacing.after)}`);let e=tt((c=t.spacing)==null?void 0:c.line,(m=t.spacing)==null?void 0:m.lineRule);e&&n.push(`line-height: ${e}`),t.fontSize!==void 0&&n.push(`font-size: ${t.fontSize}pt`),t.bold!==void 0&&n.push(`font-weight: ${t.bold?"700":"400"}`);let o=Z(t.borderBottom);return o&&(n.push(`border-bottom: ${o}`),n.push(`padding-bottom: ${(w=(h=t.borderBottom)==null?void 0:h.space)!=null?w:4}pt`)),n.join("; ")}function Y(t){return t==="both"||t==="distribute"?"justify":t}function Z(t){var l;if(!t||t.val==="none"||t.val==="nil")return null;let n=(l=f(t.color))!=null?l:"#000000",e=t.size!==void 0?Math.max(.75,t.size/8):.75,o=t.val==="double"?"double":"solid";return `${e}pt ${o} ${n}`}function tt(t,n){return t===void 0?null:n==="exact"||n==="atLeast"?u(t):String(t/240)}function u(t){return `${t/20}pt`}function f(t){return !t||t==="auto"?null:/^[0-9a-f]{6}$/i.test(t)?`#${t}`:null}function nt(t){return new Plugin({key:I,state:{init:()=>t,apply:(n,e)=>e.map(n.mapping,n.doc)},props:{decorations(n){return I.getState(n)}}})}function et(){return new Plugin({key:g,appendTransaction(t,n,e){if(!t.some(r=>r.docChanged)||t.some(r=>r.getMeta(g)))return null;let o=new Set,l=e.tr,i=false;return e.doc.descendants((r,a)=>{if(r.type!==d.nodes.paragraph)return true;let s=typeof r.attrs.paraId=="string"?r.attrs.paraId:"";if(s&&!o.has(s))return o.add(s),true;let c=ot(o);return o.add(c),l=l.setNodeMarkup(a,void 0,k(p({},r.attrs),{paraId:c})),i=true,true}),i?l.setMeta(g,{normalized:true}):null}})}function ot(t){let n="";do n=Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0");while(!n||t.has(n));return n}export{ut as createWordEditorState,W as projectWordViewToProseMirror,I as wordDecorationsKey,d as wordEditorSchema,g as wordStructureNormalizationKey};
|