@coco-vexel/coco-office-editor 0.0.0-stage → 1.0.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.
Files changed (57) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +510 -2
  3. package/THIRD_PARTY_NOTICES.md +212 -0
  4. package/dist/index.cjs +26401 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +12 -0
  7. package/dist/index.d.ts +12 -0
  8. package/dist/index.js +26192 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/model-DB6aN6uJ.d.cts +321 -0
  11. package/dist/model-DB6aN6uJ.d.ts +321 -0
  12. package/dist/native-B6B649CC.d.ts +1111 -0
  13. package/dist/native-Ct9nN06K.d.cts +1111 -0
  14. package/dist/ppt-native.cjs +5334 -0
  15. package/dist/ppt-native.cjs.map +1 -0
  16. package/dist/ppt-native.d.cts +2 -0
  17. package/dist/ppt-native.d.ts +2 -0
  18. package/dist/ppt-native.js +5332 -0
  19. package/dist/ppt-native.js.map +1 -0
  20. package/dist/ppt.cjs +5426 -0
  21. package/dist/ppt.cjs.map +1 -0
  22. package/dist/ppt.d.cts +306 -0
  23. package/dist/ppt.d.ts +306 -0
  24. package/dist/ppt.js +5410 -0
  25. package/dist/ppt.js.map +1 -0
  26. package/dist/spreadsheet.cjs +4276 -0
  27. package/dist/spreadsheet.cjs.map +1 -0
  28. package/dist/spreadsheet.d.cts +676 -0
  29. package/dist/spreadsheet.d.ts +676 -0
  30. package/dist/spreadsheet.js +4213 -0
  31. package/dist/spreadsheet.js.map +1 -0
  32. package/dist/word-editing.cjs +812 -0
  33. package/dist/word-editing.cjs.map +1 -0
  34. package/dist/word-editing.d.cts +149 -0
  35. package/dist/word-editing.d.ts +149 -0
  36. package/dist/word-editing.js +803 -0
  37. package/dist/word-editing.js.map +1 -0
  38. package/dist/word-native.cjs +13400 -0
  39. package/dist/word-native.cjs.map +1 -0
  40. package/dist/word-native.d.cts +4 -0
  41. package/dist/word-native.d.ts +4 -0
  42. package/dist/word-native.js +13293 -0
  43. package/dist/word-native.js.map +1 -0
  44. package/dist/word-prosemirror.cjs +489 -0
  45. package/dist/word-prosemirror.cjs.map +1 -0
  46. package/dist/word-prosemirror.d.cts +21 -0
  47. package/dist/word-prosemirror.d.ts +21 -0
  48. package/dist/word-prosemirror.js +483 -0
  49. package/dist/word-prosemirror.js.map +1 -0
  50. package/dist/word.cjs +16764 -0
  51. package/dist/word.cjs.map +1 -0
  52. package/dist/word.d.cts +84 -0
  53. package/dist/word.d.ts +84 -0
  54. package/dist/word.js +16632 -0
  55. package/dist/word.js.map +1 -0
  56. package/package.json +106 -3
  57. package/src/styles/editor.css +1507 -0
