@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,112 @@
|
|
|
1
|
+
// src/ui/TableMenu.tsx
|
|
2
|
+
import { Fragment, useCallback, useRef } from "react";
|
|
3
|
+
import { unlockSelection } from "../editor/commands/lockCommands.js";
|
|
4
|
+
import {
|
|
5
|
+
closeTableMenu
|
|
6
|
+
} from "../editor/plugins/tableContextMenu.js";
|
|
7
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
8
|
+
import {
|
|
9
|
+
addColumnAfter,
|
|
10
|
+
addColumnBefore,
|
|
11
|
+
addRowAfter,
|
|
12
|
+
addRowBefore,
|
|
13
|
+
deleteColumn,
|
|
14
|
+
deleteRow,
|
|
15
|
+
deleteTable,
|
|
16
|
+
mergeCells,
|
|
17
|
+
splitCell
|
|
18
|
+
} from "../table/index.js";
|
|
19
|
+
import { usePanelAtPoint } from "./panelPlacement.js";
|
|
20
|
+
import { commandRunner } from "./runCommand.js";
|
|
21
|
+
import { useDismiss } from "./useDismiss.js";
|
|
22
|
+
import { useMenuKeyboard } from "./useMenuKeyboard.js";
|
|
23
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
24
|
+
var MENU_GROUPS = [
|
|
25
|
+
{
|
|
26
|
+
name: "rows",
|
|
27
|
+
items: [
|
|
28
|
+
{ label: "Insert row above", command: addRowBefore },
|
|
29
|
+
{ label: "Insert row below", command: addRowAfter },
|
|
30
|
+
{ label: "Delete row", command: deleteRow }
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "columns",
|
|
35
|
+
items: [
|
|
36
|
+
{ label: "Insert column left", command: addColumnBefore },
|
|
37
|
+
{ label: "Insert column right", command: addColumnAfter },
|
|
38
|
+
{ label: "Delete column", command: deleteColumn }
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "cells",
|
|
43
|
+
items: [
|
|
44
|
+
{ label: "Merge cells", command: mergeCells },
|
|
45
|
+
{ label: "Split cell", command: splitCell }
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "table",
|
|
50
|
+
items: [{ label: "Delete table", command: deleteTable }]
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
var UNLOCK_GROUP = {
|
|
54
|
+
name: "lock",
|
|
55
|
+
items: [{ label: "Unlock", command: unlockSelection }]
|
|
56
|
+
};
|
|
57
|
+
function TableMenu({
|
|
58
|
+
view,
|
|
59
|
+
state,
|
|
60
|
+
anchor,
|
|
61
|
+
allowLocking = false
|
|
62
|
+
}) {
|
|
63
|
+
const box = useRef(null);
|
|
64
|
+
const placement = usePanelAtPoint(box, anchor);
|
|
65
|
+
const run = commandRunner(view);
|
|
66
|
+
const close = useCallback(() => {
|
|
67
|
+
closeTableMenu(view.state, (tr) => view.dispatch(tr));
|
|
68
|
+
view.focus();
|
|
69
|
+
}, [view]);
|
|
70
|
+
useDismiss(box, true, close);
|
|
71
|
+
const keys = useMenuKeyboard({ menu: box, onClose: close });
|
|
72
|
+
const choose = (command) => {
|
|
73
|
+
if (!command(state)) return;
|
|
74
|
+
run(command);
|
|
75
|
+
close();
|
|
76
|
+
};
|
|
77
|
+
const groups = allowLocking ? [...MENU_GROUPS, UNLOCK_GROUP] : MENU_GROUPS;
|
|
78
|
+
return /* @__PURE__ */ jsx(
|
|
79
|
+
"div",
|
|
80
|
+
{
|
|
81
|
+
ref: box,
|
|
82
|
+
className: editorClassNames.menu,
|
|
83
|
+
role: "menu",
|
|
84
|
+
"aria-label": "Table actions",
|
|
85
|
+
...keys,
|
|
86
|
+
style: {
|
|
87
|
+
left: placement?.left ?? anchor.clientX,
|
|
88
|
+
top: placement?.top ?? anchor.clientY,
|
|
89
|
+
visibility: placement ? void 0 : "hidden"
|
|
90
|
+
},
|
|
91
|
+
children: groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
92
|
+
index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
|
|
93
|
+
group.items.map((item) => /* @__PURE__ */ jsx(
|
|
94
|
+
"button",
|
|
95
|
+
{
|
|
96
|
+
type: "button",
|
|
97
|
+
role: "menuitem",
|
|
98
|
+
className: editorClassNames.menuItem,
|
|
99
|
+
"aria-disabled": !item.command(state),
|
|
100
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
101
|
+
onClick: () => choose(item.command),
|
|
102
|
+
children: item.label
|
|
103
|
+
},
|
|
104
|
+
item.label
|
|
105
|
+
))
|
|
106
|
+
] }, group.name))
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
TableMenu
|
|
112
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Grid for choosing the dimensions of a table to insert. */
|
|
2
|
+
import { type ReactElement } from "react";
|
|
3
|
+
import type { RunCommand } from "./runCommand";
|
|
4
|
+
export interface TableSizePickerProps {
|
|
5
|
+
run: RunCommand;
|
|
6
|
+
close: () => void;
|
|
7
|
+
takeFocus: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function TableSizePicker({ run, close, takeFocus, }: TableSizePickerProps): ReactElement;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/ui/TableSizePicker.tsx
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { insertTable } from "../editor/insertTable.js";
|
|
4
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
5
|
+
import { useGridKeyboard } from "./useGridKeyboard.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
var MAX_SIDE = 6;
|
|
8
|
+
var SIDES = Array.from({ length: MAX_SIDE }, (_, index) => index + 1);
|
|
9
|
+
var NO_SIZE = { rows: 0, cols: 0 };
|
|
10
|
+
function TableSizePicker({
|
|
11
|
+
run,
|
|
12
|
+
close,
|
|
13
|
+
takeFocus
|
|
14
|
+
}) {
|
|
15
|
+
const [size, setSize] = useState(NO_SIZE);
|
|
16
|
+
const grid = useRef(null);
|
|
17
|
+
const keys = useGridKeyboard({ grid, onClose: close, takeFocus });
|
|
18
|
+
const choose = (rows, cols) => {
|
|
19
|
+
run(insertTable({ rows, columns: cols }));
|
|
20
|
+
close();
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx(
|
|
24
|
+
"div",
|
|
25
|
+
{
|
|
26
|
+
ref: grid,
|
|
27
|
+
className: editorClassNames.sizeGrid,
|
|
28
|
+
role: "grid",
|
|
29
|
+
"aria-label": "Table size",
|
|
30
|
+
...keys,
|
|
31
|
+
children: SIDES.map((rows) => /* @__PURE__ */ jsx("div", { className: editorClassNames.sizeGridRow, role: "row", children: SIDES.map((cols) => /* @__PURE__ */ jsx(
|
|
32
|
+
"button",
|
|
33
|
+
{
|
|
34
|
+
type: "button",
|
|
35
|
+
role: "gridcell",
|
|
36
|
+
className: editorClassNames.sizeGridCell,
|
|
37
|
+
"aria-label": `${rows} by ${cols} table`,
|
|
38
|
+
"data-on": rows <= size.rows && cols <= size.cols ? "" : void 0,
|
|
39
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
40
|
+
onMouseEnter: () => setSize({ rows, cols }),
|
|
41
|
+
onFocus: () => setSize({ rows, cols }),
|
|
42
|
+
onClick: () => choose(rows, cols)
|
|
43
|
+
},
|
|
44
|
+
cols
|
|
45
|
+
)) }, rows))
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
/* @__PURE__ */ jsx("p", { className: editorClassNames.sizeGridLabel, "aria-live": "polite", children: size.rows > 0 ? `${size.rows} x ${size.cols}` : "Pick a size" })
|
|
49
|
+
] });
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
TableSizePicker
|
|
53
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Custom text context menu with clipboard, comment, and optional locking actions. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import type { EditorView } from "prosemirror-view";
|
|
4
|
+
import { type ReactElement } from "react";
|
|
5
|
+
import { type TextMenuAnchor } from "../editor/plugins/textContextMenu";
|
|
6
|
+
export interface TextMenuProps {
|
|
7
|
+
view: EditorView;
|
|
8
|
+
state: EditorState;
|
|
9
|
+
anchor: TextMenuAnchor;
|
|
10
|
+
/** Whether the entries that lock and unlock a stretch of text are offered */
|
|
11
|
+
allowLocking?: boolean;
|
|
12
|
+
/** Opens the built-in composer for the selected text. */
|
|
13
|
+
onAddComment?: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function TextMenu({ view, state, anchor, allowLocking, onAddComment, }: TextMenuProps): ReactElement;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// src/ui/TextMenu.tsx
|
|
2
|
+
import {
|
|
3
|
+
ClipboardPaste,
|
|
4
|
+
Copy,
|
|
5
|
+
Lock,
|
|
6
|
+
LockOpen,
|
|
7
|
+
MessageSquarePlus,
|
|
8
|
+
Scissors,
|
|
9
|
+
Trash2
|
|
10
|
+
} from "lucide-react";
|
|
11
|
+
import { deleteSelection } from "prosemirror-commands";
|
|
12
|
+
import { Fragment, useCallback, useRef } from "react";
|
|
13
|
+
import { canAddComment } from "../editor/commands/commentCommands.js";
|
|
14
|
+
import {
|
|
15
|
+
lockSelection,
|
|
16
|
+
selectionLock,
|
|
17
|
+
selectionTouchesLocked,
|
|
18
|
+
unlockSelection
|
|
19
|
+
} from "../editor/commands/lockCommands.js";
|
|
20
|
+
import { insertClipboardData } from "../editor/externalClipboard.js";
|
|
21
|
+
import {
|
|
22
|
+
closeTextMenu
|
|
23
|
+
} from "../editor/plugins/textContextMenu.js";
|
|
24
|
+
import { editorClassNames } from "../styles/classNames.js";
|
|
25
|
+
import { usePanelAtPoint } from "./panelPlacement.js";
|
|
26
|
+
import { commandRunner } from "./runCommand.js";
|
|
27
|
+
import { ICON_SIZE } from "./ToolbarButton.js";
|
|
28
|
+
import { useDismiss } from "./useDismiss.js";
|
|
29
|
+
import { useMenuKeyboard } from "./useMenuKeyboard.js";
|
|
30
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
31
|
+
var MOD = typeof navigator !== "undefined" && navigator.platform.includes("Mac") ? "\u2318" : "Ctrl+";
|
|
32
|
+
function clipboardCommand(view, command) {
|
|
33
|
+
view.focus();
|
|
34
|
+
document.execCommand(command);
|
|
35
|
+
}
|
|
36
|
+
async function clipboardContent() {
|
|
37
|
+
const clipboard = navigator.clipboard;
|
|
38
|
+
if (!clipboard) return { html: "", text: "" };
|
|
39
|
+
try {
|
|
40
|
+
if (clipboard.read) {
|
|
41
|
+
const items = await clipboard.read();
|
|
42
|
+
let html = "";
|
|
43
|
+
let text = "";
|
|
44
|
+
for (const item of items) {
|
|
45
|
+
if (!html && item.types.includes("text/html")) {
|
|
46
|
+
html = await (await item.getType("text/html")).text();
|
|
47
|
+
}
|
|
48
|
+
if (!text && item.types.includes("text/plain")) {
|
|
49
|
+
text = await (await item.getType("text/plain")).text();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (html || text) return { html, text };
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
html: "",
|
|
58
|
+
text: await clipboard.readText().catch(() => "")
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function pasteFromClipboard(view) {
|
|
62
|
+
const content = await clipboardContent();
|
|
63
|
+
if (!content.html && !content.text) return;
|
|
64
|
+
view.focus();
|
|
65
|
+
insertClipboardData(view, content);
|
|
66
|
+
}
|
|
67
|
+
function lockItem(lock, run) {
|
|
68
|
+
const locking = {
|
|
69
|
+
label: "Lock",
|
|
70
|
+
icon: Lock,
|
|
71
|
+
run: () => run(lockSelection)
|
|
72
|
+
};
|
|
73
|
+
switch (lock) {
|
|
74
|
+
case "none":
|
|
75
|
+
return { ...locking, enabled: false };
|
|
76
|
+
case "lockable":
|
|
77
|
+
return { ...locking, enabled: true };
|
|
78
|
+
case "locked":
|
|
79
|
+
case "mixed":
|
|
80
|
+
return {
|
|
81
|
+
label: "Unlock",
|
|
82
|
+
icon: LockOpen,
|
|
83
|
+
enabled: true,
|
|
84
|
+
run: () => run(unlockSelection)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function TextMenu({
|
|
89
|
+
view,
|
|
90
|
+
state,
|
|
91
|
+
anchor,
|
|
92
|
+
allowLocking = false,
|
|
93
|
+
onAddComment
|
|
94
|
+
}) {
|
|
95
|
+
const box = useRef(null);
|
|
96
|
+
const placement = usePanelAtPoint(box, anchor);
|
|
97
|
+
const run = commandRunner(view);
|
|
98
|
+
const close = useCallback(() => {
|
|
99
|
+
closeTextMenu(view.state, (tr) => view.dispatch(tr));
|
|
100
|
+
view.focus();
|
|
101
|
+
}, [view]);
|
|
102
|
+
useDismiss(box, true, close);
|
|
103
|
+
const keys = useMenuKeyboard({ menu: box, onClose: close });
|
|
104
|
+
const selected = !state.selection.empty;
|
|
105
|
+
const shut = selectionTouchesLocked(state);
|
|
106
|
+
const groups = [
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
label: "Cut",
|
|
110
|
+
icon: Scissors,
|
|
111
|
+
hint: `${MOD}X`,
|
|
112
|
+
enabled: selected && !shut,
|
|
113
|
+
run: () => clipboardCommand(view, "cut")
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
label: "Copy",
|
|
117
|
+
icon: Copy,
|
|
118
|
+
hint: `${MOD}C`,
|
|
119
|
+
enabled: selected,
|
|
120
|
+
run: () => clipboardCommand(view, "copy")
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
label: "Paste",
|
|
124
|
+
icon: ClipboardPaste,
|
|
125
|
+
hint: `${MOD}V`,
|
|
126
|
+
enabled: !shut,
|
|
127
|
+
run: () => {
|
|
128
|
+
void pasteFromClipboard(view);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
label: "Delete",
|
|
133
|
+
icon: Trash2,
|
|
134
|
+
enabled: selected && !shut,
|
|
135
|
+
run: () => run(deleteSelection)
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
];
|
|
139
|
+
groups.push([
|
|
140
|
+
{
|
|
141
|
+
label: "Add comment",
|
|
142
|
+
icon: MessageSquarePlus,
|
|
143
|
+
enabled: !!onAddComment && canAddComment(state),
|
|
144
|
+
run: () => onAddComment?.()
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
if (allowLocking) groups.push([lockItem(selectionLock(state), run)]);
|
|
148
|
+
const choose = (item) => {
|
|
149
|
+
if (!item.enabled) return;
|
|
150
|
+
item.run();
|
|
151
|
+
close();
|
|
152
|
+
};
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
ref: box,
|
|
157
|
+
className: editorClassNames.menu,
|
|
158
|
+
role: "menu",
|
|
159
|
+
"aria-label": "Text actions",
|
|
160
|
+
...keys,
|
|
161
|
+
style: {
|
|
162
|
+
left: placement?.left ?? anchor.clientX,
|
|
163
|
+
top: placement?.top ?? anchor.clientY,
|
|
164
|
+
visibility: placement ? void 0 : "hidden"
|
|
165
|
+
},
|
|
166
|
+
children: groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
167
|
+
index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
|
|
168
|
+
group.map((item) => {
|
|
169
|
+
const Icon = item.icon;
|
|
170
|
+
return /* @__PURE__ */ jsxs(
|
|
171
|
+
"button",
|
|
172
|
+
{
|
|
173
|
+
type: "button",
|
|
174
|
+
role: "menuitem",
|
|
175
|
+
className: editorClassNames.menuItem,
|
|
176
|
+
"aria-disabled": !item.enabled,
|
|
177
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
178
|
+
onClick: () => choose(item),
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ jsx(Icon, { size: ICON_SIZE, "aria-hidden": "true" }),
|
|
181
|
+
item.label,
|
|
182
|
+
item.hint && /* @__PURE__ */ jsx("span", { className: editorClassNames.menuHint, children: item.hint })
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
item.label
|
|
186
|
+
);
|
|
187
|
+
})
|
|
188
|
+
] }, group[0].label))
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
TextMenu
|
|
194
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Editor toolbar with roving focus across its enabled controls. */
|
|
2
|
+
import type { EditorState } from "prosemirror-state";
|
|
3
|
+
import type { EditorView } from "prosemirror-view";
|
|
4
|
+
import { type ReactElement } from "react";
|
|
5
|
+
import type { FontFallbacks } from "../styles/fontStack";
|
|
6
|
+
import type { DocxEditorPresets } from "./presets";
|
|
7
|
+
import type { DocxEditorZoom } from "./zoom";
|
|
8
|
+
export interface ToolbarProps {
|
|
9
|
+
view: EditorView;
|
|
10
|
+
state: EditorState;
|
|
11
|
+
fontFallbacks?: FontFallbacks;
|
|
12
|
+
/** Optional values offered by toolbar pickers. */
|
|
13
|
+
presets?: DocxEditorPresets;
|
|
14
|
+
onToggleComments?: () => void;
|
|
15
|
+
commentsOpen?: boolean;
|
|
16
|
+
zoom: DocxEditorZoom;
|
|
17
|
+
onZoomChange: (zoom: DocxEditorZoom) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function Toolbar({ view, state, fontFallbacks, presets, onToggleComments, commentsOpen, zoom, onZoomChange, }: ToolbarProps): ReactElement;
|