@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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cell border presets the built-in menu offers, each with the name written on its row.
|
|
3
|
+
* A menu of your own takes the list from the root entry and hands the preset it picked to
|
|
4
|
+
* `setCellBorders`.
|
|
5
|
+
*/
|
|
6
|
+
import type { CellBorderPreset } from "./cellFormatting";
|
|
7
|
+
export interface CellBorderOption {
|
|
8
|
+
/** What the row is called on screen */
|
|
9
|
+
label: string;
|
|
10
|
+
preset: CellBorderPreset;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_CELL_BORDERS: readonly CellBorderOption[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A job applies to the cell holding the caret, or to every cell a cell selection covers.
|
|
3
|
+
* All XML handling belongs to `docx/tableFormatting`; this file only decides which cells take part
|
|
4
|
+
* and which of their sides a border preset writes.
|
|
5
|
+
*
|
|
6
|
+
* A cell already in the state the job wants is left untouched, so its original XML survives.
|
|
7
|
+
* That is also what tells the menu whether an entry has anything to do: following the ProseMirror
|
|
8
|
+
* convention, calling a command without `dispatch` only reports whether it would change something.
|
|
9
|
+
*/
|
|
10
|
+
import type { EditorState } from "prosemirror-state";
|
|
11
|
+
import { type CellSide } from "../docx/tableFormatting";
|
|
12
|
+
import { type CellVerticalAlign } from "../model/format";
|
|
13
|
+
import type { TableCommand } from "./commands";
|
|
14
|
+
/**
|
|
15
|
+
* Which sides of the selected block a preset writes.
|
|
16
|
+
* `all` and `none` speak for every side of every selected cell, while `outer` writes only the sides
|
|
17
|
+
* that lie on the edge of the block, leaving the lines inside it as they are (the same as Word).
|
|
18
|
+
*/
|
|
19
|
+
export type CellBorderPreset = "all" | "outer" | "none";
|
|
20
|
+
export type MixedCellValue<T> = T | "mixed" | null;
|
|
21
|
+
export interface ActiveCellPadding {
|
|
22
|
+
top: MixedCellValue<number>;
|
|
23
|
+
right: MixedCellValue<number>;
|
|
24
|
+
bottom: MixedCellValue<number>;
|
|
25
|
+
left: MixedCellValue<number>;
|
|
26
|
+
}
|
|
27
|
+
/** The effective vertical alignment of the selected cells. An omitted OOXML value means top. */
|
|
28
|
+
export declare function activeCellVerticalAlign(state: EditorState): MixedCellValue<CellVerticalAlign>;
|
|
29
|
+
/** The effective padding on each side of the selected cells, with mixed sides reported separately. */
|
|
30
|
+
export declare function activeCellPadding(state: EditorState): ActiveCellPadding;
|
|
31
|
+
/** Places content at the top, center, or bottom of every selected cell. */
|
|
32
|
+
export declare function setCellVerticalAlign(align: CellVerticalAlign): TableCommand;
|
|
33
|
+
/** Writes direct padding only for the sides supplied, leaving every omitted side unchanged. */
|
|
34
|
+
export declare function setCellPadding(values: Partial<Record<CellSide, number>>): TableCommand;
|
|
35
|
+
/** Draws (or clears) the lines of the selected cells. */
|
|
36
|
+
export declare function setCellBorders(preset: CellBorderPreset): TableCommand;
|
|
37
|
+
/**
|
|
38
|
+
* Colors the visible lines of the selected cells as `#RRGGBB`. Inherited table lines become direct
|
|
39
|
+
* cell overrides only on the sides that are visible. Null resets the resulting color to `auto`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function setCellBorderColor(hex: string | null): TableCommand;
|
|
42
|
+
/** Fills the selected cells with `#RRGGBB`. Null takes the fill away */
|
|
43
|
+
export declare function setCellBackground(hex: string | null): TableCommand;
|
|
44
|
+
/** Whether direct cell formatting can act on the whole current cell selection. */
|
|
45
|
+
export declare function canSetCellFormatting(state: EditorState): boolean;
|
|
46
|
+
/** The fill shared by the selected cells. Null when they differ or none is filled */
|
|
47
|
+
export declare function activeCellBackground(state: EditorState): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* The color shared by every line the selected cells draw.
|
|
50
|
+
* The lines are looked at as they appear on screen, so a color the table's inside lines gave is
|
|
51
|
+
* counted too. Null when the lines differ, or when none is drawn.
|
|
52
|
+
*/
|
|
53
|
+
export declare function activeCellBorderColor(state: EditorState): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the border color has anything visible to act on in the current cell selection.
|
|
56
|
+
*/
|
|
57
|
+
export declare function canSetCellBorderColor(state: EditorState): boolean;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// src/table/cellFormatting.ts
|
|
2
|
+
import { isInTable as pmIsInTable, selectedRect } from "prosemirror-tables";
|
|
3
|
+
import {
|
|
4
|
+
ALL_CELL_SIDES,
|
|
5
|
+
editCellProps
|
|
6
|
+
} from "../docx/tableFormatting.js";
|
|
7
|
+
import {
|
|
8
|
+
NO_FILL,
|
|
9
|
+
toCellFormat
|
|
10
|
+
} from "../model/format.js";
|
|
11
|
+
import { isLockedCell, transactionAllowed } from "../schema/locks.js";
|
|
12
|
+
import { cellDefaultsAt, tableCellSources } from "./gridBorders.js";
|
|
13
|
+
function text(value) {
|
|
14
|
+
return typeof value === "string" ? value : null;
|
|
15
|
+
}
|
|
16
|
+
function outerSides(rect, pos) {
|
|
17
|
+
const cell = rect.map.findCell(pos);
|
|
18
|
+
const sides = [];
|
|
19
|
+
if (cell.top === rect.top) sides.push("top");
|
|
20
|
+
if (cell.bottom === rect.bottom) sides.push("bottom");
|
|
21
|
+
if (cell.left === rect.left) sides.push("left");
|
|
22
|
+
if (cell.right === rect.right) sides.push("right");
|
|
23
|
+
return sides;
|
|
24
|
+
}
|
|
25
|
+
function borderEdit(preset, rect, pos) {
|
|
26
|
+
return {
|
|
27
|
+
kind: "borders",
|
|
28
|
+
line: preset === "none" ? "none" : "single",
|
|
29
|
+
sides: preset === "outer" ? outerSides(rect, pos) : ALL_CELL_SIDES
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function planChanges(rect, edit) {
|
|
33
|
+
const sources = tableCellSources(rect.table);
|
|
34
|
+
const changes = [];
|
|
35
|
+
for (const pos of rect.map.cellsInRect(rect)) {
|
|
36
|
+
const cell = rect.table.nodeAt(pos);
|
|
37
|
+
if (!cell) continue;
|
|
38
|
+
const next = editCellProps(
|
|
39
|
+
text(cell.attrs.tcPr),
|
|
40
|
+
edit(rect, pos),
|
|
41
|
+
cellDefaultsAt(rect.map, pos, sources),
|
|
42
|
+
sources.margins
|
|
43
|
+
);
|
|
44
|
+
if (!next) continue;
|
|
45
|
+
changes.push({
|
|
46
|
+
pos,
|
|
47
|
+
attrs: { ...cell.attrs, tcPr: next.tcPr, format: next.format }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return changes;
|
|
51
|
+
}
|
|
52
|
+
function cellFormatCommand(edit) {
|
|
53
|
+
return (state, dispatch) => {
|
|
54
|
+
if (!pmIsInTable(state)) return false;
|
|
55
|
+
const rect = selectedRect(state);
|
|
56
|
+
if (rect.map.cellsInRect(rect).some((pos) => isLockedCell(rect.table.nodeAt(pos)))) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const changes = planChanges(rect, edit);
|
|
60
|
+
if (changes.length === 0) return false;
|
|
61
|
+
const transaction = applyChanges(state.tr, rect.tableStart, changes);
|
|
62
|
+
if (!transactionAllowed(transaction, state.doc)) return false;
|
|
63
|
+
dispatch?.(transaction);
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function shared(values) {
|
|
68
|
+
const [first, ...rest] = values;
|
|
69
|
+
if (first === void 0) return null;
|
|
70
|
+
return rest.every((value) => value === first) ? first : "mixed";
|
|
71
|
+
}
|
|
72
|
+
function activeCellVerticalAlign(state) {
|
|
73
|
+
return shared(
|
|
74
|
+
cellFormats(state).map((format) => format?.verticalAlign ?? "top")
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function activeCellPadding(state) {
|
|
78
|
+
const formats = cellFormats(state);
|
|
79
|
+
return {
|
|
80
|
+
top: shared(formats.map((format) => format?.paddingTopPt ?? null)),
|
|
81
|
+
right: shared(formats.map((format) => format?.paddingRightPt ?? null)),
|
|
82
|
+
bottom: shared(formats.map((format) => format?.paddingBottomPt ?? null)),
|
|
83
|
+
left: shared(formats.map((format) => format?.paddingLeftPt ?? null))
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function setCellVerticalAlign(align) {
|
|
87
|
+
return cellFormatCommand(() => ({ kind: "verticalAlign", align }));
|
|
88
|
+
}
|
|
89
|
+
function setCellPadding(values) {
|
|
90
|
+
return cellFormatCommand(() => ({ kind: "padding", values }));
|
|
91
|
+
}
|
|
92
|
+
function applyChanges(tr, tableStart, changes) {
|
|
93
|
+
for (const change of changes) {
|
|
94
|
+
tr.setNodeMarkup(tableStart + change.pos, null, change.attrs);
|
|
95
|
+
}
|
|
96
|
+
return tr;
|
|
97
|
+
}
|
|
98
|
+
function setCellBorders(preset) {
|
|
99
|
+
return cellFormatCommand((rect, pos) => borderEdit(preset, rect, pos));
|
|
100
|
+
}
|
|
101
|
+
function setCellBorderColor(hex) {
|
|
102
|
+
return cellFormatCommand(() => ({ kind: "borderColor", hex }));
|
|
103
|
+
}
|
|
104
|
+
function setCellBackground(hex) {
|
|
105
|
+
return cellFormatCommand(() => ({ kind: "background", hex }));
|
|
106
|
+
}
|
|
107
|
+
function selectedCells(state) {
|
|
108
|
+
if (!pmIsInTable(state)) return [];
|
|
109
|
+
const rect = selectedRect(state);
|
|
110
|
+
const cells = [];
|
|
111
|
+
for (const pos of rect.map.cellsInRect(rect)) {
|
|
112
|
+
const cell = rect.table.nodeAt(pos);
|
|
113
|
+
if (cell) cells.push(cell);
|
|
114
|
+
}
|
|
115
|
+
return cells;
|
|
116
|
+
}
|
|
117
|
+
function cellFormats(state) {
|
|
118
|
+
return selectedCells(state).map((cell) => toCellFormat(cell.attrs.format));
|
|
119
|
+
}
|
|
120
|
+
function canSetCellFormatting(state) {
|
|
121
|
+
const cells = selectedCells(state);
|
|
122
|
+
return cells.length > 0 && cells.every((cell) => !isLockedCell(cell));
|
|
123
|
+
}
|
|
124
|
+
function sharedValue(values) {
|
|
125
|
+
const [first, ...rest] = values;
|
|
126
|
+
if (first === void 0) return null;
|
|
127
|
+
return rest.every((value) => value === first) ? first : null;
|
|
128
|
+
}
|
|
129
|
+
function borderColorOf(border) {
|
|
130
|
+
if (border === void 0 || border === "none") return null;
|
|
131
|
+
const color = border.slice(border.lastIndexOf(" ") + 1);
|
|
132
|
+
return color.startsWith("#") ? color : null;
|
|
133
|
+
}
|
|
134
|
+
function activeCellBackground(state) {
|
|
135
|
+
const shared2 = sharedValue(
|
|
136
|
+
cellFormats(state).map((format) => format?.background ?? null)
|
|
137
|
+
);
|
|
138
|
+
return shared2 === NO_FILL ? null : shared2;
|
|
139
|
+
}
|
|
140
|
+
function activeCellBorderColor(state) {
|
|
141
|
+
const colors = cellFormats(state).flatMap(
|
|
142
|
+
(format) => [
|
|
143
|
+
format?.borderTop,
|
|
144
|
+
format?.borderBottom,
|
|
145
|
+
format?.borderLeft,
|
|
146
|
+
format?.borderRight
|
|
147
|
+
].map(borderColorOf).filter((color) => color !== null)
|
|
148
|
+
);
|
|
149
|
+
return sharedValue(colors);
|
|
150
|
+
}
|
|
151
|
+
function canSetCellBorderColor(state) {
|
|
152
|
+
return canSetCellFormatting(state) && cellFormats(state).some(
|
|
153
|
+
(format) => [
|
|
154
|
+
format?.borderTop,
|
|
155
|
+
format?.borderBottom,
|
|
156
|
+
format?.borderLeft,
|
|
157
|
+
format?.borderRight
|
|
158
|
+
].some((border) => border !== void 0 && border !== "none")
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
activeCellBackground,
|
|
163
|
+
activeCellBorderColor,
|
|
164
|
+
activeCellPadding,
|
|
165
|
+
activeCellVerticalAlign,
|
|
166
|
+
canSetCellBorderColor,
|
|
167
|
+
canSetCellFormatting,
|
|
168
|
+
setCellBackground,
|
|
169
|
+
setCellBorderColor,
|
|
170
|
+
setCellBorders,
|
|
171
|
+
setCellPadding,
|
|
172
|
+
setCellVerticalAlign
|
|
173
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `prosemirror-tables`' `addColumn` gets the grid math right but creates the new cells
|
|
3
|
+
* without any formatting. So only its skeleton is followed here, with inheritance of
|
|
4
|
+
* the reference cell's formatting and an update of the grid column widths added on top.
|
|
5
|
+
* Deletion is left to `deleteColumn`, and only the deleted columns are dropped from the
|
|
6
|
+
* grid.
|
|
7
|
+
*
|
|
8
|
+
* Adding a column leaves the grid total the same as it was before: widening the table
|
|
9
|
+
* by the new column's width would push it past the page.
|
|
10
|
+
*/
|
|
11
|
+
import { type EditorState, type Transaction } from "prosemirror-state";
|
|
12
|
+
/**
|
|
13
|
+
* Builds the transaction that adds a column right of the column holding the cursor.
|
|
14
|
+
* `null` when the cursor is outside a table. The cursor moves into a cell of the new
|
|
15
|
+
* column.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildAddColumnAfterTransaction(state: EditorState): Transaction | null;
|
|
18
|
+
/** The left-hand version. Only the insertion position differs */
|
|
19
|
+
export declare function buildAddColumnBeforeTransaction(state: EditorState): Transaction | null;
|
|
20
|
+
/**
|
|
21
|
+
* Builds the transaction that deletes the column holding the cursor (or the columns
|
|
22
|
+
* spanned by a multi-column selection).
|
|
23
|
+
* `null` outside a table, or when every column of the table is selected.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildDeleteColumnTransaction(state: EditorState): Transaction | null;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// src/table/columns.ts
|
|
2
|
+
import {
|
|
3
|
+
TextSelection
|
|
4
|
+
} from "prosemirror-state";
|
|
5
|
+
import {
|
|
6
|
+
addColSpan,
|
|
7
|
+
deleteColumn as pmDeleteColumn,
|
|
8
|
+
isInTable as pmIsInTable,
|
|
9
|
+
selectedRect,
|
|
10
|
+
TableMap,
|
|
11
|
+
tableNodeTypes
|
|
12
|
+
} from "prosemirror-tables";
|
|
13
|
+
import { spanCount, toTableWidth } from "../model/format.js";
|
|
14
|
+
import {
|
|
15
|
+
colwidthOf,
|
|
16
|
+
inheritCellAttrs
|
|
17
|
+
} from "./format.js";
|
|
18
|
+
import {
|
|
19
|
+
cellWidthForGridCol,
|
|
20
|
+
gridColsScaledTo,
|
|
21
|
+
gridTotal,
|
|
22
|
+
rescaleCellWidths,
|
|
23
|
+
tableGridCols,
|
|
24
|
+
writeGridCols
|
|
25
|
+
} from "./widths.js";
|
|
26
|
+
function spanAttrsOf(cell) {
|
|
27
|
+
return {
|
|
28
|
+
...cell.attrs,
|
|
29
|
+
colspan: spanCount(cell.attrs.colspan),
|
|
30
|
+
rowspan: spanCount(cell.attrs.rowspan),
|
|
31
|
+
colwidth: colwidthOf(cell)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function columnSlice(cell, offset) {
|
|
35
|
+
const value = colwidthOf(cell);
|
|
36
|
+
if (!value) return null;
|
|
37
|
+
const entry = value[offset] ?? value[0];
|
|
38
|
+
return typeof entry === "number" ? [entry] : null;
|
|
39
|
+
}
|
|
40
|
+
function newColumnCellAttrs(rect, referenceCell, referencePos, referenceGridCol) {
|
|
41
|
+
return inheritCellAttrs(referenceCell, {
|
|
42
|
+
colspan: 1,
|
|
43
|
+
rowspan: 1,
|
|
44
|
+
colwidth: columnSlice(
|
|
45
|
+
referenceCell,
|
|
46
|
+
referenceGridCol - rect.map.colCount(referencePos)
|
|
47
|
+
),
|
|
48
|
+
tcW: cellWidthForGridCol(
|
|
49
|
+
tableGridCols(rect.table),
|
|
50
|
+
referenceGridCol,
|
|
51
|
+
toTableWidth(referenceCell.attrs.tcW),
|
|
52
|
+
spanCount(referenceCell.attrs.colspan)
|
|
53
|
+
)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function isCrossedFromLeft(map, col, index) {
|
|
57
|
+
return col > 0 && col < map.width && map.map[index - 1] === map.map[index];
|
|
58
|
+
}
|
|
59
|
+
function growColspan(tr, rect, col, index) {
|
|
60
|
+
const { map, table, tableStart } = rect;
|
|
61
|
+
const pos = map.map[index];
|
|
62
|
+
const cell = table.nodeAt(pos);
|
|
63
|
+
if (!cell) return 1;
|
|
64
|
+
const attrs = spanAttrsOf(cell);
|
|
65
|
+
tr.setNodeMarkup(
|
|
66
|
+
tr.mapping.map(tableStart + pos),
|
|
67
|
+
null,
|
|
68
|
+
addColSpan(attrs, col - map.colCount(pos))
|
|
69
|
+
);
|
|
70
|
+
return attrs.rowspan;
|
|
71
|
+
}
|
|
72
|
+
function widthIsPageShare(table) {
|
|
73
|
+
return toTableWidth(table.attrs.tblW)?.type === "pct";
|
|
74
|
+
}
|
|
75
|
+
function insertGridCol(tr, rect, col, referenceGridCol) {
|
|
76
|
+
const gridCols = tableGridCols(rect.table);
|
|
77
|
+
if (!gridCols) return;
|
|
78
|
+
const at = Math.min(col, gridCols.length);
|
|
79
|
+
const inserted = gridCols[referenceGridCol] ?? gridCols[gridCols.length - 1] ?? 0;
|
|
80
|
+
const grown = [...gridCols.slice(0, at), inserted, ...gridCols.slice(at)];
|
|
81
|
+
if (widthIsPageShare(rect.table)) {
|
|
82
|
+
writeGridCols(tr, rect.tableStart, grown);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const shared = gridColsScaledTo(grown, gridTotal(gridCols));
|
|
86
|
+
writeGridCols(tr, rect.tableStart, shared);
|
|
87
|
+
rescaleCellWidths(tr, rect.tableStart, shared);
|
|
88
|
+
}
|
|
89
|
+
function insertColumnWithFormat(tr, rect, col) {
|
|
90
|
+
const { map, table, tableStart } = rect;
|
|
91
|
+
const referenceOffset = col > 0 ? -1 : 0;
|
|
92
|
+
const referenceGridCol = col + referenceOffset;
|
|
93
|
+
for (let row = 0; row < map.height; row++) {
|
|
94
|
+
const index = row * map.width + col;
|
|
95
|
+
if (isCrossedFromLeft(map, col, index)) {
|
|
96
|
+
row += growColspan(tr, rect, col, index) - 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const referencePos = map.map[index + referenceOffset];
|
|
100
|
+
const referenceCell = referencePos != null ? table.nodeAt(referencePos) : null;
|
|
101
|
+
const type = referenceCell ? referenceCell.type : tableNodeTypes(table.type.schema).cell;
|
|
102
|
+
const attrs = referenceCell ? newColumnCellAttrs(rect, referenceCell, referencePos, referenceGridCol) : null;
|
|
103
|
+
const node = type.createAndFill(attrs);
|
|
104
|
+
if (!node) continue;
|
|
105
|
+
tr.insert(
|
|
106
|
+
tr.mapping.map(tableStart + map.positionAt(row, col, table)),
|
|
107
|
+
node
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
insertGridCol(tr, rect, col, referenceGridCol);
|
|
111
|
+
}
|
|
112
|
+
function buildAddColumnTransaction(state, column) {
|
|
113
|
+
if (!pmIsInTable(state)) return null;
|
|
114
|
+
const rect = selectedRect(state);
|
|
115
|
+
const col = column(rect);
|
|
116
|
+
const tr = state.tr;
|
|
117
|
+
insertColumnWithFormat(tr, rect, col);
|
|
118
|
+
const tablePos = tr.mapping.map(rect.tableStart - 1);
|
|
119
|
+
const table = tr.doc.nodeAt(tablePos);
|
|
120
|
+
if (table) {
|
|
121
|
+
const map = TableMap.get(table);
|
|
122
|
+
const row = Math.min(rect.top, map.height - 1);
|
|
123
|
+
const cellPos = map.map[row * map.width + col];
|
|
124
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(tablePos + 1 + cellPos)));
|
|
125
|
+
}
|
|
126
|
+
return tr.scrollIntoView();
|
|
127
|
+
}
|
|
128
|
+
function buildAddColumnAfterTransaction(state) {
|
|
129
|
+
return buildAddColumnTransaction(state, (rect) => rect.right);
|
|
130
|
+
}
|
|
131
|
+
function buildAddColumnBeforeTransaction(state) {
|
|
132
|
+
return buildAddColumnTransaction(state, (rect) => rect.left);
|
|
133
|
+
}
|
|
134
|
+
function buildDeleteColumnTransaction(state) {
|
|
135
|
+
if (!pmIsInTable(state)) return null;
|
|
136
|
+
const rect = selectedRect(state);
|
|
137
|
+
const { left, right, tableStart } = rect;
|
|
138
|
+
const gridCols = tableGridCols(rect.table);
|
|
139
|
+
const captured = [];
|
|
140
|
+
pmDeleteColumn(state, (tr2) => captured.push(tr2));
|
|
141
|
+
const tr = captured[0];
|
|
142
|
+
if (!tr) return null;
|
|
143
|
+
if (gridCols) {
|
|
144
|
+
writeGridCols(tr, tableStart, [
|
|
145
|
+
...gridCols.slice(0, left),
|
|
146
|
+
...gridCols.slice(right)
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
return tr;
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
buildAddColumnAfterTransaction,
|
|
153
|
+
buildAddColumnBeforeTransaction,
|
|
154
|
+
buildDeleteColumnTransaction
|
|
155
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building a transaction and running it are kept apart.
|
|
3
|
+
* Following the ProseMirror convention, calling a command without `dispatch` only
|
|
4
|
+
* reports whether it can run right now, and that answer takes in the lock guard
|
|
5
|
+
* (`schema/locks`), so no caller has to ask about locks separately.
|
|
6
|
+
*/
|
|
7
|
+
import type { EditorState, Transaction } from "prosemirror-state";
|
|
8
|
+
export type TableCommand = (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
|
|
9
|
+
/** Whether the cursor sits inside a table. Used to enable and disable the table buttons */
|
|
10
|
+
export declare function isInTable(state: EditorState): boolean;
|
|
11
|
+
export declare const addRowBefore: TableCommand;
|
|
12
|
+
export declare const addRowAfter: TableCommand;
|
|
13
|
+
export declare const deleteRow: TableCommand;
|
|
14
|
+
export declare const addColumnBefore: TableCommand;
|
|
15
|
+
export declare const addColumnAfter: TableCommand;
|
|
16
|
+
export declare const deleteColumn: TableCommand;
|
|
17
|
+
export declare const deleteTable: TableCommand;
|
|
18
|
+
export declare const mergeCells: TableCommand;
|
|
19
|
+
export declare const splitCell: TableCommand;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/table/commands.ts
|
|
2
|
+
import {
|
|
3
|
+
deleteTable as pmDeleteTable,
|
|
4
|
+
isInTable as pmIsInTable
|
|
5
|
+
} from "prosemirror-tables";
|
|
6
|
+
import { transactionAllowed } from "../schema/locks.js";
|
|
7
|
+
import {
|
|
8
|
+
buildAddColumnAfterTransaction,
|
|
9
|
+
buildAddColumnBeforeTransaction,
|
|
10
|
+
buildDeleteColumnTransaction
|
|
11
|
+
} from "./columns.js";
|
|
12
|
+
import { buildMergeCellsTransaction, buildSplitCellTransaction } from "./merge.js";
|
|
13
|
+
import {
|
|
14
|
+
buildAddRowAfterTransaction,
|
|
15
|
+
buildAddRowBeforeTransaction,
|
|
16
|
+
buildDeleteRowTransaction
|
|
17
|
+
} from "./rows.js";
|
|
18
|
+
function isInTable(state) {
|
|
19
|
+
return pmIsInTable(state);
|
|
20
|
+
}
|
|
21
|
+
function toCommand(build) {
|
|
22
|
+
return (state, dispatch) => {
|
|
23
|
+
const tr = build(state);
|
|
24
|
+
if (!tr || !transactionAllowed(tr, state.doc)) return false;
|
|
25
|
+
dispatch?.(tr);
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var addRowBefore = toCommand(
|
|
30
|
+
buildAddRowBeforeTransaction
|
|
31
|
+
);
|
|
32
|
+
var addRowAfter = toCommand(buildAddRowAfterTransaction);
|
|
33
|
+
var deleteRow = toCommand(buildDeleteRowTransaction);
|
|
34
|
+
var addColumnBefore = toCommand(
|
|
35
|
+
buildAddColumnBeforeTransaction
|
|
36
|
+
);
|
|
37
|
+
var addColumnAfter = toCommand(
|
|
38
|
+
buildAddColumnAfterTransaction
|
|
39
|
+
);
|
|
40
|
+
var deleteColumn = toCommand(
|
|
41
|
+
buildDeleteColumnTransaction
|
|
42
|
+
);
|
|
43
|
+
function buildDeleteTableTransaction(state) {
|
|
44
|
+
if (!pmIsInTable(state)) return null;
|
|
45
|
+
const captured = [];
|
|
46
|
+
pmDeleteTable(state, (tr) => captured.push(tr));
|
|
47
|
+
return captured[0] ?? null;
|
|
48
|
+
}
|
|
49
|
+
var deleteTable = toCommand(buildDeleteTableTransaction);
|
|
50
|
+
var mergeCells = toCommand(buildMergeCellsTransaction);
|
|
51
|
+
var splitCell = toCommand(buildSplitCellTransaction);
|
|
52
|
+
export {
|
|
53
|
+
addColumnAfter,
|
|
54
|
+
addColumnBefore,
|
|
55
|
+
addRowAfter,
|
|
56
|
+
addRowBefore,
|
|
57
|
+
deleteColumn,
|
|
58
|
+
deleteRow,
|
|
59
|
+
deleteTable,
|
|
60
|
+
isInTable,
|
|
61
|
+
mergeCells,
|
|
62
|
+
splitCell
|
|
63
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Newly created cells and rows inherit only the formatting of the cell or row they
|
|
3
|
+
* are based on. Values that have to be recomputed from the grid (colspan, rowspan,
|
|
4
|
+
* colwidth) are not inherited.
|
|
5
|
+
*/
|
|
6
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
7
|
+
import type { GridRect } from "../docx/tableFormatting";
|
|
8
|
+
export type NodeAttrs = Record<string, unknown>;
|
|
9
|
+
export type { GridRect };
|
|
10
|
+
/** Only the parts of what `selectedRect()` returns that are actually used here */
|
|
11
|
+
export interface TableGridMap {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
map: number[];
|
|
15
|
+
colCount(pos: number): number;
|
|
16
|
+
positionAt(row: number, col: number, table: PMNode): number;
|
|
17
|
+
/** The coordinates the cell at this position covers, merges included */
|
|
18
|
+
findCell(pos: number): GridRect;
|
|
19
|
+
/** The positions of the cells the block covers, each one listed once */
|
|
20
|
+
cellsInRect(rect: GridRect): number[];
|
|
21
|
+
}
|
|
22
|
+
export interface TableRect extends GridRect {
|
|
23
|
+
map: TableGridMap;
|
|
24
|
+
table: PMNode;
|
|
25
|
+
tableStart: number;
|
|
26
|
+
}
|
|
27
|
+
/** The list of on-screen widths. `prosemirror-tables` uses it for column resizing */
|
|
28
|
+
export declare function colwidthOf(cell: PMNode): number[] | null;
|
|
29
|
+
/** Copies only the formatting of the reference cell. Values passed in `overrides` win */
|
|
30
|
+
export declare function inheritCellAttrs(cell: PMNode, overrides?: NodeAttrs): NodeAttrs;
|
|
31
|
+
/**
|
|
32
|
+
* Copies only the formatting of the reference row. `null` when there is no reference
|
|
33
|
+
* row, meaning the schema defaults should be used
|
|
34
|
+
*/
|
|
35
|
+
export declare function inheritRowAttrs(row: PMNode | null): NodeAttrs | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/table/format.ts
|
|
2
|
+
function isNumberArray(value) {
|
|
3
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "number");
|
|
4
|
+
}
|
|
5
|
+
function colwidthOf(cell) {
|
|
6
|
+
const value = cell.attrs.colwidth;
|
|
7
|
+
return isNumberArray(value) ? value : null;
|
|
8
|
+
}
|
|
9
|
+
var INHERITED_CELL_ATTRS = ["tcAttrs", "tcPr", "tcW", "format"];
|
|
10
|
+
function inheritCellAttrs(cell, overrides = {}) {
|
|
11
|
+
const attrs = {};
|
|
12
|
+
for (const key of INHERITED_CELL_ATTRS) attrs[key] = cell.attrs[key];
|
|
13
|
+
return { ...attrs, ...overrides };
|
|
14
|
+
}
|
|
15
|
+
var INHERITED_ROW_ATTRS = ["trAttrs", "trPr", "format"];
|
|
16
|
+
function inheritRowAttrs(row) {
|
|
17
|
+
if (!row) return null;
|
|
18
|
+
const attrs = {};
|
|
19
|
+
for (const key of INHERITED_ROW_ATTRS) attrs[key] = row.attrs[key];
|
|
20
|
+
return attrs;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
colwidthOf,
|
|
24
|
+
inheritCellAttrs,
|
|
25
|
+
inheritRowAttrs
|
|
26
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lines a cell draws because of where it sits in the grid, kept true after a structure edit.
|
|
3
|
+
*
|
|
4
|
+
* Every line of a table is drawn by its cells (see `docx/tableFormatting`), so which line a side
|
|
5
|
+
* falls back on depends on where in the grid the cell sits. A new cell inherits its neighbour's
|
|
6
|
+
* formatting, which is what a background has to do but not a line: the row appended under the last
|
|
7
|
+
* one would draw the table's outer line against the row above it, and deleting the last row would
|
|
8
|
+
* leave the table with no line along its bottom.
|
|
9
|
+
*
|
|
10
|
+
* So the cells of a table whose grid moved derive their display values again, along the same path
|
|
11
|
+
* the import takes. What a cell wrote down itself lives in its `w:tcPr` and is read straight back
|
|
12
|
+
* out of it, so only the share that came from the table can change.
|
|
13
|
+
*/
|
|
14
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
15
|
+
import { Plugin } from "prosemirror-state";
|
|
16
|
+
import { type CellBorderDefaults } from "../docx/tableFormatting";
|
|
17
|
+
import { type CellMargins, type InsideBorders, type TableFormat } from "../model/format";
|
|
18
|
+
import type { TableGridMap } from "./format";
|
|
19
|
+
/**
|
|
20
|
+
* What a table lays down for its cells to draw.
|
|
21
|
+
* The values a table style laid down are not in the `tblPr`, so the table carries them separately.
|
|
22
|
+
*/
|
|
23
|
+
export interface TableCellSources {
|
|
24
|
+
outer: TableFormat | null;
|
|
25
|
+
inside: InsideBorders;
|
|
26
|
+
margins: CellMargins;
|
|
27
|
+
}
|
|
28
|
+
export declare function tableCellSources(table: PMNode): TableCellSources;
|
|
29
|
+
/** The lines the cell at this position falls back on for the sides it draws no border of its own on */
|
|
30
|
+
export declare function cellDefaultsAt(map: TableGridMap, pos: number, sources: TableCellSources): CellBorderDefaults;
|
|
31
|
+
/** Derives shared-border display values before the first editor view is drawn. */
|
|
32
|
+
export declare function withDerivedGridBorders(doc: PMNode): PMNode;
|
|
33
|
+
/**
|
|
34
|
+
* Keeps the derived lines current after a table's grid or border inputs change.
|
|
35
|
+
*
|
|
36
|
+
* The tables are paired up by the order they stand in. A document that gained or lost a whole table
|
|
37
|
+
* pairs the ones after it with the wrong partner, which costs a derivation that changes no cell.
|
|
38
|
+
*
|
|
39
|
+
* No transaction of its own goes to the history: ProseMirror hands an appended transaction to the
|
|
40
|
+
* history as part of the same event, so a single undo takes the edit and this correction back together.
|
|
41
|
+
*/
|
|
42
|
+
export declare function gridBorders(): Plugin;
|