@@ -0,0 +1,483 @@
1
+ import { Schema } from 'prosemirror-model';
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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/word/prosemirror.ts"],"names":["_a","_b","tr"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,IAAM,gBAAA,GAAmB,IAAI,MAAA,CAAO;AAAA,EACzC,KAAA,EAAO;AAAA,IACL,GAAA,EAAK,EAAE,OAAA,EAAS,QAAA,EAAS;AAAA,IACzB,SAAA,EAAW;AAAA,MACT,KAAA,EAAO,OAAA;AAAA,MACP,OAAA,EAAS,SAAA;AAAA,MACT,KAAA,EAAO;AAAA,QACL,MAAA,EAAQ,EAAE,OAAA,EAAS,EAAA,EAAG;AAAA,QACtB,KAAA,EAAO,EAAE,OAAA,EAAS,MAAA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AAM,CAAA;AACnC,EAAA,OAAO,MAAA;AACT;AATS,MAAA,CAAA,gBAAA,EAAA,kBAAA,CAAA","file":"word-prosemirror.js","sourcesContent":["import { Schema, type Node as ProseMirrorNode } from 'prosemirror-model';\nimport { baseKeymap } from 'prosemirror-commands';\nimport { keymap } from 'prosemirror-keymap';\nimport { EditorState, Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport type {\n EditorBlockView,\n EditorDocumentView,\n EditorParagraphFormat,\n EditorParagraphView,\n EditorRunFormat,\n EditorTableCellView,\n EditorTableView,\n} from './model.js';\n\nexport interface WordProjection {\n doc: ProseMirrorNode;\n decorations: DecorationSet;\n paragraphContentPos: Map<string, number>;\n}\n\nexport interface CreateWordEditorStateOptions {\n plugins?: Plugin[];\n}\n\nexport const wordEditorSchema = new Schema({\n nodes: {\n doc: { content: 'block+' },\n paragraph: {\n group: 'block',\n content: 'inline*',\n attrs: {\n paraId: { default: '' },\n story: { default: 'body' },\n styleId: { default: null },\n format: { default: null },\n },\n parseDOM: [{ tag: 'p' }],\n toDOM: (node) => ['p', paragraphDomAttrs(node.attrs), 0],\n },\n table: {\n group: 'block',\n content: 'table_row+',\n attrs: {\n tableId: { default: '' },\n columnWidths: { default: null },\n },\n tableRole: 'table',\n toDOM: (node) => [\n 'div',\n { class: 'coco-word-table-scroll' },\n ['table', tableDomAttrs(node.attrs), ['tbody', 0]],\n ],\n },\n table_row: {\n content: 'table_cell+',\n tableRole: 'row',\n toDOM: () => ['tr', 0],\n },\n table_cell: {\n content: 'block+',\n attrs: {\n colspan: { default: 1 },\n rowspan: { default: 1 },\n width: { default: null },\n shading: { default: null },\n verticalAlignment: { default: null },\n },\n tableRole: 'cell',\n toDOM: (node) => ['td', tableCellDomAttrs(node.attrs), 0],\n },\n image: {\n inline: true,\n group: 'inline',\n atom: true,\n attrs: {\n src: {},\n alt: { default: '' },\n width: { default: null },\n height: { default: null },\n drawingId: { default: null },\n },\n toDOM: (node) => ['img', imageDomAttrs(node.attrs)],\n },\n text: { group: 'inline' },\n },\n marks: {\n strong: {\n parseDOM: [{ tag: 'strong' }, { tag: 'b' }],\n toDOM: () => ['strong', 0],\n },\n em: {\n parseDOM: [{ tag: 'em' }, { tag: 'i' }],\n toDOM: () => ['em', 0],\n },\n underline: {\n parseDOM: [{ tag: 'u' }],\n toDOM: () => ['u', 0],\n },\n textStyle: {\n attrs: {\n color: { default: null },\n fontSize: { default: null },\n },\n parseDOM: [{ tag: 'span' }],\n toDOM: (mark) => ['span', textStyleDomAttrs(mark.attrs), 0],\n },\n },\n});\n\nexport const wordDecorationsKey = new PluginKey<DecorationSet>('coco-word-decorations');\nexport const wordStructureNormalizationKey = new PluginKey('coco-word-structure-normalization');\n\nexport function createWordEditorState(\n view: EditorDocumentView,\n options: CreateWordEditorStateOptions = {},\n): EditorState {\n const projection = projectWordViewToProseMirror(view);\n return EditorState.create({\n schema: wordEditorSchema,\n doc: projection.doc,\n plugins: [\n createWordDecorationsPlugin(projection.decorations),\n keymap(baseKeymap),\n createWordStructureNormalizationPlugin(),\n ...(options.plugins ?? []),\n ],\n });\n}\n\nexport function projectWordViewToProseMirror(view: EditorDocumentView): WordProjection {\n const paragraphContentPos = new Map<string, number>();\n const blocks = view.blocks.map((block) => blockToNode(block));\n const doc = wordEditorSchema.nodes.doc.create(null, blocks);\n\n doc.descendants((node, pos) => {\n if (node.type === wordEditorSchema.nodes.paragraph && typeof node.attrs.paraId === 'string') {\n paragraphContentPos.set(node.attrs.paraId, pos + 1);\n }\n });\n\n const decorations: Decoration[] = [];\n for (const paragraph of view.paragraphs) {\n const base = paragraphContentPos.get(paragraph.paraId)!;\n for (const span of paragraph.spans) {\n if (span.to <= span.from) {\n if (span.kind === 'comment') {\n decorations.push(createCommentWidget(base + span.from, span));\n }\n continue;\n }\n const className =\n span.kind === 'comment'\n ? 'coco-word-comment'\n : span.revisionKind === 'delete'\n ? 'coco-word-revision-delete'\n : 'coco-word-revision-insert';\n decorations.push(\n Decoration.inline(\n base + span.from,\n base + span.to,\n {\n class: className,\n ...(span.kind === 'comment' ? commentDomAttrs(span) : {}),\n },\n {\n id: span.id,\n kind: span.kind,\n paraId: paragraph.paraId,\n },\n ),\n );\n }\n }\n\n return {\n doc,\n decorations: DecorationSet.create(doc, decorations),\n paragraphContentPos,\n };\n}\n\nfunction createCommentWidget(pos: number, span: { id: string; commentId: number; body: string }) {\n return Decoration.widget(\n pos,\n () => {\n const marker = document.createElement('span');\n marker.className = 'coco-word-comment-widget';\n marker.dataset.commentId = String(span.commentId);\n marker.title = commentTitle(span);\n marker.textContent = '!';\n return marker;\n },\n {\n id: span.id,\n kind: 'comment',\n side: 1,\n },\n );\n}\n\nfunction commentDomAttrs(span: { commentId: number; body: string }): Record<string, string> {\n return {\n 'data-comment-id': String(span.commentId),\n title: commentTitle(span),\n };\n}\n\nfunction commentTitle(span: { commentId: number; body: string }): string {\n const body = span.body.trim();\n return body.length > 0 ? `Comment ${span.commentId}: ${body}` : `Comment ${span.commentId}`;\n}\n\nfunction blockToNode(block: EditorBlockView): ProseMirrorNode {\n return block.type === 'table' ? tableToNode(block) : paragraphToNode(block);\n}\n\nfunction paragraphToNode(paragraph: EditorParagraphView): ProseMirrorNode {\n return wordEditorSchema.nodes.paragraph.create(\n {\n paraId: paragraph.paraId,\n story: paragraph.story,\n styleId: paragraph.styleId ?? null,\n format: paragraph.format ?? null,\n },\n paragraph.segments.length > 0 ? paragraph.segments.flatMap((segment) => {\n if (segment.kind === 'placeholder') {\n return [wordEditorSchema.text('\\uFFFC')];\n }\n if (segment.kind === 'drawing') {\n return [wordEditorSchema.text(segment.text && segment.text.length > 0 ? segment.text : '\\uFFFC')];\n }\n if (segment.kind === 'field') {\n return [wordEditorSchema.text(segment.cachedText ?? '\\uFFFC', marksForRunFormat(segment.format))];\n }\n if (segment.kind === 'image') {\n return [\n wordEditorSchema.nodes.image.create({\n src: segment.src,\n alt: segment.drawingId,\n width: segment.width ?? null,\n height: segment.height ?? null,\n drawingId: segment.drawingId,\n }),\n ];\n }\n if (segment.text.length === 0) return [];\n const format = segment.kind === 'text' ? segment.format : undefined;\n return [wordEditorSchema.text(segment.text, marksForRunFormat(format))];\n }) : paragraph.text.length > 0 ? wordEditorSchema.text(paragraph.text) : undefined,\n );\n}\n\nfunction tableToNode(table: EditorTableView): ProseMirrorNode {\n return wordEditorSchema.nodes.table.create(\n { tableId: table.tableId, columnWidths: table.columnWidths },\n table.rows.map((row) =>\n wordEditorSchema.nodes.table_row.create(\n null,\n row.cells\n .filter((cell) => cell.vMerge !== 'continue')\n .map((cell) => tableCellToNode(cell)),\n ),\n ),\n );\n}\n\nfunction tableCellToNode(cell: EditorTableCellView): ProseMirrorNode {\n const paragraphs =\n cell.paragraphs.length > 0\n ? cell.paragraphs.map((paragraph) => paragraphToNode(paragraph))\n : [wordEditorSchema.nodes.paragraph.create(null)];\n return wordEditorSchema.nodes.table_cell.create(\n {\n colspan: Math.max(1, cell.gridSpan),\n rowspan: Math.max(1, cell.rowSpan ?? 1),\n width: cell.width ?? null,\n shading: cell.shading ?? null,\n verticalAlignment: cell.verticalAlignment ?? null,\n },\n paragraphs,\n );\n}\n\nfunction marksForRunFormat(format: EditorRunFormat | undefined) {\n if (!format) return undefined;\n const marks = [];\n if (format.bold) marks.push(wordEditorSchema.marks.strong.create());\n if (format.italic) marks.push(wordEditorSchema.marks.em.create());\n if (format.underline) marks.push(wordEditorSchema.marks.underline.create());\n if (format.color || format.fontSize) {\n marks.push(\n wordEditorSchema.marks.textStyle.create({\n color: format.color ?? null,\n fontSize: format.fontSize ?? null,\n }),\n );\n }\n return marks.length > 0 ? marks : undefined;\n}\n\nfunction paragraphDomAttrs(attrs: {\n paraId?: unknown;\n story?: unknown;\n styleId?: unknown;\n format?: unknown;\n}): Record<string, string> {\n const domAttrs: Record<string, string> = {};\n if (typeof attrs.paraId === 'string' && attrs.paraId.length > 0) {\n domAttrs['data-para-id'] = attrs.paraId;\n }\n if (typeof attrs.story === 'string' && attrs.story.length > 0) {\n domAttrs['data-story'] = attrs.story;\n }\n if (typeof attrs.styleId === 'string' && attrs.styleId.length > 0) {\n domAttrs['data-style-id'] = attrs.styleId;\n }\n\n const format = isParagraphFormat(attrs.format) ? attrs.format : null;\n if (format?.outlineLevel !== undefined) {\n domAttrs['data-outline-level'] = String(format.outlineLevel);\n }\n\n const style = paragraphStyle(format);\n if (style.length > 0) domAttrs.style = style;\n return domAttrs;\n}\n\nfunction tableDomAttrs(attrs: { tableId?: unknown; columnWidths?: unknown }): Record<string, string> {\n const domAttrs: Record<string, string> = {};\n if (typeof attrs.tableId === 'string' && attrs.tableId.length > 0) {\n domAttrs['data-table-id'] = attrs.tableId;\n }\n return domAttrs;\n}\n\nfunction tableCellDomAttrs(attrs: {\n colspan?: unknown;\n rowspan?: unknown;\n width?: unknown;\n shading?: unknown;\n verticalAlignment?: unknown;\n}): Record<string, string> {\n const domAttrs: Record<string, string> = {};\n if (typeof attrs.colspan === 'number' && attrs.colspan > 1) {\n domAttrs.colspan = String(attrs.colspan);\n }\n if (typeof attrs.rowspan === 'number' && attrs.rowspan > 1) {\n domAttrs.rowspan = String(attrs.rowspan);\n }\n const style: string[] = [];\n if (typeof attrs.width === 'number' && attrs.width > 0) {\n style.push(`width: ${twipsToPt(attrs.width)}`);\n }\n if (isShading(attrs.shading)) {\n const fill = colorToCss(attrs.shading.fill);\n if (fill) style.push(`background-color: ${fill}`);\n }\n if (typeof attrs.verticalAlignment === 'string') {\n style.push(`vertical-align: ${attrs.verticalAlignment === 'center' ? 'middle' : attrs.verticalAlignment}`);\n }\n if (style.length > 0) domAttrs.style = style.join('; ');\n return domAttrs;\n}\n\nfunction imageDomAttrs(attrs: {\n src?: unknown;\n alt?: unknown;\n width?: unknown;\n height?: unknown;\n drawingId?: unknown;\n}): Record<string, string> {\n const domAttrs: Record<string, string> = {\n src: typeof attrs.src === 'string' ? attrs.src : '',\n alt: typeof attrs.alt === 'string' ? attrs.alt : '',\n };\n if (typeof attrs.drawingId === 'string') domAttrs['data-drawing-id'] = attrs.drawingId;\n const style: string[] = [];\n if (typeof attrs.width === 'number' && attrs.width > 0) {\n style.push(`width: ${attrs.width}px`);\n }\n if (typeof attrs.height === 'number' && attrs.height > 0) {\n style.push(`height: ${attrs.height}px`);\n }\n if (style.length > 0) domAttrs.style = style.join('; ');\n return domAttrs;\n}\n\nfunction isShading(value: unknown): value is { fill?: string } {\n return value !== null && typeof value === 'object';\n}\n\nfunction textStyleDomAttrs(attrs: { color?: unknown; fontSize?: unknown }): Record<string, string> {\n const style: string[] = [];\n const color = typeof attrs.color === 'string' ? colorToCss(attrs.color) : null;\n if (color) style.push(`color: ${color}`);\n if (typeof attrs.fontSize === 'number') style.push(`font-size: ${attrs.fontSize}pt`);\n return style.length > 0 ? { style: style.join('; ') } : {};\n}\n\nfunction isParagraphFormat(value: unknown): value is EditorParagraphFormat {\n return value !== null && typeof value === 'object';\n}\n\nfunction paragraphStyle(format: EditorParagraphFormat | null): string {\n if (!format) return '';\n const declarations: string[] = [];\n\n if (format.alignment) declarations.push(`text-align: ${alignmentToCss(format.alignment)}`);\n if (format.indent?.left !== undefined) declarations.push(`margin-left: ${twipsToPt(format.indent.left)}`);\n if (format.indent?.right !== undefined) declarations.push(`margin-right: ${twipsToPt(format.indent.right)}`);\n if (format.indent?.firstLine !== undefined) {\n declarations.push(`text-indent: ${twipsToPt(format.indent.firstLine)}`);\n }\n if (format.spacing?.before !== undefined) {\n declarations.push(`margin-top: ${twipsToPt(format.spacing.before)}`);\n }\n if (format.spacing?.after !== undefined) {\n declarations.push(`margin-bottom: ${twipsToPt(format.spacing.after)}`);\n }\n const lineHeight = lineHeightToCss(format.spacing?.line, format.spacing?.lineRule);\n if (lineHeight) declarations.push(`line-height: ${lineHeight}`);\n if (format.fontSize !== undefined) declarations.push(`font-size: ${format.fontSize}pt`);\n if (format.bold !== undefined) declarations.push(`font-weight: ${format.bold ? '700' : '400'}`);\n const borderBottom = borderToCss(format.borderBottom);\n if (borderBottom) {\n declarations.push(`border-bottom: ${borderBottom}`);\n declarations.push(`padding-bottom: ${format.borderBottom?.space ?? 4}pt`);\n }\n\n return declarations.join('; ');\n}\n\nfunction alignmentToCss(alignment: NonNullable<EditorParagraphFormat['alignment']>): string {\n if (alignment === 'both' || alignment === 'distribute') return 'justify';\n return alignment;\n}\n\nfunction borderToCss(border: EditorParagraphFormat['borderBottom']): string | null {\n if (!border || border.val === 'none' || border.val === 'nil') return null;\n const color = colorToCss(border.color) ?? '#000000';\n const widthPt = border.size !== undefined ? Math.max(0.75, border.size / 8) : 0.75;\n const style = border.val === 'double' ? 'double' : 'solid';\n return `${widthPt}pt ${style} ${color}`;\n}\n\nfunction lineHeightToCss(\n line: number | undefined,\n lineRule: 'auto' | 'exact' | 'atLeast' | undefined,\n): string | null {\n if (line === undefined) return null;\n if (lineRule === 'exact' || lineRule === 'atLeast') return twipsToPt(line);\n return String(line / 240);\n}\n\nfunction twipsToPt(twips: number): string {\n return `${twips / 20}pt`;\n}\n\nfunction colorToCss(color: string | undefined): string | null {\n if (!color || color === 'auto') return null;\n return /^[0-9a-f]{6}$/i.test(color) ? `#${color}` : null;\n}\n\nfunction createWordDecorationsPlugin(decorations: DecorationSet): Plugin {\n return new Plugin({\n key: wordDecorationsKey,\n state: {\n init: () => decorations,\n apply: (tr, set) => set.map(tr.mapping, tr.doc),\n },\n props: {\n decorations(state) {\n return wordDecorationsKey.getState(state);\n },\n },\n });\n}\n\nfunction createWordStructureNormalizationPlugin(): Plugin {\n return new Plugin({\n key: wordStructureNormalizationKey,\n appendTransaction(transactions, _oldState, newState) {\n if (!transactions.some((tr) => tr.docChanged)) return null;\n if (transactions.some((tr) => tr.getMeta(wordStructureNormalizationKey))) return null;\n\n const seen = new Set<string>();\n let tr = newState.tr;\n let changed = false;\n newState.doc.descendants((node, pos) => {\n if (node.type !== wordEditorSchema.nodes.paragraph) return true;\n const paraId = typeof node.attrs.paraId === 'string' ? node.attrs.paraId : '';\n if (paraId && !seen.has(paraId)) {\n seen.add(paraId);\n return true;\n }\n\n const nextParaId = nextUniqueParaId(seen);\n seen.add(nextParaId);\n tr = tr.setNodeMarkup(pos, undefined, { ...node.attrs, paraId: nextParaId });\n changed = true;\n return true;\n });\n\n return changed ? tr.setMeta(wordStructureNormalizationKey, { normalized: true }) : null;\n },\n });\n}\n\nfunction nextUniqueParaId(seen: Set<string>): string {\n let paraId = '';\n do {\n paraId = Math.floor(Math.random() * 0xffffffff)\n .toString(16)\n .toUpperCase()\n .padStart(8, '0');\n } while (!paraId || seen.has(paraId));\n return paraId;\n}\n"]}