@beyondwork/docx-react-component 1.0.11 → 1.0.13

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 (40) hide show
  1. package/README.md +8 -2
  2. package/package.json +35 -21
  3. package/src/api/public-types.ts +103 -1
  4. package/src/core/commands/formatting-commands.ts +742 -0
  5. package/src/core/commands/image-commands.ts +84 -2
  6. package/src/core/commands/structural-helpers.ts +309 -0
  7. package/src/core/commands/table-structure-commands.ts +721 -0
  8. package/src/core/commands/text-commands.ts +166 -1
  9. package/src/core/state/editor-state.ts +318 -9
  10. package/src/formats/xlsx/io/parse-sheet.ts +177 -7
  11. package/src/formats/xlsx/io/parse-styles.ts +2 -0
  12. package/src/formats/xlsx/io/xlsx-session.ts +18 -12
  13. package/src/formats/xlsx/model/sheet.ts +81 -1
  14. package/src/formats/xlsx/model/workbook.ts +10 -6
  15. package/src/io/docx-session.ts +392 -22
  16. package/src/io/export/export-session.ts +55 -0
  17. package/src/io/export/serialize-footnotes.ts +5 -20
  18. package/src/io/export/serialize-headers-footers.ts +5 -31
  19. package/src/io/export/serialize-main-document.ts +78 -5
  20. package/src/io/normalize/normalize-text.ts +90 -1
  21. package/src/io/ooxml/parse-footnotes.ts +68 -5
  22. package/src/io/ooxml/parse-headers-footers.ts +67 -9
  23. package/src/io/ooxml/parse-main-document.ts +169 -6
  24. package/src/io/opc/package-reader.ts +3 -3
  25. package/src/io/source-package-provenance.ts +241 -0
  26. package/src/model/canonical-document.ts +450 -2
  27. package/src/model/cds-1.0.0.ts +5 -2
  28. package/src/model/snapshot.ts +190 -19
  29. package/src/preservation/package-preservation.ts +0 -7
  30. package/src/runtime/document-runtime.ts +7 -1
  31. package/src/runtime/read-only-diagnostics-runtime.ts +1 -1
  32. package/src/runtime/surface-projection.ts +200 -17
  33. package/src/runtime/table-commands.ts +79 -0
  34. package/src/runtime/table-schema.ts +9 -0
  35. package/src/ui/WordReviewEditor.tsx +708 -16
  36. package/src/ui-tailwind/editor-surface/pm-schema.ts +121 -5
  37. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +73 -7
  38. package/src/ui-tailwind/editor-surface/search-plugin.ts +76 -16
  39. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +162 -14
  40. package/src/validation/compatibility-engine.ts +208 -0
@@ -11,6 +11,7 @@
11
11
 
12
12
  import type { Command as PMCommand, EditorState } from "prosemirror-state";
