@beyondwork/docx-react-component 1.0.12 → 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.
- package/package.json +42 -23
- package/src/api/public-types.ts +72 -0
- package/src/core/commands/formatting-commands.ts +742 -0
- package/src/core/commands/image-commands.ts +84 -2
- package/src/core/commands/structural-helpers.ts +309 -0
- package/src/core/commands/table-structure-commands.ts +721 -0
- package/src/core/commands/text-commands.ts +166 -1
- package/src/formats/xlsx/io/parse-sheet.ts +177 -7
- package/src/formats/xlsx/io/parse-styles.ts +2 -0
- package/src/formats/xlsx/io/xlsx-session.ts +18 -12
- package/src/formats/xlsx/model/sheet.ts +81 -1
- package/src/formats/xlsx/model/workbook.ts +10 -6
- package/src/runtime/surface-projection.ts +1 -0
- package/src/runtime/table-commands.ts +79 -0
- package/src/runtime/table-schema.ts +9 -0
- package/src/ui/WordReviewEditor.tsx +519 -2
- package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +7 -5
- package/src/ui-tailwind/editor-surface/search-plugin.ts +76 -16
- package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +162 -14
|
@@ -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 = {
|