Skip to content

Commit 4462419

Browse files
committed
chore(docviewer): cleanup mammoth js
1 parent 7b6f70b commit 4462419

File tree

6 files changed

+41
-162
lines changed

6 files changed

+41
-162
lines changed

packages/pluggableWidgets/document-viewer-web/components/DocxViewer.tsx

+4-49
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,9 @@
1-
import { createElement, Fragment, useCallback, useEffect, useState } from "react";
2-
import mammoth from "mammoth";
3-
import { DocumentViewerContainerProps } from "typings/DocumentViewerProps";
1+
import { createElement, Fragment } from "react";
2+
import { DocumentViewerContainerProps } from "../typings/DocumentViewerProps";
43
import { DocRendererElement } from "./documentRenderer";
54

6-
const DocxViewer: DocRendererElement = (props: DocumentViewerContainerProps) => {
7-
const { file } = props;
8-
const [docxHtml, setDocxHtml] = useState<string | null>(null);
9-
10-
const loadContent = useCallback(async (arrayBuffer: any) => {
11-
try {
12-
mammoth
13-
.convertToHtml(
14-
{ arrayBuffer: arrayBuffer },
15-
{
16-
includeDefaultStyleMap: true
17-
}
18-
)
19-
.then(result => {
20-
if (result) {
21-
setDocxHtml(result.value);
22-
}
23-
});
24-
} catch (error) {}
25-
}, []);
26-
27-
useEffect(() => {
28-
const controller = new AbortController();
29-
const { signal } = controller;
30-
if (file.status === "available" && file.value.uri) {
31-
fetch(file.value.uri, { method: "GET", signal })
32-
.then(res => res.arrayBuffer())
33-
.then(response => {
34-
loadContent(response);
35-
});
36-
}
37-
38-
return () => {
39-
controller.abort();
40-
};
41-
}, [file, file?.status, file?.value?.uri]);
42-
43-
return (
44-
<Fragment>
45-
{docxHtml && (
46-
<div className="widget-document-viewer-content" dangerouslySetInnerHTML={{ __html: docxHtml }}>
47-
{/* {docHtmlStr} */}
48-
</div>
49-
)}
50-
</Fragment>
51-
);
5+
const DocxViewer: DocRendererElement = (_props: DocumentViewerContainerProps) => {
6+
return <Fragment>DOCX</Fragment>;
527
};
538

549
DocxViewer.contentTypes = [

packages/pluggableWidgets/document-viewer-web/components/ErrorViewer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createElement, Fragment, useContext } from "react";
2-
import { DocumentContext } from "store";
2+
import { DocumentContext } from "../store";
33
import { DocRendererElement } from "./documentRenderer";
44

55
const ErrorViewer: DocRendererElement = () => {

packages/pluggableWidgets/document-viewer-web/components/documentRenderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC } from "react";
2-
import { DocumentViewerContainerProps } from "typings/DocumentViewerProps";
2+
import { DocumentViewerContainerProps } from "../typings/DocumentViewerProps";
33

44
export interface DocRendererElement extends FC<DocumentViewerContainerProps> {
55
contentTypes: string[];

packages/pluggableWidgets/document-viewer-web/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
},
3636
"dependencies": {
3737
"classnames": "^2.3.2",
38-
"mammoth": "^1.9.0",
3938
"pdfjs-dist": "^5.0.375",
4039
"react-pdf": "^9.2.1"
4140
},
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
import commonjs from "@rollup/plugin-commonjs";
2+
13
export default args => {
2-
return args.configDefaultConfig.map((config, _index) => {
4+
const result = args.configDefaultConfig;
5+
return result.map((config, _index) => {
36
config.output.inlineDynamicImports = true;
4-
return config;
7+
if (config.output.format !== "es") {
8+
return config;
9+
}
10+
return {
11+
...config,
12+
plugins: config.plugins.map(plugin => {
13+
if (plugin && plugin.name === "commonjs") {
14+
// replace common js plugin that transforms
15+
// external requires to imports
16+
// this is needed in order to work with modern client
17+
return commonjs({
18+
extensions: [".js", ".jsx", ".tsx", ".ts"],
19+
transformMixedEsModules: true,
20+
requireReturnsDefault: "auto",
21+
esmExternals: true
22+
});
23+
}
24+
25+
return plugin;
26+
})
27+
};
528
});
629
};

0 commit comments

Comments
 (0)