@extend-ai/react-docx 0.5.0 → 0.6.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/dist/chunk-TIKIYV26.js +6131 -0
- package/dist/chunk-TIKIYV26.js.map +1 -0
- package/dist/docx-import-worker.cjs +5927 -0
- package/dist/docx-import-worker.cjs.map +1 -0
- package/dist/docx-import-worker.js +33 -0
- package/dist/docx-import-worker.js.map +1 -0
- package/dist/index.cjs +2429 -223
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +397 -10
- package/dist/index.d.ts +397 -10
- package/dist/index.js +2704 -6607
- package/dist/index.js.map +1 -1
- package/package.json +18 -2
package/dist/index.d.ts
CHANGED
|
@@ -241,6 +241,7 @@ interface TableRowStyle {
|
|
|
241
241
|
heightTwips?: number;
|
|
242
242
|
heightRule?: "auto" | "atLeast" | "exact";
|
|
243
243
|
cantSplit?: boolean;
|
|
244
|
+
isHeader?: boolean;
|
|
244
245
|
}
|
|
245
246
|
interface TableRowNode {
|
|
246
247
|
type: "table-row";
|
|
@@ -650,18 +651,68 @@ interface DocxLineSpacingInfo {
|
|
|
650
651
|
type DocxBorderContext = "paragraph" | "table";
|
|
651
652
|
type DocxBorderPreset = "bottom" | "top" | "left" | "right" | "none" | "all" | "outside" | "inside" | "inside-horizontal" | "inside-vertical" | "diagonal-down" | "diagonal-up" | "horizontal-line";
|
|
652
653
|
type DocxBorderPresetState = Record<DocxBorderPreset, boolean>;
|
|
654
|
+
/**
|
|
655
|
+
* Initial state for `useDocxEditor`.
|
|
656
|
+
*
|
|
657
|
+
* These values are read when the editor controller is created. Later document
|
|
658
|
+
* imports update the controller through `editor.importDocxFile`.
|
|
659
|
+
*/
|
|
653
660
|
interface UseDocxEditorOptions {
|
|
661
|
+
/**
|
|
662
|
+
* Model used for `editor.newDocument()` and for the initial empty editor.
|
|
663
|
+
*
|
|
664
|
+
* @defaultValue `defaultStarterModel`
|
|
665
|
+
*/
|
|
654
666
|
starterModel?: DocModel;
|
|
667
|
+
/**
|
|
668
|
+
* Initial display name before a user imports a file.
|
|
669
|
+
*
|
|
670
|
+
* @defaultValue `"(new document)"`
|
|
671
|
+
*/
|
|
655
672
|
initialFileName?: string;
|
|
673
|
+
/**
|
|
674
|
+
* Initial status text exposed on `editor.status`.
|
|
675
|
+
*
|
|
676
|
+
* @defaultValue `"Ready"`
|
|
677
|
+
*/
|
|
656
678
|
initialStatus?: string;
|
|
679
|
+
/**
|
|
680
|
+
* Initial document surface theme.
|
|
681
|
+
*
|
|
682
|
+
* @defaultValue `"light"`
|
|
683
|
+
*/
|
|
657
684
|
initialDocumentTheme?: DocxDocumentTheme;
|
|
685
|
+
/**
|
|
686
|
+
* Whether tracked changes are visible when the editor first mounts.
|
|
687
|
+
*
|
|
688
|
+
* @defaultValue `false`
|
|
689
|
+
*/
|
|
658
690
|
initialShowTrackedChanges?: boolean;
|
|
659
691
|
}
|
|
692
|
+
/**
|
|
693
|
+
* Controller returned by `useDocxEditor`.
|
|
694
|
+
*
|
|
695
|
+
* Pass this object to `DocxEditorViewer`, then wire toolbar buttons and custom
|
|
696
|
+
* controls to the methods exposed here.
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* ```tsx
|
|
700
|
+
* const editor = useDocxEditor();
|
|
701
|
+
*
|
|
702
|
+
* return (
|
|
703
|
+
* <>
|
|
704
|
+
* <button onClick={() => editor.toggleBold()}>Bold</button>
|
|
705
|
+
* <DocxEditorViewer editor={editor} />
|
|
706
|
+
* </>
|
|
707
|
+
* );
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
660
710
|
interface DocxEditorController {
|
|
661
711
|
model: DocModel;
|
|
662
712
|
documentLoadNonce: number;
|
|
663
713
|
fileName: string;
|
|
664
714
|
status: string;
|
|
715
|
+
isImporting: boolean;
|
|
665
716
|
documentTheme: DocxDocumentTheme;
|
|
666
717
|
selection: DocxEditorSelection;
|
|
667
718
|
activeTextRange?: DocxTextRange;
|
|
@@ -767,95 +818,301 @@ interface DocxEditorController {
|
|
|
767
818
|
type DocxTableContextMenuActionId = "insert-row-above" | "insert-row-below" | "insert-column-left" | "insert-column-right" | "delete-row" | "delete-column" | "delete-table";
|
|
768
819
|
type DocxContextMenuActionId = DocxTableContextMenuActionId | "cut" | "copy" | "paste" | "image-wrap-inline" | "image-wrap-square" | "image-wrap-tight" | "image-wrap-through" | "image-wrap-top-and-bottom" | "image-wrap-behind-text" | "image-wrap-in-front-of-text" | "image-edit-wrap-boundary" | "image-move-with-text" | "image-fix-position-on-page" | "image-more-layout-options" | "image-bring-to-front" | "image-bring-forward" | "image-in-front-of-text" | "image-send-to-back" | "image-send-backward" | "image-behind-text";
|
|
769
820
|
interface DocxTableContextMenuContext {
|
|
821
|
+
/** Zero-based table index in the document body. */
|
|
770
822
|
tableIndex: number;
|
|
823
|
+
/** Zero-based row index under the pointer. */
|
|
771
824
|
rowIndex: number;
|
|
825
|
+
/** Zero-based cell index under the pointer. */
|
|
772
826
|
cellIndex: number;
|
|
773
827
|
}
|
|
774
828
|
interface DocxTableContextMenuAction {
|
|
829
|
+
/** Built-in table command id. */
|
|
775
830
|
id: DocxTableContextMenuActionId;
|
|
831
|
+
/** Human-readable menu label. */
|
|
776
832
|
label: string;
|
|
833
|
+
/** True when the action removes content or structure. */
|
|
777
834
|
destructive?: boolean;
|
|
778
835
|
}
|
|
779
836
|
interface DocxContextMenuAction {
|
|
837
|
+
/** Built-in command id, or a custom id from your menu renderer. */
|
|
780
838
|
id: DocxContextMenuActionId | (string & {});
|
|
839
|
+
/** Human-readable menu label. */
|
|
781
840
|
label: string;
|
|
841
|
+
/** Optional keyboard shortcut text to display next to the label. */
|
|
782
842
|
shortcut?: string;
|
|
843
|
+
/** True when the action removes content or structure. */
|
|
783
844
|
destructive?: boolean;
|
|
845
|
+
/** Prevents the action from being selected. */
|
|
784
846
|
disabled?: boolean;
|
|
847
|
+
/** Marks toggle-style menu items as active. */
|
|
785
848
|
checked?: boolean;
|
|
849
|
+
/** Adds a visual separator before this item in default-style menus. */
|
|
786
850
|
separatorBefore?: boolean;
|
|
851
|
+
/** Nested submenu actions. */
|
|
787
852
|
children?: DocxContextMenuAction[];
|
|
788
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* Arguments passed to `renderTableContextMenu`.
|
|
856
|
+
*/
|
|
789
857
|
interface DocxTableContextMenuRenderProps {
|
|
858
|
+
/** Table cell that opened the menu. */
|
|
790
859
|
context: DocxTableContextMenuContext;
|
|
860
|
+
/** Built-in table actions available for this context. */
|
|
791
861
|
actions: DocxTableContextMenuAction[];
|
|
862
|
+
/** Runs a built-in table action. */
|
|
792
863
|
runAction: (actionId: DocxTableContextMenuActionId) => void;
|
|
864
|
+
/** Closes the menu without running an action. */
|
|
793
865
|
closeMenu: () => void;
|
|
866
|
+
/** Viewport coordinates where the menu should be placed. */
|
|
794
867
|
position: {
|
|
795
868
|
x: number;
|
|
796
869
|
y: number;
|
|
797
870
|
};
|
|
871
|
+
/** Current document theme, useful for custom menu styling. */
|
|
798
872
|
documentTheme: DocxDocumentTheme;
|
|
799
873
|
}
|
|
800
874
|
interface DocxContextMenuContext {
|
|
875
|
+
/** Type of target that opened the menu. */
|
|
801
876
|
kind: "text" | "table" | "image";
|
|
877
|
+
/** Active text range when the menu was opened from text. */
|
|
802
878
|
activeTextRange?: DocxTextRange;
|
|
879
|
+
/** Text location under the pointer when available. */
|
|
803
880
|
location?: DocxTextRangeLocation;
|
|
881
|
+
/** Table context when `kind` is `"table"`. */
|
|
804
882
|
tableContext?: DocxTableContextMenuContext;
|
|
883
|
+
/** Image context when `kind` is `"image"`. */
|
|
805
884
|
image?: {
|
|
806
885
|
location: DocxImageLocation;
|
|
807
886
|
floating?: NonNullable<ImageRunNode["floating"]>;
|
|
808
887
|
wrap?: DocxImageWrapState;
|
|
809
888
|
} | undefined;
|
|
810
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* Arguments passed to `renderContextMenu`.
|
|
892
|
+
*/
|
|
811
893
|
interface DocxContextMenuRenderProps {
|
|
894
|
+
/** Target context that opened the menu. */
|
|
812
895
|
context: DocxContextMenuContext;
|
|
896
|
+
/** Built-in actions available for this context. */
|
|
813
897
|
actions: DocxContextMenuAction[];
|
|
898
|
+
/** Runs a built-in or custom action id. */
|
|
814
899
|
runAction: (actionId: DocxContextMenuActionId | (string & {})) => void;
|
|
900
|
+
/** Closes the menu without running an action. */
|
|
815
901
|
closeMenu: () => void;
|
|
902
|
+
/** Viewport coordinates where the menu should be placed. */
|
|
816
903
|
position: {
|
|
817
904
|
x: number;
|
|
818
905
|
y: number;
|
|
819
906
|
};
|
|
907
|
+
/** Current document theme, useful for custom menu styling. */
|
|
820
908
|
documentTheme: DocxDocumentTheme;
|
|
821
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* Controls how `DocxEditorViewer` windows page DOM nodes.
|
|
912
|
+
*
|
|
913
|
+
* Virtualization is enabled by default for multi-page documents. It keeps
|
|
914
|
+
* offscreen pages as lightweight placeholders, which is important for large
|
|
915
|
+
* DOCX files with many tables or complex paragraphs.
|
|
916
|
+
*/
|
|
917
|
+
interface DocxPageVirtualizationOptions {
|
|
918
|
+
/**
|
|
919
|
+
* Enables or disables internal page virtualization.
|
|
920
|
+
*
|
|
921
|
+
* Disable only when you need every page mounted at once, for example when
|
|
922
|
+
* generating thumbnails for all pages from the live DOM.
|
|
923
|
+
*
|
|
924
|
+
* @defaultValue `true`
|
|
925
|
+
*/
|
|
926
|
+
enabled?: boolean;
|
|
927
|
+
/**
|
|
928
|
+
* Number of pages to keep mounted before and after the visible viewport.
|
|
929
|
+
*
|
|
930
|
+
* Higher values reduce mount/unmount churn while scrolling but increase
|
|
931
|
+
* initial DOM work.
|
|
932
|
+
*
|
|
933
|
+
* @defaultValue `2`
|
|
934
|
+
*/
|
|
935
|
+
overscan?: number;
|
|
936
|
+
/**
|
|
937
|
+
* Compatibility option from earlier releases.
|
|
938
|
+
*
|
|
939
|
+
* Page virtualization now starts immediately, so this option is accepted but
|
|
940
|
+
* does not delay the initial page window.
|
|
941
|
+
*
|
|
942
|
+
* @defaultValue `0`
|
|
943
|
+
*/
|
|
944
|
+
settleDelayMs?: number;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Externally controlled visible page window.
|
|
948
|
+
*
|
|
949
|
+
* Provide this when your app owns scrolling or virtualization and wants
|
|
950
|
+
* `DocxEditorViewer` to mount only a specific page range.
|
|
951
|
+
*/
|
|
952
|
+
interface DocxVisiblePageRange {
|
|
953
|
+
/**
|
|
954
|
+
* Zero-based first page index to render.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* ```tsx
|
|
958
|
+
* <DocxEditorViewer
|
|
959
|
+
* editor={editor}
|
|
960
|
+
* visiblePageRange={{ startPageIndex: 0, endPageIndex: 2 }}
|
|
961
|
+
* />
|
|
962
|
+
* ```
|
|
963
|
+
*/
|
|
964
|
+
startPageIndex: number;
|
|
965
|
+
/** Zero-based last page index to render. */
|
|
966
|
+
endPageIndex: number;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Props for the full DOCX editor/viewer surface.
|
|
970
|
+
*
|
|
971
|
+
* Use this component with a controller from `useDocxEditor`.
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```tsx
|
|
975
|
+
* const editor = useDocxEditor();
|
|
976
|
+
*
|
|
977
|
+
* return (
|
|
978
|
+
* <DocxEditorViewer
|
|
979
|
+
* editor={editor}
|
|
980
|
+
* mode="read-only"
|
|
981
|
+
* pageVirtualization={{ overscan: 3 }}
|
|
982
|
+
* />
|
|
983
|
+
* );
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
822
986
|
interface DocxEditorViewerProps {
|
|
987
|
+
/**
|
|
988
|
+
* Editor controller returned by `useDocxEditor`.
|
|
989
|
+
*/
|
|
823
990
|
editor: DocxEditorController;
|
|
991
|
+
/**
|
|
992
|
+
* CSS class applied to the outer viewer root.
|
|
993
|
+
*/
|
|
824
994
|
className?: string;
|
|
995
|
+
/**
|
|
996
|
+
* Inline styles applied to the outer viewer root.
|
|
997
|
+
*/
|
|
825
998
|
style?: React.CSSProperties;
|
|
999
|
+
/**
|
|
1000
|
+
* Background color of each rendered page surface.
|
|
1001
|
+
*
|
|
1002
|
+
* @defaultValue Viewer theme page color.
|
|
1003
|
+
*/
|
|
826
1004
|
pageBackgroundColor?: string;
|
|
1005
|
+
/**
|
|
1006
|
+
* Background color shown between pages.
|
|
1007
|
+
*
|
|
1008
|
+
* @defaultValue `"transparent"`
|
|
1009
|
+
*/
|
|
827
1010
|
pageGapBackgroundColor?: string;
|
|
1011
|
+
/**
|
|
1012
|
+
* Hides the document behind `loadingState` until initial pagination settles.
|
|
1013
|
+
*
|
|
1014
|
+
* Leave enabled when you prefer stable first paint over immediate approximate
|
|
1015
|
+
* layout. Disable when you want the first visible page as soon as possible.
|
|
1016
|
+
*
|
|
1017
|
+
* @defaultValue `true`
|
|
1018
|
+
*/
|
|
828
1019
|
deferInitialPaginationPaint?: boolean;
|
|
1020
|
+
/**
|
|
1021
|
+
* Custom content shown while initial pagination is settling.
|
|
1022
|
+
*
|
|
1023
|
+
* Used only when `deferInitialPaginationPaint` is true.
|
|
1024
|
+
*
|
|
1025
|
+
* @defaultValue A compact `"Loading..."` pill.
|
|
1026
|
+
*/
|
|
829
1027
|
loadingState?: React.ReactNode;
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
1028
|
+
/**
|
|
1029
|
+
* Configures internal page virtualization.
|
|
1030
|
+
*
|
|
1031
|
+
* @defaultValue `{ enabled: true, overscan: 2 }`
|
|
1032
|
+
*/
|
|
1033
|
+
pageVirtualization?: DocxPageVirtualizationOptions;
|
|
1034
|
+
/**
|
|
1035
|
+
* Controlled page range to mount.
|
|
1036
|
+
*
|
|
1037
|
+
* When provided, internal page virtualization is bypassed and only this
|
|
1038
|
+
* range is rendered.
|
|
1039
|
+
*/
|
|
1040
|
+
visiblePageRange?: DocxVisiblePageRange;
|
|
1041
|
+
/**
|
|
1042
|
+
* Called whenever the viewer's resolved page count changes.
|
|
1043
|
+
*/
|
|
839
1044
|
onPageCountChange?: (pageCount: number) => void;
|
|
1045
|
+
/**
|
|
1046
|
+
* Called when the viewer needs a page to become visible, such as after a
|
|
1047
|
+
* bookmark or cross-reference navigation.
|
|
1048
|
+
*
|
|
1049
|
+
* If omitted, the internal virtualizer scrolls the page into view.
|
|
1050
|
+
*/
|
|
840
1051
|
onRequestPageReveal?: (pageIndex: number) => void;
|
|
1052
|
+
/**
|
|
1053
|
+
* Overrides visual styles for heading levels.
|
|
1054
|
+
*/
|
|
841
1055
|
headingStyles?: DocxHeadingStyleMap;
|
|
1056
|
+
/**
|
|
1057
|
+
* Interaction mode for the viewer.
|
|
1058
|
+
*
|
|
1059
|
+
* @defaultValue `"edit"`
|
|
1060
|
+
*/
|
|
842
1061
|
mode?: DocxEditorViewerMode;
|
|
1062
|
+
/**
|
|
1063
|
+
* Overrides whether tracked changes are shown.
|
|
1064
|
+
*
|
|
1065
|
+
* If omitted, the value from `useDocxTrackChanges(editor)` or
|
|
1066
|
+
* `editor.showTrackedChanges` is used.
|
|
1067
|
+
*/
|
|
843
1068
|
showTrackedChanges?: boolean;
|
|
1069
|
+
/**
|
|
1070
|
+
* Custom renderer for tracked-change cards in the page gutter.
|
|
1071
|
+
*/
|
|
844
1072
|
renderTrackedChangeCard?: (props: DocxTrackedChangeCardRenderProps) => React.ReactNode;
|
|
1073
|
+
/**
|
|
1074
|
+
* Custom renderer for table context menus.
|
|
1075
|
+
*
|
|
1076
|
+
* Call `props.runAction(action.id)` to execute built-in actions.
|
|
1077
|
+
*/
|
|
845
1078
|
renderTableContextMenu?: (props: DocxTableContextMenuRenderProps) => React.ReactNode;
|
|
1079
|
+
/**
|
|
1080
|
+
* Custom renderer for text, image, and table context menus.
|
|
1081
|
+
*
|
|
1082
|
+
* Call `props.closeMenu()` after handling a custom action.
|
|
1083
|
+
*/
|
|
846
1084
|
renderContextMenu?: (props: DocxContextMenuRenderProps) => React.ReactNode;
|
|
1085
|
+
/**
|
|
1086
|
+
* Called when a form field is double-clicked.
|
|
1087
|
+
*
|
|
1088
|
+
* Use this to open a custom field settings panel.
|
|
1089
|
+
*/
|
|
847
1090
|
onFormFieldDoubleClick?: (location: DocxFormFieldLocation) => void;
|
|
848
1091
|
}
|
|
849
1092
|
interface DocxTrackedChangeCardRenderProps {
|
|
1093
|
+
/** Tracked-change data represented by the card. */
|
|
850
1094
|
change: DocxTrackedChange;
|
|
1095
|
+
/** Short display label for the change kind. */
|
|
851
1096
|
kindLabel: string;
|
|
1097
|
+
/** Plain-text excerpt for the changed content. */
|
|
852
1098
|
snippet: string;
|
|
1099
|
+
/** Formatted change date, if the source document provided one. */
|
|
853
1100
|
formattedDate?: string;
|
|
1101
|
+
/** Accent color chosen for this change kind. */
|
|
854
1102
|
accentColor: string;
|
|
1103
|
+
/** Current document theme. */
|
|
855
1104
|
documentTheme: DocxDocumentTheme;
|
|
1105
|
+
/** Zero-based page index that owns the card. */
|
|
856
1106
|
pageIndex: number;
|
|
1107
|
+
/** Positioning style computed by the viewer. Apply this to the card root. */
|
|
857
1108
|
style: React.CSSProperties;
|
|
858
1109
|
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Viewer interaction mode.
|
|
1112
|
+
*
|
|
1113
|
+
* - `"edit"` allows editing when the document state permits it.
|
|
1114
|
+
* - `"read-only"` disables editing affordances while preserving navigation.
|
|
1115
|
+
*/
|
|
859
1116
|
type DocxEditorViewerMode = "edit" | "read-only";
|
|
860
1117
|
interface UseDocxDocumentThemeResult {
|
|
861
1118
|
documentTheme: DocxDocumentTheme;
|
|
@@ -929,52 +1186,133 @@ interface UseDocxPaginationResult {
|
|
|
929
1186
|
pagination: DocxPaginationInfo;
|
|
930
1187
|
}
|
|
931
1188
|
interface DocxPageThumbnailResolutionOptions {
|
|
1189
|
+
/** Source page width in CSS pixels. */
|
|
932
1190
|
sourceWidthPx: number;
|
|
1191
|
+
/** Source page height in CSS pixels. */
|
|
933
1192
|
sourceHeightPx: number;
|
|
1193
|
+
/**
|
|
1194
|
+
* Desired thumbnail bounds.
|
|
1195
|
+
*
|
|
1196
|
+
* A number means "fit within this max width and max height". An object lets
|
|
1197
|
+
* you constrain width and height independently.
|
|
1198
|
+
*
|
|
1199
|
+
* @defaultValue `160`
|
|
1200
|
+
*/
|
|
934
1201
|
resolution?: DocxPageThumbnailBounds;
|
|
1202
|
+
/**
|
|
1203
|
+
* Maximum CSS pixel width for the thumbnail.
|
|
1204
|
+
*
|
|
1205
|
+
* Overrides `resolution.maxWidth` when provided.
|
|
1206
|
+
*/
|
|
935
1207
|
maxWidthPx?: number;
|
|
1208
|
+
/**
|
|
1209
|
+
* Maximum CSS pixel height for the thumbnail.
|
|
1210
|
+
*
|
|
1211
|
+
* Overrides `resolution.maxHeight` when provided.
|
|
1212
|
+
*/
|
|
936
1213
|
maxHeightPx?: number;
|
|
1214
|
+
/**
|
|
1215
|
+
* Canvas backing-store pixel ratio.
|
|
1216
|
+
*
|
|
1217
|
+
* Increase for sharper thumbnails on high-density displays.
|
|
1218
|
+
*
|
|
1219
|
+
* @defaultValue `window.devicePixelRatio`, capped internally.
|
|
1220
|
+
*/
|
|
937
1221
|
pixelRatio?: number;
|
|
938
1222
|
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Thumbnail size constraint.
|
|
1225
|
+
*
|
|
1226
|
+
* @example
|
|
1227
|
+
* ```tsx
|
|
1228
|
+
* useDocxPageThumbnails(editor, { resolution: 180 });
|
|
1229
|
+
* useDocxPageThumbnails(editor, { resolution: { maxWidth: 120 } });
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
939
1232
|
type DocxPageThumbnailBounds = number | {
|
|
1233
|
+
/** Maximum thumbnail CSS height. */
|
|
940
1234
|
maxHeight?: number;
|
|
1235
|
+
/** Maximum thumbnail CSS width. */
|
|
941
1236
|
maxWidth?: number;
|
|
942
1237
|
};
|
|
943
1238
|
interface DocxPageThumbnailResolution {
|
|
1239
|
+
/** Thumbnail CSS width. */
|
|
944
1240
|
widthPx: number;
|
|
1241
|
+
/** Thumbnail CSS height. */
|
|
945
1242
|
heightPx: number;
|
|
1243
|
+
/** Canvas backing-store width. */
|
|
946
1244
|
pixelWidthPx: number;
|
|
1245
|
+
/** Canvas backing-store height. */
|
|
947
1246
|
pixelHeightPx: number;
|
|
1247
|
+
/** Scale from source page pixels to thumbnail CSS pixels. */
|
|
948
1248
|
scale: number;
|
|
949
1249
|
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Options for `useDocxPageThumbnails`.
|
|
1252
|
+
*/
|
|
950
1253
|
interface UseDocxPageThumbnailsOptions {
|
|
1254
|
+
/**
|
|
1255
|
+
* Desired thumbnail bounds.
|
|
1256
|
+
*
|
|
1257
|
+
* @defaultValue `160`
|
|
1258
|
+
*/
|
|
951
1259
|
resolution?: DocxPageThumbnailBounds;
|
|
1260
|
+
/** Maximum thumbnail CSS width. */
|
|
952
1261
|
maxWidthPx?: number;
|
|
1262
|
+
/** Maximum thumbnail CSS height. */
|
|
953
1263
|
maxHeightPx?: number;
|
|
1264
|
+
/**
|
|
1265
|
+
* Canvas backing-store pixel ratio.
|
|
1266
|
+
*
|
|
1267
|
+
* @defaultValue `window.devicePixelRatio`, capped internally.
|
|
1268
|
+
*/
|
|
954
1269
|
pixelRatio?: number;
|
|
1270
|
+
/**
|
|
1271
|
+
* Prevents thumbnail rendering while keeping stable item metadata.
|
|
1272
|
+
*
|
|
1273
|
+
* @defaultValue `false`
|
|
1274
|
+
*/
|
|
955
1275
|
disabled?: boolean;
|
|
956
1276
|
}
|
|
957
1277
|
type DocxPageThumbnailStatus = "idle" | "rendering" | "ready" | "unavailable" | "error";
|
|
958
1278
|
interface DocxPageThumbnailItem extends DocxPageThumbnailResolution {
|
|
1279
|
+
/** Source page aspect ratio. */
|
|
959
1280
|
aspectRatio: number;
|
|
1281
|
+
/** Alias for `sourceHeightPx` for compatibility with other preview APIs. */
|
|
960
1282
|
contentHeight: number;
|
|
1283
|
+
/** Alias for `sourceWidthPx` for compatibility with other preview APIs. */
|
|
961
1284
|
contentWidth: number;
|
|
1285
|
+
/** Alias for `heightPx`. */
|
|
962
1286
|
height: number;
|
|
1287
|
+
/** Zero-based page index. */
|
|
963
1288
|
pageIndex: number;
|
|
1289
|
+
/** One-based page number for display. */
|
|
964
1290
|
pageNumber: number;
|
|
1291
|
+
/** Source page width in CSS pixels. */
|
|
965
1292
|
sourceWidthPx: number;
|
|
1293
|
+
/** Source page height in CSS pixels. */
|
|
966
1294
|
sourceHeightPx: number;
|
|
1295
|
+
/** True when the source page DOM is currently mounted. */
|
|
967
1296
|
isMounted: boolean;
|
|
1297
|
+
/** Current thumbnail render status. */
|
|
968
1298
|
status: DocxPageThumbnailStatus;
|
|
1299
|
+
/** Last thumbnail rendering error, if any. */
|
|
969
1300
|
error?: Error;
|
|
1301
|
+
/** Paints this thumbnail into a canvas. Returns false when unavailable. */
|
|
970
1302
|
paint: (canvas: HTMLCanvasElement | null) => boolean;
|
|
1303
|
+
/** Ref callback that keeps an attached canvas rendered as the page changes. */
|
|
971
1304
|
canvasRef: (canvas: HTMLCanvasElement | null) => void;
|
|
1305
|
+
/** Asynchronously renders this thumbnail into a canvas. */
|
|
972
1306
|
renderToCanvas: (canvas: HTMLCanvasElement) => Promise<void>;
|
|
1307
|
+
/** Alias for `widthPx`. */
|
|
973
1308
|
width: number;
|
|
974
1309
|
}
|
|
975
1310
|
interface UseDocxPageThumbnailsResult {
|
|
1311
|
+
/** Paints the requested page thumbnail into a canvas. */
|
|
976
1312
|
paintThumbnail: (pageIndex: number, canvas: HTMLCanvasElement | null) => boolean;
|
|
1313
|
+
/** Thumbnail metadata and paint helpers for each known page. */
|
|
977
1314
|
thumbnails: DocxPageThumbnailItem[];
|
|
1315
|
+
/** Re-renders every thumbnail canvas currently attached through `canvasRef`. */
|
|
978
1316
|
rerenderAttachedThumbnails: () => Promise<void>;
|
|
979
1317
|
}
|
|
980
1318
|
type UseDocxViewerThumbnailsOptions = UseDocxPageThumbnailsOptions;
|
|
@@ -1244,18 +1582,67 @@ declare function serializeDocModel(model: DocModel, basePackage?: OoxmlPackage):
|
|
|
1244
1582
|
declare function serializeDocx(model: DocModel, basePackage?: OoxmlPackage): ArrayBuffer;
|
|
1245
1583
|
|
|
1246
1584
|
interface ReactDocxViewerProps {
|
|
1585
|
+
/**
|
|
1586
|
+
* Raw `.docx` file contents to parse and render.
|
|
1587
|
+
*
|
|
1588
|
+
* Pass either `file` or `model`. When both are provided, `model` wins and
|
|
1589
|
+
* the file buffer is ignored.
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* ```tsx
|
|
1593
|
+
* const buffer = await file.arrayBuffer();
|
|
1594
|
+
* <ReactDocxViewer file={buffer} />
|
|
1595
|
+
* ```
|
|
1596
|
+
*/
|
|
1247
1597
|
file?: ArrayBuffer;
|
|
1598
|
+
/**
|
|
1599
|
+
* Prebuilt document model to render without parsing a `.docx` buffer.
|
|
1600
|
+
*
|
|
1601
|
+
* Useful when you already parsed the document with `parseDocx` and
|
|
1602
|
+
* `buildDocModel`, or when you are rendering a model produced by your own
|
|
1603
|
+
* pipeline.
|
|
1604
|
+
*/
|
|
1248
1605
|
model?: DocModel;
|
|
1606
|
+
/**
|
|
1607
|
+
* CSS class applied to the outer viewer container.
|
|
1608
|
+
*
|
|
1609
|
+
* @example
|
|
1610
|
+
* ```tsx
|
|
1611
|
+
* <ReactDocxViewer file={buffer} className="docx-preview" />
|
|
1612
|
+
* ```
|
|
1613
|
+
*/
|
|
1249
1614
|
className?: string;
|
|
1615
|
+
/**
|
|
1616
|
+
* Layout overrides for the simple read-only renderer.
|
|
1617
|
+
*
|
|
1618
|
+
* If omitted, page width and height are derived from the document section
|
|
1619
|
+
* properties when available.
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* ```tsx
|
|
1623
|
+
* <ReactDocxViewer
|
|
1624
|
+
* file={buffer}
|
|
1625
|
+
* layoutOptions={{ pageWidth: 816, pageHeight: 1056, margin: 72 }}
|
|
1626
|
+
* />
|
|
1627
|
+
* ```
|
|
1628
|
+
*/
|
|
1250
1629
|
layoutOptions?: LayoutOptions;
|
|
1630
|
+
/**
|
|
1631
|
+
* Content shown when neither `file` nor `model` is provided.
|
|
1632
|
+
*
|
|
1633
|
+
* @defaultValue `"No DOCX loaded."`
|
|
1634
|
+
*/
|
|
1251
1635
|
emptyState?: React.ReactNode;
|
|
1252
1636
|
}
|
|
1253
1637
|
interface UseDocxModelState {
|
|
1638
|
+
/** Parsed document model, available once loading succeeds. */
|
|
1254
1639
|
model?: DocModel;
|
|
1640
|
+
/** True while the hook is parsing the current file buffer. */
|
|
1255
1641
|
isLoading: boolean;
|
|
1642
|
+
/** Parse or model-build failure for the current file buffer. */
|
|
1256
1643
|
error?: Error;
|
|
1257
1644
|
}
|
|
1258
1645
|
declare function useDocxModel(file?: ArrayBuffer): UseDocxModelState;
|
|
1259
1646
|
declare function ReactDocxViewer({ file, model, className, layoutOptions, emptyState }: ReactDocxViewerProps): React.JSX.Element;
|
|
1260
1647
|
|
|
1261
|
-
export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, applyRunStyle, buildDocModel, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, insertParagraph, layoutDocument, modelToDocumentXml, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocumentXml, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };
|
|
1648
|
+
export { DEFAULT_MIN_PARAGRAPH_LINE_HEIGHT_PX, DEFAULT_PAGE_OVERFLOW_TOLERANCE_PX, type DocModel, type DocNode, type DocumentCompatibilitySettings, type DocumentNoteDefinition, type DocumentPageNodeSegment, type DocumentPageRange, type DocumentPageSegmentationOptions, type DocumentSection, type DocxBorderContext, type DocxBorderPreset, type DocxBorderPresetState, type DocxContextMenuAction, type DocxContextMenuActionId, type DocxContextMenuContext, type DocxContextMenuRenderProps, type DocxDocumentTheme, type DocxEditorController, type DocxEditorSelection, DocxEditorViewer, type DocxEditorViewerMode, type DocxEditorViewerProps, type DocxFormFieldLocation, type DocxHeadingStyleMap, type DocxImageDropTarget, type DocxImageLocation, type DocxImageWrapMenuOption, type DocxImageWrapMode, type DocxImageWrapState, type DocxLineSpacingInfo, type DocxListType, type DocxPageLayoutInfo, type DocxPageThumbnailBounds, type DocxPageThumbnailItem, type DocxPageThumbnailResolution, type DocxPageThumbnailResolutionOptions, type DocxPageThumbnailStatus, type DocxPageVirtualizationOptions, type DocxPaginationInfo, type DocxSectionColumnLayout, type DocxSelectedFormField, type DocxTableContextMenuAction, type DocxTableContextMenuActionId, type DocxTableContextMenuContext, type DocxTableContextMenuRenderProps, type DocxTextRange, type DocxTextRangeLocation, type DocxTrackedChange, type DocxTrackedChangeCardRenderProps, type DocxTrackedChangeKind, type DocxViewerThumbnails, type DocxVisiblePageRange, type FooterSection, type FormFieldCheckboxWidgetSettings, type FormFieldDropdownWidgetSettings, type FormFieldOption, type FormFieldRunNode, type FormFieldSourceKind, type FormFieldTextWidgetSettings, type FormFieldType, type FormFieldWidgetSettings, type HeaderSection, type HeadingLevel, type ImageRunNode, type InsertParagraphOptions, type LayoutBlock, type LayoutFragmentSource, type LayoutImageRun, type LayoutOptions, type LayoutPage, type LayoutParagraphBlock, type LayoutRun, type LayoutSnapshot, type LayoutSnapshotBlockFragment, type LayoutSnapshotImageRun, type LayoutSnapshotMargins, type LayoutSnapshotOptions, type LayoutSnapshotPage, type LayoutSnapshotPageSize, type LayoutSnapshotParagraphFragment, type LayoutSnapshotRect, type LayoutSnapshotRun, type LayoutSnapshotTableCellFragment, type LayoutSnapshotTableFragment, type LayoutSnapshotTableRowFragment, type LayoutSnapshotTextRun, type LayoutTableBlock, type LayoutTableCell, type LayoutTableRow, type LayoutTextRun, type LetterheadColumnSegmentGroup, type NumberingAbstractDefinition, type NumberingDefinitionSet, type NumberingInstanceDefinition, type NumberingLevelDefinition, type NumberingPictureBulletDefinition, type OoxmlPackage, type OoxmlPart, type OverflowBreakCollectionOptions, type PageSegmentationCallbacks, type PaginationSectionMetrics, type ParagraphAlignment, type ParagraphBorderSet, type ParagraphBorderStyle, type ParagraphChildNode, type ParagraphIndent, type ParagraphLineRange, type ParagraphNode, type ParagraphNumbering, type ParagraphSpacing, type ParagraphSplitControlOptions, type ParagraphStyle, type ParagraphStyleDefinition, ReactDocxViewer, type ReactDocxViewerProps, type ResolvedDocument, type ResolvedDocumentSection, type ResolvedLayoutMetrics, type ResolvedModelSection, type TableBorderSet, type TableBorderStyle, type TableBoxSpacing, type TableCellContentNode, type TableCellNode, type TableCellStyle, type TableExplicitPageBreakInfo, type TableNode, type TableRowNode, type TableRowRange, type TableRowStyle, type TableStyle, type TextRunBorderStyle, type TextRunNode, type TextStyle, type UpdateTextOptions, type UseDocxBordersResult, type UseDocxDocumentThemeResult, type UseDocxEditorOptions, type UseDocxFormFieldsResult, type UseDocxImageWrapMenuResult, type UseDocxLineSpacingResult, type UseDocxModelState, type UseDocxPageLayoutResult, type UseDocxPageThumbnailsOptions, type UseDocxPageThumbnailsResult, type UseDocxPaginationResult, type UseDocxParagraphStylesResult, type UseDocxTrackChangesResult, type UseDocxViewerThumbnailsOptions, applyRunStyle, buildDocModel, buildDocumentPageNodeSegments, buildDocumentPageRanges, buildLayoutSnapshot, cloneDocModel, collectDocxEstimatedOverflowBreakStartNodeIndexes, collectDocxHardPageBreakStartNodeIndexes, collectDocxLastRenderedPageBreakStartNodeIndexes, collectTableExplicitPageBreakInfo, collectTopLevelExplicitPageBreakStartNodeIndexes, copyParagraphs, createMinimalDocxPackage, defaultStarterModel, duplicateParagraph, getPart, insertParagraph, layoutDocument, modelToDocumentXml, packageToArrayBuffer, paragraphAfterSpacingPx, paragraphBeforeSpacingPx, paragraphHasExplicitPageBreak, paragraphHasLastRenderedPageBreak, paragraphHasPageBreakBefore, paragraphLetterheadColumnGroupAtSegmentOffset, paragraphLetterheadFloatSideAtNodeIndex, paragraphStartsWithLastRenderedPageBreak, parseDocumentXml, parseDocx, parseParagraphsFromClipboard, parseSectionLayout, pasteParagraphs, removeParagraph, replaceText, resolveDocumentForLayout, resolveDocumentLayout, resolveDocumentPageSegmentStartNodeIndex, resolveDocumentSectionsFromMetadata, resolveDocxPageThumbnailResolution, resolvePaginationSectionMetricsIndexForNodeIndex, resolveParagraphBeforeSpacingPx, resolveSectionIndexForNodeIndex, resolveSectionPropertiesXmlForNodeIndex, scalePaginationSectionMetricsHeights, scorePaginationAgainstStoredPageBreaks, sectionBreakAfterParagraphStartsNewPage, sectionBreakPropertiesStartNewPage, sectionTitlePageEnabled, selectSectionVariantForPage, serializeDocModel, serializeDocx, serializeParagraphsForClipboard, setParagraphAlignment, setParagraphHeading, setRunColor, setRunHighlight, splitParagraphChildrenAtTextOffsets, toggleRunStyleFlag, updateParagraphText, updateTableCellParagraphText, updateTableCellParagraphTextRecursive, updateTableCellText, useDocxBorders, useDocxDocumentTheme, useDocxEditor, useDocxFormFields, useDocxImageWrapMenu, useDocxLineSpacing, useDocxModel, useDocxPageLayout, useDocxPageThumbnails, useDocxPagination, useDocxParagraphStyles, useDocxTrackChanges, useDocxViewerThumbnails, withPart };
|