@portone/docx-editor 0.1.0
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/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +63 -0
- package/LICENSE +203 -0
- package/README.md +48 -0
- package/assets/editor.png +0 -0
- package/dist/DocxEditor.d.ts +123 -0
- package/dist/DocxEditor.js +348 -0
- package/dist/core.d.ts +36 -0
- package/dist/core.js +38 -0
- package/dist/docx/comments/constants.d.ts +8 -0
- package/dist/docx/comments/constants.js +20 -0
- package/dist/docx/comments/model.d.ts +37 -0
- package/dist/docx/comments/model.js +104 -0
- package/dist/docx/comments/reading.d.ts +36 -0
- package/dist/docx/comments/reading.js +149 -0
- package/dist/docx/comments/writing.d.ts +11 -0
- package/dist/docx/comments/writing.js +327 -0
- package/dist/docx/comments.d.ts +3 -0
- package/dist/docx/comments.js +4 -0
- package/dist/docx/container.d.ts +12 -0
- package/dist/docx/container.js +130 -0
- package/dist/docx/documentSettings.d.ts +4 -0
- package/dist/docx/documentSettings.js +14 -0
- package/dist/docx/exportDocx.d.ts +15 -0
- package/dist/docx/exportDocx.js +163 -0
- package/dist/docx/exportRefs.d.ts +16 -0
- package/dist/docx/exportRefs.js +10 -0
- package/dist/docx/formatting/direct.d.ts +30 -0
- package/dist/docx/formatting/direct.js +201 -0
- package/dist/docx/formatting/effectiveParagraph.d.ts +15 -0
- package/dist/docx/formatting/effectiveParagraph.js +81 -0
- package/dist/docx/formatting/styles.d.ts +67 -0
- package/dist/docx/formatting/styles.js +165 -0
- package/dist/docx/formatting/tabStops.d.ts +8 -0
- package/dist/docx/formatting/tabStops.js +65 -0
- package/dist/docx/formatting.d.ts +4 -0
- package/dist/docx/formatting.js +4 -0
- package/dist/docx/headersFooters.d.ts +36 -0
- package/dist/docx/headersFooters.js +218 -0
- package/dist/docx/hyperlink.d.ts +75 -0
- package/dist/docx/hyperlink.js +71 -0
- package/dist/docx/importDocx.d.ts +21 -0
- package/dist/docx/importDocx.js +263 -0
- package/dist/docx/importParagraph.d.ts +32 -0
- package/dist/docx/importParagraph.js +308 -0
- package/dist/docx/importTable.d.ts +9 -0
- package/dist/docx/importTable.js +275 -0
- package/dist/docx/media.d.ts +60 -0
- package/dist/docx/media.js +213 -0
- package/dist/docx/notes.d.ts +22 -0
- package/dist/docx/notes.js +71 -0
- package/dist/docx/pageGeometry.d.ts +75 -0
- package/dist/docx/pageGeometry.js +88 -0
- package/dist/docx/paraProps.d.ts +74 -0
- package/dist/docx/paraProps.js +167 -0
- package/dist/docx/propsXml.d.ts +49 -0
- package/dist/docx/propsXml.js +302 -0
- package/dist/docx/relationships.d.ts +42 -0
- package/dist/docx/relationships.js +94 -0
- package/dist/docx/runProps.d.ts +51 -0
- package/dist/docx/runProps.js +207 -0
- package/dist/docx/scan.d.ts +20 -0
- package/dist/docx/scan.js +110 -0
- package/dist/docx/sdt.d.ts +56 -0
- package/dist/docx/sdt.js +104 -0
- package/dist/docx/sdtProps.d.ts +18 -0
- package/dist/docx/sdtProps.js +11 -0
- package/dist/docx/serializeBlock.d.ts +4 -0
- package/dist/docx/serializeBlock.js +30 -0
- package/dist/docx/serializeParagraph.d.ts +15 -0
- package/dist/docx/serializeParagraph.js +208 -0
- package/dist/docx/serializeTable.d.ts +12 -0
- package/dist/docx/serializeTable.js +134 -0
- package/dist/docx/session.d.ts +81 -0
- package/dist/docx/session.js +79 -0
- package/dist/docx/tableFormatting/editing.d.ts +64 -0
- package/dist/docx/tableFormatting/editing.js +318 -0
- package/dist/docx/tableFormatting/reading.d.ts +96 -0
- package/dist/docx/tableFormatting/reading.js +221 -0
- package/dist/docx/tableFormatting.d.ts +2 -0
- package/dist/docx/tableFormatting.js +3 -0
- package/dist/docx/tableTemplate.d.ts +22 -0
- package/dist/docx/tableTemplate.js +111 -0
- package/dist/docx/theme.d.ts +40 -0
- package/dist/docx/theme.js +61 -0
- package/dist/docx/uniqueControls.d.ts +14 -0
- package/dist/docx/uniqueControls.js +62 -0
- package/dist/download.d.ts +57 -0
- package/dist/download.js +44 -0
- package/dist/editor/clipboard/images.d.ts +14 -0
- package/dist/editor/clipboard/images.js +158 -0
- package/dist/editor/clipboard/inlineFormatting.d.ts +21 -0
- package/dist/editor/clipboard/inlineFormatting.js +232 -0
- package/dist/editor/commands/breakCommands.d.ts +8 -0
- package/dist/editor/commands/breakCommands.js +19 -0
- package/dist/editor/commands/canRunCommand.d.ts +6 -0
- package/dist/editor/commands/canRunCommand.js +10 -0
- package/dist/editor/commands/commentCommands.d.ts +3 -0
- package/dist/editor/commands/commentCommands.js +4 -0
- package/dist/editor/commands/comments/editing.d.ts +21 -0
- package/dist/editor/commands/comments/editing.js +305 -0
- package/dist/editor/commands/comments/model.d.ts +31 -0
- package/dist/editor/commands/comments/model.js +0 -0
- package/dist/editor/commands/comments/reading.d.ts +8 -0
- package/dist/editor/commands/comments/reading.js +58 -0
- package/dist/editor/commands/formatting/editing.d.ts +32 -0
- package/dist/editor/commands/formatting/editing.js +138 -0
- package/dist/editor/commands/formatting/reading.d.ts +57 -0
- package/dist/editor/commands/formatting/reading.js +82 -0
- package/dist/editor/commands/formatting/shared.d.ts +32 -0
- package/dist/editor/commands/formatting/shared.js +53 -0
- package/dist/editor/commands/formattingCommands.d.ts +2 -0
- package/dist/editor/commands/formattingCommands.js +3 -0
- package/dist/editor/commands/historyCommands.d.ts +11 -0
- package/dist/editor/commands/historyCommands.js +16 -0
- package/dist/editor/commands/indentCommands.d.ts +15 -0
- package/dist/editor/commands/indentCommands.js +44 -0
- package/dist/editor/commands/index.d.ts +82 -0
- package/dist/editor/commands/index.js +171 -0
- package/dist/editor/commands/linkCommands.d.ts +56 -0
- package/dist/editor/commands/linkCommands.js +146 -0
- package/dist/editor/commands/listCommands.d.ts +58 -0
- package/dist/editor/commands/listCommands.js +140 -0
- package/dist/editor/commands/lockCommands.d.ts +47 -0
- package/dist/editor/commands/lockCommands.js +198 -0
- package/dist/editor/commands/noteQueries.d.ts +12 -0
- package/dist/editor/commands/noteQueries.js +29 -0
- package/dist/editor/commands/paragraphCommands.d.ts +59 -0
- package/dist/editor/commands/paragraphCommands.js +113 -0
- package/dist/editor/commands/spacingCommands.d.ts +23 -0
- package/dist/editor/commands/spacingCommands.js +48 -0
- package/dist/editor/commands/tabCommands.d.ts +5 -0
- package/dist/editor/commands/tabCommands.js +65 -0
- package/dist/editor/createEditor.d.ts +59 -0
- package/dist/editor/createEditor.js +160 -0
- package/dist/editor/documentStyles.d.ts +60 -0
- package/dist/editor/documentStyles.js +80 -0
- package/dist/editor/externalClipboard.d.ts +11 -0
- package/dist/editor/externalClipboard.js +323 -0
- package/dist/editor/imageFiles.d.ts +74 -0
- package/dist/editor/imageFiles.js +173 -0
- package/dist/editor/insertImage.d.ts +31 -0
- package/dist/editor/insertImage.js +35 -0
- package/dist/editor/insertTable.d.ts +18 -0
- package/dist/editor/insertTable.js +44 -0
- package/dist/editor/paragraphEdits.d.ts +42 -0
- package/dist/editor/paragraphEdits.js +59 -0
- package/dist/editor/plainText.d.ts +3 -0
- package/dist/editor/plainText.js +50 -0
- package/dist/editor/plugins/bookmarkProtection.d.ts +3 -0
- package/dist/editor/plugins/bookmarkProtection.js +28 -0
- package/dist/editor/plugins/columnResize.d.ts +27 -0
- package/dist/editor/plugins/columnResize.js +192 -0
- package/dist/editor/plugins/commentDecorations.d.ts +3 -0
- package/dist/editor/plugins/commentDecorations.js +23 -0
- package/dist/editor/plugins/commentReservations.d.ts +5 -0
- package/dist/editor/plugins/commentReservations.js +26 -0
- package/dist/editor/plugins/dropCaret.d.ts +10 -0
- package/dist/editor/plugins/dropCaret.js +11 -0
- package/dist/editor/plugins/imagePaste.d.ts +8 -0
- package/dist/editor/plugins/imagePaste.js +265 -0
- package/dist/editor/plugins/keymap.d.ts +5 -0
- package/dist/editor/plugins/keymap.js +94 -0
- package/dist/editor/plugins/linkPanel.d.ts +23 -0
- package/dist/editor/plugins/linkPanel.js +39 -0
- package/dist/editor/plugins/listInputRules.d.ts +14 -0
- package/dist/editor/plugins/listInputRules.js +36 -0
- package/dist/editor/plugins/lockedContent.d.ts +6 -0
- package/dist/editor/plugins/lockedContent.js +41 -0
- package/dist/editor/plugins/noteProtection.d.ts +3 -0
- package/dist/editor/plugins/noteProtection.js +25 -0
- package/dist/editor/plugins/numberingDecorations.d.ts +42 -0
- package/dist/editor/plugins/numberingDecorations.js +110 -0
- package/dist/editor/plugins/rowResize.d.ts +15 -0
- package/dist/editor/plugins/rowResize.js +196 -0
- package/dist/editor/plugins/styledParagraphs.d.ts +15 -0
- package/dist/editor/plugins/styledParagraphs.js +65 -0
- package/dist/editor/plugins/tabCaret.d.ts +3 -0
- package/dist/editor/plugins/tabCaret.js +126 -0
- package/dist/editor/plugins/tabDecorations.d.ts +11 -0
- package/dist/editor/plugins/tabDecorations.js +87 -0
- package/dist/editor/plugins/tabLayout.d.ts +16 -0
- package/dist/editor/plugins/tabLayout.js +328 -0
- package/dist/editor/plugins/tabPointer.d.ts +7 -0
- package/dist/editor/plugins/tabPointer.js +95 -0
- package/dist/editor/plugins/tableContextMenu.d.ts +21 -0
- package/dist/editor/plugins/tableContextMenu.js +88 -0
- package/dist/editor/plugins/textContextMenu.d.ts +15 -0
- package/dist/editor/plugins/textContextMenu.js +90 -0
- package/dist/editor/views/imageResize.d.ts +53 -0
- package/dist/editor/views/imageResize.js +167 -0
- package/dist/editor/views/runMarkView.d.ts +15 -0
- package/dist/editor/views/runMarkView.js +9 -0
- package/dist/editor/views/tableView.d.ts +24 -0
- package/dist/editor/views/tableView.js +32 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +38 -0
- package/dist/model/format.d.ts +240 -0
- package/dist/model/format.js +305 -0
- package/dist/model/tabStops.d.ts +17 -0
- package/dist/model/tabStops.js +22 -0
- package/dist/numbering/listTemplate.d.ts +29 -0
- package/dist/numbering/listTemplate.js +83 -0
- package/dist/numbering/markers.d.ts +24 -0
- package/dist/numbering/markers.js +93 -0
- package/dist/numbering/parseNumbering.d.ts +65 -0
- package/dist/numbering/parseNumbering.js +116 -0
- package/dist/numbering/writeNumbering.d.ts +13 -0
- package/dist/numbering/writeNumbering.js +49 -0
- package/dist/ooxml/errors.d.ts +39 -0
- package/dist/ooxml/errors.js +21 -0
- package/dist/ooxml/image.d.ts +88 -0
- package/dist/ooxml/image.js +106 -0
- package/dist/ooxml/tabStops.d.ts +3 -0
- package/dist/ooxml/tabStops.js +51 -0
- package/dist/ooxml/units.d.ts +37 -0
- package/dist/ooxml/units.js +116 -0
- package/dist/ooxml/xml.d.ts +36 -0
- package/dist/ooxml/xml.js +89 -0
- package/dist/page/PageGuides.d.ts +16 -0
- package/dist/page/PageGuides.js +114 -0
- package/dist/page/measureBlocks.d.ts +25 -0
- package/dist/page/measureBlocks.js +80 -0
- package/dist/page/pageDecorations.d.ts +36 -0
- package/dist/page/pageDecorations.js +211 -0
- package/dist/page/pageLayout.d.ts +176 -0
- package/dist/page/pageLayout.js +157 -0
- package/dist/page/tableMeasurements.d.ts +10 -0
- package/dist/page/tableMeasurements.js +115 -0
- package/dist/page/usePageLayout.d.ts +57 -0
- package/dist/page/usePageLayout.js +141 -0
- package/dist/schema/docxSchema.d.ts +9 -0
- package/dist/schema/docxSchema.js +863 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +9 -0
- package/dist/schema/locks.d.ts +112 -0
- package/dist/schema/locks.js +211 -0
- package/dist/schema/rendering.d.ts +6 -0
- package/dist/schema/rendering.js +46 -0
- package/dist/styles/classNames.d.ts +214 -0
- package/dist/styles/classNames.js +208 -0
- package/dist/styles/colors.d.ts +11 -0
- package/dist/styles/colors.js +14 -0
- package/dist/styles/fontSizes.d.ts +6 -0
- package/dist/styles/fontSizes.js +20 -0
- package/dist/styles/fontStack.d.ts +55 -0
- package/dist/styles/fontStack.js +262 -0
- package/dist/styles/fonts.d.ts +6 -0
- package/dist/styles/fonts.js +11 -0
- package/dist/styles/inlineStyle.d.ts +67 -0
- package/dist/styles/inlineStyle.js +212 -0
- package/dist/styles/lineSpacings.d.ts +11 -0
- package/dist/styles/lineSpacings.js +10 -0
- package/dist/styles.css +1650 -0
- package/dist/table/cellBorders.d.ts +12 -0
- package/dist/table/cellBorders.js +9 -0
- package/dist/table/cellFormatting.d.ts +57 -0
- package/dist/table/cellFormatting.js +173 -0
- package/dist/table/columns.d.ts +25 -0
- package/dist/table/columns.js +155 -0
- package/dist/table/commands.d.ts +19 -0
- package/dist/table/commands.js +63 -0
- package/dist/table/format.d.ts +35 -0
- package/dist/table/format.js +26 -0
- package/dist/table/gridBorders.d.ts +42 -0
- package/dist/table/gridBorders.js +192 -0
- package/dist/table/index.d.ts +16 -0
- package/dist/table/index.js +52 -0
- package/dist/table/merge.d.ts +36 -0
- package/dist/table/merge.js +125 -0
- package/dist/table/resize.d.ts +55 -0
- package/dist/table/resize.js +66 -0
- package/dist/table/rowResize.d.ts +14 -0
- package/dist/table/rowResize.js +44 -0
- package/dist/table/rows.d.ts +32 -0
- package/dist/table/rows.js +89 -0
- package/dist/table/widths.d.ts +69 -0
- package/dist/table/widths.js +97 -0
- package/dist/ui/AlignMenu.d.ts +15 -0
- package/dist/ui/AlignMenu.js +64 -0
- package/dist/ui/CellStyleGroup.d.ts +15 -0
- package/dist/ui/CellStyleGroup.js +232 -0
- package/dist/ui/ColorPicker.d.ts +13 -0
- package/dist/ui/ColorPicker.js +165 -0
- package/dist/ui/CommentsPanel.d.ts +15 -0
- package/dist/ui/CommentsPanel.js +348 -0
- package/dist/ui/FontFamilySelect.d.ts +14 -0
- package/dist/ui/FontFamilySelect.js +59 -0
- package/dist/ui/FontSizeSelect.d.ts +11 -0
- package/dist/ui/FontSizeSelect.js +49 -0
- package/dist/ui/InsertImageButton.d.ts +9 -0
- package/dist/ui/InsertImageButton.js +47 -0
- package/dist/ui/LinkCard.d.ts +12 -0
- package/dist/ui/LinkCard.js +127 -0
- package/dist/ui/LinkPanel.d.ts +9 -0
- package/dist/ui/LinkPanel.js +121 -0
- package/dist/ui/MenuChoice.d.ts +11 -0
- package/dist/ui/MenuChoice.js +32 -0
- package/dist/ui/NotesPanel.d.ts +6 -0
- package/dist/ui/NotesPanel.js +33 -0
- package/dist/ui/ParagraphStyleSelect.d.ts +11 -0
- package/dist/ui/ParagraphStyleSelect.js +62 -0
- package/dist/ui/Popover.d.ts +22 -0
- package/dist/ui/Popover.js +74 -0
- package/dist/ui/SpacingMenu.d.ts +12 -0
- package/dist/ui/SpacingMenu.js +54 -0
- package/dist/ui/TableMenu.d.ts +12 -0
- package/dist/ui/TableMenu.js +112 -0
- package/dist/ui/TableSizePicker.d.ts +9 -0
- package/dist/ui/TableSizePicker.js +53 -0
- package/dist/ui/TextMenu.d.ts +15 -0
- package/dist/ui/TextMenu.js +194 -0
- package/dist/ui/Toolbar.d.ts +19 -0
- package/dist/ui/Toolbar.js +448 -0
- package/dist/ui/ToolbarButton.d.ts +23 -0
- package/dist/ui/ToolbarButton.js +56 -0
- package/dist/ui/Tooltip.d.ts +19 -0
- package/dist/ui/Tooltip.js +47 -0
- package/dist/ui/ZoomSelect.d.ts +7 -0
- package/dist/ui/ZoomSelect.js +44 -0
- package/dist/ui/comments/CommentComposer.d.ts +17 -0
- package/dist/ui/comments/CommentComposer.js +59 -0
- package/dist/ui/comments/useCommentRailLayout.d.ts +18 -0
- package/dist/ui/comments/useCommentRailLayout.js +183 -0
- package/dist/ui/keyboardWalk.d.ts +22 -0
- package/dist/ui/keyboardWalk.js +70 -0
- package/dist/ui/openAddress.d.ts +11 -0
- package/dist/ui/openAddress.js +16 -0
- package/dist/ui/panelPlacement.d.ts +51 -0
- package/dist/ui/panelPlacement.js +71 -0
- package/dist/ui/presets.d.ts +11 -0
- package/dist/ui/presets.js +0 -0
- package/dist/ui/rovingFocus.d.ts +20 -0
- package/dist/ui/rovingFocus.js +61 -0
- package/dist/ui/runCommand.d.ts +5 -0
- package/dist/ui/runCommand.js +13 -0
- package/dist/ui/useDismiss.d.ts +6 -0
- package/dist/ui/useDismiss.js +31 -0
- package/dist/ui/useFitWidthZoom.d.ts +2 -0
- package/dist/ui/useFitWidthZoom.js +26 -0
- package/dist/ui/useGridKeyboard.d.ts +12 -0
- package/dist/ui/useGridKeyboard.js +90 -0
- package/dist/ui/useMenuKeyboard.d.ts +12 -0
- package/dist/ui/useMenuKeyboard.js +56 -0
- package/dist/ui/zoom.d.ts +4 -0
- package/dist/ui/zoom.js +21 -0
- package/package.json +120 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/table/rows.ts
|
|
2
|
+
import {
|
|
3
|
+
TextSelection
|
|
4
|
+
} from "prosemirror-state";
|
|
5
|
+
import {
|
|
6
|
+
deleteRow as pmDeleteRow,
|
|
7
|
+
isInTable as pmIsInTable,
|
|
8
|
+
selectedRect,
|
|
9
|
+
tableNodeTypes
|
|
10
|
+
} from "prosemirror-tables";
|
|
11
|
+
import { spanCount } from "../model/format.js";
|
|
12
|
+
import {
|
|
13
|
+
colwidthOf,
|
|
14
|
+
inheritCellAttrs,
|
|
15
|
+
inheritRowAttrs
|
|
16
|
+
} from "./format.js";
|
|
17
|
+
function isCoveredFromAbove(map, row, index) {
|
|
18
|
+
return row > 0 && row < map.height && map.map[index] === map.map[index - map.width];
|
|
19
|
+
}
|
|
20
|
+
function growRowspan(tr, rect, index) {
|
|
21
|
+
const { map, table, tableStart } = rect;
|
|
22
|
+
const pos = map.map[index];
|
|
23
|
+
const cell = table.nodeAt(pos);
|
|
24
|
+
if (!cell) return 1;
|
|
25
|
+
tr.setNodeMarkup(tableStart + pos, null, {
|
|
26
|
+
...cell.attrs,
|
|
27
|
+
rowspan: spanCount(cell.attrs.rowspan) + 1
|
|
28
|
+
});
|
|
29
|
+
return spanCount(cell.attrs.colspan);
|
|
30
|
+
}
|
|
31
|
+
function inheritedCell(rect, index, referenceRowOffset) {
|
|
32
|
+
const { map, table } = rect;
|
|
33
|
+
const referencePos = map.map[index + referenceRowOffset * map.width];
|
|
34
|
+
const referenceCell = referencePos != null ? table.nodeAt(referencePos) : null;
|
|
35
|
+
const type = referenceCell ? referenceCell.type : tableNodeTypes(table.type.schema).cell;
|
|
36
|
+
const colspan = referenceCell ? spanCount(referenceCell.attrs.colspan) : 1;
|
|
37
|
+
const attrs = referenceCell ? inheritCellAttrs(referenceCell, {
|
|
38
|
+
colspan,
|
|
39
|
+
rowspan: 1,
|
|
40
|
+
colwidth: colwidthOf(referenceCell)
|
|
41
|
+
}) : null;
|
|
42
|
+
return { node: type.createAndFill(attrs), colspan };
|
|
43
|
+
}
|
|
44
|
+
function insertRowWithFormat(tr, rect, row) {
|
|
45
|
+
const { map, table, tableStart } = rect;
|
|
46
|
+
let rowPos = tableStart;
|
|
47
|
+
for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
|
|
48
|
+
const referenceRowOffset = row > 0 ? -1 : 0;
|
|
49
|
+
const referenceRow = table.childCount > 0 ? table.child(row + referenceRowOffset) : null;
|
|
50
|
+
const cells = [];
|
|
51
|
+
for (let col = 0; col < map.width; ) {
|
|
52
|
+
const index = map.width * row + col;
|
|
53
|
+
if (isCoveredFromAbove(map, row, index)) {
|
|
54
|
+
col += growRowspan(tr, rect, index);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const { node, colspan } = inheritedCell(rect, index, referenceRowOffset);
|
|
58
|
+
if (node) cells.push(node);
|
|
59
|
+
col += colspan;
|
|
60
|
+
}
|
|
61
|
+
const rowType = tableNodeTypes(table.type.schema).row;
|
|
62
|
+
tr.insert(rowPos, rowType.create(inheritRowAttrs(referenceRow), cells));
|
|
63
|
+
return rowPos;
|
|
64
|
+
}
|
|
65
|
+
function buildAddRowTransaction(state, row) {
|
|
66
|
+
if (!pmIsInTable(state)) return null;
|
|
67
|
+
const rect = selectedRect(state);
|
|
68
|
+
const tr = state.tr;
|
|
69
|
+
const rowPos = insertRowWithFormat(tr, rect, row(rect));
|
|
70
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(rowPos + 1)));
|
|
71
|
+
return tr.scrollIntoView();
|
|
72
|
+
}
|
|
73
|
+
function buildAddRowAfterTransaction(state) {
|
|
74
|
+
return buildAddRowTransaction(state, (rect) => rect.bottom);
|
|
75
|
+
}
|
|
76
|
+
function buildAddRowBeforeTransaction(state) {
|
|
77
|
+
return buildAddRowTransaction(state, (rect) => rect.top);
|
|
78
|
+
}
|
|
79
|
+
function buildDeleteRowTransaction(state) {
|
|
80
|
+
if (!pmIsInTable(state)) return null;
|
|
81
|
+
const captured = [];
|
|
82
|
+
pmDeleteRow(state, (tr) => captured.push(tr));
|
|
83
|
+
return captured[0] ?? null;
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
buildAddRowAfterTransaction,
|
|
87
|
+
buildAddRowBeforeTransaction,
|
|
88
|
+
buildDeleteRowTransaction
|
|
89
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grid widths (`gridCols`) are always in dxa (1/20 of a point).
|
|
3
|
+
* Cell widths (`tcW`) and table widths (`tblW`) carry a value together with a unit,
|
|
4
|
+
* so a width taken from the grid has to be converted into the unit that cell uses.
|
|
5
|
+
*/
|
|
6
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
7
|
+
import type { Transaction } from "prosemirror-state";
|
|
8
|
+
import { type TableWidth, type TableWidthType } from "../model/format";
|
|
9
|
+
/**
|
|
10
|
+
* The grid column widths the table remembers, read from docx `w:gridCol`.
|
|
11
|
+
* An empty list means the grid is unknown, so it is treated the same as an absent one
|
|
12
|
+
* (no zero-width columns are created).
|
|
13
|
+
*/
|
|
14
|
+
export declare function tableGridCols(table: PMNode): number[] | null;
|
|
15
|
+
/** The sum of the grid column widths, which is the dxa width the table occupies */
|
|
16
|
+
export declare function gridTotal(gridCols: number[]): number;
|
|
17
|
+
/**
|
|
18
|
+
* Redistributes the grid column widths proportionally so that they sum to `total`.
|
|
19
|
+
*
|
|
20
|
+
* Widths are integer dxa, so scaling them proportionally leaves a rounding error
|
|
21
|
+
* behind. The leftover error is absorbed by the last column, making the sum exactly
|
|
22
|
+
* `total`. When there is no width to distribute (the sum is 0), they are left as they
|
|
23
|
+
* are.
|
|
24
|
+
*/
|
|
25
|
+
export declare function gridColsScaledTo(gridCols: number[], total: number): number[];
|
|
26
|
+
/**
|
|
27
|
+
* Converts the width of one grid column into the unit the cell uses. A percentage is
|
|
28
|
+
* a ratio of the grid total
|
|
29
|
+
*/
|
|
30
|
+
export declare function gridWidthInCellUnit(gridWidth: number, gridCols: number[], type: TableWidthType): number;
|
|
31
|
+
/**
|
|
32
|
+
* The width of a new cell that occupies a single grid column.
|
|
33
|
+
*
|
|
34
|
+
* When the grid is known, one grid column is converted into the reference cell's unit;
|
|
35
|
+
* when it is not, the reference cell's width is divided by its span count (using the
|
|
36
|
+
* full width of a merged cell as is would make the new cell several columns wide).
|
|
37
|
+
* If the reference cell records no width, none is created for the new cell either.
|
|
38
|
+
*/
|
|
39
|
+
export declare function cellWidthForGridCol(gridCols: number[] | null, gridCol: number, reference: TableWidth | null, referenceColspan: number): TableWidth | null;
|
|
40
|
+
/**
|
|
41
|
+
* The width of a single cell covering several grid columns.
|
|
42
|
+
* It is null when the grid is unknown or the range falls outside the grid, leaving the
|
|
43
|
+
* caller to pick another value.
|
|
44
|
+
*/
|
|
45
|
+
export declare function gridSpanWidth(gridCols: number[] | null, from: number, to: number, type: TableWidthType): number | null;
|
|
46
|
+
/**
|
|
47
|
+
* The table width shifted by however much the grid total moved.
|
|
48
|
+
* Only dxa shares its unit with the grid. A percentage is a ratio of the page width,
|
|
49
|
+
* so it is left as it is.
|
|
50
|
+
*/
|
|
51
|
+
export declare function shiftedTableWidth(table: PMNode, gridCols: number[]): TableWidth | null;
|
|
52
|
+
/**
|
|
53
|
+
* Writes the grid column widths back onto the table and brings the table width in line
|
|
54
|
+
* with the grid total.
|
|
55
|
+
*
|
|
56
|
+
* `tableStart - 1` is the position of the table itself. Cell insertions and deletions
|
|
57
|
+
* all happen after it, so that position never changes, but it is mapped once anyway to
|
|
58
|
+
* stay safe regardless of call order.
|
|
59
|
+
*/
|
|
60
|
+
export declare function writeGridCols(tr: Transaction, tableStart: number, gridCols: number[]): void;
|
|
61
|
+
/**
|
|
62
|
+
* Fits the cell widths to the changed grid. Every cell records the new sum of the grid
|
|
63
|
+
* columns it covers.
|
|
64
|
+
*
|
|
65
|
+
* Only widths recorded in dxa are touched. A percentage is a ratio of the table width,
|
|
66
|
+
* so it stays the same even when the grid moves, and a cell with no width (null) gets
|
|
67
|
+
* none created because its original XML has to be written back as it is.
|
|
68
|
+
*/
|
|
69
|
+
export declare function rescaleCellWidths(tr: Transaction, tableStart: number, gridCols: number[]): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/table/widths.ts
|
|
2
|
+
import { TableMap } from "prosemirror-tables";
|
|
3
|
+
import {
|
|
4
|
+
spanCount,
|
|
5
|
+
toTableWidth,
|
|
6
|
+
widthNumber,
|
|
7
|
+
withWidthNumber
|
|
8
|
+
} from "../model/format.js";
|
|
9
|
+
var PCT_FULL = 5e3;
|
|
10
|
+
function isNumberArray(value) {
|
|
11
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "number");
|
|
12
|
+
}
|
|
13
|
+
function tableGridCols(table) {
|
|
14
|
+
const value = table.attrs.gridCols;
|
|
15
|
+
return isNumberArray(value) && value.length > 0 ? value : null;
|
|
16
|
+
}
|
|
17
|
+
function gridTotal(gridCols) {
|
|
18
|
+
return gridCols.reduce((sum, width) => sum + width, 0);
|
|
19
|
+
}
|
|
20
|
+
function gridColsScaledTo(gridCols, total) {
|
|
21
|
+
const current = gridTotal(gridCols);
|
|
22
|
+
if (current <= 0 || total <= 0) return gridCols;
|
|
23
|
+
const scaled = gridCols.map((width) => Math.round(width * total / current));
|
|
24
|
+
const drift = total - gridTotal(scaled);
|
|
25
|
+
const last = scaled.length - 1;
|
|
26
|
+
return scaled.map((width, at) => at === last ? width + drift : width);
|
|
27
|
+
}
|
|
28
|
+
function gridWidthInCellUnit(gridWidth, gridCols, type) {
|
|
29
|
+
if (type !== "pct") return gridWidth;
|
|
30
|
+
const total = gridTotal(gridCols);
|
|
31
|
+
return total > 0 ? Math.round(gridWidth / total * PCT_FULL) : gridWidth;
|
|
32
|
+
}
|
|
33
|
+
function cellWidthForGridCol(gridCols, gridCol, reference, referenceColspan) {
|
|
34
|
+
if (!reference) return null;
|
|
35
|
+
const gridWidth = gridCols?.[gridCol];
|
|
36
|
+
if (gridCols && typeof gridWidth === "number") {
|
|
37
|
+
return withWidthNumber(
|
|
38
|
+
reference,
|
|
39
|
+
gridWidthInCellUnit(gridWidth, gridCols, reference.type)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const own = widthNumber(reference);
|
|
43
|
+
return own === null ? reference : withWidthNumber(reference, Math.round(own / referenceColspan));
|
|
44
|
+
}
|
|
45
|
+
function gridSpanWidth(gridCols, from, to, type) {
|
|
46
|
+
if (!gridCols) return null;
|
|
47
|
+
const covered = gridCols.slice(from, to);
|
|
48
|
+
if (covered.length === 0) return null;
|
|
49
|
+
return gridWidthInCellUnit(gridTotal(covered), gridCols, type);
|
|
50
|
+
}
|
|
51
|
+
function shiftedTableWidth(table, gridCols) {
|
|
52
|
+
const width = toTableWidth(table.attrs.tblW);
|
|
53
|
+
const previous = tableGridCols(table);
|
|
54
|
+
if (!width || width.type !== "dxa" || !previous) return width;
|
|
55
|
+
const shifted = width.twips + gridTotal(gridCols) - gridTotal(previous);
|
|
56
|
+
return { type: "dxa", twips: shifted };
|
|
57
|
+
}
|
|
58
|
+
function writeGridCols(tr, tableStart, gridCols) {
|
|
59
|
+
const tablePos = tr.mapping.map(tableStart - 1);
|
|
60
|
+
const table = tr.doc.nodeAt(tablePos);
|
|
61
|
+
if (!table) return;
|
|
62
|
+
tr.setNodeMarkup(tablePos, null, {
|
|
63
|
+
...table.attrs,
|
|
64
|
+
gridCols,
|
|
65
|
+
tblW: shiftedTableWidth(table, gridCols)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function rescaleCellWidths(tr, tableStart, gridCols) {
|
|
69
|
+
const tablePos = tr.mapping.map(tableStart - 1);
|
|
70
|
+
const table = tr.doc.nodeAt(tablePos);
|
|
71
|
+
if (!table) return;
|
|
72
|
+
const map = TableMap.get(table);
|
|
73
|
+
for (const pos of new Set(map.map)) {
|
|
74
|
+
const cell = table.nodeAt(pos);
|
|
75
|
+
const width = cell ? toTableWidth(cell.attrs.tcW) : null;
|
|
76
|
+
if (!cell || !width || width.type !== "dxa") continue;
|
|
77
|
+
const from = map.colCount(pos);
|
|
78
|
+
const to = from + spanCount(cell.attrs.colspan);
|
|
79
|
+
const spanned = gridSpanWidth(gridCols, from, to, width.type);
|
|
80
|
+
if (spanned === null || spanned === width.twips) continue;
|
|
81
|
+
tr.setNodeMarkup(tablePos + 1 + pos, null, {
|
|
82
|
+
...cell.attrs,
|
|
83
|
+
tcW: { type: "dxa", twips: spanned }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
cellWidthForGridCol,
|
|
89
|
+
gridColsScaledTo,
|
|
90
|
+
gridSpanWidth,
|
|
91
|
+
gridTotal,
|
|
92
|
+
gridWidthInCellUnit,
|
|
93
|
+
rescaleCellWidths,
|
|
94
|
+
shiftedTableWidth,
|
|
95
|
+
tableGridCols,
|
|
96
|
+
writeGridCols
|
|
97
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Menu for choosing the current paragraph alignment. */
|
|
2
|
+
import { type LucideIcon } from "lucide-react";
|
|
3
|
+
import type { EditorState } from "prosemirror-state";
|
|
4
|
+
import { type ReactElement } from "react";
|
|
5
|
+
import { type ActiveParagraphAlign } from "../editor/commands/paragraphCommands";
|
|
6
|
+
import type { RunCommand } from "./runCommand";
|
|
7
|
+
/** Uses the left-align icon when the selection has no shared alignment. */
|
|
8
|
+
export declare function alignIcon(current: ActiveParagraphAlign): LucideIcon;
|
|
9
|
+
export interface AlignMenuProps {
|
|
10
|
+
state: EditorState;
|
|
11
|
+
run: RunCommand;
|
|
12
|
+
close: () => void;
|
|
13
|
+
takeFocus: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function AlignMenu({ state, run, close, takeFocus, }: AlignMenuProps): ReactElement;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/ui/AlignMenu.tsx
|
|
2
|
+
import {
|
|
3
|
+
AlignCenter,
|
|
4
|
+
AlignJustify,
|
|
5
|
+
AlignLeft,
|
|
6
|
+
AlignRight
|
|
7
|
+
} from "lucide-react";
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
import {
|
|
10
|
+
activeParagraphAlign,
|
|
11
|
+
setParagraphAlign
|
|
12
|
+
} from "../editor/commands/paragraphCommands.js";
|
|
13
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
14
|
+
import { MenuChoice } from "./MenuChoice.js";
|
|
15
|
+
import { useMenuKeyboard } from "./useMenuKeyboard.js";
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
var ALIGNMENTS = [
|
|
18
|
+
{ label: "Align left", icon: AlignLeft, align: "left" },
|
|
19
|
+
{ label: "Align center", icon: AlignCenter, align: "center" },
|
|
20
|
+
{ label: "Align right", icon: AlignRight, align: "right" },
|
|
21
|
+
{ label: "Justify", icon: AlignJustify, align: "justify" }
|
|
22
|
+
];
|
|
23
|
+
function alignIcon(current) {
|
|
24
|
+
const align = current.kind === "shared" ? current.align : null;
|
|
25
|
+
return ALIGNMENTS.find((choice) => choice.align === align)?.icon ?? AlignLeft;
|
|
26
|
+
}
|
|
27
|
+
function AlignMenu({
|
|
28
|
+
state,
|
|
29
|
+
run,
|
|
30
|
+
close,
|
|
31
|
+
takeFocus
|
|
32
|
+
}) {
|
|
33
|
+
const current = activeParagraphAlign(state);
|
|
34
|
+
const menu = useRef(null);
|
|
35
|
+
const keys = useMenuKeyboard({ menu, onClose: close, takeFocus });
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
"div",
|
|
38
|
+
{
|
|
39
|
+
ref: menu,
|
|
40
|
+
className: editorClassNames.menuList,
|
|
41
|
+
role: "menu",
|
|
42
|
+
"aria-label": "Paragraph alignment",
|
|
43
|
+
...keys,
|
|
44
|
+
children: ALIGNMENTS.map((choice) => /* @__PURE__ */ jsx(
|
|
45
|
+
MenuChoice,
|
|
46
|
+
{
|
|
47
|
+
label: choice.label,
|
|
48
|
+
icon: choice.icon,
|
|
49
|
+
role: "menuitemradio",
|
|
50
|
+
checked: current.kind === "shared" && current.align === choice.align,
|
|
51
|
+
onChoose: () => {
|
|
52
|
+
run(setParagraphAlign(choice.align));
|
|
53
|
+
close();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
choice.align
|
|
57
|
+
))
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
AlignMenu,
|
|
63
|
+
alignIcon
|
|
64
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Toolbar controls for formatting the current table cell selection. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import { type ReactElement } from "react";
|
|
4
|
+
import type { ColorRow } from "../styles/colors";
|
|
5
|
+
import { type CellBorderOption } from "../table/cellBorders";
|
|
6
|
+
import type { RunCommand } from "./runCommand";
|
|
7
|
+
export interface CellStyleGroupProps {
|
|
8
|
+
state: EditorState;
|
|
9
|
+
/** The border choices the menu offers. The built-in list when none is given */
|
|
10
|
+
cellBorders?: readonly CellBorderOption[];
|
|
11
|
+
/** The swatches both color buttons offer. The built-in palette when none is given */
|
|
12
|
+
colors?: readonly ColorRow[];
|
|
13
|
+
run: RunCommand;
|
|
14
|
+
}
|
|
15
|
+
export declare function CellStyleGroup({ state, cellBorders, colors, run, }: CellStyleGroupProps): ReactElement;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// src/ui/CellStyleGroup.tsx
|
|
2
|
+
import {
|
|
3
|
+
AlignVerticalJustifyCenter,
|
|
4
|
+
AlignVerticalJustifyEnd,
|
|
5
|
+
AlignVerticalJustifyStart,
|
|
6
|
+
Grid2x2,
|
|
7
|
+
PaintBucket,
|
|
8
|
+
Palette,
|
|
9
|
+
Square,
|
|
10
|
+
SquareDashed
|
|
11
|
+
} from "lucide-react";
|
|
12
|
+
import { useRef } from "react";
|
|
13
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
14
|
+
import {
|
|
15
|
+
activeCellBackground,
|
|
16
|
+
activeCellBorderColor,
|
|
17
|
+
activeCellVerticalAlign,
|
|
18
|
+
canSetCellBorderColor,
|
|
19
|
+
canSetCellFormatting,
|
|
20
|
+
setCellBackground,
|
|
21
|
+
setCellBorderColor,
|
|
22
|
+
setCellBorders,
|
|
23
|
+
setCellVerticalAlign
|
|
24
|
+
} from "../table/index.js";
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_CELL_BORDERS
|
|
27
|
+
} from "../table/cellBorders.js";
|
|
28
|
+
import { ColorPicker } from "./ColorPicker.js";
|
|
29
|
+
import { MenuChoice } from "./MenuChoice.js";
|
|
30
|
+
import { Popover } from "./Popover.js";
|
|
31
|
+
import { ICON_SIZE } from "./ToolbarButton.js";
|
|
32
|
+
import { useMenuKeyboard } from "./useMenuKeyboard.js";
|
|
33
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
34
|
+
var BORDER_ICONS = {
|
|
35
|
+
all: Grid2x2,
|
|
36
|
+
outer: Square,
|
|
37
|
+
none: SquareDashed
|
|
38
|
+
};
|
|
39
|
+
var ALIGNMENTS = [
|
|
40
|
+
{ value: "top", label: "Align cell top", icon: AlignVerticalJustifyStart },
|
|
41
|
+
{
|
|
42
|
+
value: "center",
|
|
43
|
+
label: "Align cell center",
|
|
44
|
+
icon: AlignVerticalJustifyCenter
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
value: "bottom",
|
|
48
|
+
label: "Align cell bottom",
|
|
49
|
+
icon: AlignVerticalJustifyEnd
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
function CellVerticalAlignMenu({
|
|
53
|
+
state,
|
|
54
|
+
run,
|
|
55
|
+
close,
|
|
56
|
+
takeFocus
|
|
57
|
+
}) {
|
|
58
|
+
const current = activeCellVerticalAlign(state);
|
|
59
|
+
const menu = useRef(null);
|
|
60
|
+
const keys = useMenuKeyboard({ menu, onClose: close, takeFocus });
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
"div",
|
|
63
|
+
{
|
|
64
|
+
ref: menu,
|
|
65
|
+
className: editorClassNames.menuList,
|
|
66
|
+
role: "menu",
|
|
67
|
+
"aria-label": "Cell vertical alignment",
|
|
68
|
+
...keys,
|
|
69
|
+
children: ALIGNMENTS.map((option) => /* @__PURE__ */ jsx(
|
|
70
|
+
MenuChoice,
|
|
71
|
+
{
|
|
72
|
+
label: option.label,
|
|
73
|
+
icon: option.icon,
|
|
74
|
+
role: "menuitemradio",
|
|
75
|
+
checked: current === option.value,
|
|
76
|
+
onChoose: () => {
|
|
77
|
+
run(setCellVerticalAlign(option.value));
|
|
78
|
+
close();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
option.value
|
|
82
|
+
))
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function cellVerticalAlignIcon(current) {
|
|
87
|
+
return ALIGNMENTS.find((option) => option.value === current)?.icon ?? AlignVerticalJustifyStart;
|
|
88
|
+
}
|
|
89
|
+
function BorderPresetMenu({
|
|
90
|
+
state,
|
|
91
|
+
cellBorders,
|
|
92
|
+
run,
|
|
93
|
+
close,
|
|
94
|
+
takeFocus
|
|
95
|
+
}) {
|
|
96
|
+
const menu = useRef(null);
|
|
97
|
+
const keys = useMenuKeyboard({ menu, onClose: close, takeFocus });
|
|
98
|
+
return /* @__PURE__ */ jsx(
|
|
99
|
+
"div",
|
|
100
|
+
{
|
|
101
|
+
ref: menu,
|
|
102
|
+
className: editorClassNames.menuList,
|
|
103
|
+
role: "menu",
|
|
104
|
+
"aria-label": "Cell borders",
|
|
105
|
+
...keys,
|
|
106
|
+
children: cellBorders.map((option) => {
|
|
107
|
+
const command = setCellBorders(option.preset);
|
|
108
|
+
const Icon = BORDER_ICONS[option.preset];
|
|
109
|
+
return /* @__PURE__ */ jsxs(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
type: "button",
|
|
113
|
+
role: "menuitem",
|
|
114
|
+
className: editorClassNames.menuItem,
|
|
115
|
+
"aria-disabled": !command(state),
|
|
116
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
117
|
+
onClick: () => {
|
|
118
|
+
if (!command(state)) return;
|
|
119
|
+
run(command);
|
|
120
|
+
close();
|
|
121
|
+
},
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsx("span", { className: editorClassNames.menuCheck }),
|
|
124
|
+
/* @__PURE__ */ jsx(Icon, { size: ICON_SIZE, "aria-hidden": "true" }),
|
|
125
|
+
option.label
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
option.preset
|
|
129
|
+
);
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
function CellStyleGroup({
|
|
135
|
+
state,
|
|
136
|
+
cellBorders = DEFAULT_CELL_BORDERS,
|
|
137
|
+
colors,
|
|
138
|
+
run
|
|
139
|
+
}) {
|
|
140
|
+
const activeAlignment = activeCellVerticalAlign(state);
|
|
141
|
+
const layoutEditable = canSetCellFormatting(state);
|
|
142
|
+
return /* @__PURE__ */ jsxs("div", { className: editorClassNames.toolbarGroup, children: [
|
|
143
|
+
/* @__PURE__ */ jsx(
|
|
144
|
+
Popover,
|
|
145
|
+
{
|
|
146
|
+
label: "Cell vertical alignment",
|
|
147
|
+
icon: cellVerticalAlignIcon(activeAlignment),
|
|
148
|
+
panel: "menu",
|
|
149
|
+
disabled: !layoutEditable,
|
|
150
|
+
children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
|
|
151
|
+
CellVerticalAlignMenu,
|
|
152
|
+
{
|
|
153
|
+
state,
|
|
154
|
+
run,
|
|
155
|
+
close,
|
|
156
|
+
takeFocus
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
/* @__PURE__ */ jsx(
|
|
162
|
+
Popover,
|
|
163
|
+
{
|
|
164
|
+
label: "Cell borders",
|
|
165
|
+
icon: Grid2x2,
|
|
166
|
+
panel: "menu",
|
|
167
|
+
disabled: !layoutEditable,
|
|
168
|
+
children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
|
|
169
|
+
BorderPresetMenu,
|
|
170
|
+
{
|
|
171
|
+
state,
|
|
172
|
+
cellBorders,
|
|
173
|
+
run,
|
|
174
|
+
close,
|
|
175
|
+
takeFocus
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
/* @__PURE__ */ jsx(
|
|
181
|
+
Popover,
|
|
182
|
+
{
|
|
183
|
+
label: "Border color",
|
|
184
|
+
icon: Palette,
|
|
185
|
+
indicatorColor: activeCellBorderColor(state) ?? "#000000",
|
|
186
|
+
panel: "dialog",
|
|
187
|
+
disabled: !layoutEditable || !canSetCellBorderColor(state),
|
|
188
|
+
children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
|
|
189
|
+
ColorPicker,
|
|
190
|
+
{
|
|
191
|
+
current: activeCellBorderColor(state),
|
|
192
|
+
colors,
|
|
193
|
+
clearLabel: "Automatic",
|
|
194
|
+
close,
|
|
195
|
+
takeFocus,
|
|
196
|
+
onPick: (hex) => {
|
|
197
|
+
run(setCellBorderColor(hex));
|
|
198
|
+
close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
Popover,
|
|
206
|
+
{
|
|
207
|
+
label: "Cell fill",
|
|
208
|
+
icon: PaintBucket,
|
|
209
|
+
indicatorColor: activeCellBackground(state) ?? "transparent",
|
|
210
|
+
panel: "dialog",
|
|
211
|
+
disabled: !layoutEditable,
|
|
212
|
+
children: ({ close, takeFocus }) => /* @__PURE__ */ jsx(
|
|
213
|
+
ColorPicker,
|
|
214
|
+
{
|
|
215
|
+
current: activeCellBackground(state),
|
|
216
|
+
colors,
|
|
217
|
+
clearLabel: "No fill",
|
|
218
|
+
close,
|
|
219
|
+
takeFocus,
|
|
220
|
+
onPick: (hex) => {
|
|
221
|
+
run(setCellBackground(hex));
|
|
222
|
+
close();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
] });
|
|
229
|
+
}
|
|
230
|
+
export {
|
|
231
|
+
CellStyleGroup
|
|
232
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Preset and custom colors shared by text, background, border, and cell formatting. */
|
|
2
|
+
import { type ReactElement } from "react";
|
|
3
|
+
import { type ColorRow } from "../styles/colors";
|
|
4
|
+
export interface ColorPickerProps {
|
|
5
|
+
current: string | null;
|
|
6
|
+
colors?: readonly ColorRow[];
|
|
7
|
+
/** Label for the entry that clears the color. */
|
|
8
|
+
clearLabel?: string;
|
|
9
|
+
close: () => void;
|
|
10
|
+
takeFocus: boolean;
|
|
11
|
+
onPick: (hex: string | null) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function ColorPicker({ current, colors, clearLabel, close, takeFocus, onPick, }: ColorPickerProps): ReactElement;
|