13
13
  import {
14
+ CellSelection,
14
15
  TableMap,
15
16
  addColumnAfter as pmAddColumnAfter,
16
17
  addColumnBefore as pmAddColumnBefore,
@@ -21,10 +22,13 @@ import {
21
22
  deleteTable,
22
23
  goToNextCell,
23
24
  mergeCells,
25
+ selectedRect,
26
+ selectionCell,
24
27
  splitCell,
25
28
  toggleHeaderCell,
26
29
  toggleHeaderColumn,
27
30
  toggleHeaderRow,
31
+ findTable,
28
32
  } from "prosemirror-tables";
29
33
 
30
34
  // prosemirror-tables does not export goToPreviousCell; replicate via direction -1.
@@ -33,6 +37,25 @@ const goToPreviousCell: PMCommand = (state, dispatch, view) =>
33
37
 
34
38
  export type { Command as TableCommand } from "prosemirror-state";
35
39
 
40
+ export interface TableSelectionDescriptor {
41
+ tableBlockIndex: number;
42
+ selectionKind: "text" | "cell";
43
+ anchorCell: {
44
+ rowIndex: number;
45
+ columnIndex: number;
46
+ };
47
+ headCell: {
48
+ rowIndex: number;
49
+ columnIndex: number;
50
+ };
51
+ rect: {
52
+ top: number;
53
+ left: number;
54
+ bottom: number;
55
+ right: number;
56
+ };
57
+ }
58
+
36
59
  function tableAtSelection(state: EditorState) {
37
60
  const { $head } = state.selection;
38
61
  for (let depth = $head.depth; depth > 0; depth -= 1) {
@@ -92,3 +115,59 @@ export {
92
115
  goToNextCell,
93
116
  goToPreviousCell,
94
117
  };
118
+
119
+ export function getTableSelectionDescriptor(
120
+ state: EditorState,
121
+ ): TableSelectionDescriptor | null {
122
+ const tableInfo = findTable(state.selection.$from);
123
+ if (!tableInfo) {
124
+ return null;
125
+ }
126
+
127
+ const tableBlockIndex = resolveTopLevelTableIndex(state, tableInfo.pos);
128
+ if (tableBlockIndex < 0) {
129
+ return null;
130
+ }
131
+
132
+ const rect = selectedRect(state);
133
+ const isCellSelection = state.selection instanceof CellSelection;
134
+ const anchorCellPos = (
135
+ isCellSelection ? (state.selection as CellSelection).$anchorCell : selectionCell(state)
136
+ ).pos - rect.tableStart;
137
+ const headCellPos = (
138
+ isCellSelection ? (state.selection as CellSelection).$headCell : selectionCell(state)
139
+ ).pos - rect.tableStart;
140
+ const anchorRect = rect.map.findCell(anchorCellPos);
141
+ const headRect = rect.map.findCell(headCellPos);
142
+
143
+ return {
144
+ tableBlockIndex,
145
+ selectionKind: isCellSelection ? "cell" : "text",
146
+ anchorCell: {
147
+ rowIndex: anchorRect.top,
148
+ columnIndex: anchorRect.left,
149
+ },
150
+ headCell: {
151
+ rowIndex: headRect.top,
152
+ columnIndex: headRect.left,
153
+ },
154
+ rect: {
155
+ top: rect.top,
156
+ left: rect.left,
157
+ bottom: rect.bottom,
158
+ right: rect.right,
159
+ },
160
+ };
161
+ }
162
+
163
+ function resolveTopLevelTableIndex(state: EditorState, tablePos: number): number {
164
+ let index = -1;
165
+
166
+ state.doc.forEach((node, offset, currentIndex) => {
167
+ if (offset === tablePos && node.type.spec.tableRole === "table") {
168
+ index = currentIndex;
169
+ }
170
+ });
171
+
172
+ return index;
173
+ }
@@ -17,6 +17,7 @@ type TableCellAttrs = {
17
17
  colwidth?: number[] | null;
18
18
  gridSpan?: number | null;
19
19
  verticalMerge?: "restart" | "continue" | null;
20
+ backgroundColor?: string | null;
20
21
  };
21
22
 
22
23
  function resolveRenderedColspan(attrs: {
@@ -52,6 +53,8 @@ function getCellAttrs(dom: HTMLElement): TableCellAttrs {
52
53
  const gridSpanAttr = dom.getAttribute("data-grid-span");
53
54
  const verticalMergeAttr = dom.getAttribute("data-vertical-merge");
54
55
  const gridSpan = gridSpanAttr ? Number.parseInt(gridSpanAttr, 10) : colspan;
56
+ const backgroundColor =
57
+ dom.getAttribute("data-cell-background") ?? dom.style.backgroundColor ?? null;
55
58
 
56
59
  return {
57
60
  colspan,
@@ -62,6 +65,7 @@ function getCellAttrs(dom: HTMLElement): TableCellAttrs {
62
65
  verticalMergeAttr === "restart" || verticalMergeAttr === "continue"
63
66
  ? verticalMergeAttr
64
67
  : null,
68
+ backgroundColor,
65
69
  };
66
70
  }
67
71
 
@@ -85,6 +89,10 @@ function setCellDomAttrs(nodeAttrs: TableCellAttrs, className: string): Record<s
85
89
  if (nodeAttrs.verticalMerge) {
86
90
  attrs["data-vertical-merge"] = nodeAttrs.verticalMerge;
87
91
  }
92
+ if (nodeAttrs.backgroundColor) {
93
+ attrs["data-cell-background"] = nodeAttrs.backgroundColor;
94
+ attrs.style = `background-color: ${nodeAttrs.backgroundColor}`;
95
+ }
88
96
 
89
97
  return attrs;
90
98
  }
@@ -117,6 +125,7 @@ const tableCellSpecAttrs = {
117
125
  colspan: { default: 1, validate: "number" },
118
126
  rowspan: { default: 1, validate: "number" },
119
127
  colwidth: { default: null, validate: validateColwidth },
128
+ backgroundColor: { default: null },
120
129
  } as const;
121
130
 
122
131
  export const tableNodeSpec: NodeSpec = {