@coco-vexel/coco-office-editor 1.0.4 → 1.0.6

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