@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,26 @@
|
|
|
1
|
+
// src/ui/useFitWidthZoom.ts
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
import { fitWidthZoom } from "./zoom.js";
|
|
4
|
+
function useFitWidthZoom(container, pageWidth) {
|
|
5
|
+
const [zoom, setZoom] = useState(1);
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
const element = container.current;
|
|
8
|
+
if (!element) return;
|
|
9
|
+
const frameWindow = element.ownerDocument.defaultView;
|
|
10
|
+
const update = () => {
|
|
11
|
+
setZoom(fitWidthZoom(element.clientWidth, pageWidth));
|
|
12
|
+
};
|
|
13
|
+
update();
|
|
14
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
|
|
15
|
+
observer?.observe(element);
|
|
16
|
+
frameWindow?.addEventListener("resize", update, { passive: true });
|
|
17
|
+
return () => {
|
|
18
|
+
observer?.disconnect();
|
|
19
|
+
frameWindow?.removeEventListener("resize", update);
|
|
20
|
+
};
|
|
21
|
+
}, [container, pageWidth]);
|
|
22
|
+
return zoom;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
useFitWidthZoom
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Two-dimensional ARIA grid navigation with clamped edges and Tab dismissal. */
|
|
2
|
+
import { type KeyboardEvent, type RefObject } from "react";
|
|
3
|
+
export interface GridKeyboardOptions {
|
|
4
|
+
grid: RefObject<HTMLElement | null>;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
start?: (cells: readonly HTMLElement[]) => HTMLElement | undefined;
|
|
7
|
+
takeFocus?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface GridKeyboard {
|
|
10
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useGridKeyboard({ grid, onClose, start, takeFocus, }: GridKeyboardOptions): GridKeyboard;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/ui/useGridKeyboard.ts
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { SCROLLING_KEYS } from "./keyboardWalk.js";
|
|
4
|
+
import { useRovingFocus } from "./rovingFocus.js";
|
|
5
|
+
var GRID_ROWS = '[role="row"]';
|
|
6
|
+
var GRID_CELLS = '[role="gridcell"]';
|
|
7
|
+
function rowsOf(grid) {
|
|
8
|
+
return Array.from(
|
|
9
|
+
grid?.querySelectorAll(GRID_ROWS) ?? [],
|
|
10
|
+
(row) => Array.from(row.querySelectorAll(GRID_CELLS))
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function spotOf(rows, cell) {
|
|
14
|
+
for (const [row, cells] of rows.entries()) {
|
|
15
|
+
const column = cells.findIndex((found) => found === cell);
|
|
16
|
+
if (column !== -1) return { row, column };
|
|
17
|
+
}
|
|
18
|
+
return { row: 0, column: 0 };
|
|
19
|
+
}
|
|
20
|
+
function held(value, last) {
|
|
21
|
+
return Math.max(0, Math.min(value, last));
|
|
22
|
+
}
|
|
23
|
+
function stepped(rows, from, event) {
|
|
24
|
+
const acrossRows = (row) => ({
|
|
25
|
+
row,
|
|
26
|
+
column: held(from.column, rows[row].length - 1)
|
|
27
|
+
});
|
|
28
|
+
const wholeGrid = event.ctrlKey || event.metaKey;
|
|
29
|
+
switch (event.key) {
|
|
30
|
+
case "ArrowRight":
|
|
31
|
+
return {
|
|
32
|
+
row: from.row,
|
|
33
|
+
column: held(from.column + 1, rows[from.row].length - 1)
|
|
34
|
+
};
|
|
35
|
+
case "ArrowLeft":
|
|
36
|
+
return {
|
|
37
|
+
row: from.row,
|
|
38
|
+
column: held(from.column - 1, rows[from.row].length - 1)
|
|
39
|
+
};
|
|
40
|
+
case "ArrowDown":
|
|
41
|
+
return acrossRows(held(from.row + 1, rows.length - 1));
|
|
42
|
+
case "ArrowUp":
|
|
43
|
+
return acrossRows(held(from.row - 1, rows.length - 1));
|
|
44
|
+
case "Home":
|
|
45
|
+
return wholeGrid ? { row: 0, column: 0 } : { row: from.row, column: 0 };
|
|
46
|
+
case "End": {
|
|
47
|
+
const row = wholeGrid ? rows.length - 1 : from.row;
|
|
48
|
+
return { row, column: rows[row].length - 1 };
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function useGridKeyboard({
|
|
55
|
+
grid,
|
|
56
|
+
onClose,
|
|
57
|
+
start,
|
|
58
|
+
takeFocus = true
|
|
59
|
+
}) {
|
|
60
|
+
const roving = useRovingFocus({
|
|
61
|
+
container: grid,
|
|
62
|
+
selector: GRID_CELLS,
|
|
63
|
+
start,
|
|
64
|
+
takeFocus
|
|
65
|
+
});
|
|
66
|
+
const onKeyDown = useCallback(
|
|
67
|
+
(event) => {
|
|
68
|
+
const rows = rowsOf(grid.current).filter((cells) => cells.length > 0);
|
|
69
|
+
if (rows.length === 0) return;
|
|
70
|
+
if (event.key === "Tab") {
|
|
71
|
+
onClose();
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (SCROLLING_KEYS.has(event.key)) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const to = stepped(rows, spotOf(rows, document.activeElement), event);
|
|
80
|
+
if (!to) return;
|
|
81
|
+
roving.moveTo(rows[to.row][to.column]);
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
},
|
|
84
|
+
[grid, onClose, roving]
|
|
85
|
+
);
|
|
86
|
+
return { onKeyDown };
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
useGridKeyboard
|
|
90
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** ARIA menu navigation with roving focus, typeahead, and Tab dismissal. */
|
|
2
|
+
import { type KeyboardEvent, type RefObject } from "react";
|
|
3
|
+
export interface MenuKeyboardOptions {
|
|
4
|
+
menu: RefObject<HTMLElement | null>;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
/** Whether focus moves into the menu when it appears. */
|
|
7
|
+
takeFocus?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface MenuKeyboard {
|
|
10
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useMenuKeyboard({ menu, onClose, takeFocus, }: MenuKeyboardOptions): MenuKeyboard;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/ui/useMenuKeyboard.ts
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { SCROLLING_KEYS, useLinearWalk } from "./keyboardWalk.js";
|
|
4
|
+
var MENU_ROWS = '[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';
|
|
5
|
+
function currentChoice(rows) {
|
|
6
|
+
return rows.find((row) => row.getAttribute("aria-checked") === "true");
|
|
7
|
+
}
|
|
8
|
+
function typedAhead(rows, from, letter) {
|
|
9
|
+
const wanted = letter.toLowerCase();
|
|
10
|
+
for (let step = 1; step <= rows.length; step += 1) {
|
|
11
|
+
const row = rows[(from + step) % rows.length];
|
|
12
|
+
if (row.textContent?.trim().toLowerCase().startsWith(wanted)) return row;
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
function useMenuKeyboard({
|
|
17
|
+
menu,
|
|
18
|
+
onClose,
|
|
19
|
+
takeFocus = true
|
|
20
|
+
}) {
|
|
21
|
+
const rows = useLinearWalk({
|
|
22
|
+
container: menu,
|
|
23
|
+
selector: MENU_ROWS,
|
|
24
|
+
orientation: "vertical",
|
|
25
|
+
start: currentChoice,
|
|
26
|
+
takeFocus
|
|
27
|
+
});
|
|
28
|
+
const onKeyDown = useCallback(
|
|
29
|
+
(event) => {
|
|
30
|
+
const found = rows.controls();
|
|
31
|
+
if (found.length === 0) return;
|
|
32
|
+
if (rows.walk(event)) return;
|
|
33
|
+
if (event.key === "Tab") {
|
|
34
|
+
onClose();
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (SCROLLING_KEYS.has(event.key)) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const typed = event.key.length === 1 && event.key !== " ";
|
|
43
|
+
if (!typed || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
44
|
+
const at = found.findIndex((row2) => row2 === document.activeElement);
|
|
45
|
+
const row = typedAhead(found, at === -1 ? 0 : at, event.key);
|
|
46
|
+
if (!row) return;
|
|
47
|
+
rows.moveTo(row);
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
},
|
|
50
|
+
[rows, onClose]
|
|
51
|
+
);
|
|
52
|
+
return { onKeyDown };
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
useMenuKeyboard
|
|
56
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type DocxEditorZoom = "fit-width" | number;
|
|
2
|
+
export declare const DEFAULT_ZOOM_LEVELS: readonly [0.5, 0.75, 1, 1.25, 1.5];
|
|
3
|
+
export declare function normalizeZoom(zoom: DocxEditorZoom): DocxEditorZoom;
|
|
4
|
+
export declare function fitWidthZoom(containerWidth: number, pageWidth: number): number;
|
package/dist/ui/zoom.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/ui/zoom.ts
|
|
2
|
+
var DEFAULT_ZOOM_LEVELS = [0.5, 0.75, 1, 1.25, 1.5];
|
|
3
|
+
var MIN_ZOOM = 0.25;
|
|
4
|
+
var MAX_ZOOM = 2;
|
|
5
|
+
var MIN_FIT_WIDTH_ZOOM = 0.5;
|
|
6
|
+
function normalizeZoom(zoom) {
|
|
7
|
+
if (zoom === "fit-width") return zoom;
|
|
8
|
+
if (!Number.isFinite(zoom)) return 1;
|
|
9
|
+
return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
|
|
10
|
+
}
|
|
11
|
+
function fitWidthZoom(containerWidth, pageWidth) {
|
|
12
|
+
if (containerWidth <= 0 || pageWidth <= 0) return 1;
|
|
13
|
+
const availableWidth = Math.max(0, containerWidth - 32);
|
|
14
|
+
const zoom = Math.min(1, availableWidth / pageWidth);
|
|
15
|
+
return Math.max(MIN_FIT_WIDTH_ZOOM, Math.round(zoom * 100) / 100);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_ZOOM_LEVELS,
|
|
19
|
+
fitWidthZoom,
|
|
20
|
+
normalizeZoom
|
|
21
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@portone/docx-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A simple DOCX editor for React, built directly on OOXML.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/portone-io/docx-editor.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://docx-editor.portone.io",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/portone-io/docx-editor/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"docx",
|
|
20
|
+
"editor",
|
|
21
|
+
"ooxml",
|
|
22
|
+
"prosemirror",
|
|
23
|
+
"react"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./core": {
|
|
34
|
+
"types": "./dist/core.d.ts",
|
|
35
|
+
"default": "./dist/core.js"
|
|
36
|
+
},
|
|
37
|
+
"./commands": {
|
|
38
|
+
"types": "./dist/editor/commands/index.d.ts",
|
|
39
|
+
"default": "./dist/editor/commands/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./table": {
|
|
42
|
+
"types": "./dist/table/index.d.ts",
|
|
43
|
+
"default": "./dist/table/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./styles.css": "./dist/styles.css"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
"README.md",
|
|
54
|
+
"CHANGELOG.md",
|
|
55
|
+
"CONTRIBUTING.md",
|
|
56
|
+
"assets"
|
|
57
|
+
],
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"fflate": "^0.8.2",
|
|
60
|
+
"lucide-react": "^1.16.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"prosemirror-commands": "^1.5.2",
|
|
64
|
+
"prosemirror-dropcursor": "^1.8.2",
|
|
65
|
+
"prosemirror-history": "^1.5.0",
|
|
66
|
+
"prosemirror-inputrules": "^1.5.0",
|
|
67
|
+
"prosemirror-keymap": "^1.2.2",
|
|
68
|
+
"prosemirror-model": "^1.19.4",
|
|
69
|
+
"prosemirror-state": "^1.4.3",
|
|
70
|
+
"prosemirror-tables": "^1.8.5",
|
|
71
|
+
"prosemirror-transform": "^1.12.0",
|
|
72
|
+
"prosemirror-view": "^1.41.6",
|
|
73
|
+
"react": ">=18"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@biomejs/biome": "2.5.10",
|
|
77
|
+
"@changesets/changelog-github": "^1.0.0",
|
|
78
|
+
"@changesets/cli": "^3.0.1",
|
|
79
|
+
"@playwright/test": "^1.62.1",
|
|
80
|
+
"@types/node": "^26.2.0",
|
|
81
|
+
"@types/react": "19.2.18",
|
|
82
|
+
"@types/react-dom": "19.2.4",
|
|
83
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
84
|
+
"esbuild": "^0.28.1",
|
|
85
|
+
"jsdom": "^30.0.1",
|
|
86
|
+
"prosemirror-commands": "^1.5.2",
|
|
87
|
+
"prosemirror-dropcursor": "^1.8.2",
|
|
88
|
+
"prosemirror-history": "^1.5.0",
|
|
89
|
+
"prosemirror-inputrules": "^1.5.0",
|
|
90
|
+
"prosemirror-keymap": "^1.2.2",
|
|
91
|
+
"prosemirror-model": "^1.19.4",
|
|
92
|
+
"prosemirror-state": "^1.4.3",
|
|
93
|
+
"prosemirror-tables": "^1.8.5",
|
|
94
|
+
"prosemirror-transform": "^1.12.0",
|
|
95
|
+
"prosemirror-view": "^1.41.6",
|
|
96
|
+
"react": "^19.2.8",
|
|
97
|
+
"react-dom": "^19.2.8",
|
|
98
|
+
"typescript": "^7.0.2",
|
|
99
|
+
"vite": "^8.0.12",
|
|
100
|
+
"vitest": "^4.1.6"
|
|
101
|
+
},
|
|
102
|
+
"scripts": {
|
|
103
|
+
"build": "node scripts/build.mjs && tsc -p tsconfig.build.json",
|
|
104
|
+
"dev": "vite --config demo/vite.config.ts --open",
|
|
105
|
+
"build:demo": "vite build --config demo/vite.config.ts",
|
|
106
|
+
"dev:site": "pnpm --filter @portone/docx-editor-site dev",
|
|
107
|
+
"build:site": "pnpm --filter @portone/docx-editor-site build",
|
|
108
|
+
"check": "pnpm lint && pnpm typecheck && pnpm test",
|
|
109
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p e2e && tsc --noEmit -p demo && pnpm --filter @portone/docx-editor-site typecheck",
|
|
110
|
+
"lint": "pnpm biome check . --diagnostic-level=error",
|
|
111
|
+
"test": "vitest run",
|
|
112
|
+
"test:package": "vitest run --dir packaging --no-file-parallelism",
|
|
113
|
+
"verify:package": "node scripts/verify-package.mjs",
|
|
114
|
+
"spec": "node scripts/index-ooxml-spec.mjs",
|
|
115
|
+
"changeset": "changeset",
|
|
116
|
+
"changeset:version": "changeset version",
|
|
117
|
+
"test:e2e": "playwright test"
|
|
118
|
+
},
|
|
119
|
+
"types": "./dist/index.d.ts"
|
|
120
|
+
}
|